Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /* Copyright (C) 2006, Red Hat, Inc. */ |
| 2 | |
| 3 | #include <linux/bitops.h> |
| 4 | #include <net/ieee80211.h> |
| 5 | |
| 6 | #include "assoc.h" |
| 7 | #include "join.h" |
| 8 | #include "decl.h" |
| 9 | #include "hostcmd.h" |
| 10 | #include "host.h" |
| 11 | |
| 12 | |
| 13 | static const u8 bssid_any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
| 14 | static const u8 bssid_off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 15 | |
| 16 | static int assoc_helper_essid(wlan_private *priv, |
| 17 | struct assoc_request * assoc_req) |
| 18 | { |
| 19 | wlan_adapter *adapter = priv->adapter; |
| 20 | int ret = 0; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 21 | struct bss_descriptor * bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 22 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 23 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 24 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 25 | lbs_deb_assoc("New SSID requested: %s\n", assoc_req->ssid.ssid); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 26 | if (assoc_req->mode == IW_MODE_INFRA) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 27 | if (adapter->prescan) { |
| 28 | libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 1); |
| 29 | } |
| 30 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 31 | bss = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 32 | NULL, IW_MODE_INFRA); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 33 | if (bss != NULL) { |
| 34 | lbs_deb_assoc("SSID found in scan list, associating\n"); |
| 35 | ret = wlan_associate(priv, bss); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 36 | if (ret == 0) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 37 | memcpy(&assoc_req->bssid, bss->bssid, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 38 | } |
| 39 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 40 | lbs_deb_assoc("SSID '%s' not found; cannot associate\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 41 | assoc_req->ssid.ssid); |
| 42 | } |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 43 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 44 | /* Scan for the network, do not save previous results. Stale |
| 45 | * scan data will cause us to join a non-existant adhoc network |
| 46 | */ |
| 47 | libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 0); |
| 48 | |
| 49 | /* Search for the requested SSID in the scan table */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 50 | bss = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL, |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 51 | IW_MODE_ADHOC); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 52 | if (bss != NULL) { |
| 53 | lbs_deb_assoc("SSID found joining\n"); |
| 54 | libertas_join_adhoc_network(priv, bss); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 55 | } else { |
| 56 | /* else send START command */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 57 | lbs_deb_assoc("SSID not found in list, so creating adhoc" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 58 | " with SSID '%s'\n", assoc_req->ssid.ssid); |
| 59 | libertas_start_adhoc_network(priv, &assoc_req->ssid); |
| 60 | } |
| 61 | memcpy(&assoc_req->bssid, &adapter->current_addr, ETH_ALEN); |
| 62 | } |
| 63 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 64 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | static int assoc_helper_bssid(wlan_private *priv, |
| 70 | struct assoc_request * assoc_req) |
| 71 | { |
| 72 | wlan_adapter *adapter = priv->adapter; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 73 | int ret = 0; |
| 74 | struct bss_descriptor * bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 75 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 76 | lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID" MAC_FMT "\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 77 | MAC_ARG(assoc_req->bssid)); |
| 78 | |
| 79 | /* Search for index position in list for requested MAC */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 80 | bss = libertas_find_BSSID_in_list(adapter, assoc_req->bssid, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 81 | assoc_req->mode); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 82 | if (bss == NULL) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 83 | lbs_deb_assoc("ASSOC: WAP: BSSID " MAC_FMT " not found, " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 84 | "cannot associate.\n", MAC_ARG(assoc_req->bssid)); |
| 85 | goto out; |
| 86 | } |
| 87 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 88 | if (assoc_req->mode == IW_MODE_INFRA) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 89 | ret = wlan_associate(priv, bss); |
| 90 | lbs_deb_assoc("ASSOC: wlan_associate(bssid) returned %d\n", ret); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 91 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 92 | libertas_join_adhoc_network(priv, bss); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 93 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame^] | 94 | memcpy(&assoc_req->ssid, &bss->ssid, sizeof(struct WLAN_802_11_SSID)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 95 | |
| 96 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 97 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | static int assoc_helper_associate(wlan_private *priv, |
| 103 | struct assoc_request * assoc_req) |
| 104 | { |
| 105 | int ret = 0, done = 0; |
| 106 | |
| 107 | /* If we're given and 'any' BSSID, try associating based on SSID */ |
| 108 | |
| 109 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
| 110 | if (memcmp(bssid_any, assoc_req->bssid, ETH_ALEN) |
| 111 | && memcmp(bssid_off, assoc_req->bssid, ETH_ALEN)) { |
| 112 | ret = assoc_helper_bssid(priv, assoc_req); |
| 113 | done = 1; |
| 114 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 115 | lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 121 | ret = assoc_helper_essid(priv, assoc_req); |
| 122 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 123 | lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | static int assoc_helper_mode(wlan_private *priv, |
| 132 | struct assoc_request * assoc_req) |
| 133 | { |
| 134 | wlan_adapter *adapter = priv->adapter; |
| 135 | int ret = 0; |
| 136 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 137 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 138 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 139 | if (assoc_req->mode == adapter->mode) |
| 140 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 141 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 142 | if (assoc_req->mode == IW_MODE_INFRA) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 143 | if (adapter->psstate != PS_STATE_FULL_POWER) |
| 144 | libertas_ps_wakeup(priv, cmd_option_waitforrsp); |
| 145 | adapter->psmode = wlan802_11powermodecam; |
| 146 | } |
| 147 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 148 | adapter->mode = assoc_req->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 149 | ret = libertas_prepare_and_send_command(priv, |
| 150 | cmd_802_11_snmp_mib, |
| 151 | 0, cmd_option_waitforrsp, |
| 152 | OID_802_11_INFRASTRUCTURE_MODE, |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 153 | (void *) (size_t) assoc_req->mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 154 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 155 | done: |
| 156 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | static int assoc_helper_wep_keys(wlan_private *priv, |
| 162 | struct assoc_request * assoc_req) |
| 163 | { |
| 164 | wlan_adapter *adapter = priv->adapter; |
| 165 | int i; |
| 166 | int ret = 0; |
| 167 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 168 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 169 | |
| 170 | /* Set or remove WEP keys */ |
| 171 | if ( assoc_req->wep_keys[0].len |
| 172 | || assoc_req->wep_keys[1].len |
| 173 | || assoc_req->wep_keys[2].len |
| 174 | || assoc_req->wep_keys[3].len) { |
| 175 | ret = libertas_prepare_and_send_command(priv, |
| 176 | cmd_802_11_set_wep, |
| 177 | cmd_act_add, |
| 178 | cmd_option_waitforrsp, |
| 179 | 0, assoc_req); |
| 180 | } else { |
| 181 | ret = libertas_prepare_and_send_command(priv, |
| 182 | cmd_802_11_set_wep, |
| 183 | cmd_act_remove, |
| 184 | cmd_option_waitforrsp, |
| 185 | 0, NULL); |
| 186 | } |
| 187 | |
| 188 | if (ret) |
| 189 | goto out; |
| 190 | |
| 191 | /* enable/disable the MAC's WEP packet filter */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 192 | if (assoc_req->secinfo.wep_enabled) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 193 | adapter->currentpacketfilter |= cmd_act_mac_wep_enable; |
| 194 | else |
| 195 | adapter->currentpacketfilter &= ~cmd_act_mac_wep_enable; |
| 196 | ret = libertas_set_mac_packet_filter(priv); |
| 197 | if (ret) |
| 198 | goto out; |
| 199 | |
| 200 | mutex_lock(&adapter->lock); |
| 201 | |
| 202 | /* Copy WEP keys into adapter wep key fields */ |
| 203 | for (i = 0; i < 4; i++) { |
| 204 | memcpy(&adapter->wep_keys[i], &assoc_req->wep_keys[i], |
| 205 | sizeof(struct WLAN_802_11_KEY)); |
| 206 | } |
| 207 | adapter->wep_tx_keyidx = assoc_req->wep_tx_keyidx; |
| 208 | |
| 209 | mutex_unlock(&adapter->lock); |
| 210 | |
| 211 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 212 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 213 | return ret; |
| 214 | } |
| 215 | |
| 216 | static int assoc_helper_secinfo(wlan_private *priv, |
| 217 | struct assoc_request * assoc_req) |
| 218 | { |
| 219 | wlan_adapter *adapter = priv->adapter; |
| 220 | int ret = 0; |
| 221 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 222 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 223 | |
| 224 | memcpy(&adapter->secinfo, &assoc_req->secinfo, |
| 225 | sizeof(struct wlan_802_11_security)); |
| 226 | |
| 227 | ret = libertas_set_mac_packet_filter(priv); |
| 228 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 229 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 230 | return ret; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | static int assoc_helper_wpa_keys(wlan_private *priv, |
| 235 | struct assoc_request * assoc_req) |
| 236 | { |
| 237 | int ret = 0; |
| 238 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 239 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 240 | |
| 241 | /* enable/Disable RSN */ |
| 242 | ret = libertas_prepare_and_send_command(priv, |
| 243 | cmd_802_11_enable_rsn, |
| 244 | cmd_act_set, |
| 245 | cmd_option_waitforrsp, |
| 246 | 0, assoc_req); |
| 247 | if (ret) |
| 248 | goto out; |
| 249 | |
| 250 | ret = libertas_prepare_and_send_command(priv, |
| 251 | cmd_802_11_key_material, |
| 252 | cmd_act_set, |
| 253 | cmd_option_waitforrsp, |
| 254 | 0, assoc_req); |
| 255 | |
| 256 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 257 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 258 | return ret; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | static int assoc_helper_wpa_ie(wlan_private *priv, |
| 263 | struct assoc_request * assoc_req) |
| 264 | { |
| 265 | wlan_adapter *adapter = priv->adapter; |
| 266 | int ret = 0; |
| 267 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 268 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 269 | |
| 270 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { |
| 271 | memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len); |
| 272 | adapter->wpa_ie_len = assoc_req->wpa_ie_len; |
| 273 | } else { |
| 274 | memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN); |
| 275 | adapter->wpa_ie_len = 0; |
| 276 | } |
| 277 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 278 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 279 | return ret; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | static int should_deauth_infrastructure(wlan_adapter *adapter, |
| 284 | struct assoc_request * assoc_req) |
| 285 | { |
| 286 | if (adapter->connect_status != libertas_connected) |
| 287 | return 0; |
| 288 | |
| 289 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 290 | lbs_deb_assoc("Deauthenticating due to new SSID in " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 291 | " configuration request.\n"); |
| 292 | return 1; |
| 293 | } |
| 294 | |
| 295 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 296 | if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 297 | lbs_deb_assoc("Deauthenticating due to updated security " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 298 | "info in configuration request.\n"); |
| 299 | return 1; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 304 | lbs_deb_assoc("Deauthenticating due to new BSSID in " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 305 | " configuration request.\n"); |
| 306 | return 1; |
| 307 | } |
| 308 | |
| 309 | /* FIXME: deal with 'auto' mode somehow */ |
| 310 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 311 | if (assoc_req->mode != IW_MODE_INFRA) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 312 | return 1; |
| 313 | } |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | |
| 319 | static int should_stop_adhoc(wlan_adapter *adapter, |
| 320 | struct assoc_request * assoc_req) |
| 321 | { |
| 322 | if (adapter->connect_status != libertas_connected) |
| 323 | return 0; |
| 324 | |
| 325 | if (adapter->curbssparams.ssid.ssidlength != assoc_req->ssid.ssidlength) |
| 326 | return 1; |
| 327 | if (memcmp(adapter->curbssparams.ssid.ssid, assoc_req->ssid.ssid, |
Dan Williams | ad1f329 | 2007-05-10 22:52:37 -0400 | [diff] [blame] | 328 | adapter->curbssparams.ssid.ssidlength)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 329 | return 1; |
| 330 | |
| 331 | /* FIXME: deal with 'auto' mode somehow */ |
| 332 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 333 | if (assoc_req->mode != IW_MODE_ADHOC) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 334 | return 1; |
| 335 | } |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | |
Holger Schurig | eb3ce63 | 2007-05-24 23:41:15 -0400 | [diff] [blame] | 341 | void libertas_association_worker(struct work_struct *work) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 342 | { |
| 343 | wlan_private *priv = container_of(work, wlan_private, assoc_work.work); |
| 344 | wlan_adapter *adapter = priv->adapter; |
| 345 | struct assoc_request * assoc_req = NULL; |
| 346 | int ret = 0; |
| 347 | int find_any_ssid = 0; |
| 348 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 349 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 350 | |
| 351 | mutex_lock(&adapter->lock); |
| 352 | assoc_req = adapter->assoc_req; |
| 353 | adapter->assoc_req = NULL; |
| 354 | mutex_unlock(&adapter->lock); |
| 355 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 356 | if (!assoc_req) |
| 357 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 358 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 359 | lbs_deb_assoc("ASSOC: starting new association request: flags = 0x%lX\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 360 | assoc_req->flags); |
| 361 | |
| 362 | /* If 'any' SSID was specified, find an SSID to associate with */ |
| 363 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags) |
| 364 | && !assoc_req->ssid.ssidlength) |
| 365 | find_any_ssid = 1; |
| 366 | |
| 367 | /* But don't use 'any' SSID if there's a valid locked BSSID to use */ |
| 368 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
| 369 | if (memcmp(&assoc_req->bssid, bssid_any, ETH_ALEN) |
| 370 | && memcmp(&assoc_req->bssid, bssid_off, ETH_ALEN)) |
| 371 | find_any_ssid = 0; |
| 372 | } |
| 373 | |
| 374 | if (find_any_ssid) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 375 | u8 new_mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 376 | |
| 377 | ret = libertas_find_best_network_SSID(priv, &assoc_req->ssid, |
| 378 | assoc_req->mode, &new_mode); |
| 379 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 380 | lbs_deb_assoc("Could not find best network\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 381 | ret = -ENETUNREACH; |
| 382 | goto out; |
| 383 | } |
| 384 | |
| 385 | /* Ensure we switch to the mode of the AP */ |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 386 | if (assoc_req->mode == IW_MODE_AUTO) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 387 | set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); |
| 388 | assoc_req->mode = new_mode; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Check if the attributes being changing require deauthentication |
| 394 | * from the currently associated infrastructure access point. |
| 395 | */ |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 396 | if (adapter->mode == IW_MODE_INFRA) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 397 | if (should_deauth_infrastructure(adapter, assoc_req)) { |
| 398 | ret = libertas_send_deauthentication(priv); |
| 399 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 400 | lbs_deb_assoc("Deauthentication due to new " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 401 | "configuration request failed: %d\n", |
| 402 | ret); |
| 403 | } |
| 404 | } |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 405 | } else if (adapter->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 406 | if (should_stop_adhoc(adapter, assoc_req)) { |
| 407 | ret = libertas_stop_adhoc_network(priv); |
| 408 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 409 | lbs_deb_assoc("Teardown of AdHoc network due to " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 410 | "new configuration request failed: %d\n", |
| 411 | ret); |
| 412 | } |
| 413 | |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /* Send the various configuration bits to the firmware */ |
| 418 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
| 419 | ret = assoc_helper_mode(priv, assoc_req); |
| 420 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 421 | lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n", __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 422 | goto out; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags) |
| 427 | || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) { |
| 428 | ret = assoc_helper_wep_keys(priv, assoc_req); |
| 429 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 430 | lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 431 | goto out; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
| 436 | ret = assoc_helper_secinfo(priv, assoc_req); |
| 437 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 438 | lbs_deb_assoc("ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 439 | goto out; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
| 444 | ret = assoc_helper_wpa_ie(priv, assoc_req); |
| 445 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 446 | lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 447 | goto out; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags) |
| 452 | || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 453 | ret = assoc_helper_wpa_keys(priv, assoc_req); |
| 454 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 455 | lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 456 | goto out; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | /* SSID/BSSID should be the _last_ config option set, because they |
| 461 | * trigger the association attempt. |
| 462 | */ |
| 463 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags) |
| 464 | || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 465 | int success = 1; |
| 466 | |
| 467 | ret = assoc_helper_associate(priv, assoc_req); |
| 468 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 469 | lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 470 | ret); |
| 471 | success = 0; |
| 472 | } |
| 473 | |
| 474 | if (adapter->connect_status != libertas_connected) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 475 | lbs_deb_assoc("ASSOC: assoication attempt unsuccessful, " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 476 | "not connected.\n"); |
| 477 | success = 0; |
| 478 | } |
| 479 | |
| 480 | if (success) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 481 | lbs_deb_assoc("ASSOC: association attempt successful. " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 482 | "Associated to '%s' (" MAC_FMT ")\n", |
| 483 | assoc_req->ssid.ssid, MAC_ARG(assoc_req->bssid)); |
| 484 | libertas_prepare_and_send_command(priv, |
| 485 | cmd_802_11_rssi, |
| 486 | 0, cmd_option_waitforrsp, 0, NULL); |
| 487 | |
| 488 | libertas_prepare_and_send_command(priv, |
| 489 | cmd_802_11_get_log, |
| 490 | 0, cmd_option_waitforrsp, 0, NULL); |
| 491 | } else { |
| 492 | |
| 493 | ret = -1; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | out: |
| 498 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 499 | lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 500 | ret); |
| 501 | } |
| 502 | kfree(assoc_req); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 503 | |
| 504 | done: |
| 505 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | |
| 509 | /* |
| 510 | * Caller MUST hold any necessary locks |
| 511 | */ |
| 512 | struct assoc_request * wlan_get_association_request(wlan_adapter *adapter) |
| 513 | { |
| 514 | struct assoc_request * assoc_req; |
| 515 | |
| 516 | if (!adapter->assoc_req) { |
| 517 | adapter->assoc_req = kzalloc(sizeof(struct assoc_request), GFP_KERNEL); |
| 518 | if (!adapter->assoc_req) { |
| 519 | lbs_pr_info("Not enough memory to allocate association" |
| 520 | " request!\n"); |
| 521 | return NULL; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | /* Copy current configuration attributes to the association request, |
| 526 | * but don't overwrite any that are already set. |
| 527 | */ |
| 528 | assoc_req = adapter->assoc_req; |
| 529 | if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 530 | memcpy(&assoc_req->ssid, adapter->curbssparams.ssid.ssid, |
| 531 | adapter->curbssparams.ssid.ssidlength); |
| 532 | } |
| 533 | |
| 534 | if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
| 535 | assoc_req->channel = adapter->curbssparams.channel; |
| 536 | |
| 537 | if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 538 | assoc_req->mode = adapter->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 539 | |
| 540 | if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
| 541 | memcpy(&assoc_req->bssid, adapter->curbssparams.bssid, |
| 542 | ETH_ALEN); |
| 543 | } |
| 544 | |
| 545 | if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) { |
| 546 | int i; |
| 547 | for (i = 0; i < 4; i++) { |
| 548 | memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i], |
| 549 | sizeof(struct WLAN_802_11_KEY)); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) |
| 554 | assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx; |
| 555 | |
| 556 | if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
| 557 | memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key, |
| 558 | sizeof(struct WLAN_802_11_KEY)); |
| 559 | } |
| 560 | |
| 561 | if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 562 | memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key, |
| 563 | sizeof(struct WLAN_802_11_KEY)); |
| 564 | } |
| 565 | |
| 566 | if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
| 567 | memcpy(&assoc_req->secinfo, &adapter->secinfo, |
| 568 | sizeof(struct wlan_802_11_security)); |
| 569 | } |
| 570 | |
| 571 | if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
| 572 | memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie, |
| 573 | MAX_WPA_IE_LEN); |
| 574 | assoc_req->wpa_ie_len = adapter->wpa_ie_len; |
| 575 | } |
| 576 | |
| 577 | return assoc_req; |
| 578 | } |
| 579 | |
| 580 | |