blob: aad6263dee6d59057da5f2cac4e1bb98f5a8946b [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 Cardona9c31fd62008-09-11 15:32:50 -070033static inline void lbs_do_association_work(struct lbs_private *priv)
34{
35 if (priv->surpriseremoved)
36 return;
37 cancel_delayed_work(&priv->assoc_work);
38 queue_delayed_work(priv->work_thread, &priv->assoc_work, 0);
39}
40
Holger Schurig69f90322007-11-23 15:43:44 +010041static inline void lbs_cancel_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020042{
43 cancel_delayed_work(&priv->assoc_work);
David Woodhouseaa21c002007-12-08 20:04:36 +000044 kfree(priv->pending_assoc_req);
45 priv->pending_assoc_req = NULL;
Holger Schurig9f9dac22007-10-26 10:12:14 +020046}
47
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) &&
Holger Schurig602114a2009-12-02 15:26:01 +0100195 !lbs_mesh_connected(priv))
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
Holger Schurig4143a232009-12-02 15:26:02 +0100301#ifdef CONFIG_LIBERTAS_MESH
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400302static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
303 struct iw_point *dwrq, char *extra)
304{
Kiran Divekarab65f642009-02-19 19:32:39 -0500305 struct lbs_private *priv = dev->ml_priv;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400306
307 lbs_deb_enter(LBS_DEB_WEXT);
308
309 /* Use nickname to indicate that mesh is on */
310
Holger Schurig602114a2009-12-02 15:26:01 +0100311 if (lbs_mesh_connected(priv)) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400312 strncpy(extra, "Mesh", 12);
313 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400314 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400315 }
316
317 else {
318 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400319 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400320 }
321
322 lbs_deb_leave(LBS_DEB_WEXT);
323 return 0;
324}
Holger Schurig4143a232009-12-02 15:26:02 +0100325#endif
Holger Schurig04799fa2007-10-09 15:04:14 +0200326
Holger Schurig10078322007-11-15 18:05:47 -0500327static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200328 struct iw_param *vwrq, char *extra)
329{
330 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -0500331 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400332 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333
Holger Schurig9012b282007-05-25 11:27:16 -0400334 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200335
Dan Williams39fcf7a2008-09-10 12:49:00 -0400336 if (vwrq->disabled)
337 val = MRVDRV_RTS_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338
John W. Linville375da532008-09-15 17:25:54 -0400339 if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400340 return -EINVAL;
341
342 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343
Holger Schurig9012b282007-05-25 11:27:16 -0400344 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200345 return ret;
346}
347
Holger Schurig10078322007-11-15 18:05:47 -0500348static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349 struct iw_param *vwrq, char *extra)
350{
Kiran Divekarab65f642009-02-19 19:32:39 -0500351 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400352 int ret = 0;
353 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354
Holger Schurig9012b282007-05-25 11:27:16 -0400355 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200356
Dan Williams39fcf7a2008-09-10 12:49:00 -0400357 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400358 if (ret)
359 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360
Dan Williams39fcf7a2008-09-10 12:49:00 -0400361 vwrq->value = val;
John W. Linville375da532008-09-15 17:25:54 -0400362 vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200363 vwrq->fixed = 1;
364
Holger Schurig9012b282007-05-25 11:27:16 -0400365out:
366 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
367 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200368}
369
Holger Schurig10078322007-11-15 18:05:47 -0500370static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371 struct iw_param *vwrq, char *extra)
372{
Kiran Divekarab65f642009-02-19 19:32:39 -0500373 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400374 int ret = 0;
375 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376
Holger Schurig9012b282007-05-25 11:27:16 -0400377 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378
Dan Williams39fcf7a2008-09-10 12:49:00 -0400379 if (vwrq->disabled)
380 val = MRVDRV_FRAG_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200381
Dan Williams39fcf7a2008-09-10 12:49:00 -0400382 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
383 return -EINVAL;
384
385 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
Holger Schurig9012b282007-05-25 11:27:16 -0400386
387 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388 return ret;
389}
390
Holger Schurig10078322007-11-15 18:05:47 -0500391static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392 struct iw_param *vwrq, char *extra)
393{
Kiran Divekarab65f642009-02-19 19:32:39 -0500394 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400395 int ret = 0;
396 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397
Holger Schurig9012b282007-05-25 11:27:16 -0400398 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200399
Dan Williams39fcf7a2008-09-10 12:49:00 -0400400 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400401 if (ret)
402 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200403
Dan Williams39fcf7a2008-09-10 12:49:00 -0400404 vwrq->value = val;
405 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
406 || (val > MRVDRV_FRAG_MAX_VALUE));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200407 vwrq->fixed = 1;
408
Holger Schurig9012b282007-05-25 11:27:16 -0400409out:
410 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200411 return ret;
412}
413
Holger Schurig10078322007-11-15 18:05:47 -0500414static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200415 struct iw_request_info *info, u32 * uwrq, char *extra)
416{
Kiran Divekarab65f642009-02-19 19:32:39 -0500417 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200418
Holger Schurig9012b282007-05-25 11:27:16 -0400419 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200420
David Woodhouseaa21c002007-12-08 20:04:36 +0000421 *uwrq = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200422
Holger Schurig9012b282007-05-25 11:27:16 -0400423 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200424 return 0;
425}
426
Holger Schurig4143a232009-12-02 15:26:02 +0100427#ifdef CONFIG_LIBERTAS_MESH
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400428static int mesh_wlan_get_mode(struct net_device *dev,
429 struct iw_request_info *info, u32 * uwrq,
430 char *extra)
431{
432 lbs_deb_enter(LBS_DEB_WEXT);
433
Dan Williams39fcf7a2008-09-10 12:49:00 -0400434 *uwrq = IW_MODE_REPEAT;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400435
436 lbs_deb_leave(LBS_DEB_WEXT);
437 return 0;
438}
Holger Schurig4143a232009-12-02 15:26:02 +0100439#endif
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400440
Holger Schurig10078322007-11-15 18:05:47 -0500441static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200442 struct iw_request_info *info,
443 struct iw_param *vwrq, char *extra)
444{
Kiran Divekarab65f642009-02-19 19:32:39 -0500445 struct lbs_private *priv = dev->ml_priv;
Dan Williams87c8c722008-08-19 15:15:35 -0400446 s16 curlevel = 0;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400447 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200448
Holger Schurig9012b282007-05-25 11:27:16 -0400449 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200450
Dan Williamsd5db2df2008-08-21 17:51:07 -0400451 if (!priv->radio_on) {
452 lbs_deb_wext("tx power off\n");
453 vwrq->value = 0;
454 vwrq->disabled = 1;
455 goto out;
456 }
457
Dan Williams87c8c722008-08-19 15:15:35 -0400458 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400459 if (ret)
460 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200461
Dan Williams87c8c722008-08-19 15:15:35 -0400462 lbs_deb_wext("tx power level %d dbm\n", curlevel);
Dan Williams87c8c722008-08-19 15:15:35 -0400463 priv->txpower_cur = curlevel;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400464
Dan Williams87c8c722008-08-19 15:15:35 -0400465 vwrq->value = curlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200466 vwrq->fixed = 1;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400467 vwrq->disabled = 0;
468 vwrq->flags = IW_TXPOW_DBM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469
Holger Schurig9012b282007-05-25 11:27:16 -0400470out:
471 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
472 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200473}
474
Holger Schurig10078322007-11-15 18:05:47 -0500475static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 struct iw_param *vwrq, char *extra)
477{
Kiran Divekarab65f642009-02-19 19:32:39 -0500478 struct lbs_private *priv = dev->ml_priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400479 int ret = 0;
480 u16 slimit = 0, llimit = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481
Holger Schurig9012b282007-05-25 11:27:16 -0400482 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483
Dan Williams39fcf7a2008-09-10 12:49:00 -0400484 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
485 return -EOPNOTSUPP;
486
487 /* The MAC has a 4-bit Total_Tx_Count register
488 Total_Tx_Count = 1 + Tx_Retry_Count */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200489#define TX_RETRY_MIN 0
490#define TX_RETRY_MAX 14
Dan Williams39fcf7a2008-09-10 12:49:00 -0400491 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
492 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200493
Dan Williams39fcf7a2008-09-10 12:49:00 -0400494 /* Add 1 to convert retry count to try count */
495 if (vwrq->flags & IW_RETRY_SHORT)
496 slimit = (u16) (vwrq->value + 1);
497 else if (vwrq->flags & IW_RETRY_LONG)
498 llimit = (u16) (vwrq->value + 1);
499 else
500 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501
Dan Williams39fcf7a2008-09-10 12:49:00 -0400502 if (llimit) {
503 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
504 llimit);
Holger Schurig9012b282007-05-25 11:27:16 -0400505 if (ret)
506 goto out;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400507 }
508
509 if (slimit) {
510 /* txretrycount follows the short retry limit */
511 priv->txretrycount = slimit;
512 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
513 slimit);
514 if (ret)
515 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200516 }
517
Holger Schurig9012b282007-05-25 11:27:16 -0400518out:
519 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
520 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200521}
522
Holger Schurig10078322007-11-15 18:05:47 -0500523static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200524 struct iw_param *vwrq, char *extra)
525{
Kiran Divekarab65f642009-02-19 19:32:39 -0500526 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200527 int ret = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400528 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529
Holger Schurig9012b282007-05-25 11:27:16 -0400530 lbs_deb_enter(LBS_DEB_WEXT);
531
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200532 vwrq->disabled = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400533
534 if (vwrq->flags & IW_RETRY_LONG) {
535 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
536 if (ret)
537 goto out;
538
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200539 /* Subtract 1 to convert try count to retry count */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400540 vwrq->value = val - 1;
541 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
542 } else {
543 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
544 if (ret)
545 goto out;
546
547 /* txretry count follows the short retry limit */
548 priv->txretrycount = val;
549 /* Subtract 1 to convert try count to retry count */
550 vwrq->value = val - 1;
551 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200552 }
553
Holger Schurig9012b282007-05-25 11:27:16 -0400554out:
555 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
556 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200557}
558
559static inline void sort_channels(struct iw_freq *freq, int num)
560{
561 int i, j;
562 struct iw_freq temp;
563
564 for (i = 0; i < num; i++)
565 for (j = i + 1; j < num; j++)
566 if (freq[i].i > freq[j].i) {
567 temp.i = freq[i].i;
568 temp.m = freq[i].m;
569
570 freq[i].i = freq[j].i;
571 freq[i].m = freq[j].m;
572
573 freq[j].i = temp.i;
574 freq[j].m = temp.m;
575 }
576}
577
578/* data rate listing
579 MULTI_BANDS:
580 abg a b b/g
581 Infra G(12) A(8) B(4) G(12)
582 Adhoc A+B(12) A(8) B(4) B(4)
583
584 non-MULTI_BANDS:
585 b b/g
586 Infra B(4) G(12)
587 Adhoc B(4) B(4)
588 */
589/**
590 * @brief Get Range Info
591 *
592 * @param dev A pointer to net_device structure
593 * @param info A pointer to iw_request_info structure
594 * @param vwrq A pointer to iw_param structure
595 * @param extra A pointer to extra data buf
596 * @return 0 --success, otherwise fail
597 */
Holger Schurig10078322007-11-15 18:05:47 -0500598static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599 struct iw_point *dwrq, char *extra)
600{
601 int i, j;
Kiran Divekarab65f642009-02-19 19:32:39 -0500602 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603 struct iw_range *range = (struct iw_range *)extra;
604 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400605 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200606
Holger Schurig9012b282007-05-25 11:27:16 -0400607 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608
609 dwrq->length = sizeof(struct iw_range);
610 memset(range, 0, sizeof(struct iw_range));
611
612 range->min_nwid = 0;
613 range->max_nwid = 0;
614
615 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000616 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400617 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
618 for (i = 0; i < range->num_bitrates; i++)
619 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200620 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400621 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200622 range->num_bitrates);
623
624 range->num_frequency = 0;
Holger Schurig52933d82008-03-05 07:05:32 +0100625
626 range->scan_capa = IW_SCAN_CAPA_ESSID;
627
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200628 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
629 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
630 cfp = priv->region_channel[j].CFP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200632 && priv->region_channel[j].valid
633 && cfp
634 && (i < priv->region_channel[j].nrcfp); i++) {
635 range->freq[range->num_frequency].i =
636 (long)cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200637 range->freq[range->num_frequency].m =
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200638 (long)cfp->freq * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200639 range->freq[range->num_frequency].e = 1;
Holger Schurigd37b4fd2009-10-22 15:30:45 +0200640 cfp++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641 range->num_frequency++;
642 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200643 }
644
Holger Schurig9012b282007-05-25 11:27:16 -0400645 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200646 IW_MAX_FREQUENCIES, range->num_frequency);
647
648 range->num_channels = range->num_frequency;
649
650 sort_channels(&range->freq[0], range->num_frequency);
651
652 /*
653 * Set an indication of the max TCP throughput in bit/s that we can
654 * expect using this interface
655 */
656 if (i > 2)
657 range->throughput = 5000 * 1000;
658 else
659 range->throughput = 1500 * 1000;
660
661 range->min_rts = MRVDRV_RTS_MIN_VALUE;
662 range->max_rts = MRVDRV_RTS_MAX_VALUE;
663 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
664 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
665
666 range->encoding_size[0] = 5;
667 range->encoding_size[1] = 13;
668 range->num_encoding_sizes = 2;
669 range->max_encoding_tokens = 4;
670
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100671 /*
672 * Right now we support only "iwconfig ethX power on|off"
673 */
674 range->pm_capa = IW_POWER_ON;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200675
676 /*
677 * Minimum version we recommend
678 */
679 range->we_version_source = 15;
680
681 /*
682 * Version we are compiled with
683 */
684 range->we_version_compiled = WIRELESS_EXT;
685
686 range->retry_capa = IW_RETRY_LIMIT;
687 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
688
689 range->min_retry = TX_RETRY_MIN;
690 range->max_retry = TX_RETRY_MAX;
691
692 /*
693 * Set the qual, level and noise range values
694 */
695 range->max_qual.qual = 100;
696 range->max_qual.level = 0;
697 range->max_qual.noise = 0;
698 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
699
700 range->avg_qual.qual = 70;
701 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
702 range->avg_qual.level = 0;
703 range->avg_qual.noise = 0;
704 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
705
706 range->sensitivity = 0;
707
Dan Williams87c8c722008-08-19 15:15:35 -0400708 /* Setup the supported power level ranges */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709 memset(range->txpower, 0, sizeof(range->txpower));
Dan Williams87c8c722008-08-19 15:15:35 -0400710 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
711 range->txpower[0] = priv->txpower_min;
712 range->txpower[1] = priv->txpower_max;
713 range->num_txpower = 2;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200714
715 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
716 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
717 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
718 range->event_capa[1] = IW_EVENT_CAPA_K_1;
719
David Woodhouseaa21c002007-12-08 20:04:36 +0000720 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200721 range->enc_capa = IW_ENC_CAPA_WPA
722 | IW_ENC_CAPA_WPA2
723 | IW_ENC_CAPA_CIPHER_TKIP
724 | IW_ENC_CAPA_CIPHER_CCMP;
725 }
726
Holger Schurig9012b282007-05-25 11:27:16 -0400727 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200728 return 0;
729}
730
Holger Schurig10078322007-11-15 18:05:47 -0500731static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200732 struct iw_param *vwrq, char *extra)
733{
Kiran Divekarab65f642009-02-19 19:32:39 -0500734 struct lbs_private *priv = dev->ml_priv;
Amitkumar Karwar49125452009-09-30 20:04:38 -0700735 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200736
Holger Schurig9012b282007-05-25 11:27:16 -0400737 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200738
Andrey Yurovskye0d61332009-06-16 13:20:01 -0700739 if (!(priv->fwcapinfo & FW_CAPINFO_PS)) {
David Woodhouseb2c57ee2007-12-17 14:41:13 -0500740 if (vwrq->disabled)
741 return 0;
742 else
743 return -EINVAL;
744 }
745
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200746 /* PS is currently supported only in Infrastructure mode
747 * Remove this check if it is to be supported in IBSS mode also
748 */
749
750 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000751 priv->psmode = LBS802_11POWERMODECAM;
752 if (priv->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500753 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200754 }
755
756 return 0;
757 }
758
759 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400760 lbs_deb_wext(
761 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762 return -EINVAL;
763 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Amitkumar Karwar49125452009-09-30 20:04:38 -0700764 vwrq->value = vwrq->value / 1000;
765 if (!priv->enter_deep_sleep) {
766 lbs_pr_err("deep sleep feature is not implemented "
767 "for this interface driver\n");
768 return -EINVAL;
769 }
770
771 if (priv->connect_status == LBS_CONNECTED) {
772 if ((priv->is_auto_deep_sleep_enabled) &&
773 (vwrq->value == -1000)) {
774 lbs_exit_auto_deep_sleep(priv);
775 return 0;
776 } else {
777 lbs_pr_err("can't use deep sleep cmd in "
778 "connected state\n");
779 return -EINVAL;
780 }
781 }
782
783 if ((vwrq->value < 0) && (vwrq->value != -1000)) {
784 lbs_pr_err("unknown option\n");
785 return -EINVAL;
786 }
787
788 if (vwrq->value > 0) {
789 if (!priv->is_auto_deep_sleep_enabled) {
790 priv->is_activity_detected = 0;
791 priv->auto_deep_sleep_timeout = vwrq->value;
792 lbs_enter_auto_deep_sleep(priv);
793 } else {
794 priv->auto_deep_sleep_timeout = vwrq->value;
795 lbs_deb_debugfs("auto deep sleep: "
796 "already enabled\n");
797 }
798 return 0;
799 } else {
800 if (priv->is_auto_deep_sleep_enabled) {
801 lbs_exit_auto_deep_sleep(priv);
802 /* Try to exit deep sleep if auto */
803 /*deep sleep disabled */
804 ret = lbs_set_deep_sleep(priv, 0);
805 }
806 if (vwrq->value == 0)
807 ret = lbs_set_deep_sleep(priv, 1);
808 else if (vwrq->value == -1000)
809 ret = lbs_set_deep_sleep(priv, 0);
810 return ret;
811 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200812 }
813
David Woodhouseaa21c002007-12-08 20:04:36 +0000814 if (priv->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200815 return 0;
816 }
817
David Woodhouseaa21c002007-12-08 20:04:36 +0000818 priv->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200819
David Woodhouseaa21c002007-12-08 20:04:36 +0000820 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500821 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200822 }
823
Holger Schurig9012b282007-05-25 11:27:16 -0400824 lbs_deb_leave(LBS_DEB_WEXT);
Amitkumar Karwar49125452009-09-30 20:04:38 -0700825
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200826 return 0;
827}
828
Holger Schurig10078322007-11-15 18:05:47 -0500829static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200830 struct iw_param *vwrq, char *extra)
831{
Kiran Divekarab65f642009-02-19 19:32:39 -0500832 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200833
Holger Schurig9012b282007-05-25 11:27:16 -0400834 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200835
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200836 vwrq->value = 0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100837 vwrq->flags = 0;
838 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
839 || priv->connect_status == LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200840
Holger Schurig9012b282007-05-25 11:27:16 -0400841 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200842 return 0;
843}
844
Holger Schurig10078322007-11-15 18:05:47 -0500845static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200846{
847 enum {
848 POOR = 30,
849 FAIR = 60,
850 GOOD = 80,
851 VERY_GOOD = 90,
852 EXCELLENT = 95,
853 PERFECT = 100
854 };
Kiran Divekarab65f642009-02-19 19:32:39 -0500855 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856 u32 rssi_qual;
857 u32 tx_qual;
858 u32 quality = 0;
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700859 int ret, stats_valid = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200860 u8 rssi;
861 u32 tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100862 struct cmd_ds_802_11_get_log log;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200863
Holger Schurig9012b282007-05-25 11:27:16 -0400864 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200865
David Woodhouseaa21c002007-12-08 20:04:36 +0000866 priv->wstats.status = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200867
868 /* If we're not associated, all quality values are meaningless */
David Woodhouseaa21c002007-12-08 20:04:36 +0000869 if ((priv->connect_status != LBS_CONNECTED) &&
Holger Schurig602114a2009-12-02 15:26:01 +0100870 !lbs_mesh_connected(priv))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200871 goto out;
872
873 /* Quality by RSSI */
874 priv->wstats.qual.level =
David Woodhouseaa21c002007-12-08 20:04:36 +0000875 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
876 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200877
David Woodhouseaa21c002007-12-08 20:04:36 +0000878 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200879 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
880 } else {
881 priv->wstats.qual.noise =
David Woodhouseaa21c002007-12-08 20:04:36 +0000882 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200883 }
884
Holger Schurig9012b282007-05-25 11:27:16 -0400885 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
886 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200887
888 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
889 if (rssi < 15)
890 rssi_qual = rssi * POOR / 10;
891 else if (rssi < 20)
892 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
893 else if (rssi < 30)
894 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
895 else if (rssi < 40)
896 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
897 10 + GOOD;
898 else
899 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
900 10 + VERY_GOOD;
901 quality = rssi_qual;
902
903 /* Quality by TX errors */
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000904 priv->wstats.discard.retries = dev->stats.tx_errors;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905
Holger Schurigc49c3b72008-03-17 12:45:58 +0100906 memset(&log, 0, sizeof(log));
907 log.hdr.size = cpu_to_le16(sizeof(log));
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700908 ret = lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
909 if (ret)
910 goto out;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100911
912 tx_retries = le32_to_cpu(log.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200913
914 if (tx_retries > 75)
915 tx_qual = (90 - tx_retries) * POOR / 15;
916 else if (tx_retries > 70)
917 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
918 else if (tx_retries > 65)
919 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
920 else if (tx_retries > 50)
921 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
922 15 + GOOD;
923 else
924 tx_qual = (50 - tx_retries) *
925 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
926 quality = min(quality, tx_qual);
927
Holger Schurigc49c3b72008-03-17 12:45:58 +0100928 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200929 priv->wstats.discard.retries = tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100930 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200931
932 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400933 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200934 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
935 stats_valid = 1;
936
937 /* update stats asynchronously for future calls */
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700938 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200939 0, 0, NULL);
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700940 if (ret)
941 lbs_pr_err("RSSI command failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200942out:
943 if (!stats_valid) {
944 priv->wstats.miss.beacon = 0;
945 priv->wstats.discard.retries = 0;
946 priv->wstats.qual.qual = 0;
947 priv->wstats.qual.level = 0;
948 priv->wstats.qual.noise = 0;
949 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
950 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
951 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
952 }
953
Holger Schurig9012b282007-05-25 11:27:16 -0400954 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200955 return &priv->wstats;
956
957
958}
959
Holger Schurig10078322007-11-15 18:05:47 -0500960static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200961 struct iw_freq *fwrq, char *extra)
962{
Dan Williamsef9a2642007-05-25 16:46:33 -0400963 int ret = -EINVAL;
Kiran Divekarab65f642009-02-19 19:32:39 -0500964 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200965 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400966 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200967
Holger Schurig9012b282007-05-25 11:27:16 -0400968 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200969
David Woodhouseaa21c002007-12-08 20:04:36 +0000970 mutex_lock(&priv->lock);
971 assoc_req = lbs_get_association_request(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400972 if (!assoc_req) {
973 ret = -ENOMEM;
974 goto out;
975 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200976
Dan Williamsef9a2642007-05-25 16:46:33 -0400977 /* If setting by frequency, convert to a channel */
978 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200979 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200980
David Woodhouseaa21c002007-12-08 20:04:36 +0000981 cfp = find_cfp_by_band_and_freq(priv, 0, f);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200982 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400983 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400984 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200985 }
986
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200987 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400988 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200989 }
990
Dan Williamsef9a2642007-05-25 16:46:33 -0400991 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200992 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400993 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200994 }
995
David Woodhouseaa21c002007-12-08 20:04:36 +0000996 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400997 if (!cfp) {
998 goto out;
999 }
1000
1001 assoc_req->channel = fwrq->m;
1002 ret = 0;
1003
Holger Schurig9012b282007-05-25 11:27:16 -04001004out:
Dan Williamsef9a2642007-05-25 16:46:33 -04001005 if (ret == 0) {
1006 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001007 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -04001008 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001009 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -04001010 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001011 mutex_unlock(&priv->lock);
Dan Williamsef9a2642007-05-25 16:46:33 -04001012
1013 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1014 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001015}
1016
Holger Schurig4143a232009-12-02 15:26:02 +01001017#ifdef CONFIG_LIBERTAS_MESH
David Woodhouse823eaa22007-12-11 19:56:28 -05001018static int lbs_mesh_set_freq(struct net_device *dev,
1019 struct iw_request_info *info,
1020 struct iw_freq *fwrq, char *extra)
1021{
Kiran Divekarab65f642009-02-19 19:32:39 -05001022 struct lbs_private *priv = dev->ml_priv;
David Woodhouse823eaa22007-12-11 19:56:28 -05001023 struct chan_freq_power *cfp;
1024 int ret = -EINVAL;
1025
1026 lbs_deb_enter(LBS_DEB_WEXT);
1027
1028 /* If setting by frequency, convert to a channel */
1029 if (fwrq->e == 1) {
1030 long f = fwrq->m / 100000;
1031
1032 cfp = find_cfp_by_band_and_freq(priv, 0, f);
1033 if (!cfp) {
1034 lbs_deb_wext("invalid freq %ld\n", f);
1035 goto out;
1036 }
1037
1038 fwrq->e = 0;
1039 fwrq->m = (int) cfp->channel;
1040 }
1041
1042 /* Setting by channel number */
1043 if (fwrq->m > 1000 || fwrq->e > 0) {
1044 goto out;
1045 }
1046
1047 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
1048 if (!cfp) {
1049 goto out;
1050 }
1051
Holger Schurigc14951f2009-10-22 15:30:50 +02001052 if (fwrq->m != priv->channel) {
David Woodhouse823eaa22007-12-11 19:56:28 -05001053 lbs_deb_wext("mesh channel change forces eth disconnect\n");
1054 if (priv->mode == IW_MODE_INFRA)
Dan Williams191bb402008-08-21 17:46:18 -04001055 lbs_cmd_80211_deauthenticate(priv,
1056 priv->curbssparams.bssid,
1057 WLAN_REASON_DEAUTH_LEAVING);
David Woodhouse823eaa22007-12-11 19:56:28 -05001058 else if (priv->mode == IW_MODE_ADHOC)
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001059 lbs_adhoc_stop(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -05001060 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001061 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
David Woodhouse86062132007-12-13 00:32:36 -05001062 lbs_update_channel(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -05001063 ret = 0;
1064
1065out:
1066 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1067 return ret;
1068}
Holger Schurig4143a232009-12-02 15:26:02 +01001069#endif
David Woodhouse823eaa22007-12-11 19:56:28 -05001070
Holger Schurig10078322007-11-15 18:05:47 -05001071static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001072 struct iw_param *vwrq, char *extra)
1073{
Kiran Divekarab65f642009-02-19 19:32:39 -05001074 struct lbs_private *priv = dev->ml_priv;
Dan Williams8e3c91b2007-12-11 15:50:59 -05001075 u8 new_rate = 0;
Dan Williams8c512762007-08-02 11:40:45 -04001076 int ret = -EINVAL;
1077 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001078
Holger Schurig9012b282007-05-25 11:27:16 -04001079 lbs_deb_enter(LBS_DEB_WEXT);
Amitkumar Karwar49125452009-09-30 20:04:38 -07001080
Holger Schurig9012b282007-05-25 11:27:16 -04001081 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Javier Cardona85319f92008-05-24 10:59:49 +01001082 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1083
1084 if (vwrq->fixed && vwrq->value == -1)
1085 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001086
Dan Williams8c512762007-08-02 11:40:45 -04001087 /* Auto rate? */
Javier Cardona85319f92008-05-24 10:59:49 +01001088 priv->enablehwauto = !vwrq->fixed;
1089
1090 if (vwrq->value == -1)
David Woodhouseaa21c002007-12-08 20:04:36 +00001091 priv->cur_rate = 0;
Javier Cardona85319f92008-05-24 10:59:49 +01001092 else {
Dan Williams8c512762007-08-02 11:40:45 -04001093 if (vwrq->value % 100000)
1094 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001095
Javier Cardona85319f92008-05-24 10:59:49 +01001096 new_rate = vwrq->value / 500000;
1097 priv->cur_rate = new_rate;
1098 /* the rest is only needed for lbs_set_data_rate() */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001099 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +00001100 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -04001101 if (!memchr(rates, new_rate, sizeof(rates))) {
1102 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1103 new_rate);
1104 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001105 }
Anna Neal3ed6e082008-09-26 11:34:35 -04001106 if (priv->fwrelease < 0x09000000) {
1107 ret = lbs_set_power_adapt_cfg(priv, 0,
1108 POW_ADAPT_DEFAULT_P0,
1109 POW_ADAPT_DEFAULT_P1,
1110 POW_ADAPT_DEFAULT_P2);
1111 if (ret)
1112 goto out;
1113 }
1114 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1115 TPC_DEFAULT_P2, 1);
1116 if (ret)
1117 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001118 }
1119
Javier Cardona85319f92008-05-24 10:59:49 +01001120 /* Try the newer command first (Firmware Spec 5.1 and above) */
1121 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1122
1123 /* Fallback to older version */
1124 if (ret)
1125 ret = lbs_set_data_rate(priv, new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001126
Dan Williams8c512762007-08-02 11:40:45 -04001127out:
Holger Schurig9012b282007-05-25 11:27:16 -04001128 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001129 return ret;
1130}
1131
Holger Schurig10078322007-11-15 18:05:47 -05001132static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001133 struct iw_param *vwrq, char *extra)
1134{
Kiran Divekarab65f642009-02-19 19:32:39 -05001135 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001136
Holger Schurig9012b282007-05-25 11:27:16 -04001137 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001138
David Woodhouseaa21c002007-12-08 20:04:36 +00001139 if (priv->connect_status == LBS_CONNECTED) {
1140 vwrq->value = priv->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001141
Javier Cardona85319f92008-05-24 10:59:49 +01001142 if (priv->enablehwauto)
Dan Williams8c512762007-08-02 11:40:45 -04001143 vwrq->fixed = 0;
1144 else
1145 vwrq->fixed = 1;
1146
1147 } else {
1148 vwrq->fixed = 0;
1149 vwrq->value = 0;
1150 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001151
Holger Schurig9012b282007-05-25 11:27:16 -04001152 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001153 return 0;
1154}
1155
Holger Schurig10078322007-11-15 18:05:47 -05001156static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001157 struct iw_request_info *info, u32 * uwrq, char *extra)
1158{
1159 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001160 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001161 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001162
Holger Schurig9012b282007-05-25 11:27:16 -04001163 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001164
Dan Williams0dc5a292007-05-10 22:58:02 -04001165 if ( (*uwrq != IW_MODE_ADHOC)
1166 && (*uwrq != IW_MODE_INFRA)
1167 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001168 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001169 ret = -EINVAL;
1170 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001171 }
1172
David Woodhouseaa21c002007-12-08 20:04:36 +00001173 mutex_lock(&priv->lock);
1174 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001175 if (!assoc_req) {
1176 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001177 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001178 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001179 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001180 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001181 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001182 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001183 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001184 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001185
Dan Williams0dc5a292007-05-10 22:58:02 -04001186out:
Holger Schurig9012b282007-05-25 11:27:16 -04001187 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001188 return ret;
1189}
1190
1191
1192/**
1193 * @brief Get Encryption key
1194 *
1195 * @param dev A pointer to net_device structure
1196 * @param info A pointer to iw_request_info structure
1197 * @param vwrq A pointer to iw_param structure
1198 * @param extra A pointer to extra data buf
1199 * @return 0 --success, otherwise fail
1200 */
Holger Schurig10078322007-11-15 18:05:47 -05001201static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001202 struct iw_request_info *info,
1203 struct iw_point *dwrq, u8 * extra)
1204{
Kiran Divekarab65f642009-02-19 19:32:39 -05001205 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001206 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1207
Holger Schurig9012b282007-05-25 11:27:16 -04001208 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001209
Holger Schurig9012b282007-05-25 11:27:16 -04001210 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001211 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001212
1213 dwrq->flags = 0;
1214
1215 /* Authentication method */
David Woodhouseaa21c002007-12-08 20:04:36 +00001216 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -04001217 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001218 dwrq->flags = IW_ENCODE_OPEN;
1219 break;
1220
Dan Williams6affe782007-05-10 22:56:42 -04001221 case IW_AUTH_ALG_SHARED_KEY:
1222 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001223 dwrq->flags = IW_ENCODE_RESTRICTED;
1224 break;
1225 default:
1226 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1227 break;
1228 }
1229
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001230 memset(extra, 0, 16);
1231
David Woodhouseaa21c002007-12-08 20:04:36 +00001232 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001233
1234 /* Default to returning current transmit key */
1235 if (index < 0)
David Woodhouseaa21c002007-12-08 20:04:36 +00001236 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001237
David Woodhouseaa21c002007-12-08 20:04:36 +00001238 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1239 memcpy(extra, priv->wep_keys[index].key,
1240 priv->wep_keys[index].len);
1241 dwrq->length = priv->wep_keys[index].len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001242
1243 dwrq->flags |= (index + 1);
1244 /* Return WEP enabled */
1245 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhouseaa21c002007-12-08 20:04:36 +00001246 } else if ((priv->secinfo.WPAenabled)
1247 || (priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001248 /* return WPA enabled */
1249 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhousec12bdc42007-12-07 19:32:12 +00001250 dwrq->flags |= IW_ENCODE_NOKEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001251 } else {
1252 dwrq->flags |= IW_ENCODE_DISABLED;
1253 }
1254
David Woodhouseaa21c002007-12-08 20:04:36 +00001255 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001256
Joe Perches0795af52007-10-03 17:59:30 -07001257 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001258 extra[0], extra[1], extra[2],
1259 extra[3], extra[4], extra[5], dwrq->length);
1260
Holger Schurig9012b282007-05-25 11:27:16 -04001261 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001262
Holger Schurig9012b282007-05-25 11:27:16 -04001263 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001264 return 0;
1265}
1266
1267/**
1268 * @brief Set Encryption key (internal)
1269 *
1270 * @param priv A pointer to private card structure
1271 * @param key_material A pointer to key material
1272 * @param key_length length of key material
1273 * @param index key index to set
1274 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1275 * @return 0 --success, otherwise fail
1276 */
Holger Schurig10078322007-11-15 18:05:47 -05001277static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001278 const char *key_material,
1279 u16 key_length,
1280 u16 index,
1281 int set_tx_key)
1282{
Holger Schurig9012b282007-05-25 11:27:16 -04001283 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001284 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001285
Holger Schurig9012b282007-05-25 11:27:16 -04001286 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001287
1288 /* Paranoid validation of key index */
1289 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001290 ret = -EINVAL;
1291 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001292 }
1293
1294 /* validate max key length */
1295 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001296 ret = -EINVAL;
1297 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001298 }
1299
1300 pkey = &assoc_req->wep_keys[index];
1301
1302 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001303 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001304 pkey->type = KEY_TYPE_ID_WEP;
1305
1306 /* Standardize the key length */
1307 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1308 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1309 memcpy(pkey->key, key_material, key_length);
1310 }
1311
1312 if (set_tx_key) {
1313 /* Ensure the chosen key is valid */
1314 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001315 lbs_deb_wext("key not set, so cannot enable it\n");
1316 ret = -EINVAL;
1317 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001318 }
1319 assoc_req->wep_tx_keyidx = index;
1320 }
1321
Dan Williams889c05b2007-05-10 22:57:23 -04001322 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001323
Holger Schurig9012b282007-05-25 11:27:16 -04001324out:
1325 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1326 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001327}
1328
1329static int validate_key_index(u16 def_index, u16 raw_index,
1330 u16 *out_index, u16 *is_default)
1331{
1332 if (!out_index || !is_default)
1333 return -EINVAL;
1334
1335 /* Verify index if present, otherwise use default TX key index */
1336 if (raw_index > 0) {
1337 if (raw_index > 4)
1338 return -EINVAL;
1339 *out_index = raw_index - 1;
1340 } else {
1341 *out_index = def_index;
1342 *is_default = 1;
1343 }
1344 return 0;
1345}
1346
1347static void disable_wep(struct assoc_request *assoc_req)
1348{
1349 int i;
1350
Dan Williams90a42212007-05-25 23:01:24 -04001351 lbs_deb_enter(LBS_DEB_WEXT);
1352
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001353 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001354 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001355
1356 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001357 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001358 for (i = 0; i < 4; i++)
1359 assoc_req->wep_keys[i].len = 0;
1360
1361 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1362 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001363
1364 lbs_deb_leave(LBS_DEB_WEXT);
1365}
1366
1367static void disable_wpa(struct assoc_request *assoc_req)
1368{
1369 lbs_deb_enter(LBS_DEB_WEXT);
1370
Dan Williams1443b652007-08-02 10:45:55 -04001371 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001372 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1373 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1374
Dan Williams1443b652007-08-02 10:45:55 -04001375 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001376 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1377 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1378
1379 assoc_req->secinfo.WPAenabled = 0;
1380 assoc_req->secinfo.WPA2enabled = 0;
1381 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1382
1383 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001384}
1385
1386/**
1387 * @brief Set Encryption key
1388 *
1389 * @param dev A pointer to net_device structure
1390 * @param info A pointer to iw_request_info structure
1391 * @param vwrq A pointer to iw_param structure
1392 * @param extra A pointer to extra data buf
1393 * @return 0 --success, otherwise fail
1394 */
Holger Schurig10078322007-11-15 18:05:47 -05001395static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001396 struct iw_request_info *info,
1397 struct iw_point *dwrq, char *extra)
1398{
1399 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001400 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001401 struct assoc_request * assoc_req;
1402 u16 is_default = 0, index = 0, set_tx_key = 0;
1403
Holger Schurig9012b282007-05-25 11:27:16 -04001404 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001405
David Woodhouseaa21c002007-12-08 20:04:36 +00001406 mutex_lock(&priv->lock);
1407 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001408 if (!assoc_req) {
1409 ret = -ENOMEM;
1410 goto out;
1411 }
1412
1413 if (dwrq->flags & IW_ENCODE_DISABLED) {
1414 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001415 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001416 goto out;
1417 }
1418
1419 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1420 (dwrq->flags & IW_ENCODE_INDEX),
1421 &index, &is_default);
1422 if (ret) {
1423 ret = -EINVAL;
1424 goto out;
1425 }
1426
1427 /* If WEP isn't enabled, or if there is no key data but a valid
1428 * index, set the TX key.
1429 */
Dan Williams889c05b2007-05-10 22:57:23 -04001430 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001431 set_tx_key = 1;
1432
Holger Schurig10078322007-11-15 18:05:47 -05001433 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001434 if (ret)
1435 goto out;
1436
1437 if (dwrq->length)
1438 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1439 if (set_tx_key)
1440 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1441
1442 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Amitkumar Karwar921ca032010-02-25 17:16:36 -08001443 priv->authtype_auto = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001444 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001445 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Amitkumar Karwar921ca032010-02-25 17:16:36 -08001446 priv->authtype_auto = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001447 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001448 }
1449
1450out:
1451 if (ret == 0) {
1452 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001453 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001454 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001455 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001456 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001457 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001458
Holger Schurig9012b282007-05-25 11:27:16 -04001459 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001460 return ret;
1461}
1462
1463/**
1464 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1465 *
1466 * @param dev A pointer to net_device structure
1467 * @param info A pointer to iw_request_info structure
1468 * @param vwrq A pointer to iw_param structure
1469 * @param extra A pointer to extra data buf
1470 * @return 0 on success, otherwise failure
1471 */
Holger Schurig10078322007-11-15 18:05:47 -05001472static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001473 struct iw_request_info *info,
1474 struct iw_point *dwrq,
1475 char *extra)
1476{
1477 int ret = -EINVAL;
Kiran Divekarab65f642009-02-19 19:32:39 -05001478 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001479 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1480 int index, max_key_len;
1481
Holger Schurig9012b282007-05-25 11:27:16 -04001482 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001483
1484 max_key_len = dwrq->length - sizeof(*ext);
1485 if (max_key_len < 0)
1486 goto out;
1487
1488 index = dwrq->flags & IW_ENCODE_INDEX;
1489 if (index) {
1490 if (index < 1 || index > 4)
1491 goto out;
1492 index--;
1493 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001494 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001495 }
1496
Roel Kluinf59d9782007-10-26 21:51:26 +02001497 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001498 ext->alg != IW_ENCODE_ALG_WEP) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001499 if (index != 0 || priv->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001500 goto out;
1501 }
1502
1503 dwrq->flags = index + 1;
1504 memset(ext, 0, sizeof(*ext));
1505
David Woodhouseaa21c002007-12-08 20:04:36 +00001506 if ( !priv->secinfo.wep_enabled
1507 && !priv->secinfo.WPAenabled
1508 && !priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001509 ext->alg = IW_ENCODE_ALG_NONE;
1510 ext->key_len = 0;
1511 dwrq->flags |= IW_ENCODE_DISABLED;
1512 } else {
1513 u8 *key = NULL;
1514
David Woodhouseaa21c002007-12-08 20:04:36 +00001515 if ( priv->secinfo.wep_enabled
1516 && !priv->secinfo.WPAenabled
1517 && !priv->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001518 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001519 ext->alg = IW_ENCODE_ALG_WEP;
David Woodhouseaa21c002007-12-08 20:04:36 +00001520 ext->key_len = priv->wep_keys[index].len;
1521 key = &priv->wep_keys[index].key[0];
1522 } else if ( !priv->secinfo.wep_enabled
1523 && (priv->secinfo.WPAenabled ||
1524 priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001525 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001526 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001527
David Woodhouseaa21c002007-12-08 20:04:36 +00001528 if ( priv->wpa_mcast_key.len
1529 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1530 pkey = &priv->wpa_mcast_key;
1531 else if ( priv->wpa_unicast_key.len
1532 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1533 pkey = &priv->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001534
1535 if (pkey) {
1536 if (pkey->type == KEY_TYPE_ID_AES) {
1537 ext->alg = IW_ENCODE_ALG_CCMP;
1538 } else {
1539 ext->alg = IW_ENCODE_ALG_TKIP;
1540 }
1541 ext->key_len = pkey->len;
1542 key = &pkey->key[0];
1543 } else {
1544 ext->alg = IW_ENCODE_ALG_TKIP;
1545 ext->key_len = 0;
1546 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001547 } else {
1548 goto out;
1549 }
1550
1551 if (ext->key_len > max_key_len) {
1552 ret = -E2BIG;
1553 goto out;
1554 }
1555
1556 if (ext->key_len)
1557 memcpy(ext->key, key, ext->key_len);
1558 else
1559 dwrq->flags |= IW_ENCODE_NOKEY;
1560 dwrq->flags |= IW_ENCODE_ENABLED;
1561 }
1562 ret = 0;
1563
1564out:
Holger Schurig9012b282007-05-25 11:27:16 -04001565 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001566 return ret;
1567}
1568
1569/**
1570 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1571 *
1572 * @param dev A pointer to net_device structure
1573 * @param info A pointer to iw_request_info structure
1574 * @param vwrq A pointer to iw_param structure
1575 * @param extra A pointer to extra data buf
1576 * @return 0 --success, otherwise fail
1577 */
Holger Schurig10078322007-11-15 18:05:47 -05001578static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001579 struct iw_request_info *info,
1580 struct iw_point *dwrq,
1581 char *extra)
1582{
1583 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001584 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001585 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1586 int alg = ext->alg;
1587 struct assoc_request * assoc_req;
1588
Holger Schurig9012b282007-05-25 11:27:16 -04001589 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001590
David Woodhouseaa21c002007-12-08 20:04:36 +00001591 mutex_lock(&priv->lock);
1592 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001593 if (!assoc_req) {
1594 ret = -ENOMEM;
1595 goto out;
1596 }
1597
1598 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1599 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001600 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001601 } else if (alg == IW_ENCODE_ALG_WEP) {
1602 u16 is_default = 0, index, set_tx_key = 0;
1603
1604 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1605 (dwrq->flags & IW_ENCODE_INDEX),
1606 &index, &is_default);
1607 if (ret)
1608 goto out;
1609
1610 /* If WEP isn't enabled, or if there is no key data but a valid
1611 * index, or if the set-TX-key flag was passed, set the TX key.
1612 */
Dan Williams889c05b2007-05-10 22:57:23 -04001613 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001614 || (dwrq->length == 0 && !is_default)
1615 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1616 set_tx_key = 1;
1617
1618 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001619 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001620 set_tx_key);
1621 if (ret)
1622 goto out;
1623
1624 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Amitkumar Karwar921ca032010-02-25 17:16:36 -08001625 priv->authtype_auto = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001626 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001627 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Amitkumar Karwar921ca032010-02-25 17:16:36 -08001628 priv->authtype_auto = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001629 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001630 }
1631
1632 /* Mark the various WEP bits as modified */
1633 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1634 if (dwrq->length)
1635 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1636 if (set_tx_key)
1637 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001638 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001639 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001640
1641 /* validate key length */
1642 if (((alg == IW_ENCODE_ALG_TKIP)
1643 && (ext->key_len != KEY_LEN_WPA_TKIP))
1644 || ((alg == IW_ENCODE_ALG_CCMP)
1645 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001646 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001647 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001648 ext->key_len,
1649 alg);
1650 ret = -EINVAL;
1651 goto out;
1652 }
1653
Dan Williams90a42212007-05-25 23:01:24 -04001654 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001655 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001656 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1657 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001658 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001659 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1660 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001661
Dan Williams1443b652007-08-02 10:45:55 -04001662 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001663 memcpy(pkey->key, ext->key, ext->key_len);
1664 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001665 if (pkey->len)
1666 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001667
Dan Williams90a42212007-05-25 23:01:24 -04001668 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001669 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1670 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001671 } else {
1672 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001673 }
1674
Dan Williams90a42212007-05-25 23:01:24 -04001675 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001676 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001677 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001678 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001679 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001680
1681 /* If WPA isn't enabled yet, do that now */
1682 if ( assoc_req->secinfo.WPAenabled == 0
1683 && assoc_req->secinfo.WPA2enabled == 0) {
1684 assoc_req->secinfo.WPAenabled = 1;
1685 assoc_req->secinfo.WPA2enabled = 1;
1686 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1687 }
1688
Javier Cardona9c31fd62008-09-11 15:32:50 -07001689 /* Only disable wep if necessary: can't waste time here. */
1690 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1691 disable_wep(assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001692 }
1693
1694out:
Javier Cardona9c40fc52008-09-16 18:08:39 -07001695 if (ret == 0) {
1696 /* 802.1x and WPA rekeying must happen as quickly as possible,
1697 * especially during the 4-way handshake; thus if in
1698 * infrastructure mode, and either (a) 802.1x is enabled or
1699 * (b) WPA is being used, set the key right away.
1700 */
1701 if (assoc_req->mode == IW_MODE_INFRA &&
1702 ((assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_802_1X) ||
1703 (assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_PSK) ||
1704 assoc_req->secinfo.WPAenabled ||
1705 assoc_req->secinfo.WPA2enabled)) {
1706 lbs_do_association_work(priv);
1707 } else
1708 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001709 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001710 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001711 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001712 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001713
Holger Schurig9012b282007-05-25 11:27:16 -04001714 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001715 return ret;
1716}
1717
1718
Holger Schurig10078322007-11-15 18:05:47 -05001719static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001720 struct iw_request_info *info,
1721 struct iw_point *dwrq,
1722 char *extra)
1723{
Kiran Divekarab65f642009-02-19 19:32:39 -05001724 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001725 int ret = 0;
1726 struct assoc_request * assoc_req;
1727
Holger Schurig9012b282007-05-25 11:27:16 -04001728 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001729
David Woodhouseaa21c002007-12-08 20:04:36 +00001730 mutex_lock(&priv->lock);
1731 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001732 if (!assoc_req) {
1733 ret = -ENOMEM;
1734 goto out;
1735 }
1736
1737 if (dwrq->length > MAX_WPA_IE_LEN ||
1738 (dwrq->length && extra == NULL)) {
1739 ret = -EINVAL;
1740 goto out;
1741 }
1742
1743 if (dwrq->length) {
1744 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1745 assoc_req->wpa_ie_len = dwrq->length;
1746 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001747 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001748 assoc_req->wpa_ie_len = 0;
1749 }
1750
1751out:
1752 if (ret == 0) {
1753 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001754 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001755 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001756 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001757 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001758 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001759
Holger Schurig9012b282007-05-25 11:27:16 -04001760 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001761 return ret;
1762}
1763
Holger Schurig10078322007-11-15 18:05:47 -05001764static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001765 struct iw_request_info *info,
1766 struct iw_point *dwrq,
1767 char *extra)
1768{
Holger Schurig9012b282007-05-25 11:27:16 -04001769 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001770 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001771
Holger Schurig9012b282007-05-25 11:27:16 -04001772 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001773
David Woodhouseaa21c002007-12-08 20:04:36 +00001774 if (priv->wpa_ie_len == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001775 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001776 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001777 }
1778
David Woodhouseaa21c002007-12-08 20:04:36 +00001779 if (dwrq->length < priv->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001780 ret = -E2BIG;
1781 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001782 }
1783
David Woodhouseaa21c002007-12-08 20:04:36 +00001784 dwrq->length = priv->wpa_ie_len;
1785 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001786
Holger Schurig9012b282007-05-25 11:27:16 -04001787out:
1788 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1789 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001790}
1791
1792
Holger Schurig10078322007-11-15 18:05:47 -05001793static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001794 struct iw_request_info *info,
1795 struct iw_param *dwrq,
1796 char *extra)
1797{
Kiran Divekarab65f642009-02-19 19:32:39 -05001798 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001799 struct assoc_request * assoc_req;
1800 int ret = 0;
1801 int updated = 0;
1802
Holger Schurig9012b282007-05-25 11:27:16 -04001803 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001804
David Woodhouseaa21c002007-12-08 20:04:36 +00001805 mutex_lock(&priv->lock);
1806 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001807 if (!assoc_req) {
1808 ret = -ENOMEM;
1809 goto out;
1810 }
1811
1812 switch (dwrq->flags & IW_AUTH_INDEX) {
Maithili Hinge2c8d5102009-07-31 20:02:19 -07001813 case IW_AUTH_PRIVACY_INVOKED:
1814 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001815 case IW_AUTH_TKIP_COUNTERMEASURES:
1816 case IW_AUTH_CIPHER_PAIRWISE:
1817 case IW_AUTH_CIPHER_GROUP:
Dan Williams90a42212007-05-25 23:01:24 -04001818 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001819 /*
1820 * libertas does not use these parameters
1821 */
1822 break;
1823
Javier Cardona9c40fc52008-09-16 18:08:39 -07001824 case IW_AUTH_KEY_MGMT:
1825 assoc_req->secinfo.key_mgmt = dwrq->value;
1826 updated = 1;
1827 break;
1828
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001829 case IW_AUTH_WPA_VERSION:
1830 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1831 assoc_req->secinfo.WPAenabled = 0;
1832 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001833 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001834 }
1835 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1836 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001837 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001838 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001839 }
1840 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1841 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001842 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001843 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001844 }
1845 updated = 1;
1846 break;
1847
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001848 case IW_AUTH_80211_AUTH_ALG:
1849 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001850 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001851 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001852 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001853 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001854 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001855 } else {
1856 ret = -EINVAL;
1857 }
1858 updated = 1;
1859 break;
1860
1861 case IW_AUTH_WPA_ENABLED:
1862 if (dwrq->value) {
1863 if (!assoc_req->secinfo.WPAenabled &&
1864 !assoc_req->secinfo.WPA2enabled) {
1865 assoc_req->secinfo.WPAenabled = 1;
1866 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001867 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001868 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001869 }
1870 } else {
1871 assoc_req->secinfo.WPAenabled = 0;
1872 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001873 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001874 }
1875 updated = 1;
1876 break;
1877
1878 default:
1879 ret = -EOPNOTSUPP;
1880 break;
1881 }
1882
1883out:
1884 if (ret == 0) {
1885 if (updated)
1886 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001887 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001888 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001889 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001890 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001891 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001892
Holger Schurig9012b282007-05-25 11:27:16 -04001893 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001894 return ret;
1895}
1896
Holger Schurig10078322007-11-15 18:05:47 -05001897static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001898 struct iw_request_info *info,
1899 struct iw_param *dwrq,
1900 char *extra)
1901{
Holger Schurig9012b282007-05-25 11:27:16 -04001902 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001903 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001904
Holger Schurig9012b282007-05-25 11:27:16 -04001905 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001906
1907 switch (dwrq->flags & IW_AUTH_INDEX) {
Javier Cardona9c40fc52008-09-16 18:08:39 -07001908 case IW_AUTH_KEY_MGMT:
1909 dwrq->value = priv->secinfo.key_mgmt;
1910 break;
1911
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001912 case IW_AUTH_WPA_VERSION:
1913 dwrq->value = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +00001914 if (priv->secinfo.WPAenabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001915 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
David Woodhouseaa21c002007-12-08 20:04:36 +00001916 if (priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001917 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1918 if (!dwrq->value)
1919 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1920 break;
1921
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001922 case IW_AUTH_80211_AUTH_ALG:
David Woodhouseaa21c002007-12-08 20:04:36 +00001923 dwrq->value = priv->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001924 break;
1925
1926 case IW_AUTH_WPA_ENABLED:
David Woodhouseaa21c002007-12-08 20:04:36 +00001927 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001928 dwrq->value = 1;
1929 break;
1930
1931 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001932 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001933 }
1934
Holger Schurig9012b282007-05-25 11:27:16 -04001935 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1936 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001937}
1938
1939
Holger Schurig10078322007-11-15 18:05:47 -05001940static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001941 struct iw_param *vwrq, char *extra)
1942{
1943 int ret = 0;
Kiran Divekarab65f642009-02-19 19:32:39 -05001944 struct lbs_private *priv = dev->ml_priv;
Dan Williams87c8c722008-08-19 15:15:35 -04001945 s16 dbm = (s16) vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001946
Holger Schurig9012b282007-05-25 11:27:16 -04001947 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001948
1949 if (vwrq->disabled) {
Dan Williamsd5db2df2008-08-21 17:51:07 -04001950 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
Dan Williams87c8c722008-08-19 15:15:35 -04001951 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001952 }
1953
Dan Williams87c8c722008-08-19 15:15:35 -04001954 if (vwrq->fixed == 0) {
Anna Neal0112c9e2008-09-11 11:17:25 -07001955 /* User requests automatic tx power control, however there are
1956 * many auto tx settings. For now use firmware defaults until
1957 * we come up with a good way to expose these to the user. */
1958 if (priv->fwrelease < 0x09000000) {
1959 ret = lbs_set_power_adapt_cfg(priv, 1,
1960 POW_ADAPT_DEFAULT_P0,
1961 POW_ADAPT_DEFAULT_P1,
1962 POW_ADAPT_DEFAULT_P2);
1963 if (ret)
1964 goto out;
1965 }
1966 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1967 TPC_DEFAULT_P2, 1);
1968 if (ret)
1969 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001970 dbm = priv->txpower_max;
1971 } else {
1972 /* Userspace check in iwrange if it should use dBm or mW,
1973 * therefore this should never happen... Jean II */
1974 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1975 ret = -EOPNOTSUPP;
1976 goto out;
1977 }
1978
Anna Neal0112c9e2008-09-11 11:17:25 -07001979 /* Validate requested power level against firmware allowed
1980 * levels */
Dan Williams87c8c722008-08-19 15:15:35 -04001981 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1982 ret = -EINVAL;
1983 goto out;
1984 }
1985
1986 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1987 ret = -EINVAL;
1988 goto out;
1989 }
Anna Neal0112c9e2008-09-11 11:17:25 -07001990 if (priv->fwrelease < 0x09000000) {
1991 ret = lbs_set_power_adapt_cfg(priv, 0,
1992 POW_ADAPT_DEFAULT_P0,
1993 POW_ADAPT_DEFAULT_P1,
1994 POW_ADAPT_DEFAULT_P2);
1995 if (ret)
1996 goto out;
1997 }
1998 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1999 TPC_DEFAULT_P2, 1);
2000 if (ret)
2001 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04002002 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002003
Dan Williamsd5db2df2008-08-21 17:51:07 -04002004 /* If the radio was off, turn it on */
2005 if (!priv->radio_on) {
2006 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
2007 if (ret)
2008 goto out;
2009 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002010
Dan Williams87c8c722008-08-19 15:15:35 -04002011 lbs_deb_wext("txpower set %d dBm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002012
Dan Williams87c8c722008-08-19 15:15:35 -04002013 ret = lbs_set_tx_power(priv, dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002014
Dan Williams87c8c722008-08-19 15:15:35 -04002015out:
Holger Schurig9012b282007-05-25 11:27:16 -04002016 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002017 return ret;
2018}
2019
Holger Schurig10078322007-11-15 18:05:47 -05002020static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002021 struct iw_point *dwrq, char *extra)
2022{
Kiran Divekarab65f642009-02-19 19:32:39 -05002023 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002024
Holger Schurig9012b282007-05-25 11:27:16 -04002025 lbs_deb_enter(LBS_DEB_WEXT);
2026
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002027 /*
2028 * Note : if dwrq->flags != 0, we should get the relevant SSID from
2029 * the SSID list...
2030 */
2031
2032 /*
2033 * Get the current SSID
2034 */
David Woodhouseaa21c002007-12-08 20:04:36 +00002035 if (priv->connect_status == LBS_CONNECTED) {
2036 memcpy(extra, priv->curbssparams.ssid,
2037 priv->curbssparams.ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002038 } else {
2039 memset(extra, 0, 32);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002040 }
2041 /*
2042 * If none, we may want to get the one that was set
2043 */
2044
David Woodhouseaa21c002007-12-08 20:04:36 +00002045 dwrq->length = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002046
2047 dwrq->flags = 1; /* active */
2048
Holger Schurig9012b282007-05-25 11:27:16 -04002049 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002050 return 0;
2051}
2052
Holger Schurig10078322007-11-15 18:05:47 -05002053static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002054 struct iw_point *dwrq, char *extra)
2055{
Kiran Divekarab65f642009-02-19 19:32:39 -05002056 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002057 int ret = 0;
Holger Schurig243e84e2009-10-22 15:30:47 +02002058 u8 ssid[IEEE80211_MAX_SSID_LEN];
Dan Williamsd8efea22007-05-28 23:54:55 -04002059 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002060 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04002061 int in_ssid_len = dwrq->length;
John W. Linville9387b7c2008-09-30 20:59:05 -04002062 DECLARE_SSID_BUF(ssid_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002063
Holger Schurig9012b282007-05-25 11:27:16 -04002064 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002065
Dan Williamsd5db2df2008-08-21 17:51:07 -04002066 if (!priv->radio_on) {
2067 ret = -EINVAL;
2068 goto out;
2069 }
2070
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002071 /* Check the size of the string */
Holger Schurig243e84e2009-10-22 15:30:47 +02002072 if (in_ssid_len > IEEE80211_MAX_SSID_LEN) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002073 ret = -E2BIG;
2074 goto out;
2075 }
2076
Dan Williamsd8efea22007-05-28 23:54:55 -04002077 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002078
Dan Williamsd8efea22007-05-28 23:54:55 -04002079 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002080 /* "any" SSID requested; leave SSID blank */
2081 } else {
2082 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04002083 memcpy(&ssid, extra, in_ssid_len);
2084 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002085 }
2086
Dan Williamsd8efea22007-05-28 23:54:55 -04002087 if (!ssid_len) {
2088 lbs_deb_wext("requested any SSID\n");
2089 } else {
2090 lbs_deb_wext("requested SSID '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04002091 print_ssid(ssid_buf, ssid, ssid_len));
Dan Williamsd8efea22007-05-28 23:54:55 -04002092 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002093
2094out:
David Woodhouseaa21c002007-12-08 20:04:36 +00002095 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002096 if (ret == 0) {
2097 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002098 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002099 if (!assoc_req) {
2100 ret = -ENOMEM;
2101 } else {
2102 /* Copy the SSID to the association request */
Holger Schurig243e84e2009-10-22 15:30:47 +02002103 memcpy(&assoc_req->ssid, &ssid, IEEE80211_MAX_SSID_LEN);
Dan Williamsd8efea22007-05-28 23:54:55 -04002104 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002105 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002106 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002107 }
2108 }
2109
2110 /* Cancel the association request if there was an error */
2111 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05002112 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002113 }
2114
David Woodhouseaa21c002007-12-08 20:04:36 +00002115 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002116
Holger Schurig9012b282007-05-25 11:27:16 -04002117 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002118 return ret;
2119}
2120
Holger Schurig4143a232009-12-02 15:26:02 +01002121#ifdef CONFIG_LIBERTAS_MESH
David Woodhousef5956bf2007-12-11 19:30:57 -05002122static int lbs_mesh_get_essid(struct net_device *dev,
2123 struct iw_request_info *info,
2124 struct iw_point *dwrq, char *extra)
2125{
Kiran Divekarab65f642009-02-19 19:32:39 -05002126 struct lbs_private *priv = dev->ml_priv;
David Woodhousef5956bf2007-12-11 19:30:57 -05002127
2128 lbs_deb_enter(LBS_DEB_WEXT);
2129
2130 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2131
2132 dwrq->length = priv->mesh_ssid_len;
2133
2134 dwrq->flags = 1; /* active */
2135
2136 lbs_deb_leave(LBS_DEB_WEXT);
2137 return 0;
2138}
2139
2140static int lbs_mesh_set_essid(struct net_device *dev,
2141 struct iw_request_info *info,
2142 struct iw_point *dwrq, char *extra)
2143{
Kiran Divekarab65f642009-02-19 19:32:39 -05002144 struct lbs_private *priv = dev->ml_priv;
David Woodhousef5956bf2007-12-11 19:30:57 -05002145 int ret = 0;
2146
2147 lbs_deb_enter(LBS_DEB_WEXT);
2148
Dan Williamsd5db2df2008-08-21 17:51:07 -04002149 if (!priv->radio_on) {
2150 ret = -EINVAL;
2151 goto out;
2152 }
2153
David Woodhousef5956bf2007-12-11 19:30:57 -05002154 /* Check the size of the string */
Holger Schurig243e84e2009-10-22 15:30:47 +02002155 if (dwrq->length > IEEE80211_MAX_SSID_LEN) {
David Woodhousef5956bf2007-12-11 19:30:57 -05002156 ret = -E2BIG;
2157 goto out;
2158 }
2159
2160 if (!dwrq->flags || !dwrq->length) {
2161 ret = -EINVAL;
2162 goto out;
2163 } else {
2164 /* Specific SSID requested */
2165 memcpy(priv->mesh_ssid, extra, dwrq->length);
2166 priv->mesh_ssid_len = dwrq->length;
2167 }
2168
Javier Cardonaedaea5c2008-05-17 00:55:10 -07002169 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
Holger Schurigc14951f2009-10-22 15:30:50 +02002170 priv->channel);
David Woodhousef5956bf2007-12-11 19:30:57 -05002171 out:
2172 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2173 return ret;
2174}
Holger Schurig4143a232009-12-02 15:26:02 +01002175#endif
David Woodhousef5956bf2007-12-11 19:30:57 -05002176
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002177/**
2178 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2179 *
2180 * @param dev A pointer to net_device structure
2181 * @param info A pointer to iw_request_info structure
2182 * @param awrq A pointer to iw_param structure
2183 * @param extra A pointer to extra data buf
2184 * @return 0 --success, otherwise fail
2185 */
Holger Schurig10078322007-11-15 18:05:47 -05002186static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002187 struct sockaddr *awrq, char *extra)
2188{
Kiran Divekarab65f642009-02-19 19:32:39 -05002189 struct lbs_private *priv = dev->ml_priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002190 struct assoc_request * assoc_req;
2191 int ret = 0;
2192
Holger Schurig9012b282007-05-25 11:27:16 -04002193 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002194
Dan Williamsd5db2df2008-08-21 17:51:07 -04002195 if (!priv->radio_on)
2196 return -EINVAL;
2197
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002198 if (awrq->sa_family != ARPHRD_ETHER)
2199 return -EINVAL;
2200
Johannes Berge1749612008-10-27 15:59:26 -07002201 lbs_deb_wext("ASSOC: WAP: sa_data %pM\n", awrq->sa_data);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002202
David Woodhouseaa21c002007-12-08 20:04:36 +00002203 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002204
2205 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002206 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002207 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05002208 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002209 ret = -ENOMEM;
2210 } else {
2211 /* Copy the BSSID to the association request */
2212 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2213 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002214 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002215 }
2216
David Woodhouseaa21c002007-12-08 20:04:36 +00002217 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002218
2219 return ret;
2220}
2221
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002222/*
2223 * iwconfig settable callbacks
2224 */
Holger Schurig10078322007-11-15 18:05:47 -05002225static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002226 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002227 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002228 (iw_handler) NULL, /* SIOCSIWNWID */
2229 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002230 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2231 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2232 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2233 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002234 (iw_handler) NULL, /* SIOCSIWSENS */
2235 (iw_handler) NULL, /* SIOCGIWSENS */
2236 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002237 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002238 (iw_handler) NULL, /* SIOCSIWPRIV */
2239 (iw_handler) NULL, /* SIOCGIWPRIV */
2240 (iw_handler) NULL, /* SIOCSIWSTATS */
2241 (iw_handler) NULL, /* SIOCGIWSTATS */
2242 iw_handler_set_spy, /* SIOCSIWSPY */
2243 iw_handler_get_spy, /* SIOCGIWSPY */
2244 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2245 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002246 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2247 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002248 (iw_handler) NULL, /* SIOCSIWMLME */
2249 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002250 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2251 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2252 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2253 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2254 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2255 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002256 (iw_handler) NULL, /* -- hole -- */
2257 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002258 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2259 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2260 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2261 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2262 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2263 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2264 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2265 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2266 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2267 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2268 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2269 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2270 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2271 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002272 (iw_handler) NULL, /* -- hole -- */
2273 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002274 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2275 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2276 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2277 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2278 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2279 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002280 (iw_handler) NULL, /* SIOCSIWPMKSA */
2281};
Holger Schurig4143a232009-12-02 15:26:02 +01002282struct iw_handler_def lbs_handler_def = {
2283 .num_standard = ARRAY_SIZE(lbs_handler),
2284 .standard = (iw_handler *) lbs_handler,
2285 .get_wireless_stats = lbs_get_wireless_stats,
2286};
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002287
Holger Schurig4143a232009-12-02 15:26:02 +01002288#ifdef CONFIG_LIBERTAS_MESH
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002289static const iw_handler mesh_wlan_handler[] = {
2290 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002291 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002292 (iw_handler) NULL, /* SIOCSIWNWID */
2293 (iw_handler) NULL, /* SIOCGIWNWID */
David Woodhouse823eaa22007-12-11 19:56:28 -05002294 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
Holger Schurig10078322007-11-15 18:05:47 -05002295 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002296 (iw_handler) NULL, /* SIOCSIWMODE */
2297 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2298 (iw_handler) NULL, /* SIOCSIWSENS */
2299 (iw_handler) NULL, /* SIOCGIWSENS */
2300 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002301 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002302 (iw_handler) NULL, /* SIOCSIWPRIV */
2303 (iw_handler) NULL, /* SIOCGIWPRIV */
2304 (iw_handler) NULL, /* SIOCSIWSTATS */
2305 (iw_handler) NULL, /* SIOCGIWSTATS */
2306 iw_handler_set_spy, /* SIOCSIWSPY */
2307 iw_handler_get_spy, /* SIOCGIWSPY */
2308 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2309 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2310 (iw_handler) NULL, /* SIOCSIWAP */
2311 (iw_handler) NULL, /* SIOCGIWAP */
2312 (iw_handler) NULL, /* SIOCSIWMLME */
2313 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002314 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2315 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
David Woodhousef5956bf2007-12-11 19:30:57 -05002316 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2317 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002318 (iw_handler) NULL, /* SIOCSIWNICKN */
2319 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2320 (iw_handler) NULL, /* -- hole -- */
2321 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002322 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2323 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2324 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2325 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2326 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2327 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2328 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2329 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2330 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2331 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2332 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2333 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2334 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2335 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002336 (iw_handler) NULL, /* -- hole -- */
2337 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002338 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2339 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2340 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2341 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2342 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2343 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002344 (iw_handler) NULL, /* SIOCSIWPMKSA */
2345};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002346
2347struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002348 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002349 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002350 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002351};
Holger Schurig4143a232009-12-02 15:26:02 +01002352#endif