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