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