blob: b8c93c0adb2e680c573da080b5fcf5372b78424b [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
Holger Schurig69f90322007-11-23 15:43:44 +010024static inline void lbs_postpone_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020025{
26 if (priv->adapter->surpriseremoved)
27 return;
28 cancel_delayed_work(&priv->assoc_work);
29 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
30}
31
Holger Schurig69f90322007-11-23 15:43:44 +010032static inline void lbs_cancel_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020033{
34 cancel_delayed_work(&priv->assoc_work);
Jeff Garzik93a3b602007-11-23 21:50:20 -050035 kfree(priv->adapter->pending_assoc_req);
36 priv->adapter->pending_assoc_req = NULL;
Holger Schurig9f9dac22007-10-26 10:12:14 +020037}
38
39
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020040/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020041 * @brief Find the channel frequency power info with specific channel
42 *
Holger Schurig69f90322007-11-23 15:43:44 +010043 * @param adapter A pointer to struct lbs_adapter structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020044 * @param band it can be BAND_A, BAND_G or BAND_B
45 * @param channel the channel for looking
46 * @return A pointer to struct chan_freq_power structure or NULL if not find.
47 */
Holger Schurig69f90322007-11-23 15:43:44 +010048struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
49 struct lbs_adapter *adapter,
50 u8 band,
51 u16 channel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020052{
53 struct chan_freq_power *cfp = NULL;
54 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020055 int i, j;
56
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020057 for (j = 0; !cfp && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020058 rc = &adapter->region_channel[j];
59
60 if (adapter->enable11d)
61 rc = &adapter->universal_channel[j];
62 if (!rc->valid || !rc->CFP)
63 continue;
64 if (rc->band != band)
65 continue;
66 for (i = 0; i < rc->nrcfp; i++) {
67 if (rc->CFP[i].channel == channel) {
68 cfp = &rc->CFP[i];
69 break;
70 }
71 }
72 }
73
74 if (!cfp && channel)
Holger Schurig10078322007-11-15 18:05:47 -050075 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
Holger Schurig9012b282007-05-25 11:27:16 -040076 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020077
78 return cfp;
79}
80
81/**
82 * @brief Find the channel frequency power info with specific frequency
83 *
Holger Schurig69f90322007-11-23 15:43:44 +010084 * @param adapter A pointer to struct lbs_adapter structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020085 * @param band it can be BAND_A, BAND_G or BAND_B
86 * @param freq the frequency for looking
87 * @return A pointer to struct chan_freq_power structure or NULL if not find.
88 */
Holger Schurig69f90322007-11-23 15:43:44 +010089static struct chan_freq_power *find_cfp_by_band_and_freq(
90 struct lbs_adapter *adapter,
91 u8 band,
92 u32 freq)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020093{
94 struct chan_freq_power *cfp = NULL;
95 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020096 int i, j;
97
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020098 for (j = 0; !cfp && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020099 rc = &adapter->region_channel[j];
100
101 if (adapter->enable11d)
102 rc = &adapter->universal_channel[j];
103 if (!rc->valid || !rc->CFP)
104 continue;
105 if (rc->band != band)
106 continue;
107 for (i = 0; i < rc->nrcfp; i++) {
108 if (rc->CFP[i].freq == freq) {
109 cfp = &rc->CFP[i];
110 break;
111 }
112 }
113 }
114
115 if (!cfp && freq)
Holger Schurig9012b282007-05-25 11:27:16 -0400116 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
117 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200118
119 return cfp;
120}
121
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122
123/**
124 * @brief Set Radio On/OFF
125 *
Holger Schurig69f90322007-11-23 15:43:44 +0100126 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127 * @option Radio Option
128 * @return 0 --success, otherwise fail
129 */
Holger Schurig69f90322007-11-23 15:43:44 +0100130static int lbs_radio_ioctl(struct lbs_private *priv, u8 option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200131{
132 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100133 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200134
Holger Schurig9012b282007-05-25 11:27:16 -0400135 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200136
137 if (adapter->radioon != option) {
Holger Schurig9012b282007-05-25 11:27:16 -0400138 lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139 adapter->radioon = option;
140
Holger Schurig10078322007-11-15 18:05:47 -0500141 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400142 CMD_802_11_RADIO_CONTROL,
143 CMD_ACT_SET,
144 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200145 }
146
Holger Schurig9012b282007-05-25 11:27:16 -0400147 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148 return ret;
149}
150
151/**
Dan Williams8c512762007-08-02 11:40:45 -0400152 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200153 *
Holger Schurig69f90322007-11-23 15:43:44 +0100154 * @param adapter A pointer to struct lbs_adapter structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156 */
Holger Schurig69f90322007-11-23 15:43:44 +0100157static void copy_active_data_rates(struct lbs_adapter *adapter, u8 *rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158{
Holger Schurig9012b282007-05-25 11:27:16 -0400159 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160
Brajesh Dave01d77d82007-11-20 17:44:14 -0500161 if ((adapter->connect_status != LBS_CONNECTED) &&
162 (adapter->mesh_connect_status != LBS_CONNECTED))
Holger Schurig10078322007-11-15 18:05:47 -0500163 memcpy(rates, lbs_bg_rates, MAX_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400164 else
165 memcpy(rates, adapter->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200166
Dan Williams8c512762007-08-02 11:40:45 -0400167 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200168}
169
Holger Schurig10078322007-11-15 18:05:47 -0500170static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200171 char *cwrq, char *extra)
172{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200173
Holger Schurig9012b282007-05-25 11:27:16 -0400174 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200175
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400176 /* We could add support for 802.11n here as needed. Jean II */
177 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200178
Holger Schurig9012b282007-05-25 11:27:16 -0400179 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200180 return 0;
181}
182
Holger Schurig10078322007-11-15 18:05:47 -0500183static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200184 struct iw_freq *fwrq, char *extra)
185{
Holger Schurig69f90322007-11-23 15:43:44 +0100186 struct lbs_private *priv = dev->priv;
187 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200188 struct chan_freq_power *cfp;
189
Holger Schurig9012b282007-05-25 11:27:16 -0400190 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200191
Holger Schurig10078322007-11-15 18:05:47 -0500192 cfp = lbs_find_cfp_by_band_and_channel(adapter, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200193 adapter->curbssparams.channel);
194
195 if (!cfp) {
196 if (adapter->curbssparams.channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400197 lbs_deb_wext("invalid channel %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200198 adapter->curbssparams.channel);
199 return -EINVAL;
200 }
201
202 fwrq->m = (long)cfp->freq * 100000;
203 fwrq->e = 1;
204
Holger Schurig9012b282007-05-25 11:27:16 -0400205 lbs_deb_wext("freq %u\n", fwrq->m);
206 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200207 return 0;
208}
209
Holger Schurig10078322007-11-15 18:05:47 -0500210static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211 struct sockaddr *awrq, char *extra)
212{
Holger Schurig69f90322007-11-23 15:43:44 +0100213 struct lbs_private *priv = dev->priv;
214 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200215
Holger Schurig9012b282007-05-25 11:27:16 -0400216 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200217
Holger Schurig10078322007-11-15 18:05:47 -0500218 if (adapter->connect_status == LBS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200219 memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
220 } else {
221 memset(awrq->sa_data, 0, ETH_ALEN);
222 }
223 awrq->sa_family = ARPHRD_ETHER;
224
Holger Schurig9012b282007-05-25 11:27:16 -0400225 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226 return 0;
227}
228
Holger Schurig10078322007-11-15 18:05:47 -0500229static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200230 struct iw_point *dwrq, char *extra)
231{
Holger Schurig69f90322007-11-23 15:43:44 +0100232 struct lbs_private *priv = dev->priv;
233 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234
Holger Schurig9012b282007-05-25 11:27:16 -0400235 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200236
237 /*
238 * Check the size of the string
239 */
240
241 if (dwrq->length > 16) {
242 return -E2BIG;
243 }
244
245 mutex_lock(&adapter->lock);
246 memset(adapter->nodename, 0, sizeof(adapter->nodename));
247 memcpy(adapter->nodename, extra, dwrq->length);
248 mutex_unlock(&adapter->lock);
249
Holger Schurig9012b282007-05-25 11:27:16 -0400250 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200251 return 0;
252}
253
Holger Schurig10078322007-11-15 18:05:47 -0500254static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200255 struct iw_point *dwrq, char *extra)
256{
Holger Schurig69f90322007-11-23 15:43:44 +0100257 struct lbs_private *priv = dev->priv;
258 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200259
Holger Schurig9012b282007-05-25 11:27:16 -0400260 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200261
Holger Schurig04799fa2007-10-09 15:04:14 +0200262 dwrq->length = strlen(adapter->nodename);
263 memcpy(extra, adapter->nodename, dwrq->length);
264 extra[dwrq->length] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265
Holger Schurig04799fa2007-10-09 15:04:14 +0200266 dwrq->flags = 1; /* active */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200267
Holger Schurig9012b282007-05-25 11:27:16 -0400268 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200269 return 0;
270}
271
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400272static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
273 struct iw_point *dwrq, char *extra)
274{
Holger Schurig69f90322007-11-23 15:43:44 +0100275 struct lbs_private *priv = dev->priv;
276 struct lbs_adapter *adapter = priv->adapter;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400277
278 lbs_deb_enter(LBS_DEB_WEXT);
279
280 /* Use nickname to indicate that mesh is on */
281
Brajesh Dave01d77d82007-11-20 17:44:14 -0500282 if (adapter->mesh_connect_status == LBS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400283 strncpy(extra, "Mesh", 12);
284 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400285 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400286 }
287
288 else {
289 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400290 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400291 }
292
293 lbs_deb_leave(LBS_DEB_WEXT);
294 return 0;
295}
Holger Schurig04799fa2007-10-09 15:04:14 +0200296
Holger Schurig10078322007-11-15 18:05:47 -0500297static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298 struct iw_param *vwrq, char *extra)
299{
300 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100301 struct lbs_private *priv = dev->priv;
302 struct lbs_adapter *adapter = priv->adapter;
David Woodhouse981f1872007-05-25 23:36:54 -0400303 u32 rthr = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200304
Holger Schurig9012b282007-05-25 11:27:16 -0400305 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306
307 if (vwrq->disabled) {
308 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
309 } else {
310 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
311 return -EINVAL;
312 adapter->rtsthsd = rthr;
313 }
314
Holger Schurig10078322007-11-15 18:05:47 -0500315 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400316 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317 OID_802_11_RTS_THRESHOLD, &rthr);
318
Holger Schurig9012b282007-05-25 11:27:16 -0400319 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200320 return ret;
321}
322
Holger Schurig10078322007-11-15 18:05:47 -0500323static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324 struct iw_param *vwrq, char *extra)
325{
326 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100327 struct lbs_private *priv = dev->priv;
328 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200329
Holger Schurig9012b282007-05-25 11:27:16 -0400330 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200331
332 adapter->rtsthsd = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500333 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400334 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200335 OID_802_11_RTS_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400336 if (ret)
337 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338
339 vwrq->value = adapter->rtsthsd;
340 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
341 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
342 vwrq->fixed = 1;
343
Holger Schurig9012b282007-05-25 11:27:16 -0400344out:
345 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
346 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200347}
348
Holger Schurig10078322007-11-15 18:05:47 -0500349static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200350 struct iw_param *vwrq, char *extra)
351{
352 int ret = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400353 u32 fthr = vwrq->value;
Holger Schurig69f90322007-11-23 15:43:44 +0100354 struct lbs_private *priv = dev->priv;
355 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200356
Holger Schurig9012b282007-05-25 11:27:16 -0400357 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200358
359 if (vwrq->disabled) {
360 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
361 } else {
362 if (fthr < MRVDRV_FRAG_MIN_VALUE
363 || fthr > MRVDRV_FRAG_MAX_VALUE)
364 return -EINVAL;
365 adapter->fragthsd = fthr;
366 }
367
Holger Schurig10078322007-11-15 18:05:47 -0500368 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400369 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
Holger Schurig9012b282007-05-25 11:27:16 -0400371
372 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373 return ret;
374}
375
Holger Schurig10078322007-11-15 18:05:47 -0500376static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200377 struct iw_param *vwrq, char *extra)
378{
379 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100380 struct lbs_private *priv = dev->priv;
381 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200382
Holger Schurig9012b282007-05-25 11:27:16 -0400383 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200384
385 adapter->fragthsd = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500386 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400387 CMD_802_11_SNMP_MIB,
388 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400390 if (ret)
391 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392
393 vwrq->value = adapter->fragthsd;
394 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
395 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
396 vwrq->fixed = 1;
397
Holger Schurig9012b282007-05-25 11:27:16 -0400398out:
399 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400 return ret;
401}
402
Holger Schurig10078322007-11-15 18:05:47 -0500403static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404 struct iw_request_info *info, u32 * uwrq, char *extra)
405{
Holger Schurig69f90322007-11-23 15:43:44 +0100406 struct lbs_private *priv = dev->priv;
407 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408
Holger Schurig9012b282007-05-25 11:27:16 -0400409 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410
Dan Williams0dc5a292007-05-10 22:58:02 -0400411 *uwrq = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200412
Holger Schurig9012b282007-05-25 11:27:16 -0400413 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200414 return 0;
415}
416
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400417static int mesh_wlan_get_mode(struct net_device *dev,
418 struct iw_request_info *info, u32 * uwrq,
419 char *extra)
420{
421 lbs_deb_enter(LBS_DEB_WEXT);
422
423 *uwrq = IW_MODE_REPEAT ;
424
425 lbs_deb_leave(LBS_DEB_WEXT);
426 return 0;
427}
428
Holger Schurig10078322007-11-15 18:05:47 -0500429static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200430 struct iw_request_info *info,
431 struct iw_param *vwrq, char *extra)
432{
433 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100434 struct lbs_private *priv = dev->priv;
435 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436
Holger Schurig9012b282007-05-25 11:27:16 -0400437 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200438
Holger Schurig10078322007-11-15 18:05:47 -0500439 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400440 CMD_802_11_RF_TX_POWER,
441 CMD_ACT_TX_POWER_OPT_GET,
442 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200443
Holger Schurig9012b282007-05-25 11:27:16 -0400444 if (ret)
445 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200446
Holger Schurig9012b282007-05-25 11:27:16 -0400447 lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200448 vwrq->value = adapter->txpowerlevel;
449 vwrq->fixed = 1;
450 if (adapter->radioon) {
451 vwrq->disabled = 0;
452 vwrq->flags = IW_TXPOW_DBM;
453 } else {
454 vwrq->disabled = 1;
455 }
456
Holger Schurig9012b282007-05-25 11:27:16 -0400457out:
458 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
459 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200460}
461
Holger Schurig10078322007-11-15 18:05:47 -0500462static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200463 struct iw_param *vwrq, char *extra)
464{
465 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100466 struct lbs_private *priv = dev->priv;
467 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468
Holger Schurig9012b282007-05-25 11:27:16 -0400469 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470
471 if (vwrq->flags == IW_RETRY_LIMIT) {
472 /* The MAC has a 4-bit Total_Tx_Count register
473 Total_Tx_Count = 1 + Tx_Retry_Count */
474#define TX_RETRY_MIN 0
475#define TX_RETRY_MAX 14
476 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
477 return -EINVAL;
478
479 /* Adding 1 to convert retry count to try count */
480 adapter->txretrycount = vwrq->value + 1;
481
Holger Schurig10078322007-11-15 18:05:47 -0500482 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400483 CMD_ACT_SET,
484 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200485 OID_802_11_TX_RETRYCOUNT, NULL);
486
Holger Schurig9012b282007-05-25 11:27:16 -0400487 if (ret)
488 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489 } else {
490 return -EOPNOTSUPP;
491 }
492
Holger Schurig9012b282007-05-25 11:27:16 -0400493out:
494 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
495 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496}
497
Holger Schurig10078322007-11-15 18:05:47 -0500498static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499 struct iw_param *vwrq, char *extra)
500{
Holger Schurig69f90322007-11-23 15:43:44 +0100501 struct lbs_private *priv = dev->priv;
502 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200503 int ret = 0;
504
Holger Schurig9012b282007-05-25 11:27:16 -0400505 lbs_deb_enter(LBS_DEB_WEXT);
506
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507 adapter->txretrycount = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500508 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400509 CMD_802_11_SNMP_MIB,
510 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200511 OID_802_11_TX_RETRYCOUNT, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400512 if (ret)
513 goto out;
514
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200515 vwrq->disabled = 0;
516 if (!vwrq->flags) {
517 vwrq->flags = IW_RETRY_LIMIT;
518 /* Subtract 1 to convert try count to retry count */
519 vwrq->value = adapter->txretrycount - 1;
520 }
521
Holger Schurig9012b282007-05-25 11:27:16 -0400522out:
523 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
524 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200525}
526
527static inline void sort_channels(struct iw_freq *freq, int num)
528{
529 int i, j;
530 struct iw_freq temp;
531
532 for (i = 0; i < num; i++)
533 for (j = i + 1; j < num; j++)
534 if (freq[i].i > freq[j].i) {
535 temp.i = freq[i].i;
536 temp.m = freq[i].m;
537
538 freq[i].i = freq[j].i;
539 freq[i].m = freq[j].m;
540
541 freq[j].i = temp.i;
542 freq[j].m = temp.m;
543 }
544}
545
546/* data rate listing
547 MULTI_BANDS:
548 abg a b b/g
549 Infra G(12) A(8) B(4) G(12)
550 Adhoc A+B(12) A(8) B(4) B(4)
551
552 non-MULTI_BANDS:
553 b b/g
554 Infra B(4) G(12)
555 Adhoc B(4) B(4)
556 */
557/**
558 * @brief Get Range Info
559 *
560 * @param dev A pointer to net_device structure
561 * @param info A pointer to iw_request_info structure
562 * @param vwrq A pointer to iw_param structure
563 * @param extra A pointer to extra data buf
564 * @return 0 --success, otherwise fail
565 */
Holger Schurig10078322007-11-15 18:05:47 -0500566static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567 struct iw_point *dwrq, char *extra)
568{
569 int i, j;
Holger Schurig69f90322007-11-23 15:43:44 +0100570 struct lbs_private *priv = dev->priv;
571 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200572 struct iw_range *range = (struct iw_range *)extra;
573 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400574 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575
576 u8 flag = 0;
577
Holger Schurig9012b282007-05-25 11:27:16 -0400578 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579
580 dwrq->length = sizeof(struct iw_range);
581 memset(range, 0, sizeof(struct iw_range));
582
583 range->min_nwid = 0;
584 range->max_nwid = 0;
585
586 memset(rates, 0, sizeof(rates));
Dan Williams8c512762007-08-02 11:40:45 -0400587 copy_active_data_rates(adapter, rates);
588 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
589 for (i = 0; i < range->num_bitrates; i++)
590 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200591 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400592 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593 range->num_bitrates);
594
595 range->num_frequency = 0;
596 if (priv->adapter->enable11d &&
Brajesh Dave01d77d82007-11-20 17:44:14 -0500597 (adapter->connect_status == LBS_CONNECTED ||
598 adapter->mesh_connect_status == LBS_CONNECTED)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599 u8 chan_no;
600 u8 band;
601
602 struct parsed_region_chan_11d *parsed_region_chan =
603 &adapter->parsed_region_chan;
604
605 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400606 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
607 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608 }
609 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400610 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611 parsed_region_chan->nr_chan);
612
613 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
614 && (i < parsed_region_chan->nr_chan); i++) {
615 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400616 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617 range->freq[range->num_frequency].i = (long)chan_no;
618 range->freq[range->num_frequency].m =
Holger Schurig10078322007-11-15 18:05:47 -0500619 (long)lbs_chan_2_freq(chan_no, band) * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200620 range->freq[range->num_frequency].e = 1;
621 range->num_frequency++;
622 }
623 flag = 1;
624 }
625 if (!flag) {
626 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200627 && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200628 cfp = adapter->region_channel[j].CFP;
629 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
630 && adapter->region_channel[j].valid
631 && cfp
632 && (i < adapter->region_channel[j].nrcfp); i++) {
633 range->freq[range->num_frequency].i =
634 (long)cfp->channel;
635 range->freq[range->num_frequency].m =
636 (long)cfp->freq * 100000;
637 range->freq[range->num_frequency].e = 1;
638 cfp++;
639 range->num_frequency++;
640 }
641 }
642 }
643
Holger Schurig9012b282007-05-25 11:27:16 -0400644 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200645 IW_MAX_FREQUENCIES, range->num_frequency);
646
647 range->num_channels = range->num_frequency;
648
649 sort_channels(&range->freq[0], range->num_frequency);
650
651 /*
652 * Set an indication of the max TCP throughput in bit/s that we can
653 * expect using this interface
654 */
655 if (i > 2)
656 range->throughput = 5000 * 1000;
657 else
658 range->throughput = 1500 * 1000;
659
660 range->min_rts = MRVDRV_RTS_MIN_VALUE;
661 range->max_rts = MRVDRV_RTS_MAX_VALUE;
662 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
663 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
664
665 range->encoding_size[0] = 5;
666 range->encoding_size[1] = 13;
667 range->num_encoding_sizes = 2;
668 range->max_encoding_tokens = 4;
669
670 range->min_pmp = 1000000;
671 range->max_pmp = 120000000;
672 range->min_pmt = 1000;
673 range->max_pmt = 1000000;
674 range->pmp_flags = IW_POWER_PERIOD;
675 range->pmt_flags = IW_POWER_TIMEOUT;
676 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
677
678 /*
679 * Minimum version we recommend
680 */
681 range->we_version_source = 15;
682
683 /*
684 * Version we are compiled with
685 */
686 range->we_version_compiled = WIRELESS_EXT;
687
688 range->retry_capa = IW_RETRY_LIMIT;
689 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
690
691 range->min_retry = TX_RETRY_MIN;
692 range->max_retry = TX_RETRY_MAX;
693
694 /*
695 * Set the qual, level and noise range values
696 */
697 range->max_qual.qual = 100;
698 range->max_qual.level = 0;
699 range->max_qual.noise = 0;
700 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
701
702 range->avg_qual.qual = 70;
703 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
704 range->avg_qual.level = 0;
705 range->avg_qual.noise = 0;
706 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
707
708 range->sensitivity = 0;
709
710 /*
711 * Setup the supported power level ranges
712 */
713 memset(range->txpower, 0, sizeof(range->txpower));
714 range->txpower[0] = 5;
715 range->txpower[1] = 7;
716 range->txpower[2] = 9;
717 range->txpower[3] = 11;
718 range->txpower[4] = 13;
719 range->txpower[5] = 15;
720 range->txpower[6] = 17;
721 range->txpower[7] = 19;
722
723 range->num_txpower = 8;
724 range->txpower_capa = IW_TXPOW_DBM;
725 range->txpower_capa |= IW_TXPOW_RANGE;
726
727 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
728 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
729 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
730 range->event_capa[1] = IW_EVENT_CAPA_K_1;
731
732 if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
733 range->enc_capa = IW_ENC_CAPA_WPA
734 | IW_ENC_CAPA_WPA2
735 | IW_ENC_CAPA_CIPHER_TKIP
736 | IW_ENC_CAPA_CIPHER_CCMP;
737 }
738
Holger Schurig9012b282007-05-25 11:27:16 -0400739out:
740 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741 return 0;
742}
743
Holger Schurig10078322007-11-15 18:05:47 -0500744static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745 struct iw_param *vwrq, char *extra)
746{
Holger Schurig69f90322007-11-23 15:43:44 +0100747 struct lbs_private *priv = dev->priv;
748 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200749
Holger Schurig9012b282007-05-25 11:27:16 -0400750 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200751
752 /* PS is currently supported only in Infrastructure mode
753 * Remove this check if it is to be supported in IBSS mode also
754 */
755
756 if (vwrq->disabled) {
Holger Schurig10078322007-11-15 18:05:47 -0500757 adapter->psmode = LBS802_11POWERMODECAM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200758 if (adapter->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500759 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200760 }
761
762 return 0;
763 }
764
765 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400766 lbs_deb_wext(
767 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200768 return -EINVAL;
769 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400770 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200771 return -EINVAL;
772 }
773
Holger Schurig10078322007-11-15 18:05:47 -0500774 if (adapter->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200775 return 0;
776 }
777
Holger Schurig10078322007-11-15 18:05:47 -0500778 adapter->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200779
Holger Schurig10078322007-11-15 18:05:47 -0500780 if (adapter->connect_status == LBS_CONNECTED) {
781 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200782 }
783
Holger Schurig9012b282007-05-25 11:27:16 -0400784 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785 return 0;
786}
787
Holger Schurig10078322007-11-15 18:05:47 -0500788static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200789 struct iw_param *vwrq, char *extra)
790{
Holger Schurig69f90322007-11-23 15:43:44 +0100791 struct lbs_private *priv = dev->priv;
792 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793 int mode;
794
Holger Schurig9012b282007-05-25 11:27:16 -0400795 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200796
797 mode = adapter->psmode;
798
Holger Schurig10078322007-11-15 18:05:47 -0500799 if ((vwrq->disabled = (mode == LBS802_11POWERMODECAM))
800 || adapter->connect_status == LBS_DISCONNECTED)
Holger Schurig9012b282007-05-25 11:27:16 -0400801 {
802 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200803 }
804
805 vwrq->value = 0;
806
Holger Schurig9012b282007-05-25 11:27:16 -0400807out:
808 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200809 return 0;
810}
811
Holger Schurig10078322007-11-15 18:05:47 -0500812static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813{
814 enum {
815 POOR = 30,
816 FAIR = 60,
817 GOOD = 80,
818 VERY_GOOD = 90,
819 EXCELLENT = 95,
820 PERFECT = 100
821 };
Holger Schurig69f90322007-11-23 15:43:44 +0100822 struct lbs_private *priv = dev->priv;
823 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200824 u32 rssi_qual;
825 u32 tx_qual;
826 u32 quality = 0;
827 int stats_valid = 0;
828 u8 rssi;
829 u32 tx_retries;
830
Holger Schurig9012b282007-05-25 11:27:16 -0400831 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200832
Dan Williams0dc5a292007-05-10 22:58:02 -0400833 priv->wstats.status = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200834
835 /* If we're not associated, all quality values are meaningless */
Brajesh Dave01d77d82007-11-20 17:44:14 -0500836 if ((adapter->connect_status != LBS_CONNECTED) &&
837 (adapter->mesh_connect_status != LBS_CONNECTED))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200838 goto out;
839
840 /* Quality by RSSI */
841 priv->wstats.qual.level =
842 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
843 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
844
845 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
846 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
847 } else {
848 priv->wstats.qual.noise =
849 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
850 }
851
Holger Schurig9012b282007-05-25 11:27:16 -0400852 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
853 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200854
855 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
856 if (rssi < 15)
857 rssi_qual = rssi * POOR / 10;
858 else if (rssi < 20)
859 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
860 else if (rssi < 30)
861 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
862 else if (rssi < 40)
863 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
864 10 + GOOD;
865 else
866 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
867 10 + VERY_GOOD;
868 quality = rssi_qual;
869
870 /* Quality by TX errors */
871 priv->wstats.discard.retries = priv->stats.tx_errors;
872
Dan Williams8362cd42007-08-03 09:40:55 -0400873 tx_retries = le32_to_cpu(adapter->logmsg.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200874
875 if (tx_retries > 75)
876 tx_qual = (90 - tx_retries) * POOR / 15;
877 else if (tx_retries > 70)
878 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
879 else if (tx_retries > 65)
880 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
881 else if (tx_retries > 50)
882 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
883 15 + GOOD;
884 else
885 tx_qual = (50 - tx_retries) *
886 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
887 quality = min(quality, tx_qual);
888
Dan Williams8362cd42007-08-03 09:40:55 -0400889 priv->wstats.discard.code = le32_to_cpu(adapter->logmsg.wepundecryptable);
890 priv->wstats.discard.fragment = le32_to_cpu(adapter->logmsg.rxfrag);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200891 priv->wstats.discard.retries = tx_retries;
Dan Williams8362cd42007-08-03 09:40:55 -0400892 priv->wstats.discard.misc = le32_to_cpu(adapter->logmsg.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200893
894 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400895 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200896 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
897 stats_valid = 1;
898
899 /* update stats asynchronously for future calls */
Holger Schurig10078322007-11-15 18:05:47 -0500900 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200901 0, 0, NULL);
Holger Schurig10078322007-11-15 18:05:47 -0500902 lbs_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200903 0, 0, NULL);
904out:
905 if (!stats_valid) {
906 priv->wstats.miss.beacon = 0;
907 priv->wstats.discard.retries = 0;
908 priv->wstats.qual.qual = 0;
909 priv->wstats.qual.level = 0;
910 priv->wstats.qual.noise = 0;
911 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
912 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
913 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
914 }
915
Holger Schurig9012b282007-05-25 11:27:16 -0400916 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200917 return &priv->wstats;
918
919
920}
921
Holger Schurig10078322007-11-15 18:05:47 -0500922static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200923 struct iw_freq *fwrq, char *extra)
924{
Dan Williamsef9a2642007-05-25 16:46:33 -0400925 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +0100926 struct lbs_private *priv = dev->priv;
927 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200928 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400929 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200930
Holger Schurig9012b282007-05-25 11:27:16 -0400931 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200932
Dan Williamsef9a2642007-05-25 16:46:33 -0400933 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -0500934 assoc_req = lbs_get_association_request(adapter);
Dan Williamsef9a2642007-05-25 16:46:33 -0400935 if (!assoc_req) {
936 ret = -ENOMEM;
937 goto out;
938 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200939
Dan Williamsef9a2642007-05-25 16:46:33 -0400940 /* If setting by frequency, convert to a channel */
941 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200942 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200943
944 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
945 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400946 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400947 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200948 }
949
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200950 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400951 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200952 }
953
Dan Williamsef9a2642007-05-25 16:46:33 -0400954 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200955 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400956 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200957 }
958
Holger Schurig10078322007-11-15 18:05:47 -0500959 cfp = lbs_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400960 if (!cfp) {
961 goto out;
962 }
963
964 assoc_req->channel = fwrq->m;
965 ret = 0;
966
Holger Schurig9012b282007-05-25 11:27:16 -0400967out:
Dan Williamsef9a2642007-05-25 16:46:33 -0400968 if (ret == 0) {
969 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500970 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400971 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500972 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400973 }
974 mutex_unlock(&adapter->lock);
975
976 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
977 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200978}
979
Holger Schurig10078322007-11-15 18:05:47 -0500980static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200981 struct iw_param *vwrq, char *extra)
982{
Holger Schurig69f90322007-11-23 15:43:44 +0100983 struct lbs_private *priv = dev->priv;
984 struct lbs_adapter *adapter = priv->adapter;
Dan Williams8c512762007-08-02 11:40:45 -0400985 u32 new_rate;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200986 u16 action;
Dan Williams8c512762007-08-02 11:40:45 -0400987 int ret = -EINVAL;
988 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200989
Holger Schurig9012b282007-05-25 11:27:16 -0400990 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -0400991 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200992
Dan Williams8c512762007-08-02 11:40:45 -0400993 /* Auto rate? */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200994 if (vwrq->value == -1) {
Dan Williams8c512762007-08-02 11:40:45 -0400995 action = CMD_ACT_SET_TX_AUTO;
996 adapter->auto_rate = 1;
997 adapter->cur_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200998 } else {
Dan Williams8c512762007-08-02 11:40:45 -0400999 if (vwrq->value % 100000)
1000 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001001
1002 memset(rates, 0, sizeof(rates));
Dan Williams8c512762007-08-02 11:40:45 -04001003 copy_active_data_rates(adapter, rates);
1004 new_rate = vwrq->value / 500000;
1005 if (!memchr(rates, new_rate, sizeof(rates))) {
1006 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1007 new_rate);
1008 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001009 }
1010
Dan Williams8c512762007-08-02 11:40:45 -04001011 adapter->cur_rate = new_rate;
Dan Williamsffcae952007-08-02 11:35:46 -04001012 action = CMD_ACT_SET_TX_FIX_RATE;
Dan Williams8c512762007-08-02 11:40:45 -04001013 adapter->auto_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001014 }
1015
Holger Schurig10078322007-11-15 18:05:47 -05001016 ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001017 action, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001018
Dan Williams8c512762007-08-02 11:40:45 -04001019out:
Holger Schurig9012b282007-05-25 11:27:16 -04001020 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001021 return ret;
1022}
1023
Holger Schurig10078322007-11-15 18:05:47 -05001024static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001025 struct iw_param *vwrq, char *extra)
1026{
Holger Schurig69f90322007-11-23 15:43:44 +01001027 struct lbs_private *priv = dev->priv;
1028 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029
Holger Schurig9012b282007-05-25 11:27:16 -04001030 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001031
Holger Schurig10078322007-11-15 18:05:47 -05001032 if (adapter->connect_status == LBS_CONNECTED) {
Dan Williams8c512762007-08-02 11:40:45 -04001033 vwrq->value = adapter->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001034
Dan Williams8c512762007-08-02 11:40:45 -04001035 if (adapter->auto_rate)
1036 vwrq->fixed = 0;
1037 else
1038 vwrq->fixed = 1;
1039
1040 } else {
1041 vwrq->fixed = 0;
1042 vwrq->value = 0;
1043 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001044
Holger Schurig9012b282007-05-25 11:27:16 -04001045 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001046 return 0;
1047}
1048
Holger Schurig10078322007-11-15 18:05:47 -05001049static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001050 struct iw_request_info *info, u32 * uwrq, char *extra)
1051{
1052 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001053 struct lbs_private *priv = dev->priv;
1054 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001055 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001056
Holger Schurig9012b282007-05-25 11:27:16 -04001057 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001058
Dan Williams0dc5a292007-05-10 22:58:02 -04001059 if ( (*uwrq != IW_MODE_ADHOC)
1060 && (*uwrq != IW_MODE_INFRA)
1061 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001062 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001063 ret = -EINVAL;
1064 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001065 }
1066
1067 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -05001068 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001069 if (!assoc_req) {
1070 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001071 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001072 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001073 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001075 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001076 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001077 }
1078 mutex_unlock(&adapter->lock);
1079
Dan Williams0dc5a292007-05-10 22:58:02 -04001080out:
Holger Schurig9012b282007-05-25 11:27:16 -04001081 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001082 return ret;
1083}
1084
1085
1086/**
1087 * @brief Get Encryption key
1088 *
1089 * @param dev A pointer to net_device structure
1090 * @param info A pointer to iw_request_info structure
1091 * @param vwrq A pointer to iw_param structure
1092 * @param extra A pointer to extra data buf
1093 * @return 0 --success, otherwise fail
1094 */
Holger Schurig10078322007-11-15 18:05:47 -05001095static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001096 struct iw_request_info *info,
1097 struct iw_point *dwrq, u8 * extra)
1098{
Holger Schurig69f90322007-11-23 15:43:44 +01001099 struct lbs_private *priv = dev->priv;
1100 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001101 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1102
Holger Schurig9012b282007-05-25 11:27:16 -04001103 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001104
Holger Schurig9012b282007-05-25 11:27:16 -04001105 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001106 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1107
1108 dwrq->flags = 0;
1109
1110 /* Authentication method */
Dan Williams6affe782007-05-10 22:56:42 -04001111 switch (adapter->secinfo.auth_mode) {
1112 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001113 dwrq->flags = IW_ENCODE_OPEN;
1114 break;
1115
Dan Williams6affe782007-05-10 22:56:42 -04001116 case IW_AUTH_ALG_SHARED_KEY:
1117 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001118 dwrq->flags = IW_ENCODE_RESTRICTED;
1119 break;
1120 default:
1121 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1122 break;
1123 }
1124
Dan Williams889c05b2007-05-10 22:57:23 -04001125 if ( adapter->secinfo.wep_enabled
1126 || adapter->secinfo.WPAenabled
1127 || adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001128 dwrq->flags &= ~IW_ENCODE_DISABLED;
1129 } else {
1130 dwrq->flags |= IW_ENCODE_DISABLED;
1131 }
1132
1133 memset(extra, 0, 16);
1134
1135 mutex_lock(&adapter->lock);
1136
1137 /* Default to returning current transmit key */
1138 if (index < 0)
1139 index = adapter->wep_tx_keyidx;
1140
Dan Williams889c05b2007-05-10 22:57:23 -04001141 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001142 memcpy(extra, adapter->wep_keys[index].key,
1143 adapter->wep_keys[index].len);
1144 dwrq->length = adapter->wep_keys[index].len;
1145
1146 dwrq->flags |= (index + 1);
1147 /* Return WEP enabled */
1148 dwrq->flags &= ~IW_ENCODE_DISABLED;
1149 } else if ((adapter->secinfo.WPAenabled)
1150 || (adapter->secinfo.WPA2enabled)) {
1151 /* return WPA enabled */
1152 dwrq->flags &= ~IW_ENCODE_DISABLED;
1153 } else {
1154 dwrq->flags |= IW_ENCODE_DISABLED;
1155 }
1156
1157 mutex_unlock(&adapter->lock);
1158
1159 dwrq->flags |= IW_ENCODE_NOKEY;
1160
Joe Perches0795af52007-10-03 17:59:30 -07001161 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001162 extra[0], extra[1], extra[2],
1163 extra[3], extra[4], extra[5], dwrq->length);
1164
Holger Schurig9012b282007-05-25 11:27:16 -04001165 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001166
Holger Schurig9012b282007-05-25 11:27:16 -04001167 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001168 return 0;
1169}
1170
1171/**
1172 * @brief Set Encryption key (internal)
1173 *
1174 * @param priv A pointer to private card structure
1175 * @param key_material A pointer to key material
1176 * @param key_length length of key material
1177 * @param index key index to set
1178 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1179 * @return 0 --success, otherwise fail
1180 */
Holger Schurig10078322007-11-15 18:05:47 -05001181static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001182 const char *key_material,
1183 u16 key_length,
1184 u16 index,
1185 int set_tx_key)
1186{
Holger Schurig9012b282007-05-25 11:27:16 -04001187 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001188 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001189
Holger Schurig9012b282007-05-25 11:27:16 -04001190 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001191
1192 /* Paranoid validation of key index */
1193 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001194 ret = -EINVAL;
1195 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001196 }
1197
1198 /* validate max key length */
1199 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001200 ret = -EINVAL;
1201 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001202 }
1203
1204 pkey = &assoc_req->wep_keys[index];
1205
1206 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001207 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001208 pkey->type = KEY_TYPE_ID_WEP;
1209
1210 /* Standardize the key length */
1211 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1212 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1213 memcpy(pkey->key, key_material, key_length);
1214 }
1215
1216 if (set_tx_key) {
1217 /* Ensure the chosen key is valid */
1218 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001219 lbs_deb_wext("key not set, so cannot enable it\n");
1220 ret = -EINVAL;
1221 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001222 }
1223 assoc_req->wep_tx_keyidx = index;
1224 }
1225
Dan Williams889c05b2007-05-10 22:57:23 -04001226 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001227
Holger Schurig9012b282007-05-25 11:27:16 -04001228out:
1229 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1230 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001231}
1232
1233static int validate_key_index(u16 def_index, u16 raw_index,
1234 u16 *out_index, u16 *is_default)
1235{
1236 if (!out_index || !is_default)
1237 return -EINVAL;
1238
1239 /* Verify index if present, otherwise use default TX key index */
1240 if (raw_index > 0) {
1241 if (raw_index > 4)
1242 return -EINVAL;
1243 *out_index = raw_index - 1;
1244 } else {
1245 *out_index = def_index;
1246 *is_default = 1;
1247 }
1248 return 0;
1249}
1250
1251static void disable_wep(struct assoc_request *assoc_req)
1252{
1253 int i;
1254
Dan Williams90a42212007-05-25 23:01:24 -04001255 lbs_deb_enter(LBS_DEB_WEXT);
1256
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001257 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001258 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001259
1260 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001261 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001262 for (i = 0; i < 4; i++)
1263 assoc_req->wep_keys[i].len = 0;
1264
1265 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1266 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001267
1268 lbs_deb_leave(LBS_DEB_WEXT);
1269}
1270
1271static void disable_wpa(struct assoc_request *assoc_req)
1272{
1273 lbs_deb_enter(LBS_DEB_WEXT);
1274
Dan Williams1443b652007-08-02 10:45:55 -04001275 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001276 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1277 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1278
Dan Williams1443b652007-08-02 10:45:55 -04001279 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001280 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1281 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1282
1283 assoc_req->secinfo.WPAenabled = 0;
1284 assoc_req->secinfo.WPA2enabled = 0;
1285 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1286
1287 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001288}
1289
1290/**
1291 * @brief Set Encryption key
1292 *
1293 * @param dev A pointer to net_device structure
1294 * @param info A pointer to iw_request_info structure
1295 * @param vwrq A pointer to iw_param structure
1296 * @param extra A pointer to extra data buf
1297 * @return 0 --success, otherwise fail
1298 */
Holger Schurig10078322007-11-15 18:05:47 -05001299static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001300 struct iw_request_info *info,
1301 struct iw_point *dwrq, char *extra)
1302{
1303 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001304 struct lbs_private *priv = dev->priv;
1305 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001306 struct assoc_request * assoc_req;
1307 u16 is_default = 0, index = 0, set_tx_key = 0;
1308
Holger Schurig9012b282007-05-25 11:27:16 -04001309 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001310
1311 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -05001312 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001313 if (!assoc_req) {
1314 ret = -ENOMEM;
1315 goto out;
1316 }
1317
1318 if (dwrq->flags & IW_ENCODE_DISABLED) {
1319 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001320 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001321 goto out;
1322 }
1323
1324 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1325 (dwrq->flags & IW_ENCODE_INDEX),
1326 &index, &is_default);
1327 if (ret) {
1328 ret = -EINVAL;
1329 goto out;
1330 }
1331
1332 /* If WEP isn't enabled, or if there is no key data but a valid
1333 * index, set the TX key.
1334 */
Dan Williams889c05b2007-05-10 22:57:23 -04001335 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001336 set_tx_key = 1;
1337
Holger Schurig10078322007-11-15 18:05:47 -05001338 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001339 if (ret)
1340 goto out;
1341
1342 if (dwrq->length)
1343 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1344 if (set_tx_key)
1345 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1346
1347 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001348 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001350 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001351 }
1352
1353out:
1354 if (ret == 0) {
1355 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001356 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001357 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001358 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001359 }
1360 mutex_unlock(&adapter->lock);
1361
Holger Schurig9012b282007-05-25 11:27:16 -04001362 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001363 return ret;
1364}
1365
1366/**
1367 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1368 *
1369 * @param dev A pointer to net_device structure
1370 * @param info A pointer to iw_request_info structure
1371 * @param vwrq A pointer to iw_param structure
1372 * @param extra A pointer to extra data buf
1373 * @return 0 on success, otherwise failure
1374 */
Holger Schurig10078322007-11-15 18:05:47 -05001375static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001376 struct iw_request_info *info,
1377 struct iw_point *dwrq,
1378 char *extra)
1379{
1380 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +01001381 struct lbs_private *priv = dev->priv;
1382 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001383 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1384 int index, max_key_len;
1385
Holger Schurig9012b282007-05-25 11:27:16 -04001386 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001387
1388 max_key_len = dwrq->length - sizeof(*ext);
1389 if (max_key_len < 0)
1390 goto out;
1391
1392 index = dwrq->flags & IW_ENCODE_INDEX;
1393 if (index) {
1394 if (index < 1 || index > 4)
1395 goto out;
1396 index--;
1397 } else {
1398 index = adapter->wep_tx_keyidx;
1399 }
1400
Roel Kluinf59d9782007-10-26 21:51:26 +02001401 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001402 ext->alg != IW_ENCODE_ALG_WEP) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001403 if (index != 0 || adapter->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001404 goto out;
1405 }
1406
1407 dwrq->flags = index + 1;
1408 memset(ext, 0, sizeof(*ext));
1409
Dan Williams889c05b2007-05-10 22:57:23 -04001410 if ( !adapter->secinfo.wep_enabled
1411 && !adapter->secinfo.WPAenabled
1412 && !adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001413 ext->alg = IW_ENCODE_ALG_NONE;
1414 ext->key_len = 0;
1415 dwrq->flags |= IW_ENCODE_DISABLED;
1416 } else {
1417 u8 *key = NULL;
1418
Dan Williams889c05b2007-05-10 22:57:23 -04001419 if ( adapter->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001420 && !adapter->secinfo.WPAenabled
1421 && !adapter->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001422 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001423 ext->alg = IW_ENCODE_ALG_WEP;
1424 ext->key_len = adapter->wep_keys[index].len;
1425 key = &adapter->wep_keys[index].key[0];
Dan Williams889c05b2007-05-10 22:57:23 -04001426 } else if ( !adapter->secinfo.wep_enabled
1427 && (adapter->secinfo.WPAenabled ||
1428 adapter->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001429 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001430 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001431
1432 if ( adapter->wpa_mcast_key.len
1433 && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1434 pkey = &adapter->wpa_mcast_key;
1435 else if ( adapter->wpa_unicast_key.len
1436 && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1437 pkey = &adapter->wpa_unicast_key;
1438
1439 if (pkey) {
1440 if (pkey->type == KEY_TYPE_ID_AES) {
1441 ext->alg = IW_ENCODE_ALG_CCMP;
1442 } else {
1443 ext->alg = IW_ENCODE_ALG_TKIP;
1444 }
1445 ext->key_len = pkey->len;
1446 key = &pkey->key[0];
1447 } else {
1448 ext->alg = IW_ENCODE_ALG_TKIP;
1449 ext->key_len = 0;
1450 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001451 } else {
1452 goto out;
1453 }
1454
1455 if (ext->key_len > max_key_len) {
1456 ret = -E2BIG;
1457 goto out;
1458 }
1459
1460 if (ext->key_len)
1461 memcpy(ext->key, key, ext->key_len);
1462 else
1463 dwrq->flags |= IW_ENCODE_NOKEY;
1464 dwrq->flags |= IW_ENCODE_ENABLED;
1465 }
1466 ret = 0;
1467
1468out:
Holger Schurig9012b282007-05-25 11:27:16 -04001469 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001470 return ret;
1471}
1472
1473/**
1474 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1475 *
1476 * @param dev A pointer to net_device structure
1477 * @param info A pointer to iw_request_info structure
1478 * @param vwrq A pointer to iw_param structure
1479 * @param extra A pointer to extra data buf
1480 * @return 0 --success, otherwise fail
1481 */
Holger Schurig10078322007-11-15 18:05:47 -05001482static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001483 struct iw_request_info *info,
1484 struct iw_point *dwrq,
1485 char *extra)
1486{
1487 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001488 struct lbs_private *priv = dev->priv;
1489 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001490 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1491 int alg = ext->alg;
1492 struct assoc_request * assoc_req;
1493
Holger Schurig9012b282007-05-25 11:27:16 -04001494 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001495
1496 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -05001497 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001498 if (!assoc_req) {
1499 ret = -ENOMEM;
1500 goto out;
1501 }
1502
1503 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1504 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001505 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001506 } else if (alg == IW_ENCODE_ALG_WEP) {
1507 u16 is_default = 0, index, set_tx_key = 0;
1508
1509 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1510 (dwrq->flags & IW_ENCODE_INDEX),
1511 &index, &is_default);
1512 if (ret)
1513 goto out;
1514
1515 /* If WEP isn't enabled, or if there is no key data but a valid
1516 * index, or if the set-TX-key flag was passed, set the TX key.
1517 */
Dan Williams889c05b2007-05-10 22:57:23 -04001518 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001519 || (dwrq->length == 0 && !is_default)
1520 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1521 set_tx_key = 1;
1522
1523 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001524 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001525 set_tx_key);
1526 if (ret)
1527 goto out;
1528
1529 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001530 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001531 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001532 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001533 }
1534
1535 /* Mark the various WEP bits as modified */
1536 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1537 if (dwrq->length)
1538 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1539 if (set_tx_key)
1540 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001541 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001542 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001543
1544 /* validate key length */
1545 if (((alg == IW_ENCODE_ALG_TKIP)
1546 && (ext->key_len != KEY_LEN_WPA_TKIP))
1547 || ((alg == IW_ENCODE_ALG_CCMP)
1548 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001549 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001550 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001551 ext->key_len,
1552 alg);
1553 ret = -EINVAL;
1554 goto out;
1555 }
1556
Dan Williams90a42212007-05-25 23:01:24 -04001557 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001558 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001559 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1560 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001561 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001562 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1563 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001564
Dan Williams1443b652007-08-02 10:45:55 -04001565 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001566 memcpy(pkey->key, ext->key, ext->key_len);
1567 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001568 if (pkey->len)
1569 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001570
Dan Williams90a42212007-05-25 23:01:24 -04001571 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001572 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1573 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001574 } else {
1575 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001576 }
1577
Dan Williams90a42212007-05-25 23:01:24 -04001578 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001579 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001580 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001581 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001582 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001583
1584 /* If WPA isn't enabled yet, do that now */
1585 if ( assoc_req->secinfo.WPAenabled == 0
1586 && assoc_req->secinfo.WPA2enabled == 0) {
1587 assoc_req->secinfo.WPAenabled = 1;
1588 assoc_req->secinfo.WPA2enabled = 1;
1589 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1590 }
1591
1592 disable_wep (assoc_req);
1593 }
1594
1595out:
1596 if (ret == 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001597 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001598 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001599 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001600 }
1601 mutex_unlock(&adapter->lock);
1602
Holger Schurig9012b282007-05-25 11:27:16 -04001603 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001604 return ret;
1605}
1606
1607
Holger Schurig10078322007-11-15 18:05:47 -05001608static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001609 struct iw_request_info *info,
1610 struct iw_point *dwrq,
1611 char *extra)
1612{
Holger Schurig69f90322007-11-23 15:43:44 +01001613 struct lbs_private *priv = dev->priv;
1614 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001615 int ret = 0;
1616 struct assoc_request * assoc_req;
1617
Holger Schurig9012b282007-05-25 11:27:16 -04001618 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001619
1620 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -05001621 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001622 if (!assoc_req) {
1623 ret = -ENOMEM;
1624 goto out;
1625 }
1626
1627 if (dwrq->length > MAX_WPA_IE_LEN ||
1628 (dwrq->length && extra == NULL)) {
1629 ret = -EINVAL;
1630 goto out;
1631 }
1632
1633 if (dwrq->length) {
1634 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1635 assoc_req->wpa_ie_len = dwrq->length;
1636 } else {
1637 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
1638 assoc_req->wpa_ie_len = 0;
1639 }
1640
1641out:
1642 if (ret == 0) {
1643 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001644 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001645 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001646 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001647 }
1648 mutex_unlock(&adapter->lock);
1649
Holger Schurig9012b282007-05-25 11:27:16 -04001650 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001651 return ret;
1652}
1653
Holger Schurig10078322007-11-15 18:05:47 -05001654static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001655 struct iw_request_info *info,
1656 struct iw_point *dwrq,
1657 char *extra)
1658{
Holger Schurig9012b282007-05-25 11:27:16 -04001659 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001660 struct lbs_private *priv = dev->priv;
1661 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001662
Holger Schurig9012b282007-05-25 11:27:16 -04001663 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001664
1665 if (adapter->wpa_ie_len == 0) {
1666 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001667 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001668 }
1669
1670 if (dwrq->length < adapter->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001671 ret = -E2BIG;
1672 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001673 }
1674
1675 dwrq->length = adapter->wpa_ie_len;
1676 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
1677
Holger Schurig9012b282007-05-25 11:27:16 -04001678out:
1679 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1680 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001681}
1682
1683
Holger Schurig10078322007-11-15 18:05:47 -05001684static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001685 struct iw_request_info *info,
1686 struct iw_param *dwrq,
1687 char *extra)
1688{
Holger Schurig69f90322007-11-23 15:43:44 +01001689 struct lbs_private *priv = dev->priv;
1690 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001691 struct assoc_request * assoc_req;
1692 int ret = 0;
1693 int updated = 0;
1694
Holger Schurig9012b282007-05-25 11:27:16 -04001695 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001696
1697 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -05001698 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001699 if (!assoc_req) {
1700 ret = -ENOMEM;
1701 goto out;
1702 }
1703
1704 switch (dwrq->flags & IW_AUTH_INDEX) {
1705 case IW_AUTH_TKIP_COUNTERMEASURES:
1706 case IW_AUTH_CIPHER_PAIRWISE:
1707 case IW_AUTH_CIPHER_GROUP:
1708 case IW_AUTH_KEY_MGMT:
Dan Williams90a42212007-05-25 23:01:24 -04001709 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001710 /*
1711 * libertas does not use these parameters
1712 */
1713 break;
1714
1715 case IW_AUTH_WPA_VERSION:
1716 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1717 assoc_req->secinfo.WPAenabled = 0;
1718 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001719 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001720 }
1721 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1722 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001723 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001724 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001725 }
1726 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1727 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001728 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001729 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001730 }
1731 updated = 1;
1732 break;
1733
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001734 case IW_AUTH_80211_AUTH_ALG:
1735 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001736 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001737 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001738 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001739 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001740 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001741 } else {
1742 ret = -EINVAL;
1743 }
1744 updated = 1;
1745 break;
1746
1747 case IW_AUTH_WPA_ENABLED:
1748 if (dwrq->value) {
1749 if (!assoc_req->secinfo.WPAenabled &&
1750 !assoc_req->secinfo.WPA2enabled) {
1751 assoc_req->secinfo.WPAenabled = 1;
1752 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001753 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001754 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001755 }
1756 } else {
1757 assoc_req->secinfo.WPAenabled = 0;
1758 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001759 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001760 }
1761 updated = 1;
1762 break;
1763
1764 default:
1765 ret = -EOPNOTSUPP;
1766 break;
1767 }
1768
1769out:
1770 if (ret == 0) {
1771 if (updated)
1772 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001773 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001774 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001775 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001776 }
1777 mutex_unlock(&adapter->lock);
1778
Holger Schurig9012b282007-05-25 11:27:16 -04001779 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001780 return ret;
1781}
1782
Holger Schurig10078322007-11-15 18:05:47 -05001783static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001784 struct iw_request_info *info,
1785 struct iw_param *dwrq,
1786 char *extra)
1787{
Holger Schurig9012b282007-05-25 11:27:16 -04001788 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001789 struct lbs_private *priv = dev->priv;
1790 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001791
Holger Schurig9012b282007-05-25 11:27:16 -04001792 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001793
1794 switch (dwrq->flags & IW_AUTH_INDEX) {
1795 case IW_AUTH_WPA_VERSION:
1796 dwrq->value = 0;
1797 if (adapter->secinfo.WPAenabled)
1798 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1799 if (adapter->secinfo.WPA2enabled)
1800 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1801 if (!dwrq->value)
1802 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1803 break;
1804
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001805 case IW_AUTH_80211_AUTH_ALG:
Dan Williams6affe782007-05-10 22:56:42 -04001806 dwrq->value = adapter->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001807 break;
1808
1809 case IW_AUTH_WPA_ENABLED:
1810 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
1811 dwrq->value = 1;
1812 break;
1813
1814 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001815 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816 }
1817
Holger Schurig9012b282007-05-25 11:27:16 -04001818 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1819 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001820}
1821
1822
Holger Schurig10078322007-11-15 18:05:47 -05001823static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001824 struct iw_param *vwrq, char *extra)
1825{
1826 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001827 struct lbs_private *priv = dev->priv;
1828 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001829
1830 u16 dbm;
1831
Holger Schurig9012b282007-05-25 11:27:16 -04001832 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001833
1834 if (vwrq->disabled) {
Holger Schurig10078322007-11-15 18:05:47 -05001835 lbs_radio_ioctl(priv, RADIO_OFF);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001836 return 0;
1837 }
1838
Dan Williams0aef64d2007-08-02 11:31:18 -04001839 adapter->preamble = CMD_TYPE_AUTO_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001840
Holger Schurig10078322007-11-15 18:05:47 -05001841 lbs_radio_ioctl(priv, RADIO_ON);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001842
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001843 /* Userspace check in iwrange if it should use dBm or mW,
1844 * therefore this should never happen... Jean II */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001846 return -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001847 } else
1848 dbm = (u16) vwrq->value;
1849
1850 /* auto tx power control */
1851
1852 if (vwrq->fixed == 0)
1853 dbm = 0xffff;
1854
Holger Schurig9012b282007-05-25 11:27:16 -04001855 lbs_deb_wext("txpower set %d dbm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001856
Holger Schurig10078322007-11-15 18:05:47 -05001857 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -04001858 CMD_802_11_RF_TX_POWER,
1859 CMD_ACT_TX_POWER_OPT_SET_LOW,
1860 CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001861
Holger Schurig9012b282007-05-25 11:27:16 -04001862 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001863 return ret;
1864}
1865
Holger Schurig10078322007-11-15 18:05:47 -05001866static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001867 struct iw_point *dwrq, char *extra)
1868{
Holger Schurig69f90322007-11-23 15:43:44 +01001869 struct lbs_private *priv = dev->priv;
1870 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001871
Holger Schurig9012b282007-05-25 11:27:16 -04001872 lbs_deb_enter(LBS_DEB_WEXT);
1873
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001874 /*
1875 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1876 * the SSID list...
1877 */
1878
1879 /*
1880 * Get the current SSID
1881 */
Holger Schurig10078322007-11-15 18:05:47 -05001882 if (adapter->connect_status == LBS_CONNECTED) {
Dan Williamsd8efea22007-05-28 23:54:55 -04001883 memcpy(extra, adapter->curbssparams.ssid,
1884 adapter->curbssparams.ssid_len);
1885 extra[adapter->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001886 } else {
1887 memset(extra, 0, 32);
Dan Williamsd8efea22007-05-28 23:54:55 -04001888 extra[adapter->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001889 }
1890 /*
1891 * If none, we may want to get the one that was set
1892 */
1893
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001894 dwrq->length = adapter->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001895
1896 dwrq->flags = 1; /* active */
1897
Holger Schurig9012b282007-05-25 11:27:16 -04001898 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001899 return 0;
1900}
1901
Holger Schurig10078322007-11-15 18:05:47 -05001902static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001903 struct iw_point *dwrq, char *extra)
1904{
Holger Schurig69f90322007-11-23 15:43:44 +01001905 struct lbs_private *priv = dev->priv;
1906 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001907 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04001908 u8 ssid[IW_ESSID_MAX_SIZE];
1909 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001910 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001911 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001912
Holger Schurig9012b282007-05-25 11:27:16 -04001913 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001914
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001915 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001916 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001917 ret = -E2BIG;
1918 goto out;
1919 }
1920
Dan Williamsd8efea22007-05-28 23:54:55 -04001921 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001922
Dan Williamsd8efea22007-05-28 23:54:55 -04001923 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001924 /* "any" SSID requested; leave SSID blank */
1925 } else {
1926 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04001927 memcpy(&ssid, extra, in_ssid_len);
1928 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001929 }
1930
Dan Williamsd8efea22007-05-28 23:54:55 -04001931 if (!ssid_len) {
1932 lbs_deb_wext("requested any SSID\n");
1933 } else {
1934 lbs_deb_wext("requested SSID '%s'\n",
1935 escape_essid(ssid, ssid_len));
1936 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001937
1938out:
1939 mutex_lock(&adapter->lock);
1940 if (ret == 0) {
1941 /* Get or create the current association request */
Holger Schurig10078322007-11-15 18:05:47 -05001942 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001943 if (!assoc_req) {
1944 ret = -ENOMEM;
1945 } else {
1946 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04001947 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1948 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001949 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001950 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001951 }
1952 }
1953
1954 /* Cancel the association request if there was an error */
1955 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001956 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001957 }
1958
1959 mutex_unlock(&adapter->lock);
1960
Holger Schurig9012b282007-05-25 11:27:16 -04001961 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001962 return ret;
1963}
1964
1965/**
1966 * @brief Connect to the AP or Ad-hoc Network with specific bssid
1967 *
1968 * @param dev A pointer to net_device structure
1969 * @param info A pointer to iw_request_info structure
1970 * @param awrq A pointer to iw_param structure
1971 * @param extra A pointer to extra data buf
1972 * @return 0 --success, otherwise fail
1973 */
Holger Schurig10078322007-11-15 18:05:47 -05001974static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001975 struct sockaddr *awrq, char *extra)
1976{
Holger Schurig69f90322007-11-23 15:43:44 +01001977 struct lbs_private *priv = dev->priv;
1978 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001979 struct assoc_request * assoc_req;
1980 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07001981 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001982
Holger Schurig9012b282007-05-25 11:27:16 -04001983 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001984
1985 if (awrq->sa_family != ARPHRD_ETHER)
1986 return -EINVAL;
1987
Joe Perches0795af52007-10-03 17:59:30 -07001988 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001989
1990 mutex_lock(&adapter->lock);
1991
1992 /* Get or create the current association request */
Holger Schurig10078322007-11-15 18:05:47 -05001993 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001994 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05001995 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001996 ret = -ENOMEM;
1997 } else {
1998 /* Copy the BSSID to the association request */
1999 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2000 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002001 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002002 }
2003
2004 mutex_unlock(&adapter->lock);
2005
2006 return ret;
2007}
2008
Holger Schurig69f90322007-11-23 15:43:44 +01002009void lbs_get_fwversion(struct lbs_adapter *adapter, char *fwversion, int maxlen)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002010{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002011 char fwver[32];
2012
2013 mutex_lock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002014
David Woodhousee5b3d472007-05-25 23:40:21 -04002015 if (adapter->fwreleasenumber[3] == 0)
2016 sprintf(fwver, "%u.%u.%u",
2017 adapter->fwreleasenumber[2],
2018 adapter->fwreleasenumber[1],
2019 adapter->fwreleasenumber[0]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002020 else
2021 sprintf(fwver, "%u.%u.%u.p%u",
David Woodhousee5b3d472007-05-25 23:40:21 -04002022 adapter->fwreleasenumber[2],
2023 adapter->fwreleasenumber[1],
2024 adapter->fwreleasenumber[0],
2025 adapter->fwreleasenumber[3]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002026
David Woodhousee5b3d472007-05-25 23:40:21 -04002027 mutex_unlock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002028 snprintf(fwversion, maxlen, fwver);
2029}
2030
2031
2032/*
2033 * iwconfig settable callbacks
2034 */
Holger Schurig10078322007-11-15 18:05:47 -05002035static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002036 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002037 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002038 (iw_handler) NULL, /* SIOCSIWNWID */
2039 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002040 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2041 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2042 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2043 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002044 (iw_handler) NULL, /* SIOCSIWSENS */
2045 (iw_handler) NULL, /* SIOCGIWSENS */
2046 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002047 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002048 (iw_handler) NULL, /* SIOCSIWPRIV */
2049 (iw_handler) NULL, /* SIOCGIWPRIV */
2050 (iw_handler) NULL, /* SIOCSIWSTATS */
2051 (iw_handler) NULL, /* SIOCGIWSTATS */
2052 iw_handler_set_spy, /* SIOCSIWSPY */
2053 iw_handler_get_spy, /* SIOCGIWSPY */
2054 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2055 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002056 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2057 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002058 (iw_handler) NULL, /* SIOCSIWMLME */
2059 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002060 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2061 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2062 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2063 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2064 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2065 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002066 (iw_handler) NULL, /* -- hole -- */
2067 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002068 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2069 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2070 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2071 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2072 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2073 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2074 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2075 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2076 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2077 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2078 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2079 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2080 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2081 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002082 (iw_handler) NULL, /* -- hole -- */
2083 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002084 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2085 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2086 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2087 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2088 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2089 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002090 (iw_handler) NULL, /* SIOCSIWPMKSA */
2091};
2092
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002093static const iw_handler mesh_wlan_handler[] = {
2094 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002095 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002096 (iw_handler) NULL, /* SIOCSIWNWID */
2097 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002098 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2099 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002100 (iw_handler) NULL, /* SIOCSIWMODE */
2101 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2102 (iw_handler) NULL, /* SIOCSIWSENS */
2103 (iw_handler) NULL, /* SIOCGIWSENS */
2104 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002105 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002106 (iw_handler) NULL, /* SIOCSIWPRIV */
2107 (iw_handler) NULL, /* SIOCGIWPRIV */
2108 (iw_handler) NULL, /* SIOCSIWSTATS */
2109 (iw_handler) NULL, /* SIOCGIWSTATS */
2110 iw_handler_set_spy, /* SIOCSIWSPY */
2111 iw_handler_get_spy, /* SIOCGIWSPY */
2112 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2113 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2114 (iw_handler) NULL, /* SIOCSIWAP */
2115 (iw_handler) NULL, /* SIOCGIWAP */
2116 (iw_handler) NULL, /* SIOCSIWMLME */
2117 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002118 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2119 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002120 (iw_handler) NULL, /* SIOCSIWESSID */
2121 (iw_handler) NULL, /* SIOCGIWESSID */
2122 (iw_handler) NULL, /* SIOCSIWNICKN */
2123 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2124 (iw_handler) NULL, /* -- hole -- */
2125 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002126 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2127 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2128 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2129 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2130 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2131 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2132 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2133 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2134 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2135 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2136 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2137 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2138 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2139 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002140 (iw_handler) NULL, /* -- hole -- */
2141 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002142 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2143 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2144 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2145 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2146 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2147 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002148 (iw_handler) NULL, /* SIOCSIWPMKSA */
2149};
Holger Schurig10078322007-11-15 18:05:47 -05002150struct iw_handler_def lbs_handler_def = {
2151 .num_standard = ARRAY_SIZE(lbs_handler),
2152 .standard = (iw_handler *) lbs_handler,
2153 .get_wireless_stats = lbs_get_wireless_stats,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002154};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002155
2156struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002157 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002158 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002159 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002160};