blob: 1d8dd003e39617124ff87d92d2d3437391b7ba84 [file] [log] [blame]
Avinash Patilede98bf2012-05-08 18:30:28 -07001/*
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 */
27static int
28mwifiex_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 */
46static int
47mwifiex_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);
Avinash Patilbd6aa032012-06-28 20:30:27 -070054 len = le16_to_cpu(ie->ie_length);
Avinash Patilede98bf2012-05-08 18:30:28 -070055
56 if (mask == MWIFIEX_AUTO_IDX_MASK)
57 continue;
58
59 if (mask == subtype_mask) {
60 if (len > IEEE_MAX_IE_SIZE)
61 continue;
62
63 *index = i;
64 return 0;
65 }
66
67 if (!priv->mgmt_ie[i].ie_length) {
68 if (mwifiex_ie_index_used_by_other_intf(priv, i))
69 continue;
70
71 *index = i;
72 return 0;
73 }
74 }
75
76 return -1;
77}
78
79/* This function prepares IE data buffer for command to be sent to FW */
80static int
81mwifiex_update_autoindex_ies(struct mwifiex_private *priv,
82 struct mwifiex_ie_list *ie_list)
83{
84 u16 travel_len, index, mask;
85 s16 input_len;
86 struct mwifiex_ie *ie;
87 u8 *tmp;
88
89 input_len = le16_to_cpu(ie_list->len);
90 travel_len = sizeof(struct host_cmd_tlv);
91
92 ie_list->len = 0;
93
94 while (input_len > 0) {
95 ie = (struct mwifiex_ie *)(((u8 *)ie_list) + travel_len);
96 input_len -= le16_to_cpu(ie->ie_length) + MWIFIEX_IE_HDR_SIZE;
97 travel_len += le16_to_cpu(ie->ie_length) + MWIFIEX_IE_HDR_SIZE;
98
99 index = le16_to_cpu(ie->ie_index);
100 mask = le16_to_cpu(ie->mgmt_subtype_mask);
101
102 if (index == MWIFIEX_AUTO_IDX_MASK) {
103 /* automatic addition */
104 if (mwifiex_ie_get_autoidx(priv, mask, ie, &index))
105 return -1;
106 if (index == MWIFIEX_AUTO_IDX_MASK)
107 return -1;
108
109 tmp = (u8 *)&priv->mgmt_ie[index].ie_buffer;
Avinash Patilede98bf2012-05-08 18:30:28 -0700110 memcpy(tmp, &ie->ie_buffer, le16_to_cpu(ie->ie_length));
Avinash Patilbd6aa032012-06-28 20:30:27 -0700111 priv->mgmt_ie[index].ie_length = ie->ie_length;
Avinash Patilede98bf2012-05-08 18:30:28 -0700112 priv->mgmt_ie[index].ie_index = cpu_to_le16(index);
113 priv->mgmt_ie[index].mgmt_subtype_mask =
114 cpu_to_le16(mask);
115
116 ie->ie_index = cpu_to_le16(index);
117 ie->ie_length = priv->mgmt_ie[index].ie_length;
118 memcpy(&ie->ie_buffer, &priv->mgmt_ie[index].ie_buffer,
119 le16_to_cpu(priv->mgmt_ie[index].ie_length));
120 } else {
121 if (mask != MWIFIEX_DELETE_MASK)
122 return -1;
123 /*
124 * Check if this index is being used on any
125 * other interface.
126 */
127 if (mwifiex_ie_index_used_by_other_intf(priv, index))
128 return -1;
129
130 ie->ie_length = 0;
131 memcpy(&priv->mgmt_ie[index], ie,
132 sizeof(struct mwifiex_ie));
133 }
134
135 le16_add_cpu(&ie_list->len,
136 le16_to_cpu(priv->mgmt_ie[index].ie_length) +
137 MWIFIEX_IE_HDR_SIZE);
138 }
139
140 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
141 return mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
142 HostCmd_ACT_GEN_SET,
143 UAP_CUSTOM_IE_I, ie_list);
144
145 return 0;
146}
Avinash Patilf31acab2012-05-08 18:30:29 -0700147
148/* Copy individual custom IEs for beacon, probe response and assoc response
149 * and prepare single structure for IE setting.
150 * This function also updates allocated IE indices from driver.
151 */
152static int
153mwifiex_update_uap_custom_ie(struct mwifiex_private *priv,
154 struct mwifiex_ie *beacon_ie, u16 *beacon_idx,
155 struct mwifiex_ie *pr_ie, u16 *probe_idx,
156 struct mwifiex_ie *ar_ie, u16 *assoc_idx)
157{
158 struct mwifiex_ie_list *ap_custom_ie;
159 u8 *pos;
160 u16 len;
161 int ret;
162
163 ap_custom_ie = kzalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
164 if (!ap_custom_ie)
165 return -ENOMEM;
166
167 ap_custom_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
168 pos = (u8 *)ap_custom_ie->ie_list;
169
170 if (beacon_ie) {
171 len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
172 le16_to_cpu(beacon_ie->ie_length);
173 memcpy(pos, beacon_ie, len);
174 pos += len;
175 le16_add_cpu(&ap_custom_ie->len, len);
176 }
177 if (pr_ie) {
178 len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
179 le16_to_cpu(pr_ie->ie_length);
180 memcpy(pos, pr_ie, len);
181 pos += len;
182 le16_add_cpu(&ap_custom_ie->len, len);
183 }
184 if (ar_ie) {
185 len = sizeof(struct mwifiex_ie) - IEEE_MAX_IE_SIZE +
186 le16_to_cpu(ar_ie->ie_length);
187 memcpy(pos, ar_ie, len);
188 pos += len;
189 le16_add_cpu(&ap_custom_ie->len, len);
190 }
191
192 ret = mwifiex_update_autoindex_ies(priv, ap_custom_ie);
193
194 pos = (u8 *)(&ap_custom_ie->ie_list[0].ie_index);
195 if (beacon_ie && *beacon_idx == MWIFIEX_AUTO_IDX_MASK) {
196 /* save beacon ie index after auto-indexing */
197 *beacon_idx = le16_to_cpu(ap_custom_ie->ie_list[0].ie_index);
198 len = sizeof(*beacon_ie) - IEEE_MAX_IE_SIZE +
199 le16_to_cpu(beacon_ie->ie_length);
200 pos += len;
201 }
202 if (pr_ie && le16_to_cpu(pr_ie->ie_index) == MWIFIEX_AUTO_IDX_MASK) {
203 /* save probe resp ie index after auto-indexing */
204 *probe_idx = *((u16 *)pos);
205 len = sizeof(*pr_ie) - IEEE_MAX_IE_SIZE +
206 le16_to_cpu(pr_ie->ie_length);
207 pos += len;
208 }
209 if (ar_ie && le16_to_cpu(ar_ie->ie_index) == MWIFIEX_AUTO_IDX_MASK)
210 /* save assoc resp ie index after auto-indexing */
211 *assoc_idx = *((u16 *)pos);
212
Avinash Patilc9015b22012-06-27 12:46:24 -0700213 kfree(ap_custom_ie);
Avinash Patilf31acab2012-05-08 18:30:29 -0700214 return ret;
215}
216
Avinash Patil2152fe92012-06-28 20:30:30 -0700217/* This function checks if WPS IE is present in passed buffer and copies it to
218 * mwifiex_ie structure.
219 * Function takes pointer to struct mwifiex_ie pointer as argument.
220 * If WPS IE is present memory is allocated for mwifiex_ie pointer and filled
221 * in with WPS IE. Caller should take care of freeing this memory.
222 */
223static int mwifiex_update_wps_ie(const u8 *ies, int ies_len,
224 struct mwifiex_ie **ie_ptr, u16 mask)
225{
226 struct ieee_types_header *wps_ie;
227 struct mwifiex_ie *ie = NULL;
228 const u8 *vendor_ie;
229
230 vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
231 WLAN_OUI_TYPE_MICROSOFT_WPS,
232 ies, ies_len);
233 if (vendor_ie) {
234 ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
235 if (!ie)
236 return -ENOMEM;
237
238 wps_ie = (struct ieee_types_header *)vendor_ie;
239 memcpy(ie->ie_buffer, wps_ie, wps_ie->len + 2);
240 ie->ie_length = cpu_to_le16(wps_ie->len + 2);
241 ie->mgmt_subtype_mask = cpu_to_le16(mask);
242 ie->ie_index = cpu_to_le16(MWIFIEX_AUTO_IDX_MASK);
243 }
244
245 *ie_ptr = ie;
246 return 0;
247}
248
Avinash Patilea4c12f2012-06-28 20:30:26 -0700249/* This function parses beacon IEs, probe response IEs, association response IEs
250 * from cfg80211_ap_settings->beacon and sets these IE to FW.
Avinash Patilf31acab2012-05-08 18:30:29 -0700251 */
Avinash Patilea4c12f2012-06-28 20:30:26 -0700252static int mwifiex_set_mgmt_beacon_data_ies(struct mwifiex_private *priv,
253 struct cfg80211_beacon_data *data)
Avinash Patilf31acab2012-05-08 18:30:29 -0700254{
Avinash Patilea4c12f2012-06-28 20:30:26 -0700255 struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL, *ar_ie = NULL;
Avinash Patilf31acab2012-05-08 18:30:29 -0700256 u16 beacon_idx = MWIFIEX_AUTO_IDX_MASK, pr_idx = MWIFIEX_AUTO_IDX_MASK;
Avinash Patilea4c12f2012-06-28 20:30:26 -0700257 u16 ar_idx = MWIFIEX_AUTO_IDX_MASK;
Avinash Patilf31acab2012-05-08 18:30:29 -0700258 int ret = 0;
259
Avinash Patil2152fe92012-06-28 20:30:30 -0700260 if (data->beacon_ies && data->beacon_ies_len)
261 mwifiex_update_wps_ie(data->beacon_ies, data->beacon_ies_len,
262 &beacon_ie, MGMT_MASK_BEACON);
Avinash Patilf31acab2012-05-08 18:30:29 -0700263
Avinash Patil2152fe92012-06-28 20:30:30 -0700264 if (data->proberesp_ies && data->proberesp_ies_len)
265 mwifiex_update_wps_ie(data->proberesp_ies,
266 data->proberesp_ies_len, &pr_ie,
267 MGMT_MASK_PROBE_RESP);
Avinash Patilf31acab2012-05-08 18:30:29 -0700268
Avinash Patil2152fe92012-06-28 20:30:30 -0700269 if (data->assocresp_ies && data->assocresp_ies_len)
270 mwifiex_update_wps_ie(data->assocresp_ies,
271 data->assocresp_ies_len, &ar_ie,
272 MGMT_MASK_ASSOC_RESP |
273 MGMT_MASK_REASSOC_RESP);
Avinash Patilf31acab2012-05-08 18:30:29 -0700274
275 if (beacon_ie || pr_ie || ar_ie) {
276 ret = mwifiex_update_uap_custom_ie(priv, beacon_ie,
277 &beacon_idx, pr_ie,
278 &pr_idx, ar_ie, &ar_idx);
279 if (ret)
280 goto done;
281 }
282
283 priv->beacon_idx = beacon_idx;
284 priv->proberesp_idx = pr_idx;
285 priv->assocresp_idx = ar_idx;
286
287done:
288 kfree(beacon_ie);
289 kfree(pr_ie);
290 kfree(ar_ie);
Avinash Patilf31acab2012-05-08 18:30:29 -0700291
292 return ret;
293}
Avinash Patil40bbc212012-05-08 18:30:30 -0700294
Avinash Patilea4c12f2012-06-28 20:30:26 -0700295/* This function parses different IEs-tail IEs, beacon IEs, probe response IEs,
296 * association response IEs from cfg80211_ap_settings function and sets these IE
297 * to FW.
298 */
299int mwifiex_set_mgmt_ies(struct mwifiex_private *priv,
300 struct cfg80211_beacon_data *info)
301{
302 struct mwifiex_ie *gen_ie;
303 struct ieee_types_header *rsn_ie, *wpa_ie = NULL;
304 u16 rsn_idx = MWIFIEX_AUTO_IDX_MASK, ie_len = 0;
305 const u8 *vendor_ie;
306
307 if (info->tail && info->tail_len) {
308 gen_ie = kzalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
309 if (!gen_ie)
310 return -ENOMEM;
311 gen_ie->ie_index = cpu_to_le16(rsn_idx);
312 gen_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_BEACON |
313 MGMT_MASK_PROBE_RESP |
314 MGMT_MASK_ASSOC_RESP);
315
316 rsn_ie = (void *)cfg80211_find_ie(WLAN_EID_RSN,
317 info->tail, info->tail_len);
318 if (rsn_ie) {
319 memcpy(gen_ie->ie_buffer, rsn_ie, rsn_ie->len + 2);
320 ie_len = rsn_ie->len + 2;
321 gen_ie->ie_length = cpu_to_le16(ie_len);
322 }
323
324 vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
325 WLAN_OUI_TYPE_MICROSOFT_WPA,
326 info->tail,
327 info->tail_len);
328 if (vendor_ie) {
329 wpa_ie = (struct ieee_types_header *)vendor_ie;
330 memcpy(gen_ie->ie_buffer + ie_len,
331 wpa_ie, wpa_ie->len + 2);
332 ie_len += wpa_ie->len + 2;
333 gen_ie->ie_length = cpu_to_le16(ie_len);
334 }
335
336 if (rsn_ie || wpa_ie) {
337 if (mwifiex_update_uap_custom_ie(priv, gen_ie, &rsn_idx,
338 NULL, NULL,
339 NULL, NULL)) {
340 kfree(gen_ie);
341 return -1;
342 }
343 priv->rsn_idx = rsn_idx;
344 }
345
346 kfree(gen_ie);
347 }
348
349 return mwifiex_set_mgmt_beacon_data_ies(priv, info);
350}
351
Avinash Patil40bbc212012-05-08 18:30:30 -0700352/* This function removes management IE set */
353int mwifiex_del_mgmt_ies(struct mwifiex_private *priv)
354{
355 struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL;
356 struct mwifiex_ie *ar_ie = NULL, *rsn_ie = NULL;
357 int ret = 0;
358
359 if (priv->rsn_idx != MWIFIEX_AUTO_IDX_MASK) {
360 rsn_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
361 if (!rsn_ie)
362 return -ENOMEM;
363
364 rsn_ie->ie_index = cpu_to_le16(priv->rsn_idx);
365 rsn_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
366 rsn_ie->ie_length = 0;
367 if (mwifiex_update_uap_custom_ie(priv, rsn_ie, &priv->rsn_idx,
368 NULL, &priv->proberesp_idx,
369 NULL, &priv->assocresp_idx)) {
370 ret = -1;
371 goto done;
372 }
373
374 priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK;
375 }
376
377 if (priv->beacon_idx != MWIFIEX_AUTO_IDX_MASK) {
378 beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
379 if (!beacon_ie) {
380 ret = -ENOMEM;
381 goto done;
382 }
383 beacon_ie->ie_index = cpu_to_le16(priv->beacon_idx);
384 beacon_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
385 beacon_ie->ie_length = 0;
386 }
387 if (priv->proberesp_idx != MWIFIEX_AUTO_IDX_MASK) {
388 pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
389 if (!pr_ie) {
390 ret = -ENOMEM;
391 goto done;
392 }
393 pr_ie->ie_index = cpu_to_le16(priv->proberesp_idx);
394 pr_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
395 pr_ie->ie_length = 0;
396 }
397 if (priv->assocresp_idx != MWIFIEX_AUTO_IDX_MASK) {
398 ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
399 if (!ar_ie) {
400 ret = -ENOMEM;
401 goto done;
402 }
403 ar_ie->ie_index = cpu_to_le16(priv->assocresp_idx);
404 ar_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
405 ar_ie->ie_length = 0;
406 }
407
408 if (beacon_ie || pr_ie || ar_ie)
409 ret = mwifiex_update_uap_custom_ie(priv,
410 beacon_ie, &priv->beacon_idx,
411 pr_ie, &priv->proberesp_idx,
412 ar_ie, &priv->assocresp_idx);
413
414done:
415 kfree(beacon_ie);
416 kfree(pr_ie);
417 kfree(ar_ie);
418 kfree(rsn_ie);
419
420 return ret;
421}