blob: f8036efd72940b35b76d275f82f12e6aeb1456a0 [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/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020025 * @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)
Holger Schurig9012b282007-05-25 11:27:16 -040059 lbs_deb_wext("libertas_find_cfp_by_band_and_channel: can't find "
60 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061
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)
Holger Schurig9012b282007-05-25 11:27:16 -0400100 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
101 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200102
103 return cfp;
104}
105
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200106
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 */
Holger Schurigac558ca2007-08-02 11:49:06 -0400114static int wlan_radio_ioctl(wlan_private * priv, u8 option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115{
116 int ret = 0;
117 wlan_adapter *adapter = priv->adapter;
118
Holger Schurig9012b282007-05-25 11:27:16 -0400119 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200120
121 if (adapter->radioon != option) {
Holger Schurig9012b282007-05-25 11:27:16 -0400122 lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200123 adapter->radioon = option;
124
125 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400126 CMD_802_11_RADIO_CONTROL,
127 CMD_ACT_SET,
128 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129 }
130
Holger Schurig9012b282007-05-25 11:27:16 -0400131 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200132 return ret;
133}
134
135/**
Dan Williams8c512762007-08-02 11:40:45 -0400136 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200137 *
138 * @param adapter A pointer to wlan_adapter structure
139 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200140 */
Dan Williams8c512762007-08-02 11:40:45 -0400141static void copy_active_data_rates(wlan_adapter * adapter, u8 * rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142{
Holger Schurig9012b282007-05-25 11:27:16 -0400143 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200144
Dan Williams8c512762007-08-02 11:40:45 -0400145 if (adapter->connect_status != LIBERTAS_CONNECTED)
146 memcpy(rates, libertas_bg_rates, MAX_RATES);
147 else
148 memcpy(rates, adapter->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149
Dan Williams8c512762007-08-02 11:40:45 -0400150 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200151}
152
153static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
154 char *cwrq, char *extra)
155{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156
Holger Schurig9012b282007-05-25 11:27:16 -0400157 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400159 /* We could add support for 802.11n here as needed. Jean II */
160 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161
Holger Schurig9012b282007-05-25 11:27:16 -0400162 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200163 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
Holger Schurig9012b282007-05-25 11:27:16 -0400173 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200174
175 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
176 adapter->curbssparams.channel);
177
178 if (!cfp) {
179 if (adapter->curbssparams.channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400180 lbs_deb_wext("invalid channel %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181 adapter->curbssparams.channel);
182 return -EINVAL;
183 }
184
185 fwrq->m = (long)cfp->freq * 100000;
186 fwrq->e = 1;
187
Holger Schurig9012b282007-05-25 11:27:16 -0400188 lbs_deb_wext("freq %u\n", fwrq->m);
189 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190 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
Holger Schurig9012b282007-05-25 11:27:16 -0400199 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200
Dan Williams0aef64d2007-08-02 11:31:18 -0400201 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200202 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
Holger Schurig9012b282007-05-25 11:27:16 -0400208 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200209 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
Holger Schurig9012b282007-05-25 11:27:16 -0400218 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200219
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
Holger Schurig9012b282007-05-25 11:27:16 -0400233 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234 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{
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400240 const char *cp;
241 char comm[6] = { "COMM-" };
242 char mrvl[6] = { "MRVL-" };
243 int cnt;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244
Holger Schurig9012b282007-05-25 11:27:16 -0400245 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246
247 /*
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400248 * Nick Name is not used internally in this mode,
249 * therefore return something useful instead. Jean II
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200250 */
251
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400252 strcpy(extra, mrvl);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200253
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400254 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;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200259
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400260 cnt = strlen(mrvl);
261 extra += cnt;
262 while (cnt < 16 && (*cp != '-')) {
263 *extra++ = toupper(*cp++);
264 cnt++;
265 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200266
267 /*
268 * Push it out !
269 */
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400270 dwrq->length = cnt;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200271
Holger Schurig9012b282007-05-25 11:27:16 -0400272 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200273 return 0;
274}
275
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400276static 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
Dan Williams0aef64d2007-08-02 11:31:18 -0400286 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400287 strncpy(extra, "Mesh", 12);
288 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400289 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400290 }
291
292 else {
293 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400294 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400295 }
296
297 lbs_deb_leave(LBS_DEB_WEXT);
298 return 0;
299}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300static 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;
David Woodhouse981f1872007-05-25 23:36:54 -0400306 u32 rthr = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307
Holger Schurig9012b282007-05-25 11:27:16 -0400308 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309
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
Dan Williams0aef64d2007-08-02 11:31:18 -0400318 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
319 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200320 OID_802_11_RTS_THRESHOLD, &rthr);
321
Holger Schurig9012b282007-05-25 11:27:16 -0400322 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200323 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
Holger Schurig9012b282007-05-25 11:27:16 -0400333 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334
335 adapter->rtsthsd = 0;
Dan Williams0aef64d2007-08-02 11:31:18 -0400336 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
337 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338 OID_802_11_RTS_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400339 if (ret)
340 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200341
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
Holger Schurig9012b282007-05-25 11:27:16 -0400347out:
348 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
349 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200350}
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;
David Woodhouse981f1872007-05-25 23:36:54 -0400356 u32 fthr = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357 wlan_private *priv = dev->priv;
358 wlan_adapter *adapter = priv->adapter;
359
Holger Schurig9012b282007-05-25 11:27:16 -0400360 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200361
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
Dan Williams0aef64d2007-08-02 11:31:18 -0400371 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
372 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
Holger Schurig9012b282007-05-25 11:27:16 -0400374
375 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376 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
Holger Schurig9012b282007-05-25 11:27:16 -0400386 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200387
388 adapter->fragthsd = 0;
389 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400390 CMD_802_11_SNMP_MIB,
391 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400393 if (ret)
394 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200395
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
Holger Schurig9012b282007-05-25 11:27:16 -0400401out:
402 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200403 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
Holger Schurig9012b282007-05-25 11:27:16 -0400412 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413
Dan Williams0dc5a292007-05-10 22:58:02 -0400414 *uwrq = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200415
Holger Schurig9012b282007-05-25 11:27:16 -0400416 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417 return 0;
418}
419
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400420static 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
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200432static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400440 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200441
442 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400443 CMD_802_11_RF_TX_POWER,
444 CMD_ACT_TX_POWER_OPT_GET,
445 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200446
Holger Schurig9012b282007-05-25 11:27:16 -0400447 if (ret)
448 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200449
Holger Schurig9012b282007-05-25 11:27:16 -0400450 lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200451 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
Holger Schurig9012b282007-05-25 11:27:16 -0400460out:
461 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
462 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200463}
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
Holger Schurig9012b282007-05-25 11:27:16 -0400472 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200473
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
Dan Williams0aef64d2007-08-02 11:31:18 -0400485 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
486 CMD_ACT_SET,
487 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200488 OID_802_11_TX_RETRYCOUNT, NULL);
489
Holger Schurig9012b282007-05-25 11:27:16 -0400490 if (ret)
491 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200492 } else {
493 return -EOPNOTSUPP;
494 }
495
Holger Schurig9012b282007-05-25 11:27:16 -0400496out:
497 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
498 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499}
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
Holger Schurig9012b282007-05-25 11:27:16 -0400508 lbs_deb_enter(LBS_DEB_WEXT);
509
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200510 adapter->txretrycount = 0;
511 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400512 CMD_802_11_SNMP_MIB,
513 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200514 OID_802_11_TX_RETRYCOUNT, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400515 if (ret)
516 goto out;
517
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200518 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
Holger Schurig9012b282007-05-25 11:27:16 -0400525out:
526 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
527 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528}
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;
Dan Williams8c512762007-08-02 11:40:45 -0400577 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200578
579 u8 flag = 0;
580
Holger Schurig9012b282007-05-25 11:27:16 -0400581 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200582
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));
Dan Williams8c512762007-08-02 11:40:45 -0400590 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;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200594 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400595 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200596 range->num_bitrates);
597
598 range->num_frequency = 0;
599 if (priv->adapter->enable11d &&
Dan Williams0aef64d2007-08-02 11:31:18 -0400600 adapter->connect_status == LIBERTAS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200601 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) {
Holger Schurig9012b282007-05-25 11:27:16 -0400608 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
609 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610 }
611 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400612 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200613 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;
Holger Schurig9012b282007-05-25 11:27:16 -0400618 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200619 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
Holger Schurig9012b282007-05-25 11:27:16 -0400647 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200648 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
Holger Schurig9012b282007-05-25 11:27:16 -0400742out:
743 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200744 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
Holger Schurig9012b282007-05-25 11:27:16 -0400753 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200754
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) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400760 adapter->psmode = WLAN802_11POWERMODECAM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200761 if (adapter->psstate != PS_STATE_FULL_POWER) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400762 libertas_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200763 }
764
765 return 0;
766 }
767
768 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400769 lbs_deb_wext(
770 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200771 return -EINVAL;
772 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400773 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200774 return -EINVAL;
775 }
776
Dan Williams0aef64d2007-08-02 11:31:18 -0400777 if (adapter->psmode != WLAN802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778 return 0;
779 }
780
Dan Williams0aef64d2007-08-02 11:31:18 -0400781 adapter->psmode = WLAN802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200782
Dan Williams0aef64d2007-08-02 11:31:18 -0400783 if (adapter->connect_status == LIBERTAS_CONNECTED) {
784 libertas_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785 }
786
Holger Schurig9012b282007-05-25 11:27:16 -0400787 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200788 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
Holger Schurig9012b282007-05-25 11:27:16 -0400798 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200799
800 mode = adapter->psmode;
801
Dan Williams0aef64d2007-08-02 11:31:18 -0400802 if ((vwrq->disabled = (mode == WLAN802_11POWERMODECAM))
803 || adapter->connect_status == LIBERTAS_DISCONNECTED)
Holger Schurig9012b282007-05-25 11:27:16 -0400804 {
805 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200806 }
807
808 vwrq->value = 0;
809
Holger Schurig9012b282007-05-25 11:27:16 -0400810out:
811 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200812 return 0;
813}
814
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200815static 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
Holger Schurig9012b282007-05-25 11:27:16 -0400834 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200835
Dan Williams0dc5a292007-05-10 22:58:02 -0400836 priv->wstats.status = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200837
838 /* If we're not associated, all quality values are meaningless */
Dan Williams0aef64d2007-08-02 11:31:18 -0400839 if (adapter->connect_status != LIBERTAS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200840 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
Holger Schurig9012b282007-05-25 11:27:16 -0400854 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
855 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856
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
Dan Williams8362cd42007-08-03 09:40:55 -0400875 tx_retries = le32_to_cpu(adapter->logmsg.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200876
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
Dan Williams8362cd42007-08-03 09:40:55 -0400891 priv->wstats.discard.code = le32_to_cpu(adapter->logmsg.wepundecryptable);
892 priv->wstats.discard.fragment = le32_to_cpu(adapter->logmsg.rxfrag);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200893 priv->wstats.discard.retries = tx_retries;
Dan Williams8362cd42007-08-03 09:40:55 -0400894 priv->wstats.discard.misc = le32_to_cpu(adapter->logmsg.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200895
896 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400897 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200898 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
899 stats_valid = 1;
900
901 /* update stats asynchronously for future calls */
Dan Williams0aef64d2007-08-02 11:31:18 -0400902 libertas_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200903 0, 0, NULL);
Dan Williams0aef64d2007-08-02 11:31:18 -0400904 libertas_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905 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
Holger Schurig9012b282007-05-25 11:27:16 -0400918 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200919 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{
Dan Williamsef9a2642007-05-25 16:46:33 -0400927 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200928 wlan_private *priv = dev->priv;
929 wlan_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200930 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400931 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200932
Holger Schurig9012b282007-05-25 11:27:16 -0400933 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200934
Dan Williamsef9a2642007-05-25 16:46:33 -0400935 mutex_lock(&adapter->lock);
936 assoc_req = wlan_get_association_request(adapter);
937 if (!assoc_req) {
938 ret = -ENOMEM;
939 goto out;
940 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200941
Dan Williamsef9a2642007-05-25 16:46:33 -0400942 /* If setting by frequency, convert to a channel */
943 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200944 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200945
946 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
947 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400948 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400949 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200950 }
951
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200952 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400953 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200954 }
955
Dan Williamsef9a2642007-05-25 16:46:33 -0400956 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200957 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400958 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200959 }
960
Dan Williamsef9a2642007-05-25 16:46:33 -0400961 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
962 if (!cfp) {
963 goto out;
964 }
965
966 assoc_req->channel = fwrq->m;
967 ret = 0;
968
Holger Schurig9012b282007-05-25 11:27:16 -0400969out:
Dan Williamsef9a2642007-05-25 16:46:33 -0400970 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;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200980}
981
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200982static 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;
Dan Williams8c512762007-08-02 11:40:45 -0400987 u32 new_rate;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200988 u16 action;
Dan Williams8c512762007-08-02 11:40:45 -0400989 int ret = -EINVAL;
990 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200991
Holger Schurig9012b282007-05-25 11:27:16 -0400992 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -0400993 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200994
Dan Williams8c512762007-08-02 11:40:45 -0400995 /* Auto rate? */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200996 if (vwrq->value == -1) {
Dan Williams8c512762007-08-02 11:40:45 -0400997 action = CMD_ACT_SET_TX_AUTO;
998 adapter->auto_rate = 1;
999 adapter->cur_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001000 } else {
Dan Williams8c512762007-08-02 11:40:45 -04001001 if (vwrq->value % 100000)
1002 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001003
1004 memset(rates, 0, sizeof(rates));
Dan Williams8c512762007-08-02 11:40:45 -04001005 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;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001011 }
1012
Dan Williams8c512762007-08-02 11:40:45 -04001013 adapter->cur_rate = new_rate;
Dan Williamsffcae952007-08-02 11:35:46 -04001014 action = CMD_ACT_SET_TX_FIX_RATE;
Dan Williams8c512762007-08-02 11:40:45 -04001015 adapter->auto_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001016 }
1017
Dan Williams0aef64d2007-08-02 11:31:18 -04001018 ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
1019 action, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001020
Dan Williams8c512762007-08-02 11:40:45 -04001021out:
Holger Schurig9012b282007-05-25 11:27:16 -04001022 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001023 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
Holger Schurig9012b282007-05-25 11:27:16 -04001032 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001033
Dan Williams8c512762007-08-02 11:40:45 -04001034 if (adapter->connect_status == LIBERTAS_CONNECTED) {
1035 vwrq->value = adapter->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001036
Dan Williams8c512762007-08-02 11:40:45 -04001037 if (adapter->auto_rate)
1038 vwrq->fixed = 0;
1039 else
1040 vwrq->fixed = 1;
1041
1042 } else {
1043 vwrq->fixed = 0;
1044 vwrq->value = 0;
1045 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001046
Holger Schurig9012b282007-05-25 11:27:16 -04001047 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001048 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;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001058
Holger Schurig9012b282007-05-25 11:27:16 -04001059 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001060
Dan Williams0dc5a292007-05-10 22:58:02 -04001061 if ( (*uwrq != IW_MODE_ADHOC)
1062 && (*uwrq != IW_MODE_INFRA)
1063 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001064 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001065 ret = -EINVAL;
1066 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001067 }
1068
1069 mutex_lock(&adapter->lock);
1070 assoc_req = wlan_get_association_request(adapter);
1071 if (!assoc_req) {
1072 ret = -ENOMEM;
Dan Williams0dc5a292007-05-10 22:58:02 -04001073 wlan_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001075 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001076 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1077 wlan_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001078 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001079 }
1080 mutex_unlock(&adapter->lock);
1081
Dan Williams0dc5a292007-05-10 22:58:02 -04001082out:
Holger Schurig9012b282007-05-25 11:27:16 -04001083 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001084 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
Holger Schurig9012b282007-05-25 11:27:16 -04001105 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001106
Holger Schurig9012b282007-05-25 11:27:16 -04001107 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001108 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1109
1110 dwrq->flags = 0;
1111
1112 /* Authentication method */
Dan Williams6affe782007-05-10 22:56:42 -04001113 switch (adapter->secinfo.auth_mode) {
1114 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001115 dwrq->flags = IW_ENCODE_OPEN;
1116 break;
1117
Dan Williams6affe782007-05-10 22:56:42 -04001118 case IW_AUTH_ALG_SHARED_KEY:
1119 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001120 dwrq->flags = IW_ENCODE_RESTRICTED;
1121 break;
1122 default:
1123 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1124 break;
1125 }
1126
Dan Williams889c05b2007-05-10 22:57:23 -04001127 if ( adapter->secinfo.wep_enabled
1128 || adapter->secinfo.WPAenabled
1129 || adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001130 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
Dan Williams889c05b2007-05-10 22:57:23 -04001143 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001144 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
Holger Schurig9012b282007-05-25 11:27:16 -04001163 lbs_deb_wext("key: " MAC_FMT ", keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001164 extra[0], extra[1], extra[2],
1165 extra[3], extra[4], extra[5], dwrq->length);
1166
Holger Schurig9012b282007-05-25 11:27:16 -04001167 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001168
Holger Schurig9012b282007-05-25 11:27:16 -04001169 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170 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{
Holger Schurig9012b282007-05-25 11:27:16 -04001189 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001190 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001191
Holger Schurig9012b282007-05-25 11:27:16 -04001192 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001193
1194 /* Paranoid validation of key index */
1195 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001196 ret = -EINVAL;
1197 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001198 }
1199
1200 /* validate max key length */
1201 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001202 ret = -EINVAL;
1203 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001204 }
1205
1206 pkey = &assoc_req->wep_keys[index];
1207
1208 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001209 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001210 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) {
Holger Schurig9012b282007-05-25 11:27:16 -04001221 lbs_deb_wext("key not set, so cannot enable it\n");
1222 ret = -EINVAL;
1223 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001224 }
1225 assoc_req->wep_tx_keyidx = index;
1226 }
1227
Dan Williams889c05b2007-05-10 22:57:23 -04001228 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001229
Holger Schurig9012b282007-05-25 11:27:16 -04001230out:
1231 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1232 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001233}
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
Dan Williams90a42212007-05-25 23:01:24 -04001257 lbs_deb_enter(LBS_DEB_WEXT);
1258
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001259 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001260 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001261
1262 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001263 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001264 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);
Dan Williams90a42212007-05-25 23:01:24 -04001269
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
Dan Williams1443b652007-08-02 10:45:55 -04001277 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001278 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1279 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1280
Dan Williams1443b652007-08-02 10:45:55 -04001281 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001282 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);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001290}
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
Holger Schurig9012b282007-05-25 11:27:16 -04001311 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001312
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);
Dan Williams90a42212007-05-25 23:01:24 -04001322 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001323 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 */
Dan Williams889c05b2007-05-10 22:57:23 -04001337 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001338 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) {
Dan Williams6affe782007-05-10 22:56:42 -04001350 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001351 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001352 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001353 }
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
Holger Schurig9012b282007-05-25 11:27:16 -04001364 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001365 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
Holger Schurig9012b282007-05-25 11:27:16 -04001388 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001389
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) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001405 if (index != 0 || adapter->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001406 goto out;
1407 }
1408
1409 dwrq->flags = index + 1;
1410 memset(ext, 0, sizeof(*ext));
1411
Dan Williams889c05b2007-05-10 22:57:23 -04001412 if ( !adapter->secinfo.wep_enabled
1413 && !adapter->secinfo.WPAenabled
1414 && !adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001415 ext->alg = IW_ENCODE_ALG_NONE;
1416 ext->key_len = 0;
1417 dwrq->flags |= IW_ENCODE_DISABLED;
1418 } else {
1419 u8 *key = NULL;
1420
Dan Williams889c05b2007-05-10 22:57:23 -04001421 if ( adapter->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001422 && !adapter->secinfo.WPAenabled
1423 && !adapter->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001424 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001425 ext->alg = IW_ENCODE_ALG_WEP;
1426 ext->key_len = adapter->wep_keys[index].len;
1427 key = &adapter->wep_keys[index].key[0];
Dan Williams889c05b2007-05-10 22:57:23 -04001428 } else if ( !adapter->secinfo.wep_enabled
1429 && (adapter->secinfo.WPAenabled ||
1430 adapter->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001431 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001432 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001433
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 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001453 } 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:
Holger Schurig9012b282007-05-25 11:27:16 -04001471 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001472 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
Holger Schurig9012b282007-05-25 11:27:16 -04001496 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001497
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);
Dan Williams90a42212007-05-25 23:01:24 -04001507 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508 } 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 */
Dan Williams889c05b2007-05-10 22:57:23 -04001520 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001521 || (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) {
Dan Williams6affe782007-05-10 22:56:42 -04001532 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001533 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001534 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001535 }
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);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001543 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001544 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001545
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))) {
Holger Schurig9012b282007-05-25 11:27:16 -04001551 lbs_deb_wext("invalid size %d for key of alg"
1552 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001553 ext->key_len,
1554 alg);
1555 ret = -EINVAL;
1556 goto out;
1557 }
1558
Dan Williams90a42212007-05-25 23:01:24 -04001559 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001561 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1562 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001563 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001564 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1565 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001566
Dan Williams1443b652007-08-02 10:45:55 -04001567 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001568 memcpy(pkey->key, ext->key, ext->key_len);
1569 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001570 if (pkey->len)
1571 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001572
Dan Williams90a42212007-05-25 23:01:24 -04001573 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001574 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1575 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001576 } else {
1577 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001578 }
1579
Dan Williams90a42212007-05-25 23:01:24 -04001580 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001581 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001582 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001583 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001584 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001585
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
Holger Schurig9012b282007-05-25 11:27:16 -04001605 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001606 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
Holger Schurig9012b282007-05-25 11:27:16 -04001620 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001621
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
Holger Schurig9012b282007-05-25 11:27:16 -04001652 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001653 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{
Holger Schurig9012b282007-05-25 11:27:16 -04001661 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001662 wlan_private *priv = dev->priv;
1663 wlan_adapter *adapter = priv->adapter;
1664
Holger Schurig9012b282007-05-25 11:27:16 -04001665 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001666
1667 if (adapter->wpa_ie_len == 0) {
1668 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001669 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001670 }
1671
1672 if (dwrq->length < adapter->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001673 ret = -E2BIG;
1674 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001675 }
1676
1677 dwrq->length = adapter->wpa_ie_len;
1678 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
1679
Holger Schurig9012b282007-05-25 11:27:16 -04001680out:
1681 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1682 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001683}
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
Holger Schurig9012b282007-05-25 11:27:16 -04001697 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001698
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:
Dan Williams90a42212007-05-25 23:01:24 -04001711 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001712 /*
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;
Dan Williams90a42212007-05-25 23:01:24 -04001721 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001722 }
1723 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1724 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001725 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001726 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001727 }
1728 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1729 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001730 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001731 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001732 }
1733 updated = 1;
1734 break;
1735
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001736 case IW_AUTH_80211_AUTH_ALG:
1737 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001738 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001739 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001740 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001741 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001742 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001743 } 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;
Dan Williams889c05b2007-05-10 22:57:23 -04001755 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001756 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001757 }
1758 } else {
1759 assoc_req->secinfo.WPAenabled = 0;
1760 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001761 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001762 }
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
Holger Schurig9012b282007-05-25 11:27:16 -04001781 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001782 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{
Holger Schurig9012b282007-05-25 11:27:16 -04001790 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001791 wlan_private *priv = dev->priv;
1792 wlan_adapter *adapter = priv->adapter;
1793
Holger Schurig9012b282007-05-25 11:27:16 -04001794 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001795
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
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001807 case IW_AUTH_80211_AUTH_ALG:
Dan Williams6affe782007-05-10 22:56:42 -04001808 dwrq->value = adapter->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001809 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:
Holger Schurig9012b282007-05-25 11:27:16 -04001817 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001818 }
1819
Holger Schurig9012b282007-05-25 11:27:16 -04001820 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1821 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001822}
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
Holger Schurig9012b282007-05-25 11:27:16 -04001834 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001835
1836 if (vwrq->disabled) {
1837 wlan_radio_ioctl(priv, RADIO_OFF);
1838 return 0;
1839 }
1840
Dan Williams0aef64d2007-08-02 11:31:18 -04001841 adapter->preamble = CMD_TYPE_AUTO_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001842
1843 wlan_radio_ioctl(priv, RADIO_ON);
1844
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001845 /* Userspace check in iwrange if it should use dBm or mW,
1846 * therefore this should never happen... Jean II */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001847 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001848 return -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001849 } else
1850 dbm = (u16) vwrq->value;
1851
1852 /* auto tx power control */
1853
1854 if (vwrq->fixed == 0)
1855 dbm = 0xffff;
1856
Holger Schurig9012b282007-05-25 11:27:16 -04001857 lbs_deb_wext("txpower set %d dbm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001858
1859 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -04001860 CMD_802_11_RF_TX_POWER,
1861 CMD_ACT_TX_POWER_OPT_SET_LOW,
1862 CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001863
Holger Schurig9012b282007-05-25 11:27:16 -04001864 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001865 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
Holger Schurig9012b282007-05-25 11:27:16 -04001874 lbs_deb_enter(LBS_DEB_WEXT);
1875
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001876 /*
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 */
Dan Williams0aef64d2007-08-02 11:31:18 -04001884 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Dan Williamsd8efea22007-05-28 23:54:55 -04001885 memcpy(extra, adapter->curbssparams.ssid,
1886 adapter->curbssparams.ssid_len);
1887 extra[adapter->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001888 } else {
1889 memset(extra, 0, 32);
Dan Williamsd8efea22007-05-28 23:54:55 -04001890 extra[adapter->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001891 }
1892 /*
1893 * If none, we may want to get the one that was set
1894 */
1895
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001896 dwrq->length = adapter->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001897
1898 dwrq->flags = 1; /* active */
1899
Holger Schurig9012b282007-05-25 11:27:16 -04001900 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001901 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;
Dan Williamsd8efea22007-05-28 23:54:55 -04001910 u8 ssid[IW_ESSID_MAX_SIZE];
1911 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001912 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001913 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001914
Holger Schurig9012b282007-05-25 11:27:16 -04001915 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001916
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001917 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001918 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001919 ret = -E2BIG;
1920 goto out;
1921 }
1922
Dan Williamsd8efea22007-05-28 23:54:55 -04001923 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001924
Dan Williamsd8efea22007-05-28 23:54:55 -04001925 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001926 /* "any" SSID requested; leave SSID blank */
1927 } else {
1928 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04001929 memcpy(&ssid, extra, in_ssid_len);
1930 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001931 }
1932
Dan Williamsd8efea22007-05-28 23:54:55 -04001933 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 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001939
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 */
Dan Williamsd8efea22007-05-28 23:54:55 -04001949 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1950 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001951 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
Holger Schurig9012b282007-05-25 11:27:16 -04001963 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001964 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;
1983
Holger Schurig9012b282007-05-25 11:27:16 -04001984 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001985
1986 if (awrq->sa_family != ARPHRD_ETHER)
1987 return -EINVAL;
1988
Holger Schurig9012b282007-05-25 11:27:16 -04001989 lbs_deb_wext("ASSOC: WAP: sa_data " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001990
1991 mutex_lock(&adapter->lock);
1992
1993 /* Get or create the current association request */
1994 assoc_req = wlan_get_association_request(adapter);
1995 if (!assoc_req) {
1996 wlan_cancel_association_work(priv);
1997 ret = -ENOMEM;
1998 } else {
1999 /* Copy the BSSID to the association request */
2000 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2001 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2002 wlan_postpone_association_work(priv);
2003 }
2004
2005 mutex_unlock(&adapter->lock);
2006
2007 return ret;
2008}
2009
2010void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
2011{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002012 char fwver[32];
2013
2014 mutex_lock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002015
David Woodhousee5b3d472007-05-25 23:40:21 -04002016 if (adapter->fwreleasenumber[3] == 0)
2017 sprintf(fwver, "%u.%u.%u",
2018 adapter->fwreleasenumber[2],
2019 adapter->fwreleasenumber[1],
2020 adapter->fwreleasenumber[0]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002021 else
2022 sprintf(fwver, "%u.%u.%u.p%u",
David Woodhousee5b3d472007-05-25 23:40:21 -04002023 adapter->fwreleasenumber[2],
2024 adapter->fwreleasenumber[1],
2025 adapter->fwreleasenumber[0],
2026 adapter->fwreleasenumber[3]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002027
David Woodhousee5b3d472007-05-25 23:40:21 -04002028 mutex_unlock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002029 snprintf(fwversion, maxlen, fwver);
2030}
2031
2032
2033/*
2034 * iwconfig settable callbacks
2035 */
2036static const iw_handler wlan_handler[] = {
2037 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2038 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2039 (iw_handler) NULL, /* SIOCSIWNWID */
2040 (iw_handler) NULL, /* SIOCGIWNWID */
2041 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2042 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2043 (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
2044 (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
2045 (iw_handler) NULL, /* SIOCSIWSENS */
2046 (iw_handler) NULL, /* SIOCGIWSENS */
2047 (iw_handler) NULL, /* SIOCSIWRANGE */
2048 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2049 (iw_handler) NULL, /* SIOCSIWPRIV */
2050 (iw_handler) NULL, /* SIOCGIWPRIV */
2051 (iw_handler) NULL, /* SIOCSIWSTATS */
2052 (iw_handler) NULL, /* SIOCGIWSTATS */
2053 iw_handler_set_spy, /* SIOCSIWSPY */
2054 iw_handler_get_spy, /* SIOCGIWSPY */
2055 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2056 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2057 (iw_handler) wlan_set_wap, /* SIOCSIWAP */
2058 (iw_handler) wlan_get_wap, /* SIOCGIWAP */
2059 (iw_handler) NULL, /* SIOCSIWMLME */
2060 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2061 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2062 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2063 (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
2064 (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
2065 (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
2066 (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
2067 (iw_handler) NULL, /* -- hole -- */
2068 (iw_handler) NULL, /* -- hole -- */
2069 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2070 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2071 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2072 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2073 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2074 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2075 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2076 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2077 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2078 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2079 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2080 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2081 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2082 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2083 (iw_handler) NULL, /* -- hole -- */
2084 (iw_handler) NULL, /* -- hole -- */
2085 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2086 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2087 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2088 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2089 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2090 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2091 (iw_handler) NULL, /* SIOCSIWPMKSA */
2092};
2093
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002094static const iw_handler mesh_wlan_handler[] = {
2095 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2096 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2097 (iw_handler) NULL, /* SIOCSIWNWID */
2098 (iw_handler) NULL, /* SIOCGIWNWID */
2099 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2100 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2101 (iw_handler) NULL, /* SIOCSIWMODE */
2102 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2103 (iw_handler) NULL, /* SIOCSIWSENS */
2104 (iw_handler) NULL, /* SIOCGIWSENS */
2105 (iw_handler) NULL, /* SIOCSIWRANGE */
2106 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2107 (iw_handler) NULL, /* SIOCSIWPRIV */
2108 (iw_handler) NULL, /* SIOCGIWPRIV */
2109 (iw_handler) NULL, /* SIOCSIWSTATS */
2110 (iw_handler) NULL, /* SIOCGIWSTATS */
2111 iw_handler_set_spy, /* SIOCSIWSPY */
2112 iw_handler_get_spy, /* SIOCGIWSPY */
2113 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2114 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2115 (iw_handler) NULL, /* SIOCSIWAP */
2116 (iw_handler) NULL, /* SIOCGIWAP */
2117 (iw_handler) NULL, /* SIOCSIWMLME */
2118 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2119 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2120 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2121 (iw_handler) NULL, /* SIOCSIWESSID */
2122 (iw_handler) NULL, /* SIOCGIWESSID */
2123 (iw_handler) NULL, /* SIOCSIWNICKN */
2124 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2125 (iw_handler) NULL, /* -- hole -- */
2126 (iw_handler) NULL, /* -- hole -- */
2127 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2128 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2129 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2130 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2131 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2132 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2133 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2134 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2135 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2136 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2137 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2138 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2139 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2140 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2141 (iw_handler) NULL, /* -- hole -- */
2142 (iw_handler) NULL, /* -- hole -- */
2143 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2144 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2145 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2146 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2147 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2148 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2149 (iw_handler) NULL, /* SIOCSIWPMKSA */
2150};
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002151struct iw_handler_def libertas_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002152 .num_standard = ARRAY_SIZE(wlan_handler),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002153 .standard = (iw_handler *) wlan_handler,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002154 .get_wireless_stats = wlan_get_wireless_stats,
2155};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002156
2157struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002158 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002159 .standard = (iw_handler *) mesh_wlan_handler,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002160 .get_wireless_stats = wlan_get_wireless_stats,
2161};