]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/net/wireless/mwifiex/join.c
2ee48e7067bfc6b4a7bb596a589811a692d7f9bc
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / mwifiex / join.c
1 /*
2 * Marvell Wireless LAN device driver: association and ad-hoc start/join
3 *
4 * Copyright (C) 2011-2014, 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 #include "11ac.h"
28
29 #define CAPINFO_MASK (~(BIT(15) | BIT(14) | BIT(12) | BIT(11) | BIT(9)))
30
31 /*
32 * Append a generic IE as a pass through TLV to a TLV buffer.
33 *
34 * This function is called from the network join command preparation routine.
35 *
36 * If the IE buffer has been setup by the application, this routine appends
37 * the buffer as a pass through TLV type to the request.
38 */
39 static int
40 mwifiex_cmd_append_generic_ie(struct mwifiex_private *priv, u8 **buffer)
41 {
42 int ret_len = 0;
43 struct mwifiex_ie_types_header ie_header;
44
45 /* Null Checks */
46 if (!buffer)
47 return 0;
48 if (!(*buffer))
49 return 0;
50
51 /*
52 * If there is a generic ie buffer setup, append it to the return
53 * parameter buffer pointer.
54 */
55 if (priv->gen_ie_buf_len) {
56 dev_dbg(priv->adapter->dev,
57 "info: %s: append generic ie len %d to %p\n",
58 __func__, priv->gen_ie_buf_len, *buffer);
59
60 /* Wrap the generic IE buffer with a pass through TLV type */
61 ie_header.type = cpu_to_le16(TLV_TYPE_PASSTHROUGH);
62 ie_header.len = cpu_to_le16(priv->gen_ie_buf_len);
63 memcpy(*buffer, &ie_header, sizeof(ie_header));
64
65 /* Increment the return size and the return buffer pointer
66 param */
67 *buffer += sizeof(ie_header);
68 ret_len += sizeof(ie_header);
69
70 /* Copy the generic IE buffer to the output buffer, advance
71 pointer */
72 memcpy(*buffer, priv->gen_ie_buf, priv->gen_ie_buf_len);
73
74 /* Increment the return size and the return buffer pointer
75 param */
76 *buffer += priv->gen_ie_buf_len;
77 ret_len += priv->gen_ie_buf_len;
78
79 /* Reset the generic IE buffer */
80 priv->gen_ie_buf_len = 0;
81 }
82
83 /* return the length appended to the buffer */
84 return ret_len;
85 }
86
87 /*
88 * Append TSF tracking info from the scan table for the target AP.
89 *
90 * This function is called from the network join command preparation routine.
91 *
92 * The TSF table TSF sent to the firmware contains two TSF values:
93 * - The TSF of the target AP from its previous beacon/probe response
94 * - The TSF timestamp of our local MAC at the time we observed the
95 * beacon/probe response.
96 *
97 * The firmware uses the timestamp values to set an initial TSF value
98 * in the MAC for the new association after a reassociation attempt.
99 */
100 static int
101 mwifiex_cmd_append_tsf_tlv(struct mwifiex_private *priv, u8 **buffer,
102 struct mwifiex_bssdescriptor *bss_desc)
103 {
104 struct mwifiex_ie_types_tsf_timestamp tsf_tlv;
105 __le64 tsf_val;
106
107 /* Null Checks */
108 if (buffer == NULL)
109 return 0;
110 if (*buffer == NULL)
111 return 0;
112
113 memset(&tsf_tlv, 0x00, sizeof(struct mwifiex_ie_types_tsf_timestamp));
114
115 tsf_tlv.header.type = cpu_to_le16(TLV_TYPE_TSFTIMESTAMP);
116 tsf_tlv.header.len = cpu_to_le16(2 * sizeof(tsf_val));
117
118 memcpy(*buffer, &tsf_tlv, sizeof(tsf_tlv.header));
119 *buffer += sizeof(tsf_tlv.header);
120
121 /* TSF at the time when beacon/probe_response was received */
122 tsf_val = cpu_to_le64(bss_desc->fw_tsf);
123 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
124 *buffer += sizeof(tsf_val);
125
126 tsf_val = cpu_to_le64(bss_desc->timestamp);
127
128 dev_dbg(priv->adapter->dev,
129 "info: %s: TSF offset calc: %016llx - %016llx\n",
130 __func__, bss_desc->timestamp, bss_desc->fw_tsf);
131
132 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
133 *buffer += sizeof(tsf_val);
134
135 return sizeof(tsf_tlv.header) + (2 * sizeof(tsf_val));
136 }
137
138 /*
139 * This function finds out the common rates between rate1 and rate2.
140 *
141 * It will fill common rates in rate1 as output if found.
142 *
143 * NOTE: Setting the MSB of the basic rates needs to be taken
144 * care of, either before or after calling this function.
145 */
146 static int mwifiex_get_common_rates(struct mwifiex_private *priv, u8 *rate1,
147 u32 rate1_size, u8 *rate2, u32 rate2_size)
148 {
149 int ret;
150 u8 *ptr = rate1, *tmp;
151 u32 i, j;
152
153 tmp = kmemdup(rate1, rate1_size, GFP_KERNEL);
154 if (!tmp) {
155 dev_err(priv->adapter->dev, "failed to alloc tmp buf\n");
156 return -ENOMEM;
157 }
158
159 memset(rate1, 0, rate1_size);
160
161 for (i = 0; i < rate2_size && rate2[i]; i++) {
162 for (j = 0; j < rate1_size && tmp[j]; j++) {
163 /* Check common rate, excluding the bit for
164 basic rate */
165 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) {
166 *rate1++ = tmp[j];
167 break;
168 }
169 }
170 }
171
172 dev_dbg(priv->adapter->dev, "info: Tx data rate set to %#x\n",
173 priv->data_rate);
174
175 if (!priv->is_data_rate_auto) {
176 while (*ptr) {
177 if ((*ptr & 0x7f) == priv->data_rate) {
178 ret = 0;
179 goto done;
180 }
181 ptr++;
182 }
183 dev_err(priv->adapter->dev, "previously set fixed data rate %#x"
184 " is not compatible with the network\n",
185 priv->data_rate);
186
187 ret = -1;
188 goto done;
189 }
190
191 ret = 0;
192 done:
193 kfree(tmp);
194 return ret;
195 }
196
197 /*
198 * This function creates the intersection of the rates supported by a
199 * target BSS and our adapter settings for use in an assoc/join command.
200 */
201 static int
202 mwifiex_setup_rates_from_bssdesc(struct mwifiex_private *priv,
203 struct mwifiex_bssdescriptor *bss_desc,
204 u8 *out_rates, u32 *out_rates_size)
205 {
206 u8 card_rates[MWIFIEX_SUPPORTED_RATES];
207 u32 card_rates_size;
208
209 /* Copy AP supported rates */
210 memcpy(out_rates, bss_desc->supported_rates, MWIFIEX_SUPPORTED_RATES);
211 /* Get the STA supported rates */
212 card_rates_size = mwifiex_get_active_data_rates(priv, card_rates);
213 /* Get the common rates between AP and STA supported rates */
214 if (mwifiex_get_common_rates(priv, out_rates, MWIFIEX_SUPPORTED_RATES,
215 card_rates, card_rates_size)) {
216 *out_rates_size = 0;
217 dev_err(priv->adapter->dev, "%s: cannot get common rates\n",
218 __func__);
219 return -1;
220 }
221
222 *out_rates_size =
223 min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES);
224
225 return 0;
226 }
227
228 /*
229 * This function appends a WPS IE. It is called from the network join command
230 * preparation routine.
231 *
232 * If the IE buffer has been setup by the application, this routine appends
233 * the buffer as a WPS TLV type to the request.
234 */
235 static int
236 mwifiex_cmd_append_wps_ie(struct mwifiex_private *priv, u8 **buffer)
237 {
238 int retLen = 0;
239 struct mwifiex_ie_types_header ie_header;
240
241 if (!buffer || !*buffer)
242 return 0;
243
244 /*
245 * If there is a wps ie buffer setup, append it to the return
246 * parameter buffer pointer.
247 */
248 if (priv->wps_ie_len) {
249 dev_dbg(priv->adapter->dev, "cmd: append wps ie %d to %p\n",
250 priv->wps_ie_len, *buffer);
251
252 /* Wrap the generic IE buffer with a pass through TLV type */
253 ie_header.type = cpu_to_le16(TLV_TYPE_MGMT_IE);
254 ie_header.len = cpu_to_le16(priv->wps_ie_len);
255 memcpy(*buffer, &ie_header, sizeof(ie_header));
256 *buffer += sizeof(ie_header);
257 retLen += sizeof(ie_header);
258
259 memcpy(*buffer, priv->wps_ie, priv->wps_ie_len);
260 *buffer += priv->wps_ie_len;
261 retLen += priv->wps_ie_len;
262
263 }
264
265 kfree(priv->wps_ie);
266 priv->wps_ie_len = 0;
267 return retLen;
268 }
269
270 /*
271 * This function appends a WAPI IE.
272 *
273 * This function is called from the network join command preparation routine.
274 *
275 * If the IE buffer has been setup by the application, this routine appends
276 * the buffer as a WAPI TLV type to the request.
277 */
278 static int
279 mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer)
280 {
281 int retLen = 0;
282 struct mwifiex_ie_types_header ie_header;
283
284 /* Null Checks */
285 if (buffer == NULL)
286 return 0;
287 if (*buffer == NULL)
288 return 0;
289
290 /*
291 * If there is a wapi ie buffer setup, append it to the return
292 * parameter buffer pointer.
293 */
294 if (priv->wapi_ie_len) {
295 dev_dbg(priv->adapter->dev, "cmd: append wapi ie %d to %p\n",
296 priv->wapi_ie_len, *buffer);
297
298 /* Wrap the generic IE buffer with a pass through TLV type */
299 ie_header.type = cpu_to_le16(TLV_TYPE_WAPI_IE);
300 ie_header.len = cpu_to_le16(priv->wapi_ie_len);
301 memcpy(*buffer, &ie_header, sizeof(ie_header));
302
303 /* Increment the return size and the return buffer pointer
304 param */
305 *buffer += sizeof(ie_header);
306 retLen += sizeof(ie_header);
307
308 /* Copy the wapi IE buffer to the output buffer, advance
309 pointer */
310 memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len);
311
312 /* Increment the return size and the return buffer pointer
313 param */
314 *buffer += priv->wapi_ie_len;
315 retLen += priv->wapi_ie_len;
316
317 }
318 /* return the length appended to the buffer */
319 return retLen;
320 }
321
322 /*
323 * This function appends rsn ie tlv for wpa/wpa2 security modes.
324 * It is called from the network join command preparation routine.
325 */
326 static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private *priv,
327 u8 **buffer)
328 {
329 struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv;
330 int rsn_ie_len;
331
332 if (!buffer || !(*buffer))
333 return 0;
334
335 rsn_ie_tlv = (struct mwifiex_ie_types_rsn_param_set *) (*buffer);
336 rsn_ie_tlv->header.type = cpu_to_le16((u16) priv->wpa_ie[0]);
337 rsn_ie_tlv->header.type = cpu_to_le16(
338 le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF);
339 rsn_ie_tlv->header.len = cpu_to_le16((u16) priv->wpa_ie[1]);
340 rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len)
341 & 0x00FF);
342 if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2))
343 memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2],
344 le16_to_cpu(rsn_ie_tlv->header.len));
345 else
346 return -1;
347
348 rsn_ie_len = sizeof(rsn_ie_tlv->header) +
349 le16_to_cpu(rsn_ie_tlv->header.len);
350 *buffer += rsn_ie_len;
351
352 return rsn_ie_len;
353 }
354
355 /*
356 * This function prepares command for association.
357 *
358 * This sets the following parameters -
359 * - Peer MAC address
360 * - Listen interval
361 * - Beacon interval
362 * - Capability information
363 *
364 * ...and the following TLVs, as required -
365 * - SSID TLV
366 * - PHY TLV
367 * - SS TLV
368 * - Rates TLV
369 * - Authentication TLV
370 * - Channel TLV
371 * - WPA/WPA2 IE
372 * - 11n TLV
373 * - Vendor specific TLV
374 * - WMM TLV
375 * - WAPI IE
376 * - Generic IE
377 * - TSF TLV
378 *
379 * Preparation also includes -
380 * - Setting command ID and proper size
381 * - Ensuring correct endian-ness
382 */
383 int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
384 struct host_cmd_ds_command *cmd,
385 struct mwifiex_bssdescriptor *bss_desc)
386 {
387 struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate;
388 struct mwifiex_ie_types_ssid_param_set *ssid_tlv;
389 struct mwifiex_ie_types_phy_param_set *phy_tlv;
390 struct mwifiex_ie_types_ss_param_set *ss_tlv;
391 struct mwifiex_ie_types_rates_param_set *rates_tlv;
392 struct mwifiex_ie_types_auth_type *auth_tlv;
393 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
394 u8 rates[MWIFIEX_SUPPORTED_RATES];
395 u32 rates_size;
396 u16 tmp_cap;
397 u8 *pos;
398 int rsn_ie_len = 0;
399
400 pos = (u8 *) assoc;
401
402 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
403
404 /* Save so we know which BSS Desc to use in the response handler */
405 priv->attempted_bss_desc = bss_desc;
406
407 memcpy(assoc->peer_sta_addr,
408 bss_desc->mac_address, sizeof(assoc->peer_sta_addr));
409 pos += sizeof(assoc->peer_sta_addr);
410
411 /* Set the listen interval */
412 assoc->listen_interval = cpu_to_le16(priv->listen_interval);
413 /* Set the beacon period */
414 assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period);
415
416 pos += sizeof(assoc->cap_info_bitmap);
417 pos += sizeof(assoc->listen_interval);
418 pos += sizeof(assoc->beacon_period);
419 pos += sizeof(assoc->dtim_period);
420
421 ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos;
422 ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID);
423 ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len);
424 memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid,
425 le16_to_cpu(ssid_tlv->header.len));
426 pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len);
427
428 phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos;
429 phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS);
430 phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set));
431 memcpy(&phy_tlv->fh_ds.ds_param_set,
432 &bss_desc->phy_param_set.ds_param_set.current_chan,
433 sizeof(phy_tlv->fh_ds.ds_param_set));
434 pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len);
435
436 ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos;
437 ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS);
438 ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set));
439 pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len);
440
441 /* Get the common rates supported between the driver and the BSS Desc */
442 if (mwifiex_setup_rates_from_bssdesc
443 (priv, bss_desc, rates, &rates_size))
444 return -1;
445
446 /* Save the data rates into Current BSS state structure */
447 priv->curr_bss_params.num_of_rates = rates_size;
448 memcpy(&priv->curr_bss_params.data_rates, rates, rates_size);
449
450 /* Setup the Rates TLV in the association command */
451 rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos;
452 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
453 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
454 memcpy(rates_tlv->rates, rates, rates_size);
455 pos += sizeof(rates_tlv->header) + rates_size;
456 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: rates size = %d\n",
457 rates_size);
458
459 /* Add the Authentication type to be used for Auth frames */
460 auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
461 auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
462 auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
463 if (priv->sec_info.wep_enabled)
464 auth_tlv->auth_type = cpu_to_le16(
465 (u16) priv->sec_info.authentication_mode);
466 else
467 auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM);
468
469 pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len);
470
471 if (IS_SUPPORT_MULTI_BANDS(priv->adapter) &&
472 !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
473 (!bss_desc->disable_11n) &&
474 (priv->adapter->config_bands & BAND_GN ||
475 priv->adapter->config_bands & BAND_AN) &&
476 (bss_desc->bcn_ht_cap)
477 )
478 ) {
479 /* Append a channel TLV for the channel the attempted AP was
480 found on */
481 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
482 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
483 chan_tlv->header.len =
484 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
485
486 memset(chan_tlv->chan_scan_param, 0x00,
487 sizeof(struct mwifiex_chan_scan_param_set));
488 chan_tlv->chan_scan_param[0].chan_number =
489 (bss_desc->phy_param_set.ds_param_set.current_chan);
490 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
491 chan_tlv->chan_scan_param[0].chan_number);
492
493 chan_tlv->chan_scan_param[0].radio_type =
494 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
495
496 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
497 chan_tlv->chan_scan_param[0].radio_type);
498 pos += sizeof(chan_tlv->header) +
499 sizeof(struct mwifiex_chan_scan_param_set);
500 }
501
502 if (!priv->wps.session_enable) {
503 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
504 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
505
506 if (rsn_ie_len == -1)
507 return -1;
508 }
509
510 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
511 (!bss_desc->disable_11n) &&
512 (priv->adapter->config_bands & BAND_GN ||
513 priv->adapter->config_bands & BAND_AN))
514 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
515
516 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
517 !bss_desc->disable_11n && !bss_desc->disable_11ac &&
518 priv->adapter->config_bands & BAND_AAC)
519 mwifiex_cmd_append_11ac_tlv(priv, bss_desc, &pos);
520
521 /* Append vendor specific IE TLV */
522 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
523
524 mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
525 bss_desc->bcn_ht_cap);
526 if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
527 mwifiex_cmd_append_wapi_ie(priv, &pos);
528
529 if (priv->wps.session_enable && priv->wps_ie_len)
530 mwifiex_cmd_append_wps_ie(priv, &pos);
531
532 mwifiex_cmd_append_generic_ie(priv, &pos);
533
534 mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
535
536 mwifiex_11h_process_join(priv, &pos, bss_desc);
537
538 cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
539
540 /* Set the Capability info at last */
541 tmp_cap = bss_desc->cap_info_bitmap;
542
543 if (priv->adapter->config_bands == BAND_B)
544 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
545
546 tmp_cap &= CAPINFO_MASK;
547 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
548 tmp_cap, CAPINFO_MASK);
549 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
550
551 return 0;
552 }
553
554 /*
555 * Association firmware command response handler
556 *
557 * The response buffer for the association command has the following
558 * memory layout.
559 *
560 * For cases where an association response was not received (indicated
561 * by the CapInfo and AId field):
562 *
563 * .------------------------------------------------------------.
564 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
565 * .------------------------------------------------------------.
566 * | cap_info/Error Return(t_u16): |
567 * | 0xFFFF(-1): Internal error |
568 * | 0xFFFE(-2): Authentication unhandled message |
569 * | 0xFFFD(-3): Authentication refused |
570 * | 0xFFFC(-4): Timeout waiting for AP response |
571 * .------------------------------------------------------------.
572 * | status_code(t_u16): |
573 * | If cap_info is -1: |
574 * | An internal firmware failure prevented the |
575 * | command from being processed. The status_code |
576 * | will be set to 1. |
577 * | |
578 * | If cap_info is -2: |
579 * | An authentication frame was received but was |
580 * | not handled by the firmware. IEEE Status |
581 * | code for the failure is returned. |
582 * | |
583 * | If cap_info is -3: |
584 * | An authentication frame was received and the |
585 * | status_code is the IEEE Status reported in the |
586 * | response. |
587 * | |
588 * | If cap_info is -4: |
589 * | (1) Association response timeout |
590 * | (2) Authentication response timeout |
591 * .------------------------------------------------------------.
592 * | a_id(t_u16): 0xFFFF |
593 * .------------------------------------------------------------.
594 *
595 *
596 * For cases where an association response was received, the IEEE
597 * standard association response frame is returned:
598 *
599 * .------------------------------------------------------------.
600 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
601 * .------------------------------------------------------------.
602 * | cap_info(t_u16): IEEE Capability |
603 * .------------------------------------------------------------.
604 * | status_code(t_u16): IEEE Status Code |
605 * .------------------------------------------------------------.
606 * | a_id(t_u16): IEEE Association ID |
607 * .------------------------------------------------------------.
608 * | IEEE IEs(variable): Any received IEs comprising the |
609 * | remaining portion of a received |
610 * | association response frame. |
611 * .------------------------------------------------------------.
612 *
613 * For simplistic handling, the status_code field can be used to determine
614 * an association success (0) or failure (non-zero).
615 */
616 int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
617 struct host_cmd_ds_command *resp)
618 {
619 struct mwifiex_adapter *adapter = priv->adapter;
620 int ret = 0;
621 struct ieee_types_assoc_rsp *assoc_rsp;
622 struct mwifiex_bssdescriptor *bss_desc;
623 bool enable_data = true;
624 u16 cap_info, status_code, aid;
625
626 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
627
628 cap_info = le16_to_cpu(assoc_rsp->cap_info_bitmap);
629 status_code = le16_to_cpu(assoc_rsp->status_code);
630 aid = le16_to_cpu(assoc_rsp->a_id);
631
632 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
633 dev_err(priv->adapter->dev,
634 "invalid AID value 0x%x; bits 15:14 not set\n",
635 aid);
636
637 aid &= ~(BIT(15) | BIT(14));
638
639 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
640 sizeof(priv->assoc_rsp_buf));
641
642 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
643
644 assoc_rsp->a_id = cpu_to_le16(aid);
645
646 if (status_code) {
647 priv->adapter->dbg.num_cmd_assoc_failure++;
648 dev_err(priv->adapter->dev,
649 "ASSOC_RESP: failed, status code=%d err=%#x a_id=%#x\n",
650 status_code, cap_info, le16_to_cpu(assoc_rsp->a_id));
651
652 if (cap_info == MWIFIEX_TIMEOUT_FOR_AP_RESP) {
653 if (status_code == MWIFIEX_STATUS_CODE_AUTH_TIMEOUT)
654 ret = WLAN_STATUS_AUTH_TIMEOUT;
655 else
656 ret = WLAN_STATUS_UNSPECIFIED_FAILURE;
657 } else {
658 ret = status_code;
659 }
660
661 goto done;
662 }
663
664 /* Send a Media Connected event, according to the Spec */
665 priv->media_connected = true;
666
667 priv->adapter->ps_state = PS_STATE_AWAKE;
668 priv->adapter->pps_uapsd_mode = false;
669 priv->adapter->tx_lock_flag = false;
670
671 /* Set the attempted BSSID Index to current */
672 bss_desc = priv->attempted_bss_desc;
673
674 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n",
675 bss_desc->ssid.ssid);
676
677 /* Make a copy of current BSSID descriptor */
678 memcpy(&priv->curr_bss_params.bss_descriptor,
679 bss_desc, sizeof(struct mwifiex_bssdescriptor));
680
681 /* Update curr_bss_params */
682 priv->curr_bss_params.bss_descriptor.channel
683 = bss_desc->phy_param_set.ds_param_set.current_chan;
684
685 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
686
687 if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
688 priv->curr_bss_params.wmm_enabled = true;
689 else
690 priv->curr_bss_params.wmm_enabled = false;
691
692 if ((priv->wmm_required || bss_desc->bcn_ht_cap) &&
693 priv->curr_bss_params.wmm_enabled)
694 priv->wmm_enabled = true;
695 else
696 priv->wmm_enabled = false;
697
698 priv->curr_bss_params.wmm_uapsd_enabled = false;
699
700 if (priv->wmm_enabled)
701 priv->curr_bss_params.wmm_uapsd_enabled
702 = ((bss_desc->wmm_ie.qos_info_bitmap &
703 IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
704
705 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
706 priv->curr_pkt_filter);
707 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
708 priv->wpa_is_gtk_set = false;
709
710 if (priv->wmm_enabled) {
711 /* Don't re-enable carrier until we get the WMM_GET_STATUS
712 event */
713 enable_data = false;
714 } else {
715 /* Since WMM is not enabled, setup the queues with the
716 defaults */
717 mwifiex_wmm_setup_queue_priorities(priv, NULL);
718 mwifiex_wmm_setup_ac_downgrade(priv);
719 }
720
721 if (enable_data)
722 dev_dbg(priv->adapter->dev,
723 "info: post association, re-enabling data flow\n");
724
725 /* Reset SNR/NF/RSSI values */
726 priv->data_rssi_last = 0;
727 priv->data_nf_last = 0;
728 priv->data_rssi_avg = 0;
729 priv->data_nf_avg = 0;
730 priv->bcn_rssi_last = 0;
731 priv->bcn_nf_last = 0;
732 priv->bcn_rssi_avg = 0;
733 priv->bcn_nf_avg = 0;
734 priv->rxpd_rate = 0;
735 priv->rxpd_htinfo = 0;
736
737 mwifiex_save_curr_bcn(priv);
738
739 priv->adapter->dbg.num_cmd_assoc_success++;
740
741 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n");
742
743 /* Add the ra_list here for infra mode as there will be only 1 ra
744 always */
745 mwifiex_ralist_add(priv,
746 priv->curr_bss_params.bss_descriptor.mac_address);
747
748 if (!netif_carrier_ok(priv->netdev))
749 netif_carrier_on(priv->netdev);
750 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
751
752 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
753 priv->scan_block = true;
754
755 done:
756 /* Need to indicate IOCTL complete */
757 if (adapter->curr_cmd->wait_q_enabled) {
758 if (ret)
759 adapter->cmd_wait_q.status = -1;
760 else
761 adapter->cmd_wait_q.status = 0;
762 }
763
764 return ret;
765 }
766
767 /*
768 * This function prepares command for ad-hoc start.
769 *
770 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
771 * parameters, probe delay, and capability information. Firmware
772 * will fill up beacon period, basic rates and operational rates.
773 *
774 * In addition, the following TLVs are added -
775 * - Channel TLV
776 * - Vendor specific IE
777 * - WPA/WPA2 IE
778 * - HT Capabilities IE
779 * - HT Information IE
780 *
781 * Preparation also includes -
782 * - Setting command ID and proper size
783 * - Ensuring correct endian-ness
784 */
785 int
786 mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
787 struct host_cmd_ds_command *cmd,
788 struct cfg80211_ssid *req_ssid)
789 {
790 int rsn_ie_len = 0;
791 struct mwifiex_adapter *adapter = priv->adapter;
792 struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
793 &cmd->params.adhoc_start;
794 struct mwifiex_bssdescriptor *bss_desc;
795 u32 cmd_append_size = 0;
796 u32 i;
797 u16 tmp_cap;
798 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
799 u8 radio_type;
800
801 struct mwifiex_ie_types_htcap *ht_cap;
802 struct mwifiex_ie_types_htinfo *ht_info;
803 u8 *pos = (u8 *) adhoc_start +
804 sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
805
806 if (!adapter)
807 return -1;
808
809 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
810
811 bss_desc = &priv->curr_bss_params.bss_descriptor;
812 priv->attempted_bss_desc = bss_desc;
813
814 /*
815 * Fill in the parameters for 2 data structures:
816 * 1. struct host_cmd_ds_802_11_ad_hoc_start command
817 * 2. bss_desc
818 * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
819 * probe delay, and Cap info.
820 * Firmware will fill up beacon period, Basic rates
821 * and operational rates.
822 */
823
824 memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
825
826 memcpy(adhoc_start->ssid, req_ssid->ssid, req_ssid->ssid_len);
827
828 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
829 adhoc_start->ssid);
830
831 memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
832 memcpy(bss_desc->ssid.ssid, req_ssid->ssid, req_ssid->ssid_len);
833
834 bss_desc->ssid.ssid_len = req_ssid->ssid_len;
835
836 /* Set the BSS mode */
837 adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
838 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
839 adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
840 bss_desc->beacon_period = priv->beacon_period;
841
842 /* Set Physical param set */
843 /* Parameter IE Id */
844 #define DS_PARA_IE_ID 3
845 /* Parameter IE length */
846 #define DS_PARA_IE_LEN 1
847
848 adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
849 adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
850
851 if (!mwifiex_get_cfp(priv, adapter->adhoc_start_band,
852 (u16) priv->adhoc_channel, 0)) {
853 struct mwifiex_chan_freq_power *cfp;
854 cfp = mwifiex_get_cfp(priv, adapter->adhoc_start_band,
855 FIRST_VALID_CHANNEL, 0);
856 if (cfp)
857 priv->adhoc_channel = (u8) cfp->channel;
858 }
859
860 if (!priv->adhoc_channel) {
861 dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
862 return -1;
863 }
864
865 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
866 priv->adhoc_channel);
867
868 priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
869 priv->curr_bss_params.band = adapter->adhoc_start_band;
870
871 bss_desc->channel = priv->adhoc_channel;
872 adhoc_start->phy_param_set.ds_param_set.current_chan =
873 priv->adhoc_channel;
874
875 memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
876 sizeof(union ieee_types_phy_param_set));
877
878 /* Set IBSS param set */
879 /* IBSS parameter IE Id */
880 #define IBSS_PARA_IE_ID 6
881 /* IBSS parameter IE length */
882 #define IBSS_PARA_IE_LEN 2
883
884 adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
885 adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
886 adhoc_start->ss_param_set.ibss_param_set.atim_window
887 = cpu_to_le16(priv->atim_window);
888 memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
889 sizeof(union ieee_types_ss_param_set));
890
891 /* Set Capability info */
892 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
893 tmp_cap = WLAN_CAPABILITY_IBSS;
894
895 /* Set up privacy in bss_desc */
896 if (priv->sec_info.encryption_mode) {
897 /* Ad-Hoc capability privacy on */
898 dev_dbg(adapter->dev,
899 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
900 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
901 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
902 } else {
903 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
904 " setting privacy to ACCEPT ALL\n");
905 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
906 }
907
908 memset(adhoc_start->data_rate, 0, sizeof(adhoc_start->data_rate));
909 mwifiex_get_active_data_rates(priv, adhoc_start->data_rate);
910 if ((adapter->adhoc_start_band & BAND_G) &&
911 (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
912 if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
913 HostCmd_ACT_GEN_SET, 0,
914 &priv->curr_pkt_filter, false)) {
915 dev_err(adapter->dev,
916 "ADHOC_S_CMD: G Protection config failed\n");
917 return -1;
918 }
919 }
920 /* Find the last non zero */
921 for (i = 0; i < sizeof(adhoc_start->data_rate); i++)
922 if (!adhoc_start->data_rate[i])
923 break;
924
925 priv->curr_bss_params.num_of_rates = i;
926
927 /* Copy the ad-hoc creating rates into Current BSS rate structure */
928 memcpy(&priv->curr_bss_params.data_rates,
929 &adhoc_start->data_rate, priv->curr_bss_params.num_of_rates);
930
931 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%4ph\n",
932 adhoc_start->data_rate);
933
934 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
935
936 if (IS_SUPPORT_MULTI_BANDS(adapter)) {
937 /* Append a channel TLV */
938 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
939 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
940 chan_tlv->header.len =
941 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
942
943 memset(chan_tlv->chan_scan_param, 0x00,
944 sizeof(struct mwifiex_chan_scan_param_set));
945 chan_tlv->chan_scan_param[0].chan_number =
946 (u8) priv->curr_bss_params.bss_descriptor.channel;
947
948 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
949 chan_tlv->chan_scan_param[0].chan_number);
950
951 chan_tlv->chan_scan_param[0].radio_type
952 = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
953 if (adapter->adhoc_start_band & BAND_GN ||
954 adapter->adhoc_start_band & BAND_AN) {
955 if (adapter->sec_chan_offset ==
956 IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
957 chan_tlv->chan_scan_param[0].radio_type |=
958 (IEEE80211_HT_PARAM_CHA_SEC_ABOVE << 4);
959 else if (adapter->sec_chan_offset ==
960 IEEE80211_HT_PARAM_CHA_SEC_BELOW)
961 chan_tlv->chan_scan_param[0].radio_type |=
962 (IEEE80211_HT_PARAM_CHA_SEC_BELOW << 4);
963 }
964 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
965 chan_tlv->chan_scan_param[0].radio_type);
966 pos += sizeof(chan_tlv->header) +
967 sizeof(struct mwifiex_chan_scan_param_set);
968 cmd_append_size +=
969 sizeof(chan_tlv->header) +
970 sizeof(struct mwifiex_chan_scan_param_set);
971 }
972
973 /* Append vendor specific IE TLV */
974 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
975 MWIFIEX_VSIE_MASK_ADHOC, &pos);
976
977 if (priv->sec_info.wpa_enabled) {
978 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
979 if (rsn_ie_len == -1)
980 return -1;
981 cmd_append_size += rsn_ie_len;
982 }
983
984 if (adapter->adhoc_11n_enabled) {
985 /* Fill HT CAPABILITY */
986 ht_cap = (struct mwifiex_ie_types_htcap *) pos;
987 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
988 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
989 ht_cap->header.len =
990 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
991 radio_type = mwifiex_band_to_radio_type(
992 priv->adapter->config_bands);
993 mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap);
994
995 if (adapter->sec_chan_offset ==
996 IEEE80211_HT_PARAM_CHA_SEC_NONE) {
997 u16 tmp_ht_cap;
998
999 tmp_ht_cap = le16_to_cpu(ht_cap->ht_cap.cap_info);
1000 tmp_ht_cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1001 tmp_ht_cap &= ~IEEE80211_HT_CAP_SGI_40;
1002 ht_cap->ht_cap.cap_info = cpu_to_le16(tmp_ht_cap);
1003 }
1004
1005 pos += sizeof(struct mwifiex_ie_types_htcap);
1006 cmd_append_size += sizeof(struct mwifiex_ie_types_htcap);
1007
1008 /* Fill HT INFORMATION */
1009 ht_info = (struct mwifiex_ie_types_htinfo *) pos;
1010 memset(ht_info, 0, sizeof(struct mwifiex_ie_types_htinfo));
1011 ht_info->header.type = cpu_to_le16(WLAN_EID_HT_OPERATION);
1012 ht_info->header.len =
1013 cpu_to_le16(sizeof(struct ieee80211_ht_operation));
1014
1015 ht_info->ht_oper.primary_chan =
1016 (u8) priv->curr_bss_params.bss_descriptor.channel;
1017 if (adapter->sec_chan_offset) {
1018 ht_info->ht_oper.ht_param = adapter->sec_chan_offset;
1019 ht_info->ht_oper.ht_param |=
1020 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
1021 }
1022 ht_info->ht_oper.operation_mode =
1023 cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1024 ht_info->ht_oper.basic_set[0] = 0xff;
1025 pos += sizeof(struct mwifiex_ie_types_htinfo);
1026 cmd_append_size +=
1027 sizeof(struct mwifiex_ie_types_htinfo);
1028 }
1029
1030 cmd->size =
1031 cpu_to_le16((u16)(sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
1032 + S_DS_GEN + cmd_append_size));
1033
1034 if (adapter->adhoc_start_band == BAND_B)
1035 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
1036 else
1037 tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1038
1039 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1040
1041 return 0;
1042 }
1043
1044 /*
1045 * This function prepares command for ad-hoc join.
1046 *
1047 * Most of the parameters are set up by copying from the target BSS descriptor
1048 * from the scan response.
1049 *
1050 * In addition, the following TLVs are added -
1051 * - Channel TLV
1052 * - Vendor specific IE
1053 * - WPA/WPA2 IE
1054 * - 11n IE
1055 *
1056 * Preparation also includes -
1057 * - Setting command ID and proper size
1058 * - Ensuring correct endian-ness
1059 */
1060 int
1061 mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1062 struct host_cmd_ds_command *cmd,
1063 struct mwifiex_bssdescriptor *bss_desc)
1064 {
1065 int rsn_ie_len = 0;
1066 struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
1067 &cmd->params.adhoc_join;
1068 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
1069 u32 cmd_append_size = 0;
1070 u16 tmp_cap;
1071 u32 i, rates_size = 0;
1072 u16 curr_pkt_filter;
1073 u8 *pos =
1074 (u8 *) adhoc_join +
1075 sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
1076
1077 /* Use G protection */
1078 #define USE_G_PROTECTION 0x02
1079 if (bss_desc->erp_flags & USE_G_PROTECTION) {
1080 curr_pkt_filter =
1081 priv->
1082 curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
1083
1084 if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
1085 HostCmd_ACT_GEN_SET, 0,
1086 &curr_pkt_filter, false)) {
1087 dev_err(priv->adapter->dev,
1088 "ADHOC_J_CMD: G Protection config failed\n");
1089 return -1;
1090 }
1091 }
1092
1093 priv->attempted_bss_desc = bss_desc;
1094
1095 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1096
1097 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1098
1099 adhoc_join->bss_descriptor.beacon_period
1100 = cpu_to_le16(bss_desc->beacon_period);
1101
1102 memcpy(&adhoc_join->bss_descriptor.bssid,
1103 &bss_desc->mac_address, ETH_ALEN);
1104
1105 memcpy(&adhoc_join->bss_descriptor.ssid,
1106 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1107
1108 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1109 &bss_desc->phy_param_set,
1110 sizeof(union ieee_types_phy_param_set));
1111
1112 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1113 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1114
1115 tmp_cap = bss_desc->cap_info_bitmap;
1116
1117 tmp_cap &= CAPINFO_MASK;
1118
1119 dev_dbg(priv->adapter->dev,
1120 "info: ADHOC_J_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
1121 tmp_cap, CAPINFO_MASK);
1122
1123 /* Information on BSSID descriptor passed to FW */
1124 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID=%pM, SSID='%s'\n",
1125 adhoc_join->bss_descriptor.bssid,
1126 adhoc_join->bss_descriptor.ssid);
1127
1128 for (i = 0; i < MWIFIEX_SUPPORTED_RATES &&
1129 bss_desc->supported_rates[i]; i++)
1130 ;
1131 rates_size = i;
1132
1133 /* Copy Data Rates from the Rates recorded in scan response */
1134 memset(adhoc_join->bss_descriptor.data_rates, 0,
1135 sizeof(adhoc_join->bss_descriptor.data_rates));
1136 memcpy(adhoc_join->bss_descriptor.data_rates,
1137 bss_desc->supported_rates, rates_size);
1138
1139 /* Copy the adhoc join rates into Current BSS state structure */
1140 priv->curr_bss_params.num_of_rates = rates_size;
1141 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1142 rates_size);
1143
1144 /* Copy the channel information */
1145 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1146 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1147
1148 if (priv->sec_info.wep_enabled || priv->sec_info.wpa_enabled)
1149 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1150
1151 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1152 /* Append a channel TLV */
1153 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1154 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1155 chan_tlv->header.len =
1156 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1157
1158 memset(chan_tlv->chan_scan_param, 0x00,
1159 sizeof(struct mwifiex_chan_scan_param_set));
1160 chan_tlv->chan_scan_param[0].chan_number =
1161 (bss_desc->phy_param_set.ds_param_set.current_chan);
1162 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan=%d\n",
1163 chan_tlv->chan_scan_param[0].chan_number);
1164
1165 chan_tlv->chan_scan_param[0].radio_type =
1166 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1167
1168 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band=%d\n",
1169 chan_tlv->chan_scan_param[0].radio_type);
1170 pos += sizeof(chan_tlv->header) +
1171 sizeof(struct mwifiex_chan_scan_param_set);
1172 cmd_append_size += sizeof(chan_tlv->header) +
1173 sizeof(struct mwifiex_chan_scan_param_set);
1174 }
1175
1176 if (priv->sec_info.wpa_enabled)
1177 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1178 if (rsn_ie_len == -1)
1179 return -1;
1180 cmd_append_size += rsn_ie_len;
1181
1182 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1183 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1184 bss_desc, &pos);
1185
1186 /* Append vendor specific IE TLV */
1187 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1188 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1189
1190 cmd->size = cpu_to_le16
1191 ((u16) (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1192 + S_DS_GEN + cmd_append_size));
1193
1194 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1195
1196 return 0;
1197 }
1198
1199 /*
1200 * This function handles the command response of ad-hoc start and
1201 * ad-hoc join.
1202 *
1203 * The function generates a device-connected event to notify
1204 * the applications, in case of successful ad-hoc start/join, and
1205 * saves the beacon buffer.
1206 */
1207 int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
1208 struct host_cmd_ds_command *resp)
1209 {
1210 int ret = 0;
1211 struct mwifiex_adapter *adapter = priv->adapter;
1212 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1213 struct mwifiex_bssdescriptor *bss_desc;
1214 u16 reason_code;
1215
1216 adhoc_result = &resp->params.adhoc_result;
1217
1218 bss_desc = priv->attempted_bss_desc;
1219
1220 /* Join result code 0 --> SUCCESS */
1221 reason_code = le16_to_cpu(resp->result);
1222 if (reason_code) {
1223 dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
1224 if (priv->media_connected)
1225 mwifiex_reset_connect_state(priv, reason_code);
1226
1227 memset(&priv->curr_bss_params.bss_descriptor,
1228 0x00, sizeof(struct mwifiex_bssdescriptor));
1229
1230 ret = -1;
1231 goto done;
1232 }
1233
1234 /* Send a Media Connected event, according to the Spec */
1235 priv->media_connected = true;
1236
1237 if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) {
1238 dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
1239 bss_desc->ssid.ssid);
1240
1241 /* Update the created network descriptor with the new BSSID */
1242 memcpy(bss_desc->mac_address,
1243 adhoc_result->bssid, ETH_ALEN);
1244
1245 priv->adhoc_state = ADHOC_STARTED;
1246 } else {
1247 /*
1248 * Now the join cmd should be successful.
1249 * If BSSID has changed use SSID to compare instead of BSSID
1250 */
1251 dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
1252 bss_desc->ssid.ssid);
1253
1254 /*
1255 * Make a copy of current BSSID descriptor, only needed for
1256 * join since the current descriptor is already being used
1257 * for adhoc start
1258 */
1259 memcpy(&priv->curr_bss_params.bss_descriptor,
1260 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1261
1262 priv->adhoc_state = ADHOC_JOINED;
1263 }
1264
1265 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
1266 priv->adhoc_channel);
1267 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
1268 priv->curr_bss_params.bss_descriptor.mac_address);
1269
1270 if (!netif_carrier_ok(priv->netdev))
1271 netif_carrier_on(priv->netdev);
1272 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
1273
1274 mwifiex_save_curr_bcn(priv);
1275
1276 done:
1277 /* Need to indicate IOCTL complete */
1278 if (adapter->curr_cmd->wait_q_enabled) {
1279 if (ret)
1280 adapter->cmd_wait_q.status = -1;
1281 else
1282 adapter->cmd_wait_q.status = 0;
1283
1284 }
1285
1286 return ret;
1287 }
1288
1289 /*
1290 * This function associates to a specific BSS discovered in a scan.
1291 *
1292 * It clears any past association response stored for application
1293 * retrieval and calls the command preparation routine to send the
1294 * command to firmware.
1295 */
1296 int mwifiex_associate(struct mwifiex_private *priv,
1297 struct mwifiex_bssdescriptor *bss_desc)
1298 {
1299 /* Return error if the adapter is not STA role or table entry
1300 * is not marked as infra.
1301 */
1302 if ((GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) ||
1303 (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
1304 return -1;
1305
1306 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
1307 !bss_desc->disable_11n && !bss_desc->disable_11ac &&
1308 priv->adapter->config_bands & BAND_AAC)
1309 mwifiex_set_11ac_ba_params(priv);
1310 else
1311 mwifiex_set_ba_params(priv);
1312
1313 /* Clear any past association response stored for application
1314 retrieval */
1315 priv->assoc_rsp_size = 0;
1316
1317 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_ASSOCIATE,
1318 HostCmd_ACT_GEN_SET, 0, bss_desc, true);
1319 }
1320
1321 /*
1322 * This function starts an ad-hoc network.
1323 *
1324 * It calls the command preparation routine to send the command to firmware.
1325 */
1326 int
1327 mwifiex_adhoc_start(struct mwifiex_private *priv,
1328 struct cfg80211_ssid *adhoc_ssid)
1329 {
1330 dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
1331 priv->adhoc_channel);
1332 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1333 priv->curr_bss_params.bss_descriptor.channel);
1334 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
1335 priv->curr_bss_params.band);
1336
1337 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
1338 priv->adapter->config_bands & BAND_AAC)
1339 mwifiex_set_11ac_ba_params(priv);
1340 else
1341 mwifiex_set_ba_params(priv);
1342
1343 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_AD_HOC_START,
1344 HostCmd_ACT_GEN_SET, 0, adhoc_ssid, true);
1345 }
1346
1347 /*
1348 * This function joins an ad-hoc network found in a previous scan.
1349 *
1350 * It calls the command preparation routine to send the command to firmware,
1351 * if already not connected to the requested SSID.
1352 */
1353 int mwifiex_adhoc_join(struct mwifiex_private *priv,
1354 struct mwifiex_bssdescriptor *bss_desc)
1355 {
1356 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
1357 priv->curr_bss_params.bss_descriptor.ssid.ssid);
1358 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
1359 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
1360 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
1361 bss_desc->ssid.ssid);
1362 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
1363 bss_desc->ssid.ssid_len);
1364
1365 /* Check if the requested SSID is already joined */
1366 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1367 !mwifiex_ssid_cmp(&bss_desc->ssid,
1368 &priv->curr_bss_params.bss_descriptor.ssid) &&
1369 (priv->curr_bss_params.bss_descriptor.bss_mode ==
1370 NL80211_IFTYPE_ADHOC)) {
1371 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
1372 " is the same as current; not attempting to re-join\n");
1373 return -1;
1374 }
1375
1376 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
1377 !bss_desc->disable_11n && !bss_desc->disable_11ac &&
1378 priv->adapter->config_bands & BAND_AAC)
1379 mwifiex_set_11ac_ba_params(priv);
1380 else
1381 mwifiex_set_ba_params(priv);
1382
1383 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
1384 priv->curr_bss_params.bss_descriptor.channel);
1385 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
1386 priv->curr_bss_params.band);
1387
1388 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
1389 HostCmd_ACT_GEN_SET, 0, bss_desc, true);
1390 }
1391
1392 /*
1393 * This function deauthenticates/disconnects from infra network by sending
1394 * deauthentication request.
1395 */
1396 static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
1397 {
1398 u8 mac_address[ETH_ALEN];
1399 int ret;
1400
1401 if (!mac || is_zero_ether_addr(mac))
1402 memcpy(mac_address,
1403 priv->curr_bss_params.bss_descriptor.mac_address,
1404 ETH_ALEN);
1405 else
1406 memcpy(mac_address, mac, ETH_ALEN);
1407
1408 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
1409 HostCmd_ACT_GEN_SET, 0, mac_address, true);
1410
1411 return ret;
1412 }
1413
1414 /*
1415 * This function deauthenticates/disconnects from a BSS.
1416 *
1417 * In case of infra made, it sends deauthentication request, and
1418 * in case of ad-hoc mode, a stop network request is sent to the firmware.
1419 * In AP mode, a command to stop bss is sent to firmware.
1420 */
1421 int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
1422 {
1423 int ret = 0;
1424
1425 if (!priv->media_connected)
1426 return 0;
1427
1428 switch (priv->bss_mode) {
1429 case NL80211_IFTYPE_STATION:
1430 case NL80211_IFTYPE_P2P_CLIENT:
1431 ret = mwifiex_deauthenticate_infra(priv, mac);
1432 if (ret)
1433 cfg80211_disconnected(priv->netdev, 0, NULL, 0,
1434 true, GFP_KERNEL);
1435 break;
1436 case NL80211_IFTYPE_ADHOC:
1437 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_AD_HOC_STOP,
1438 HostCmd_ACT_GEN_SET, 0, NULL, true);
1439 case NL80211_IFTYPE_AP:
1440 return mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
1441 HostCmd_ACT_GEN_SET, 0, NULL, true);
1442 default:
1443 break;
1444 }
1445
1446 return ret;
1447 }
1448
1449 /* This function deauthenticates/disconnects from all BSS. */
1450 void mwifiex_deauthenticate_all(struct mwifiex_adapter *adapter)
1451 {
1452 struct mwifiex_private *priv;
1453 int i;
1454
1455 for (i = 0; i < adapter->priv_num; i++) {
1456 priv = adapter->priv[i];
1457 if (priv)
1458 mwifiex_deauthenticate(priv, NULL);
1459 }
1460 }
1461 EXPORT_SYMBOL_GPL(mwifiex_deauthenticate_all);
1462
1463 /*
1464 * This function converts band to radio type used in channel TLV.
1465 */
1466 u8
1467 mwifiex_band_to_radio_type(u8 band)
1468 {
1469 switch (band) {
1470 case BAND_A:
1471 case BAND_AN:
1472 case BAND_A | BAND_AN:
1473 case BAND_A | BAND_AN | BAND_AAC:
1474 return HostCmd_SCAN_RADIO_TYPE_A;
1475 case BAND_B:
1476 case BAND_G:
1477 case BAND_B | BAND_G:
1478 default:
1479 return HostCmd_SCAN_RADIO_TYPE_BG;
1480 }
1481 }