Revert "Merge branch 'ath6kl-next' of master.kernel.org:/pub/scm/linux/kernel/git...
[linux-2.6/next.git] / drivers / net / wireless / mwifiex / join.c
blob644e2e405cb555511e4a12b9bab5b8bfd8a76cb2
1 /*
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.
20 #include "decl.h"
21 #include "ioctl.h"
22 #include "util.h"
23 #include "fw.h"
24 #include "main.h"
25 #include "wmm.h"
26 #include "11n.h"
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.
38 static int
39 mwifiex_cmd_append_generic_ie(struct mwifiex_private *priv, u8 **buffer)
41 int ret_len = 0;
42 struct mwifiex_ie_types_header ie_header;
44 /* Null Checks */
45 if (!buffer)
46 return 0;
47 if (!(*buffer))
48 return 0;
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
64 param */
65 *buffer += sizeof(ie_header);
66 ret_len += sizeof(ie_header);
68 /* Copy the generic IE buffer to the output buffer, advance
69 pointer */
70 memcpy(*buffer, priv->gen_ie_buf, priv->gen_ie_buf_len);
72 /* Increment the return size and the return buffer pointer
73 param */
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 */
82 return ret_len;
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.
98 static int
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;
103 __le64 tsf_val;
105 /* Null Checks */
106 if (buffer == NULL)
107 return 0;
108 if (*buffer == NULL)
109 return 0;
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)
146 int ret;
147 u8 *ptr = rate1, *tmp;
148 u32 i, j;
150 tmp = kmalloc(rate1_size, GFP_KERNEL);
151 if (!tmp) {
152 dev_err(priv->adapter->dev, "failed to alloc tmp buf\n");
153 return -ENOMEM;
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
162 basic rate */
163 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) {
164 *rate1++ = tmp[j];
165 break;
170 dev_dbg(priv->adapter->dev, "info: Tx data rate set to %#x\n",
171 priv->data_rate);
173 if (!priv->is_data_rate_auto) {
174 while (*ptr) {
175 if ((*ptr & 0x7f) == priv->data_rate) {
176 ret = 0;
177 goto done;
179 ptr++;
181 dev_err(priv->adapter->dev, "previously set fixed data rate %#x"
182 " is not compatible with the network\n",
183 priv->data_rate);
185 ret = -1;
186 goto done;
189 ret = 0;
190 done:
191 kfree(tmp);
192 return ret;
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.
199 static int
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];
205 u32 card_rates_size;
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)) {
214 *out_rates_size = 0;
215 dev_err(priv->adapter->dev, "%s: cannot get common rates\n",
216 __func__);
217 return -1;
220 *out_rates_size =
221 min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES);
223 return 0;
227 * This function updates the scan entry TSF timestamps to reflect
228 * a new association.
230 static void
231 mwifiex_update_tsf_timestamps(struct mwifiex_private *priv,
232 struct mwifiex_bssdescriptor *new_bss_desc)
234 struct mwifiex_adapter *adapter = priv->adapter;
235 u32 table_idx;
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;
248 table_idx++)
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.
260 static int
261 mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer)
263 int retLen = 0;
264 struct mwifiex_ie_types_header ie_header;
266 /* Null Checks */
267 if (buffer == NULL)
268 return 0;
269 if (*buffer == NULL)
270 return 0;
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
286 param */
287 *buffer += sizeof(ie_header);
288 retLen += sizeof(ie_header);
290 /* Copy the wapi IE buffer to the output buffer, advance
291 pointer */
292 memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len);
294 /* Increment the return size and the return buffer pointer
295 param */
296 *buffer += priv->wapi_ie_len;
297 retLen += priv->wapi_ie_len;
300 /* return the length appended to the buffer */
301 return retLen;
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,
309 u8 **buffer)
311 struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv;
312 int rsn_ie_len;
314 if (!buffer || !(*buffer))
315 return 0;
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)
323 & 0x00FF);
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));
327 else
328 return -1;
330 rsn_ie_len = sizeof(rsn_ie_tlv->header) +
331 le16_to_cpu(rsn_ie_tlv->header.len);
332 *buffer += rsn_ie_len;
334 return rsn_ie_len;
338 * This function prepares command for association.
340 * This sets the following parameters -
341 * - Peer MAC address
342 * - Listen interval
343 * - Beacon interval
344 * - Capability information
346 * ...and the following TLVs, as required -
347 * - SSID TLV
348 * - PHY TLV
349 * - SS TLV
350 * - Rates TLV
351 * - Authentication TLV
352 * - Channel TLV
353 * - WPA/WPA2 IE
354 * - 11n TLV
355 * - Vendor specific TLV
356 * - WMM TLV
357 * - WAPI IE
358 * - Generic IE
359 * - TSF 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,
367 struct mwifiex_bssdescriptor *bss_desc)
369 struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate;
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];
377 u32 rates_size;
378 u16 tmp_cap;
379 u8 *pos;
380 int rsn_ie_len = 0;
382 pos = (u8 *) assoc;
384 mwifiex_cfg_tx_buf(priv, bss_desc);
386 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
388 /* Save so we know which BSS Desc to use in the response handler */
389 priv->attempted_bss_desc = bss_desc;
391 memcpy(assoc->peer_sta_addr,
392 bss_desc->mac_address, sizeof(assoc->peer_sta_addr));
393 pos += sizeof(assoc->peer_sta_addr);
395 /* Set the listen interval */
396 assoc->listen_interval = cpu_to_le16(priv->listen_interval);
397 /* Set the beacon period */
398 assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period);
400 pos += sizeof(assoc->cap_info_bitmap);
401 pos += sizeof(assoc->listen_interval);
402 pos += sizeof(assoc->beacon_period);
403 pos += sizeof(assoc->dtim_period);
405 ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos;
406 ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID);
407 ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len);
408 memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid,
409 le16_to_cpu(ssid_tlv->header.len));
410 pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len);
412 phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos;
413 phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS);
414 phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set));
415 memcpy(&phy_tlv->fh_ds.ds_param_set,
416 &bss_desc->phy_param_set.ds_param_set.current_chan,
417 sizeof(phy_tlv->fh_ds.ds_param_set));
418 pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len);
420 ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos;
421 ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS);
422 ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set));
423 pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len);
425 /* Get the common rates supported between the driver and the BSS Desc */
426 if (mwifiex_setup_rates_from_bssdesc
427 (priv, bss_desc, rates, &rates_size))
428 return -1;
430 /* Save the data rates into Current BSS state structure */
431 priv->curr_bss_params.num_of_rates = rates_size;
432 memcpy(&priv->curr_bss_params.data_rates, rates, rates_size);
434 /* Setup the Rates TLV in the association command */
435 rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos;
436 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
437 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
438 memcpy(rates_tlv->rates, rates, rates_size);
439 pos += sizeof(rates_tlv->header) + rates_size;
440 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: rates size = %d\n",
441 rates_size);
443 /* Add the Authentication type to be used for Auth frames */
444 auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
445 auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
446 auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
447 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
448 auth_tlv->auth_type = cpu_to_le16(
449 (u16) priv->sec_info.authentication_mode);
450 else
451 auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM);
453 pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len);
455 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)
456 && !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
457 && (!bss_desc->disable_11n)
458 && (priv->adapter->config_bands & BAND_GN
459 || priv->adapter->config_bands & BAND_AN)
460 && (bss_desc->bcn_ht_cap)
463 /* Append a channel TLV for the channel the attempted AP was
464 found on */
465 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
466 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
467 chan_tlv->header.len =
468 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
470 memset(chan_tlv->chan_scan_param, 0x00,
471 sizeof(struct mwifiex_chan_scan_param_set));
472 chan_tlv->chan_scan_param[0].chan_number =
473 (bss_desc->phy_param_set.ds_param_set.current_chan);
474 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
475 chan_tlv->chan_scan_param[0].chan_number);
477 chan_tlv->chan_scan_param[0].radio_type =
478 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
480 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
481 chan_tlv->chan_scan_param[0].radio_type);
482 pos += sizeof(chan_tlv->header) +
483 sizeof(struct mwifiex_chan_scan_param_set);
486 if (!priv->wps.session_enable) {
487 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
488 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
490 if (rsn_ie_len == -1)
491 return -1;
494 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
495 && (!bss_desc->disable_11n)
496 && (priv->adapter->config_bands & BAND_GN
497 || priv->adapter->config_bands & BAND_AN))
498 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
500 /* Append vendor specific IE TLV */
501 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
503 mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
504 bss_desc->bcn_ht_cap);
505 if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
506 mwifiex_cmd_append_wapi_ie(priv, &pos);
509 mwifiex_cmd_append_generic_ie(priv, &pos);
511 mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
513 cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
515 /* Set the Capability info at last */
516 tmp_cap = bss_desc->cap_info_bitmap;
518 if (priv->adapter->config_bands == BAND_B)
519 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
521 tmp_cap &= CAPINFO_MASK;
522 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
523 tmp_cap, CAPINFO_MASK);
524 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
526 return 0;
530 * Association firmware command response handler
532 * The response buffer for the association command has the following
533 * memory layout.
535 * For cases where an association response was not received (indicated
536 * by the CapInfo and AId field):
538 * .------------------------------------------------------------.
539 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
540 * .------------------------------------------------------------.
541 * | cap_info/Error Return(t_u16): |
542 * | 0xFFFF(-1): Internal error |
543 * | 0xFFFE(-2): Authentication unhandled message |
544 * | 0xFFFD(-3): Authentication refused |
545 * | 0xFFFC(-4): Timeout waiting for AP response |
546 * .------------------------------------------------------------.
547 * | status_code(t_u16): |
548 * | If cap_info is -1: |
549 * | An internal firmware failure prevented the |
550 * | command from being processed. The status_code |
551 * | will be set to 1. |
552 * | |
553 * | If cap_info is -2: |
554 * | An authentication frame was received but was |
555 * | not handled by the firmware. IEEE Status |
556 * | code for the failure is returned. |
557 * | |
558 * | If cap_info is -3: |
559 * | An authentication frame was received and the |
560 * | status_code is the IEEE Status reported in the |
561 * | response. |
562 * | |
563 * | If cap_info is -4: |
564 * | (1) Association response timeout |
565 * | (2) Authentication response timeout |
566 * .------------------------------------------------------------.
567 * | a_id(t_u16): 0xFFFF |
568 * .------------------------------------------------------------.
571 * For cases where an association response was received, the IEEE
572 * standard association response frame is returned:
574 * .------------------------------------------------------------.
575 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
576 * .------------------------------------------------------------.
577 * | cap_info(t_u16): IEEE Capability |
578 * .------------------------------------------------------------.
579 * | status_code(t_u16): IEEE Status Code |
580 * .------------------------------------------------------------.
581 * | a_id(t_u16): IEEE Association ID |
582 * .------------------------------------------------------------.
583 * | IEEE IEs(variable): Any received IEs comprising the |
584 * | remaining portion of a received |
585 * | association response frame. |
586 * .------------------------------------------------------------.
588 * For simplistic handling, the status_code field can be used to determine
589 * an association success (0) or failure (non-zero).
591 int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
592 struct host_cmd_ds_command *resp)
594 struct mwifiex_adapter *adapter = priv->adapter;
595 int ret = 0;
596 struct ieee_types_assoc_rsp *assoc_rsp;
597 struct mwifiex_bssdescriptor *bss_desc;
598 u8 enable_data = true;
600 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
602 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
603 sizeof(priv->assoc_rsp_buf));
605 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
607 if (le16_to_cpu(assoc_rsp->status_code)) {
608 priv->adapter->dbg.num_cmd_assoc_failure++;
609 dev_err(priv->adapter->dev, "ASSOC_RESP: association failed, "
610 "status code = %d, error = 0x%x, a_id = 0x%x\n",
611 le16_to_cpu(assoc_rsp->status_code),
612 le16_to_cpu(assoc_rsp->cap_info_bitmap),
613 le16_to_cpu(assoc_rsp->a_id));
615 ret = -1;
616 goto done;
619 /* Send a Media Connected event, according to the Spec */
620 priv->media_connected = true;
622 priv->adapter->ps_state = PS_STATE_AWAKE;
623 priv->adapter->pps_uapsd_mode = false;
624 priv->adapter->tx_lock_flag = false;
626 /* Set the attempted BSSID Index to current */
627 bss_desc = priv->attempted_bss_desc;
629 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n",
630 bss_desc->ssid.ssid);
632 /* Make a copy of current BSSID descriptor */
633 memcpy(&priv->curr_bss_params.bss_descriptor,
634 bss_desc, sizeof(struct mwifiex_bssdescriptor));
636 /* Update curr_bss_params */
637 priv->curr_bss_params.bss_descriptor.channel
638 = bss_desc->phy_param_set.ds_param_set.current_chan;
640 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
643 * Adjust the timestamps in the scan table to be relative to the newly
644 * associated AP's TSF
646 mwifiex_update_tsf_timestamps(priv, bss_desc);
648 if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
649 priv->curr_bss_params.wmm_enabled = true;
650 else
651 priv->curr_bss_params.wmm_enabled = false;
653 if ((priv->wmm_required || bss_desc->bcn_ht_cap)
654 && priv->curr_bss_params.wmm_enabled)
655 priv->wmm_enabled = true;
656 else
657 priv->wmm_enabled = false;
659 priv->curr_bss_params.wmm_uapsd_enabled = false;
661 if (priv->wmm_enabled)
662 priv->curr_bss_params.wmm_uapsd_enabled
663 = ((bss_desc->wmm_ie.qos_info_bitmap &
664 IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
666 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
667 priv->curr_pkt_filter);
668 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
669 priv->wpa_is_gtk_set = false;
671 if (priv->wmm_enabled) {
672 /* Don't re-enable carrier until we get the WMM_GET_STATUS
673 event */
674 enable_data = false;
675 } else {
676 /* Since WMM is not enabled, setup the queues with the
677 defaults */
678 mwifiex_wmm_setup_queue_priorities(priv, NULL);
679 mwifiex_wmm_setup_ac_downgrade(priv);
682 if (enable_data)
683 dev_dbg(priv->adapter->dev,
684 "info: post association, re-enabling data flow\n");
686 /* Reset SNR/NF/RSSI values */
687 priv->data_rssi_last = 0;
688 priv->data_nf_last = 0;
689 priv->data_rssi_avg = 0;
690 priv->data_nf_avg = 0;
691 priv->bcn_rssi_last = 0;
692 priv->bcn_nf_last = 0;
693 priv->bcn_rssi_avg = 0;
694 priv->bcn_nf_avg = 0;
695 priv->rxpd_rate = 0;
696 priv->rxpd_htinfo = 0;
698 mwifiex_save_curr_bcn(priv);
700 priv->adapter->dbg.num_cmd_assoc_success++;
702 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n");
704 /* Add the ra_list here for infra mode as there will be only 1 ra
705 always */
706 mwifiex_ralist_add(priv,
707 priv->curr_bss_params.bss_descriptor.mac_address);
709 if (!netif_carrier_ok(priv->netdev))
710 netif_carrier_on(priv->netdev);
711 if (netif_queue_stopped(priv->netdev))
712 netif_wake_queue(priv->netdev);
714 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
715 priv->scan_block = true;
717 done:
718 /* Need to indicate IOCTL complete */
719 if (adapter->curr_cmd->wait_q_enabled) {
720 if (ret)
721 adapter->cmd_wait_q.status = -1;
722 else
723 adapter->cmd_wait_q.status = 0;
726 return ret;
730 * This function prepares command for ad-hoc start.
732 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
733 * parameters, probe delay, and capability information. Firmware
734 * will fill up beacon period, basic rates and operational rates.
736 * In addition, the following TLVs are added -
737 * - Channel TLV
738 * - Vendor specific IE
739 * - WPA/WPA2 IE
740 * - HT Capabilities IE
741 * - HT Information IE
743 * Preparation also includes -
744 * - Setting command ID and proper size
745 * - Ensuring correct endian-ness
748 mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
749 struct host_cmd_ds_command *cmd,
750 struct mwifiex_802_11_ssid *req_ssid)
752 int rsn_ie_len = 0;
753 struct mwifiex_adapter *adapter = priv->adapter;
754 struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
755 &cmd->params.adhoc_start;
756 struct mwifiex_bssdescriptor *bss_desc;
757 u32 cmd_append_size = 0;
758 u32 i;
759 u16 tmp_cap;
760 uint16_t ht_cap_info;
761 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
763 struct mwifiex_ie_types_htcap *ht_cap;
764 struct mwifiex_ie_types_htinfo *ht_info;
765 u8 *pos = (u8 *) adhoc_start +
766 sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
768 if (!adapter)
769 return -1;
771 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
773 bss_desc = &priv->curr_bss_params.bss_descriptor;
774 priv->attempted_bss_desc = bss_desc;
777 * Fill in the parameters for 2 data structures:
778 * 1. struct host_cmd_ds_802_11_ad_hoc_start command
779 * 2. bss_desc
780 * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
781 * probe delay, and Cap info.
782 * Firmware will fill up beacon period, Basic rates
783 * and operational rates.
786 memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
788 memcpy(adhoc_start->ssid, req_ssid->ssid, req_ssid->ssid_len);
790 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
791 adhoc_start->ssid);
793 memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
794 memcpy(bss_desc->ssid.ssid, req_ssid->ssid, req_ssid->ssid_len);
796 bss_desc->ssid.ssid_len = req_ssid->ssid_len;
798 /* Set the BSS mode */
799 adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
800 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
801 adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
802 bss_desc->beacon_period = priv->beacon_period;
804 /* Set Physical param set */
805 /* Parameter IE Id */
806 #define DS_PARA_IE_ID 3
807 /* Parameter IE length */
808 #define DS_PARA_IE_LEN 1
810 adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
811 adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
813 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
814 (priv, adapter->adhoc_start_band, (u16)
815 priv->adhoc_channel)) {
816 struct mwifiex_chan_freq_power *cfp;
817 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
818 adapter->adhoc_start_band, FIRST_VALID_CHANNEL);
819 if (cfp)
820 priv->adhoc_channel = (u8) cfp->channel;
823 if (!priv->adhoc_channel) {
824 dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
825 return -1;
828 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
829 priv->adhoc_channel);
831 priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
832 priv->curr_bss_params.band = adapter->adhoc_start_band;
834 bss_desc->channel = priv->adhoc_channel;
835 adhoc_start->phy_param_set.ds_param_set.current_chan =
836 priv->adhoc_channel;
838 memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
839 sizeof(union ieee_types_phy_param_set));
841 /* Set IBSS param set */
842 /* IBSS parameter IE Id */
843 #define IBSS_PARA_IE_ID 6
844 /* IBSS parameter IE length */
845 #define IBSS_PARA_IE_LEN 2
847 adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
848 adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
849 adhoc_start->ss_param_set.ibss_param_set.atim_window
850 = cpu_to_le16(priv->atim_window);
851 memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
852 sizeof(union ieee_types_ss_param_set));
854 /* Set Capability info */
855 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
856 tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap);
857 tmp_cap &= ~WLAN_CAPABILITY_ESS;
858 tmp_cap |= WLAN_CAPABILITY_IBSS;
860 /* Set up privacy in bss_desc */
861 if (priv->sec_info.encryption_mode) {
862 /* Ad-Hoc capability privacy on */
863 dev_dbg(adapter->dev,
864 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
865 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
866 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
867 } else {
868 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
869 " setting privacy to ACCEPT ALL\n");
870 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
873 memset(adhoc_start->DataRate, 0, sizeof(adhoc_start->DataRate));
874 mwifiex_get_active_data_rates(priv, adhoc_start->DataRate);
875 if ((adapter->adhoc_start_band & BAND_G) &&
876 (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
877 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
878 HostCmd_ACT_GEN_SET, 0,
879 &priv->curr_pkt_filter)) {
880 dev_err(adapter->dev,
881 "ADHOC_S_CMD: G Protection config failed\n");
882 return -1;
885 /* Find the last non zero */
886 for (i = 0; i < sizeof(adhoc_start->DataRate) &&
887 adhoc_start->DataRate[i];
888 i++)
891 priv->curr_bss_params.num_of_rates = i;
893 /* Copy the ad-hoc creating rates into Current BSS rate structure */
894 memcpy(&priv->curr_bss_params.data_rates,
895 &adhoc_start->DataRate, priv->curr_bss_params.num_of_rates);
897 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n",
898 adhoc_start->DataRate[0], adhoc_start->DataRate[1],
899 adhoc_start->DataRate[2], adhoc_start->DataRate[3]);
901 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
903 if (IS_SUPPORT_MULTI_BANDS(adapter)) {
904 /* Append a channel TLV */
905 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
906 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
907 chan_tlv->header.len =
908 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
910 memset(chan_tlv->chan_scan_param, 0x00,
911 sizeof(struct mwifiex_chan_scan_param_set));
912 chan_tlv->chan_scan_param[0].chan_number =
913 (u8) priv->curr_bss_params.bss_descriptor.channel;
915 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
916 chan_tlv->chan_scan_param[0].chan_number);
918 chan_tlv->chan_scan_param[0].radio_type
919 = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
920 if (adapter->adhoc_start_band & BAND_GN
921 || adapter->adhoc_start_band & BAND_AN) {
922 if (adapter->chan_offset == SEC_CHANNEL_ABOVE)
923 chan_tlv->chan_scan_param[0].radio_type |=
924 SECOND_CHANNEL_ABOVE;
925 else if (adapter->chan_offset == SEC_CHANNEL_BELOW)
926 chan_tlv->chan_scan_param[0].radio_type |=
927 SECOND_CHANNEL_BELOW;
929 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
930 chan_tlv->chan_scan_param[0].radio_type);
931 pos += sizeof(chan_tlv->header) +
932 sizeof(struct mwifiex_chan_scan_param_set);
933 cmd_append_size +=
934 sizeof(chan_tlv->header) +
935 sizeof(struct mwifiex_chan_scan_param_set);
938 /* Append vendor specific IE TLV */
939 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
940 MWIFIEX_VSIE_MASK_ADHOC, &pos);
942 if (priv->sec_info.wpa_enabled) {
943 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
944 if (rsn_ie_len == -1)
945 return -1;
946 cmd_append_size += rsn_ie_len;
949 if (adapter->adhoc_11n_enabled) {
951 ht_cap = (struct mwifiex_ie_types_htcap *) pos;
952 memset(ht_cap, 0,
953 sizeof(struct mwifiex_ie_types_htcap));
954 ht_cap->header.type =
955 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
956 ht_cap->header.len =
957 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
958 ht_cap_info = le16_to_cpu(ht_cap->ht_cap.cap_info);
960 ht_cap_info |= IEEE80211_HT_CAP_SGI_20;
961 if (adapter->chan_offset) {
962 ht_cap_info |= IEEE80211_HT_CAP_SGI_40;
963 ht_cap_info |= IEEE80211_HT_CAP_DSSSCCK40;
964 ht_cap_info |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
965 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
968 ht_cap->ht_cap.ampdu_params_info
969 = IEEE80211_HT_MAX_AMPDU_64K;
970 ht_cap->ht_cap.mcs.rx_mask[0] = 0xff;
971 pos += sizeof(struct mwifiex_ie_types_htcap);
972 cmd_append_size +=
973 sizeof(struct mwifiex_ie_types_htcap);
976 ht_info = (struct mwifiex_ie_types_htinfo *) pos;
977 memset(ht_info, 0,
978 sizeof(struct mwifiex_ie_types_htinfo));
979 ht_info->header.type =
980 cpu_to_le16(WLAN_EID_HT_INFORMATION);
981 ht_info->header.len =
982 cpu_to_le16(sizeof(struct ieee80211_ht_info));
983 ht_info->ht_info.control_chan =
984 (u8) priv->curr_bss_params.bss_descriptor.
985 channel;
986 if (adapter->chan_offset) {
987 ht_info->ht_info.ht_param =
988 adapter->chan_offset;
989 ht_info->ht_info.ht_param |=
990 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
992 ht_info->ht_info.operation_mode =
993 cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
994 ht_info->ht_info.basic_set[0] = 0xff;
995 pos += sizeof(struct mwifiex_ie_types_htinfo);
996 cmd_append_size +=
997 sizeof(struct mwifiex_ie_types_htinfo);
1001 cmd->size = cpu_to_le16((u16)
1002 (sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
1003 + S_DS_GEN + cmd_append_size));
1005 if (adapter->adhoc_start_band == BAND_B)
1006 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
1007 else
1008 tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1010 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1012 return 0;
1016 * This function prepares command for ad-hoc join.
1018 * Most of the parameters are set up by copying from the target BSS descriptor
1019 * from the scan response.
1021 * In addition, the following TLVs are added -
1022 * - Channel TLV
1023 * - Vendor specific IE
1024 * - WPA/WPA2 IE
1025 * - 11n IE
1027 * Preparation also includes -
1028 * - Setting command ID and proper size
1029 * - Ensuring correct endian-ness
1032 mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1033 struct host_cmd_ds_command *cmd,
1034 struct mwifiex_bssdescriptor *bss_desc)
1036 int rsn_ie_len = 0;
1037 struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
1038 &cmd->params.adhoc_join;
1039 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
1040 u32 cmd_append_size = 0;
1041 u16 tmp_cap;
1042 u32 i, rates_size = 0;
1043 u16 curr_pkt_filter;
1044 u8 *pos =
1045 (u8 *) adhoc_join +
1046 sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
1048 /* Use G protection */
1049 #define USE_G_PROTECTION 0x02
1050 if (bss_desc->erp_flags & USE_G_PROTECTION) {
1051 curr_pkt_filter =
1052 priv->
1053 curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
1055 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
1056 HostCmd_ACT_GEN_SET, 0,
1057 &curr_pkt_filter)) {
1058 dev_err(priv->adapter->dev,
1059 "ADHOC_J_CMD: G Protection config failed\n");
1060 return -1;
1064 priv->attempted_bss_desc = bss_desc;
1066 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1068 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1070 adhoc_join->bss_descriptor.beacon_period
1071 = cpu_to_le16(bss_desc->beacon_period);
1073 memcpy(&adhoc_join->bss_descriptor.bssid,
1074 &bss_desc->mac_address, ETH_ALEN);
1076 memcpy(&adhoc_join->bss_descriptor.ssid,
1077 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1079 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1080 &bss_desc->phy_param_set,
1081 sizeof(union ieee_types_phy_param_set));
1083 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1084 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1086 tmp_cap = bss_desc->cap_info_bitmap;
1088 tmp_cap &= CAPINFO_MASK;
1090 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: tmp_cap=%4X"
1091 " CAPINFO_MASK=%4lX\n", tmp_cap, CAPINFO_MASK);
1093 /* Information on BSSID descriptor passed to FW */
1094 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID = %pM, SSID = %s\n",
1095 adhoc_join->bss_descriptor.bssid,
1096 adhoc_join->bss_descriptor.ssid);
1098 for (i = 0; bss_desc->supported_rates[i] &&
1099 i < MWIFIEX_SUPPORTED_RATES;
1100 i++)
1102 rates_size = i;
1104 /* Copy Data Rates from the Rates recorded in scan response */
1105 memset(adhoc_join->bss_descriptor.data_rates, 0,
1106 sizeof(adhoc_join->bss_descriptor.data_rates));
1107 memcpy(adhoc_join->bss_descriptor.data_rates,
1108 bss_desc->supported_rates, rates_size);
1110 /* Copy the adhoc join rates into Current BSS state structure */
1111 priv->curr_bss_params.num_of_rates = rates_size;
1112 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1113 rates_size);
1115 /* Copy the channel information */
1116 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1117 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1119 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED
1120 || priv->sec_info.wpa_enabled)
1121 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1123 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1124 /* Append a channel TLV */
1125 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1126 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1127 chan_tlv->header.len =
1128 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1130 memset(chan_tlv->chan_scan_param, 0x00,
1131 sizeof(struct mwifiex_chan_scan_param_set));
1132 chan_tlv->chan_scan_param[0].chan_number =
1133 (bss_desc->phy_param_set.ds_param_set.current_chan);
1134 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan = %d\n",
1135 chan_tlv->chan_scan_param[0].chan_number);
1137 chan_tlv->chan_scan_param[0].radio_type =
1138 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1140 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band = %d\n",
1141 chan_tlv->chan_scan_param[0].radio_type);
1142 pos += sizeof(chan_tlv->header) +
1143 sizeof(struct mwifiex_chan_scan_param_set);
1144 cmd_append_size += sizeof(chan_tlv->header) +
1145 sizeof(struct mwifiex_chan_scan_param_set);
1148 if (priv->sec_info.wpa_enabled)
1149 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1150 if (rsn_ie_len == -1)
1151 return -1;
1152 cmd_append_size += rsn_ie_len;
1154 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1155 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1156 bss_desc, &pos);
1158 /* Append vendor specific IE TLV */
1159 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1160 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1162 cmd->size = cpu_to_le16((u16)
1163 (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1164 + S_DS_GEN + cmd_append_size));
1166 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1168 return 0;
1172 * This function handles the command response of ad-hoc start and
1173 * ad-hoc join.
1175 * The function generates a device-connected event to notify
1176 * the applications, in case of successful ad-hoc start/join, and
1177 * saves the beacon buffer.
1179 int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
1180 struct host_cmd_ds_command *resp)
1182 int ret = 0;
1183 struct mwifiex_adapter *adapter = priv->adapter;
1184 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1185 struct mwifiex_bssdescriptor *bss_desc;
1187 adhoc_result = &resp->params.adhoc_result;
1189 bss_desc = priv->attempted_bss_desc;
1191 /* Join result code 0 --> SUCCESS */
1192 if (le16_to_cpu(resp->result)) {
1193 dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
1194 if (priv->media_connected)
1195 mwifiex_reset_connect_state(priv);
1197 memset(&priv->curr_bss_params.bss_descriptor,
1198 0x00, sizeof(struct mwifiex_bssdescriptor));
1200 ret = -1;
1201 goto done;
1204 /* Send a Media Connected event, according to the Spec */
1205 priv->media_connected = true;
1207 if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) {
1208 dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
1209 bss_desc->ssid.ssid);
1211 /* Update the created network descriptor with the new BSSID */
1212 memcpy(bss_desc->mac_address,
1213 adhoc_result->bssid, ETH_ALEN);
1215 priv->adhoc_state = ADHOC_STARTED;
1216 } else {
1218 * Now the join cmd should be successful.
1219 * If BSSID has changed use SSID to compare instead of BSSID
1221 dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
1222 bss_desc->ssid.ssid);
1225 * Make a copy of current BSSID descriptor, only needed for
1226 * join since the current descriptor is already being used
1227 * for adhoc start
1229 memcpy(&priv->curr_bss_params.bss_descriptor,
1230 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1232 priv->adhoc_state = ADHOC_JOINED;
1235 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
1236 priv->adhoc_channel);
1237 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
1238 priv->curr_bss_params.bss_descriptor.mac_address);
1240 if (!netif_carrier_ok(priv->netdev))
1241 netif_carrier_on(priv->netdev);
1242 if (netif_queue_stopped(priv->netdev))
1243 netif_wake_queue(priv->netdev);
1245 mwifiex_save_curr_bcn(priv);
1247 done:
1248 /* Need to indicate IOCTL complete */
1249 if (adapter->curr_cmd->wait_q_enabled) {
1250 if (ret)
1251 adapter->cmd_wait_q.status = -1;
1252 else
1253 adapter->cmd_wait_q.status = 0;
1257 return ret;
1261 * This function associates to a specific BSS discovered in a scan.
1263 * It clears any past association response stored for application
1264 * retrieval and calls the command preparation routine to send the
1265 * command to firmware.
1267 int mwifiex_associate(struct mwifiex_private *priv,
1268 struct mwifiex_bssdescriptor *bss_desc)
1270 u8 current_bssid[ETH_ALEN];
1272 /* Return error if the adapter or table entry is not marked as infra */
1273 if ((priv->bss_mode != NL80211_IFTYPE_STATION) ||
1274 (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
1275 return -1;
1277 memcpy(&current_bssid,
1278 &priv->curr_bss_params.bss_descriptor.mac_address,
1279 sizeof(current_bssid));
1281 /* Clear any past association response stored for application
1282 retrieval */
1283 priv->assoc_rsp_size = 0;
1285 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_ASSOCIATE,
1286 HostCmd_ACT_GEN_SET, 0, bss_desc);
1290 * This function starts an ad-hoc network.
1292 * It calls the command preparation routine to send the command to firmware.
1295 mwifiex_adhoc_start(struct mwifiex_private *priv,
1296 struct mwifiex_802_11_ssid *adhoc_ssid)
1298 dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
1299 priv->adhoc_channel);
1300 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1301 priv->curr_bss_params.bss_descriptor.channel);
1302 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
1303 priv->curr_bss_params.band);
1305 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_START,
1306 HostCmd_ACT_GEN_SET, 0, adhoc_ssid);
1310 * This function joins an ad-hoc network found in a previous scan.
1312 * It calls the command preparation routine to send the command to firmware,
1313 * if already not connected to the requested SSID.
1315 int mwifiex_adhoc_join(struct mwifiex_private *priv,
1316 struct mwifiex_bssdescriptor *bss_desc)
1318 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
1319 priv->curr_bss_params.bss_descriptor.ssid.ssid);
1320 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
1321 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
1322 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
1323 bss_desc->ssid.ssid);
1324 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
1325 bss_desc->ssid.ssid_len);
1327 /* Check if the requested SSID is already joined */
1328 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1329 !mwifiex_ssid_cmp(&bss_desc->ssid,
1330 &priv->curr_bss_params.bss_descriptor.ssid) &&
1331 (priv->curr_bss_params.bss_descriptor.bss_mode ==
1332 NL80211_IFTYPE_ADHOC)) {
1333 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
1334 " is the same as current; not attempting to re-join\n");
1335 return -1;
1338 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1339 priv->curr_bss_params.bss_descriptor.channel);
1340 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
1341 priv->curr_bss_params.band);
1343 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
1344 HostCmd_ACT_GEN_SET, 0, bss_desc);
1348 * This function deauthenticates/disconnects from infra network by sending
1349 * deauthentication request.
1351 static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
1353 u8 mac_address[ETH_ALEN];
1354 int ret;
1355 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
1357 if (mac) {
1358 if (!memcmp(mac, zero_mac, sizeof(zero_mac)))
1359 memcpy((u8 *) &mac_address,
1360 (u8 *) &priv->curr_bss_params.bss_descriptor.
1361 mac_address, ETH_ALEN);
1362 else
1363 memcpy((u8 *) &mac_address, (u8 *) mac, ETH_ALEN);
1364 } else {
1365 memcpy((u8 *) &mac_address, (u8 *) &priv->curr_bss_params.
1366 bss_descriptor.mac_address, ETH_ALEN);
1369 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
1370 HostCmd_ACT_GEN_SET, 0, &mac_address);
1372 return ret;
1376 * This function deauthenticates/disconnects from a BSS.
1378 * In case of infra made, it sends deauthentication request, and
1379 * in case of ad-hoc mode, a stop network request is sent to the firmware.
1381 int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
1383 int ret = 0;
1385 if (priv->media_connected) {
1386 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1387 ret = mwifiex_deauthenticate_infra(priv, mac);
1388 } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1389 ret = mwifiex_send_cmd_sync(priv,
1390 HostCmd_CMD_802_11_AD_HOC_STOP,
1391 HostCmd_ACT_GEN_SET, 0, NULL);
1395 return ret;
1397 EXPORT_SYMBOL_GPL(mwifiex_deauthenticate);
1400 * This function converts band to radio type used in channel TLV.
1403 mwifiex_band_to_radio_type(u8 band)
1405 switch (band) {
1406 case BAND_A:
1407 case BAND_AN:
1408 case BAND_A | BAND_AN:
1409 return HostCmd_SCAN_RADIO_TYPE_A;
1410 case BAND_B:
1411 case BAND_G:
1412 case BAND_B | BAND_G:
1413 default:
1414 return HostCmd_SCAN_RADIO_TYPE_BG;