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 if needed */
445 if (priv->sec_info.authentication_mode != MWIFIEX_AUTH_MODE_AUTO) {
446 auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
447 auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
448 auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
449 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
450 auth_tlv->auth_type = cpu_to_le16((u16) priv->sec_info.
451 authentication_mode);
453 auth_tlv->auth_type =
454 cpu_to_le16(MWIFIEX_AUTH_MODE_OPEN);
455 pos += sizeof(auth_tlv->header) +
456 le16_to_cpu(auth_tlv->header.len);
459 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)
460 && !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
461 && (!bss_desc->disable_11n)
462 && (priv->adapter->config_bands & BAND_GN
463 || priv->adapter->config_bands & BAND_AN)
464 && (bss_desc->bcn_ht_cap)
467 /* Append a channel TLV for the channel the attempted AP was
469 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
470 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
471 chan_tlv->header.len =
472 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
474 memset(chan_tlv->chan_scan_param, 0x00,
475 sizeof(struct mwifiex_chan_scan_param_set));
476 chan_tlv->chan_scan_param[0].chan_number =
477 (bss_desc->phy_param_set.ds_param_set.current_chan);
478 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
479 chan_tlv->chan_scan_param[0].chan_number);
481 chan_tlv->chan_scan_param[0].radio_type =
482 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
484 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
485 chan_tlv->chan_scan_param[0].radio_type);
486 pos += sizeof(chan_tlv->header) +
487 sizeof(struct mwifiex_chan_scan_param_set);
490 if (!priv->wps.session_enable) {
491 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
492 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
494 if (rsn_ie_len == -1)
498 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
499 && (!bss_desc->disable_11n)
500 && (priv->adapter->config_bands & BAND_GN
501 || priv->adapter->config_bands & BAND_AN))
502 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
504 /* Append vendor specific IE TLV */
505 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
507 mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
508 bss_desc->bcn_ht_cap);
509 if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
510 mwifiex_cmd_append_wapi_ie(priv, &pos);
513 mwifiex_cmd_append_generic_ie(priv, &pos);
515 mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
517 cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
519 /* Set the Capability info at last */
520 tmp_cap = bss_desc->cap_info_bitmap;
522 if (priv->adapter->config_bands == BAND_B)
523 SHORT_SLOT_TIME_DISABLED(tmp_cap);
525 tmp_cap &= CAPINFO_MASK;
526 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
527 tmp_cap, CAPINFO_MASK);
528 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
534 * Association firmware command response handler
536 * The response buffer for the association command has the following
539 * For cases where an association response was not received (indicated
540 * by the CapInfo and AId field):
542 * .------------------------------------------------------------.
543 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
544 * .------------------------------------------------------------.
545 * | cap_info/Error Return(t_u16): |
546 * | 0xFFFF(-1): Internal error |
547 * | 0xFFFE(-2): Authentication unhandled message |
548 * | 0xFFFD(-3): Authentication refused |
549 * | 0xFFFC(-4): Timeout waiting for AP response |
550 * .------------------------------------------------------------.
551 * | status_code(t_u16): |
552 * | If cap_info is -1: |
553 * | An internal firmware failure prevented the |
554 * | command from being processed. The status_code |
555 * | will be set to 1. |
557 * | If cap_info is -2: |
558 * | An authentication frame was received but was |
559 * | not handled by the firmware. IEEE Status |
560 * | code for the failure is returned. |
562 * | If cap_info is -3: |
563 * | An authentication frame was received and the |
564 * | status_code is the IEEE Status reported in the |
567 * | If cap_info is -4: |
568 * | (1) Association response timeout |
569 * | (2) Authentication response timeout |
570 * .------------------------------------------------------------.
571 * | a_id(t_u16): 0xFFFF |
572 * .------------------------------------------------------------.
575 * For cases where an association response was received, the IEEE
576 * standard association response frame is returned:
578 * .------------------------------------------------------------.
579 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
580 * .------------------------------------------------------------.
581 * | cap_info(t_u16): IEEE Capability |
582 * .------------------------------------------------------------.
583 * | status_code(t_u16): IEEE Status Code |
584 * .------------------------------------------------------------.
585 * | a_id(t_u16): IEEE Association ID |
586 * .------------------------------------------------------------.
587 * | IEEE IEs(variable): Any received IEs comprising the |
588 * | remaining portion of a received |
589 * | association response frame. |
590 * .------------------------------------------------------------.
592 * For simplistic handling, the status_code field can be used to determine
593 * an association success (0) or failure (non-zero).
595 int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
596 struct host_cmd_ds_command *resp, void *wq_buf)
599 struct mwifiex_wait_queue *wait_queue =
600 (struct mwifiex_wait_queue *) wq_buf;
601 struct ieee_types_assoc_rsp *assoc_rsp;
602 struct mwifiex_bssdescriptor *bss_desc;
603 u8 enable_data = true;
605 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
607 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
608 sizeof(priv->assoc_rsp_buf));
610 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
612 if (le16_to_cpu(assoc_rsp->status_code)) {
613 priv->adapter->dbg.num_cmd_assoc_failure++;
614 dev_err(priv->adapter->dev, "ASSOC_RESP: association failed, "
615 "status code = %d, error = 0x%x, a_id = 0x%x\n",
616 le16_to_cpu(assoc_rsp->status_code),
617 le16_to_cpu(assoc_rsp->cap_info_bitmap),
618 le16_to_cpu(assoc_rsp->a_id));
624 /* Send a Media Connected event, according to the Spec */
625 priv->media_connected = true;
627 priv->adapter->ps_state = PS_STATE_AWAKE;
628 priv->adapter->pps_uapsd_mode = false;
629 priv->adapter->tx_lock_flag = false;
631 /* Set the attempted BSSID Index to current */
632 bss_desc = priv->attempted_bss_desc;
634 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n",
635 bss_desc->ssid.ssid);
637 /* Make a copy of current BSSID descriptor */
638 memcpy(&priv->curr_bss_params.bss_descriptor,
639 bss_desc, sizeof(struct mwifiex_bssdescriptor));
641 /* Update curr_bss_params */
642 priv->curr_bss_params.bss_descriptor.channel
643 = bss_desc->phy_param_set.ds_param_set.current_chan;
645 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
648 * Adjust the timestamps in the scan table to be relative to the newly
649 * associated AP's TSF
651 mwifiex_update_tsf_timestamps(priv, bss_desc);
653 if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
654 priv->curr_bss_params.wmm_enabled = true;
656 priv->curr_bss_params.wmm_enabled = false;
658 if ((priv->wmm_required || bss_desc->bcn_ht_cap)
659 && priv->curr_bss_params.wmm_enabled)
660 priv->wmm_enabled = true;
662 priv->wmm_enabled = false;
664 priv->curr_bss_params.wmm_uapsd_enabled = false;
666 if (priv->wmm_enabled)
667 priv->curr_bss_params.wmm_uapsd_enabled
668 = ((bss_desc->wmm_ie.qos_info_bitmap &
669 IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
671 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
672 priv->curr_pkt_filter);
673 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
674 priv->wpa_is_gtk_set = false;
676 if (priv->wmm_enabled) {
677 /* Don't re-enable carrier until we get the WMM_GET_STATUS
681 /* Since WMM is not enabled, setup the queues with the
683 mwifiex_wmm_setup_queue_priorities(priv, NULL);
684 mwifiex_wmm_setup_ac_downgrade(priv);
688 dev_dbg(priv->adapter->dev,
689 "info: post association, re-enabling data flow\n");
691 /* Reset SNR/NF/RSSI values */
692 priv->data_rssi_last = 0;
693 priv->data_nf_last = 0;
694 priv->data_rssi_avg = 0;
695 priv->data_nf_avg = 0;
696 priv->bcn_rssi_last = 0;
697 priv->bcn_nf_last = 0;
698 priv->bcn_rssi_avg = 0;
699 priv->bcn_nf_avg = 0;
701 priv->rxpd_htinfo = 0;
703 mwifiex_save_curr_bcn(priv);
705 priv->adapter->dbg.num_cmd_assoc_success++;
707 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n");
709 /* Add the ra_list here for infra mode as there will be only 1 ra
711 mwifiex_ralist_add(priv,
712 priv->curr_bss_params.bss_descriptor.mac_address);
714 if (!netif_carrier_ok(priv->netdev))
715 netif_carrier_on(priv->netdev);
716 if (netif_queue_stopped(priv->netdev))
717 netif_wake_queue(priv->netdev);
719 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
720 priv->scan_block = true;
723 /* Need to indicate IOCTL complete */
726 if (assoc_rsp->status_code)
728 le16_to_cpu(assoc_rsp->status_code);
730 wait_queue->status = MWIFIEX_ERROR_ASSOC_FAIL;
732 wait_queue->status = MWIFIEX_ERROR_NO_ERROR;
740 * This function prepares command for ad-hoc start.
742 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
743 * parameters, probe delay, and capability information. Firmware
744 * will fill up beacon period, basic rates and operational rates.
746 * In addition, the following TLVs are added -
748 * - Vendor specific IE
750 * - HT Capabilities IE
751 * - HT Information IE
753 * Preparation also includes -
754 * - Setting command ID and proper size
755 * - Ensuring correct endian-ness
758 mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
759 struct host_cmd_ds_command *cmd, void *data_buf)
761 int ret = 0, rsn_ie_len = 0;
762 struct mwifiex_adapter *adapter = priv->adapter;
763 struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
764 &cmd->params.adhoc_start;
765 struct mwifiex_bssdescriptor *bss_desc;
766 u32 cmd_append_size = 0;
769 uint16_t ht_cap_info;
770 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
772 struct mwifiex_ie_types_htcap *ht_cap;
773 struct mwifiex_ie_types_htinfo *ht_info;
774 u8 *pos = (u8 *) adhoc_start +
775 sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
780 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
782 bss_desc = &priv->curr_bss_params.bss_descriptor;
783 priv->attempted_bss_desc = bss_desc;
786 * Fill in the parameters for 2 data structures:
787 * 1. struct host_cmd_ds_802_11_ad_hoc_start command
789 * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
790 * probe delay, and Cap info.
791 * Firmware will fill up beacon period, Basic rates
792 * and operational rates.
795 memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
797 memcpy(adhoc_start->ssid,
798 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
799 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
801 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
804 memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
805 memcpy(bss_desc->ssid.ssid,
806 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
807 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
809 bss_desc->ssid.ssid_len =
810 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len;
812 /* Set the BSS mode */
813 adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
814 bss_desc->bss_mode = MWIFIEX_BSS_MODE_IBSS;
815 adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
816 bss_desc->beacon_period = priv->beacon_period;
818 /* Set Physical param set */
819 /* Parameter IE Id */
820 #define DS_PARA_IE_ID 3
821 /* Parameter IE length */
822 #define DS_PARA_IE_LEN 1
824 adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
825 adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
827 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
828 (priv, adapter->adhoc_start_band, (u16)
829 priv->adhoc_channel)) {
830 struct mwifiex_chan_freq_power *cfp;
831 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
832 adapter->adhoc_start_band, FIRST_VALID_CHANNEL);
834 priv->adhoc_channel = (u8) cfp->channel;
837 if (!priv->adhoc_channel) {
838 dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
842 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
843 priv->adhoc_channel);
845 priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
846 priv->curr_bss_params.band = adapter->adhoc_start_band;
848 bss_desc->channel = priv->adhoc_channel;
849 adhoc_start->phy_param_set.ds_param_set.current_chan =
852 memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
853 sizeof(union ieee_types_phy_param_set));
855 /* Set IBSS param set */
856 /* IBSS parameter IE Id */
857 #define IBSS_PARA_IE_ID 6
858 /* IBSS parameter IE length */
859 #define IBSS_PARA_IE_LEN 2
861 adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
862 adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
863 adhoc_start->ss_param_set.ibss_param_set.atim_window
864 = cpu_to_le16(priv->atim_window);
865 memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
866 sizeof(union ieee_types_ss_param_set));
868 /* Set Capability info */
869 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
870 tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap);
871 tmp_cap &= ~WLAN_CAPABILITY_ESS;
872 tmp_cap |= WLAN_CAPABILITY_IBSS;
874 /* Set up privacy in bss_desc */
875 if (priv->sec_info.encryption_mode != MWIFIEX_ENCRYPTION_MODE_NONE) {
876 /* Ad-Hoc capability privacy on */
877 dev_dbg(adapter->dev,
878 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
879 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
880 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
882 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
883 " setting privacy to ACCEPT ALL\n");
884 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
887 memset(adhoc_start->DataRate, 0, sizeof(adhoc_start->DataRate));
888 mwifiex_get_active_data_rates(priv, adhoc_start->DataRate);
889 if ((adapter->adhoc_start_band & BAND_G) &&
890 (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
891 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL,
893 0, NULL, &priv->curr_pkt_filter);
896 dev_err(adapter->dev,
897 "ADHOC_S_CMD: G Protection config failed\n");
901 /* Find the last non zero */
902 for (i = 0; i < sizeof(adhoc_start->DataRate) &&
903 adhoc_start->DataRate[i];
907 priv->curr_bss_params.num_of_rates = i;
909 /* Copy the ad-hoc creating rates into Current BSS rate structure */
910 memcpy(&priv->curr_bss_params.data_rates,
911 &adhoc_start->DataRate, priv->curr_bss_params.num_of_rates);
913 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n",
914 adhoc_start->DataRate[0], adhoc_start->DataRate[1],
915 adhoc_start->DataRate[2], adhoc_start->DataRate[3]);
917 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
919 if (IS_SUPPORT_MULTI_BANDS(adapter)) {
920 /* Append a channel TLV */
921 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
922 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
923 chan_tlv->header.len =
924 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
926 memset(chan_tlv->chan_scan_param, 0x00,
927 sizeof(struct mwifiex_chan_scan_param_set));
928 chan_tlv->chan_scan_param[0].chan_number =
929 (u8) priv->curr_bss_params.bss_descriptor.channel;
931 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
932 chan_tlv->chan_scan_param[0].chan_number);
934 chan_tlv->chan_scan_param[0].radio_type
935 = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
936 if (adapter->adhoc_start_band & BAND_GN
937 || adapter->adhoc_start_band & BAND_AN) {
938 if (adapter->chan_offset == SEC_CHANNEL_ABOVE)
939 chan_tlv->chan_scan_param[0].radio_type |=
940 SECOND_CHANNEL_ABOVE;
941 else if (adapter->chan_offset == SEC_CHANNEL_BELOW)
942 chan_tlv->chan_scan_param[0].radio_type |=
943 SECOND_CHANNEL_BELOW;
945 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
946 chan_tlv->chan_scan_param[0].radio_type);
947 pos += sizeof(chan_tlv->header) +
948 sizeof(struct mwifiex_chan_scan_param_set);
950 sizeof(chan_tlv->header) +
951 sizeof(struct mwifiex_chan_scan_param_set);
954 /* Append vendor specific IE TLV */
955 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
956 MWIFIEX_VSIE_MASK_ADHOC, &pos);
958 if (priv->sec_info.wpa_enabled) {
959 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
960 if (rsn_ie_len == -1)
962 cmd_append_size += rsn_ie_len;
965 if (adapter->adhoc_11n_enabled) {
967 ht_cap = (struct mwifiex_ie_types_htcap *) pos;
969 sizeof(struct mwifiex_ie_types_htcap));
970 ht_cap->header.type =
971 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
973 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
974 ht_cap_info = le16_to_cpu(ht_cap->ht_cap.cap_info);
976 SETHT_SHORTGI20(ht_cap_info);
977 if (adapter->chan_offset) {
978 SETHT_SHORTGI40(ht_cap_info);
979 SETHT_DSSSCCK40(ht_cap_info);
980 SETHT_SUPPCHANWIDTH(ht_cap_info);
981 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
984 ht_cap->ht_cap.ampdu_params_info
985 = MAX_RX_AMPDU_SIZE_64K;
986 ht_cap->ht_cap.mcs.rx_mask[0] = 0xff;
987 pos += sizeof(struct mwifiex_ie_types_htcap);
989 sizeof(struct mwifiex_ie_types_htcap);
992 ht_info = (struct mwifiex_ie_types_htinfo *) pos;
994 sizeof(struct mwifiex_ie_types_htinfo));
995 ht_info->header.type =
996 cpu_to_le16(WLAN_EID_HT_INFORMATION);
997 ht_info->header.len =
998 cpu_to_le16(sizeof(struct ieee80211_ht_info));
999 ht_info->ht_info.control_chan =
1000 (u8) priv->curr_bss_params.bss_descriptor.
1002 if (adapter->chan_offset) {
1003 ht_info->ht_info.ht_param =
1004 adapter->chan_offset;
1005 SET_CHANWIDTH40(ht_info->ht_info.ht_param);
1007 ht_info->ht_info.operation_mode =
1008 cpu_to_le16(NON_GREENFIELD_STAS);
1009 ht_info->ht_info.basic_set[0] = 0xff;
1010 pos += sizeof(struct mwifiex_ie_types_htinfo);
1012 sizeof(struct mwifiex_ie_types_htinfo);
1016 cmd->size = cpu_to_le16((u16)
1017 (sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
1018 + S_DS_GEN + cmd_append_size));
1020 if (adapter->adhoc_start_band == BAND_B)
1021 SHORT_SLOT_TIME_DISABLED(tmp_cap);
1023 SHORT_SLOT_TIME_ENABLED(tmp_cap);
1025 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1031 * This function prepares command for ad-hoc join.
1033 * Most of the parameters are set up by copying from the target BSS descriptor
1034 * from the scan response.
1036 * In addition, the following TLVs are added -
1038 * - Vendor specific IE
1042 * Preparation also includes -
1043 * - Setting command ID and proper size
1044 * - Ensuring correct endian-ness
1047 mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1048 struct host_cmd_ds_command *cmd, void *data_buf)
1050 int ret = 0, rsn_ie_len = 0;
1051 struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
1052 &cmd->params.adhoc_join;
1053 struct mwifiex_bssdescriptor *bss_desc =
1054 (struct mwifiex_bssdescriptor *) data_buf;
1055 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
1056 u32 cmd_append_size = 0;
1058 u32 i, rates_size = 0;
1059 u16 curr_pkt_filter;
1062 sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
1064 /* Use G protection */
1065 #define USE_G_PROTECTION 0x02
1066 if (bss_desc->erp_flags & USE_G_PROTECTION) {
1069 curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
1071 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_MAC_CONTROL,
1072 HostCmd_ACT_GEN_SET, 0, NULL,
1075 dev_err(priv->adapter->dev,
1076 "ADHOC_J_CMD: G Protection config failed\n");
1081 priv->attempted_bss_desc = bss_desc;
1083 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1085 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1087 adhoc_join->bss_descriptor.beacon_period
1088 = cpu_to_le16(bss_desc->beacon_period);
1090 memcpy(&adhoc_join->bss_descriptor.bssid,
1091 &bss_desc->mac_address, ETH_ALEN);
1093 memcpy(&adhoc_join->bss_descriptor.ssid,
1094 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1096 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1097 &bss_desc->phy_param_set,
1098 sizeof(union ieee_types_phy_param_set));
1100 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1101 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1103 tmp_cap = bss_desc->cap_info_bitmap;
1105 tmp_cap &= CAPINFO_MASK;
1107 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: tmp_cap=%4X"
1108 " CAPINFO_MASK=%4lX\n", tmp_cap, CAPINFO_MASK);
1110 /* Information on BSSID descriptor passed to FW */
1111 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID = %pM, SSID = %s\n",
1112 adhoc_join->bss_descriptor.bssid,
1113 adhoc_join->bss_descriptor.ssid);
1115 for (i = 0; bss_desc->supported_rates[i] &&
1116 i < MWIFIEX_SUPPORTED_RATES;
1121 /* Copy Data Rates from the Rates recorded in scan response */
1122 memset(adhoc_join->bss_descriptor.data_rates, 0,
1123 sizeof(adhoc_join->bss_descriptor.data_rates));
1124 memcpy(adhoc_join->bss_descriptor.data_rates,
1125 bss_desc->supported_rates, rates_size);
1127 /* Copy the adhoc join rates into Current BSS state structure */
1128 priv->curr_bss_params.num_of_rates = rates_size;
1129 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1132 /* Copy the channel information */
1133 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1134 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1136 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED
1137 || priv->sec_info.wpa_enabled)
1138 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1140 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1141 /* Append a channel TLV */
1142 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1143 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1144 chan_tlv->header.len =
1145 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1147 memset(chan_tlv->chan_scan_param, 0x00,
1148 sizeof(struct mwifiex_chan_scan_param_set));
1149 chan_tlv->chan_scan_param[0].chan_number =
1150 (bss_desc->phy_param_set.ds_param_set.current_chan);
1151 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan = %d\n",
1152 chan_tlv->chan_scan_param[0].chan_number);
1154 chan_tlv->chan_scan_param[0].radio_type =
1155 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1157 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band = %d\n",
1158 chan_tlv->chan_scan_param[0].radio_type);
1159 pos += sizeof(chan_tlv->header) +
1160 sizeof(struct mwifiex_chan_scan_param_set);
1161 cmd_append_size += sizeof(chan_tlv->header) +
1162 sizeof(struct mwifiex_chan_scan_param_set);
1165 if (priv->sec_info.wpa_enabled)
1166 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1167 if (rsn_ie_len == -1)
1169 cmd_append_size += rsn_ie_len;
1171 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1172 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1175 /* Append vendor specific IE TLV */
1176 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1177 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1179 cmd->size = cpu_to_le16((u16)
1180 (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1181 + S_DS_GEN + cmd_append_size));
1183 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1189 * This function handles the command response of ad-hoc start and
1192 * The function generates a device-connected event to notify
1193 * the applications, in case of successful ad-hoc start/join, and
1194 * saves the beacon buffer.
1196 int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
1197 struct host_cmd_ds_command *resp, void *wq_buf)
1200 struct mwifiex_wait_queue *wait_queue =
1201 (struct mwifiex_wait_queue *) wq_buf;
1202 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1203 struct mwifiex_bssdescriptor *bss_desc;
1204 u16 command = le16_to_cpu(resp->command);
1205 u16 result = le16_to_cpu(resp->result);
1207 adhoc_result = &resp->params.adhoc_result;
1209 bss_desc = priv->attempted_bss_desc;
1211 /* Join result code 0 --> SUCCESS */
1213 dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
1214 if (priv->media_connected)
1215 mwifiex_reset_connect_state(priv);
1217 memset(&priv->curr_bss_params.bss_descriptor,
1218 0x00, sizeof(struct mwifiex_bssdescriptor));
1224 /* Send a Media Connected event, according to the Spec */
1225 priv->media_connected = true;
1227 if (command == HostCmd_CMD_802_11_AD_HOC_START) {
1228 dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
1229 bss_desc->ssid.ssid);
1231 /* Update the created network descriptor with the new BSSID */
1232 memcpy(bss_desc->mac_address,
1233 adhoc_result->bssid, ETH_ALEN);
1235 priv->adhoc_state = ADHOC_STARTED;
1238 * Now the join cmd should be successful.
1239 * If BSSID has changed use SSID to compare instead of BSSID
1241 dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
1242 bss_desc->ssid.ssid);
1245 * Make a copy of current BSSID descriptor, only needed for
1246 * join since the current descriptor is already being used
1249 memcpy(&priv->curr_bss_params.bss_descriptor,
1250 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1252 priv->adhoc_state = ADHOC_JOINED;
1255 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
1256 priv->adhoc_channel);
1257 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
1258 priv->curr_bss_params.bss_descriptor.mac_address);
1260 if (!netif_carrier_ok(priv->netdev))
1261 netif_carrier_on(priv->netdev);
1262 if (netif_queue_stopped(priv->netdev))
1263 netif_wake_queue(priv->netdev);
1265 mwifiex_save_curr_bcn(priv);
1268 /* Need to indicate IOCTL complete */
1271 wait_queue->status = MWIFIEX_ERROR_ASSOC_FAIL;
1273 wait_queue->status = MWIFIEX_ERROR_NO_ERROR;
1281 * This function associates to a specific BSS discovered in a scan.
1283 * It clears any past association response stored for application
1284 * retrieval and calls the command preparation routine to send the
1285 * command to firmware.
1287 int mwifiex_associate(struct mwifiex_private *priv,
1288 void *wait_queue, struct mwifiex_bssdescriptor *bss_desc)
1291 u8 current_bssid[ETH_ALEN];
1293 /* Return error if the adapter or table entry is not marked as infra */
1294 if ((priv->bss_mode != MWIFIEX_BSS_MODE_INFRA) ||
1295 (bss_desc->bss_mode != MWIFIEX_BSS_MODE_INFRA))
1298 memcpy(¤t_bssid,
1299 &priv->curr_bss_params.bss_descriptor.mac_address,
1300 sizeof(current_bssid));
1302 /* Clear any past association response stored for application
1304 priv->assoc_rsp_size = 0;
1306 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_ASSOCIATE,
1307 HostCmd_ACT_GEN_SET, 0, wait_queue,
1314 * This function starts an ad-hoc network.
1316 * It calls the command preparation routine to send the command to firmware.
1319 mwifiex_adhoc_start(struct mwifiex_private *priv,
1320 void *wait_queue, struct mwifiex_802_11_ssid *adhoc_ssid)
1324 dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
1325 priv->adhoc_channel);
1326 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1327 priv->curr_bss_params.bss_descriptor.channel);
1328 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
1329 priv->curr_bss_params.band);
1331 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_AD_HOC_START,
1332 HostCmd_ACT_GEN_SET, 0, wait_queue,
1339 * This function joins an ad-hoc network found in a previous scan.
1341 * It calls the command preparation routine to send the command to firmware,
1342 * if already not connected to the requested SSID.
1344 int mwifiex_adhoc_join(struct mwifiex_private *priv,
1345 void *wait_queue, struct mwifiex_bssdescriptor *bss_desc)
1349 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
1350 priv->curr_bss_params.bss_descriptor.ssid.ssid);
1351 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
1352 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
1353 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
1354 bss_desc->ssid.ssid);
1355 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
1356 bss_desc->ssid.ssid_len);
1358 /* Check if the requested SSID is already joined */
1359 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1360 !mwifiex_ssid_cmp(&bss_desc->ssid,
1361 &priv->curr_bss_params.bss_descriptor.ssid) &&
1362 (priv->curr_bss_params.bss_descriptor.bss_mode ==
1363 MWIFIEX_BSS_MODE_IBSS)) {
1364 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
1365 " is the same as current; not attempting to re-join\n");
1369 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1370 priv->curr_bss_params.bss_descriptor.channel);
1371 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
1372 priv->curr_bss_params.band);
1374 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
1375 HostCmd_ACT_GEN_SET, 0, wait_queue,
1382 * This function deauthenticates/disconnects from infra network by sending
1383 * deauthentication request.
1385 static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv,
1386 struct mwifiex_wait_queue *wait,
1389 u8 mac_address[ETH_ALEN];
1391 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
1394 if (!memcmp(mac, zero_mac, sizeof(zero_mac)))
1395 memcpy((u8 *) &mac_address,
1396 (u8 *) &priv->curr_bss_params.bss_descriptor.
1397 mac_address, ETH_ALEN);
1399 memcpy((u8 *) &mac_address, (u8 *) mac, ETH_ALEN);
1401 memcpy((u8 *) &mac_address, (u8 *) &priv->curr_bss_params.
1402 bss_descriptor.mac_address, ETH_ALEN);
1405 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
1406 HostCmd_ACT_GEN_SET, 0, wait, &mac_address);
1415 * This function deauthenticates/disconnects from a BSS.
1417 * In case of infra made, it sends deauthentication request, and
1418 * in case of ad-hoc mode, a stop network request is sent to the firmware.
1420 int mwifiex_deauthenticate(struct mwifiex_private *priv,
1421 struct mwifiex_wait_queue *wait, u8 *mac)
1425 if (priv->media_connected) {
1426 if (priv->bss_mode == MWIFIEX_BSS_MODE_INFRA) {
1427 ret = mwifiex_deauthenticate_infra(priv, wait, mac);
1428 } else if (priv->bss_mode == MWIFIEX_BSS_MODE_IBSS) {
1429 ret = mwifiex_prepare_cmd(priv,
1430 HostCmd_CMD_802_11_AD_HOC_STOP,
1431 HostCmd_ACT_GEN_SET, 0, wait, NULL);
1442 * This function converts band to radio type used in channel TLV.
1445 mwifiex_band_to_radio_type(u8 band)
1452 case BAND_A | BAND_AN:
1453 ret_radio_type = HostCmd_SCAN_RADIO_TYPE_A;
1457 case BAND_B | BAND_G:
1459 ret_radio_type = HostCmd_SCAN_RADIO_TYPE_BG;
1463 return ret_radio_type;