Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Copyright (C) 2002 Intersil Americas Inc. |
3 | * (C) 2003,2004 Aurelien Alleaume <slts@free.fr> | |
4 | * (C) 2003 Herbert Valerio Riedel <hvr@gnu.org> | |
5 | * (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
21 | ||
1da177e4 LT |
22 | #include <linux/module.h> |
23 | #include <linux/kernel.h> | |
24 | #include <linux/if_arp.h> | |
25 | #include <linux/pci.h> | |
26 | ||
27 | #include <asm/uaccess.h> | |
28 | ||
29 | #include "prismcompat.h" | |
30 | #include "isl_ioctl.h" | |
31 | #include "islpci_mgt.h" | |
32 | #include "isl_oid.h" /* additional types and defs for isl38xx fw */ | |
33 | #include "oid_mgt.h" | |
34 | ||
35 | #include <net/iw_handler.h> /* New driver API */ | |
36 | ||
eab411f1 DW |
37 | #define KEY_SIZE_WEP104 13 /* 104/128-bit WEP keys */ |
38 | #define KEY_SIZE_WEP40 5 /* 40/64-bit WEP keys */ | |
39 | /* KEY_SIZE_TKIP should match isl_oid.h, struct obj_key.key[] size */ | |
40 | #define KEY_SIZE_TKIP 32 /* TKIP keys */ | |
1da177e4 | 41 | |
eab411f1 | 42 | static void prism54_wpa_bss_ie_add(islpci_private *priv, u8 *bssid, |
1da177e4 | 43 | u8 *wpa_ie, size_t wpa_ie_len); |
eab411f1 | 44 | static size_t prism54_wpa_bss_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie); |
1da177e4 LT |
45 | static int prism54_set_wpa(struct net_device *, struct iw_request_info *, |
46 | __u32 *, char *); | |
47 | ||
bd6dd756 JT |
48 | /* In 500 kbps */ |
49 | static const unsigned char scan_rate_list[] = { 2, 4, 11, 22, | |
50 | 12, 18, 24, 36, | |
51 | 48, 72, 96, 108 }; | |
1da177e4 LT |
52 | |
53 | /** | |
54 | * prism54_mib_mode_helper - MIB change mode helper function | |
55 | * @mib: the &struct islpci_mib object to modify | |
56 | * @iw_mode: new mode (%IW_MODE_*) | |
93b2dd12 | 57 | * |
1da177e4 | 58 | * This is a helper function, hence it does not lock. Make sure |
93b2dd12 DT |
59 | * caller deals with locking *if* necessary. This function sets the |
60 | * mode-dependent mib values and does the mapping of the Linux | |
61 | * Wireless API modes to Device firmware modes. It also checks for | |
62 | * correct valid Linux wireless modes. | |
1da177e4 LT |
63 | */ |
64 | static int | |
65 | prism54_mib_mode_helper(islpci_private *priv, u32 iw_mode) | |
66 | { | |
67 | u32 config = INL_CONFIG_MANUALRUN; | |
68 | u32 mode, bsstype; | |
69 | ||
70 | /* For now, just catch early the Repeater and Secondary modes here */ | |
71 | if (iw_mode == IW_MODE_REPEAT || iw_mode == IW_MODE_SECOND) { | |
72 | printk(KERN_DEBUG | |
73 | "%s(): Sorry, Repeater mode and Secondary mode " | |
74 | "are not yet supported by this driver.\n", __FUNCTION__); | |
75 | return -EINVAL; | |
76 | } | |
77 | ||
78 | priv->iw_mode = iw_mode; | |
79 | ||
80 | switch (iw_mode) { | |
81 | case IW_MODE_AUTO: | |
82 | mode = INL_MODE_CLIENT; | |
83 | bsstype = DOT11_BSSTYPE_ANY; | |
84 | break; | |
85 | case IW_MODE_ADHOC: | |
86 | mode = INL_MODE_CLIENT; | |
87 | bsstype = DOT11_BSSTYPE_IBSS; | |
88 | break; | |
89 | case IW_MODE_INFRA: | |
90 | mode = INL_MODE_CLIENT; | |
91 | bsstype = DOT11_BSSTYPE_INFRA; | |
92 | break; | |
93 | case IW_MODE_MASTER: | |
94 | mode = INL_MODE_AP; | |
95 | bsstype = DOT11_BSSTYPE_INFRA; | |
96 | break; | |
97 | case IW_MODE_MONITOR: | |
98 | mode = INL_MODE_PROMISCUOUS; | |
99 | bsstype = DOT11_BSSTYPE_ANY; | |
100 | config |= INL_CONFIG_RXANNEX; | |
101 | break; | |
102 | default: | |
103 | return -EINVAL; | |
104 | } | |
105 | ||
106 | if (init_wds) | |
107 | config |= INL_CONFIG_WDS; | |
108 | mgt_set(priv, DOT11_OID_BSSTYPE, &bsstype); | |
109 | mgt_set(priv, OID_INL_CONFIG, &config); | |
110 | mgt_set(priv, OID_INL_MODE, &mode); | |
111 | ||
112 | return 0; | |
113 | } | |
114 | ||
115 | /** | |
116 | * prism54_mib_init - fill MIB cache with defaults | |
117 | * | |
118 | * this function initializes the struct given as @mib with defaults, | |
119 | * of which many are retrieved from the global module parameter | |
93b2dd12 | 120 | * variables. |
1da177e4 LT |
121 | */ |
122 | ||
123 | void | |
124 | prism54_mib_init(islpci_private *priv) | |
125 | { | |
126 | u32 channel, authen, wep, filter, dot1x, mlme, conformance, power, mode; | |
127 | struct obj_buffer psm_buffer = { | |
128 | .size = PSM_BUFFER_SIZE, | |
129 | .addr = priv->device_psm_buffer | |
130 | }; | |
131 | ||
132 | channel = CARD_DEFAULT_CHANNEL; | |
133 | authen = CARD_DEFAULT_AUTHEN; | |
134 | wep = CARD_DEFAULT_WEP; | |
135 | filter = CARD_DEFAULT_FILTER; /* (0) Do not filter un-encrypted data */ | |
93b2dd12 | 136 | dot1x = CARD_DEFAULT_DOT1X; |
1da177e4 LT |
137 | mlme = CARD_DEFAULT_MLME_MODE; |
138 | conformance = CARD_DEFAULT_CONFORMANCE; | |
139 | power = 127; | |
140 | mode = CARD_DEFAULT_IW_MODE; | |
141 | ||
142 | mgt_set(priv, DOT11_OID_CHANNEL, &channel); | |
143 | mgt_set(priv, DOT11_OID_AUTHENABLE, &authen); | |
144 | mgt_set(priv, DOT11_OID_PRIVACYINVOKED, &wep); | |
145 | mgt_set(priv, DOT11_OID_PSMBUFFER, &psm_buffer); | |
146 | mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &filter); | |
147 | mgt_set(priv, DOT11_OID_DOT1XENABLE, &dot1x); | |
148 | mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlme); | |
149 | mgt_set(priv, OID_INL_DOT11D_CONFORMANCE, &conformance); | |
150 | mgt_set(priv, OID_INL_OUTPUTPOWER, &power); | |
151 | ||
152 | /* This sets all of the mode-dependent values */ | |
153 | prism54_mib_mode_helper(priv, mode); | |
154 | } | |
155 | ||
156 | /* this will be executed outside of atomic context thanks to | |
157 | * schedule_work(), thus we can as well use sleeping semaphore | |
158 | * locking */ | |
159 | void | |
c4028958 | 160 | prism54_update_stats(struct work_struct *work) |
1da177e4 | 161 | { |
c4028958 | 162 | islpci_private *priv = container_of(work, islpci_private, stats_work); |
1da177e4 LT |
163 | char *data; |
164 | int j; | |
165 | struct obj_bss bss, *bss2; | |
166 | union oid_res_t r; | |
167 | ||
f8139218 | 168 | mutex_lock(&priv->stats_lock); |
1da177e4 LT |
169 | |
170 | /* Noise floor. | |
171 | * I'm not sure if the unit is dBm. | |
172 | * Note : If we are not connected, this value seems to be irrelevant. */ | |
173 | ||
174 | mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r); | |
175 | priv->local_iwstatistics.qual.noise = r.u; | |
176 | ||
177 | /* Get the rssi of the link. To do this we need to retrieve a bss. */ | |
178 | ||
179 | /* First get the MAC address of the AP we are associated with. */ | |
180 | mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r); | |
181 | data = r.ptr; | |
182 | ||
183 | /* copy this MAC to the bss */ | |
184 | memcpy(bss.address, data, 6); | |
185 | kfree(data); | |
186 | ||
187 | /* now ask for the corresponding bss */ | |
188 | j = mgt_get_request(priv, DOT11_OID_BSSFIND, 0, (void *) &bss, &r); | |
189 | bss2 = r.ptr; | |
190 | /* report the rssi and use it to calculate | |
191 | * link quality through a signal-noise | |
192 | * ratio */ | |
193 | priv->local_iwstatistics.qual.level = bss2->rssi; | |
194 | priv->local_iwstatistics.qual.qual = | |
195 | bss2->rssi - priv->iwstatistics.qual.noise; | |
196 | ||
197 | kfree(bss2); | |
198 | ||
199 | /* report that the stats are new */ | |
200 | priv->local_iwstatistics.qual.updated = 0x7; | |
201 | ||
202 | /* Rx : unable to decrypt the MPDU */ | |
203 | mgt_get_request(priv, DOT11_OID_PRIVRXFAILED, 0, NULL, &r); | |
204 | priv->local_iwstatistics.discard.code = r.u; | |
205 | ||
206 | /* Tx : Max MAC retries num reached */ | |
207 | mgt_get_request(priv, DOT11_OID_MPDUTXFAILED, 0, NULL, &r); | |
208 | priv->local_iwstatistics.discard.retries = r.u; | |
209 | ||
f8139218 | 210 | mutex_unlock(&priv->stats_lock); |
1da177e4 LT |
211 | |
212 | return; | |
213 | } | |
214 | ||
215 | struct iw_statistics * | |
216 | prism54_get_wireless_stats(struct net_device *ndev) | |
217 | { | |
218 | islpci_private *priv = netdev_priv(ndev); | |
219 | ||
220 | /* If the stats are being updated return old data */ | |
8dd62822 | 221 | if (mutex_trylock(&priv->stats_lock)) { |
1da177e4 LT |
222 | memcpy(&priv->iwstatistics, &priv->local_iwstatistics, |
223 | sizeof (struct iw_statistics)); | |
224 | /* They won't be marked updated for the next time */ | |
225 | priv->local_iwstatistics.qual.updated = 0; | |
f8139218 | 226 | mutex_unlock(&priv->stats_lock); |
1da177e4 LT |
227 | } else |
228 | priv->iwstatistics.qual.updated = 0; | |
229 | ||
93b2dd12 | 230 | /* Update our wireless stats, but do not schedule to often |
1da177e4 LT |
231 | * (max 1 HZ) */ |
232 | if ((priv->stats_timestamp == 0) || | |
233 | time_after(jiffies, priv->stats_timestamp + 1 * HZ)) { | |
234 | schedule_work(&priv->stats_work); | |
235 | priv->stats_timestamp = jiffies; | |
236 | } | |
237 | ||
238 | return &priv->iwstatistics; | |
239 | } | |
240 | ||
241 | static int | |
242 | prism54_commit(struct net_device *ndev, struct iw_request_info *info, | |
243 | char *cwrq, char *extra) | |
244 | { | |
245 | islpci_private *priv = netdev_priv(ndev); | |
246 | ||
247 | /* simply re-set the last set SSID, this should commit most stuff */ | |
248 | ||
249 | /* Commit in Monitor mode is not necessary, also setting essid | |
250 | * in Monitor mode does not make sense and isn't allowed for this | |
251 | * device's firmware */ | |
252 | if (priv->iw_mode != IW_MODE_MONITOR) | |
253 | return mgt_set_request(priv, DOT11_OID_SSID, 0, NULL); | |
254 | return 0; | |
255 | } | |
256 | ||
257 | static int | |
258 | prism54_get_name(struct net_device *ndev, struct iw_request_info *info, | |
259 | char *cwrq, char *extra) | |
260 | { | |
261 | islpci_private *priv = netdev_priv(ndev); | |
262 | char *capabilities; | |
263 | union oid_res_t r; | |
264 | int rvalue; | |
265 | ||
266 | if (islpci_get_state(priv) < PRV_STATE_INIT) { | |
267 | strncpy(cwrq, "NOT READY!", IFNAMSIZ); | |
268 | return 0; | |
269 | } | |
270 | rvalue = mgt_get_request(priv, OID_INL_PHYCAPABILITIES, 0, NULL, &r); | |
271 | ||
272 | switch (r.u) { | |
273 | case INL_PHYCAP_5000MHZ: | |
274 | capabilities = "IEEE 802.11a/b/g"; | |
275 | break; | |
276 | case INL_PHYCAP_FAA: | |
277 | capabilities = "IEEE 802.11b/g - FAA Support"; | |
278 | break; | |
279 | case INL_PHYCAP_2400MHZ: | |
280 | default: | |
281 | capabilities = "IEEE 802.11b/g"; /* Default */ | |
282 | break; | |
283 | } | |
284 | strncpy(cwrq, capabilities, IFNAMSIZ); | |
285 | return rvalue; | |
286 | } | |
287 | ||
288 | static int | |
289 | prism54_set_freq(struct net_device *ndev, struct iw_request_info *info, | |
290 | struct iw_freq *fwrq, char *extra) | |
291 | { | |
292 | islpci_private *priv = netdev_priv(ndev); | |
293 | int rvalue; | |
294 | u32 c; | |
295 | ||
296 | if (fwrq->m < 1000) | |
297 | /* we have a channel number */ | |
298 | c = fwrq->m; | |
299 | else | |
300 | c = (fwrq->e == 1) ? channel_of_freq(fwrq->m / 100000) : 0; | |
301 | ||
302 | rvalue = c ? mgt_set_request(priv, DOT11_OID_CHANNEL, 0, &c) : -EINVAL; | |
303 | ||
304 | /* Call commit handler */ | |
305 | return (rvalue ? rvalue : -EINPROGRESS); | |
306 | } | |
307 | ||
308 | static int | |
309 | prism54_get_freq(struct net_device *ndev, struct iw_request_info *info, | |
310 | struct iw_freq *fwrq, char *extra) | |
311 | { | |
312 | islpci_private *priv = netdev_priv(ndev); | |
313 | union oid_res_t r; | |
314 | int rvalue; | |
315 | ||
316 | rvalue = mgt_get_request(priv, DOT11_OID_CHANNEL, 0, NULL, &r); | |
317 | fwrq->i = r.u; | |
318 | rvalue |= mgt_get_request(priv, DOT11_OID_FREQUENCY, 0, NULL, &r); | |
319 | fwrq->m = r.u; | |
320 | fwrq->e = 3; | |
321 | ||
322 | return rvalue; | |
323 | } | |
324 | ||
325 | static int | |
326 | prism54_set_mode(struct net_device *ndev, struct iw_request_info *info, | |
327 | __u32 * uwrq, char *extra) | |
328 | { | |
329 | islpci_private *priv = netdev_priv(ndev); | |
330 | u32 mlmeautolevel = CARD_DEFAULT_MLME_MODE; | |
331 | ||
332 | /* Let's see if the user passed a valid Linux Wireless mode */ | |
333 | if (*uwrq > IW_MODE_MONITOR || *uwrq < IW_MODE_AUTO) { | |
334 | printk(KERN_DEBUG | |
335 | "%s: %s() You passed a non-valid init_mode.\n", | |
336 | priv->ndev->name, __FUNCTION__); | |
337 | return -EINVAL; | |
338 | } | |
339 | ||
340 | down_write(&priv->mib_sem); | |
341 | ||
342 | if (prism54_mib_mode_helper(priv, *uwrq)) { | |
343 | up_write(&priv->mib_sem); | |
344 | return -EOPNOTSUPP; | |
345 | } | |
346 | ||
347 | /* the ACL code needs an intermediate mlmeautolevel. The wpa stuff an | |
348 | * extended one. | |
349 | */ | |
350 | if ((*uwrq == IW_MODE_MASTER) && (priv->acl.policy != MAC_POLICY_OPEN)) | |
351 | mlmeautolevel = DOT11_MLME_INTERMEDIATE; | |
352 | if (priv->wpa) | |
353 | mlmeautolevel = DOT11_MLME_EXTENDED; | |
354 | ||
355 | mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel); | |
356 | ||
357 | if (mgt_commit(priv)) { | |
358 | up_write(&priv->mib_sem); | |
359 | return -EIO; | |
360 | } | |
361 | priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR) | |
362 | ? priv->monitor_type : ARPHRD_ETHER; | |
363 | up_write(&priv->mib_sem); | |
364 | ||
365 | return 0; | |
366 | } | |
367 | ||
368 | /* Use mib cache */ | |
369 | static int | |
370 | prism54_get_mode(struct net_device *ndev, struct iw_request_info *info, | |
371 | __u32 * uwrq, char *extra) | |
372 | { | |
373 | islpci_private *priv = netdev_priv(ndev); | |
374 | ||
375 | BUG_ON((priv->iw_mode < IW_MODE_AUTO) || (priv->iw_mode > | |
376 | IW_MODE_MONITOR)); | |
377 | *uwrq = priv->iw_mode; | |
378 | ||
379 | return 0; | |
380 | } | |
381 | ||
382 | /* we use DOT11_OID_EDTHRESHOLD. From what I guess the card will not try to | |
383 | * emit data if (sensitivity > rssi - noise) (in dBm). | |
384 | * prism54_set_sens does not seem to work. | |
385 | */ | |
386 | ||
387 | static int | |
388 | prism54_set_sens(struct net_device *ndev, struct iw_request_info *info, | |
389 | struct iw_param *vwrq, char *extra) | |
390 | { | |
391 | islpci_private *priv = netdev_priv(ndev); | |
392 | u32 sens; | |
393 | ||
394 | /* by default the card sets this to 20. */ | |
395 | sens = vwrq->disabled ? 20 : vwrq->value; | |
396 | ||
397 | return mgt_set_request(priv, DOT11_OID_EDTHRESHOLD, 0, &sens); | |
398 | } | |
399 | ||
400 | static int | |
401 | prism54_get_sens(struct net_device *ndev, struct iw_request_info *info, | |
402 | struct iw_param *vwrq, char *extra) | |
403 | { | |
404 | islpci_private *priv = netdev_priv(ndev); | |
405 | union oid_res_t r; | |
406 | int rvalue; | |
407 | ||
408 | rvalue = mgt_get_request(priv, DOT11_OID_EDTHRESHOLD, 0, NULL, &r); | |
409 | ||
410 | vwrq->value = r.u; | |
411 | vwrq->disabled = (vwrq->value == 0); | |
412 | vwrq->fixed = 1; | |
413 | ||
414 | return rvalue; | |
415 | } | |
416 | ||
417 | static int | |
418 | prism54_get_range(struct net_device *ndev, struct iw_request_info *info, | |
419 | struct iw_point *dwrq, char *extra) | |
420 | { | |
421 | struct iw_range *range = (struct iw_range *) extra; | |
422 | islpci_private *priv = netdev_priv(ndev); | |
423 | u8 *data; | |
424 | int i, m, rvalue; | |
425 | struct obj_frequencies *freq; | |
426 | union oid_res_t r; | |
427 | ||
428 | memset(range, 0, sizeof (struct iw_range)); | |
429 | dwrq->length = sizeof (struct iw_range); | |
430 | ||
431 | /* set the wireless extension version number */ | |
432 | range->we_version_source = SUPPORTED_WIRELESS_EXT; | |
433 | range->we_version_compiled = WIRELESS_EXT; | |
434 | ||
435 | /* Now the encoding capabilities */ | |
436 | range->num_encoding_sizes = 3; | |
437 | /* 64(40) bits WEP */ | |
438 | range->encoding_size[0] = 5; | |
439 | /* 128(104) bits WEP */ | |
440 | range->encoding_size[1] = 13; | |
441 | /* 256 bits for WPA-PSK */ | |
442 | range->encoding_size[2] = 32; | |
443 | /* 4 keys are allowed */ | |
444 | range->max_encoding_tokens = 4; | |
445 | ||
446 | /* we don't know the quality range... */ | |
447 | range->max_qual.level = 0; | |
448 | range->max_qual.noise = 0; | |
449 | range->max_qual.qual = 0; | |
450 | /* these value describe an average quality. Needs more tweaking... */ | |
451 | range->avg_qual.level = -80; /* -80 dBm */ | |
452 | range->avg_qual.noise = 0; /* don't know what to put here */ | |
453 | range->avg_qual.qual = 0; | |
454 | ||
455 | range->sensitivity = 200; | |
456 | ||
457 | /* retry limit capabilities */ | |
458 | range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME; | |
459 | range->retry_flags = IW_RETRY_LIMIT; | |
460 | range->r_time_flags = IW_RETRY_LIFETIME; | |
461 | ||
462 | /* I don't know the range. Put stupid things here */ | |
463 | range->min_retry = 1; | |
464 | range->max_retry = 65535; | |
465 | range->min_r_time = 1024; | |
466 | range->max_r_time = 65535 * 1024; | |
467 | ||
468 | /* txpower is supported in dBm's */ | |
469 | range->txpower_capa = IW_TXPOW_DBM; | |
470 | ||
1da177e4 LT |
471 | /* Event capability (kernel + driver) */ |
472 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | | |
473 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | | |
474 | IW_EVENT_CAPA_MASK(SIOCGIWAP)); | |
475 | range->event_capa[1] = IW_EVENT_CAPA_K_1; | |
476 | range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVCUSTOM); | |
1da177e4 | 477 | |
eab411f1 DW |
478 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
479 | IW_ENC_CAPA_CIPHER_TKIP; | |
480 | ||
1da177e4 LT |
481 | if (islpci_get_state(priv) < PRV_STATE_INIT) |
482 | return 0; | |
483 | ||
484 | /* Request the device for the supported frequencies | |
485 | * not really relevant since some devices will report the 5 GHz band | |
486 | * frequencies even if they don't support them. | |
487 | */ | |
488 | rvalue = | |
489 | mgt_get_request(priv, DOT11_OID_SUPPORTEDFREQUENCIES, 0, NULL, &r); | |
490 | freq = r.ptr; | |
491 | ||
492 | range->num_channels = freq->nr; | |
493 | range->num_frequency = freq->nr; | |
494 | ||
495 | m = min(IW_MAX_FREQUENCIES, (int) freq->nr); | |
496 | for (i = 0; i < m; i++) { | |
497 | range->freq[i].m = freq->mhz[i]; | |
498 | range->freq[i].e = 6; | |
499 | range->freq[i].i = channel_of_freq(freq->mhz[i]); | |
500 | } | |
501 | kfree(freq); | |
502 | ||
503 | rvalue |= mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r); | |
504 | data = r.ptr; | |
505 | ||
506 | /* We got an array of char. It is NULL terminated. */ | |
507 | i = 0; | |
508 | while ((i < IW_MAX_BITRATES) && (*data != 0)) { | |
509 | /* the result must be in bps. The card gives us 500Kbps */ | |
510 | range->bitrate[i] = *data * 500000; | |
511 | i++; | |
512 | data++; | |
513 | } | |
514 | range->num_bitrates = i; | |
515 | kfree(r.ptr); | |
516 | ||
517 | return rvalue; | |
518 | } | |
519 | ||
520 | /* Set AP address*/ | |
521 | ||
522 | static int | |
523 | prism54_set_wap(struct net_device *ndev, struct iw_request_info *info, | |
524 | struct sockaddr *awrq, char *extra) | |
525 | { | |
526 | islpci_private *priv = netdev_priv(ndev); | |
527 | char bssid[6]; | |
528 | int rvalue; | |
529 | ||
530 | if (awrq->sa_family != ARPHRD_ETHER) | |
531 | return -EINVAL; | |
532 | ||
533 | /* prepare the structure for the set object */ | |
534 | memcpy(&bssid[0], awrq->sa_data, 6); | |
535 | ||
536 | /* set the bssid -- does this make sense when in AP mode? */ | |
537 | rvalue = mgt_set_request(priv, DOT11_OID_BSSID, 0, &bssid); | |
538 | ||
539 | return (rvalue ? rvalue : -EINPROGRESS); /* Call commit handler */ | |
540 | } | |
541 | ||
542 | /* get AP address*/ | |
543 | ||
544 | static int | |
545 | prism54_get_wap(struct net_device *ndev, struct iw_request_info *info, | |
546 | struct sockaddr *awrq, char *extra) | |
547 | { | |
548 | islpci_private *priv = netdev_priv(ndev); | |
549 | union oid_res_t r; | |
550 | int rvalue; | |
551 | ||
552 | rvalue = mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r); | |
553 | memcpy(awrq->sa_data, r.ptr, 6); | |
554 | awrq->sa_family = ARPHRD_ETHER; | |
555 | kfree(r.ptr); | |
556 | ||
557 | return rvalue; | |
558 | } | |
559 | ||
560 | static int | |
561 | prism54_set_scan(struct net_device *dev, struct iw_request_info *info, | |
562 | struct iw_param *vwrq, char *extra) | |
563 | { | |
564 | /* hehe the device does this automagicaly */ | |
565 | return 0; | |
566 | } | |
567 | ||
568 | /* a little helper that will translate our data into a card independent | |
569 | * format that the Wireless Tools will understand. This was inspired by | |
570 | * the "Aironet driver for 4500 and 4800 series cards" (GPL) | |
571 | */ | |
572 | ||
573 | static char * | |
574 | prism54_translate_bss(struct net_device *ndev, char *current_ev, | |
575 | char *end_buf, struct obj_bss *bss, char noise) | |
576 | { | |
577 | struct iw_event iwe; /* Temporary buffer */ | |
578 | short cap; | |
579 | islpci_private *priv = netdev_priv(ndev); | |
eab411f1 DW |
580 | u8 wpa_ie[MAX_WPA_IE_LEN]; |
581 | size_t wpa_ie_len; | |
1da177e4 LT |
582 | |
583 | /* The first entry must be the MAC address */ | |
584 | memcpy(iwe.u.ap_addr.sa_data, bss->address, 6); | |
585 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
586 | iwe.cmd = SIOCGIWAP; | |
587 | current_ev = | |
588 | iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN); | |
589 | ||
590 | /* The following entries will be displayed in the same order we give them */ | |
591 | ||
592 | /* The ESSID. */ | |
593 | iwe.u.data.length = bss->ssid.length; | |
594 | iwe.u.data.flags = 1; | |
595 | iwe.cmd = SIOCGIWESSID; | |
596 | current_ev = iwe_stream_add_point(current_ev, end_buf, | |
597 | &iwe, bss->ssid.octets); | |
598 | ||
599 | /* Capabilities */ | |
600 | #define CAP_ESS 0x01 | |
601 | #define CAP_IBSS 0x02 | |
602 | #define CAP_CRYPT 0x10 | |
603 | ||
604 | /* Mode */ | |
605 | cap = bss->capinfo; | |
606 | iwe.u.mode = 0; | |
607 | if (cap & CAP_ESS) | |
608 | iwe.u.mode = IW_MODE_MASTER; | |
609 | else if (cap & CAP_IBSS) | |
610 | iwe.u.mode = IW_MODE_ADHOC; | |
611 | iwe.cmd = SIOCGIWMODE; | |
612 | if (iwe.u.mode) | |
613 | current_ev = | |
614 | iwe_stream_add_event(current_ev, end_buf, &iwe, | |
615 | IW_EV_UINT_LEN); | |
616 | ||
617 | /* Encryption capability */ | |
618 | if (cap & CAP_CRYPT) | |
619 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | |
620 | else | |
621 | iwe.u.data.flags = IW_ENCODE_DISABLED; | |
622 | iwe.u.data.length = 0; | |
623 | iwe.cmd = SIOCGIWENCODE; | |
624 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, NULL); | |
625 | ||
626 | /* Add frequency. (short) bss->channel is the frequency in MHz */ | |
627 | iwe.u.freq.m = bss->channel; | |
628 | iwe.u.freq.e = 6; | |
629 | iwe.cmd = SIOCGIWFREQ; | |
630 | current_ev = | |
631 | iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN); | |
632 | ||
633 | /* Add quality statistics */ | |
634 | iwe.u.qual.level = bss->rssi; | |
635 | iwe.u.qual.noise = noise; | |
636 | /* do a simple SNR for quality */ | |
637 | iwe.u.qual.qual = bss->rssi - noise; | |
638 | iwe.cmd = IWEVQUAL; | |
639 | current_ev = | |
640 | iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN); | |
641 | ||
eab411f1 DW |
642 | /* Add WPA/RSN Information Element, if any */ |
643 | wpa_ie_len = prism54_wpa_bss_ie_get(priv, bss->address, wpa_ie); | |
644 | if (wpa_ie_len > 0) { | |
645 | iwe.cmd = IWEVGENIE; | |
646 | iwe.u.data.length = min(wpa_ie_len, (size_t)MAX_WPA_IE_LEN); | |
647 | current_ev = iwe_stream_add_point(current_ev, end_buf, | |
648 | &iwe, wpa_ie); | |
1da177e4 | 649 | } |
bd6dd756 JT |
650 | /* Do the bitrates */ |
651 | { | |
652 | char * current_val = current_ev + IW_EV_LCP_LEN; | |
653 | int i; | |
654 | int mask; | |
655 | ||
656 | iwe.cmd = SIOCGIWRATE; | |
657 | /* Those two flags are ignored... */ | |
658 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | |
659 | ||
660 | /* Parse the bitmask */ | |
661 | mask = 0x1; | |
662 | for(i = 0; i < sizeof(scan_rate_list); i++) { | |
663 | if(bss->rates & mask) { | |
664 | iwe.u.bitrate.value = (scan_rate_list[i] * 500000); | |
665 | current_val = iwe_stream_add_value(current_ev, current_val, | |
666 | end_buf, &iwe, | |
667 | IW_EV_PARAM_LEN); | |
668 | } | |
669 | mask <<= 1; | |
670 | } | |
671 | /* Check if we added any event */ | |
672 | if ((current_val - current_ev) > IW_EV_LCP_LEN) | |
673 | current_ev = current_val; | |
674 | } | |
675 | ||
1da177e4 LT |
676 | return current_ev; |
677 | } | |
678 | ||
679 | static int | |
680 | prism54_get_scan(struct net_device *ndev, struct iw_request_info *info, | |
681 | struct iw_point *dwrq, char *extra) | |
682 | { | |
683 | islpci_private *priv = netdev_priv(ndev); | |
684 | int i, rvalue; | |
685 | struct obj_bsslist *bsslist; | |
686 | u32 noise = 0; | |
687 | char *current_ev = extra; | |
688 | union oid_res_t r; | |
689 | ||
690 | if (islpci_get_state(priv) < PRV_STATE_INIT) { | |
691 | /* device is not ready, fail gently */ | |
692 | dwrq->length = 0; | |
693 | return 0; | |
694 | } | |
695 | ||
696 | /* first get the noise value. We will use it to report the link quality */ | |
697 | rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r); | |
698 | noise = r.u; | |
699 | ||
700 | /* Ask the device for a list of known bss. | |
701 | * The old API, using SIOCGIWAPLIST, had a hard limit of IW_MAX_AP=64. | |
702 | * The new API, using SIOCGIWSCAN, is only limited by the buffer size. | |
703 | * WE-14->WE-16, the buffer is limited to IW_SCAN_MAX_DATA bytes. | |
704 | * Starting with WE-17, the buffer can be as big as needed. | |
705 | * But the device won't repport anything if you change the value | |
706 | * of IWMAX_BSS=24. */ | |
93b2dd12 | 707 | |
1da177e4 LT |
708 | rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r); |
709 | bsslist = r.ptr; | |
710 | ||
711 | /* ok now, scan the list and translate its info */ | |
712 | for (i = 0; i < (int) bsslist->nr; i++) { | |
713 | current_ev = prism54_translate_bss(ndev, current_ev, | |
714 | extra + dwrq->length, | |
715 | &(bsslist->bsslist[i]), | |
716 | noise); | |
e2e96507 | 717 | |
1da177e4 LT |
718 | /* Check if there is space for one more entry */ |
719 | if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) { | |
720 | /* Ask user space to try again with a bigger buffer */ | |
721 | rvalue = -E2BIG; | |
722 | break; | |
723 | } | |
1da177e4 LT |
724 | } |
725 | ||
726 | kfree(bsslist); | |
727 | dwrq->length = (current_ev - extra); | |
728 | dwrq->flags = 0; /* todo */ | |
729 | ||
730 | return rvalue; | |
731 | } | |
732 | ||
733 | static int | |
734 | prism54_set_essid(struct net_device *ndev, struct iw_request_info *info, | |
735 | struct iw_point *dwrq, char *extra) | |
736 | { | |
737 | islpci_private *priv = netdev_priv(ndev); | |
738 | struct obj_ssid essid; | |
739 | ||
740 | memset(essid.octets, 0, 33); | |
741 | ||
742 | /* Check if we were asked for `any' */ | |
743 | if (dwrq->flags && dwrq->length) { | |
bad04f2c | 744 | if (dwrq->length > 32) |
1da177e4 | 745 | return -E2BIG; |
bad04f2c | 746 | essid.length = dwrq->length; |
1da177e4 LT |
747 | memcpy(essid.octets, extra, dwrq->length); |
748 | } else | |
749 | essid.length = 0; | |
750 | ||
751 | if (priv->iw_mode != IW_MODE_MONITOR) | |
752 | return mgt_set_request(priv, DOT11_OID_SSID, 0, &essid); | |
753 | ||
754 | /* If in monitor mode, just save to mib */ | |
755 | mgt_set(priv, DOT11_OID_SSID, &essid); | |
756 | return 0; | |
757 | ||
758 | } | |
759 | ||
760 | static int | |
761 | prism54_get_essid(struct net_device *ndev, struct iw_request_info *info, | |
762 | struct iw_point *dwrq, char *extra) | |
763 | { | |
764 | islpci_private *priv = netdev_priv(ndev); | |
765 | struct obj_ssid *essid; | |
766 | union oid_res_t r; | |
767 | int rvalue; | |
768 | ||
769 | rvalue = mgt_get_request(priv, DOT11_OID_SSID, 0, NULL, &r); | |
770 | essid = r.ptr; | |
771 | ||
772 | if (essid->length) { | |
773 | dwrq->flags = 1; /* set ESSID to ON for Wireless Extensions */ | |
7f927fcc | 774 | /* if it is too big, trunk it */ |
bf82a449 | 775 | dwrq->length = min((u8)IW_ESSID_MAX_SIZE, essid->length); |
1da177e4 LT |
776 | } else { |
777 | dwrq->flags = 0; | |
778 | dwrq->length = 0; | |
779 | } | |
780 | essid->octets[essid->length] = '\0'; | |
781 | memcpy(extra, essid->octets, dwrq->length); | |
782 | kfree(essid); | |
783 | ||
784 | return rvalue; | |
785 | } | |
786 | ||
93b2dd12 | 787 | /* Provides no functionality, just completes the ioctl. In essence this is a |
1da177e4 LT |
788 | * just a cosmetic ioctl. |
789 | */ | |
790 | static int | |
791 | prism54_set_nick(struct net_device *ndev, struct iw_request_info *info, | |
792 | struct iw_point *dwrq, char *extra) | |
793 | { | |
794 | islpci_private *priv = netdev_priv(ndev); | |
795 | ||
796 | if (dwrq->length > IW_ESSID_MAX_SIZE) | |
797 | return -E2BIG; | |
798 | ||
799 | down_write(&priv->mib_sem); | |
800 | memset(priv->nickname, 0, sizeof (priv->nickname)); | |
801 | memcpy(priv->nickname, extra, dwrq->length); | |
802 | up_write(&priv->mib_sem); | |
803 | ||
804 | return 0; | |
805 | } | |
806 | ||
807 | static int | |
808 | prism54_get_nick(struct net_device *ndev, struct iw_request_info *info, | |
809 | struct iw_point *dwrq, char *extra) | |
810 | { | |
811 | islpci_private *priv = netdev_priv(ndev); | |
812 | ||
813 | dwrq->length = 0; | |
814 | ||
815 | down_read(&priv->mib_sem); | |
bad04f2c | 816 | dwrq->length = strlen(priv->nickname); |
1da177e4 LT |
817 | memcpy(extra, priv->nickname, dwrq->length); |
818 | up_read(&priv->mib_sem); | |
819 | ||
820 | return 0; | |
821 | } | |
822 | ||
823 | /* Set the allowed Bitrates */ | |
824 | ||
825 | static int | |
826 | prism54_set_rate(struct net_device *ndev, | |
827 | struct iw_request_info *info, | |
828 | struct iw_param *vwrq, char *extra) | |
829 | { | |
830 | ||
831 | islpci_private *priv = netdev_priv(ndev); | |
832 | u32 rate, profile; | |
833 | char *data; | |
834 | int ret, i; | |
835 | union oid_res_t r; | |
836 | ||
837 | if (vwrq->value == -1) { | |
838 | /* auto mode. No limit. */ | |
839 | profile = 1; | |
840 | return mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile); | |
841 | } | |
842 | ||
843 | ret = mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r); | |
844 | if (ret) { | |
845 | kfree(r.ptr); | |
846 | return ret; | |
847 | } | |
848 | ||
849 | rate = (u32) (vwrq->value / 500000); | |
850 | data = r.ptr; | |
851 | i = 0; | |
852 | ||
853 | while (data[i]) { | |
854 | if (rate && (data[i] == rate)) { | |
855 | break; | |
856 | } | |
857 | if (vwrq->value == i) { | |
858 | break; | |
859 | } | |
860 | data[i] |= 0x80; | |
861 | i++; | |
862 | } | |
863 | ||
864 | if (!data[i]) { | |
865 | kfree(r.ptr); | |
866 | return -EINVAL; | |
867 | } | |
868 | ||
869 | data[i] |= 0x80; | |
870 | data[i + 1] = 0; | |
871 | ||
872 | /* Now, check if we want a fixed or auto value */ | |
873 | if (vwrq->fixed) { | |
874 | data[0] = data[i]; | |
875 | data[1] = 0; | |
876 | } | |
877 | ||
878 | /* | |
879 | i = 0; | |
880 | printk("prism54 rate: "); | |
881 | while(data[i]) { | |
882 | printk("%u ", data[i]); | |
883 | i++; | |
884 | } | |
885 | printk("0\n"); | |
886 | */ | |
887 | profile = -1; | |
888 | ret = mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile); | |
889 | ret |= mgt_set_request(priv, DOT11_OID_EXTENDEDRATES, 0, data); | |
890 | ret |= mgt_set_request(priv, DOT11_OID_RATES, 0, data); | |
891 | ||
892 | kfree(r.ptr); | |
893 | ||
894 | return ret; | |
895 | } | |
896 | ||
897 | /* Get the current bit rate */ | |
898 | static int | |
899 | prism54_get_rate(struct net_device *ndev, | |
900 | struct iw_request_info *info, | |
901 | struct iw_param *vwrq, char *extra) | |
902 | { | |
903 | islpci_private *priv = netdev_priv(ndev); | |
904 | int rvalue; | |
905 | char *data; | |
906 | union oid_res_t r; | |
907 | ||
908 | /* Get the current bit rate */ | |
909 | if ((rvalue = mgt_get_request(priv, GEN_OID_LINKSTATE, 0, NULL, &r))) | |
910 | return rvalue; | |
911 | vwrq->value = r.u * 500000; | |
912 | ||
913 | /* request the device for the enabled rates */ | |
914 | rvalue = mgt_get_request(priv, DOT11_OID_RATES, 0, NULL, &r); | |
915 | if (rvalue) { | |
916 | kfree(r.ptr); | |
917 | return rvalue; | |
918 | } | |
919 | data = r.ptr; | |
920 | vwrq->fixed = (data[0] != 0) && (data[1] == 0); | |
921 | kfree(r.ptr); | |
922 | ||
923 | return 0; | |
924 | } | |
925 | ||
926 | static int | |
927 | prism54_set_rts(struct net_device *ndev, struct iw_request_info *info, | |
928 | struct iw_param *vwrq, char *extra) | |
929 | { | |
930 | islpci_private *priv = netdev_priv(ndev); | |
931 | ||
932 | return mgt_set_request(priv, DOT11_OID_RTSTHRESH, 0, &vwrq->value); | |
933 | } | |
934 | ||
935 | static int | |
936 | prism54_get_rts(struct net_device *ndev, struct iw_request_info *info, | |
937 | struct iw_param *vwrq, char *extra) | |
938 | { | |
939 | islpci_private *priv = netdev_priv(ndev); | |
940 | union oid_res_t r; | |
941 | int rvalue; | |
942 | ||
943 | /* get the rts threshold */ | |
944 | rvalue = mgt_get_request(priv, DOT11_OID_RTSTHRESH, 0, NULL, &r); | |
945 | vwrq->value = r.u; | |
946 | ||
947 | return rvalue; | |
948 | } | |
949 | ||
950 | static int | |
951 | prism54_set_frag(struct net_device *ndev, struct iw_request_info *info, | |
952 | struct iw_param *vwrq, char *extra) | |
953 | { | |
954 | islpci_private *priv = netdev_priv(ndev); | |
955 | ||
956 | return mgt_set_request(priv, DOT11_OID_FRAGTHRESH, 0, &vwrq->value); | |
957 | } | |
958 | ||
959 | static int | |
960 | prism54_get_frag(struct net_device *ndev, struct iw_request_info *info, | |
961 | struct iw_param *vwrq, char *extra) | |
962 | { | |
963 | islpci_private *priv = netdev_priv(ndev); | |
964 | union oid_res_t r; | |
965 | int rvalue; | |
966 | ||
967 | rvalue = mgt_get_request(priv, DOT11_OID_FRAGTHRESH, 0, NULL, &r); | |
968 | vwrq->value = r.u; | |
969 | ||
970 | return rvalue; | |
971 | } | |
972 | ||
973 | /* Here we have (min,max) = max retries for (small frames, big frames). Where | |
974 | * big frame <=> bigger than the rts threshold | |
975 | * small frame <=> smaller than the rts threshold | |
976 | * This is not really the behavior expected by the wireless tool but it seems | |
977 | * to be a common behavior in other drivers. | |
978 | */ | |
979 | ||
980 | static int | |
981 | prism54_set_retry(struct net_device *ndev, struct iw_request_info *info, | |
982 | struct iw_param *vwrq, char *extra) | |
983 | { | |
984 | islpci_private *priv = netdev_priv(ndev); | |
985 | u32 slimit = 0, llimit = 0; /* short and long limit */ | |
986 | u32 lifetime = 0; | |
987 | int rvalue = 0; | |
988 | ||
989 | if (vwrq->disabled) | |
990 | /* we cannot disable this feature */ | |
991 | return -EINVAL; | |
992 | ||
993 | if (vwrq->flags & IW_RETRY_LIMIT) { | |
bad04f2c | 994 | if (vwrq->flags & IW_RETRY_SHORT) |
1da177e4 | 995 | slimit = vwrq->value; |
bad04f2c | 996 | else if (vwrq->flags & IW_RETRY_LONG) |
1da177e4 LT |
997 | llimit = vwrq->value; |
998 | else { | |
999 | /* we are asked to set both */ | |
1000 | slimit = vwrq->value; | |
1001 | llimit = vwrq->value; | |
1002 | } | |
1003 | } | |
1004 | if (vwrq->flags & IW_RETRY_LIFETIME) | |
1005 | /* Wireless tools use us unit while the device uses 1024 us unit */ | |
1006 | lifetime = vwrq->value / 1024; | |
1007 | ||
1008 | /* now set what is requested */ | |
1009 | if (slimit) | |
1010 | rvalue = | |
1011 | mgt_set_request(priv, DOT11_OID_SHORTRETRIES, 0, &slimit); | |
1012 | if (llimit) | |
1013 | rvalue |= | |
1014 | mgt_set_request(priv, DOT11_OID_LONGRETRIES, 0, &llimit); | |
1015 | if (lifetime) | |
1016 | rvalue |= | |
1017 | mgt_set_request(priv, DOT11_OID_MAXTXLIFETIME, 0, | |
1018 | &lifetime); | |
1019 | return rvalue; | |
1020 | } | |
1021 | ||
1022 | static int | |
1023 | prism54_get_retry(struct net_device *ndev, struct iw_request_info *info, | |
1024 | struct iw_param *vwrq, char *extra) | |
1025 | { | |
1026 | islpci_private *priv = netdev_priv(ndev); | |
1027 | union oid_res_t r; | |
1028 | int rvalue = 0; | |
1029 | vwrq->disabled = 0; /* It cannot be disabled */ | |
1030 | ||
1031 | if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { | |
1032 | /* we are asked for the life time */ | |
1033 | rvalue = | |
1034 | mgt_get_request(priv, DOT11_OID_MAXTXLIFETIME, 0, NULL, &r); | |
1035 | vwrq->value = r.u * 1024; | |
1036 | vwrq->flags = IW_RETRY_LIFETIME; | |
bad04f2c | 1037 | } else if ((vwrq->flags & IW_RETRY_LONG)) { |
1da177e4 LT |
1038 | /* we are asked for the long retry limit */ |
1039 | rvalue |= | |
1040 | mgt_get_request(priv, DOT11_OID_LONGRETRIES, 0, NULL, &r); | |
1041 | vwrq->value = r.u; | |
bad04f2c | 1042 | vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG; |
1da177e4 LT |
1043 | } else { |
1044 | /* default. get the short retry limit */ | |
1045 | rvalue |= | |
1046 | mgt_get_request(priv, DOT11_OID_SHORTRETRIES, 0, NULL, &r); | |
1047 | vwrq->value = r.u; | |
bad04f2c | 1048 | vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT; |
1da177e4 LT |
1049 | } |
1050 | ||
1051 | return rvalue; | |
1052 | } | |
1053 | ||
1054 | static int | |
1055 | prism54_set_encode(struct net_device *ndev, struct iw_request_info *info, | |
1056 | struct iw_point *dwrq, char *extra) | |
1057 | { | |
1058 | islpci_private *priv = netdev_priv(ndev); | |
1059 | int rvalue = 0, force = 0; | |
1060 | int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0; | |
1061 | union oid_res_t r; | |
1062 | ||
1063 | /* with the new API, it's impossible to get a NULL pointer. | |
1064 | * New version of iwconfig set the IW_ENCODE_NOKEY flag | |
1065 | * when no key is given, but older versions don't. */ | |
1066 | ||
1067 | if (dwrq->length > 0) { | |
1068 | /* we have a key to set */ | |
1069 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; | |
1070 | int current_index; | |
1071 | struct obj_key key = { DOT11_PRIV_WEP, 0, "" }; | |
1072 | ||
1073 | /* get the current key index */ | |
1074 | rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); | |
1075 | current_index = r.u; | |
1076 | /* Verify that the key is not marked as invalid */ | |
1077 | if (!(dwrq->flags & IW_ENCODE_NOKEY)) { | |
eab411f1 DW |
1078 | if (dwrq->length > KEY_SIZE_TKIP) { |
1079 | /* User-provided key data too big */ | |
1080 | return -EINVAL; | |
1081 | } | |
1082 | if (dwrq->length > KEY_SIZE_WEP104) { | |
1083 | /* WPA-PSK TKIP */ | |
1da177e4 | 1084 | key.type = DOT11_PRIV_TKIP; |
eab411f1 DW |
1085 | key.length = KEY_SIZE_TKIP; |
1086 | } else if (dwrq->length > KEY_SIZE_WEP40) { | |
1087 | /* WEP 104/128 */ | |
1088 | key.length = KEY_SIZE_WEP104; | |
1089 | } else { | |
1090 | /* WEP 40/64 */ | |
1091 | key.length = KEY_SIZE_WEP40; | |
1092 | } | |
1093 | memset(key.key, 0, sizeof (key.key)); | |
1094 | memcpy(key.key, extra, dwrq->length); | |
1095 | ||
1da177e4 LT |
1096 | if ((index < 0) || (index > 3)) |
1097 | /* no index provided use the current one */ | |
1098 | index = current_index; | |
1099 | ||
1100 | /* now send the key to the card */ | |
1101 | rvalue |= | |
1102 | mgt_set_request(priv, DOT11_OID_DEFKEYX, index, | |
1103 | &key); | |
1104 | } | |
1105 | /* | |
93b2dd12 | 1106 | * If a valid key is set, encryption should be enabled |
1da177e4 LT |
1107 | * (user may turn it off later). |
1108 | * This is also how "iwconfig ethX key on" works | |
1109 | */ | |
1110 | if ((index == current_index) && (key.length > 0)) | |
1111 | force = 1; | |
1112 | } else { | |
1113 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; | |
1114 | if ((index >= 0) && (index <= 3)) { | |
1115 | /* we want to set the key index */ | |
1116 | rvalue |= | |
1117 | mgt_set_request(priv, DOT11_OID_DEFKEYID, 0, | |
1118 | &index); | |
1119 | } else { | |
f59d9782 | 1120 | if (!(dwrq->flags & IW_ENCODE_MODE)) { |
1da177e4 LT |
1121 | /* we cannot do anything. Complain. */ |
1122 | return -EINVAL; | |
1123 | } | |
1124 | } | |
1125 | } | |
1126 | /* now read the flags */ | |
1127 | if (dwrq->flags & IW_ENCODE_DISABLED) { | |
93b2dd12 | 1128 | /* Encoding disabled, |
1da177e4 LT |
1129 | * authen = DOT11_AUTH_OS; |
1130 | * invoke = 0; | |
1131 | * exunencrypt = 0; */ | |
1132 | } | |
1133 | if (dwrq->flags & IW_ENCODE_OPEN) | |
1134 | /* Encode but accept non-encoded packets. No auth */ | |
1135 | invoke = 1; | |
1136 | if ((dwrq->flags & IW_ENCODE_RESTRICTED) || force) { | |
1137 | /* Refuse non-encoded packets. Auth */ | |
1138 | authen = DOT11_AUTH_BOTH; | |
1139 | invoke = 1; | |
1140 | exunencrypt = 1; | |
1141 | } | |
1142 | /* do the change if requested */ | |
1143 | if ((dwrq->flags & IW_ENCODE_MODE) || force) { | |
1144 | rvalue |= | |
1145 | mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen); | |
1146 | rvalue |= | |
1147 | mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke); | |
1148 | rvalue |= | |
1149 | mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, | |
1150 | &exunencrypt); | |
1151 | } | |
1152 | return rvalue; | |
1153 | } | |
1154 | ||
1155 | static int | |
1156 | prism54_get_encode(struct net_device *ndev, struct iw_request_info *info, | |
1157 | struct iw_point *dwrq, char *extra) | |
1158 | { | |
1159 | islpci_private *priv = netdev_priv(ndev); | |
1160 | struct obj_key *key; | |
1161 | u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1; | |
1162 | u32 authen = 0, invoke = 0, exunencrypt = 0; | |
1163 | int rvalue; | |
1164 | union oid_res_t r; | |
1165 | ||
1166 | /* first get the flags */ | |
1167 | rvalue = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r); | |
1168 | authen = r.u; | |
1169 | rvalue |= mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r); | |
1170 | invoke = r.u; | |
1171 | rvalue |= mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r); | |
1172 | exunencrypt = r.u; | |
1173 | ||
1174 | if (invoke && (authen == DOT11_AUTH_BOTH) && exunencrypt) | |
1175 | dwrq->flags = IW_ENCODE_RESTRICTED; | |
1176 | else if ((authen == DOT11_AUTH_OS) && !exunencrypt) { | |
1177 | if (invoke) | |
1178 | dwrq->flags = IW_ENCODE_OPEN; | |
1179 | else | |
1180 | dwrq->flags = IW_ENCODE_DISABLED; | |
1181 | } else | |
1182 | /* The card should not work in this state */ | |
1183 | dwrq->flags = 0; | |
1184 | ||
1185 | /* get the current device key index */ | |
1186 | rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); | |
1187 | devindex = r.u; | |
1188 | /* Now get the key, return it */ | |
8ba82e96 | 1189 | if (index == -1 || index > 3) |
1da177e4 LT |
1190 | /* no index provided, use the current one */ |
1191 | index = devindex; | |
1192 | rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r); | |
1193 | key = r.ptr; | |
1194 | dwrq->length = key->length; | |
1195 | memcpy(extra, key->key, dwrq->length); | |
1196 | kfree(key); | |
1197 | /* return the used key index */ | |
1198 | dwrq->flags |= devindex + 1; | |
1199 | ||
1200 | return rvalue; | |
1201 | } | |
1202 | ||
1203 | static int | |
1204 | prism54_get_txpower(struct net_device *ndev, struct iw_request_info *info, | |
1205 | struct iw_param *vwrq, char *extra) | |
1206 | { | |
1207 | islpci_private *priv = netdev_priv(ndev); | |
1208 | union oid_res_t r; | |
1209 | int rvalue; | |
1210 | ||
1211 | rvalue = mgt_get_request(priv, OID_INL_OUTPUTPOWER, 0, NULL, &r); | |
1212 | /* intersil firmware operates in 0.25 dBm (1/4 dBm) */ | |
1213 | vwrq->value = (s32) r.u / 4; | |
1214 | vwrq->fixed = 1; | |
1215 | /* radio is not turned of | |
93b2dd12 | 1216 | * btw: how is possible to turn off only the radio |
1da177e4 LT |
1217 | */ |
1218 | vwrq->disabled = 0; | |
1219 | ||
1220 | return rvalue; | |
1221 | } | |
1222 | ||
1223 | static int | |
1224 | prism54_set_txpower(struct net_device *ndev, struct iw_request_info *info, | |
1225 | struct iw_param *vwrq, char *extra) | |
1226 | { | |
1227 | islpci_private *priv = netdev_priv(ndev); | |
1228 | s32 u = vwrq->value; | |
1229 | ||
1230 | /* intersil firmware operates in 0.25 dBm (1/4) */ | |
1231 | u *= 4; | |
1232 | if (vwrq->disabled) { | |
1233 | /* don't know how to disable radio */ | |
1234 | printk(KERN_DEBUG | |
1235 | "%s: %s() disabling radio is not yet supported.\n", | |
1236 | priv->ndev->name, __FUNCTION__); | |
1237 | return -ENOTSUPP; | |
1238 | } else if (vwrq->fixed) | |
1239 | /* currently only fixed value is supported */ | |
1240 | return mgt_set_request(priv, OID_INL_OUTPUTPOWER, 0, &u); | |
1241 | else { | |
1242 | printk(KERN_DEBUG | |
1243 | "%s: %s() auto power will be implemented later.\n", | |
1244 | priv->ndev->name, __FUNCTION__); | |
1245 | return -ENOTSUPP; | |
1246 | } | |
1247 | } | |
1248 | ||
eab411f1 DW |
1249 | static int prism54_set_genie(struct net_device *ndev, |
1250 | struct iw_request_info *info, | |
1251 | struct iw_point *data, char *extra) | |
1252 | { | |
1253 | islpci_private *priv = netdev_priv(ndev); | |
1254 | int alen, ret = 0; | |
1255 | struct obj_attachment *attach; | |
1256 | ||
1257 | if (data->length > MAX_WPA_IE_LEN || | |
1258 | (data->length && extra == NULL)) | |
1259 | return -EINVAL; | |
1260 | ||
1261 | memcpy(priv->wpa_ie, extra, data->length); | |
1262 | priv->wpa_ie_len = data->length; | |
1263 | ||
1264 | alen = sizeof(*attach) + priv->wpa_ie_len; | |
1265 | attach = kzalloc(alen, GFP_KERNEL); | |
1266 | if (attach == NULL) | |
1267 | return -ENOMEM; | |
1268 | ||
1269 | #define WLAN_FC_TYPE_MGMT 0 | |
1270 | #define WLAN_FC_STYPE_ASSOC_REQ 0 | |
1271 | #define WLAN_FC_STYPE_REASSOC_REQ 2 | |
1272 | ||
1273 | /* Note: endianness is covered by mgt_set_varlen */ | |
1274 | attach->type = (WLAN_FC_TYPE_MGMT << 2) | | |
1275 | (WLAN_FC_STYPE_ASSOC_REQ << 4); | |
1276 | attach->id = -1; | |
1277 | attach->size = priv->wpa_ie_len; | |
1278 | memcpy(attach->data, extra, priv->wpa_ie_len); | |
1279 | ||
1280 | ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, | |
1281 | priv->wpa_ie_len); | |
1282 | if (ret == 0) { | |
1283 | attach->type = (WLAN_FC_TYPE_MGMT << 2) | | |
1284 | (WLAN_FC_STYPE_REASSOC_REQ << 4); | |
1285 | ||
1286 | ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, | |
1287 | priv->wpa_ie_len); | |
1288 | if (ret == 0) | |
1289 | printk(KERN_DEBUG "%s: WPA IE Attachment was set\n", | |
1290 | ndev->name); | |
1291 | } | |
1292 | ||
1293 | kfree(attach); | |
1294 | return ret; | |
1295 | } | |
1296 | ||
1297 | ||
1298 | static int prism54_get_genie(struct net_device *ndev, | |
1299 | struct iw_request_info *info, | |
1300 | struct iw_point *data, char *extra) | |
1301 | { | |
1302 | islpci_private *priv = netdev_priv(ndev); | |
1303 | int len = priv->wpa_ie_len; | |
1304 | ||
1305 | if (len <= 0) { | |
1306 | data->length = 0; | |
1307 | return 0; | |
1308 | } | |
1309 | ||
1310 | if (data->length < len) | |
1311 | return -E2BIG; | |
1312 | ||
1313 | data->length = len; | |
1314 | memcpy(extra, priv->wpa_ie, len); | |
1315 | ||
1316 | return 0; | |
1317 | } | |
1318 | ||
1319 | static int prism54_set_auth(struct net_device *ndev, | |
1320 | struct iw_request_info *info, | |
1321 | union iwreq_data *wrqu, char *extra) | |
1322 | { | |
1323 | islpci_private *priv = netdev_priv(ndev); | |
1324 | struct iw_param *param = &wrqu->param; | |
1325 | u32 mlmelevel = 0, authen = 0, dot1x = 0; | |
1326 | u32 exunencrypt = 0, privinvoked = 0, wpa = 0; | |
1327 | u32 old_wpa; | |
1328 | int ret = 0; | |
1329 | union oid_res_t r; | |
1330 | ||
1331 | if (islpci_get_state(priv) < PRV_STATE_INIT) | |
1332 | return 0; | |
1333 | ||
1334 | /* first get the flags */ | |
1335 | down_write(&priv->mib_sem); | |
1336 | wpa = old_wpa = priv->wpa; | |
1337 | up_write(&priv->mib_sem); | |
1338 | ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r); | |
1339 | authen = r.u; | |
1340 | ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r); | |
1341 | privinvoked = r.u; | |
1342 | ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r); | |
1343 | exunencrypt = r.u; | |
1344 | ret = mgt_get_request(priv, DOT11_OID_DOT1XENABLE, 0, NULL, &r); | |
1345 | dot1x = r.u; | |
1346 | ret = mgt_get_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, NULL, &r); | |
1347 | mlmelevel = r.u; | |
1348 | ||
1349 | if (ret < 0) | |
1350 | goto out; | |
1351 | ||
1352 | switch (param->flags & IW_AUTH_INDEX) { | |
1353 | case IW_AUTH_CIPHER_PAIRWISE: | |
1354 | case IW_AUTH_CIPHER_GROUP: | |
1355 | case IW_AUTH_KEY_MGMT: | |
1356 | break; | |
1357 | ||
1358 | case IW_AUTH_WPA_ENABLED: | |
1359 | /* Do the same thing as IW_AUTH_WPA_VERSION */ | |
1360 | if (param->value) { | |
1361 | wpa = 1; | |
1362 | privinvoked = 1; /* For privacy invoked */ | |
1363 | exunencrypt = 1; /* Filter out all unencrypted frames */ | |
1364 | dot1x = 0x01; /* To enable eap filter */ | |
1365 | mlmelevel = DOT11_MLME_EXTENDED; | |
1366 | authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */ | |
1367 | } else { | |
1368 | wpa = 0; | |
1369 | privinvoked = 0; | |
1370 | exunencrypt = 0; /* Do not filter un-encrypted data */ | |
1371 | dot1x = 0; | |
1372 | mlmelevel = DOT11_MLME_AUTO; | |
1373 | } | |
1374 | break; | |
1375 | ||
1376 | case IW_AUTH_WPA_VERSION: | |
1377 | if (param->value & IW_AUTH_WPA_VERSION_DISABLED) { | |
1378 | wpa = 0; | |
1379 | privinvoked = 0; | |
1380 | exunencrypt = 0; /* Do not filter un-encrypted data */ | |
1381 | dot1x = 0; | |
1382 | mlmelevel = DOT11_MLME_AUTO; | |
1383 | } else { | |
1384 | if (param->value & IW_AUTH_WPA_VERSION_WPA) | |
1385 | wpa = 1; | |
1386 | else if (param->value & IW_AUTH_WPA_VERSION_WPA2) | |
1387 | wpa = 2; | |
1388 | privinvoked = 1; /* For privacy invoked */ | |
1389 | exunencrypt = 1; /* Filter out all unencrypted frames */ | |
1390 | dot1x = 0x01; /* To enable eap filter */ | |
1391 | mlmelevel = DOT11_MLME_EXTENDED; | |
1392 | authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */ | |
1393 | } | |
1394 | break; | |
1395 | ||
1396 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
b5c41651 DW |
1397 | /* dot1x should be the opposite of RX_UNENCRYPTED_EAPOL; |
1398 | * turn off dot1x when allowing receipt of unencrypted EAPOL | |
1399 | * frames, turn on dot1x when receipt should be disallowed | |
1400 | */ | |
1401 | dot1x = param->value ? 0 : 0x01; | |
eab411f1 DW |
1402 | break; |
1403 | ||
1404 | case IW_AUTH_PRIVACY_INVOKED: | |
1405 | privinvoked = param->value ? 1 : 0; | |
b5c41651 | 1406 | break; |
eab411f1 DW |
1407 | |
1408 | case IW_AUTH_DROP_UNENCRYPTED: | |
1409 | exunencrypt = param->value ? 1 : 0; | |
1410 | break; | |
1411 | ||
1412 | case IW_AUTH_80211_AUTH_ALG: | |
1413 | if (param->value & IW_AUTH_ALG_SHARED_KEY) { | |
1414 | /* Only WEP uses _SK and _BOTH */ | |
1415 | if (wpa > 0) { | |
1416 | ret = -EINVAL; | |
1417 | goto out; | |
1418 | } | |
1419 | authen = DOT11_AUTH_SK; | |
1420 | } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) { | |
1421 | authen = DOT11_AUTH_OS; | |
1422 | } else { | |
1423 | ret = -EINVAL; | |
1424 | goto out; | |
1425 | } | |
1426 | break; | |
1427 | ||
1428 | default: | |
1429 | return -EOPNOTSUPP; | |
1430 | } | |
1431 | ||
1432 | /* Set all the values */ | |
1433 | down_write(&priv->mib_sem); | |
1434 | priv->wpa = wpa; | |
1435 | up_write(&priv->mib_sem); | |
1436 | mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen); | |
1437 | mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &privinvoked); | |
1438 | mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &exunencrypt); | |
1439 | mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x); | |
1440 | mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlmelevel); | |
1441 | ||
1442 | out: | |
1443 | return ret; | |
1444 | } | |
1445 | ||
1446 | static int prism54_get_auth(struct net_device *ndev, | |
1447 | struct iw_request_info *info, | |
1448 | union iwreq_data *wrqu, char *extra) | |
1449 | { | |
1450 | islpci_private *priv = netdev_priv(ndev); | |
1451 | struct iw_param *param = &wrqu->param; | |
1452 | u32 wpa = 0; | |
1453 | int ret = 0; | |
1454 | union oid_res_t r; | |
1455 | ||
1456 | if (islpci_get_state(priv) < PRV_STATE_INIT) | |
1457 | return 0; | |
1458 | ||
1459 | /* first get the flags */ | |
1460 | down_write(&priv->mib_sem); | |
1461 | wpa = priv->wpa; | |
1462 | up_write(&priv->mib_sem); | |
1463 | ||
1464 | switch (param->flags & IW_AUTH_INDEX) { | |
1465 | case IW_AUTH_CIPHER_PAIRWISE: | |
1466 | case IW_AUTH_CIPHER_GROUP: | |
1467 | case IW_AUTH_KEY_MGMT: | |
1468 | /* | |
1469 | * wpa_supplicant will control these internally | |
1470 | */ | |
1471 | ret = -EOPNOTSUPP; | |
1472 | break; | |
1473 | ||
1474 | case IW_AUTH_WPA_VERSION: | |
1475 | switch (wpa) { | |
1476 | case 1: | |
1477 | param->value = IW_AUTH_WPA_VERSION_WPA; | |
1478 | break; | |
1479 | case 2: | |
1480 | param->value = IW_AUTH_WPA_VERSION_WPA2; | |
1481 | break; | |
1482 | case 0: | |
1483 | default: | |
1484 | param->value = IW_AUTH_WPA_VERSION_DISABLED; | |
1485 | break; | |
1486 | } | |
1487 | break; | |
1488 | ||
1489 | case IW_AUTH_DROP_UNENCRYPTED: | |
1490 | ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r); | |
1491 | if (ret >= 0) | |
1492 | param->value = r.u > 0 ? 1 : 0; | |
1493 | break; | |
1494 | ||
1495 | case IW_AUTH_80211_AUTH_ALG: | |
1496 | ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r); | |
1497 | if (ret >= 0) { | |
1498 | switch (r.u) { | |
1499 | case DOT11_AUTH_OS: | |
1500 | param->value = IW_AUTH_ALG_OPEN_SYSTEM; | |
1501 | break; | |
1502 | case DOT11_AUTH_BOTH: | |
1503 | case DOT11_AUTH_SK: | |
1504 | param->value = IW_AUTH_ALG_SHARED_KEY; | |
1505 | case DOT11_AUTH_NONE: | |
1506 | default: | |
1507 | param->value = 0; | |
1508 | break; | |
1509 | } | |
1510 | } | |
1511 | break; | |
1512 | ||
1513 | case IW_AUTH_WPA_ENABLED: | |
1514 | param->value = wpa > 0 ? 1 : 0; | |
1515 | break; | |
1516 | ||
1517 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
1518 | ret = mgt_get_request(priv, DOT11_OID_DOT1XENABLE, 0, NULL, &r); | |
1519 | if (ret >= 0) | |
1520 | param->value = r.u > 0 ? 1 : 0; | |
1521 | break; | |
1522 | ||
1523 | case IW_AUTH_PRIVACY_INVOKED: | |
1524 | ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r); | |
1525 | if (ret >= 0) | |
1526 | param->value = r.u > 0 ? 1 : 0; | |
1527 | break; | |
1528 | ||
1529 | default: | |
1530 | return -EOPNOTSUPP; | |
1531 | } | |
1532 | return ret; | |
1533 | } | |
1534 | ||
1535 | static int prism54_set_encodeext(struct net_device *ndev, | |
1536 | struct iw_request_info *info, | |
1537 | union iwreq_data *wrqu, | |
1538 | char *extra) | |
1539 | { | |
1540 | islpci_private *priv = netdev_priv(ndev); | |
1541 | struct iw_point *encoding = &wrqu->encoding; | |
1542 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
1543 | int idx, alg = ext->alg, set_key = 1; | |
1544 | union oid_res_t r; | |
1545 | int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0; | |
1546 | int ret = 0; | |
1547 | ||
1548 | if (islpci_get_state(priv) < PRV_STATE_INIT) | |
1549 | return 0; | |
1550 | ||
1551 | /* Determine and validate the key index */ | |
1552 | idx = (encoding->flags & IW_ENCODE_INDEX) - 1; | |
1553 | if (idx) { | |
1554 | if (idx < 0 || idx > 3) | |
1555 | return -EINVAL; | |
1556 | } else { | |
1557 | ret = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); | |
1558 | if (ret < 0) | |
1559 | goto out; | |
1560 | idx = r.u; | |
1561 | } | |
1562 | ||
1563 | if (encoding->flags & IW_ENCODE_DISABLED) | |
1564 | alg = IW_ENCODE_ALG_NONE; | |
1565 | ||
1566 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { | |
1567 | /* Only set transmit key index here, actual | |
1568 | * key is set below if needed. | |
1569 | */ | |
1570 | ret = mgt_set_request(priv, DOT11_OID_DEFKEYID, 0, &idx); | |
1571 | set_key = ext->key_len > 0 ? 1 : 0; | |
1572 | } | |
1573 | ||
1574 | if (set_key) { | |
1575 | struct obj_key key = { DOT11_PRIV_WEP, 0, "" }; | |
1576 | switch (alg) { | |
1577 | case IW_ENCODE_ALG_NONE: | |
1578 | break; | |
1579 | case IW_ENCODE_ALG_WEP: | |
1580 | if (ext->key_len > KEY_SIZE_WEP104) { | |
1581 | ret = -EINVAL; | |
1582 | goto out; | |
1583 | } | |
1584 | if (ext->key_len > KEY_SIZE_WEP40) | |
1585 | key.length = KEY_SIZE_WEP104; | |
1586 | else | |
1587 | key.length = KEY_SIZE_WEP40; | |
1588 | break; | |
1589 | case IW_ENCODE_ALG_TKIP: | |
1590 | if (ext->key_len > KEY_SIZE_TKIP) { | |
1591 | ret = -EINVAL; | |
1592 | goto out; | |
1593 | } | |
1594 | key.type = DOT11_PRIV_TKIP; | |
1595 | key.length = KEY_SIZE_TKIP; | |
b5c41651 | 1596 | break; |
eab411f1 DW |
1597 | default: |
1598 | return -EINVAL; | |
1599 | } | |
1600 | ||
1601 | if (key.length) { | |
1602 | memset(key.key, 0, sizeof(key.key)); | |
1603 | memcpy(key.key, ext->key, ext->key_len); | |
1604 | ret = mgt_set_request(priv, DOT11_OID_DEFKEYX, idx, | |
1605 | &key); | |
1606 | if (ret < 0) | |
1607 | goto out; | |
1608 | } | |
1609 | } | |
1610 | ||
1611 | /* Read the flags */ | |
1612 | if (encoding->flags & IW_ENCODE_DISABLED) { | |
1613 | /* Encoding disabled, | |
1614 | * authen = DOT11_AUTH_OS; | |
1615 | * invoke = 0; | |
1616 | * exunencrypt = 0; */ | |
1617 | } | |
1618 | if (encoding->flags & IW_ENCODE_OPEN) { | |
1619 | /* Encode but accept non-encoded packets. No auth */ | |
1620 | invoke = 1; | |
1621 | } | |
1622 | if (encoding->flags & IW_ENCODE_RESTRICTED) { | |
1623 | /* Refuse non-encoded packets. Auth */ | |
1624 | authen = DOT11_AUTH_BOTH; | |
1625 | invoke = 1; | |
1626 | exunencrypt = 1; | |
1627 | } | |
1628 | ||
1629 | /* do the change if requested */ | |
1630 | if (encoding->flags & IW_ENCODE_MODE) { | |
1631 | ret = mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, | |
1632 | &authen); | |
1633 | ret = mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, | |
1634 | &invoke); | |
1635 | ret = mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, | |
1636 | &exunencrypt); | |
1637 | } | |
1638 | ||
1639 | out: | |
1640 | return ret; | |
1641 | } | |
1642 | ||
1643 | ||
1644 | static int prism54_get_encodeext(struct net_device *ndev, | |
1645 | struct iw_request_info *info, | |
1646 | union iwreq_data *wrqu, | |
1647 | char *extra) | |
1648 | { | |
1649 | islpci_private *priv = netdev_priv(ndev); | |
1650 | struct iw_point *encoding = &wrqu->encoding; | |
1651 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
1652 | int idx, max_key_len; | |
1653 | union oid_res_t r; | |
1654 | int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0, wpa = 0; | |
1655 | int ret = 0; | |
1656 | ||
1657 | if (islpci_get_state(priv) < PRV_STATE_INIT) | |
1658 | return 0; | |
1659 | ||
1660 | /* first get the flags */ | |
1661 | ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r); | |
1662 | authen = r.u; | |
1663 | ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r); | |
1664 | invoke = r.u; | |
1665 | ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r); | |
1666 | exunencrypt = r.u; | |
1667 | if (ret < 0) | |
1668 | goto out; | |
1669 | ||
1670 | max_key_len = encoding->length - sizeof(*ext); | |
1671 | if (max_key_len < 0) | |
1672 | return -EINVAL; | |
1673 | ||
1674 | idx = (encoding->flags & IW_ENCODE_INDEX) - 1; | |
1675 | if (idx) { | |
1676 | if (idx < 0 || idx > 3) | |
1677 | return -EINVAL; | |
1678 | } else { | |
1679 | ret = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); | |
1680 | if (ret < 0) | |
1681 | goto out; | |
1682 | idx = r.u; | |
1683 | } | |
1684 | ||
1685 | encoding->flags = idx + 1; | |
1686 | memset(ext, 0, sizeof(*ext)); | |
1687 | ||
1688 | switch (authen) { | |
1689 | case DOT11_AUTH_BOTH: | |
1690 | case DOT11_AUTH_SK: | |
1691 | wrqu->encoding.flags |= IW_ENCODE_RESTRICTED; | |
1692 | case DOT11_AUTH_OS: | |
1693 | default: | |
1694 | wrqu->encoding.flags |= IW_ENCODE_OPEN; | |
1695 | break; | |
1696 | } | |
1697 | ||
1698 | down_write(&priv->mib_sem); | |
1699 | wpa = priv->wpa; | |
1700 | up_write(&priv->mib_sem); | |
1701 | ||
1702 | if (authen == DOT11_AUTH_OS && !exunencrypt && !invoke && !wpa) { | |
1703 | /* No encryption */ | |
1704 | ext->alg = IW_ENCODE_ALG_NONE; | |
1705 | ext->key_len = 0; | |
1706 | wrqu->encoding.flags |= IW_ENCODE_DISABLED; | |
1707 | } else { | |
1708 | struct obj_key *key; | |
1709 | ||
1710 | ret = mgt_get_request(priv, DOT11_OID_DEFKEYX, idx, NULL, &r); | |
1711 | if (ret < 0) | |
1712 | goto out; | |
1713 | key = r.ptr; | |
1714 | if (max_key_len < key->length) { | |
1715 | ret = -E2BIG; | |
1716 | goto out; | |
1717 | } | |
1718 | memcpy(ext->key, key->key, key->length); | |
1719 | ext->key_len = key->length; | |
1720 | ||
1721 | switch (key->type) { | |
1722 | case DOT11_PRIV_TKIP: | |
1723 | ext->alg = IW_ENCODE_ALG_TKIP; | |
1724 | break; | |
1725 | default: | |
1726 | case DOT11_PRIV_WEP: | |
1727 | ext->alg = IW_ENCODE_ALG_WEP; | |
1728 | break; | |
1729 | } | |
1730 | wrqu->encoding.flags |= IW_ENCODE_ENABLED; | |
1731 | } | |
1732 | ||
1733 | out: | |
1734 | return ret; | |
1735 | } | |
1736 | ||
1737 | ||
1da177e4 LT |
1738 | static int |
1739 | prism54_reset(struct net_device *ndev, struct iw_request_info *info, | |
1740 | __u32 * uwrq, char *extra) | |
1741 | { | |
1742 | islpci_reset(netdev_priv(ndev), 0); | |
1743 | ||
1744 | return 0; | |
1745 | } | |
1746 | ||
1747 | static int | |
1748 | prism54_get_oid(struct net_device *ndev, struct iw_request_info *info, | |
1749 | struct iw_point *dwrq, char *extra) | |
1750 | { | |
1751 | union oid_res_t r; | |
1752 | int rvalue; | |
1753 | enum oid_num_t n = dwrq->flags; | |
1754 | ||
6dbc9c89 | 1755 | rvalue = mgt_get_request(netdev_priv(ndev), n, 0, NULL, &r); |
1da177e4 LT |
1756 | dwrq->length = mgt_response_to_str(n, &r, extra); |
1757 | if ((isl_oid[n].flags & OID_FLAG_TYPE) != OID_TYPE_U32) | |
1758 | kfree(r.ptr); | |
1759 | return rvalue; | |
1760 | } | |
1761 | ||
1762 | static int | |
1763 | prism54_set_u32(struct net_device *ndev, struct iw_request_info *info, | |
1764 | __u32 * uwrq, char *extra) | |
1765 | { | |
1766 | u32 oid = uwrq[0], u = uwrq[1]; | |
1767 | ||
6dbc9c89 | 1768 | return mgt_set_request(netdev_priv(ndev), oid, 0, &u); |
1da177e4 LT |
1769 | } |
1770 | ||
1771 | static int | |
1772 | prism54_set_raw(struct net_device *ndev, struct iw_request_info *info, | |
1773 | struct iw_point *dwrq, char *extra) | |
1774 | { | |
1775 | u32 oid = dwrq->flags; | |
1776 | ||
6dbc9c89 | 1777 | return mgt_set_request(netdev_priv(ndev), oid, 0, extra); |
1da177e4 LT |
1778 | } |
1779 | ||
1780 | void | |
1781 | prism54_acl_init(struct islpci_acl *acl) | |
1782 | { | |
6f865c0a | 1783 | mutex_init(&acl->lock); |
1da177e4 LT |
1784 | INIT_LIST_HEAD(&acl->mac_list); |
1785 | acl->size = 0; | |
1786 | acl->policy = MAC_POLICY_OPEN; | |
1787 | } | |
1788 | ||
1789 | static void | |
1790 | prism54_clear_mac(struct islpci_acl *acl) | |
1791 | { | |
1792 | struct list_head *ptr, *next; | |
1793 | struct mac_entry *entry; | |
1794 | ||
6f865c0a | 1795 | mutex_lock(&acl->lock); |
1da177e4 LT |
1796 | |
1797 | if (acl->size == 0) { | |
6f865c0a | 1798 | mutex_unlock(&acl->lock); |
1da177e4 LT |
1799 | return; |
1800 | } | |
1801 | ||
1802 | for (ptr = acl->mac_list.next, next = ptr->next; | |
1803 | ptr != &acl->mac_list; ptr = next, next = ptr->next) { | |
1804 | entry = list_entry(ptr, struct mac_entry, _list); | |
1805 | list_del(ptr); | |
1806 | kfree(entry); | |
1807 | } | |
1808 | acl->size = 0; | |
6f865c0a | 1809 | mutex_unlock(&acl->lock); |
1da177e4 LT |
1810 | } |
1811 | ||
1812 | void | |
1813 | prism54_acl_clean(struct islpci_acl *acl) | |
1814 | { | |
1815 | prism54_clear_mac(acl); | |
1816 | } | |
1817 | ||
1818 | static int | |
1819 | prism54_add_mac(struct net_device *ndev, struct iw_request_info *info, | |
1820 | struct sockaddr *awrq, char *extra) | |
1821 | { | |
1822 | islpci_private *priv = netdev_priv(ndev); | |
1823 | struct islpci_acl *acl = &priv->acl; | |
1824 | struct mac_entry *entry; | |
1825 | struct sockaddr *addr = (struct sockaddr *) extra; | |
1826 | ||
1827 | if (addr->sa_family != ARPHRD_ETHER) | |
1828 | return -EOPNOTSUPP; | |
1829 | ||
1830 | entry = kmalloc(sizeof (struct mac_entry), GFP_KERNEL); | |
1831 | if (entry == NULL) | |
1832 | return -ENOMEM; | |
1833 | ||
1834 | memcpy(entry->addr, addr->sa_data, ETH_ALEN); | |
1835 | ||
6f865c0a | 1836 | if (mutex_lock_interruptible(&acl->lock)) { |
1da177e4 LT |
1837 | kfree(entry); |
1838 | return -ERESTARTSYS; | |
1839 | } | |
1840 | list_add_tail(&entry->_list, &acl->mac_list); | |
1841 | acl->size++; | |
6f865c0a | 1842 | mutex_unlock(&acl->lock); |
1da177e4 LT |
1843 | |
1844 | return 0; | |
1845 | } | |
1846 | ||
1847 | static int | |
1848 | prism54_del_mac(struct net_device *ndev, struct iw_request_info *info, | |
1849 | struct sockaddr *awrq, char *extra) | |
1850 | { | |
1851 | islpci_private *priv = netdev_priv(ndev); | |
1852 | struct islpci_acl *acl = &priv->acl; | |
1853 | struct mac_entry *entry; | |
1da177e4 LT |
1854 | struct sockaddr *addr = (struct sockaddr *) extra; |
1855 | ||
1856 | if (addr->sa_family != ARPHRD_ETHER) | |
1857 | return -EOPNOTSUPP; | |
1858 | ||
6f865c0a | 1859 | if (mutex_lock_interruptible(&acl->lock)) |
1da177e4 | 1860 | return -ERESTARTSYS; |
426921bd | 1861 | list_for_each_entry(entry, &acl->mac_list, _list) { |
1da177e4 | 1862 | if (memcmp(entry->addr, addr->sa_data, ETH_ALEN) == 0) { |
426921bd | 1863 | list_del(&entry->_list); |
1da177e4 LT |
1864 | acl->size--; |
1865 | kfree(entry); | |
6f865c0a | 1866 | mutex_unlock(&acl->lock); |
1da177e4 LT |
1867 | return 0; |
1868 | } | |
1869 | } | |
6f865c0a | 1870 | mutex_unlock(&acl->lock); |
1da177e4 LT |
1871 | return -EINVAL; |
1872 | } | |
1873 | ||
1874 | static int | |
1875 | prism54_get_mac(struct net_device *ndev, struct iw_request_info *info, | |
1876 | struct iw_point *dwrq, char *extra) | |
1877 | { | |
1878 | islpci_private *priv = netdev_priv(ndev); | |
1879 | struct islpci_acl *acl = &priv->acl; | |
1880 | struct mac_entry *entry; | |
1da177e4 LT |
1881 | struct sockaddr *dst = (struct sockaddr *) extra; |
1882 | ||
1883 | dwrq->length = 0; | |
1884 | ||
6f865c0a | 1885 | if (mutex_lock_interruptible(&acl->lock)) |
1da177e4 LT |
1886 | return -ERESTARTSYS; |
1887 | ||
426921bd | 1888 | list_for_each_entry(entry, &acl->mac_list, _list) { |
1da177e4 LT |
1889 | memcpy(dst->sa_data, entry->addr, ETH_ALEN); |
1890 | dst->sa_family = ARPHRD_ETHER; | |
1891 | dwrq->length++; | |
1892 | dst++; | |
1893 | } | |
6f865c0a | 1894 | mutex_unlock(&acl->lock); |
1da177e4 LT |
1895 | return 0; |
1896 | } | |
1897 | ||
1898 | /* Setting policy also clears the MAC acl, even if we don't change the defaut | |
1899 | * policy | |
1900 | */ | |
1901 | ||
1902 | static int | |
1903 | prism54_set_policy(struct net_device *ndev, struct iw_request_info *info, | |
1904 | __u32 * uwrq, char *extra) | |
1905 | { | |
1906 | islpci_private *priv = netdev_priv(ndev); | |
1907 | struct islpci_acl *acl = &priv->acl; | |
1908 | u32 mlmeautolevel; | |
1909 | ||
1910 | prism54_clear_mac(acl); | |
1911 | ||
1912 | if ((*uwrq < MAC_POLICY_OPEN) || (*uwrq > MAC_POLICY_REJECT)) | |
1913 | return -EINVAL; | |
1914 | ||
1915 | down_write(&priv->mib_sem); | |
1916 | ||
1917 | acl->policy = *uwrq; | |
1918 | ||
1919 | /* the ACL code needs an intermediate mlmeautolevel */ | |
1920 | if ((priv->iw_mode == IW_MODE_MASTER) && | |
1921 | (acl->policy != MAC_POLICY_OPEN)) | |
1922 | mlmeautolevel = DOT11_MLME_INTERMEDIATE; | |
1923 | else | |
1924 | mlmeautolevel = CARD_DEFAULT_MLME_MODE; | |
1925 | if (priv->wpa) | |
1926 | mlmeautolevel = DOT11_MLME_EXTENDED; | |
1927 | mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel); | |
1928 | /* restart the card with our new policy */ | |
1929 | if (mgt_commit(priv)) { | |
1930 | up_write(&priv->mib_sem); | |
1931 | return -EIO; | |
1932 | } | |
1933 | up_write(&priv->mib_sem); | |
1934 | ||
1935 | return 0; | |
1936 | } | |
1937 | ||
1938 | static int | |
1939 | prism54_get_policy(struct net_device *ndev, struct iw_request_info *info, | |
1940 | __u32 * uwrq, char *extra) | |
1941 | { | |
1942 | islpci_private *priv = netdev_priv(ndev); | |
1943 | struct islpci_acl *acl = &priv->acl; | |
1944 | ||
1945 | *uwrq = acl->policy; | |
1946 | ||
1947 | return 0; | |
1948 | } | |
1949 | ||
1950 | /* Return 1 only if client should be accepted. */ | |
1951 | ||
1952 | static int | |
1953 | prism54_mac_accept(struct islpci_acl *acl, char *mac) | |
1954 | { | |
1da177e4 LT |
1955 | struct mac_entry *entry; |
1956 | int res = 0; | |
1957 | ||
6f865c0a | 1958 | if (mutex_lock_interruptible(&acl->lock)) |
1da177e4 LT |
1959 | return -ERESTARTSYS; |
1960 | ||
1961 | if (acl->policy == MAC_POLICY_OPEN) { | |
6f865c0a | 1962 | mutex_unlock(&acl->lock); |
1da177e4 LT |
1963 | return 1; |
1964 | } | |
1965 | ||
426921bd | 1966 | list_for_each_entry(entry, &acl->mac_list, _list) { |
1da177e4 LT |
1967 | if (memcmp(entry->addr, mac, ETH_ALEN) == 0) { |
1968 | res = 1; | |
1969 | break; | |
1970 | } | |
1971 | } | |
1972 | res = (acl->policy == MAC_POLICY_ACCEPT) ? !res : res; | |
6f865c0a | 1973 | mutex_unlock(&acl->lock); |
1da177e4 LT |
1974 | |
1975 | return res; | |
1976 | } | |
1977 | ||
1978 | static int | |
1979 | prism54_kick_all(struct net_device *ndev, struct iw_request_info *info, | |
1980 | struct iw_point *dwrq, char *extra) | |
1981 | { | |
1982 | struct obj_mlme *mlme; | |
1983 | int rvalue; | |
1984 | ||
1985 | mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL); | |
1986 | if (mlme == NULL) | |
1987 | return -ENOMEM; | |
1988 | ||
1989 | /* Tell the card to kick every client */ | |
1990 | mlme->id = 0; | |
1991 | rvalue = | |
1992 | mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme); | |
1993 | kfree(mlme); | |
1994 | ||
1995 | return rvalue; | |
1996 | } | |
1997 | ||
1998 | static int | |
1999 | prism54_kick_mac(struct net_device *ndev, struct iw_request_info *info, | |
2000 | struct sockaddr *awrq, char *extra) | |
2001 | { | |
2002 | struct obj_mlme *mlme; | |
2003 | struct sockaddr *addr = (struct sockaddr *) extra; | |
2004 | int rvalue; | |
2005 | ||
2006 | if (addr->sa_family != ARPHRD_ETHER) | |
2007 | return -EOPNOTSUPP; | |
2008 | ||
2009 | mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL); | |
2010 | if (mlme == NULL) | |
2011 | return -ENOMEM; | |
2012 | ||
2013 | /* Tell the card to only kick the corresponding bastard */ | |
2014 | memcpy(mlme->address, addr->sa_data, ETH_ALEN); | |
2015 | mlme->id = -1; | |
2016 | rvalue = | |
2017 | mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme); | |
2018 | ||
2019 | kfree(mlme); | |
2020 | ||
2021 | return rvalue; | |
2022 | } | |
2023 | ||
2024 | /* Translate a TRAP oid into a wireless event. Called in islpci_mgt_receive. */ | |
2025 | ||
2026 | static void | |
2027 | format_event(islpci_private *priv, char *dest, const char *str, | |
2028 | const struct obj_mlme *mlme, u16 *length, int error) | |
2029 | { | |
0795af57 | 2030 | DECLARE_MAC_BUF(mac); |
1da177e4 | 2031 | int n = snprintf(dest, IW_CUSTOM_MAX, |
0795af57 | 2032 | "%s %s %s %s (%2.2X)", |
1da177e4 LT |
2033 | str, |
2034 | ((priv->iw_mode == IW_MODE_MASTER) ? "from" : "to"), | |
0795af57 | 2035 | print_mac(mac, mlme->address), |
1da177e4 LT |
2036 | (error ? (mlme->code ? " : REJECTED " : " : ACCEPTED ") |
2037 | : ""), mlme->code); | |
2038 | BUG_ON(n > IW_CUSTOM_MAX); | |
2039 | *length = n; | |
2040 | } | |
2041 | ||
2042 | static void | |
2043 | send_formatted_event(islpci_private *priv, const char *str, | |
2044 | const struct obj_mlme *mlme, int error) | |
2045 | { | |
2046 | union iwreq_data wrqu; | |
2047 | char *memptr; | |
2048 | ||
2049 | memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL); | |
2050 | if (!memptr) | |
2051 | return; | |
2052 | wrqu.data.pointer = memptr; | |
2053 | wrqu.data.length = 0; | |
2054 | format_event(priv, memptr, str, mlme, &wrqu.data.length, | |
2055 | error); | |
2056 | wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr); | |
2057 | kfree(memptr); | |
2058 | } | |
2059 | ||
2060 | static void | |
2061 | send_simple_event(islpci_private *priv, const char *str) | |
2062 | { | |
2063 | union iwreq_data wrqu; | |
2064 | char *memptr; | |
2065 | int n = strlen(str); | |
2066 | ||
2067 | memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL); | |
2068 | if (!memptr) | |
2069 | return; | |
2070 | BUG_ON(n > IW_CUSTOM_MAX); | |
2071 | wrqu.data.pointer = memptr; | |
2072 | wrqu.data.length = n; | |
2073 | strcpy(memptr, str); | |
2074 | wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr); | |
2075 | kfree(memptr); | |
2076 | } | |
2077 | ||
2078 | static void | |
2079 | link_changed(struct net_device *ndev, u32 bitrate) | |
2080 | { | |
2081 | islpci_private *priv = netdev_priv(ndev); | |
2082 | ||
2083 | if (bitrate) { | |
7b463ced | 2084 | netif_carrier_on(ndev); |
1da177e4 LT |
2085 | if (priv->iw_mode == IW_MODE_INFRA) { |
2086 | union iwreq_data uwrq; | |
2087 | prism54_get_wap(ndev, NULL, (struct sockaddr *) &uwrq, | |
2088 | NULL); | |
2089 | wireless_send_event(ndev, SIOCGIWAP, &uwrq, NULL); | |
2090 | } else | |
2091 | send_simple_event(netdev_priv(ndev), | |
2092 | "Link established"); | |
7b463ced LR |
2093 | } else { |
2094 | netif_carrier_off(ndev); | |
1da177e4 | 2095 | send_simple_event(netdev_priv(ndev), "Link lost"); |
7b463ced | 2096 | } |
1da177e4 LT |
2097 | } |
2098 | ||
2099 | /* Beacon/ProbeResp payload header */ | |
2100 | struct ieee80211_beacon_phdr { | |
2101 | u8 timestamp[8]; | |
2102 | u16 beacon_int; | |
2103 | u16 capab_info; | |
2104 | } __attribute__ ((packed)); | |
2105 | ||
2106 | #define WLAN_EID_GENERIC 0xdd | |
2107 | static u8 wpa_oid[4] = { 0x00, 0x50, 0xf2, 1 }; | |
2108 | ||
1da177e4 | 2109 | static void |
eab411f1 DW |
2110 | prism54_wpa_bss_ie_add(islpci_private *priv, u8 *bssid, |
2111 | u8 *wpa_ie, size_t wpa_ie_len) | |
1da177e4 LT |
2112 | { |
2113 | struct list_head *ptr; | |
2114 | struct islpci_bss_wpa_ie *bss = NULL; | |
0795af57 | 2115 | DECLARE_MAC_BUF(mac); |
1da177e4 LT |
2116 | |
2117 | if (wpa_ie_len > MAX_WPA_IE_LEN) | |
2118 | wpa_ie_len = MAX_WPA_IE_LEN; | |
2119 | ||
f948db5d | 2120 | mutex_lock(&priv->wpa_lock); |
1da177e4 LT |
2121 | |
2122 | /* try to use existing entry */ | |
2123 | list_for_each(ptr, &priv->bss_wpa_list) { | |
2124 | bss = list_entry(ptr, struct islpci_bss_wpa_ie, list); | |
2125 | if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) { | |
2126 | list_move(&bss->list, &priv->bss_wpa_list); | |
2127 | break; | |
2128 | } | |
2129 | bss = NULL; | |
2130 | } | |
2131 | ||
2132 | if (bss == NULL) { | |
2133 | /* add a new BSS entry; if max number of entries is already | |
2134 | * reached, replace the least recently updated */ | |
2135 | if (priv->num_bss_wpa >= MAX_BSS_WPA_IE_COUNT) { | |
2136 | bss = list_entry(priv->bss_wpa_list.prev, | |
2137 | struct islpci_bss_wpa_ie, list); | |
2138 | list_del(&bss->list); | |
2139 | } else { | |
b950e83b YB |
2140 | bss = kzalloc(sizeof (*bss), GFP_ATOMIC); |
2141 | if (bss != NULL) | |
1da177e4 | 2142 | priv->num_bss_wpa++; |
1da177e4 LT |
2143 | } |
2144 | if (bss != NULL) { | |
2145 | memcpy(bss->bssid, bssid, ETH_ALEN); | |
2146 | list_add(&bss->list, &priv->bss_wpa_list); | |
2147 | } | |
2148 | } | |
2149 | ||
2150 | if (bss != NULL) { | |
2151 | memcpy(bss->wpa_ie, wpa_ie, wpa_ie_len); | |
2152 | bss->wpa_ie_len = wpa_ie_len; | |
2153 | bss->last_update = jiffies; | |
2154 | } else { | |
0795af57 JP |
2155 | printk(KERN_DEBUG "Failed to add BSS WPA entry for " |
2156 | "%s\n", print_mac(mac, bssid)); | |
1da177e4 LT |
2157 | } |
2158 | ||
2159 | /* expire old entries from WPA list */ | |
2160 | while (priv->num_bss_wpa > 0) { | |
2161 | bss = list_entry(priv->bss_wpa_list.prev, | |
2162 | struct islpci_bss_wpa_ie, list); | |
2163 | if (!time_after(jiffies, bss->last_update + 60 * HZ)) | |
2164 | break; | |
2165 | ||
2166 | list_del(&bss->list); | |
2167 | priv->num_bss_wpa--; | |
2168 | kfree(bss); | |
2169 | } | |
2170 | ||
f948db5d | 2171 | mutex_unlock(&priv->wpa_lock); |
1da177e4 LT |
2172 | } |
2173 | ||
2174 | static size_t | |
eab411f1 | 2175 | prism54_wpa_bss_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie) |
1da177e4 LT |
2176 | { |
2177 | struct list_head *ptr; | |
2178 | struct islpci_bss_wpa_ie *bss = NULL; | |
2179 | size_t len = 0; | |
2180 | ||
f948db5d | 2181 | mutex_lock(&priv->wpa_lock); |
1da177e4 LT |
2182 | |
2183 | list_for_each(ptr, &priv->bss_wpa_list) { | |
2184 | bss = list_entry(ptr, struct islpci_bss_wpa_ie, list); | |
2185 | if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) | |
2186 | break; | |
2187 | bss = NULL; | |
2188 | } | |
2189 | if (bss) { | |
2190 | len = bss->wpa_ie_len; | |
2191 | memcpy(wpa_ie, bss->wpa_ie, len); | |
2192 | } | |
f948db5d | 2193 | mutex_unlock(&priv->wpa_lock); |
1da177e4 LT |
2194 | |
2195 | return len; | |
2196 | } | |
2197 | ||
2198 | void | |
eab411f1 | 2199 | prism54_wpa_bss_ie_init(islpci_private *priv) |
1da177e4 LT |
2200 | { |
2201 | INIT_LIST_HEAD(&priv->bss_wpa_list); | |
f948db5d | 2202 | mutex_init(&priv->wpa_lock); |
1da177e4 LT |
2203 | } |
2204 | ||
2205 | void | |
eab411f1 | 2206 | prism54_wpa_bss_ie_clean(islpci_private *priv) |
1da177e4 | 2207 | { |
426921bd | 2208 | struct islpci_bss_wpa_ie *bss, *n; |
1da177e4 | 2209 | |
426921bd | 2210 | list_for_each_entry_safe(bss, n, &priv->bss_wpa_list, list) { |
1da177e4 LT |
2211 | kfree(bss); |
2212 | } | |
2213 | } | |
2214 | ||
2215 | static void | |
2216 | prism54_process_bss_data(islpci_private *priv, u32 oid, u8 *addr, | |
2217 | u8 *payload, size_t len) | |
2218 | { | |
2219 | struct ieee80211_beacon_phdr *hdr; | |
2220 | u8 *pos, *end; | |
0795af57 | 2221 | DECLARE_MAC_BUF(mac); |
1da177e4 LT |
2222 | |
2223 | if (!priv->wpa) | |
2224 | return; | |
2225 | ||
2226 | hdr = (struct ieee80211_beacon_phdr *) payload; | |
2227 | pos = (u8 *) (hdr + 1); | |
2228 | end = payload + len; | |
2229 | while (pos < end) { | |
2230 | if (pos + 2 + pos[1] > end) { | |
2231 | printk(KERN_DEBUG "Parsing Beacon/ProbeResp failed " | |
0795af57 | 2232 | "for %s\n", print_mac(mac, addr)); |
1da177e4 LT |
2233 | return; |
2234 | } | |
2235 | if (pos[0] == WLAN_EID_GENERIC && pos[1] >= 4 && | |
2236 | memcmp(pos + 2, wpa_oid, 4) == 0) { | |
eab411f1 | 2237 | prism54_wpa_bss_ie_add(priv, addr, pos, pos[1] + 2); |
1da177e4 LT |
2238 | return; |
2239 | } | |
2240 | pos += 2 + pos[1]; | |
2241 | } | |
2242 | } | |
2243 | ||
2244 | static void | |
2245 | handle_request(islpci_private *priv, struct obj_mlme *mlme, enum oid_num_t oid) | |
2246 | { | |
2247 | if (((mlme->state == DOT11_STATE_AUTHING) || | |
2248 | (mlme->state == DOT11_STATE_ASSOCING)) | |
2249 | && mgt_mlme_answer(priv)) { | |
2250 | /* Someone is requesting auth and we must respond. Just send back | |
2251 | * the trap with error code set accordingly. | |
2252 | */ | |
2253 | mlme->code = prism54_mac_accept(&priv->acl, | |
2254 | mlme->address) ? 0 : 1; | |
2255 | mgt_set_request(priv, oid, 0, mlme); | |
2256 | } | |
2257 | } | |
2258 | ||
2259 | static int | |
2260 | prism54_process_trap_helper(islpci_private *priv, enum oid_num_t oid, | |
2261 | char *data) | |
2262 | { | |
2263 | struct obj_mlme *mlme = (struct obj_mlme *) data; | |
2264 | struct obj_mlmeex *mlmeex = (struct obj_mlmeex *) data; | |
2265 | struct obj_mlmeex *confirm; | |
2266 | u8 wpa_ie[MAX_WPA_IE_LEN]; | |
2267 | int wpa_ie_len; | |
2268 | size_t len = 0; /* u16, better? */ | |
2269 | u8 *payload = NULL, *pos = NULL; | |
2270 | int ret; | |
0795af57 | 2271 | DECLARE_MAC_BUF(mac); |
1da177e4 LT |
2272 | |
2273 | /* I think all trapable objects are listed here. | |
2274 | * Some oids have a EX version. The difference is that they are emitted | |
2275 | * in DOT11_MLME_EXTENDED mode (set with DOT11_OID_MLMEAUTOLEVEL) | |
2276 | * with more info. | |
2277 | * The few events already defined by the wireless tools are not really | |
2278 | * suited. We use the more flexible custom event facility. | |
2279 | */ | |
2280 | ||
2281 | if (oid >= DOT11_OID_BEACON) { | |
2282 | len = mlmeex->size; | |
2283 | payload = pos = mlmeex->data; | |
2284 | } | |
2285 | ||
2286 | /* I fear prism54_process_bss_data won't work with big endian data */ | |
2287 | if ((oid == DOT11_OID_BEACON) || (oid == DOT11_OID_PROBE)) | |
2288 | prism54_process_bss_data(priv, oid, mlmeex->address, | |
2289 | payload, len); | |
2290 | ||
2291 | mgt_le_to_cpu(isl_oid[oid].flags & OID_FLAG_TYPE, (void *) mlme); | |
2292 | ||
2293 | switch (oid) { | |
2294 | ||
2295 | case GEN_OID_LINKSTATE: | |
2296 | link_changed(priv->ndev, (u32) *data); | |
2297 | break; | |
2298 | ||
2299 | case DOT11_OID_MICFAILURE: | |
2300 | send_simple_event(priv, "Mic failure"); | |
2301 | break; | |
2302 | ||
2303 | case DOT11_OID_DEAUTHENTICATE: | |
2304 | send_formatted_event(priv, "DeAuthenticate request", mlme, 0); | |
2305 | break; | |
2306 | ||
2307 | case DOT11_OID_AUTHENTICATE: | |
2308 | handle_request(priv, mlme, oid); | |
2309 | send_formatted_event(priv, "Authenticate request", mlme, 1); | |
2310 | break; | |
2311 | ||
2312 | case DOT11_OID_DISASSOCIATE: | |
2313 | send_formatted_event(priv, "Disassociate request", mlme, 0); | |
2314 | break; | |
2315 | ||
2316 | case DOT11_OID_ASSOCIATE: | |
2317 | handle_request(priv, mlme, oid); | |
2318 | send_formatted_event(priv, "Associate request", mlme, 1); | |
2319 | break; | |
2320 | ||
2321 | case DOT11_OID_REASSOCIATE: | |
2322 | handle_request(priv, mlme, oid); | |
2323 | send_formatted_event(priv, "ReAssociate request", mlme, 1); | |
2324 | break; | |
2325 | ||
2326 | case DOT11_OID_BEACON: | |
2327 | send_formatted_event(priv, | |
2328 | "Received a beacon from an unkown AP", | |
2329 | mlme, 0); | |
2330 | break; | |
2331 | ||
2332 | case DOT11_OID_PROBE: | |
2333 | /* we received a probe from a client. */ | |
2334 | send_formatted_event(priv, "Received a probe from client", mlme, | |
2335 | 0); | |
2336 | break; | |
2337 | ||
2338 | /* Note : "mlme" is actually a "struct obj_mlmeex *" here, but this | |
2339 | * is backward compatible layout-wise with "struct obj_mlme". | |
2340 | */ | |
2341 | ||
2342 | case DOT11_OID_DEAUTHENTICATEEX: | |
2343 | send_formatted_event(priv, "DeAuthenticate request", mlme, 0); | |
2344 | break; | |
2345 | ||
2346 | case DOT11_OID_AUTHENTICATEEX: | |
2347 | handle_request(priv, mlme, oid); | |
2348 | send_formatted_event(priv, "Authenticate request (ex)", mlme, 1); | |
2349 | ||
93b2dd12 | 2350 | if (priv->iw_mode != IW_MODE_MASTER |
1da177e4 LT |
2351 | && mlmeex->state != DOT11_STATE_AUTHING) |
2352 | break; | |
2353 | ||
2354 | confirm = kmalloc(sizeof(struct obj_mlmeex) + 6, GFP_ATOMIC); | |
2355 | ||
93b2dd12 | 2356 | if (!confirm) |
1da177e4 LT |
2357 | break; |
2358 | ||
2359 | memcpy(&confirm->address, mlmeex->address, ETH_ALEN); | |
0795af57 JP |
2360 | printk(KERN_DEBUG "Authenticate from: address:\t%s\n", |
2361 | print_mac(mac, mlmeex->address)); | |
1da177e4 LT |
2362 | confirm->id = -1; /* or mlmeex->id ? */ |
2363 | confirm->state = 0; /* not used */ | |
2364 | confirm->code = 0; | |
2365 | confirm->size = 6; | |
2366 | confirm->data[0] = 0x00; | |
2367 | confirm->data[1] = 0x00; | |
2368 | confirm->data[2] = 0x02; | |
2369 | confirm->data[3] = 0x00; | |
2370 | confirm->data[4] = 0x00; | |
2371 | confirm->data[5] = 0x00; | |
2372 | ||
2373 | ret = mgt_set_varlen(priv, DOT11_OID_ASSOCIATEEX, confirm, 6); | |
2374 | ||
2375 | kfree(confirm); | |
2376 | if (ret) | |
2377 | return ret; | |
2378 | break; | |
2379 | ||
2380 | case DOT11_OID_DISASSOCIATEEX: | |
2381 | send_formatted_event(priv, "Disassociate request (ex)", mlme, 0); | |
2382 | break; | |
2383 | ||
2384 | case DOT11_OID_ASSOCIATEEX: | |
2385 | handle_request(priv, mlme, oid); | |
2386 | send_formatted_event(priv, "Associate request (ex)", mlme, 1); | |
2387 | ||
93b2dd12 | 2388 | if (priv->iw_mode != IW_MODE_MASTER |
eab411f1 | 2389 | && mlmeex->state != DOT11_STATE_ASSOCING) |
1da177e4 | 2390 | break; |
93b2dd12 | 2391 | |
1da177e4 LT |
2392 | confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC); |
2393 | ||
2394 | if (!confirm) | |
2395 | break; | |
2396 | ||
2397 | memcpy(&confirm->address, mlmeex->address, ETH_ALEN); | |
2398 | ||
2399 | confirm->id = ((struct obj_mlmeex *)mlme)->id; | |
2400 | confirm->state = 0; /* not used */ | |
2401 | confirm->code = 0; | |
2402 | ||
eab411f1 | 2403 | wpa_ie_len = prism54_wpa_bss_ie_get(priv, mlmeex->address, wpa_ie); |
1da177e4 LT |
2404 | |
2405 | if (!wpa_ie_len) { | |
0795af57 JP |
2406 | printk(KERN_DEBUG "No WPA IE found from address:\t%s\n", |
2407 | print_mac(mac, mlmeex->address)); | |
1da177e4 LT |
2408 | kfree(confirm); |
2409 | break; | |
2410 | } | |
2411 | ||
2412 | confirm->size = wpa_ie_len; | |
2413 | memcpy(&confirm->data, wpa_ie, wpa_ie_len); | |
2414 | ||
2415 | mgt_set_varlen(priv, oid, confirm, wpa_ie_len); | |
2416 | ||
2417 | kfree(confirm); | |
93b2dd12 | 2418 | |
1da177e4 LT |
2419 | break; |
2420 | ||
2421 | case DOT11_OID_REASSOCIATEEX: | |
2422 | handle_request(priv, mlme, oid); | |
2423 | send_formatted_event(priv, "Reassociate request (ex)", mlme, 1); | |
2424 | ||
93b2dd12 | 2425 | if (priv->iw_mode != IW_MODE_MASTER |
1da177e4 LT |
2426 | && mlmeex->state != DOT11_STATE_ASSOCING) |
2427 | break; | |
2428 | ||
2429 | confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC); | |
2430 | ||
2431 | if (!confirm) | |
2432 | break; | |
2433 | ||
2434 | memcpy(&confirm->address, mlmeex->address, ETH_ALEN); | |
2435 | ||
2436 | confirm->id = mlmeex->id; | |
2437 | confirm->state = 0; /* not used */ | |
2438 | confirm->code = 0; | |
2439 | ||
eab411f1 | 2440 | wpa_ie_len = prism54_wpa_bss_ie_get(priv, mlmeex->address, wpa_ie); |
1da177e4 LT |
2441 | |
2442 | if (!wpa_ie_len) { | |
0795af57 JP |
2443 | printk(KERN_DEBUG "No WPA IE found from address:\t%s\n", |
2444 | print_mac(mac, mlmeex->address)); | |
1da177e4 LT |
2445 | kfree(confirm); |
2446 | break; | |
2447 | } | |
2448 | ||
93b2dd12 | 2449 | confirm->size = wpa_ie_len; |
1da177e4 LT |
2450 | memcpy(&confirm->data, wpa_ie, wpa_ie_len); |
2451 | ||
2452 | mgt_set_varlen(priv, oid, confirm, wpa_ie_len); | |
2453 | ||
2454 | kfree(confirm); | |
93b2dd12 | 2455 | |
1da177e4 LT |
2456 | break; |
2457 | ||
2458 | default: | |
2459 | return -EINVAL; | |
2460 | } | |
2461 | ||
2462 | return 0; | |
2463 | } | |
2464 | ||
2465 | /* | |
2466 | * Process a device trap. This is called via schedule_work(), outside of | |
2467 | * interrupt context, no locks held. | |
2468 | */ | |
2469 | void | |
c4028958 | 2470 | prism54_process_trap(struct work_struct *work) |
1da177e4 | 2471 | { |
c4028958 DH |
2472 | struct islpci_mgmtframe *frame = |
2473 | container_of(work, struct islpci_mgmtframe, ws); | |
1da177e4 LT |
2474 | struct net_device *ndev = frame->ndev; |
2475 | enum oid_num_t n = mgt_oidtonum(frame->header->oid); | |
2476 | ||
2477 | if (n != OID_NUM_LAST) | |
2478 | prism54_process_trap_helper(netdev_priv(ndev), n, frame->data); | |
2479 | islpci_mgt_release(frame); | |
2480 | } | |
2481 | ||
2482 | int | |
2483 | prism54_set_mac_address(struct net_device *ndev, void *addr) | |
2484 | { | |
2485 | islpci_private *priv = netdev_priv(ndev); | |
2486 | int ret; | |
2487 | ||
2488 | if (ndev->addr_len != 6) | |
2489 | return -EINVAL; | |
2490 | ret = mgt_set_request(priv, GEN_OID_MACADDRESS, 0, | |
2491 | &((struct sockaddr *) addr)->sa_data); | |
2492 | if (!ret) | |
2493 | memcpy(priv->ndev->dev_addr, | |
2494 | &((struct sockaddr *) addr)->sa_data, 6); | |
2495 | ||
2496 | return ret; | |
2497 | } | |
2498 | ||
2499 | /* Note: currently, use hostapd ioctl from the Host AP driver for WPA | |
2500 | * support. This is to be replaced with Linux wireless extensions once they | |
2501 | * get WPA support. */ | |
2502 | ||
2503 | /* Note II: please leave all this together as it will be easier to remove later, | |
2504 | * once wireless extensions add WPA support -mcgrof */ | |
2505 | ||
2506 | /* PRISM54_HOSTAPD ioctl() cmd: */ | |
2507 | enum { | |
2508 | PRISM2_SET_ENCRYPTION = 6, | |
2509 | PRISM2_HOSTAPD_SET_GENERIC_ELEMENT = 12, | |
2510 | PRISM2_HOSTAPD_MLME = 13, | |
2511 | PRISM2_HOSTAPD_SCAN_REQ = 14, | |
2512 | }; | |
2513 | ||
2514 | #define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12 | |
2515 | #define PRISM54_HOSTAPD SIOCIWFIRSTPRIV+25 | |
2516 | #define PRISM54_DROP_UNENCRYPTED SIOCIWFIRSTPRIV+26 | |
2517 | ||
2518 | #define PRISM2_HOSTAPD_MAX_BUF_SIZE 1024 | |
2519 | #define PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \ | |
2520 | ((int) (&((struct prism2_hostapd_param *) 0)->u.generic_elem.data)) | |
2521 | ||
93b2dd12 | 2522 | /* Maximum length for algorithm names (-1 for nul termination) |
1da177e4 LT |
2523 | * used in ioctl() */ |
2524 | #define HOSTAP_CRYPT_ALG_NAME_LEN 16 | |
93b2dd12 | 2525 | |
1da177e4 LT |
2526 | struct prism2_hostapd_param { |
2527 | u32 cmd; | |
2528 | u8 sta_addr[ETH_ALEN]; | |
2529 | union { | |
2530 | struct { | |
2531 | u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN]; | |
2532 | u32 flags; | |
2533 | u32 err; | |
2534 | u8 idx; | |
2535 | u8 seq[8]; /* sequence counter (set: RX, get: TX) */ | |
2536 | u16 key_len; | |
2537 | u8 key[0]; | |
2538 | } crypt; | |
2539 | struct { | |
2540 | u8 len; | |
2541 | u8 data[0]; | |
2542 | } generic_elem; | |
2543 | struct { | |
2544 | #define MLME_STA_DEAUTH 0 | |
2545 | #define MLME_STA_DISASSOC 1 | |
2546 | u16 cmd; | |
2547 | u16 reason_code; | |
2548 | } mlme; | |
2549 | struct { | |
2550 | u8 ssid_len; | |
2551 | u8 ssid[32]; | |
2552 | } scan_req; | |
2553 | } u; | |
2554 | }; | |
2555 | ||
2556 | ||
2557 | static int | |
2558 | prism2_ioctl_set_encryption(struct net_device *dev, | |
2559 | struct prism2_hostapd_param *param, | |
2560 | int param_len) | |
2561 | { | |
2562 | islpci_private *priv = netdev_priv(dev); | |
2563 | int rvalue = 0, force = 0; | |
2564 | int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0; | |
2565 | union oid_res_t r; | |
2566 | ||
2567 | /* with the new API, it's impossible to get a NULL pointer. | |
2568 | * New version of iwconfig set the IW_ENCODE_NOKEY flag | |
2569 | * when no key is given, but older versions don't. */ | |
2570 | ||
2571 | if (param->u.crypt.key_len > 0) { | |
2572 | /* we have a key to set */ | |
2573 | int index = param->u.crypt.idx; | |
2574 | int current_index; | |
2575 | struct obj_key key = { DOT11_PRIV_TKIP, 0, "" }; | |
2576 | ||
2577 | /* get the current key index */ | |
2578 | rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); | |
2579 | current_index = r.u; | |
2580 | /* Verify that the key is not marked as invalid */ | |
2581 | if (!(param->u.crypt.flags & IW_ENCODE_NOKEY)) { | |
2582 | key.length = param->u.crypt.key_len > sizeof (param->u.crypt.key) ? | |
2583 | sizeof (param->u.crypt.key) : param->u.crypt.key_len; | |
2584 | memcpy(key.key, param->u.crypt.key, key.length); | |
2585 | if (key.length == 32) | |
2586 | /* we want WPA-PSK */ | |
2587 | key.type = DOT11_PRIV_TKIP; | |
2588 | if ((index < 0) || (index > 3)) | |
2589 | /* no index provided use the current one */ | |
2590 | index = current_index; | |
2591 | ||
2592 | /* now send the key to the card */ | |
2593 | rvalue |= | |
2594 | mgt_set_request(priv, DOT11_OID_DEFKEYX, index, | |
2595 | &key); | |
2596 | } | |
2597 | /* | |
93b2dd12 | 2598 | * If a valid key is set, encryption should be enabled |
1da177e4 LT |
2599 | * (user may turn it off later). |
2600 | * This is also how "iwconfig ethX key on" works | |
2601 | */ | |
2602 | if ((index == current_index) && (key.length > 0)) | |
2603 | force = 1; | |
2604 | } else { | |
2605 | int index = (param->u.crypt.flags & IW_ENCODE_INDEX) - 1; | |
2606 | if ((index >= 0) && (index <= 3)) { | |
2607 | /* we want to set the key index */ | |
2608 | rvalue |= | |
2609 | mgt_set_request(priv, DOT11_OID_DEFKEYID, 0, | |
2610 | &index); | |
2611 | } else { | |
f59d9782 | 2612 | if (!(param->u.crypt.flags & IW_ENCODE_MODE)) { |
1da177e4 LT |
2613 | /* we cannot do anything. Complain. */ |
2614 | return -EINVAL; | |
2615 | } | |
2616 | } | |
2617 | } | |
2618 | /* now read the flags */ | |
2619 | if (param->u.crypt.flags & IW_ENCODE_DISABLED) { | |
93b2dd12 | 2620 | /* Encoding disabled, |
1da177e4 LT |
2621 | * authen = DOT11_AUTH_OS; |
2622 | * invoke = 0; | |
2623 | * exunencrypt = 0; */ | |
2624 | } | |
2625 | if (param->u.crypt.flags & IW_ENCODE_OPEN) | |
2626 | /* Encode but accept non-encoded packets. No auth */ | |
2627 | invoke = 1; | |
2628 | if ((param->u.crypt.flags & IW_ENCODE_RESTRICTED) || force) { | |
2629 | /* Refuse non-encoded packets. Auth */ | |
2630 | authen = DOT11_AUTH_BOTH; | |
2631 | invoke = 1; | |
2632 | exunencrypt = 1; | |
2633 | } | |
2634 | /* do the change if requested */ | |
2635 | if ((param->u.crypt.flags & IW_ENCODE_MODE) || force) { | |
2636 | rvalue |= | |
2637 | mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen); | |
2638 | rvalue |= | |
2639 | mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke); | |
2640 | rvalue |= | |
2641 | mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, | |
2642 | &exunencrypt); | |
2643 | } | |
2644 | return rvalue; | |
2645 | } | |
2646 | ||
2647 | static int | |
2648 | prism2_ioctl_set_generic_element(struct net_device *ndev, | |
2649 | struct prism2_hostapd_param *param, | |
2650 | int param_len) | |
2651 | { | |
2652 | islpci_private *priv = netdev_priv(ndev); | |
2653 | int max_len, len, alen, ret=0; | |
2654 | struct obj_attachment *attach; | |
2655 | ||
2656 | len = param->u.generic_elem.len; | |
2657 | max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN; | |
2658 | if (max_len < 0 || max_len < len) | |
2659 | return -EINVAL; | |
2660 | ||
2661 | alen = sizeof(*attach) + len; | |
b950e83b | 2662 | attach = kzalloc(alen, GFP_KERNEL); |
1da177e4 LT |
2663 | if (attach == NULL) |
2664 | return -ENOMEM; | |
2665 | ||
1da177e4 LT |
2666 | #define WLAN_FC_TYPE_MGMT 0 |
2667 | #define WLAN_FC_STYPE_ASSOC_REQ 0 | |
2668 | #define WLAN_FC_STYPE_REASSOC_REQ 2 | |
2669 | ||
2670 | /* Note: endianness is covered by mgt_set_varlen */ | |
2671 | ||
2672 | attach->type = (WLAN_FC_TYPE_MGMT << 2) | | |
2673 | (WLAN_FC_STYPE_ASSOC_REQ << 4); | |
2674 | attach->id = -1; | |
2675 | attach->size = len; | |
2676 | memcpy(attach->data, param->u.generic_elem.data, len); | |
2677 | ||
2678 | ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, len); | |
2679 | ||
2680 | if (ret == 0) { | |
2681 | attach->type = (WLAN_FC_TYPE_MGMT << 2) | | |
2682 | (WLAN_FC_STYPE_REASSOC_REQ << 4); | |
2683 | ||
2684 | ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, len); | |
2685 | ||
93b2dd12 | 2686 | if (ret == 0) |
1da177e4 LT |
2687 | printk(KERN_DEBUG "%s: WPA IE Attachment was set\n", |
2688 | ndev->name); | |
2689 | } | |
2690 | ||
2691 | kfree(attach); | |
2692 | return ret; | |
2693 | ||
2694 | } | |
2695 | ||
2696 | static int | |
2697 | prism2_ioctl_mlme(struct net_device *dev, struct prism2_hostapd_param *param) | |
2698 | { | |
2699 | return -EOPNOTSUPP; | |
2700 | } | |
2701 | ||
2702 | static int | |
2703 | prism2_ioctl_scan_req(struct net_device *ndev, | |
2704 | struct prism2_hostapd_param *param) | |
2705 | { | |
2706 | islpci_private *priv = netdev_priv(ndev); | |
2707 | int i, rvalue; | |
2708 | struct obj_bsslist *bsslist; | |
2709 | u32 noise = 0; | |
2710 | char *extra = ""; | |
2711 | char *current_ev = "foo"; | |
2712 | union oid_res_t r; | |
2713 | ||
2714 | if (islpci_get_state(priv) < PRV_STATE_INIT) { | |
2715 | /* device is not ready, fail gently */ | |
2716 | return 0; | |
2717 | } | |
2718 | ||
2719 | /* first get the noise value. We will use it to report the link quality */ | |
2720 | rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r); | |
2721 | noise = r.u; | |
2722 | ||
2723 | /* Ask the device for a list of known bss. We can report at most | |
2724 | * IW_MAX_AP=64 to the range struct. But the device won't repport anything | |
2725 | * if you change the value of IWMAX_BSS=24. | |
2726 | */ | |
2727 | rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r); | |
2728 | bsslist = r.ptr; | |
2729 | ||
2730 | /* ok now, scan the list and translate its info */ | |
2731 | for (i = 0; i < min(IW_MAX_AP, (int) bsslist->nr); i++) | |
2732 | current_ev = prism54_translate_bss(ndev, current_ev, | |
2733 | extra + IW_SCAN_MAX_DATA, | |
2734 | &(bsslist->bsslist[i]), | |
2735 | noise); | |
2736 | kfree(bsslist); | |
2737 | ||
2738 | return rvalue; | |
2739 | } | |
2740 | ||
2741 | static int | |
2742 | prism54_hostapd(struct net_device *ndev, struct iw_point *p) | |
2743 | { | |
2744 | struct prism2_hostapd_param *param; | |
2745 | int ret = 0; | |
2746 | u32 uwrq; | |
2747 | ||
2748 | printk(KERN_DEBUG "prism54_hostapd - len=%d\n", p->length); | |
2749 | if (p->length < sizeof(struct prism2_hostapd_param) || | |
2750 | p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer) | |
2751 | return -EINVAL; | |
2752 | ||
5cbded58 | 2753 | param = kmalloc(p->length, GFP_KERNEL); |
1da177e4 LT |
2754 | if (param == NULL) |
2755 | return -ENOMEM; | |
2756 | ||
2757 | if (copy_from_user(param, p->pointer, p->length)) { | |
2758 | kfree(param); | |
2759 | return -EFAULT; | |
2760 | } | |
2761 | ||
2762 | switch (param->cmd) { | |
2763 | case PRISM2_SET_ENCRYPTION: | |
2764 | printk(KERN_DEBUG "%s: Caught WPA supplicant set encryption request\n", | |
2765 | ndev->name); | |
2766 | ret = prism2_ioctl_set_encryption(ndev, param, p->length); | |
2767 | break; | |
2768 | case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT: | |
2769 | printk(KERN_DEBUG "%s: Caught WPA supplicant set WPA IE request\n", | |
2770 | ndev->name); | |
2771 | ret = prism2_ioctl_set_generic_element(ndev, param, | |
2772 | p->length); | |
2773 | break; | |
2774 | case PRISM2_HOSTAPD_MLME: | |
2775 | printk(KERN_DEBUG "%s: Caught WPA supplicant MLME request\n", | |
2776 | ndev->name); | |
2777 | ret = prism2_ioctl_mlme(ndev, param); | |
2778 | break; | |
2779 | case PRISM2_HOSTAPD_SCAN_REQ: | |
2780 | printk(KERN_DEBUG "%s: Caught WPA supplicant scan request\n", | |
2781 | ndev->name); | |
2782 | ret = prism2_ioctl_scan_req(ndev, param); | |
2783 | break; | |
2784 | case PRISM54_SET_WPA: | |
2785 | printk(KERN_DEBUG "%s: Caught WPA supplicant wpa init request\n", | |
2786 | ndev->name); | |
2787 | uwrq = 1; | |
2788 | ret = prism54_set_wpa(ndev, NULL, &uwrq, NULL); | |
2789 | break; | |
2790 | case PRISM54_DROP_UNENCRYPTED: | |
2791 | printk(KERN_DEBUG "%s: Caught WPA drop unencrypted request\n", | |
2792 | ndev->name); | |
2793 | #if 0 | |
2794 | uwrq = 0x01; | |
2795 | mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &uwrq); | |
2796 | down_write(&priv->mib_sem); | |
2797 | mgt_commit(priv); | |
2798 | up_write(&priv->mib_sem); | |
2799 | #endif | |
2800 | /* Not necessary, as set_wpa does it, should we just do it here though? */ | |
2801 | ret = 0; | |
2802 | break; | |
2803 | default: | |
2804 | printk(KERN_DEBUG "%s: Caught a WPA supplicant request that is not supported\n", | |
2805 | ndev->name); | |
2806 | ret = -EOPNOTSUPP; | |
2807 | break; | |
2808 | } | |
2809 | ||
2810 | if (ret == 0 && copy_to_user(p->pointer, param, p->length)) | |
2811 | ret = -EFAULT; | |
2812 | ||
2813 | kfree(param); | |
2814 | ||
2815 | return ret; | |
2816 | } | |
2817 | ||
2818 | static int | |
2819 | prism54_set_wpa(struct net_device *ndev, struct iw_request_info *info, | |
2820 | __u32 * uwrq, char *extra) | |
2821 | { | |
2822 | islpci_private *priv = netdev_priv(ndev); | |
2823 | u32 mlme, authen, dot1x, filter, wep; | |
2824 | ||
2825 | if (islpci_get_state(priv) < PRV_STATE_INIT) | |
2826 | return 0; | |
2827 | ||
2828 | wep = 1; /* For privacy invoked */ | |
2829 | filter = 1; /* Filter out all unencrypted frames */ | |
2830 | dot1x = 0x01; /* To enable eap filter */ | |
2831 | mlme = DOT11_MLME_EXTENDED; | |
2832 | authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */ | |
2833 | ||
2834 | down_write(&priv->mib_sem); | |
2835 | priv->wpa = *uwrq; | |
2836 | ||
2837 | switch (priv->wpa) { | |
2838 | default: | |
2839 | case 0: /* Clears/disables WPA and friends */ | |
2840 | wep = 0; | |
2841 | filter = 0; /* Do not filter un-encrypted data */ | |
2842 | dot1x = 0; | |
2843 | mlme = DOT11_MLME_AUTO; | |
2844 | printk("%s: Disabling WPA\n", ndev->name); | |
2845 | break; | |
93b2dd12 | 2846 | case 2: |
1da177e4 LT |
2847 | case 1: /* WPA */ |
2848 | printk("%s: Enabling WPA\n", ndev->name); | |
2849 | break; | |
2850 | } | |
2851 | up_write(&priv->mib_sem); | |
2852 | ||
2853 | mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen); | |
2854 | mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &wep); | |
2855 | mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &filter); | |
2856 | mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x); | |
2857 | mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlme); | |
2858 | ||
2859 | return 0; | |
2860 | } | |
2861 | ||
2862 | static int | |
2863 | prism54_get_wpa(struct net_device *ndev, struct iw_request_info *info, | |
2864 | __u32 * uwrq, char *extra) | |
2865 | { | |
2866 | islpci_private *priv = netdev_priv(ndev); | |
2867 | *uwrq = priv->wpa; | |
2868 | return 0; | |
2869 | } | |
2870 | ||
2871 | static int | |
2872 | prism54_set_prismhdr(struct net_device *ndev, struct iw_request_info *info, | |
2873 | __u32 * uwrq, char *extra) | |
2874 | { | |
2875 | islpci_private *priv = netdev_priv(ndev); | |
2876 | priv->monitor_type = | |
2877 | (*uwrq ? ARPHRD_IEEE80211_PRISM : ARPHRD_IEEE80211); | |
2878 | if (priv->iw_mode == IW_MODE_MONITOR) | |
2879 | priv->ndev->type = priv->monitor_type; | |
2880 | ||
2881 | return 0; | |
2882 | } | |
2883 | ||
2884 | static int | |
2885 | prism54_get_prismhdr(struct net_device *ndev, struct iw_request_info *info, | |
2886 | __u32 * uwrq, char *extra) | |
2887 | { | |
2888 | islpci_private *priv = netdev_priv(ndev); | |
2889 | *uwrq = (priv->monitor_type == ARPHRD_IEEE80211_PRISM); | |
2890 | return 0; | |
2891 | } | |
2892 | ||
2893 | static int | |
2894 | prism54_debug_oid(struct net_device *ndev, struct iw_request_info *info, | |
2895 | __u32 * uwrq, char *extra) | |
2896 | { | |
2897 | islpci_private *priv = netdev_priv(ndev); | |
2898 | ||
2899 | priv->priv_oid = *uwrq; | |
2900 | printk("%s: oid 0x%08X\n", ndev->name, *uwrq); | |
2901 | ||
2902 | return 0; | |
2903 | } | |
2904 | ||
2905 | static int | |
2906 | prism54_debug_get_oid(struct net_device *ndev, struct iw_request_info *info, | |
2907 | struct iw_point *data, char *extra) | |
2908 | { | |
2909 | islpci_private *priv = netdev_priv(ndev); | |
2910 | struct islpci_mgmtframe *response; | |
2911 | int ret = -EIO; | |
2912 | ||
2913 | printk("%s: get_oid 0x%08X\n", ndev->name, priv->priv_oid); | |
2914 | data->length = 0; | |
2915 | ||
2916 | if (islpci_get_state(priv) >= PRV_STATE_INIT) { | |
2917 | ret = | |
2918 | islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET, | |
2919 | priv->priv_oid, extra, 256, | |
2920 | &response); | |
2921 | printk("%s: ret: %i\n", ndev->name, ret); | |
2922 | if (ret || !response | |
2923 | || response->header->operation == PIMFOR_OP_ERROR) { | |
2924 | if (response) { | |
2925 | islpci_mgt_release(response); | |
2926 | } | |
2927 | printk("%s: EIO\n", ndev->name); | |
2928 | ret = -EIO; | |
2929 | } | |
2930 | if (!ret) { | |
2931 | data->length = response->header->length; | |
2932 | memcpy(extra, response->data, data->length); | |
2933 | islpci_mgt_release(response); | |
2934 | printk("%s: len: %i\n", ndev->name, data->length); | |
2935 | } | |
2936 | } | |
2937 | ||
2938 | return ret; | |
2939 | } | |
2940 | ||
2941 | static int | |
2942 | prism54_debug_set_oid(struct net_device *ndev, struct iw_request_info *info, | |
2943 | struct iw_point *data, char *extra) | |
2944 | { | |
2945 | islpci_private *priv = netdev_priv(ndev); | |
2946 | struct islpci_mgmtframe *response; | |
2947 | int ret = 0, response_op = PIMFOR_OP_ERROR; | |
2948 | ||
2949 | printk("%s: set_oid 0x%08X\tlen: %d\n", ndev->name, priv->priv_oid, | |
2950 | data->length); | |
2951 | ||
2952 | if (islpci_get_state(priv) >= PRV_STATE_INIT) { | |
2953 | ret = | |
2954 | islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET, | |
2955 | priv->priv_oid, extra, data->length, | |
2956 | &response); | |
2957 | printk("%s: ret: %i\n", ndev->name, ret); | |
2958 | if (ret || !response | |
2959 | || response->header->operation == PIMFOR_OP_ERROR) { | |
2960 | if (response) { | |
2961 | islpci_mgt_release(response); | |
2962 | } | |
2963 | printk("%s: EIO\n", ndev->name); | |
2964 | ret = -EIO; | |
2965 | } | |
2966 | if (!ret) { | |
2967 | response_op = response->header->operation; | |
2968 | printk("%s: response_op: %i\n", ndev->name, | |
2969 | response_op); | |
2970 | islpci_mgt_release(response); | |
2971 | } | |
2972 | } | |
2973 | ||
2974 | return (ret ? ret : -EINPROGRESS); | |
2975 | } | |
2976 | ||
2977 | static int | |
2978 | prism54_set_spy(struct net_device *ndev, | |
2979 | struct iw_request_info *info, | |
2980 | union iwreq_data *uwrq, char *extra) | |
2981 | { | |
2982 | islpci_private *priv = netdev_priv(ndev); | |
2983 | u32 u, oid = OID_INL_CONFIG; | |
2984 | ||
2985 | down_write(&priv->mib_sem); | |
2986 | mgt_get(priv, OID_INL_CONFIG, &u); | |
2987 | ||
2988 | if ((uwrq->data.length == 0) && (priv->spy_data.spy_number > 0)) | |
2989 | /* disable spy */ | |
2990 | u &= ~INL_CONFIG_RXANNEX; | |
2991 | else if ((uwrq->data.length > 0) && (priv->spy_data.spy_number == 0)) | |
2992 | /* enable spy */ | |
2993 | u |= INL_CONFIG_RXANNEX; | |
2994 | ||
2995 | mgt_set(priv, OID_INL_CONFIG, &u); | |
2996 | mgt_commit_list(priv, &oid, 1); | |
2997 | up_write(&priv->mib_sem); | |
2998 | ||
2999 | return iw_handler_set_spy(ndev, info, uwrq, extra); | |
3000 | } | |
3001 | ||
3002 | static const iw_handler prism54_handler[] = { | |
3003 | (iw_handler) prism54_commit, /* SIOCSIWCOMMIT */ | |
3004 | (iw_handler) prism54_get_name, /* SIOCGIWNAME */ | |
3005 | (iw_handler) NULL, /* SIOCSIWNWID */ | |
3006 | (iw_handler) NULL, /* SIOCGIWNWID */ | |
3007 | (iw_handler) prism54_set_freq, /* SIOCSIWFREQ */ | |
3008 | (iw_handler) prism54_get_freq, /* SIOCGIWFREQ */ | |
3009 | (iw_handler) prism54_set_mode, /* SIOCSIWMODE */ | |
3010 | (iw_handler) prism54_get_mode, /* SIOCGIWMODE */ | |
3011 | (iw_handler) prism54_set_sens, /* SIOCSIWSENS */ | |
3012 | (iw_handler) prism54_get_sens, /* SIOCGIWSENS */ | |
3013 | (iw_handler) NULL, /* SIOCSIWRANGE */ | |
3014 | (iw_handler) prism54_get_range, /* SIOCGIWRANGE */ | |
3015 | (iw_handler) NULL, /* SIOCSIWPRIV */ | |
3016 | (iw_handler) NULL, /* SIOCGIWPRIV */ | |
3017 | (iw_handler) NULL, /* SIOCSIWSTATS */ | |
3018 | (iw_handler) NULL, /* SIOCGIWSTATS */ | |
3019 | prism54_set_spy, /* SIOCSIWSPY */ | |
3020 | iw_handler_get_spy, /* SIOCGIWSPY */ | |
3021 | iw_handler_set_thrspy, /* SIOCSIWTHRSPY */ | |
3022 | iw_handler_get_thrspy, /* SIOCGIWTHRSPY */ | |
3023 | (iw_handler) prism54_set_wap, /* SIOCSIWAP */ | |
3024 | (iw_handler) prism54_get_wap, /* SIOCGIWAP */ | |
3025 | (iw_handler) NULL, /* -- hole -- */ | |
1591275c | 3026 | (iw_handler) NULL, /* SIOCGIWAPLIST deprecated */ |
1da177e4 LT |
3027 | (iw_handler) prism54_set_scan, /* SIOCSIWSCAN */ |
3028 | (iw_handler) prism54_get_scan, /* SIOCGIWSCAN */ | |
3029 | (iw_handler) prism54_set_essid, /* SIOCSIWESSID */ | |
3030 | (iw_handler) prism54_get_essid, /* SIOCGIWESSID */ | |
3031 | (iw_handler) prism54_set_nick, /* SIOCSIWNICKN */ | |
3032 | (iw_handler) prism54_get_nick, /* SIOCGIWNICKN */ | |
3033 | (iw_handler) NULL, /* -- hole -- */ | |
3034 | (iw_handler) NULL, /* -- hole -- */ | |
3035 | (iw_handler) prism54_set_rate, /* SIOCSIWRATE */ | |
3036 | (iw_handler) prism54_get_rate, /* SIOCGIWRATE */ | |
3037 | (iw_handler) prism54_set_rts, /* SIOCSIWRTS */ | |
3038 | (iw_handler) prism54_get_rts, /* SIOCGIWRTS */ | |
3039 | (iw_handler) prism54_set_frag, /* SIOCSIWFRAG */ | |
3040 | (iw_handler) prism54_get_frag, /* SIOCGIWFRAG */ | |
3041 | (iw_handler) prism54_set_txpower, /* SIOCSIWTXPOW */ | |
3042 | (iw_handler) prism54_get_txpower, /* SIOCGIWTXPOW */ | |
3043 | (iw_handler) prism54_set_retry, /* SIOCSIWRETRY */ | |
3044 | (iw_handler) prism54_get_retry, /* SIOCGIWRETRY */ | |
3045 | (iw_handler) prism54_set_encode, /* SIOCSIWENCODE */ | |
3046 | (iw_handler) prism54_get_encode, /* SIOCGIWENCODE */ | |
3047 | (iw_handler) NULL, /* SIOCSIWPOWER */ | |
3048 | (iw_handler) NULL, /* SIOCGIWPOWER */ | |
eab411f1 DW |
3049 | NULL, /* -- hole -- */ |
3050 | NULL, /* -- hole -- */ | |
3051 | (iw_handler) prism54_set_genie, /* SIOCSIWGENIE */ | |
3052 | (iw_handler) prism54_get_genie, /* SIOCGIWGENIE */ | |
3053 | (iw_handler) prism54_set_auth, /* SIOCSIWAUTH */ | |
3054 | (iw_handler) prism54_get_auth, /* SIOCGIWAUTH */ | |
3055 | (iw_handler) prism54_set_encodeext, /* SIOCSIWENCODEEXT */ | |
3056 | (iw_handler) prism54_get_encodeext, /* SIOCGIWENCODEEXT */ | |
3057 | NULL, /* SIOCSIWPMKSA */ | |
1da177e4 LT |
3058 | }; |
3059 | ||
3060 | /* The low order bit identify a SET (0) or a GET (1) ioctl. */ | |
3061 | ||
3062 | #define PRISM54_RESET SIOCIWFIRSTPRIV | |
3063 | #define PRISM54_GET_POLICY SIOCIWFIRSTPRIV+1 | |
3064 | #define PRISM54_SET_POLICY SIOCIWFIRSTPRIV+2 | |
3065 | #define PRISM54_GET_MAC SIOCIWFIRSTPRIV+3 | |
3066 | #define PRISM54_ADD_MAC SIOCIWFIRSTPRIV+4 | |
3067 | ||
3068 | #define PRISM54_DEL_MAC SIOCIWFIRSTPRIV+6 | |
3069 | ||
3070 | #define PRISM54_KICK_MAC SIOCIWFIRSTPRIV+8 | |
3071 | ||
3072 | #define PRISM54_KICK_ALL SIOCIWFIRSTPRIV+10 | |
3073 | ||
3074 | #define PRISM54_GET_WPA SIOCIWFIRSTPRIV+11 | |
3075 | #define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12 | |
3076 | ||
3077 | #define PRISM54_DBG_OID SIOCIWFIRSTPRIV+14 | |
3078 | #define PRISM54_DBG_GET_OID SIOCIWFIRSTPRIV+15 | |
3079 | #define PRISM54_DBG_SET_OID SIOCIWFIRSTPRIV+16 | |
3080 | ||
3081 | #define PRISM54_GET_OID SIOCIWFIRSTPRIV+17 | |
3082 | #define PRISM54_SET_OID_U32 SIOCIWFIRSTPRIV+18 | |
3083 | #define PRISM54_SET_OID_STR SIOCIWFIRSTPRIV+20 | |
3084 | #define PRISM54_SET_OID_ADDR SIOCIWFIRSTPRIV+22 | |
3085 | ||
3086 | #define PRISM54_GET_PRISMHDR SIOCIWFIRSTPRIV+23 | |
3087 | #define PRISM54_SET_PRISMHDR SIOCIWFIRSTPRIV+24 | |
3088 | ||
3089 | #define IWPRIV_SET_U32(n,x) { n, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x } | |
3090 | #define IWPRIV_SET_SSID(n,x) { n, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x } | |
3091 | #define IWPRIV_SET_ADDR(n,x) { n, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x } | |
3092 | #define IWPRIV_GET(n,x) { n, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, "g_"x } | |
3093 | ||
3094 | #define IWPRIV_U32(n,x) IWPRIV_SET_U32(n,x), IWPRIV_GET(n,x) | |
3095 | #define IWPRIV_SSID(n,x) IWPRIV_SET_SSID(n,x), IWPRIV_GET(n,x) | |
3096 | #define IWPRIV_ADDR(n,x) IWPRIV_SET_ADDR(n,x), IWPRIV_GET(n,x) | |
3097 | ||
3098 | /* Note : limited to 128 private ioctls (wireless tools 26) */ | |
3099 | ||
3100 | static const struct iw_priv_args prism54_private_args[] = { | |
3101 | /*{ cmd, set_args, get_args, name } */ | |
3102 | {PRISM54_RESET, 0, 0, "reset"}, | |
3103 | {PRISM54_GET_PRISMHDR, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3104 | "get_prismhdr"}, | |
3105 | {PRISM54_SET_PRISMHDR, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, | |
3106 | "set_prismhdr"}, | |
3107 | {PRISM54_GET_POLICY, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3108 | "getPolicy"}, | |
3109 | {PRISM54_SET_POLICY, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, | |
3110 | "setPolicy"}, | |
3111 | {PRISM54_GET_MAC, 0, IW_PRIV_TYPE_ADDR | 64, "getMac"}, | |
3112 | {PRISM54_ADD_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, | |
3113 | "addMac"}, | |
3114 | {PRISM54_DEL_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, | |
3115 | "delMac"}, | |
3116 | {PRISM54_KICK_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, | |
3117 | "kickMac"}, | |
3118 | {PRISM54_KICK_ALL, 0, 0, "kickAll"}, | |
3119 | {PRISM54_GET_WPA, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
3120 | "get_wpa"}, | |
3121 | {PRISM54_SET_WPA, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, | |
3122 | "set_wpa"}, | |
3123 | {PRISM54_DBG_OID, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, | |
3124 | "dbg_oid"}, | |
3125 | {PRISM54_DBG_GET_OID, 0, IW_PRIV_TYPE_BYTE | 256, "dbg_get_oid"}, | |
3126 | {PRISM54_DBG_SET_OID, IW_PRIV_TYPE_BYTE | 256, 0, "dbg_set_oid"}, | |
3127 | /* --- sub-ioctls handlers --- */ | |
3128 | {PRISM54_GET_OID, | |
3129 | 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, ""}, | |
3130 | {PRISM54_SET_OID_U32, | |
3131 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, ""}, | |
3132 | {PRISM54_SET_OID_STR, | |
3133 | IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, ""}, | |
3134 | {PRISM54_SET_OID_ADDR, | |
3135 | IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, ""}, | |
3136 | /* --- sub-ioctls definitions --- */ | |
3137 | IWPRIV_ADDR(GEN_OID_MACADDRESS, "addr"), | |
3138 | IWPRIV_GET(GEN_OID_LINKSTATE, "linkstate"), | |
3139 | IWPRIV_U32(DOT11_OID_BSSTYPE, "bsstype"), | |
3140 | IWPRIV_ADDR(DOT11_OID_BSSID, "bssid"), | |
3141 | IWPRIV_U32(DOT11_OID_STATE, "state"), | |
3142 | IWPRIV_U32(DOT11_OID_AID, "aid"), | |
3143 | ||
3144 | IWPRIV_SSID(DOT11_OID_SSIDOVERRIDE, "ssidoverride"), | |
3145 | ||
3146 | IWPRIV_U32(DOT11_OID_MEDIUMLIMIT, "medlimit"), | |
3147 | IWPRIV_U32(DOT11_OID_BEACONPERIOD, "beacon"), | |
3148 | IWPRIV_U32(DOT11_OID_DTIMPERIOD, "dtimperiod"), | |
3149 | ||
3150 | IWPRIV_U32(DOT11_OID_AUTHENABLE, "authenable"), | |
3151 | IWPRIV_U32(DOT11_OID_PRIVACYINVOKED, "privinvok"), | |
3152 | IWPRIV_U32(DOT11_OID_EXUNENCRYPTED, "exunencrypt"), | |
3153 | ||
3154 | IWPRIV_U32(DOT11_OID_REKEYTHRESHOLD, "rekeythresh"), | |
3155 | ||
3156 | IWPRIV_U32(DOT11_OID_MAXTXLIFETIME, "maxtxlife"), | |
3157 | IWPRIV_U32(DOT11_OID_MAXRXLIFETIME, "maxrxlife"), | |
3158 | IWPRIV_U32(DOT11_OID_ALOFT_FIXEDRATE, "fixedrate"), | |
3159 | IWPRIV_U32(DOT11_OID_MAXFRAMEBURST, "frameburst"), | |
3160 | IWPRIV_U32(DOT11_OID_PSM, "psm"), | |
3161 | ||
3162 | IWPRIV_U32(DOT11_OID_BRIDGELOCAL, "bridge"), | |
3163 | IWPRIV_U32(DOT11_OID_CLIENTS, "clients"), | |
3164 | IWPRIV_U32(DOT11_OID_CLIENTSASSOCIATED, "clientassoc"), | |
3165 | IWPRIV_U32(DOT11_OID_DOT1XENABLE, "dot1xenable"), | |
3166 | IWPRIV_U32(DOT11_OID_ANTENNARX, "rxant"), | |
3167 | IWPRIV_U32(DOT11_OID_ANTENNATX, "txant"), | |
3168 | IWPRIV_U32(DOT11_OID_ANTENNADIVERSITY, "antdivers"), | |
3169 | IWPRIV_U32(DOT11_OID_EDTHRESHOLD, "edthresh"), | |
3170 | IWPRIV_U32(DOT11_OID_PREAMBLESETTINGS, "preamble"), | |
3171 | IWPRIV_GET(DOT11_OID_RATES, "rates"), | |
3172 | IWPRIV_U32(DOT11_OID_OUTPUTPOWER, ".11outpower"), | |
3173 | IWPRIV_GET(DOT11_OID_SUPPORTEDRATES, "supprates"), | |
3174 | IWPRIV_GET(DOT11_OID_SUPPORTEDFREQUENCIES, "suppfreq"), | |
3175 | ||
3176 | IWPRIV_U32(DOT11_OID_NOISEFLOOR, "noisefloor"), | |
3177 | IWPRIV_GET(DOT11_OID_FREQUENCYACTIVITY, "freqactivity"), | |
3178 | IWPRIV_U32(DOT11_OID_NONERPPROTECTION, "nonerpprotec"), | |
3179 | IWPRIV_U32(DOT11_OID_PROFILES, "profile"), | |
3180 | IWPRIV_GET(DOT11_OID_EXTENDEDRATES, "extrates"), | |
3181 | IWPRIV_U32(DOT11_OID_MLMEAUTOLEVEL, "mlmelevel"), | |
3182 | ||
3183 | IWPRIV_GET(DOT11_OID_BSSS, "bsss"), | |
3184 | IWPRIV_GET(DOT11_OID_BSSLIST, "bsslist"), | |
3185 | IWPRIV_U32(OID_INL_MODE, "mode"), | |
3186 | IWPRIV_U32(OID_INL_CONFIG, "config"), | |
3187 | IWPRIV_U32(OID_INL_DOT11D_CONFORMANCE, ".11dconform"), | |
3188 | IWPRIV_GET(OID_INL_PHYCAPABILITIES, "phycapa"), | |
3189 | IWPRIV_U32(OID_INL_OUTPUTPOWER, "outpower"), | |
3190 | }; | |
3191 | ||
3192 | static const iw_handler prism54_private_handler[] = { | |
3193 | (iw_handler) prism54_reset, | |
3194 | (iw_handler) prism54_get_policy, | |
3195 | (iw_handler) prism54_set_policy, | |
3196 | (iw_handler) prism54_get_mac, | |
3197 | (iw_handler) prism54_add_mac, | |
3198 | (iw_handler) NULL, | |
3199 | (iw_handler) prism54_del_mac, | |
3200 | (iw_handler) NULL, | |
3201 | (iw_handler) prism54_kick_mac, | |
3202 | (iw_handler) NULL, | |
3203 | (iw_handler) prism54_kick_all, | |
3204 | (iw_handler) prism54_get_wpa, | |
3205 | (iw_handler) prism54_set_wpa, | |
3206 | (iw_handler) NULL, | |
3207 | (iw_handler) prism54_debug_oid, | |
3208 | (iw_handler) prism54_debug_get_oid, | |
3209 | (iw_handler) prism54_debug_set_oid, | |
3210 | (iw_handler) prism54_get_oid, | |
3211 | (iw_handler) prism54_set_u32, | |
3212 | (iw_handler) NULL, | |
3213 | (iw_handler) prism54_set_raw, | |
3214 | (iw_handler) NULL, | |
3215 | (iw_handler) prism54_set_raw, | |
3216 | (iw_handler) prism54_get_prismhdr, | |
3217 | (iw_handler) prism54_set_prismhdr, | |
3218 | }; | |
3219 | ||
3220 | const struct iw_handler_def prism54_handler_def = { | |
ff8ac609 DC |
3221 | .num_standard = ARRAY_SIZE(prism54_handler), |
3222 | .num_private = ARRAY_SIZE(prism54_private_handler), | |
3223 | .num_private_args = ARRAY_SIZE(prism54_private_args), | |
1da177e4 LT |
3224 | .standard = (iw_handler *) prism54_handler, |
3225 | .private = (iw_handler *) prism54_private_handler, | |
3226 | .private_args = (struct iw_priv_args *) prism54_private_args, | |
61bd4963 | 3227 | .get_wireless_stats = prism54_get_wireless_stats, |
1da177e4 LT |
3228 | }; |
3229 | ||
3230 | /* For wpa_supplicant */ | |
3231 | ||
3232 | int | |
3233 | prism54_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) | |
3234 | { | |
3235 | struct iwreq *wrq = (struct iwreq *) rq; | |
3236 | int ret = -1; | |
3237 | switch (cmd) { | |
3238 | case PRISM54_HOSTAPD: | |
3239 | if (!capable(CAP_NET_ADMIN)) | |
3240 | return -EPERM; | |
3241 | ret = prism54_hostapd(ndev, &wrq->u.data); | |
3242 | return ret; | |
3243 | } | |
3244 | return -EOPNOTSUPP; | |
3245 | } |