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