blob: 6208ef1f589ada919b5756954f24f071959af97a [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: association and ad-hoc start/join
3 *
Xinming Hu65da33f2014-06-19 21:38:57 -07004 * Copyright (C) 2011-2014, Marvell International Ltd.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07005 *
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"
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -080027#include "11ac.h"
Bing Zhao5e6e3a92011-03-21 18:00:50 -070028
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 */
39static int
40mwifiex_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) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +053056 mwifiex_dbg(priv->adapter, INFO,
57 "info: %s: append generic ie len %d to %p\n",
58 __func__, priv->gen_ie_buf_len, *buffer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070059
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 */
100static int
101mwifiex_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;
Bing Zhao1a5b3062011-05-02 11:00:45 -0700105 __le64 tsf_val;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700106
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
Bing Zhao1a5b3062011-05-02 11:00:45 -0700121 /* TSF at the time when beacon/probe_response was received */
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700122 tsf_val = cpu_to_le64(bss_desc->fw_tsf);
Bing Zhao1a5b3062011-05-02 11:00:45 -0700123 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
124 *buffer += sizeof(tsf_val);
125
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700126 tsf_val = cpu_to_le64(bss_desc->timestamp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700127
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530128 mwifiex_dbg(priv->adapter, INFO,
129 "info: %s: TSF offset calc: %016llx - %016llx\n",
130 __func__, bss_desc->timestamp, bss_desc->fw_tsf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700131
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 */
146static int mwifiex_get_common_rates(struct mwifiex_private *priv, u8 *rate1,
147 u32 rate1_size, u8 *rate2, u32 rate2_size)
148{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700149 int ret;
150 u8 *ptr = rate1, *tmp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700151 u32 i, j;
152
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700153 tmp = kmemdup(rate1, rate1_size, GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700154 if (!tmp) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530155 mwifiex_dbg(priv->adapter, ERROR, "failed to alloc tmp buf\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700156 return -ENOMEM;
157 }
158
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700159 memset(rate1, 0, rate1_size);
160
Cyril Roelandt485f1072013-01-27 23:42:48 +0100161 for (i = 0; i < rate2_size && rate2[i]; i++) {
162 for (j = 0; j < rate1_size && tmp[j]; j++) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700163 /* 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
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530172 mwifiex_dbg(priv->adapter, INFO, "info: Tx data rate set to %#x\n",
173 priv->data_rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700174
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 }
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530183 mwifiex_dbg(priv->adapter, ERROR,
184 "previously set fixed data rate %#x\t"
185 "is not compatible with the network\n",
186 priv->data_rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700187
188 ret = -1;
189 goto done;
190 }
191
192 ret = 0;
193done:
194 kfree(tmp);
195 return ret;
196}
197
198/*
199 * This function creates the intersection of the rates supported by a
200 * target BSS and our adapter settings for use in an assoc/join command.
201 */
202static int
203mwifiex_setup_rates_from_bssdesc(struct mwifiex_private *priv,
204 struct mwifiex_bssdescriptor *bss_desc,
205 u8 *out_rates, u32 *out_rates_size)
206{
207 u8 card_rates[MWIFIEX_SUPPORTED_RATES];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700208 u32 card_rates_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700209
210 /* Copy AP supported rates */
211 memcpy(out_rates, bss_desc->supported_rates, MWIFIEX_SUPPORTED_RATES);
212 /* Get the STA supported rates */
213 card_rates_size = mwifiex_get_active_data_rates(priv, card_rates);
214 /* Get the common rates between AP and STA supported rates */
215 if (mwifiex_get_common_rates(priv, out_rates, MWIFIEX_SUPPORTED_RATES,
216 card_rates, card_rates_size)) {
217 *out_rates_size = 0;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530218 mwifiex_dbg(priv->adapter, ERROR,
219 "%s: cannot get common rates\n",
220 __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700221 return -1;
222 }
223
224 *out_rates_size =
225 min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES);
226
227 return 0;
228}
229
230/*
Avinash Patil13d7ba72012-04-09 20:06:56 -0700231 * This function appends a WPS IE. It is called from the network join command
232 * preparation routine.
233 *
234 * If the IE buffer has been setup by the application, this routine appends
235 * the buffer as a WPS TLV type to the request.
236 */
237static int
238mwifiex_cmd_append_wps_ie(struct mwifiex_private *priv, u8 **buffer)
239{
240 int retLen = 0;
241 struct mwifiex_ie_types_header ie_header;
242
243 if (!buffer || !*buffer)
244 return 0;
245
246 /*
247 * If there is a wps ie buffer setup, append it to the return
248 * parameter buffer pointer.
249 */
250 if (priv->wps_ie_len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530251 mwifiex_dbg(priv->adapter, CMD,
252 "cmd: append wps ie %d to %p\n",
253 priv->wps_ie_len, *buffer);
Avinash Patil13d7ba72012-04-09 20:06:56 -0700254
255 /* Wrap the generic IE buffer with a pass through TLV type */
256 ie_header.type = cpu_to_le16(TLV_TYPE_MGMT_IE);
257 ie_header.len = cpu_to_le16(priv->wps_ie_len);
258 memcpy(*buffer, &ie_header, sizeof(ie_header));
259 *buffer += sizeof(ie_header);
260 retLen += sizeof(ie_header);
261
262 memcpy(*buffer, priv->wps_ie, priv->wps_ie_len);
263 *buffer += priv->wps_ie_len;
264 retLen += priv->wps_ie_len;
265
266 }
267
268 kfree(priv->wps_ie);
269 priv->wps_ie_len = 0;
270 return retLen;
271}
272
273/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700274 * This function appends a WAPI IE.
275 *
276 * This function is called from the network join command preparation routine.
277 *
278 * If the IE buffer has been setup by the application, this routine appends
279 * the buffer as a WAPI TLV type to the request.
280 */
281static int
282mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer)
283{
284 int retLen = 0;
285 struct mwifiex_ie_types_header ie_header;
286
287 /* Null Checks */
288 if (buffer == NULL)
289 return 0;
290 if (*buffer == NULL)
291 return 0;
292
293 /*
294 * If there is a wapi ie buffer setup, append it to the return
295 * parameter buffer pointer.
296 */
297 if (priv->wapi_ie_len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530298 mwifiex_dbg(priv->adapter, CMD,
299 "cmd: append wapi ie %d to %p\n",
300 priv->wapi_ie_len, *buffer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700301
302 /* Wrap the generic IE buffer with a pass through TLV type */
303 ie_header.type = cpu_to_le16(TLV_TYPE_WAPI_IE);
304 ie_header.len = cpu_to_le16(priv->wapi_ie_len);
305 memcpy(*buffer, &ie_header, sizeof(ie_header));
306
307 /* Increment the return size and the return buffer pointer
308 param */
309 *buffer += sizeof(ie_header);
310 retLen += sizeof(ie_header);
311
312 /* Copy the wapi IE buffer to the output buffer, advance
313 pointer */
314 memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len);
315
316 /* Increment the return size and the return buffer pointer
317 param */
318 *buffer += priv->wapi_ie_len;
319 retLen += priv->wapi_ie_len;
320
321 }
322 /* return the length appended to the buffer */
323 return retLen;
324}
325
326/*
327 * This function appends rsn ie tlv for wpa/wpa2 security modes.
328 * It is called from the network join command preparation routine.
329 */
330static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private *priv,
331 u8 **buffer)
332{
333 struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv;
334 int rsn_ie_len;
335
336 if (!buffer || !(*buffer))
337 return 0;
338
339 rsn_ie_tlv = (struct mwifiex_ie_types_rsn_param_set *) (*buffer);
340 rsn_ie_tlv->header.type = cpu_to_le16((u16) priv->wpa_ie[0]);
341 rsn_ie_tlv->header.type = cpu_to_le16(
342 le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF);
343 rsn_ie_tlv->header.len = cpu_to_le16((u16) priv->wpa_ie[1]);
344 rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len)
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700345 & 0x00FF);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700346 if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2))
347 memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2],
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700348 le16_to_cpu(rsn_ie_tlv->header.len));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700349 else
350 return -1;
351
352 rsn_ie_len = sizeof(rsn_ie_tlv->header) +
353 le16_to_cpu(rsn_ie_tlv->header.len);
354 *buffer += rsn_ie_len;
355
356 return rsn_ie_len;
357}
358
359/*
360 * This function prepares command for association.
361 *
362 * This sets the following parameters -
363 * - Peer MAC address
364 * - Listen interval
365 * - Beacon interval
366 * - Capability information
367 *
368 * ...and the following TLVs, as required -
369 * - SSID TLV
370 * - PHY TLV
371 * - SS TLV
372 * - Rates TLV
373 * - Authentication TLV
374 * - Channel TLV
375 * - WPA/WPA2 IE
376 * - 11n TLV
377 * - Vendor specific TLV
378 * - WMM TLV
379 * - WAPI IE
380 * - Generic IE
381 * - TSF TLV
382 *
383 * Preparation also includes -
384 * - Setting command ID and proper size
385 * - Ensuring correct endian-ness
386 */
387int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
388 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700389 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700390{
391 struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700392 struct mwifiex_ie_types_ssid_param_set *ssid_tlv;
393 struct mwifiex_ie_types_phy_param_set *phy_tlv;
394 struct mwifiex_ie_types_ss_param_set *ss_tlv;
395 struct mwifiex_ie_types_rates_param_set *rates_tlv;
396 struct mwifiex_ie_types_auth_type *auth_tlv;
397 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
398 u8 rates[MWIFIEX_SUPPORTED_RATES];
399 u32 rates_size;
400 u16 tmp_cap;
401 u8 *pos;
402 int rsn_ie_len = 0;
403
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700404 pos = (u8 *) assoc;
405
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700406 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
407
408 /* Save so we know which BSS Desc to use in the response handler */
409 priv->attempted_bss_desc = bss_desc;
410
411 memcpy(assoc->peer_sta_addr,
412 bss_desc->mac_address, sizeof(assoc->peer_sta_addr));
413 pos += sizeof(assoc->peer_sta_addr);
414
415 /* Set the listen interval */
416 assoc->listen_interval = cpu_to_le16(priv->listen_interval);
417 /* Set the beacon period */
418 assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period);
419
420 pos += sizeof(assoc->cap_info_bitmap);
421 pos += sizeof(assoc->listen_interval);
422 pos += sizeof(assoc->beacon_period);
423 pos += sizeof(assoc->dtim_period);
424
425 ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos;
426 ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID);
427 ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len);
428 memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid,
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700429 le16_to_cpu(ssid_tlv->header.len));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700430 pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len);
431
432 phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos;
433 phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS);
434 phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set));
435 memcpy(&phy_tlv->fh_ds.ds_param_set,
436 &bss_desc->phy_param_set.ds_param_set.current_chan,
437 sizeof(phy_tlv->fh_ds.ds_param_set));
438 pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len);
439
440 ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos;
441 ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS);
442 ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set));
443 pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len);
444
445 /* Get the common rates supported between the driver and the BSS Desc */
446 if (mwifiex_setup_rates_from_bssdesc
447 (priv, bss_desc, rates, &rates_size))
448 return -1;
449
450 /* Save the data rates into Current BSS state structure */
451 priv->curr_bss_params.num_of_rates = rates_size;
452 memcpy(&priv->curr_bss_params.data_rates, rates, rates_size);
453
454 /* Setup the Rates TLV in the association command */
455 rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos;
456 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
457 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
458 memcpy(rates_tlv->rates, rates, rates_size);
459 pos += sizeof(rates_tlv->header) + rates_size;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530460 mwifiex_dbg(priv->adapter, INFO, "info: ASSOC_CMD: rates size = %d\n",
461 rates_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700462
Marc Yang203afec2011-03-24 20:49:39 -0700463 /* Add the Authentication type to be used for Auth frames */
464 auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
465 auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
466 auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800467 if (priv->sec_info.wep_enabled)
Marc Yang203afec2011-03-24 20:49:39 -0700468 auth_tlv->auth_type = cpu_to_le16(
469 (u16) priv->sec_info.authentication_mode);
470 else
Marc Yangf986b6d2011-03-28 17:55:42 -0700471 auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM);
Marc Yang203afec2011-03-24 20:49:39 -0700472
473 pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700474
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700475 if (IS_SUPPORT_MULTI_BANDS(priv->adapter) &&
476 !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
477 (!bss_desc->disable_11n) &&
478 (priv->adapter->config_bands & BAND_GN ||
479 priv->adapter->config_bands & BAND_AN) &&
480 (bss_desc->bcn_ht_cap)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700481 )
482 ) {
483 /* Append a channel TLV for the channel the attempted AP was
484 found on */
485 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
486 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
487 chan_tlv->header.len =
488 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
489
490 memset(chan_tlv->chan_scan_param, 0x00,
491 sizeof(struct mwifiex_chan_scan_param_set));
492 chan_tlv->chan_scan_param[0].chan_number =
493 (bss_desc->phy_param_set.ds_param_set.current_chan);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530494 mwifiex_dbg(priv->adapter, INFO, "info: Assoc: TLV Chan = %d\n",
495 chan_tlv->chan_scan_param[0].chan_number);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700496
497 chan_tlv->chan_scan_param[0].radio_type =
498 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
499
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530500 mwifiex_dbg(priv->adapter, INFO, "info: Assoc: TLV Band = %d\n",
501 chan_tlv->chan_scan_param[0].radio_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700502 pos += sizeof(chan_tlv->header) +
503 sizeof(struct mwifiex_chan_scan_param_set);
504 }
505
506 if (!priv->wps.session_enable) {
507 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
508 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
509
510 if (rsn_ie_len == -1)
511 return -1;
512 }
513
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700514 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
515 (!bss_desc->disable_11n) &&
516 (priv->adapter->config_bands & BAND_GN ||
517 priv->adapter->config_bands & BAND_AN))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700518 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
519
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800520 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
521 !bss_desc->disable_11n && !bss_desc->disable_11ac &&
Bing Zhaof25b1432014-02-07 16:21:01 -0800522 priv->adapter->config_bands & BAND_AAC)
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800523 mwifiex_cmd_append_11ac_tlv(priv, bss_desc, &pos);
524
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700525 /* Append vendor specific IE TLV */
526 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
527
528 mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
529 bss_desc->bcn_ht_cap);
530 if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
531 mwifiex_cmd_append_wapi_ie(priv, &pos);
532
Avinash Patil13d7ba72012-04-09 20:06:56 -0700533 if (priv->wps.session_enable && priv->wps_ie_len)
534 mwifiex_cmd_append_wps_ie(priv, &pos);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700535
536 mwifiex_cmd_append_generic_ie(priv, &pos);
537
538 mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
539
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700540 mwifiex_11h_process_join(priv, &pos, bss_desc);
541
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700542 cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
543
544 /* Set the Capability info at last */
545 tmp_cap = bss_desc->cap_info_bitmap;
546
547 if (priv->adapter->config_bands == BAND_B)
Bing Zhaob93f85f2011-03-25 19:47:01 -0700548 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700549
550 tmp_cap &= CAPINFO_MASK;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530551 mwifiex_dbg(priv->adapter, INFO,
552 "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
553 tmp_cap, CAPINFO_MASK);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700554 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
555
556 return 0;
557}
558
559/*
560 * Association firmware command response handler
561 *
562 * The response buffer for the association command has the following
563 * memory layout.
564 *
565 * For cases where an association response was not received (indicated
566 * by the CapInfo and AId field):
567 *
568 * .------------------------------------------------------------.
569 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
570 * .------------------------------------------------------------.
571 * | cap_info/Error Return(t_u16): |
572 * | 0xFFFF(-1): Internal error |
573 * | 0xFFFE(-2): Authentication unhandled message |
574 * | 0xFFFD(-3): Authentication refused |
575 * | 0xFFFC(-4): Timeout waiting for AP response |
576 * .------------------------------------------------------------.
577 * | status_code(t_u16): |
578 * | If cap_info is -1: |
579 * | An internal firmware failure prevented the |
580 * | command from being processed. The status_code |
581 * | will be set to 1. |
582 * | |
583 * | If cap_info is -2: |
584 * | An authentication frame was received but was |
585 * | not handled by the firmware. IEEE Status |
586 * | code for the failure is returned. |
587 * | |
588 * | If cap_info is -3: |
589 * | An authentication frame was received and the |
590 * | status_code is the IEEE Status reported in the |
591 * | response. |
592 * | |
593 * | If cap_info is -4: |
594 * | (1) Association response timeout |
595 * | (2) Authentication response timeout |
596 * .------------------------------------------------------------.
597 * | a_id(t_u16): 0xFFFF |
598 * .------------------------------------------------------------.
599 *
600 *
601 * For cases where an association response was received, the IEEE
602 * standard association response frame is returned:
603 *
604 * .------------------------------------------------------------.
605 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
606 * .------------------------------------------------------------.
607 * | cap_info(t_u16): IEEE Capability |
608 * .------------------------------------------------------------.
609 * | status_code(t_u16): IEEE Status Code |
610 * .------------------------------------------------------------.
611 * | a_id(t_u16): IEEE Association ID |
612 * .------------------------------------------------------------.
613 * | IEEE IEs(variable): Any received IEs comprising the |
614 * | remaining portion of a received |
615 * | association response frame. |
616 * .------------------------------------------------------------.
617 *
618 * For simplistic handling, the status_code field can be used to determine
619 * an association success (0) or failure (non-zero).
620 */
621int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700622 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700623{
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700624 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700625 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700626 struct ieee_types_assoc_rsp *assoc_rsp;
627 struct mwifiex_bssdescriptor *bss_desc;
Peter Senna Tschudinc8561972013-09-22 00:27:43 +0200628 bool enable_data = true;
Xinming Hu4aff53e2015-05-04 22:10:08 +0530629 u16 cap_info, status_code, aid;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700630
631 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
632
Amitkumar Karwar7532c7d2013-01-17 17:41:57 -0800633 cap_info = le16_to_cpu(assoc_rsp->cap_info_bitmap);
634 status_code = le16_to_cpu(assoc_rsp->status_code);
Xinming Hu4aff53e2015-05-04 22:10:08 +0530635 aid = le16_to_cpu(assoc_rsp->a_id);
636
637 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
638 dev_err(priv->adapter->dev,
639 "invalid AID value 0x%x; bits 15:14 not set\n",
640 aid);
641
642 aid &= ~(BIT(15) | BIT(14));
Amitkumar Karwar7532c7d2013-01-17 17:41:57 -0800643
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700644 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700645 sizeof(priv->assoc_rsp_buf));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700646
647 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
648
Xinming Hu4aff53e2015-05-04 22:10:08 +0530649 assoc_rsp->a_id = cpu_to_le16(aid);
650
Amitkumar Karwar7532c7d2013-01-17 17:41:57 -0800651 if (status_code) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700652 priv->adapter->dbg.num_cmd_assoc_failure++;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530653 mwifiex_dbg(priv->adapter, ERROR,
654 "ASSOC_RESP: failed,\t"
655 "status code=%d err=%#x a_id=%#x\n",
656 status_code, cap_info,
657 le16_to_cpu(assoc_rsp->a_id));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700658
Amitkumar Karwar7532c7d2013-01-17 17:41:57 -0800659 if (cap_info == MWIFIEX_TIMEOUT_FOR_AP_RESP) {
660 if (status_code == MWIFIEX_STATUS_CODE_AUTH_TIMEOUT)
661 ret = WLAN_STATUS_AUTH_TIMEOUT;
662 else
663 ret = WLAN_STATUS_UNSPECIFIED_FAILURE;
664 } else {
665 ret = status_code;
666 }
667
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700668 goto done;
669 }
670
671 /* Send a Media Connected event, according to the Spec */
672 priv->media_connected = true;
673
674 priv->adapter->ps_state = PS_STATE_AWAKE;
675 priv->adapter->pps_uapsd_mode = false;
676 priv->adapter->tx_lock_flag = false;
677
678 /* Set the attempted BSSID Index to current */
679 bss_desc = priv->attempted_bss_desc;
680
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530681 mwifiex_dbg(priv->adapter, INFO, "info: ASSOC_RESP: %s\n",
682 bss_desc->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700683
684 /* Make a copy of current BSSID descriptor */
685 memcpy(&priv->curr_bss_params.bss_descriptor,
686 bss_desc, sizeof(struct mwifiex_bssdescriptor));
687
688 /* Update curr_bss_params */
689 priv->curr_bss_params.bss_descriptor.channel
690 = bss_desc->phy_param_set.ds_param_set.current_chan;
691
692 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
693
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700694 if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
695 priv->curr_bss_params.wmm_enabled = true;
696 else
697 priv->curr_bss_params.wmm_enabled = false;
698
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700699 if ((priv->wmm_required || bss_desc->bcn_ht_cap) &&
700 priv->curr_bss_params.wmm_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700701 priv->wmm_enabled = true;
702 else
703 priv->wmm_enabled = false;
704
705 priv->curr_bss_params.wmm_uapsd_enabled = false;
706
707 if (priv->wmm_enabled)
708 priv->curr_bss_params.wmm_uapsd_enabled
709 = ((bss_desc->wmm_ie.qos_info_bitmap &
710 IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
711
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530712 mwifiex_dbg(priv->adapter, INFO,
713 "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
714 priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700715 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
716 priv->wpa_is_gtk_set = false;
717
718 if (priv->wmm_enabled) {
719 /* Don't re-enable carrier until we get the WMM_GET_STATUS
720 event */
721 enable_data = false;
722 } else {
723 /* Since WMM is not enabled, setup the queues with the
724 defaults */
725 mwifiex_wmm_setup_queue_priorities(priv, NULL);
726 mwifiex_wmm_setup_ac_downgrade(priv);
727 }
728
729 if (enable_data)
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530730 mwifiex_dbg(priv->adapter, INFO,
731 "info: post association, re-enabling data flow\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700732
733 /* Reset SNR/NF/RSSI values */
734 priv->data_rssi_last = 0;
735 priv->data_nf_last = 0;
736 priv->data_rssi_avg = 0;
737 priv->data_nf_avg = 0;
738 priv->bcn_rssi_last = 0;
739 priv->bcn_nf_last = 0;
740 priv->bcn_rssi_avg = 0;
741 priv->bcn_nf_avg = 0;
742 priv->rxpd_rate = 0;
743 priv->rxpd_htinfo = 0;
744
745 mwifiex_save_curr_bcn(priv);
746
747 priv->adapter->dbg.num_cmd_assoc_success++;
748
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530749 mwifiex_dbg(priv->adapter, INFO, "info: ASSOC_RESP: associated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700750
751 /* Add the ra_list here for infra mode as there will be only 1 ra
752 always */
753 mwifiex_ralist_add(priv,
754 priv->curr_bss_params.bss_descriptor.mac_address);
755
756 if (!netif_carrier_ok(priv->netdev))
757 netif_carrier_on(priv->netdev);
Avinash Patil47411a02012-11-01 18:44:16 -0700758 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700759
760 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
761 priv->scan_block = true;
762
763done:
764 /* Need to indicate IOCTL complete */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700765 if (adapter->curr_cmd->wait_q_enabled) {
766 if (ret)
767 adapter->cmd_wait_q.status = -1;
768 else
769 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700770 }
771
772 return ret;
773}
774
775/*
776 * This function prepares command for ad-hoc start.
777 *
778 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
779 * parameters, probe delay, and capability information. Firmware
780 * will fill up beacon period, basic rates and operational rates.
781 *
782 * In addition, the following TLVs are added -
783 * - Channel TLV
784 * - Vendor specific IE
785 * - WPA/WPA2 IE
786 * - HT Capabilities IE
787 * - HT Information IE
788 *
789 * Preparation also includes -
790 * - Setting command ID and proper size
791 * - Ensuring correct endian-ness
792 */
793int
794mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700795 struct host_cmd_ds_command *cmd,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800796 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700797{
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700798 int rsn_ie_len = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700799 struct mwifiex_adapter *adapter = priv->adapter;
800 struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
801 &cmd->params.adhoc_start;
802 struct mwifiex_bssdescriptor *bss_desc;
803 u32 cmd_append_size = 0;
804 u32 i;
805 u16 tmp_cap;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700806 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800807 u8 radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700808
809 struct mwifiex_ie_types_htcap *ht_cap;
810 struct mwifiex_ie_types_htinfo *ht_info;
811 u8 *pos = (u8 *) adhoc_start +
812 sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
813
814 if (!adapter)
815 return -1;
816
817 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
818
819 bss_desc = &priv->curr_bss_params.bss_descriptor;
820 priv->attempted_bss_desc = bss_desc;
821
822 /*
823 * Fill in the parameters for 2 data structures:
824 * 1. struct host_cmd_ds_802_11_ad_hoc_start command
825 * 2. bss_desc
826 * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
827 * probe delay, and Cap info.
828 * Firmware will fill up beacon period, Basic rates
829 * and operational rates.
830 */
831
832 memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
833
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700834 memcpy(adhoc_start->ssid, req_ssid->ssid, req_ssid->ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700835
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530836 mwifiex_dbg(adapter, INFO, "info: ADHOC_S_CMD: SSID = %s\n",
837 adhoc_start->ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700838
839 memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700840 memcpy(bss_desc->ssid.ssid, req_ssid->ssid, req_ssid->ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700841
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700842 bss_desc->ssid.ssid_len = req_ssid->ssid_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700843
844 /* Set the BSS mode */
845 adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700846 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700847 adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
848 bss_desc->beacon_period = priv->beacon_period;
849
850 /* Set Physical param set */
851/* Parameter IE Id */
852#define DS_PARA_IE_ID 3
853/* Parameter IE length */
854#define DS_PARA_IE_LEN 1
855
856 adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
857 adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
858
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -0700859 if (!mwifiex_get_cfp(priv, adapter->adhoc_start_band,
860 (u16) priv->adhoc_channel, 0)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700861 struct mwifiex_chan_freq_power *cfp;
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -0700862 cfp = mwifiex_get_cfp(priv, adapter->adhoc_start_band,
863 FIRST_VALID_CHANNEL, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700864 if (cfp)
865 priv->adhoc_channel = (u8) cfp->channel;
866 }
867
868 if (!priv->adhoc_channel) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530869 mwifiex_dbg(adapter, ERROR,
870 "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700871 return -1;
872 }
873
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530874 mwifiex_dbg(adapter, INFO,
875 "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
876 priv->adhoc_channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700877
878 priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
879 priv->curr_bss_params.band = adapter->adhoc_start_band;
880
881 bss_desc->channel = priv->adhoc_channel;
882 adhoc_start->phy_param_set.ds_param_set.current_chan =
883 priv->adhoc_channel;
884
885 memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
886 sizeof(union ieee_types_phy_param_set));
887
888 /* Set IBSS param set */
889/* IBSS parameter IE Id */
890#define IBSS_PARA_IE_ID 6
891/* IBSS parameter IE length */
892#define IBSS_PARA_IE_LEN 2
893
894 adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
895 adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
896 adhoc_start->ss_param_set.ibss_param_set.atim_window
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700897 = cpu_to_le16(priv->atim_window);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700898 memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
899 sizeof(union ieee_types_ss_param_set));
900
901 /* Set Capability info */
902 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
James Cameron4eed83a2014-11-11 16:21:28 +1100903 tmp_cap = WLAN_CAPABILITY_IBSS;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700904
905 /* Set up privacy in bss_desc */
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700906 if (priv->sec_info.encryption_mode) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700907 /* Ad-Hoc capability privacy on */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530908 mwifiex_dbg(adapter, INFO,
909 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700910 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
911 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
912 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530913 mwifiex_dbg(adapter, INFO,
914 "info: ADHOC_S_CMD: wep_status NOT set,\t"
915 "setting privacy to ACCEPT ALL\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700916 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
917 }
918
Yogesh Ashok Powar63af6332011-11-07 21:41:09 -0800919 memset(adhoc_start->data_rate, 0, sizeof(adhoc_start->data_rate));
920 mwifiex_get_active_data_rates(priv, adhoc_start->data_rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700921 if ((adapter->adhoc_start_band & BAND_G) &&
922 (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800923 if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
924 HostCmd_ACT_GEN_SET, 0,
925 &priv->curr_pkt_filter, false)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530926 mwifiex_dbg(adapter, ERROR,
927 "ADHOC_S_CMD: G Protection config failed\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700928 return -1;
929 }
930 }
931 /* Find the last non zero */
Yogesh Ashok Powar63af6332011-11-07 21:41:09 -0800932 for (i = 0; i < sizeof(adhoc_start->data_rate); i++)
933 if (!adhoc_start->data_rate[i])
934 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700935
936 priv->curr_bss_params.num_of_rates = i;
937
938 /* Copy the ad-hoc creating rates into Current BSS rate structure */
939 memcpy(&priv->curr_bss_params.data_rates,
Yogesh Ashok Powar63af6332011-11-07 21:41:09 -0800940 &adhoc_start->data_rate, priv->curr_bss_params.num_of_rates);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700941
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530942 mwifiex_dbg(adapter, INFO, "info: ADHOC_S_CMD: rates=%4ph\n",
943 adhoc_start->data_rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700944
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530945 mwifiex_dbg(adapter, INFO, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700946
947 if (IS_SUPPORT_MULTI_BANDS(adapter)) {
948 /* Append a channel TLV */
949 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
950 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
951 chan_tlv->header.len =
952 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
953
954 memset(chan_tlv->chan_scan_param, 0x00,
955 sizeof(struct mwifiex_chan_scan_param_set));
956 chan_tlv->chan_scan_param[0].chan_number =
957 (u8) priv->curr_bss_params.bss_descriptor.channel;
958
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530959 mwifiex_dbg(adapter, INFO, "info: ADHOC_S_CMD: TLV Chan = %d\n",
960 chan_tlv->chan_scan_param[0].chan_number);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700961
962 chan_tlv->chan_scan_param[0].radio_type
963 = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700964 if (adapter->adhoc_start_band & BAND_GN ||
965 adapter->adhoc_start_band & BAND_AN) {
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800966 if (adapter->sec_chan_offset ==
967 IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700968 chan_tlv->chan_scan_param[0].radio_type |=
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800969 (IEEE80211_HT_PARAM_CHA_SEC_ABOVE << 4);
970 else if (adapter->sec_chan_offset ==
Bing Zhao2a317ad2014-07-11 20:54:32 -0700971 IEEE80211_HT_PARAM_CHA_SEC_BELOW)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700972 chan_tlv->chan_scan_param[0].radio_type |=
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800973 (IEEE80211_HT_PARAM_CHA_SEC_BELOW << 4);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700974 }
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530975 mwifiex_dbg(adapter, INFO, "info: ADHOC_S_CMD: TLV Band = %d\n",
976 chan_tlv->chan_scan_param[0].radio_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700977 pos += sizeof(chan_tlv->header) +
978 sizeof(struct mwifiex_chan_scan_param_set);
979 cmd_append_size +=
980 sizeof(chan_tlv->header) +
981 sizeof(struct mwifiex_chan_scan_param_set);
982 }
983
984 /* Append vendor specific IE TLV */
985 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
986 MWIFIEX_VSIE_MASK_ADHOC, &pos);
987
988 if (priv->sec_info.wpa_enabled) {
989 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
990 if (rsn_ie_len == -1)
991 return -1;
992 cmd_append_size += rsn_ie_len;
993 }
994
995 if (adapter->adhoc_11n_enabled) {
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800996 /* Fill HT CAPABILITY */
997 ht_cap = (struct mwifiex_ie_types_htcap *) pos;
998 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
999 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1000 ht_cap->header.len =
1001 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
1002 radio_type = mwifiex_band_to_radio_type(
1003 priv->adapter->config_bands);
Amitkumar Karwar341b8802014-02-07 16:27:31 -08001004 mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001005
Amitkumar Karward35f1032013-01-02 16:56:00 -08001006 if (adapter->sec_chan_offset ==
1007 IEEE80211_HT_PARAM_CHA_SEC_NONE) {
1008 u16 tmp_ht_cap;
1009
1010 tmp_ht_cap = le16_to_cpu(ht_cap->ht_cap.cap_info);
1011 tmp_ht_cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1012 tmp_ht_cap &= ~IEEE80211_HT_CAP_SGI_40;
1013 ht_cap->ht_cap.cap_info = cpu_to_le16(tmp_ht_cap);
1014 }
1015
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -08001016 pos += sizeof(struct mwifiex_ie_types_htcap);
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001017 cmd_append_size += sizeof(struct mwifiex_ie_types_htcap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001018
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -08001019 /* Fill HT INFORMATION */
1020 ht_info = (struct mwifiex_ie_types_htinfo *) pos;
1021 memset(ht_info, 0, sizeof(struct mwifiex_ie_types_htinfo));
Johannes Berg074d46d2012-03-15 19:45:16 +01001022 ht_info->header.type = cpu_to_le16(WLAN_EID_HT_OPERATION);
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -08001023 ht_info->header.len =
Johannes Berg074d46d2012-03-15 19:45:16 +01001024 cpu_to_le16(sizeof(struct ieee80211_ht_operation));
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -08001025
Johannes Berg074d46d2012-03-15 19:45:16 +01001026 ht_info->ht_oper.primary_chan =
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -08001027 (u8) priv->curr_bss_params.bss_descriptor.channel;
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -08001028 if (adapter->sec_chan_offset) {
Johannes Berg074d46d2012-03-15 19:45:16 +01001029 ht_info->ht_oper.ht_param = adapter->sec_chan_offset;
1030 ht_info->ht_oper.ht_param |=
Marc Yang6d2bd912011-03-25 19:47:02 -07001031 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001032 }
Johannes Berg074d46d2012-03-15 19:45:16 +01001033 ht_info->ht_oper.operation_mode =
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -08001034 cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
Johannes Berg074d46d2012-03-15 19:45:16 +01001035 ht_info->ht_oper.basic_set[0] = 0xff;
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -08001036 pos += sizeof(struct mwifiex_ie_types_htinfo);
1037 cmd_append_size +=
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001038 sizeof(struct mwifiex_ie_types_htinfo);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001039 }
1040
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001041 cmd->size =
1042 cpu_to_le16((u16)(sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
1043 + S_DS_GEN + cmd_append_size));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001044
1045 if (adapter->adhoc_start_band == BAND_B)
Bing Zhaob93f85f2011-03-25 19:47:01 -07001046 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001047 else
Bing Zhaob93f85f2011-03-25 19:47:01 -07001048 tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001049
1050 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1051
1052 return 0;
1053}
1054
1055/*
1056 * This function prepares command for ad-hoc join.
1057 *
1058 * Most of the parameters are set up by copying from the target BSS descriptor
1059 * from the scan response.
1060 *
1061 * In addition, the following TLVs are added -
1062 * - Channel TLV
1063 * - Vendor specific IE
1064 * - WPA/WPA2 IE
1065 * - 11n IE
1066 *
1067 * Preparation also includes -
1068 * - Setting command ID and proper size
1069 * - Ensuring correct endian-ness
1070 */
1071int
1072mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001073 struct host_cmd_ds_command *cmd,
1074 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001075{
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001076 int rsn_ie_len = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001077 struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
1078 &cmd->params.adhoc_join;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001079 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
1080 u32 cmd_append_size = 0;
1081 u16 tmp_cap;
1082 u32 i, rates_size = 0;
1083 u16 curr_pkt_filter;
1084 u8 *pos =
1085 (u8 *) adhoc_join +
1086 sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
1087
1088/* Use G protection */
1089#define USE_G_PROTECTION 0x02
1090 if (bss_desc->erp_flags & USE_G_PROTECTION) {
1091 curr_pkt_filter =
1092 priv->
1093 curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
1094
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001095 if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
1096 HostCmd_ACT_GEN_SET, 0,
1097 &curr_pkt_filter, false)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301098 mwifiex_dbg(priv->adapter, ERROR,
1099 "ADHOC_J_CMD: G Protection config failed\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001100 return -1;
1101 }
1102 }
1103
1104 priv->attempted_bss_desc = bss_desc;
1105
1106 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1107
1108 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1109
1110 adhoc_join->bss_descriptor.beacon_period
1111 = cpu_to_le16(bss_desc->beacon_period);
1112
1113 memcpy(&adhoc_join->bss_descriptor.bssid,
1114 &bss_desc->mac_address, ETH_ALEN);
1115
1116 memcpy(&adhoc_join->bss_descriptor.ssid,
1117 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1118
1119 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1120 &bss_desc->phy_param_set,
1121 sizeof(union ieee_types_phy_param_set));
1122
1123 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1124 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1125
1126 tmp_cap = bss_desc->cap_info_bitmap;
1127
1128 tmp_cap &= CAPINFO_MASK;
1129
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301130 mwifiex_dbg(priv->adapter, INFO,
1131 "info: ADHOC_J_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
1132 tmp_cap, CAPINFO_MASK);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001133
1134 /* Information on BSSID descriptor passed to FW */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301135 mwifiex_dbg(priv->adapter, INFO,
1136 "info: ADHOC_J_CMD: BSSID=%pM, SSID='%s'\n",
1137 adhoc_join->bss_descriptor.bssid,
1138 adhoc_join->bss_descriptor.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001139
Bing Zhao5f0fabf2013-03-07 20:00:16 -08001140 for (i = 0; i < MWIFIEX_SUPPORTED_RATES &&
1141 bss_desc->supported_rates[i]; i++)
1142 ;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001143 rates_size = i;
1144
1145 /* Copy Data Rates from the Rates recorded in scan response */
1146 memset(adhoc_join->bss_descriptor.data_rates, 0,
1147 sizeof(adhoc_join->bss_descriptor.data_rates));
1148 memcpy(adhoc_join->bss_descriptor.data_rates,
1149 bss_desc->supported_rates, rates_size);
1150
1151 /* Copy the adhoc join rates into Current BSS state structure */
1152 priv->curr_bss_params.num_of_rates = rates_size;
1153 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1154 rates_size);
1155
1156 /* Copy the channel information */
1157 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1158 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1159
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -08001160 if (priv->sec_info.wep_enabled || priv->sec_info.wpa_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1162
1163 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1164 /* Append a channel TLV */
1165 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1166 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1167 chan_tlv->header.len =
1168 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1169
1170 memset(chan_tlv->chan_scan_param, 0x00,
1171 sizeof(struct mwifiex_chan_scan_param_set));
1172 chan_tlv->chan_scan_param[0].chan_number =
1173 (bss_desc->phy_param_set.ds_param_set.current_chan);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301174 mwifiex_dbg(priv->adapter, INFO, "info: ADHOC_J_CMD: TLV Chan=%d\n",
1175 chan_tlv->chan_scan_param[0].chan_number);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001176
1177 chan_tlv->chan_scan_param[0].radio_type =
1178 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1179
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301180 mwifiex_dbg(priv->adapter, INFO, "info: ADHOC_J_CMD: TLV Band=%d\n",
1181 chan_tlv->chan_scan_param[0].radio_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001182 pos += sizeof(chan_tlv->header) +
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001183 sizeof(struct mwifiex_chan_scan_param_set);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001184 cmd_append_size += sizeof(chan_tlv->header) +
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001185 sizeof(struct mwifiex_chan_scan_param_set);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001186 }
1187
1188 if (priv->sec_info.wpa_enabled)
1189 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1190 if (rsn_ie_len == -1)
1191 return -1;
1192 cmd_append_size += rsn_ie_len;
1193
1194 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1195 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1196 bss_desc, &pos);
1197
1198 /* Append vendor specific IE TLV */
1199 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1200 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1201
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001202 cmd->size = cpu_to_le16
1203 ((u16) (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1204 + S_DS_GEN + cmd_append_size));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001205
1206 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1207
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001208 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001209}
1210
1211/*
1212 * This function handles the command response of ad-hoc start and
1213 * ad-hoc join.
1214 *
1215 * The function generates a device-connected event to notify
1216 * the applications, in case of successful ad-hoc start/join, and
1217 * saves the beacon buffer.
1218 */
1219int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001220 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001221{
1222 int ret = 0;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001223 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001224 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1225 struct mwifiex_bssdescriptor *bss_desc;
Amitkumar Karwar8cc1d522012-10-05 20:21:43 -07001226 u16 reason_code;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001227
1228 adhoc_result = &resp->params.adhoc_result;
1229
1230 bss_desc = priv->attempted_bss_desc;
1231
1232 /* Join result code 0 --> SUCCESS */
Amitkumar Karwar8cc1d522012-10-05 20:21:43 -07001233 reason_code = le16_to_cpu(resp->result);
1234 if (reason_code) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301235 mwifiex_dbg(priv->adapter, ERROR, "ADHOC_RESP: failed\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001236 if (priv->media_connected)
Amitkumar Karwar8cc1d522012-10-05 20:21:43 -07001237 mwifiex_reset_connect_state(priv, reason_code);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001238
1239 memset(&priv->curr_bss_params.bss_descriptor,
1240 0x00, sizeof(struct mwifiex_bssdescriptor));
1241
1242 ret = -1;
1243 goto done;
1244 }
1245
1246 /* Send a Media Connected event, according to the Spec */
1247 priv->media_connected = true;
1248
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001249 if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301250 mwifiex_dbg(priv->adapter, INFO, "info: ADHOC_S_RESP %s\n",
1251 bss_desc->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001252
1253 /* Update the created network descriptor with the new BSSID */
1254 memcpy(bss_desc->mac_address,
1255 adhoc_result->bssid, ETH_ALEN);
1256
1257 priv->adhoc_state = ADHOC_STARTED;
1258 } else {
1259 /*
1260 * Now the join cmd should be successful.
1261 * If BSSID has changed use SSID to compare instead of BSSID
1262 */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301263 mwifiex_dbg(priv->adapter, INFO,
1264 "info: ADHOC_J_RESP %s\n",
1265 bss_desc->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001266
1267 /*
1268 * Make a copy of current BSSID descriptor, only needed for
1269 * join since the current descriptor is already being used
1270 * for adhoc start
1271 */
1272 memcpy(&priv->curr_bss_params.bss_descriptor,
1273 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1274
1275 priv->adhoc_state = ADHOC_JOINED;
1276 }
1277
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301278 mwifiex_dbg(priv->adapter, INFO, "info: ADHOC_RESP: channel = %d\n",
1279 priv->adhoc_channel);
1280 mwifiex_dbg(priv->adapter, INFO, "info: ADHOC_RESP: BSSID = %pM\n",
1281 priv->curr_bss_params.bss_descriptor.mac_address);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001282
1283 if (!netif_carrier_ok(priv->netdev))
1284 netif_carrier_on(priv->netdev);
Avinash Patil47411a02012-11-01 18:44:16 -07001285 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001286
1287 mwifiex_save_curr_bcn(priv);
1288
1289done:
1290 /* Need to indicate IOCTL complete */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001291 if (adapter->curr_cmd->wait_q_enabled) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001292 if (ret)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001293 adapter->cmd_wait_q.status = -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001294 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001295 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001296
1297 }
1298
1299 return ret;
1300}
1301
1302/*
1303 * This function associates to a specific BSS discovered in a scan.
1304 *
1305 * It clears any past association response stored for application
1306 * retrieval and calls the command preparation routine to send the
1307 * command to firmware.
1308 */
1309int mwifiex_associate(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001310 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001311{
Avinash Patil953b3532013-07-29 16:32:37 -07001312 /* Return error if the adapter is not STA role or table entry
1313 * is not marked as infra.
1314 */
1315 if ((GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) ||
Bing Zhaoeecd8252011-03-28 17:55:41 -07001316 (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001317 return -1;
1318
Avinash Patil2b6254d2013-03-27 19:10:32 -07001319 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
1320 !bss_desc->disable_11n && !bss_desc->disable_11ac &&
Bing Zhaof25b1432014-02-07 16:21:01 -08001321 priv->adapter->config_bands & BAND_AAC)
Avinash Patil2b6254d2013-03-27 19:10:32 -07001322 mwifiex_set_11ac_ba_params(priv);
1323 else
1324 mwifiex_set_ba_params(priv);
1325
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001326 /* Clear any past association response stored for application
1327 retrieval */
1328 priv->assoc_rsp_size = 0;
1329
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001330 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_ASSOCIATE,
1331 HostCmd_ACT_GEN_SET, 0, bss_desc, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001332}
1333
1334/*
1335 * This function starts an ad-hoc network.
1336 *
1337 * It calls the command preparation routine to send the command to firmware.
1338 */
1339int
1340mwifiex_adhoc_start(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08001341 struct cfg80211_ssid *adhoc_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001342{
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301343 mwifiex_dbg(priv->adapter, INFO, "info: Adhoc Channel = %d\n",
1344 priv->adhoc_channel);
1345 mwifiex_dbg(priv->adapter, INFO, "info: curr_bss_params.channel = %d\n",
1346 priv->curr_bss_params.bss_descriptor.channel);
1347 mwifiex_dbg(priv->adapter, INFO, "info: curr_bss_params.band = %d\n",
1348 priv->curr_bss_params.band);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001349
Avinash Patil2b6254d2013-03-27 19:10:32 -07001350 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
Bing Zhaof25b1432014-02-07 16:21:01 -08001351 priv->adapter->config_bands & BAND_AAC)
Avinash Patil2b6254d2013-03-27 19:10:32 -07001352 mwifiex_set_11ac_ba_params(priv);
1353 else
1354 mwifiex_set_ba_params(priv);
1355
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001356 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_AD_HOC_START,
1357 HostCmd_ACT_GEN_SET, 0, adhoc_ssid, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001358}
1359
1360/*
1361 * This function joins an ad-hoc network found in a previous scan.
1362 *
1363 * It calls the command preparation routine to send the command to firmware,
1364 * if already not connected to the requested SSID.
1365 */
1366int mwifiex_adhoc_join(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001367 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001368{
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301369 mwifiex_dbg(priv->adapter, INFO,
1370 "info: adhoc join: curr_bss ssid =%s\n",
1371 priv->curr_bss_params.bss_descriptor.ssid.ssid);
1372 mwifiex_dbg(priv->adapter, INFO,
1373 "info: adhoc join: curr_bss ssid_len =%u\n",
1374 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
1375 mwifiex_dbg(priv->adapter, INFO, "info: adhoc join: ssid =%s\n",
1376 bss_desc->ssid.ssid);
1377 mwifiex_dbg(priv->adapter, INFO, "info: adhoc join: ssid_len =%u\n",
1378 bss_desc->ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001379
1380 /* Check if the requested SSID is already joined */
1381 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1382 !mwifiex_ssid_cmp(&bss_desc->ssid,
1383 &priv->curr_bss_params.bss_descriptor.ssid) &&
1384 (priv->curr_bss_params.bss_descriptor.bss_mode ==
Bing Zhaoeecd8252011-03-28 17:55:41 -07001385 NL80211_IFTYPE_ADHOC)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301386 mwifiex_dbg(priv->adapter, INFO,
1387 "info: ADHOC_J_CMD: new ad-hoc SSID\t"
1388 "is the same as current; not attempting to re-join\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001389 return -1;
1390 }
1391
Avinash Patil2b6254d2013-03-27 19:10:32 -07001392 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) &&
1393 !bss_desc->disable_11n && !bss_desc->disable_11ac &&
Bing Zhaof25b1432014-02-07 16:21:01 -08001394 priv->adapter->config_bands & BAND_AAC)
Avinash Patil2b6254d2013-03-27 19:10:32 -07001395 mwifiex_set_11ac_ba_params(priv);
1396 else
1397 mwifiex_set_ba_params(priv);
1398
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301399 mwifiex_dbg(priv->adapter, INFO,
1400 "info: curr_bss_params.channel = %d\n",
1401 priv->curr_bss_params.bss_descriptor.channel);
1402 mwifiex_dbg(priv->adapter, INFO,
1403 "info: curr_bss_params.band = %c\n",
1404 priv->curr_bss_params.band);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001405
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001406 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
1407 HostCmd_ACT_GEN_SET, 0, bss_desc, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001408}
1409
1410/*
1411 * This function deauthenticates/disconnects from infra network by sending
1412 * deauthentication request.
1413 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001414static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001415{
1416 u8 mac_address[ETH_ALEN];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001417 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001418
Joe Perches2c208892012-06-04 12:44:17 +00001419 if (!mac || is_zero_ether_addr(mac))
1420 memcpy(mac_address,
1421 priv->curr_bss_params.bss_descriptor.mac_address,
1422 ETH_ALEN);
1423 else
1424 memcpy(mac_address, mac, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001425
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001426 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
1427 HostCmd_ACT_GEN_SET, 0, mac_address, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001428
1429 return ret;
1430}
1431
1432/*
1433 * This function deauthenticates/disconnects from a BSS.
1434 *
1435 * In case of infra made, it sends deauthentication request, and
1436 * in case of ad-hoc mode, a stop network request is sent to the firmware.
Avinash Patil26134e62012-05-08 18:30:21 -07001437 * In AP mode, a command to stop bss is sent to firmware.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001438 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001439int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001440{
Avinash Patile8041ce2013-10-11 18:31:31 -07001441 int ret = 0;
1442
Bing Zhao99e126f2012-05-01 19:53:51 -07001443 if (!priv->media_connected)
1444 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001445
Bing Zhao99e126f2012-05-01 19:53:51 -07001446 switch (priv->bss_mode) {
1447 case NL80211_IFTYPE_STATION:
Stone Piao5e4c0792013-07-22 19:17:45 -07001448 case NL80211_IFTYPE_P2P_CLIENT:
Avinash Patile8041ce2013-10-11 18:31:31 -07001449 ret = mwifiex_deauthenticate_infra(priv, mac);
1450 if (ret)
1451 cfg80211_disconnected(priv->netdev, 0, NULL, 0,
1452 GFP_KERNEL);
1453 break;
Bing Zhao99e126f2012-05-01 19:53:51 -07001454 case NL80211_IFTYPE_ADHOC:
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001455 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_AD_HOC_STOP,
1456 HostCmd_ACT_GEN_SET, 0, NULL, true);
Avinash Patil26134e62012-05-08 18:30:21 -07001457 case NL80211_IFTYPE_AP:
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001458 return mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
1459 HostCmd_ACT_GEN_SET, 0, NULL, true);
Bing Zhao99e126f2012-05-01 19:53:51 -07001460 default:
1461 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001462 }
1463
Avinash Patile8041ce2013-10-11 18:31:31 -07001464 return ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001465}
Amitkumar Karwar848819f2014-02-27 19:35:17 -08001466
1467/* This function deauthenticates/disconnects from all BSS. */
1468void mwifiex_deauthenticate_all(struct mwifiex_adapter *adapter)
1469{
1470 struct mwifiex_private *priv;
1471 int i;
1472
1473 for (i = 0; i < adapter->priv_num; i++) {
1474 priv = adapter->priv[i];
1475 if (priv)
1476 mwifiex_deauthenticate(priv, NULL);
1477 }
1478}
1479EXPORT_SYMBOL_GPL(mwifiex_deauthenticate_all);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001480
1481/*
1482 * This function converts band to radio type used in channel TLV.
1483 */
1484u8
1485mwifiex_band_to_radio_type(u8 band)
1486{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001487 switch (band) {
1488 case BAND_A:
1489 case BAND_AN:
1490 case BAND_A | BAND_AN:
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001491 case BAND_A | BAND_AN | BAND_AAC:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001492 return HostCmd_SCAN_RADIO_TYPE_A;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001493 case BAND_B:
1494 case BAND_G:
1495 case BAND_B | BAND_G:
1496 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001497 return HostCmd_SCAN_RADIO_TYPE_BG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001498 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001499}