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