]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/wireless/mwifiex/uap_cmd.c
arm: imx6: defconfig: update tx6 defconfigs
[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 #include "11ac.h"
22
23 /* This function parses security related parameters from cfg80211_ap_settings
24  * and sets into FW understandable bss_config structure.
25  */
26 int 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;
30         struct mwifiex_wep_key wep_key;
31
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
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) {
70                                 bss_config->protocol |= PROTOCOL_WPA2;
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) {
82                                 bss_config->protocol |= PROTOCOL_WPA2;
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:
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;
102                         break;
103                 case WLAN_CIPHER_SUITE_CCMP:
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 |=
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:
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                 }
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
153 /* This function updates 11n related parameters from IE and sets them into
154  * bss_config structure.
155  */
156 void
157 mwifiex_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;
162
163         if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
164                 return;
165
166         ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
167                                  params->beacon.tail_len);
168         if (ht_ie) {
169                 memcpy(&bss_cfg->ht_cap, ht_ie + 2,
170                        sizeof(struct ieee80211_ht_cap));
171                 priv->ap_11n_enabled = 1;
172         } else {
173                 memset(&bss_cfg->ht_cap , 0, sizeof(struct ieee80211_ht_cap));
174                 bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP);
175                 bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU;
176         }
177
178         return;
179 }
180
181 /* This function updates 11ac related parameters from IE
182  * and sets them into bss_config structure.
183  */
184 void mwifiex_set_vht_params(struct mwifiex_private *priv,
185                             struct mwifiex_uap_bss_param *bss_cfg,
186                             struct cfg80211_ap_settings *params)
187 {
188         const u8 *vht_ie;
189
190         vht_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, params->beacon.tail,
191                                   params->beacon.tail_len);
192         if (vht_ie) {
193                 memcpy(&bss_cfg->vht_cap, vht_ie + 2,
194                        sizeof(struct ieee80211_vht_cap));
195                 priv->ap_11ac_enabled = 1;
196         } else {
197                 priv->ap_11ac_enabled = 0;
198         }
199
200         return;
201 }
202
203 /* Enable VHT only when cfg80211_ap_settings has VHT IE.
204  * Otherwise disable VHT.
205  */
206 void mwifiex_set_vht_width(struct mwifiex_private *priv,
207                            enum nl80211_chan_width width,
208                            bool ap_11ac_enable)
209 {
210         struct mwifiex_adapter *adapter = priv->adapter;
211         struct mwifiex_11ac_vht_cfg vht_cfg;
212
213         vht_cfg.band_config = VHT_CFG_5GHZ;
214         vht_cfg.cap_info = adapter->hw_dot_11ac_dev_cap;
215
216         if (!ap_11ac_enable) {
217                 vht_cfg.mcs_tx_set = DISABLE_VHT_MCS_SET;
218                 vht_cfg.mcs_rx_set = DISABLE_VHT_MCS_SET;
219         } else {
220                 vht_cfg.mcs_tx_set = DEFAULT_VHT_MCS_SET;
221                 vht_cfg.mcs_rx_set = DEFAULT_VHT_MCS_SET;
222         }
223
224         vht_cfg.misc_config  = VHT_CAP_UAP_ONLY;
225
226         if (ap_11ac_enable && width >= NL80211_CHAN_WIDTH_80)
227                 vht_cfg.misc_config |= VHT_BW_80_160_80P80;
228
229         mwifiex_send_cmd_sync(priv, HostCmd_CMD_11AC_CFG,
230                               HostCmd_ACT_GEN_SET, 0, &vht_cfg);
231
232         return;
233 }
234
235 /* This function finds supported rates IE from beacon parameter and sets
236  * these rates into bss_config structure.
237  */
238 void
239 mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
240                       struct cfg80211_ap_settings *params)
241 {
242         struct ieee_types_header *rate_ie;
243         int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
244         const u8 *var_pos = params->beacon.head + var_offset;
245         int len = params->beacon.head_len - var_offset;
246         u8 rate_len = 0;
247
248         rate_ie = (void *)cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
249         if (rate_ie) {
250                 memcpy(bss_cfg->rates, rate_ie + 1, rate_ie->len);
251                 rate_len = rate_ie->len;
252         }
253
254         rate_ie = (void *)cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
255                                            params->beacon.tail,
256                                            params->beacon.tail_len);
257         if (rate_ie)
258                 memcpy(bss_cfg->rates + rate_len, rate_ie + 1, rate_ie->len);
259
260         return;
261 }
262
263 /* This function initializes some of mwifiex_uap_bss_param variables.
264  * This helps FW in ignoring invalid values. These values may or may not
265  * be get updated to valid ones at later stage.
266  */
267 void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
268 {
269         config->bcast_ssid_ctl = 0x7F;
270         config->radio_ctl = 0x7F;
271         config->dtim_period = 0x7F;
272         config->beacon_period = 0x7FFF;
273         config->auth_mode = 0x7F;
274         config->rts_threshold = 0x7FFF;
275         config->frag_threshold = 0x7FFF;
276         config->retry_limit = 0x7F;
277         config->qos_info = 0xFF;
278 }
279
280 /* This function parses BSS related parameters from structure
281  * and prepares TLVs specific to WPA/WPA2 security.
282  * These TLVs are appended to command buffer.
283  */
284 static void
285 mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
286 {
287         struct host_cmd_tlv_pwk_cipher *pwk_cipher;
288         struct host_cmd_tlv_gwk_cipher *gwk_cipher;
289         struct host_cmd_tlv_passphrase *passphrase;
290         struct host_cmd_tlv_akmp *tlv_akmp;
291         struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
292         u16 cmd_size = *param_size;
293         u8 *tlv = *tlv_buf;
294
295         tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
296         tlv_akmp->header.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
297         tlv_akmp->header.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
298                                         sizeof(struct mwifiex_ie_types_header));
299         tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
300         tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
301         cmd_size += sizeof(struct host_cmd_tlv_akmp);
302         tlv += sizeof(struct host_cmd_tlv_akmp);
303
304         if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
305                 pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
306                 pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
307                 pwk_cipher->header.len =
308                         cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
309                                     sizeof(struct mwifiex_ie_types_header));
310                 pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
311                 pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
312                 cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
313                 tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
314         }
315
316         if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
317                 pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
318                 pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
319                 pwk_cipher->header.len =
320                         cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
321                                     sizeof(struct mwifiex_ie_types_header));
322                 pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
323                 pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
324                 cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
325                 tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
326         }
327
328         if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
329                 gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
330                 gwk_cipher->header.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
331                 gwk_cipher->header.len =
332                         cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
333                                     sizeof(struct mwifiex_ie_types_header));
334                 gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
335                 cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
336                 tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
337         }
338
339         if (bss_cfg->wpa_cfg.length) {
340                 passphrase = (struct host_cmd_tlv_passphrase *)tlv;
341                 passphrase->header.type =
342                                 cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
343                 passphrase->header.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
344                 memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
345                        bss_cfg->wpa_cfg.length);
346                 cmd_size += sizeof(struct mwifiex_ie_types_header) +
347                             bss_cfg->wpa_cfg.length;
348                 tlv += sizeof(struct mwifiex_ie_types_header) +
349                                 bss_cfg->wpa_cfg.length;
350         }
351
352         *param_size = cmd_size;
353         *tlv_buf = tlv;
354
355         return;
356 }
357
358 /* This function parses WMM related parameters from cfg80211_ap_settings
359  * structure and updates bss_config structure.
360  */
361 void
362 mwifiex_set_wmm_params(struct mwifiex_private *priv,
363                        struct mwifiex_uap_bss_param *bss_cfg,
364                        struct cfg80211_ap_settings *params)
365 {
366         const u8 *vendor_ie;
367         struct ieee_types_header *wmm_ie;
368         u8 wmm_oui[] = {0x00, 0x50, 0xf2, 0x02};
369
370         vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
371                                             WLAN_OUI_TYPE_MICROSOFT_WMM,
372                                             params->beacon.tail,
373                                             params->beacon.tail_len);
374         if (vendor_ie) {
375                 wmm_ie = (struct ieee_types_header *)vendor_ie;
376                 memcpy(&bss_cfg->wmm_info, wmm_ie + 1,
377                        sizeof(bss_cfg->wmm_info));
378                 priv->wmm_enabled = 1;
379         } else {
380                 memset(&bss_cfg->wmm_info, 0, sizeof(bss_cfg->wmm_info));
381                 memcpy(&bss_cfg->wmm_info.oui, wmm_oui, sizeof(wmm_oui));
382                 bss_cfg->wmm_info.subtype = MWIFIEX_WMM_SUBTYPE;
383                 bss_cfg->wmm_info.version = MWIFIEX_WMM_VERSION;
384                 priv->wmm_enabled = 0;
385         }
386
387         bss_cfg->qos_info = 0x00;
388         return;
389 }
390 /* This function parses BSS related parameters from structure
391  * and prepares TLVs specific to WEP encryption.
392  * These TLVs are appended to command buffer.
393  */
394 static void
395 mwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
396 {
397         struct host_cmd_tlv_wep_key *wep_key;
398         u16 cmd_size = *param_size;
399         int i;
400         u8 *tlv = *tlv_buf;
401         struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
402
403         for (i = 0; i < NUM_WEP_KEYS; i++) {
404                 if (bss_cfg->wep_cfg[i].length &&
405                     (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 ||
406                      bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) {
407                         wep_key = (struct host_cmd_tlv_wep_key *)tlv;
408                         wep_key->header.type =
409                                 cpu_to_le16(TLV_TYPE_UAP_WEP_KEY);
410                         wep_key->header.len =
411                                 cpu_to_le16(bss_cfg->wep_cfg[i].length + 2);
412                         wep_key->key_index = bss_cfg->wep_cfg[i].key_index;
413                         wep_key->is_default = bss_cfg->wep_cfg[i].is_default;
414                         memcpy(wep_key->key, bss_cfg->wep_cfg[i].key,
415                                bss_cfg->wep_cfg[i].length);
416                         cmd_size += sizeof(struct mwifiex_ie_types_header) + 2 +
417                                     bss_cfg->wep_cfg[i].length;
418                         tlv += sizeof(struct mwifiex_ie_types_header) + 2 +
419                                     bss_cfg->wep_cfg[i].length;
420                 }
421         }
422
423         *param_size = cmd_size;
424         *tlv_buf = tlv;
425
426         return;
427 }
428
429 /* This function parses BSS related parameters from structure
430  * and prepares TLVs. These TLVs are appended to command buffer.
431 */
432 static int
433 mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
434 {
435         struct host_cmd_tlv_dtim_period *dtim_period;
436         struct host_cmd_tlv_beacon_period *beacon_period;
437         struct host_cmd_tlv_ssid *ssid;
438         struct host_cmd_tlv_bcast_ssid *bcast_ssid;
439         struct host_cmd_tlv_channel_band *chan_band;
440         struct host_cmd_tlv_frag_threshold *frag_threshold;
441         struct host_cmd_tlv_rts_threshold *rts_threshold;
442         struct host_cmd_tlv_retry_limit *retry_limit;
443         struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
444         struct host_cmd_tlv_auth_type *auth_type;
445         struct host_cmd_tlv_rates *tlv_rates;
446         struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer;
447         struct mwifiex_ie_types_htcap *htcap;
448         struct mwifiex_ie_types_wmmcap *wmm_cap;
449         struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
450         int i;
451         u16 cmd_size = *param_size;
452
453         if (bss_cfg->ssid.ssid_len) {
454                 ssid = (struct host_cmd_tlv_ssid *)tlv;
455                 ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
456                 ssid->header.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
457                 memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
458                 cmd_size += sizeof(struct mwifiex_ie_types_header) +
459                             bss_cfg->ssid.ssid_len;
460                 tlv += sizeof(struct mwifiex_ie_types_header) +
461                                 bss_cfg->ssid.ssid_len;
462
463                 bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
464                 bcast_ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
465                 bcast_ssid->header.len =
466                                 cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
467                 bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
468                 cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
469                 tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
470         }
471         if (bss_cfg->rates[0]) {
472                 tlv_rates = (struct host_cmd_tlv_rates *)tlv;
473                 tlv_rates->header.type = cpu_to_le16(TLV_TYPE_UAP_RATES);
474
475                 for (i = 0; i < MWIFIEX_SUPPORTED_RATES && bss_cfg->rates[i];
476                      i++)
477                         tlv_rates->rates[i] = bss_cfg->rates[i];
478
479                 tlv_rates->header.len = cpu_to_le16(i);
480                 cmd_size += sizeof(struct host_cmd_tlv_rates) + i;
481                 tlv += sizeof(struct host_cmd_tlv_rates) + i;
482         }
483         if (bss_cfg->channel &&
484             ((bss_cfg->band_cfg == BAND_CONFIG_BG &&
485               bss_cfg->channel <= MAX_CHANNEL_BAND_BG) ||
486             (bss_cfg->band_cfg == BAND_CONFIG_A &&
487              bss_cfg->channel <= MAX_CHANNEL_BAND_A))) {
488                 chan_band = (struct host_cmd_tlv_channel_band *)tlv;
489                 chan_band->header.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
490                 chan_band->header.len =
491                         cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
492                                     sizeof(struct mwifiex_ie_types_header));
493                 chan_band->band_config = bss_cfg->band_cfg;
494                 chan_band->channel = bss_cfg->channel;
495                 cmd_size += sizeof(struct host_cmd_tlv_channel_band);
496                 tlv += sizeof(struct host_cmd_tlv_channel_band);
497         }
498         if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
499             bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
500                 beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
501                 beacon_period->header.type =
502                                         cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
503                 beacon_period->header.len =
504                         cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
505                                     sizeof(struct mwifiex_ie_types_header));
506                 beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
507                 cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
508                 tlv += sizeof(struct host_cmd_tlv_beacon_period);
509         }
510         if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
511             bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
512                 dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
513                 dtim_period->header.type =
514                         cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
515                 dtim_period->header.len =
516                         cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
517                                     sizeof(struct mwifiex_ie_types_header));
518                 dtim_period->period = bss_cfg->dtim_period;
519                 cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
520                 tlv += sizeof(struct host_cmd_tlv_dtim_period);
521         }
522         if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
523                 rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
524                 rts_threshold->header.type =
525                                         cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
526                 rts_threshold->header.len =
527                         cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
528                                     sizeof(struct mwifiex_ie_types_header));
529                 rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
530                 cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
531                 tlv += sizeof(struct host_cmd_tlv_frag_threshold);
532         }
533         if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
534             (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
535                 frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
536                 frag_threshold->header.type =
537                                 cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
538                 frag_threshold->header.len =
539                         cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
540                                     sizeof(struct mwifiex_ie_types_header));
541                 frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
542                 cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
543                 tlv += sizeof(struct host_cmd_tlv_frag_threshold);
544         }
545         if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
546                 retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
547                 retry_limit->header.type =
548                         cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
549                 retry_limit->header.len =
550                         cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
551                                     sizeof(struct mwifiex_ie_types_header));
552                 retry_limit->limit = (u8)bss_cfg->retry_limit;
553                 cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
554                 tlv += sizeof(struct host_cmd_tlv_retry_limit);
555         }
556         if ((bss_cfg->protocol & PROTOCOL_WPA) ||
557             (bss_cfg->protocol & PROTOCOL_WPA2) ||
558             (bss_cfg->protocol & PROTOCOL_EAP))
559                 mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
560         else
561                 mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size);
562
563         if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
564             (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
565                 auth_type = (struct host_cmd_tlv_auth_type *)tlv;
566                 auth_type->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
567                 auth_type->header.len =
568                         cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
569                         sizeof(struct mwifiex_ie_types_header));
570                 auth_type->auth_type = (u8)bss_cfg->auth_mode;
571                 cmd_size += sizeof(struct host_cmd_tlv_auth_type);
572                 tlv += sizeof(struct host_cmd_tlv_auth_type);
573         }
574         if (bss_cfg->protocol) {
575                 encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
576                 encrypt_protocol->header.type =
577                         cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
578                 encrypt_protocol->header.len =
579                         cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
580                         - sizeof(struct mwifiex_ie_types_header));
581                 encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
582                 cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
583                 tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
584         }
585
586         if (bss_cfg->ht_cap.cap_info) {
587                 htcap = (struct mwifiex_ie_types_htcap *)tlv;
588                 htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
589                 htcap->header.len =
590                                 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
591                 htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
592                 htcap->ht_cap.ampdu_params_info =
593                                              bss_cfg->ht_cap.ampdu_params_info;
594                 memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
595                        sizeof(struct ieee80211_mcs_info));
596                 htcap->ht_cap.extended_ht_cap_info =
597                                         bss_cfg->ht_cap.extended_ht_cap_info;
598                 htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
599                 htcap->ht_cap.antenna_selection_info =
600                                         bss_cfg->ht_cap.antenna_selection_info;
601                 cmd_size += sizeof(struct mwifiex_ie_types_htcap);
602                 tlv += sizeof(struct mwifiex_ie_types_htcap);
603         }
604
605         if (bss_cfg->wmm_info.qos_info != 0xFF) {
606                 wmm_cap = (struct mwifiex_ie_types_wmmcap *)tlv;
607                 wmm_cap->header.type = cpu_to_le16(WLAN_EID_VENDOR_SPECIFIC);
608                 wmm_cap->header.len = cpu_to_le16(sizeof(wmm_cap->wmm_info));
609                 memcpy(&wmm_cap->wmm_info, &bss_cfg->wmm_info,
610                        sizeof(wmm_cap->wmm_info));
611                 cmd_size += sizeof(struct mwifiex_ie_types_wmmcap);
612                 tlv += sizeof(struct mwifiex_ie_types_wmmcap);
613         }
614
615         if (bss_cfg->sta_ao_timer) {
616                 ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
617                 ao_timer->header.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER);
618                 ao_timer->header.len = cpu_to_le16(sizeof(*ao_timer) -
619                                         sizeof(struct mwifiex_ie_types_header));
620                 ao_timer->sta_ao_timer = cpu_to_le32(bss_cfg->sta_ao_timer);
621                 cmd_size += sizeof(*ao_timer);
622                 tlv += sizeof(*ao_timer);
623         }
624
625         if (bss_cfg->ps_sta_ao_timer) {
626                 ps_ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
627                 ps_ao_timer->header.type =
628                                 cpu_to_le16(TLV_TYPE_UAP_PS_AO_TIMER);
629                 ps_ao_timer->header.len = cpu_to_le16(sizeof(*ps_ao_timer) -
630                                 sizeof(struct mwifiex_ie_types_header));
631                 ps_ao_timer->sta_ao_timer =
632                                         cpu_to_le32(bss_cfg->ps_sta_ao_timer);
633                 cmd_size += sizeof(*ps_ao_timer);
634                 tlv += sizeof(*ps_ao_timer);
635         }
636
637         *param_size = cmd_size;
638
639         return 0;
640 }
641
642 /* This function parses custom IEs from IE list and prepares command buffer */
643 static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
644 {
645         struct mwifiex_ie_list *ap_ie = cmd_buf;
646         struct mwifiex_ie_types_header *tlv_ie = (void *)tlv;
647
648         if (!ap_ie || !ap_ie->len || !ap_ie->ie_list)
649                 return -1;
650
651         *ie_size += le16_to_cpu(ap_ie->len) +
652                         sizeof(struct mwifiex_ie_types_header);
653
654         tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
655         tlv_ie->len = ap_ie->len;
656         tlv += sizeof(struct mwifiex_ie_types_header);
657
658         memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
659
660         return 0;
661 }
662
663 /* Parse AP config structure and prepare TLV based command structure
664  * to be sent to FW for uAP configuration
665  */
666 static int
667 mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
668                            u32 type, void *cmd_buf)
669 {
670         u8 *tlv;
671         u16 cmd_size, param_size, ie_size;
672         struct host_cmd_ds_sys_config *sys_cfg;
673
674         cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
675         cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
676         sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
677         sys_cfg->action = cpu_to_le16(cmd_action);
678         tlv = sys_cfg->tlv;
679
680         switch (type) {
681         case UAP_BSS_PARAMS_I:
682                 param_size = cmd_size;
683                 if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
684                         return -1;
685                 cmd->size = cpu_to_le16(param_size);
686                 break;
687         case UAP_CUSTOM_IE_I:
688                 ie_size = cmd_size;
689                 if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
690                         return -1;
691                 cmd->size = cpu_to_le16(ie_size);
692                 break;
693         default:
694                 return -1;
695         }
696
697         return 0;
698 }
699
700 /* This function prepares AP specific deauth command with mac supplied in
701  * function parameter.
702  */
703 static int mwifiex_cmd_uap_sta_deauth(struct mwifiex_private *priv,
704                                       struct host_cmd_ds_command *cmd, u8 *mac)
705 {
706         struct host_cmd_ds_sta_deauth *sta_deauth = &cmd->params.sta_deauth;
707
708         cmd->command = cpu_to_le16(HostCmd_CMD_UAP_STA_DEAUTH);
709         memcpy(sta_deauth->mac, mac, ETH_ALEN);
710         sta_deauth->reason = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
711
712         cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_sta_deauth) +
713                                 S_DS_GEN);
714         return 0;
715 }
716
717 /* This function prepares the AP specific commands before sending them
718  * to the firmware.
719  * This is a generic function which calls specific command preparation
720  * routines based upon the command number.
721  */
722 int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
723                             u16 cmd_action, u32 type,
724                             void *data_buf, void *cmd_buf)
725 {
726         struct host_cmd_ds_command *cmd = cmd_buf;
727
728         switch (cmd_no) {
729         case HostCmd_CMD_UAP_SYS_CONFIG:
730                 if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
731                         return -1;
732                 break;
733         case HostCmd_CMD_UAP_BSS_START:
734         case HostCmd_CMD_UAP_BSS_STOP:
735                 cmd->command = cpu_to_le16(cmd_no);
736                 cmd->size = cpu_to_le16(S_DS_GEN);
737                 break;
738         case HostCmd_CMD_UAP_STA_DEAUTH:
739                 if (mwifiex_cmd_uap_sta_deauth(priv, cmd, data_buf))
740                         return -1;
741                 break;
742         default:
743                 dev_err(priv->adapter->dev,
744                         "PREP_CMD: unknown cmd %#x\n", cmd_no);
745                 return -1;
746         }
747
748         return 0;
749 }