blob: 1e0b2245db56b157db6b71f093ae8b5fc941aa0b [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains ioctl functions
3 */
4#include <linux/ctype.h>
5#include <linux/delay.h>
6#include <linux/if.h>
7#include <linux/if_arp.h>
8#include <linux/wireless.h>
9#include <linux/bitops.h>
10
11#include <net/ieee80211.h>
12#include <net/iw_handler.h>
13
14#include "host.h"
15#include "radiotap.h"
16#include "decl.h"
17#include "defs.h"
18#include "dev.h"
19#include "join.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020#include "wext.h"
21#include "assoc.h"
22
23
Holger Schurig69f90322007-11-23 15:43:44 +010024static inline void lbs_postpone_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020025{
David Woodhouseaa21c002007-12-08 20:04:36 +000026 if (priv->surpriseremoved)
Holger Schurig9f9dac22007-10-26 10:12:14 +020027 return;
28 cancel_delayed_work(&priv->assoc_work);
29 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
30}
31
Holger Schurig69f90322007-11-23 15:43:44 +010032static inline void lbs_cancel_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020033{
34 cancel_delayed_work(&priv->assoc_work);
David Woodhouseaa21c002007-12-08 20:04:36 +000035 kfree(priv->pending_assoc_req);
36 priv->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 *
David Woodhouseaa21c002007-12-08 20:04:36 +000043 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020044 * @param band it can be BAND_A, BAND_G or BAND_B
45 * @param channel the channel for looking
46 * @return A pointer to struct chan_freq_power structure or NULL if not find.
47 */
Holger Schurig69f90322007-11-23 15:43:44 +010048struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
David Woodhouseaa21c002007-12-08 20:04:36 +000049 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +010050 u8 band,
51 u16 channel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020052{
53 struct chan_freq_power *cfp = NULL;
54 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020055 int i, j;
56
David Woodhouseaa21c002007-12-08 20:04:36 +000057 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
58 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020059
David Woodhouseaa21c002007-12-08 20:04:36 +000060 if (priv->enable11d)
61 rc = &priv->universal_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020062 if (!rc->valid || !rc->CFP)
63 continue;
64 if (rc->band != band)
65 continue;
66 for (i = 0; i < rc->nrcfp; i++) {
67 if (rc->CFP[i].channel == channel) {
68 cfp = &rc->CFP[i];
69 break;
70 }
71 }
72 }
73
74 if (!cfp && channel)
Holger Schurig10078322007-11-15 18:05:47 -050075 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
Holger Schurig9012b282007-05-25 11:27:16 -040076 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020077
78 return cfp;
79}
80
81/**
82 * @brief Find the channel frequency power info with specific frequency
83 *
David Woodhouseaa21c002007-12-08 20:04:36 +000084 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020085 * @param band it can be BAND_A, BAND_G or BAND_B
86 * @param freq the frequency for looking
87 * @return A pointer to struct chan_freq_power structure or NULL if not find.
88 */
Holger Schurig69f90322007-11-23 15:43:44 +010089static struct chan_freq_power *find_cfp_by_band_and_freq(
David Woodhouseaa21c002007-12-08 20:04:36 +000090 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +010091 u8 band,
92 u32 freq)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020093{
94 struct chan_freq_power *cfp = NULL;
95 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020096 int i, j;
97
David Woodhouseaa21c002007-12-08 20:04:36 +000098 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
99 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200100
David Woodhouseaa21c002007-12-08 20:04:36 +0000101 if (priv->enable11d)
102 rc = &priv->universal_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200103 if (!rc->valid || !rc->CFP)
104 continue;
105 if (rc->band != band)
106 continue;
107 for (i = 0; i < rc->nrcfp; i++) {
108 if (rc->CFP[i].freq == freq) {
109 cfp = &rc->CFP[i];
110 break;
111 }
112 }
113 }
114
115 if (!cfp && freq)
Holger Schurig9012b282007-05-25 11:27:16 -0400116 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
117 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200118
119 return cfp;
120}
121
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122
123/**
124 * @brief Set Radio On/OFF
125 *
Holger Schurig69f90322007-11-23 15:43:44 +0100126 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127 * @option Radio Option
128 * @return 0 --success, otherwise fail
129 */
Holger Schurig69f90322007-11-23 15:43:44 +0100130static int lbs_radio_ioctl(struct lbs_private *priv, u8 option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200131{
132 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200133
Holger Schurig9012b282007-05-25 11:27:16 -0400134 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200135
David Woodhouseaa21c002007-12-08 20:04:36 +0000136 if (priv->radioon != option) {
Holger Schurig9012b282007-05-25 11:27:16 -0400137 lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
David Woodhouseaa21c002007-12-08 20:04:36 +0000138 priv->radioon = option;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139
Holger Schurig10078322007-11-15 18:05:47 -0500140 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400141 CMD_802_11_RADIO_CONTROL,
142 CMD_ACT_SET,
143 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200144 }
145
Holger Schurig9012b282007-05-25 11:27:16 -0400146 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200147 return ret;
148}
149
150/**
Dan Williams8c512762007-08-02 11:40:45 -0400151 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000153 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200154 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000156static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200157{
Holger Schurig9012b282007-05-25 11:27:16 -0400158 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159
David Woodhouseaa21c002007-12-08 20:04:36 +0000160 if ((priv->connect_status != LBS_CONNECTED) &&
161 (priv->mesh_connect_status != LBS_CONNECTED))
Holger Schurig10078322007-11-15 18:05:47 -0500162 memcpy(rates, lbs_bg_rates, MAX_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400163 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000164 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165
Dan Williams8c512762007-08-02 11:40:45 -0400166 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200167}
168
Holger Schurig10078322007-11-15 18:05:47 -0500169static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200170 char *cwrq, char *extra)
171{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200172
Holger Schurig9012b282007-05-25 11:27:16 -0400173 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200174
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400175 /* We could add support for 802.11n here as needed. Jean II */
176 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200177
Holger Schurig9012b282007-05-25 11:27:16 -0400178 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200179 return 0;
180}
181
Holger Schurig10078322007-11-15 18:05:47 -0500182static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183 struct iw_freq *fwrq, char *extra)
184{
Holger Schurig69f90322007-11-23 15:43:44 +0100185 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200186 struct chan_freq_power *cfp;
187
Holger Schurig9012b282007-05-25 11:27:16 -0400188 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200189
David Woodhouseaa21c002007-12-08 20:04:36 +0000190 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
191 priv->curbssparams.channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200192
193 if (!cfp) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000194 if (priv->curbssparams.channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400195 lbs_deb_wext("invalid channel %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000196 priv->curbssparams.channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200197 return -EINVAL;
198 }
199
200 fwrq->m = (long)cfp->freq * 100000;
201 fwrq->e = 1;
202
Holger Schurig9012b282007-05-25 11:27:16 -0400203 lbs_deb_wext("freq %u\n", fwrq->m);
204 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200205 return 0;
206}
207
Holger Schurig10078322007-11-15 18:05:47 -0500208static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200209 struct sockaddr *awrq, char *extra)
210{
Holger Schurig69f90322007-11-23 15:43:44 +0100211 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200212
Holger Schurig9012b282007-05-25 11:27:16 -0400213 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200214
David Woodhouseaa21c002007-12-08 20:04:36 +0000215 if (priv->connect_status == LBS_CONNECTED) {
216 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200217 } else {
218 memset(awrq->sa_data, 0, ETH_ALEN);
219 }
220 awrq->sa_family = ARPHRD_ETHER;
221
Holger Schurig9012b282007-05-25 11:27:16 -0400222 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200223 return 0;
224}
225
Holger Schurig10078322007-11-15 18:05:47 -0500226static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227 struct iw_point *dwrq, char *extra)
228{
Holger Schurig69f90322007-11-23 15:43:44 +0100229 struct lbs_private *priv = dev->priv;
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
David Woodhouseaa21c002007-12-08 20:04:36 +0000241 mutex_lock(&priv->lock);
242 memset(priv->nodename, 0, sizeof(priv->nodename));
243 memcpy(priv->nodename, extra, dwrq->length);
244 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200245
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 Schurig69f90322007-11-23 15:43:44 +0100253 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200254
Holger Schurig9012b282007-05-25 11:27:16 -0400255 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200256
David Woodhouseaa21c002007-12-08 20:04:36 +0000257 dwrq->length = strlen(priv->nodename);
258 memcpy(extra, priv->nodename, dwrq->length);
Holger Schurig04799fa2007-10-09 15:04:14 +0200259 extra[dwrq->length] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200260
Holger Schurig04799fa2007-10-09 15:04:14 +0200261 dwrq->flags = 1; /* active */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200262
Holger Schurig9012b282007-05-25 11:27:16 -0400263 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200264 return 0;
265}
266
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400267static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
268 struct iw_point *dwrq, char *extra)
269{
Holger Schurig69f90322007-11-23 15:43:44 +0100270 struct lbs_private *priv = dev->priv;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400271
272 lbs_deb_enter(LBS_DEB_WEXT);
273
274 /* Use nickname to indicate that mesh is on */
275
David Woodhouseaa21c002007-12-08 20:04:36 +0000276 if (priv->mesh_connect_status == LBS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400277 strncpy(extra, "Mesh", 12);
278 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400279 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400280 }
281
282 else {
283 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400284 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400285 }
286
287 lbs_deb_leave(LBS_DEB_WEXT);
288 return 0;
289}
Holger Schurig04799fa2007-10-09 15:04:14 +0200290
Holger Schurig10078322007-11-15 18:05:47 -0500291static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200292 struct iw_param *vwrq, char *extra)
293{
294 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100295 struct lbs_private *priv = dev->priv;
David Woodhouse981f1872007-05-25 23:36:54 -0400296 u32 rthr = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297
Holger Schurig9012b282007-05-25 11:27:16 -0400298 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200299
300 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000301 priv->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302 } else {
303 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
304 return -EINVAL;
David Woodhouseaa21c002007-12-08 20:04:36 +0000305 priv->rtsthsd = rthr;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306 }
307
Holger Schurig10078322007-11-15 18:05:47 -0500308 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400309 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200310 OID_802_11_RTS_THRESHOLD, &rthr);
311
Holger Schurig9012b282007-05-25 11:27:16 -0400312 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200313 return ret;
314}
315
Holger Schurig10078322007-11-15 18:05:47 -0500316static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317 struct iw_param *vwrq, char *extra)
318{
319 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100320 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200321
Holger Schurig9012b282007-05-25 11:27:16 -0400322 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200323
David Woodhouseaa21c002007-12-08 20:04:36 +0000324 priv->rtsthsd = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500325 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400326 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200327 OID_802_11_RTS_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400328 if (ret)
329 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200330
David Woodhouseaa21c002007-12-08 20:04:36 +0000331 vwrq->value = priv->rtsthsd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200332 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
333 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
334 vwrq->fixed = 1;
335
Holger Schurig9012b282007-05-25 11:27:16 -0400336out:
337 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
338 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200339}
340
Holger Schurig10078322007-11-15 18:05:47 -0500341static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200342 struct iw_param *vwrq, char *extra)
343{
344 int ret = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400345 u32 fthr = vwrq->value;
Holger Schurig69f90322007-11-23 15:43:44 +0100346 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200347
Holger Schurig9012b282007-05-25 11:27:16 -0400348 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349
350 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000351 priv->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352 } else {
353 if (fthr < MRVDRV_FRAG_MIN_VALUE
354 || fthr > MRVDRV_FRAG_MAX_VALUE)
355 return -EINVAL;
David Woodhouseaa21c002007-12-08 20:04:36 +0000356 priv->fragthsd = fthr;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357 }
358
Holger Schurig10078322007-11-15 18:05:47 -0500359 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400360 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200361 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
Holger Schurig9012b282007-05-25 11:27:16 -0400362
363 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364 return ret;
365}
366
Holger Schurig10078322007-11-15 18:05:47 -0500367static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200368 struct iw_param *vwrq, char *extra)
369{
370 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100371 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200372
Holger Schurig9012b282007-05-25 11:27:16 -0400373 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200374
David Woodhouseaa21c002007-12-08 20:04:36 +0000375 priv->fragthsd = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500376 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400377 CMD_802_11_SNMP_MIB,
378 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200379 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400380 if (ret)
381 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200382
David Woodhouseaa21c002007-12-08 20:04:36 +0000383 vwrq->value = priv->fragthsd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200384 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
385 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
386 vwrq->fixed = 1;
387
Holger Schurig9012b282007-05-25 11:27:16 -0400388out:
389 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200390 return ret;
391}
392
Holger Schurig10078322007-11-15 18:05:47 -0500393static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200394 struct iw_request_info *info, u32 * uwrq, char *extra)
395{
Holger Schurig69f90322007-11-23 15:43:44 +0100396 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397
Holger Schurig9012b282007-05-25 11:27:16 -0400398 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200399
David Woodhouseaa21c002007-12-08 20:04:36 +0000400 *uwrq = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200401
Holger Schurig9012b282007-05-25 11:27:16 -0400402 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200403 return 0;
404}
405
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400406static int mesh_wlan_get_mode(struct net_device *dev,
407 struct iw_request_info *info, u32 * uwrq,
408 char *extra)
409{
410 lbs_deb_enter(LBS_DEB_WEXT);
411
412 *uwrq = IW_MODE_REPEAT ;
413
414 lbs_deb_leave(LBS_DEB_WEXT);
415 return 0;
416}
417
Holger Schurig10078322007-11-15 18:05:47 -0500418static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419 struct iw_request_info *info,
420 struct iw_param *vwrq, char *extra)
421{
422 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100423 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200424
Holger Schurig9012b282007-05-25 11:27:16 -0400425 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426
Holger Schurig10078322007-11-15 18:05:47 -0500427 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400428 CMD_802_11_RF_TX_POWER,
429 CMD_ACT_TX_POWER_OPT_GET,
430 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431
Holger Schurig9012b282007-05-25 11:27:16 -0400432 if (ret)
433 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200434
David Woodhouseaa21c002007-12-08 20:04:36 +0000435 lbs_deb_wext("tx power level %d dbm\n", priv->txpowerlevel);
436 vwrq->value = priv->txpowerlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437 vwrq->fixed = 1;
David Woodhouseaa21c002007-12-08 20:04:36 +0000438 if (priv->radioon) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200439 vwrq->disabled = 0;
440 vwrq->flags = IW_TXPOW_DBM;
441 } else {
442 vwrq->disabled = 1;
443 }
444
Holger Schurig9012b282007-05-25 11:27:16 -0400445out:
446 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
447 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200448}
449
Holger Schurig10078322007-11-15 18:05:47 -0500450static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200451 struct iw_param *vwrq, char *extra)
452{
453 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100454 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200455
Holger Schurig9012b282007-05-25 11:27:16 -0400456 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200457
458 if (vwrq->flags == IW_RETRY_LIMIT) {
459 /* The MAC has a 4-bit Total_Tx_Count register
460 Total_Tx_Count = 1 + Tx_Retry_Count */
461#define TX_RETRY_MIN 0
462#define TX_RETRY_MAX 14
463 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
464 return -EINVAL;
465
466 /* Adding 1 to convert retry count to try count */
David Woodhouseaa21c002007-12-08 20:04:36 +0000467 priv->txretrycount = vwrq->value + 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468
Holger Schurig10078322007-11-15 18:05:47 -0500469 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400470 CMD_ACT_SET,
471 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472 OID_802_11_TX_RETRYCOUNT, NULL);
473
Holger Schurig9012b282007-05-25 11:27:16 -0400474 if (ret)
475 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 } else {
477 return -EOPNOTSUPP;
478 }
479
Holger Schurig9012b282007-05-25 11:27:16 -0400480out:
481 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
482 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483}
484
Holger Schurig10078322007-11-15 18:05:47 -0500485static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200486 struct iw_param *vwrq, char *extra)
487{
Holger Schurig69f90322007-11-23 15:43:44 +0100488 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489 int ret = 0;
490
Holger Schurig9012b282007-05-25 11:27:16 -0400491 lbs_deb_enter(LBS_DEB_WEXT);
492
David Woodhouseaa21c002007-12-08 20:04:36 +0000493 priv->txretrycount = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500494 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400495 CMD_802_11_SNMP_MIB,
496 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200497 OID_802_11_TX_RETRYCOUNT, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400498 if (ret)
499 goto out;
500
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501 vwrq->disabled = 0;
502 if (!vwrq->flags) {
503 vwrq->flags = IW_RETRY_LIMIT;
504 /* Subtract 1 to convert try count to retry count */
David Woodhouseaa21c002007-12-08 20:04:36 +0000505 vwrq->value = priv->txretrycount - 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200506 }
507
Holger Schurig9012b282007-05-25 11:27:16 -0400508out:
509 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
510 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200511}
512
513static inline void sort_channels(struct iw_freq *freq, int num)
514{
515 int i, j;
516 struct iw_freq temp;
517
518 for (i = 0; i < num; i++)
519 for (j = i + 1; j < num; j++)
520 if (freq[i].i > freq[j].i) {
521 temp.i = freq[i].i;
522 temp.m = freq[i].m;
523
524 freq[i].i = freq[j].i;
525 freq[i].m = freq[j].m;
526
527 freq[j].i = temp.i;
528 freq[j].m = temp.m;
529 }
530}
531
532/* data rate listing
533 MULTI_BANDS:
534 abg a b b/g
535 Infra G(12) A(8) B(4) G(12)
536 Adhoc A+B(12) A(8) B(4) B(4)
537
538 non-MULTI_BANDS:
539 b b/g
540 Infra B(4) G(12)
541 Adhoc B(4) B(4)
542 */
543/**
544 * @brief Get Range Info
545 *
546 * @param dev A pointer to net_device structure
547 * @param info A pointer to iw_request_info structure
548 * @param vwrq A pointer to iw_param structure
549 * @param extra A pointer to extra data buf
550 * @return 0 --success, otherwise fail
551 */
Holger Schurig10078322007-11-15 18:05:47 -0500552static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553 struct iw_point *dwrq, char *extra)
554{
555 int i, j;
Holger Schurig69f90322007-11-23 15:43:44 +0100556 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200557 struct iw_range *range = (struct iw_range *)extra;
558 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400559 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200560
561 u8 flag = 0;
562
Holger Schurig9012b282007-05-25 11:27:16 -0400563 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200564
565 dwrq->length = sizeof(struct iw_range);
566 memset(range, 0, sizeof(struct iw_range));
567
568 range->min_nwid = 0;
569 range->max_nwid = 0;
570
571 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000572 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400573 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
574 for (i = 0; i < range->num_bitrates; i++)
575 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400577 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200578 range->num_bitrates);
579
580 range->num_frequency = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +0000581 if (priv->enable11d &&
582 (priv->connect_status == LBS_CONNECTED ||
583 priv->mesh_connect_status == LBS_CONNECTED)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200584 u8 chan_no;
585 u8 band;
586
587 struct parsed_region_chan_11d *parsed_region_chan =
David Woodhouseaa21c002007-12-08 20:04:36 +0000588 &priv->parsed_region_chan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200589
590 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400591 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
592 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593 }
594 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400595 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200596 parsed_region_chan->nr_chan);
597
598 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
599 && (i < parsed_region_chan->nr_chan); i++) {
600 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400601 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200602 range->freq[range->num_frequency].i = (long)chan_no;
603 range->freq[range->num_frequency].m =
Holger Schurig10078322007-11-15 18:05:47 -0500604 (long)lbs_chan_2_freq(chan_no, band) * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200605 range->freq[range->num_frequency].e = 1;
606 range->num_frequency++;
607 }
608 flag = 1;
609 }
610 if (!flag) {
611 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000612 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
613 cfp = priv->region_channel[j].CFP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000615 && priv->region_channel[j].valid
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616 && cfp
David Woodhouseaa21c002007-12-08 20:04:36 +0000617 && (i < priv->region_channel[j].nrcfp); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200618 range->freq[range->num_frequency].i =
619 (long)cfp->channel;
620 range->freq[range->num_frequency].m =
621 (long)cfp->freq * 100000;
622 range->freq[range->num_frequency].e = 1;
623 cfp++;
624 range->num_frequency++;
625 }
626 }
627 }
628
Holger Schurig9012b282007-05-25 11:27:16 -0400629 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200630 IW_MAX_FREQUENCIES, range->num_frequency);
631
632 range->num_channels = range->num_frequency;
633
634 sort_channels(&range->freq[0], range->num_frequency);
635
636 /*
637 * Set an indication of the max TCP throughput in bit/s that we can
638 * expect using this interface
639 */
640 if (i > 2)
641 range->throughput = 5000 * 1000;
642 else
643 range->throughput = 1500 * 1000;
644
645 range->min_rts = MRVDRV_RTS_MIN_VALUE;
646 range->max_rts = MRVDRV_RTS_MAX_VALUE;
647 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
648 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
649
650 range->encoding_size[0] = 5;
651 range->encoding_size[1] = 13;
652 range->num_encoding_sizes = 2;
653 range->max_encoding_tokens = 4;
654
655 range->min_pmp = 1000000;
656 range->max_pmp = 120000000;
657 range->min_pmt = 1000;
658 range->max_pmt = 1000000;
659 range->pmp_flags = IW_POWER_PERIOD;
660 range->pmt_flags = IW_POWER_TIMEOUT;
661 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
662
663 /*
664 * Minimum version we recommend
665 */
666 range->we_version_source = 15;
667
668 /*
669 * Version we are compiled with
670 */
671 range->we_version_compiled = WIRELESS_EXT;
672
673 range->retry_capa = IW_RETRY_LIMIT;
674 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
675
676 range->min_retry = TX_RETRY_MIN;
677 range->max_retry = TX_RETRY_MAX;
678
679 /*
680 * Set the qual, level and noise range values
681 */
682 range->max_qual.qual = 100;
683 range->max_qual.level = 0;
684 range->max_qual.noise = 0;
685 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
686
687 range->avg_qual.qual = 70;
688 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
689 range->avg_qual.level = 0;
690 range->avg_qual.noise = 0;
691 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
692
693 range->sensitivity = 0;
694
695 /*
696 * Setup the supported power level ranges
697 */
698 memset(range->txpower, 0, sizeof(range->txpower));
699 range->txpower[0] = 5;
700 range->txpower[1] = 7;
701 range->txpower[2] = 9;
702 range->txpower[3] = 11;
703 range->txpower[4] = 13;
704 range->txpower[5] = 15;
705 range->txpower[6] = 17;
706 range->txpower[7] = 19;
707
708 range->num_txpower = 8;
709 range->txpower_capa = IW_TXPOW_DBM;
710 range->txpower_capa |= IW_TXPOW_RANGE;
711
712 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
713 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
714 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
715 range->event_capa[1] = IW_EVENT_CAPA_K_1;
716
David Woodhouseaa21c002007-12-08 20:04:36 +0000717 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200718 range->enc_capa = IW_ENC_CAPA_WPA
719 | IW_ENC_CAPA_WPA2
720 | IW_ENC_CAPA_CIPHER_TKIP
721 | IW_ENC_CAPA_CIPHER_CCMP;
722 }
723
Holger Schurig9012b282007-05-25 11:27:16 -0400724out:
725 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200726 return 0;
727}
728
Holger Schurig10078322007-11-15 18:05:47 -0500729static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200730 struct iw_param *vwrq, char *extra)
731{
Holger Schurig69f90322007-11-23 15:43:44 +0100732 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200733
Holger Schurig9012b282007-05-25 11:27:16 -0400734 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200735
736 /* PS is currently supported only in Infrastructure mode
737 * Remove this check if it is to be supported in IBSS mode also
738 */
739
740 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000741 priv->psmode = LBS802_11POWERMODECAM;
742 if (priv->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500743 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200744 }
745
746 return 0;
747 }
748
749 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400750 lbs_deb_wext(
751 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200752 return -EINVAL;
753 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400754 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200755 return -EINVAL;
756 }
757
David Woodhouseaa21c002007-12-08 20:04:36 +0000758 if (priv->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200759 return 0;
760 }
761
David Woodhouseaa21c002007-12-08 20:04:36 +0000762 priv->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200763
David Woodhouseaa21c002007-12-08 20:04:36 +0000764 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500765 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200766 }
767
Holger Schurig9012b282007-05-25 11:27:16 -0400768 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200769 return 0;
770}
771
Holger Schurig10078322007-11-15 18:05:47 -0500772static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200773 struct iw_param *vwrq, char *extra)
774{
Holger Schurig69f90322007-11-23 15:43:44 +0100775 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200776 int mode;
777
Holger Schurig9012b282007-05-25 11:27:16 -0400778 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200779
David Woodhouseaa21c002007-12-08 20:04:36 +0000780 mode = priv->psmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200781
Holger Schurig10078322007-11-15 18:05:47 -0500782 if ((vwrq->disabled = (mode == LBS802_11POWERMODECAM))
David Woodhouseaa21c002007-12-08 20:04:36 +0000783 || priv->connect_status == LBS_DISCONNECTED)
Holger Schurig9012b282007-05-25 11:27:16 -0400784 {
785 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200786 }
787
788 vwrq->value = 0;
789
Holger Schurig9012b282007-05-25 11:27:16 -0400790out:
791 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200792 return 0;
793}
794
Holger Schurig10078322007-11-15 18:05:47 -0500795static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200796{
797 enum {
798 POOR = 30,
799 FAIR = 60,
800 GOOD = 80,
801 VERY_GOOD = 90,
802 EXCELLENT = 95,
803 PERFECT = 100
804 };
Holger Schurig69f90322007-11-23 15:43:44 +0100805 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200806 u32 rssi_qual;
807 u32 tx_qual;
808 u32 quality = 0;
809 int stats_valid = 0;
810 u8 rssi;
811 u32 tx_retries;
812
Holger Schurig9012b282007-05-25 11:27:16 -0400813 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200814
David Woodhouseaa21c002007-12-08 20:04:36 +0000815 priv->wstats.status = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200816
817 /* If we're not associated, all quality values are meaningless */
David Woodhouseaa21c002007-12-08 20:04:36 +0000818 if ((priv->connect_status != LBS_CONNECTED) &&
819 (priv->mesh_connect_status != LBS_CONNECTED))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820 goto out;
821
822 /* Quality by RSSI */
823 priv->wstats.qual.level =
David Woodhouseaa21c002007-12-08 20:04:36 +0000824 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
825 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200826
David Woodhouseaa21c002007-12-08 20:04:36 +0000827 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200828 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
829 } else {
830 priv->wstats.qual.noise =
David Woodhouseaa21c002007-12-08 20:04:36 +0000831 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200832 }
833
Holger Schurig9012b282007-05-25 11:27:16 -0400834 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
835 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200836
837 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
838 if (rssi < 15)
839 rssi_qual = rssi * POOR / 10;
840 else if (rssi < 20)
841 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
842 else if (rssi < 30)
843 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
844 else if (rssi < 40)
845 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
846 10 + GOOD;
847 else
848 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
849 10 + VERY_GOOD;
850 quality = rssi_qual;
851
852 /* Quality by TX errors */
853 priv->wstats.discard.retries = priv->stats.tx_errors;
854
David Woodhouseaa21c002007-12-08 20:04:36 +0000855 tx_retries = le32_to_cpu(priv->logmsg.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856
857 if (tx_retries > 75)
858 tx_qual = (90 - tx_retries) * POOR / 15;
859 else if (tx_retries > 70)
860 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
861 else if (tx_retries > 65)
862 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
863 else if (tx_retries > 50)
864 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
865 15 + GOOD;
866 else
867 tx_qual = (50 - tx_retries) *
868 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
869 quality = min(quality, tx_qual);
870
David Woodhouseaa21c002007-12-08 20:04:36 +0000871 priv->wstats.discard.code = le32_to_cpu(priv->logmsg.wepundecryptable);
872 priv->wstats.discard.fragment = le32_to_cpu(priv->logmsg.rxfrag);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200873 priv->wstats.discard.retries = tx_retries;
David Woodhouseaa21c002007-12-08 20:04:36 +0000874 priv->wstats.discard.misc = le32_to_cpu(priv->logmsg.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200875
876 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400877 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200878 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
879 stats_valid = 1;
880
881 /* update stats asynchronously for future calls */
Holger Schurig10078322007-11-15 18:05:47 -0500882 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200883 0, 0, NULL);
Holger Schurig10078322007-11-15 18:05:47 -0500884 lbs_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200885 0, 0, NULL);
886out:
887 if (!stats_valid) {
888 priv->wstats.miss.beacon = 0;
889 priv->wstats.discard.retries = 0;
890 priv->wstats.qual.qual = 0;
891 priv->wstats.qual.level = 0;
892 priv->wstats.qual.noise = 0;
893 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
894 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
895 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
896 }
897
Holger Schurig9012b282007-05-25 11:27:16 -0400898 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200899 return &priv->wstats;
900
901
902}
903
Holger Schurig10078322007-11-15 18:05:47 -0500904static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905 struct iw_freq *fwrq, char *extra)
906{
Dan Williamsef9a2642007-05-25 16:46:33 -0400907 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +0100908 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200909 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400910 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200911
Holger Schurig9012b282007-05-25 11:27:16 -0400912 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200913
David Woodhouseaa21c002007-12-08 20:04:36 +0000914 mutex_lock(&priv->lock);
915 assoc_req = lbs_get_association_request(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400916 if (!assoc_req) {
917 ret = -ENOMEM;
918 goto out;
919 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200920
Dan Williamsef9a2642007-05-25 16:46:33 -0400921 /* If setting by frequency, convert to a channel */
922 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200923 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200924
David Woodhouseaa21c002007-12-08 20:04:36 +0000925 cfp = find_cfp_by_band_and_freq(priv, 0, f);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200926 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400927 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400928 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200929 }
930
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200931 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400932 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200933 }
934
Dan Williamsef9a2642007-05-25 16:46:33 -0400935 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200936 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400937 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200938 }
939
David Woodhouseaa21c002007-12-08 20:04:36 +0000940 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400941 if (!cfp) {
942 goto out;
943 }
944
945 assoc_req->channel = fwrq->m;
946 ret = 0;
947
Holger Schurig9012b282007-05-25 11:27:16 -0400948out:
Dan Williamsef9a2642007-05-25 16:46:33 -0400949 if (ret == 0) {
950 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500951 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400952 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500953 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400954 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000955 mutex_unlock(&priv->lock);
Dan Williamsef9a2642007-05-25 16:46:33 -0400956
957 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
958 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200959}
960
Holger Schurig10078322007-11-15 18:05:47 -0500961static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200962 struct iw_param *vwrq, char *extra)
963{
Holger Schurig69f90322007-11-23 15:43:44 +0100964 struct lbs_private *priv = dev->priv;
Dan Williams8c512762007-08-02 11:40:45 -0400965 u32 new_rate;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200966 u16 action;
Dan Williams8c512762007-08-02 11:40:45 -0400967 int ret = -EINVAL;
968 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200969
Holger Schurig9012b282007-05-25 11:27:16 -0400970 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -0400971 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200972
Dan Williams8c512762007-08-02 11:40:45 -0400973 /* Auto rate? */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200974 if (vwrq->value == -1) {
Dan Williams8c512762007-08-02 11:40:45 -0400975 action = CMD_ACT_SET_TX_AUTO;
David Woodhouseaa21c002007-12-08 20:04:36 +0000976 priv->auto_rate = 1;
977 priv->cur_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200978 } else {
Dan Williams8c512762007-08-02 11:40:45 -0400979 if (vwrq->value % 100000)
980 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200981
982 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000983 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400984 new_rate = vwrq->value / 500000;
985 if (!memchr(rates, new_rate, sizeof(rates))) {
986 lbs_pr_alert("fixed data rate 0x%X out of range\n",
987 new_rate);
988 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200989 }
990
David Woodhouseaa21c002007-12-08 20:04:36 +0000991 priv->cur_rate = new_rate;
Dan Williamsffcae952007-08-02 11:35:46 -0400992 action = CMD_ACT_SET_TX_FIX_RATE;
David Woodhouseaa21c002007-12-08 20:04:36 +0000993 priv->auto_rate = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200994 }
995
Holger Schurig10078322007-11-15 18:05:47 -0500996 ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
Dan Williams0aef64d2007-08-02 11:31:18 -0400997 action, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200998
Dan Williams8c512762007-08-02 11:40:45 -0400999out:
Holger Schurig9012b282007-05-25 11:27:16 -04001000 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001001 return ret;
1002}
1003
Holger Schurig10078322007-11-15 18:05:47 -05001004static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001005 struct iw_param *vwrq, char *extra)
1006{
Holger Schurig69f90322007-11-23 15:43:44 +01001007 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001008
Holger Schurig9012b282007-05-25 11:27:16 -04001009 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001010
David Woodhouseaa21c002007-12-08 20:04:36 +00001011 if (priv->connect_status == LBS_CONNECTED) {
1012 vwrq->value = priv->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001013
David Woodhouseaa21c002007-12-08 20:04:36 +00001014 if (priv->auto_rate)
Dan Williams8c512762007-08-02 11:40:45 -04001015 vwrq->fixed = 0;
1016 else
1017 vwrq->fixed = 1;
1018
1019 } else {
1020 vwrq->fixed = 0;
1021 vwrq->value = 0;
1022 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001023
Holger Schurig9012b282007-05-25 11:27:16 -04001024 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001025 return 0;
1026}
1027
Holger Schurig10078322007-11-15 18:05:47 -05001028static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029 struct iw_request_info *info, u32 * uwrq, char *extra)
1030{
1031 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001032 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001033 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001034
Holger Schurig9012b282007-05-25 11:27:16 -04001035 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001036
Dan Williams0dc5a292007-05-10 22:58:02 -04001037 if ( (*uwrq != IW_MODE_ADHOC)
1038 && (*uwrq != IW_MODE_INFRA)
1039 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001040 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001041 ret = -EINVAL;
1042 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001043 }
1044
David Woodhouseaa21c002007-12-08 20:04:36 +00001045 mutex_lock(&priv->lock);
1046 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001047 if (!assoc_req) {
1048 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001049 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001050 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001051 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001052 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001053 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001054 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001055 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001056 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001057
Dan Williams0dc5a292007-05-10 22:58:02 -04001058out:
Holger Schurig9012b282007-05-25 11:27:16 -04001059 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001060 return ret;
1061}
1062
1063
1064/**
1065 * @brief Get Encryption key
1066 *
1067 * @param dev A pointer to net_device structure
1068 * @param info A pointer to iw_request_info structure
1069 * @param vwrq A pointer to iw_param structure
1070 * @param extra A pointer to extra data buf
1071 * @return 0 --success, otherwise fail
1072 */
Holger Schurig10078322007-11-15 18:05:47 -05001073static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074 struct iw_request_info *info,
1075 struct iw_point *dwrq, u8 * extra)
1076{
Holger Schurig69f90322007-11-23 15:43:44 +01001077 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001078 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1079
Holger Schurig9012b282007-05-25 11:27:16 -04001080 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001081
Holger Schurig9012b282007-05-25 11:27:16 -04001082 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001083 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001084
1085 dwrq->flags = 0;
1086
1087 /* Authentication method */
David Woodhouseaa21c002007-12-08 20:04:36 +00001088 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -04001089 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001090 dwrq->flags = IW_ENCODE_OPEN;
1091 break;
1092
Dan Williams6affe782007-05-10 22:56:42 -04001093 case IW_AUTH_ALG_SHARED_KEY:
1094 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001095 dwrq->flags = IW_ENCODE_RESTRICTED;
1096 break;
1097 default:
1098 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1099 break;
1100 }
1101
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001102 memset(extra, 0, 16);
1103
David Woodhouseaa21c002007-12-08 20:04:36 +00001104 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001105
1106 /* Default to returning current transmit key */
1107 if (index < 0)
David Woodhouseaa21c002007-12-08 20:04:36 +00001108 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001109
David Woodhouseaa21c002007-12-08 20:04:36 +00001110 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1111 memcpy(extra, priv->wep_keys[index].key,
1112 priv->wep_keys[index].len);
1113 dwrq->length = priv->wep_keys[index].len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001114
1115 dwrq->flags |= (index + 1);
1116 /* Return WEP enabled */
1117 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhouseaa21c002007-12-08 20:04:36 +00001118 } else if ((priv->secinfo.WPAenabled)
1119 || (priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001120 /* return WPA enabled */
1121 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhousec12bdc42007-12-07 19:32:12 +00001122 dwrq->flags |= IW_ENCODE_NOKEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001123 } else {
1124 dwrq->flags |= IW_ENCODE_DISABLED;
1125 }
1126
David Woodhouseaa21c002007-12-08 20:04:36 +00001127 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001128
Joe Perches0795af52007-10-03 17:59:30 -07001129 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001130 extra[0], extra[1], extra[2],
1131 extra[3], extra[4], extra[5], dwrq->length);
1132
Holger Schurig9012b282007-05-25 11:27:16 -04001133 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001134
Holger Schurig9012b282007-05-25 11:27:16 -04001135 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001136 return 0;
1137}
1138
1139/**
1140 * @brief Set Encryption key (internal)
1141 *
1142 * @param priv A pointer to private card structure
1143 * @param key_material A pointer to key material
1144 * @param key_length length of key material
1145 * @param index key index to set
1146 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1147 * @return 0 --success, otherwise fail
1148 */
Holger Schurig10078322007-11-15 18:05:47 -05001149static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001150 const char *key_material,
1151 u16 key_length,
1152 u16 index,
1153 int set_tx_key)
1154{
Holger Schurig9012b282007-05-25 11:27:16 -04001155 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001156 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001157
Holger Schurig9012b282007-05-25 11:27:16 -04001158 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001159
1160 /* Paranoid validation of key index */
1161 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001162 ret = -EINVAL;
1163 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001164 }
1165
1166 /* validate max key length */
1167 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001168 ret = -EINVAL;
1169 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170 }
1171
1172 pkey = &assoc_req->wep_keys[index];
1173
1174 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001175 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001176 pkey->type = KEY_TYPE_ID_WEP;
1177
1178 /* Standardize the key length */
1179 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1180 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1181 memcpy(pkey->key, key_material, key_length);
1182 }
1183
1184 if (set_tx_key) {
1185 /* Ensure the chosen key is valid */
1186 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001187 lbs_deb_wext("key not set, so cannot enable it\n");
1188 ret = -EINVAL;
1189 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001190 }
1191 assoc_req->wep_tx_keyidx = index;
1192 }
1193
Dan Williams889c05b2007-05-10 22:57:23 -04001194 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001195
Holger Schurig9012b282007-05-25 11:27:16 -04001196out:
1197 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1198 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001199}
1200
1201static int validate_key_index(u16 def_index, u16 raw_index,
1202 u16 *out_index, u16 *is_default)
1203{
1204 if (!out_index || !is_default)
1205 return -EINVAL;
1206
1207 /* Verify index if present, otherwise use default TX key index */
1208 if (raw_index > 0) {
1209 if (raw_index > 4)
1210 return -EINVAL;
1211 *out_index = raw_index - 1;
1212 } else {
1213 *out_index = def_index;
1214 *is_default = 1;
1215 }
1216 return 0;
1217}
1218
1219static void disable_wep(struct assoc_request *assoc_req)
1220{
1221 int i;
1222
Dan Williams90a42212007-05-25 23:01:24 -04001223 lbs_deb_enter(LBS_DEB_WEXT);
1224
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001225 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001226 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001227
1228 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001229 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001230 for (i = 0; i < 4; i++)
1231 assoc_req->wep_keys[i].len = 0;
1232
1233 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1234 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001235
1236 lbs_deb_leave(LBS_DEB_WEXT);
1237}
1238
1239static void disable_wpa(struct assoc_request *assoc_req)
1240{
1241 lbs_deb_enter(LBS_DEB_WEXT);
1242
Dan Williams1443b652007-08-02 10:45:55 -04001243 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001244 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1245 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1246
Dan Williams1443b652007-08-02 10:45:55 -04001247 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001248 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1249 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1250
1251 assoc_req->secinfo.WPAenabled = 0;
1252 assoc_req->secinfo.WPA2enabled = 0;
1253 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1254
1255 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001256}
1257
1258/**
1259 * @brief Set Encryption key
1260 *
1261 * @param dev A pointer to net_device structure
1262 * @param info A pointer to iw_request_info structure
1263 * @param vwrq A pointer to iw_param structure
1264 * @param extra A pointer to extra data buf
1265 * @return 0 --success, otherwise fail
1266 */
Holger Schurig10078322007-11-15 18:05:47 -05001267static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001268 struct iw_request_info *info,
1269 struct iw_point *dwrq, char *extra)
1270{
1271 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001272 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001273 struct assoc_request * assoc_req;
1274 u16 is_default = 0, index = 0, set_tx_key = 0;
1275
Holger Schurig9012b282007-05-25 11:27:16 -04001276 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001277
David Woodhouseaa21c002007-12-08 20:04:36 +00001278 mutex_lock(&priv->lock);
1279 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001280 if (!assoc_req) {
1281 ret = -ENOMEM;
1282 goto out;
1283 }
1284
1285 if (dwrq->flags & IW_ENCODE_DISABLED) {
1286 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001287 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001288 goto out;
1289 }
1290
1291 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1292 (dwrq->flags & IW_ENCODE_INDEX),
1293 &index, &is_default);
1294 if (ret) {
1295 ret = -EINVAL;
1296 goto out;
1297 }
1298
1299 /* If WEP isn't enabled, or if there is no key data but a valid
1300 * index, set the TX key.
1301 */
Dan Williams889c05b2007-05-10 22:57:23 -04001302 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001303 set_tx_key = 1;
1304
Holger Schurig10078322007-11-15 18:05:47 -05001305 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001306 if (ret)
1307 goto out;
1308
1309 if (dwrq->length)
1310 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1311 if (set_tx_key)
1312 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1313
1314 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001315 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001316 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001317 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001318 }
1319
1320out:
1321 if (ret == 0) {
1322 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001323 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001324 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001325 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001326 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001327 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001328
Holger Schurig9012b282007-05-25 11:27:16 -04001329 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001330 return ret;
1331}
1332
1333/**
1334 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1335 *
1336 * @param dev A pointer to net_device structure
1337 * @param info A pointer to iw_request_info structure
1338 * @param vwrq A pointer to iw_param structure
1339 * @param extra A pointer to extra data buf
1340 * @return 0 on success, otherwise failure
1341 */
Holger Schurig10078322007-11-15 18:05:47 -05001342static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001343 struct iw_request_info *info,
1344 struct iw_point *dwrq,
1345 char *extra)
1346{
1347 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +01001348 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1350 int index, max_key_len;
1351
Holger Schurig9012b282007-05-25 11:27:16 -04001352 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001353
1354 max_key_len = dwrq->length - sizeof(*ext);
1355 if (max_key_len < 0)
1356 goto out;
1357
1358 index = dwrq->flags & IW_ENCODE_INDEX;
1359 if (index) {
1360 if (index < 1 || index > 4)
1361 goto out;
1362 index--;
1363 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001364 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001365 }
1366
Roel Kluinf59d9782007-10-26 21:51:26 +02001367 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001368 ext->alg != IW_ENCODE_ALG_WEP) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001369 if (index != 0 || priv->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001370 goto out;
1371 }
1372
1373 dwrq->flags = index + 1;
1374 memset(ext, 0, sizeof(*ext));
1375
David Woodhouseaa21c002007-12-08 20:04:36 +00001376 if ( !priv->secinfo.wep_enabled
1377 && !priv->secinfo.WPAenabled
1378 && !priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001379 ext->alg = IW_ENCODE_ALG_NONE;
1380 ext->key_len = 0;
1381 dwrq->flags |= IW_ENCODE_DISABLED;
1382 } else {
1383 u8 *key = NULL;
1384
David Woodhouseaa21c002007-12-08 20:04:36 +00001385 if ( priv->secinfo.wep_enabled
1386 && !priv->secinfo.WPAenabled
1387 && !priv->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001388 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001389 ext->alg = IW_ENCODE_ALG_WEP;
David Woodhouseaa21c002007-12-08 20:04:36 +00001390 ext->key_len = priv->wep_keys[index].len;
1391 key = &priv->wep_keys[index].key[0];
1392 } else if ( !priv->secinfo.wep_enabled
1393 && (priv->secinfo.WPAenabled ||
1394 priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001395 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001396 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001397
David Woodhouseaa21c002007-12-08 20:04:36 +00001398 if ( priv->wpa_mcast_key.len
1399 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1400 pkey = &priv->wpa_mcast_key;
1401 else if ( priv->wpa_unicast_key.len
1402 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1403 pkey = &priv->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001404
1405 if (pkey) {
1406 if (pkey->type == KEY_TYPE_ID_AES) {
1407 ext->alg = IW_ENCODE_ALG_CCMP;
1408 } else {
1409 ext->alg = IW_ENCODE_ALG_TKIP;
1410 }
1411 ext->key_len = pkey->len;
1412 key = &pkey->key[0];
1413 } else {
1414 ext->alg = IW_ENCODE_ALG_TKIP;
1415 ext->key_len = 0;
1416 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001417 } else {
1418 goto out;
1419 }
1420
1421 if (ext->key_len > max_key_len) {
1422 ret = -E2BIG;
1423 goto out;
1424 }
1425
1426 if (ext->key_len)
1427 memcpy(ext->key, key, ext->key_len);
1428 else
1429 dwrq->flags |= IW_ENCODE_NOKEY;
1430 dwrq->flags |= IW_ENCODE_ENABLED;
1431 }
1432 ret = 0;
1433
1434out:
Holger Schurig9012b282007-05-25 11:27:16 -04001435 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001436 return ret;
1437}
1438
1439/**
1440 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1441 *
1442 * @param dev A pointer to net_device structure
1443 * @param info A pointer to iw_request_info structure
1444 * @param vwrq A pointer to iw_param structure
1445 * @param extra A pointer to extra data buf
1446 * @return 0 --success, otherwise fail
1447 */
Holger Schurig10078322007-11-15 18:05:47 -05001448static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001449 struct iw_request_info *info,
1450 struct iw_point *dwrq,
1451 char *extra)
1452{
1453 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001454 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001455 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1456 int alg = ext->alg;
1457 struct assoc_request * assoc_req;
1458
Holger Schurig9012b282007-05-25 11:27:16 -04001459 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001460
David Woodhouseaa21c002007-12-08 20:04:36 +00001461 mutex_lock(&priv->lock);
1462 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001463 if (!assoc_req) {
1464 ret = -ENOMEM;
1465 goto out;
1466 }
1467
1468 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1469 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001470 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001471 } else if (alg == IW_ENCODE_ALG_WEP) {
1472 u16 is_default = 0, index, set_tx_key = 0;
1473
1474 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1475 (dwrq->flags & IW_ENCODE_INDEX),
1476 &index, &is_default);
1477 if (ret)
1478 goto out;
1479
1480 /* If WEP isn't enabled, or if there is no key data but a valid
1481 * index, or if the set-TX-key flag was passed, set the TX key.
1482 */
Dan Williams889c05b2007-05-10 22:57:23 -04001483 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001484 || (dwrq->length == 0 && !is_default)
1485 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1486 set_tx_key = 1;
1487
1488 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001489 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001490 set_tx_key);
1491 if (ret)
1492 goto out;
1493
1494 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001495 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001496 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001497 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001498 }
1499
1500 /* Mark the various WEP bits as modified */
1501 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1502 if (dwrq->length)
1503 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1504 if (set_tx_key)
1505 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001506 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001507 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508
1509 /* validate key length */
1510 if (((alg == IW_ENCODE_ALG_TKIP)
1511 && (ext->key_len != KEY_LEN_WPA_TKIP))
1512 || ((alg == IW_ENCODE_ALG_CCMP)
1513 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001514 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001515 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001516 ext->key_len,
1517 alg);
1518 ret = -EINVAL;
1519 goto out;
1520 }
1521
Dan Williams90a42212007-05-25 23:01:24 -04001522 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001523 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001524 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1525 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001526 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001527 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1528 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001529
Dan Williams1443b652007-08-02 10:45:55 -04001530 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001531 memcpy(pkey->key, ext->key, ext->key_len);
1532 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001533 if (pkey->len)
1534 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001535
Dan Williams90a42212007-05-25 23:01:24 -04001536 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001537 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1538 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001539 } else {
1540 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001541 }
1542
Dan Williams90a42212007-05-25 23:01:24 -04001543 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001544 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001545 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001546 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001547 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001548
1549 /* If WPA isn't enabled yet, do that now */
1550 if ( assoc_req->secinfo.WPAenabled == 0
1551 && assoc_req->secinfo.WPA2enabled == 0) {
1552 assoc_req->secinfo.WPAenabled = 1;
1553 assoc_req->secinfo.WPA2enabled = 1;
1554 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1555 }
1556
1557 disable_wep (assoc_req);
1558 }
1559
1560out:
1561 if (ret == 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001562 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001563 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001564 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001565 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001566 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001567
Holger Schurig9012b282007-05-25 11:27:16 -04001568 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001569 return ret;
1570}
1571
1572
Holger Schurig10078322007-11-15 18:05:47 -05001573static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001574 struct iw_request_info *info,
1575 struct iw_point *dwrq,
1576 char *extra)
1577{
Holger Schurig69f90322007-11-23 15:43:44 +01001578 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001579 int ret = 0;
1580 struct assoc_request * assoc_req;
1581
Holger Schurig9012b282007-05-25 11:27:16 -04001582 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001583
David Woodhouseaa21c002007-12-08 20:04:36 +00001584 mutex_lock(&priv->lock);
1585 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001586 if (!assoc_req) {
1587 ret = -ENOMEM;
1588 goto out;
1589 }
1590
1591 if (dwrq->length > MAX_WPA_IE_LEN ||
1592 (dwrq->length && extra == NULL)) {
1593 ret = -EINVAL;
1594 goto out;
1595 }
1596
1597 if (dwrq->length) {
1598 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1599 assoc_req->wpa_ie_len = dwrq->length;
1600 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001601 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001602 assoc_req->wpa_ie_len = 0;
1603 }
1604
1605out:
1606 if (ret == 0) {
1607 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001608 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001609 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001610 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001611 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001612 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001613
Holger Schurig9012b282007-05-25 11:27:16 -04001614 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001615 return ret;
1616}
1617
Holger Schurig10078322007-11-15 18:05:47 -05001618static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001619 struct iw_request_info *info,
1620 struct iw_point *dwrq,
1621 char *extra)
1622{
Holger Schurig9012b282007-05-25 11:27:16 -04001623 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001624 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001625
Holger Schurig9012b282007-05-25 11:27:16 -04001626 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001627
David Woodhouseaa21c002007-12-08 20:04:36 +00001628 if (priv->wpa_ie_len == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001629 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001630 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001631 }
1632
David Woodhouseaa21c002007-12-08 20:04:36 +00001633 if (dwrq->length < priv->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001634 ret = -E2BIG;
1635 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001636 }
1637
David Woodhouseaa21c002007-12-08 20:04:36 +00001638 dwrq->length = priv->wpa_ie_len;
1639 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001640
Holger Schurig9012b282007-05-25 11:27:16 -04001641out:
1642 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1643 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001644}
1645
1646
Holger Schurig10078322007-11-15 18:05:47 -05001647static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001648 struct iw_request_info *info,
1649 struct iw_param *dwrq,
1650 char *extra)
1651{
Holger Schurig69f90322007-11-23 15:43:44 +01001652 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001653 struct assoc_request * assoc_req;
1654 int ret = 0;
1655 int updated = 0;
1656
Holger Schurig9012b282007-05-25 11:27:16 -04001657 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001658
David Woodhouseaa21c002007-12-08 20:04:36 +00001659 mutex_lock(&priv->lock);
1660 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001661 if (!assoc_req) {
1662 ret = -ENOMEM;
1663 goto out;
1664 }
1665
1666 switch (dwrq->flags & IW_AUTH_INDEX) {
1667 case IW_AUTH_TKIP_COUNTERMEASURES:
1668 case IW_AUTH_CIPHER_PAIRWISE:
1669 case IW_AUTH_CIPHER_GROUP:
1670 case IW_AUTH_KEY_MGMT:
Dan Williams90a42212007-05-25 23:01:24 -04001671 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001672 /*
1673 * libertas does not use these parameters
1674 */
1675 break;
1676
1677 case IW_AUTH_WPA_VERSION:
1678 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1679 assoc_req->secinfo.WPAenabled = 0;
1680 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001681 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001682 }
1683 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1684 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001685 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001686 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001687 }
1688 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1689 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001690 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001691 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001692 }
1693 updated = 1;
1694 break;
1695
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001696 case IW_AUTH_80211_AUTH_ALG:
1697 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001698 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001699 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001700 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001701 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001702 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001703 } else {
1704 ret = -EINVAL;
1705 }
1706 updated = 1;
1707 break;
1708
1709 case IW_AUTH_WPA_ENABLED:
1710 if (dwrq->value) {
1711 if (!assoc_req->secinfo.WPAenabled &&
1712 !assoc_req->secinfo.WPA2enabled) {
1713 assoc_req->secinfo.WPAenabled = 1;
1714 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001715 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001716 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001717 }
1718 } else {
1719 assoc_req->secinfo.WPAenabled = 0;
1720 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001721 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001722 }
1723 updated = 1;
1724 break;
1725
1726 default:
1727 ret = -EOPNOTSUPP;
1728 break;
1729 }
1730
1731out:
1732 if (ret == 0) {
1733 if (updated)
1734 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001735 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001736 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001737 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001738 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001739 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001740
Holger Schurig9012b282007-05-25 11:27:16 -04001741 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001742 return ret;
1743}
1744
Holger Schurig10078322007-11-15 18:05:47 -05001745static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001746 struct iw_request_info *info,
1747 struct iw_param *dwrq,
1748 char *extra)
1749{
Holger Schurig9012b282007-05-25 11:27:16 -04001750 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001751 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001752
Holger Schurig9012b282007-05-25 11:27:16 -04001753 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001754
1755 switch (dwrq->flags & IW_AUTH_INDEX) {
1756 case IW_AUTH_WPA_VERSION:
1757 dwrq->value = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +00001758 if (priv->secinfo.WPAenabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001759 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
David Woodhouseaa21c002007-12-08 20:04:36 +00001760 if (priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001761 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1762 if (!dwrq->value)
1763 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1764 break;
1765
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001766 case IW_AUTH_80211_AUTH_ALG:
David Woodhouseaa21c002007-12-08 20:04:36 +00001767 dwrq->value = priv->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001768 break;
1769
1770 case IW_AUTH_WPA_ENABLED:
David Woodhouseaa21c002007-12-08 20:04:36 +00001771 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001772 dwrq->value = 1;
1773 break;
1774
1775 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001776 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001777 }
1778
Holger Schurig9012b282007-05-25 11:27:16 -04001779 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1780 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001781}
1782
1783
Holger Schurig10078322007-11-15 18:05:47 -05001784static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001785 struct iw_param *vwrq, char *extra)
1786{
1787 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001788 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001789
1790 u16 dbm;
1791
Holger Schurig9012b282007-05-25 11:27:16 -04001792 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001793
1794 if (vwrq->disabled) {
Holger Schurig10078322007-11-15 18:05:47 -05001795 lbs_radio_ioctl(priv, RADIO_OFF);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001796 return 0;
1797 }
1798
David Woodhouseaa21c002007-12-08 20:04:36 +00001799 priv->preamble = CMD_TYPE_AUTO_PREAMBLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001800
Holger Schurig10078322007-11-15 18:05:47 -05001801 lbs_radio_ioctl(priv, RADIO_ON);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001802
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001803 /* Userspace check in iwrange if it should use dBm or mW,
1804 * therefore this should never happen... Jean II */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001805 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
Jean Tourrilhes9483f032007-08-02 13:16:30 -04001806 return -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001807 } else
1808 dbm = (u16) vwrq->value;
1809
1810 /* auto tx power control */
1811
1812 if (vwrq->fixed == 0)
1813 dbm = 0xffff;
1814
Holger Schurig9012b282007-05-25 11:27:16 -04001815 lbs_deb_wext("txpower set %d dbm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816
Holger Schurig10078322007-11-15 18:05:47 -05001817 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -04001818 CMD_802_11_RF_TX_POWER,
1819 CMD_ACT_TX_POWER_OPT_SET_LOW,
1820 CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001821
Holger Schurig9012b282007-05-25 11:27:16 -04001822 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001823 return ret;
1824}
1825
Holger Schurig10078322007-11-15 18:05:47 -05001826static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001827 struct iw_point *dwrq, char *extra)
1828{
Holger Schurig69f90322007-11-23 15:43:44 +01001829 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001830
Holger Schurig9012b282007-05-25 11:27:16 -04001831 lbs_deb_enter(LBS_DEB_WEXT);
1832
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001833 /*
1834 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1835 * the SSID list...
1836 */
1837
1838 /*
1839 * Get the current SSID
1840 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001841 if (priv->connect_status == LBS_CONNECTED) {
1842 memcpy(extra, priv->curbssparams.ssid,
1843 priv->curbssparams.ssid_len);
1844 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845 } else {
1846 memset(extra, 0, 32);
David Woodhouseaa21c002007-12-08 20:04:36 +00001847 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001848 }
1849 /*
1850 * If none, we may want to get the one that was set
1851 */
1852
David Woodhouseaa21c002007-12-08 20:04:36 +00001853 dwrq->length = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001854
1855 dwrq->flags = 1; /* active */
1856
Holger Schurig9012b282007-05-25 11:27:16 -04001857 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001858 return 0;
1859}
1860
Holger Schurig10078322007-11-15 18:05:47 -05001861static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001862 struct iw_point *dwrq, char *extra)
1863{
Holger Schurig69f90322007-11-23 15:43:44 +01001864 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001865 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04001866 u8 ssid[IW_ESSID_MAX_SIZE];
1867 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001868 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001869 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001870
Holger Schurig9012b282007-05-25 11:27:16 -04001871 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001872
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001873 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001874 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001875 ret = -E2BIG;
1876 goto out;
1877 }
1878
Dan Williamsd8efea22007-05-28 23:54:55 -04001879 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001880
Dan Williamsd8efea22007-05-28 23:54:55 -04001881 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001882 /* "any" SSID requested; leave SSID blank */
1883 } else {
1884 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04001885 memcpy(&ssid, extra, in_ssid_len);
1886 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001887 }
1888
Dan Williamsd8efea22007-05-28 23:54:55 -04001889 if (!ssid_len) {
1890 lbs_deb_wext("requested any SSID\n");
1891 } else {
1892 lbs_deb_wext("requested SSID '%s'\n",
1893 escape_essid(ssid, ssid_len));
1894 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001895
1896out:
David Woodhouseaa21c002007-12-08 20:04:36 +00001897 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001898 if (ret == 0) {
1899 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00001900 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001901 if (!assoc_req) {
1902 ret = -ENOMEM;
1903 } else {
1904 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04001905 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1906 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001907 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001908 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001909 }
1910 }
1911
1912 /* Cancel the association request if there was an error */
1913 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001914 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001915 }
1916
David Woodhouseaa21c002007-12-08 20:04:36 +00001917 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001918
Holger Schurig9012b282007-05-25 11:27:16 -04001919 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001920 return ret;
1921}
1922
1923/**
1924 * @brief Connect to the AP or Ad-hoc Network with specific bssid
1925 *
1926 * @param dev A pointer to net_device structure
1927 * @param info A pointer to iw_request_info structure
1928 * @param awrq A pointer to iw_param structure
1929 * @param extra A pointer to extra data buf
1930 * @return 0 --success, otherwise fail
1931 */
Holger Schurig10078322007-11-15 18:05:47 -05001932static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001933 struct sockaddr *awrq, char *extra)
1934{
Holger Schurig69f90322007-11-23 15:43:44 +01001935 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001936 struct assoc_request * assoc_req;
1937 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07001938 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001939
Holger Schurig9012b282007-05-25 11:27:16 -04001940 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001941
1942 if (awrq->sa_family != ARPHRD_ETHER)
1943 return -EINVAL;
1944
Joe Perches0795af52007-10-03 17:59:30 -07001945 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001946
David Woodhouseaa21c002007-12-08 20:04:36 +00001947 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001948
1949 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00001950 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001951 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05001952 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001953 ret = -ENOMEM;
1954 } else {
1955 /* Copy the BSSID to the association request */
1956 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
1957 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001958 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001959 }
1960
David Woodhouseaa21c002007-12-08 20:04:36 +00001961 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001962
1963 return ret;
1964}
1965
David Woodhouseaa21c002007-12-08 20:04:36 +00001966void lbs_get_fwversion(struct lbs_private *priv, char *fwversion, int maxlen)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001967{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001968 char fwver[32];
1969
David Woodhouseaa21c002007-12-08 20:04:36 +00001970 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001971
David Woodhouseaa21c002007-12-08 20:04:36 +00001972 if (priv->fwreleasenumber[3] == 0)
David Woodhousee5b3d472007-05-25 23:40:21 -04001973 sprintf(fwver, "%u.%u.%u",
David Woodhouseaa21c002007-12-08 20:04:36 +00001974 priv->fwreleasenumber[2],
1975 priv->fwreleasenumber[1],
1976 priv->fwreleasenumber[0]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001977 else
1978 sprintf(fwver, "%u.%u.%u.p%u",
David Woodhouseaa21c002007-12-08 20:04:36 +00001979 priv->fwreleasenumber[2],
1980 priv->fwreleasenumber[1],
1981 priv->fwreleasenumber[0],
1982 priv->fwreleasenumber[3]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001983
David Woodhouseaa21c002007-12-08 20:04:36 +00001984 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001985 snprintf(fwversion, maxlen, fwver);
1986}
1987
1988
1989/*
1990 * iwconfig settable callbacks
1991 */
Holger Schurig10078322007-11-15 18:05:47 -05001992static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001993 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05001994 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001995 (iw_handler) NULL, /* SIOCSIWNWID */
1996 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05001997 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
1998 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
1999 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2000 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002001 (iw_handler) NULL, /* SIOCSIWSENS */
2002 (iw_handler) NULL, /* SIOCGIWSENS */
2003 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002004 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002005 (iw_handler) NULL, /* SIOCSIWPRIV */
2006 (iw_handler) NULL, /* SIOCGIWPRIV */
2007 (iw_handler) NULL, /* SIOCSIWSTATS */
2008 (iw_handler) NULL, /* SIOCGIWSTATS */
2009 iw_handler_set_spy, /* SIOCSIWSPY */
2010 iw_handler_get_spy, /* SIOCGIWSPY */
2011 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2012 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002013 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2014 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002015 (iw_handler) NULL, /* SIOCSIWMLME */
2016 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002017 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2018 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2019 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2020 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2021 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2022 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002023 (iw_handler) NULL, /* -- hole -- */
2024 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002025 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2026 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2027 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2028 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2029 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2030 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2031 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2032 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2033 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2034 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2035 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2036 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2037 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2038 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002039 (iw_handler) NULL, /* -- hole -- */
2040 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002041 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2042 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2043 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2044 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2045 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2046 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002047 (iw_handler) NULL, /* SIOCSIWPMKSA */
2048};
2049
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002050static const iw_handler mesh_wlan_handler[] = {
2051 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002052 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002053 (iw_handler) NULL, /* SIOCSIWNWID */
2054 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002055 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2056 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002057 (iw_handler) NULL, /* SIOCSIWMODE */
2058 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2059 (iw_handler) NULL, /* SIOCSIWSENS */
2060 (iw_handler) NULL, /* SIOCGIWSENS */
2061 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002062 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002063 (iw_handler) NULL, /* SIOCSIWPRIV */
2064 (iw_handler) NULL, /* SIOCGIWPRIV */
2065 (iw_handler) NULL, /* SIOCSIWSTATS */
2066 (iw_handler) NULL, /* SIOCGIWSTATS */
2067 iw_handler_set_spy, /* SIOCSIWSPY */
2068 iw_handler_get_spy, /* SIOCGIWSPY */
2069 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2070 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2071 (iw_handler) NULL, /* SIOCSIWAP */
2072 (iw_handler) NULL, /* SIOCGIWAP */
2073 (iw_handler) NULL, /* SIOCSIWMLME */
2074 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002075 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2076 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002077 (iw_handler) NULL, /* SIOCSIWESSID */
2078 (iw_handler) NULL, /* SIOCGIWESSID */
2079 (iw_handler) NULL, /* SIOCSIWNICKN */
2080 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2081 (iw_handler) NULL, /* -- hole -- */
2082 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002083 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2084 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2085 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2086 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2087 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2088 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2089 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2090 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2091 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2092 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2093 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2094 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2095 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2096 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002097 (iw_handler) NULL, /* -- hole -- */
2098 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002099 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2100 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2101 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2102 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2103 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2104 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002105 (iw_handler) NULL, /* SIOCSIWPMKSA */
2106};
Holger Schurig10078322007-11-15 18:05:47 -05002107struct iw_handler_def lbs_handler_def = {
2108 .num_standard = ARRAY_SIZE(lbs_handler),
2109 .standard = (iw_handler *) lbs_handler,
2110 .get_wireless_stats = lbs_get_wireless_stats,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002111};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002112
2113struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002114 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002115 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002116 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002117};