1 /* Copyright (C) 2006, Red Hat, Inc. */
3 #include <linux/types.h>
4 #include <linux/etherdevice.h>
5 #include <linux/ieee80211.h>
6 #include <linux/if_arp.h>
7 #include <net/lib80211.h>
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 };
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)
24 #define CAPINFO_MASK (~(0xda00))
27 * 802.11b/g supported bitrates (in 500Kb/s units)
29 u8 lbs_bg_rates[MAX_RATES] =
30 { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
35 * @brief This function finds common rates between rates and card rates.
37 * It will fill common rates in rates as output if found.
39 * NOTE: Setting the MSB of the basic rates need to be taken
40 * care, either before or after calling this function
42 * @param priv A pointer to struct lbs_private structure
43 * @param rates the buffer which keeps input and output
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
47 * @return 0 on success, or -1 on error
49 static int get_common_rates(struct lbs_private *priv,
54 u8 intersection[MAX_RATES];
55 u16 intersection_size;
58 intersection_size = min_t(u16, *rates_size, ARRAY_SIZE(intersection));
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];
68 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size);
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);
72 lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate);
74 if (!priv->enablehwauto) {
75 for (i = 0; i < num_rates; i++) {
76 if (intersection[i] == priv->cur_rate)
79 lbs_pr_alert("Previously set fixed data rate %#x isn't "
80 "compatible with the network.\n", priv->cur_rate);
85 memset(rates, 0, *rates_size);
86 *rates_size = num_rates;
87 memcpy(rates, intersection, num_rates);
93 * @brief Sets the MSB on basic rates as the firmware requires
95 * Scan through an array and set the MSB for basic data rates.
97 * @param rates buffer of data rates
98 * @param len size of buffer
100 static void lbs_set_basic_rate_flags(u8 *rates, size_t len)
104 for (i = 0; i < len; i++) {
105 if (rates[i] == 0x02 || rates[i] == 0x04 ||
106 rates[i] == 0x0b || rates[i] == 0x16)
112 static u8 iw_auth_to_ieee_auth(u8 auth)
114 if (auth == IW_AUTH_ALG_OPEN_SYSTEM)
116 else if (auth == IW_AUTH_ALG_SHARED_KEY)
118 else if (auth == IW_AUTH_ALG_LEAP)
121 lbs_deb_join("%s: invalid auth alg 0x%X\n", __func__, auth);
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.
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)
136 static int lbs_set_authentication(struct lbs_private *priv, u8 bssid[6], u8 auth)
138 struct cmd_ds_802_11_authenticate cmd;
141 lbs_deb_enter(LBS_DEB_JOIN);
143 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
144 memcpy(cmd.bssid, bssid, ETH_ALEN);
146 cmd.authtype = iw_auth_to_ieee_auth(auth);
148 lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n", bssid, cmd.authtype);
150 ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd);
152 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
157 int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
158 struct assoc_request *assoc)
160 struct cmd_ds_802_11_set_wep cmd;
163 lbs_deb_enter(LBS_DEB_CMD);
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));
169 cmd.action = cpu_to_le16(cmd_action);
171 if (cmd_action == CMD_ACT_ADD) {
174 /* default tx key index */
175 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
176 CMD_WEP_KEY_INDEX_MASK);
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];
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);
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);
196 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
203 } else if (cmd_action == CMD_ACT_REMOVE) {
204 /* ACT_REMOVE clears _all_ WEP keys */
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);
212 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
214 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
218 int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
221 struct cmd_ds_802_11_enable_rsn cmd;
224 lbs_deb_enter(LBS_DEB_CMD);
226 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
227 cmd.action = cpu_to_le16(cmd_action);
229 if (cmd_action == CMD_ACT_GET)
233 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
235 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
236 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
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);
243 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
247 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
250 lbs_deb_enter(LBS_DEB_CMD);
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);
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);
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);
269 int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
270 struct assoc_request *assoc)
272 struct cmd_ds_802_11_key_material cmd;
276 lbs_deb_enter(LBS_DEB_CMD);
278 cmd.action = cpu_to_le16(cmd_action);
279 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
281 if (cmd_action == CMD_ACT_GET) {
282 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
284 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
286 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
287 set_one_wpa_key(&cmd.keyParamSet[index],
288 &assoc->wpa_unicast_key);
292 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
293 set_one_wpa_key(&cmd.keyParamSet[index],
294 &assoc->wpa_mcast_key);
298 /* The common header and as many keys as we included */
299 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
300 keyParamSet[index]));
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];
308 while (buf_ptr < resp_end) {
309 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
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);
317 end = (void *)keyparam + sizeof(keyparam->type)
318 + sizeof(keyparam->length) + param_set_len;
320 /* Make sure we don't access past the end of the IEs */
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;
331 /* Copy returned key into driver */
332 memset(key, 0, sizeof(struct enc_key));
333 if (key_len > sizeof(key->key))
335 key->type = key_type;
336 key->flags = key_flags;
338 memcpy(key->key, keyparam->key, key->len);
344 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
348 static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
368 int i = lbs_data_rate_to_fw_index(rate);
370 ratemask = (0x1fef >> (12 - i));
373 return cpu_to_le16(ratemask);
376 int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
379 struct cmd_ds_802_11_rate_adapt_rateset cmd;
382 lbs_deb_enter(LBS_DEB_CMD);
384 if (!priv->cur_rate && !priv->enablehwauto)
387 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
389 cmd.action = cpu_to_le16(cmd_action);
390 cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
391 cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
392 ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
393 if (!ret && cmd_action == CMD_ACT_GET) {
394 priv->ratebitmap = le16_to_cpu(cmd.bitmap);
395 priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
398 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
403 * @brief Set the data rate
405 * @param priv A pointer to struct lbs_private structure
406 * @param rate The desired data rate, or 0 to clear a locked rate
408 * @return 0 on success, error on failure
410 int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
412 struct cmd_ds_802_11_data_rate cmd;
415 lbs_deb_enter(LBS_DEB_CMD);
417 memset(&cmd, 0, sizeof(cmd));
418 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
421 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
422 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
423 if (cmd.rates[0] == 0) {
424 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
429 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
431 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
432 lbs_deb_cmd("DATA_RATE: setting auto\n");
435 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
439 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof(cmd));
441 /* FIXME: get actual rates FW can do if this command actually returns
442 * all data rates supported.
444 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
445 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
448 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
453 int lbs_cmd_802_11_rssi(struct lbs_private *priv,
454 struct cmd_ds_command *cmd)
457 lbs_deb_enter(LBS_DEB_CMD);
458 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
459 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
460 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
462 /* reset Beacon SNR/NF/RSSI values */
463 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
464 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
465 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
466 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
467 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
468 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
470 lbs_deb_leave(LBS_DEB_CMD);
474 int lbs_ret_802_11_rssi(struct lbs_private *priv,
475 struct cmd_ds_command *resp)
477 struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
479 lbs_deb_enter(LBS_DEB_CMD);
481 /* store the non average value */
482 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = get_unaligned_le16(&rssirsp->SNR);
483 priv->NF[TYPE_BEACON][TYPE_NOAVG] =
484 get_unaligned_le16(&rssirsp->noisefloor);
486 priv->SNR[TYPE_BEACON][TYPE_AVG] = get_unaligned_le16(&rssirsp->avgSNR);
487 priv->NF[TYPE_BEACON][TYPE_AVG] =
488 get_unaligned_le16(&rssirsp->avgnoisefloor);
490 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] =
491 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
492 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
494 priv->RSSI[TYPE_BEACON][TYPE_AVG] =
495 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
496 priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
498 lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
499 priv->RSSI[TYPE_BEACON][TYPE_NOAVG],
500 priv->RSSI[TYPE_BEACON][TYPE_AVG]);
502 lbs_deb_leave(LBS_DEB_CMD);
507 int lbs_cmd_bcn_ctrl(struct lbs_private *priv,
508 struct cmd_ds_command *cmd,
511 struct cmd_ds_802_11_beacon_control
512 *bcn_ctrl = &cmd->params.bcn_ctrl;
514 lbs_deb_enter(LBS_DEB_CMD);
516 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
518 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
520 bcn_ctrl->action = cpu_to_le16(cmd_action);
521 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
522 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
524 lbs_deb_leave(LBS_DEB_CMD);
528 int lbs_ret_802_11_bcn_ctrl(struct lbs_private *priv,
529 struct cmd_ds_command *resp)
531 struct cmd_ds_802_11_beacon_control *bcn_ctrl =
532 &resp->params.bcn_ctrl;
534 lbs_deb_enter(LBS_DEB_CMD);
536 if (bcn_ctrl->action == CMD_ACT_GET) {
537 priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable);
538 priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period);
541 lbs_deb_enter(LBS_DEB_CMD);
547 static int lbs_assoc_post(struct lbs_private *priv,
548 struct cmd_ds_802_11_associate_response *resp)
551 union iwreq_data wrqu;
552 struct bss_descriptor *bss;
555 lbs_deb_enter(LBS_DEB_ASSOC);
557 if (!priv->in_progress_assoc_req) {
558 lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n");
562 bss = &priv->in_progress_assoc_req->bss;
565 * Older FW versions map the IEEE 802.11 Status Code in the association
566 * response to the following values returned in resp->statuscode:
568 * IEEE Status Code Marvell Status Code
569 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
570 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
571 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
572 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
573 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
574 * others -> 0x0003 ASSOC_RESULT_REFUSED
576 * Other response codes:
577 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
578 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
579 * association response from the AP)
582 status_code = le16_to_cpu(resp->statuscode);
583 if (priv->fwrelease < 0x09000000) {
584 switch (status_code) {
588 lbs_deb_assoc("ASSOC_RESP: invalid parameters\n");
591 lbs_deb_assoc("ASSOC_RESP: internal timer "
592 "expired while waiting for the AP\n");
595 lbs_deb_assoc("ASSOC_RESP: association "
599 lbs_deb_assoc("ASSOC_RESP: authentication "
603 lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x "
604 " unknown\n", status_code);
608 /* v9+ returns the AP's association response */
609 lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x\n", status_code);
613 lbs_mac_event_disconnected(priv);
618 lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP",
619 (void *) (resp + sizeof (resp->hdr)),
620 le16_to_cpu(resp->hdr.size) - sizeof (resp->hdr));
622 /* Send a Media Connected event, according to the Spec */
623 priv->connect_status = LBS_CONNECTED;
625 /* Update current SSID and BSSID */
626 memcpy(&priv->curbssparams.ssid, &bss->ssid, IEEE80211_MAX_SSID_LEN);
627 priv->curbssparams.ssid_len = bss->ssid_len;
628 memcpy(priv->curbssparams.bssid, bss->bssid, ETH_ALEN);
630 priv->SNR[TYPE_RXPD][TYPE_AVG] = 0;
631 priv->NF[TYPE_RXPD][TYPE_AVG] = 0;
633 memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR));
634 memset(priv->rawNF, 0x00, sizeof(priv->rawNF));
638 netif_carrier_on(priv->dev);
639 if (!priv->tx_pending_len)
640 netif_wake_queue(priv->dev);
642 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN);
643 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
644 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
647 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
652 * @brief This function prepares an association-class command.
654 * @param priv A pointer to struct lbs_private structure
655 * @param assoc_req The association request describing the BSS to associate
656 * or reassociate with
657 * @param command The actual command, either CMD_802_11_ASSOCIATE or
658 * CMD_802_11_REASSOCIATE
662 static int lbs_associate(struct lbs_private *priv,
663 struct assoc_request *assoc_req,
666 struct cmd_ds_802_11_associate cmd;
668 struct bss_descriptor *bss = &assoc_req->bss;
669 u8 *pos = &(cmd.iebuf[0]);
670 u16 tmpcap, tmplen, tmpauth;
671 struct mrvl_ie_ssid_param_set *ssid;
672 struct mrvl_ie_ds_param_set *ds;
673 struct mrvl_ie_cf_param_set *cf;
674 struct mrvl_ie_rates_param_set *rates;
675 struct mrvl_ie_rsn_param_set *rsn;
676 struct mrvl_ie_auth_type *auth;
678 lbs_deb_enter(LBS_DEB_ASSOC);
680 BUG_ON((command != CMD_802_11_ASSOCIATE) &&
681 (command != CMD_802_11_REASSOCIATE));
683 memset(&cmd, 0, sizeof(cmd));
684 cmd.hdr.command = cpu_to_le16(command);
686 /* Fill in static fields */
687 memcpy(cmd.bssid, bss->bssid, ETH_ALEN);
688 cmd.listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
690 /* Capability info */
691 tmpcap = (bss->capability & CAPINFO_MASK);
692 if (bss->mode == IW_MODE_INFRA)
693 tmpcap |= WLAN_CAPABILITY_ESS;
694 cmd.capability = cpu_to_le16(tmpcap);
695 lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap);
698 ssid = (struct mrvl_ie_ssid_param_set *) pos;
699 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
700 tmplen = bss->ssid_len;
701 ssid->header.len = cpu_to_le16(tmplen);
702 memcpy(ssid->ssid, bss->ssid, tmplen);
703 pos += sizeof(ssid->header) + tmplen;
705 ds = (struct mrvl_ie_ds_param_set *) pos;
706 ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
707 ds->header.len = cpu_to_le16(1);
708 ds->channel = bss->phy.ds.channel;
709 pos += sizeof(ds->header) + 1;
711 cf = (struct mrvl_ie_cf_param_set *) pos;
712 cf->header.type = cpu_to_le16(TLV_TYPE_CF);
713 tmplen = sizeof(*cf) - sizeof (cf->header);
714 cf->header.len = cpu_to_le16(tmplen);
715 /* IE payload should be zeroed, firmware fills it in for us */
718 rates = (struct mrvl_ie_rates_param_set *) pos;
719 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
720 tmplen = min_t(u16, ARRAY_SIZE(bss->rates), MAX_RATES);
721 memcpy(&rates->rates, &bss->rates, tmplen);
722 if (get_common_rates(priv, rates->rates, &tmplen)) {
726 pos += sizeof(rates->header) + tmplen;
727 rates->header.len = cpu_to_le16(tmplen);
728 lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen);
730 /* Copy the infra. association rates into Current BSS state structure */
731 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
732 memcpy(&priv->curbssparams.rates, &rates->rates, tmplen);
734 /* Set MSB on basic rates as the firmware requires, but _after_
735 * copying to current bss rates.
737 lbs_set_basic_rate_flags(rates->rates, tmplen);
739 /* Firmware v9+ indicate authentication suites as a TLV */
740 if (priv->fwrelease >= 0x09000000) {
741 auth = (struct mrvl_ie_auth_type *) pos;
742 auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
743 auth->header.len = cpu_to_le16(2);
744 tmpauth = iw_auth_to_ieee_auth(priv->secinfo.auth_mode);
745 auth->auth = cpu_to_le16(tmpauth);
746 pos += sizeof(auth->header) + 2;
748 lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n",
749 bss->bssid, priv->secinfo.auth_mode);
753 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
754 rsn = (struct mrvl_ie_rsn_param_set *) pos;
755 /* WPA_IE or WPA2_IE */
756 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
757 tmplen = (u16) assoc_req->wpa_ie[1];
758 rsn->header.len = cpu_to_le16(tmplen);
759 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
760 lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: WPA/RSN IE", (u8 *) rsn,
761 sizeof(rsn->header) + tmplen);
762 pos += sizeof(rsn->header) + tmplen;
765 cmd.hdr.size = cpu_to_le16((sizeof(cmd) - sizeof(cmd.iebuf)) +
766 (u16)(pos - (u8 *) &cmd.iebuf));
768 /* update curbssparams */
769 priv->channel = bss->phy.ds.channel;
771 ret = lbs_cmd_with_response(priv, command, &cmd);
773 ret = lbs_assoc_post(priv,
774 (struct cmd_ds_802_11_associate_response *) &cmd);
778 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
783 * @brief Associate to a specific BSS discovered in a scan
785 * @param priv A pointer to struct lbs_private structure
786 * @param assoc_req The association request describing the BSS to associate with
788 * @return 0-success, otherwise fail
790 static int lbs_try_associate(struct lbs_private *priv,
791 struct assoc_request *assoc_req)
794 u8 preamble = RADIO_PREAMBLE_LONG;
796 lbs_deb_enter(LBS_DEB_ASSOC);
798 /* FW v9 and higher indicate authentication suites as a TLV in the
799 * association command, not as a separate authentication command.
801 if (priv->fwrelease < 0x09000000) {
802 ret = lbs_set_authentication(priv, assoc_req->bss.bssid,
803 priv->secinfo.auth_mode);
808 /* Use short preamble only when both the BSS and firmware support it */
809 if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
810 (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
811 preamble = RADIO_PREAMBLE_SHORT;
813 ret = lbs_set_radio(priv, preamble, 1);
817 ret = lbs_associate(priv, assoc_req, CMD_802_11_ASSOCIATE);
820 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
824 static int lbs_adhoc_post(struct lbs_private *priv,
825 struct cmd_ds_802_11_ad_hoc_result *resp)
828 u16 command = le16_to_cpu(resp->hdr.command);
829 u16 result = le16_to_cpu(resp->hdr.result);
830 union iwreq_data wrqu;
831 struct bss_descriptor *bss;
832 DECLARE_SSID_BUF(ssid);
834 lbs_deb_enter(LBS_DEB_JOIN);
836 if (!priv->in_progress_assoc_req) {
837 lbs_deb_join("ADHOC_RESP: no in-progress association "
842 bss = &priv->in_progress_assoc_req->bss;
845 * Join result code 0 --> SUCCESS
848 lbs_deb_join("ADHOC_RESP: failed (result 0x%X)\n", result);
849 if (priv->connect_status == LBS_CONNECTED)
850 lbs_mac_event_disconnected(priv);
855 /* Send a Media Connected event, according to the Spec */
856 priv->connect_status = LBS_CONNECTED;
858 if (command == CMD_RET(CMD_802_11_AD_HOC_START)) {
859 /* Update the created network descriptor with the new BSSID */
860 memcpy(bss->bssid, resp->bssid, ETH_ALEN);
863 /* Set the BSSID from the joined/started descriptor */
864 memcpy(&priv->curbssparams.bssid, bss->bssid, ETH_ALEN);
866 /* Set the new SSID to current SSID */
867 memcpy(&priv->curbssparams.ssid, &bss->ssid, IEEE80211_MAX_SSID_LEN);
868 priv->curbssparams.ssid_len = bss->ssid_len;
870 netif_carrier_on(priv->dev);
871 if (!priv->tx_pending_len)
872 netif_wake_queue(priv->dev);
874 memset(&wrqu, 0, sizeof(wrqu));
875 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN);
876 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
877 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
879 lbs_deb_join("ADHOC_RESP: Joined/started '%s', BSSID %pM, channel %d\n",
880 print_ssid(ssid, bss->ssid, bss->ssid_len),
881 priv->curbssparams.bssid,
885 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
890 * @brief Join an adhoc network found in a previous scan
892 * @param priv A pointer to struct lbs_private structure
893 * @param assoc_req The association request describing the BSS to join
895 * @return 0 on success, error on failure
897 static int lbs_adhoc_join(struct lbs_private *priv,
898 struct assoc_request *assoc_req)
900 struct cmd_ds_802_11_ad_hoc_join cmd;
901 struct bss_descriptor *bss = &assoc_req->bss;
902 u8 preamble = RADIO_PREAMBLE_LONG;
903 DECLARE_SSID_BUF(ssid);
907 lbs_deb_enter(LBS_DEB_ASSOC);
909 lbs_deb_join("current SSID '%s', ssid length %u\n",
910 print_ssid(ssid, priv->curbssparams.ssid,
911 priv->curbssparams.ssid_len),
912 priv->curbssparams.ssid_len);
913 lbs_deb_join("requested ssid '%s', ssid length %u\n",
914 print_ssid(ssid, bss->ssid, bss->ssid_len),
917 /* check if the requested SSID is already joined */
918 if (priv->curbssparams.ssid_len &&
919 !lbs_ssid_cmp(priv->curbssparams.ssid,
920 priv->curbssparams.ssid_len,
921 bss->ssid, bss->ssid_len) &&
922 (priv->mode == IW_MODE_ADHOC) &&
923 (priv->connect_status == LBS_CONNECTED)) {
924 union iwreq_data wrqu;
926 lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as "
927 "current, not attempting to re-join");
929 /* Send the re-association event though, because the association
930 * request really was successful, even if just a null-op.
932 memset(&wrqu, 0, sizeof(wrqu));
933 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid,
935 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
936 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
940 /* Use short preamble only when both the BSS and firmware support it */
941 if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
942 (bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
943 lbs_deb_join("AdhocJoin: Short preamble\n");
944 preamble = RADIO_PREAMBLE_SHORT;
947 ret = lbs_set_radio(priv, preamble, 1);
951 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
952 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
954 priv->adhoccreate = 0;
955 priv->channel = bss->channel;
957 /* Build the join command */
958 memset(&cmd, 0, sizeof(cmd));
959 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
961 cmd.bss.type = CMD_BSS_TYPE_IBSS;
962 cmd.bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
964 memcpy(&cmd.bss.bssid, &bss->bssid, ETH_ALEN);
965 memcpy(&cmd.bss.ssid, &bss->ssid, bss->ssid_len);
967 memcpy(&cmd.bss.ds, &bss->phy.ds, sizeof(struct ieee_ie_ds_param_set));
969 memcpy(&cmd.bss.ibss, &bss->ss.ibss,
970 sizeof(struct ieee_ie_ibss_param_set));
972 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
973 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
974 bss->capability, CAPINFO_MASK);
976 /* information on BSSID descriptor passed to FW */
977 lbs_deb_join("ADHOC_J_CMD: BSSID = %pM, SSID = '%s'\n",
978 cmd.bss.bssid, cmd.bss.ssid);
980 /* Only v8 and below support setting these */
981 if (priv->fwrelease < 0x09000000) {
983 cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
985 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
988 /* Copy Data rates from the rates recorded in scan response */
989 memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates));
990 ratesize = min_t(u16, ARRAY_SIZE(cmd.bss.rates), ARRAY_SIZE (bss->rates));
991 memcpy(cmd.bss.rates, bss->rates, ratesize);
992 if (get_common_rates(priv, cmd.bss.rates, &ratesize)) {
993 lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n");
998 /* Copy the ad-hoc creation rates into Current BSS state structure */
999 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
1000 memcpy(&priv->curbssparams.rates, cmd.bss.rates, ratesize);
1002 /* Set MSB on basic rates as the firmware requires, but _after_
1003 * copying to current bss rates.
1005 lbs_set_basic_rate_flags(cmd.bss.rates, ratesize);
1007 cmd.bss.ibss.atimwindow = bss->atimwindow;
1009 if (assoc_req->secinfo.wep_enabled) {
1010 u16 tmp = le16_to_cpu(cmd.bss.capability);
1011 tmp |= WLAN_CAPABILITY_PRIVACY;
1012 cmd.bss.capability = cpu_to_le16(tmp);
1015 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1016 __le32 local_ps_mode = cpu_to_le32(LBS802_11POWERMODECAM);
1019 ret = lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1028 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
1030 ret = lbs_adhoc_post(priv,
1031 (struct cmd_ds_802_11_ad_hoc_result *)&cmd);
1035 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1040 * @brief Start an Adhoc Network
1042 * @param priv A pointer to struct lbs_private structure
1043 * @param assoc_req The association request describing the BSS to start
1045 * @return 0 on success, error on failure
1047 static int lbs_adhoc_start(struct lbs_private *priv,
1048 struct assoc_request *assoc_req)
1050 struct cmd_ds_802_11_ad_hoc_start cmd;
1051 u8 preamble = RADIO_PREAMBLE_LONG;
1052 size_t ratesize = 0;
1055 DECLARE_SSID_BUF(ssid);
1057 lbs_deb_enter(LBS_DEB_ASSOC);
1059 if (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
1060 lbs_deb_join("ADHOC_START: Will use short preamble\n");
1061 preamble = RADIO_PREAMBLE_SHORT;
1064 ret = lbs_set_radio(priv, preamble, 1);
1068 /* Build the start command */
1069 memset(&cmd, 0, sizeof(cmd));
1070 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1072 memcpy(cmd.ssid, assoc_req->ssid, assoc_req->ssid_len);
1074 lbs_deb_join("ADHOC_START: SSID '%s', ssid length %u\n",
1075 print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len),
1076 assoc_req->ssid_len);
1078 cmd.bsstype = CMD_BSS_TYPE_IBSS;
1080 if (priv->beacon_period == 0)
1081 priv->beacon_period = MRVDRV_BEACON_INTERVAL;
1082 cmd.beaconperiod = cpu_to_le16(priv->beacon_period);
1084 WARN_ON(!assoc_req->channel);
1086 /* set Physical parameter set */
1087 cmd.ds.header.id = WLAN_EID_DS_PARAMS;
1088 cmd.ds.header.len = 1;
1089 cmd.ds.channel = assoc_req->channel;
1091 /* set IBSS parameter set */
1092 cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1093 cmd.ibss.header.len = 2;
1094 cmd.ibss.atimwindow = cpu_to_le16(0);
1096 /* set capability info */
1097 tmpcap = WLAN_CAPABILITY_IBSS;
1098 if (assoc_req->secinfo.wep_enabled ||
1099 assoc_req->secinfo.WPAenabled ||
1100 assoc_req->secinfo.WPA2enabled) {
1101 lbs_deb_join("ADHOC_START: WEP/WPA enabled, privacy on\n");
1102 tmpcap |= WLAN_CAPABILITY_PRIVACY;
1104 lbs_deb_join("ADHOC_START: WEP disabled, privacy off\n");
1106 cmd.capability = cpu_to_le16(tmpcap);
1108 /* Only v8 and below support setting probe delay */
1109 if (priv->fwrelease < 0x09000000)
1110 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1112 ratesize = min(sizeof(cmd.rates), sizeof(lbs_bg_rates));
1113 memcpy(cmd.rates, lbs_bg_rates, ratesize);
1115 /* Copy the ad-hoc creating rates into Current BSS state structure */
1116 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
1117 memcpy(&priv->curbssparams.rates, &cmd.rates, ratesize);
1119 /* Set MSB on basic rates as the firmware requires, but _after_
1120 * copying to current bss rates.
1122 lbs_set_basic_rate_flags(cmd.rates, ratesize);
1124 lbs_deb_join("ADHOC_START: rates=%02x %02x %02x %02x\n",
1125 cmd.rates[0], cmd.rates[1], cmd.rates[2], cmd.rates[3]);
1127 lbs_deb_join("ADHOC_START: Starting Ad-Hoc BSS on channel %d, band %d\n",
1128 assoc_req->channel, assoc_req->band);
1130 priv->adhoccreate = 1;
1131 priv->mode = IW_MODE_ADHOC;
1133 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
1135 ret = lbs_adhoc_post(priv,
1136 (struct cmd_ds_802_11_ad_hoc_result *)&cmd);
1139 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1144 * @brief Stop and Ad-Hoc network and exit Ad-Hoc mode
1146 * @param priv A pointer to struct lbs_private structure
1147 * @return 0 on success, or an error
1149 int lbs_adhoc_stop(struct lbs_private *priv)
1151 struct cmd_ds_802_11_ad_hoc_stop cmd;
1154 lbs_deb_enter(LBS_DEB_JOIN);
1156 memset(&cmd, 0, sizeof (cmd));
1157 cmd.hdr.size = cpu_to_le16 (sizeof (cmd));
1159 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
1161 /* Clean up everything even if there was an error */
1162 lbs_mac_event_disconnected(priv);
1164 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1168 static inline int match_bss_no_security(struct lbs_802_11_security *secinfo,
1169 struct bss_descriptor *match_bss)
1171 if (!secinfo->wep_enabled && !secinfo->WPAenabled
1172 && !secinfo->WPA2enabled
1173 && match_bss->wpa_ie[0] != WLAN_EID_GENERIC
1174 && match_bss->rsn_ie[0] != WLAN_EID_RSN
1175 && !(match_bss->capability & WLAN_CAPABILITY_PRIVACY))
1181 static inline int match_bss_static_wep(struct lbs_802_11_security *secinfo,
1182 struct bss_descriptor *match_bss)
1184 if (secinfo->wep_enabled && !secinfo->WPAenabled
1185 && !secinfo->WPA2enabled
1186 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY))
1192 static inline int match_bss_wpa(struct lbs_802_11_security *secinfo,
1193 struct bss_descriptor *match_bss)
1195 if (!secinfo->wep_enabled && secinfo->WPAenabled
1196 && (match_bss->wpa_ie[0] == WLAN_EID_GENERIC)
1197 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
1198 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
1205 static inline int match_bss_wpa2(struct lbs_802_11_security *secinfo,
1206 struct bss_descriptor *match_bss)
1208 if (!secinfo->wep_enabled && secinfo->WPA2enabled &&
1209 (match_bss->rsn_ie[0] == WLAN_EID_RSN)
1210 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
1211 (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
1218 static inline int match_bss_dynamic_wep(struct lbs_802_11_security *secinfo,
1219 struct bss_descriptor *match_bss)
1221 if (!secinfo->wep_enabled && !secinfo->WPAenabled
1222 && !secinfo->WPA2enabled
1223 && (match_bss->wpa_ie[0] != WLAN_EID_GENERIC)
1224 && (match_bss->rsn_ie[0] != WLAN_EID_RSN)
1225 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY))
1232 * @brief Check if a scanned network compatible with the driver settings
1234 * WEP WPA WPA2 ad-hoc encrypt Network
1235 * enabled enabled enabled AES mode privacy WPA WPA2 Compatible
1236 * 0 0 0 0 NONE 0 0 0 yes No security
1237 * 1 0 0 0 NONE 1 0 0 yes Static WEP
1238 * 0 1 0 0 x 1x 1 x yes WPA
1239 * 0 0 1 0 x 1x x 1 yes WPA2
1240 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
1241 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
1244 * @param priv A pointer to struct lbs_private
1245 * @param index Index in scantable to check against current driver settings
1246 * @param mode Network mode: Infrastructure or IBSS
1248 * @return Index in scantable, or error code if negative
1250 static int is_network_compatible(struct lbs_private *priv,
1251 struct bss_descriptor *bss, uint8_t mode)
1255 lbs_deb_enter(LBS_DEB_SCAN);
1257 if (bss->mode != mode)
1260 matched = match_bss_no_security(&priv->secinfo, bss);
1263 matched = match_bss_static_wep(&priv->secinfo, bss);
1266 matched = match_bss_wpa(&priv->secinfo, bss);
1268 lbs_deb_scan("is_network_compatible() WPA: wpa_ie 0x%x "
1269 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
1270 "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0],
1271 priv->secinfo.wep_enabled ? "e" : "d",
1272 priv->secinfo.WPAenabled ? "e" : "d",
1273 priv->secinfo.WPA2enabled ? "e" : "d",
1274 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1277 matched = match_bss_wpa2(&priv->secinfo, bss);
1279 lbs_deb_scan("is_network_compatible() WPA2: wpa_ie 0x%x "
1280 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
1281 "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0],
1282 priv->secinfo.wep_enabled ? "e" : "d",
1283 priv->secinfo.WPAenabled ? "e" : "d",
1284 priv->secinfo.WPA2enabled ? "e" : "d",
1285 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1288 matched = match_bss_dynamic_wep(&priv->secinfo, bss);
1290 lbs_deb_scan("is_network_compatible() dynamic WEP: "
1291 "wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n",
1292 bss->wpa_ie[0], bss->rsn_ie[0],
1293 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1297 /* bss security settings don't match those configured on card */
1298 lbs_deb_scan("is_network_compatible() FAILED: wpa_ie 0x%x "
1299 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n",
1300 bss->wpa_ie[0], bss->rsn_ie[0],
1301 priv->secinfo.wep_enabled ? "e" : "d",
1302 priv->secinfo.WPAenabled ? "e" : "d",
1303 priv->secinfo.WPA2enabled ? "e" : "d",
1304 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1307 lbs_deb_leave_args(LBS_DEB_SCAN, "matched: %d", matched);
1312 * @brief This function finds a specific compatible BSSID in the scan list
1314 * Used in association code
1316 * @param priv A pointer to struct lbs_private
1317 * @param bssid BSSID to find in the scan list
1318 * @param mode Network mode: Infrastructure or IBSS
1320 * @return index in BSSID list, or error return code (< 0)
1322 static struct bss_descriptor *lbs_find_bssid_in_list(struct lbs_private *priv,
1323 uint8_t *bssid, uint8_t mode)
1325 struct bss_descriptor *iter_bss;
1326 struct bss_descriptor *found_bss = NULL;
1328 lbs_deb_enter(LBS_DEB_SCAN);
1333 lbs_deb_hex(LBS_DEB_SCAN, "looking for", bssid, ETH_ALEN);
1335 /* Look through the scan table for a compatible match. The loop will
1336 * continue past a matched bssid that is not compatible in case there
1337 * is an AP with multiple SSIDs assigned to the same BSSID
1339 mutex_lock(&priv->lock);
1340 list_for_each_entry(iter_bss, &priv->network_list, list) {
1341 if (compare_ether_addr(iter_bss->bssid, bssid))
1342 continue; /* bssid doesn't match */
1346 if (!is_network_compatible(priv, iter_bss, mode))
1348 found_bss = iter_bss;
1351 found_bss = iter_bss;
1355 mutex_unlock(&priv->lock);
1358 lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss);
1363 * @brief This function finds ssid in ssid list.
1365 * Used in association code
1367 * @param priv A pointer to struct lbs_private
1368 * @param ssid SSID to find in the list
1369 * @param bssid BSSID to qualify the SSID selection (if provided)
1370 * @param mode Network mode: Infrastructure or IBSS
1372 * @return index in BSSID list
1374 static struct bss_descriptor *lbs_find_ssid_in_list(struct lbs_private *priv,
1375 uint8_t *ssid, uint8_t ssid_len,
1376 uint8_t *bssid, uint8_t mode,
1380 struct bss_descriptor *iter_bss = NULL;
1381 struct bss_descriptor *found_bss = NULL;
1382 struct bss_descriptor *tmp_oldest = NULL;
1384 lbs_deb_enter(LBS_DEB_SCAN);
1386 mutex_lock(&priv->lock);
1388 list_for_each_entry(iter_bss, &priv->network_list, list) {
1390 (iter_bss->last_scanned < tmp_oldest->last_scanned))
1391 tmp_oldest = iter_bss;
1393 if (lbs_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len,
1394 ssid, ssid_len) != 0)
1395 continue; /* ssid doesn't match */
1396 if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0)
1397 continue; /* bssid doesn't match */
1398 if ((channel > 0) && (iter_bss->channel != channel))
1399 continue; /* channel doesn't match */
1404 if (!is_network_compatible(priv, iter_bss, mode))
1408 /* Found requested BSSID */
1409 found_bss = iter_bss;
1413 if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
1414 bestrssi = SCAN_RSSI(iter_bss->rssi);
1415 found_bss = iter_bss;
1420 if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
1421 bestrssi = SCAN_RSSI(iter_bss->rssi);
1422 found_bss = iter_bss;
1429 mutex_unlock(&priv->lock);
1430 lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss);
1434 static int assoc_helper_essid(struct lbs_private *priv,
1435 struct assoc_request * assoc_req)
1438 struct bss_descriptor * bss;
1440 DECLARE_SSID_BUF(ssid);
1442 lbs_deb_enter(LBS_DEB_ASSOC);
1444 /* FIXME: take channel into account when picking SSIDs if a channel
1448 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
1449 channel = assoc_req->channel;
1451 lbs_deb_assoc("SSID '%s' requested\n",
1452 print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len));
1453 if (assoc_req->mode == IW_MODE_INFRA) {
1454 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
1455 assoc_req->ssid_len);
1457 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
1458 assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
1460 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
1461 ret = lbs_try_associate(priv, assoc_req);
1463 lbs_deb_assoc("SSID not found; cannot associate\n");
1465 } else if (assoc_req->mode == IW_MODE_ADHOC) {
1466 /* Scan for the network, do not save previous results. Stale
1467 * scan data will cause us to join a non-existant adhoc network
1469 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
1470 assoc_req->ssid_len);
1472 /* Search for the requested SSID in the scan table */
1473 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
1474 assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
1476 lbs_deb_assoc("SSID found, will join\n");
1477 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
1478 lbs_adhoc_join(priv, assoc_req);
1480 /* else send START command */
1481 lbs_deb_assoc("SSID not found, creating adhoc network\n");
1482 memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
1483 IEEE80211_MAX_SSID_LEN);
1484 assoc_req->bss.ssid_len = assoc_req->ssid_len;
1485 lbs_adhoc_start(priv, assoc_req);
1489 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1494 static int assoc_helper_bssid(struct lbs_private *priv,
1495 struct assoc_request * assoc_req)
1498 struct bss_descriptor * bss;
1500 lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %pM", assoc_req->bssid);
1502 /* Search for index position in list for requested MAC */
1503 bss = lbs_find_bssid_in_list(priv, assoc_req->bssid,
1506 lbs_deb_assoc("ASSOC: WAP: BSSID %pM not found, "
1507 "cannot associate.\n", assoc_req->bssid);
1511 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
1512 if (assoc_req->mode == IW_MODE_INFRA) {
1513 ret = lbs_try_associate(priv, assoc_req);
1514 lbs_deb_assoc("ASSOC: lbs_try_associate(bssid) returned %d\n",
1516 } else if (assoc_req->mode == IW_MODE_ADHOC) {
1517 lbs_adhoc_join(priv, assoc_req);
1521 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1526 static int assoc_helper_associate(struct lbs_private *priv,
1527 struct assoc_request * assoc_req)
1529 int ret = 0, done = 0;
1531 lbs_deb_enter(LBS_DEB_ASSOC);
1533 /* If we're given and 'any' BSSID, try associating based on SSID */
1535 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
1536 if (compare_ether_addr(bssid_any, assoc_req->bssid)
1537 && compare_ether_addr(bssid_off, assoc_req->bssid)) {
1538 ret = assoc_helper_bssid(priv, assoc_req);
1543 if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
1544 ret = assoc_helper_essid(priv, assoc_req);
1547 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1552 static int assoc_helper_mode(struct lbs_private *priv,
1553 struct assoc_request * assoc_req)
1557 lbs_deb_enter(LBS_DEB_ASSOC);
1559 if (assoc_req->mode == priv->mode)
1562 if (assoc_req->mode == IW_MODE_INFRA) {
1563 if (priv->psstate != PS_STATE_FULL_POWER)
1564 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
1565 priv->psmode = LBS802_11POWERMODECAM;
1568 priv->mode = assoc_req->mode;
1569 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, assoc_req->mode);
1572 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1576 static int assoc_helper_channel(struct lbs_private *priv,
1577 struct assoc_request * assoc_req)
1581 lbs_deb_enter(LBS_DEB_ASSOC);
1583 ret = lbs_update_channel(priv);
1585 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
1589 if (assoc_req->channel == priv->channel)
1592 if (priv->mesh_dev) {
1593 /* Change mesh channel first; 21.p21 firmware won't let
1594 you change channel otherwise (even though it'll return
1596 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP,
1597 assoc_req->channel);
1600 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
1601 priv->channel, assoc_req->channel);
1603 ret = lbs_set_channel(priv, assoc_req->channel);
1605 lbs_deb_assoc("ASSOC: channel: error setting channel.\n");
1607 /* FIXME: shouldn't need to grab the channel _again_ after setting
1608 * it since the firmware is supposed to return the new channel, but
1610 ret = lbs_update_channel(priv);
1612 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
1616 if (assoc_req->channel != priv->channel) {
1617 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n",
1618 assoc_req->channel);
1622 if ( assoc_req->secinfo.wep_enabled
1623 && (assoc_req->wep_keys[0].len
1624 || assoc_req->wep_keys[1].len
1625 || assoc_req->wep_keys[2].len
1626 || assoc_req->wep_keys[3].len)) {
1627 /* Make sure WEP keys are re-sent to firmware */
1628 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1631 /* Must restart/rejoin adhoc networks after channel change */
1632 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
1636 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
1640 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1645 static int assoc_helper_wep_keys(struct lbs_private *priv,
1646 struct assoc_request *assoc_req)
1651 lbs_deb_enter(LBS_DEB_ASSOC);
1653 /* Set or remove WEP keys */
1654 if (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len ||
1655 assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len)
1656 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_ADD, assoc_req);
1658 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_REMOVE, assoc_req);
1663 /* enable/disable the MAC's WEP packet filter */
1664 if (assoc_req->secinfo.wep_enabled)
1665 priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
1667 priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
1669 lbs_set_mac_control(priv);
1671 mutex_lock(&priv->lock);
1673 /* Copy WEP keys into priv wep key fields */
1674 for (i = 0; i < 4; i++) {
1675 memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i],
1676 sizeof(struct enc_key));
1678 priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
1680 mutex_unlock(&priv->lock);
1683 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1687 static int assoc_helper_secinfo(struct lbs_private *priv,
1688 struct assoc_request * assoc_req)
1694 lbs_deb_enter(LBS_DEB_ASSOC);
1696 memcpy(&priv->secinfo, &assoc_req->secinfo,
1697 sizeof(struct lbs_802_11_security));
1699 lbs_set_mac_control(priv);
1701 /* If RSN is already enabled, don't try to enable it again, since
1702 * ENABLE_RSN resets internal state machines and will clobber the
1703 * 4-way WPA handshake.
1706 /* Get RSN enabled/disabled */
1707 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn);
1709 lbs_deb_assoc("Failed to get RSN status: %d\n", ret);
1713 /* Don't re-enable RSN if it's already enabled */
1714 do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled;
1718 /* Set RSN enabled/disabled */
1719 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa);
1722 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1727 static int assoc_helper_wpa_keys(struct lbs_private *priv,
1728 struct assoc_request * assoc_req)
1731 unsigned int flags = assoc_req->flags;
1733 lbs_deb_enter(LBS_DEB_ASSOC);
1735 /* Work around older firmware bug where WPA unicast and multicast
1736 * keys must be set independently. Seen in SDIO parts with firmware
1740 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
1741 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1742 ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
1743 assoc_req->flags = flags;
1749 memcpy(&priv->wpa_unicast_key, &assoc_req->wpa_unicast_key,
1750 sizeof(struct enc_key));
1752 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
1753 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1755 ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
1756 assoc_req->flags = flags;
1758 memcpy(&priv->wpa_mcast_key, &assoc_req->wpa_mcast_key,
1759 sizeof(struct enc_key));
1763 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1768 static int assoc_helper_wpa_ie(struct lbs_private *priv,
1769 struct assoc_request * assoc_req)
1773 lbs_deb_enter(LBS_DEB_ASSOC);
1775 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
1776 memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
1777 priv->wpa_ie_len = assoc_req->wpa_ie_len;
1779 memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
1780 priv->wpa_ie_len = 0;
1783 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1788 static int should_deauth_infrastructure(struct lbs_private *priv,
1789 struct assoc_request * assoc_req)
1793 if (priv->connect_status != LBS_CONNECTED)
1796 lbs_deb_enter(LBS_DEB_ASSOC);
1797 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
1798 lbs_deb_assoc("Deauthenticating due to new SSID\n");
1803 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
1804 if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
1805 lbs_deb_assoc("Deauthenticating due to new security\n");
1811 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
1812 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
1817 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
1818 lbs_deb_assoc("Deauthenticating due to channel switch\n");
1823 /* FIXME: deal with 'auto' mode somehow */
1824 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
1825 if (assoc_req->mode != IW_MODE_INFRA) {
1826 lbs_deb_assoc("Deauthenticating due to leaving "
1834 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1839 static int should_stop_adhoc(struct lbs_private *priv,
1840 struct assoc_request * assoc_req)
1842 lbs_deb_enter(LBS_DEB_ASSOC);
1844 if (priv->connect_status != LBS_CONNECTED)
1847 if (lbs_ssid_cmp(priv->curbssparams.ssid,
1848 priv->curbssparams.ssid_len,
1849 assoc_req->ssid, assoc_req->ssid_len) != 0)
1852 /* FIXME: deal with 'auto' mode somehow */
1853 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
1854 if (assoc_req->mode != IW_MODE_ADHOC)
1858 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
1859 if (assoc_req->channel != priv->channel)
1863 lbs_deb_leave(LBS_DEB_ASSOC);
1869 * @brief This function finds the best SSID in the Scan List
1871 * Search the scan table for the best SSID that also matches the current
1872 * adapter network preference (infrastructure or adhoc)
1874 * @param priv A pointer to struct lbs_private
1876 * @return index in BSSID list
1878 static struct bss_descriptor *lbs_find_best_ssid_in_list(
1879 struct lbs_private *priv, uint8_t mode)
1881 uint8_t bestrssi = 0;
1882 struct bss_descriptor *iter_bss;
1883 struct bss_descriptor *best_bss = NULL;
1885 lbs_deb_enter(LBS_DEB_SCAN);
1887 mutex_lock(&priv->lock);
1889 list_for_each_entry(iter_bss, &priv->network_list, list) {
1893 if (!is_network_compatible(priv, iter_bss, mode))
1895 if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
1897 bestrssi = SCAN_RSSI(iter_bss->rssi);
1898 best_bss = iter_bss;
1902 if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
1904 bestrssi = SCAN_RSSI(iter_bss->rssi);
1905 best_bss = iter_bss;
1910 mutex_unlock(&priv->lock);
1911 lbs_deb_leave_args(LBS_DEB_SCAN, "best_bss %p", best_bss);
1916 * @brief Find the best AP
1918 * Used from association worker.
1920 * @param priv A pointer to struct lbs_private structure
1921 * @param pSSID A pointer to AP's ssid
1923 * @return 0--success, otherwise--fail
1925 static int lbs_find_best_network_ssid(struct lbs_private *priv,
1926 uint8_t *out_ssid, uint8_t *out_ssid_len, uint8_t preferred_mode,
1930 struct bss_descriptor *found;
1932 lbs_deb_enter(LBS_DEB_SCAN);
1934 priv->scan_ssid_len = 0;
1935 lbs_scan_networks(priv, 1);
1936 if (priv->surpriseremoved)
1939 found = lbs_find_best_ssid_in_list(priv, preferred_mode);
1940 if (found && (found->ssid_len > 0)) {
1941 memcpy(out_ssid, &found->ssid, IEEE80211_MAX_SSID_LEN);
1942 *out_ssid_len = found->ssid_len;
1943 *out_mode = found->mode;
1948 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
1953 void lbs_association_worker(struct work_struct *work)
1955 struct lbs_private *priv = container_of(work, struct lbs_private,
1957 struct assoc_request * assoc_req = NULL;
1959 int find_any_ssid = 0;
1960 DECLARE_SSID_BUF(ssid);
1962 lbs_deb_enter(LBS_DEB_ASSOC);
1964 mutex_lock(&priv->lock);
1965 assoc_req = priv->pending_assoc_req;
1966 priv->pending_assoc_req = NULL;
1967 priv->in_progress_assoc_req = assoc_req;
1968 mutex_unlock(&priv->lock);
1974 "Association Request:\n"
1981 " secinfo: %s%s%s\n"
1984 print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len),
1985 assoc_req->channel, assoc_req->band, assoc_req->mode,
1987 assoc_req->secinfo.WPAenabled ? " WPA" : "",
1988 assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
1989 assoc_req->secinfo.wep_enabled ? " WEP" : "",
1990 assoc_req->secinfo.auth_mode);
1992 /* If 'any' SSID was specified, find an SSID to associate with */
1993 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
1994 && !assoc_req->ssid_len)
1997 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
1998 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
1999 if (compare_ether_addr(assoc_req->bssid, bssid_any)
2000 && compare_ether_addr(assoc_req->bssid, bssid_off))
2004 if (find_any_ssid) {
2005 u8 new_mode = assoc_req->mode;
2007 ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
2008 &assoc_req->ssid_len, assoc_req->mode, &new_mode);
2010 lbs_deb_assoc("Could not find best network\n");
2015 /* Ensure we switch to the mode of the AP */
2016 if (assoc_req->mode == IW_MODE_AUTO) {
2017 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
2018 assoc_req->mode = new_mode;
2023 * Check if the attributes being changing require deauthentication
2024 * from the currently associated infrastructure access point.
2026 if (priv->mode == IW_MODE_INFRA) {
2027 if (should_deauth_infrastructure(priv, assoc_req)) {
2028 ret = lbs_cmd_80211_deauthenticate(priv,
2029 priv->curbssparams.bssid,
2030 WLAN_REASON_DEAUTH_LEAVING);
2032 lbs_deb_assoc("Deauthentication due to new "
2033 "configuration request failed: %d\n",
2037 } else if (priv->mode == IW_MODE_ADHOC) {
2038 if (should_stop_adhoc(priv, assoc_req)) {
2039 ret = lbs_adhoc_stop(priv);
2041 lbs_deb_assoc("Teardown of AdHoc network due to "
2042 "new configuration request failed: %d\n",
2049 /* Send the various configuration bits to the firmware */
2050 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
2051 ret = assoc_helper_mode(priv, assoc_req);
2056 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
2057 ret = assoc_helper_channel(priv, assoc_req);
2062 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
2063 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
2064 ret = assoc_helper_wep_keys(priv, assoc_req);
2069 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
2070 ret = assoc_helper_secinfo(priv, assoc_req);
2075 if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
2076 ret = assoc_helper_wpa_ie(priv, assoc_req);
2081 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
2082 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
2083 ret = assoc_helper_wpa_keys(priv, assoc_req);
2088 /* SSID/BSSID should be the _last_ config option set, because they
2089 * trigger the association attempt.
2091 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
2092 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
2095 ret = assoc_helper_associate(priv, assoc_req);
2097 lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
2102 if (priv->connect_status != LBS_CONNECTED) {
2103 lbs_deb_assoc("ASSOC: association unsuccessful, "
2109 lbs_deb_assoc("associated to %pM\n",
2110 priv->curbssparams.bssid);
2111 lbs_prepare_and_send_command(priv,
2113 0, CMD_OPTION_WAITFORRSP, 0, NULL);
2121 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
2125 mutex_lock(&priv->lock);
2126 priv->in_progress_assoc_req = NULL;
2127 mutex_unlock(&priv->lock);
2131 lbs_deb_leave(LBS_DEB_ASSOC);
2136 * Caller MUST hold any necessary locks
2138 struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
2140 struct assoc_request * assoc_req;
2142 lbs_deb_enter(LBS_DEB_ASSOC);
2143 if (!priv->pending_assoc_req) {
2144 priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
2146 if (!priv->pending_assoc_req) {
2147 lbs_pr_info("Not enough memory to allocate association"
2153 /* Copy current configuration attributes to the association request,
2154 * but don't overwrite any that are already set.
2156 assoc_req = priv->pending_assoc_req;
2157 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
2158 memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
2159 IEEE80211_MAX_SSID_LEN);
2160 assoc_req->ssid_len = priv->curbssparams.ssid_len;
2163 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
2164 assoc_req->channel = priv->channel;
2166 if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
2167 assoc_req->band = priv->curbssparams.band;
2169 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
2170 assoc_req->mode = priv->mode;
2172 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
2173 memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
2177 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
2179 for (i = 0; i < 4; i++) {
2180 memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
2181 sizeof(struct enc_key));
2185 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
2186 assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
2188 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
2189 memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
2190 sizeof(struct enc_key));
2193 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
2194 memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
2195 sizeof(struct enc_key));
2198 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
2199 memcpy(&assoc_req->secinfo, &priv->secinfo,
2200 sizeof(struct lbs_802_11_security));
2203 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
2204 memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
2206 assoc_req->wpa_ie_len = priv->wpa_ie_len;
2209 lbs_deb_leave(LBS_DEB_ASSOC);
2215 * @brief Deauthenticate from a specific BSS
2217 * @param priv A pointer to struct lbs_private structure
2218 * @param bssid The specific BSS to deauthenticate from
2219 * @param reason The 802.11 sec. 7.3.1.7 Reason Code for deauthenticating
2221 * @return 0 on success, error on failure
2223 int lbs_cmd_80211_deauthenticate(struct lbs_private *priv, u8 bssid[ETH_ALEN],
2226 struct cmd_ds_802_11_deauthenticate cmd;
2229 lbs_deb_enter(LBS_DEB_JOIN);
2231 memset(&cmd, 0, sizeof(cmd));
2232 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2233 memcpy(cmd.macaddr, &bssid[0], ETH_ALEN);
2234 cmd.reasoncode = cpu_to_le16(reason);
2236 ret = lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd);
2238 /* Clean up everything even if there was an error; can't assume that
2239 * we're still authenticated to the AP after trying to deauth.
2241 lbs_mac_event_disconnected(priv);
2243 lbs_deb_leave(LBS_DEB_JOIN);