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