Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 2 | /* |
| 3 | * cfg80211 wext compat for managed mode. |
| 4 | * |
| 5 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 6 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 7 | */ |
| 8 | |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 9 | #include <linux/export.h> |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 10 | #include <linux/etherdevice.h> |
| 11 | #include <linux/if_arp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 13 | #include <net/cfg80211.h> |
Johannes Berg | 262eb9b2 | 2011-07-13 10:39:09 +0200 | [diff] [blame] | 14 | #include <net/cfg80211-wext.h> |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 15 | #include "wext-compat.h" |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 16 | #include "nl80211.h" |
| 17 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 18 | int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev, |
| 19 | struct wireless_dev *wdev) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 20 | { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 21 | struct cfg80211_cached_keys *ck = NULL; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 22 | const u8 *prev_bssid = NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 23 | int err, i; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 24 | |
Zhao, Gang | 73fb08e | 2014-03-19 17:04:36 +0800 | [diff] [blame] | 25 | ASSERT_RTNL(); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 26 | ASSERT_WDEV_LOCK(wdev); |
| 27 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 28 | if (!netif_running(wdev->netdev)) |
| 29 | return 0; |
| 30 | |
| 31 | wdev->wext.connect.ie = wdev->wext.ie; |
| 32 | wdev->wext.connect.ie_len = wdev->wext.ie_len; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 33 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 34 | /* Use default background scan period */ |
| 35 | wdev->wext.connect.bg_scan_period = -1; |
| 36 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 37 | if (wdev->wext.keys) { |
| 38 | wdev->wext.keys->def = wdev->wext.default_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 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 46 | if (wdev->wext.keys && wdev->wext.keys->def != -1) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 47 | ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL); |
| 48 | if (!ck) |
| 49 | return -ENOMEM; |
David Spinadel | b867622 | 2016-09-22 23:16:50 +0300 | [diff] [blame] | 50 | for (i = 0; i < CFG80211_MAX_WEP_KEYS; i++) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 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 | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 57 | err = cfg80211_connect(rdev, wdev->netdev, |
| 58 | &wdev->wext.connect, ck, prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 59 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 60 | kzfree(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; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 70 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(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 | |
Zhao, Gang | 96998e3 | 2014-04-09 09:28:06 +0800 | [diff] [blame] | 78 | freq = cfg80211_wext_freq(wextfreq); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 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 | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 90 | wdev_lock(wdev); |
| 91 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 92 | if (wdev->conn) { |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 93 | bool event = true; |
Johannes Berg | 25e83c4 | 2009-07-16 11:39:04 +0200 | [diff] [blame] | 94 | |
| 95 | if (wdev->wext.connect.channel == chan) { |
| 96 | err = 0; |
| 97 | goto out; |
| 98 | } |
| 99 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 100 | /* if SSID set, we'll try right again, avoid event */ |
| 101 | if (wdev->wext.connect.ssid_len) |
| 102 | event = false; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 103 | err = cfg80211_disconnect(rdev, dev, |
| 104 | WLAN_REASON_DEAUTH_LEAVING, event); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 105 | if (err) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 106 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | wdev->wext.connect.channel = chan; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 110 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 111 | out: |
| 112 | wdev_unlock(wdev); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 113 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 114 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 115 | |
| 116 | int cfg80211_mgd_wext_giwfreq(struct net_device *dev, |
| 117 | struct iw_request_info *info, |
| 118 | struct iw_freq *freq, char *extra) |
| 119 | { |
| 120 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 121 | struct ieee80211_channel *chan = NULL; |
| 122 | |
| 123 | /* call only for station! */ |
| 124 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 125 | return -EINVAL; |
| 126 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 127 | wdev_lock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 128 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 129 | chan = wdev->current_bss->pub.channel; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 130 | else if (wdev->wext.connect.channel) |
| 131 | chan = wdev->wext.connect.channel; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 132 | wdev_unlock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 133 | |
| 134 | if (chan) { |
| 135 | freq->m = chan->center_freq; |
| 136 | freq->e = 6; |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | /* no channel if not joining */ |
| 141 | return -EINVAL; |
| 142 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 143 | |
| 144 | int cfg80211_mgd_wext_siwessid(struct net_device *dev, |
| 145 | struct iw_request_info *info, |
| 146 | struct iw_point *data, char *ssid) |
| 147 | { |
| 148 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 149 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 150 | size_t len = data->length; |
| 151 | int err; |
| 152 | |
| 153 | /* call only for station! */ |
| 154 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 155 | return -EINVAL; |
| 156 | |
| 157 | if (!data->flags) |
| 158 | len = 0; |
| 159 | |
| 160 | /* iwconfig uses nul termination in SSID.. */ |
| 161 | if (len > 0 && ssid[len - 1] == '\0') |
| 162 | len--; |
| 163 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 164 | wdev_lock(wdev); |
| 165 | |
| 166 | err = 0; |
| 167 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 168 | if (wdev->conn) { |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 169 | bool event = true; |
Johannes Berg | 25e83c4 | 2009-07-16 11:39:04 +0200 | [diff] [blame] | 170 | |
| 171 | if (wdev->wext.connect.ssid && len && |
| 172 | len == wdev->wext.connect.ssid_len && |
| 173 | memcmp(wdev->wext.connect.ssid, ssid, len) == 0) |
| 174 | goto out; |
| 175 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 176 | /* if SSID set now, we'll try to connect, avoid event */ |
| 177 | if (len) |
| 178 | event = false; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 179 | err = cfg80211_disconnect(rdev, dev, |
| 180 | WLAN_REASON_DEAUTH_LEAVING, event); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 181 | if (err) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 182 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 185 | wdev->wext.prev_bssid_valid = false; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 186 | wdev->wext.connect.ssid = wdev->wext.ssid; |
| 187 | memcpy(wdev->wext.ssid, ssid, len); |
| 188 | wdev->wext.connect.ssid_len = len; |
| 189 | |
| 190 | wdev->wext.connect.crypto.control_port = false; |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 191 | wdev->wext.connect.crypto.control_port_ethertype = |
| 192 | cpu_to_be16(ETH_P_PAE); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 193 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 194 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 195 | out: |
| 196 | wdev_unlock(wdev); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 197 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 198 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 199 | |
| 200 | int cfg80211_mgd_wext_giwessid(struct net_device *dev, |
| 201 | struct iw_request_info *info, |
| 202 | struct iw_point *data, char *ssid) |
| 203 | { |
| 204 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Will Deacon | 63eb9c2 | 2019-10-04 10:51:32 +0100 | [diff] [blame] | 205 | int ret = 0; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 206 | |
| 207 | /* call only for station! */ |
| 208 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 209 | return -EINVAL; |
| 210 | |
| 211 | data->flags = 0; |
| 212 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 213 | wdev_lock(wdev); |
Zhu Yi | a42dd7ef | 2009-08-05 15:07:13 +0800 | [diff] [blame] | 214 | if (wdev->current_bss) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 215 | const u8 *ie; |
| 216 | |
| 217 | rcu_read_lock(); |
| 218 | ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 219 | WLAN_EID_SSID); |
Zhu Yi | a42dd7ef | 2009-08-05 15:07:13 +0800 | [diff] [blame] | 220 | if (ie) { |
| 221 | data->flags = 1; |
| 222 | data->length = ie[1]; |
Will Deacon | 63eb9c2 | 2019-10-04 10:51:32 +0100 | [diff] [blame] | 223 | if (data->length > IW_ESSID_MAX_SIZE) |
| 224 | ret = -EINVAL; |
| 225 | else |
| 226 | memcpy(ssid, ie + 2, data->length); |
Zhu Yi | a42dd7ef | 2009-08-05 15:07:13 +0800 | [diff] [blame] | 227 | } |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 228 | rcu_read_unlock(); |
Zhu Yi | a42dd7ef | 2009-08-05 15:07:13 +0800 | [diff] [blame] | 229 | } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) { |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 230 | data->flags = 1; |
| 231 | data->length = wdev->wext.connect.ssid_len; |
| 232 | memcpy(ssid, wdev->wext.connect.ssid, data->length); |
Johannes Berg | 33de4f9 | 2009-09-17 08:35:54 -0700 | [diff] [blame] | 233 | } |
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 | |
Will Deacon | 63eb9c2 | 2019-10-04 10:51:32 +0100 | [diff] [blame] | 236 | return ret; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 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; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 244 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(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 | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 259 | wdev_lock(wdev); |
| 260 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 261 | if (wdev->conn) { |
Johannes Berg | 25e83c4 | 2009-07-16 11:39:04 +0200 | [diff] [blame] | 262 | err = 0; |
| 263 | /* both automatic */ |
| 264 | if (!bssid && !wdev->wext.connect.bssid) |
| 265 | goto out; |
| 266 | |
| 267 | /* fixed already - and no change */ |
| 268 | if (wdev->wext.connect.bssid && bssid && |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 269 | ether_addr_equal(bssid, wdev->wext.connect.bssid)) |
Johannes Berg | 25e83c4 | 2009-07-16 11:39:04 +0200 | [diff] [blame] | 270 | goto out; |
| 271 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 272 | err = cfg80211_disconnect(rdev, dev, |
| 273 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 274 | if (err) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 275 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | if (bssid) { |
| 279 | memcpy(wdev->wext.bssid, bssid, ETH_ALEN); |
| 280 | wdev->wext.connect.bssid = wdev->wext.bssid; |
| 281 | } else |
| 282 | wdev->wext.connect.bssid = NULL; |
| 283 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 284 | err = cfg80211_mgd_wext_connect(rdev, wdev); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 285 | out: |
| 286 | wdev_unlock(wdev); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 287 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 288 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 289 | |
| 290 | int cfg80211_mgd_wext_giwap(struct net_device *dev, |
| 291 | struct iw_request_info *info, |
| 292 | struct sockaddr *ap_addr, char *extra) |
| 293 | { |
| 294 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 295 | |
| 296 | /* call only for station! */ |
| 297 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 298 | return -EINVAL; |
| 299 | |
| 300 | ap_addr->sa_family = ARPHRD_ETHER; |
| 301 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 302 | wdev_lock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 303 | if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 304 | memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 305 | else |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 306 | eth_zero_addr(ap_addr->sa_data); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 307 | wdev_unlock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 308 | |
| 309 | return 0; |
| 310 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 311 | |
| 312 | int cfg80211_wext_siwgenie(struct net_device *dev, |
| 313 | struct iw_request_info *info, |
| 314 | struct iw_point *data, char *extra) |
| 315 | { |
| 316 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 317 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 318 | u8 *ie = extra; |
| 319 | int ie_len = data->length, err; |
| 320 | |
| 321 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 322 | return -EOPNOTSUPP; |
| 323 | |
| 324 | if (!ie_len) |
| 325 | ie = NULL; |
| 326 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 327 | wdev_lock(wdev); |
| 328 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 329 | /* no change */ |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 330 | err = 0; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 331 | if (wdev->wext.ie_len == ie_len && |
| 332 | memcmp(wdev->wext.ie, ie, ie_len) == 0) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 333 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 334 | |
| 335 | if (ie_len) { |
| 336 | ie = kmemdup(extra, ie_len, GFP_KERNEL); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 337 | if (!ie) { |
| 338 | err = -ENOMEM; |
| 339 | goto out; |
| 340 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 341 | } else |
| 342 | ie = NULL; |
| 343 | |
| 344 | kfree(wdev->wext.ie); |
| 345 | wdev->wext.ie = ie; |
| 346 | wdev->wext.ie_len = ie_len; |
| 347 | |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 348 | if (wdev->conn) { |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 349 | err = cfg80211_disconnect(rdev, dev, |
| 350 | WLAN_REASON_DEAUTH_LEAVING, false); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 351 | if (err) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 352 | goto out; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /* userspace better not think we'll reconnect */ |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 356 | err = 0; |
| 357 | out: |
| 358 | wdev_unlock(wdev); |
| 359 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 360 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 361 | |
| 362 | int cfg80211_wext_siwmlme(struct net_device *dev, |
| 363 | struct iw_request_info *info, |
| 364 | struct iw_point *data, char *extra) |
| 365 | { |
| 366 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 367 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 368 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 369 | int err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 370 | |
| 371 | if (!wdev) |
| 372 | return -EOPNOTSUPP; |
| 373 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 374 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 375 | |
| 376 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 377 | return -EINVAL; |
| 378 | |
| 379 | if (mlme->addr.sa_family != ARPHRD_ETHER) |
| 380 | return -EINVAL; |
| 381 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 382 | wdev_lock(wdev); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 383 | switch (mlme->cmd) { |
| 384 | case IW_MLME_DEAUTH: |
| 385 | case IW_MLME_DISASSOC: |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 386 | err = cfg80211_disconnect(rdev, dev, mlme->reason_code, true); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 387 | break; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 388 | default: |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 389 | err = -EOPNOTSUPP; |
| 390 | break; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 391 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 392 | wdev_unlock(wdev); |
| 393 | |
| 394 | return err; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 395 | } |