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