Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Some IBSS support code for cfg80211. |
| 3 | * |
| 4 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 5 | */ |
| 6 | |
| 7 | #include <linux/etherdevice.h> |
| 8 | #include <linux/if_arp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 10 | #include <linux/export.h> |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11 | #include <net/cfg80211.h> |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 12 | #include "wext-compat.h" |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13 | #include "nl80211.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 14 | #include "rdev-ops.h" |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15 | |
| 16 | |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 17 | void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, |
| 18 | struct ieee80211_channel *channel) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 19 | { |
| 20 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 21 | struct cfg80211_bss *bss; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 22 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 23 | union iwreq_data wrqu; |
| 24 | #endif |
| 25 | |
| 26 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 27 | return; |
| 28 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 29 | if (!wdev->ssid_len) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 30 | return; |
| 31 | |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 32 | bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, NULL, 0, |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 33 | IEEE80211_BSS_TYPE_IBSS, IEEE80211_PRIVACY_ANY); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 34 | |
| 35 | if (WARN_ON(!bss)) |
| 36 | return; |
| 37 | |
| 38 | if (wdev->current_bss) { |
| 39 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 40 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 41 | } |
| 42 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 43 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 44 | wdev->current_bss = bss_from_pub(bss); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 45 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 46 | cfg80211_upload_connect_keys(wdev); |
| 47 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 48 | nl80211_send_ibss_bssid(wiphy_to_rdev(wdev->wiphy), dev, bssid, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 49 | GFP_KERNEL); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 50 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 51 | memset(&wrqu, 0, sizeof(wrqu)); |
| 52 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
| 53 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 54 | #endif |
| 55 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 56 | |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 57 | void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, |
| 58 | struct ieee80211_channel *channel, gfp_t gfp) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 59 | { |
| 60 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 61 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 62 | struct cfg80211_event *ev; |
| 63 | unsigned long flags; |
| 64 | |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 65 | trace_cfg80211_ibss_joined(dev, bssid, channel); |
| 66 | |
| 67 | if (WARN_ON(!channel)) |
| 68 | return; |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 69 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 70 | ev = kzalloc(sizeof(*ev), gfp); |
| 71 | if (!ev) |
| 72 | return; |
| 73 | |
| 74 | ev->type = EVENT_IBSS_JOINED; |
Antonio Quartulli | fe94f3a | 2014-01-29 17:53:43 +0100 | [diff] [blame] | 75 | memcpy(ev->ij.bssid, bssid, ETH_ALEN); |
| 76 | ev->ij.channel = channel; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 77 | |
| 78 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 79 | list_add_tail(&ev->list, &wdev->event_list); |
| 80 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 81 | queue_work(cfg80211_wq, &rdev->event_work); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 82 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 83 | EXPORT_SYMBOL(cfg80211_ibss_joined); |
| 84 | |
Zhao, Gang | 2316d7b | 2014-03-08 11:01:24 +0800 | [diff] [blame] | 85 | static int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev, |
| 86 | struct net_device *dev, |
| 87 | struct cfg80211_ibss_params *params, |
| 88 | struct cfg80211_cached_keys *connkeys) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 89 | { |
| 90 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 91 | int err; |
| 92 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 93 | ASSERT_WDEV_LOCK(wdev); |
| 94 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 95 | if (wdev->ssid_len) |
| 96 | return -EALREADY; |
| 97 | |
Johannes Berg | 93b0523 | 2010-09-28 12:53:14 +0200 | [diff] [blame] | 98 | if (!params->basic_rates) { |
| 99 | /* |
| 100 | * If no rates were explicitly configured, |
| 101 | * use the mandatory rate set for 11b or |
| 102 | * 11a for maximum compatibility. |
| 103 | */ |
| 104 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 105 | rdev->wiphy.bands[params->chandef.chan->band]; |
Johannes Berg | 93b0523 | 2010-09-28 12:53:14 +0200 | [diff] [blame] | 106 | int j; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 107 | u32 flag = params->chandef.chan->band == IEEE80211_BAND_5GHZ ? |
Johannes Berg | 93b0523 | 2010-09-28 12:53:14 +0200 | [diff] [blame] | 108 | IEEE80211_RATE_MANDATORY_A : |
| 109 | IEEE80211_RATE_MANDATORY_B; |
| 110 | |
| 111 | for (j = 0; j < sband->n_bitrates; j++) { |
| 112 | if (sband->bitrates[j].flags & flag) |
| 113 | params->basic_rates |= BIT(j); |
| 114 | } |
| 115 | } |
| 116 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 117 | if (WARN_ON(wdev->connect_keys)) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 118 | kzfree(wdev->connect_keys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 119 | wdev->connect_keys = connkeys; |
| 120 | |
Michal Kazior | c30a3d3 | 2012-06-29 12:46:59 +0200 | [diff] [blame] | 121 | wdev->ibss_fixed = params->channel_fixed; |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 122 | wdev->ibss_dfs_possible = params->userspace_handles_dfs; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 123 | wdev->chandef = params->chandef; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 124 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 125 | wdev->wext.ibss.chandef = params->chandef; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 126 | #endif |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 127 | err = rdev_join_ibss(rdev, dev, params); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 128 | if (err) { |
| 129 | wdev->connect_keys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 130 | return err; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 131 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 132 | |
| 133 | memcpy(wdev->ssid, params->ssid, params->ssid_len); |
| 134 | wdev->ssid_len = params->ssid_len; |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 139 | int cfg80211_join_ibss(struct cfg80211_registered_device *rdev, |
| 140 | struct net_device *dev, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 141 | struct cfg80211_ibss_params *params, |
| 142 | struct cfg80211_cached_keys *connkeys) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 143 | { |
| 144 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 145 | int err; |
| 146 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 147 | ASSERT_RTNL(); |
| 148 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 149 | wdev_lock(wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 150 | err = __cfg80211_join_ibss(rdev, dev, params, connkeys); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 151 | wdev_unlock(wdev); |
| 152 | |
| 153 | return err; |
| 154 | } |
| 155 | |
| 156 | static void __cfg80211_clear_ibss(struct net_device *dev, bool nowext) |
| 157 | { |
| 158 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 159 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 160 | int i; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 161 | |
| 162 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 163 | |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 164 | kzfree(wdev->connect_keys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 165 | wdev->connect_keys = NULL; |
| 166 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 167 | rdev_set_qos_map(rdev, dev, NULL); |
| 168 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 169 | /* |
| 170 | * Delete all the keys ... pairwise keys can't really |
| 171 | * exist any more anyway, but default keys might. |
| 172 | */ |
| 173 | if (rdev->ops->del_key) |
| 174 | for (i = 0; i < 6; i++) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 175 | rdev_del_key(rdev, dev, i, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 176 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 177 | if (wdev->current_bss) { |
| 178 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 179 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | wdev->current_bss = NULL; |
| 183 | wdev->ssid_len = 0; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 184 | memset(&wdev->chandef, 0, sizeof(wdev->chandef)); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 185 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 9d30842 | 2009-04-20 18:43:46 +0200 | [diff] [blame] | 186 | if (!nowext) |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 187 | wdev->wext.ibss.ssid_len = 0; |
Johannes Berg | 9d30842 | 2009-04-20 18:43:46 +0200 | [diff] [blame] | 188 | #endif |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 189 | } |
| 190 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 191 | void cfg80211_clear_ibss(struct net_device *dev, bool nowext) |
| 192 | { |
| 193 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 194 | |
| 195 | wdev_lock(wdev); |
| 196 | __cfg80211_clear_ibss(dev, nowext); |
| 197 | wdev_unlock(wdev); |
| 198 | } |
| 199 | |
Johannes Berg | 98d3a7c | 2009-11-18 13:03:43 +0100 | [diff] [blame] | 200 | int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev, |
| 201 | struct net_device *dev, bool nowext) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 202 | { |
Johannes Berg | 7848547 | 2009-07-07 03:56:05 +0200 | [diff] [blame] | 203 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 204 | int err; |
| 205 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 206 | ASSERT_WDEV_LOCK(wdev); |
| 207 | |
Johannes Berg | 7848547 | 2009-07-07 03:56:05 +0200 | [diff] [blame] | 208 | if (!wdev->ssid_len) |
| 209 | return -ENOLINK; |
| 210 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 211 | err = rdev_leave_ibss(rdev, dev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 212 | |
| 213 | if (err) |
| 214 | return err; |
| 215 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 216 | __cfg80211_clear_ibss(dev, nowext); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 221 | int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev, |
| 222 | struct net_device *dev, bool nowext) |
| 223 | { |
| 224 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 225 | int err; |
| 226 | |
| 227 | wdev_lock(wdev); |
| 228 | err = __cfg80211_leave_ibss(rdev, dev, nowext); |
| 229 | wdev_unlock(wdev); |
| 230 | |
| 231 | return err; |
| 232 | } |
| 233 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 234 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 235 | int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev, |
| 236 | struct wireless_dev *wdev) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 237 | { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 238 | struct cfg80211_cached_keys *ck = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 239 | enum ieee80211_band band; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 240 | int i, err; |
| 241 | |
| 242 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 243 | |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 244 | if (!wdev->wext.ibss.beacon_interval) |
| 245 | wdev->wext.ibss.beacon_interval = 100; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 246 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 247 | /* try to find an IBSS channel if none requested ... */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 248 | if (!wdev->wext.ibss.chandef.chan) { |
Simon Wunderlich | 1fe4517 | 2013-10-30 16:09:33 +0100 | [diff] [blame] | 249 | struct ieee80211_channel *new_chan = NULL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 250 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 251 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 252 | struct ieee80211_supported_band *sband; |
| 253 | struct ieee80211_channel *chan; |
| 254 | |
| 255 | sband = rdev->wiphy.bands[band]; |
| 256 | if (!sband) |
| 257 | continue; |
| 258 | |
| 259 | for (i = 0; i < sband->n_channels; i++) { |
| 260 | chan = &sband->channels[i]; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 261 | if (chan->flags & IEEE80211_CHAN_NO_IR) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 262 | continue; |
| 263 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 264 | continue; |
Simon Wunderlich | 1fe4517 | 2013-10-30 16:09:33 +0100 | [diff] [blame] | 265 | new_chan = chan; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 266 | break; |
| 267 | } |
| 268 | |
Simon Wunderlich | 1fe4517 | 2013-10-30 16:09:33 +0100 | [diff] [blame] | 269 | if (new_chan) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 270 | break; |
| 271 | } |
| 272 | |
Simon Wunderlich | 1fe4517 | 2013-10-30 16:09:33 +0100 | [diff] [blame] | 273 | if (!new_chan) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 274 | return -EINVAL; |
Simon Wunderlich | 1fe4517 | 2013-10-30 16:09:33 +0100 | [diff] [blame] | 275 | |
| 276 | cfg80211_chandef_create(&wdev->wext.ibss.chandef, new_chan, |
| 277 | NL80211_CHAN_NO_HT); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* don't join -- SSID is not there */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 281 | if (!wdev->wext.ibss.ssid_len) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 282 | return 0; |
| 283 | |
| 284 | if (!netif_running(wdev->netdev)) |
| 285 | return 0; |
| 286 | |
Johannes Berg | 3be61a3 | 2010-07-22 13:59:15 +0200 | [diff] [blame] | 287 | if (wdev->wext.keys) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 288 | wdev->wext.keys->def = wdev->wext.default_key; |
Johannes Berg | 3be61a3 | 2010-07-22 13:59:15 +0200 | [diff] [blame] | 289 | wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key; |
| 290 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 291 | |
| 292 | wdev->wext.ibss.privacy = wdev->wext.default_key != -1; |
| 293 | |
| 294 | if (wdev->wext.keys) { |
| 295 | ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL); |
| 296 | if (!ck) |
| 297 | return -ENOMEM; |
| 298 | for (i = 0; i < 6; i++) |
| 299 | ck->params[i].key = ck->data[i]; |
| 300 | } |
| 301 | err = __cfg80211_join_ibss(rdev, wdev->netdev, |
| 302 | &wdev->wext.ibss, ck); |
| 303 | if (err) |
| 304 | kfree(ck); |
| 305 | |
| 306 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | int cfg80211_ibss_wext_siwfreq(struct net_device *dev, |
| 310 | struct iw_request_info *info, |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 311 | struct iw_freq *wextfreq, char *extra) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 312 | { |
| 313 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 314 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 315 | struct ieee80211_channel *chan = NULL; |
| 316 | int err, freq; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 317 | |
| 318 | /* call only for ibss! */ |
| 319 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 320 | return -EINVAL; |
| 321 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 322 | if (!rdev->ops->join_ibss) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 323 | return -EOPNOTSUPP; |
| 324 | |
Zhao, Gang | 96998e3 | 2014-04-09 09:28:06 +0800 | [diff] [blame] | 325 | freq = cfg80211_wext_freq(wextfreq); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 326 | if (freq < 0) |
| 327 | return freq; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 328 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 329 | if (freq) { |
| 330 | chan = ieee80211_get_channel(wdev->wiphy, freq); |
| 331 | if (!chan) |
| 332 | return -EINVAL; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 333 | if (chan->flags & IEEE80211_CHAN_NO_IR || |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 334 | chan->flags & IEEE80211_CHAN_DISABLED) |
| 335 | return -EINVAL; |
| 336 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 337 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 338 | if (wdev->wext.ibss.chandef.chan == chan) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 339 | return 0; |
| 340 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 341 | wdev_lock(wdev); |
| 342 | err = 0; |
| 343 | if (wdev->ssid_len) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 344 | err = __cfg80211_leave_ibss(rdev, dev, true); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 345 | wdev_unlock(wdev); |
| 346 | |
| 347 | if (err) |
| 348 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 349 | |
| 350 | if (chan) { |
Simon Wunderlich | 1fe4517 | 2013-10-30 16:09:33 +0100 | [diff] [blame] | 351 | cfg80211_chandef_create(&wdev->wext.ibss.chandef, chan, |
| 352 | NL80211_CHAN_NO_HT); |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 353 | wdev->wext.ibss.channel_fixed = true; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 354 | } else { |
| 355 | /* cfg80211_ibss_wext_join will pick one if needed */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 356 | wdev->wext.ibss.channel_fixed = false; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 357 | } |
| 358 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 359 | wdev_lock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 360 | err = cfg80211_ibss_wext_join(rdev, wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 361 | wdev_unlock(wdev); |
| 362 | |
| 363 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 364 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 365 | |
| 366 | int cfg80211_ibss_wext_giwfreq(struct net_device *dev, |
| 367 | struct iw_request_info *info, |
| 368 | struct iw_freq *freq, char *extra) |
| 369 | { |
| 370 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 371 | struct ieee80211_channel *chan = NULL; |
| 372 | |
| 373 | /* call only for ibss! */ |
| 374 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 375 | return -EINVAL; |
| 376 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 377 | wdev_lock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 378 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 379 | chan = wdev->current_bss->pub.channel; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 380 | else if (wdev->wext.ibss.chandef.chan) |
| 381 | chan = wdev->wext.ibss.chandef.chan; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 382 | wdev_unlock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 383 | |
| 384 | if (chan) { |
| 385 | freq->m = chan->center_freq; |
| 386 | freq->e = 6; |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | /* no channel if not joining */ |
| 391 | return -EINVAL; |
| 392 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 393 | |
| 394 | int cfg80211_ibss_wext_siwessid(struct net_device *dev, |
| 395 | struct iw_request_info *info, |
| 396 | struct iw_point *data, char *ssid) |
| 397 | { |
| 398 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 399 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 400 | size_t len = data->length; |
| 401 | int err; |
| 402 | |
| 403 | /* call only for ibss! */ |
| 404 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 405 | return -EINVAL; |
| 406 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 407 | if (!rdev->ops->join_ibss) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 408 | return -EOPNOTSUPP; |
| 409 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 410 | wdev_lock(wdev); |
| 411 | err = 0; |
| 412 | if (wdev->ssid_len) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 413 | err = __cfg80211_leave_ibss(rdev, dev, true); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 414 | wdev_unlock(wdev); |
| 415 | |
| 416 | if (err) |
| 417 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 418 | |
| 419 | /* iwconfig uses nul termination in SSID.. */ |
| 420 | if (len > 0 && ssid[len - 1] == '\0') |
| 421 | len--; |
| 422 | |
Johannes Berg | c1e5f47 | 2014-05-19 17:53:16 +0200 | [diff] [blame] | 423 | memcpy(wdev->ssid, ssid, len); |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 424 | wdev->wext.ibss.ssid = wdev->ssid; |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 425 | wdev->wext.ibss.ssid_len = len; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 426 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 427 | wdev_lock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 428 | err = cfg80211_ibss_wext_join(rdev, wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 429 | wdev_unlock(wdev); |
| 430 | |
| 431 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 432 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 433 | |
| 434 | int cfg80211_ibss_wext_giwessid(struct net_device *dev, |
| 435 | struct iw_request_info *info, |
| 436 | struct iw_point *data, char *ssid) |
| 437 | { |
| 438 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 439 | |
| 440 | /* call only for ibss! */ |
| 441 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 442 | return -EINVAL; |
| 443 | |
| 444 | data->flags = 0; |
| 445 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 446 | wdev_lock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 447 | if (wdev->ssid_len) { |
| 448 | data->flags = 1; |
| 449 | data->length = wdev->ssid_len; |
| 450 | memcpy(ssid, wdev->ssid, data->length); |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 451 | } else if (wdev->wext.ibss.ssid && wdev->wext.ibss.ssid_len) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 452 | data->flags = 1; |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 453 | data->length = wdev->wext.ibss.ssid_len; |
| 454 | memcpy(ssid, wdev->wext.ibss.ssid, data->length); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 455 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 456 | wdev_unlock(wdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 457 | |
| 458 | return 0; |
| 459 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 460 | |
| 461 | int cfg80211_ibss_wext_siwap(struct net_device *dev, |
| 462 | struct iw_request_info *info, |
| 463 | struct sockaddr *ap_addr, char *extra) |
| 464 | { |
| 465 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 466 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 467 | u8 *bssid = ap_addr->sa_data; |
| 468 | int err; |
| 469 | |
| 470 | /* call only for ibss! */ |
| 471 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 472 | return -EINVAL; |
| 473 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 474 | if (!rdev->ops->join_ibss) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 475 | return -EOPNOTSUPP; |
| 476 | |
| 477 | if (ap_addr->sa_family != ARPHRD_ETHER) |
| 478 | return -EINVAL; |
| 479 | |
| 480 | /* automatic mode */ |
| 481 | if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid)) |
| 482 | bssid = NULL; |
| 483 | |
Johannes Berg | 74f8274 | 2014-04-09 22:32:16 +0200 | [diff] [blame] | 484 | if (bssid && !is_valid_ether_addr(bssid)) |
| 485 | return -EINVAL; |
| 486 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 487 | /* both automatic */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 488 | if (!bssid && !wdev->wext.ibss.bssid) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 489 | return 0; |
| 490 | |
| 491 | /* fixed already - and no change */ |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 492 | if (wdev->wext.ibss.bssid && bssid && |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 493 | ether_addr_equal(bssid, wdev->wext.ibss.bssid)) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 494 | return 0; |
| 495 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 496 | wdev_lock(wdev); |
| 497 | err = 0; |
| 498 | if (wdev->ssid_len) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 499 | err = __cfg80211_leave_ibss(rdev, dev, true); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 500 | wdev_unlock(wdev); |
| 501 | |
| 502 | if (err) |
| 503 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 504 | |
| 505 | if (bssid) { |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 506 | memcpy(wdev->wext.bssid, bssid, ETH_ALEN); |
| 507 | wdev->wext.ibss.bssid = wdev->wext.bssid; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 508 | } else |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 509 | wdev->wext.ibss.bssid = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 510 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 511 | wdev_lock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 512 | err = cfg80211_ibss_wext_join(rdev, wdev); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 513 | wdev_unlock(wdev); |
| 514 | |
| 515 | return err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 516 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 517 | |
| 518 | int cfg80211_ibss_wext_giwap(struct net_device *dev, |
| 519 | struct iw_request_info *info, |
| 520 | struct sockaddr *ap_addr, char *extra) |
| 521 | { |
| 522 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 523 | |
| 524 | /* call only for ibss! */ |
| 525 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) |
| 526 | return -EINVAL; |
| 527 | |
| 528 | ap_addr->sa_family = ARPHRD_ETHER; |
| 529 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 530 | wdev_lock(wdev); |
Johannes Berg | 7ebbe6b | 2009-07-01 21:26:48 +0200 | [diff] [blame] | 531 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 532 | memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN); |
Zhu Yi | 80e5b06 | 2009-07-09 16:59:49 +0800 | [diff] [blame] | 533 | else if (wdev->wext.ibss.bssid) |
Johannes Berg | cbe8fa9 | 2009-05-09 20:09:03 +0200 | [diff] [blame] | 534 | memcpy(ap_addr->sa_data, wdev->wext.ibss.bssid, ETH_ALEN); |
Zhu Yi | 80e5b06 | 2009-07-09 16:59:49 +0800 | [diff] [blame] | 535 | else |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 536 | eth_zero_addr(ap_addr->sa_data); |
Zhu Yi | 80e5b06 | 2009-07-09 16:59:49 +0800 | [diff] [blame] | 537 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 538 | wdev_unlock(wdev); |
| 539 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 540 | return 0; |
| 541 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 542 | #endif |