Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /* Copyright (C) 2006, Red Hat, Inc. */ |
| 2 | |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 3 | #include <linux/types.h> |
Dan Williams | 3cf2093 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 4 | #include <linux/etherdevice.h> |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 5 | #include <linux/ieee80211.h> |
| 6 | #include <linux/if_arp.h> |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 7 | #include <net/lib80211.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 8 | |
| 9 | #include "assoc.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 10 | #include "decl.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 11 | #include "host.h" |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 12 | #include "scan.h" |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 13 | #include "cmd.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 14 | |
Ihar Hrachyshka | 5a6e043 | 2008-01-25 14:15:00 +0100 | [diff] [blame] | 15 | static const u8 bssid_any[ETH_ALEN] __attribute__ ((aligned (2))) = |
| 16 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
| 17 | static const u8 bssid_off[ETH_ALEN] __attribute__ ((aligned (2))) = |
| 18 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 19 | |
Dan Williams | be0d76e | 2009-05-22 20:05:25 -0400 | [diff] [blame] | 20 | /* The firmware needs the following bits masked out of the beacon-derived |
| 21 | * capability field when associating/joining to a BSS: |
| 22 | * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused) |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 23 | */ |
| 24 | #define CAPINFO_MASK (~(0xda00)) |
| 25 | |
Holger Schurig | 2d46502 | 2009-10-22 15:30:48 +0200 | [diff] [blame] | 26 | /** |
| 27 | * 802.11b/g supported bitrates (in 500Kb/s units) |
| 28 | */ |
| 29 | u8 lbs_bg_rates[MAX_RATES] = |
| 30 | { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, |
| 31 | 0x00, 0x00 }; |
| 32 | |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 33 | |
Amitkumar Karwar | 921ca03 | 2010-02-25 17:16:36 -0800 | [diff] [blame^] | 34 | static int assoc_helper_wep_keys(struct lbs_private *priv, |
| 35 | struct assoc_request *assoc_req); |
| 36 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 37 | /** |
| 38 | * @brief This function finds common rates between rates and card rates. |
| 39 | * |
| 40 | * It will fill common rates in rates as output if found. |
| 41 | * |
| 42 | * NOTE: Setting the MSB of the basic rates need to be taken |
| 43 | * care, either before or after calling this function |
| 44 | * |
| 45 | * @param priv A pointer to struct lbs_private structure |
| 46 | * @param rates the buffer which keeps input and output |
Dan Williams | ca4fe30 | 2009-08-21 09:35:20 -0500 | [diff] [blame] | 47 | * @param rates_size the size of rates buffer; new size of buffer on return, |
| 48 | * which will be less than or equal to original rates_size |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 49 | * |
| 50 | * @return 0 on success, or -1 on error |
| 51 | */ |
| 52 | static int get_common_rates(struct lbs_private *priv, |
| 53 | u8 *rates, |
| 54 | u16 *rates_size) |
| 55 | { |
Roel Kluin | 1e3d31c | 2009-08-02 09:44:12 +0200 | [diff] [blame] | 56 | int i, j; |
Dan Williams | ca4fe30 | 2009-08-21 09:35:20 -0500 | [diff] [blame] | 57 | u8 intersection[MAX_RATES]; |
| 58 | u16 intersection_size; |
| 59 | u16 num_rates = 0; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 60 | |
Dan Williams | ca4fe30 | 2009-08-21 09:35:20 -0500 | [diff] [blame] | 61 | intersection_size = min_t(u16, *rates_size, ARRAY_SIZE(intersection)); |
Andrey Yurovsky | 6f632d5 | 2009-08-13 17:34:40 -0700 | [diff] [blame] | 62 | |
Dan Williams | ca4fe30 | 2009-08-21 09:35:20 -0500 | [diff] [blame] | 63 | /* Allow each rate from 'rates' that is supported by the hardware */ |
| 64 | for (i = 0; i < ARRAY_SIZE(lbs_bg_rates) && lbs_bg_rates[i]; i++) { |
| 65 | for (j = 0; j < intersection_size && rates[j]; j++) { |
| 66 | if (rates[j] == lbs_bg_rates[i]) |
| 67 | intersection[num_rates++] = rates[j]; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size); |
Dan Williams | ca4fe30 | 2009-08-21 09:35:20 -0500 | [diff] [blame] | 72 | lbs_deb_hex(LBS_DEB_JOIN, "card rates ", lbs_bg_rates, |
| 73 | ARRAY_SIZE(lbs_bg_rates)); |
| 74 | lbs_deb_hex(LBS_DEB_JOIN, "common rates", intersection, num_rates); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 75 | lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate); |
| 76 | |
| 77 | if (!priv->enablehwauto) { |
Dan Williams | ca4fe30 | 2009-08-21 09:35:20 -0500 | [diff] [blame] | 78 | for (i = 0; i < num_rates; i++) { |
| 79 | if (intersection[i] == priv->cur_rate) |
| 80 | goto done; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 81 | } |
Dan Williams | ca4fe30 | 2009-08-21 09:35:20 -0500 | [diff] [blame] | 82 | lbs_pr_alert("Previously set fixed data rate %#x isn't " |
| 83 | "compatible with the network.\n", priv->cur_rate); |
| 84 | return -1; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 85 | } |
Dan Williams | ca4fe30 | 2009-08-21 09:35:20 -0500 | [diff] [blame] | 86 | |
| 87 | done: |
| 88 | memset(rates, 0, *rates_size); |
| 89 | *rates_size = num_rates; |
| 90 | memcpy(rates, intersection, num_rates); |
Roel Kluin | 1e3d31c | 2009-08-02 09:44:12 +0200 | [diff] [blame] | 91 | return 0; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | |
| 95 | /** |
| 96 | * @brief Sets the MSB on basic rates as the firmware requires |
| 97 | * |
| 98 | * Scan through an array and set the MSB for basic data rates. |
| 99 | * |
| 100 | * @param rates buffer of data rates |
| 101 | * @param len size of buffer |
| 102 | */ |
| 103 | static void lbs_set_basic_rate_flags(u8 *rates, size_t len) |
| 104 | { |
| 105 | int i; |
| 106 | |
| 107 | for (i = 0; i < len; i++) { |
| 108 | if (rates[i] == 0x02 || rates[i] == 0x04 || |
| 109 | rates[i] == 0x0b || rates[i] == 0x16) |
| 110 | rates[i] |= 0x80; |
| 111 | } |
| 112 | } |
| 113 | |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 114 | |
Dan Williams | be0d76e | 2009-05-22 20:05:25 -0400 | [diff] [blame] | 115 | static u8 iw_auth_to_ieee_auth(u8 auth) |
| 116 | { |
| 117 | if (auth == IW_AUTH_ALG_OPEN_SYSTEM) |
| 118 | return 0x00; |
| 119 | else if (auth == IW_AUTH_ALG_SHARED_KEY) |
| 120 | return 0x01; |
| 121 | else if (auth == IW_AUTH_ALG_LEAP) |
| 122 | return 0x80; |
| 123 | |
| 124 | lbs_deb_join("%s: invalid auth alg 0x%X\n", __func__, auth); |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @brief This function prepares the authenticate command. AUTHENTICATE only |
| 130 | * sets the authentication suite for future associations, as the firmware |
| 131 | * handles authentication internally during the ASSOCIATE command. |
| 132 | * |
| 133 | * @param priv A pointer to struct lbs_private structure |
| 134 | * @param bssid The peer BSSID with which to authenticate |
| 135 | * @param auth The authentication mode to use (from wireless.h) |
| 136 | * |
| 137 | * @return 0 or -1 |
| 138 | */ |
| 139 | static int lbs_set_authentication(struct lbs_private *priv, u8 bssid[6], u8 auth) |
| 140 | { |
| 141 | struct cmd_ds_802_11_authenticate cmd; |
| 142 | int ret = -1; |
Dan Williams | be0d76e | 2009-05-22 20:05:25 -0400 | [diff] [blame] | 143 | |
| 144 | lbs_deb_enter(LBS_DEB_JOIN); |
| 145 | |
| 146 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 147 | memcpy(cmd.bssid, bssid, ETH_ALEN); |
| 148 | |
| 149 | cmd.authtype = iw_auth_to_ieee_auth(auth); |
| 150 | |
Johannes Berg | e91d833 | 2009-07-15 17:21:41 +0200 | [diff] [blame] | 151 | lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n", bssid, cmd.authtype); |
Dan Williams | be0d76e | 2009-05-22 20:05:25 -0400 | [diff] [blame] | 152 | |
| 153 | ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd); |
| 154 | |
| 155 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); |
| 156 | return ret; |
| 157 | } |
| 158 | |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 159 | |
Holger Schurig | d0de374 | 2009-10-22 15:30:51 +0200 | [diff] [blame] | 160 | int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action, |
| 161 | struct assoc_request *assoc) |
| 162 | { |
| 163 | struct cmd_ds_802_11_set_wep cmd; |
| 164 | int ret = 0; |
| 165 | |
| 166 | lbs_deb_enter(LBS_DEB_CMD); |
| 167 | |
| 168 | memset(&cmd, 0, sizeof(cmd)); |
| 169 | cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP); |
| 170 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 171 | |
| 172 | cmd.action = cpu_to_le16(cmd_action); |
| 173 | |
| 174 | if (cmd_action == CMD_ACT_ADD) { |
| 175 | int i; |
| 176 | |
| 177 | /* default tx key index */ |
| 178 | cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx & |
| 179 | CMD_WEP_KEY_INDEX_MASK); |
| 180 | |
| 181 | /* Copy key types and material to host command structure */ |
| 182 | for (i = 0; i < 4; i++) { |
| 183 | struct enc_key *pkey = &assoc->wep_keys[i]; |
| 184 | |
| 185 | switch (pkey->len) { |
| 186 | case KEY_LEN_WEP_40: |
| 187 | cmd.keytype[i] = CMD_TYPE_WEP_40_BIT; |
| 188 | memmove(cmd.keymaterial[i], pkey->key, pkey->len); |
| 189 | lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i); |
| 190 | break; |
| 191 | case KEY_LEN_WEP_104: |
| 192 | cmd.keytype[i] = CMD_TYPE_WEP_104_BIT; |
| 193 | memmove(cmd.keymaterial[i], pkey->key, pkey->len); |
| 194 | lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i); |
| 195 | break; |
| 196 | case 0: |
| 197 | break; |
| 198 | default: |
| 199 | lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n", |
| 200 | i, pkey->len); |
| 201 | ret = -1; |
| 202 | goto done; |
| 203 | break; |
| 204 | } |
| 205 | } |
| 206 | } else if (cmd_action == CMD_ACT_REMOVE) { |
| 207 | /* ACT_REMOVE clears _all_ WEP keys */ |
| 208 | |
| 209 | /* default tx key index */ |
| 210 | cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx & |
| 211 | CMD_WEP_KEY_INDEX_MASK); |
| 212 | lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx); |
| 213 | } |
| 214 | |
| 215 | ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd); |
| 216 | done: |
| 217 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 218 | return ret; |
| 219 | } |
| 220 | |
| 221 | int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action, |
| 222 | uint16_t *enable) |
| 223 | { |
| 224 | struct cmd_ds_802_11_enable_rsn cmd; |
| 225 | int ret; |
| 226 | |
| 227 | lbs_deb_enter(LBS_DEB_CMD); |
| 228 | |
| 229 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 230 | cmd.action = cpu_to_le16(cmd_action); |
| 231 | |
| 232 | if (cmd_action == CMD_ACT_GET) |
| 233 | cmd.enable = 0; |
| 234 | else { |
| 235 | if (*enable) |
| 236 | cmd.enable = cpu_to_le16(CMD_ENABLE_RSN); |
| 237 | else |
| 238 | cmd.enable = cpu_to_le16(CMD_DISABLE_RSN); |
| 239 | lbs_deb_cmd("ENABLE_RSN: %d\n", *enable); |
| 240 | } |
| 241 | |
| 242 | ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd); |
| 243 | if (!ret && cmd_action == CMD_ACT_GET) |
| 244 | *enable = le16_to_cpu(cmd.enable); |
| 245 | |
| 246 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam, |
| 251 | struct enc_key *key) |
| 252 | { |
| 253 | lbs_deb_enter(LBS_DEB_CMD); |
| 254 | |
| 255 | if (key->flags & KEY_INFO_WPA_ENABLED) |
| 256 | keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED); |
| 257 | if (key->flags & KEY_INFO_WPA_UNICAST) |
| 258 | keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST); |
| 259 | if (key->flags & KEY_INFO_WPA_MCAST) |
| 260 | keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST); |
| 261 | |
| 262 | keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL); |
| 263 | keyparam->keytypeid = cpu_to_le16(key->type); |
| 264 | keyparam->keylen = cpu_to_le16(key->len); |
| 265 | memcpy(keyparam->key, key->key, key->len); |
| 266 | |
| 267 | /* Length field doesn't include the {type,length} header */ |
| 268 | keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4); |
| 269 | lbs_deb_leave(LBS_DEB_CMD); |
| 270 | } |
| 271 | |
| 272 | int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action, |
| 273 | struct assoc_request *assoc) |
| 274 | { |
| 275 | struct cmd_ds_802_11_key_material cmd; |
| 276 | int ret = 0; |
| 277 | int index = 0; |
| 278 | |
| 279 | lbs_deb_enter(LBS_DEB_CMD); |
| 280 | |
| 281 | cmd.action = cpu_to_le16(cmd_action); |
| 282 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 283 | |
| 284 | if (cmd_action == CMD_ACT_GET) { |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 285 | cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_header) + 2); |
Holger Schurig | d0de374 | 2009-10-22 15:30:51 +0200 | [diff] [blame] | 286 | } else { |
| 287 | memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet)); |
| 288 | |
| 289 | if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) { |
| 290 | set_one_wpa_key(&cmd.keyParamSet[index], |
| 291 | &assoc->wpa_unicast_key); |
| 292 | index++; |
| 293 | } |
| 294 | |
| 295 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) { |
| 296 | set_one_wpa_key(&cmd.keyParamSet[index], |
| 297 | &assoc->wpa_mcast_key); |
| 298 | index++; |
| 299 | } |
| 300 | |
| 301 | /* The common header and as many keys as we included */ |
| 302 | cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd), |
| 303 | keyParamSet[index])); |
| 304 | } |
| 305 | ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd); |
| 306 | /* Copy the returned key to driver private data */ |
| 307 | if (!ret && cmd_action == CMD_ACT_GET) { |
| 308 | void *buf_ptr = cmd.keyParamSet; |
| 309 | void *resp_end = &(&cmd)[1]; |
| 310 | |
| 311 | while (buf_ptr < resp_end) { |
| 312 | struct MrvlIEtype_keyParamSet *keyparam = buf_ptr; |
| 313 | struct enc_key *key; |
| 314 | uint16_t param_set_len = le16_to_cpu(keyparam->length); |
| 315 | uint16_t key_len = le16_to_cpu(keyparam->keylen); |
| 316 | uint16_t key_flags = le16_to_cpu(keyparam->keyinfo); |
| 317 | uint16_t key_type = le16_to_cpu(keyparam->keytypeid); |
| 318 | void *end; |
| 319 | |
| 320 | end = (void *)keyparam + sizeof(keyparam->type) |
| 321 | + sizeof(keyparam->length) + param_set_len; |
| 322 | |
| 323 | /* Make sure we don't access past the end of the IEs */ |
| 324 | if (end > resp_end) |
| 325 | break; |
| 326 | |
| 327 | if (key_flags & KEY_INFO_WPA_UNICAST) |
| 328 | key = &priv->wpa_unicast_key; |
| 329 | else if (key_flags & KEY_INFO_WPA_MCAST) |
| 330 | key = &priv->wpa_mcast_key; |
| 331 | else |
| 332 | break; |
| 333 | |
| 334 | /* Copy returned key into driver */ |
| 335 | memset(key, 0, sizeof(struct enc_key)); |
| 336 | if (key_len > sizeof(key->key)) |
| 337 | break; |
| 338 | key->type = key_type; |
| 339 | key->flags = key_flags; |
| 340 | key->len = key_len; |
| 341 | memcpy(key->key, keyparam->key, key->len); |
| 342 | |
| 343 | buf_ptr = end + 1; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 348 | return ret; |
| 349 | } |
| 350 | |
| 351 | static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok) |
| 352 | { |
| 353 | /* Bit Rate |
| 354 | * 15:13 Reserved |
| 355 | * 12 54 Mbps |
| 356 | * 11 48 Mbps |
| 357 | * 10 36 Mbps |
| 358 | * 9 24 Mbps |
| 359 | * 8 18 Mbps |
| 360 | * 7 12 Mbps |
| 361 | * 6 9 Mbps |
| 362 | * 5 6 Mbps |
| 363 | * 4 Reserved |
| 364 | * 3 11 Mbps |
| 365 | * 2 5.5 Mbps |
| 366 | * 1 2 Mbps |
| 367 | * 0 1 Mbps |
| 368 | **/ |
| 369 | |
| 370 | uint16_t ratemask; |
| 371 | int i = lbs_data_rate_to_fw_index(rate); |
| 372 | if (lower_rates_ok) |
| 373 | ratemask = (0x1fef >> (12 - i)); |
| 374 | else |
| 375 | ratemask = (1 << i); |
| 376 | return cpu_to_le16(ratemask); |
| 377 | } |
| 378 | |
| 379 | int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv, |
| 380 | uint16_t cmd_action) |
| 381 | { |
| 382 | struct cmd_ds_802_11_rate_adapt_rateset cmd; |
| 383 | int ret; |
| 384 | |
| 385 | lbs_deb_enter(LBS_DEB_CMD); |
| 386 | |
| 387 | if (!priv->cur_rate && !priv->enablehwauto) |
| 388 | return -EINVAL; |
| 389 | |
| 390 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 391 | |
| 392 | cmd.action = cpu_to_le16(cmd_action); |
| 393 | cmd.enablehwauto = cpu_to_le16(priv->enablehwauto); |
| 394 | cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto); |
| 395 | ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd); |
Holger Schurig | 48631de | 2009-12-02 15:26:04 +0100 | [diff] [blame] | 396 | if (!ret && cmd_action == CMD_ACT_GET) |
Holger Schurig | d0de374 | 2009-10-22 15:30:51 +0200 | [diff] [blame] | 397 | priv->enablehwauto = le16_to_cpu(cmd.enablehwauto); |
Holger Schurig | d0de374 | 2009-10-22 15:30:51 +0200 | [diff] [blame] | 398 | |
| 399 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 400 | return ret; |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * @brief Set the data rate |
| 405 | * |
| 406 | * @param priv A pointer to struct lbs_private structure |
| 407 | * @param rate The desired data rate, or 0 to clear a locked rate |
| 408 | * |
| 409 | * @return 0 on success, error on failure |
| 410 | */ |
| 411 | int lbs_set_data_rate(struct lbs_private *priv, u8 rate) |
| 412 | { |
| 413 | struct cmd_ds_802_11_data_rate cmd; |
| 414 | int ret = 0; |
| 415 | |
| 416 | lbs_deb_enter(LBS_DEB_CMD); |
| 417 | |
| 418 | memset(&cmd, 0, sizeof(cmd)); |
| 419 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 420 | |
| 421 | if (rate > 0) { |
| 422 | cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE); |
| 423 | cmd.rates[0] = lbs_data_rate_to_fw_index(rate); |
| 424 | if (cmd.rates[0] == 0) { |
| 425 | lbs_deb_cmd("DATA_RATE: invalid requested rate of" |
| 426 | " 0x%02X\n", rate); |
| 427 | ret = 0; |
| 428 | goto out; |
| 429 | } |
| 430 | lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]); |
| 431 | } else { |
| 432 | cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO); |
| 433 | lbs_deb_cmd("DATA_RATE: setting auto\n"); |
| 434 | } |
| 435 | |
| 436 | ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd); |
| 437 | if (ret) |
| 438 | goto out; |
| 439 | |
| 440 | lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof(cmd)); |
| 441 | |
| 442 | /* FIXME: get actual rates FW can do if this command actually returns |
| 443 | * all data rates supported. |
| 444 | */ |
| 445 | priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]); |
| 446 | lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate); |
| 447 | |
| 448 | out: |
| 449 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 450 | return ret; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | int lbs_cmd_802_11_rssi(struct lbs_private *priv, |
| 455 | struct cmd_ds_command *cmd) |
| 456 | { |
| 457 | |
| 458 | lbs_deb_enter(LBS_DEB_CMD); |
| 459 | cmd->command = cpu_to_le16(CMD_802_11_RSSI); |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 460 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + |
| 461 | sizeof(struct cmd_header)); |
Holger Schurig | d0de374 | 2009-10-22 15:30:51 +0200 | [diff] [blame] | 462 | cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR); |
| 463 | |
| 464 | /* reset Beacon SNR/NF/RSSI values */ |
| 465 | priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0; |
| 466 | priv->SNR[TYPE_BEACON][TYPE_AVG] = 0; |
| 467 | priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0; |
| 468 | priv->NF[TYPE_BEACON][TYPE_AVG] = 0; |
| 469 | priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0; |
| 470 | priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0; |
| 471 | |
| 472 | lbs_deb_leave(LBS_DEB_CMD); |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | int lbs_ret_802_11_rssi(struct lbs_private *priv, |
| 477 | struct cmd_ds_command *resp) |
| 478 | { |
| 479 | struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp; |
| 480 | |
| 481 | lbs_deb_enter(LBS_DEB_CMD); |
| 482 | |
| 483 | /* store the non average value */ |
| 484 | priv->SNR[TYPE_BEACON][TYPE_NOAVG] = get_unaligned_le16(&rssirsp->SNR); |
| 485 | priv->NF[TYPE_BEACON][TYPE_NOAVG] = |
| 486 | get_unaligned_le16(&rssirsp->noisefloor); |
| 487 | |
| 488 | priv->SNR[TYPE_BEACON][TYPE_AVG] = get_unaligned_le16(&rssirsp->avgSNR); |
| 489 | priv->NF[TYPE_BEACON][TYPE_AVG] = |
| 490 | get_unaligned_le16(&rssirsp->avgnoisefloor); |
| 491 | |
| 492 | priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = |
| 493 | CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG], |
| 494 | priv->NF[TYPE_BEACON][TYPE_NOAVG]); |
| 495 | |
| 496 | priv->RSSI[TYPE_BEACON][TYPE_AVG] = |
| 497 | CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE, |
| 498 | priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE); |
| 499 | |
| 500 | lbs_deb_cmd("RSSI: beacon %d, avg %d\n", |
| 501 | priv->RSSI[TYPE_BEACON][TYPE_NOAVG], |
| 502 | priv->RSSI[TYPE_BEACON][TYPE_AVG]); |
| 503 | |
| 504 | lbs_deb_leave(LBS_DEB_CMD); |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | |
| 509 | int lbs_cmd_bcn_ctrl(struct lbs_private *priv, |
| 510 | struct cmd_ds_command *cmd, |
| 511 | u16 cmd_action) |
| 512 | { |
| 513 | struct cmd_ds_802_11_beacon_control |
| 514 | *bcn_ctrl = &cmd->params.bcn_ctrl; |
| 515 | |
| 516 | lbs_deb_enter(LBS_DEB_CMD); |
| 517 | cmd->size = |
| 518 | cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control) |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 519 | + sizeof(struct cmd_header)); |
Holger Schurig | d0de374 | 2009-10-22 15:30:51 +0200 | [diff] [blame] | 520 | cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL); |
| 521 | |
| 522 | bcn_ctrl->action = cpu_to_le16(cmd_action); |
| 523 | bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable); |
| 524 | bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period); |
| 525 | |
| 526 | lbs_deb_leave(LBS_DEB_CMD); |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | int lbs_ret_802_11_bcn_ctrl(struct lbs_private *priv, |
| 531 | struct cmd_ds_command *resp) |
| 532 | { |
| 533 | struct cmd_ds_802_11_beacon_control *bcn_ctrl = |
| 534 | &resp->params.bcn_ctrl; |
| 535 | |
| 536 | lbs_deb_enter(LBS_DEB_CMD); |
| 537 | |
| 538 | if (bcn_ctrl->action == CMD_ACT_GET) { |
| 539 | priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable); |
| 540 | priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period); |
| 541 | } |
| 542 | |
| 543 | lbs_deb_enter(LBS_DEB_CMD); |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | |
| 548 | |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 549 | static int lbs_assoc_post(struct lbs_private *priv, |
| 550 | struct cmd_ds_802_11_associate_response *resp) |
| 551 | { |
| 552 | int ret = 0; |
| 553 | union iwreq_data wrqu; |
| 554 | struct bss_descriptor *bss; |
| 555 | u16 status_code; |
| 556 | |
| 557 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 558 | |
| 559 | if (!priv->in_progress_assoc_req) { |
| 560 | lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n"); |
| 561 | ret = -1; |
| 562 | goto done; |
| 563 | } |
| 564 | bss = &priv->in_progress_assoc_req->bss; |
| 565 | |
| 566 | /* |
| 567 | * Older FW versions map the IEEE 802.11 Status Code in the association |
| 568 | * response to the following values returned in resp->statuscode: |
| 569 | * |
| 570 | * IEEE Status Code Marvell Status Code |
| 571 | * 0 -> 0x0000 ASSOC_RESULT_SUCCESS |
| 572 | * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 573 | * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 574 | * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 575 | * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 576 | * others -> 0x0003 ASSOC_RESULT_REFUSED |
| 577 | * |
| 578 | * Other response codes: |
| 579 | * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused) |
| 580 | * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for |
| 581 | * association response from the AP) |
| 582 | */ |
| 583 | |
| 584 | status_code = le16_to_cpu(resp->statuscode); |
| 585 | if (priv->fwrelease < 0x09000000) { |
| 586 | switch (status_code) { |
| 587 | case 0x00: |
| 588 | break; |
| 589 | case 0x01: |
| 590 | lbs_deb_assoc("ASSOC_RESP: invalid parameters\n"); |
| 591 | break; |
| 592 | case 0x02: |
| 593 | lbs_deb_assoc("ASSOC_RESP: internal timer " |
| 594 | "expired while waiting for the AP\n"); |
| 595 | break; |
| 596 | case 0x03: |
| 597 | lbs_deb_assoc("ASSOC_RESP: association " |
| 598 | "refused by AP\n"); |
| 599 | break; |
| 600 | case 0x04: |
| 601 | lbs_deb_assoc("ASSOC_RESP: authentication " |
| 602 | "refused by AP\n"); |
| 603 | break; |
| 604 | default: |
| 605 | lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x " |
| 606 | " unknown\n", status_code); |
| 607 | break; |
| 608 | } |
| 609 | } else { |
| 610 | /* v9+ returns the AP's association response */ |
| 611 | lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x\n", status_code); |
| 612 | } |
| 613 | |
| 614 | if (status_code) { |
| 615 | lbs_mac_event_disconnected(priv); |
Amitkumar Karwar | 921ca03 | 2010-02-25 17:16:36 -0800 | [diff] [blame^] | 616 | ret = status_code; |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 617 | goto done; |
| 618 | } |
| 619 | |
| 620 | lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP", |
| 621 | (void *) (resp + sizeof (resp->hdr)), |
| 622 | le16_to_cpu(resp->hdr.size) - sizeof (resp->hdr)); |
| 623 | |
| 624 | /* Send a Media Connected event, according to the Spec */ |
| 625 | priv->connect_status = LBS_CONNECTED; |
| 626 | |
| 627 | /* Update current SSID and BSSID */ |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 628 | memcpy(&priv->curbssparams.ssid, &bss->ssid, IEEE80211_MAX_SSID_LEN); |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 629 | priv->curbssparams.ssid_len = bss->ssid_len; |
| 630 | memcpy(priv->curbssparams.bssid, bss->bssid, ETH_ALEN); |
| 631 | |
| 632 | priv->SNR[TYPE_RXPD][TYPE_AVG] = 0; |
| 633 | priv->NF[TYPE_RXPD][TYPE_AVG] = 0; |
| 634 | |
| 635 | memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR)); |
| 636 | memset(priv->rawNF, 0x00, sizeof(priv->rawNF)); |
| 637 | priv->nextSNRNF = 0; |
| 638 | priv->numSNRNF = 0; |
| 639 | |
| 640 | netif_carrier_on(priv->dev); |
| 641 | if (!priv->tx_pending_len) |
| 642 | netif_wake_queue(priv->dev); |
| 643 | |
| 644 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); |
| 645 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 646 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
| 647 | |
| 648 | done: |
| 649 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 650 | return ret; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * @brief This function prepares an association-class command. |
| 655 | * |
| 656 | * @param priv A pointer to struct lbs_private structure |
| 657 | * @param assoc_req The association request describing the BSS to associate |
| 658 | * or reassociate with |
| 659 | * @param command The actual command, either CMD_802_11_ASSOCIATE or |
| 660 | * CMD_802_11_REASSOCIATE |
| 661 | * |
| 662 | * @return 0 or -1 |
| 663 | */ |
| 664 | static int lbs_associate(struct lbs_private *priv, |
| 665 | struct assoc_request *assoc_req, |
| 666 | u16 command) |
| 667 | { |
| 668 | struct cmd_ds_802_11_associate cmd; |
| 669 | int ret = 0; |
| 670 | struct bss_descriptor *bss = &assoc_req->bss; |
| 671 | u8 *pos = &(cmd.iebuf[0]); |
| 672 | u16 tmpcap, tmplen, tmpauth; |
| 673 | struct mrvl_ie_ssid_param_set *ssid; |
| 674 | struct mrvl_ie_ds_param_set *ds; |
| 675 | struct mrvl_ie_cf_param_set *cf; |
| 676 | struct mrvl_ie_rates_param_set *rates; |
| 677 | struct mrvl_ie_rsn_param_set *rsn; |
| 678 | struct mrvl_ie_auth_type *auth; |
| 679 | |
| 680 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 681 | |
| 682 | BUG_ON((command != CMD_802_11_ASSOCIATE) && |
| 683 | (command != CMD_802_11_REASSOCIATE)); |
| 684 | |
| 685 | memset(&cmd, 0, sizeof(cmd)); |
| 686 | cmd.hdr.command = cpu_to_le16(command); |
| 687 | |
| 688 | /* Fill in static fields */ |
| 689 | memcpy(cmd.bssid, bss->bssid, ETH_ALEN); |
| 690 | cmd.listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL); |
| 691 | |
| 692 | /* Capability info */ |
| 693 | tmpcap = (bss->capability & CAPINFO_MASK); |
| 694 | if (bss->mode == IW_MODE_INFRA) |
| 695 | tmpcap |= WLAN_CAPABILITY_ESS; |
| 696 | cmd.capability = cpu_to_le16(tmpcap); |
| 697 | lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap); |
| 698 | |
| 699 | /* SSID */ |
| 700 | ssid = (struct mrvl_ie_ssid_param_set *) pos; |
| 701 | ssid->header.type = cpu_to_le16(TLV_TYPE_SSID); |
| 702 | tmplen = bss->ssid_len; |
| 703 | ssid->header.len = cpu_to_le16(tmplen); |
| 704 | memcpy(ssid->ssid, bss->ssid, tmplen); |
| 705 | pos += sizeof(ssid->header) + tmplen; |
| 706 | |
| 707 | ds = (struct mrvl_ie_ds_param_set *) pos; |
| 708 | ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS); |
| 709 | ds->header.len = cpu_to_le16(1); |
| 710 | ds->channel = bss->phy.ds.channel; |
| 711 | pos += sizeof(ds->header) + 1; |
| 712 | |
| 713 | cf = (struct mrvl_ie_cf_param_set *) pos; |
| 714 | cf->header.type = cpu_to_le16(TLV_TYPE_CF); |
| 715 | tmplen = sizeof(*cf) - sizeof (cf->header); |
| 716 | cf->header.len = cpu_to_le16(tmplen); |
| 717 | /* IE payload should be zeroed, firmware fills it in for us */ |
| 718 | pos += sizeof(*cf); |
| 719 | |
| 720 | rates = (struct mrvl_ie_rates_param_set *) pos; |
| 721 | rates->header.type = cpu_to_le16(TLV_TYPE_RATES); |
Dan Williams | ca4fe30 | 2009-08-21 09:35:20 -0500 | [diff] [blame] | 722 | tmplen = min_t(u16, ARRAY_SIZE(bss->rates), MAX_RATES); |
Roel Kluin | 1e3d31c | 2009-08-02 09:44:12 +0200 | [diff] [blame] | 723 | memcpy(&rates->rates, &bss->rates, tmplen); |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 724 | if (get_common_rates(priv, rates->rates, &tmplen)) { |
| 725 | ret = -1; |
| 726 | goto done; |
| 727 | } |
| 728 | pos += sizeof(rates->header) + tmplen; |
| 729 | rates->header.len = cpu_to_le16(tmplen); |
| 730 | lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen); |
| 731 | |
| 732 | /* Copy the infra. association rates into Current BSS state structure */ |
| 733 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); |
| 734 | memcpy(&priv->curbssparams.rates, &rates->rates, tmplen); |
| 735 | |
| 736 | /* Set MSB on basic rates as the firmware requires, but _after_ |
| 737 | * copying to current bss rates. |
| 738 | */ |
| 739 | lbs_set_basic_rate_flags(rates->rates, tmplen); |
| 740 | |
| 741 | /* Firmware v9+ indicate authentication suites as a TLV */ |
| 742 | if (priv->fwrelease >= 0x09000000) { |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 743 | auth = (struct mrvl_ie_auth_type *) pos; |
| 744 | auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE); |
| 745 | auth->header.len = cpu_to_le16(2); |
| 746 | tmpauth = iw_auth_to_ieee_auth(priv->secinfo.auth_mode); |
| 747 | auth->auth = cpu_to_le16(tmpauth); |
| 748 | pos += sizeof(auth->header) + 2; |
| 749 | |
Johannes Berg | e91d833 | 2009-07-15 17:21:41 +0200 | [diff] [blame] | 750 | lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n", |
| 751 | bss->bssid, priv->secinfo.auth_mode); |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /* WPA/WPA2 IEs */ |
| 755 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { |
| 756 | rsn = (struct mrvl_ie_rsn_param_set *) pos; |
| 757 | /* WPA_IE or WPA2_IE */ |
| 758 | rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]); |
| 759 | tmplen = (u16) assoc_req->wpa_ie[1]; |
| 760 | rsn->header.len = cpu_to_le16(tmplen); |
| 761 | memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen); |
| 762 | lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: WPA/RSN IE", (u8 *) rsn, |
| 763 | sizeof(rsn->header) + tmplen); |
| 764 | pos += sizeof(rsn->header) + tmplen; |
| 765 | } |
| 766 | |
| 767 | cmd.hdr.size = cpu_to_le16((sizeof(cmd) - sizeof(cmd.iebuf)) + |
| 768 | (u16)(pos - (u8 *) &cmd.iebuf)); |
| 769 | |
| 770 | /* update curbssparams */ |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 771 | priv->channel = bss->phy.ds.channel; |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 772 | |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 773 | ret = lbs_cmd_with_response(priv, command, &cmd); |
| 774 | if (ret == 0) { |
| 775 | ret = lbs_assoc_post(priv, |
| 776 | (struct cmd_ds_802_11_associate_response *) &cmd); |
| 777 | } |
| 778 | |
| 779 | done: |
| 780 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 781 | return ret; |
| 782 | } |
| 783 | |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 784 | /** |
| 785 | * @brief Associate to a specific BSS discovered in a scan |
| 786 | * |
| 787 | * @param priv A pointer to struct lbs_private structure |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 788 | * @param assoc_req The association request describing the BSS to associate with |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 789 | * |
| 790 | * @return 0-success, otherwise fail |
| 791 | */ |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 792 | static int lbs_try_associate(struct lbs_private *priv, |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 793 | struct assoc_request *assoc_req) |
| 794 | { |
| 795 | int ret; |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 796 | u8 preamble = RADIO_PREAMBLE_LONG; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 797 | |
| 798 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 799 | |
Dan Williams | be0d76e | 2009-05-22 20:05:25 -0400 | [diff] [blame] | 800 | /* FW v9 and higher indicate authentication suites as a TLV in the |
| 801 | * association command, not as a separate authentication command. |
| 802 | */ |
| 803 | if (priv->fwrelease < 0x09000000) { |
| 804 | ret = lbs_set_authentication(priv, assoc_req->bss.bssid, |
| 805 | priv->secinfo.auth_mode); |
| 806 | if (ret) |
| 807 | goto out; |
| 808 | } |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 809 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 810 | /* Use short preamble only when both the BSS and firmware support it */ |
Holger Schurig | 0e78ff8 | 2009-12-02 15:26:03 +0100 | [diff] [blame] | 811 | if (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 812 | preamble = RADIO_PREAMBLE_SHORT; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 813 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 814 | ret = lbs_set_radio(priv, preamble, 1); |
| 815 | if (ret) |
| 816 | goto out; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 817 | |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 818 | ret = lbs_associate(priv, assoc_req, CMD_802_11_ASSOCIATE); |
Amitkumar Karwar | 921ca03 | 2010-02-25 17:16:36 -0800 | [diff] [blame^] | 819 | /* If the association fails with current auth mode, let's |
| 820 | * try by changing the auth mode |
| 821 | */ |
| 822 | if ((priv->authtype_auto) && |
| 823 | (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) && |
| 824 | (assoc_req->secinfo.wep_enabled) && |
| 825 | (priv->connect_status != LBS_CONNECTED)) { |
| 826 | if (priv->secinfo.auth_mode == IW_AUTH_ALG_OPEN_SYSTEM) |
| 827 | priv->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY; |
| 828 | else |
| 829 | priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
| 830 | if (!assoc_helper_wep_keys(priv, assoc_req)) |
| 831 | ret = lbs_associate(priv, assoc_req, |
| 832 | CMD_802_11_ASSOCIATE); |
| 833 | } |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 834 | |
Amitkumar Karwar | 921ca03 | 2010-02-25 17:16:36 -0800 | [diff] [blame^] | 835 | if (ret) |
| 836 | ret = -1; |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 837 | out: |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 838 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 839 | return ret; |
| 840 | } |
| 841 | |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 842 | static int lbs_adhoc_post(struct lbs_private *priv, |
| 843 | struct cmd_ds_802_11_ad_hoc_result *resp) |
| 844 | { |
| 845 | int ret = 0; |
| 846 | u16 command = le16_to_cpu(resp->hdr.command); |
| 847 | u16 result = le16_to_cpu(resp->hdr.result); |
| 848 | union iwreq_data wrqu; |
| 849 | struct bss_descriptor *bss; |
| 850 | DECLARE_SSID_BUF(ssid); |
| 851 | |
| 852 | lbs_deb_enter(LBS_DEB_JOIN); |
| 853 | |
| 854 | if (!priv->in_progress_assoc_req) { |
| 855 | lbs_deb_join("ADHOC_RESP: no in-progress association " |
| 856 | "request\n"); |
| 857 | ret = -1; |
| 858 | goto done; |
| 859 | } |
| 860 | bss = &priv->in_progress_assoc_req->bss; |
| 861 | |
| 862 | /* |
| 863 | * Join result code 0 --> SUCCESS |
| 864 | */ |
| 865 | if (result) { |
| 866 | lbs_deb_join("ADHOC_RESP: failed (result 0x%X)\n", result); |
| 867 | if (priv->connect_status == LBS_CONNECTED) |
| 868 | lbs_mac_event_disconnected(priv); |
| 869 | ret = -1; |
| 870 | goto done; |
| 871 | } |
| 872 | |
| 873 | /* Send a Media Connected event, according to the Spec */ |
| 874 | priv->connect_status = LBS_CONNECTED; |
| 875 | |
| 876 | if (command == CMD_RET(CMD_802_11_AD_HOC_START)) { |
| 877 | /* Update the created network descriptor with the new BSSID */ |
| 878 | memcpy(bss->bssid, resp->bssid, ETH_ALEN); |
| 879 | } |
| 880 | |
| 881 | /* Set the BSSID from the joined/started descriptor */ |
| 882 | memcpy(&priv->curbssparams.bssid, bss->bssid, ETH_ALEN); |
| 883 | |
| 884 | /* Set the new SSID to current SSID */ |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 885 | memcpy(&priv->curbssparams.ssid, &bss->ssid, IEEE80211_MAX_SSID_LEN); |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 886 | priv->curbssparams.ssid_len = bss->ssid_len; |
| 887 | |
| 888 | netif_carrier_on(priv->dev); |
| 889 | if (!priv->tx_pending_len) |
| 890 | netif_wake_queue(priv->dev); |
| 891 | |
| 892 | memset(&wrqu, 0, sizeof(wrqu)); |
| 893 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); |
| 894 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 895 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
| 896 | |
| 897 | lbs_deb_join("ADHOC_RESP: Joined/started '%s', BSSID %pM, channel %d\n", |
| 898 | print_ssid(ssid, bss->ssid, bss->ssid_len), |
| 899 | priv->curbssparams.bssid, |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 900 | priv->channel); |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 901 | |
| 902 | done: |
| 903 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); |
| 904 | return ret; |
| 905 | } |
| 906 | |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 907 | /** |
| 908 | * @brief Join an adhoc network found in a previous scan |
| 909 | * |
| 910 | * @param priv A pointer to struct lbs_private structure |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 911 | * @param assoc_req The association request describing the BSS to join |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 912 | * |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 913 | * @return 0 on success, error on failure |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 914 | */ |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 915 | static int lbs_adhoc_join(struct lbs_private *priv, |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 916 | struct assoc_request *assoc_req) |
| 917 | { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 918 | struct cmd_ds_802_11_ad_hoc_join cmd; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 919 | struct bss_descriptor *bss = &assoc_req->bss; |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 920 | u8 preamble = RADIO_PREAMBLE_LONG; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 921 | DECLARE_SSID_BUF(ssid); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 922 | u16 ratesize = 0; |
| 923 | int ret = 0; |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 924 | |
| 925 | lbs_deb_enter(LBS_DEB_ASSOC); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 926 | |
| 927 | lbs_deb_join("current SSID '%s', ssid length %u\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 928 | print_ssid(ssid, priv->curbssparams.ssid, |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 929 | priv->curbssparams.ssid_len), |
| 930 | priv->curbssparams.ssid_len); |
| 931 | lbs_deb_join("requested ssid '%s', ssid length %u\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 932 | print_ssid(ssid, bss->ssid, bss->ssid_len), |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 933 | bss->ssid_len); |
| 934 | |
| 935 | /* check if the requested SSID is already joined */ |
| 936 | if (priv->curbssparams.ssid_len && |
| 937 | !lbs_ssid_cmp(priv->curbssparams.ssid, |
| 938 | priv->curbssparams.ssid_len, |
| 939 | bss->ssid, bss->ssid_len) && |
| 940 | (priv->mode == IW_MODE_ADHOC) && |
| 941 | (priv->connect_status == LBS_CONNECTED)) { |
| 942 | union iwreq_data wrqu; |
| 943 | |
| 944 | lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as " |
| 945 | "current, not attempting to re-join"); |
| 946 | |
| 947 | /* Send the re-association event though, because the association |
| 948 | * request really was successful, even if just a null-op. |
| 949 | */ |
| 950 | memset(&wrqu, 0, sizeof(wrqu)); |
| 951 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, |
| 952 | ETH_ALEN); |
| 953 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 954 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
| 955 | goto out; |
| 956 | } |
| 957 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 958 | /* Use short preamble only when both the BSS and firmware support it */ |
Holger Schurig | 0e78ff8 | 2009-12-02 15:26:03 +0100 | [diff] [blame] | 959 | if (bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) { |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 960 | lbs_deb_join("AdhocJoin: Short preamble\n"); |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 961 | preamble = RADIO_PREAMBLE_SHORT; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 962 | } |
| 963 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 964 | ret = lbs_set_radio(priv, preamble, 1); |
| 965 | if (ret) |
| 966 | goto out; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 967 | |
| 968 | lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel); |
| 969 | lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band); |
| 970 | |
| 971 | priv->adhoccreate = 0; |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 972 | priv->channel = bss->channel; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 973 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 974 | /* Build the join command */ |
| 975 | memset(&cmd, 0, sizeof(cmd)); |
| 976 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 977 | |
| 978 | cmd.bss.type = CMD_BSS_TYPE_IBSS; |
| 979 | cmd.bss.beaconperiod = cpu_to_le16(bss->beaconperiod); |
| 980 | |
| 981 | memcpy(&cmd.bss.bssid, &bss->bssid, ETH_ALEN); |
| 982 | memcpy(&cmd.bss.ssid, &bss->ssid, bss->ssid_len); |
| 983 | |
Dan Williams | 5fd164e | 2009-05-22 20:01:21 -0400 | [diff] [blame] | 984 | memcpy(&cmd.bss.ds, &bss->phy.ds, sizeof(struct ieee_ie_ds_param_set)); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 985 | |
Dan Williams | 5fd164e | 2009-05-22 20:01:21 -0400 | [diff] [blame] | 986 | memcpy(&cmd.bss.ibss, &bss->ss.ibss, |
| 987 | sizeof(struct ieee_ie_ibss_param_set)); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 988 | |
| 989 | cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK); |
| 990 | lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n", |
| 991 | bss->capability, CAPINFO_MASK); |
| 992 | |
| 993 | /* information on BSSID descriptor passed to FW */ |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 994 | lbs_deb_join("ADHOC_J_CMD: BSSID = %pM, SSID = '%s'\n", |
| 995 | cmd.bss.bssid, cmd.bss.ssid); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 996 | |
| 997 | /* Only v8 and below support setting these */ |
| 998 | if (priv->fwrelease < 0x09000000) { |
| 999 | /* failtimeout */ |
| 1000 | cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT); |
| 1001 | /* probedelay */ |
| 1002 | cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); |
| 1003 | } |
| 1004 | |
| 1005 | /* Copy Data rates from the rates recorded in scan response */ |
| 1006 | memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates)); |
Dan Williams | ca4fe30 | 2009-08-21 09:35:20 -0500 | [diff] [blame] | 1007 | ratesize = min_t(u16, ARRAY_SIZE(cmd.bss.rates), ARRAY_SIZE (bss->rates)); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1008 | memcpy(cmd.bss.rates, bss->rates, ratesize); |
| 1009 | if (get_common_rates(priv, cmd.bss.rates, &ratesize)) { |
| 1010 | lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n"); |
| 1011 | ret = -1; |
| 1012 | goto out; |
| 1013 | } |
| 1014 | |
| 1015 | /* Copy the ad-hoc creation rates into Current BSS state structure */ |
| 1016 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); |
| 1017 | memcpy(&priv->curbssparams.rates, cmd.bss.rates, ratesize); |
| 1018 | |
| 1019 | /* Set MSB on basic rates as the firmware requires, but _after_ |
| 1020 | * copying to current bss rates. |
| 1021 | */ |
| 1022 | lbs_set_basic_rate_flags(cmd.bss.rates, ratesize); |
| 1023 | |
Dan Williams | 5fd164e | 2009-05-22 20:01:21 -0400 | [diff] [blame] | 1024 | cmd.bss.ibss.atimwindow = bss->atimwindow; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1025 | |
| 1026 | if (assoc_req->secinfo.wep_enabled) { |
| 1027 | u16 tmp = le16_to_cpu(cmd.bss.capability); |
| 1028 | tmp |= WLAN_CAPABILITY_PRIVACY; |
| 1029 | cmd.bss.capability = cpu_to_le16(tmp); |
| 1030 | } |
| 1031 | |
| 1032 | if (priv->psmode == LBS802_11POWERMODEMAX_PSP) { |
| 1033 | __le32 local_ps_mode = cpu_to_le32(LBS802_11POWERMODECAM); |
| 1034 | |
| 1035 | /* wake up first */ |
| 1036 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
| 1037 | CMD_ACT_SET, 0, 0, |
| 1038 | &local_ps_mode); |
| 1039 | if (ret) { |
| 1040 | ret = -1; |
| 1041 | goto out; |
| 1042 | } |
| 1043 | } |
| 1044 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1045 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd); |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 1046 | if (ret == 0) { |
| 1047 | ret = lbs_adhoc_post(priv, |
| 1048 | (struct cmd_ds_802_11_ad_hoc_result *)&cmd); |
| 1049 | } |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1050 | |
| 1051 | out: |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1052 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1053 | return ret; |
| 1054 | } |
| 1055 | |
| 1056 | /** |
| 1057 | * @brief Start an Adhoc Network |
| 1058 | * |
| 1059 | * @param priv A pointer to struct lbs_private structure |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1060 | * @param assoc_req The association request describing the BSS to start |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1061 | * |
| 1062 | * @return 0 on success, error on failure |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1063 | */ |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1064 | static int lbs_adhoc_start(struct lbs_private *priv, |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1065 | struct assoc_request *assoc_req) |
| 1066 | { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1067 | struct cmd_ds_802_11_ad_hoc_start cmd; |
Holger Schurig | 0e78ff8 | 2009-12-02 15:26:03 +0100 | [diff] [blame] | 1068 | u8 preamble = RADIO_PREAMBLE_SHORT; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1069 | size_t ratesize = 0; |
| 1070 | u16 tmpcap = 0; |
| 1071 | int ret = 0; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1072 | DECLARE_SSID_BUF(ssid); |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1073 | |
| 1074 | lbs_deb_enter(LBS_DEB_ASSOC); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1075 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1076 | ret = lbs_set_radio(priv, preamble, 1); |
| 1077 | if (ret) |
| 1078 | goto out; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1079 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1080 | /* Build the start command */ |
| 1081 | memset(&cmd, 0, sizeof(cmd)); |
| 1082 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1083 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1084 | memcpy(cmd.ssid, assoc_req->ssid, assoc_req->ssid_len); |
| 1085 | |
| 1086 | lbs_deb_join("ADHOC_START: SSID '%s', ssid length %u\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1087 | print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len), |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1088 | assoc_req->ssid_len); |
| 1089 | |
| 1090 | cmd.bsstype = CMD_BSS_TYPE_IBSS; |
| 1091 | |
| 1092 | if (priv->beacon_period == 0) |
| 1093 | priv->beacon_period = MRVDRV_BEACON_INTERVAL; |
| 1094 | cmd.beaconperiod = cpu_to_le16(priv->beacon_period); |
| 1095 | |
| 1096 | WARN_ON(!assoc_req->channel); |
| 1097 | |
| 1098 | /* set Physical parameter set */ |
Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 1099 | cmd.ds.header.id = WLAN_EID_DS_PARAMS; |
| 1100 | cmd.ds.header.len = 1; |
Dan Williams | 5fd164e | 2009-05-22 20:01:21 -0400 | [diff] [blame] | 1101 | cmd.ds.channel = assoc_req->channel; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1102 | |
| 1103 | /* set IBSS parameter set */ |
Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 1104 | cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS; |
| 1105 | cmd.ibss.header.len = 2; |
Dan Williams | 5fd164e | 2009-05-22 20:01:21 -0400 | [diff] [blame] | 1106 | cmd.ibss.atimwindow = cpu_to_le16(0); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1107 | |
| 1108 | /* set capability info */ |
| 1109 | tmpcap = WLAN_CAPABILITY_IBSS; |
Dan Williams | 2fa7a98 | 2009-05-22 20:09:58 -0400 | [diff] [blame] | 1110 | if (assoc_req->secinfo.wep_enabled || |
| 1111 | assoc_req->secinfo.WPAenabled || |
| 1112 | assoc_req->secinfo.WPA2enabled) { |
| 1113 | lbs_deb_join("ADHOC_START: WEP/WPA enabled, privacy on\n"); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1114 | tmpcap |= WLAN_CAPABILITY_PRIVACY; |
| 1115 | } else |
Dan Williams | 2fa7a98 | 2009-05-22 20:09:58 -0400 | [diff] [blame] | 1116 | lbs_deb_join("ADHOC_START: WEP disabled, privacy off\n"); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1117 | |
| 1118 | cmd.capability = cpu_to_le16(tmpcap); |
| 1119 | |
| 1120 | /* Only v8 and below support setting probe delay */ |
| 1121 | if (priv->fwrelease < 0x09000000) |
| 1122 | cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); |
| 1123 | |
| 1124 | ratesize = min(sizeof(cmd.rates), sizeof(lbs_bg_rates)); |
| 1125 | memcpy(cmd.rates, lbs_bg_rates, ratesize); |
| 1126 | |
| 1127 | /* Copy the ad-hoc creating rates into Current BSS state structure */ |
| 1128 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); |
| 1129 | memcpy(&priv->curbssparams.rates, &cmd.rates, ratesize); |
| 1130 | |
| 1131 | /* Set MSB on basic rates as the firmware requires, but _after_ |
| 1132 | * copying to current bss rates. |
| 1133 | */ |
| 1134 | lbs_set_basic_rate_flags(cmd.rates, ratesize); |
| 1135 | |
| 1136 | lbs_deb_join("ADHOC_START: rates=%02x %02x %02x %02x\n", |
| 1137 | cmd.rates[0], cmd.rates[1], cmd.rates[2], cmd.rates[3]); |
| 1138 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1139 | lbs_deb_join("ADHOC_START: Starting Ad-Hoc BSS on channel %d, band %d\n", |
| 1140 | assoc_req->channel, assoc_req->band); |
| 1141 | |
| 1142 | priv->adhoccreate = 1; |
| 1143 | priv->mode = IW_MODE_ADHOC; |
| 1144 | |
| 1145 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd); |
| 1146 | if (ret == 0) |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 1147 | ret = lbs_adhoc_post(priv, |
| 1148 | (struct cmd_ds_802_11_ad_hoc_result *)&cmd); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1149 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1150 | out: |
| 1151 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1152 | return ret; |
| 1153 | } |
| 1154 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1155 | /** |
| 1156 | * @brief Stop and Ad-Hoc network and exit Ad-Hoc mode |
| 1157 | * |
| 1158 | * @param priv A pointer to struct lbs_private structure |
| 1159 | * @return 0 on success, or an error |
| 1160 | */ |
| 1161 | int lbs_adhoc_stop(struct lbs_private *priv) |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1162 | { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1163 | struct cmd_ds_802_11_ad_hoc_stop cmd; |
| 1164 | int ret; |
| 1165 | |
| 1166 | lbs_deb_enter(LBS_DEB_JOIN); |
| 1167 | |
| 1168 | memset(&cmd, 0, sizeof (cmd)); |
| 1169 | cmd.hdr.size = cpu_to_le16 (sizeof (cmd)); |
| 1170 | |
| 1171 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd); |
| 1172 | |
| 1173 | /* Clean up everything even if there was an error */ |
| 1174 | lbs_mac_event_disconnected(priv); |
| 1175 | |
| 1176 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 1177 | return ret; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1178 | } |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 1179 | |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 1180 | static inline int match_bss_no_security(struct lbs_802_11_security *secinfo, |
| 1181 | struct bss_descriptor *match_bss) |
| 1182 | { |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 1183 | if (!secinfo->wep_enabled && |
| 1184 | !secinfo->WPAenabled && !secinfo->WPA2enabled && |
| 1185 | match_bss->wpa_ie[0] != WLAN_EID_GENERIC && |
| 1186 | match_bss->rsn_ie[0] != WLAN_EID_RSN && |
| 1187 | !(match_bss->capability & WLAN_CAPABILITY_PRIVACY)) |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 1188 | return 1; |
| 1189 | else |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
| 1193 | static inline int match_bss_static_wep(struct lbs_802_11_security *secinfo, |
| 1194 | struct bss_descriptor *match_bss) |
| 1195 | { |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 1196 | if (secinfo->wep_enabled && |
| 1197 | !secinfo->WPAenabled && !secinfo->WPA2enabled && |
| 1198 | (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 1199 | return 1; |
| 1200 | else |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | static inline int match_bss_wpa(struct lbs_802_11_security *secinfo, |
| 1205 | struct bss_descriptor *match_bss) |
| 1206 | { |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 1207 | if (!secinfo->wep_enabled && secinfo->WPAenabled && |
| 1208 | (match_bss->wpa_ie[0] == WLAN_EID_GENERIC) |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 1209 | /* privacy bit may NOT be set in some APs like LinkSys WRT54G |
| 1210 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */ |
| 1211 | ) |
| 1212 | return 1; |
| 1213 | else |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | static inline int match_bss_wpa2(struct lbs_802_11_security *secinfo, |
| 1218 | struct bss_descriptor *match_bss) |
| 1219 | { |
| 1220 | if (!secinfo->wep_enabled && secinfo->WPA2enabled && |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 1221 | (match_bss->rsn_ie[0] == WLAN_EID_RSN) |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 1222 | /* privacy bit may NOT be set in some APs like LinkSys WRT54G |
| 1223 | (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */ |
| 1224 | ) |
| 1225 | return 1; |
| 1226 | else |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | static inline int match_bss_dynamic_wep(struct lbs_802_11_security *secinfo, |
| 1231 | struct bss_descriptor *match_bss) |
| 1232 | { |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 1233 | if (!secinfo->wep_enabled && |
| 1234 | !secinfo->WPAenabled && !secinfo->WPA2enabled && |
| 1235 | (match_bss->wpa_ie[0] != WLAN_EID_GENERIC) && |
| 1236 | (match_bss->rsn_ie[0] != WLAN_EID_RSN) && |
| 1237 | (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 1238 | return 1; |
| 1239 | else |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * @brief Check if a scanned network compatible with the driver settings |
| 1245 | * |
| 1246 | * WEP WPA WPA2 ad-hoc encrypt Network |
| 1247 | * enabled enabled enabled AES mode privacy WPA WPA2 Compatible |
| 1248 | * 0 0 0 0 NONE 0 0 0 yes No security |
| 1249 | * 1 0 0 0 NONE 1 0 0 yes Static WEP |
| 1250 | * 0 1 0 0 x 1x 1 x yes WPA |
| 1251 | * 0 0 1 0 x 1x x 1 yes WPA2 |
| 1252 | * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES |
| 1253 | * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP |
| 1254 | * |
| 1255 | * |
| 1256 | * @param priv A pointer to struct lbs_private |
| 1257 | * @param index Index in scantable to check against current driver settings |
| 1258 | * @param mode Network mode: Infrastructure or IBSS |
| 1259 | * |
| 1260 | * @return Index in scantable, or error code if negative |
| 1261 | */ |
| 1262 | static int is_network_compatible(struct lbs_private *priv, |
| 1263 | struct bss_descriptor *bss, uint8_t mode) |
| 1264 | { |
| 1265 | int matched = 0; |
| 1266 | |
| 1267 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1268 | |
| 1269 | if (bss->mode != mode) |
| 1270 | goto done; |
| 1271 | |
| 1272 | matched = match_bss_no_security(&priv->secinfo, bss); |
| 1273 | if (matched) |
| 1274 | goto done; |
| 1275 | matched = match_bss_static_wep(&priv->secinfo, bss); |
| 1276 | if (matched) |
| 1277 | goto done; |
| 1278 | matched = match_bss_wpa(&priv->secinfo, bss); |
| 1279 | if (matched) { |
| 1280 | lbs_deb_scan("is_network_compatible() WPA: wpa_ie 0x%x " |
| 1281 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s " |
| 1282 | "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0], |
| 1283 | priv->secinfo.wep_enabled ? "e" : "d", |
| 1284 | priv->secinfo.WPAenabled ? "e" : "d", |
| 1285 | priv->secinfo.WPA2enabled ? "e" : "d", |
| 1286 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
| 1287 | goto done; |
| 1288 | } |
| 1289 | matched = match_bss_wpa2(&priv->secinfo, bss); |
| 1290 | if (matched) { |
| 1291 | lbs_deb_scan("is_network_compatible() WPA2: wpa_ie 0x%x " |
| 1292 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s " |
| 1293 | "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0], |
| 1294 | priv->secinfo.wep_enabled ? "e" : "d", |
| 1295 | priv->secinfo.WPAenabled ? "e" : "d", |
| 1296 | priv->secinfo.WPA2enabled ? "e" : "d", |
| 1297 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
| 1298 | goto done; |
| 1299 | } |
| 1300 | matched = match_bss_dynamic_wep(&priv->secinfo, bss); |
| 1301 | if (matched) { |
| 1302 | lbs_deb_scan("is_network_compatible() dynamic WEP: " |
| 1303 | "wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n", |
| 1304 | bss->wpa_ie[0], bss->rsn_ie[0], |
| 1305 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
| 1306 | goto done; |
| 1307 | } |
| 1308 | |
| 1309 | /* bss security settings don't match those configured on card */ |
| 1310 | lbs_deb_scan("is_network_compatible() FAILED: wpa_ie 0x%x " |
| 1311 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n", |
| 1312 | bss->wpa_ie[0], bss->rsn_ie[0], |
| 1313 | priv->secinfo.wep_enabled ? "e" : "d", |
| 1314 | priv->secinfo.WPAenabled ? "e" : "d", |
| 1315 | priv->secinfo.WPA2enabled ? "e" : "d", |
| 1316 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
| 1317 | |
| 1318 | done: |
| 1319 | lbs_deb_leave_args(LBS_DEB_SCAN, "matched: %d", matched); |
| 1320 | return matched; |
| 1321 | } |
| 1322 | |
| 1323 | /** |
| 1324 | * @brief This function finds a specific compatible BSSID in the scan list |
| 1325 | * |
| 1326 | * Used in association code |
| 1327 | * |
| 1328 | * @param priv A pointer to struct lbs_private |
| 1329 | * @param bssid BSSID to find in the scan list |
| 1330 | * @param mode Network mode: Infrastructure or IBSS |
| 1331 | * |
| 1332 | * @return index in BSSID list, or error return code (< 0) |
| 1333 | */ |
| 1334 | static struct bss_descriptor *lbs_find_bssid_in_list(struct lbs_private *priv, |
| 1335 | uint8_t *bssid, uint8_t mode) |
| 1336 | { |
| 1337 | struct bss_descriptor *iter_bss; |
| 1338 | struct bss_descriptor *found_bss = NULL; |
| 1339 | |
| 1340 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1341 | |
| 1342 | if (!bssid) |
| 1343 | goto out; |
| 1344 | |
| 1345 | lbs_deb_hex(LBS_DEB_SCAN, "looking for", bssid, ETH_ALEN); |
| 1346 | |
| 1347 | /* Look through the scan table for a compatible match. The loop will |
| 1348 | * continue past a matched bssid that is not compatible in case there |
| 1349 | * is an AP with multiple SSIDs assigned to the same BSSID |
| 1350 | */ |
| 1351 | mutex_lock(&priv->lock); |
| 1352 | list_for_each_entry(iter_bss, &priv->network_list, list) { |
| 1353 | if (compare_ether_addr(iter_bss->bssid, bssid)) |
| 1354 | continue; /* bssid doesn't match */ |
| 1355 | switch (mode) { |
| 1356 | case IW_MODE_INFRA: |
| 1357 | case IW_MODE_ADHOC: |
| 1358 | if (!is_network_compatible(priv, iter_bss, mode)) |
| 1359 | break; |
| 1360 | found_bss = iter_bss; |
| 1361 | break; |
| 1362 | default: |
| 1363 | found_bss = iter_bss; |
| 1364 | break; |
| 1365 | } |
| 1366 | } |
| 1367 | mutex_unlock(&priv->lock); |
| 1368 | |
| 1369 | out: |
| 1370 | lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss); |
| 1371 | return found_bss; |
| 1372 | } |
| 1373 | |
| 1374 | /** |
| 1375 | * @brief This function finds ssid in ssid list. |
| 1376 | * |
| 1377 | * Used in association code |
| 1378 | * |
| 1379 | * @param priv A pointer to struct lbs_private |
| 1380 | * @param ssid SSID to find in the list |
| 1381 | * @param bssid BSSID to qualify the SSID selection (if provided) |
| 1382 | * @param mode Network mode: Infrastructure or IBSS |
| 1383 | * |
| 1384 | * @return index in BSSID list |
| 1385 | */ |
| 1386 | static struct bss_descriptor *lbs_find_ssid_in_list(struct lbs_private *priv, |
| 1387 | uint8_t *ssid, uint8_t ssid_len, |
| 1388 | uint8_t *bssid, uint8_t mode, |
| 1389 | int channel) |
| 1390 | { |
| 1391 | u32 bestrssi = 0; |
| 1392 | struct bss_descriptor *iter_bss = NULL; |
| 1393 | struct bss_descriptor *found_bss = NULL; |
| 1394 | struct bss_descriptor *tmp_oldest = NULL; |
| 1395 | |
| 1396 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1397 | |
| 1398 | mutex_lock(&priv->lock); |
| 1399 | |
| 1400 | list_for_each_entry(iter_bss, &priv->network_list, list) { |
| 1401 | if (!tmp_oldest || |
| 1402 | (iter_bss->last_scanned < tmp_oldest->last_scanned)) |
| 1403 | tmp_oldest = iter_bss; |
| 1404 | |
| 1405 | if (lbs_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len, |
| 1406 | ssid, ssid_len) != 0) |
| 1407 | continue; /* ssid doesn't match */ |
| 1408 | if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0) |
| 1409 | continue; /* bssid doesn't match */ |
| 1410 | if ((channel > 0) && (iter_bss->channel != channel)) |
| 1411 | continue; /* channel doesn't match */ |
| 1412 | |
| 1413 | switch (mode) { |
| 1414 | case IW_MODE_INFRA: |
| 1415 | case IW_MODE_ADHOC: |
| 1416 | if (!is_network_compatible(priv, iter_bss, mode)) |
| 1417 | break; |
| 1418 | |
| 1419 | if (bssid) { |
| 1420 | /* Found requested BSSID */ |
| 1421 | found_bss = iter_bss; |
| 1422 | goto out; |
| 1423 | } |
| 1424 | |
| 1425 | if (SCAN_RSSI(iter_bss->rssi) > bestrssi) { |
| 1426 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1427 | found_bss = iter_bss; |
| 1428 | } |
| 1429 | break; |
| 1430 | case IW_MODE_AUTO: |
| 1431 | default: |
| 1432 | if (SCAN_RSSI(iter_bss->rssi) > bestrssi) { |
| 1433 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1434 | found_bss = iter_bss; |
| 1435 | } |
| 1436 | break; |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | out: |
| 1441 | mutex_unlock(&priv->lock); |
| 1442 | lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss); |
| 1443 | return found_bss; |
| 1444 | } |
| 1445 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1446 | static int assoc_helper_essid(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1447 | struct assoc_request * assoc_req) |
| 1448 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1449 | int ret = 0; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1450 | struct bss_descriptor * bss; |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 1451 | int channel = -1; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1452 | DECLARE_SSID_BUF(ssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1453 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1454 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1455 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1456 | /* FIXME: take channel into account when picking SSIDs if a channel |
| 1457 | * is set. |
| 1458 | */ |
| 1459 | |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 1460 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
| 1461 | channel = assoc_req->channel; |
| 1462 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1463 | lbs_deb_assoc("SSID '%s' requested\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1464 | print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len)); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1465 | if (assoc_req->mode == IW_MODE_INFRA) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1466 | lbs_send_specific_ssid_scan(priv, assoc_req->ssid, |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1467 | assoc_req->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1468 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1469 | bss = lbs_find_ssid_in_list(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1470 | assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1471 | if (bss != NULL) { |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 1472 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 1473 | ret = lbs_try_associate(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1474 | } else { |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1475 | lbs_deb_assoc("SSID not found; cannot associate\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1476 | } |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1477 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1478 | /* Scan for the network, do not save previous results. Stale |
| 1479 | * scan data will cause us to join a non-existant adhoc network |
| 1480 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1481 | lbs_send_specific_ssid_scan(priv, assoc_req->ssid, |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1482 | assoc_req->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1483 | |
| 1484 | /* Search for the requested SSID in the scan table */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1485 | bss = lbs_find_ssid_in_list(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1486 | assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1487 | if (bss != NULL) { |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1488 | lbs_deb_assoc("SSID found, will join\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 1489 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1490 | lbs_adhoc_join(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1491 | } else { |
| 1492 | /* else send START command */ |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1493 | lbs_deb_assoc("SSID not found, creating adhoc network\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 1494 | memcpy(&assoc_req->bss.ssid, &assoc_req->ssid, |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 1495 | IEEE80211_MAX_SSID_LEN); |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1496 | assoc_req->bss.ssid_len = assoc_req->ssid_len; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1497 | lbs_adhoc_start(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1498 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1499 | } |
| 1500 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1501 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1502 | return ret; |
| 1503 | } |
| 1504 | |
| 1505 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1506 | static int assoc_helper_bssid(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1507 | struct assoc_request * assoc_req) |
| 1508 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1509 | int ret = 0; |
| 1510 | struct bss_descriptor * bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1511 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1512 | lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %pM", assoc_req->bssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1513 | |
| 1514 | /* Search for index position in list for requested MAC */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1515 | bss = lbs_find_bssid_in_list(priv, assoc_req->bssid, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1516 | assoc_req->mode); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1517 | if (bss == NULL) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1518 | lbs_deb_assoc("ASSOC: WAP: BSSID %pM not found, " |
| 1519 | "cannot associate.\n", assoc_req->bssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1520 | goto out; |
| 1521 | } |
| 1522 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 1523 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1524 | if (assoc_req->mode == IW_MODE_INFRA) { |
Dan Williams | 822ac03 | 2009-05-22 20:07:14 -0400 | [diff] [blame] | 1525 | ret = lbs_try_associate(priv, assoc_req); |
| 1526 | lbs_deb_assoc("ASSOC: lbs_try_associate(bssid) returned %d\n", |
| 1527 | ret); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1528 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1529 | lbs_adhoc_join(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1530 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1531 | |
| 1532 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1533 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1534 | return ret; |
| 1535 | } |
| 1536 | |
| 1537 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1538 | static int assoc_helper_associate(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1539 | struct assoc_request * assoc_req) |
| 1540 | { |
| 1541 | int ret = 0, done = 0; |
| 1542 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1543 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 1544 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1545 | /* If we're given and 'any' BSSID, try associating based on SSID */ |
| 1546 | |
| 1547 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 1548 | if (compare_ether_addr(bssid_any, assoc_req->bssid) && |
| 1549 | compare_ether_addr(bssid_off, assoc_req->bssid)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1550 | ret = assoc_helper_bssid(priv, assoc_req); |
| 1551 | done = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 1556 | ret = assoc_helper_essid(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1557 | } |
| 1558 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1559 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1560 | return ret; |
| 1561 | } |
| 1562 | |
| 1563 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1564 | static int assoc_helper_mode(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1565 | struct assoc_request * assoc_req) |
| 1566 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1567 | int ret = 0; |
| 1568 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1569 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1570 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1571 | if (assoc_req->mode == priv->mode) |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1572 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1573 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1574 | if (assoc_req->mode == IW_MODE_INFRA) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1575 | if (priv->psstate != PS_STATE_FULL_POWER) |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1576 | lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1577 | priv->psmode = LBS802_11POWERMODECAM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1578 | } |
| 1579 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1580 | priv->mode = assoc_req->mode; |
Holger Schurig | fef0640 | 2009-10-22 15:30:59 +0200 | [diff] [blame] | 1581 | ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, |
| 1582 | assoc_req->mode == IW_MODE_ADHOC ? 2 : 1); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1583 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1584 | done: |
| 1585 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1586 | return ret; |
| 1587 | } |
| 1588 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1589 | static int assoc_helper_channel(struct lbs_private *priv, |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1590 | struct assoc_request * assoc_req) |
| 1591 | { |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1592 | int ret = 0; |
| 1593 | |
| 1594 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 1595 | |
David Woodhouse | 9f46257 | 2007-12-12 22:50:21 -0500 | [diff] [blame] | 1596 | ret = lbs_update_channel(priv); |
David Woodhouse | d1a469f | 2007-12-16 17:21:00 -0500 | [diff] [blame] | 1597 | if (ret) { |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 1598 | lbs_deb_assoc("ASSOC: channel: error getting channel.\n"); |
David Woodhouse | d1a469f | 2007-12-16 17:21:00 -0500 | [diff] [blame] | 1599 | goto done; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1600 | } |
| 1601 | |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 1602 | if (assoc_req->channel == priv->channel) |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1603 | goto done; |
| 1604 | |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 1605 | if (priv->mesh_dev) { |
David Woodhouse | 8606213 | 2007-12-13 00:32:36 -0500 | [diff] [blame] | 1606 | /* Change mesh channel first; 21.p21 firmware won't let |
| 1607 | you change channel otherwise (even though it'll return |
| 1608 | an error to this */ |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 1609 | lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP, |
| 1610 | assoc_req->channel); |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 1611 | } |
| 1612 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1613 | lbs_deb_assoc("ASSOC: channel: %d -> %d\n", |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 1614 | priv->channel, assoc_req->channel); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1615 | |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 1616 | ret = lbs_set_channel(priv, assoc_req->channel); |
| 1617 | if (ret < 0) |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 1618 | lbs_deb_assoc("ASSOC: channel: error setting channel.\n"); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1619 | |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 1620 | /* FIXME: shouldn't need to grab the channel _again_ after setting |
| 1621 | * it since the firmware is supposed to return the new channel, but |
| 1622 | * whatever... */ |
David Woodhouse | 9f46257 | 2007-12-12 22:50:21 -0500 | [diff] [blame] | 1623 | ret = lbs_update_channel(priv); |
David Woodhouse | d1a469f | 2007-12-16 17:21:00 -0500 | [diff] [blame] | 1624 | if (ret) { |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 1625 | lbs_deb_assoc("ASSOC: channel: error getting channel.\n"); |
David Woodhouse | d1a469f | 2007-12-16 17:21:00 -0500 | [diff] [blame] | 1626 | goto done; |
| 1627 | } |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1628 | |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 1629 | if (assoc_req->channel != priv->channel) { |
David Woodhouse | 88ae291 | 2007-12-11 19:57:05 -0500 | [diff] [blame] | 1630 | lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n", |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1631 | assoc_req->channel); |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 1632 | goto restore_mesh; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1633 | } |
| 1634 | |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 1635 | if (assoc_req->secinfo.wep_enabled && |
| 1636 | (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len || |
| 1637 | assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len)) { |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1638 | /* Make sure WEP keys are re-sent to firmware */ |
| 1639 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); |
| 1640 | } |
| 1641 | |
| 1642 | /* Must restart/rejoin adhoc networks after channel change */ |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 1643 | set_bit(ASSOC_FLAG_SSID, &assoc_req->flags); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1644 | |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 1645 | restore_mesh: |
| 1646 | if (priv->mesh_dev) |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 1647 | lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 1648 | priv->channel); |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 1649 | |
| 1650 | done: |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1651 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 1652 | return ret; |
| 1653 | } |
| 1654 | |
| 1655 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1656 | static int assoc_helper_wep_keys(struct lbs_private *priv, |
David Woodhouse | f70dd45 | 2007-12-18 00:18:05 -0500 | [diff] [blame] | 1657 | struct assoc_request *assoc_req) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1658 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1659 | int i; |
| 1660 | int ret = 0; |
| 1661 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1662 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1663 | |
| 1664 | /* Set or remove WEP keys */ |
David Woodhouse | f70dd45 | 2007-12-18 00:18:05 -0500 | [diff] [blame] | 1665 | if (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len || |
| 1666 | assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len) |
| 1667 | ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_ADD, assoc_req); |
| 1668 | else |
| 1669 | ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_REMOVE, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1670 | |
| 1671 | if (ret) |
| 1672 | goto out; |
| 1673 | |
| 1674 | /* enable/disable the MAC's WEP packet filter */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1675 | if (assoc_req->secinfo.wep_enabled) |
Holger Schurig | d9e9778 | 2008-03-12 16:06:43 +0100 | [diff] [blame] | 1676 | priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1677 | else |
Holger Schurig | d9e9778 | 2008-03-12 16:06:43 +0100 | [diff] [blame] | 1678 | priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE; |
David Woodhouse | f70dd45 | 2007-12-18 00:18:05 -0500 | [diff] [blame] | 1679 | |
Holger Schurig | c97329e | 2008-03-18 11:20:21 +0100 | [diff] [blame] | 1680 | lbs_set_mac_control(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1681 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1682 | mutex_lock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1683 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1684 | /* Copy WEP keys into priv wep key fields */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1685 | for (i = 0; i < 4; i++) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1686 | memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i], |
David Woodhouse | f70dd45 | 2007-12-18 00:18:05 -0500 | [diff] [blame] | 1687 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1688 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1689 | priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1690 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1691 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1692 | |
| 1693 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1694 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1695 | return ret; |
| 1696 | } |
| 1697 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1698 | static int assoc_helper_secinfo(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1699 | struct assoc_request * assoc_req) |
| 1700 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1701 | int ret = 0; |
David Woodhouse | 4f59abf | 2007-12-18 00:47:17 -0500 | [diff] [blame] | 1702 | uint16_t do_wpa; |
| 1703 | uint16_t rsn = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1704 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1705 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1706 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1707 | memcpy(&priv->secinfo, &assoc_req->secinfo, |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1708 | sizeof(struct lbs_802_11_security)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1709 | |
Holger Schurig | c97329e | 2008-03-18 11:20:21 +0100 | [diff] [blame] | 1710 | lbs_set_mac_control(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1711 | |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 1712 | /* If RSN is already enabled, don't try to enable it again, since |
| 1713 | * ENABLE_RSN resets internal state machines and will clobber the |
| 1714 | * 4-way WPA handshake. |
| 1715 | */ |
| 1716 | |
| 1717 | /* Get RSN enabled/disabled */ |
David Woodhouse | 4f59abf | 2007-12-18 00:47:17 -0500 | [diff] [blame] | 1718 | ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn); |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 1719 | if (ret) { |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 1720 | lbs_deb_assoc("Failed to get RSN status: %d\n", ret); |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 1721 | goto out; |
| 1722 | } |
| 1723 | |
| 1724 | /* Don't re-enable RSN if it's already enabled */ |
David Woodhouse | 4f59abf | 2007-12-18 00:47:17 -0500 | [diff] [blame] | 1725 | do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled; |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 1726 | if (do_wpa == rsn) |
| 1727 | goto out; |
| 1728 | |
| 1729 | /* Set RSN enabled/disabled */ |
David Woodhouse | 4f59abf | 2007-12-18 00:47:17 -0500 | [diff] [blame] | 1730 | ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa); |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 1731 | |
| 1732 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1733 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1734 | return ret; |
| 1735 | } |
| 1736 | |
| 1737 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1738 | static int assoc_helper_wpa_keys(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1739 | struct assoc_request * assoc_req) |
| 1740 | { |
| 1741 | int ret = 0; |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 1742 | unsigned int flags = assoc_req->flags; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1743 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1744 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1745 | |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 1746 | /* Work around older firmware bug where WPA unicast and multicast |
| 1747 | * keys must be set independently. Seen in SDIO parts with firmware |
| 1748 | * version 5.0.11p0. |
| 1749 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1750 | |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 1751 | if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 1752 | clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags); |
David Woodhouse | 9e1228d | 2008-03-03 12:15:39 +0100 | [diff] [blame] | 1753 | ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req); |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 1754 | assoc_req->flags = flags; |
| 1755 | } |
| 1756 | |
| 1757 | if (ret) |
| 1758 | goto out; |
| 1759 | |
Andrey Yurovsky | ce8d096 | 2009-06-17 18:45:34 -0700 | [diff] [blame] | 1760 | memcpy(&priv->wpa_unicast_key, &assoc_req->wpa_unicast_key, |
| 1761 | sizeof(struct enc_key)); |
| 1762 | |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 1763 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
| 1764 | clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags); |
| 1765 | |
David Woodhouse | 9e1228d | 2008-03-03 12:15:39 +0100 | [diff] [blame] | 1766 | ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req); |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 1767 | assoc_req->flags = flags; |
Andrey Yurovsky | ce8d096 | 2009-06-17 18:45:34 -0700 | [diff] [blame] | 1768 | |
| 1769 | memcpy(&priv->wpa_mcast_key, &assoc_req->wpa_mcast_key, |
| 1770 | sizeof(struct enc_key)); |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1774 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1775 | return ret; |
| 1776 | } |
| 1777 | |
| 1778 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1779 | static int assoc_helper_wpa_ie(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1780 | struct assoc_request * assoc_req) |
| 1781 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1782 | int ret = 0; |
| 1783 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1784 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1785 | |
| 1786 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1787 | memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len); |
| 1788 | priv->wpa_ie_len = assoc_req->wpa_ie_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1789 | } else { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1790 | memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN); |
| 1791 | priv->wpa_ie_len = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1792 | } |
| 1793 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1794 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1795 | return ret; |
| 1796 | } |
| 1797 | |
| 1798 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1799 | static int should_deauth_infrastructure(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1800 | struct assoc_request * assoc_req) |
| 1801 | { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1802 | int ret = 0; |
| 1803 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1804 | if (priv->connect_status != LBS_CONNECTED) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1805 | return 0; |
| 1806 | |
Holger Schurig | 52507c2 | 2008-01-28 17:25:53 +0100 | [diff] [blame] | 1807 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1808 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1809 | lbs_deb_assoc("Deauthenticating due to new SSID\n"); |
| 1810 | ret = 1; |
| 1811 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1815 | if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1816 | lbs_deb_assoc("Deauthenticating due to new security\n"); |
| 1817 | ret = 1; |
| 1818 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1823 | lbs_deb_assoc("Deauthenticating due to new BSSID\n"); |
| 1824 | ret = 1; |
| 1825 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1826 | } |
| 1827 | |
Luis Carlos Cobo Rus | fff47f1 | 2007-05-30 12:16:13 -0400 | [diff] [blame] | 1828 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1829 | lbs_deb_assoc("Deauthenticating due to channel switch\n"); |
| 1830 | ret = 1; |
| 1831 | goto out; |
Luis Carlos Cobo Rus | fff47f1 | 2007-05-30 12:16:13 -0400 | [diff] [blame] | 1832 | } |
| 1833 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1834 | /* FIXME: deal with 'auto' mode somehow */ |
| 1835 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1836 | if (assoc_req->mode != IW_MODE_INFRA) { |
| 1837 | lbs_deb_assoc("Deauthenticating due to leaving " |
| 1838 | "infra mode\n"); |
| 1839 | ret = 1; |
| 1840 | goto out; |
| 1841 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1842 | } |
| 1843 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1844 | out: |
| 1845 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Holger Schurig | 52507c2 | 2008-01-28 17:25:53 +0100 | [diff] [blame] | 1846 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1850 | static int should_stop_adhoc(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1851 | struct assoc_request * assoc_req) |
| 1852 | { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1853 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 1854 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1855 | if (priv->connect_status != LBS_CONNECTED) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1856 | return 0; |
| 1857 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1858 | if (lbs_ssid_cmp(priv->curbssparams.ssid, |
| 1859 | priv->curbssparams.ssid_len, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1860 | assoc_req->ssid, assoc_req->ssid_len) != 0) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1861 | return 1; |
| 1862 | |
| 1863 | /* FIXME: deal with 'auto' mode somehow */ |
| 1864 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1865 | if (assoc_req->mode != IW_MODE_ADHOC) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1866 | return 1; |
| 1867 | } |
| 1868 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1869 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 1870 | if (assoc_req->channel != priv->channel) |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1871 | return 1; |
| 1872 | } |
| 1873 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1874 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1875 | return 0; |
| 1876 | } |
| 1877 | |
| 1878 | |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 1879 | /** |
| 1880 | * @brief This function finds the best SSID in the Scan List |
| 1881 | * |
| 1882 | * Search the scan table for the best SSID that also matches the current |
| 1883 | * adapter network preference (infrastructure or adhoc) |
| 1884 | * |
| 1885 | * @param priv A pointer to struct lbs_private |
| 1886 | * |
| 1887 | * @return index in BSSID list |
| 1888 | */ |
| 1889 | static struct bss_descriptor *lbs_find_best_ssid_in_list( |
| 1890 | struct lbs_private *priv, uint8_t mode) |
| 1891 | { |
| 1892 | uint8_t bestrssi = 0; |
| 1893 | struct bss_descriptor *iter_bss; |
| 1894 | struct bss_descriptor *best_bss = NULL; |
| 1895 | |
| 1896 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1897 | |
| 1898 | mutex_lock(&priv->lock); |
| 1899 | |
| 1900 | list_for_each_entry(iter_bss, &priv->network_list, list) { |
| 1901 | switch (mode) { |
| 1902 | case IW_MODE_INFRA: |
| 1903 | case IW_MODE_ADHOC: |
| 1904 | if (!is_network_compatible(priv, iter_bss, mode)) |
| 1905 | break; |
| 1906 | if (SCAN_RSSI(iter_bss->rssi) <= bestrssi) |
| 1907 | break; |
| 1908 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1909 | best_bss = iter_bss; |
| 1910 | break; |
| 1911 | case IW_MODE_AUTO: |
| 1912 | default: |
| 1913 | if (SCAN_RSSI(iter_bss->rssi) <= bestrssi) |
| 1914 | break; |
| 1915 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1916 | best_bss = iter_bss; |
| 1917 | break; |
| 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | mutex_unlock(&priv->lock); |
| 1922 | lbs_deb_leave_args(LBS_DEB_SCAN, "best_bss %p", best_bss); |
| 1923 | return best_bss; |
| 1924 | } |
| 1925 | |
| 1926 | /** |
| 1927 | * @brief Find the best AP |
| 1928 | * |
| 1929 | * Used from association worker. |
| 1930 | * |
| 1931 | * @param priv A pointer to struct lbs_private structure |
| 1932 | * @param pSSID A pointer to AP's ssid |
| 1933 | * |
| 1934 | * @return 0--success, otherwise--fail |
| 1935 | */ |
| 1936 | static int lbs_find_best_network_ssid(struct lbs_private *priv, |
| 1937 | uint8_t *out_ssid, uint8_t *out_ssid_len, uint8_t preferred_mode, |
| 1938 | uint8_t *out_mode) |
| 1939 | { |
| 1940 | int ret = -1; |
| 1941 | struct bss_descriptor *found; |
| 1942 | |
| 1943 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1944 | |
| 1945 | priv->scan_ssid_len = 0; |
| 1946 | lbs_scan_networks(priv, 1); |
| 1947 | if (priv->surpriseremoved) |
| 1948 | goto out; |
| 1949 | |
| 1950 | found = lbs_find_best_ssid_in_list(priv, preferred_mode); |
| 1951 | if (found && (found->ssid_len > 0)) { |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 1952 | memcpy(out_ssid, &found->ssid, IEEE80211_MAX_SSID_LEN); |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 1953 | *out_ssid_len = found->ssid_len; |
| 1954 | *out_mode = found->mode; |
| 1955 | ret = 0; |
| 1956 | } |
| 1957 | |
| 1958 | out: |
| 1959 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
| 1960 | return ret; |
| 1961 | } |
| 1962 | |
| 1963 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1964 | void lbs_association_worker(struct work_struct *work) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1965 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1966 | struct lbs_private *priv = container_of(work, struct lbs_private, |
| 1967 | assoc_work.work); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1968 | struct assoc_request * assoc_req = NULL; |
| 1969 | int ret = 0; |
| 1970 | int find_any_ssid = 0; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1971 | DECLARE_SSID_BUF(ssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1972 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1973 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1974 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1975 | mutex_lock(&priv->lock); |
| 1976 | assoc_req = priv->pending_assoc_req; |
| 1977 | priv->pending_assoc_req = NULL; |
| 1978 | priv->in_progress_assoc_req = assoc_req; |
| 1979 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1980 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1981 | if (!assoc_req) |
| 1982 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1983 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1984 | lbs_deb_assoc( |
| 1985 | "Association Request:\n" |
| 1986 | " flags: 0x%08lx\n" |
| 1987 | " SSID: '%s'\n" |
| 1988 | " chann: %d\n" |
| 1989 | " band: %d\n" |
| 1990 | " mode: %d\n" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1991 | " BSSID: %pM\n" |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1992 | " secinfo: %s%s%s\n" |
| 1993 | " auth_mode: %d\n", |
| 1994 | assoc_req->flags, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1995 | print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len), |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1996 | assoc_req->channel, assoc_req->band, assoc_req->mode, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1997 | assoc_req->bssid, |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1998 | assoc_req->secinfo.WPAenabled ? " WPA" : "", |
| 1999 | assoc_req->secinfo.WPA2enabled ? " WPA2" : "", |
| 2000 | assoc_req->secinfo.wep_enabled ? " WEP" : "", |
| 2001 | assoc_req->secinfo.auth_mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2002 | |
| 2003 | /* If 'any' SSID was specified, find an SSID to associate with */ |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 2004 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags) && |
| 2005 | !assoc_req->ssid_len) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2006 | find_any_ssid = 1; |
| 2007 | |
| 2008 | /* But don't use 'any' SSID if there's a valid locked BSSID to use */ |
| 2009 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 2010 | if (compare_ether_addr(assoc_req->bssid, bssid_any) && |
| 2011 | compare_ether_addr(assoc_req->bssid, bssid_off)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2012 | find_any_ssid = 0; |
| 2013 | } |
| 2014 | |
| 2015 | if (find_any_ssid) { |
Holger Schurig | 877cb0d | 2008-04-02 16:34:51 +0200 | [diff] [blame] | 2016 | u8 new_mode = assoc_req->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2017 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 2018 | ret = lbs_find_best_network_ssid(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 2019 | &assoc_req->ssid_len, assoc_req->mode, &new_mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2020 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2021 | lbs_deb_assoc("Could not find best network\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2022 | ret = -ENETUNREACH; |
| 2023 | goto out; |
| 2024 | } |
| 2025 | |
| 2026 | /* Ensure we switch to the mode of the AP */ |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 2027 | if (assoc_req->mode == IW_MODE_AUTO) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2028 | set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); |
| 2029 | assoc_req->mode = new_mode; |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | /* |
| 2034 | * Check if the attributes being changing require deauthentication |
| 2035 | * from the currently associated infrastructure access point. |
| 2036 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2037 | if (priv->mode == IW_MODE_INFRA) { |
| 2038 | if (should_deauth_infrastructure(priv, assoc_req)) { |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 2039 | ret = lbs_cmd_80211_deauthenticate(priv, |
| 2040 | priv->curbssparams.bssid, |
| 2041 | WLAN_REASON_DEAUTH_LEAVING); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2042 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2043 | lbs_deb_assoc("Deauthentication due to new " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2044 | "configuration request failed: %d\n", |
| 2045 | ret); |
| 2046 | } |
| 2047 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2048 | } else if (priv->mode == IW_MODE_ADHOC) { |
| 2049 | if (should_stop_adhoc(priv, assoc_req)) { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 2050 | ret = lbs_adhoc_stop(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2051 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2052 | lbs_deb_assoc("Teardown of AdHoc network due to " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2053 | "new configuration request failed: %d\n", |
| 2054 | ret); |
| 2055 | } |
| 2056 | |
| 2057 | } |
| 2058 | } |
| 2059 | |
| 2060 | /* Send the various configuration bits to the firmware */ |
| 2061 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
| 2062 | ret = assoc_helper_mode(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 2063 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2064 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2065 | } |
| 2066 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 2067 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
| 2068 | ret = assoc_helper_channel(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 2069 | if (ret) |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 2070 | goto out; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 2071 | } |
| 2072 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2073 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
| 2074 | ret = assoc_helper_secinfo(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 2075 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2076 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
| 2080 | ret = assoc_helper_wpa_ie(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 2081 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2082 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2083 | } |
| 2084 | |
John W. Linville | d3d5621 | 2010-01-27 14:23:17 -0500 | [diff] [blame] | 2085 | /* |
| 2086 | * v10 FW wants WPA keys to be set/cleared before WEP key operations, |
| 2087 | * otherwise it will fail to correctly associate to WEP networks. |
| 2088 | * Other firmware versions don't appear to care. |
| 2089 | */ |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 2090 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags) || |
| 2091 | test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2092 | ret = assoc_helper_wpa_keys(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 2093 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2094 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2095 | } |
| 2096 | |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 2097 | if (test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags) || |
| 2098 | test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) { |
Samuel Ortiz | 1625c14 | 2010-01-19 00:19:21 +0100 | [diff] [blame] | 2099 | ret = assoc_helper_wep_keys(priv, assoc_req); |
| 2100 | if (ret) |
| 2101 | goto out; |
| 2102 | } |
| 2103 | |
| 2104 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2105 | /* SSID/BSSID should be the _last_ config option set, because they |
| 2106 | * trigger the association attempt. |
| 2107 | */ |
John W. Linville | 64147c7 | 2010-01-19 17:07:41 -0500 | [diff] [blame] | 2108 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags) || |
| 2109 | test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2110 | int success = 1; |
| 2111 | |
| 2112 | ret = assoc_helper_associate(priv, assoc_req); |
| 2113 | if (ret) { |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 2114 | lbs_deb_assoc("ASSOC: association unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2115 | ret); |
| 2116 | success = 0; |
| 2117 | } |
| 2118 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2119 | if (priv->connect_status != LBS_CONNECTED) { |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 2120 | lbs_deb_assoc("ASSOC: association unsuccessful, " |
| 2121 | "not connected\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2122 | success = 0; |
| 2123 | } |
| 2124 | |
| 2125 | if (success) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2126 | lbs_deb_assoc("associated to %pM\n", |
| 2127 | priv->curbssparams.bssid); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 2128 | lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 2129 | CMD_802_11_RSSI, |
| 2130 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2131 | } else { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2132 | ret = -1; |
| 2133 | } |
| 2134 | } |
| 2135 | |
| 2136 | out: |
| 2137 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2138 | lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2139 | ret); |
| 2140 | } |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 2141 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2142 | mutex_lock(&priv->lock); |
| 2143 | priv->in_progress_assoc_req = NULL; |
| 2144 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2145 | kfree(assoc_req); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 2146 | |
| 2147 | done: |
| 2148 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | |
| 2152 | /* |
| 2153 | * Caller MUST hold any necessary locks |
| 2154 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2155 | struct assoc_request *lbs_get_association_request(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2156 | { |
| 2157 | struct assoc_request * assoc_req; |
| 2158 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 2159 | lbs_deb_enter(LBS_DEB_ASSOC); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2160 | if (!priv->pending_assoc_req) { |
| 2161 | priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request), |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 2162 | GFP_KERNEL); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2163 | if (!priv->pending_assoc_req) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2164 | lbs_pr_info("Not enough memory to allocate association" |
| 2165 | " request!\n"); |
| 2166 | return NULL; |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | /* Copy current configuration attributes to the association request, |
| 2171 | * but don't overwrite any that are already set. |
| 2172 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2173 | assoc_req = priv->pending_assoc_req; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2174 | if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2175 | memcpy(&assoc_req->ssid, &priv->curbssparams.ssid, |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 2176 | IEEE80211_MAX_SSID_LEN); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2177 | assoc_req->ssid_len = priv->curbssparams.ssid_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 2181 | assoc_req->channel = priv->channel; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2182 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 2183 | if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2184 | assoc_req->band = priv->curbssparams.band; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 2185 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2186 | if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2187 | assoc_req->mode = priv->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2188 | |
| 2189 | if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2190 | memcpy(&assoc_req->bssid, priv->curbssparams.bssid, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2191 | ETH_ALEN); |
| 2192 | } |
| 2193 | |
| 2194 | if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) { |
| 2195 | int i; |
| 2196 | for (i = 0; i < 4; i++) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2197 | memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i], |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 2198 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2199 | } |
| 2200 | } |
| 2201 | |
| 2202 | if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2203 | assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2204 | |
| 2205 | if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2206 | memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key, |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 2207 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2211 | memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key, |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 2212 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2216 | memcpy(&assoc_req->secinfo, &priv->secinfo, |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 2217 | sizeof(struct lbs_802_11_security)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2221 | memcpy(&assoc_req->wpa_ie, &priv->wpa_ie, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2222 | MAX_WPA_IE_LEN); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 2223 | assoc_req->wpa_ie_len = priv->wpa_ie_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2224 | } |
| 2225 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 2226 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2227 | return assoc_req; |
| 2228 | } |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 2229 | |
| 2230 | |
| 2231 | /** |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 2232 | * @brief Deauthenticate from a specific BSS |
| 2233 | * |
| 2234 | * @param priv A pointer to struct lbs_private structure |
| 2235 | * @param bssid The specific BSS to deauthenticate from |
| 2236 | * @param reason The 802.11 sec. 7.3.1.7 Reason Code for deauthenticating |
| 2237 | * |
| 2238 | * @return 0 on success, error on failure |
| 2239 | */ |
| 2240 | int lbs_cmd_80211_deauthenticate(struct lbs_private *priv, u8 bssid[ETH_ALEN], |
| 2241 | u16 reason) |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 2242 | { |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 2243 | struct cmd_ds_802_11_deauthenticate cmd; |
| 2244 | int ret; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 2245 | |
| 2246 | lbs_deb_enter(LBS_DEB_JOIN); |
| 2247 | |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 2248 | memset(&cmd, 0, sizeof(cmd)); |
| 2249 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 2250 | memcpy(cmd.macaddr, &bssid[0], ETH_ALEN); |
| 2251 | cmd.reasoncode = cpu_to_le16(reason); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 2252 | |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 2253 | ret = lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 2254 | |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 2255 | /* Clean up everything even if there was an error; can't assume that |
| 2256 | * we're still authenticated to the AP after trying to deauth. |
| 2257 | */ |
| 2258 | lbs_mac_event_disconnected(priv); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 2259 | |
| 2260 | lbs_deb_leave(LBS_DEB_JOIN); |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 2261 | return ret; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 2262 | } |
| 2263 | |