Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * cfg80211 wext compat for managed mode. |
| 3 | * |
| 4 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 5 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 6 | */ |
| 7 | |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 8 | #include <linux/export.h> |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 9 | #include <linux/etherdevice.h> |
| 10 | #include <linux/if_arp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 12 | #include <net/cfg80211.h> |
Johannes Berg | 262eb9b2 | 2011-07-13 10:39:09 +0200 | [diff] [blame] | 13 | #include <net/cfg80211-wext.h> |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 14 | #include "wext-compat.h" |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 15 | #include "nl80211.h" |
| 16 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 17 | int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev, |
| 18 | struct wireless_dev *wdev) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 19 | { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 20 | struct cfg80211_cached_keys *ck = NULL; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 21 | const u8 *prev_bssid = NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 22 | int err, i; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 23 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 24 | ASSERT_RDEV_LOCK(rdev); |
| 25 | ASSERT_WDEV_LOCK(wdev); |
| 26 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 27 | if (!netif_running(wdev->netdev)) |
| 28 | return 0; |
| 29 | |
| 30 | wdev->wext.connect.ie = wdev->wext.ie; |
| 31 | wdev->wext.connect.ie_len = wdev->wext.ie_len; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 32 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 33 | /* Use default background scan period */ |
| 34 | wdev->wext.connect.bg_scan_period = -1; |
| 35 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 36 | if (wdev->wext.keys) { |
| 37 | wdev->wext.keys->def = wdev->wext.default_key; |
| 38 | wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key; |
Johannes Berg | 4be3bd8 | 2009-09-24 09:00:57 +0200 | [diff] [blame] | 39 | if (wdev->wext.default_key != -1) |
| 40 | wdev->wext.connect.privacy = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | if (!wdev->wext.connect.ssid_len) |
| 44 | return 0; |
| 45 | |
| 46 | if (wdev->wext.keys) { |
| 47 | ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL); |
| 48 | if (!ck) |
| 49 | return -ENOMEM; |
| 50 | for (i = 0; i < 6; i++) |
| 51 | ck->params[i].key = ck->data[i]; |
| 52 | } |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 53 | |
| 54 | if (wdev->wext.prev_bssid_valid) |
| 55 | prev_bssid = wdev->wext.prev_bssid; |
| 56 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 57 | err = __cfg80211_connect(rdev, wdev->netdev, |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 58 | &wdev->wext.connect, ck, prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 59 | if (err) |
| 60 | kfree(ck); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 61 | |
| 62 | return err; |
| 63 | } |
| 64 | |
| 65 | int cfg80211_mgd_wext_siwfreq(struct net_device *dev, |
| 66 | struct iw_request_info *info, |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 67 | struct iw_freq *wextfreq, char *extra) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 68 | { |
| 69 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 70 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 71 | struct ieee80211_channel *chan = NULL; |
| 72 | int err, freq; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 73 | |
| 74 | /* call only for station! */ |
| 75 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 76 | return -EINVAL; |
| 77 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 78 | freq = cfg80211_wext_freq(wdev->wiphy, wextfreq); |
| 79 | if (freq < 0) |
| 80 | return freq; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 81 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 82 | if (freq) { |
| 83 | chan = ieee80211_get_channel(wdev->wiphy, freq); |
| 84 | if (!chan) |
| 85 | return -EINVAL; |
| 86 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 87 | return -EINVAL; |
| 88 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 89 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 90 | cfg80211_lock_rdev(rdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 91 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 92 | wdev_lock(wdev); |
| 93 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 94 | if (wdev->sme_state != CFG80211_SME_IDLE) { |
| 95 | bool event = true; |
Johannes Berg | 25e83c4 | 2009-07-16 11:39:04 +0200 | [diff] [blame] | 96 | |
| 97 | if (wdev->wext.connect.channel == chan) { |
| 98 | err = 0; |
| 99 | goto out; |
| 100 | } |
| 101 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 102 | /* if SSID set, we'll try right again, avoid event */ |
| 103 | if (wdev->wext.connect.ssid_len) |
| 104 | event = false; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 105 | err = __cfg80211_disconnect(rdev, dev, |
| 106 | WLAN_REASON_DEAUTH_LEAVING, event); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 107 | if (err) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 108 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 111 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 112 | wdev->wext.connect.channel = chan; |
| 113 | |
| 114 | /* SSID is not set, we just want to switch channel */ |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 115 | if (chan && !wdev->wext.connect.ssid_len) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 116 | err = cfg80211_set_freq(rdev, wdev, freq, NL80211_CHAN_NO_HT); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 117 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 120 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 121 | out: |
| 122 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 123 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 124 | cfg80211_unlock_rdev(rdev); |
| 125 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 126 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 127 | |
| 128 | int cfg80211_mgd_wext_giwfreq(struct net_device *dev, |
| 129 | struct iw_request_info *info, |
| 130 | struct iw_freq *freq, char *extra) |
| 131 | { |
| 132 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 133 | struct ieee80211_channel *chan = NULL; |
| 134 | |
| 135 | /* call only for station! */ |
| 136 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 137 | return -EINVAL; |
| 138 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 139 | wdev_lock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 140 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 141 | chan = wdev->current_bss->pub.channel; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 142 | else if (wdev->wext.connect.channel) |
| 143 | chan = wdev->wext.connect.channel; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 144 | wdev_unlock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 145 | |
| 146 | if (chan) { |
| 147 | freq->m = chan->center_freq; |
| 148 | freq->e = 6; |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | /* no channel if not joining */ |
| 153 | return -EINVAL; |
| 154 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 155 | |
| 156 | int cfg80211_mgd_wext_siwessid(struct net_device *dev, |
| 157 | struct iw_request_info *info, |
| 158 | struct iw_point *data, char *ssid) |
| 159 | { |
| 160 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 161 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 162 | size_t len = data->length; |
| 163 | int err; |
| 164 | |
| 165 | /* call only for station! */ |
| 166 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 167 | return -EINVAL; |
| 168 | |
| 169 | if (!data->flags) |
| 170 | len = 0; |
| 171 | |
| 172 | /* iwconfig uses nul termination in SSID.. */ |
| 173 | if (len > 0 && ssid[len - 1] == '\0') |
| 174 | len--; |
| 175 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 176 | cfg80211_lock_rdev(rdev); |
| 177 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 178 | wdev_lock(wdev); |
| 179 | |
| 180 | err = 0; |
| 181 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 182 | if (wdev->sme_state != CFG80211_SME_IDLE) { |
| 183 | bool event = true; |
Johannes Berg | 25e83c4 | 2009-07-16 11:39:04 +0200 | [diff] [blame] | 184 | |
| 185 | if (wdev->wext.connect.ssid && len && |
| 186 | len == wdev->wext.connect.ssid_len && |
| 187 | memcmp(wdev->wext.connect.ssid, ssid, len) == 0) |
| 188 | goto out; |
| 189 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 190 | /* if SSID set now, we'll try to connect, avoid event */ |
| 191 | if (len) |
| 192 | event = false; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 193 | err = __cfg80211_disconnect(rdev, dev, |
| 194 | WLAN_REASON_DEAUTH_LEAVING, event); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 195 | if (err) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 196 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 197 | } |
| 198 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 199 | wdev->wext.prev_bssid_valid = false; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 200 | wdev->wext.connect.ssid = wdev->wext.ssid; |
| 201 | memcpy(wdev->wext.ssid, ssid, len); |
| 202 | wdev->wext.connect.ssid_len = len; |
| 203 | |
| 204 | wdev->wext.connect.crypto.control_port = false; |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 205 | wdev->wext.connect.crypto.control_port_ethertype = |
| 206 | cpu_to_be16(ETH_P_PAE); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 207 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 208 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 209 | out: |
| 210 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 211 | mutex_unlock(&rdev->devlist_mtx); |
| 212 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 213 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 214 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 215 | |
| 216 | int cfg80211_mgd_wext_giwessid(struct net_device *dev, |
| 217 | struct iw_request_info *info, |
| 218 | struct iw_point *data, char *ssid) |
| 219 | { |
| 220 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 221 | |
| 222 | /* call only for station! */ |
| 223 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 224 | return -EINVAL; |
| 225 | |
| 226 | data->flags = 0; |
| 227 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 228 | wdev_lock(wdev); |
Zhu Yi | a42dd7ef | 2009-08-05 15:07:13 +0800 | [diff] [blame] | 229 | if (wdev->current_bss) { |
| 230 | const u8 *ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 231 | WLAN_EID_SSID); |
| 232 | if (ie) { |
| 233 | data->flags = 1; |
| 234 | data->length = ie[1]; |
| 235 | memcpy(ssid, ie + 2, data->length); |
| 236 | } |
| 237 | } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) { |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 238 | data->flags = 1; |
| 239 | data->length = wdev->wext.connect.ssid_len; |
| 240 | memcpy(ssid, wdev->wext.connect.ssid, data->length); |
Johannes Berg | 33de4f9 | 2009-09-17 08:35:54 -0700 | [diff] [blame] | 241 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 242 | wdev_unlock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 243 | |
| 244 | return 0; |
| 245 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 246 | |
| 247 | int cfg80211_mgd_wext_siwap(struct net_device *dev, |
| 248 | struct iw_request_info *info, |
| 249 | struct sockaddr *ap_addr, char *extra) |
| 250 | { |
| 251 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 252 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 253 | u8 *bssid = ap_addr->sa_data; |
| 254 | int err; |
| 255 | |
| 256 | /* call only for station! */ |
| 257 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 258 | return -EINVAL; |
| 259 | |
| 260 | if (ap_addr->sa_family != ARPHRD_ETHER) |
| 261 | return -EINVAL; |
| 262 | |
| 263 | /* automatic mode */ |
| 264 | if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid)) |
| 265 | bssid = NULL; |
| 266 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 267 | cfg80211_lock_rdev(rdev); |
| 268 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 269 | wdev_lock(wdev); |
| 270 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 271 | if (wdev->sme_state != CFG80211_SME_IDLE) { |
Johannes Berg | 25e83c4 | 2009-07-16 11:39:04 +0200 | [diff] [blame] | 272 | err = 0; |
| 273 | /* both automatic */ |
| 274 | if (!bssid && !wdev->wext.connect.bssid) |
| 275 | goto out; |
| 276 | |
| 277 | /* fixed already - and no change */ |
| 278 | if (wdev->wext.connect.bssid && bssid && |
| 279 | compare_ether_addr(bssid, wdev->wext.connect.bssid) == 0) |
| 280 | goto out; |
| 281 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 282 | err = __cfg80211_disconnect(rdev, dev, |
| 283 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 284 | if (err) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 285 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | if (bssid) { |
| 289 | memcpy(wdev->wext.bssid, bssid, ETH_ALEN); |
| 290 | wdev->wext.connect.bssid = wdev->wext.bssid; |
| 291 | } else |
| 292 | wdev->wext.connect.bssid = NULL; |
| 293 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 294 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 295 | out: |
| 296 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 297 | mutex_unlock(&rdev->devlist_mtx); |
| 298 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 299 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 300 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 301 | |
| 302 | int cfg80211_mgd_wext_giwap(struct net_device *dev, |
| 303 | struct iw_request_info *info, |
| 304 | struct sockaddr *ap_addr, char *extra) |
| 305 | { |
| 306 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 307 | |
| 308 | /* call only for station! */ |
| 309 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 310 | return -EINVAL; |
| 311 | |
| 312 | ap_addr->sa_family = ARPHRD_ETHER; |
| 313 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 314 | wdev_lock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 315 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 316 | memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 317 | else |
| 318 | memset(ap_addr->sa_data, 0, ETH_ALEN); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 319 | wdev_unlock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 320 | |
| 321 | return 0; |
| 322 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 323 | |
| 324 | int cfg80211_wext_siwgenie(struct net_device *dev, |
| 325 | struct iw_request_info *info, |
| 326 | struct iw_point *data, char *extra) |
| 327 | { |
| 328 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 329 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 330 | u8 *ie = extra; |
| 331 | int ie_len = data->length, err; |
| 332 | |
| 333 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 334 | return -EOPNOTSUPP; |
| 335 | |
| 336 | if (!ie_len) |
| 337 | ie = NULL; |
| 338 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 339 | wdev_lock(wdev); |
| 340 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 341 | /* no change */ |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 342 | err = 0; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 343 | if (wdev->wext.ie_len == ie_len && |
| 344 | memcmp(wdev->wext.ie, ie, ie_len) == 0) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 345 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 346 | |
| 347 | if (ie_len) { |
| 348 | ie = kmemdup(extra, ie_len, GFP_KERNEL); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 349 | if (!ie) { |
| 350 | err = -ENOMEM; |
| 351 | goto out; |
| 352 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 353 | } else |
| 354 | ie = NULL; |
| 355 | |
| 356 | kfree(wdev->wext.ie); |
| 357 | wdev->wext.ie = ie; |
| 358 | wdev->wext.ie_len = ie_len; |
| 359 | |
| 360 | if (wdev->sme_state != CFG80211_SME_IDLE) { |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 361 | err = __cfg80211_disconnect(rdev, dev, |
| 362 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 363 | if (err) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 364 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /* userspace better not think we'll reconnect */ |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 368 | err = 0; |
| 369 | out: |
| 370 | wdev_unlock(wdev); |
| 371 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 372 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 373 | |
| 374 | int cfg80211_wext_siwmlme(struct net_device *dev, |
| 375 | struct iw_request_info *info, |
| 376 | struct iw_point *data, char *extra) |
| 377 | { |
| 378 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 379 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 380 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 381 | int err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 382 | |
| 383 | if (!wdev) |
| 384 | return -EOPNOTSUPP; |
| 385 | |
| 386 | rdev = wiphy_to_dev(wdev->wiphy); |
| 387 | |
| 388 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 389 | return -EINVAL; |
| 390 | |
| 391 | if (mlme->addr.sa_family != ARPHRD_ETHER) |
| 392 | return -EINVAL; |
| 393 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 394 | wdev_lock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 395 | switch (mlme->cmd) { |
| 396 | case IW_MLME_DEAUTH: |
| 397 | case IW_MLME_DISASSOC: |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 398 | err = __cfg80211_disconnect(rdev, dev, mlme->reason_code, |
| 399 | true); |
| 400 | break; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 401 | default: |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 402 | err = -EOPNOTSUPP; |
| 403 | break; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 404 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 405 | wdev_unlock(wdev); |
| 406 | |
| 407 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 408 | } |