blob: 2231a65a537d15196dfcdd6b841cee714dbbe463 [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 Schurig10078322007-11-15 18:05:47 -050024static inline void lbs_postpone_association_work(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 Schurig10078322007-11-15 18:05:47 -050032static inline void lbs_cancel_association_work(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 Schurig10078322007-11-15 18:05:47 -050043 * @param adapter A pointer to 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 Schurig10078322007-11-15 18:05:47 -050048struct chan_freq_power *lbs_find_cfp_by_band_and_channel(lbs_adapter *adapter,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020049 u8 band, u16 channel)
50{
51 struct chan_freq_power *cfp = NULL;
52 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020053 int i, j;
54
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020055 for (j = 0; !cfp && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020056 rc = &adapter->region_channel[j];
57
58 if (adapter->enable11d)
59 rc = &adapter->universal_channel[j];
60 if (!rc->valid || !rc->CFP)
61 continue;
62 if (rc->band != band)
63 continue;
64 for (i = 0; i < rc->nrcfp; i++) {
65 if (rc->CFP[i].channel == channel) {
66 cfp = &rc->CFP[i];
67 break;
68 }
69 }
70 }
71
72 if (!cfp && channel)
Holger Schurig10078322007-11-15 18:05:47 -050073 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
Holger Schurig9012b282007-05-25 11:27:16 -040074 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075
76 return cfp;
77}
78
79/**
80 * @brief Find the channel frequency power info with specific frequency
81 *
Holger Schurig10078322007-11-15 18:05:47 -050082 * @param adapter A pointer to lbs_adapter structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020083 * @param band it can be BAND_A, BAND_G or BAND_B
84 * @param freq the frequency for looking
85 * @return A pointer to struct chan_freq_power structure or NULL if not find.
86 */
Holger Schurig10078322007-11-15 18:05:47 -050087static struct chan_freq_power *find_cfp_by_band_and_freq(lbs_adapter *adapter,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020088 u8 band, u32 freq)
89{
90 struct chan_freq_power *cfp = NULL;
91 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020092 int i, j;
93
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020094 for (j = 0; !cfp && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020095 rc = &adapter->region_channel[j];
96
97 if (adapter->enable11d)
98 rc = &adapter->universal_channel[j];
99 if (!rc->valid || !rc->CFP)
100 continue;
101 if (rc->band != band)
102 continue;
103 for (i = 0; i < rc->nrcfp; i++) {
104 if (rc->CFP[i].freq == freq) {
105 cfp = &rc->CFP[i];
106 break;
107 }
108 }
109 }
110
111 if (!cfp && freq)
Holger Schurig9012b282007-05-25 11:27:16 -0400112 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
113 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200114
115 return cfp;
116}
117
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200118
119/**
120 * @brief Set Radio On/OFF
121 *
Holger Schurig10078322007-11-15 18:05:47 -0500122 * @param priv A pointer to lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200123 * @option Radio Option
124 * @return 0 --success, otherwise fail
125 */
Holger Schurig10078322007-11-15 18:05:47 -0500126static int lbs_radio_ioctl(lbs_private *priv, u8 option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127{
128 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500129 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130
Holger Schurig9012b282007-05-25 11:27:16 -0400131 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200132
133 if (adapter->radioon != option) {
Holger Schurig9012b282007-05-25 11:27:16 -0400134 lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200135 adapter->radioon = option;
136
Holger Schurig10078322007-11-15 18:05:47 -0500137 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400138 CMD_802_11_RADIO_CONTROL,
139 CMD_ACT_SET,
140 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200141 }
142
Holger Schurig9012b282007-05-25 11:27:16 -0400143 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200144 return ret;
145}
146
147/**
Dan Williams8c512762007-08-02 11:40:45 -0400148 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 *
Holger Schurig10078322007-11-15 18:05:47 -0500150 * @param adapter A pointer to lbs_adapter structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200151 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152 */
Holger Schurig10078322007-11-15 18:05:47 -0500153static void copy_active_data_rates(lbs_adapter *adapter, u8 *rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200154{
Holger Schurig9012b282007-05-25 11:27:16 -0400155 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156
Brajesh Dave01d77d82007-11-20 17:44:14 -0500157 if ((adapter->connect_status != LBS_CONNECTED) &&
158 (adapter->mesh_connect_status != LBS_CONNECTED))
Holger Schurig10078322007-11-15 18:05:47 -0500159 memcpy(rates, lbs_bg_rates, MAX_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400160 else
161 memcpy(rates, adapter->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200162
Dan Williams8c512762007-08-02 11:40:45 -0400163 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200164}
165
Holger Schurig10078322007-11-15 18:05:47 -0500166static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200167 char *cwrq, char *extra)
168{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200169
Holger Schurig9012b282007-05-25 11:27:16 -0400170 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200171
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400172 /* We could add support for 802.11n here as needed. Jean II */
173 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200174
Holger Schurig9012b282007-05-25 11:27:16 -0400175 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200176 return 0;
177}
178
Holger Schurig10078322007-11-15 18:05:47 -0500179static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200180 struct iw_freq *fwrq, char *extra)
181{
Holger Schurig10078322007-11-15 18:05:47 -0500182 lbs_private *priv = dev->priv;
183 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200184 struct chan_freq_power *cfp;
185
Holger Schurig9012b282007-05-25 11:27:16 -0400186 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200187
Holger Schurig10078322007-11-15 18:05:47 -0500188 cfp = lbs_find_cfp_by_band_and_channel(adapter, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200189 adapter->curbssparams.channel);
190
191 if (!cfp) {
192 if (adapter->curbssparams.channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400193 lbs_deb_wext("invalid channel %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200194 adapter->curbssparams.channel);
195 return -EINVAL;
196 }
197
198 fwrq->m = (long)cfp->freq * 100000;
199 fwrq->e = 1;
200
Holger Schurig9012b282007-05-25 11:27:16 -0400201 lbs_deb_wext("freq %u\n", fwrq->m);
202 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200203 return 0;
204}
205
Holger Schurig10078322007-11-15 18:05:47 -0500206static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200207 struct sockaddr *awrq, char *extra)
208{
Holger Schurig10078322007-11-15 18:05:47 -0500209 lbs_private *priv = dev->priv;
210 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211
Holger Schurig9012b282007-05-25 11:27:16 -0400212 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200213
Holger Schurig10078322007-11-15 18:05:47 -0500214 if (adapter->connect_status == LBS_CONNECTED) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200215 memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
216 } else {
217 memset(awrq->sa_data, 0, ETH_ALEN);
218 }
219 awrq->sa_family = ARPHRD_ETHER;
220
Holger Schurig9012b282007-05-25 11:27:16 -0400221 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200222 return 0;
223}
224
Holger Schurig10078322007-11-15 18:05:47 -0500225static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226 struct iw_point *dwrq, char *extra)
227{
Holger Schurig10078322007-11-15 18:05:47 -0500228 lbs_private *priv = dev->priv;
229 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200230
Holger Schurig9012b282007-05-25 11:27:16 -0400231 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200232
233 /*
234 * Check the size of the string
235 */
236
237 if (dwrq->length > 16) {
238 return -E2BIG;
239 }
240
241 mutex_lock(&adapter->lock);
242 memset(adapter->nodename, 0, sizeof(adapter->nodename));
243 memcpy(adapter->nodename, extra, dwrq->length);
244 mutex_unlock(&adapter->lock);
245
Holger Schurig9012b282007-05-25 11:27:16 -0400246 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200247 return 0;
248}
249
Holger Schurig10078322007-11-15 18:05:47 -0500250static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200251 struct iw_point *dwrq, char *extra)
252{
Holger Schurig10078322007-11-15 18:05:47 -0500253 lbs_private *priv = dev->priv;
254 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200255
Holger Schurig9012b282007-05-25 11:27:16 -0400256 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200257
Holger Schurig04799fa2007-10-09 15:04:14 +0200258 dwrq->length = strlen(adapter->nodename);
259 memcpy(extra, adapter->nodename, dwrq->length);
260 extra[dwrq->length] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200261
Holger Schurig04799fa2007-10-09 15:04:14 +0200262 dwrq->flags = 1; /* active */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200263
Holger Schurig9012b282007-05-25 11:27:16 -0400264 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265 return 0;
266}
267
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400268static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
269 struct iw_point *dwrq, char *extra)
270{
Holger Schurig10078322007-11-15 18:05:47 -0500271 lbs_private *priv = dev->priv;
272 lbs_adapter *adapter = priv->adapter;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400273
274 lbs_deb_enter(LBS_DEB_WEXT);
275
276 /* Use nickname to indicate that mesh is on */
277
Brajesh Dave01d77d82007-11-20 17:44:14 -0500278 if (adapter->mesh_connect_status == LBS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400279 strncpy(extra, "Mesh", 12);
280 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400281 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400282 }
283
284 else {
285 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400286 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400287 }
288
289 lbs_deb_leave(LBS_DEB_WEXT);
290 return 0;
291}
Holger Schurig04799fa2007-10-09 15:04:14 +0200292
Holger Schurig10078322007-11-15 18:05:47 -0500293static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200294 struct iw_param *vwrq, char *extra)
295{
296 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500297 lbs_private *priv = dev->priv;
298 lbs_adapter *adapter = priv->adapter;
David Woodhouse981f1872007-05-25 23:36:54 -0400299 u32 rthr = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300
Holger Schurig9012b282007-05-25 11:27:16 -0400301 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302
303 if (vwrq->disabled) {
304 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
305 } else {
306 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
307 return -EINVAL;
308 adapter->rtsthsd = rthr;
309 }
310
Holger Schurig10078322007-11-15 18:05:47 -0500311 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400312 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200313 OID_802_11_RTS_THRESHOLD, &rthr);
314
Holger Schurig9012b282007-05-25 11:27:16 -0400315 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200316 return ret;
317}
318
Holger Schurig10078322007-11-15 18:05:47 -0500319static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200320 struct iw_param *vwrq, char *extra)
321{
322 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500323 lbs_private *priv = dev->priv;
324 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200325
Holger Schurig9012b282007-05-25 11:27:16 -0400326 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200327
328 adapter->rtsthsd = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500329 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400330 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200331 OID_802_11_RTS_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400332 if (ret)
333 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334
335 vwrq->value = adapter->rtsthsd;
336 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
337 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
338 vwrq->fixed = 1;
339
Holger Schurig9012b282007-05-25 11:27:16 -0400340out:
341 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
342 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343}
344
Holger Schurig10078322007-11-15 18:05:47 -0500345static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200346 struct iw_param *vwrq, char *extra)
347{
348 int ret = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400349 u32 fthr = vwrq->value;
Holger Schurig10078322007-11-15 18:05:47 -0500350 lbs_private *priv = dev->priv;
351 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352
Holger Schurig9012b282007-05-25 11:27:16 -0400353 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354
355 if (vwrq->disabled) {
356 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
357 } else {
358 if (fthr < MRVDRV_FRAG_MIN_VALUE
359 || fthr > MRVDRV_FRAG_MAX_VALUE)
360 return -EINVAL;
361 adapter->fragthsd = fthr;
362 }
363
Holger Schurig10078322007-11-15 18:05:47 -0500364 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400365 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200366 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
Holger Schurig9012b282007-05-25 11:27:16 -0400367
368 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369 return ret;
370}
371
Holger Schurig10078322007-11-15 18:05:47 -0500372static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373 struct iw_param *vwrq, char *extra)
374{
375 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500376 lbs_private *priv = dev->priv;
377 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378
Holger Schurig9012b282007-05-25 11:27:16 -0400379 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380
381 adapter->fragthsd = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500382 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400383 CMD_802_11_SNMP_MIB,
384 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200385 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400386 if (ret)
387 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388
389 vwrq->value = adapter->fragthsd;
390 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
391 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
392 vwrq->fixed = 1;
393
Holger Schurig9012b282007-05-25 11:27:16 -0400394out:
395 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200396 return ret;
397}
398
Holger Schurig10078322007-11-15 18:05:47 -0500399static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400 struct iw_request_info *info, u32 * uwrq, char *extra)
401{
Holger Schurig10078322007-11-15 18:05:47 -0500402 lbs_private *priv = dev->priv;
403 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404
Holger Schurig9012b282007-05-25 11:27:16 -0400405 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200406
Dan Williams0dc5a292007-05-10 22:58:02 -0400407 *uwrq = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408
Holger Schurig9012b282007-05-25 11:27:16 -0400409 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410 return 0;
411}
412
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400413static int mesh_wlan_get_mode(struct net_device *dev,
414 struct iw_request_info *info, u32 * uwrq,
415 char *extra)
416{
417 lbs_deb_enter(LBS_DEB_WEXT);
418
419 *uwrq = IW_MODE_REPEAT ;
420
421 lbs_deb_leave(LBS_DEB_WEXT);
422 return 0;
423}
424
Holger Schurig10078322007-11-15 18:05:47 -0500425static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426 struct iw_request_info *info,
427 struct iw_param *vwrq, char *extra)
428{
429 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500430 lbs_private *priv = dev->priv;
431 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200432
Holger Schurig9012b282007-05-25 11:27:16 -0400433 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200434
Holger Schurig10078322007-11-15 18:05:47 -0500435 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400436 CMD_802_11_RF_TX_POWER,
437 CMD_ACT_TX_POWER_OPT_GET,
438 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200439
Holger Schurig9012b282007-05-25 11:27:16 -0400440 if (ret)
441 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200442
Holger Schurig9012b282007-05-25 11:27:16 -0400443 lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200444 vwrq->value = adapter->txpowerlevel;
445 vwrq->fixed = 1;
446 if (adapter->radioon) {
447 vwrq->disabled = 0;
448 vwrq->flags = IW_TXPOW_DBM;
449 } else {
450 vwrq->disabled = 1;
451 }
452
Holger Schurig9012b282007-05-25 11:27:16 -0400453out:
454 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
455 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200456}
457
Holger Schurig10078322007-11-15 18:05:47 -0500458static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459 struct iw_param *vwrq, char *extra)
460{
461 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500462 lbs_private *priv = dev->priv;
463 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464
Holger Schurig9012b282007-05-25 11:27:16 -0400465 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200466
467 if (vwrq->flags == IW_RETRY_LIMIT) {
468 /* The MAC has a 4-bit Total_Tx_Count register
469 Total_Tx_Count = 1 + Tx_Retry_Count */
470#define TX_RETRY_MIN 0
471#define TX_RETRY_MAX 14
472 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
473 return -EINVAL;
474
475 /* Adding 1 to convert retry count to try count */
476 adapter->txretrycount = vwrq->value + 1;
477
Holger Schurig10078322007-11-15 18:05:47 -0500478 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400479 CMD_ACT_SET,
480 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481 OID_802_11_TX_RETRYCOUNT, NULL);
482
Holger Schurig9012b282007-05-25 11:27:16 -0400483 if (ret)
484 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200485 } else {
486 return -EOPNOTSUPP;
487 }
488
Holger Schurig9012b282007-05-25 11:27:16 -0400489out:
490 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
491 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200492}
493
Holger Schurig10078322007-11-15 18:05:47 -0500494static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495 struct iw_param *vwrq, char *extra)
496{
Holger Schurig10078322007-11-15 18:05:47 -0500497 lbs_private *priv = dev->priv;
498 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499 int ret = 0;
500
Holger Schurig9012b282007-05-25 11:27:16 -0400501 lbs_deb_enter(LBS_DEB_WEXT);
502
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200503 adapter->txretrycount = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500504 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400505 CMD_802_11_SNMP_MIB,
506 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507 OID_802_11_TX_RETRYCOUNT, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400508 if (ret)
509 goto out;
510
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200511 vwrq->disabled = 0;
512 if (!vwrq->flags) {
513 vwrq->flags = IW_RETRY_LIMIT;
514 /* Subtract 1 to convert try count to retry count */
515 vwrq->value = adapter->txretrycount - 1;
516 }
517
Holger Schurig9012b282007-05-25 11:27:16 -0400518out:
519 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
520 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200521}
522
523static inline void sort_channels(struct iw_freq *freq, int num)
524{
525 int i, j;
526 struct iw_freq temp;
527
528 for (i = 0; i < num; i++)
529 for (j = i + 1; j < num; j++)
530 if (freq[i].i > freq[j].i) {
531 temp.i = freq[i].i;
532 temp.m = freq[i].m;
533
534 freq[i].i = freq[j].i;
535 freq[i].m = freq[j].m;
536
537 freq[j].i = temp.i;
538 freq[j].m = temp.m;
539 }
540}
541
542/* data rate listing
543 MULTI_BANDS:
544 abg a b b/g
545 Infra G(12) A(8) B(4) G(12)
546 Adhoc A+B(12) A(8) B(4) B(4)
547
548 non-MULTI_BANDS:
549 b b/g
550 Infra B(4) G(12)
551 Adhoc B(4) B(4)
552 */
553/**
554 * @brief Get Range Info
555 *
556 * @param dev A pointer to net_device structure
557 * @param info A pointer to iw_request_info structure
558 * @param vwrq A pointer to iw_param structure
559 * @param extra A pointer to extra data buf
560 * @return 0 --success, otherwise fail
561 */
Holger Schurig10078322007-11-15 18:05:47 -0500562static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200563 struct iw_point *dwrq, char *extra)
564{
565 int i, j;
Holger Schurig10078322007-11-15 18:05:47 -0500566 lbs_private *priv = dev->priv;
567 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568 struct iw_range *range = (struct iw_range *)extra;
569 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400570 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200571
572 u8 flag = 0;
573
Holger Schurig9012b282007-05-25 11:27:16 -0400574 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575
576 dwrq->length = sizeof(struct iw_range);
577 memset(range, 0, sizeof(struct iw_range));
578
579 range->min_nwid = 0;
580 range->max_nwid = 0;
581
582 memset(rates, 0, sizeof(rates));
Dan Williams8c512762007-08-02 11:40:45 -0400583 copy_active_data_rates(adapter, rates);
584 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
585 for (i = 0; i < range->num_bitrates; i++)
586 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200587 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400588 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200589 range->num_bitrates);
590
591 range->num_frequency = 0;
592 if (priv->adapter->enable11d &&
Brajesh Dave01d77d82007-11-20 17:44:14 -0500593 (adapter->connect_status == LBS_CONNECTED ||
594 adapter->mesh_connect_status == LBS_CONNECTED)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200595 u8 chan_no;
596 u8 band;
597
598 struct parsed_region_chan_11d *parsed_region_chan =
599 &adapter->parsed_region_chan;
600
601 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400602 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
603 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604 }
605 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400606 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200607 parsed_region_chan->nr_chan);
608
609 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
610 && (i < parsed_region_chan->nr_chan); i++) {
611 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400612 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200613 range->freq[range->num_frequency].i = (long)chan_no;
614 range->freq[range->num_frequency].m =
Holger Schurig10078322007-11-15 18:05:47 -0500615 (long)lbs_chan_2_freq(chan_no, band) * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616 range->freq[range->num_frequency].e = 1;
617 range->num_frequency++;
618 }
619 flag = 1;
620 }
621 if (!flag) {
622 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200623 && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200624 cfp = adapter->region_channel[j].CFP;
625 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
626 && adapter->region_channel[j].valid
627 && cfp
628 && (i < adapter->region_channel[j].nrcfp); i++) {
629 range->freq[range->num_frequency].i =
630 (long)cfp->channel;
631 range->freq[range->num_frequency].m =
632 (long)cfp->freq * 100000;
633 range->freq[range->num_frequency].e = 1;
634 cfp++;
635 range->num_frequency++;
636 }
637 }
638 }
639
Holger Schurig9012b282007-05-25 11:27:16 -0400640 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641 IW_MAX_FREQUENCIES, range->num_frequency);
642
643 range->num_channels = range->num_frequency;
644
645 sort_channels(&range->freq[0], range->num_frequency);
646
647 /*
648 * Set an indication of the max TCP throughput in bit/s that we can
649 * expect using this interface
650 */
651 if (i > 2)
652 range->throughput = 5000 * 1000;
653 else
654 range->throughput = 1500 * 1000;
655
656 range->min_rts = MRVDRV_RTS_MIN_VALUE;
657 range->max_rts = MRVDRV_RTS_MAX_VALUE;
658 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
659 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
660
661 range->encoding_size[0] = 5;
662 range->encoding_size[1] = 13;
663 range->num_encoding_sizes = 2;
664 range->max_encoding_tokens = 4;
665
666 range->min_pmp = 1000000;
667 range->max_pmp = 120000000;
668 range->min_pmt = 1000;
669 range->max_pmt = 1000000;
670 range->pmp_flags = IW_POWER_PERIOD;
671 range->pmt_flags = IW_POWER_TIMEOUT;
672 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
673
674 /*
675 * Minimum version we recommend
676 */
677 range->we_version_source = 15;
678
679 /*
680 * Version we are compiled with
681 */
682 range->we_version_compiled = WIRELESS_EXT;
683
684 range->retry_capa = IW_RETRY_LIMIT;
685 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
686
687 range->min_retry = TX_RETRY_MIN;
688 range->max_retry = TX_RETRY_MAX;
689
690 /*
691 * Set the qual, level and noise range values
692 */
693 range->max_qual.qual = 100;
694 range->max_qual.level = 0;
695 range->max_qual.noise = 0;
696 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
697
698 range->avg_qual.qual = 70;
699 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
700 range->avg_qual.level = 0;
701 range->avg_qual.noise = 0;
702 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
703
704 range->sensitivity = 0;
705
706 /*
707 * Setup the supported power level ranges
708 */
709 memset(range->txpower, 0, sizeof(range->txpower));
710 range->txpower[0] = 5;
711 range->txpower[1] = 7;
712 range->txpower[2] = 9;
713 range->txpower[3] = 11;
714 range->txpower[4] = 13;
715 range->txpower[5] = 15;
716 range->txpower[6] = 17;
717 range->txpower[7] = 19;
718
719 range->num_txpower = 8;
720 range->txpower_capa = IW_TXPOW_DBM;
721 range->txpower_capa |= IW_TXPOW_RANGE;
722
723 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
724 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
725 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
726 range->event_capa[1] = IW_EVENT_CAPA_K_1;
727
728 if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
729 range->enc_capa = IW_ENC_CAPA_WPA
730 | IW_ENC_CAPA_WPA2
731 | IW_ENC_CAPA_CIPHER_TKIP
732 | IW_ENC_CAPA_CIPHER_CCMP;
733 }
734
Holger Schurig9012b282007-05-25 11:27:16 -0400735out:
736 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200737 return 0;
738}
739
Holger Schurig10078322007-11-15 18:05:47 -0500740static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741 struct iw_param *vwrq, char *extra)
742{
Holger Schurig10078322007-11-15 18:05:47 -0500743 lbs_private *priv = dev->priv;
744 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745
Holger Schurig9012b282007-05-25 11:27:16 -0400746 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200747
748 /* PS is currently supported only in Infrastructure mode
749 * Remove this check if it is to be supported in IBSS mode also
750 */
751
752 if (vwrq->disabled) {
Holger Schurig10078322007-11-15 18:05:47 -0500753 adapter->psmode = LBS802_11POWERMODECAM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200754 if (adapter->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500755 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200756 }
757
758 return 0;
759 }
760
761 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400762 lbs_deb_wext(
763 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200764 return -EINVAL;
765 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400766 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200767 return -EINVAL;
768 }
769
Holger Schurig10078322007-11-15 18:05:47 -0500770 if (adapter->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200771 return 0;
772 }
773
Holger Schurig10078322007-11-15 18:05:47 -0500774 adapter->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200775
Holger Schurig10078322007-11-15 18:05:47 -0500776 if (adapter->connect_status == LBS_CONNECTED) {
777 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778 }
779
Holger Schurig9012b282007-05-25 11:27:16 -0400780 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200781 return 0;
782}
783
Holger Schurig10078322007-11-15 18:05:47 -0500784static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785 struct iw_param *vwrq, char *extra)
786{
Holger Schurig10078322007-11-15 18:05:47 -0500787 lbs_private *priv = dev->priv;
788 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200789 int mode;
790
Holger Schurig9012b282007-05-25 11:27:16 -0400791 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200792
793 mode = adapter->psmode;
794
Holger Schurig10078322007-11-15 18:05:47 -0500795 if ((vwrq->disabled = (mode == LBS802_11POWERMODECAM))
796 || adapter->connect_status == LBS_DISCONNECTED)
Holger Schurig9012b282007-05-25 11:27:16 -0400797 {
798 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200799 }
800
801 vwrq->value = 0;
802
Holger Schurig9012b282007-05-25 11:27:16 -0400803out:
804 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200805 return 0;
806}
807
Holger Schurig10078322007-11-15 18:05:47 -0500808static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200809{
810 enum {
811 POOR = 30,
812 FAIR = 60,
813 GOOD = 80,
814 VERY_GOOD = 90,
815 EXCELLENT = 95,
816 PERFECT = 100
817 };
Holger Schurig10078322007-11-15 18:05:47 -0500818 lbs_private *priv = dev->priv;
819 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820 u32 rssi_qual;
821 u32 tx_qual;
822 u32 quality = 0;
823 int stats_valid = 0;
824 u8 rssi;
825 u32 tx_retries;
826
Holger Schurig9012b282007-05-25 11:27:16 -0400827 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200828
Dan Williams0dc5a292007-05-10 22:58:02 -0400829 priv->wstats.status = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200830
831 /* If we're not associated, all quality values are meaningless */
Brajesh Dave01d77d82007-11-20 17:44:14 -0500832 if ((adapter->connect_status != LBS_CONNECTED) &&
833 (adapter->mesh_connect_status != LBS_CONNECTED))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200834 goto out;
835
836 /* Quality by RSSI */
837 priv->wstats.qual.level =
838 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
839 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
840
841 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
842 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
843 } else {
844 priv->wstats.qual.noise =
845 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
846 }
847
Holger Schurig9012b282007-05-25 11:27:16 -0400848 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
849 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200850
851 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
852 if (rssi < 15)
853 rssi_qual = rssi * POOR / 10;
854 else if (rssi < 20)
855 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
856 else if (rssi < 30)
857 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
858 else if (rssi < 40)
859 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
860 10 + GOOD;
861 else
862 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
863 10 + VERY_GOOD;
864 quality = rssi_qual;
865
866 /* Quality by TX errors */
867 priv->wstats.discard.retries = priv->stats.tx_errors;
868
Dan Williams8362cd42007-08-03 09:40:55 -0400869 tx_retries = le32_to_cpu(adapter->logmsg.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200870
871 if (tx_retries > 75)
872 tx_qual = (90 - tx_retries) * POOR / 15;
873 else if (tx_retries > 70)
874 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
875 else if (tx_retries > 65)
876 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
877 else if (tx_retries > 50)
878 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
879 15 + GOOD;
880 else
881 tx_qual = (50 - tx_retries) *
882 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
883 quality = min(quality, tx_qual);
884
Dan Williams8362cd42007-08-03 09:40:55 -0400885 priv->wstats.discard.code = le32_to_cpu(adapter->logmsg.wepundecryptable);
886 priv->wstats.discard.fragment = le32_to_cpu(adapter->logmsg.rxfrag);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200887 priv->wstats.discard.retries = tx_retries;
Dan Williams8362cd42007-08-03 09:40:55 -0400888 priv->wstats.discard.misc = le32_to_cpu(adapter->logmsg.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200889
890 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400891 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200892 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
893 stats_valid = 1;
894
895 /* update stats asynchronously for future calls */
Holger Schurig10078322007-11-15 18:05:47 -0500896 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200897 0, 0, NULL);
Holger Schurig10078322007-11-15 18:05:47 -0500898 lbs_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200899 0, 0, NULL);
900out:
901 if (!stats_valid) {
902 priv->wstats.miss.beacon = 0;
903 priv->wstats.discard.retries = 0;
904 priv->wstats.qual.qual = 0;
905 priv->wstats.qual.level = 0;
906 priv->wstats.qual.noise = 0;
907 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
908 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
909 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
910 }
911
Holger Schurig9012b282007-05-25 11:27:16 -0400912 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200913 return &priv->wstats;
914
915
916}
917
Holger Schurig10078322007-11-15 18:05:47 -0500918static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200919 struct iw_freq *fwrq, char *extra)
920{
Dan Williamsef9a2642007-05-25 16:46:33 -0400921 int ret = -EINVAL;
Holger Schurig10078322007-11-15 18:05:47 -0500922 lbs_private *priv = dev->priv;
923 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200924 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400925 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200926
Holger Schurig9012b282007-05-25 11:27:16 -0400927 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200928
Dan Williamsef9a2642007-05-25 16:46:33 -0400929 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -0500930 assoc_req = lbs_get_association_request(adapter);
Dan Williamsef9a2642007-05-25 16:46:33 -0400931 if (!assoc_req) {
932 ret = -ENOMEM;
933 goto out;
934 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200935
Dan Williamsef9a2642007-05-25 16:46:33 -0400936 /* If setting by frequency, convert to a channel */
937 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200938 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200939
940 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
941 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400942 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400943 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200944 }
945
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200946 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400947 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200948 }
949
Dan Williamsef9a2642007-05-25 16:46:33 -0400950 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200951 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400952 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200953 }
954
Holger Schurig10078322007-11-15 18:05:47 -0500955 cfp = lbs_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400956 if (!cfp) {
957 goto out;
958 }
959
960 assoc_req->channel = fwrq->m;
961 ret = 0;
962
Holger Schurig9012b282007-05-25 11:27:16 -0400963out:
Dan Williamsef9a2642007-05-25 16:46:33 -0400964 if (ret == 0) {
965 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500966 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400967 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500968 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400969 }
970 mutex_unlock(&adapter->lock);
971
972 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
973 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200974}
975
Holger Schurig10078322007-11-15 18:05:47 -0500976static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200977 struct iw_param *vwrq, char *extra)
978{
Holger Schurig10078322007-11-15 18:05:47 -0500979 lbs_private *priv = dev->priv;
980 lbs_adapter *adapter = priv->adapter;
Dan Williams8c512762007-08-02 11:40:45 -0400981 u32 new_rate;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200982 u16 action;
Dan Williams8c512762007-08-02 11:40:45 -0400983 int ret = -EINVAL;
984 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200985
Holger Schurig9012b282007-05-25 11:27:16 -0400986 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -0400987 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200988
Dan Williams8c512762007-08-02 11:40:45 -0400989 /* Auto rate? */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200990 if (vwrq->value == -1) {
Dan Williams8c512762007-08-02 11:40:45 -0400991 action = CMD_ACT_SET_TX_AUTO;
992 adapter->auto_rate = 1;
993 adapter->cur_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200994 } else {
Dan Williams8c512762007-08-02 11:40:45 -0400995 if (vwrq->value % 100000)
996 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200997
998 memset(rates, 0, sizeof(rates));
Dan Williams8c512762007-08-02 11:40:45 -0400999 copy_active_data_rates(adapter, rates);
1000 new_rate = vwrq->value / 500000;
1001 if (!memchr(rates, new_rate, sizeof(rates))) {
1002 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1003 new_rate);
1004 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001005 }
1006
Dan Williams8c512762007-08-02 11:40:45 -04001007 adapter->cur_rate = new_rate;
Dan Williamsffcae952007-08-02 11:35:46 -04001008 action = CMD_ACT_SET_TX_FIX_RATE;
Dan Williams8c512762007-08-02 11:40:45 -04001009 adapter->auto_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001010 }
1011
Holger Schurig10078322007-11-15 18:05:47 -05001012 ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001013 action, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001014
Dan Williams8c512762007-08-02 11:40:45 -04001015out:
Holger Schurig9012b282007-05-25 11:27:16 -04001016 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001017 return ret;
1018}
1019
Holger Schurig10078322007-11-15 18:05:47 -05001020static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001021 struct iw_param *vwrq, char *extra)
1022{
Holger Schurig10078322007-11-15 18:05:47 -05001023 lbs_private *priv = dev->priv;
1024 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001025
Holger Schurig9012b282007-05-25 11:27:16 -04001026 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001027
Holger Schurig10078322007-11-15 18:05:47 -05001028 if (adapter->connect_status == LBS_CONNECTED) {
Dan Williams8c512762007-08-02 11:40:45 -04001029 vwrq->value = adapter->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001030
Dan Williams8c512762007-08-02 11:40:45 -04001031 if (adapter->auto_rate)
1032 vwrq->fixed = 0;
1033 else
1034 vwrq->fixed = 1;
1035
1036 } else {
1037 vwrq->fixed = 0;
1038 vwrq->value = 0;
1039 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001040
Holger Schurig9012b282007-05-25 11:27:16 -04001041 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001042 return 0;
1043}
1044
Holger Schurig10078322007-11-15 18:05:47 -05001045static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001046 struct iw_request_info *info, u32 * uwrq, char *extra)
1047{
1048 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -05001049 lbs_private *priv = dev->priv;
1050 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001051 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001052
Holger Schurig9012b282007-05-25 11:27:16 -04001053 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001054
Dan Williams0dc5a292007-05-10 22:58:02 -04001055 if ( (*uwrq != IW_MODE_ADHOC)
1056 && (*uwrq != IW_MODE_INFRA)
1057 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001058 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001059 ret = -EINVAL;
1060 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001061 }
1062
1063 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -05001064 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001065 if (!assoc_req) {
1066 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001067 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001068 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001069 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001070 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001071 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001072 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001073 }
1074 mutex_unlock(&adapter->lock);
1075
Dan Williams0dc5a292007-05-10 22:58:02 -04001076out:
Holger Schurig9012b282007-05-25 11:27:16 -04001077 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001078 return ret;
1079}
1080
1081
1082/**
1083 * @brief Get Encryption key
1084 *
1085 * @param dev A pointer to net_device structure
1086 * @param info A pointer to iw_request_info structure
1087 * @param vwrq A pointer to iw_param structure
1088 * @param extra A pointer to extra data buf
1089 * @return 0 --success, otherwise fail
1090 */
Holger Schurig10078322007-11-15 18:05:47 -05001091static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001092 struct iw_request_info *info,
1093 struct iw_point *dwrq, u8 * extra)
1094{
Holger Schurig10078322007-11-15 18:05:47 -05001095 lbs_private *priv = dev->priv;
1096 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001097 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1098
Holger Schurig9012b282007-05-25 11:27:16 -04001099 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001100
Holger Schurig9012b282007-05-25 11:27:16 -04001101 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001102 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1103
1104 dwrq->flags = 0;
1105
1106 /* Authentication method */
Dan Williams6affe782007-05-10 22:56:42 -04001107 switch (adapter->secinfo.auth_mode) {
1108 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001109 dwrq->flags = IW_ENCODE_OPEN;
1110 break;
1111
Dan Williams6affe782007-05-10 22:56:42 -04001112 case IW_AUTH_ALG_SHARED_KEY:
1113 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001114 dwrq->flags = IW_ENCODE_RESTRICTED;
1115 break;
1116 default:
1117 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1118 break;
1119 }
1120
Dan Williams889c05b2007-05-10 22:57:23 -04001121 if ( adapter->secinfo.wep_enabled
1122 || adapter->secinfo.WPAenabled
1123 || adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001124 dwrq->flags &= ~IW_ENCODE_DISABLED;
1125 } else {
1126 dwrq->flags |= IW_ENCODE_DISABLED;
1127 }
1128
1129 memset(extra, 0, 16);
1130
1131 mutex_lock(&adapter->lock);
1132
1133 /* Default to returning current transmit key */
1134 if (index < 0)
1135 index = adapter->wep_tx_keyidx;
1136
Dan Williams889c05b2007-05-10 22:57:23 -04001137 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001138 memcpy(extra, adapter->wep_keys[index].key,
1139 adapter->wep_keys[index].len);
1140 dwrq->length = adapter->wep_keys[index].len;
1141
1142 dwrq->flags |= (index + 1);
1143 /* Return WEP enabled */
1144 dwrq->flags &= ~IW_ENCODE_DISABLED;
1145 } else if ((adapter->secinfo.WPAenabled)
1146 || (adapter->secinfo.WPA2enabled)) {
1147 /* return WPA enabled */
1148 dwrq->flags &= ~IW_ENCODE_DISABLED;
1149 } else {
1150 dwrq->flags |= IW_ENCODE_DISABLED;
1151 }
1152
1153 mutex_unlock(&adapter->lock);
1154
1155 dwrq->flags |= IW_ENCODE_NOKEY;
1156
Joe Perches0795af52007-10-03 17:59:30 -07001157 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001158 extra[0], extra[1], extra[2],
1159 extra[3], extra[4], extra[5], dwrq->length);
1160
Holger Schurig9012b282007-05-25 11:27:16 -04001161 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001162
Holger Schurig9012b282007-05-25 11:27:16 -04001163 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001164 return 0;
1165}
1166
1167/**
1168 * @brief Set Encryption key (internal)
1169 *
1170 * @param priv A pointer to private card structure
1171 * @param key_material A pointer to key material
1172 * @param key_length length of key material
1173 * @param index key index to set
1174 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1175 * @return 0 --success, otherwise fail
1176 */
Holger Schurig10078322007-11-15 18:05:47 -05001177static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001178 const char *key_material,
1179 u16 key_length,
1180 u16 index,
1181 int set_tx_key)
1182{
Holger Schurig9012b282007-05-25 11:27:16 -04001183 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001184 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001185
Holger Schurig9012b282007-05-25 11:27:16 -04001186 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001187
1188 /* Paranoid validation of key index */
1189 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001190 ret = -EINVAL;
1191 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001192 }
1193
1194 /* validate max key length */
1195 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001196 ret = -EINVAL;
1197 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001198 }
1199
1200 pkey = &assoc_req->wep_keys[index];
1201
1202 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001203 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001204 pkey->type = KEY_TYPE_ID_WEP;
1205
1206 /* Standardize the key length */
1207 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1208 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1209 memcpy(pkey->key, key_material, key_length);
1210 }
1211
1212 if (set_tx_key) {
1213 /* Ensure the chosen key is valid */
1214 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001215 lbs_deb_wext("key not set, so cannot enable it\n");
1216 ret = -EINVAL;
1217 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001218 }
1219 assoc_req->wep_tx_keyidx = index;
1220 }
1221
Dan Williams889c05b2007-05-10 22:57:23 -04001222 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001223
Holger Schurig9012b282007-05-25 11:27:16 -04001224out:
1225 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1226 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001227}
1228
1229static int validate_key_index(u16 def_index, u16 raw_index,
1230 u16 *out_index, u16 *is_default)
1231{
1232 if (!out_index || !is_default)
1233 return -EINVAL;
1234
1235 /* Verify index if present, otherwise use default TX key index */
1236 if (raw_index > 0) {
1237 if (raw_index > 4)
1238 return -EINVAL;
1239 *out_index = raw_index - 1;
1240 } else {
1241 *out_index = def_index;
1242 *is_default = 1;
1243 }
1244 return 0;
1245}
1246
1247static void disable_wep(struct assoc_request *assoc_req)
1248{
1249 int i;
1250
Dan Williams90a42212007-05-25 23:01:24 -04001251 lbs_deb_enter(LBS_DEB_WEXT);
1252
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001253 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001254 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001255
1256 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001257 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001258 for (i = 0; i < 4; i++)
1259 assoc_req->wep_keys[i].len = 0;
1260
1261 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1262 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001263
1264 lbs_deb_leave(LBS_DEB_WEXT);
1265}
1266
1267static void disable_wpa(struct assoc_request *assoc_req)
1268{
1269 lbs_deb_enter(LBS_DEB_WEXT);
1270
Dan Williams1443b652007-08-02 10:45:55 -04001271 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001272 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1273 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1274
Dan Williams1443b652007-08-02 10:45:55 -04001275 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001276 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1277 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1278
1279 assoc_req->secinfo.WPAenabled = 0;
1280 assoc_req->secinfo.WPA2enabled = 0;
1281 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1282
1283 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001284}
1285
1286/**
1287 * @brief Set Encryption key
1288 *
1289 * @param dev A pointer to net_device structure
1290 * @param info A pointer to iw_request_info structure
1291 * @param vwrq A pointer to iw_param structure
1292 * @param extra A pointer to extra data buf
1293 * @return 0 --success, otherwise fail
1294 */
Holger Schurig10078322007-11-15 18:05:47 -05001295static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001296 struct iw_request_info *info,
1297 struct iw_point *dwrq, char *extra)
1298{
1299 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -05001300 lbs_private *priv = dev->priv;
1301 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001302 struct assoc_request * assoc_req;
1303 u16 is_default = 0, index = 0, set_tx_key = 0;
1304
Holger Schurig9012b282007-05-25 11:27:16 -04001305 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001306
1307 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -05001308 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001309 if (!assoc_req) {
1310 ret = -ENOMEM;
1311 goto out;
1312 }
1313
1314 if (dwrq->flags & IW_ENCODE_DISABLED) {
1315 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001316 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001317 goto out;
1318 }
1319
1320 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1321 (dwrq->flags & IW_ENCODE_INDEX),
1322 &index, &is_default);
1323 if (ret) {
1324 ret = -EINVAL;
1325 goto out;
1326 }
1327
1328 /* If WEP isn't enabled, or if there is no key data but a valid
1329 * index, set the TX key.
1330 */
Dan Williams889c05b2007-05-10 22:57:23 -04001331 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001332 set_tx_key = 1;
1333
Holger Schurig10078322007-11-15 18:05:47 -05001334 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001335 if (ret)
1336 goto out;
1337
1338 if (dwrq->length)
1339 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1340 if (set_tx_key)
1341 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1342
1343 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001344 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001345 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001346 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001347 }
1348
1349out:
1350 if (ret == 0) {
1351 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001352 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001353 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001354 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001355 }
1356 mutex_unlock(&adapter->lock);
1357
Holger Schurig9012b282007-05-25 11:27:16 -04001358 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001359 return ret;
1360}
1361
1362/**
1363 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1364 *
1365 * @param dev A pointer to net_device structure
1366 * @param info A pointer to iw_request_info structure
1367 * @param vwrq A pointer to iw_param structure
1368 * @param extra A pointer to extra data buf
1369 * @return 0 on success, otherwise failure
1370 */
Holger Schurig10078322007-11-15 18:05:47 -05001371static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001372 struct iw_request_info *info,
1373 struct iw_point *dwrq,
1374 char *extra)
1375{
1376 int ret = -EINVAL;
Holger Schurig10078322007-11-15 18:05:47 -05001377 lbs_private *priv = dev->priv;
1378 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001379 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1380 int index, max_key_len;
1381
Holger Schurig9012b282007-05-25 11:27:16 -04001382 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001383
1384 max_key_len = dwrq->length - sizeof(*ext);
1385 if (max_key_len < 0)
1386 goto out;
1387
1388 index = dwrq->flags & IW_ENCODE_INDEX;
1389 if (index) {
1390 if (index < 1 || index > 4)
1391 goto out;
1392 index--;
1393 } else {
1394 index = adapter->wep_tx_keyidx;
1395 }
1396
Roel Kluinf59d9782007-10-26 21:51:26 +02001397 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001398 ext->alg != IW_ENCODE_ALG_WEP) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001399 if (index != 0 || adapter->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001400 goto out;
1401 }
1402
1403 dwrq->flags = index + 1;
1404 memset(ext, 0, sizeof(*ext));
1405
Dan Williams889c05b2007-05-10 22:57:23 -04001406 if ( !adapter->secinfo.wep_enabled
1407 && !adapter->secinfo.WPAenabled
1408 && !adapter->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001409 ext->alg = IW_ENCODE_ALG_NONE;
1410 ext->key_len = 0;
1411 dwrq->flags |= IW_ENCODE_DISABLED;
1412 } else {
1413 u8 *key = NULL;
1414
Dan Williams889c05b2007-05-10 22:57:23 -04001415 if ( adapter->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001416 && !adapter->secinfo.WPAenabled
1417 && !adapter->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001418 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001419 ext->alg = IW_ENCODE_ALG_WEP;
1420 ext->key_len = adapter->wep_keys[index].len;
1421 key = &adapter->wep_keys[index].key[0];
Dan Williams889c05b2007-05-10 22:57:23 -04001422 } else if ( !adapter->secinfo.wep_enabled
1423 && (adapter->secinfo.WPAenabled ||
1424 adapter->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001425 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001426 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001427
1428 if ( adapter->wpa_mcast_key.len
1429 && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1430 pkey = &adapter->wpa_mcast_key;
1431 else if ( adapter->wpa_unicast_key.len
1432 && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1433 pkey = &adapter->wpa_unicast_key;
1434
1435 if (pkey) {
1436 if (pkey->type == KEY_TYPE_ID_AES) {
1437 ext->alg = IW_ENCODE_ALG_CCMP;
1438 } else {
1439 ext->alg = IW_ENCODE_ALG_TKIP;
1440 }
1441 ext->key_len = pkey->len;
1442 key = &pkey->key[0];
1443 } else {
1444 ext->alg = IW_ENCODE_ALG_TKIP;
1445 ext->key_len = 0;
1446 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001447 } else {
1448 goto out;
1449 }
1450
1451 if (ext->key_len > max_key_len) {
1452 ret = -E2BIG;
1453 goto out;
1454 }
1455
1456 if (ext->key_len)
1457 memcpy(ext->key, key, ext->key_len);
1458 else
1459 dwrq->flags |= IW_ENCODE_NOKEY;
1460 dwrq->flags |= IW_ENCODE_ENABLED;
1461 }
1462 ret = 0;
1463
1464out:
Holger Schurig9012b282007-05-25 11:27:16 -04001465 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001466 return ret;
1467}
1468
1469/**
1470 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1471 *
1472 * @param dev A pointer to net_device structure
1473 * @param info A pointer to iw_request_info structure
1474 * @param vwrq A pointer to iw_param structure
1475 * @param extra A pointer to extra data buf
1476 * @return 0 --success, otherwise fail
1477 */
Holger Schurig10078322007-11-15 18:05:47 -05001478static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001479 struct iw_request_info *info,
1480 struct iw_point *dwrq,
1481 char *extra)
1482{
1483 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -05001484 lbs_private *priv = dev->priv;
1485 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001486 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1487 int alg = ext->alg;
1488 struct assoc_request * assoc_req;
1489
Holger Schurig9012b282007-05-25 11:27:16 -04001490 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001491
1492 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -05001493 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001494 if (!assoc_req) {
1495 ret = -ENOMEM;
1496 goto out;
1497 }
1498
1499 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1500 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001501 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001502 } else if (alg == IW_ENCODE_ALG_WEP) {
1503 u16 is_default = 0, index, set_tx_key = 0;
1504
1505 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1506 (dwrq->flags & IW_ENCODE_INDEX),
1507 &index, &is_default);
1508 if (ret)
1509 goto out;
1510
1511 /* If WEP isn't enabled, or if there is no key data but a valid
1512 * index, or if the set-TX-key flag was passed, set the TX key.
1513 */
Dan Williams889c05b2007-05-10 22:57:23 -04001514 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001515 || (dwrq->length == 0 && !is_default)
1516 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1517 set_tx_key = 1;
1518
1519 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001520 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001521 set_tx_key);
1522 if (ret)
1523 goto out;
1524
1525 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001526 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001527 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001528 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001529 }
1530
1531 /* Mark the various WEP bits as modified */
1532 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1533 if (dwrq->length)
1534 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1535 if (set_tx_key)
1536 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001537 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001538 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001539
1540 /* validate key length */
1541 if (((alg == IW_ENCODE_ALG_TKIP)
1542 && (ext->key_len != KEY_LEN_WPA_TKIP))
1543 || ((alg == IW_ENCODE_ALG_CCMP)
1544 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001545 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001546 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001547 ext->key_len,
1548 alg);
1549 ret = -EINVAL;
1550 goto out;
1551 }
1552
Dan Williams90a42212007-05-25 23:01:24 -04001553 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001554 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001555 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1556 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001557 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001558 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1559 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560
Dan Williams1443b652007-08-02 10:45:55 -04001561 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001562 memcpy(pkey->key, ext->key, ext->key_len);
1563 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001564 if (pkey->len)
1565 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001566
Dan Williams90a42212007-05-25 23:01:24 -04001567 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001568 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1569 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001570 } else {
1571 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001572 }
1573
Dan Williams90a42212007-05-25 23:01:24 -04001574 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001575 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001576 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001577 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001578 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001579
1580 /* If WPA isn't enabled yet, do that now */
1581 if ( assoc_req->secinfo.WPAenabled == 0
1582 && assoc_req->secinfo.WPA2enabled == 0) {
1583 assoc_req->secinfo.WPAenabled = 1;
1584 assoc_req->secinfo.WPA2enabled = 1;
1585 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1586 }
1587
1588 disable_wep (assoc_req);
1589 }
1590
1591out:
1592 if (ret == 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001593 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001594 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001595 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001596 }
1597 mutex_unlock(&adapter->lock);
1598
Holger Schurig9012b282007-05-25 11:27:16 -04001599 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001600 return ret;
1601}
1602
1603
Holger Schurig10078322007-11-15 18:05:47 -05001604static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001605 struct iw_request_info *info,
1606 struct iw_point *dwrq,
1607 char *extra)
1608{
Holger Schurig10078322007-11-15 18:05:47 -05001609 lbs_private *priv = dev->priv;
1610 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001611 int ret = 0;
1612 struct assoc_request * assoc_req;
1613
Holger Schurig9012b282007-05-25 11:27:16 -04001614 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001615
1616 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -05001617 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001618 if (!assoc_req) {
1619 ret = -ENOMEM;
1620 goto out;
1621 }
1622
1623 if (dwrq->length > MAX_WPA_IE_LEN ||
1624 (dwrq->length && extra == NULL)) {
1625 ret = -EINVAL;
1626 goto out;
1627 }
1628
1629 if (dwrq->length) {
1630 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1631 assoc_req->wpa_ie_len = dwrq->length;
1632 } else {
1633 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
1634 assoc_req->wpa_ie_len = 0;
1635 }
1636
1637out:
1638 if (ret == 0) {
1639 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001640 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001641 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001642 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001643 }
1644 mutex_unlock(&adapter->lock);
1645
Holger Schurig9012b282007-05-25 11:27:16 -04001646 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001647 return ret;
1648}
1649
Holger Schurig10078322007-11-15 18:05:47 -05001650static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001651 struct iw_request_info *info,
1652 struct iw_point *dwrq,
1653 char *extra)
1654{
Holger Schurig9012b282007-05-25 11:27:16 -04001655 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -05001656 lbs_private *priv = dev->priv;
1657 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001658
Holger Schurig9012b282007-05-25 11:27:16 -04001659 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001660
1661 if (adapter->wpa_ie_len == 0) {
1662 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001663 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001664 }
1665
1666 if (dwrq->length < adapter->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001667 ret = -E2BIG;
1668 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001669 }
1670
1671 dwrq->length = adapter->wpa_ie_len;
1672 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
1673
Holger Schurig9012b282007-05-25 11:27:16 -04001674out:
1675 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1676 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001677}
1678
1679
Holger Schurig10078322007-11-15 18:05:47 -05001680static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001681 struct iw_request_info *info,
1682 struct iw_param *dwrq,
1683 char *extra)
1684{
Holger Schurig10078322007-11-15 18:05:47 -05001685 lbs_private *priv = dev->priv;
1686 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001687 struct assoc_request * assoc_req;
1688 int ret = 0;
1689 int updated = 0;
1690
Holger Schurig9012b282007-05-25 11:27:16 -04001691 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001692
1693 mutex_lock(&adapter->lock);
Holger Schurig10078322007-11-15 18:05:47 -05001694 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001695 if (!assoc_req) {
1696 ret = -ENOMEM;
1697 goto out;
1698 }
1699
1700 switch (dwrq->flags & IW_AUTH_INDEX) {
1701 case IW_AUTH_TKIP_COUNTERMEASURES:
1702 case IW_AUTH_CIPHER_PAIRWISE:
1703 case IW_AUTH_CIPHER_GROUP:
1704 case IW_AUTH_KEY_MGMT:
Dan Williams90a42212007-05-25 23:01:24 -04001705 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001706 /*
1707 * libertas does not use these parameters
1708 */
1709 break;
1710
1711 case IW_AUTH_WPA_VERSION:
1712 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1713 assoc_req->secinfo.WPAenabled = 0;
1714 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001715 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001716 }
1717 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1718 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001719 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001720 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001721 }
1722 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1723 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001724 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001725 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001726 }
1727 updated = 1;
1728 break;
1729
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001730 case IW_AUTH_80211_AUTH_ALG:
1731 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001732 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001733 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001734 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001735 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001736 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001737 } else {
1738 ret = -EINVAL;
1739 }
1740 updated = 1;
1741 break;
1742
1743 case IW_AUTH_WPA_ENABLED:
1744 if (dwrq->value) {
1745 if (!assoc_req->secinfo.WPAenabled &&
1746 !assoc_req->secinfo.WPA2enabled) {
1747 assoc_req->secinfo.WPAenabled = 1;
1748 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001749 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001750 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001751 }
1752 } else {
1753 assoc_req->secinfo.WPAenabled = 0;
1754 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001755 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001756 }
1757 updated = 1;
1758 break;
1759
1760 default:
1761 ret = -EOPNOTSUPP;
1762 break;
1763 }
1764
1765out:
1766 if (ret == 0) {
1767 if (updated)
1768 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001769 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001770 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001771 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001772 }
1773 mutex_unlock(&adapter->lock);
1774
Holger Schurig9012b282007-05-25 11:27:16 -04001775 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001776 return ret;
1777}
1778
Holger Schurig10078322007-11-15 18:05:47 -05001779static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001780 struct iw_request_info *info,
1781 struct iw_param *dwrq,
1782 char *extra)
1783{
Holger Schurig9012b282007-05-25 11:27:16 -04001784 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -05001785 lbs_private *priv = dev->priv;
1786 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001787
Holger Schurig9012b282007-05-25 11:27:16 -04001788 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001789
1790 switch (dwrq->flags & IW_AUTH_INDEX) {
1791 case IW_AUTH_WPA_VERSION:
1792 dwrq->value = 0;
1793 if (adapter->secinfo.WPAenabled)
1794 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1795 if (adapter->secinfo.WPA2enabled)
1796 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1797 if (!dwrq->value)
1798 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1799 break;
1800
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001801 case IW_AUTH_80211_AUTH_ALG:
Dan Williams6affe782007-05-10 22:56:42 -04001802 dwrq->value = adapter->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001803 break;
1804
1805 case IW_AUTH_WPA_ENABLED:
1806 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
1807 dwrq->value = 1;
1808 break;
1809
1810 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001811 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001812 }
1813
Holger Schurig9012b282007-05-25 11:27:16 -04001814 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1815 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816}
1817
1818
Holger Schurig10078322007-11-15 18:05:47 -05001819static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001820 struct iw_param *vwrq, char *extra)
1821{
1822 int ret = 0;
Holger Schurig10078322007-11-15 18:05:47 -05001823 lbs_private *priv = dev->priv;
1824 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001825
1826 u16 dbm;
1827
Holger Schurig9012b282007-05-25 11:27:16 -04001828 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001829
1830 if (vwrq->disabled) {
Holger Schurig10078322007-11-15 18:05:47 -05001831 lbs_radio_ioctl(priv, RADIO_OFF);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001832 return 0;
1833 }
1834
Dan Williams0aef64d2007-08-02 11:31:18 -04001835 adapter->preamble = CMD_TYPE_AUTO_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001836
Holger Schurig10078322007-11-15 18:05:47 -05001837 lbs_radio_ioctl(priv, RADIO_ON);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001838
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001839 /* Userspace check in iwrange if it should use dBm or mW,
1840 * therefore this should never happen... Jean II */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001841 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001842 return -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001843 } else
1844 dbm = (u16) vwrq->value;
1845
1846 /* auto tx power control */
1847
1848 if (vwrq->fixed == 0)
1849 dbm = 0xffff;
1850
Holger Schurig9012b282007-05-25 11:27:16 -04001851 lbs_deb_wext("txpower set %d dbm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001852
Holger Schurig10078322007-11-15 18:05:47 -05001853 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -04001854 CMD_802_11_RF_TX_POWER,
1855 CMD_ACT_TX_POWER_OPT_SET_LOW,
1856 CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001857
Holger Schurig9012b282007-05-25 11:27:16 -04001858 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001859 return ret;
1860}
1861
Holger Schurig10078322007-11-15 18:05:47 -05001862static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001863 struct iw_point *dwrq, char *extra)
1864{
Holger Schurig10078322007-11-15 18:05:47 -05001865 lbs_private *priv = dev->priv;
1866 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001867
Holger Schurig9012b282007-05-25 11:27:16 -04001868 lbs_deb_enter(LBS_DEB_WEXT);
1869
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001870 /*
1871 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1872 * the SSID list...
1873 */
1874
1875 /*
1876 * Get the current SSID
1877 */
Holger Schurig10078322007-11-15 18:05:47 -05001878 if (adapter->connect_status == LBS_CONNECTED) {
Dan Williamsd8efea22007-05-28 23:54:55 -04001879 memcpy(extra, adapter->curbssparams.ssid,
1880 adapter->curbssparams.ssid_len);
1881 extra[adapter->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001882 } else {
1883 memset(extra, 0, 32);
Dan Williamsd8efea22007-05-28 23:54:55 -04001884 extra[adapter->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001885 }
1886 /*
1887 * If none, we may want to get the one that was set
1888 */
1889
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001890 dwrq->length = adapter->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001891
1892 dwrq->flags = 1; /* active */
1893
Holger Schurig9012b282007-05-25 11:27:16 -04001894 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001895 return 0;
1896}
1897
Holger Schurig10078322007-11-15 18:05:47 -05001898static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001899 struct iw_point *dwrq, char *extra)
1900{
Holger Schurig10078322007-11-15 18:05:47 -05001901 lbs_private *priv = dev->priv;
1902 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001903 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04001904 u8 ssid[IW_ESSID_MAX_SIZE];
1905 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001906 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001907 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001908
Holger Schurig9012b282007-05-25 11:27:16 -04001909 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001910
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001911 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001912 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001913 ret = -E2BIG;
1914 goto out;
1915 }
1916
Dan Williamsd8efea22007-05-28 23:54:55 -04001917 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001918
Dan Williamsd8efea22007-05-28 23:54:55 -04001919 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001920 /* "any" SSID requested; leave SSID blank */
1921 } else {
1922 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04001923 memcpy(&ssid, extra, in_ssid_len);
1924 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001925 }
1926
Dan Williamsd8efea22007-05-28 23:54:55 -04001927 if (!ssid_len) {
1928 lbs_deb_wext("requested any SSID\n");
1929 } else {
1930 lbs_deb_wext("requested SSID '%s'\n",
1931 escape_essid(ssid, ssid_len));
1932 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001933
1934out:
1935 mutex_lock(&adapter->lock);
1936 if (ret == 0) {
1937 /* Get or create the current association request */
Holger Schurig10078322007-11-15 18:05:47 -05001938 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001939 if (!assoc_req) {
1940 ret = -ENOMEM;
1941 } else {
1942 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04001943 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1944 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001945 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001946 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001947 }
1948 }
1949
1950 /* Cancel the association request if there was an error */
1951 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001952 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001953 }
1954
1955 mutex_unlock(&adapter->lock);
1956
Holger Schurig9012b282007-05-25 11:27:16 -04001957 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001958 return ret;
1959}
1960
1961/**
1962 * @brief Connect to the AP or Ad-hoc Network with specific bssid
1963 *
1964 * @param dev A pointer to net_device structure
1965 * @param info A pointer to iw_request_info structure
1966 * @param awrq A pointer to iw_param structure
1967 * @param extra A pointer to extra data buf
1968 * @return 0 --success, otherwise fail
1969 */
Holger Schurig10078322007-11-15 18:05:47 -05001970static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001971 struct sockaddr *awrq, char *extra)
1972{
Holger Schurig10078322007-11-15 18:05:47 -05001973 lbs_private *priv = dev->priv;
1974 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001975 struct assoc_request * assoc_req;
1976 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07001977 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001978
Holger Schurig9012b282007-05-25 11:27:16 -04001979 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001980
1981 if (awrq->sa_family != ARPHRD_ETHER)
1982 return -EINVAL;
1983
Joe Perches0795af52007-10-03 17:59:30 -07001984 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001985
1986 mutex_lock(&adapter->lock);
1987
1988 /* Get or create the current association request */
Holger Schurig10078322007-11-15 18:05:47 -05001989 assoc_req = lbs_get_association_request(adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001990 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05001991 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001992 ret = -ENOMEM;
1993 } else {
1994 /* Copy the BSSID to the association request */
1995 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
1996 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001997 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001998 }
1999
2000 mutex_unlock(&adapter->lock);
2001
2002 return ret;
2003}
2004
Holger Schurig10078322007-11-15 18:05:47 -05002005void lbs_get_fwversion(lbs_adapter *adapter, char *fwversion, int maxlen)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002006{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002007 char fwver[32];
2008
2009 mutex_lock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002010
David Woodhousee5b3d472007-05-25 23:40:21 -04002011 if (adapter->fwreleasenumber[3] == 0)
2012 sprintf(fwver, "%u.%u.%u",
2013 adapter->fwreleasenumber[2],
2014 adapter->fwreleasenumber[1],
2015 adapter->fwreleasenumber[0]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002016 else
2017 sprintf(fwver, "%u.%u.%u.p%u",
David Woodhousee5b3d472007-05-25 23:40:21 -04002018 adapter->fwreleasenumber[2],
2019 adapter->fwreleasenumber[1],
2020 adapter->fwreleasenumber[0],
2021 adapter->fwreleasenumber[3]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002022
David Woodhousee5b3d472007-05-25 23:40:21 -04002023 mutex_unlock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002024 snprintf(fwversion, maxlen, fwver);
2025}
2026
2027
2028/*
2029 * iwconfig settable callbacks
2030 */
Holger Schurig10078322007-11-15 18:05:47 -05002031static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002032 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002033 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002034 (iw_handler) NULL, /* SIOCSIWNWID */
2035 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002036 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2037 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2038 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2039 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002040 (iw_handler) NULL, /* SIOCSIWSENS */
2041 (iw_handler) NULL, /* SIOCGIWSENS */
2042 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002043 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002044 (iw_handler) NULL, /* SIOCSIWPRIV */
2045 (iw_handler) NULL, /* SIOCGIWPRIV */
2046 (iw_handler) NULL, /* SIOCSIWSTATS */
2047 (iw_handler) NULL, /* SIOCGIWSTATS */
2048 iw_handler_set_spy, /* SIOCSIWSPY */
2049 iw_handler_get_spy, /* SIOCGIWSPY */
2050 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2051 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002052 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2053 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002054 (iw_handler) NULL, /* SIOCSIWMLME */
2055 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002056 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2057 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2058 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2059 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2060 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2061 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002062 (iw_handler) NULL, /* -- hole -- */
2063 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002064 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2065 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2066 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2067 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2068 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2069 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2070 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2071 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2072 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2073 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2074 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2075 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2076 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2077 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002078 (iw_handler) NULL, /* -- hole -- */
2079 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002080 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2081 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2082 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2083 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2084 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2085 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002086 (iw_handler) NULL, /* SIOCSIWPMKSA */
2087};
2088
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002089static const iw_handler mesh_wlan_handler[] = {
2090 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002091 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002092 (iw_handler) NULL, /* SIOCSIWNWID */
2093 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002094 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2095 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002096 (iw_handler) NULL, /* SIOCSIWMODE */
2097 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2098 (iw_handler) NULL, /* SIOCSIWSENS */
2099 (iw_handler) NULL, /* SIOCGIWSENS */
2100 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002101 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002102 (iw_handler) NULL, /* SIOCSIWPRIV */
2103 (iw_handler) NULL, /* SIOCGIWPRIV */
2104 (iw_handler) NULL, /* SIOCSIWSTATS */
2105 (iw_handler) NULL, /* SIOCGIWSTATS */
2106 iw_handler_set_spy, /* SIOCSIWSPY */
2107 iw_handler_get_spy, /* SIOCGIWSPY */
2108 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2109 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2110 (iw_handler) NULL, /* SIOCSIWAP */
2111 (iw_handler) NULL, /* SIOCGIWAP */
2112 (iw_handler) NULL, /* SIOCSIWMLME */
2113 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002114 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2115 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002116 (iw_handler) NULL, /* SIOCSIWESSID */
2117 (iw_handler) NULL, /* SIOCGIWESSID */
2118 (iw_handler) NULL, /* SIOCSIWNICKN */
2119 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2120 (iw_handler) NULL, /* -- hole -- */
2121 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002122 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2123 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2124 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2125 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2126 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2127 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2128 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2129 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2130 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2131 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2132 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2133 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2134 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2135 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002136 (iw_handler) NULL, /* -- hole -- */
2137 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002138 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2139 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2140 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2141 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2142 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2143 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002144 (iw_handler) NULL, /* SIOCSIWPMKSA */
2145};
Holger Schurig10078322007-11-15 18:05:47 -05002146struct iw_handler_def lbs_handler_def = {
2147 .num_standard = ARRAY_SIZE(lbs_handler),
2148 .standard = (iw_handler *) lbs_handler,
2149 .get_wireless_stats = lbs_get_wireless_stats,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002150};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002151
2152struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002153 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002154 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002155 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002156};