blob: 9b555884b08a99dd1c936f49245549a5b87266db [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains ioctl functions
3 */
4#include <linux/ctype.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09005#include <linux/slab.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02006#include <linux/delay.h>
7#include <linux/if.h>
8#include <linux/if_arp.h>
9#include <linux/wireless.h>
10#include <linux/bitops.h>
11
John W. Linville7e272fc2008-09-24 18:13:14 -040012#include <net/lib80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020013#include <net/iw_handler.h>
14
15#include "host.h"
16#include "radiotap.h"
17#include "decl.h"
18#include "defs.h"
19#include "dev.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020#include "wext.h"
Holger Schurig245bf202008-04-02 16:27:42 +020021#include "scan.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022#include "assoc.h"
Dan Williams8e3c91b2007-12-11 15:50:59 -050023#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024
25
Holger Schurig69f90322007-11-23 15:43:44 +010026static inline void lbs_postpone_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020027{
David Woodhouseaa21c002007-12-08 20:04:36 +000028 if (priv->surpriseremoved)
Holger Schurig9f9dac22007-10-26 10:12:14 +020029 return;
30 cancel_delayed_work(&priv->assoc_work);
31 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
32}
33
Javier Cardona9c31fd62008-09-11 15:32:50 -070034static inline void lbs_do_association_work(struct lbs_private *priv)
35{
36 if (priv->surpriseremoved)
37 return;
38 cancel_delayed_work(&priv->assoc_work);
39 queue_delayed_work(priv->work_thread, &priv->assoc_work, 0);
40}
41
Holger Schurig69f90322007-11-23 15:43:44 +010042static inline void lbs_cancel_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020043{
44 cancel_delayed_work(&priv->assoc_work);
David Woodhouseaa21c002007-12-08 20:04:36 +000045 kfree(priv->pending_assoc_req);
46 priv->pending_assoc_req = NULL;
Holger Schurig9f9dac22007-10-26 10:12:14 +020047}
48
Holger Schurigfea2b8e2009-10-22 15:30:56 +020049void lbs_send_disconnect_notification(struct lbs_private *priv)
50{
51 union iwreq_data wrqu;
52
53 memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
54 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
55 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
56}
57
Holger Schurig560c6332009-10-22 15:30:57 +020058static void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
Holger Schurig6e85e0b2009-10-22 15:30:52 +020059{
60 union iwreq_data iwrq;
61 u8 buf[50];
62
63 lbs_deb_enter(LBS_DEB_WEXT);
64
65 memset(&iwrq, 0, sizeof(union iwreq_data));
66 memset(buf, 0, sizeof(buf));
67
68 snprintf(buf, sizeof(buf) - 1, "%s", str);
69
70 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
71
72 /* Send Event to upper layer */
73 lbs_deb_wext("event indication string %s\n", (char *)buf);
74 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
75 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
76
77 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
78
79 lbs_deb_leave(LBS_DEB_WEXT);
80}
81
Amitkumar Karwar49125452009-09-30 20:04:38 -070082/**
Holger Schurig560c6332009-10-22 15:30:57 +020083 * @brief This function handles MIC failure event.
84 *
85 * @param priv A pointer to struct lbs_private structure
86 * @para event the event id
87 * @return n/a
88 */
89void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
90{
91 char buf[50];
92
93 lbs_deb_enter(LBS_DEB_CMD);
94 memset(buf, 0, sizeof(buf));
95
96 sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication ");
97
98 if (event == MACREG_INT_CODE_MIC_ERR_UNICAST)
99 strcat(buf, "unicast ");
100 else
101 strcat(buf, "multicast ");
102
103 lbs_send_iwevcustom_event(priv, buf);
104 lbs_deb_leave(LBS_DEB_CMD);
105}
106
107/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200108 * @brief Find the channel frequency power info with specific channel
109 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000110 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200111 * @param band it can be BAND_A, BAND_G or BAND_B
112 * @param channel the channel for looking
113 * @return A pointer to struct chan_freq_power structure or NULL if not find.
114 */
Holger Schurig69f90322007-11-23 15:43:44 +0100115struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
David Woodhouseaa21c002007-12-08 20:04:36 +0000116 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +0100117 u8 band,
118 u16 channel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200119{
120 struct chan_freq_power *cfp = NULL;
121 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122 int i, j;
123
David Woodhouseaa21c002007-12-08 20:04:36 +0000124 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
125 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200126
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127 if (!rc->valid || !rc->CFP)
128 continue;
129 if (rc->band != band)
130 continue;
131 for (i = 0; i < rc->nrcfp; i++) {
132 if (rc->CFP[i].channel == channel) {
133 cfp = &rc->CFP[i];
134 break;
135 }
136 }
137 }
138
139 if (!cfp && channel)
Holger Schurig10078322007-11-15 18:05:47 -0500140 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
Holger Schurig9012b282007-05-25 11:27:16 -0400141 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142
143 return cfp;
144}
145
146/**
147 * @brief Find the channel frequency power info with specific frequency
148 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000149 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200150 * @param band it can be BAND_A, BAND_G or BAND_B
151 * @param freq the frequency for looking
152 * @return A pointer to struct chan_freq_power structure or NULL if not find.
153 */
Holger Schurig69f90322007-11-23 15:43:44 +0100154static struct chan_freq_power *find_cfp_by_band_and_freq(
David Woodhouseaa21c002007-12-08 20:04:36 +0000155 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +0100156 u8 band,
157 u32 freq)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158{
159 struct chan_freq_power *cfp = NULL;
160 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161 int i, j;
162
David Woodhouseaa21c002007-12-08 20:04:36 +0000163 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
164 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200166 if (!rc->valid || !rc->CFP)
167 continue;
168 if (rc->band != band)
169 continue;
170 for (i = 0; i < rc->nrcfp; i++) {
171 if (rc->CFP[i].freq == freq) {
172 cfp = &rc->CFP[i];
173 break;
174 }
175 }
176 }
177
178 if (!cfp && freq)
Holger Schurig9012b282007-05-25 11:27:16 -0400179 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
180 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181
182 return cfp;
183}
184
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185/**
Dan Williams8c512762007-08-02 11:40:45 -0400186 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200187 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000188 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200189 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000191static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200192{
Holger Schurig9012b282007-05-25 11:27:16 -0400193 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200194
David Woodhouseaa21c002007-12-08 20:04:36 +0000195 if ((priv->connect_status != LBS_CONNECTED) &&
Holger Schurig602114a2009-12-02 15:26:01 +0100196 !lbs_mesh_connected(priv))
Holger Schurig10078322007-11-15 18:05:47 -0500197 memcpy(rates, lbs_bg_rates, MAX_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400198 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000199 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200
Dan Williams8c512762007-08-02 11:40:45 -0400201 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200202}
203
Holger Schurig10078322007-11-15 18:05:47 -0500204static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200205 char *cwrq, char *extra)
206{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200207
Holger Schurig9012b282007-05-25 11:27:16 -0400208 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200209
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400210 /* We could add support for 802.11n here as needed. Jean II */
211 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200212
Holger Schurig9012b282007-05-25 11:27:16 -0400213 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200214 return 0;
215}
216
Holger Schurig10078322007-11-15 18:05:47 -0500217static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200218 struct iw_freq *fwrq, char *extra)
219{
Kiran Divekarab65f642009-02-19 19:32:39 -0500220 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200221 struct chan_freq_power *cfp;
222
Holger Schurig9012b282007-05-25 11:27:16 -0400223 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224
David Woodhouseaa21c002007-12-08 20:04:36 +0000225 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
Holger Schurigc14951f2009-10-22 15:30:50 +0200226 priv->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227
228 if (!cfp) {
Holger Schurigc14951f2009-10-22 15:30:50 +0200229 if (priv->channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400230 lbs_deb_wext("invalid channel %d\n",
Holger Schurigc14951f2009-10-22 15:30:50 +0200231 priv->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200232 return -EINVAL;
233 }
234
235 fwrq->m = (long)cfp->freq * 100000;
236 fwrq->e = 1;
237
Holger Schurig9012b282007-05-25 11:27:16 -0400238 lbs_deb_wext("freq %u\n", fwrq->m);
239 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240 return 0;
241}
242
Holger Schurig10078322007-11-15 18:05:47 -0500243static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244 struct sockaddr *awrq, char *extra)
245{
Kiran Divekarab65f642009-02-19 19:32:39 -0500246 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200247
Holger Schurig9012b282007-05-25 11:27:16 -0400248 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200249
David Woodhouseaa21c002007-12-08 20:04:36 +0000250 if (priv->connect_status == LBS_CONNECTED) {
251 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200252 } else {
253 memset(awrq->sa_data, 0, ETH_ALEN);
254 }
255 awrq->sa_family = ARPHRD_ETHER;
256
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_set_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
268 /*
269 * Check the size of the string
270 */
271
272 if (dwrq->length > 16) {
273 return -E2BIG;
274 }
275
David Woodhouseaa21c002007-12-08 20:04:36 +0000276 mutex_lock(&priv->lock);
277 memset(priv->nodename, 0, sizeof(priv->nodename));
278 memcpy(priv->nodename, extra, dwrq->length);
279 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280
Holger Schurig9012b282007-05-25 11:27:16 -0400281 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200282 return 0;
283}
284
Holger Schurig10078322007-11-15 18:05:47 -0500285static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286 struct iw_point *dwrq, char *extra)
287{
Kiran Divekarab65f642009-02-19 19:32:39 -0500288 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200289
Holger Schurig9012b282007-05-25 11:27:16 -0400290 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200291
David Woodhouseaa21c002007-12-08 20:04:36 +0000292 dwrq->length = strlen(priv->nodename);
293 memcpy(extra, priv->nodename, dwrq->length);
Holger Schurig04799fa2007-10-09 15:04:14 +0200294 extra[dwrq->length] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200295
Holger Schurig04799fa2007-10-09 15:04:14 +0200296 dwrq->flags = 1; /* active */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297
Holger Schurig9012b282007-05-25 11:27:16 -0400298 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200299 return 0;
300}
301
Holger Schurig4143a232009-12-02 15:26:02 +0100302#ifdef CONFIG_LIBERTAS_MESH
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400303static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
304 struct iw_point *dwrq, char *extra)
305{
Kiran Divekarab65f642009-02-19 19:32:39 -0500306 struct lbs_private *priv = dev->ml_priv;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400307
308 lbs_deb_enter(LBS_DEB_WEXT);
309
310 /* Use nickname to indicate that mesh is on */
311
Holger Schurig602114a2009-12-02 15:26:01 +0100312 if (lbs_mesh_connected(priv)) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400313 strncpy(extra, "Mesh", 12);
314 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400315 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400316 }
317
318 else {
319 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400320 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400321 }
322
323 lbs_deb_leave(LBS_DEB_WEXT);
324 return 0;
325}
Holger Schurig4143a232009-12-02 15:26:02 +0100326#endif
Holger Schurig04799fa2007-10-09 15:04:14 +0200327
Holger Schurig10078322007-11-15 18:05:47 -0500328static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200329 struct iw_param *vwrq, char *extra)
330{
331 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -0500332 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400333 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334
Holger Schurig9012b282007-05-25 11:27:16 -0400335 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200336
Dan Williams39fcf7a2008-09-10 12:49:00 -0400337 if (vwrq->disabled)
338 val = MRVDRV_RTS_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200339
John W. Linville375da532008-09-15 17:25:54 -0400340 if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400341 return -EINVAL;
342
343 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344
Holger Schurig9012b282007-05-25 11:27:16 -0400345 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200346 return ret;
347}
348
Holger Schurig10078322007-11-15 18:05:47 -0500349static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200350 struct iw_param *vwrq, char *extra)
351{
Kiran Divekarab65f642009-02-19 19:32:39 -0500352 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400353 int ret = 0;
354 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200355
Holger Schurig9012b282007-05-25 11:27:16 -0400356 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357
Dan Williams39fcf7a2008-09-10 12:49:00 -0400358 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400359 if (ret)
360 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200361
Dan Williams39fcf7a2008-09-10 12:49:00 -0400362 vwrq->value = val;
John W. Linville375da532008-09-15 17:25:54 -0400363 vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364 vwrq->fixed = 1;
365
Holger Schurig9012b282007-05-25 11:27:16 -0400366out:
367 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
368 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369}
370
Holger Schurig10078322007-11-15 18:05:47 -0500371static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200372 struct iw_param *vwrq, char *extra)
373{
Kiran Divekarab65f642009-02-19 19:32:39 -0500374 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400375 int ret = 0;
376 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200377
Holger Schurig9012b282007-05-25 11:27:16 -0400378 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200379
Dan Williams39fcf7a2008-09-10 12:49:00 -0400380 if (vwrq->disabled)
381 val = MRVDRV_FRAG_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200382
Dan Williams39fcf7a2008-09-10 12:49:00 -0400383 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
384 return -EINVAL;
385
386 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
Holger Schurig9012b282007-05-25 11:27:16 -0400387
388 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200389 return ret;
390}
391
Holger Schurig10078322007-11-15 18:05:47 -0500392static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200393 struct iw_param *vwrq, char *extra)
394{
Kiran Divekarab65f642009-02-19 19:32:39 -0500395 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400396 int ret = 0;
397 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200398
Holger Schurig9012b282007-05-25 11:27:16 -0400399 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400
Dan Williams39fcf7a2008-09-10 12:49:00 -0400401 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400402 if (ret)
403 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404
Dan Williams39fcf7a2008-09-10 12:49:00 -0400405 vwrq->value = val;
406 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
407 || (val > MRVDRV_FRAG_MAX_VALUE));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200408 vwrq->fixed = 1;
409
Holger Schurig9012b282007-05-25 11:27:16 -0400410out:
411 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200412 return ret;
413}
414
Holger Schurig10078322007-11-15 18:05:47 -0500415static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200416 struct iw_request_info *info, u32 * uwrq, char *extra)
417{
Kiran Divekarab65f642009-02-19 19:32:39 -0500418 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419
Holger Schurig9012b282007-05-25 11:27:16 -0400420 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200421
David Woodhouseaa21c002007-12-08 20:04:36 +0000422 *uwrq = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200423
Holger Schurig9012b282007-05-25 11:27:16 -0400424 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425 return 0;
426}
427
Holger Schurig4143a232009-12-02 15:26:02 +0100428#ifdef CONFIG_LIBERTAS_MESH
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400429static int mesh_wlan_get_mode(struct net_device *dev,
430 struct iw_request_info *info, u32 * uwrq,
431 char *extra)
432{
433 lbs_deb_enter(LBS_DEB_WEXT);
434
Dan Williams39fcf7a2008-09-10 12:49:00 -0400435 *uwrq = IW_MODE_REPEAT;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400436
437 lbs_deb_leave(LBS_DEB_WEXT);
438 return 0;
439}
Holger Schurig4143a232009-12-02 15:26:02 +0100440#endif
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400441
Holger Schurig10078322007-11-15 18:05:47 -0500442static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200443 struct iw_request_info *info,
444 struct iw_param *vwrq, char *extra)
445{
Kiran Divekarab65f642009-02-19 19:32:39 -0500446 struct lbs_private *priv = dev->ml_priv;
Dan Williams87c8c722008-08-19 15:15:35 -0400447 s16 curlevel = 0;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400448 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200449
Holger Schurig9012b282007-05-25 11:27:16 -0400450 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200451
Dan Williamsd5db2df2008-08-21 17:51:07 -0400452 if (!priv->radio_on) {
453 lbs_deb_wext("tx power off\n");
454 vwrq->value = 0;
455 vwrq->disabled = 1;
456 goto out;
457 }
458
Dan Williams87c8c722008-08-19 15:15:35 -0400459 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400460 if (ret)
461 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200462
Dan Williams87c8c722008-08-19 15:15:35 -0400463 lbs_deb_wext("tx power level %d dbm\n", curlevel);
Dan Williams87c8c722008-08-19 15:15:35 -0400464 priv->txpower_cur = curlevel;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400465
Dan Williams87c8c722008-08-19 15:15:35 -0400466 vwrq->value = curlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200467 vwrq->fixed = 1;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400468 vwrq->disabled = 0;
469 vwrq->flags = IW_TXPOW_DBM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470
Holger Schurig9012b282007-05-25 11:27:16 -0400471out:
472 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
473 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200474}
475
Holger Schurig10078322007-11-15 18:05:47 -0500476static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200477 struct iw_param *vwrq, char *extra)
478{
Kiran Divekarab65f642009-02-19 19:32:39 -0500479 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400480 int ret = 0;
481 u16 slimit = 0, llimit = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200482
Holger Schurig9012b282007-05-25 11:27:16 -0400483 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200484
Dan Williams39fcf7a2008-09-10 12:49:00 -0400485 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
486 return -EOPNOTSUPP;
487
488 /* The MAC has a 4-bit Total_Tx_Count register
489 Total_Tx_Count = 1 + Tx_Retry_Count */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200490#define TX_RETRY_MIN 0
491#define TX_RETRY_MAX 14
Dan Williams39fcf7a2008-09-10 12:49:00 -0400492 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
493 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200494
Dan Williams39fcf7a2008-09-10 12:49:00 -0400495 /* Add 1 to convert retry count to try count */
496 if (vwrq->flags & IW_RETRY_SHORT)
497 slimit = (u16) (vwrq->value + 1);
498 else if (vwrq->flags & IW_RETRY_LONG)
499 llimit = (u16) (vwrq->value + 1);
500 else
501 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200502
Dan Williams39fcf7a2008-09-10 12:49:00 -0400503 if (llimit) {
504 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
505 llimit);
Holger Schurig9012b282007-05-25 11:27:16 -0400506 if (ret)
507 goto out;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400508 }
509
510 if (slimit) {
511 /* txretrycount follows the short retry limit */
512 priv->txretrycount = slimit;
513 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
514 slimit);
515 if (ret)
516 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200517 }
518
Holger Schurig9012b282007-05-25 11:27:16 -0400519out:
520 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
521 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200522}
523
Holger Schurig10078322007-11-15 18:05:47 -0500524static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200525 struct iw_param *vwrq, char *extra)
526{
Kiran Divekarab65f642009-02-19 19:32:39 -0500527 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528 int ret = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400529 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200530
Holger Schurig9012b282007-05-25 11:27:16 -0400531 lbs_deb_enter(LBS_DEB_WEXT);
532
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200533 vwrq->disabled = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400534
535 if (vwrq->flags & IW_RETRY_LONG) {
536 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
537 if (ret)
538 goto out;
539
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200540 /* Subtract 1 to convert try count to retry count */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400541 vwrq->value = val - 1;
542 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
543 } else {
544 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
545 if (ret)
546 goto out;
547
548 /* txretry count follows the short retry limit */
549 priv->txretrycount = val;
550 /* Subtract 1 to convert try count to retry count */
551 vwrq->value = val - 1;
552 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553 }
554
Holger Schurig9012b282007-05-25 11:27:16 -0400555out:
556 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
557 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200558}
559
560static inline void sort_channels(struct iw_freq *freq, int num)
561{
562 int i, j;
563 struct iw_freq temp;
564
565 for (i = 0; i < num; i++)
566 for (j = i + 1; j < num; j++)
567 if (freq[i].i > freq[j].i) {
568 temp.i = freq[i].i;
569 temp.m = freq[i].m;
570
571 freq[i].i = freq[j].i;
572 freq[i].m = freq[j].m;
573
574 freq[j].i = temp.i;
575 freq[j].m = temp.m;
576 }
577}
578
579/* data rate listing
580 MULTI_BANDS:
581 abg a b b/g
582 Infra G(12) A(8) B(4) G(12)
583 Adhoc A+B(12) A(8) B(4) B(4)
584
585 non-MULTI_BANDS:
586 b b/g
587 Infra B(4) G(12)
588 Adhoc B(4) B(4)
589 */
590/**
591 * @brief Get Range Info
592 *
593 * @param dev A pointer to net_device structure
594 * @param info A pointer to iw_request_info structure
595 * @param vwrq A pointer to iw_param structure
596 * @param extra A pointer to extra data buf
597 * @return 0 --success, otherwise fail
598 */
Holger Schurig10078322007-11-15 18:05:47 -0500599static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200600 struct iw_point *dwrq, char *extra)
601{
602 int i, j;
Kiran Divekarab65f642009-02-19 19:32:39 -0500603 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604 struct iw_range *range = (struct iw_range *)extra;
605 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400606 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200607
Holger Schurig9012b282007-05-25 11:27:16 -0400608 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609
610 dwrq->length = sizeof(struct iw_range);
611 memset(range, 0, sizeof(struct iw_range));
612
613 range->min_nwid = 0;
614 range->max_nwid = 0;
615
616 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000617 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400618 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
619 for (i = 0; i < range->num_bitrates; i++)
620 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200621 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400622 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623 range->num_bitrates);
624
625 range->num_frequency = 0;
Holger Schurig52933d82008-03-05 07:05:32 +0100626
627 range->scan_capa = IW_SCAN_CAPA_ESSID;
628
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200629 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
630 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
631 cfp = priv->region_channel[j].CFP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200632 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200633 && priv->region_channel[j].valid
634 && cfp
635 && (i < priv->region_channel[j].nrcfp); i++) {
636 range->freq[range->num_frequency].i =
637 (long)cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200638 range->freq[range->num_frequency].m =
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200639 (long)cfp->freq * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200640 range->freq[range->num_frequency].e = 1;
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200641 cfp++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200642 range->num_frequency++;
643 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200644 }
645
Holger Schurig9012b282007-05-25 11:27:16 -0400646 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647 IW_MAX_FREQUENCIES, range->num_frequency);
648
649 range->num_channels = range->num_frequency;
650
651 sort_channels(&range->freq[0], range->num_frequency);
652
653 /*
654 * Set an indication of the max TCP throughput in bit/s that we can
655 * expect using this interface
656 */
657 if (i > 2)
658 range->throughput = 5000 * 1000;
659 else
660 range->throughput = 1500 * 1000;
661
662 range->min_rts = MRVDRV_RTS_MIN_VALUE;
663 range->max_rts = MRVDRV_RTS_MAX_VALUE;
664 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
665 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
666
667 range->encoding_size[0] = 5;
668 range->encoding_size[1] = 13;
669 range->num_encoding_sizes = 2;
670 range->max_encoding_tokens = 4;
671
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100672 /*
673 * Right now we support only "iwconfig ethX power on|off"
674 */
675 range->pm_capa = IW_POWER_ON;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200676
677 /*
678 * Minimum version we recommend
679 */
680 range->we_version_source = 15;
681
682 /*
683 * Version we are compiled with
684 */
685 range->we_version_compiled = WIRELESS_EXT;
686
687 range->retry_capa = IW_RETRY_LIMIT;
688 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
689
690 range->min_retry = TX_RETRY_MIN;
691 range->max_retry = TX_RETRY_MAX;
692
693 /*
694 * Set the qual, level and noise range values
695 */
696 range->max_qual.qual = 100;
697 range->max_qual.level = 0;
698 range->max_qual.noise = 0;
699 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
700
701 range->avg_qual.qual = 70;
702 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
703 range->avg_qual.level = 0;
704 range->avg_qual.noise = 0;
705 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
706
707 range->sensitivity = 0;
708
Dan Williams87c8c722008-08-19 15:15:35 -0400709 /* Setup the supported power level ranges */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200710 memset(range->txpower, 0, sizeof(range->txpower));
Dan Williams87c8c722008-08-19 15:15:35 -0400711 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
712 range->txpower[0] = priv->txpower_min;
713 range->txpower[1] = priv->txpower_max;
714 range->num_txpower = 2;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715
716 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
717 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
718 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
719 range->event_capa[1] = IW_EVENT_CAPA_K_1;
720
David Woodhouseaa21c002007-12-08 20:04:36 +0000721 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200722 range->enc_capa = IW_ENC_CAPA_WPA
723 | IW_ENC_CAPA_WPA2
724 | IW_ENC_CAPA_CIPHER_TKIP
725 | IW_ENC_CAPA_CIPHER_CCMP;
726 }
727
Holger Schurig9012b282007-05-25 11:27:16 -0400728 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200729 return 0;
730}
731
Holger Schurig10078322007-11-15 18:05:47 -0500732static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200733 struct iw_param *vwrq, char *extra)
734{
Kiran Divekarab65f642009-02-19 19:32:39 -0500735 struct lbs_private *priv = dev->ml_priv;
Amitkumar Karwar49125452009-09-30 20:04:38 -0700736 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200737
Holger Schurig9012b282007-05-25 11:27:16 -0400738 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200739
Andrey Yurovskye0d61332009-06-16 13:20:01 -0700740 if (!(priv->fwcapinfo & FW_CAPINFO_PS)) {
David Woodhouseb2c57ee2007-12-17 14:41:13 -0500741 if (vwrq->disabled)
742 return 0;
743 else
744 return -EINVAL;
745 }
746
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200747 /* PS is currently supported only in Infrastructure mode
748 * Remove this check if it is to be supported in IBSS mode also
749 */
750
751 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000752 priv->psmode = LBS802_11POWERMODECAM;
753 if (priv->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500754 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200755 }
756
757 return 0;
758 }
759
760 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400761 lbs_deb_wext(
762 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200763 return -EINVAL;
764 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Amitkumar Karwar49125452009-09-30 20:04:38 -0700765 vwrq->value = vwrq->value / 1000;
766 if (!priv->enter_deep_sleep) {
767 lbs_pr_err("deep sleep feature is not implemented "
768 "for this interface driver\n");
769 return -EINVAL;
770 }
771
772 if (priv->connect_status == LBS_CONNECTED) {
773 if ((priv->is_auto_deep_sleep_enabled) &&
774 (vwrq->value == -1000)) {
775 lbs_exit_auto_deep_sleep(priv);
776 return 0;
777 } else {
778 lbs_pr_err("can't use deep sleep cmd in "
779 "connected state\n");
780 return -EINVAL;
781 }
782 }
783
784 if ((vwrq->value < 0) && (vwrq->value != -1000)) {
785 lbs_pr_err("unknown option\n");
786 return -EINVAL;
787 }
788
789 if (vwrq->value > 0) {
790 if (!priv->is_auto_deep_sleep_enabled) {
791 priv->is_activity_detected = 0;
792 priv->auto_deep_sleep_timeout = vwrq->value;
793 lbs_enter_auto_deep_sleep(priv);
794 } else {
795 priv->auto_deep_sleep_timeout = vwrq->value;
796 lbs_deb_debugfs("auto deep sleep: "
797 "already enabled\n");
798 }
799 return 0;
800 } else {
801 if (priv->is_auto_deep_sleep_enabled) {
802 lbs_exit_auto_deep_sleep(priv);
803 /* Try to exit deep sleep if auto */
804 /*deep sleep disabled */
805 ret = lbs_set_deep_sleep(priv, 0);
806 }
807 if (vwrq->value == 0)
808 ret = lbs_set_deep_sleep(priv, 1);
809 else if (vwrq->value == -1000)
810 ret = lbs_set_deep_sleep(priv, 0);
811 return ret;
812 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813 }
814
David Woodhouseaa21c002007-12-08 20:04:36 +0000815 if (priv->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200816 return 0;
817 }
818
David Woodhouseaa21c002007-12-08 20:04:36 +0000819 priv->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820
David Woodhouseaa21c002007-12-08 20:04:36 +0000821 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500822 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200823 }
824
Holger Schurig9012b282007-05-25 11:27:16 -0400825 lbs_deb_leave(LBS_DEB_WEXT);
Amitkumar Karwar49125452009-09-30 20:04:38 -0700826
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200827 return 0;
828}
829
Holger Schurig10078322007-11-15 18:05:47 -0500830static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200831 struct iw_param *vwrq, char *extra)
832{
Kiran Divekarab65f642009-02-19 19:32:39 -0500833 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200834
Holger Schurig9012b282007-05-25 11:27:16 -0400835 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200836
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200837 vwrq->value = 0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100838 vwrq->flags = 0;
839 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
840 || priv->connect_status == LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200841
Holger Schurig9012b282007-05-25 11:27:16 -0400842 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200843 return 0;
844}
845
Holger Schurig10078322007-11-15 18:05:47 -0500846static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200847{
848 enum {
849 POOR = 30,
850 FAIR = 60,
851 GOOD = 80,
852 VERY_GOOD = 90,
853 EXCELLENT = 95,
854 PERFECT = 100
855 };
Kiran Divekarab65f642009-02-19 19:32:39 -0500856 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200857 u32 rssi_qual;
858 u32 tx_qual;
859 u32 quality = 0;
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700860 int ret, stats_valid = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200861 u8 rssi;
862 u32 tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100863 struct cmd_ds_802_11_get_log log;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200864
Holger Schurig9012b282007-05-25 11:27:16 -0400865 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200866
David Woodhouseaa21c002007-12-08 20:04:36 +0000867 priv->wstats.status = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200868
869 /* If we're not associated, all quality values are meaningless */
David Woodhouseaa21c002007-12-08 20:04:36 +0000870 if ((priv->connect_status != LBS_CONNECTED) &&
Holger Schurig602114a2009-12-02 15:26:01 +0100871 !lbs_mesh_connected(priv))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200872 goto out;
873
874 /* Quality by RSSI */
875 priv->wstats.qual.level =
David Woodhouseaa21c002007-12-08 20:04:36 +0000876 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
877 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200878
David Woodhouseaa21c002007-12-08 20:04:36 +0000879 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200880 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
881 } else {
882 priv->wstats.qual.noise =
David Woodhouseaa21c002007-12-08 20:04:36 +0000883 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200884 }
885
Holger Schurig9012b282007-05-25 11:27:16 -0400886 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
887 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200888
889 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
890 if (rssi < 15)
891 rssi_qual = rssi * POOR / 10;
892 else if (rssi < 20)
893 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
894 else if (rssi < 30)
895 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
896 else if (rssi < 40)
897 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
898 10 + GOOD;
899 else
900 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
901 10 + VERY_GOOD;
902 quality = rssi_qual;
903
904 /* Quality by TX errors */
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000905 priv->wstats.discard.retries = dev->stats.tx_errors;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200906
Holger Schurigc49c3b72008-03-17 12:45:58 +0100907 memset(&log, 0, sizeof(log));
908 log.hdr.size = cpu_to_le16(sizeof(log));
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700909 ret = lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
910 if (ret)
911 goto out;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100912
913 tx_retries = le32_to_cpu(log.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200914
915 if (tx_retries > 75)
916 tx_qual = (90 - tx_retries) * POOR / 15;
917 else if (tx_retries > 70)
918 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
919 else if (tx_retries > 65)
920 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
921 else if (tx_retries > 50)
922 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
923 15 + GOOD;
924 else
925 tx_qual = (50 - tx_retries) *
926 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
927 quality = min(quality, tx_qual);
928
Holger Schurigc49c3b72008-03-17 12:45:58 +0100929 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200930 priv->wstats.discard.retries = tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100931 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200932
933 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400934 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200935 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
936 stats_valid = 1;
937
938 /* update stats asynchronously for future calls */
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700939 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200940 0, 0, NULL);
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700941 if (ret)
942 lbs_pr_err("RSSI command failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200943out:
944 if (!stats_valid) {
945 priv->wstats.miss.beacon = 0;
946 priv->wstats.discard.retries = 0;
947 priv->wstats.qual.qual = 0;
948 priv->wstats.qual.level = 0;
949 priv->wstats.qual.noise = 0;
950 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
951 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
952 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
953 }
954
Holger Schurig9012b282007-05-25 11:27:16 -0400955 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200956 return &priv->wstats;
957
958
959}
960
Holger Schurig10078322007-11-15 18:05:47 -0500961static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200962 struct iw_freq *fwrq, char *extra)
963{
Dan Williamsef9a2642007-05-25 16:46:33 -0400964 int ret = -EINVAL;
Kiran Divekarab65f642009-02-19 19:32:39 -0500965 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200966 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400967 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200968
Holger Schurig9012b282007-05-25 11:27:16 -0400969 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200970
David Woodhouseaa21c002007-12-08 20:04:36 +0000971 mutex_lock(&priv->lock);
972 assoc_req = lbs_get_association_request(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400973 if (!assoc_req) {
974 ret = -ENOMEM;
975 goto out;
976 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200977
Dan Williamsef9a2642007-05-25 16:46:33 -0400978 /* If setting by frequency, convert to a channel */
979 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200980 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200981
David Woodhouseaa21c002007-12-08 20:04:36 +0000982 cfp = find_cfp_by_band_and_freq(priv, 0, f);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200983 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400984 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400985 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200986 }
987
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200988 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400989 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200990 }
991
Dan Williamsef9a2642007-05-25 16:46:33 -0400992 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200993 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400994 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200995 }
996
David Woodhouseaa21c002007-12-08 20:04:36 +0000997 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400998 if (!cfp) {
999 goto out;
1000 }
1001
1002 assoc_req->channel = fwrq->m;
1003 ret = 0;
1004
Holger Schurig9012b282007-05-25 11:27:16 -04001005out:
Dan Williamsef9a2642007-05-25 16:46:33 -04001006 if (ret == 0) {
1007 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001008 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -04001009 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001010 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -04001011 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001012 mutex_unlock(&priv->lock);
Dan Williamsef9a2642007-05-25 16:46:33 -04001013
1014 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1015 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001016}
1017
Holger Schurig4143a232009-12-02 15:26:02 +01001018#ifdef CONFIG_LIBERTAS_MESH
David Woodhouse823eaa22007-12-11 19:56:28 -05001019static int lbs_mesh_set_freq(struct net_device *dev,
1020 struct iw_request_info *info,
1021 struct iw_freq *fwrq, char *extra)
1022{
Kiran Divekarab65f642009-02-19 19:32:39 -05001023 struct lbs_private *priv = dev->ml_priv;
David Woodhouse823eaa22007-12-11 19:56:28 -05001024 struct chan_freq_power *cfp;
1025 int ret = -EINVAL;
1026
1027 lbs_deb_enter(LBS_DEB_WEXT);
1028
1029 /* If setting by frequency, convert to a channel */
1030 if (fwrq->e == 1) {
1031 long f = fwrq->m / 100000;
1032
1033 cfp = find_cfp_by_band_and_freq(priv, 0, f);
1034 if (!cfp) {
1035 lbs_deb_wext("invalid freq %ld\n", f);
1036 goto out;
1037 }
1038
1039 fwrq->e = 0;
1040 fwrq->m = (int) cfp->channel;
1041 }
1042
1043 /* Setting by channel number */
1044 if (fwrq->m > 1000 || fwrq->e > 0) {
1045 goto out;
1046 }
1047
1048 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
1049 if (!cfp) {
1050 goto out;
1051 }
1052
Holger Schurigc14951f2009-10-22 15:30:50 +02001053 if (fwrq->m != priv->channel) {
David Woodhouse823eaa22007-12-11 19:56:28 -05001054 lbs_deb_wext("mesh channel change forces eth disconnect\n");
1055 if (priv->mode == IW_MODE_INFRA)
Dan Williams191bb402008-08-21 17:46:18 -04001056 lbs_cmd_80211_deauthenticate(priv,
1057 priv->curbssparams.bssid,
1058 WLAN_REASON_DEAUTH_LEAVING);
David Woodhouse823eaa22007-12-11 19:56:28 -05001059 else if (priv->mode == IW_MODE_ADHOC)
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001060 lbs_adhoc_stop(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -05001061 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001062 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
David Woodhouse86062132007-12-13 00:32:36 -05001063 lbs_update_channel(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -05001064 ret = 0;
1065
1066out:
1067 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1068 return ret;
1069}
Holger Schurig4143a232009-12-02 15:26:02 +01001070#endif
David Woodhouse823eaa22007-12-11 19:56:28 -05001071
Holger Schurig10078322007-11-15 18:05:47 -05001072static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001073 struct iw_param *vwrq, char *extra)
1074{
Kiran Divekarab65f642009-02-19 19:32:39 -05001075 struct lbs_private *priv = dev->ml_priv;
Dan Williams8e3c91b2007-12-11 15:50:59 -05001076 u8 new_rate = 0;
Dan Williams8c512762007-08-02 11:40:45 -04001077 int ret = -EINVAL;
1078 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001079
Holger Schurig9012b282007-05-25 11:27:16 -04001080 lbs_deb_enter(LBS_DEB_WEXT);
Amitkumar Karwar49125452009-09-30 20:04:38 -07001081
Holger Schurig9012b282007-05-25 11:27:16 -04001082 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Javier Cardona85319f92008-05-24 10:59:49 +01001083 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1084
1085 if (vwrq->fixed && vwrq->value == -1)
1086 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001087
Dan Williams8c512762007-08-02 11:40:45 -04001088 /* Auto rate? */
Javier Cardona85319f92008-05-24 10:59:49 +01001089 priv->enablehwauto = !vwrq->fixed;
1090
1091 if (vwrq->value == -1)
David Woodhouseaa21c002007-12-08 20:04:36 +00001092 priv->cur_rate = 0;
Javier Cardona85319f92008-05-24 10:59:49 +01001093 else {
Dan Williams8c512762007-08-02 11:40:45 -04001094 if (vwrq->value % 100000)
1095 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001096
Javier Cardona85319f92008-05-24 10:59:49 +01001097 new_rate = vwrq->value / 500000;
1098 priv->cur_rate = new_rate;
1099 /* the rest is only needed for lbs_set_data_rate() */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001100 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +00001101 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -04001102 if (!memchr(rates, new_rate, sizeof(rates))) {
1103 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1104 new_rate);
1105 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001106 }
Anna Neal3ed6e082008-09-26 11:34:35 -04001107 if (priv->fwrelease < 0x09000000) {
1108 ret = lbs_set_power_adapt_cfg(priv, 0,
1109 POW_ADAPT_DEFAULT_P0,
1110 POW_ADAPT_DEFAULT_P1,
1111 POW_ADAPT_DEFAULT_P2);
1112 if (ret)
1113 goto out;
1114 }
1115 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1116 TPC_DEFAULT_P2, 1);
1117 if (ret)
1118 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001119 }
1120
Javier Cardona85319f92008-05-24 10:59:49 +01001121 /* Try the newer command first (Firmware Spec 5.1 and above) */
1122 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1123
1124 /* Fallback to older version */
1125 if (ret)
1126 ret = lbs_set_data_rate(priv, new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001127
Dan Williams8c512762007-08-02 11:40:45 -04001128out:
Holger Schurig9012b282007-05-25 11:27:16 -04001129 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001130 return ret;
1131}
1132
Holger Schurig10078322007-11-15 18:05:47 -05001133static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001134 struct iw_param *vwrq, char *extra)
1135{
Kiran Divekarab65f642009-02-19 19:32:39 -05001136 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001137
Holger Schurig9012b282007-05-25 11:27:16 -04001138 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001139
David Woodhouseaa21c002007-12-08 20:04:36 +00001140 if (priv->connect_status == LBS_CONNECTED) {
1141 vwrq->value = priv->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001142
Javier Cardona85319f92008-05-24 10:59:49 +01001143 if (priv->enablehwauto)
Dan Williams8c512762007-08-02 11:40:45 -04001144 vwrq->fixed = 0;
1145 else
1146 vwrq->fixed = 1;
1147
1148 } else {
1149 vwrq->fixed = 0;
1150 vwrq->value = 0;
1151 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001152
Holger Schurig9012b282007-05-25 11:27:16 -04001153 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001154 return 0;
1155}
1156
Holger Schurig10078322007-11-15 18:05:47 -05001157static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001158 struct iw_request_info *info, u32 * uwrq, char *extra)
1159{
1160 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001161 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001162 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001163
Holger Schurig9012b282007-05-25 11:27:16 -04001164 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001165
Dan Williams0dc5a292007-05-10 22:58:02 -04001166 if ( (*uwrq != IW_MODE_ADHOC)
1167 && (*uwrq != IW_MODE_INFRA)
1168 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001169 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001170 ret = -EINVAL;
1171 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001172 }
1173
David Woodhouseaa21c002007-12-08 20:04:36 +00001174 mutex_lock(&priv->lock);
1175 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001176 if (!assoc_req) {
1177 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001178 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001179 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001180 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001181 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001182 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001183 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001184 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001185 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001186
Dan Williams0dc5a292007-05-10 22:58:02 -04001187out:
Holger Schurig9012b282007-05-25 11:27:16 -04001188 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001189 return ret;
1190}
1191
1192
1193/**
1194 * @brief Get Encryption key
1195 *
1196 * @param dev A pointer to net_device structure
1197 * @param info A pointer to iw_request_info structure
1198 * @param vwrq A pointer to iw_param structure
1199 * @param extra A pointer to extra data buf
1200 * @return 0 --success, otherwise fail
1201 */
Holger Schurig10078322007-11-15 18:05:47 -05001202static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001203 struct iw_request_info *info,
1204 struct iw_point *dwrq, u8 * extra)
1205{
Kiran Divekarab65f642009-02-19 19:32:39 -05001206 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001207 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1208
Holger Schurig9012b282007-05-25 11:27:16 -04001209 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001210
Holger Schurig9012b282007-05-25 11:27:16 -04001211 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001212 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001213
1214 dwrq->flags = 0;
1215
1216 /* Authentication method */
David Woodhouseaa21c002007-12-08 20:04:36 +00001217 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -04001218 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001219 dwrq->flags = IW_ENCODE_OPEN;
1220 break;
1221
Dan Williams6affe782007-05-10 22:56:42 -04001222 case IW_AUTH_ALG_SHARED_KEY:
1223 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001224 dwrq->flags = IW_ENCODE_RESTRICTED;
1225 break;
1226 default:
1227 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1228 break;
1229 }
1230
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001231 memset(extra, 0, 16);
1232
David Woodhouseaa21c002007-12-08 20:04:36 +00001233 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001234
1235 /* Default to returning current transmit key */
1236 if (index < 0)
David Woodhouseaa21c002007-12-08 20:04:36 +00001237 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001238
David Woodhouseaa21c002007-12-08 20:04:36 +00001239 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1240 memcpy(extra, priv->wep_keys[index].key,
1241 priv->wep_keys[index].len);
1242 dwrq->length = priv->wep_keys[index].len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001243
1244 dwrq->flags |= (index + 1);
1245 /* Return WEP enabled */
1246 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhouseaa21c002007-12-08 20:04:36 +00001247 } else if ((priv->secinfo.WPAenabled)
1248 || (priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001249 /* return WPA enabled */
1250 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhousec12bdc42007-12-07 19:32:12 +00001251 dwrq->flags |= IW_ENCODE_NOKEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001252 } else {
1253 dwrq->flags |= IW_ENCODE_DISABLED;
1254 }
1255
David Woodhouseaa21c002007-12-08 20:04:36 +00001256 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001257
Joe Perches0795af52007-10-03 17:59:30 -07001258 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001259 extra[0], extra[1], extra[2],
1260 extra[3], extra[4], extra[5], dwrq->length);
1261
Holger Schurig9012b282007-05-25 11:27:16 -04001262 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001263
Holger Schurig9012b282007-05-25 11:27:16 -04001264 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001265 return 0;
1266}
1267
1268/**
1269 * @brief Set Encryption key (internal)
1270 *
1271 * @param priv A pointer to private card structure
1272 * @param key_material A pointer to key material
1273 * @param key_length length of key material
1274 * @param index key index to set
1275 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1276 * @return 0 --success, otherwise fail
1277 */
Holger Schurig10078322007-11-15 18:05:47 -05001278static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001279 const char *key_material,
1280 u16 key_length,
1281 u16 index,
1282 int set_tx_key)
1283{
Holger Schurig9012b282007-05-25 11:27:16 -04001284 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001285 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001286
Holger Schurig9012b282007-05-25 11:27:16 -04001287 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001288
1289 /* Paranoid validation of key index */
1290 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001291 ret = -EINVAL;
1292 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001293 }
1294
1295 /* validate max key length */
1296 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001297 ret = -EINVAL;
1298 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001299 }
1300
1301 pkey = &assoc_req->wep_keys[index];
1302
1303 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001304 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001305 pkey->type = KEY_TYPE_ID_WEP;
1306
1307 /* Standardize the key length */
1308 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1309 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1310 memcpy(pkey->key, key_material, key_length);
1311 }
1312
1313 if (set_tx_key) {
1314 /* Ensure the chosen key is valid */
1315 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001316 lbs_deb_wext("key not set, so cannot enable it\n");
1317 ret = -EINVAL;
1318 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001319 }
1320 assoc_req->wep_tx_keyidx = index;
1321 }
1322
Dan Williams889c05b2007-05-10 22:57:23 -04001323 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001324
Holger Schurig9012b282007-05-25 11:27:16 -04001325out:
1326 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1327 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001328}
1329
1330static int validate_key_index(u16 def_index, u16 raw_index,
1331 u16 *out_index, u16 *is_default)
1332{
1333 if (!out_index || !is_default)
1334 return -EINVAL;
1335
1336 /* Verify index if present, otherwise use default TX key index */
1337 if (raw_index > 0) {
1338 if (raw_index > 4)
1339 return -EINVAL;
1340 *out_index = raw_index - 1;
1341 } else {
1342 *out_index = def_index;
1343 *is_default = 1;
1344 }
1345 return 0;
1346}
1347
1348static void disable_wep(struct assoc_request *assoc_req)
1349{
1350 int i;
1351
Dan Williams90a42212007-05-25 23:01:24 -04001352 lbs_deb_enter(LBS_DEB_WEXT);
1353
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001354 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001355 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001356
1357 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001358 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001359 for (i = 0; i < 4; i++)
1360 assoc_req->wep_keys[i].len = 0;
1361
1362 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1363 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001364
1365 lbs_deb_leave(LBS_DEB_WEXT);
1366}
1367
1368static void disable_wpa(struct assoc_request *assoc_req)
1369{
1370 lbs_deb_enter(LBS_DEB_WEXT);
1371
Dan Williams1443b652007-08-02 10:45:55 -04001372 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001373 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1374 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1375
Dan Williams1443b652007-08-02 10:45:55 -04001376 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001377 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1378 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1379
1380 assoc_req->secinfo.WPAenabled = 0;
1381 assoc_req->secinfo.WPA2enabled = 0;
1382 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1383
1384 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001385}
1386
1387/**
1388 * @brief Set Encryption key
1389 *
1390 * @param dev A pointer to net_device structure
1391 * @param info A pointer to iw_request_info structure
1392 * @param vwrq A pointer to iw_param structure
1393 * @param extra A pointer to extra data buf
1394 * @return 0 --success, otherwise fail
1395 */
Holger Schurig10078322007-11-15 18:05:47 -05001396static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001397 struct iw_request_info *info,
1398 struct iw_point *dwrq, char *extra)
1399{
1400 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001401 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001402 struct assoc_request * assoc_req;
1403 u16 is_default = 0, index = 0, set_tx_key = 0;
1404
Holger Schurig9012b282007-05-25 11:27:16 -04001405 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001406
David Woodhouseaa21c002007-12-08 20:04:36 +00001407 mutex_lock(&priv->lock);
1408 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001409 if (!assoc_req) {
1410 ret = -ENOMEM;
1411 goto out;
1412 }
1413
1414 if (dwrq->flags & IW_ENCODE_DISABLED) {
1415 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001416 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001417 goto out;
1418 }
1419
1420 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1421 (dwrq->flags & IW_ENCODE_INDEX),
1422 &index, &is_default);
1423 if (ret) {
1424 ret = -EINVAL;
1425 goto out;
1426 }
1427
1428 /* If WEP isn't enabled, or if there is no key data but a valid
1429 * index, set the TX key.
1430 */
Dan Williams889c05b2007-05-10 22:57:23 -04001431 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001432 set_tx_key = 1;
1433
Holger Schurig10078322007-11-15 18:05:47 -05001434 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001435 if (ret)
1436 goto out;
1437
1438 if (dwrq->length)
1439 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1440 if (set_tx_key)
1441 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1442
1443 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001444 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001445 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001446 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001447 }
1448
1449out:
1450 if (ret == 0) {
1451 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001452 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001453 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001454 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001455 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001456 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001457
Holger Schurig9012b282007-05-25 11:27:16 -04001458 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001459 return ret;
1460}
1461
1462/**
1463 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1464 *
1465 * @param dev A pointer to net_device structure
1466 * @param info A pointer to iw_request_info structure
1467 * @param vwrq A pointer to iw_param structure
1468 * @param extra A pointer to extra data buf
1469 * @return 0 on success, otherwise failure
1470 */
Holger Schurig10078322007-11-15 18:05:47 -05001471static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001472 struct iw_request_info *info,
1473 struct iw_point *dwrq,
1474 char *extra)
1475{
1476 int ret = -EINVAL;
Kiran Divekarab65f642009-02-19 19:32:39 -05001477 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001478 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1479 int index, max_key_len;
1480
Holger Schurig9012b282007-05-25 11:27:16 -04001481 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001482
1483 max_key_len = dwrq->length - sizeof(*ext);
1484 if (max_key_len < 0)
1485 goto out;
1486
1487 index = dwrq->flags & IW_ENCODE_INDEX;
1488 if (index) {
1489 if (index < 1 || index > 4)
1490 goto out;
1491 index--;
1492 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001493 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001494 }
1495
Roel Kluinf59d9782007-10-26 21:51:26 +02001496 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001497 ext->alg != IW_ENCODE_ALG_WEP) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001498 if (index != 0 || priv->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001499 goto out;
1500 }
1501
1502 dwrq->flags = index + 1;
1503 memset(ext, 0, sizeof(*ext));
1504
David Woodhouseaa21c002007-12-08 20:04:36 +00001505 if ( !priv->secinfo.wep_enabled
1506 && !priv->secinfo.WPAenabled
1507 && !priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508 ext->alg = IW_ENCODE_ALG_NONE;
1509 ext->key_len = 0;
1510 dwrq->flags |= IW_ENCODE_DISABLED;
1511 } else {
1512 u8 *key = NULL;
1513
David Woodhouseaa21c002007-12-08 20:04:36 +00001514 if ( priv->secinfo.wep_enabled
1515 && !priv->secinfo.WPAenabled
1516 && !priv->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001517 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001518 ext->alg = IW_ENCODE_ALG_WEP;
David Woodhouseaa21c002007-12-08 20:04:36 +00001519 ext->key_len = priv->wep_keys[index].len;
1520 key = &priv->wep_keys[index].key[0];
1521 } else if ( !priv->secinfo.wep_enabled
1522 && (priv->secinfo.WPAenabled ||
1523 priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001524 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001525 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001526
David Woodhouseaa21c002007-12-08 20:04:36 +00001527 if ( priv->wpa_mcast_key.len
1528 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1529 pkey = &priv->wpa_mcast_key;
1530 else if ( priv->wpa_unicast_key.len
1531 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1532 pkey = &priv->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001533
1534 if (pkey) {
1535 if (pkey->type == KEY_TYPE_ID_AES) {
1536 ext->alg = IW_ENCODE_ALG_CCMP;
1537 } else {
1538 ext->alg = IW_ENCODE_ALG_TKIP;
1539 }
1540 ext->key_len = pkey->len;
1541 key = &pkey->key[0];
1542 } else {
1543 ext->alg = IW_ENCODE_ALG_TKIP;
1544 ext->key_len = 0;
1545 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001546 } else {
1547 goto out;
1548 }
1549
1550 if (ext->key_len > max_key_len) {
1551 ret = -E2BIG;
1552 goto out;
1553 }
1554
1555 if (ext->key_len)
1556 memcpy(ext->key, key, ext->key_len);
1557 else
1558 dwrq->flags |= IW_ENCODE_NOKEY;
1559 dwrq->flags |= IW_ENCODE_ENABLED;
1560 }
1561 ret = 0;
1562
1563out:
Holger Schurig9012b282007-05-25 11:27:16 -04001564 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001565 return ret;
1566}
1567
1568/**
1569 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1570 *
1571 * @param dev A pointer to net_device structure
1572 * @param info A pointer to iw_request_info structure
1573 * @param vwrq A pointer to iw_param structure
1574 * @param extra A pointer to extra data buf
1575 * @return 0 --success, otherwise fail
1576 */
Holger Schurig10078322007-11-15 18:05:47 -05001577static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001578 struct iw_request_info *info,
1579 struct iw_point *dwrq,
1580 char *extra)
1581{
1582 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001583 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001584 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1585 int alg = ext->alg;
1586 struct assoc_request * assoc_req;
1587
Holger Schurig9012b282007-05-25 11:27:16 -04001588 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001589
David Woodhouseaa21c002007-12-08 20:04:36 +00001590 mutex_lock(&priv->lock);
1591 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001592 if (!assoc_req) {
1593 ret = -ENOMEM;
1594 goto out;
1595 }
1596
1597 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1598 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001599 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001600 } else if (alg == IW_ENCODE_ALG_WEP) {
1601 u16 is_default = 0, index, set_tx_key = 0;
1602
1603 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1604 (dwrq->flags & IW_ENCODE_INDEX),
1605 &index, &is_default);
1606 if (ret)
1607 goto out;
1608
1609 /* If WEP isn't enabled, or if there is no key data but a valid
1610 * index, or if the set-TX-key flag was passed, set the TX key.
1611 */
Dan Williams889c05b2007-05-10 22:57:23 -04001612 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001613 || (dwrq->length == 0 && !is_default)
1614 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1615 set_tx_key = 1;
1616
1617 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001618 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001619 set_tx_key);
1620 if (ret)
1621 goto out;
1622
1623 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001624 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001625 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001626 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001627 }
1628
1629 /* Mark the various WEP bits as modified */
1630 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1631 if (dwrq->length)
1632 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1633 if (set_tx_key)
1634 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001635 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001636 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001637
1638 /* validate key length */
1639 if (((alg == IW_ENCODE_ALG_TKIP)
1640 && (ext->key_len != KEY_LEN_WPA_TKIP))
1641 || ((alg == IW_ENCODE_ALG_CCMP)
1642 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001643 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001644 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001645 ext->key_len,
1646 alg);
1647 ret = -EINVAL;
1648 goto out;
1649 }
1650
Dan Williams90a42212007-05-25 23:01:24 -04001651 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001652 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001653 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1654 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001655 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001656 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1657 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001658
Dan Williams1443b652007-08-02 10:45:55 -04001659 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001660 memcpy(pkey->key, ext->key, ext->key_len);
1661 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001662 if (pkey->len)
1663 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001664
Dan Williams90a42212007-05-25 23:01:24 -04001665 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001666 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1667 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001668 } else {
1669 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001670 }
1671
Dan Williams90a42212007-05-25 23:01:24 -04001672 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001673 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001674 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001675 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001676 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001677
1678 /* If WPA isn't enabled yet, do that now */
1679 if ( assoc_req->secinfo.WPAenabled == 0
1680 && assoc_req->secinfo.WPA2enabled == 0) {
1681 assoc_req->secinfo.WPAenabled = 1;
1682 assoc_req->secinfo.WPA2enabled = 1;
1683 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1684 }
1685
Javier Cardona9c31fd62008-09-11 15:32:50 -07001686 /* Only disable wep if necessary: can't waste time here. */
1687 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1688 disable_wep(assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001689 }
1690
1691out:
Javier Cardona9c40fc52008-09-16 18:08:39 -07001692 if (ret == 0) {
1693 /* 802.1x and WPA rekeying must happen as quickly as possible,
1694 * especially during the 4-way handshake; thus if in
1695 * infrastructure mode, and either (a) 802.1x is enabled or
1696 * (b) WPA is being used, set the key right away.
1697 */
1698 if (assoc_req->mode == IW_MODE_INFRA &&
1699 ((assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_802_1X) ||
1700 (assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_PSK) ||
1701 assoc_req->secinfo.WPAenabled ||
1702 assoc_req->secinfo.WPA2enabled)) {
1703 lbs_do_association_work(priv);
1704 } else
1705 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001706 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001707 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001708 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001709 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001710
Holger Schurig9012b282007-05-25 11:27:16 -04001711 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001712 return ret;
1713}
1714
1715
Holger Schurig10078322007-11-15 18:05:47 -05001716static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001717 struct iw_request_info *info,
1718 struct iw_point *dwrq,
1719 char *extra)
1720{
Kiran Divekarab65f642009-02-19 19:32:39 -05001721 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001722 int ret = 0;
1723 struct assoc_request * assoc_req;
1724
Holger Schurig9012b282007-05-25 11:27:16 -04001725 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001726
David Woodhouseaa21c002007-12-08 20:04:36 +00001727 mutex_lock(&priv->lock);
1728 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001729 if (!assoc_req) {
1730 ret = -ENOMEM;
1731 goto out;
1732 }
1733
1734 if (dwrq->length > MAX_WPA_IE_LEN ||
1735 (dwrq->length && extra == NULL)) {
1736 ret = -EINVAL;
1737 goto out;
1738 }
1739
1740 if (dwrq->length) {
1741 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1742 assoc_req->wpa_ie_len = dwrq->length;
1743 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001744 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001745 assoc_req->wpa_ie_len = 0;
1746 }
1747
1748out:
1749 if (ret == 0) {
1750 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001751 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001752 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001753 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001754 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001755 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001756
Holger Schurig9012b282007-05-25 11:27:16 -04001757 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001758 return ret;
1759}
1760
Holger Schurig10078322007-11-15 18:05:47 -05001761static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001762 struct iw_request_info *info,
1763 struct iw_point *dwrq,
1764 char *extra)
1765{
Holger Schurig9012b282007-05-25 11:27:16 -04001766 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001767 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001768
Holger Schurig9012b282007-05-25 11:27:16 -04001769 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001770
David Woodhouseaa21c002007-12-08 20:04:36 +00001771 if (priv->wpa_ie_len == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001772 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001773 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001774 }
1775
David Woodhouseaa21c002007-12-08 20:04:36 +00001776 if (dwrq->length < priv->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001777 ret = -E2BIG;
1778 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001779 }
1780
David Woodhouseaa21c002007-12-08 20:04:36 +00001781 dwrq->length = priv->wpa_ie_len;
1782 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001783
Holger Schurig9012b282007-05-25 11:27:16 -04001784out:
1785 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1786 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001787}
1788
1789
Holger Schurig10078322007-11-15 18:05:47 -05001790static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001791 struct iw_request_info *info,
1792 struct iw_param *dwrq,
1793 char *extra)
1794{
Kiran Divekarab65f642009-02-19 19:32:39 -05001795 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001796 struct assoc_request * assoc_req;
1797 int ret = 0;
1798 int updated = 0;
1799
Holger Schurig9012b282007-05-25 11:27:16 -04001800 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001801
David Woodhouseaa21c002007-12-08 20:04:36 +00001802 mutex_lock(&priv->lock);
1803 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001804 if (!assoc_req) {
1805 ret = -ENOMEM;
1806 goto out;
1807 }
1808
1809 switch (dwrq->flags & IW_AUTH_INDEX) {
Maithili Hinge2c8d5102009-07-31 20:02:19 -07001810 case IW_AUTH_PRIVACY_INVOKED:
1811 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001812 case IW_AUTH_TKIP_COUNTERMEASURES:
1813 case IW_AUTH_CIPHER_PAIRWISE:
1814 case IW_AUTH_CIPHER_GROUP:
Dan Williams90a42212007-05-25 23:01:24 -04001815 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816 /*
1817 * libertas does not use these parameters
1818 */
1819 break;
1820
Javier Cardona9c40fc52008-09-16 18:08:39 -07001821 case IW_AUTH_KEY_MGMT:
1822 assoc_req->secinfo.key_mgmt = dwrq->value;
1823 updated = 1;
1824 break;
1825
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001826 case IW_AUTH_WPA_VERSION:
1827 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1828 assoc_req->secinfo.WPAenabled = 0;
1829 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001830 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001831 }
1832 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1833 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001834 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001835 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001836 }
1837 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1838 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001839 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001840 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001841 }
1842 updated = 1;
1843 break;
1844
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845 case IW_AUTH_80211_AUTH_ALG:
1846 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001847 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001848 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001849 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001850 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001851 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001852 } else {
1853 ret = -EINVAL;
1854 }
1855 updated = 1;
1856 break;
1857
1858 case IW_AUTH_WPA_ENABLED:
1859 if (dwrq->value) {
1860 if (!assoc_req->secinfo.WPAenabled &&
1861 !assoc_req->secinfo.WPA2enabled) {
1862 assoc_req->secinfo.WPAenabled = 1;
1863 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001864 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001865 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001866 }
1867 } else {
1868 assoc_req->secinfo.WPAenabled = 0;
1869 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001870 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001871 }
1872 updated = 1;
1873 break;
1874
1875 default:
1876 ret = -EOPNOTSUPP;
1877 break;
1878 }
1879
1880out:
1881 if (ret == 0) {
1882 if (updated)
1883 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001884 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001885 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001886 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001887 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001888 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001889
Holger Schurig9012b282007-05-25 11:27:16 -04001890 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001891 return ret;
1892}
1893
Holger Schurig10078322007-11-15 18:05:47 -05001894static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001895 struct iw_request_info *info,
1896 struct iw_param *dwrq,
1897 char *extra)
1898{
Holger Schurig9012b282007-05-25 11:27:16 -04001899 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001900 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001901
Holger Schurig9012b282007-05-25 11:27:16 -04001902 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001903
1904 switch (dwrq->flags & IW_AUTH_INDEX) {
Javier Cardona9c40fc52008-09-16 18:08:39 -07001905 case IW_AUTH_KEY_MGMT:
1906 dwrq->value = priv->secinfo.key_mgmt;
1907 break;
1908
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001909 case IW_AUTH_WPA_VERSION:
1910 dwrq->value = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +00001911 if (priv->secinfo.WPAenabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001912 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
David Woodhouseaa21c002007-12-08 20:04:36 +00001913 if (priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001914 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1915 if (!dwrq->value)
1916 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1917 break;
1918
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001919 case IW_AUTH_80211_AUTH_ALG:
David Woodhouseaa21c002007-12-08 20:04:36 +00001920 dwrq->value = priv->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001921 break;
1922
1923 case IW_AUTH_WPA_ENABLED:
David Woodhouseaa21c002007-12-08 20:04:36 +00001924 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001925 dwrq->value = 1;
1926 break;
1927
1928 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001929 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001930 }
1931
Holger Schurig9012b282007-05-25 11:27:16 -04001932 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1933 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001934}
1935
1936
Holger Schurig10078322007-11-15 18:05:47 -05001937static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001938 struct iw_param *vwrq, char *extra)
1939{
1940 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001941 struct lbs_private *priv = dev->ml_priv;
Dan Williams87c8c722008-08-19 15:15:35 -04001942 s16 dbm = (s16) vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001943
Holger Schurig9012b282007-05-25 11:27:16 -04001944 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001945
1946 if (vwrq->disabled) {
Dan Williamsd5db2df2008-08-21 17:51:07 -04001947 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
Dan Williams87c8c722008-08-19 15:15:35 -04001948 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001949 }
1950
Dan Williams87c8c722008-08-19 15:15:35 -04001951 if (vwrq->fixed == 0) {
Anna Neal0112c9e2008-09-11 11:17:25 -07001952 /* User requests automatic tx power control, however there are
1953 * many auto tx settings. For now use firmware defaults until
1954 * we come up with a good way to expose these to the user. */
1955 if (priv->fwrelease < 0x09000000) {
1956 ret = lbs_set_power_adapt_cfg(priv, 1,
1957 POW_ADAPT_DEFAULT_P0,
1958 POW_ADAPT_DEFAULT_P1,
1959 POW_ADAPT_DEFAULT_P2);
1960 if (ret)
1961 goto out;
1962 }
1963 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1964 TPC_DEFAULT_P2, 1);
1965 if (ret)
1966 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001967 dbm = priv->txpower_max;
1968 } else {
1969 /* Userspace check in iwrange if it should use dBm or mW,
1970 * therefore this should never happen... Jean II */
1971 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1972 ret = -EOPNOTSUPP;
1973 goto out;
1974 }
1975
Anna Neal0112c9e2008-09-11 11:17:25 -07001976 /* Validate requested power level against firmware allowed
1977 * levels */
Dan Williams87c8c722008-08-19 15:15:35 -04001978 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1979 ret = -EINVAL;
1980 goto out;
1981 }
1982
1983 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1984 ret = -EINVAL;
1985 goto out;
1986 }
Anna Neal0112c9e2008-09-11 11:17:25 -07001987 if (priv->fwrelease < 0x09000000) {
1988 ret = lbs_set_power_adapt_cfg(priv, 0,
1989 POW_ADAPT_DEFAULT_P0,
1990 POW_ADAPT_DEFAULT_P1,
1991 POW_ADAPT_DEFAULT_P2);
1992 if (ret)
1993 goto out;
1994 }
1995 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1996 TPC_DEFAULT_P2, 1);
1997 if (ret)
1998 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001999 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002000
Dan Williamsd5db2df2008-08-21 17:51:07 -04002001 /* If the radio was off, turn it on */
2002 if (!priv->radio_on) {
2003 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
2004 if (ret)
2005 goto out;
2006 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002007
Dan Williams87c8c722008-08-19 15:15:35 -04002008 lbs_deb_wext("txpower set %d dBm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002009
Dan Williams87c8c722008-08-19 15:15:35 -04002010 ret = lbs_set_tx_power(priv, dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002011
Dan Williams87c8c722008-08-19 15:15:35 -04002012out:
Holger Schurig9012b282007-05-25 11:27:16 -04002013 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002014 return ret;
2015}
2016
Holger Schurig10078322007-11-15 18:05:47 -05002017static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002018 struct iw_point *dwrq, char *extra)
2019{
Kiran Divekarab65f642009-02-19 19:32:39 -05002020 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002021
Holger Schurig9012b282007-05-25 11:27:16 -04002022 lbs_deb_enter(LBS_DEB_WEXT);
2023
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002024 /*
2025 * Note : if dwrq->flags != 0, we should get the relevant SSID from
2026 * the SSID list...
2027 */
2028
2029 /*
2030 * Get the current SSID
2031 */
David Woodhouseaa21c002007-12-08 20:04:36 +00002032 if (priv->connect_status == LBS_CONNECTED) {
2033 memcpy(extra, priv->curbssparams.ssid,
2034 priv->curbssparams.ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002035 } else {
2036 memset(extra, 0, 32);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002037 }
2038 /*
2039 * If none, we may want to get the one that was set
2040 */
2041
David Woodhouseaa21c002007-12-08 20:04:36 +00002042 dwrq->length = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002043
2044 dwrq->flags = 1; /* active */
2045
Holger Schurig9012b282007-05-25 11:27:16 -04002046 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002047 return 0;
2048}
2049
Holger Schurig10078322007-11-15 18:05:47 -05002050static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002051 struct iw_point *dwrq, char *extra)
2052{
Kiran Divekarab65f642009-02-19 19:32:39 -05002053 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002054 int ret = 0;
Holger Schurig243e84e2009-10-22 15:30:47 +02002055 u8 ssid[IEEE80211_MAX_SSID_LEN];
Dan Williamsd8efea22007-05-28 23:54:55 -04002056 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002057 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04002058 int in_ssid_len = dwrq->length;
John W. Linville9387b7c2008-09-30 20:59:05 -04002059 DECLARE_SSID_BUF(ssid_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002060
Holger Schurig9012b282007-05-25 11:27:16 -04002061 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002062
Dan Williamsd5db2df2008-08-21 17:51:07 -04002063 if (!priv->radio_on) {
2064 ret = -EINVAL;
2065 goto out;
2066 }
2067
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002068 /* Check the size of the string */
Holger Schurig243e84e2009-10-22 15:30:47 +02002069 if (in_ssid_len > IEEE80211_MAX_SSID_LEN) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002070 ret = -E2BIG;
2071 goto out;
2072 }
2073
Dan Williamsd8efea22007-05-28 23:54:55 -04002074 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002075
Dan Williamsd8efea22007-05-28 23:54:55 -04002076 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002077 /* "any" SSID requested; leave SSID blank */
2078 } else {
2079 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04002080 memcpy(&ssid, extra, in_ssid_len);
2081 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002082 }
2083
Dan Williamsd8efea22007-05-28 23:54:55 -04002084 if (!ssid_len) {
2085 lbs_deb_wext("requested any SSID\n");
2086 } else {
2087 lbs_deb_wext("requested SSID '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04002088 print_ssid(ssid_buf, ssid, ssid_len));
Dan Williamsd8efea22007-05-28 23:54:55 -04002089 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002090
2091out:
David Woodhouseaa21c002007-12-08 20:04:36 +00002092 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002093 if (ret == 0) {
2094 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002095 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002096 if (!assoc_req) {
2097 ret = -ENOMEM;
2098 } else {
2099 /* Copy the SSID to the association request */
Holger Schurig243e84e2009-10-22 15:30:47 +02002100 memcpy(&assoc_req->ssid, &ssid, IEEE80211_MAX_SSID_LEN);
Dan Williamsd8efea22007-05-28 23:54:55 -04002101 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002102 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002103 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002104 }
2105 }
2106
2107 /* Cancel the association request if there was an error */
2108 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05002109 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002110 }
2111
David Woodhouseaa21c002007-12-08 20:04:36 +00002112 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002113
Holger Schurig9012b282007-05-25 11:27:16 -04002114 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002115 return ret;
2116}
2117
Holger Schurig4143a232009-12-02 15:26:02 +01002118#ifdef CONFIG_LIBERTAS_MESH
David Woodhousef5956bf2007-12-11 19:30:57 -05002119static int lbs_mesh_get_essid(struct net_device *dev,
2120 struct iw_request_info *info,
2121 struct iw_point *dwrq, char *extra)
2122{
Kiran Divekarab65f642009-02-19 19:32:39 -05002123 struct lbs_private *priv = dev->ml_priv;
David Woodhousef5956bf2007-12-11 19:30:57 -05002124
2125 lbs_deb_enter(LBS_DEB_WEXT);
2126
2127 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2128
2129 dwrq->length = priv->mesh_ssid_len;
2130
2131 dwrq->flags = 1; /* active */
2132
2133 lbs_deb_leave(LBS_DEB_WEXT);
2134 return 0;
2135}
2136
2137static int lbs_mesh_set_essid(struct net_device *dev,
2138 struct iw_request_info *info,
2139 struct iw_point *dwrq, char *extra)
2140{
Kiran Divekarab65f642009-02-19 19:32:39 -05002141 struct lbs_private *priv = dev->ml_priv;
David Woodhousef5956bf2007-12-11 19:30:57 -05002142 int ret = 0;
2143
2144 lbs_deb_enter(LBS_DEB_WEXT);
2145
Dan Williamsd5db2df2008-08-21 17:51:07 -04002146 if (!priv->radio_on) {
2147 ret = -EINVAL;
2148 goto out;
2149 }
2150
David Woodhousef5956bf2007-12-11 19:30:57 -05002151 /* Check the size of the string */
Holger Schurig243e84e2009-10-22 15:30:47 +02002152 if (dwrq->length > IEEE80211_MAX_SSID_LEN) {
David Woodhousef5956bf2007-12-11 19:30:57 -05002153 ret = -E2BIG;
2154 goto out;
2155 }
2156
2157 if (!dwrq->flags || !dwrq->length) {
2158 ret = -EINVAL;
2159 goto out;
2160 } else {
2161 /* Specific SSID requested */
2162 memcpy(priv->mesh_ssid, extra, dwrq->length);
2163 priv->mesh_ssid_len = dwrq->length;
2164 }
2165
Javier Cardonaedaea5c2008-05-17 00:55:10 -07002166 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
Holger Schurigc14951f2009-10-22 15:30:50 +02002167 priv->channel);
David Woodhousef5956bf2007-12-11 19:30:57 -05002168 out:
2169 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2170 return ret;
2171}
Holger Schurig4143a232009-12-02 15:26:02 +01002172#endif
David Woodhousef5956bf2007-12-11 19:30:57 -05002173
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002174/**
2175 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2176 *
2177 * @param dev A pointer to net_device structure
2178 * @param info A pointer to iw_request_info structure
2179 * @param awrq A pointer to iw_param structure
2180 * @param extra A pointer to extra data buf
2181 * @return 0 --success, otherwise fail
2182 */
Holger Schurig10078322007-11-15 18:05:47 -05002183static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002184 struct sockaddr *awrq, char *extra)
2185{
Kiran Divekarab65f642009-02-19 19:32:39 -05002186 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002187 struct assoc_request * assoc_req;
2188 int ret = 0;
2189
Holger Schurig9012b282007-05-25 11:27:16 -04002190 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002191
Dan Williamsd5db2df2008-08-21 17:51:07 -04002192 if (!priv->radio_on)
2193 return -EINVAL;
2194
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002195 if (awrq->sa_family != ARPHRD_ETHER)
2196 return -EINVAL;
2197
Johannes Berge1749612008-10-27 15:59:26 -07002198 lbs_deb_wext("ASSOC: WAP: sa_data %pM\n", awrq->sa_data);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002199
David Woodhouseaa21c002007-12-08 20:04:36 +00002200 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002201
2202 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002203 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002204 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05002205 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002206 ret = -ENOMEM;
2207 } else {
2208 /* Copy the BSSID to the association request */
2209 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2210 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002211 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002212 }
2213
David Woodhouseaa21c002007-12-08 20:04:36 +00002214 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002215
2216 return ret;
2217}
2218
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002219/*
2220 * iwconfig settable callbacks
2221 */
Holger Schurig10078322007-11-15 18:05:47 -05002222static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002223 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002224 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002225 (iw_handler) NULL, /* SIOCSIWNWID */
2226 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002227 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2228 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2229 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2230 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002231 (iw_handler) NULL, /* SIOCSIWSENS */
2232 (iw_handler) NULL, /* SIOCGIWSENS */
2233 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002234 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002235 (iw_handler) NULL, /* SIOCSIWPRIV */
2236 (iw_handler) NULL, /* SIOCGIWPRIV */
2237 (iw_handler) NULL, /* SIOCSIWSTATS */
2238 (iw_handler) NULL, /* SIOCGIWSTATS */
2239 iw_handler_set_spy, /* SIOCSIWSPY */
2240 iw_handler_get_spy, /* SIOCGIWSPY */
2241 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2242 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002243 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2244 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002245 (iw_handler) NULL, /* SIOCSIWMLME */
2246 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002247 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2248 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2249 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2250 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2251 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2252 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002253 (iw_handler) NULL, /* -- hole -- */
2254 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002255 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2256 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2257 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2258 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2259 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2260 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2261 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2262 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2263 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2264 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2265 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2266 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2267 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2268 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002269 (iw_handler) NULL, /* -- hole -- */
2270 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002271 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2272 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2273 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2274 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2275 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2276 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002277 (iw_handler) NULL, /* SIOCSIWPMKSA */
2278};
Holger Schurig4143a232009-12-02 15:26:02 +01002279struct iw_handler_def lbs_handler_def = {
2280 .num_standard = ARRAY_SIZE(lbs_handler),
2281 .standard = (iw_handler *) lbs_handler,
2282 .get_wireless_stats = lbs_get_wireless_stats,
2283};
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002284
Holger Schurig4143a232009-12-02 15:26:02 +01002285#ifdef CONFIG_LIBERTAS_MESH
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002286static const iw_handler mesh_wlan_handler[] = {
2287 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002288 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002289 (iw_handler) NULL, /* SIOCSIWNWID */
2290 (iw_handler) NULL, /* SIOCGIWNWID */
David Woodhouse823eaa22007-12-11 19:56:28 -05002291 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
Holger Schurig10078322007-11-15 18:05:47 -05002292 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002293 (iw_handler) NULL, /* SIOCSIWMODE */
2294 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2295 (iw_handler) NULL, /* SIOCSIWSENS */
2296 (iw_handler) NULL, /* SIOCGIWSENS */
2297 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002298 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002299 (iw_handler) NULL, /* SIOCSIWPRIV */
2300 (iw_handler) NULL, /* SIOCGIWPRIV */
2301 (iw_handler) NULL, /* SIOCSIWSTATS */
2302 (iw_handler) NULL, /* SIOCGIWSTATS */
2303 iw_handler_set_spy, /* SIOCSIWSPY */
2304 iw_handler_get_spy, /* SIOCGIWSPY */
2305 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2306 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2307 (iw_handler) NULL, /* SIOCSIWAP */
2308 (iw_handler) NULL, /* SIOCGIWAP */
2309 (iw_handler) NULL, /* SIOCSIWMLME */
2310 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002311 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2312 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
David Woodhousef5956bf2007-12-11 19:30:57 -05002313 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2314 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002315 (iw_handler) NULL, /* SIOCSIWNICKN */
2316 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2317 (iw_handler) NULL, /* -- hole -- */
2318 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002319 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2320 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2321 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2322 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2323 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2324 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2325 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2326 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2327 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2328 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2329 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2330 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2331 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2332 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002333 (iw_handler) NULL, /* -- hole -- */
2334 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002335 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2336 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2337 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2338 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2339 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2340 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002341 (iw_handler) NULL, /* SIOCSIWPMKSA */
2342};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002343
2344struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002345 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002346 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002347 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002348};
Holger Schurig4143a232009-12-02 15:26:02 +01002349#endif