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