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