blob: 042eb7701d04ed0bf48ac8dc0bf646cf2f7f2125 [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
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700119 memcpy(&tsf_val, bss_desc->time_stamp, sizeof(tsf_val));
120
121 dev_dbg(priv->adapter->dev, "info: %s: TSF offset calc: %016llx - "
122 "%016llx\n", __func__, tsf_val, bss_desc->network_tsf);
123
124 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
125 *buffer += sizeof(tsf_val);
126
127 return sizeof(tsf_tlv.header) + (2 * sizeof(tsf_val));
128}
129
130/*
131 * This function finds out the common rates between rate1 and rate2.
132 *
133 * It will fill common rates in rate1 as output if found.
134 *
135 * NOTE: Setting the MSB of the basic rates needs to be taken
136 * care of, either before or after calling this function.
137 */
138static int mwifiex_get_common_rates(struct mwifiex_private *priv, u8 *rate1,
139 u32 rate1_size, u8 *rate2, u32 rate2_size)
140{
141 int ret = 0;
142 u8 *ptr = rate1;
143 u8 *tmp = NULL;
144 u32 i, j;
145
146 tmp = kmalloc(rate1_size, GFP_KERNEL);
147 if (!tmp) {
148 dev_err(priv->adapter->dev, "failed to alloc tmp buf\n");
149 return -ENOMEM;
150 }
151
152 memcpy(tmp, rate1, rate1_size);
153 memset(rate1, 0, rate1_size);
154
155 for (i = 0; rate2[i] && i < rate2_size; i++) {
156 for (j = 0; tmp[j] && j < rate1_size; j++) {
157 /* Check common rate, excluding the bit for
158 basic rate */
159 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) {
160 *rate1++ = tmp[j];
161 break;
162 }
163 }
164 }
165
166 dev_dbg(priv->adapter->dev, "info: Tx data rate set to %#x\n",
167 priv->data_rate);
168
169 if (!priv->is_data_rate_auto) {
170 while (*ptr) {
171 if ((*ptr & 0x7f) == priv->data_rate) {
172 ret = 0;
173 goto done;
174 }
175 ptr++;
176 }
177 dev_err(priv->adapter->dev, "previously set fixed data rate %#x"
178 " is not compatible with the network\n",
179 priv->data_rate);
180
181 ret = -1;
182 goto done;
183 }
184
185 ret = 0;
186done:
187 kfree(tmp);
188 return ret;
189}
190
191/*
192 * This function creates the intersection of the rates supported by a
193 * target BSS and our adapter settings for use in an assoc/join command.
194 */
195static int
196mwifiex_setup_rates_from_bssdesc(struct mwifiex_private *priv,
197 struct mwifiex_bssdescriptor *bss_desc,
198 u8 *out_rates, u32 *out_rates_size)
199{
200 u8 card_rates[MWIFIEX_SUPPORTED_RATES];
201 u32 card_rates_size = 0;
202
203 /* Copy AP supported rates */
204 memcpy(out_rates, bss_desc->supported_rates, MWIFIEX_SUPPORTED_RATES);
205 /* Get the STA supported rates */
206 card_rates_size = mwifiex_get_active_data_rates(priv, card_rates);
207 /* Get the common rates between AP and STA supported rates */
208 if (mwifiex_get_common_rates(priv, out_rates, MWIFIEX_SUPPORTED_RATES,
209 card_rates, card_rates_size)) {
210 *out_rates_size = 0;
211 dev_err(priv->adapter->dev, "%s: cannot get common rates\n",
212 __func__);
213 return -1;
214 }
215
216 *out_rates_size =
217 min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES);
218
219 return 0;
220}
221
222/*
223 * This function updates the scan entry TSF timestamps to reflect
224 * a new association.
225 */
226static void
227mwifiex_update_tsf_timestamps(struct mwifiex_private *priv,
228 struct mwifiex_bssdescriptor *new_bss_desc)
229{
230 struct mwifiex_adapter *adapter = priv->adapter;
231 u32 table_idx;
232 long long new_tsf_base;
233 signed long long tsf_delta;
234
235 memcpy(&new_tsf_base, new_bss_desc->time_stamp, sizeof(new_tsf_base));
236
237 tsf_delta = new_tsf_base - new_bss_desc->network_tsf;
238
239 dev_dbg(adapter->dev, "info: TSF: update TSF timestamps, "
240 "0x%016llx -> 0x%016llx\n",
241 new_bss_desc->network_tsf, new_tsf_base);
242
243 for (table_idx = 0; table_idx < adapter->num_in_scan_table;
244 table_idx++)
245 adapter->scan_table[table_idx].network_tsf += tsf_delta;
246}
247
248/*
249 * This function appends a WAPI IE.
250 *
251 * This function is called from the network join command preparation routine.
252 *
253 * If the IE buffer has been setup by the application, this routine appends
254 * the buffer as a WAPI TLV type to the request.
255 */
256static int
257mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer)
258{
259 int retLen = 0;
260 struct mwifiex_ie_types_header ie_header;
261
262 /* Null Checks */
263 if (buffer == NULL)
264 return 0;
265 if (*buffer == NULL)
266 return 0;
267
268 /*
269 * If there is a wapi ie buffer setup, append it to the return
270 * parameter buffer pointer.
271 */
272 if (priv->wapi_ie_len) {
273 dev_dbg(priv->adapter->dev, "cmd: append wapi ie %d to %p\n",
274 priv->wapi_ie_len, *buffer);
275
276 /* Wrap the generic IE buffer with a pass through TLV type */
277 ie_header.type = cpu_to_le16(TLV_TYPE_WAPI_IE);
278 ie_header.len = cpu_to_le16(priv->wapi_ie_len);
279 memcpy(*buffer, &ie_header, sizeof(ie_header));
280
281 /* Increment the return size and the return buffer pointer
282 param */
283 *buffer += sizeof(ie_header);
284 retLen += sizeof(ie_header);
285
286 /* Copy the wapi IE buffer to the output buffer, advance
287 pointer */
288 memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len);
289
290 /* Increment the return size and the return buffer pointer
291 param */
292 *buffer += priv->wapi_ie_len;
293 retLen += priv->wapi_ie_len;
294
295 }
296 /* return the length appended to the buffer */
297 return retLen;
298}
299
300/*
301 * This function appends rsn ie tlv for wpa/wpa2 security modes.
302 * It is called from the network join command preparation routine.
303 */
304static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private *priv,
305 u8 **buffer)
306{
307 struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv;
308 int rsn_ie_len;
309
310 if (!buffer || !(*buffer))
311 return 0;
312
313 rsn_ie_tlv = (struct mwifiex_ie_types_rsn_param_set *) (*buffer);
314 rsn_ie_tlv->header.type = cpu_to_le16((u16) priv->wpa_ie[0]);
315 rsn_ie_tlv->header.type = cpu_to_le16(
316 le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF);
317 rsn_ie_tlv->header.len = cpu_to_le16((u16) priv->wpa_ie[1]);
318 rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len)
319 & 0x00FF);
320 if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2))
321 memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2],
322 le16_to_cpu(rsn_ie_tlv->header.len));
323 else
324 return -1;
325
326 rsn_ie_len = sizeof(rsn_ie_tlv->header) +
327 le16_to_cpu(rsn_ie_tlv->header.len);
328 *buffer += rsn_ie_len;
329
330 return rsn_ie_len;
331}
332
333/*
334 * This function prepares command for association.
335 *
336 * This sets the following parameters -
337 * - Peer MAC address
338 * - Listen interval
339 * - Beacon interval
340 * - Capability information
341 *
342 * ...and the following TLVs, as required -
343 * - SSID TLV
344 * - PHY TLV
345 * - SS TLV
346 * - Rates TLV
347 * - Authentication TLV
348 * - Channel TLV
349 * - WPA/WPA2 IE
350 * - 11n TLV
351 * - Vendor specific TLV
352 * - WMM TLV
353 * - WAPI IE
354 * - Generic IE
355 * - TSF TLV
356 *
357 * Preparation also includes -
358 * - Setting command ID and proper size
359 * - Ensuring correct endian-ness
360 */
361int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
362 struct host_cmd_ds_command *cmd,
363 void *data_buf)
364{
365 struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate;
366 struct mwifiex_bssdescriptor *bss_desc;
367 struct mwifiex_ie_types_ssid_param_set *ssid_tlv;
368 struct mwifiex_ie_types_phy_param_set *phy_tlv;
369 struct mwifiex_ie_types_ss_param_set *ss_tlv;
370 struct mwifiex_ie_types_rates_param_set *rates_tlv;
371 struct mwifiex_ie_types_auth_type *auth_tlv;
372 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
373 u8 rates[MWIFIEX_SUPPORTED_RATES];
374 u32 rates_size;
375 u16 tmp_cap;
376 u8 *pos;
377 int rsn_ie_len = 0;
378
379 bss_desc = (struct mwifiex_bssdescriptor *) data_buf;
380 pos = (u8 *) assoc;
381
382 mwifiex_cfg_tx_buf(priv, bss_desc);
383
384 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
385
386 /* Save so we know which BSS Desc to use in the response handler */
387 priv->attempted_bss_desc = bss_desc;
388
389 memcpy(assoc->peer_sta_addr,
390 bss_desc->mac_address, sizeof(assoc->peer_sta_addr));
391 pos += sizeof(assoc->peer_sta_addr);
392
393 /* Set the listen interval */
394 assoc->listen_interval = cpu_to_le16(priv->listen_interval);
395 /* Set the beacon period */
396 assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period);
397
398 pos += sizeof(assoc->cap_info_bitmap);
399 pos += sizeof(assoc->listen_interval);
400 pos += sizeof(assoc->beacon_period);
401 pos += sizeof(assoc->dtim_period);
402
403 ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos;
404 ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID);
405 ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len);
406 memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid,
407 le16_to_cpu(ssid_tlv->header.len));
408 pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len);
409
410 phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos;
411 phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS);
412 phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set));
413 memcpy(&phy_tlv->fh_ds.ds_param_set,
414 &bss_desc->phy_param_set.ds_param_set.current_chan,
415 sizeof(phy_tlv->fh_ds.ds_param_set));
416 pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len);
417
418 ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos;
419 ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS);
420 ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set));
421 pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len);
422
423 /* Get the common rates supported between the driver and the BSS Desc */
424 if (mwifiex_setup_rates_from_bssdesc
425 (priv, bss_desc, rates, &rates_size))
426 return -1;
427
428 /* Save the data rates into Current BSS state structure */
429 priv->curr_bss_params.num_of_rates = rates_size;
430 memcpy(&priv->curr_bss_params.data_rates, rates, rates_size);
431
432 /* Setup the Rates TLV in the association command */
433 rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos;
434 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
435 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
436 memcpy(rates_tlv->rates, rates, rates_size);
437 pos += sizeof(rates_tlv->header) + rates_size;
438 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: rates size = %d\n",
439 rates_size);
440
Marc Yang203afec2011-03-24 20:49:39 -0700441 /* Add the Authentication type to be used for Auth frames */
442 auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
443 auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
444 auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
445 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
446 auth_tlv->auth_type = cpu_to_le16(
447 (u16) priv->sec_info.authentication_mode);
448 else
Marc Yangf986b6d2011-03-28 17:55:42 -0700449 auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM);
Marc Yang203afec2011-03-24 20:49:39 -0700450
451 pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700452
453 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)
454 && !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
455 && (!bss_desc->disable_11n)
456 && (priv->adapter->config_bands & BAND_GN
457 || priv->adapter->config_bands & BAND_AN)
458 && (bss_desc->bcn_ht_cap)
459 )
460 ) {
461 /* Append a channel TLV for the channel the attempted AP was
462 found on */
463 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
464 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
465 chan_tlv->header.len =
466 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
467
468 memset(chan_tlv->chan_scan_param, 0x00,
469 sizeof(struct mwifiex_chan_scan_param_set));
470 chan_tlv->chan_scan_param[0].chan_number =
471 (bss_desc->phy_param_set.ds_param_set.current_chan);
472 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
473 chan_tlv->chan_scan_param[0].chan_number);
474
475 chan_tlv->chan_scan_param[0].radio_type =
476 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
477
478 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
479 chan_tlv->chan_scan_param[0].radio_type);
480 pos += sizeof(chan_tlv->header) +
481 sizeof(struct mwifiex_chan_scan_param_set);
482 }
483
484 if (!priv->wps.session_enable) {
485 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
486 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
487
488 if (rsn_ie_len == -1)
489 return -1;
490 }
491
492 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
493 && (!bss_desc->disable_11n)
494 && (priv->adapter->config_bands & BAND_GN
495 || priv->adapter->config_bands & BAND_AN))
496 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
497
498 /* Append vendor specific IE TLV */
499 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
500
501 mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
502 bss_desc->bcn_ht_cap);
503 if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
504 mwifiex_cmd_append_wapi_ie(priv, &pos);
505
506
507 mwifiex_cmd_append_generic_ie(priv, &pos);
508
509 mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
510
511 cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
512
513 /* Set the Capability info at last */
514 tmp_cap = bss_desc->cap_info_bitmap;
515
516 if (priv->adapter->config_bands == BAND_B)
Bing Zhaob93f85f2011-03-25 19:47:01 -0700517 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700518
519 tmp_cap &= CAPINFO_MASK;
520 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
521 tmp_cap, CAPINFO_MASK);
522 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
523
524 return 0;
525}
526
527/*
528 * Association firmware command response handler
529 *
530 * The response buffer for the association command has the following
531 * memory layout.
532 *
533 * For cases where an association response was not received (indicated
534 * by the CapInfo and AId field):
535 *
536 * .------------------------------------------------------------.
537 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
538 * .------------------------------------------------------------.
539 * | cap_info/Error Return(t_u16): |
540 * | 0xFFFF(-1): Internal error |
541 * | 0xFFFE(-2): Authentication unhandled message |
542 * | 0xFFFD(-3): Authentication refused |
543 * | 0xFFFC(-4): Timeout waiting for AP response |
544 * .------------------------------------------------------------.
545 * | status_code(t_u16): |
546 * | If cap_info is -1: |
547 * | An internal firmware failure prevented the |
548 * | command from being processed. The status_code |
549 * | will be set to 1. |
550 * | |
551 * | If cap_info is -2: |
552 * | An authentication frame was received but was |
553 * | not handled by the firmware. IEEE Status |
554 * | code for the failure is returned. |
555 * | |
556 * | If cap_info is -3: |
557 * | An authentication frame was received and the |
558 * | status_code is the IEEE Status reported in the |
559 * | response. |
560 * | |
561 * | If cap_info is -4: |
562 * | (1) Association response timeout |
563 * | (2) Authentication response timeout |
564 * .------------------------------------------------------------.
565 * | a_id(t_u16): 0xFFFF |
566 * .------------------------------------------------------------.
567 *
568 *
569 * For cases where an association response was received, the IEEE
570 * standard association response frame is returned:
571 *
572 * .------------------------------------------------------------.
573 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
574 * .------------------------------------------------------------.
575 * | cap_info(t_u16): IEEE Capability |
576 * .------------------------------------------------------------.
577 * | status_code(t_u16): IEEE Status Code |
578 * .------------------------------------------------------------.
579 * | a_id(t_u16): IEEE Association ID |
580 * .------------------------------------------------------------.
581 * | IEEE IEs(variable): Any received IEs comprising the |
582 * | remaining portion of a received |
583 * | association response frame. |
584 * .------------------------------------------------------------.
585 *
586 * For simplistic handling, the status_code field can be used to determine
587 * an association success (0) or failure (non-zero).
588 */
589int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700590 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700591{
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700592 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700593 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700594 struct ieee_types_assoc_rsp *assoc_rsp;
595 struct mwifiex_bssdescriptor *bss_desc;
596 u8 enable_data = true;
597
598 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
599
600 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
601 sizeof(priv->assoc_rsp_buf));
602
603 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
604
605 if (le16_to_cpu(assoc_rsp->status_code)) {
606 priv->adapter->dbg.num_cmd_assoc_failure++;
607 dev_err(priv->adapter->dev, "ASSOC_RESP: association failed, "
608 "status code = %d, error = 0x%x, a_id = 0x%x\n",
609 le16_to_cpu(assoc_rsp->status_code),
610 le16_to_cpu(assoc_rsp->cap_info_bitmap),
611 le16_to_cpu(assoc_rsp->a_id));
612
613 ret = -1;
614 goto done;
615 }
616
617 /* Send a Media Connected event, according to the Spec */
618 priv->media_connected = true;
619
620 priv->adapter->ps_state = PS_STATE_AWAKE;
621 priv->adapter->pps_uapsd_mode = false;
622 priv->adapter->tx_lock_flag = false;
623
624 /* Set the attempted BSSID Index to current */
625 bss_desc = priv->attempted_bss_desc;
626
627 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n",
628 bss_desc->ssid.ssid);
629
630 /* Make a copy of current BSSID descriptor */
631 memcpy(&priv->curr_bss_params.bss_descriptor,
632 bss_desc, sizeof(struct mwifiex_bssdescriptor));
633
634 /* Update curr_bss_params */
635 priv->curr_bss_params.bss_descriptor.channel
636 = bss_desc->phy_param_set.ds_param_set.current_chan;
637
638 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
639
640 /*
641 * Adjust the timestamps in the scan table to be relative to the newly
642 * associated AP's TSF
643 */
644 mwifiex_update_tsf_timestamps(priv, bss_desc);
645
646 if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
647 priv->curr_bss_params.wmm_enabled = true;
648 else
649 priv->curr_bss_params.wmm_enabled = false;
650
651 if ((priv->wmm_required || bss_desc->bcn_ht_cap)
652 && priv->curr_bss_params.wmm_enabled)
653 priv->wmm_enabled = true;
654 else
655 priv->wmm_enabled = false;
656
657 priv->curr_bss_params.wmm_uapsd_enabled = false;
658
659 if (priv->wmm_enabled)
660 priv->curr_bss_params.wmm_uapsd_enabled
661 = ((bss_desc->wmm_ie.qos_info_bitmap &
662 IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
663
664 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
665 priv->curr_pkt_filter);
666 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
667 priv->wpa_is_gtk_set = false;
668
669 if (priv->wmm_enabled) {
670 /* Don't re-enable carrier until we get the WMM_GET_STATUS
671 event */
672 enable_data = false;
673 } else {
674 /* Since WMM is not enabled, setup the queues with the
675 defaults */
676 mwifiex_wmm_setup_queue_priorities(priv, NULL);
677 mwifiex_wmm_setup_ac_downgrade(priv);
678 }
679
680 if (enable_data)
681 dev_dbg(priv->adapter->dev,
682 "info: post association, re-enabling data flow\n");
683
684 /* Reset SNR/NF/RSSI values */
685 priv->data_rssi_last = 0;
686 priv->data_nf_last = 0;
687 priv->data_rssi_avg = 0;
688 priv->data_nf_avg = 0;
689 priv->bcn_rssi_last = 0;
690 priv->bcn_nf_last = 0;
691 priv->bcn_rssi_avg = 0;
692 priv->bcn_nf_avg = 0;
693 priv->rxpd_rate = 0;
694 priv->rxpd_htinfo = 0;
695
696 mwifiex_save_curr_bcn(priv);
697
698 priv->adapter->dbg.num_cmd_assoc_success++;
699
700 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n");
701
702 /* Add the ra_list here for infra mode as there will be only 1 ra
703 always */
704 mwifiex_ralist_add(priv,
705 priv->curr_bss_params.bss_descriptor.mac_address);
706
707 if (!netif_carrier_ok(priv->netdev))
708 netif_carrier_on(priv->netdev);
709 if (netif_queue_stopped(priv->netdev))
710 netif_wake_queue(priv->netdev);
711
712 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
713 priv->scan_block = true;
714
715done:
716 /* Need to indicate IOCTL complete */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700717 if (adapter->curr_cmd->wait_q_enabled) {
718 if (ret)
719 adapter->cmd_wait_q.status = -1;
720 else
721 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700722 }
723
724 return ret;
725}
726
727/*
728 * This function prepares command for ad-hoc start.
729 *
730 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
731 * parameters, probe delay, and capability information. Firmware
732 * will fill up beacon period, basic rates and operational rates.
733 *
734 * In addition, the following TLVs are added -
735 * - Channel TLV
736 * - Vendor specific IE
737 * - WPA/WPA2 IE
738 * - HT Capabilities IE
739 * - HT Information IE
740 *
741 * Preparation also includes -
742 * - Setting command ID and proper size
743 * - Ensuring correct endian-ness
744 */
745int
746mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
747 struct host_cmd_ds_command *cmd, void *data_buf)
748{
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700749 int rsn_ie_len = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700750 struct mwifiex_adapter *adapter = priv->adapter;
751 struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
752 &cmd->params.adhoc_start;
753 struct mwifiex_bssdescriptor *bss_desc;
754 u32 cmd_append_size = 0;
755 u32 i;
756 u16 tmp_cap;
757 uint16_t ht_cap_info;
758 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
759
760 struct mwifiex_ie_types_htcap *ht_cap;
761 struct mwifiex_ie_types_htinfo *ht_info;
762 u8 *pos = (u8 *) adhoc_start +
763 sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
764
765 if (!adapter)
766 return -1;
767
768 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
769
770 bss_desc = &priv->curr_bss_params.bss_descriptor;
771 priv->attempted_bss_desc = bss_desc;
772
773 /*
774 * Fill in the parameters for 2 data structures:
775 * 1. struct host_cmd_ds_802_11_ad_hoc_start command
776 * 2. bss_desc
777 * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
778 * probe delay, and Cap info.
779 * Firmware will fill up beacon period, Basic rates
780 * and operational rates.
781 */
782
783 memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
784
785 memcpy(adhoc_start->ssid,
786 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
787 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
788
789 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
790 adhoc_start->ssid);
791
792 memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
793 memcpy(bss_desc->ssid.ssid,
794 ((struct mwifiex_802_11_ssid *) data_buf)->ssid,
795 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len);
796
797 bss_desc->ssid.ssid_len =
798 ((struct mwifiex_802_11_ssid *) data_buf)->ssid_len;
799
800 /* Set the BSS mode */
801 adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700802 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700803 adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
804 bss_desc->beacon_period = priv->beacon_period;
805
806 /* Set Physical param set */
807/* Parameter IE Id */
808#define DS_PARA_IE_ID 3
809/* Parameter IE length */
810#define DS_PARA_IE_LEN 1
811
812 adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
813 adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
814
815 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
816 (priv, adapter->adhoc_start_band, (u16)
817 priv->adhoc_channel)) {
818 struct mwifiex_chan_freq_power *cfp;
819 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
820 adapter->adhoc_start_band, FIRST_VALID_CHANNEL);
821 if (cfp)
822 priv->adhoc_channel = (u8) cfp->channel;
823 }
824
825 if (!priv->adhoc_channel) {
826 dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
827 return -1;
828 }
829
830 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
831 priv->adhoc_channel);
832
833 priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
834 priv->curr_bss_params.band = adapter->adhoc_start_band;
835
836 bss_desc->channel = priv->adhoc_channel;
837 adhoc_start->phy_param_set.ds_param_set.current_chan =
838 priv->adhoc_channel;
839
840 memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
841 sizeof(union ieee_types_phy_param_set));
842
843 /* Set IBSS param set */
844/* IBSS parameter IE Id */
845#define IBSS_PARA_IE_ID 6
846/* IBSS parameter IE length */
847#define IBSS_PARA_IE_LEN 2
848
849 adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
850 adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
851 adhoc_start->ss_param_set.ibss_param_set.atim_window
852 = cpu_to_le16(priv->atim_window);
853 memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
854 sizeof(union ieee_types_ss_param_set));
855
856 /* Set Capability info */
857 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
858 tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap);
859 tmp_cap &= ~WLAN_CAPABILITY_ESS;
860 tmp_cap |= WLAN_CAPABILITY_IBSS;
861
862 /* Set up privacy in bss_desc */
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700863 if (priv->sec_info.encryption_mode) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700864 /* Ad-Hoc capability privacy on */
865 dev_dbg(adapter->dev,
866 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
867 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
868 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
869 } else {
870 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
871 " setting privacy to ACCEPT ALL\n");
872 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
873 }
874
875 memset(adhoc_start->DataRate, 0, sizeof(adhoc_start->DataRate));
876 mwifiex_get_active_data_rates(priv, adhoc_start->DataRate);
877 if ((adapter->adhoc_start_band & BAND_G) &&
878 (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700879 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700880 HostCmd_ACT_GEN_SET, 0,
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700881 &priv->curr_pkt_filter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700882 dev_err(adapter->dev,
883 "ADHOC_S_CMD: G Protection config failed\n");
884 return -1;
885 }
886 }
887 /* Find the last non zero */
888 for (i = 0; i < sizeof(adhoc_start->DataRate) &&
889 adhoc_start->DataRate[i];
890 i++)
891 ;
892
893 priv->curr_bss_params.num_of_rates = i;
894
895 /* Copy the ad-hoc creating rates into Current BSS rate structure */
896 memcpy(&priv->curr_bss_params.data_rates,
897 &adhoc_start->DataRate, priv->curr_bss_params.num_of_rates);
898
899 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n",
900 adhoc_start->DataRate[0], adhoc_start->DataRate[1],
901 adhoc_start->DataRate[2], adhoc_start->DataRate[3]);
902
903 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
904
905 if (IS_SUPPORT_MULTI_BANDS(adapter)) {
906 /* Append a channel TLV */
907 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
908 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
909 chan_tlv->header.len =
910 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
911
912 memset(chan_tlv->chan_scan_param, 0x00,
913 sizeof(struct mwifiex_chan_scan_param_set));
914 chan_tlv->chan_scan_param[0].chan_number =
915 (u8) priv->curr_bss_params.bss_descriptor.channel;
916
917 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
918 chan_tlv->chan_scan_param[0].chan_number);
919
920 chan_tlv->chan_scan_param[0].radio_type
921 = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
922 if (adapter->adhoc_start_band & BAND_GN
923 || adapter->adhoc_start_band & BAND_AN) {
924 if (adapter->chan_offset == SEC_CHANNEL_ABOVE)
925 chan_tlv->chan_scan_param[0].radio_type |=
926 SECOND_CHANNEL_ABOVE;
927 else if (adapter->chan_offset == SEC_CHANNEL_BELOW)
928 chan_tlv->chan_scan_param[0].radio_type |=
929 SECOND_CHANNEL_BELOW;
930 }
931 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
932 chan_tlv->chan_scan_param[0].radio_type);
933 pos += sizeof(chan_tlv->header) +
934 sizeof(struct mwifiex_chan_scan_param_set);
935 cmd_append_size +=
936 sizeof(chan_tlv->header) +
937 sizeof(struct mwifiex_chan_scan_param_set);
938 }
939
940 /* Append vendor specific IE TLV */
941 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
942 MWIFIEX_VSIE_MASK_ADHOC, &pos);
943
944 if (priv->sec_info.wpa_enabled) {
945 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
946 if (rsn_ie_len == -1)
947 return -1;
948 cmd_append_size += rsn_ie_len;
949 }
950
951 if (adapter->adhoc_11n_enabled) {
952 {
953 ht_cap = (struct mwifiex_ie_types_htcap *) pos;
954 memset(ht_cap, 0,
955 sizeof(struct mwifiex_ie_types_htcap));
956 ht_cap->header.type =
957 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
958 ht_cap->header.len =
959 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
960 ht_cap_info = le16_to_cpu(ht_cap->ht_cap.cap_info);
961
Marc Yang6d2bd912011-03-25 19:47:02 -0700962 ht_cap_info |= IEEE80211_HT_CAP_SGI_20;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700963 if (adapter->chan_offset) {
Marc Yang6d2bd912011-03-25 19:47:02 -0700964 ht_cap_info |= IEEE80211_HT_CAP_SGI_40;
965 ht_cap_info |= IEEE80211_HT_CAP_DSSSCCK40;
966 ht_cap_info |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700967 SETHT_MCS32(ht_cap->ht_cap.mcs.rx_mask);
968 }
969
970 ht_cap->ht_cap.ampdu_params_info
Marc Yang6d2bd912011-03-25 19:47:02 -0700971 = IEEE80211_HT_MAX_AMPDU_64K;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700972 ht_cap->ht_cap.mcs.rx_mask[0] = 0xff;
973 pos += sizeof(struct mwifiex_ie_types_htcap);
974 cmd_append_size +=
975 sizeof(struct mwifiex_ie_types_htcap);
976 }
977 {
978 ht_info = (struct mwifiex_ie_types_htinfo *) pos;
979 memset(ht_info, 0,
980 sizeof(struct mwifiex_ie_types_htinfo));
981 ht_info->header.type =
982 cpu_to_le16(WLAN_EID_HT_INFORMATION);
983 ht_info->header.len =
984 cpu_to_le16(sizeof(struct ieee80211_ht_info));
985 ht_info->ht_info.control_chan =
986 (u8) priv->curr_bss_params.bss_descriptor.
987 channel;
988 if (adapter->chan_offset) {
989 ht_info->ht_info.ht_param =
990 adapter->chan_offset;
Marc Yang6d2bd912011-03-25 19:47:02 -0700991 ht_info->ht_info.ht_param |=
992 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700993 }
994 ht_info->ht_info.operation_mode =
Amitkumar Karwara3731652011-04-15 20:50:41 -0700995 cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700996 ht_info->ht_info.basic_set[0] = 0xff;
997 pos += sizeof(struct mwifiex_ie_types_htinfo);
998 cmd_append_size +=
999 sizeof(struct mwifiex_ie_types_htinfo);
1000 }
1001 }
1002
1003 cmd->size = cpu_to_le16((u16)
1004 (sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
1005 + S_DS_GEN + cmd_append_size));
1006
1007 if (adapter->adhoc_start_band == BAND_B)
Bing Zhaob93f85f2011-03-25 19:47:01 -07001008 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001009 else
Bing Zhaob93f85f2011-03-25 19:47:01 -07001010 tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001011
1012 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1013
1014 return 0;
1015}
1016
1017/*
1018 * This function prepares command for ad-hoc join.
1019 *
1020 * Most of the parameters are set up by copying from the target BSS descriptor
1021 * from the scan response.
1022 *
1023 * In addition, the following TLVs are added -
1024 * - Channel TLV
1025 * - Vendor specific IE
1026 * - WPA/WPA2 IE
1027 * - 11n IE
1028 *
1029 * Preparation also includes -
1030 * - Setting command ID and proper size
1031 * - Ensuring correct endian-ness
1032 */
1033int
1034mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1035 struct host_cmd_ds_command *cmd, void *data_buf)
1036{
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001037 int rsn_ie_len = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001038 struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
1039 &cmd->params.adhoc_join;
1040 struct mwifiex_bssdescriptor *bss_desc =
1041 (struct mwifiex_bssdescriptor *) data_buf;
1042 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
1043 u32 cmd_append_size = 0;
1044 u16 tmp_cap;
1045 u32 i, rates_size = 0;
1046 u16 curr_pkt_filter;
1047 u8 *pos =
1048 (u8 *) adhoc_join +
1049 sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
1050
1051/* Use G protection */
1052#define USE_G_PROTECTION 0x02
1053 if (bss_desc->erp_flags & USE_G_PROTECTION) {
1054 curr_pkt_filter =
1055 priv->
1056 curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
1057
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001058 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001059 HostCmd_ACT_GEN_SET, 0,
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001060 &curr_pkt_filter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001061 dev_err(priv->adapter->dev,
1062 "ADHOC_J_CMD: G Protection config failed\n");
1063 return -1;
1064 }
1065 }
1066
1067 priv->attempted_bss_desc = bss_desc;
1068
1069 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1070
1071 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1072
1073 adhoc_join->bss_descriptor.beacon_period
1074 = cpu_to_le16(bss_desc->beacon_period);
1075
1076 memcpy(&adhoc_join->bss_descriptor.bssid,
1077 &bss_desc->mac_address, ETH_ALEN);
1078
1079 memcpy(&adhoc_join->bss_descriptor.ssid,
1080 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1081
1082 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1083 &bss_desc->phy_param_set,
1084 sizeof(union ieee_types_phy_param_set));
1085
1086 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1087 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1088
1089 tmp_cap = bss_desc->cap_info_bitmap;
1090
1091 tmp_cap &= CAPINFO_MASK;
1092
1093 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: tmp_cap=%4X"
1094 " CAPINFO_MASK=%4lX\n", tmp_cap, CAPINFO_MASK);
1095
1096 /* Information on BSSID descriptor passed to FW */
1097 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID = %pM, SSID = %s\n",
1098 adhoc_join->bss_descriptor.bssid,
1099 adhoc_join->bss_descriptor.ssid);
1100
1101 for (i = 0; bss_desc->supported_rates[i] &&
1102 i < MWIFIEX_SUPPORTED_RATES;
1103 i++)
1104 ;
1105 rates_size = i;
1106
1107 /* Copy Data Rates from the Rates recorded in scan response */
1108 memset(adhoc_join->bss_descriptor.data_rates, 0,
1109 sizeof(adhoc_join->bss_descriptor.data_rates));
1110 memcpy(adhoc_join->bss_descriptor.data_rates,
1111 bss_desc->supported_rates, rates_size);
1112
1113 /* Copy the adhoc join rates into Current BSS state structure */
1114 priv->curr_bss_params.num_of_rates = rates_size;
1115 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1116 rates_size);
1117
1118 /* Copy the channel information */
1119 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1120 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1121
1122 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED
1123 || priv->sec_info.wpa_enabled)
1124 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1125
1126 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1127 /* Append a channel TLV */
1128 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1129 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1130 chan_tlv->header.len =
1131 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1132
1133 memset(chan_tlv->chan_scan_param, 0x00,
1134 sizeof(struct mwifiex_chan_scan_param_set));
1135 chan_tlv->chan_scan_param[0].chan_number =
1136 (bss_desc->phy_param_set.ds_param_set.current_chan);
1137 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan = %d\n",
1138 chan_tlv->chan_scan_param[0].chan_number);
1139
1140 chan_tlv->chan_scan_param[0].radio_type =
1141 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1142
1143 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band = %d\n",
1144 chan_tlv->chan_scan_param[0].radio_type);
1145 pos += sizeof(chan_tlv->header) +
1146 sizeof(struct mwifiex_chan_scan_param_set);
1147 cmd_append_size += sizeof(chan_tlv->header) +
1148 sizeof(struct mwifiex_chan_scan_param_set);
1149 }
1150
1151 if (priv->sec_info.wpa_enabled)
1152 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1153 if (rsn_ie_len == -1)
1154 return -1;
1155 cmd_append_size += rsn_ie_len;
1156
1157 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1158 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1159 bss_desc, &pos);
1160
1161 /* Append vendor specific IE TLV */
1162 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1163 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1164
1165 cmd->size = cpu_to_le16((u16)
1166 (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1167 + S_DS_GEN + cmd_append_size));
1168
1169 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1170
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001171 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001172}
1173
1174/*
1175 * This function handles the command response of ad-hoc start and
1176 * ad-hoc join.
1177 *
1178 * The function generates a device-connected event to notify
1179 * the applications, in case of successful ad-hoc start/join, and
1180 * saves the beacon buffer.
1181 */
1182int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001183 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001184{
1185 int ret = 0;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001186 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001187 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1188 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001189
1190 adhoc_result = &resp->params.adhoc_result;
1191
1192 bss_desc = priv->attempted_bss_desc;
1193
1194 /* Join result code 0 --> SUCCESS */
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001195 if (le16_to_cpu(resp->result)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001196 dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
1197 if (priv->media_connected)
1198 mwifiex_reset_connect_state(priv);
1199
1200 memset(&priv->curr_bss_params.bss_descriptor,
1201 0x00, sizeof(struct mwifiex_bssdescriptor));
1202
1203 ret = -1;
1204 goto done;
1205 }
1206
1207 /* Send a Media Connected event, according to the Spec */
1208 priv->media_connected = true;
1209
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001210 if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001211 dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
1212 bss_desc->ssid.ssid);
1213
1214 /* Update the created network descriptor with the new BSSID */
1215 memcpy(bss_desc->mac_address,
1216 adhoc_result->bssid, ETH_ALEN);
1217
1218 priv->adhoc_state = ADHOC_STARTED;
1219 } else {
1220 /*
1221 * Now the join cmd should be successful.
1222 * If BSSID has changed use SSID to compare instead of BSSID
1223 */
1224 dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
1225 bss_desc->ssid.ssid);
1226
1227 /*
1228 * Make a copy of current BSSID descriptor, only needed for
1229 * join since the current descriptor is already being used
1230 * for adhoc start
1231 */
1232 memcpy(&priv->curr_bss_params.bss_descriptor,
1233 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1234
1235 priv->adhoc_state = ADHOC_JOINED;
1236 }
1237
1238 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
1239 priv->adhoc_channel);
1240 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
1241 priv->curr_bss_params.bss_descriptor.mac_address);
1242
1243 if (!netif_carrier_ok(priv->netdev))
1244 netif_carrier_on(priv->netdev);
1245 if (netif_queue_stopped(priv->netdev))
1246 netif_wake_queue(priv->netdev);
1247
1248 mwifiex_save_curr_bcn(priv);
1249
1250done:
1251 /* Need to indicate IOCTL complete */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001252 if (adapter->curr_cmd->wait_q_enabled) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001253 if (ret)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001254 adapter->cmd_wait_q.status = -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001255 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001256 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257
1258 }
1259
1260 return ret;
1261}
1262
1263/*
1264 * This function associates to a specific BSS discovered in a scan.
1265 *
1266 * It clears any past association response stored for application
1267 * retrieval and calls the command preparation routine to send the
1268 * command to firmware.
1269 */
1270int mwifiex_associate(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001271 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001272{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001273 u8 current_bssid[ETH_ALEN];
1274
1275 /* Return error if the adapter or table entry is not marked as infra */
Bing Zhaoeecd8252011-03-28 17:55:41 -07001276 if ((priv->bss_mode != NL80211_IFTYPE_STATION) ||
1277 (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001278 return -1;
1279
1280 memcpy(&current_bssid,
1281 &priv->curr_bss_params.bss_descriptor.mac_address,
1282 sizeof(current_bssid));
1283
1284 /* Clear any past association response stored for application
1285 retrieval */
1286 priv->assoc_rsp_size = 0;
1287
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001288 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_ASSOCIATE,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001289 HostCmd_ACT_GEN_SET, 0, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001290}
1291
1292/*
1293 * This function starts an ad-hoc network.
1294 *
1295 * It calls the command preparation routine to send the command to firmware.
1296 */
1297int
1298mwifiex_adhoc_start(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001299 struct mwifiex_802_11_ssid *adhoc_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001300{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001301 dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
1302 priv->adhoc_channel);
1303 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1304 priv->curr_bss_params.bss_descriptor.channel);
1305 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
1306 priv->curr_bss_params.band);
1307
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001308 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_START,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001309 HostCmd_ACT_GEN_SET, 0, adhoc_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001310}
1311
1312/*
1313 * This function joins an ad-hoc network found in a previous scan.
1314 *
1315 * It calls the command preparation routine to send the command to firmware,
1316 * if already not connected to the requested SSID.
1317 */
1318int mwifiex_adhoc_join(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001319 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001320{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001321 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
1322 priv->curr_bss_params.bss_descriptor.ssid.ssid);
1323 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
1324 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
1325 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
1326 bss_desc->ssid.ssid);
1327 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
1328 bss_desc->ssid.ssid_len);
1329
1330 /* Check if the requested SSID is already joined */
1331 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1332 !mwifiex_ssid_cmp(&bss_desc->ssid,
1333 &priv->curr_bss_params.bss_descriptor.ssid) &&
1334 (priv->curr_bss_params.bss_descriptor.bss_mode ==
Bing Zhaoeecd8252011-03-28 17:55:41 -07001335 NL80211_IFTYPE_ADHOC)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001336 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
1337 " is the same as current; not attempting to re-join\n");
1338 return -1;
1339 }
1340
1341 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1342 priv->curr_bss_params.bss_descriptor.channel);
1343 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
1344 priv->curr_bss_params.band);
1345
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001346 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001347 HostCmd_ACT_GEN_SET, 0, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001348}
1349
1350/*
1351 * This function deauthenticates/disconnects from infra network by sending
1352 * deauthentication request.
1353 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001354static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001355{
1356 u8 mac_address[ETH_ALEN];
1357 int ret = 0;
1358 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
1359
1360 if (mac) {
1361 if (!memcmp(mac, zero_mac, sizeof(zero_mac)))
1362 memcpy((u8 *) &mac_address,
1363 (u8 *) &priv->curr_bss_params.bss_descriptor.
1364 mac_address, ETH_ALEN);
1365 else
1366 memcpy((u8 *) &mac_address, (u8 *) mac, ETH_ALEN);
1367 } else {
1368 memcpy((u8 *) &mac_address, (u8 *) &priv->curr_bss_params.
1369 bss_descriptor.mac_address, ETH_ALEN);
1370 }
1371
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001372 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
1373 HostCmd_ACT_GEN_SET, 0, &mac_address);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001374
1375 return ret;
1376}
1377
1378/*
1379 * This function deauthenticates/disconnects from a BSS.
1380 *
1381 * In case of infra made, it sends deauthentication request, and
1382 * in case of ad-hoc mode, a stop network request is sent to the firmware.
1383 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001384int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001385{
1386 int ret = 0;
1387
1388 if (priv->media_connected) {
Bing Zhaoeecd8252011-03-28 17:55:41 -07001389 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001390 ret = mwifiex_deauthenticate_infra(priv, mac);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001391 } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001392 ret = mwifiex_send_cmd_sync(priv,
1393 HostCmd_CMD_802_11_AD_HOC_STOP,
1394 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001395 }
1396 }
1397
1398 return ret;
1399}
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001400EXPORT_SYMBOL_GPL(mwifiex_deauthenticate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001401
1402/*
1403 * This function converts band to radio type used in channel TLV.
1404 */
1405u8
1406mwifiex_band_to_radio_type(u8 band)
1407{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001408 switch (band) {
1409 case BAND_A:
1410 case BAND_AN:
1411 case BAND_A | BAND_AN:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001412 return HostCmd_SCAN_RADIO_TYPE_A;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001413 case BAND_B:
1414 case BAND_G:
1415 case BAND_B | BAND_G:
1416 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001417 return HostCmd_SCAN_RADIO_TYPE_BG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001418 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001419}