Commit | Line | Data |
---|---|---|
ede98bfa AP |
1 | /* |
2 | * Marvell Wireless LAN device driver: management IE handling- setting and | |
3 | * deleting IE. | |
4 | * | |
5 | * Copyright (C) 2012, Marvell International Ltd. | |
6 | * | |
7 | * This software file (the "File") is distributed by Marvell International | |
8 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 | |
9 | * (the "License"). You may use, redistribute and/or modify this File in | |
10 | * accordance with the terms and conditions of the License, a copy of which | |
11 | * is available by writing to the Free Software Foundation, Inc., | |
12 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the | |
13 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | |
14 | * | |
15 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE | |
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE | |
17 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about | |
18 | * this warranty disclaimer. | |
19 | */ | |
20 | ||
21 | #include "main.h" | |
22 | ||
23 | /* This function checks if current IE index is used by any on other interface. | |
24 | * Return: -1: yes, current IE index is used by someone else. | |
25 | * 0: no, current IE index is NOT used by other interface. | |
26 | */ | |
27 | static int | |
28 | mwifiex_ie_index_used_by_other_intf(struct mwifiex_private *priv, u16 idx) | |
29 | { | |
30 | int i; | |
31 | struct mwifiex_adapter *adapter = priv->adapter; | |
32 | struct mwifiex_ie *ie; | |
33 | ||
34 | for (i = 0; i < adapter->priv_num; i++) { | |
35 | if (adapter->priv[i] != priv) { | |
36 | ie = &adapter->priv[i]->mgmt_ie[idx]; | |
37 | if (ie->mgmt_subtype_mask && ie->ie_length) | |
38 | return -1; | |
39 | } | |
40 | } | |
41 | ||
42 | return 0; | |
43 | } | |
44 | ||
45 | /* Get unused IE index. This index will be used for setting new IE */ | |
46 | static int | |
47 | mwifiex_ie_get_autoidx(struct mwifiex_private *priv, u16 subtype_mask, | |
48 | struct mwifiex_ie *ie, u16 *index) | |
49 | { | |
50 | u16 mask, len, i; | |
51 | ||
52 | for (i = 0; i < priv->adapter->max_mgmt_ie_index; i++) { | |
53 | mask = le16_to_cpu(priv->mgmt_ie[i].mgmt_subtype_mask); | |
54 | len = le16_to_cpu(priv->mgmt_ie[i].ie_length) + | |
55 | le16_to_cpu(ie->ie_length); | |
56 | ||
57 | if (mask == MWIFIEX_AUTO_IDX_MASK) | |
58 | continue; | |
59 | ||
60 | if (mask == subtype_mask) { | |
61 | if (len > IEEE_MAX_IE_SIZE) | |
62 | continue; | |
63 | ||
64 | *index = i; | |
65 | return 0; | |
66 | } | |
67 | ||
68 | if (!priv->mgmt_ie[i].ie_length) { | |
69 | if (mwifiex_ie_index_used_by_other_intf(priv, i)) | |
70 | continue; | |
71 | ||
72 | *index = i; | |
73 | return 0; | |
74 | } | |
75 | } | |
76 | ||
77 | return -1; | |
78 | } | |
79 | ||
80 | /* This function prepares IE data buffer for command to be sent to FW */ | |
81 | static int | |
82 | mwifiex_update_autoindex_ies(struct mwifiex_private *priv, | |
83 | struct mwifiex_ie_list *ie_list) | |
84 | { | |
85 | u16 travel_len, index, mask; | |
86 | s16 input_len; | |
87 | struct mwifiex_ie *ie; | |
88 | u8 *tmp; | |
89 | ||
90 | input_len = le16_to_cpu(ie_list->len); | |
91 | travel_len = sizeof(struct host_cmd_tlv); | |
92 | ||
93 | ie_list->len = 0; | |
94 | ||
95 | while (input_len > 0) { | |
96 | ie = (struct mwifiex_ie *)(((u8 *)ie_list) + travel_len); | |
97 | input_len -= le16_to_cpu(ie->ie_length) + MWIFIEX_IE_HDR_SIZE; | |
98 | travel_len += le16_to_cpu(ie->ie_length) + MWIFIEX_IE_HDR_SIZE; | |
99 | ||
100 | index = le16_to_cpu(ie->ie_index); | |
101 | mask = le16_to_cpu(ie->mgmt_subtype_mask); | |
102 | ||
103 | if (index == MWIFIEX_AUTO_IDX_MASK) { | |
104 | /* automatic addition */ | |
105 | if (mwifiex_ie_get_autoidx(priv, mask, ie, &index)) | |
106 | return -1; | |
107 | if (index == MWIFIEX_AUTO_IDX_MASK) | |
108 | return -1; | |
109 | ||
110 | tmp = (u8 *)&priv->mgmt_ie[index].ie_buffer; | |
111 | tmp += le16_to_cpu(priv->mgmt_ie[index].ie_length); | |
112 | memcpy(tmp, &ie->ie_buffer, le16_to_cpu(ie->ie_length)); | |
113 | le16_add_cpu(&priv->mgmt_ie[index].ie_length, | |
114 | le16_to_cpu(ie->ie_length)); | |
115 | priv->mgmt_ie[index].ie_index = cpu_to_le16(index); | |
116 | priv->mgmt_ie[index].mgmt_subtype_mask = | |
117 | cpu_to_le16(mask); | |
118 | ||
119 | ie->ie_index = cpu_to_le16(index); | |
120 | ie->ie_length = priv->mgmt_ie[index].ie_length; | |
121 | memcpy(&ie->ie_buffer, &priv->mgmt_ie[index].ie_buffer, | |
122 | le16_to_cpu(priv->mgmt_ie[index].ie_length)); | |
123 | } else { | |
124 | if (mask != MWIFIEX_DELETE_MASK) | |
125 | return -1; | |
126 | /* | |
127 | * Check if this index is being used on any | |
128 | * other interface. | |
129 | */ | |
130 | if (mwifiex_ie_index_used_by_other_intf(priv, index)) | |
131 | return -1; | |
132 | ||
133 | ie->ie_length = 0; | |
134 | memcpy(&priv->mgmt_ie[index], ie, | |
135 | sizeof(struct mwifiex_ie)); | |
136 | } | |
137 | ||
138 | le16_add_cpu(&ie_list->len, | |
139 | le16_to_cpu(priv->mgmt_ie[index].ie_length) + | |
140 | MWIFIEX_IE_HDR_SIZE); | |
141 | } | |
142 | ||
143 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) | |
144 | return mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG, | |
145 | HostCmd_ACT_GEN_SET, | |
146 | UAP_CUSTOM_IE_I, ie_list); | |
147 | ||
148 | return 0; | |
149 | } | |
f31acabe AP |
150 | |
151 | /* Copy individual custom IEs for beacon, probe response and assoc response | |
152 | * and prepare single structure for IE setting. | |
153 | * This function also updates allocated IE indices from driver. | |
154 | */ | |
155 | static int | |
156 | mwifiex_update_uap_custom_ie(struct mwifiex_private *priv, | |
157 | struct mwifiex_ie *beacon_ie, u16 *beacon_idx, | |
158 | struct mwifiex_ie *pr_ie, u16 *probe_idx, | |
159 | struct mwifiex_ie *ar_ie, u16 *assoc_idx) | |
160 | { | |
161 | struct mwifiex_ie_list *ap_custom_ie; | |
162 | u8 *pos; | |
163 | u16 len; | |
164 | int ret; | |
165 | ||
166 | ap_custom_ie = kzalloc(sizeof(struct mwifiex_ie), GFP_KERNEL); | |
167 | if (!ap_custom_ie) | |
168 | return -ENOMEM; | |
169 | ||
170 | ap_custom_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE); | |
171 | pos = (u8 *)ap_custom_ie->ie_list; | |
172 | ||
173 | if (beacon_ie) { | |
174 | len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE + | |
175 | le16_to_cpu(beacon_ie->ie_length); | |
176 | memcpy(pos, beacon_ie, len); | |
177 | pos += len; | |
178 | le16_add_cpu(&ap_custom_ie->len, len); | |
179 | } | |
180 | if (pr_ie) { | |
181 | len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE + | |
182 | le16_to_cpu(pr_ie->ie_length); | |
183 | memcpy(pos, pr_ie, len); | |
184 | pos += len; | |
185 | le16_add_cpu(&ap_custom_ie->len, len); | |
186 | } | |
187 | if (ar_ie) { | |
188 | len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE + | |
189 | le16_to_cpu(ar_ie->ie_length); | |
190 | memcpy(pos, ar_ie, len); | |
191 | pos += len; | |
192 | le16_add_cpu(&ap_custom_ie->len, len); | |
193 | } | |
194 | ||
195 | ret = mwifiex_update_autoindex_ies(priv, ap_custom_ie); | |
196 | ||
197 | pos = (u8 *)(&ap_custom_ie->ie_list[0].ie_index); | |
198 | if (beacon_ie && *beacon_idx == MWIFIEX_AUTO_IDX_MASK) { | |
199 | /* save beacon ie index after auto-indexing */ | |
200 | *beacon_idx = le16_to_cpu(ap_custom_ie->ie_list[0].ie_index); | |
201 | len = sizeof(*beacon_ie) - IEEE_MAX_IE_SIZE + | |
202 | le16_to_cpu(beacon_ie->ie_length); | |
203 | pos += len; | |
204 | } | |
205 | if (pr_ie && le16_to_cpu(pr_ie->ie_index) == MWIFIEX_AUTO_IDX_MASK) { | |
206 | /* save probe resp ie index after auto-indexing */ | |
207 | *probe_idx = *((u16 *)pos); | |
208 | len = sizeof(*pr_ie) - IEEE_MAX_IE_SIZE + | |
209 | le16_to_cpu(pr_ie->ie_length); | |
210 | pos += len; | |
211 | } | |
212 | if (ar_ie && le16_to_cpu(ar_ie->ie_index) == MWIFIEX_AUTO_IDX_MASK) | |
213 | /* save assoc resp ie index after auto-indexing */ | |
214 | *assoc_idx = *((u16 *)pos); | |
215 | ||
c9015b24 | 216 | kfree(ap_custom_ie); |
f31acabe AP |
217 | return ret; |
218 | } | |
219 | ||
220 | /* This function parses different IEs- Tail IEs, beacon IEs, probe response IEs, | |
221 | * association response IEs from cfg80211_ap_settings function and sets these IE | |
222 | * to FW. | |
223 | */ | |
224 | int mwifiex_set_mgmt_ies(struct mwifiex_private *priv, | |
225 | struct cfg80211_ap_settings *params) | |
226 | { | |
227 | struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL; | |
0fd66be4 AP |
228 | struct mwifiex_ie *ar_ie = NULL, *gen_ie = NULL; |
229 | struct ieee_types_header *rsn_ie = NULL, *wpa_ie = NULL; | |
f31acabe AP |
230 | u16 beacon_idx = MWIFIEX_AUTO_IDX_MASK, pr_idx = MWIFIEX_AUTO_IDX_MASK; |
231 | u16 ar_idx = MWIFIEX_AUTO_IDX_MASK, rsn_idx = MWIFIEX_AUTO_IDX_MASK; | |
0fd66be4 AP |
232 | u16 mask, ie_len = 0; |
233 | const u8 *vendor_ie; | |
f31acabe AP |
234 | int ret = 0; |
235 | ||
236 | if (params->beacon.tail && params->beacon.tail_len) { | |
0fd66be4 AP |
237 | gen_ie = kzalloc(sizeof(struct mwifiex_ie), GFP_KERNEL); |
238 | if (!gen_ie) | |
239 | return -ENOMEM; | |
240 | gen_ie->ie_index = cpu_to_le16(rsn_idx); | |
241 | mask = MGMT_MASK_BEACON | MGMT_MASK_PROBE_RESP | | |
242 | MGMT_MASK_ASSOC_RESP; | |
243 | gen_ie->mgmt_subtype_mask = cpu_to_le16(mask); | |
244 | ||
245 | rsn_ie = (void *)cfg80211_find_ie(WLAN_EID_RSN, | |
246 | params->beacon.tail, | |
247 | params->beacon.tail_len); | |
248 | if (rsn_ie) { | |
249 | memcpy(gen_ie->ie_buffer, rsn_ie, rsn_ie->len + 2); | |
250 | ie_len = rsn_ie->len + 2; | |
251 | gen_ie->ie_length = cpu_to_le16(ie_len); | |
252 | } | |
253 | ||
254 | vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, | |
255 | WLAN_OUI_TYPE_MICROSOFT_WPA, | |
256 | params->beacon.tail, | |
257 | params->beacon.tail_len); | |
258 | if (vendor_ie) { | |
259 | wpa_ie = (struct ieee_types_header *)vendor_ie; | |
260 | memcpy(gen_ie->ie_buffer + ie_len, | |
261 | wpa_ie, wpa_ie->len + 2); | |
262 | ie_len += wpa_ie->len + 2; | |
263 | gen_ie->ie_length = cpu_to_le16(ie_len); | |
264 | } | |
265 | ||
266 | if (rsn_ie || wpa_ie) { | |
267 | if (mwifiex_update_uap_custom_ie(priv, gen_ie, &rsn_idx, | |
f31acabe AP |
268 | NULL, NULL, |
269 | NULL, NULL)) { | |
270 | ret = -1; | |
271 | goto done; | |
272 | } | |
273 | ||
274 | priv->rsn_idx = rsn_idx; | |
275 | } | |
276 | } | |
277 | ||
278 | if (params->beacon.beacon_ies && params->beacon.beacon_ies_len) { | |
279 | beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL); | |
280 | if (!beacon_ie) { | |
281 | ret = -ENOMEM; | |
282 | goto done; | |
283 | } | |
284 | ||
285 | beacon_ie->ie_index = cpu_to_le16(beacon_idx); | |
286 | beacon_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_BEACON); | |
287 | beacon_ie->ie_length = | |
288 | cpu_to_le16(params->beacon.beacon_ies_len); | |
289 | memcpy(beacon_ie->ie_buffer, params->beacon.beacon_ies, | |
290 | params->beacon.beacon_ies_len); | |
291 | } | |
292 | ||
293 | if (params->beacon.proberesp_ies && params->beacon.proberesp_ies_len) { | |
294 | pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL); | |
295 | if (!pr_ie) { | |
296 | ret = -ENOMEM; | |
297 | goto done; | |
298 | } | |
299 | ||
300 | pr_ie->ie_index = cpu_to_le16(pr_idx); | |
301 | pr_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_PROBE_RESP); | |
302 | pr_ie->ie_length = | |
303 | cpu_to_le16(params->beacon.proberesp_ies_len); | |
304 | memcpy(pr_ie->ie_buffer, params->beacon.proberesp_ies, | |
305 | params->beacon.proberesp_ies_len); | |
306 | } | |
307 | ||
308 | if (params->beacon.assocresp_ies && params->beacon.assocresp_ies_len) { | |
309 | ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL); | |
310 | if (!ar_ie) { | |
311 | ret = -ENOMEM; | |
312 | goto done; | |
313 | } | |
314 | ||
315 | ar_ie->ie_index = cpu_to_le16(ar_idx); | |
316 | mask = MGMT_MASK_ASSOC_RESP | MGMT_MASK_REASSOC_RESP; | |
317 | ar_ie->mgmt_subtype_mask = cpu_to_le16(mask); | |
318 | ar_ie->ie_length = | |
319 | cpu_to_le16(params->beacon.assocresp_ies_len); | |
320 | memcpy(ar_ie->ie_buffer, params->beacon.assocresp_ies, | |
321 | params->beacon.assocresp_ies_len); | |
322 | } | |
323 | ||
324 | if (beacon_ie || pr_ie || ar_ie) { | |
325 | ret = mwifiex_update_uap_custom_ie(priv, beacon_ie, | |
326 | &beacon_idx, pr_ie, | |
327 | &pr_idx, ar_ie, &ar_idx); | |
328 | if (ret) | |
329 | goto done; | |
330 | } | |
331 | ||
332 | priv->beacon_idx = beacon_idx; | |
333 | priv->proberesp_idx = pr_idx; | |
334 | priv->assocresp_idx = ar_idx; | |
335 | ||
336 | done: | |
337 | kfree(beacon_ie); | |
338 | kfree(pr_ie); | |
339 | kfree(ar_ie); | |
0fd66be4 | 340 | kfree(gen_ie); |
f31acabe AP |
341 | |
342 | return ret; | |
343 | } | |
40bbc21a AP |
344 | |
345 | /* This function removes management IE set */ | |
346 | int mwifiex_del_mgmt_ies(struct mwifiex_private *priv) | |
347 | { | |
348 | struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL; | |
349 | struct mwifiex_ie *ar_ie = NULL, *rsn_ie = NULL; | |
350 | int ret = 0; | |
351 | ||
352 | if (priv->rsn_idx != MWIFIEX_AUTO_IDX_MASK) { | |
353 | rsn_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL); | |
354 | if (!rsn_ie) | |
355 | return -ENOMEM; | |
356 | ||
357 | rsn_ie->ie_index = cpu_to_le16(priv->rsn_idx); | |
358 | rsn_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK); | |
359 | rsn_ie->ie_length = 0; | |
360 | if (mwifiex_update_uap_custom_ie(priv, rsn_ie, &priv->rsn_idx, | |
361 | NULL, &priv->proberesp_idx, | |
362 | NULL, &priv->assocresp_idx)) { | |
363 | ret = -1; | |
364 | goto done; | |
365 | } | |
366 | ||
367 | priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK; | |
368 | } | |
369 | ||
370 | if (priv->beacon_idx != MWIFIEX_AUTO_IDX_MASK) { | |
371 | beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL); | |
372 | if (!beacon_ie) { | |
373 | ret = -ENOMEM; | |
374 | goto done; | |
375 | } | |
376 | beacon_ie->ie_index = cpu_to_le16(priv->beacon_idx); | |
377 | beacon_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK); | |
378 | beacon_ie->ie_length = 0; | |
379 | } | |
380 | if (priv->proberesp_idx != MWIFIEX_AUTO_IDX_MASK) { | |
381 | pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL); | |
382 | if (!pr_ie) { | |
383 | ret = -ENOMEM; | |
384 | goto done; | |
385 | } | |
386 | pr_ie->ie_index = cpu_to_le16(priv->proberesp_idx); | |
387 | pr_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK); | |
388 | pr_ie->ie_length = 0; | |
389 | } | |
390 | if (priv->assocresp_idx != MWIFIEX_AUTO_IDX_MASK) { | |
391 | ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL); | |
392 | if (!ar_ie) { | |
393 | ret = -ENOMEM; | |
394 | goto done; | |
395 | } | |
396 | ar_ie->ie_index = cpu_to_le16(priv->assocresp_idx); | |
397 | ar_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK); | |
398 | ar_ie->ie_length = 0; | |
399 | } | |
400 | ||
401 | if (beacon_ie || pr_ie || ar_ie) | |
402 | ret = mwifiex_update_uap_custom_ie(priv, | |
403 | beacon_ie, &priv->beacon_idx, | |
404 | pr_ie, &priv->proberesp_idx, | |
405 | ar_ie, &priv->assocresp_idx); | |
406 | ||
407 | done: | |
408 | kfree(beacon_ie); | |
409 | kfree(pr_ie); | |
410 | kfree(ar_ie); | |
411 | kfree(rsn_ie); | |
412 | ||
413 | return ret; | |
414 | } |