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