mwifiex: maintain station statistic in uap mode
[deliverable/linux.git] / drivers / net / wireless / mwifiex / uap_cmd.c
CommitLineData
40d07030
AP
1/*
2 * Marvell Wireless LAN device driver: AP specific command handling
3 *
65da33f5 4 * Copyright (C) 2012-2014, Marvell International Ltd.
40d07030
AP
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 "main.h"
83c78da9 21#include "11ac.h"
40d07030 22
f752dcd5
AP
23/* This function parses security related parameters from cfg80211_ap_settings
24 * and sets into FW understandable bss_config structure.
25 */
26int mwifiex_set_secure_params(struct mwifiex_private *priv,
27 struct mwifiex_uap_bss_param *bss_config,
28 struct cfg80211_ap_settings *params) {
29 int i;
96893538 30 struct mwifiex_wep_key wep_key;
f752dcd5 31
6ddcd464
AP
32 if (!params->privacy) {
33 bss_config->protocol = PROTOCOL_NO_SECURITY;
34 bss_config->key_mgmt = KEY_MGMT_NONE;
35 bss_config->wpa_cfg.length = 0;
36 priv->sec_info.wep_enabled = 0;
37 priv->sec_info.wpa_enabled = 0;
38 priv->sec_info.wpa2_enabled = 0;
39
40 return 0;
41 }
42
f752dcd5
AP
43 switch (params->auth_type) {
44 case NL80211_AUTHTYPE_OPEN_SYSTEM:
45 bss_config->auth_mode = WLAN_AUTH_OPEN;
46 break;
47 case NL80211_AUTHTYPE_SHARED_KEY:
48 bss_config->auth_mode = WLAN_AUTH_SHARED_KEY;
49 break;
50 case NL80211_AUTHTYPE_NETWORK_EAP:
51 bss_config->auth_mode = WLAN_AUTH_LEAP;
52 break;
53 default:
54 bss_config->auth_mode = MWIFIEX_AUTH_MODE_AUTO;
55 break;
56 }
57
58 bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
59
60 for (i = 0; i < params->crypto.n_akm_suites; i++) {
61 switch (params->crypto.akm_suites[i]) {
62 case WLAN_AKM_SUITE_8021X:
63 if (params->crypto.wpa_versions &
64 NL80211_WPA_VERSION_1) {
65 bss_config->protocol = PROTOCOL_WPA;
66 bss_config->key_mgmt = KEY_MGMT_EAP;
67 }
68 if (params->crypto.wpa_versions &
69 NL80211_WPA_VERSION_2) {
0fd66be4 70 bss_config->protocol |= PROTOCOL_WPA2;
f752dcd5
AP
71 bss_config->key_mgmt = KEY_MGMT_EAP;
72 }
73 break;
74 case WLAN_AKM_SUITE_PSK:
75 if (params->crypto.wpa_versions &
76 NL80211_WPA_VERSION_1) {
77 bss_config->protocol = PROTOCOL_WPA;
78 bss_config->key_mgmt = KEY_MGMT_PSK;
79 }
80 if (params->crypto.wpa_versions &
81 NL80211_WPA_VERSION_2) {
0fd66be4 82 bss_config->protocol |= PROTOCOL_WPA2;
f752dcd5
AP
83 bss_config->key_mgmt = KEY_MGMT_PSK;
84 }
85 break;
86 default:
87 break;
88 }
89 }
90 for (i = 0; i < params->crypto.n_ciphers_pairwise; i++) {
91 switch (params->crypto.ciphers_pairwise[i]) {
92 case WLAN_CIPHER_SUITE_WEP40:
93 case WLAN_CIPHER_SUITE_WEP104:
94 break;
95 case WLAN_CIPHER_SUITE_TKIP:
0fd66be4
AP
96 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
97 bss_config->wpa_cfg.pairwise_cipher_wpa |=
98 CIPHER_TKIP;
99 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
100 bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
101 CIPHER_TKIP;
f752dcd5
AP
102 break;
103 case WLAN_CIPHER_SUITE_CCMP:
0fd66be4
AP
104 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
105 bss_config->wpa_cfg.pairwise_cipher_wpa |=
106 CIPHER_AES_CCMP;
107 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
108 bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
f752dcd5
AP
109 CIPHER_AES_CCMP;
110 default:
111 break;
112 }
113 }
114
115 switch (params->crypto.cipher_group) {
116 case WLAN_CIPHER_SUITE_WEP40:
117 case WLAN_CIPHER_SUITE_WEP104:
96893538
AP
118 if (priv->sec_info.wep_enabled) {
119 bss_config->protocol = PROTOCOL_STATIC_WEP;
120 bss_config->key_mgmt = KEY_MGMT_NONE;
121 bss_config->wpa_cfg.length = 0;
122
123 for (i = 0; i < NUM_WEP_KEYS; i++) {
124 wep_key = priv->wep_key[i];
125 bss_config->wep_cfg[i].key_index = i;
126
127 if (priv->wep_key_curr_index == i)
128 bss_config->wep_cfg[i].is_default = 1;
129 else
130 bss_config->wep_cfg[i].is_default = 0;
131
132 bss_config->wep_cfg[i].length =
133 wep_key.key_length;
134 memcpy(&bss_config->wep_cfg[i].key,
135 &wep_key.key_material,
136 wep_key.key_length);
137 }
138 }
f752dcd5
AP
139 break;
140 case WLAN_CIPHER_SUITE_TKIP:
141 bss_config->wpa_cfg.group_cipher = CIPHER_TKIP;
142 break;
143 case WLAN_CIPHER_SUITE_CCMP:
144 bss_config->wpa_cfg.group_cipher = CIPHER_AES_CCMP;
145 break;
146 default:
147 break;
148 }
149
150 return 0;
151}
152
22281256
AP
153/* This function updates 11n related parameters from IE and sets them into
154 * bss_config structure.
155 */
156void
157mwifiex_set_ht_params(struct mwifiex_private *priv,
158 struct mwifiex_uap_bss_param *bss_cfg,
159 struct cfg80211_ap_settings *params)
160{
161 const u8 *ht_ie;
474a41e9 162 u16 cap_info;
22281256
AP
163
164 if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
165 return;
166
167 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
168 params->beacon.tail_len);
169 if (ht_ie) {
9ab7b5b9 170 memcpy(&bss_cfg->ht_cap, ht_ie + 2,
22281256 171 sizeof(struct ieee80211_ht_cap));
474a41e9
MH
172 cap_info = le16_to_cpu(bss_cfg->ht_cap.cap_info);
173 memset(&bss_cfg->ht_cap.mcs, 0,
174 priv->adapter->number_of_antenna);
175 switch (GET_RXSTBC(cap_info)) {
176 case MWIFIEX_RX_STBC1:
177 /* HT_CAP 1X1 mode */
16cf6b80 178 bss_cfg->ht_cap.mcs.rx_mask[0] = 0xff;
474a41e9
MH
179 break;
180 case MWIFIEX_RX_STBC12: /* fall through */
181 case MWIFIEX_RX_STBC123:
182 /* HT_CAP 2X2 mode */
16cf6b80
MH
183 bss_cfg->ht_cap.mcs.rx_mask[0] = 0xff;
184 bss_cfg->ht_cap.mcs.rx_mask[1] = 0xff;
474a41e9
MH
185 break;
186 default:
acebe8c1
ZL
187 mwifiex_dbg(priv->adapter, WARN,
188 "Unsupported RX-STBC, default to 2x2\n");
16cf6b80
MH
189 bss_cfg->ht_cap.mcs.rx_mask[0] = 0xff;
190 bss_cfg->ht_cap.mcs.rx_mask[1] = 0xff;
474a41e9
MH
191 break;
192 }
c8258913 193 priv->ap_11n_enabled = 1;
22281256
AP
194 } else {
195 memset(&bss_cfg->ht_cap , 0, sizeof(struct ieee80211_ht_cap));
196 bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP);
197 bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU;
198 }
199
200 return;
201}
202
83c78da9
YAP
203/* This function updates 11ac related parameters from IE
204 * and sets them into bss_config structure.
205 */
206void mwifiex_set_vht_params(struct mwifiex_private *priv,
207 struct mwifiex_uap_bss_param *bss_cfg,
208 struct cfg80211_ap_settings *params)
209{
210 const u8 *vht_ie;
211
212 vht_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, params->beacon.tail,
213 params->beacon.tail_len);
214 if (vht_ie) {
215 memcpy(&bss_cfg->vht_cap, vht_ie + 2,
216 sizeof(struct ieee80211_vht_cap));
217 priv->ap_11ac_enabled = 1;
218 } else {
219 priv->ap_11ac_enabled = 0;
220 }
221
222 return;
223}
224
225/* Enable VHT only when cfg80211_ap_settings has VHT IE.
226 * Otherwise disable VHT.
227 */
228void mwifiex_set_vht_width(struct mwifiex_private *priv,
229 enum nl80211_chan_width width,
230 bool ap_11ac_enable)
231{
232 struct mwifiex_adapter *adapter = priv->adapter;
233 struct mwifiex_11ac_vht_cfg vht_cfg;
234
235 vht_cfg.band_config = VHT_CFG_5GHZ;
236 vht_cfg.cap_info = adapter->hw_dot_11ac_dev_cap;
237
238 if (!ap_11ac_enable) {
239 vht_cfg.mcs_tx_set = DISABLE_VHT_MCS_SET;
240 vht_cfg.mcs_rx_set = DISABLE_VHT_MCS_SET;
241 } else {
242 vht_cfg.mcs_tx_set = DEFAULT_VHT_MCS_SET;
243 vht_cfg.mcs_rx_set = DEFAULT_VHT_MCS_SET;
244 }
245
246 vht_cfg.misc_config = VHT_CAP_UAP_ONLY;
247
248 if (ap_11ac_enable && width >= NL80211_CHAN_WIDTH_80)
249 vht_cfg.misc_config |= VHT_BW_80_160_80P80;
250
fa0ecbb9
BZ
251 mwifiex_send_cmd(priv, HostCmd_CMD_11AC_CFG,
252 HostCmd_ACT_GEN_SET, 0, &vht_cfg, true);
83c78da9
YAP
253
254 return;
255}
256
a3c2c4f6
AP
257/* This function finds supported rates IE from beacon parameter and sets
258 * these rates into bss_config structure.
259 */
260void
261mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
262 struct cfg80211_ap_settings *params)
263{
264 struct ieee_types_header *rate_ie;
265 int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
266 const u8 *var_pos = params->beacon.head + var_offset;
267 int len = params->beacon.head_len - var_offset;
3a5b8a16 268 u8 rate_len = 0;
a3c2c4f6
AP
269
270 rate_ie = (void *)cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
3a5b8a16 271 if (rate_ie) {
a3c2c4f6 272 memcpy(bss_cfg->rates, rate_ie + 1, rate_ie->len);
3a5b8a16
AP
273 rate_len = rate_ie->len;
274 }
275
276 rate_ie = (void *)cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
277 params->beacon.tail,
278 params->beacon.tail_len);
279 if (rate_ie)
280 memcpy(bss_cfg->rates + rate_len, rate_ie + 1, rate_ie->len);
a3c2c4f6
AP
281
282 return;
283}
284
9b930eae
AP
285/* This function initializes some of mwifiex_uap_bss_param variables.
286 * This helps FW in ignoring invalid values. These values may or may not
287 * be get updated to valid ones at later stage.
288 */
289void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
290{
f752dcd5
AP
291 config->bcast_ssid_ctl = 0x7F;
292 config->radio_ctl = 0x7F;
293 config->dtim_period = 0x7F;
294 config->beacon_period = 0x7FFF;
295 config->auth_mode = 0x7F;
9b930eae
AP
296 config->rts_threshold = 0x7FFF;
297 config->frag_threshold = 0x7FFF;
298 config->retry_limit = 0x7F;
54428c57 299 config->qos_info = 0xFF;
9b930eae
AP
300}
301
5d66cb62
AP
302/* This function parses BSS related parameters from structure
303 * and prepares TLVs specific to WPA/WPA2 security.
304 * These TLVs are appended to command buffer.
305 */
306static void
307mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
308{
309 struct host_cmd_tlv_pwk_cipher *pwk_cipher;
310 struct host_cmd_tlv_gwk_cipher *gwk_cipher;
311 struct host_cmd_tlv_passphrase *passphrase;
312 struct host_cmd_tlv_akmp *tlv_akmp;
313 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
314 u16 cmd_size = *param_size;
315 u8 *tlv = *tlv_buf;
316
317 tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
6b21a69f
AK
318 tlv_akmp->header.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
319 tlv_akmp->header.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
320 sizeof(struct mwifiex_ie_types_header));
5d66cb62
AP
321 tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
322 tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
323 cmd_size += sizeof(struct host_cmd_tlv_akmp);
324 tlv += sizeof(struct host_cmd_tlv_akmp);
325
326 if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
327 pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
6b21a69f
AK
328 pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
329 pwk_cipher->header.len =
5d66cb62 330 cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
6b21a69f 331 sizeof(struct mwifiex_ie_types_header));
5d66cb62
AP
332 pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
333 pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
334 cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
335 tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
336 }
337
338 if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
339 pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
6b21a69f
AK
340 pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
341 pwk_cipher->header.len =
5d66cb62 342 cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
6b21a69f 343 sizeof(struct mwifiex_ie_types_header));
5d66cb62
AP
344 pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
345 pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
346 cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
347 tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
348 }
349
350 if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
351 gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
6b21a69f
AK
352 gwk_cipher->header.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
353 gwk_cipher->header.len =
5d66cb62 354 cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
6b21a69f 355 sizeof(struct mwifiex_ie_types_header));
5d66cb62
AP
356 gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
357 cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
358 tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
359 }
360
361 if (bss_cfg->wpa_cfg.length) {
362 passphrase = (struct host_cmd_tlv_passphrase *)tlv;
6b21a69f
AK
363 passphrase->header.type =
364 cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
365 passphrase->header.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
5d66cb62
AP
366 memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
367 bss_cfg->wpa_cfg.length);
6b21a69f 368 cmd_size += sizeof(struct mwifiex_ie_types_header) +
5d66cb62 369 bss_cfg->wpa_cfg.length;
6b21a69f
AK
370 tlv += sizeof(struct mwifiex_ie_types_header) +
371 bss_cfg->wpa_cfg.length;
5d66cb62
AP
372 }
373
374 *param_size = cmd_size;
375 *tlv_buf = tlv;
376
377 return;
378}
379
54428c57
AP
380/* This function parses WMM related parameters from cfg80211_ap_settings
381 * structure and updates bss_config structure.
382 */
383void
384mwifiex_set_wmm_params(struct mwifiex_private *priv,
385 struct mwifiex_uap_bss_param *bss_cfg,
386 struct cfg80211_ap_settings *params)
387{
388 const u8 *vendor_ie;
389 struct ieee_types_header *wmm_ie;
390 u8 wmm_oui[] = {0x00, 0x50, 0xf2, 0x02};
391
392 vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
393 WLAN_OUI_TYPE_MICROSOFT_WMM,
394 params->beacon.tail,
395 params->beacon.tail_len);
396 if (vendor_ie) {
397 wmm_ie = (struct ieee_types_header *)vendor_ie;
398 memcpy(&bss_cfg->wmm_info, wmm_ie + 1,
399 sizeof(bss_cfg->wmm_info));
400 priv->wmm_enabled = 1;
401 } else {
402 memset(&bss_cfg->wmm_info, 0, sizeof(bss_cfg->wmm_info));
403 memcpy(&bss_cfg->wmm_info.oui, wmm_oui, sizeof(wmm_oui));
404 bss_cfg->wmm_info.subtype = MWIFIEX_WMM_SUBTYPE;
405 bss_cfg->wmm_info.version = MWIFIEX_WMM_VERSION;
406 priv->wmm_enabled = 0;
407 }
408
409 bss_cfg->qos_info = 0x00;
410 return;
411}
96893538
AP
412/* This function parses BSS related parameters from structure
413 * and prepares TLVs specific to WEP encryption.
414 * These TLVs are appended to command buffer.
415 */
416static void
417mwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
418{
419 struct host_cmd_tlv_wep_key *wep_key;
420 u16 cmd_size = *param_size;
421 int i;
422 u8 *tlv = *tlv_buf;
423 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
424
425 for (i = 0; i < NUM_WEP_KEYS; i++) {
426 if (bss_cfg->wep_cfg[i].length &&
427 (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 ||
428 bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) {
429 wep_key = (struct host_cmd_tlv_wep_key *)tlv;
6b21a69f
AK
430 wep_key->header.type =
431 cpu_to_le16(TLV_TYPE_UAP_WEP_KEY);
432 wep_key->header.len =
96893538
AP
433 cpu_to_le16(bss_cfg->wep_cfg[i].length + 2);
434 wep_key->key_index = bss_cfg->wep_cfg[i].key_index;
435 wep_key->is_default = bss_cfg->wep_cfg[i].is_default;
436 memcpy(wep_key->key, bss_cfg->wep_cfg[i].key,
437 bss_cfg->wep_cfg[i].length);
6b21a69f 438 cmd_size += sizeof(struct mwifiex_ie_types_header) + 2 +
96893538 439 bss_cfg->wep_cfg[i].length;
6b21a69f 440 tlv += sizeof(struct mwifiex_ie_types_header) + 2 +
96893538
AP
441 bss_cfg->wep_cfg[i].length;
442 }
443 }
444
445 *param_size = cmd_size;
446 *tlv_buf = tlv;
447
448 return;
449}
450
e76268da
AP
451/* This function parses BSS related parameters from structure
452 * and prepares TLVs. These TLVs are appended to command buffer.
453*/
454static int
455mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
4db16a18 456{
12190c5d
AP
457 struct host_cmd_tlv_dtim_period *dtim_period;
458 struct host_cmd_tlv_beacon_period *beacon_period;
459 struct host_cmd_tlv_ssid *ssid;
7a1c9934 460 struct host_cmd_tlv_bcast_ssid *bcast_ssid;
4db16a18 461 struct host_cmd_tlv_channel_band *chan_band;
9b930eae
AP
462 struct host_cmd_tlv_frag_threshold *frag_threshold;
463 struct host_cmd_tlv_rts_threshold *rts_threshold;
464 struct host_cmd_tlv_retry_limit *retry_limit;
f752dcd5
AP
465 struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
466 struct host_cmd_tlv_auth_type *auth_type;
a3c2c4f6 467 struct host_cmd_tlv_rates *tlv_rates;
8b4509f6 468 struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer;
22281256 469 struct mwifiex_ie_types_htcap *htcap;
54428c57 470 struct mwifiex_ie_types_wmmcap *wmm_cap;
4db16a18 471 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
a3c2c4f6 472 int i;
e76268da 473 u16 cmd_size = *param_size;
4db16a18 474
12190c5d
AP
475 if (bss_cfg->ssid.ssid_len) {
476 ssid = (struct host_cmd_tlv_ssid *)tlv;
6b21a69f
AK
477 ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
478 ssid->header.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
12190c5d 479 memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
6b21a69f 480 cmd_size += sizeof(struct mwifiex_ie_types_header) +
12190c5d 481 bss_cfg->ssid.ssid_len;
6b21a69f
AK
482 tlv += sizeof(struct mwifiex_ie_types_header) +
483 bss_cfg->ssid.ssid_len;
7a1c9934
AP
484
485 bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
6b21a69f
AK
486 bcast_ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
487 bcast_ssid->header.len =
7a1c9934
AP
488 cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
489 bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
490 cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
491 tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
12190c5d 492 }
a3c2c4f6
AP
493 if (bss_cfg->rates[0]) {
494 tlv_rates = (struct host_cmd_tlv_rates *)tlv;
6b21a69f 495 tlv_rates->header.type = cpu_to_le16(TLV_TYPE_UAP_RATES);
a3c2c4f6
AP
496
497 for (i = 0; i < MWIFIEX_SUPPORTED_RATES && bss_cfg->rates[i];
498 i++)
499 tlv_rates->rates[i] = bss_cfg->rates[i];
500
6b21a69f 501 tlv_rates->header.len = cpu_to_le16(i);
a3c2c4f6
AP
502 cmd_size += sizeof(struct host_cmd_tlv_rates) + i;
503 tlv += sizeof(struct host_cmd_tlv_rates) + i;
504 }
505 if (bss_cfg->channel &&
506 ((bss_cfg->band_cfg == BAND_CONFIG_BG &&
507 bss_cfg->channel <= MAX_CHANNEL_BAND_BG) ||
508 (bss_cfg->band_cfg == BAND_CONFIG_A &&
509 bss_cfg->channel <= MAX_CHANNEL_BAND_A))) {
4db16a18 510 chan_band = (struct host_cmd_tlv_channel_band *)tlv;
6b21a69f
AK
511 chan_band->header.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
512 chan_band->header.len =
4db16a18 513 cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
6b21a69f 514 sizeof(struct mwifiex_ie_types_header));
4db16a18
AP
515 chan_band->band_config = bss_cfg->band_cfg;
516 chan_band->channel = bss_cfg->channel;
517 cmd_size += sizeof(struct host_cmd_tlv_channel_band);
518 tlv += sizeof(struct host_cmd_tlv_channel_band);
519 }
12190c5d
AP
520 if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
521 bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
522 beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
6b21a69f 523 beacon_period->header.type =
12190c5d 524 cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
6b21a69f 525 beacon_period->header.len =
12190c5d 526 cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
6b21a69f 527 sizeof(struct mwifiex_ie_types_header));
12190c5d
AP
528 beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
529 cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
530 tlv += sizeof(struct host_cmd_tlv_beacon_period);
531 }
532 if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
533 bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
534 dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
6b21a69f
AK
535 dtim_period->header.type =
536 cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
537 dtim_period->header.len =
12190c5d 538 cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
6b21a69f 539 sizeof(struct mwifiex_ie_types_header));
12190c5d
AP
540 dtim_period->period = bss_cfg->dtim_period;
541 cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
542 tlv += sizeof(struct host_cmd_tlv_dtim_period);
543 }
9b930eae
AP
544 if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
545 rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
6b21a69f 546 rts_threshold->header.type =
9b930eae 547 cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
6b21a69f 548 rts_threshold->header.len =
9b930eae 549 cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
6b21a69f 550 sizeof(struct mwifiex_ie_types_header));
9b930eae
AP
551 rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
552 cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
553 tlv += sizeof(struct host_cmd_tlv_frag_threshold);
554 }
555 if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
556 (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
557 frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
6b21a69f 558 frag_threshold->header.type =
9b930eae 559 cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
6b21a69f 560 frag_threshold->header.len =
9b930eae 561 cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
6b21a69f 562 sizeof(struct mwifiex_ie_types_header));
9b930eae
AP
563 frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
564 cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
565 tlv += sizeof(struct host_cmd_tlv_frag_threshold);
566 }
567 if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
568 retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
6b21a69f
AK
569 retry_limit->header.type =
570 cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
571 retry_limit->header.len =
9b930eae 572 cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
6b21a69f 573 sizeof(struct mwifiex_ie_types_header));
9b930eae
AP
574 retry_limit->limit = (u8)bss_cfg->retry_limit;
575 cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
576 tlv += sizeof(struct host_cmd_tlv_retry_limit);
577 }
f752dcd5
AP
578 if ((bss_cfg->protocol & PROTOCOL_WPA) ||
579 (bss_cfg->protocol & PROTOCOL_WPA2) ||
5d66cb62
AP
580 (bss_cfg->protocol & PROTOCOL_EAP))
581 mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
96893538
AP
582 else
583 mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size);
f752dcd5 584
f752dcd5
AP
585 if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
586 (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
587 auth_type = (struct host_cmd_tlv_auth_type *)tlv;
6b21a69f
AK
588 auth_type->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
589 auth_type->header.len =
f752dcd5 590 cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
6b21a69f 591 sizeof(struct mwifiex_ie_types_header));
f752dcd5
AP
592 auth_type->auth_type = (u8)bss_cfg->auth_mode;
593 cmd_size += sizeof(struct host_cmd_tlv_auth_type);
594 tlv += sizeof(struct host_cmd_tlv_auth_type);
595 }
596 if (bss_cfg->protocol) {
597 encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
6b21a69f 598 encrypt_protocol->header.type =
f752dcd5 599 cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
6b21a69f 600 encrypt_protocol->header.len =
f752dcd5 601 cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
6b21a69f 602 - sizeof(struct mwifiex_ie_types_header));
f752dcd5
AP
603 encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
604 cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
605 tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
606 }
4db16a18 607
22281256
AP
608 if (bss_cfg->ht_cap.cap_info) {
609 htcap = (struct mwifiex_ie_types_htcap *)tlv;
610 htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
611 htcap->header.len =
612 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
613 htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
614 htcap->ht_cap.ampdu_params_info =
615 bss_cfg->ht_cap.ampdu_params_info;
616 memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
617 sizeof(struct ieee80211_mcs_info));
618 htcap->ht_cap.extended_ht_cap_info =
619 bss_cfg->ht_cap.extended_ht_cap_info;
620 htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
621 htcap->ht_cap.antenna_selection_info =
622 bss_cfg->ht_cap.antenna_selection_info;
623 cmd_size += sizeof(struct mwifiex_ie_types_htcap);
624 tlv += sizeof(struct mwifiex_ie_types_htcap);
625 }
626
54428c57
AP
627 if (bss_cfg->wmm_info.qos_info != 0xFF) {
628 wmm_cap = (struct mwifiex_ie_types_wmmcap *)tlv;
629 wmm_cap->header.type = cpu_to_le16(WLAN_EID_VENDOR_SPECIFIC);
630 wmm_cap->header.len = cpu_to_le16(sizeof(wmm_cap->wmm_info));
631 memcpy(&wmm_cap->wmm_info, &bss_cfg->wmm_info,
632 sizeof(wmm_cap->wmm_info));
633 cmd_size += sizeof(struct mwifiex_ie_types_wmmcap);
634 tlv += sizeof(struct mwifiex_ie_types_wmmcap);
635 }
636
8b4509f6
KG
637 if (bss_cfg->sta_ao_timer) {
638 ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
6b21a69f
AK
639 ao_timer->header.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER);
640 ao_timer->header.len = cpu_to_le16(sizeof(*ao_timer) -
641 sizeof(struct mwifiex_ie_types_header));
8b4509f6
KG
642 ao_timer->sta_ao_timer = cpu_to_le32(bss_cfg->sta_ao_timer);
643 cmd_size += sizeof(*ao_timer);
644 tlv += sizeof(*ao_timer);
645 }
646
647 if (bss_cfg->ps_sta_ao_timer) {
648 ps_ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
6b21a69f
AK
649 ps_ao_timer->header.type =
650 cpu_to_le16(TLV_TYPE_UAP_PS_AO_TIMER);
651 ps_ao_timer->header.len = cpu_to_le16(sizeof(*ps_ao_timer) -
652 sizeof(struct mwifiex_ie_types_header));
8b4509f6
KG
653 ps_ao_timer->sta_ao_timer =
654 cpu_to_le32(bss_cfg->ps_sta_ao_timer);
655 cmd_size += sizeof(*ps_ao_timer);
656 tlv += sizeof(*ps_ao_timer);
657 }
658
e76268da
AP
659 *param_size = cmd_size;
660
661 return 0;
662}
663
ede98bfa
AP
664/* This function parses custom IEs from IE list and prepares command buffer */
665static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
666{
667 struct mwifiex_ie_list *ap_ie = cmd_buf;
6b21a69f 668 struct mwifiex_ie_types_header *tlv_ie = (void *)tlv;
ede98bfa
AP
669
670 if (!ap_ie || !ap_ie->len || !ap_ie->ie_list)
671 return -1;
672
6b21a69f
AK
673 *ie_size += le16_to_cpu(ap_ie->len) +
674 sizeof(struct mwifiex_ie_types_header);
ede98bfa
AP
675
676 tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
677 tlv_ie->len = ap_ie->len;
6b21a69f 678 tlv += sizeof(struct mwifiex_ie_types_header);
ede98bfa
AP
679
680 memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
681
682 return 0;
683}
684
e76268da
AP
685/* Parse AP config structure and prepare TLV based command structure
686 * to be sent to FW for uAP configuration
687 */
688static int
689mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
690 u32 type, void *cmd_buf)
691{
692 u8 *tlv;
ede98bfa 693 u16 cmd_size, param_size, ie_size;
e76268da
AP
694 struct host_cmd_ds_sys_config *sys_cfg;
695
696 cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
697 cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
698 sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
699 sys_cfg->action = cpu_to_le16(cmd_action);
700 tlv = sys_cfg->tlv;
701
702 switch (type) {
703 case UAP_BSS_PARAMS_I:
704 param_size = cmd_size;
705 if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
706 return -1;
707 cmd->size = cpu_to_le16(param_size);
708 break;
ede98bfa
AP
709 case UAP_CUSTOM_IE_I:
710 ie_size = cmd_size;
711 if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
712 return -1;
713 cmd->size = cpu_to_le16(ie_size);
714 break;
e76268da
AP
715 default:
716 return -1;
717 }
718
4db16a18
AP
719 return 0;
720}
721
0f9e9b8b
AP
722/* This function prepares AP specific deauth command with mac supplied in
723 * function parameter.
724 */
725static int mwifiex_cmd_uap_sta_deauth(struct mwifiex_private *priv,
726 struct host_cmd_ds_command *cmd, u8 *mac)
727{
728 struct host_cmd_ds_sta_deauth *sta_deauth = &cmd->params.sta_deauth;
729
730 cmd->command = cpu_to_le16(HostCmd_CMD_UAP_STA_DEAUTH);
731 memcpy(sta_deauth->mac, mac, ETH_ALEN);
732 sta_deauth->reason = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
733
734 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_sta_deauth) +
735 S_DS_GEN);
736 return 0;
737}
738
40d07030
AP
739/* This function prepares the AP specific commands before sending them
740 * to the firmware.
741 * This is a generic function which calls specific command preparation
742 * routines based upon the command number.
743 */
744int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
e76268da 745 u16 cmd_action, u32 type,
40d07030
AP
746 void *data_buf, void *cmd_buf)
747{
748 struct host_cmd_ds_command *cmd = cmd_buf;
749
750 switch (cmd_no) {
4db16a18 751 case HostCmd_CMD_UAP_SYS_CONFIG:
e76268da 752 if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
4db16a18
AP
753 return -1;
754 break;
40d07030
AP
755 case HostCmd_CMD_UAP_BSS_START:
756 case HostCmd_CMD_UAP_BSS_STOP:
ed5cfbe6 757 case HOST_CMD_APCMD_SYS_RESET:
40d07030
AP
758 cmd->command = cpu_to_le16(cmd_no);
759 cmd->size = cpu_to_le16(S_DS_GEN);
760 break;
0f9e9b8b
AP
761 case HostCmd_CMD_UAP_STA_DEAUTH:
762 if (mwifiex_cmd_uap_sta_deauth(priv, cmd, data_buf))
763 return -1;
764 break;
85afb186
AP
765 case HostCmd_CMD_CHAN_REPORT_REQUEST:
766 if (mwifiex_cmd_issue_chan_report_request(priv, cmd_buf,
767 data_buf))
768 return -1;
769 break;
40d07030 770 default:
acebe8c1
ZL
771 mwifiex_dbg(priv->adapter, ERROR,
772 "PREP_CMD: unknown cmd %#x\n", cmd_no);
40d07030
AP
773 return -1;
774 }
775
776 return 0;
777}
b654ca18 778
7ee38bf4
XH
779void mwifiex_uap_set_channel(struct mwifiex_private *priv,
780 struct mwifiex_uap_bss_param *bss_cfg,
b654ca18
AP
781 struct cfg80211_chan_def chandef)
782{
783 u8 config_bands = 0;
784
7ee38bf4
XH
785 priv->bss_chandef = chandef;
786
b654ca18
AP
787 bss_cfg->channel = ieee80211_frequency_to_channel(
788 chandef.chan->center_freq);
789
790 /* Set appropriate bands */
791 if (chandef.chan->band == IEEE80211_BAND_2GHZ) {
792 bss_cfg->band_cfg = BAND_CONFIG_BG;
793 config_bands = BAND_B | BAND_G;
794
795 if (chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
796 config_bands |= BAND_GN;
797 } else {
798 bss_cfg->band_cfg = BAND_CONFIG_A;
799 config_bands = BAND_A;
800
801 if (chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
802 config_bands |= BAND_AN;
803
804 if (chandef.width > NL80211_CHAN_WIDTH_40)
805 config_bands |= BAND_AAC;
806 }
807}
808
809int mwifiex_config_start_uap(struct mwifiex_private *priv,
810 struct mwifiex_uap_bss_param *bss_cfg)
811{
88af6f05
AP
812 enum state_11d_t state_11d;
813
b654ca18 814 if (mwifiex_del_mgmt_ies(priv))
acebe8c1
ZL
815 mwifiex_dbg(priv->adapter, ERROR,
816 "Failed to delete mgmt IEs!\n");
b654ca18
AP
817
818 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
819 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
ed5cfbe6
AP
820 mwifiex_dbg(priv->adapter, ERROR, "Failed to stop the BSS\n");
821 return -1;
822 }
823
824 if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
825 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
826 mwifiex_dbg(priv->adapter, ERROR, "Failed to reset BSS\n");
b654ca18
AP
827 return -1;
828 }
829
830 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
831 HostCmd_ACT_GEN_SET,
832 UAP_BSS_PARAMS_I, bss_cfg, false)) {
acebe8c1
ZL
833 mwifiex_dbg(priv->adapter, ERROR,
834 "Failed to set the SSID\n");
b654ca18
AP
835 return -1;
836 }
837
88af6f05
AP
838 /* Send cmd to FW to enable 11D function */
839 state_11d = ENABLE_11D;
840 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
841 HostCmd_ACT_GEN_SET, DOT11D_I,
842 &state_11d, true)) {
843 mwifiex_dbg(priv->adapter, ERROR,
844 "11D: failed to enable 11D\n");
845 return -1;
846 }
847
b654ca18
AP
848 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_START,
849 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
acebe8c1
ZL
850 mwifiex_dbg(priv->adapter, ERROR,
851 "Failed to start the BSS\n");
b654ca18
AP
852 return -1;
853 }
854
855 if (priv->sec_info.wep_enabled)
856 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
857 else
858 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
859
860 if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
861 HostCmd_ACT_GEN_SET, 0,
862 &priv->curr_pkt_filter, true))
863 return -1;
864
865 return 0;
866}
This page took 0.260206 seconds and 5 git commands to generate.