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