blob: 1156be53df3fd341aa312807597c9def85fb8667 [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"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019#include "wext.h"
Holger Schurig245bf202008-04-02 16:27:42 +020020#include "scan.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020021#include "assoc.h"
Dan Williams8e3c91b2007-12-11 15:50:59 -050022#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020023
24
Holger Schurig69f90322007-11-23 15:43:44 +010025static inline void lbs_postpone_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020026{
David Woodhouseaa21c002007-12-08 20:04:36 +000027 if (priv->surpriseremoved)
Holger Schurig9f9dac22007-10-26 10:12:14 +020028 return;
29 cancel_delayed_work(&priv->assoc_work);
30 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
31}
32
Javier Cardona9c31fd62008-09-11 15:32:50 -070033static inline void lbs_do_association_work(struct lbs_private *priv)
34{
35 if (priv->surpriseremoved)
36 return;
37 cancel_delayed_work(&priv->assoc_work);
38 queue_delayed_work(priv->work_thread, &priv->assoc_work, 0);
39}
40
Holger Schurig69f90322007-11-23 15:43:44 +010041static inline void lbs_cancel_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020042{
43 cancel_delayed_work(&priv->assoc_work);
David Woodhouseaa21c002007-12-08 20:04:36 +000044 kfree(priv->pending_assoc_req);
45 priv->pending_assoc_req = NULL;
Holger Schurig9f9dac22007-10-26 10:12:14 +020046}
47
48
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020049/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020050 * @brief Find the channel frequency power info with specific channel
51 *
David Woodhouseaa21c002007-12-08 20:04:36 +000052 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020053 * @param band it can be BAND_A, BAND_G or BAND_B
54 * @param channel the channel for looking
55 * @return A pointer to struct chan_freq_power structure or NULL if not find.
56 */
Holger Schurig69f90322007-11-23 15:43:44 +010057struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
David Woodhouseaa21c002007-12-08 20:04:36 +000058 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +010059 u8 band,
60 u16 channel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061{
62 struct chan_freq_power *cfp = NULL;
63 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064 int i, j;
65
David Woodhouseaa21c002007-12-08 20:04:36 +000066 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
67 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020068
David Woodhouseaa21c002007-12-08 20:04:36 +000069 if (priv->enable11d)
70 rc = &priv->universal_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020071 if (!rc->valid || !rc->CFP)
72 continue;
73 if (rc->band != band)
74 continue;
75 for (i = 0; i < rc->nrcfp; i++) {
76 if (rc->CFP[i].channel == channel) {
77 cfp = &rc->CFP[i];
78 break;
79 }
80 }
81 }
82
83 if (!cfp && channel)
Holger Schurig10078322007-11-15 18:05:47 -050084 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
Holger Schurig9012b282007-05-25 11:27:16 -040085 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020086
87 return cfp;
88}
89
90/**
91 * @brief Find the channel frequency power info with specific frequency
92 *
David Woodhouseaa21c002007-12-08 20:04:36 +000093 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020094 * @param band it can be BAND_A, BAND_G or BAND_B
95 * @param freq the frequency for looking
96 * @return A pointer to struct chan_freq_power structure or NULL if not find.
97 */
Holger Schurig69f90322007-11-23 15:43:44 +010098static struct chan_freq_power *find_cfp_by_band_and_freq(
David Woodhouseaa21c002007-12-08 20:04:36 +000099 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +0100100 u8 band,
101 u32 freq)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200102{
103 struct chan_freq_power *cfp = NULL;
104 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200105 int i, j;
106
David Woodhouseaa21c002007-12-08 20:04:36 +0000107 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
108 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200109
David Woodhouseaa21c002007-12-08 20:04:36 +0000110 if (priv->enable11d)
111 rc = &priv->universal_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200112 if (!rc->valid || !rc->CFP)
113 continue;
114 if (rc->band != band)
115 continue;
116 for (i = 0; i < rc->nrcfp; i++) {
117 if (rc->CFP[i].freq == freq) {
118 cfp = &rc->CFP[i];
119 break;
120 }
121 }
122 }
123
124 if (!cfp && freq)
Holger Schurig9012b282007-05-25 11:27:16 -0400125 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
126 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127
128 return cfp;
129}
130
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200131/**
Dan Williams8c512762007-08-02 11:40:45 -0400132 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200133 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000134 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200135 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200136 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000137static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138{
Holger Schurig9012b282007-05-25 11:27:16 -0400139 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200140
David Woodhouseaa21c002007-12-08 20:04:36 +0000141 if ((priv->connect_status != LBS_CONNECTED) &&
142 (priv->mesh_connect_status != LBS_CONNECTED))
Holger Schurig10078322007-11-15 18:05:47 -0500143 memcpy(rates, lbs_bg_rates, MAX_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400144 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000145 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200146
Dan Williams8c512762007-08-02 11:40:45 -0400147 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148}
149
Holger Schurig10078322007-11-15 18:05:47 -0500150static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200151 char *cwrq, char *extra)
152{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200153
Holger Schurig9012b282007-05-25 11:27:16 -0400154 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200155
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400156 /* We could add support for 802.11n here as needed. Jean II */
157 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158
Holger Schurig9012b282007-05-25 11:27:16 -0400159 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160 return 0;
161}
162
Holger Schurig10078322007-11-15 18:05:47 -0500163static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200164 struct iw_freq *fwrq, char *extra)
165{
Holger Schurig69f90322007-11-23 15:43:44 +0100166 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200167 struct chan_freq_power *cfp;
168
Holger Schurig9012b282007-05-25 11:27:16 -0400169 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200170
David Woodhouseaa21c002007-12-08 20:04:36 +0000171 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
172 priv->curbssparams.channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200173
174 if (!cfp) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000175 if (priv->curbssparams.channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400176 lbs_deb_wext("invalid channel %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000177 priv->curbssparams.channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200178 return -EINVAL;
179 }
180
181 fwrq->m = (long)cfp->freq * 100000;
182 fwrq->e = 1;
183
Holger Schurig9012b282007-05-25 11:27:16 -0400184 lbs_deb_wext("freq %u\n", fwrq->m);
185 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200186 return 0;
187}
188
Holger Schurig10078322007-11-15 18:05:47 -0500189static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190 struct sockaddr *awrq, char *extra)
191{
Holger Schurig69f90322007-11-23 15:43:44 +0100192 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200193
Holger Schurig9012b282007-05-25 11:27:16 -0400194 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200195
David Woodhouseaa21c002007-12-08 20:04:36 +0000196 if (priv->connect_status == LBS_CONNECTED) {
197 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200198 } else {
199 memset(awrq->sa_data, 0, ETH_ALEN);
200 }
201 awrq->sa_family = ARPHRD_ETHER;
202
Holger Schurig9012b282007-05-25 11:27:16 -0400203 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200204 return 0;
205}
206
Holger Schurig10078322007-11-15 18:05:47 -0500207static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200208 struct iw_point *dwrq, char *extra)
209{
Holger Schurig69f90322007-11-23 15:43:44 +0100210 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211
Holger Schurig9012b282007-05-25 11:27:16 -0400212 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200213
214 /*
215 * Check the size of the string
216 */
217
218 if (dwrq->length > 16) {
219 return -E2BIG;
220 }
221
David Woodhouseaa21c002007-12-08 20:04:36 +0000222 mutex_lock(&priv->lock);
223 memset(priv->nodename, 0, sizeof(priv->nodename));
224 memcpy(priv->nodename, extra, dwrq->length);
225 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226
Holger Schurig9012b282007-05-25 11:27:16 -0400227 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228 return 0;
229}
230
Holger Schurig10078322007-11-15 18:05:47 -0500231static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200232 struct iw_point *dwrq, char *extra)
233{
Holger Schurig69f90322007-11-23 15:43:44 +0100234 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235
Holger Schurig9012b282007-05-25 11:27:16 -0400236 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200237
David Woodhouseaa21c002007-12-08 20:04:36 +0000238 dwrq->length = strlen(priv->nodename);
239 memcpy(extra, priv->nodename, dwrq->length);
Holger Schurig04799fa2007-10-09 15:04:14 +0200240 extra[dwrq->length] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200241
Holger Schurig04799fa2007-10-09 15:04:14 +0200242 dwrq->flags = 1; /* active */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200243
Holger Schurig9012b282007-05-25 11:27:16 -0400244 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200245 return 0;
246}
247
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400248static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
249 struct iw_point *dwrq, char *extra)
250{
Holger Schurig69f90322007-11-23 15:43:44 +0100251 struct lbs_private *priv = dev->priv;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400252
253 lbs_deb_enter(LBS_DEB_WEXT);
254
255 /* Use nickname to indicate that mesh is on */
256
David Woodhouseaa21c002007-12-08 20:04:36 +0000257 if (priv->mesh_connect_status == LBS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400258 strncpy(extra, "Mesh", 12);
259 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400260 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400261 }
262
263 else {
264 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400265 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400266 }
267
268 lbs_deb_leave(LBS_DEB_WEXT);
269 return 0;
270}
Holger Schurig04799fa2007-10-09 15:04:14 +0200271
Holger Schurig10078322007-11-15 18:05:47 -0500272static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200273 struct iw_param *vwrq, char *extra)
274{
275 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100276 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400277 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200278
Holger Schurig9012b282007-05-25 11:27:16 -0400279 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280
Dan Williams39fcf7a2008-09-10 12:49:00 -0400281 if (vwrq->disabled)
282 val = MRVDRV_RTS_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200283
Dan Williams39fcf7a2008-09-10 12:49:00 -0400284 if (val < MRVDRV_RTS_MIN_VALUE || val > MRVDRV_RTS_MAX_VALUE)
285 return -EINVAL;
286
287 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200288
Holger Schurig9012b282007-05-25 11:27:16 -0400289 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200290 return ret;
291}
292
Holger Schurig10078322007-11-15 18:05:47 -0500293static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200294 struct iw_param *vwrq, char *extra)
295{
Holger Schurig69f90322007-11-23 15:43:44 +0100296 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400297 int ret = 0;
298 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200299
Holger Schurig9012b282007-05-25 11:27:16 -0400300 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200301
Dan Williams39fcf7a2008-09-10 12:49:00 -0400302 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400303 if (ret)
304 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200305
Dan Williams39fcf7a2008-09-10 12:49:00 -0400306 vwrq->value = val;
307 vwrq->disabled = ((val < MRVDRV_RTS_MIN_VALUE)
308 || (val > MRVDRV_RTS_MAX_VALUE));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309 vwrq->fixed = 1;
310
Holger Schurig9012b282007-05-25 11:27:16 -0400311out:
312 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
313 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314}
315
Holger Schurig10078322007-11-15 18:05:47 -0500316static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317 struct iw_param *vwrq, char *extra)
318{
Holger Schurig69f90322007-11-23 15:43:44 +0100319 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400320 int ret = 0;
321 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200322
Holger Schurig9012b282007-05-25 11:27:16 -0400323 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324
Dan Williams39fcf7a2008-09-10 12:49:00 -0400325 if (vwrq->disabled)
326 val = MRVDRV_FRAG_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200327
Dan Williams39fcf7a2008-09-10 12:49:00 -0400328 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
329 return -EINVAL;
330
331 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
Holger Schurig9012b282007-05-25 11:27:16 -0400332
333 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334 return ret;
335}
336
Holger Schurig10078322007-11-15 18:05:47 -0500337static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338 struct iw_param *vwrq, char *extra)
339{
Holger Schurig69f90322007-11-23 15:43:44 +0100340 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400341 int ret = 0;
342 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343
Holger Schurig9012b282007-05-25 11:27:16 -0400344 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200345
Dan Williams39fcf7a2008-09-10 12:49:00 -0400346 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400347 if (ret)
348 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349
Dan Williams39fcf7a2008-09-10 12:49:00 -0400350 vwrq->value = val;
351 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
352 || (val > MRVDRV_FRAG_MAX_VALUE));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353 vwrq->fixed = 1;
354
Holger Schurig9012b282007-05-25 11:27:16 -0400355out:
356 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357 return ret;
358}
359
Holger Schurig10078322007-11-15 18:05:47 -0500360static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200361 struct iw_request_info *info, u32 * uwrq, char *extra)
362{
Holger Schurig69f90322007-11-23 15:43:44 +0100363 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364
Holger Schurig9012b282007-05-25 11:27:16 -0400365 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200366
David Woodhouseaa21c002007-12-08 20:04:36 +0000367 *uwrq = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200368
Holger Schurig9012b282007-05-25 11:27:16 -0400369 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370 return 0;
371}
372
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400373static int mesh_wlan_get_mode(struct net_device *dev,
374 struct iw_request_info *info, u32 * uwrq,
375 char *extra)
376{
377 lbs_deb_enter(LBS_DEB_WEXT);
378
Dan Williams39fcf7a2008-09-10 12:49:00 -0400379 *uwrq = IW_MODE_REPEAT;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400380
381 lbs_deb_leave(LBS_DEB_WEXT);
382 return 0;
383}
384
Holger Schurig10078322007-11-15 18:05:47 -0500385static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386 struct iw_request_info *info,
387 struct iw_param *vwrq, char *extra)
388{
Holger Schurig69f90322007-11-23 15:43:44 +0100389 struct lbs_private *priv = dev->priv;
Dan Williams87c8c722008-08-19 15:15:35 -0400390 s16 curlevel = 0;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400391 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392
Holger Schurig9012b282007-05-25 11:27:16 -0400393 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200394
Dan Williamsd5db2df2008-08-21 17:51:07 -0400395 if (!priv->radio_on) {
396 lbs_deb_wext("tx power off\n");
397 vwrq->value = 0;
398 vwrq->disabled = 1;
399 goto out;
400 }
401
Dan Williams87c8c722008-08-19 15:15:35 -0400402 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400403 if (ret)
404 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200405
Dan Williams87c8c722008-08-19 15:15:35 -0400406 lbs_deb_wext("tx power level %d dbm\n", curlevel);
Dan Williams87c8c722008-08-19 15:15:35 -0400407 priv->txpower_cur = curlevel;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400408
Dan Williams87c8c722008-08-19 15:15:35 -0400409 vwrq->value = curlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410 vwrq->fixed = 1;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400411 vwrq->disabled = 0;
412 vwrq->flags = IW_TXPOW_DBM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413
Holger Schurig9012b282007-05-25 11:27:16 -0400414out:
415 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
416 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417}
418
Holger Schurig10078322007-11-15 18:05:47 -0500419static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200420 struct iw_param *vwrq, char *extra)
421{
Holger Schurig69f90322007-11-23 15:43:44 +0100422 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400423 int ret = 0;
424 u16 slimit = 0, llimit = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425
Holger Schurig9012b282007-05-25 11:27:16 -0400426 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200427
Dan Williams39fcf7a2008-09-10 12:49:00 -0400428 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
429 return -EOPNOTSUPP;
430
431 /* The MAC has a 4-bit Total_Tx_Count register
432 Total_Tx_Count = 1 + Tx_Retry_Count */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433#define TX_RETRY_MIN 0
434#define TX_RETRY_MAX 14
Dan Williams39fcf7a2008-09-10 12:49:00 -0400435 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
436 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437
Dan Williams39fcf7a2008-09-10 12:49:00 -0400438 /* Add 1 to convert retry count to try count */
439 if (vwrq->flags & IW_RETRY_SHORT)
440 slimit = (u16) (vwrq->value + 1);
441 else if (vwrq->flags & IW_RETRY_LONG)
442 llimit = (u16) (vwrq->value + 1);
443 else
444 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200445
Dan Williams39fcf7a2008-09-10 12:49:00 -0400446 if (llimit) {
447 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
448 llimit);
Holger Schurig9012b282007-05-25 11:27:16 -0400449 if (ret)
450 goto out;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400451 }
452
453 if (slimit) {
454 /* txretrycount follows the short retry limit */
455 priv->txretrycount = slimit;
456 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
457 slimit);
458 if (ret)
459 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200460 }
461
Holger Schurig9012b282007-05-25 11:27:16 -0400462out:
463 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
464 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200465}
466
Holger Schurig10078322007-11-15 18:05:47 -0500467static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468 struct iw_param *vwrq, char *extra)
469{
Holger Schurig69f90322007-11-23 15:43:44 +0100470 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200471 int ret = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400472 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200473
Holger Schurig9012b282007-05-25 11:27:16 -0400474 lbs_deb_enter(LBS_DEB_WEXT);
475
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 vwrq->disabled = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400477
478 if (vwrq->flags & IW_RETRY_LONG) {
479 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
480 if (ret)
481 goto out;
482
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483 /* Subtract 1 to convert try count to retry count */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400484 vwrq->value = val - 1;
485 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
486 } else {
487 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
488 if (ret)
489 goto out;
490
491 /* txretry count follows the short retry limit */
492 priv->txretrycount = val;
493 /* Subtract 1 to convert try count to retry count */
494 vwrq->value = val - 1;
495 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496 }
497
Holger Schurig9012b282007-05-25 11:27:16 -0400498out:
499 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
500 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501}
502
503static inline void sort_channels(struct iw_freq *freq, int num)
504{
505 int i, j;
506 struct iw_freq temp;
507
508 for (i = 0; i < num; i++)
509 for (j = i + 1; j < num; j++)
510 if (freq[i].i > freq[j].i) {
511 temp.i = freq[i].i;
512 temp.m = freq[i].m;
513
514 freq[i].i = freq[j].i;
515 freq[i].m = freq[j].m;
516
517 freq[j].i = temp.i;
518 freq[j].m = temp.m;
519 }
520}
521
522/* data rate listing
523 MULTI_BANDS:
524 abg a b b/g
525 Infra G(12) A(8) B(4) G(12)
526 Adhoc A+B(12) A(8) B(4) B(4)
527
528 non-MULTI_BANDS:
529 b b/g
530 Infra B(4) G(12)
531 Adhoc B(4) B(4)
532 */
533/**
534 * @brief Get Range Info
535 *
536 * @param dev A pointer to net_device structure
537 * @param info A pointer to iw_request_info structure
538 * @param vwrq A pointer to iw_param structure
539 * @param extra A pointer to extra data buf
540 * @return 0 --success, otherwise fail
541 */
Holger Schurig10078322007-11-15 18:05:47 -0500542static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200543 struct iw_point *dwrq, char *extra)
544{
545 int i, j;
Holger Schurig69f90322007-11-23 15:43:44 +0100546 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547 struct iw_range *range = (struct iw_range *)extra;
548 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400549 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200550
551 u8 flag = 0;
552
Holger Schurig9012b282007-05-25 11:27:16 -0400553 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200554
555 dwrq->length = sizeof(struct iw_range);
556 memset(range, 0, sizeof(struct iw_range));
557
558 range->min_nwid = 0;
559 range->max_nwid = 0;
560
561 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000562 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400563 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
564 for (i = 0; i < range->num_bitrates; i++)
565 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200566 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400567 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568 range->num_bitrates);
569
570 range->num_frequency = 0;
Holger Schurig52933d82008-03-05 07:05:32 +0100571
572 range->scan_capa = IW_SCAN_CAPA_ESSID;
573
David Woodhouseaa21c002007-12-08 20:04:36 +0000574 if (priv->enable11d &&
575 (priv->connect_status == LBS_CONNECTED ||
576 priv->mesh_connect_status == LBS_CONNECTED)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200577 u8 chan_no;
578 u8 band;
579
580 struct parsed_region_chan_11d *parsed_region_chan =
David Woodhouseaa21c002007-12-08 20:04:36 +0000581 &priv->parsed_region_chan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200582
583 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400584 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
585 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200586 }
587 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400588 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200589 parsed_region_chan->nr_chan);
590
591 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
592 && (i < parsed_region_chan->nr_chan); i++) {
593 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400594 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200595 range->freq[range->num_frequency].i = (long)chan_no;
596 range->freq[range->num_frequency].m =
Holger Schurige98a88d2008-03-19 14:25:58 +0100597 (long)lbs_chan_2_freq(chan_no) * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200598 range->freq[range->num_frequency].e = 1;
599 range->num_frequency++;
600 }
601 flag = 1;
602 }
603 if (!flag) {
604 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000605 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
606 cfp = priv->region_channel[j].CFP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200607 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000608 && priv->region_channel[j].valid
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609 && cfp
David Woodhouseaa21c002007-12-08 20:04:36 +0000610 && (i < priv->region_channel[j].nrcfp); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611 range->freq[range->num_frequency].i =
612 (long)cfp->channel;
613 range->freq[range->num_frequency].m =
614 (long)cfp->freq * 100000;
615 range->freq[range->num_frequency].e = 1;
616 cfp++;
617 range->num_frequency++;
618 }
619 }
620 }
621
Holger Schurig9012b282007-05-25 11:27:16 -0400622 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623 IW_MAX_FREQUENCIES, range->num_frequency);
624
625 range->num_channels = range->num_frequency;
626
627 sort_channels(&range->freq[0], range->num_frequency);
628
629 /*
630 * Set an indication of the max TCP throughput in bit/s that we can
631 * expect using this interface
632 */
633 if (i > 2)
634 range->throughput = 5000 * 1000;
635 else
636 range->throughput = 1500 * 1000;
637
638 range->min_rts = MRVDRV_RTS_MIN_VALUE;
639 range->max_rts = MRVDRV_RTS_MAX_VALUE;
640 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
641 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
642
643 range->encoding_size[0] = 5;
644 range->encoding_size[1] = 13;
645 range->num_encoding_sizes = 2;
646 range->max_encoding_tokens = 4;
647
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100648 /*
649 * Right now we support only "iwconfig ethX power on|off"
650 */
651 range->pm_capa = IW_POWER_ON;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200652
653 /*
654 * Minimum version we recommend
655 */
656 range->we_version_source = 15;
657
658 /*
659 * Version we are compiled with
660 */
661 range->we_version_compiled = WIRELESS_EXT;
662
663 range->retry_capa = IW_RETRY_LIMIT;
664 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
665
666 range->min_retry = TX_RETRY_MIN;
667 range->max_retry = TX_RETRY_MAX;
668
669 /*
670 * Set the qual, level and noise range values
671 */
672 range->max_qual.qual = 100;
673 range->max_qual.level = 0;
674 range->max_qual.noise = 0;
675 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
676
677 range->avg_qual.qual = 70;
678 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
679 range->avg_qual.level = 0;
680 range->avg_qual.noise = 0;
681 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
682
683 range->sensitivity = 0;
684
Dan Williams87c8c722008-08-19 15:15:35 -0400685 /* Setup the supported power level ranges */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200686 memset(range->txpower, 0, sizeof(range->txpower));
Dan Williams87c8c722008-08-19 15:15:35 -0400687 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
688 range->txpower[0] = priv->txpower_min;
689 range->txpower[1] = priv->txpower_max;
690 range->num_txpower = 2;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200691
692 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
693 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
694 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
695 range->event_capa[1] = IW_EVENT_CAPA_K_1;
696
David Woodhouseaa21c002007-12-08 20:04:36 +0000697 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200698 range->enc_capa = IW_ENC_CAPA_WPA
699 | IW_ENC_CAPA_WPA2
700 | IW_ENC_CAPA_CIPHER_TKIP
701 | IW_ENC_CAPA_CIPHER_CCMP;
702 }
703
Holger Schurig9012b282007-05-25 11:27:16 -0400704out:
705 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200706 return 0;
707}
708
Holger Schurig10078322007-11-15 18:05:47 -0500709static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200710 struct iw_param *vwrq, char *extra)
711{
Holger Schurig69f90322007-11-23 15:43:44 +0100712 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200713
Holger Schurig9012b282007-05-25 11:27:16 -0400714 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715
David Woodhouseb2c57ee2007-12-17 14:41:13 -0500716 if (!priv->ps_supported) {
717 if (vwrq->disabled)
718 return 0;
719 else
720 return -EINVAL;
721 }
722
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200723 /* PS is currently supported only in Infrastructure mode
724 * Remove this check if it is to be supported in IBSS mode also
725 */
726
727 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000728 priv->psmode = LBS802_11POWERMODECAM;
729 if (priv->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500730 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731 }
732
733 return 0;
734 }
735
736 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400737 lbs_deb_wext(
738 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200739 return -EINVAL;
740 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400741 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200742 return -EINVAL;
743 }
744
David Woodhouseaa21c002007-12-08 20:04:36 +0000745 if (priv->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200746 return 0;
747 }
748
David Woodhouseaa21c002007-12-08 20:04:36 +0000749 priv->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200750
David Woodhouseaa21c002007-12-08 20:04:36 +0000751 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500752 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200753 }
754
Holger Schurig9012b282007-05-25 11:27:16 -0400755 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200756 return 0;
757}
758
Holger Schurig10078322007-11-15 18:05:47 -0500759static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200760 struct iw_param *vwrq, char *extra)
761{
Holger Schurig69f90322007-11-23 15:43:44 +0100762 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200763
Holger Schurig9012b282007-05-25 11:27:16 -0400764 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200765
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200766 vwrq->value = 0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100767 vwrq->flags = 0;
768 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
769 || priv->connect_status == LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200770
Holger Schurig9012b282007-05-25 11:27:16 -0400771 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200772 return 0;
773}
774
Holger Schurig10078322007-11-15 18:05:47 -0500775static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200776{
777 enum {
778 POOR = 30,
779 FAIR = 60,
780 GOOD = 80,
781 VERY_GOOD = 90,
782 EXCELLENT = 95,
783 PERFECT = 100
784 };
Holger Schurig69f90322007-11-23 15:43:44 +0100785 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200786 u32 rssi_qual;
787 u32 tx_qual;
788 u32 quality = 0;
789 int stats_valid = 0;
790 u8 rssi;
791 u32 tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100792 struct cmd_ds_802_11_get_log log;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793
Holger Schurig9012b282007-05-25 11:27:16 -0400794 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200795
David Woodhouseaa21c002007-12-08 20:04:36 +0000796 priv->wstats.status = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200797
798 /* If we're not associated, all quality values are meaningless */
David Woodhouseaa21c002007-12-08 20:04:36 +0000799 if ((priv->connect_status != LBS_CONNECTED) &&
800 (priv->mesh_connect_status != LBS_CONNECTED))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801 goto out;
802
803 /* Quality by RSSI */
804 priv->wstats.qual.level =
David Woodhouseaa21c002007-12-08 20:04:36 +0000805 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
806 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200807
David Woodhouseaa21c002007-12-08 20:04:36 +0000808 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200809 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
810 } else {
811 priv->wstats.qual.noise =
David Woodhouseaa21c002007-12-08 20:04:36 +0000812 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813 }
814
Holger Schurig9012b282007-05-25 11:27:16 -0400815 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
816 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200817
818 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
819 if (rssi < 15)
820 rssi_qual = rssi * POOR / 10;
821 else if (rssi < 20)
822 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
823 else if (rssi < 30)
824 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
825 else if (rssi < 40)
826 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
827 10 + GOOD;
828 else
829 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
830 10 + VERY_GOOD;
831 quality = rssi_qual;
832
833 /* Quality by TX errors */
834 priv->wstats.discard.retries = priv->stats.tx_errors;
835
Holger Schurigc49c3b72008-03-17 12:45:58 +0100836 memset(&log, 0, sizeof(log));
837 log.hdr.size = cpu_to_le16(sizeof(log));
838 lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
839
840 tx_retries = le32_to_cpu(log.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200841
842 if (tx_retries > 75)
843 tx_qual = (90 - tx_retries) * POOR / 15;
844 else if (tx_retries > 70)
845 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
846 else if (tx_retries > 65)
847 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
848 else if (tx_retries > 50)
849 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
850 15 + GOOD;
851 else
852 tx_qual = (50 - tx_retries) *
853 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
854 quality = min(quality, tx_qual);
855
Holger Schurigc49c3b72008-03-17 12:45:58 +0100856 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200857 priv->wstats.discard.retries = tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100858 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200859
860 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400861 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200862 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
863 stats_valid = 1;
864
865 /* update stats asynchronously for future calls */
Holger Schurig10078322007-11-15 18:05:47 -0500866 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200867 0, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200868out:
869 if (!stats_valid) {
870 priv->wstats.miss.beacon = 0;
871 priv->wstats.discard.retries = 0;
872 priv->wstats.qual.qual = 0;
873 priv->wstats.qual.level = 0;
874 priv->wstats.qual.noise = 0;
875 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
876 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
877 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
878 }
879
Holger Schurig9012b282007-05-25 11:27:16 -0400880 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200881 return &priv->wstats;
882
883
884}
885
Holger Schurig10078322007-11-15 18:05:47 -0500886static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200887 struct iw_freq *fwrq, char *extra)
888{
Dan Williamsef9a2642007-05-25 16:46:33 -0400889 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +0100890 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200891 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400892 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200893
Holger Schurig9012b282007-05-25 11:27:16 -0400894 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200895
David Woodhouseaa21c002007-12-08 20:04:36 +0000896 mutex_lock(&priv->lock);
897 assoc_req = lbs_get_association_request(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400898 if (!assoc_req) {
899 ret = -ENOMEM;
900 goto out;
901 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200902
Dan Williamsef9a2642007-05-25 16:46:33 -0400903 /* If setting by frequency, convert to a channel */
904 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200906
David Woodhouseaa21c002007-12-08 20:04:36 +0000907 cfp = find_cfp_by_band_and_freq(priv, 0, f);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200908 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400909 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400910 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200911 }
912
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200913 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400914 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200915 }
916
Dan Williamsef9a2642007-05-25 16:46:33 -0400917 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200918 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400919 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200920 }
921
David Woodhouseaa21c002007-12-08 20:04:36 +0000922 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400923 if (!cfp) {
924 goto out;
925 }
926
927 assoc_req->channel = fwrq->m;
928 ret = 0;
929
Holger Schurig9012b282007-05-25 11:27:16 -0400930out:
Dan Williamsef9a2642007-05-25 16:46:33 -0400931 if (ret == 0) {
932 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500933 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400934 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500935 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400936 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000937 mutex_unlock(&priv->lock);
Dan Williamsef9a2642007-05-25 16:46:33 -0400938
939 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
940 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200941}
942
David Woodhouse823eaa22007-12-11 19:56:28 -0500943static int lbs_mesh_set_freq(struct net_device *dev,
944 struct iw_request_info *info,
945 struct iw_freq *fwrq, char *extra)
946{
947 struct lbs_private *priv = dev->priv;
948 struct chan_freq_power *cfp;
949 int ret = -EINVAL;
950
951 lbs_deb_enter(LBS_DEB_WEXT);
952
953 /* If setting by frequency, convert to a channel */
954 if (fwrq->e == 1) {
955 long f = fwrq->m / 100000;
956
957 cfp = find_cfp_by_band_and_freq(priv, 0, f);
958 if (!cfp) {
959 lbs_deb_wext("invalid freq %ld\n", f);
960 goto out;
961 }
962
963 fwrq->e = 0;
964 fwrq->m = (int) cfp->channel;
965 }
966
967 /* Setting by channel number */
968 if (fwrq->m > 1000 || fwrq->e > 0) {
969 goto out;
970 }
971
972 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
973 if (!cfp) {
974 goto out;
975 }
976
977 if (fwrq->m != priv->curbssparams.channel) {
978 lbs_deb_wext("mesh channel change forces eth disconnect\n");
979 if (priv->mode == IW_MODE_INFRA)
Dan Williams191bb402008-08-21 17:46:18 -0400980 lbs_cmd_80211_deauthenticate(priv,
981 priv->curbssparams.bssid,
982 WLAN_REASON_DEAUTH_LEAVING);
David Woodhouse823eaa22007-12-11 19:56:28 -0500983 else if (priv->mode == IW_MODE_ADHOC)
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400984 lbs_adhoc_stop(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -0500985 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700986 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
David Woodhouse86062132007-12-13 00:32:36 -0500987 lbs_update_channel(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -0500988 ret = 0;
989
990out:
991 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
992 return ret;
993}
994
Holger Schurig10078322007-11-15 18:05:47 -0500995static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200996 struct iw_param *vwrq, char *extra)
997{
Holger Schurig69f90322007-11-23 15:43:44 +0100998 struct lbs_private *priv = dev->priv;
Dan Williams8e3c91b2007-12-11 15:50:59 -0500999 u8 new_rate = 0;
Dan Williams8c512762007-08-02 11:40:45 -04001000 int ret = -EINVAL;
1001 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001002
Holger Schurig9012b282007-05-25 11:27:16 -04001003 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -04001004 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Javier Cardona85319f92008-05-24 10:59:49 +01001005 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1006
1007 if (vwrq->fixed && vwrq->value == -1)
1008 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001009
Dan Williams8c512762007-08-02 11:40:45 -04001010 /* Auto rate? */
Javier Cardona85319f92008-05-24 10:59:49 +01001011 priv->enablehwauto = !vwrq->fixed;
1012
1013 if (vwrq->value == -1)
David Woodhouseaa21c002007-12-08 20:04:36 +00001014 priv->cur_rate = 0;
Javier Cardona85319f92008-05-24 10:59:49 +01001015 else {
Dan Williams8c512762007-08-02 11:40:45 -04001016 if (vwrq->value % 100000)
1017 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001018
Javier Cardona85319f92008-05-24 10:59:49 +01001019 new_rate = vwrq->value / 500000;
1020 priv->cur_rate = new_rate;
1021 /* the rest is only needed for lbs_set_data_rate() */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001022 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +00001023 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -04001024 if (!memchr(rates, new_rate, sizeof(rates))) {
1025 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1026 new_rate);
1027 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001028 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029 }
1030
Javier Cardona85319f92008-05-24 10:59:49 +01001031 /* Try the newer command first (Firmware Spec 5.1 and above) */
1032 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1033
1034 /* Fallback to older version */
1035 if (ret)
1036 ret = lbs_set_data_rate(priv, new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037
Dan Williams8c512762007-08-02 11:40:45 -04001038out:
Holger Schurig9012b282007-05-25 11:27:16 -04001039 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001040 return ret;
1041}
1042
Holger Schurig10078322007-11-15 18:05:47 -05001043static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001044 struct iw_param *vwrq, char *extra)
1045{
Holger Schurig69f90322007-11-23 15:43:44 +01001046 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001047
Holger Schurig9012b282007-05-25 11:27:16 -04001048 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001049
David Woodhouseaa21c002007-12-08 20:04:36 +00001050 if (priv->connect_status == LBS_CONNECTED) {
1051 vwrq->value = priv->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001052
Javier Cardona85319f92008-05-24 10:59:49 +01001053 if (priv->enablehwauto)
Dan Williams8c512762007-08-02 11:40:45 -04001054 vwrq->fixed = 0;
1055 else
1056 vwrq->fixed = 1;
1057
1058 } else {
1059 vwrq->fixed = 0;
1060 vwrq->value = 0;
1061 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001062
Holger Schurig9012b282007-05-25 11:27:16 -04001063 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064 return 0;
1065}
1066
Holger Schurig10078322007-11-15 18:05:47 -05001067static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001068 struct iw_request_info *info, u32 * uwrq, char *extra)
1069{
1070 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001071 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001072 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001073
Holger Schurig9012b282007-05-25 11:27:16 -04001074 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001075
Dan Williams0dc5a292007-05-10 22:58:02 -04001076 if ( (*uwrq != IW_MODE_ADHOC)
1077 && (*uwrq != IW_MODE_INFRA)
1078 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001079 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001080 ret = -EINVAL;
1081 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001082 }
1083
David Woodhouseaa21c002007-12-08 20:04:36 +00001084 mutex_lock(&priv->lock);
1085 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001086 if (!assoc_req) {
1087 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001088 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001089 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001090 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001091 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001092 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001093 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001094 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001095 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001096
Dan Williams0dc5a292007-05-10 22:58:02 -04001097out:
Holger Schurig9012b282007-05-25 11:27:16 -04001098 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001099 return ret;
1100}
1101
1102
1103/**
1104 * @brief Get Encryption key
1105 *
1106 * @param dev A pointer to net_device structure
1107 * @param info A pointer to iw_request_info structure
1108 * @param vwrq A pointer to iw_param structure
1109 * @param extra A pointer to extra data buf
1110 * @return 0 --success, otherwise fail
1111 */
Holger Schurig10078322007-11-15 18:05:47 -05001112static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001113 struct iw_request_info *info,
1114 struct iw_point *dwrq, u8 * extra)
1115{
Holger Schurig69f90322007-11-23 15:43:44 +01001116 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001117 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1118
Holger Schurig9012b282007-05-25 11:27:16 -04001119 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001120
Holger Schurig9012b282007-05-25 11:27:16 -04001121 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001122 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001123
1124 dwrq->flags = 0;
1125
1126 /* Authentication method */
David Woodhouseaa21c002007-12-08 20:04:36 +00001127 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -04001128 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001129 dwrq->flags = IW_ENCODE_OPEN;
1130 break;
1131
Dan Williams6affe782007-05-10 22:56:42 -04001132 case IW_AUTH_ALG_SHARED_KEY:
1133 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001134 dwrq->flags = IW_ENCODE_RESTRICTED;
1135 break;
1136 default:
1137 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1138 break;
1139 }
1140
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001141 memset(extra, 0, 16);
1142
David Woodhouseaa21c002007-12-08 20:04:36 +00001143 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001144
1145 /* Default to returning current transmit key */
1146 if (index < 0)
David Woodhouseaa21c002007-12-08 20:04:36 +00001147 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001148
David Woodhouseaa21c002007-12-08 20:04:36 +00001149 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1150 memcpy(extra, priv->wep_keys[index].key,
1151 priv->wep_keys[index].len);
1152 dwrq->length = priv->wep_keys[index].len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001153
1154 dwrq->flags |= (index + 1);
1155 /* Return WEP enabled */
1156 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhouseaa21c002007-12-08 20:04:36 +00001157 } else if ((priv->secinfo.WPAenabled)
1158 || (priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001159 /* return WPA enabled */
1160 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhousec12bdc42007-12-07 19:32:12 +00001161 dwrq->flags |= IW_ENCODE_NOKEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001162 } else {
1163 dwrq->flags |= IW_ENCODE_DISABLED;
1164 }
1165
David Woodhouseaa21c002007-12-08 20:04:36 +00001166 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001167
Joe Perches0795af52007-10-03 17:59:30 -07001168 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001169 extra[0], extra[1], extra[2],
1170 extra[3], extra[4], extra[5], dwrq->length);
1171
Holger Schurig9012b282007-05-25 11:27:16 -04001172 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001173
Holger Schurig9012b282007-05-25 11:27:16 -04001174 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001175 return 0;
1176}
1177
1178/**
1179 * @brief Set Encryption key (internal)
1180 *
1181 * @param priv A pointer to private card structure
1182 * @param key_material A pointer to key material
1183 * @param key_length length of key material
1184 * @param index key index to set
1185 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1186 * @return 0 --success, otherwise fail
1187 */
Holger Schurig10078322007-11-15 18:05:47 -05001188static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001189 const char *key_material,
1190 u16 key_length,
1191 u16 index,
1192 int set_tx_key)
1193{
Holger Schurig9012b282007-05-25 11:27:16 -04001194 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001195 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001196
Holger Schurig9012b282007-05-25 11:27:16 -04001197 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001198
1199 /* Paranoid validation of key index */
1200 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001201 ret = -EINVAL;
1202 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001203 }
1204
1205 /* validate max key length */
1206 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001207 ret = -EINVAL;
1208 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001209 }
1210
1211 pkey = &assoc_req->wep_keys[index];
1212
1213 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001214 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001215 pkey->type = KEY_TYPE_ID_WEP;
1216
1217 /* Standardize the key length */
1218 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1219 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1220 memcpy(pkey->key, key_material, key_length);
1221 }
1222
1223 if (set_tx_key) {
1224 /* Ensure the chosen key is valid */
1225 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001226 lbs_deb_wext("key not set, so cannot enable it\n");
1227 ret = -EINVAL;
1228 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001229 }
1230 assoc_req->wep_tx_keyidx = index;
1231 }
1232
Dan Williams889c05b2007-05-10 22:57:23 -04001233 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001234
Holger Schurig9012b282007-05-25 11:27:16 -04001235out:
1236 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1237 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001238}
1239
1240static int validate_key_index(u16 def_index, u16 raw_index,
1241 u16 *out_index, u16 *is_default)
1242{
1243 if (!out_index || !is_default)
1244 return -EINVAL;
1245
1246 /* Verify index if present, otherwise use default TX key index */
1247 if (raw_index > 0) {
1248 if (raw_index > 4)
1249 return -EINVAL;
1250 *out_index = raw_index - 1;
1251 } else {
1252 *out_index = def_index;
1253 *is_default = 1;
1254 }
1255 return 0;
1256}
1257
1258static void disable_wep(struct assoc_request *assoc_req)
1259{
1260 int i;
1261
Dan Williams90a42212007-05-25 23:01:24 -04001262 lbs_deb_enter(LBS_DEB_WEXT);
1263
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001264 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001265 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001266
1267 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001268 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001269 for (i = 0; i < 4; i++)
1270 assoc_req->wep_keys[i].len = 0;
1271
1272 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1273 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001274
1275 lbs_deb_leave(LBS_DEB_WEXT);
1276}
1277
1278static void disable_wpa(struct assoc_request *assoc_req)
1279{
1280 lbs_deb_enter(LBS_DEB_WEXT);
1281
Dan Williams1443b652007-08-02 10:45:55 -04001282 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001283 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1284 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1285
Dan Williams1443b652007-08-02 10:45:55 -04001286 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001287 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1288 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1289
1290 assoc_req->secinfo.WPAenabled = 0;
1291 assoc_req->secinfo.WPA2enabled = 0;
1292 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1293
1294 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001295}
1296
1297/**
1298 * @brief Set Encryption key
1299 *
1300 * @param dev A pointer to net_device structure
1301 * @param info A pointer to iw_request_info structure
1302 * @param vwrq A pointer to iw_param structure
1303 * @param extra A pointer to extra data buf
1304 * @return 0 --success, otherwise fail
1305 */
Holger Schurig10078322007-11-15 18:05:47 -05001306static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001307 struct iw_request_info *info,
1308 struct iw_point *dwrq, char *extra)
1309{
1310 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001311 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001312 struct assoc_request * assoc_req;
1313 u16 is_default = 0, index = 0, set_tx_key = 0;
1314
Holger Schurig9012b282007-05-25 11:27:16 -04001315 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001316
David Woodhouseaa21c002007-12-08 20:04:36 +00001317 mutex_lock(&priv->lock);
1318 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001319 if (!assoc_req) {
1320 ret = -ENOMEM;
1321 goto out;
1322 }
1323
1324 if (dwrq->flags & IW_ENCODE_DISABLED) {
1325 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001326 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001327 goto out;
1328 }
1329
1330 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1331 (dwrq->flags & IW_ENCODE_INDEX),
1332 &index, &is_default);
1333 if (ret) {
1334 ret = -EINVAL;
1335 goto out;
1336 }
1337
1338 /* If WEP isn't enabled, or if there is no key data but a valid
1339 * index, set the TX key.
1340 */
Dan Williams889c05b2007-05-10 22:57:23 -04001341 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001342 set_tx_key = 1;
1343
Holger Schurig10078322007-11-15 18:05:47 -05001344 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001345 if (ret)
1346 goto out;
1347
1348 if (dwrq->length)
1349 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1350 if (set_tx_key)
1351 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1352
1353 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001354 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001355 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001356 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001357 }
1358
1359out:
1360 if (ret == 0) {
1361 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001362 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001363 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001364 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001365 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001366 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367
Holger Schurig9012b282007-05-25 11:27:16 -04001368 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001369 return ret;
1370}
1371
1372/**
1373 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1374 *
1375 * @param dev A pointer to net_device structure
1376 * @param info A pointer to iw_request_info structure
1377 * @param vwrq A pointer to iw_param structure
1378 * @param extra A pointer to extra data buf
1379 * @return 0 on success, otherwise failure
1380 */
Holger Schurig10078322007-11-15 18:05:47 -05001381static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001382 struct iw_request_info *info,
1383 struct iw_point *dwrq,
1384 char *extra)
1385{
1386 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +01001387 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001388 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1389 int index, max_key_len;
1390
Holger Schurig9012b282007-05-25 11:27:16 -04001391 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001392
1393 max_key_len = dwrq->length - sizeof(*ext);
1394 if (max_key_len < 0)
1395 goto out;
1396
1397 index = dwrq->flags & IW_ENCODE_INDEX;
1398 if (index) {
1399 if (index < 1 || index > 4)
1400 goto out;
1401 index--;
1402 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001403 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001404 }
1405
Roel Kluinf59d9782007-10-26 21:51:26 +02001406 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001407 ext->alg != IW_ENCODE_ALG_WEP) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001408 if (index != 0 || priv->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001409 goto out;
1410 }
1411
1412 dwrq->flags = index + 1;
1413 memset(ext, 0, sizeof(*ext));
1414
David Woodhouseaa21c002007-12-08 20:04:36 +00001415 if ( !priv->secinfo.wep_enabled
1416 && !priv->secinfo.WPAenabled
1417 && !priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001418 ext->alg = IW_ENCODE_ALG_NONE;
1419 ext->key_len = 0;
1420 dwrq->flags |= IW_ENCODE_DISABLED;
1421 } else {
1422 u8 *key = NULL;
1423
David Woodhouseaa21c002007-12-08 20:04:36 +00001424 if ( priv->secinfo.wep_enabled
1425 && !priv->secinfo.WPAenabled
1426 && !priv->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001427 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001428 ext->alg = IW_ENCODE_ALG_WEP;
David Woodhouseaa21c002007-12-08 20:04:36 +00001429 ext->key_len = priv->wep_keys[index].len;
1430 key = &priv->wep_keys[index].key[0];
1431 } else if ( !priv->secinfo.wep_enabled
1432 && (priv->secinfo.WPAenabled ||
1433 priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001434 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001435 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001436
David Woodhouseaa21c002007-12-08 20:04:36 +00001437 if ( priv->wpa_mcast_key.len
1438 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1439 pkey = &priv->wpa_mcast_key;
1440 else if ( priv->wpa_unicast_key.len
1441 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1442 pkey = &priv->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001443
1444 if (pkey) {
1445 if (pkey->type == KEY_TYPE_ID_AES) {
1446 ext->alg = IW_ENCODE_ALG_CCMP;
1447 } else {
1448 ext->alg = IW_ENCODE_ALG_TKIP;
1449 }
1450 ext->key_len = pkey->len;
1451 key = &pkey->key[0];
1452 } else {
1453 ext->alg = IW_ENCODE_ALG_TKIP;
1454 ext->key_len = 0;
1455 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001456 } else {
1457 goto out;
1458 }
1459
1460 if (ext->key_len > max_key_len) {
1461 ret = -E2BIG;
1462 goto out;
1463 }
1464
1465 if (ext->key_len)
1466 memcpy(ext->key, key, ext->key_len);
1467 else
1468 dwrq->flags |= IW_ENCODE_NOKEY;
1469 dwrq->flags |= IW_ENCODE_ENABLED;
1470 }
1471 ret = 0;
1472
1473out:
Holger Schurig9012b282007-05-25 11:27:16 -04001474 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001475 return ret;
1476}
1477
1478/**
1479 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1480 *
1481 * @param dev A pointer to net_device structure
1482 * @param info A pointer to iw_request_info structure
1483 * @param vwrq A pointer to iw_param structure
1484 * @param extra A pointer to extra data buf
1485 * @return 0 --success, otherwise fail
1486 */
Holger Schurig10078322007-11-15 18:05:47 -05001487static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001488 struct iw_request_info *info,
1489 struct iw_point *dwrq,
1490 char *extra)
1491{
1492 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001493 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001494 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1495 int alg = ext->alg;
1496 struct assoc_request * assoc_req;
1497
Holger Schurig9012b282007-05-25 11:27:16 -04001498 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001499
David Woodhouseaa21c002007-12-08 20:04:36 +00001500 mutex_lock(&priv->lock);
1501 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001502 if (!assoc_req) {
1503 ret = -ENOMEM;
1504 goto out;
1505 }
1506
1507 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1508 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001509 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001510 } else if (alg == IW_ENCODE_ALG_WEP) {
1511 u16 is_default = 0, index, set_tx_key = 0;
1512
1513 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1514 (dwrq->flags & IW_ENCODE_INDEX),
1515 &index, &is_default);
1516 if (ret)
1517 goto out;
1518
1519 /* If WEP isn't enabled, or if there is no key data but a valid
1520 * index, or if the set-TX-key flag was passed, set the TX key.
1521 */
Dan Williams889c05b2007-05-10 22:57:23 -04001522 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001523 || (dwrq->length == 0 && !is_default)
1524 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1525 set_tx_key = 1;
1526
1527 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001528 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001529 set_tx_key);
1530 if (ret)
1531 goto out;
1532
1533 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001534 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001535 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001536 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001537 }
1538
1539 /* Mark the various WEP bits as modified */
1540 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1541 if (dwrq->length)
1542 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1543 if (set_tx_key)
1544 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001545 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001546 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001547
1548 /* validate key length */
1549 if (((alg == IW_ENCODE_ALG_TKIP)
1550 && (ext->key_len != KEY_LEN_WPA_TKIP))
1551 || ((alg == IW_ENCODE_ALG_CCMP)
1552 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001553 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001554 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001555 ext->key_len,
1556 alg);
1557 ret = -EINVAL;
1558 goto out;
1559 }
1560
Dan Williams90a42212007-05-25 23:01:24 -04001561 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001562 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001563 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1564 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001565 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001566 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1567 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001568
Dan Williams1443b652007-08-02 10:45:55 -04001569 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001570 memcpy(pkey->key, ext->key, ext->key_len);
1571 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001572 if (pkey->len)
1573 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001574
Dan Williams90a42212007-05-25 23:01:24 -04001575 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001576 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1577 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001578 } else {
1579 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001580 }
1581
Dan Williams90a42212007-05-25 23:01:24 -04001582 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001583 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001584 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001585 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001586 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001587
1588 /* If WPA isn't enabled yet, do that now */
1589 if ( assoc_req->secinfo.WPAenabled == 0
1590 && assoc_req->secinfo.WPA2enabled == 0) {
1591 assoc_req->secinfo.WPAenabled = 1;
1592 assoc_req->secinfo.WPA2enabled = 1;
1593 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1594 }
1595
Javier Cardona9c31fd62008-09-11 15:32:50 -07001596 /* Only disable wep if necessary: can't waste time here. */
1597 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1598 disable_wep(assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001599 }
1600
1601out:
Javier Cardona9c31fd62008-09-11 15:32:50 -07001602 if (ret == 0) { /* key installation is time critical: postpone not! */
1603 lbs_do_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001604 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001605 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001606 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001607 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001608
Holger Schurig9012b282007-05-25 11:27:16 -04001609 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001610 return ret;
1611}
1612
1613
Holger Schurig10078322007-11-15 18:05:47 -05001614static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001615 struct iw_request_info *info,
1616 struct iw_point *dwrq,
1617 char *extra)
1618{
Holger Schurig69f90322007-11-23 15:43:44 +01001619 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001620 int ret = 0;
1621 struct assoc_request * assoc_req;
1622
Holger Schurig9012b282007-05-25 11:27:16 -04001623 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001624
David Woodhouseaa21c002007-12-08 20:04:36 +00001625 mutex_lock(&priv->lock);
1626 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001627 if (!assoc_req) {
1628 ret = -ENOMEM;
1629 goto out;
1630 }
1631
1632 if (dwrq->length > MAX_WPA_IE_LEN ||
1633 (dwrq->length && extra == NULL)) {
1634 ret = -EINVAL;
1635 goto out;
1636 }
1637
1638 if (dwrq->length) {
1639 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1640 assoc_req->wpa_ie_len = dwrq->length;
1641 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001642 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001643 assoc_req->wpa_ie_len = 0;
1644 }
1645
1646out:
1647 if (ret == 0) {
1648 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001649 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001650 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001651 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001652 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001653 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001654
Holger Schurig9012b282007-05-25 11:27:16 -04001655 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001656 return ret;
1657}
1658
Holger Schurig10078322007-11-15 18:05:47 -05001659static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001660 struct iw_request_info *info,
1661 struct iw_point *dwrq,
1662 char *extra)
1663{
Holger Schurig9012b282007-05-25 11:27:16 -04001664 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001665 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001666
Holger Schurig9012b282007-05-25 11:27:16 -04001667 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001668
David Woodhouseaa21c002007-12-08 20:04:36 +00001669 if (priv->wpa_ie_len == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001670 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001671 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001672 }
1673
David Woodhouseaa21c002007-12-08 20:04:36 +00001674 if (dwrq->length < priv->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001675 ret = -E2BIG;
1676 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001677 }
1678
David Woodhouseaa21c002007-12-08 20:04:36 +00001679 dwrq->length = priv->wpa_ie_len;
1680 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001681
Holger Schurig9012b282007-05-25 11:27:16 -04001682out:
1683 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1684 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001685}
1686
1687
Holger Schurig10078322007-11-15 18:05:47 -05001688static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001689 struct iw_request_info *info,
1690 struct iw_param *dwrq,
1691 char *extra)
1692{
Holger Schurig69f90322007-11-23 15:43:44 +01001693 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001694 struct assoc_request * assoc_req;
1695 int ret = 0;
1696 int updated = 0;
1697
Holger Schurig9012b282007-05-25 11:27:16 -04001698 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001699
David Woodhouseaa21c002007-12-08 20:04:36 +00001700 mutex_lock(&priv->lock);
1701 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001702 if (!assoc_req) {
1703 ret = -ENOMEM;
1704 goto out;
1705 }
1706
1707 switch (dwrq->flags & IW_AUTH_INDEX) {
1708 case IW_AUTH_TKIP_COUNTERMEASURES:
1709 case IW_AUTH_CIPHER_PAIRWISE:
1710 case IW_AUTH_CIPHER_GROUP:
1711 case IW_AUTH_KEY_MGMT:
Dan Williams90a42212007-05-25 23:01:24 -04001712 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001713 /*
1714 * libertas does not use these parameters
1715 */
1716 break;
1717
1718 case IW_AUTH_WPA_VERSION:
1719 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1720 assoc_req->secinfo.WPAenabled = 0;
1721 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001722 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001723 }
1724 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1725 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001726 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001727 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001728 }
1729 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1730 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001731 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001732 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001733 }
1734 updated = 1;
1735 break;
1736
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001737 case IW_AUTH_80211_AUTH_ALG:
1738 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001739 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001740 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001741 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001742 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001743 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001744 } else {
1745 ret = -EINVAL;
1746 }
1747 updated = 1;
1748 break;
1749
1750 case IW_AUTH_WPA_ENABLED:
1751 if (dwrq->value) {
1752 if (!assoc_req->secinfo.WPAenabled &&
1753 !assoc_req->secinfo.WPA2enabled) {
1754 assoc_req->secinfo.WPAenabled = 1;
1755 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001756 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001757 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001758 }
1759 } else {
1760 assoc_req->secinfo.WPAenabled = 0;
1761 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001762 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001763 }
1764 updated = 1;
1765 break;
1766
1767 default:
1768 ret = -EOPNOTSUPP;
1769 break;
1770 }
1771
1772out:
1773 if (ret == 0) {
1774 if (updated)
1775 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001776 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001777 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001778 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001779 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001780 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001781
Holger Schurig9012b282007-05-25 11:27:16 -04001782 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001783 return ret;
1784}
1785
Holger Schurig10078322007-11-15 18:05:47 -05001786static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001787 struct iw_request_info *info,
1788 struct iw_param *dwrq,
1789 char *extra)
1790{
Holger Schurig9012b282007-05-25 11:27:16 -04001791 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001792 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001793
Holger Schurig9012b282007-05-25 11:27:16 -04001794 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001795
1796 switch (dwrq->flags & IW_AUTH_INDEX) {
1797 case IW_AUTH_WPA_VERSION:
1798 dwrq->value = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +00001799 if (priv->secinfo.WPAenabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001800 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
David Woodhouseaa21c002007-12-08 20:04:36 +00001801 if (priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001802 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1803 if (!dwrq->value)
1804 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1805 break;
1806
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001807 case IW_AUTH_80211_AUTH_ALG:
David Woodhouseaa21c002007-12-08 20:04:36 +00001808 dwrq->value = priv->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001809 break;
1810
1811 case IW_AUTH_WPA_ENABLED:
David Woodhouseaa21c002007-12-08 20:04:36 +00001812 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001813 dwrq->value = 1;
1814 break;
1815
1816 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001817 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001818 }
1819
Holger Schurig9012b282007-05-25 11:27:16 -04001820 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1821 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001822}
1823
1824
Holger Schurig10078322007-11-15 18:05:47 -05001825static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001826 struct iw_param *vwrq, char *extra)
1827{
1828 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001829 struct lbs_private *priv = dev->priv;
Dan Williams87c8c722008-08-19 15:15:35 -04001830 s16 dbm = (s16) vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001831
Holger Schurig9012b282007-05-25 11:27:16 -04001832 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001833
1834 if (vwrq->disabled) {
Dan Williamsd5db2df2008-08-21 17:51:07 -04001835 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
Dan Williams87c8c722008-08-19 15:15:35 -04001836 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001837 }
1838
Dan Williams87c8c722008-08-19 15:15:35 -04001839 if (vwrq->fixed == 0) {
Anna Neal0112c9e2008-09-11 11:17:25 -07001840 /* User requests automatic tx power control, however there are
1841 * many auto tx settings. For now use firmware defaults until
1842 * we come up with a good way to expose these to the user. */
1843 if (priv->fwrelease < 0x09000000) {
1844 ret = lbs_set_power_adapt_cfg(priv, 1,
1845 POW_ADAPT_DEFAULT_P0,
1846 POW_ADAPT_DEFAULT_P1,
1847 POW_ADAPT_DEFAULT_P2);
1848 if (ret)
1849 goto out;
1850 }
1851 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1852 TPC_DEFAULT_P2, 1);
1853 if (ret)
1854 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001855 dbm = priv->txpower_max;
1856 } else {
1857 /* Userspace check in iwrange if it should use dBm or mW,
1858 * therefore this should never happen... Jean II */
1859 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1860 ret = -EOPNOTSUPP;
1861 goto out;
1862 }
1863
Anna Neal0112c9e2008-09-11 11:17:25 -07001864 /* Validate requested power level against firmware allowed
1865 * levels */
Dan Williams87c8c722008-08-19 15:15:35 -04001866 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1867 ret = -EINVAL;
1868 goto out;
1869 }
1870
1871 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1872 ret = -EINVAL;
1873 goto out;
1874 }
Anna Neal0112c9e2008-09-11 11:17:25 -07001875 if (priv->fwrelease < 0x09000000) {
1876 ret = lbs_set_power_adapt_cfg(priv, 0,
1877 POW_ADAPT_DEFAULT_P0,
1878 POW_ADAPT_DEFAULT_P1,
1879 POW_ADAPT_DEFAULT_P2);
1880 if (ret)
1881 goto out;
1882 }
1883 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1884 TPC_DEFAULT_P2, 1);
1885 if (ret)
1886 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001887 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001888
Dan Williamsd5db2df2008-08-21 17:51:07 -04001889 /* If the radio was off, turn it on */
1890 if (!priv->radio_on) {
1891 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
1892 if (ret)
1893 goto out;
1894 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001895
Dan Williams87c8c722008-08-19 15:15:35 -04001896 lbs_deb_wext("txpower set %d dBm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001897
Dan Williams87c8c722008-08-19 15:15:35 -04001898 ret = lbs_set_tx_power(priv, dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001899
Dan Williams87c8c722008-08-19 15:15:35 -04001900out:
Holger Schurig9012b282007-05-25 11:27:16 -04001901 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001902 return ret;
1903}
1904
Holger Schurig10078322007-11-15 18:05:47 -05001905static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001906 struct iw_point *dwrq, char *extra)
1907{
Holger Schurig69f90322007-11-23 15:43:44 +01001908 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001909
Holger Schurig9012b282007-05-25 11:27:16 -04001910 lbs_deb_enter(LBS_DEB_WEXT);
1911
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001912 /*
1913 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1914 * the SSID list...
1915 */
1916
1917 /*
1918 * Get the current SSID
1919 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001920 if (priv->connect_status == LBS_CONNECTED) {
1921 memcpy(extra, priv->curbssparams.ssid,
1922 priv->curbssparams.ssid_len);
1923 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001924 } else {
1925 memset(extra, 0, 32);
David Woodhouseaa21c002007-12-08 20:04:36 +00001926 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001927 }
1928 /*
1929 * If none, we may want to get the one that was set
1930 */
1931
David Woodhouseaa21c002007-12-08 20:04:36 +00001932 dwrq->length = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001933
1934 dwrq->flags = 1; /* active */
1935
Holger Schurig9012b282007-05-25 11:27:16 -04001936 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001937 return 0;
1938}
1939
Holger Schurig10078322007-11-15 18:05:47 -05001940static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001941 struct iw_point *dwrq, char *extra)
1942{
Holger Schurig69f90322007-11-23 15:43:44 +01001943 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001944 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04001945 u8 ssid[IW_ESSID_MAX_SIZE];
1946 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001947 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001948 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001949
Holger Schurig9012b282007-05-25 11:27:16 -04001950 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001951
Dan Williamsd5db2df2008-08-21 17:51:07 -04001952 if (!priv->radio_on) {
1953 ret = -EINVAL;
1954 goto out;
1955 }
1956
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001957 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001958 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001959 ret = -E2BIG;
1960 goto out;
1961 }
1962
Dan Williamsd8efea22007-05-28 23:54:55 -04001963 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001964
Dan Williamsd8efea22007-05-28 23:54:55 -04001965 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001966 /* "any" SSID requested; leave SSID blank */
1967 } else {
1968 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04001969 memcpy(&ssid, extra, in_ssid_len);
1970 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001971 }
1972
Dan Williamsd8efea22007-05-28 23:54:55 -04001973 if (!ssid_len) {
1974 lbs_deb_wext("requested any SSID\n");
1975 } else {
1976 lbs_deb_wext("requested SSID '%s'\n",
1977 escape_essid(ssid, ssid_len));
1978 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001979
1980out:
David Woodhouseaa21c002007-12-08 20:04:36 +00001981 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001982 if (ret == 0) {
1983 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00001984 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001985 if (!assoc_req) {
1986 ret = -ENOMEM;
1987 } else {
1988 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04001989 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1990 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001991 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001992 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001993 }
1994 }
1995
1996 /* Cancel the association request if there was an error */
1997 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001998 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001999 }
2000
David Woodhouseaa21c002007-12-08 20:04:36 +00002001 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002002
Holger Schurig9012b282007-05-25 11:27:16 -04002003 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002004 return ret;
2005}
2006
David Woodhousef5956bf2007-12-11 19:30:57 -05002007static int lbs_mesh_get_essid(struct net_device *dev,
2008 struct iw_request_info *info,
2009 struct iw_point *dwrq, char *extra)
2010{
2011 struct lbs_private *priv = dev->priv;
2012
2013 lbs_deb_enter(LBS_DEB_WEXT);
2014
2015 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2016
2017 dwrq->length = priv->mesh_ssid_len;
2018
2019 dwrq->flags = 1; /* active */
2020
2021 lbs_deb_leave(LBS_DEB_WEXT);
2022 return 0;
2023}
2024
2025static int lbs_mesh_set_essid(struct net_device *dev,
2026 struct iw_request_info *info,
2027 struct iw_point *dwrq, char *extra)
2028{
2029 struct lbs_private *priv = dev->priv;
2030 int ret = 0;
2031
2032 lbs_deb_enter(LBS_DEB_WEXT);
2033
Dan Williamsd5db2df2008-08-21 17:51:07 -04002034 if (!priv->radio_on) {
2035 ret = -EINVAL;
2036 goto out;
2037 }
2038
David Woodhousef5956bf2007-12-11 19:30:57 -05002039 /* Check the size of the string */
2040 if (dwrq->length > IW_ESSID_MAX_SIZE) {
2041 ret = -E2BIG;
2042 goto out;
2043 }
2044
2045 if (!dwrq->flags || !dwrq->length) {
2046 ret = -EINVAL;
2047 goto out;
2048 } else {
2049 /* Specific SSID requested */
2050 memcpy(priv->mesh_ssid, extra, dwrq->length);
2051 priv->mesh_ssid_len = dwrq->length;
2052 }
2053
Javier Cardonaedaea5c2008-05-17 00:55:10 -07002054 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
2055 priv->curbssparams.channel);
David Woodhousef5956bf2007-12-11 19:30:57 -05002056 out:
2057 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2058 return ret;
2059}
2060
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002061/**
2062 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2063 *
2064 * @param dev A pointer to net_device structure
2065 * @param info A pointer to iw_request_info structure
2066 * @param awrq A pointer to iw_param structure
2067 * @param extra A pointer to extra data buf
2068 * @return 0 --success, otherwise fail
2069 */
Holger Schurig10078322007-11-15 18:05:47 -05002070static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002071 struct sockaddr *awrq, char *extra)
2072{
Holger Schurig69f90322007-11-23 15:43:44 +01002073 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002074 struct assoc_request * assoc_req;
2075 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07002076 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002077
Holger Schurig9012b282007-05-25 11:27:16 -04002078 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002079
Dan Williamsd5db2df2008-08-21 17:51:07 -04002080 if (!priv->radio_on)
2081 return -EINVAL;
2082
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002083 if (awrq->sa_family != ARPHRD_ETHER)
2084 return -EINVAL;
2085
Joe Perches0795af52007-10-03 17:59:30 -07002086 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002087
David Woodhouseaa21c002007-12-08 20:04:36 +00002088 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002089
2090 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002091 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002092 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05002093 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002094 ret = -ENOMEM;
2095 } else {
2096 /* Copy the BSSID to the association request */
2097 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2098 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002099 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002100 }
2101
David Woodhouseaa21c002007-12-08 20:04:36 +00002102 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002103
2104 return ret;
2105}
2106
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002107/*
2108 * iwconfig settable callbacks
2109 */
Holger Schurig10078322007-11-15 18:05:47 -05002110static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002111 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002112 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002113 (iw_handler) NULL, /* SIOCSIWNWID */
2114 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002115 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2116 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2117 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2118 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002119 (iw_handler) NULL, /* SIOCSIWSENS */
2120 (iw_handler) NULL, /* SIOCGIWSENS */
2121 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002122 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002123 (iw_handler) NULL, /* SIOCSIWPRIV */
2124 (iw_handler) NULL, /* SIOCGIWPRIV */
2125 (iw_handler) NULL, /* SIOCSIWSTATS */
2126 (iw_handler) NULL, /* SIOCGIWSTATS */
2127 iw_handler_set_spy, /* SIOCSIWSPY */
2128 iw_handler_get_spy, /* SIOCGIWSPY */
2129 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2130 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002131 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2132 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002133 (iw_handler) NULL, /* SIOCSIWMLME */
2134 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002135 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2136 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2137 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2138 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2139 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2140 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002141 (iw_handler) NULL, /* -- hole -- */
2142 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002143 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2144 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2145 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2146 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2147 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2148 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2149 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2150 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2151 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2152 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2153 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2154 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2155 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2156 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002157 (iw_handler) NULL, /* -- hole -- */
2158 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002159 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2160 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2161 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2162 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2163 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2164 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002165 (iw_handler) NULL, /* SIOCSIWPMKSA */
2166};
2167
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002168static const iw_handler mesh_wlan_handler[] = {
2169 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002170 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002171 (iw_handler) NULL, /* SIOCSIWNWID */
2172 (iw_handler) NULL, /* SIOCGIWNWID */
David Woodhouse823eaa22007-12-11 19:56:28 -05002173 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
Holger Schurig10078322007-11-15 18:05:47 -05002174 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002175 (iw_handler) NULL, /* SIOCSIWMODE */
2176 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2177 (iw_handler) NULL, /* SIOCSIWSENS */
2178 (iw_handler) NULL, /* SIOCGIWSENS */
2179 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002180 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002181 (iw_handler) NULL, /* SIOCSIWPRIV */
2182 (iw_handler) NULL, /* SIOCGIWPRIV */
2183 (iw_handler) NULL, /* SIOCSIWSTATS */
2184 (iw_handler) NULL, /* SIOCGIWSTATS */
2185 iw_handler_set_spy, /* SIOCSIWSPY */
2186 iw_handler_get_spy, /* SIOCGIWSPY */
2187 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2188 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2189 (iw_handler) NULL, /* SIOCSIWAP */
2190 (iw_handler) NULL, /* SIOCGIWAP */
2191 (iw_handler) NULL, /* SIOCSIWMLME */
2192 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002193 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2194 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
David Woodhousef5956bf2007-12-11 19:30:57 -05002195 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2196 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002197 (iw_handler) NULL, /* SIOCSIWNICKN */
2198 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2199 (iw_handler) NULL, /* -- hole -- */
2200 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002201 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2202 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2203 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2204 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2205 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2206 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2207 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2208 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2209 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2210 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2211 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2212 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2213 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2214 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002215 (iw_handler) NULL, /* -- hole -- */
2216 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002217 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2218 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2219 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2220 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2221 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2222 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002223 (iw_handler) NULL, /* SIOCSIWPMKSA */
2224};
Holger Schurig10078322007-11-15 18:05:47 -05002225struct iw_handler_def lbs_handler_def = {
2226 .num_standard = ARRAY_SIZE(lbs_handler),
2227 .standard = (iw_handler *) lbs_handler,
2228 .get_wireless_stats = lbs_get_wireless_stats,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002229};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002230
2231struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002232 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002233 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002234 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002235};