blob: 4a38fd8a5e1d0f1f4d3bc8344d00e719f0a9cb61 [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);
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 */
81static int
82mwifiex_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}
Avinash Patilf31acab2012-05-08 18:30:29 -0700150
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 */
155static int
156mwifiex_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
Avinash Patilc9015b22012-06-27 12:46:24 -0700216 kfree(ap_custom_ie);
Avinash Patilf31acab2012-05-08 18:30:29 -0700217 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 */
224int mwifiex_set_mgmt_ies(struct mwifiex_private *priv,
Avinash Patiladb6ed02012-06-28 20:30:25 -0700225 struct cfg80211_beacon_data *data)
Avinash Patilf31acab2012-05-08 18:30:29 -0700226{
227 struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL;
Avinash Patil0fd66be2012-06-15 12:21:52 -0700228 struct mwifiex_ie *ar_ie = NULL, *gen_ie = NULL;
229 struct ieee_types_header *rsn_ie = NULL, *wpa_ie = NULL;
Avinash Patilf31acab2012-05-08 18:30:29 -0700230 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;
Avinash Patil0fd66be2012-06-15 12:21:52 -0700232 u16 mask, ie_len = 0;
233 const u8 *vendor_ie;
Avinash Patilf31acab2012-05-08 18:30:29 -0700234 int ret = 0;
235
Avinash Patiladb6ed02012-06-28 20:30:25 -0700236 if (data->tail && data->tail_len) {
Avinash Patil0fd66be2012-06-15 12:21:52 -0700237 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);
Avinash Patilf31acab2012-05-08 18:30:29 -0700244
Avinash Patil0fd66be2012-06-15 12:21:52 -0700245 rsn_ie = (void *)cfg80211_find_ie(WLAN_EID_RSN,
Avinash Patiladb6ed02012-06-28 20:30:25 -0700246 data->tail, data->tail_len);
Avinash Patil0fd66be2012-06-15 12:21:52 -0700247 if (rsn_ie) {
248 memcpy(gen_ie->ie_buffer, rsn_ie, rsn_ie->len + 2);
249 ie_len = rsn_ie->len + 2;
250 gen_ie->ie_length = cpu_to_le16(ie_len);
251 }
Avinash Patilf31acab2012-05-08 18:30:29 -0700252
Avinash Patil0fd66be2012-06-15 12:21:52 -0700253 vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
254 WLAN_OUI_TYPE_MICROSOFT_WPA,
Avinash Patiladb6ed02012-06-28 20:30:25 -0700255 data->tail, data->tail_len);
Avinash Patil0fd66be2012-06-15 12:21:52 -0700256 if (vendor_ie) {
257 wpa_ie = (struct ieee_types_header *)vendor_ie;
258 memcpy(gen_ie->ie_buffer + ie_len,
259 wpa_ie, wpa_ie->len + 2);
260 ie_len += wpa_ie->len + 2;
261 gen_ie->ie_length = cpu_to_le16(ie_len);
262 }
263
264 if (rsn_ie || wpa_ie) {
265 if (mwifiex_update_uap_custom_ie(priv, gen_ie, &rsn_idx,
Avinash Patilf31acab2012-05-08 18:30:29 -0700266 NULL, NULL,
267 NULL, NULL)) {
268 ret = -1;
269 goto done;
270 }
271
272 priv->rsn_idx = rsn_idx;
273 }
274 }
275
Avinash Patiladb6ed02012-06-28 20:30:25 -0700276 if (data->beacon_ies && data->beacon_ies_len) {
Avinash Patilf31acab2012-05-08 18:30:29 -0700277 beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
278 if (!beacon_ie) {
279 ret = -ENOMEM;
280 goto done;
281 }
282
283 beacon_ie->ie_index = cpu_to_le16(beacon_idx);
284 beacon_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_BEACON);
Avinash Patiladb6ed02012-06-28 20:30:25 -0700285 beacon_ie->ie_length = cpu_to_le16(data->beacon_ies_len);
286 memcpy(beacon_ie->ie_buffer, data->beacon_ies,
287 data->beacon_ies_len);
Avinash Patilf31acab2012-05-08 18:30:29 -0700288 }
289
Avinash Patiladb6ed02012-06-28 20:30:25 -0700290 if (data->proberesp_ies && data->proberesp_ies_len) {
Avinash Patilf31acab2012-05-08 18:30:29 -0700291 pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
292 if (!pr_ie) {
293 ret = -ENOMEM;
294 goto done;
295 }
296
297 pr_ie->ie_index = cpu_to_le16(pr_idx);
298 pr_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_PROBE_RESP);
Avinash Patiladb6ed02012-06-28 20:30:25 -0700299 pr_ie->ie_length = cpu_to_le16(data->proberesp_ies_len);
300 memcpy(pr_ie->ie_buffer, data->proberesp_ies,
301 data->proberesp_ies_len);
Avinash Patilf31acab2012-05-08 18:30:29 -0700302 }
303
Avinash Patiladb6ed02012-06-28 20:30:25 -0700304 if (data->assocresp_ies && data->assocresp_ies_len) {
Avinash Patilf31acab2012-05-08 18:30:29 -0700305 ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
306 if (!ar_ie) {
307 ret = -ENOMEM;
308 goto done;
309 }
310
311 ar_ie->ie_index = cpu_to_le16(ar_idx);
312 mask = MGMT_MASK_ASSOC_RESP | MGMT_MASK_REASSOC_RESP;
313 ar_ie->mgmt_subtype_mask = cpu_to_le16(mask);
Avinash Patiladb6ed02012-06-28 20:30:25 -0700314 ar_ie->ie_length = cpu_to_le16(data->assocresp_ies_len);
315 memcpy(ar_ie->ie_buffer, data->assocresp_ies,
316 data->assocresp_ies_len);
Avinash Patilf31acab2012-05-08 18:30:29 -0700317 }
318
319 if (beacon_ie || pr_ie || ar_ie) {
320 ret = mwifiex_update_uap_custom_ie(priv, beacon_ie,
321 &beacon_idx, pr_ie,
322 &pr_idx, ar_ie, &ar_idx);
323 if (ret)
324 goto done;
325 }
326
327 priv->beacon_idx = beacon_idx;
328 priv->proberesp_idx = pr_idx;
329 priv->assocresp_idx = ar_idx;
330
331done:
332 kfree(beacon_ie);
333 kfree(pr_ie);
334 kfree(ar_ie);
Avinash Patil0fd66be2012-06-15 12:21:52 -0700335 kfree(gen_ie);
Avinash Patilf31acab2012-05-08 18:30:29 -0700336
337 return ret;
338}
Avinash Patil40bbc212012-05-08 18:30:30 -0700339
340/* This function removes management IE set */
341int mwifiex_del_mgmt_ies(struct mwifiex_private *priv)
342{
343 struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL;
344 struct mwifiex_ie *ar_ie = NULL, *rsn_ie = NULL;
345 int ret = 0;
346
347 if (priv->rsn_idx != MWIFIEX_AUTO_IDX_MASK) {
348 rsn_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
349 if (!rsn_ie)
350 return -ENOMEM;
351
352 rsn_ie->ie_index = cpu_to_le16(priv->rsn_idx);
353 rsn_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
354 rsn_ie->ie_length = 0;
355 if (mwifiex_update_uap_custom_ie(priv, rsn_ie, &priv->rsn_idx,
356 NULL, &priv->proberesp_idx,
357 NULL, &priv->assocresp_idx)) {
358 ret = -1;
359 goto done;
360 }
361
362 priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK;
363 }
364
365 if (priv->beacon_idx != MWIFIEX_AUTO_IDX_MASK) {
366 beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
367 if (!beacon_ie) {
368 ret = -ENOMEM;
369 goto done;
370 }
371 beacon_ie->ie_index = cpu_to_le16(priv->beacon_idx);
372 beacon_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
373 beacon_ie->ie_length = 0;
374 }
375 if (priv->proberesp_idx != MWIFIEX_AUTO_IDX_MASK) {
376 pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
377 if (!pr_ie) {
378 ret = -ENOMEM;
379 goto done;
380 }
381 pr_ie->ie_index = cpu_to_le16(priv->proberesp_idx);
382 pr_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
383 pr_ie->ie_length = 0;
384 }
385 if (priv->assocresp_idx != MWIFIEX_AUTO_IDX_MASK) {
386 ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
387 if (!ar_ie) {
388 ret = -ENOMEM;
389 goto done;
390 }
391 ar_ie->ie_index = cpu_to_le16(priv->assocresp_idx);
392 ar_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
393 ar_ie->ie_length = 0;
394 }
395
396 if (beacon_ie || pr_ie || ar_ie)
397 ret = mwifiex_update_uap_custom_ie(priv,
398 beacon_ie, &priv->beacon_idx,
399 pr_ie, &priv->proberesp_idx,
400 ar_ie, &priv->assocresp_idx);
401
402done:
403 kfree(beacon_ie);
404 kfree(pr_ie);
405 kfree(ar_ie);
406 kfree(rsn_ie);
407
408 return ret;
409}