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 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 114 | /* |
| 115 | * SSID is not set, we just want to switch monitor channel, |
| 116 | * this is really just backward compatibility, if the SSID |
| 117 | * is set then we use the channel to select the BSS to use |
| 118 | * to connect to instead. If we were connected on another |
| 119 | * channel we disconnected above and reconnect below. |
| 120 | */ |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 121 | if (chan && !wdev->wext.connect.ssid_len) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 122 | struct cfg80211_chan_def chandef = { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 123 | .width = NL80211_CHAN_WIDTH_20_NOHT, |
| 124 | .center_freq1 = freq, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq); |
| 128 | if (chandef.chan) |
| 129 | err = cfg80211_set_monitor_channel(rdev, &chandef); |
| 130 | else |
| 131 | err = -EINVAL; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 132 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 135 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 136 | out: |
| 137 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 138 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 139 | cfg80211_unlock_rdev(rdev); |
| 140 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 141 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 142 | |
| 143 | int cfg80211_mgd_wext_giwfreq(struct net_device *dev, |
| 144 | struct iw_request_info *info, |
| 145 | struct iw_freq *freq, char *extra) |
| 146 | { |
| 147 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 148 | struct ieee80211_channel *chan = NULL; |
| 149 | |
| 150 | /* call only for station! */ |
| 151 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 152 | return -EINVAL; |
| 153 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 154 | wdev_lock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 155 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 156 | chan = wdev->current_bss->pub.channel; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 157 | else if (wdev->wext.connect.channel) |
| 158 | chan = wdev->wext.connect.channel; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 159 | wdev_unlock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 160 | |
| 161 | if (chan) { |
| 162 | freq->m = chan->center_freq; |
| 163 | freq->e = 6; |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | /* no channel if not joining */ |
| 168 | return -EINVAL; |
| 169 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 170 | |
| 171 | int cfg80211_mgd_wext_siwessid(struct net_device *dev, |
| 172 | struct iw_request_info *info, |
| 173 | struct iw_point *data, char *ssid) |
| 174 | { |
| 175 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 176 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 177 | size_t len = data->length; |
| 178 | int err; |
| 179 | |
| 180 | /* call only for station! */ |
| 181 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 182 | return -EINVAL; |
| 183 | |
| 184 | if (!data->flags) |
| 185 | len = 0; |
| 186 | |
| 187 | /* iwconfig uses nul termination in SSID.. */ |
| 188 | if (len > 0 && ssid[len - 1] == '\0') |
| 189 | len--; |
| 190 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 191 | cfg80211_lock_rdev(rdev); |
| 192 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 193 | wdev_lock(wdev); |
| 194 | |
| 195 | err = 0; |
| 196 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 197 | if (wdev->sme_state != CFG80211_SME_IDLE) { |
| 198 | bool event = true; |
Johannes Berg | 25e83c4 | 2009-07-16 11:39:04 +0200 | [diff] [blame] | 199 | |
| 200 | if (wdev->wext.connect.ssid && len && |
| 201 | len == wdev->wext.connect.ssid_len && |
| 202 | memcmp(wdev->wext.connect.ssid, ssid, len) == 0) |
| 203 | goto out; |
| 204 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 205 | /* if SSID set now, we'll try to connect, avoid event */ |
| 206 | if (len) |
| 207 | event = false; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 208 | err = __cfg80211_disconnect(rdev, dev, |
| 209 | WLAN_REASON_DEAUTH_LEAVING, event); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 210 | if (err) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 211 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 212 | } |
| 213 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 214 | wdev->wext.prev_bssid_valid = false; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 215 | wdev->wext.connect.ssid = wdev->wext.ssid; |
| 216 | memcpy(wdev->wext.ssid, ssid, len); |
| 217 | wdev->wext.connect.ssid_len = len; |
| 218 | |
| 219 | wdev->wext.connect.crypto.control_port = false; |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 220 | wdev->wext.connect.crypto.control_port_ethertype = |
| 221 | cpu_to_be16(ETH_P_PAE); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 222 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 223 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 224 | out: |
| 225 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 226 | mutex_unlock(&rdev->devlist_mtx); |
| 227 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 228 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 229 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 230 | |
| 231 | int cfg80211_mgd_wext_giwessid(struct net_device *dev, |
| 232 | struct iw_request_info *info, |
| 233 | struct iw_point *data, char *ssid) |
| 234 | { |
| 235 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 236 | |
| 237 | /* call only for station! */ |
| 238 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 239 | return -EINVAL; |
| 240 | |
| 241 | data->flags = 0; |
| 242 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 243 | wdev_lock(wdev); |
Zhu Yi | a42dd7ef | 2009-08-05 15:07:13 +0800 | [diff] [blame] | 244 | if (wdev->current_bss) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 245 | const u8 *ie; |
| 246 | |
| 247 | rcu_read_lock(); |
| 248 | ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 249 | WLAN_EID_SSID); |
Zhu Yi | a42dd7ef | 2009-08-05 15:07:13 +0800 | [diff] [blame] | 250 | if (ie) { |
| 251 | data->flags = 1; |
| 252 | data->length = ie[1]; |
| 253 | memcpy(ssid, ie + 2, data->length); |
| 254 | } |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 255 | rcu_read_unlock(); |
Zhu Yi | a42dd7ef | 2009-08-05 15:07:13 +0800 | [diff] [blame] | 256 | } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) { |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 257 | data->flags = 1; |
| 258 | data->length = wdev->wext.connect.ssid_len; |
| 259 | memcpy(ssid, wdev->wext.connect.ssid, data->length); |
Johannes Berg | 33de4f9 | 2009-09-17 08:35:54 -0700 | [diff] [blame] | 260 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 261 | wdev_unlock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 262 | |
| 263 | return 0; |
| 264 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 265 | |
| 266 | int cfg80211_mgd_wext_siwap(struct net_device *dev, |
| 267 | struct iw_request_info *info, |
| 268 | struct sockaddr *ap_addr, char *extra) |
| 269 | { |
| 270 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 271 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 272 | u8 *bssid = ap_addr->sa_data; |
| 273 | int err; |
| 274 | |
| 275 | /* call only for station! */ |
| 276 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 277 | return -EINVAL; |
| 278 | |
| 279 | if (ap_addr->sa_family != ARPHRD_ETHER) |
| 280 | return -EINVAL; |
| 281 | |
| 282 | /* automatic mode */ |
| 283 | if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid)) |
| 284 | bssid = NULL; |
| 285 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 286 | cfg80211_lock_rdev(rdev); |
| 287 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 288 | wdev_lock(wdev); |
| 289 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 290 | if (wdev->sme_state != CFG80211_SME_IDLE) { |
Johannes Berg | 25e83c4 | 2009-07-16 11:39:04 +0200 | [diff] [blame] | 291 | err = 0; |
| 292 | /* both automatic */ |
| 293 | if (!bssid && !wdev->wext.connect.bssid) |
| 294 | goto out; |
| 295 | |
| 296 | /* fixed already - and no change */ |
| 297 | if (wdev->wext.connect.bssid && bssid && |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 298 | ether_addr_equal(bssid, wdev->wext.connect.bssid)) |
Johannes Berg | 25e83c4 | 2009-07-16 11:39:04 +0200 | [diff] [blame] | 299 | goto out; |
| 300 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 301 | err = __cfg80211_disconnect(rdev, dev, |
| 302 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 303 | if (err) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 304 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | if (bssid) { |
| 308 | memcpy(wdev->wext.bssid, bssid, ETH_ALEN); |
| 309 | wdev->wext.connect.bssid = wdev->wext.bssid; |
| 310 | } else |
| 311 | wdev->wext.connect.bssid = NULL; |
| 312 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 313 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 314 | out: |
| 315 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 316 | mutex_unlock(&rdev->devlist_mtx); |
| 317 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 318 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 319 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 320 | |
| 321 | int cfg80211_mgd_wext_giwap(struct net_device *dev, |
| 322 | struct iw_request_info *info, |
| 323 | struct sockaddr *ap_addr, char *extra) |
| 324 | { |
| 325 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 326 | |
| 327 | /* call only for station! */ |
| 328 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 329 | return -EINVAL; |
| 330 | |
| 331 | ap_addr->sa_family = ARPHRD_ETHER; |
| 332 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 333 | wdev_lock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 334 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 335 | memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 336 | else |
| 337 | memset(ap_addr->sa_data, 0, ETH_ALEN); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 338 | wdev_unlock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 339 | |
| 340 | return 0; |
| 341 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 342 | |
| 343 | int cfg80211_wext_siwgenie(struct net_device *dev, |
| 344 | struct iw_request_info *info, |
| 345 | struct iw_point *data, char *extra) |
| 346 | { |
| 347 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 348 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 349 | u8 *ie = extra; |
| 350 | int ie_len = data->length, err; |
| 351 | |
| 352 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 353 | return -EOPNOTSUPP; |
| 354 | |
| 355 | if (!ie_len) |
| 356 | ie = NULL; |
| 357 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 358 | wdev_lock(wdev); |
| 359 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 360 | /* no change */ |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 361 | err = 0; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 362 | if (wdev->wext.ie_len == ie_len && |
| 363 | memcmp(wdev->wext.ie, ie, ie_len) == 0) |
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 | if (ie_len) { |
| 367 | ie = kmemdup(extra, ie_len, GFP_KERNEL); |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 368 | if (!ie) { |
| 369 | err = -ENOMEM; |
| 370 | goto out; |
| 371 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 372 | } else |
| 373 | ie = NULL; |
| 374 | |
| 375 | kfree(wdev->wext.ie); |
| 376 | wdev->wext.ie = ie; |
| 377 | wdev->wext.ie_len = ie_len; |
| 378 | |
| 379 | if (wdev->sme_state != CFG80211_SME_IDLE) { |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 380 | err = __cfg80211_disconnect(rdev, dev, |
| 381 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 382 | if (err) |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 383 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /* userspace better not think we'll reconnect */ |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 387 | err = 0; |
| 388 | out: |
| 389 | wdev_unlock(wdev); |
| 390 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 391 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 392 | |
| 393 | int cfg80211_wext_siwmlme(struct net_device *dev, |
| 394 | struct iw_request_info *info, |
| 395 | struct iw_point *data, char *extra) |
| 396 | { |
| 397 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 398 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 399 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 400 | int err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 401 | |
| 402 | if (!wdev) |
| 403 | return -EOPNOTSUPP; |
| 404 | |
| 405 | rdev = wiphy_to_dev(wdev->wiphy); |
| 406 | |
| 407 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 408 | return -EINVAL; |
| 409 | |
| 410 | if (mlme->addr.sa_family != ARPHRD_ETHER) |
| 411 | return -EINVAL; |
| 412 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 413 | wdev_lock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 414 | switch (mlme->cmd) { |
| 415 | case IW_MLME_DEAUTH: |
| 416 | case IW_MLME_DISASSOC: |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 417 | err = __cfg80211_disconnect(rdev, dev, mlme->reason_code, |
| 418 | true); |
| 419 | break; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 420 | default: |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 421 | err = -EOPNOTSUPP; |
| 422 | break; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 423 | } |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 424 | wdev_unlock(wdev); |
| 425 | |
| 426 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 427 | } |