blob: 88664ae667ba65ea18e9c27410f26095e1931309 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: association and ad-hoc start/join
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27
28#define CAPINFO_MASK (~(BIT(15) | BIT(14) | BIT(12) | BIT(11) | BIT(9)))
29
30/*
31 * Append a generic IE as a pass through TLV to a TLV buffer.
32 *
33 * This function is called from the network join command preparation routine.
34 *
35 * If the IE buffer has been setup by the application, this routine appends
36 * the buffer as a pass through TLV type to the request.
37 */
38static int
39mwifiex_cmd_append_generic_ie(struct mwifiex_private *priv, u8 **buffer)
40{
41 int ret_len = 0;
42 struct mwifiex_ie_types_header ie_header;
43
44 /* Null Checks */
45 if (!buffer)
46 return 0;
47 if (!(*buffer))
48 return 0;
49
50 /*
51 * If there is a generic ie buffer setup, append it to the return
52 * parameter buffer pointer.
53 */
54 if (priv->gen_ie_buf_len) {
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -070055 dev_dbg(priv->adapter->dev,
56 "info: %s: append generic ie len %d to %p\n",
57 __func__, priv->gen_ie_buf_len, *buffer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070058
59 /* Wrap the generic IE buffer with a pass through TLV type */
60 ie_header.type = cpu_to_le16(TLV_TYPE_PASSTHROUGH);
61 ie_header.len = cpu_to_le16(priv->gen_ie_buf_len);
62 memcpy(*buffer, &ie_header, sizeof(ie_header));
63
64 /* Increment the return size and the return buffer pointer
65 param */
66 *buffer += sizeof(ie_header);
67 ret_len += sizeof(ie_header);
68
69 /* Copy the generic IE buffer to the output buffer, advance
70 pointer */
71 memcpy(*buffer, priv->gen_ie_buf, priv->gen_ie_buf_len);
72
73 /* Increment the return size and the return buffer pointer
74 param */
75 *buffer += priv->gen_ie_buf_len;
76 ret_len += priv->gen_ie_buf_len;
77
78 /* Reset the generic IE buffer */
79 priv->gen_ie_buf_len = 0;
80 }
81
82 /* return the length appended to the buffer */
83 return ret_len;
84}
85
86/*
87 * Append TSF tracking info from the scan table for the target AP.
88 *
89 * This function is called from the network join command preparation routine.
90 *
91 * The TSF table TSF sent to the firmware contains two TSF values:
92 * - The TSF of the target AP from its previous beacon/probe response
93 * - The TSF timestamp of our local MAC at the time we observed the
94 * beacon/probe response.
95 *
96 * The firmware uses the timestamp values to set an initial TSF value
97 * in the MAC for the new association after a reassociation attempt.
98 */
99static int
100mwifiex_cmd_append_tsf_tlv(struct mwifiex_private *priv, u8 **buffer,
101 struct mwifiex_bssdescriptor *bss_desc)
102{
103 struct mwifiex_ie_types_tsf_timestamp tsf_tlv;
Bing Zhao1a5b3062011-05-02 11:00:45 -0700104 __le64 tsf_val;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700105
106 /* Null Checks */
107 if (buffer == NULL)
108 return 0;
109 if (*buffer == NULL)
110 return 0;
111
112 memset(&tsf_tlv, 0x00, sizeof(struct mwifiex_ie_types_tsf_timestamp));
113
114 tsf_tlv.header.type = cpu_to_le16(TLV_TYPE_TSFTIMESTAMP);
115 tsf_tlv.header.len = cpu_to_le16(2 * sizeof(tsf_val));
116
117 memcpy(*buffer, &tsf_tlv, sizeof(tsf_tlv.header));
118 *buffer += sizeof(tsf_tlv.header);
119
Bing Zhao1a5b3062011-05-02 11:00:45 -0700120 /* TSF at the time when beacon/probe_response was received */
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700121 tsf_val = cpu_to_le64(bss_desc->fw_tsf);
Bing Zhao1a5b3062011-05-02 11:00:45 -0700122 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
123 *buffer += sizeof(tsf_val);
124
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700125 tsf_val = cpu_to_le64(bss_desc->timestamp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700126
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700127 dev_dbg(priv->adapter->dev,
128 "info: %s: TSF offset calc: %016llx - %016llx\n",
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700129 __func__, bss_desc->timestamp, bss_desc->fw_tsf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700130
131 memcpy(*buffer, &tsf_val, sizeof(tsf_val));
132 *buffer += sizeof(tsf_val);
133
134 return sizeof(tsf_tlv.header) + (2 * sizeof(tsf_val));
135}
136
137/*
138 * This function finds out the common rates between rate1 and rate2.
139 *
140 * It will fill common rates in rate1 as output if found.
141 *
142 * NOTE: Setting the MSB of the basic rates needs to be taken
143 * care of, either before or after calling this function.
144 */
145static int mwifiex_get_common_rates(struct mwifiex_private *priv, u8 *rate1,
146 u32 rate1_size, u8 *rate2, u32 rate2_size)
147{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700148 int ret;
149 u8 *ptr = rate1, *tmp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700150 u32 i, j;
151
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700152 tmp = kmemdup(rate1, rate1_size, GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700153 if (!tmp) {
154 dev_err(priv->adapter->dev, "failed to alloc tmp buf\n");
155 return -ENOMEM;
156 }
157
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700158 memset(rate1, 0, rate1_size);
159
160 for (i = 0; rate2[i] && i < rate2_size; i++) {
161 for (j = 0; tmp[j] && j < rate1_size; j++) {
162 /* Check common rate, excluding the bit for
163 basic rate */
164 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) {
165 *rate1++ = tmp[j];
166 break;
167 }
168 }
169 }
170
171 dev_dbg(priv->adapter->dev, "info: Tx data rate set to %#x\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700172 priv->data_rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700173
174 if (!priv->is_data_rate_auto) {
175 while (*ptr) {
176 if ((*ptr & 0x7f) == priv->data_rate) {
177 ret = 0;
178 goto done;
179 }
180 ptr++;
181 }
182 dev_err(priv->adapter->dev, "previously set fixed data rate %#x"
183 " is not compatible with the network\n",
184 priv->data_rate);
185
186 ret = -1;
187 goto done;
188 }
189
190 ret = 0;
191done:
192 kfree(tmp);
193 return ret;
194}
195
196/*
197 * This function creates the intersection of the rates supported by a
198 * target BSS and our adapter settings for use in an assoc/join command.
199 */
200static int
201mwifiex_setup_rates_from_bssdesc(struct mwifiex_private *priv,
202 struct mwifiex_bssdescriptor *bss_desc,
203 u8 *out_rates, u32 *out_rates_size)
204{
205 u8 card_rates[MWIFIEX_SUPPORTED_RATES];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700206 u32 card_rates_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700207
208 /* Copy AP supported rates */
209 memcpy(out_rates, bss_desc->supported_rates, MWIFIEX_SUPPORTED_RATES);
210 /* Get the STA supported rates */
211 card_rates_size = mwifiex_get_active_data_rates(priv, card_rates);
212 /* Get the common rates between AP and STA supported rates */
213 if (mwifiex_get_common_rates(priv, out_rates, MWIFIEX_SUPPORTED_RATES,
214 card_rates, card_rates_size)) {
215 *out_rates_size = 0;
216 dev_err(priv->adapter->dev, "%s: cannot get common rates\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700217 __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700218 return -1;
219 }
220
221 *out_rates_size =
222 min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES);
223
224 return 0;
225}
226
227/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700228 * This function appends a WPS IE. It is called from the network join command
229 * preparation routine.
230 *
231 * If the IE buffer has been setup by the application, this routine appends
232 * the buffer as a WPS TLV type to the request.
233 */
234static int
235mwifiex_cmd_append_wps_ie(struct mwifiex_private *priv, u8 **buffer)
236{
237 int retLen = 0;
238 struct mwifiex_ie_types_header ie_header;
239
240 if (!buffer || !*buffer)
241 return 0;
242
243 /*
244 * If there is a wps ie buffer setup, append it to the return
245 * parameter buffer pointer.
246 */
247 if (priv->wps_ie_len) {
248 dev_dbg(priv->adapter->dev, "cmd: append wps ie %d to %p\n",
249 priv->wps_ie_len, *buffer);
250
251 /* Wrap the generic IE buffer with a pass through TLV type */
252 ie_header.type = cpu_to_le16(TLV_TYPE_MGMT_IE);
253 ie_header.len = cpu_to_le16(priv->wps_ie_len);
254 memcpy(*buffer, &ie_header, sizeof(ie_header));
255 *buffer += sizeof(ie_header);
256 retLen += sizeof(ie_header);
257
258 memcpy(*buffer, priv->wps_ie, priv->wps_ie_len);
259 *buffer += priv->wps_ie_len;
260 retLen += priv->wps_ie_len;
261
262 }
263
264 kfree(priv->wps_ie);
265 priv->wps_ie_len = 0;
266 return retLen;
267}
268
269/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700270 * This function appends a WAPI IE.
271 *
272 * This function is called from the network join command preparation routine.
273 *
274 * If the IE buffer has been setup by the application, this routine appends
275 * the buffer as a WAPI TLV type to the request.
276 */
277static int
278mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer)
279{
280 int retLen = 0;
281 struct mwifiex_ie_types_header ie_header;
282
283 /* Null Checks */
284 if (buffer == NULL)
285 return 0;
286 if (*buffer == NULL)
287 return 0;
288
289 /*
290 * If there is a wapi ie buffer setup, append it to the return
291 * parameter buffer pointer.
292 */
293 if (priv->wapi_ie_len) {
294 dev_dbg(priv->adapter->dev, "cmd: append wapi ie %d to %p\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700295 priv->wapi_ie_len, *buffer);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700296
297 /* Wrap the generic IE buffer with a pass through TLV type */
298 ie_header.type = cpu_to_le16(TLV_TYPE_WAPI_IE);
299 ie_header.len = cpu_to_le16(priv->wapi_ie_len);
300 memcpy(*buffer, &ie_header, sizeof(ie_header));
301
302 /* Increment the return size and the return buffer pointer
303 param */
304 *buffer += sizeof(ie_header);
305 retLen += sizeof(ie_header);
306
307 /* Copy the wapi IE buffer to the output buffer, advance
308 pointer */
309 memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len);
310
311 /* Increment the return size and the return buffer pointer
312 param */
313 *buffer += priv->wapi_ie_len;
314 retLen += priv->wapi_ie_len;
315
316 }
317 /* return the length appended to the buffer */
318 return retLen;
319}
320
321/*
322 * This function appends rsn ie tlv for wpa/wpa2 security modes.
323 * It is called from the network join command preparation routine.
324 */
325static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private *priv,
326 u8 **buffer)
327{
328 struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv;
329 int rsn_ie_len;
330
331 if (!buffer || !(*buffer))
332 return 0;
333
334 rsn_ie_tlv = (struct mwifiex_ie_types_rsn_param_set *) (*buffer);
335 rsn_ie_tlv->header.type = cpu_to_le16((u16) priv->wpa_ie[0]);
336 rsn_ie_tlv->header.type = cpu_to_le16(
337 le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF);
338 rsn_ie_tlv->header.len = cpu_to_le16((u16) priv->wpa_ie[1]);
339 rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len)
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700340 & 0x00FF);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700341 if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2))
342 memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2],
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700343 le16_to_cpu(rsn_ie_tlv->header.len));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700344 else
345 return -1;
346
347 rsn_ie_len = sizeof(rsn_ie_tlv->header) +
348 le16_to_cpu(rsn_ie_tlv->header.len);
349 *buffer += rsn_ie_len;
350
351 return rsn_ie_len;
352}
353
354/*
355 * This function prepares command for association.
356 *
357 * This sets the following parameters -
358 * - Peer MAC address
359 * - Listen interval
360 * - Beacon interval
361 * - Capability information
362 *
363 * ...and the following TLVs, as required -
364 * - SSID TLV
365 * - PHY TLV
366 * - SS TLV
367 * - Rates TLV
368 * - Authentication TLV
369 * - Channel TLV
370 * - WPA/WPA2 IE
371 * - 11n TLV
372 * - Vendor specific TLV
373 * - WMM TLV
374 * - WAPI IE
375 * - Generic IE
376 * - TSF TLV
377 *
378 * Preparation also includes -
379 * - Setting command ID and proper size
380 * - Ensuring correct endian-ness
381 */
382int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
383 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700384 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700385{
386 struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700387 struct mwifiex_ie_types_ssid_param_set *ssid_tlv;
388 struct mwifiex_ie_types_phy_param_set *phy_tlv;
389 struct mwifiex_ie_types_ss_param_set *ss_tlv;
390 struct mwifiex_ie_types_rates_param_set *rates_tlv;
391 struct mwifiex_ie_types_auth_type *auth_tlv;
392 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
393 u8 rates[MWIFIEX_SUPPORTED_RATES];
394 u32 rates_size;
395 u16 tmp_cap;
396 u8 *pos;
397 int rsn_ie_len = 0;
398
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700399 pos = (u8 *) assoc;
400
401 mwifiex_cfg_tx_buf(priv, bss_desc);
402
403 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE);
404
405 /* Save so we know which BSS Desc to use in the response handler */
406 priv->attempted_bss_desc = bss_desc;
407
408 memcpy(assoc->peer_sta_addr,
409 bss_desc->mac_address, sizeof(assoc->peer_sta_addr));
410 pos += sizeof(assoc->peer_sta_addr);
411
412 /* Set the listen interval */
413 assoc->listen_interval = cpu_to_le16(priv->listen_interval);
414 /* Set the beacon period */
415 assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period);
416
417 pos += sizeof(assoc->cap_info_bitmap);
418 pos += sizeof(assoc->listen_interval);
419 pos += sizeof(assoc->beacon_period);
420 pos += sizeof(assoc->dtim_period);
421
422 ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos;
423 ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID);
424 ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len);
425 memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid,
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700426 le16_to_cpu(ssid_tlv->header.len));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700427 pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len);
428
429 phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos;
430 phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS);
431 phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set));
432 memcpy(&phy_tlv->fh_ds.ds_param_set,
433 &bss_desc->phy_param_set.ds_param_set.current_chan,
434 sizeof(phy_tlv->fh_ds.ds_param_set));
435 pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len);
436
437 ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos;
438 ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS);
439 ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set));
440 pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len);
441
442 /* Get the common rates supported between the driver and the BSS Desc */
443 if (mwifiex_setup_rates_from_bssdesc
444 (priv, bss_desc, rates, &rates_size))
445 return -1;
446
447 /* Save the data rates into Current BSS state structure */
448 priv->curr_bss_params.num_of_rates = rates_size;
449 memcpy(&priv->curr_bss_params.data_rates, rates, rates_size);
450
451 /* Setup the Rates TLV in the association command */
452 rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos;
453 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
454 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
455 memcpy(rates_tlv->rates, rates, rates_size);
456 pos += sizeof(rates_tlv->header) + rates_size;
457 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: rates size = %d\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700458 rates_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700459
Marc Yang203afec2011-03-24 20:49:39 -0700460 /* Add the Authentication type to be used for Auth frames */
461 auth_tlv = (struct mwifiex_ie_types_auth_type *) pos;
462 auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
463 auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type));
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800464 if (priv->sec_info.wep_enabled)
Marc Yang203afec2011-03-24 20:49:39 -0700465 auth_tlv->auth_type = cpu_to_le16(
466 (u16) priv->sec_info.authentication_mode);
467 else
Marc Yangf986b6d2011-03-28 17:55:42 -0700468 auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM);
Marc Yang203afec2011-03-24 20:49:39 -0700469
470 pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700471
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700472 if (IS_SUPPORT_MULTI_BANDS(priv->adapter) &&
473 !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
474 (!bss_desc->disable_11n) &&
475 (priv->adapter->config_bands & BAND_GN ||
476 priv->adapter->config_bands & BAND_AN) &&
477 (bss_desc->bcn_ht_cap)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700478 )
479 ) {
480 /* Append a channel TLV for the channel the attempted AP was
481 found on */
482 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
483 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
484 chan_tlv->header.len =
485 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
486
487 memset(chan_tlv->chan_scan_param, 0x00,
488 sizeof(struct mwifiex_chan_scan_param_set));
489 chan_tlv->chan_scan_param[0].chan_number =
490 (bss_desc->phy_param_set.ds_param_set.current_chan);
491 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700492 chan_tlv->chan_scan_param[0].chan_number);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700493
494 chan_tlv->chan_scan_param[0].radio_type =
495 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
496
497 dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700498 chan_tlv->chan_scan_param[0].radio_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700499 pos += sizeof(chan_tlv->header) +
500 sizeof(struct mwifiex_chan_scan_param_set);
501 }
502
503 if (!priv->wps.session_enable) {
504 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
505 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
506
507 if (rsn_ie_len == -1)
508 return -1;
509 }
510
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700511 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
512 (!bss_desc->disable_11n) &&
513 (priv->adapter->config_bands & BAND_GN ||
514 priv->adapter->config_bands & BAND_AN))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700515 mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos);
516
517 /* Append vendor specific IE TLV */
518 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos);
519
520 mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie,
521 bss_desc->bcn_ht_cap);
522 if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
523 mwifiex_cmd_append_wapi_ie(priv, &pos);
524
Avinash Patil13d7ba782012-04-09 20:06:56 -0700525 if (priv->wps.session_enable && priv->wps_ie_len)
526 mwifiex_cmd_append_wps_ie(priv, &pos);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700527
528 mwifiex_cmd_append_generic_ie(priv, &pos);
529
530 mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc);
531
532 cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN);
533
534 /* Set the Capability info at last */
535 tmp_cap = bss_desc->cap_info_bitmap;
536
537 if (priv->adapter->config_bands == BAND_B)
Bing Zhaob93f85f2011-03-25 19:47:01 -0700538 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700539
540 tmp_cap &= CAPINFO_MASK;
541 dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700542 tmp_cap, CAPINFO_MASK);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700543 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap);
544
545 return 0;
546}
547
548/*
549 * Association firmware command response handler
550 *
551 * The response buffer for the association command has the following
552 * memory layout.
553 *
554 * For cases where an association response was not received (indicated
555 * by the CapInfo and AId field):
556 *
557 * .------------------------------------------------------------.
558 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
559 * .------------------------------------------------------------.
560 * | cap_info/Error Return(t_u16): |
561 * | 0xFFFF(-1): Internal error |
562 * | 0xFFFE(-2): Authentication unhandled message |
563 * | 0xFFFD(-3): Authentication refused |
564 * | 0xFFFC(-4): Timeout waiting for AP response |
565 * .------------------------------------------------------------.
566 * | status_code(t_u16): |
567 * | If cap_info is -1: |
568 * | An internal firmware failure prevented the |
569 * | command from being processed. The status_code |
570 * | will be set to 1. |
571 * | |
572 * | If cap_info is -2: |
573 * | An authentication frame was received but was |
574 * | not handled by the firmware. IEEE Status |
575 * | code for the failure is returned. |
576 * | |
577 * | If cap_info is -3: |
578 * | An authentication frame was received and the |
579 * | status_code is the IEEE Status reported in the |
580 * | response. |
581 * | |
582 * | If cap_info is -4: |
583 * | (1) Association response timeout |
584 * | (2) Authentication response timeout |
585 * .------------------------------------------------------------.
586 * | a_id(t_u16): 0xFFFF |
587 * .------------------------------------------------------------.
588 *
589 *
590 * For cases where an association response was received, the IEEE
591 * standard association response frame is returned:
592 *
593 * .------------------------------------------------------------.
594 * | Header(4 * sizeof(t_u16)): Standard command response hdr |
595 * .------------------------------------------------------------.
596 * | cap_info(t_u16): IEEE Capability |
597 * .------------------------------------------------------------.
598 * | status_code(t_u16): IEEE Status Code |
599 * .------------------------------------------------------------.
600 * | a_id(t_u16): IEEE Association ID |
601 * .------------------------------------------------------------.
602 * | IEEE IEs(variable): Any received IEs comprising the |
603 * | remaining portion of a received |
604 * | association response frame. |
605 * .------------------------------------------------------------.
606 *
607 * For simplistic handling, the status_code field can be used to determine
608 * an association success (0) or failure (non-zero).
609 */
610int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700611 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700612{
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700613 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700614 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700615 struct ieee_types_assoc_rsp *assoc_rsp;
616 struct mwifiex_bssdescriptor *bss_desc;
617 u8 enable_data = true;
618
619 assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params;
620
621 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN,
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700622 sizeof(priv->assoc_rsp_buf));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700623
624 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size);
625
626 if (le16_to_cpu(assoc_rsp->status_code)) {
627 priv->adapter->dbg.num_cmd_assoc_failure++;
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700628 dev_err(priv->adapter->dev,
629 "ASSOC_RESP: failed, status code=%d err=%#x a_id=%#x\n",
630 le16_to_cpu(assoc_rsp->status_code),
631 le16_to_cpu(assoc_rsp->cap_info_bitmap),
632 le16_to_cpu(assoc_rsp->a_id));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700633
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800634 ret = le16_to_cpu(assoc_rsp->status_code);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700635 goto done;
636 }
637
638 /* Send a Media Connected event, according to the Spec */
639 priv->media_connected = true;
640
641 priv->adapter->ps_state = PS_STATE_AWAKE;
642 priv->adapter->pps_uapsd_mode = false;
643 priv->adapter->tx_lock_flag = false;
644
645 /* Set the attempted BSSID Index to current */
646 bss_desc = priv->attempted_bss_desc;
647
648 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700649 bss_desc->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700650
651 /* Make a copy of current BSSID descriptor */
652 memcpy(&priv->curr_bss_params.bss_descriptor,
653 bss_desc, sizeof(struct mwifiex_bssdescriptor));
654
655 /* Update curr_bss_params */
656 priv->curr_bss_params.bss_descriptor.channel
657 = bss_desc->phy_param_set.ds_param_set.current_chan;
658
659 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
660
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700661 if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC)
662 priv->curr_bss_params.wmm_enabled = true;
663 else
664 priv->curr_bss_params.wmm_enabled = false;
665
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700666 if ((priv->wmm_required || bss_desc->bcn_ht_cap) &&
667 priv->curr_bss_params.wmm_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700668 priv->wmm_enabled = true;
669 else
670 priv->wmm_enabled = false;
671
672 priv->curr_bss_params.wmm_uapsd_enabled = false;
673
674 if (priv->wmm_enabled)
675 priv->curr_bss_params.wmm_uapsd_enabled
676 = ((bss_desc->wmm_ie.qos_info_bitmap &
677 IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0);
678
679 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700680 priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700681 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
682 priv->wpa_is_gtk_set = false;
683
684 if (priv->wmm_enabled) {
685 /* Don't re-enable carrier until we get the WMM_GET_STATUS
686 event */
687 enable_data = false;
688 } else {
689 /* Since WMM is not enabled, setup the queues with the
690 defaults */
691 mwifiex_wmm_setup_queue_priorities(priv, NULL);
692 mwifiex_wmm_setup_ac_downgrade(priv);
693 }
694
695 if (enable_data)
696 dev_dbg(priv->adapter->dev,
697 "info: post association, re-enabling data flow\n");
698
699 /* Reset SNR/NF/RSSI values */
700 priv->data_rssi_last = 0;
701 priv->data_nf_last = 0;
702 priv->data_rssi_avg = 0;
703 priv->data_nf_avg = 0;
704 priv->bcn_rssi_last = 0;
705 priv->bcn_nf_last = 0;
706 priv->bcn_rssi_avg = 0;
707 priv->bcn_nf_avg = 0;
708 priv->rxpd_rate = 0;
709 priv->rxpd_htinfo = 0;
710
711 mwifiex_save_curr_bcn(priv);
712
713 priv->adapter->dbg.num_cmd_assoc_success++;
714
715 dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n");
716
717 /* Add the ra_list here for infra mode as there will be only 1 ra
718 always */
719 mwifiex_ralist_add(priv,
720 priv->curr_bss_params.bss_descriptor.mac_address);
721
722 if (!netif_carrier_ok(priv->netdev))
723 netif_carrier_on(priv->netdev);
Avinash Patil47411a02012-11-01 18:44:16 -0700724 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700725
726 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled)
727 priv->scan_block = true;
728
729done:
730 /* Need to indicate IOCTL complete */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700731 if (adapter->curr_cmd->wait_q_enabled) {
732 if (ret)
733 adapter->cmd_wait_q.status = -1;
734 else
735 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700736 }
737
738 return ret;
739}
740
741/*
742 * This function prepares command for ad-hoc start.
743 *
744 * Driver will fill up SSID, BSS mode, IBSS parameters, physical
745 * parameters, probe delay, and capability information. Firmware
746 * will fill up beacon period, basic rates and operational rates.
747 *
748 * In addition, the following TLVs are added -
749 * - Channel TLV
750 * - Vendor specific IE
751 * - WPA/WPA2 IE
752 * - HT Capabilities IE
753 * - HT Information IE
754 *
755 * Preparation also includes -
756 * - Setting command ID and proper size
757 * - Ensuring correct endian-ness
758 */
759int
760mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700761 struct host_cmd_ds_command *cmd,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800762 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700763{
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700764 int rsn_ie_len = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700765 struct mwifiex_adapter *adapter = priv->adapter;
766 struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start =
767 &cmd->params.adhoc_start;
768 struct mwifiex_bssdescriptor *bss_desc;
769 u32 cmd_append_size = 0;
770 u32 i;
771 u16 tmp_cap;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700772 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800773 u8 radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700774
775 struct mwifiex_ie_types_htcap *ht_cap;
776 struct mwifiex_ie_types_htinfo *ht_info;
777 u8 *pos = (u8 *) adhoc_start +
778 sizeof(struct host_cmd_ds_802_11_ad_hoc_start);
779
780 if (!adapter)
781 return -1;
782
783 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START);
784
785 bss_desc = &priv->curr_bss_params.bss_descriptor;
786 priv->attempted_bss_desc = bss_desc;
787
788 /*
789 * Fill in the parameters for 2 data structures:
790 * 1. struct host_cmd_ds_802_11_ad_hoc_start command
791 * 2. bss_desc
792 * Driver will fill up SSID, bss_mode,IBSS param, Physical Param,
793 * probe delay, and Cap info.
794 * Firmware will fill up beacon period, Basic rates
795 * and operational rates.
796 */
797
798 memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN);
799
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700800 memcpy(adhoc_start->ssid, req_ssid->ssid, req_ssid->ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700801
802 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700803 adhoc_start->ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700804
805 memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700806 memcpy(bss_desc->ssid.ssid, req_ssid->ssid, req_ssid->ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700807
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700808 bss_desc->ssid.ssid_len = req_ssid->ssid_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700809
810 /* Set the BSS mode */
811 adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700812 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700813 adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period);
814 bss_desc->beacon_period = priv->beacon_period;
815
816 /* Set Physical param set */
817/* Parameter IE Id */
818#define DS_PARA_IE_ID 3
819/* Parameter IE length */
820#define DS_PARA_IE_LEN 1
821
822 adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
823 adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
824
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -0700825 if (!mwifiex_get_cfp(priv, adapter->adhoc_start_band,
826 (u16) priv->adhoc_channel, 0)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700827 struct mwifiex_chan_freq_power *cfp;
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -0700828 cfp = mwifiex_get_cfp(priv, adapter->adhoc_start_band,
829 FIRST_VALID_CHANNEL, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700830 if (cfp)
831 priv->adhoc_channel = (u8) cfp->channel;
832 }
833
834 if (!priv->adhoc_channel) {
835 dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n");
836 return -1;
837 }
838
839 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700840 priv->adhoc_channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700841
842 priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel;
843 priv->curr_bss_params.band = adapter->adhoc_start_band;
844
845 bss_desc->channel = priv->adhoc_channel;
846 adhoc_start->phy_param_set.ds_param_set.current_chan =
847 priv->adhoc_channel;
848
849 memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set,
850 sizeof(union ieee_types_phy_param_set));
851
852 /* Set IBSS param set */
853/* IBSS parameter IE Id */
854#define IBSS_PARA_IE_ID 6
855/* IBSS parameter IE length */
856#define IBSS_PARA_IE_LEN 2
857
858 adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID;
859 adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN;
860 adhoc_start->ss_param_set.ibss_param_set.atim_window
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700861 = cpu_to_le16(priv->atim_window);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700862 memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set,
863 sizeof(union ieee_types_ss_param_set));
864
865 /* Set Capability info */
866 bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS;
867 tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap);
868 tmp_cap &= ~WLAN_CAPABILITY_ESS;
869 tmp_cap |= WLAN_CAPABILITY_IBSS;
870
871 /* Set up privacy in bss_desc */
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700872 if (priv->sec_info.encryption_mode) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700873 /* Ad-Hoc capability privacy on */
874 dev_dbg(adapter->dev,
875 "info: ADHOC_S_CMD: wep_status set privacy to WEP\n");
876 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
877 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
878 } else {
879 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set,"
880 " setting privacy to ACCEPT ALL\n");
881 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
882 }
883
Yogesh Ashok Powar63af6332011-11-07 21:41:09 -0800884 memset(adhoc_start->data_rate, 0, sizeof(adhoc_start->data_rate));
885 mwifiex_get_active_data_rates(priv, adhoc_start->data_rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700886 if ((adapter->adhoc_start_band & BAND_G) &&
887 (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) {
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700888 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700889 HostCmd_ACT_GEN_SET, 0,
890 &priv->curr_pkt_filter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700891 dev_err(adapter->dev,
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700892 "ADHOC_S_CMD: G Protection config failed\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700893 return -1;
894 }
895 }
896 /* Find the last non zero */
Yogesh Ashok Powar63af6332011-11-07 21:41:09 -0800897 for (i = 0; i < sizeof(adhoc_start->data_rate); i++)
898 if (!adhoc_start->data_rate[i])
899 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700900
901 priv->curr_bss_params.num_of_rates = i;
902
903 /* Copy the ad-hoc creating rates into Current BSS rate structure */
904 memcpy(&priv->curr_bss_params.data_rates,
Yogesh Ashok Powar63af6332011-11-07 21:41:09 -0800905 &adhoc_start->data_rate, priv->curr_bss_params.num_of_rates);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700906
907 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700908 adhoc_start->data_rate[0], adhoc_start->data_rate[1],
909 adhoc_start->data_rate[2], adhoc_start->data_rate[3]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700910
911 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n");
912
913 if (IS_SUPPORT_MULTI_BANDS(adapter)) {
914 /* Append a channel TLV */
915 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
916 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
917 chan_tlv->header.len =
918 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
919
920 memset(chan_tlv->chan_scan_param, 0x00,
921 sizeof(struct mwifiex_chan_scan_param_set));
922 chan_tlv->chan_scan_param[0].chan_number =
923 (u8) priv->curr_bss_params.bss_descriptor.channel;
924
925 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700926 chan_tlv->chan_scan_param[0].chan_number);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700927
928 chan_tlv->chan_scan_param[0].radio_type
929 = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700930 if (adapter->adhoc_start_band & BAND_GN ||
931 adapter->adhoc_start_band & BAND_AN) {
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800932 if (adapter->sec_chan_offset ==
933 IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700934 chan_tlv->chan_scan_param[0].radio_type |=
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800935 (IEEE80211_HT_PARAM_CHA_SEC_ABOVE << 4);
936 else if (adapter->sec_chan_offset ==
937 IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700938 chan_tlv->chan_scan_param[0].radio_type |=
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800939 (IEEE80211_HT_PARAM_CHA_SEC_BELOW << 4);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700940 }
941 dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700942 chan_tlv->chan_scan_param[0].radio_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700943 pos += sizeof(chan_tlv->header) +
944 sizeof(struct mwifiex_chan_scan_param_set);
945 cmd_append_size +=
946 sizeof(chan_tlv->header) +
947 sizeof(struct mwifiex_chan_scan_param_set);
948 }
949
950 /* Append vendor specific IE TLV */
951 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
952 MWIFIEX_VSIE_MASK_ADHOC, &pos);
953
954 if (priv->sec_info.wpa_enabled) {
955 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
956 if (rsn_ie_len == -1)
957 return -1;
958 cmd_append_size += rsn_ie_len;
959 }
960
961 if (adapter->adhoc_11n_enabled) {
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800962 /* Fill HT CAPABILITY */
963 ht_cap = (struct mwifiex_ie_types_htcap *) pos;
964 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
965 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
966 ht_cap->header.len =
967 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
968 radio_type = mwifiex_band_to_radio_type(
969 priv->adapter->config_bands);
970 mwifiex_fill_cap_info(priv, radio_type, ht_cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700971
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800972 pos += sizeof(struct mwifiex_ie_types_htcap);
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700973 cmd_append_size += sizeof(struct mwifiex_ie_types_htcap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700974
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800975 /* Fill HT INFORMATION */
976 ht_info = (struct mwifiex_ie_types_htinfo *) pos;
977 memset(ht_info, 0, sizeof(struct mwifiex_ie_types_htinfo));
Johannes Berg074d46d2012-03-15 19:45:16 +0100978 ht_info->header.type = cpu_to_le16(WLAN_EID_HT_OPERATION);
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800979 ht_info->header.len =
Johannes Berg074d46d2012-03-15 19:45:16 +0100980 cpu_to_le16(sizeof(struct ieee80211_ht_operation));
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800981
Johannes Berg074d46d2012-03-15 19:45:16 +0100982 ht_info->ht_oper.primary_chan =
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800983 (u8) priv->curr_bss_params.bss_descriptor.channel;
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800984 if (adapter->sec_chan_offset) {
Johannes Berg074d46d2012-03-15 19:45:16 +0100985 ht_info->ht_oper.ht_param = adapter->sec_chan_offset;
986 ht_info->ht_oper.ht_param |=
Marc Yang6d2bd912011-03-25 19:47:02 -0700987 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700988 }
Johannes Berg074d46d2012-03-15 19:45:16 +0100989 ht_info->ht_oper.operation_mode =
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800990 cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
Johannes Berg074d46d2012-03-15 19:45:16 +0100991 ht_info->ht_oper.basic_set[0] = 0xff;
Yogesh Ashok Powareedf15d2011-11-07 21:41:07 -0800992 pos += sizeof(struct mwifiex_ie_types_htinfo);
993 cmd_append_size +=
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700994 sizeof(struct mwifiex_ie_types_htinfo);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700995 }
996
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -0700997 cmd->size =
998 cpu_to_le16((u16)(sizeof(struct host_cmd_ds_802_11_ad_hoc_start)
999 + S_DS_GEN + cmd_append_size));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001000
1001 if (adapter->adhoc_start_band == BAND_B)
Bing Zhaob93f85f2011-03-25 19:47:01 -07001002 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001003 else
Bing Zhaob93f85f2011-03-25 19:47:01 -07001004 tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001005
1006 adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap);
1007
1008 return 0;
1009}
1010
1011/*
1012 * This function prepares command for ad-hoc join.
1013 *
1014 * Most of the parameters are set up by copying from the target BSS descriptor
1015 * from the scan response.
1016 *
1017 * In addition, the following TLVs are added -
1018 * - Channel TLV
1019 * - Vendor specific IE
1020 * - WPA/WPA2 IE
1021 * - 11n IE
1022 *
1023 * Preparation also includes -
1024 * - Setting command ID and proper size
1025 * - Ensuring correct endian-ness
1026 */
1027int
1028mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001029 struct host_cmd_ds_command *cmd,
1030 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001031{
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001032 int rsn_ie_len = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001033 struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join =
1034 &cmd->params.adhoc_join;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001035 struct mwifiex_ie_types_chan_list_param_set *chan_tlv;
1036 u32 cmd_append_size = 0;
1037 u16 tmp_cap;
1038 u32 i, rates_size = 0;
1039 u16 curr_pkt_filter;
1040 u8 *pos =
1041 (u8 *) adhoc_join +
1042 sizeof(struct host_cmd_ds_802_11_ad_hoc_join);
1043
1044/* Use G protection */
1045#define USE_G_PROTECTION 0x02
1046 if (bss_desc->erp_flags & USE_G_PROTECTION) {
1047 curr_pkt_filter =
1048 priv->
1049 curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON;
1050
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001051 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001052 HostCmd_ACT_GEN_SET, 0,
1053 &curr_pkt_filter)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001054 dev_err(priv->adapter->dev,
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001055 "ADHOC_J_CMD: G Protection config failed\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001056 return -1;
1057 }
1058 }
1059
1060 priv->attempted_bss_desc = bss_desc;
1061
1062 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
1063
1064 adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS;
1065
1066 adhoc_join->bss_descriptor.beacon_period
1067 = cpu_to_le16(bss_desc->beacon_period);
1068
1069 memcpy(&adhoc_join->bss_descriptor.bssid,
1070 &bss_desc->mac_address, ETH_ALEN);
1071
1072 memcpy(&adhoc_join->bss_descriptor.ssid,
1073 &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len);
1074
1075 memcpy(&adhoc_join->bss_descriptor.phy_param_set,
1076 &bss_desc->phy_param_set,
1077 sizeof(union ieee_types_phy_param_set));
1078
1079 memcpy(&adhoc_join->bss_descriptor.ss_param_set,
1080 &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set));
1081
1082 tmp_cap = bss_desc->cap_info_bitmap;
1083
1084 tmp_cap &= CAPINFO_MASK;
1085
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001086 dev_dbg(priv->adapter->dev,
1087 "info: ADHOC_J_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n",
1088 tmp_cap, CAPINFO_MASK);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001089
1090 /* Information on BSSID descriptor passed to FW */
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001091 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID=%pM, SSID='%s'\n",
1092 adhoc_join->bss_descriptor.bssid,
1093 adhoc_join->bss_descriptor.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001094
1095 for (i = 0; bss_desc->supported_rates[i] &&
1096 i < MWIFIEX_SUPPORTED_RATES;
1097 i++)
1098 ;
1099 rates_size = i;
1100
1101 /* Copy Data Rates from the Rates recorded in scan response */
1102 memset(adhoc_join->bss_descriptor.data_rates, 0,
1103 sizeof(adhoc_join->bss_descriptor.data_rates));
1104 memcpy(adhoc_join->bss_descriptor.data_rates,
1105 bss_desc->supported_rates, rates_size);
1106
1107 /* Copy the adhoc join rates into Current BSS state structure */
1108 priv->curr_bss_params.num_of_rates = rates_size;
1109 memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates,
1110 rates_size);
1111
1112 /* Copy the channel information */
1113 priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel;
1114 priv->curr_bss_params.band = (u8) bss_desc->bss_band;
1115
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -08001116 if (priv->sec_info.wep_enabled || priv->sec_info.wpa_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001117 tmp_cap |= WLAN_CAPABILITY_PRIVACY;
1118
1119 if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) {
1120 /* Append a channel TLV */
1121 chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos;
1122 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
1123 chan_tlv->header.len =
1124 cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
1125
1126 memset(chan_tlv->chan_scan_param, 0x00,
1127 sizeof(struct mwifiex_chan_scan_param_set));
1128 chan_tlv->chan_scan_param[0].chan_number =
1129 (bss_desc->phy_param_set.ds_param_set.current_chan);
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001130 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan=%d\n",
1131 chan_tlv->chan_scan_param[0].chan_number);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001132
1133 chan_tlv->chan_scan_param[0].radio_type =
1134 mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
1135
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001136 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band=%d\n",
1137 chan_tlv->chan_scan_param[0].radio_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001138 pos += sizeof(chan_tlv->header) +
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001139 sizeof(struct mwifiex_chan_scan_param_set);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001140 cmd_append_size += sizeof(chan_tlv->header) +
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001141 sizeof(struct mwifiex_chan_scan_param_set);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001142 }
1143
1144 if (priv->sec_info.wpa_enabled)
1145 rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos);
1146 if (rsn_ie_len == -1)
1147 return -1;
1148 cmd_append_size += rsn_ie_len;
1149
1150 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1151 cmd_append_size += mwifiex_cmd_append_11n_tlv(priv,
1152 bss_desc, &pos);
1153
1154 /* Append vendor specific IE TLV */
1155 cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv,
1156 MWIFIEX_VSIE_MASK_ADHOC, &pos);
1157
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001158 cmd->size = cpu_to_le16
1159 ((u16) (sizeof(struct host_cmd_ds_802_11_ad_hoc_join)
1160 + S_DS_GEN + cmd_append_size));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161
1162 adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap);
1163
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001164 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001165}
1166
1167/*
1168 * This function handles the command response of ad-hoc start and
1169 * ad-hoc join.
1170 *
1171 * The function generates a device-connected event to notify
1172 * the applications, in case of successful ad-hoc start/join, and
1173 * saves the beacon buffer.
1174 */
1175int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001176 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001177{
1178 int ret = 0;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001179 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001180 struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result;
1181 struct mwifiex_bssdescriptor *bss_desc;
Amitkumar Karwar8cc1d522012-10-05 20:21:43 -07001182 u16 reason_code;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001183
1184 adhoc_result = &resp->params.adhoc_result;
1185
1186 bss_desc = priv->attempted_bss_desc;
1187
1188 /* Join result code 0 --> SUCCESS */
Amitkumar Karwar8cc1d522012-10-05 20:21:43 -07001189 reason_code = le16_to_cpu(resp->result);
1190 if (reason_code) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001191 dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n");
1192 if (priv->media_connected)
Amitkumar Karwar8cc1d522012-10-05 20:21:43 -07001193 mwifiex_reset_connect_state(priv, reason_code);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001194
1195 memset(&priv->curr_bss_params.bss_descriptor,
1196 0x00, sizeof(struct mwifiex_bssdescriptor));
1197
1198 ret = -1;
1199 goto done;
1200 }
1201
1202 /* Send a Media Connected event, according to the Spec */
1203 priv->media_connected = true;
1204
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001205 if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001206 dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001207 bss_desc->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001208
1209 /* Update the created network descriptor with the new BSSID */
1210 memcpy(bss_desc->mac_address,
1211 adhoc_result->bssid, ETH_ALEN);
1212
1213 priv->adhoc_state = ADHOC_STARTED;
1214 } else {
1215 /*
1216 * Now the join cmd should be successful.
1217 * If BSSID has changed use SSID to compare instead of BSSID
1218 */
1219 dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001220 bss_desc->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001221
1222 /*
1223 * Make a copy of current BSSID descriptor, only needed for
1224 * join since the current descriptor is already being used
1225 * for adhoc start
1226 */
1227 memcpy(&priv->curr_bss_params.bss_descriptor,
1228 bss_desc, sizeof(struct mwifiex_bssdescriptor));
1229
1230 priv->adhoc_state = ADHOC_JOINED;
1231 }
1232
1233 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001234 priv->adhoc_channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001235 dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001236 priv->curr_bss_params.bss_descriptor.mac_address);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001237
1238 if (!netif_carrier_ok(priv->netdev))
1239 netif_carrier_on(priv->netdev);
Avinash Patil47411a02012-11-01 18:44:16 -07001240 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001241
1242 mwifiex_save_curr_bcn(priv);
1243
1244done:
1245 /* Need to indicate IOCTL complete */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001246 if (adapter->curr_cmd->wait_q_enabled) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001247 if (ret)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001248 adapter->cmd_wait_q.status = -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001249 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001250 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001251
1252 }
1253
1254 return ret;
1255}
1256
1257/*
1258 * This function associates to a specific BSS discovered in a scan.
1259 *
1260 * It clears any past association response stored for application
1261 * retrieval and calls the command preparation routine to send the
1262 * command to firmware.
1263 */
1264int mwifiex_associate(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001265 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001266{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001267 u8 current_bssid[ETH_ALEN];
1268
1269 /* Return error if the adapter or table entry is not marked as infra */
Bing Zhaoeecd8252011-03-28 17:55:41 -07001270 if ((priv->bss_mode != NL80211_IFTYPE_STATION) ||
1271 (bss_desc->bss_mode != NL80211_IFTYPE_STATION))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001272 return -1;
1273
1274 memcpy(&current_bssid,
1275 &priv->curr_bss_params.bss_descriptor.mac_address,
1276 sizeof(current_bssid));
1277
1278 /* Clear any past association response stored for application
1279 retrieval */
1280 priv->assoc_rsp_size = 0;
1281
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001282 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_ASSOCIATE,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001283 HostCmd_ACT_GEN_SET, 0, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001284}
1285
1286/*
1287 * This function starts an ad-hoc network.
1288 *
1289 * It calls the command preparation routine to send the command to firmware.
1290 */
1291int
1292mwifiex_adhoc_start(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08001293 struct cfg80211_ssid *adhoc_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001294{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001295 dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n",
1296 priv->adhoc_channel);
1297 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001298 priv->curr_bss_params.bss_descriptor.channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001299 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001300 priv->curr_bss_params.band);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001301
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001302 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_START,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001303 HostCmd_ACT_GEN_SET, 0, adhoc_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001304}
1305
1306/*
1307 * This function joins an ad-hoc network found in a previous scan.
1308 *
1309 * It calls the command preparation routine to send the command to firmware,
1310 * if already not connected to the requested SSID.
1311 */
1312int mwifiex_adhoc_join(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001313 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001314{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001315 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001316 priv->curr_bss_params.bss_descriptor.ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001317 dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001318 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001319 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n",
1320 bss_desc->ssid.ssid);
1321 dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001322 bss_desc->ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001323
1324 /* Check if the requested SSID is already joined */
1325 if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len &&
1326 !mwifiex_ssid_cmp(&bss_desc->ssid,
1327 &priv->curr_bss_params.bss_descriptor.ssid) &&
1328 (priv->curr_bss_params.bss_descriptor.bss_mode ==
Bing Zhaoeecd8252011-03-28 17:55:41 -07001329 NL80211_IFTYPE_ADHOC)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001330 dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID"
1331 " is the same as current; not attempting to re-join\n");
1332 return -1;
1333 }
1334
1335 dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001336 priv->curr_bss_params.bss_descriptor.channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001337 dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n",
Yogesh Ashok Powar931f1582012-03-13 19:22:36 -07001338 priv->curr_bss_params.band);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001339
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001340 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_JOIN,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001341 HostCmd_ACT_GEN_SET, 0, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001342}
1343
1344/*
1345 * This function deauthenticates/disconnects from infra network by sending
1346 * deauthentication request.
1347 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001348static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001349{
1350 u8 mac_address[ETH_ALEN];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001351 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001352
Joe Perches2c208892012-06-04 12:44:17 +00001353 if (!mac || is_zero_ether_addr(mac))
1354 memcpy(mac_address,
1355 priv->curr_bss_params.bss_descriptor.mac_address,
1356 ETH_ALEN);
1357 else
1358 memcpy(mac_address, mac, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001359
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001360 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
Joe Perches2c208892012-06-04 12:44:17 +00001361 HostCmd_ACT_GEN_SET, 0, mac_address);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001362
1363 return ret;
1364}
1365
1366/*
1367 * This function deauthenticates/disconnects from a BSS.
1368 *
1369 * In case of infra made, it sends deauthentication request, and
1370 * in case of ad-hoc mode, a stop network request is sent to the firmware.
Avinash Patil26134e62012-05-08 18:30:21 -07001371 * In AP mode, a command to stop bss is sent to firmware.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001372 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001373int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001374{
Bing Zhao99e126f2012-05-01 19:53:51 -07001375 if (!priv->media_connected)
1376 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001377
Bing Zhao99e126f2012-05-01 19:53:51 -07001378 switch (priv->bss_mode) {
1379 case NL80211_IFTYPE_STATION:
1380 return mwifiex_deauthenticate_infra(priv, mac);
1381 case NL80211_IFTYPE_ADHOC:
1382 return mwifiex_send_cmd_sync(priv,
1383 HostCmd_CMD_802_11_AD_HOC_STOP,
1384 HostCmd_ACT_GEN_SET, 0, NULL);
Avinash Patil26134e62012-05-08 18:30:21 -07001385 case NL80211_IFTYPE_AP:
1386 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
1387 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao99e126f2012-05-01 19:53:51 -07001388 default:
1389 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001390 }
1391
Bing Zhao99e126f2012-05-01 19:53:51 -07001392 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001393}
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001394EXPORT_SYMBOL_GPL(mwifiex_deauthenticate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001395
1396/*
1397 * This function converts band to radio type used in channel TLV.
1398 */
1399u8
1400mwifiex_band_to_radio_type(u8 band)
1401{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001402 switch (band) {
1403 case BAND_A:
1404 case BAND_AN:
1405 case BAND_A | BAND_AN:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001406 return HostCmd_SCAN_RADIO_TYPE_A;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001407 case BAND_B:
1408 case BAND_G:
1409 case BAND_B | BAND_G:
1410 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001411 return HostCmd_SCAN_RADIO_TYPE_BG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001412 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001413}