blob: 395b7882d4d65f1e33ee074913e026ca71394812 [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{
Holger Schurig04799fa2007-10-09 15:04:14 +0200240 wlan_private *priv = dev->priv;
241 wlan_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200242
Holger Schurig9012b282007-05-25 11:27:16 -0400243 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244
Holger Schurig04799fa2007-10-09 15:04:14 +0200245 dwrq->length = strlen(adapter->nodename);
246 memcpy(extra, adapter->nodename, dwrq->length);
247 extra[dwrq->length] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200248
Holger Schurig04799fa2007-10-09 15:04:14 +0200249 dwrq->flags = 1; /* active */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200250
Holger Schurig9012b282007-05-25 11:27:16 -0400251 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200252 return 0;
253}
254
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400255static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
256 struct iw_point *dwrq, char *extra)
257{
258 wlan_private *priv = dev->priv;
259 wlan_adapter *adapter = priv->adapter;
260
261 lbs_deb_enter(LBS_DEB_WEXT);
262
263 /* Use nickname to indicate that mesh is on */
264
Dan Williams0aef64d2007-08-02 11:31:18 -0400265 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400266 strncpy(extra, "Mesh", 12);
267 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400268 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400269 }
270
271 else {
272 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400273 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400274 }
275
276 lbs_deb_leave(LBS_DEB_WEXT);
277 return 0;
278}
Holger Schurig04799fa2007-10-09 15:04:14 +0200279
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
281 struct iw_param *vwrq, char *extra)
282{
283 int ret = 0;
284 wlan_private *priv = dev->priv;
285 wlan_adapter *adapter = priv->adapter;
David Woodhouse981f1872007-05-25 23:36:54 -0400286 u32 rthr = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200287
Holger Schurig9012b282007-05-25 11:27:16 -0400288 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200289
290 if (vwrq->disabled) {
291 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
292 } else {
293 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
294 return -EINVAL;
295 adapter->rtsthsd = rthr;
296 }
297
Dan Williams0aef64d2007-08-02 11:31:18 -0400298 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
299 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300 OID_802_11_RTS_THRESHOLD, &rthr);
301
Holger Schurig9012b282007-05-25 11:27:16 -0400302 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200303 return ret;
304}
305
306static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
307 struct iw_param *vwrq, char *extra)
308{
309 int ret = 0;
310 wlan_private *priv = dev->priv;
311 wlan_adapter *adapter = priv->adapter;
312
Holger Schurig9012b282007-05-25 11:27:16 -0400313 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314
315 adapter->rtsthsd = 0;
Dan Williams0aef64d2007-08-02 11:31:18 -0400316 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
317 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200318 OID_802_11_RTS_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400319 if (ret)
320 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200321
322 vwrq->value = adapter->rtsthsd;
323 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
324 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
325 vwrq->fixed = 1;
326
Holger Schurig9012b282007-05-25 11:27:16 -0400327out:
328 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
329 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200330}
331
332static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
333 struct iw_param *vwrq, char *extra)
334{
335 int ret = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400336 u32 fthr = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200337 wlan_private *priv = dev->priv;
338 wlan_adapter *adapter = priv->adapter;
339
Holger Schurig9012b282007-05-25 11:27:16 -0400340 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200341
342 if (vwrq->disabled) {
343 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
344 } else {
345 if (fthr < MRVDRV_FRAG_MIN_VALUE
346 || fthr > MRVDRV_FRAG_MAX_VALUE)
347 return -EINVAL;
348 adapter->fragthsd = fthr;
349 }
350
Dan Williams0aef64d2007-08-02 11:31:18 -0400351 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
352 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
Holger Schurig9012b282007-05-25 11:27:16 -0400354
355 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200356 return ret;
357}
358
359static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
360 struct iw_param *vwrq, char *extra)
361{
362 int ret = 0;
363 wlan_private *priv = dev->priv;
364 wlan_adapter *adapter = priv->adapter;
365
Holger Schurig9012b282007-05-25 11:27:16 -0400366 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200367
368 adapter->fragthsd = 0;
369 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400370 CMD_802_11_SNMP_MIB,
371 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200372 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400373 if (ret)
374 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200375
376 vwrq->value = adapter->fragthsd;
377 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
378 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
379 vwrq->fixed = 1;
380
Holger Schurig9012b282007-05-25 11:27:16 -0400381out:
382 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383 return ret;
384}
385
386static int wlan_get_mode(struct net_device *dev,
387 struct iw_request_info *info, u32 * uwrq, char *extra)
388{
389 wlan_private *priv = dev->priv;
390 wlan_adapter *adapter = priv->adapter;
391
Holger Schurig9012b282007-05-25 11:27:16 -0400392 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200393
Dan Williams0dc5a292007-05-10 22:58:02 -0400394 *uwrq = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200395
Holger Schurig9012b282007-05-25 11:27:16 -0400396 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397 return 0;
398}
399
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400400static int mesh_wlan_get_mode(struct net_device *dev,
401 struct iw_request_info *info, u32 * uwrq,
402 char *extra)
403{
404 lbs_deb_enter(LBS_DEB_WEXT);
405
406 *uwrq = IW_MODE_REPEAT ;
407
408 lbs_deb_leave(LBS_DEB_WEXT);
409 return 0;
410}
411
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200412static int wlan_get_txpow(struct net_device *dev,
413 struct iw_request_info *info,
414 struct iw_param *vwrq, char *extra)
415{
416 int ret = 0;
417 wlan_private *priv = dev->priv;
418 wlan_adapter *adapter = priv->adapter;
419
Holger Schurig9012b282007-05-25 11:27:16 -0400420 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200421
422 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400423 CMD_802_11_RF_TX_POWER,
424 CMD_ACT_TX_POWER_OPT_GET,
425 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426
Holger Schurig9012b282007-05-25 11:27:16 -0400427 if (ret)
428 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200429
Holger Schurig9012b282007-05-25 11:27:16 -0400430 lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431 vwrq->value = adapter->txpowerlevel;
432 vwrq->fixed = 1;
433 if (adapter->radioon) {
434 vwrq->disabled = 0;
435 vwrq->flags = IW_TXPOW_DBM;
436 } else {
437 vwrq->disabled = 1;
438 }
439
Holger Schurig9012b282007-05-25 11:27:16 -0400440out:
441 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
442 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200443}
444
445static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
446 struct iw_param *vwrq, char *extra)
447{
448 int ret = 0;
449 wlan_private *priv = dev->priv;
450 wlan_adapter *adapter = priv->adapter;
451
Holger Schurig9012b282007-05-25 11:27:16 -0400452 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200453
454 if (vwrq->flags == IW_RETRY_LIMIT) {
455 /* The MAC has a 4-bit Total_Tx_Count register
456 Total_Tx_Count = 1 + Tx_Retry_Count */
457#define TX_RETRY_MIN 0
458#define TX_RETRY_MAX 14
459 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
460 return -EINVAL;
461
462 /* Adding 1 to convert retry count to try count */
463 adapter->txretrycount = vwrq->value + 1;
464
Dan Williams0aef64d2007-08-02 11:31:18 -0400465 ret = libertas_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
466 CMD_ACT_SET,
467 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468 OID_802_11_TX_RETRYCOUNT, NULL);
469
Holger Schurig9012b282007-05-25 11:27:16 -0400470 if (ret)
471 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472 } else {
473 return -EOPNOTSUPP;
474 }
475
Holger Schurig9012b282007-05-25 11:27:16 -0400476out:
477 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
478 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200479}
480
481static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
482 struct iw_param *vwrq, char *extra)
483{
484 wlan_private *priv = dev->priv;
485 wlan_adapter *adapter = priv->adapter;
486 int ret = 0;
487
Holger Schurig9012b282007-05-25 11:27:16 -0400488 lbs_deb_enter(LBS_DEB_WEXT);
489
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200490 adapter->txretrycount = 0;
491 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400492 CMD_802_11_SNMP_MIB,
493 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200494 OID_802_11_TX_RETRYCOUNT, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400495 if (ret)
496 goto out;
497
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200498 vwrq->disabled = 0;
499 if (!vwrq->flags) {
500 vwrq->flags = IW_RETRY_LIMIT;
501 /* Subtract 1 to convert try count to retry count */
502 vwrq->value = adapter->txretrycount - 1;
503 }
504
Holger Schurig9012b282007-05-25 11:27:16 -0400505out:
506 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
507 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200508}
509
510static inline void sort_channels(struct iw_freq *freq, int num)
511{
512 int i, j;
513 struct iw_freq temp;
514
515 for (i = 0; i < num; i++)
516 for (j = i + 1; j < num; j++)
517 if (freq[i].i > freq[j].i) {
518 temp.i = freq[i].i;
519 temp.m = freq[i].m;
520
521 freq[i].i = freq[j].i;
522 freq[i].m = freq[j].m;
523
524 freq[j].i = temp.i;
525 freq[j].m = temp.m;
526 }
527}
528
529/* data rate listing
530 MULTI_BANDS:
531 abg a b b/g
532 Infra G(12) A(8) B(4) G(12)
533 Adhoc A+B(12) A(8) B(4) B(4)
534
535 non-MULTI_BANDS:
536 b b/g
537 Infra B(4) G(12)
538 Adhoc B(4) B(4)
539 */
540/**
541 * @brief Get Range Info
542 *
543 * @param dev A pointer to net_device structure
544 * @param info A pointer to iw_request_info structure
545 * @param vwrq A pointer to iw_param structure
546 * @param extra A pointer to extra data buf
547 * @return 0 --success, otherwise fail
548 */
549static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
550 struct iw_point *dwrq, char *extra)
551{
552 int i, j;
553 wlan_private *priv = dev->priv;
554 wlan_adapter *adapter = priv->adapter;
555 struct iw_range *range = (struct iw_range *)extra;
556 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400557 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200558
559 u8 flag = 0;
560
Holger Schurig9012b282007-05-25 11:27:16 -0400561 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200562
563 dwrq->length = sizeof(struct iw_range);
564 memset(range, 0, sizeof(struct iw_range));
565
566 range->min_nwid = 0;
567 range->max_nwid = 0;
568
569 memset(rates, 0, sizeof(rates));
Dan Williams8c512762007-08-02 11:40:45 -0400570 copy_active_data_rates(adapter, rates);
571 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
572 for (i = 0; i < range->num_bitrates; i++)
573 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200574 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400575 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576 range->num_bitrates);
577
578 range->num_frequency = 0;
579 if (priv->adapter->enable11d &&
Dan Williams0aef64d2007-08-02 11:31:18 -0400580 adapter->connect_status == LIBERTAS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200581 u8 chan_no;
582 u8 band;
583
584 struct parsed_region_chan_11d *parsed_region_chan =
585 &adapter->parsed_region_chan;
586
587 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400588 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
589 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200590 }
591 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400592 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593 parsed_region_chan->nr_chan);
594
595 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
596 && (i < parsed_region_chan->nr_chan); i++) {
597 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400598 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599 range->freq[range->num_frequency].i = (long)chan_no;
600 range->freq[range->num_frequency].m =
601 (long)libertas_chan_2_freq(chan_no, band) * 100000;
602 range->freq[range->num_frequency].e = 1;
603 range->num_frequency++;
604 }
605 flag = 1;
606 }
607 if (!flag) {
608 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
609 && (j < sizeof(adapter->region_channel)
610 / sizeof(adapter->region_channel[0])); j++) {
611 cfp = adapter->region_channel[j].CFP;
612 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
613 && adapter->region_channel[j].valid
614 && cfp
615 && (i < adapter->region_channel[j].nrcfp); i++) {
616 range->freq[range->num_frequency].i =
617 (long)cfp->channel;
618 range->freq[range->num_frequency].m =
619 (long)cfp->freq * 100000;
620 range->freq[range->num_frequency].e = 1;
621 cfp++;
622 range->num_frequency++;
623 }
624 }
625 }
626
Holger Schurig9012b282007-05-25 11:27:16 -0400627 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200628 IW_MAX_FREQUENCIES, range->num_frequency);
629
630 range->num_channels = range->num_frequency;
631
632 sort_channels(&range->freq[0], range->num_frequency);
633
634 /*
635 * Set an indication of the max TCP throughput in bit/s that we can
636 * expect using this interface
637 */
638 if (i > 2)
639 range->throughput = 5000 * 1000;
640 else
641 range->throughput = 1500 * 1000;
642
643 range->min_rts = MRVDRV_RTS_MIN_VALUE;
644 range->max_rts = MRVDRV_RTS_MAX_VALUE;
645 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
646 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
647
648 range->encoding_size[0] = 5;
649 range->encoding_size[1] = 13;
650 range->num_encoding_sizes = 2;
651 range->max_encoding_tokens = 4;
652
653 range->min_pmp = 1000000;
654 range->max_pmp = 120000000;
655 range->min_pmt = 1000;
656 range->max_pmt = 1000000;
657 range->pmp_flags = IW_POWER_PERIOD;
658 range->pmt_flags = IW_POWER_TIMEOUT;
659 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
660
661 /*
662 * Minimum version we recommend
663 */
664 range->we_version_source = 15;
665
666 /*
667 * Version we are compiled with
668 */
669 range->we_version_compiled = WIRELESS_EXT;
670
671 range->retry_capa = IW_RETRY_LIMIT;
672 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
673
674 range->min_retry = TX_RETRY_MIN;
675 range->max_retry = TX_RETRY_MAX;
676
677 /*
678 * Set the qual, level and noise range values
679 */
680 range->max_qual.qual = 100;
681 range->max_qual.level = 0;
682 range->max_qual.noise = 0;
683 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
684
685 range->avg_qual.qual = 70;
686 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
687 range->avg_qual.level = 0;
688 range->avg_qual.noise = 0;
689 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
690
691 range->sensitivity = 0;
692
693 /*
694 * Setup the supported power level ranges
695 */
696 memset(range->txpower, 0, sizeof(range->txpower));
697 range->txpower[0] = 5;
698 range->txpower[1] = 7;
699 range->txpower[2] = 9;
700 range->txpower[3] = 11;
701 range->txpower[4] = 13;
702 range->txpower[5] = 15;
703 range->txpower[6] = 17;
704 range->txpower[7] = 19;
705
706 range->num_txpower = 8;
707 range->txpower_capa = IW_TXPOW_DBM;
708 range->txpower_capa |= IW_TXPOW_RANGE;
709
710 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
711 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
712 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
713 range->event_capa[1] = IW_EVENT_CAPA_K_1;
714
715 if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
716 range->enc_capa = IW_ENC_CAPA_WPA
717 | IW_ENC_CAPA_WPA2
718 | IW_ENC_CAPA_CIPHER_TKIP
719 | IW_ENC_CAPA_CIPHER_CCMP;
720 }
721
Holger Schurig9012b282007-05-25 11:27:16 -0400722out:
723 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724 return 0;
725}
726
727static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
728 struct iw_param *vwrq, char *extra)
729{
730 wlan_private *priv = dev->priv;
731 wlan_adapter *adapter = priv->adapter;
732
Holger Schurig9012b282007-05-25 11:27:16 -0400733 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200734
735 /* PS is currently supported only in Infrastructure mode
736 * Remove this check if it is to be supported in IBSS mode also
737 */
738
739 if (vwrq->disabled) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400740 adapter->psmode = WLAN802_11POWERMODECAM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741 if (adapter->psstate != PS_STATE_FULL_POWER) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400742 libertas_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200743 }
744
745 return 0;
746 }
747
748 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400749 lbs_deb_wext(
750 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200751 return -EINVAL;
752 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400753 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200754 return -EINVAL;
755 }
756
Dan Williams0aef64d2007-08-02 11:31:18 -0400757 if (adapter->psmode != WLAN802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200758 return 0;
759 }
760
Dan Williams0aef64d2007-08-02 11:31:18 -0400761 adapter->psmode = WLAN802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762
Dan Williams0aef64d2007-08-02 11:31:18 -0400763 if (adapter->connect_status == LIBERTAS_CONNECTED) {
764 libertas_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200765 }
766
Holger Schurig9012b282007-05-25 11:27:16 -0400767 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200768 return 0;
769}
770
771static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
772 struct iw_param *vwrq, char *extra)
773{
774 wlan_private *priv = dev->priv;
775 wlan_adapter *adapter = priv->adapter;
776 int mode;
777
Holger Schurig9012b282007-05-25 11:27:16 -0400778 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200779
780 mode = adapter->psmode;
781
Dan Williams0aef64d2007-08-02 11:31:18 -0400782 if ((vwrq->disabled = (mode == WLAN802_11POWERMODECAM))
783 || adapter->connect_status == LIBERTAS_DISCONNECTED)
Holger Schurig9012b282007-05-25 11:27:16 -0400784 {
785 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200786 }
787
788 vwrq->value = 0;
789
Holger Schurig9012b282007-05-25 11:27:16 -0400790out:
791 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200792 return 0;
793}
794
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200795static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
796{
797 enum {
798 POOR = 30,
799 FAIR = 60,
800 GOOD = 80,
801 VERY_GOOD = 90,
802 EXCELLENT = 95,
803 PERFECT = 100
804 };
805 wlan_private *priv = dev->priv;
806 wlan_adapter *adapter = priv->adapter;
807 u32 rssi_qual;
808 u32 tx_qual;
809 u32 quality = 0;
810 int stats_valid = 0;
811 u8 rssi;
812 u32 tx_retries;
813
Holger Schurig9012b282007-05-25 11:27:16 -0400814 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200815
Dan Williams0dc5a292007-05-10 22:58:02 -0400816 priv->wstats.status = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200817
818 /* If we're not associated, all quality values are meaningless */
Dan Williams0aef64d2007-08-02 11:31:18 -0400819 if (adapter->connect_status != LIBERTAS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820 goto out;
821
822 /* Quality by RSSI */
823 priv->wstats.qual.level =
824 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
825 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
826
827 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
828 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
829 } else {
830 priv->wstats.qual.noise =
831 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
832 }
833
Holger Schurig9012b282007-05-25 11:27:16 -0400834 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
835 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200836
837 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
838 if (rssi < 15)
839 rssi_qual = rssi * POOR / 10;
840 else if (rssi < 20)
841 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
842 else if (rssi < 30)
843 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
844 else if (rssi < 40)
845 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
846 10 + GOOD;
847 else
848 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
849 10 + VERY_GOOD;
850 quality = rssi_qual;
851
852 /* Quality by TX errors */
853 priv->wstats.discard.retries = priv->stats.tx_errors;
854
Dan Williams8362cd42007-08-03 09:40:55 -0400855 tx_retries = le32_to_cpu(adapter->logmsg.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856
857 if (tx_retries > 75)
858 tx_qual = (90 - tx_retries) * POOR / 15;
859 else if (tx_retries > 70)
860 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
861 else if (tx_retries > 65)
862 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
863 else if (tx_retries > 50)
864 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
865 15 + GOOD;
866 else
867 tx_qual = (50 - tx_retries) *
868 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
869 quality = min(quality, tx_qual);
870
Dan Williams8362cd42007-08-03 09:40:55 -0400871 priv->wstats.discard.code = le32_to_cpu(adapter->logmsg.wepundecryptable);
872 priv->wstats.discard.fragment = le32_to_cpu(adapter->logmsg.rxfrag);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200873 priv->wstats.discard.retries = tx_retries;
Dan Williams8362cd42007-08-03 09:40:55 -0400874 priv->wstats.discard.misc = le32_to_cpu(adapter->logmsg.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200875
876 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400877 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200878 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
879 stats_valid = 1;
880
881 /* update stats asynchronously for future calls */
Dan Williams0aef64d2007-08-02 11:31:18 -0400882 libertas_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200883 0, 0, NULL);
Dan Williams0aef64d2007-08-02 11:31:18 -0400884 libertas_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200885 0, 0, NULL);
886out:
887 if (!stats_valid) {
888 priv->wstats.miss.beacon = 0;
889 priv->wstats.discard.retries = 0;
890 priv->wstats.qual.qual = 0;
891 priv->wstats.qual.level = 0;
892 priv->wstats.qual.noise = 0;
893 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
894 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
895 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
896 }
897
Holger Schurig9012b282007-05-25 11:27:16 -0400898 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200899 return &priv->wstats;
900
901
902}
903
904static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
905 struct iw_freq *fwrq, char *extra)
906{
Dan Williamsef9a2642007-05-25 16:46:33 -0400907 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200908 wlan_private *priv = dev->priv;
909 wlan_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200910 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400911 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200912
Holger Schurig9012b282007-05-25 11:27:16 -0400913 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200914
Dan Williamsef9a2642007-05-25 16:46:33 -0400915 mutex_lock(&adapter->lock);
916 assoc_req = wlan_get_association_request(adapter);
917 if (!assoc_req) {
918 ret = -ENOMEM;
919 goto out;
920 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200921
Dan Williamsef9a2642007-05-25 16:46:33 -0400922 /* If setting by frequency, convert to a channel */
923 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200924 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200925
926 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
927 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400928 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400929 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200930 }
931
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200932 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400933 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200934 }
935
Dan Williamsef9a2642007-05-25 16:46:33 -0400936 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200937 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400938 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200939 }
940
Dan Williamsef9a2642007-05-25 16:46:33 -0400941 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
942 if (!cfp) {
943 goto out;
944 }
945
946 assoc_req->channel = fwrq->m;
947 ret = 0;
948
Holger Schurig9012b282007-05-25 11:27:16 -0400949out:
Dan Williamsef9a2642007-05-25 16:46:33 -0400950 if (ret == 0) {
951 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
952 wlan_postpone_association_work(priv);
953 } else {
954 wlan_cancel_association_work(priv);
955 }
956 mutex_unlock(&adapter->lock);
957
958 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
959 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200960}
961
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200962static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
963 struct iw_param *vwrq, char *extra)
964{
965 wlan_private *priv = dev->priv;
966 wlan_adapter *adapter = priv->adapter;
Dan Williams8c512762007-08-02 11:40:45 -0400967 u32 new_rate;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200968 u16 action;
Dan Williams8c512762007-08-02 11:40:45 -0400969 int ret = -EINVAL;
970 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200971
Holger Schurig9012b282007-05-25 11:27:16 -0400972 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -0400973 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200974
Dan Williams8c512762007-08-02 11:40:45 -0400975 /* Auto rate? */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200976 if (vwrq->value == -1) {
Dan Williams8c512762007-08-02 11:40:45 -0400977 action = CMD_ACT_SET_TX_AUTO;
978 adapter->auto_rate = 1;
979 adapter->cur_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200980 } else {
Dan Williams8c512762007-08-02 11:40:45 -0400981 if (vwrq->value % 100000)
982 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200983
984 memset(rates, 0, sizeof(rates));
Dan Williams8c512762007-08-02 11:40:45 -0400985 copy_active_data_rates(adapter, rates);
986 new_rate = vwrq->value / 500000;
987 if (!memchr(rates, new_rate, sizeof(rates))) {
988 lbs_pr_alert("fixed data rate 0x%X out of range\n",
989 new_rate);
990 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200991 }
992
Dan Williams8c512762007-08-02 11:40:45 -0400993 adapter->cur_rate = new_rate;
Dan Williamsffcae952007-08-02 11:35:46 -0400994 action = CMD_ACT_SET_TX_FIX_RATE;
Dan Williams8c512762007-08-02 11:40:45 -0400995 adapter->auto_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200996 }
997
Dan Williams0aef64d2007-08-02 11:31:18 -0400998 ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
999 action, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001000
Dan Williams8c512762007-08-02 11:40:45 -04001001out:
Holger Schurig9012b282007-05-25 11:27:16 -04001002 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001003 return ret;
1004}
1005
1006static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
1007 struct iw_param *vwrq, char *extra)
1008{
1009 wlan_private *priv = dev->priv;
1010 wlan_adapter *adapter = priv->adapter;
1011
Holger Schurig9012b282007-05-25 11:27:16 -04001012 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001013
Dan Williams8c512762007-08-02 11:40:45 -04001014 if (adapter->connect_status == LIBERTAS_CONNECTED) {
1015 vwrq->value = adapter->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001016
Dan Williams8c512762007-08-02 11:40:45 -04001017 if (adapter->auto_rate)
1018 vwrq->fixed = 0;
1019 else
1020 vwrq->fixed = 1;
1021
1022 } else {
1023 vwrq->fixed = 0;
1024 vwrq->value = 0;
1025 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001026
Holger Schurig9012b282007-05-25 11:27:16 -04001027 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001028 return 0;
1029}
1030
1031static int wlan_set_mode(struct net_device *dev,
1032 struct iw_request_info *info, u32 * uwrq, char *extra)
1033{
1034 int ret = 0;
1035 wlan_private *priv = dev->priv;
1036 wlan_adapter *adapter = priv->adapter;
1037 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001038
Holger Schurig9012b282007-05-25 11:27:16 -04001039 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001040
Dan Williams0dc5a292007-05-10 22:58:02 -04001041 if ( (*uwrq != IW_MODE_ADHOC)
1042 && (*uwrq != IW_MODE_INFRA)
1043 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001044 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001045 ret = -EINVAL;
1046 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001047 }
1048
1049 mutex_lock(&adapter->lock);
1050 assoc_req = wlan_get_association_request(adapter);
1051 if (!assoc_req) {
1052 ret = -ENOMEM;
Dan Williams0dc5a292007-05-10 22:58:02 -04001053 wlan_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001054 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001055 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001056 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1057 wlan_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001058 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001059 }
1060 mutex_unlock(&adapter->lock);
1061
Dan Williams0dc5a292007-05-10 22:58:02 -04001062out:
Holger Schurig9012b282007-05-25 11:27:16 -04001063 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064 return ret;
1065}
1066
1067
1068/**
1069 * @brief Get Encryption key
1070 *
1071 * @param dev A pointer to net_device structure
1072 * @param info A pointer to iw_request_info structure
1073 * @param vwrq A pointer to iw_param structure
1074 * @param extra A pointer to extra data buf
1075 * @return 0 --success, otherwise fail
1076 */
1077static int wlan_get_encode(struct net_device *dev,
1078 struct iw_request_info *info,
1079 struct iw_point *dwrq, u8 * extra)
1080{
1081 wlan_private *priv = dev->priv;
1082 wlan_adapter *adapter = priv->adapter;
1083 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1084
Holger Schurig9012b282007-05-25 11:27:16 -04001085 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001086
Holger Schurig9012b282007-05-25 11:27:16 -04001087 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001088 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1089
1090 dwrq->flags = 0;
1091
1092 /* Authentication method */
Dan Williams6affe782007-05-10 22:56:42 -04001093 switch (adapter->secinfo.auth_mode) {
1094 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001095 dwrq->flags = IW_ENCODE_OPEN;
1096 break;
1097
Dan Williams6affe782007-05-10 22:56:42 -04001098 case IW_AUTH_ALG_SHARED_KEY:
1099 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001100 dwrq->flags = IW_ENCODE_RESTRICTED;
1101 break;
1102 default:
1103 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1104 break;
1105 }
1106
Dan Williams889c05b2007-05-10 22:57:23 -04001107 if ( adapter->secinfo.wep_enabled
1108 || adapter->secinfo.WPAenabled
1109 || adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001110 dwrq->flags &= ~IW_ENCODE_DISABLED;
1111 } else {
1112 dwrq->flags |= IW_ENCODE_DISABLED;
1113 }
1114
1115 memset(extra, 0, 16);
1116
1117 mutex_lock(&adapter->lock);
1118
1119 /* Default to returning current transmit key */
1120 if (index < 0)
1121 index = adapter->wep_tx_keyidx;
1122
Dan Williams889c05b2007-05-10 22:57:23 -04001123 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001124 memcpy(extra, adapter->wep_keys[index].key,
1125 adapter->wep_keys[index].len);
1126 dwrq->length = adapter->wep_keys[index].len;
1127
1128 dwrq->flags |= (index + 1);
1129 /* Return WEP enabled */
1130 dwrq->flags &= ~IW_ENCODE_DISABLED;
1131 } else if ((adapter->secinfo.WPAenabled)
1132 || (adapter->secinfo.WPA2enabled)) {
1133 /* return WPA enabled */
1134 dwrq->flags &= ~IW_ENCODE_DISABLED;
1135 } else {
1136 dwrq->flags |= IW_ENCODE_DISABLED;
1137 }
1138
1139 mutex_unlock(&adapter->lock);
1140
1141 dwrq->flags |= IW_ENCODE_NOKEY;
1142
Joe Perches0795af52007-10-03 17:59:30 -07001143 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001144 extra[0], extra[1], extra[2],
1145 extra[3], extra[4], extra[5], dwrq->length);
1146
Holger Schurig9012b282007-05-25 11:27:16 -04001147 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001148
Holger Schurig9012b282007-05-25 11:27:16 -04001149 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001150 return 0;
1151}
1152
1153/**
1154 * @brief Set Encryption key (internal)
1155 *
1156 * @param priv A pointer to private card structure
1157 * @param key_material A pointer to key material
1158 * @param key_length length of key material
1159 * @param index key index to set
1160 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1161 * @return 0 --success, otherwise fail
1162 */
1163static int wlan_set_wep_key(struct assoc_request *assoc_req,
1164 const char *key_material,
1165 u16 key_length,
1166 u16 index,
1167 int set_tx_key)
1168{
Holger Schurig9012b282007-05-25 11:27:16 -04001169 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001170 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001171
Holger Schurig9012b282007-05-25 11:27:16 -04001172 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001173
1174 /* Paranoid validation of key index */
1175 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001176 ret = -EINVAL;
1177 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001178 }
1179
1180 /* validate max key length */
1181 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001182 ret = -EINVAL;
1183 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001184 }
1185
1186 pkey = &assoc_req->wep_keys[index];
1187
1188 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001189 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001190 pkey->type = KEY_TYPE_ID_WEP;
1191
1192 /* Standardize the key length */
1193 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1194 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1195 memcpy(pkey->key, key_material, key_length);
1196 }
1197
1198 if (set_tx_key) {
1199 /* Ensure the chosen key is valid */
1200 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001201 lbs_deb_wext("key not set, so cannot enable it\n");
1202 ret = -EINVAL;
1203 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001204 }
1205 assoc_req->wep_tx_keyidx = index;
1206 }
1207
Dan Williams889c05b2007-05-10 22:57:23 -04001208 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001209
Holger Schurig9012b282007-05-25 11:27:16 -04001210out:
1211 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1212 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001213}
1214
1215static int validate_key_index(u16 def_index, u16 raw_index,
1216 u16 *out_index, u16 *is_default)
1217{
1218 if (!out_index || !is_default)
1219 return -EINVAL;
1220
1221 /* Verify index if present, otherwise use default TX key index */
1222 if (raw_index > 0) {
1223 if (raw_index > 4)
1224 return -EINVAL;
1225 *out_index = raw_index - 1;
1226 } else {
1227 *out_index = def_index;
1228 *is_default = 1;
1229 }
1230 return 0;
1231}
1232
1233static void disable_wep(struct assoc_request *assoc_req)
1234{
1235 int i;
1236
Dan Williams90a42212007-05-25 23:01:24 -04001237 lbs_deb_enter(LBS_DEB_WEXT);
1238
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001239 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001240 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001241
1242 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001243 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001244 for (i = 0; i < 4; i++)
1245 assoc_req->wep_keys[i].len = 0;
1246
1247 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1248 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001249
1250 lbs_deb_leave(LBS_DEB_WEXT);
1251}
1252
1253static void disable_wpa(struct assoc_request *assoc_req)
1254{
1255 lbs_deb_enter(LBS_DEB_WEXT);
1256
Dan Williams1443b652007-08-02 10:45:55 -04001257 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001258 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1259 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1260
Dan Williams1443b652007-08-02 10:45:55 -04001261 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001262 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1263 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1264
1265 assoc_req->secinfo.WPAenabled = 0;
1266 assoc_req->secinfo.WPA2enabled = 0;
1267 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1268
1269 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001270}
1271
1272/**
1273 * @brief Set Encryption key
1274 *
1275 * @param dev A pointer to net_device structure
1276 * @param info A pointer to iw_request_info structure
1277 * @param vwrq A pointer to iw_param structure
1278 * @param extra A pointer to extra data buf
1279 * @return 0 --success, otherwise fail
1280 */
1281static int wlan_set_encode(struct net_device *dev,
1282 struct iw_request_info *info,
1283 struct iw_point *dwrq, char *extra)
1284{
1285 int ret = 0;
1286 wlan_private *priv = dev->priv;
1287 wlan_adapter *adapter = priv->adapter;
1288 struct assoc_request * assoc_req;
1289 u16 is_default = 0, index = 0, set_tx_key = 0;
1290
Holger Schurig9012b282007-05-25 11:27:16 -04001291 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001292
1293 mutex_lock(&adapter->lock);
1294 assoc_req = wlan_get_association_request(adapter);
1295 if (!assoc_req) {
1296 ret = -ENOMEM;
1297 goto out;
1298 }
1299
1300 if (dwrq->flags & IW_ENCODE_DISABLED) {
1301 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001302 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001303 goto out;
1304 }
1305
1306 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1307 (dwrq->flags & IW_ENCODE_INDEX),
1308 &index, &is_default);
1309 if (ret) {
1310 ret = -EINVAL;
1311 goto out;
1312 }
1313
1314 /* If WEP isn't enabled, or if there is no key data but a valid
1315 * index, set the TX key.
1316 */
Dan Williams889c05b2007-05-10 22:57:23 -04001317 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001318 set_tx_key = 1;
1319
1320 ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1321 if (ret)
1322 goto out;
1323
1324 if (dwrq->length)
1325 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1326 if (set_tx_key)
1327 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1328
1329 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001330 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001331 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001332 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001333 }
1334
1335out:
1336 if (ret == 0) {
1337 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1338 wlan_postpone_association_work(priv);
1339 } else {
1340 wlan_cancel_association_work(priv);
1341 }
1342 mutex_unlock(&adapter->lock);
1343
Holger Schurig9012b282007-05-25 11:27:16 -04001344 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001345 return ret;
1346}
1347
1348/**
1349 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1350 *
1351 * @param dev A pointer to net_device structure
1352 * @param info A pointer to iw_request_info structure
1353 * @param vwrq A pointer to iw_param structure
1354 * @param extra A pointer to extra data buf
1355 * @return 0 on success, otherwise failure
1356 */
1357static int wlan_get_encodeext(struct net_device *dev,
1358 struct iw_request_info *info,
1359 struct iw_point *dwrq,
1360 char *extra)
1361{
1362 int ret = -EINVAL;
1363 wlan_private *priv = dev->priv;
1364 wlan_adapter *adapter = priv->adapter;
1365 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1366 int index, max_key_len;
1367
Holger Schurig9012b282007-05-25 11:27:16 -04001368 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001369
1370 max_key_len = dwrq->length - sizeof(*ext);
1371 if (max_key_len < 0)
1372 goto out;
1373
1374 index = dwrq->flags & IW_ENCODE_INDEX;
1375 if (index) {
1376 if (index < 1 || index > 4)
1377 goto out;
1378 index--;
1379 } else {
1380 index = adapter->wep_tx_keyidx;
1381 }
1382
1383 if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
1384 ext->alg != IW_ENCODE_ALG_WEP) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001385 if (index != 0 || adapter->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001386 goto out;
1387 }
1388
1389 dwrq->flags = index + 1;
1390 memset(ext, 0, sizeof(*ext));
1391
Dan Williams889c05b2007-05-10 22:57:23 -04001392 if ( !adapter->secinfo.wep_enabled
1393 && !adapter->secinfo.WPAenabled
1394 && !adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001395 ext->alg = IW_ENCODE_ALG_NONE;
1396 ext->key_len = 0;
1397 dwrq->flags |= IW_ENCODE_DISABLED;
1398 } else {
1399 u8 *key = NULL;
1400
Dan Williams889c05b2007-05-10 22:57:23 -04001401 if ( adapter->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001402 && !adapter->secinfo.WPAenabled
1403 && !adapter->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001404 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001405 ext->alg = IW_ENCODE_ALG_WEP;
1406 ext->key_len = adapter->wep_keys[index].len;
1407 key = &adapter->wep_keys[index].key[0];
Dan Williams889c05b2007-05-10 22:57:23 -04001408 } else if ( !adapter->secinfo.wep_enabled
1409 && (adapter->secinfo.WPAenabled ||
1410 adapter->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001411 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001412 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001413
1414 if ( adapter->wpa_mcast_key.len
1415 && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1416 pkey = &adapter->wpa_mcast_key;
1417 else if ( adapter->wpa_unicast_key.len
1418 && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1419 pkey = &adapter->wpa_unicast_key;
1420
1421 if (pkey) {
1422 if (pkey->type == KEY_TYPE_ID_AES) {
1423 ext->alg = IW_ENCODE_ALG_CCMP;
1424 } else {
1425 ext->alg = IW_ENCODE_ALG_TKIP;
1426 }
1427 ext->key_len = pkey->len;
1428 key = &pkey->key[0];
1429 } else {
1430 ext->alg = IW_ENCODE_ALG_TKIP;
1431 ext->key_len = 0;
1432 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001433 } else {
1434 goto out;
1435 }
1436
1437 if (ext->key_len > max_key_len) {
1438 ret = -E2BIG;
1439 goto out;
1440 }
1441
1442 if (ext->key_len)
1443 memcpy(ext->key, key, ext->key_len);
1444 else
1445 dwrq->flags |= IW_ENCODE_NOKEY;
1446 dwrq->flags |= IW_ENCODE_ENABLED;
1447 }
1448 ret = 0;
1449
1450out:
Holger Schurig9012b282007-05-25 11:27:16 -04001451 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001452 return ret;
1453}
1454
1455/**
1456 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1457 *
1458 * @param dev A pointer to net_device structure
1459 * @param info A pointer to iw_request_info structure
1460 * @param vwrq A pointer to iw_param structure
1461 * @param extra A pointer to extra data buf
1462 * @return 0 --success, otherwise fail
1463 */
1464static int wlan_set_encodeext(struct net_device *dev,
1465 struct iw_request_info *info,
1466 struct iw_point *dwrq,
1467 char *extra)
1468{
1469 int ret = 0;
1470 wlan_private *priv = dev->priv;
1471 wlan_adapter *adapter = priv->adapter;
1472 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1473 int alg = ext->alg;
1474 struct assoc_request * assoc_req;
1475
Holger Schurig9012b282007-05-25 11:27:16 -04001476 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001477
1478 mutex_lock(&adapter->lock);
1479 assoc_req = wlan_get_association_request(adapter);
1480 if (!assoc_req) {
1481 ret = -ENOMEM;
1482 goto out;
1483 }
1484
1485 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1486 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001487 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001488 } else if (alg == IW_ENCODE_ALG_WEP) {
1489 u16 is_default = 0, index, set_tx_key = 0;
1490
1491 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1492 (dwrq->flags & IW_ENCODE_INDEX),
1493 &index, &is_default);
1494 if (ret)
1495 goto out;
1496
1497 /* If WEP isn't enabled, or if there is no key data but a valid
1498 * index, or if the set-TX-key flag was passed, set the TX key.
1499 */
Dan Williams889c05b2007-05-10 22:57:23 -04001500 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001501 || (dwrq->length == 0 && !is_default)
1502 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1503 set_tx_key = 1;
1504
1505 /* Copy key to driver */
1506 ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
1507 set_tx_key);
1508 if (ret)
1509 goto out;
1510
1511 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001512 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001513 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001514 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001515 }
1516
1517 /* Mark the various WEP bits as modified */
1518 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1519 if (dwrq->length)
1520 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1521 if (set_tx_key)
1522 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001523 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001524 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001525
1526 /* validate key length */
1527 if (((alg == IW_ENCODE_ALG_TKIP)
1528 && (ext->key_len != KEY_LEN_WPA_TKIP))
1529 || ((alg == IW_ENCODE_ALG_CCMP)
1530 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001531 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001532 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001533 ext->key_len,
1534 alg);
1535 ret = -EINVAL;
1536 goto out;
1537 }
1538
Dan Williams90a42212007-05-25 23:01:24 -04001539 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001540 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001541 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1542 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001543 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001544 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1545 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001546
Dan Williams1443b652007-08-02 10:45:55 -04001547 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001548 memcpy(pkey->key, ext->key, ext->key_len);
1549 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001550 if (pkey->len)
1551 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001552
Dan Williams90a42212007-05-25 23:01:24 -04001553 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001554 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1555 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001556 } else {
1557 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001558 }
1559
Dan Williams90a42212007-05-25 23:01:24 -04001560 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001561 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001562 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001563 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001564 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001565
1566 /* If WPA isn't enabled yet, do that now */
1567 if ( assoc_req->secinfo.WPAenabled == 0
1568 && assoc_req->secinfo.WPA2enabled == 0) {
1569 assoc_req->secinfo.WPAenabled = 1;
1570 assoc_req->secinfo.WPA2enabled = 1;
1571 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1572 }
1573
1574 disable_wep (assoc_req);
1575 }
1576
1577out:
1578 if (ret == 0) {
1579 wlan_postpone_association_work(priv);
1580 } else {
1581 wlan_cancel_association_work(priv);
1582 }
1583 mutex_unlock(&adapter->lock);
1584
Holger Schurig9012b282007-05-25 11:27:16 -04001585 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001586 return ret;
1587}
1588
1589
1590static int wlan_set_genie(struct net_device *dev,
1591 struct iw_request_info *info,
1592 struct iw_point *dwrq,
1593 char *extra)
1594{
1595 wlan_private *priv = dev->priv;
1596 wlan_adapter *adapter = priv->adapter;
1597 int ret = 0;
1598 struct assoc_request * assoc_req;
1599
Holger Schurig9012b282007-05-25 11:27:16 -04001600 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001601
1602 mutex_lock(&adapter->lock);
1603 assoc_req = wlan_get_association_request(adapter);
1604 if (!assoc_req) {
1605 ret = -ENOMEM;
1606 goto out;
1607 }
1608
1609 if (dwrq->length > MAX_WPA_IE_LEN ||
1610 (dwrq->length && extra == NULL)) {
1611 ret = -EINVAL;
1612 goto out;
1613 }
1614
1615 if (dwrq->length) {
1616 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1617 assoc_req->wpa_ie_len = dwrq->length;
1618 } else {
1619 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
1620 assoc_req->wpa_ie_len = 0;
1621 }
1622
1623out:
1624 if (ret == 0) {
1625 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1626 wlan_postpone_association_work(priv);
1627 } else {
1628 wlan_cancel_association_work(priv);
1629 }
1630 mutex_unlock(&adapter->lock);
1631
Holger Schurig9012b282007-05-25 11:27:16 -04001632 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001633 return ret;
1634}
1635
1636static int wlan_get_genie(struct net_device *dev,
1637 struct iw_request_info *info,
1638 struct iw_point *dwrq,
1639 char *extra)
1640{
Holger Schurig9012b282007-05-25 11:27:16 -04001641 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001642 wlan_private *priv = dev->priv;
1643 wlan_adapter *adapter = priv->adapter;
1644
Holger Schurig9012b282007-05-25 11:27:16 -04001645 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001646
1647 if (adapter->wpa_ie_len == 0) {
1648 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001649 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001650 }
1651
1652 if (dwrq->length < adapter->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001653 ret = -E2BIG;
1654 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001655 }
1656
1657 dwrq->length = adapter->wpa_ie_len;
1658 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
1659
Holger Schurig9012b282007-05-25 11:27:16 -04001660out:
1661 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1662 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001663}
1664
1665
1666static int wlan_set_auth(struct net_device *dev,
1667 struct iw_request_info *info,
1668 struct iw_param *dwrq,
1669 char *extra)
1670{
1671 wlan_private *priv = dev->priv;
1672 wlan_adapter *adapter = priv->adapter;
1673 struct assoc_request * assoc_req;
1674 int ret = 0;
1675 int updated = 0;
1676
Holger Schurig9012b282007-05-25 11:27:16 -04001677 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001678
1679 mutex_lock(&adapter->lock);
1680 assoc_req = wlan_get_association_request(adapter);
1681 if (!assoc_req) {
1682 ret = -ENOMEM;
1683 goto out;
1684 }
1685
1686 switch (dwrq->flags & IW_AUTH_INDEX) {
1687 case IW_AUTH_TKIP_COUNTERMEASURES:
1688 case IW_AUTH_CIPHER_PAIRWISE:
1689 case IW_AUTH_CIPHER_GROUP:
1690 case IW_AUTH_KEY_MGMT:
Dan Williams90a42212007-05-25 23:01:24 -04001691 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001692 /*
1693 * libertas does not use these parameters
1694 */
1695 break;
1696
1697 case IW_AUTH_WPA_VERSION:
1698 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1699 assoc_req->secinfo.WPAenabled = 0;
1700 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001701 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001702 }
1703 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1704 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001705 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001706 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001707 }
1708 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1709 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001710 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001711 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001712 }
1713 updated = 1;
1714 break;
1715
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001716 case IW_AUTH_80211_AUTH_ALG:
1717 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001718 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001719 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001720 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001721 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001722 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001723 } else {
1724 ret = -EINVAL;
1725 }
1726 updated = 1;
1727 break;
1728
1729 case IW_AUTH_WPA_ENABLED:
1730 if (dwrq->value) {
1731 if (!assoc_req->secinfo.WPAenabled &&
1732 !assoc_req->secinfo.WPA2enabled) {
1733 assoc_req->secinfo.WPAenabled = 1;
1734 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001735 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001736 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001737 }
1738 } else {
1739 assoc_req->secinfo.WPAenabled = 0;
1740 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001741 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001742 }
1743 updated = 1;
1744 break;
1745
1746 default:
1747 ret = -EOPNOTSUPP;
1748 break;
1749 }
1750
1751out:
1752 if (ret == 0) {
1753 if (updated)
1754 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1755 wlan_postpone_association_work(priv);
1756 } else if (ret != -EOPNOTSUPP) {
1757 wlan_cancel_association_work(priv);
1758 }
1759 mutex_unlock(&adapter->lock);
1760
Holger Schurig9012b282007-05-25 11:27:16 -04001761 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001762 return ret;
1763}
1764
1765static int wlan_get_auth(struct net_device *dev,
1766 struct iw_request_info *info,
1767 struct iw_param *dwrq,
1768 char *extra)
1769{
Holger Schurig9012b282007-05-25 11:27:16 -04001770 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001771 wlan_private *priv = dev->priv;
1772 wlan_adapter *adapter = priv->adapter;
1773
Holger Schurig9012b282007-05-25 11:27:16 -04001774 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001775
1776 switch (dwrq->flags & IW_AUTH_INDEX) {
1777 case IW_AUTH_WPA_VERSION:
1778 dwrq->value = 0;
1779 if (adapter->secinfo.WPAenabled)
1780 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1781 if (adapter->secinfo.WPA2enabled)
1782 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1783 if (!dwrq->value)
1784 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1785 break;
1786
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001787 case IW_AUTH_80211_AUTH_ALG:
Dan Williams6affe782007-05-10 22:56:42 -04001788 dwrq->value = adapter->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001789 break;
1790
1791 case IW_AUTH_WPA_ENABLED:
1792 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
1793 dwrq->value = 1;
1794 break;
1795
1796 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001797 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001798 }
1799
Holger Schurig9012b282007-05-25 11:27:16 -04001800 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1801 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001802}
1803
1804
1805static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
1806 struct iw_param *vwrq, char *extra)
1807{
1808 int ret = 0;
1809 wlan_private *priv = dev->priv;
1810 wlan_adapter *adapter = priv->adapter;
1811
1812 u16 dbm;
1813
Holger Schurig9012b282007-05-25 11:27:16 -04001814 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001815
1816 if (vwrq->disabled) {
1817 wlan_radio_ioctl(priv, RADIO_OFF);
1818 return 0;
1819 }
1820
Dan Williams0aef64d2007-08-02 11:31:18 -04001821 adapter->preamble = CMD_TYPE_AUTO_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001822
1823 wlan_radio_ioctl(priv, RADIO_ON);
1824
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001825 /* Userspace check in iwrange if it should use dBm or mW,
1826 * therefore this should never happen... Jean II */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001827 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001828 return -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001829 } else
1830 dbm = (u16) vwrq->value;
1831
1832 /* auto tx power control */
1833
1834 if (vwrq->fixed == 0)
1835 dbm = 0xffff;
1836
Holger Schurig9012b282007-05-25 11:27:16 -04001837 lbs_deb_wext("txpower set %d dbm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001838
1839 ret = libertas_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -04001840 CMD_802_11_RF_TX_POWER,
1841 CMD_ACT_TX_POWER_OPT_SET_LOW,
1842 CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001843
Holger Schurig9012b282007-05-25 11:27:16 -04001844 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845 return ret;
1846}
1847
1848static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
1849 struct iw_point *dwrq, char *extra)
1850{
1851 wlan_private *priv = dev->priv;
1852 wlan_adapter *adapter = priv->adapter;
1853
Holger Schurig9012b282007-05-25 11:27:16 -04001854 lbs_deb_enter(LBS_DEB_WEXT);
1855
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001856 /*
1857 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1858 * the SSID list...
1859 */
1860
1861 /*
1862 * Get the current SSID
1863 */
Dan Williams0aef64d2007-08-02 11:31:18 -04001864 if (adapter->connect_status == LIBERTAS_CONNECTED) {
Dan Williamsd8efea22007-05-28 23:54:55 -04001865 memcpy(extra, adapter->curbssparams.ssid,
1866 adapter->curbssparams.ssid_len);
1867 extra[adapter->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001868 } else {
1869 memset(extra, 0, 32);
Dan Williamsd8efea22007-05-28 23:54:55 -04001870 extra[adapter->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001871 }
1872 /*
1873 * If none, we may want to get the one that was set
1874 */
1875
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001876 dwrq->length = adapter->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001877
1878 dwrq->flags = 1; /* active */
1879
Holger Schurig9012b282007-05-25 11:27:16 -04001880 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001881 return 0;
1882}
1883
1884static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
1885 struct iw_point *dwrq, char *extra)
1886{
1887 wlan_private *priv = dev->priv;
1888 wlan_adapter *adapter = priv->adapter;
1889 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04001890 u8 ssid[IW_ESSID_MAX_SIZE];
1891 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001892 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001893 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001894
Holger Schurig9012b282007-05-25 11:27:16 -04001895 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001896
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001897 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001898 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001899 ret = -E2BIG;
1900 goto out;
1901 }
1902
Dan Williamsd8efea22007-05-28 23:54:55 -04001903 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001904
Dan Williamsd8efea22007-05-28 23:54:55 -04001905 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001906 /* "any" SSID requested; leave SSID blank */
1907 } else {
1908 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04001909 memcpy(&ssid, extra, in_ssid_len);
1910 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001911 }
1912
Dan Williamsd8efea22007-05-28 23:54:55 -04001913 if (!ssid_len) {
1914 lbs_deb_wext("requested any SSID\n");
1915 } else {
1916 lbs_deb_wext("requested SSID '%s'\n",
1917 escape_essid(ssid, ssid_len));
1918 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001919
1920out:
1921 mutex_lock(&adapter->lock);
1922 if (ret == 0) {
1923 /* Get or create the current association request */
1924 assoc_req = wlan_get_association_request(adapter);
1925 if (!assoc_req) {
1926 ret = -ENOMEM;
1927 } else {
1928 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04001929 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1930 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001931 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
1932 wlan_postpone_association_work(priv);
1933 }
1934 }
1935
1936 /* Cancel the association request if there was an error */
1937 if (ret != 0) {
1938 wlan_cancel_association_work(priv);
1939 }
1940
1941 mutex_unlock(&adapter->lock);
1942
Holger Schurig9012b282007-05-25 11:27:16 -04001943 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001944 return ret;
1945}
1946
1947/**
1948 * @brief Connect to the AP or Ad-hoc Network with specific bssid
1949 *
1950 * @param dev A pointer to net_device structure
1951 * @param info A pointer to iw_request_info structure
1952 * @param awrq A pointer to iw_param structure
1953 * @param extra A pointer to extra data buf
1954 * @return 0 --success, otherwise fail
1955 */
1956static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
1957 struct sockaddr *awrq, char *extra)
1958{
1959 wlan_private *priv = dev->priv;
1960 wlan_adapter *adapter = priv->adapter;
1961 struct assoc_request * assoc_req;
1962 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07001963 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001964
Holger Schurig9012b282007-05-25 11:27:16 -04001965 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001966
1967 if (awrq->sa_family != ARPHRD_ETHER)
1968 return -EINVAL;
1969
Joe Perches0795af52007-10-03 17:59:30 -07001970 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001971
1972 mutex_lock(&adapter->lock);
1973
1974 /* Get or create the current association request */
1975 assoc_req = wlan_get_association_request(adapter);
1976 if (!assoc_req) {
1977 wlan_cancel_association_work(priv);
1978 ret = -ENOMEM;
1979 } else {
1980 /* Copy the BSSID to the association request */
1981 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
1982 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
1983 wlan_postpone_association_work(priv);
1984 }
1985
1986 mutex_unlock(&adapter->lock);
1987
1988 return ret;
1989}
1990
1991void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
1992{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001993 char fwver[32];
1994
1995 mutex_lock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001996
David Woodhousee5b3d472007-05-25 23:40:21 -04001997 if (adapter->fwreleasenumber[3] == 0)
1998 sprintf(fwver, "%u.%u.%u",
1999 adapter->fwreleasenumber[2],
2000 adapter->fwreleasenumber[1],
2001 adapter->fwreleasenumber[0]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002002 else
2003 sprintf(fwver, "%u.%u.%u.p%u",
David Woodhousee5b3d472007-05-25 23:40:21 -04002004 adapter->fwreleasenumber[2],
2005 adapter->fwreleasenumber[1],
2006 adapter->fwreleasenumber[0],
2007 adapter->fwreleasenumber[3]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002008
David Woodhousee5b3d472007-05-25 23:40:21 -04002009 mutex_unlock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002010 snprintf(fwversion, maxlen, fwver);
2011}
2012
2013
2014/*
2015 * iwconfig settable callbacks
2016 */
2017static const iw_handler wlan_handler[] = {
2018 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2019 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2020 (iw_handler) NULL, /* SIOCSIWNWID */
2021 (iw_handler) NULL, /* SIOCGIWNWID */
2022 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2023 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2024 (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
2025 (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
2026 (iw_handler) NULL, /* SIOCSIWSENS */
2027 (iw_handler) NULL, /* SIOCGIWSENS */
2028 (iw_handler) NULL, /* SIOCSIWRANGE */
2029 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2030 (iw_handler) NULL, /* SIOCSIWPRIV */
2031 (iw_handler) NULL, /* SIOCGIWPRIV */
2032 (iw_handler) NULL, /* SIOCSIWSTATS */
2033 (iw_handler) NULL, /* SIOCGIWSTATS */
2034 iw_handler_set_spy, /* SIOCSIWSPY */
2035 iw_handler_get_spy, /* SIOCGIWSPY */
2036 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2037 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2038 (iw_handler) wlan_set_wap, /* SIOCSIWAP */
2039 (iw_handler) wlan_get_wap, /* SIOCGIWAP */
2040 (iw_handler) NULL, /* SIOCSIWMLME */
2041 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2042 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2043 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2044 (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
2045 (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
2046 (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
2047 (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
2048 (iw_handler) NULL, /* -- hole -- */
2049 (iw_handler) NULL, /* -- hole -- */
2050 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2051 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2052 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2053 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2054 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2055 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2056 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2057 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2058 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2059 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2060 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2061 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2062 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2063 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2064 (iw_handler) NULL, /* -- hole -- */
2065 (iw_handler) NULL, /* -- hole -- */
2066 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2067 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2068 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2069 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2070 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2071 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2072 (iw_handler) NULL, /* SIOCSIWPMKSA */
2073};
2074
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002075static const iw_handler mesh_wlan_handler[] = {
2076 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2077 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2078 (iw_handler) NULL, /* SIOCSIWNWID */
2079 (iw_handler) NULL, /* SIOCGIWNWID */
2080 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2081 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2082 (iw_handler) NULL, /* SIOCSIWMODE */
2083 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2084 (iw_handler) NULL, /* SIOCSIWSENS */
2085 (iw_handler) NULL, /* SIOCGIWSENS */
2086 (iw_handler) NULL, /* SIOCSIWRANGE */
2087 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2088 (iw_handler) NULL, /* SIOCSIWPRIV */
2089 (iw_handler) NULL, /* SIOCGIWPRIV */
2090 (iw_handler) NULL, /* SIOCSIWSTATS */
2091 (iw_handler) NULL, /* SIOCGIWSTATS */
2092 iw_handler_set_spy, /* SIOCSIWSPY */
2093 iw_handler_get_spy, /* SIOCGIWSPY */
2094 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2095 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2096 (iw_handler) NULL, /* SIOCSIWAP */
2097 (iw_handler) NULL, /* SIOCGIWAP */
2098 (iw_handler) NULL, /* SIOCSIWMLME */
2099 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2100 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2101 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2102 (iw_handler) NULL, /* SIOCSIWESSID */
2103 (iw_handler) NULL, /* SIOCGIWESSID */
2104 (iw_handler) NULL, /* SIOCSIWNICKN */
2105 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2106 (iw_handler) NULL, /* -- hole -- */
2107 (iw_handler) NULL, /* -- hole -- */
2108 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2109 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2110 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2111 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2112 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2113 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2114 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2115 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2116 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2117 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2118 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2119 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2120 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2121 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2122 (iw_handler) NULL, /* -- hole -- */
2123 (iw_handler) NULL, /* -- hole -- */
2124 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2125 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2126 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2127 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2128 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2129 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2130 (iw_handler) NULL, /* SIOCSIWPMKSA */
2131};
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002132struct iw_handler_def libertas_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002133 .num_standard = ARRAY_SIZE(wlan_handler),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002134 .standard = (iw_handler *) wlan_handler,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002135 .get_wireless_stats = wlan_get_wireless_stats,
2136};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002137
2138struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002139 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002140 .standard = (iw_handler *) mesh_wlan_handler,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002141 .get_wireless_stats = wlan_get_wireless_stats,
2142};