blob: e8cadad2c863acd8e11334287a93dd395121c527 [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;
David Woodhouse981f1872007-05-25 23:36:54 -0400269 u32 rthr = 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
273 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000274 priv->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200275 } else {
276 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
277 return -EINVAL;
David Woodhouseaa21c002007-12-08 20:04:36 +0000278 priv->rtsthsd = rthr;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200279 }
280
Holger Schurig10078322007-11-15 18:05:47 -0500281 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400282 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200283 OID_802_11_RTS_THRESHOLD, &rthr);
284
Holger Schurig9012b282007-05-25 11:27:16 -0400285 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286 return ret;
287}
288
Holger Schurig10078322007-11-15 18:05:47 -0500289static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200290 struct iw_param *vwrq, char *extra)
291{
292 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100293 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200294
Holger Schurig9012b282007-05-25 11:27:16 -0400295 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200296
David Woodhouseaa21c002007-12-08 20:04:36 +0000297 priv->rtsthsd = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500298 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400299 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300 OID_802_11_RTS_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400301 if (ret)
302 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200303
David Woodhouseaa21c002007-12-08 20:04:36 +0000304 vwrq->value = priv->rtsthsd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200305 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
306 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
307 vwrq->fixed = 1;
308
Holger Schurig9012b282007-05-25 11:27:16 -0400309out:
310 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
311 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312}
313
Holger Schurig10078322007-11-15 18:05:47 -0500314static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200315 struct iw_param *vwrq, char *extra)
316{
317 int ret = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400318 u32 fthr = vwrq->value;
Holger Schurig69f90322007-11-23 15:43:44 +0100319 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200320
Holger Schurig9012b282007-05-25 11:27:16 -0400321 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200322
323 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000324 priv->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200325 } else {
326 if (fthr < MRVDRV_FRAG_MIN_VALUE
327 || fthr > MRVDRV_FRAG_MAX_VALUE)
328 return -EINVAL;
David Woodhouseaa21c002007-12-08 20:04:36 +0000329 priv->fragthsd = fthr;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200330 }
331
Holger Schurig10078322007-11-15 18:05:47 -0500332 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400333 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
Holger Schurig9012b282007-05-25 11:27:16 -0400335
336 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200337 return ret;
338}
339
Holger Schurig10078322007-11-15 18:05:47 -0500340static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200341 struct iw_param *vwrq, char *extra)
342{
343 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100344 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200345
Holger Schurig9012b282007-05-25 11:27:16 -0400346 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200347
David Woodhouseaa21c002007-12-08 20:04:36 +0000348 priv->fragthsd = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500349 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400350 CMD_802_11_SNMP_MIB,
351 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400353 if (ret)
354 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200355
David Woodhouseaa21c002007-12-08 20:04:36 +0000356 vwrq->value = priv->fragthsd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
358 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
359 vwrq->fixed = 1;
360
Holger Schurig9012b282007-05-25 11:27:16 -0400361out:
362 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200363 return ret;
364}
365
Holger Schurig10078322007-11-15 18:05:47 -0500366static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200367 struct iw_request_info *info, u32 * uwrq, char *extra)
368{
Holger Schurig69f90322007-11-23 15:43:44 +0100369 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370
Holger Schurig9012b282007-05-25 11:27:16 -0400371 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200372
David Woodhouseaa21c002007-12-08 20:04:36 +0000373 *uwrq = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200374
Holger Schurig9012b282007-05-25 11:27:16 -0400375 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376 return 0;
377}
378
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400379static int mesh_wlan_get_mode(struct net_device *dev,
380 struct iw_request_info *info, u32 * uwrq,
381 char *extra)
382{
383 lbs_deb_enter(LBS_DEB_WEXT);
384
385 *uwrq = IW_MODE_REPEAT ;
386
387 lbs_deb_leave(LBS_DEB_WEXT);
388 return 0;
389}
390
Holger Schurig10078322007-11-15 18:05:47 -0500391static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392 struct iw_request_info *info,
393 struct iw_param *vwrq, char *extra)
394{
Holger Schurig69f90322007-11-23 15:43:44 +0100395 struct lbs_private *priv = dev->priv;
Dan Williams87c8c722008-08-19 15:15:35 -0400396 s16 curlevel = 0;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400397 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200398
Holger Schurig9012b282007-05-25 11:27:16 -0400399 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400
Dan Williamsd5db2df2008-08-21 17:51:07 -0400401 if (!priv->radio_on) {
402 lbs_deb_wext("tx power off\n");
403 vwrq->value = 0;
404 vwrq->disabled = 1;
405 goto out;
406 }
407
Dan Williams87c8c722008-08-19 15:15:35 -0400408 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400409 if (ret)
410 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200411
Dan Williams87c8c722008-08-19 15:15:35 -0400412 lbs_deb_wext("tx power level %d dbm\n", curlevel);
Dan Williams87c8c722008-08-19 15:15:35 -0400413 priv->txpower_cur = curlevel;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400414
Dan Williams87c8c722008-08-19 15:15:35 -0400415 vwrq->value = curlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200416 vwrq->fixed = 1;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400417 vwrq->disabled = 0;
418 vwrq->flags = IW_TXPOW_DBM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419
Holger Schurig9012b282007-05-25 11:27:16 -0400420out:
421 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
422 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200423}
424
Holger Schurig10078322007-11-15 18:05:47 -0500425static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426 struct iw_param *vwrq, char *extra)
427{
428 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100429 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200430
Holger Schurig9012b282007-05-25 11:27:16 -0400431 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200432
433 if (vwrq->flags == IW_RETRY_LIMIT) {
434 /* The MAC has a 4-bit Total_Tx_Count register
435 Total_Tx_Count = 1 + Tx_Retry_Count */
436#define TX_RETRY_MIN 0
437#define TX_RETRY_MAX 14
438 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
439 return -EINVAL;
440
441 /* Adding 1 to convert retry count to try count */
David Woodhouseaa21c002007-12-08 20:04:36 +0000442 priv->txretrycount = vwrq->value + 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200443
Holger Schurig10078322007-11-15 18:05:47 -0500444 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
Dan Williams0aef64d2007-08-02 11:31:18 -0400445 CMD_ACT_SET,
446 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200447 OID_802_11_TX_RETRYCOUNT, NULL);
448
Holger Schurig9012b282007-05-25 11:27:16 -0400449 if (ret)
450 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200451 } else {
452 return -EOPNOTSUPP;
453 }
454
Holger Schurig9012b282007-05-25 11:27:16 -0400455out:
456 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
457 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200458}
459
Holger Schurig10078322007-11-15 18:05:47 -0500460static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200461 struct iw_param *vwrq, char *extra)
462{
Holger Schurig69f90322007-11-23 15:43:44 +0100463 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464 int ret = 0;
465
Holger Schurig9012b282007-05-25 11:27:16 -0400466 lbs_deb_enter(LBS_DEB_WEXT);
467
David Woodhouseaa21c002007-12-08 20:04:36 +0000468 priv->txretrycount = 0;
Holger Schurig10078322007-11-15 18:05:47 -0500469 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400470 CMD_802_11_SNMP_MIB,
471 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472 OID_802_11_TX_RETRYCOUNT, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400473 if (ret)
474 goto out;
475
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 vwrq->disabled = 0;
477 if (!vwrq->flags) {
478 vwrq->flags = IW_RETRY_LIMIT;
479 /* Subtract 1 to convert try count to retry count */
David Woodhouseaa21c002007-12-08 20:04:36 +0000480 vwrq->value = priv->txretrycount - 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481 }
482
Holger Schurig9012b282007-05-25 11:27:16 -0400483out:
484 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
485 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200486}
487
488static inline void sort_channels(struct iw_freq *freq, int num)
489{
490 int i, j;
491 struct iw_freq temp;
492
493 for (i = 0; i < num; i++)
494 for (j = i + 1; j < num; j++)
495 if (freq[i].i > freq[j].i) {
496 temp.i = freq[i].i;
497 temp.m = freq[i].m;
498
499 freq[i].i = freq[j].i;
500 freq[i].m = freq[j].m;
501
502 freq[j].i = temp.i;
503 freq[j].m = temp.m;
504 }
505}
506
507/* data rate listing
508 MULTI_BANDS:
509 abg a b b/g
510 Infra G(12) A(8) B(4) G(12)
511 Adhoc A+B(12) A(8) B(4) B(4)
512
513 non-MULTI_BANDS:
514 b b/g
515 Infra B(4) G(12)
516 Adhoc B(4) B(4)
517 */
518/**
519 * @brief Get Range Info
520 *
521 * @param dev A pointer to net_device structure
522 * @param info A pointer to iw_request_info structure
523 * @param vwrq A pointer to iw_param structure
524 * @param extra A pointer to extra data buf
525 * @return 0 --success, otherwise fail
526 */
Holger Schurig10078322007-11-15 18:05:47 -0500527static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528 struct iw_point *dwrq, char *extra)
529{
530 int i, j;
Holger Schurig69f90322007-11-23 15:43:44 +0100531 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200532 struct iw_range *range = (struct iw_range *)extra;
533 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400534 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200535
536 u8 flag = 0;
537
Holger Schurig9012b282007-05-25 11:27:16 -0400538 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200539
540 dwrq->length = sizeof(struct iw_range);
541 memset(range, 0, sizeof(struct iw_range));
542
543 range->min_nwid = 0;
544 range->max_nwid = 0;
545
546 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000547 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400548 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
549 for (i = 0; i < range->num_bitrates; i++)
550 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200551 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400552 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553 range->num_bitrates);
554
555 range->num_frequency = 0;
Holger Schurig52933d82008-03-05 07:05:32 +0100556
557 range->scan_capa = IW_SCAN_CAPA_ESSID;
558
David Woodhouseaa21c002007-12-08 20:04:36 +0000559 if (priv->enable11d &&
560 (priv->connect_status == LBS_CONNECTED ||
561 priv->mesh_connect_status == LBS_CONNECTED)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200562 u8 chan_no;
563 u8 band;
564
565 struct parsed_region_chan_11d *parsed_region_chan =
David Woodhouseaa21c002007-12-08 20:04:36 +0000566 &priv->parsed_region_chan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567
568 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400569 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
570 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200571 }
572 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400573 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200574 parsed_region_chan->nr_chan);
575
576 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
577 && (i < parsed_region_chan->nr_chan); i++) {
578 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400579 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200580 range->freq[range->num_frequency].i = (long)chan_no;
581 range->freq[range->num_frequency].m =
Holger Schurige98a88d2008-03-19 14:25:58 +0100582 (long)lbs_chan_2_freq(chan_no) * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200583 range->freq[range->num_frequency].e = 1;
584 range->num_frequency++;
585 }
586 flag = 1;
587 }
588 if (!flag) {
589 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000590 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
591 cfp = priv->region_channel[j].CFP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200592 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000593 && priv->region_channel[j].valid
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200594 && cfp
David Woodhouseaa21c002007-12-08 20:04:36 +0000595 && (i < priv->region_channel[j].nrcfp); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200596 range->freq[range->num_frequency].i =
597 (long)cfp->channel;
598 range->freq[range->num_frequency].m =
599 (long)cfp->freq * 100000;
600 range->freq[range->num_frequency].e = 1;
601 cfp++;
602 range->num_frequency++;
603 }
604 }
605 }
606
Holger Schurig9012b282007-05-25 11:27:16 -0400607 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608 IW_MAX_FREQUENCIES, range->num_frequency);
609
610 range->num_channels = range->num_frequency;
611
612 sort_channels(&range->freq[0], range->num_frequency);
613
614 /*
615 * Set an indication of the max TCP throughput in bit/s that we can
616 * expect using this interface
617 */
618 if (i > 2)
619 range->throughput = 5000 * 1000;
620 else
621 range->throughput = 1500 * 1000;
622
623 range->min_rts = MRVDRV_RTS_MIN_VALUE;
624 range->max_rts = MRVDRV_RTS_MAX_VALUE;
625 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
626 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
627
628 range->encoding_size[0] = 5;
629 range->encoding_size[1] = 13;
630 range->num_encoding_sizes = 2;
631 range->max_encoding_tokens = 4;
632
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100633 /*
634 * Right now we support only "iwconfig ethX power on|off"
635 */
636 range->pm_capa = IW_POWER_ON;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200637
638 /*
639 * Minimum version we recommend
640 */
641 range->we_version_source = 15;
642
643 /*
644 * Version we are compiled with
645 */
646 range->we_version_compiled = WIRELESS_EXT;
647
648 range->retry_capa = IW_RETRY_LIMIT;
649 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
650
651 range->min_retry = TX_RETRY_MIN;
652 range->max_retry = TX_RETRY_MAX;
653
654 /*
655 * Set the qual, level and noise range values
656 */
657 range->max_qual.qual = 100;
658 range->max_qual.level = 0;
659 range->max_qual.noise = 0;
660 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
661
662 range->avg_qual.qual = 70;
663 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
664 range->avg_qual.level = 0;
665 range->avg_qual.noise = 0;
666 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
667
668 range->sensitivity = 0;
669
Dan Williams87c8c722008-08-19 15:15:35 -0400670 /* Setup the supported power level ranges */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200671 memset(range->txpower, 0, sizeof(range->txpower));
Dan Williams87c8c722008-08-19 15:15:35 -0400672 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
673 range->txpower[0] = priv->txpower_min;
674 range->txpower[1] = priv->txpower_max;
675 range->num_txpower = 2;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200676
677 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
678 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
679 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
680 range->event_capa[1] = IW_EVENT_CAPA_K_1;
681
David Woodhouseaa21c002007-12-08 20:04:36 +0000682 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200683 range->enc_capa = IW_ENC_CAPA_WPA
684 | IW_ENC_CAPA_WPA2
685 | IW_ENC_CAPA_CIPHER_TKIP
686 | IW_ENC_CAPA_CIPHER_CCMP;
687 }
688
Holger Schurig9012b282007-05-25 11:27:16 -0400689out:
690 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200691 return 0;
692}
693
Holger Schurig10078322007-11-15 18:05:47 -0500694static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200695 struct iw_param *vwrq, char *extra)
696{
Holger Schurig69f90322007-11-23 15:43:44 +0100697 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200698
Holger Schurig9012b282007-05-25 11:27:16 -0400699 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200700
David Woodhouseb2c57ee2007-12-17 14:41:13 -0500701 if (!priv->ps_supported) {
702 if (vwrq->disabled)
703 return 0;
704 else
705 return -EINVAL;
706 }
707
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200708 /* PS is currently supported only in Infrastructure mode
709 * Remove this check if it is to be supported in IBSS mode also
710 */
711
712 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000713 priv->psmode = LBS802_11POWERMODECAM;
714 if (priv->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500715 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200716 }
717
718 return 0;
719 }
720
721 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400722 lbs_deb_wext(
723 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724 return -EINVAL;
725 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400726 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200727 return -EINVAL;
728 }
729
David Woodhouseaa21c002007-12-08 20:04:36 +0000730 if (priv->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731 return 0;
732 }
733
David Woodhouseaa21c002007-12-08 20:04:36 +0000734 priv->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200735
David Woodhouseaa21c002007-12-08 20:04:36 +0000736 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500737 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200738 }
739
Holger Schurig9012b282007-05-25 11:27:16 -0400740 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741 return 0;
742}
743
Holger Schurig10078322007-11-15 18:05:47 -0500744static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745 struct iw_param *vwrq, char *extra)
746{
Holger Schurig69f90322007-11-23 15:43:44 +0100747 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200748
Holger Schurig9012b282007-05-25 11:27:16 -0400749 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200750
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200751 vwrq->value = 0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100752 vwrq->flags = 0;
753 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
754 || priv->connect_status == LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200755
Holger Schurig9012b282007-05-25 11:27:16 -0400756 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200757 return 0;
758}
759
Holger Schurig10078322007-11-15 18:05:47 -0500760static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200761{
762 enum {
763 POOR = 30,
764 FAIR = 60,
765 GOOD = 80,
766 VERY_GOOD = 90,
767 EXCELLENT = 95,
768 PERFECT = 100
769 };
Holger Schurig69f90322007-11-23 15:43:44 +0100770 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200771 u32 rssi_qual;
772 u32 tx_qual;
773 u32 quality = 0;
774 int stats_valid = 0;
775 u8 rssi;
776 u32 tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100777 struct cmd_ds_802_11_get_log log;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778
Holger Schurig9012b282007-05-25 11:27:16 -0400779 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200780
David Woodhouseaa21c002007-12-08 20:04:36 +0000781 priv->wstats.status = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200782
783 /* If we're not associated, all quality values are meaningless */
David Woodhouseaa21c002007-12-08 20:04:36 +0000784 if ((priv->connect_status != LBS_CONNECTED) &&
785 (priv->mesh_connect_status != LBS_CONNECTED))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200786 goto out;
787
788 /* Quality by RSSI */
789 priv->wstats.qual.level =
David Woodhouseaa21c002007-12-08 20:04:36 +0000790 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
791 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200792
David Woodhouseaa21c002007-12-08 20:04:36 +0000793 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200794 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
795 } else {
796 priv->wstats.qual.noise =
David Woodhouseaa21c002007-12-08 20:04:36 +0000797 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200798 }
799
Holger Schurig9012b282007-05-25 11:27:16 -0400800 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
801 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200802
803 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
804 if (rssi < 15)
805 rssi_qual = rssi * POOR / 10;
806 else if (rssi < 20)
807 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
808 else if (rssi < 30)
809 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
810 else if (rssi < 40)
811 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
812 10 + GOOD;
813 else
814 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
815 10 + VERY_GOOD;
816 quality = rssi_qual;
817
818 /* Quality by TX errors */
819 priv->wstats.discard.retries = priv->stats.tx_errors;
820
Holger Schurigc49c3b72008-03-17 12:45:58 +0100821 memset(&log, 0, sizeof(log));
822 log.hdr.size = cpu_to_le16(sizeof(log));
823 lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
824
825 tx_retries = le32_to_cpu(log.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200826
827 if (tx_retries > 75)
828 tx_qual = (90 - tx_retries) * POOR / 15;
829 else if (tx_retries > 70)
830 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
831 else if (tx_retries > 65)
832 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
833 else if (tx_retries > 50)
834 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
835 15 + GOOD;
836 else
837 tx_qual = (50 - tx_retries) *
838 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
839 quality = min(quality, tx_qual);
840
Holger Schurigc49c3b72008-03-17 12:45:58 +0100841 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200842 priv->wstats.discard.retries = tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100843 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200844
845 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400846 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200847 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
848 stats_valid = 1;
849
850 /* update stats asynchronously for future calls */
Holger Schurig10078322007-11-15 18:05:47 -0500851 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200852 0, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200853out:
854 if (!stats_valid) {
855 priv->wstats.miss.beacon = 0;
856 priv->wstats.discard.retries = 0;
857 priv->wstats.qual.qual = 0;
858 priv->wstats.qual.level = 0;
859 priv->wstats.qual.noise = 0;
860 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
861 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
862 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
863 }
864
Holger Schurig9012b282007-05-25 11:27:16 -0400865 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200866 return &priv->wstats;
867
868
869}
870
Holger Schurig10078322007-11-15 18:05:47 -0500871static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200872 struct iw_freq *fwrq, char *extra)
873{
Dan Williamsef9a2642007-05-25 16:46:33 -0400874 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +0100875 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200876 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400877 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200878
Holger Schurig9012b282007-05-25 11:27:16 -0400879 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200880
David Woodhouseaa21c002007-12-08 20:04:36 +0000881 mutex_lock(&priv->lock);
882 assoc_req = lbs_get_association_request(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400883 if (!assoc_req) {
884 ret = -ENOMEM;
885 goto out;
886 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200887
Dan Williamsef9a2642007-05-25 16:46:33 -0400888 /* If setting by frequency, convert to a channel */
889 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200890 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200891
David Woodhouseaa21c002007-12-08 20:04:36 +0000892 cfp = find_cfp_by_band_and_freq(priv, 0, f);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200893 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400894 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400895 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200896 }
897
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200898 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400899 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200900 }
901
Dan Williamsef9a2642007-05-25 16:46:33 -0400902 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200903 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400904 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905 }
906
David Woodhouseaa21c002007-12-08 20:04:36 +0000907 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400908 if (!cfp) {
909 goto out;
910 }
911
912 assoc_req->channel = fwrq->m;
913 ret = 0;
914
Holger Schurig9012b282007-05-25 11:27:16 -0400915out:
Dan Williamsef9a2642007-05-25 16:46:33 -0400916 if (ret == 0) {
917 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500918 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400919 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500920 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400921 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000922 mutex_unlock(&priv->lock);
Dan Williamsef9a2642007-05-25 16:46:33 -0400923
924 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
925 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200926}
927
David Woodhouse823eaa22007-12-11 19:56:28 -0500928static int lbs_mesh_set_freq(struct net_device *dev,
929 struct iw_request_info *info,
930 struct iw_freq *fwrq, char *extra)
931{
932 struct lbs_private *priv = dev->priv;
933 struct chan_freq_power *cfp;
934 int ret = -EINVAL;
935
936 lbs_deb_enter(LBS_DEB_WEXT);
937
938 /* If setting by frequency, convert to a channel */
939 if (fwrq->e == 1) {
940 long f = fwrq->m / 100000;
941
942 cfp = find_cfp_by_band_and_freq(priv, 0, f);
943 if (!cfp) {
944 lbs_deb_wext("invalid freq %ld\n", f);
945 goto out;
946 }
947
948 fwrq->e = 0;
949 fwrq->m = (int) cfp->channel;
950 }
951
952 /* Setting by channel number */
953 if (fwrq->m > 1000 || fwrq->e > 0) {
954 goto out;
955 }
956
957 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
958 if (!cfp) {
959 goto out;
960 }
961
962 if (fwrq->m != priv->curbssparams.channel) {
963 lbs_deb_wext("mesh channel change forces eth disconnect\n");
964 if (priv->mode == IW_MODE_INFRA)
Dan Williams191bb402008-08-21 17:46:18 -0400965 lbs_cmd_80211_deauthenticate(priv,
966 priv->curbssparams.bssid,
967 WLAN_REASON_DEAUTH_LEAVING);
David Woodhouse823eaa22007-12-11 19:56:28 -0500968 else if (priv->mode == IW_MODE_ADHOC)
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400969 lbs_adhoc_stop(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -0500970 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700971 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
David Woodhouse86062132007-12-13 00:32:36 -0500972 lbs_update_channel(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -0500973 ret = 0;
974
975out:
976 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
977 return ret;
978}
979
Holger Schurig10078322007-11-15 18:05:47 -0500980static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200981 struct iw_param *vwrq, char *extra)
982{
Holger Schurig69f90322007-11-23 15:43:44 +0100983 struct lbs_private *priv = dev->priv;
Dan Williams8e3c91b2007-12-11 15:50:59 -0500984 u8 new_rate = 0;
Dan Williams8c512762007-08-02 11:40:45 -0400985 int ret = -EINVAL;
986 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200987
Holger Schurig9012b282007-05-25 11:27:16 -0400988 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -0400989 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Javier Cardona85319f92008-05-24 10:59:49 +0100990 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
991
992 if (vwrq->fixed && vwrq->value == -1)
993 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200994
Dan Williams8c512762007-08-02 11:40:45 -0400995 /* Auto rate? */
Javier Cardona85319f92008-05-24 10:59:49 +0100996 priv->enablehwauto = !vwrq->fixed;
997
998 if (vwrq->value == -1)
David Woodhouseaa21c002007-12-08 20:04:36 +0000999 priv->cur_rate = 0;
Javier Cardona85319f92008-05-24 10:59:49 +01001000 else {
Dan Williams8c512762007-08-02 11:40:45 -04001001 if (vwrq->value % 100000)
1002 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001003
Javier Cardona85319f92008-05-24 10:59:49 +01001004 new_rate = vwrq->value / 500000;
1005 priv->cur_rate = new_rate;
1006 /* the rest is only needed for lbs_set_data_rate() */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001007 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +00001008 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -04001009 if (!memchr(rates, new_rate, sizeof(rates))) {
1010 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1011 new_rate);
1012 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001013 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001014 }
1015
Javier Cardona85319f92008-05-24 10:59:49 +01001016 /* Try the newer command first (Firmware Spec 5.1 and above) */
1017 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1018
1019 /* Fallback to older version */
1020 if (ret)
1021 ret = lbs_set_data_rate(priv, new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001022
Dan Williams8c512762007-08-02 11:40:45 -04001023out:
Holger Schurig9012b282007-05-25 11:27:16 -04001024 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001025 return ret;
1026}
1027
Holger Schurig10078322007-11-15 18:05:47 -05001028static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029 struct iw_param *vwrq, char *extra)
1030{
Holger Schurig69f90322007-11-23 15:43:44 +01001031 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001032
Holger Schurig9012b282007-05-25 11:27:16 -04001033 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001034
David Woodhouseaa21c002007-12-08 20:04:36 +00001035 if (priv->connect_status == LBS_CONNECTED) {
1036 vwrq->value = priv->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037
Javier Cardona85319f92008-05-24 10:59:49 +01001038 if (priv->enablehwauto)
Dan Williams8c512762007-08-02 11:40:45 -04001039 vwrq->fixed = 0;
1040 else
1041 vwrq->fixed = 1;
1042
1043 } else {
1044 vwrq->fixed = 0;
1045 vwrq->value = 0;
1046 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001047
Holger Schurig9012b282007-05-25 11:27:16 -04001048 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001049 return 0;
1050}
1051
Holger Schurig10078322007-11-15 18:05:47 -05001052static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001053 struct iw_request_info *info, u32 * uwrq, char *extra)
1054{
1055 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001056 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001057 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001058
Holger Schurig9012b282007-05-25 11:27:16 -04001059 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001060
Dan Williams0dc5a292007-05-10 22:58:02 -04001061 if ( (*uwrq != IW_MODE_ADHOC)
1062 && (*uwrq != IW_MODE_INFRA)
1063 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001064 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001065 ret = -EINVAL;
1066 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001067 }
1068
David Woodhouseaa21c002007-12-08 20:04:36 +00001069 mutex_lock(&priv->lock);
1070 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001071 if (!assoc_req) {
1072 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001073 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001075 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001076 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001077 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001078 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001079 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001080 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001081
Dan Williams0dc5a292007-05-10 22:58:02 -04001082out:
Holger Schurig9012b282007-05-25 11:27:16 -04001083 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001084 return ret;
1085}
1086
1087
1088/**
1089 * @brief Get Encryption key
1090 *
1091 * @param dev A pointer to net_device structure
1092 * @param info A pointer to iw_request_info structure
1093 * @param vwrq A pointer to iw_param structure
1094 * @param extra A pointer to extra data buf
1095 * @return 0 --success, otherwise fail
1096 */
Holger Schurig10078322007-11-15 18:05:47 -05001097static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001098 struct iw_request_info *info,
1099 struct iw_point *dwrq, u8 * extra)
1100{
Holger Schurig69f90322007-11-23 15:43:44 +01001101 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001102 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1103
Holger Schurig9012b282007-05-25 11:27:16 -04001104 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001105
Holger Schurig9012b282007-05-25 11:27:16 -04001106 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001107 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001108
1109 dwrq->flags = 0;
1110
1111 /* Authentication method */
David Woodhouseaa21c002007-12-08 20:04:36 +00001112 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -04001113 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001114 dwrq->flags = IW_ENCODE_OPEN;
1115 break;
1116
Dan Williams6affe782007-05-10 22:56:42 -04001117 case IW_AUTH_ALG_SHARED_KEY:
1118 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001119 dwrq->flags = IW_ENCODE_RESTRICTED;
1120 break;
1121 default:
1122 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1123 break;
1124 }
1125
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001126 memset(extra, 0, 16);
1127
David Woodhouseaa21c002007-12-08 20:04:36 +00001128 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001129
1130 /* Default to returning current transmit key */
1131 if (index < 0)
David Woodhouseaa21c002007-12-08 20:04:36 +00001132 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001133
David Woodhouseaa21c002007-12-08 20:04:36 +00001134 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1135 memcpy(extra, priv->wep_keys[index].key,
1136 priv->wep_keys[index].len);
1137 dwrq->length = priv->wep_keys[index].len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001138
1139 dwrq->flags |= (index + 1);
1140 /* Return WEP enabled */
1141 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhouseaa21c002007-12-08 20:04:36 +00001142 } else if ((priv->secinfo.WPAenabled)
1143 || (priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001144 /* return WPA enabled */
1145 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhousec12bdc42007-12-07 19:32:12 +00001146 dwrq->flags |= IW_ENCODE_NOKEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001147 } else {
1148 dwrq->flags |= IW_ENCODE_DISABLED;
1149 }
1150
David Woodhouseaa21c002007-12-08 20:04:36 +00001151 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001152
Joe Perches0795af52007-10-03 17:59:30 -07001153 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001154 extra[0], extra[1], extra[2],
1155 extra[3], extra[4], extra[5], dwrq->length);
1156
Holger Schurig9012b282007-05-25 11:27:16 -04001157 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001158
Holger Schurig9012b282007-05-25 11:27:16 -04001159 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001160 return 0;
1161}
1162
1163/**
1164 * @brief Set Encryption key (internal)
1165 *
1166 * @param priv A pointer to private card structure
1167 * @param key_material A pointer to key material
1168 * @param key_length length of key material
1169 * @param index key index to set
1170 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1171 * @return 0 --success, otherwise fail
1172 */
Holger Schurig10078322007-11-15 18:05:47 -05001173static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001174 const char *key_material,
1175 u16 key_length,
1176 u16 index,
1177 int set_tx_key)
1178{
Holger Schurig9012b282007-05-25 11:27:16 -04001179 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001180 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001181
Holger Schurig9012b282007-05-25 11:27:16 -04001182 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001183
1184 /* Paranoid validation of key index */
1185 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001186 ret = -EINVAL;
1187 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001188 }
1189
1190 /* validate max key length */
1191 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001192 ret = -EINVAL;
1193 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001194 }
1195
1196 pkey = &assoc_req->wep_keys[index];
1197
1198 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001199 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001200 pkey->type = KEY_TYPE_ID_WEP;
1201
1202 /* Standardize the key length */
1203 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1204 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1205 memcpy(pkey->key, key_material, key_length);
1206 }
1207
1208 if (set_tx_key) {
1209 /* Ensure the chosen key is valid */
1210 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001211 lbs_deb_wext("key not set, so cannot enable it\n");
1212 ret = -EINVAL;
1213 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001214 }
1215 assoc_req->wep_tx_keyidx = index;
1216 }
1217
Dan Williams889c05b2007-05-10 22:57:23 -04001218 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001219
Holger Schurig9012b282007-05-25 11:27:16 -04001220out:
1221 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1222 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001223}
1224
1225static int validate_key_index(u16 def_index, u16 raw_index,
1226 u16 *out_index, u16 *is_default)
1227{
1228 if (!out_index || !is_default)
1229 return -EINVAL;
1230
1231 /* Verify index if present, otherwise use default TX key index */
1232 if (raw_index > 0) {
1233 if (raw_index > 4)
1234 return -EINVAL;
1235 *out_index = raw_index - 1;
1236 } else {
1237 *out_index = def_index;
1238 *is_default = 1;
1239 }
1240 return 0;
1241}
1242
1243static void disable_wep(struct assoc_request *assoc_req)
1244{
1245 int i;
1246
Dan Williams90a42212007-05-25 23:01:24 -04001247 lbs_deb_enter(LBS_DEB_WEXT);
1248
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001249 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001250 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001251
1252 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001253 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001254 for (i = 0; i < 4; i++)
1255 assoc_req->wep_keys[i].len = 0;
1256
1257 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1258 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001259
1260 lbs_deb_leave(LBS_DEB_WEXT);
1261}
1262
1263static void disable_wpa(struct assoc_request *assoc_req)
1264{
1265 lbs_deb_enter(LBS_DEB_WEXT);
1266
Dan Williams1443b652007-08-02 10:45:55 -04001267 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001268 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1269 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1270
Dan Williams1443b652007-08-02 10:45:55 -04001271 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001272 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1273 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1274
1275 assoc_req->secinfo.WPAenabled = 0;
1276 assoc_req->secinfo.WPA2enabled = 0;
1277 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1278
1279 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001280}
1281
1282/**
1283 * @brief Set Encryption key
1284 *
1285 * @param dev A pointer to net_device structure
1286 * @param info A pointer to iw_request_info structure
1287 * @param vwrq A pointer to iw_param structure
1288 * @param extra A pointer to extra data buf
1289 * @return 0 --success, otherwise fail
1290 */
Holger Schurig10078322007-11-15 18:05:47 -05001291static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001292 struct iw_request_info *info,
1293 struct iw_point *dwrq, char *extra)
1294{
1295 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001296 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001297 struct assoc_request * assoc_req;
1298 u16 is_default = 0, index = 0, set_tx_key = 0;
1299
Holger Schurig9012b282007-05-25 11:27:16 -04001300 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001301
David Woodhouseaa21c002007-12-08 20:04:36 +00001302 mutex_lock(&priv->lock);
1303 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001304 if (!assoc_req) {
1305 ret = -ENOMEM;
1306 goto out;
1307 }
1308
1309 if (dwrq->flags & IW_ENCODE_DISABLED) {
1310 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001311 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001312 goto out;
1313 }
1314
1315 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1316 (dwrq->flags & IW_ENCODE_INDEX),
1317 &index, &is_default);
1318 if (ret) {
1319 ret = -EINVAL;
1320 goto out;
1321 }
1322
1323 /* If WEP isn't enabled, or if there is no key data but a valid
1324 * index, set the TX key.
1325 */
Dan Williams889c05b2007-05-10 22:57:23 -04001326 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001327 set_tx_key = 1;
1328
Holger Schurig10078322007-11-15 18:05:47 -05001329 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001330 if (ret)
1331 goto out;
1332
1333 if (dwrq->length)
1334 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1335 if (set_tx_key)
1336 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1337
1338 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001339 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001340 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001341 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001342 }
1343
1344out:
1345 if (ret == 0) {
1346 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001347 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001348 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001349 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001350 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001351 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001352
Holger Schurig9012b282007-05-25 11:27:16 -04001353 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001354 return ret;
1355}
1356
1357/**
1358 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1359 *
1360 * @param dev A pointer to net_device structure
1361 * @param info A pointer to iw_request_info structure
1362 * @param vwrq A pointer to iw_param structure
1363 * @param extra A pointer to extra data buf
1364 * @return 0 on success, otherwise failure
1365 */
Holger Schurig10078322007-11-15 18:05:47 -05001366static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367 struct iw_request_info *info,
1368 struct iw_point *dwrq,
1369 char *extra)
1370{
1371 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +01001372 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001373 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1374 int index, max_key_len;
1375
Holger Schurig9012b282007-05-25 11:27:16 -04001376 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001377
1378 max_key_len = dwrq->length - sizeof(*ext);
1379 if (max_key_len < 0)
1380 goto out;
1381
1382 index = dwrq->flags & IW_ENCODE_INDEX;
1383 if (index) {
1384 if (index < 1 || index > 4)
1385 goto out;
1386 index--;
1387 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001388 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001389 }
1390
Roel Kluinf59d9782007-10-26 21:51:26 +02001391 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001392 ext->alg != IW_ENCODE_ALG_WEP) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001393 if (index != 0 || priv->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001394 goto out;
1395 }
1396
1397 dwrq->flags = index + 1;
1398 memset(ext, 0, sizeof(*ext));
1399
David Woodhouseaa21c002007-12-08 20:04:36 +00001400 if ( !priv->secinfo.wep_enabled
1401 && !priv->secinfo.WPAenabled
1402 && !priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001403 ext->alg = IW_ENCODE_ALG_NONE;
1404 ext->key_len = 0;
1405 dwrq->flags |= IW_ENCODE_DISABLED;
1406 } else {
1407 u8 *key = NULL;
1408
David Woodhouseaa21c002007-12-08 20:04:36 +00001409 if ( priv->secinfo.wep_enabled
1410 && !priv->secinfo.WPAenabled
1411 && !priv->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001412 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001413 ext->alg = IW_ENCODE_ALG_WEP;
David Woodhouseaa21c002007-12-08 20:04:36 +00001414 ext->key_len = priv->wep_keys[index].len;
1415 key = &priv->wep_keys[index].key[0];
1416 } else if ( !priv->secinfo.wep_enabled
1417 && (priv->secinfo.WPAenabled ||
1418 priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001419 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001420 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001421
David Woodhouseaa21c002007-12-08 20:04:36 +00001422 if ( priv->wpa_mcast_key.len
1423 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1424 pkey = &priv->wpa_mcast_key;
1425 else if ( priv->wpa_unicast_key.len
1426 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1427 pkey = &priv->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001428
1429 if (pkey) {
1430 if (pkey->type == KEY_TYPE_ID_AES) {
1431 ext->alg = IW_ENCODE_ALG_CCMP;
1432 } else {
1433 ext->alg = IW_ENCODE_ALG_TKIP;
1434 }
1435 ext->key_len = pkey->len;
1436 key = &pkey->key[0];
1437 } else {
1438 ext->alg = IW_ENCODE_ALG_TKIP;
1439 ext->key_len = 0;
1440 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001441 } else {
1442 goto out;
1443 }
1444
1445 if (ext->key_len > max_key_len) {
1446 ret = -E2BIG;
1447 goto out;
1448 }
1449
1450 if (ext->key_len)
1451 memcpy(ext->key, key, ext->key_len);
1452 else
1453 dwrq->flags |= IW_ENCODE_NOKEY;
1454 dwrq->flags |= IW_ENCODE_ENABLED;
1455 }
1456 ret = 0;
1457
1458out:
Holger Schurig9012b282007-05-25 11:27:16 -04001459 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001460 return ret;
1461}
1462
1463/**
1464 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1465 *
1466 * @param dev A pointer to net_device structure
1467 * @param info A pointer to iw_request_info structure
1468 * @param vwrq A pointer to iw_param structure
1469 * @param extra A pointer to extra data buf
1470 * @return 0 --success, otherwise fail
1471 */
Holger Schurig10078322007-11-15 18:05:47 -05001472static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001473 struct iw_request_info *info,
1474 struct iw_point *dwrq,
1475 char *extra)
1476{
1477 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001478 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001479 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1480 int alg = ext->alg;
1481 struct assoc_request * assoc_req;
1482
Holger Schurig9012b282007-05-25 11:27:16 -04001483 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001484
David Woodhouseaa21c002007-12-08 20:04:36 +00001485 mutex_lock(&priv->lock);
1486 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487 if (!assoc_req) {
1488 ret = -ENOMEM;
1489 goto out;
1490 }
1491
1492 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1493 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001494 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001495 } else if (alg == IW_ENCODE_ALG_WEP) {
1496 u16 is_default = 0, index, set_tx_key = 0;
1497
1498 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1499 (dwrq->flags & IW_ENCODE_INDEX),
1500 &index, &is_default);
1501 if (ret)
1502 goto out;
1503
1504 /* If WEP isn't enabled, or if there is no key data but a valid
1505 * index, or if the set-TX-key flag was passed, set the TX key.
1506 */
Dan Williams889c05b2007-05-10 22:57:23 -04001507 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508 || (dwrq->length == 0 && !is_default)
1509 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1510 set_tx_key = 1;
1511
1512 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001513 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001514 set_tx_key);
1515 if (ret)
1516 goto out;
1517
1518 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001519 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001520 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001521 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001522 }
1523
1524 /* Mark the various WEP bits as modified */
1525 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1526 if (dwrq->length)
1527 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1528 if (set_tx_key)
1529 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001530 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001531 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001532
1533 /* validate key length */
1534 if (((alg == IW_ENCODE_ALG_TKIP)
1535 && (ext->key_len != KEY_LEN_WPA_TKIP))
1536 || ((alg == IW_ENCODE_ALG_CCMP)
1537 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001538 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001539 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001540 ext->key_len,
1541 alg);
1542 ret = -EINVAL;
1543 goto out;
1544 }
1545
Dan Williams90a42212007-05-25 23:01:24 -04001546 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001547 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001548 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1549 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001550 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001551 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1552 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001553
Dan Williams1443b652007-08-02 10:45:55 -04001554 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001555 memcpy(pkey->key, ext->key, ext->key_len);
1556 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001557 if (pkey->len)
1558 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001559
Dan Williams90a42212007-05-25 23:01:24 -04001560 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001561 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1562 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001563 } else {
1564 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001565 }
1566
Dan Williams90a42212007-05-25 23:01:24 -04001567 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001568 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001569 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001570 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001571 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001572
1573 /* If WPA isn't enabled yet, do that now */
1574 if ( assoc_req->secinfo.WPAenabled == 0
1575 && assoc_req->secinfo.WPA2enabled == 0) {
1576 assoc_req->secinfo.WPAenabled = 1;
1577 assoc_req->secinfo.WPA2enabled = 1;
1578 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1579 }
1580
1581 disable_wep (assoc_req);
1582 }
1583
1584out:
1585 if (ret == 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001586 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001587 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001588 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001589 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001590 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001591
Holger Schurig9012b282007-05-25 11:27:16 -04001592 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001593 return ret;
1594}
1595
1596
Holger Schurig10078322007-11-15 18:05:47 -05001597static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001598 struct iw_request_info *info,
1599 struct iw_point *dwrq,
1600 char *extra)
1601{
Holger Schurig69f90322007-11-23 15:43:44 +01001602 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001603 int ret = 0;
1604 struct assoc_request * assoc_req;
1605
Holger Schurig9012b282007-05-25 11:27:16 -04001606 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001607
David Woodhouseaa21c002007-12-08 20:04:36 +00001608 mutex_lock(&priv->lock);
1609 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001610 if (!assoc_req) {
1611 ret = -ENOMEM;
1612 goto out;
1613 }
1614
1615 if (dwrq->length > MAX_WPA_IE_LEN ||
1616 (dwrq->length && extra == NULL)) {
1617 ret = -EINVAL;
1618 goto out;
1619 }
1620
1621 if (dwrq->length) {
1622 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1623 assoc_req->wpa_ie_len = dwrq->length;
1624 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001625 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001626 assoc_req->wpa_ie_len = 0;
1627 }
1628
1629out:
1630 if (ret == 0) {
1631 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001632 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001633 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001634 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001635 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001636 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001637
Holger Schurig9012b282007-05-25 11:27:16 -04001638 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001639 return ret;
1640}
1641
Holger Schurig10078322007-11-15 18:05:47 -05001642static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001643 struct iw_request_info *info,
1644 struct iw_point *dwrq,
1645 char *extra)
1646{
Holger Schurig9012b282007-05-25 11:27:16 -04001647 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001648 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001649
Holger Schurig9012b282007-05-25 11:27:16 -04001650 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001651
David Woodhouseaa21c002007-12-08 20:04:36 +00001652 if (priv->wpa_ie_len == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001653 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001654 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001655 }
1656
David Woodhouseaa21c002007-12-08 20:04:36 +00001657 if (dwrq->length < priv->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001658 ret = -E2BIG;
1659 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001660 }
1661
David Woodhouseaa21c002007-12-08 20:04:36 +00001662 dwrq->length = priv->wpa_ie_len;
1663 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001664
Holger Schurig9012b282007-05-25 11:27:16 -04001665out:
1666 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1667 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001668}
1669
1670
Holger Schurig10078322007-11-15 18:05:47 -05001671static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001672 struct iw_request_info *info,
1673 struct iw_param *dwrq,
1674 char *extra)
1675{
Holger Schurig69f90322007-11-23 15:43:44 +01001676 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001677 struct assoc_request * assoc_req;
1678 int ret = 0;
1679 int updated = 0;
1680
Holger Schurig9012b282007-05-25 11:27:16 -04001681 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001682
David Woodhouseaa21c002007-12-08 20:04:36 +00001683 mutex_lock(&priv->lock);
1684 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001685 if (!assoc_req) {
1686 ret = -ENOMEM;
1687 goto out;
1688 }
1689
1690 switch (dwrq->flags & IW_AUTH_INDEX) {
1691 case IW_AUTH_TKIP_COUNTERMEASURES:
1692 case IW_AUTH_CIPHER_PAIRWISE:
1693 case IW_AUTH_CIPHER_GROUP:
1694 case IW_AUTH_KEY_MGMT:
Dan Williams90a42212007-05-25 23:01:24 -04001695 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001696 /*
1697 * libertas does not use these parameters
1698 */
1699 break;
1700
1701 case IW_AUTH_WPA_VERSION:
1702 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1703 assoc_req->secinfo.WPAenabled = 0;
1704 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001705 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001706 }
1707 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1708 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001709 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001710 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001711 }
1712 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1713 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001714 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001715 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001716 }
1717 updated = 1;
1718 break;
1719
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001720 case IW_AUTH_80211_AUTH_ALG:
1721 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001722 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001723 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001724 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001725 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001726 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001727 } else {
1728 ret = -EINVAL;
1729 }
1730 updated = 1;
1731 break;
1732
1733 case IW_AUTH_WPA_ENABLED:
1734 if (dwrq->value) {
1735 if (!assoc_req->secinfo.WPAenabled &&
1736 !assoc_req->secinfo.WPA2enabled) {
1737 assoc_req->secinfo.WPAenabled = 1;
1738 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001739 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001740 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001741 }
1742 } else {
1743 assoc_req->secinfo.WPAenabled = 0;
1744 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001745 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001746 }
1747 updated = 1;
1748 break;
1749
1750 default:
1751 ret = -EOPNOTSUPP;
1752 break;
1753 }
1754
1755out:
1756 if (ret == 0) {
1757 if (updated)
1758 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001759 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001760 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001761 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001762 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001763 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001764
Holger Schurig9012b282007-05-25 11:27:16 -04001765 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001766 return ret;
1767}
1768
Holger Schurig10078322007-11-15 18:05:47 -05001769static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001770 struct iw_request_info *info,
1771 struct iw_param *dwrq,
1772 char *extra)
1773{
Holger Schurig9012b282007-05-25 11:27:16 -04001774 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001775 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001776
Holger Schurig9012b282007-05-25 11:27:16 -04001777 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001778
1779 switch (dwrq->flags & IW_AUTH_INDEX) {
1780 case IW_AUTH_WPA_VERSION:
1781 dwrq->value = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +00001782 if (priv->secinfo.WPAenabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001783 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
David Woodhouseaa21c002007-12-08 20:04:36 +00001784 if (priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001785 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1786 if (!dwrq->value)
1787 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1788 break;
1789
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001790 case IW_AUTH_80211_AUTH_ALG:
David Woodhouseaa21c002007-12-08 20:04:36 +00001791 dwrq->value = priv->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001792 break;
1793
1794 case IW_AUTH_WPA_ENABLED:
David Woodhouseaa21c002007-12-08 20:04:36 +00001795 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001796 dwrq->value = 1;
1797 break;
1798
1799 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001800 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001801 }
1802
Holger Schurig9012b282007-05-25 11:27:16 -04001803 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1804 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001805}
1806
1807
Holger Schurig10078322007-11-15 18:05:47 -05001808static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001809 struct iw_param *vwrq, char *extra)
1810{
1811 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001812 struct lbs_private *priv = dev->priv;
Dan Williams87c8c722008-08-19 15:15:35 -04001813 s16 dbm = (s16) vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001814
Holger Schurig9012b282007-05-25 11:27:16 -04001815 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816
1817 if (vwrq->disabled) {
Dan Williamsd5db2df2008-08-21 17:51:07 -04001818 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
Dan Williams87c8c722008-08-19 15:15:35 -04001819 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001820 }
1821
Dan Williams87c8c722008-08-19 15:15:35 -04001822 if (vwrq->fixed == 0) {
Anna Neal0112c9e2008-09-11 11:17:25 -07001823 /* User requests automatic tx power control, however there are
1824 * many auto tx settings. For now use firmware defaults until
1825 * we come up with a good way to expose these to the user. */
1826 if (priv->fwrelease < 0x09000000) {
1827 ret = lbs_set_power_adapt_cfg(priv, 1,
1828 POW_ADAPT_DEFAULT_P0,
1829 POW_ADAPT_DEFAULT_P1,
1830 POW_ADAPT_DEFAULT_P2);
1831 if (ret)
1832 goto out;
1833 }
1834 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1835 TPC_DEFAULT_P2, 1);
1836 if (ret)
1837 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001838 dbm = priv->txpower_max;
1839 } else {
1840 /* Userspace check in iwrange if it should use dBm or mW,
1841 * therefore this should never happen... Jean II */
1842 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1843 ret = -EOPNOTSUPP;
1844 goto out;
1845 }
1846
Anna Neal0112c9e2008-09-11 11:17:25 -07001847 /* Validate requested power level against firmware allowed
1848 * levels */
Dan Williams87c8c722008-08-19 15:15:35 -04001849 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1850 ret = -EINVAL;
1851 goto out;
1852 }
1853
1854 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1855 ret = -EINVAL;
1856 goto out;
1857 }
Anna Neal0112c9e2008-09-11 11:17:25 -07001858 if (priv->fwrelease < 0x09000000) {
1859 ret = lbs_set_power_adapt_cfg(priv, 0,
1860 POW_ADAPT_DEFAULT_P0,
1861 POW_ADAPT_DEFAULT_P1,
1862 POW_ADAPT_DEFAULT_P2);
1863 if (ret)
1864 goto out;
1865 }
1866 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1867 TPC_DEFAULT_P2, 1);
1868 if (ret)
1869 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001870 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001871
Dan Williamsd5db2df2008-08-21 17:51:07 -04001872 /* If the radio was off, turn it on */
1873 if (!priv->radio_on) {
1874 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
1875 if (ret)
1876 goto out;
1877 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001878
Dan Williams87c8c722008-08-19 15:15:35 -04001879 lbs_deb_wext("txpower set %d dBm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001880
Dan Williams87c8c722008-08-19 15:15:35 -04001881 ret = lbs_set_tx_power(priv, dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001882
Dan Williams87c8c722008-08-19 15:15:35 -04001883out:
Holger Schurig9012b282007-05-25 11:27:16 -04001884 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001885 return ret;
1886}
1887
Holger Schurig10078322007-11-15 18:05:47 -05001888static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001889 struct iw_point *dwrq, char *extra)
1890{
Holger Schurig69f90322007-11-23 15:43:44 +01001891 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001892
Holger Schurig9012b282007-05-25 11:27:16 -04001893 lbs_deb_enter(LBS_DEB_WEXT);
1894
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001895 /*
1896 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1897 * the SSID list...
1898 */
1899
1900 /*
1901 * Get the current SSID
1902 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001903 if (priv->connect_status == LBS_CONNECTED) {
1904 memcpy(extra, priv->curbssparams.ssid,
1905 priv->curbssparams.ssid_len);
1906 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001907 } else {
1908 memset(extra, 0, 32);
David Woodhouseaa21c002007-12-08 20:04:36 +00001909 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001910 }
1911 /*
1912 * If none, we may want to get the one that was set
1913 */
1914
David Woodhouseaa21c002007-12-08 20:04:36 +00001915 dwrq->length = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001916
1917 dwrq->flags = 1; /* active */
1918
Holger Schurig9012b282007-05-25 11:27:16 -04001919 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001920 return 0;
1921}
1922
Holger Schurig10078322007-11-15 18:05:47 -05001923static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001924 struct iw_point *dwrq, char *extra)
1925{
Holger Schurig69f90322007-11-23 15:43:44 +01001926 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001927 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04001928 u8 ssid[IW_ESSID_MAX_SIZE];
1929 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001930 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001931 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001932
Holger Schurig9012b282007-05-25 11:27:16 -04001933 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001934
Dan Williamsd5db2df2008-08-21 17:51:07 -04001935 if (!priv->radio_on) {
1936 ret = -EINVAL;
1937 goto out;
1938 }
1939
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001940 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001941 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001942 ret = -E2BIG;
1943 goto out;
1944 }
1945
Dan Williamsd8efea22007-05-28 23:54:55 -04001946 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001947
Dan Williamsd8efea22007-05-28 23:54:55 -04001948 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001949 /* "any" SSID requested; leave SSID blank */
1950 } else {
1951 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04001952 memcpy(&ssid, extra, in_ssid_len);
1953 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001954 }
1955
Dan Williamsd8efea22007-05-28 23:54:55 -04001956 if (!ssid_len) {
1957 lbs_deb_wext("requested any SSID\n");
1958 } else {
1959 lbs_deb_wext("requested SSID '%s'\n",
1960 escape_essid(ssid, ssid_len));
1961 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001962
1963out:
David Woodhouseaa21c002007-12-08 20:04:36 +00001964 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001965 if (ret == 0) {
1966 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00001967 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001968 if (!assoc_req) {
1969 ret = -ENOMEM;
1970 } else {
1971 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04001972 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1973 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001974 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001975 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001976 }
1977 }
1978
1979 /* Cancel the association request if there was an error */
1980 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05001981 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001982 }
1983
David Woodhouseaa21c002007-12-08 20:04:36 +00001984 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001985
Holger Schurig9012b282007-05-25 11:27:16 -04001986 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001987 return ret;
1988}
1989
David Woodhousef5956bf2007-12-11 19:30:57 -05001990static int lbs_mesh_get_essid(struct net_device *dev,
1991 struct iw_request_info *info,
1992 struct iw_point *dwrq, char *extra)
1993{
1994 struct lbs_private *priv = dev->priv;
1995
1996 lbs_deb_enter(LBS_DEB_WEXT);
1997
1998 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
1999
2000 dwrq->length = priv->mesh_ssid_len;
2001
2002 dwrq->flags = 1; /* active */
2003
2004 lbs_deb_leave(LBS_DEB_WEXT);
2005 return 0;
2006}
2007
2008static int lbs_mesh_set_essid(struct net_device *dev,
2009 struct iw_request_info *info,
2010 struct iw_point *dwrq, char *extra)
2011{
2012 struct lbs_private *priv = dev->priv;
2013 int ret = 0;
2014
2015 lbs_deb_enter(LBS_DEB_WEXT);
2016
Dan Williamsd5db2df2008-08-21 17:51:07 -04002017 if (!priv->radio_on) {
2018 ret = -EINVAL;
2019 goto out;
2020 }
2021
David Woodhousef5956bf2007-12-11 19:30:57 -05002022 /* Check the size of the string */
2023 if (dwrq->length > IW_ESSID_MAX_SIZE) {
2024 ret = -E2BIG;
2025 goto out;
2026 }
2027
2028 if (!dwrq->flags || !dwrq->length) {
2029 ret = -EINVAL;
2030 goto out;
2031 } else {
2032 /* Specific SSID requested */
2033 memcpy(priv->mesh_ssid, extra, dwrq->length);
2034 priv->mesh_ssid_len = dwrq->length;
2035 }
2036
Javier Cardonaedaea5c2008-05-17 00:55:10 -07002037 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
2038 priv->curbssparams.channel);
David Woodhousef5956bf2007-12-11 19:30:57 -05002039 out:
2040 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2041 return ret;
2042}
2043
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002044/**
2045 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2046 *
2047 * @param dev A pointer to net_device structure
2048 * @param info A pointer to iw_request_info structure
2049 * @param awrq A pointer to iw_param structure
2050 * @param extra A pointer to extra data buf
2051 * @return 0 --success, otherwise fail
2052 */
Holger Schurig10078322007-11-15 18:05:47 -05002053static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002054 struct sockaddr *awrq, char *extra)
2055{
Holger Schurig69f90322007-11-23 15:43:44 +01002056 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002057 struct assoc_request * assoc_req;
2058 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07002059 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002060
Holger Schurig9012b282007-05-25 11:27:16 -04002061 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002062
Dan Williamsd5db2df2008-08-21 17:51:07 -04002063 if (!priv->radio_on)
2064 return -EINVAL;
2065
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002066 if (awrq->sa_family != ARPHRD_ETHER)
2067 return -EINVAL;
2068
Joe Perches0795af52007-10-03 17:59:30 -07002069 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002070
David Woodhouseaa21c002007-12-08 20:04:36 +00002071 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002072
2073 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002074 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002075 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05002076 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002077 ret = -ENOMEM;
2078 } else {
2079 /* Copy the BSSID to the association request */
2080 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2081 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002082 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002083 }
2084
David Woodhouseaa21c002007-12-08 20:04:36 +00002085 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002086
2087 return ret;
2088}
2089
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002090/*
2091 * iwconfig settable callbacks
2092 */
Holger Schurig10078322007-11-15 18:05:47 -05002093static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002094 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002095 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002096 (iw_handler) NULL, /* SIOCSIWNWID */
2097 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002098 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2099 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2100 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2101 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002102 (iw_handler) NULL, /* SIOCSIWSENS */
2103 (iw_handler) NULL, /* SIOCGIWSENS */
2104 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002105 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002106 (iw_handler) NULL, /* SIOCSIWPRIV */
2107 (iw_handler) NULL, /* SIOCGIWPRIV */
2108 (iw_handler) NULL, /* SIOCSIWSTATS */
2109 (iw_handler) NULL, /* SIOCGIWSTATS */
2110 iw_handler_set_spy, /* SIOCSIWSPY */
2111 iw_handler_get_spy, /* SIOCGIWSPY */
2112 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2113 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002114 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2115 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002116 (iw_handler) NULL, /* SIOCSIWMLME */
2117 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002118 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2119 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2120 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2121 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2122 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2123 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002124 (iw_handler) NULL, /* -- hole -- */
2125 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002126 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2127 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2128 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2129 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2130 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2131 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2132 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2133 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2134 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2135 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2136 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2137 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2138 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2139 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002140 (iw_handler) NULL, /* -- hole -- */
2141 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002142 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2143 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2144 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2145 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2146 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2147 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002148 (iw_handler) NULL, /* SIOCSIWPMKSA */
2149};
2150
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002151static const iw_handler mesh_wlan_handler[] = {
2152 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002153 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002154 (iw_handler) NULL, /* SIOCSIWNWID */
2155 (iw_handler) NULL, /* SIOCGIWNWID */
David Woodhouse823eaa22007-12-11 19:56:28 -05002156 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
Holger Schurig10078322007-11-15 18:05:47 -05002157 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002158 (iw_handler) NULL, /* SIOCSIWMODE */
2159 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2160 (iw_handler) NULL, /* SIOCSIWSENS */
2161 (iw_handler) NULL, /* SIOCGIWSENS */
2162 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002163 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002164 (iw_handler) NULL, /* SIOCSIWPRIV */
2165 (iw_handler) NULL, /* SIOCGIWPRIV */
2166 (iw_handler) NULL, /* SIOCSIWSTATS */
2167 (iw_handler) NULL, /* SIOCGIWSTATS */
2168 iw_handler_set_spy, /* SIOCSIWSPY */
2169 iw_handler_get_spy, /* SIOCGIWSPY */
2170 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2171 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2172 (iw_handler) NULL, /* SIOCSIWAP */
2173 (iw_handler) NULL, /* SIOCGIWAP */
2174 (iw_handler) NULL, /* SIOCSIWMLME */
2175 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002176 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2177 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
David Woodhousef5956bf2007-12-11 19:30:57 -05002178 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2179 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002180 (iw_handler) NULL, /* SIOCSIWNICKN */
2181 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2182 (iw_handler) NULL, /* -- hole -- */
2183 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002184 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2185 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2186 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2187 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2188 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2189 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2190 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2191 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2192 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2193 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2194 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2195 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2196 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2197 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002198 (iw_handler) NULL, /* -- hole -- */
2199 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002200 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2201 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2202 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2203 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2204 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2205 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002206 (iw_handler) NULL, /* SIOCSIWPMKSA */
2207};
Holger Schurig10078322007-11-15 18:05:47 -05002208struct iw_handler_def lbs_handler_def = {
2209 .num_standard = ARRAY_SIZE(lbs_handler),
2210 .standard = (iw_handler *) lbs_handler,
2211 .get_wireless_stats = lbs_get_wireless_stats,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002212};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002213
2214struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002215 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002216 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002217 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002218};