blob: ceb82cd749cc7ba1ca2054ae0b675802d2194190 [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
216 return ret;
217}
218
219/* This function parses different IEs- Tail IEs, beacon IEs, probe response IEs,
220 * association response IEs from cfg80211_ap_settings function and sets these IE
221 * to FW.
222 */
223int mwifiex_set_mgmt_ies(struct mwifiex_private *priv,
224 struct cfg80211_ap_settings *params)
225{
226 struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL;
227 struct mwifiex_ie *ar_ie = NULL, *rsn_ie = NULL;
228 struct ieee_types_header *ie = NULL;
229 u16 beacon_idx = MWIFIEX_AUTO_IDX_MASK, pr_idx = MWIFIEX_AUTO_IDX_MASK;
230 u16 ar_idx = MWIFIEX_AUTO_IDX_MASK, rsn_idx = MWIFIEX_AUTO_IDX_MASK;
231 u16 mask;
232 int ret = 0;
233
234 if (params->beacon.tail && params->beacon.tail_len) {
235 ie = (void *)cfg80211_find_ie(WLAN_EID_RSN, params->beacon.tail,
236 params->beacon.tail_len);
237 if (ie) {
238 rsn_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
239 if (!rsn_ie)
240 return -ENOMEM;
241
242 rsn_ie->ie_index = cpu_to_le16(rsn_idx);
243 mask = MGMT_MASK_BEACON | MGMT_MASK_PROBE_RESP |
244 MGMT_MASK_ASSOC_RESP;
245 rsn_ie->mgmt_subtype_mask = cpu_to_le16(mask);
246 rsn_ie->ie_length = cpu_to_le16(ie->len + 2);
247 memcpy(rsn_ie->ie_buffer, ie, ie->len + 2);
248
249 if (mwifiex_update_uap_custom_ie(priv, rsn_ie, &rsn_idx,
250 NULL, NULL,
251 NULL, NULL)) {
252 ret = -1;
253 goto done;
254 }
255
256 priv->rsn_idx = rsn_idx;
257 }
258 }
259
260 if (params->beacon.beacon_ies && params->beacon.beacon_ies_len) {
261 beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
262 if (!beacon_ie) {
263 ret = -ENOMEM;
264 goto done;
265 }
266
267 beacon_ie->ie_index = cpu_to_le16(beacon_idx);
268 beacon_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_BEACON);
269 beacon_ie->ie_length =
270 cpu_to_le16(params->beacon.beacon_ies_len);
271 memcpy(beacon_ie->ie_buffer, params->beacon.beacon_ies,
272 params->beacon.beacon_ies_len);
273 }
274
275 if (params->beacon.proberesp_ies && params->beacon.proberesp_ies_len) {
276 pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
277 if (!pr_ie) {
278 ret = -ENOMEM;
279 goto done;
280 }
281
282 pr_ie->ie_index = cpu_to_le16(pr_idx);
283 pr_ie->mgmt_subtype_mask = cpu_to_le16(MGMT_MASK_PROBE_RESP);
284 pr_ie->ie_length =
285 cpu_to_le16(params->beacon.proberesp_ies_len);
286 memcpy(pr_ie->ie_buffer, params->beacon.proberesp_ies,
287 params->beacon.proberesp_ies_len);
288 }
289
290 if (params->beacon.assocresp_ies && params->beacon.assocresp_ies_len) {
291 ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
292 if (!ar_ie) {
293 ret = -ENOMEM;
294 goto done;
295 }
296
297 ar_ie->ie_index = cpu_to_le16(ar_idx);
298 mask = MGMT_MASK_ASSOC_RESP | MGMT_MASK_REASSOC_RESP;
299 ar_ie->mgmt_subtype_mask = cpu_to_le16(mask);
300 ar_ie->ie_length =
301 cpu_to_le16(params->beacon.assocresp_ies_len);
302 memcpy(ar_ie->ie_buffer, params->beacon.assocresp_ies,
303 params->beacon.assocresp_ies_len);
304 }
305
306 if (beacon_ie || pr_ie || ar_ie) {
307 ret = mwifiex_update_uap_custom_ie(priv, beacon_ie,
308 &beacon_idx, pr_ie,
309 &pr_idx, ar_ie, &ar_idx);
310 if (ret)
311 goto done;
312 }
313
314 priv->beacon_idx = beacon_idx;
315 priv->proberesp_idx = pr_idx;
316 priv->assocresp_idx = ar_idx;
317
318done:
319 kfree(beacon_ie);
320 kfree(pr_ie);
321 kfree(ar_ie);
322 kfree(rsn_ie);
323
324 return ret;
325}
Avinash Patil40bbc212012-05-08 18:30:30 -0700326
327/* This function removes management IE set */
328int mwifiex_del_mgmt_ies(struct mwifiex_private *priv)
329{
330 struct mwifiex_ie *beacon_ie = NULL, *pr_ie = NULL;
331 struct mwifiex_ie *ar_ie = NULL, *rsn_ie = NULL;
332 int ret = 0;
333
334 if (priv->rsn_idx != MWIFIEX_AUTO_IDX_MASK) {
335 rsn_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
336 if (!rsn_ie)
337 return -ENOMEM;
338
339 rsn_ie->ie_index = cpu_to_le16(priv->rsn_idx);
340 rsn_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
341 rsn_ie->ie_length = 0;
342 if (mwifiex_update_uap_custom_ie(priv, rsn_ie, &priv->rsn_idx,
343 NULL, &priv->proberesp_idx,
344 NULL, &priv->assocresp_idx)) {
345 ret = -1;
346 goto done;
347 }
348
349 priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK;
350 }
351
352 if (priv->beacon_idx != MWIFIEX_AUTO_IDX_MASK) {
353 beacon_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
354 if (!beacon_ie) {
355 ret = -ENOMEM;
356 goto done;
357 }
358 beacon_ie->ie_index = cpu_to_le16(priv->beacon_idx);
359 beacon_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
360 beacon_ie->ie_length = 0;
361 }
362 if (priv->proberesp_idx != MWIFIEX_AUTO_IDX_MASK) {
363 pr_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
364 if (!pr_ie) {
365 ret = -ENOMEM;
366 goto done;
367 }
368 pr_ie->ie_index = cpu_to_le16(priv->proberesp_idx);
369 pr_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
370 pr_ie->ie_length = 0;
371 }
372 if (priv->assocresp_idx != MWIFIEX_AUTO_IDX_MASK) {
373 ar_ie = kmalloc(sizeof(struct mwifiex_ie), GFP_KERNEL);
374 if (!ar_ie) {
375 ret = -ENOMEM;
376 goto done;
377 }
378 ar_ie->ie_index = cpu_to_le16(priv->assocresp_idx);
379 ar_ie->mgmt_subtype_mask = cpu_to_le16(MWIFIEX_DELETE_MASK);
380 ar_ie->ie_length = 0;
381 }
382
383 if (beacon_ie || pr_ie || ar_ie)
384 ret = mwifiex_update_uap_custom_ie(priv,
385 beacon_ie, &priv->beacon_idx,
386 pr_ie, &priv->proberesp_idx,
387 ar_ie, &priv->assocresp_idx);
388
389done:
390 kfree(beacon_ie);
391 kfree(pr_ie);
392 kfree(ar_ie);
393 kfree(rsn_ie);
394
395 return ret;
396}