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