blob: 11297dcf9fc3f2639fcda0014ba837877488d9b6 [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
John W. Linville375da532008-09-15 17:25:54 -0400284 if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400285 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;
John W. Linville375da532008-09-15 17:25:54 -0400307 vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200308 vwrq->fixed = 1;
309
Holger Schurig9012b282007-05-25 11:27:16 -0400310out:
311 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
312 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200313}
314
Holger Schurig10078322007-11-15 18:05:47 -0500315static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200316 struct iw_param *vwrq, char *extra)
317{
Holger Schurig69f90322007-11-23 15:43:44 +0100318 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400319 int ret = 0;
320 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200321
Holger Schurig9012b282007-05-25 11:27:16 -0400322 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200323
Dan Williams39fcf7a2008-09-10 12:49:00 -0400324 if (vwrq->disabled)
325 val = MRVDRV_FRAG_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200326
Dan Williams39fcf7a2008-09-10 12:49:00 -0400327 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
328 return -EINVAL;
329
330 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
Holger Schurig9012b282007-05-25 11:27:16 -0400331
332 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333 return ret;
334}
335
Holger Schurig10078322007-11-15 18:05:47 -0500336static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200337 struct iw_param *vwrq, char *extra)
338{
Holger Schurig69f90322007-11-23 15:43:44 +0100339 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400340 int ret = 0;
341 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200342
Holger Schurig9012b282007-05-25 11:27:16 -0400343 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344
Dan Williams39fcf7a2008-09-10 12:49:00 -0400345 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400346 if (ret)
347 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200348
Dan Williams39fcf7a2008-09-10 12:49:00 -0400349 vwrq->value = val;
350 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
351 || (val > MRVDRV_FRAG_MAX_VALUE));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352 vwrq->fixed = 1;
353
Holger Schurig9012b282007-05-25 11:27:16 -0400354out:
355 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200356 return ret;
357}
358
Holger Schurig10078322007-11-15 18:05:47 -0500359static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360 struct iw_request_info *info, u32 * uwrq, char *extra)
361{
Holger Schurig69f90322007-11-23 15:43:44 +0100362 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200363
Holger Schurig9012b282007-05-25 11:27:16 -0400364 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200365
David Woodhouseaa21c002007-12-08 20:04:36 +0000366 *uwrq = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200367
Holger Schurig9012b282007-05-25 11:27:16 -0400368 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369 return 0;
370}
371
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400372static int mesh_wlan_get_mode(struct net_device *dev,
373 struct iw_request_info *info, u32 * uwrq,
374 char *extra)
375{
376 lbs_deb_enter(LBS_DEB_WEXT);
377
Dan Williams39fcf7a2008-09-10 12:49:00 -0400378 *uwrq = IW_MODE_REPEAT;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400379
380 lbs_deb_leave(LBS_DEB_WEXT);
381 return 0;
382}
383
Holger Schurig10078322007-11-15 18:05:47 -0500384static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200385 struct iw_request_info *info,
386 struct iw_param *vwrq, char *extra)
387{
Holger Schurig69f90322007-11-23 15:43:44 +0100388 struct lbs_private *priv = dev->priv;
Dan Williams87c8c722008-08-19 15:15:35 -0400389 s16 curlevel = 0;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400390 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391
Holger Schurig9012b282007-05-25 11:27:16 -0400392 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200393
Dan Williamsd5db2df2008-08-21 17:51:07 -0400394 if (!priv->radio_on) {
395 lbs_deb_wext("tx power off\n");
396 vwrq->value = 0;
397 vwrq->disabled = 1;
398 goto out;
399 }
400
Dan Williams87c8c722008-08-19 15:15:35 -0400401 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400402 if (ret)
403 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404
Dan Williams87c8c722008-08-19 15:15:35 -0400405 lbs_deb_wext("tx power level %d dbm\n", curlevel);
Dan Williams87c8c722008-08-19 15:15:35 -0400406 priv->txpower_cur = curlevel;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400407
Dan Williams87c8c722008-08-19 15:15:35 -0400408 vwrq->value = curlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200409 vwrq->fixed = 1;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400410 vwrq->disabled = 0;
411 vwrq->flags = IW_TXPOW_DBM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200412
Holger Schurig9012b282007-05-25 11:27:16 -0400413out:
414 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
415 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200416}
417
Holger Schurig10078322007-11-15 18:05:47 -0500418static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419 struct iw_param *vwrq, char *extra)
420{
Holger Schurig69f90322007-11-23 15:43:44 +0100421 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400422 int ret = 0;
423 u16 slimit = 0, llimit = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200424
Holger Schurig9012b282007-05-25 11:27:16 -0400425 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426
Dan Williams39fcf7a2008-09-10 12:49:00 -0400427 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
428 return -EOPNOTSUPP;
429
430 /* The MAC has a 4-bit Total_Tx_Count register
431 Total_Tx_Count = 1 + Tx_Retry_Count */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200432#define TX_RETRY_MIN 0
433#define TX_RETRY_MAX 14
Dan Williams39fcf7a2008-09-10 12:49:00 -0400434 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
435 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436
Dan Williams39fcf7a2008-09-10 12:49:00 -0400437 /* Add 1 to convert retry count to try count */
438 if (vwrq->flags & IW_RETRY_SHORT)
439 slimit = (u16) (vwrq->value + 1);
440 else if (vwrq->flags & IW_RETRY_LONG)
441 llimit = (u16) (vwrq->value + 1);
442 else
443 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200444
Dan Williams39fcf7a2008-09-10 12:49:00 -0400445 if (llimit) {
446 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
447 llimit);
Holger Schurig9012b282007-05-25 11:27:16 -0400448 if (ret)
449 goto out;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400450 }
451
452 if (slimit) {
453 /* txretrycount follows the short retry limit */
454 priv->txretrycount = slimit;
455 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
456 slimit);
457 if (ret)
458 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459 }
460
Holger Schurig9012b282007-05-25 11:27:16 -0400461out:
462 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
463 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464}
465
Holger Schurig10078322007-11-15 18:05:47 -0500466static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200467 struct iw_param *vwrq, char *extra)
468{
Holger Schurig69f90322007-11-23 15:43:44 +0100469 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470 int ret = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400471 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472
Holger Schurig9012b282007-05-25 11:27:16 -0400473 lbs_deb_enter(LBS_DEB_WEXT);
474
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200475 vwrq->disabled = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400476
477 if (vwrq->flags & IW_RETRY_LONG) {
478 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
479 if (ret)
480 goto out;
481
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200482 /* Subtract 1 to convert try count to retry count */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400483 vwrq->value = val - 1;
484 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
485 } else {
486 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
487 if (ret)
488 goto out;
489
490 /* txretry count follows the short retry limit */
491 priv->txretrycount = val;
492 /* Subtract 1 to convert try count to retry count */
493 vwrq->value = val - 1;
494 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495 }
496
Holger Schurig9012b282007-05-25 11:27:16 -0400497out:
498 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
499 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200500}
501
502static inline void sort_channels(struct iw_freq *freq, int num)
503{
504 int i, j;
505 struct iw_freq temp;
506
507 for (i = 0; i < num; i++)
508 for (j = i + 1; j < num; j++)
509 if (freq[i].i > freq[j].i) {
510 temp.i = freq[i].i;
511 temp.m = freq[i].m;
512
513 freq[i].i = freq[j].i;
514 freq[i].m = freq[j].m;
515
516 freq[j].i = temp.i;
517 freq[j].m = temp.m;
518 }
519}
520
521/* data rate listing
522 MULTI_BANDS:
523 abg a b b/g
524 Infra G(12) A(8) B(4) G(12)
525 Adhoc A+B(12) A(8) B(4) B(4)
526
527 non-MULTI_BANDS:
528 b b/g
529 Infra B(4) G(12)
530 Adhoc B(4) B(4)
531 */
532/**
533 * @brief Get Range Info
534 *
535 * @param dev A pointer to net_device structure
536 * @param info A pointer to iw_request_info structure
537 * @param vwrq A pointer to iw_param structure
538 * @param extra A pointer to extra data buf
539 * @return 0 --success, otherwise fail
540 */
Holger Schurig10078322007-11-15 18:05:47 -0500541static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200542 struct iw_point *dwrq, char *extra)
543{
544 int i, j;
Holger Schurig69f90322007-11-23 15:43:44 +0100545 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200546 struct iw_range *range = (struct iw_range *)extra;
547 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400548 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200549
550 u8 flag = 0;
551
Holger Schurig9012b282007-05-25 11:27:16 -0400552 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553
554 dwrq->length = sizeof(struct iw_range);
555 memset(range, 0, sizeof(struct iw_range));
556
557 range->min_nwid = 0;
558 range->max_nwid = 0;
559
560 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000561 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400562 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
563 for (i = 0; i < range->num_bitrates; i++)
564 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200565 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400566 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567 range->num_bitrates);
568
569 range->num_frequency = 0;
Holger Schurig52933d82008-03-05 07:05:32 +0100570
571 range->scan_capa = IW_SCAN_CAPA_ESSID;
572
David Woodhouseaa21c002007-12-08 20:04:36 +0000573 if (priv->enable11d &&
574 (priv->connect_status == LBS_CONNECTED ||
575 priv->mesh_connect_status == LBS_CONNECTED)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576 u8 chan_no;
577 u8 band;
578
579 struct parsed_region_chan_11d *parsed_region_chan =
David Woodhouseaa21c002007-12-08 20:04:36 +0000580 &priv->parsed_region_chan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200581
582 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400583 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
584 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200585 }
586 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400587 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200588 parsed_region_chan->nr_chan);
589
590 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
591 && (i < parsed_region_chan->nr_chan); i++) {
592 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400593 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200594 range->freq[range->num_frequency].i = (long)chan_no;
595 range->freq[range->num_frequency].m =
Holger Schurige98a88d2008-03-19 14:25:58 +0100596 (long)lbs_chan_2_freq(chan_no) * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200597 range->freq[range->num_frequency].e = 1;
598 range->num_frequency++;
599 }
600 flag = 1;
601 }
602 if (!flag) {
603 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000604 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
605 cfp = priv->region_channel[j].CFP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200606 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000607 && priv->region_channel[j].valid
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608 && cfp
David Woodhouseaa21c002007-12-08 20:04:36 +0000609 && (i < priv->region_channel[j].nrcfp); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610 range->freq[range->num_frequency].i =
611 (long)cfp->channel;
612 range->freq[range->num_frequency].m =
613 (long)cfp->freq * 100000;
614 range->freq[range->num_frequency].e = 1;
615 cfp++;
616 range->num_frequency++;
617 }
618 }
619 }
620
Holger Schurig9012b282007-05-25 11:27:16 -0400621 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200622 IW_MAX_FREQUENCIES, range->num_frequency);
623
624 range->num_channels = range->num_frequency;
625
626 sort_channels(&range->freq[0], range->num_frequency);
627
628 /*
629 * Set an indication of the max TCP throughput in bit/s that we can
630 * expect using this interface
631 */
632 if (i > 2)
633 range->throughput = 5000 * 1000;
634 else
635 range->throughput = 1500 * 1000;
636
637 range->min_rts = MRVDRV_RTS_MIN_VALUE;
638 range->max_rts = MRVDRV_RTS_MAX_VALUE;
639 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
640 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
641
642 range->encoding_size[0] = 5;
643 range->encoding_size[1] = 13;
644 range->num_encoding_sizes = 2;
645 range->max_encoding_tokens = 4;
646
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100647 /*
648 * Right now we support only "iwconfig ethX power on|off"
649 */
650 range->pm_capa = IW_POWER_ON;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200651
652 /*
653 * Minimum version we recommend
654 */
655 range->we_version_source = 15;
656
657 /*
658 * Version we are compiled with
659 */
660 range->we_version_compiled = WIRELESS_EXT;
661
662 range->retry_capa = IW_RETRY_LIMIT;
663 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
664
665 range->min_retry = TX_RETRY_MIN;
666 range->max_retry = TX_RETRY_MAX;
667
668 /*
669 * Set the qual, level and noise range values
670 */
671 range->max_qual.qual = 100;
672 range->max_qual.level = 0;
673 range->max_qual.noise = 0;
674 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
675
676 range->avg_qual.qual = 70;
677 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
678 range->avg_qual.level = 0;
679 range->avg_qual.noise = 0;
680 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
681
682 range->sensitivity = 0;
683
Dan Williams87c8c722008-08-19 15:15:35 -0400684 /* Setup the supported power level ranges */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200685 memset(range->txpower, 0, sizeof(range->txpower));
Dan Williams87c8c722008-08-19 15:15:35 -0400686 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
687 range->txpower[0] = priv->txpower_min;
688 range->txpower[1] = priv->txpower_max;
689 range->num_txpower = 2;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200690
691 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
692 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
693 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
694 range->event_capa[1] = IW_EVENT_CAPA_K_1;
695
David Woodhouseaa21c002007-12-08 20:04:36 +0000696 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200697 range->enc_capa = IW_ENC_CAPA_WPA
698 | IW_ENC_CAPA_WPA2
699 | IW_ENC_CAPA_CIPHER_TKIP
700 | IW_ENC_CAPA_CIPHER_CCMP;
701 }
702
Holger Schurig9012b282007-05-25 11:27:16 -0400703out:
704 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200705 return 0;
706}
707
Holger Schurig10078322007-11-15 18:05:47 -0500708static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709 struct iw_param *vwrq, char *extra)
710{
Holger Schurig69f90322007-11-23 15:43:44 +0100711 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200712
Holger Schurig9012b282007-05-25 11:27:16 -0400713 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200714
David Woodhouseb2c57ee2007-12-17 14:41:13 -0500715 if (!priv->ps_supported) {
716 if (vwrq->disabled)
717 return 0;
718 else
719 return -EINVAL;
720 }
721
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200722 /* PS is currently supported only in Infrastructure mode
723 * Remove this check if it is to be supported in IBSS mode also
724 */
725
726 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000727 priv->psmode = LBS802_11POWERMODECAM;
728 if (priv->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500729 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200730 }
731
732 return 0;
733 }
734
735 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400736 lbs_deb_wext(
737 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200738 return -EINVAL;
739 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400740 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741 return -EINVAL;
742 }
743
David Woodhouseaa21c002007-12-08 20:04:36 +0000744 if (priv->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745 return 0;
746 }
747
David Woodhouseaa21c002007-12-08 20:04:36 +0000748 priv->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200749
David Woodhouseaa21c002007-12-08 20:04:36 +0000750 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500751 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200752 }
753
Holger Schurig9012b282007-05-25 11:27:16 -0400754 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200755 return 0;
756}
757
Holger Schurig10078322007-11-15 18:05:47 -0500758static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200759 struct iw_param *vwrq, char *extra)
760{
Holger Schurig69f90322007-11-23 15:43:44 +0100761 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762
Holger Schurig9012b282007-05-25 11:27:16 -0400763 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200764
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200765 vwrq->value = 0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100766 vwrq->flags = 0;
767 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
768 || priv->connect_status == LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200769
Holger Schurig9012b282007-05-25 11:27:16 -0400770 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200771 return 0;
772}
773
Holger Schurig10078322007-11-15 18:05:47 -0500774static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200775{
776 enum {
777 POOR = 30,
778 FAIR = 60,
779 GOOD = 80,
780 VERY_GOOD = 90,
781 EXCELLENT = 95,
782 PERFECT = 100
783 };
Holger Schurig69f90322007-11-23 15:43:44 +0100784 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785 u32 rssi_qual;
786 u32 tx_qual;
787 u32 quality = 0;
788 int stats_valid = 0;
789 u8 rssi;
790 u32 tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100791 struct cmd_ds_802_11_get_log log;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200792
Holger Schurig9012b282007-05-25 11:27:16 -0400793 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200794
David Woodhouseaa21c002007-12-08 20:04:36 +0000795 priv->wstats.status = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200796
797 /* If we're not associated, all quality values are meaningless */
David Woodhouseaa21c002007-12-08 20:04:36 +0000798 if ((priv->connect_status != LBS_CONNECTED) &&
799 (priv->mesh_connect_status != LBS_CONNECTED))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200800 goto out;
801
802 /* Quality by RSSI */
803 priv->wstats.qual.level =
David Woodhouseaa21c002007-12-08 20:04:36 +0000804 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
805 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200806
David Woodhouseaa21c002007-12-08 20:04:36 +0000807 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200808 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
809 } else {
810 priv->wstats.qual.noise =
David Woodhouseaa21c002007-12-08 20:04:36 +0000811 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200812 }
813
Holger Schurig9012b282007-05-25 11:27:16 -0400814 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
815 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200816
817 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
818 if (rssi < 15)
819 rssi_qual = rssi * POOR / 10;
820 else if (rssi < 20)
821 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
822 else if (rssi < 30)
823 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
824 else if (rssi < 40)
825 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
826 10 + GOOD;
827 else
828 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
829 10 + VERY_GOOD;
830 quality = rssi_qual;
831
832 /* Quality by TX errors */
833 priv->wstats.discard.retries = priv->stats.tx_errors;
834
Holger Schurigc49c3b72008-03-17 12:45:58 +0100835 memset(&log, 0, sizeof(log));
836 log.hdr.size = cpu_to_le16(sizeof(log));
837 lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
838
839 tx_retries = le32_to_cpu(log.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200840
841 if (tx_retries > 75)
842 tx_qual = (90 - tx_retries) * POOR / 15;
843 else if (tx_retries > 70)
844 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
845 else if (tx_retries > 65)
846 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
847 else if (tx_retries > 50)
848 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
849 15 + GOOD;
850 else
851 tx_qual = (50 - tx_retries) *
852 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
853 quality = min(quality, tx_qual);
854
Holger Schurigc49c3b72008-03-17 12:45:58 +0100855 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856 priv->wstats.discard.retries = tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100857 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200858
859 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400860 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200861 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
862 stats_valid = 1;
863
864 /* update stats asynchronously for future calls */
Holger Schurig10078322007-11-15 18:05:47 -0500865 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200866 0, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200867out:
868 if (!stats_valid) {
869 priv->wstats.miss.beacon = 0;
870 priv->wstats.discard.retries = 0;
871 priv->wstats.qual.qual = 0;
872 priv->wstats.qual.level = 0;
873 priv->wstats.qual.noise = 0;
874 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
875 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
876 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
877 }
878
Holger Schurig9012b282007-05-25 11:27:16 -0400879 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200880 return &priv->wstats;
881
882
883}
884
Holger Schurig10078322007-11-15 18:05:47 -0500885static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200886 struct iw_freq *fwrq, char *extra)
887{
Dan Williamsef9a2642007-05-25 16:46:33 -0400888 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +0100889 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200890 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400891 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200892
Holger Schurig9012b282007-05-25 11:27:16 -0400893 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200894
David Woodhouseaa21c002007-12-08 20:04:36 +0000895 mutex_lock(&priv->lock);
896 assoc_req = lbs_get_association_request(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400897 if (!assoc_req) {
898 ret = -ENOMEM;
899 goto out;
900 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200901
Dan Williamsef9a2642007-05-25 16:46:33 -0400902 /* If setting by frequency, convert to a channel */
903 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200904 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905
David Woodhouseaa21c002007-12-08 20:04:36 +0000906 cfp = find_cfp_by_band_and_freq(priv, 0, f);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200907 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400908 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400909 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200910 }
911
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200912 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400913 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200914 }
915
Dan Williamsef9a2642007-05-25 16:46:33 -0400916 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200917 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400918 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200919 }
920
David Woodhouseaa21c002007-12-08 20:04:36 +0000921 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400922 if (!cfp) {
923 goto out;
924 }
925
926 assoc_req->channel = fwrq->m;
927 ret = 0;
928
Holger Schurig9012b282007-05-25 11:27:16 -0400929out:
Dan Williamsef9a2642007-05-25 16:46:33 -0400930 if (ret == 0) {
931 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500932 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400933 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500934 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400935 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000936 mutex_unlock(&priv->lock);
Dan Williamsef9a2642007-05-25 16:46:33 -0400937
938 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
939 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200940}
941
David Woodhouse823eaa22007-12-11 19:56:28 -0500942static int lbs_mesh_set_freq(struct net_device *dev,
943 struct iw_request_info *info,
944 struct iw_freq *fwrq, char *extra)
945{
946 struct lbs_private *priv = dev->priv;
947 struct chan_freq_power *cfp;
948 int ret = -EINVAL;
949
950 lbs_deb_enter(LBS_DEB_WEXT);
951
952 /* If setting by frequency, convert to a channel */
953 if (fwrq->e == 1) {
954 long f = fwrq->m / 100000;
955
956 cfp = find_cfp_by_band_and_freq(priv, 0, f);
957 if (!cfp) {
958 lbs_deb_wext("invalid freq %ld\n", f);
959 goto out;
960 }
961
962 fwrq->e = 0;
963 fwrq->m = (int) cfp->channel;
964 }
965
966 /* Setting by channel number */
967 if (fwrq->m > 1000 || fwrq->e > 0) {
968 goto out;
969 }
970
971 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
972 if (!cfp) {
973 goto out;
974 }
975
976 if (fwrq->m != priv->curbssparams.channel) {
977 lbs_deb_wext("mesh channel change forces eth disconnect\n");
978 if (priv->mode == IW_MODE_INFRA)
Dan Williams191bb402008-08-21 17:46:18 -0400979 lbs_cmd_80211_deauthenticate(priv,
980 priv->curbssparams.bssid,
981 WLAN_REASON_DEAUTH_LEAVING);
David Woodhouse823eaa22007-12-11 19:56:28 -0500982 else if (priv->mode == IW_MODE_ADHOC)
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400983 lbs_adhoc_stop(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -0500984 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700985 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
David Woodhouse86062132007-12-13 00:32:36 -0500986 lbs_update_channel(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -0500987 ret = 0;
988
989out:
990 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
991 return ret;
992}
993
Holger Schurig10078322007-11-15 18:05:47 -0500994static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200995 struct iw_param *vwrq, char *extra)
996{
Holger Schurig69f90322007-11-23 15:43:44 +0100997 struct lbs_private *priv = dev->priv;
Dan Williams8e3c91b2007-12-11 15:50:59 -0500998 u8 new_rate = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400999 int ret = -EINVAL;
1000 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001001
Holger Schurig9012b282007-05-25 11:27:16 -04001002 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -04001003 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Javier Cardona85319f92008-05-24 10:59:49 +01001004 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1005
1006 if (vwrq->fixed && vwrq->value == -1)
1007 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001008
Dan Williams8c512762007-08-02 11:40:45 -04001009 /* Auto rate? */
Javier Cardona85319f92008-05-24 10:59:49 +01001010 priv->enablehwauto = !vwrq->fixed;
1011
1012 if (vwrq->value == -1)
David Woodhouseaa21c002007-12-08 20:04:36 +00001013 priv->cur_rate = 0;
Javier Cardona85319f92008-05-24 10:59:49 +01001014 else {
Dan Williams8c512762007-08-02 11:40:45 -04001015 if (vwrq->value % 100000)
1016 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001017
Javier Cardona85319f92008-05-24 10:59:49 +01001018 new_rate = vwrq->value / 500000;
1019 priv->cur_rate = new_rate;
1020 /* the rest is only needed for lbs_set_data_rate() */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001021 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +00001022 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -04001023 if (!memchr(rates, new_rate, sizeof(rates))) {
1024 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1025 new_rate);
1026 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001027 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001028 }
1029
Javier Cardona85319f92008-05-24 10:59:49 +01001030 /* Try the newer command first (Firmware Spec 5.1 and above) */
1031 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1032
1033 /* Fallback to older version */
1034 if (ret)
1035 ret = lbs_set_data_rate(priv, new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001036
Dan Williams8c512762007-08-02 11:40:45 -04001037out:
Holger Schurig9012b282007-05-25 11:27:16 -04001038 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001039 return ret;
1040}
1041
Holger Schurig10078322007-11-15 18:05:47 -05001042static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001043 struct iw_param *vwrq, char *extra)
1044{
Holger Schurig69f90322007-11-23 15:43:44 +01001045 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001046
Holger Schurig9012b282007-05-25 11:27:16 -04001047 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001048
David Woodhouseaa21c002007-12-08 20:04:36 +00001049 if (priv->connect_status == LBS_CONNECTED) {
1050 vwrq->value = priv->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001051
Javier Cardona85319f92008-05-24 10:59:49 +01001052 if (priv->enablehwauto)
Dan Williams8c512762007-08-02 11:40:45 -04001053 vwrq->fixed = 0;
1054 else
1055 vwrq->fixed = 1;
1056
1057 } else {
1058 vwrq->fixed = 0;
1059 vwrq->value = 0;
1060 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001061
Holger Schurig9012b282007-05-25 11:27:16 -04001062 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001063 return 0;
1064}
1065
Holger Schurig10078322007-11-15 18:05:47 -05001066static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001067 struct iw_request_info *info, u32 * uwrq, char *extra)
1068{
1069 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001070 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001071 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001072
Holger Schurig9012b282007-05-25 11:27:16 -04001073 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074
Dan Williams0dc5a292007-05-10 22:58:02 -04001075 if ( (*uwrq != IW_MODE_ADHOC)
1076 && (*uwrq != IW_MODE_INFRA)
1077 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001078 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001079 ret = -EINVAL;
1080 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001081 }
1082
David Woodhouseaa21c002007-12-08 20:04:36 +00001083 mutex_lock(&priv->lock);
1084 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001085 if (!assoc_req) {
1086 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001087 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001088 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001089 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001090 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001091 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001092 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001093 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001094 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001095
Dan Williams0dc5a292007-05-10 22:58:02 -04001096out:
Holger Schurig9012b282007-05-25 11:27:16 -04001097 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001098 return ret;
1099}
1100
1101
1102/**
1103 * @brief Get Encryption key
1104 *
1105 * @param dev A pointer to net_device structure
1106 * @param info A pointer to iw_request_info structure
1107 * @param vwrq A pointer to iw_param structure
1108 * @param extra A pointer to extra data buf
1109 * @return 0 --success, otherwise fail
1110 */
Holger Schurig10078322007-11-15 18:05:47 -05001111static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001112 struct iw_request_info *info,
1113 struct iw_point *dwrq, u8 * extra)
1114{
Holger Schurig69f90322007-11-23 15:43:44 +01001115 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001116 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1117
Holger Schurig9012b282007-05-25 11:27:16 -04001118 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001119
Holger Schurig9012b282007-05-25 11:27:16 -04001120 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001121 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001122
1123 dwrq->flags = 0;
1124
1125 /* Authentication method */
David Woodhouseaa21c002007-12-08 20:04:36 +00001126 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -04001127 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001128 dwrq->flags = IW_ENCODE_OPEN;
1129 break;
1130
Dan Williams6affe782007-05-10 22:56:42 -04001131 case IW_AUTH_ALG_SHARED_KEY:
1132 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001133 dwrq->flags = IW_ENCODE_RESTRICTED;
1134 break;
1135 default:
1136 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1137 break;
1138 }
1139
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001140 memset(extra, 0, 16);
1141
David Woodhouseaa21c002007-12-08 20:04:36 +00001142 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001143
1144 /* Default to returning current transmit key */
1145 if (index < 0)
David Woodhouseaa21c002007-12-08 20:04:36 +00001146 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001147
David Woodhouseaa21c002007-12-08 20:04:36 +00001148 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1149 memcpy(extra, priv->wep_keys[index].key,
1150 priv->wep_keys[index].len);
1151 dwrq->length = priv->wep_keys[index].len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001152
1153 dwrq->flags |= (index + 1);
1154 /* Return WEP enabled */
1155 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhouseaa21c002007-12-08 20:04:36 +00001156 } else if ((priv->secinfo.WPAenabled)
1157 || (priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001158 /* return WPA enabled */
1159 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhousec12bdc42007-12-07 19:32:12 +00001160 dwrq->flags |= IW_ENCODE_NOKEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001161 } else {
1162 dwrq->flags |= IW_ENCODE_DISABLED;
1163 }
1164
David Woodhouseaa21c002007-12-08 20:04:36 +00001165 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001166
Joe Perches0795af52007-10-03 17:59:30 -07001167 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001168 extra[0], extra[1], extra[2],
1169 extra[3], extra[4], extra[5], dwrq->length);
1170
Holger Schurig9012b282007-05-25 11:27:16 -04001171 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001172
Holger Schurig9012b282007-05-25 11:27:16 -04001173 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001174 return 0;
1175}
1176
1177/**
1178 * @brief Set Encryption key (internal)
1179 *
1180 * @param priv A pointer to private card structure
1181 * @param key_material A pointer to key material
1182 * @param key_length length of key material
1183 * @param index key index to set
1184 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1185 * @return 0 --success, otherwise fail
1186 */
Holger Schurig10078322007-11-15 18:05:47 -05001187static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001188 const char *key_material,
1189 u16 key_length,
1190 u16 index,
1191 int set_tx_key)
1192{
Holger Schurig9012b282007-05-25 11:27:16 -04001193 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001194 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001195
Holger Schurig9012b282007-05-25 11:27:16 -04001196 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001197
1198 /* Paranoid validation of key index */
1199 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001200 ret = -EINVAL;
1201 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001202 }
1203
1204 /* validate max key length */
1205 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001206 ret = -EINVAL;
1207 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001208 }
1209
1210 pkey = &assoc_req->wep_keys[index];
1211
1212 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001213 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001214 pkey->type = KEY_TYPE_ID_WEP;
1215
1216 /* Standardize the key length */
1217 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1218 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1219 memcpy(pkey->key, key_material, key_length);
1220 }
1221
1222 if (set_tx_key) {
1223 /* Ensure the chosen key is valid */
1224 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001225 lbs_deb_wext("key not set, so cannot enable it\n");
1226 ret = -EINVAL;
1227 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001228 }
1229 assoc_req->wep_tx_keyidx = index;
1230 }
1231
Dan Williams889c05b2007-05-10 22:57:23 -04001232 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001233
Holger Schurig9012b282007-05-25 11:27:16 -04001234out:
1235 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1236 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001237}
1238
1239static int validate_key_index(u16 def_index, u16 raw_index,
1240 u16 *out_index, u16 *is_default)
1241{
1242 if (!out_index || !is_default)
1243 return -EINVAL;
1244
1245 /* Verify index if present, otherwise use default TX key index */
1246 if (raw_index > 0) {
1247 if (raw_index > 4)
1248 return -EINVAL;
1249 *out_index = raw_index - 1;
1250 } else {
1251 *out_index = def_index;
1252 *is_default = 1;
1253 }
1254 return 0;
1255}
1256
1257static void disable_wep(struct assoc_request *assoc_req)
1258{
1259 int i;
1260
Dan Williams90a42212007-05-25 23:01:24 -04001261 lbs_deb_enter(LBS_DEB_WEXT);
1262
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001263 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001264 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001265
1266 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001267 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001268 for (i = 0; i < 4; i++)
1269 assoc_req->wep_keys[i].len = 0;
1270
1271 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1272 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001273
1274 lbs_deb_leave(LBS_DEB_WEXT);
1275}
1276
1277static void disable_wpa(struct assoc_request *assoc_req)
1278{
1279 lbs_deb_enter(LBS_DEB_WEXT);
1280
Dan Williams1443b652007-08-02 10:45:55 -04001281 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001282 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1283 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1284
Dan Williams1443b652007-08-02 10:45:55 -04001285 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001286 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1287 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1288
1289 assoc_req->secinfo.WPAenabled = 0;
1290 assoc_req->secinfo.WPA2enabled = 0;
1291 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1292
1293 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001294}
1295
1296/**
1297 * @brief Set Encryption key
1298 *
1299 * @param dev A pointer to net_device structure
1300 * @param info A pointer to iw_request_info structure
1301 * @param vwrq A pointer to iw_param structure
1302 * @param extra A pointer to extra data buf
1303 * @return 0 --success, otherwise fail
1304 */
Holger Schurig10078322007-11-15 18:05:47 -05001305static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001306 struct iw_request_info *info,
1307 struct iw_point *dwrq, char *extra)
1308{
1309 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001310 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001311 struct assoc_request * assoc_req;
1312 u16 is_default = 0, index = 0, set_tx_key = 0;
1313
Holger Schurig9012b282007-05-25 11:27:16 -04001314 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001315
David Woodhouseaa21c002007-12-08 20:04:36 +00001316 mutex_lock(&priv->lock);
1317 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001318 if (!assoc_req) {
1319 ret = -ENOMEM;
1320 goto out;
1321 }
1322
1323 if (dwrq->flags & IW_ENCODE_DISABLED) {
1324 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001325 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001326 goto out;
1327 }
1328
1329 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1330 (dwrq->flags & IW_ENCODE_INDEX),
1331 &index, &is_default);
1332 if (ret) {
1333 ret = -EINVAL;
1334 goto out;
1335 }
1336
1337 /* If WEP isn't enabled, or if there is no key data but a valid
1338 * index, set the TX key.
1339 */
Dan Williams889c05b2007-05-10 22:57:23 -04001340 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001341 set_tx_key = 1;
1342
Holger Schurig10078322007-11-15 18:05:47 -05001343 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001344 if (ret)
1345 goto out;
1346
1347 if (dwrq->length)
1348 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1349 if (set_tx_key)
1350 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1351
1352 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001353 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001354 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001355 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001356 }
1357
1358out:
1359 if (ret == 0) {
1360 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001361 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001362 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001363 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001364 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001365 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001366
Holger Schurig9012b282007-05-25 11:27:16 -04001367 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001368 return ret;
1369}
1370
1371/**
1372 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1373 *
1374 * @param dev A pointer to net_device structure
1375 * @param info A pointer to iw_request_info structure
1376 * @param vwrq A pointer to iw_param structure
1377 * @param extra A pointer to extra data buf
1378 * @return 0 on success, otherwise failure
1379 */
Holger Schurig10078322007-11-15 18:05:47 -05001380static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001381 struct iw_request_info *info,
1382 struct iw_point *dwrq,
1383 char *extra)
1384{
1385 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +01001386 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001387 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1388 int index, max_key_len;
1389
Holger Schurig9012b282007-05-25 11:27:16 -04001390 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001391
1392 max_key_len = dwrq->length - sizeof(*ext);
1393 if (max_key_len < 0)
1394 goto out;
1395
1396 index = dwrq->flags & IW_ENCODE_INDEX;
1397 if (index) {
1398 if (index < 1 || index > 4)
1399 goto out;
1400 index--;
1401 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001402 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001403 }
1404
Roel Kluinf59d9782007-10-26 21:51:26 +02001405 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001406 ext->alg != IW_ENCODE_ALG_WEP) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001407 if (index != 0 || priv->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001408 goto out;
1409 }
1410
1411 dwrq->flags = index + 1;
1412 memset(ext, 0, sizeof(*ext));
1413
David Woodhouseaa21c002007-12-08 20:04:36 +00001414 if ( !priv->secinfo.wep_enabled
1415 && !priv->secinfo.WPAenabled
1416 && !priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001417 ext->alg = IW_ENCODE_ALG_NONE;
1418 ext->key_len = 0;
1419 dwrq->flags |= IW_ENCODE_DISABLED;
1420 } else {
1421 u8 *key = NULL;
1422
David Woodhouseaa21c002007-12-08 20:04:36 +00001423 if ( priv->secinfo.wep_enabled
1424 && !priv->secinfo.WPAenabled
1425 && !priv->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001426 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001427 ext->alg = IW_ENCODE_ALG_WEP;
David Woodhouseaa21c002007-12-08 20:04:36 +00001428 ext->key_len = priv->wep_keys[index].len;
1429 key = &priv->wep_keys[index].key[0];
1430 } else if ( !priv->secinfo.wep_enabled
1431 && (priv->secinfo.WPAenabled ||
1432 priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001433 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001434 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001435
David Woodhouseaa21c002007-12-08 20:04:36 +00001436 if ( priv->wpa_mcast_key.len
1437 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1438 pkey = &priv->wpa_mcast_key;
1439 else if ( priv->wpa_unicast_key.len
1440 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1441 pkey = &priv->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001442
1443 if (pkey) {
1444 if (pkey->type == KEY_TYPE_ID_AES) {
1445 ext->alg = IW_ENCODE_ALG_CCMP;
1446 } else {
1447 ext->alg = IW_ENCODE_ALG_TKIP;
1448 }
1449 ext->key_len = pkey->len;
1450 key = &pkey->key[0];
1451 } else {
1452 ext->alg = IW_ENCODE_ALG_TKIP;
1453 ext->key_len = 0;
1454 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001455 } else {
1456 goto out;
1457 }
1458
1459 if (ext->key_len > max_key_len) {
1460 ret = -E2BIG;
1461 goto out;
1462 }
1463
1464 if (ext->key_len)
1465 memcpy(ext->key, key, ext->key_len);
1466 else
1467 dwrq->flags |= IW_ENCODE_NOKEY;
1468 dwrq->flags |= IW_ENCODE_ENABLED;
1469 }
1470 ret = 0;
1471
1472out:
Holger Schurig9012b282007-05-25 11:27:16 -04001473 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001474 return ret;
1475}
1476
1477/**
1478 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1479 *
1480 * @param dev A pointer to net_device structure
1481 * @param info A pointer to iw_request_info structure
1482 * @param vwrq A pointer to iw_param structure
1483 * @param extra A pointer to extra data buf
1484 * @return 0 --success, otherwise fail
1485 */
Holger Schurig10078322007-11-15 18:05:47 -05001486static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487 struct iw_request_info *info,
1488 struct iw_point *dwrq,
1489 char *extra)
1490{
1491 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001492 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001493 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1494 int alg = ext->alg;
1495 struct assoc_request * assoc_req;
1496
Holger Schurig9012b282007-05-25 11:27:16 -04001497 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001498
David Woodhouseaa21c002007-12-08 20:04:36 +00001499 mutex_lock(&priv->lock);
1500 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001501 if (!assoc_req) {
1502 ret = -ENOMEM;
1503 goto out;
1504 }
1505
1506 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1507 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001508 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001509 } else if (alg == IW_ENCODE_ALG_WEP) {
1510 u16 is_default = 0, index, set_tx_key = 0;
1511
1512 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1513 (dwrq->flags & IW_ENCODE_INDEX),
1514 &index, &is_default);
1515 if (ret)
1516 goto out;
1517
1518 /* If WEP isn't enabled, or if there is no key data but a valid
1519 * index, or if the set-TX-key flag was passed, set the TX key.
1520 */
Dan Williams889c05b2007-05-10 22:57:23 -04001521 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001522 || (dwrq->length == 0 && !is_default)
1523 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1524 set_tx_key = 1;
1525
1526 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001527 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001528 set_tx_key);
1529 if (ret)
1530 goto out;
1531
1532 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001533 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001534 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001535 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001536 }
1537
1538 /* Mark the various WEP bits as modified */
1539 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1540 if (dwrq->length)
1541 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1542 if (set_tx_key)
1543 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001544 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001545 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001546
1547 /* validate key length */
1548 if (((alg == IW_ENCODE_ALG_TKIP)
1549 && (ext->key_len != KEY_LEN_WPA_TKIP))
1550 || ((alg == IW_ENCODE_ALG_CCMP)
1551 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001552 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001553 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001554 ext->key_len,
1555 alg);
1556 ret = -EINVAL;
1557 goto out;
1558 }
1559
Dan Williams90a42212007-05-25 23:01:24 -04001560 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001561 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001562 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1563 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001564 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001565 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1566 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001567
Dan Williams1443b652007-08-02 10:45:55 -04001568 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001569 memcpy(pkey->key, ext->key, ext->key_len);
1570 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001571 if (pkey->len)
1572 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001573
Dan Williams90a42212007-05-25 23:01:24 -04001574 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001575 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1576 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001577 } else {
1578 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001579 }
1580
Dan Williams90a42212007-05-25 23:01:24 -04001581 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001582 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001583 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001584 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001585 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001586
1587 /* If WPA isn't enabled yet, do that now */
1588 if ( assoc_req->secinfo.WPAenabled == 0
1589 && assoc_req->secinfo.WPA2enabled == 0) {
1590 assoc_req->secinfo.WPAenabled = 1;
1591 assoc_req->secinfo.WPA2enabled = 1;
1592 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1593 }
1594
Javier Cardona9c31fd62008-09-11 15:32:50 -07001595 /* Only disable wep if necessary: can't waste time here. */
1596 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1597 disable_wep(assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001598 }
1599
1600out:
Javier Cardona9c31fd62008-09-11 15:32:50 -07001601 if (ret == 0) { /* key installation is time critical: postpone not! */
1602 lbs_do_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001603 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001604 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001605 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001606 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001607
Holger Schurig9012b282007-05-25 11:27:16 -04001608 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001609 return ret;
1610}
1611
1612
Holger Schurig10078322007-11-15 18:05:47 -05001613static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001614 struct iw_request_info *info,
1615 struct iw_point *dwrq,
1616 char *extra)
1617{
Holger Schurig69f90322007-11-23 15:43:44 +01001618 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001619 int ret = 0;
1620 struct assoc_request * assoc_req;
1621
Holger Schurig9012b282007-05-25 11:27:16 -04001622 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001623
David Woodhouseaa21c002007-12-08 20:04:36 +00001624 mutex_lock(&priv->lock);
1625 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001626 if (!assoc_req) {
1627 ret = -ENOMEM;
1628 goto out;
1629 }
1630
1631 if (dwrq->length > MAX_WPA_IE_LEN ||
1632 (dwrq->length && extra == NULL)) {
1633 ret = -EINVAL;
1634 goto out;
1635 }
1636
1637 if (dwrq->length) {
1638 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1639 assoc_req->wpa_ie_len = dwrq->length;
1640 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001641 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001642 assoc_req->wpa_ie_len = 0;
1643 }
1644
1645out:
1646 if (ret == 0) {
1647 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001648 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001649 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001650 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001651 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001652 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001653
Holger Schurig9012b282007-05-25 11:27:16 -04001654 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001655 return ret;
1656}
1657
Holger Schurig10078322007-11-15 18:05:47 -05001658static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001659 struct iw_request_info *info,
1660 struct iw_point *dwrq,
1661 char *extra)
1662{
Holger Schurig9012b282007-05-25 11:27:16 -04001663 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001664 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001665
Holger Schurig9012b282007-05-25 11:27:16 -04001666 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001667
David Woodhouseaa21c002007-12-08 20:04:36 +00001668 if (priv->wpa_ie_len == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001669 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001670 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001671 }
1672
David Woodhouseaa21c002007-12-08 20:04:36 +00001673 if (dwrq->length < priv->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001674 ret = -E2BIG;
1675 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001676 }
1677
David Woodhouseaa21c002007-12-08 20:04:36 +00001678 dwrq->length = priv->wpa_ie_len;
1679 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001680
Holger Schurig9012b282007-05-25 11:27:16 -04001681out:
1682 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1683 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001684}
1685
1686
Holger Schurig10078322007-11-15 18:05:47 -05001687static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001688 struct iw_request_info *info,
1689 struct iw_param *dwrq,
1690 char *extra)
1691{
Holger Schurig69f90322007-11-23 15:43:44 +01001692 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001693 struct assoc_request * assoc_req;
1694 int ret = 0;
1695 int updated = 0;
1696
Holger Schurig9012b282007-05-25 11:27:16 -04001697 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001698
David Woodhouseaa21c002007-12-08 20:04:36 +00001699 mutex_lock(&priv->lock);
1700 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001701 if (!assoc_req) {
1702 ret = -ENOMEM;
1703 goto out;
1704 }
1705
1706 switch (dwrq->flags & IW_AUTH_INDEX) {
1707 case IW_AUTH_TKIP_COUNTERMEASURES:
1708 case IW_AUTH_CIPHER_PAIRWISE:
1709 case IW_AUTH_CIPHER_GROUP:
1710 case IW_AUTH_KEY_MGMT:
Dan Williams90a42212007-05-25 23:01:24 -04001711 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001712 /*
1713 * libertas does not use these parameters
1714 */
1715 break;
1716
1717 case IW_AUTH_WPA_VERSION:
1718 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1719 assoc_req->secinfo.WPAenabled = 0;
1720 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001721 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001722 }
1723 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1724 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001725 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001726 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001727 }
1728 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1729 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001730 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001731 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001732 }
1733 updated = 1;
1734 break;
1735
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001736 case IW_AUTH_80211_AUTH_ALG:
1737 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001738 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001739 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001740 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001741 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001742 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001743 } else {
1744 ret = -EINVAL;
1745 }
1746 updated = 1;
1747 break;
1748
1749 case IW_AUTH_WPA_ENABLED:
1750 if (dwrq->value) {
1751 if (!assoc_req->secinfo.WPAenabled &&
1752 !assoc_req->secinfo.WPA2enabled) {
1753 assoc_req->secinfo.WPAenabled = 1;
1754 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001755 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001756 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001757 }
1758 } else {
1759 assoc_req->secinfo.WPAenabled = 0;
1760 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001761 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001762 }
1763 updated = 1;
1764 break;
1765
1766 default:
1767 ret = -EOPNOTSUPP;
1768 break;
1769 }
1770
1771out:
1772 if (ret == 0) {
1773 if (updated)
1774 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001775 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001776 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001777 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001778 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001779 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001780
Holger Schurig9012b282007-05-25 11:27:16 -04001781 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001782 return ret;
1783}
1784
Holger Schurig10078322007-11-15 18:05:47 -05001785static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001786 struct iw_request_info *info,
1787 struct iw_param *dwrq,
1788 char *extra)
1789{
Holger Schurig9012b282007-05-25 11:27:16 -04001790 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001791 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001792
Holger Schurig9012b282007-05-25 11:27:16 -04001793 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001794
1795 switch (dwrq->flags & IW_AUTH_INDEX) {
1796 case IW_AUTH_WPA_VERSION:
1797 dwrq->value = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +00001798 if (priv->secinfo.WPAenabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001799 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
David Woodhouseaa21c002007-12-08 20:04:36 +00001800 if (priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001801 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1802 if (!dwrq->value)
1803 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1804 break;
1805
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001806 case IW_AUTH_80211_AUTH_ALG:
David Woodhouseaa21c002007-12-08 20:04:36 +00001807 dwrq->value = priv->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001808 break;
1809
1810 case IW_AUTH_WPA_ENABLED:
David Woodhouseaa21c002007-12-08 20:04:36 +00001811 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001812 dwrq->value = 1;
1813 break;
1814
1815 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001816 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001817 }
1818
Holger Schurig9012b282007-05-25 11:27:16 -04001819 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1820 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001821}
1822
1823
Holger Schurig10078322007-11-15 18:05:47 -05001824static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001825 struct iw_param *vwrq, char *extra)
1826{
1827 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001828 struct lbs_private *priv = dev->priv;
Dan Williams87c8c722008-08-19 15:15:35 -04001829 s16 dbm = (s16) vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001830
Holger Schurig9012b282007-05-25 11:27:16 -04001831 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001832
1833 if (vwrq->disabled) {
Dan Williamsd5db2df2008-08-21 17:51:07 -04001834 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
Dan Williams87c8c722008-08-19 15:15:35 -04001835 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001836 }
1837
Dan Williams87c8c722008-08-19 15:15:35 -04001838 if (vwrq->fixed == 0) {
Anna Neal0112c9e2008-09-11 11:17:25 -07001839 /* User requests automatic tx power control, however there are
1840 * many auto tx settings. For now use firmware defaults until
1841 * we come up with a good way to expose these to the user. */
1842 if (priv->fwrelease < 0x09000000) {
1843 ret = lbs_set_power_adapt_cfg(priv, 1,
1844 POW_ADAPT_DEFAULT_P0,
1845 POW_ADAPT_DEFAULT_P1,
1846 POW_ADAPT_DEFAULT_P2);
1847 if (ret)
1848 goto out;
1849 }
1850 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1851 TPC_DEFAULT_P2, 1);
1852 if (ret)
1853 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001854 dbm = priv->txpower_max;
1855 } else {
1856 /* Userspace check in iwrange if it should use dBm or mW,
1857 * therefore this should never happen... Jean II */
1858 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1859 ret = -EOPNOTSUPP;
1860 goto out;
1861 }
1862
Anna Neal0112c9e2008-09-11 11:17:25 -07001863 /* Validate requested power level against firmware allowed
1864 * levels */
Dan Williams87c8c722008-08-19 15:15:35 -04001865 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1866 ret = -EINVAL;
1867 goto out;
1868 }
1869
1870 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1871 ret = -EINVAL;
1872 goto out;
1873 }
Anna Neal0112c9e2008-09-11 11:17:25 -07001874 if (priv->fwrelease < 0x09000000) {
1875 ret = lbs_set_power_adapt_cfg(priv, 0,
1876 POW_ADAPT_DEFAULT_P0,
1877 POW_ADAPT_DEFAULT_P1,
1878 POW_ADAPT_DEFAULT_P2);
1879 if (ret)
1880 goto out;
1881 }
1882 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1883 TPC_DEFAULT_P2, 1);
1884 if (ret)
1885 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001886 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001887
Dan Williamsd5db2df2008-08-21 17:51:07 -04001888 /* If the radio was off, turn it on */
1889 if (!priv->radio_on) {
1890 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
1891 if (ret)
1892 goto out;
1893 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001894
Dan Williams87c8c722008-08-19 15:15:35 -04001895 lbs_deb_wext("txpower set %d dBm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001896
Dan Williams87c8c722008-08-19 15:15:35 -04001897 ret = lbs_set_tx_power(priv, dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001898
Dan Williams87c8c722008-08-19 15:15:35 -04001899out:
Holger Schurig9012b282007-05-25 11:27:16 -04001900 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001901 return ret;
1902}
1903
Holger Schurig10078322007-11-15 18:05:47 -05001904static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001905 struct iw_point *dwrq, char *extra)
1906{
Holger Schurig69f90322007-11-23 15:43:44 +01001907 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001908
Holger Schurig9012b282007-05-25 11:27:16 -04001909 lbs_deb_enter(LBS_DEB_WEXT);
1910
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001911 /*
1912 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1913 * the SSID list...
1914 */
1915
1916 /*
1917 * Get the current SSID
1918 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001919 if (priv->connect_status == LBS_CONNECTED) {
1920 memcpy(extra, priv->curbssparams.ssid,
1921 priv->curbssparams.ssid_len);
1922 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001923 } else {
1924 memset(extra, 0, 32);
David Woodhouseaa21c002007-12-08 20:04:36 +00001925 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001926 }
1927 /*
1928 * If none, we may want to get the one that was set
1929 */
1930
David Woodhouseaa21c002007-12-08 20:04:36 +00001931 dwrq->length = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001932
1933 dwrq->flags = 1; /* active */
1934
Holger Schurig9012b282007-05-25 11:27:16 -04001935 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001936 return 0;
1937}
1938
Holger Schurig10078322007-11-15 18:05:47 -05001939static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001940 struct iw_point *dwrq, char *extra)
1941{
Holger Schurig69f90322007-11-23 15:43:44 +01001942 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001943 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04001944 u8 ssid[IW_ESSID_MAX_SIZE];
1945 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001946 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001947 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001948
Holger Schurig9012b282007-05-25 11:27:16 -04001949 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001950
Dan Williamsd5db2df2008-08-21 17:51:07 -04001951 if (!priv->radio_on) {
1952 ret = -EINVAL;
1953 goto out;
1954 }
1955
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001956 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001957 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001958 ret = -E2BIG;
1959 goto out;
1960 }
1961
Dan Williamsd8efea22007-05-28 23:54:55 -04001962 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001963
Dan Williamsd8efea22007-05-28 23:54:55 -04001964 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001965 /* "any" SSID requested; leave SSID blank */
1966 } else {
1967 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04001968 memcpy(&ssid, extra, in_ssid_len);
1969 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001970 }
1971
Dan Williamsd8efea22007-05-28 23:54:55 -04001972 if (!ssid_len) {
1973 lbs_deb_wext("requested any SSID\n");
1974 } else {
1975 lbs_deb_wext("requested SSID '%s'\n",
1976 escape_essid(ssid, ssid_len));
1977 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001978
1979out:
David Woodhouseaa21c002007-12-08 20:04:36 +00001980 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001981 if (ret == 0) {
1982 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00001983 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001984 if (!assoc_req) {
1985 ret = -ENOMEM;
1986 } else {
1987 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04001988 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1989 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001990 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001991 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001992 }
1993 }
1994
1995 /* Cancel the association request if there was an error */
1996 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001997 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001998 }
1999
David Woodhouseaa21c002007-12-08 20:04:36 +00002000 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002001
Holger Schurig9012b282007-05-25 11:27:16 -04002002 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002003 return ret;
2004}
2005
David Woodhousef5956bf2007-12-11 19:30:57 -05002006static int lbs_mesh_get_essid(struct net_device *dev,
2007 struct iw_request_info *info,
2008 struct iw_point *dwrq, char *extra)
2009{
2010 struct lbs_private *priv = dev->priv;
2011
2012 lbs_deb_enter(LBS_DEB_WEXT);
2013
2014 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2015
2016 dwrq->length = priv->mesh_ssid_len;
2017
2018 dwrq->flags = 1; /* active */
2019
2020 lbs_deb_leave(LBS_DEB_WEXT);
2021 return 0;
2022}
2023
2024static int lbs_mesh_set_essid(struct net_device *dev,
2025 struct iw_request_info *info,
2026 struct iw_point *dwrq, char *extra)
2027{
2028 struct lbs_private *priv = dev->priv;
2029 int ret = 0;
2030
2031 lbs_deb_enter(LBS_DEB_WEXT);
2032
Dan Williamsd5db2df2008-08-21 17:51:07 -04002033 if (!priv->radio_on) {
2034 ret = -EINVAL;
2035 goto out;
2036 }
2037
David Woodhousef5956bf2007-12-11 19:30:57 -05002038 /* Check the size of the string */
2039 if (dwrq->length > IW_ESSID_MAX_SIZE) {
2040 ret = -E2BIG;
2041 goto out;
2042 }
2043
2044 if (!dwrq->flags || !dwrq->length) {
2045 ret = -EINVAL;
2046 goto out;
2047 } else {
2048 /* Specific SSID requested */
2049 memcpy(priv->mesh_ssid, extra, dwrq->length);
2050 priv->mesh_ssid_len = dwrq->length;
2051 }
2052
Javier Cardonaedaea5c2008-05-17 00:55:10 -07002053 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
2054 priv->curbssparams.channel);
David Woodhousef5956bf2007-12-11 19:30:57 -05002055 out:
2056 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2057 return ret;
2058}
2059
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002060/**
2061 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2062 *
2063 * @param dev A pointer to net_device structure
2064 * @param info A pointer to iw_request_info structure
2065 * @param awrq A pointer to iw_param structure
2066 * @param extra A pointer to extra data buf
2067 * @return 0 --success, otherwise fail
2068 */
Holger Schurig10078322007-11-15 18:05:47 -05002069static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002070 struct sockaddr *awrq, char *extra)
2071{
Holger Schurig69f90322007-11-23 15:43:44 +01002072 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002073 struct assoc_request * assoc_req;
2074 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07002075 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002076
Holger Schurig9012b282007-05-25 11:27:16 -04002077 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002078
Dan Williamsd5db2df2008-08-21 17:51:07 -04002079 if (!priv->radio_on)
2080 return -EINVAL;
2081
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002082 if (awrq->sa_family != ARPHRD_ETHER)
2083 return -EINVAL;
2084
Joe Perches0795af52007-10-03 17:59:30 -07002085 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002086
David Woodhouseaa21c002007-12-08 20:04:36 +00002087 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002088
2089 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002090 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002091 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05002092 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002093 ret = -ENOMEM;
2094 } else {
2095 /* Copy the BSSID to the association request */
2096 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2097 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002098 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002099 }
2100
David Woodhouseaa21c002007-12-08 20:04:36 +00002101 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002102
2103 return ret;
2104}
2105
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002106/*
2107 * iwconfig settable callbacks
2108 */
Holger Schurig10078322007-11-15 18:05:47 -05002109static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002110 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002111 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002112 (iw_handler) NULL, /* SIOCSIWNWID */
2113 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002114 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2115 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2116 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2117 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002118 (iw_handler) NULL, /* SIOCSIWSENS */
2119 (iw_handler) NULL, /* SIOCGIWSENS */
2120 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002121 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002122 (iw_handler) NULL, /* SIOCSIWPRIV */
2123 (iw_handler) NULL, /* SIOCGIWPRIV */
2124 (iw_handler) NULL, /* SIOCSIWSTATS */
2125 (iw_handler) NULL, /* SIOCGIWSTATS */
2126 iw_handler_set_spy, /* SIOCSIWSPY */
2127 iw_handler_get_spy, /* SIOCGIWSPY */
2128 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2129 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002130 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2131 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002132 (iw_handler) NULL, /* SIOCSIWMLME */
2133 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002134 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2135 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2136 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2137 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2138 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2139 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002140 (iw_handler) NULL, /* -- hole -- */
2141 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002142 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2143 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2144 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2145 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2146 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2147 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2148 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2149 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2150 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2151 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2152 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2153 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2154 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2155 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002156 (iw_handler) NULL, /* -- hole -- */
2157 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002158 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2159 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2160 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2161 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2162 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2163 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002164 (iw_handler) NULL, /* SIOCSIWPMKSA */
2165};
2166
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002167static const iw_handler mesh_wlan_handler[] = {
2168 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002169 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002170 (iw_handler) NULL, /* SIOCSIWNWID */
2171 (iw_handler) NULL, /* SIOCGIWNWID */
David Woodhouse823eaa22007-12-11 19:56:28 -05002172 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
Holger Schurig10078322007-11-15 18:05:47 -05002173 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002174 (iw_handler) NULL, /* SIOCSIWMODE */
2175 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2176 (iw_handler) NULL, /* SIOCSIWSENS */
2177 (iw_handler) NULL, /* SIOCGIWSENS */
2178 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002179 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002180 (iw_handler) NULL, /* SIOCSIWPRIV */
2181 (iw_handler) NULL, /* SIOCGIWPRIV */
2182 (iw_handler) NULL, /* SIOCSIWSTATS */
2183 (iw_handler) NULL, /* SIOCGIWSTATS */
2184 iw_handler_set_spy, /* SIOCSIWSPY */
2185 iw_handler_get_spy, /* SIOCGIWSPY */
2186 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2187 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2188 (iw_handler) NULL, /* SIOCSIWAP */
2189 (iw_handler) NULL, /* SIOCGIWAP */
2190 (iw_handler) NULL, /* SIOCSIWMLME */
2191 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002192 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2193 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
David Woodhousef5956bf2007-12-11 19:30:57 -05002194 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2195 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002196 (iw_handler) NULL, /* SIOCSIWNICKN */
2197 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2198 (iw_handler) NULL, /* -- hole -- */
2199 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002200 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2201 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2202 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2203 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2204 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2205 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2206 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2207 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2208 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2209 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2210 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2211 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2212 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2213 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002214 (iw_handler) NULL, /* -- hole -- */
2215 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002216 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2217 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2218 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2219 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2220 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2221 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002222 (iw_handler) NULL, /* SIOCSIWPMKSA */
2223};
Holger Schurig10078322007-11-15 18:05:47 -05002224struct iw_handler_def lbs_handler_def = {
2225 .num_standard = ARRAY_SIZE(lbs_handler),
2226 .standard = (iw_handler *) lbs_handler,
2227 .get_wireless_stats = lbs_get_wireless_stats,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002228};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002229
2230struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002231 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002232 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002233 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002234};