blob: 38a451edb70359052877d66fce0293ad65b0aac3 [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
John W. Linville7e272fc2008-09-24 18:13:14 -040011#include <net/lib80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020012#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 Cardona9c31fd632008-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
Amitkumar Karwar49125452009-09-30 20:04:38 -070048/**
49 * @brief This function checks if the command is allowed.
50 *
51 * @param priv A pointer to lbs_private structure
52 * @return allowed or not allowed.
53 */
54
55int lbs_is_cmd_allowed(struct lbs_private *priv)
56{
57 int ret = 1;
58
59 lbs_deb_enter(LBS_DEB_WEXT);
60
61 if (!priv->is_auto_deep_sleep_enabled) {
62 if (priv->is_deep_sleep) {
63 lbs_deb_wext("IOCTLS called when station"
64 "is in deep sleep\n");
65 ret = 0;
66 }
67 }
68
69 lbs_deb_leave(LBS_DEB_WEXT);
70 return ret;
71}
72
Holger Schurig9f9dac22007-10-26 10:12:14 +020073
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 * @brief Find the channel frequency power info with specific channel
76 *
David Woodhouseaa21c002007-12-08 20:04:36 +000077 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020078 * @param band it can be BAND_A, BAND_G or BAND_B
79 * @param channel the channel for looking
80 * @return A pointer to struct chan_freq_power structure or NULL if not find.
81 */
Holger Schurig69f90322007-11-23 15:43:44 +010082struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
David Woodhouseaa21c002007-12-08 20:04:36 +000083 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +010084 u8 band,
85 u16 channel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020086{
87 struct chan_freq_power *cfp = NULL;
88 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089 int i, j;
90
David Woodhouseaa21c002007-12-08 20:04:36 +000091 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
92 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020093
David Woodhouseaa21c002007-12-08 20:04:36 +000094 if (priv->enable11d)
95 rc = &priv->universal_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020096 if (!rc->valid || !rc->CFP)
97 continue;
98 if (rc->band != band)
99 continue;
100 for (i = 0; i < rc->nrcfp; i++) {
101 if (rc->CFP[i].channel == channel) {
102 cfp = &rc->CFP[i];
103 break;
104 }
105 }
106 }
107
108 if (!cfp && channel)
Holger Schurig10078322007-11-15 18:05:47 -0500109 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
Holger Schurig9012b282007-05-25 11:27:16 -0400110 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200111
112 return cfp;
113}
114
115/**
116 * @brief Find the channel frequency power info with specific frequency
117 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000118 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200119 * @param band it can be BAND_A, BAND_G or BAND_B
120 * @param freq the frequency for looking
121 * @return A pointer to struct chan_freq_power structure or NULL if not find.
122 */
Holger Schurig69f90322007-11-23 15:43:44 +0100123static struct chan_freq_power *find_cfp_by_band_and_freq(
David Woodhouseaa21c002007-12-08 20:04:36 +0000124 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +0100125 u8 band,
126 u32 freq)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127{
128 struct chan_freq_power *cfp = NULL;
129 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130 int i, j;
131
David Woodhouseaa21c002007-12-08 20:04:36 +0000132 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
133 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200134
David Woodhouseaa21c002007-12-08 20:04:36 +0000135 if (priv->enable11d)
136 rc = &priv->universal_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200137 if (!rc->valid || !rc->CFP)
138 continue;
139 if (rc->band != band)
140 continue;
141 for (i = 0; i < rc->nrcfp; i++) {
142 if (rc->CFP[i].freq == freq) {
143 cfp = &rc->CFP[i];
144 break;
145 }
146 }
147 }
148
149 if (!cfp && freq)
Holger Schurig9012b282007-05-25 11:27:16 -0400150 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
151 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152
153 return cfp;
154}
155
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156/**
Dan Williams8c512762007-08-02 11:40:45 -0400157 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000159 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000162static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200163{
Holger Schurig9012b282007-05-25 11:27:16 -0400164 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165
David Woodhouseaa21c002007-12-08 20:04:36 +0000166 if ((priv->connect_status != LBS_CONNECTED) &&
167 (priv->mesh_connect_status != LBS_CONNECTED))
Holger Schurig10078322007-11-15 18:05:47 -0500168 memcpy(rates, lbs_bg_rates, MAX_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400169 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000170 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200171
Dan Williams8c512762007-08-02 11:40:45 -0400172 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200173}
174
Holger Schurig10078322007-11-15 18:05:47 -0500175static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200176 char *cwrq, char *extra)
177{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200178
Holger Schurig9012b282007-05-25 11:27:16 -0400179 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200180
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400181 /* We could add support for 802.11n here as needed. Jean II */
182 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183
Holger Schurig9012b282007-05-25 11:27:16 -0400184 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185 return 0;
186}
187
Holger Schurig10078322007-11-15 18:05:47 -0500188static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200189 struct iw_freq *fwrq, char *extra)
190{
Kiran Divekarab65f642009-02-19 19:32:39 -0500191 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200192 struct chan_freq_power *cfp;
193
Holger Schurig9012b282007-05-25 11:27:16 -0400194 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200195
Amitkumar Karwar49125452009-09-30 20:04:38 -0700196 if (!lbs_is_cmd_allowed(priv)) {
197 lbs_deb_leave(LBS_DEB_WEXT);
198 return -EBUSY;
199 }
200
David Woodhouseaa21c002007-12-08 20:04:36 +0000201 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
202 priv->curbssparams.channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200203
204 if (!cfp) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000205 if (priv->curbssparams.channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400206 lbs_deb_wext("invalid channel %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000207 priv->curbssparams.channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200208 return -EINVAL;
209 }
210
211 fwrq->m = (long)cfp->freq * 100000;
212 fwrq->e = 1;
213
Holger Schurig9012b282007-05-25 11:27:16 -0400214 lbs_deb_wext("freq %u\n", fwrq->m);
215 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200216 return 0;
217}
218
Holger Schurig10078322007-11-15 18:05:47 -0500219static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220 struct sockaddr *awrq, char *extra)
221{
Kiran Divekarab65f642009-02-19 19:32:39 -0500222 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200223
Holger Schurig9012b282007-05-25 11:27:16 -0400224 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200225
David Woodhouseaa21c002007-12-08 20:04:36 +0000226 if (priv->connect_status == LBS_CONNECTED) {
227 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228 } else {
229 memset(awrq->sa_data, 0, ETH_ALEN);
230 }
231 awrq->sa_family = ARPHRD_ETHER;
232
Holger Schurig9012b282007-05-25 11:27:16 -0400233 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234 return 0;
235}
236
Holger Schurig10078322007-11-15 18:05:47 -0500237static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200238 struct iw_point *dwrq, char *extra)
239{
Kiran Divekarab65f642009-02-19 19:32:39 -0500240 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200241
Holger Schurig9012b282007-05-25 11:27:16 -0400242 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200243
244 /*
245 * Check the size of the string
246 */
247
248 if (dwrq->length > 16) {
249 return -E2BIG;
250 }
251
David Woodhouseaa21c002007-12-08 20:04:36 +0000252 mutex_lock(&priv->lock);
253 memset(priv->nodename, 0, sizeof(priv->nodename));
254 memcpy(priv->nodename, extra, dwrq->length);
255 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200256
Holger Schurig9012b282007-05-25 11:27:16 -0400257 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200258 return 0;
259}
260
Holger Schurig10078322007-11-15 18:05:47 -0500261static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200262 struct iw_point *dwrq, char *extra)
263{
Kiran Divekarab65f642009-02-19 19:32:39 -0500264 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265
Holger Schurig9012b282007-05-25 11:27:16 -0400266 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200267
David Woodhouseaa21c002007-12-08 20:04:36 +0000268 dwrq->length = strlen(priv->nodename);
269 memcpy(extra, priv->nodename, dwrq->length);
Holger Schurig04799fa2007-10-09 15:04:14 +0200270 extra[dwrq->length] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200271
Holger Schurig04799fa2007-10-09 15:04:14 +0200272 dwrq->flags = 1; /* active */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200273
Holger Schurig9012b282007-05-25 11:27:16 -0400274 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200275 return 0;
276}
277
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400278static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
279 struct iw_point *dwrq, char *extra)
280{
Kiran Divekarab65f642009-02-19 19:32:39 -0500281 struct lbs_private *priv = dev->ml_priv;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400282
283 lbs_deb_enter(LBS_DEB_WEXT);
284
285 /* Use nickname to indicate that mesh is on */
286
David Woodhouseaa21c002007-12-08 20:04:36 +0000287 if (priv->mesh_connect_status == LBS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400288 strncpy(extra, "Mesh", 12);
289 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400290 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400291 }
292
293 else {
294 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400295 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400296 }
297
298 lbs_deb_leave(LBS_DEB_WEXT);
299 return 0;
300}
Holger Schurig04799fa2007-10-09 15:04:14 +0200301
Holger Schurig10078322007-11-15 18:05:47 -0500302static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200303 struct iw_param *vwrq, char *extra)
304{
305 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -0500306 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400307 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200308
Holger Schurig9012b282007-05-25 11:27:16 -0400309 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200310
Amitkumar Karwar49125452009-09-30 20:04:38 -0700311 if (!lbs_is_cmd_allowed(priv)) {
312 ret = -EBUSY;
313 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
314 return ret;
315 }
316
Dan Williams39fcf7a2008-09-10 12:49:00 -0400317 if (vwrq->disabled)
318 val = MRVDRV_RTS_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200319
John W. Linville375da532008-09-15 17:25:54 -0400320 if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400321 return -EINVAL;
322
323 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324
Holger Schurig9012b282007-05-25 11:27:16 -0400325 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200326 return ret;
327}
328
Holger Schurig10078322007-11-15 18:05:47 -0500329static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200330 struct iw_param *vwrq, char *extra)
331{
Kiran Divekarab65f642009-02-19 19:32:39 -0500332 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400333 int ret = 0;
334 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200335
Holger Schurig9012b282007-05-25 11:27:16 -0400336 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200337
Amitkumar Karwar49125452009-09-30 20:04:38 -0700338 if (!lbs_is_cmd_allowed(priv)) {
339 ret = -EBUSY;
340 goto out;
341 }
342
Dan Williams39fcf7a2008-09-10 12:49:00 -0400343 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400344 if (ret)
345 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200346
Dan Williams39fcf7a2008-09-10 12:49:00 -0400347 vwrq->value = val;
John W. Linville375da532008-09-15 17:25:54 -0400348 vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349 vwrq->fixed = 1;
350
Holger Schurig9012b282007-05-25 11:27:16 -0400351out:
352 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
353 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354}
355
Holger Schurig10078322007-11-15 18:05:47 -0500356static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357 struct iw_param *vwrq, char *extra)
358{
Kiran Divekarab65f642009-02-19 19:32:39 -0500359 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400360 int ret = 0;
361 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200362
Holger Schurig9012b282007-05-25 11:27:16 -0400363 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364
Amitkumar Karwar49125452009-09-30 20:04:38 -0700365 if (!lbs_is_cmd_allowed(priv)) {
366 ret = -EBUSY;
367 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
368 return ret;
369 }
370
Dan Williams39fcf7a2008-09-10 12:49:00 -0400371 if (vwrq->disabled)
372 val = MRVDRV_FRAG_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373
Dan Williams39fcf7a2008-09-10 12:49:00 -0400374 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
375 return -EINVAL;
376
377 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
Holger Schurig9012b282007-05-25 11:27:16 -0400378
379 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200380 return ret;
381}
382
Holger Schurig10078322007-11-15 18:05:47 -0500383static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200384 struct iw_param *vwrq, char *extra)
385{
Kiran Divekarab65f642009-02-19 19:32:39 -0500386 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400387 int ret = 0;
388 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389
Holger Schurig9012b282007-05-25 11:27:16 -0400390 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391
Amitkumar Karwar49125452009-09-30 20:04:38 -0700392 if (!lbs_is_cmd_allowed(priv)) {
393 ret = -EBUSY;
394 goto out;
395 }
396
Dan Williams39fcf7a2008-09-10 12:49:00 -0400397 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400398 if (ret)
399 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400
Dan Williams39fcf7a2008-09-10 12:49:00 -0400401 vwrq->value = val;
402 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
403 || (val > MRVDRV_FRAG_MAX_VALUE));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404 vwrq->fixed = 1;
405
Holger Schurig9012b282007-05-25 11:27:16 -0400406out:
407 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408 return ret;
409}
410
Holger Schurig10078322007-11-15 18:05:47 -0500411static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200412 struct iw_request_info *info, u32 * uwrq, char *extra)
413{
Kiran Divekarab65f642009-02-19 19:32:39 -0500414 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200415
Holger Schurig9012b282007-05-25 11:27:16 -0400416 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417
David Woodhouseaa21c002007-12-08 20:04:36 +0000418 *uwrq = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419
Holger Schurig9012b282007-05-25 11:27:16 -0400420 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200421 return 0;
422}
423
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400424static int mesh_wlan_get_mode(struct net_device *dev,
425 struct iw_request_info *info, u32 * uwrq,
426 char *extra)
427{
428 lbs_deb_enter(LBS_DEB_WEXT);
429
Dan Williams39fcf7a2008-09-10 12:49:00 -0400430 *uwrq = IW_MODE_REPEAT;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400431
432 lbs_deb_leave(LBS_DEB_WEXT);
433 return 0;
434}
435
Holger Schurig10078322007-11-15 18:05:47 -0500436static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437 struct iw_request_info *info,
438 struct iw_param *vwrq, char *extra)
439{
Kiran Divekarab65f642009-02-19 19:32:39 -0500440 struct lbs_private *priv = dev->ml_priv;
Dan Williams87c8c722008-08-19 15:15:35 -0400441 s16 curlevel = 0;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400442 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200443
Holger Schurig9012b282007-05-25 11:27:16 -0400444 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200445
Amitkumar Karwar49125452009-09-30 20:04:38 -0700446 if (!lbs_is_cmd_allowed(priv)) {
447 ret = -EBUSY;
448 goto out;
449 }
450
Dan Williamsd5db2df2008-08-21 17:51:07 -0400451 if (!priv->radio_on) {
452 lbs_deb_wext("tx power off\n");
453 vwrq->value = 0;
454 vwrq->disabled = 1;
455 goto out;
456 }
457
Dan Williams87c8c722008-08-19 15:15:35 -0400458 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400459 if (ret)
460 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200461
Dan Williams87c8c722008-08-19 15:15:35 -0400462 lbs_deb_wext("tx power level %d dbm\n", curlevel);
Dan Williams87c8c722008-08-19 15:15:35 -0400463 priv->txpower_cur = curlevel;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400464
Dan Williams87c8c722008-08-19 15:15:35 -0400465 vwrq->value = curlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200466 vwrq->fixed = 1;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400467 vwrq->disabled = 0;
468 vwrq->flags = IW_TXPOW_DBM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469
Holger Schurig9012b282007-05-25 11:27:16 -0400470out:
471 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
472 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200473}
474
Holger Schurig10078322007-11-15 18:05:47 -0500475static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 struct iw_param *vwrq, char *extra)
477{
Kiran Divekarab65f642009-02-19 19:32:39 -0500478 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400479 int ret = 0;
480 u16 slimit = 0, llimit = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481
Holger Schurig9012b282007-05-25 11:27:16 -0400482 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483
Amitkumar Karwar49125452009-09-30 20:04:38 -0700484 if (!lbs_is_cmd_allowed(priv)) {
485 ret = -EBUSY;
486 goto out;
487 }
488
Dan Williams39fcf7a2008-09-10 12:49:00 -0400489 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
490 return -EOPNOTSUPP;
491
492 /* The MAC has a 4-bit Total_Tx_Count register
493 Total_Tx_Count = 1 + Tx_Retry_Count */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200494#define TX_RETRY_MIN 0
495#define TX_RETRY_MAX 14
Dan Williams39fcf7a2008-09-10 12:49:00 -0400496 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
497 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200498
Dan Williams39fcf7a2008-09-10 12:49:00 -0400499 /* Add 1 to convert retry count to try count */
500 if (vwrq->flags & IW_RETRY_SHORT)
501 slimit = (u16) (vwrq->value + 1);
502 else if (vwrq->flags & IW_RETRY_LONG)
503 llimit = (u16) (vwrq->value + 1);
504 else
505 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200506
Dan Williams39fcf7a2008-09-10 12:49:00 -0400507 if (llimit) {
508 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
509 llimit);
Holger Schurig9012b282007-05-25 11:27:16 -0400510 if (ret)
511 goto out;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400512 }
513
514 if (slimit) {
515 /* txretrycount follows the short retry limit */
516 priv->txretrycount = slimit;
517 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
518 slimit);
519 if (ret)
520 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200521 }
522
Holger Schurig9012b282007-05-25 11:27:16 -0400523out:
524 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
525 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200526}
527
Holger Schurig10078322007-11-15 18:05:47 -0500528static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529 struct iw_param *vwrq, char *extra)
530{
Kiran Divekarab65f642009-02-19 19:32:39 -0500531 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200532 int ret = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400533 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200534
Holger Schurig9012b282007-05-25 11:27:16 -0400535 lbs_deb_enter(LBS_DEB_WEXT);
536
Amitkumar Karwar49125452009-09-30 20:04:38 -0700537 if (!lbs_is_cmd_allowed(priv)) {
538 ret = -EBUSY;
539 goto out;
540 }
541
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200542 vwrq->disabled = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400543
544 if (vwrq->flags & IW_RETRY_LONG) {
545 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
546 if (ret)
547 goto out;
548
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200549 /* Subtract 1 to convert try count to retry count */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400550 vwrq->value = val - 1;
551 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
552 } else {
553 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
554 if (ret)
555 goto out;
556
557 /* txretry count follows the short retry limit */
558 priv->txretrycount = val;
559 /* Subtract 1 to convert try count to retry count */
560 vwrq->value = val - 1;
561 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200562 }
563
Holger Schurig9012b282007-05-25 11:27:16 -0400564out:
565 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
566 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567}
568
569static inline void sort_channels(struct iw_freq *freq, int num)
570{
571 int i, j;
572 struct iw_freq temp;
573
574 for (i = 0; i < num; i++)
575 for (j = i + 1; j < num; j++)
576 if (freq[i].i > freq[j].i) {
577 temp.i = freq[i].i;
578 temp.m = freq[i].m;
579
580 freq[i].i = freq[j].i;
581 freq[i].m = freq[j].m;
582
583 freq[j].i = temp.i;
584 freq[j].m = temp.m;
585 }
586}
587
588/* data rate listing
589 MULTI_BANDS:
590 abg a b b/g
591 Infra G(12) A(8) B(4) G(12)
592 Adhoc A+B(12) A(8) B(4) B(4)
593
594 non-MULTI_BANDS:
595 b b/g
596 Infra B(4) G(12)
597 Adhoc B(4) B(4)
598 */
599/**
600 * @brief Get Range Info
601 *
602 * @param dev A pointer to net_device structure
603 * @param info A pointer to iw_request_info structure
604 * @param vwrq A pointer to iw_param structure
605 * @param extra A pointer to extra data buf
606 * @return 0 --success, otherwise fail
607 */
Holger Schurig10078322007-11-15 18:05:47 -0500608static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609 struct iw_point *dwrq, char *extra)
610{
611 int i, j;
Kiran Divekarab65f642009-02-19 19:32:39 -0500612 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200613 struct iw_range *range = (struct iw_range *)extra;
614 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400615 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616
617 u8 flag = 0;
618
Holger Schurig9012b282007-05-25 11:27:16 -0400619 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200620
621 dwrq->length = sizeof(struct iw_range);
622 memset(range, 0, sizeof(struct iw_range));
623
624 range->min_nwid = 0;
625 range->max_nwid = 0;
626
627 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000628 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400629 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
630 for (i = 0; i < range->num_bitrates; i++)
631 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200632 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400633 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634 range->num_bitrates);
635
636 range->num_frequency = 0;
Holger Schurig52933d82008-03-05 07:05:32 +0100637
638 range->scan_capa = IW_SCAN_CAPA_ESSID;
639
David Woodhouseaa21c002007-12-08 20:04:36 +0000640 if (priv->enable11d &&
641 (priv->connect_status == LBS_CONNECTED ||
642 priv->mesh_connect_status == LBS_CONNECTED)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200643 u8 chan_no;
644 u8 band;
645
646 struct parsed_region_chan_11d *parsed_region_chan =
David Woodhouseaa21c002007-12-08 20:04:36 +0000647 &priv->parsed_region_chan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200648
649 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400650 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
651 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200652 }
653 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400654 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200655 parsed_region_chan->nr_chan);
656
657 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
658 && (i < parsed_region_chan->nr_chan); i++) {
659 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400660 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200661 range->freq[range->num_frequency].i = (long)chan_no;
662 range->freq[range->num_frequency].m =
Holger Schurige98a88d2008-03-19 14:25:58 +0100663 (long)lbs_chan_2_freq(chan_no) * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200664 range->freq[range->num_frequency].e = 1;
665 range->num_frequency++;
666 }
667 flag = 1;
668 }
669 if (!flag) {
670 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000671 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
672 cfp = priv->region_channel[j].CFP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200673 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000674 && priv->region_channel[j].valid
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200675 && cfp
David Woodhouseaa21c002007-12-08 20:04:36 +0000676 && (i < priv->region_channel[j].nrcfp); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200677 range->freq[range->num_frequency].i =
678 (long)cfp->channel;
679 range->freq[range->num_frequency].m =
680 (long)cfp->freq * 100000;
681 range->freq[range->num_frequency].e = 1;
682 cfp++;
683 range->num_frequency++;
684 }
685 }
686 }
687
Holger Schurig9012b282007-05-25 11:27:16 -0400688 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200689 IW_MAX_FREQUENCIES, range->num_frequency);
690
691 range->num_channels = range->num_frequency;
692
693 sort_channels(&range->freq[0], range->num_frequency);
694
695 /*
696 * Set an indication of the max TCP throughput in bit/s that we can
697 * expect using this interface
698 */
699 if (i > 2)
700 range->throughput = 5000 * 1000;
701 else
702 range->throughput = 1500 * 1000;
703
704 range->min_rts = MRVDRV_RTS_MIN_VALUE;
705 range->max_rts = MRVDRV_RTS_MAX_VALUE;
706 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
707 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
708
709 range->encoding_size[0] = 5;
710 range->encoding_size[1] = 13;
711 range->num_encoding_sizes = 2;
712 range->max_encoding_tokens = 4;
713
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100714 /*
715 * Right now we support only "iwconfig ethX power on|off"
716 */
717 range->pm_capa = IW_POWER_ON;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200718
719 /*
720 * Minimum version we recommend
721 */
722 range->we_version_source = 15;
723
724 /*
725 * Version we are compiled with
726 */
727 range->we_version_compiled = WIRELESS_EXT;
728
729 range->retry_capa = IW_RETRY_LIMIT;
730 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
731
732 range->min_retry = TX_RETRY_MIN;
733 range->max_retry = TX_RETRY_MAX;
734
735 /*
736 * Set the qual, level and noise range values
737 */
738 range->max_qual.qual = 100;
739 range->max_qual.level = 0;
740 range->max_qual.noise = 0;
741 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
742
743 range->avg_qual.qual = 70;
744 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
745 range->avg_qual.level = 0;
746 range->avg_qual.noise = 0;
747 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
748
749 range->sensitivity = 0;
750
Dan Williams87c8c722008-08-19 15:15:35 -0400751 /* Setup the supported power level ranges */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200752 memset(range->txpower, 0, sizeof(range->txpower));
Dan Williams87c8c722008-08-19 15:15:35 -0400753 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
754 range->txpower[0] = priv->txpower_min;
755 range->txpower[1] = priv->txpower_max;
756 range->num_txpower = 2;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200757
758 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
759 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
760 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
761 range->event_capa[1] = IW_EVENT_CAPA_K_1;
762
David Woodhouseaa21c002007-12-08 20:04:36 +0000763 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200764 range->enc_capa = IW_ENC_CAPA_WPA
765 | IW_ENC_CAPA_WPA2
766 | IW_ENC_CAPA_CIPHER_TKIP
767 | IW_ENC_CAPA_CIPHER_CCMP;
768 }
769
Holger Schurig9012b282007-05-25 11:27:16 -0400770out:
771 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200772 return 0;
773}
774
Holger Schurig10078322007-11-15 18:05:47 -0500775static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200776 struct iw_param *vwrq, char *extra)
777{
Kiran Divekarab65f642009-02-19 19:32:39 -0500778 struct lbs_private *priv = dev->ml_priv;
Amitkumar Karwar49125452009-09-30 20:04:38 -0700779 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200780
Holger Schurig9012b282007-05-25 11:27:16 -0400781 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200782
Andrey Yurovskye0d61332009-06-16 13:20:01 -0700783 if (!(priv->fwcapinfo & FW_CAPINFO_PS)) {
David Woodhouseb2c57ee2007-12-17 14:41:13 -0500784 if (vwrq->disabled)
785 return 0;
786 else
787 return -EINVAL;
788 }
789
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200790 /* PS is currently supported only in Infrastructure mode
791 * Remove this check if it is to be supported in IBSS mode also
792 */
793
794 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000795 priv->psmode = LBS802_11POWERMODECAM;
796 if (priv->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500797 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200798 }
799
800 return 0;
801 }
802
803 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400804 lbs_deb_wext(
805 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200806 return -EINVAL;
807 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Amitkumar Karwar49125452009-09-30 20:04:38 -0700808 vwrq->value = vwrq->value / 1000;
809 if (!priv->enter_deep_sleep) {
810 lbs_pr_err("deep sleep feature is not implemented "
811 "for this interface driver\n");
812 return -EINVAL;
813 }
814
815 if (priv->connect_status == LBS_CONNECTED) {
816 if ((priv->is_auto_deep_sleep_enabled) &&
817 (vwrq->value == -1000)) {
818 lbs_exit_auto_deep_sleep(priv);
819 return 0;
820 } else {
821 lbs_pr_err("can't use deep sleep cmd in "
822 "connected state\n");
823 return -EINVAL;
824 }
825 }
826
827 if ((vwrq->value < 0) && (vwrq->value != -1000)) {
828 lbs_pr_err("unknown option\n");
829 return -EINVAL;
830 }
831
832 if (vwrq->value > 0) {
833 if (!priv->is_auto_deep_sleep_enabled) {
834 priv->is_activity_detected = 0;
835 priv->auto_deep_sleep_timeout = vwrq->value;
836 lbs_enter_auto_deep_sleep(priv);
837 } else {
838 priv->auto_deep_sleep_timeout = vwrq->value;
839 lbs_deb_debugfs("auto deep sleep: "
840 "already enabled\n");
841 }
842 return 0;
843 } else {
844 if (priv->is_auto_deep_sleep_enabled) {
845 lbs_exit_auto_deep_sleep(priv);
846 /* Try to exit deep sleep if auto */
847 /*deep sleep disabled */
848 ret = lbs_set_deep_sleep(priv, 0);
849 }
850 if (vwrq->value == 0)
851 ret = lbs_set_deep_sleep(priv, 1);
852 else if (vwrq->value == -1000)
853 ret = lbs_set_deep_sleep(priv, 0);
854 return ret;
855 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856 }
857
David Woodhouseaa21c002007-12-08 20:04:36 +0000858 if (priv->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200859 return 0;
860 }
861
David Woodhouseaa21c002007-12-08 20:04:36 +0000862 priv->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200863
David Woodhouseaa21c002007-12-08 20:04:36 +0000864 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500865 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200866 }
867
Holger Schurig9012b282007-05-25 11:27:16 -0400868 lbs_deb_leave(LBS_DEB_WEXT);
Amitkumar Karwar49125452009-09-30 20:04:38 -0700869
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200870 return 0;
871}
872
Holger Schurig10078322007-11-15 18:05:47 -0500873static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200874 struct iw_param *vwrq, char *extra)
875{
Kiran Divekarab65f642009-02-19 19:32:39 -0500876 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200877
Holger Schurig9012b282007-05-25 11:27:16 -0400878 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200879
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200880 vwrq->value = 0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100881 vwrq->flags = 0;
882 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
883 || priv->connect_status == LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200884
Holger Schurig9012b282007-05-25 11:27:16 -0400885 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200886 return 0;
887}
888
Holger Schurig10078322007-11-15 18:05:47 -0500889static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200890{
891 enum {
892 POOR = 30,
893 FAIR = 60,
894 GOOD = 80,
895 VERY_GOOD = 90,
896 EXCELLENT = 95,
897 PERFECT = 100
898 };
Kiran Divekarab65f642009-02-19 19:32:39 -0500899 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200900 u32 rssi_qual;
901 u32 tx_qual;
902 u32 quality = 0;
903 int stats_valid = 0;
904 u8 rssi;
905 u32 tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100906 struct cmd_ds_802_11_get_log log;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200907
Holger Schurig9012b282007-05-25 11:27:16 -0400908 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200909
Amitkumar Karwar49125452009-09-30 20:04:38 -0700910 if (!lbs_is_cmd_allowed(priv))
911 return NULL;
912
David Woodhouseaa21c002007-12-08 20:04:36 +0000913 priv->wstats.status = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200914
915 /* If we're not associated, all quality values are meaningless */
David Woodhouseaa21c002007-12-08 20:04:36 +0000916 if ((priv->connect_status != LBS_CONNECTED) &&
917 (priv->mesh_connect_status != LBS_CONNECTED))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200918 goto out;
919
920 /* Quality by RSSI */
921 priv->wstats.qual.level =
David Woodhouseaa21c002007-12-08 20:04:36 +0000922 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
923 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200924
David Woodhouseaa21c002007-12-08 20:04:36 +0000925 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200926 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
927 } else {
928 priv->wstats.qual.noise =
David Woodhouseaa21c002007-12-08 20:04:36 +0000929 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200930 }
931
Holger Schurig9012b282007-05-25 11:27:16 -0400932 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
933 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200934
935 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
936 if (rssi < 15)
937 rssi_qual = rssi * POOR / 10;
938 else if (rssi < 20)
939 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
940 else if (rssi < 30)
941 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
942 else if (rssi < 40)
943 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
944 10 + GOOD;
945 else
946 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
947 10 + VERY_GOOD;
948 quality = rssi_qual;
949
950 /* Quality by TX errors */
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000951 priv->wstats.discard.retries = dev->stats.tx_errors;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200952
Holger Schurigc49c3b72008-03-17 12:45:58 +0100953 memset(&log, 0, sizeof(log));
954 log.hdr.size = cpu_to_le16(sizeof(log));
955 lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
956
957 tx_retries = le32_to_cpu(log.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200958
959 if (tx_retries > 75)
960 tx_qual = (90 - tx_retries) * POOR / 15;
961 else if (tx_retries > 70)
962 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
963 else if (tx_retries > 65)
964 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
965 else if (tx_retries > 50)
966 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
967 15 + GOOD;
968 else
969 tx_qual = (50 - tx_retries) *
970 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
971 quality = min(quality, tx_qual);
972
Holger Schurigc49c3b72008-03-17 12:45:58 +0100973 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200974 priv->wstats.discard.retries = tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100975 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200976
977 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400978 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200979 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
980 stats_valid = 1;
981
982 /* update stats asynchronously for future calls */
Holger Schurig10078322007-11-15 18:05:47 -0500983 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200984 0, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200985out:
986 if (!stats_valid) {
987 priv->wstats.miss.beacon = 0;
988 priv->wstats.discard.retries = 0;
989 priv->wstats.qual.qual = 0;
990 priv->wstats.qual.level = 0;
991 priv->wstats.qual.noise = 0;
992 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
993 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
994 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
995 }
996
Holger Schurig9012b282007-05-25 11:27:16 -0400997 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200998 return &priv->wstats;
999
1000
1001}
1002
Holger Schurig10078322007-11-15 18:05:47 -05001003static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001004 struct iw_freq *fwrq, char *extra)
1005{
Dan Williamsef9a2642007-05-25 16:46:33 -04001006 int ret = -EINVAL;
Kiran Divekarab65f642009-02-19 19:32:39 -05001007 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001008 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -04001009 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001010
Holger Schurig9012b282007-05-25 11:27:16 -04001011 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001012
Amitkumar Karwar49125452009-09-30 20:04:38 -07001013 if (!lbs_is_cmd_allowed(priv)) {
1014 ret = -EBUSY;
1015 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1016 return ret;
1017 }
1018
David Woodhouseaa21c002007-12-08 20:04:36 +00001019 mutex_lock(&priv->lock);
1020 assoc_req = lbs_get_association_request(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -04001021 if (!assoc_req) {
1022 ret = -ENOMEM;
1023 goto out;
1024 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001025
Dan Williamsef9a2642007-05-25 16:46:33 -04001026 /* If setting by frequency, convert to a channel */
1027 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001028 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029
David Woodhouseaa21c002007-12-08 20:04:36 +00001030 cfp = find_cfp_by_band_and_freq(priv, 0, f);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001031 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -04001032 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -04001033 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001034 }
1035
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001036 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -04001037 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001038 }
1039
Dan Williamsef9a2642007-05-25 16:46:33 -04001040 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001041 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -04001042 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001043 }
1044
David Woodhouseaa21c002007-12-08 20:04:36 +00001045 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -04001046 if (!cfp) {
1047 goto out;
1048 }
1049
1050 assoc_req->channel = fwrq->m;
1051 ret = 0;
1052
Holger Schurig9012b282007-05-25 11:27:16 -04001053out:
Dan Williamsef9a2642007-05-25 16:46:33 -04001054 if (ret == 0) {
1055 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001056 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -04001057 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001058 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -04001059 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001060 mutex_unlock(&priv->lock);
Dan Williamsef9a2642007-05-25 16:46:33 -04001061
1062 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1063 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064}
1065
David Woodhouse823eaa22007-12-11 19:56:28 -05001066static int lbs_mesh_set_freq(struct net_device *dev,
1067 struct iw_request_info *info,
1068 struct iw_freq *fwrq, char *extra)
1069{
Kiran Divekarab65f642009-02-19 19:32:39 -05001070 struct lbs_private *priv = dev->ml_priv;
David Woodhouse823eaa22007-12-11 19:56:28 -05001071 struct chan_freq_power *cfp;
1072 int ret = -EINVAL;
1073
1074 lbs_deb_enter(LBS_DEB_WEXT);
1075
1076 /* If setting by frequency, convert to a channel */
1077 if (fwrq->e == 1) {
1078 long f = fwrq->m / 100000;
1079
1080 cfp = find_cfp_by_band_and_freq(priv, 0, f);
1081 if (!cfp) {
1082 lbs_deb_wext("invalid freq %ld\n", f);
1083 goto out;
1084 }
1085
1086 fwrq->e = 0;
1087 fwrq->m = (int) cfp->channel;
1088 }
1089
1090 /* Setting by channel number */
1091 if (fwrq->m > 1000 || fwrq->e > 0) {
1092 goto out;
1093 }
1094
1095 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
1096 if (!cfp) {
1097 goto out;
1098 }
1099
1100 if (fwrq->m != priv->curbssparams.channel) {
1101 lbs_deb_wext("mesh channel change forces eth disconnect\n");
1102 if (priv->mode == IW_MODE_INFRA)
Dan Williams191bb402008-08-21 17:46:18 -04001103 lbs_cmd_80211_deauthenticate(priv,
1104 priv->curbssparams.bssid,
1105 WLAN_REASON_DEAUTH_LEAVING);
David Woodhouse823eaa22007-12-11 19:56:28 -05001106 else if (priv->mode == IW_MODE_ADHOC)
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001107 lbs_adhoc_stop(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -05001108 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001109 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
David Woodhouse86062132007-12-13 00:32:36 -05001110 lbs_update_channel(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -05001111 ret = 0;
1112
1113out:
1114 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1115 return ret;
1116}
1117
Holger Schurig10078322007-11-15 18:05:47 -05001118static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001119 struct iw_param *vwrq, char *extra)
1120{
Kiran Divekarab65f642009-02-19 19:32:39 -05001121 struct lbs_private *priv = dev->ml_priv;
Dan Williams8e3c91b2007-12-11 15:50:59 -05001122 u8 new_rate = 0;
Dan Williams8c512762007-08-02 11:40:45 -04001123 int ret = -EINVAL;
1124 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001125
Holger Schurig9012b282007-05-25 11:27:16 -04001126 lbs_deb_enter(LBS_DEB_WEXT);
Amitkumar Karwar49125452009-09-30 20:04:38 -07001127
1128 if (!lbs_is_cmd_allowed(priv)) {
1129 ret = -EBUSY;
1130 goto out;
1131 }
1132
Holger Schurig9012b282007-05-25 11:27:16 -04001133 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Javier Cardona85319f92008-05-24 10:59:49 +01001134 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1135
1136 if (vwrq->fixed && vwrq->value == -1)
1137 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001138
Dan Williams8c512762007-08-02 11:40:45 -04001139 /* Auto rate? */
Javier Cardona85319f92008-05-24 10:59:49 +01001140 priv->enablehwauto = !vwrq->fixed;
1141
1142 if (vwrq->value == -1)
David Woodhouseaa21c002007-12-08 20:04:36 +00001143 priv->cur_rate = 0;
Javier Cardona85319f92008-05-24 10:59:49 +01001144 else {
Dan Williams8c512762007-08-02 11:40:45 -04001145 if (vwrq->value % 100000)
1146 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001147
Javier Cardona85319f92008-05-24 10:59:49 +01001148 new_rate = vwrq->value / 500000;
1149 priv->cur_rate = new_rate;
1150 /* the rest is only needed for lbs_set_data_rate() */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001151 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +00001152 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -04001153 if (!memchr(rates, new_rate, sizeof(rates))) {
1154 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1155 new_rate);
1156 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001157 }
Anna Neal3ed6e082008-09-26 11:34:35 -04001158 if (priv->fwrelease < 0x09000000) {
1159 ret = lbs_set_power_adapt_cfg(priv, 0,
1160 POW_ADAPT_DEFAULT_P0,
1161 POW_ADAPT_DEFAULT_P1,
1162 POW_ADAPT_DEFAULT_P2);
1163 if (ret)
1164 goto out;
1165 }
1166 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1167 TPC_DEFAULT_P2, 1);
1168 if (ret)
1169 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170 }
1171
Javier Cardona85319f92008-05-24 10:59:49 +01001172 /* Try the newer command first (Firmware Spec 5.1 and above) */
1173 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1174
1175 /* Fallback to older version */
1176 if (ret)
1177 ret = lbs_set_data_rate(priv, new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001178
Dan Williams8c512762007-08-02 11:40:45 -04001179out:
Holger Schurig9012b282007-05-25 11:27:16 -04001180 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001181 return ret;
1182}
1183
Holger Schurig10078322007-11-15 18:05:47 -05001184static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001185 struct iw_param *vwrq, char *extra)
1186{
Kiran Divekarab65f642009-02-19 19:32:39 -05001187 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001188
Holger Schurig9012b282007-05-25 11:27:16 -04001189 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001190
Amitkumar Karwar49125452009-09-30 20:04:38 -07001191 if (!lbs_is_cmd_allowed(priv)) {
1192 lbs_deb_leave(LBS_DEB_WEXT);
1193 return -EBUSY;
1194 }
1195
David Woodhouseaa21c002007-12-08 20:04:36 +00001196 if (priv->connect_status == LBS_CONNECTED) {
1197 vwrq->value = priv->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001198
Javier Cardona85319f92008-05-24 10:59:49 +01001199 if (priv->enablehwauto)
Dan Williams8c512762007-08-02 11:40:45 -04001200 vwrq->fixed = 0;
1201 else
1202 vwrq->fixed = 1;
1203
1204 } else {
1205 vwrq->fixed = 0;
1206 vwrq->value = 0;
1207 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001208
Holger Schurig9012b282007-05-25 11:27:16 -04001209 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001210 return 0;
1211}
1212
Holger Schurig10078322007-11-15 18:05:47 -05001213static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001214 struct iw_request_info *info, u32 * uwrq, char *extra)
1215{
1216 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001217 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001218 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001219
Holger Schurig9012b282007-05-25 11:27:16 -04001220 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001221
Amitkumar Karwar49125452009-09-30 20:04:38 -07001222 if (!lbs_is_cmd_allowed(priv)) {
1223 ret = -EBUSY;
1224 goto out;
1225 }
1226
Dan Williams0dc5a292007-05-10 22:58:02 -04001227 if ( (*uwrq != IW_MODE_ADHOC)
1228 && (*uwrq != IW_MODE_INFRA)
1229 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001230 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001231 ret = -EINVAL;
1232 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001233 }
1234
David Woodhouseaa21c002007-12-08 20:04:36 +00001235 mutex_lock(&priv->lock);
1236 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001237 if (!assoc_req) {
1238 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001239 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001240 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001241 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001242 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001243 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001244 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001245 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001246 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001247
Dan Williams0dc5a292007-05-10 22:58:02 -04001248out:
Holger Schurig9012b282007-05-25 11:27:16 -04001249 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001250 return ret;
1251}
1252
1253
1254/**
1255 * @brief Get Encryption key
1256 *
1257 * @param dev A pointer to net_device structure
1258 * @param info A pointer to iw_request_info structure
1259 * @param vwrq A pointer to iw_param structure
1260 * @param extra A pointer to extra data buf
1261 * @return 0 --success, otherwise fail
1262 */
Holger Schurig10078322007-11-15 18:05:47 -05001263static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001264 struct iw_request_info *info,
1265 struct iw_point *dwrq, u8 * extra)
1266{
Kiran Divekarab65f642009-02-19 19:32:39 -05001267 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001268 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1269
Holger Schurig9012b282007-05-25 11:27:16 -04001270 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001271
Holger Schurig9012b282007-05-25 11:27:16 -04001272 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001273 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001274
1275 dwrq->flags = 0;
1276
1277 /* Authentication method */
David Woodhouseaa21c002007-12-08 20:04:36 +00001278 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -04001279 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001280 dwrq->flags = IW_ENCODE_OPEN;
1281 break;
1282
Dan Williams6affe782007-05-10 22:56:42 -04001283 case IW_AUTH_ALG_SHARED_KEY:
1284 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001285 dwrq->flags = IW_ENCODE_RESTRICTED;
1286 break;
1287 default:
1288 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1289 break;
1290 }
1291
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001292 memset(extra, 0, 16);
1293
David Woodhouseaa21c002007-12-08 20:04:36 +00001294 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001295
1296 /* Default to returning current transmit key */
1297 if (index < 0)
David Woodhouseaa21c002007-12-08 20:04:36 +00001298 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001299
David Woodhouseaa21c002007-12-08 20:04:36 +00001300 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1301 memcpy(extra, priv->wep_keys[index].key,
1302 priv->wep_keys[index].len);
1303 dwrq->length = priv->wep_keys[index].len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001304
1305 dwrq->flags |= (index + 1);
1306 /* Return WEP enabled */
1307 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhouseaa21c002007-12-08 20:04:36 +00001308 } else if ((priv->secinfo.WPAenabled)
1309 || (priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001310 /* return WPA enabled */
1311 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhousec12bdc42007-12-07 19:32:12 +00001312 dwrq->flags |= IW_ENCODE_NOKEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001313 } else {
1314 dwrq->flags |= IW_ENCODE_DISABLED;
1315 }
1316
David Woodhouseaa21c002007-12-08 20:04:36 +00001317 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001318
Joe Perches0795af52007-10-03 17:59:30 -07001319 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001320 extra[0], extra[1], extra[2],
1321 extra[3], extra[4], extra[5], dwrq->length);
1322
Holger Schurig9012b282007-05-25 11:27:16 -04001323 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001324
Holger Schurig9012b282007-05-25 11:27:16 -04001325 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001326 return 0;
1327}
1328
1329/**
1330 * @brief Set Encryption key (internal)
1331 *
1332 * @param priv A pointer to private card structure
1333 * @param key_material A pointer to key material
1334 * @param key_length length of key material
1335 * @param index key index to set
1336 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1337 * @return 0 --success, otherwise fail
1338 */
Holger Schurig10078322007-11-15 18:05:47 -05001339static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001340 const char *key_material,
1341 u16 key_length,
1342 u16 index,
1343 int set_tx_key)
1344{
Holger Schurig9012b282007-05-25 11:27:16 -04001345 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001346 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001347
Holger Schurig9012b282007-05-25 11:27:16 -04001348 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349
1350 /* Paranoid validation of key index */
1351 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001352 ret = -EINVAL;
1353 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001354 }
1355
1356 /* validate max key length */
1357 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001358 ret = -EINVAL;
1359 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001360 }
1361
1362 pkey = &assoc_req->wep_keys[index];
1363
1364 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001365 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001366 pkey->type = KEY_TYPE_ID_WEP;
1367
1368 /* Standardize the key length */
1369 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1370 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1371 memcpy(pkey->key, key_material, key_length);
1372 }
1373
1374 if (set_tx_key) {
1375 /* Ensure the chosen key is valid */
1376 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001377 lbs_deb_wext("key not set, so cannot enable it\n");
1378 ret = -EINVAL;
1379 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001380 }
1381 assoc_req->wep_tx_keyidx = index;
1382 }
1383
Dan Williams889c05b2007-05-10 22:57:23 -04001384 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001385
Holger Schurig9012b282007-05-25 11:27:16 -04001386out:
1387 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1388 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001389}
1390
1391static int validate_key_index(u16 def_index, u16 raw_index,
1392 u16 *out_index, u16 *is_default)
1393{
1394 if (!out_index || !is_default)
1395 return -EINVAL;
1396
1397 /* Verify index if present, otherwise use default TX key index */
1398 if (raw_index > 0) {
1399 if (raw_index > 4)
1400 return -EINVAL;
1401 *out_index = raw_index - 1;
1402 } else {
1403 *out_index = def_index;
1404 *is_default = 1;
1405 }
1406 return 0;
1407}
1408
1409static void disable_wep(struct assoc_request *assoc_req)
1410{
1411 int i;
1412
Dan Williams90a42212007-05-25 23:01:24 -04001413 lbs_deb_enter(LBS_DEB_WEXT);
1414
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001415 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001416 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001417
1418 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001419 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001420 for (i = 0; i < 4; i++)
1421 assoc_req->wep_keys[i].len = 0;
1422
1423 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1424 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001425
1426 lbs_deb_leave(LBS_DEB_WEXT);
1427}
1428
1429static void disable_wpa(struct assoc_request *assoc_req)
1430{
1431 lbs_deb_enter(LBS_DEB_WEXT);
1432
Dan Williams1443b652007-08-02 10:45:55 -04001433 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001434 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1435 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1436
Dan Williams1443b652007-08-02 10:45:55 -04001437 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001438 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1439 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1440
1441 assoc_req->secinfo.WPAenabled = 0;
1442 assoc_req->secinfo.WPA2enabled = 0;
1443 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1444
1445 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001446}
1447
1448/**
1449 * @brief Set Encryption key
1450 *
1451 * @param dev A pointer to net_device structure
1452 * @param info A pointer to iw_request_info structure
1453 * @param vwrq A pointer to iw_param structure
1454 * @param extra A pointer to extra data buf
1455 * @return 0 --success, otherwise fail
1456 */
Holger Schurig10078322007-11-15 18:05:47 -05001457static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001458 struct iw_request_info *info,
1459 struct iw_point *dwrq, char *extra)
1460{
1461 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001462 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001463 struct assoc_request * assoc_req;
1464 u16 is_default = 0, index = 0, set_tx_key = 0;
1465
Holger Schurig9012b282007-05-25 11:27:16 -04001466 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001467
Amitkumar Karwar49125452009-09-30 20:04:38 -07001468 if (!lbs_is_cmd_allowed(priv)) {
1469 ret = -EBUSY;
1470 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1471 return ret;
1472 }
1473
David Woodhouseaa21c002007-12-08 20:04:36 +00001474 mutex_lock(&priv->lock);
1475 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001476 if (!assoc_req) {
1477 ret = -ENOMEM;
1478 goto out;
1479 }
1480
1481 if (dwrq->flags & IW_ENCODE_DISABLED) {
1482 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001483 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001484 goto out;
1485 }
1486
1487 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1488 (dwrq->flags & IW_ENCODE_INDEX),
1489 &index, &is_default);
1490 if (ret) {
1491 ret = -EINVAL;
1492 goto out;
1493 }
1494
1495 /* If WEP isn't enabled, or if there is no key data but a valid
1496 * index, set the TX key.
1497 */
Dan Williams889c05b2007-05-10 22:57:23 -04001498 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001499 set_tx_key = 1;
1500
Holger Schurig10078322007-11-15 18:05:47 -05001501 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001502 if (ret)
1503 goto out;
1504
1505 if (dwrq->length)
1506 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1507 if (set_tx_key)
1508 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1509
1510 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001511 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001512 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001513 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001514 }
1515
1516out:
1517 if (ret == 0) {
1518 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001519 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001520 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001521 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001522 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001523 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001524
Holger Schurig9012b282007-05-25 11:27:16 -04001525 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001526 return ret;
1527}
1528
1529/**
1530 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1531 *
1532 * @param dev A pointer to net_device structure
1533 * @param info A pointer to iw_request_info structure
1534 * @param vwrq A pointer to iw_param structure
1535 * @param extra A pointer to extra data buf
1536 * @return 0 on success, otherwise failure
1537 */
Holger Schurig10078322007-11-15 18:05:47 -05001538static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001539 struct iw_request_info *info,
1540 struct iw_point *dwrq,
1541 char *extra)
1542{
1543 int ret = -EINVAL;
Kiran Divekarab65f642009-02-19 19:32:39 -05001544 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001545 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1546 int index, max_key_len;
1547
Holger Schurig9012b282007-05-25 11:27:16 -04001548 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001549
1550 max_key_len = dwrq->length - sizeof(*ext);
1551 if (max_key_len < 0)
1552 goto out;
1553
1554 index = dwrq->flags & IW_ENCODE_INDEX;
1555 if (index) {
1556 if (index < 1 || index > 4)
1557 goto out;
1558 index--;
1559 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001560 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001561 }
1562
Roel Kluinf59d9782007-10-26 21:51:26 +02001563 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001564 ext->alg != IW_ENCODE_ALG_WEP) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001565 if (index != 0 || priv->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001566 goto out;
1567 }
1568
1569 dwrq->flags = index + 1;
1570 memset(ext, 0, sizeof(*ext));
1571
David Woodhouseaa21c002007-12-08 20:04:36 +00001572 if ( !priv->secinfo.wep_enabled
1573 && !priv->secinfo.WPAenabled
1574 && !priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001575 ext->alg = IW_ENCODE_ALG_NONE;
1576 ext->key_len = 0;
1577 dwrq->flags |= IW_ENCODE_DISABLED;
1578 } else {
1579 u8 *key = NULL;
1580
David Woodhouseaa21c002007-12-08 20:04:36 +00001581 if ( priv->secinfo.wep_enabled
1582 && !priv->secinfo.WPAenabled
1583 && !priv->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001584 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001585 ext->alg = IW_ENCODE_ALG_WEP;
David Woodhouseaa21c002007-12-08 20:04:36 +00001586 ext->key_len = priv->wep_keys[index].len;
1587 key = &priv->wep_keys[index].key[0];
1588 } else if ( !priv->secinfo.wep_enabled
1589 && (priv->secinfo.WPAenabled ||
1590 priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001591 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001592 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001593
David Woodhouseaa21c002007-12-08 20:04:36 +00001594 if ( priv->wpa_mcast_key.len
1595 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1596 pkey = &priv->wpa_mcast_key;
1597 else if ( priv->wpa_unicast_key.len
1598 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1599 pkey = &priv->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001600
1601 if (pkey) {
1602 if (pkey->type == KEY_TYPE_ID_AES) {
1603 ext->alg = IW_ENCODE_ALG_CCMP;
1604 } else {
1605 ext->alg = IW_ENCODE_ALG_TKIP;
1606 }
1607 ext->key_len = pkey->len;
1608 key = &pkey->key[0];
1609 } else {
1610 ext->alg = IW_ENCODE_ALG_TKIP;
1611 ext->key_len = 0;
1612 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001613 } else {
1614 goto out;
1615 }
1616
1617 if (ext->key_len > max_key_len) {
1618 ret = -E2BIG;
1619 goto out;
1620 }
1621
1622 if (ext->key_len)
1623 memcpy(ext->key, key, ext->key_len);
1624 else
1625 dwrq->flags |= IW_ENCODE_NOKEY;
1626 dwrq->flags |= IW_ENCODE_ENABLED;
1627 }
1628 ret = 0;
1629
1630out:
Holger Schurig9012b282007-05-25 11:27:16 -04001631 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001632 return ret;
1633}
1634
1635/**
1636 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1637 *
1638 * @param dev A pointer to net_device structure
1639 * @param info A pointer to iw_request_info structure
1640 * @param vwrq A pointer to iw_param structure
1641 * @param extra A pointer to extra data buf
1642 * @return 0 --success, otherwise fail
1643 */
Holger Schurig10078322007-11-15 18:05:47 -05001644static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001645 struct iw_request_info *info,
1646 struct iw_point *dwrq,
1647 char *extra)
1648{
1649 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001650 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001651 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1652 int alg = ext->alg;
1653 struct assoc_request * assoc_req;
1654
Holger Schurig9012b282007-05-25 11:27:16 -04001655 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001656
Amitkumar Karwar49125452009-09-30 20:04:38 -07001657 if (!lbs_is_cmd_allowed(priv)) {
1658 ret = -EBUSY;
1659 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1660 return ret;
1661 }
1662
David Woodhouseaa21c002007-12-08 20:04:36 +00001663 mutex_lock(&priv->lock);
1664 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001665 if (!assoc_req) {
1666 ret = -ENOMEM;
1667 goto out;
1668 }
1669
1670 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1671 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001672 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001673 } else if (alg == IW_ENCODE_ALG_WEP) {
1674 u16 is_default = 0, index, set_tx_key = 0;
1675
1676 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1677 (dwrq->flags & IW_ENCODE_INDEX),
1678 &index, &is_default);
1679 if (ret)
1680 goto out;
1681
1682 /* If WEP isn't enabled, or if there is no key data but a valid
1683 * index, or if the set-TX-key flag was passed, set the TX key.
1684 */
Dan Williams889c05b2007-05-10 22:57:23 -04001685 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001686 || (dwrq->length == 0 && !is_default)
1687 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1688 set_tx_key = 1;
1689
1690 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001691 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001692 set_tx_key);
1693 if (ret)
1694 goto out;
1695
1696 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001697 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001698 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001699 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001700 }
1701
1702 /* Mark the various WEP bits as modified */
1703 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1704 if (dwrq->length)
1705 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1706 if (set_tx_key)
1707 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001708 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001709 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001710
1711 /* validate key length */
1712 if (((alg == IW_ENCODE_ALG_TKIP)
1713 && (ext->key_len != KEY_LEN_WPA_TKIP))
1714 || ((alg == IW_ENCODE_ALG_CCMP)
1715 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001716 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001717 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001718 ext->key_len,
1719 alg);
1720 ret = -EINVAL;
1721 goto out;
1722 }
1723
Dan Williams90a42212007-05-25 23:01:24 -04001724 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001725 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001726 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1727 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001728 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001729 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1730 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001731
Dan Williams1443b652007-08-02 10:45:55 -04001732 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001733 memcpy(pkey->key, ext->key, ext->key_len);
1734 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001735 if (pkey->len)
1736 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001737
Dan Williams90a42212007-05-25 23:01:24 -04001738 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001739 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1740 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001741 } else {
1742 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001743 }
1744
Dan Williams90a42212007-05-25 23:01:24 -04001745 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001746 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001747 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001748 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001749 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001750
1751 /* If WPA isn't enabled yet, do that now */
1752 if ( assoc_req->secinfo.WPAenabled == 0
1753 && assoc_req->secinfo.WPA2enabled == 0) {
1754 assoc_req->secinfo.WPAenabled = 1;
1755 assoc_req->secinfo.WPA2enabled = 1;
1756 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1757 }
1758
Javier Cardona9c31fd632008-09-11 15:32:50 -07001759 /* Only disable wep if necessary: can't waste time here. */
1760 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1761 disable_wep(assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001762 }
1763
1764out:
Javier Cardona9c40fc52008-09-16 18:08:39 -07001765 if (ret == 0) {
1766 /* 802.1x and WPA rekeying must happen as quickly as possible,
1767 * especially during the 4-way handshake; thus if in
1768 * infrastructure mode, and either (a) 802.1x is enabled or
1769 * (b) WPA is being used, set the key right away.
1770 */
1771 if (assoc_req->mode == IW_MODE_INFRA &&
1772 ((assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_802_1X) ||
1773 (assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_PSK) ||
1774 assoc_req->secinfo.WPAenabled ||
1775 assoc_req->secinfo.WPA2enabled)) {
1776 lbs_do_association_work(priv);
1777 } else
1778 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001779 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001780 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001781 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001782 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001783
Holger Schurig9012b282007-05-25 11:27:16 -04001784 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001785 return ret;
1786}
1787
1788
Holger Schurig10078322007-11-15 18:05:47 -05001789static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001790 struct iw_request_info *info,
1791 struct iw_point *dwrq,
1792 char *extra)
1793{
Kiran Divekarab65f642009-02-19 19:32:39 -05001794 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001795 int ret = 0;
1796 struct assoc_request * assoc_req;
1797
Holger Schurig9012b282007-05-25 11:27:16 -04001798 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001799
David Woodhouseaa21c002007-12-08 20:04:36 +00001800 mutex_lock(&priv->lock);
1801 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001802 if (!assoc_req) {
1803 ret = -ENOMEM;
1804 goto out;
1805 }
1806
1807 if (dwrq->length > MAX_WPA_IE_LEN ||
1808 (dwrq->length && extra == NULL)) {
1809 ret = -EINVAL;
1810 goto out;
1811 }
1812
1813 if (dwrq->length) {
1814 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1815 assoc_req->wpa_ie_len = dwrq->length;
1816 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001817 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001818 assoc_req->wpa_ie_len = 0;
1819 }
1820
1821out:
1822 if (ret == 0) {
1823 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001824 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001825 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001826 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001827 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001828 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001829
Holger Schurig9012b282007-05-25 11:27:16 -04001830 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001831 return ret;
1832}
1833
Holger Schurig10078322007-11-15 18:05:47 -05001834static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001835 struct iw_request_info *info,
1836 struct iw_point *dwrq,
1837 char *extra)
1838{
Holger Schurig9012b282007-05-25 11:27:16 -04001839 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001840 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001841
Holger Schurig9012b282007-05-25 11:27:16 -04001842 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001843
David Woodhouseaa21c002007-12-08 20:04:36 +00001844 if (priv->wpa_ie_len == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001846 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001847 }
1848
David Woodhouseaa21c002007-12-08 20:04:36 +00001849 if (dwrq->length < priv->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001850 ret = -E2BIG;
1851 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001852 }
1853
David Woodhouseaa21c002007-12-08 20:04:36 +00001854 dwrq->length = priv->wpa_ie_len;
1855 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001856
Holger Schurig9012b282007-05-25 11:27:16 -04001857out:
1858 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1859 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001860}
1861
1862
Holger Schurig10078322007-11-15 18:05:47 -05001863static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001864 struct iw_request_info *info,
1865 struct iw_param *dwrq,
1866 char *extra)
1867{
Kiran Divekarab65f642009-02-19 19:32:39 -05001868 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001869 struct assoc_request * assoc_req;
1870 int ret = 0;
1871 int updated = 0;
1872
Holger Schurig9012b282007-05-25 11:27:16 -04001873 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001874
Amitkumar Karwar49125452009-09-30 20:04:38 -07001875 if (!lbs_is_cmd_allowed(priv)) {
1876 ret = -EBUSY;
1877 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1878 return ret;
1879 }
1880
David Woodhouseaa21c002007-12-08 20:04:36 +00001881 mutex_lock(&priv->lock);
1882 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001883 if (!assoc_req) {
1884 ret = -ENOMEM;
1885 goto out;
1886 }
1887
1888 switch (dwrq->flags & IW_AUTH_INDEX) {
Maithili Hinge2c8d5102009-07-31 20:02:19 -07001889 case IW_AUTH_PRIVACY_INVOKED:
1890 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001891 case IW_AUTH_TKIP_COUNTERMEASURES:
1892 case IW_AUTH_CIPHER_PAIRWISE:
1893 case IW_AUTH_CIPHER_GROUP:
Dan Williams90a42212007-05-25 23:01:24 -04001894 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001895 /*
1896 * libertas does not use these parameters
1897 */
1898 break;
1899
Javier Cardona9c40fc52008-09-16 18:08:39 -07001900 case IW_AUTH_KEY_MGMT:
1901 assoc_req->secinfo.key_mgmt = dwrq->value;
1902 updated = 1;
1903 break;
1904
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001905 case IW_AUTH_WPA_VERSION:
1906 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1907 assoc_req->secinfo.WPAenabled = 0;
1908 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001909 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001910 }
1911 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1912 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001913 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001914 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001915 }
1916 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1917 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001918 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001919 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001920 }
1921 updated = 1;
1922 break;
1923
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001924 case IW_AUTH_80211_AUTH_ALG:
1925 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001926 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001927 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001928 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001929 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001930 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001931 } else {
1932 ret = -EINVAL;
1933 }
1934 updated = 1;
1935 break;
1936
1937 case IW_AUTH_WPA_ENABLED:
1938 if (dwrq->value) {
1939 if (!assoc_req->secinfo.WPAenabled &&
1940 !assoc_req->secinfo.WPA2enabled) {
1941 assoc_req->secinfo.WPAenabled = 1;
1942 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001943 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001944 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001945 }
1946 } else {
1947 assoc_req->secinfo.WPAenabled = 0;
1948 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001949 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001950 }
1951 updated = 1;
1952 break;
1953
1954 default:
1955 ret = -EOPNOTSUPP;
1956 break;
1957 }
1958
1959out:
1960 if (ret == 0) {
1961 if (updated)
1962 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001963 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001964 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001965 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001966 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001967 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001968
Holger Schurig9012b282007-05-25 11:27:16 -04001969 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001970 return ret;
1971}
1972
Holger Schurig10078322007-11-15 18:05:47 -05001973static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001974 struct iw_request_info *info,
1975 struct iw_param *dwrq,
1976 char *extra)
1977{
Holger Schurig9012b282007-05-25 11:27:16 -04001978 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001979 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001980
Holger Schurig9012b282007-05-25 11:27:16 -04001981 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001982
Amitkumar Karwar49125452009-09-30 20:04:38 -07001983 if (!lbs_is_cmd_allowed(priv)) {
1984 ret = -EBUSY;
1985 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1986 return ret;
1987 }
1988
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001989 switch (dwrq->flags & IW_AUTH_INDEX) {
Javier Cardona9c40fc52008-09-16 18:08:39 -07001990 case IW_AUTH_KEY_MGMT:
1991 dwrq->value = priv->secinfo.key_mgmt;
1992 break;
1993
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001994 case IW_AUTH_WPA_VERSION:
1995 dwrq->value = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +00001996 if (priv->secinfo.WPAenabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001997 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
David Woodhouseaa21c002007-12-08 20:04:36 +00001998 if (priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001999 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
2000 if (!dwrq->value)
2001 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
2002 break;
2003
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002004 case IW_AUTH_80211_AUTH_ALG:
David Woodhouseaa21c002007-12-08 20:04:36 +00002005 dwrq->value = priv->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002006 break;
2007
2008 case IW_AUTH_WPA_ENABLED:
David Woodhouseaa21c002007-12-08 20:04:36 +00002009 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002010 dwrq->value = 1;
2011 break;
2012
2013 default:
Holger Schurig9012b282007-05-25 11:27:16 -04002014 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002015 }
2016
Holger Schurig9012b282007-05-25 11:27:16 -04002017 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2018 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002019}
2020
2021
Holger Schurig10078322007-11-15 18:05:47 -05002022static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002023 struct iw_param *vwrq, char *extra)
2024{
2025 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05002026 struct lbs_private *priv = dev->ml_priv;
Dan Williams87c8c722008-08-19 15:15:35 -04002027 s16 dbm = (s16) vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002028
Holger Schurig9012b282007-05-25 11:27:16 -04002029 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002030
Amitkumar Karwar49125452009-09-30 20:04:38 -07002031 if (!lbs_is_cmd_allowed(priv)) {
2032 ret = -EBUSY;
2033 goto out;
2034 }
2035
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002036 if (vwrq->disabled) {
Dan Williamsd5db2df2008-08-21 17:51:07 -04002037 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
Dan Williams87c8c722008-08-19 15:15:35 -04002038 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002039 }
2040
Dan Williams87c8c722008-08-19 15:15:35 -04002041 if (vwrq->fixed == 0) {
Anna Neal0112c9e2008-09-11 11:17:25 -07002042 /* User requests automatic tx power control, however there are
2043 * many auto tx settings. For now use firmware defaults until
2044 * we come up with a good way to expose these to the user. */
2045 if (priv->fwrelease < 0x09000000) {
2046 ret = lbs_set_power_adapt_cfg(priv, 1,
2047 POW_ADAPT_DEFAULT_P0,
2048 POW_ADAPT_DEFAULT_P1,
2049 POW_ADAPT_DEFAULT_P2);
2050 if (ret)
2051 goto out;
2052 }
2053 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
2054 TPC_DEFAULT_P2, 1);
2055 if (ret)
2056 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04002057 dbm = priv->txpower_max;
2058 } else {
2059 /* Userspace check in iwrange if it should use dBm or mW,
2060 * therefore this should never happen... Jean II */
2061 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
2062 ret = -EOPNOTSUPP;
2063 goto out;
2064 }
2065
Anna Neal0112c9e2008-09-11 11:17:25 -07002066 /* Validate requested power level against firmware allowed
2067 * levels */
Dan Williams87c8c722008-08-19 15:15:35 -04002068 if (priv->txpower_min && (dbm < priv->txpower_min)) {
2069 ret = -EINVAL;
2070 goto out;
2071 }
2072
2073 if (priv->txpower_max && (dbm > priv->txpower_max)) {
2074 ret = -EINVAL;
2075 goto out;
2076 }
Anna Neal0112c9e2008-09-11 11:17:25 -07002077 if (priv->fwrelease < 0x09000000) {
2078 ret = lbs_set_power_adapt_cfg(priv, 0,
2079 POW_ADAPT_DEFAULT_P0,
2080 POW_ADAPT_DEFAULT_P1,
2081 POW_ADAPT_DEFAULT_P2);
2082 if (ret)
2083 goto out;
2084 }
2085 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
2086 TPC_DEFAULT_P2, 1);
2087 if (ret)
2088 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04002089 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002090
Dan Williamsd5db2df2008-08-21 17:51:07 -04002091 /* If the radio was off, turn it on */
2092 if (!priv->radio_on) {
2093 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
2094 if (ret)
2095 goto out;
2096 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002097
Dan Williams87c8c722008-08-19 15:15:35 -04002098 lbs_deb_wext("txpower set %d dBm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002099
Dan Williams87c8c722008-08-19 15:15:35 -04002100 ret = lbs_set_tx_power(priv, dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002101
Dan Williams87c8c722008-08-19 15:15:35 -04002102out:
Holger Schurig9012b282007-05-25 11:27:16 -04002103 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002104 return ret;
2105}
2106
Holger Schurig10078322007-11-15 18:05:47 -05002107static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002108 struct iw_point *dwrq, char *extra)
2109{
Kiran Divekarab65f642009-02-19 19:32:39 -05002110 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002111
Holger Schurig9012b282007-05-25 11:27:16 -04002112 lbs_deb_enter(LBS_DEB_WEXT);
2113
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002114 /*
2115 * Note : if dwrq->flags != 0, we should get the relevant SSID from
2116 * the SSID list...
2117 */
2118
2119 /*
2120 * Get the current SSID
2121 */
David Woodhouseaa21c002007-12-08 20:04:36 +00002122 if (priv->connect_status == LBS_CONNECTED) {
2123 memcpy(extra, priv->curbssparams.ssid,
2124 priv->curbssparams.ssid_len);
2125 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002126 } else {
2127 memset(extra, 0, 32);
David Woodhouseaa21c002007-12-08 20:04:36 +00002128 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002129 }
2130 /*
2131 * If none, we may want to get the one that was set
2132 */
2133
David Woodhouseaa21c002007-12-08 20:04:36 +00002134 dwrq->length = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002135
2136 dwrq->flags = 1; /* active */
2137
Holger Schurig9012b282007-05-25 11:27:16 -04002138 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002139 return 0;
2140}
2141
Holger Schurig10078322007-11-15 18:05:47 -05002142static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002143 struct iw_point *dwrq, char *extra)
2144{
Kiran Divekarab65f642009-02-19 19:32:39 -05002145 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002146 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04002147 u8 ssid[IW_ESSID_MAX_SIZE];
2148 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002149 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04002150 int in_ssid_len = dwrq->length;
John W. Linville9387b7c2008-09-30 20:59:05 -04002151 DECLARE_SSID_BUF(ssid_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002152
Holger Schurig9012b282007-05-25 11:27:16 -04002153 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002154
Amitkumar Karwar49125452009-09-30 20:04:38 -07002155 if (!lbs_is_cmd_allowed(priv)) {
2156 ret = -EBUSY;
2157 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2158 return ret;
2159 }
2160
Dan Williamsd5db2df2008-08-21 17:51:07 -04002161 if (!priv->radio_on) {
2162 ret = -EINVAL;
2163 goto out;
2164 }
2165
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002166 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04002167 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002168 ret = -E2BIG;
2169 goto out;
2170 }
2171
Dan Williamsd8efea22007-05-28 23:54:55 -04002172 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002173
Dan Williamsd8efea22007-05-28 23:54:55 -04002174 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002175 /* "any" SSID requested; leave SSID blank */
2176 } else {
2177 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04002178 memcpy(&ssid, extra, in_ssid_len);
2179 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002180 }
2181
Dan Williamsd8efea22007-05-28 23:54:55 -04002182 if (!ssid_len) {
2183 lbs_deb_wext("requested any SSID\n");
2184 } else {
2185 lbs_deb_wext("requested SSID '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04002186 print_ssid(ssid_buf, ssid, ssid_len));
Dan Williamsd8efea22007-05-28 23:54:55 -04002187 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002188
2189out:
David Woodhouseaa21c002007-12-08 20:04:36 +00002190 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002191 if (ret == 0) {
2192 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002193 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002194 if (!assoc_req) {
2195 ret = -ENOMEM;
2196 } else {
2197 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04002198 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
2199 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002200 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002201 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002202 }
2203 }
2204
2205 /* Cancel the association request if there was an error */
2206 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05002207 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002208 }
2209
David Woodhouseaa21c002007-12-08 20:04:36 +00002210 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002211
Holger Schurig9012b282007-05-25 11:27:16 -04002212 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002213 return ret;
2214}
2215
David Woodhousef5956bf2007-12-11 19:30:57 -05002216static int lbs_mesh_get_essid(struct net_device *dev,
2217 struct iw_request_info *info,
2218 struct iw_point *dwrq, char *extra)
2219{
Kiran Divekarab65f642009-02-19 19:32:39 -05002220 struct lbs_private *priv = dev->ml_priv;
David Woodhousef5956bf2007-12-11 19:30:57 -05002221
2222 lbs_deb_enter(LBS_DEB_WEXT);
2223
2224 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2225
2226 dwrq->length = priv->mesh_ssid_len;
2227
2228 dwrq->flags = 1; /* active */
2229
2230 lbs_deb_leave(LBS_DEB_WEXT);
2231 return 0;
2232}
2233
2234static int lbs_mesh_set_essid(struct net_device *dev,
2235 struct iw_request_info *info,
2236 struct iw_point *dwrq, char *extra)
2237{
Kiran Divekarab65f642009-02-19 19:32:39 -05002238 struct lbs_private *priv = dev->ml_priv;
David Woodhousef5956bf2007-12-11 19:30:57 -05002239 int ret = 0;
2240
2241 lbs_deb_enter(LBS_DEB_WEXT);
2242
Dan Williamsd5db2df2008-08-21 17:51:07 -04002243 if (!priv->radio_on) {
2244 ret = -EINVAL;
2245 goto out;
2246 }
2247
David Woodhousef5956bf2007-12-11 19:30:57 -05002248 /* Check the size of the string */
2249 if (dwrq->length > IW_ESSID_MAX_SIZE) {
2250 ret = -E2BIG;
2251 goto out;
2252 }
2253
2254 if (!dwrq->flags || !dwrq->length) {
2255 ret = -EINVAL;
2256 goto out;
2257 } else {
2258 /* Specific SSID requested */
2259 memcpy(priv->mesh_ssid, extra, dwrq->length);
2260 priv->mesh_ssid_len = dwrq->length;
2261 }
2262
Javier Cardonaedaea5c2008-05-17 00:55:10 -07002263 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
2264 priv->curbssparams.channel);
David Woodhousef5956bf2007-12-11 19:30:57 -05002265 out:
2266 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2267 return ret;
2268}
2269
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002270/**
2271 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2272 *
2273 * @param dev A pointer to net_device structure
2274 * @param info A pointer to iw_request_info structure
2275 * @param awrq A pointer to iw_param structure
2276 * @param extra A pointer to extra data buf
2277 * @return 0 --success, otherwise fail
2278 */
Holger Schurig10078322007-11-15 18:05:47 -05002279static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002280 struct sockaddr *awrq, char *extra)
2281{
Kiran Divekarab65f642009-02-19 19:32:39 -05002282 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002283 struct assoc_request * assoc_req;
2284 int ret = 0;
2285
Holger Schurig9012b282007-05-25 11:27:16 -04002286 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002287
Amitkumar Karwar49125452009-09-30 20:04:38 -07002288 if (!lbs_is_cmd_allowed(priv)) {
2289 ret = -EBUSY;
2290 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2291 return ret;
2292 }
2293
Dan Williamsd5db2df2008-08-21 17:51:07 -04002294 if (!priv->radio_on)
2295 return -EINVAL;
2296
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002297 if (awrq->sa_family != ARPHRD_ETHER)
2298 return -EINVAL;
2299
Johannes Berge1749612008-10-27 15:59:26 -07002300 lbs_deb_wext("ASSOC: WAP: sa_data %pM\n", awrq->sa_data);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002301
David Woodhouseaa21c002007-12-08 20:04:36 +00002302 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002303
2304 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002305 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002306 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05002307 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002308 ret = -ENOMEM;
2309 } else {
2310 /* Copy the BSSID to the association request */
2311 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2312 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002313 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002314 }
2315
David Woodhouseaa21c002007-12-08 20:04:36 +00002316 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002317
2318 return ret;
2319}
2320
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002321/*
2322 * iwconfig settable callbacks
2323 */
Holger Schurig10078322007-11-15 18:05:47 -05002324static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002325 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002326 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002327 (iw_handler) NULL, /* SIOCSIWNWID */
2328 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002329 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2330 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2331 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2332 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002333 (iw_handler) NULL, /* SIOCSIWSENS */
2334 (iw_handler) NULL, /* SIOCGIWSENS */
2335 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002336 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002337 (iw_handler) NULL, /* SIOCSIWPRIV */
2338 (iw_handler) NULL, /* SIOCGIWPRIV */
2339 (iw_handler) NULL, /* SIOCSIWSTATS */
2340 (iw_handler) NULL, /* SIOCGIWSTATS */
2341 iw_handler_set_spy, /* SIOCSIWSPY */
2342 iw_handler_get_spy, /* SIOCGIWSPY */
2343 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2344 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002345 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2346 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002347 (iw_handler) NULL, /* SIOCSIWMLME */
2348 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002349 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2350 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2351 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2352 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2353 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2354 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002355 (iw_handler) NULL, /* -- hole -- */
2356 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002357 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2358 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2359 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2360 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2361 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2362 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2363 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2364 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2365 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2366 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2367 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2368 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2369 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2370 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002371 (iw_handler) NULL, /* -- hole -- */
2372 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002373 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2374 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2375 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2376 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2377 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2378 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002379 (iw_handler) NULL, /* SIOCSIWPMKSA */
2380};
2381
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002382static const iw_handler mesh_wlan_handler[] = {
2383 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002384 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002385 (iw_handler) NULL, /* SIOCSIWNWID */
2386 (iw_handler) NULL, /* SIOCGIWNWID */
David Woodhouse823eaa22007-12-11 19:56:28 -05002387 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
Holger Schurig10078322007-11-15 18:05:47 -05002388 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002389 (iw_handler) NULL, /* SIOCSIWMODE */
2390 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2391 (iw_handler) NULL, /* SIOCSIWSENS */
2392 (iw_handler) NULL, /* SIOCGIWSENS */
2393 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002394 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002395 (iw_handler) NULL, /* SIOCSIWPRIV */
2396 (iw_handler) NULL, /* SIOCGIWPRIV */
2397 (iw_handler) NULL, /* SIOCSIWSTATS */
2398 (iw_handler) NULL, /* SIOCGIWSTATS */
2399 iw_handler_set_spy, /* SIOCSIWSPY */
2400 iw_handler_get_spy, /* SIOCGIWSPY */
2401 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2402 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2403 (iw_handler) NULL, /* SIOCSIWAP */
2404 (iw_handler) NULL, /* SIOCGIWAP */
2405 (iw_handler) NULL, /* SIOCSIWMLME */
2406 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002407 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2408 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
David Woodhousef5956bf2007-12-11 19:30:57 -05002409 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2410 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002411 (iw_handler) NULL, /* SIOCSIWNICKN */
2412 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2413 (iw_handler) NULL, /* -- hole -- */
2414 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002415 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2416 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2417 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2418 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2419 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2420 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2421 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2422 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2423 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2424 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2425 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2426 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2427 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2428 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002429 (iw_handler) NULL, /* -- hole -- */
2430 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002431 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2432 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2433 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2434 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2435 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2436 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002437 (iw_handler) NULL, /* SIOCSIWPMKSA */
2438};
Holger Schurig10078322007-11-15 18:05:47 -05002439struct iw_handler_def lbs_handler_def = {
2440 .num_standard = ARRAY_SIZE(lbs_handler),
2441 .standard = (iw_handler *) lbs_handler,
2442 .get_wireless_stats = lbs_get_wireless_stats,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002443};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002444
2445struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002446 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002447 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002448 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002449};