blob: d86fcf0a5ad54faed078a2cd84082cf369e74068 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains ioctl functions
3 */
4#include <linux/ctype.h>
5#include <linux/delay.h>
6#include <linux/if.h>
7#include <linux/if_arp.h>
8#include <linux/wireless.h>
9#include <linux/bitops.h>
10
11#include <net/ieee80211.h>
12#include <net/iw_handler.h>
13
14#include "host.h"
15#include "radiotap.h"
16#include "decl.h"
17#include "defs.h"
18#include "dev.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019#include "wext.h"
Holger Schurig245bf202008-04-02 16:27:42 +020020#include "scan.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020021#include "assoc.h"
Dan Williams8e3c91b2007-12-11 15:50:59 -050022#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020023
24
Holger Schurig69f90322007-11-23 15:43:44 +010025static inline void lbs_postpone_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020026{
David Woodhouseaa21c002007-12-08 20:04:36 +000027 if (priv->surpriseremoved)
Holger Schurig9f9dac22007-10-26 10:12:14 +020028 return;
29 cancel_delayed_work(&priv->assoc_work);
30 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
31}
32
Holger Schurig69f90322007-11-23 15:43:44 +010033static inline void lbs_cancel_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020034{
35 cancel_delayed_work(&priv->assoc_work);
David Woodhouseaa21c002007-12-08 20:04:36 +000036 kfree(priv->pending_assoc_req);
37 priv->pending_assoc_req = NULL;
Holger Schurig9f9dac22007-10-26 10:12:14 +020038}
39
40
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020041/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020042 * @brief Find the channel frequency power info with specific channel
43 *
David Woodhouseaa21c002007-12-08 20:04:36 +000044 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020045 * @param band it can be BAND_A, BAND_G or BAND_B
46 * @param channel the channel for looking
47 * @return A pointer to struct chan_freq_power structure or NULL if not find.
48 */
Holger Schurig69f90322007-11-23 15:43:44 +010049struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
David Woodhouseaa21c002007-12-08 20:04:36 +000050 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +010051 u8 band,
52 u16 channel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020053{
54 struct chan_freq_power *cfp = NULL;
55 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020056 int i, j;
57
David Woodhouseaa21c002007-12-08 20:04:36 +000058 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
59 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020060
David Woodhouseaa21c002007-12-08 20:04:36 +000061 if (priv->enable11d)
62 rc = &priv->universal_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020063 if (!rc->valid || !rc->CFP)
64 continue;
65 if (rc->band != band)
66 continue;
67 for (i = 0; i < rc->nrcfp; i++) {
68 if (rc->CFP[i].channel == channel) {
69 cfp = &rc->CFP[i];
70 break;
71 }
72 }
73 }
74
75 if (!cfp && channel)
Holger Schurig10078322007-11-15 18:05:47 -050076 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
Holger Schurig9012b282007-05-25 11:27:16 -040077 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020078
79 return cfp;
80}
81
82/**
83 * @brief Find the channel frequency power info with specific frequency
84 *
David Woodhouseaa21c002007-12-08 20:04:36 +000085 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020086 * @param band it can be BAND_A, BAND_G or BAND_B
87 * @param freq the frequency for looking
88 * @return A pointer to struct chan_freq_power structure or NULL if not find.
89 */
Holger Schurig69f90322007-11-23 15:43:44 +010090static struct chan_freq_power *find_cfp_by_band_and_freq(
David Woodhouseaa21c002007-12-08 20:04:36 +000091 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +010092 u8 band,
93 u32 freq)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020094{
95 struct chan_freq_power *cfp = NULL;
96 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020097 int i, j;
98
David Woodhouseaa21c002007-12-08 20:04:36 +000099 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
100 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200101
David Woodhouseaa21c002007-12-08 20:04:36 +0000102 if (priv->enable11d)
103 rc = &priv->universal_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200104 if (!rc->valid || !rc->CFP)
105 continue;
106 if (rc->band != band)
107 continue;
108 for (i = 0; i < rc->nrcfp; i++) {
109 if (rc->CFP[i].freq == freq) {
110 cfp = &rc->CFP[i];
111 break;
112 }
113 }
114 }
115
116 if (!cfp && freq)
Holger Schurig9012b282007-05-25 11:27:16 -0400117 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
118 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200119
120 return cfp;
121}
122
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200123/**
Dan Williams8c512762007-08-02 11:40:45 -0400124 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200125 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000126 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200128 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000129static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130{
Holger Schurig9012b282007-05-25 11:27:16 -0400131 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200132
David Woodhouseaa21c002007-12-08 20:04:36 +0000133 if ((priv->connect_status != LBS_CONNECTED) &&
134 (priv->mesh_connect_status != LBS_CONNECTED))
Holger Schurig10078322007-11-15 18:05:47 -0500135 memcpy(rates, lbs_bg_rates, MAX_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400136 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000137 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138
Dan Williams8c512762007-08-02 11:40:45 -0400139 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200140}
141
Holger Schurig10078322007-11-15 18:05:47 -0500142static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200143 char *cwrq, char *extra)
144{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200145
Holger Schurig9012b282007-05-25 11:27:16 -0400146 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200147
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400148 /* We could add support for 802.11n here as needed. Jean II */
149 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200150
Holger Schurig9012b282007-05-25 11:27:16 -0400151 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152 return 0;
153}
154
Holger Schurig10078322007-11-15 18:05:47 -0500155static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156 struct iw_freq *fwrq, char *extra)
157{
Holger Schurig69f90322007-11-23 15:43:44 +0100158 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159 struct chan_freq_power *cfp;
160
Holger Schurig9012b282007-05-25 11:27:16 -0400161 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200162
David Woodhouseaa21c002007-12-08 20:04:36 +0000163 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
164 priv->curbssparams.channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165
166 if (!cfp) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000167 if (priv->curbssparams.channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400168 lbs_deb_wext("invalid channel %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000169 priv->curbssparams.channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200170 return -EINVAL;
171 }
172
173 fwrq->m = (long)cfp->freq * 100000;
174 fwrq->e = 1;
175
Holger Schurig9012b282007-05-25 11:27:16 -0400176 lbs_deb_wext("freq %u\n", fwrq->m);
177 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200178 return 0;
179}
180
Holger Schurig10078322007-11-15 18:05:47 -0500181static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200182 struct sockaddr *awrq, char *extra)
183{
Holger Schurig69f90322007-11-23 15:43:44 +0100184 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185
Holger Schurig9012b282007-05-25 11:27:16 -0400186 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200187
David Woodhouseaa21c002007-12-08 20:04:36 +0000188 if (priv->connect_status == LBS_CONNECTED) {
189 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190 } else {
191 memset(awrq->sa_data, 0, ETH_ALEN);
192 }
193 awrq->sa_family = ARPHRD_ETHER;
194
Holger Schurig9012b282007-05-25 11:27:16 -0400195 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200196 return 0;
197}
198
Holger Schurig10078322007-11-15 18:05:47 -0500199static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200 struct iw_point *dwrq, char *extra)
201{
Holger Schurig69f90322007-11-23 15:43:44 +0100202 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200203
Holger Schurig9012b282007-05-25 11:27:16 -0400204 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200205
206 /*
207 * Check the size of the string
208 */
209
210 if (dwrq->length > 16) {
211 return -E2BIG;
212 }
213
David Woodhouseaa21c002007-12-08 20:04:36 +0000214 mutex_lock(&priv->lock);
215 memset(priv->nodename, 0, sizeof(priv->nodename));
216 memcpy(priv->nodename, extra, dwrq->length);
217 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200218
Holger Schurig9012b282007-05-25 11:27:16 -0400219 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220 return 0;
221}
222
Holger Schurig10078322007-11-15 18:05:47 -0500223static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224 struct iw_point *dwrq, char *extra)
225{
Holger Schurig69f90322007-11-23 15:43:44 +0100226 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227
Holger Schurig9012b282007-05-25 11:27:16 -0400228 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200229
David Woodhouseaa21c002007-12-08 20:04:36 +0000230 dwrq->length = strlen(priv->nodename);
231 memcpy(extra, priv->nodename, dwrq->length);
Holger Schurig04799fa2007-10-09 15:04:14 +0200232 extra[dwrq->length] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200233
Holger Schurig04799fa2007-10-09 15:04:14 +0200234 dwrq->flags = 1; /* active */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235
Holger Schurig9012b282007-05-25 11:27:16 -0400236 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200237 return 0;
238}
239
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400240static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
241 struct iw_point *dwrq, char *extra)
242{
Holger Schurig69f90322007-11-23 15:43:44 +0100243 struct lbs_private *priv = dev->priv;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400244
245 lbs_deb_enter(LBS_DEB_WEXT);
246
247 /* Use nickname to indicate that mesh is on */
248
David Woodhouseaa21c002007-12-08 20:04:36 +0000249 if (priv->mesh_connect_status == LBS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400250 strncpy(extra, "Mesh", 12);
251 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400252 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400253 }
254
255 else {
256 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400257 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400258 }
259
260 lbs_deb_leave(LBS_DEB_WEXT);
261 return 0;
262}
Holger Schurig04799fa2007-10-09 15:04:14 +0200263
Holger Schurig10078322007-11-15 18:05:47 -0500264static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265 struct iw_param *vwrq, char *extra)
266{
267 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100268 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400269 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200270
Holger Schurig9012b282007-05-25 11:27:16 -0400271 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200272
Dan Williams39fcf7a2008-09-10 12:49:00 -0400273 if (vwrq->disabled)
274 val = MRVDRV_RTS_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200275
Dan Williams39fcf7a2008-09-10 12:49:00 -0400276 if (val < MRVDRV_RTS_MIN_VALUE || val > MRVDRV_RTS_MAX_VALUE)
277 return -EINVAL;
278
279 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280
Holger Schurig9012b282007-05-25 11:27:16 -0400281 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200282 return ret;
283}
284
Holger Schurig10078322007-11-15 18:05:47 -0500285static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286 struct iw_param *vwrq, char *extra)
287{
Holger Schurig69f90322007-11-23 15:43:44 +0100288 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400289 int ret = 0;
290 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200291
Holger Schurig9012b282007-05-25 11:27:16 -0400292 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200293
Dan Williams39fcf7a2008-09-10 12:49:00 -0400294 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400295 if (ret)
296 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297
Dan Williams39fcf7a2008-09-10 12:49:00 -0400298 vwrq->value = val;
299 vwrq->disabled = ((val < MRVDRV_RTS_MIN_VALUE)
300 || (val > MRVDRV_RTS_MAX_VALUE));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200301 vwrq->fixed = 1;
302
Holger Schurig9012b282007-05-25 11:27:16 -0400303out:
304 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
305 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306}
307
Holger Schurig10078322007-11-15 18:05:47 -0500308static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309 struct iw_param *vwrq, char *extra)
310{
Holger Schurig69f90322007-11-23 15:43:44 +0100311 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400312 int ret = 0;
313 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314
Holger Schurig9012b282007-05-25 11:27:16 -0400315 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200316
Dan Williams39fcf7a2008-09-10 12:49:00 -0400317 if (vwrq->disabled)
318 val = MRVDRV_FRAG_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200319
Dan Williams39fcf7a2008-09-10 12:49:00 -0400320 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
321 return -EINVAL;
322
323 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
Holger Schurig9012b282007-05-25 11:27:16 -0400324
325 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200326 return ret;
327}
328
Holger Schurig10078322007-11-15 18:05:47 -0500329static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200330 struct iw_param *vwrq, char *extra)
331{
Holger Schurig69f90322007-11-23 15:43:44 +0100332 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400333 int ret = 0;
334 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200335
Holger Schurig9012b282007-05-25 11:27:16 -0400336 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200337
Dan Williams39fcf7a2008-09-10 12:49:00 -0400338 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400339 if (ret)
340 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200341
Dan Williams39fcf7a2008-09-10 12:49:00 -0400342 vwrq->value = val;
343 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
344 || (val > MRVDRV_FRAG_MAX_VALUE));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200345 vwrq->fixed = 1;
346
Holger Schurig9012b282007-05-25 11:27:16 -0400347out:
348 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349 return ret;
350}
351
Holger Schurig10078322007-11-15 18:05:47 -0500352static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353 struct iw_request_info *info, u32 * uwrq, char *extra)
354{
Holger Schurig69f90322007-11-23 15:43:44 +0100355 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200356
Holger Schurig9012b282007-05-25 11:27:16 -0400357 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200358
David Woodhouseaa21c002007-12-08 20:04:36 +0000359 *uwrq = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360
Holger Schurig9012b282007-05-25 11:27:16 -0400361 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200362 return 0;
363}
364
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400365static int mesh_wlan_get_mode(struct net_device *dev,
366 struct iw_request_info *info, u32 * uwrq,
367 char *extra)
368{
369 lbs_deb_enter(LBS_DEB_WEXT);
370
Dan Williams39fcf7a2008-09-10 12:49:00 -0400371 *uwrq = IW_MODE_REPEAT;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400372
373 lbs_deb_leave(LBS_DEB_WEXT);
374 return 0;
375}
376
Holger Schurig10078322007-11-15 18:05:47 -0500377static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378 struct iw_request_info *info,
379 struct iw_param *vwrq, char *extra)
380{
Holger Schurig69f90322007-11-23 15:43:44 +0100381 struct lbs_private *priv = dev->priv;
Dan Williams87c8c722008-08-19 15:15:35 -0400382 s16 curlevel = 0;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400383 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200384
Holger Schurig9012b282007-05-25 11:27:16 -0400385 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386
Dan Williamsd5db2df2008-08-21 17:51:07 -0400387 if (!priv->radio_on) {
388 lbs_deb_wext("tx power off\n");
389 vwrq->value = 0;
390 vwrq->disabled = 1;
391 goto out;
392 }
393
Dan Williams87c8c722008-08-19 15:15:35 -0400394 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400395 if (ret)
396 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397
Dan Williams87c8c722008-08-19 15:15:35 -0400398 lbs_deb_wext("tx power level %d dbm\n", curlevel);
Dan Williams87c8c722008-08-19 15:15:35 -0400399 priv->txpower_cur = curlevel;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400400
Dan Williams87c8c722008-08-19 15:15:35 -0400401 vwrq->value = curlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200402 vwrq->fixed = 1;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400403 vwrq->disabled = 0;
404 vwrq->flags = IW_TXPOW_DBM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200405
Holger Schurig9012b282007-05-25 11:27:16 -0400406out:
407 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
408 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200409}
410
Holger Schurig10078322007-11-15 18:05:47 -0500411static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200412 struct iw_param *vwrq, char *extra)
413{
Holger Schurig69f90322007-11-23 15:43:44 +0100414 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400415 int ret = 0;
416 u16 slimit = 0, llimit = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417
Holger Schurig9012b282007-05-25 11:27:16 -0400418 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419
Dan Williams39fcf7a2008-09-10 12:49:00 -0400420 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
421 return -EOPNOTSUPP;
422
423 /* The MAC has a 4-bit Total_Tx_Count register
424 Total_Tx_Count = 1 + Tx_Retry_Count */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425#define TX_RETRY_MIN 0
426#define TX_RETRY_MAX 14
Dan Williams39fcf7a2008-09-10 12:49:00 -0400427 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
428 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200429
Dan Williams39fcf7a2008-09-10 12:49:00 -0400430 /* Add 1 to convert retry count to try count */
431 if (vwrq->flags & IW_RETRY_SHORT)
432 slimit = (u16) (vwrq->value + 1);
433 else if (vwrq->flags & IW_RETRY_LONG)
434 llimit = (u16) (vwrq->value + 1);
435 else
436 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437
Dan Williams39fcf7a2008-09-10 12:49:00 -0400438 if (llimit) {
439 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
440 llimit);
Holger Schurig9012b282007-05-25 11:27:16 -0400441 if (ret)
442 goto out;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400443 }
444
445 if (slimit) {
446 /* txretrycount follows the short retry limit */
447 priv->txretrycount = slimit;
448 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
449 slimit);
450 if (ret)
451 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200452 }
453
Holger Schurig9012b282007-05-25 11:27:16 -0400454out:
455 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
456 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200457}
458
Holger Schurig10078322007-11-15 18:05:47 -0500459static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200460 struct iw_param *vwrq, char *extra)
461{
Holger Schurig69f90322007-11-23 15:43:44 +0100462 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200463 int ret = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400464 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200465
Holger Schurig9012b282007-05-25 11:27:16 -0400466 lbs_deb_enter(LBS_DEB_WEXT);
467
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468 vwrq->disabled = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400469
470 if (vwrq->flags & IW_RETRY_LONG) {
471 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
472 if (ret)
473 goto out;
474
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200475 /* Subtract 1 to convert try count to retry count */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400476 vwrq->value = val - 1;
477 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
478 } else {
479 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
480 if (ret)
481 goto out;
482
483 /* txretry count follows the short retry limit */
484 priv->txretrycount = val;
485 /* Subtract 1 to convert try count to retry count */
486 vwrq->value = val - 1;
487 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200488 }
489
Holger Schurig9012b282007-05-25 11:27:16 -0400490out:
491 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
492 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200493}
494
495static inline void sort_channels(struct iw_freq *freq, int num)
496{
497 int i, j;
498 struct iw_freq temp;
499
500 for (i = 0; i < num; i++)
501 for (j = i + 1; j < num; j++)
502 if (freq[i].i > freq[j].i) {
503 temp.i = freq[i].i;
504 temp.m = freq[i].m;
505
506 freq[i].i = freq[j].i;
507 freq[i].m = freq[j].m;
508
509 freq[j].i = temp.i;
510 freq[j].m = temp.m;
511 }
512}
513
514/* data rate listing
515 MULTI_BANDS:
516 abg a b b/g
517 Infra G(12) A(8) B(4) G(12)
518 Adhoc A+B(12) A(8) B(4) B(4)
519
520 non-MULTI_BANDS:
521 b b/g
522 Infra B(4) G(12)
523 Adhoc B(4) B(4)
524 */
525/**
526 * @brief Get Range Info
527 *
528 * @param dev A pointer to net_device structure
529 * @param info A pointer to iw_request_info structure
530 * @param vwrq A pointer to iw_param structure
531 * @param extra A pointer to extra data buf
532 * @return 0 --success, otherwise fail
533 */
Holger Schurig10078322007-11-15 18:05:47 -0500534static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200535 struct iw_point *dwrq, char *extra)
536{
537 int i, j;
Holger Schurig69f90322007-11-23 15:43:44 +0100538 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200539 struct iw_range *range = (struct iw_range *)extra;
540 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400541 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200542
543 u8 flag = 0;
544
Holger Schurig9012b282007-05-25 11:27:16 -0400545 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200546
547 dwrq->length = sizeof(struct iw_range);
548 memset(range, 0, sizeof(struct iw_range));
549
550 range->min_nwid = 0;
551 range->max_nwid = 0;
552
553 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000554 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400555 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
556 for (i = 0; i < range->num_bitrates; i++)
557 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200558 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400559 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200560 range->num_bitrates);
561
562 range->num_frequency = 0;
Holger Schurig52933d82008-03-05 07:05:32 +0100563
564 range->scan_capa = IW_SCAN_CAPA_ESSID;
565
David Woodhouseaa21c002007-12-08 20:04:36 +0000566 if (priv->enable11d &&
567 (priv->connect_status == LBS_CONNECTED ||
568 priv->mesh_connect_status == LBS_CONNECTED)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200569 u8 chan_no;
570 u8 band;
571
572 struct parsed_region_chan_11d *parsed_region_chan =
David Woodhouseaa21c002007-12-08 20:04:36 +0000573 &priv->parsed_region_chan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200574
575 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400576 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
577 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200578 }
579 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400580 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200581 parsed_region_chan->nr_chan);
582
583 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
584 && (i < parsed_region_chan->nr_chan); i++) {
585 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400586 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200587 range->freq[range->num_frequency].i = (long)chan_no;
588 range->freq[range->num_frequency].m =
Holger Schurige98a88d2008-03-19 14:25:58 +0100589 (long)lbs_chan_2_freq(chan_no) * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200590 range->freq[range->num_frequency].e = 1;
591 range->num_frequency++;
592 }
593 flag = 1;
594 }
595 if (!flag) {
596 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000597 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
598 cfp = priv->region_channel[j].CFP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000600 && priv->region_channel[j].valid
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200601 && cfp
David Woodhouseaa21c002007-12-08 20:04:36 +0000602 && (i < priv->region_channel[j].nrcfp); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603 range->freq[range->num_frequency].i =
604 (long)cfp->channel;
605 range->freq[range->num_frequency].m =
606 (long)cfp->freq * 100000;
607 range->freq[range->num_frequency].e = 1;
608 cfp++;
609 range->num_frequency++;
610 }
611 }
612 }
613
Holger Schurig9012b282007-05-25 11:27:16 -0400614 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615 IW_MAX_FREQUENCIES, range->num_frequency);
616
617 range->num_channels = range->num_frequency;
618
619 sort_channels(&range->freq[0], range->num_frequency);
620
621 /*
622 * Set an indication of the max TCP throughput in bit/s that we can
623 * expect using this interface
624 */
625 if (i > 2)
626 range->throughput = 5000 * 1000;
627 else
628 range->throughput = 1500 * 1000;
629
630 range->min_rts = MRVDRV_RTS_MIN_VALUE;
631 range->max_rts = MRVDRV_RTS_MAX_VALUE;
632 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
633 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
634
635 range->encoding_size[0] = 5;
636 range->encoding_size[1] = 13;
637 range->num_encoding_sizes = 2;
638 range->max_encoding_tokens = 4;
639
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100640 /*
641 * Right now we support only "iwconfig ethX power on|off"
642 */
643 range->pm_capa = IW_POWER_ON;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200644
645 /*
646 * Minimum version we recommend
647 */
648 range->we_version_source = 15;
649
650 /*
651 * Version we are compiled with
652 */
653 range->we_version_compiled = WIRELESS_EXT;
654
655 range->retry_capa = IW_RETRY_LIMIT;
656 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
657
658 range->min_retry = TX_RETRY_MIN;
659 range->max_retry = TX_RETRY_MAX;
660
661 /*
662 * Set the qual, level and noise range values
663 */
664 range->max_qual.qual = 100;
665 range->max_qual.level = 0;
666 range->max_qual.noise = 0;
667 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
668
669 range->avg_qual.qual = 70;
670 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
671 range->avg_qual.level = 0;
672 range->avg_qual.noise = 0;
673 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
674
675 range->sensitivity = 0;
676
Dan Williams87c8c722008-08-19 15:15:35 -0400677 /* Setup the supported power level ranges */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200678 memset(range->txpower, 0, sizeof(range->txpower));
Dan Williams87c8c722008-08-19 15:15:35 -0400679 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
680 range->txpower[0] = priv->txpower_min;
681 range->txpower[1] = priv->txpower_max;
682 range->num_txpower = 2;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200683
684 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
685 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
686 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
687 range->event_capa[1] = IW_EVENT_CAPA_K_1;
688
David Woodhouseaa21c002007-12-08 20:04:36 +0000689 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200690 range->enc_capa = IW_ENC_CAPA_WPA
691 | IW_ENC_CAPA_WPA2
692 | IW_ENC_CAPA_CIPHER_TKIP
693 | IW_ENC_CAPA_CIPHER_CCMP;
694 }
695
Holger Schurig9012b282007-05-25 11:27:16 -0400696out:
697 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200698 return 0;
699}
700
Holger Schurig10078322007-11-15 18:05:47 -0500701static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200702 struct iw_param *vwrq, char *extra)
703{
Holger Schurig69f90322007-11-23 15:43:44 +0100704 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200705
Holger Schurig9012b282007-05-25 11:27:16 -0400706 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707
David Woodhouseb2c57ee2007-12-17 14:41:13 -0500708 if (!priv->ps_supported) {
709 if (vwrq->disabled)
710 return 0;
711 else
712 return -EINVAL;
713 }
714
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715 /* PS is currently supported only in Infrastructure mode
716 * Remove this check if it is to be supported in IBSS mode also
717 */
718
719 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000720 priv->psmode = LBS802_11POWERMODECAM;
721 if (priv->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500722 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200723 }
724
725 return 0;
726 }
727
728 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400729 lbs_deb_wext(
730 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731 return -EINVAL;
732 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400733 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200734 return -EINVAL;
735 }
736
David Woodhouseaa21c002007-12-08 20:04:36 +0000737 if (priv->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200738 return 0;
739 }
740
David Woodhouseaa21c002007-12-08 20:04:36 +0000741 priv->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200742
David Woodhouseaa21c002007-12-08 20:04:36 +0000743 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500744 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745 }
746
Holger Schurig9012b282007-05-25 11:27:16 -0400747 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200748 return 0;
749}
750
Holger Schurig10078322007-11-15 18:05:47 -0500751static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200752 struct iw_param *vwrq, char *extra)
753{
Holger Schurig69f90322007-11-23 15:43:44 +0100754 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200755
Holger Schurig9012b282007-05-25 11:27:16 -0400756 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200757
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200758 vwrq->value = 0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100759 vwrq->flags = 0;
760 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
761 || priv->connect_status == LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200762
Holger Schurig9012b282007-05-25 11:27:16 -0400763 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200764 return 0;
765}
766
Holger Schurig10078322007-11-15 18:05:47 -0500767static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200768{
769 enum {
770 POOR = 30,
771 FAIR = 60,
772 GOOD = 80,
773 VERY_GOOD = 90,
774 EXCELLENT = 95,
775 PERFECT = 100
776 };
Holger Schurig69f90322007-11-23 15:43:44 +0100777 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778 u32 rssi_qual;
779 u32 tx_qual;
780 u32 quality = 0;
781 int stats_valid = 0;
782 u8 rssi;
783 u32 tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100784 struct cmd_ds_802_11_get_log log;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785
Holger Schurig9012b282007-05-25 11:27:16 -0400786 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200787
David Woodhouseaa21c002007-12-08 20:04:36 +0000788 priv->wstats.status = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200789
790 /* If we're not associated, all quality values are meaningless */
David Woodhouseaa21c002007-12-08 20:04:36 +0000791 if ((priv->connect_status != LBS_CONNECTED) &&
792 (priv->mesh_connect_status != LBS_CONNECTED))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793 goto out;
794
795 /* Quality by RSSI */
796 priv->wstats.qual.level =
David Woodhouseaa21c002007-12-08 20:04:36 +0000797 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
798 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200799
David Woodhouseaa21c002007-12-08 20:04:36 +0000800 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
802 } else {
803 priv->wstats.qual.noise =
David Woodhouseaa21c002007-12-08 20:04:36 +0000804 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200805 }
806
Holger Schurig9012b282007-05-25 11:27:16 -0400807 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
808 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200809
810 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
811 if (rssi < 15)
812 rssi_qual = rssi * POOR / 10;
813 else if (rssi < 20)
814 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
815 else if (rssi < 30)
816 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
817 else if (rssi < 40)
818 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
819 10 + GOOD;
820 else
821 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
822 10 + VERY_GOOD;
823 quality = rssi_qual;
824
825 /* Quality by TX errors */
826 priv->wstats.discard.retries = priv->stats.tx_errors;
827
Holger Schurigc49c3b72008-03-17 12:45:58 +0100828 memset(&log, 0, sizeof(log));
829 log.hdr.size = cpu_to_le16(sizeof(log));
830 lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
831
832 tx_retries = le32_to_cpu(log.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200833
834 if (tx_retries > 75)
835 tx_qual = (90 - tx_retries) * POOR / 15;
836 else if (tx_retries > 70)
837 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
838 else if (tx_retries > 65)
839 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
840 else if (tx_retries > 50)
841 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
842 15 + GOOD;
843 else
844 tx_qual = (50 - tx_retries) *
845 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
846 quality = min(quality, tx_qual);
847
Holger Schurigc49c3b72008-03-17 12:45:58 +0100848 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200849 priv->wstats.discard.retries = tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100850 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200851
852 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400853 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200854 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
855 stats_valid = 1;
856
857 /* update stats asynchronously for future calls */
Holger Schurig10078322007-11-15 18:05:47 -0500858 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200859 0, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200860out:
861 if (!stats_valid) {
862 priv->wstats.miss.beacon = 0;
863 priv->wstats.discard.retries = 0;
864 priv->wstats.qual.qual = 0;
865 priv->wstats.qual.level = 0;
866 priv->wstats.qual.noise = 0;
867 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
868 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
869 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
870 }
871
Holger Schurig9012b282007-05-25 11:27:16 -0400872 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200873 return &priv->wstats;
874
875
876}
877
Holger Schurig10078322007-11-15 18:05:47 -0500878static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200879 struct iw_freq *fwrq, char *extra)
880{
Dan Williamsef9a2642007-05-25 16:46:33 -0400881 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +0100882 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200883 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400884 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200885
Holger Schurig9012b282007-05-25 11:27:16 -0400886 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200887
David Woodhouseaa21c002007-12-08 20:04:36 +0000888 mutex_lock(&priv->lock);
889 assoc_req = lbs_get_association_request(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400890 if (!assoc_req) {
891 ret = -ENOMEM;
892 goto out;
893 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200894
Dan Williamsef9a2642007-05-25 16:46:33 -0400895 /* If setting by frequency, convert to a channel */
896 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200897 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200898
David Woodhouseaa21c002007-12-08 20:04:36 +0000899 cfp = find_cfp_by_band_and_freq(priv, 0, f);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200900 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400901 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400902 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200903 }
904
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400906 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200907 }
908
Dan Williamsef9a2642007-05-25 16:46:33 -0400909 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200910 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400911 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200912 }
913
David Woodhouseaa21c002007-12-08 20:04:36 +0000914 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400915 if (!cfp) {
916 goto out;
917 }
918
919 assoc_req->channel = fwrq->m;
920 ret = 0;
921
Holger Schurig9012b282007-05-25 11:27:16 -0400922out:
Dan Williamsef9a2642007-05-25 16:46:33 -0400923 if (ret == 0) {
924 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500925 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400926 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500927 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400928 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000929 mutex_unlock(&priv->lock);
Dan Williamsef9a2642007-05-25 16:46:33 -0400930
931 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
932 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200933}
934
David Woodhouse823eaa22007-12-11 19:56:28 -0500935static int lbs_mesh_set_freq(struct net_device *dev,
936 struct iw_request_info *info,
937 struct iw_freq *fwrq, char *extra)
938{
939 struct lbs_private *priv = dev->priv;
940 struct chan_freq_power *cfp;
941 int ret = -EINVAL;
942
943 lbs_deb_enter(LBS_DEB_WEXT);
944
945 /* If setting by frequency, convert to a channel */
946 if (fwrq->e == 1) {
947 long f = fwrq->m / 100000;
948
949 cfp = find_cfp_by_band_and_freq(priv, 0, f);
950 if (!cfp) {
951 lbs_deb_wext("invalid freq %ld\n", f);
952 goto out;
953 }
954
955 fwrq->e = 0;
956 fwrq->m = (int) cfp->channel;
957 }
958
959 /* Setting by channel number */
960 if (fwrq->m > 1000 || fwrq->e > 0) {
961 goto out;
962 }
963
964 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
965 if (!cfp) {
966 goto out;
967 }
968
969 if (fwrq->m != priv->curbssparams.channel) {
970 lbs_deb_wext("mesh channel change forces eth disconnect\n");
971 if (priv->mode == IW_MODE_INFRA)
Dan Williams191bb402008-08-21 17:46:18 -0400972 lbs_cmd_80211_deauthenticate(priv,
973 priv->curbssparams.bssid,
974 WLAN_REASON_DEAUTH_LEAVING);
David Woodhouse823eaa22007-12-11 19:56:28 -0500975 else if (priv->mode == IW_MODE_ADHOC)
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400976 lbs_adhoc_stop(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -0500977 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700978 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
David Woodhouse86062132007-12-13 00:32:36 -0500979 lbs_update_channel(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -0500980 ret = 0;
981
982out:
983 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
984 return ret;
985}
986
Holger Schurig10078322007-11-15 18:05:47 -0500987static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200988 struct iw_param *vwrq, char *extra)
989{
Holger Schurig69f90322007-11-23 15:43:44 +0100990 struct lbs_private *priv = dev->priv;
Dan Williams8e3c91b2007-12-11 15:50:59 -0500991 u8 new_rate = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400992 int ret = -EINVAL;
993 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200994
Holger Schurig9012b282007-05-25 11:27:16 -0400995 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -0400996 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Javier Cardona85319f92008-05-24 10:59:49 +0100997 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
998
999 if (vwrq->fixed && vwrq->value == -1)
1000 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001001
Dan Williams8c512762007-08-02 11:40:45 -04001002 /* Auto rate? */
Javier Cardona85319f92008-05-24 10:59:49 +01001003 priv->enablehwauto = !vwrq->fixed;
1004
1005 if (vwrq->value == -1)
David Woodhouseaa21c002007-12-08 20:04:36 +00001006 priv->cur_rate = 0;
Javier Cardona85319f92008-05-24 10:59:49 +01001007 else {
Dan Williams8c512762007-08-02 11:40:45 -04001008 if (vwrq->value % 100000)
1009 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001010
Javier Cardona85319f92008-05-24 10:59:49 +01001011 new_rate = vwrq->value / 500000;
1012 priv->cur_rate = new_rate;
1013 /* the rest is only needed for lbs_set_data_rate() */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001014 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +00001015 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -04001016 if (!memchr(rates, new_rate, sizeof(rates))) {
1017 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1018 new_rate);
1019 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001020 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001021 }
1022
Javier Cardona85319f92008-05-24 10:59:49 +01001023 /* Try the newer command first (Firmware Spec 5.1 and above) */
1024 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1025
1026 /* Fallback to older version */
1027 if (ret)
1028 ret = lbs_set_data_rate(priv, new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029
Dan Williams8c512762007-08-02 11:40:45 -04001030out:
Holger Schurig9012b282007-05-25 11:27:16 -04001031 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001032 return ret;
1033}
1034
Holger Schurig10078322007-11-15 18:05:47 -05001035static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001036 struct iw_param *vwrq, char *extra)
1037{
Holger Schurig69f90322007-11-23 15:43:44 +01001038 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001039
Holger Schurig9012b282007-05-25 11:27:16 -04001040 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001041
David Woodhouseaa21c002007-12-08 20:04:36 +00001042 if (priv->connect_status == LBS_CONNECTED) {
1043 vwrq->value = priv->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001044
Javier Cardona85319f92008-05-24 10:59:49 +01001045 if (priv->enablehwauto)
Dan Williams8c512762007-08-02 11:40:45 -04001046 vwrq->fixed = 0;
1047 else
1048 vwrq->fixed = 1;
1049
1050 } else {
1051 vwrq->fixed = 0;
1052 vwrq->value = 0;
1053 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001054
Holger Schurig9012b282007-05-25 11:27:16 -04001055 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001056 return 0;
1057}
1058
Holger Schurig10078322007-11-15 18:05:47 -05001059static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001060 struct iw_request_info *info, u32 * uwrq, char *extra)
1061{
1062 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001063 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001065
Holger Schurig9012b282007-05-25 11:27:16 -04001066 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001067
Dan Williams0dc5a292007-05-10 22:58:02 -04001068 if ( (*uwrq != IW_MODE_ADHOC)
1069 && (*uwrq != IW_MODE_INFRA)
1070 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001071 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001072 ret = -EINVAL;
1073 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074 }
1075
David Woodhouseaa21c002007-12-08 20:04:36 +00001076 mutex_lock(&priv->lock);
1077 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001078 if (!assoc_req) {
1079 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001080 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001081 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001082 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001083 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001084 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001085 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001086 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001087 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001088
Dan Williams0dc5a292007-05-10 22:58:02 -04001089out:
Holger Schurig9012b282007-05-25 11:27:16 -04001090 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001091 return ret;
1092}
1093
1094
1095/**
1096 * @brief Get Encryption key
1097 *
1098 * @param dev A pointer to net_device structure
1099 * @param info A pointer to iw_request_info structure
1100 * @param vwrq A pointer to iw_param structure
1101 * @param extra A pointer to extra data buf
1102 * @return 0 --success, otherwise fail
1103 */
Holger Schurig10078322007-11-15 18:05:47 -05001104static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001105 struct iw_request_info *info,
1106 struct iw_point *dwrq, u8 * extra)
1107{
Holger Schurig69f90322007-11-23 15:43:44 +01001108 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001109 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1110
Holger Schurig9012b282007-05-25 11:27:16 -04001111 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001112
Holger Schurig9012b282007-05-25 11:27:16 -04001113 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001114 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001115
1116 dwrq->flags = 0;
1117
1118 /* Authentication method */
David Woodhouseaa21c002007-12-08 20:04:36 +00001119 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -04001120 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001121 dwrq->flags = IW_ENCODE_OPEN;
1122 break;
1123
Dan Williams6affe782007-05-10 22:56:42 -04001124 case IW_AUTH_ALG_SHARED_KEY:
1125 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001126 dwrq->flags = IW_ENCODE_RESTRICTED;
1127 break;
1128 default:
1129 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1130 break;
1131 }
1132
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001133 memset(extra, 0, 16);
1134
David Woodhouseaa21c002007-12-08 20:04:36 +00001135 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001136
1137 /* Default to returning current transmit key */
1138 if (index < 0)
David Woodhouseaa21c002007-12-08 20:04:36 +00001139 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001140
David Woodhouseaa21c002007-12-08 20:04:36 +00001141 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1142 memcpy(extra, priv->wep_keys[index].key,
1143 priv->wep_keys[index].len);
1144 dwrq->length = priv->wep_keys[index].len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001145
1146 dwrq->flags |= (index + 1);
1147 /* Return WEP enabled */
1148 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhouseaa21c002007-12-08 20:04:36 +00001149 } else if ((priv->secinfo.WPAenabled)
1150 || (priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001151 /* return WPA enabled */
1152 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhousec12bdc42007-12-07 19:32:12 +00001153 dwrq->flags |= IW_ENCODE_NOKEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001154 } else {
1155 dwrq->flags |= IW_ENCODE_DISABLED;
1156 }
1157
David Woodhouseaa21c002007-12-08 20:04:36 +00001158 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001159
Joe Perches0795af52007-10-03 17:59:30 -07001160 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001161 extra[0], extra[1], extra[2],
1162 extra[3], extra[4], extra[5], dwrq->length);
1163
Holger Schurig9012b282007-05-25 11:27:16 -04001164 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001165
Holger Schurig9012b282007-05-25 11:27:16 -04001166 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001167 return 0;
1168}
1169
1170/**
1171 * @brief Set Encryption key (internal)
1172 *
1173 * @param priv A pointer to private card structure
1174 * @param key_material A pointer to key material
1175 * @param key_length length of key material
1176 * @param index key index to set
1177 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1178 * @return 0 --success, otherwise fail
1179 */
Holger Schurig10078322007-11-15 18:05:47 -05001180static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001181 const char *key_material,
1182 u16 key_length,
1183 u16 index,
1184 int set_tx_key)
1185{
Holger Schurig9012b282007-05-25 11:27:16 -04001186 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001187 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001188
Holger Schurig9012b282007-05-25 11:27:16 -04001189 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001190
1191 /* Paranoid validation of key index */
1192 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001193 ret = -EINVAL;
1194 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001195 }
1196
1197 /* validate max key length */
1198 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001199 ret = -EINVAL;
1200 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001201 }
1202
1203 pkey = &assoc_req->wep_keys[index];
1204
1205 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001206 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001207 pkey->type = KEY_TYPE_ID_WEP;
1208
1209 /* Standardize the key length */
1210 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1211 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1212 memcpy(pkey->key, key_material, key_length);
1213 }
1214
1215 if (set_tx_key) {
1216 /* Ensure the chosen key is valid */
1217 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001218 lbs_deb_wext("key not set, so cannot enable it\n");
1219 ret = -EINVAL;
1220 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001221 }
1222 assoc_req->wep_tx_keyidx = index;
1223 }
1224
Dan Williams889c05b2007-05-10 22:57:23 -04001225 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001226
Holger Schurig9012b282007-05-25 11:27:16 -04001227out:
1228 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1229 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001230}
1231
1232static int validate_key_index(u16 def_index, u16 raw_index,
1233 u16 *out_index, u16 *is_default)
1234{
1235 if (!out_index || !is_default)
1236 return -EINVAL;
1237
1238 /* Verify index if present, otherwise use default TX key index */
1239 if (raw_index > 0) {
1240 if (raw_index > 4)
1241 return -EINVAL;
1242 *out_index = raw_index - 1;
1243 } else {
1244 *out_index = def_index;
1245 *is_default = 1;
1246 }
1247 return 0;
1248}
1249
1250static void disable_wep(struct assoc_request *assoc_req)
1251{
1252 int i;
1253
Dan Williams90a42212007-05-25 23:01:24 -04001254 lbs_deb_enter(LBS_DEB_WEXT);
1255
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001256 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001257 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001258
1259 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001260 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001261 for (i = 0; i < 4; i++)
1262 assoc_req->wep_keys[i].len = 0;
1263
1264 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1265 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001266
1267 lbs_deb_leave(LBS_DEB_WEXT);
1268}
1269
1270static void disable_wpa(struct assoc_request *assoc_req)
1271{
1272 lbs_deb_enter(LBS_DEB_WEXT);
1273
Dan Williams1443b652007-08-02 10:45:55 -04001274 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001275 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1276 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1277
Dan Williams1443b652007-08-02 10:45:55 -04001278 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001279 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1280 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1281
1282 assoc_req->secinfo.WPAenabled = 0;
1283 assoc_req->secinfo.WPA2enabled = 0;
1284 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1285
1286 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001287}
1288
1289/**
1290 * @brief Set Encryption key
1291 *
1292 * @param dev A pointer to net_device structure
1293 * @param info A pointer to iw_request_info structure
1294 * @param vwrq A pointer to iw_param structure
1295 * @param extra A pointer to extra data buf
1296 * @return 0 --success, otherwise fail
1297 */
Holger Schurig10078322007-11-15 18:05:47 -05001298static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001299 struct iw_request_info *info,
1300 struct iw_point *dwrq, char *extra)
1301{
1302 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001303 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001304 struct assoc_request * assoc_req;
1305 u16 is_default = 0, index = 0, set_tx_key = 0;
1306
Holger Schurig9012b282007-05-25 11:27:16 -04001307 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001308
David Woodhouseaa21c002007-12-08 20:04:36 +00001309 mutex_lock(&priv->lock);
1310 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001311 if (!assoc_req) {
1312 ret = -ENOMEM;
1313 goto out;
1314 }
1315
1316 if (dwrq->flags & IW_ENCODE_DISABLED) {
1317 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001318 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001319 goto out;
1320 }
1321
1322 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1323 (dwrq->flags & IW_ENCODE_INDEX),
1324 &index, &is_default);
1325 if (ret) {
1326 ret = -EINVAL;
1327 goto out;
1328 }
1329
1330 /* If WEP isn't enabled, or if there is no key data but a valid
1331 * index, set the TX key.
1332 */
Dan Williams889c05b2007-05-10 22:57:23 -04001333 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001334 set_tx_key = 1;
1335
Holger Schurig10078322007-11-15 18:05:47 -05001336 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001337 if (ret)
1338 goto out;
1339
1340 if (dwrq->length)
1341 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1342 if (set_tx_key)
1343 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1344
1345 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001346 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001347 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001348 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349 }
1350
1351out:
1352 if (ret == 0) {
1353 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001354 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001355 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001356 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001357 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001358 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001359
Holger Schurig9012b282007-05-25 11:27:16 -04001360 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001361 return ret;
1362}
1363
1364/**
1365 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1366 *
1367 * @param dev A pointer to net_device structure
1368 * @param info A pointer to iw_request_info structure
1369 * @param vwrq A pointer to iw_param structure
1370 * @param extra A pointer to extra data buf
1371 * @return 0 on success, otherwise failure
1372 */
Holger Schurig10078322007-11-15 18:05:47 -05001373static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001374 struct iw_request_info *info,
1375 struct iw_point *dwrq,
1376 char *extra)
1377{
1378 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +01001379 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001380 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1381 int index, max_key_len;
1382
Holger Schurig9012b282007-05-25 11:27:16 -04001383 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001384
1385 max_key_len = dwrq->length - sizeof(*ext);
1386 if (max_key_len < 0)
1387 goto out;
1388
1389 index = dwrq->flags & IW_ENCODE_INDEX;
1390 if (index) {
1391 if (index < 1 || index > 4)
1392 goto out;
1393 index--;
1394 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001395 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001396 }
1397
Roel Kluinf59d9782007-10-26 21:51:26 +02001398 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001399 ext->alg != IW_ENCODE_ALG_WEP) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001400 if (index != 0 || priv->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001401 goto out;
1402 }
1403
1404 dwrq->flags = index + 1;
1405 memset(ext, 0, sizeof(*ext));
1406
David Woodhouseaa21c002007-12-08 20:04:36 +00001407 if ( !priv->secinfo.wep_enabled
1408 && !priv->secinfo.WPAenabled
1409 && !priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001410 ext->alg = IW_ENCODE_ALG_NONE;
1411 ext->key_len = 0;
1412 dwrq->flags |= IW_ENCODE_DISABLED;
1413 } else {
1414 u8 *key = NULL;
1415
David Woodhouseaa21c002007-12-08 20:04:36 +00001416 if ( priv->secinfo.wep_enabled
1417 && !priv->secinfo.WPAenabled
1418 && !priv->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001419 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001420 ext->alg = IW_ENCODE_ALG_WEP;
David Woodhouseaa21c002007-12-08 20:04:36 +00001421 ext->key_len = priv->wep_keys[index].len;
1422 key = &priv->wep_keys[index].key[0];
1423 } else if ( !priv->secinfo.wep_enabled
1424 && (priv->secinfo.WPAenabled ||
1425 priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001426 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001427 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001428
David Woodhouseaa21c002007-12-08 20:04:36 +00001429 if ( priv->wpa_mcast_key.len
1430 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1431 pkey = &priv->wpa_mcast_key;
1432 else if ( priv->wpa_unicast_key.len
1433 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1434 pkey = &priv->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001435
1436 if (pkey) {
1437 if (pkey->type == KEY_TYPE_ID_AES) {
1438 ext->alg = IW_ENCODE_ALG_CCMP;
1439 } else {
1440 ext->alg = IW_ENCODE_ALG_TKIP;
1441 }
1442 ext->key_len = pkey->len;
1443 key = &pkey->key[0];
1444 } else {
1445 ext->alg = IW_ENCODE_ALG_TKIP;
1446 ext->key_len = 0;
1447 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001448 } else {
1449 goto out;
1450 }
1451
1452 if (ext->key_len > max_key_len) {
1453 ret = -E2BIG;
1454 goto out;
1455 }
1456
1457 if (ext->key_len)
1458 memcpy(ext->key, key, ext->key_len);
1459 else
1460 dwrq->flags |= IW_ENCODE_NOKEY;
1461 dwrq->flags |= IW_ENCODE_ENABLED;
1462 }
1463 ret = 0;
1464
1465out:
Holger Schurig9012b282007-05-25 11:27:16 -04001466 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001467 return ret;
1468}
1469
1470/**
1471 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1472 *
1473 * @param dev A pointer to net_device structure
1474 * @param info A pointer to iw_request_info structure
1475 * @param vwrq A pointer to iw_param structure
1476 * @param extra A pointer to extra data buf
1477 * @return 0 --success, otherwise fail
1478 */
Holger Schurig10078322007-11-15 18:05:47 -05001479static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001480 struct iw_request_info *info,
1481 struct iw_point *dwrq,
1482 char *extra)
1483{
1484 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001485 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001486 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1487 int alg = ext->alg;
1488 struct assoc_request * assoc_req;
1489
Holger Schurig9012b282007-05-25 11:27:16 -04001490 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001491
David Woodhouseaa21c002007-12-08 20:04:36 +00001492 mutex_lock(&priv->lock);
1493 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001494 if (!assoc_req) {
1495 ret = -ENOMEM;
1496 goto out;
1497 }
1498
1499 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1500 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001501 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001502 } else if (alg == IW_ENCODE_ALG_WEP) {
1503 u16 is_default = 0, index, set_tx_key = 0;
1504
1505 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1506 (dwrq->flags & IW_ENCODE_INDEX),
1507 &index, &is_default);
1508 if (ret)
1509 goto out;
1510
1511 /* If WEP isn't enabled, or if there is no key data but a valid
1512 * index, or if the set-TX-key flag was passed, set the TX key.
1513 */
Dan Williams889c05b2007-05-10 22:57:23 -04001514 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001515 || (dwrq->length == 0 && !is_default)
1516 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1517 set_tx_key = 1;
1518
1519 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001520 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001521 set_tx_key);
1522 if (ret)
1523 goto out;
1524
1525 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001526 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001527 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001528 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001529 }
1530
1531 /* Mark the various WEP bits as modified */
1532 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1533 if (dwrq->length)
1534 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1535 if (set_tx_key)
1536 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001537 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001538 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001539
1540 /* validate key length */
1541 if (((alg == IW_ENCODE_ALG_TKIP)
1542 && (ext->key_len != KEY_LEN_WPA_TKIP))
1543 || ((alg == IW_ENCODE_ALG_CCMP)
1544 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001545 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001546 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001547 ext->key_len,
1548 alg);
1549 ret = -EINVAL;
1550 goto out;
1551 }
1552
Dan Williams90a42212007-05-25 23:01:24 -04001553 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001554 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001555 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1556 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001557 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001558 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1559 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560
Dan Williams1443b652007-08-02 10:45:55 -04001561 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001562 memcpy(pkey->key, ext->key, ext->key_len);
1563 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001564 if (pkey->len)
1565 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001566
Dan Williams90a42212007-05-25 23:01:24 -04001567 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001568 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1569 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001570 } else {
1571 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001572 }
1573
Dan Williams90a42212007-05-25 23:01:24 -04001574 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001575 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001576 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001577 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001578 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001579
1580 /* If WPA isn't enabled yet, do that now */
1581 if ( assoc_req->secinfo.WPAenabled == 0
1582 && assoc_req->secinfo.WPA2enabled == 0) {
1583 assoc_req->secinfo.WPAenabled = 1;
1584 assoc_req->secinfo.WPA2enabled = 1;
1585 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1586 }
1587
1588 disable_wep (assoc_req);
1589 }
1590
1591out:
1592 if (ret == 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001593 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001594 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001595 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001596 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001597 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001598
Holger Schurig9012b282007-05-25 11:27:16 -04001599 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001600 return ret;
1601}
1602
1603
Holger Schurig10078322007-11-15 18:05:47 -05001604static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001605 struct iw_request_info *info,
1606 struct iw_point *dwrq,
1607 char *extra)
1608{
Holger Schurig69f90322007-11-23 15:43:44 +01001609 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001610 int ret = 0;
1611 struct assoc_request * assoc_req;
1612
Holger Schurig9012b282007-05-25 11:27:16 -04001613 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001614
David Woodhouseaa21c002007-12-08 20:04:36 +00001615 mutex_lock(&priv->lock);
1616 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001617 if (!assoc_req) {
1618 ret = -ENOMEM;
1619 goto out;
1620 }
1621
1622 if (dwrq->length > MAX_WPA_IE_LEN ||
1623 (dwrq->length && extra == NULL)) {
1624 ret = -EINVAL;
1625 goto out;
1626 }
1627
1628 if (dwrq->length) {
1629 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1630 assoc_req->wpa_ie_len = dwrq->length;
1631 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001632 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001633 assoc_req->wpa_ie_len = 0;
1634 }
1635
1636out:
1637 if (ret == 0) {
1638 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001639 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001640 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001641 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001642 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001643 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001644
Holger Schurig9012b282007-05-25 11:27:16 -04001645 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001646 return ret;
1647}
1648
Holger Schurig10078322007-11-15 18:05:47 -05001649static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001650 struct iw_request_info *info,
1651 struct iw_point *dwrq,
1652 char *extra)
1653{
Holger Schurig9012b282007-05-25 11:27:16 -04001654 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001655 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001656
Holger Schurig9012b282007-05-25 11:27:16 -04001657 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001658
David Woodhouseaa21c002007-12-08 20:04:36 +00001659 if (priv->wpa_ie_len == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001660 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001661 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001662 }
1663
David Woodhouseaa21c002007-12-08 20:04:36 +00001664 if (dwrq->length < priv->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001665 ret = -E2BIG;
1666 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001667 }
1668
David Woodhouseaa21c002007-12-08 20:04:36 +00001669 dwrq->length = priv->wpa_ie_len;
1670 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001671
Holger Schurig9012b282007-05-25 11:27:16 -04001672out:
1673 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1674 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001675}
1676
1677
Holger Schurig10078322007-11-15 18:05:47 -05001678static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001679 struct iw_request_info *info,
1680 struct iw_param *dwrq,
1681 char *extra)
1682{
Holger Schurig69f90322007-11-23 15:43:44 +01001683 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001684 struct assoc_request * assoc_req;
1685 int ret = 0;
1686 int updated = 0;
1687
Holger Schurig9012b282007-05-25 11:27:16 -04001688 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001689
David Woodhouseaa21c002007-12-08 20:04:36 +00001690 mutex_lock(&priv->lock);
1691 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001692 if (!assoc_req) {
1693 ret = -ENOMEM;
1694 goto out;
1695 }
1696
1697 switch (dwrq->flags & IW_AUTH_INDEX) {
1698 case IW_AUTH_TKIP_COUNTERMEASURES:
1699 case IW_AUTH_CIPHER_PAIRWISE:
1700 case IW_AUTH_CIPHER_GROUP:
1701 case IW_AUTH_KEY_MGMT:
Dan Williams90a42212007-05-25 23:01:24 -04001702 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001703 /*
1704 * libertas does not use these parameters
1705 */
1706 break;
1707
1708 case IW_AUTH_WPA_VERSION:
1709 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1710 assoc_req->secinfo.WPAenabled = 0;
1711 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001712 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001713 }
1714 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1715 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001716 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001717 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001718 }
1719 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1720 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001721 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001722 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001723 }
1724 updated = 1;
1725 break;
1726
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001727 case IW_AUTH_80211_AUTH_ALG:
1728 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001729 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001730 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001731 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001732 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001733 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001734 } else {
1735 ret = -EINVAL;
1736 }
1737 updated = 1;
1738 break;
1739
1740 case IW_AUTH_WPA_ENABLED:
1741 if (dwrq->value) {
1742 if (!assoc_req->secinfo.WPAenabled &&
1743 !assoc_req->secinfo.WPA2enabled) {
1744 assoc_req->secinfo.WPAenabled = 1;
1745 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001746 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001747 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001748 }
1749 } else {
1750 assoc_req->secinfo.WPAenabled = 0;
1751 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001752 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001753 }
1754 updated = 1;
1755 break;
1756
1757 default:
1758 ret = -EOPNOTSUPP;
1759 break;
1760 }
1761
1762out:
1763 if (ret == 0) {
1764 if (updated)
1765 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001766 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001767 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001768 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001769 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001770 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001771
Holger Schurig9012b282007-05-25 11:27:16 -04001772 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001773 return ret;
1774}
1775
Holger Schurig10078322007-11-15 18:05:47 -05001776static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001777 struct iw_request_info *info,
1778 struct iw_param *dwrq,
1779 char *extra)
1780{
Holger Schurig9012b282007-05-25 11:27:16 -04001781 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001782 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001783
Holger Schurig9012b282007-05-25 11:27:16 -04001784 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001785
1786 switch (dwrq->flags & IW_AUTH_INDEX) {
1787 case IW_AUTH_WPA_VERSION:
1788 dwrq->value = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +00001789 if (priv->secinfo.WPAenabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001790 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
David Woodhouseaa21c002007-12-08 20:04:36 +00001791 if (priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001792 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1793 if (!dwrq->value)
1794 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1795 break;
1796
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001797 case IW_AUTH_80211_AUTH_ALG:
David Woodhouseaa21c002007-12-08 20:04:36 +00001798 dwrq->value = priv->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001799 break;
1800
1801 case IW_AUTH_WPA_ENABLED:
David Woodhouseaa21c002007-12-08 20:04:36 +00001802 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001803 dwrq->value = 1;
1804 break;
1805
1806 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001807 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001808 }
1809
Holger Schurig9012b282007-05-25 11:27:16 -04001810 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1811 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001812}
1813
1814
Holger Schurig10078322007-11-15 18:05:47 -05001815static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816 struct iw_param *vwrq, char *extra)
1817{
1818 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001819 struct lbs_private *priv = dev->priv;
Dan Williams87c8c722008-08-19 15:15:35 -04001820 s16 dbm = (s16) vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001821
Holger Schurig9012b282007-05-25 11:27:16 -04001822 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001823
1824 if (vwrq->disabled) {
Dan Williamsd5db2df2008-08-21 17:51:07 -04001825 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
Dan Williams87c8c722008-08-19 15:15:35 -04001826 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001827 }
1828
Dan Williams87c8c722008-08-19 15:15:35 -04001829 if (vwrq->fixed == 0) {
Anna Neal0112c9e2008-09-11 11:17:25 -07001830 /* User requests automatic tx power control, however there are
1831 * many auto tx settings. For now use firmware defaults until
1832 * we come up with a good way to expose these to the user. */
1833 if (priv->fwrelease < 0x09000000) {
1834 ret = lbs_set_power_adapt_cfg(priv, 1,
1835 POW_ADAPT_DEFAULT_P0,
1836 POW_ADAPT_DEFAULT_P1,
1837 POW_ADAPT_DEFAULT_P2);
1838 if (ret)
1839 goto out;
1840 }
1841 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1842 TPC_DEFAULT_P2, 1);
1843 if (ret)
1844 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001845 dbm = priv->txpower_max;
1846 } else {
1847 /* Userspace check in iwrange if it should use dBm or mW,
1848 * therefore this should never happen... Jean II */
1849 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1850 ret = -EOPNOTSUPP;
1851 goto out;
1852 }
1853
Anna Neal0112c9e2008-09-11 11:17:25 -07001854 /* Validate requested power level against firmware allowed
1855 * levels */
Dan Williams87c8c722008-08-19 15:15:35 -04001856 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1857 ret = -EINVAL;
1858 goto out;
1859 }
1860
1861 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1862 ret = -EINVAL;
1863 goto out;
1864 }
Anna Neal0112c9e2008-09-11 11:17:25 -07001865 if (priv->fwrelease < 0x09000000) {
1866 ret = lbs_set_power_adapt_cfg(priv, 0,
1867 POW_ADAPT_DEFAULT_P0,
1868 POW_ADAPT_DEFAULT_P1,
1869 POW_ADAPT_DEFAULT_P2);
1870 if (ret)
1871 goto out;
1872 }
1873 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1874 TPC_DEFAULT_P2, 1);
1875 if (ret)
1876 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001877 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001878
Dan Williamsd5db2df2008-08-21 17:51:07 -04001879 /* If the radio was off, turn it on */
1880 if (!priv->radio_on) {
1881 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
1882 if (ret)
1883 goto out;
1884 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001885
Dan Williams87c8c722008-08-19 15:15:35 -04001886 lbs_deb_wext("txpower set %d dBm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001887
Dan Williams87c8c722008-08-19 15:15:35 -04001888 ret = lbs_set_tx_power(priv, dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001889
Dan Williams87c8c722008-08-19 15:15:35 -04001890out:
Holger Schurig9012b282007-05-25 11:27:16 -04001891 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001892 return ret;
1893}
1894
Holger Schurig10078322007-11-15 18:05:47 -05001895static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001896 struct iw_point *dwrq, char *extra)
1897{
Holger Schurig69f90322007-11-23 15:43:44 +01001898 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001899
Holger Schurig9012b282007-05-25 11:27:16 -04001900 lbs_deb_enter(LBS_DEB_WEXT);
1901
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001902 /*
1903 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1904 * the SSID list...
1905 */
1906
1907 /*
1908 * Get the current SSID
1909 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001910 if (priv->connect_status == LBS_CONNECTED) {
1911 memcpy(extra, priv->curbssparams.ssid,
1912 priv->curbssparams.ssid_len);
1913 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001914 } else {
1915 memset(extra, 0, 32);
David Woodhouseaa21c002007-12-08 20:04:36 +00001916 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001917 }
1918 /*
1919 * If none, we may want to get the one that was set
1920 */
1921
David Woodhouseaa21c002007-12-08 20:04:36 +00001922 dwrq->length = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001923
1924 dwrq->flags = 1; /* active */
1925
Holger Schurig9012b282007-05-25 11:27:16 -04001926 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001927 return 0;
1928}
1929
Holger Schurig10078322007-11-15 18:05:47 -05001930static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001931 struct iw_point *dwrq, char *extra)
1932{
Holger Schurig69f90322007-11-23 15:43:44 +01001933 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001934 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04001935 u8 ssid[IW_ESSID_MAX_SIZE];
1936 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001937 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001938 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001939
Holger Schurig9012b282007-05-25 11:27:16 -04001940 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001941
Dan Williamsd5db2df2008-08-21 17:51:07 -04001942 if (!priv->radio_on) {
1943 ret = -EINVAL;
1944 goto out;
1945 }
1946
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001947 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001948 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001949 ret = -E2BIG;
1950 goto out;
1951 }
1952
Dan Williamsd8efea22007-05-28 23:54:55 -04001953 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001954
Dan Williamsd8efea22007-05-28 23:54:55 -04001955 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001956 /* "any" SSID requested; leave SSID blank */
1957 } else {
1958 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04001959 memcpy(&ssid, extra, in_ssid_len);
1960 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001961 }
1962
Dan Williamsd8efea22007-05-28 23:54:55 -04001963 if (!ssid_len) {
1964 lbs_deb_wext("requested any SSID\n");
1965 } else {
1966 lbs_deb_wext("requested SSID '%s'\n",
1967 escape_essid(ssid, ssid_len));
1968 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001969
1970out:
David Woodhouseaa21c002007-12-08 20:04:36 +00001971 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001972 if (ret == 0) {
1973 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00001974 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001975 if (!assoc_req) {
1976 ret = -ENOMEM;
1977 } else {
1978 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04001979 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1980 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001981 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001982 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001983 }
1984 }
1985
1986 /* Cancel the association request if there was an error */
1987 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001988 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001989 }
1990
David Woodhouseaa21c002007-12-08 20:04:36 +00001991 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001992
Holger Schurig9012b282007-05-25 11:27:16 -04001993 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001994 return ret;
1995}
1996
David Woodhousef5956bf2007-12-11 19:30:57 -05001997static int lbs_mesh_get_essid(struct net_device *dev,
1998 struct iw_request_info *info,
1999 struct iw_point *dwrq, char *extra)
2000{
2001 struct lbs_private *priv = dev->priv;
2002
2003 lbs_deb_enter(LBS_DEB_WEXT);
2004
2005 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2006
2007 dwrq->length = priv->mesh_ssid_len;
2008
2009 dwrq->flags = 1; /* active */
2010
2011 lbs_deb_leave(LBS_DEB_WEXT);
2012 return 0;
2013}
2014
2015static int lbs_mesh_set_essid(struct net_device *dev,
2016 struct iw_request_info *info,
2017 struct iw_point *dwrq, char *extra)
2018{
2019 struct lbs_private *priv = dev->priv;
2020 int ret = 0;
2021
2022 lbs_deb_enter(LBS_DEB_WEXT);
2023
Dan Williamsd5db2df2008-08-21 17:51:07 -04002024 if (!priv->radio_on) {
2025 ret = -EINVAL;
2026 goto out;
2027 }
2028
David Woodhousef5956bf2007-12-11 19:30:57 -05002029 /* Check the size of the string */
2030 if (dwrq->length > IW_ESSID_MAX_SIZE) {
2031 ret = -E2BIG;
2032 goto out;
2033 }
2034
2035 if (!dwrq->flags || !dwrq->length) {
2036 ret = -EINVAL;
2037 goto out;
2038 } else {
2039 /* Specific SSID requested */
2040 memcpy(priv->mesh_ssid, extra, dwrq->length);
2041 priv->mesh_ssid_len = dwrq->length;
2042 }
2043
Javier Cardonaedaea5c2008-05-17 00:55:10 -07002044 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
2045 priv->curbssparams.channel);
David Woodhousef5956bf2007-12-11 19:30:57 -05002046 out:
2047 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2048 return ret;
2049}
2050
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002051/**
2052 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2053 *
2054 * @param dev A pointer to net_device structure
2055 * @param info A pointer to iw_request_info structure
2056 * @param awrq A pointer to iw_param structure
2057 * @param extra A pointer to extra data buf
2058 * @return 0 --success, otherwise fail
2059 */
Holger Schurig10078322007-11-15 18:05:47 -05002060static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002061 struct sockaddr *awrq, char *extra)
2062{
Holger Schurig69f90322007-11-23 15:43:44 +01002063 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002064 struct assoc_request * assoc_req;
2065 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07002066 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002067
Holger Schurig9012b282007-05-25 11:27:16 -04002068 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002069
Dan Williamsd5db2df2008-08-21 17:51:07 -04002070 if (!priv->radio_on)
2071 return -EINVAL;
2072
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002073 if (awrq->sa_family != ARPHRD_ETHER)
2074 return -EINVAL;
2075
Joe Perches0795af52007-10-03 17:59:30 -07002076 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002077
David Woodhouseaa21c002007-12-08 20:04:36 +00002078 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002079
2080 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002081 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002082 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05002083 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002084 ret = -ENOMEM;
2085 } else {
2086 /* Copy the BSSID to the association request */
2087 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2088 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002089 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002090 }
2091
David Woodhouseaa21c002007-12-08 20:04:36 +00002092 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002093
2094 return ret;
2095}
2096
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002097/*
2098 * iwconfig settable callbacks
2099 */
Holger Schurig10078322007-11-15 18:05:47 -05002100static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002101 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002102 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002103 (iw_handler) NULL, /* SIOCSIWNWID */
2104 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002105 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2106 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2107 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2108 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002109 (iw_handler) NULL, /* SIOCSIWSENS */
2110 (iw_handler) NULL, /* SIOCGIWSENS */
2111 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002112 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002113 (iw_handler) NULL, /* SIOCSIWPRIV */
2114 (iw_handler) NULL, /* SIOCGIWPRIV */
2115 (iw_handler) NULL, /* SIOCSIWSTATS */
2116 (iw_handler) NULL, /* SIOCGIWSTATS */
2117 iw_handler_set_spy, /* SIOCSIWSPY */
2118 iw_handler_get_spy, /* SIOCGIWSPY */
2119 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2120 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002121 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2122 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002123 (iw_handler) NULL, /* SIOCSIWMLME */
2124 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002125 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2126 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2127 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2128 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2129 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2130 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002131 (iw_handler) NULL, /* -- hole -- */
2132 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002133 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2134 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2135 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2136 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2137 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2138 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2139 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2140 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2141 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2142 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2143 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2144 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2145 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2146 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002147 (iw_handler) NULL, /* -- hole -- */
2148 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002149 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2150 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2151 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2152 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2153 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2154 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002155 (iw_handler) NULL, /* SIOCSIWPMKSA */
2156};
2157
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002158static const iw_handler mesh_wlan_handler[] = {
2159 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002160 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002161 (iw_handler) NULL, /* SIOCSIWNWID */
2162 (iw_handler) NULL, /* SIOCGIWNWID */
David Woodhouse823eaa22007-12-11 19:56:28 -05002163 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
Holger Schurig10078322007-11-15 18:05:47 -05002164 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002165 (iw_handler) NULL, /* SIOCSIWMODE */
2166 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2167 (iw_handler) NULL, /* SIOCSIWSENS */
2168 (iw_handler) NULL, /* SIOCGIWSENS */
2169 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002170 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002171 (iw_handler) NULL, /* SIOCSIWPRIV */
2172 (iw_handler) NULL, /* SIOCGIWPRIV */
2173 (iw_handler) NULL, /* SIOCSIWSTATS */
2174 (iw_handler) NULL, /* SIOCGIWSTATS */
2175 iw_handler_set_spy, /* SIOCSIWSPY */
2176 iw_handler_get_spy, /* SIOCGIWSPY */
2177 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2178 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2179 (iw_handler) NULL, /* SIOCSIWAP */
2180 (iw_handler) NULL, /* SIOCGIWAP */
2181 (iw_handler) NULL, /* SIOCSIWMLME */
2182 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002183 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2184 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
David Woodhousef5956bf2007-12-11 19:30:57 -05002185 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2186 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002187 (iw_handler) NULL, /* SIOCSIWNICKN */
2188 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2189 (iw_handler) NULL, /* -- hole -- */
2190 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002191 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2192 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2193 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2194 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2195 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2196 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2197 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2198 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2199 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2200 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2201 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2202 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2203 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2204 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002205 (iw_handler) NULL, /* -- hole -- */
2206 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002207 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2208 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2209 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2210 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2211 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2212 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002213 (iw_handler) NULL, /* SIOCSIWPMKSA */
2214};
Holger Schurig10078322007-11-15 18:05:47 -05002215struct iw_handler_def lbs_handler_def = {
2216 .num_standard = ARRAY_SIZE(lbs_handler),
2217 .standard = (iw_handler *) lbs_handler,
2218 .get_wireless_stats = lbs_get_wireless_stats,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002219};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002220
2221struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002222 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002223 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002224 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002225};