]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/wireless/mwifiex/uap_cmd.c
Merge tag 'nfs-for-3.8-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
[karo-tx-linux.git] / drivers / net / wireless / mwifiex / uap_cmd.c
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
22 /* This function parses security related parameters from cfg80211_ap_settings
23  * and sets into FW understandable bss_config structure.
24  */
25 int 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;
29         struct mwifiex_wep_key wep_key;
30
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
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                         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;
101                         break;
102                 case WLAN_CIPHER_SUITE_CCMP:
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 |=
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:
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                 }
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
152 /* This function updates 11n related parameters from IE and sets them into
153  * bss_config structure.
154  */
155 void
156 mwifiex_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));
170                 priv->ap_11n_enabled = 1;
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
180 /* This function finds supported rates IE from beacon parameter and sets
181  * these rates into bss_config structure.
182  */
183 void
184 mwifiex_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         u8 rate_len = 0;
192
193         rate_ie = (void *)cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
194         if (rate_ie) {
195                 memcpy(bss_cfg->rates, rate_ie + 1, rate_ie->len);
196                 rate_len = rate_ie->len;
197         }
198
199         rate_ie = (void *)cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
200                                            params->beacon.tail,
201                                            params->beacon.tail_len);
202         if (rate_ie)
203                 memcpy(bss_cfg->rates + rate_len, rate_ie + 1, rate_ie->len);
204
205         return;
206 }
207
208 /* This function initializes some of mwifiex_uap_bss_param variables.
209  * This helps FW in ignoring invalid values. These values may or may not
210  * be get updated to valid ones at later stage.
211  */
212 void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
213 {
214         config->bcast_ssid_ctl = 0x7F;
215         config->radio_ctl = 0x7F;
216         config->dtim_period = 0x7F;
217         config->beacon_period = 0x7FFF;
218         config->auth_mode = 0x7F;
219         config->rts_threshold = 0x7FFF;
220         config->frag_threshold = 0x7FFF;
221         config->retry_limit = 0x7F;
222 }
223
224 /* This function parses BSS related parameters from structure
225  * and prepares TLVs specific to WPA/WPA2 security.
226  * These TLVs are appended to command buffer.
227  */
228 static void
229 mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
230 {
231         struct host_cmd_tlv_pwk_cipher *pwk_cipher;
232         struct host_cmd_tlv_gwk_cipher *gwk_cipher;
233         struct host_cmd_tlv_passphrase *passphrase;
234         struct host_cmd_tlv_akmp *tlv_akmp;
235         struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
236         u16 cmd_size = *param_size;
237         u8 *tlv = *tlv_buf;
238
239         tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
240         tlv_akmp->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
241         tlv_akmp->tlv.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
242                                         sizeof(struct host_cmd_tlv));
243         tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
244         tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
245         cmd_size += sizeof(struct host_cmd_tlv_akmp);
246         tlv += sizeof(struct host_cmd_tlv_akmp);
247
248         if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
249                 pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
250                 pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
251                 pwk_cipher->tlv.len =
252                         cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
253                                     sizeof(struct host_cmd_tlv));
254                 pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
255                 pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
256                 cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
257                 tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
258         }
259
260         if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
261                 pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
262                 pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
263                 pwk_cipher->tlv.len =
264                         cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
265                                     sizeof(struct host_cmd_tlv));
266                 pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
267                 pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
268                 cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
269                 tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
270         }
271
272         if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
273                 gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
274                 gwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
275                 gwk_cipher->tlv.len =
276                         cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
277                                     sizeof(struct host_cmd_tlv));
278                 gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
279                 cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
280                 tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
281         }
282
283         if (bss_cfg->wpa_cfg.length) {
284                 passphrase = (struct host_cmd_tlv_passphrase *)tlv;
285                 passphrase->tlv.type = cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
286                 passphrase->tlv.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
287                 memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
288                        bss_cfg->wpa_cfg.length);
289                 cmd_size += sizeof(struct host_cmd_tlv) +
290                             bss_cfg->wpa_cfg.length;
291                 tlv += sizeof(struct host_cmd_tlv) + bss_cfg->wpa_cfg.length;
292         }
293
294         *param_size = cmd_size;
295         *tlv_buf = tlv;
296
297         return;
298 }
299
300 /* This function parses BSS related parameters from structure
301  * and prepares TLVs specific to WEP encryption.
302  * These TLVs are appended to command buffer.
303  */
304 static void
305 mwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
306 {
307         struct host_cmd_tlv_wep_key *wep_key;
308         u16 cmd_size = *param_size;
309         int i;
310         u8 *tlv = *tlv_buf;
311         struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
312
313         for (i = 0; i < NUM_WEP_KEYS; i++) {
314                 if (bss_cfg->wep_cfg[i].length &&
315                     (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 ||
316                      bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) {
317                         wep_key = (struct host_cmd_tlv_wep_key *)tlv;
318                         wep_key->tlv.type = cpu_to_le16(TLV_TYPE_UAP_WEP_KEY);
319                         wep_key->tlv.len =
320                                 cpu_to_le16(bss_cfg->wep_cfg[i].length + 2);
321                         wep_key->key_index = bss_cfg->wep_cfg[i].key_index;
322                         wep_key->is_default = bss_cfg->wep_cfg[i].is_default;
323                         memcpy(wep_key->key, bss_cfg->wep_cfg[i].key,
324                                bss_cfg->wep_cfg[i].length);
325                         cmd_size += sizeof(struct host_cmd_tlv) + 2 +
326                                     bss_cfg->wep_cfg[i].length;
327                         tlv += sizeof(struct host_cmd_tlv) + 2 +
328                                     bss_cfg->wep_cfg[i].length;
329                 }
330         }
331
332         *param_size = cmd_size;
333         *tlv_buf = tlv;
334
335         return;
336 }
337
338 /* This function parses BSS related parameters from structure
339  * and prepares TLVs. These TLVs are appended to command buffer.
340 */
341 static int
342 mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
343 {
344         struct host_cmd_tlv_dtim_period *dtim_period;
345         struct host_cmd_tlv_beacon_period *beacon_period;
346         struct host_cmd_tlv_ssid *ssid;
347         struct host_cmd_tlv_bcast_ssid *bcast_ssid;
348         struct host_cmd_tlv_channel_band *chan_band;
349         struct host_cmd_tlv_frag_threshold *frag_threshold;
350         struct host_cmd_tlv_rts_threshold *rts_threshold;
351         struct host_cmd_tlv_retry_limit *retry_limit;
352         struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
353         struct host_cmd_tlv_auth_type *auth_type;
354         struct host_cmd_tlv_rates *tlv_rates;
355         struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer;
356         struct mwifiex_ie_types_htcap *htcap;
357         struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
358         int i;
359         u16 cmd_size = *param_size;
360
361         if (bss_cfg->ssid.ssid_len) {
362                 ssid = (struct host_cmd_tlv_ssid *)tlv;
363                 ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
364                 ssid->tlv.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
365                 memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
366                 cmd_size += sizeof(struct host_cmd_tlv) +
367                             bss_cfg->ssid.ssid_len;
368                 tlv += sizeof(struct host_cmd_tlv) + bss_cfg->ssid.ssid_len;
369
370                 bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
371                 bcast_ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
372                 bcast_ssid->tlv.len =
373                                 cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
374                 bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
375                 cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
376                 tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
377         }
378         if (bss_cfg->rates[0]) {
379                 tlv_rates = (struct host_cmd_tlv_rates *)tlv;
380                 tlv_rates->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RATES);
381
382                 for (i = 0; i < MWIFIEX_SUPPORTED_RATES && bss_cfg->rates[i];
383                      i++)
384                         tlv_rates->rates[i] = bss_cfg->rates[i];
385
386                 tlv_rates->tlv.len = cpu_to_le16(i);
387                 cmd_size += sizeof(struct host_cmd_tlv_rates) + i;
388                 tlv += sizeof(struct host_cmd_tlv_rates) + i;
389         }
390         if (bss_cfg->channel &&
391             ((bss_cfg->band_cfg == BAND_CONFIG_BG &&
392               bss_cfg->channel <= MAX_CHANNEL_BAND_BG) ||
393             (bss_cfg->band_cfg == BAND_CONFIG_A &&
394              bss_cfg->channel <= MAX_CHANNEL_BAND_A))) {
395                 chan_band = (struct host_cmd_tlv_channel_band *)tlv;
396                 chan_band->tlv.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
397                 chan_band->tlv.len =
398                         cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
399                                     sizeof(struct host_cmd_tlv));
400                 chan_band->band_config = bss_cfg->band_cfg;
401                 chan_band->channel = bss_cfg->channel;
402                 cmd_size += sizeof(struct host_cmd_tlv_channel_band);
403                 tlv += sizeof(struct host_cmd_tlv_channel_band);
404         }
405         if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
406             bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
407                 beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
408                 beacon_period->tlv.type =
409                                         cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
410                 beacon_period->tlv.len =
411                         cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
412                                     sizeof(struct host_cmd_tlv));
413                 beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
414                 cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
415                 tlv += sizeof(struct host_cmd_tlv_beacon_period);
416         }
417         if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
418             bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
419                 dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
420                 dtim_period->tlv.type = cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
421                 dtim_period->tlv.len =
422                         cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
423                                     sizeof(struct host_cmd_tlv));
424                 dtim_period->period = bss_cfg->dtim_period;
425                 cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
426                 tlv += sizeof(struct host_cmd_tlv_dtim_period);
427         }
428         if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
429                 rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
430                 rts_threshold->tlv.type =
431                                         cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
432                 rts_threshold->tlv.len =
433                         cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
434                                     sizeof(struct host_cmd_tlv));
435                 rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
436                 cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
437                 tlv += sizeof(struct host_cmd_tlv_frag_threshold);
438         }
439         if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
440             (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
441                 frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
442                 frag_threshold->tlv.type =
443                                 cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
444                 frag_threshold->tlv.len =
445                         cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
446                                     sizeof(struct host_cmd_tlv));
447                 frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
448                 cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
449                 tlv += sizeof(struct host_cmd_tlv_frag_threshold);
450         }
451         if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
452                 retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
453                 retry_limit->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
454                 retry_limit->tlv.len =
455                         cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
456                                     sizeof(struct host_cmd_tlv));
457                 retry_limit->limit = (u8)bss_cfg->retry_limit;
458                 cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
459                 tlv += sizeof(struct host_cmd_tlv_retry_limit);
460         }
461         if ((bss_cfg->protocol & PROTOCOL_WPA) ||
462             (bss_cfg->protocol & PROTOCOL_WPA2) ||
463             (bss_cfg->protocol & PROTOCOL_EAP))
464                 mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
465         else
466                 mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size);
467
468         if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
469             (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
470                 auth_type = (struct host_cmd_tlv_auth_type *)tlv;
471                 auth_type->tlv.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
472                 auth_type->tlv.len =
473                         cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
474                         sizeof(struct host_cmd_tlv));
475                 auth_type->auth_type = (u8)bss_cfg->auth_mode;
476                 cmd_size += sizeof(struct host_cmd_tlv_auth_type);
477                 tlv += sizeof(struct host_cmd_tlv_auth_type);
478         }
479         if (bss_cfg->protocol) {
480                 encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
481                 encrypt_protocol->tlv.type =
482                         cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
483                 encrypt_protocol->tlv.len =
484                         cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
485                         - sizeof(struct host_cmd_tlv));
486                 encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
487                 cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
488                 tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
489         }
490
491         if (bss_cfg->ht_cap.cap_info) {
492                 htcap = (struct mwifiex_ie_types_htcap *)tlv;
493                 htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
494                 htcap->header.len =
495                                 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
496                 htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
497                 htcap->ht_cap.ampdu_params_info =
498                                              bss_cfg->ht_cap.ampdu_params_info;
499                 memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
500                        sizeof(struct ieee80211_mcs_info));
501                 htcap->ht_cap.extended_ht_cap_info =
502                                         bss_cfg->ht_cap.extended_ht_cap_info;
503                 htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
504                 htcap->ht_cap.antenna_selection_info =
505                                         bss_cfg->ht_cap.antenna_selection_info;
506                 cmd_size += sizeof(struct mwifiex_ie_types_htcap);
507                 tlv += sizeof(struct mwifiex_ie_types_htcap);
508         }
509
510         if (bss_cfg->sta_ao_timer) {
511                 ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
512                 ao_timer->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER);
513                 ao_timer->tlv.len = cpu_to_le16(sizeof(*ao_timer) -
514                                                 sizeof(struct host_cmd_tlv));
515                 ao_timer->sta_ao_timer = cpu_to_le32(bss_cfg->sta_ao_timer);
516                 cmd_size += sizeof(*ao_timer);
517                 tlv += sizeof(*ao_timer);
518         }
519
520         if (bss_cfg->ps_sta_ao_timer) {
521                 ps_ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
522                 ps_ao_timer->tlv.type = cpu_to_le16(TLV_TYPE_UAP_PS_AO_TIMER);
523                 ps_ao_timer->tlv.len = cpu_to_le16(sizeof(*ps_ao_timer) -
524                                                    sizeof(struct host_cmd_tlv));
525                 ps_ao_timer->sta_ao_timer =
526                                         cpu_to_le32(bss_cfg->ps_sta_ao_timer);
527                 cmd_size += sizeof(*ps_ao_timer);
528                 tlv += sizeof(*ps_ao_timer);
529         }
530
531         *param_size = cmd_size;
532
533         return 0;
534 }
535
536 /* This function parses custom IEs from IE list and prepares command buffer */
537 static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
538 {
539         struct mwifiex_ie_list *ap_ie = cmd_buf;
540         struct host_cmd_tlv *tlv_ie = (struct host_cmd_tlv *)tlv;
541
542         if (!ap_ie || !ap_ie->len || !ap_ie->ie_list)
543                 return -1;
544
545         *ie_size += le16_to_cpu(ap_ie->len) + sizeof(struct host_cmd_tlv);
546
547         tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
548         tlv_ie->len = ap_ie->len;
549         tlv += sizeof(struct host_cmd_tlv);
550
551         memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
552
553         return 0;
554 }
555
556 /* Parse AP config structure and prepare TLV based command structure
557  * to be sent to FW for uAP configuration
558  */
559 static int
560 mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
561                            u32 type, void *cmd_buf)
562 {
563         u8 *tlv;
564         u16 cmd_size, param_size, ie_size;
565         struct host_cmd_ds_sys_config *sys_cfg;
566
567         cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
568         cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
569         sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
570         sys_cfg->action = cpu_to_le16(cmd_action);
571         tlv = sys_cfg->tlv;
572
573         switch (type) {
574         case UAP_BSS_PARAMS_I:
575                 param_size = cmd_size;
576                 if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
577                         return -1;
578                 cmd->size = cpu_to_le16(param_size);
579                 break;
580         case UAP_CUSTOM_IE_I:
581                 ie_size = cmd_size;
582                 if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
583                         return -1;
584                 cmd->size = cpu_to_le16(ie_size);
585                 break;
586         default:
587                 return -1;
588         }
589
590         return 0;
591 }
592
593 /* This function prepares the AP specific commands before sending them
594  * to the firmware.
595  * This is a generic function which calls specific command preparation
596  * routines based upon the command number.
597  */
598 int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
599                             u16 cmd_action, u32 type,
600                             void *data_buf, void *cmd_buf)
601 {
602         struct host_cmd_ds_command *cmd = cmd_buf;
603
604         switch (cmd_no) {
605         case HostCmd_CMD_UAP_SYS_CONFIG:
606                 if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
607                         return -1;
608                 break;
609         case HostCmd_CMD_UAP_BSS_START:
610         case HostCmd_CMD_UAP_BSS_STOP:
611                 cmd->command = cpu_to_le16(cmd_no);
612                 cmd->size = cpu_to_le16(S_DS_GEN);
613                 break;
614         default:
615                 dev_err(priv->adapter->dev,
616                         "PREP_CMD: unknown cmd %#x\n", cmd_no);
617                 return -1;
618         }
619
620         return 0;
621 }