2 * Marvell Wireless LAN device driver: association and ad-hoc start/join
4 * Copyright (C) 2011, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
28 #define CAPINFO_MASK (~(BIT(15) | BIT(14) | BIT(12) | BIT(11) | BIT(9)))
31 * Append a generic IE as a pass through TLV to a TLV buffer.
33 * This function is called from the network join command preparation routine.
35 * If the IE buffer has been setup by the application, this routine appends
36 * the buffer as a pass through TLV type to the request.
39 mwifiex_cmd_append_generic_ie(struct mwifiex_private *priv, u8 **buffer)
42 struct mwifiex_ie_types_header ie_header;
51 * If there is a generic ie buffer setup, append it to the return
52 * parameter buffer pointer.
54 if (priv->gen_ie_buf_len) {
55 dev_dbg(priv->adapter->dev, "info: %s: append generic %d to %p\n",
56 __func__, priv->gen_ie_buf_len, *buffer);
58 /* Wrap the generic IE buffer with a pass through TLV type */
59 ie_header.type = cpu_to_le16(TLV_TYPE_PASSTHROUGH);
60 ie_header.len = cpu_to_le16(priv->gen_ie_buf_len);
61 memcpy(*buffer, &ie_header, sizeof(ie_header));
63 /* Increment the return size and the return buffer pointer
65 *buffer += sizeof(ie_header);
66 ret_len += sizeof(ie_header);
68 /* Copy the generic IE buffer to the output buffer, advance
70 memcpy(*buffer, priv->gen_ie_buf, priv->gen_ie_buf_len);
72 /* Increment the return size and the return buffer pointer
74 *buffer += priv->gen_ie_buf_len;
75 ret_len += priv->gen_ie_buf_len;
77 /* Reset the generic IE buffer */
78 priv->gen_ie_buf_len = 0;
81 /* return the length appended to the buffer */
86 * Append TSF tracking info from the scan table for the target AP.
88 * This function is called from the network join command preparation routine.
90 * The TSF table TSF sent to the firmware contains two TSF values:
91 * - The TSF of the target AP from its previous beacon/probe response
92 * - The TSF timestamp of our local MAC at the time we observed the
93 * beacon/probe response.
95 * The firmware uses the timestamp values to set an initial TSF value
96 * in the MAC for the new association after a reassociation attempt.
99 mwifiex_cmd_append_tsf_tlv(struct mwifiex_private *priv, u8 **buffer,
100 struct mwifiex_bssdescriptor *bss_desc)
102 struct mwifiex_ie_types_tsf_timestamp tsf_tlv;
111 memset(&tsf_tlv, 0x00, sizeof(struct mwifiex_ie_types_tsf_timestamp));
113 tsf_tlv.header.type = cpu_to_le16(TLV_TYPE_TSFTIMESTAMP);
114 tsf_tlv.header.len = cpu_to_le16(2 * sizeof(tsf_val));
116 memcpy(*buffer, &tsf_tlv, sizeof(tsf_tlv.header));
117 *buffer += sizeof(tsf_tlv.header);
119 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
120 *buffer += sizeof(tsf_val);
122 memcpy(&tsf_val, bss_desc->time_stamp, sizeof(tsf_val));
124 dev_dbg(priv->adapter->dev, "info: %s: TSF offset calc: %016llx - "
125 "%016llx\n", __func__, tsf_val, bss_desc->network_tsf);
127 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
128 *buffer += sizeof(tsf_val);
130 return sizeof(tsf_tlv.header) + (2 * sizeof(tsf_val));
134 * This function finds out the common rates between rate1 and rate2.
136 * It will fill common rates in rate1 as output if found.
138 * NOTE: Setting the MSB of the basic rates needs to be taken
139 * care of, either before or after calling this function.
141 static int mwifiex_get_common_rates(struct mwifiex_private *priv, u8 *rate1,
142 u32 rate1_size, u8 *rate2, u32 rate2_size)
149 tmp = kmalloc(rate1_size, GFP_KERNEL);
151 dev_err(priv->adapter->dev, "failed to alloc tmp buf\n");
155 memcpy(tmp, rate1, rate1_size);
156 memset(rate1, 0, rate1_size);
158 for (i = 0; rate2[i] && i < rate2_size; i++) {
159 for (j = 0; tmp[j] && j < rate1_size; j++) {
160 /* Check common rate, excluding the bit for
162 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) {
169 dev_dbg(priv->adapter->dev, "info: Tx data rate set to %#x\n",
172 if (!priv->is_data_rate_auto) {
174 if ((*ptr & 0x7f) == priv->data_rate) {
180 dev_err(priv->adapter->dev, "previously set fixed data rate %#x"
181 " is not compatible with the network\n",
195 * This function creates the intersection of the rates supported by a
196 * target BSS and our adapter settings for use in an assoc/join command.
199 mwifiex_setup_rates_from_bssdesc(struct mwifiex_private *priv,
200 struct mwifiex_bssdescriptor *bss_desc,
201 u8 *out_rates, u32 *out_rates_size)
203 u8 card_rates[MWIFIEX_SUPPORTED_RATES];
204 u32 card_rates_size = 0;
206 /* Copy AP supported rates */
207 memcpy(out_rates, bss_desc->supported_rates, MWIFIEX_SUPPORTED_RATES);
208 /* Get the STA supported rates */
209 card_rates_size = mwifiex_get_active_data_rates(priv, card_rates);
210 /* Get the common rates between AP and STA supported rates */
211 if (mwifiex_get_common_rates(priv, out_rates, MWIFIEX_SUPPORTED_RATES,
212 card_rates, card_rates_size)) {
214 dev_err(priv->adapter->dev, "%s: cannot get common rates\n",
220 min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES);
226 * This function updates the scan entry TSF timestamps to reflect
230 mwifiex_update_tsf_timestamps(struct mwifiex_private *priv,
231 struct mwifiex_bssdescriptor *new_bss_desc)
233 struct mwifiex_adapter *adapter = priv->adapter;
235 long long new_tsf_base;
236 signed long long tsf_delta;
238 memcpy(&new_tsf_base, new_bss_desc->time_stamp, sizeof(new_tsf_base));
240 tsf_delta = new_tsf_base - new_bss_desc->network_tsf;
242 dev_dbg(adapter->dev, "info: TSF: update TSF timestamps, "
243 "0x%016llx -> 0x%016llx\n",
244 new_bss_desc->network_tsf, new_tsf_base);
246 for (table_idx = 0; table_idx < adapter->num_in_scan_table;
248 adapter->scan_table[table_idx].network_tsf += tsf_delta;
252 * This function appends a WAPI IE.
254 * This function is called from the network join command preparation routine.
256 * If the IE buffer has been setup by the application, this routine appends
257 * the buffer as a WAPI TLV type to the request.
260 mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer)
263 struct mwifiex_ie_types_header ie_header;
272 * If there is a wapi ie buffer setup, append it to the return
273 * parameter buffer pointer.
275 if (priv->wapi_ie_len) {
276 dev_dbg(priv->adapter->dev, "cmd: append wapi ie %d to %p\n",
277 priv->wapi_ie_len, *buffer);
279 /* Wrap the generic IE buffer with a pass through TLV type */
280 ie_header.type = cpu_to_le16(TLV_TYPE_WAPI_IE);
281 ie_header.len = cpu_to_le16(priv->wapi_ie_len);
282 memcpy(*buffer, &ie_header, sizeof(ie_header));
284 /* Increment the return size and the return buffer pointer
286 *buffer += sizeof(ie_header);
287 retLen += sizeof(ie_header);
289 /* Copy the wapi IE buffer to the output buffer, advance
291 memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len);
293 /* Increment the return size and the return buffer pointer
295 *buffer += priv->wapi_ie_len;
296 retLen += priv->wapi_ie_len;
299 /* return the length appended to the buffer */
304 * This function appends rsn ie tlv for wpa/wpa2 security modes.
305 * It is called from the network join command preparation routine.
307 static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private *priv,
310 struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv;
313 if (!buffer || !(*buffer))
316 rsn_ie_tlv = (struct mwifiex_ie_types_rsn_param_set *) (*buffer);
317 rsn_ie_tlv->header.type = cpu_to_le16((u16) priv->wpa_ie[0]);
318 rsn_ie_tlv->header.type = cpu_to_le16(
319 le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF);
320 rsn_ie_tlv->header.len = cpu_to_le16((u16) priv->wpa_ie[1]);
321 rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len)
323 if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2))
324 memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2],
325 le16_to_cpu(rsn_ie_tlv->header.len));
329 rsn_ie_len = sizeof(rsn_ie_tlv->header) +
330 le16_to_cpu(rsn_ie_tlv->header.len);
331 *buffer += rsn_ie_len;
337 * This function prepares command for association.
339 * This sets the following parameters -
343 * - Capability information
345 * ...and the following TLVs, as required -
350 * - Authentication TLV
354 * - Vendor specific TLV
360 * Preparation also includes -
361 * - Setting command ID and proper size
362 * - Ensuring correct endian-ness
364 int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
365 struct host_cmd_ds_command *cmd,
368 struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate;
369 struct mwifiex_bssdescriptor *bss_desc;
370 struct mwifiex_ie_types_ssid_param_set *ssid_tlv;
371 struct mwifiex_ie_types_phy_param_set *phy_tlv;
372 struct mwifiex_ie_types_ss_param_set *ss_tlv;
373 struct mwifiex_ie_types_rates_param_set *rates_tlv;
374 struct mwifiex_ie_types_auth_type *auth_tlv;
375 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
376 u8 rates[MWIFIEX_SUPPORTED_RATES];
382 bss_desc = (struct mwifiex_bssdescriptor *) data_buf;
385 mwifiex_cfg_tx_buf(priv, bss_desc);
387 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
389 /* Save so we know which BSS Desc to use in the response handler */
390 priv->attempted_bss_desc = bss_desc;
392 memcpy(assoc->peer_sta_addr,
393 bss_desc->mac_address, sizeof(assoc->peer_sta_addr));
394 pos += sizeof(assoc->peer_sta_addr);
396 /* Set the listen interval */
397 assoc->listen_interval = cpu_to_le16(priv->listen_interval);
398 /* Set the beacon period */
399 assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period);
401 pos += sizeof(assoc->cap_info_bitmap);
402 pos += sizeof(assoc->listen_interval);
403 pos += sizeof(assoc->beacon_period);
404 pos += sizeof(assoc->dtim_period);
406 ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos;
407 ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID);
408 ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len);
409 memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid,
410 le16_to_cpu(ssid_tlv->header.len));
411 pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len);
413 phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos;
414 phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS);
415 phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set));
416 memcpy(&phy_tlv->fh_ds.ds_param_set,
417 &bss_desc->phy_param_set.ds_param_set.current_chan,
418 sizeof(phy_tlv->fh_ds.ds_param_set));
419 pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len);
421 ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos;
422 ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS);
423 ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set));
424 pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len);
426 /* Get the common rates supported between the driver and the BSS Desc */
427 if (mwifiex_setup_rates_from_bssdesc
428 (priv, bss_desc, rates, &rates_size))
431 /* Save the data rates into Current BSS state structure */
432 priv->curr_bss_params.num_of_rates = rates_size;
433 memcpy(&priv->curr_bss_params.data_rates, rates, rates_size);
435 /* Setup the Rates TLV in the association command */
436 rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos;
437 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
438 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
439 memcpy(rates_tlv->rates, rates, rates_size);
440 pos += sizeof(rates_tlv->header) + rates_size;
441 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: rates size = %d\n",
444 /* Add the Authentication type to be used for Auth frames */
445 auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
446 auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
447 auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
448 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
449 auth_tlv->auth_type = cpu_to_le16(
450 (u16) priv->sec_info.authentication_mode);
452 auth_tlv->auth_type = cpu_to_le16(MWIFIEX_AUTH_MODE_OPEN);
454 pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len);
456 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)
457 && !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
458 && (!bss_desc->disable_11n)
459 && (priv->adapter->config_bands & BAND_GN
460 || priv->adapter->config_bands & BAND_AN)
461 && (bss_desc->bcn_ht_cap)
464 /* Append a channel TLV for the channel the attempted AP was
466 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
467 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
468 chan_tlv->header.len =
469 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
471 memset(chan_tlv->chan_scan_param, 0x00,
472 sizeof(struct mwifiex_chan_scan_param_set));
473 chan_tlv->chan_scan_param[0].chan_number =
474 (bss_desc->phy_param_set.ds_param_set.current_chan);
475 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
476 chan_tlv->chan_scan_param[0].chan_number);
478 chan_tlv->chan_scan_param[0].radio_type =
479 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
481 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
482 chan_tlv->chan_scan_param[0].radio_type);
483 pos += sizeof(chan_tlv->header) +
484 sizeof(struct mwifiex_chan_scan_param_set);
487 if (!priv->wps.session_enable) {
488 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
489 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
491 if (rsn_ie_len == -1)
495 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
496 && (!bss_desc->disable_11n)
497 && (priv->adapter->config_bands & BAND_GN
498 || priv->adapter->config_bands & BAND_AN))
499 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
501 /* Append vendor specific IE TLV */
502 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
504 mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
505 bss_desc->bcn_ht_cap);
506 if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
507 mwifiex_cmd_append_wapi_ie(priv, &pos);
510 mwifiex_cmd_append_generic_ie(priv, &pos);
512 mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
514 cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
516 /* Set the Capability info at last */
517 tmp_cap = bss_desc->cap_info_bitmap;
519 if (priv->adapter->config_bands == BAND_B)
520 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
522 tmp_cap &= CAPINFO_MASK;
523 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
524 tmp_cap, CAPINFO_MASK);
525 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
531 * Association firmware command response handler
533 * The response buffer for the association command has the following
536 * For cases where an association response was not received (indicated
537 * by the CapInfo and AId field):
539 * .------------------------------------------------------------.
540 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
541 * .------------------------------------------------------------.
542 * | cap_info/Error Return(t_u16): |
543 * | 0xFFFF(-1): Internal error |
544 * | 0xFFFE(-2): Authentication unhandled message |
545 * | 0xFFFD(-3): Authentication refused |
546 * | 0xFFFC(-4): Timeout waiting for AP response |
547 * .------------------------------------------------------------.
548 * | status_code(t_u16): |
549 * | If cap_info is -1: |
550 * | An internal firmware failure prevented the |
551 * | command from being processed. The status_code |
552 * | will be set to 1. |
554 * | If cap_info is -2: |
555 * | An authentication frame was received but was |
556 * | not handled by the firmware. IEEE Status |
557 * | code for the failure is returned. |
559 * | If cap_info is -3: |
560 * | An authentication frame was received and the |
561 * | status_code is the IEEE Status reported in the |
564 * | If cap_info is -4: |
565 * | (1) Association response timeout |
566 * | (2) Authentication response timeout |
567 * .------------------------------------------------------------.
568 * | a_id(t_u16): 0xFFFF |
569 * .------------------------------------------------------------.
572 * For cases where an association response was received, the IEEE
573 * standard association response frame is returned:
575 * .------------------------------------------------------------.
576 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
577 * .------------------------------------------------------------.
578 * | cap_info(t_u16): IEEE Capability |
579 * .------------------------------------------------------------.
580 * | status_code(t_u16): IEEE Status Code |
581 * .------------------------------------------------------------.
582 * | a_id(t_u16): IEEE Association ID |
583 * .------------------------------------------------------------.
584 * | IEEE IEs(variable): Any received IEs comprising the |
585 * | remaining portion of a received |
586 * | association response frame. |
587 * .------------------------------------------------------------.
589 * For simplistic handling, the status_code field can be used to determine
590 * an association success (0) or failure (non-zero).
592 int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
593 struct host_cmd_ds_command *resp, void *wq_buf)
596 struct mwifiex_wait_queue *wait_queue =
597 (struct mwifiex_wait_queue *) wq_buf;
598 struct ieee_types_assoc_rsp *assoc_rsp;
599 struct mwifiex_bssdescriptor *bss_desc;
600 u8 enable_data = true;
602 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
604 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
605 sizeof(priv->assoc_rsp_buf));
607 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
609 if (le16_to_cpu(assoc_rsp->status_code)) {
610 priv->adapter->dbg.num_cmd_assoc_failure++;
611 dev_err(priv->adapter->dev, "ASSOC_RESP: association failed, "
612 "status code = %d, error = 0x%x, a_id = 0x%x\n",
613 le16_to_cpu(assoc_rsp->status_code),
614 le16_to_cpu(assoc_rsp->cap_info_bitmap),
615 le16_to_cpu(assoc_rsp->a_id));
621 /* Send a Media Connected event, according to the Spec */
622 priv->media_connected = true;
624 priv->adapter->ps_state = PS_STATE_AWAKE;
625 priv->adapter->pps_uapsd_mode = false;
626 priv->adapter->tx_lock_flag = false;
628 /* Set the attempted BSSID Index to current */
629 bss_desc = priv->attempted_bss_desc;
631 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n",
632 bss_desc->ssid.ssid);
634 /* Make a copy of current BSSID descriptor */
635 memcpy(&priv->curr_bss_params.bss_descriptor,
636 bss_desc, sizeof(struct mwifiex_bssdescriptor));
638 /* Update curr_bss_params */
639 priv->curr_bss_params.bss_descriptor.channel
640 = bss_desc->phy_param_set.ds_param_set.current_chan;
642 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
645 * Adjust the timestamps in the scan table to be relative to the newly
646 * associated AP's TSF
648 mwifiex_update_tsf_timestamps(priv, bss_desc);
650 if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
651 priv->curr_bss_params.wmm_enabled = true;
653 priv->curr_bss_params.wmm_enabled = false;
655 if ((priv->wmm_required || bss_desc->bcn_ht_cap)
656 && priv->curr_bss_params.wmm_enabled)
657 priv->wmm_enabled = true;
659 priv->wmm_enabled = false;
661 priv->curr_bss_params.wmm_uapsd_enabled = false;
663 if (priv->wmm_enabled)
664 priv->curr_bss_params.wmm_uapsd_enabled
665 = ((bss_desc->wmm_ie.qos_info_bitmap &
666 IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
668 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
669 priv->curr_pkt_filter);
670 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
671 priv->wpa_is_gtk_set = false;
673 if (priv->wmm_enabled) {
674 /* Don't re-enable carrier until we get the WMM_GET_STATUS
678 /* Since WMM is not enabled, setup the queues with the
680 mwifiex_wmm_setup_queue_priorities(priv, NULL);
681 mwifiex_wmm_setup_ac_downgrade(priv);
685 dev_dbg(priv->adapter->dev,
686 "info: post association, re-enabling data flow\n");
688 /* Reset SNR/NF/RSSI values */
689 priv->data_rssi_last = 0;
690 priv->data_nf_last = 0;
691 priv->data_rssi_avg = 0;
692 priv->data_nf_avg = 0;
693 priv->bcn_rssi_last = 0;
694 priv->bcn_nf_last = 0;
695 priv->bcn_rssi_avg = 0;
696 priv->bcn_nf_avg = 0;
698 priv->rxpd_htinfo = 0;
700 mwifiex_save_curr_bcn(priv);
702 priv->adapter->dbg.num_cmd_assoc_success++;
704 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n");
706 /* Add the ra_list here for infra mode as there will be only 1 ra
708 mwifiex_ralist_add(priv,
709 priv->curr_bss_params.bss_descriptor.mac_address);
711 if (!netif_carrier_ok(priv->netdev))
712 netif_carrier_on(priv->netdev);
713 if (netif_queue_stopped(priv->netdev))
714 netif_wake_queue(priv->netdev);
716 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
717 priv->scan_block = true;
720 /* Need to indicate IOCTL complete */
723 if (assoc_rsp->status_code)
725 le16_to_cpu(assoc_rsp->status_code);
727 wait_queue->status = MWIFIEX_ERROR_ASSOC_FAIL;
729 wait_queue->status = MWIFIEX_ERROR_NO_ERROR;
737 * This function prepares command for ad-hoc start.
739 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
740 * parameters, probe delay, and capability information. Firmware
741 * will fill up beacon period, basic rates and operational rates.
743 * In addition, the following TLVs are added -
745 * - Vendor specific IE
747 * - HT Capabilities IE
748 * - HT Information IE
750 * Preparation also includes -
751 * - Setting command ID and proper size
752 * - Ensuring correct endian-ness
755 mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
756 struct host_cmd_ds_command *cmd, void *data_buf)
758 int ret = 0, rsn_ie_len = 0;
759 struct mwifiex_adapter *adapter = priv->adapter;
760 struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
761 &cmd->params.adhoc_start;
762 struct mwifiex_bssdescriptor *bss_desc;
763 u32 cmd_append_size = 0;
766 uint16_t ht_cap_info;
767 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
769 struct mwifiex_ie_types_htcap *ht_cap;
770 struct mwifiex_ie_types_htinfo *ht_info;
771 u8 *pos = (u8 *) adhoc_start +
772 sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
777 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
779 bss_desc = &priv->curr_bss_params.bss_descriptor;
780 priv->attempted_bss_desc = bss_desc;
783 * Fill in the parameters for 2 data structures:
784 * 1. struct host_cmd_ds_802_11_ad_hoc_start command
786 * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
787 * probe delay, and Cap info.
788 * Firmware will fill up beacon period, Basic rates
789 * and operational rates.
792 memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
794 memcpy(adhoc_start->ssid,
795 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
796 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
798 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
801 memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
802 memcpy(bss_desc->ssid.ssid,
803 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
804 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
806 bss_desc->ssid.ssid_len =
807 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len;
809 /* Set the BSS mode */
810 adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
811 bss_desc->bss_mode = MWIFIEX_BSS_MODE_IBSS;
812 adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
813 bss_desc->beacon_period = priv->beacon_period;
815 /* Set Physical param set */
816 /* Parameter IE Id */
817 #define DS_PARA_IE_ID 3
818 /* Parameter IE length */
819 #define DS_PARA_IE_LEN 1
821 adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
822 adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
824 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
825 (priv, adapter->adhoc_start_band, (u16)
826 priv->adhoc_channel)) {
827 struct mwifiex_chan_freq_power *cfp;
828 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
829 adapter->adhoc_start_band, FIRST_VALID_CHANNEL);
831 priv->adhoc_channel = (u8) cfp->channel;
834 if (!priv->adhoc_channel) {
835 dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
839 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
840 priv->adhoc_channel);
842 priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
843 priv->curr_bss_params.band = adapter->adhoc_start_band;
845 bss_desc->channel = priv->adhoc_channel;
846 adhoc_start->phy_param_set.ds_param_set.current_chan =
849 memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
850 sizeof(union ieee_types_phy_param_set));
852 /* Set IBSS param set */
853 /* IBSS parameter IE Id */
854 #define IBSS_PARA_IE_ID 6
855 /* IBSS parameter IE length */
856 #define IBSS_PARA_IE_LEN 2
858 adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
859 adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
860 adhoc_start->ss_param_set.ibss_param_set.atim_window
861 = cpu_to_le16(priv->atim_window);
862 memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
863 sizeof(union ieee_types_ss_param_set));
865 /* Set Capability info */
866 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
867 tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap);
868 tmp_cap &= ~WLAN_CAPABILITY_ESS;
869 tmp_cap |= WLAN_CAPABILITY_IBSS;
871 /* Set up privacy in bss_desc */
872 if (priv->sec_info.encryption_mode != MWIFIEX_ENCRYPTION_MODE_NONE) {
873 /* Ad-Hoc capability privacy on */
874 dev_dbg(adapter->dev,
875 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
876 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
877 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
879 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
880 " setting privacy to ACCEPT ALL\n");
881 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
884 memset(adhoc_start->DataRate, 0, sizeof(adhoc_start->DataRate));
885 mwifiex_get_active_data_rates(priv, adhoc_start->DataRate);
886 if ((adapter->adhoc_start_band & BAND_G) &&
887 (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
888 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL,
890 0, NULL, &priv->curr_pkt_filter);
893 dev_err(adapter->dev,
894 "ADHOC_S_CMD: G Protection config failed\n");
898 /* Find the last non zero */
899 for (i = 0; i < sizeof(adhoc_start->DataRate) &&
900 adhoc_start->DataRate[i];
904 priv->curr_bss_params.num_of_rates = i;
906 /* Copy the ad-hoc creating rates into Current BSS rate structure */
907 memcpy(&priv->curr_bss_params.data_rates,
908 &adhoc_start->DataRate, priv->curr_bss_params.num_of_rates);
910 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n",
911 adhoc_start->DataRate[0], adhoc_start->DataRate[1],
912 adhoc_start->DataRate[2], adhoc_start->DataRate[3]);
914 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
916 if (IS_SUPPORT_MULTI_BANDS(adapter)) {
917 /* Append a channel TLV */
918 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
919 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
920 chan_tlv->header.len =
921 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
923 memset(chan_tlv->chan_scan_param, 0x00,
924 sizeof(struct mwifiex_chan_scan_param_set));
925 chan_tlv->chan_scan_param[0].chan_number =
926 (u8) priv->curr_bss_params.bss_descriptor.channel;
928 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
929 chan_tlv->chan_scan_param[0].chan_number);
931 chan_tlv->chan_scan_param[0].radio_type
932 = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
933 if (adapter->adhoc_start_band & BAND_GN
934 || adapter->adhoc_start_band & BAND_AN) {
935 if (adapter->chan_offset == SEC_CHANNEL_ABOVE)
936 chan_tlv->chan_scan_param[0].radio_type |=
937 SECOND_CHANNEL_ABOVE;
938 else if (adapter->chan_offset == SEC_CHANNEL_BELOW)
939 chan_tlv->chan_scan_param[0].radio_type |=
940 SECOND_CHANNEL_BELOW;
942 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
943 chan_tlv->chan_scan_param[0].radio_type);
944 pos += sizeof(chan_tlv->header) +
945 sizeof(struct mwifiex_chan_scan_param_set);
947 sizeof(chan_tlv->header) +
948 sizeof(struct mwifiex_chan_scan_param_set);
951 /* Append vendor specific IE TLV */
952 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
953 MWIFIEX_VSIE_MASK_ADHOC, &pos);
955 if (priv->sec_info.wpa_enabled) {
956 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
957 if (rsn_ie_len == -1)
959 cmd_append_size += rsn_ie_len;
962 if (adapter->adhoc_11n_enabled) {
964 ht_cap = (struct mwifiex_ie_types_htcap *) pos;
966 sizeof(struct mwifiex_ie_types_htcap));
967 ht_cap->header.type =
968 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
970 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
971 ht_cap_info = le16_to_cpu(ht_cap->ht_cap.cap_info);
973 ht_cap_info |= IEEE80211_HT_CAP_SGI_20;
974 if (adapter->chan_offset) {
975 ht_cap_info |= IEEE80211_HT_CAP_SGI_40;
976 ht_cap_info |= IEEE80211_HT_CAP_DSSSCCK40;
977 ht_cap_info |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
978 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
981 ht_cap->ht_cap.ampdu_params_info
982 = IEEE80211_HT_MAX_AMPDU_64K;
983 ht_cap->ht_cap.mcs.rx_mask[0] = 0xff;
984 pos += sizeof(struct mwifiex_ie_types_htcap);
986 sizeof(struct mwifiex_ie_types_htcap);
989 ht_info = (struct mwifiex_ie_types_htinfo *) pos;
991 sizeof(struct mwifiex_ie_types_htinfo));
992 ht_info->header.type =
993 cpu_to_le16(WLAN_EID_HT_INFORMATION);
994 ht_info->header.len =
995 cpu_to_le16(sizeof(struct ieee80211_ht_info));
996 ht_info->ht_info.control_chan =
997 (u8) priv->curr_bss_params.bss_descriptor.
999 if (adapter->chan_offset) {
1000 ht_info->ht_info.ht_param =
1001 adapter->chan_offset;
1002 ht_info->ht_info.ht_param |=
1003 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
1005 ht_info->ht_info.operation_mode =
1006 cpu_to_le16(NON_GREENFIELD_STAS);
1007 ht_info->ht_info.basic_set[0] = 0xff;
1008 pos += sizeof(struct mwifiex_ie_types_htinfo);
1010 sizeof(struct mwifiex_ie_types_htinfo);
1014 cmd->size = cpu_to_le16((u16)
1015 (sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
1016 + S_DS_GEN + cmd_append_size));
1018 if (adapter->adhoc_start_band == BAND_B)
1019 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
1021 tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1023 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1029 * This function prepares command for ad-hoc join.
1031 * Most of the parameters are set up by copying from the target BSS descriptor
1032 * from the scan response.
1034 * In addition, the following TLVs are added -
1036 * - Vendor specific IE
1040 * Preparation also includes -
1041 * - Setting command ID and proper size
1042 * - Ensuring correct endian-ness
1045 mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1046 struct host_cmd_ds_command *cmd, void *data_buf)
1048 int ret = 0, rsn_ie_len = 0;
1049 struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
1050 &cmd->params.adhoc_join;
1051 struct mwifiex_bssdescriptor *bss_desc =
1052 (struct mwifiex_bssdescriptor *) data_buf;
1053 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
1054 u32 cmd_append_size = 0;
1056 u32 i, rates_size = 0;
1057 u16 curr_pkt_filter;
1060 sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
1062 /* Use G protection */
1063 #define USE_G_PROTECTION 0x02
1064 if (bss_desc->erp_flags & USE_G_PROTECTION) {
1067 curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
1069 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL,
1070 HostCmd_ACT_GEN_SET, 0, NULL,
1073 dev_err(priv->adapter->dev,
1074 "ADHOC_J_CMD: G Protection config failed\n");
1079 priv->attempted_bss_desc = bss_desc;
1081 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1083 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1085 adhoc_join->bss_descriptor.beacon_period
1086 = cpu_to_le16(bss_desc->beacon_period);
1088 memcpy(&adhoc_join->bss_descriptor.bssid,
1089 &bss_desc->mac_address, ETH_ALEN);
1091 memcpy(&adhoc_join->bss_descriptor.ssid,
1092 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1094 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1095 &bss_desc->phy_param_set,
1096 sizeof(union ieee_types_phy_param_set));
1098 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1099 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1101 tmp_cap = bss_desc->cap_info_bitmap;
1103 tmp_cap &= CAPINFO_MASK;
1105 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: tmp_cap=%4X"
1106 " CAPINFO_MASK=%4lX\n", tmp_cap, CAPINFO_MASK);
1108 /* Information on BSSID descriptor passed to FW */
1109 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID = %pM, SSID = %s\n",
1110 adhoc_join->bss_descriptor.bssid,
1111 adhoc_join->bss_descriptor.ssid);
1113 for (i = 0; bss_desc->supported_rates[i] &&
1114 i < MWIFIEX_SUPPORTED_RATES;
1119 /* Copy Data Rates from the Rates recorded in scan response */
1120 memset(adhoc_join->bss_descriptor.data_rates, 0,
1121 sizeof(adhoc_join->bss_descriptor.data_rates));
1122 memcpy(adhoc_join->bss_descriptor.data_rates,
1123 bss_desc->supported_rates, rates_size);
1125 /* Copy the adhoc join rates into Current BSS state structure */
1126 priv->curr_bss_params.num_of_rates = rates_size;
1127 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1130 /* Copy the channel information */
1131 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1132 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1134 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED
1135 || priv->sec_info.wpa_enabled)
1136 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1138 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1139 /* Append a channel TLV */
1140 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1141 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1142 chan_tlv->header.len =
1143 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1145 memset(chan_tlv->chan_scan_param, 0x00,
1146 sizeof(struct mwifiex_chan_scan_param_set));
1147 chan_tlv->chan_scan_param[0].chan_number =
1148 (bss_desc->phy_param_set.ds_param_set.current_chan);
1149 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan = %d\n",
1150 chan_tlv->chan_scan_param[0].chan_number);
1152 chan_tlv->chan_scan_param[0].radio_type =
1153 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1155 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band = %d\n",
1156 chan_tlv->chan_scan_param[0].radio_type);
1157 pos += sizeof(chan_tlv->header) +
1158 sizeof(struct mwifiex_chan_scan_param_set);
1159 cmd_append_size += sizeof(chan_tlv->header) +
1160 sizeof(struct mwifiex_chan_scan_param_set);
1163 if (priv->sec_info.wpa_enabled)
1164 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1165 if (rsn_ie_len == -1)
1167 cmd_append_size += rsn_ie_len;
1169 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1170 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1173 /* Append vendor specific IE TLV */
1174 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1175 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1177 cmd->size = cpu_to_le16((u16)
1178 (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1179 + S_DS_GEN + cmd_append_size));
1181 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1187 * This function handles the command response of ad-hoc start and
1190 * The function generates a device-connected event to notify
1191 * the applications, in case of successful ad-hoc start/join, and
1192 * saves the beacon buffer.
1194 int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
1195 struct host_cmd_ds_command *resp, void *wq_buf)
1198 struct mwifiex_wait_queue *wait_queue =
1199 (struct mwifiex_wait_queue *) wq_buf;
1200 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1201 struct mwifiex_bssdescriptor *bss_desc;
1202 u16 command = le16_to_cpu(resp->command);
1203 u16 result = le16_to_cpu(resp->result);
1205 adhoc_result = &resp->params.adhoc_result;
1207 bss_desc = priv->attempted_bss_desc;
1209 /* Join result code 0 --> SUCCESS */
1211 dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
1212 if (priv->media_connected)
1213 mwifiex_reset_connect_state(priv);
1215 memset(&priv->curr_bss_params.bss_descriptor,
1216 0x00, sizeof(struct mwifiex_bssdescriptor));
1222 /* Send a Media Connected event, according to the Spec */
1223 priv->media_connected = true;
1225 if (command == HostCmd_CMD_802_11_AD_HOC_START) {
1226 dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
1227 bss_desc->ssid.ssid);
1229 /* Update the created network descriptor with the new BSSID */
1230 memcpy(bss_desc->mac_address,
1231 adhoc_result->bssid, ETH_ALEN);
1233 priv->adhoc_state = ADHOC_STARTED;
1236 * Now the join cmd should be successful.
1237 * If BSSID has changed use SSID to compare instead of BSSID
1239 dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
1240 bss_desc->ssid.ssid);
1243 * Make a copy of current BSSID descriptor, only needed for
1244 * join since the current descriptor is already being used
1247 memcpy(&priv->curr_bss_params.bss_descriptor,
1248 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1250 priv->adhoc_state = ADHOC_JOINED;
1253 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
1254 priv->adhoc_channel);
1255 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
1256 priv->curr_bss_params.bss_descriptor.mac_address);
1258 if (!netif_carrier_ok(priv->netdev))
1259 netif_carrier_on(priv->netdev);
1260 if (netif_queue_stopped(priv->netdev))
1261 netif_wake_queue(priv->netdev);
1263 mwifiex_save_curr_bcn(priv);
1266 /* Need to indicate IOCTL complete */
1269 wait_queue->status = MWIFIEX_ERROR_ASSOC_FAIL;
1271 wait_queue->status = MWIFIEX_ERROR_NO_ERROR;
1279 * This function associates to a specific BSS discovered in a scan.
1281 * It clears any past association response stored for application
1282 * retrieval and calls the command preparation routine to send the
1283 * command to firmware.
1285 int mwifiex_associate(struct mwifiex_private *priv,
1286 void *wait_queue, struct mwifiex_bssdescriptor *bss_desc)
1289 u8 current_bssid[ETH_ALEN];
1291 /* Return error if the adapter or table entry is not marked as infra */
1292 if ((priv->bss_mode != MWIFIEX_BSS_MODE_INFRA) ||
1293 (bss_desc->bss_mode != MWIFIEX_BSS_MODE_INFRA))
1296 memcpy(¤t_bssid,
1297 &priv->curr_bss_params.bss_descriptor.mac_address,
1298 sizeof(current_bssid));
1300 /* Clear any past association response stored for application
1302 priv->assoc_rsp_size = 0;
1304 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_ASSOCIATE,
1305 HostCmd_ACT_GEN_SET, 0, wait_queue,
1312 * This function starts an ad-hoc network.
1314 * It calls the command preparation routine to send the command to firmware.
1317 mwifiex_adhoc_start(struct mwifiex_private *priv,
1318 void *wait_queue, struct mwifiex_802_11_ssid *adhoc_ssid)
1322 dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
1323 priv->adhoc_channel);
1324 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1325 priv->curr_bss_params.bss_descriptor.channel);
1326 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
1327 priv->curr_bss_params.band);
1329 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_AD_HOC_START,
1330 HostCmd_ACT_GEN_SET, 0, wait_queue,
1337 * This function joins an ad-hoc network found in a previous scan.
1339 * It calls the command preparation routine to send the command to firmware,
1340 * if already not connected to the requested SSID.
1342 int mwifiex_adhoc_join(struct mwifiex_private *priv,
1343 void *wait_queue, struct mwifiex_bssdescriptor *bss_desc)
1347 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
1348 priv->curr_bss_params.bss_descriptor.ssid.ssid);
1349 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
1350 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
1351 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
1352 bss_desc->ssid.ssid);
1353 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
1354 bss_desc->ssid.ssid_len);
1356 /* Check if the requested SSID is already joined */
1357 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1358 !mwifiex_ssid_cmp(&bss_desc->ssid,
1359 &priv->curr_bss_params.bss_descriptor.ssid) &&
1360 (priv->curr_bss_params.bss_descriptor.bss_mode ==
1361 MWIFIEX_BSS_MODE_IBSS)) {
1362 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
1363 " is the same as current; not attempting to re-join\n");
1367 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1368 priv->curr_bss_params.bss_descriptor.channel);
1369 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
1370 priv->curr_bss_params.band);
1372 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
1373 HostCmd_ACT_GEN_SET, 0, wait_queue,
1380 * This function deauthenticates/disconnects from infra network by sending
1381 * deauthentication request.
1383 static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv,
1384 struct mwifiex_wait_queue *wait,
1387 u8 mac_address[ETH_ALEN];
1389 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
1392 if (!memcmp(mac, zero_mac, sizeof(zero_mac)))
1393 memcpy((u8 *) &mac_address,
1394 (u8 *) &priv->curr_bss_params.bss_descriptor.
1395 mac_address, ETH_ALEN);
1397 memcpy((u8 *) &mac_address, (u8 *) mac, ETH_ALEN);
1399 memcpy((u8 *) &mac_address, (u8 *) &priv->curr_bss_params.
1400 bss_descriptor.mac_address, ETH_ALEN);
1403 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
1404 HostCmd_ACT_GEN_SET, 0, wait, &mac_address);
1413 * This function deauthenticates/disconnects from a BSS.
1415 * In case of infra made, it sends deauthentication request, and
1416 * in case of ad-hoc mode, a stop network request is sent to the firmware.
1418 int mwifiex_deauthenticate(struct mwifiex_private *priv,
1419 struct mwifiex_wait_queue *wait, u8 *mac)
1423 if (priv->media_connected) {
1424 if (priv->bss_mode == MWIFIEX_BSS_MODE_INFRA) {
1425 ret = mwifiex_deauthenticate_infra(priv, wait, mac);
1426 } else if (priv->bss_mode == MWIFIEX_BSS_MODE_IBSS) {
1427 ret = mwifiex_prepare_cmd(priv,
1428 HostCmd_CMD_802_11_AD_HOC_STOP,
1429 HostCmd_ACT_GEN_SET, 0, wait, NULL);
1440 * This function converts band to radio type used in channel TLV.
1443 mwifiex_band_to_radio_type(u8 band)
1450 case BAND_A | BAND_AN:
1451 ret_radio_type = HostCmd_SCAN_RADIO_TYPE_A;
1455 case BAND_B | BAND_G:
1457 ret_radio_type = HostCmd_SCAN_RADIO_TYPE_BG;
1461 return ret_radio_type;