mwifiex: fix missing tsf_val TLV
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / mwifiex / join.c
blob85fca5eb4195f5c9a7f268247b5dec685d212d82
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 = 0;
147 u8 *ptr = rate1;
148 u8 *tmp = NULL;
149 u32 i, j;
151 tmp = kmalloc(rate1_size, GFP_KERNEL);
152 if (!tmp) {
153 dev_err(priv->adapter->dev, "failed to alloc tmp buf\n");
154 return -ENOMEM;
157 memcpy(tmp, rate1, rate1_size);
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
163 basic rate */
164 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) {
165 *rate1++ = tmp[j];
166 break;
171 dev_dbg(priv->adapter->dev, "info: Tx data rate set to %#x\n",
172 priv->data_rate);
174 if (!priv->is_data_rate_auto) {
175 while (*ptr) {
176 if ((*ptr & 0x7f) == priv->data_rate) {
177 ret = 0;
178 goto done;
180 ptr++;
182 dev_err(priv->adapter->dev, "previously set fixed data rate %#x"
183 " is not compatible with the network\n",
184 priv->data_rate);
186 ret = -1;
187 goto done;
190 ret = 0;
191 done:
192 kfree(tmp);
193 return ret;
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.
200 static int
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];
206 u32 card_rates_size = 0;
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)) {
215 *out_rates_size = 0;
216 dev_err(priv->adapter->dev, "%s: cannot get common rates\n",
217 __func__);
218 return -1;
221 *out_rates_size =
222 min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES);
224 return 0;
228 * This function updates the scan entry TSF timestamps to reflect
229 * a new association.
231 static void
232 mwifiex_update_tsf_timestamps(struct mwifiex_private *priv,
233 struct mwifiex_bssdescriptor *new_bss_desc)
235 struct mwifiex_adapter *adapter = priv->adapter;
236 u32 table_idx;
237 long long new_tsf_base;
238 signed long long tsf_delta;
240 memcpy(&new_tsf_base, new_bss_desc->time_stamp, sizeof(new_tsf_base));
242 tsf_delta = new_tsf_base - new_bss_desc->network_tsf;
244 dev_dbg(adapter->dev, "info: TSF: update TSF timestamps, "
245 "0x%016llx -> 0x%016llx\n",
246 new_bss_desc->network_tsf, new_tsf_base);
248 for (table_idx = 0; table_idx < adapter->num_in_scan_table;
249 table_idx++)
250 adapter->scan_table[table_idx].network_tsf += tsf_delta;
254 * This function appends a WAPI IE.
256 * This function is called from the network join command preparation routine.
258 * If the IE buffer has been setup by the application, this routine appends
259 * the buffer as a WAPI TLV type to the request.
261 static int
262 mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer)
264 int retLen = 0;
265 struct mwifiex_ie_types_header ie_header;
267 /* Null Checks */
268 if (buffer == NULL)
269 return 0;
270 if (*buffer == NULL)
271 return 0;
274 * If there is a wapi ie buffer setup, append it to the return
275 * parameter buffer pointer.
277 if (priv->wapi_ie_len) {
278 dev_dbg(priv->adapter->dev, "cmd: append wapi ie %d to %p\n",
279 priv->wapi_ie_len, *buffer);
281 /* Wrap the generic IE buffer with a pass through TLV type */
282 ie_header.type = cpu_to_le16(TLV_TYPE_WAPI_IE);
283 ie_header.len = cpu_to_le16(priv->wapi_ie_len);
284 memcpy(*buffer, &ie_header, sizeof(ie_header));
286 /* Increment the return size and the return buffer pointer
287 param */
288 *buffer += sizeof(ie_header);
289 retLen += sizeof(ie_header);
291 /* Copy the wapi IE buffer to the output buffer, advance
292 pointer */
293 memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len);
295 /* Increment the return size and the return buffer pointer
296 param */
297 *buffer += priv->wapi_ie_len;
298 retLen += priv->wapi_ie_len;
301 /* return the length appended to the buffer */
302 return retLen;
306 * This function appends rsn ie tlv for wpa/wpa2 security modes.
307 * It is called from the network join command preparation routine.
309 static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private *priv,
310 u8 **buffer)
312 struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv;
313 int rsn_ie_len;
315 if (!buffer || !(*buffer))
316 return 0;
318 rsn_ie_tlv = (struct mwifiex_ie_types_rsn_param_set *) (*buffer);
319 rsn_ie_tlv->header.type = cpu_to_le16((u16) priv->wpa_ie[0]);
320 rsn_ie_tlv->header.type = cpu_to_le16(
321 le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF);
322 rsn_ie_tlv->header.len = cpu_to_le16((u16) priv->wpa_ie[1]);
323 rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len)
324 & 0x00FF);
325 if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2))
326 memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2],
327 le16_to_cpu(rsn_ie_tlv->header.len));
328 else
329 return -1;
331 rsn_ie_len = sizeof(rsn_ie_tlv->header) +
332 le16_to_cpu(rsn_ie_tlv->header.len);
333 *buffer += rsn_ie_len;
335 return rsn_ie_len;
339 * This function prepares command for association.
341 * This sets the following parameters -
342 * - Peer MAC address
343 * - Listen interval
344 * - Beacon interval
345 * - Capability information
347 * ...and the following TLVs, as required -
348 * - SSID TLV
349 * - PHY TLV
350 * - SS TLV
351 * - Rates TLV
352 * - Authentication TLV
353 * - Channel TLV
354 * - WPA/WPA2 IE
355 * - 11n TLV
356 * - Vendor specific TLV
357 * - WMM TLV
358 * - WAPI IE
359 * - Generic IE
360 * - TSF TLV
362 * Preparation also includes -
363 * - Setting command ID and proper size
364 * - Ensuring correct endian-ness
366 int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
367 struct host_cmd_ds_command *cmd,
368 void *data_buf)
370 struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate;
371 struct mwifiex_bssdescriptor *bss_desc;
372 struct mwifiex_ie_types_ssid_param_set *ssid_tlv;
373 struct mwifiex_ie_types_phy_param_set *phy_tlv;
374 struct mwifiex_ie_types_ss_param_set *ss_tlv;
375 struct mwifiex_ie_types_rates_param_set *rates_tlv;
376 struct mwifiex_ie_types_auth_type *auth_tlv;
377 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
378 u8 rates[MWIFIEX_SUPPORTED_RATES];
379 u32 rates_size;
380 u16 tmp_cap;
381 u8 *pos;
382 int rsn_ie_len = 0;
384 bss_desc = (struct mwifiex_bssdescriptor *) data_buf;
385 pos = (u8 *) assoc;
387 mwifiex_cfg_tx_buf(priv, bss_desc);
389 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
391 /* Save so we know which BSS Desc to use in the response handler */
392 priv->attempted_bss_desc = bss_desc;
394 memcpy(assoc->peer_sta_addr,
395 bss_desc->mac_address, sizeof(assoc->peer_sta_addr));
396 pos += sizeof(assoc->peer_sta_addr);
398 /* Set the listen interval */
399 assoc->listen_interval = cpu_to_le16(priv->listen_interval);
400 /* Set the beacon period */
401 assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period);
403 pos += sizeof(assoc->cap_info_bitmap);
404 pos += sizeof(assoc->listen_interval);
405 pos += sizeof(assoc->beacon_period);
406 pos += sizeof(assoc->dtim_period);
408 ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos;
409 ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID);
410 ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len);
411 memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid,
412 le16_to_cpu(ssid_tlv->header.len));
413 pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len);
415 phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos;
416 phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS);
417 phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set));
418 memcpy(&phy_tlv->fh_ds.ds_param_set,
419 &bss_desc->phy_param_set.ds_param_set.current_chan,
420 sizeof(phy_tlv->fh_ds.ds_param_set));
421 pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len);
423 ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos;
424 ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS);
425 ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set));
426 pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len);
428 /* Get the common rates supported between the driver and the BSS Desc */
429 if (mwifiex_setup_rates_from_bssdesc
430 (priv, bss_desc, rates, &rates_size))
431 return -1;
433 /* Save the data rates into Current BSS state structure */
434 priv->curr_bss_params.num_of_rates = rates_size;
435 memcpy(&priv->curr_bss_params.data_rates, rates, rates_size);
437 /* Setup the Rates TLV in the association command */
438 rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos;
439 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
440 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
441 memcpy(rates_tlv->rates, rates, rates_size);
442 pos += sizeof(rates_tlv->header) + rates_size;
443 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: rates size = %d\n",
444 rates_size);
446 /* Add the Authentication type to be used for Auth frames */
447 auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
448 auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
449 auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
450 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
451 auth_tlv->auth_type = cpu_to_le16(
452 (u16) priv->sec_info.authentication_mode);
453 else
454 auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM);
456 pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len);
458 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)
459 && !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
460 && (!bss_desc->disable_11n)
461 && (priv->adapter->config_bands & BAND_GN
462 || priv->adapter->config_bands & BAND_AN)
463 && (bss_desc->bcn_ht_cap)
466 /* Append a channel TLV for the channel the attempted AP was
467 found on */
468 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
469 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
470 chan_tlv->header.len =
471 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
473 memset(chan_tlv->chan_scan_param, 0x00,
474 sizeof(struct mwifiex_chan_scan_param_set));
475 chan_tlv->chan_scan_param[0].chan_number =
476 (bss_desc->phy_param_set.ds_param_set.current_chan);
477 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
478 chan_tlv->chan_scan_param[0].chan_number);
480 chan_tlv->chan_scan_param[0].radio_type =
481 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
483 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
484 chan_tlv->chan_scan_param[0].radio_type);
485 pos += sizeof(chan_tlv->header) +
486 sizeof(struct mwifiex_chan_scan_param_set);
489 if (!priv->wps.session_enable) {
490 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
491 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
493 if (rsn_ie_len == -1)
494 return -1;
497 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
498 && (!bss_desc->disable_11n)
499 && (priv->adapter->config_bands & BAND_GN
500 || priv->adapter->config_bands & BAND_AN))
501 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
503 /* Append vendor specific IE TLV */
504 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
506 mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
507 bss_desc->bcn_ht_cap);
508 if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
509 mwifiex_cmd_append_wapi_ie(priv, &pos);
512 mwifiex_cmd_append_generic_ie(priv, &pos);
514 mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
516 cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
518 /* Set the Capability info at last */
519 tmp_cap = bss_desc->cap_info_bitmap;
521 if (priv->adapter->config_bands == BAND_B)
522 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
524 tmp_cap &= CAPINFO_MASK;
525 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
526 tmp_cap, CAPINFO_MASK);
527 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
529 return 0;
533 * Association firmware command response handler
535 * The response buffer for the association command has the following
536 * memory layout.
538 * For cases where an association response was not received (indicated
539 * by the CapInfo and AId field):
541 * .------------------------------------------------------------.
542 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
543 * .------------------------------------------------------------.
544 * | cap_info/Error Return(t_u16): |
545 * | 0xFFFF(-1): Internal error |
546 * | 0xFFFE(-2): Authentication unhandled message |
547 * | 0xFFFD(-3): Authentication refused |
548 * | 0xFFFC(-4): Timeout waiting for AP response |
549 * .------------------------------------------------------------.
550 * | status_code(t_u16): |
551 * | If cap_info is -1: |
552 * | An internal firmware failure prevented the |
553 * | command from being processed. The status_code |
554 * | will be set to 1. |
555 * | |
556 * | If cap_info is -2: |
557 * | An authentication frame was received but was |
558 * | not handled by the firmware. IEEE Status |
559 * | code for the failure is returned. |
560 * | |
561 * | If cap_info is -3: |
562 * | An authentication frame was received and the |
563 * | status_code is the IEEE Status reported in the |
564 * | response. |
565 * | |
566 * | If cap_info is -4: |
567 * | (1) Association response timeout |
568 * | (2) Authentication response timeout |
569 * .------------------------------------------------------------.
570 * | a_id(t_u16): 0xFFFF |
571 * .------------------------------------------------------------.
574 * For cases where an association response was received, the IEEE
575 * standard association response frame is returned:
577 * .------------------------------------------------------------.
578 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
579 * .------------------------------------------------------------.
580 * | cap_info(t_u16): IEEE Capability |
581 * .------------------------------------------------------------.
582 * | status_code(t_u16): IEEE Status Code |
583 * .------------------------------------------------------------.
584 * | a_id(t_u16): IEEE Association ID |
585 * .------------------------------------------------------------.
586 * | IEEE IEs(variable): Any received IEs comprising the |
587 * | remaining portion of a received |
588 * | association response frame. |
589 * .------------------------------------------------------------.
591 * For simplistic handling, the status_code field can be used to determine
592 * an association success (0) or failure (non-zero).
594 int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
595 struct host_cmd_ds_command *resp)
597 struct mwifiex_adapter *adapter = priv->adapter;
598 int ret = 0;
599 struct ieee_types_assoc_rsp *assoc_rsp;
600 struct mwifiex_bssdescriptor *bss_desc;
601 u8 enable_data = true;
603 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
605 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
606 sizeof(priv->assoc_rsp_buf));
608 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
610 if (le16_to_cpu(assoc_rsp->status_code)) {
611 priv->adapter->dbg.num_cmd_assoc_failure++;
612 dev_err(priv->adapter->dev, "ASSOC_RESP: association failed, "
613 "status code = %d, error = 0x%x, a_id = 0x%x\n",
614 le16_to_cpu(assoc_rsp->status_code),
615 le16_to_cpu(assoc_rsp->cap_info_bitmap),
616 le16_to_cpu(assoc_rsp->a_id));
618 ret = -1;
619 goto done;
622 /* Send a Media Connected event, according to the Spec */
623 priv->media_connected = true;
625 priv->adapter->ps_state = PS_STATE_AWAKE;
626 priv->adapter->pps_uapsd_mode = false;
627 priv->adapter->tx_lock_flag = false;
629 /* Set the attempted BSSID Index to current */
630 bss_desc = priv->attempted_bss_desc;
632 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n",
633 bss_desc->ssid.ssid);
635 /* Make a copy of current BSSID descriptor */
636 memcpy(&priv->curr_bss_params.bss_descriptor,
637 bss_desc, sizeof(struct mwifiex_bssdescriptor));
639 /* Update curr_bss_params */
640 priv->curr_bss_params.bss_descriptor.channel
641 = bss_desc->phy_param_set.ds_param_set.current_chan;
643 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
646 * Adjust the timestamps in the scan table to be relative to the newly
647 * associated AP's TSF
649 mwifiex_update_tsf_timestamps(priv, bss_desc);
651 if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
652 priv->curr_bss_params.wmm_enabled = true;
653 else
654 priv->curr_bss_params.wmm_enabled = false;
656 if ((priv->wmm_required || bss_desc->bcn_ht_cap)
657 && priv->curr_bss_params.wmm_enabled)
658 priv->wmm_enabled = true;
659 else
660 priv->wmm_enabled = false;
662 priv->curr_bss_params.wmm_uapsd_enabled = false;
664 if (priv->wmm_enabled)
665 priv->curr_bss_params.wmm_uapsd_enabled
666 = ((bss_desc->wmm_ie.qos_info_bitmap &
667 IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
669 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
670 priv->curr_pkt_filter);
671 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
672 priv->wpa_is_gtk_set = false;
674 if (priv->wmm_enabled) {
675 /* Don't re-enable carrier until we get the WMM_GET_STATUS
676 event */
677 enable_data = false;
678 } else {
679 /* Since WMM is not enabled, setup the queues with the
680 defaults */
681 mwifiex_wmm_setup_queue_priorities(priv, NULL);
682 mwifiex_wmm_setup_ac_downgrade(priv);
685 if (enable_data)
686 dev_dbg(priv->adapter->dev,
687 "info: post association, re-enabling data flow\n");
689 /* Reset SNR/NF/RSSI values */
690 priv->data_rssi_last = 0;
691 priv->data_nf_last = 0;
692 priv->data_rssi_avg = 0;
693 priv->data_nf_avg = 0;
694 priv->bcn_rssi_last = 0;
695 priv->bcn_nf_last = 0;
696 priv->bcn_rssi_avg = 0;
697 priv->bcn_nf_avg = 0;
698 priv->rxpd_rate = 0;
699 priv->rxpd_htinfo = 0;
701 mwifiex_save_curr_bcn(priv);
703 priv->adapter->dbg.num_cmd_assoc_success++;
705 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n");
707 /* Add the ra_list here for infra mode as there will be only 1 ra
708 always */
709 mwifiex_ralist_add(priv,
710 priv->curr_bss_params.bss_descriptor.mac_address);
712 if (!netif_carrier_ok(priv->netdev))
713 netif_carrier_on(priv->netdev);
714 if (netif_queue_stopped(priv->netdev))
715 netif_wake_queue(priv->netdev);
717 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
718 priv->scan_block = true;
720 done:
721 /* Need to indicate IOCTL complete */
722 if (adapter->curr_cmd->wait_q_enabled) {
723 if (ret)
724 adapter->cmd_wait_q.status = -1;
725 else
726 adapter->cmd_wait_q.status = 0;
729 return ret;
733 * This function prepares command for ad-hoc start.
735 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
736 * parameters, probe delay, and capability information. Firmware
737 * will fill up beacon period, basic rates and operational rates.
739 * In addition, the following TLVs are added -
740 * - Channel TLV
741 * - Vendor specific IE
742 * - WPA/WPA2 IE
743 * - HT Capabilities IE
744 * - HT Information IE
746 * Preparation also includes -
747 * - Setting command ID and proper size
748 * - Ensuring correct endian-ness
751 mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
752 struct host_cmd_ds_command *cmd, void *data_buf)
754 int rsn_ie_len = 0;
755 struct mwifiex_adapter *adapter = priv->adapter;
756 struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
757 &cmd->params.adhoc_start;
758 struct mwifiex_bssdescriptor *bss_desc;
759 u32 cmd_append_size = 0;
760 u32 i;
761 u16 tmp_cap;
762 uint16_t ht_cap_info;
763 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
765 struct mwifiex_ie_types_htcap *ht_cap;
766 struct mwifiex_ie_types_htinfo *ht_info;
767 u8 *pos = (u8 *) adhoc_start +
768 sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
770 if (!adapter)
771 return -1;
773 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
775 bss_desc = &priv->curr_bss_params.bss_descriptor;
776 priv->attempted_bss_desc = bss_desc;
779 * Fill in the parameters for 2 data structures:
780 * 1. struct host_cmd_ds_802_11_ad_hoc_start command
781 * 2. bss_desc
782 * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
783 * probe delay, and Cap info.
784 * Firmware will fill up beacon period, Basic rates
785 * and operational rates.
788 memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
790 memcpy(adhoc_start->ssid,
791 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
792 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
794 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
795 adhoc_start->ssid);
797 memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
798 memcpy(bss_desc->ssid.ssid,
799 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
800 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
802 bss_desc->ssid.ssid_len =
803 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len;
805 /* Set the BSS mode */
806 adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
807 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
808 adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
809 bss_desc->beacon_period = priv->beacon_period;
811 /* Set Physical param set */
812 /* Parameter IE Id */
813 #define DS_PARA_IE_ID 3
814 /* Parameter IE length */
815 #define DS_PARA_IE_LEN 1
817 adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
818 adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
820 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
821 (priv, adapter->adhoc_start_band, (u16)
822 priv->adhoc_channel)) {
823 struct mwifiex_chan_freq_power *cfp;
824 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
825 adapter->adhoc_start_band, FIRST_VALID_CHANNEL);
826 if (cfp)
827 priv->adhoc_channel = (u8) cfp->channel;
830 if (!priv->adhoc_channel) {
831 dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
832 return -1;
835 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
836 priv->adhoc_channel);
838 priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
839 priv->curr_bss_params.band = adapter->adhoc_start_band;
841 bss_desc->channel = priv->adhoc_channel;
842 adhoc_start->phy_param_set.ds_param_set.current_chan =
843 priv->adhoc_channel;
845 memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
846 sizeof(union ieee_types_phy_param_set));
848 /* Set IBSS param set */
849 /* IBSS parameter IE Id */
850 #define IBSS_PARA_IE_ID 6
851 /* IBSS parameter IE length */
852 #define IBSS_PARA_IE_LEN 2
854 adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
855 adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
856 adhoc_start->ss_param_set.ibss_param_set.atim_window
857 = cpu_to_le16(priv->atim_window);
858 memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
859 sizeof(union ieee_types_ss_param_set));
861 /* Set Capability info */
862 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
863 tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap);
864 tmp_cap &= ~WLAN_CAPABILITY_ESS;
865 tmp_cap |= WLAN_CAPABILITY_IBSS;
867 /* Set up privacy in bss_desc */
868 if (priv->sec_info.encryption_mode) {
869 /* Ad-Hoc capability privacy on */
870 dev_dbg(adapter->dev,
871 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
872 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
873 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
874 } else {
875 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
876 " setting privacy to ACCEPT ALL\n");
877 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
880 memset(adhoc_start->DataRate, 0, sizeof(adhoc_start->DataRate));
881 mwifiex_get_active_data_rates(priv, adhoc_start->DataRate);
882 if ((adapter->adhoc_start_band & BAND_G) &&
883 (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
884 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
885 HostCmd_ACT_GEN_SET, 0,
886 &priv->curr_pkt_filter)) {
887 dev_err(adapter->dev,
888 "ADHOC_S_CMD: G Protection config failed\n");
889 return -1;
892 /* Find the last non zero */
893 for (i = 0; i < sizeof(adhoc_start->DataRate) &&
894 adhoc_start->DataRate[i];
895 i++)
898 priv->curr_bss_params.num_of_rates = i;
900 /* Copy the ad-hoc creating rates into Current BSS rate structure */
901 memcpy(&priv->curr_bss_params.data_rates,
902 &adhoc_start->DataRate, priv->curr_bss_params.num_of_rates);
904 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n",
905 adhoc_start->DataRate[0], adhoc_start->DataRate[1],
906 adhoc_start->DataRate[2], adhoc_start->DataRate[3]);
908 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
910 if (IS_SUPPORT_MULTI_BANDS(adapter)) {
911 /* Append a channel TLV */
912 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
913 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
914 chan_tlv->header.len =
915 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
917 memset(chan_tlv->chan_scan_param, 0x00,
918 sizeof(struct mwifiex_chan_scan_param_set));
919 chan_tlv->chan_scan_param[0].chan_number =
920 (u8) priv->curr_bss_params.bss_descriptor.channel;
922 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
923 chan_tlv->chan_scan_param[0].chan_number);
925 chan_tlv->chan_scan_param[0].radio_type
926 = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
927 if (adapter->adhoc_start_band & BAND_GN
928 || adapter->adhoc_start_band & BAND_AN) {
929 if (adapter->chan_offset == SEC_CHANNEL_ABOVE)
930 chan_tlv->chan_scan_param[0].radio_type |=
931 SECOND_CHANNEL_ABOVE;
932 else if (adapter->chan_offset == SEC_CHANNEL_BELOW)
933 chan_tlv->chan_scan_param[0].radio_type |=
934 SECOND_CHANNEL_BELOW;
936 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
937 chan_tlv->chan_scan_param[0].radio_type);
938 pos += sizeof(chan_tlv->header) +
939 sizeof(struct mwifiex_chan_scan_param_set);
940 cmd_append_size +=
941 sizeof(chan_tlv->header) +
942 sizeof(struct mwifiex_chan_scan_param_set);
945 /* Append vendor specific IE TLV */
946 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
947 MWIFIEX_VSIE_MASK_ADHOC, &pos);
949 if (priv->sec_info.wpa_enabled) {
950 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
951 if (rsn_ie_len == -1)
952 return -1;
953 cmd_append_size += rsn_ie_len;
956 if (adapter->adhoc_11n_enabled) {
958 ht_cap = (struct mwifiex_ie_types_htcap *) pos;
959 memset(ht_cap, 0,
960 sizeof(struct mwifiex_ie_types_htcap));
961 ht_cap->header.type =
962 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
963 ht_cap->header.len =
964 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
965 ht_cap_info = le16_to_cpu(ht_cap->ht_cap.cap_info);
967 ht_cap_info |= IEEE80211_HT_CAP_SGI_20;
968 if (adapter->chan_offset) {
969 ht_cap_info |= IEEE80211_HT_CAP_SGI_40;
970 ht_cap_info |= IEEE80211_HT_CAP_DSSSCCK40;
971 ht_cap_info |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
972 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
975 ht_cap->ht_cap.ampdu_params_info
976 = IEEE80211_HT_MAX_AMPDU_64K;
977 ht_cap->ht_cap.mcs.rx_mask[0] = 0xff;
978 pos += sizeof(struct mwifiex_ie_types_htcap);
979 cmd_append_size +=
980 sizeof(struct mwifiex_ie_types_htcap);
983 ht_info = (struct mwifiex_ie_types_htinfo *) pos;
984 memset(ht_info, 0,
985 sizeof(struct mwifiex_ie_types_htinfo));
986 ht_info->header.type =
987 cpu_to_le16(WLAN_EID_HT_INFORMATION);
988 ht_info->header.len =
989 cpu_to_le16(sizeof(struct ieee80211_ht_info));
990 ht_info->ht_info.control_chan =
991 (u8) priv->curr_bss_params.bss_descriptor.
992 channel;
993 if (adapter->chan_offset) {
994 ht_info->ht_info.ht_param =
995 adapter->chan_offset;
996 ht_info->ht_info.ht_param |=
997 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
999 ht_info->ht_info.operation_mode =
1000 cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1001 ht_info->ht_info.basic_set[0] = 0xff;
1002 pos += sizeof(struct mwifiex_ie_types_htinfo);
1003 cmd_append_size +=
1004 sizeof(struct mwifiex_ie_types_htinfo);
1008 cmd->size = cpu_to_le16((u16)
1009 (sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
1010 + S_DS_GEN + cmd_append_size));
1012 if (adapter->adhoc_start_band == BAND_B)
1013 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
1014 else
1015 tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1017 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1019 return 0;
1023 * This function prepares command for ad-hoc join.
1025 * Most of the parameters are set up by copying from the target BSS descriptor
1026 * from the scan response.
1028 * In addition, the following TLVs are added -
1029 * - Channel TLV
1030 * - Vendor specific IE
1031 * - WPA/WPA2 IE
1032 * - 11n IE
1034 * Preparation also includes -
1035 * - Setting command ID and proper size
1036 * - Ensuring correct endian-ness
1039 mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1040 struct host_cmd_ds_command *cmd, void *data_buf)
1042 int rsn_ie_len = 0;
1043 struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
1044 &cmd->params.adhoc_join;
1045 struct mwifiex_bssdescriptor *bss_desc =
1046 (struct mwifiex_bssdescriptor *) data_buf;
1047 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
1048 u32 cmd_append_size = 0;
1049 u16 tmp_cap;
1050 u32 i, rates_size = 0;
1051 u16 curr_pkt_filter;
1052 u8 *pos =
1053 (u8 *) adhoc_join +
1054 sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
1056 /* Use G protection */
1057 #define USE_G_PROTECTION 0x02
1058 if (bss_desc->erp_flags & USE_G_PROTECTION) {
1059 curr_pkt_filter =
1060 priv->
1061 curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
1063 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
1064 HostCmd_ACT_GEN_SET, 0,
1065 &curr_pkt_filter)) {
1066 dev_err(priv->adapter->dev,
1067 "ADHOC_J_CMD: G Protection config failed\n");
1068 return -1;
1072 priv->attempted_bss_desc = bss_desc;
1074 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1076 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1078 adhoc_join->bss_descriptor.beacon_period
1079 = cpu_to_le16(bss_desc->beacon_period);
1081 memcpy(&adhoc_join->bss_descriptor.bssid,
1082 &bss_desc->mac_address, ETH_ALEN);
1084 memcpy(&adhoc_join->bss_descriptor.ssid,
1085 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1087 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1088 &bss_desc->phy_param_set,
1089 sizeof(union ieee_types_phy_param_set));
1091 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1092 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1094 tmp_cap = bss_desc->cap_info_bitmap;
1096 tmp_cap &= CAPINFO_MASK;
1098 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: tmp_cap=%4X"
1099 " CAPINFO_MASK=%4lX\n", tmp_cap, CAPINFO_MASK);
1101 /* Information on BSSID descriptor passed to FW */
1102 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID = %pM, SSID = %s\n",
1103 adhoc_join->bss_descriptor.bssid,
1104 adhoc_join->bss_descriptor.ssid);
1106 for (i = 0; bss_desc->supported_rates[i] &&
1107 i < MWIFIEX_SUPPORTED_RATES;
1108 i++)
1110 rates_size = i;
1112 /* Copy Data Rates from the Rates recorded in scan response */
1113 memset(adhoc_join->bss_descriptor.data_rates, 0,
1114 sizeof(adhoc_join->bss_descriptor.data_rates));
1115 memcpy(adhoc_join->bss_descriptor.data_rates,
1116 bss_desc->supported_rates, rates_size);
1118 /* Copy the adhoc join rates into Current BSS state structure */
1119 priv->curr_bss_params.num_of_rates = rates_size;
1120 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1121 rates_size);
1123 /* Copy the channel information */
1124 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1125 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1127 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED
1128 || priv->sec_info.wpa_enabled)
1129 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1131 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1132 /* Append a channel TLV */
1133 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1134 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1135 chan_tlv->header.len =
1136 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1138 memset(chan_tlv->chan_scan_param, 0x00,
1139 sizeof(struct mwifiex_chan_scan_param_set));
1140 chan_tlv->chan_scan_param[0].chan_number =
1141 (bss_desc->phy_param_set.ds_param_set.current_chan);
1142 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan = %d\n",
1143 chan_tlv->chan_scan_param[0].chan_number);
1145 chan_tlv->chan_scan_param[0].radio_type =
1146 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1148 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band = %d\n",
1149 chan_tlv->chan_scan_param[0].radio_type);
1150 pos += sizeof(chan_tlv->header) +
1151 sizeof(struct mwifiex_chan_scan_param_set);
1152 cmd_append_size += sizeof(chan_tlv->header) +
1153 sizeof(struct mwifiex_chan_scan_param_set);
1156 if (priv->sec_info.wpa_enabled)
1157 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1158 if (rsn_ie_len == -1)
1159 return -1;
1160 cmd_append_size += rsn_ie_len;
1162 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1163 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1164 bss_desc, &pos);
1166 /* Append vendor specific IE TLV */
1167 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1168 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1170 cmd->size = cpu_to_le16((u16)
1171 (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1172 + S_DS_GEN + cmd_append_size));
1174 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1176 return 0;
1180 * This function handles the command response of ad-hoc start and
1181 * ad-hoc join.
1183 * The function generates a device-connected event to notify
1184 * the applications, in case of successful ad-hoc start/join, and
1185 * saves the beacon buffer.
1187 int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
1188 struct host_cmd_ds_command *resp)
1190 int ret = 0;
1191 struct mwifiex_adapter *adapter = priv->adapter;
1192 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1193 struct mwifiex_bssdescriptor *bss_desc;
1195 adhoc_result = &resp->params.adhoc_result;
1197 bss_desc = priv->attempted_bss_desc;
1199 /* Join result code 0 --> SUCCESS */
1200 if (le16_to_cpu(resp->result)) {
1201 dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
1202 if (priv->media_connected)
1203 mwifiex_reset_connect_state(priv);
1205 memset(&priv->curr_bss_params.bss_descriptor,
1206 0x00, sizeof(struct mwifiex_bssdescriptor));
1208 ret = -1;
1209 goto done;
1212 /* Send a Media Connected event, according to the Spec */
1213 priv->media_connected = true;
1215 if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) {
1216 dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
1217 bss_desc->ssid.ssid);
1219 /* Update the created network descriptor with the new BSSID */
1220 memcpy(bss_desc->mac_address,
1221 adhoc_result->bssid, ETH_ALEN);
1223 priv->adhoc_state = ADHOC_STARTED;
1224 } else {
1226 * Now the join cmd should be successful.
1227 * If BSSID has changed use SSID to compare instead of BSSID
1229 dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
1230 bss_desc->ssid.ssid);
1233 * Make a copy of current BSSID descriptor, only needed for
1234 * join since the current descriptor is already being used
1235 * for adhoc start
1237 memcpy(&priv->curr_bss_params.bss_descriptor,
1238 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1240 priv->adhoc_state = ADHOC_JOINED;
1243 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
1244 priv->adhoc_channel);
1245 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
1246 priv->curr_bss_params.bss_descriptor.mac_address);
1248 if (!netif_carrier_ok(priv->netdev))
1249 netif_carrier_on(priv->netdev);
1250 if (netif_queue_stopped(priv->netdev))
1251 netif_wake_queue(priv->netdev);
1253 mwifiex_save_curr_bcn(priv);
1255 done:
1256 /* Need to indicate IOCTL complete */
1257 if (adapter->curr_cmd->wait_q_enabled) {
1258 if (ret)
1259 adapter->cmd_wait_q.status = -1;
1260 else
1261 adapter->cmd_wait_q.status = 0;
1265 return ret;
1269 * This function associates to a specific BSS discovered in a scan.
1271 * It clears any past association response stored for application
1272 * retrieval and calls the command preparation routine to send the
1273 * command to firmware.
1275 int mwifiex_associate(struct mwifiex_private *priv,
1276 struct mwifiex_bssdescriptor *bss_desc)
1278 u8 current_bssid[ETH_ALEN];
1280 /* Return error if the adapter or table entry is not marked as infra */
1281 if ((priv->bss_mode != NL80211_IFTYPE_STATION) ||
1282 (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
1283 return -1;
1285 memcpy(&current_bssid,
1286 &priv->curr_bss_params.bss_descriptor.mac_address,
1287 sizeof(current_bssid));
1289 /* Clear any past association response stored for application
1290 retrieval */
1291 priv->assoc_rsp_size = 0;
1293 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_ASSOCIATE,
1294 HostCmd_ACT_GEN_SET, 0, bss_desc);
1298 * This function starts an ad-hoc network.
1300 * It calls the command preparation routine to send the command to firmware.
1303 mwifiex_adhoc_start(struct mwifiex_private *priv,
1304 struct mwifiex_802_11_ssid *adhoc_ssid)
1306 dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
1307 priv->adhoc_channel);
1308 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1309 priv->curr_bss_params.bss_descriptor.channel);
1310 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
1311 priv->curr_bss_params.band);
1313 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_START,
1314 HostCmd_ACT_GEN_SET, 0, adhoc_ssid);
1318 * This function joins an ad-hoc network found in a previous scan.
1320 * It calls the command preparation routine to send the command to firmware,
1321 * if already not connected to the requested SSID.
1323 int mwifiex_adhoc_join(struct mwifiex_private *priv,
1324 struct mwifiex_bssdescriptor *bss_desc)
1326 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
1327 priv->curr_bss_params.bss_descriptor.ssid.ssid);
1328 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
1329 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
1330 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
1331 bss_desc->ssid.ssid);
1332 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
1333 bss_desc->ssid.ssid_len);
1335 /* Check if the requested SSID is already joined */
1336 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1337 !mwifiex_ssid_cmp(&bss_desc->ssid,
1338 &priv->curr_bss_params.bss_descriptor.ssid) &&
1339 (priv->curr_bss_params.bss_descriptor.bss_mode ==
1340 NL80211_IFTYPE_ADHOC)) {
1341 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
1342 " is the same as current; not attempting to re-join\n");
1343 return -1;
1346 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1347 priv->curr_bss_params.bss_descriptor.channel);
1348 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
1349 priv->curr_bss_params.band);
1351 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
1352 HostCmd_ACT_GEN_SET, 0, bss_desc);
1356 * This function deauthenticates/disconnects from infra network by sending
1357 * deauthentication request.
1359 static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
1361 u8 mac_address[ETH_ALEN];
1362 int ret = 0;
1363 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
1365 if (mac) {
1366 if (!memcmp(mac, zero_mac, sizeof(zero_mac)))
1367 memcpy((u8 *) &mac_address,
1368 (u8 *) &priv->curr_bss_params.bss_descriptor.
1369 mac_address, ETH_ALEN);
1370 else
1371 memcpy((u8 *) &mac_address, (u8 *) mac, ETH_ALEN);
1372 } else {
1373 memcpy((u8 *) &mac_address, (u8 *) &priv->curr_bss_params.
1374 bss_descriptor.mac_address, ETH_ALEN);
1377 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
1378 HostCmd_ACT_GEN_SET, 0, &mac_address);
1380 return ret;
1384 * This function deauthenticates/disconnects from a BSS.
1386 * In case of infra made, it sends deauthentication request, and
1387 * in case of ad-hoc mode, a stop network request is sent to the firmware.
1389 int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
1391 int ret = 0;
1393 if (priv->media_connected) {
1394 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
1395 ret = mwifiex_deauthenticate_infra(priv, mac);
1396 } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1397 ret = mwifiex_send_cmd_sync(priv,
1398 HostCmd_CMD_802_11_AD_HOC_STOP,
1399 HostCmd_ACT_GEN_SET, 0, NULL);
1403 return ret;
1405 EXPORT_SYMBOL_GPL(mwifiex_deauthenticate);
1408 * This function converts band to radio type used in channel TLV.
1411 mwifiex_band_to_radio_type(u8 band)
1413 switch (band) {
1414 case BAND_A:
1415 case BAND_AN:
1416 case BAND_A | BAND_AN:
1417 return HostCmd_SCAN_RADIO_TYPE_A;
1418 case BAND_B:
1419 case BAND_G:
1420 case BAND_B | BAND_G:
1421 default:
1422 return HostCmd_SCAN_RADIO_TYPE_BG;