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(sizeof(struct cmd_header) + 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) +
460 sizeof(struct cmd_header));
461 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
463 /* reset Beacon SNR/NF/RSSI values */
464 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
465 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
466 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
467 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
468 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
469 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
471 lbs_deb_leave(LBS_DEB_CMD);
475 int lbs_ret_802_11_rssi(struct lbs_private *priv,
476 struct cmd_ds_command *resp)
478 struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
480 lbs_deb_enter(LBS_DEB_CMD);
482 /* store the non average value */
483 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = get_unaligned_le16(&rssirsp->SNR);
484 priv->NF[TYPE_BEACON][TYPE_NOAVG] =
485 get_unaligned_le16(&rssirsp->noisefloor);
487 priv->SNR[TYPE_BEACON][TYPE_AVG] = get_unaligned_le16(&rssirsp->avgSNR);
488 priv->NF[TYPE_BEACON][TYPE_AVG] =
489 get_unaligned_le16(&rssirsp->avgnoisefloor);
491 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] =
492 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
493 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
495 priv->RSSI[TYPE_BEACON][TYPE_AVG] =
496 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
497 priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
499 lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
500 priv->RSSI[TYPE_BEACON][TYPE_NOAVG],
501 priv->RSSI[TYPE_BEACON][TYPE_AVG]);
503 lbs_deb_leave(LBS_DEB_CMD);
508 int lbs_cmd_bcn_ctrl(struct lbs_private *priv,
509 struct cmd_ds_command *cmd,
512 struct cmd_ds_802_11_beacon_control
513 *bcn_ctrl = &cmd->params.bcn_ctrl;
515 lbs_deb_enter(LBS_DEB_CMD);
517 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
518 + sizeof(struct cmd_header));
519 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
521 bcn_ctrl->action = cpu_to_le16(cmd_action);
522 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
523 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
525 lbs_deb_leave(LBS_DEB_CMD);
529 int lbs_ret_802_11_bcn_ctrl(struct lbs_private *priv,
530 struct cmd_ds_command *resp)
532 struct cmd_ds_802_11_beacon_control *bcn_ctrl =
533 &resp->params.bcn_ctrl;
535 lbs_deb_enter(LBS_DEB_CMD);
537 if (bcn_ctrl->action == CMD_ACT_GET) {
538 priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable);
539 priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period);
542 lbs_deb_enter(LBS_DEB_CMD);
548 static int lbs_assoc_post(struct lbs_private *priv,
549 struct cmd_ds_802_11_associate_response *resp)
552 union iwreq_data wrqu;
553 struct bss_descriptor *bss;
556 lbs_deb_enter(LBS_DEB_ASSOC);
558 if (!priv->in_progress_assoc_req) {
559 lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n");
563 bss = &priv->in_progress_assoc_req->bss;
566 * Older FW versions map the IEEE 802.11 Status Code in the association
567 * response to the following values returned in resp->statuscode:
569 * IEEE Status Code Marvell Status Code
570 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
571 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
572 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
573 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
574 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
575 * others -> 0x0003 ASSOC_RESULT_REFUSED
577 * Other response codes:
578 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
579 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
580 * association response from the AP)
583 status_code = le16_to_cpu(resp->statuscode);
584 if (priv->fwrelease < 0x09000000) {
585 switch (status_code) {
589 lbs_deb_assoc("ASSOC_RESP: invalid parameters\n");
592 lbs_deb_assoc("ASSOC_RESP: internal timer "
593 "expired while waiting for the AP\n");
596 lbs_deb_assoc("ASSOC_RESP: association "
600 lbs_deb_assoc("ASSOC_RESP: authentication "
604 lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x "
605 " unknown\n", status_code);
609 /* v9+ returns the AP's association response */
610 lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x\n", status_code);
614 lbs_mac_event_disconnected(priv);
619 lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP",
620 (void *) (resp + sizeof (resp->hdr)),
621 le16_to_cpu(resp->hdr.size) - sizeof (resp->hdr));
623 /* Send a Media Connected event, according to the Spec */
624 priv->connect_status = LBS_CONNECTED;
626 /* Update current SSID and BSSID */
627 memcpy(&priv->curbssparams.ssid, &bss->ssid, IEEE80211_MAX_SSID_LEN);
628 priv->curbssparams.ssid_len = bss->ssid_len;
629 memcpy(priv->curbssparams.bssid, bss->bssid, ETH_ALEN);
631 priv->SNR[TYPE_RXPD][TYPE_AVG] = 0;
632 priv->NF[TYPE_RXPD][TYPE_AVG] = 0;
634 memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR));
635 memset(priv->rawNF, 0x00, sizeof(priv->rawNF));
639 netif_carrier_on(priv->dev);
640 if (!priv->tx_pending_len)
641 netif_wake_queue(priv->dev);
643 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN);
644 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
645 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
648 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
653 * @brief This function prepares an association-class command.
655 * @param priv A pointer to struct lbs_private structure
656 * @param assoc_req The association request describing the BSS to associate
657 * or reassociate with
658 * @param command The actual command, either CMD_802_11_ASSOCIATE or
659 * CMD_802_11_REASSOCIATE
663 static int lbs_associate(struct lbs_private *priv,
664 struct assoc_request *assoc_req,
667 struct cmd_ds_802_11_associate cmd;
669 struct bss_descriptor *bss = &assoc_req->bss;
670 u8 *pos = &(cmd.iebuf[0]);
671 u16 tmpcap, tmplen, tmpauth;
672 struct mrvl_ie_ssid_param_set *ssid;
673 struct mrvl_ie_ds_param_set *ds;
674 struct mrvl_ie_cf_param_set *cf;
675 struct mrvl_ie_rates_param_set *rates;
676 struct mrvl_ie_rsn_param_set *rsn;
677 struct mrvl_ie_auth_type *auth;
679 lbs_deb_enter(LBS_DEB_ASSOC);
681 BUG_ON((command != CMD_802_11_ASSOCIATE) &&
682 (command != CMD_802_11_REASSOCIATE));
684 memset(&cmd, 0, sizeof(cmd));
685 cmd.hdr.command = cpu_to_le16(command);
687 /* Fill in static fields */
688 memcpy(cmd.bssid, bss->bssid, ETH_ALEN);
689 cmd.listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
691 /* Capability info */
692 tmpcap = (bss->capability & CAPINFO_MASK);
693 if (bss->mode == IW_MODE_INFRA)
694 tmpcap |= WLAN_CAPABILITY_ESS;
695 cmd.capability = cpu_to_le16(tmpcap);
696 lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap);
699 ssid = (struct mrvl_ie_ssid_param_set *) pos;
700 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
701 tmplen = bss->ssid_len;
702 ssid->header.len = cpu_to_le16(tmplen);
703 memcpy(ssid->ssid, bss->ssid, tmplen);
704 pos += sizeof(ssid->header) + tmplen;
706 ds = (struct mrvl_ie_ds_param_set *) pos;
707 ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
708 ds->header.len = cpu_to_le16(1);
709 ds->channel = bss->phy.ds.channel;
710 pos += sizeof(ds->header) + 1;
712 cf = (struct mrvl_ie_cf_param_set *) pos;
713 cf->header.type = cpu_to_le16(TLV_TYPE_CF);
714 tmplen = sizeof(*cf) - sizeof (cf->header);
715 cf->header.len = cpu_to_le16(tmplen);
716 /* IE payload should be zeroed, firmware fills it in for us */
719 rates = (struct mrvl_ie_rates_param_set *) pos;
720 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
721 tmplen = min_t(u16, ARRAY_SIZE(bss->rates), MAX_RATES);
722 memcpy(&rates->rates, &bss->rates, tmplen);
723 if (get_common_rates(priv, rates->rates, &tmplen)) {
727 pos += sizeof(rates->header) + tmplen;
728 rates->header.len = cpu_to_le16(tmplen);
729 lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen);
731 /* Copy the infra. association rates into Current BSS state structure */
732 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
733 memcpy(&priv->curbssparams.rates, &rates->rates, tmplen);
735 /* Set MSB on basic rates as the firmware requires, but _after_
736 * copying to current bss rates.
738 lbs_set_basic_rate_flags(rates->rates, tmplen);
740 /* Firmware v9+ indicate authentication suites as a TLV */
741 if (priv->fwrelease >= 0x09000000) {
742 auth = (struct mrvl_ie_auth_type *) pos;
743 auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
744 auth->header.len = cpu_to_le16(2);
745 tmpauth = iw_auth_to_ieee_auth(priv->secinfo.auth_mode);
746 auth->auth = cpu_to_le16(tmpauth);
747 pos += sizeof(auth->header) + 2;
749 lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n",
750 bss->bssid, priv->secinfo.auth_mode);
754 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
755 rsn = (struct mrvl_ie_rsn_param_set *) pos;
756 /* WPA_IE or WPA2_IE */
757 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
758 tmplen = (u16) assoc_req->wpa_ie[1];
759 rsn->header.len = cpu_to_le16(tmplen);
760 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
761 lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: WPA/RSN IE", (u8 *) rsn,
762 sizeof(rsn->header) + tmplen);
763 pos += sizeof(rsn->header) + tmplen;
766 cmd.hdr.size = cpu_to_le16((sizeof(cmd) - sizeof(cmd.iebuf)) +
767 (u16)(pos - (u8 *) &cmd.iebuf));
769 /* update curbssparams */
770 priv->channel = bss->phy.ds.channel;
772 ret = lbs_cmd_with_response(priv, command, &cmd);
774 ret = lbs_assoc_post(priv,
775 (struct cmd_ds_802_11_associate_response *) &cmd);
779 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
784 * @brief Associate to a specific BSS discovered in a scan
786 * @param priv A pointer to struct lbs_private structure
787 * @param assoc_req The association request describing the BSS to associate with
789 * @return 0-success, otherwise fail
791 static int lbs_try_associate(struct lbs_private *priv,
792 struct assoc_request *assoc_req)
795 u8 preamble = RADIO_PREAMBLE_LONG;
797 lbs_deb_enter(LBS_DEB_ASSOC);
799 /* FW v9 and higher indicate authentication suites as a TLV in the
800 * association command, not as a separate authentication command.
802 if (priv->fwrelease < 0x09000000) {
803 ret = lbs_set_authentication(priv, assoc_req->bss.bssid,
804 priv->secinfo.auth_mode);
809 /* Use short preamble only when both the BSS and firmware support it */
810 if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
811 (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
812 preamble = RADIO_PREAMBLE_SHORT;
814 ret = lbs_set_radio(priv, preamble, 1);
818 ret = lbs_associate(priv, assoc_req, CMD_802_11_ASSOCIATE);
821 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
825 static int lbs_adhoc_post(struct lbs_private *priv,
826 struct cmd_ds_802_11_ad_hoc_result *resp)
829 u16 command = le16_to_cpu(resp->hdr.command);
830 u16 result = le16_to_cpu(resp->hdr.result);
831 union iwreq_data wrqu;
832 struct bss_descriptor *bss;
833 DECLARE_SSID_BUF(ssid);
835 lbs_deb_enter(LBS_DEB_JOIN);
837 if (!priv->in_progress_assoc_req) {
838 lbs_deb_join("ADHOC_RESP: no in-progress association "
843 bss = &priv->in_progress_assoc_req->bss;
846 * Join result code 0 --> SUCCESS
849 lbs_deb_join("ADHOC_RESP: failed (result 0x%X)\n", result);
850 if (priv->connect_status == LBS_CONNECTED)
851 lbs_mac_event_disconnected(priv);
856 /* Send a Media Connected event, according to the Spec */
857 priv->connect_status = LBS_CONNECTED;
859 if (command == CMD_RET(CMD_802_11_AD_HOC_START)) {
860 /* Update the created network descriptor with the new BSSID */
861 memcpy(bss->bssid, resp->bssid, ETH_ALEN);
864 /* Set the BSSID from the joined/started descriptor */
865 memcpy(&priv->curbssparams.bssid, bss->bssid, ETH_ALEN);
867 /* Set the new SSID to current SSID */
868 memcpy(&priv->curbssparams.ssid, &bss->ssid, IEEE80211_MAX_SSID_LEN);
869 priv->curbssparams.ssid_len = bss->ssid_len;
871 netif_carrier_on(priv->dev);
872 if (!priv->tx_pending_len)
873 netif_wake_queue(priv->dev);
875 memset(&wrqu, 0, sizeof(wrqu));
876 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN);
877 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
878 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
880 lbs_deb_join("ADHOC_RESP: Joined/started '%s', BSSID %pM, channel %d\n",
881 print_ssid(ssid, bss->ssid, bss->ssid_len),
882 priv->curbssparams.bssid,
886 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
891 * @brief Join an adhoc network found in a previous scan
893 * @param priv A pointer to struct lbs_private structure
894 * @param assoc_req The association request describing the BSS to join
896 * @return 0 on success, error on failure
898 static int lbs_adhoc_join(struct lbs_private *priv,
899 struct assoc_request *assoc_req)
901 struct cmd_ds_802_11_ad_hoc_join cmd;
902 struct bss_descriptor *bss = &assoc_req->bss;
903 u8 preamble = RADIO_PREAMBLE_LONG;
904 DECLARE_SSID_BUF(ssid);
908 lbs_deb_enter(LBS_DEB_ASSOC);
910 lbs_deb_join("current SSID '%s', ssid length %u\n",
911 print_ssid(ssid, priv->curbssparams.ssid,
912 priv->curbssparams.ssid_len),
913 priv->curbssparams.ssid_len);
914 lbs_deb_join("requested ssid '%s', ssid length %u\n",
915 print_ssid(ssid, bss->ssid, bss->ssid_len),
918 /* check if the requested SSID is already joined */
919 if (priv->curbssparams.ssid_len &&
920 !lbs_ssid_cmp(priv->curbssparams.ssid,
921 priv->curbssparams.ssid_len,
922 bss->ssid, bss->ssid_len) &&
923 (priv->mode == IW_MODE_ADHOC) &&
924 (priv->connect_status == LBS_CONNECTED)) {
925 union iwreq_data wrqu;
927 lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as "
928 "current, not attempting to re-join");
930 /* Send the re-association event though, because the association
931 * request really was successful, even if just a null-op.
933 memset(&wrqu, 0, sizeof(wrqu));
934 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid,
936 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
937 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
941 /* Use short preamble only when both the BSS and firmware support it */
942 if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
943 (bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
944 lbs_deb_join("AdhocJoin: Short preamble\n");
945 preamble = RADIO_PREAMBLE_SHORT;
948 ret = lbs_set_radio(priv, preamble, 1);
952 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
953 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
955 priv->adhoccreate = 0;
956 priv->channel = bss->channel;
958 /* Build the join command */
959 memset(&cmd, 0, sizeof(cmd));
960 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
962 cmd.bss.type = CMD_BSS_TYPE_IBSS;
963 cmd.bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
965 memcpy(&cmd.bss.bssid, &bss->bssid, ETH_ALEN);
966 memcpy(&cmd.bss.ssid, &bss->ssid, bss->ssid_len);
968 memcpy(&cmd.bss.ds, &bss->phy.ds, sizeof(struct ieee_ie_ds_param_set));
970 memcpy(&cmd.bss.ibss, &bss->ss.ibss,
971 sizeof(struct ieee_ie_ibss_param_set));
973 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
974 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
975 bss->capability, CAPINFO_MASK);
977 /* information on BSSID descriptor passed to FW */
978 lbs_deb_join("ADHOC_J_CMD: BSSID = %pM, SSID = '%s'\n",
979 cmd.bss.bssid, cmd.bss.ssid);
981 /* Only v8 and below support setting these */
982 if (priv->fwrelease < 0x09000000) {
984 cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
986 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
989 /* Copy Data rates from the rates recorded in scan response */
990 memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates));
991 ratesize = min_t(u16, ARRAY_SIZE(cmd.bss.rates), ARRAY_SIZE (bss->rates));
992 memcpy(cmd.bss.rates, bss->rates, ratesize);
993 if (get_common_rates(priv, cmd.bss.rates, &ratesize)) {
994 lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n");
999 /* Copy the ad-hoc creation rates into Current BSS state structure */
1000 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
1001 memcpy(&priv->curbssparams.rates, cmd.bss.rates, ratesize);
1003 /* Set MSB on basic rates as the firmware requires, but _after_
1004 * copying to current bss rates.
1006 lbs_set_basic_rate_flags(cmd.bss.rates, ratesize);
1008 cmd.bss.ibss.atimwindow = bss->atimwindow;
1010 if (assoc_req->secinfo.wep_enabled) {
1011 u16 tmp = le16_to_cpu(cmd.bss.capability);
1012 tmp |= WLAN_CAPABILITY_PRIVACY;
1013 cmd.bss.capability = cpu_to_le16(tmp);
1016 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1017 __le32 local_ps_mode = cpu_to_le32(LBS802_11POWERMODECAM);
1020 ret = lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1029 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
1031 ret = lbs_adhoc_post(priv,
1032 (struct cmd_ds_802_11_ad_hoc_result *)&cmd);
1036 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1041 * @brief Start an Adhoc Network
1043 * @param priv A pointer to struct lbs_private structure
1044 * @param assoc_req The association request describing the BSS to start
1046 * @return 0 on success, error on failure
1048 static int lbs_adhoc_start(struct lbs_private *priv,
1049 struct assoc_request *assoc_req)
1051 struct cmd_ds_802_11_ad_hoc_start cmd;
1052 u8 preamble = RADIO_PREAMBLE_LONG;
1053 size_t ratesize = 0;
1056 DECLARE_SSID_BUF(ssid);
1058 lbs_deb_enter(LBS_DEB_ASSOC);
1060 if (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
1061 lbs_deb_join("ADHOC_START: Will use short preamble\n");
1062 preamble = RADIO_PREAMBLE_SHORT;
1065 ret = lbs_set_radio(priv, preamble, 1);
1069 /* Build the start command */
1070 memset(&cmd, 0, sizeof(cmd));
1071 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1073 memcpy(cmd.ssid, assoc_req->ssid, assoc_req->ssid_len);
1075 lbs_deb_join("ADHOC_START: SSID '%s', ssid length %u\n",
1076 print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len),
1077 assoc_req->ssid_len);
1079 cmd.bsstype = CMD_BSS_TYPE_IBSS;
1081 if (priv->beacon_period == 0)
1082 priv->beacon_period = MRVDRV_BEACON_INTERVAL;
1083 cmd.beaconperiod = cpu_to_le16(priv->beacon_period);
1085 WARN_ON(!assoc_req->channel);
1087 /* set Physical parameter set */
1088 cmd.ds.header.id = WLAN_EID_DS_PARAMS;
1089 cmd.ds.header.len = 1;
1090 cmd.ds.channel = assoc_req->channel;
1092 /* set IBSS parameter set */
1093 cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1094 cmd.ibss.header.len = 2;
1095 cmd.ibss.atimwindow = cpu_to_le16(0);
1097 /* set capability info */
1098 tmpcap = WLAN_CAPABILITY_IBSS;
1099 if (assoc_req->secinfo.wep_enabled ||
1100 assoc_req->secinfo.WPAenabled ||
1101 assoc_req->secinfo.WPA2enabled) {
1102 lbs_deb_join("ADHOC_START: WEP/WPA enabled, privacy on\n");
1103 tmpcap |= WLAN_CAPABILITY_PRIVACY;
1105 lbs_deb_join("ADHOC_START: WEP disabled, privacy off\n");
1107 cmd.capability = cpu_to_le16(tmpcap);
1109 /* Only v8 and below support setting probe delay */
1110 if (priv->fwrelease < 0x09000000)
1111 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1113 ratesize = min(sizeof(cmd.rates), sizeof(lbs_bg_rates));
1114 memcpy(cmd.rates, lbs_bg_rates, ratesize);
1116 /* Copy the ad-hoc creating rates into Current BSS state structure */
1117 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
1118 memcpy(&priv->curbssparams.rates, &cmd.rates, ratesize);
1120 /* Set MSB on basic rates as the firmware requires, but _after_
1121 * copying to current bss rates.
1123 lbs_set_basic_rate_flags(cmd.rates, ratesize);
1125 lbs_deb_join("ADHOC_START: rates=%02x %02x %02x %02x\n",
1126 cmd.rates[0], cmd.rates[1], cmd.rates[2], cmd.rates[3]);
1128 lbs_deb_join("ADHOC_START: Starting Ad-Hoc BSS on channel %d, band %d\n",
1129 assoc_req->channel, assoc_req->band);
1131 priv->adhoccreate = 1;
1132 priv->mode = IW_MODE_ADHOC;
1134 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
1136 ret = lbs_adhoc_post(priv,
1137 (struct cmd_ds_802_11_ad_hoc_result *)&cmd);
1140 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1145 * @brief Stop and Ad-Hoc network and exit Ad-Hoc mode
1147 * @param priv A pointer to struct lbs_private structure
1148 * @return 0 on success, or an error
1150 int lbs_adhoc_stop(struct lbs_private *priv)
1152 struct cmd_ds_802_11_ad_hoc_stop cmd;
1155 lbs_deb_enter(LBS_DEB_JOIN);
1157 memset(&cmd, 0, sizeof (cmd));
1158 cmd.hdr.size = cpu_to_le16 (sizeof (cmd));
1160 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
1162 /* Clean up everything even if there was an error */
1163 lbs_mac_event_disconnected(priv);
1165 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1169 static inline int match_bss_no_security(struct lbs_802_11_security *secinfo,
1170 struct bss_descriptor *match_bss)
1172 if (!secinfo->wep_enabled && !secinfo->WPAenabled
1173 && !secinfo->WPA2enabled
1174 && match_bss->wpa_ie[0] != WLAN_EID_GENERIC
1175 && match_bss->rsn_ie[0] != WLAN_EID_RSN
1176 && !(match_bss->capability & WLAN_CAPABILITY_PRIVACY))
1182 static inline int match_bss_static_wep(struct lbs_802_11_security *secinfo,
1183 struct bss_descriptor *match_bss)
1185 if (secinfo->wep_enabled && !secinfo->WPAenabled
1186 && !secinfo->WPA2enabled
1187 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY))
1193 static inline int match_bss_wpa(struct lbs_802_11_security *secinfo,
1194 struct bss_descriptor *match_bss)
1196 if (!secinfo->wep_enabled && secinfo->WPAenabled
1197 && (match_bss->wpa_ie[0] == WLAN_EID_GENERIC)
1198 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
1199 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
1206 static inline int match_bss_wpa2(struct lbs_802_11_security *secinfo,
1207 struct bss_descriptor *match_bss)
1209 if (!secinfo->wep_enabled && secinfo->WPA2enabled &&
1210 (match_bss->rsn_ie[0] == WLAN_EID_RSN)
1211 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
1212 (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
1219 static inline int match_bss_dynamic_wep(struct lbs_802_11_security *secinfo,
1220 struct bss_descriptor *match_bss)
1222 if (!secinfo->wep_enabled && !secinfo->WPAenabled
1223 && !secinfo->WPA2enabled
1224 && (match_bss->wpa_ie[0] != WLAN_EID_GENERIC)
1225 && (match_bss->rsn_ie[0] != WLAN_EID_RSN)
1226 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY))
1233 * @brief Check if a scanned network compatible with the driver settings
1235 * WEP WPA WPA2 ad-hoc encrypt Network
1236 * enabled enabled enabled AES mode privacy WPA WPA2 Compatible
1237 * 0 0 0 0 NONE 0 0 0 yes No security
1238 * 1 0 0 0 NONE 1 0 0 yes Static WEP
1239 * 0 1 0 0 x 1x 1 x yes WPA
1240 * 0 0 1 0 x 1x x 1 yes WPA2
1241 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
1242 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
1245 * @param priv A pointer to struct lbs_private
1246 * @param index Index in scantable to check against current driver settings
1247 * @param mode Network mode: Infrastructure or IBSS
1249 * @return Index in scantable, or error code if negative
1251 static int is_network_compatible(struct lbs_private *priv,
1252 struct bss_descriptor *bss, uint8_t mode)
1256 lbs_deb_enter(LBS_DEB_SCAN);
1258 if (bss->mode != mode)
1261 matched = match_bss_no_security(&priv->secinfo, bss);
1264 matched = match_bss_static_wep(&priv->secinfo, bss);
1267 matched = match_bss_wpa(&priv->secinfo, bss);
1269 lbs_deb_scan("is_network_compatible() WPA: wpa_ie 0x%x "
1270 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
1271 "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0],
1272 priv->secinfo.wep_enabled ? "e" : "d",
1273 priv->secinfo.WPAenabled ? "e" : "d",
1274 priv->secinfo.WPA2enabled ? "e" : "d",
1275 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1278 matched = match_bss_wpa2(&priv->secinfo, bss);
1280 lbs_deb_scan("is_network_compatible() WPA2: wpa_ie 0x%x "
1281 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
1282 "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0],
1283 priv->secinfo.wep_enabled ? "e" : "d",
1284 priv->secinfo.WPAenabled ? "e" : "d",
1285 priv->secinfo.WPA2enabled ? "e" : "d",
1286 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1289 matched = match_bss_dynamic_wep(&priv->secinfo, bss);
1291 lbs_deb_scan("is_network_compatible() dynamic WEP: "
1292 "wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n",
1293 bss->wpa_ie[0], bss->rsn_ie[0],
1294 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1298 /* bss security settings don't match those configured on card */
1299 lbs_deb_scan("is_network_compatible() FAILED: wpa_ie 0x%x "
1300 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n",
1301 bss->wpa_ie[0], bss->rsn_ie[0],
1302 priv->secinfo.wep_enabled ? "e" : "d",
1303 priv->secinfo.WPAenabled ? "e" : "d",
1304 priv->secinfo.WPA2enabled ? "e" : "d",
1305 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1308 lbs_deb_leave_args(LBS_DEB_SCAN, "matched: %d", matched);
1313 * @brief This function finds a specific compatible BSSID in the scan list
1315 * Used in association code
1317 * @param priv A pointer to struct lbs_private
1318 * @param bssid BSSID to find in the scan list
1319 * @param mode Network mode: Infrastructure or IBSS
1321 * @return index in BSSID list, or error return code (< 0)
1323 static struct bss_descriptor *lbs_find_bssid_in_list(struct lbs_private *priv,
1324 uint8_t *bssid, uint8_t mode)
1326 struct bss_descriptor *iter_bss;
1327 struct bss_descriptor *found_bss = NULL;
1329 lbs_deb_enter(LBS_DEB_SCAN);
1334 lbs_deb_hex(LBS_DEB_SCAN, "looking for", bssid, ETH_ALEN);
1336 /* Look through the scan table for a compatible match. The loop will
1337 * continue past a matched bssid that is not compatible in case there
1338 * is an AP with multiple SSIDs assigned to the same BSSID
1340 mutex_lock(&priv->lock);
1341 list_for_each_entry(iter_bss, &priv->network_list, list) {
1342 if (compare_ether_addr(iter_bss->bssid, bssid))
1343 continue; /* bssid doesn't match */
1347 if (!is_network_compatible(priv, iter_bss, mode))
1349 found_bss = iter_bss;
1352 found_bss = iter_bss;
1356 mutex_unlock(&priv->lock);
1359 lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss);
1364 * @brief This function finds ssid in ssid list.
1366 * Used in association code
1368 * @param priv A pointer to struct lbs_private
1369 * @param ssid SSID to find in the list
1370 * @param bssid BSSID to qualify the SSID selection (if provided)
1371 * @param mode Network mode: Infrastructure or IBSS
1373 * @return index in BSSID list
1375 static struct bss_descriptor *lbs_find_ssid_in_list(struct lbs_private *priv,
1376 uint8_t *ssid, uint8_t ssid_len,
1377 uint8_t *bssid, uint8_t mode,
1381 struct bss_descriptor *iter_bss = NULL;
1382 struct bss_descriptor *found_bss = NULL;
1383 struct bss_descriptor *tmp_oldest = NULL;
1385 lbs_deb_enter(LBS_DEB_SCAN);
1387 mutex_lock(&priv->lock);
1389 list_for_each_entry(iter_bss, &priv->network_list, list) {
1391 (iter_bss->last_scanned < tmp_oldest->last_scanned))
1392 tmp_oldest = iter_bss;
1394 if (lbs_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len,
1395 ssid, ssid_len) != 0)
1396 continue; /* ssid doesn't match */
1397 if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0)
1398 continue; /* bssid doesn't match */
1399 if ((channel > 0) && (iter_bss->channel != channel))
1400 continue; /* channel doesn't match */
1405 if (!is_network_compatible(priv, iter_bss, mode))
1409 /* Found requested BSSID */
1410 found_bss = iter_bss;
1414 if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
1415 bestrssi = SCAN_RSSI(iter_bss->rssi);
1416 found_bss = iter_bss;
1421 if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
1422 bestrssi = SCAN_RSSI(iter_bss->rssi);
1423 found_bss = iter_bss;
1430 mutex_unlock(&priv->lock);
1431 lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss);
1435 static int assoc_helper_essid(struct lbs_private *priv,
1436 struct assoc_request * assoc_req)
1439 struct bss_descriptor * bss;
1441 DECLARE_SSID_BUF(ssid);
1443 lbs_deb_enter(LBS_DEB_ASSOC);
1445 /* FIXME: take channel into account when picking SSIDs if a channel
1449 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
1450 channel = assoc_req->channel;
1452 lbs_deb_assoc("SSID '%s' requested\n",
1453 print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len));
1454 if (assoc_req->mode == IW_MODE_INFRA) {
1455 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
1456 assoc_req->ssid_len);
1458 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
1459 assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
1461 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
1462 ret = lbs_try_associate(priv, assoc_req);
1464 lbs_deb_assoc("SSID not found; cannot associate\n");
1466 } else if (assoc_req->mode == IW_MODE_ADHOC) {
1467 /* Scan for the network, do not save previous results. Stale
1468 * scan data will cause us to join a non-existant adhoc network
1470 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
1471 assoc_req->ssid_len);
1473 /* Search for the requested SSID in the scan table */
1474 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
1475 assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
1477 lbs_deb_assoc("SSID found, will join\n");
1478 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
1479 lbs_adhoc_join(priv, assoc_req);
1481 /* else send START command */
1482 lbs_deb_assoc("SSID not found, creating adhoc network\n");
1483 memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
1484 IEEE80211_MAX_SSID_LEN);
1485 assoc_req->bss.ssid_len = assoc_req->ssid_len;
1486 lbs_adhoc_start(priv, assoc_req);
1490 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1495 static int assoc_helper_bssid(struct lbs_private *priv,
1496 struct assoc_request * assoc_req)
1499 struct bss_descriptor * bss;
1501 lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %pM", assoc_req->bssid);
1503 /* Search for index position in list for requested MAC */
1504 bss = lbs_find_bssid_in_list(priv, assoc_req->bssid,
1507 lbs_deb_assoc("ASSOC: WAP: BSSID %pM not found, "
1508 "cannot associate.\n", assoc_req->bssid);
1512 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
1513 if (assoc_req->mode == IW_MODE_INFRA) {
1514 ret = lbs_try_associate(priv, assoc_req);
1515 lbs_deb_assoc("ASSOC: lbs_try_associate(bssid) returned %d\n",
1517 } else if (assoc_req->mode == IW_MODE_ADHOC) {
1518 lbs_adhoc_join(priv, assoc_req);
1522 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1527 static int assoc_helper_associate(struct lbs_private *priv,
1528 struct assoc_request * assoc_req)
1530 int ret = 0, done = 0;
1532 lbs_deb_enter(LBS_DEB_ASSOC);
1534 /* If we're given and 'any' BSSID, try associating based on SSID */
1536 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
1537 if (compare_ether_addr(bssid_any, assoc_req->bssid)
1538 && compare_ether_addr(bssid_off, assoc_req->bssid)) {
1539 ret = assoc_helper_bssid(priv, assoc_req);
1544 if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
1545 ret = assoc_helper_essid(priv, assoc_req);
1548 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1553 static int assoc_helper_mode(struct lbs_private *priv,
1554 struct assoc_request * assoc_req)
1558 lbs_deb_enter(LBS_DEB_ASSOC);
1560 if (assoc_req->mode == priv->mode)
1563 if (assoc_req->mode == IW_MODE_INFRA) {
1564 if (priv->psstate != PS_STATE_FULL_POWER)
1565 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
1566 priv->psmode = LBS802_11POWERMODECAM;
1569 priv->mode = assoc_req->mode;
1570 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, assoc_req->mode);
1573 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1577 static int assoc_helper_channel(struct lbs_private *priv,
1578 struct assoc_request * assoc_req)
1582 lbs_deb_enter(LBS_DEB_ASSOC);
1584 ret = lbs_update_channel(priv);
1586 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
1590 if (assoc_req->channel == priv->channel)
1593 if (priv->mesh_dev) {
1594 /* Change mesh channel first; 21.p21 firmware won't let
1595 you change channel otherwise (even though it'll return
1597 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP,
1598 assoc_req->channel);
1601 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
1602 priv->channel, assoc_req->channel);
1604 ret = lbs_set_channel(priv, assoc_req->channel);
1606 lbs_deb_assoc("ASSOC: channel: error setting channel.\n");
1608 /* FIXME: shouldn't need to grab the channel _again_ after setting
1609 * it since the firmware is supposed to return the new channel, but
1611 ret = lbs_update_channel(priv);
1613 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
1617 if (assoc_req->channel != priv->channel) {
1618 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n",
1619 assoc_req->channel);
1623 if ( assoc_req->secinfo.wep_enabled
1624 && (assoc_req->wep_keys[0].len
1625 || assoc_req->wep_keys[1].len
1626 || assoc_req->wep_keys[2].len
1627 || assoc_req->wep_keys[3].len)) {
1628 /* Make sure WEP keys are re-sent to firmware */
1629 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1632 /* Must restart/rejoin adhoc networks after channel change */
1633 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
1637 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
1641 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1646 static int assoc_helper_wep_keys(struct lbs_private *priv,
1647 struct assoc_request *assoc_req)
1652 lbs_deb_enter(LBS_DEB_ASSOC);
1654 /* Set or remove WEP keys */
1655 if (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len ||
1656 assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len)
1657 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_ADD, assoc_req);
1659 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_REMOVE, assoc_req);
1664 /* enable/disable the MAC's WEP packet filter */
1665 if (assoc_req->secinfo.wep_enabled)
1666 priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
1668 priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
1670 lbs_set_mac_control(priv);
1672 mutex_lock(&priv->lock);
1674 /* Copy WEP keys into priv wep key fields */
1675 for (i = 0; i < 4; i++) {
1676 memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i],
1677 sizeof(struct enc_key));
1679 priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
1681 mutex_unlock(&priv->lock);
1684 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1688 static int assoc_helper_secinfo(struct lbs_private *priv,
1689 struct assoc_request * assoc_req)
1695 lbs_deb_enter(LBS_DEB_ASSOC);
1697 memcpy(&priv->secinfo, &assoc_req->secinfo,
1698 sizeof(struct lbs_802_11_security));
1700 lbs_set_mac_control(priv);
1702 /* If RSN is already enabled, don't try to enable it again, since
1703 * ENABLE_RSN resets internal state machines and will clobber the
1704 * 4-way WPA handshake.
1707 /* Get RSN enabled/disabled */
1708 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn);
1710 lbs_deb_assoc("Failed to get RSN status: %d\n", ret);
1714 /* Don't re-enable RSN if it's already enabled */
1715 do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled;
1719 /* Set RSN enabled/disabled */
1720 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa);
1723 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1728 static int assoc_helper_wpa_keys(struct lbs_private *priv,
1729 struct assoc_request * assoc_req)
1732 unsigned int flags = assoc_req->flags;
1734 lbs_deb_enter(LBS_DEB_ASSOC);
1736 /* Work around older firmware bug where WPA unicast and multicast
1737 * keys must be set independently. Seen in SDIO parts with firmware
1741 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
1742 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1743 ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
1744 assoc_req->flags = flags;
1750 memcpy(&priv->wpa_unicast_key, &assoc_req->wpa_unicast_key,
1751 sizeof(struct enc_key));
1753 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
1754 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1756 ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
1757 assoc_req->flags = flags;
1759 memcpy(&priv->wpa_mcast_key, &assoc_req->wpa_mcast_key,
1760 sizeof(struct enc_key));
1764 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1769 static int assoc_helper_wpa_ie(struct lbs_private *priv,
1770 struct assoc_request * assoc_req)
1774 lbs_deb_enter(LBS_DEB_ASSOC);
1776 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
1777 memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
1778 priv->wpa_ie_len = assoc_req->wpa_ie_len;
1780 memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
1781 priv->wpa_ie_len = 0;
1784 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1789 static int should_deauth_infrastructure(struct lbs_private *priv,
1790 struct assoc_request * assoc_req)
1794 if (priv->connect_status != LBS_CONNECTED)
1797 lbs_deb_enter(LBS_DEB_ASSOC);
1798 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
1799 lbs_deb_assoc("Deauthenticating due to new SSID\n");
1804 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
1805 if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
1806 lbs_deb_assoc("Deauthenticating due to new security\n");
1812 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
1813 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
1818 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
1819 lbs_deb_assoc("Deauthenticating due to channel switch\n");
1824 /* FIXME: deal with 'auto' mode somehow */
1825 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
1826 if (assoc_req->mode != IW_MODE_INFRA) {
1827 lbs_deb_assoc("Deauthenticating due to leaving "
1835 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1840 static int should_stop_adhoc(struct lbs_private *priv,
1841 struct assoc_request * assoc_req)
1843 lbs_deb_enter(LBS_DEB_ASSOC);
1845 if (priv->connect_status != LBS_CONNECTED)
1848 if (lbs_ssid_cmp(priv->curbssparams.ssid,
1849 priv->curbssparams.ssid_len,
1850 assoc_req->ssid, assoc_req->ssid_len) != 0)
1853 /* FIXME: deal with 'auto' mode somehow */
1854 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
1855 if (assoc_req->mode != IW_MODE_ADHOC)
1859 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
1860 if (assoc_req->channel != priv->channel)
1864 lbs_deb_leave(LBS_DEB_ASSOC);
1870 * @brief This function finds the best SSID in the Scan List
1872 * Search the scan table for the best SSID that also matches the current
1873 * adapter network preference (infrastructure or adhoc)
1875 * @param priv A pointer to struct lbs_private
1877 * @return index in BSSID list
1879 static struct bss_descriptor *lbs_find_best_ssid_in_list(
1880 struct lbs_private *priv, uint8_t mode)
1882 uint8_t bestrssi = 0;
1883 struct bss_descriptor *iter_bss;
1884 struct bss_descriptor *best_bss = NULL;
1886 lbs_deb_enter(LBS_DEB_SCAN);
1888 mutex_lock(&priv->lock);
1890 list_for_each_entry(iter_bss, &priv->network_list, list) {
1894 if (!is_network_compatible(priv, iter_bss, mode))
1896 if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
1898 bestrssi = SCAN_RSSI(iter_bss->rssi);
1899 best_bss = iter_bss;
1903 if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
1905 bestrssi = SCAN_RSSI(iter_bss->rssi);
1906 best_bss = iter_bss;
1911 mutex_unlock(&priv->lock);
1912 lbs_deb_leave_args(LBS_DEB_SCAN, "best_bss %p", best_bss);
1917 * @brief Find the best AP
1919 * Used from association worker.
1921 * @param priv A pointer to struct lbs_private structure
1922 * @param pSSID A pointer to AP's ssid
1924 * @return 0--success, otherwise--fail
1926 static int lbs_find_best_network_ssid(struct lbs_private *priv,
1927 uint8_t *out_ssid, uint8_t *out_ssid_len, uint8_t preferred_mode,
1931 struct bss_descriptor *found;
1933 lbs_deb_enter(LBS_DEB_SCAN);
1935 priv->scan_ssid_len = 0;
1936 lbs_scan_networks(priv, 1);
1937 if (priv->surpriseremoved)
1940 found = lbs_find_best_ssid_in_list(priv, preferred_mode);
1941 if (found && (found->ssid_len > 0)) {
1942 memcpy(out_ssid, &found->ssid, IEEE80211_MAX_SSID_LEN);
1943 *out_ssid_len = found->ssid_len;
1944 *out_mode = found->mode;
1949 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
1954 void lbs_association_worker(struct work_struct *work)
1956 struct lbs_private *priv = container_of(work, struct lbs_private,
1958 struct assoc_request * assoc_req = NULL;
1960 int find_any_ssid = 0;
1961 DECLARE_SSID_BUF(ssid);
1963 lbs_deb_enter(LBS_DEB_ASSOC);
1965 mutex_lock(&priv->lock);
1966 assoc_req = priv->pending_assoc_req;
1967 priv->pending_assoc_req = NULL;
1968 priv->in_progress_assoc_req = assoc_req;
1969 mutex_unlock(&priv->lock);
1975 "Association Request:\n"
1982 " secinfo: %s%s%s\n"
1985 print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len),
1986 assoc_req->channel, assoc_req->band, assoc_req->mode,
1988 assoc_req->secinfo.WPAenabled ? " WPA" : "",
1989 assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
1990 assoc_req->secinfo.wep_enabled ? " WEP" : "",
1991 assoc_req->secinfo.auth_mode);
1993 /* If 'any' SSID was specified, find an SSID to associate with */
1994 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
1995 && !assoc_req->ssid_len)
1998 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
1999 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
2000 if (compare_ether_addr(assoc_req->bssid, bssid_any)
2001 && compare_ether_addr(assoc_req->bssid, bssid_off))
2005 if (find_any_ssid) {
2006 u8 new_mode = assoc_req->mode;
2008 ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
2009 &assoc_req->ssid_len, assoc_req->mode, &new_mode);
2011 lbs_deb_assoc("Could not find best network\n");
2016 /* Ensure we switch to the mode of the AP */
2017 if (assoc_req->mode == IW_MODE_AUTO) {
2018 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
2019 assoc_req->mode = new_mode;
2024 * Check if the attributes being changing require deauthentication
2025 * from the currently associated infrastructure access point.
2027 if (priv->mode == IW_MODE_INFRA) {
2028 if (should_deauth_infrastructure(priv, assoc_req)) {
2029 ret = lbs_cmd_80211_deauthenticate(priv,
2030 priv->curbssparams.bssid,
2031 WLAN_REASON_DEAUTH_LEAVING);
2033 lbs_deb_assoc("Deauthentication due to new "
2034 "configuration request failed: %d\n",
2038 } else if (priv->mode == IW_MODE_ADHOC) {
2039 if (should_stop_adhoc(priv, assoc_req)) {
2040 ret = lbs_adhoc_stop(priv);
2042 lbs_deb_assoc("Teardown of AdHoc network due to "
2043 "new configuration request failed: %d\n",
2050 /* Send the various configuration bits to the firmware */
2051 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
2052 ret = assoc_helper_mode(priv, assoc_req);
2057 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
2058 ret = assoc_helper_channel(priv, assoc_req);
2063 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
2064 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
2065 ret = assoc_helper_wep_keys(priv, assoc_req);
2070 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
2071 ret = assoc_helper_secinfo(priv, assoc_req);
2076 if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
2077 ret = assoc_helper_wpa_ie(priv, assoc_req);
2082 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
2083 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
2084 ret = assoc_helper_wpa_keys(priv, assoc_req);
2089 /* SSID/BSSID should be the _last_ config option set, because they
2090 * trigger the association attempt.
2092 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
2093 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
2096 ret = assoc_helper_associate(priv, assoc_req);
2098 lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
2103 if (priv->connect_status != LBS_CONNECTED) {
2104 lbs_deb_assoc("ASSOC: association unsuccessful, "
2110 lbs_deb_assoc("associated to %pM\n",
2111 priv->curbssparams.bssid);
2112 lbs_prepare_and_send_command(priv,
2114 0, CMD_OPTION_WAITFORRSP, 0, NULL);
2122 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
2126 mutex_lock(&priv->lock);
2127 priv->in_progress_assoc_req = NULL;
2128 mutex_unlock(&priv->lock);
2132 lbs_deb_leave(LBS_DEB_ASSOC);
2137 * Caller MUST hold any necessary locks
2139 struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
2141 struct assoc_request * assoc_req;
2143 lbs_deb_enter(LBS_DEB_ASSOC);
2144 if (!priv->pending_assoc_req) {
2145 priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
2147 if (!priv->pending_assoc_req) {
2148 lbs_pr_info("Not enough memory to allocate association"
2154 /* Copy current configuration attributes to the association request,
2155 * but don't overwrite any that are already set.
2157 assoc_req = priv->pending_assoc_req;
2158 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
2159 memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
2160 IEEE80211_MAX_SSID_LEN);
2161 assoc_req->ssid_len = priv->curbssparams.ssid_len;
2164 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
2165 assoc_req->channel = priv->channel;
2167 if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
2168 assoc_req->band = priv->curbssparams.band;
2170 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
2171 assoc_req->mode = priv->mode;
2173 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
2174 memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
2178 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
2180 for (i = 0; i < 4; i++) {
2181 memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
2182 sizeof(struct enc_key));
2186 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
2187 assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
2189 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
2190 memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
2191 sizeof(struct enc_key));
2194 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
2195 memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
2196 sizeof(struct enc_key));
2199 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
2200 memcpy(&assoc_req->secinfo, &priv->secinfo,
2201 sizeof(struct lbs_802_11_security));
2204 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
2205 memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
2207 assoc_req->wpa_ie_len = priv->wpa_ie_len;
2210 lbs_deb_leave(LBS_DEB_ASSOC);
2216 * @brief Deauthenticate from a specific BSS
2218 * @param priv A pointer to struct lbs_private structure
2219 * @param bssid The specific BSS to deauthenticate from
2220 * @param reason The 802.11 sec. 7.3.1.7 Reason Code for deauthenticating
2222 * @return 0 on success, error on failure
2224 int lbs_cmd_80211_deauthenticate(struct lbs_private *priv, u8 bssid[ETH_ALEN],
2227 struct cmd_ds_802_11_deauthenticate cmd;
2230 lbs_deb_enter(LBS_DEB_JOIN);
2232 memset(&cmd, 0, sizeof(cmd));
2233 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2234 memcpy(cmd.macaddr, &bssid[0], ETH_ALEN);
2235 cmd.reasoncode = cpu_to_le16(reason);
2237 ret = lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd);
2239 /* Clean up everything even if there was an error; can't assume that
2240 * we're still authenticated to the AP after trying to deauth.
2242 lbs_mac_event_disconnected(priv);
2244 lbs_deb_leave(LBS_DEB_JOIN);