Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*====================================================================== |
| 2 | |
| 3 | Aironet driver for 4500 and 4800 series cards |
| 4 | |
| 5 | This code is released under both the GPL version 2 and BSD licenses. |
| 6 | Either license may be used. The respective licenses are found at |
| 7 | the end of this file. |
| 8 | |
| 9 | This code was developed by Benjamin Reed <breed@users.sourceforge.net> |
| 10 | including portions of which come from the Aironet PC4500 |
| 11 | Developer's Reference Manual and used with permission. Copyright |
| 12 | (C) 1999 Benjamin Reed. All Rights Reserved. Permission to use |
| 13 | code in the Developer's manual was granted for this driver by |
| 14 | Aironet. Major code contributions were received from Javier Achirica |
| 15 | <achirica@users.sourceforge.net> and Jean Tourrilhes <jt@hpl.hp.com>. |
| 16 | Code was also integrated from the Cisco Aironet driver for Linux. |
| 17 | Support for MPI350 cards was added by Fabrice Bellet |
| 18 | <fabrice@bellet.info>. |
| 19 | |
| 20 | ======================================================================*/ |
| 21 | |
| 22 | #include <linux/config.h> |
| 23 | #include <linux/init.h> |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/proc_fs.h> |
| 28 | #include <linux/smp_lock.h> |
| 29 | |
| 30 | #include <linux/sched.h> |
| 31 | #include <linux/ptrace.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/timer.h> |
| 35 | #include <linux/interrupt.h> |
| 36 | #include <linux/in.h> |
| 37 | #include <linux/bitops.h> |
| 38 | #include <asm/io.h> |
| 39 | #include <asm/system.h> |
| 40 | |
| 41 | #include <linux/netdevice.h> |
| 42 | #include <linux/etherdevice.h> |
| 43 | #include <linux/skbuff.h> |
| 44 | #include <linux/if_arp.h> |
| 45 | #include <linux/ioport.h> |
| 46 | #include <linux/pci.h> |
| 47 | #include <asm/uaccess.h> |
| 48 | |
| 49 | #ifdef CONFIG_PCI |
| 50 | static struct pci_device_id card_ids[] = { |
| 51 | { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, }, |
| 52 | { 0x14b9, 0x4500, PCI_ANY_ID, PCI_ANY_ID }, |
| 53 | { 0x14b9, 0x4800, PCI_ANY_ID, PCI_ANY_ID, }, |
| 54 | { 0x14b9, 0x0340, PCI_ANY_ID, PCI_ANY_ID, }, |
| 55 | { 0x14b9, 0x0350, PCI_ANY_ID, PCI_ANY_ID, }, |
| 56 | { 0x14b9, 0x5000, PCI_ANY_ID, PCI_ANY_ID, }, |
| 57 | { 0x14b9, 0xa504, PCI_ANY_ID, PCI_ANY_ID, }, |
| 58 | { 0, } |
| 59 | }; |
| 60 | MODULE_DEVICE_TABLE(pci, card_ids); |
| 61 | |
| 62 | static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *); |
| 63 | static void airo_pci_remove(struct pci_dev *); |
Pavel Machek | 05adc3b | 2005-04-16 15:25:25 -0700 | [diff] [blame] | 64 | static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static int airo_pci_resume(struct pci_dev *pdev); |
| 66 | |
| 67 | static struct pci_driver airo_driver = { |
| 68 | .name = "airo", |
| 69 | .id_table = card_ids, |
| 70 | .probe = airo_pci_probe, |
| 71 | .remove = __devexit_p(airo_pci_remove), |
| 72 | .suspend = airo_pci_suspend, |
| 73 | .resume = airo_pci_resume, |
| 74 | }; |
| 75 | #endif /* CONFIG_PCI */ |
| 76 | |
| 77 | /* Include Wireless Extension definition and check version - Jean II */ |
| 78 | #include <linux/wireless.h> |
| 79 | #define WIRELESS_SPY // enable iwspy support |
| 80 | #include <net/iw_handler.h> // New driver API |
| 81 | |
| 82 | #define CISCO_EXT // enable Cisco extensions |
| 83 | #ifdef CISCO_EXT |
| 84 | #include <linux/delay.h> |
| 85 | #endif |
| 86 | |
| 87 | /* Support Cisco MIC feature */ |
| 88 | #define MICSUPPORT |
| 89 | |
| 90 | #if defined(MICSUPPORT) && !defined(CONFIG_CRYPTO) |
| 91 | #warning MIC support requires Crypto API |
| 92 | #undef MICSUPPORT |
| 93 | #endif |
| 94 | |
| 95 | /* Hack to do some power saving */ |
| 96 | #define POWER_ON_DOWN |
| 97 | |
| 98 | /* As you can see this list is HUGH! |
| 99 | I really don't know what a lot of these counts are about, but they |
| 100 | are all here for completeness. If the IGNLABEL macro is put in |
| 101 | infront of the label, that statistic will not be included in the list |
| 102 | of statistics in the /proc filesystem */ |
| 103 | |
| 104 | #define IGNLABEL(comment) NULL |
| 105 | static char *statsLabels[] = { |
| 106 | "RxOverrun", |
| 107 | IGNLABEL("RxPlcpCrcErr"), |
| 108 | IGNLABEL("RxPlcpFormatErr"), |
| 109 | IGNLABEL("RxPlcpLengthErr"), |
| 110 | "RxMacCrcErr", |
| 111 | "RxMacCrcOk", |
| 112 | "RxWepErr", |
| 113 | "RxWepOk", |
| 114 | "RetryLong", |
| 115 | "RetryShort", |
| 116 | "MaxRetries", |
| 117 | "NoAck", |
| 118 | "NoCts", |
| 119 | "RxAck", |
| 120 | "RxCts", |
| 121 | "TxAck", |
| 122 | "TxRts", |
| 123 | "TxCts", |
| 124 | "TxMc", |
| 125 | "TxBc", |
| 126 | "TxUcFrags", |
| 127 | "TxUcPackets", |
| 128 | "TxBeacon", |
| 129 | "RxBeacon", |
| 130 | "TxSinColl", |
| 131 | "TxMulColl", |
| 132 | "DefersNo", |
| 133 | "DefersProt", |
| 134 | "DefersEngy", |
| 135 | "DupFram", |
| 136 | "RxFragDisc", |
| 137 | "TxAged", |
| 138 | "RxAged", |
| 139 | "LostSync-MaxRetry", |
| 140 | "LostSync-MissedBeacons", |
| 141 | "LostSync-ArlExceeded", |
| 142 | "LostSync-Deauth", |
| 143 | "LostSync-Disassoced", |
| 144 | "LostSync-TsfTiming", |
| 145 | "HostTxMc", |
| 146 | "HostTxBc", |
| 147 | "HostTxUc", |
| 148 | "HostTxFail", |
| 149 | "HostRxMc", |
| 150 | "HostRxBc", |
| 151 | "HostRxUc", |
| 152 | "HostRxDiscard", |
| 153 | IGNLABEL("HmacTxMc"), |
| 154 | IGNLABEL("HmacTxBc"), |
| 155 | IGNLABEL("HmacTxUc"), |
| 156 | IGNLABEL("HmacTxFail"), |
| 157 | IGNLABEL("HmacRxMc"), |
| 158 | IGNLABEL("HmacRxBc"), |
| 159 | IGNLABEL("HmacRxUc"), |
| 160 | IGNLABEL("HmacRxDiscard"), |
| 161 | IGNLABEL("HmacRxAccepted"), |
| 162 | "SsidMismatch", |
| 163 | "ApMismatch", |
| 164 | "RatesMismatch", |
| 165 | "AuthReject", |
| 166 | "AuthTimeout", |
| 167 | "AssocReject", |
| 168 | "AssocTimeout", |
| 169 | IGNLABEL("ReasonOutsideTable"), |
| 170 | IGNLABEL("ReasonStatus1"), |
| 171 | IGNLABEL("ReasonStatus2"), |
| 172 | IGNLABEL("ReasonStatus3"), |
| 173 | IGNLABEL("ReasonStatus4"), |
| 174 | IGNLABEL("ReasonStatus5"), |
| 175 | IGNLABEL("ReasonStatus6"), |
| 176 | IGNLABEL("ReasonStatus7"), |
| 177 | IGNLABEL("ReasonStatus8"), |
| 178 | IGNLABEL("ReasonStatus9"), |
| 179 | IGNLABEL("ReasonStatus10"), |
| 180 | IGNLABEL("ReasonStatus11"), |
| 181 | IGNLABEL("ReasonStatus12"), |
| 182 | IGNLABEL("ReasonStatus13"), |
| 183 | IGNLABEL("ReasonStatus14"), |
| 184 | IGNLABEL("ReasonStatus15"), |
| 185 | IGNLABEL("ReasonStatus16"), |
| 186 | IGNLABEL("ReasonStatus17"), |
| 187 | IGNLABEL("ReasonStatus18"), |
| 188 | IGNLABEL("ReasonStatus19"), |
| 189 | "RxMan", |
| 190 | "TxMan", |
| 191 | "RxRefresh", |
| 192 | "TxRefresh", |
| 193 | "RxPoll", |
| 194 | "TxPoll", |
| 195 | "HostRetries", |
| 196 | "LostSync-HostReq", |
| 197 | "HostTxBytes", |
| 198 | "HostRxBytes", |
| 199 | "ElapsedUsec", |
| 200 | "ElapsedSec", |
| 201 | "LostSyncBetterAP", |
| 202 | "PrivacyMismatch", |
| 203 | "Jammed", |
| 204 | "DiscRxNotWepped", |
| 205 | "PhyEleMismatch", |
| 206 | (char*)-1 }; |
| 207 | #ifndef RUN_AT |
| 208 | #define RUN_AT(x) (jiffies+(x)) |
| 209 | #endif |
| 210 | |
| 211 | |
| 212 | /* These variables are for insmod, since it seems that the rates |
| 213 | can only be set in setup_card. Rates should be a comma separated |
| 214 | (no spaces) list of rates (up to 8). */ |
| 215 | |
| 216 | static int rates[8]; |
| 217 | static int basic_rate; |
| 218 | static char *ssids[3]; |
| 219 | |
| 220 | static int io[4]; |
| 221 | static int irq[4]; |
| 222 | |
| 223 | static |
| 224 | int maxencrypt /* = 0 */; /* The highest rate that the card can encrypt at. |
| 225 | 0 means no limit. For old cards this was 4 */ |
| 226 | |
| 227 | static int auto_wep /* = 0 */; /* If set, it tries to figure out the wep mode */ |
| 228 | static int aux_bap /* = 0 */; /* Checks to see if the aux ports are needed to read |
| 229 | the bap, needed on some older cards and buses. */ |
| 230 | static int adhoc; |
| 231 | |
| 232 | static int probe = 1; |
| 233 | |
| 234 | static int proc_uid /* = 0 */; |
| 235 | |
| 236 | static int proc_gid /* = 0 */; |
| 237 | |
| 238 | static int airo_perm = 0555; |
| 239 | |
| 240 | static int proc_perm = 0644; |
| 241 | |
| 242 | MODULE_AUTHOR("Benjamin Reed"); |
| 243 | MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \ |
| 244 | cards. Direct support for ISA/PCI/MPI cards and support \ |
| 245 | for PCMCIA when used with airo_cs."); |
| 246 | MODULE_LICENSE("Dual BSD/GPL"); |
| 247 | MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340/350"); |
| 248 | module_param_array(io, int, NULL, 0); |
| 249 | module_param_array(irq, int, NULL, 0); |
| 250 | module_param(basic_rate, int, 0); |
| 251 | module_param_array(rates, int, NULL, 0); |
| 252 | module_param_array(ssids, charp, NULL, 0); |
| 253 | module_param(auto_wep, int, 0); |
| 254 | MODULE_PARM_DESC(auto_wep, "If non-zero, the driver will keep looping through \ |
| 255 | the authentication options until an association is made. The value of \ |
| 256 | auto_wep is number of the wep keys to check. A value of 2 will try using \ |
| 257 | the key at index 0 and index 1."); |
| 258 | module_param(aux_bap, int, 0); |
| 259 | MODULE_PARM_DESC(aux_bap, "If non-zero, the driver will switch into a mode \ |
| 260 | than seems to work better for older cards with some older buses. Before \ |
| 261 | switching it checks that the switch is needed."); |
| 262 | module_param(maxencrypt, int, 0); |
| 263 | MODULE_PARM_DESC(maxencrypt, "The maximum speed that the card can do \ |
| 264 | encryption. Units are in 512kbs. Zero (default) means there is no limit. \ |
| 265 | Older cards used to be limited to 2mbs (4)."); |
| 266 | module_param(adhoc, int, 0); |
| 267 | MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode."); |
| 268 | module_param(probe, int, 0); |
| 269 | MODULE_PARM_DESC(probe, "If zero, the driver won't start the card."); |
| 270 | |
| 271 | module_param(proc_uid, int, 0); |
| 272 | MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to."); |
| 273 | module_param(proc_gid, int, 0); |
| 274 | MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to."); |
| 275 | module_param(airo_perm, int, 0); |
| 276 | MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet."); |
| 277 | module_param(proc_perm, int, 0); |
| 278 | MODULE_PARM_DESC(proc_perm, "The permission bits of the files in /proc"); |
| 279 | |
| 280 | /* This is a kind of sloppy hack to get this information to OUT4500 and |
| 281 | IN4500. I would be extremely interested in the situation where this |
| 282 | doesn't work though!!! */ |
| 283 | static int do8bitIO = 0; |
| 284 | |
| 285 | /* Return codes */ |
| 286 | #define SUCCESS 0 |
| 287 | #define ERROR -1 |
| 288 | #define NO_PACKET -2 |
| 289 | |
| 290 | /* Commands */ |
| 291 | #define NOP2 0x0000 |
| 292 | #define MAC_ENABLE 0x0001 |
| 293 | #define MAC_DISABLE 0x0002 |
| 294 | #define CMD_LOSE_SYNC 0x0003 /* Not sure what this does... */ |
| 295 | #define CMD_SOFTRESET 0x0004 |
| 296 | #define HOSTSLEEP 0x0005 |
| 297 | #define CMD_MAGIC_PKT 0x0006 |
| 298 | #define CMD_SETWAKEMASK 0x0007 |
| 299 | #define CMD_READCFG 0x0008 |
| 300 | #define CMD_SETMODE 0x0009 |
| 301 | #define CMD_ALLOCATETX 0x000a |
| 302 | #define CMD_TRANSMIT 0x000b |
| 303 | #define CMD_DEALLOCATETX 0x000c |
| 304 | #define NOP 0x0010 |
| 305 | #define CMD_WORKAROUND 0x0011 |
| 306 | #define CMD_ALLOCATEAUX 0x0020 |
| 307 | #define CMD_ACCESS 0x0021 |
| 308 | #define CMD_PCIBAP 0x0022 |
| 309 | #define CMD_PCIAUX 0x0023 |
| 310 | #define CMD_ALLOCBUF 0x0028 |
| 311 | #define CMD_GETTLV 0x0029 |
| 312 | #define CMD_PUTTLV 0x002a |
| 313 | #define CMD_DELTLV 0x002b |
| 314 | #define CMD_FINDNEXTTLV 0x002c |
| 315 | #define CMD_PSPNODES 0x0030 |
| 316 | #define CMD_SETCW 0x0031 |
| 317 | #define CMD_SETPCF 0x0032 |
| 318 | #define CMD_SETPHYREG 0x003e |
| 319 | #define CMD_TXTEST 0x003f |
| 320 | #define MAC_ENABLETX 0x0101 |
| 321 | #define CMD_LISTBSS 0x0103 |
| 322 | #define CMD_SAVECFG 0x0108 |
| 323 | #define CMD_ENABLEAUX 0x0111 |
| 324 | #define CMD_WRITERID 0x0121 |
| 325 | #define CMD_USEPSPNODES 0x0130 |
| 326 | #define MAC_ENABLERX 0x0201 |
| 327 | |
| 328 | /* Command errors */ |
| 329 | #define ERROR_QUALIF 0x00 |
| 330 | #define ERROR_ILLCMD 0x01 |
| 331 | #define ERROR_ILLFMT 0x02 |
| 332 | #define ERROR_INVFID 0x03 |
| 333 | #define ERROR_INVRID 0x04 |
| 334 | #define ERROR_LARGE 0x05 |
| 335 | #define ERROR_NDISABL 0x06 |
| 336 | #define ERROR_ALLOCBSY 0x07 |
| 337 | #define ERROR_NORD 0x0B |
| 338 | #define ERROR_NOWR 0x0C |
| 339 | #define ERROR_INVFIDTX 0x0D |
| 340 | #define ERROR_TESTACT 0x0E |
| 341 | #define ERROR_TAGNFND 0x12 |
| 342 | #define ERROR_DECODE 0x20 |
| 343 | #define ERROR_DESCUNAV 0x21 |
| 344 | #define ERROR_BADLEN 0x22 |
| 345 | #define ERROR_MODE 0x80 |
| 346 | #define ERROR_HOP 0x81 |
| 347 | #define ERROR_BINTER 0x82 |
| 348 | #define ERROR_RXMODE 0x83 |
| 349 | #define ERROR_MACADDR 0x84 |
| 350 | #define ERROR_RATES 0x85 |
| 351 | #define ERROR_ORDER 0x86 |
| 352 | #define ERROR_SCAN 0x87 |
| 353 | #define ERROR_AUTH 0x88 |
| 354 | #define ERROR_PSMODE 0x89 |
| 355 | #define ERROR_RTYPE 0x8A |
| 356 | #define ERROR_DIVER 0x8B |
| 357 | #define ERROR_SSID 0x8C |
| 358 | #define ERROR_APLIST 0x8D |
| 359 | #define ERROR_AUTOWAKE 0x8E |
| 360 | #define ERROR_LEAP 0x8F |
| 361 | |
| 362 | /* Registers */ |
| 363 | #define COMMAND 0x00 |
| 364 | #define PARAM0 0x02 |
| 365 | #define PARAM1 0x04 |
| 366 | #define PARAM2 0x06 |
| 367 | #define STATUS 0x08 |
| 368 | #define RESP0 0x0a |
| 369 | #define RESP1 0x0c |
| 370 | #define RESP2 0x0e |
| 371 | #define LINKSTAT 0x10 |
| 372 | #define SELECT0 0x18 |
| 373 | #define OFFSET0 0x1c |
| 374 | #define RXFID 0x20 |
| 375 | #define TXALLOCFID 0x22 |
| 376 | #define TXCOMPLFID 0x24 |
| 377 | #define DATA0 0x36 |
| 378 | #define EVSTAT 0x30 |
| 379 | #define EVINTEN 0x32 |
| 380 | #define EVACK 0x34 |
| 381 | #define SWS0 0x28 |
| 382 | #define SWS1 0x2a |
| 383 | #define SWS2 0x2c |
| 384 | #define SWS3 0x2e |
| 385 | #define AUXPAGE 0x3A |
| 386 | #define AUXOFF 0x3C |
| 387 | #define AUXDATA 0x3E |
| 388 | |
| 389 | #define FID_TX 1 |
| 390 | #define FID_RX 2 |
| 391 | /* Offset into aux memory for descriptors */ |
| 392 | #define AUX_OFFSET 0x800 |
| 393 | /* Size of allocated packets */ |
| 394 | #define PKTSIZE 1840 |
| 395 | #define RIDSIZE 2048 |
| 396 | /* Size of the transmit queue */ |
| 397 | #define MAXTXQ 64 |
| 398 | |
| 399 | /* BAP selectors */ |
| 400 | #define BAP0 0 // Used for receiving packets |
| 401 | #define BAP1 2 // Used for xmiting packets and working with RIDS |
| 402 | |
| 403 | /* Flags */ |
| 404 | #define COMMAND_BUSY 0x8000 |
| 405 | |
| 406 | #define BAP_BUSY 0x8000 |
| 407 | #define BAP_ERR 0x4000 |
| 408 | #define BAP_DONE 0x2000 |
| 409 | |
| 410 | #define PROMISC 0xffff |
| 411 | #define NOPROMISC 0x0000 |
| 412 | |
| 413 | #define EV_CMD 0x10 |
| 414 | #define EV_CLEARCOMMANDBUSY 0x4000 |
| 415 | #define EV_RX 0x01 |
| 416 | #define EV_TX 0x02 |
| 417 | #define EV_TXEXC 0x04 |
| 418 | #define EV_ALLOC 0x08 |
| 419 | #define EV_LINK 0x80 |
| 420 | #define EV_AWAKE 0x100 |
| 421 | #define EV_TXCPY 0x400 |
| 422 | #define EV_UNKNOWN 0x800 |
| 423 | #define EV_MIC 0x1000 /* Message Integrity Check Interrupt */ |
| 424 | #define EV_AWAKEN 0x2000 |
| 425 | #define STATUS_INTS (EV_AWAKE|EV_LINK|EV_TXEXC|EV_TX|EV_TXCPY|EV_RX|EV_MIC) |
| 426 | |
| 427 | #ifdef CHECK_UNKNOWN_INTS |
| 428 | #define IGNORE_INTS ( EV_CMD | EV_UNKNOWN) |
| 429 | #else |
| 430 | #define IGNORE_INTS (~STATUS_INTS) |
| 431 | #endif |
| 432 | |
| 433 | /* RID TYPES */ |
| 434 | #define RID_RW 0x20 |
| 435 | |
| 436 | /* The RIDs */ |
| 437 | #define RID_CAPABILITIES 0xFF00 |
| 438 | #define RID_APINFO 0xFF01 |
| 439 | #define RID_RADIOINFO 0xFF02 |
| 440 | #define RID_UNKNOWN3 0xFF03 |
| 441 | #define RID_RSSI 0xFF04 |
| 442 | #define RID_CONFIG 0xFF10 |
| 443 | #define RID_SSID 0xFF11 |
| 444 | #define RID_APLIST 0xFF12 |
| 445 | #define RID_DRVNAME 0xFF13 |
| 446 | #define RID_ETHERENCAP 0xFF14 |
| 447 | #define RID_WEP_TEMP 0xFF15 |
| 448 | #define RID_WEP_PERM 0xFF16 |
| 449 | #define RID_MODULATION 0xFF17 |
| 450 | #define RID_OPTIONS 0xFF18 |
| 451 | #define RID_ACTUALCONFIG 0xFF20 /*readonly*/ |
| 452 | #define RID_FACTORYCONFIG 0xFF21 |
| 453 | #define RID_UNKNOWN22 0xFF22 |
| 454 | #define RID_LEAPUSERNAME 0xFF23 |
| 455 | #define RID_LEAPPASSWORD 0xFF24 |
| 456 | #define RID_STATUS 0xFF50 |
| 457 | #define RID_BEACON_HST 0xFF51 |
| 458 | #define RID_BUSY_HST 0xFF52 |
| 459 | #define RID_RETRIES_HST 0xFF53 |
| 460 | #define RID_UNKNOWN54 0xFF54 |
| 461 | #define RID_UNKNOWN55 0xFF55 |
| 462 | #define RID_UNKNOWN56 0xFF56 |
| 463 | #define RID_MIC 0xFF57 |
| 464 | #define RID_STATS16 0xFF60 |
| 465 | #define RID_STATS16DELTA 0xFF61 |
| 466 | #define RID_STATS16DELTACLEAR 0xFF62 |
| 467 | #define RID_STATS 0xFF68 |
| 468 | #define RID_STATSDELTA 0xFF69 |
| 469 | #define RID_STATSDELTACLEAR 0xFF6A |
| 470 | #define RID_ECHOTEST_RID 0xFF70 |
| 471 | #define RID_ECHOTEST_RESULTS 0xFF71 |
| 472 | #define RID_BSSLISTFIRST 0xFF72 |
| 473 | #define RID_BSSLISTNEXT 0xFF73 |
| 474 | |
| 475 | typedef struct { |
| 476 | u16 cmd; |
| 477 | u16 parm0; |
| 478 | u16 parm1; |
| 479 | u16 parm2; |
| 480 | } Cmd; |
| 481 | |
| 482 | typedef struct { |
| 483 | u16 status; |
| 484 | u16 rsp0; |
| 485 | u16 rsp1; |
| 486 | u16 rsp2; |
| 487 | } Resp; |
| 488 | |
| 489 | /* |
| 490 | * Rids and endian-ness: The Rids will always be in cpu endian, since |
| 491 | * this all the patches from the big-endian guys end up doing that. |
| 492 | * so all rid access should use the read/writeXXXRid routines. |
| 493 | */ |
| 494 | |
| 495 | /* This is redundant for x86 archs, but it seems necessary for ARM */ |
| 496 | #pragma pack(1) |
| 497 | |
| 498 | /* This structure came from an email sent to me from an engineer at |
| 499 | aironet for inclusion into this driver */ |
| 500 | typedef struct { |
| 501 | u16 len; |
| 502 | u16 kindex; |
| 503 | u8 mac[ETH_ALEN]; |
| 504 | u16 klen; |
| 505 | u8 key[16]; |
| 506 | } WepKeyRid; |
| 507 | |
| 508 | /* These structures are from the Aironet's PC4500 Developers Manual */ |
| 509 | typedef struct { |
| 510 | u16 len; |
| 511 | u8 ssid[32]; |
| 512 | } Ssid; |
| 513 | |
| 514 | typedef struct { |
| 515 | u16 len; |
| 516 | Ssid ssids[3]; |
| 517 | } SsidRid; |
| 518 | |
| 519 | typedef struct { |
| 520 | u16 len; |
| 521 | u16 modulation; |
| 522 | #define MOD_DEFAULT 0 |
| 523 | #define MOD_CCK 1 |
| 524 | #define MOD_MOK 2 |
| 525 | } ModulationRid; |
| 526 | |
| 527 | typedef struct { |
| 528 | u16 len; /* sizeof(ConfigRid) */ |
| 529 | u16 opmode; /* operating mode */ |
| 530 | #define MODE_STA_IBSS 0 |
| 531 | #define MODE_STA_ESS 1 |
| 532 | #define MODE_AP 2 |
| 533 | #define MODE_AP_RPTR 3 |
| 534 | #define MODE_ETHERNET_HOST (0<<8) /* rx payloads converted */ |
| 535 | #define MODE_LLC_HOST (1<<8) /* rx payloads left as is */ |
| 536 | #define MODE_AIRONET_EXTEND (1<<9) /* enable Aironet extenstions */ |
| 537 | #define MODE_AP_INTERFACE (1<<10) /* enable ap interface extensions */ |
| 538 | #define MODE_ANTENNA_ALIGN (1<<11) /* enable antenna alignment */ |
| 539 | #define MODE_ETHER_LLC (1<<12) /* enable ethernet LLC */ |
| 540 | #define MODE_LEAF_NODE (1<<13) /* enable leaf node bridge */ |
| 541 | #define MODE_CF_POLLABLE (1<<14) /* enable CF pollable */ |
| 542 | #define MODE_MIC (1<<15) /* enable MIC */ |
| 543 | u16 rmode; /* receive mode */ |
| 544 | #define RXMODE_BC_MC_ADDR 0 |
| 545 | #define RXMODE_BC_ADDR 1 /* ignore multicasts */ |
| 546 | #define RXMODE_ADDR 2 /* ignore multicast and broadcast */ |
| 547 | #define RXMODE_RFMON 3 /* wireless monitor mode */ |
| 548 | #define RXMODE_RFMON_ANYBSS 4 |
| 549 | #define RXMODE_LANMON 5 /* lan style monitor -- data packets only */ |
| 550 | #define RXMODE_DISABLE_802_3_HEADER (1<<8) /* disables 802.3 header on rx */ |
| 551 | #define RXMODE_NORMALIZED_RSSI (1<<9) /* return normalized RSSI */ |
| 552 | u16 fragThresh; |
| 553 | u16 rtsThres; |
| 554 | u8 macAddr[ETH_ALEN]; |
| 555 | u8 rates[8]; |
| 556 | u16 shortRetryLimit; |
| 557 | u16 longRetryLimit; |
| 558 | u16 txLifetime; /* in kusec */ |
| 559 | u16 rxLifetime; /* in kusec */ |
| 560 | u16 stationary; |
| 561 | u16 ordering; |
| 562 | u16 u16deviceType; /* for overriding device type */ |
| 563 | u16 cfpRate; |
| 564 | u16 cfpDuration; |
| 565 | u16 _reserved1[3]; |
| 566 | /*---------- Scanning/Associating ----------*/ |
| 567 | u16 scanMode; |
| 568 | #define SCANMODE_ACTIVE 0 |
| 569 | #define SCANMODE_PASSIVE 1 |
| 570 | #define SCANMODE_AIROSCAN 2 |
| 571 | u16 probeDelay; /* in kusec */ |
| 572 | u16 probeEnergyTimeout; /* in kusec */ |
| 573 | u16 probeResponseTimeout; |
| 574 | u16 beaconListenTimeout; |
| 575 | u16 joinNetTimeout; |
| 576 | u16 authTimeout; |
| 577 | u16 authType; |
| 578 | #define AUTH_OPEN 0x1 |
| 579 | #define AUTH_ENCRYPT 0x101 |
| 580 | #define AUTH_SHAREDKEY 0x102 |
| 581 | #define AUTH_ALLOW_UNENCRYPTED 0x200 |
| 582 | u16 associationTimeout; |
| 583 | u16 specifiedApTimeout; |
| 584 | u16 offlineScanInterval; |
| 585 | u16 offlineScanDuration; |
| 586 | u16 linkLossDelay; |
| 587 | u16 maxBeaconLostTime; |
| 588 | u16 refreshInterval; |
| 589 | #define DISABLE_REFRESH 0xFFFF |
| 590 | u16 _reserved1a[1]; |
| 591 | /*---------- Power save operation ----------*/ |
| 592 | u16 powerSaveMode; |
| 593 | #define POWERSAVE_CAM 0 |
| 594 | #define POWERSAVE_PSP 1 |
| 595 | #define POWERSAVE_PSPCAM 2 |
| 596 | u16 sleepForDtims; |
| 597 | u16 listenInterval; |
| 598 | u16 fastListenInterval; |
| 599 | u16 listenDecay; |
| 600 | u16 fastListenDelay; |
| 601 | u16 _reserved2[2]; |
| 602 | /*---------- Ap/Ibss config items ----------*/ |
| 603 | u16 beaconPeriod; |
| 604 | u16 atimDuration; |
| 605 | u16 hopPeriod; |
| 606 | u16 channelSet; |
| 607 | u16 channel; |
| 608 | u16 dtimPeriod; |
| 609 | u16 bridgeDistance; |
| 610 | u16 radioID; |
| 611 | /*---------- Radio configuration ----------*/ |
| 612 | u16 radioType; |
| 613 | #define RADIOTYPE_DEFAULT 0 |
| 614 | #define RADIOTYPE_802_11 1 |
| 615 | #define RADIOTYPE_LEGACY 2 |
| 616 | u8 rxDiversity; |
| 617 | u8 txDiversity; |
| 618 | u16 txPower; |
| 619 | #define TXPOWER_DEFAULT 0 |
| 620 | u16 rssiThreshold; |
| 621 | #define RSSI_DEFAULT 0 |
| 622 | u16 modulation; |
| 623 | #define PREAMBLE_AUTO 0 |
| 624 | #define PREAMBLE_LONG 1 |
| 625 | #define PREAMBLE_SHORT 2 |
| 626 | u16 preamble; |
| 627 | u16 homeProduct; |
| 628 | u16 radioSpecific; |
| 629 | /*---------- Aironet Extensions ----------*/ |
| 630 | u8 nodeName[16]; |
| 631 | u16 arlThreshold; |
| 632 | u16 arlDecay; |
| 633 | u16 arlDelay; |
| 634 | u16 _reserved4[1]; |
| 635 | /*---------- Aironet Extensions ----------*/ |
| 636 | u8 magicAction; |
| 637 | #define MAGIC_ACTION_STSCHG 1 |
| 638 | #define MAGIC_ACTION_RESUME 2 |
| 639 | #define MAGIC_IGNORE_MCAST (1<<8) |
| 640 | #define MAGIC_IGNORE_BCAST (1<<9) |
| 641 | #define MAGIC_SWITCH_TO_PSP (0<<10) |
| 642 | #define MAGIC_STAY_IN_CAM (1<<10) |
| 643 | u8 magicControl; |
| 644 | u16 autoWake; |
| 645 | } ConfigRid; |
| 646 | |
| 647 | typedef struct { |
| 648 | u16 len; |
| 649 | u8 mac[ETH_ALEN]; |
| 650 | u16 mode; |
| 651 | u16 errorCode; |
| 652 | u16 sigQuality; |
| 653 | u16 SSIDlen; |
| 654 | char SSID[32]; |
| 655 | char apName[16]; |
| 656 | u8 bssid[4][ETH_ALEN]; |
| 657 | u16 beaconPeriod; |
| 658 | u16 dimPeriod; |
| 659 | u16 atimDuration; |
| 660 | u16 hopPeriod; |
| 661 | u16 channelSet; |
| 662 | u16 channel; |
| 663 | u16 hopsToBackbone; |
| 664 | u16 apTotalLoad; |
| 665 | u16 generatedLoad; |
| 666 | u16 accumulatedArl; |
| 667 | u16 signalQuality; |
| 668 | u16 currentXmitRate; |
| 669 | u16 apDevExtensions; |
| 670 | u16 normalizedSignalStrength; |
| 671 | u16 shortPreamble; |
| 672 | u8 apIP[4]; |
| 673 | u8 noisePercent; /* Noise percent in last second */ |
| 674 | u8 noisedBm; /* Noise dBm in last second */ |
| 675 | u8 noiseAvePercent; /* Noise percent in last minute */ |
| 676 | u8 noiseAvedBm; /* Noise dBm in last minute */ |
| 677 | u8 noiseMaxPercent; /* Highest noise percent in last minute */ |
| 678 | u8 noiseMaxdBm; /* Highest noise dbm in last minute */ |
| 679 | u16 load; |
| 680 | u8 carrier[4]; |
| 681 | u16 assocStatus; |
| 682 | #define STAT_NOPACKETS 0 |
| 683 | #define STAT_NOCARRIERSET 10 |
| 684 | #define STAT_GOTCARRIERSET 11 |
| 685 | #define STAT_WRONGSSID 20 |
| 686 | #define STAT_BADCHANNEL 25 |
| 687 | #define STAT_BADBITRATES 30 |
| 688 | #define STAT_BADPRIVACY 35 |
| 689 | #define STAT_APFOUND 40 |
| 690 | #define STAT_APREJECTED 50 |
| 691 | #define STAT_AUTHENTICATING 60 |
| 692 | #define STAT_DEAUTHENTICATED 61 |
| 693 | #define STAT_AUTHTIMEOUT 62 |
| 694 | #define STAT_ASSOCIATING 70 |
| 695 | #define STAT_DEASSOCIATED 71 |
| 696 | #define STAT_ASSOCTIMEOUT 72 |
| 697 | #define STAT_NOTAIROAP 73 |
| 698 | #define STAT_ASSOCIATED 80 |
| 699 | #define STAT_LEAPING 90 |
| 700 | #define STAT_LEAPFAILED 91 |
| 701 | #define STAT_LEAPTIMEDOUT 92 |
| 702 | #define STAT_LEAPCOMPLETE 93 |
| 703 | } StatusRid; |
| 704 | |
| 705 | typedef struct { |
| 706 | u16 len; |
| 707 | u16 spacer; |
| 708 | u32 vals[100]; |
| 709 | } StatsRid; |
| 710 | |
| 711 | |
| 712 | typedef struct { |
| 713 | u16 len; |
| 714 | u8 ap[4][ETH_ALEN]; |
| 715 | } APListRid; |
| 716 | |
| 717 | typedef struct { |
| 718 | u16 len; |
| 719 | char oui[3]; |
| 720 | char zero; |
| 721 | u16 prodNum; |
| 722 | char manName[32]; |
| 723 | char prodName[16]; |
| 724 | char prodVer[8]; |
| 725 | char factoryAddr[ETH_ALEN]; |
| 726 | char aironetAddr[ETH_ALEN]; |
| 727 | u16 radioType; |
| 728 | u16 country; |
| 729 | char callid[ETH_ALEN]; |
| 730 | char supportedRates[8]; |
| 731 | char rxDiversity; |
| 732 | char txDiversity; |
| 733 | u16 txPowerLevels[8]; |
| 734 | u16 hardVer; |
| 735 | u16 hardCap; |
| 736 | u16 tempRange; |
| 737 | u16 softVer; |
| 738 | u16 softSubVer; |
| 739 | u16 interfaceVer; |
| 740 | u16 softCap; |
| 741 | u16 bootBlockVer; |
| 742 | u16 requiredHard; |
| 743 | u16 extSoftCap; |
| 744 | } CapabilityRid; |
| 745 | |
| 746 | typedef struct { |
| 747 | u16 len; |
| 748 | u16 index; /* First is 0 and 0xffff means end of list */ |
| 749 | #define RADIO_FH 1 /* Frequency hopping radio type */ |
| 750 | #define RADIO_DS 2 /* Direct sequence radio type */ |
| 751 | #define RADIO_TMA 4 /* Proprietary radio used in old cards (2500) */ |
| 752 | u16 radioType; |
| 753 | u8 bssid[ETH_ALEN]; /* Mac address of the BSS */ |
| 754 | u8 zero; |
| 755 | u8 ssidLen; |
| 756 | u8 ssid[32]; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 757 | u16 dBm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | #define CAP_ESS (1<<0) |
| 759 | #define CAP_IBSS (1<<1) |
| 760 | #define CAP_PRIVACY (1<<4) |
| 761 | #define CAP_SHORTHDR (1<<5) |
| 762 | u16 cap; |
| 763 | u16 beaconInterval; |
| 764 | u8 rates[8]; /* Same as rates for config rid */ |
| 765 | struct { /* For frequency hopping only */ |
| 766 | u16 dwell; |
| 767 | u8 hopSet; |
| 768 | u8 hopPattern; |
| 769 | u8 hopIndex; |
| 770 | u8 fill; |
| 771 | } fh; |
| 772 | u16 dsChannel; |
| 773 | u16 atimWindow; |
| 774 | } BSSListRid; |
| 775 | |
| 776 | typedef struct { |
| 777 | u8 rssipct; |
| 778 | u8 rssidBm; |
| 779 | } tdsRssiEntry; |
| 780 | |
| 781 | typedef struct { |
| 782 | u16 len; |
| 783 | tdsRssiEntry x[256]; |
| 784 | } tdsRssiRid; |
| 785 | |
| 786 | typedef struct { |
| 787 | u16 len; |
| 788 | u16 state; |
| 789 | u16 multicastValid; |
| 790 | u8 multicast[16]; |
| 791 | u16 unicastValid; |
| 792 | u8 unicast[16]; |
| 793 | } MICRid; |
| 794 | |
| 795 | typedef struct { |
| 796 | u16 typelen; |
| 797 | |
| 798 | union { |
| 799 | u8 snap[8]; |
| 800 | struct { |
| 801 | u8 dsap; |
| 802 | u8 ssap; |
| 803 | u8 control; |
| 804 | u8 orgcode[3]; |
| 805 | u8 fieldtype[2]; |
| 806 | } llc; |
| 807 | } u; |
| 808 | u32 mic; |
| 809 | u32 seq; |
| 810 | } MICBuffer; |
| 811 | |
| 812 | typedef struct { |
| 813 | u8 da[ETH_ALEN]; |
| 814 | u8 sa[ETH_ALEN]; |
| 815 | } etherHead; |
| 816 | |
| 817 | #pragma pack() |
| 818 | |
| 819 | #define TXCTL_TXOK (1<<1) /* report if tx is ok */ |
| 820 | #define TXCTL_TXEX (1<<2) /* report if tx fails */ |
| 821 | #define TXCTL_802_3 (0<<3) /* 802.3 packet */ |
| 822 | #define TXCTL_802_11 (1<<3) /* 802.11 mac packet */ |
| 823 | #define TXCTL_ETHERNET (0<<4) /* payload has ethertype */ |
| 824 | #define TXCTL_LLC (1<<4) /* payload is llc */ |
| 825 | #define TXCTL_RELEASE (0<<5) /* release after completion */ |
| 826 | #define TXCTL_NORELEASE (1<<5) /* on completion returns to host */ |
| 827 | |
| 828 | #define BUSY_FID 0x10000 |
| 829 | |
| 830 | #ifdef CISCO_EXT |
| 831 | #define AIROMAGIC 0xa55a |
| 832 | /* Warning : SIOCDEVPRIVATE may disapear during 2.5.X - Jean II */ |
| 833 | #ifdef SIOCIWFIRSTPRIV |
| 834 | #ifdef SIOCDEVPRIVATE |
| 835 | #define AIROOLDIOCTL SIOCDEVPRIVATE |
| 836 | #define AIROOLDIDIFC AIROOLDIOCTL + 1 |
| 837 | #endif /* SIOCDEVPRIVATE */ |
| 838 | #else /* SIOCIWFIRSTPRIV */ |
| 839 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE |
| 840 | #endif /* SIOCIWFIRSTPRIV */ |
| 841 | /* This may be wrong. When using the new SIOCIWFIRSTPRIV range, we probably |
| 842 | * should use only "GET" ioctls (last bit set to 1). "SET" ioctls are root |
| 843 | * only and don't return the modified struct ifreq to the application which |
| 844 | * is usually a problem. - Jean II */ |
| 845 | #define AIROIOCTL SIOCIWFIRSTPRIV |
| 846 | #define AIROIDIFC AIROIOCTL + 1 |
| 847 | |
| 848 | /* Ioctl constants to be used in airo_ioctl.command */ |
| 849 | |
| 850 | #define AIROGCAP 0 // Capability rid |
| 851 | #define AIROGCFG 1 // USED A LOT |
| 852 | #define AIROGSLIST 2 // System ID list |
| 853 | #define AIROGVLIST 3 // List of specified AP's |
| 854 | #define AIROGDRVNAM 4 // NOTUSED |
| 855 | #define AIROGEHTENC 5 // NOTUSED |
| 856 | #define AIROGWEPKTMP 6 |
| 857 | #define AIROGWEPKNV 7 |
| 858 | #define AIROGSTAT 8 |
| 859 | #define AIROGSTATSC32 9 |
| 860 | #define AIROGSTATSD32 10 |
| 861 | #define AIROGMICRID 11 |
| 862 | #define AIROGMICSTATS 12 |
| 863 | #define AIROGFLAGS 13 |
| 864 | #define AIROGID 14 |
| 865 | #define AIRORRID 15 |
| 866 | #define AIRORSWVERSION 17 |
| 867 | |
| 868 | /* Leave gap of 40 commands after AIROGSTATSD32 for future */ |
| 869 | |
| 870 | #define AIROPCAP AIROGSTATSD32 + 40 |
| 871 | #define AIROPVLIST AIROPCAP + 1 |
| 872 | #define AIROPSLIST AIROPVLIST + 1 |
| 873 | #define AIROPCFG AIROPSLIST + 1 |
| 874 | #define AIROPSIDS AIROPCFG + 1 |
| 875 | #define AIROPAPLIST AIROPSIDS + 1 |
| 876 | #define AIROPMACON AIROPAPLIST + 1 /* Enable mac */ |
| 877 | #define AIROPMACOFF AIROPMACON + 1 /* Disable mac */ |
| 878 | #define AIROPSTCLR AIROPMACOFF + 1 |
| 879 | #define AIROPWEPKEY AIROPSTCLR + 1 |
| 880 | #define AIROPWEPKEYNV AIROPWEPKEY + 1 |
| 881 | #define AIROPLEAPPWD AIROPWEPKEYNV + 1 |
| 882 | #define AIROPLEAPUSR AIROPLEAPPWD + 1 |
| 883 | |
| 884 | /* Flash codes */ |
| 885 | |
| 886 | #define AIROFLSHRST AIROPWEPKEYNV + 40 |
| 887 | #define AIROFLSHGCHR AIROFLSHRST + 1 |
| 888 | #define AIROFLSHSTFL AIROFLSHGCHR + 1 |
| 889 | #define AIROFLSHPCHR AIROFLSHSTFL + 1 |
| 890 | #define AIROFLPUTBUF AIROFLSHPCHR + 1 |
| 891 | #define AIRORESTART AIROFLPUTBUF + 1 |
| 892 | |
| 893 | #define FLASHSIZE 32768 |
| 894 | #define AUXMEMSIZE (256 * 1024) |
| 895 | |
| 896 | typedef struct aironet_ioctl { |
| 897 | unsigned short command; // What to do |
| 898 | unsigned short len; // Len of data |
| 899 | unsigned short ridnum; // rid number |
| 900 | unsigned char __user *data; // d-data |
| 901 | } aironet_ioctl; |
| 902 | |
Domen Puncer | 62595eb | 2005-06-20 23:54:37 +0200 | [diff] [blame] | 903 | static char swversion[] = "2.1"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | #endif /* CISCO_EXT */ |
| 905 | |
| 906 | #define NUM_MODULES 2 |
| 907 | #define MIC_MSGLEN_MAX 2400 |
| 908 | #define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX |
| 909 | |
| 910 | typedef struct { |
| 911 | u32 size; // size |
| 912 | u8 enabled; // MIC enabled or not |
| 913 | u32 rxSuccess; // successful packets received |
| 914 | u32 rxIncorrectMIC; // pkts dropped due to incorrect MIC comparison |
| 915 | u32 rxNotMICed; // pkts dropped due to not being MIC'd |
| 916 | u32 rxMICPlummed; // pkts dropped due to not having a MIC plummed |
| 917 | u32 rxWrongSequence; // pkts dropped due to sequence number violation |
| 918 | u32 reserve[32]; |
| 919 | } mic_statistics; |
| 920 | |
| 921 | typedef struct { |
| 922 | u32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2]; |
| 923 | u64 accum; // accumulated mic, reduced to u32 in final() |
| 924 | int position; // current position (byte offset) in message |
| 925 | union { |
| 926 | u8 d8[4]; |
| 927 | u32 d32; |
| 928 | } part; // saves partial message word across update() calls |
| 929 | } emmh32_context; |
| 930 | |
| 931 | typedef struct { |
| 932 | emmh32_context seed; // Context - the seed |
| 933 | u32 rx; // Received sequence number |
| 934 | u32 tx; // Tx sequence number |
| 935 | u32 window; // Start of window |
| 936 | u8 valid; // Flag to say if context is valid or not |
| 937 | u8 key[16]; |
| 938 | } miccntx; |
| 939 | |
| 940 | typedef struct { |
| 941 | miccntx mCtx; // Multicast context |
| 942 | miccntx uCtx; // Unicast context |
| 943 | } mic_module; |
| 944 | |
| 945 | typedef struct { |
| 946 | unsigned int rid: 16; |
| 947 | unsigned int len: 15; |
| 948 | unsigned int valid: 1; |
| 949 | dma_addr_t host_addr; |
| 950 | } Rid; |
| 951 | |
| 952 | typedef struct { |
| 953 | unsigned int offset: 15; |
| 954 | unsigned int eoc: 1; |
| 955 | unsigned int len: 15; |
| 956 | unsigned int valid: 1; |
| 957 | dma_addr_t host_addr; |
| 958 | } TxFid; |
| 959 | |
| 960 | typedef struct { |
| 961 | unsigned int ctl: 15; |
| 962 | unsigned int rdy: 1; |
| 963 | unsigned int len: 15; |
| 964 | unsigned int valid: 1; |
| 965 | dma_addr_t host_addr; |
| 966 | } RxFid; |
| 967 | |
| 968 | /* |
| 969 | * Host receive descriptor |
| 970 | */ |
| 971 | typedef struct { |
| 972 | unsigned char __iomem *card_ram_off; /* offset into card memory of the |
| 973 | desc */ |
| 974 | RxFid rx_desc; /* card receive descriptor */ |
| 975 | char *virtual_host_addr; /* virtual address of host receive |
| 976 | buffer */ |
| 977 | int pending; |
| 978 | } HostRxDesc; |
| 979 | |
| 980 | /* |
| 981 | * Host transmit descriptor |
| 982 | */ |
| 983 | typedef struct { |
| 984 | unsigned char __iomem *card_ram_off; /* offset into card memory of the |
| 985 | desc */ |
| 986 | TxFid tx_desc; /* card transmit descriptor */ |
| 987 | char *virtual_host_addr; /* virtual address of host receive |
| 988 | buffer */ |
| 989 | int pending; |
| 990 | } HostTxDesc; |
| 991 | |
| 992 | /* |
| 993 | * Host RID descriptor |
| 994 | */ |
| 995 | typedef struct { |
| 996 | unsigned char __iomem *card_ram_off; /* offset into card memory of the |
| 997 | descriptor */ |
| 998 | Rid rid_desc; /* card RID descriptor */ |
| 999 | char *virtual_host_addr; /* virtual address of host receive |
| 1000 | buffer */ |
| 1001 | } HostRidDesc; |
| 1002 | |
| 1003 | typedef struct { |
| 1004 | u16 sw0; |
| 1005 | u16 sw1; |
| 1006 | u16 status; |
| 1007 | u16 len; |
| 1008 | #define HOST_SET (1 << 0) |
| 1009 | #define HOST_INT_TX (1 << 1) /* Interrupt on successful TX */ |
| 1010 | #define HOST_INT_TXERR (1 << 2) /* Interrupt on unseccessful TX */ |
| 1011 | #define HOST_LCC_PAYLOAD (1 << 4) /* LLC payload, 0 = Ethertype */ |
| 1012 | #define HOST_DONT_RLSE (1 << 5) /* Don't release buffer when done */ |
| 1013 | #define HOST_DONT_RETRY (1 << 6) /* Don't retry trasmit */ |
| 1014 | #define HOST_CLR_AID (1 << 7) /* clear AID failure */ |
| 1015 | #define HOST_RTS (1 << 9) /* Force RTS use */ |
| 1016 | #define HOST_SHORT (1 << 10) /* Do short preamble */ |
| 1017 | u16 ctl; |
| 1018 | u16 aid; |
| 1019 | u16 retries; |
| 1020 | u16 fill; |
| 1021 | } TxCtlHdr; |
| 1022 | |
| 1023 | typedef struct { |
| 1024 | u16 ctl; |
| 1025 | u16 duration; |
| 1026 | char addr1[6]; |
| 1027 | char addr2[6]; |
| 1028 | char addr3[6]; |
| 1029 | u16 seq; |
| 1030 | char addr4[6]; |
| 1031 | } WifiHdr; |
| 1032 | |
| 1033 | |
| 1034 | typedef struct { |
| 1035 | TxCtlHdr ctlhdr; |
| 1036 | u16 fill1; |
| 1037 | u16 fill2; |
| 1038 | WifiHdr wifihdr; |
| 1039 | u16 gaplen; |
| 1040 | u16 status; |
| 1041 | } WifiCtlHdr; |
| 1042 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1043 | static WifiCtlHdr wifictlhdr8023 = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | .ctlhdr = { |
| 1045 | .ctl = HOST_DONT_RLSE, |
| 1046 | } |
| 1047 | }; |
| 1048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | // Frequency list (map channels to frequencies) |
| 1050 | static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442, |
| 1051 | 2447, 2452, 2457, 2462, 2467, 2472, 2484 }; |
| 1052 | |
| 1053 | // A few details needed for WEP (Wireless Equivalent Privacy) |
| 1054 | #define MAX_KEY_SIZE 13 // 128 (?) bits |
| 1055 | #define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP |
| 1056 | typedef struct wep_key_t { |
| 1057 | u16 len; |
| 1058 | u8 key[16]; /* 40-bit and 104-bit keys */ |
| 1059 | } wep_key_t; |
| 1060 | |
| 1061 | /* Backward compatibility */ |
| 1062 | #ifndef IW_ENCODE_NOKEY |
| 1063 | #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */ |
| 1064 | #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN) |
| 1065 | #endif /* IW_ENCODE_NOKEY */ |
| 1066 | |
| 1067 | /* List of Wireless Handlers (new API) */ |
| 1068 | static const struct iw_handler_def airo_handler_def; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | |
| 1070 | static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)"; |
| 1071 | |
| 1072 | struct airo_info; |
| 1073 | |
| 1074 | static int get_dec_u16( char *buffer, int *start, int limit ); |
| 1075 | static void OUT4500( struct airo_info *, u16 register, u16 value ); |
| 1076 | static unsigned short IN4500( struct airo_info *, u16 register ); |
| 1077 | static u16 setup_card(struct airo_info*, u8 *mac, int lock); |
| 1078 | static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ); |
| 1079 | static void disable_MAC(struct airo_info *ai, int lock); |
| 1080 | static void enable_interrupts(struct airo_info*); |
| 1081 | static void disable_interrupts(struct airo_info*); |
| 1082 | static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp); |
| 1083 | static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap); |
| 1084 | static int aux_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen, |
| 1085 | int whichbap); |
| 1086 | static int fast_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen, |
| 1087 | int whichbap); |
| 1088 | static int bap_write(struct airo_info*, const u16 *pu16Src, int bytelen, |
| 1089 | int whichbap); |
| 1090 | static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd); |
| 1091 | static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock); |
| 1092 | static int PC4500_writerid(struct airo_info*, u16 rid, const void |
| 1093 | *pBuf, int len, int lock); |
| 1094 | static int do_writerid( struct airo_info*, u16 rid, const void *rid_data, |
| 1095 | int len, int dummy ); |
| 1096 | static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw); |
| 1097 | static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket); |
| 1098 | static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket); |
| 1099 | |
| 1100 | static int mpi_send_packet (struct net_device *dev); |
| 1101 | static void mpi_unmap_card(struct pci_dev *pci); |
| 1102 | static void mpi_receive_802_3(struct airo_info *ai); |
| 1103 | static void mpi_receive_802_11(struct airo_info *ai); |
| 1104 | static int waitbusy (struct airo_info *ai); |
| 1105 | |
| 1106 | static irqreturn_t airo_interrupt( int irq, void* dev_id, struct pt_regs |
| 1107 | *regs); |
| 1108 | static int airo_thread(void *data); |
| 1109 | static void timer_func( struct net_device *dev ); |
| 1110 | static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1111 | static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | static void airo_read_wireless_stats (struct airo_info *local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | #ifdef CISCO_EXT |
| 1114 | static int readrids(struct net_device *dev, aironet_ioctl *comp); |
| 1115 | static int writerids(struct net_device *dev, aironet_ioctl *comp); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1116 | static int flashcard(struct net_device *dev, aironet_ioctl *comp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | #endif /* CISCO_EXT */ |
| 1118 | #ifdef MICSUPPORT |
| 1119 | static void micinit(struct airo_info *ai); |
| 1120 | static int micsetup(struct airo_info *ai); |
| 1121 | static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len); |
| 1122 | static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen); |
| 1123 | |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 1124 | static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi); |
| 1125 | static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm); |
| 1126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | #include <linux/crypto.h> |
| 1128 | #endif |
| 1129 | |
| 1130 | struct airo_info { |
| 1131 | struct net_device_stats stats; |
| 1132 | struct net_device *dev; |
| 1133 | /* Note, we can have MAX_FIDS outstanding. FIDs are 16-bits, so we |
| 1134 | use the high bit to mark whether it is in use. */ |
| 1135 | #define MAX_FIDS 6 |
| 1136 | #define MPI_MAX_FIDS 1 |
| 1137 | int fids[MAX_FIDS]; |
| 1138 | ConfigRid config; |
| 1139 | char keyindex; // Used with auto wep |
| 1140 | char defindex; // Used with auto wep |
| 1141 | struct proc_dir_entry *proc_entry; |
| 1142 | spinlock_t aux_lock; |
| 1143 | unsigned long flags; |
| 1144 | #define FLAG_PROMISC 8 /* IFF_PROMISC 0x100 - include/linux/if.h */ |
| 1145 | #define FLAG_RADIO_OFF 0 /* User disabling of MAC */ |
| 1146 | #define FLAG_RADIO_DOWN 1 /* ifup/ifdown disabling of MAC */ |
| 1147 | #define FLAG_RADIO_MASK 0x03 |
| 1148 | #define FLAG_ENABLED 2 |
| 1149 | #define FLAG_ADHOC 3 /* Needed by MIC */ |
| 1150 | #define FLAG_MIC_CAPABLE 4 |
| 1151 | #define FLAG_UPDATE_MULTI 5 |
| 1152 | #define FLAG_UPDATE_UNI 6 |
| 1153 | #define FLAG_802_11 7 |
| 1154 | #define FLAG_PENDING_XMIT 9 |
| 1155 | #define FLAG_PENDING_XMIT11 10 |
| 1156 | #define FLAG_MPI 11 |
| 1157 | #define FLAG_REGISTERED 12 |
| 1158 | #define FLAG_COMMIT 13 |
| 1159 | #define FLAG_RESET 14 |
| 1160 | #define FLAG_FLASHING 15 |
| 1161 | #define JOB_MASK 0x1ff0000 |
| 1162 | #define JOB_DIE 16 |
| 1163 | #define JOB_XMIT 17 |
| 1164 | #define JOB_XMIT11 18 |
| 1165 | #define JOB_STATS 19 |
| 1166 | #define JOB_PROMISC 20 |
| 1167 | #define JOB_MIC 21 |
| 1168 | #define JOB_EVENT 22 |
| 1169 | #define JOB_AUTOWEP 23 |
| 1170 | #define JOB_WSTATS 24 |
| 1171 | int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen, |
| 1172 | int whichbap); |
| 1173 | unsigned short *flash; |
| 1174 | tdsRssiEntry *rssi; |
| 1175 | struct task_struct *task; |
| 1176 | struct semaphore sem; |
| 1177 | pid_t thr_pid; |
| 1178 | wait_queue_head_t thr_wait; |
| 1179 | struct completion thr_exited; |
| 1180 | unsigned long expires; |
| 1181 | struct { |
| 1182 | struct sk_buff *skb; |
| 1183 | int fid; |
| 1184 | } xmit, xmit11; |
| 1185 | struct net_device *wifidev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | struct iw_statistics wstats; // wireless stats |
| 1187 | unsigned long scan_timestamp; /* Time started to scan */ |
| 1188 | struct iw_spy_data spy_data; |
| 1189 | struct iw_public_data wireless_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | #ifdef MICSUPPORT |
| 1191 | /* MIC stuff */ |
| 1192 | struct crypto_tfm *tfm; |
| 1193 | mic_module mod[2]; |
| 1194 | mic_statistics micstats; |
| 1195 | #endif |
| 1196 | HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors |
| 1197 | HostTxDesc txfids[MPI_MAX_FIDS]; |
| 1198 | HostRidDesc config_desc; |
| 1199 | unsigned long ridbus; // phys addr of config_desc |
| 1200 | struct sk_buff_head txq;// tx queue used by mpi350 code |
| 1201 | struct pci_dev *pci; |
| 1202 | unsigned char __iomem *pcimem; |
| 1203 | unsigned char __iomem *pciaux; |
| 1204 | unsigned char *shared; |
| 1205 | dma_addr_t shared_dma; |
Pavel Machek | 1cc68ae | 2005-06-20 15:33:04 -0700 | [diff] [blame] | 1206 | pm_message_t power; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | SsidRid *SSID; |
| 1208 | APListRid *APList; |
| 1209 | #define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE |
| 1210 | char proc_name[IFNAMSIZ]; |
| 1211 | }; |
| 1212 | |
| 1213 | static inline int bap_read(struct airo_info *ai, u16 *pu16Dst, int bytelen, |
| 1214 | int whichbap) { |
| 1215 | return ai->bap_read(ai, pu16Dst, bytelen, whichbap); |
| 1216 | } |
| 1217 | |
| 1218 | static int setup_proc_entry( struct net_device *dev, |
| 1219 | struct airo_info *apriv ); |
| 1220 | static int takedown_proc_entry( struct net_device *dev, |
| 1221 | struct airo_info *apriv ); |
| 1222 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1223 | static int cmdreset(struct airo_info *ai); |
| 1224 | static int setflashmode (struct airo_info *ai); |
| 1225 | static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime); |
| 1226 | static int flashputbuf(struct airo_info *ai); |
| 1227 | static int flashrestart(struct airo_info *ai,struct net_device *dev); |
| 1228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | #ifdef MICSUPPORT |
| 1230 | /*********************************************************************** |
| 1231 | * MIC ROUTINES * |
| 1232 | *********************************************************************** |
| 1233 | */ |
| 1234 | |
| 1235 | static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq); |
| 1236 | static void MoveWindow(miccntx *context, u32 micSeq); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1237 | static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *); |
| 1238 | static void emmh32_init(emmh32_context *context); |
| 1239 | static void emmh32_update(emmh32_context *context, u8 *pOctets, int len); |
| 1240 | static void emmh32_final(emmh32_context *context, u8 digest[4]); |
| 1241 | static int flashpchar(struct airo_info *ai,int byte,int dwelltime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
| 1243 | /* micinit - Initialize mic seed */ |
| 1244 | |
| 1245 | static void micinit(struct airo_info *ai) |
| 1246 | { |
| 1247 | MICRid mic_rid; |
| 1248 | |
| 1249 | clear_bit(JOB_MIC, &ai->flags); |
| 1250 | PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0); |
| 1251 | up(&ai->sem); |
| 1252 | |
| 1253 | ai->micstats.enabled = (mic_rid.state & 0x00FF) ? 1 : 0; |
| 1254 | |
| 1255 | if (ai->micstats.enabled) { |
| 1256 | /* Key must be valid and different */ |
| 1257 | if (mic_rid.multicastValid && (!ai->mod[0].mCtx.valid || |
| 1258 | (memcmp (ai->mod[0].mCtx.key, mic_rid.multicast, |
| 1259 | sizeof(ai->mod[0].mCtx.key)) != 0))) { |
| 1260 | /* Age current mic Context */ |
| 1261 | memcpy(&ai->mod[1].mCtx,&ai->mod[0].mCtx,sizeof(miccntx)); |
| 1262 | /* Initialize new context */ |
| 1263 | memcpy(&ai->mod[0].mCtx.key,mic_rid.multicast,sizeof(mic_rid.multicast)); |
| 1264 | ai->mod[0].mCtx.window = 33; //Window always points to the middle |
| 1265 | ai->mod[0].mCtx.rx = 0; //Rx Sequence numbers |
| 1266 | ai->mod[0].mCtx.tx = 0; //Tx sequence numbers |
| 1267 | ai->mod[0].mCtx.valid = 1; //Key is now valid |
| 1268 | |
| 1269 | /* Give key to mic seed */ |
| 1270 | emmh32_setseed(&ai->mod[0].mCtx.seed,mic_rid.multicast,sizeof(mic_rid.multicast), ai->tfm); |
| 1271 | } |
| 1272 | |
| 1273 | /* Key must be valid and different */ |
| 1274 | if (mic_rid.unicastValid && (!ai->mod[0].uCtx.valid || |
| 1275 | (memcmp(ai->mod[0].uCtx.key, mic_rid.unicast, |
| 1276 | sizeof(ai->mod[0].uCtx.key)) != 0))) { |
| 1277 | /* Age current mic Context */ |
| 1278 | memcpy(&ai->mod[1].uCtx,&ai->mod[0].uCtx,sizeof(miccntx)); |
| 1279 | /* Initialize new context */ |
| 1280 | memcpy(&ai->mod[0].uCtx.key,mic_rid.unicast,sizeof(mic_rid.unicast)); |
| 1281 | |
| 1282 | ai->mod[0].uCtx.window = 33; //Window always points to the middle |
| 1283 | ai->mod[0].uCtx.rx = 0; //Rx Sequence numbers |
| 1284 | ai->mod[0].uCtx.tx = 0; //Tx sequence numbers |
| 1285 | ai->mod[0].uCtx.valid = 1; //Key is now valid |
| 1286 | |
| 1287 | //Give key to mic seed |
| 1288 | emmh32_setseed(&ai->mod[0].uCtx.seed, mic_rid.unicast, sizeof(mic_rid.unicast), ai->tfm); |
| 1289 | } |
| 1290 | } else { |
| 1291 | /* So next time we have a valid key and mic is enabled, we will update |
| 1292 | * the sequence number if the key is the same as before. |
| 1293 | */ |
| 1294 | ai->mod[0].uCtx.valid = 0; |
| 1295 | ai->mod[0].mCtx.valid = 0; |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | /* micsetup - Get ready for business */ |
| 1300 | |
| 1301 | static int micsetup(struct airo_info *ai) { |
| 1302 | int i; |
| 1303 | |
| 1304 | if (ai->tfm == NULL) |
Herbert Xu | eb6f116 | 2005-09-01 17:43:25 -0700 | [diff] [blame] | 1305 | ai->tfm = crypto_alloc_tfm("aes", CRYPTO_TFM_REQ_MAY_SLEEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | |
| 1307 | if (ai->tfm == NULL) { |
| 1308 | printk(KERN_ERR "airo: failed to load transform for AES\n"); |
| 1309 | return ERROR; |
| 1310 | } |
| 1311 | |
| 1312 | for (i=0; i < NUM_MODULES; i++) { |
| 1313 | memset(&ai->mod[i].mCtx,0,sizeof(miccntx)); |
| 1314 | memset(&ai->mod[i].uCtx,0,sizeof(miccntx)); |
| 1315 | } |
| 1316 | return SUCCESS; |
| 1317 | } |
| 1318 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1319 | static char micsnap[] = {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | |
| 1321 | /*=========================================================================== |
| 1322 | * Description: Mic a packet |
| 1323 | * |
| 1324 | * Inputs: etherHead * pointer to an 802.3 frame |
| 1325 | * |
| 1326 | * Returns: BOOLEAN if successful, otherwise false. |
| 1327 | * PacketTxLen will be updated with the mic'd packets size. |
| 1328 | * |
| 1329 | * Caveats: It is assumed that the frame buffer will already |
| 1330 | * be big enough to hold the largets mic message possible. |
| 1331 | * (No memory allocation is done here). |
| 1332 | * |
| 1333 | * Author: sbraneky (10/15/01) |
| 1334 | * Merciless hacks by rwilcher (1/14/02) |
| 1335 | */ |
| 1336 | |
| 1337 | static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen) |
| 1338 | { |
| 1339 | miccntx *context; |
| 1340 | |
| 1341 | // Determine correct context |
| 1342 | // If not adhoc, always use unicast key |
| 1343 | |
| 1344 | if (test_bit(FLAG_ADHOC, &ai->flags) && (frame->da[0] & 0x1)) |
| 1345 | context = &ai->mod[0].mCtx; |
| 1346 | else |
| 1347 | context = &ai->mod[0].uCtx; |
| 1348 | |
| 1349 | if (!context->valid) |
| 1350 | return ERROR; |
| 1351 | |
| 1352 | mic->typelen = htons(payLen + 16); //Length of Mic'd packet |
| 1353 | |
| 1354 | memcpy(&mic->u.snap, micsnap, sizeof(micsnap)); // Add Snap |
| 1355 | |
| 1356 | // Add Tx sequence |
| 1357 | mic->seq = htonl(context->tx); |
| 1358 | context->tx += 2; |
| 1359 | |
| 1360 | emmh32_init(&context->seed); // Mic the packet |
| 1361 | emmh32_update(&context->seed,frame->da,ETH_ALEN * 2); // DA,SA |
| 1362 | emmh32_update(&context->seed,(u8*)&mic->typelen,10); // Type/Length and Snap |
| 1363 | emmh32_update(&context->seed,(u8*)&mic->seq,sizeof(mic->seq)); //SEQ |
| 1364 | emmh32_update(&context->seed,frame->da + ETH_ALEN * 2,payLen); //payload |
| 1365 | emmh32_final(&context->seed, (u8*)&mic->mic); |
| 1366 | |
| 1367 | /* New Type/length ?????????? */ |
| 1368 | mic->typelen = 0; //Let NIC know it could be an oversized packet |
| 1369 | return SUCCESS; |
| 1370 | } |
| 1371 | |
| 1372 | typedef enum { |
| 1373 | NONE, |
| 1374 | NOMIC, |
| 1375 | NOMICPLUMMED, |
| 1376 | SEQUENCE, |
| 1377 | INCORRECTMIC, |
| 1378 | } mic_error; |
| 1379 | |
| 1380 | /*=========================================================================== |
| 1381 | * Description: Decapsulates a MIC'd packet and returns the 802.3 packet |
| 1382 | * (removes the MIC stuff) if packet is a valid packet. |
| 1383 | * |
| 1384 | * Inputs: etherHead pointer to the 802.3 packet |
| 1385 | * |
| 1386 | * Returns: BOOLEAN - TRUE if packet should be dropped otherwise FALSE |
| 1387 | * |
| 1388 | * Author: sbraneky (10/15/01) |
| 1389 | * Merciless hacks by rwilcher (1/14/02) |
| 1390 | *--------------------------------------------------------------------------- |
| 1391 | */ |
| 1392 | |
| 1393 | static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen) |
| 1394 | { |
| 1395 | int i; |
| 1396 | u32 micSEQ; |
| 1397 | miccntx *context; |
| 1398 | u8 digest[4]; |
| 1399 | mic_error micError = NONE; |
| 1400 | |
| 1401 | // Check if the packet is a Mic'd packet |
| 1402 | |
| 1403 | if (!ai->micstats.enabled) { |
| 1404 | //No Mic set or Mic OFF but we received a MIC'd packet. |
| 1405 | if (memcmp ((u8*)eth + 14, micsnap, sizeof(micsnap)) == 0) { |
| 1406 | ai->micstats.rxMICPlummed++; |
| 1407 | return ERROR; |
| 1408 | } |
| 1409 | return SUCCESS; |
| 1410 | } |
| 1411 | |
| 1412 | if (ntohs(mic->typelen) == 0x888E) |
| 1413 | return SUCCESS; |
| 1414 | |
| 1415 | if (memcmp (mic->u.snap, micsnap, sizeof(micsnap)) != 0) { |
| 1416 | // Mic enabled but packet isn't Mic'd |
| 1417 | ai->micstats.rxMICPlummed++; |
| 1418 | return ERROR; |
| 1419 | } |
| 1420 | |
| 1421 | micSEQ = ntohl(mic->seq); //store SEQ as CPU order |
| 1422 | |
| 1423 | //At this point we a have a mic'd packet and mic is enabled |
| 1424 | //Now do the mic error checking. |
| 1425 | |
| 1426 | //Receive seq must be odd |
| 1427 | if ( (micSEQ & 1) == 0 ) { |
| 1428 | ai->micstats.rxWrongSequence++; |
| 1429 | return ERROR; |
| 1430 | } |
| 1431 | |
| 1432 | for (i = 0; i < NUM_MODULES; i++) { |
| 1433 | int mcast = eth->da[0] & 1; |
| 1434 | //Determine proper context |
| 1435 | context = mcast ? &ai->mod[i].mCtx : &ai->mod[i].uCtx; |
| 1436 | |
| 1437 | //Make sure context is valid |
| 1438 | if (!context->valid) { |
| 1439 | if (i == 0) |
| 1440 | micError = NOMICPLUMMED; |
| 1441 | continue; |
| 1442 | } |
| 1443 | //DeMic it |
| 1444 | |
| 1445 | if (!mic->typelen) |
| 1446 | mic->typelen = htons(payLen + sizeof(MICBuffer) - 2); |
| 1447 | |
| 1448 | emmh32_init(&context->seed); |
| 1449 | emmh32_update(&context->seed, eth->da, ETH_ALEN*2); |
| 1450 | emmh32_update(&context->seed, (u8 *)&mic->typelen, sizeof(mic->typelen)+sizeof(mic->u.snap)); |
| 1451 | emmh32_update(&context->seed, (u8 *)&mic->seq,sizeof(mic->seq)); |
| 1452 | emmh32_update(&context->seed, eth->da + ETH_ALEN*2,payLen); |
| 1453 | //Calculate MIC |
| 1454 | emmh32_final(&context->seed, digest); |
| 1455 | |
| 1456 | if (memcmp(digest, &mic->mic, 4)) { //Make sure the mics match |
| 1457 | //Invalid Mic |
| 1458 | if (i == 0) |
| 1459 | micError = INCORRECTMIC; |
| 1460 | continue; |
| 1461 | } |
| 1462 | |
| 1463 | //Check Sequence number if mics pass |
| 1464 | if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) { |
| 1465 | ai->micstats.rxSuccess++; |
| 1466 | return SUCCESS; |
| 1467 | } |
| 1468 | if (i == 0) |
| 1469 | micError = SEQUENCE; |
| 1470 | } |
| 1471 | |
| 1472 | // Update statistics |
| 1473 | switch (micError) { |
| 1474 | case NOMICPLUMMED: ai->micstats.rxMICPlummed++; break; |
| 1475 | case SEQUENCE: ai->micstats.rxWrongSequence++; break; |
| 1476 | case INCORRECTMIC: ai->micstats.rxIncorrectMIC++; break; |
| 1477 | case NONE: break; |
| 1478 | case NOMIC: break; |
| 1479 | } |
| 1480 | return ERROR; |
| 1481 | } |
| 1482 | |
| 1483 | /*=========================================================================== |
| 1484 | * Description: Checks the Rx Seq number to make sure it is valid |
| 1485 | * and hasn't already been received |
| 1486 | * |
| 1487 | * Inputs: miccntx - mic context to check seq against |
| 1488 | * micSeq - the Mic seq number |
| 1489 | * |
| 1490 | * Returns: TRUE if valid otherwise FALSE. |
| 1491 | * |
| 1492 | * Author: sbraneky (10/15/01) |
| 1493 | * Merciless hacks by rwilcher (1/14/02) |
| 1494 | *--------------------------------------------------------------------------- |
| 1495 | */ |
| 1496 | |
| 1497 | static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq) |
| 1498 | { |
| 1499 | u32 seq,index; |
| 1500 | |
| 1501 | //Allow for the ap being rebooted - if it is then use the next |
| 1502 | //sequence number of the current sequence number - might go backwards |
| 1503 | |
| 1504 | if (mcast) { |
| 1505 | if (test_bit(FLAG_UPDATE_MULTI, &ai->flags)) { |
| 1506 | clear_bit (FLAG_UPDATE_MULTI, &ai->flags); |
| 1507 | context->window = (micSeq > 33) ? micSeq : 33; |
| 1508 | context->rx = 0; // Reset rx |
| 1509 | } |
| 1510 | } else if (test_bit(FLAG_UPDATE_UNI, &ai->flags)) { |
| 1511 | clear_bit (FLAG_UPDATE_UNI, &ai->flags); |
| 1512 | context->window = (micSeq > 33) ? micSeq : 33; // Move window |
| 1513 | context->rx = 0; // Reset rx |
| 1514 | } |
| 1515 | |
| 1516 | //Make sequence number relative to START of window |
| 1517 | seq = micSeq - (context->window - 33); |
| 1518 | |
| 1519 | //Too old of a SEQ number to check. |
| 1520 | if ((s32)seq < 0) |
| 1521 | return ERROR; |
| 1522 | |
| 1523 | if ( seq > 64 ) { |
| 1524 | //Window is infinite forward |
| 1525 | MoveWindow(context,micSeq); |
| 1526 | return SUCCESS; |
| 1527 | } |
| 1528 | |
| 1529 | // We are in the window. Now check the context rx bit to see if it was already sent |
| 1530 | seq >>= 1; //divide by 2 because we only have odd numbers |
| 1531 | index = 1 << seq; //Get an index number |
| 1532 | |
| 1533 | if (!(context->rx & index)) { |
| 1534 | //micSEQ falls inside the window. |
| 1535 | //Add seqence number to the list of received numbers. |
| 1536 | context->rx |= index; |
| 1537 | |
| 1538 | MoveWindow(context,micSeq); |
| 1539 | |
| 1540 | return SUCCESS; |
| 1541 | } |
| 1542 | return ERROR; |
| 1543 | } |
| 1544 | |
| 1545 | static void MoveWindow(miccntx *context, u32 micSeq) |
| 1546 | { |
| 1547 | u32 shift; |
| 1548 | |
| 1549 | //Move window if seq greater than the middle of the window |
| 1550 | if (micSeq > context->window) { |
| 1551 | shift = (micSeq - context->window) >> 1; |
| 1552 | |
| 1553 | //Shift out old |
| 1554 | if (shift < 32) |
| 1555 | context->rx >>= shift; |
| 1556 | else |
| 1557 | context->rx = 0; |
| 1558 | |
| 1559 | context->window = micSeq; //Move window |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | /*==============================================*/ |
| 1564 | /*========== EMMH ROUTINES ====================*/ |
| 1565 | /*==============================================*/ |
| 1566 | |
| 1567 | /* mic accumulate */ |
| 1568 | #define MIC_ACCUM(val) \ |
| 1569 | context->accum += (u64)(val) * context->coeff[coeff_position++]; |
| 1570 | |
| 1571 | static unsigned char aes_counter[16]; |
| 1572 | |
| 1573 | /* expand the key to fill the MMH coefficient array */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1574 | static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | { |
| 1576 | /* take the keying material, expand if necessary, truncate at 16-bytes */ |
| 1577 | /* run through AES counter mode to generate context->coeff[] */ |
| 1578 | |
| 1579 | int i,j; |
| 1580 | u32 counter; |
| 1581 | u8 *cipher, plain[16]; |
| 1582 | struct scatterlist sg[1]; |
| 1583 | |
| 1584 | crypto_cipher_setkey(tfm, pkey, 16); |
| 1585 | counter = 0; |
| 1586 | for (i = 0; i < (sizeof(context->coeff)/sizeof(context->coeff[0])); ) { |
| 1587 | aes_counter[15] = (u8)(counter >> 0); |
| 1588 | aes_counter[14] = (u8)(counter >> 8); |
| 1589 | aes_counter[13] = (u8)(counter >> 16); |
| 1590 | aes_counter[12] = (u8)(counter >> 24); |
| 1591 | counter++; |
| 1592 | memcpy (plain, aes_counter, 16); |
| 1593 | sg[0].page = virt_to_page(plain); |
| 1594 | sg[0].offset = ((long) plain & ~PAGE_MASK); |
| 1595 | sg[0].length = 16; |
| 1596 | crypto_cipher_encrypt(tfm, sg, sg, 16); |
| 1597 | cipher = kmap(sg[0].page) + sg[0].offset; |
| 1598 | for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) { |
| 1599 | context->coeff[i++] = ntohl(*(u32 *)&cipher[j]); |
| 1600 | j += 4; |
| 1601 | } |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | /* prepare for calculation of a new mic */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1606 | static void emmh32_init(emmh32_context *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | { |
| 1608 | /* prepare for new mic calculation */ |
| 1609 | context->accum = 0; |
| 1610 | context->position = 0; |
| 1611 | } |
| 1612 | |
| 1613 | /* add some bytes to the mic calculation */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1614 | static void emmh32_update(emmh32_context *context, u8 *pOctets, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | { |
| 1616 | int coeff_position, byte_position; |
| 1617 | |
| 1618 | if (len == 0) return; |
| 1619 | |
| 1620 | coeff_position = context->position >> 2; |
| 1621 | |
| 1622 | /* deal with partial 32-bit word left over from last update */ |
| 1623 | byte_position = context->position & 3; |
| 1624 | if (byte_position) { |
| 1625 | /* have a partial word in part to deal with */ |
| 1626 | do { |
| 1627 | if (len == 0) return; |
| 1628 | context->part.d8[byte_position++] = *pOctets++; |
| 1629 | context->position++; |
| 1630 | len--; |
| 1631 | } while (byte_position < 4); |
| 1632 | MIC_ACCUM(htonl(context->part.d32)); |
| 1633 | } |
| 1634 | |
| 1635 | /* deal with full 32-bit words */ |
| 1636 | while (len >= 4) { |
| 1637 | MIC_ACCUM(htonl(*(u32 *)pOctets)); |
| 1638 | context->position += 4; |
| 1639 | pOctets += 4; |
| 1640 | len -= 4; |
| 1641 | } |
| 1642 | |
| 1643 | /* deal with partial 32-bit word that will be left over from this update */ |
| 1644 | byte_position = 0; |
| 1645 | while (len > 0) { |
| 1646 | context->part.d8[byte_position++] = *pOctets++; |
| 1647 | context->position++; |
| 1648 | len--; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | /* mask used to zero empty bytes for final partial word */ |
| 1653 | static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L }; |
| 1654 | |
| 1655 | /* calculate the mic */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1656 | static void emmh32_final(emmh32_context *context, u8 digest[4]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | { |
| 1658 | int coeff_position, byte_position; |
| 1659 | u32 val; |
| 1660 | |
| 1661 | u64 sum, utmp; |
| 1662 | s64 stmp; |
| 1663 | |
| 1664 | coeff_position = context->position >> 2; |
| 1665 | |
| 1666 | /* deal with partial 32-bit word left over from last update */ |
| 1667 | byte_position = context->position & 3; |
| 1668 | if (byte_position) { |
| 1669 | /* have a partial word in part to deal with */ |
| 1670 | val = htonl(context->part.d32); |
| 1671 | MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */ |
| 1672 | } |
| 1673 | |
| 1674 | /* reduce the accumulated u64 to a 32-bit MIC */ |
| 1675 | sum = context->accum; |
| 1676 | stmp = (sum & 0xffffffffLL) - ((sum >> 32) * 15); |
| 1677 | utmp = (stmp & 0xffffffffLL) - ((stmp >> 32) * 15); |
| 1678 | sum = utmp & 0xffffffffLL; |
| 1679 | if (utmp > 0x10000000fLL) |
| 1680 | sum -= 15; |
| 1681 | |
| 1682 | val = (u32)sum; |
| 1683 | digest[0] = (val>>24) & 0xFF; |
| 1684 | digest[1] = (val>>16) & 0xFF; |
| 1685 | digest[2] = (val>>8) & 0xFF; |
| 1686 | digest[3] = val & 0xFF; |
| 1687 | } |
| 1688 | #endif |
| 1689 | |
| 1690 | static int readBSSListRid(struct airo_info *ai, int first, |
| 1691 | BSSListRid *list) { |
| 1692 | int rc; |
| 1693 | Cmd cmd; |
| 1694 | Resp rsp; |
| 1695 | |
| 1696 | if (first == 1) { |
| 1697 | if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN; |
| 1698 | memset(&cmd, 0, sizeof(cmd)); |
| 1699 | cmd.cmd=CMD_LISTBSS; |
| 1700 | if (down_interruptible(&ai->sem)) |
| 1701 | return -ERESTARTSYS; |
| 1702 | issuecommand(ai, &cmd, &rsp); |
| 1703 | up(&ai->sem); |
| 1704 | /* Let the command take effect */ |
| 1705 | ai->task = current; |
| 1706 | ssleep(3); |
| 1707 | ai->task = NULL; |
| 1708 | } |
| 1709 | rc = PC4500_readrid(ai, first ? RID_BSSLISTFIRST : RID_BSSLISTNEXT, |
| 1710 | list, sizeof(*list), 1); |
| 1711 | |
| 1712 | list->len = le16_to_cpu(list->len); |
| 1713 | list->index = le16_to_cpu(list->index); |
| 1714 | list->radioType = le16_to_cpu(list->radioType); |
| 1715 | list->cap = le16_to_cpu(list->cap); |
| 1716 | list->beaconInterval = le16_to_cpu(list->beaconInterval); |
| 1717 | list->fh.dwell = le16_to_cpu(list->fh.dwell); |
| 1718 | list->dsChannel = le16_to_cpu(list->dsChannel); |
| 1719 | list->atimWindow = le16_to_cpu(list->atimWindow); |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 1720 | list->dBm = le16_to_cpu(list->dBm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | return rc; |
| 1722 | } |
| 1723 | |
| 1724 | static int readWepKeyRid(struct airo_info*ai, WepKeyRid *wkr, int temp, int lock) { |
| 1725 | int rc = PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM, |
| 1726 | wkr, sizeof(*wkr), lock); |
| 1727 | |
| 1728 | wkr->len = le16_to_cpu(wkr->len); |
| 1729 | wkr->kindex = le16_to_cpu(wkr->kindex); |
| 1730 | wkr->klen = le16_to_cpu(wkr->klen); |
| 1731 | return rc; |
| 1732 | } |
| 1733 | /* In the writeXXXRid routines we copy the rids so that we don't screwup |
| 1734 | * the originals when we endian them... */ |
| 1735 | static int writeWepKeyRid(struct airo_info*ai, WepKeyRid *pwkr, int perm, int lock) { |
| 1736 | int rc; |
| 1737 | WepKeyRid wkr = *pwkr; |
| 1738 | |
| 1739 | wkr.len = cpu_to_le16(wkr.len); |
| 1740 | wkr.kindex = cpu_to_le16(wkr.kindex); |
| 1741 | wkr.klen = cpu_to_le16(wkr.klen); |
| 1742 | rc = PC4500_writerid(ai, RID_WEP_TEMP, &wkr, sizeof(wkr), lock); |
| 1743 | if (rc!=SUCCESS) printk(KERN_ERR "airo: WEP_TEMP set %x\n", rc); |
| 1744 | if (perm) { |
| 1745 | rc = PC4500_writerid(ai, RID_WEP_PERM, &wkr, sizeof(wkr), lock); |
| 1746 | if (rc!=SUCCESS) { |
| 1747 | printk(KERN_ERR "airo: WEP_PERM set %x\n", rc); |
| 1748 | } |
| 1749 | } |
| 1750 | return rc; |
| 1751 | } |
| 1752 | |
| 1753 | static int readSsidRid(struct airo_info*ai, SsidRid *ssidr) { |
| 1754 | int i; |
| 1755 | int rc = PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1); |
| 1756 | |
| 1757 | ssidr->len = le16_to_cpu(ssidr->len); |
| 1758 | for(i = 0; i < 3; i++) { |
| 1759 | ssidr->ssids[i].len = le16_to_cpu(ssidr->ssids[i].len); |
| 1760 | } |
| 1761 | return rc; |
| 1762 | } |
| 1763 | static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock) { |
| 1764 | int rc; |
| 1765 | int i; |
| 1766 | SsidRid ssidr = *pssidr; |
| 1767 | |
| 1768 | ssidr.len = cpu_to_le16(ssidr.len); |
| 1769 | for(i = 0; i < 3; i++) { |
| 1770 | ssidr.ssids[i].len = cpu_to_le16(ssidr.ssids[i].len); |
| 1771 | } |
| 1772 | rc = PC4500_writerid(ai, RID_SSID, &ssidr, sizeof(ssidr), lock); |
| 1773 | return rc; |
| 1774 | } |
| 1775 | static int readConfigRid(struct airo_info*ai, int lock) { |
| 1776 | int rc; |
| 1777 | u16 *s; |
| 1778 | ConfigRid cfg; |
| 1779 | |
| 1780 | if (ai->config.len) |
| 1781 | return SUCCESS; |
| 1782 | |
| 1783 | rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock); |
| 1784 | if (rc != SUCCESS) |
| 1785 | return rc; |
| 1786 | |
| 1787 | for(s = &cfg.len; s <= &cfg.rtsThres; s++) *s = le16_to_cpu(*s); |
| 1788 | |
| 1789 | for(s = &cfg.shortRetryLimit; s <= &cfg.radioType; s++) |
| 1790 | *s = le16_to_cpu(*s); |
| 1791 | |
| 1792 | for(s = &cfg.txPower; s <= &cfg.radioSpecific; s++) |
| 1793 | *s = le16_to_cpu(*s); |
| 1794 | |
| 1795 | for(s = &cfg.arlThreshold; s <= &cfg._reserved4[0]; s++) |
| 1796 | *s = cpu_to_le16(*s); |
| 1797 | |
| 1798 | for(s = &cfg.autoWake; s <= &cfg.autoWake; s++) |
| 1799 | *s = cpu_to_le16(*s); |
| 1800 | |
| 1801 | ai->config = cfg; |
| 1802 | return SUCCESS; |
| 1803 | } |
| 1804 | static inline void checkThrottle(struct airo_info *ai) { |
| 1805 | int i; |
| 1806 | /* Old hardware had a limit on encryption speed */ |
| 1807 | if (ai->config.authType != AUTH_OPEN && maxencrypt) { |
| 1808 | for(i=0; i<8; i++) { |
| 1809 | if (ai->config.rates[i] > maxencrypt) { |
| 1810 | ai->config.rates[i] = 0; |
| 1811 | } |
| 1812 | } |
| 1813 | } |
| 1814 | } |
| 1815 | static int writeConfigRid(struct airo_info*ai, int lock) { |
| 1816 | u16 *s; |
| 1817 | ConfigRid cfgr; |
| 1818 | |
| 1819 | if (!test_bit (FLAG_COMMIT, &ai->flags)) |
| 1820 | return SUCCESS; |
| 1821 | |
| 1822 | clear_bit (FLAG_COMMIT, &ai->flags); |
| 1823 | clear_bit (FLAG_RESET, &ai->flags); |
| 1824 | checkThrottle(ai); |
| 1825 | cfgr = ai->config; |
| 1826 | |
| 1827 | if ((cfgr.opmode & 0xFF) == MODE_STA_IBSS) |
| 1828 | set_bit(FLAG_ADHOC, &ai->flags); |
| 1829 | else |
| 1830 | clear_bit(FLAG_ADHOC, &ai->flags); |
| 1831 | |
| 1832 | for(s = &cfgr.len; s <= &cfgr.rtsThres; s++) *s = cpu_to_le16(*s); |
| 1833 | |
| 1834 | for(s = &cfgr.shortRetryLimit; s <= &cfgr.radioType; s++) |
| 1835 | *s = cpu_to_le16(*s); |
| 1836 | |
| 1837 | for(s = &cfgr.txPower; s <= &cfgr.radioSpecific; s++) |
| 1838 | *s = cpu_to_le16(*s); |
| 1839 | |
| 1840 | for(s = &cfgr.arlThreshold; s <= &cfgr._reserved4[0]; s++) |
| 1841 | *s = cpu_to_le16(*s); |
| 1842 | |
| 1843 | for(s = &cfgr.autoWake; s <= &cfgr.autoWake; s++) |
| 1844 | *s = cpu_to_le16(*s); |
| 1845 | |
| 1846 | return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock); |
| 1847 | } |
| 1848 | static int readStatusRid(struct airo_info*ai, StatusRid *statr, int lock) { |
| 1849 | int rc = PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock); |
| 1850 | u16 *s; |
| 1851 | |
| 1852 | statr->len = le16_to_cpu(statr->len); |
| 1853 | for(s = &statr->mode; s <= &statr->SSIDlen; s++) *s = le16_to_cpu(*s); |
| 1854 | |
| 1855 | for(s = &statr->beaconPeriod; s <= &statr->shortPreamble; s++) |
| 1856 | *s = le16_to_cpu(*s); |
| 1857 | statr->load = le16_to_cpu(statr->load); |
| 1858 | statr->assocStatus = le16_to_cpu(statr->assocStatus); |
| 1859 | return rc; |
| 1860 | } |
| 1861 | static int readAPListRid(struct airo_info*ai, APListRid *aplr) { |
| 1862 | int rc = PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1); |
| 1863 | aplr->len = le16_to_cpu(aplr->len); |
| 1864 | return rc; |
| 1865 | } |
| 1866 | static int writeAPListRid(struct airo_info*ai, APListRid *aplr, int lock) { |
| 1867 | int rc; |
| 1868 | aplr->len = cpu_to_le16(aplr->len); |
| 1869 | rc = PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock); |
| 1870 | return rc; |
| 1871 | } |
| 1872 | static int readCapabilityRid(struct airo_info*ai, CapabilityRid *capr, int lock) { |
| 1873 | int rc = PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock); |
| 1874 | u16 *s; |
| 1875 | |
| 1876 | capr->len = le16_to_cpu(capr->len); |
| 1877 | capr->prodNum = le16_to_cpu(capr->prodNum); |
| 1878 | capr->radioType = le16_to_cpu(capr->radioType); |
| 1879 | capr->country = le16_to_cpu(capr->country); |
| 1880 | for(s = &capr->txPowerLevels[0]; s <= &capr->requiredHard; s++) |
| 1881 | *s = le16_to_cpu(*s); |
| 1882 | return rc; |
| 1883 | } |
| 1884 | static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock) { |
| 1885 | int rc = PC4500_readrid(ai, rid, sr, sizeof(*sr), lock); |
| 1886 | u32 *i; |
| 1887 | |
| 1888 | sr->len = le16_to_cpu(sr->len); |
| 1889 | for(i = &sr->vals[0]; i <= &sr->vals[99]; i++) *i = le32_to_cpu(*i); |
| 1890 | return rc; |
| 1891 | } |
| 1892 | |
| 1893 | static int airo_open(struct net_device *dev) { |
| 1894 | struct airo_info *info = dev->priv; |
| 1895 | Resp rsp; |
| 1896 | |
| 1897 | if (test_bit(FLAG_FLASHING, &info->flags)) |
| 1898 | return -EIO; |
| 1899 | |
| 1900 | /* Make sure the card is configured. |
| 1901 | * Wireless Extensions may postpone config changes until the card |
| 1902 | * is open (to pipeline changes and speed-up card setup). If |
| 1903 | * those changes are not yet commited, do it now - Jean II */ |
| 1904 | if (test_bit (FLAG_COMMIT, &info->flags)) { |
| 1905 | disable_MAC(info, 1); |
| 1906 | writeConfigRid(info, 1); |
| 1907 | } |
| 1908 | |
| 1909 | if (info->wifidev != dev) { |
| 1910 | /* Power on the MAC controller (which may have been disabled) */ |
| 1911 | clear_bit(FLAG_RADIO_DOWN, &info->flags); |
| 1912 | enable_interrupts(info); |
| 1913 | } |
| 1914 | enable_MAC(info, &rsp, 1); |
| 1915 | |
| 1916 | netif_start_queue(dev); |
| 1917 | return 0; |
| 1918 | } |
| 1919 | |
| 1920 | static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) { |
| 1921 | int npacks, pending; |
| 1922 | unsigned long flags; |
| 1923 | struct airo_info *ai = dev->priv; |
| 1924 | |
| 1925 | if (!skb) { |
| 1926 | printk(KERN_ERR "airo: %s: skb==NULL\n",__FUNCTION__); |
| 1927 | return 0; |
| 1928 | } |
| 1929 | npacks = skb_queue_len (&ai->txq); |
| 1930 | |
| 1931 | if (npacks >= MAXTXQ - 1) { |
| 1932 | netif_stop_queue (dev); |
| 1933 | if (npacks > MAXTXQ) { |
| 1934 | ai->stats.tx_fifo_errors++; |
| 1935 | return 1; |
| 1936 | } |
| 1937 | skb_queue_tail (&ai->txq, skb); |
| 1938 | return 0; |
| 1939 | } |
| 1940 | |
| 1941 | spin_lock_irqsave(&ai->aux_lock, flags); |
| 1942 | skb_queue_tail (&ai->txq, skb); |
| 1943 | pending = test_bit(FLAG_PENDING_XMIT, &ai->flags); |
| 1944 | spin_unlock_irqrestore(&ai->aux_lock,flags); |
| 1945 | netif_wake_queue (dev); |
| 1946 | |
| 1947 | if (pending == 0) { |
| 1948 | set_bit(FLAG_PENDING_XMIT, &ai->flags); |
| 1949 | mpi_send_packet (dev); |
| 1950 | } |
| 1951 | return 0; |
| 1952 | } |
| 1953 | |
| 1954 | /* |
| 1955 | * @mpi_send_packet |
| 1956 | * |
| 1957 | * Attempt to transmit a packet. Can be called from interrupt |
| 1958 | * or transmit . return number of packets we tried to send |
| 1959 | */ |
| 1960 | |
| 1961 | static int mpi_send_packet (struct net_device *dev) |
| 1962 | { |
| 1963 | struct sk_buff *skb; |
| 1964 | unsigned char *buffer; |
| 1965 | s16 len, *payloadLen; |
| 1966 | struct airo_info *ai = dev->priv; |
| 1967 | u8 *sendbuf; |
| 1968 | |
| 1969 | /* get a packet to send */ |
| 1970 | |
| 1971 | if ((skb = skb_dequeue(&ai->txq)) == 0) { |
| 1972 | printk (KERN_ERR |
| 1973 | "airo: %s: Dequeue'd zero in send_packet()\n", |
| 1974 | __FUNCTION__); |
| 1975 | return 0; |
| 1976 | } |
| 1977 | |
| 1978 | /* check min length*/ |
| 1979 | len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; |
| 1980 | buffer = skb->data; |
| 1981 | |
| 1982 | ai->txfids[0].tx_desc.offset = 0; |
| 1983 | ai->txfids[0].tx_desc.valid = 1; |
| 1984 | ai->txfids[0].tx_desc.eoc = 1; |
| 1985 | ai->txfids[0].tx_desc.len =len+sizeof(WifiHdr); |
| 1986 | |
| 1987 | /* |
| 1988 | * Magic, the cards firmware needs a length count (2 bytes) in the host buffer |
| 1989 | * right after TXFID_HDR.The TXFID_HDR contains the status short so payloadlen |
| 1990 | * is immediatly after it. ------------------------------------------------ |
| 1991 | * |TXFIDHDR+STATUS|PAYLOADLEN|802.3HDR|PACKETDATA| |
| 1992 | * ------------------------------------------------ |
| 1993 | */ |
| 1994 | |
| 1995 | memcpy((char *)ai->txfids[0].virtual_host_addr, |
| 1996 | (char *)&wifictlhdr8023, sizeof(wifictlhdr8023)); |
| 1997 | |
| 1998 | payloadLen = (s16 *)(ai->txfids[0].virtual_host_addr + |
| 1999 | sizeof(wifictlhdr8023)); |
| 2000 | sendbuf = ai->txfids[0].virtual_host_addr + |
| 2001 | sizeof(wifictlhdr8023) + 2 ; |
| 2002 | |
| 2003 | /* |
| 2004 | * Firmware automaticly puts 802 header on so |
| 2005 | * we don't need to account for it in the length |
| 2006 | */ |
| 2007 | #ifdef MICSUPPORT |
| 2008 | if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled && |
| 2009 | (ntohs(((u16 *)buffer)[6]) != 0x888E)) { |
| 2010 | MICBuffer pMic; |
| 2011 | |
| 2012 | if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS) |
| 2013 | return ERROR; |
| 2014 | |
| 2015 | *payloadLen = cpu_to_le16(len-sizeof(etherHead)+sizeof(pMic)); |
| 2016 | ai->txfids[0].tx_desc.len += sizeof(pMic); |
| 2017 | /* copy data into airo dma buffer */ |
| 2018 | memcpy (sendbuf, buffer, sizeof(etherHead)); |
| 2019 | buffer += sizeof(etherHead); |
| 2020 | sendbuf += sizeof(etherHead); |
| 2021 | memcpy (sendbuf, &pMic, sizeof(pMic)); |
| 2022 | sendbuf += sizeof(pMic); |
| 2023 | memcpy (sendbuf, buffer, len - sizeof(etherHead)); |
| 2024 | } else |
| 2025 | #endif |
| 2026 | { |
| 2027 | *payloadLen = cpu_to_le16(len - sizeof(etherHead)); |
| 2028 | |
| 2029 | dev->trans_start = jiffies; |
| 2030 | |
| 2031 | /* copy data into airo dma buffer */ |
| 2032 | memcpy(sendbuf, buffer, len); |
| 2033 | } |
| 2034 | |
| 2035 | memcpy_toio(ai->txfids[0].card_ram_off, |
| 2036 | &ai->txfids[0].tx_desc, sizeof(TxFid)); |
| 2037 | |
| 2038 | OUT4500(ai, EVACK, 8); |
| 2039 | |
| 2040 | dev_kfree_skb_any(skb); |
| 2041 | return 1; |
| 2042 | } |
| 2043 | |
| 2044 | static void get_tx_error(struct airo_info *ai, u32 fid) |
| 2045 | { |
| 2046 | u16 status; |
| 2047 | |
| 2048 | if (fid < 0) |
| 2049 | status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status; |
| 2050 | else { |
| 2051 | if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) != SUCCESS) |
| 2052 | return; |
| 2053 | bap_read(ai, &status, 2, BAP0); |
| 2054 | } |
| 2055 | if (le16_to_cpu(status) & 2) /* Too many retries */ |
| 2056 | ai->stats.tx_aborted_errors++; |
| 2057 | if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */ |
| 2058 | ai->stats.tx_heartbeat_errors++; |
| 2059 | if (le16_to_cpu(status) & 8) /* Aid fail */ |
| 2060 | { } |
| 2061 | if (le16_to_cpu(status) & 0x10) /* MAC disabled */ |
| 2062 | ai->stats.tx_carrier_errors++; |
| 2063 | if (le16_to_cpu(status) & 0x20) /* Association lost */ |
| 2064 | { } |
| 2065 | /* We produce a TXDROP event only for retry or lifetime |
| 2066 | * exceeded, because that's the only status that really mean |
| 2067 | * that this particular node went away. |
| 2068 | * Other errors means that *we* screwed up. - Jean II */ |
| 2069 | if ((le16_to_cpu(status) & 2) || |
| 2070 | (le16_to_cpu(status) & 4)) { |
| 2071 | union iwreq_data wrqu; |
| 2072 | char junk[0x18]; |
| 2073 | |
| 2074 | /* Faster to skip over useless data than to do |
| 2075 | * another bap_setup(). We are at offset 0x6 and |
| 2076 | * need to go to 0x18 and read 6 bytes - Jean II */ |
| 2077 | bap_read(ai, (u16 *) junk, 0x18, BAP0); |
| 2078 | |
| 2079 | /* Copy 802.11 dest address. |
| 2080 | * We use the 802.11 header because the frame may |
| 2081 | * not be 802.3 or may be mangled... |
| 2082 | * In Ad-Hoc mode, it will be the node address. |
| 2083 | * In managed mode, it will be most likely the AP addr |
| 2084 | * User space will figure out how to convert it to |
| 2085 | * whatever it needs (IP address or else). |
| 2086 | * - Jean II */ |
| 2087 | memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN); |
| 2088 | wrqu.addr.sa_family = ARPHRD_ETHER; |
| 2089 | |
| 2090 | /* Send event to user space */ |
| 2091 | wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL); |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | static void airo_end_xmit(struct net_device *dev) { |
| 2096 | u16 status; |
| 2097 | int i; |
| 2098 | struct airo_info *priv = dev->priv; |
| 2099 | struct sk_buff *skb = priv->xmit.skb; |
| 2100 | int fid = priv->xmit.fid; |
| 2101 | u32 *fids = priv->fids; |
| 2102 | |
| 2103 | clear_bit(JOB_XMIT, &priv->flags); |
| 2104 | clear_bit(FLAG_PENDING_XMIT, &priv->flags); |
| 2105 | status = transmit_802_3_packet (priv, fids[fid], skb->data); |
| 2106 | up(&priv->sem); |
| 2107 | |
| 2108 | i = 0; |
| 2109 | if ( status == SUCCESS ) { |
| 2110 | dev->trans_start = jiffies; |
| 2111 | for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++); |
| 2112 | } else { |
| 2113 | priv->fids[fid] &= 0xffff; |
| 2114 | priv->stats.tx_window_errors++; |
| 2115 | } |
| 2116 | if (i < MAX_FIDS / 2) |
| 2117 | netif_wake_queue(dev); |
| 2118 | dev_kfree_skb(skb); |
| 2119 | } |
| 2120 | |
| 2121 | static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) { |
| 2122 | s16 len; |
| 2123 | int i, j; |
| 2124 | struct airo_info *priv = dev->priv; |
| 2125 | u32 *fids = priv->fids; |
| 2126 | |
| 2127 | if ( skb == NULL ) { |
| 2128 | printk( KERN_ERR "airo: skb == NULL!!!\n" ); |
| 2129 | return 0; |
| 2130 | } |
| 2131 | |
| 2132 | /* Find a vacant FID */ |
| 2133 | for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ ); |
| 2134 | for( j = i + 1; j < MAX_FIDS / 2 && (fids[j] & 0xffff0000); j++ ); |
| 2135 | |
| 2136 | if ( j >= MAX_FIDS / 2 ) { |
| 2137 | netif_stop_queue(dev); |
| 2138 | |
| 2139 | if (i == MAX_FIDS / 2) { |
| 2140 | priv->stats.tx_fifo_errors++; |
| 2141 | return 1; |
| 2142 | } |
| 2143 | } |
| 2144 | /* check min length*/ |
| 2145 | len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; |
| 2146 | /* Mark fid as used & save length for later */ |
| 2147 | fids[i] |= (len << 16); |
| 2148 | priv->xmit.skb = skb; |
| 2149 | priv->xmit.fid = i; |
| 2150 | if (down_trylock(&priv->sem) != 0) { |
| 2151 | set_bit(FLAG_PENDING_XMIT, &priv->flags); |
| 2152 | netif_stop_queue(dev); |
| 2153 | set_bit(JOB_XMIT, &priv->flags); |
| 2154 | wake_up_interruptible(&priv->thr_wait); |
| 2155 | } else |
| 2156 | airo_end_xmit(dev); |
| 2157 | return 0; |
| 2158 | } |
| 2159 | |
| 2160 | static void airo_end_xmit11(struct net_device *dev) { |
| 2161 | u16 status; |
| 2162 | int i; |
| 2163 | struct airo_info *priv = dev->priv; |
| 2164 | struct sk_buff *skb = priv->xmit11.skb; |
| 2165 | int fid = priv->xmit11.fid; |
| 2166 | u32 *fids = priv->fids; |
| 2167 | |
| 2168 | clear_bit(JOB_XMIT11, &priv->flags); |
| 2169 | clear_bit(FLAG_PENDING_XMIT11, &priv->flags); |
| 2170 | status = transmit_802_11_packet (priv, fids[fid], skb->data); |
| 2171 | up(&priv->sem); |
| 2172 | |
| 2173 | i = MAX_FIDS / 2; |
| 2174 | if ( status == SUCCESS ) { |
| 2175 | dev->trans_start = jiffies; |
| 2176 | for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++); |
| 2177 | } else { |
| 2178 | priv->fids[fid] &= 0xffff; |
| 2179 | priv->stats.tx_window_errors++; |
| 2180 | } |
| 2181 | if (i < MAX_FIDS) |
| 2182 | netif_wake_queue(dev); |
| 2183 | dev_kfree_skb(skb); |
| 2184 | } |
| 2185 | |
| 2186 | static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) { |
| 2187 | s16 len; |
| 2188 | int i, j; |
| 2189 | struct airo_info *priv = dev->priv; |
| 2190 | u32 *fids = priv->fids; |
| 2191 | |
| 2192 | if (test_bit(FLAG_MPI, &priv->flags)) { |
| 2193 | /* Not implemented yet for MPI350 */ |
| 2194 | netif_stop_queue(dev); |
| 2195 | return -ENETDOWN; |
| 2196 | } |
| 2197 | |
| 2198 | if ( skb == NULL ) { |
| 2199 | printk( KERN_ERR "airo: skb == NULL!!!\n" ); |
| 2200 | return 0; |
| 2201 | } |
| 2202 | |
| 2203 | /* Find a vacant FID */ |
| 2204 | for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ ); |
| 2205 | for( j = i + 1; j < MAX_FIDS && (fids[j] & 0xffff0000); j++ ); |
| 2206 | |
| 2207 | if ( j >= MAX_FIDS ) { |
| 2208 | netif_stop_queue(dev); |
| 2209 | |
| 2210 | if (i == MAX_FIDS) { |
| 2211 | priv->stats.tx_fifo_errors++; |
| 2212 | return 1; |
| 2213 | } |
| 2214 | } |
| 2215 | /* check min length*/ |
| 2216 | len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; |
| 2217 | /* Mark fid as used & save length for later */ |
| 2218 | fids[i] |= (len << 16); |
| 2219 | priv->xmit11.skb = skb; |
| 2220 | priv->xmit11.fid = i; |
| 2221 | if (down_trylock(&priv->sem) != 0) { |
| 2222 | set_bit(FLAG_PENDING_XMIT11, &priv->flags); |
| 2223 | netif_stop_queue(dev); |
| 2224 | set_bit(JOB_XMIT11, &priv->flags); |
| 2225 | wake_up_interruptible(&priv->thr_wait); |
| 2226 | } else |
| 2227 | airo_end_xmit11(dev); |
| 2228 | return 0; |
| 2229 | } |
| 2230 | |
| 2231 | static void airo_read_stats(struct airo_info *ai) { |
| 2232 | StatsRid stats_rid; |
| 2233 | u32 *vals = stats_rid.vals; |
| 2234 | |
| 2235 | clear_bit(JOB_STATS, &ai->flags); |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 2236 | if (ai->power.event) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | up(&ai->sem); |
| 2238 | return; |
| 2239 | } |
| 2240 | readStatsRid(ai, &stats_rid, RID_STATS, 0); |
| 2241 | up(&ai->sem); |
| 2242 | |
| 2243 | ai->stats.rx_packets = vals[43] + vals[44] + vals[45]; |
| 2244 | ai->stats.tx_packets = vals[39] + vals[40] + vals[41]; |
| 2245 | ai->stats.rx_bytes = vals[92]; |
| 2246 | ai->stats.tx_bytes = vals[91]; |
| 2247 | ai->stats.rx_errors = vals[0] + vals[2] + vals[3] + vals[4]; |
| 2248 | ai->stats.tx_errors = vals[42] + ai->stats.tx_fifo_errors; |
| 2249 | ai->stats.multicast = vals[43]; |
| 2250 | ai->stats.collisions = vals[89]; |
| 2251 | |
| 2252 | /* detailed rx_errors: */ |
| 2253 | ai->stats.rx_length_errors = vals[3]; |
| 2254 | ai->stats.rx_crc_errors = vals[4]; |
| 2255 | ai->stats.rx_frame_errors = vals[2]; |
| 2256 | ai->stats.rx_fifo_errors = vals[0]; |
| 2257 | } |
| 2258 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 2259 | static struct net_device_stats *airo_get_stats(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | { |
| 2261 | struct airo_info *local = dev->priv; |
| 2262 | |
| 2263 | if (!test_bit(JOB_STATS, &local->flags)) { |
| 2264 | /* Get stats out of the card if available */ |
| 2265 | if (down_trylock(&local->sem) != 0) { |
| 2266 | set_bit(JOB_STATS, &local->flags); |
| 2267 | wake_up_interruptible(&local->thr_wait); |
| 2268 | } else |
| 2269 | airo_read_stats(local); |
| 2270 | } |
| 2271 | |
| 2272 | return &local->stats; |
| 2273 | } |
| 2274 | |
| 2275 | static void airo_set_promisc(struct airo_info *ai) { |
| 2276 | Cmd cmd; |
| 2277 | Resp rsp; |
| 2278 | |
| 2279 | memset(&cmd, 0, sizeof(cmd)); |
| 2280 | cmd.cmd=CMD_SETMODE; |
| 2281 | clear_bit(JOB_PROMISC, &ai->flags); |
| 2282 | cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC; |
| 2283 | issuecommand(ai, &cmd, &rsp); |
| 2284 | up(&ai->sem); |
| 2285 | } |
| 2286 | |
| 2287 | static void airo_set_multicast_list(struct net_device *dev) { |
| 2288 | struct airo_info *ai = dev->priv; |
| 2289 | |
| 2290 | if ((dev->flags ^ ai->flags) & IFF_PROMISC) { |
| 2291 | change_bit(FLAG_PROMISC, &ai->flags); |
| 2292 | if (down_trylock(&ai->sem) != 0) { |
| 2293 | set_bit(JOB_PROMISC, &ai->flags); |
| 2294 | wake_up_interruptible(&ai->thr_wait); |
| 2295 | } else |
| 2296 | airo_set_promisc(ai); |
| 2297 | } |
| 2298 | |
| 2299 | if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) { |
| 2300 | /* Turn on multicast. (Should be already setup...) */ |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | static int airo_set_mac_address(struct net_device *dev, void *p) |
| 2305 | { |
| 2306 | struct airo_info *ai = dev->priv; |
| 2307 | struct sockaddr *addr = p; |
| 2308 | Resp rsp; |
| 2309 | |
| 2310 | readConfigRid(ai, 1); |
| 2311 | memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len); |
| 2312 | set_bit (FLAG_COMMIT, &ai->flags); |
| 2313 | disable_MAC(ai, 1); |
| 2314 | writeConfigRid (ai, 1); |
| 2315 | enable_MAC(ai, &rsp, 1); |
| 2316 | memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len); |
| 2317 | if (ai->wifidev) |
| 2318 | memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len); |
| 2319 | return 0; |
| 2320 | } |
| 2321 | |
| 2322 | static int airo_change_mtu(struct net_device *dev, int new_mtu) |
| 2323 | { |
| 2324 | if ((new_mtu < 68) || (new_mtu > 2400)) |
| 2325 | return -EINVAL; |
| 2326 | dev->mtu = new_mtu; |
| 2327 | return 0; |
| 2328 | } |
| 2329 | |
| 2330 | |
| 2331 | static int airo_close(struct net_device *dev) { |
| 2332 | struct airo_info *ai = dev->priv; |
| 2333 | |
| 2334 | netif_stop_queue(dev); |
| 2335 | |
| 2336 | if (ai->wifidev != dev) { |
| 2337 | #ifdef POWER_ON_DOWN |
| 2338 | /* Shut power to the card. The idea is that the user can save |
| 2339 | * power when he doesn't need the card with "ifconfig down". |
| 2340 | * That's the method that is most friendly towards the network |
| 2341 | * stack (i.e. the network stack won't try to broadcast |
| 2342 | * anything on the interface and routes are gone. Jean II */ |
| 2343 | set_bit(FLAG_RADIO_DOWN, &ai->flags); |
| 2344 | disable_MAC(ai, 1); |
| 2345 | #endif |
| 2346 | disable_interrupts( ai ); |
| 2347 | } |
| 2348 | return 0; |
| 2349 | } |
| 2350 | |
| 2351 | static void del_airo_dev( struct net_device *dev ); |
| 2352 | |
| 2353 | void stop_airo_card( struct net_device *dev, int freeres ) |
| 2354 | { |
| 2355 | struct airo_info *ai = dev->priv; |
| 2356 | |
| 2357 | set_bit(FLAG_RADIO_DOWN, &ai->flags); |
| 2358 | disable_MAC(ai, 1); |
| 2359 | disable_interrupts(ai); |
| 2360 | free_irq( dev->irq, dev ); |
| 2361 | takedown_proc_entry( dev, ai ); |
| 2362 | if (test_bit(FLAG_REGISTERED, &ai->flags)) { |
| 2363 | unregister_netdev( dev ); |
| 2364 | if (ai->wifidev) { |
| 2365 | unregister_netdev(ai->wifidev); |
| 2366 | free_netdev(ai->wifidev); |
| 2367 | ai->wifidev = NULL; |
| 2368 | } |
| 2369 | clear_bit(FLAG_REGISTERED, &ai->flags); |
| 2370 | } |
| 2371 | set_bit(JOB_DIE, &ai->flags); |
| 2372 | kill_proc(ai->thr_pid, SIGTERM, 1); |
| 2373 | wait_for_completion(&ai->thr_exited); |
| 2374 | |
| 2375 | /* |
| 2376 | * Clean out tx queue |
| 2377 | */ |
David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 2378 | if (test_bit(FLAG_MPI, &ai->flags) && !skb_queue_empty(&ai->txq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | struct sk_buff *skb = NULL; |
| 2380 | for (;(skb = skb_dequeue(&ai->txq));) |
| 2381 | dev_kfree_skb(skb); |
| 2382 | } |
| 2383 | |
| 2384 | if (ai->flash) |
| 2385 | kfree(ai->flash); |
| 2386 | if (ai->rssi) |
| 2387 | kfree(ai->rssi); |
| 2388 | if (ai->APList) |
| 2389 | kfree(ai->APList); |
| 2390 | if (ai->SSID) |
| 2391 | kfree(ai->SSID); |
| 2392 | if (freeres) { |
| 2393 | /* PCMCIA frees this stuff, so only for PCI and ISA */ |
| 2394 | release_region( dev->base_addr, 64 ); |
| 2395 | if (test_bit(FLAG_MPI, &ai->flags)) { |
| 2396 | if (ai->pci) |
| 2397 | mpi_unmap_card(ai->pci); |
| 2398 | if (ai->pcimem) |
| 2399 | iounmap(ai->pcimem); |
| 2400 | if (ai->pciaux) |
| 2401 | iounmap(ai->pciaux); |
| 2402 | pci_free_consistent(ai->pci, PCI_SHARED_LEN, |
| 2403 | ai->shared, ai->shared_dma); |
| 2404 | } |
| 2405 | } |
| 2406 | #ifdef MICSUPPORT |
Jesper Juhl | 573dbd9 | 2005-09-01 17:44:29 -0700 | [diff] [blame] | 2407 | crypto_free_tfm(ai->tfm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | #endif |
| 2409 | del_airo_dev( dev ); |
| 2410 | free_netdev( dev ); |
| 2411 | } |
| 2412 | |
| 2413 | EXPORT_SYMBOL(stop_airo_card); |
| 2414 | |
| 2415 | static int add_airo_dev( struct net_device *dev ); |
| 2416 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 2417 | static int wll_header_parse(struct sk_buff *skb, unsigned char *haddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | { |
| 2419 | memcpy(haddr, skb->mac.raw + 10, ETH_ALEN); |
| 2420 | return ETH_ALEN; |
| 2421 | } |
| 2422 | |
| 2423 | static void mpi_unmap_card(struct pci_dev *pci) |
| 2424 | { |
| 2425 | unsigned long mem_start = pci_resource_start(pci, 1); |
| 2426 | unsigned long mem_len = pci_resource_len(pci, 1); |
| 2427 | unsigned long aux_start = pci_resource_start(pci, 2); |
| 2428 | unsigned long aux_len = AUXMEMSIZE; |
| 2429 | |
| 2430 | release_mem_region(aux_start, aux_len); |
| 2431 | release_mem_region(mem_start, mem_len); |
| 2432 | } |
| 2433 | |
| 2434 | /************************************************************* |
| 2435 | * This routine assumes that descriptors have been setup . |
| 2436 | * Run at insmod time or after reset when the decriptors |
| 2437 | * have been initialized . Returns 0 if all is well nz |
| 2438 | * otherwise . Does not allocate memory but sets up card |
| 2439 | * using previously allocated descriptors. |
| 2440 | */ |
| 2441 | static int mpi_init_descriptors (struct airo_info *ai) |
| 2442 | { |
| 2443 | Cmd cmd; |
| 2444 | Resp rsp; |
| 2445 | int i; |
| 2446 | int rc = SUCCESS; |
| 2447 | |
| 2448 | /* Alloc card RX descriptors */ |
| 2449 | netif_stop_queue(ai->dev); |
| 2450 | |
| 2451 | memset(&rsp,0,sizeof(rsp)); |
| 2452 | memset(&cmd,0,sizeof(cmd)); |
| 2453 | |
| 2454 | cmd.cmd = CMD_ALLOCATEAUX; |
| 2455 | cmd.parm0 = FID_RX; |
| 2456 | cmd.parm1 = (ai->rxfids[0].card_ram_off - ai->pciaux); |
| 2457 | cmd.parm2 = MPI_MAX_FIDS; |
| 2458 | rc=issuecommand(ai, &cmd, &rsp); |
| 2459 | if (rc != SUCCESS) { |
| 2460 | printk(KERN_ERR "airo: Couldn't allocate RX FID\n"); |
| 2461 | return rc; |
| 2462 | } |
| 2463 | |
| 2464 | for (i=0; i<MPI_MAX_FIDS; i++) { |
| 2465 | memcpy_toio(ai->rxfids[i].card_ram_off, |
| 2466 | &ai->rxfids[i].rx_desc, sizeof(RxFid)); |
| 2467 | } |
| 2468 | |
| 2469 | /* Alloc card TX descriptors */ |
| 2470 | |
| 2471 | memset(&rsp,0,sizeof(rsp)); |
| 2472 | memset(&cmd,0,sizeof(cmd)); |
| 2473 | |
| 2474 | cmd.cmd = CMD_ALLOCATEAUX; |
| 2475 | cmd.parm0 = FID_TX; |
| 2476 | cmd.parm1 = (ai->txfids[0].card_ram_off - ai->pciaux); |
| 2477 | cmd.parm2 = MPI_MAX_FIDS; |
| 2478 | |
| 2479 | for (i=0; i<MPI_MAX_FIDS; i++) { |
| 2480 | ai->txfids[i].tx_desc.valid = 1; |
| 2481 | memcpy_toio(ai->txfids[i].card_ram_off, |
| 2482 | &ai->txfids[i].tx_desc, sizeof(TxFid)); |
| 2483 | } |
| 2484 | ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */ |
| 2485 | |
| 2486 | rc=issuecommand(ai, &cmd, &rsp); |
| 2487 | if (rc != SUCCESS) { |
| 2488 | printk(KERN_ERR "airo: Couldn't allocate TX FID\n"); |
| 2489 | return rc; |
| 2490 | } |
| 2491 | |
| 2492 | /* Alloc card Rid descriptor */ |
| 2493 | memset(&rsp,0,sizeof(rsp)); |
| 2494 | memset(&cmd,0,sizeof(cmd)); |
| 2495 | |
| 2496 | cmd.cmd = CMD_ALLOCATEAUX; |
| 2497 | cmd.parm0 = RID_RW; |
| 2498 | cmd.parm1 = (ai->config_desc.card_ram_off - ai->pciaux); |
| 2499 | cmd.parm2 = 1; /* Magic number... */ |
| 2500 | rc=issuecommand(ai, &cmd, &rsp); |
| 2501 | if (rc != SUCCESS) { |
| 2502 | printk(KERN_ERR "airo: Couldn't allocate RID\n"); |
| 2503 | return rc; |
| 2504 | } |
| 2505 | |
| 2506 | memcpy_toio(ai->config_desc.card_ram_off, |
| 2507 | &ai->config_desc.rid_desc, sizeof(Rid)); |
| 2508 | |
| 2509 | return rc; |
| 2510 | } |
| 2511 | |
| 2512 | /* |
| 2513 | * We are setting up three things here: |
| 2514 | * 1) Map AUX memory for descriptors: Rid, TxFid, or RxFid. |
| 2515 | * 2) Map PCI memory for issueing commands. |
| 2516 | * 3) Allocate memory (shared) to send and receive ethernet frames. |
| 2517 | */ |
| 2518 | static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci, |
| 2519 | const char *name) |
| 2520 | { |
| 2521 | unsigned long mem_start, mem_len, aux_start, aux_len; |
| 2522 | int rc = -1; |
| 2523 | int i; |
Jeff Garzik | 2759c8d | 2005-09-24 04:09:04 -0400 | [diff] [blame] | 2524 | dma_addr_t busaddroff; |
| 2525 | unsigned char *vpackoff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | unsigned char __iomem *pciaddroff; |
| 2527 | |
| 2528 | mem_start = pci_resource_start(pci, 1); |
| 2529 | mem_len = pci_resource_len(pci, 1); |
| 2530 | aux_start = pci_resource_start(pci, 2); |
| 2531 | aux_len = AUXMEMSIZE; |
| 2532 | |
| 2533 | if (!request_mem_region(mem_start, mem_len, name)) { |
| 2534 | printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n", |
| 2535 | (int)mem_start, (int)mem_len, name); |
| 2536 | goto out; |
| 2537 | } |
| 2538 | if (!request_mem_region(aux_start, aux_len, name)) { |
| 2539 | printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n", |
| 2540 | (int)aux_start, (int)aux_len, name); |
| 2541 | goto free_region1; |
| 2542 | } |
| 2543 | |
| 2544 | ai->pcimem = ioremap(mem_start, mem_len); |
| 2545 | if (!ai->pcimem) { |
| 2546 | printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n", |
| 2547 | (int)mem_start, (int)mem_len, name); |
| 2548 | goto free_region2; |
| 2549 | } |
| 2550 | ai->pciaux = ioremap(aux_start, aux_len); |
| 2551 | if (!ai->pciaux) { |
| 2552 | printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n", |
| 2553 | (int)aux_start, (int)aux_len, name); |
| 2554 | goto free_memmap; |
| 2555 | } |
| 2556 | |
| 2557 | /* Reserve PKTSIZE for each fid and 2K for the Rids */ |
| 2558 | ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma); |
| 2559 | if (!ai->shared) { |
| 2560 | printk(KERN_ERR "airo: Couldn't alloc_consistent %d\n", |
| 2561 | PCI_SHARED_LEN); |
| 2562 | goto free_auxmap; |
| 2563 | } |
| 2564 | |
| 2565 | /* |
| 2566 | * Setup descriptor RX, TX, CONFIG |
| 2567 | */ |
Jeff Garzik | 2759c8d | 2005-09-24 04:09:04 -0400 | [diff] [blame] | 2568 | busaddroff = ai->shared_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | pciaddroff = ai->pciaux + AUX_OFFSET; |
| 2570 | vpackoff = ai->shared; |
| 2571 | |
| 2572 | /* RX descriptor setup */ |
| 2573 | for(i = 0; i < MPI_MAX_FIDS; i++) { |
| 2574 | ai->rxfids[i].pending = 0; |
| 2575 | ai->rxfids[i].card_ram_off = pciaddroff; |
| 2576 | ai->rxfids[i].virtual_host_addr = vpackoff; |
Jeff Garzik | 2759c8d | 2005-09-24 04:09:04 -0400 | [diff] [blame] | 2577 | ai->rxfids[i].rx_desc.host_addr = busaddroff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | ai->rxfids[i].rx_desc.valid = 1; |
| 2579 | ai->rxfids[i].rx_desc.len = PKTSIZE; |
| 2580 | ai->rxfids[i].rx_desc.rdy = 0; |
| 2581 | |
| 2582 | pciaddroff += sizeof(RxFid); |
| 2583 | busaddroff += PKTSIZE; |
| 2584 | vpackoff += PKTSIZE; |
| 2585 | } |
| 2586 | |
| 2587 | /* TX descriptor setup */ |
| 2588 | for(i = 0; i < MPI_MAX_FIDS; i++) { |
| 2589 | ai->txfids[i].card_ram_off = pciaddroff; |
| 2590 | ai->txfids[i].virtual_host_addr = vpackoff; |
| 2591 | ai->txfids[i].tx_desc.valid = 1; |
Jeff Garzik | 2759c8d | 2005-09-24 04:09:04 -0400 | [diff] [blame] | 2592 | ai->txfids[i].tx_desc.host_addr = busaddroff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | memcpy(ai->txfids[i].virtual_host_addr, |
| 2594 | &wifictlhdr8023, sizeof(wifictlhdr8023)); |
| 2595 | |
| 2596 | pciaddroff += sizeof(TxFid); |
| 2597 | busaddroff += PKTSIZE; |
| 2598 | vpackoff += PKTSIZE; |
| 2599 | } |
| 2600 | ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */ |
| 2601 | |
| 2602 | /* Rid descriptor setup */ |
| 2603 | ai->config_desc.card_ram_off = pciaddroff; |
| 2604 | ai->config_desc.virtual_host_addr = vpackoff; |
Jeff Garzik | 2759c8d | 2005-09-24 04:09:04 -0400 | [diff] [blame] | 2605 | ai->config_desc.rid_desc.host_addr = busaddroff; |
| 2606 | ai->ridbus = busaddroff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | ai->config_desc.rid_desc.rid = 0; |
| 2608 | ai->config_desc.rid_desc.len = RIDSIZE; |
| 2609 | ai->config_desc.rid_desc.valid = 1; |
| 2610 | pciaddroff += sizeof(Rid); |
| 2611 | busaddroff += RIDSIZE; |
| 2612 | vpackoff += RIDSIZE; |
| 2613 | |
| 2614 | /* Tell card about descriptors */ |
| 2615 | if (mpi_init_descriptors (ai) != SUCCESS) |
| 2616 | goto free_shared; |
| 2617 | |
| 2618 | return 0; |
| 2619 | free_shared: |
| 2620 | pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma); |
| 2621 | free_auxmap: |
| 2622 | iounmap(ai->pciaux); |
| 2623 | free_memmap: |
| 2624 | iounmap(ai->pcimem); |
| 2625 | free_region2: |
| 2626 | release_mem_region(aux_start, aux_len); |
| 2627 | free_region1: |
| 2628 | release_mem_region(mem_start, mem_len); |
| 2629 | out: |
| 2630 | return rc; |
| 2631 | } |
| 2632 | |
| 2633 | static void wifi_setup(struct net_device *dev) |
| 2634 | { |
| 2635 | dev->hard_header = NULL; |
| 2636 | dev->rebuild_header = NULL; |
| 2637 | dev->hard_header_cache = NULL; |
| 2638 | dev->header_cache_update= NULL; |
| 2639 | |
| 2640 | dev->hard_header_parse = wll_header_parse; |
| 2641 | dev->hard_start_xmit = &airo_start_xmit11; |
| 2642 | dev->get_stats = &airo_get_stats; |
| 2643 | dev->set_mac_address = &airo_set_mac_address; |
| 2644 | dev->do_ioctl = &airo_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | dev->wireless_handlers = &airo_handler_def; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | dev->change_mtu = &airo_change_mtu; |
| 2647 | dev->open = &airo_open; |
| 2648 | dev->stop = &airo_close; |
| 2649 | |
| 2650 | dev->type = ARPHRD_IEEE80211; |
| 2651 | dev->hard_header_len = ETH_HLEN; |
| 2652 | dev->mtu = 2312; |
| 2653 | dev->addr_len = ETH_ALEN; |
| 2654 | dev->tx_queue_len = 100; |
| 2655 | |
| 2656 | memset(dev->broadcast,0xFF, ETH_ALEN); |
| 2657 | |
| 2658 | dev->flags = IFF_BROADCAST|IFF_MULTICAST; |
| 2659 | } |
| 2660 | |
| 2661 | static struct net_device *init_wifidev(struct airo_info *ai, |
| 2662 | struct net_device *ethdev) |
| 2663 | { |
| 2664 | int err; |
| 2665 | struct net_device *dev = alloc_netdev(0, "wifi%d", wifi_setup); |
| 2666 | if (!dev) |
| 2667 | return NULL; |
| 2668 | dev->priv = ethdev->priv; |
| 2669 | dev->irq = ethdev->irq; |
| 2670 | dev->base_addr = ethdev->base_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | dev->wireless_data = ethdev->wireless_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len); |
| 2673 | err = register_netdev(dev); |
| 2674 | if (err<0) { |
| 2675 | free_netdev(dev); |
| 2676 | return NULL; |
| 2677 | } |
| 2678 | return dev; |
| 2679 | } |
| 2680 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 2681 | static int reset_card( struct net_device *dev , int lock) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | struct airo_info *ai = dev->priv; |
| 2683 | |
| 2684 | if (lock && down_interruptible(&ai->sem)) |
| 2685 | return -1; |
| 2686 | waitbusy (ai); |
| 2687 | OUT4500(ai,COMMAND,CMD_SOFTRESET); |
| 2688 | msleep(200); |
| 2689 | waitbusy (ai); |
| 2690 | msleep(200); |
| 2691 | if (lock) |
| 2692 | up(&ai->sem); |
| 2693 | return 0; |
| 2694 | } |
| 2695 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 2696 | static struct net_device *_init_airo_card( unsigned short irq, int port, |
| 2697 | int is_pcmcia, struct pci_dev *pci, |
| 2698 | struct device *dmdev ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | { |
| 2700 | struct net_device *dev; |
| 2701 | struct airo_info *ai; |
| 2702 | int i, rc; |
| 2703 | |
| 2704 | /* Create the network device object. */ |
| 2705 | dev = alloc_etherdev(sizeof(*ai)); |
| 2706 | if (!dev) { |
| 2707 | printk(KERN_ERR "airo: Couldn't alloc_etherdev\n"); |
| 2708 | return NULL; |
| 2709 | } |
| 2710 | if (dev_alloc_name(dev, dev->name) < 0) { |
| 2711 | printk(KERN_ERR "airo: Couldn't get name!\n"); |
| 2712 | goto err_out_free; |
| 2713 | } |
| 2714 | |
| 2715 | ai = dev->priv; |
| 2716 | ai->wifidev = NULL; |
| 2717 | ai->flags = 0; |
| 2718 | if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) { |
| 2719 | printk(KERN_DEBUG "airo: Found an MPI350 card\n"); |
| 2720 | set_bit(FLAG_MPI, &ai->flags); |
| 2721 | } |
| 2722 | ai->dev = dev; |
| 2723 | spin_lock_init(&ai->aux_lock); |
| 2724 | sema_init(&ai->sem, 1); |
| 2725 | ai->config.len = 0; |
| 2726 | ai->pci = pci; |
| 2727 | init_waitqueue_head (&ai->thr_wait); |
| 2728 | init_completion (&ai->thr_exited); |
| 2729 | ai->thr_pid = kernel_thread(airo_thread, dev, CLONE_FS | CLONE_FILES); |
| 2730 | if (ai->thr_pid < 0) |
| 2731 | goto err_out_free; |
| 2732 | #ifdef MICSUPPORT |
| 2733 | ai->tfm = NULL; |
| 2734 | #endif |
| 2735 | rc = add_airo_dev( dev ); |
| 2736 | if (rc) |
| 2737 | goto err_out_thr; |
| 2738 | |
| 2739 | /* The Airo-specific entries in the device structure. */ |
| 2740 | if (test_bit(FLAG_MPI,&ai->flags)) { |
| 2741 | skb_queue_head_init (&ai->txq); |
| 2742 | dev->hard_start_xmit = &mpi_start_xmit; |
| 2743 | } else |
| 2744 | dev->hard_start_xmit = &airo_start_xmit; |
| 2745 | dev->get_stats = &airo_get_stats; |
| 2746 | dev->set_multicast_list = &airo_set_multicast_list; |
| 2747 | dev->set_mac_address = &airo_set_mac_address; |
| 2748 | dev->do_ioctl = &airo_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | dev->wireless_handlers = &airo_handler_def; |
| 2750 | ai->wireless_data.spy_data = &ai->spy_data; |
| 2751 | dev->wireless_data = &ai->wireless_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | dev->change_mtu = &airo_change_mtu; |
| 2753 | dev->open = &airo_open; |
| 2754 | dev->stop = &airo_close; |
| 2755 | dev->irq = irq; |
| 2756 | dev->base_addr = port; |
| 2757 | |
| 2758 | SET_NETDEV_DEV(dev, dmdev); |
| 2759 | |
| 2760 | |
| 2761 | if (test_bit(FLAG_MPI,&ai->flags)) |
| 2762 | reset_card (dev, 1); |
| 2763 | |
| 2764 | rc = request_irq( dev->irq, airo_interrupt, SA_SHIRQ, dev->name, dev ); |
| 2765 | if (rc) { |
| 2766 | printk(KERN_ERR "airo: register interrupt %d failed, rc %d\n", irq, rc ); |
| 2767 | goto err_out_unlink; |
| 2768 | } |
| 2769 | if (!is_pcmcia) { |
| 2770 | if (!request_region( dev->base_addr, 64, dev->name )) { |
| 2771 | rc = -EBUSY; |
| 2772 | printk(KERN_ERR "airo: Couldn't request region\n"); |
| 2773 | goto err_out_irq; |
| 2774 | } |
| 2775 | } |
| 2776 | |
| 2777 | if (test_bit(FLAG_MPI,&ai->flags)) { |
| 2778 | if (mpi_map_card(ai, pci, dev->name)) { |
| 2779 | printk(KERN_ERR "airo: Could not map memory\n"); |
| 2780 | goto err_out_res; |
| 2781 | } |
| 2782 | } |
| 2783 | |
| 2784 | if (probe) { |
| 2785 | if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) { |
| 2786 | printk( KERN_ERR "airo: MAC could not be enabled\n" ); |
| 2787 | rc = -EIO; |
| 2788 | goto err_out_map; |
| 2789 | } |
| 2790 | } else if (!test_bit(FLAG_MPI,&ai->flags)) { |
| 2791 | ai->bap_read = fast_bap_read; |
| 2792 | set_bit(FLAG_FLASHING, &ai->flags); |
| 2793 | } |
| 2794 | |
| 2795 | rc = register_netdev(dev); |
| 2796 | if (rc) { |
| 2797 | printk(KERN_ERR "airo: Couldn't register_netdev\n"); |
| 2798 | goto err_out_map; |
| 2799 | } |
| 2800 | ai->wifidev = init_wifidev(ai, dev); |
| 2801 | |
| 2802 | set_bit(FLAG_REGISTERED,&ai->flags); |
| 2803 | printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n", |
| 2804 | dev->name, |
| 2805 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], |
| 2806 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] ); |
| 2807 | |
| 2808 | /* Allocate the transmit buffers */ |
| 2809 | if (probe && !test_bit(FLAG_MPI,&ai->flags)) |
| 2810 | for( i = 0; i < MAX_FIDS; i++ ) |
| 2811 | ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2); |
| 2812 | |
| 2813 | setup_proc_entry( dev, dev->priv ); /* XXX check for failure */ |
| 2814 | netif_start_queue(dev); |
| 2815 | SET_MODULE_OWNER(dev); |
| 2816 | return dev; |
| 2817 | |
| 2818 | err_out_map: |
| 2819 | if (test_bit(FLAG_MPI,&ai->flags) && pci) { |
| 2820 | pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma); |
| 2821 | iounmap(ai->pciaux); |
| 2822 | iounmap(ai->pcimem); |
| 2823 | mpi_unmap_card(ai->pci); |
| 2824 | } |
| 2825 | err_out_res: |
| 2826 | if (!is_pcmcia) |
| 2827 | release_region( dev->base_addr, 64 ); |
| 2828 | err_out_irq: |
| 2829 | free_irq(dev->irq, dev); |
| 2830 | err_out_unlink: |
| 2831 | del_airo_dev(dev); |
| 2832 | err_out_thr: |
| 2833 | set_bit(JOB_DIE, &ai->flags); |
| 2834 | kill_proc(ai->thr_pid, SIGTERM, 1); |
| 2835 | wait_for_completion(&ai->thr_exited); |
| 2836 | err_out_free: |
| 2837 | free_netdev(dev); |
| 2838 | return NULL; |
| 2839 | } |
| 2840 | |
| 2841 | struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia, |
| 2842 | struct device *dmdev) |
| 2843 | { |
| 2844 | return _init_airo_card ( irq, port, is_pcmcia, NULL, dmdev); |
| 2845 | } |
| 2846 | |
| 2847 | EXPORT_SYMBOL(init_airo_card); |
| 2848 | |
| 2849 | static int waitbusy (struct airo_info *ai) { |
| 2850 | int delay = 0; |
| 2851 | while ((IN4500 (ai, COMMAND) & COMMAND_BUSY) & (delay < 10000)) { |
| 2852 | udelay (10); |
| 2853 | if ((++delay % 20) == 0) |
| 2854 | OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY); |
| 2855 | } |
| 2856 | return delay < 10000; |
| 2857 | } |
| 2858 | |
| 2859 | int reset_airo_card( struct net_device *dev ) |
| 2860 | { |
| 2861 | int i; |
| 2862 | struct airo_info *ai = dev->priv; |
| 2863 | |
| 2864 | if (reset_card (dev, 1)) |
| 2865 | return -1; |
| 2866 | |
| 2867 | if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) { |
| 2868 | printk( KERN_ERR "airo: MAC could not be enabled\n" ); |
| 2869 | return -1; |
| 2870 | } |
| 2871 | printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n", dev->name, |
| 2872 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], |
| 2873 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); |
| 2874 | /* Allocate the transmit buffers if needed */ |
| 2875 | if (!test_bit(FLAG_MPI,&ai->flags)) |
| 2876 | for( i = 0; i < MAX_FIDS; i++ ) |
| 2877 | ai->fids[i] = transmit_allocate (ai,2312,i>=MAX_FIDS/2); |
| 2878 | |
| 2879 | enable_interrupts( ai ); |
| 2880 | netif_wake_queue(dev); |
| 2881 | return 0; |
| 2882 | } |
| 2883 | |
| 2884 | EXPORT_SYMBOL(reset_airo_card); |
| 2885 | |
| 2886 | static void airo_send_event(struct net_device *dev) { |
| 2887 | struct airo_info *ai = dev->priv; |
| 2888 | union iwreq_data wrqu; |
| 2889 | StatusRid status_rid; |
| 2890 | |
| 2891 | clear_bit(JOB_EVENT, &ai->flags); |
| 2892 | PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0); |
| 2893 | up(&ai->sem); |
| 2894 | wrqu.data.length = 0; |
| 2895 | wrqu.data.flags = 0; |
| 2896 | memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN); |
| 2897 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 2898 | |
| 2899 | /* Send event to user space */ |
| 2900 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 2901 | } |
| 2902 | |
| 2903 | static int airo_thread(void *data) { |
| 2904 | struct net_device *dev = data; |
| 2905 | struct airo_info *ai = dev->priv; |
| 2906 | int locked; |
| 2907 | |
| 2908 | daemonize("%s", dev->name); |
| 2909 | allow_signal(SIGTERM); |
| 2910 | |
| 2911 | while(1) { |
| 2912 | if (signal_pending(current)) |
| 2913 | flush_signals(current); |
| 2914 | |
| 2915 | /* make swsusp happy with our thread */ |
Christoph Lameter | 3e1d1d2 | 2005-06-24 23:13:50 -0700 | [diff] [blame] | 2916 | try_to_freeze(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | |
| 2918 | if (test_bit(JOB_DIE, &ai->flags)) |
| 2919 | break; |
| 2920 | |
| 2921 | if (ai->flags & JOB_MASK) { |
| 2922 | locked = down_interruptible(&ai->sem); |
| 2923 | } else { |
| 2924 | wait_queue_t wait; |
| 2925 | |
| 2926 | init_waitqueue_entry(&wait, current); |
| 2927 | add_wait_queue(&ai->thr_wait, &wait); |
| 2928 | for (;;) { |
| 2929 | set_current_state(TASK_INTERRUPTIBLE); |
| 2930 | if (ai->flags & JOB_MASK) |
| 2931 | break; |
| 2932 | if (ai->expires) { |
| 2933 | if (time_after_eq(jiffies,ai->expires)){ |
| 2934 | set_bit(JOB_AUTOWEP,&ai->flags); |
| 2935 | break; |
| 2936 | } |
| 2937 | if (!signal_pending(current)) { |
| 2938 | schedule_timeout(ai->expires - jiffies); |
| 2939 | continue; |
| 2940 | } |
| 2941 | } else if (!signal_pending(current)) { |
| 2942 | schedule(); |
| 2943 | continue; |
| 2944 | } |
| 2945 | break; |
| 2946 | } |
| 2947 | current->state = TASK_RUNNING; |
| 2948 | remove_wait_queue(&ai->thr_wait, &wait); |
| 2949 | locked = 1; |
| 2950 | } |
| 2951 | |
| 2952 | if (locked) |
| 2953 | continue; |
| 2954 | |
| 2955 | if (test_bit(JOB_DIE, &ai->flags)) { |
| 2956 | up(&ai->sem); |
| 2957 | break; |
| 2958 | } |
| 2959 | |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 2960 | if (ai->power.event || test_bit(FLAG_FLASHING, &ai->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | up(&ai->sem); |
| 2962 | continue; |
| 2963 | } |
| 2964 | |
| 2965 | if (test_bit(JOB_XMIT, &ai->flags)) |
| 2966 | airo_end_xmit(dev); |
| 2967 | else if (test_bit(JOB_XMIT11, &ai->flags)) |
| 2968 | airo_end_xmit11(dev); |
| 2969 | else if (test_bit(JOB_STATS, &ai->flags)) |
| 2970 | airo_read_stats(ai); |
| 2971 | else if (test_bit(JOB_WSTATS, &ai->flags)) |
| 2972 | airo_read_wireless_stats(ai); |
| 2973 | else if (test_bit(JOB_PROMISC, &ai->flags)) |
| 2974 | airo_set_promisc(ai); |
| 2975 | #ifdef MICSUPPORT |
| 2976 | else if (test_bit(JOB_MIC, &ai->flags)) |
| 2977 | micinit(ai); |
| 2978 | #endif |
| 2979 | else if (test_bit(JOB_EVENT, &ai->flags)) |
| 2980 | airo_send_event(dev); |
| 2981 | else if (test_bit(JOB_AUTOWEP, &ai->flags)) |
| 2982 | timer_func(dev); |
| 2983 | } |
| 2984 | complete_and_exit (&ai->thr_exited, 0); |
| 2985 | } |
| 2986 | |
| 2987 | static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs) { |
| 2988 | struct net_device *dev = (struct net_device *)dev_id; |
| 2989 | u16 status; |
| 2990 | u16 fid; |
| 2991 | struct airo_info *apriv = dev->priv; |
| 2992 | u16 savedInterrupts = 0; |
| 2993 | int handled = 0; |
| 2994 | |
| 2995 | if (!netif_device_present(dev)) |
| 2996 | return IRQ_NONE; |
| 2997 | |
| 2998 | for (;;) { |
| 2999 | status = IN4500( apriv, EVSTAT ); |
| 3000 | if ( !(status & STATUS_INTS) || status == 0xffff ) break; |
| 3001 | |
| 3002 | handled = 1; |
| 3003 | |
| 3004 | if ( status & EV_AWAKE ) { |
| 3005 | OUT4500( apriv, EVACK, EV_AWAKE ); |
| 3006 | OUT4500( apriv, EVACK, EV_AWAKE ); |
| 3007 | } |
| 3008 | |
| 3009 | if (!savedInterrupts) { |
| 3010 | savedInterrupts = IN4500( apriv, EVINTEN ); |
| 3011 | OUT4500( apriv, EVINTEN, 0 ); |
| 3012 | } |
| 3013 | |
| 3014 | if ( status & EV_MIC ) { |
| 3015 | OUT4500( apriv, EVACK, EV_MIC ); |
| 3016 | #ifdef MICSUPPORT |
| 3017 | if (test_bit(FLAG_MIC_CAPABLE, &apriv->flags)) { |
| 3018 | set_bit(JOB_MIC, &apriv->flags); |
| 3019 | wake_up_interruptible(&apriv->thr_wait); |
| 3020 | } |
| 3021 | #endif |
| 3022 | } |
| 3023 | if ( status & EV_LINK ) { |
| 3024 | union iwreq_data wrqu; |
| 3025 | /* The link status has changed, if you want to put a |
| 3026 | monitor hook in, do it here. (Remember that |
| 3027 | interrupts are still disabled!) |
| 3028 | */ |
| 3029 | u16 newStatus = IN4500(apriv, LINKSTAT); |
| 3030 | OUT4500( apriv, EVACK, EV_LINK); |
| 3031 | /* Here is what newStatus means: */ |
| 3032 | #define NOBEACON 0x8000 /* Loss of sync - missed beacons */ |
| 3033 | #define MAXRETRIES 0x8001 /* Loss of sync - max retries */ |
| 3034 | #define MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/ |
| 3035 | #define FORCELOSS 0x8003 /* Loss of sync - host request */ |
| 3036 | #define TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */ |
| 3037 | #define DEAUTH 0x8100 /* Deauthentication (low byte is reason code) */ |
| 3038 | #define DISASS 0x8200 /* Disassociation (low byte is reason code) */ |
| 3039 | #define ASSFAIL 0x8400 /* Association failure (low byte is reason |
| 3040 | code) */ |
| 3041 | #define AUTHFAIL 0x0300 /* Authentication failure (low byte is reason |
| 3042 | code) */ |
| 3043 | #define ASSOCIATED 0x0400 /* Assocatied */ |
| 3044 | #define RC_RESERVED 0 /* Reserved return code */ |
| 3045 | #define RC_NOREASON 1 /* Unspecified reason */ |
| 3046 | #define RC_AUTHINV 2 /* Previous authentication invalid */ |
| 3047 | #define RC_DEAUTH 3 /* Deauthenticated because sending station is |
| 3048 | leaving */ |
| 3049 | #define RC_NOACT 4 /* Disassociated due to inactivity */ |
| 3050 | #define RC_MAXLOAD 5 /* Disassociated because AP is unable to handle |
| 3051 | all currently associated stations */ |
| 3052 | #define RC_BADCLASS2 6 /* Class 2 frame received from |
| 3053 | non-Authenticated station */ |
| 3054 | #define RC_BADCLASS3 7 /* Class 3 frame received from |
| 3055 | non-Associated station */ |
| 3056 | #define RC_STATLEAVE 8 /* Disassociated because sending station is |
| 3057 | leaving BSS */ |
| 3058 | #define RC_NOAUTH 9 /* Station requesting (Re)Association is not |
| 3059 | Authenticated with the responding station */ |
| 3060 | if (newStatus != ASSOCIATED) { |
| 3061 | if (auto_wep && !apriv->expires) { |
| 3062 | apriv->expires = RUN_AT(3*HZ); |
| 3063 | wake_up_interruptible(&apriv->thr_wait); |
| 3064 | } |
| 3065 | } else { |
| 3066 | struct task_struct *task = apriv->task; |
| 3067 | if (auto_wep) |
| 3068 | apriv->expires = 0; |
| 3069 | if (task) |
| 3070 | wake_up_process (task); |
| 3071 | set_bit(FLAG_UPDATE_UNI, &apriv->flags); |
| 3072 | set_bit(FLAG_UPDATE_MULTI, &apriv->flags); |
| 3073 | } |
| 3074 | /* Question : is ASSOCIATED the only status |
| 3075 | * that is valid ? We want to catch handover |
| 3076 | * and reassociations as valid status |
| 3077 | * Jean II */ |
| 3078 | if(newStatus == ASSOCIATED) { |
| 3079 | if (apriv->scan_timestamp) { |
| 3080 | /* Send an empty event to user space. |
| 3081 | * We don't send the received data on |
| 3082 | * the event because it would require |
| 3083 | * us to do complex transcoding, and |
| 3084 | * we want to minimise the work done in |
| 3085 | * the irq handler. Use a request to |
| 3086 | * extract the data - Jean II */ |
| 3087 | wrqu.data.length = 0; |
| 3088 | wrqu.data.flags = 0; |
| 3089 | wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL); |
| 3090 | apriv->scan_timestamp = 0; |
| 3091 | } |
| 3092 | if (down_trylock(&apriv->sem) != 0) { |
| 3093 | set_bit(JOB_EVENT, &apriv->flags); |
| 3094 | wake_up_interruptible(&apriv->thr_wait); |
| 3095 | } else |
| 3096 | airo_send_event(dev); |
| 3097 | } else { |
| 3098 | memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN); |
| 3099 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 3100 | |
| 3101 | /* Send event to user space */ |
| 3102 | wireless_send_event(dev, SIOCGIWAP, &wrqu,NULL); |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | /* Check to see if there is something to receive */ |
| 3107 | if ( status & EV_RX ) { |
| 3108 | struct sk_buff *skb = NULL; |
| 3109 | u16 fc, len, hdrlen = 0; |
| 3110 | #pragma pack(1) |
| 3111 | struct { |
| 3112 | u16 status, len; |
| 3113 | u8 rssi[2]; |
| 3114 | u8 rate; |
| 3115 | u8 freq; |
| 3116 | u16 tmp[4]; |
| 3117 | } hdr; |
| 3118 | #pragma pack() |
| 3119 | u16 gap; |
| 3120 | u16 tmpbuf[4]; |
| 3121 | u16 *buffer; |
| 3122 | |
| 3123 | if (test_bit(FLAG_MPI,&apriv->flags)) { |
| 3124 | if (test_bit(FLAG_802_11, &apriv->flags)) |
| 3125 | mpi_receive_802_11(apriv); |
| 3126 | else |
| 3127 | mpi_receive_802_3(apriv); |
| 3128 | OUT4500(apriv, EVACK, EV_RX); |
| 3129 | goto exitrx; |
| 3130 | } |
| 3131 | |
| 3132 | fid = IN4500( apriv, RXFID ); |
| 3133 | |
| 3134 | /* Get the packet length */ |
| 3135 | if (test_bit(FLAG_802_11, &apriv->flags)) { |
| 3136 | bap_setup (apriv, fid, 4, BAP0); |
| 3137 | bap_read (apriv, (u16*)&hdr, sizeof(hdr), BAP0); |
| 3138 | /* Bad CRC. Ignore packet */ |
| 3139 | if (le16_to_cpu(hdr.status) & 2) |
| 3140 | hdr.len = 0; |
| 3141 | if (apriv->wifidev == NULL) |
| 3142 | hdr.len = 0; |
| 3143 | } else { |
| 3144 | bap_setup (apriv, fid, 0x36, BAP0); |
| 3145 | bap_read (apriv, (u16*)&hdr.len, 2, BAP0); |
| 3146 | } |
| 3147 | len = le16_to_cpu(hdr.len); |
| 3148 | |
| 3149 | if (len > 2312) { |
| 3150 | printk( KERN_ERR "airo: Bad size %d\n", len ); |
| 3151 | goto badrx; |
| 3152 | } |
| 3153 | if (len == 0) |
| 3154 | goto badrx; |
| 3155 | |
| 3156 | if (test_bit(FLAG_802_11, &apriv->flags)) { |
| 3157 | bap_read (apriv, (u16*)&fc, sizeof(fc), BAP0); |
| 3158 | fc = le16_to_cpu(fc); |
| 3159 | switch (fc & 0xc) { |
| 3160 | case 4: |
| 3161 | if ((fc & 0xe0) == 0xc0) |
| 3162 | hdrlen = 10; |
| 3163 | else |
| 3164 | hdrlen = 16; |
| 3165 | break; |
| 3166 | case 8: |
| 3167 | if ((fc&0x300)==0x300){ |
| 3168 | hdrlen = 30; |
| 3169 | break; |
| 3170 | } |
| 3171 | default: |
| 3172 | hdrlen = 24; |
| 3173 | } |
| 3174 | } else |
| 3175 | hdrlen = ETH_ALEN * 2; |
| 3176 | |
| 3177 | skb = dev_alloc_skb( len + hdrlen + 2 + 2 ); |
| 3178 | if ( !skb ) { |
| 3179 | apriv->stats.rx_dropped++; |
| 3180 | goto badrx; |
| 3181 | } |
| 3182 | skb_reserve(skb, 2); /* This way the IP header is aligned */ |
| 3183 | buffer = (u16*)skb_put (skb, len + hdrlen); |
| 3184 | if (test_bit(FLAG_802_11, &apriv->flags)) { |
| 3185 | buffer[0] = fc; |
| 3186 | bap_read (apriv, buffer + 1, hdrlen - 2, BAP0); |
| 3187 | if (hdrlen == 24) |
| 3188 | bap_read (apriv, tmpbuf, 6, BAP0); |
| 3189 | |
| 3190 | bap_read (apriv, &gap, sizeof(gap), BAP0); |
| 3191 | gap = le16_to_cpu(gap); |
| 3192 | if (gap) { |
| 3193 | if (gap <= 8) |
| 3194 | bap_read (apriv, tmpbuf, gap, BAP0); |
| 3195 | else |
| 3196 | printk(KERN_ERR "airo: gaplen too big. Problems will follow...\n"); |
| 3197 | } |
| 3198 | bap_read (apriv, buffer + hdrlen/2, len, BAP0); |
| 3199 | } else { |
| 3200 | #ifdef MICSUPPORT |
| 3201 | MICBuffer micbuf; |
| 3202 | #endif |
| 3203 | bap_read (apriv, buffer, ETH_ALEN*2, BAP0); |
| 3204 | #ifdef MICSUPPORT |
| 3205 | if (apriv->micstats.enabled) { |
| 3206 | bap_read (apriv,(u16*)&micbuf,sizeof(micbuf),BAP0); |
| 3207 | if (ntohs(micbuf.typelen) > 0x05DC) |
| 3208 | bap_setup (apriv, fid, 0x44, BAP0); |
| 3209 | else { |
| 3210 | if (len <= sizeof(micbuf)) |
| 3211 | goto badmic; |
| 3212 | |
| 3213 | len -= sizeof(micbuf); |
| 3214 | skb_trim (skb, len + hdrlen); |
| 3215 | } |
| 3216 | } |
| 3217 | #endif |
| 3218 | bap_read(apriv,buffer+ETH_ALEN,len,BAP0); |
| 3219 | #ifdef MICSUPPORT |
| 3220 | if (decapsulate(apriv,&micbuf,(etherHead*)buffer,len)) { |
| 3221 | badmic: |
| 3222 | dev_kfree_skb_irq (skb); |
| 3223 | #else |
| 3224 | if (0) { |
| 3225 | #endif |
| 3226 | badrx: |
| 3227 | OUT4500( apriv, EVACK, EV_RX); |
| 3228 | goto exitrx; |
| 3229 | } |
| 3230 | } |
| 3231 | #ifdef WIRELESS_SPY |
| 3232 | if (apriv->spy_data.spy_number > 0) { |
| 3233 | char *sa; |
| 3234 | struct iw_quality wstats; |
| 3235 | /* Prepare spy data : addr + qual */ |
| 3236 | if (!test_bit(FLAG_802_11, &apriv->flags)) { |
| 3237 | sa = (char*)buffer + 6; |
| 3238 | bap_setup (apriv, fid, 8, BAP0); |
| 3239 | bap_read (apriv, (u16*)hdr.rssi, 2, BAP0); |
| 3240 | } else |
| 3241 | sa = (char*)buffer + 10; |
| 3242 | wstats.qual = hdr.rssi[0]; |
| 3243 | if (apriv->rssi) |
| 3244 | wstats.level = 0x100 - apriv->rssi[hdr.rssi[1]].rssidBm; |
| 3245 | else |
| 3246 | wstats.level = (hdr.rssi[1] + 321) / 2; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 3247 | wstats.noise = apriv->wstats.qual.noise; |
| 3248 | wstats.updated = IW_QUAL_LEVEL_UPDATED |
| 3249 | | IW_QUAL_QUAL_UPDATED |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 3250 | | IW_QUAL_DBM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | /* Update spy records */ |
| 3252 | wireless_spy_update(dev, sa, &wstats); |
| 3253 | } |
| 3254 | #endif /* WIRELESS_SPY */ |
| 3255 | OUT4500( apriv, EVACK, EV_RX); |
| 3256 | |
| 3257 | if (test_bit(FLAG_802_11, &apriv->flags)) { |
| 3258 | skb->mac.raw = skb->data; |
| 3259 | skb->pkt_type = PACKET_OTHERHOST; |
| 3260 | skb->dev = apriv->wifidev; |
| 3261 | skb->protocol = htons(ETH_P_802_2); |
| 3262 | } else { |
| 3263 | skb->dev = dev; |
| 3264 | skb->protocol = eth_type_trans(skb,dev); |
| 3265 | } |
| 3266 | skb->dev->last_rx = jiffies; |
| 3267 | skb->ip_summed = CHECKSUM_NONE; |
| 3268 | |
| 3269 | netif_rx( skb ); |
| 3270 | } |
| 3271 | exitrx: |
| 3272 | |
| 3273 | /* Check to see if a packet has been transmitted */ |
| 3274 | if ( status & ( EV_TX|EV_TXCPY|EV_TXEXC ) ) { |
| 3275 | int i; |
| 3276 | int len = 0; |
| 3277 | int index = -1; |
| 3278 | |
| 3279 | if (test_bit(FLAG_MPI,&apriv->flags)) { |
| 3280 | unsigned long flags; |
| 3281 | |
| 3282 | if (status & EV_TXEXC) |
| 3283 | get_tx_error(apriv, -1); |
| 3284 | spin_lock_irqsave(&apriv->aux_lock, flags); |
David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 3285 | if (!skb_queue_empty(&apriv->txq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | spin_unlock_irqrestore(&apriv->aux_lock,flags); |
| 3287 | mpi_send_packet (dev); |
| 3288 | } else { |
| 3289 | clear_bit(FLAG_PENDING_XMIT, &apriv->flags); |
| 3290 | spin_unlock_irqrestore(&apriv->aux_lock,flags); |
| 3291 | netif_wake_queue (dev); |
| 3292 | } |
| 3293 | OUT4500( apriv, EVACK, |
| 3294 | status & (EV_TX|EV_TXCPY|EV_TXEXC)); |
| 3295 | goto exittx; |
| 3296 | } |
| 3297 | |
| 3298 | fid = IN4500(apriv, TXCOMPLFID); |
| 3299 | |
| 3300 | for( i = 0; i < MAX_FIDS; i++ ) { |
| 3301 | if ( ( apriv->fids[i] & 0xffff ) == fid ) { |
| 3302 | len = apriv->fids[i] >> 16; |
| 3303 | index = i; |
| 3304 | } |
| 3305 | } |
| 3306 | if (index != -1) { |
| 3307 | if (status & EV_TXEXC) |
| 3308 | get_tx_error(apriv, index); |
| 3309 | OUT4500( apriv, EVACK, status & (EV_TX | EV_TXEXC)); |
| 3310 | /* Set up to be used again */ |
| 3311 | apriv->fids[index] &= 0xffff; |
| 3312 | if (index < MAX_FIDS / 2) { |
| 3313 | if (!test_bit(FLAG_PENDING_XMIT, &apriv->flags)) |
| 3314 | netif_wake_queue(dev); |
| 3315 | } else { |
| 3316 | if (!test_bit(FLAG_PENDING_XMIT11, &apriv->flags)) |
| 3317 | netif_wake_queue(apriv->wifidev); |
| 3318 | } |
| 3319 | } else { |
| 3320 | OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC)); |
| 3321 | printk( KERN_ERR "airo: Unallocated FID was used to xmit\n" ); |
| 3322 | } |
| 3323 | } |
| 3324 | exittx: |
| 3325 | if ( status & ~STATUS_INTS & ~IGNORE_INTS ) |
| 3326 | printk( KERN_WARNING "airo: Got weird status %x\n", |
| 3327 | status & ~STATUS_INTS & ~IGNORE_INTS ); |
| 3328 | } |
| 3329 | |
| 3330 | if (savedInterrupts) |
| 3331 | OUT4500( apriv, EVINTEN, savedInterrupts ); |
| 3332 | |
| 3333 | /* done.. */ |
| 3334 | return IRQ_RETVAL(handled); |
| 3335 | } |
| 3336 | |
| 3337 | /* |
| 3338 | * Routines to talk to the card |
| 3339 | */ |
| 3340 | |
| 3341 | /* |
| 3342 | * This was originally written for the 4500, hence the name |
| 3343 | * NOTE: If use with 8bit mode and SMP bad things will happen! |
| 3344 | * Why would some one do 8 bit IO in an SMP machine?!? |
| 3345 | */ |
| 3346 | static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) { |
| 3347 | if (test_bit(FLAG_MPI,&ai->flags)) |
| 3348 | reg <<= 1; |
| 3349 | if ( !do8bitIO ) |
| 3350 | outw( val, ai->dev->base_addr + reg ); |
| 3351 | else { |
| 3352 | outb( val & 0xff, ai->dev->base_addr + reg ); |
| 3353 | outb( val >> 8, ai->dev->base_addr + reg + 1 ); |
| 3354 | } |
| 3355 | } |
| 3356 | |
| 3357 | static u16 IN4500( struct airo_info *ai, u16 reg ) { |
| 3358 | unsigned short rc; |
| 3359 | |
| 3360 | if (test_bit(FLAG_MPI,&ai->flags)) |
| 3361 | reg <<= 1; |
| 3362 | if ( !do8bitIO ) |
| 3363 | rc = inw( ai->dev->base_addr + reg ); |
| 3364 | else { |
| 3365 | rc = inb( ai->dev->base_addr + reg ); |
| 3366 | rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8; |
| 3367 | } |
| 3368 | return rc; |
| 3369 | } |
| 3370 | |
| 3371 | static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ) { |
| 3372 | int rc; |
| 3373 | Cmd cmd; |
| 3374 | |
| 3375 | /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions |
| 3376 | * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down" |
| 3377 | * Note : we could try to use !netif_running(dev) in enable_MAC() |
| 3378 | * instead of this flag, but I don't trust it *within* the |
| 3379 | * open/close functions, and testing both flags together is |
| 3380 | * "cheaper" - Jean II */ |
| 3381 | if (ai->flags & FLAG_RADIO_MASK) return SUCCESS; |
| 3382 | |
| 3383 | if (lock && down_interruptible(&ai->sem)) |
| 3384 | return -ERESTARTSYS; |
| 3385 | |
| 3386 | if (!test_bit(FLAG_ENABLED, &ai->flags)) { |
| 3387 | memset(&cmd, 0, sizeof(cmd)); |
| 3388 | cmd.cmd = MAC_ENABLE; |
| 3389 | rc = issuecommand(ai, &cmd, rsp); |
| 3390 | if (rc == SUCCESS) |
| 3391 | set_bit(FLAG_ENABLED, &ai->flags); |
| 3392 | } else |
| 3393 | rc = SUCCESS; |
| 3394 | |
| 3395 | if (lock) |
| 3396 | up(&ai->sem); |
| 3397 | |
| 3398 | if (rc) |
| 3399 | printk(KERN_ERR "%s: Cannot enable MAC, err=%d\n", |
| 3400 | __FUNCTION__,rc); |
| 3401 | return rc; |
| 3402 | } |
| 3403 | |
| 3404 | static void disable_MAC( struct airo_info *ai, int lock ) { |
| 3405 | Cmd cmd; |
| 3406 | Resp rsp; |
| 3407 | |
| 3408 | if (lock && down_interruptible(&ai->sem)) |
| 3409 | return; |
| 3410 | |
| 3411 | if (test_bit(FLAG_ENABLED, &ai->flags)) { |
| 3412 | memset(&cmd, 0, sizeof(cmd)); |
| 3413 | cmd.cmd = MAC_DISABLE; // disable in case already enabled |
| 3414 | issuecommand(ai, &cmd, &rsp); |
| 3415 | clear_bit(FLAG_ENABLED, &ai->flags); |
| 3416 | } |
| 3417 | if (lock) |
| 3418 | up(&ai->sem); |
| 3419 | } |
| 3420 | |
| 3421 | static void enable_interrupts( struct airo_info *ai ) { |
| 3422 | /* Enable the interrupts */ |
| 3423 | OUT4500( ai, EVINTEN, STATUS_INTS ); |
| 3424 | } |
| 3425 | |
| 3426 | static void disable_interrupts( struct airo_info *ai ) { |
| 3427 | OUT4500( ai, EVINTEN, 0 ); |
| 3428 | } |
| 3429 | |
| 3430 | static void mpi_receive_802_3(struct airo_info *ai) |
| 3431 | { |
| 3432 | RxFid rxd; |
| 3433 | int len = 0; |
| 3434 | struct sk_buff *skb; |
| 3435 | char *buffer; |
| 3436 | #ifdef MICSUPPORT |
| 3437 | int off = 0; |
| 3438 | MICBuffer micbuf; |
| 3439 | #endif |
| 3440 | |
| 3441 | memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd)); |
| 3442 | /* Make sure we got something */ |
| 3443 | if (rxd.rdy && rxd.valid == 0) { |
| 3444 | len = rxd.len + 12; |
| 3445 | if (len < 12 || len > 2048) |
| 3446 | goto badrx; |
| 3447 | |
| 3448 | skb = dev_alloc_skb(len); |
| 3449 | if (!skb) { |
| 3450 | ai->stats.rx_dropped++; |
| 3451 | goto badrx; |
| 3452 | } |
| 3453 | buffer = skb_put(skb,len); |
| 3454 | #ifdef MICSUPPORT |
| 3455 | memcpy(buffer, ai->rxfids[0].virtual_host_addr, ETH_ALEN * 2); |
| 3456 | if (ai->micstats.enabled) { |
| 3457 | memcpy(&micbuf, |
| 3458 | ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2, |
| 3459 | sizeof(micbuf)); |
| 3460 | if (ntohs(micbuf.typelen) <= 0x05DC) { |
| 3461 | if (len <= sizeof(micbuf) + ETH_ALEN * 2) |
| 3462 | goto badmic; |
| 3463 | |
| 3464 | off = sizeof(micbuf); |
| 3465 | skb_trim (skb, len - off); |
| 3466 | } |
| 3467 | } |
| 3468 | memcpy(buffer + ETH_ALEN * 2, |
| 3469 | ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2 + off, |
| 3470 | len - ETH_ALEN * 2 - off); |
| 3471 | if (decapsulate (ai, &micbuf, (etherHead*)buffer, len - off - ETH_ALEN * 2)) { |
| 3472 | badmic: |
| 3473 | dev_kfree_skb_irq (skb); |
| 3474 | goto badrx; |
| 3475 | } |
| 3476 | #else |
| 3477 | memcpy(buffer, ai->rxfids[0].virtual_host_addr, len); |
| 3478 | #endif |
| 3479 | #ifdef WIRELESS_SPY |
| 3480 | if (ai->spy_data.spy_number > 0) { |
| 3481 | char *sa; |
| 3482 | struct iw_quality wstats; |
| 3483 | /* Prepare spy data : addr + qual */ |
| 3484 | sa = buffer + ETH_ALEN; |
| 3485 | wstats.qual = 0; /* XXX Where do I get that info from ??? */ |
| 3486 | wstats.level = 0; |
| 3487 | wstats.updated = 0; |
| 3488 | /* Update spy records */ |
| 3489 | wireless_spy_update(ai->dev, sa, &wstats); |
| 3490 | } |
| 3491 | #endif /* WIRELESS_SPY */ |
| 3492 | |
| 3493 | skb->dev = ai->dev; |
| 3494 | skb->ip_summed = CHECKSUM_NONE; |
| 3495 | skb->protocol = eth_type_trans(skb, ai->dev); |
| 3496 | skb->dev->last_rx = jiffies; |
| 3497 | netif_rx(skb); |
| 3498 | } |
| 3499 | badrx: |
| 3500 | if (rxd.valid == 0) { |
| 3501 | rxd.valid = 1; |
| 3502 | rxd.rdy = 0; |
| 3503 | rxd.len = PKTSIZE; |
| 3504 | memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd)); |
| 3505 | } |
| 3506 | } |
| 3507 | |
| 3508 | void mpi_receive_802_11 (struct airo_info *ai) |
| 3509 | { |
| 3510 | RxFid rxd; |
| 3511 | struct sk_buff *skb = NULL; |
| 3512 | u16 fc, len, hdrlen = 0; |
| 3513 | #pragma pack(1) |
| 3514 | struct { |
| 3515 | u16 status, len; |
| 3516 | u8 rssi[2]; |
| 3517 | u8 rate; |
| 3518 | u8 freq; |
| 3519 | u16 tmp[4]; |
| 3520 | } hdr; |
| 3521 | #pragma pack() |
| 3522 | u16 gap; |
| 3523 | u16 *buffer; |
| 3524 | char *ptr = ai->rxfids[0].virtual_host_addr+4; |
| 3525 | |
| 3526 | memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd)); |
| 3527 | memcpy ((char *)&hdr, ptr, sizeof(hdr)); |
| 3528 | ptr += sizeof(hdr); |
| 3529 | /* Bad CRC. Ignore packet */ |
| 3530 | if (le16_to_cpu(hdr.status) & 2) |
| 3531 | hdr.len = 0; |
| 3532 | if (ai->wifidev == NULL) |
| 3533 | hdr.len = 0; |
| 3534 | len = le16_to_cpu(hdr.len); |
| 3535 | if (len > 2312) { |
| 3536 | printk( KERN_ERR "airo: Bad size %d\n", len ); |
| 3537 | goto badrx; |
| 3538 | } |
| 3539 | if (len == 0) |
| 3540 | goto badrx; |
| 3541 | |
| 3542 | memcpy ((char *)&fc, ptr, sizeof(fc)); |
| 3543 | fc = le16_to_cpu(fc); |
| 3544 | switch (fc & 0xc) { |
| 3545 | case 4: |
| 3546 | if ((fc & 0xe0) == 0xc0) |
| 3547 | hdrlen = 10; |
| 3548 | else |
| 3549 | hdrlen = 16; |
| 3550 | break; |
| 3551 | case 8: |
| 3552 | if ((fc&0x300)==0x300){ |
| 3553 | hdrlen = 30; |
| 3554 | break; |
| 3555 | } |
| 3556 | default: |
| 3557 | hdrlen = 24; |
| 3558 | } |
| 3559 | |
| 3560 | skb = dev_alloc_skb( len + hdrlen + 2 ); |
| 3561 | if ( !skb ) { |
| 3562 | ai->stats.rx_dropped++; |
| 3563 | goto badrx; |
| 3564 | } |
| 3565 | buffer = (u16*)skb_put (skb, len + hdrlen); |
| 3566 | memcpy ((char *)buffer, ptr, hdrlen); |
| 3567 | ptr += hdrlen; |
| 3568 | if (hdrlen == 24) |
| 3569 | ptr += 6; |
| 3570 | memcpy ((char *)&gap, ptr, sizeof(gap)); |
| 3571 | ptr += sizeof(gap); |
| 3572 | gap = le16_to_cpu(gap); |
| 3573 | if (gap) { |
| 3574 | if (gap <= 8) |
| 3575 | ptr += gap; |
| 3576 | else |
| 3577 | printk(KERN_ERR |
| 3578 | "airo: gaplen too big. Problems will follow...\n"); |
| 3579 | } |
| 3580 | memcpy ((char *)buffer + hdrlen, ptr, len); |
| 3581 | ptr += len; |
| 3582 | #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */ |
| 3583 | if (ai->spy_data.spy_number > 0) { |
| 3584 | char *sa; |
| 3585 | struct iw_quality wstats; |
| 3586 | /* Prepare spy data : addr + qual */ |
| 3587 | sa = (char*)buffer + 10; |
| 3588 | wstats.qual = hdr.rssi[0]; |
| 3589 | if (ai->rssi) |
| 3590 | wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm; |
| 3591 | else |
| 3592 | wstats.level = (hdr.rssi[1] + 321) / 2; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 3593 | wstats.noise = ai->wstats.qual.noise; |
| 3594 | wstats.updated = IW_QUAL_QUAL_UPDATED |
| 3595 | | IW_QUAL_LEVEL_UPDATED |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 3596 | | IW_QUAL_DBM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | /* Update spy records */ |
| 3598 | wireless_spy_update(ai->dev, sa, &wstats); |
| 3599 | } |
| 3600 | #endif /* IW_WIRELESS_SPY */ |
| 3601 | skb->mac.raw = skb->data; |
| 3602 | skb->pkt_type = PACKET_OTHERHOST; |
| 3603 | skb->dev = ai->wifidev; |
| 3604 | skb->protocol = htons(ETH_P_802_2); |
| 3605 | skb->dev->last_rx = jiffies; |
| 3606 | skb->ip_summed = CHECKSUM_NONE; |
| 3607 | netif_rx( skb ); |
| 3608 | badrx: |
| 3609 | if (rxd.valid == 0) { |
| 3610 | rxd.valid = 1; |
| 3611 | rxd.rdy = 0; |
| 3612 | rxd.len = PKTSIZE; |
| 3613 | memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd)); |
| 3614 | } |
| 3615 | } |
| 3616 | |
| 3617 | static u16 setup_card(struct airo_info *ai, u8 *mac, int lock) |
| 3618 | { |
| 3619 | Cmd cmd; |
| 3620 | Resp rsp; |
| 3621 | int status; |
| 3622 | int i; |
| 3623 | SsidRid mySsid; |
| 3624 | u16 lastindex; |
| 3625 | WepKeyRid wkr; |
| 3626 | int rc; |
| 3627 | |
| 3628 | memset( &mySsid, 0, sizeof( mySsid ) ); |
| 3629 | if (ai->flash) { |
| 3630 | kfree (ai->flash); |
| 3631 | ai->flash = NULL; |
| 3632 | } |
| 3633 | |
| 3634 | /* The NOP is the first step in getting the card going */ |
| 3635 | cmd.cmd = NOP; |
| 3636 | cmd.parm0 = cmd.parm1 = cmd.parm2 = 0; |
| 3637 | if (lock && down_interruptible(&ai->sem)) |
| 3638 | return ERROR; |
| 3639 | if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) { |
| 3640 | if (lock) |
| 3641 | up(&ai->sem); |
| 3642 | return ERROR; |
| 3643 | } |
| 3644 | disable_MAC( ai, 0); |
| 3645 | |
| 3646 | // Let's figure out if we need to use the AUX port |
| 3647 | if (!test_bit(FLAG_MPI,&ai->flags)) { |
| 3648 | cmd.cmd = CMD_ENABLEAUX; |
| 3649 | if (issuecommand(ai, &cmd, &rsp) != SUCCESS) { |
| 3650 | if (lock) |
| 3651 | up(&ai->sem); |
| 3652 | printk(KERN_ERR "airo: Error checking for AUX port\n"); |
| 3653 | return ERROR; |
| 3654 | } |
| 3655 | if (!aux_bap || rsp.status & 0xff00) { |
| 3656 | ai->bap_read = fast_bap_read; |
| 3657 | printk(KERN_DEBUG "airo: Doing fast bap_reads\n"); |
| 3658 | } else { |
| 3659 | ai->bap_read = aux_bap_read; |
| 3660 | printk(KERN_DEBUG "airo: Doing AUX bap_reads\n"); |
| 3661 | } |
| 3662 | } |
| 3663 | if (lock) |
| 3664 | up(&ai->sem); |
| 3665 | if (ai->config.len == 0) { |
| 3666 | tdsRssiRid rssi_rid; |
| 3667 | CapabilityRid cap_rid; |
| 3668 | |
| 3669 | if (ai->APList) { |
| 3670 | kfree(ai->APList); |
| 3671 | ai->APList = NULL; |
| 3672 | } |
| 3673 | if (ai->SSID) { |
| 3674 | kfree(ai->SSID); |
| 3675 | ai->SSID = NULL; |
| 3676 | } |
| 3677 | // general configuration (read/modify/write) |
| 3678 | status = readConfigRid(ai, lock); |
| 3679 | if ( status != SUCCESS ) return ERROR; |
| 3680 | |
| 3681 | status = readCapabilityRid(ai, &cap_rid, lock); |
| 3682 | if ( status != SUCCESS ) return ERROR; |
| 3683 | |
| 3684 | status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid),lock); |
| 3685 | if ( status == SUCCESS ) { |
| 3686 | if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL) |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 3687 | memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | } |
| 3689 | else { |
| 3690 | if (ai->rssi) { |
| 3691 | kfree(ai->rssi); |
| 3692 | ai->rssi = NULL; |
| 3693 | } |
| 3694 | if (cap_rid.softCap & 8) |
| 3695 | ai->config.rmode |= RXMODE_NORMALIZED_RSSI; |
| 3696 | else |
| 3697 | printk(KERN_WARNING "airo: unknown received signal level scale\n"); |
| 3698 | } |
| 3699 | ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS; |
| 3700 | ai->config.authType = AUTH_OPEN; |
| 3701 | ai->config.modulation = MOD_CCK; |
| 3702 | |
| 3703 | #ifdef MICSUPPORT |
| 3704 | if ((cap_rid.len>=sizeof(cap_rid)) && (cap_rid.extSoftCap&1) && |
| 3705 | (micsetup(ai) == SUCCESS)) { |
| 3706 | ai->config.opmode |= MODE_MIC; |
| 3707 | set_bit(FLAG_MIC_CAPABLE, &ai->flags); |
| 3708 | } |
| 3709 | #endif |
| 3710 | |
| 3711 | /* Save off the MAC */ |
| 3712 | for( i = 0; i < ETH_ALEN; i++ ) { |
| 3713 | mac[i] = ai->config.macAddr[i]; |
| 3714 | } |
| 3715 | |
| 3716 | /* Check to see if there are any insmod configured |
| 3717 | rates to add */ |
| 3718 | if ( rates[0] ) { |
| 3719 | int i = 0; |
| 3720 | memset(ai->config.rates,0,sizeof(ai->config.rates)); |
| 3721 | for( i = 0; i < 8 && rates[i]; i++ ) { |
| 3722 | ai->config.rates[i] = rates[i]; |
| 3723 | } |
| 3724 | } |
| 3725 | if ( basic_rate > 0 ) { |
| 3726 | int i; |
| 3727 | for( i = 0; i < 8; i++ ) { |
| 3728 | if ( ai->config.rates[i] == basic_rate || |
| 3729 | !ai->config.rates ) { |
| 3730 | ai->config.rates[i] = basic_rate | 0x80; |
| 3731 | break; |
| 3732 | } |
| 3733 | } |
| 3734 | } |
| 3735 | set_bit (FLAG_COMMIT, &ai->flags); |
| 3736 | } |
| 3737 | |
| 3738 | /* Setup the SSIDs if present */ |
| 3739 | if ( ssids[0] ) { |
| 3740 | int i; |
| 3741 | for( i = 0; i < 3 && ssids[i]; i++ ) { |
| 3742 | mySsid.ssids[i].len = strlen(ssids[i]); |
| 3743 | if ( mySsid.ssids[i].len > 32 ) |
| 3744 | mySsid.ssids[i].len = 32; |
| 3745 | memcpy(mySsid.ssids[i].ssid, ssids[i], |
| 3746 | mySsid.ssids[i].len); |
| 3747 | } |
| 3748 | mySsid.len = sizeof(mySsid); |
| 3749 | } |
| 3750 | |
| 3751 | status = writeConfigRid(ai, lock); |
| 3752 | if ( status != SUCCESS ) return ERROR; |
| 3753 | |
| 3754 | /* Set up the SSID list */ |
| 3755 | if ( ssids[0] ) { |
| 3756 | status = writeSsidRid(ai, &mySsid, lock); |
| 3757 | if ( status != SUCCESS ) return ERROR; |
| 3758 | } |
| 3759 | |
| 3760 | status = enable_MAC(ai, &rsp, lock); |
| 3761 | if ( status != SUCCESS || (rsp.status & 0xFF00) != 0) { |
| 3762 | printk( KERN_ERR "airo: Bad MAC enable reason = %x, rid = %x, offset = %d\n", rsp.rsp0, rsp.rsp1, rsp.rsp2 ); |
| 3763 | return ERROR; |
| 3764 | } |
| 3765 | |
| 3766 | /* Grab the initial wep key, we gotta save it for auto_wep */ |
| 3767 | rc = readWepKeyRid(ai, &wkr, 1, lock); |
| 3768 | if (rc == SUCCESS) do { |
| 3769 | lastindex = wkr.kindex; |
| 3770 | if (wkr.kindex == 0xffff) { |
| 3771 | ai->defindex = wkr.mac[0]; |
| 3772 | } |
| 3773 | rc = readWepKeyRid(ai, &wkr, 0, lock); |
| 3774 | } while(lastindex != wkr.kindex); |
| 3775 | |
| 3776 | if (auto_wep) { |
| 3777 | ai->expires = RUN_AT(3*HZ); |
| 3778 | wake_up_interruptible(&ai->thr_wait); |
| 3779 | } |
| 3780 | |
| 3781 | return SUCCESS; |
| 3782 | } |
| 3783 | |
| 3784 | static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) { |
| 3785 | // Im really paranoid about letting it run forever! |
| 3786 | int max_tries = 600000; |
| 3787 | |
| 3788 | if (IN4500(ai, EVSTAT) & EV_CMD) |
| 3789 | OUT4500(ai, EVACK, EV_CMD); |
| 3790 | |
| 3791 | OUT4500(ai, PARAM0, pCmd->parm0); |
| 3792 | OUT4500(ai, PARAM1, pCmd->parm1); |
| 3793 | OUT4500(ai, PARAM2, pCmd->parm2); |
| 3794 | OUT4500(ai, COMMAND, pCmd->cmd); |
| 3795 | |
| 3796 | while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) { |
| 3797 | if ((IN4500(ai, COMMAND)) == pCmd->cmd) |
| 3798 | // PC4500 didn't notice command, try again |
| 3799 | OUT4500(ai, COMMAND, pCmd->cmd); |
| 3800 | if (!in_atomic() && (max_tries & 255) == 0) |
| 3801 | schedule(); |
| 3802 | } |
| 3803 | |
| 3804 | if ( max_tries == -1 ) { |
| 3805 | printk( KERN_ERR |
| 3806 | "airo: Max tries exceeded when issueing command\n" ); |
| 3807 | if (IN4500(ai, COMMAND) & COMMAND_BUSY) |
| 3808 | OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY); |
| 3809 | return ERROR; |
| 3810 | } |
| 3811 | |
| 3812 | // command completed |
| 3813 | pRsp->status = IN4500(ai, STATUS); |
| 3814 | pRsp->rsp0 = IN4500(ai, RESP0); |
| 3815 | pRsp->rsp1 = IN4500(ai, RESP1); |
| 3816 | pRsp->rsp2 = IN4500(ai, RESP2); |
| 3817 | if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET) { |
| 3818 | printk (KERN_ERR "airo: cmd= %x\n", pCmd->cmd); |
| 3819 | printk (KERN_ERR "airo: status= %x\n", pRsp->status); |
| 3820 | printk (KERN_ERR "airo: Rsp0= %x\n", pRsp->rsp0); |
| 3821 | printk (KERN_ERR "airo: Rsp1= %x\n", pRsp->rsp1); |
| 3822 | printk (KERN_ERR "airo: Rsp2= %x\n", pRsp->rsp2); |
| 3823 | } |
| 3824 | |
| 3825 | // clear stuck command busy if necessary |
| 3826 | if (IN4500(ai, COMMAND) & COMMAND_BUSY) { |
| 3827 | OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY); |
| 3828 | } |
| 3829 | // acknowledge processing the status/response |
| 3830 | OUT4500(ai, EVACK, EV_CMD); |
| 3831 | |
| 3832 | return SUCCESS; |
| 3833 | } |
| 3834 | |
| 3835 | /* Sets up the bap to start exchange data. whichbap should |
| 3836 | * be one of the BAP0 or BAP1 defines. Locks should be held before |
| 3837 | * calling! */ |
| 3838 | static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap ) |
| 3839 | { |
| 3840 | int timeout = 50; |
| 3841 | int max_tries = 3; |
| 3842 | |
| 3843 | OUT4500(ai, SELECT0+whichbap, rid); |
| 3844 | OUT4500(ai, OFFSET0+whichbap, offset); |
| 3845 | while (1) { |
| 3846 | int status = IN4500(ai, OFFSET0+whichbap); |
| 3847 | if (status & BAP_BUSY) { |
| 3848 | /* This isn't really a timeout, but its kinda |
| 3849 | close */ |
| 3850 | if (timeout--) { |
| 3851 | continue; |
| 3852 | } |
| 3853 | } else if ( status & BAP_ERR ) { |
| 3854 | /* invalid rid or offset */ |
| 3855 | printk( KERN_ERR "airo: BAP error %x %d\n", |
| 3856 | status, whichbap ); |
| 3857 | return ERROR; |
| 3858 | } else if (status & BAP_DONE) { // success |
| 3859 | return SUCCESS; |
| 3860 | } |
| 3861 | if ( !(max_tries--) ) { |
| 3862 | printk( KERN_ERR |
| 3863 | "airo: BAP setup error too many retries\n" ); |
| 3864 | return ERROR; |
| 3865 | } |
| 3866 | // -- PC4500 missed it, try again |
| 3867 | OUT4500(ai, SELECT0+whichbap, rid); |
| 3868 | OUT4500(ai, OFFSET0+whichbap, offset); |
| 3869 | timeout = 50; |
| 3870 | } |
| 3871 | } |
| 3872 | |
| 3873 | /* should only be called by aux_bap_read. This aux function and the |
| 3874 | following use concepts not documented in the developers guide. I |
| 3875 | got them from a patch given to my by Aironet */ |
| 3876 | static u16 aux_setup(struct airo_info *ai, u16 page, |
| 3877 | u16 offset, u16 *len) |
| 3878 | { |
| 3879 | u16 next; |
| 3880 | |
| 3881 | OUT4500(ai, AUXPAGE, page); |
| 3882 | OUT4500(ai, AUXOFF, 0); |
| 3883 | next = IN4500(ai, AUXDATA); |
| 3884 | *len = IN4500(ai, AUXDATA)&0xff; |
| 3885 | if (offset != 4) OUT4500(ai, AUXOFF, offset); |
| 3886 | return next; |
| 3887 | } |
| 3888 | |
| 3889 | /* requires call to bap_setup() first */ |
| 3890 | static int aux_bap_read(struct airo_info *ai, u16 *pu16Dst, |
| 3891 | int bytelen, int whichbap) |
| 3892 | { |
| 3893 | u16 len; |
| 3894 | u16 page; |
| 3895 | u16 offset; |
| 3896 | u16 next; |
| 3897 | int words; |
| 3898 | int i; |
| 3899 | unsigned long flags; |
| 3900 | |
| 3901 | spin_lock_irqsave(&ai->aux_lock, flags); |
| 3902 | page = IN4500(ai, SWS0+whichbap); |
| 3903 | offset = IN4500(ai, SWS2+whichbap); |
| 3904 | next = aux_setup(ai, page, offset, &len); |
| 3905 | words = (bytelen+1)>>1; |
| 3906 | |
| 3907 | for (i=0; i<words;) { |
| 3908 | int count; |
| 3909 | count = (len>>1) < (words-i) ? (len>>1) : (words-i); |
| 3910 | if ( !do8bitIO ) |
| 3911 | insw( ai->dev->base_addr+DATA0+whichbap, |
| 3912 | pu16Dst+i,count ); |
| 3913 | else |
| 3914 | insb( ai->dev->base_addr+DATA0+whichbap, |
| 3915 | pu16Dst+i, count << 1 ); |
| 3916 | i += count; |
| 3917 | if (i<words) { |
| 3918 | next = aux_setup(ai, next, 4, &len); |
| 3919 | } |
| 3920 | } |
| 3921 | spin_unlock_irqrestore(&ai->aux_lock, flags); |
| 3922 | return SUCCESS; |
| 3923 | } |
| 3924 | |
| 3925 | |
| 3926 | /* requires call to bap_setup() first */ |
| 3927 | static int fast_bap_read(struct airo_info *ai, u16 *pu16Dst, |
| 3928 | int bytelen, int whichbap) |
| 3929 | { |
| 3930 | bytelen = (bytelen + 1) & (~1); // round up to even value |
| 3931 | if ( !do8bitIO ) |
| 3932 | insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 ); |
| 3933 | else |
| 3934 | insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen ); |
| 3935 | return SUCCESS; |
| 3936 | } |
| 3937 | |
| 3938 | /* requires call to bap_setup() first */ |
| 3939 | static int bap_write(struct airo_info *ai, const u16 *pu16Src, |
| 3940 | int bytelen, int whichbap) |
| 3941 | { |
| 3942 | bytelen = (bytelen + 1) & (~1); // round up to even value |
| 3943 | if ( !do8bitIO ) |
| 3944 | outsw( ai->dev->base_addr+DATA0+whichbap, |
| 3945 | pu16Src, bytelen>>1 ); |
| 3946 | else |
| 3947 | outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen ); |
| 3948 | return SUCCESS; |
| 3949 | } |
| 3950 | |
| 3951 | static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd) |
| 3952 | { |
| 3953 | Cmd cmd; /* for issuing commands */ |
| 3954 | Resp rsp; /* response from commands */ |
| 3955 | u16 status; |
| 3956 | |
| 3957 | memset(&cmd, 0, sizeof(cmd)); |
| 3958 | cmd.cmd = accmd; |
| 3959 | cmd.parm0 = rid; |
| 3960 | status = issuecommand(ai, &cmd, &rsp); |
| 3961 | if (status != 0) return status; |
| 3962 | if ( (rsp.status & 0x7F00) != 0) { |
| 3963 | return (accmd << 8) + (rsp.rsp0 & 0xFF); |
| 3964 | } |
| 3965 | return 0; |
| 3966 | } |
| 3967 | |
| 3968 | /* Note, that we are using BAP1 which is also used by transmit, so |
| 3969 | * we must get a lock. */ |
| 3970 | static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, int lock) |
| 3971 | { |
| 3972 | u16 status; |
| 3973 | int rc = SUCCESS; |
| 3974 | |
| 3975 | if (lock) { |
| 3976 | if (down_interruptible(&ai->sem)) |
| 3977 | return ERROR; |
| 3978 | } |
| 3979 | if (test_bit(FLAG_MPI,&ai->flags)) { |
| 3980 | Cmd cmd; |
| 3981 | Resp rsp; |
| 3982 | |
| 3983 | memset(&cmd, 0, sizeof(cmd)); |
| 3984 | memset(&rsp, 0, sizeof(rsp)); |
| 3985 | ai->config_desc.rid_desc.valid = 1; |
| 3986 | ai->config_desc.rid_desc.len = RIDSIZE; |
| 3987 | ai->config_desc.rid_desc.rid = 0; |
| 3988 | ai->config_desc.rid_desc.host_addr = ai->ridbus; |
| 3989 | |
| 3990 | cmd.cmd = CMD_ACCESS; |
| 3991 | cmd.parm0 = rid; |
| 3992 | |
| 3993 | memcpy_toio(ai->config_desc.card_ram_off, |
| 3994 | &ai->config_desc.rid_desc, sizeof(Rid)); |
| 3995 | |
| 3996 | rc = issuecommand(ai, &cmd, &rsp); |
| 3997 | |
| 3998 | if (rsp.status & 0x7f00) |
| 3999 | rc = rsp.rsp0; |
| 4000 | if (!rc) |
| 4001 | memcpy(pBuf, ai->config_desc.virtual_host_addr, len); |
| 4002 | goto done; |
| 4003 | } else { |
| 4004 | if ((status = PC4500_accessrid(ai, rid, CMD_ACCESS))!=SUCCESS) { |
| 4005 | rc = status; |
| 4006 | goto done; |
| 4007 | } |
| 4008 | if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) { |
| 4009 | rc = ERROR; |
| 4010 | goto done; |
| 4011 | } |
| 4012 | // read the rid length field |
| 4013 | bap_read(ai, pBuf, 2, BAP1); |
| 4014 | // length for remaining part of rid |
| 4015 | len = min(len, (int)le16_to_cpu(*(u16*)pBuf)) - 2; |
| 4016 | |
| 4017 | if ( len <= 2 ) { |
| 4018 | printk( KERN_ERR |
| 4019 | "airo: Rid %x has a length of %d which is too short\n", |
| 4020 | (int)rid, (int)len ); |
| 4021 | rc = ERROR; |
| 4022 | goto done; |
| 4023 | } |
| 4024 | // read remainder of the rid |
| 4025 | rc = bap_read(ai, ((u16*)pBuf)+1, len, BAP1); |
| 4026 | } |
| 4027 | done: |
| 4028 | if (lock) |
| 4029 | up(&ai->sem); |
| 4030 | return rc; |
| 4031 | } |
| 4032 | |
| 4033 | /* Note, that we are using BAP1 which is also used by transmit, so |
| 4034 | * make sure this isnt called when a transmit is happening */ |
| 4035 | static int PC4500_writerid(struct airo_info *ai, u16 rid, |
| 4036 | const void *pBuf, int len, int lock) |
| 4037 | { |
| 4038 | u16 status; |
| 4039 | int rc = SUCCESS; |
| 4040 | |
| 4041 | *(u16*)pBuf = cpu_to_le16((u16)len); |
| 4042 | |
| 4043 | if (lock) { |
| 4044 | if (down_interruptible(&ai->sem)) |
| 4045 | return ERROR; |
| 4046 | } |
| 4047 | if (test_bit(FLAG_MPI,&ai->flags)) { |
| 4048 | Cmd cmd; |
| 4049 | Resp rsp; |
| 4050 | |
| 4051 | if (test_bit(FLAG_ENABLED, &ai->flags)) |
| 4052 | printk(KERN_ERR |
| 4053 | "%s: MAC should be disabled (rid=%04x)\n", |
| 4054 | __FUNCTION__, rid); |
| 4055 | memset(&cmd, 0, sizeof(cmd)); |
| 4056 | memset(&rsp, 0, sizeof(rsp)); |
| 4057 | |
| 4058 | ai->config_desc.rid_desc.valid = 1; |
| 4059 | ai->config_desc.rid_desc.len = *((u16 *)pBuf); |
| 4060 | ai->config_desc.rid_desc.rid = 0; |
| 4061 | |
| 4062 | cmd.cmd = CMD_WRITERID; |
| 4063 | cmd.parm0 = rid; |
| 4064 | |
| 4065 | memcpy_toio(ai->config_desc.card_ram_off, |
| 4066 | &ai->config_desc.rid_desc, sizeof(Rid)); |
| 4067 | |
| 4068 | if (len < 4 || len > 2047) { |
| 4069 | printk(KERN_ERR "%s: len=%d\n",__FUNCTION__,len); |
| 4070 | rc = -1; |
| 4071 | } else { |
| 4072 | memcpy((char *)ai->config_desc.virtual_host_addr, |
| 4073 | pBuf, len); |
| 4074 | |
| 4075 | rc = issuecommand(ai, &cmd, &rsp); |
| 4076 | if ((rc & 0xff00) != 0) { |
| 4077 | printk(KERN_ERR "%s: Write rid Error %d\n", |
| 4078 | __FUNCTION__,rc); |
| 4079 | printk(KERN_ERR "%s: Cmd=%04x\n", |
| 4080 | __FUNCTION__,cmd.cmd); |
| 4081 | } |
| 4082 | |
| 4083 | if ((rsp.status & 0x7f00)) |
| 4084 | rc = rsp.rsp0; |
| 4085 | } |
| 4086 | } else { |
| 4087 | // --- first access so that we can write the rid data |
| 4088 | if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) { |
| 4089 | rc = status; |
| 4090 | goto done; |
| 4091 | } |
| 4092 | // --- now write the rid data |
| 4093 | if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) { |
| 4094 | rc = ERROR; |
| 4095 | goto done; |
| 4096 | } |
| 4097 | bap_write(ai, pBuf, len, BAP1); |
| 4098 | // ---now commit the rid data |
| 4099 | rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS); |
| 4100 | } |
| 4101 | done: |
| 4102 | if (lock) |
| 4103 | up(&ai->sem); |
| 4104 | return rc; |
| 4105 | } |
| 4106 | |
| 4107 | /* Allocates a FID to be used for transmitting packets. We only use |
| 4108 | one for now. */ |
| 4109 | static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw) |
| 4110 | { |
| 4111 | unsigned int loop = 3000; |
| 4112 | Cmd cmd; |
| 4113 | Resp rsp; |
| 4114 | u16 txFid; |
| 4115 | u16 txControl; |
| 4116 | |
| 4117 | cmd.cmd = CMD_ALLOCATETX; |
| 4118 | cmd.parm0 = lenPayload; |
| 4119 | if (down_interruptible(&ai->sem)) |
| 4120 | return ERROR; |
| 4121 | if (issuecommand(ai, &cmd, &rsp) != SUCCESS) { |
| 4122 | txFid = ERROR; |
| 4123 | goto done; |
| 4124 | } |
| 4125 | if ( (rsp.status & 0xFF00) != 0) { |
| 4126 | txFid = ERROR; |
| 4127 | goto done; |
| 4128 | } |
| 4129 | /* wait for the allocate event/indication |
| 4130 | * It makes me kind of nervous that this can just sit here and spin, |
| 4131 | * but in practice it only loops like four times. */ |
| 4132 | while (((IN4500(ai, EVSTAT) & EV_ALLOC) == 0) && --loop); |
| 4133 | if (!loop) { |
| 4134 | txFid = ERROR; |
| 4135 | goto done; |
| 4136 | } |
| 4137 | |
| 4138 | // get the allocated fid and acknowledge |
| 4139 | txFid = IN4500(ai, TXALLOCFID); |
| 4140 | OUT4500(ai, EVACK, EV_ALLOC); |
| 4141 | |
| 4142 | /* The CARD is pretty cool since it converts the ethernet packet |
| 4143 | * into 802.11. Also note that we don't release the FID since we |
| 4144 | * will be using the same one over and over again. */ |
| 4145 | /* We only have to setup the control once since we are not |
| 4146 | * releasing the fid. */ |
| 4147 | if (raw) |
| 4148 | txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11 |
| 4149 | | TXCTL_ETHERNET | TXCTL_NORELEASE); |
| 4150 | else |
| 4151 | txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3 |
| 4152 | | TXCTL_ETHERNET | TXCTL_NORELEASE); |
| 4153 | if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS) |
| 4154 | txFid = ERROR; |
| 4155 | else |
| 4156 | bap_write(ai, &txControl, sizeof(txControl), BAP1); |
| 4157 | |
| 4158 | done: |
| 4159 | up(&ai->sem); |
| 4160 | |
| 4161 | return txFid; |
| 4162 | } |
| 4163 | |
| 4164 | /* In general BAP1 is dedicated to transmiting packets. However, |
| 4165 | since we need a BAP when accessing RIDs, we also use BAP1 for that. |
| 4166 | Make sure the BAP1 spinlock is held when this is called. */ |
| 4167 | static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket) |
| 4168 | { |
| 4169 | u16 payloadLen; |
| 4170 | Cmd cmd; |
| 4171 | Resp rsp; |
| 4172 | int miclen = 0; |
| 4173 | u16 txFid = len; |
| 4174 | MICBuffer pMic; |
| 4175 | |
| 4176 | len >>= 16; |
| 4177 | |
| 4178 | if (len <= ETH_ALEN * 2) { |
| 4179 | printk( KERN_WARNING "Short packet %d\n", len ); |
| 4180 | return ERROR; |
| 4181 | } |
| 4182 | len -= ETH_ALEN * 2; |
| 4183 | |
| 4184 | #ifdef MICSUPPORT |
| 4185 | if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled && |
| 4186 | (ntohs(((u16 *)pPacket)[6]) != 0x888E)) { |
| 4187 | if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS) |
| 4188 | return ERROR; |
| 4189 | miclen = sizeof(pMic); |
| 4190 | } |
| 4191 | #endif |
| 4192 | |
| 4193 | // packet is destination[6], source[6], payload[len-12] |
| 4194 | // write the payload length and dst/src/payload |
| 4195 | if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR; |
| 4196 | /* The hardware addresses aren't counted as part of the payload, so |
| 4197 | * we have to subtract the 12 bytes for the addresses off */ |
| 4198 | payloadLen = cpu_to_le16(len + miclen); |
| 4199 | bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1); |
| 4200 | bap_write(ai, (const u16*)pPacket, sizeof(etherHead), BAP1); |
| 4201 | if (miclen) |
| 4202 | bap_write(ai, (const u16*)&pMic, miclen, BAP1); |
| 4203 | bap_write(ai, (const u16*)(pPacket + sizeof(etherHead)), len, BAP1); |
| 4204 | // issue the transmit command |
| 4205 | memset( &cmd, 0, sizeof( cmd ) ); |
| 4206 | cmd.cmd = CMD_TRANSMIT; |
| 4207 | cmd.parm0 = txFid; |
| 4208 | if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR; |
| 4209 | if ( (rsp.status & 0xFF00) != 0) return ERROR; |
| 4210 | return SUCCESS; |
| 4211 | } |
| 4212 | |
| 4213 | static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket) |
| 4214 | { |
| 4215 | u16 fc, payloadLen; |
| 4216 | Cmd cmd; |
| 4217 | Resp rsp; |
| 4218 | int hdrlen; |
| 4219 | struct { |
| 4220 | u8 addr4[ETH_ALEN]; |
| 4221 | u16 gaplen; |
| 4222 | u8 gap[6]; |
| 4223 | } gap; |
| 4224 | u16 txFid = len; |
| 4225 | len >>= 16; |
| 4226 | gap.gaplen = 6; |
| 4227 | |
| 4228 | fc = le16_to_cpu(*(const u16*)pPacket); |
| 4229 | switch (fc & 0xc) { |
| 4230 | case 4: |
| 4231 | if ((fc & 0xe0) == 0xc0) |
| 4232 | hdrlen = 10; |
| 4233 | else |
| 4234 | hdrlen = 16; |
| 4235 | break; |
| 4236 | case 8: |
| 4237 | if ((fc&0x300)==0x300){ |
| 4238 | hdrlen = 30; |
| 4239 | break; |
| 4240 | } |
| 4241 | default: |
| 4242 | hdrlen = 24; |
| 4243 | } |
| 4244 | |
| 4245 | if (len < hdrlen) { |
| 4246 | printk( KERN_WARNING "Short packet %d\n", len ); |
| 4247 | return ERROR; |
| 4248 | } |
| 4249 | |
| 4250 | /* packet is 802.11 header + payload |
| 4251 | * write the payload length and dst/src/payload */ |
| 4252 | if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR; |
| 4253 | /* The 802.11 header aren't counted as part of the payload, so |
| 4254 | * we have to subtract the header bytes off */ |
| 4255 | payloadLen = cpu_to_le16(len-hdrlen); |
| 4256 | bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1); |
| 4257 | if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR; |
| 4258 | bap_write(ai, (const u16*)pPacket, hdrlen, BAP1); |
| 4259 | bap_write(ai, hdrlen == 30 ? |
| 4260 | (const u16*)&gap.gaplen : (const u16*)&gap, 38 - hdrlen, BAP1); |
| 4261 | |
| 4262 | bap_write(ai, (const u16*)(pPacket + hdrlen), len - hdrlen, BAP1); |
| 4263 | // issue the transmit command |
| 4264 | memset( &cmd, 0, sizeof( cmd ) ); |
| 4265 | cmd.cmd = CMD_TRANSMIT; |
| 4266 | cmd.parm0 = txFid; |
| 4267 | if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR; |
| 4268 | if ( (rsp.status & 0xFF00) != 0) return ERROR; |
| 4269 | return SUCCESS; |
| 4270 | } |
| 4271 | |
| 4272 | /* |
| 4273 | * This is the proc_fs routines. It is a bit messier than I would |
| 4274 | * like! Feel free to clean it up! |
| 4275 | */ |
| 4276 | |
| 4277 | static ssize_t proc_read( struct file *file, |
| 4278 | char __user *buffer, |
| 4279 | size_t len, |
| 4280 | loff_t *offset); |
| 4281 | |
| 4282 | static ssize_t proc_write( struct file *file, |
| 4283 | const char __user *buffer, |
| 4284 | size_t len, |
| 4285 | loff_t *offset ); |
| 4286 | static int proc_close( struct inode *inode, struct file *file ); |
| 4287 | |
| 4288 | static int proc_stats_open( struct inode *inode, struct file *file ); |
| 4289 | static int proc_statsdelta_open( struct inode *inode, struct file *file ); |
| 4290 | static int proc_status_open( struct inode *inode, struct file *file ); |
| 4291 | static int proc_SSID_open( struct inode *inode, struct file *file ); |
| 4292 | static int proc_APList_open( struct inode *inode, struct file *file ); |
| 4293 | static int proc_BSSList_open( struct inode *inode, struct file *file ); |
| 4294 | static int proc_config_open( struct inode *inode, struct file *file ); |
| 4295 | static int proc_wepkey_open( struct inode *inode, struct file *file ); |
| 4296 | |
| 4297 | static struct file_operations proc_statsdelta_ops = { |
| 4298 | .read = proc_read, |
| 4299 | .open = proc_statsdelta_open, |
| 4300 | .release = proc_close |
| 4301 | }; |
| 4302 | |
| 4303 | static struct file_operations proc_stats_ops = { |
| 4304 | .read = proc_read, |
| 4305 | .open = proc_stats_open, |
| 4306 | .release = proc_close |
| 4307 | }; |
| 4308 | |
| 4309 | static struct file_operations proc_status_ops = { |
| 4310 | .read = proc_read, |
| 4311 | .open = proc_status_open, |
| 4312 | .release = proc_close |
| 4313 | }; |
| 4314 | |
| 4315 | static struct file_operations proc_SSID_ops = { |
| 4316 | .read = proc_read, |
| 4317 | .write = proc_write, |
| 4318 | .open = proc_SSID_open, |
| 4319 | .release = proc_close |
| 4320 | }; |
| 4321 | |
| 4322 | static struct file_operations proc_BSSList_ops = { |
| 4323 | .read = proc_read, |
| 4324 | .write = proc_write, |
| 4325 | .open = proc_BSSList_open, |
| 4326 | .release = proc_close |
| 4327 | }; |
| 4328 | |
| 4329 | static struct file_operations proc_APList_ops = { |
| 4330 | .read = proc_read, |
| 4331 | .write = proc_write, |
| 4332 | .open = proc_APList_open, |
| 4333 | .release = proc_close |
| 4334 | }; |
| 4335 | |
| 4336 | static struct file_operations proc_config_ops = { |
| 4337 | .read = proc_read, |
| 4338 | .write = proc_write, |
| 4339 | .open = proc_config_open, |
| 4340 | .release = proc_close |
| 4341 | }; |
| 4342 | |
| 4343 | static struct file_operations proc_wepkey_ops = { |
| 4344 | .read = proc_read, |
| 4345 | .write = proc_write, |
| 4346 | .open = proc_wepkey_open, |
| 4347 | .release = proc_close |
| 4348 | }; |
| 4349 | |
| 4350 | static struct proc_dir_entry *airo_entry; |
| 4351 | |
| 4352 | struct proc_data { |
| 4353 | int release_buffer; |
| 4354 | int readlen; |
| 4355 | char *rbuffer; |
| 4356 | int writelen; |
| 4357 | int maxwritelen; |
| 4358 | char *wbuffer; |
| 4359 | void (*on_close) (struct inode *, struct file *); |
| 4360 | }; |
| 4361 | |
| 4362 | #ifndef SETPROC_OPS |
| 4363 | #define SETPROC_OPS(entry, ops) (entry)->proc_fops = &(ops) |
| 4364 | #endif |
| 4365 | |
| 4366 | static int setup_proc_entry( struct net_device *dev, |
| 4367 | struct airo_info *apriv ) { |
| 4368 | struct proc_dir_entry *entry; |
| 4369 | /* First setup the device directory */ |
| 4370 | strcpy(apriv->proc_name,dev->name); |
| 4371 | apriv->proc_entry = create_proc_entry(apriv->proc_name, |
| 4372 | S_IFDIR|airo_perm, |
| 4373 | airo_entry); |
| 4374 | apriv->proc_entry->uid = proc_uid; |
| 4375 | apriv->proc_entry->gid = proc_gid; |
| 4376 | apriv->proc_entry->owner = THIS_MODULE; |
| 4377 | |
| 4378 | /* Setup the StatsDelta */ |
| 4379 | entry = create_proc_entry("StatsDelta", |
| 4380 | S_IFREG | (S_IRUGO&proc_perm), |
| 4381 | apriv->proc_entry); |
| 4382 | entry->uid = proc_uid; |
| 4383 | entry->gid = proc_gid; |
| 4384 | entry->data = dev; |
| 4385 | entry->owner = THIS_MODULE; |
| 4386 | SETPROC_OPS(entry, proc_statsdelta_ops); |
| 4387 | |
| 4388 | /* Setup the Stats */ |
| 4389 | entry = create_proc_entry("Stats", |
| 4390 | S_IFREG | (S_IRUGO&proc_perm), |
| 4391 | apriv->proc_entry); |
| 4392 | entry->uid = proc_uid; |
| 4393 | entry->gid = proc_gid; |
| 4394 | entry->data = dev; |
| 4395 | entry->owner = THIS_MODULE; |
| 4396 | SETPROC_OPS(entry, proc_stats_ops); |
| 4397 | |
| 4398 | /* Setup the Status */ |
| 4399 | entry = create_proc_entry("Status", |
| 4400 | S_IFREG | (S_IRUGO&proc_perm), |
| 4401 | apriv->proc_entry); |
| 4402 | entry->uid = proc_uid; |
| 4403 | entry->gid = proc_gid; |
| 4404 | entry->data = dev; |
| 4405 | entry->owner = THIS_MODULE; |
| 4406 | SETPROC_OPS(entry, proc_status_ops); |
| 4407 | |
| 4408 | /* Setup the Config */ |
| 4409 | entry = create_proc_entry("Config", |
| 4410 | S_IFREG | proc_perm, |
| 4411 | apriv->proc_entry); |
| 4412 | entry->uid = proc_uid; |
| 4413 | entry->gid = proc_gid; |
| 4414 | entry->data = dev; |
| 4415 | entry->owner = THIS_MODULE; |
| 4416 | SETPROC_OPS(entry, proc_config_ops); |
| 4417 | |
| 4418 | /* Setup the SSID */ |
| 4419 | entry = create_proc_entry("SSID", |
| 4420 | S_IFREG | proc_perm, |
| 4421 | apriv->proc_entry); |
| 4422 | entry->uid = proc_uid; |
| 4423 | entry->gid = proc_gid; |
| 4424 | entry->data = dev; |
| 4425 | entry->owner = THIS_MODULE; |
| 4426 | SETPROC_OPS(entry, proc_SSID_ops); |
| 4427 | |
| 4428 | /* Setup the APList */ |
| 4429 | entry = create_proc_entry("APList", |
| 4430 | S_IFREG | proc_perm, |
| 4431 | apriv->proc_entry); |
| 4432 | entry->uid = proc_uid; |
| 4433 | entry->gid = proc_gid; |
| 4434 | entry->data = dev; |
| 4435 | entry->owner = THIS_MODULE; |
| 4436 | SETPROC_OPS(entry, proc_APList_ops); |
| 4437 | |
| 4438 | /* Setup the BSSList */ |
| 4439 | entry = create_proc_entry("BSSList", |
| 4440 | S_IFREG | proc_perm, |
| 4441 | apriv->proc_entry); |
| 4442 | entry->uid = proc_uid; |
| 4443 | entry->gid = proc_gid; |
| 4444 | entry->data = dev; |
| 4445 | entry->owner = THIS_MODULE; |
| 4446 | SETPROC_OPS(entry, proc_BSSList_ops); |
| 4447 | |
| 4448 | /* Setup the WepKey */ |
| 4449 | entry = create_proc_entry("WepKey", |
| 4450 | S_IFREG | proc_perm, |
| 4451 | apriv->proc_entry); |
| 4452 | entry->uid = proc_uid; |
| 4453 | entry->gid = proc_gid; |
| 4454 | entry->data = dev; |
| 4455 | entry->owner = THIS_MODULE; |
| 4456 | SETPROC_OPS(entry, proc_wepkey_ops); |
| 4457 | |
| 4458 | return 0; |
| 4459 | } |
| 4460 | |
| 4461 | static int takedown_proc_entry( struct net_device *dev, |
| 4462 | struct airo_info *apriv ) { |
| 4463 | if ( !apriv->proc_entry->namelen ) return 0; |
| 4464 | remove_proc_entry("Stats",apriv->proc_entry); |
| 4465 | remove_proc_entry("StatsDelta",apriv->proc_entry); |
| 4466 | remove_proc_entry("Status",apriv->proc_entry); |
| 4467 | remove_proc_entry("Config",apriv->proc_entry); |
| 4468 | remove_proc_entry("SSID",apriv->proc_entry); |
| 4469 | remove_proc_entry("APList",apriv->proc_entry); |
| 4470 | remove_proc_entry("BSSList",apriv->proc_entry); |
| 4471 | remove_proc_entry("WepKey",apriv->proc_entry); |
| 4472 | remove_proc_entry(apriv->proc_name,airo_entry); |
| 4473 | return 0; |
| 4474 | } |
| 4475 | |
| 4476 | /* |
| 4477 | * What we want from the proc_fs is to be able to efficiently read |
| 4478 | * and write the configuration. To do this, we want to read the |
| 4479 | * configuration when the file is opened and write it when the file is |
| 4480 | * closed. So basically we allocate a read buffer at open and fill it |
| 4481 | * with data, and allocate a write buffer and read it at close. |
| 4482 | */ |
| 4483 | |
| 4484 | /* |
| 4485 | * The read routine is generic, it relies on the preallocated rbuffer |
| 4486 | * to supply the data. |
| 4487 | */ |
| 4488 | static ssize_t proc_read( struct file *file, |
| 4489 | char __user *buffer, |
| 4490 | size_t len, |
| 4491 | loff_t *offset ) |
| 4492 | { |
| 4493 | loff_t pos = *offset; |
| 4494 | struct proc_data *priv = (struct proc_data*)file->private_data; |
| 4495 | |
| 4496 | if (!priv->rbuffer) |
| 4497 | return -EINVAL; |
| 4498 | |
| 4499 | if (pos < 0) |
| 4500 | return -EINVAL; |
| 4501 | if (pos >= priv->readlen) |
| 4502 | return 0; |
| 4503 | if (len > priv->readlen - pos) |
| 4504 | len = priv->readlen - pos; |
| 4505 | if (copy_to_user(buffer, priv->rbuffer + pos, len)) |
| 4506 | return -EFAULT; |
| 4507 | *offset = pos + len; |
| 4508 | return len; |
| 4509 | } |
| 4510 | |
| 4511 | /* |
| 4512 | * The write routine is generic, it fills in a preallocated rbuffer |
| 4513 | * to supply the data. |
| 4514 | */ |
| 4515 | static ssize_t proc_write( struct file *file, |
| 4516 | const char __user *buffer, |
| 4517 | size_t len, |
| 4518 | loff_t *offset ) |
| 4519 | { |
| 4520 | loff_t pos = *offset; |
| 4521 | struct proc_data *priv = (struct proc_data*)file->private_data; |
| 4522 | |
| 4523 | if (!priv->wbuffer) |
| 4524 | return -EINVAL; |
| 4525 | |
| 4526 | if (pos < 0) |
| 4527 | return -EINVAL; |
| 4528 | if (pos >= priv->maxwritelen) |
| 4529 | return 0; |
| 4530 | if (len > priv->maxwritelen - pos) |
| 4531 | len = priv->maxwritelen - pos; |
| 4532 | if (copy_from_user(priv->wbuffer + pos, buffer, len)) |
| 4533 | return -EFAULT; |
| 4534 | if ( pos + len > priv->writelen ) |
| 4535 | priv->writelen = len + file->f_pos; |
| 4536 | *offset = pos + len; |
| 4537 | return len; |
| 4538 | } |
| 4539 | |
| 4540 | static int proc_status_open( struct inode *inode, struct file *file ) { |
| 4541 | struct proc_data *data; |
| 4542 | struct proc_dir_entry *dp = PDE(inode); |
| 4543 | struct net_device *dev = dp->data; |
| 4544 | struct airo_info *apriv = dev->priv; |
| 4545 | CapabilityRid cap_rid; |
| 4546 | StatusRid status_rid; |
| 4547 | int i; |
| 4548 | |
| 4549 | if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
| 4550 | return -ENOMEM; |
| 4551 | memset(file->private_data, 0, sizeof(struct proc_data)); |
| 4552 | data = (struct proc_data *)file->private_data; |
| 4553 | if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) { |
| 4554 | kfree (file->private_data); |
| 4555 | return -ENOMEM; |
| 4556 | } |
| 4557 | |
| 4558 | readStatusRid(apriv, &status_rid, 1); |
| 4559 | readCapabilityRid(apriv, &cap_rid, 1); |
| 4560 | |
| 4561 | i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n", |
| 4562 | status_rid.mode & 1 ? "CFG ": "", |
| 4563 | status_rid.mode & 2 ? "ACT ": "", |
| 4564 | status_rid.mode & 0x10 ? "SYN ": "", |
| 4565 | status_rid.mode & 0x20 ? "LNK ": "", |
| 4566 | status_rid.mode & 0x40 ? "LEAP ": "", |
| 4567 | status_rid.mode & 0x80 ? "PRIV ": "", |
| 4568 | status_rid.mode & 0x100 ? "KEY ": "", |
| 4569 | status_rid.mode & 0x200 ? "WEP ": "", |
| 4570 | status_rid.mode & 0x8000 ? "ERR ": ""); |
| 4571 | sprintf( data->rbuffer+i, "Mode: %x\n" |
| 4572 | "Signal Strength: %d\n" |
| 4573 | "Signal Quality: %d\n" |
| 4574 | "SSID: %-.*s\n" |
| 4575 | "AP: %-.16s\n" |
| 4576 | "Freq: %d\n" |
| 4577 | "BitRate: %dmbs\n" |
| 4578 | "Driver Version: %s\n" |
| 4579 | "Device: %s\nManufacturer: %s\nFirmware Version: %s\n" |
| 4580 | "Radio type: %x\nCountry: %x\nHardware Version: %x\n" |
| 4581 | "Software Version: %x\nSoftware Subversion: %x\n" |
| 4582 | "Boot block version: %x\n", |
| 4583 | (int)status_rid.mode, |
| 4584 | (int)status_rid.normalizedSignalStrength, |
| 4585 | (int)status_rid.signalQuality, |
| 4586 | (int)status_rid.SSIDlen, |
| 4587 | status_rid.SSID, |
| 4588 | status_rid.apName, |
| 4589 | (int)status_rid.channel, |
| 4590 | (int)status_rid.currentXmitRate/2, |
| 4591 | version, |
| 4592 | cap_rid.prodName, |
| 4593 | cap_rid.manName, |
| 4594 | cap_rid.prodVer, |
| 4595 | cap_rid.radioType, |
| 4596 | cap_rid.country, |
| 4597 | cap_rid.hardVer, |
| 4598 | (int)cap_rid.softVer, |
| 4599 | (int)cap_rid.softSubVer, |
| 4600 | (int)cap_rid.bootBlockVer ); |
| 4601 | data->readlen = strlen( data->rbuffer ); |
| 4602 | return 0; |
| 4603 | } |
| 4604 | |
| 4605 | static int proc_stats_rid_open(struct inode*, struct file*, u16); |
| 4606 | static int proc_statsdelta_open( struct inode *inode, |
| 4607 | struct file *file ) { |
| 4608 | if (file->f_mode&FMODE_WRITE) { |
| 4609 | return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR); |
| 4610 | } |
| 4611 | return proc_stats_rid_open(inode, file, RID_STATSDELTA); |
| 4612 | } |
| 4613 | |
| 4614 | static int proc_stats_open( struct inode *inode, struct file *file ) { |
| 4615 | return proc_stats_rid_open(inode, file, RID_STATS); |
| 4616 | } |
| 4617 | |
| 4618 | static int proc_stats_rid_open( struct inode *inode, |
| 4619 | struct file *file, |
| 4620 | u16 rid ) { |
| 4621 | struct proc_data *data; |
| 4622 | struct proc_dir_entry *dp = PDE(inode); |
| 4623 | struct net_device *dev = dp->data; |
| 4624 | struct airo_info *apriv = dev->priv; |
| 4625 | StatsRid stats; |
| 4626 | int i, j; |
| 4627 | u32 *vals = stats.vals; |
| 4628 | |
| 4629 | if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
| 4630 | return -ENOMEM; |
| 4631 | memset(file->private_data, 0, sizeof(struct proc_data)); |
| 4632 | data = (struct proc_data *)file->private_data; |
| 4633 | if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) { |
| 4634 | kfree (file->private_data); |
| 4635 | return -ENOMEM; |
| 4636 | } |
| 4637 | |
| 4638 | readStatsRid(apriv, &stats, rid, 1); |
| 4639 | |
| 4640 | j = 0; |
| 4641 | for(i=0; statsLabels[i]!=(char *)-1 && |
| 4642 | i*4<stats.len; i++){ |
| 4643 | if (!statsLabels[i]) continue; |
| 4644 | if (j+strlen(statsLabels[i])+16>4096) { |
| 4645 | printk(KERN_WARNING |
| 4646 | "airo: Potentially disasterous buffer overflow averted!\n"); |
| 4647 | break; |
| 4648 | } |
| 4649 | j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i], vals[i]); |
| 4650 | } |
| 4651 | if (i*4>=stats.len){ |
| 4652 | printk(KERN_WARNING |
| 4653 | "airo: Got a short rid\n"); |
| 4654 | } |
| 4655 | data->readlen = j; |
| 4656 | return 0; |
| 4657 | } |
| 4658 | |
| 4659 | static int get_dec_u16( char *buffer, int *start, int limit ) { |
| 4660 | u16 value; |
| 4661 | int valid = 0; |
| 4662 | for( value = 0; buffer[*start] >= '0' && |
| 4663 | buffer[*start] <= '9' && |
| 4664 | *start < limit; (*start)++ ) { |
| 4665 | valid = 1; |
| 4666 | value *= 10; |
| 4667 | value += buffer[*start] - '0'; |
| 4668 | } |
| 4669 | if ( !valid ) return -1; |
| 4670 | return value; |
| 4671 | } |
| 4672 | |
| 4673 | static int airo_config_commit(struct net_device *dev, |
| 4674 | struct iw_request_info *info, void *zwrq, |
| 4675 | char *extra); |
| 4676 | |
| 4677 | static void proc_config_on_close( struct inode *inode, struct file *file ) { |
| 4678 | struct proc_data *data = file->private_data; |
| 4679 | struct proc_dir_entry *dp = PDE(inode); |
| 4680 | struct net_device *dev = dp->data; |
| 4681 | struct airo_info *ai = dev->priv; |
| 4682 | char *line; |
| 4683 | |
| 4684 | if ( !data->writelen ) return; |
| 4685 | |
| 4686 | readConfigRid(ai, 1); |
| 4687 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4688 | |
| 4689 | line = data->wbuffer; |
| 4690 | while( line[0] ) { |
| 4691 | /*** Mode processing */ |
| 4692 | if ( !strncmp( line, "Mode: ", 6 ) ) { |
| 4693 | line += 6; |
| 4694 | if ((ai->config.rmode & 0xff) >= RXMODE_RFMON) |
| 4695 | set_bit (FLAG_RESET, &ai->flags); |
| 4696 | ai->config.rmode &= 0xfe00; |
| 4697 | clear_bit (FLAG_802_11, &ai->flags); |
| 4698 | ai->config.opmode &= 0xFF00; |
| 4699 | ai->config.scanMode = SCANMODE_ACTIVE; |
| 4700 | if ( line[0] == 'a' ) { |
| 4701 | ai->config.opmode |= 0; |
| 4702 | } else { |
| 4703 | ai->config.opmode |= 1; |
| 4704 | if ( line[0] == 'r' ) { |
| 4705 | ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER; |
| 4706 | ai->config.scanMode = SCANMODE_PASSIVE; |
| 4707 | set_bit (FLAG_802_11, &ai->flags); |
| 4708 | } else if ( line[0] == 'y' ) { |
| 4709 | ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER; |
| 4710 | ai->config.scanMode = SCANMODE_PASSIVE; |
| 4711 | set_bit (FLAG_802_11, &ai->flags); |
| 4712 | } else if ( line[0] == 'l' ) |
| 4713 | ai->config.rmode |= RXMODE_LANMON; |
| 4714 | } |
| 4715 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4716 | } |
| 4717 | |
| 4718 | /*** Radio status */ |
| 4719 | else if (!strncmp(line,"Radio: ", 7)) { |
| 4720 | line += 7; |
| 4721 | if (!strncmp(line,"off",3)) { |
| 4722 | set_bit (FLAG_RADIO_OFF, &ai->flags); |
| 4723 | } else { |
| 4724 | clear_bit (FLAG_RADIO_OFF, &ai->flags); |
| 4725 | } |
| 4726 | } |
| 4727 | /*** NodeName processing */ |
| 4728 | else if ( !strncmp( line, "NodeName: ", 10 ) ) { |
| 4729 | int j; |
| 4730 | |
| 4731 | line += 10; |
| 4732 | memset( ai->config.nodeName, 0, 16 ); |
| 4733 | /* Do the name, assume a space between the mode and node name */ |
| 4734 | for( j = 0; j < 16 && line[j] != '\n'; j++ ) { |
| 4735 | ai->config.nodeName[j] = line[j]; |
| 4736 | } |
| 4737 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4738 | } |
| 4739 | |
| 4740 | /*** PowerMode processing */ |
| 4741 | else if ( !strncmp( line, "PowerMode: ", 11 ) ) { |
| 4742 | line += 11; |
| 4743 | if ( !strncmp( line, "PSPCAM", 6 ) ) { |
| 4744 | ai->config.powerSaveMode = POWERSAVE_PSPCAM; |
| 4745 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4746 | } else if ( !strncmp( line, "PSP", 3 ) ) { |
| 4747 | ai->config.powerSaveMode = POWERSAVE_PSP; |
| 4748 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4749 | } else { |
| 4750 | ai->config.powerSaveMode = POWERSAVE_CAM; |
| 4751 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4752 | } |
| 4753 | } else if ( !strncmp( line, "DataRates: ", 11 ) ) { |
| 4754 | int v, i = 0, k = 0; /* i is index into line, |
| 4755 | k is index to rates */ |
| 4756 | |
| 4757 | line += 11; |
| 4758 | while((v = get_dec_u16(line, &i, 3))!=-1) { |
| 4759 | ai->config.rates[k++] = (u8)v; |
| 4760 | line += i + 1; |
| 4761 | i = 0; |
| 4762 | } |
| 4763 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4764 | } else if ( !strncmp( line, "Channel: ", 9 ) ) { |
| 4765 | int v, i = 0; |
| 4766 | line += 9; |
| 4767 | v = get_dec_u16(line, &i, i+3); |
| 4768 | if ( v != -1 ) { |
| 4769 | ai->config.channelSet = (u16)v; |
| 4770 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4771 | } |
| 4772 | } else if ( !strncmp( line, "XmitPower: ", 11 ) ) { |
| 4773 | int v, i = 0; |
| 4774 | line += 11; |
| 4775 | v = get_dec_u16(line, &i, i+3); |
| 4776 | if ( v != -1 ) { |
| 4777 | ai->config.txPower = (u16)v; |
| 4778 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4779 | } |
| 4780 | } else if ( !strncmp( line, "WEP: ", 5 ) ) { |
| 4781 | line += 5; |
| 4782 | switch( line[0] ) { |
| 4783 | case 's': |
| 4784 | ai->config.authType = (u16)AUTH_SHAREDKEY; |
| 4785 | break; |
| 4786 | case 'e': |
| 4787 | ai->config.authType = (u16)AUTH_ENCRYPT; |
| 4788 | break; |
| 4789 | default: |
| 4790 | ai->config.authType = (u16)AUTH_OPEN; |
| 4791 | break; |
| 4792 | } |
| 4793 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4794 | } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) { |
| 4795 | int v, i = 0; |
| 4796 | |
| 4797 | line += 16; |
| 4798 | v = get_dec_u16(line, &i, 3); |
| 4799 | v = (v<0) ? 0 : ((v>255) ? 255 : v); |
| 4800 | ai->config.longRetryLimit = (u16)v; |
| 4801 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4802 | } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) { |
| 4803 | int v, i = 0; |
| 4804 | |
| 4805 | line += 17; |
| 4806 | v = get_dec_u16(line, &i, 3); |
| 4807 | v = (v<0) ? 0 : ((v>255) ? 255 : v); |
| 4808 | ai->config.shortRetryLimit = (u16)v; |
| 4809 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4810 | } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) { |
| 4811 | int v, i = 0; |
| 4812 | |
| 4813 | line += 14; |
| 4814 | v = get_dec_u16(line, &i, 4); |
| 4815 | v = (v<0) ? 0 : ((v>2312) ? 2312 : v); |
| 4816 | ai->config.rtsThres = (u16)v; |
| 4817 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4818 | } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) { |
| 4819 | int v, i = 0; |
| 4820 | |
| 4821 | line += 16; |
| 4822 | v = get_dec_u16(line, &i, 5); |
| 4823 | v = (v<0) ? 0 : v; |
| 4824 | ai->config.txLifetime = (u16)v; |
| 4825 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4826 | } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) { |
| 4827 | int v, i = 0; |
| 4828 | |
| 4829 | line += 16; |
| 4830 | v = get_dec_u16(line, &i, 5); |
| 4831 | v = (v<0) ? 0 : v; |
| 4832 | ai->config.rxLifetime = (u16)v; |
| 4833 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4834 | } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) { |
| 4835 | ai->config.txDiversity = |
| 4836 | (line[13]=='l') ? 1 : |
| 4837 | ((line[13]=='r')? 2: 3); |
| 4838 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4839 | } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) { |
| 4840 | ai->config.rxDiversity = |
| 4841 | (line[13]=='l') ? 1 : |
| 4842 | ((line[13]=='r')? 2: 3); |
| 4843 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4844 | } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) { |
| 4845 | int v, i = 0; |
| 4846 | |
| 4847 | line += 15; |
| 4848 | v = get_dec_u16(line, &i, 4); |
| 4849 | v = (v<256) ? 256 : ((v>2312) ? 2312 : v); |
| 4850 | v = v & 0xfffe; /* Make sure its even */ |
| 4851 | ai->config.fragThresh = (u16)v; |
| 4852 | set_bit (FLAG_COMMIT, &ai->flags); |
| 4853 | } else if (!strncmp(line, "Modulation: ", 12)) { |
| 4854 | line += 12; |
| 4855 | switch(*line) { |
| 4856 | case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break; |
| 4857 | case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break; |
| 4858 | case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break; |
| 4859 | default: |
| 4860 | printk( KERN_WARNING "airo: Unknown modulation\n" ); |
| 4861 | } |
| 4862 | } else if (!strncmp(line, "Preamble: ", 10)) { |
| 4863 | line += 10; |
| 4864 | switch(*line) { |
| 4865 | case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break; |
| 4866 | case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break; |
| 4867 | case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break; |
| 4868 | default: printk(KERN_WARNING "airo: Unknown preamble\n"); |
| 4869 | } |
| 4870 | } else { |
| 4871 | printk( KERN_WARNING "Couldn't figure out %s\n", line ); |
| 4872 | } |
| 4873 | while( line[0] && line[0] != '\n' ) line++; |
| 4874 | if ( line[0] ) line++; |
| 4875 | } |
| 4876 | airo_config_commit(dev, NULL, NULL, NULL); |
| 4877 | } |
| 4878 | |
| 4879 | static char *get_rmode(u16 mode) { |
| 4880 | switch(mode&0xff) { |
| 4881 | case RXMODE_RFMON: return "rfmon"; |
| 4882 | case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon"; |
| 4883 | case RXMODE_LANMON: return "lanmon"; |
| 4884 | } |
| 4885 | return "ESS"; |
| 4886 | } |
| 4887 | |
| 4888 | static int proc_config_open( struct inode *inode, struct file *file ) { |
| 4889 | struct proc_data *data; |
| 4890 | struct proc_dir_entry *dp = PDE(inode); |
| 4891 | struct net_device *dev = dp->data; |
| 4892 | struct airo_info *ai = dev->priv; |
| 4893 | int i; |
| 4894 | |
| 4895 | if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
| 4896 | return -ENOMEM; |
| 4897 | memset(file->private_data, 0, sizeof(struct proc_data)); |
| 4898 | data = (struct proc_data *)file->private_data; |
| 4899 | if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) { |
| 4900 | kfree (file->private_data); |
| 4901 | return -ENOMEM; |
| 4902 | } |
| 4903 | if ((data->wbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) { |
| 4904 | kfree (data->rbuffer); |
| 4905 | kfree (file->private_data); |
| 4906 | return -ENOMEM; |
| 4907 | } |
| 4908 | memset( data->wbuffer, 0, 2048 ); |
| 4909 | data->maxwritelen = 2048; |
| 4910 | data->on_close = proc_config_on_close; |
| 4911 | |
| 4912 | readConfigRid(ai, 1); |
| 4913 | |
| 4914 | i = sprintf( data->rbuffer, |
| 4915 | "Mode: %s\n" |
| 4916 | "Radio: %s\n" |
| 4917 | "NodeName: %-16s\n" |
| 4918 | "PowerMode: %s\n" |
| 4919 | "DataRates: %d %d %d %d %d %d %d %d\n" |
| 4920 | "Channel: %d\n" |
| 4921 | "XmitPower: %d\n", |
| 4922 | (ai->config.opmode & 0xFF) == 0 ? "adhoc" : |
| 4923 | (ai->config.opmode & 0xFF) == 1 ? get_rmode(ai->config.rmode): |
| 4924 | (ai->config.opmode & 0xFF) == 2 ? "AP" : |
| 4925 | (ai->config.opmode & 0xFF) == 3 ? "AP RPTR" : "Error", |
| 4926 | test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on", |
| 4927 | ai->config.nodeName, |
| 4928 | ai->config.powerSaveMode == 0 ? "CAM" : |
| 4929 | ai->config.powerSaveMode == 1 ? "PSP" : |
| 4930 | ai->config.powerSaveMode == 2 ? "PSPCAM" : "Error", |
| 4931 | (int)ai->config.rates[0], |
| 4932 | (int)ai->config.rates[1], |
| 4933 | (int)ai->config.rates[2], |
| 4934 | (int)ai->config.rates[3], |
| 4935 | (int)ai->config.rates[4], |
| 4936 | (int)ai->config.rates[5], |
| 4937 | (int)ai->config.rates[6], |
| 4938 | (int)ai->config.rates[7], |
| 4939 | (int)ai->config.channelSet, |
| 4940 | (int)ai->config.txPower |
| 4941 | ); |
| 4942 | sprintf( data->rbuffer + i, |
| 4943 | "LongRetryLimit: %d\n" |
| 4944 | "ShortRetryLimit: %d\n" |
| 4945 | "RTSThreshold: %d\n" |
| 4946 | "TXMSDULifetime: %d\n" |
| 4947 | "RXMSDULifetime: %d\n" |
| 4948 | "TXDiversity: %s\n" |
| 4949 | "RXDiversity: %s\n" |
| 4950 | "FragThreshold: %d\n" |
| 4951 | "WEP: %s\n" |
| 4952 | "Modulation: %s\n" |
| 4953 | "Preamble: %s\n", |
| 4954 | (int)ai->config.longRetryLimit, |
| 4955 | (int)ai->config.shortRetryLimit, |
| 4956 | (int)ai->config.rtsThres, |
| 4957 | (int)ai->config.txLifetime, |
| 4958 | (int)ai->config.rxLifetime, |
| 4959 | ai->config.txDiversity == 1 ? "left" : |
| 4960 | ai->config.txDiversity == 2 ? "right" : "both", |
| 4961 | ai->config.rxDiversity == 1 ? "left" : |
| 4962 | ai->config.rxDiversity == 2 ? "right" : "both", |
| 4963 | (int)ai->config.fragThresh, |
| 4964 | ai->config.authType == AUTH_ENCRYPT ? "encrypt" : |
| 4965 | ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open", |
| 4966 | ai->config.modulation == 0 ? "default" : |
| 4967 | ai->config.modulation == MOD_CCK ? "cck" : |
| 4968 | ai->config.modulation == MOD_MOK ? "mok" : "error", |
| 4969 | ai->config.preamble == PREAMBLE_AUTO ? "auto" : |
| 4970 | ai->config.preamble == PREAMBLE_LONG ? "long" : |
| 4971 | ai->config.preamble == PREAMBLE_SHORT ? "short" : "error" |
| 4972 | ); |
| 4973 | data->readlen = strlen( data->rbuffer ); |
| 4974 | return 0; |
| 4975 | } |
| 4976 | |
| 4977 | static void proc_SSID_on_close( struct inode *inode, struct file *file ) { |
| 4978 | struct proc_data *data = (struct proc_data *)file->private_data; |
| 4979 | struct proc_dir_entry *dp = PDE(inode); |
| 4980 | struct net_device *dev = dp->data; |
| 4981 | struct airo_info *ai = dev->priv; |
| 4982 | SsidRid SSID_rid; |
| 4983 | Resp rsp; |
| 4984 | int i; |
| 4985 | int offset = 0; |
| 4986 | |
| 4987 | if ( !data->writelen ) return; |
| 4988 | |
| 4989 | memset( &SSID_rid, 0, sizeof( SSID_rid ) ); |
| 4990 | |
| 4991 | for( i = 0; i < 3; i++ ) { |
| 4992 | int j; |
| 4993 | for( j = 0; j+offset < data->writelen && j < 32 && |
| 4994 | data->wbuffer[offset+j] != '\n'; j++ ) { |
| 4995 | SSID_rid.ssids[i].ssid[j] = data->wbuffer[offset+j]; |
| 4996 | } |
| 4997 | if ( j == 0 ) break; |
| 4998 | SSID_rid.ssids[i].len = j; |
| 4999 | offset += j; |
| 5000 | while( data->wbuffer[offset] != '\n' && |
| 5001 | offset < data->writelen ) offset++; |
| 5002 | offset++; |
| 5003 | } |
| 5004 | if (i) |
| 5005 | SSID_rid.len = sizeof(SSID_rid); |
| 5006 | disable_MAC(ai, 1); |
| 5007 | writeSsidRid(ai, &SSID_rid, 1); |
| 5008 | enable_MAC(ai, &rsp, 1); |
| 5009 | } |
| 5010 | |
Jesper Juhl | 77933d7 | 2005-07-27 11:46:09 -0700 | [diff] [blame] | 5011 | static inline u8 hexVal(char c) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | if (c>='0' && c<='9') return c -= '0'; |
| 5013 | if (c>='a' && c<='f') return c -= 'a'-10; |
| 5014 | if (c>='A' && c<='F') return c -= 'A'-10; |
| 5015 | return 0; |
| 5016 | } |
| 5017 | |
| 5018 | static void proc_APList_on_close( struct inode *inode, struct file *file ) { |
| 5019 | struct proc_data *data = (struct proc_data *)file->private_data; |
| 5020 | struct proc_dir_entry *dp = PDE(inode); |
| 5021 | struct net_device *dev = dp->data; |
| 5022 | struct airo_info *ai = dev->priv; |
| 5023 | APListRid APList_rid; |
| 5024 | Resp rsp; |
| 5025 | int i; |
| 5026 | |
| 5027 | if ( !data->writelen ) return; |
| 5028 | |
| 5029 | memset( &APList_rid, 0, sizeof(APList_rid) ); |
| 5030 | APList_rid.len = sizeof(APList_rid); |
| 5031 | |
| 5032 | for( i = 0; i < 4 && data->writelen >= (i+1)*6*3; i++ ) { |
| 5033 | int j; |
| 5034 | for( j = 0; j < 6*3 && data->wbuffer[j+i*6*3]; j++ ) { |
| 5035 | switch(j%3) { |
| 5036 | case 0: |
| 5037 | APList_rid.ap[i][j/3]= |
| 5038 | hexVal(data->wbuffer[j+i*6*3])<<4; |
| 5039 | break; |
| 5040 | case 1: |
| 5041 | APList_rid.ap[i][j/3]|= |
| 5042 | hexVal(data->wbuffer[j+i*6*3]); |
| 5043 | break; |
| 5044 | } |
| 5045 | } |
| 5046 | } |
| 5047 | disable_MAC(ai, 1); |
| 5048 | writeAPListRid(ai, &APList_rid, 1); |
| 5049 | enable_MAC(ai, &rsp, 1); |
| 5050 | } |
| 5051 | |
| 5052 | /* This function wraps PC4500_writerid with a MAC disable */ |
| 5053 | static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data, |
| 5054 | int len, int dummy ) { |
| 5055 | int rc; |
| 5056 | Resp rsp; |
| 5057 | |
| 5058 | disable_MAC(ai, 1); |
| 5059 | rc = PC4500_writerid(ai, rid, rid_data, len, 1); |
| 5060 | enable_MAC(ai, &rsp, 1); |
| 5061 | return rc; |
| 5062 | } |
| 5063 | |
| 5064 | /* Returns the length of the key at the index. If index == 0xffff |
| 5065 | * the index of the transmit key is returned. If the key doesn't exist, |
| 5066 | * -1 will be returned. |
| 5067 | */ |
| 5068 | static int get_wep_key(struct airo_info *ai, u16 index) { |
| 5069 | WepKeyRid wkr; |
| 5070 | int rc; |
| 5071 | u16 lastindex; |
| 5072 | |
| 5073 | rc = readWepKeyRid(ai, &wkr, 1, 1); |
| 5074 | if (rc == SUCCESS) do { |
| 5075 | lastindex = wkr.kindex; |
| 5076 | if (wkr.kindex == index) { |
| 5077 | if (index == 0xffff) { |
| 5078 | return wkr.mac[0]; |
| 5079 | } |
| 5080 | return wkr.klen; |
| 5081 | } |
| 5082 | readWepKeyRid(ai, &wkr, 0, 1); |
| 5083 | } while(lastindex != wkr.kindex); |
| 5084 | return -1; |
| 5085 | } |
| 5086 | |
| 5087 | static int set_wep_key(struct airo_info *ai, u16 index, |
| 5088 | const char *key, u16 keylen, int perm, int lock ) { |
| 5089 | static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 }; |
| 5090 | WepKeyRid wkr; |
| 5091 | Resp rsp; |
| 5092 | |
| 5093 | memset(&wkr, 0, sizeof(wkr)); |
| 5094 | if (keylen == 0) { |
| 5095 | // We are selecting which key to use |
| 5096 | wkr.len = sizeof(wkr); |
| 5097 | wkr.kindex = 0xffff; |
| 5098 | wkr.mac[0] = (char)index; |
| 5099 | if (perm) printk(KERN_INFO "Setting transmit key to %d\n", index); |
| 5100 | if (perm) ai->defindex = (char)index; |
| 5101 | } else { |
| 5102 | // We are actually setting the key |
| 5103 | wkr.len = sizeof(wkr); |
| 5104 | wkr.kindex = index; |
| 5105 | wkr.klen = keylen; |
| 5106 | memcpy( wkr.key, key, keylen ); |
| 5107 | memcpy( wkr.mac, macaddr, ETH_ALEN ); |
| 5108 | printk(KERN_INFO "Setting key %d\n", index); |
| 5109 | } |
| 5110 | |
| 5111 | disable_MAC(ai, lock); |
| 5112 | writeWepKeyRid(ai, &wkr, perm, lock); |
| 5113 | enable_MAC(ai, &rsp, lock); |
| 5114 | return 0; |
| 5115 | } |
| 5116 | |
| 5117 | static void proc_wepkey_on_close( struct inode *inode, struct file *file ) { |
| 5118 | struct proc_data *data; |
| 5119 | struct proc_dir_entry *dp = PDE(inode); |
| 5120 | struct net_device *dev = dp->data; |
| 5121 | struct airo_info *ai = dev->priv; |
| 5122 | int i; |
| 5123 | char key[16]; |
| 5124 | u16 index = 0; |
| 5125 | int j = 0; |
| 5126 | |
| 5127 | memset(key, 0, sizeof(key)); |
| 5128 | |
| 5129 | data = (struct proc_data *)file->private_data; |
| 5130 | if ( !data->writelen ) return; |
| 5131 | |
| 5132 | if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' && |
| 5133 | (data->wbuffer[1] == ' ' || data->wbuffer[1] == '\n')) { |
| 5134 | index = data->wbuffer[0] - '0'; |
| 5135 | if (data->wbuffer[1] == '\n') { |
| 5136 | set_wep_key(ai, index, NULL, 0, 1, 1); |
| 5137 | return; |
| 5138 | } |
| 5139 | j = 2; |
| 5140 | } else { |
| 5141 | printk(KERN_ERR "airo: WepKey passed invalid key index\n"); |
| 5142 | return; |
| 5143 | } |
| 5144 | |
| 5145 | for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) { |
| 5146 | switch(i%3) { |
| 5147 | case 0: |
| 5148 | key[i/3] = hexVal(data->wbuffer[i+j])<<4; |
| 5149 | break; |
| 5150 | case 1: |
| 5151 | key[i/3] |= hexVal(data->wbuffer[i+j]); |
| 5152 | break; |
| 5153 | } |
| 5154 | } |
| 5155 | set_wep_key(ai, index, key, i/3, 1, 1); |
| 5156 | } |
| 5157 | |
| 5158 | static int proc_wepkey_open( struct inode *inode, struct file *file ) { |
| 5159 | struct proc_data *data; |
| 5160 | struct proc_dir_entry *dp = PDE(inode); |
| 5161 | struct net_device *dev = dp->data; |
| 5162 | struct airo_info *ai = dev->priv; |
| 5163 | char *ptr; |
| 5164 | WepKeyRid wkr; |
| 5165 | u16 lastindex; |
| 5166 | int j=0; |
| 5167 | int rc; |
| 5168 | |
| 5169 | if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
| 5170 | return -ENOMEM; |
| 5171 | memset(file->private_data, 0, sizeof(struct proc_data)); |
| 5172 | memset(&wkr, 0, sizeof(wkr)); |
| 5173 | data = (struct proc_data *)file->private_data; |
| 5174 | if ((data->rbuffer = kmalloc( 180, GFP_KERNEL )) == NULL) { |
| 5175 | kfree (file->private_data); |
| 5176 | return -ENOMEM; |
| 5177 | } |
| 5178 | memset(data->rbuffer, 0, 180); |
| 5179 | data->writelen = 0; |
| 5180 | data->maxwritelen = 80; |
| 5181 | if ((data->wbuffer = kmalloc( 80, GFP_KERNEL )) == NULL) { |
| 5182 | kfree (data->rbuffer); |
| 5183 | kfree (file->private_data); |
| 5184 | return -ENOMEM; |
| 5185 | } |
| 5186 | memset( data->wbuffer, 0, 80 ); |
| 5187 | data->on_close = proc_wepkey_on_close; |
| 5188 | |
| 5189 | ptr = data->rbuffer; |
| 5190 | strcpy(ptr, "No wep keys\n"); |
| 5191 | rc = readWepKeyRid(ai, &wkr, 1, 1); |
| 5192 | if (rc == SUCCESS) do { |
| 5193 | lastindex = wkr.kindex; |
| 5194 | if (wkr.kindex == 0xffff) { |
| 5195 | j += sprintf(ptr+j, "Tx key = %d\n", |
| 5196 | (int)wkr.mac[0]); |
| 5197 | } else { |
| 5198 | j += sprintf(ptr+j, "Key %d set with length = %d\n", |
| 5199 | (int)wkr.kindex, (int)wkr.klen); |
| 5200 | } |
| 5201 | readWepKeyRid(ai, &wkr, 0, 1); |
| 5202 | } while((lastindex != wkr.kindex) && (j < 180-30)); |
| 5203 | |
| 5204 | data->readlen = strlen( data->rbuffer ); |
| 5205 | return 0; |
| 5206 | } |
| 5207 | |
| 5208 | static int proc_SSID_open( struct inode *inode, struct file *file ) { |
| 5209 | struct proc_data *data; |
| 5210 | struct proc_dir_entry *dp = PDE(inode); |
| 5211 | struct net_device *dev = dp->data; |
| 5212 | struct airo_info *ai = dev->priv; |
| 5213 | int i; |
| 5214 | char *ptr; |
| 5215 | SsidRid SSID_rid; |
| 5216 | |
| 5217 | if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
| 5218 | return -ENOMEM; |
| 5219 | memset(file->private_data, 0, sizeof(struct proc_data)); |
| 5220 | data = (struct proc_data *)file->private_data; |
| 5221 | if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) { |
| 5222 | kfree (file->private_data); |
| 5223 | return -ENOMEM; |
| 5224 | } |
| 5225 | data->writelen = 0; |
| 5226 | data->maxwritelen = 33*3; |
| 5227 | if ((data->wbuffer = kmalloc( 33*3, GFP_KERNEL )) == NULL) { |
| 5228 | kfree (data->rbuffer); |
| 5229 | kfree (file->private_data); |
| 5230 | return -ENOMEM; |
| 5231 | } |
| 5232 | memset( data->wbuffer, 0, 33*3 ); |
| 5233 | data->on_close = proc_SSID_on_close; |
| 5234 | |
| 5235 | readSsidRid(ai, &SSID_rid); |
| 5236 | ptr = data->rbuffer; |
| 5237 | for( i = 0; i < 3; i++ ) { |
| 5238 | int j; |
| 5239 | if ( !SSID_rid.ssids[i].len ) break; |
| 5240 | for( j = 0; j < 32 && |
| 5241 | j < SSID_rid.ssids[i].len && |
| 5242 | SSID_rid.ssids[i].ssid[j]; j++ ) { |
| 5243 | *ptr++ = SSID_rid.ssids[i].ssid[j]; |
| 5244 | } |
| 5245 | *ptr++ = '\n'; |
| 5246 | } |
| 5247 | *ptr = '\0'; |
| 5248 | data->readlen = strlen( data->rbuffer ); |
| 5249 | return 0; |
| 5250 | } |
| 5251 | |
| 5252 | static int proc_APList_open( struct inode *inode, struct file *file ) { |
| 5253 | struct proc_data *data; |
| 5254 | struct proc_dir_entry *dp = PDE(inode); |
| 5255 | struct net_device *dev = dp->data; |
| 5256 | struct airo_info *ai = dev->priv; |
| 5257 | int i; |
| 5258 | char *ptr; |
| 5259 | APListRid APList_rid; |
| 5260 | |
| 5261 | if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
| 5262 | return -ENOMEM; |
| 5263 | memset(file->private_data, 0, sizeof(struct proc_data)); |
| 5264 | data = (struct proc_data *)file->private_data; |
| 5265 | if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) { |
| 5266 | kfree (file->private_data); |
| 5267 | return -ENOMEM; |
| 5268 | } |
| 5269 | data->writelen = 0; |
| 5270 | data->maxwritelen = 4*6*3; |
| 5271 | if ((data->wbuffer = kmalloc( data->maxwritelen, GFP_KERNEL )) == NULL) { |
| 5272 | kfree (data->rbuffer); |
| 5273 | kfree (file->private_data); |
| 5274 | return -ENOMEM; |
| 5275 | } |
| 5276 | memset( data->wbuffer, 0, data->maxwritelen ); |
| 5277 | data->on_close = proc_APList_on_close; |
| 5278 | |
| 5279 | readAPListRid(ai, &APList_rid); |
| 5280 | ptr = data->rbuffer; |
| 5281 | for( i = 0; i < 4; i++ ) { |
| 5282 | // We end when we find a zero MAC |
| 5283 | if ( !*(int*)APList_rid.ap[i] && |
| 5284 | !*(int*)&APList_rid.ap[i][2]) break; |
| 5285 | ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 5286 | (int)APList_rid.ap[i][0], |
| 5287 | (int)APList_rid.ap[i][1], |
| 5288 | (int)APList_rid.ap[i][2], |
| 5289 | (int)APList_rid.ap[i][3], |
| 5290 | (int)APList_rid.ap[i][4], |
| 5291 | (int)APList_rid.ap[i][5]); |
| 5292 | } |
| 5293 | if (i==0) ptr += sprintf(ptr, "Not using specific APs\n"); |
| 5294 | |
| 5295 | *ptr = '\0'; |
| 5296 | data->readlen = strlen( data->rbuffer ); |
| 5297 | return 0; |
| 5298 | } |
| 5299 | |
| 5300 | static int proc_BSSList_open( struct inode *inode, struct file *file ) { |
| 5301 | struct proc_data *data; |
| 5302 | struct proc_dir_entry *dp = PDE(inode); |
| 5303 | struct net_device *dev = dp->data; |
| 5304 | struct airo_info *ai = dev->priv; |
| 5305 | char *ptr; |
| 5306 | BSSListRid BSSList_rid; |
| 5307 | int rc; |
| 5308 | /* If doLoseSync is not 1, we won't do a Lose Sync */ |
| 5309 | int doLoseSync = -1; |
| 5310 | |
| 5311 | if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
| 5312 | return -ENOMEM; |
| 5313 | memset(file->private_data, 0, sizeof(struct proc_data)); |
| 5314 | data = (struct proc_data *)file->private_data; |
| 5315 | if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) { |
| 5316 | kfree (file->private_data); |
| 5317 | return -ENOMEM; |
| 5318 | } |
| 5319 | data->writelen = 0; |
| 5320 | data->maxwritelen = 0; |
| 5321 | data->wbuffer = NULL; |
| 5322 | data->on_close = NULL; |
| 5323 | |
| 5324 | if (file->f_mode & FMODE_WRITE) { |
| 5325 | if (!(file->f_mode & FMODE_READ)) { |
| 5326 | Cmd cmd; |
| 5327 | Resp rsp; |
| 5328 | |
| 5329 | if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN; |
| 5330 | memset(&cmd, 0, sizeof(cmd)); |
| 5331 | cmd.cmd=CMD_LISTBSS; |
| 5332 | if (down_interruptible(&ai->sem)) |
| 5333 | return -ERESTARTSYS; |
| 5334 | issuecommand(ai, &cmd, &rsp); |
| 5335 | up(&ai->sem); |
| 5336 | data->readlen = 0; |
| 5337 | return 0; |
| 5338 | } |
| 5339 | doLoseSync = 1; |
| 5340 | } |
| 5341 | ptr = data->rbuffer; |
| 5342 | /* There is a race condition here if there are concurrent opens. |
| 5343 | Since it is a rare condition, we'll just live with it, otherwise |
| 5344 | we have to add a spin lock... */ |
| 5345 | rc = readBSSListRid(ai, doLoseSync, &BSSList_rid); |
| 5346 | while(rc == 0 && BSSList_rid.index != 0xffff) { |
| 5347 | ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x %*s rssi = %d", |
| 5348 | (int)BSSList_rid.bssid[0], |
| 5349 | (int)BSSList_rid.bssid[1], |
| 5350 | (int)BSSList_rid.bssid[2], |
| 5351 | (int)BSSList_rid.bssid[3], |
| 5352 | (int)BSSList_rid.bssid[4], |
| 5353 | (int)BSSList_rid.bssid[5], |
| 5354 | (int)BSSList_rid.ssidLen, |
| 5355 | BSSList_rid.ssid, |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 5356 | (int)BSSList_rid.dBm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | ptr += sprintf(ptr, " channel = %d %s %s %s %s\n", |
| 5358 | (int)BSSList_rid.dsChannel, |
| 5359 | BSSList_rid.cap & CAP_ESS ? "ESS" : "", |
| 5360 | BSSList_rid.cap & CAP_IBSS ? "adhoc" : "", |
| 5361 | BSSList_rid.cap & CAP_PRIVACY ? "wep" : "", |
| 5362 | BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : ""); |
| 5363 | rc = readBSSListRid(ai, 0, &BSSList_rid); |
| 5364 | } |
| 5365 | *ptr = '\0'; |
| 5366 | data->readlen = strlen( data->rbuffer ); |
| 5367 | return 0; |
| 5368 | } |
| 5369 | |
| 5370 | static int proc_close( struct inode *inode, struct file *file ) |
| 5371 | { |
| 5372 | struct proc_data *data = (struct proc_data *)file->private_data; |
| 5373 | if ( data->on_close != NULL ) data->on_close( inode, file ); |
| 5374 | if ( data->rbuffer ) kfree( data->rbuffer ); |
| 5375 | if ( data->wbuffer ) kfree( data->wbuffer ); |
| 5376 | kfree( data ); |
| 5377 | return 0; |
| 5378 | } |
| 5379 | |
| 5380 | static struct net_device_list { |
| 5381 | struct net_device *dev; |
| 5382 | struct net_device_list *next; |
| 5383 | } *airo_devices; |
| 5384 | |
| 5385 | /* Since the card doesn't automatically switch to the right WEP mode, |
| 5386 | we will make it do it. If the card isn't associated, every secs we |
| 5387 | will switch WEP modes to see if that will help. If the card is |
| 5388 | associated we will check every minute to see if anything has |
| 5389 | changed. */ |
| 5390 | static void timer_func( struct net_device *dev ) { |
| 5391 | struct airo_info *apriv = dev->priv; |
| 5392 | Resp rsp; |
| 5393 | |
| 5394 | /* We don't have a link so try changing the authtype */ |
| 5395 | readConfigRid(apriv, 0); |
| 5396 | disable_MAC(apriv, 0); |
| 5397 | switch(apriv->config.authType) { |
| 5398 | case AUTH_ENCRYPT: |
| 5399 | /* So drop to OPEN */ |
| 5400 | apriv->config.authType = AUTH_OPEN; |
| 5401 | break; |
| 5402 | case AUTH_SHAREDKEY: |
| 5403 | if (apriv->keyindex < auto_wep) { |
| 5404 | set_wep_key(apriv, apriv->keyindex, NULL, 0, 0, 0); |
| 5405 | apriv->config.authType = AUTH_SHAREDKEY; |
| 5406 | apriv->keyindex++; |
| 5407 | } else { |
| 5408 | /* Drop to ENCRYPT */ |
| 5409 | apriv->keyindex = 0; |
| 5410 | set_wep_key(apriv, apriv->defindex, NULL, 0, 0, 0); |
| 5411 | apriv->config.authType = AUTH_ENCRYPT; |
| 5412 | } |
| 5413 | break; |
| 5414 | default: /* We'll escalate to SHAREDKEY */ |
| 5415 | apriv->config.authType = AUTH_SHAREDKEY; |
| 5416 | } |
| 5417 | set_bit (FLAG_COMMIT, &apriv->flags); |
| 5418 | writeConfigRid(apriv, 0); |
| 5419 | enable_MAC(apriv, &rsp, 0); |
| 5420 | up(&apriv->sem); |
| 5421 | |
| 5422 | /* Schedule check to see if the change worked */ |
| 5423 | clear_bit(JOB_AUTOWEP, &apriv->flags); |
| 5424 | apriv->expires = RUN_AT(HZ*3); |
| 5425 | } |
| 5426 | |
| 5427 | static int add_airo_dev( struct net_device *dev ) { |
| 5428 | struct net_device_list *node = kmalloc( sizeof( *node ), GFP_KERNEL ); |
| 5429 | if ( !node ) |
| 5430 | return -ENOMEM; |
| 5431 | |
| 5432 | node->dev = dev; |
| 5433 | node->next = airo_devices; |
| 5434 | airo_devices = node; |
| 5435 | |
| 5436 | return 0; |
| 5437 | } |
| 5438 | |
| 5439 | static void del_airo_dev( struct net_device *dev ) { |
| 5440 | struct net_device_list **p = &airo_devices; |
| 5441 | while( *p && ( (*p)->dev != dev ) ) |
| 5442 | p = &(*p)->next; |
| 5443 | if ( *p && (*p)->dev == dev ) |
| 5444 | *p = (*p)->next; |
| 5445 | } |
| 5446 | |
| 5447 | #ifdef CONFIG_PCI |
| 5448 | static int __devinit airo_pci_probe(struct pci_dev *pdev, |
| 5449 | const struct pci_device_id *pent) |
| 5450 | { |
| 5451 | struct net_device *dev; |
| 5452 | |
| 5453 | if (pci_enable_device(pdev)) |
| 5454 | return -ENODEV; |
| 5455 | pci_set_master(pdev); |
| 5456 | |
| 5457 | if (pdev->device == 0x5000 || pdev->device == 0xa504) |
| 5458 | dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev, &pdev->dev); |
| 5459 | else |
| 5460 | dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev, &pdev->dev); |
| 5461 | if (!dev) |
| 5462 | return -ENODEV; |
| 5463 | |
| 5464 | pci_set_drvdata(pdev, dev); |
| 5465 | return 0; |
| 5466 | } |
| 5467 | |
| 5468 | static void __devexit airo_pci_remove(struct pci_dev *pdev) |
| 5469 | { |
| 5470 | } |
| 5471 | |
Pavel Machek | 05adc3b | 2005-04-16 15:25:25 -0700 | [diff] [blame] | 5472 | static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5473 | { |
| 5474 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5475 | struct airo_info *ai = dev->priv; |
| 5476 | Cmd cmd; |
| 5477 | Resp rsp; |
| 5478 | |
| 5479 | if ((ai->APList == NULL) && |
| 5480 | (ai->APList = kmalloc(sizeof(APListRid), GFP_KERNEL)) == NULL) |
| 5481 | return -ENOMEM; |
| 5482 | if ((ai->SSID == NULL) && |
| 5483 | (ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL)) == NULL) |
| 5484 | return -ENOMEM; |
| 5485 | readAPListRid(ai, ai->APList); |
| 5486 | readSsidRid(ai, ai->SSID); |
| 5487 | memset(&cmd, 0, sizeof(cmd)); |
| 5488 | /* the lock will be released at the end of the resume callback */ |
| 5489 | if (down_interruptible(&ai->sem)) |
| 5490 | return -EAGAIN; |
| 5491 | disable_MAC(ai, 0); |
| 5492 | netif_device_detach(dev); |
| 5493 | ai->power = state; |
| 5494 | cmd.cmd=HOSTSLEEP; |
| 5495 | issuecommand(ai, &cmd, &rsp); |
| 5496 | |
Pavel Machek | 1cc68ae | 2005-06-20 15:33:04 -0700 | [diff] [blame] | 5497 | pci_enable_wake(pdev, pci_choose_state(pdev, state), 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5498 | pci_save_state(pdev); |
Pavel Machek | 1cc68ae | 2005-06-20 15:33:04 -0700 | [diff] [blame] | 5499 | return pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | } |
| 5501 | |
| 5502 | static int airo_pci_resume(struct pci_dev *pdev) |
| 5503 | { |
| 5504 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5505 | struct airo_info *ai = dev->priv; |
| 5506 | Resp rsp; |
| 5507 | |
| 5508 | pci_set_power_state(pdev, 0); |
| 5509 | pci_restore_state(pdev); |
Pavel Machek | 1cc68ae | 2005-06-20 15:33:04 -0700 | [diff] [blame] | 5510 | pci_enable_wake(pdev, pci_choose_state(pdev, ai->power), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5511 | |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 5512 | if (ai->power.event > 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5513 | reset_card(dev, 0); |
| 5514 | mpi_init_descriptors(ai); |
| 5515 | setup_card(ai, dev->dev_addr, 0); |
| 5516 | clear_bit(FLAG_RADIO_OFF, &ai->flags); |
| 5517 | clear_bit(FLAG_PENDING_XMIT, &ai->flags); |
| 5518 | } else { |
| 5519 | OUT4500(ai, EVACK, EV_AWAKEN); |
| 5520 | OUT4500(ai, EVACK, EV_AWAKEN); |
| 5521 | msleep(100); |
| 5522 | } |
| 5523 | |
| 5524 | set_bit (FLAG_COMMIT, &ai->flags); |
| 5525 | disable_MAC(ai, 0); |
| 5526 | msleep(200); |
| 5527 | if (ai->SSID) { |
| 5528 | writeSsidRid(ai, ai->SSID, 0); |
| 5529 | kfree(ai->SSID); |
| 5530 | ai->SSID = NULL; |
| 5531 | } |
| 5532 | if (ai->APList) { |
| 5533 | writeAPListRid(ai, ai->APList, 0); |
| 5534 | kfree(ai->APList); |
| 5535 | ai->APList = NULL; |
| 5536 | } |
| 5537 | writeConfigRid(ai, 0); |
| 5538 | enable_MAC(ai, &rsp, 0); |
Pavel Machek | 1cc68ae | 2005-06-20 15:33:04 -0700 | [diff] [blame] | 5539 | ai->power = PMSG_ON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | netif_device_attach(dev); |
| 5541 | netif_wake_queue(dev); |
| 5542 | enable_interrupts(ai); |
| 5543 | up(&ai->sem); |
| 5544 | return 0; |
| 5545 | } |
| 5546 | #endif |
| 5547 | |
| 5548 | static int __init airo_init_module( void ) |
| 5549 | { |
| 5550 | int i, have_isa_dev = 0; |
| 5551 | |
| 5552 | airo_entry = create_proc_entry("aironet", |
| 5553 | S_IFDIR | airo_perm, |
| 5554 | proc_root_driver); |
| 5555 | airo_entry->uid = proc_uid; |
| 5556 | airo_entry->gid = proc_gid; |
| 5557 | |
| 5558 | for( i = 0; i < 4 && io[i] && irq[i]; i++ ) { |
| 5559 | printk( KERN_INFO |
| 5560 | "airo: Trying to configure ISA adapter at irq=%d io=0x%x\n", |
| 5561 | irq[i], io[i] ); |
| 5562 | if (init_airo_card( irq[i], io[i], 0, NULL )) |
| 5563 | have_isa_dev = 1; |
| 5564 | } |
| 5565 | |
| 5566 | #ifdef CONFIG_PCI |
| 5567 | printk( KERN_INFO "airo: Probing for PCI adapters\n" ); |
| 5568 | pci_register_driver(&airo_driver); |
| 5569 | printk( KERN_INFO "airo: Finished probing for PCI adapters\n" ); |
| 5570 | #endif |
| 5571 | |
| 5572 | /* Always exit with success, as we are a library module |
| 5573 | * as well as a driver module |
| 5574 | */ |
| 5575 | return 0; |
| 5576 | } |
| 5577 | |
| 5578 | static void __exit airo_cleanup_module( void ) |
| 5579 | { |
| 5580 | while( airo_devices ) { |
| 5581 | printk( KERN_INFO "airo: Unregistering %s\n", airo_devices->dev->name ); |
| 5582 | stop_airo_card( airo_devices->dev, 1 ); |
| 5583 | } |
| 5584 | #ifdef CONFIG_PCI |
| 5585 | pci_unregister_driver(&airo_driver); |
| 5586 | #endif |
| 5587 | remove_proc_entry("aironet", proc_root_driver); |
| 5588 | } |
| 5589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | /* |
| 5591 | * Initial Wireless Extension code for Aironet driver by : |
| 5592 | * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00 |
| 5593 | * Conversion to new driver API by : |
| 5594 | * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02 |
| 5595 | * Javier also did a good amount of work here, adding some new extensions |
| 5596 | * and fixing my code. Let's just say that without him this code just |
| 5597 | * would not work at all... - Jean II |
| 5598 | */ |
| 5599 | |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 5600 | static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi) |
| 5601 | { |
| 5602 | if( !rssi_rid ) |
| 5603 | return 0; |
| 5604 | |
| 5605 | return (0x100 - rssi_rid[rssi].rssidBm); |
| 5606 | } |
| 5607 | |
| 5608 | static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm) |
| 5609 | { |
| 5610 | int i; |
| 5611 | |
| 5612 | if( !rssi_rid ) |
| 5613 | return 0; |
| 5614 | |
| 5615 | for( i = 0; i < 256; i++ ) |
| 5616 | if (rssi_rid[i].rssidBm == dbm) |
| 5617 | return rssi_rid[i].rssipct; |
| 5618 | |
| 5619 | return 0; |
| 5620 | } |
| 5621 | |
| 5622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid) |
| 5624 | { |
| 5625 | int quality = 0; |
| 5626 | |
| 5627 | if ((status_rid->mode & 0x3f) == 0x3f && (cap_rid->hardCap & 8)) { |
| 5628 | if (memcmp(cap_rid->prodName, "350", 3)) |
| 5629 | if (status_rid->signalQuality > 0x20) |
| 5630 | quality = 0; |
| 5631 | else |
| 5632 | quality = 0x20 - status_rid->signalQuality; |
| 5633 | else |
| 5634 | if (status_rid->signalQuality > 0xb0) |
| 5635 | quality = 0; |
| 5636 | else if (status_rid->signalQuality < 0x10) |
| 5637 | quality = 0xa0; |
| 5638 | else |
| 5639 | quality = 0xb0 - status_rid->signalQuality; |
| 5640 | } |
| 5641 | return quality; |
| 5642 | } |
| 5643 | |
| 5644 | #define airo_get_max_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x20 : 0xa0) |
| 5645 | #define airo_get_avg_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x10 : 0x50); |
| 5646 | |
| 5647 | /*------------------------------------------------------------------*/ |
| 5648 | /* |
| 5649 | * Wireless Handler : get protocol name |
| 5650 | */ |
| 5651 | static int airo_get_name(struct net_device *dev, |
| 5652 | struct iw_request_info *info, |
| 5653 | char *cwrq, |
| 5654 | char *extra) |
| 5655 | { |
| 5656 | strcpy(cwrq, "IEEE 802.11-DS"); |
| 5657 | return 0; |
| 5658 | } |
| 5659 | |
| 5660 | /*------------------------------------------------------------------*/ |
| 5661 | /* |
| 5662 | * Wireless Handler : set frequency |
| 5663 | */ |
| 5664 | static int airo_set_freq(struct net_device *dev, |
| 5665 | struct iw_request_info *info, |
| 5666 | struct iw_freq *fwrq, |
| 5667 | char *extra) |
| 5668 | { |
| 5669 | struct airo_info *local = dev->priv; |
| 5670 | int rc = -EINPROGRESS; /* Call commit handler */ |
| 5671 | |
| 5672 | /* If setting by frequency, convert to a channel */ |
| 5673 | if((fwrq->e == 1) && |
| 5674 | (fwrq->m >= (int) 2.412e8) && |
| 5675 | (fwrq->m <= (int) 2.487e8)) { |
| 5676 | int f = fwrq->m / 100000; |
| 5677 | int c = 0; |
| 5678 | while((c < 14) && (f != frequency_list[c])) |
| 5679 | c++; |
| 5680 | /* Hack to fall through... */ |
| 5681 | fwrq->e = 0; |
| 5682 | fwrq->m = c + 1; |
| 5683 | } |
| 5684 | /* Setting by channel number */ |
| 5685 | if((fwrq->m > 1000) || (fwrq->e > 0)) |
| 5686 | rc = -EOPNOTSUPP; |
| 5687 | else { |
| 5688 | int channel = fwrq->m; |
| 5689 | /* We should do a better check than that, |
| 5690 | * based on the card capability !!! */ |
| 5691 | if((channel < 1) || (channel > 16)) { |
| 5692 | printk(KERN_DEBUG "%s: New channel value of %d is invalid!\n", dev->name, fwrq->m); |
| 5693 | rc = -EINVAL; |
| 5694 | } else { |
| 5695 | readConfigRid(local, 1); |
| 5696 | /* Yes ! We can set it !!! */ |
| 5697 | local->config.channelSet = (u16)(channel - 1); |
| 5698 | set_bit (FLAG_COMMIT, &local->flags); |
| 5699 | } |
| 5700 | } |
| 5701 | return rc; |
| 5702 | } |
| 5703 | |
| 5704 | /*------------------------------------------------------------------*/ |
| 5705 | /* |
| 5706 | * Wireless Handler : get frequency |
| 5707 | */ |
| 5708 | static int airo_get_freq(struct net_device *dev, |
| 5709 | struct iw_request_info *info, |
| 5710 | struct iw_freq *fwrq, |
| 5711 | char *extra) |
| 5712 | { |
| 5713 | struct airo_info *local = dev->priv; |
| 5714 | StatusRid status_rid; /* Card status info */ |
| 5715 | |
| 5716 | readConfigRid(local, 1); |
| 5717 | if ((local->config.opmode & 0xFF) == MODE_STA_ESS) |
| 5718 | status_rid.channel = local->config.channelSet; |
| 5719 | else |
| 5720 | readStatusRid(local, &status_rid, 1); |
| 5721 | |
| 5722 | #ifdef WEXT_USECHANNELS |
| 5723 | fwrq->m = ((int)status_rid.channel) + 1; |
| 5724 | fwrq->e = 0; |
| 5725 | #else |
| 5726 | { |
| 5727 | int f = (int)status_rid.channel; |
| 5728 | fwrq->m = frequency_list[f] * 100000; |
| 5729 | fwrq->e = 1; |
| 5730 | } |
| 5731 | #endif |
| 5732 | |
| 5733 | return 0; |
| 5734 | } |
| 5735 | |
| 5736 | /*------------------------------------------------------------------*/ |
| 5737 | /* |
| 5738 | * Wireless Handler : set ESSID |
| 5739 | */ |
| 5740 | static int airo_set_essid(struct net_device *dev, |
| 5741 | struct iw_request_info *info, |
| 5742 | struct iw_point *dwrq, |
| 5743 | char *extra) |
| 5744 | { |
| 5745 | struct airo_info *local = dev->priv; |
| 5746 | Resp rsp; |
| 5747 | SsidRid SSID_rid; /* SSIDs */ |
| 5748 | |
| 5749 | /* Reload the list of current SSID */ |
| 5750 | readSsidRid(local, &SSID_rid); |
| 5751 | |
| 5752 | /* Check if we asked for `any' */ |
| 5753 | if(dwrq->flags == 0) { |
| 5754 | /* Just send an empty SSID list */ |
| 5755 | memset(&SSID_rid, 0, sizeof(SSID_rid)); |
| 5756 | } else { |
| 5757 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
| 5758 | |
| 5759 | /* Check the size of the string */ |
| 5760 | if(dwrq->length > IW_ESSID_MAX_SIZE+1) { |
| 5761 | return -E2BIG ; |
| 5762 | } |
| 5763 | /* Check if index is valid */ |
| 5764 | if((index < 0) || (index >= 4)) { |
| 5765 | return -EINVAL; |
| 5766 | } |
| 5767 | |
| 5768 | /* Set the SSID */ |
| 5769 | memset(SSID_rid.ssids[index].ssid, 0, |
| 5770 | sizeof(SSID_rid.ssids[index].ssid)); |
| 5771 | memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length); |
| 5772 | SSID_rid.ssids[index].len = dwrq->length - 1; |
| 5773 | } |
| 5774 | SSID_rid.len = sizeof(SSID_rid); |
| 5775 | /* Write it to the card */ |
| 5776 | disable_MAC(local, 1); |
| 5777 | writeSsidRid(local, &SSID_rid, 1); |
| 5778 | enable_MAC(local, &rsp, 1); |
| 5779 | |
| 5780 | return 0; |
| 5781 | } |
| 5782 | |
| 5783 | /*------------------------------------------------------------------*/ |
| 5784 | /* |
| 5785 | * Wireless Handler : get ESSID |
| 5786 | */ |
| 5787 | static int airo_get_essid(struct net_device *dev, |
| 5788 | struct iw_request_info *info, |
| 5789 | struct iw_point *dwrq, |
| 5790 | char *extra) |
| 5791 | { |
| 5792 | struct airo_info *local = dev->priv; |
| 5793 | StatusRid status_rid; /* Card status info */ |
| 5794 | |
| 5795 | readStatusRid(local, &status_rid, 1); |
| 5796 | |
| 5797 | /* Note : if dwrq->flags != 0, we should |
| 5798 | * get the relevant SSID from the SSID list... */ |
| 5799 | |
| 5800 | /* Get the current SSID */ |
| 5801 | memcpy(extra, status_rid.SSID, status_rid.SSIDlen); |
| 5802 | extra[status_rid.SSIDlen] = '\0'; |
| 5803 | /* If none, we may want to get the one that was set */ |
| 5804 | |
| 5805 | /* Push it out ! */ |
| 5806 | dwrq->length = status_rid.SSIDlen + 1; |
| 5807 | dwrq->flags = 1; /* active */ |
| 5808 | |
| 5809 | return 0; |
| 5810 | } |
| 5811 | |
| 5812 | /*------------------------------------------------------------------*/ |
| 5813 | /* |
| 5814 | * Wireless Handler : set AP address |
| 5815 | */ |
| 5816 | static int airo_set_wap(struct net_device *dev, |
| 5817 | struct iw_request_info *info, |
| 5818 | struct sockaddr *awrq, |
| 5819 | char *extra) |
| 5820 | { |
| 5821 | struct airo_info *local = dev->priv; |
| 5822 | Cmd cmd; |
| 5823 | Resp rsp; |
| 5824 | APListRid APList_rid; |
| 5825 | static const unsigned char bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 }; |
| 5826 | |
| 5827 | if (awrq->sa_family != ARPHRD_ETHER) |
| 5828 | return -EINVAL; |
| 5829 | else if (!memcmp(bcast, awrq->sa_data, ETH_ALEN)) { |
| 5830 | memset(&cmd, 0, sizeof(cmd)); |
| 5831 | cmd.cmd=CMD_LOSE_SYNC; |
| 5832 | if (down_interruptible(&local->sem)) |
| 5833 | return -ERESTARTSYS; |
| 5834 | issuecommand(local, &cmd, &rsp); |
| 5835 | up(&local->sem); |
| 5836 | } else { |
| 5837 | memset(&APList_rid, 0, sizeof(APList_rid)); |
| 5838 | APList_rid.len = sizeof(APList_rid); |
| 5839 | memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN); |
| 5840 | disable_MAC(local, 1); |
| 5841 | writeAPListRid(local, &APList_rid, 1); |
| 5842 | enable_MAC(local, &rsp, 1); |
| 5843 | } |
| 5844 | return 0; |
| 5845 | } |
| 5846 | |
| 5847 | /*------------------------------------------------------------------*/ |
| 5848 | /* |
| 5849 | * Wireless Handler : get AP address |
| 5850 | */ |
| 5851 | static int airo_get_wap(struct net_device *dev, |
| 5852 | struct iw_request_info *info, |
| 5853 | struct sockaddr *awrq, |
| 5854 | char *extra) |
| 5855 | { |
| 5856 | struct airo_info *local = dev->priv; |
| 5857 | StatusRid status_rid; /* Card status info */ |
| 5858 | |
| 5859 | readStatusRid(local, &status_rid, 1); |
| 5860 | |
| 5861 | /* Tentative. This seems to work, wow, I'm lucky !!! */ |
| 5862 | memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN); |
| 5863 | awrq->sa_family = ARPHRD_ETHER; |
| 5864 | |
| 5865 | return 0; |
| 5866 | } |
| 5867 | |
| 5868 | /*------------------------------------------------------------------*/ |
| 5869 | /* |
| 5870 | * Wireless Handler : set Nickname |
| 5871 | */ |
| 5872 | static int airo_set_nick(struct net_device *dev, |
| 5873 | struct iw_request_info *info, |
| 5874 | struct iw_point *dwrq, |
| 5875 | char *extra) |
| 5876 | { |
| 5877 | struct airo_info *local = dev->priv; |
| 5878 | |
| 5879 | /* Check the size of the string */ |
| 5880 | if(dwrq->length > 16 + 1) { |
| 5881 | return -E2BIG; |
| 5882 | } |
| 5883 | readConfigRid(local, 1); |
| 5884 | memset(local->config.nodeName, 0, sizeof(local->config.nodeName)); |
| 5885 | memcpy(local->config.nodeName, extra, dwrq->length); |
| 5886 | set_bit (FLAG_COMMIT, &local->flags); |
| 5887 | |
| 5888 | return -EINPROGRESS; /* Call commit handler */ |
| 5889 | } |
| 5890 | |
| 5891 | /*------------------------------------------------------------------*/ |
| 5892 | /* |
| 5893 | * Wireless Handler : get Nickname |
| 5894 | */ |
| 5895 | static int airo_get_nick(struct net_device *dev, |
| 5896 | struct iw_request_info *info, |
| 5897 | struct iw_point *dwrq, |
| 5898 | char *extra) |
| 5899 | { |
| 5900 | struct airo_info *local = dev->priv; |
| 5901 | |
| 5902 | readConfigRid(local, 1); |
| 5903 | strncpy(extra, local->config.nodeName, 16); |
| 5904 | extra[16] = '\0'; |
| 5905 | dwrq->length = strlen(extra) + 1; |
| 5906 | |
| 5907 | return 0; |
| 5908 | } |
| 5909 | |
| 5910 | /*------------------------------------------------------------------*/ |
| 5911 | /* |
| 5912 | * Wireless Handler : set Bit-Rate |
| 5913 | */ |
| 5914 | static int airo_set_rate(struct net_device *dev, |
| 5915 | struct iw_request_info *info, |
| 5916 | struct iw_param *vwrq, |
| 5917 | char *extra) |
| 5918 | { |
| 5919 | struct airo_info *local = dev->priv; |
| 5920 | CapabilityRid cap_rid; /* Card capability info */ |
| 5921 | u8 brate = 0; |
| 5922 | int i; |
| 5923 | |
| 5924 | /* First : get a valid bit rate value */ |
| 5925 | readCapabilityRid(local, &cap_rid, 1); |
| 5926 | |
| 5927 | /* Which type of value ? */ |
| 5928 | if((vwrq->value < 8) && (vwrq->value >= 0)) { |
| 5929 | /* Setting by rate index */ |
| 5930 | /* Find value in the magic rate table */ |
| 5931 | brate = cap_rid.supportedRates[vwrq->value]; |
| 5932 | } else { |
| 5933 | /* Setting by frequency value */ |
| 5934 | u8 normvalue = (u8) (vwrq->value/500000); |
| 5935 | |
| 5936 | /* Check if rate is valid */ |
| 5937 | for(i = 0 ; i < 8 ; i++) { |
| 5938 | if(normvalue == cap_rid.supportedRates[i]) { |
| 5939 | brate = normvalue; |
| 5940 | break; |
| 5941 | } |
| 5942 | } |
| 5943 | } |
| 5944 | /* -1 designed the max rate (mostly auto mode) */ |
| 5945 | if(vwrq->value == -1) { |
| 5946 | /* Get the highest available rate */ |
| 5947 | for(i = 0 ; i < 8 ; i++) { |
| 5948 | if(cap_rid.supportedRates[i] == 0) |
| 5949 | break; |
| 5950 | } |
| 5951 | if(i != 0) |
| 5952 | brate = cap_rid.supportedRates[i - 1]; |
| 5953 | } |
| 5954 | /* Check that it is valid */ |
| 5955 | if(brate == 0) { |
| 5956 | return -EINVAL; |
| 5957 | } |
| 5958 | |
| 5959 | readConfigRid(local, 1); |
| 5960 | /* Now, check if we want a fixed or auto value */ |
| 5961 | if(vwrq->fixed == 0) { |
| 5962 | /* Fill all the rates up to this max rate */ |
| 5963 | memset(local->config.rates, 0, 8); |
| 5964 | for(i = 0 ; i < 8 ; i++) { |
| 5965 | local->config.rates[i] = cap_rid.supportedRates[i]; |
| 5966 | if(local->config.rates[i] == brate) |
| 5967 | break; |
| 5968 | } |
| 5969 | } else { |
| 5970 | /* Fixed mode */ |
| 5971 | /* One rate, fixed */ |
| 5972 | memset(local->config.rates, 0, 8); |
| 5973 | local->config.rates[0] = brate; |
| 5974 | } |
| 5975 | set_bit (FLAG_COMMIT, &local->flags); |
| 5976 | |
| 5977 | return -EINPROGRESS; /* Call commit handler */ |
| 5978 | } |
| 5979 | |
| 5980 | /*------------------------------------------------------------------*/ |
| 5981 | /* |
| 5982 | * Wireless Handler : get Bit-Rate |
| 5983 | */ |
| 5984 | static int airo_get_rate(struct net_device *dev, |
| 5985 | struct iw_request_info *info, |
| 5986 | struct iw_param *vwrq, |
| 5987 | char *extra) |
| 5988 | { |
| 5989 | struct airo_info *local = dev->priv; |
| 5990 | StatusRid status_rid; /* Card status info */ |
| 5991 | |
| 5992 | readStatusRid(local, &status_rid, 1); |
| 5993 | |
| 5994 | vwrq->value = status_rid.currentXmitRate * 500000; |
| 5995 | /* If more than one rate, set auto */ |
| 5996 | readConfigRid(local, 1); |
| 5997 | vwrq->fixed = (local->config.rates[1] == 0); |
| 5998 | |
| 5999 | return 0; |
| 6000 | } |
| 6001 | |
| 6002 | /*------------------------------------------------------------------*/ |
| 6003 | /* |
| 6004 | * Wireless Handler : set RTS threshold |
| 6005 | */ |
| 6006 | static int airo_set_rts(struct net_device *dev, |
| 6007 | struct iw_request_info *info, |
| 6008 | struct iw_param *vwrq, |
| 6009 | char *extra) |
| 6010 | { |
| 6011 | struct airo_info *local = dev->priv; |
| 6012 | int rthr = vwrq->value; |
| 6013 | |
| 6014 | if(vwrq->disabled) |
| 6015 | rthr = 2312; |
| 6016 | if((rthr < 0) || (rthr > 2312)) { |
| 6017 | return -EINVAL; |
| 6018 | } |
| 6019 | readConfigRid(local, 1); |
| 6020 | local->config.rtsThres = rthr; |
| 6021 | set_bit (FLAG_COMMIT, &local->flags); |
| 6022 | |
| 6023 | return -EINPROGRESS; /* Call commit handler */ |
| 6024 | } |
| 6025 | |
| 6026 | /*------------------------------------------------------------------*/ |
| 6027 | /* |
| 6028 | * Wireless Handler : get RTS threshold |
| 6029 | */ |
| 6030 | static int airo_get_rts(struct net_device *dev, |
| 6031 | struct iw_request_info *info, |
| 6032 | struct iw_param *vwrq, |
| 6033 | char *extra) |
| 6034 | { |
| 6035 | struct airo_info *local = dev->priv; |
| 6036 | |
| 6037 | readConfigRid(local, 1); |
| 6038 | vwrq->value = local->config.rtsThres; |
| 6039 | vwrq->disabled = (vwrq->value >= 2312); |
| 6040 | vwrq->fixed = 1; |
| 6041 | |
| 6042 | return 0; |
| 6043 | } |
| 6044 | |
| 6045 | /*------------------------------------------------------------------*/ |
| 6046 | /* |
| 6047 | * Wireless Handler : set Fragmentation threshold |
| 6048 | */ |
| 6049 | static int airo_set_frag(struct net_device *dev, |
| 6050 | struct iw_request_info *info, |
| 6051 | struct iw_param *vwrq, |
| 6052 | char *extra) |
| 6053 | { |
| 6054 | struct airo_info *local = dev->priv; |
| 6055 | int fthr = vwrq->value; |
| 6056 | |
| 6057 | if(vwrq->disabled) |
| 6058 | fthr = 2312; |
| 6059 | if((fthr < 256) || (fthr > 2312)) { |
| 6060 | return -EINVAL; |
| 6061 | } |
| 6062 | fthr &= ~0x1; /* Get an even value - is it really needed ??? */ |
| 6063 | readConfigRid(local, 1); |
| 6064 | local->config.fragThresh = (u16)fthr; |
| 6065 | set_bit (FLAG_COMMIT, &local->flags); |
| 6066 | |
| 6067 | return -EINPROGRESS; /* Call commit handler */ |
| 6068 | } |
| 6069 | |
| 6070 | /*------------------------------------------------------------------*/ |
| 6071 | /* |
| 6072 | * Wireless Handler : get Fragmentation threshold |
| 6073 | */ |
| 6074 | static int airo_get_frag(struct net_device *dev, |
| 6075 | struct iw_request_info *info, |
| 6076 | struct iw_param *vwrq, |
| 6077 | char *extra) |
| 6078 | { |
| 6079 | struct airo_info *local = dev->priv; |
| 6080 | |
| 6081 | readConfigRid(local, 1); |
| 6082 | vwrq->value = local->config.fragThresh; |
| 6083 | vwrq->disabled = (vwrq->value >= 2312); |
| 6084 | vwrq->fixed = 1; |
| 6085 | |
| 6086 | return 0; |
| 6087 | } |
| 6088 | |
| 6089 | /*------------------------------------------------------------------*/ |
| 6090 | /* |
| 6091 | * Wireless Handler : set Mode of Operation |
| 6092 | */ |
| 6093 | static int airo_set_mode(struct net_device *dev, |
| 6094 | struct iw_request_info *info, |
| 6095 | __u32 *uwrq, |
| 6096 | char *extra) |
| 6097 | { |
| 6098 | struct airo_info *local = dev->priv; |
| 6099 | int reset = 0; |
| 6100 | |
| 6101 | readConfigRid(local, 1); |
| 6102 | if ((local->config.rmode & 0xff) >= RXMODE_RFMON) |
| 6103 | reset = 1; |
| 6104 | |
| 6105 | switch(*uwrq) { |
| 6106 | case IW_MODE_ADHOC: |
| 6107 | local->config.opmode &= 0xFF00; |
| 6108 | local->config.opmode |= MODE_STA_IBSS; |
| 6109 | local->config.rmode &= 0xfe00; |
| 6110 | local->config.scanMode = SCANMODE_ACTIVE; |
| 6111 | clear_bit (FLAG_802_11, &local->flags); |
| 6112 | break; |
| 6113 | case IW_MODE_INFRA: |
| 6114 | local->config.opmode &= 0xFF00; |
| 6115 | local->config.opmode |= MODE_STA_ESS; |
| 6116 | local->config.rmode &= 0xfe00; |
| 6117 | local->config.scanMode = SCANMODE_ACTIVE; |
| 6118 | clear_bit (FLAG_802_11, &local->flags); |
| 6119 | break; |
| 6120 | case IW_MODE_MASTER: |
| 6121 | local->config.opmode &= 0xFF00; |
| 6122 | local->config.opmode |= MODE_AP; |
| 6123 | local->config.rmode &= 0xfe00; |
| 6124 | local->config.scanMode = SCANMODE_ACTIVE; |
| 6125 | clear_bit (FLAG_802_11, &local->flags); |
| 6126 | break; |
| 6127 | case IW_MODE_REPEAT: |
| 6128 | local->config.opmode &= 0xFF00; |
| 6129 | local->config.opmode |= MODE_AP_RPTR; |
| 6130 | local->config.rmode &= 0xfe00; |
| 6131 | local->config.scanMode = SCANMODE_ACTIVE; |
| 6132 | clear_bit (FLAG_802_11, &local->flags); |
| 6133 | break; |
| 6134 | case IW_MODE_MONITOR: |
| 6135 | local->config.opmode &= 0xFF00; |
| 6136 | local->config.opmode |= MODE_STA_ESS; |
| 6137 | local->config.rmode &= 0xfe00; |
| 6138 | local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER; |
| 6139 | local->config.scanMode = SCANMODE_PASSIVE; |
| 6140 | set_bit (FLAG_802_11, &local->flags); |
| 6141 | break; |
| 6142 | default: |
| 6143 | return -EINVAL; |
| 6144 | } |
| 6145 | if (reset) |
| 6146 | set_bit (FLAG_RESET, &local->flags); |
| 6147 | set_bit (FLAG_COMMIT, &local->flags); |
| 6148 | |
| 6149 | return -EINPROGRESS; /* Call commit handler */ |
| 6150 | } |
| 6151 | |
| 6152 | /*------------------------------------------------------------------*/ |
| 6153 | /* |
| 6154 | * Wireless Handler : get Mode of Operation |
| 6155 | */ |
| 6156 | static int airo_get_mode(struct net_device *dev, |
| 6157 | struct iw_request_info *info, |
| 6158 | __u32 *uwrq, |
| 6159 | char *extra) |
| 6160 | { |
| 6161 | struct airo_info *local = dev->priv; |
| 6162 | |
| 6163 | readConfigRid(local, 1); |
| 6164 | /* If not managed, assume it's ad-hoc */ |
| 6165 | switch (local->config.opmode & 0xFF) { |
| 6166 | case MODE_STA_ESS: |
| 6167 | *uwrq = IW_MODE_INFRA; |
| 6168 | break; |
| 6169 | case MODE_AP: |
| 6170 | *uwrq = IW_MODE_MASTER; |
| 6171 | break; |
| 6172 | case MODE_AP_RPTR: |
| 6173 | *uwrq = IW_MODE_REPEAT; |
| 6174 | break; |
| 6175 | default: |
| 6176 | *uwrq = IW_MODE_ADHOC; |
| 6177 | } |
| 6178 | |
| 6179 | return 0; |
| 6180 | } |
| 6181 | |
| 6182 | /*------------------------------------------------------------------*/ |
| 6183 | /* |
| 6184 | * Wireless Handler : set Encryption Key |
| 6185 | */ |
| 6186 | static int airo_set_encode(struct net_device *dev, |
| 6187 | struct iw_request_info *info, |
| 6188 | struct iw_point *dwrq, |
| 6189 | char *extra) |
| 6190 | { |
| 6191 | struct airo_info *local = dev->priv; |
| 6192 | CapabilityRid cap_rid; /* Card capability info */ |
| 6193 | |
| 6194 | /* Is WEP supported ? */ |
| 6195 | readCapabilityRid(local, &cap_rid, 1); |
| 6196 | /* Older firmware doesn't support this... |
| 6197 | if(!(cap_rid.softCap & 2)) { |
| 6198 | return -EOPNOTSUPP; |
| 6199 | } */ |
| 6200 | readConfigRid(local, 1); |
| 6201 | |
| 6202 | /* Basic checking: do we have a key to set ? |
| 6203 | * Note : with the new API, it's impossible to get a NULL pointer. |
| 6204 | * Therefore, we need to check a key size == 0 instead. |
| 6205 | * New version of iwconfig properly set the IW_ENCODE_NOKEY flag |
| 6206 | * when no key is present (only change flags), but older versions |
| 6207 | * don't do it. - Jean II */ |
| 6208 | if (dwrq->length > 0) { |
| 6209 | wep_key_t key; |
| 6210 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
| 6211 | int current_index = get_wep_key(local, 0xffff); |
| 6212 | /* Check the size of the key */ |
| 6213 | if (dwrq->length > MAX_KEY_SIZE) { |
| 6214 | return -EINVAL; |
| 6215 | } |
| 6216 | /* Check the index (none -> use current) */ |
| 6217 | if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4:1))) |
| 6218 | index = current_index; |
| 6219 | /* Set the length */ |
| 6220 | if (dwrq->length > MIN_KEY_SIZE) |
| 6221 | key.len = MAX_KEY_SIZE; |
| 6222 | else |
| 6223 | if (dwrq->length > 0) |
| 6224 | key.len = MIN_KEY_SIZE; |
| 6225 | else |
| 6226 | /* Disable the key */ |
| 6227 | key.len = 0; |
| 6228 | /* Check if the key is not marked as invalid */ |
| 6229 | if(!(dwrq->flags & IW_ENCODE_NOKEY)) { |
| 6230 | /* Cleanup */ |
| 6231 | memset(key.key, 0, MAX_KEY_SIZE); |
| 6232 | /* Copy the key in the driver */ |
| 6233 | memcpy(key.key, extra, dwrq->length); |
| 6234 | /* Send the key to the card */ |
| 6235 | set_wep_key(local, index, key.key, key.len, 1, 1); |
| 6236 | } |
| 6237 | /* WE specify that if a valid key is set, encryption |
| 6238 | * should be enabled (user may turn it off later) |
| 6239 | * This is also how "iwconfig ethX key on" works */ |
| 6240 | if((index == current_index) && (key.len > 0) && |
| 6241 | (local->config.authType == AUTH_OPEN)) { |
| 6242 | local->config.authType = AUTH_ENCRYPT; |
| 6243 | set_bit (FLAG_COMMIT, &local->flags); |
| 6244 | } |
| 6245 | } else { |
| 6246 | /* Do we want to just set the transmit key index ? */ |
| 6247 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
| 6248 | if ((index >= 0) && (index < ((cap_rid.softCap & 0x80)?4:1))) { |
| 6249 | set_wep_key(local, index, NULL, 0, 1, 1); |
| 6250 | } else |
| 6251 | /* Don't complain if only change the mode */ |
| 6252 | if(!dwrq->flags & IW_ENCODE_MODE) { |
| 6253 | return -EINVAL; |
| 6254 | } |
| 6255 | } |
| 6256 | /* Read the flags */ |
| 6257 | if(dwrq->flags & IW_ENCODE_DISABLED) |
| 6258 | local->config.authType = AUTH_OPEN; // disable encryption |
| 6259 | if(dwrq->flags & IW_ENCODE_RESTRICTED) |
| 6260 | local->config.authType = AUTH_SHAREDKEY; // Only Both |
| 6261 | if(dwrq->flags & IW_ENCODE_OPEN) |
| 6262 | local->config.authType = AUTH_ENCRYPT; // Only Wep |
| 6263 | /* Commit the changes to flags if needed */ |
| 6264 | if(dwrq->flags & IW_ENCODE_MODE) |
| 6265 | set_bit (FLAG_COMMIT, &local->flags); |
| 6266 | return -EINPROGRESS; /* Call commit handler */ |
| 6267 | } |
| 6268 | |
| 6269 | /*------------------------------------------------------------------*/ |
| 6270 | /* |
| 6271 | * Wireless Handler : get Encryption Key |
| 6272 | */ |
| 6273 | static int airo_get_encode(struct net_device *dev, |
| 6274 | struct iw_request_info *info, |
| 6275 | struct iw_point *dwrq, |
| 6276 | char *extra) |
| 6277 | { |
| 6278 | struct airo_info *local = dev->priv; |
| 6279 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
| 6280 | CapabilityRid cap_rid; /* Card capability info */ |
| 6281 | |
| 6282 | /* Is it supported ? */ |
| 6283 | readCapabilityRid(local, &cap_rid, 1); |
| 6284 | if(!(cap_rid.softCap & 2)) { |
| 6285 | return -EOPNOTSUPP; |
| 6286 | } |
| 6287 | readConfigRid(local, 1); |
| 6288 | /* Check encryption mode */ |
| 6289 | switch(local->config.authType) { |
| 6290 | case AUTH_ENCRYPT: |
| 6291 | dwrq->flags = IW_ENCODE_OPEN; |
| 6292 | break; |
| 6293 | case AUTH_SHAREDKEY: |
| 6294 | dwrq->flags = IW_ENCODE_RESTRICTED; |
| 6295 | break; |
| 6296 | default: |
| 6297 | case AUTH_OPEN: |
| 6298 | dwrq->flags = IW_ENCODE_DISABLED; |
| 6299 | break; |
| 6300 | } |
| 6301 | /* We can't return the key, so set the proper flag and return zero */ |
| 6302 | dwrq->flags |= IW_ENCODE_NOKEY; |
| 6303 | memset(extra, 0, 16); |
| 6304 | |
| 6305 | /* Which key do we want ? -1 -> tx index */ |
| 6306 | if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4 : 1))) |
| 6307 | index = get_wep_key(local, 0xffff); |
| 6308 | dwrq->flags |= index + 1; |
| 6309 | /* Copy the key to the user buffer */ |
| 6310 | dwrq->length = get_wep_key(local, index); |
| 6311 | if (dwrq->length > 16) { |
| 6312 | dwrq->length=0; |
| 6313 | } |
| 6314 | return 0; |
| 6315 | } |
| 6316 | |
| 6317 | /*------------------------------------------------------------------*/ |
| 6318 | /* |
| 6319 | * Wireless Handler : set Tx-Power |
| 6320 | */ |
| 6321 | static int airo_set_txpow(struct net_device *dev, |
| 6322 | struct iw_request_info *info, |
| 6323 | struct iw_param *vwrq, |
| 6324 | char *extra) |
| 6325 | { |
| 6326 | struct airo_info *local = dev->priv; |
| 6327 | CapabilityRid cap_rid; /* Card capability info */ |
| 6328 | int i; |
| 6329 | int rc = -EINVAL; |
| 6330 | |
| 6331 | readCapabilityRid(local, &cap_rid, 1); |
| 6332 | |
| 6333 | if (vwrq->disabled) { |
| 6334 | set_bit (FLAG_RADIO_OFF, &local->flags); |
| 6335 | set_bit (FLAG_COMMIT, &local->flags); |
| 6336 | return -EINPROGRESS; /* Call commit handler */ |
| 6337 | } |
| 6338 | if (vwrq->flags != IW_TXPOW_MWATT) { |
| 6339 | return -EINVAL; |
| 6340 | } |
| 6341 | clear_bit (FLAG_RADIO_OFF, &local->flags); |
| 6342 | for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++) |
| 6343 | if ((vwrq->value==cap_rid.txPowerLevels[i])) { |
| 6344 | readConfigRid(local, 1); |
| 6345 | local->config.txPower = vwrq->value; |
| 6346 | set_bit (FLAG_COMMIT, &local->flags); |
| 6347 | rc = -EINPROGRESS; /* Call commit handler */ |
| 6348 | break; |
| 6349 | } |
| 6350 | return rc; |
| 6351 | } |
| 6352 | |
| 6353 | /*------------------------------------------------------------------*/ |
| 6354 | /* |
| 6355 | * Wireless Handler : get Tx-Power |
| 6356 | */ |
| 6357 | static int airo_get_txpow(struct net_device *dev, |
| 6358 | struct iw_request_info *info, |
| 6359 | struct iw_param *vwrq, |
| 6360 | char *extra) |
| 6361 | { |
| 6362 | struct airo_info *local = dev->priv; |
| 6363 | |
| 6364 | readConfigRid(local, 1); |
| 6365 | vwrq->value = local->config.txPower; |
| 6366 | vwrq->fixed = 1; /* No power control */ |
| 6367 | vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags); |
| 6368 | vwrq->flags = IW_TXPOW_MWATT; |
| 6369 | |
| 6370 | return 0; |
| 6371 | } |
| 6372 | |
| 6373 | /*------------------------------------------------------------------*/ |
| 6374 | /* |
| 6375 | * Wireless Handler : set Retry limits |
| 6376 | */ |
| 6377 | static int airo_set_retry(struct net_device *dev, |
| 6378 | struct iw_request_info *info, |
| 6379 | struct iw_param *vwrq, |
| 6380 | char *extra) |
| 6381 | { |
| 6382 | struct airo_info *local = dev->priv; |
| 6383 | int rc = -EINVAL; |
| 6384 | |
| 6385 | if(vwrq->disabled) { |
| 6386 | return -EINVAL; |
| 6387 | } |
| 6388 | readConfigRid(local, 1); |
| 6389 | if(vwrq->flags & IW_RETRY_LIMIT) { |
| 6390 | if(vwrq->flags & IW_RETRY_MAX) |
| 6391 | local->config.longRetryLimit = vwrq->value; |
| 6392 | else if (vwrq->flags & IW_RETRY_MIN) |
| 6393 | local->config.shortRetryLimit = vwrq->value; |
| 6394 | else { |
| 6395 | /* No modifier : set both */ |
| 6396 | local->config.longRetryLimit = vwrq->value; |
| 6397 | local->config.shortRetryLimit = vwrq->value; |
| 6398 | } |
| 6399 | set_bit (FLAG_COMMIT, &local->flags); |
| 6400 | rc = -EINPROGRESS; /* Call commit handler */ |
| 6401 | } |
| 6402 | if(vwrq->flags & IW_RETRY_LIFETIME) { |
| 6403 | local->config.txLifetime = vwrq->value / 1024; |
| 6404 | set_bit (FLAG_COMMIT, &local->flags); |
| 6405 | rc = -EINPROGRESS; /* Call commit handler */ |
| 6406 | } |
| 6407 | return rc; |
| 6408 | } |
| 6409 | |
| 6410 | /*------------------------------------------------------------------*/ |
| 6411 | /* |
| 6412 | * Wireless Handler : get Retry limits |
| 6413 | */ |
| 6414 | static int airo_get_retry(struct net_device *dev, |
| 6415 | struct iw_request_info *info, |
| 6416 | struct iw_param *vwrq, |
| 6417 | char *extra) |
| 6418 | { |
| 6419 | struct airo_info *local = dev->priv; |
| 6420 | |
| 6421 | vwrq->disabled = 0; /* Can't be disabled */ |
| 6422 | |
| 6423 | readConfigRid(local, 1); |
| 6424 | /* Note : by default, display the min retry number */ |
| 6425 | if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
| 6426 | vwrq->flags = IW_RETRY_LIFETIME; |
| 6427 | vwrq->value = (int)local->config.txLifetime * 1024; |
| 6428 | } else if((vwrq->flags & IW_RETRY_MAX)) { |
| 6429 | vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 6430 | vwrq->value = (int)local->config.longRetryLimit; |
| 6431 | } else { |
| 6432 | vwrq->flags = IW_RETRY_LIMIT; |
| 6433 | vwrq->value = (int)local->config.shortRetryLimit; |
| 6434 | if((int)local->config.shortRetryLimit != (int)local->config.longRetryLimit) |
| 6435 | vwrq->flags |= IW_RETRY_MIN; |
| 6436 | } |
| 6437 | |
| 6438 | return 0; |
| 6439 | } |
| 6440 | |
| 6441 | /*------------------------------------------------------------------*/ |
| 6442 | /* |
| 6443 | * Wireless Handler : get range info |
| 6444 | */ |
| 6445 | static int airo_get_range(struct net_device *dev, |
| 6446 | struct iw_request_info *info, |
| 6447 | struct iw_point *dwrq, |
| 6448 | char *extra) |
| 6449 | { |
| 6450 | struct airo_info *local = dev->priv; |
| 6451 | struct iw_range *range = (struct iw_range *) extra; |
| 6452 | CapabilityRid cap_rid; /* Card capability info */ |
| 6453 | int i; |
| 6454 | int k; |
| 6455 | |
| 6456 | readCapabilityRid(local, &cap_rid, 1); |
| 6457 | |
| 6458 | dwrq->length = sizeof(struct iw_range); |
| 6459 | memset(range, 0, sizeof(*range)); |
| 6460 | range->min_nwid = 0x0000; |
| 6461 | range->max_nwid = 0x0000; |
| 6462 | range->num_channels = 14; |
| 6463 | /* Should be based on cap_rid.country to give only |
| 6464 | * what the current card support */ |
| 6465 | k = 0; |
| 6466 | for(i = 0; i < 14; i++) { |
| 6467 | range->freq[k].i = i + 1; /* List index */ |
| 6468 | range->freq[k].m = frequency_list[i] * 100000; |
| 6469 | range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */ |
| 6470 | } |
| 6471 | range->num_frequency = k; |
| 6472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6473 | range->sensitivity = 65535; |
| 6474 | |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6475 | /* Hum... Should put the right values there */ |
| 6476 | if (local->rssi) |
| 6477 | range->max_qual.qual = 100; /* % */ |
| 6478 | else |
| 6479 | range->max_qual.qual = airo_get_max_quality(&cap_rid); |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 6480 | range->max_qual.level = 0x100 - 120; /* -120 dBm */ |
| 6481 | range->max_qual.noise = 0x100 - 120; /* -120 dBm */ |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6482 | |
| 6483 | /* Experimental measurements - boundary 11/5.5 Mb/s */ |
| 6484 | /* Note : with or without the (local->rssi), results |
| 6485 | * are somewhat different. - Jean II */ |
| 6486 | if (local->rssi) { |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 6487 | range->avg_qual.qual = 50; /* % */ |
| 6488 | range->avg_qual.level = 0x100 - 70; /* -70 dBm */ |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6489 | } else { |
| 6490 | range->avg_qual.qual = airo_get_avg_quality(&cap_rid); |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 6491 | range->avg_qual.level = 0x100 - 80; /* -80 dBm */ |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6492 | } |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 6493 | range->avg_qual.noise = 0x100 - 85; /* -85 dBm */ |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6495 | for(i = 0 ; i < 8 ; i++) { |
| 6496 | range->bitrate[i] = cap_rid.supportedRates[i] * 500000; |
| 6497 | if(range->bitrate[i] == 0) |
| 6498 | break; |
| 6499 | } |
| 6500 | range->num_bitrates = i; |
| 6501 | |
| 6502 | /* Set an indication of the max TCP throughput |
| 6503 | * in bit/s that we can expect using this interface. |
| 6504 | * May be use for QoS stuff... Jean II */ |
| 6505 | if(i > 2) |
| 6506 | range->throughput = 5000 * 1000; |
| 6507 | else |
| 6508 | range->throughput = 1500 * 1000; |
| 6509 | |
| 6510 | range->min_rts = 0; |
| 6511 | range->max_rts = 2312; |
| 6512 | range->min_frag = 256; |
| 6513 | range->max_frag = 2312; |
| 6514 | |
| 6515 | if(cap_rid.softCap & 2) { |
| 6516 | // WEP: RC4 40 bits |
| 6517 | range->encoding_size[0] = 5; |
| 6518 | // RC4 ~128 bits |
| 6519 | if (cap_rid.softCap & 0x100) { |
| 6520 | range->encoding_size[1] = 13; |
| 6521 | range->num_encoding_sizes = 2; |
| 6522 | } else |
| 6523 | range->num_encoding_sizes = 1; |
| 6524 | range->max_encoding_tokens = (cap_rid.softCap & 0x80) ? 4 : 1; |
| 6525 | } else { |
| 6526 | range->num_encoding_sizes = 0; |
| 6527 | range->max_encoding_tokens = 0; |
| 6528 | } |
| 6529 | range->min_pmp = 0; |
| 6530 | range->max_pmp = 5000000; /* 5 secs */ |
| 6531 | range->min_pmt = 0; |
| 6532 | range->max_pmt = 65535 * 1024; /* ??? */ |
| 6533 | range->pmp_flags = IW_POWER_PERIOD; |
| 6534 | range->pmt_flags = IW_POWER_TIMEOUT; |
| 6535 | range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R; |
| 6536 | |
| 6537 | /* Transmit Power - values are in mW */ |
| 6538 | for(i = 0 ; i < 8 ; i++) { |
| 6539 | range->txpower[i] = cap_rid.txPowerLevels[i]; |
| 6540 | if(range->txpower[i] == 0) |
| 6541 | break; |
| 6542 | } |
| 6543 | range->num_txpower = i; |
| 6544 | range->txpower_capa = IW_TXPOW_MWATT; |
| 6545 | range->we_version_source = 12; |
| 6546 | range->we_version_compiled = WIRELESS_EXT; |
| 6547 | range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME; |
| 6548 | range->retry_flags = IW_RETRY_LIMIT; |
| 6549 | range->r_time_flags = IW_RETRY_LIFETIME; |
| 6550 | range->min_retry = 1; |
| 6551 | range->max_retry = 65535; |
| 6552 | range->min_r_time = 1024; |
| 6553 | range->max_r_time = 65535 * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6554 | |
| 6555 | /* Event capability (kernel + driver) */ |
| 6556 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 6557 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
| 6558 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | |
| 6559 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); |
| 6560 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
| 6561 | range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVTXDROP); |
| 6562 | return 0; |
| 6563 | } |
| 6564 | |
| 6565 | /*------------------------------------------------------------------*/ |
| 6566 | /* |
| 6567 | * Wireless Handler : set Power Management |
| 6568 | */ |
| 6569 | static int airo_set_power(struct net_device *dev, |
| 6570 | struct iw_request_info *info, |
| 6571 | struct iw_param *vwrq, |
| 6572 | char *extra) |
| 6573 | { |
| 6574 | struct airo_info *local = dev->priv; |
| 6575 | |
| 6576 | readConfigRid(local, 1); |
| 6577 | if (vwrq->disabled) { |
| 6578 | if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) { |
| 6579 | return -EINVAL; |
| 6580 | } |
| 6581 | local->config.powerSaveMode = POWERSAVE_CAM; |
| 6582 | local->config.rmode &= 0xFF00; |
| 6583 | local->config.rmode |= RXMODE_BC_MC_ADDR; |
| 6584 | set_bit (FLAG_COMMIT, &local->flags); |
| 6585 | return -EINPROGRESS; /* Call commit handler */ |
| 6586 | } |
| 6587 | if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { |
| 6588 | local->config.fastListenDelay = (vwrq->value + 500) / 1024; |
| 6589 | local->config.powerSaveMode = POWERSAVE_PSPCAM; |
| 6590 | set_bit (FLAG_COMMIT, &local->flags); |
| 6591 | } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) { |
| 6592 | local->config.fastListenInterval = local->config.listenInterval = (vwrq->value + 500) / 1024; |
| 6593 | local->config.powerSaveMode = POWERSAVE_PSPCAM; |
| 6594 | set_bit (FLAG_COMMIT, &local->flags); |
| 6595 | } |
| 6596 | switch (vwrq->flags & IW_POWER_MODE) { |
| 6597 | case IW_POWER_UNICAST_R: |
| 6598 | if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) { |
| 6599 | return -EINVAL; |
| 6600 | } |
| 6601 | local->config.rmode &= 0xFF00; |
| 6602 | local->config.rmode |= RXMODE_ADDR; |
| 6603 | set_bit (FLAG_COMMIT, &local->flags); |
| 6604 | break; |
| 6605 | case IW_POWER_ALL_R: |
| 6606 | if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) { |
| 6607 | return -EINVAL; |
| 6608 | } |
| 6609 | local->config.rmode &= 0xFF00; |
| 6610 | local->config.rmode |= RXMODE_BC_MC_ADDR; |
| 6611 | set_bit (FLAG_COMMIT, &local->flags); |
| 6612 | case IW_POWER_ON: |
| 6613 | break; |
| 6614 | default: |
| 6615 | return -EINVAL; |
| 6616 | } |
| 6617 | // Note : we may want to factor local->need_commit here |
| 6618 | // Note2 : may also want to factor RXMODE_RFMON test |
| 6619 | return -EINPROGRESS; /* Call commit handler */ |
| 6620 | } |
| 6621 | |
| 6622 | /*------------------------------------------------------------------*/ |
| 6623 | /* |
| 6624 | * Wireless Handler : get Power Management |
| 6625 | */ |
| 6626 | static int airo_get_power(struct net_device *dev, |
| 6627 | struct iw_request_info *info, |
| 6628 | struct iw_param *vwrq, |
| 6629 | char *extra) |
| 6630 | { |
| 6631 | struct airo_info *local = dev->priv; |
| 6632 | int mode; |
| 6633 | |
| 6634 | readConfigRid(local, 1); |
| 6635 | mode = local->config.powerSaveMode; |
| 6636 | if ((vwrq->disabled = (mode == POWERSAVE_CAM))) |
| 6637 | return 0; |
| 6638 | if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { |
| 6639 | vwrq->value = (int)local->config.fastListenDelay * 1024; |
| 6640 | vwrq->flags = IW_POWER_TIMEOUT; |
| 6641 | } else { |
| 6642 | vwrq->value = (int)local->config.fastListenInterval * 1024; |
| 6643 | vwrq->flags = IW_POWER_PERIOD; |
| 6644 | } |
| 6645 | if ((local->config.rmode & 0xFF) == RXMODE_ADDR) |
| 6646 | vwrq->flags |= IW_POWER_UNICAST_R; |
| 6647 | else |
| 6648 | vwrq->flags |= IW_POWER_ALL_R; |
| 6649 | |
| 6650 | return 0; |
| 6651 | } |
| 6652 | |
| 6653 | /*------------------------------------------------------------------*/ |
| 6654 | /* |
| 6655 | * Wireless Handler : set Sensitivity |
| 6656 | */ |
| 6657 | static int airo_set_sens(struct net_device *dev, |
| 6658 | struct iw_request_info *info, |
| 6659 | struct iw_param *vwrq, |
| 6660 | char *extra) |
| 6661 | { |
| 6662 | struct airo_info *local = dev->priv; |
| 6663 | |
| 6664 | readConfigRid(local, 1); |
| 6665 | local->config.rssiThreshold = vwrq->disabled ? RSSI_DEFAULT : vwrq->value; |
| 6666 | set_bit (FLAG_COMMIT, &local->flags); |
| 6667 | |
| 6668 | return -EINPROGRESS; /* Call commit handler */ |
| 6669 | } |
| 6670 | |
| 6671 | /*------------------------------------------------------------------*/ |
| 6672 | /* |
| 6673 | * Wireless Handler : get Sensitivity |
| 6674 | */ |
| 6675 | static int airo_get_sens(struct net_device *dev, |
| 6676 | struct iw_request_info *info, |
| 6677 | struct iw_param *vwrq, |
| 6678 | char *extra) |
| 6679 | { |
| 6680 | struct airo_info *local = dev->priv; |
| 6681 | |
| 6682 | readConfigRid(local, 1); |
| 6683 | vwrq->value = local->config.rssiThreshold; |
| 6684 | vwrq->disabled = (vwrq->value == 0); |
| 6685 | vwrq->fixed = 1; |
| 6686 | |
| 6687 | return 0; |
| 6688 | } |
| 6689 | |
| 6690 | /*------------------------------------------------------------------*/ |
| 6691 | /* |
| 6692 | * Wireless Handler : get AP List |
| 6693 | * Note : this is deprecated in favor of IWSCAN |
| 6694 | */ |
| 6695 | static int airo_get_aplist(struct net_device *dev, |
| 6696 | struct iw_request_info *info, |
| 6697 | struct iw_point *dwrq, |
| 6698 | char *extra) |
| 6699 | { |
| 6700 | struct airo_info *local = dev->priv; |
| 6701 | struct sockaddr *address = (struct sockaddr *) extra; |
| 6702 | struct iw_quality qual[IW_MAX_AP]; |
| 6703 | BSSListRid BSSList; |
| 6704 | int i; |
| 6705 | int loseSync = capable(CAP_NET_ADMIN) ? 1: -1; |
| 6706 | |
| 6707 | for (i = 0; i < IW_MAX_AP; i++) { |
| 6708 | if (readBSSListRid(local, loseSync, &BSSList)) |
| 6709 | break; |
| 6710 | loseSync = 0; |
| 6711 | memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN); |
| 6712 | address[i].sa_family = ARPHRD_ETHER; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6713 | if (local->rssi) { |
| 6714 | qual[i].level = 0x100 - BSSList.dBm; |
| 6715 | qual[i].qual = airo_dbm_to_pct( local->rssi, BSSList.dBm ); |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 6716 | qual[i].updated = IW_QUAL_QUAL_UPDATED |
| 6717 | | IW_QUAL_LEVEL_UPDATED |
| 6718 | | IW_QUAL_DBM; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6719 | } else { |
| 6720 | qual[i].level = (BSSList.dBm + 321) / 2; |
| 6721 | qual[i].qual = 0; |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 6722 | qual[i].updated = IW_QUAL_QUAL_INVALID |
| 6723 | | IW_QUAL_LEVEL_UPDATED |
| 6724 | | IW_QUAL_DBM; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6725 | } |
| 6726 | qual[i].noise = local->wstats.qual.noise; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6727 | if (BSSList.index == 0xffff) |
| 6728 | break; |
| 6729 | } |
| 6730 | if (!i) { |
| 6731 | StatusRid status_rid; /* Card status info */ |
| 6732 | readStatusRid(local, &status_rid, 1); |
| 6733 | for (i = 0; |
| 6734 | i < min(IW_MAX_AP, 4) && |
| 6735 | (status_rid.bssid[i][0] |
| 6736 | & status_rid.bssid[i][1] |
| 6737 | & status_rid.bssid[i][2] |
| 6738 | & status_rid.bssid[i][3] |
| 6739 | & status_rid.bssid[i][4] |
| 6740 | & status_rid.bssid[i][5])!=0xff && |
| 6741 | (status_rid.bssid[i][0] |
| 6742 | | status_rid.bssid[i][1] |
| 6743 | | status_rid.bssid[i][2] |
| 6744 | | status_rid.bssid[i][3] |
| 6745 | | status_rid.bssid[i][4] |
| 6746 | | status_rid.bssid[i][5]); |
| 6747 | i++) { |
| 6748 | memcpy(address[i].sa_data, |
| 6749 | status_rid.bssid[i], ETH_ALEN); |
| 6750 | address[i].sa_family = ARPHRD_ETHER; |
| 6751 | } |
| 6752 | } else { |
| 6753 | dwrq->flags = 1; /* Should be define'd */ |
| 6754 | memcpy(extra + sizeof(struct sockaddr)*i, |
| 6755 | &qual, sizeof(struct iw_quality)*i); |
| 6756 | } |
| 6757 | dwrq->length = i; |
| 6758 | |
| 6759 | return 0; |
| 6760 | } |
| 6761 | |
| 6762 | /*------------------------------------------------------------------*/ |
| 6763 | /* |
| 6764 | * Wireless Handler : Initiate Scan |
| 6765 | */ |
| 6766 | static int airo_set_scan(struct net_device *dev, |
| 6767 | struct iw_request_info *info, |
| 6768 | struct iw_param *vwrq, |
| 6769 | char *extra) |
| 6770 | { |
| 6771 | struct airo_info *ai = dev->priv; |
| 6772 | Cmd cmd; |
| 6773 | Resp rsp; |
| 6774 | |
| 6775 | /* Note : you may have realised that, as this is a SET operation, |
| 6776 | * this is privileged and therefore a normal user can't |
| 6777 | * perform scanning. |
| 6778 | * This is not an error, while the device perform scanning, |
| 6779 | * traffic doesn't flow, so it's a perfect DoS... |
| 6780 | * Jean II */ |
| 6781 | if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN; |
| 6782 | |
| 6783 | /* Initiate a scan command */ |
| 6784 | memset(&cmd, 0, sizeof(cmd)); |
| 6785 | cmd.cmd=CMD_LISTBSS; |
| 6786 | if (down_interruptible(&ai->sem)) |
| 6787 | return -ERESTARTSYS; |
| 6788 | issuecommand(ai, &cmd, &rsp); |
| 6789 | ai->scan_timestamp = jiffies; |
| 6790 | up(&ai->sem); |
| 6791 | |
| 6792 | /* At this point, just return to the user. */ |
| 6793 | |
| 6794 | return 0; |
| 6795 | } |
| 6796 | |
| 6797 | /*------------------------------------------------------------------*/ |
| 6798 | /* |
| 6799 | * Translate scan data returned from the card to a card independent |
| 6800 | * format that the Wireless Tools will understand - Jean II |
| 6801 | */ |
| 6802 | static inline char *airo_translate_scan(struct net_device *dev, |
| 6803 | char *current_ev, |
| 6804 | char *end_buf, |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6805 | BSSListRid *bss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6806 | { |
| 6807 | struct airo_info *ai = dev->priv; |
| 6808 | struct iw_event iwe; /* Temporary buffer */ |
| 6809 | u16 capabilities; |
| 6810 | char * current_val; /* For rates */ |
| 6811 | int i; |
| 6812 | |
| 6813 | /* First entry *MUST* be the AP MAC address */ |
| 6814 | iwe.cmd = SIOCGIWAP; |
| 6815 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6816 | memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6817 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN); |
| 6818 | |
| 6819 | /* Other entries will be displayed in the order we give them */ |
| 6820 | |
| 6821 | /* Add the ESSID */ |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6822 | iwe.u.data.length = bss->ssidLen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6823 | if(iwe.u.data.length > 32) |
| 6824 | iwe.u.data.length = 32; |
| 6825 | iwe.cmd = SIOCGIWESSID; |
| 6826 | iwe.u.data.flags = 1; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6827 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ssid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6828 | |
| 6829 | /* Add mode */ |
| 6830 | iwe.cmd = SIOCGIWMODE; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6831 | capabilities = le16_to_cpu(bss->cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6832 | if(capabilities & (CAP_ESS | CAP_IBSS)) { |
| 6833 | if(capabilities & CAP_ESS) |
| 6834 | iwe.u.mode = IW_MODE_MASTER; |
| 6835 | else |
| 6836 | iwe.u.mode = IW_MODE_ADHOC; |
| 6837 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN); |
| 6838 | } |
| 6839 | |
| 6840 | /* Add frequency */ |
| 6841 | iwe.cmd = SIOCGIWFREQ; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6842 | iwe.u.freq.m = le16_to_cpu(bss->dsChannel); |
matthieu castet | 1141455 | 2005-09-12 23:31:39 +0200 | [diff] [blame] | 6843 | /* iwe.u.freq.m containt the channel (starting 1), our |
| 6844 | * frequency_list array start at index 0... |
| 6845 | */ |
| 6846 | iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6847 | iwe.u.freq.e = 1; |
| 6848 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN); |
| 6849 | |
| 6850 | /* Add quality statistics */ |
| 6851 | iwe.cmd = IWEVQUAL; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6852 | if (ai->rssi) { |
| 6853 | iwe.u.qual.level = 0x100 - bss->dBm; |
| 6854 | iwe.u.qual.qual = airo_dbm_to_pct( ai->rssi, bss->dBm ); |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 6855 | iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED |
| 6856 | | IW_QUAL_LEVEL_UPDATED |
| 6857 | | IW_QUAL_DBM; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6858 | } else { |
| 6859 | iwe.u.qual.level = (bss->dBm + 321) / 2; |
| 6860 | iwe.u.qual.qual = 0; |
Jeff Garzik | bbeec90 | 2005-09-07 00:27:54 -0400 | [diff] [blame] | 6861 | iwe.u.qual.updated = IW_QUAL_QUAL_INVALID |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 6862 | | IW_QUAL_LEVEL_UPDATED |
| 6863 | | IW_QUAL_DBM; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6864 | } |
| 6865 | iwe.u.qual.noise = ai->wstats.qual.noise; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6866 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN); |
| 6867 | |
| 6868 | /* Add encryption capability */ |
| 6869 | iwe.cmd = SIOCGIWENCODE; |
| 6870 | if(capabilities & CAP_PRIVACY) |
| 6871 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 6872 | else |
| 6873 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 6874 | iwe.u.data.length = 0; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6875 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ssid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6876 | |
| 6877 | /* Rate : stuffing multiple values in a single event require a bit |
| 6878 | * more of magic - Jean II */ |
| 6879 | current_val = current_ev + IW_EV_LCP_LEN; |
| 6880 | |
| 6881 | iwe.cmd = SIOCGIWRATE; |
| 6882 | /* Those two flags are ignored... */ |
| 6883 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; |
| 6884 | /* Max 8 values */ |
| 6885 | for(i = 0 ; i < 8 ; i++) { |
| 6886 | /* NULL terminated */ |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6887 | if(bss->rates[i] == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6888 | break; |
| 6889 | /* Bit rate given in 500 kb/s units (+ 0x80) */ |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 6890 | iwe.u.bitrate.value = ((bss->rates[i] & 0x7f) * 500000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6891 | /* Add new value to event */ |
| 6892 | current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN); |
| 6893 | } |
| 6894 | /* Check if we added any event */ |
| 6895 | if((current_val - current_ev) > IW_EV_LCP_LEN) |
| 6896 | current_ev = current_val; |
| 6897 | |
| 6898 | /* The other data in the scan result are not really |
| 6899 | * interesting, so for now drop it - Jean II */ |
| 6900 | return current_ev; |
| 6901 | } |
| 6902 | |
| 6903 | /*------------------------------------------------------------------*/ |
| 6904 | /* |
| 6905 | * Wireless Handler : Read Scan Results |
| 6906 | */ |
| 6907 | static int airo_get_scan(struct net_device *dev, |
| 6908 | struct iw_request_info *info, |
| 6909 | struct iw_point *dwrq, |
| 6910 | char *extra) |
| 6911 | { |
| 6912 | struct airo_info *ai = dev->priv; |
| 6913 | BSSListRid BSSList; |
| 6914 | int rc; |
| 6915 | char *current_ev = extra; |
| 6916 | |
| 6917 | /* When we are associated again, the scan has surely finished. |
| 6918 | * Just in case, let's make sure enough time has elapsed since |
| 6919 | * we started the scan. - Javier */ |
| 6920 | if(ai->scan_timestamp && time_before(jiffies,ai->scan_timestamp+3*HZ)) { |
| 6921 | /* Important note : we don't want to block the caller |
| 6922 | * until results are ready for various reasons. |
| 6923 | * First, managing wait queues is complex and racy |
| 6924 | * (there may be multiple simultaneous callers). |
| 6925 | * Second, we grab some rtnetlink lock before comming |
| 6926 | * here (in dev_ioctl()). |
| 6927 | * Third, the caller can wait on the Wireless Event |
| 6928 | * - Jean II */ |
| 6929 | return -EAGAIN; |
| 6930 | } |
| 6931 | ai->scan_timestamp = 0; |
| 6932 | |
| 6933 | /* There's only a race with proc_BSSList_open(), but its |
| 6934 | * consequences are begnign. So I don't bother fixing it - Javier */ |
| 6935 | |
| 6936 | /* Try to read the first entry of the scan result */ |
| 6937 | rc = PC4500_readrid(ai, RID_BSSLISTFIRST, &BSSList, sizeof(BSSList), 1); |
| 6938 | if((rc) || (BSSList.index == 0xffff)) { |
| 6939 | /* Client error, no scan results... |
| 6940 | * The caller need to restart the scan. */ |
| 6941 | return -ENODATA; |
| 6942 | } |
| 6943 | |
| 6944 | /* Read and parse all entries */ |
| 6945 | while((!rc) && (BSSList.index != 0xffff)) { |
| 6946 | /* Translate to WE format this entry */ |
| 6947 | current_ev = airo_translate_scan(dev, current_ev, |
| 6948 | extra + dwrq->length, |
| 6949 | &BSSList); |
| 6950 | |
| 6951 | /* Check if there is space for one more entry */ |
| 6952 | if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) { |
| 6953 | /* Ask user space to try again with a bigger buffer */ |
| 6954 | return -E2BIG; |
| 6955 | } |
| 6956 | |
| 6957 | /* Read next entry */ |
| 6958 | rc = PC4500_readrid(ai, RID_BSSLISTNEXT, |
| 6959 | &BSSList, sizeof(BSSList), 1); |
| 6960 | } |
| 6961 | /* Length of data */ |
| 6962 | dwrq->length = (current_ev - extra); |
| 6963 | dwrq->flags = 0; /* todo */ |
| 6964 | |
| 6965 | return 0; |
| 6966 | } |
| 6967 | |
| 6968 | /*------------------------------------------------------------------*/ |
| 6969 | /* |
| 6970 | * Commit handler : called after a bunch of SET operations |
| 6971 | */ |
| 6972 | static int airo_config_commit(struct net_device *dev, |
| 6973 | struct iw_request_info *info, /* NULL */ |
| 6974 | void *zwrq, /* NULL */ |
| 6975 | char *extra) /* NULL */ |
| 6976 | { |
| 6977 | struct airo_info *local = dev->priv; |
| 6978 | Resp rsp; |
| 6979 | |
| 6980 | if (!test_bit (FLAG_COMMIT, &local->flags)) |
| 6981 | return 0; |
| 6982 | |
| 6983 | /* Some of the "SET" function may have modified some of the |
| 6984 | * parameters. It's now time to commit them in the card */ |
| 6985 | disable_MAC(local, 1); |
| 6986 | if (test_bit (FLAG_RESET, &local->flags)) { |
| 6987 | APListRid APList_rid; |
| 6988 | SsidRid SSID_rid; |
| 6989 | |
| 6990 | readAPListRid(local, &APList_rid); |
| 6991 | readSsidRid(local, &SSID_rid); |
| 6992 | if (test_bit(FLAG_MPI,&local->flags)) |
| 6993 | setup_card(local, dev->dev_addr, 1 ); |
| 6994 | else |
| 6995 | reset_airo_card(dev); |
| 6996 | disable_MAC(local, 1); |
| 6997 | writeSsidRid(local, &SSID_rid, 1); |
| 6998 | writeAPListRid(local, &APList_rid, 1); |
| 6999 | } |
| 7000 | if (down_interruptible(&local->sem)) |
| 7001 | return -ERESTARTSYS; |
| 7002 | writeConfigRid(local, 0); |
| 7003 | enable_MAC(local, &rsp, 0); |
| 7004 | if (test_bit (FLAG_RESET, &local->flags)) |
| 7005 | airo_set_promisc(local); |
| 7006 | else |
| 7007 | up(&local->sem); |
| 7008 | |
| 7009 | return 0; |
| 7010 | } |
| 7011 | |
| 7012 | /*------------------------------------------------------------------*/ |
| 7013 | /* |
| 7014 | * Structures to export the Wireless Handlers |
| 7015 | */ |
| 7016 | |
| 7017 | static const struct iw_priv_args airo_private_args[] = { |
| 7018 | /*{ cmd, set_args, get_args, name } */ |
| 7019 | { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl), |
| 7020 | IW_PRIV_TYPE_BYTE | 2047, "airoioctl" }, |
| 7021 | { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl), |
| 7022 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" }, |
| 7023 | }; |
| 7024 | |
| 7025 | static const iw_handler airo_handler[] = |
| 7026 | { |
| 7027 | (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */ |
| 7028 | (iw_handler) airo_get_name, /* SIOCGIWNAME */ |
| 7029 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 7030 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 7031 | (iw_handler) airo_set_freq, /* SIOCSIWFREQ */ |
| 7032 | (iw_handler) airo_get_freq, /* SIOCGIWFREQ */ |
| 7033 | (iw_handler) airo_set_mode, /* SIOCSIWMODE */ |
| 7034 | (iw_handler) airo_get_mode, /* SIOCGIWMODE */ |
| 7035 | (iw_handler) airo_set_sens, /* SIOCSIWSENS */ |
| 7036 | (iw_handler) airo_get_sens, /* SIOCGIWSENS */ |
| 7037 | (iw_handler) NULL, /* SIOCSIWRANGE */ |
| 7038 | (iw_handler) airo_get_range, /* SIOCGIWRANGE */ |
| 7039 | (iw_handler) NULL, /* SIOCSIWPRIV */ |
| 7040 | (iw_handler) NULL, /* SIOCGIWPRIV */ |
| 7041 | (iw_handler) NULL, /* SIOCSIWSTATS */ |
| 7042 | (iw_handler) NULL, /* SIOCGIWSTATS */ |
| 7043 | iw_handler_set_spy, /* SIOCSIWSPY */ |
| 7044 | iw_handler_get_spy, /* SIOCGIWSPY */ |
| 7045 | iw_handler_set_thrspy, /* SIOCSIWTHRSPY */ |
| 7046 | iw_handler_get_thrspy, /* SIOCGIWTHRSPY */ |
| 7047 | (iw_handler) airo_set_wap, /* SIOCSIWAP */ |
| 7048 | (iw_handler) airo_get_wap, /* SIOCGIWAP */ |
| 7049 | (iw_handler) NULL, /* -- hole -- */ |
| 7050 | (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */ |
| 7051 | (iw_handler) airo_set_scan, /* SIOCSIWSCAN */ |
| 7052 | (iw_handler) airo_get_scan, /* SIOCGIWSCAN */ |
| 7053 | (iw_handler) airo_set_essid, /* SIOCSIWESSID */ |
| 7054 | (iw_handler) airo_get_essid, /* SIOCGIWESSID */ |
| 7055 | (iw_handler) airo_set_nick, /* SIOCSIWNICKN */ |
| 7056 | (iw_handler) airo_get_nick, /* SIOCGIWNICKN */ |
| 7057 | (iw_handler) NULL, /* -- hole -- */ |
| 7058 | (iw_handler) NULL, /* -- hole -- */ |
| 7059 | (iw_handler) airo_set_rate, /* SIOCSIWRATE */ |
| 7060 | (iw_handler) airo_get_rate, /* SIOCGIWRATE */ |
| 7061 | (iw_handler) airo_set_rts, /* SIOCSIWRTS */ |
| 7062 | (iw_handler) airo_get_rts, /* SIOCGIWRTS */ |
| 7063 | (iw_handler) airo_set_frag, /* SIOCSIWFRAG */ |
| 7064 | (iw_handler) airo_get_frag, /* SIOCGIWFRAG */ |
| 7065 | (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */ |
| 7066 | (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */ |
| 7067 | (iw_handler) airo_set_retry, /* SIOCSIWRETRY */ |
| 7068 | (iw_handler) airo_get_retry, /* SIOCGIWRETRY */ |
| 7069 | (iw_handler) airo_set_encode, /* SIOCSIWENCODE */ |
| 7070 | (iw_handler) airo_get_encode, /* SIOCGIWENCODE */ |
| 7071 | (iw_handler) airo_set_power, /* SIOCSIWPOWER */ |
| 7072 | (iw_handler) airo_get_power, /* SIOCGIWPOWER */ |
| 7073 | }; |
| 7074 | |
| 7075 | /* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here. |
| 7076 | * We want to force the use of the ioctl code, because those can't be |
| 7077 | * won't work the iw_handler code (because they simultaneously read |
| 7078 | * and write data and iw_handler can't do that). |
| 7079 | * Note that it's perfectly legal to read/write on a single ioctl command, |
| 7080 | * you just can't use iwpriv and need to force it via the ioctl handler. |
| 7081 | * Jean II */ |
| 7082 | static const iw_handler airo_private_handler[] = |
| 7083 | { |
| 7084 | NULL, /* SIOCIWFIRSTPRIV */ |
| 7085 | }; |
| 7086 | |
| 7087 | static const struct iw_handler_def airo_handler_def = |
| 7088 | { |
| 7089 | .num_standard = sizeof(airo_handler)/sizeof(iw_handler), |
| 7090 | .num_private = sizeof(airo_private_handler)/sizeof(iw_handler), |
| 7091 | .num_private_args = sizeof(airo_private_args)/sizeof(struct iw_priv_args), |
| 7092 | .standard = airo_handler, |
| 7093 | .private = airo_private_handler, |
| 7094 | .private_args = airo_private_args, |
| 7095 | .get_wireless_stats = airo_get_wireless_stats, |
| 7096 | }; |
| 7097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7098 | /* |
| 7099 | * This defines the configuration part of the Wireless Extensions |
| 7100 | * Note : irq and spinlock protection will occur in the subroutines |
| 7101 | * |
| 7102 | * TODO : |
| 7103 | * o Check input value more carefully and fill correct values in range |
| 7104 | * o Test and shakeout the bugs (if any) |
| 7105 | * |
| 7106 | * Jean II |
| 7107 | * |
| 7108 | * Javier Achirica did a great job of merging code from the unnamed CISCO |
| 7109 | * developer that added support for flashing the card. |
| 7110 | */ |
| 7111 | static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 7112 | { |
| 7113 | int rc = 0; |
| 7114 | struct airo_info *ai = (struct airo_info *)dev->priv; |
| 7115 | |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 7116 | if (ai->power.event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7117 | return 0; |
| 7118 | |
| 7119 | switch (cmd) { |
| 7120 | #ifdef CISCO_EXT |
| 7121 | case AIROIDIFC: |
| 7122 | #ifdef AIROOLDIDIFC |
| 7123 | case AIROOLDIDIFC: |
| 7124 | #endif |
| 7125 | { |
| 7126 | int val = AIROMAGIC; |
| 7127 | aironet_ioctl com; |
| 7128 | if (copy_from_user(&com,rq->ifr_data,sizeof(com))) |
| 7129 | rc = -EFAULT; |
| 7130 | else if (copy_to_user(com.data,(char *)&val,sizeof(val))) |
| 7131 | rc = -EFAULT; |
| 7132 | } |
| 7133 | break; |
| 7134 | |
| 7135 | case AIROIOCTL: |
| 7136 | #ifdef AIROOLDIOCTL |
| 7137 | case AIROOLDIOCTL: |
| 7138 | #endif |
| 7139 | /* Get the command struct and hand it off for evaluation by |
| 7140 | * the proper subfunction |
| 7141 | */ |
| 7142 | { |
| 7143 | aironet_ioctl com; |
| 7144 | if (copy_from_user(&com,rq->ifr_data,sizeof(com))) { |
| 7145 | rc = -EFAULT; |
| 7146 | break; |
| 7147 | } |
| 7148 | |
| 7149 | /* Separate R/W functions bracket legality here |
| 7150 | */ |
| 7151 | if ( com.command == AIRORSWVERSION ) { |
| 7152 | if (copy_to_user(com.data, swversion, sizeof(swversion))) |
| 7153 | rc = -EFAULT; |
| 7154 | else |
| 7155 | rc = 0; |
| 7156 | } |
| 7157 | else if ( com.command <= AIRORRID) |
| 7158 | rc = readrids(dev,&com); |
| 7159 | else if ( com.command >= AIROPCAP && com.command <= (AIROPLEAPUSR+2) ) |
| 7160 | rc = writerids(dev,&com); |
| 7161 | else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART ) |
| 7162 | rc = flashcard(dev,&com); |
| 7163 | else |
| 7164 | rc = -EINVAL; /* Bad command in ioctl */ |
| 7165 | } |
| 7166 | break; |
| 7167 | #endif /* CISCO_EXT */ |
| 7168 | |
| 7169 | // All other calls are currently unsupported |
| 7170 | default: |
| 7171 | rc = -EOPNOTSUPP; |
| 7172 | } |
| 7173 | return rc; |
| 7174 | } |
| 7175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7176 | /* |
| 7177 | * Get the Wireless stats out of the driver |
| 7178 | * Note : irq and spinlock protection will occur in the subroutines |
| 7179 | * |
| 7180 | * TODO : |
| 7181 | * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs) |
| 7182 | * |
| 7183 | * Jean |
| 7184 | */ |
| 7185 | static void airo_read_wireless_stats(struct airo_info *local) |
| 7186 | { |
| 7187 | StatusRid status_rid; |
| 7188 | StatsRid stats_rid; |
| 7189 | CapabilityRid cap_rid; |
| 7190 | u32 *vals = stats_rid.vals; |
| 7191 | |
| 7192 | /* Get stats out of the card */ |
| 7193 | clear_bit(JOB_WSTATS, &local->flags); |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 7194 | if (local->power.event) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7195 | up(&local->sem); |
| 7196 | return; |
| 7197 | } |
| 7198 | readCapabilityRid(local, &cap_rid, 0); |
| 7199 | readStatusRid(local, &status_rid, 0); |
| 7200 | readStatsRid(local, &stats_rid, RID_STATS, 0); |
| 7201 | up(&local->sem); |
| 7202 | |
| 7203 | /* The status */ |
| 7204 | local->wstats.status = status_rid.mode; |
| 7205 | |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 7206 | /* Signal quality and co */ |
| 7207 | if (local->rssi) { |
| 7208 | local->wstats.qual.level = airo_rssi_to_dbm( local->rssi, status_rid.sigQuality ); |
| 7209 | /* normalizedSignalStrength appears to be a percentage */ |
| 7210 | local->wstats.qual.qual = status_rid.normalizedSignalStrength; |
| 7211 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7212 | local->wstats.qual.level = (status_rid.normalizedSignalStrength + 321) / 2; |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 7213 | local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid); |
| 7214 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7215 | if (status_rid.len >= 124) { |
Dan Williams | 41480af | 2005-05-10 09:45:51 -0400 | [diff] [blame] | 7216 | local->wstats.qual.noise = 0x100 - status_rid.noisedBm; |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 7217 | local->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7218 | } else { |
| 7219 | local->wstats.qual.noise = 0; |
Jean Tourrilhes | ce6623c | 2005-09-02 11:45:10 -0700 | [diff] [blame] | 7220 | local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID | IW_QUAL_DBM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7221 | } |
| 7222 | |
| 7223 | /* Packets discarded in the wireless adapter due to wireless |
| 7224 | * specific problems */ |
| 7225 | local->wstats.discard.nwid = vals[56] + vals[57] + vals[58];/* SSID Mismatch */ |
| 7226 | local->wstats.discard.code = vals[6];/* RxWepErr */ |
| 7227 | local->wstats.discard.fragment = vals[30]; |
| 7228 | local->wstats.discard.retries = vals[10]; |
| 7229 | local->wstats.discard.misc = vals[1] + vals[32]; |
| 7230 | local->wstats.miss.beacon = vals[34]; |
| 7231 | } |
| 7232 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 7233 | static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7234 | { |
| 7235 | struct airo_info *local = dev->priv; |
| 7236 | |
| 7237 | if (!test_bit(JOB_WSTATS, &local->flags)) { |
| 7238 | /* Get stats out of the card if available */ |
| 7239 | if (down_trylock(&local->sem) != 0) { |
| 7240 | set_bit(JOB_WSTATS, &local->flags); |
| 7241 | wake_up_interruptible(&local->thr_wait); |
| 7242 | } else |
| 7243 | airo_read_wireless_stats(local); |
| 7244 | } |
| 7245 | |
| 7246 | return &local->wstats; |
| 7247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7248 | |
| 7249 | #ifdef CISCO_EXT |
| 7250 | /* |
| 7251 | * This just translates from driver IOCTL codes to the command codes to |
| 7252 | * feed to the radio's host interface. Things can be added/deleted |
| 7253 | * as needed. This represents the READ side of control I/O to |
| 7254 | * the card |
| 7255 | */ |
| 7256 | static int readrids(struct net_device *dev, aironet_ioctl *comp) { |
| 7257 | unsigned short ridcode; |
| 7258 | unsigned char *iobuf; |
| 7259 | int len; |
| 7260 | struct airo_info *ai = dev->priv; |
| 7261 | Resp rsp; |
| 7262 | |
| 7263 | if (test_bit(FLAG_FLASHING, &ai->flags)) |
| 7264 | return -EIO; |
| 7265 | |
| 7266 | switch(comp->command) |
| 7267 | { |
| 7268 | case AIROGCAP: ridcode = RID_CAPABILITIES; break; |
| 7269 | case AIROGCFG: ridcode = RID_CONFIG; |
| 7270 | if (test_bit(FLAG_COMMIT, &ai->flags)) { |
| 7271 | disable_MAC (ai, 1); |
| 7272 | writeConfigRid (ai, 1); |
| 7273 | enable_MAC (ai, &rsp, 1); |
| 7274 | } |
| 7275 | break; |
| 7276 | case AIROGSLIST: ridcode = RID_SSID; break; |
| 7277 | case AIROGVLIST: ridcode = RID_APLIST; break; |
| 7278 | case AIROGDRVNAM: ridcode = RID_DRVNAME; break; |
| 7279 | case AIROGEHTENC: ridcode = RID_ETHERENCAP; break; |
| 7280 | case AIROGWEPKTMP: ridcode = RID_WEP_TEMP; |
| 7281 | /* Only super-user can read WEP keys */ |
| 7282 | if (!capable(CAP_NET_ADMIN)) |
| 7283 | return -EPERM; |
| 7284 | break; |
| 7285 | case AIROGWEPKNV: ridcode = RID_WEP_PERM; |
| 7286 | /* Only super-user can read WEP keys */ |
| 7287 | if (!capable(CAP_NET_ADMIN)) |
| 7288 | return -EPERM; |
| 7289 | break; |
| 7290 | case AIROGSTAT: ridcode = RID_STATUS; break; |
| 7291 | case AIROGSTATSD32: ridcode = RID_STATSDELTA; break; |
| 7292 | case AIROGSTATSC32: ridcode = RID_STATS; break; |
| 7293 | #ifdef MICSUPPORT |
| 7294 | case AIROGMICSTATS: |
| 7295 | if (copy_to_user(comp->data, &ai->micstats, |
| 7296 | min((int)comp->len,(int)sizeof(ai->micstats)))) |
| 7297 | return -EFAULT; |
| 7298 | return 0; |
| 7299 | #endif |
| 7300 | case AIRORRID: ridcode = comp->ridnum; break; |
| 7301 | default: |
| 7302 | return -EINVAL; |
| 7303 | break; |
| 7304 | } |
| 7305 | |
| 7306 | if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL) |
| 7307 | return -ENOMEM; |
| 7308 | |
| 7309 | PC4500_readrid(ai,ridcode,iobuf,RIDSIZE, 1); |
| 7310 | /* get the count of bytes in the rid docs say 1st 2 bytes is it. |
| 7311 | * then return it to the user |
| 7312 | * 9/22/2000 Honor user given length |
| 7313 | */ |
| 7314 | len = comp->len; |
| 7315 | |
| 7316 | if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) { |
| 7317 | kfree (iobuf); |
| 7318 | return -EFAULT; |
| 7319 | } |
| 7320 | kfree (iobuf); |
| 7321 | return 0; |
| 7322 | } |
| 7323 | |
| 7324 | /* |
| 7325 | * Danger Will Robinson write the rids here |
| 7326 | */ |
| 7327 | |
| 7328 | static int writerids(struct net_device *dev, aironet_ioctl *comp) { |
| 7329 | struct airo_info *ai = dev->priv; |
| 7330 | int ridcode; |
| 7331 | #ifdef MICSUPPORT |
| 7332 | int enabled; |
| 7333 | #endif |
| 7334 | Resp rsp; |
| 7335 | static int (* writer)(struct airo_info *, u16 rid, const void *, int, int); |
| 7336 | unsigned char *iobuf; |
| 7337 | |
| 7338 | /* Only super-user can write RIDs */ |
| 7339 | if (!capable(CAP_NET_ADMIN)) |
| 7340 | return -EPERM; |
| 7341 | |
| 7342 | if (test_bit(FLAG_FLASHING, &ai->flags)) |
| 7343 | return -EIO; |
| 7344 | |
| 7345 | ridcode = 0; |
| 7346 | writer = do_writerid; |
| 7347 | |
| 7348 | switch(comp->command) |
| 7349 | { |
| 7350 | case AIROPSIDS: ridcode = RID_SSID; break; |
| 7351 | case AIROPCAP: ridcode = RID_CAPABILITIES; break; |
| 7352 | case AIROPAPLIST: ridcode = RID_APLIST; break; |
| 7353 | case AIROPCFG: ai->config.len = 0; |
| 7354 | clear_bit(FLAG_COMMIT, &ai->flags); |
| 7355 | ridcode = RID_CONFIG; break; |
| 7356 | case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break; |
| 7357 | case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break; |
| 7358 | case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break; |
| 7359 | case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid; |
| 7360 | break; |
| 7361 | case AIROPLEAPUSR+1: ridcode = 0xFF2A; break; |
| 7362 | case AIROPLEAPUSR+2: ridcode = 0xFF2B; break; |
| 7363 | |
| 7364 | /* this is not really a rid but a command given to the card |
| 7365 | * same with MAC off |
| 7366 | */ |
| 7367 | case AIROPMACON: |
| 7368 | if (enable_MAC(ai, &rsp, 1) != 0) |
| 7369 | return -EIO; |
| 7370 | return 0; |
| 7371 | |
| 7372 | /* |
| 7373 | * Evidently this code in the airo driver does not get a symbol |
| 7374 | * as disable_MAC. it's probably so short the compiler does not gen one. |
| 7375 | */ |
| 7376 | case AIROPMACOFF: |
| 7377 | disable_MAC(ai, 1); |
| 7378 | return 0; |
| 7379 | |
| 7380 | /* This command merely clears the counts does not actually store any data |
| 7381 | * only reads rid. But as it changes the cards state, I put it in the |
| 7382 | * writerid routines. |
| 7383 | */ |
| 7384 | case AIROPSTCLR: |
| 7385 | if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL) |
| 7386 | return -ENOMEM; |
| 7387 | |
| 7388 | PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1); |
| 7389 | |
| 7390 | #ifdef MICSUPPORT |
| 7391 | enabled = ai->micstats.enabled; |
| 7392 | memset(&ai->micstats,0,sizeof(ai->micstats)); |
| 7393 | ai->micstats.enabled = enabled; |
| 7394 | #endif |
| 7395 | |
| 7396 | if (copy_to_user(comp->data, iobuf, |
| 7397 | min((int)comp->len, (int)RIDSIZE))) { |
| 7398 | kfree (iobuf); |
| 7399 | return -EFAULT; |
| 7400 | } |
| 7401 | kfree (iobuf); |
| 7402 | return 0; |
| 7403 | |
| 7404 | default: |
| 7405 | return -EOPNOTSUPP; /* Blarg! */ |
| 7406 | } |
| 7407 | if(comp->len > RIDSIZE) |
| 7408 | return -EINVAL; |
| 7409 | |
| 7410 | if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL) |
| 7411 | return -ENOMEM; |
| 7412 | |
| 7413 | if (copy_from_user(iobuf,comp->data,comp->len)) { |
| 7414 | kfree (iobuf); |
| 7415 | return -EFAULT; |
| 7416 | } |
| 7417 | |
| 7418 | if (comp->command == AIROPCFG) { |
| 7419 | ConfigRid *cfg = (ConfigRid *)iobuf; |
| 7420 | |
| 7421 | if (test_bit(FLAG_MIC_CAPABLE, &ai->flags)) |
| 7422 | cfg->opmode |= MODE_MIC; |
| 7423 | |
| 7424 | if ((cfg->opmode & 0xFF) == MODE_STA_IBSS) |
| 7425 | set_bit (FLAG_ADHOC, &ai->flags); |
| 7426 | else |
| 7427 | clear_bit (FLAG_ADHOC, &ai->flags); |
| 7428 | } |
| 7429 | |
| 7430 | if((*writer)(ai, ridcode, iobuf,comp->len,1)) { |
| 7431 | kfree (iobuf); |
| 7432 | return -EIO; |
| 7433 | } |
| 7434 | kfree (iobuf); |
| 7435 | return 0; |
| 7436 | } |
| 7437 | |
| 7438 | /***************************************************************************** |
| 7439 | * Ancillary flash / mod functions much black magic lurkes here * |
| 7440 | ***************************************************************************** |
| 7441 | */ |
| 7442 | |
| 7443 | /* |
| 7444 | * Flash command switch table |
| 7445 | */ |
| 7446 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 7447 | static int flashcard(struct net_device *dev, aironet_ioctl *comp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7448 | int z; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7449 | |
| 7450 | /* Only super-user can modify flash */ |
| 7451 | if (!capable(CAP_NET_ADMIN)) |
| 7452 | return -EPERM; |
| 7453 | |
| 7454 | switch(comp->command) |
| 7455 | { |
| 7456 | case AIROFLSHRST: |
| 7457 | return cmdreset((struct airo_info *)dev->priv); |
| 7458 | |
| 7459 | case AIROFLSHSTFL: |
| 7460 | if (!((struct airo_info *)dev->priv)->flash && |
| 7461 | (((struct airo_info *)dev->priv)->flash = kmalloc (FLASHSIZE, GFP_KERNEL)) == NULL) |
| 7462 | return -ENOMEM; |
| 7463 | return setflashmode((struct airo_info *)dev->priv); |
| 7464 | |
| 7465 | case AIROFLSHGCHR: /* Get char from aux */ |
| 7466 | if(comp->len != sizeof(int)) |
| 7467 | return -EINVAL; |
| 7468 | if (copy_from_user(&z,comp->data,comp->len)) |
| 7469 | return -EFAULT; |
| 7470 | return flashgchar((struct airo_info *)dev->priv,z,8000); |
| 7471 | |
| 7472 | case AIROFLSHPCHR: /* Send char to card. */ |
| 7473 | if(comp->len != sizeof(int)) |
| 7474 | return -EINVAL; |
| 7475 | if (copy_from_user(&z,comp->data,comp->len)) |
| 7476 | return -EFAULT; |
| 7477 | return flashpchar((struct airo_info *)dev->priv,z,8000); |
| 7478 | |
| 7479 | case AIROFLPUTBUF: /* Send 32k to card */ |
| 7480 | if (!((struct airo_info *)dev->priv)->flash) |
| 7481 | return -ENOMEM; |
| 7482 | if(comp->len > FLASHSIZE) |
| 7483 | return -EINVAL; |
| 7484 | if(copy_from_user(((struct airo_info *)dev->priv)->flash,comp->data,comp->len)) |
| 7485 | return -EFAULT; |
| 7486 | |
| 7487 | flashputbuf((struct airo_info *)dev->priv); |
| 7488 | return 0; |
| 7489 | |
| 7490 | case AIRORESTART: |
| 7491 | if(flashrestart((struct airo_info *)dev->priv,dev)) |
| 7492 | return -EIO; |
| 7493 | return 0; |
| 7494 | } |
| 7495 | return -EINVAL; |
| 7496 | } |
| 7497 | |
| 7498 | #define FLASH_COMMAND 0x7e7e |
| 7499 | |
| 7500 | /* |
| 7501 | * STEP 1) |
| 7502 | * Disable MAC and do soft reset on |
| 7503 | * card. |
| 7504 | */ |
| 7505 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 7506 | static int cmdreset(struct airo_info *ai) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7507 | disable_MAC(ai, 1); |
| 7508 | |
| 7509 | if(!waitbusy (ai)){ |
| 7510 | printk(KERN_INFO "Waitbusy hang before RESET\n"); |
| 7511 | return -EBUSY; |
| 7512 | } |
| 7513 | |
| 7514 | OUT4500(ai,COMMAND,CMD_SOFTRESET); |
| 7515 | |
| 7516 | ssleep(1); /* WAS 600 12/7/00 */ |
| 7517 | |
| 7518 | if(!waitbusy (ai)){ |
| 7519 | printk(KERN_INFO "Waitbusy hang AFTER RESET\n"); |
| 7520 | return -EBUSY; |
| 7521 | } |
| 7522 | return 0; |
| 7523 | } |
| 7524 | |
| 7525 | /* STEP 2) |
| 7526 | * Put the card in legendary flash |
| 7527 | * mode |
| 7528 | */ |
| 7529 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 7530 | static int setflashmode (struct airo_info *ai) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7531 | set_bit (FLAG_FLASHING, &ai->flags); |
| 7532 | |
| 7533 | OUT4500(ai, SWS0, FLASH_COMMAND); |
| 7534 | OUT4500(ai, SWS1, FLASH_COMMAND); |
| 7535 | if (probe) { |
| 7536 | OUT4500(ai, SWS0, FLASH_COMMAND); |
| 7537 | OUT4500(ai, COMMAND,0x10); |
| 7538 | } else { |
| 7539 | OUT4500(ai, SWS2, FLASH_COMMAND); |
| 7540 | OUT4500(ai, SWS3, FLASH_COMMAND); |
| 7541 | OUT4500(ai, COMMAND,0); |
| 7542 | } |
| 7543 | msleep(500); /* 500ms delay */ |
| 7544 | |
| 7545 | if(!waitbusy(ai)) { |
| 7546 | clear_bit (FLAG_FLASHING, &ai->flags); |
| 7547 | printk(KERN_INFO "Waitbusy hang after setflash mode\n"); |
| 7548 | return -EIO; |
| 7549 | } |
| 7550 | return 0; |
| 7551 | } |
| 7552 | |
| 7553 | /* Put character to SWS0 wait for dwelltime |
| 7554 | * x 50us for echo . |
| 7555 | */ |
| 7556 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 7557 | static int flashpchar(struct airo_info *ai,int byte,int dwelltime) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7558 | int echo; |
| 7559 | int waittime; |
| 7560 | |
| 7561 | byte |= 0x8000; |
| 7562 | |
| 7563 | if(dwelltime == 0 ) |
| 7564 | dwelltime = 200; |
| 7565 | |
| 7566 | waittime=dwelltime; |
| 7567 | |
| 7568 | /* Wait for busy bit d15 to go false indicating buffer empty */ |
| 7569 | while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) { |
| 7570 | udelay (50); |
| 7571 | waittime -= 50; |
| 7572 | } |
| 7573 | |
| 7574 | /* timeout for busy clear wait */ |
| 7575 | if(waittime <= 0 ){ |
| 7576 | printk(KERN_INFO "flash putchar busywait timeout! \n"); |
| 7577 | return -EBUSY; |
| 7578 | } |
| 7579 | |
| 7580 | /* Port is clear now write byte and wait for it to echo back */ |
| 7581 | do { |
| 7582 | OUT4500(ai,SWS0,byte); |
| 7583 | udelay(50); |
| 7584 | dwelltime -= 50; |
| 7585 | echo = IN4500(ai,SWS1); |
| 7586 | } while (dwelltime >= 0 && echo != byte); |
| 7587 | |
| 7588 | OUT4500(ai,SWS1,0); |
| 7589 | |
| 7590 | return (echo == byte) ? 0 : -EIO; |
| 7591 | } |
| 7592 | |
| 7593 | /* |
| 7594 | * Get a character from the card matching matchbyte |
| 7595 | * Step 3) |
| 7596 | */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 7597 | static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7598 | int rchar; |
| 7599 | unsigned char rbyte=0; |
| 7600 | |
| 7601 | do { |
| 7602 | rchar = IN4500(ai,SWS1); |
| 7603 | |
| 7604 | if(dwelltime && !(0x8000 & rchar)){ |
| 7605 | dwelltime -= 10; |
| 7606 | mdelay(10); |
| 7607 | continue; |
| 7608 | } |
| 7609 | rbyte = 0xff & rchar; |
| 7610 | |
| 7611 | if( (rbyte == matchbyte) && (0x8000 & rchar) ){ |
| 7612 | OUT4500(ai,SWS1,0); |
| 7613 | return 0; |
| 7614 | } |
| 7615 | if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar) |
| 7616 | break; |
| 7617 | OUT4500(ai,SWS1,0); |
| 7618 | |
| 7619 | }while(dwelltime > 0); |
| 7620 | return -EIO; |
| 7621 | } |
| 7622 | |
| 7623 | /* |
| 7624 | * Transfer 32k of firmware data from user buffer to our buffer and |
| 7625 | * send to the card |
| 7626 | */ |
| 7627 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 7628 | static int flashputbuf(struct airo_info *ai){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7629 | int nwords; |
| 7630 | |
| 7631 | /* Write stuff */ |
| 7632 | if (test_bit(FLAG_MPI,&ai->flags)) |
| 7633 | memcpy_toio(ai->pciaux + 0x8000, ai->flash, FLASHSIZE); |
| 7634 | else { |
| 7635 | OUT4500(ai,AUXPAGE,0x100); |
| 7636 | OUT4500(ai,AUXOFF,0); |
| 7637 | |
| 7638 | for(nwords=0;nwords != FLASHSIZE / 2;nwords++){ |
| 7639 | OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff); |
| 7640 | } |
| 7641 | } |
| 7642 | OUT4500(ai,SWS0,0x8000); |
| 7643 | |
| 7644 | return 0; |
| 7645 | } |
| 7646 | |
| 7647 | /* |
| 7648 | * |
| 7649 | */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 7650 | static int flashrestart(struct airo_info *ai,struct net_device *dev){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7651 | int i,status; |
| 7652 | |
| 7653 | ssleep(1); /* Added 12/7/00 */ |
| 7654 | clear_bit (FLAG_FLASHING, &ai->flags); |
| 7655 | if (test_bit(FLAG_MPI, &ai->flags)) { |
| 7656 | status = mpi_init_descriptors(ai); |
| 7657 | if (status != SUCCESS) |
| 7658 | return status; |
| 7659 | } |
| 7660 | status = setup_card(ai, dev->dev_addr, 1); |
| 7661 | |
| 7662 | if (!test_bit(FLAG_MPI,&ai->flags)) |
| 7663 | for( i = 0; i < MAX_FIDS; i++ ) { |
| 7664 | ai->fids[i] = transmit_allocate |
| 7665 | ( ai, 2312, i >= MAX_FIDS / 2 ); |
| 7666 | } |
| 7667 | |
| 7668 | ssleep(1); /* Added 12/7/00 */ |
| 7669 | return status; |
| 7670 | } |
| 7671 | #endif /* CISCO_EXT */ |
| 7672 | |
| 7673 | /* |
| 7674 | This program is free software; you can redistribute it and/or |
| 7675 | modify it under the terms of the GNU General Public License |
| 7676 | as published by the Free Software Foundation; either version 2 |
| 7677 | of the License, or (at your option) any later version. |
| 7678 | |
| 7679 | This program is distributed in the hope that it will be useful, |
| 7680 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 7681 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 7682 | GNU General Public License for more details. |
| 7683 | |
| 7684 | In addition: |
| 7685 | |
| 7686 | Redistribution and use in source and binary forms, with or without |
| 7687 | modification, are permitted provided that the following conditions |
| 7688 | are met: |
| 7689 | |
| 7690 | 1. Redistributions of source code must retain the above copyright |
| 7691 | notice, this list of conditions and the following disclaimer. |
| 7692 | 2. Redistributions in binary form must reproduce the above copyright |
| 7693 | notice, this list of conditions and the following disclaimer in the |
| 7694 | documentation and/or other materials provided with the distribution. |
| 7695 | 3. The name of the author may not be used to endorse or promote |
| 7696 | products derived from this software without specific prior written |
| 7697 | permission. |
| 7698 | |
| 7699 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 7700 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 7701 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 7702 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 7703 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 7704 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 7705 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 7706 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 7707 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 7708 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 7709 | POSSIBILITY OF SUCH DAMAGE. |
| 7710 | */ |
| 7711 | |
| 7712 | module_init(airo_init_module); |
| 7713 | module_exit(airo_cleanup_module); |