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 /* TSF at the time when beacon/probe_response was received */
120 tsf_val = cpu_to_le64(bss_desc->network_tsf);
121 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
122 *buffer += sizeof(tsf_val);
124 memcpy(&tsf_val, bss_desc->time_stamp, sizeof(tsf_val));
126 dev_dbg(priv->adapter->dev, "info: %s: TSF offset calc: %016llx - "
127 "%016llx\n", __func__, tsf_val, bss_desc->network_tsf);
129 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
130 *buffer += sizeof(tsf_val);
132 return sizeof(tsf_tlv.header) + (2 * sizeof(tsf_val));
136 * This function finds out the common rates between rate1 and rate2.
138 * It will fill common rates in rate1 as output if found.
140 * NOTE: Setting the MSB of the basic rates needs to be taken
141 * care of, either before or after calling this function.
143 static int mwifiex_get_common_rates(struct mwifiex_private *priv, u8 *rate1,
144 u32 rate1_size, u8 *rate2, u32 rate2_size)
147 u8 *ptr = rate1, *tmp;
150 tmp = kmalloc(rate1_size, GFP_KERNEL);
152 dev_err(priv->adapter->dev, "failed to alloc tmp buf\n");
156 memcpy(tmp, rate1, rate1_size);
157 memset(rate1, 0, rate1_size);
159 for (i = 0; rate2[i] && i < rate2_size; i++) {
160 for (j = 0; tmp[j] && j < rate1_size; j++) {
161 /* Check common rate, excluding the bit for
163 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) {
170 dev_dbg(priv->adapter->dev, "info: Tx data rate set to %#x\n",
173 if (!priv->is_data_rate_auto) {
175 if ((*ptr & 0x7f) == priv->data_rate) {
181 dev_err(priv->adapter->dev, "previously set fixed data rate %#x"
182 " is not compatible with the network\n",
196 * This function creates the intersection of the rates supported by a
197 * target BSS and our adapter settings for use in an assoc/join command.
200 mwifiex_setup_rates_from_bssdesc(struct mwifiex_private *priv,
201 struct mwifiex_bssdescriptor *bss_desc,
202 u8 *out_rates, u32 *out_rates_size)
204 u8 card_rates[MWIFIEX_SUPPORTED_RATES];
207 /* Copy AP supported rates */
208 memcpy(out_rates, bss_desc->supported_rates, MWIFIEX_SUPPORTED_RATES);
209 /* Get the STA supported rates */
210 card_rates_size = mwifiex_get_active_data_rates(priv, card_rates);
211 /* Get the common rates between AP and STA supported rates */
212 if (mwifiex_get_common_rates(priv, out_rates, MWIFIEX_SUPPORTED_RATES,
213 card_rates, card_rates_size)) {
215 dev_err(priv->adapter->dev, "%s: cannot get common rates\n",
221 min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES);
227 * This function updates the scan entry TSF timestamps to reflect
231 mwifiex_update_tsf_timestamps(struct mwifiex_private *priv,
232 struct mwifiex_bssdescriptor *new_bss_desc)
234 struct mwifiex_adapter *adapter = priv->adapter;
236 long long new_tsf_base;
237 signed long long tsf_delta;
239 memcpy(&new_tsf_base, new_bss_desc->time_stamp, sizeof(new_tsf_base));
241 tsf_delta = new_tsf_base - new_bss_desc->network_tsf;
243 dev_dbg(adapter->dev, "info: TSF: update TSF timestamps, "
244 "0x%016llx -> 0x%016llx\n",
245 new_bss_desc->network_tsf, new_tsf_base);
247 for (table_idx = 0; table_idx < adapter->num_in_scan_table;
249 adapter->scan_table[table_idx].network_tsf += tsf_delta;
253 * This function appends a WAPI IE.
255 * This function is called from the network join command preparation routine.
257 * If the IE buffer has been setup by the application, this routine appends
258 * the buffer as a WAPI TLV type to the request.
261 mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer)
264 struct mwifiex_ie_types_header ie_header;
273 * If there is a wapi ie buffer setup, append it to the return
274 * parameter buffer pointer.
276 if (priv->wapi_ie_len) {
277 dev_dbg(priv->adapter->dev, "cmd: append wapi ie %d to %p\n",
278 priv->wapi_ie_len, *buffer);
280 /* Wrap the generic IE buffer with a pass through TLV type */
281 ie_header.type = cpu_to_le16(TLV_TYPE_WAPI_IE);
282 ie_header.len = cpu_to_le16(priv->wapi_ie_len);
283 memcpy(*buffer, &ie_header, sizeof(ie_header));
285 /* Increment the return size and the return buffer pointer
287 *buffer += sizeof(ie_header);
288 retLen += sizeof(ie_header);
290 /* Copy the wapi IE buffer to the output buffer, advance
292 memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len);
294 /* Increment the return size and the return buffer pointer
296 *buffer += priv->wapi_ie_len;
297 retLen += priv->wapi_ie_len;
300 /* return the length appended to the buffer */
305 * This function appends rsn ie tlv for wpa/wpa2 security modes.
306 * It is called from the network join command preparation routine.
308 static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private *priv,
311 struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv;
314 if (!buffer || !(*buffer))
317 rsn_ie_tlv = (struct mwifiex_ie_types_rsn_param_set *) (*buffer);
318 rsn_ie_tlv->header.type = cpu_to_le16((u16) priv->wpa_ie[0]);
319 rsn_ie_tlv->header.type = cpu_to_le16(
320 le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF);
321 rsn_ie_tlv->header.len = cpu_to_le16((u16) priv->wpa_ie[1]);
322 rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len)
324 if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2))
325 memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2],
326 le16_to_cpu(rsn_ie_tlv->header.len));
330 rsn_ie_len = sizeof(rsn_ie_tlv->header) +
331 le16_to_cpu(rsn_ie_tlv->header.len);
332 *buffer += rsn_ie_len;
338 * This function prepares command for association.
340 * This sets the following parameters -
344 * - Capability information
346 * ...and the following TLVs, as required -
351 * - Authentication TLV
355 * - Vendor specific TLV
361 * Preparation also includes -
362 * - Setting command ID and proper size
363 * - Ensuring correct endian-ness
365 int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
366 struct host_cmd_ds_command *cmd,
369 struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate;
370 struct mwifiex_bssdescriptor *bss_desc;
371 struct mwifiex_ie_types_ssid_param_set *ssid_tlv;
372 struct mwifiex_ie_types_phy_param_set *phy_tlv;
373 struct mwifiex_ie_types_ss_param_set *ss_tlv;
374 struct mwifiex_ie_types_rates_param_set *rates_tlv;
375 struct mwifiex_ie_types_auth_type *auth_tlv;
376 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
377 u8 rates[MWIFIEX_SUPPORTED_RATES];
383 bss_desc = (struct mwifiex_bssdescriptor *) data_buf;
386 mwifiex_cfg_tx_buf(priv, bss_desc);
388 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
390 /* Save so we know which BSS Desc to use in the response handler */
391 priv->attempted_bss_desc = bss_desc;
393 memcpy(assoc->peer_sta_addr,
394 bss_desc->mac_address, sizeof(assoc->peer_sta_addr));
395 pos += sizeof(assoc->peer_sta_addr);
397 /* Set the listen interval */
398 assoc->listen_interval = cpu_to_le16(priv->listen_interval);
399 /* Set the beacon period */
400 assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period);
402 pos += sizeof(assoc->cap_info_bitmap);
403 pos += sizeof(assoc->listen_interval);
404 pos += sizeof(assoc->beacon_period);
405 pos += sizeof(assoc->dtim_period);
407 ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos;
408 ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID);
409 ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len);
410 memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid,
411 le16_to_cpu(ssid_tlv->header.len));
412 pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len);
414 phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos;
415 phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS);
416 phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set));
417 memcpy(&phy_tlv->fh_ds.ds_param_set,
418 &bss_desc->phy_param_set.ds_param_set.current_chan,
419 sizeof(phy_tlv->fh_ds.ds_param_set));
420 pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len);
422 ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos;
423 ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS);
424 ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set));
425 pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len);
427 /* Get the common rates supported between the driver and the BSS Desc */
428 if (mwifiex_setup_rates_from_bssdesc
429 (priv, bss_desc, rates, &rates_size))
432 /* Save the data rates into Current BSS state structure */
433 priv->curr_bss_params.num_of_rates = rates_size;
434 memcpy(&priv->curr_bss_params.data_rates, rates, rates_size);
436 /* Setup the Rates TLV in the association command */
437 rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos;
438 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
439 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
440 memcpy(rates_tlv->rates, rates, rates_size);
441 pos += sizeof(rates_tlv->header) + rates_size;
442 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: rates size = %d\n",
445 /* Add the Authentication type to be used for Auth frames */
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(
451 (u16) priv->sec_info.authentication_mode);
453 auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM);
455 pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len);
457 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)
458 && !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
459 && (!bss_desc->disable_11n)
460 && (priv->adapter->config_bands & BAND_GN
461 || priv->adapter->config_bands & BAND_AN)
462 && (bss_desc->bcn_ht_cap)
465 /* Append a channel TLV for the channel the attempted AP was
467 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
468 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
469 chan_tlv->header.len =
470 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
472 memset(chan_tlv->chan_scan_param, 0x00,
473 sizeof(struct mwifiex_chan_scan_param_set));
474 chan_tlv->chan_scan_param[0].chan_number =
475 (bss_desc->phy_param_set.ds_param_set.current_chan);
476 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
477 chan_tlv->chan_scan_param[0].chan_number);
479 chan_tlv->chan_scan_param[0].radio_type =
480 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
482 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
483 chan_tlv->chan_scan_param[0].radio_type);
484 pos += sizeof(chan_tlv->header) +
485 sizeof(struct mwifiex_chan_scan_param_set);
488 if (!priv->wps.session_enable) {
489 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
490 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
492 if (rsn_ie_len == -1)
496 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
497 && (!bss_desc->disable_11n)
498 && (priv->adapter->config_bands & BAND_GN
499 || priv->adapter->config_bands & BAND_AN))
500 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
502 /* Append vendor specific IE TLV */
503 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
505 mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
506 bss_desc->bcn_ht_cap);
507 if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
508 mwifiex_cmd_append_wapi_ie(priv, &pos);
511 mwifiex_cmd_append_generic_ie(priv, &pos);
513 mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
515 cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
517 /* Set the Capability info at last */
518 tmp_cap = bss_desc->cap_info_bitmap;
520 if (priv->adapter->config_bands == BAND_B)
521 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
523 tmp_cap &= CAPINFO_MASK;
524 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
525 tmp_cap, CAPINFO_MASK);
526 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
532 * Association firmware command response handler
534 * The response buffer for the association command has the following
537 * For cases where an association response was not received (indicated
538 * by the CapInfo and AId field):
540 * .------------------------------------------------------------.
541 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
542 * .------------------------------------------------------------.
543 * | cap_info/Error Return(t_u16): |
544 * | 0xFFFF(-1): Internal error |
545 * | 0xFFFE(-2): Authentication unhandled message |
546 * | 0xFFFD(-3): Authentication refused |
547 * | 0xFFFC(-4): Timeout waiting for AP response |
548 * .------------------------------------------------------------.
549 * | status_code(t_u16): |
550 * | If cap_info is -1: |
551 * | An internal firmware failure prevented the |
552 * | command from being processed. The status_code |
553 * | will be set to 1. |
555 * | If cap_info is -2: |
556 * | An authentication frame was received but was |
557 * | not handled by the firmware. IEEE Status |
558 * | code for the failure is returned. |
560 * | If cap_info is -3: |
561 * | An authentication frame was received and the |
562 * | status_code is the IEEE Status reported in the |
565 * | If cap_info is -4: |
566 * | (1) Association response timeout |
567 * | (2) Authentication response timeout |
568 * .------------------------------------------------------------.
569 * | a_id(t_u16): 0xFFFF |
570 * .------------------------------------------------------------.
573 * For cases where an association response was received, the IEEE
574 * standard association response frame is returned:
576 * .------------------------------------------------------------.
577 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
578 * .------------------------------------------------------------.
579 * | cap_info(t_u16): IEEE Capability |
580 * .------------------------------------------------------------.
581 * | status_code(t_u16): IEEE Status Code |
582 * .------------------------------------------------------------.
583 * | a_id(t_u16): IEEE Association ID |
584 * .------------------------------------------------------------.
585 * | IEEE IEs(variable): Any received IEs comprising the |
586 * | remaining portion of a received |
587 * | association response frame. |
588 * .------------------------------------------------------------.
590 * For simplistic handling, the status_code field can be used to determine
591 * an association success (0) or failure (non-zero).
593 int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
594 struct host_cmd_ds_command *resp)
596 struct mwifiex_adapter *adapter = priv->adapter;
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 */
721 if (adapter->curr_cmd->wait_q_enabled) {
723 adapter->cmd_wait_q.status = -1;
725 adapter->cmd_wait_q.status = 0;
732 * This function prepares command for ad-hoc start.
734 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
735 * parameters, probe delay, and capability information. Firmware
736 * will fill up beacon period, basic rates and operational rates.
738 * In addition, the following TLVs are added -
740 * - Vendor specific IE
742 * - HT Capabilities IE
743 * - HT Information IE
745 * Preparation also includes -
746 * - Setting command ID and proper size
747 * - Ensuring correct endian-ness
750 mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
751 struct host_cmd_ds_command *cmd, void *data_buf)
754 struct mwifiex_adapter *adapter = priv->adapter;
755 struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
756 &cmd->params.adhoc_start;
757 struct mwifiex_bssdescriptor *bss_desc;
758 u32 cmd_append_size = 0;
761 uint16_t ht_cap_info;
762 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
764 struct mwifiex_ie_types_htcap *ht_cap;
765 struct mwifiex_ie_types_htinfo *ht_info;
766 u8 *pos = (u8 *) adhoc_start +
767 sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
772 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
774 bss_desc = &priv->curr_bss_params.bss_descriptor;
775 priv->attempted_bss_desc = bss_desc;
778 * Fill in the parameters for 2 data structures:
779 * 1. struct host_cmd_ds_802_11_ad_hoc_start command
781 * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
782 * probe delay, and Cap info.
783 * Firmware will fill up beacon period, Basic rates
784 * and operational rates.
787 memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
789 memcpy(adhoc_start->ssid,
790 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
791 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
793 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
796 memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
797 memcpy(bss_desc->ssid.ssid,
798 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
799 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
801 bss_desc->ssid.ssid_len =
802 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len;
804 /* Set the BSS mode */
805 adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
806 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
807 adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
808 bss_desc->beacon_period = priv->beacon_period;
810 /* Set Physical param set */
811 /* Parameter IE Id */
812 #define DS_PARA_IE_ID 3
813 /* Parameter IE length */
814 #define DS_PARA_IE_LEN 1
816 adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
817 adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
819 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
820 (priv, adapter->adhoc_start_band, (u16)
821 priv->adhoc_channel)) {
822 struct mwifiex_chan_freq_power *cfp;
823 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
824 adapter->adhoc_start_band, FIRST_VALID_CHANNEL);
826 priv->adhoc_channel = (u8) cfp->channel;
829 if (!priv->adhoc_channel) {
830 dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
834 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
835 priv->adhoc_channel);
837 priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
838 priv->curr_bss_params.band = adapter->adhoc_start_band;
840 bss_desc->channel = priv->adhoc_channel;
841 adhoc_start->phy_param_set.ds_param_set.current_chan =
844 memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
845 sizeof(union ieee_types_phy_param_set));
847 /* Set IBSS param set */
848 /* IBSS parameter IE Id */
849 #define IBSS_PARA_IE_ID 6
850 /* IBSS parameter IE length */
851 #define IBSS_PARA_IE_LEN 2
853 adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
854 adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
855 adhoc_start->ss_param_set.ibss_param_set.atim_window
856 = cpu_to_le16(priv->atim_window);
857 memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
858 sizeof(union ieee_types_ss_param_set));
860 /* Set Capability info */
861 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
862 tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap);
863 tmp_cap &= ~WLAN_CAPABILITY_ESS;
864 tmp_cap |= WLAN_CAPABILITY_IBSS;
866 /* Set up privacy in bss_desc */
867 if (priv->sec_info.encryption_mode) {
868 /* Ad-Hoc capability privacy on */
869 dev_dbg(adapter->dev,
870 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
871 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
872 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
874 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
875 " setting privacy to ACCEPT ALL\n");
876 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
879 memset(adhoc_start->DataRate, 0, sizeof(adhoc_start->DataRate));
880 mwifiex_get_active_data_rates(priv, adhoc_start->DataRate);
881 if ((adapter->adhoc_start_band & BAND_G) &&
882 (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
883 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
884 HostCmd_ACT_GEN_SET, 0,
885 &priv->curr_pkt_filter)) {
886 dev_err(adapter->dev,
887 "ADHOC_S_CMD: G Protection config failed\n");
891 /* Find the last non zero */
892 for (i = 0; i < sizeof(adhoc_start->DataRate) &&
893 adhoc_start->DataRate[i];
897 priv->curr_bss_params.num_of_rates = i;
899 /* Copy the ad-hoc creating rates into Current BSS rate structure */
900 memcpy(&priv->curr_bss_params.data_rates,
901 &adhoc_start->DataRate, priv->curr_bss_params.num_of_rates);
903 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n",
904 adhoc_start->DataRate[0], adhoc_start->DataRate[1],
905 adhoc_start->DataRate[2], adhoc_start->DataRate[3]);
907 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
909 if (IS_SUPPORT_MULTI_BANDS(adapter)) {
910 /* Append a channel TLV */
911 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
912 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
913 chan_tlv->header.len =
914 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
916 memset(chan_tlv->chan_scan_param, 0x00,
917 sizeof(struct mwifiex_chan_scan_param_set));
918 chan_tlv->chan_scan_param[0].chan_number =
919 (u8) priv->curr_bss_params.bss_descriptor.channel;
921 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
922 chan_tlv->chan_scan_param[0].chan_number);
924 chan_tlv->chan_scan_param[0].radio_type
925 = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
926 if (adapter->adhoc_start_band & BAND_GN
927 || adapter->adhoc_start_band & BAND_AN) {
928 if (adapter->chan_offset == SEC_CHANNEL_ABOVE)
929 chan_tlv->chan_scan_param[0].radio_type |=
930 SECOND_CHANNEL_ABOVE;
931 else if (adapter->chan_offset == SEC_CHANNEL_BELOW)
932 chan_tlv->chan_scan_param[0].radio_type |=
933 SECOND_CHANNEL_BELOW;
935 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
936 chan_tlv->chan_scan_param[0].radio_type);
937 pos += sizeof(chan_tlv->header) +
938 sizeof(struct mwifiex_chan_scan_param_set);
940 sizeof(chan_tlv->header) +
941 sizeof(struct mwifiex_chan_scan_param_set);
944 /* Append vendor specific IE TLV */
945 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
946 MWIFIEX_VSIE_MASK_ADHOC, &pos);
948 if (priv->sec_info.wpa_enabled) {
949 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
950 if (rsn_ie_len == -1)
952 cmd_append_size += rsn_ie_len;
955 if (adapter->adhoc_11n_enabled) {
957 ht_cap = (struct mwifiex_ie_types_htcap *) pos;
959 sizeof(struct mwifiex_ie_types_htcap));
960 ht_cap->header.type =
961 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
963 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
964 ht_cap_info = le16_to_cpu(ht_cap->ht_cap.cap_info);
966 ht_cap_info |= IEEE80211_HT_CAP_SGI_20;
967 if (adapter->chan_offset) {
968 ht_cap_info |= IEEE80211_HT_CAP_SGI_40;
969 ht_cap_info |= IEEE80211_HT_CAP_DSSSCCK40;
970 ht_cap_info |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
971 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
974 ht_cap->ht_cap.ampdu_params_info
975 = IEEE80211_HT_MAX_AMPDU_64K;
976 ht_cap->ht_cap.mcs.rx_mask[0] = 0xff;
977 pos += sizeof(struct mwifiex_ie_types_htcap);
979 sizeof(struct mwifiex_ie_types_htcap);
982 ht_info = (struct mwifiex_ie_types_htinfo *) pos;
984 sizeof(struct mwifiex_ie_types_htinfo));
985 ht_info->header.type =
986 cpu_to_le16(WLAN_EID_HT_INFORMATION);
987 ht_info->header.len =
988 cpu_to_le16(sizeof(struct ieee80211_ht_info));
989 ht_info->ht_info.control_chan =
990 (u8) priv->curr_bss_params.bss_descriptor.
992 if (adapter->chan_offset) {
993 ht_info->ht_info.ht_param =
994 adapter->chan_offset;
995 ht_info->ht_info.ht_param |=
996 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
998 ht_info->ht_info.operation_mode =
999 cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1000 ht_info->ht_info.basic_set[0] = 0xff;
1001 pos += sizeof(struct mwifiex_ie_types_htinfo);
1003 sizeof(struct mwifiex_ie_types_htinfo);
1007 cmd->size = cpu_to_le16((u16)
1008 (sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
1009 + S_DS_GEN + cmd_append_size));
1011 if (adapter->adhoc_start_band == BAND_B)
1012 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
1014 tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1016 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1022 * This function prepares command for ad-hoc join.
1024 * Most of the parameters are set up by copying from the target BSS descriptor
1025 * from the scan response.
1027 * In addition, the following TLVs are added -
1029 * - Vendor specific IE
1033 * Preparation also includes -
1034 * - Setting command ID and proper size
1035 * - Ensuring correct endian-ness
1038 mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1039 struct host_cmd_ds_command *cmd, void *data_buf)
1042 struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
1043 &cmd->params.adhoc_join;
1044 struct mwifiex_bssdescriptor *bss_desc =
1045 (struct mwifiex_bssdescriptor *) data_buf;
1046 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
1047 u32 cmd_append_size = 0;
1049 u32 i, rates_size = 0;
1050 u16 curr_pkt_filter;
1053 sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
1055 /* Use G protection */
1056 #define USE_G_PROTECTION 0x02
1057 if (bss_desc->erp_flags & USE_G_PROTECTION) {
1060 curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
1062 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
1063 HostCmd_ACT_GEN_SET, 0,
1064 &curr_pkt_filter)) {
1065 dev_err(priv->adapter->dev,
1066 "ADHOC_J_CMD: G Protection config failed\n");
1071 priv->attempted_bss_desc = bss_desc;
1073 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1075 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1077 adhoc_join->bss_descriptor.beacon_period
1078 = cpu_to_le16(bss_desc->beacon_period);
1080 memcpy(&adhoc_join->bss_descriptor.bssid,
1081 &bss_desc->mac_address, ETH_ALEN);
1083 memcpy(&adhoc_join->bss_descriptor.ssid,
1084 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1086 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1087 &bss_desc->phy_param_set,
1088 sizeof(union ieee_types_phy_param_set));
1090 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1091 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1093 tmp_cap = bss_desc->cap_info_bitmap;
1095 tmp_cap &= CAPINFO_MASK;
1097 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: tmp_cap=%4X"
1098 " CAPINFO_MASK=%4lX\n", tmp_cap, CAPINFO_MASK);
1100 /* Information on BSSID descriptor passed to FW */
1101 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID = %pM, SSID = %s\n",
1102 adhoc_join->bss_descriptor.bssid,
1103 adhoc_join->bss_descriptor.ssid);
1105 for (i = 0; bss_desc->supported_rates[i] &&
1106 i < MWIFIEX_SUPPORTED_RATES;
1111 /* Copy Data Rates from the Rates recorded in scan response */
1112 memset(adhoc_join->bss_descriptor.data_rates, 0,
1113 sizeof(adhoc_join->bss_descriptor.data_rates));
1114 memcpy(adhoc_join->bss_descriptor.data_rates,
1115 bss_desc->supported_rates, rates_size);
1117 /* Copy the adhoc join rates into Current BSS state structure */
1118 priv->curr_bss_params.num_of_rates = rates_size;
1119 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1122 /* Copy the channel information */
1123 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1124 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1126 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED
1127 || priv->sec_info.wpa_enabled)
1128 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1130 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1131 /* Append a channel TLV */
1132 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1133 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1134 chan_tlv->header.len =
1135 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1137 memset(chan_tlv->chan_scan_param, 0x00,
1138 sizeof(struct mwifiex_chan_scan_param_set));
1139 chan_tlv->chan_scan_param[0].chan_number =
1140 (bss_desc->phy_param_set.ds_param_set.current_chan);
1141 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan = %d\n",
1142 chan_tlv->chan_scan_param[0].chan_number);
1144 chan_tlv->chan_scan_param[0].radio_type =
1145 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1147 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band = %d\n",
1148 chan_tlv->chan_scan_param[0].radio_type);
1149 pos += sizeof(chan_tlv->header) +
1150 sizeof(struct mwifiex_chan_scan_param_set);
1151 cmd_append_size += sizeof(chan_tlv->header) +
1152 sizeof(struct mwifiex_chan_scan_param_set);
1155 if (priv->sec_info.wpa_enabled)
1156 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1157 if (rsn_ie_len == -1)
1159 cmd_append_size += rsn_ie_len;
1161 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1162 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1165 /* Append vendor specific IE TLV */
1166 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1167 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1169 cmd->size = cpu_to_le16((u16)
1170 (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1171 + S_DS_GEN + cmd_append_size));
1173 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1179 * This function handles the command response of ad-hoc start and
1182 * The function generates a device-connected event to notify
1183 * the applications, in case of successful ad-hoc start/join, and
1184 * saves the beacon buffer.
1186 int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
1187 struct host_cmd_ds_command *resp)
1190 struct mwifiex_adapter *adapter = priv->adapter;
1191 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1192 struct mwifiex_bssdescriptor *bss_desc;
1194 adhoc_result = &resp->params.adhoc_result;
1196 bss_desc = priv->attempted_bss_desc;
1198 /* Join result code 0 --> SUCCESS */
1199 if (le16_to_cpu(resp->result)) {
1200 dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
1201 if (priv->media_connected)
1202 mwifiex_reset_connect_state(priv);
1204 memset(&priv->curr_bss_params.bss_descriptor,
1205 0x00, sizeof(struct mwifiex_bssdescriptor));
1211 /* Send a Media Connected event, according to the Spec */
1212 priv->media_connected = true;
1214 if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) {
1215 dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
1216 bss_desc->ssid.ssid);
1218 /* Update the created network descriptor with the new BSSID */
1219 memcpy(bss_desc->mac_address,
1220 adhoc_result->bssid, ETH_ALEN);
1222 priv->adhoc_state = ADHOC_STARTED;
1225 * Now the join cmd should be successful.
1226 * If BSSID has changed use SSID to compare instead of BSSID
1228 dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
1229 bss_desc->ssid.ssid);
1232 * Make a copy of current BSSID descriptor, only needed for
1233 * join since the current descriptor is already being used
1236 memcpy(&priv->curr_bss_params.bss_descriptor,
1237 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1239 priv->adhoc_state = ADHOC_JOINED;
1242 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
1243 priv->adhoc_channel);
1244 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
1245 priv->curr_bss_params.bss_descriptor.mac_address);
1247 if (!netif_carrier_ok(priv->netdev))
1248 netif_carrier_on(priv->netdev);
1249 if (netif_queue_stopped(priv->netdev))
1250 netif_wake_queue(priv->netdev);
1252 mwifiex_save_curr_bcn(priv);
1255 /* Need to indicate IOCTL complete */
1256 if (adapter->curr_cmd->wait_q_enabled) {
1258 adapter->cmd_wait_q.status = -1;
1260 adapter->cmd_wait_q.status = 0;
1268 * This function associates to a specific BSS discovered in a scan.
1270 * It clears any past association response stored for application
1271 * retrieval and calls the command preparation routine to send the
1272 * command to firmware.
1274 int mwifiex_associate(struct mwifiex_private *priv,
1275 struct mwifiex_bssdescriptor *bss_desc)
1277 u8 current_bssid[ETH_ALEN];
1279 /* Return error if the adapter or table entry is not marked as infra */
1280 if ((priv->bss_mode != NL80211_IFTYPE_STATION) ||
1281 (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
1284 memcpy(¤t_bssid,
1285 &priv->curr_bss_params.bss_descriptor.mac_address,
1286 sizeof(current_bssid));
1288 /* Clear any past association response stored for application
1290 priv->assoc_rsp_size = 0;
1292 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_ASSOCIATE,
1293 HostCmd_ACT_GEN_SET, 0, bss_desc);
1297 * This function starts an ad-hoc network.
1299 * It calls the command preparation routine to send the command to firmware.
1302 mwifiex_adhoc_start(struct mwifiex_private *priv,
1303 struct mwifiex_802_11_ssid *adhoc_ssid)
1305 dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
1306 priv->adhoc_channel);
1307 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1308 priv->curr_bss_params.bss_descriptor.channel);
1309 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
1310 priv->curr_bss_params.band);
1312 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_START,
1313 HostCmd_ACT_GEN_SET, 0, adhoc_ssid);
1317 * This function joins an ad-hoc network found in a previous scan.
1319 * It calls the command preparation routine to send the command to firmware,
1320 * if already not connected to the requested SSID.
1322 int mwifiex_adhoc_join(struct mwifiex_private *priv,
1323 struct mwifiex_bssdescriptor *bss_desc)
1325 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
1326 priv->curr_bss_params.bss_descriptor.ssid.ssid);
1327 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
1328 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
1329 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
1330 bss_desc->ssid.ssid);
1331 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
1332 bss_desc->ssid.ssid_len);
1334 /* Check if the requested SSID is already joined */
1335 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1336 !mwifiex_ssid_cmp(&bss_desc->ssid,
1337 &priv->curr_bss_params.bss_descriptor.ssid) &&
1338 (priv->curr_bss_params.bss_descriptor.bss_mode ==
1339 NL80211_IFTYPE_ADHOC)) {
1340 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
1341 " is the same as current; not attempting to re-join\n");
1345 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1346 priv->curr_bss_params.bss_descriptor.channel);
1347 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
1348 priv->curr_bss_params.band);
1350 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
1351 HostCmd_ACT_GEN_SET, 0, bss_desc);
1355 * This function deauthenticates/disconnects from infra network by sending
1356 * deauthentication request.
1358 static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
1360 u8 mac_address[ETH_ALEN];
1362 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
1365 if (!memcmp(mac, zero_mac, sizeof(zero_mac)))
1366 memcpy((u8 *) &mac_address,
1367 (u8 *) &priv->curr_bss_params.bss_descriptor.
1368 mac_address, ETH_ALEN);
1370 memcpy((u8 *) &mac_address, (u8 *) mac, ETH_ALEN);
1372 memcpy((u8 *) &mac_address, (u8 *) &priv->curr_bss_params.
1373 bss_descriptor.mac_address, ETH_ALEN);
1376 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
1377 HostCmd_ACT_GEN_SET, 0, &mac_address);
1383 * This function deauthenticates/disconnects from a BSS.
1385 * In case of infra made, it sends deauthentication request, and
1386 * in case of ad-hoc mode, a stop network request is sent to the firmware.
1388 int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
1392 if (priv->media_connected) {
1393 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1394 ret = mwifiex_deauthenticate_infra(priv, mac);
1395 } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1396 ret = mwifiex_send_cmd_sync(priv,
1397 HostCmd_CMD_802_11_AD_HOC_STOP,
1398 HostCmd_ACT_GEN_SET, 0, NULL);
1404 EXPORT_SYMBOL_GPL(mwifiex_deauthenticate);
1407 * This function converts band to radio type used in channel TLV.
1410 mwifiex_band_to_radio_type(u8 band)
1415 case BAND_A | BAND_AN:
1416 return HostCmd_SCAN_RADIO_TYPE_A;
1419 case BAND_B | BAND_G:
1421 return HostCmd_SCAN_RADIO_TYPE_BG;