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