blob: 60d25c690c07f46f28f7039c5e82f7d38f5a5e8c [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: association and ad-hoc start/join
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
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.
13 *
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.
18 */
19
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"
27
28#define CAPINFO_MASK (~(BIT(15) | BIT(14) | BIT(12) | BIT(11) | BIT(9)))
29
30/*
31 * Append a generic IE as a pass through TLV to a TLV buffer.
32 *
33 * This function is called from the network join command preparation routine.
34 *
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.
37 */
38static int
39mwifiex_cmd_append_generic_ie(struct mwifiex_private *priv, u8 **buffer)
40{
41 int ret_len = 0;
42 struct mwifiex_ie_types_header ie_header;
43
44 /* Null Checks */
45 if (!buffer)
46 return 0;
47 if (!(*buffer))
48 return 0;
49
50 /*
51 * If there is a generic ie buffer setup, append it to the return
52 * parameter buffer pointer.
53 */
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);
57
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));
62
63 /* Increment the return size and the return buffer pointer
64 param */
65 *buffer += sizeof(ie_header);
66 ret_len += sizeof(ie_header);
67
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);
71
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;
76
77 /* Reset the generic IE buffer */
78 priv->gen_ie_buf_len = 0;
79 }
80
81 /* return the length appended to the buffer */
82 return ret_len;
83}
84
85/*
86 * Append TSF tracking info from the scan table for the target AP.
87 *
88 * This function is called from the network join command preparation routine.
89 *
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.
94 *
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.
97 */
98static int
99mwifiex_cmd_append_tsf_tlv(struct mwifiex_private *priv, u8 **buffer,
100 struct mwifiex_bssdescriptor *bss_desc)
101{
102 struct mwifiex_ie_types_tsf_timestamp tsf_tlv;
103 long long tsf_val;
104
105 /* Null Checks */
106 if (buffer == NULL)
107 return 0;
108 if (*buffer == NULL)
109 return 0;
110
111 memset(&tsf_tlv, 0x00, sizeof(struct mwifiex_ie_types_tsf_timestamp));
112
113 tsf_tlv.header.type = cpu_to_le16(TLV_TYPE_TSFTIMESTAMP);
114 tsf_tlv.header.len = cpu_to_le16(2 * sizeof(tsf_val));
115
116 memcpy(*buffer, &tsf_tlv, sizeof(tsf_tlv.header));
117 *buffer += sizeof(tsf_tlv.header);
118
119 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
120 *buffer += sizeof(tsf_val);
121
122 memcpy(&tsf_val, bss_desc->time_stamp, sizeof(tsf_val));
123
124 dev_dbg(priv->adapter->dev, "info: %s: TSF offset calc: %016llx - "
125 "%016llx\n", __func__, tsf_val, bss_desc->network_tsf);
126
127 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
128 *buffer += sizeof(tsf_val);
129
130 return sizeof(tsf_tlv.header) + (2 * sizeof(tsf_val));
131}
132
133/*
134 * This function finds out the common rates between rate1 and rate2.
135 *
136 * It will fill common rates in rate1 as output if found.
137 *
138 * NOTE: Setting the MSB of the basic rates needs to be taken
139 * care of, either before or after calling this function.
140 */
141static int mwifiex_get_common_rates(struct mwifiex_private *priv, u8 *rate1,
142 u32 rate1_size, u8 *rate2, u32 rate2_size)
143{
144 int ret = 0;
145 u8 *ptr = rate1;
146 u8 *tmp = NULL;
147 u32 i, j;
148
149 tmp = kmalloc(rate1_size, GFP_KERNEL);
150 if (!tmp) {
151 dev_err(priv->adapter->dev, "failed to alloc tmp buf\n");
152 return -ENOMEM;
153 }
154
155 memcpy(tmp, rate1, rate1_size);
156 memset(rate1, 0, rate1_size);
157
158 for (i = 0; rate2[i] && i < rate2_size; i++) {
159 for (j = 0; tmp[j] && j < rate1_size; j++) {
160 /* Check common rate, excluding the bit for
161 basic rate */
162 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) {
163 *rate1++ = tmp[j];
164 break;
165 }
166 }
167 }
168
169 dev_dbg(priv->adapter->dev, "info: Tx data rate set to %#x\n",
170 priv->data_rate);
171
172 if (!priv->is_data_rate_auto) {
173 while (*ptr) {
174 if ((*ptr & 0x7f) == priv->data_rate) {
175 ret = 0;
176 goto done;
177 }
178 ptr++;
179 }
180 dev_err(priv->adapter->dev, "previously set fixed data rate %#x"
181 " is not compatible with the network\n",
182 priv->data_rate);
183
184 ret = -1;
185 goto done;
186 }
187
188 ret = 0;
189done:
190 kfree(tmp);
191 return ret;
192}
193
194/*
195 * This function creates the intersection of the rates supported by a
196 * target BSS and our adapter settings for use in an assoc/join command.
197 */
198static int
199mwifiex_setup_rates_from_bssdesc(struct mwifiex_private *priv,
200 struct mwifiex_bssdescriptor *bss_desc,
201 u8 *out_rates, u32 *out_rates_size)
202{
203 u8 card_rates[MWIFIEX_SUPPORTED_RATES];
204 u32 card_rates_size = 0;
205
206 /* Copy AP supported rates */
207 memcpy(out_rates, bss_desc->supported_rates, MWIFIEX_SUPPORTED_RATES);
208 /* Get the STA supported rates */
209 card_rates_size = mwifiex_get_active_data_rates(priv, card_rates);
210 /* Get the common rates between AP and STA supported rates */
211 if (mwifiex_get_common_rates(priv, out_rates, MWIFIEX_SUPPORTED_RATES,
212 card_rates, card_rates_size)) {
213 *out_rates_size = 0;
214 dev_err(priv->adapter->dev, "%s: cannot get common rates\n",
215 __func__);
216 return -1;
217 }
218
219 *out_rates_size =
220 min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES);
221
222 return 0;
223}
224
225/*
226 * This function updates the scan entry TSF timestamps to reflect
227 * a new association.
228 */
229static void
230mwifiex_update_tsf_timestamps(struct mwifiex_private *priv,
231 struct mwifiex_bssdescriptor *new_bss_desc)
232{
233 struct mwifiex_adapter *adapter = priv->adapter;
234 u32 table_idx;
235 long long new_tsf_base;
236 signed long long tsf_delta;
237
238 memcpy(&new_tsf_base, new_bss_desc->time_stamp, sizeof(new_tsf_base));
239
240 tsf_delta = new_tsf_base - new_bss_desc->network_tsf;
241
242 dev_dbg(adapter->dev, "info: TSF: update TSF timestamps, "
243 "0x%016llx -> 0x%016llx\n",
244 new_bss_desc->network_tsf, new_tsf_base);
245
246 for (table_idx = 0; table_idx < adapter->num_in_scan_table;
247 table_idx++)
248 adapter->scan_table[table_idx].network_tsf += tsf_delta;
249}
250
251/*
252 * This function appends a WAPI IE.
253 *
254 * This function is called from the network join command preparation routine.
255 *
256 * If the IE buffer has been setup by the application, this routine appends
257 * the buffer as a WAPI TLV type to the request.
258 */
259static int
260mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer)
261{
262 int retLen = 0;
263 struct mwifiex_ie_types_header ie_header;
264
265 /* Null Checks */
266 if (buffer == NULL)
267 return 0;
268 if (*buffer == NULL)
269 return 0;
270
271 /*
272 * If there is a wapi ie buffer setup, append it to the return
273 * parameter buffer pointer.
274 */
275 if (priv->wapi_ie_len) {
276 dev_dbg(priv->adapter->dev, "cmd: append wapi ie %d to %p\n",
277 priv->wapi_ie_len, *buffer);
278
279 /* Wrap the generic IE buffer with a pass through TLV type */
280 ie_header.type = cpu_to_le16(TLV_TYPE_WAPI_IE);
281 ie_header.len = cpu_to_le16(priv->wapi_ie_len);
282 memcpy(*buffer, &ie_header, sizeof(ie_header));
283
284 /* Increment the return size and the return buffer pointer
285 param */
286 *buffer += sizeof(ie_header);
287 retLen += sizeof(ie_header);
288
289 /* Copy the wapi IE buffer to the output buffer, advance
290 pointer */
291 memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len);
292
293 /* Increment the return size and the return buffer pointer
294 param */
295 *buffer += priv->wapi_ie_len;
296 retLen += priv->wapi_ie_len;
297
298 }
299 /* return the length appended to the buffer */
300 return retLen;
301}
302
303/*
304 * This function appends rsn ie tlv for wpa/wpa2 security modes.
305 * It is called from the network join command preparation routine.
306 */
307static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private *priv,
308 u8 **buffer)
309{
310 struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv;
311 int rsn_ie_len;
312
313 if (!buffer || !(*buffer))
314 return 0;
315
316 rsn_ie_tlv = (struct mwifiex_ie_types_rsn_param_set *) (*buffer);
317 rsn_ie_tlv->header.type = cpu_to_le16((u16) priv->wpa_ie[0]);
318 rsn_ie_tlv->header.type = cpu_to_le16(
319 le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF);
320 rsn_ie_tlv->header.len = cpu_to_le16((u16) priv->wpa_ie[1]);
321 rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len)
322 & 0x00FF);
323 if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2))
324 memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2],
325 le16_to_cpu(rsn_ie_tlv->header.len));
326 else
327 return -1;
328
329 rsn_ie_len = sizeof(rsn_ie_tlv->header) +
330 le16_to_cpu(rsn_ie_tlv->header.len);
331 *buffer += rsn_ie_len;
332
333 return rsn_ie_len;
334}
335
336/*
337 * This function prepares command for association.
338 *
339 * This sets the following parameters -
340 * - Peer MAC address
341 * - Listen interval
342 * - Beacon interval
343 * - Capability information
344 *
345 * ...and the following TLVs, as required -
346 * - SSID TLV
347 * - PHY TLV
348 * - SS TLV
349 * - Rates TLV
350 * - Authentication TLV
351 * - Channel TLV
352 * - WPA/WPA2 IE
353 * - 11n TLV
354 * - Vendor specific TLV
355 * - WMM TLV
356 * - WAPI IE
357 * - Generic IE
358 * - TSF TLV
359 *
360 * Preparation also includes -
361 * - Setting command ID and proper size
362 * - Ensuring correct endian-ness
363 */
364int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
365 struct host_cmd_ds_command *cmd,
366 void *data_buf)
367{
368 struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate;
369 struct mwifiex_bssdescriptor *bss_desc;
370 struct mwifiex_ie_types_ssid_param_set *ssid_tlv;
371 struct mwifiex_ie_types_phy_param_set *phy_tlv;
372 struct mwifiex_ie_types_ss_param_set *ss_tlv;
373 struct mwifiex_ie_types_rates_param_set *rates_tlv;
374 struct mwifiex_ie_types_auth_type *auth_tlv;
375 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
376 u8 rates[MWIFIEX_SUPPORTED_RATES];
377 u32 rates_size;
378 u16 tmp_cap;
379 u8 *pos;
380 int rsn_ie_len = 0;
381
382 bss_desc = (struct mwifiex_bssdescriptor *) data_buf;
383 pos = (u8 *) assoc;
384
385 mwifiex_cfg_tx_buf(priv, bss_desc);
386
387 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
388
389 /* Save so we know which BSS Desc to use in the response handler */
390 priv->attempted_bss_desc = bss_desc;
391
392 memcpy(assoc->peer_sta_addr,
393 bss_desc->mac_address, sizeof(assoc->peer_sta_addr));
394 pos += sizeof(assoc->peer_sta_addr);
395
396 /* Set the listen interval */
397 assoc->listen_interval = cpu_to_le16(priv->listen_interval);
398 /* Set the beacon period */
399 assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period);
400
401 pos += sizeof(assoc->cap_info_bitmap);
402 pos += sizeof(assoc->listen_interval);
403 pos += sizeof(assoc->beacon_period);
404 pos += sizeof(assoc->dtim_period);
405
406 ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos;
407 ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID);
408 ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len);
409 memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid,
410 le16_to_cpu(ssid_tlv->header.len));
411 pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len);
412
413 phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos;
414 phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS);
415 phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set));
416 memcpy(&phy_tlv->fh_ds.ds_param_set,
417 &bss_desc->phy_param_set.ds_param_set.current_chan,
418 sizeof(phy_tlv->fh_ds.ds_param_set));
419 pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len);
420
421 ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos;
422 ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS);
423 ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set));
424 pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len);
425
426 /* Get the common rates supported between the driver and the BSS Desc */
427 if (mwifiex_setup_rates_from_bssdesc
428 (priv, bss_desc, rates, &rates_size))
429 return -1;
430
431 /* Save the data rates into Current BSS state structure */
432 priv->curr_bss_params.num_of_rates = rates_size;
433 memcpy(&priv->curr_bss_params.data_rates, rates, rates_size);
434
435 /* Setup the Rates TLV in the association command */
436 rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos;
437 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
438 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
439 memcpy(rates_tlv->rates, rates, rates_size);
440 pos += sizeof(rates_tlv->header) + rates_size;
441 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: rates size = %d\n",
442 rates_size);
443
Marc Yang203afec2011-03-24 20:49:39 -0700444 /* Add the Authentication type to be used for Auth frames */
445 auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
446 auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
447 auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
448 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
449 auth_tlv->auth_type = cpu_to_le16(
450 (u16) priv->sec_info.authentication_mode);
451 else
Marc Yangf986b6d2011-03-28 17:55:42 -0700452 auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM);
Marc Yang203afec2011-03-24 20:49:39 -0700453
454 pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700455
456 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)
457 && !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
458 && (!bss_desc->disable_11n)
459 && (priv->adapter->config_bands & BAND_GN
460 || priv->adapter->config_bands & BAND_AN)
461 && (bss_desc->bcn_ht_cap)
462 )
463 ) {
464 /* Append a channel TLV for the channel the attempted AP was
465 found on */
466 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
467 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
468 chan_tlv->header.len =
469 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
470
471 memset(chan_tlv->chan_scan_param, 0x00,
472 sizeof(struct mwifiex_chan_scan_param_set));
473 chan_tlv->chan_scan_param[0].chan_number =
474 (bss_desc->phy_param_set.ds_param_set.current_chan);
475 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
476 chan_tlv->chan_scan_param[0].chan_number);
477
478 chan_tlv->chan_scan_param[0].radio_type =
479 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
480
481 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
482 chan_tlv->chan_scan_param[0].radio_type);
483 pos += sizeof(chan_tlv->header) +
484 sizeof(struct mwifiex_chan_scan_param_set);
485 }
486
487 if (!priv->wps.session_enable) {
488 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
489 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
490
491 if (rsn_ie_len == -1)
492 return -1;
493 }
494
495 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
496 && (!bss_desc->disable_11n)
497 && (priv->adapter->config_bands & BAND_GN
498 || priv->adapter->config_bands & BAND_AN))
499 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
500
501 /* Append vendor specific IE TLV */
502 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
503
504 mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
505 bss_desc->bcn_ht_cap);
506 if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
507 mwifiex_cmd_append_wapi_ie(priv, &pos);
508
509
510 mwifiex_cmd_append_generic_ie(priv, &pos);
511
512 mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
513
514 cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
515
516 /* Set the Capability info at last */
517 tmp_cap = bss_desc->cap_info_bitmap;
518
519 if (priv->adapter->config_bands == BAND_B)
Bing Zhaob93f85f2011-03-25 19:47:01 -0700520 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700521
522 tmp_cap &= CAPINFO_MASK;
523 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
524 tmp_cap, CAPINFO_MASK);
525 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
526
527 return 0;
528}
529
530/*
531 * Association firmware command response handler
532 *
533 * The response buffer for the association command has the following
534 * memory layout.
535 *
536 * For cases where an association response was not received (indicated
537 * by the CapInfo and AId field):
538 *
539 * .------------------------------------------------------------.
540 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
541 * .------------------------------------------------------------.
542 * | cap_info/Error Return(t_u16): |
543 * | 0xFFFF(-1): Internal error |
544 * | 0xFFFE(-2): Authentication unhandled message |
545 * | 0xFFFD(-3): Authentication refused |
546 * | 0xFFFC(-4): Timeout waiting for AP response |
547 * .------------------------------------------------------------.
548 * | status_code(t_u16): |
549 * | If cap_info is -1: |
550 * | An internal firmware failure prevented the |
551 * | command from being processed. The status_code |
552 * | will be set to 1. |
553 * | |
554 * | If cap_info is -2: |
555 * | An authentication frame was received but was |
556 * | not handled by the firmware. IEEE Status |
557 * | code for the failure is returned. |
558 * | |
559 * | If cap_info is -3: |
560 * | An authentication frame was received and the |
561 * | status_code is the IEEE Status reported in the |
562 * | response. |
563 * | |
564 * | If cap_info is -4: |
565 * | (1) Association response timeout |
566 * | (2) Authentication response timeout |
567 * .------------------------------------------------------------.
568 * | a_id(t_u16): 0xFFFF |
569 * .------------------------------------------------------------.
570 *
571 *
572 * For cases where an association response was received, the IEEE
573 * standard association response frame is returned:
574 *
575 * .------------------------------------------------------------.
576 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
577 * .------------------------------------------------------------.
578 * | cap_info(t_u16): IEEE Capability |
579 * .------------------------------------------------------------.
580 * | status_code(t_u16): IEEE Status Code |
581 * .------------------------------------------------------------.
582 * | a_id(t_u16): IEEE Association ID |
583 * .------------------------------------------------------------.
584 * | IEEE IEs(variable): Any received IEs comprising the |
585 * | remaining portion of a received |
586 * | association response frame. |
587 * .------------------------------------------------------------.
588 *
589 * For simplistic handling, the status_code field can be used to determine
590 * an association success (0) or failure (non-zero).
591 */
592int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700593 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700594{
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700595 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700596 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700597 struct ieee_types_assoc_rsp *assoc_rsp;
598 struct mwifiex_bssdescriptor *bss_desc;
599 u8 enable_data = true;
600
601 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
602
603 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
604 sizeof(priv->assoc_rsp_buf));
605
606 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
607
608 if (le16_to_cpu(assoc_rsp->status_code)) {
609 priv->adapter->dbg.num_cmd_assoc_failure++;
610 dev_err(priv->adapter->dev, "ASSOC_RESP: association failed, "
611 "status code = %d, error = 0x%x, a_id = 0x%x\n",
612 le16_to_cpu(assoc_rsp->status_code),
613 le16_to_cpu(assoc_rsp->cap_info_bitmap),
614 le16_to_cpu(assoc_rsp->a_id));
615
616 ret = -1;
617 goto done;
618 }
619
620 /* Send a Media Connected event, according to the Spec */
621 priv->media_connected = true;
622
623 priv->adapter->ps_state = PS_STATE_AWAKE;
624 priv->adapter->pps_uapsd_mode = false;
625 priv->adapter->tx_lock_flag = false;
626
627 /* Set the attempted BSSID Index to current */
628 bss_desc = priv->attempted_bss_desc;
629
630 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n",
631 bss_desc->ssid.ssid);
632
633 /* Make a copy of current BSSID descriptor */
634 memcpy(&priv->curr_bss_params.bss_descriptor,
635 bss_desc, sizeof(struct mwifiex_bssdescriptor));
636
637 /* Update curr_bss_params */
638 priv->curr_bss_params.bss_descriptor.channel
639 = bss_desc->phy_param_set.ds_param_set.current_chan;
640
641 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
642
643 /*
644 * Adjust the timestamps in the scan table to be relative to the newly
645 * associated AP's TSF
646 */
647 mwifiex_update_tsf_timestamps(priv, bss_desc);
648
649 if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
650 priv->curr_bss_params.wmm_enabled = true;
651 else
652 priv->curr_bss_params.wmm_enabled = false;
653
654 if ((priv->wmm_required || bss_desc->bcn_ht_cap)
655 && priv->curr_bss_params.wmm_enabled)
656 priv->wmm_enabled = true;
657 else
658 priv->wmm_enabled = false;
659
660 priv->curr_bss_params.wmm_uapsd_enabled = false;
661
662 if (priv->wmm_enabled)
663 priv->curr_bss_params.wmm_uapsd_enabled
664 = ((bss_desc->wmm_ie.qos_info_bitmap &
665 IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
666
667 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
668 priv->curr_pkt_filter);
669 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
670 priv->wpa_is_gtk_set = false;
671
672 if (priv->wmm_enabled) {
673 /* Don't re-enable carrier until we get the WMM_GET_STATUS
674 event */
675 enable_data = false;
676 } else {
677 /* Since WMM is not enabled, setup the queues with the
678 defaults */
679 mwifiex_wmm_setup_queue_priorities(priv, NULL);
680 mwifiex_wmm_setup_ac_downgrade(priv);
681 }
682
683 if (enable_data)
684 dev_dbg(priv->adapter->dev,
685 "info: post association, re-enabling data flow\n");
686
687 /* Reset SNR/NF/RSSI values */
688 priv->data_rssi_last = 0;
689 priv->data_nf_last = 0;
690 priv->data_rssi_avg = 0;
691 priv->data_nf_avg = 0;
692 priv->bcn_rssi_last = 0;
693 priv->bcn_nf_last = 0;
694 priv->bcn_rssi_avg = 0;
695 priv->bcn_nf_avg = 0;
696 priv->rxpd_rate = 0;
697 priv->rxpd_htinfo = 0;
698
699 mwifiex_save_curr_bcn(priv);
700
701 priv->adapter->dbg.num_cmd_assoc_success++;
702
703 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n");
704
705 /* Add the ra_list here for infra mode as there will be only 1 ra
706 always */
707 mwifiex_ralist_add(priv,
708 priv->curr_bss_params.bss_descriptor.mac_address);
709
710 if (!netif_carrier_ok(priv->netdev))
711 netif_carrier_on(priv->netdev);
712 if (netif_queue_stopped(priv->netdev))
713 netif_wake_queue(priv->netdev);
714
715 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
716 priv->scan_block = true;
717
718done:
719 /* Need to indicate IOCTL complete */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700720 if (adapter->curr_cmd->wait_q_enabled) {
721 if (ret)
722 adapter->cmd_wait_q.status = -1;
723 else
724 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700725 }
726
727 return ret;
728}
729
730/*
731 * This function prepares command for ad-hoc start.
732 *
733 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
734 * parameters, probe delay, and capability information. Firmware
735 * will fill up beacon period, basic rates and operational rates.
736 *
737 * In addition, the following TLVs are added -
738 * - Channel TLV
739 * - Vendor specific IE
740 * - WPA/WPA2 IE
741 * - HT Capabilities IE
742 * - HT Information IE
743 *
744 * Preparation also includes -
745 * - Setting command ID and proper size
746 * - Ensuring correct endian-ness
747 */
748int
749mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
750 struct host_cmd_ds_command *cmd, void *data_buf)
751{
752 int ret = 0, 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;
762
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);
767
768 if (!adapter)
769 return -1;
770
771 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
772
773 bss_desc = &priv->curr_bss_params.bss_descriptor;
774 priv->attempted_bss_desc = bss_desc;
775
776 /*
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.
784 */
785
786 memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
787
788 memcpy(adhoc_start->ssid,
789 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
790 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
791
792 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
793 adhoc_start->ssid);
794
795 memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
796 memcpy(bss_desc->ssid.ssid,
797 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
798 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
799
800 bss_desc->ssid.ssid_len =
801 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len;
802
803 /* Set the BSS mode */
804 adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700805 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700806 adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
807 bss_desc->beacon_period = priv->beacon_period;
808
809 /* Set Physical param set */
810/* Parameter IE Id */
811#define DS_PARA_IE_ID 3
812/* Parameter IE length */
813#define DS_PARA_IE_LEN 1
814
815 adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
816 adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
817
818 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
819 (priv, adapter->adhoc_start_band, (u16)
820 priv->adhoc_channel)) {
821 struct mwifiex_chan_freq_power *cfp;
822 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
823 adapter->adhoc_start_band, FIRST_VALID_CHANNEL);
824 if (cfp)
825 priv->adhoc_channel = (u8) cfp->channel;
826 }
827
828 if (!priv->adhoc_channel) {
829 dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
830 return -1;
831 }
832
833 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
834 priv->adhoc_channel);
835
836 priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
837 priv->curr_bss_params.band = adapter->adhoc_start_band;
838
839 bss_desc->channel = priv->adhoc_channel;
840 adhoc_start->phy_param_set.ds_param_set.current_chan =
841 priv->adhoc_channel;
842
843 memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
844 sizeof(union ieee_types_phy_param_set));
845
846 /* Set IBSS param set */
847/* IBSS parameter IE Id */
848#define IBSS_PARA_IE_ID 6
849/* IBSS parameter IE length */
850#define IBSS_PARA_IE_LEN 2
851
852 adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
853 adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
854 adhoc_start->ss_param_set.ibss_param_set.atim_window
855 = cpu_to_le16(priv->atim_window);
856 memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
857 sizeof(union ieee_types_ss_param_set));
858
859 /* Set Capability info */
860 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
861 tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap);
862 tmp_cap &= ~WLAN_CAPABILITY_ESS;
863 tmp_cap |= WLAN_CAPABILITY_IBSS;
864
865 /* Set up privacy in bss_desc */
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700866 if (priv->sec_info.encryption_mode) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700867 /* Ad-Hoc capability privacy on */
868 dev_dbg(adapter->dev,
869 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
870 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
871 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
872 } else {
873 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
874 " setting privacy to ACCEPT ALL\n");
875 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
876 }
877
878 memset(adhoc_start->DataRate, 0, sizeof(adhoc_start->DataRate));
879 mwifiex_get_active_data_rates(priv, adhoc_start->DataRate);
880 if ((adapter->adhoc_start_band & BAND_G) &&
881 (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700882 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
883 HostCmd_ACT_GEN_SET, 0,
884 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700885
886 if (ret) {
887 dev_err(adapter->dev,
888 "ADHOC_S_CMD: G Protection config failed\n");
889 return -1;
890 }
891 }
892 /* Find the last non zero */
893 for (i = 0; i < sizeof(adhoc_start->DataRate) &&
894 adhoc_start->DataRate[i];
895 i++)
896 ;
897
898 priv->curr_bss_params.num_of_rates = i;
899
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);
903
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]);
907
908 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
909
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));
916
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;
921
922 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
923 chan_tlv->chan_scan_param[0].chan_number);
924
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;
935 }
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);
943 }
944
945 /* Append vendor specific IE TLV */
946 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
947 MWIFIEX_VSIE_MASK_ADHOC, &pos);
948
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;
954 }
955
956 if (adapter->adhoc_11n_enabled) {
957 {
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);
966
Marc Yang6d2bd912011-03-25 19:47:02 -0700967 ht_cap_info |= IEEE80211_HT_CAP_SGI_20;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700968 if (adapter->chan_offset) {
Marc Yang6d2bd912011-03-25 19:47:02 -0700969 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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700972 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
973 }
974
975 ht_cap->ht_cap.ampdu_params_info
Marc Yang6d2bd912011-03-25 19:47:02 -0700976 = IEEE80211_HT_MAX_AMPDU_64K;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700977 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);
981 }
982 {
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;
Marc Yang6d2bd912011-03-25 19:47:02 -0700996 ht_info->ht_info.ht_param |=
997 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700998 }
999 ht_info->ht_info.operation_mode =
1000 cpu_to_le16(NON_GREENFIELD_STAS);
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);
1005 }
1006 }
1007
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));
1011
1012 if (adapter->adhoc_start_band == BAND_B)
Bing Zhaob93f85f2011-03-25 19:47:01 -07001013 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001014 else
Bing Zhaob93f85f2011-03-25 19:47:01 -07001015 tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001016
1017 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1018
1019 return 0;
1020}
1021
1022/*
1023 * This function prepares command for ad-hoc join.
1024 *
1025 * Most of the parameters are set up by copying from the target BSS descriptor
1026 * from the scan response.
1027 *
1028 * In addition, the following TLVs are added -
1029 * - Channel TLV
1030 * - Vendor specific IE
1031 * - WPA/WPA2 IE
1032 * - 11n IE
1033 *
1034 * Preparation also includes -
1035 * - Setting command ID and proper size
1036 * - Ensuring correct endian-ness
1037 */
1038int
1039mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1040 struct host_cmd_ds_command *cmd, void *data_buf)
1041{
1042 int ret = 0, 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);
1055
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;
1062
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001063 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
1064 HostCmd_ACT_GEN_SET, 0,
1065 &curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001066 if (ret) {
1067 dev_err(priv->adapter->dev,
1068 "ADHOC_J_CMD: G Protection config failed\n");
1069 return -1;
1070 }
1071 }
1072
1073 priv->attempted_bss_desc = bss_desc;
1074
1075 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1076
1077 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1078
1079 adhoc_join->bss_descriptor.beacon_period
1080 = cpu_to_le16(bss_desc->beacon_period);
1081
1082 memcpy(&adhoc_join->bss_descriptor.bssid,
1083 &bss_desc->mac_address, ETH_ALEN);
1084
1085 memcpy(&adhoc_join->bss_descriptor.ssid,
1086 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1087
1088 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1089 &bss_desc->phy_param_set,
1090 sizeof(union ieee_types_phy_param_set));
1091
1092 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1093 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1094
1095 tmp_cap = bss_desc->cap_info_bitmap;
1096
1097 tmp_cap &= CAPINFO_MASK;
1098
1099 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: tmp_cap=%4X"
1100 " CAPINFO_MASK=%4lX\n", tmp_cap, CAPINFO_MASK);
1101
1102 /* Information on BSSID descriptor passed to FW */
1103 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID = %pM, SSID = %s\n",
1104 adhoc_join->bss_descriptor.bssid,
1105 adhoc_join->bss_descriptor.ssid);
1106
1107 for (i = 0; bss_desc->supported_rates[i] &&
1108 i < MWIFIEX_SUPPORTED_RATES;
1109 i++)
1110 ;
1111 rates_size = i;
1112
1113 /* Copy Data Rates from the Rates recorded in scan response */
1114 memset(adhoc_join->bss_descriptor.data_rates, 0,
1115 sizeof(adhoc_join->bss_descriptor.data_rates));
1116 memcpy(adhoc_join->bss_descriptor.data_rates,
1117 bss_desc->supported_rates, rates_size);
1118
1119 /* Copy the adhoc join rates into Current BSS state structure */
1120 priv->curr_bss_params.num_of_rates = rates_size;
1121 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1122 rates_size);
1123
1124 /* Copy the channel information */
1125 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1126 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1127
1128 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED
1129 || priv->sec_info.wpa_enabled)
1130 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1131
1132 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1133 /* Append a channel TLV */
1134 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1135 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1136 chan_tlv->header.len =
1137 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1138
1139 memset(chan_tlv->chan_scan_param, 0x00,
1140 sizeof(struct mwifiex_chan_scan_param_set));
1141 chan_tlv->chan_scan_param[0].chan_number =
1142 (bss_desc->phy_param_set.ds_param_set.current_chan);
1143 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan = %d\n",
1144 chan_tlv->chan_scan_param[0].chan_number);
1145
1146 chan_tlv->chan_scan_param[0].radio_type =
1147 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1148
1149 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band = %d\n",
1150 chan_tlv->chan_scan_param[0].radio_type);
1151 pos += sizeof(chan_tlv->header) +
1152 sizeof(struct mwifiex_chan_scan_param_set);
1153 cmd_append_size += sizeof(chan_tlv->header) +
1154 sizeof(struct mwifiex_chan_scan_param_set);
1155 }
1156
1157 if (priv->sec_info.wpa_enabled)
1158 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1159 if (rsn_ie_len == -1)
1160 return -1;
1161 cmd_append_size += rsn_ie_len;
1162
1163 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1164 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1165 bss_desc, &pos);
1166
1167 /* Append vendor specific IE TLV */
1168 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1169 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1170
1171 cmd->size = cpu_to_le16((u16)
1172 (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1173 + S_DS_GEN + cmd_append_size));
1174
1175 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1176
1177 return ret;
1178}
1179
1180/*
1181 * This function handles the command response of ad-hoc start and
1182 * ad-hoc join.
1183 *
1184 * The function generates a device-connected event to notify
1185 * the applications, in case of successful ad-hoc start/join, and
1186 * saves the beacon buffer.
1187 */
1188int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001189 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001190{
1191 int ret = 0;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001192 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001193 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1194 struct mwifiex_bssdescriptor *bss_desc;
1195 u16 command = le16_to_cpu(resp->command);
1196 u16 result = le16_to_cpu(resp->result);
1197
1198 adhoc_result = &resp->params.adhoc_result;
1199
1200 bss_desc = priv->attempted_bss_desc;
1201
1202 /* Join result code 0 --> SUCCESS */
1203 if (result) {
1204 dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
1205 if (priv->media_connected)
1206 mwifiex_reset_connect_state(priv);
1207
1208 memset(&priv->curr_bss_params.bss_descriptor,
1209 0x00, sizeof(struct mwifiex_bssdescriptor));
1210
1211 ret = -1;
1212 goto done;
1213 }
1214
1215 /* Send a Media Connected event, according to the Spec */
1216 priv->media_connected = true;
1217
1218 if (command == HostCmd_CMD_802_11_AD_HOC_START) {
1219 dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
1220 bss_desc->ssid.ssid);
1221
1222 /* Update the created network descriptor with the new BSSID */
1223 memcpy(bss_desc->mac_address,
1224 adhoc_result->bssid, ETH_ALEN);
1225
1226 priv->adhoc_state = ADHOC_STARTED;
1227 } else {
1228 /*
1229 * Now the join cmd should be successful.
1230 * If BSSID has changed use SSID to compare instead of BSSID
1231 */
1232 dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
1233 bss_desc->ssid.ssid);
1234
1235 /*
1236 * Make a copy of current BSSID descriptor, only needed for
1237 * join since the current descriptor is already being used
1238 * for adhoc start
1239 */
1240 memcpy(&priv->curr_bss_params.bss_descriptor,
1241 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1242
1243 priv->adhoc_state = ADHOC_JOINED;
1244 }
1245
1246 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
1247 priv->adhoc_channel);
1248 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
1249 priv->curr_bss_params.bss_descriptor.mac_address);
1250
1251 if (!netif_carrier_ok(priv->netdev))
1252 netif_carrier_on(priv->netdev);
1253 if (netif_queue_stopped(priv->netdev))
1254 netif_wake_queue(priv->netdev);
1255
1256 mwifiex_save_curr_bcn(priv);
1257
1258done:
1259 /* Need to indicate IOCTL complete */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001260 if (adapter->curr_cmd->wait_q_enabled) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001261 if (ret)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001262 adapter->cmd_wait_q.status = -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001263 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001264 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001265
1266 }
1267
1268 return ret;
1269}
1270
1271/*
1272 * This function associates to a specific BSS discovered in a scan.
1273 *
1274 * It clears any past association response stored for application
1275 * retrieval and calls the command preparation routine to send the
1276 * command to firmware.
1277 */
1278int mwifiex_associate(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001279 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001280{
1281 int ret = 0;
1282 u8 current_bssid[ETH_ALEN];
1283
1284 /* Return error if the adapter or table entry is not marked as infra */
Bing Zhaoeecd8252011-03-28 17:55:41 -07001285 if ((priv->bss_mode != NL80211_IFTYPE_STATION) ||
1286 (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001287 return -1;
1288
1289 memcpy(&current_bssid,
1290 &priv->curr_bss_params.bss_descriptor.mac_address,
1291 sizeof(current_bssid));
1292
1293 /* Clear any past association response stored for application
1294 retrieval */
1295 priv->assoc_rsp_size = 0;
1296
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001297 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_ASSOCIATE,
1298 HostCmd_ACT_GEN_SET, 0, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001299
1300 return ret;
1301}
1302
1303/*
1304 * This function starts an ad-hoc network.
1305 *
1306 * It calls the command preparation routine to send the command to firmware.
1307 */
1308int
1309mwifiex_adhoc_start(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001310 struct mwifiex_802_11_ssid *adhoc_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001311{
1312 int ret = 0;
1313
1314 dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
1315 priv->adhoc_channel);
1316 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1317 priv->curr_bss_params.bss_descriptor.channel);
1318 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
1319 priv->curr_bss_params.band);
1320
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001321 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_START,
1322 HostCmd_ACT_GEN_SET, 0, adhoc_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001323
1324 return ret;
1325}
1326
1327/*
1328 * This function joins an ad-hoc network found in a previous scan.
1329 *
1330 * It calls the command preparation routine to send the command to firmware,
1331 * if already not connected to the requested SSID.
1332 */
1333int mwifiex_adhoc_join(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001334 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001335{
1336 int ret = 0;
1337
1338 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
1339 priv->curr_bss_params.bss_descriptor.ssid.ssid);
1340 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
1341 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
1342 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
1343 bss_desc->ssid.ssid);
1344 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
1345 bss_desc->ssid.ssid_len);
1346
1347 /* Check if the requested SSID is already joined */
1348 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1349 !mwifiex_ssid_cmp(&bss_desc->ssid,
1350 &priv->curr_bss_params.bss_descriptor.ssid) &&
1351 (priv->curr_bss_params.bss_descriptor.bss_mode ==
Bing Zhaoeecd8252011-03-28 17:55:41 -07001352 NL80211_IFTYPE_ADHOC)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001353 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
1354 " is the same as current; not attempting to re-join\n");
1355 return -1;
1356 }
1357
1358 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1359 priv->curr_bss_params.bss_descriptor.channel);
1360 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
1361 priv->curr_bss_params.band);
1362
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001363 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
1364 HostCmd_ACT_GEN_SET, 0, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001365
1366 return ret;
1367}
1368
1369/*
1370 * This function deauthenticates/disconnects from infra network by sending
1371 * deauthentication request.
1372 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001373static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001374{
1375 u8 mac_address[ETH_ALEN];
1376 int ret = 0;
1377 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
1378
1379 if (mac) {
1380 if (!memcmp(mac, zero_mac, sizeof(zero_mac)))
1381 memcpy((u8 *) &mac_address,
1382 (u8 *) &priv->curr_bss_params.bss_descriptor.
1383 mac_address, ETH_ALEN);
1384 else
1385 memcpy((u8 *) &mac_address, (u8 *) mac, ETH_ALEN);
1386 } else {
1387 memcpy((u8 *) &mac_address, (u8 *) &priv->curr_bss_params.
1388 bss_descriptor.mac_address, ETH_ALEN);
1389 }
1390
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001391 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
1392 HostCmd_ACT_GEN_SET, 0, &mac_address);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001393
1394 return ret;
1395}
1396
1397/*
1398 * This function deauthenticates/disconnects from a BSS.
1399 *
1400 * In case of infra made, it sends deauthentication request, and
1401 * in case of ad-hoc mode, a stop network request is sent to the firmware.
1402 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001403int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001404{
1405 int ret = 0;
1406
1407 if (priv->media_connected) {
Bing Zhaoeecd8252011-03-28 17:55:41 -07001408 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001409 ret = mwifiex_deauthenticate_infra(priv, mac);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001410 } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001411 ret = mwifiex_send_cmd_sync(priv,
1412 HostCmd_CMD_802_11_AD_HOC_STOP,
1413 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001414 }
1415 }
1416
1417 return ret;
1418}
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001419EXPORT_SYMBOL_GPL(mwifiex_deauthenticate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001420
1421/*
1422 * This function converts band to radio type used in channel TLV.
1423 */
1424u8
1425mwifiex_band_to_radio_type(u8 band)
1426{
1427 u8 ret_radio_type;
1428
1429 switch (band) {
1430 case BAND_A:
1431 case BAND_AN:
1432 case BAND_A | BAND_AN:
1433 ret_radio_type = HostCmd_SCAN_RADIO_TYPE_A;
1434 break;
1435 case BAND_B:
1436 case BAND_G:
1437 case BAND_B | BAND_G:
1438 default:
1439 ret_radio_type = HostCmd_SCAN_RADIO_TYPE_BG;
1440 break;
1441 }
1442
1443 return ret_radio_type;
1444}