blob: 23d2d0b9a52784531fafb86e4e8d72a6befaa7cf [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{
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700752 int rsn_ie_len = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700753 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)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700882 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700883 HostCmd_ACT_GEN_SET, 0,
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700884 &priv->curr_pkt_filter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700885 dev_err(adapter->dev,
886 "ADHOC_S_CMD: G Protection config failed\n");
887 return -1;
888 }
889 }
890 /* Find the last non zero */
891 for (i = 0; i < sizeof(adhoc_start->DataRate) &&
892 adhoc_start->DataRate[i];
893 i++)
894 ;
895
896 priv->curr_bss_params.num_of_rates = i;
897
898 /* Copy the ad-hoc creating rates into Current BSS rate structure */
899 memcpy(&priv->curr_bss_params.data_rates,
900 &adhoc_start->DataRate, priv->curr_bss_params.num_of_rates);
901
902 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n",
903 adhoc_start->DataRate[0], adhoc_start->DataRate[1],
904 adhoc_start->DataRate[2], adhoc_start->DataRate[3]);
905
906 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
907
908 if (IS_SUPPORT_MULTI_BANDS(adapter)) {
909 /* Append a channel TLV */
910 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
911 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
912 chan_tlv->header.len =
913 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
914
915 memset(chan_tlv->chan_scan_param, 0x00,
916 sizeof(struct mwifiex_chan_scan_param_set));
917 chan_tlv->chan_scan_param[0].chan_number =
918 (u8) priv->curr_bss_params.bss_descriptor.channel;
919
920 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
921 chan_tlv->chan_scan_param[0].chan_number);
922
923 chan_tlv->chan_scan_param[0].radio_type
924 = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
925 if (adapter->adhoc_start_band & BAND_GN
926 || adapter->adhoc_start_band & BAND_AN) {
927 if (adapter->chan_offset == SEC_CHANNEL_ABOVE)
928 chan_tlv->chan_scan_param[0].radio_type |=
929 SECOND_CHANNEL_ABOVE;
930 else if (adapter->chan_offset == SEC_CHANNEL_BELOW)
931 chan_tlv->chan_scan_param[0].radio_type |=
932 SECOND_CHANNEL_BELOW;
933 }
934 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
935 chan_tlv->chan_scan_param[0].radio_type);
936 pos += sizeof(chan_tlv->header) +
937 sizeof(struct mwifiex_chan_scan_param_set);
938 cmd_append_size +=
939 sizeof(chan_tlv->header) +
940 sizeof(struct mwifiex_chan_scan_param_set);
941 }
942
943 /* Append vendor specific IE TLV */
944 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
945 MWIFIEX_VSIE_MASK_ADHOC, &pos);
946
947 if (priv->sec_info.wpa_enabled) {
948 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
949 if (rsn_ie_len == -1)
950 return -1;
951 cmd_append_size += rsn_ie_len;
952 }
953
954 if (adapter->adhoc_11n_enabled) {
955 {
956 ht_cap = (struct mwifiex_ie_types_htcap *) pos;
957 memset(ht_cap, 0,
958 sizeof(struct mwifiex_ie_types_htcap));
959 ht_cap->header.type =
960 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
961 ht_cap->header.len =
962 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
963 ht_cap_info = le16_to_cpu(ht_cap->ht_cap.cap_info);
964
Marc Yang6d2bd912011-03-25 19:47:02 -0700965 ht_cap_info |= IEEE80211_HT_CAP_SGI_20;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700966 if (adapter->chan_offset) {
Marc Yang6d2bd912011-03-25 19:47:02 -0700967 ht_cap_info |= IEEE80211_HT_CAP_SGI_40;
968 ht_cap_info |= IEEE80211_HT_CAP_DSSSCCK40;
969 ht_cap_info |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700970 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
971 }
972
973 ht_cap->ht_cap.ampdu_params_info
Marc Yang6d2bd912011-03-25 19:47:02 -0700974 = IEEE80211_HT_MAX_AMPDU_64K;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700975 ht_cap->ht_cap.mcs.rx_mask[0] = 0xff;
976 pos += sizeof(struct mwifiex_ie_types_htcap);
977 cmd_append_size +=
978 sizeof(struct mwifiex_ie_types_htcap);
979 }
980 {
981 ht_info = (struct mwifiex_ie_types_htinfo *) pos;
982 memset(ht_info, 0,
983 sizeof(struct mwifiex_ie_types_htinfo));
984 ht_info->header.type =
985 cpu_to_le16(WLAN_EID_HT_INFORMATION);
986 ht_info->header.len =
987 cpu_to_le16(sizeof(struct ieee80211_ht_info));
988 ht_info->ht_info.control_chan =
989 (u8) priv->curr_bss_params.bss_descriptor.
990 channel;
991 if (adapter->chan_offset) {
992 ht_info->ht_info.ht_param =
993 adapter->chan_offset;
Marc Yang6d2bd912011-03-25 19:47:02 -0700994 ht_info->ht_info.ht_param |=
995 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700996 }
997 ht_info->ht_info.operation_mode =
Amitkumar Karwara3731652011-04-15 20:50:41 -0700998 cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700999 ht_info->ht_info.basic_set[0] = 0xff;
1000 pos += sizeof(struct mwifiex_ie_types_htinfo);
1001 cmd_append_size +=
1002 sizeof(struct mwifiex_ie_types_htinfo);
1003 }
1004 }
1005
1006 cmd->size = cpu_to_le16((u16)
1007 (sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
1008 + S_DS_GEN + cmd_append_size));
1009
1010 if (adapter->adhoc_start_band == BAND_B)
Bing Zhaob93f85f2011-03-25 19:47:01 -07001011 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001012 else
Bing Zhaob93f85f2011-03-25 19:47:01 -07001013 tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001014
1015 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1016
1017 return 0;
1018}
1019
1020/*
1021 * This function prepares command for ad-hoc join.
1022 *
1023 * Most of the parameters are set up by copying from the target BSS descriptor
1024 * from the scan response.
1025 *
1026 * In addition, the following TLVs are added -
1027 * - Channel TLV
1028 * - Vendor specific IE
1029 * - WPA/WPA2 IE
1030 * - 11n IE
1031 *
1032 * Preparation also includes -
1033 * - Setting command ID and proper size
1034 * - Ensuring correct endian-ness
1035 */
1036int
1037mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1038 struct host_cmd_ds_command *cmd, void *data_buf)
1039{
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001040 int rsn_ie_len = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001041 struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
1042 &cmd->params.adhoc_join;
1043 struct mwifiex_bssdescriptor *bss_desc =
1044 (struct mwifiex_bssdescriptor *) data_buf;
1045 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
1046 u32 cmd_append_size = 0;
1047 u16 tmp_cap;
1048 u32 i, rates_size = 0;
1049 u16 curr_pkt_filter;
1050 u8 *pos =
1051 (u8 *) adhoc_join +
1052 sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
1053
1054/* Use G protection */
1055#define USE_G_PROTECTION 0x02
1056 if (bss_desc->erp_flags & USE_G_PROTECTION) {
1057 curr_pkt_filter =
1058 priv->
1059 curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
1060
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001061 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001062 HostCmd_ACT_GEN_SET, 0,
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001063 &curr_pkt_filter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001064 dev_err(priv->adapter->dev,
1065 "ADHOC_J_CMD: G Protection config failed\n");
1066 return -1;
1067 }
1068 }
1069
1070 priv->attempted_bss_desc = bss_desc;
1071
1072 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1073
1074 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1075
1076 adhoc_join->bss_descriptor.beacon_period
1077 = cpu_to_le16(bss_desc->beacon_period);
1078
1079 memcpy(&adhoc_join->bss_descriptor.bssid,
1080 &bss_desc->mac_address, ETH_ALEN);
1081
1082 memcpy(&adhoc_join->bss_descriptor.ssid,
1083 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1084
1085 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1086 &bss_desc->phy_param_set,
1087 sizeof(union ieee_types_phy_param_set));
1088
1089 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1090 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1091
1092 tmp_cap = bss_desc->cap_info_bitmap;
1093
1094 tmp_cap &= CAPINFO_MASK;
1095
1096 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: tmp_cap=%4X"
1097 " CAPINFO_MASK=%4lX\n", tmp_cap, CAPINFO_MASK);
1098
1099 /* Information on BSSID descriptor passed to FW */
1100 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID = %pM, SSID = %s\n",
1101 adhoc_join->bss_descriptor.bssid,
1102 adhoc_join->bss_descriptor.ssid);
1103
1104 for (i = 0; bss_desc->supported_rates[i] &&
1105 i < MWIFIEX_SUPPORTED_RATES;
1106 i++)
1107 ;
1108 rates_size = i;
1109
1110 /* Copy Data Rates from the Rates recorded in scan response */
1111 memset(adhoc_join->bss_descriptor.data_rates, 0,
1112 sizeof(adhoc_join->bss_descriptor.data_rates));
1113 memcpy(adhoc_join->bss_descriptor.data_rates,
1114 bss_desc->supported_rates, rates_size);
1115
1116 /* Copy the adhoc join rates into Current BSS state structure */
1117 priv->curr_bss_params.num_of_rates = rates_size;
1118 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1119 rates_size);
1120
1121 /* Copy the channel information */
1122 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1123 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1124
1125 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED
1126 || priv->sec_info.wpa_enabled)
1127 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1128
1129 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1130 /* Append a channel TLV */
1131 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1132 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1133 chan_tlv->header.len =
1134 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1135
1136 memset(chan_tlv->chan_scan_param, 0x00,
1137 sizeof(struct mwifiex_chan_scan_param_set));
1138 chan_tlv->chan_scan_param[0].chan_number =
1139 (bss_desc->phy_param_set.ds_param_set.current_chan);
1140 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan = %d\n",
1141 chan_tlv->chan_scan_param[0].chan_number);
1142
1143 chan_tlv->chan_scan_param[0].radio_type =
1144 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1145
1146 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band = %d\n",
1147 chan_tlv->chan_scan_param[0].radio_type);
1148 pos += sizeof(chan_tlv->header) +
1149 sizeof(struct mwifiex_chan_scan_param_set);
1150 cmd_append_size += sizeof(chan_tlv->header) +
1151 sizeof(struct mwifiex_chan_scan_param_set);
1152 }
1153
1154 if (priv->sec_info.wpa_enabled)
1155 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1156 if (rsn_ie_len == -1)
1157 return -1;
1158 cmd_append_size += rsn_ie_len;
1159
1160 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1161 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1162 bss_desc, &pos);
1163
1164 /* Append vendor specific IE TLV */
1165 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1166 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1167
1168 cmd->size = cpu_to_le16((u16)
1169 (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1170 + S_DS_GEN + cmd_append_size));
1171
1172 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1173
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001174 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001175}
1176
1177/*
1178 * This function handles the command response of ad-hoc start and
1179 * ad-hoc join.
1180 *
1181 * The function generates a device-connected event to notify
1182 * the applications, in case of successful ad-hoc start/join, and
1183 * saves the beacon buffer.
1184 */
1185int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001186 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001187{
1188 int ret = 0;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001189 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001190 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1191 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001192
1193 adhoc_result = &resp->params.adhoc_result;
1194
1195 bss_desc = priv->attempted_bss_desc;
1196
1197 /* Join result code 0 --> SUCCESS */
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001198 if (le16_to_cpu(resp->result)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001199 dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
1200 if (priv->media_connected)
1201 mwifiex_reset_connect_state(priv);
1202
1203 memset(&priv->curr_bss_params.bss_descriptor,
1204 0x00, sizeof(struct mwifiex_bssdescriptor));
1205
1206 ret = -1;
1207 goto done;
1208 }
1209
1210 /* Send a Media Connected event, according to the Spec */
1211 priv->media_connected = true;
1212
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001213 if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001214 dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
1215 bss_desc->ssid.ssid);
1216
1217 /* Update the created network descriptor with the new BSSID */
1218 memcpy(bss_desc->mac_address,
1219 adhoc_result->bssid, ETH_ALEN);
1220
1221 priv->adhoc_state = ADHOC_STARTED;
1222 } else {
1223 /*
1224 * Now the join cmd should be successful.
1225 * If BSSID has changed use SSID to compare instead of BSSID
1226 */
1227 dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
1228 bss_desc->ssid.ssid);
1229
1230 /*
1231 * Make a copy of current BSSID descriptor, only needed for
1232 * join since the current descriptor is already being used
1233 * for adhoc start
1234 */
1235 memcpy(&priv->curr_bss_params.bss_descriptor,
1236 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1237
1238 priv->adhoc_state = ADHOC_JOINED;
1239 }
1240
1241 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
1242 priv->adhoc_channel);
1243 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
1244 priv->curr_bss_params.bss_descriptor.mac_address);
1245
1246 if (!netif_carrier_ok(priv->netdev))
1247 netif_carrier_on(priv->netdev);
1248 if (netif_queue_stopped(priv->netdev))
1249 netif_wake_queue(priv->netdev);
1250
1251 mwifiex_save_curr_bcn(priv);
1252
1253done:
1254 /* Need to indicate IOCTL complete */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001255 if (adapter->curr_cmd->wait_q_enabled) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001256 if (ret)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001257 adapter->cmd_wait_q.status = -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001258 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001259 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001260
1261 }
1262
1263 return ret;
1264}
1265
1266/*
1267 * This function associates to a specific BSS discovered in a scan.
1268 *
1269 * It clears any past association response stored for application
1270 * retrieval and calls the command preparation routine to send the
1271 * command to firmware.
1272 */
1273int mwifiex_associate(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001274 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001275{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001276 u8 current_bssid[ETH_ALEN];
1277
1278 /* Return error if the adapter or table entry is not marked as infra */
Bing Zhaoeecd8252011-03-28 17:55:41 -07001279 if ((priv->bss_mode != NL80211_IFTYPE_STATION) ||
1280 (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001281 return -1;
1282
1283 memcpy(&current_bssid,
1284 &priv->curr_bss_params.bss_descriptor.mac_address,
1285 sizeof(current_bssid));
1286
1287 /* Clear any past association response stored for application
1288 retrieval */
1289 priv->assoc_rsp_size = 0;
1290
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001291 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_ASSOCIATE,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001292 HostCmd_ACT_GEN_SET, 0, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001293}
1294
1295/*
1296 * This function starts an ad-hoc network.
1297 *
1298 * It calls the command preparation routine to send the command to firmware.
1299 */
1300int
1301mwifiex_adhoc_start(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001302 struct mwifiex_802_11_ssid *adhoc_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001303{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001304 dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
1305 priv->adhoc_channel);
1306 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1307 priv->curr_bss_params.bss_descriptor.channel);
1308 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
1309 priv->curr_bss_params.band);
1310
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001311 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_START,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001312 HostCmd_ACT_GEN_SET, 0, adhoc_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001313}
1314
1315/*
1316 * This function joins an ad-hoc network found in a previous scan.
1317 *
1318 * It calls the command preparation routine to send the command to firmware,
1319 * if already not connected to the requested SSID.
1320 */
1321int mwifiex_adhoc_join(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001322 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001323{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001324 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
1325 priv->curr_bss_params.bss_descriptor.ssid.ssid);
1326 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
1327 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
1328 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
1329 bss_desc->ssid.ssid);
1330 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
1331 bss_desc->ssid.ssid_len);
1332
1333 /* Check if the requested SSID is already joined */
1334 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1335 !mwifiex_ssid_cmp(&bss_desc->ssid,
1336 &priv->curr_bss_params.bss_descriptor.ssid) &&
1337 (priv->curr_bss_params.bss_descriptor.bss_mode ==
Bing Zhaoeecd8252011-03-28 17:55:41 -07001338 NL80211_IFTYPE_ADHOC)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001339 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
1340 " is the same as current; not attempting to re-join\n");
1341 return -1;
1342 }
1343
1344 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1345 priv->curr_bss_params.bss_descriptor.channel);
1346 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
1347 priv->curr_bss_params.band);
1348
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001349 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001350 HostCmd_ACT_GEN_SET, 0, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001351}
1352
1353/*
1354 * This function deauthenticates/disconnects from infra network by sending
1355 * deauthentication request.
1356 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001357static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001358{
1359 u8 mac_address[ETH_ALEN];
1360 int ret = 0;
1361 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
1362
1363 if (mac) {
1364 if (!memcmp(mac, zero_mac, sizeof(zero_mac)))
1365 memcpy((u8 *) &mac_address,
1366 (u8 *) &priv->curr_bss_params.bss_descriptor.
1367 mac_address, ETH_ALEN);
1368 else
1369 memcpy((u8 *) &mac_address, (u8 *) mac, ETH_ALEN);
1370 } else {
1371 memcpy((u8 *) &mac_address, (u8 *) &priv->curr_bss_params.
1372 bss_descriptor.mac_address, ETH_ALEN);
1373 }
1374
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001375 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
1376 HostCmd_ACT_GEN_SET, 0, &mac_address);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001377
1378 return ret;
1379}
1380
1381/*
1382 * This function deauthenticates/disconnects from a BSS.
1383 *
1384 * In case of infra made, it sends deauthentication request, and
1385 * in case of ad-hoc mode, a stop network request is sent to the firmware.
1386 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001387int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001388{
1389 int ret = 0;
1390
1391 if (priv->media_connected) {
Bing Zhaoeecd8252011-03-28 17:55:41 -07001392 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001393 ret = mwifiex_deauthenticate_infra(priv, mac);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001394 } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001395 ret = mwifiex_send_cmd_sync(priv,
1396 HostCmd_CMD_802_11_AD_HOC_STOP,
1397 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001398 }
1399 }
1400
1401 return ret;
1402}
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001403EXPORT_SYMBOL_GPL(mwifiex_deauthenticate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001404
1405/*
1406 * This function converts band to radio type used in channel TLV.
1407 */
1408u8
1409mwifiex_band_to_radio_type(u8 band)
1410{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001411 switch (band) {
1412 case BAND_A:
1413 case BAND_AN:
1414 case BAND_A | BAND_AN:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001415 return HostCmd_SCAN_RADIO_TYPE_A;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001416 case BAND_B:
1417 case BAND_G:
1418 case BAND_B | BAND_G:
1419 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001420 return HostCmd_SCAN_RADIO_TYPE_BG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001421 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001422}