blob: 2475799518583c729a06ea0b209a0e640712dc14 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains ioctl functions
3 */
4#include <linux/ctype.h>
5#include <linux/delay.h>
6#include <linux/if.h>
7#include <linux/if_arp.h>
8#include <linux/wireless.h>
9#include <linux/bitops.h>
10
John W. Linville7e272fc2008-09-24 18:13:14 -040011#include <net/lib80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020012#include <net/ieee80211.h>
13#include <net/iw_handler.h>
14
15#include "host.h"
16#include "radiotap.h"
17#include "decl.h"
18#include "defs.h"
19#include "dev.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020#include "wext.h"
Holger Schurig245bf202008-04-02 16:27:42 +020021#include "scan.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022#include "assoc.h"
Dan Williams8e3c91b2007-12-11 15:50:59 -050023#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024
25
Holger Schurig69f90322007-11-23 15:43:44 +010026static inline void lbs_postpone_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020027{
David Woodhouseaa21c002007-12-08 20:04:36 +000028 if (priv->surpriseremoved)
Holger Schurig9f9dac22007-10-26 10:12:14 +020029 return;
30 cancel_delayed_work(&priv->assoc_work);
31 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
32}
33
Javier Cardona9c31fd62008-09-11 15:32:50 -070034static inline void lbs_do_association_work(struct lbs_private *priv)
35{
36 if (priv->surpriseremoved)
37 return;
38 cancel_delayed_work(&priv->assoc_work);
39 queue_delayed_work(priv->work_thread, &priv->assoc_work, 0);
40}
41
Holger Schurig69f90322007-11-23 15:43:44 +010042static inline void lbs_cancel_association_work(struct lbs_private *priv)
Holger Schurig9f9dac22007-10-26 10:12:14 +020043{
44 cancel_delayed_work(&priv->assoc_work);
David Woodhouseaa21c002007-12-08 20:04:36 +000045 kfree(priv->pending_assoc_req);
46 priv->pending_assoc_req = NULL;
Holger Schurig9f9dac22007-10-26 10:12:14 +020047}
48
49
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020050/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020051 * @brief Find the channel frequency power info with specific channel
52 *
David Woodhouseaa21c002007-12-08 20:04:36 +000053 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020054 * @param band it can be BAND_A, BAND_G or BAND_B
55 * @param channel the channel for looking
56 * @return A pointer to struct chan_freq_power structure or NULL if not find.
57 */
Holger Schurig69f90322007-11-23 15:43:44 +010058struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
David Woodhouseaa21c002007-12-08 20:04:36 +000059 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +010060 u8 band,
61 u16 channel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020062{
63 struct chan_freq_power *cfp = NULL;
64 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065 int i, j;
66
David Woodhouseaa21c002007-12-08 20:04:36 +000067 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
68 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020069
David Woodhouseaa21c002007-12-08 20:04:36 +000070 if (priv->enable11d)
71 rc = &priv->universal_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072 if (!rc->valid || !rc->CFP)
73 continue;
74 if (rc->band != band)
75 continue;
76 for (i = 0; i < rc->nrcfp; i++) {
77 if (rc->CFP[i].channel == channel) {
78 cfp = &rc->CFP[i];
79 break;
80 }
81 }
82 }
83
84 if (!cfp && channel)
Holger Schurig10078322007-11-15 18:05:47 -050085 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
Holger Schurig9012b282007-05-25 11:27:16 -040086 "cfp by band %d / channel %d\n", band, channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020087
88 return cfp;
89}
90
91/**
92 * @brief Find the channel frequency power info with specific frequency
93 *
David Woodhouseaa21c002007-12-08 20:04:36 +000094 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020095 * @param band it can be BAND_A, BAND_G or BAND_B
96 * @param freq the frequency for looking
97 * @return A pointer to struct chan_freq_power structure or NULL if not find.
98 */
Holger Schurig69f90322007-11-23 15:43:44 +010099static struct chan_freq_power *find_cfp_by_band_and_freq(
David Woodhouseaa21c002007-12-08 20:04:36 +0000100 struct lbs_private *priv,
Holger Schurig69f90322007-11-23 15:43:44 +0100101 u8 band,
102 u32 freq)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200103{
104 struct chan_freq_power *cfp = NULL;
105 struct region_channel *rc;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200106 int i, j;
107
David Woodhouseaa21c002007-12-08 20:04:36 +0000108 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
109 rc = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110
David Woodhouseaa21c002007-12-08 20:04:36 +0000111 if (priv->enable11d)
112 rc = &priv->universal_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200113 if (!rc->valid || !rc->CFP)
114 continue;
115 if (rc->band != band)
116 continue;
117 for (i = 0; i < rc->nrcfp; i++) {
118 if (rc->CFP[i].freq == freq) {
119 cfp = &rc->CFP[i];
120 break;
121 }
122 }
123 }
124
125 if (!cfp && freq)
Holger Schurig9012b282007-05-25 11:27:16 -0400126 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
127 "band %d / freq %d\n", band, freq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200128
129 return cfp;
130}
131
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200132/**
Dan Williams8c512762007-08-02 11:40:45 -0400133 * @brief Copy active data rates based on adapter mode and status
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200134 *
David Woodhouseaa21c002007-12-08 20:04:36 +0000135 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200136 * @param rate The buf to return the active rates
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200137 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000138static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139{
Holger Schurig9012b282007-05-25 11:27:16 -0400140 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200141
David Woodhouseaa21c002007-12-08 20:04:36 +0000142 if ((priv->connect_status != LBS_CONNECTED) &&
143 (priv->mesh_connect_status != LBS_CONNECTED))
Holger Schurig10078322007-11-15 18:05:47 -0500144 memcpy(rates, lbs_bg_rates, MAX_RATES);
Dan Williams8c512762007-08-02 11:40:45 -0400145 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000146 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200147
Dan Williams8c512762007-08-02 11:40:45 -0400148 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149}
150
Holger Schurig10078322007-11-15 18:05:47 -0500151static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152 char *cwrq, char *extra)
153{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200154
Holger Schurig9012b282007-05-25 11:27:16 -0400155 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400157 /* We could add support for 802.11n here as needed. Jean II */
158 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159
Holger Schurig9012b282007-05-25 11:27:16 -0400160 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161 return 0;
162}
163
Holger Schurig10078322007-11-15 18:05:47 -0500164static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165 struct iw_freq *fwrq, char *extra)
166{
Holger Schurig69f90322007-11-23 15:43:44 +0100167 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200168 struct chan_freq_power *cfp;
169
Holger Schurig9012b282007-05-25 11:27:16 -0400170 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200171
David Woodhouseaa21c002007-12-08 20:04:36 +0000172 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
173 priv->curbssparams.channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200174
175 if (!cfp) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000176 if (priv->curbssparams.channel)
Holger Schurig9012b282007-05-25 11:27:16 -0400177 lbs_deb_wext("invalid channel %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000178 priv->curbssparams.channel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200179 return -EINVAL;
180 }
181
182 fwrq->m = (long)cfp->freq * 100000;
183 fwrq->e = 1;
184
Holger Schurig9012b282007-05-25 11:27:16 -0400185 lbs_deb_wext("freq %u\n", fwrq->m);
186 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200187 return 0;
188}
189
Holger Schurig10078322007-11-15 18:05:47 -0500190static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200191 struct sockaddr *awrq, char *extra)
192{
Holger Schurig69f90322007-11-23 15:43:44 +0100193 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200194
Holger Schurig9012b282007-05-25 11:27:16 -0400195 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200196
David Woodhouseaa21c002007-12-08 20:04:36 +0000197 if (priv->connect_status == LBS_CONNECTED) {
198 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200199 } else {
200 memset(awrq->sa_data, 0, ETH_ALEN);
201 }
202 awrq->sa_family = ARPHRD_ETHER;
203
Holger Schurig9012b282007-05-25 11:27:16 -0400204 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200205 return 0;
206}
207
Holger Schurig10078322007-11-15 18:05:47 -0500208static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200209 struct iw_point *dwrq, char *extra)
210{
Holger Schurig69f90322007-11-23 15:43:44 +0100211 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200212
Holger Schurig9012b282007-05-25 11:27:16 -0400213 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200214
215 /*
216 * Check the size of the string
217 */
218
219 if (dwrq->length > 16) {
220 return -E2BIG;
221 }
222
David Woodhouseaa21c002007-12-08 20:04:36 +0000223 mutex_lock(&priv->lock);
224 memset(priv->nodename, 0, sizeof(priv->nodename));
225 memcpy(priv->nodename, extra, dwrq->length);
226 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227
Holger Schurig9012b282007-05-25 11:27:16 -0400228 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200229 return 0;
230}
231
Holger Schurig10078322007-11-15 18:05:47 -0500232static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200233 struct iw_point *dwrq, char *extra)
234{
Holger Schurig69f90322007-11-23 15:43:44 +0100235 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200236
Holger Schurig9012b282007-05-25 11:27:16 -0400237 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200238
David Woodhouseaa21c002007-12-08 20:04:36 +0000239 dwrq->length = strlen(priv->nodename);
240 memcpy(extra, priv->nodename, dwrq->length);
Holger Schurig04799fa2007-10-09 15:04:14 +0200241 extra[dwrq->length] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200242
Holger Schurig04799fa2007-10-09 15:04:14 +0200243 dwrq->flags = 1; /* active */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244
Holger Schurig9012b282007-05-25 11:27:16 -0400245 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246 return 0;
247}
248
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400249static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
250 struct iw_point *dwrq, char *extra)
251{
Holger Schurig69f90322007-11-23 15:43:44 +0100252 struct lbs_private *priv = dev->priv;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400253
254 lbs_deb_enter(LBS_DEB_WEXT);
255
256 /* Use nickname to indicate that mesh is on */
257
David Woodhouseaa21c002007-12-08 20:04:36 +0000258 if (priv->mesh_connect_status == LBS_CONNECTED) {
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400259 strncpy(extra, "Mesh", 12);
260 extra[12] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400261 dwrq->length = strlen(extra);
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400262 }
263
264 else {
265 extra[0] = '\0';
Jean Tourrilhes9483f032007-08-02 13:16:30 -0400266 dwrq->length = 0;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400267 }
268
269 lbs_deb_leave(LBS_DEB_WEXT);
270 return 0;
271}
Holger Schurig04799fa2007-10-09 15:04:14 +0200272
Holger Schurig10078322007-11-15 18:05:47 -0500273static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200274 struct iw_param *vwrq, char *extra)
275{
276 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +0100277 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400278 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200279
Holger Schurig9012b282007-05-25 11:27:16 -0400280 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200281
Dan Williams39fcf7a2008-09-10 12:49:00 -0400282 if (vwrq->disabled)
283 val = MRVDRV_RTS_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200284
John W. Linville375da532008-09-15 17:25:54 -0400285 if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400286 return -EINVAL;
287
288 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200289
Holger Schurig9012b282007-05-25 11:27:16 -0400290 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200291 return ret;
292}
293
Holger Schurig10078322007-11-15 18:05:47 -0500294static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200295 struct iw_param *vwrq, char *extra)
296{
Holger Schurig69f90322007-11-23 15:43:44 +0100297 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400298 int ret = 0;
299 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300
Holger Schurig9012b282007-05-25 11:27:16 -0400301 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302
Dan Williams39fcf7a2008-09-10 12:49:00 -0400303 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400304 if (ret)
305 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306
Dan Williams39fcf7a2008-09-10 12:49:00 -0400307 vwrq->value = val;
John W. Linville375da532008-09-15 17:25:54 -0400308 vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309 vwrq->fixed = 1;
310
Holger Schurig9012b282007-05-25 11:27:16 -0400311out:
312 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
313 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314}
315
Holger Schurig10078322007-11-15 18:05:47 -0500316static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317 struct iw_param *vwrq, char *extra)
318{
Holger Schurig69f90322007-11-23 15:43:44 +0100319 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400320 int ret = 0;
321 u32 val = vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200322
Holger Schurig9012b282007-05-25 11:27:16 -0400323 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324
Dan Williams39fcf7a2008-09-10 12:49:00 -0400325 if (vwrq->disabled)
326 val = MRVDRV_FRAG_MAX_VALUE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200327
Dan Williams39fcf7a2008-09-10 12:49:00 -0400328 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
329 return -EINVAL;
330
331 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
Holger Schurig9012b282007-05-25 11:27:16 -0400332
333 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334 return ret;
335}
336
Holger Schurig10078322007-11-15 18:05:47 -0500337static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338 struct iw_param *vwrq, char *extra)
339{
Holger Schurig69f90322007-11-23 15:43:44 +0100340 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400341 int ret = 0;
342 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343
Holger Schurig9012b282007-05-25 11:27:16 -0400344 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200345
Dan Williams39fcf7a2008-09-10 12:49:00 -0400346 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
Holger Schurig9012b282007-05-25 11:27:16 -0400347 if (ret)
348 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349
Dan Williams39fcf7a2008-09-10 12:49:00 -0400350 vwrq->value = val;
351 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
352 || (val > MRVDRV_FRAG_MAX_VALUE));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353 vwrq->fixed = 1;
354
Holger Schurig9012b282007-05-25 11:27:16 -0400355out:
356 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357 return ret;
358}
359
Holger Schurig10078322007-11-15 18:05:47 -0500360static int lbs_get_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200361 struct iw_request_info *info, u32 * uwrq, char *extra)
362{
Holger Schurig69f90322007-11-23 15:43:44 +0100363 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364
Holger Schurig9012b282007-05-25 11:27:16 -0400365 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200366
David Woodhouseaa21c002007-12-08 20:04:36 +0000367 *uwrq = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200368
Holger Schurig9012b282007-05-25 11:27:16 -0400369 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370 return 0;
371}
372
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400373static int mesh_wlan_get_mode(struct net_device *dev,
374 struct iw_request_info *info, u32 * uwrq,
375 char *extra)
376{
377 lbs_deb_enter(LBS_DEB_WEXT);
378
Dan Williams39fcf7a2008-09-10 12:49:00 -0400379 *uwrq = IW_MODE_REPEAT;
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -0400380
381 lbs_deb_leave(LBS_DEB_WEXT);
382 return 0;
383}
384
Holger Schurig10078322007-11-15 18:05:47 -0500385static int lbs_get_txpow(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386 struct iw_request_info *info,
387 struct iw_param *vwrq, char *extra)
388{
Holger Schurig69f90322007-11-23 15:43:44 +0100389 struct lbs_private *priv = dev->priv;
Dan Williams87c8c722008-08-19 15:15:35 -0400390 s16 curlevel = 0;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400391 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392
Holger Schurig9012b282007-05-25 11:27:16 -0400393 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200394
Dan Williamsd5db2df2008-08-21 17:51:07 -0400395 if (!priv->radio_on) {
396 lbs_deb_wext("tx power off\n");
397 vwrq->value = 0;
398 vwrq->disabled = 1;
399 goto out;
400 }
401
Dan Williams87c8c722008-08-19 15:15:35 -0400402 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
Holger Schurig9012b282007-05-25 11:27:16 -0400403 if (ret)
404 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200405
Dan Williams87c8c722008-08-19 15:15:35 -0400406 lbs_deb_wext("tx power level %d dbm\n", curlevel);
Dan Williams87c8c722008-08-19 15:15:35 -0400407 priv->txpower_cur = curlevel;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400408
Dan Williams87c8c722008-08-19 15:15:35 -0400409 vwrq->value = curlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410 vwrq->fixed = 1;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400411 vwrq->disabled = 0;
412 vwrq->flags = IW_TXPOW_DBM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413
Holger Schurig9012b282007-05-25 11:27:16 -0400414out:
415 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
416 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417}
418
Holger Schurig10078322007-11-15 18:05:47 -0500419static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200420 struct iw_param *vwrq, char *extra)
421{
Holger Schurig69f90322007-11-23 15:43:44 +0100422 struct lbs_private *priv = dev->priv;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400423 int ret = 0;
424 u16 slimit = 0, llimit = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425
Holger Schurig9012b282007-05-25 11:27:16 -0400426 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200427
Dan Williams39fcf7a2008-09-10 12:49:00 -0400428 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
429 return -EOPNOTSUPP;
430
431 /* The MAC has a 4-bit Total_Tx_Count register
432 Total_Tx_Count = 1 + Tx_Retry_Count */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433#define TX_RETRY_MIN 0
434#define TX_RETRY_MAX 14
Dan Williams39fcf7a2008-09-10 12:49:00 -0400435 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
436 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437
Dan Williams39fcf7a2008-09-10 12:49:00 -0400438 /* Add 1 to convert retry count to try count */
439 if (vwrq->flags & IW_RETRY_SHORT)
440 slimit = (u16) (vwrq->value + 1);
441 else if (vwrq->flags & IW_RETRY_LONG)
442 llimit = (u16) (vwrq->value + 1);
443 else
444 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200445
Dan Williams39fcf7a2008-09-10 12:49:00 -0400446 if (llimit) {
447 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
448 llimit);
Holger Schurig9012b282007-05-25 11:27:16 -0400449 if (ret)
450 goto out;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400451 }
452
453 if (slimit) {
454 /* txretrycount follows the short retry limit */
455 priv->txretrycount = slimit;
456 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
457 slimit);
458 if (ret)
459 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200460 }
461
Holger Schurig9012b282007-05-25 11:27:16 -0400462out:
463 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
464 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200465}
466
Holger Schurig10078322007-11-15 18:05:47 -0500467static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468 struct iw_param *vwrq, char *extra)
469{
Holger Schurig69f90322007-11-23 15:43:44 +0100470 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200471 int ret = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400472 u16 val = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200473
Holger Schurig9012b282007-05-25 11:27:16 -0400474 lbs_deb_enter(LBS_DEB_WEXT);
475
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 vwrq->disabled = 0;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400477
478 if (vwrq->flags & IW_RETRY_LONG) {
479 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
480 if (ret)
481 goto out;
482
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200483 /* Subtract 1 to convert try count to retry count */
Dan Williams39fcf7a2008-09-10 12:49:00 -0400484 vwrq->value = val - 1;
485 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
486 } else {
487 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
488 if (ret)
489 goto out;
490
491 /* txretry count follows the short retry limit */
492 priv->txretrycount = val;
493 /* Subtract 1 to convert try count to retry count */
494 vwrq->value = val - 1;
495 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496 }
497
Holger Schurig9012b282007-05-25 11:27:16 -0400498out:
499 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
500 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501}
502
503static inline void sort_channels(struct iw_freq *freq, int num)
504{
505 int i, j;
506 struct iw_freq temp;
507
508 for (i = 0; i < num; i++)
509 for (j = i + 1; j < num; j++)
510 if (freq[i].i > freq[j].i) {
511 temp.i = freq[i].i;
512 temp.m = freq[i].m;
513
514 freq[i].i = freq[j].i;
515 freq[i].m = freq[j].m;
516
517 freq[j].i = temp.i;
518 freq[j].m = temp.m;
519 }
520}
521
522/* data rate listing
523 MULTI_BANDS:
524 abg a b b/g
525 Infra G(12) A(8) B(4) G(12)
526 Adhoc A+B(12) A(8) B(4) B(4)
527
528 non-MULTI_BANDS:
529 b b/g
530 Infra B(4) G(12)
531 Adhoc B(4) B(4)
532 */
533/**
534 * @brief Get Range Info
535 *
536 * @param dev A pointer to net_device structure
537 * @param info A pointer to iw_request_info structure
538 * @param vwrq A pointer to iw_param structure
539 * @param extra A pointer to extra data buf
540 * @return 0 --success, otherwise fail
541 */
Holger Schurig10078322007-11-15 18:05:47 -0500542static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200543 struct iw_point *dwrq, char *extra)
544{
545 int i, j;
Holger Schurig69f90322007-11-23 15:43:44 +0100546 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547 struct iw_range *range = (struct iw_range *)extra;
548 struct chan_freq_power *cfp;
Dan Williams8c512762007-08-02 11:40:45 -0400549 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200550
551 u8 flag = 0;
552
Holger Schurig9012b282007-05-25 11:27:16 -0400553 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200554
555 dwrq->length = sizeof(struct iw_range);
556 memset(range, 0, sizeof(struct iw_range));
557
558 range->min_nwid = 0;
559 range->max_nwid = 0;
560
561 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +0000562 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -0400563 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
564 for (i = 0; i < range->num_bitrates; i++)
565 range->bitrate[i] = rates[i] * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200566 range->num_bitrates = i;
Holger Schurig9012b282007-05-25 11:27:16 -0400567 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568 range->num_bitrates);
569
570 range->num_frequency = 0;
Holger Schurig52933d82008-03-05 07:05:32 +0100571
572 range->scan_capa = IW_SCAN_CAPA_ESSID;
573
David Woodhouseaa21c002007-12-08 20:04:36 +0000574 if (priv->enable11d &&
575 (priv->connect_status == LBS_CONNECTED ||
576 priv->mesh_connect_status == LBS_CONNECTED)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200577 u8 chan_no;
578 u8 band;
579
580 struct parsed_region_chan_11d *parsed_region_chan =
David Woodhouseaa21c002007-12-08 20:04:36 +0000581 &priv->parsed_region_chan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200582
583 if (parsed_region_chan == NULL) {
Holger Schurig9012b282007-05-25 11:27:16 -0400584 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
585 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200586 }
587 band = parsed_region_chan->band;
Holger Schurig9012b282007-05-25 11:27:16 -0400588 lbs_deb_wext("band %d, nr_char %d\n", band,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200589 parsed_region_chan->nr_chan);
590
591 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
592 && (i < parsed_region_chan->nr_chan); i++) {
593 chan_no = parsed_region_chan->chanpwr[i].chan;
Holger Schurig9012b282007-05-25 11:27:16 -0400594 lbs_deb_wext("chan_no %d\n", chan_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200595 range->freq[range->num_frequency].i = (long)chan_no;
596 range->freq[range->num_frequency].m =
Holger Schurige98a88d2008-03-19 14:25:58 +0100597 (long)lbs_chan_2_freq(chan_no) * 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200598 range->freq[range->num_frequency].e = 1;
599 range->num_frequency++;
600 }
601 flag = 1;
602 }
603 if (!flag) {
604 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000605 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
606 cfp = priv->region_channel[j].CFP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200607 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
David Woodhouseaa21c002007-12-08 20:04:36 +0000608 && priv->region_channel[j].valid
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609 && cfp
David Woodhouseaa21c002007-12-08 20:04:36 +0000610 && (i < priv->region_channel[j].nrcfp); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611 range->freq[range->num_frequency].i =
612 (long)cfp->channel;
613 range->freq[range->num_frequency].m =
614 (long)cfp->freq * 100000;
615 range->freq[range->num_frequency].e = 1;
616 cfp++;
617 range->num_frequency++;
618 }
619 }
620 }
621
Holger Schurig9012b282007-05-25 11:27:16 -0400622 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623 IW_MAX_FREQUENCIES, range->num_frequency);
624
625 range->num_channels = range->num_frequency;
626
627 sort_channels(&range->freq[0], range->num_frequency);
628
629 /*
630 * Set an indication of the max TCP throughput in bit/s that we can
631 * expect using this interface
632 */
633 if (i > 2)
634 range->throughput = 5000 * 1000;
635 else
636 range->throughput = 1500 * 1000;
637
638 range->min_rts = MRVDRV_RTS_MIN_VALUE;
639 range->max_rts = MRVDRV_RTS_MAX_VALUE;
640 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
641 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
642
643 range->encoding_size[0] = 5;
644 range->encoding_size[1] = 13;
645 range->num_encoding_sizes = 2;
646 range->max_encoding_tokens = 4;
647
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100648 /*
649 * Right now we support only "iwconfig ethX power on|off"
650 */
651 range->pm_capa = IW_POWER_ON;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200652
653 /*
654 * Minimum version we recommend
655 */
656 range->we_version_source = 15;
657
658 /*
659 * Version we are compiled with
660 */
661 range->we_version_compiled = WIRELESS_EXT;
662
663 range->retry_capa = IW_RETRY_LIMIT;
664 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
665
666 range->min_retry = TX_RETRY_MIN;
667 range->max_retry = TX_RETRY_MAX;
668
669 /*
670 * Set the qual, level and noise range values
671 */
672 range->max_qual.qual = 100;
673 range->max_qual.level = 0;
674 range->max_qual.noise = 0;
675 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
676
677 range->avg_qual.qual = 70;
678 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
679 range->avg_qual.level = 0;
680 range->avg_qual.noise = 0;
681 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
682
683 range->sensitivity = 0;
684
Dan Williams87c8c722008-08-19 15:15:35 -0400685 /* Setup the supported power level ranges */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200686 memset(range->txpower, 0, sizeof(range->txpower));
Dan Williams87c8c722008-08-19 15:15:35 -0400687 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
688 range->txpower[0] = priv->txpower_min;
689 range->txpower[1] = priv->txpower_max;
690 range->num_txpower = 2;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200691
692 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
693 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
694 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
695 range->event_capa[1] = IW_EVENT_CAPA_K_1;
696
David Woodhouseaa21c002007-12-08 20:04:36 +0000697 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200698 range->enc_capa = IW_ENC_CAPA_WPA
699 | IW_ENC_CAPA_WPA2
700 | IW_ENC_CAPA_CIPHER_TKIP
701 | IW_ENC_CAPA_CIPHER_CCMP;
702 }
703
Holger Schurig9012b282007-05-25 11:27:16 -0400704out:
705 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200706 return 0;
707}
708
Holger Schurig10078322007-11-15 18:05:47 -0500709static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200710 struct iw_param *vwrq, char *extra)
711{
Holger Schurig69f90322007-11-23 15:43:44 +0100712 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200713
Holger Schurig9012b282007-05-25 11:27:16 -0400714 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715
David Woodhouseb2c57ee2007-12-17 14:41:13 -0500716 if (!priv->ps_supported) {
717 if (vwrq->disabled)
718 return 0;
719 else
720 return -EINVAL;
721 }
722
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200723 /* PS is currently supported only in Infrastructure mode
724 * Remove this check if it is to be supported in IBSS mode also
725 */
726
727 if (vwrq->disabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000728 priv->psmode = LBS802_11POWERMODECAM;
729 if (priv->psstate != PS_STATE_FULL_POWER) {
Holger Schurig10078322007-11-15 18:05:47 -0500730 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731 }
732
733 return 0;
734 }
735
736 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
Holger Schurig9012b282007-05-25 11:27:16 -0400737 lbs_deb_wext(
738 "setting power timeout is not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200739 return -EINVAL;
740 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
Holger Schurig9012b282007-05-25 11:27:16 -0400741 lbs_deb_wext("setting power period not supported\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200742 return -EINVAL;
743 }
744
David Woodhouseaa21c002007-12-08 20:04:36 +0000745 if (priv->psmode != LBS802_11POWERMODECAM) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200746 return 0;
747 }
748
David Woodhouseaa21c002007-12-08 20:04:36 +0000749 priv->psmode = LBS802_11POWERMODEMAX_PSP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200750
David Woodhouseaa21c002007-12-08 20:04:36 +0000751 if (priv->connect_status == LBS_CONNECTED) {
Holger Schurig10078322007-11-15 18:05:47 -0500752 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200753 }
754
Holger Schurig9012b282007-05-25 11:27:16 -0400755 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200756 return 0;
757}
758
Holger Schurig10078322007-11-15 18:05:47 -0500759static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200760 struct iw_param *vwrq, char *extra)
761{
Holger Schurig69f90322007-11-23 15:43:44 +0100762 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200763
Holger Schurig9012b282007-05-25 11:27:16 -0400764 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200765
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200766 vwrq->value = 0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +0100767 vwrq->flags = 0;
768 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
769 || priv->connect_status == LBS_DISCONNECTED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200770
Holger Schurig9012b282007-05-25 11:27:16 -0400771 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200772 return 0;
773}
774
Holger Schurig10078322007-11-15 18:05:47 -0500775static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200776{
777 enum {
778 POOR = 30,
779 FAIR = 60,
780 GOOD = 80,
781 VERY_GOOD = 90,
782 EXCELLENT = 95,
783 PERFECT = 100
784 };
Holger Schurig69f90322007-11-23 15:43:44 +0100785 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200786 u32 rssi_qual;
787 u32 tx_qual;
788 u32 quality = 0;
789 int stats_valid = 0;
790 u8 rssi;
791 u32 tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100792 struct cmd_ds_802_11_get_log log;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793
Holger Schurig9012b282007-05-25 11:27:16 -0400794 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200795
David Woodhouseaa21c002007-12-08 20:04:36 +0000796 priv->wstats.status = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200797
798 /* If we're not associated, all quality values are meaningless */
David Woodhouseaa21c002007-12-08 20:04:36 +0000799 if ((priv->connect_status != LBS_CONNECTED) &&
800 (priv->mesh_connect_status != LBS_CONNECTED))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801 goto out;
802
803 /* Quality by RSSI */
804 priv->wstats.qual.level =
David Woodhouseaa21c002007-12-08 20:04:36 +0000805 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
806 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200807
David Woodhouseaa21c002007-12-08 20:04:36 +0000808 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200809 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
810 } else {
811 priv->wstats.qual.noise =
David Woodhouseaa21c002007-12-08 20:04:36 +0000812 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813 }
814
Holger Schurig9012b282007-05-25 11:27:16 -0400815 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
816 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200817
818 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
819 if (rssi < 15)
820 rssi_qual = rssi * POOR / 10;
821 else if (rssi < 20)
822 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
823 else if (rssi < 30)
824 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
825 else if (rssi < 40)
826 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
827 10 + GOOD;
828 else
829 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
830 10 + VERY_GOOD;
831 quality = rssi_qual;
832
833 /* Quality by TX errors */
834 priv->wstats.discard.retries = priv->stats.tx_errors;
835
Holger Schurigc49c3b72008-03-17 12:45:58 +0100836 memset(&log, 0, sizeof(log));
837 log.hdr.size = cpu_to_le16(sizeof(log));
838 lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
839
840 tx_retries = le32_to_cpu(log.retry);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200841
842 if (tx_retries > 75)
843 tx_qual = (90 - tx_retries) * POOR / 15;
844 else if (tx_retries > 70)
845 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
846 else if (tx_retries > 65)
847 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
848 else if (tx_retries > 50)
849 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
850 15 + GOOD;
851 else
852 tx_qual = (50 - tx_retries) *
853 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
854 quality = min(quality, tx_qual);
855
Holger Schurigc49c3b72008-03-17 12:45:58 +0100856 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200857 priv->wstats.discard.retries = tx_retries;
Holger Schurigc49c3b72008-03-17 12:45:58 +0100858 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200859
860 /* Calculate quality */
Holger Schurigcad9d9b2007-08-02 13:07:15 -0400861 priv->wstats.qual.qual = min_t(u8, quality, 100);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200862 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
863 stats_valid = 1;
864
865 /* update stats asynchronously for future calls */
Holger Schurig10078322007-11-15 18:05:47 -0500866 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200867 0, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200868out:
869 if (!stats_valid) {
870 priv->wstats.miss.beacon = 0;
871 priv->wstats.discard.retries = 0;
872 priv->wstats.qual.qual = 0;
873 priv->wstats.qual.level = 0;
874 priv->wstats.qual.noise = 0;
875 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
876 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
877 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
878 }
879
Holger Schurig9012b282007-05-25 11:27:16 -0400880 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200881 return &priv->wstats;
882
883
884}
885
Holger Schurig10078322007-11-15 18:05:47 -0500886static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200887 struct iw_freq *fwrq, char *extra)
888{
Dan Williamsef9a2642007-05-25 16:46:33 -0400889 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +0100890 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200891 struct chan_freq_power *cfp;
Dan Williamsef9a2642007-05-25 16:46:33 -0400892 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200893
Holger Schurig9012b282007-05-25 11:27:16 -0400894 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200895
David Woodhouseaa21c002007-12-08 20:04:36 +0000896 mutex_lock(&priv->lock);
897 assoc_req = lbs_get_association_request(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400898 if (!assoc_req) {
899 ret = -ENOMEM;
900 goto out;
901 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200902
Dan Williamsef9a2642007-05-25 16:46:33 -0400903 /* If setting by frequency, convert to a channel */
904 if (fwrq->e == 1) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905 long f = fwrq->m / 100000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200906
David Woodhouseaa21c002007-12-08 20:04:36 +0000907 cfp = find_cfp_by_band_and_freq(priv, 0, f);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200908 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -0400909 lbs_deb_wext("invalid freq %ld\n", f);
Dan Williamsef9a2642007-05-25 16:46:33 -0400910 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200911 }
912
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200913 fwrq->e = 0;
Dan Williamsef9a2642007-05-25 16:46:33 -0400914 fwrq->m = (int) cfp->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200915 }
916
Dan Williamsef9a2642007-05-25 16:46:33 -0400917 /* Setting by channel number */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200918 if (fwrq->m > 1000 || fwrq->e > 0) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400919 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200920 }
921
David Woodhouseaa21c002007-12-08 20:04:36 +0000922 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
Dan Williamsef9a2642007-05-25 16:46:33 -0400923 if (!cfp) {
924 goto out;
925 }
926
927 assoc_req->channel = fwrq->m;
928 ret = 0;
929
Holger Schurig9012b282007-05-25 11:27:16 -0400930out:
Dan Williamsef9a2642007-05-25 16:46:33 -0400931 if (ret == 0) {
932 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500933 lbs_postpone_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400934 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500935 lbs_cancel_association_work(priv);
Dan Williamsef9a2642007-05-25 16:46:33 -0400936 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000937 mutex_unlock(&priv->lock);
Dan Williamsef9a2642007-05-25 16:46:33 -0400938
939 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
940 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200941}
942
David Woodhouse823eaa22007-12-11 19:56:28 -0500943static int lbs_mesh_set_freq(struct net_device *dev,
944 struct iw_request_info *info,
945 struct iw_freq *fwrq, char *extra)
946{
947 struct lbs_private *priv = dev->priv;
948 struct chan_freq_power *cfp;
949 int ret = -EINVAL;
950
951 lbs_deb_enter(LBS_DEB_WEXT);
952
953 /* If setting by frequency, convert to a channel */
954 if (fwrq->e == 1) {
955 long f = fwrq->m / 100000;
956
957 cfp = find_cfp_by_band_and_freq(priv, 0, f);
958 if (!cfp) {
959 lbs_deb_wext("invalid freq %ld\n", f);
960 goto out;
961 }
962
963 fwrq->e = 0;
964 fwrq->m = (int) cfp->channel;
965 }
966
967 /* Setting by channel number */
968 if (fwrq->m > 1000 || fwrq->e > 0) {
969 goto out;
970 }
971
972 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
973 if (!cfp) {
974 goto out;
975 }
976
977 if (fwrq->m != priv->curbssparams.channel) {
978 lbs_deb_wext("mesh channel change forces eth disconnect\n");
979 if (priv->mode == IW_MODE_INFRA)
Dan Williams191bb402008-08-21 17:46:18 -0400980 lbs_cmd_80211_deauthenticate(priv,
981 priv->curbssparams.bssid,
982 WLAN_REASON_DEAUTH_LEAVING);
David Woodhouse823eaa22007-12-11 19:56:28 -0500983 else if (priv->mode == IW_MODE_ADHOC)
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400984 lbs_adhoc_stop(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -0500985 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -0700986 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
David Woodhouse86062132007-12-13 00:32:36 -0500987 lbs_update_channel(priv);
David Woodhouse823eaa22007-12-11 19:56:28 -0500988 ret = 0;
989
990out:
991 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
992 return ret;
993}
994
Holger Schurig10078322007-11-15 18:05:47 -0500995static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200996 struct iw_param *vwrq, char *extra)
997{
Holger Schurig69f90322007-11-23 15:43:44 +0100998 struct lbs_private *priv = dev->priv;
Dan Williams8e3c91b2007-12-11 15:50:59 -0500999 u8 new_rate = 0;
Dan Williams8c512762007-08-02 11:40:45 -04001000 int ret = -EINVAL;
1001 u8 rates[MAX_RATES + 1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001002
Holger Schurig9012b282007-05-25 11:27:16 -04001003 lbs_deb_enter(LBS_DEB_WEXT);
Holger Schurig9012b282007-05-25 11:27:16 -04001004 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
Javier Cardona85319f92008-05-24 10:59:49 +01001005 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1006
1007 if (vwrq->fixed && vwrq->value == -1)
1008 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001009
Dan Williams8c512762007-08-02 11:40:45 -04001010 /* Auto rate? */
Javier Cardona85319f92008-05-24 10:59:49 +01001011 priv->enablehwauto = !vwrq->fixed;
1012
1013 if (vwrq->value == -1)
David Woodhouseaa21c002007-12-08 20:04:36 +00001014 priv->cur_rate = 0;
Javier Cardona85319f92008-05-24 10:59:49 +01001015 else {
Dan Williams8c512762007-08-02 11:40:45 -04001016 if (vwrq->value % 100000)
1017 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001018
Javier Cardona85319f92008-05-24 10:59:49 +01001019 new_rate = vwrq->value / 500000;
1020 priv->cur_rate = new_rate;
1021 /* the rest is only needed for lbs_set_data_rate() */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001022 memset(rates, 0, sizeof(rates));
David Woodhouseaa21c002007-12-08 20:04:36 +00001023 copy_active_data_rates(priv, rates);
Dan Williams8c512762007-08-02 11:40:45 -04001024 if (!memchr(rates, new_rate, sizeof(rates))) {
1025 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1026 new_rate);
1027 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001028 }
Anna Neal3ed6e082008-09-26 11:34:35 -04001029 if (priv->fwrelease < 0x09000000) {
1030 ret = lbs_set_power_adapt_cfg(priv, 0,
1031 POW_ADAPT_DEFAULT_P0,
1032 POW_ADAPT_DEFAULT_P1,
1033 POW_ADAPT_DEFAULT_P2);
1034 if (ret)
1035 goto out;
1036 }
1037 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1038 TPC_DEFAULT_P2, 1);
1039 if (ret)
1040 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001041 }
1042
Javier Cardona85319f92008-05-24 10:59:49 +01001043 /* Try the newer command first (Firmware Spec 5.1 and above) */
1044 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1045
1046 /* Fallback to older version */
1047 if (ret)
1048 ret = lbs_set_data_rate(priv, new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001049
Dan Williams8c512762007-08-02 11:40:45 -04001050out:
Holger Schurig9012b282007-05-25 11:27:16 -04001051 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001052 return ret;
1053}
1054
Holger Schurig10078322007-11-15 18:05:47 -05001055static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001056 struct iw_param *vwrq, char *extra)
1057{
Holger Schurig69f90322007-11-23 15:43:44 +01001058 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001059
Holger Schurig9012b282007-05-25 11:27:16 -04001060 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001061
David Woodhouseaa21c002007-12-08 20:04:36 +00001062 if (priv->connect_status == LBS_CONNECTED) {
1063 vwrq->value = priv->cur_rate * 500000;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064
Javier Cardona85319f92008-05-24 10:59:49 +01001065 if (priv->enablehwauto)
Dan Williams8c512762007-08-02 11:40:45 -04001066 vwrq->fixed = 0;
1067 else
1068 vwrq->fixed = 1;
1069
1070 } else {
1071 vwrq->fixed = 0;
1072 vwrq->value = 0;
1073 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001074
Holger Schurig9012b282007-05-25 11:27:16 -04001075 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001076 return 0;
1077}
1078
Holger Schurig10078322007-11-15 18:05:47 -05001079static int lbs_set_mode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001080 struct iw_request_info *info, u32 * uwrq, char *extra)
1081{
1082 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001083 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001084 struct assoc_request * assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001085
Holger Schurig9012b282007-05-25 11:27:16 -04001086 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001087
Dan Williams0dc5a292007-05-10 22:58:02 -04001088 if ( (*uwrq != IW_MODE_ADHOC)
1089 && (*uwrq != IW_MODE_INFRA)
1090 && (*uwrq != IW_MODE_AUTO)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001091 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
Dan Williams0dc5a292007-05-10 22:58:02 -04001092 ret = -EINVAL;
1093 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001094 }
1095
David Woodhouseaa21c002007-12-08 20:04:36 +00001096 mutex_lock(&priv->lock);
1097 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001098 if (!assoc_req) {
1099 ret = -ENOMEM;
Holger Schurig10078322007-11-15 18:05:47 -05001100 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001101 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001102 assoc_req->mode = *uwrq;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001103 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001104 lbs_postpone_association_work(priv);
Holger Schurig9012b282007-05-25 11:27:16 -04001105 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001106 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001107 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001108
Dan Williams0dc5a292007-05-10 22:58:02 -04001109out:
Holger Schurig9012b282007-05-25 11:27:16 -04001110 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001111 return ret;
1112}
1113
1114
1115/**
1116 * @brief Get Encryption key
1117 *
1118 * @param dev A pointer to net_device structure
1119 * @param info A pointer to iw_request_info structure
1120 * @param vwrq A pointer to iw_param structure
1121 * @param extra A pointer to extra data buf
1122 * @return 0 --success, otherwise fail
1123 */
Holger Schurig10078322007-11-15 18:05:47 -05001124static int lbs_get_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001125 struct iw_request_info *info,
1126 struct iw_point *dwrq, u8 * extra)
1127{
Holger Schurig69f90322007-11-23 15:43:44 +01001128 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001129 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1130
Holger Schurig9012b282007-05-25 11:27:16 -04001131 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001132
Holger Schurig9012b282007-05-25 11:27:16 -04001133 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001134 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001135
1136 dwrq->flags = 0;
1137
1138 /* Authentication method */
David Woodhouseaa21c002007-12-08 20:04:36 +00001139 switch (priv->secinfo.auth_mode) {
Dan Williams6affe782007-05-10 22:56:42 -04001140 case IW_AUTH_ALG_OPEN_SYSTEM:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001141 dwrq->flags = IW_ENCODE_OPEN;
1142 break;
1143
Dan Williams6affe782007-05-10 22:56:42 -04001144 case IW_AUTH_ALG_SHARED_KEY:
1145 case IW_AUTH_ALG_LEAP:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001146 dwrq->flags = IW_ENCODE_RESTRICTED;
1147 break;
1148 default:
1149 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1150 break;
1151 }
1152
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001153 memset(extra, 0, 16);
1154
David Woodhouseaa21c002007-12-08 20:04:36 +00001155 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001156
1157 /* Default to returning current transmit key */
1158 if (index < 0)
David Woodhouseaa21c002007-12-08 20:04:36 +00001159 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001160
David Woodhouseaa21c002007-12-08 20:04:36 +00001161 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1162 memcpy(extra, priv->wep_keys[index].key,
1163 priv->wep_keys[index].len);
1164 dwrq->length = priv->wep_keys[index].len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001165
1166 dwrq->flags |= (index + 1);
1167 /* Return WEP enabled */
1168 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhouseaa21c002007-12-08 20:04:36 +00001169 } else if ((priv->secinfo.WPAenabled)
1170 || (priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001171 /* return WPA enabled */
1172 dwrq->flags &= ~IW_ENCODE_DISABLED;
David Woodhousec12bdc42007-12-07 19:32:12 +00001173 dwrq->flags |= IW_ENCODE_NOKEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001174 } else {
1175 dwrq->flags |= IW_ENCODE_DISABLED;
1176 }
1177
David Woodhouseaa21c002007-12-08 20:04:36 +00001178 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001179
Joe Perches0795af52007-10-03 17:59:30 -07001180 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001181 extra[0], extra[1], extra[2],
1182 extra[3], extra[4], extra[5], dwrq->length);
1183
Holger Schurig9012b282007-05-25 11:27:16 -04001184 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001185
Holger Schurig9012b282007-05-25 11:27:16 -04001186 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001187 return 0;
1188}
1189
1190/**
1191 * @brief Set Encryption key (internal)
1192 *
1193 * @param priv A pointer to private card structure
1194 * @param key_material A pointer to key material
1195 * @param key_length length of key material
1196 * @param index key index to set
1197 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1198 * @return 0 --success, otherwise fail
1199 */
Holger Schurig10078322007-11-15 18:05:47 -05001200static int lbs_set_wep_key(struct assoc_request *assoc_req,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001201 const char *key_material,
1202 u16 key_length,
1203 u16 index,
1204 int set_tx_key)
1205{
Holger Schurig9012b282007-05-25 11:27:16 -04001206 int ret = 0;
Dan Williams1443b652007-08-02 10:45:55 -04001207 struct enc_key *pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001208
Holger Schurig9012b282007-05-25 11:27:16 -04001209 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001210
1211 /* Paranoid validation of key index */
1212 if (index > 3) {
Holger Schurig9012b282007-05-25 11:27:16 -04001213 ret = -EINVAL;
1214 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001215 }
1216
1217 /* validate max key length */
1218 if (key_length > KEY_LEN_WEP_104) {
Holger Schurig9012b282007-05-25 11:27:16 -04001219 ret = -EINVAL;
1220 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001221 }
1222
1223 pkey = &assoc_req->wep_keys[index];
1224
1225 if (key_length > 0) {
Dan Williams1443b652007-08-02 10:45:55 -04001226 memset(pkey, 0, sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001227 pkey->type = KEY_TYPE_ID_WEP;
1228
1229 /* Standardize the key length */
1230 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1231 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1232 memcpy(pkey->key, key_material, key_length);
1233 }
1234
1235 if (set_tx_key) {
1236 /* Ensure the chosen key is valid */
1237 if (!pkey->len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001238 lbs_deb_wext("key not set, so cannot enable it\n");
1239 ret = -EINVAL;
1240 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001241 }
1242 assoc_req->wep_tx_keyidx = index;
1243 }
1244
Dan Williams889c05b2007-05-10 22:57:23 -04001245 assoc_req->secinfo.wep_enabled = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001246
Holger Schurig9012b282007-05-25 11:27:16 -04001247out:
1248 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1249 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001250}
1251
1252static int validate_key_index(u16 def_index, u16 raw_index,
1253 u16 *out_index, u16 *is_default)
1254{
1255 if (!out_index || !is_default)
1256 return -EINVAL;
1257
1258 /* Verify index if present, otherwise use default TX key index */
1259 if (raw_index > 0) {
1260 if (raw_index > 4)
1261 return -EINVAL;
1262 *out_index = raw_index - 1;
1263 } else {
1264 *out_index = def_index;
1265 *is_default = 1;
1266 }
1267 return 0;
1268}
1269
1270static void disable_wep(struct assoc_request *assoc_req)
1271{
1272 int i;
1273
Dan Williams90a42212007-05-25 23:01:24 -04001274 lbs_deb_enter(LBS_DEB_WEXT);
1275
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001276 /* Set Open System auth mode */
Dan Williams6affe782007-05-10 22:56:42 -04001277 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001278
1279 /* Clear WEP keys and mark WEP as disabled */
Dan Williams889c05b2007-05-10 22:57:23 -04001280 assoc_req->secinfo.wep_enabled = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001281 for (i = 0; i < 4; i++)
1282 assoc_req->wep_keys[i].len = 0;
1283
1284 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1285 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
Dan Williams90a42212007-05-25 23:01:24 -04001286
1287 lbs_deb_leave(LBS_DEB_WEXT);
1288}
1289
1290static void disable_wpa(struct assoc_request *assoc_req)
1291{
1292 lbs_deb_enter(LBS_DEB_WEXT);
1293
Dan Williams1443b652007-08-02 10:45:55 -04001294 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001295 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1296 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1297
Dan Williams1443b652007-08-02 10:45:55 -04001298 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
Dan Williams90a42212007-05-25 23:01:24 -04001299 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1300 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1301
1302 assoc_req->secinfo.WPAenabled = 0;
1303 assoc_req->secinfo.WPA2enabled = 0;
1304 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1305
1306 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001307}
1308
1309/**
1310 * @brief Set Encryption key
1311 *
1312 * @param dev A pointer to net_device structure
1313 * @param info A pointer to iw_request_info structure
1314 * @param vwrq A pointer to iw_param structure
1315 * @param extra A pointer to extra data buf
1316 * @return 0 --success, otherwise fail
1317 */
Holger Schurig10078322007-11-15 18:05:47 -05001318static int lbs_set_encode(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001319 struct iw_request_info *info,
1320 struct iw_point *dwrq, char *extra)
1321{
1322 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001323 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001324 struct assoc_request * assoc_req;
1325 u16 is_default = 0, index = 0, set_tx_key = 0;
1326
Holger Schurig9012b282007-05-25 11:27:16 -04001327 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001328
David Woodhouseaa21c002007-12-08 20:04:36 +00001329 mutex_lock(&priv->lock);
1330 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001331 if (!assoc_req) {
1332 ret = -ENOMEM;
1333 goto out;
1334 }
1335
1336 if (dwrq->flags & IW_ENCODE_DISABLED) {
1337 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001338 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001339 goto out;
1340 }
1341
1342 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1343 (dwrq->flags & IW_ENCODE_INDEX),
1344 &index, &is_default);
1345 if (ret) {
1346 ret = -EINVAL;
1347 goto out;
1348 }
1349
1350 /* If WEP isn't enabled, or if there is no key data but a valid
1351 * index, set the TX key.
1352 */
Dan Williams889c05b2007-05-10 22:57:23 -04001353 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001354 set_tx_key = 1;
1355
Holger Schurig10078322007-11-15 18:05:47 -05001356 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001357 if (ret)
1358 goto out;
1359
1360 if (dwrq->length)
1361 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1362 if (set_tx_key)
1363 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1364
1365 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001366 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001368 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001369 }
1370
1371out:
1372 if (ret == 0) {
1373 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001374 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001375 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001376 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001377 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001378 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001379
Holger Schurig9012b282007-05-25 11:27:16 -04001380 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001381 return ret;
1382}
1383
1384/**
1385 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1386 *
1387 * @param dev A pointer to net_device structure
1388 * @param info A pointer to iw_request_info structure
1389 * @param vwrq A pointer to iw_param structure
1390 * @param extra A pointer to extra data buf
1391 * @return 0 on success, otherwise failure
1392 */
Holger Schurig10078322007-11-15 18:05:47 -05001393static int lbs_get_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001394 struct iw_request_info *info,
1395 struct iw_point *dwrq,
1396 char *extra)
1397{
1398 int ret = -EINVAL;
Holger Schurig69f90322007-11-23 15:43:44 +01001399 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001400 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1401 int index, max_key_len;
1402
Holger Schurig9012b282007-05-25 11:27:16 -04001403 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001404
1405 max_key_len = dwrq->length - sizeof(*ext);
1406 if (max_key_len < 0)
1407 goto out;
1408
1409 index = dwrq->flags & IW_ENCODE_INDEX;
1410 if (index) {
1411 if (index < 1 || index > 4)
1412 goto out;
1413 index--;
1414 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001415 index = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001416 }
1417
Roel Kluinf59d9782007-10-26 21:51:26 +02001418 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001419 ext->alg != IW_ENCODE_ALG_WEP) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001420 if (index != 0 || priv->mode != IW_MODE_INFRA)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001421 goto out;
1422 }
1423
1424 dwrq->flags = index + 1;
1425 memset(ext, 0, sizeof(*ext));
1426
David Woodhouseaa21c002007-12-08 20:04:36 +00001427 if ( !priv->secinfo.wep_enabled
1428 && !priv->secinfo.WPAenabled
1429 && !priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001430 ext->alg = IW_ENCODE_ALG_NONE;
1431 ext->key_len = 0;
1432 dwrq->flags |= IW_ENCODE_DISABLED;
1433 } else {
1434 u8 *key = NULL;
1435
David Woodhouseaa21c002007-12-08 20:04:36 +00001436 if ( priv->secinfo.wep_enabled
1437 && !priv->secinfo.WPAenabled
1438 && !priv->secinfo.WPA2enabled) {
Dan Williams90a42212007-05-25 23:01:24 -04001439 /* WEP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001440 ext->alg = IW_ENCODE_ALG_WEP;
David Woodhouseaa21c002007-12-08 20:04:36 +00001441 ext->key_len = priv->wep_keys[index].len;
1442 key = &priv->wep_keys[index].key[0];
1443 } else if ( !priv->secinfo.wep_enabled
1444 && (priv->secinfo.WPAenabled ||
1445 priv->secinfo.WPA2enabled)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001446 /* WPA */
Dan Williams1443b652007-08-02 10:45:55 -04001447 struct enc_key * pkey = NULL;
Dan Williams90a42212007-05-25 23:01:24 -04001448
David Woodhouseaa21c002007-12-08 20:04:36 +00001449 if ( priv->wpa_mcast_key.len
1450 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1451 pkey = &priv->wpa_mcast_key;
1452 else if ( priv->wpa_unicast_key.len
1453 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1454 pkey = &priv->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001455
1456 if (pkey) {
1457 if (pkey->type == KEY_TYPE_ID_AES) {
1458 ext->alg = IW_ENCODE_ALG_CCMP;
1459 } else {
1460 ext->alg = IW_ENCODE_ALG_TKIP;
1461 }
1462 ext->key_len = pkey->len;
1463 key = &pkey->key[0];
1464 } else {
1465 ext->alg = IW_ENCODE_ALG_TKIP;
1466 ext->key_len = 0;
1467 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001468 } else {
1469 goto out;
1470 }
1471
1472 if (ext->key_len > max_key_len) {
1473 ret = -E2BIG;
1474 goto out;
1475 }
1476
1477 if (ext->key_len)
1478 memcpy(ext->key, key, ext->key_len);
1479 else
1480 dwrq->flags |= IW_ENCODE_NOKEY;
1481 dwrq->flags |= IW_ENCODE_ENABLED;
1482 }
1483 ret = 0;
1484
1485out:
Holger Schurig9012b282007-05-25 11:27:16 -04001486 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487 return ret;
1488}
1489
1490/**
1491 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1492 *
1493 * @param dev A pointer to net_device structure
1494 * @param info A pointer to iw_request_info structure
1495 * @param vwrq A pointer to iw_param structure
1496 * @param extra A pointer to extra data buf
1497 * @return 0 --success, otherwise fail
1498 */
Holger Schurig10078322007-11-15 18:05:47 -05001499static int lbs_set_encodeext(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001500 struct iw_request_info *info,
1501 struct iw_point *dwrq,
1502 char *extra)
1503{
1504 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001505 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001506 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1507 int alg = ext->alg;
1508 struct assoc_request * assoc_req;
1509
Holger Schurig9012b282007-05-25 11:27:16 -04001510 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001511
David Woodhouseaa21c002007-12-08 20:04:36 +00001512 mutex_lock(&priv->lock);
1513 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001514 if (!assoc_req) {
1515 ret = -ENOMEM;
1516 goto out;
1517 }
1518
1519 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1520 disable_wep (assoc_req);
Dan Williams90a42212007-05-25 23:01:24 -04001521 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001522 } else if (alg == IW_ENCODE_ALG_WEP) {
1523 u16 is_default = 0, index, set_tx_key = 0;
1524
1525 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1526 (dwrq->flags & IW_ENCODE_INDEX),
1527 &index, &is_default);
1528 if (ret)
1529 goto out;
1530
1531 /* If WEP isn't enabled, or if there is no key data but a valid
1532 * index, or if the set-TX-key flag was passed, set the TX key.
1533 */
Dan Williams889c05b2007-05-10 22:57:23 -04001534 if ( !assoc_req->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001535 || (dwrq->length == 0 && !is_default)
1536 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1537 set_tx_key = 1;
1538
1539 /* Copy key to driver */
Holger Schurig10078322007-11-15 18:05:47 -05001540 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001541 set_tx_key);
1542 if (ret)
1543 goto out;
1544
1545 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
Dan Williams6affe782007-05-10 22:56:42 -04001546 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001547 } else if (dwrq->flags & IW_ENCODE_OPEN) {
Dan Williams6affe782007-05-10 22:56:42 -04001548 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001549 }
1550
1551 /* Mark the various WEP bits as modified */
1552 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1553 if (dwrq->length)
1554 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1555 if (set_tx_key)
1556 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001557 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
Dan Williams1443b652007-08-02 10:45:55 -04001558 struct enc_key * pkey;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001559
1560 /* validate key length */
1561 if (((alg == IW_ENCODE_ALG_TKIP)
1562 && (ext->key_len != KEY_LEN_WPA_TKIP))
1563 || ((alg == IW_ENCODE_ALG_CCMP)
1564 && (ext->key_len != KEY_LEN_WPA_AES))) {
Joe Perches8376e7a2007-11-19 17:48:27 -08001565 lbs_deb_wext("invalid size %d for key of alg "
Holger Schurig9012b282007-05-25 11:27:16 -04001566 "type %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001567 ext->key_len,
1568 alg);
1569 ret = -EINVAL;
1570 goto out;
1571 }
1572
Dan Williams90a42212007-05-25 23:01:24 -04001573 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001574 pkey = &assoc_req->wpa_mcast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001575 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1576 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001577 pkey = &assoc_req->wpa_unicast_key;
Dan Williams90a42212007-05-25 23:01:24 -04001578 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1579 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001580
Dan Williams1443b652007-08-02 10:45:55 -04001581 memset(pkey, 0, sizeof (struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001582 memcpy(pkey->key, ext->key, ext->key_len);
1583 pkey->len = ext->key_len;
Dan Williams90a42212007-05-25 23:01:24 -04001584 if (pkey->len)
1585 pkey->flags |= KEY_INFO_WPA_ENABLED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001586
Dan Williams90a42212007-05-25 23:01:24 -04001587 /* Do this after zeroing key structure */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001588 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1589 pkey->flags |= KEY_INFO_WPA_MCAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001590 } else {
1591 pkey->flags |= KEY_INFO_WPA_UNICAST;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001592 }
1593
Dan Williams90a42212007-05-25 23:01:24 -04001594 if (alg == IW_ENCODE_ALG_TKIP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001595 pkey->type = KEY_TYPE_ID_TKIP;
Dan Williams90a42212007-05-25 23:01:24 -04001596 } else if (alg == IW_ENCODE_ALG_CCMP) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001597 pkey->type = KEY_TYPE_ID_AES;
Dan Williams90a42212007-05-25 23:01:24 -04001598 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001599
1600 /* If WPA isn't enabled yet, do that now */
1601 if ( assoc_req->secinfo.WPAenabled == 0
1602 && assoc_req->secinfo.WPA2enabled == 0) {
1603 assoc_req->secinfo.WPAenabled = 1;
1604 assoc_req->secinfo.WPA2enabled = 1;
1605 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1606 }
1607
Javier Cardona9c31fd62008-09-11 15:32:50 -07001608 /* Only disable wep if necessary: can't waste time here. */
1609 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1610 disable_wep(assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001611 }
1612
1613out:
Javier Cardona9c40fc52008-09-16 18:08:39 -07001614 if (ret == 0) {
1615 /* 802.1x and WPA rekeying must happen as quickly as possible,
1616 * especially during the 4-way handshake; thus if in
1617 * infrastructure mode, and either (a) 802.1x is enabled or
1618 * (b) WPA is being used, set the key right away.
1619 */
1620 if (assoc_req->mode == IW_MODE_INFRA &&
1621 ((assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_802_1X) ||
1622 (assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_PSK) ||
1623 assoc_req->secinfo.WPAenabled ||
1624 assoc_req->secinfo.WPA2enabled)) {
1625 lbs_do_association_work(priv);
1626 } else
1627 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001628 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001629 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001630 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001631 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001632
Holger Schurig9012b282007-05-25 11:27:16 -04001633 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001634 return ret;
1635}
1636
1637
Holger Schurig10078322007-11-15 18:05:47 -05001638static int lbs_set_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001639 struct iw_request_info *info,
1640 struct iw_point *dwrq,
1641 char *extra)
1642{
Holger Schurig69f90322007-11-23 15:43:44 +01001643 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001644 int ret = 0;
1645 struct assoc_request * assoc_req;
1646
Holger Schurig9012b282007-05-25 11:27:16 -04001647 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001648
David Woodhouseaa21c002007-12-08 20:04:36 +00001649 mutex_lock(&priv->lock);
1650 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001651 if (!assoc_req) {
1652 ret = -ENOMEM;
1653 goto out;
1654 }
1655
1656 if (dwrq->length > MAX_WPA_IE_LEN ||
1657 (dwrq->length && extra == NULL)) {
1658 ret = -EINVAL;
1659 goto out;
1660 }
1661
1662 if (dwrq->length) {
1663 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1664 assoc_req->wpa_ie_len = dwrq->length;
1665 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001666 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001667 assoc_req->wpa_ie_len = 0;
1668 }
1669
1670out:
1671 if (ret == 0) {
1672 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001673 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001674 } else {
Holger Schurig10078322007-11-15 18:05:47 -05001675 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001676 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001677 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001678
Holger Schurig9012b282007-05-25 11:27:16 -04001679 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001680 return ret;
1681}
1682
Holger Schurig10078322007-11-15 18:05:47 -05001683static int lbs_get_genie(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001684 struct iw_request_info *info,
1685 struct iw_point *dwrq,
1686 char *extra)
1687{
Holger Schurig9012b282007-05-25 11:27:16 -04001688 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001689 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001690
Holger Schurig9012b282007-05-25 11:27:16 -04001691 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001692
David Woodhouseaa21c002007-12-08 20:04:36 +00001693 if (priv->wpa_ie_len == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001694 dwrq->length = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001695 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001696 }
1697
David Woodhouseaa21c002007-12-08 20:04:36 +00001698 if (dwrq->length < priv->wpa_ie_len) {
Holger Schurig9012b282007-05-25 11:27:16 -04001699 ret = -E2BIG;
1700 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001701 }
1702
David Woodhouseaa21c002007-12-08 20:04:36 +00001703 dwrq->length = priv->wpa_ie_len;
1704 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001705
Holger Schurig9012b282007-05-25 11:27:16 -04001706out:
1707 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1708 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001709}
1710
1711
Holger Schurig10078322007-11-15 18:05:47 -05001712static int lbs_set_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001713 struct iw_request_info *info,
1714 struct iw_param *dwrq,
1715 char *extra)
1716{
Holger Schurig69f90322007-11-23 15:43:44 +01001717 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001718 struct assoc_request * assoc_req;
1719 int ret = 0;
1720 int updated = 0;
1721
Holger Schurig9012b282007-05-25 11:27:16 -04001722 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001723
David Woodhouseaa21c002007-12-08 20:04:36 +00001724 mutex_lock(&priv->lock);
1725 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001726 if (!assoc_req) {
1727 ret = -ENOMEM;
1728 goto out;
1729 }
1730
1731 switch (dwrq->flags & IW_AUTH_INDEX) {
1732 case IW_AUTH_TKIP_COUNTERMEASURES:
1733 case IW_AUTH_CIPHER_PAIRWISE:
1734 case IW_AUTH_CIPHER_GROUP:
Dan Williams90a42212007-05-25 23:01:24 -04001735 case IW_AUTH_DROP_UNENCRYPTED:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001736 /*
1737 * libertas does not use these parameters
1738 */
1739 break;
1740
Javier Cardona9c40fc52008-09-16 18:08:39 -07001741 case IW_AUTH_KEY_MGMT:
1742 assoc_req->secinfo.key_mgmt = dwrq->value;
1743 updated = 1;
1744 break;
1745
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001746 case IW_AUTH_WPA_VERSION:
1747 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1748 assoc_req->secinfo.WPAenabled = 0;
1749 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001750 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001751 }
1752 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1753 assoc_req->secinfo.WPAenabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001754 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001755 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001756 }
1757 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1758 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001759 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001760 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001761 }
1762 updated = 1;
1763 break;
1764
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001765 case IW_AUTH_80211_AUTH_ALG:
1766 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
Dan Williams6affe782007-05-10 22:56:42 -04001767 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001768 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
Dan Williams6affe782007-05-10 22:56:42 -04001769 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001770 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
Dan Williams6affe782007-05-10 22:56:42 -04001771 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001772 } else {
1773 ret = -EINVAL;
1774 }
1775 updated = 1;
1776 break;
1777
1778 case IW_AUTH_WPA_ENABLED:
1779 if (dwrq->value) {
1780 if (!assoc_req->secinfo.WPAenabled &&
1781 !assoc_req->secinfo.WPA2enabled) {
1782 assoc_req->secinfo.WPAenabled = 1;
1783 assoc_req->secinfo.WPA2enabled = 1;
Dan Williams889c05b2007-05-10 22:57:23 -04001784 assoc_req->secinfo.wep_enabled = 0;
Dan Williams6affe782007-05-10 22:56:42 -04001785 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001786 }
1787 } else {
1788 assoc_req->secinfo.WPAenabled = 0;
1789 assoc_req->secinfo.WPA2enabled = 0;
Dan Williams90a42212007-05-25 23:01:24 -04001790 disable_wpa (assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001791 }
1792 updated = 1;
1793 break;
1794
1795 default:
1796 ret = -EOPNOTSUPP;
1797 break;
1798 }
1799
1800out:
1801 if (ret == 0) {
1802 if (updated)
1803 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05001804 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001805 } else if (ret != -EOPNOTSUPP) {
Holger Schurig10078322007-11-15 18:05:47 -05001806 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001807 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001808 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001809
Holger Schurig9012b282007-05-25 11:27:16 -04001810 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001811 return ret;
1812}
1813
Holger Schurig10078322007-11-15 18:05:47 -05001814static int lbs_get_auth(struct net_device *dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001815 struct iw_request_info *info,
1816 struct iw_param *dwrq,
1817 char *extra)
1818{
Holger Schurig9012b282007-05-25 11:27:16 -04001819 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001820 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001821
Holger Schurig9012b282007-05-25 11:27:16 -04001822 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001823
1824 switch (dwrq->flags & IW_AUTH_INDEX) {
Javier Cardona9c40fc52008-09-16 18:08:39 -07001825 case IW_AUTH_KEY_MGMT:
1826 dwrq->value = priv->secinfo.key_mgmt;
1827 break;
1828
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001829 case IW_AUTH_WPA_VERSION:
1830 dwrq->value = 0;
David Woodhouseaa21c002007-12-08 20:04:36 +00001831 if (priv->secinfo.WPAenabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001832 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
David Woodhouseaa21c002007-12-08 20:04:36 +00001833 if (priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001834 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1835 if (!dwrq->value)
1836 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1837 break;
1838
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001839 case IW_AUTH_80211_AUTH_ALG:
David Woodhouseaa21c002007-12-08 20:04:36 +00001840 dwrq->value = priv->secinfo.auth_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001841 break;
1842
1843 case IW_AUTH_WPA_ENABLED:
David Woodhouseaa21c002007-12-08 20:04:36 +00001844 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845 dwrq->value = 1;
1846 break;
1847
1848 default:
Holger Schurig9012b282007-05-25 11:27:16 -04001849 ret = -EOPNOTSUPP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001850 }
1851
Holger Schurig9012b282007-05-25 11:27:16 -04001852 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1853 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001854}
1855
1856
Holger Schurig10078322007-11-15 18:05:47 -05001857static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001858 struct iw_param *vwrq, char *extra)
1859{
1860 int ret = 0;
Holger Schurig69f90322007-11-23 15:43:44 +01001861 struct lbs_private *priv = dev->priv;
Dan Williams87c8c722008-08-19 15:15:35 -04001862 s16 dbm = (s16) vwrq->value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001863
Holger Schurig9012b282007-05-25 11:27:16 -04001864 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001865
1866 if (vwrq->disabled) {
Dan Williamsd5db2df2008-08-21 17:51:07 -04001867 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
Dan Williams87c8c722008-08-19 15:15:35 -04001868 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001869 }
1870
Dan Williams87c8c722008-08-19 15:15:35 -04001871 if (vwrq->fixed == 0) {
Anna Neal0112c9e2008-09-11 11:17:25 -07001872 /* User requests automatic tx power control, however there are
1873 * many auto tx settings. For now use firmware defaults until
1874 * we come up with a good way to expose these to the user. */
1875 if (priv->fwrelease < 0x09000000) {
1876 ret = lbs_set_power_adapt_cfg(priv, 1,
1877 POW_ADAPT_DEFAULT_P0,
1878 POW_ADAPT_DEFAULT_P1,
1879 POW_ADAPT_DEFAULT_P2);
1880 if (ret)
1881 goto out;
1882 }
1883 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1884 TPC_DEFAULT_P2, 1);
1885 if (ret)
1886 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001887 dbm = priv->txpower_max;
1888 } else {
1889 /* Userspace check in iwrange if it should use dBm or mW,
1890 * therefore this should never happen... Jean II */
1891 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1892 ret = -EOPNOTSUPP;
1893 goto out;
1894 }
1895
Anna Neal0112c9e2008-09-11 11:17:25 -07001896 /* Validate requested power level against firmware allowed
1897 * levels */
Dan Williams87c8c722008-08-19 15:15:35 -04001898 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1899 ret = -EINVAL;
1900 goto out;
1901 }
1902
1903 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1904 ret = -EINVAL;
1905 goto out;
1906 }
Anna Neal0112c9e2008-09-11 11:17:25 -07001907 if (priv->fwrelease < 0x09000000) {
1908 ret = lbs_set_power_adapt_cfg(priv, 0,
1909 POW_ADAPT_DEFAULT_P0,
1910 POW_ADAPT_DEFAULT_P1,
1911 POW_ADAPT_DEFAULT_P2);
1912 if (ret)
1913 goto out;
1914 }
1915 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1916 TPC_DEFAULT_P2, 1);
1917 if (ret)
1918 goto out;
Dan Williams87c8c722008-08-19 15:15:35 -04001919 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001920
Dan Williamsd5db2df2008-08-21 17:51:07 -04001921 /* If the radio was off, turn it on */
1922 if (!priv->radio_on) {
1923 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
1924 if (ret)
1925 goto out;
1926 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001927
Dan Williams87c8c722008-08-19 15:15:35 -04001928 lbs_deb_wext("txpower set %d dBm\n", dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001929
Dan Williams87c8c722008-08-19 15:15:35 -04001930 ret = lbs_set_tx_power(priv, dbm);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001931
Dan Williams87c8c722008-08-19 15:15:35 -04001932out:
Holger Schurig9012b282007-05-25 11:27:16 -04001933 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001934 return ret;
1935}
1936
Holger Schurig10078322007-11-15 18:05:47 -05001937static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001938 struct iw_point *dwrq, char *extra)
1939{
Holger Schurig69f90322007-11-23 15:43:44 +01001940 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001941
Holger Schurig9012b282007-05-25 11:27:16 -04001942 lbs_deb_enter(LBS_DEB_WEXT);
1943
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001944 /*
1945 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1946 * the SSID list...
1947 */
1948
1949 /*
1950 * Get the current SSID
1951 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001952 if (priv->connect_status == LBS_CONNECTED) {
1953 memcpy(extra, priv->curbssparams.ssid,
1954 priv->curbssparams.ssid_len);
1955 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001956 } else {
1957 memset(extra, 0, 32);
David Woodhouseaa21c002007-12-08 20:04:36 +00001958 extra[priv->curbssparams.ssid_len] = '\0';
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001959 }
1960 /*
1961 * If none, we may want to get the one that was set
1962 */
1963
David Woodhouseaa21c002007-12-08 20:04:36 +00001964 dwrq->length = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001965
1966 dwrq->flags = 1; /* active */
1967
Holger Schurig9012b282007-05-25 11:27:16 -04001968 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001969 return 0;
1970}
1971
Holger Schurig10078322007-11-15 18:05:47 -05001972static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001973 struct iw_point *dwrq, char *extra)
1974{
Holger Schurig69f90322007-11-23 15:43:44 +01001975 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001976 int ret = 0;
Dan Williamsd8efea22007-05-28 23:54:55 -04001977 u8 ssid[IW_ESSID_MAX_SIZE];
1978 u8 ssid_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001979 struct assoc_request * assoc_req;
Dan Williamsd8efea22007-05-28 23:54:55 -04001980 int in_ssid_len = dwrq->length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001981
Holger Schurig9012b282007-05-25 11:27:16 -04001982 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001983
Dan Williamsd5db2df2008-08-21 17:51:07 -04001984 if (!priv->radio_on) {
1985 ret = -EINVAL;
1986 goto out;
1987 }
1988
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001989 /* Check the size of the string */
Dan Williamsd8efea22007-05-28 23:54:55 -04001990 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001991 ret = -E2BIG;
1992 goto out;
1993 }
1994
Dan Williamsd8efea22007-05-28 23:54:55 -04001995 memset(&ssid, 0, sizeof(ssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001996
Dan Williamsd8efea22007-05-28 23:54:55 -04001997 if (!dwrq->flags || !in_ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001998 /* "any" SSID requested; leave SSID blank */
1999 } else {
2000 /* Specific SSID requested */
Dan Williamsd8efea22007-05-28 23:54:55 -04002001 memcpy(&ssid, extra, in_ssid_len);
2002 ssid_len = in_ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002003 }
2004
Dan Williamsd8efea22007-05-28 23:54:55 -04002005 if (!ssid_len) {
2006 lbs_deb_wext("requested any SSID\n");
2007 } else {
2008 lbs_deb_wext("requested SSID '%s'\n",
John W. Linville7e272fc2008-09-24 18:13:14 -04002009 escape_ssid(ssid, ssid_len));
Dan Williamsd8efea22007-05-28 23:54:55 -04002010 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002011
2012out:
David Woodhouseaa21c002007-12-08 20:04:36 +00002013 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002014 if (ret == 0) {
2015 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002016 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002017 if (!assoc_req) {
2018 ret = -ENOMEM;
2019 } else {
2020 /* Copy the SSID to the association request */
Dan Williamsd8efea22007-05-28 23:54:55 -04002021 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
2022 assoc_req->ssid_len = ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002023 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002024 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002025 }
2026 }
2027
2028 /* Cancel the association request if there was an error */
2029 if (ret != 0) {
Holger Schurig10078322007-11-15 18:05:47 -05002030 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002031 }
2032
David Woodhouseaa21c002007-12-08 20:04:36 +00002033 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002034
Holger Schurig9012b282007-05-25 11:27:16 -04002035 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002036 return ret;
2037}
2038
David Woodhousef5956bf2007-12-11 19:30:57 -05002039static int lbs_mesh_get_essid(struct net_device *dev,
2040 struct iw_request_info *info,
2041 struct iw_point *dwrq, char *extra)
2042{
2043 struct lbs_private *priv = dev->priv;
2044
2045 lbs_deb_enter(LBS_DEB_WEXT);
2046
2047 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2048
2049 dwrq->length = priv->mesh_ssid_len;
2050
2051 dwrq->flags = 1; /* active */
2052
2053 lbs_deb_leave(LBS_DEB_WEXT);
2054 return 0;
2055}
2056
2057static int lbs_mesh_set_essid(struct net_device *dev,
2058 struct iw_request_info *info,
2059 struct iw_point *dwrq, char *extra)
2060{
2061 struct lbs_private *priv = dev->priv;
2062 int ret = 0;
2063
2064 lbs_deb_enter(LBS_DEB_WEXT);
2065
Dan Williamsd5db2df2008-08-21 17:51:07 -04002066 if (!priv->radio_on) {
2067 ret = -EINVAL;
2068 goto out;
2069 }
2070
David Woodhousef5956bf2007-12-11 19:30:57 -05002071 /* Check the size of the string */
2072 if (dwrq->length > IW_ESSID_MAX_SIZE) {
2073 ret = -E2BIG;
2074 goto out;
2075 }
2076
2077 if (!dwrq->flags || !dwrq->length) {
2078 ret = -EINVAL;
2079 goto out;
2080 } else {
2081 /* Specific SSID requested */
2082 memcpy(priv->mesh_ssid, extra, dwrq->length);
2083 priv->mesh_ssid_len = dwrq->length;
2084 }
2085
Javier Cardonaedaea5c2008-05-17 00:55:10 -07002086 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
2087 priv->curbssparams.channel);
David Woodhousef5956bf2007-12-11 19:30:57 -05002088 out:
2089 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2090 return ret;
2091}
2092
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002093/**
2094 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2095 *
2096 * @param dev A pointer to net_device structure
2097 * @param info A pointer to iw_request_info structure
2098 * @param awrq A pointer to iw_param structure
2099 * @param extra A pointer to extra data buf
2100 * @return 0 --success, otherwise fail
2101 */
Holger Schurig10078322007-11-15 18:05:47 -05002102static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002103 struct sockaddr *awrq, char *extra)
2104{
Holger Schurig69f90322007-11-23 15:43:44 +01002105 struct lbs_private *priv = dev->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002106 struct assoc_request * assoc_req;
2107 int ret = 0;
2108
Holger Schurig9012b282007-05-25 11:27:16 -04002109 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002110
Dan Williamsd5db2df2008-08-21 17:51:07 -04002111 if (!priv->radio_on)
2112 return -EINVAL;
2113
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002114 if (awrq->sa_family != ARPHRD_ETHER)
2115 return -EINVAL;
2116
Johannes Berge1749612008-10-27 15:59:26 -07002117 lbs_deb_wext("ASSOC: WAP: sa_data %pM\n", awrq->sa_data);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002118
David Woodhouseaa21c002007-12-08 20:04:36 +00002119 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002120
2121 /* Get or create the current association request */
David Woodhouseaa21c002007-12-08 20:04:36 +00002122 assoc_req = lbs_get_association_request(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002123 if (!assoc_req) {
Holger Schurig10078322007-11-15 18:05:47 -05002124 lbs_cancel_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002125 ret = -ENOMEM;
2126 } else {
2127 /* Copy the BSSID to the association request */
2128 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2129 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -05002130 lbs_postpone_association_work(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002131 }
2132
David Woodhouseaa21c002007-12-08 20:04:36 +00002133 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002134
2135 return ret;
2136}
2137
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002138/*
2139 * iwconfig settable callbacks
2140 */
Holger Schurig10078322007-11-15 18:05:47 -05002141static const iw_handler lbs_handler[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002142 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002143 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002144 (iw_handler) NULL, /* SIOCSIWNWID */
2145 (iw_handler) NULL, /* SIOCGIWNWID */
Holger Schurig10078322007-11-15 18:05:47 -05002146 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2147 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2148 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2149 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002150 (iw_handler) NULL, /* SIOCSIWSENS */
2151 (iw_handler) NULL, /* SIOCGIWSENS */
2152 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002153 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002154 (iw_handler) NULL, /* SIOCSIWPRIV */
2155 (iw_handler) NULL, /* SIOCGIWPRIV */
2156 (iw_handler) NULL, /* SIOCSIWSTATS */
2157 (iw_handler) NULL, /* SIOCGIWSTATS */
2158 iw_handler_set_spy, /* SIOCSIWSPY */
2159 iw_handler_get_spy, /* SIOCGIWSPY */
2160 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2161 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
Holger Schurig10078322007-11-15 18:05:47 -05002162 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2163 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002164 (iw_handler) NULL, /* SIOCSIWMLME */
2165 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002166 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2167 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2168 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2169 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2170 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2171 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002172 (iw_handler) NULL, /* -- hole -- */
2173 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002174 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2175 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2176 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2177 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2178 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2179 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2180 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2181 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2182 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2183 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2184 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2185 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2186 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2187 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002188 (iw_handler) NULL, /* -- hole -- */
2189 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002190 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2191 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2192 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2193 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2194 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2195 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002196 (iw_handler) NULL, /* SIOCSIWPMKSA */
2197};
2198
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002199static const iw_handler mesh_wlan_handler[] = {
2200 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Holger Schurig10078322007-11-15 18:05:47 -05002201 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002202 (iw_handler) NULL, /* SIOCSIWNWID */
2203 (iw_handler) NULL, /* SIOCGIWNWID */
David Woodhouse823eaa22007-12-11 19:56:28 -05002204 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
Holger Schurig10078322007-11-15 18:05:47 -05002205 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002206 (iw_handler) NULL, /* SIOCSIWMODE */
2207 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2208 (iw_handler) NULL, /* SIOCSIWSENS */
2209 (iw_handler) NULL, /* SIOCGIWSENS */
2210 (iw_handler) NULL, /* SIOCSIWRANGE */
Holger Schurig10078322007-11-15 18:05:47 -05002211 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002212 (iw_handler) NULL, /* SIOCSIWPRIV */
2213 (iw_handler) NULL, /* SIOCGIWPRIV */
2214 (iw_handler) NULL, /* SIOCSIWSTATS */
2215 (iw_handler) NULL, /* SIOCGIWSTATS */
2216 iw_handler_set_spy, /* SIOCSIWSPY */
2217 iw_handler_get_spy, /* SIOCGIWSPY */
2218 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2219 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2220 (iw_handler) NULL, /* SIOCSIWAP */
2221 (iw_handler) NULL, /* SIOCGIWAP */
2222 (iw_handler) NULL, /* SIOCSIWMLME */
2223 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
Holger Schurig10078322007-11-15 18:05:47 -05002224 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2225 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
David Woodhousef5956bf2007-12-11 19:30:57 -05002226 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2227 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002228 (iw_handler) NULL, /* SIOCSIWNICKN */
2229 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2230 (iw_handler) NULL, /* -- hole -- */
2231 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002232 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2233 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2234 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2235 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2236 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2237 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2238 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2239 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2240 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2241 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2242 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2243 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2244 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2245 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002246 (iw_handler) NULL, /* -- hole -- */
2247 (iw_handler) NULL, /* -- hole -- */
Holger Schurig10078322007-11-15 18:05:47 -05002248 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2249 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2250 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2251 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2252 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2253 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002254 (iw_handler) NULL, /* SIOCSIWPMKSA */
2255};
Holger Schurig10078322007-11-15 18:05:47 -05002256struct iw_handler_def lbs_handler_def = {
2257 .num_standard = ARRAY_SIZE(lbs_handler),
2258 .standard = (iw_handler *) lbs_handler,
2259 .get_wireless_stats = lbs_get_wireless_stats,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002260};
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002261
2262struct iw_handler_def mesh_handler_def = {
Denis Chengff8ac602007-09-02 18:30:18 +08002263 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002264 .standard = (iw_handler *) mesh_wlan_handler,
Holger Schurig10078322007-11-15 18:05:47 -05002265 .get_wireless_stats = lbs_get_wireless_stats,
Luis Carlos Cobo Rusf5e05b62007-05-25 23:08:34 -04002266};