blob: 1fb0f91e538a4ed0849c4ffda2b245bb11617e09 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
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"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020#include "wext.h"
21#include "assoc.h"
22
23
24/**
25 * @brief Convert mw value to dbm value
26 *
27 * @param mw the value of mw
28 * @return the value of dbm
29 */
30static int mw_to_dbm(int mw)
31{
32 if (mw < 2)
33 return 0;
34 else if (mw < 3)
35 return 3;
36 else if (mw < 4)
37 return 5;
38 else if (mw < 6)
39 return 7;
40 else if (mw < 7)
41 return 8;
42 else if (mw < 8)
43 return 9;
44 else if (mw < 10)
45 return 10;
46 else if (mw < 13)
47 return 11;
48 else if (mw < 16)
49 return 12;
50 else if (mw < 20)
51 return 13;
52 else if (mw < 25)
53 return 14;
54 else if (mw < 32)
55 return 15;
56 else if (mw < 40)
57 return 16;
58 else if (mw < 50)
59 return 17;
60 else if (mw < 63)
61 return 18;
62 else if (mw < 79)
63 return 19;
64 else if (mw < 100)
65 return 20;
66 else
67 return 21;
68}
69
70/**
71 * @brief Find the channel frequency power info with specific channel
72 *
73 * @param adapter A pointer to wlan_adapter structure
74 * @param band it can be BAND_A, BAND_G or BAND_B
75 * @param channel the channel for looking
76 * @return A pointer to struct chan_freq_power structure or NULL if not find.
77 */
78struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * adapter,
79 u8 band, u16 channel)
80{
81 struct chan_freq_power *cfp = NULL;
82 struct region_channel *rc;
83 int count = sizeof(adapter->region_channel) /
84 sizeof(adapter->region_channel[0]);
85 int i, j;
86
87 for (j = 0; !cfp && (j < count); j++) {
88 rc = &adapter->region_channel[j];
89
90 if (adapter->enable11d)
91 rc = &adapter->universal_channel[j];
92 if (!rc->valid || !rc->CFP)
93 continue;
94 if (rc->band != band)
95 continue;
96 for (i = 0; i < rc->nrcfp; i++) {
97 if (rc->CFP[i].channel == channel) {
98 cfp = &rc->CFP[i];
99 break;
100 }
101 }
102 }
103
104 if (!cfp && channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400105 lbs_deb_wext("libertas_find_cfp_by_band_and_channel: can't find "
106 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200107
108 return cfp;
109}
110
111/**
112 * @brief Find the channel frequency power info with specific frequency
113 *
114 * @param adapter A pointer to wlan_adapter structure
115 * @param band it can be BAND_A, BAND_G or BAND_B
116 * @param freq the frequency for looking
117 * @return A pointer to struct chan_freq_power structure or NULL if not find.
118 */
119static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter,
120 u8 band, u32 freq)
121{
122 struct chan_freq_power *cfp = NULL;
123 struct region_channel *rc;
124 int count = sizeof(adapter->region_channel) /
125 sizeof(adapter->region_channel[0]);
126 int i, j;
127
128 for (j = 0; !cfp && (j < count); j++) {
129 rc = &adapter->region_channel[j];
130
131 if (adapter->enable11d)
132 rc = &adapter->universal_channel[j];
133 if (!rc->valid || !rc->CFP)
134 continue;
135 if (rc->band != band)
136 continue;
137 for (i = 0; i < rc->nrcfp; i++) {
138 if (rc->CFP[i].freq == freq) {
139 cfp = &rc->CFP[i];
140 break;
141 }
142 }
143 }
144
145 if (!cfp && freq)
Holger Schurig9012b282007-05-25 11:27:16 -0400146 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
147 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148
149 return cfp;
150}
151
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152
153/**
154 * @brief Set Radio On/OFF
155 *
156 * @param priv A pointer to wlan_private structure
157 * @option Radio Option
158 * @return 0 --success, otherwise fail
159 */
Holger Schurigac558ca2007-08-02 11:49:06 -0400160static int wlan_radio_ioctl(wlan_private * priv, u8 option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161{
162 int ret = 0;
163 wlan_adapter *adapter = priv->adapter;
164
Holger Schurig9012b282007-05-25 11:27:16 -0400165 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200166
167 if (adapter->radioon != option) {
Holger Schurig9012b282007-05-25 11:27:16 -0400168 lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200169 adapter->radioon = option;
170
171 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400172 CMD_802_11_RADIO_CONTROL,
173 CMD_ACT_SET,
174 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200175 }
176
Holger Schurig9012b282007-05-25 11:27:16 -0400177 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200178 return ret;
179}
180
181/**
Dan Williams8c512762007-08-02 11:40:45 -0400182 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183 *
184 * @param adapter A pointer to wlan_adapter structure
185 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200186 */
Dan Williams8c512762007-08-02 11:40:45 -0400187static void copy_active_data_rates(wlan_adapter * adapter, u8 * rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200188{
Holger Schurig9012b282007-05-25 11:27:16 -0400189 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190
Dan Williams8c512762007-08-02 11:40:45 -0400191 if (adapter->connect_status != LIBERTAS_CONNECTED)
192 memcpy(rates, libertas_bg_rates, MAX_RATES);
193 else
194 memcpy(rates, adapter->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200195
Dan Williams8c512762007-08-02 11:40:45 -0400196 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200197}
198
199static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
200 char *cwrq, char *extra)
201{
202 const char *cp;
203 char comm[6] = { "COMM-" };
204 char mrvl[6] = { "MRVL-" };
205 int cnt;
206
Holger Schurig9012b282007-05-25 11:27:16 -0400207 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200208
209 strcpy(cwrq, mrvl);
210
211 cp = strstr(libertas_driver_version, comm);
212 if (cp == libertas_driver_version) //skip leading "COMM-"
213 cp = libertas_driver_version + strlen(comm);
214 else
215 cp = libertas_driver_version;
216
217 cnt = strlen(mrvl);
218 cwrq += cnt;
219 while (cnt < 16 && (*cp != '-')) {
220 *cwrq++ = toupper(*cp++);
221 cnt++;
222 }
223 *cwrq = '\0';
224
Holger Schurig9012b282007-05-25 11:27:16 -0400225 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226 return 0;
227}
228
229static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
230 struct iw_freq *fwrq, char *extra)
231{
232 wlan_private *priv = dev->priv;
233 wlan_adapter *adapter = priv->adapter;
234 struct chan_freq_power *cfp;
235
Holger Schurig9012b282007-05-25 11:27:16 -0400236 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200237
238 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
239 adapter->curbssparams.channel);
240
241 if (!cfp) {
242 if (adapter->curbssparams.channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400243 lbs_deb_wext("invalid channel %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244 adapter->curbssparams.channel);
245 return -EINVAL;
246 }
247
248 fwrq->m = (long)cfp->freq * 100000;
249 fwrq->e = 1;
250
Holger Schurig9012b282007-05-25 11:27:16 -0400251 lbs_deb_wext("freq %u\n", fwrq->m);
252 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200253 return 0;
254}
255
256static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
257 struct sockaddr *awrq, char *extra)
258{
259 wlan_private *priv = dev->priv;
260 wlan_adapter *adapter = priv->adapter;
261
Holger Schurig9012b282007-05-25 11:27:16 -0400262 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200263
Dan Williams0aef64d2007-08-02 11:31:18 -0400264 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265 memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
266 } else {
267 memset(awrq->sa_data, 0, ETH_ALEN);
268 }
269 awrq->sa_family = ARPHRD_ETHER;
270
Holger Schurig9012b282007-05-25 11:27:16 -0400271 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200272 return 0;
273}
274
275static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
276 struct iw_point *dwrq, char *extra)
277{
278 wlan_private *priv = dev->priv;
279 wlan_adapter *adapter = priv->adapter;
280
Holger Schurig9012b282007-05-25 11:27:16 -0400281 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200282
283 /*
284 * Check the size of the string
285 */
286
287 if (dwrq->length > 16) {
288 return -E2BIG;
289 }
290
291 mutex_lock(&adapter->lock);
292 memset(adapter->nodename, 0, sizeof(adapter->nodename));
293 memcpy(adapter->nodename, extra, dwrq->length);
294 mutex_unlock(&adapter->lock);
295
Holger Schurig9012b282007-05-25 11:27:16 -0400296 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297 return 0;
298}
299
300static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
301 struct iw_point *dwrq, char *extra)
302{
303 wlan_private *priv = dev->priv;
304 wlan_adapter *adapter = priv->adapter;
305
Holger Schurig9012b282007-05-25 11:27:16 -0400306 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307
308 /*
309 * Get the Nick Name saved
310 */
311
312 mutex_lock(&adapter->lock);
313 strncpy(extra, adapter->nodename, 16);
314 mutex_unlock(&adapter->lock);
315
316 extra[16] = '\0';
317
318 /*
319 * If none, we may want to get the one that was set
320 */
321
322 /*
323 * Push it out !
324 */
325 dwrq->length = strlen(extra) + 1;
326
Holger Schurig9012b282007-05-25 11:27:16 -0400327 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200328 return 0;
329}
330
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400331static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
332 struct iw_point *dwrq, char *extra)
333{
334 wlan_private *priv = dev->priv;
335 wlan_adapter *adapter = priv->adapter;
336
337 lbs_deb_enter(LBS_DEB_WEXT);
338
339 /* Use nickname to indicate that mesh is on */
340
Dan Williams0aef64d2007-08-02 11:31:18 -0400341 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400342 strncpy(extra, "Mesh", 12);
343 extra[12] = '\0';
344 dwrq->length = strlen(extra) + 1;
345 }
346
347 else {
348 extra[0] = '\0';
349 dwrq->length = 1 ;
350 }
351
352 lbs_deb_leave(LBS_DEB_WEXT);
353 return 0;
354}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200355static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
356 struct iw_param *vwrq, char *extra)
357{
358 int ret = 0;
359 wlan_private *priv = dev->priv;
360 wlan_adapter *adapter = priv->adapter;
David Woodhouse981f1872007-05-25 23:36:54 -0400361 u32 rthr = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200362
Holger Schurig9012b282007-05-25 11:27:16 -0400363 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364
365 if (vwrq->disabled) {
366 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
367 } else {
368 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
369 return -EINVAL;
370 adapter->rtsthsd = rthr;
371 }
372
Dan Williams0aef64d2007-08-02 11:31:18 -0400373 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
374 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200375 OID_802_11_RTS_THRESHOLD, &rthr);
376
Holger Schurig9012b282007-05-25 11:27:16 -0400377 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378 return ret;
379}
380
381static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
382 struct iw_param *vwrq, char *extra)
383{
384 int ret = 0;
385 wlan_private *priv = dev->priv;
386 wlan_adapter *adapter = priv->adapter;
387
Holger Schurig9012b282007-05-25 11:27:16 -0400388 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389
390 adapter->rtsthsd = 0;
Dan Williams0aef64d2007-08-02 11:31:18 -0400391 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
392 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200393 OID_802_11_RTS_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400394 if (ret)
395 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200396
397 vwrq->value = adapter->rtsthsd;
398 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
399 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
400 vwrq->fixed = 1;
401
Holger Schurig9012b282007-05-25 11:27:16 -0400402out:
403 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
404 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200405}
406
407static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
408 struct iw_param *vwrq, char *extra)
409{
410 int ret = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400411 u32 fthr = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200412 wlan_private *priv = dev->priv;
413 wlan_adapter *adapter = priv->adapter;
414
Holger Schurig9012b282007-05-25 11:27:16 -0400415 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200416
417 if (vwrq->disabled) {
418 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
419 } else {
420 if (fthr < MRVDRV_FRAG_MIN_VALUE
421 || fthr > MRVDRV_FRAG_MAX_VALUE)
422 return -EINVAL;
423 adapter->fragthsd = fthr;
424 }
425
Dan Williams0aef64d2007-08-02 11:31:18 -0400426 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
427 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200428 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
Holger Schurig9012b282007-05-25 11:27:16 -0400429
430 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431 return ret;
432}
433
434static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
435 struct iw_param *vwrq, char *extra)
436{
437 int ret = 0;
438 wlan_private *priv = dev->priv;
439 wlan_adapter *adapter = priv->adapter;
440
Holger Schurig9012b282007-05-25 11:27:16 -0400441 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200442
443 adapter->fragthsd = 0;
444 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400445 CMD_802_11_SNMP_MIB,
446 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200447 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400448 if (ret)
449 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200450
451 vwrq->value = adapter->fragthsd;
452 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
453 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
454 vwrq->fixed = 1;
455
Holger Schurig9012b282007-05-25 11:27:16 -0400456out:
457 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200458 return ret;
459}
460
461static int wlan_get_mode(struct net_device *dev,
462 struct iw_request_info *info, u32 * uwrq, char *extra)
463{
464 wlan_private *priv = dev->priv;
465 wlan_adapter *adapter = priv->adapter;
466
Holger Schurig9012b282007-05-25 11:27:16 -0400467 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468
Dan Williams0dc5a292007-05-10 22:58:02 -0400469 *uwrq = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470
Holger Schurig9012b282007-05-25 11:27:16 -0400471 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472 return 0;
473}
474
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400475static int mesh_wlan_get_mode(struct net_device *dev,
476 struct iw_request_info *info, u32 * uwrq,
477 char *extra)
478{
479 lbs_deb_enter(LBS_DEB_WEXT);
480
481 *uwrq = IW_MODE_REPEAT ;
482
483 lbs_deb_leave(LBS_DEB_WEXT);
484 return 0;
485}
486
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200487static int wlan_get_txpow(struct net_device *dev,
488 struct iw_request_info *info,
489 struct iw_param *vwrq, char *extra)
490{
491 int ret = 0;
492 wlan_private *priv = dev->priv;
493 wlan_adapter *adapter = priv->adapter;
494
Holger Schurig9012b282007-05-25 11:27:16 -0400495 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496
497 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400498 CMD_802_11_RF_TX_POWER,
499 CMD_ACT_TX_POWER_OPT_GET,
500 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501
Holger Schurig9012b282007-05-25 11:27:16 -0400502 if (ret)
503 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200504
Holger Schurig9012b282007-05-25 11:27:16 -0400505 lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200506 vwrq->value = adapter->txpowerlevel;
507 vwrq->fixed = 1;
508 if (adapter->radioon) {
509 vwrq->disabled = 0;
510 vwrq->flags = IW_TXPOW_DBM;
511 } else {
512 vwrq->disabled = 1;
513 }
514
Holger Schurig9012b282007-05-25 11:27:16 -0400515out:
516 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
517 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200518}
519
520static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
521 struct iw_param *vwrq, char *extra)
522{
523 int ret = 0;
524 wlan_private *priv = dev->priv;
525 wlan_adapter *adapter = priv->adapter;
526
Holger Schurig9012b282007-05-25 11:27:16 -0400527 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528
529 if (vwrq->flags == IW_RETRY_LIMIT) {
530 /* The MAC has a 4-bit Total_Tx_Count register
531 Total_Tx_Count = 1 + Tx_Retry_Count */
532#define TX_RETRY_MIN 0
533#define TX_RETRY_MAX 14
534 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
535 return -EINVAL;
536
537 /* Adding 1 to convert retry count to try count */
538 adapter->txretrycount = vwrq->value + 1;
539
Dan Williams0aef64d2007-08-02 11:31:18 -0400540 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
541 CMD_ACT_SET,
542 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200543 OID_802_11_TX_RETRYCOUNT, NULL);
544
Holger Schurig9012b282007-05-25 11:27:16 -0400545 if (ret)
546 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547 } else {
548 return -EOPNOTSUPP;
549 }
550
Holger Schurig9012b282007-05-25 11:27:16 -0400551out:
552 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
553 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200554}
555
556static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
557 struct iw_param *vwrq, char *extra)
558{
559 wlan_private *priv = dev->priv;
560 wlan_adapter *adapter = priv->adapter;
561 int ret = 0;
562
Holger Schurig9012b282007-05-25 11:27:16 -0400563 lbs_deb_enter(LBS_DEB_WEXT);
564
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200565 adapter->txretrycount = 0;
566 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400567 CMD_802_11_SNMP_MIB,
568 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200569 OID_802_11_TX_RETRYCOUNT, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400570 if (ret)
571 goto out;
572
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200573 vwrq->disabled = 0;
574 if (!vwrq->flags) {
575 vwrq->flags = IW_RETRY_LIMIT;
576 /* Subtract 1 to convert try count to retry count */
577 vwrq->value = adapter->txretrycount - 1;
578 }
579
Holger Schurig9012b282007-05-25 11:27:16 -0400580out:
581 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
582 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200583}
584
585static inline void sort_channels(struct iw_freq *freq, int num)
586{
587 int i, j;
588 struct iw_freq temp;
589
590 for (i = 0; i < num; i++)
591 for (j = i + 1; j < num; j++)
592 if (freq[i].i > freq[j].i) {
593 temp.i = freq[i].i;
594 temp.m = freq[i].m;
595
596 freq[i].i = freq[j].i;
597 freq[i].m = freq[j].m;
598
599 freq[j].i = temp.i;
600 freq[j].m = temp.m;
601 }
602}
603
604/* data rate listing
605 MULTI_BANDS:
606 abg a b b/g
607 Infra G(12) A(8) B(4) G(12)
608 Adhoc A+B(12) A(8) B(4) B(4)
609
610 non-MULTI_BANDS:
611 b b/g
612 Infra B(4) G(12)
613 Adhoc B(4) B(4)
614 */
615/**
616 * @brief Get Range Info
617 *
618 * @param dev A pointer to net_device structure
619 * @param info A pointer to iw_request_info structure
620 * @param vwrq A pointer to iw_param structure
621 * @param extra A pointer to extra data buf
622 * @return 0 --success, otherwise fail
623 */
624static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
625 struct iw_point *dwrq, char *extra)
626{
627 int i, j;
628 wlan_private *priv = dev->priv;
629 wlan_adapter *adapter = priv->adapter;
630 struct iw_range *range = (struct iw_range *)extra;
631 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400632 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633
634 u8 flag = 0;
635
Holger Schurig9012b282007-05-25 11:27:16 -0400636 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200637
638 dwrq->length = sizeof(struct iw_range);
639 memset(range, 0, sizeof(struct iw_range));
640
641 range->min_nwid = 0;
642 range->max_nwid = 0;
643
644 memset(rates, 0, sizeof(rates));
Dan Williams8c512762007-08-02 11:40:45 -0400645 copy_active_data_rates(adapter, rates);
646 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
647 for (i = 0; i < range->num_bitrates; i++)
648 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400650 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200651 range->num_bitrates);
652
653 range->num_frequency = 0;
654 if (priv->adapter->enable11d &&
Dan Williams0aef64d2007-08-02 11:31:18 -0400655 adapter->connect_status == LIBERTAS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200656 u8 chan_no;
657 u8 band;
658
659 struct parsed_region_chan_11d *parsed_region_chan =
660 &adapter->parsed_region_chan;
661
662 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400663 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
664 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200665 }
666 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400667 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200668 parsed_region_chan->nr_chan);
669
670 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
671 && (i < parsed_region_chan->nr_chan); i++) {
672 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400673 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200674 range->freq[range->num_frequency].i = (long)chan_no;
675 range->freq[range->num_frequency].m =
676 (long)libertas_chan_2_freq(chan_no, band) * 100000;
677 range->freq[range->num_frequency].e = 1;
678 range->num_frequency++;
679 }
680 flag = 1;
681 }
682 if (!flag) {
683 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
684 && (j < sizeof(adapter->region_channel)
685 / sizeof(adapter->region_channel[0])); j++) {
686 cfp = adapter->region_channel[j].CFP;
687 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
688 && adapter->region_channel[j].valid
689 && cfp
690 && (i < adapter->region_channel[j].nrcfp); i++) {
691 range->freq[range->num_frequency].i =
692 (long)cfp->channel;
693 range->freq[range->num_frequency].m =
694 (long)cfp->freq * 100000;
695 range->freq[range->num_frequency].e = 1;
696 cfp++;
697 range->num_frequency++;
698 }
699 }
700 }
701
Holger Schurig9012b282007-05-25 11:27:16 -0400702 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200703 IW_MAX_FREQUENCIES, range->num_frequency);
704
705 range->num_channels = range->num_frequency;
706
707 sort_channels(&range->freq[0], range->num_frequency);
708
709 /*
710 * Set an indication of the max TCP throughput in bit/s that we can
711 * expect using this interface
712 */
713 if (i > 2)
714 range->throughput = 5000 * 1000;
715 else
716 range->throughput = 1500 * 1000;
717
718 range->min_rts = MRVDRV_RTS_MIN_VALUE;
719 range->max_rts = MRVDRV_RTS_MAX_VALUE;
720 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
721 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
722
723 range->encoding_size[0] = 5;
724 range->encoding_size[1] = 13;
725 range->num_encoding_sizes = 2;
726 range->max_encoding_tokens = 4;
727
728 range->min_pmp = 1000000;
729 range->max_pmp = 120000000;
730 range->min_pmt = 1000;
731 range->max_pmt = 1000000;
732 range->pmp_flags = IW_POWER_PERIOD;
733 range->pmt_flags = IW_POWER_TIMEOUT;
734 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
735
736 /*
737 * Minimum version we recommend
738 */
739 range->we_version_source = 15;
740
741 /*
742 * Version we are compiled with
743 */
744 range->we_version_compiled = WIRELESS_EXT;
745
746 range->retry_capa = IW_RETRY_LIMIT;
747 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
748
749 range->min_retry = TX_RETRY_MIN;
750 range->max_retry = TX_RETRY_MAX;
751
752 /*
753 * Set the qual, level and noise range values
754 */
755 range->max_qual.qual = 100;
756 range->max_qual.level = 0;
757 range->max_qual.noise = 0;
758 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
759
760 range->avg_qual.qual = 70;
761 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
762 range->avg_qual.level = 0;
763 range->avg_qual.noise = 0;
764 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
765
766 range->sensitivity = 0;
767
768 /*
769 * Setup the supported power level ranges
770 */
771 memset(range->txpower, 0, sizeof(range->txpower));
772 range->txpower[0] = 5;
773 range->txpower[1] = 7;
774 range->txpower[2] = 9;
775 range->txpower[3] = 11;
776 range->txpower[4] = 13;
777 range->txpower[5] = 15;
778 range->txpower[6] = 17;
779 range->txpower[7] = 19;
780
781 range->num_txpower = 8;
782 range->txpower_capa = IW_TXPOW_DBM;
783 range->txpower_capa |= IW_TXPOW_RANGE;
784
785 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
786 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
787 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
788 range->event_capa[1] = IW_EVENT_CAPA_K_1;
789
790 if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
791 range->enc_capa = IW_ENC_CAPA_WPA
792 | IW_ENC_CAPA_WPA2
793 | IW_ENC_CAPA_CIPHER_TKIP
794 | IW_ENC_CAPA_CIPHER_CCMP;
795 }
796
Holger Schurig9012b282007-05-25 11:27:16 -0400797out:
798 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200799 return 0;
800}
801
802static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
803 struct iw_param *vwrq, char *extra)
804{
805 wlan_private *priv = dev->priv;
806 wlan_adapter *adapter = priv->adapter;
807
Holger Schurig9012b282007-05-25 11:27:16 -0400808 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200809
810 /* PS is currently supported only in Infrastructure mode
811 * Remove this check if it is to be supported in IBSS mode also
812 */
813
814 if (vwrq->disabled) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400815 adapter->psmode = WLAN802_11POWERMODECAM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200816 if (adapter->psstate != PS_STATE_FULL_POWER) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400817 libertas_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200818 }
819
820 return 0;
821 }
822
823 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400824 lbs_deb_wext(
825 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200826 return -EINVAL;
827 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400828 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200829 return -EINVAL;
830 }
831
Dan Williams0aef64d2007-08-02 11:31:18 -0400832 if (adapter->psmode != WLAN802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200833 return 0;
834 }
835
Dan Williams0aef64d2007-08-02 11:31:18 -0400836 adapter->psmode = WLAN802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200837
Dan Williams0aef64d2007-08-02 11:31:18 -0400838 if (adapter->connect_status == LIBERTAS_CONNECTED) {
839 libertas_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200840 }
841
Holger Schurig9012b282007-05-25 11:27:16 -0400842 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200843 return 0;
844}
845
846static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
847 struct iw_param *vwrq, char *extra)
848{
849 wlan_private *priv = dev->priv;
850 wlan_adapter *adapter = priv->adapter;
851 int mode;
852
Holger Schurig9012b282007-05-25 11:27:16 -0400853 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200854
855 mode = adapter->psmode;
856
Dan Williams0aef64d2007-08-02 11:31:18 -0400857 if ((vwrq->disabled = (mode == WLAN802_11POWERMODECAM))
858 || adapter->connect_status == LIBERTAS_DISCONNECTED)
Holger Schurig9012b282007-05-25 11:27:16 -0400859 {
860 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200861 }
862
863 vwrq->value = 0;
864
Holger Schurig9012b282007-05-25 11:27:16 -0400865out:
866 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200867 return 0;
868}
869
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200870static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
871{
872 enum {
873 POOR = 30,
874 FAIR = 60,
875 GOOD = 80,
876 VERY_GOOD = 90,
877 EXCELLENT = 95,
878 PERFECT = 100
879 };
880 wlan_private *priv = dev->priv;
881 wlan_adapter *adapter = priv->adapter;
882 u32 rssi_qual;
883 u32 tx_qual;
884 u32 quality = 0;
885 int stats_valid = 0;
886 u8 rssi;
887 u32 tx_retries;
888
Holger Schurig9012b282007-05-25 11:27:16 -0400889 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200890
Dan Williams0dc5a292007-05-10 22:58:02 -0400891 priv->wstats.status = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200892
893 /* If we're not associated, all quality values are meaningless */
Dan Williams0aef64d2007-08-02 11:31:18 -0400894 if (adapter->connect_status != LIBERTAS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200895 goto out;
896
897 /* Quality by RSSI */
898 priv->wstats.qual.level =
899 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
900 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
901
902 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
903 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
904 } else {
905 priv->wstats.qual.noise =
906 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
907 }
908
Holger Schurig9012b282007-05-25 11:27:16 -0400909 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
910 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200911
912 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
913 if (rssi < 15)
914 rssi_qual = rssi * POOR / 10;
915 else if (rssi < 20)
916 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
917 else if (rssi < 30)
918 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
919 else if (rssi < 40)
920 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
921 10 + GOOD;
922 else
923 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
924 10 + VERY_GOOD;
925 quality = rssi_qual;
926
927 /* Quality by TX errors */
928 priv->wstats.discard.retries = priv->stats.tx_errors;
929
David Woodhouse981f1872007-05-25 23:36:54 -0400930 tx_retries = le16_to_cpu(adapter->logmsg.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200931
932 if (tx_retries > 75)
933 tx_qual = (90 - tx_retries) * POOR / 15;
934 else if (tx_retries > 70)
935 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
936 else if (tx_retries > 65)
937 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
938 else if (tx_retries > 50)
939 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
940 15 + GOOD;
941 else
942 tx_qual = (50 - tx_retries) *
943 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
944 quality = min(quality, tx_qual);
945
David Woodhouse981f1872007-05-25 23:36:54 -0400946 priv->wstats.discard.code = le16_to_cpu(adapter->logmsg.wepundecryptable);
947 priv->wstats.discard.fragment = le16_to_cpu(adapter->logmsg.rxfrag);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200948 priv->wstats.discard.retries = tx_retries;
David Woodhouse981f1872007-05-25 23:36:54 -0400949 priv->wstats.discard.misc = le16_to_cpu(adapter->logmsg.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200950
951 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400952 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200953 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
954 stats_valid = 1;
955
956 /* update stats asynchronously for future calls */
Dan Williams0aef64d2007-08-02 11:31:18 -0400957 libertas_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200958 0, 0, NULL);
Dan Williams0aef64d2007-08-02 11:31:18 -0400959 libertas_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200960 0, 0, NULL);
961out:
962 if (!stats_valid) {
963 priv->wstats.miss.beacon = 0;
964 priv->wstats.discard.retries = 0;
965 priv->wstats.qual.qual = 0;
966 priv->wstats.qual.level = 0;
967 priv->wstats.qual.noise = 0;
968 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
969 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
970 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
971 }
972
Holger Schurig9012b282007-05-25 11:27:16 -0400973 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200974 return &priv->wstats;
975
976
977}
978
979static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
980 struct iw_freq *fwrq, char *extra)
981{
Dan Williamsef9a2642007-05-25 16:46:33 -0400982 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200983 wlan_private *priv = dev->priv;
984 wlan_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200985 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400986 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200987
Holger Schurig9012b282007-05-25 11:27:16 -0400988 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200989
Dan Williamsef9a2642007-05-25 16:46:33 -0400990 mutex_lock(&adapter->lock);
991 assoc_req = wlan_get_association_request(adapter);
992 if (!assoc_req) {
993 ret = -ENOMEM;
994 goto out;
995 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200996
Dan Williamsef9a2642007-05-25 16:46:33 -0400997 /* If setting by frequency, convert to a channel */
998 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200999 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001000
1001 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
1002 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -04001003 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -04001004 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001005 }
1006
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001007 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -04001008 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001009 }
1010
Dan Williamsef9a2642007-05-25 16:46:33 -04001011 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001012 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -04001013 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001014 }
1015
Dan Williamsef9a2642007-05-25 16:46:33 -04001016 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
1017 if (!cfp) {
1018 goto out;
1019 }
1020
1021 assoc_req->channel = fwrq->m;
1022 ret = 0;
1023
Holger Schurig9012b282007-05-25 11:27:16 -04001024out:
Dan Williamsef9a2642007-05-25 16:46:33 -04001025 if (ret == 0) {
1026 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
1027 wlan_postpone_association_work(priv);
1028 } else {
1029 wlan_cancel_association_work(priv);
1030 }
1031 mutex_unlock(&adapter->lock);
1032
1033 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1034 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001035}
1036
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
1038 struct iw_param *vwrq, char *extra)
1039{
1040 wlan_private *priv = dev->priv;
1041 wlan_adapter *adapter = priv->adapter;
Dan Williams8c512762007-08-02 11:40:45 -04001042 u32 new_rate;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001043 u16 action;
Dan Williams8c512762007-08-02 11:40:45 -04001044 int ret = -EINVAL;
1045 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001046
Holger Schurig9012b282007-05-25 11:27:16 -04001047 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -04001048 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001049
Dan Williams8c512762007-08-02 11:40:45 -04001050 /* Auto rate? */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001051 if (vwrq->value == -1) {
Dan Williams8c512762007-08-02 11:40:45 -04001052 action = CMD_ACT_SET_TX_AUTO;
1053 adapter->auto_rate = 1;
1054 adapter->cur_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001055 } else {
Dan Williams8c512762007-08-02 11:40:45 -04001056 if (vwrq->value % 100000)
1057 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001058
1059 memset(rates, 0, sizeof(rates));
Dan Williams8c512762007-08-02 11:40:45 -04001060 copy_active_data_rates(adapter, rates);
1061 new_rate = vwrq->value / 500000;
1062 if (!memchr(rates, new_rate, sizeof(rates))) {
1063 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1064 new_rate);
1065 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001066 }
1067
Dan Williams8c512762007-08-02 11:40:45 -04001068 adapter->cur_rate = new_rate;
Dan Williamsffcae952007-08-02 11:35:46 -04001069 action = CMD_ACT_SET_TX_FIX_RATE;
Dan Williams8c512762007-08-02 11:40:45 -04001070 adapter->auto_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001071 }
1072
Dan Williams0aef64d2007-08-02 11:31:18 -04001073 ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
1074 action, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001075
Dan Williams8c512762007-08-02 11:40:45 -04001076out:
Holger Schurig9012b282007-05-25 11:27:16 -04001077 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001078 return ret;
1079}
1080
1081static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
1082 struct iw_param *vwrq, char *extra)
1083{
1084 wlan_private *priv = dev->priv;
1085 wlan_adapter *adapter = priv->adapter;
1086
Holger Schurig9012b282007-05-25 11:27:16 -04001087 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001088
Dan Williams8c512762007-08-02 11:40:45 -04001089 if (adapter->connect_status == LIBERTAS_CONNECTED) {
1090 vwrq->value = adapter->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001091
Dan Williams8c512762007-08-02 11:40:45 -04001092 if (adapter->auto_rate)
1093 vwrq->fixed = 0;
1094 else
1095 vwrq->fixed = 1;
1096
1097 } else {
1098 vwrq->fixed = 0;
1099 vwrq->value = 0;
1100 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001101
Holger Schurig9012b282007-05-25 11:27:16 -04001102 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001103 return 0;
1104}
1105
1106static int wlan_set_mode(struct net_device *dev,
1107 struct iw_request_info *info, u32 * uwrq, char *extra)
1108{
1109 int ret = 0;
1110 wlan_private *priv = dev->priv;
1111 wlan_adapter *adapter = priv->adapter;
1112 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001113
Holger Schurig9012b282007-05-25 11:27:16 -04001114 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001115
Dan Williams0dc5a292007-05-10 22:58:02 -04001116 if ( (*uwrq != IW_MODE_ADHOC)
1117 && (*uwrq != IW_MODE_INFRA)
1118 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001119 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001120 ret = -EINVAL;
1121 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001122 }
1123
1124 mutex_lock(&adapter->lock);
1125 assoc_req = wlan_get_association_request(adapter);
1126 if (!assoc_req) {
1127 ret = -ENOMEM;
Dan Williams0dc5a292007-05-10 22:58:02 -04001128 wlan_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001129 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001130 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001131 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1132 wlan_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001133 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001134 }
1135 mutex_unlock(&adapter->lock);
1136
Dan Williams0dc5a292007-05-10 22:58:02 -04001137out:
Holger Schurig9012b282007-05-25 11:27:16 -04001138 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001139 return ret;
1140}
1141
1142
1143/**
1144 * @brief Get Encryption key
1145 *
1146 * @param dev A pointer to net_device structure
1147 * @param info A pointer to iw_request_info structure
1148 * @param vwrq A pointer to iw_param structure
1149 * @param extra A pointer to extra data buf
1150 * @return 0 --success, otherwise fail
1151 */
1152static int wlan_get_encode(struct net_device *dev,
1153 struct iw_request_info *info,
1154 struct iw_point *dwrq, u8 * extra)
1155{
1156 wlan_private *priv = dev->priv;
1157 wlan_adapter *adapter = priv->adapter;
1158 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1159
Holger Schurig9012b282007-05-25 11:27:16 -04001160 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001161
Holger Schurig9012b282007-05-25 11:27:16 -04001162 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001163 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1164
1165 dwrq->flags = 0;
1166
1167 /* Authentication method */
Dan Williams6affe782007-05-10 22:56:42 -04001168 switch (adapter->secinfo.auth_mode) {
1169 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170 dwrq->flags = IW_ENCODE_OPEN;
1171 break;
1172
Dan Williams6affe782007-05-10 22:56:42 -04001173 case IW_AUTH_ALG_SHARED_KEY:
1174 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001175 dwrq->flags = IW_ENCODE_RESTRICTED;
1176 break;
1177 default:
1178 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1179 break;
1180 }
1181
Dan Williams889c05b2007-05-10 22:57:23 -04001182 if ( adapter->secinfo.wep_enabled
1183 || adapter->secinfo.WPAenabled
1184 || adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001185 dwrq->flags &= ~IW_ENCODE_DISABLED;
1186 } else {
1187 dwrq->flags |= IW_ENCODE_DISABLED;
1188 }
1189
1190 memset(extra, 0, 16);
1191
1192 mutex_lock(&adapter->lock);
1193
1194 /* Default to returning current transmit key */
1195 if (index < 0)
1196 index = adapter->wep_tx_keyidx;
1197
Dan Williams889c05b2007-05-10 22:57:23 -04001198 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001199 memcpy(extra, adapter->wep_keys[index].key,
1200 adapter->wep_keys[index].len);
1201 dwrq->length = adapter->wep_keys[index].len;
1202
1203 dwrq->flags |= (index + 1);
1204 /* Return WEP enabled */
1205 dwrq->flags &= ~IW_ENCODE_DISABLED;
1206 } else if ((adapter->secinfo.WPAenabled)
1207 || (adapter->secinfo.WPA2enabled)) {
1208 /* return WPA enabled */
1209 dwrq->flags &= ~IW_ENCODE_DISABLED;
1210 } else {
1211 dwrq->flags |= IW_ENCODE_DISABLED;
1212 }
1213
1214 mutex_unlock(&adapter->lock);
1215
1216 dwrq->flags |= IW_ENCODE_NOKEY;
1217
Holger Schurig9012b282007-05-25 11:27:16 -04001218 lbs_deb_wext("key: " MAC_FMT ", keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001219 extra[0], extra[1], extra[2],
1220 extra[3], extra[4], extra[5], dwrq->length);
1221
Holger Schurig9012b282007-05-25 11:27:16 -04001222 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001223
Holger Schurig9012b282007-05-25 11:27:16 -04001224 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001225 return 0;
1226}
1227
1228/**
1229 * @brief Set Encryption key (internal)
1230 *
1231 * @param priv A pointer to private card structure
1232 * @param key_material A pointer to key material
1233 * @param key_length length of key material
1234 * @param index key index to set
1235 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1236 * @return 0 --success, otherwise fail
1237 */
1238static int wlan_set_wep_key(struct assoc_request *assoc_req,
1239 const char *key_material,
1240 u16 key_length,
1241 u16 index,
1242 int set_tx_key)
1243{
Holger Schurig9012b282007-05-25 11:27:16 -04001244 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001245 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001246
Holger Schurig9012b282007-05-25 11:27:16 -04001247 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001248
1249 /* Paranoid validation of key index */
1250 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001251 ret = -EINVAL;
1252 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001253 }
1254
1255 /* validate max key length */
1256 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001257 ret = -EINVAL;
1258 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001259 }
1260
1261 pkey = &assoc_req->wep_keys[index];
1262
1263 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001264 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001265 pkey->type = KEY_TYPE_ID_WEP;
1266
1267 /* Standardize the key length */
1268 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1269 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1270 memcpy(pkey->key, key_material, key_length);
1271 }
1272
1273 if (set_tx_key) {
1274 /* Ensure the chosen key is valid */
1275 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001276 lbs_deb_wext("key not set, so cannot enable it\n");
1277 ret = -EINVAL;
1278 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001279 }
1280 assoc_req->wep_tx_keyidx = index;
1281 }
1282
Dan Williams889c05b2007-05-10 22:57:23 -04001283 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001284
Holger Schurig9012b282007-05-25 11:27:16 -04001285out:
1286 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1287 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001288}
1289
1290static int validate_key_index(u16 def_index, u16 raw_index,
1291 u16 *out_index, u16 *is_default)
1292{
1293 if (!out_index || !is_default)
1294 return -EINVAL;
1295
1296 /* Verify index if present, otherwise use default TX key index */
1297 if (raw_index > 0) {
1298 if (raw_index > 4)
1299 return -EINVAL;
1300 *out_index = raw_index - 1;
1301 } else {
1302 *out_index = def_index;
1303 *is_default = 1;
1304 }
1305 return 0;
1306}
1307
1308static void disable_wep(struct assoc_request *assoc_req)
1309{
1310 int i;
1311
Dan Williams90a42212007-05-25 23:01:24 -04001312 lbs_deb_enter(LBS_DEB_WEXT);
1313
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001314 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001315 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001316
1317 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001318 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001319 for (i = 0; i < 4; i++)
1320 assoc_req->wep_keys[i].len = 0;
1321
1322 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1323 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001324
1325 lbs_deb_leave(LBS_DEB_WEXT);
1326}
1327
1328static void disable_wpa(struct assoc_request *assoc_req)
1329{
1330 lbs_deb_enter(LBS_DEB_WEXT);
1331
Dan Williams1443b652007-08-02 10:45:55 -04001332 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001333 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1334 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1335
Dan Williams1443b652007-08-02 10:45:55 -04001336 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001337 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1338 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1339
1340 assoc_req->secinfo.WPAenabled = 0;
1341 assoc_req->secinfo.WPA2enabled = 0;
1342 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1343
1344 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001345}
1346
1347/**
1348 * @brief Set Encryption key
1349 *
1350 * @param dev A pointer to net_device structure
1351 * @param info A pointer to iw_request_info structure
1352 * @param vwrq A pointer to iw_param structure
1353 * @param extra A pointer to extra data buf
1354 * @return 0 --success, otherwise fail
1355 */
1356static int wlan_set_encode(struct net_device *dev,
1357 struct iw_request_info *info,
1358 struct iw_point *dwrq, char *extra)
1359{
1360 int ret = 0;
1361 wlan_private *priv = dev->priv;
1362 wlan_adapter *adapter = priv->adapter;
1363 struct assoc_request * assoc_req;
1364 u16 is_default = 0, index = 0, set_tx_key = 0;
1365
Holger Schurig9012b282007-05-25 11:27:16 -04001366 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367
1368 mutex_lock(&adapter->lock);
1369 assoc_req = wlan_get_association_request(adapter);
1370 if (!assoc_req) {
1371 ret = -ENOMEM;
1372 goto out;
1373 }
1374
1375 if (dwrq->flags & IW_ENCODE_DISABLED) {
1376 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001377 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001378 goto out;
1379 }
1380
1381 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1382 (dwrq->flags & IW_ENCODE_INDEX),
1383 &index, &is_default);
1384 if (ret) {
1385 ret = -EINVAL;
1386 goto out;
1387 }
1388
1389 /* If WEP isn't enabled, or if there is no key data but a valid
1390 * index, set the TX key.
1391 */
Dan Williams889c05b2007-05-10 22:57:23 -04001392 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001393 set_tx_key = 1;
1394
1395 ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1396 if (ret)
1397 goto out;
1398
1399 if (dwrq->length)
1400 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1401 if (set_tx_key)
1402 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1403
1404 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001405 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001406 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001407 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001408 }
1409
1410out:
1411 if (ret == 0) {
1412 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1413 wlan_postpone_association_work(priv);
1414 } else {
1415 wlan_cancel_association_work(priv);
1416 }
1417 mutex_unlock(&adapter->lock);
1418
Holger Schurig9012b282007-05-25 11:27:16 -04001419 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001420 return ret;
1421}
1422
1423/**
1424 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1425 *
1426 * @param dev A pointer to net_device structure
1427 * @param info A pointer to iw_request_info structure
1428 * @param vwrq A pointer to iw_param structure
1429 * @param extra A pointer to extra data buf
1430 * @return 0 on success, otherwise failure
1431 */
1432static int wlan_get_encodeext(struct net_device *dev,
1433 struct iw_request_info *info,
1434 struct iw_point *dwrq,
1435 char *extra)
1436{
1437 int ret = -EINVAL;
1438 wlan_private *priv = dev->priv;
1439 wlan_adapter *adapter = priv->adapter;
1440 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1441 int index, max_key_len;
1442
Holger Schurig9012b282007-05-25 11:27:16 -04001443 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001444
1445 max_key_len = dwrq->length - sizeof(*ext);
1446 if (max_key_len < 0)
1447 goto out;
1448
1449 index = dwrq->flags & IW_ENCODE_INDEX;
1450 if (index) {
1451 if (index < 1 || index > 4)
1452 goto out;
1453 index--;
1454 } else {
1455 index = adapter->wep_tx_keyidx;
1456 }
1457
1458 if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
1459 ext->alg != IW_ENCODE_ALG_WEP) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001460 if (index != 0 || adapter->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001461 goto out;
1462 }
1463
1464 dwrq->flags = index + 1;
1465 memset(ext, 0, sizeof(*ext));
1466
Dan Williams889c05b2007-05-10 22:57:23 -04001467 if ( !adapter->secinfo.wep_enabled
1468 && !adapter->secinfo.WPAenabled
1469 && !adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001470 ext->alg = IW_ENCODE_ALG_NONE;
1471 ext->key_len = 0;
1472 dwrq->flags |= IW_ENCODE_DISABLED;
1473 } else {
1474 u8 *key = NULL;
1475
Dan Williams889c05b2007-05-10 22:57:23 -04001476 if ( adapter->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001477 && !adapter->secinfo.WPAenabled
1478 && !adapter->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001479 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001480 ext->alg = IW_ENCODE_ALG_WEP;
1481 ext->key_len = adapter->wep_keys[index].len;
1482 key = &adapter->wep_keys[index].key[0];
Dan Williams889c05b2007-05-10 22:57:23 -04001483 } else if ( !adapter->secinfo.wep_enabled
1484 && (adapter->secinfo.WPAenabled ||
1485 adapter->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001486 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001487 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001488
1489 if ( adapter->wpa_mcast_key.len
1490 && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1491 pkey = &adapter->wpa_mcast_key;
1492 else if ( adapter->wpa_unicast_key.len
1493 && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1494 pkey = &adapter->wpa_unicast_key;
1495
1496 if (pkey) {
1497 if (pkey->type == KEY_TYPE_ID_AES) {
1498 ext->alg = IW_ENCODE_ALG_CCMP;
1499 } else {
1500 ext->alg = IW_ENCODE_ALG_TKIP;
1501 }
1502 ext->key_len = pkey->len;
1503 key = &pkey->key[0];
1504 } else {
1505 ext->alg = IW_ENCODE_ALG_TKIP;
1506 ext->key_len = 0;
1507 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508 } else {
1509 goto out;
1510 }
1511
1512 if (ext->key_len > max_key_len) {
1513 ret = -E2BIG;
1514 goto out;
1515 }
1516
1517 if (ext->key_len)
1518 memcpy(ext->key, key, ext->key_len);
1519 else
1520 dwrq->flags |= IW_ENCODE_NOKEY;
1521 dwrq->flags |= IW_ENCODE_ENABLED;
1522 }
1523 ret = 0;
1524
1525out:
Holger Schurig9012b282007-05-25 11:27:16 -04001526 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001527 return ret;
1528}
1529
1530/**
1531 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1532 *
1533 * @param dev A pointer to net_device structure
1534 * @param info A pointer to iw_request_info structure
1535 * @param vwrq A pointer to iw_param structure
1536 * @param extra A pointer to extra data buf
1537 * @return 0 --success, otherwise fail
1538 */
1539static int wlan_set_encodeext(struct net_device *dev,
1540 struct iw_request_info *info,
1541 struct iw_point *dwrq,
1542 char *extra)
1543{
1544 int ret = 0;
1545 wlan_private *priv = dev->priv;
1546 wlan_adapter *adapter = priv->adapter;
1547 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1548 int alg = ext->alg;
1549 struct assoc_request * assoc_req;
1550
Holger Schurig9012b282007-05-25 11:27:16 -04001551 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001552
1553 mutex_lock(&adapter->lock);
1554 assoc_req = wlan_get_association_request(adapter);
1555 if (!assoc_req) {
1556 ret = -ENOMEM;
1557 goto out;
1558 }
1559
1560 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1561 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001562 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001563 } else if (alg == IW_ENCODE_ALG_WEP) {
1564 u16 is_default = 0, index, set_tx_key = 0;
1565
1566 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1567 (dwrq->flags & IW_ENCODE_INDEX),
1568 &index, &is_default);
1569 if (ret)
1570 goto out;
1571
1572 /* If WEP isn't enabled, or if there is no key data but a valid
1573 * index, or if the set-TX-key flag was passed, set the TX key.
1574 */
Dan Williams889c05b2007-05-10 22:57:23 -04001575 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001576 || (dwrq->length == 0 && !is_default)
1577 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1578 set_tx_key = 1;
1579
1580 /* Copy key to driver */
1581 ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
1582 set_tx_key);
1583 if (ret)
1584 goto out;
1585
1586 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001587 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001588 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001589 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001590 }
1591
1592 /* Mark the various WEP bits as modified */
1593 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1594 if (dwrq->length)
1595 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1596 if (set_tx_key)
1597 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001598 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001599 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001600
1601 /* validate key length */
1602 if (((alg == IW_ENCODE_ALG_TKIP)
1603 && (ext->key_len != KEY_LEN_WPA_TKIP))
1604 || ((alg == IW_ENCODE_ALG_CCMP)
1605 && (ext->key_len != KEY_LEN_WPA_AES))) {
Holger Schurig9012b282007-05-25 11:27:16 -04001606 lbs_deb_wext("invalid size %d for key of alg"
1607 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001608 ext->key_len,
1609 alg);
1610 ret = -EINVAL;
1611 goto out;
1612 }
1613
Dan Williams90a42212007-05-25 23:01:24 -04001614 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001615 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001616 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1617 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001618 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001619 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1620 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001621
Dan Williams1443b652007-08-02 10:45:55 -04001622 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001623 memcpy(pkey->key, ext->key, ext->key_len);
1624 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001625 if (pkey->len)
1626 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001627
Dan Williams90a42212007-05-25 23:01:24 -04001628 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001629 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1630 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001631 } else {
1632 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001633 }
1634
Dan Williams90a42212007-05-25 23:01:24 -04001635 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001636 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001637 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001638 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001639 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001640
1641 /* If WPA isn't enabled yet, do that now */
1642 if ( assoc_req->secinfo.WPAenabled == 0
1643 && assoc_req->secinfo.WPA2enabled == 0) {
1644 assoc_req->secinfo.WPAenabled = 1;
1645 assoc_req->secinfo.WPA2enabled = 1;
1646 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1647 }
1648
1649 disable_wep (assoc_req);
1650 }
1651
1652out:
1653 if (ret == 0) {
1654 wlan_postpone_association_work(priv);
1655 } else {
1656 wlan_cancel_association_work(priv);
1657 }
1658 mutex_unlock(&adapter->lock);
1659
Holger Schurig9012b282007-05-25 11:27:16 -04001660 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001661 return ret;
1662}
1663
1664
1665static int wlan_set_genie(struct net_device *dev,
1666 struct iw_request_info *info,
1667 struct iw_point *dwrq,
1668 char *extra)
1669{
1670 wlan_private *priv = dev->priv;
1671 wlan_adapter *adapter = priv->adapter;
1672 int ret = 0;
1673 struct assoc_request * assoc_req;
1674
Holger Schurig9012b282007-05-25 11:27:16 -04001675 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001676
1677 mutex_lock(&adapter->lock);
1678 assoc_req = wlan_get_association_request(adapter);
1679 if (!assoc_req) {
1680 ret = -ENOMEM;
1681 goto out;
1682 }
1683
1684 if (dwrq->length > MAX_WPA_IE_LEN ||
1685 (dwrq->length && extra == NULL)) {
1686 ret = -EINVAL;
1687 goto out;
1688 }
1689
1690 if (dwrq->length) {
1691 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1692 assoc_req->wpa_ie_len = dwrq->length;
1693 } else {
1694 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
1695 assoc_req->wpa_ie_len = 0;
1696 }
1697
1698out:
1699 if (ret == 0) {
1700 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1701 wlan_postpone_association_work(priv);
1702 } else {
1703 wlan_cancel_association_work(priv);
1704 }
1705 mutex_unlock(&adapter->lock);
1706
Holger Schurig9012b282007-05-25 11:27:16 -04001707 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001708 return ret;
1709}
1710
1711static int wlan_get_genie(struct net_device *dev,
1712 struct iw_request_info *info,
1713 struct iw_point *dwrq,
1714 char *extra)
1715{
Holger Schurig9012b282007-05-25 11:27:16 -04001716 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001717 wlan_private *priv = dev->priv;
1718 wlan_adapter *adapter = priv->adapter;
1719
Holger Schurig9012b282007-05-25 11:27:16 -04001720 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001721
1722 if (adapter->wpa_ie_len == 0) {
1723 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001724 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001725 }
1726
1727 if (dwrq->length < adapter->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001728 ret = -E2BIG;
1729 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001730 }
1731
1732 dwrq->length = adapter->wpa_ie_len;
1733 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
1734
Holger Schurig9012b282007-05-25 11:27:16 -04001735out:
1736 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1737 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001738}
1739
1740
1741static int wlan_set_auth(struct net_device *dev,
1742 struct iw_request_info *info,
1743 struct iw_param *dwrq,
1744 char *extra)
1745{
1746 wlan_private *priv = dev->priv;
1747 wlan_adapter *adapter = priv->adapter;
1748 struct assoc_request * assoc_req;
1749 int ret = 0;
1750 int updated = 0;
1751
Holger Schurig9012b282007-05-25 11:27:16 -04001752 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001753
1754 mutex_lock(&adapter->lock);
1755 assoc_req = wlan_get_association_request(adapter);
1756 if (!assoc_req) {
1757 ret = -ENOMEM;
1758 goto out;
1759 }
1760
1761 switch (dwrq->flags & IW_AUTH_INDEX) {
1762 case IW_AUTH_TKIP_COUNTERMEASURES:
1763 case IW_AUTH_CIPHER_PAIRWISE:
1764 case IW_AUTH_CIPHER_GROUP:
1765 case IW_AUTH_KEY_MGMT:
Dan Williams90a42212007-05-25 23:01:24 -04001766 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001767 /*
1768 * libertas does not use these parameters
1769 */
1770 break;
1771
1772 case IW_AUTH_WPA_VERSION:
1773 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1774 assoc_req->secinfo.WPAenabled = 0;
1775 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001776 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001777 }
1778 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1779 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001780 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001781 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001782 }
1783 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1784 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001785 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001786 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001787 }
1788 updated = 1;
1789 break;
1790
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001791 case IW_AUTH_80211_AUTH_ALG:
1792 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001793 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001794 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001795 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001796 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001797 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001798 } else {
1799 ret = -EINVAL;
1800 }
1801 updated = 1;
1802 break;
1803
1804 case IW_AUTH_WPA_ENABLED:
1805 if (dwrq->value) {
1806 if (!assoc_req->secinfo.WPAenabled &&
1807 !assoc_req->secinfo.WPA2enabled) {
1808 assoc_req->secinfo.WPAenabled = 1;
1809 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001810 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001811 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001812 }
1813 } else {
1814 assoc_req->secinfo.WPAenabled = 0;
1815 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001816 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001817 }
1818 updated = 1;
1819 break;
1820
1821 default:
1822 ret = -EOPNOTSUPP;
1823 break;
1824 }
1825
1826out:
1827 if (ret == 0) {
1828 if (updated)
1829 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1830 wlan_postpone_association_work(priv);
1831 } else if (ret != -EOPNOTSUPP) {
1832 wlan_cancel_association_work(priv);
1833 }
1834 mutex_unlock(&adapter->lock);
1835
Holger Schurig9012b282007-05-25 11:27:16 -04001836 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001837 return ret;
1838}
1839
1840static int wlan_get_auth(struct net_device *dev,
1841 struct iw_request_info *info,
1842 struct iw_param *dwrq,
1843 char *extra)
1844{
Holger Schurig9012b282007-05-25 11:27:16 -04001845 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001846 wlan_private *priv = dev->priv;
1847 wlan_adapter *adapter = priv->adapter;
1848
Holger Schurig9012b282007-05-25 11:27:16 -04001849 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001850
1851 switch (dwrq->flags & IW_AUTH_INDEX) {
1852 case IW_AUTH_WPA_VERSION:
1853 dwrq->value = 0;
1854 if (adapter->secinfo.WPAenabled)
1855 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1856 if (adapter->secinfo.WPA2enabled)
1857 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1858 if (!dwrq->value)
1859 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1860 break;
1861
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001862 case IW_AUTH_80211_AUTH_ALG:
Dan Williams6affe782007-05-10 22:56:42 -04001863 dwrq->value = adapter->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001864 break;
1865
1866 case IW_AUTH_WPA_ENABLED:
1867 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
1868 dwrq->value = 1;
1869 break;
1870
1871 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001872 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001873 }
1874
Holger Schurig9012b282007-05-25 11:27:16 -04001875 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1876 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001877}
1878
1879
1880static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
1881 struct iw_param *vwrq, char *extra)
1882{
1883 int ret = 0;
1884 wlan_private *priv = dev->priv;
1885 wlan_adapter *adapter = priv->adapter;
1886
1887 u16 dbm;
1888
Holger Schurig9012b282007-05-25 11:27:16 -04001889 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001890
1891 if (vwrq->disabled) {
1892 wlan_radio_ioctl(priv, RADIO_OFF);
1893 return 0;
1894 }
1895
Dan Williams0aef64d2007-08-02 11:31:18 -04001896 adapter->preamble = CMD_TYPE_AUTO_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001897
1898 wlan_radio_ioctl(priv, RADIO_ON);
1899
1900 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
1901 dbm = (u16) mw_to_dbm(vwrq->value);
1902 } else
1903 dbm = (u16) vwrq->value;
1904
1905 /* auto tx power control */
1906
1907 if (vwrq->fixed == 0)
1908 dbm = 0xffff;
1909
Holger Schurig9012b282007-05-25 11:27:16 -04001910 lbs_deb_wext("txpower set %d dbm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001911
1912 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -04001913 CMD_802_11_RF_TX_POWER,
1914 CMD_ACT_TX_POWER_OPT_SET_LOW,
1915 CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001916
Holger Schurig9012b282007-05-25 11:27:16 -04001917 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001918 return ret;
1919}
1920
1921static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
1922 struct iw_point *dwrq, char *extra)
1923{
1924 wlan_private *priv = dev->priv;
1925 wlan_adapter *adapter = priv->adapter;
1926
Holger Schurig9012b282007-05-25 11:27:16 -04001927 lbs_deb_enter(LBS_DEB_WEXT);
1928
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001929 /*
1930 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1931 * the SSID list...
1932 */
1933
1934 /*
1935 * Get the current SSID
1936 */
Dan Williams0aef64d2007-08-02 11:31:18 -04001937 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Dan Williamsd8efea22007-05-28 23:54:55 -04001938 memcpy(extra, adapter->curbssparams.ssid,
1939 adapter->curbssparams.ssid_len);
1940 extra[adapter->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001941 } else {
1942 memset(extra, 0, 32);
Dan Williamsd8efea22007-05-28 23:54:55 -04001943 extra[adapter->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001944 }
1945 /*
1946 * If none, we may want to get the one that was set
1947 */
1948
1949 /* To make the driver backward compatible with WPA supplicant v0.2.4 */
1950 if (dwrq->length == 32) /* check with WPA supplicant buffer size */
Dan Williamsd8efea22007-05-28 23:54:55 -04001951 dwrq->length = min_t(size_t, adapter->curbssparams.ssid_len,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001952 IW_ESSID_MAX_SIZE);
1953 else
Dan Williamsd8efea22007-05-28 23:54:55 -04001954 dwrq->length = adapter->curbssparams.ssid_len + 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001955
1956 dwrq->flags = 1; /* active */
1957
Holger Schurig9012b282007-05-25 11:27:16 -04001958 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001959 return 0;
1960}
1961
1962static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
1963 struct iw_point *dwrq, char *extra)
1964{
1965 wlan_private *priv = dev->priv;
1966 wlan_adapter *adapter = priv->adapter;
1967 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04001968 u8 ssid[IW_ESSID_MAX_SIZE];
1969 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001970 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001971 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001972
Holger Schurig9012b282007-05-25 11:27:16 -04001973 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001974
1975 /*
1976 * WE-20 and earlier NULL pad the end of the SSID and increment
1977 * SSID length so it can be used like a string. WE-21 and later don't,
1978 * but some userspace tools aren't able to cope with the change.
1979 */
Dan Williamsd8efea22007-05-28 23:54:55 -04001980 if ((in_ssid_len > 0) && (extra[in_ssid_len - 1] == '\0'))
1981 in_ssid_len--;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001982
1983 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001984 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001985 ret = -E2BIG;
1986 goto out;
1987 }
1988
Dan Williamsd8efea22007-05-28 23:54:55 -04001989 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001990
Dan Williamsd8efea22007-05-28 23:54:55 -04001991 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001992 /* "any" SSID requested; leave SSID blank */
1993 } else {
1994 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04001995 memcpy(&ssid, extra, in_ssid_len);
1996 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001997 }
1998
Dan Williamsd8efea22007-05-28 23:54:55 -04001999 if (!ssid_len) {
2000 lbs_deb_wext("requested any SSID\n");
2001 } else {
2002 lbs_deb_wext("requested SSID '%s'\n",
2003 escape_essid(ssid, ssid_len));
2004 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002005
2006out:
2007 mutex_lock(&adapter->lock);
2008 if (ret == 0) {
2009 /* Get or create the current association request */
2010 assoc_req = wlan_get_association_request(adapter);
2011 if (!assoc_req) {
2012 ret = -ENOMEM;
2013 } else {
2014 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04002015 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
2016 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002017 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2018 wlan_postpone_association_work(priv);
2019 }
2020 }
2021
2022 /* Cancel the association request if there was an error */
2023 if (ret != 0) {
2024 wlan_cancel_association_work(priv);
2025 }
2026
2027 mutex_unlock(&adapter->lock);
2028
Holger Schurig9012b282007-05-25 11:27:16 -04002029 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002030 return ret;
2031}
2032
2033/**
2034 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2035 *
2036 * @param dev A pointer to net_device structure
2037 * @param info A pointer to iw_request_info structure
2038 * @param awrq A pointer to iw_param structure
2039 * @param extra A pointer to extra data buf
2040 * @return 0 --success, otherwise fail
2041 */
2042static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
2043 struct sockaddr *awrq, char *extra)
2044{
2045 wlan_private *priv = dev->priv;
2046 wlan_adapter *adapter = priv->adapter;
2047 struct assoc_request * assoc_req;
2048 int ret = 0;
2049
Holger Schurig9012b282007-05-25 11:27:16 -04002050 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002051
2052 if (awrq->sa_family != ARPHRD_ETHER)
2053 return -EINVAL;
2054
Holger Schurig9012b282007-05-25 11:27:16 -04002055 lbs_deb_wext("ASSOC: WAP: sa_data " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002056
2057 mutex_lock(&adapter->lock);
2058
2059 /* Get or create the current association request */
2060 assoc_req = wlan_get_association_request(adapter);
2061 if (!assoc_req) {
2062 wlan_cancel_association_work(priv);
2063 ret = -ENOMEM;
2064 } else {
2065 /* Copy the BSSID to the association request */
2066 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2067 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2068 wlan_postpone_association_work(priv);
2069 }
2070
2071 mutex_unlock(&adapter->lock);
2072
2073 return ret;
2074}
2075
2076void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
2077{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002078 char fwver[32];
2079
2080 mutex_lock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002081
David Woodhousee5b3d472007-05-25 23:40:21 -04002082 if (adapter->fwreleasenumber[3] == 0)
2083 sprintf(fwver, "%u.%u.%u",
2084 adapter->fwreleasenumber[2],
2085 adapter->fwreleasenumber[1],
2086 adapter->fwreleasenumber[0]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002087 else
2088 sprintf(fwver, "%u.%u.%u.p%u",
David Woodhousee5b3d472007-05-25 23:40:21 -04002089 adapter->fwreleasenumber[2],
2090 adapter->fwreleasenumber[1],
2091 adapter->fwreleasenumber[0],
2092 adapter->fwreleasenumber[3]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002093
David Woodhousee5b3d472007-05-25 23:40:21 -04002094 mutex_unlock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002095 snprintf(fwversion, maxlen, fwver);
2096}
2097
2098
2099/*
2100 * iwconfig settable callbacks
2101 */
2102static const iw_handler wlan_handler[] = {
2103 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2104 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2105 (iw_handler) NULL, /* SIOCSIWNWID */
2106 (iw_handler) NULL, /* SIOCGIWNWID */
2107 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2108 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2109 (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
2110 (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
2111 (iw_handler) NULL, /* SIOCSIWSENS */
2112 (iw_handler) NULL, /* SIOCGIWSENS */
2113 (iw_handler) NULL, /* SIOCSIWRANGE */
2114 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2115 (iw_handler) NULL, /* SIOCSIWPRIV */
2116 (iw_handler) NULL, /* SIOCGIWPRIV */
2117 (iw_handler) NULL, /* SIOCSIWSTATS */
2118 (iw_handler) NULL, /* SIOCGIWSTATS */
2119 iw_handler_set_spy, /* SIOCSIWSPY */
2120 iw_handler_get_spy, /* SIOCGIWSPY */
2121 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2122 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2123 (iw_handler) wlan_set_wap, /* SIOCSIWAP */
2124 (iw_handler) wlan_get_wap, /* SIOCGIWAP */
2125 (iw_handler) NULL, /* SIOCSIWMLME */
2126 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2127 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2128 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2129 (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
2130 (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
2131 (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
2132 (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
2133 (iw_handler) NULL, /* -- hole -- */
2134 (iw_handler) NULL, /* -- hole -- */
2135 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2136 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2137 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2138 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2139 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2140 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2141 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2142 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2143 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2144 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2145 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2146 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2147 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2148 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2149 (iw_handler) NULL, /* -- hole -- */
2150 (iw_handler) NULL, /* -- hole -- */
2151 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2152 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2153 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2154 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2155 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2156 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2157 (iw_handler) NULL, /* SIOCSIWPMKSA */
2158};
2159
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002160static const iw_handler mesh_wlan_handler[] = {
2161 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2162 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2163 (iw_handler) NULL, /* SIOCSIWNWID */
2164 (iw_handler) NULL, /* SIOCGIWNWID */
2165 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2166 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2167 (iw_handler) NULL, /* SIOCSIWMODE */
2168 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2169 (iw_handler) NULL, /* SIOCSIWSENS */
2170 (iw_handler) NULL, /* SIOCGIWSENS */
2171 (iw_handler) NULL, /* SIOCSIWRANGE */
2172 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2173 (iw_handler) NULL, /* SIOCSIWPRIV */
2174 (iw_handler) NULL, /* SIOCGIWPRIV */
2175 (iw_handler) NULL, /* SIOCSIWSTATS */
2176 (iw_handler) NULL, /* SIOCGIWSTATS */
2177 iw_handler_set_spy, /* SIOCSIWSPY */
2178 iw_handler_get_spy, /* SIOCGIWSPY */
2179 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2180 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2181 (iw_handler) NULL, /* SIOCSIWAP */
2182 (iw_handler) NULL, /* SIOCGIWAP */
2183 (iw_handler) NULL, /* SIOCSIWMLME */
2184 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2185 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2186 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2187 (iw_handler) NULL, /* SIOCSIWESSID */
2188 (iw_handler) NULL, /* SIOCGIWESSID */
2189 (iw_handler) NULL, /* SIOCSIWNICKN */
2190 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2191 (iw_handler) NULL, /* -- hole -- */
2192 (iw_handler) NULL, /* -- hole -- */
2193 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2194 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2195 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2196 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2197 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2198 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2199 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2200 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2201 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2202 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2203 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2204 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2205 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2206 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2207 (iw_handler) NULL, /* -- hole -- */
2208 (iw_handler) NULL, /* -- hole -- */
2209 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2210 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2211 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2212 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2213 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2214 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2215 (iw_handler) NULL, /* SIOCSIWPMKSA */
2216};
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002217struct iw_handler_def libertas_handler_def = {
2218 .num_standard = sizeof(wlan_handler) / sizeof(iw_handler),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002219 .standard = (iw_handler *) wlan_handler,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002220 .get_wireless_stats = wlan_get_wireless_stats,
2221};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002222
2223struct iw_handler_def mesh_handler_def = {
2224 .num_standard = sizeof(mesh_wlan_handler) / sizeof(iw_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002225 .standard = (iw_handler *) mesh_wlan_handler,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002226 .get_wireless_stats = wlan_get_wireless_stats,
2227};