Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * SME code for cfg80211's connect emulation. |
| 3 | * |
| 4 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 5 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/etherdevice.h> |
| 9 | #include <linux/if_arp.h> |
| 10 | #include <linux/workqueue.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 11 | #include <linux/wireless.h> |
| 12 | #include <net/iw_handler.h> |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13 | #include <net/cfg80211.h> |
| 14 | #include <net/rtnetlink.h> |
| 15 | #include "nl80211.h" |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 16 | #include "reg.h" |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 17 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 18 | struct cfg80211_conn { |
| 19 | struct cfg80211_connect_params params; |
| 20 | /* these are sub-states of the _CONNECTING sme_state */ |
| 21 | enum { |
| 22 | CFG80211_CONN_IDLE, |
| 23 | CFG80211_CONN_SCANNING, |
| 24 | CFG80211_CONN_SCAN_AGAIN, |
| 25 | CFG80211_CONN_AUTHENTICATE_NEXT, |
| 26 | CFG80211_CONN_AUTHENTICATING, |
| 27 | CFG80211_CONN_ASSOCIATE_NEXT, |
| 28 | CFG80211_CONN_ASSOCIATING, |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 29 | CFG80211_CONN_DEAUTH_ASSOC_FAIL, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 30 | } state; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 31 | u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN]; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 32 | u8 *ie; |
| 33 | size_t ie_len; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 34 | bool auto_auth, prev_bssid_valid; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | |
| 38 | static int cfg80211_conn_scan(struct wireless_dev *wdev) |
| 39 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 40 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 41 | struct cfg80211_scan_request *request; |
| 42 | int n_channels, err; |
| 43 | |
| 44 | ASSERT_RTNL(); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 45 | ASSERT_RDEV_LOCK(rdev); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 46 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 47 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 48 | if (rdev->scan_req) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 49 | return -EBUSY; |
| 50 | |
| 51 | if (wdev->conn->params.channel) { |
| 52 | n_channels = 1; |
| 53 | } else { |
| 54 | enum ieee80211_band band; |
| 55 | n_channels = 0; |
| 56 | |
| 57 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 58 | if (!wdev->wiphy->bands[band]) |
| 59 | continue; |
| 60 | n_channels += wdev->wiphy->bands[band]->n_channels; |
| 61 | } |
| 62 | } |
| 63 | request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) + |
| 64 | sizeof(request->channels[0]) * n_channels, |
| 65 | GFP_KERNEL); |
| 66 | if (!request) |
| 67 | return -ENOMEM; |
| 68 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 69 | if (wdev->conn->params.channel) |
| 70 | request->channels[0] = wdev->conn->params.channel; |
| 71 | else { |
| 72 | int i = 0, j; |
| 73 | enum ieee80211_band band; |
| 74 | |
| 75 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 76 | if (!wdev->wiphy->bands[band]) |
| 77 | continue; |
| 78 | for (j = 0; j < wdev->wiphy->bands[band]->n_channels; |
| 79 | i++, j++) |
| 80 | request->channels[i] = |
| 81 | &wdev->wiphy->bands[band]->channels[j]; |
| 82 | } |
| 83 | } |
| 84 | request->n_channels = n_channels; |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 85 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 86 | request->n_ssids = 1; |
| 87 | |
| 88 | memcpy(request->ssids[0].ssid, wdev->conn->params.ssid, |
| 89 | wdev->conn->params.ssid_len); |
| 90 | request->ssids[0].ssid_len = wdev->conn->params.ssid_len; |
| 91 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 92 | request->dev = wdev->netdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 93 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 94 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 95 | rdev->scan_req = request; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 96 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 97 | err = rdev->ops->scan(wdev->wiphy, wdev->netdev, request); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 98 | if (!err) { |
| 99 | wdev->conn->state = CFG80211_CONN_SCANNING; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 100 | nl80211_send_scan_start(rdev, wdev->netdev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 101 | dev_hold(wdev->netdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 102 | } else { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 103 | rdev->scan_req = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 104 | kfree(request); |
| 105 | } |
| 106 | return err; |
| 107 | } |
| 108 | |
| 109 | static int cfg80211_conn_do_work(struct wireless_dev *wdev) |
| 110 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 111 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 112 | struct cfg80211_connect_params *params; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 113 | const u8 *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 114 | int err; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 115 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 116 | ASSERT_WDEV_LOCK(wdev); |
| 117 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 118 | if (!wdev->conn) |
| 119 | return 0; |
| 120 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 121 | params = &wdev->conn->params; |
| 122 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 123 | switch (wdev->conn->state) { |
| 124 | case CFG80211_CONN_SCAN_AGAIN: |
| 125 | return cfg80211_conn_scan(wdev); |
| 126 | case CFG80211_CONN_AUTHENTICATE_NEXT: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 127 | BUG_ON(!rdev->ops->auth); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 128 | wdev->conn->state = CFG80211_CONN_AUTHENTICATING; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 129 | return __cfg80211_mlme_auth(rdev, wdev->netdev, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 130 | params->channel, params->auth_type, |
| 131 | params->bssid, |
| 132 | params->ssid, params->ssid_len, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 133 | NULL, 0, |
| 134 | params->key, params->key_len, |
| 135 | params->key_idx); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 136 | case CFG80211_CONN_ASSOCIATE_NEXT: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 137 | BUG_ON(!rdev->ops->assoc); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 138 | wdev->conn->state = CFG80211_CONN_ASSOCIATING; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 139 | if (wdev->conn->prev_bssid_valid) |
| 140 | prev_bssid = wdev->conn->prev_bssid; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 141 | err = __cfg80211_mlme_assoc(rdev, wdev->netdev, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 142 | params->channel, params->bssid, |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 143 | prev_bssid, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 144 | params->ssid, params->ssid_len, |
| 145 | params->ie, params->ie_len, |
| 146 | false, ¶ms->crypto); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 147 | if (err) |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 148 | __cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 149 | NULL, 0, |
| 150 | WLAN_REASON_DEAUTH_LEAVING); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 151 | return err; |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 152 | case CFG80211_CONN_DEAUTH_ASSOC_FAIL: |
| 153 | __cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, |
| 154 | NULL, 0, |
| 155 | WLAN_REASON_DEAUTH_LEAVING); |
| 156 | /* return an error so that we call __cfg80211_connect_result() */ |
| 157 | return -EINVAL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 158 | default: |
| 159 | return 0; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void cfg80211_conn_work(struct work_struct *work) |
| 164 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 165 | struct cfg80211_registered_device *rdev = |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 166 | container_of(work, struct cfg80211_registered_device, conn_work); |
| 167 | struct wireless_dev *wdev; |
Johannes Berg | 7400f42 | 2009-10-31 07:40:37 +0100 | [diff] [blame] | 168 | u8 bssid_buf[ETH_ALEN], *bssid = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 169 | |
| 170 | rtnl_lock(); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 171 | cfg80211_lock_rdev(rdev); |
| 172 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 173 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 174 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 175 | wdev_lock(wdev); |
| 176 | if (!netif_running(wdev->netdev)) { |
| 177 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 178 | continue; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 179 | } |
| 180 | if (wdev->sme_state != CFG80211_SME_CONNECTING) { |
| 181 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 182 | continue; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 183 | } |
Johannes Berg | 7400f42 | 2009-10-31 07:40:37 +0100 | [diff] [blame] | 184 | if (wdev->conn->params.bssid) { |
| 185 | memcpy(bssid_buf, wdev->conn->params.bssid, ETH_ALEN); |
| 186 | bssid = bssid_buf; |
| 187 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 188 | if (cfg80211_conn_do_work(wdev)) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 189 | __cfg80211_connect_result( |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 190 | wdev->netdev, bssid, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 191 | NULL, 0, NULL, 0, |
| 192 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 193 | false, NULL); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 194 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 195 | } |
| 196 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 197 | mutex_unlock(&rdev->devlist_mtx); |
| 198 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 199 | rtnl_unlock(); |
| 200 | } |
| 201 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 202 | static struct cfg80211_bss *cfg80211_get_conn_bss(struct wireless_dev *wdev) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 203 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 204 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 205 | struct cfg80211_bss *bss; |
| 206 | u16 capa = WLAN_CAPABILITY_ESS; |
| 207 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 208 | ASSERT_WDEV_LOCK(wdev); |
| 209 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 210 | if (wdev->conn->params.privacy) |
| 211 | capa |= WLAN_CAPABILITY_PRIVACY; |
| 212 | |
| 213 | bss = cfg80211_get_bss(wdev->wiphy, NULL, wdev->conn->params.bssid, |
| 214 | wdev->conn->params.ssid, |
| 215 | wdev->conn->params.ssid_len, |
| 216 | WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY, |
| 217 | capa); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 218 | if (!bss) |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 219 | return NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 220 | |
| 221 | memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN); |
| 222 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 223 | wdev->conn->params.channel = bss->channel; |
| 224 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 225 | schedule_work(&rdev->conn_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 226 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 227 | return bss; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 228 | } |
| 229 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 230 | static void __cfg80211_sme_scan_done(struct net_device *dev) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 231 | { |
| 232 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 233 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 234 | struct cfg80211_bss *bss; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 235 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 236 | ASSERT_WDEV_LOCK(wdev); |
| 237 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 238 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
| 239 | return; |
| 240 | |
Zhu Yi | d4b1a68 | 2009-07-16 17:34:14 +0800 | [diff] [blame] | 241 | if (!wdev->conn) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 242 | return; |
| 243 | |
| 244 | if (wdev->conn->state != CFG80211_CONN_SCANNING && |
| 245 | wdev->conn->state != CFG80211_CONN_SCAN_AGAIN) |
| 246 | return; |
| 247 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 248 | bss = cfg80211_get_conn_bss(wdev); |
| 249 | if (bss) { |
| 250 | cfg80211_put_bss(bss); |
| 251 | } else { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 252 | /* not found */ |
| 253 | if (wdev->conn->state == CFG80211_CONN_SCAN_AGAIN) |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 254 | schedule_work(&rdev->conn_work); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 255 | else |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 256 | __cfg80211_connect_result( |
| 257 | wdev->netdev, |
| 258 | wdev->conn->params.bssid, |
| 259 | NULL, 0, NULL, 0, |
| 260 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 261 | false, NULL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 265 | void cfg80211_sme_scan_done(struct net_device *dev) |
| 266 | { |
| 267 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 268 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 269 | mutex_lock(&wiphy_to_dev(wdev->wiphy)->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 270 | wdev_lock(wdev); |
| 271 | __cfg80211_sme_scan_done(dev); |
| 272 | wdev_unlock(wdev); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 273 | mutex_unlock(&wiphy_to_dev(wdev->wiphy)->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | void cfg80211_sme_rx_auth(struct net_device *dev, |
| 277 | const u8 *buf, size_t len) |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 278 | { |
| 279 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 280 | struct wiphy *wiphy = wdev->wiphy; |
| 281 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 282 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 283 | u16 status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 284 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 285 | ASSERT_WDEV_LOCK(wdev); |
| 286 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 287 | /* should only RX auth frames when connecting */ |
| 288 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
| 289 | return; |
| 290 | |
| 291 | if (WARN_ON(!wdev->conn)) |
| 292 | return; |
| 293 | |
| 294 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG && |
| 295 | wdev->conn->auto_auth && |
| 296 | wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) { |
| 297 | /* select automatically between only open, shared, leap */ |
| 298 | switch (wdev->conn->params.auth_type) { |
| 299 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 300 | if (wdev->connect_keys) |
| 301 | wdev->conn->params.auth_type = |
| 302 | NL80211_AUTHTYPE_SHARED_KEY; |
| 303 | else |
| 304 | wdev->conn->params.auth_type = |
| 305 | NL80211_AUTHTYPE_NETWORK_EAP; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 306 | break; |
| 307 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 308 | wdev->conn->params.auth_type = |
| 309 | NL80211_AUTHTYPE_NETWORK_EAP; |
| 310 | break; |
| 311 | default: |
| 312 | /* huh? */ |
| 313 | wdev->conn->params.auth_type = |
| 314 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 315 | break; |
| 316 | } |
| 317 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 318 | schedule_work(&rdev->conn_work); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 319 | } else if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | 4bde0f7 | 2009-07-07 23:46:51 +0200 | [diff] [blame] | 320 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 321 | status_code, false, NULL); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 322 | } else if (wdev->sme_state == CFG80211_SME_CONNECTING && |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 323 | wdev->conn->state == CFG80211_CONN_AUTHENTICATING) { |
| 324 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 325 | schedule_work(&rdev->conn_work); |
| 326 | } |
| 327 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 328 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 329 | bool cfg80211_sme_failed_reassoc(struct wireless_dev *wdev) |
| 330 | { |
| 331 | struct wiphy *wiphy = wdev->wiphy; |
| 332 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 333 | |
| 334 | if (WARN_ON(!wdev->conn)) |
| 335 | return false; |
| 336 | |
| 337 | if (!wdev->conn->prev_bssid_valid) |
| 338 | return false; |
| 339 | |
| 340 | /* |
| 341 | * Some stupid APs don't accept reassoc, so we |
| 342 | * need to fall back to trying regular assoc. |
| 343 | */ |
| 344 | wdev->conn->prev_bssid_valid = false; |
| 345 | wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT; |
| 346 | schedule_work(&rdev->conn_work); |
| 347 | |
| 348 | return true; |
| 349 | } |
| 350 | |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 351 | void cfg80211_sme_failed_assoc(struct wireless_dev *wdev) |
| 352 | { |
| 353 | struct wiphy *wiphy = wdev->wiphy; |
| 354 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 355 | |
| 356 | wdev->conn->state = CFG80211_CONN_DEAUTH_ASSOC_FAIL; |
| 357 | schedule_work(&rdev->conn_work); |
| 358 | } |
| 359 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 360 | void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 361 | const u8 *req_ie, size_t req_ie_len, |
| 362 | const u8 *resp_ie, size_t resp_ie_len, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 363 | u16 status, bool wextev, |
| 364 | struct cfg80211_bss *bss) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 365 | { |
| 366 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 367 | u8 *country_ie; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 368 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 369 | union iwreq_data wrqu; |
| 370 | #endif |
| 371 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 372 | ASSERT_WDEV_LOCK(wdev); |
| 373 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 374 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 375 | return; |
| 376 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 377 | if (wdev->sme_state != CFG80211_SME_CONNECTING) |
Johannes Berg | ea416a7 | 2009-08-17 12:22:14 +0200 | [diff] [blame] | 378 | return; |
| 379 | |
| 380 | nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev, |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 381 | bssid, req_ie, req_ie_len, |
Johannes Berg | ea416a7 | 2009-08-17 12:22:14 +0200 | [diff] [blame] | 382 | resp_ie, resp_ie_len, |
| 383 | status, GFP_KERNEL); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 384 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 385 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 386 | if (wextev) { |
| 387 | if (req_ie && status == WLAN_STATUS_SUCCESS) { |
| 388 | memset(&wrqu, 0, sizeof(wrqu)); |
| 389 | wrqu.data.length = req_ie_len; |
Zhu Yi | 3409ff7 | 2009-07-20 11:47:44 +0800 | [diff] [blame] | 390 | wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, req_ie); |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | if (resp_ie && status == WLAN_STATUS_SUCCESS) { |
| 394 | memset(&wrqu, 0, sizeof(wrqu)); |
| 395 | wrqu.data.length = resp_ie_len; |
| 396 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie); |
| 397 | } |
| 398 | |
| 399 | memset(&wrqu, 0, sizeof(wrqu)); |
| 400 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 401 | if (bssid && status == WLAN_STATUS_SUCCESS) { |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 402 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 403 | memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN); |
| 404 | wdev->wext.prev_bssid_valid = true; |
| 405 | } |
Johannes Berg | e45cd82 | 2009-07-02 09:58:04 +0200 | [diff] [blame] | 406 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 407 | } |
| 408 | #endif |
| 409 | |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 410 | if (wdev->current_bss) { |
| 411 | cfg80211_unhold_bss(wdev->current_bss); |
| 412 | cfg80211_put_bss(&wdev->current_bss->pub); |
| 413 | wdev->current_bss = NULL; |
| 414 | } |
| 415 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 416 | if (wdev->conn) |
| 417 | wdev->conn->state = CFG80211_CONN_IDLE; |
| 418 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 419 | if (status != WLAN_STATUS_SUCCESS) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 420 | wdev->sme_state = CFG80211_SME_IDLE; |
David Kilroy | 415ad1ef | 2009-08-19 00:43:31 +0100 | [diff] [blame] | 421 | if (wdev->conn) |
| 422 | kfree(wdev->conn->ie); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 423 | kfree(wdev->conn); |
| 424 | wdev->conn = NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 425 | kfree(wdev->connect_keys); |
| 426 | wdev->connect_keys = NULL; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 427 | wdev->ssid_len = 0; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 428 | return; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 429 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 430 | |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 431 | if (!bss) |
| 432 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
| 433 | wdev->ssid, wdev->ssid_len, |
| 434 | WLAN_CAPABILITY_ESS, |
| 435 | WLAN_CAPABILITY_ESS); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 436 | |
| 437 | if (WARN_ON(!bss)) |
| 438 | return; |
| 439 | |
| 440 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 441 | wdev->current_bss = bss_from_pub(bss); |
| 442 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 443 | wdev->sme_state = CFG80211_SME_CONNECTED; |
| 444 | cfg80211_upload_connect_keys(wdev); |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 445 | |
| 446 | country_ie = (u8 *) ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY); |
| 447 | |
| 448 | if (!country_ie) |
| 449 | return; |
| 450 | |
| 451 | /* |
| 452 | * ieee80211_bss_get_ie() ensures we can access: |
| 453 | * - country_ie + 2, the start of the country ie data, and |
| 454 | * - and country_ie[1] which is the IE length |
| 455 | */ |
| 456 | regulatory_hint_11d(wdev->wiphy, |
Luis R. Rodriguez | 84920e3 | 2010-01-14 20:08:20 -0500 | [diff] [blame] | 457 | bss->channel->band, |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 458 | country_ie + 2, |
| 459 | country_ie[1]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 460 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 461 | |
| 462 | void cfg80211_connect_result(struct net_device *dev, const u8 *bssid, |
| 463 | const u8 *req_ie, size_t req_ie_len, |
| 464 | const u8 *resp_ie, size_t resp_ie_len, |
| 465 | u16 status, gfp_t gfp) |
| 466 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 467 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 468 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 469 | struct cfg80211_event *ev; |
| 470 | unsigned long flags; |
| 471 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 472 | CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTING); |
| 473 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 474 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 475 | if (!ev) |
| 476 | return; |
| 477 | |
| 478 | ev->type = EVENT_CONNECT_RESULT; |
Zhu Yi | 16a832e | 2009-08-19 16:08:22 +0800 | [diff] [blame] | 479 | if (bssid) |
| 480 | memcpy(ev->cr.bssid, bssid, ETH_ALEN); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 481 | ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 482 | ev->cr.req_ie_len = req_ie_len; |
| 483 | memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len); |
| 484 | ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 485 | ev->cr.resp_ie_len = resp_ie_len; |
| 486 | memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len); |
| 487 | ev->cr.status = status; |
| 488 | |
| 489 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 490 | list_add_tail(&ev->list, &wdev->event_list); |
| 491 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 492 | queue_work(cfg80211_wq, &rdev->event_work); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 493 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 494 | EXPORT_SYMBOL(cfg80211_connect_result); |
| 495 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 496 | void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid, |
| 497 | const u8 *req_ie, size_t req_ie_len, |
| 498 | const u8 *resp_ie, size_t resp_ie_len) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 499 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 500 | struct cfg80211_bss *bss; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 501 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 502 | union iwreq_data wrqu; |
| 503 | #endif |
| 504 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 505 | ASSERT_WDEV_LOCK(wdev); |
| 506 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 507 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 508 | return; |
| 509 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 510 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 511 | return; |
| 512 | |
| 513 | /* internal error -- how did we get to CONNECTED w/o BSS? */ |
| 514 | if (WARN_ON(!wdev->current_bss)) { |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 519 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 520 | wdev->current_bss = NULL; |
| 521 | |
| 522 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
| 523 | wdev->ssid, wdev->ssid_len, |
| 524 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
| 525 | |
| 526 | if (WARN_ON(!bss)) |
| 527 | return; |
| 528 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 529 | cfg80211_hold_bss(bss_from_pub(bss)); |
| 530 | wdev->current_bss = bss_from_pub(bss); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 531 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 532 | nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), wdev->netdev, bssid, |
| 533 | req_ie, req_ie_len, resp_ie, resp_ie_len, |
| 534 | GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 535 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 536 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 537 | if (req_ie) { |
| 538 | memset(&wrqu, 0, sizeof(wrqu)); |
| 539 | wrqu.data.length = req_ie_len; |
Zhu Yi | 3409ff7 | 2009-07-20 11:47:44 +0800 | [diff] [blame] | 540 | wireless_send_event(wdev->netdev, IWEVASSOCREQIE, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 541 | &wrqu, req_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | if (resp_ie) { |
| 545 | memset(&wrqu, 0, sizeof(wrqu)); |
| 546 | wrqu.data.length = resp_ie_len; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 547 | wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, |
| 548 | &wrqu, resp_ie); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | memset(&wrqu, 0, sizeof(wrqu)); |
| 552 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 553 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 554 | memcpy(wdev->wext.prev_bssid, bssid, ETH_ALEN); |
| 555 | wdev->wext.prev_bssid_valid = true; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 556 | wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 557 | #endif |
| 558 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 559 | |
| 560 | void cfg80211_roamed(struct net_device *dev, const u8 *bssid, |
| 561 | const u8 *req_ie, size_t req_ie_len, |
| 562 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 563 | { |
| 564 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 565 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 566 | struct cfg80211_event *ev; |
| 567 | unsigned long flags; |
| 568 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 569 | CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED); |
| 570 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 571 | ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); |
| 572 | if (!ev) |
| 573 | return; |
| 574 | |
| 575 | ev->type = EVENT_ROAMED; |
| 576 | memcpy(ev->rm.bssid, bssid, ETH_ALEN); |
| 577 | ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev); |
| 578 | ev->rm.req_ie_len = req_ie_len; |
| 579 | memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len); |
| 580 | ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; |
| 581 | ev->rm.resp_ie_len = resp_ie_len; |
| 582 | memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len); |
| 583 | |
| 584 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 585 | list_add_tail(&ev->list, &wdev->event_list); |
| 586 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 587 | queue_work(cfg80211_wq, &rdev->event_work); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 588 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 589 | EXPORT_SYMBOL(cfg80211_roamed); |
| 590 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 591 | void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 592 | size_t ie_len, u16 reason, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 593 | { |
| 594 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 595 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 596 | int i; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 597 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 598 | union iwreq_data wrqu; |
| 599 | #endif |
| 600 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 601 | ASSERT_WDEV_LOCK(wdev); |
| 602 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 603 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) |
| 604 | return; |
| 605 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 606 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 607 | return; |
| 608 | |
| 609 | if (wdev->current_bss) { |
| 610 | cfg80211_unhold_bss(wdev->current_bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 611 | cfg80211_put_bss(&wdev->current_bss->pub); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | wdev->current_bss = NULL; |
| 615 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 616 | wdev->ssid_len = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 617 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 618 | if (wdev->conn) { |
Johannes Berg | b6f0b63 | 2009-08-06 20:41:34 +0200 | [diff] [blame] | 619 | const u8 *bssid; |
| 620 | int ret; |
| 621 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 622 | kfree(wdev->conn->ie); |
| 623 | wdev->conn->ie = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 624 | kfree(wdev->conn); |
| 625 | wdev->conn = NULL; |
Johannes Berg | b6f0b63 | 2009-08-06 20:41:34 +0200 | [diff] [blame] | 626 | |
| 627 | /* |
| 628 | * If this disconnect was due to a disassoc, we |
| 629 | * we might still have an auth BSS around. For |
| 630 | * the userspace SME that's currently expected, |
| 631 | * but for the kernel SME (nl80211 CONNECT or |
| 632 | * wireless extensions) we want to clear up all |
| 633 | * state. |
| 634 | */ |
| 635 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 636 | if (!wdev->auth_bsses[i]) |
| 637 | continue; |
| 638 | bssid = wdev->auth_bsses[i]->pub.bssid; |
| 639 | ret = __cfg80211_mlme_deauth(rdev, dev, bssid, NULL, 0, |
| 640 | WLAN_REASON_DEAUTH_LEAVING); |
| 641 | WARN(ret, "deauth failed: %d\n", ret); |
| 642 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 643 | } |
| 644 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 645 | nl80211_send_disconnected(rdev, dev, reason, ie, ie_len, from_ap); |
| 646 | |
| 647 | /* |
| 648 | * Delete all the keys ... pairwise keys can't really |
| 649 | * exist any more anyway, but default keys might. |
| 650 | */ |
| 651 | if (rdev->ops->del_key) |
| 652 | for (i = 0; i < 6; i++) |
| 653 | rdev->ops->del_key(wdev->wiphy, dev, i, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 654 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 655 | #ifdef CONFIG_CFG80211_WEXT |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 656 | memset(&wrqu, 0, sizeof(wrqu)); |
| 657 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 658 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
Abhijeet Kolekar | 5f61203 | 2010-01-13 13:23:14 -0800 | [diff] [blame] | 659 | wdev->wext.connect.ssid_len = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 660 | #endif |
| 661 | } |
| 662 | |
| 663 | void cfg80211_disconnected(struct net_device *dev, u16 reason, |
| 664 | u8 *ie, size_t ie_len, gfp_t gfp) |
| 665 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 666 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 667 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 668 | struct cfg80211_event *ev; |
| 669 | unsigned long flags; |
| 670 | |
Johannes Berg | f796996 | 2009-08-21 12:23:49 +0200 | [diff] [blame] | 671 | CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED); |
| 672 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 673 | ev = kzalloc(sizeof(*ev) + ie_len, gfp); |
| 674 | if (!ev) |
| 675 | return; |
| 676 | |
| 677 | ev->type = EVENT_DISCONNECTED; |
| 678 | ev->dc.ie = ((u8 *)ev) + sizeof(*ev); |
| 679 | ev->dc.ie_len = ie_len; |
| 680 | memcpy((void *)ev->dc.ie, ie, ie_len); |
| 681 | ev->dc.reason = reason; |
| 682 | |
| 683 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 684 | list_add_tail(&ev->list, &wdev->event_list); |
| 685 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 686 | queue_work(cfg80211_wq, &rdev->event_work); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 687 | } |
| 688 | EXPORT_SYMBOL(cfg80211_disconnected); |
| 689 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 690 | int __cfg80211_connect(struct cfg80211_registered_device *rdev, |
| 691 | struct net_device *dev, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 692 | struct cfg80211_connect_params *connect, |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 693 | struct cfg80211_cached_keys *connkeys, |
| 694 | const u8 *prev_bssid) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 695 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 696 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 697 | struct ieee80211_channel *chan; |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 698 | struct cfg80211_bss *bss = NULL; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 699 | int err; |
| 700 | |
| 701 | ASSERT_WDEV_LOCK(wdev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 702 | |
| 703 | if (wdev->sme_state != CFG80211_SME_IDLE) |
| 704 | return -EALREADY; |
| 705 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 706 | chan = rdev_fixed_channel(rdev, wdev); |
| 707 | if (chan && chan != connect->channel) |
| 708 | return -EBUSY; |
| 709 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 710 | if (WARN_ON(wdev->connect_keys)) { |
| 711 | kfree(wdev->connect_keys); |
| 712 | wdev->connect_keys = NULL; |
| 713 | } |
| 714 | |
| 715 | if (connkeys && connkeys->def >= 0) { |
| 716 | int idx; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 717 | u32 cipher; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 718 | |
| 719 | idx = connkeys->def; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 720 | cipher = connkeys->params[idx].cipher; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 721 | /* If given a WEP key we may need it for shared key auth */ |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 722 | if (cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 723 | cipher == WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 724 | connect->key_idx = idx; |
| 725 | connect->key = connkeys->params[idx].key; |
| 726 | connect->key_len = connkeys->params[idx].key_len; |
Samuel Ortiz | bcba8ea | 2009-08-06 21:04:41 +0200 | [diff] [blame] | 727 | |
| 728 | /* |
| 729 | * If ciphers are not set (e.g. when going through |
| 730 | * iwconfig), we have to set them appropriately here. |
| 731 | */ |
| 732 | if (connect->crypto.cipher_group == 0) |
| 733 | connect->crypto.cipher_group = cipher; |
| 734 | |
| 735 | if (connect->crypto.n_ciphers_pairwise == 0) { |
| 736 | connect->crypto.n_ciphers_pairwise = 1; |
| 737 | connect->crypto.ciphers_pairwise[0] = cipher; |
| 738 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 742 | if (!rdev->ops->connect) { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 743 | if (!rdev->ops->auth || !rdev->ops->assoc) |
| 744 | return -EOPNOTSUPP; |
| 745 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 746 | if (WARN_ON(wdev->conn)) |
| 747 | return -EINPROGRESS; |
| 748 | |
| 749 | wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL); |
| 750 | if (!wdev->conn) |
| 751 | return -ENOMEM; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 752 | |
| 753 | /* |
| 754 | * Copy all parameters, and treat explicitly IEs, BSSID, SSID. |
| 755 | */ |
| 756 | memcpy(&wdev->conn->params, connect, sizeof(*connect)); |
| 757 | if (connect->bssid) { |
| 758 | wdev->conn->params.bssid = wdev->conn->bssid; |
| 759 | memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN); |
| 760 | } |
| 761 | |
| 762 | if (connect->ie) { |
| 763 | wdev->conn->ie = kmemdup(connect->ie, connect->ie_len, |
| 764 | GFP_KERNEL); |
| 765 | wdev->conn->params.ie = wdev->conn->ie; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 766 | if (!wdev->conn->ie) { |
| 767 | kfree(wdev->conn); |
| 768 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 769 | return -ENOMEM; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 770 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) { |
| 774 | wdev->conn->auto_auth = true; |
| 775 | /* start with open system ... should mostly work */ |
| 776 | wdev->conn->params.auth_type = |
| 777 | NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 778 | } else { |
| 779 | wdev->conn->auto_auth = false; |
| 780 | } |
| 781 | |
| 782 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); |
| 783 | wdev->ssid_len = connect->ssid_len; |
| 784 | wdev->conn->params.ssid = wdev->ssid; |
| 785 | wdev->conn->params.ssid_len = connect->ssid_len; |
| 786 | |
Johannes Berg | 8bb8948 | 2009-09-26 14:42:53 +0200 | [diff] [blame] | 787 | /* see if we have the bss already */ |
| 788 | bss = cfg80211_get_conn_bss(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 789 | |
| 790 | wdev->sme_state = CFG80211_SME_CONNECTING; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 791 | wdev->connect_keys = connkeys; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 792 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 793 | if (prev_bssid) { |
| 794 | memcpy(wdev->conn->prev_bssid, prev_bssid, ETH_ALEN); |
| 795 | wdev->conn->prev_bssid_valid = true; |
| 796 | } |
| 797 | |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 798 | /* we're good if we have a matching bss struct */ |
| 799 | if (bss) { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 800 | wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT; |
| 801 | err = cfg80211_conn_do_work(wdev); |
Johannes Berg | bbac31f | 2009-09-16 09:04:26 -0700 | [diff] [blame] | 802 | cfg80211_put_bss(bss); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 803 | } else { |
| 804 | /* otherwise we'll need to scan for the AP first */ |
| 805 | err = cfg80211_conn_scan(wdev); |
| 806 | /* |
| 807 | * If we can't scan right now, then we need to scan again |
| 808 | * after the current scan finished, since the parameters |
| 809 | * changed (unless we find a good AP anyway). |
| 810 | */ |
| 811 | if (err == -EBUSY) { |
| 812 | err = 0; |
| 813 | wdev->conn->state = CFG80211_CONN_SCAN_AGAIN; |
| 814 | } |
| 815 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 816 | if (err) { |
David Kilroy | 415ad1ef | 2009-08-19 00:43:31 +0100 | [diff] [blame] | 817 | kfree(wdev->conn->ie); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 818 | kfree(wdev->conn); |
| 819 | wdev->conn = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 820 | wdev->sme_state = CFG80211_SME_IDLE; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 821 | wdev->connect_keys = NULL; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 822 | wdev->ssid_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 823 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 824 | |
| 825 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 826 | } else { |
| 827 | wdev->sme_state = CFG80211_SME_CONNECTING; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 828 | wdev->connect_keys = connkeys; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 829 | err = rdev->ops->connect(&rdev->wiphy, dev, connect); |
| 830 | if (err) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 831 | wdev->connect_keys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 832 | wdev->sme_state = CFG80211_SME_IDLE; |
| 833 | return err; |
| 834 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 835 | |
| 836 | memcpy(wdev->ssid, connect->ssid, connect->ssid_len); |
| 837 | wdev->ssid_len = connect->ssid_len; |
| 838 | |
| 839 | return 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 840 | } |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 841 | } |
| 842 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 843 | int cfg80211_connect(struct cfg80211_registered_device *rdev, |
| 844 | struct net_device *dev, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 845 | struct cfg80211_connect_params *connect, |
| 846 | struct cfg80211_cached_keys *connkeys) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 847 | { |
| 848 | int err; |
| 849 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 850 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 851 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 852 | err = __cfg80211_connect(rdev, dev, connect, connkeys, NULL); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 853 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 854 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 855 | |
| 856 | return err; |
| 857 | } |
| 858 | |
| 859 | int __cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
| 860 | struct net_device *dev, u16 reason, bool wextev) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 861 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 862 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 863 | int err; |
| 864 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 865 | ASSERT_WDEV_LOCK(wdev); |
| 866 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 867 | if (wdev->sme_state == CFG80211_SME_IDLE) |
| 868 | return -EINVAL; |
| 869 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 870 | kfree(wdev->connect_keys); |
| 871 | wdev->connect_keys = NULL; |
| 872 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 873 | if (!rdev->ops->disconnect) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 874 | if (!rdev->ops->deauth) |
| 875 | return -EOPNOTSUPP; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 876 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 877 | /* was it connected by userspace SME? */ |
| 878 | if (!wdev->conn) { |
| 879 | cfg80211_mlme_down(rdev, dev); |
| 880 | return 0; |
| 881 | } |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 882 | |
| 883 | if (wdev->sme_state == CFG80211_SME_CONNECTING && |
| 884 | (wdev->conn->state == CFG80211_CONN_SCANNING || |
| 885 | wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)) { |
| 886 | wdev->sme_state = CFG80211_SME_IDLE; |
David Kilroy | 415ad1ef | 2009-08-19 00:43:31 +0100 | [diff] [blame] | 887 | kfree(wdev->conn->ie); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 888 | kfree(wdev->conn); |
| 889 | wdev->conn = NULL; |
Johannes Berg | 8dadadb | 2009-08-04 09:32:23 +0200 | [diff] [blame] | 890 | wdev->ssid_len = 0; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 891 | return 0; |
| 892 | } |
| 893 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 894 | /* wdev->conn->params.bssid must be set if > SCANNING */ |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 895 | err = __cfg80211_mlme_deauth(rdev, dev, |
| 896 | wdev->conn->params.bssid, |
| 897 | NULL, 0, reason); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 898 | if (err) |
| 899 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 900 | } else { |
| 901 | err = rdev->ops->disconnect(&rdev->wiphy, dev, reason); |
| 902 | if (err) |
| 903 | return err; |
| 904 | } |
| 905 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 906 | if (wdev->sme_state == CFG80211_SME_CONNECTED) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 907 | __cfg80211_disconnected(dev, NULL, 0, 0, false); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 908 | else if (wdev->sme_state == CFG80211_SME_CONNECTING) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 909 | __cfg80211_connect_result(dev, NULL, NULL, 0, NULL, 0, |
| 910 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 911 | wextev, NULL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 912 | |
| 913 | return 0; |
| 914 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 915 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 916 | int cfg80211_disconnect(struct cfg80211_registered_device *rdev, |
| 917 | struct net_device *dev, |
| 918 | u16 reason, bool wextev) |
| 919 | { |
| 920 | int err; |
| 921 | |
| 922 | wdev_lock(dev->ieee80211_ptr); |
| 923 | err = __cfg80211_disconnect(rdev, dev, reason, wextev); |
| 924 | wdev_unlock(dev->ieee80211_ptr); |
| 925 | |
| 926 | return err; |
| 927 | } |
| 928 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 929 | void cfg80211_sme_disassoc(struct net_device *dev, int idx) |
| 930 | { |
| 931 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 932 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 933 | u8 bssid[ETH_ALEN]; |
| 934 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 935 | ASSERT_WDEV_LOCK(wdev); |
| 936 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 937 | if (!wdev->conn) |
| 938 | return; |
| 939 | |
| 940 | if (wdev->conn->state == CFG80211_CONN_IDLE) |
| 941 | return; |
| 942 | |
| 943 | /* |
| 944 | * Ok, so the association was made by this SME -- we don't |
| 945 | * want it any more so deauthenticate too. |
| 946 | */ |
| 947 | |
| 948 | if (!wdev->auth_bsses[idx]) |
| 949 | return; |
| 950 | |
| 951 | memcpy(bssid, wdev->auth_bsses[idx]->pub.bssid, ETH_ALEN); |
Johannes Berg | ec3f149 | 2009-07-10 02:45:38 +0200 | [diff] [blame] | 952 | if (__cfg80211_mlme_deauth(rdev, dev, bssid, |
| 953 | NULL, 0, WLAN_REASON_DEAUTH_LEAVING)) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 954 | /* whatever -- assume gone anyway */ |
| 955 | cfg80211_unhold_bss(wdev->auth_bsses[idx]); |
| 956 | cfg80211_put_bss(&wdev->auth_bsses[idx]->pub); |
| 957 | wdev->auth_bsses[idx] = NULL; |
| 958 | } |
| 959 | } |