mwifiex: parse rate info for AP
[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 *
4 * Copyright (C) 2012, 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 "main.h"
21
f752dcd5
AP
22/* This function parses security related parameters from cfg80211_ap_settings
23 * and sets into FW understandable bss_config structure.
24 */
25int mwifiex_set_secure_params(struct mwifiex_private *priv,
26 struct mwifiex_uap_bss_param *bss_config,
27 struct cfg80211_ap_settings *params) {
28 int i;
96893538 29 struct mwifiex_wep_key wep_key;
f752dcd5 30
6ddcd464
AP
31 if (!params->privacy) {
32 bss_config->protocol = PROTOCOL_NO_SECURITY;
33 bss_config->key_mgmt = KEY_MGMT_NONE;
34 bss_config->wpa_cfg.length = 0;
35 priv->sec_info.wep_enabled = 0;
36 priv->sec_info.wpa_enabled = 0;
37 priv->sec_info.wpa2_enabled = 0;
38
39 return 0;
40 }
41
f752dcd5
AP
42 switch (params->auth_type) {
43 case NL80211_AUTHTYPE_OPEN_SYSTEM:
44 bss_config->auth_mode = WLAN_AUTH_OPEN;
45 break;
46 case NL80211_AUTHTYPE_SHARED_KEY:
47 bss_config->auth_mode = WLAN_AUTH_SHARED_KEY;
48 break;
49 case NL80211_AUTHTYPE_NETWORK_EAP:
50 bss_config->auth_mode = WLAN_AUTH_LEAP;
51 break;
52 default:
53 bss_config->auth_mode = MWIFIEX_AUTH_MODE_AUTO;
54 break;
55 }
56
57 bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
58
59 for (i = 0; i < params->crypto.n_akm_suites; i++) {
60 switch (params->crypto.akm_suites[i]) {
61 case WLAN_AKM_SUITE_8021X:
62 if (params->crypto.wpa_versions &
63 NL80211_WPA_VERSION_1) {
64 bss_config->protocol = PROTOCOL_WPA;
65 bss_config->key_mgmt = KEY_MGMT_EAP;
66 }
67 if (params->crypto.wpa_versions &
68 NL80211_WPA_VERSION_2) {
0fd66be4 69 bss_config->protocol |= PROTOCOL_WPA2;
f752dcd5
AP
70 bss_config->key_mgmt = KEY_MGMT_EAP;
71 }
72 break;
73 case WLAN_AKM_SUITE_PSK:
74 if (params->crypto.wpa_versions &
75 NL80211_WPA_VERSION_1) {
76 bss_config->protocol = PROTOCOL_WPA;
77 bss_config->key_mgmt = KEY_MGMT_PSK;
78 }
79 if (params->crypto.wpa_versions &
80 NL80211_WPA_VERSION_2) {
0fd66be4 81 bss_config->protocol |= PROTOCOL_WPA2;
f752dcd5
AP
82 bss_config->key_mgmt = KEY_MGMT_PSK;
83 }
84 break;
85 default:
86 break;
87 }
88 }
89 for (i = 0; i < params->crypto.n_ciphers_pairwise; i++) {
90 switch (params->crypto.ciphers_pairwise[i]) {
91 case WLAN_CIPHER_SUITE_WEP40:
92 case WLAN_CIPHER_SUITE_WEP104:
93 break;
94 case WLAN_CIPHER_SUITE_TKIP:
0fd66be4
AP
95 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
96 bss_config->wpa_cfg.pairwise_cipher_wpa |=
97 CIPHER_TKIP;
98 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
99 bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
100 CIPHER_TKIP;
f752dcd5
AP
101 break;
102 case WLAN_CIPHER_SUITE_CCMP:
0fd66be4
AP
103 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
104 bss_config->wpa_cfg.pairwise_cipher_wpa |=
105 CIPHER_AES_CCMP;
106 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
107 bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
f752dcd5
AP
108 CIPHER_AES_CCMP;
109 default:
110 break;
111 }
112 }
113
114 switch (params->crypto.cipher_group) {
115 case WLAN_CIPHER_SUITE_WEP40:
116 case WLAN_CIPHER_SUITE_WEP104:
96893538
AP
117 if (priv->sec_info.wep_enabled) {
118 bss_config->protocol = PROTOCOL_STATIC_WEP;
119 bss_config->key_mgmt = KEY_MGMT_NONE;
120 bss_config->wpa_cfg.length = 0;
121
122 for (i = 0; i < NUM_WEP_KEYS; i++) {
123 wep_key = priv->wep_key[i];
124 bss_config->wep_cfg[i].key_index = i;
125
126 if (priv->wep_key_curr_index == i)
127 bss_config->wep_cfg[i].is_default = 1;
128 else
129 bss_config->wep_cfg[i].is_default = 0;
130
131 bss_config->wep_cfg[i].length =
132 wep_key.key_length;
133 memcpy(&bss_config->wep_cfg[i].key,
134 &wep_key.key_material,
135 wep_key.key_length);
136 }
137 }
f752dcd5
AP
138 break;
139 case WLAN_CIPHER_SUITE_TKIP:
140 bss_config->wpa_cfg.group_cipher = CIPHER_TKIP;
141 break;
142 case WLAN_CIPHER_SUITE_CCMP:
143 bss_config->wpa_cfg.group_cipher = CIPHER_AES_CCMP;
144 break;
145 default:
146 break;
147 }
148
149 return 0;
150}
151
22281256
AP
152/* This function updates 11n related parameters from IE and sets them into
153 * bss_config structure.
154 */
155void
156mwifiex_set_ht_params(struct mwifiex_private *priv,
157 struct mwifiex_uap_bss_param *bss_cfg,
158 struct cfg80211_ap_settings *params)
159{
160 const u8 *ht_ie;
161
162 if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
163 return;
164
165 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
166 params->beacon.tail_len);
167 if (ht_ie) {
168 memcpy(&bss_cfg->ht_cap, ht_ie + 2,
169 sizeof(struct ieee80211_ht_cap));
c8258913 170 priv->ap_11n_enabled = 1;
22281256
AP
171 } else {
172 memset(&bss_cfg->ht_cap , 0, sizeof(struct ieee80211_ht_cap));
173 bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP);
174 bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU;
175 }
176
177 return;
178}
179
a3c2c4f6
AP
180/* This function finds supported rates IE from beacon parameter and sets
181 * these rates into bss_config structure.
182 */
183void
184mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
185 struct cfg80211_ap_settings *params)
186{
187 struct ieee_types_header *rate_ie;
188 int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
189 const u8 *var_pos = params->beacon.head + var_offset;
190 int len = params->beacon.head_len - var_offset;
191
192 rate_ie = (void *)cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
193 if (rate_ie)
194 memcpy(bss_cfg->rates, rate_ie + 1, rate_ie->len);
195
196 return;
197}
198
9b930eae
AP
199/* This function initializes some of mwifiex_uap_bss_param variables.
200 * This helps FW in ignoring invalid values. These values may or may not
201 * be get updated to valid ones at later stage.
202 */
203void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
204{
f752dcd5
AP
205 config->bcast_ssid_ctl = 0x7F;
206 config->radio_ctl = 0x7F;
207 config->dtim_period = 0x7F;
208 config->beacon_period = 0x7FFF;
209 config->auth_mode = 0x7F;
9b930eae
AP
210 config->rts_threshold = 0x7FFF;
211 config->frag_threshold = 0x7FFF;
212 config->retry_limit = 0x7F;
213}
214
5d66cb62
AP
215/* This function parses BSS related parameters from structure
216 * and prepares TLVs specific to WPA/WPA2 security.
217 * These TLVs are appended to command buffer.
218 */
219static void
220mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
221{
222 struct host_cmd_tlv_pwk_cipher *pwk_cipher;
223 struct host_cmd_tlv_gwk_cipher *gwk_cipher;
224 struct host_cmd_tlv_passphrase *passphrase;
225 struct host_cmd_tlv_akmp *tlv_akmp;
226 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
227 u16 cmd_size = *param_size;
228 u8 *tlv = *tlv_buf;
229
230 tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
231 tlv_akmp->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
232 tlv_akmp->tlv.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
233 sizeof(struct host_cmd_tlv));
234 tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
235 tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
236 cmd_size += sizeof(struct host_cmd_tlv_akmp);
237 tlv += sizeof(struct host_cmd_tlv_akmp);
238
239 if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
240 pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
241 pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
242 pwk_cipher->tlv.len =
243 cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
244 sizeof(struct host_cmd_tlv));
245 pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
246 pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
247 cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
248 tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
249 }
250
251 if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
252 pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
253 pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
254 pwk_cipher->tlv.len =
255 cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
256 sizeof(struct host_cmd_tlv));
257 pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
258 pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
259 cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
260 tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
261 }
262
263 if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
264 gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
265 gwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
266 gwk_cipher->tlv.len =
267 cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
268 sizeof(struct host_cmd_tlv));
269 gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
270 cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
271 tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
272 }
273
274 if (bss_cfg->wpa_cfg.length) {
275 passphrase = (struct host_cmd_tlv_passphrase *)tlv;
276 passphrase->tlv.type = cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
277 passphrase->tlv.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
278 memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
279 bss_cfg->wpa_cfg.length);
280 cmd_size += sizeof(struct host_cmd_tlv) +
281 bss_cfg->wpa_cfg.length;
282 tlv += sizeof(struct host_cmd_tlv) + bss_cfg->wpa_cfg.length;
283 }
284
285 *param_size = cmd_size;
286 *tlv_buf = tlv;
287
288 return;
289}
290
96893538
AP
291/* This function parses BSS related parameters from structure
292 * and prepares TLVs specific to WEP encryption.
293 * These TLVs are appended to command buffer.
294 */
295static void
296mwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
297{
298 struct host_cmd_tlv_wep_key *wep_key;
299 u16 cmd_size = *param_size;
300 int i;
301 u8 *tlv = *tlv_buf;
302 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
303
304 for (i = 0; i < NUM_WEP_KEYS; i++) {
305 if (bss_cfg->wep_cfg[i].length &&
306 (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 ||
307 bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) {
308 wep_key = (struct host_cmd_tlv_wep_key *)tlv;
309 wep_key->tlv.type = cpu_to_le16(TLV_TYPE_UAP_WEP_KEY);
310 wep_key->tlv.len =
311 cpu_to_le16(bss_cfg->wep_cfg[i].length + 2);
312 wep_key->key_index = bss_cfg->wep_cfg[i].key_index;
313 wep_key->is_default = bss_cfg->wep_cfg[i].is_default;
314 memcpy(wep_key->key, bss_cfg->wep_cfg[i].key,
315 bss_cfg->wep_cfg[i].length);
316 cmd_size += sizeof(struct host_cmd_tlv) + 2 +
317 bss_cfg->wep_cfg[i].length;
318 tlv += sizeof(struct host_cmd_tlv) + 2 +
319 bss_cfg->wep_cfg[i].length;
320 }
321 }
322
323 *param_size = cmd_size;
324 *tlv_buf = tlv;
325
326 return;
327}
328
e76268da
AP
329/* This function parses BSS related parameters from structure
330 * and prepares TLVs. These TLVs are appended to command buffer.
331*/
332static int
333mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
4db16a18 334{
12190c5d
AP
335 struct host_cmd_tlv_dtim_period *dtim_period;
336 struct host_cmd_tlv_beacon_period *beacon_period;
337 struct host_cmd_tlv_ssid *ssid;
7a1c9934 338 struct host_cmd_tlv_bcast_ssid *bcast_ssid;
4db16a18 339 struct host_cmd_tlv_channel_band *chan_band;
9b930eae
AP
340 struct host_cmd_tlv_frag_threshold *frag_threshold;
341 struct host_cmd_tlv_rts_threshold *rts_threshold;
342 struct host_cmd_tlv_retry_limit *retry_limit;
f752dcd5
AP
343 struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
344 struct host_cmd_tlv_auth_type *auth_type;
a3c2c4f6 345 struct host_cmd_tlv_rates *tlv_rates;
22281256 346 struct mwifiex_ie_types_htcap *htcap;
4db16a18 347 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
a3c2c4f6 348 int i;
e76268da 349 u16 cmd_size = *param_size;
4db16a18 350
12190c5d
AP
351 if (bss_cfg->ssid.ssid_len) {
352 ssid = (struct host_cmd_tlv_ssid *)tlv;
353 ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
354 ssid->tlv.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
355 memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
356 cmd_size += sizeof(struct host_cmd_tlv) +
357 bss_cfg->ssid.ssid_len;
358 tlv += sizeof(struct host_cmd_tlv) + bss_cfg->ssid.ssid_len;
7a1c9934
AP
359
360 bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
361 bcast_ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
362 bcast_ssid->tlv.len =
363 cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
364 bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
365 cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
366 tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
12190c5d 367 }
a3c2c4f6
AP
368 if (bss_cfg->rates[0]) {
369 tlv_rates = (struct host_cmd_tlv_rates *)tlv;
370 tlv_rates->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RATES);
371
372 for (i = 0; i < MWIFIEX_SUPPORTED_RATES && bss_cfg->rates[i];
373 i++)
374 tlv_rates->rates[i] = bss_cfg->rates[i];
375
376 tlv_rates->tlv.len = cpu_to_le16(i);
377 cmd_size += sizeof(struct host_cmd_tlv_rates) + i;
378 tlv += sizeof(struct host_cmd_tlv_rates) + i;
379 }
380 if (bss_cfg->channel &&
381 ((bss_cfg->band_cfg == BAND_CONFIG_BG &&
382 bss_cfg->channel <= MAX_CHANNEL_BAND_BG) ||
383 (bss_cfg->band_cfg == BAND_CONFIG_A &&
384 bss_cfg->channel <= MAX_CHANNEL_BAND_A))) {
4db16a18
AP
385 chan_band = (struct host_cmd_tlv_channel_band *)tlv;
386 chan_band->tlv.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
387 chan_band->tlv.len =
388 cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
389 sizeof(struct host_cmd_tlv));
390 chan_band->band_config = bss_cfg->band_cfg;
391 chan_band->channel = bss_cfg->channel;
392 cmd_size += sizeof(struct host_cmd_tlv_channel_band);
393 tlv += sizeof(struct host_cmd_tlv_channel_band);
394 }
12190c5d
AP
395 if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
396 bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
397 beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
398 beacon_period->tlv.type =
399 cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
400 beacon_period->tlv.len =
401 cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
402 sizeof(struct host_cmd_tlv));
403 beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
404 cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
405 tlv += sizeof(struct host_cmd_tlv_beacon_period);
406 }
407 if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
408 bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
409 dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
410 dtim_period->tlv.type = cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
411 dtim_period->tlv.len =
412 cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
413 sizeof(struct host_cmd_tlv));
414 dtim_period->period = bss_cfg->dtim_period;
415 cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
416 tlv += sizeof(struct host_cmd_tlv_dtim_period);
417 }
9b930eae
AP
418 if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
419 rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
420 rts_threshold->tlv.type =
421 cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
422 rts_threshold->tlv.len =
423 cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
424 sizeof(struct host_cmd_tlv));
425 rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
426 cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
427 tlv += sizeof(struct host_cmd_tlv_frag_threshold);
428 }
429 if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
430 (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
431 frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
432 frag_threshold->tlv.type =
433 cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
434 frag_threshold->tlv.len =
435 cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
436 sizeof(struct host_cmd_tlv));
437 frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
438 cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
439 tlv += sizeof(struct host_cmd_tlv_frag_threshold);
440 }
441 if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
442 retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
443 retry_limit->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
444 retry_limit->tlv.len =
445 cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
446 sizeof(struct host_cmd_tlv));
447 retry_limit->limit = (u8)bss_cfg->retry_limit;
448 cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
449 tlv += sizeof(struct host_cmd_tlv_retry_limit);
450 }
f752dcd5
AP
451 if ((bss_cfg->protocol & PROTOCOL_WPA) ||
452 (bss_cfg->protocol & PROTOCOL_WPA2) ||
5d66cb62
AP
453 (bss_cfg->protocol & PROTOCOL_EAP))
454 mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
96893538
AP
455 else
456 mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size);
f752dcd5 457
f752dcd5
AP
458 if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
459 (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
460 auth_type = (struct host_cmd_tlv_auth_type *)tlv;
461 auth_type->tlv.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
462 auth_type->tlv.len =
463 cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
464 sizeof(struct host_cmd_tlv));
465 auth_type->auth_type = (u8)bss_cfg->auth_mode;
466 cmd_size += sizeof(struct host_cmd_tlv_auth_type);
467 tlv += sizeof(struct host_cmd_tlv_auth_type);
468 }
469 if (bss_cfg->protocol) {
470 encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
471 encrypt_protocol->tlv.type =
472 cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
473 encrypt_protocol->tlv.len =
474 cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
475 - sizeof(struct host_cmd_tlv));
476 encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
477 cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
478 tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
479 }
4db16a18 480
22281256
AP
481 if (bss_cfg->ht_cap.cap_info) {
482 htcap = (struct mwifiex_ie_types_htcap *)tlv;
483 htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
484 htcap->header.len =
485 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
486 htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
487 htcap->ht_cap.ampdu_params_info =
488 bss_cfg->ht_cap.ampdu_params_info;
489 memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
490 sizeof(struct ieee80211_mcs_info));
491 htcap->ht_cap.extended_ht_cap_info =
492 bss_cfg->ht_cap.extended_ht_cap_info;
493 htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
494 htcap->ht_cap.antenna_selection_info =
495 bss_cfg->ht_cap.antenna_selection_info;
496 cmd_size += sizeof(struct mwifiex_ie_types_htcap);
497 tlv += sizeof(struct mwifiex_ie_types_htcap);
498 }
499
e76268da
AP
500 *param_size = cmd_size;
501
502 return 0;
503}
504
ede98bfa
AP
505/* This function parses custom IEs from IE list and prepares command buffer */
506static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
507{
508 struct mwifiex_ie_list *ap_ie = cmd_buf;
509 struct host_cmd_tlv *tlv_ie = (struct host_cmd_tlv *)tlv;
510
511 if (!ap_ie || !ap_ie->len || !ap_ie->ie_list)
512 return -1;
513
514 *ie_size += le16_to_cpu(ap_ie->len) + sizeof(struct host_cmd_tlv);
515
516 tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
517 tlv_ie->len = ap_ie->len;
518 tlv += sizeof(struct host_cmd_tlv);
519
520 memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
521
522 return 0;
523}
524
e76268da
AP
525/* Parse AP config structure and prepare TLV based command structure
526 * to be sent to FW for uAP configuration
527 */
528static int
529mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
530 u32 type, void *cmd_buf)
531{
532 u8 *tlv;
ede98bfa 533 u16 cmd_size, param_size, ie_size;
e76268da
AP
534 struct host_cmd_ds_sys_config *sys_cfg;
535
536 cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
537 cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
538 sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
539 sys_cfg->action = cpu_to_le16(cmd_action);
540 tlv = sys_cfg->tlv;
541
542 switch (type) {
543 case UAP_BSS_PARAMS_I:
544 param_size = cmd_size;
545 if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
546 return -1;
547 cmd->size = cpu_to_le16(param_size);
548 break;
ede98bfa
AP
549 case UAP_CUSTOM_IE_I:
550 ie_size = cmd_size;
551 if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
552 return -1;
553 cmd->size = cpu_to_le16(ie_size);
554 break;
e76268da
AP
555 default:
556 return -1;
557 }
558
4db16a18
AP
559 return 0;
560}
561
40d07030
AP
562/* This function prepares the AP specific commands before sending them
563 * to the firmware.
564 * This is a generic function which calls specific command preparation
565 * routines based upon the command number.
566 */
567int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
e76268da 568 u16 cmd_action, u32 type,
40d07030
AP
569 void *data_buf, void *cmd_buf)
570{
571 struct host_cmd_ds_command *cmd = cmd_buf;
572
573 switch (cmd_no) {
4db16a18 574 case HostCmd_CMD_UAP_SYS_CONFIG:
e76268da 575 if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
4db16a18
AP
576 return -1;
577 break;
40d07030
AP
578 case HostCmd_CMD_UAP_BSS_START:
579 case HostCmd_CMD_UAP_BSS_STOP:
580 cmd->command = cpu_to_le16(cmd_no);
581 cmd->size = cpu_to_le16(S_DS_GEN);
582 break;
583 default:
584 dev_err(priv->adapter->dev,
585 "PREP_CMD: unknown cmd %#x\n", cmd_no);
586 return -1;
587 }
588
589 return 0;
590}
This page took 0.102305 seconds and 5 git commands to generate.