blob: a8eb9e1fcf36ac7cca8cd3c4965af40f1454f310 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains ioctl functions
3 */
4#include <linux/ctype.h>
5#include <linux/delay.h>
6#include <linux/if.h>
7#include <linux/if_arp.h>
8#include <linux/wireless.h>
9#include <linux/bitops.h>
10
John W. Linville7e272fc2008-09-24 18:13:14 -040011#include <net/lib80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020012#include <net/iw_handler.h>
13
14#include "host.h"
15#include "radiotap.h"
16#include "decl.h"
17#include "defs.h"
18#include "dev.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019#include "wext.h"
Holger Schurig245bf202008-04-02 16:27:42 +020020#include "scan.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020021#include "assoc.h"
Dan Williams8e3c91b2007-12-11 15:50:59 -050022#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020023
24
Holger Schurig69f90322007-11-23 15:43:44 +010025static inline void lbs_postpone_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020026{
David Woodhouseaa21c002007-12-08 20:04:36 +000027 if (priv->surpriseremoved)
Holger Schurig9f9dac22007-10-26 10:12:14 +020028 return;
29 cancel_delayed_work(&priv->assoc_work);
30 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
31}
32
Javier Cardona9c31fd632008-09-11 15:32:50 -070033static inline void lbs_do_association_work(struct lbs_private *priv)
34{
35 if (priv->surpriseremoved)
36 return;
37 cancel_delayed_work(&priv->assoc_work);
38 queue_delayed_work(priv->work_thread, &priv->assoc_work, 0);
39}
40
Holger Schurig69f90322007-11-23 15:43:44 +010041static inline void lbs_cancel_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020042{
43 cancel_delayed_work(&priv->assoc_work);
David Woodhouseaa21c002007-12-08 20:04:36 +000044 kfree(priv->pending_assoc_req);
45 priv->pending_assoc_req = NULL;
Holger Schurig9f9dac22007-10-26 10:12:14 +020046}
47
Holger Schurigfea2b8e2009-10-22 15:30:56 +020048void lbs_send_disconnect_notification(struct lbs_private *priv)
49{
50 union iwreq_data wrqu;
51
52 memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
53 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
54 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
55}
56
Holger Schurig560c6332009-10-22 15:30:57 +020057static void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
Holger Schurig6e85e0b2009-10-22 15:30:52 +020058{
59 union iwreq_data iwrq;
60 u8 buf[50];
61
62 lbs_deb_enter(LBS_DEB_WEXT);
63
64 memset(&iwrq, 0, sizeof(union iwreq_data));
65 memset(buf, 0, sizeof(buf));
66
67 snprintf(buf, sizeof(buf) - 1, "%s", str);
68
69 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
70
71 /* Send Event to upper layer */
72 lbs_deb_wext("event indication string %s\n", (char *)buf);
73 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
74 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
75
76 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
77
78 lbs_deb_leave(LBS_DEB_WEXT);
79}
80
Amitkumar Karwar49125452009-09-30 20:04:38 -070081/**
Holger Schurig560c6332009-10-22 15:30:57 +020082 * @brief This function handles MIC failure event.
83 *
84 * @param priv A pointer to struct lbs_private structure
85 * @para event the event id
86 * @return n/a
87 */
88void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
89{
90 char buf[50];
91
92 lbs_deb_enter(LBS_DEB_CMD);
93 memset(buf, 0, sizeof(buf));
94
95 sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication ");
96
97 if (event == MACREG_INT_CODE_MIC_ERR_UNICAST)
98 strcat(buf, "unicast ");
99 else
100 strcat(buf, "multicast ");
101
102 lbs_send_iwevcustom_event(priv, buf);
103 lbs_deb_leave(LBS_DEB_CMD);
104}
105
106/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200107 * @brief Find the channel frequency power info with specific channel
108 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000109 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110 * @param band it can be BAND_A, BAND_G or BAND_B
111 * @param channel the channel for looking
112 * @return A pointer to struct chan_freq_power structure or NULL if not find.
113 */
Holger Schurig69f90322007-11-23 15:43:44 +0100114struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
David Woodhouseaa21c002007-12-08 20:04:36 +0000115 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +0100116 u8 band,
117 u16 channel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200118{
119 struct chan_freq_power *cfp = NULL;
120 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200121 int i, j;
122
David Woodhouseaa21c002007-12-08 20:04:36 +0000123 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
124 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200125
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200126 if (!rc->valid || !rc->CFP)
127 continue;
128 if (rc->band != band)
129 continue;
130 for (i = 0; i < rc->nrcfp; i++) {
131 if (rc->CFP[i].channel == channel) {
132 cfp = &rc->CFP[i];
133 break;
134 }
135 }
136 }
137
138 if (!cfp && channel)
Holger Schurig10078322007-11-15 18:05:47 -0500139 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
Holger Schurig9012b282007-05-25 11:27:16 -0400140 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200141
142 return cfp;
143}
144
145/**
146 * @brief Find the channel frequency power info with specific frequency
147 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000148 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 * @param band it can be BAND_A, BAND_G or BAND_B
150 * @param freq the frequency for looking
151 * @return A pointer to struct chan_freq_power structure or NULL if not find.
152 */
Holger Schurig69f90322007-11-23 15:43:44 +0100153static struct chan_freq_power *find_cfp_by_band_and_freq(
David Woodhouseaa21c002007-12-08 20:04:36 +0000154 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +0100155 u8 band,
156 u32 freq)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200157{
158 struct chan_freq_power *cfp = NULL;
159 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160 int i, j;
161
David Woodhouseaa21c002007-12-08 20:04:36 +0000162 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
163 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200164
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165 if (!rc->valid || !rc->CFP)
166 continue;
167 if (rc->band != band)
168 continue;
169 for (i = 0; i < rc->nrcfp; i++) {
170 if (rc->CFP[i].freq == freq) {
171 cfp = &rc->CFP[i];
172 break;
173 }
174 }
175 }
176
177 if (!cfp && freq)
Holger Schurig9012b282007-05-25 11:27:16 -0400178 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
179 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200180
181 return cfp;
182}
183
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200184/**
Dan Williams8c512762007-08-02 11:40:45 -0400185 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200186 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000187 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200188 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200189 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000190static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200191{
Holger Schurig9012b282007-05-25 11:27:16 -0400192 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200193
David Woodhouseaa21c002007-12-08 20:04:36 +0000194 if ((priv->connect_status != LBS_CONNECTED) &&
195 (priv->mesh_connect_status != LBS_CONNECTED))
Holger Schurig10078322007-11-15 18:05:47 -0500196 memcpy(rates, lbs_bg_rates, MAX_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400197 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000198 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200199
Dan Williams8c512762007-08-02 11:40:45 -0400200 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200201}
202
Holger Schurig10078322007-11-15 18:05:47 -0500203static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200204 char *cwrq, char *extra)
205{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200206
Holger Schurig9012b282007-05-25 11:27:16 -0400207 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200208
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400209 /* We could add support for 802.11n here as needed. Jean II */
210 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211
Holger Schurig9012b282007-05-25 11:27:16 -0400212 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200213 return 0;
214}
215
Holger Schurig10078322007-11-15 18:05:47 -0500216static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200217 struct iw_freq *fwrq, char *extra)
218{
Kiran Divekarab65f642009-02-19 19:32:39 -0500219 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220 struct chan_freq_power *cfp;
221
Holger Schurig9012b282007-05-25 11:27:16 -0400222 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200223
David Woodhouseaa21c002007-12-08 20:04:36 +0000224 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
Holger Schurigc14951f2009-10-22 15:30:50 +0200225 priv->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226
227 if (!cfp) {
Holger Schurigc14951f2009-10-22 15:30:50 +0200228 if (priv->channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400229 lbs_deb_wext("invalid channel %d\n",
Holger Schurigc14951f2009-10-22 15:30:50 +0200230 priv->channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231 return -EINVAL;
232 }
233
234 fwrq->m = (long)cfp->freq * 100000;
235 fwrq->e = 1;
236
Holger Schurig9012b282007-05-25 11:27:16 -0400237 lbs_deb_wext("freq %u\n", fwrq->m);
238 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239 return 0;
240}
241
Holger Schurig10078322007-11-15 18:05:47 -0500242static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200243 struct sockaddr *awrq, char *extra)
244{
Kiran Divekarab65f642009-02-19 19:32:39 -0500245 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246
Holger Schurig9012b282007-05-25 11:27:16 -0400247 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200248
David Woodhouseaa21c002007-12-08 20:04:36 +0000249 if (priv->connect_status == LBS_CONNECTED) {
250 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200251 } else {
252 memset(awrq->sa_data, 0, ETH_ALEN);
253 }
254 awrq->sa_family = ARPHRD_ETHER;
255
Holger Schurig9012b282007-05-25 11:27:16 -0400256 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200257 return 0;
258}
259
Holger Schurig10078322007-11-15 18:05:47 -0500260static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200261 struct iw_point *dwrq, char *extra)
262{
Kiran Divekarab65f642009-02-19 19:32:39 -0500263 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200264
Holger Schurig9012b282007-05-25 11:27:16 -0400265 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200266
267 /*
268 * Check the size of the string
269 */
270
271 if (dwrq->length > 16) {
272 return -E2BIG;
273 }
274
David Woodhouseaa21c002007-12-08 20:04:36 +0000275 mutex_lock(&priv->lock);
276 memset(priv->nodename, 0, sizeof(priv->nodename));
277 memcpy(priv->nodename, extra, dwrq->length);
278 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200279
Holger Schurig9012b282007-05-25 11:27:16 -0400280 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200281 return 0;
282}
283
Holger Schurig10078322007-11-15 18:05:47 -0500284static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200285 struct iw_point *dwrq, char *extra)
286{
Kiran Divekarab65f642009-02-19 19:32:39 -0500287 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200288
Holger Schurig9012b282007-05-25 11:27:16 -0400289 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200290
David Woodhouseaa21c002007-12-08 20:04:36 +0000291 dwrq->length = strlen(priv->nodename);
292 memcpy(extra, priv->nodename, dwrq->length);
Holger Schurig04799fa2007-10-09 15:04:14 +0200293 extra[dwrq->length] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200294
Holger Schurig04799fa2007-10-09 15:04:14 +0200295 dwrq->flags = 1; /* active */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200296
Holger Schurig9012b282007-05-25 11:27:16 -0400297 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298 return 0;
299}
300
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400301static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
302 struct iw_point *dwrq, char *extra)
303{
Kiran Divekarab65f642009-02-19 19:32:39 -0500304 struct lbs_private *priv = dev->ml_priv;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400305
306 lbs_deb_enter(LBS_DEB_WEXT);
307
308 /* Use nickname to indicate that mesh is on */
309
David Woodhouseaa21c002007-12-08 20:04:36 +0000310 if (priv->mesh_connect_status == LBS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400311 strncpy(extra, "Mesh", 12);
312 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400313 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400314 }
315
316 else {
317 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400318 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400319 }
320
321 lbs_deb_leave(LBS_DEB_WEXT);
322 return 0;
323}
Holger Schurig04799fa2007-10-09 15:04:14 +0200324
Holger Schurig10078322007-11-15 18:05:47 -0500325static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200326 struct iw_param *vwrq, char *extra)
327{
328 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -0500329 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400330 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200331
Holger Schurig9012b282007-05-25 11:27:16 -0400332 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333
Dan Williams39fcf7a2008-09-10 12:49:00 -0400334 if (vwrq->disabled)
335 val = MRVDRV_RTS_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200336
John W. Linville375da532008-09-15 17:25:54 -0400337 if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400338 return -EINVAL;
339
340 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200341
Holger Schurig9012b282007-05-25 11:27:16 -0400342 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343 return ret;
344}
345
Holger Schurig10078322007-11-15 18:05:47 -0500346static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200347 struct iw_param *vwrq, char *extra)
348{
Kiran Divekarab65f642009-02-19 19:32:39 -0500349 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400350 int ret = 0;
351 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352
Holger Schurig9012b282007-05-25 11:27:16 -0400353 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354
Dan Williams39fcf7a2008-09-10 12:49:00 -0400355 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400356 if (ret)
357 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200358
Dan Williams39fcf7a2008-09-10 12:49:00 -0400359 vwrq->value = val;
John W. Linville375da532008-09-15 17:25:54 -0400360 vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200361 vwrq->fixed = 1;
362
Holger Schurig9012b282007-05-25 11:27:16 -0400363out:
364 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
365 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200366}
367
Holger Schurig10078322007-11-15 18:05:47 -0500368static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369 struct iw_param *vwrq, char *extra)
370{
Kiran Divekarab65f642009-02-19 19:32:39 -0500371 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400372 int ret = 0;
373 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200374
Holger Schurig9012b282007-05-25 11:27:16 -0400375 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376
Dan Williams39fcf7a2008-09-10 12:49:00 -0400377 if (vwrq->disabled)
378 val = MRVDRV_FRAG_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200379
Dan Williams39fcf7a2008-09-10 12:49:00 -0400380 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
381 return -EINVAL;
382
383 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
Holger Schurig9012b282007-05-25 11:27:16 -0400384
385 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386 return ret;
387}
388
Holger Schurig10078322007-11-15 18:05:47 -0500389static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200390 struct iw_param *vwrq, char *extra)
391{
Kiran Divekarab65f642009-02-19 19:32:39 -0500392 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400393 int ret = 0;
394 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200395
Holger Schurig9012b282007-05-25 11:27:16 -0400396 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397
Dan Williams39fcf7a2008-09-10 12:49:00 -0400398 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400399 if (ret)
400 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200401
Dan Williams39fcf7a2008-09-10 12:49:00 -0400402 vwrq->value = val;
403 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
404 || (val > MRVDRV_FRAG_MAX_VALUE));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200405 vwrq->fixed = 1;
406
Holger Schurig9012b282007-05-25 11:27:16 -0400407out:
408 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200409 return ret;
410}
411
Holger Schurig10078322007-11-15 18:05:47 -0500412static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413 struct iw_request_info *info, u32 * uwrq, char *extra)
414{
Kiran Divekarab65f642009-02-19 19:32:39 -0500415 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200416
Holger Schurig9012b282007-05-25 11:27:16 -0400417 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200418
David Woodhouseaa21c002007-12-08 20:04:36 +0000419 *uwrq = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200420
Holger Schurig9012b282007-05-25 11:27:16 -0400421 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200422 return 0;
423}
424
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400425static int mesh_wlan_get_mode(struct net_device *dev,
426 struct iw_request_info *info, u32 * uwrq,
427 char *extra)
428{
429 lbs_deb_enter(LBS_DEB_WEXT);
430
Dan Williams39fcf7a2008-09-10 12:49:00 -0400431 *uwrq = IW_MODE_REPEAT;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400432
433 lbs_deb_leave(LBS_DEB_WEXT);
434 return 0;
435}
436
Holger Schurig10078322007-11-15 18:05:47 -0500437static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200438 struct iw_request_info *info,
439 struct iw_param *vwrq, char *extra)
440{
Kiran Divekarab65f642009-02-19 19:32:39 -0500441 struct lbs_private *priv = dev->ml_priv;
Dan Williams87c8c722008-08-19 15:15:35 -0400442 s16 curlevel = 0;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400443 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200444
Holger Schurig9012b282007-05-25 11:27:16 -0400445 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200446
Dan Williamsd5db2df2008-08-21 17:51:07 -0400447 if (!priv->radio_on) {
448 lbs_deb_wext("tx power off\n");
449 vwrq->value = 0;
450 vwrq->disabled = 1;
451 goto out;
452 }
453
Dan Williams87c8c722008-08-19 15:15:35 -0400454 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400455 if (ret)
456 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200457
Dan Williams87c8c722008-08-19 15:15:35 -0400458 lbs_deb_wext("tx power level %d dbm\n", curlevel);
Dan Williams87c8c722008-08-19 15:15:35 -0400459 priv->txpower_cur = curlevel;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400460
Dan Williams87c8c722008-08-19 15:15:35 -0400461 vwrq->value = curlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200462 vwrq->fixed = 1;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400463 vwrq->disabled = 0;
464 vwrq->flags = IW_TXPOW_DBM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200465
Holger Schurig9012b282007-05-25 11:27:16 -0400466out:
467 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
468 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469}
470
Holger Schurig10078322007-11-15 18:05:47 -0500471static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472 struct iw_param *vwrq, char *extra)
473{
Kiran Divekarab65f642009-02-19 19:32:39 -0500474 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400475 int ret = 0;
476 u16 slimit = 0, llimit = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200477
Holger Schurig9012b282007-05-25 11:27:16 -0400478 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200479
Dan Williams39fcf7a2008-09-10 12:49:00 -0400480 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
481 return -EOPNOTSUPP;
482
483 /* The MAC has a 4-bit Total_Tx_Count register
484 Total_Tx_Count = 1 + Tx_Retry_Count */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200485#define TX_RETRY_MIN 0
486#define TX_RETRY_MAX 14
Dan Williams39fcf7a2008-09-10 12:49:00 -0400487 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
488 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489
Dan Williams39fcf7a2008-09-10 12:49:00 -0400490 /* Add 1 to convert retry count to try count */
491 if (vwrq->flags & IW_RETRY_SHORT)
492 slimit = (u16) (vwrq->value + 1);
493 else if (vwrq->flags & IW_RETRY_LONG)
494 llimit = (u16) (vwrq->value + 1);
495 else
496 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200497
Dan Williams39fcf7a2008-09-10 12:49:00 -0400498 if (llimit) {
499 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
500 llimit);
Holger Schurig9012b282007-05-25 11:27:16 -0400501 if (ret)
502 goto out;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400503 }
504
505 if (slimit) {
506 /* txretrycount follows the short retry limit */
507 priv->txretrycount = slimit;
508 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
509 slimit);
510 if (ret)
511 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200512 }
513
Holger Schurig9012b282007-05-25 11:27:16 -0400514out:
515 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
516 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200517}
518
Holger Schurig10078322007-11-15 18:05:47 -0500519static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200520 struct iw_param *vwrq, char *extra)
521{
Kiran Divekarab65f642009-02-19 19:32:39 -0500522 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200523 int ret = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400524 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200525
Holger Schurig9012b282007-05-25 11:27:16 -0400526 lbs_deb_enter(LBS_DEB_WEXT);
527
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528 vwrq->disabled = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400529
530 if (vwrq->flags & IW_RETRY_LONG) {
531 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
532 if (ret)
533 goto out;
534
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200535 /* Subtract 1 to convert try count to retry count */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400536 vwrq->value = val - 1;
537 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
538 } else {
539 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
540 if (ret)
541 goto out;
542
543 /* txretry count follows the short retry limit */
544 priv->txretrycount = val;
545 /* Subtract 1 to convert try count to retry count */
546 vwrq->value = val - 1;
547 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200548 }
549
Holger Schurig9012b282007-05-25 11:27:16 -0400550out:
551 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
552 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553}
554
555static inline void sort_channels(struct iw_freq *freq, int num)
556{
557 int i, j;
558 struct iw_freq temp;
559
560 for (i = 0; i < num; i++)
561 for (j = i + 1; j < num; j++)
562 if (freq[i].i > freq[j].i) {
563 temp.i = freq[i].i;
564 temp.m = freq[i].m;
565
566 freq[i].i = freq[j].i;
567 freq[i].m = freq[j].m;
568
569 freq[j].i = temp.i;
570 freq[j].m = temp.m;
571 }
572}
573
574/* data rate listing
575 MULTI_BANDS:
576 abg a b b/g
577 Infra G(12) A(8) B(4) G(12)
578 Adhoc A+B(12) A(8) B(4) B(4)
579
580 non-MULTI_BANDS:
581 b b/g
582 Infra B(4) G(12)
583 Adhoc B(4) B(4)
584 */
585/**
586 * @brief Get Range Info
587 *
588 * @param dev A pointer to net_device structure
589 * @param info A pointer to iw_request_info structure
590 * @param vwrq A pointer to iw_param structure
591 * @param extra A pointer to extra data buf
592 * @return 0 --success, otherwise fail
593 */
Holger Schurig10078322007-11-15 18:05:47 -0500594static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200595 struct iw_point *dwrq, char *extra)
596{
597 int i, j;
Kiran Divekarab65f642009-02-19 19:32:39 -0500598 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599 struct iw_range *range = (struct iw_range *)extra;
600 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400601 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200602
Holger Schurig9012b282007-05-25 11:27:16 -0400603 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604
605 dwrq->length = sizeof(struct iw_range);
606 memset(range, 0, sizeof(struct iw_range));
607
608 range->min_nwid = 0;
609 range->max_nwid = 0;
610
611 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000612 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400613 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
614 for (i = 0; i < range->num_bitrates; i++)
615 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400617 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200618 range->num_bitrates);
619
620 range->num_frequency = 0;
Holger Schurig52933d82008-03-05 07:05:32 +0100621
622 range->scan_capa = IW_SCAN_CAPA_ESSID;
623
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200624 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
625 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
626 cfp = priv->region_channel[j].CFP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200628 && priv->region_channel[j].valid
629 && cfp
630 && (i < priv->region_channel[j].nrcfp); i++) {
631 range->freq[range->num_frequency].i =
632 (long)cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200633 range->freq[range->num_frequency].m =
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200634 (long)cfp->freq * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200635 range->freq[range->num_frequency].e = 1;
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200636 cfp++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200637 range->num_frequency++;
638 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200639 }
640
Holger Schurig9012b282007-05-25 11:27:16 -0400641 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200642 IW_MAX_FREQUENCIES, range->num_frequency);
643
644 range->num_channels = range->num_frequency;
645
646 sort_channels(&range->freq[0], range->num_frequency);
647
648 /*
649 * Set an indication of the max TCP throughput in bit/s that we can
650 * expect using this interface
651 */
652 if (i > 2)
653 range->throughput = 5000 * 1000;
654 else
655 range->throughput = 1500 * 1000;
656
657 range->min_rts = MRVDRV_RTS_MIN_VALUE;
658 range->max_rts = MRVDRV_RTS_MAX_VALUE;
659 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
660 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
661
662 range->encoding_size[0] = 5;
663 range->encoding_size[1] = 13;
664 range->num_encoding_sizes = 2;
665 range->max_encoding_tokens = 4;
666
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100667 /*
668 * Right now we support only "iwconfig ethX power on|off"
669 */
670 range->pm_capa = IW_POWER_ON;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200671
672 /*
673 * Minimum version we recommend
674 */
675 range->we_version_source = 15;
676
677 /*
678 * Version we are compiled with
679 */
680 range->we_version_compiled = WIRELESS_EXT;
681
682 range->retry_capa = IW_RETRY_LIMIT;
683 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
684
685 range->min_retry = TX_RETRY_MIN;
686 range->max_retry = TX_RETRY_MAX;
687
688 /*
689 * Set the qual, level and noise range values
690 */
691 range->max_qual.qual = 100;
692 range->max_qual.level = 0;
693 range->max_qual.noise = 0;
694 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
695
696 range->avg_qual.qual = 70;
697 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
698 range->avg_qual.level = 0;
699 range->avg_qual.noise = 0;
700 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
701
702 range->sensitivity = 0;
703
Dan Williams87c8c722008-08-19 15:15:35 -0400704 /* Setup the supported power level ranges */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200705 memset(range->txpower, 0, sizeof(range->txpower));
Dan Williams87c8c722008-08-19 15:15:35 -0400706 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
707 range->txpower[0] = priv->txpower_min;
708 range->txpower[1] = priv->txpower_max;
709 range->num_txpower = 2;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200710
711 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
712 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
713 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
714 range->event_capa[1] = IW_EVENT_CAPA_K_1;
715
David Woodhouseaa21c002007-12-08 20:04:36 +0000716 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200717 range->enc_capa = IW_ENC_CAPA_WPA
718 | IW_ENC_CAPA_WPA2
719 | IW_ENC_CAPA_CIPHER_TKIP
720 | IW_ENC_CAPA_CIPHER_CCMP;
721 }
722
Holger Schurig9012b282007-05-25 11:27:16 -0400723 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724 return 0;
725}
726
Holger Schurig10078322007-11-15 18:05:47 -0500727static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200728 struct iw_param *vwrq, char *extra)
729{
Kiran Divekarab65f642009-02-19 19:32:39 -0500730 struct lbs_private *priv = dev->ml_priv;
Amitkumar Karwar49125452009-09-30 20:04:38 -0700731 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200732
Holger Schurig9012b282007-05-25 11:27:16 -0400733 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200734
Andrey Yurovskye0d61332009-06-16 13:20:01 -0700735 if (!(priv->fwcapinfo & FW_CAPINFO_PS)) {
David Woodhouseb2c57ee2007-12-17 14:41:13 -0500736 if (vwrq->disabled)
737 return 0;
738 else
739 return -EINVAL;
740 }
741
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200742 /* PS is currently supported only in Infrastructure mode
743 * Remove this check if it is to be supported in IBSS mode also
744 */
745
746 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000747 priv->psmode = LBS802_11POWERMODECAM;
748 if (priv->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500749 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200750 }
751
752 return 0;
753 }
754
755 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400756 lbs_deb_wext(
757 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200758 return -EINVAL;
759 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Amitkumar Karwar49125452009-09-30 20:04:38 -0700760 vwrq->value = vwrq->value / 1000;
761 if (!priv->enter_deep_sleep) {
762 lbs_pr_err("deep sleep feature is not implemented "
763 "for this interface driver\n");
764 return -EINVAL;
765 }
766
767 if (priv->connect_status == LBS_CONNECTED) {
768 if ((priv->is_auto_deep_sleep_enabled) &&
769 (vwrq->value == -1000)) {
770 lbs_exit_auto_deep_sleep(priv);
771 return 0;
772 } else {
773 lbs_pr_err("can't use deep sleep cmd in "
774 "connected state\n");
775 return -EINVAL;
776 }
777 }
778
779 if ((vwrq->value < 0) && (vwrq->value != -1000)) {
780 lbs_pr_err("unknown option\n");
781 return -EINVAL;
782 }
783
784 if (vwrq->value > 0) {
785 if (!priv->is_auto_deep_sleep_enabled) {
786 priv->is_activity_detected = 0;
787 priv->auto_deep_sleep_timeout = vwrq->value;
788 lbs_enter_auto_deep_sleep(priv);
789 } else {
790 priv->auto_deep_sleep_timeout = vwrq->value;
791 lbs_deb_debugfs("auto deep sleep: "
792 "already enabled\n");
793 }
794 return 0;
795 } else {
796 if (priv->is_auto_deep_sleep_enabled) {
797 lbs_exit_auto_deep_sleep(priv);
798 /* Try to exit deep sleep if auto */
799 /*deep sleep disabled */
800 ret = lbs_set_deep_sleep(priv, 0);
801 }
802 if (vwrq->value == 0)
803 ret = lbs_set_deep_sleep(priv, 1);
804 else if (vwrq->value == -1000)
805 ret = lbs_set_deep_sleep(priv, 0);
806 return ret;
807 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200808 }
809
David Woodhouseaa21c002007-12-08 20:04:36 +0000810 if (priv->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200811 return 0;
812 }
813
David Woodhouseaa21c002007-12-08 20:04:36 +0000814 priv->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200815
David Woodhouseaa21c002007-12-08 20:04:36 +0000816 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500817 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200818 }
819
Holger Schurig9012b282007-05-25 11:27:16 -0400820 lbs_deb_leave(LBS_DEB_WEXT);
Amitkumar Karwar49125452009-09-30 20:04:38 -0700821
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200822 return 0;
823}
824
Holger Schurig10078322007-11-15 18:05:47 -0500825static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200826 struct iw_param *vwrq, char *extra)
827{
Kiran Divekarab65f642009-02-19 19:32:39 -0500828 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200829
Holger Schurig9012b282007-05-25 11:27:16 -0400830 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200831
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200832 vwrq->value = 0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100833 vwrq->flags = 0;
834 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
835 || priv->connect_status == LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200836
Holger Schurig9012b282007-05-25 11:27:16 -0400837 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200838 return 0;
839}
840
Holger Schurig10078322007-11-15 18:05:47 -0500841static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200842{
843 enum {
844 POOR = 30,
845 FAIR = 60,
846 GOOD = 80,
847 VERY_GOOD = 90,
848 EXCELLENT = 95,
849 PERFECT = 100
850 };
Kiran Divekarab65f642009-02-19 19:32:39 -0500851 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200852 u32 rssi_qual;
853 u32 tx_qual;
854 u32 quality = 0;
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700855 int ret, stats_valid = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856 u8 rssi;
857 u32 tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100858 struct cmd_ds_802_11_get_log log;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200859
Holger Schurig9012b282007-05-25 11:27:16 -0400860 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200861
David Woodhouseaa21c002007-12-08 20:04:36 +0000862 priv->wstats.status = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200863
864 /* If we're not associated, all quality values are meaningless */
David Woodhouseaa21c002007-12-08 20:04:36 +0000865 if ((priv->connect_status != LBS_CONNECTED) &&
866 (priv->mesh_connect_status != LBS_CONNECTED))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200867 goto out;
868
869 /* Quality by RSSI */
870 priv->wstats.qual.level =
David Woodhouseaa21c002007-12-08 20:04:36 +0000871 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
872 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200873
David Woodhouseaa21c002007-12-08 20:04:36 +0000874 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200875 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
876 } else {
877 priv->wstats.qual.noise =
David Woodhouseaa21c002007-12-08 20:04:36 +0000878 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200879 }
880
Holger Schurig9012b282007-05-25 11:27:16 -0400881 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
882 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200883
884 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
885 if (rssi < 15)
886 rssi_qual = rssi * POOR / 10;
887 else if (rssi < 20)
888 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
889 else if (rssi < 30)
890 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
891 else if (rssi < 40)
892 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
893 10 + GOOD;
894 else
895 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
896 10 + VERY_GOOD;
897 quality = rssi_qual;
898
899 /* Quality by TX errors */
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000900 priv->wstats.discard.retries = dev->stats.tx_errors;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200901
Holger Schurigc49c3b72008-03-17 12:45:58 +0100902 memset(&log, 0, sizeof(log));
903 log.hdr.size = cpu_to_le16(sizeof(log));
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700904 ret = lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
905 if (ret)
906 goto out;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100907
908 tx_retries = le32_to_cpu(log.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200909
910 if (tx_retries > 75)
911 tx_qual = (90 - tx_retries) * POOR / 15;
912 else if (tx_retries > 70)
913 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
914 else if (tx_retries > 65)
915 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
916 else if (tx_retries > 50)
917 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
918 15 + GOOD;
919 else
920 tx_qual = (50 - tx_retries) *
921 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
922 quality = min(quality, tx_qual);
923
Holger Schurigc49c3b72008-03-17 12:45:58 +0100924 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200925 priv->wstats.discard.retries = tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100926 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200927
928 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400929 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200930 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
931 stats_valid = 1;
932
933 /* update stats asynchronously for future calls */
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700934 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200935 0, 0, NULL);
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700936 if (ret)
937 lbs_pr_err("RSSI command failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200938out:
939 if (!stats_valid) {
940 priv->wstats.miss.beacon = 0;
941 priv->wstats.discard.retries = 0;
942 priv->wstats.qual.qual = 0;
943 priv->wstats.qual.level = 0;
944 priv->wstats.qual.noise = 0;
945 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
946 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
947 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
948 }
949
Holger Schurig9012b282007-05-25 11:27:16 -0400950 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200951 return &priv->wstats;
952
953
954}
955
Holger Schurig10078322007-11-15 18:05:47 -0500956static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200957 struct iw_freq *fwrq, char *extra)
958{
Dan Williamsef9a2642007-05-25 16:46:33 -0400959 int ret = -EINVAL;
Kiran Divekarab65f642009-02-19 19:32:39 -0500960 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200961 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400962 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200963
Holger Schurig9012b282007-05-25 11:27:16 -0400964 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200965
David Woodhouseaa21c002007-12-08 20:04:36 +0000966 mutex_lock(&priv->lock);
967 assoc_req = lbs_get_association_request(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400968 if (!assoc_req) {
969 ret = -ENOMEM;
970 goto out;
971 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200972
Dan Williamsef9a2642007-05-25 16:46:33 -0400973 /* If setting by frequency, convert to a channel */
974 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200975 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200976
David Woodhouseaa21c002007-12-08 20:04:36 +0000977 cfp = find_cfp_by_band_and_freq(priv, 0, f);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200978 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400979 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400980 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200981 }
982
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200983 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400984 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200985 }
986
Dan Williamsef9a2642007-05-25 16:46:33 -0400987 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200988 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400989 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200990 }
991
David Woodhouseaa21c002007-12-08 20:04:36 +0000992 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400993 if (!cfp) {
994 goto out;
995 }
996
997 assoc_req->channel = fwrq->m;
998 ret = 0;
999
Holger Schurig9012b282007-05-25 11:27:16 -04001000out:
Dan Williamsef9a2642007-05-25 16:46:33 -04001001 if (ret == 0) {
1002 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001003 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -04001004 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001005 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -04001006 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001007 mutex_unlock(&priv->lock);
Dan Williamsef9a2642007-05-25 16:46:33 -04001008
1009 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1010 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001011}
1012
David Woodhouse823eaa22007-12-11 19:56:28 -05001013static int lbs_mesh_set_freq(struct net_device *dev,
1014 struct iw_request_info *info,
1015 struct iw_freq *fwrq, char *extra)
1016{
Kiran Divekarab65f642009-02-19 19:32:39 -05001017 struct lbs_private *priv = dev->ml_priv;
David Woodhouse823eaa22007-12-11 19:56:28 -05001018 struct chan_freq_power *cfp;
1019 int ret = -EINVAL;
1020
1021 lbs_deb_enter(LBS_DEB_WEXT);
1022
1023 /* If setting by frequency, convert to a channel */
1024 if (fwrq->e == 1) {
1025 long f = fwrq->m / 100000;
1026
1027 cfp = find_cfp_by_band_and_freq(priv, 0, f);
1028 if (!cfp) {
1029 lbs_deb_wext("invalid freq %ld\n", f);
1030 goto out;
1031 }
1032
1033 fwrq->e = 0;
1034 fwrq->m = (int) cfp->channel;
1035 }
1036
1037 /* Setting by channel number */
1038 if (fwrq->m > 1000 || fwrq->e > 0) {
1039 goto out;
1040 }
1041
1042 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
1043 if (!cfp) {
1044 goto out;
1045 }
1046
Holger Schurigc14951f2009-10-22 15:30:50 +02001047 if (fwrq->m != priv->channel) {
David Woodhouse823eaa22007-12-11 19:56:28 -05001048 lbs_deb_wext("mesh channel change forces eth disconnect\n");
1049 if (priv->mode == IW_MODE_INFRA)
Dan Williams191bb402008-08-21 17:46:18 -04001050 lbs_cmd_80211_deauthenticate(priv,
1051 priv->curbssparams.bssid,
1052 WLAN_REASON_DEAUTH_LEAVING);
David Woodhouse823eaa22007-12-11 19:56:28 -05001053 else if (priv->mode == IW_MODE_ADHOC)
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001054 lbs_adhoc_stop(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -05001055 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001056 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
David Woodhouse86062132007-12-13 00:32:36 -05001057 lbs_update_channel(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -05001058 ret = 0;
1059
1060out:
1061 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1062 return ret;
1063}
1064
Holger Schurig10078322007-11-15 18:05:47 -05001065static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001066 struct iw_param *vwrq, char *extra)
1067{
Kiran Divekarab65f642009-02-19 19:32:39 -05001068 struct lbs_private *priv = dev->ml_priv;
Dan Williams8e3c91b2007-12-11 15:50:59 -05001069 u8 new_rate = 0;
Dan Williams8c512762007-08-02 11:40:45 -04001070 int ret = -EINVAL;
1071 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001072
Holger Schurig9012b282007-05-25 11:27:16 -04001073 lbs_deb_enter(LBS_DEB_WEXT);
Amitkumar Karwar49125452009-09-30 20:04:38 -07001074
Holger Schurig9012b282007-05-25 11:27:16 -04001075 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Javier Cardona85319f92008-05-24 10:59:49 +01001076 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1077
1078 if (vwrq->fixed && vwrq->value == -1)
1079 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001080
Dan Williams8c512762007-08-02 11:40:45 -04001081 /* Auto rate? */
Javier Cardona85319f92008-05-24 10:59:49 +01001082 priv->enablehwauto = !vwrq->fixed;
1083
1084 if (vwrq->value == -1)
David Woodhouseaa21c002007-12-08 20:04:36 +00001085 priv->cur_rate = 0;
Javier Cardona85319f92008-05-24 10:59:49 +01001086 else {
Dan Williams8c512762007-08-02 11:40:45 -04001087 if (vwrq->value % 100000)
1088 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001089
Javier Cardona85319f92008-05-24 10:59:49 +01001090 new_rate = vwrq->value / 500000;
1091 priv->cur_rate = new_rate;
1092 /* the rest is only needed for lbs_set_data_rate() */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001093 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +00001094 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -04001095 if (!memchr(rates, new_rate, sizeof(rates))) {
1096 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1097 new_rate);
1098 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001099 }
Anna Neal3ed6e082008-09-26 11:34:35 -04001100 if (priv->fwrelease < 0x09000000) {
1101 ret = lbs_set_power_adapt_cfg(priv, 0,
1102 POW_ADAPT_DEFAULT_P0,
1103 POW_ADAPT_DEFAULT_P1,
1104 POW_ADAPT_DEFAULT_P2);
1105 if (ret)
1106 goto out;
1107 }
1108 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1109 TPC_DEFAULT_P2, 1);
1110 if (ret)
1111 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001112 }
1113
Javier Cardona85319f92008-05-24 10:59:49 +01001114 /* Try the newer command first (Firmware Spec 5.1 and above) */
1115 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1116
1117 /* Fallback to older version */
1118 if (ret)
1119 ret = lbs_set_data_rate(priv, new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001120
Dan Williams8c512762007-08-02 11:40:45 -04001121out:
Holger Schurig9012b282007-05-25 11:27:16 -04001122 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001123 return ret;
1124}
1125
Holger Schurig10078322007-11-15 18:05:47 -05001126static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001127 struct iw_param *vwrq, char *extra)
1128{
Kiran Divekarab65f642009-02-19 19:32:39 -05001129 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001130
Holger Schurig9012b282007-05-25 11:27:16 -04001131 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001132
David Woodhouseaa21c002007-12-08 20:04:36 +00001133 if (priv->connect_status == LBS_CONNECTED) {
1134 vwrq->value = priv->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001135
Javier Cardona85319f92008-05-24 10:59:49 +01001136 if (priv->enablehwauto)
Dan Williams8c512762007-08-02 11:40:45 -04001137 vwrq->fixed = 0;
1138 else
1139 vwrq->fixed = 1;
1140
1141 } else {
1142 vwrq->fixed = 0;
1143 vwrq->value = 0;
1144 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001145
Holger Schurig9012b282007-05-25 11:27:16 -04001146 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001147 return 0;
1148}
1149
Holger Schurig10078322007-11-15 18:05:47 -05001150static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001151 struct iw_request_info *info, u32 * uwrq, char *extra)
1152{
1153 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001154 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001155 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001156
Holger Schurig9012b282007-05-25 11:27:16 -04001157 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001158
Dan Williams0dc5a292007-05-10 22:58:02 -04001159 if ( (*uwrq != IW_MODE_ADHOC)
1160 && (*uwrq != IW_MODE_INFRA)
1161 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001162 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001163 ret = -EINVAL;
1164 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001165 }
1166
David Woodhouseaa21c002007-12-08 20:04:36 +00001167 mutex_lock(&priv->lock);
1168 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001169 if (!assoc_req) {
1170 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001171 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001172 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001173 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001174 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001175 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001176 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001177 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001178 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001179
Dan Williams0dc5a292007-05-10 22:58:02 -04001180out:
Holger Schurig9012b282007-05-25 11:27:16 -04001181 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001182 return ret;
1183}
1184
1185
1186/**
1187 * @brief Get Encryption key
1188 *
1189 * @param dev A pointer to net_device structure
1190 * @param info A pointer to iw_request_info structure
1191 * @param vwrq A pointer to iw_param structure
1192 * @param extra A pointer to extra data buf
1193 * @return 0 --success, otherwise fail
1194 */
Holger Schurig10078322007-11-15 18:05:47 -05001195static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001196 struct iw_request_info *info,
1197 struct iw_point *dwrq, u8 * extra)
1198{
Kiran Divekarab65f642009-02-19 19:32:39 -05001199 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001200 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1201
Holger Schurig9012b282007-05-25 11:27:16 -04001202 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001203
Holger Schurig9012b282007-05-25 11:27:16 -04001204 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001205 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001206
1207 dwrq->flags = 0;
1208
1209 /* Authentication method */
David Woodhouseaa21c002007-12-08 20:04:36 +00001210 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -04001211 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001212 dwrq->flags = IW_ENCODE_OPEN;
1213 break;
1214
Dan Williams6affe782007-05-10 22:56:42 -04001215 case IW_AUTH_ALG_SHARED_KEY:
1216 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001217 dwrq->flags = IW_ENCODE_RESTRICTED;
1218 break;
1219 default:
1220 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1221 break;
1222 }
1223
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001224 memset(extra, 0, 16);
1225
David Woodhouseaa21c002007-12-08 20:04:36 +00001226 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001227
1228 /* Default to returning current transmit key */
1229 if (index < 0)
David Woodhouseaa21c002007-12-08 20:04:36 +00001230 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001231
David Woodhouseaa21c002007-12-08 20:04:36 +00001232 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1233 memcpy(extra, priv->wep_keys[index].key,
1234 priv->wep_keys[index].len);
1235 dwrq->length = priv->wep_keys[index].len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001236
1237 dwrq->flags |= (index + 1);
1238 /* Return WEP enabled */
1239 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhouseaa21c002007-12-08 20:04:36 +00001240 } else if ((priv->secinfo.WPAenabled)
1241 || (priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001242 /* return WPA enabled */
1243 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhousec12bdc42007-12-07 19:32:12 +00001244 dwrq->flags |= IW_ENCODE_NOKEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001245 } else {
1246 dwrq->flags |= IW_ENCODE_DISABLED;
1247 }
1248
David Woodhouseaa21c002007-12-08 20:04:36 +00001249 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001250
Joe Perches0795af52007-10-03 17:59:30 -07001251 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001252 extra[0], extra[1], extra[2],
1253 extra[3], extra[4], extra[5], dwrq->length);
1254
Holger Schurig9012b282007-05-25 11:27:16 -04001255 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001256
Holger Schurig9012b282007-05-25 11:27:16 -04001257 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001258 return 0;
1259}
1260
1261/**
1262 * @brief Set Encryption key (internal)
1263 *
1264 * @param priv A pointer to private card structure
1265 * @param key_material A pointer to key material
1266 * @param key_length length of key material
1267 * @param index key index to set
1268 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1269 * @return 0 --success, otherwise fail
1270 */
Holger Schurig10078322007-11-15 18:05:47 -05001271static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001272 const char *key_material,
1273 u16 key_length,
1274 u16 index,
1275 int set_tx_key)
1276{
Holger Schurig9012b282007-05-25 11:27:16 -04001277 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001278 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001279
Holger Schurig9012b282007-05-25 11:27:16 -04001280 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001281
1282 /* Paranoid validation of key index */
1283 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001284 ret = -EINVAL;
1285 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001286 }
1287
1288 /* validate max key length */
1289 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001290 ret = -EINVAL;
1291 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001292 }
1293
1294 pkey = &assoc_req->wep_keys[index];
1295
1296 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001297 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001298 pkey->type = KEY_TYPE_ID_WEP;
1299
1300 /* Standardize the key length */
1301 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1302 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1303 memcpy(pkey->key, key_material, key_length);
1304 }
1305
1306 if (set_tx_key) {
1307 /* Ensure the chosen key is valid */
1308 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001309 lbs_deb_wext("key not set, so cannot enable it\n");
1310 ret = -EINVAL;
1311 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001312 }
1313 assoc_req->wep_tx_keyidx = index;
1314 }
1315
Dan Williams889c05b2007-05-10 22:57:23 -04001316 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001317
Holger Schurig9012b282007-05-25 11:27:16 -04001318out:
1319 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1320 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001321}
1322
1323static int validate_key_index(u16 def_index, u16 raw_index,
1324 u16 *out_index, u16 *is_default)
1325{
1326 if (!out_index || !is_default)
1327 return -EINVAL;
1328
1329 /* Verify index if present, otherwise use default TX key index */
1330 if (raw_index > 0) {
1331 if (raw_index > 4)
1332 return -EINVAL;
1333 *out_index = raw_index - 1;
1334 } else {
1335 *out_index = def_index;
1336 *is_default = 1;
1337 }
1338 return 0;
1339}
1340
1341static void disable_wep(struct assoc_request *assoc_req)
1342{
1343 int i;
1344
Dan Williams90a42212007-05-25 23:01:24 -04001345 lbs_deb_enter(LBS_DEB_WEXT);
1346
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001347 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001348 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349
1350 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001351 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001352 for (i = 0; i < 4; i++)
1353 assoc_req->wep_keys[i].len = 0;
1354
1355 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1356 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001357
1358 lbs_deb_leave(LBS_DEB_WEXT);
1359}
1360
1361static void disable_wpa(struct assoc_request *assoc_req)
1362{
1363 lbs_deb_enter(LBS_DEB_WEXT);
1364
Dan Williams1443b652007-08-02 10:45:55 -04001365 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001366 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1367 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1368
Dan Williams1443b652007-08-02 10:45:55 -04001369 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001370 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1371 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1372
1373 assoc_req->secinfo.WPAenabled = 0;
1374 assoc_req->secinfo.WPA2enabled = 0;
1375 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1376
1377 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001378}
1379
1380/**
1381 * @brief Set Encryption key
1382 *
1383 * @param dev A pointer to net_device structure
1384 * @param info A pointer to iw_request_info structure
1385 * @param vwrq A pointer to iw_param structure
1386 * @param extra A pointer to extra data buf
1387 * @return 0 --success, otherwise fail
1388 */
Holger Schurig10078322007-11-15 18:05:47 -05001389static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001390 struct iw_request_info *info,
1391 struct iw_point *dwrq, char *extra)
1392{
1393 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001394 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001395 struct assoc_request * assoc_req;
1396 u16 is_default = 0, index = 0, set_tx_key = 0;
1397
Holger Schurig9012b282007-05-25 11:27:16 -04001398 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001399
David Woodhouseaa21c002007-12-08 20:04:36 +00001400 mutex_lock(&priv->lock);
1401 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001402 if (!assoc_req) {
1403 ret = -ENOMEM;
1404 goto out;
1405 }
1406
1407 if (dwrq->flags & IW_ENCODE_DISABLED) {
1408 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001409 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410 goto out;
1411 }
1412
1413 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1414 (dwrq->flags & IW_ENCODE_INDEX),
1415 &index, &is_default);
1416 if (ret) {
1417 ret = -EINVAL;
1418 goto out;
1419 }
1420
1421 /* If WEP isn't enabled, or if there is no key data but a valid
1422 * index, set the TX key.
1423 */
Dan Williams889c05b2007-05-10 22:57:23 -04001424 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001425 set_tx_key = 1;
1426
Holger Schurig10078322007-11-15 18:05:47 -05001427 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001428 if (ret)
1429 goto out;
1430
1431 if (dwrq->length)
1432 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1433 if (set_tx_key)
1434 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1435
1436 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001437 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001438 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001439 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001440 }
1441
1442out:
1443 if (ret == 0) {
1444 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001445 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001446 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001447 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001448 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001449 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001450
Holger Schurig9012b282007-05-25 11:27:16 -04001451 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001452 return ret;
1453}
1454
1455/**
1456 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1457 *
1458 * @param dev A pointer to net_device structure
1459 * @param info A pointer to iw_request_info structure
1460 * @param vwrq A pointer to iw_param structure
1461 * @param extra A pointer to extra data buf
1462 * @return 0 on success, otherwise failure
1463 */
Holger Schurig10078322007-11-15 18:05:47 -05001464static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001465 struct iw_request_info *info,
1466 struct iw_point *dwrq,
1467 char *extra)
1468{
1469 int ret = -EINVAL;
Kiran Divekarab65f642009-02-19 19:32:39 -05001470 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001471 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1472 int index, max_key_len;
1473
Holger Schurig9012b282007-05-25 11:27:16 -04001474 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001475
1476 max_key_len = dwrq->length - sizeof(*ext);
1477 if (max_key_len < 0)
1478 goto out;
1479
1480 index = dwrq->flags & IW_ENCODE_INDEX;
1481 if (index) {
1482 if (index < 1 || index > 4)
1483 goto out;
1484 index--;
1485 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001486 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487 }
1488
Roel Kluinf59d9782007-10-26 21:51:26 +02001489 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001490 ext->alg != IW_ENCODE_ALG_WEP) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001491 if (index != 0 || priv->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001492 goto out;
1493 }
1494
1495 dwrq->flags = index + 1;
1496 memset(ext, 0, sizeof(*ext));
1497
David Woodhouseaa21c002007-12-08 20:04:36 +00001498 if ( !priv->secinfo.wep_enabled
1499 && !priv->secinfo.WPAenabled
1500 && !priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001501 ext->alg = IW_ENCODE_ALG_NONE;
1502 ext->key_len = 0;
1503 dwrq->flags |= IW_ENCODE_DISABLED;
1504 } else {
1505 u8 *key = NULL;
1506
David Woodhouseaa21c002007-12-08 20:04:36 +00001507 if ( priv->secinfo.wep_enabled
1508 && !priv->secinfo.WPAenabled
1509 && !priv->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001510 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001511 ext->alg = IW_ENCODE_ALG_WEP;
David Woodhouseaa21c002007-12-08 20:04:36 +00001512 ext->key_len = priv->wep_keys[index].len;
1513 key = &priv->wep_keys[index].key[0];
1514 } else if ( !priv->secinfo.wep_enabled
1515 && (priv->secinfo.WPAenabled ||
1516 priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001517 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001518 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001519
David Woodhouseaa21c002007-12-08 20:04:36 +00001520 if ( priv->wpa_mcast_key.len
1521 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1522 pkey = &priv->wpa_mcast_key;
1523 else if ( priv->wpa_unicast_key.len
1524 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1525 pkey = &priv->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001526
1527 if (pkey) {
1528 if (pkey->type == KEY_TYPE_ID_AES) {
1529 ext->alg = IW_ENCODE_ALG_CCMP;
1530 } else {
1531 ext->alg = IW_ENCODE_ALG_TKIP;
1532 }
1533 ext->key_len = pkey->len;
1534 key = &pkey->key[0];
1535 } else {
1536 ext->alg = IW_ENCODE_ALG_TKIP;
1537 ext->key_len = 0;
1538 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001539 } else {
1540 goto out;
1541 }
1542
1543 if (ext->key_len > max_key_len) {
1544 ret = -E2BIG;
1545 goto out;
1546 }
1547
1548 if (ext->key_len)
1549 memcpy(ext->key, key, ext->key_len);
1550 else
1551 dwrq->flags |= IW_ENCODE_NOKEY;
1552 dwrq->flags |= IW_ENCODE_ENABLED;
1553 }
1554 ret = 0;
1555
1556out:
Holger Schurig9012b282007-05-25 11:27:16 -04001557 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001558 return ret;
1559}
1560
1561/**
1562 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1563 *
1564 * @param dev A pointer to net_device structure
1565 * @param info A pointer to iw_request_info structure
1566 * @param vwrq A pointer to iw_param structure
1567 * @param extra A pointer to extra data buf
1568 * @return 0 --success, otherwise fail
1569 */
Holger Schurig10078322007-11-15 18:05:47 -05001570static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001571 struct iw_request_info *info,
1572 struct iw_point *dwrq,
1573 char *extra)
1574{
1575 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001576 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001577 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1578 int alg = ext->alg;
1579 struct assoc_request * assoc_req;
1580
Holger Schurig9012b282007-05-25 11:27:16 -04001581 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001582
David Woodhouseaa21c002007-12-08 20:04:36 +00001583 mutex_lock(&priv->lock);
1584 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001585 if (!assoc_req) {
1586 ret = -ENOMEM;
1587 goto out;
1588 }
1589
1590 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1591 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001592 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001593 } else if (alg == IW_ENCODE_ALG_WEP) {
1594 u16 is_default = 0, index, set_tx_key = 0;
1595
1596 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1597 (dwrq->flags & IW_ENCODE_INDEX),
1598 &index, &is_default);
1599 if (ret)
1600 goto out;
1601
1602 /* If WEP isn't enabled, or if there is no key data but a valid
1603 * index, or if the set-TX-key flag was passed, set the TX key.
1604 */
Dan Williams889c05b2007-05-10 22:57:23 -04001605 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001606 || (dwrq->length == 0 && !is_default)
1607 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1608 set_tx_key = 1;
1609
1610 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001611 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001612 set_tx_key);
1613 if (ret)
1614 goto out;
1615
1616 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001617 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001618 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001619 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001620 }
1621
1622 /* Mark the various WEP bits as modified */
1623 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1624 if (dwrq->length)
1625 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1626 if (set_tx_key)
1627 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001628 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001629 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001630
1631 /* validate key length */
1632 if (((alg == IW_ENCODE_ALG_TKIP)
1633 && (ext->key_len != KEY_LEN_WPA_TKIP))
1634 || ((alg == IW_ENCODE_ALG_CCMP)
1635 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001636 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001637 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001638 ext->key_len,
1639 alg);
1640 ret = -EINVAL;
1641 goto out;
1642 }
1643
Dan Williams90a42212007-05-25 23:01:24 -04001644 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001645 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001646 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1647 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001648 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001649 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1650 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001651
Dan Williams1443b652007-08-02 10:45:55 -04001652 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001653 memcpy(pkey->key, ext->key, ext->key_len);
1654 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001655 if (pkey->len)
1656 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001657
Dan Williams90a42212007-05-25 23:01:24 -04001658 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001659 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1660 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001661 } else {
1662 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001663 }
1664
Dan Williams90a42212007-05-25 23:01:24 -04001665 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001666 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001667 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001668 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001669 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001670
1671 /* If WPA isn't enabled yet, do that now */
1672 if ( assoc_req->secinfo.WPAenabled == 0
1673 && assoc_req->secinfo.WPA2enabled == 0) {
1674 assoc_req->secinfo.WPAenabled = 1;
1675 assoc_req->secinfo.WPA2enabled = 1;
1676 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1677 }
1678
Javier Cardona9c31fd632008-09-11 15:32:50 -07001679 /* Only disable wep if necessary: can't waste time here. */
1680 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1681 disable_wep(assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001682 }
1683
1684out:
Javier Cardona9c40fc52008-09-16 18:08:39 -07001685 if (ret == 0) {
1686 /* 802.1x and WPA rekeying must happen as quickly as possible,
1687 * especially during the 4-way handshake; thus if in
1688 * infrastructure mode, and either (a) 802.1x is enabled or
1689 * (b) WPA is being used, set the key right away.
1690 */
1691 if (assoc_req->mode == IW_MODE_INFRA &&
1692 ((assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_802_1X) ||
1693 (assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_PSK) ||
1694 assoc_req->secinfo.WPAenabled ||
1695 assoc_req->secinfo.WPA2enabled)) {
1696 lbs_do_association_work(priv);
1697 } else
1698 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001699 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001700 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001701 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001702 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001703
Holger Schurig9012b282007-05-25 11:27:16 -04001704 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001705 return ret;
1706}
1707
1708
Holger Schurig10078322007-11-15 18:05:47 -05001709static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001710 struct iw_request_info *info,
1711 struct iw_point *dwrq,
1712 char *extra)
1713{
Kiran Divekarab65f642009-02-19 19:32:39 -05001714 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001715 int ret = 0;
1716 struct assoc_request * assoc_req;
1717
Holger Schurig9012b282007-05-25 11:27:16 -04001718 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001719
David Woodhouseaa21c002007-12-08 20:04:36 +00001720 mutex_lock(&priv->lock);
1721 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001722 if (!assoc_req) {
1723 ret = -ENOMEM;
1724 goto out;
1725 }
1726
1727 if (dwrq->length > MAX_WPA_IE_LEN ||
1728 (dwrq->length && extra == NULL)) {
1729 ret = -EINVAL;
1730 goto out;
1731 }
1732
1733 if (dwrq->length) {
1734 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1735 assoc_req->wpa_ie_len = dwrq->length;
1736 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001737 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001738 assoc_req->wpa_ie_len = 0;
1739 }
1740
1741out:
1742 if (ret == 0) {
1743 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001744 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001745 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001746 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001747 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001748 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001749
Holger Schurig9012b282007-05-25 11:27:16 -04001750 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001751 return ret;
1752}
1753
Holger Schurig10078322007-11-15 18:05:47 -05001754static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001755 struct iw_request_info *info,
1756 struct iw_point *dwrq,
1757 char *extra)
1758{
Holger Schurig9012b282007-05-25 11:27:16 -04001759 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001760 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001761
Holger Schurig9012b282007-05-25 11:27:16 -04001762 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001763
David Woodhouseaa21c002007-12-08 20:04:36 +00001764 if (priv->wpa_ie_len == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001765 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001766 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001767 }
1768
David Woodhouseaa21c002007-12-08 20:04:36 +00001769 if (dwrq->length < priv->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001770 ret = -E2BIG;
1771 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001772 }
1773
David Woodhouseaa21c002007-12-08 20:04:36 +00001774 dwrq->length = priv->wpa_ie_len;
1775 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001776
Holger Schurig9012b282007-05-25 11:27:16 -04001777out:
1778 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1779 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001780}
1781
1782
Holger Schurig10078322007-11-15 18:05:47 -05001783static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001784 struct iw_request_info *info,
1785 struct iw_param *dwrq,
1786 char *extra)
1787{
Kiran Divekarab65f642009-02-19 19:32:39 -05001788 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001789 struct assoc_request * assoc_req;
1790 int ret = 0;
1791 int updated = 0;
1792
Holger Schurig9012b282007-05-25 11:27:16 -04001793 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001794
David Woodhouseaa21c002007-12-08 20:04:36 +00001795 mutex_lock(&priv->lock);
1796 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001797 if (!assoc_req) {
1798 ret = -ENOMEM;
1799 goto out;
1800 }
1801
1802 switch (dwrq->flags & IW_AUTH_INDEX) {
Maithili Hinge2c8d5102009-07-31 20:02:19 -07001803 case IW_AUTH_PRIVACY_INVOKED:
1804 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001805 case IW_AUTH_TKIP_COUNTERMEASURES:
1806 case IW_AUTH_CIPHER_PAIRWISE:
1807 case IW_AUTH_CIPHER_GROUP:
Dan Williams90a42212007-05-25 23:01:24 -04001808 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001809 /*
1810 * libertas does not use these parameters
1811 */
1812 break;
1813
Javier Cardona9c40fc52008-09-16 18:08:39 -07001814 case IW_AUTH_KEY_MGMT:
1815 assoc_req->secinfo.key_mgmt = dwrq->value;
1816 updated = 1;
1817 break;
1818
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001819 case IW_AUTH_WPA_VERSION:
1820 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1821 assoc_req->secinfo.WPAenabled = 0;
1822 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001823 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001824 }
1825 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1826 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001827 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001828 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001829 }
1830 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1831 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001832 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001833 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001834 }
1835 updated = 1;
1836 break;
1837
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001838 case IW_AUTH_80211_AUTH_ALG:
1839 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001840 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001841 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001842 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001843 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001844 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845 } else {
1846 ret = -EINVAL;
1847 }
1848 updated = 1;
1849 break;
1850
1851 case IW_AUTH_WPA_ENABLED:
1852 if (dwrq->value) {
1853 if (!assoc_req->secinfo.WPAenabled &&
1854 !assoc_req->secinfo.WPA2enabled) {
1855 assoc_req->secinfo.WPAenabled = 1;
1856 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001857 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001858 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001859 }
1860 } else {
1861 assoc_req->secinfo.WPAenabled = 0;
1862 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001863 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001864 }
1865 updated = 1;
1866 break;
1867
1868 default:
1869 ret = -EOPNOTSUPP;
1870 break;
1871 }
1872
1873out:
1874 if (ret == 0) {
1875 if (updated)
1876 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001877 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001878 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001879 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001880 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001881 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001882
Holger Schurig9012b282007-05-25 11:27:16 -04001883 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001884 return ret;
1885}
1886
Holger Schurig10078322007-11-15 18:05:47 -05001887static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001888 struct iw_request_info *info,
1889 struct iw_param *dwrq,
1890 char *extra)
1891{
Holger Schurig9012b282007-05-25 11:27:16 -04001892 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001893 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001894
Holger Schurig9012b282007-05-25 11:27:16 -04001895 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001896
1897 switch (dwrq->flags & IW_AUTH_INDEX) {
Javier Cardona9c40fc52008-09-16 18:08:39 -07001898 case IW_AUTH_KEY_MGMT:
1899 dwrq->value = priv->secinfo.key_mgmt;
1900 break;
1901
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001902 case IW_AUTH_WPA_VERSION:
1903 dwrq->value = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +00001904 if (priv->secinfo.WPAenabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001905 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
David Woodhouseaa21c002007-12-08 20:04:36 +00001906 if (priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001907 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1908 if (!dwrq->value)
1909 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1910 break;
1911
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001912 case IW_AUTH_80211_AUTH_ALG:
David Woodhouseaa21c002007-12-08 20:04:36 +00001913 dwrq->value = priv->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001914 break;
1915
1916 case IW_AUTH_WPA_ENABLED:
David Woodhouseaa21c002007-12-08 20:04:36 +00001917 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001918 dwrq->value = 1;
1919 break;
1920
1921 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001922 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001923 }
1924
Holger Schurig9012b282007-05-25 11:27:16 -04001925 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1926 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001927}
1928
1929
Holger Schurig10078322007-11-15 18:05:47 -05001930static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001931 struct iw_param *vwrq, char *extra)
1932{
1933 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001934 struct lbs_private *priv = dev->ml_priv;
Dan Williams87c8c722008-08-19 15:15:35 -04001935 s16 dbm = (s16) vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001936
Holger Schurig9012b282007-05-25 11:27:16 -04001937 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001938
1939 if (vwrq->disabled) {
Dan Williamsd5db2df2008-08-21 17:51:07 -04001940 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
Dan Williams87c8c722008-08-19 15:15:35 -04001941 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001942 }
1943
Dan Williams87c8c722008-08-19 15:15:35 -04001944 if (vwrq->fixed == 0) {
Anna Neal0112c9e2008-09-11 11:17:25 -07001945 /* User requests automatic tx power control, however there are
1946 * many auto tx settings. For now use firmware defaults until
1947 * we come up with a good way to expose these to the user. */
1948 if (priv->fwrelease < 0x09000000) {
1949 ret = lbs_set_power_adapt_cfg(priv, 1,
1950 POW_ADAPT_DEFAULT_P0,
1951 POW_ADAPT_DEFAULT_P1,
1952 POW_ADAPT_DEFAULT_P2);
1953 if (ret)
1954 goto out;
1955 }
1956 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1957 TPC_DEFAULT_P2, 1);
1958 if (ret)
1959 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001960 dbm = priv->txpower_max;
1961 } else {
1962 /* Userspace check in iwrange if it should use dBm or mW,
1963 * therefore this should never happen... Jean II */
1964 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1965 ret = -EOPNOTSUPP;
1966 goto out;
1967 }
1968
Anna Neal0112c9e2008-09-11 11:17:25 -07001969 /* Validate requested power level against firmware allowed
1970 * levels */
Dan Williams87c8c722008-08-19 15:15:35 -04001971 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1972 ret = -EINVAL;
1973 goto out;
1974 }
1975
1976 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1977 ret = -EINVAL;
1978 goto out;
1979 }
Anna Neal0112c9e2008-09-11 11:17:25 -07001980 if (priv->fwrelease < 0x09000000) {
1981 ret = lbs_set_power_adapt_cfg(priv, 0,
1982 POW_ADAPT_DEFAULT_P0,
1983 POW_ADAPT_DEFAULT_P1,
1984 POW_ADAPT_DEFAULT_P2);
1985 if (ret)
1986 goto out;
1987 }
1988 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1989 TPC_DEFAULT_P2, 1);
1990 if (ret)
1991 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001992 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001993
Dan Williamsd5db2df2008-08-21 17:51:07 -04001994 /* If the radio was off, turn it on */
1995 if (!priv->radio_on) {
1996 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
1997 if (ret)
1998 goto out;
1999 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002000
Dan Williams87c8c722008-08-19 15:15:35 -04002001 lbs_deb_wext("txpower set %d dBm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002002
Dan Williams87c8c722008-08-19 15:15:35 -04002003 ret = lbs_set_tx_power(priv, dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002004
Dan Williams87c8c722008-08-19 15:15:35 -04002005out:
Holger Schurig9012b282007-05-25 11:27:16 -04002006 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002007 return ret;
2008}
2009
Holger Schurig10078322007-11-15 18:05:47 -05002010static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002011 struct iw_point *dwrq, char *extra)
2012{
Kiran Divekarab65f642009-02-19 19:32:39 -05002013 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002014
Holger Schurig9012b282007-05-25 11:27:16 -04002015 lbs_deb_enter(LBS_DEB_WEXT);
2016
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002017 /*
2018 * Note : if dwrq->flags != 0, we should get the relevant SSID from
2019 * the SSID list...
2020 */
2021
2022 /*
2023 * Get the current SSID
2024 */
David Woodhouseaa21c002007-12-08 20:04:36 +00002025 if (priv->connect_status == LBS_CONNECTED) {
2026 memcpy(extra, priv->curbssparams.ssid,
2027 priv->curbssparams.ssid_len);
2028 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002029 } else {
2030 memset(extra, 0, 32);
David Woodhouseaa21c002007-12-08 20:04:36 +00002031 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002032 }
2033 /*
2034 * If none, we may want to get the one that was set
2035 */
2036
David Woodhouseaa21c002007-12-08 20:04:36 +00002037 dwrq->length = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002038
2039 dwrq->flags = 1; /* active */
2040
Holger Schurig9012b282007-05-25 11:27:16 -04002041 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002042 return 0;
2043}
2044
Holger Schurig10078322007-11-15 18:05:47 -05002045static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002046 struct iw_point *dwrq, char *extra)
2047{
Kiran Divekarab65f642009-02-19 19:32:39 -05002048 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002049 int ret = 0;
Holger Schurig243e84e2009-10-22 15:30:47 +02002050 u8 ssid[IEEE80211_MAX_SSID_LEN];
Dan Williamsd8efea22007-05-28 23:54:55 -04002051 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002052 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04002053 int in_ssid_len = dwrq->length;
John W. Linville9387b7c2008-09-30 20:59:05 -04002054 DECLARE_SSID_BUF(ssid_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002055
Holger Schurig9012b282007-05-25 11:27:16 -04002056 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002057
Dan Williamsd5db2df2008-08-21 17:51:07 -04002058 if (!priv->radio_on) {
2059 ret = -EINVAL;
2060 goto out;
2061 }
2062
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002063 /* Check the size of the string */
Holger Schurig243e84e2009-10-22 15:30:47 +02002064 if (in_ssid_len > IEEE80211_MAX_SSID_LEN) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002065 ret = -E2BIG;
2066 goto out;
2067 }
2068
Dan Williamsd8efea22007-05-28 23:54:55 -04002069 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002070
Dan Williamsd8efea22007-05-28 23:54:55 -04002071 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002072 /* "any" SSID requested; leave SSID blank */
2073 } else {
2074 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04002075 memcpy(&ssid, extra, in_ssid_len);
2076 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002077 }
2078
Dan Williamsd8efea22007-05-28 23:54:55 -04002079 if (!ssid_len) {
2080 lbs_deb_wext("requested any SSID\n");
2081 } else {
2082 lbs_deb_wext("requested SSID '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04002083 print_ssid(ssid_buf, ssid, ssid_len));
Dan Williamsd8efea22007-05-28 23:54:55 -04002084 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002085
2086out:
David Woodhouseaa21c002007-12-08 20:04:36 +00002087 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002088 if (ret == 0) {
2089 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002090 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002091 if (!assoc_req) {
2092 ret = -ENOMEM;
2093 } else {
2094 /* Copy the SSID to the association request */
Holger Schurig243e84e2009-10-22 15:30:47 +02002095 memcpy(&assoc_req->ssid, &ssid, IEEE80211_MAX_SSID_LEN);
Dan Williamsd8efea22007-05-28 23:54:55 -04002096 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002097 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002098 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002099 }
2100 }
2101
2102 /* Cancel the association request if there was an error */
2103 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05002104 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002105 }
2106
David Woodhouseaa21c002007-12-08 20:04:36 +00002107 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002108
Holger Schurig9012b282007-05-25 11:27:16 -04002109 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002110 return ret;
2111}
2112
David Woodhousef5956bf2007-12-11 19:30:57 -05002113static int lbs_mesh_get_essid(struct net_device *dev,
2114 struct iw_request_info *info,
2115 struct iw_point *dwrq, char *extra)
2116{
Kiran Divekarab65f642009-02-19 19:32:39 -05002117 struct lbs_private *priv = dev->ml_priv;
David Woodhousef5956bf2007-12-11 19:30:57 -05002118
2119 lbs_deb_enter(LBS_DEB_WEXT);
2120
2121 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2122
2123 dwrq->length = priv->mesh_ssid_len;
2124
2125 dwrq->flags = 1; /* active */
2126
2127 lbs_deb_leave(LBS_DEB_WEXT);
2128 return 0;
2129}
2130
2131static int lbs_mesh_set_essid(struct net_device *dev,
2132 struct iw_request_info *info,
2133 struct iw_point *dwrq, char *extra)
2134{
Kiran Divekarab65f642009-02-19 19:32:39 -05002135 struct lbs_private *priv = dev->ml_priv;
David Woodhousef5956bf2007-12-11 19:30:57 -05002136 int ret = 0;
2137
2138 lbs_deb_enter(LBS_DEB_WEXT);
2139
Dan Williamsd5db2df2008-08-21 17:51:07 -04002140 if (!priv->radio_on) {
2141 ret = -EINVAL;
2142 goto out;
2143 }
2144
David Woodhousef5956bf2007-12-11 19:30:57 -05002145 /* Check the size of the string */
Holger Schurig243e84e2009-10-22 15:30:47 +02002146 if (dwrq->length > IEEE80211_MAX_SSID_LEN) {
David Woodhousef5956bf2007-12-11 19:30:57 -05002147 ret = -E2BIG;
2148 goto out;
2149 }
2150
2151 if (!dwrq->flags || !dwrq->length) {
2152 ret = -EINVAL;
2153 goto out;
2154 } else {
2155 /* Specific SSID requested */
2156 memcpy(priv->mesh_ssid, extra, dwrq->length);
2157 priv->mesh_ssid_len = dwrq->length;
2158 }
2159
Javier Cardonaedaea5c2008-05-17 00:55:10 -07002160 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
Holger Schurigc14951f2009-10-22 15:30:50 +02002161 priv->channel);
David Woodhousef5956bf2007-12-11 19:30:57 -05002162 out:
2163 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2164 return ret;
2165}
2166
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002167/**
2168 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2169 *
2170 * @param dev A pointer to net_device structure
2171 * @param info A pointer to iw_request_info structure
2172 * @param awrq A pointer to iw_param structure
2173 * @param extra A pointer to extra data buf
2174 * @return 0 --success, otherwise fail
2175 */
Holger Schurig10078322007-11-15 18:05:47 -05002176static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002177 struct sockaddr *awrq, char *extra)
2178{
Kiran Divekarab65f642009-02-19 19:32:39 -05002179 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002180 struct assoc_request * assoc_req;
2181 int ret = 0;
2182
Holger Schurig9012b282007-05-25 11:27:16 -04002183 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002184
Dan Williamsd5db2df2008-08-21 17:51:07 -04002185 if (!priv->radio_on)
2186 return -EINVAL;
2187
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002188 if (awrq->sa_family != ARPHRD_ETHER)
2189 return -EINVAL;
2190
Johannes Berge1749612008-10-27 15:59:26 -07002191 lbs_deb_wext("ASSOC: WAP: sa_data %pM\n", awrq->sa_data);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002192
David Woodhouseaa21c002007-12-08 20:04:36 +00002193 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002194
2195 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002196 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002197 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05002198 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002199 ret = -ENOMEM;
2200 } else {
2201 /* Copy the BSSID to the association request */
2202 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2203 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002204 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002205 }
2206
David Woodhouseaa21c002007-12-08 20:04:36 +00002207 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002208
2209 return ret;
2210}
2211
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002212/*
2213 * iwconfig settable callbacks
2214 */
Holger Schurig10078322007-11-15 18:05:47 -05002215static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002216 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002217 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002218 (iw_handler) NULL, /* SIOCSIWNWID */
2219 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002220 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2221 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2222 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2223 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002224 (iw_handler) NULL, /* SIOCSIWSENS */
2225 (iw_handler) NULL, /* SIOCGIWSENS */
2226 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002227 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002228 (iw_handler) NULL, /* SIOCSIWPRIV */
2229 (iw_handler) NULL, /* SIOCGIWPRIV */
2230 (iw_handler) NULL, /* SIOCSIWSTATS */
2231 (iw_handler) NULL, /* SIOCGIWSTATS */
2232 iw_handler_set_spy, /* SIOCSIWSPY */
2233 iw_handler_get_spy, /* SIOCGIWSPY */
2234 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2235 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002236 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2237 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002238 (iw_handler) NULL, /* SIOCSIWMLME */
2239 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002240 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2241 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2242 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2243 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2244 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2245 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002246 (iw_handler) NULL, /* -- hole -- */
2247 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002248 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2249 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2250 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2251 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2252 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2253 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2254 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2255 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2256 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2257 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2258 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2259 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2260 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2261 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002262 (iw_handler) NULL, /* -- hole -- */
2263 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002264 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2265 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2266 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2267 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2268 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2269 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002270 (iw_handler) NULL, /* SIOCSIWPMKSA */
2271};
2272
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002273static const iw_handler mesh_wlan_handler[] = {
2274 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002275 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002276 (iw_handler) NULL, /* SIOCSIWNWID */
2277 (iw_handler) NULL, /* SIOCGIWNWID */
David Woodhouse823eaa22007-12-11 19:56:28 -05002278 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
Holger Schurig10078322007-11-15 18:05:47 -05002279 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002280 (iw_handler) NULL, /* SIOCSIWMODE */
2281 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2282 (iw_handler) NULL, /* SIOCSIWSENS */
2283 (iw_handler) NULL, /* SIOCGIWSENS */
2284 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002285 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002286 (iw_handler) NULL, /* SIOCSIWPRIV */
2287 (iw_handler) NULL, /* SIOCGIWPRIV */
2288 (iw_handler) NULL, /* SIOCSIWSTATS */
2289 (iw_handler) NULL, /* SIOCGIWSTATS */
2290 iw_handler_set_spy, /* SIOCSIWSPY */
2291 iw_handler_get_spy, /* SIOCGIWSPY */
2292 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2293 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2294 (iw_handler) NULL, /* SIOCSIWAP */
2295 (iw_handler) NULL, /* SIOCGIWAP */
2296 (iw_handler) NULL, /* SIOCSIWMLME */
2297 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002298 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2299 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
David Woodhousef5956bf2007-12-11 19:30:57 -05002300 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2301 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002302 (iw_handler) NULL, /* SIOCSIWNICKN */
2303 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2304 (iw_handler) NULL, /* -- hole -- */
2305 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002306 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2307 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2308 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2309 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2310 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2311 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2312 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2313 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2314 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2315 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2316 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2317 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2318 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2319 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002320 (iw_handler) NULL, /* -- hole -- */
2321 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002322 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2323 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2324 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2325 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2326 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2327 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002328 (iw_handler) NULL, /* SIOCSIWPMKSA */
2329};
Holger Schurig10078322007-11-15 18:05:47 -05002330struct iw_handler_def lbs_handler_def = {
2331 .num_standard = ARRAY_SIZE(lbs_handler),
2332 .standard = (iw_handler *) lbs_handler,
2333 .get_wireless_stats = lbs_get_wireless_stats,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002334};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002335
2336struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002337 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002338 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002339 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002340};