Commit | Line | Data |
---|---|---|
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 | */ | |
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 | ||
6ddcd464 AP |
30 | if (!params->privacy) { |
31 | bss_config->protocol = PROTOCOL_NO_SECURITY; | |
32 | bss_config->key_mgmt = KEY_MGMT_NONE; | |
33 | bss_config->wpa_cfg.length = 0; | |
34 | priv->sec_info.wep_enabled = 0; | |
35 | priv->sec_info.wpa_enabled = 0; | |
36 | priv->sec_info.wpa2_enabled = 0; | |
37 | ||
38 | return 0; | |
39 | } | |
40 | ||
f752dcd5 AP |
41 | switch (params->auth_type) { |
42 | case NL80211_AUTHTYPE_OPEN_SYSTEM: | |
43 | bss_config->auth_mode = WLAN_AUTH_OPEN; | |
44 | break; | |
45 | case NL80211_AUTHTYPE_SHARED_KEY: | |
46 | bss_config->auth_mode = WLAN_AUTH_SHARED_KEY; | |
47 | break; | |
48 | case NL80211_AUTHTYPE_NETWORK_EAP: | |
49 | bss_config->auth_mode = WLAN_AUTH_LEAP; | |
50 | break; | |
51 | default: | |
52 | bss_config->auth_mode = MWIFIEX_AUTH_MODE_AUTO; | |
53 | break; | |
54 | } | |
55 | ||
56 | bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST; | |
57 | ||
58 | for (i = 0; i < params->crypto.n_akm_suites; i++) { | |
59 | switch (params->crypto.akm_suites[i]) { | |
60 | case WLAN_AKM_SUITE_8021X: | |
61 | if (params->crypto.wpa_versions & | |
62 | NL80211_WPA_VERSION_1) { | |
63 | bss_config->protocol = PROTOCOL_WPA; | |
64 | bss_config->key_mgmt = KEY_MGMT_EAP; | |
65 | } | |
66 | if (params->crypto.wpa_versions & | |
67 | NL80211_WPA_VERSION_2) { | |
68 | bss_config->protocol = PROTOCOL_WPA2; | |
69 | bss_config->key_mgmt = KEY_MGMT_EAP; | |
70 | } | |
71 | break; | |
72 | case WLAN_AKM_SUITE_PSK: | |
73 | if (params->crypto.wpa_versions & | |
74 | NL80211_WPA_VERSION_1) { | |
75 | bss_config->protocol = PROTOCOL_WPA; | |
76 | bss_config->key_mgmt = KEY_MGMT_PSK; | |
77 | } | |
78 | if (params->crypto.wpa_versions & | |
79 | NL80211_WPA_VERSION_2) { | |
80 | bss_config->protocol = PROTOCOL_WPA2; | |
81 | bss_config->key_mgmt = KEY_MGMT_PSK; | |
82 | } | |
83 | break; | |
84 | default: | |
85 | break; | |
86 | } | |
87 | } | |
88 | for (i = 0; i < params->crypto.n_ciphers_pairwise; i++) { | |
89 | switch (params->crypto.ciphers_pairwise[i]) { | |
90 | case WLAN_CIPHER_SUITE_WEP40: | |
91 | case WLAN_CIPHER_SUITE_WEP104: | |
92 | break; | |
93 | case WLAN_CIPHER_SUITE_TKIP: | |
94 | bss_config->wpa_cfg.pairwise_cipher_wpa = CIPHER_TKIP; | |
95 | break; | |
96 | case WLAN_CIPHER_SUITE_CCMP: | |
97 | bss_config->wpa_cfg.pairwise_cipher_wpa2 = | |
98 | CIPHER_AES_CCMP; | |
99 | default: | |
100 | break; | |
101 | } | |
102 | } | |
103 | ||
104 | switch (params->crypto.cipher_group) { | |
105 | case WLAN_CIPHER_SUITE_WEP40: | |
106 | case WLAN_CIPHER_SUITE_WEP104: | |
107 | break; | |
108 | case WLAN_CIPHER_SUITE_TKIP: | |
109 | bss_config->wpa_cfg.group_cipher = CIPHER_TKIP; | |
110 | break; | |
111 | case WLAN_CIPHER_SUITE_CCMP: | |
112 | bss_config->wpa_cfg.group_cipher = CIPHER_AES_CCMP; | |
113 | break; | |
114 | default: | |
115 | break; | |
116 | } | |
117 | ||
118 | return 0; | |
119 | } | |
120 | ||
22281256 AP |
121 | /* This function updates 11n related parameters from IE and sets them into |
122 | * bss_config structure. | |
123 | */ | |
124 | void | |
125 | mwifiex_set_ht_params(struct mwifiex_private *priv, | |
126 | struct mwifiex_uap_bss_param *bss_cfg, | |
127 | struct cfg80211_ap_settings *params) | |
128 | { | |
129 | const u8 *ht_ie; | |
130 | ||
131 | if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info)) | |
132 | return; | |
133 | ||
134 | ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail, | |
135 | params->beacon.tail_len); | |
136 | if (ht_ie) { | |
137 | memcpy(&bss_cfg->ht_cap, ht_ie + 2, | |
138 | sizeof(struct ieee80211_ht_cap)); | |
139 | } else { | |
140 | memset(&bss_cfg->ht_cap , 0, sizeof(struct ieee80211_ht_cap)); | |
141 | bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP); | |
142 | bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU; | |
143 | } | |
144 | ||
145 | return; | |
146 | } | |
147 | ||
9b930eae AP |
148 | /* This function initializes some of mwifiex_uap_bss_param variables. |
149 | * This helps FW in ignoring invalid values. These values may or may not | |
150 | * be get updated to valid ones at later stage. | |
151 | */ | |
152 | void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config) | |
153 | { | |
f752dcd5 AP |
154 | config->bcast_ssid_ctl = 0x7F; |
155 | config->radio_ctl = 0x7F; | |
156 | config->dtim_period = 0x7F; | |
157 | config->beacon_period = 0x7FFF; | |
158 | config->auth_mode = 0x7F; | |
9b930eae AP |
159 | config->rts_threshold = 0x7FFF; |
160 | config->frag_threshold = 0x7FFF; | |
161 | config->retry_limit = 0x7F; | |
162 | } | |
163 | ||
e76268da AP |
164 | /* This function parses BSS related parameters from structure |
165 | * and prepares TLVs. These TLVs are appended to command buffer. | |
166 | */ | |
167 | static int | |
168 | mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size) | |
4db16a18 | 169 | { |
12190c5d AP |
170 | struct host_cmd_tlv_dtim_period *dtim_period; |
171 | struct host_cmd_tlv_beacon_period *beacon_period; | |
172 | struct host_cmd_tlv_ssid *ssid; | |
7a1c9934 | 173 | struct host_cmd_tlv_bcast_ssid *bcast_ssid; |
4db16a18 | 174 | struct host_cmd_tlv_channel_band *chan_band; |
9b930eae AP |
175 | struct host_cmd_tlv_frag_threshold *frag_threshold; |
176 | struct host_cmd_tlv_rts_threshold *rts_threshold; | |
177 | struct host_cmd_tlv_retry_limit *retry_limit; | |
f752dcd5 AP |
178 | struct host_cmd_tlv_pwk_cipher *pwk_cipher; |
179 | struct host_cmd_tlv_gwk_cipher *gwk_cipher; | |
180 | struct host_cmd_tlv_encrypt_protocol *encrypt_protocol; | |
181 | struct host_cmd_tlv_auth_type *auth_type; | |
182 | struct host_cmd_tlv_passphrase *passphrase; | |
183 | struct host_cmd_tlv_akmp *tlv_akmp; | |
22281256 | 184 | struct mwifiex_ie_types_htcap *htcap; |
4db16a18 | 185 | struct mwifiex_uap_bss_param *bss_cfg = cmd_buf; |
e76268da | 186 | u16 cmd_size = *param_size; |
4db16a18 | 187 | |
12190c5d AP |
188 | if (bss_cfg->ssid.ssid_len) { |
189 | ssid = (struct host_cmd_tlv_ssid *)tlv; | |
190 | ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_SSID); | |
191 | ssid->tlv.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len); | |
192 | memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len); | |
193 | cmd_size += sizeof(struct host_cmd_tlv) + | |
194 | bss_cfg->ssid.ssid_len; | |
195 | tlv += sizeof(struct host_cmd_tlv) + bss_cfg->ssid.ssid_len; | |
7a1c9934 AP |
196 | |
197 | bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv; | |
198 | bcast_ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID); | |
199 | bcast_ssid->tlv.len = | |
200 | cpu_to_le16(sizeof(bcast_ssid->bcast_ctl)); | |
201 | bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl; | |
202 | cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid); | |
203 | tlv += sizeof(struct host_cmd_tlv_bcast_ssid); | |
12190c5d | 204 | } |
4db16a18 AP |
205 | if (bss_cfg->channel && bss_cfg->channel <= MAX_CHANNEL_BAND_BG) { |
206 | chan_band = (struct host_cmd_tlv_channel_band *)tlv; | |
207 | chan_band->tlv.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST); | |
208 | chan_band->tlv.len = | |
209 | cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) - | |
210 | sizeof(struct host_cmd_tlv)); | |
211 | chan_band->band_config = bss_cfg->band_cfg; | |
212 | chan_band->channel = bss_cfg->channel; | |
213 | cmd_size += sizeof(struct host_cmd_tlv_channel_band); | |
214 | tlv += sizeof(struct host_cmd_tlv_channel_band); | |
215 | } | |
12190c5d AP |
216 | if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD && |
217 | bss_cfg->beacon_period <= MAX_BEACON_PERIOD) { | |
218 | beacon_period = (struct host_cmd_tlv_beacon_period *)tlv; | |
219 | beacon_period->tlv.type = | |
220 | cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD); | |
221 | beacon_period->tlv.len = | |
222 | cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) - | |
223 | sizeof(struct host_cmd_tlv)); | |
224 | beacon_period->period = cpu_to_le16(bss_cfg->beacon_period); | |
225 | cmd_size += sizeof(struct host_cmd_tlv_beacon_period); | |
226 | tlv += sizeof(struct host_cmd_tlv_beacon_period); | |
227 | } | |
228 | if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD && | |
229 | bss_cfg->dtim_period <= MAX_DTIM_PERIOD) { | |
230 | dtim_period = (struct host_cmd_tlv_dtim_period *)tlv; | |
231 | dtim_period->tlv.type = cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD); | |
232 | dtim_period->tlv.len = | |
233 | cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) - | |
234 | sizeof(struct host_cmd_tlv)); | |
235 | dtim_period->period = bss_cfg->dtim_period; | |
236 | cmd_size += sizeof(struct host_cmd_tlv_dtim_period); | |
237 | tlv += sizeof(struct host_cmd_tlv_dtim_period); | |
238 | } | |
9b930eae AP |
239 | if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) { |
240 | rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv; | |
241 | rts_threshold->tlv.type = | |
242 | cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD); | |
243 | rts_threshold->tlv.len = | |
244 | cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) - | |
245 | sizeof(struct host_cmd_tlv)); | |
246 | rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold); | |
247 | cmd_size += sizeof(struct host_cmd_tlv_frag_threshold); | |
248 | tlv += sizeof(struct host_cmd_tlv_frag_threshold); | |
249 | } | |
250 | if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) && | |
251 | (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) { | |
252 | frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv; | |
253 | frag_threshold->tlv.type = | |
254 | cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD); | |
255 | frag_threshold->tlv.len = | |
256 | cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) - | |
257 | sizeof(struct host_cmd_tlv)); | |
258 | frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold); | |
259 | cmd_size += sizeof(struct host_cmd_tlv_frag_threshold); | |
260 | tlv += sizeof(struct host_cmd_tlv_frag_threshold); | |
261 | } | |
262 | if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) { | |
263 | retry_limit = (struct host_cmd_tlv_retry_limit *)tlv; | |
264 | retry_limit->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT); | |
265 | retry_limit->tlv.len = | |
266 | cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) - | |
267 | sizeof(struct host_cmd_tlv)); | |
268 | retry_limit->limit = (u8)bss_cfg->retry_limit; | |
269 | cmd_size += sizeof(struct host_cmd_tlv_retry_limit); | |
270 | tlv += sizeof(struct host_cmd_tlv_retry_limit); | |
271 | } | |
f752dcd5 AP |
272 | if ((bss_cfg->protocol & PROTOCOL_WPA) || |
273 | (bss_cfg->protocol & PROTOCOL_WPA2) || | |
274 | (bss_cfg->protocol & PROTOCOL_EAP)) { | |
275 | tlv_akmp = (struct host_cmd_tlv_akmp *)tlv; | |
276 | tlv_akmp->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AKMP); | |
277 | tlv_akmp->tlv.len = | |
278 | cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) - | |
279 | sizeof(struct host_cmd_tlv)); | |
280 | tlv_akmp->key_mgmt_operation = | |
281 | cpu_to_le16(bss_cfg->key_mgmt_operation); | |
282 | tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt); | |
283 | cmd_size += sizeof(struct host_cmd_tlv_akmp); | |
284 | tlv += sizeof(struct host_cmd_tlv_akmp); | |
285 | ||
286 | if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & | |
287 | VALID_CIPHER_BITMAP) { | |
288 | pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv; | |
289 | pwk_cipher->tlv.type = | |
290 | cpu_to_le16(TLV_TYPE_PWK_CIPHER); | |
291 | pwk_cipher->tlv.len = cpu_to_le16( | |
292 | sizeof(struct host_cmd_tlv_pwk_cipher) - | |
293 | sizeof(struct host_cmd_tlv)); | |
294 | pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA); | |
295 | pwk_cipher->cipher = | |
296 | bss_cfg->wpa_cfg.pairwise_cipher_wpa; | |
297 | cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher); | |
298 | tlv += sizeof(struct host_cmd_tlv_pwk_cipher); | |
299 | } | |
300 | if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & | |
301 | VALID_CIPHER_BITMAP) { | |
302 | pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv; | |
303 | pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER); | |
304 | pwk_cipher->tlv.len = cpu_to_le16( | |
305 | sizeof(struct host_cmd_tlv_pwk_cipher) - | |
306 | sizeof(struct host_cmd_tlv)); | |
307 | pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2); | |
308 | pwk_cipher->cipher = | |
309 | bss_cfg->wpa_cfg.pairwise_cipher_wpa2; | |
310 | cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher); | |
311 | tlv += sizeof(struct host_cmd_tlv_pwk_cipher); | |
312 | } | |
313 | if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) { | |
314 | gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv; | |
315 | gwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER); | |
316 | gwk_cipher->tlv.len = cpu_to_le16( | |
317 | sizeof(struct host_cmd_tlv_gwk_cipher) - | |
318 | sizeof(struct host_cmd_tlv)); | |
319 | gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher; | |
320 | cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher); | |
321 | tlv += sizeof(struct host_cmd_tlv_gwk_cipher); | |
322 | } | |
323 | if (bss_cfg->wpa_cfg.length) { | |
324 | passphrase = (struct host_cmd_tlv_passphrase *)tlv; | |
325 | passphrase->tlv.type = | |
326 | cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE); | |
327 | passphrase->tlv.len = | |
328 | cpu_to_le16(bss_cfg->wpa_cfg.length); | |
329 | memcpy(passphrase->passphrase, | |
330 | bss_cfg->wpa_cfg.passphrase, | |
331 | bss_cfg->wpa_cfg.length); | |
332 | cmd_size += sizeof(struct host_cmd_tlv) + | |
333 | bss_cfg->wpa_cfg.length; | |
334 | tlv += sizeof(struct host_cmd_tlv) + | |
335 | bss_cfg->wpa_cfg.length; | |
336 | } | |
337 | } | |
338 | if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) || | |
339 | (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) { | |
340 | auth_type = (struct host_cmd_tlv_auth_type *)tlv; | |
341 | auth_type->tlv.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE); | |
342 | auth_type->tlv.len = | |
343 | cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) - | |
344 | sizeof(struct host_cmd_tlv)); | |
345 | auth_type->auth_type = (u8)bss_cfg->auth_mode; | |
346 | cmd_size += sizeof(struct host_cmd_tlv_auth_type); | |
347 | tlv += sizeof(struct host_cmd_tlv_auth_type); | |
348 | } | |
349 | if (bss_cfg->protocol) { | |
350 | encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv; | |
351 | encrypt_protocol->tlv.type = | |
352 | cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL); | |
353 | encrypt_protocol->tlv.len = | |
354 | cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol) | |
355 | - sizeof(struct host_cmd_tlv)); | |
356 | encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol); | |
357 | cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol); | |
358 | tlv += sizeof(struct host_cmd_tlv_encrypt_protocol); | |
359 | } | |
4db16a18 | 360 | |
22281256 AP |
361 | if (bss_cfg->ht_cap.cap_info) { |
362 | htcap = (struct mwifiex_ie_types_htcap *)tlv; | |
363 | htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY); | |
364 | htcap->header.len = | |
365 | cpu_to_le16(sizeof(struct ieee80211_ht_cap)); | |
366 | htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info; | |
367 | htcap->ht_cap.ampdu_params_info = | |
368 | bss_cfg->ht_cap.ampdu_params_info; | |
369 | memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs, | |
370 | sizeof(struct ieee80211_mcs_info)); | |
371 | htcap->ht_cap.extended_ht_cap_info = | |
372 | bss_cfg->ht_cap.extended_ht_cap_info; | |
373 | htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info; | |
374 | htcap->ht_cap.antenna_selection_info = | |
375 | bss_cfg->ht_cap.antenna_selection_info; | |
376 | cmd_size += sizeof(struct mwifiex_ie_types_htcap); | |
377 | tlv += sizeof(struct mwifiex_ie_types_htcap); | |
378 | } | |
379 | ||
e76268da AP |
380 | *param_size = cmd_size; |
381 | ||
382 | return 0; | |
383 | } | |
384 | ||
ede98bfa AP |
385 | /* This function parses custom IEs from IE list and prepares command buffer */ |
386 | static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size) | |
387 | { | |
388 | struct mwifiex_ie_list *ap_ie = cmd_buf; | |
389 | struct host_cmd_tlv *tlv_ie = (struct host_cmd_tlv *)tlv; | |
390 | ||
391 | if (!ap_ie || !ap_ie->len || !ap_ie->ie_list) | |
392 | return -1; | |
393 | ||
394 | *ie_size += le16_to_cpu(ap_ie->len) + sizeof(struct host_cmd_tlv); | |
395 | ||
396 | tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE); | |
397 | tlv_ie->len = ap_ie->len; | |
398 | tlv += sizeof(struct host_cmd_tlv); | |
399 | ||
400 | memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len)); | |
401 | ||
402 | return 0; | |
403 | } | |
404 | ||
e76268da AP |
405 | /* Parse AP config structure and prepare TLV based command structure |
406 | * to be sent to FW for uAP configuration | |
407 | */ | |
408 | static int | |
409 | mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action, | |
410 | u32 type, void *cmd_buf) | |
411 | { | |
412 | u8 *tlv; | |
ede98bfa | 413 | u16 cmd_size, param_size, ie_size; |
e76268da AP |
414 | struct host_cmd_ds_sys_config *sys_cfg; |
415 | ||
416 | cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG); | |
417 | cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN); | |
418 | sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config; | |
419 | sys_cfg->action = cpu_to_le16(cmd_action); | |
420 | tlv = sys_cfg->tlv; | |
421 | ||
422 | switch (type) { | |
423 | case UAP_BSS_PARAMS_I: | |
424 | param_size = cmd_size; | |
425 | if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, ¶m_size)) | |
426 | return -1; | |
427 | cmd->size = cpu_to_le16(param_size); | |
428 | break; | |
ede98bfa AP |
429 | case UAP_CUSTOM_IE_I: |
430 | ie_size = cmd_size; | |
431 | if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size)) | |
432 | return -1; | |
433 | cmd->size = cpu_to_le16(ie_size); | |
434 | break; | |
e76268da AP |
435 | default: |
436 | return -1; | |
437 | } | |
438 | ||
4db16a18 AP |
439 | return 0; |
440 | } | |
441 | ||
40d07030 AP |
442 | /* This function prepares the AP specific commands before sending them |
443 | * to the firmware. | |
444 | * This is a generic function which calls specific command preparation | |
445 | * routines based upon the command number. | |
446 | */ | |
447 | int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no, | |
e76268da | 448 | u16 cmd_action, u32 type, |
40d07030 AP |
449 | void *data_buf, void *cmd_buf) |
450 | { | |
451 | struct host_cmd_ds_command *cmd = cmd_buf; | |
452 | ||
453 | switch (cmd_no) { | |
4db16a18 | 454 | case HostCmd_CMD_UAP_SYS_CONFIG: |
e76268da | 455 | if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf)) |
4db16a18 AP |
456 | return -1; |
457 | break; | |
40d07030 AP |
458 | case HostCmd_CMD_UAP_BSS_START: |
459 | case HostCmd_CMD_UAP_BSS_STOP: | |
460 | cmd->command = cpu_to_le16(cmd_no); | |
461 | cmd->size = cpu_to_le16(S_DS_GEN); | |
462 | break; | |
463 | default: | |
464 | dev_err(priv->adapter->dev, | |
465 | "PREP_CMD: unknown cmd %#x\n", cmd_no); | |
466 | return -1; | |
467 | } | |
468 | ||
469 | return 0; | |
470 | } |