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