[NET]: Introduce and use print_mac() and DECLARE_MAC_BUF()
[deliverable/linux.git] / drivers / net / wireless / libertas / wext.c
CommitLineData
876c9d3a
MT
1/**
2 * This file contains ioctl functions
3 */
4#include <linux/ctype.h>
5#include <linux/delay.h>
6#include <linux/if.h>
7#include <linux/if_arp.h>
8#include <linux/wireless.h>
9#include <linux/bitops.h>
10
11#include <net/ieee80211.h>
12#include <net/iw_handler.h>
13
14#include "host.h"
15#include "radiotap.h"
16#include "decl.h"
17#include "defs.h"
18#include "dev.h"
19#include "join.h"
876c9d3a
MT
20#include "wext.h"
21#include "assoc.h"
22
23
876c9d3a
MT
24/**
25 * @brief Find the channel frequency power info with specific channel
26 *
27 * @param adapter A pointer to wlan_adapter structure
28 * @param band it can be BAND_A, BAND_G or BAND_B
29 * @param channel the channel for looking
30 * @return A pointer to struct chan_freq_power structure or NULL if not find.
31 */
32struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * adapter,
33 u8 band, u16 channel)
34{
35 struct chan_freq_power *cfp = NULL;
36 struct region_channel *rc;
37 int count = sizeof(adapter->region_channel) /
38 sizeof(adapter->region_channel[0]);
39 int i, j;
40
41 for (j = 0; !cfp && (j < count); j++) {
42 rc = &adapter->region_channel[j];
43
44 if (adapter->enable11d)
45 rc = &adapter->universal_channel[j];
46 if (!rc->valid || !rc->CFP)
47 continue;
48 if (rc->band != band)
49 continue;
50 for (i = 0; i < rc->nrcfp; i++) {
51 if (rc->CFP[i].channel == channel) {
52 cfp = &rc->CFP[i];
53 break;
54 }
55 }
56 }
57
58 if (!cfp && channel)
9012b28a
HS
59 lbs_deb_wext("libertas_find_cfp_by_band_and_channel: can't find "
60 "cfp by band %d / channel %d\n", band, channel);
876c9d3a
MT
61
62 return cfp;
63}
64
65/**
66 * @brief Find the channel frequency power info with specific frequency
67 *
68 * @param adapter A pointer to wlan_adapter structure
69 * @param band it can be BAND_A, BAND_G or BAND_B
70 * @param freq the frequency for looking
71 * @return A pointer to struct chan_freq_power structure or NULL if not find.
72 */
73static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter,
74 u8 band, u32 freq)
75{
76 struct chan_freq_power *cfp = NULL;
77 struct region_channel *rc;
78 int count = sizeof(adapter->region_channel) /
79 sizeof(adapter->region_channel[0]);
80 int i, j;
81
82 for (j = 0; !cfp && (j < count); j++) {
83 rc = &adapter->region_channel[j];
84
85 if (adapter->enable11d)
86 rc = &adapter->universal_channel[j];
87 if (!rc->valid || !rc->CFP)
88 continue;
89 if (rc->band != band)
90 continue;
91 for (i = 0; i < rc->nrcfp; i++) {
92 if (rc->CFP[i].freq == freq) {
93 cfp = &rc->CFP[i];
94 break;
95 }
96 }
97 }
98
99 if (!cfp && freq)
9012b28a
HS
100 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
101 "band %d / freq %d\n", band, freq);
876c9d3a
MT
102
103 return cfp;
104}
105
876c9d3a
MT
106
107/**
108 * @brief Set Radio On/OFF
109 *
110 * @param priv A pointer to wlan_private structure
111 * @option Radio Option
112 * @return 0 --success, otherwise fail
113 */
ac558ca2 114static int wlan_radio_ioctl(wlan_private * priv, u8 option)
876c9d3a
MT
115{
116 int ret = 0;
117 wlan_adapter *adapter = priv->adapter;
118
9012b28a 119 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
120
121 if (adapter->radioon != option) {
9012b28a 122 lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
876c9d3a
MT
123 adapter->radioon = option;
124
125 ret = libertas_prepare_and_send_command(priv,
0aef64d7
DW
126 CMD_802_11_RADIO_CONTROL,
127 CMD_ACT_SET,
128 CMD_OPTION_WAITFORRSP, 0, NULL);
876c9d3a
MT
129 }
130
9012b28a 131 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
132 return ret;
133}
134
135/**
8c512765 136 * @brief Copy active data rates based on adapter mode and status
876c9d3a
MT
137 *
138 * @param adapter A pointer to wlan_adapter structure
139 * @param rate The buf to return the active rates
876c9d3a 140 */
8c512765 141static void copy_active_data_rates(wlan_adapter * adapter, u8 * rates)
876c9d3a 142{
9012b28a 143 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a 144
8c512765
DW
145 if (adapter->connect_status != LIBERTAS_CONNECTED)
146 memcpy(rates, libertas_bg_rates, MAX_RATES);
147 else
148 memcpy(rates, adapter->curbssparams.rates, MAX_RATES);
876c9d3a 149
8c512765 150 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
151}
152
153static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
154 char *cwrq, char *extra)
155{
876c9d3a 156
9012b28a 157 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a 158
9483f031
JT
159 /* We could add support for 802.11n here as needed. Jean II */
160 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
876c9d3a 161
9012b28a 162 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
163 return 0;
164}
165
166static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
167 struct iw_freq *fwrq, char *extra)
168{
169 wlan_private *priv = dev->priv;
170 wlan_adapter *adapter = priv->adapter;
171 struct chan_freq_power *cfp;
172
9012b28a 173 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
174
175 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
176 adapter->curbssparams.channel);
177
178 if (!cfp) {
179 if (adapter->curbssparams.channel)
9012b28a 180 lbs_deb_wext("invalid channel %d\n",
876c9d3a
MT
181 adapter->curbssparams.channel);
182 return -EINVAL;
183 }
184
185 fwrq->m = (long)cfp->freq * 100000;
186 fwrq->e = 1;
187
9012b28a
HS
188 lbs_deb_wext("freq %u\n", fwrq->m);
189 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
190 return 0;
191}
192
193static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
194 struct sockaddr *awrq, char *extra)
195{
196 wlan_private *priv = dev->priv;
197 wlan_adapter *adapter = priv->adapter;
198
9012b28a 199 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a 200
0aef64d7 201 if (adapter->connect_status == LIBERTAS_CONNECTED) {
876c9d3a
MT
202 memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
203 } else {
204 memset(awrq->sa_data, 0, ETH_ALEN);
205 }
206 awrq->sa_family = ARPHRD_ETHER;
207
9012b28a 208 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
209 return 0;
210}
211
212static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
213 struct iw_point *dwrq, char *extra)
214{
215 wlan_private *priv = dev->priv;
216 wlan_adapter *adapter = priv->adapter;
217
9012b28a 218 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
219
220 /*
221 * Check the size of the string
222 */
223
224 if (dwrq->length > 16) {
225 return -E2BIG;
226 }
227
228 mutex_lock(&adapter->lock);
229 memset(adapter->nodename, 0, sizeof(adapter->nodename));
230 memcpy(adapter->nodename, extra, dwrq->length);
231 mutex_unlock(&adapter->lock);
232
9012b28a 233 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
234 return 0;
235}
236
237static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
238 struct iw_point *dwrq, char *extra)
239{
9483f031
JT
240 const char *cp;
241 char comm[6] = { "COMM-" };
242 char mrvl[6] = { "MRVL-" };
243 int cnt;
876c9d3a 244
9012b28a 245 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
246
247 /*
9483f031
JT
248 * Nick Name is not used internally in this mode,
249 * therefore return something useful instead. Jean II
876c9d3a
MT
250 */
251
9483f031 252 strcpy(extra, mrvl);
876c9d3a 253
9483f031
JT
254 cp = strstr(libertas_driver_version, comm);
255 if (cp == libertas_driver_version) //skip leading "COMM-"
256 cp = libertas_driver_version + strlen(comm);
257 else
258 cp = libertas_driver_version;
876c9d3a 259
9483f031
JT
260 cnt = strlen(mrvl);
261 extra += cnt;
262 while (cnt < 16 && (*cp != '-')) {
263 *extra++ = toupper(*cp++);
264 cnt++;
265 }
876c9d3a
MT
266
267 /*
268 * Push it out !
269 */
9483f031 270 dwrq->length = cnt;
876c9d3a 271
9012b28a 272 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
273 return 0;
274}
275
f5e05b69
LCCR
276static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
277 struct iw_point *dwrq, char *extra)
278{
279 wlan_private *priv = dev->priv;
280 wlan_adapter *adapter = priv->adapter;
281
282 lbs_deb_enter(LBS_DEB_WEXT);
283
284 /* Use nickname to indicate that mesh is on */
285
0aef64d7 286 if (adapter->connect_status == LIBERTAS_CONNECTED) {
f5e05b69
LCCR
287 strncpy(extra, "Mesh", 12);
288 extra[12] = '\0';
9483f031 289 dwrq->length = strlen(extra);
f5e05b69
LCCR
290 }
291
292 else {
293 extra[0] = '\0';
9483f031 294 dwrq->length = 0;
f5e05b69
LCCR
295 }
296
297 lbs_deb_leave(LBS_DEB_WEXT);
298 return 0;
299}
876c9d3a
MT
300static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
301 struct iw_param *vwrq, char *extra)
302{
303 int ret = 0;
304 wlan_private *priv = dev->priv;
305 wlan_adapter *adapter = priv->adapter;
981f187b 306 u32 rthr = vwrq->value;
876c9d3a 307
9012b28a 308 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
309
310 if (vwrq->disabled) {
311 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
312 } else {
313 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
314 return -EINVAL;
315 adapter->rtsthsd = rthr;
316 }
317
0aef64d7
DW
318 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
319 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
876c9d3a
MT
320 OID_802_11_RTS_THRESHOLD, &rthr);
321
9012b28a 322 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
323 return ret;
324}
325
326static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
327 struct iw_param *vwrq, char *extra)
328{
329 int ret = 0;
330 wlan_private *priv = dev->priv;
331 wlan_adapter *adapter = priv->adapter;
332
9012b28a 333 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
334
335 adapter->rtsthsd = 0;
0aef64d7
DW
336 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
337 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
876c9d3a 338 OID_802_11_RTS_THRESHOLD, NULL);
9012b28a
HS
339 if (ret)
340 goto out;
876c9d3a
MT
341
342 vwrq->value = adapter->rtsthsd;
343 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
344 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
345 vwrq->fixed = 1;
346
9012b28a
HS
347out:
348 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
349 return ret;
876c9d3a
MT
350}
351
352static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
353 struct iw_param *vwrq, char *extra)
354{
355 int ret = 0;
981f187b 356 u32 fthr = vwrq->value;
876c9d3a
MT
357 wlan_private *priv = dev->priv;
358 wlan_adapter *adapter = priv->adapter;
359
9012b28a 360 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
361
362 if (vwrq->disabled) {
363 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
364 } else {
365 if (fthr < MRVDRV_FRAG_MIN_VALUE
366 || fthr > MRVDRV_FRAG_MAX_VALUE)
367 return -EINVAL;
368 adapter->fragthsd = fthr;
369 }
370
0aef64d7
DW
371 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
372 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
876c9d3a 373 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
9012b28a
HS
374
375 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
376 return ret;
377}
378
379static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
380 struct iw_param *vwrq, char *extra)
381{
382 int ret = 0;
383 wlan_private *priv = dev->priv;
384 wlan_adapter *adapter = priv->adapter;
385
9012b28a 386 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
387
388 adapter->fragthsd = 0;
389 ret = libertas_prepare_and_send_command(priv,
0aef64d7
DW
390 CMD_802_11_SNMP_MIB,
391 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
876c9d3a 392 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
9012b28a
HS
393 if (ret)
394 goto out;
876c9d3a
MT
395
396 vwrq->value = adapter->fragthsd;
397 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
398 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
399 vwrq->fixed = 1;
400
9012b28a
HS
401out:
402 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
403 return ret;
404}
405
406static int wlan_get_mode(struct net_device *dev,
407 struct iw_request_info *info, u32 * uwrq, char *extra)
408{
409 wlan_private *priv = dev->priv;
410 wlan_adapter *adapter = priv->adapter;
411
9012b28a 412 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a 413
0dc5a290 414 *uwrq = adapter->mode;
876c9d3a 415
9012b28a 416 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
417 return 0;
418}
419
f5e05b69
LCCR
420static int mesh_wlan_get_mode(struct net_device *dev,
421 struct iw_request_info *info, u32 * uwrq,
422 char *extra)
423{
424 lbs_deb_enter(LBS_DEB_WEXT);
425
426 *uwrq = IW_MODE_REPEAT ;
427
428 lbs_deb_leave(LBS_DEB_WEXT);
429 return 0;
430}
431
876c9d3a
MT
432static int wlan_get_txpow(struct net_device *dev,
433 struct iw_request_info *info,
434 struct iw_param *vwrq, char *extra)
435{
436 int ret = 0;
437 wlan_private *priv = dev->priv;
438 wlan_adapter *adapter = priv->adapter;
439
9012b28a 440 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
441
442 ret = libertas_prepare_and_send_command(priv,
0aef64d7
DW
443 CMD_802_11_RF_TX_POWER,
444 CMD_ACT_TX_POWER_OPT_GET,
445 CMD_OPTION_WAITFORRSP, 0, NULL);
876c9d3a 446
9012b28a
HS
447 if (ret)
448 goto out;
876c9d3a 449
9012b28a 450 lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
876c9d3a
MT
451 vwrq->value = adapter->txpowerlevel;
452 vwrq->fixed = 1;
453 if (adapter->radioon) {
454 vwrq->disabled = 0;
455 vwrq->flags = IW_TXPOW_DBM;
456 } else {
457 vwrq->disabled = 1;
458 }
459
9012b28a
HS
460out:
461 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
462 return ret;
876c9d3a
MT
463}
464
465static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
466 struct iw_param *vwrq, char *extra)
467{
468 int ret = 0;
469 wlan_private *priv = dev->priv;
470 wlan_adapter *adapter = priv->adapter;
471
9012b28a 472 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
473
474 if (vwrq->flags == IW_RETRY_LIMIT) {
475 /* The MAC has a 4-bit Total_Tx_Count register
476 Total_Tx_Count = 1 + Tx_Retry_Count */
477#define TX_RETRY_MIN 0
478#define TX_RETRY_MAX 14
479 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
480 return -EINVAL;
481
482 /* Adding 1 to convert retry count to try count */
483 adapter->txretrycount = vwrq->value + 1;
484
0aef64d7
DW
485 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
486 CMD_ACT_SET,
487 CMD_OPTION_WAITFORRSP,
876c9d3a
MT
488 OID_802_11_TX_RETRYCOUNT, NULL);
489
9012b28a
HS
490 if (ret)
491 goto out;
876c9d3a
MT
492 } else {
493 return -EOPNOTSUPP;
494 }
495
9012b28a
HS
496out:
497 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
498 return ret;
876c9d3a
MT
499}
500
501static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
502 struct iw_param *vwrq, char *extra)
503{
504 wlan_private *priv = dev->priv;
505 wlan_adapter *adapter = priv->adapter;
506 int ret = 0;
507
9012b28a
HS
508 lbs_deb_enter(LBS_DEB_WEXT);
509
876c9d3a
MT
510 adapter->txretrycount = 0;
511 ret = libertas_prepare_and_send_command(priv,
0aef64d7
DW
512 CMD_802_11_SNMP_MIB,
513 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
876c9d3a 514 OID_802_11_TX_RETRYCOUNT, NULL);
9012b28a
HS
515 if (ret)
516 goto out;
517
876c9d3a
MT
518 vwrq->disabled = 0;
519 if (!vwrq->flags) {
520 vwrq->flags = IW_RETRY_LIMIT;
521 /* Subtract 1 to convert try count to retry count */
522 vwrq->value = adapter->txretrycount - 1;
523 }
524
9012b28a
HS
525out:
526 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
527 return ret;
876c9d3a
MT
528}
529
530static inline void sort_channels(struct iw_freq *freq, int num)
531{
532 int i, j;
533 struct iw_freq temp;
534
535 for (i = 0; i < num; i++)
536 for (j = i + 1; j < num; j++)
537 if (freq[i].i > freq[j].i) {
538 temp.i = freq[i].i;
539 temp.m = freq[i].m;
540
541 freq[i].i = freq[j].i;
542 freq[i].m = freq[j].m;
543
544 freq[j].i = temp.i;
545 freq[j].m = temp.m;
546 }
547}
548
549/* data rate listing
550 MULTI_BANDS:
551 abg a b b/g
552 Infra G(12) A(8) B(4) G(12)
553 Adhoc A+B(12) A(8) B(4) B(4)
554
555 non-MULTI_BANDS:
556 b b/g
557 Infra B(4) G(12)
558 Adhoc B(4) B(4)
559 */
560/**
561 * @brief Get Range Info
562 *
563 * @param dev A pointer to net_device structure
564 * @param info A pointer to iw_request_info structure
565 * @param vwrq A pointer to iw_param structure
566 * @param extra A pointer to extra data buf
567 * @return 0 --success, otherwise fail
568 */
569static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
570 struct iw_point *dwrq, char *extra)
571{
572 int i, j;
573 wlan_private *priv = dev->priv;
574 wlan_adapter *adapter = priv->adapter;
575 struct iw_range *range = (struct iw_range *)extra;
576 struct chan_freq_power *cfp;
8c512765 577 u8 rates[MAX_RATES + 1];
876c9d3a
MT
578
579 u8 flag = 0;
580
9012b28a 581 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
582
583 dwrq->length = sizeof(struct iw_range);
584 memset(range, 0, sizeof(struct iw_range));
585
586 range->min_nwid = 0;
587 range->max_nwid = 0;
588
589 memset(rates, 0, sizeof(rates));
8c512765
DW
590 copy_active_data_rates(adapter, rates);
591 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
592 for (i = 0; i < range->num_bitrates; i++)
593 range->bitrate[i] = rates[i] * 500000;
876c9d3a 594 range->num_bitrates = i;
9012b28a 595 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
876c9d3a
MT
596 range->num_bitrates);
597
598 range->num_frequency = 0;
599 if (priv->adapter->enable11d &&
0aef64d7 600 adapter->connect_status == LIBERTAS_CONNECTED) {
876c9d3a
MT
601 u8 chan_no;
602 u8 band;
603
604 struct parsed_region_chan_11d *parsed_region_chan =
605 &adapter->parsed_region_chan;
606
607 if (parsed_region_chan == NULL) {
9012b28a
HS
608 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
609 goto out;
876c9d3a
MT
610 }
611 band = parsed_region_chan->band;
9012b28a 612 lbs_deb_wext("band %d, nr_char %d\n", band,
876c9d3a
MT
613 parsed_region_chan->nr_chan);
614
615 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
616 && (i < parsed_region_chan->nr_chan); i++) {
617 chan_no = parsed_region_chan->chanpwr[i].chan;
9012b28a 618 lbs_deb_wext("chan_no %d\n", chan_no);
876c9d3a
MT
619 range->freq[range->num_frequency].i = (long)chan_no;
620 range->freq[range->num_frequency].m =
621 (long)libertas_chan_2_freq(chan_no, band) * 100000;
622 range->freq[range->num_frequency].e = 1;
623 range->num_frequency++;
624 }
625 flag = 1;
626 }
627 if (!flag) {
628 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
629 && (j < sizeof(adapter->region_channel)
630 / sizeof(adapter->region_channel[0])); j++) {
631 cfp = adapter->region_channel[j].CFP;
632 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
633 && adapter->region_channel[j].valid
634 && cfp
635 && (i < adapter->region_channel[j].nrcfp); i++) {
636 range->freq[range->num_frequency].i =
637 (long)cfp->channel;
638 range->freq[range->num_frequency].m =
639 (long)cfp->freq * 100000;
640 range->freq[range->num_frequency].e = 1;
641 cfp++;
642 range->num_frequency++;
643 }
644 }
645 }
646
9012b28a 647 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
876c9d3a
MT
648 IW_MAX_FREQUENCIES, range->num_frequency);
649
650 range->num_channels = range->num_frequency;
651
652 sort_channels(&range->freq[0], range->num_frequency);
653
654 /*
655 * Set an indication of the max TCP throughput in bit/s that we can
656 * expect using this interface
657 */
658 if (i > 2)
659 range->throughput = 5000 * 1000;
660 else
661 range->throughput = 1500 * 1000;
662
663 range->min_rts = MRVDRV_RTS_MIN_VALUE;
664 range->max_rts = MRVDRV_RTS_MAX_VALUE;
665 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
666 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
667
668 range->encoding_size[0] = 5;
669 range->encoding_size[1] = 13;
670 range->num_encoding_sizes = 2;
671 range->max_encoding_tokens = 4;
672
673 range->min_pmp = 1000000;
674 range->max_pmp = 120000000;
675 range->min_pmt = 1000;
676 range->max_pmt = 1000000;
677 range->pmp_flags = IW_POWER_PERIOD;
678 range->pmt_flags = IW_POWER_TIMEOUT;
679 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
680
681 /*
682 * Minimum version we recommend
683 */
684 range->we_version_source = 15;
685
686 /*
687 * Version we are compiled with
688 */
689 range->we_version_compiled = WIRELESS_EXT;
690
691 range->retry_capa = IW_RETRY_LIMIT;
692 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
693
694 range->min_retry = TX_RETRY_MIN;
695 range->max_retry = TX_RETRY_MAX;
696
697 /*
698 * Set the qual, level and noise range values
699 */
700 range->max_qual.qual = 100;
701 range->max_qual.level = 0;
702 range->max_qual.noise = 0;
703 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
704
705 range->avg_qual.qual = 70;
706 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
707 range->avg_qual.level = 0;
708 range->avg_qual.noise = 0;
709 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
710
711 range->sensitivity = 0;
712
713 /*
714 * Setup the supported power level ranges
715 */
716 memset(range->txpower, 0, sizeof(range->txpower));
717 range->txpower[0] = 5;
718 range->txpower[1] = 7;
719 range->txpower[2] = 9;
720 range->txpower[3] = 11;
721 range->txpower[4] = 13;
722 range->txpower[5] = 15;
723 range->txpower[6] = 17;
724 range->txpower[7] = 19;
725
726 range->num_txpower = 8;
727 range->txpower_capa = IW_TXPOW_DBM;
728 range->txpower_capa |= IW_TXPOW_RANGE;
729
730 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
731 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
732 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
733 range->event_capa[1] = IW_EVENT_CAPA_K_1;
734
735 if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
736 range->enc_capa = IW_ENC_CAPA_WPA
737 | IW_ENC_CAPA_WPA2
738 | IW_ENC_CAPA_CIPHER_TKIP
739 | IW_ENC_CAPA_CIPHER_CCMP;
740 }
741
9012b28a
HS
742out:
743 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
744 return 0;
745}
746
747static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
748 struct iw_param *vwrq, char *extra)
749{
750 wlan_private *priv = dev->priv;
751 wlan_adapter *adapter = priv->adapter;
752
9012b28a 753 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
754
755 /* PS is currently supported only in Infrastructure mode
756 * Remove this check if it is to be supported in IBSS mode also
757 */
758
759 if (vwrq->disabled) {
0aef64d7 760 adapter->psmode = WLAN802_11POWERMODECAM;
876c9d3a 761 if (adapter->psstate != PS_STATE_FULL_POWER) {
0aef64d7 762 libertas_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
876c9d3a
MT
763 }
764
765 return 0;
766 }
767
768 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
9012b28a
HS
769 lbs_deb_wext(
770 "setting power timeout is not supported\n");
876c9d3a
MT
771 return -EINVAL;
772 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
9012b28a 773 lbs_deb_wext("setting power period not supported\n");
876c9d3a
MT
774 return -EINVAL;
775 }
776
0aef64d7 777 if (adapter->psmode != WLAN802_11POWERMODECAM) {
876c9d3a
MT
778 return 0;
779 }
780
0aef64d7 781 adapter->psmode = WLAN802_11POWERMODEMAX_PSP;
876c9d3a 782
0aef64d7
DW
783 if (adapter->connect_status == LIBERTAS_CONNECTED) {
784 libertas_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
876c9d3a
MT
785 }
786
9012b28a 787 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
788 return 0;
789}
790
791static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
792 struct iw_param *vwrq, char *extra)
793{
794 wlan_private *priv = dev->priv;
795 wlan_adapter *adapter = priv->adapter;
796 int mode;
797
9012b28a 798 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
799
800 mode = adapter->psmode;
801
0aef64d7
DW
802 if ((vwrq->disabled = (mode == WLAN802_11POWERMODECAM))
803 || adapter->connect_status == LIBERTAS_DISCONNECTED)
9012b28a
HS
804 {
805 goto out;
876c9d3a
MT
806 }
807
808 vwrq->value = 0;
809
9012b28a
HS
810out:
811 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
812 return 0;
813}
814
876c9d3a
MT
815static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
816{
817 enum {
818 POOR = 30,
819 FAIR = 60,
820 GOOD = 80,
821 VERY_GOOD = 90,
822 EXCELLENT = 95,
823 PERFECT = 100
824 };
825 wlan_private *priv = dev->priv;
826 wlan_adapter *adapter = priv->adapter;
827 u32 rssi_qual;
828 u32 tx_qual;
829 u32 quality = 0;
830 int stats_valid = 0;
831 u8 rssi;
832 u32 tx_retries;
833
9012b28a 834 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a 835
0dc5a290 836 priv->wstats.status = adapter->mode;
876c9d3a
MT
837
838 /* If we're not associated, all quality values are meaningless */
0aef64d7 839 if (adapter->connect_status != LIBERTAS_CONNECTED)
876c9d3a
MT
840 goto out;
841
842 /* Quality by RSSI */
843 priv->wstats.qual.level =
844 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
845 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
846
847 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
848 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
849 } else {
850 priv->wstats.qual.noise =
851 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
852 }
853
9012b28a
HS
854 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
855 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
876c9d3a
MT
856
857 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
858 if (rssi < 15)
859 rssi_qual = rssi * POOR / 10;
860 else if (rssi < 20)
861 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
862 else if (rssi < 30)
863 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
864 else if (rssi < 40)
865 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
866 10 + GOOD;
867 else
868 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
869 10 + VERY_GOOD;
870 quality = rssi_qual;
871
872 /* Quality by TX errors */
873 priv->wstats.discard.retries = priv->stats.tx_errors;
874
8362cd41 875 tx_retries = le32_to_cpu(adapter->logmsg.retry);
876c9d3a
MT
876
877 if (tx_retries > 75)
878 tx_qual = (90 - tx_retries) * POOR / 15;
879 else if (tx_retries > 70)
880 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
881 else if (tx_retries > 65)
882 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
883 else if (tx_retries > 50)
884 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
885 15 + GOOD;
886 else
887 tx_qual = (50 - tx_retries) *
888 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
889 quality = min(quality, tx_qual);
890
8362cd41
DW
891 priv->wstats.discard.code = le32_to_cpu(adapter->logmsg.wepundecryptable);
892 priv->wstats.discard.fragment = le32_to_cpu(adapter->logmsg.rxfrag);
876c9d3a 893 priv->wstats.discard.retries = tx_retries;
8362cd41 894 priv->wstats.discard.misc = le32_to_cpu(adapter->logmsg.ackfailure);
876c9d3a
MT
895
896 /* Calculate quality */
cad9d9b1 897 priv->wstats.qual.qual = min_t(u8, quality, 100);
876c9d3a
MT
898 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
899 stats_valid = 1;
900
901 /* update stats asynchronously for future calls */
0aef64d7 902 libertas_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
876c9d3a 903 0, 0, NULL);
0aef64d7 904 libertas_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
876c9d3a
MT
905 0, 0, NULL);
906out:
907 if (!stats_valid) {
908 priv->wstats.miss.beacon = 0;
909 priv->wstats.discard.retries = 0;
910 priv->wstats.qual.qual = 0;
911 priv->wstats.qual.level = 0;
912 priv->wstats.qual.noise = 0;
913 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
914 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
915 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
916 }
917
9012b28a 918 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
919 return &priv->wstats;
920
921
922}
923
924static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
925 struct iw_freq *fwrq, char *extra)
926{
ef9a264b 927 int ret = -EINVAL;
876c9d3a
MT
928 wlan_private *priv = dev->priv;
929 wlan_adapter *adapter = priv->adapter;
876c9d3a 930 struct chan_freq_power *cfp;
ef9a264b 931 struct assoc_request * assoc_req;
876c9d3a 932
9012b28a 933 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a 934
ef9a264b
DW
935 mutex_lock(&adapter->lock);
936 assoc_req = wlan_get_association_request(adapter);
937 if (!assoc_req) {
938 ret = -ENOMEM;
939 goto out;
940 }
876c9d3a 941
ef9a264b
DW
942 /* If setting by frequency, convert to a channel */
943 if (fwrq->e == 1) {
876c9d3a 944 long f = fwrq->m / 100000;
876c9d3a
MT
945
946 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
947 if (!cfp) {
9012b28a 948 lbs_deb_wext("invalid freq %ld\n", f);
ef9a264b 949 goto out;
876c9d3a
MT
950 }
951
876c9d3a 952 fwrq->e = 0;
ef9a264b 953 fwrq->m = (int) cfp->channel;
876c9d3a
MT
954 }
955
ef9a264b 956 /* Setting by channel number */
876c9d3a 957 if (fwrq->m > 1000 || fwrq->e > 0) {
ef9a264b
DW
958 goto out;
959 }
876c9d3a 960
ef9a264b
DW
961 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
962 if (!cfp) {
963 goto out;
876c9d3a
MT
964 }
965
ef9a264b
DW
966 assoc_req->channel = fwrq->m;
967 ret = 0;
968
9012b28a 969out:
ef9a264b
DW
970 if (ret == 0) {
971 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
972 wlan_postpone_association_work(priv);
973 } else {
974 wlan_cancel_association_work(priv);
975 }
976 mutex_unlock(&adapter->lock);
977
978 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
979 return ret;
876c9d3a
MT
980}
981
876c9d3a
MT
982static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
983 struct iw_param *vwrq, char *extra)
984{
985 wlan_private *priv = dev->priv;
986 wlan_adapter *adapter = priv->adapter;
8c512765 987 u32 new_rate;
876c9d3a 988 u16 action;
8c512765
DW
989 int ret = -EINVAL;
990 u8 rates[MAX_RATES + 1];
876c9d3a 991
9012b28a 992 lbs_deb_enter(LBS_DEB_WEXT);
9012b28a 993 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
876c9d3a 994
8c512765 995 /* Auto rate? */
876c9d3a 996 if (vwrq->value == -1) {
8c512765
DW
997 action = CMD_ACT_SET_TX_AUTO;
998 adapter->auto_rate = 1;
999 adapter->cur_rate = 0;
876c9d3a 1000 } else {
8c512765
DW
1001 if (vwrq->value % 100000)
1002 goto out;
876c9d3a
MT
1003
1004 memset(rates, 0, sizeof(rates));
8c512765
DW
1005 copy_active_data_rates(adapter, rates);
1006 new_rate = vwrq->value / 500000;
1007 if (!memchr(rates, new_rate, sizeof(rates))) {
1008 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1009 new_rate);
1010 goto out;
876c9d3a
MT
1011 }
1012
8c512765 1013 adapter->cur_rate = new_rate;
ffcae953 1014 action = CMD_ACT_SET_TX_FIX_RATE;
8c512765 1015 adapter->auto_rate = 0;
876c9d3a
MT
1016 }
1017
0aef64d7
DW
1018 ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
1019 action, CMD_OPTION_WAITFORRSP, 0, NULL);
876c9d3a 1020
8c512765 1021out:
9012b28a 1022 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
1023 return ret;
1024}
1025
1026static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
1027 struct iw_param *vwrq, char *extra)
1028{
1029 wlan_private *priv = dev->priv;
1030 wlan_adapter *adapter = priv->adapter;
1031
9012b28a 1032 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a 1033
8c512765
DW
1034 if (adapter->connect_status == LIBERTAS_CONNECTED) {
1035 vwrq->value = adapter->cur_rate * 500000;
1036
1037 if (adapter->auto_rate)
1038 vwrq->fixed = 0;
1039 else
1040 vwrq->fixed = 1;
1041
876c9d3a 1042 } else {
8c512765
DW
1043 vwrq->fixed = 0;
1044 vwrq->value = 0;
876c9d3a
MT
1045 }
1046
9012b28a 1047 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
1048 return 0;
1049}
1050
1051static int wlan_set_mode(struct net_device *dev,
1052 struct iw_request_info *info, u32 * uwrq, char *extra)
1053{
1054 int ret = 0;
1055 wlan_private *priv = dev->priv;
1056 wlan_adapter *adapter = priv->adapter;
1057 struct assoc_request * assoc_req;
876c9d3a 1058
9012b28a 1059 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a 1060
0dc5a290
DW
1061 if ( (*uwrq != IW_MODE_ADHOC)
1062 && (*uwrq != IW_MODE_INFRA)
1063 && (*uwrq != IW_MODE_AUTO)) {
9012b28a 1064 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
0dc5a290
DW
1065 ret = -EINVAL;
1066 goto out;
876c9d3a
MT
1067 }
1068
1069 mutex_lock(&adapter->lock);
1070 assoc_req = wlan_get_association_request(adapter);
1071 if (!assoc_req) {
1072 ret = -ENOMEM;
0dc5a290 1073 wlan_cancel_association_work(priv);
876c9d3a 1074 } else {
0dc5a290 1075 assoc_req->mode = *uwrq;
876c9d3a
MT
1076 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1077 wlan_postpone_association_work(priv);
9012b28a 1078 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
876c9d3a
MT
1079 }
1080 mutex_unlock(&adapter->lock);
1081
0dc5a290 1082out:
9012b28a 1083 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
1084 return ret;
1085}
1086
1087
1088/**
1089 * @brief Get Encryption key
1090 *
1091 * @param dev A pointer to net_device structure
1092 * @param info A pointer to iw_request_info structure
1093 * @param vwrq A pointer to iw_param structure
1094 * @param extra A pointer to extra data buf
1095 * @return 0 --success, otherwise fail
1096 */
1097static int wlan_get_encode(struct net_device *dev,
1098 struct iw_request_info *info,
1099 struct iw_point *dwrq, u8 * extra)
1100{
1101 wlan_private *priv = dev->priv;
1102 wlan_adapter *adapter = priv->adapter;
1103 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1104
9012b28a 1105 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a 1106
9012b28a 1107 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
876c9d3a
MT
1108 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1109
1110 dwrq->flags = 0;
1111
1112 /* Authentication method */
6affe785
DW
1113 switch (adapter->secinfo.auth_mode) {
1114 case IW_AUTH_ALG_OPEN_SYSTEM:
876c9d3a
MT
1115 dwrq->flags = IW_ENCODE_OPEN;
1116 break;
1117
6affe785
DW
1118 case IW_AUTH_ALG_SHARED_KEY:
1119 case IW_AUTH_ALG_LEAP:
876c9d3a
MT
1120 dwrq->flags = IW_ENCODE_RESTRICTED;
1121 break;
1122 default:
1123 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1124 break;
1125 }
1126
889c05bd
DW
1127 if ( adapter->secinfo.wep_enabled
1128 || adapter->secinfo.WPAenabled
1129 || adapter->secinfo.WPA2enabled) {
876c9d3a
MT
1130 dwrq->flags &= ~IW_ENCODE_DISABLED;
1131 } else {
1132 dwrq->flags |= IW_ENCODE_DISABLED;
1133 }
1134
1135 memset(extra, 0, 16);
1136
1137 mutex_lock(&adapter->lock);
1138
1139 /* Default to returning current transmit key */
1140 if (index < 0)
1141 index = adapter->wep_tx_keyidx;
1142
889c05bd 1143 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
876c9d3a
MT
1144 memcpy(extra, adapter->wep_keys[index].key,
1145 adapter->wep_keys[index].len);
1146 dwrq->length = adapter->wep_keys[index].len;
1147
1148 dwrq->flags |= (index + 1);
1149 /* Return WEP enabled */
1150 dwrq->flags &= ~IW_ENCODE_DISABLED;
1151 } else if ((adapter->secinfo.WPAenabled)
1152 || (adapter->secinfo.WPA2enabled)) {
1153 /* return WPA enabled */
1154 dwrq->flags &= ~IW_ENCODE_DISABLED;
1155 } else {
1156 dwrq->flags |= IW_ENCODE_DISABLED;
1157 }
1158
1159 mutex_unlock(&adapter->lock);
1160
1161 dwrq->flags |= IW_ENCODE_NOKEY;
1162
0795af57 1163 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
876c9d3a
MT
1164 extra[0], extra[1], extra[2],
1165 extra[3], extra[4], extra[5], dwrq->length);
1166
9012b28a 1167 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
876c9d3a 1168
9012b28a 1169 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
1170 return 0;
1171}
1172
1173/**
1174 * @brief Set Encryption key (internal)
1175 *
1176 * @param priv A pointer to private card structure
1177 * @param key_material A pointer to key material
1178 * @param key_length length of key material
1179 * @param index key index to set
1180 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1181 * @return 0 --success, otherwise fail
1182 */
1183static int wlan_set_wep_key(struct assoc_request *assoc_req,
1184 const char *key_material,
1185 u16 key_length,
1186 u16 index,
1187 int set_tx_key)
1188{
9012b28a 1189 int ret = 0;
1443b653 1190 struct enc_key *pkey;
876c9d3a 1191
9012b28a 1192 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1193
1194 /* Paranoid validation of key index */
1195 if (index > 3) {
9012b28a
HS
1196 ret = -EINVAL;
1197 goto out;
876c9d3a
MT
1198 }
1199
1200 /* validate max key length */
1201 if (key_length > KEY_LEN_WEP_104) {
9012b28a
HS
1202 ret = -EINVAL;
1203 goto out;
876c9d3a
MT
1204 }
1205
1206 pkey = &assoc_req->wep_keys[index];
1207
1208 if (key_length > 0) {
1443b653 1209 memset(pkey, 0, sizeof(struct enc_key));
876c9d3a
MT
1210 pkey->type = KEY_TYPE_ID_WEP;
1211
1212 /* Standardize the key length */
1213 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1214 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1215 memcpy(pkey->key, key_material, key_length);
1216 }
1217
1218 if (set_tx_key) {
1219 /* Ensure the chosen key is valid */
1220 if (!pkey->len) {
9012b28a
HS
1221 lbs_deb_wext("key not set, so cannot enable it\n");
1222 ret = -EINVAL;
1223 goto out;
876c9d3a
MT
1224 }
1225 assoc_req->wep_tx_keyidx = index;
1226 }
1227
889c05bd 1228 assoc_req->secinfo.wep_enabled = 1;
876c9d3a 1229
9012b28a
HS
1230out:
1231 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1232 return ret;
876c9d3a
MT
1233}
1234
1235static int validate_key_index(u16 def_index, u16 raw_index,
1236 u16 *out_index, u16 *is_default)
1237{
1238 if (!out_index || !is_default)
1239 return -EINVAL;
1240
1241 /* Verify index if present, otherwise use default TX key index */
1242 if (raw_index > 0) {
1243 if (raw_index > 4)
1244 return -EINVAL;
1245 *out_index = raw_index - 1;
1246 } else {
1247 *out_index = def_index;
1248 *is_default = 1;
1249 }
1250 return 0;
1251}
1252
1253static void disable_wep(struct assoc_request *assoc_req)
1254{
1255 int i;
1256
90a42210
DW
1257 lbs_deb_enter(LBS_DEB_WEXT);
1258
876c9d3a 1259 /* Set Open System auth mode */
6affe785 1260 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
876c9d3a
MT
1261
1262 /* Clear WEP keys and mark WEP as disabled */
889c05bd 1263 assoc_req->secinfo.wep_enabled = 0;
876c9d3a
MT
1264 for (i = 0; i < 4; i++)
1265 assoc_req->wep_keys[i].len = 0;
1266
1267 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1268 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
90a42210
DW
1269
1270 lbs_deb_leave(LBS_DEB_WEXT);
1271}
1272
1273static void disable_wpa(struct assoc_request *assoc_req)
1274{
1275 lbs_deb_enter(LBS_DEB_WEXT);
1276
1443b653 1277 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
90a42210
DW
1278 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1279 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1280
1443b653 1281 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
90a42210
DW
1282 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1283 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1284
1285 assoc_req->secinfo.WPAenabled = 0;
1286 assoc_req->secinfo.WPA2enabled = 0;
1287 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1288
1289 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
1290}
1291
1292/**
1293 * @brief Set Encryption key
1294 *
1295 * @param dev A pointer to net_device structure
1296 * @param info A pointer to iw_request_info structure
1297 * @param vwrq A pointer to iw_param structure
1298 * @param extra A pointer to extra data buf
1299 * @return 0 --success, otherwise fail
1300 */
1301static int wlan_set_encode(struct net_device *dev,
1302 struct iw_request_info *info,
1303 struct iw_point *dwrq, char *extra)
1304{
1305 int ret = 0;
1306 wlan_private *priv = dev->priv;
1307 wlan_adapter *adapter = priv->adapter;
1308 struct assoc_request * assoc_req;
1309 u16 is_default = 0, index = 0, set_tx_key = 0;
1310
9012b28a 1311 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1312
1313 mutex_lock(&adapter->lock);
1314 assoc_req = wlan_get_association_request(adapter);
1315 if (!assoc_req) {
1316 ret = -ENOMEM;
1317 goto out;
1318 }
1319
1320 if (dwrq->flags & IW_ENCODE_DISABLED) {
1321 disable_wep (assoc_req);
90a42210 1322 disable_wpa (assoc_req);
876c9d3a
MT
1323 goto out;
1324 }
1325
1326 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1327 (dwrq->flags & IW_ENCODE_INDEX),
1328 &index, &is_default);
1329 if (ret) {
1330 ret = -EINVAL;
1331 goto out;
1332 }
1333
1334 /* If WEP isn't enabled, or if there is no key data but a valid
1335 * index, set the TX key.
1336 */
889c05bd 1337 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
876c9d3a
MT
1338 set_tx_key = 1;
1339
1340 ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1341 if (ret)
1342 goto out;
1343
1344 if (dwrq->length)
1345 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1346 if (set_tx_key)
1347 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1348
1349 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
6affe785 1350 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
876c9d3a 1351 } else if (dwrq->flags & IW_ENCODE_OPEN) {
6affe785 1352 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
876c9d3a
MT
1353 }
1354
1355out:
1356 if (ret == 0) {
1357 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1358 wlan_postpone_association_work(priv);
1359 } else {
1360 wlan_cancel_association_work(priv);
1361 }
1362 mutex_unlock(&adapter->lock);
1363
9012b28a 1364 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
1365 return ret;
1366}
1367
1368/**
1369 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1370 *
1371 * @param dev A pointer to net_device structure
1372 * @param info A pointer to iw_request_info structure
1373 * @param vwrq A pointer to iw_param structure
1374 * @param extra A pointer to extra data buf
1375 * @return 0 on success, otherwise failure
1376 */
1377static int wlan_get_encodeext(struct net_device *dev,
1378 struct iw_request_info *info,
1379 struct iw_point *dwrq,
1380 char *extra)
1381{
1382 int ret = -EINVAL;
1383 wlan_private *priv = dev->priv;
1384 wlan_adapter *adapter = priv->adapter;
1385 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1386 int index, max_key_len;
1387
9012b28a 1388 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1389
1390 max_key_len = dwrq->length - sizeof(*ext);
1391 if (max_key_len < 0)
1392 goto out;
1393
1394 index = dwrq->flags & IW_ENCODE_INDEX;
1395 if (index) {
1396 if (index < 1 || index > 4)
1397 goto out;
1398 index--;
1399 } else {
1400 index = adapter->wep_tx_keyidx;
1401 }
1402
1403 if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
1404 ext->alg != IW_ENCODE_ALG_WEP) {
0dc5a290 1405 if (index != 0 || adapter->mode != IW_MODE_INFRA)
876c9d3a
MT
1406 goto out;
1407 }
1408
1409 dwrq->flags = index + 1;
1410 memset(ext, 0, sizeof(*ext));
1411
889c05bd
DW
1412 if ( !adapter->secinfo.wep_enabled
1413 && !adapter->secinfo.WPAenabled
1414 && !adapter->secinfo.WPA2enabled) {
876c9d3a
MT
1415 ext->alg = IW_ENCODE_ALG_NONE;
1416 ext->key_len = 0;
1417 dwrq->flags |= IW_ENCODE_DISABLED;
1418 } else {
1419 u8 *key = NULL;
1420
889c05bd 1421 if ( adapter->secinfo.wep_enabled
876c9d3a
MT
1422 && !adapter->secinfo.WPAenabled
1423 && !adapter->secinfo.WPA2enabled) {
90a42210 1424 /* WEP */
876c9d3a
MT
1425 ext->alg = IW_ENCODE_ALG_WEP;
1426 ext->key_len = adapter->wep_keys[index].len;
1427 key = &adapter->wep_keys[index].key[0];
889c05bd
DW
1428 } else if ( !adapter->secinfo.wep_enabled
1429 && (adapter->secinfo.WPAenabled ||
1430 adapter->secinfo.WPA2enabled)) {
876c9d3a 1431 /* WPA */
1443b653 1432 struct enc_key * pkey = NULL;
90a42210
DW
1433
1434 if ( adapter->wpa_mcast_key.len
1435 && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1436 pkey = &adapter->wpa_mcast_key;
1437 else if ( adapter->wpa_unicast_key.len
1438 && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1439 pkey = &adapter->wpa_unicast_key;
1440
1441 if (pkey) {
1442 if (pkey->type == KEY_TYPE_ID_AES) {
1443 ext->alg = IW_ENCODE_ALG_CCMP;
1444 } else {
1445 ext->alg = IW_ENCODE_ALG_TKIP;
1446 }
1447 ext->key_len = pkey->len;
1448 key = &pkey->key[0];
1449 } else {
1450 ext->alg = IW_ENCODE_ALG_TKIP;
1451 ext->key_len = 0;
1452 }
876c9d3a
MT
1453 } else {
1454 goto out;
1455 }
1456
1457 if (ext->key_len > max_key_len) {
1458 ret = -E2BIG;
1459 goto out;
1460 }
1461
1462 if (ext->key_len)
1463 memcpy(ext->key, key, ext->key_len);
1464 else
1465 dwrq->flags |= IW_ENCODE_NOKEY;
1466 dwrq->flags |= IW_ENCODE_ENABLED;
1467 }
1468 ret = 0;
1469
1470out:
9012b28a 1471 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
1472 return ret;
1473}
1474
1475/**
1476 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1477 *
1478 * @param dev A pointer to net_device structure
1479 * @param info A pointer to iw_request_info structure
1480 * @param vwrq A pointer to iw_param structure
1481 * @param extra A pointer to extra data buf
1482 * @return 0 --success, otherwise fail
1483 */
1484static int wlan_set_encodeext(struct net_device *dev,
1485 struct iw_request_info *info,
1486 struct iw_point *dwrq,
1487 char *extra)
1488{
1489 int ret = 0;
1490 wlan_private *priv = dev->priv;
1491 wlan_adapter *adapter = priv->adapter;
1492 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1493 int alg = ext->alg;
1494 struct assoc_request * assoc_req;
1495
9012b28a 1496 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1497
1498 mutex_lock(&adapter->lock);
1499 assoc_req = wlan_get_association_request(adapter);
1500 if (!assoc_req) {
1501 ret = -ENOMEM;
1502 goto out;
1503 }
1504
1505 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1506 disable_wep (assoc_req);
90a42210 1507 disable_wpa (assoc_req);
876c9d3a
MT
1508 } else if (alg == IW_ENCODE_ALG_WEP) {
1509 u16 is_default = 0, index, set_tx_key = 0;
1510
1511 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1512 (dwrq->flags & IW_ENCODE_INDEX),
1513 &index, &is_default);
1514 if (ret)
1515 goto out;
1516
1517 /* If WEP isn't enabled, or if there is no key data but a valid
1518 * index, or if the set-TX-key flag was passed, set the TX key.
1519 */
889c05bd 1520 if ( !assoc_req->secinfo.wep_enabled
876c9d3a
MT
1521 || (dwrq->length == 0 && !is_default)
1522 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1523 set_tx_key = 1;
1524
1525 /* Copy key to driver */
1526 ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
1527 set_tx_key);
1528 if (ret)
1529 goto out;
1530
1531 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
6affe785 1532 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
876c9d3a 1533 } else if (dwrq->flags & IW_ENCODE_OPEN) {
6affe785 1534 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
876c9d3a
MT
1535 }
1536
1537 /* Mark the various WEP bits as modified */
1538 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1539 if (dwrq->length)
1540 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1541 if (set_tx_key)
1542 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
876c9d3a 1543 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
1443b653 1544 struct enc_key * pkey;
876c9d3a
MT
1545
1546 /* validate key length */
1547 if (((alg == IW_ENCODE_ALG_TKIP)
1548 && (ext->key_len != KEY_LEN_WPA_TKIP))
1549 || ((alg == IW_ENCODE_ALG_CCMP)
1550 && (ext->key_len != KEY_LEN_WPA_AES))) {
9012b28a
HS
1551 lbs_deb_wext("invalid size %d for key of alg"
1552 "type %d\n",
876c9d3a
MT
1553 ext->key_len,
1554 alg);
1555 ret = -EINVAL;
1556 goto out;
1557 }
1558
90a42210 1559 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
876c9d3a 1560 pkey = &assoc_req->wpa_mcast_key;
90a42210
DW
1561 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1562 } else {
876c9d3a 1563 pkey = &assoc_req->wpa_unicast_key;
90a42210
DW
1564 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1565 }
876c9d3a 1566
1443b653 1567 memset(pkey, 0, sizeof (struct enc_key));
876c9d3a
MT
1568 memcpy(pkey->key, ext->key, ext->key_len);
1569 pkey->len = ext->key_len;
90a42210
DW
1570 if (pkey->len)
1571 pkey->flags |= KEY_INFO_WPA_ENABLED;
876c9d3a 1572
90a42210 1573 /* Do this after zeroing key structure */
876c9d3a
MT
1574 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1575 pkey->flags |= KEY_INFO_WPA_MCAST;
876c9d3a
MT
1576 } else {
1577 pkey->flags |= KEY_INFO_WPA_UNICAST;
876c9d3a
MT
1578 }
1579
90a42210 1580 if (alg == IW_ENCODE_ALG_TKIP) {
876c9d3a 1581 pkey->type = KEY_TYPE_ID_TKIP;
90a42210 1582 } else if (alg == IW_ENCODE_ALG_CCMP) {
876c9d3a 1583 pkey->type = KEY_TYPE_ID_AES;
90a42210 1584 }
876c9d3a
MT
1585
1586 /* If WPA isn't enabled yet, do that now */
1587 if ( assoc_req->secinfo.WPAenabled == 0
1588 && assoc_req->secinfo.WPA2enabled == 0) {
1589 assoc_req->secinfo.WPAenabled = 1;
1590 assoc_req->secinfo.WPA2enabled = 1;
1591 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1592 }
1593
1594 disable_wep (assoc_req);
1595 }
1596
1597out:
1598 if (ret == 0) {
1599 wlan_postpone_association_work(priv);
1600 } else {
1601 wlan_cancel_association_work(priv);
1602 }
1603 mutex_unlock(&adapter->lock);
1604
9012b28a 1605 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
1606 return ret;
1607}
1608
1609
1610static int wlan_set_genie(struct net_device *dev,
1611 struct iw_request_info *info,
1612 struct iw_point *dwrq,
1613 char *extra)
1614{
1615 wlan_private *priv = dev->priv;
1616 wlan_adapter *adapter = priv->adapter;
1617 int ret = 0;
1618 struct assoc_request * assoc_req;
1619
9012b28a 1620 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1621
1622 mutex_lock(&adapter->lock);
1623 assoc_req = wlan_get_association_request(adapter);
1624 if (!assoc_req) {
1625 ret = -ENOMEM;
1626 goto out;
1627 }
1628
1629 if (dwrq->length > MAX_WPA_IE_LEN ||
1630 (dwrq->length && extra == NULL)) {
1631 ret = -EINVAL;
1632 goto out;
1633 }
1634
1635 if (dwrq->length) {
1636 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1637 assoc_req->wpa_ie_len = dwrq->length;
1638 } else {
1639 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
1640 assoc_req->wpa_ie_len = 0;
1641 }
1642
1643out:
1644 if (ret == 0) {
1645 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1646 wlan_postpone_association_work(priv);
1647 } else {
1648 wlan_cancel_association_work(priv);
1649 }
1650 mutex_unlock(&adapter->lock);
1651
9012b28a 1652 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
1653 return ret;
1654}
1655
1656static int wlan_get_genie(struct net_device *dev,
1657 struct iw_request_info *info,
1658 struct iw_point *dwrq,
1659 char *extra)
1660{
9012b28a 1661 int ret = 0;
876c9d3a
MT
1662 wlan_private *priv = dev->priv;
1663 wlan_adapter *adapter = priv->adapter;
1664
9012b28a 1665 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1666
1667 if (adapter->wpa_ie_len == 0) {
1668 dwrq->length = 0;
9012b28a 1669 goto out;
876c9d3a
MT
1670 }
1671
1672 if (dwrq->length < adapter->wpa_ie_len) {
9012b28a
HS
1673 ret = -E2BIG;
1674 goto out;
876c9d3a
MT
1675 }
1676
1677 dwrq->length = adapter->wpa_ie_len;
1678 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
1679
9012b28a
HS
1680out:
1681 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1682 return ret;
876c9d3a
MT
1683}
1684
1685
1686static int wlan_set_auth(struct net_device *dev,
1687 struct iw_request_info *info,
1688 struct iw_param *dwrq,
1689 char *extra)
1690{
1691 wlan_private *priv = dev->priv;
1692 wlan_adapter *adapter = priv->adapter;
1693 struct assoc_request * assoc_req;
1694 int ret = 0;
1695 int updated = 0;
1696
9012b28a 1697 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1698
1699 mutex_lock(&adapter->lock);
1700 assoc_req = wlan_get_association_request(adapter);
1701 if (!assoc_req) {
1702 ret = -ENOMEM;
1703 goto out;
1704 }
1705
1706 switch (dwrq->flags & IW_AUTH_INDEX) {
1707 case IW_AUTH_TKIP_COUNTERMEASURES:
1708 case IW_AUTH_CIPHER_PAIRWISE:
1709 case IW_AUTH_CIPHER_GROUP:
1710 case IW_AUTH_KEY_MGMT:
90a42210 1711 case IW_AUTH_DROP_UNENCRYPTED:
876c9d3a
MT
1712 /*
1713 * libertas does not use these parameters
1714 */
1715 break;
1716
1717 case IW_AUTH_WPA_VERSION:
1718 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1719 assoc_req->secinfo.WPAenabled = 0;
1720 assoc_req->secinfo.WPA2enabled = 0;
90a42210 1721 disable_wpa (assoc_req);
876c9d3a
MT
1722 }
1723 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1724 assoc_req->secinfo.WPAenabled = 1;
889c05bd 1725 assoc_req->secinfo.wep_enabled = 0;
6affe785 1726 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
876c9d3a
MT
1727 }
1728 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1729 assoc_req->secinfo.WPA2enabled = 1;
889c05bd 1730 assoc_req->secinfo.wep_enabled = 0;
6affe785 1731 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
876c9d3a
MT
1732 }
1733 updated = 1;
1734 break;
1735
876c9d3a
MT
1736 case IW_AUTH_80211_AUTH_ALG:
1737 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
6affe785 1738 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
876c9d3a 1739 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
6affe785 1740 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
876c9d3a 1741 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
6affe785 1742 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
876c9d3a
MT
1743 } else {
1744 ret = -EINVAL;
1745 }
1746 updated = 1;
1747 break;
1748
1749 case IW_AUTH_WPA_ENABLED:
1750 if (dwrq->value) {
1751 if (!assoc_req->secinfo.WPAenabled &&
1752 !assoc_req->secinfo.WPA2enabled) {
1753 assoc_req->secinfo.WPAenabled = 1;
1754 assoc_req->secinfo.WPA2enabled = 1;
889c05bd 1755 assoc_req->secinfo.wep_enabled = 0;
6affe785 1756 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
876c9d3a
MT
1757 }
1758 } else {
1759 assoc_req->secinfo.WPAenabled = 0;
1760 assoc_req->secinfo.WPA2enabled = 0;
90a42210 1761 disable_wpa (assoc_req);
876c9d3a
MT
1762 }
1763 updated = 1;
1764 break;
1765
1766 default:
1767 ret = -EOPNOTSUPP;
1768 break;
1769 }
1770
1771out:
1772 if (ret == 0) {
1773 if (updated)
1774 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1775 wlan_postpone_association_work(priv);
1776 } else if (ret != -EOPNOTSUPP) {
1777 wlan_cancel_association_work(priv);
1778 }
1779 mutex_unlock(&adapter->lock);
1780
9012b28a 1781 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
1782 return ret;
1783}
1784
1785static int wlan_get_auth(struct net_device *dev,
1786 struct iw_request_info *info,
1787 struct iw_param *dwrq,
1788 char *extra)
1789{
9012b28a 1790 int ret = 0;
876c9d3a
MT
1791 wlan_private *priv = dev->priv;
1792 wlan_adapter *adapter = priv->adapter;
1793
9012b28a 1794 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1795
1796 switch (dwrq->flags & IW_AUTH_INDEX) {
1797 case IW_AUTH_WPA_VERSION:
1798 dwrq->value = 0;
1799 if (adapter->secinfo.WPAenabled)
1800 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1801 if (adapter->secinfo.WPA2enabled)
1802 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1803 if (!dwrq->value)
1804 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1805 break;
1806
876c9d3a 1807 case IW_AUTH_80211_AUTH_ALG:
6affe785 1808 dwrq->value = adapter->secinfo.auth_mode;
876c9d3a
MT
1809 break;
1810
1811 case IW_AUTH_WPA_ENABLED:
1812 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
1813 dwrq->value = 1;
1814 break;
1815
1816 default:
9012b28a 1817 ret = -EOPNOTSUPP;
876c9d3a
MT
1818 }
1819
9012b28a
HS
1820 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1821 return ret;
876c9d3a
MT
1822}
1823
1824
1825static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
1826 struct iw_param *vwrq, char *extra)
1827{
1828 int ret = 0;
1829 wlan_private *priv = dev->priv;
1830 wlan_adapter *adapter = priv->adapter;
1831
1832 u16 dbm;
1833
9012b28a 1834 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1835
1836 if (vwrq->disabled) {
1837 wlan_radio_ioctl(priv, RADIO_OFF);
1838 return 0;
1839 }
1840
0aef64d7 1841 adapter->preamble = CMD_TYPE_AUTO_PREAMBLE;
876c9d3a
MT
1842
1843 wlan_radio_ioctl(priv, RADIO_ON);
1844
9483f031
JT
1845 /* Userspace check in iwrange if it should use dBm or mW,
1846 * therefore this should never happen... Jean II */
876c9d3a 1847 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
9483f031 1848 return -EOPNOTSUPP;
876c9d3a
MT
1849 } else
1850 dbm = (u16) vwrq->value;
1851
1852 /* auto tx power control */
1853
1854 if (vwrq->fixed == 0)
1855 dbm = 0xffff;
1856
9012b28a 1857 lbs_deb_wext("txpower set %d dbm\n", dbm);
876c9d3a
MT
1858
1859 ret = libertas_prepare_and_send_command(priv,
0aef64d7
DW
1860 CMD_802_11_RF_TX_POWER,
1861 CMD_ACT_TX_POWER_OPT_SET_LOW,
1862 CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
876c9d3a 1863
9012b28a 1864 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
1865 return ret;
1866}
1867
1868static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
1869 struct iw_point *dwrq, char *extra)
1870{
1871 wlan_private *priv = dev->priv;
1872 wlan_adapter *adapter = priv->adapter;
1873
9012b28a
HS
1874 lbs_deb_enter(LBS_DEB_WEXT);
1875
876c9d3a
MT
1876 /*
1877 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1878 * the SSID list...
1879 */
1880
1881 /*
1882 * Get the current SSID
1883 */
0aef64d7 1884 if (adapter->connect_status == LIBERTAS_CONNECTED) {
d8efea25
DW
1885 memcpy(extra, adapter->curbssparams.ssid,
1886 adapter->curbssparams.ssid_len);
1887 extra[adapter->curbssparams.ssid_len] = '\0';
876c9d3a
MT
1888 } else {
1889 memset(extra, 0, 32);
d8efea25 1890 extra[adapter->curbssparams.ssid_len] = '\0';
876c9d3a
MT
1891 }
1892 /*
1893 * If none, we may want to get the one that was set
1894 */
1895
9483f031 1896 dwrq->length = adapter->curbssparams.ssid_len;
876c9d3a
MT
1897
1898 dwrq->flags = 1; /* active */
1899
9012b28a 1900 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
1901 return 0;
1902}
1903
1904static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
1905 struct iw_point *dwrq, char *extra)
1906{
1907 wlan_private *priv = dev->priv;
1908 wlan_adapter *adapter = priv->adapter;
1909 int ret = 0;
d8efea25
DW
1910 u8 ssid[IW_ESSID_MAX_SIZE];
1911 u8 ssid_len = 0;
876c9d3a 1912 struct assoc_request * assoc_req;
d8efea25 1913 int in_ssid_len = dwrq->length;
876c9d3a 1914
9012b28a 1915 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a 1916
876c9d3a 1917 /* Check the size of the string */
d8efea25 1918 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
876c9d3a
MT
1919 ret = -E2BIG;
1920 goto out;
1921 }
1922
d8efea25 1923 memset(&ssid, 0, sizeof(ssid));
876c9d3a 1924
d8efea25 1925 if (!dwrq->flags || !in_ssid_len) {
876c9d3a
MT
1926 /* "any" SSID requested; leave SSID blank */
1927 } else {
1928 /* Specific SSID requested */
d8efea25
DW
1929 memcpy(&ssid, extra, in_ssid_len);
1930 ssid_len = in_ssid_len;
876c9d3a
MT
1931 }
1932
d8efea25
DW
1933 if (!ssid_len) {
1934 lbs_deb_wext("requested any SSID\n");
1935 } else {
1936 lbs_deb_wext("requested SSID '%s'\n",
1937 escape_essid(ssid, ssid_len));
1938 }
876c9d3a
MT
1939
1940out:
1941 mutex_lock(&adapter->lock);
1942 if (ret == 0) {
1943 /* Get or create the current association request */
1944 assoc_req = wlan_get_association_request(adapter);
1945 if (!assoc_req) {
1946 ret = -ENOMEM;
1947 } else {
1948 /* Copy the SSID to the association request */
d8efea25
DW
1949 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1950 assoc_req->ssid_len = ssid_len;
876c9d3a
MT
1951 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
1952 wlan_postpone_association_work(priv);
1953 }
1954 }
1955
1956 /* Cancel the association request if there was an error */
1957 if (ret != 0) {
1958 wlan_cancel_association_work(priv);
1959 }
1960
1961 mutex_unlock(&adapter->lock);
1962
9012b28a 1963 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
876c9d3a
MT
1964 return ret;
1965}
1966
1967/**
1968 * @brief Connect to the AP or Ad-hoc Network with specific bssid
1969 *
1970 * @param dev A pointer to net_device structure
1971 * @param info A pointer to iw_request_info structure
1972 * @param awrq A pointer to iw_param structure
1973 * @param extra A pointer to extra data buf
1974 * @return 0 --success, otherwise fail
1975 */
1976static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
1977 struct sockaddr *awrq, char *extra)
1978{
1979 wlan_private *priv = dev->priv;
1980 wlan_adapter *adapter = priv->adapter;
1981 struct assoc_request * assoc_req;
1982 int ret = 0;
0795af57 1983 DECLARE_MAC_BUF(mac);
876c9d3a 1984
9012b28a 1985 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1986
1987 if (awrq->sa_family != ARPHRD_ETHER)
1988 return -EINVAL;
1989
0795af57 1990 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
876c9d3a
MT
1991
1992 mutex_lock(&adapter->lock);
1993
1994 /* Get or create the current association request */
1995 assoc_req = wlan_get_association_request(adapter);
1996 if (!assoc_req) {
1997 wlan_cancel_association_work(priv);
1998 ret = -ENOMEM;
1999 } else {
2000 /* Copy the BSSID to the association request */
2001 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2002 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2003 wlan_postpone_association_work(priv);
2004 }
2005
2006 mutex_unlock(&adapter->lock);
2007
2008 return ret;
2009}
2010
2011void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
2012{
876c9d3a
MT
2013 char fwver[32];
2014
2015 mutex_lock(&adapter->lock);
876c9d3a 2016
e5b3d472
DW
2017 if (adapter->fwreleasenumber[3] == 0)
2018 sprintf(fwver, "%u.%u.%u",
2019 adapter->fwreleasenumber[2],
2020 adapter->fwreleasenumber[1],
2021 adapter->fwreleasenumber[0]);
876c9d3a
MT
2022 else
2023 sprintf(fwver, "%u.%u.%u.p%u",
e5b3d472
DW
2024 adapter->fwreleasenumber[2],
2025 adapter->fwreleasenumber[1],
2026 adapter->fwreleasenumber[0],
2027 adapter->fwreleasenumber[3]);
876c9d3a 2028
e5b3d472 2029 mutex_unlock(&adapter->lock);
876c9d3a
MT
2030 snprintf(fwversion, maxlen, fwver);
2031}
2032
2033
2034/*
2035 * iwconfig settable callbacks
2036 */
2037static const iw_handler wlan_handler[] = {
2038 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2039 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2040 (iw_handler) NULL, /* SIOCSIWNWID */
2041 (iw_handler) NULL, /* SIOCGIWNWID */
2042 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2043 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2044 (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
2045 (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
2046 (iw_handler) NULL, /* SIOCSIWSENS */
2047 (iw_handler) NULL, /* SIOCGIWSENS */
2048 (iw_handler) NULL, /* SIOCSIWRANGE */
2049 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2050 (iw_handler) NULL, /* SIOCSIWPRIV */
2051 (iw_handler) NULL, /* SIOCGIWPRIV */
2052 (iw_handler) NULL, /* SIOCSIWSTATS */
2053 (iw_handler) NULL, /* SIOCGIWSTATS */
2054 iw_handler_set_spy, /* SIOCSIWSPY */
2055 iw_handler_get_spy, /* SIOCGIWSPY */
2056 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2057 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2058 (iw_handler) wlan_set_wap, /* SIOCSIWAP */
2059 (iw_handler) wlan_get_wap, /* SIOCGIWAP */
2060 (iw_handler) NULL, /* SIOCSIWMLME */
2061 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2062 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2063 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2064 (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
2065 (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
2066 (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
2067 (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
2068 (iw_handler) NULL, /* -- hole -- */
2069 (iw_handler) NULL, /* -- hole -- */
2070 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2071 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2072 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2073 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2074 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2075 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2076 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2077 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2078 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2079 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2080 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2081 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2082 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2083 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2084 (iw_handler) NULL, /* -- hole -- */
2085 (iw_handler) NULL, /* -- hole -- */
2086 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2087 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2088 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2089 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2090 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2091 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2092 (iw_handler) NULL, /* SIOCSIWPMKSA */
2093};
2094
f5e05b69
LCCR
2095static const iw_handler mesh_wlan_handler[] = {
2096 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2097 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2098 (iw_handler) NULL, /* SIOCSIWNWID */
2099 (iw_handler) NULL, /* SIOCGIWNWID */
2100 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2101 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2102 (iw_handler) NULL, /* SIOCSIWMODE */
2103 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2104 (iw_handler) NULL, /* SIOCSIWSENS */
2105 (iw_handler) NULL, /* SIOCGIWSENS */
2106 (iw_handler) NULL, /* SIOCSIWRANGE */
2107 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2108 (iw_handler) NULL, /* SIOCSIWPRIV */
2109 (iw_handler) NULL, /* SIOCGIWPRIV */
2110 (iw_handler) NULL, /* SIOCSIWSTATS */
2111 (iw_handler) NULL, /* SIOCGIWSTATS */
2112 iw_handler_set_spy, /* SIOCSIWSPY */
2113 iw_handler_get_spy, /* SIOCGIWSPY */
2114 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2115 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2116 (iw_handler) NULL, /* SIOCSIWAP */
2117 (iw_handler) NULL, /* SIOCGIWAP */
2118 (iw_handler) NULL, /* SIOCSIWMLME */
2119 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2120 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2121 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2122 (iw_handler) NULL, /* SIOCSIWESSID */
2123 (iw_handler) NULL, /* SIOCGIWESSID */
2124 (iw_handler) NULL, /* SIOCSIWNICKN */
2125 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2126 (iw_handler) NULL, /* -- hole -- */
2127 (iw_handler) NULL, /* -- hole -- */
2128 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2129 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2130 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2131 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2132 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2133 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2134 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2135 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2136 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2137 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2138 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2139 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2140 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2141 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2142 (iw_handler) NULL, /* -- hole -- */
2143 (iw_handler) NULL, /* -- hole -- */
2144 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2145 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2146 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2147 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2148 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2149 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2150 (iw_handler) NULL, /* SIOCSIWPMKSA */
2151};
876c9d3a 2152struct iw_handler_def libertas_handler_def = {
ff8ac609 2153 .num_standard = ARRAY_SIZE(wlan_handler),
876c9d3a 2154 .standard = (iw_handler *) wlan_handler,
876c9d3a
MT
2155 .get_wireless_stats = wlan_get_wireless_stats,
2156};
f5e05b69
LCCR
2157
2158struct iw_handler_def mesh_handler_def = {
ff8ac609 2159 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
f5e05b69 2160 .standard = (iw_handler *) mesh_wlan_handler,
f5e05b69
LCCR
2161 .get_wireless_stats = wlan_get_wireless_stats,
2162};
This page took 0.197604 seconds and 5 git commands to generate.