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