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