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
,
56 "info: %s: append generic ie len %d to %p\n",
57 __func__
, priv
->gen_ie_buf_len
, *buffer
);
59 /* Wrap the generic IE buffer with a pass through TLV type */
60 ie_header
.type
= cpu_to_le16(TLV_TYPE_PASSTHROUGH
);
61 ie_header
.len
= cpu_to_le16(priv
->gen_ie_buf_len
);
62 memcpy(*buffer
, &ie_header
, sizeof(ie_header
));
64 /* Increment the return size and the return buffer pointer
66 *buffer
+= sizeof(ie_header
);
67 ret_len
+= sizeof(ie_header
);
69 /* Copy the generic IE buffer to the output buffer, advance
71 memcpy(*buffer
, priv
->gen_ie_buf
, priv
->gen_ie_buf_len
);
73 /* Increment the return size and the return buffer pointer
75 *buffer
+= priv
->gen_ie_buf_len
;
76 ret_len
+= priv
->gen_ie_buf_len
;
78 /* Reset the generic IE buffer */
79 priv
->gen_ie_buf_len
= 0;
82 /* return the length appended to the buffer */
87 * Append TSF tracking info from the scan table for the target AP.
89 * This function is called from the network join command preparation routine.
91 * The TSF table TSF sent to the firmware contains two TSF values:
92 * - The TSF of the target AP from its previous beacon/probe response
93 * - The TSF timestamp of our local MAC at the time we observed the
94 * beacon/probe response.
96 * The firmware uses the timestamp values to set an initial TSF value
97 * in the MAC for the new association after a reassociation attempt.
100 mwifiex_cmd_append_tsf_tlv(struct mwifiex_private
*priv
, u8
**buffer
,
101 struct mwifiex_bssdescriptor
*bss_desc
)
103 struct mwifiex_ie_types_tsf_timestamp tsf_tlv
;
112 memset(&tsf_tlv
, 0x00, sizeof(struct mwifiex_ie_types_tsf_timestamp
));
114 tsf_tlv
.header
.type
= cpu_to_le16(TLV_TYPE_TSFTIMESTAMP
);
115 tsf_tlv
.header
.len
= cpu_to_le16(2 * sizeof(tsf_val
));
117 memcpy(*buffer
, &tsf_tlv
, sizeof(tsf_tlv
.header
));
118 *buffer
+= sizeof(tsf_tlv
.header
);
120 /* TSF at the time when beacon/probe_response was received */
121 tsf_val
= cpu_to_le64(bss_desc
->fw_tsf
);
122 memcpy(*buffer
, &tsf_val
, sizeof(tsf_val
));
123 *buffer
+= sizeof(tsf_val
);
125 tsf_val
= cpu_to_le64(bss_desc
->timestamp
);
127 dev_dbg(priv
->adapter
->dev
,
128 "info: %s: TSF offset calc: %016llx - %016llx\n",
129 __func__
, bss_desc
->timestamp
, bss_desc
->fw_tsf
);
131 memcpy(*buffer
, &tsf_val
, sizeof(tsf_val
));
132 *buffer
+= sizeof(tsf_val
);
134 return sizeof(tsf_tlv
.header
) + (2 * sizeof(tsf_val
));
138 * This function finds out the common rates between rate1 and rate2.
140 * It will fill common rates in rate1 as output if found.
142 * NOTE: Setting the MSB of the basic rates needs to be taken
143 * care of, either before or after calling this function.
145 static int mwifiex_get_common_rates(struct mwifiex_private
*priv
, u8
*rate1
,
146 u32 rate1_size
, u8
*rate2
, u32 rate2_size
)
149 u8
*ptr
= rate1
, *tmp
;
152 tmp
= kmemdup(rate1
, rate1_size
, GFP_KERNEL
);
154 dev_err(priv
->adapter
->dev
, "failed to alloc tmp buf\n");
158 memset(rate1
, 0, rate1_size
);
160 for (i
= 0; rate2
[i
] && i
< rate2_size
; i
++) {
161 for (j
= 0; tmp
[j
] && j
< rate1_size
; j
++) {
162 /* Check common rate, excluding the bit for
164 if ((rate2
[i
] & 0x7F) == (tmp
[j
] & 0x7F)) {
171 dev_dbg(priv
->adapter
->dev
, "info: Tx data rate set to %#x\n",
174 if (!priv
->is_data_rate_auto
) {
176 if ((*ptr
& 0x7f) == priv
->data_rate
) {
182 dev_err(priv
->adapter
->dev
, "previously set fixed data rate %#x"
183 " is not compatible with the network\n",
197 * This function creates the intersection of the rates supported by a
198 * target BSS and our adapter settings for use in an assoc/join command.
201 mwifiex_setup_rates_from_bssdesc(struct mwifiex_private
*priv
,
202 struct mwifiex_bssdescriptor
*bss_desc
,
203 u8
*out_rates
, u32
*out_rates_size
)
205 u8 card_rates
[MWIFIEX_SUPPORTED_RATES
];
208 /* Copy AP supported rates */
209 memcpy(out_rates
, bss_desc
->supported_rates
, MWIFIEX_SUPPORTED_RATES
);
210 /* Get the STA supported rates */
211 card_rates_size
= mwifiex_get_active_data_rates(priv
, card_rates
);
212 /* Get the common rates between AP and STA supported rates */
213 if (mwifiex_get_common_rates(priv
, out_rates
, MWIFIEX_SUPPORTED_RATES
,
214 card_rates
, card_rates_size
)) {
216 dev_err(priv
->adapter
->dev
, "%s: cannot get common rates\n",
222 min_t(size_t, strlen(out_rates
), MWIFIEX_SUPPORTED_RATES
);
228 * This function appends a WPS IE. It is called from the network join command
229 * preparation routine.
231 * If the IE buffer has been setup by the application, this routine appends
232 * the buffer as a WPS TLV type to the request.
235 mwifiex_cmd_append_wps_ie(struct mwifiex_private
*priv
, u8
**buffer
)
238 struct mwifiex_ie_types_header ie_header
;
240 if (!buffer
|| !*buffer
)
244 * If there is a wps ie buffer setup, append it to the return
245 * parameter buffer pointer.
247 if (priv
->wps_ie_len
) {
248 dev_dbg(priv
->adapter
->dev
, "cmd: append wps ie %d to %p\n",
249 priv
->wps_ie_len
, *buffer
);
251 /* Wrap the generic IE buffer with a pass through TLV type */
252 ie_header
.type
= cpu_to_le16(TLV_TYPE_MGMT_IE
);
253 ie_header
.len
= cpu_to_le16(priv
->wps_ie_len
);
254 memcpy(*buffer
, &ie_header
, sizeof(ie_header
));
255 *buffer
+= sizeof(ie_header
);
256 retLen
+= sizeof(ie_header
);
258 memcpy(*buffer
, priv
->wps_ie
, priv
->wps_ie_len
);
259 *buffer
+= priv
->wps_ie_len
;
260 retLen
+= priv
->wps_ie_len
;
265 priv
->wps_ie_len
= 0;
270 * This function appends a WAPI IE.
272 * This function is called from the network join command preparation routine.
274 * If the IE buffer has been setup by the application, this routine appends
275 * the buffer as a WAPI TLV type to the request.
278 mwifiex_cmd_append_wapi_ie(struct mwifiex_private
*priv
, u8
**buffer
)
281 struct mwifiex_ie_types_header ie_header
;
290 * If there is a wapi ie buffer setup, append it to the return
291 * parameter buffer pointer.
293 if (priv
->wapi_ie_len
) {
294 dev_dbg(priv
->adapter
->dev
, "cmd: append wapi ie %d to %p\n",
295 priv
->wapi_ie_len
, *buffer
);
297 /* Wrap the generic IE buffer with a pass through TLV type */
298 ie_header
.type
= cpu_to_le16(TLV_TYPE_WAPI_IE
);
299 ie_header
.len
= cpu_to_le16(priv
->wapi_ie_len
);
300 memcpy(*buffer
, &ie_header
, sizeof(ie_header
));
302 /* Increment the return size and the return buffer pointer
304 *buffer
+= sizeof(ie_header
);
305 retLen
+= sizeof(ie_header
);
307 /* Copy the wapi IE buffer to the output buffer, advance
309 memcpy(*buffer
, priv
->wapi_ie
, priv
->wapi_ie_len
);
311 /* Increment the return size and the return buffer pointer
313 *buffer
+= priv
->wapi_ie_len
;
314 retLen
+= priv
->wapi_ie_len
;
317 /* return the length appended to the buffer */
322 * This function appends rsn ie tlv for wpa/wpa2 security modes.
323 * It is called from the network join command preparation routine.
325 static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private
*priv
,
328 struct mwifiex_ie_types_rsn_param_set
*rsn_ie_tlv
;
331 if (!buffer
|| !(*buffer
))
334 rsn_ie_tlv
= (struct mwifiex_ie_types_rsn_param_set
*) (*buffer
);
335 rsn_ie_tlv
->header
.type
= cpu_to_le16((u16
) priv
->wpa_ie
[0]);
336 rsn_ie_tlv
->header
.type
= cpu_to_le16(
337 le16_to_cpu(rsn_ie_tlv
->header
.type
) & 0x00FF);
338 rsn_ie_tlv
->header
.len
= cpu_to_le16((u16
) priv
->wpa_ie
[1]);
339 rsn_ie_tlv
->header
.len
= cpu_to_le16(le16_to_cpu(rsn_ie_tlv
->header
.len
)
341 if (le16_to_cpu(rsn_ie_tlv
->header
.len
) <= (sizeof(priv
->wpa_ie
) - 2))
342 memcpy(rsn_ie_tlv
->rsn_ie
, &priv
->wpa_ie
[2],
343 le16_to_cpu(rsn_ie_tlv
->header
.len
));
347 rsn_ie_len
= sizeof(rsn_ie_tlv
->header
) +
348 le16_to_cpu(rsn_ie_tlv
->header
.len
);
349 *buffer
+= rsn_ie_len
;
355 * This function prepares command for association.
357 * This sets the following parameters -
361 * - Capability information
363 * ...and the following TLVs, as required -
368 * - Authentication TLV
372 * - Vendor specific TLV
378 * Preparation also includes -
379 * - Setting command ID and proper size
380 * - Ensuring correct endian-ness
382 int mwifiex_cmd_802_11_associate(struct mwifiex_private
*priv
,
383 struct host_cmd_ds_command
*cmd
,
384 struct mwifiex_bssdescriptor
*bss_desc
)
386 struct host_cmd_ds_802_11_associate
*assoc
= &cmd
->params
.associate
;
387 struct mwifiex_ie_types_ssid_param_set
*ssid_tlv
;
388 struct mwifiex_ie_types_phy_param_set
*phy_tlv
;
389 struct mwifiex_ie_types_ss_param_set
*ss_tlv
;
390 struct mwifiex_ie_types_rates_param_set
*rates_tlv
;
391 struct mwifiex_ie_types_auth_type
*auth_tlv
;
392 struct mwifiex_ie_types_chan_list_param_set
*chan_tlv
;
393 u8 rates
[MWIFIEX_SUPPORTED_RATES
];
401 mwifiex_cfg_tx_buf(priv
, bss_desc
);
403 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE
);
405 /* Save so we know which BSS Desc to use in the response handler */
406 priv
->attempted_bss_desc
= bss_desc
;
408 memcpy(assoc
->peer_sta_addr
,
409 bss_desc
->mac_address
, sizeof(assoc
->peer_sta_addr
));
410 pos
+= sizeof(assoc
->peer_sta_addr
);
412 /* Set the listen interval */
413 assoc
->listen_interval
= cpu_to_le16(priv
->listen_interval
);
414 /* Set the beacon period */
415 assoc
->beacon_period
= cpu_to_le16(bss_desc
->beacon_period
);
417 pos
+= sizeof(assoc
->cap_info_bitmap
);
418 pos
+= sizeof(assoc
->listen_interval
);
419 pos
+= sizeof(assoc
->beacon_period
);
420 pos
+= sizeof(assoc
->dtim_period
);
422 ssid_tlv
= (struct mwifiex_ie_types_ssid_param_set
*) pos
;
423 ssid_tlv
->header
.type
= cpu_to_le16(WLAN_EID_SSID
);
424 ssid_tlv
->header
.len
= cpu_to_le16((u16
) bss_desc
->ssid
.ssid_len
);
425 memcpy(ssid_tlv
->ssid
, bss_desc
->ssid
.ssid
,
426 le16_to_cpu(ssid_tlv
->header
.len
));
427 pos
+= sizeof(ssid_tlv
->header
) + le16_to_cpu(ssid_tlv
->header
.len
);
429 phy_tlv
= (struct mwifiex_ie_types_phy_param_set
*) pos
;
430 phy_tlv
->header
.type
= cpu_to_le16(WLAN_EID_DS_PARAMS
);
431 phy_tlv
->header
.len
= cpu_to_le16(sizeof(phy_tlv
->fh_ds
.ds_param_set
));
432 memcpy(&phy_tlv
->fh_ds
.ds_param_set
,
433 &bss_desc
->phy_param_set
.ds_param_set
.current_chan
,
434 sizeof(phy_tlv
->fh_ds
.ds_param_set
));
435 pos
+= sizeof(phy_tlv
->header
) + le16_to_cpu(phy_tlv
->header
.len
);
437 ss_tlv
= (struct mwifiex_ie_types_ss_param_set
*) pos
;
438 ss_tlv
->header
.type
= cpu_to_le16(WLAN_EID_CF_PARAMS
);
439 ss_tlv
->header
.len
= cpu_to_le16(sizeof(ss_tlv
->cf_ibss
.cf_param_set
));
440 pos
+= sizeof(ss_tlv
->header
) + le16_to_cpu(ss_tlv
->header
.len
);
442 /* Get the common rates supported between the driver and the BSS Desc */
443 if (mwifiex_setup_rates_from_bssdesc
444 (priv
, bss_desc
, rates
, &rates_size
))
447 /* Save the data rates into Current BSS state structure */
448 priv
->curr_bss_params
.num_of_rates
= rates_size
;
449 memcpy(&priv
->curr_bss_params
.data_rates
, rates
, rates_size
);
451 /* Setup the Rates TLV in the association command */
452 rates_tlv
= (struct mwifiex_ie_types_rates_param_set
*) pos
;
453 rates_tlv
->header
.type
= cpu_to_le16(WLAN_EID_SUPP_RATES
);
454 rates_tlv
->header
.len
= cpu_to_le16((u16
) rates_size
);
455 memcpy(rates_tlv
->rates
, rates
, rates_size
);
456 pos
+= sizeof(rates_tlv
->header
) + rates_size
;
457 dev_dbg(priv
->adapter
->dev
, "info: ASSOC_CMD: rates size = %d\n",
460 /* Add the Authentication type to be used for Auth frames */
461 auth_tlv
= (struct mwifiex_ie_types_auth_type
*) pos
;
462 auth_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_AUTH_TYPE
);
463 auth_tlv
->header
.len
= cpu_to_le16(sizeof(auth_tlv
->auth_type
));
464 if (priv
->sec_info
.wep_enabled
)
465 auth_tlv
->auth_type
= cpu_to_le16(
466 (u16
) priv
->sec_info
.authentication_mode
);
468 auth_tlv
->auth_type
= cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM
);
470 pos
+= sizeof(auth_tlv
->header
) + le16_to_cpu(auth_tlv
->header
.len
);
472 if (IS_SUPPORT_MULTI_BANDS(priv
->adapter
) &&
473 !(ISSUPP_11NENABLED(priv
->adapter
->fw_cap_info
) &&
474 (!bss_desc
->disable_11n
) &&
475 (priv
->adapter
->config_bands
& BAND_GN
||
476 priv
->adapter
->config_bands
& BAND_AN
) &&
477 (bss_desc
->bcn_ht_cap
)
480 /* Append a channel TLV for the channel the attempted AP was
482 chan_tlv
= (struct mwifiex_ie_types_chan_list_param_set
*) pos
;
483 chan_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_CHANLIST
);
484 chan_tlv
->header
.len
=
485 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set
));
487 memset(chan_tlv
->chan_scan_param
, 0x00,
488 sizeof(struct mwifiex_chan_scan_param_set
));
489 chan_tlv
->chan_scan_param
[0].chan_number
=
490 (bss_desc
->phy_param_set
.ds_param_set
.current_chan
);
491 dev_dbg(priv
->adapter
->dev
, "info: Assoc: TLV Chan = %d\n",
492 chan_tlv
->chan_scan_param
[0].chan_number
);
494 chan_tlv
->chan_scan_param
[0].radio_type
=
495 mwifiex_band_to_radio_type((u8
) bss_desc
->bss_band
);
497 dev_dbg(priv
->adapter
->dev
, "info: Assoc: TLV Band = %d\n",
498 chan_tlv
->chan_scan_param
[0].radio_type
);
499 pos
+= sizeof(chan_tlv
->header
) +
500 sizeof(struct mwifiex_chan_scan_param_set
);
503 if (!priv
->wps
.session_enable
) {
504 if (priv
->sec_info
.wpa_enabled
|| priv
->sec_info
.wpa2_enabled
)
505 rsn_ie_len
= mwifiex_append_rsn_ie_wpa_wpa2(priv
, &pos
);
507 if (rsn_ie_len
== -1)
511 if (ISSUPP_11NENABLED(priv
->adapter
->fw_cap_info
) &&
512 (!bss_desc
->disable_11n
) &&
513 (priv
->adapter
->config_bands
& BAND_GN
||
514 priv
->adapter
->config_bands
& BAND_AN
))
515 mwifiex_cmd_append_11n_tlv(priv
, bss_desc
, &pos
);
517 /* Append vendor specific IE TLV */
518 mwifiex_cmd_append_vsie_tlv(priv
, MWIFIEX_VSIE_MASK_ASSOC
, &pos
);
520 mwifiex_wmm_process_association_req(priv
, &pos
, &bss_desc
->wmm_ie
,
521 bss_desc
->bcn_ht_cap
);
522 if (priv
->sec_info
.wapi_enabled
&& priv
->wapi_ie_len
)
523 mwifiex_cmd_append_wapi_ie(priv
, &pos
);
525 if (priv
->wps
.session_enable
&& priv
->wps_ie_len
)
526 mwifiex_cmd_append_wps_ie(priv
, &pos
);
528 mwifiex_cmd_append_generic_ie(priv
, &pos
);
530 mwifiex_cmd_append_tsf_tlv(priv
, &pos
, bss_desc
);
532 cmd
->size
= cpu_to_le16((u16
) (pos
- (u8
*) assoc
) + S_DS_GEN
);
534 /* Set the Capability info at last */
535 tmp_cap
= bss_desc
->cap_info_bitmap
;
537 if (priv
->adapter
->config_bands
== BAND_B
)
538 tmp_cap
&= ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
540 tmp_cap
&= CAPINFO_MASK
;
541 dev_dbg(priv
->adapter
->dev
, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
542 tmp_cap
, CAPINFO_MASK
);
543 assoc
->cap_info_bitmap
= cpu_to_le16(tmp_cap
);
549 * Association firmware command response handler
551 * The response buffer for the association command has the following
554 * For cases where an association response was not received (indicated
555 * by the CapInfo and AId field):
557 * .------------------------------------------------------------.
558 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
559 * .------------------------------------------------------------.
560 * | cap_info/Error Return(t_u16): |
561 * | 0xFFFF(-1): Internal error |
562 * | 0xFFFE(-2): Authentication unhandled message |
563 * | 0xFFFD(-3): Authentication refused |
564 * | 0xFFFC(-4): Timeout waiting for AP response |
565 * .------------------------------------------------------------.
566 * | status_code(t_u16): |
567 * | If cap_info is -1: |
568 * | An internal firmware failure prevented the |
569 * | command from being processed. The status_code |
570 * | will be set to 1. |
572 * | If cap_info is -2: |
573 * | An authentication frame was received but was |
574 * | not handled by the firmware. IEEE Status |
575 * | code for the failure is returned. |
577 * | If cap_info is -3: |
578 * | An authentication frame was received and the |
579 * | status_code is the IEEE Status reported in the |
582 * | If cap_info is -4: |
583 * | (1) Association response timeout |
584 * | (2) Authentication response timeout |
585 * .------------------------------------------------------------.
586 * | a_id(t_u16): 0xFFFF |
587 * .------------------------------------------------------------.
590 * For cases where an association response was received, the IEEE
591 * standard association response frame is returned:
593 * .------------------------------------------------------------.
594 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
595 * .------------------------------------------------------------.
596 * | cap_info(t_u16): IEEE Capability |
597 * .------------------------------------------------------------.
598 * | status_code(t_u16): IEEE Status Code |
599 * .------------------------------------------------------------.
600 * | a_id(t_u16): IEEE Association ID |
601 * .------------------------------------------------------------.
602 * | IEEE IEs(variable): Any received IEs comprising the |
603 * | remaining portion of a received |
604 * | association response frame. |
605 * .------------------------------------------------------------.
607 * For simplistic handling, the status_code field can be used to determine
608 * an association success (0) or failure (non-zero).
610 int mwifiex_ret_802_11_associate(struct mwifiex_private
*priv
,
611 struct host_cmd_ds_command
*resp
)
613 struct mwifiex_adapter
*adapter
= priv
->adapter
;
615 struct ieee_types_assoc_rsp
*assoc_rsp
;
616 struct mwifiex_bssdescriptor
*bss_desc
;
617 u8 enable_data
= true;
619 assoc_rsp
= (struct ieee_types_assoc_rsp
*) &resp
->params
;
621 priv
->assoc_rsp_size
= min(le16_to_cpu(resp
->size
) - S_DS_GEN
,
622 sizeof(priv
->assoc_rsp_buf
));
624 memcpy(priv
->assoc_rsp_buf
, &resp
->params
, priv
->assoc_rsp_size
);
626 if (le16_to_cpu(assoc_rsp
->status_code
)) {
627 priv
->adapter
->dbg
.num_cmd_assoc_failure
++;
628 dev_err(priv
->adapter
->dev
,
629 "ASSOC_RESP: failed, status code=%d err=%#x a_id=%#x\n",
630 le16_to_cpu(assoc_rsp
->status_code
),
631 le16_to_cpu(assoc_rsp
->cap_info_bitmap
),
632 le16_to_cpu(assoc_rsp
->a_id
));
634 ret
= le16_to_cpu(assoc_rsp
->status_code
);
638 /* Send a Media Connected event, according to the Spec */
639 priv
->media_connected
= true;
641 priv
->adapter
->ps_state
= PS_STATE_AWAKE
;
642 priv
->adapter
->pps_uapsd_mode
= false;
643 priv
->adapter
->tx_lock_flag
= false;
645 /* Set the attempted BSSID Index to current */
646 bss_desc
= priv
->attempted_bss_desc
;
648 dev_dbg(priv
->adapter
->dev
, "info: ASSOC_RESP: %s\n",
649 bss_desc
->ssid
.ssid
);
651 /* Make a copy of current BSSID descriptor */
652 memcpy(&priv
->curr_bss_params
.bss_descriptor
,
653 bss_desc
, sizeof(struct mwifiex_bssdescriptor
));
655 /* Update curr_bss_params */
656 priv
->curr_bss_params
.bss_descriptor
.channel
657 = bss_desc
->phy_param_set
.ds_param_set
.current_chan
;
659 priv
->curr_bss_params
.band
= (u8
) bss_desc
->bss_band
;
661 if (bss_desc
->wmm_ie
.vend_hdr
.element_id
== WLAN_EID_VENDOR_SPECIFIC
)
662 priv
->curr_bss_params
.wmm_enabled
= true;
664 priv
->curr_bss_params
.wmm_enabled
= false;
666 if ((priv
->wmm_required
|| bss_desc
->bcn_ht_cap
) &&
667 priv
->curr_bss_params
.wmm_enabled
)
668 priv
->wmm_enabled
= true;
670 priv
->wmm_enabled
= false;
672 priv
->curr_bss_params
.wmm_uapsd_enabled
= false;
674 if (priv
->wmm_enabled
)
675 priv
->curr_bss_params
.wmm_uapsd_enabled
676 = ((bss_desc
->wmm_ie
.qos_info_bitmap
&
677 IEEE80211_WMM_IE_AP_QOSINFO_UAPSD
) ? 1 : 0);
679 dev_dbg(priv
->adapter
->dev
, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
680 priv
->curr_pkt_filter
);
681 if (priv
->sec_info
.wpa_enabled
|| priv
->sec_info
.wpa2_enabled
)
682 priv
->wpa_is_gtk_set
= false;
684 if (priv
->wmm_enabled
) {
685 /* Don't re-enable carrier until we get the WMM_GET_STATUS
689 /* Since WMM is not enabled, setup the queues with the
691 mwifiex_wmm_setup_queue_priorities(priv
, NULL
);
692 mwifiex_wmm_setup_ac_downgrade(priv
);
696 dev_dbg(priv
->adapter
->dev
,
697 "info: post association, re-enabling data flow\n");
699 /* Reset SNR/NF/RSSI values */
700 priv
->data_rssi_last
= 0;
701 priv
->data_nf_last
= 0;
702 priv
->data_rssi_avg
= 0;
703 priv
->data_nf_avg
= 0;
704 priv
->bcn_rssi_last
= 0;
705 priv
->bcn_nf_last
= 0;
706 priv
->bcn_rssi_avg
= 0;
707 priv
->bcn_nf_avg
= 0;
709 priv
->rxpd_htinfo
= 0;
711 mwifiex_save_curr_bcn(priv
);
713 priv
->adapter
->dbg
.num_cmd_assoc_success
++;
715 dev_dbg(priv
->adapter
->dev
, "info: ASSOC_RESP: associated\n");
717 /* Add the ra_list here for infra mode as there will be only 1 ra
719 mwifiex_ralist_add(priv
,
720 priv
->curr_bss_params
.bss_descriptor
.mac_address
);
722 if (!netif_carrier_ok(priv
->netdev
))
723 netif_carrier_on(priv
->netdev
);
724 if (netif_queue_stopped(priv
->netdev
))
725 netif_wake_queue(priv
->netdev
);
727 if (priv
->sec_info
.wpa_enabled
|| priv
->sec_info
.wpa2_enabled
)
728 priv
->scan_block
= true;
731 /* Need to indicate IOCTL complete */
732 if (adapter
->curr_cmd
->wait_q_enabled
) {
734 adapter
->cmd_wait_q
.status
= -1;
736 adapter
->cmd_wait_q
.status
= 0;
743 * This function prepares command for ad-hoc start.
745 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
746 * parameters, probe delay, and capability information. Firmware
747 * will fill up beacon period, basic rates and operational rates.
749 * In addition, the following TLVs are added -
751 * - Vendor specific IE
753 * - HT Capabilities IE
754 * - HT Information IE
756 * Preparation also includes -
757 * - Setting command ID and proper size
758 * - Ensuring correct endian-ness
761 mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private
*priv
,
762 struct host_cmd_ds_command
*cmd
,
763 struct cfg80211_ssid
*req_ssid
)
766 struct mwifiex_adapter
*adapter
= priv
->adapter
;
767 struct host_cmd_ds_802_11_ad_hoc_start
*adhoc_start
=
768 &cmd
->params
.adhoc_start
;
769 struct mwifiex_bssdescriptor
*bss_desc
;
770 u32 cmd_append_size
= 0;
773 struct mwifiex_ie_types_chan_list_param_set
*chan_tlv
;
776 struct mwifiex_ie_types_htcap
*ht_cap
;
777 struct mwifiex_ie_types_htinfo
*ht_info
;
778 u8
*pos
= (u8
*) adhoc_start
+
779 sizeof(struct host_cmd_ds_802_11_ad_hoc_start
);
784 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START
);
786 bss_desc
= &priv
->curr_bss_params
.bss_descriptor
;
787 priv
->attempted_bss_desc
= bss_desc
;
790 * Fill in the parameters for 2 data structures:
791 * 1. struct host_cmd_ds_802_11_ad_hoc_start command
793 * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
794 * probe delay, and Cap info.
795 * Firmware will fill up beacon period, Basic rates
796 * and operational rates.
799 memset(adhoc_start
->ssid
, 0, IEEE80211_MAX_SSID_LEN
);
801 memcpy(adhoc_start
->ssid
, req_ssid
->ssid
, req_ssid
->ssid_len
);
803 dev_dbg(adapter
->dev
, "info: ADHOC_S_CMD: SSID = %s\n",
806 memset(bss_desc
->ssid
.ssid
, 0, IEEE80211_MAX_SSID_LEN
);
807 memcpy(bss_desc
->ssid
.ssid
, req_ssid
->ssid
, req_ssid
->ssid_len
);
809 bss_desc
->ssid
.ssid_len
= req_ssid
->ssid_len
;
811 /* Set the BSS mode */
812 adhoc_start
->bss_mode
= HostCmd_BSS_MODE_IBSS
;
813 bss_desc
->bss_mode
= NL80211_IFTYPE_ADHOC
;
814 adhoc_start
->beacon_period
= cpu_to_le16(priv
->beacon_period
);
815 bss_desc
->beacon_period
= priv
->beacon_period
;
817 /* Set Physical param set */
818 /* Parameter IE Id */
819 #define DS_PARA_IE_ID 3
820 /* Parameter IE length */
821 #define DS_PARA_IE_LEN 1
823 adhoc_start
->phy_param_set
.ds_param_set
.element_id
= DS_PARA_IE_ID
;
824 adhoc_start
->phy_param_set
.ds_param_set
.len
= DS_PARA_IE_LEN
;
826 if (!mwifiex_get_cfp(priv
, adapter
->adhoc_start_band
,
827 (u16
) priv
->adhoc_channel
, 0)) {
828 struct mwifiex_chan_freq_power
*cfp
;
829 cfp
= mwifiex_get_cfp(priv
, adapter
->adhoc_start_band
,
830 FIRST_VALID_CHANNEL
, 0);
832 priv
->adhoc_channel
= (u8
) cfp
->channel
;
835 if (!priv
->adhoc_channel
) {
836 dev_err(adapter
->dev
, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
840 dev_dbg(adapter
->dev
, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
841 priv
->adhoc_channel
);
843 priv
->curr_bss_params
.bss_descriptor
.channel
= priv
->adhoc_channel
;
844 priv
->curr_bss_params
.band
= adapter
->adhoc_start_band
;
846 bss_desc
->channel
= priv
->adhoc_channel
;
847 adhoc_start
->phy_param_set
.ds_param_set
.current_chan
=
850 memcpy(&bss_desc
->phy_param_set
, &adhoc_start
->phy_param_set
,
851 sizeof(union ieee_types_phy_param_set
));
853 /* Set IBSS param set */
854 /* IBSS parameter IE Id */
855 #define IBSS_PARA_IE_ID 6
856 /* IBSS parameter IE length */
857 #define IBSS_PARA_IE_LEN 2
859 adhoc_start
->ss_param_set
.ibss_param_set
.element_id
= IBSS_PARA_IE_ID
;
860 adhoc_start
->ss_param_set
.ibss_param_set
.len
= IBSS_PARA_IE_LEN
;
861 adhoc_start
->ss_param_set
.ibss_param_set
.atim_window
862 = cpu_to_le16(priv
->atim_window
);
863 memcpy(&bss_desc
->ss_param_set
, &adhoc_start
->ss_param_set
,
864 sizeof(union ieee_types_ss_param_set
));
866 /* Set Capability info */
867 bss_desc
->cap_info_bitmap
|= WLAN_CAPABILITY_IBSS
;
868 tmp_cap
= le16_to_cpu(adhoc_start
->cap_info_bitmap
);
869 tmp_cap
&= ~WLAN_CAPABILITY_ESS
;
870 tmp_cap
|= WLAN_CAPABILITY_IBSS
;
872 /* Set up privacy in bss_desc */
873 if (priv
->sec_info
.encryption_mode
) {
874 /* Ad-Hoc capability privacy on */
875 dev_dbg(adapter
->dev
,
876 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
877 bss_desc
->privacy
= MWIFIEX_802_11_PRIV_FILTER_8021X_WEP
;
878 tmp_cap
|= WLAN_CAPABILITY_PRIVACY
;
880 dev_dbg(adapter
->dev
, "info: ADHOC_S_CMD: wep_status NOT set,"
881 " setting privacy to ACCEPT ALL\n");
882 bss_desc
->privacy
= MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL
;
885 memset(adhoc_start
->data_rate
, 0, sizeof(adhoc_start
->data_rate
));
886 mwifiex_get_active_data_rates(priv
, adhoc_start
->data_rate
);
887 if ((adapter
->adhoc_start_band
& BAND_G
) &&
888 (priv
->curr_pkt_filter
& HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON
)) {
889 if (mwifiex_send_cmd_async(priv
, HostCmd_CMD_MAC_CONTROL
,
890 HostCmd_ACT_GEN_SET
, 0,
891 &priv
->curr_pkt_filter
)) {
892 dev_err(adapter
->dev
,
893 "ADHOC_S_CMD: G Protection config failed\n");
897 /* Find the last non zero */
898 for (i
= 0; i
< sizeof(adhoc_start
->data_rate
); i
++)
899 if (!adhoc_start
->data_rate
[i
])
902 priv
->curr_bss_params
.num_of_rates
= i
;
904 /* Copy the ad-hoc creating rates into Current BSS rate structure */
905 memcpy(&priv
->curr_bss_params
.data_rates
,
906 &adhoc_start
->data_rate
, priv
->curr_bss_params
.num_of_rates
);
908 dev_dbg(adapter
->dev
, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n",
909 adhoc_start
->data_rate
[0], adhoc_start
->data_rate
[1],
910 adhoc_start
->data_rate
[2], adhoc_start
->data_rate
[3]);
912 dev_dbg(adapter
->dev
, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
914 if (IS_SUPPORT_MULTI_BANDS(adapter
)) {
915 /* Append a channel TLV */
916 chan_tlv
= (struct mwifiex_ie_types_chan_list_param_set
*) pos
;
917 chan_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_CHANLIST
);
918 chan_tlv
->header
.len
=
919 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set
));
921 memset(chan_tlv
->chan_scan_param
, 0x00,
922 sizeof(struct mwifiex_chan_scan_param_set
));
923 chan_tlv
->chan_scan_param
[0].chan_number
=
924 (u8
) priv
->curr_bss_params
.bss_descriptor
.channel
;
926 dev_dbg(adapter
->dev
, "info: ADHOC_S_CMD: TLV Chan = %d\n",
927 chan_tlv
->chan_scan_param
[0].chan_number
);
929 chan_tlv
->chan_scan_param
[0].radio_type
930 = mwifiex_band_to_radio_type(priv
->curr_bss_params
.band
);
931 if (adapter
->adhoc_start_band
& BAND_GN
||
932 adapter
->adhoc_start_band
& BAND_AN
) {
933 if (adapter
->sec_chan_offset
==
934 IEEE80211_HT_PARAM_CHA_SEC_ABOVE
)
935 chan_tlv
->chan_scan_param
[0].radio_type
|=
936 (IEEE80211_HT_PARAM_CHA_SEC_ABOVE
<< 4);
937 else if (adapter
->sec_chan_offset
==
938 IEEE80211_HT_PARAM_CHA_SEC_ABOVE
)
939 chan_tlv
->chan_scan_param
[0].radio_type
|=
940 (IEEE80211_HT_PARAM_CHA_SEC_BELOW
<< 4);
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
) {
963 /* Fill HT CAPABILITY */
964 ht_cap
= (struct mwifiex_ie_types_htcap
*) pos
;
965 memset(ht_cap
, 0, sizeof(struct mwifiex_ie_types_htcap
));
966 ht_cap
->header
.type
= cpu_to_le16(WLAN_EID_HT_CAPABILITY
);
968 cpu_to_le16(sizeof(struct ieee80211_ht_cap
));
969 radio_type
= mwifiex_band_to_radio_type(
970 priv
->adapter
->config_bands
);
971 mwifiex_fill_cap_info(priv
, radio_type
, ht_cap
);
973 pos
+= sizeof(struct mwifiex_ie_types_htcap
);
974 cmd_append_size
+= sizeof(struct mwifiex_ie_types_htcap
);
976 /* Fill HT INFORMATION */
977 ht_info
= (struct mwifiex_ie_types_htinfo
*) pos
;
978 memset(ht_info
, 0, sizeof(struct mwifiex_ie_types_htinfo
));
979 ht_info
->header
.type
= cpu_to_le16(WLAN_EID_HT_OPERATION
);
980 ht_info
->header
.len
=
981 cpu_to_le16(sizeof(struct ieee80211_ht_operation
));
983 ht_info
->ht_oper
.primary_chan
=
984 (u8
) priv
->curr_bss_params
.bss_descriptor
.channel
;
985 if (adapter
->sec_chan_offset
) {
986 ht_info
->ht_oper
.ht_param
= adapter
->sec_chan_offset
;
987 ht_info
->ht_oper
.ht_param
|=
988 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY
;
990 ht_info
->ht_oper
.operation_mode
=
991 cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
992 ht_info
->ht_oper
.basic_set
[0] = 0xff;
993 pos
+= sizeof(struct mwifiex_ie_types_htinfo
);
995 sizeof(struct mwifiex_ie_types_htinfo
);
999 cpu_to_le16((u16
)(sizeof(struct host_cmd_ds_802_11_ad_hoc_start
)
1000 + S_DS_GEN
+ cmd_append_size
));
1002 if (adapter
->adhoc_start_band
== BAND_B
)
1003 tmp_cap
&= ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
1005 tmp_cap
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
1007 adhoc_start
->cap_info_bitmap
= cpu_to_le16(tmp_cap
);
1013 * This function prepares command for ad-hoc join.
1015 * Most of the parameters are set up by copying from the target BSS descriptor
1016 * from the scan response.
1018 * In addition, the following TLVs are added -
1020 * - Vendor specific IE
1024 * Preparation also includes -
1025 * - Setting command ID and proper size
1026 * - Ensuring correct endian-ness
1029 mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private
*priv
,
1030 struct host_cmd_ds_command
*cmd
,
1031 struct mwifiex_bssdescriptor
*bss_desc
)
1034 struct host_cmd_ds_802_11_ad_hoc_join
*adhoc_join
=
1035 &cmd
->params
.adhoc_join
;
1036 struct mwifiex_ie_types_chan_list_param_set
*chan_tlv
;
1037 u32 cmd_append_size
= 0;
1039 u32 i
, rates_size
= 0;
1040 u16 curr_pkt_filter
;
1043 sizeof(struct host_cmd_ds_802_11_ad_hoc_join
);
1045 /* Use G protection */
1046 #define USE_G_PROTECTION 0x02
1047 if (bss_desc
->erp_flags
& USE_G_PROTECTION
) {
1050 curr_pkt_filter
| HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON
;
1052 if (mwifiex_send_cmd_async(priv
, HostCmd_CMD_MAC_CONTROL
,
1053 HostCmd_ACT_GEN_SET
, 0,
1054 &curr_pkt_filter
)) {
1055 dev_err(priv
->adapter
->dev
,
1056 "ADHOC_J_CMD: G Protection config failed\n");
1061 priv
->attempted_bss_desc
= bss_desc
;
1063 cmd
->command
= cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN
);
1065 adhoc_join
->bss_descriptor
.bss_mode
= HostCmd_BSS_MODE_IBSS
;
1067 adhoc_join
->bss_descriptor
.beacon_period
1068 = cpu_to_le16(bss_desc
->beacon_period
);
1070 memcpy(&adhoc_join
->bss_descriptor
.bssid
,
1071 &bss_desc
->mac_address
, ETH_ALEN
);
1073 memcpy(&adhoc_join
->bss_descriptor
.ssid
,
1074 &bss_desc
->ssid
.ssid
, bss_desc
->ssid
.ssid_len
);
1076 memcpy(&adhoc_join
->bss_descriptor
.phy_param_set
,
1077 &bss_desc
->phy_param_set
,
1078 sizeof(union ieee_types_phy_param_set
));
1080 memcpy(&adhoc_join
->bss_descriptor
.ss_param_set
,
1081 &bss_desc
->ss_param_set
, sizeof(union ieee_types_ss_param_set
));
1083 tmp_cap
= bss_desc
->cap_info_bitmap
;
1085 tmp_cap
&= CAPINFO_MASK
;
1087 dev_dbg(priv
->adapter
->dev
,
1088 "info: ADHOC_J_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
1089 tmp_cap
, CAPINFO_MASK
);
1091 /* Information on BSSID descriptor passed to FW */
1092 dev_dbg(priv
->adapter
->dev
, "info: ADHOC_J_CMD: BSSID=%pM, SSID='%s'\n",
1093 adhoc_join
->bss_descriptor
.bssid
,
1094 adhoc_join
->bss_descriptor
.ssid
);
1096 for (i
= 0; bss_desc
->supported_rates
[i
] &&
1097 i
< MWIFIEX_SUPPORTED_RATES
;
1102 /* Copy Data Rates from the Rates recorded in scan response */
1103 memset(adhoc_join
->bss_descriptor
.data_rates
, 0,
1104 sizeof(adhoc_join
->bss_descriptor
.data_rates
));
1105 memcpy(adhoc_join
->bss_descriptor
.data_rates
,
1106 bss_desc
->supported_rates
, rates_size
);
1108 /* Copy the adhoc join rates into Current BSS state structure */
1109 priv
->curr_bss_params
.num_of_rates
= rates_size
;
1110 memcpy(&priv
->curr_bss_params
.data_rates
, bss_desc
->supported_rates
,
1113 /* Copy the channel information */
1114 priv
->curr_bss_params
.bss_descriptor
.channel
= bss_desc
->channel
;
1115 priv
->curr_bss_params
.band
= (u8
) bss_desc
->bss_band
;
1117 if (priv
->sec_info
.wep_enabled
|| priv
->sec_info
.wpa_enabled
)
1118 tmp_cap
|= WLAN_CAPABILITY_PRIVACY
;
1120 if (IS_SUPPORT_MULTI_BANDS(priv
->adapter
)) {
1121 /* Append a channel TLV */
1122 chan_tlv
= (struct mwifiex_ie_types_chan_list_param_set
*) pos
;
1123 chan_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_CHANLIST
);
1124 chan_tlv
->header
.len
=
1125 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set
));
1127 memset(chan_tlv
->chan_scan_param
, 0x00,
1128 sizeof(struct mwifiex_chan_scan_param_set
));
1129 chan_tlv
->chan_scan_param
[0].chan_number
=
1130 (bss_desc
->phy_param_set
.ds_param_set
.current_chan
);
1131 dev_dbg(priv
->adapter
->dev
, "info: ADHOC_J_CMD: TLV Chan=%d\n",
1132 chan_tlv
->chan_scan_param
[0].chan_number
);
1134 chan_tlv
->chan_scan_param
[0].radio_type
=
1135 mwifiex_band_to_radio_type((u8
) bss_desc
->bss_band
);
1137 dev_dbg(priv
->adapter
->dev
, "info: ADHOC_J_CMD: TLV Band=%d\n",
1138 chan_tlv
->chan_scan_param
[0].radio_type
);
1139 pos
+= sizeof(chan_tlv
->header
) +
1140 sizeof(struct mwifiex_chan_scan_param_set
);
1141 cmd_append_size
+= sizeof(chan_tlv
->header
) +
1142 sizeof(struct mwifiex_chan_scan_param_set
);
1145 if (priv
->sec_info
.wpa_enabled
)
1146 rsn_ie_len
= mwifiex_append_rsn_ie_wpa_wpa2(priv
, &pos
);
1147 if (rsn_ie_len
== -1)
1149 cmd_append_size
+= rsn_ie_len
;
1151 if (ISSUPP_11NENABLED(priv
->adapter
->fw_cap_info
))
1152 cmd_append_size
+= mwifiex_cmd_append_11n_tlv(priv
,
1155 /* Append vendor specific IE TLV */
1156 cmd_append_size
+= mwifiex_cmd_append_vsie_tlv(priv
,
1157 MWIFIEX_VSIE_MASK_ADHOC
, &pos
);
1159 cmd
->size
= cpu_to_le16
1160 ((u16
) (sizeof(struct host_cmd_ds_802_11_ad_hoc_join
)
1161 + S_DS_GEN
+ cmd_append_size
));
1163 adhoc_join
->bss_descriptor
.cap_info_bitmap
= cpu_to_le16(tmp_cap
);
1169 * This function handles the command response of ad-hoc start and
1172 * The function generates a device-connected event to notify
1173 * the applications, in case of successful ad-hoc start/join, and
1174 * saves the beacon buffer.
1176 int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private
*priv
,
1177 struct host_cmd_ds_command
*resp
)
1180 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1181 struct host_cmd_ds_802_11_ad_hoc_result
*adhoc_result
;
1182 struct mwifiex_bssdescriptor
*bss_desc
;
1184 adhoc_result
= &resp
->params
.adhoc_result
;
1186 bss_desc
= priv
->attempted_bss_desc
;
1188 /* Join result code 0 --> SUCCESS */
1189 if (le16_to_cpu(resp
->result
)) {
1190 dev_err(priv
->adapter
->dev
, "ADHOC_RESP: failed\n");
1191 if (priv
->media_connected
)
1192 mwifiex_reset_connect_state(priv
);
1194 memset(&priv
->curr_bss_params
.bss_descriptor
,
1195 0x00, sizeof(struct mwifiex_bssdescriptor
));
1201 /* Send a Media Connected event, according to the Spec */
1202 priv
->media_connected
= true;
1204 if (le16_to_cpu(resp
->command
) == HostCmd_CMD_802_11_AD_HOC_START
) {
1205 dev_dbg(priv
->adapter
->dev
, "info: ADHOC_S_RESP %s\n",
1206 bss_desc
->ssid
.ssid
);
1208 /* Update the created network descriptor with the new BSSID */
1209 memcpy(bss_desc
->mac_address
,
1210 adhoc_result
->bssid
, ETH_ALEN
);
1212 priv
->adhoc_state
= ADHOC_STARTED
;
1215 * Now the join cmd should be successful.
1216 * If BSSID has changed use SSID to compare instead of BSSID
1218 dev_dbg(priv
->adapter
->dev
, "info: ADHOC_J_RESP %s\n",
1219 bss_desc
->ssid
.ssid
);
1222 * Make a copy of current BSSID descriptor, only needed for
1223 * join since the current descriptor is already being used
1226 memcpy(&priv
->curr_bss_params
.bss_descriptor
,
1227 bss_desc
, sizeof(struct mwifiex_bssdescriptor
));
1229 priv
->adhoc_state
= ADHOC_JOINED
;
1232 dev_dbg(priv
->adapter
->dev
, "info: ADHOC_RESP: channel = %d\n",
1233 priv
->adhoc_channel
);
1234 dev_dbg(priv
->adapter
->dev
, "info: ADHOC_RESP: BSSID = %pM\n",
1235 priv
->curr_bss_params
.bss_descriptor
.mac_address
);
1237 if (!netif_carrier_ok(priv
->netdev
))
1238 netif_carrier_on(priv
->netdev
);
1239 if (netif_queue_stopped(priv
->netdev
))
1240 netif_wake_queue(priv
->netdev
);
1242 mwifiex_save_curr_bcn(priv
);
1245 /* Need to indicate IOCTL complete */
1246 if (adapter
->curr_cmd
->wait_q_enabled
) {
1248 adapter
->cmd_wait_q
.status
= -1;
1250 adapter
->cmd_wait_q
.status
= 0;
1258 * This function associates to a specific BSS discovered in a scan.
1260 * It clears any past association response stored for application
1261 * retrieval and calls the command preparation routine to send the
1262 * command to firmware.
1264 int mwifiex_associate(struct mwifiex_private
*priv
,
1265 struct mwifiex_bssdescriptor
*bss_desc
)
1267 u8 current_bssid
[ETH_ALEN
];
1269 /* Return error if the adapter or table entry is not marked as infra */
1270 if ((priv
->bss_mode
!= NL80211_IFTYPE_STATION
) ||
1271 (bss_desc
->bss_mode
!= NL80211_IFTYPE_STATION
))
1274 memcpy(¤t_bssid
,
1275 &priv
->curr_bss_params
.bss_descriptor
.mac_address
,
1276 sizeof(current_bssid
));
1278 /* Clear any past association response stored for application
1280 priv
->assoc_rsp_size
= 0;
1282 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_ASSOCIATE
,
1283 HostCmd_ACT_GEN_SET
, 0, bss_desc
);
1287 * This function starts an ad-hoc network.
1289 * It calls the command preparation routine to send the command to firmware.
1292 mwifiex_adhoc_start(struct mwifiex_private
*priv
,
1293 struct cfg80211_ssid
*adhoc_ssid
)
1295 dev_dbg(priv
->adapter
->dev
, "info: Adhoc Channel = %d\n",
1296 priv
->adhoc_channel
);
1297 dev_dbg(priv
->adapter
->dev
, "info: curr_bss_params.channel = %d\n",
1298 priv
->curr_bss_params
.bss_descriptor
.channel
);
1299 dev_dbg(priv
->adapter
->dev
, "info: curr_bss_params.band = %d\n",
1300 priv
->curr_bss_params
.band
);
1302 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_AD_HOC_START
,
1303 HostCmd_ACT_GEN_SET
, 0, adhoc_ssid
);
1307 * This function joins an ad-hoc network found in a previous scan.
1309 * It calls the command preparation routine to send the command to firmware,
1310 * if already not connected to the requested SSID.
1312 int mwifiex_adhoc_join(struct mwifiex_private
*priv
,
1313 struct mwifiex_bssdescriptor
*bss_desc
)
1315 dev_dbg(priv
->adapter
->dev
, "info: adhoc join: curr_bss ssid =%s\n",
1316 priv
->curr_bss_params
.bss_descriptor
.ssid
.ssid
);
1317 dev_dbg(priv
->adapter
->dev
, "info: adhoc join: curr_bss ssid_len =%u\n",
1318 priv
->curr_bss_params
.bss_descriptor
.ssid
.ssid_len
);
1319 dev_dbg(priv
->adapter
->dev
, "info: adhoc join: ssid =%s\n",
1320 bss_desc
->ssid
.ssid
);
1321 dev_dbg(priv
->adapter
->dev
, "info: adhoc join: ssid_len =%u\n",
1322 bss_desc
->ssid
.ssid_len
);
1324 /* Check if the requested SSID is already joined */
1325 if (priv
->curr_bss_params
.bss_descriptor
.ssid
.ssid_len
&&
1326 !mwifiex_ssid_cmp(&bss_desc
->ssid
,
1327 &priv
->curr_bss_params
.bss_descriptor
.ssid
) &&
1328 (priv
->curr_bss_params
.bss_descriptor
.bss_mode
==
1329 NL80211_IFTYPE_ADHOC
)) {
1330 dev_dbg(priv
->adapter
->dev
, "info: ADHOC_J_CMD: new ad-hoc SSID"
1331 " is the same as current; not attempting to re-join\n");
1335 dev_dbg(priv
->adapter
->dev
, "info: curr_bss_params.channel = %d\n",
1336 priv
->curr_bss_params
.bss_descriptor
.channel
);
1337 dev_dbg(priv
->adapter
->dev
, "info: curr_bss_params.band = %c\n",
1338 priv
->curr_bss_params
.band
);
1340 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_AD_HOC_JOIN
,
1341 HostCmd_ACT_GEN_SET
, 0, bss_desc
);
1345 * This function deauthenticates/disconnects from infra network by sending
1346 * deauthentication request.
1348 static int mwifiex_deauthenticate_infra(struct mwifiex_private
*priv
, u8
*mac
)
1350 u8 mac_address
[ETH_ALEN
];
1353 if (!mac
|| is_zero_ether_addr(mac
))
1355 priv
->curr_bss_params
.bss_descriptor
.mac_address
,
1358 memcpy(mac_address
, mac
, ETH_ALEN
);
1360 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_DEAUTHENTICATE
,
1361 HostCmd_ACT_GEN_SET
, 0, mac_address
);
1367 * This function deauthenticates/disconnects from a BSS.
1369 * In case of infra made, it sends deauthentication request, and
1370 * in case of ad-hoc mode, a stop network request is sent to the firmware.
1371 * In AP mode, a command to stop bss is sent to firmware.
1373 int mwifiex_deauthenticate(struct mwifiex_private
*priv
, u8
*mac
)
1375 if (!priv
->media_connected
)
1378 switch (priv
->bss_mode
) {
1379 case NL80211_IFTYPE_STATION
:
1380 return mwifiex_deauthenticate_infra(priv
, mac
);
1381 case NL80211_IFTYPE_ADHOC
:
1382 return mwifiex_send_cmd_sync(priv
,
1383 HostCmd_CMD_802_11_AD_HOC_STOP
,
1384 HostCmd_ACT_GEN_SET
, 0, NULL
);
1385 case NL80211_IFTYPE_AP
:
1386 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_UAP_BSS_STOP
,
1387 HostCmd_ACT_GEN_SET
, 0, NULL
);
1394 EXPORT_SYMBOL_GPL(mwifiex_deauthenticate
);
1397 * This function converts band to radio type used in channel TLV.
1400 mwifiex_band_to_radio_type(u8 band
)
1405 case BAND_A
| BAND_AN
:
1406 return HostCmd_SCAN_RADIO_TYPE_A
;
1409 case BAND_B
| BAND_G
:
1411 return HostCmd_SCAN_RADIO_TYPE_BG
;