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