]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/wireless/airo.c
iwlwifi: cleanup usage of inline functions
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / airo.c
index 2d3a180dada035492f1c3d058e6ca63e3d7d0b69..932d6b1c9d0bad70b45a285faafedd602426c5e1 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/crypto.h>
 #include <asm/io.h>
 #include <asm/system.h>
+#include <asm/unaligned.h>
 
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
@@ -52,6 +53,8 @@
 
 #include "airo.h"
 
+#define DRV_NAME "airo"
+
 #ifdef CONFIG_PCI
 static struct pci_device_id card_ids[] = {
        { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, },
@@ -71,7 +74,7 @@ static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state);
 static int airo_pci_resume(struct pci_dev *pdev);
 
 static struct pci_driver airo_driver = {
-       .name     = "airo",
+       .name     = DRV_NAME,
        .id_table = card_ids,
        .probe    = airo_pci_probe,
        .remove   = __devexit_p(airo_pci_remove),
@@ -239,8 +242,8 @@ static int proc_perm = 0644;
 
 MODULE_AUTHOR("Benjamin Reed");
 MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \
-                   cards.  Direct support for ISA/PCI/MPI cards and support \
-                  for PCMCIA when used with airo_cs.");
+cards.  Direct support for ISA/PCI/MPI cards and support \
+for PCMCIA when used with airo_cs.");
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340/350");
 module_param_array(io, int, NULL, 0);
@@ -498,140 +501,143 @@ typedef struct {
 /* This structure came from an email sent to me from an engineer at
    aironet for inclusion into this driver */
 typedef struct {
-       u16 len;
-       u16 kindex;
+       __le16 len;
+       __le16 kindex;
        u8 mac[ETH_ALEN];
-       u16 klen;
+       __le16 klen;
        u8 key[16];
 } WepKeyRid;
 
 /* These structures are from the Aironet's PC4500 Developers Manual */
 typedef struct {
-       u16 len;
+       __le16 len;
        u8 ssid[32];
 } Ssid;
 
 typedef struct {
-       u16 len;
+       __le16 len;
        Ssid ssids[3];
 } SsidRid;
 
 typedef struct {
-        u16 len;
-        u16 modulation;
-#define MOD_DEFAULT 0
-#define MOD_CCK 1
-#define MOD_MOK 2
+        __le16 len;
+        __le16 modulation;
+#define MOD_DEFAULT cpu_to_le16(0)
+#define MOD_CCK cpu_to_le16(1)
+#define MOD_MOK cpu_to_le16(2)
 } ModulationRid;
 
 typedef struct {
-       u16 len; /* sizeof(ConfigRid) */
-       u16 opmode; /* operating mode */
-#define MODE_STA_IBSS 0
-#define MODE_STA_ESS 1
-#define MODE_AP 2
-#define MODE_AP_RPTR 3
-#define MODE_ETHERNET_HOST (0<<8) /* rx payloads converted */
-#define MODE_LLC_HOST (1<<8) /* rx payloads left as is */
-#define MODE_AIRONET_EXTEND (1<<9) /* enable Aironet extenstions */
-#define MODE_AP_INTERFACE (1<<10) /* enable ap interface extensions */
-#define MODE_ANTENNA_ALIGN (1<<11) /* enable antenna alignment */
-#define MODE_ETHER_LLC (1<<12) /* enable ethernet LLC */
-#define MODE_LEAF_NODE (1<<13) /* enable leaf node bridge */
-#define MODE_CF_POLLABLE (1<<14) /* enable CF pollable */
-#define MODE_MIC (1<<15) /* enable MIC */
-       u16 rmode; /* receive mode */
-#define RXMODE_BC_MC_ADDR 0
-#define RXMODE_BC_ADDR 1 /* ignore multicasts */
-#define RXMODE_ADDR 2 /* ignore multicast and broadcast */
-#define RXMODE_RFMON 3 /* wireless monitor mode */
-#define RXMODE_RFMON_ANYBSS 4
-#define RXMODE_LANMON 5 /* lan style monitor -- data packets only */
-#define RXMODE_DISABLE_802_3_HEADER (1<<8) /* disables 802.3 header on rx */
-#define RXMODE_NORMALIZED_RSSI (1<<9) /* return normalized RSSI */
-       u16 fragThresh;
-       u16 rtsThres;
+       __le16 len; /* sizeof(ConfigRid) */
+       __le16 opmode; /* operating mode */
+#define MODE_STA_IBSS cpu_to_le16(0)
+#define MODE_STA_ESS cpu_to_le16(1)
+#define MODE_AP cpu_to_le16(2)
+#define MODE_AP_RPTR cpu_to_le16(3)
+#define MODE_CFG_MASK cpu_to_le16(0xff)
+#define MODE_ETHERNET_HOST cpu_to_le16(0<<8) /* rx payloads converted */
+#define MODE_LLC_HOST cpu_to_le16(1<<8) /* rx payloads left as is */
+#define MODE_AIRONET_EXTEND cpu_to_le16(1<<9) /* enable Aironet extenstions */
+#define MODE_AP_INTERFACE cpu_to_le16(1<<10) /* enable ap interface extensions */
+#define MODE_ANTENNA_ALIGN cpu_to_le16(1<<11) /* enable antenna alignment */
+#define MODE_ETHER_LLC cpu_to_le16(1<<12) /* enable ethernet LLC */
+#define MODE_LEAF_NODE cpu_to_le16(1<<13) /* enable leaf node bridge */
+#define MODE_CF_POLLABLE cpu_to_le16(1<<14) /* enable CF pollable */
+#define MODE_MIC cpu_to_le16(1<<15) /* enable MIC */
+       __le16 rmode; /* receive mode */
+#define RXMODE_BC_MC_ADDR cpu_to_le16(0)
+#define RXMODE_BC_ADDR cpu_to_le16(1) /* ignore multicasts */
+#define RXMODE_ADDR cpu_to_le16(2) /* ignore multicast and broadcast */
+#define RXMODE_RFMON cpu_to_le16(3) /* wireless monitor mode */
+#define RXMODE_RFMON_ANYBSS cpu_to_le16(4)
+#define RXMODE_LANMON cpu_to_le16(5) /* lan style monitor -- data packets only */
+#define RXMODE_MASK cpu_to_le16(255)
+#define RXMODE_DISABLE_802_3_HEADER cpu_to_le16(1<<8) /* disables 802.3 header on rx */
+#define RXMODE_FULL_MASK (RXMODE_MASK | RXMODE_DISABLE_802_3_HEADER)
+#define RXMODE_NORMALIZED_RSSI cpu_to_le16(1<<9) /* return normalized RSSI */
+       __le16 fragThresh;
+       __le16 rtsThres;
        u8 macAddr[ETH_ALEN];
        u8 rates[8];
-       u16 shortRetryLimit;
-       u16 longRetryLimit;
-       u16 txLifetime; /* in kusec */
-       u16 rxLifetime; /* in kusec */
-       u16 stationary;
-       u16 ordering;
-       u16 u16deviceType; /* for overriding device type */
-       u16 cfpRate;
-       u16 cfpDuration;
-       u16 _reserved1[3];
+       __le16 shortRetryLimit;
+       __le16 longRetryLimit;
+       __le16 txLifetime; /* in kusec */
+       __le16 rxLifetime; /* in kusec */
+       __le16 stationary;
+       __le16 ordering;
+       __le16 u16deviceType; /* for overriding device type */
+       __le16 cfpRate;
+       __le16 cfpDuration;
+       __le16 _reserved1[3];
        /*---------- Scanning/Associating ----------*/
-       u16 scanMode;
-#define SCANMODE_ACTIVE 0
-#define SCANMODE_PASSIVE 1
-#define SCANMODE_AIROSCAN 2
-       u16 probeDelay; /* in kusec */
-       u16 probeEnergyTimeout; /* in kusec */
-        u16 probeResponseTimeout;
-       u16 beaconListenTimeout;
-       u16 joinNetTimeout;
-       u16 authTimeout;
-       u16 authType;
-#define AUTH_OPEN 0x1
-#define AUTH_ENCRYPT 0x101
-#define AUTH_SHAREDKEY 0x102
-#define AUTH_ALLOW_UNENCRYPTED 0x200
-       u16 associationTimeout;
-       u16 specifiedApTimeout;
-       u16 offlineScanInterval;
-       u16 offlineScanDuration;
-       u16 linkLossDelay;
-       u16 maxBeaconLostTime;
-       u16 refreshInterval;
-#define DISABLE_REFRESH 0xFFFF
-       u16 _reserved1a[1];
+       __le16 scanMode;
+#define SCANMODE_ACTIVE cpu_to_le16(0)
+#define SCANMODE_PASSIVE cpu_to_le16(1)
+#define SCANMODE_AIROSCAN cpu_to_le16(2)
+       __le16 probeDelay; /* in kusec */
+       __le16 probeEnergyTimeout; /* in kusec */
+        __le16 probeResponseTimeout;
+       __le16 beaconListenTimeout;
+       __le16 joinNetTimeout;
+       __le16 authTimeout;
+       __le16 authType;
+#define AUTH_OPEN cpu_to_le16(0x1)
+#define AUTH_ENCRYPT cpu_to_le16(0x101)
+#define AUTH_SHAREDKEY cpu_to_le16(0x102)
+#define AUTH_ALLOW_UNENCRYPTED cpu_to_le16(0x200)
+       __le16 associationTimeout;
+       __le16 specifiedApTimeout;
+       __le16 offlineScanInterval;
+       __le16 offlineScanDuration;
+       __le16 linkLossDelay;
+       __le16 maxBeaconLostTime;
+       __le16 refreshInterval;
+#define DISABLE_REFRESH cpu_to_le16(0xFFFF)
+       __le16 _reserved1a[1];
        /*---------- Power save operation ----------*/
-       u16 powerSaveMode;
-#define POWERSAVE_CAM 0
-#define POWERSAVE_PSP 1
-#define POWERSAVE_PSPCAM 2
-       u16 sleepForDtims;
-       u16 listenInterval;
-       u16 fastListenInterval;
-       u16 listenDecay;
-       u16 fastListenDelay;
-       u16 _reserved2[2];
+       __le16 powerSaveMode;
+#define POWERSAVE_CAM cpu_to_le16(0)
+#define POWERSAVE_PSP cpu_to_le16(1)
+#define POWERSAVE_PSPCAM cpu_to_le16(2)
+       __le16 sleepForDtims;
+       __le16 listenInterval;
+       __le16 fastListenInterval;
+       __le16 listenDecay;
+       __le16 fastListenDelay;
+       __le16 _reserved2[2];
        /*---------- Ap/Ibss config items ----------*/
-       u16 beaconPeriod;
-       u16 atimDuration;
-       u16 hopPeriod;
-       u16 channelSet;
-       u16 channel;
-       u16 dtimPeriod;
-       u16 bridgeDistance;
-       u16 radioID;
+       __le16 beaconPeriod;
+       __le16 atimDuration;
+       __le16 hopPeriod;
+       __le16 channelSet;
+       __le16 channel;
+       __le16 dtimPeriod;
+       __le16 bridgeDistance;
+       __le16 radioID;
        /*---------- Radio configuration ----------*/
-       u16 radioType;
-#define RADIOTYPE_DEFAULT 0
-#define RADIOTYPE_802_11 1
-#define RADIOTYPE_LEGACY 2
+       __le16 radioType;
+#define RADIOTYPE_DEFAULT cpu_to_le16(0)
+#define RADIOTYPE_802_11 cpu_to_le16(1)
+#define RADIOTYPE_LEGACY cpu_to_le16(2)
        u8 rxDiversity;
        u8 txDiversity;
-       u16 txPower;
+       __le16 txPower;
 #define TXPOWER_DEFAULT 0
-       u16 rssiThreshold;
+       __le16 rssiThreshold;
 #define RSSI_DEFAULT 0
-        u16 modulation;
-#define PREAMBLE_AUTO 0
-#define PREAMBLE_LONG 1
-#define PREAMBLE_SHORT 2
-       u16 preamble;
-       u16 homeProduct;
-       u16 radioSpecific;
+        __le16 modulation;
+#define PREAMBLE_AUTO cpu_to_le16(0)
+#define PREAMBLE_LONG cpu_to_le16(1)
+#define PREAMBLE_SHORT cpu_to_le16(2)
+       __le16 preamble;
+       __le16 homeProduct;
+       __le16 radioSpecific;
        /*---------- Aironet Extensions ----------*/
        u8 nodeName[16];
-       u16 arlThreshold;
-       u16 arlDecay;
-       u16 arlDelay;
-       u16 _reserved4[1];
+       __le16 arlThreshold;
+       __le16 arlDecay;
+       __le16 arlDelay;
+       __le16 _reserved4[1];
        /*---------- Aironet Extensions ----------*/
        u8 magicAction;
 #define MAGIC_ACTION_STSCHG 1
@@ -641,34 +647,34 @@ typedef struct {
 #define MAGIC_SWITCH_TO_PSP (0<<10)
 #define MAGIC_STAY_IN_CAM (1<<10)
        u8 magicControl;
-       u16 autoWake;
+       __le16 autoWake;
 } ConfigRid;
 
 typedef struct {
-       u16 len;
+       __le16 len;
        u8 mac[ETH_ALEN];
-       u16 mode;
-       u16 errorCode;
-       u16 sigQuality;
-       u16 SSIDlen;
+       __le16 mode;
+       __le16 errorCode;
+       __le16 sigQuality;
+       __le16 SSIDlen;
        char SSID[32];
        char apName[16];
        u8 bssid[4][ETH_ALEN];
-       u16 beaconPeriod;
-       u16 dimPeriod;
-       u16 atimDuration;
-       u16 hopPeriod;
-       u16 channelSet;
-       u16 channel;
-       u16 hopsToBackbone;
-       u16 apTotalLoad;
-       u16 generatedLoad;
-       u16 accumulatedArl;
-       u16 signalQuality;
-       u16 currentXmitRate;
-       u16 apDevExtensions;
-       u16 normalizedSignalStrength;
-       u16 shortPreamble;
+       __le16 beaconPeriod;
+       __le16 dimPeriod;
+       __le16 atimDuration;
+       __le16 hopPeriod;
+       __le16 channelSet;
+       __le16 channel;
+       __le16 hopsToBackbone;
+       __le16 apTotalLoad;
+       __le16 generatedLoad;
+       __le16 accumulatedArl;
+       __le16 signalQuality;
+       __le16 currentXmitRate;
+       __le16 apDevExtensions;
+       __le16 normalizedSignalStrength;
+       __le16 shortPreamble;
        u8 apIP[4];
        u8 noisePercent; /* Noise percent in last second */
        u8 noisedBm; /* Noise dBm in last second */
@@ -676,9 +682,9 @@ typedef struct {
        u8 noiseAvedBm; /* Noise dBm in last minute */
        u8 noiseMaxPercent; /* Highest noise percent in last minute */
        u8 noiseMaxdBm; /* Highest noise dbm in last minute */
-       u16 load;
+       __le16 load;
        u8 carrier[4];
-       u16 assocStatus;
+       __le16 assocStatus;
 #define STAT_NOPACKETS 0
 #define STAT_NOCARRIERSET 10
 #define STAT_GOTCARRIERSET 11
@@ -703,82 +709,82 @@ typedef struct {
 } StatusRid;
 
 typedef struct {
-       u16 len;
-       u16 spacer;
-       u32 vals[100];
+       __le16 len;
+       __le16 spacer;
+       __le32 vals[100];
 } StatsRid;
 
 
 typedef struct {
-       u16 len;
+       __le16 len;
        u8 ap[4][ETH_ALEN];
 } APListRid;
 
 typedef struct {
-       u16 len;
+       __le16 len;
        char oui[3];
        char zero;
-       u16 prodNum;
+       __le16 prodNum;
        char manName[32];
        char prodName[16];
        char prodVer[8];
        char factoryAddr[ETH_ALEN];
        char aironetAddr[ETH_ALEN];
-       u16 radioType;
-       u16 country;
+       __le16 radioType;
+       __le16 country;
        char callid[ETH_ALEN];
        char supportedRates[8];
        char rxDiversity;
        char txDiversity;
-       u16 txPowerLevels[8];
-       u16 hardVer;
-       u16 hardCap;
-       u16 tempRange;
-       u16 softVer;
-       u16 softSubVer;
-       u16 interfaceVer;
-       u16 softCap;
-       u16 bootBlockVer;
-       u16 requiredHard;
-       u16 extSoftCap;
+       __le16 txPowerLevels[8];
+       __le16 hardVer;
+       __le16 hardCap;
+       __le16 tempRange;
+       __le16 softVer;
+       __le16 softSubVer;
+       __le16 interfaceVer;
+       __le16 softCap;
+       __le16 bootBlockVer;
+       __le16 requiredHard;
+       __le16 extSoftCap;
 } CapabilityRid;
 
 
 /* Only present on firmware >= 5.30.17 */
 typedef struct {
-  u16 unknown[4];
+  __le16 unknown[4];
   u8 fixed[12]; /* WLAN management frame */
   u8 iep[624];
 } BSSListRidExtra;
 
 typedef struct {
-  u16 len;
-  u16 index; /* First is 0 and 0xffff means end of list */
+  __le16 len;
+  __le16 index; /* First is 0 and 0xffff means end of list */
 #define RADIO_FH 1 /* Frequency hopping radio type */
 #define RADIO_DS 2 /* Direct sequence radio type */
 #define RADIO_TMA 4 /* Proprietary radio used in old cards (2500) */
-  u16 radioType;
+  __le16 radioType;
   u8 bssid[ETH_ALEN]; /* Mac address of the BSS */
   u8 zero;
   u8 ssidLen;
   u8 ssid[32];
-  u16 dBm;
-#define CAP_ESS (1<<0)
-#define CAP_IBSS (1<<1)
-#define CAP_PRIVACY (1<<4)
-#define CAP_SHORTHDR (1<<5)
-  u16 cap;
-  u16 beaconInterval;
+  __le16 dBm;
+#define CAP_ESS cpu_to_le16(1<<0)
+#define CAP_IBSS cpu_to_le16(1<<1)
+#define CAP_PRIVACY cpu_to_le16(1<<4)
+#define CAP_SHORTHDR cpu_to_le16(1<<5)
+  __le16 cap;
+  __le16 beaconInterval;
   u8 rates[8]; /* Same as rates for config rid */
   struct { /* For frequency hopping only */
-    u16 dwell;
+    __le16 dwell;
     u8 hopSet;
     u8 hopPattern;
     u8 hopIndex;
     u8 fill;
   } fh;
-  u16 dsChannel;
-  u16 atimWindow;
+  __le16 dsChannel;
+  __le16 atimWindow;
 
   /* Only present on firmware >= 5.30.17 */
   BSSListRidExtra extra;
@@ -809,7 +815,7 @@ typedef struct {
 } MICRid;
 
 typedef struct {
-       u16 typelen;
+       __be16 typelen;
 
        union {
            u8 snap[8];
@@ -821,8 +827,8 @@ typedef struct {
                u8 fieldtype[2];
            } llc;
        } u;
-       u32 mic;
-       u32 seq;
+       __be32 mic;
+       __be32 seq;
 } MICBuffer;
 
 typedef struct {
@@ -941,7 +947,7 @@ typedef struct {
        int position;   // current position (byte offset) in message
        union {
                u8  d8[4];
-               u32 d32;
+               __be32 d32;
        } part; // saves partial message word across update() calls
 } emmh32_context;
 
@@ -1092,17 +1098,17 @@ static int get_dec_u16( char *buffer, int *start, int limit );
 static void OUT4500( struct airo_info *, u16 register, u16 value );
 static unsigned short IN4500( struct airo_info *, u16 register );
 static u16 setup_card(struct airo_info*, u8 *mac, int lock);
-static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock );
+static int enable_MAC(struct airo_info *ai, int lock);
 static void disable_MAC(struct airo_info *ai, int lock);
 static void enable_interrupts(struct airo_info*);
 static void disable_interrupts(struct airo_info*);
 static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
 static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
-static int aux_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
+static int aux_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen,
                        int whichbap);
-static int fast_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
+static int fast_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen,
                         int whichbap);
-static int bap_write(struct airo_info*, const u16 *pu16Src, int bytelen,
+static int bap_write(struct airo_info*, const __le16 *pu16Src, int bytelen,
                     int whichbap);
 static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
 static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock);
@@ -1185,7 +1191,7 @@ struct airo_info {
 #define JOB_WSTATS     8
 #define JOB_SCAN_RESULTS  9
        unsigned long jobs;
-       int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen,
+       int (*bap_read)(struct airo_info*, __le16 *pu16Dst, int bytelen,
                        int whichbap);
        unsigned short *flash;
        tdsRssiEntry *rssi;
@@ -1233,8 +1239,9 @@ struct airo_info {
        BSSListElement *networks;
 };
 
-static inline int bap_read(struct airo_info *ai, u16 *pu16Dst, int bytelen,
-                          int whichbap) {
+static inline int bap_read(struct airo_info *ai, __le16 *pu16Dst, int bytelen,
+                          int whichbap)
+{
        return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
 }
 
@@ -1250,7 +1257,7 @@ static int flashputbuf(struct airo_info *ai);
 static int flashrestart(struct airo_info *ai,struct net_device *dev);
 
 #define airo_print(type, name, fmt, args...) \
-       { printk(type "airo(%s): " fmt "\n", name, ##args); }
+       printk(type DRV_NAME "(%s): " fmt "\n", name, ##args)
 
 #define airo_print_info(name, fmt, args...) \
        airo_print(KERN_INFO, name, fmt, ##args)
@@ -1633,7 +1640,7 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
                crypto_cipher_encrypt_one(tfm, plain, plain);
                cipher = plain;
                for (j = 0; (j < 16) && (i < ARRAY_SIZE(context->coeff)); ) {
-                       context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
+                       context->coeff[i++] = ntohl(*(__be32 *)&cipher[j]);
                        j += 4;
                }
        }
@@ -1666,12 +1673,12 @@ static void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
                        context->position++;
                        len--;
                } while (byte_position < 4);
-               MIC_ACCUM(htonl(context->part.d32));
+               MIC_ACCUM(ntohl(context->part.d32));
        }
 
        /* deal with full 32-bit words */
        while (len >= 4) {
-               MIC_ACCUM(htonl(*(u32 *)pOctets));
+               MIC_ACCUM(ntohl(*(__be32 *)pOctets));
                context->position += 4;
                pOctets += 4;
                len -= 4;
@@ -1704,7 +1711,7 @@ static void emmh32_final(emmh32_context *context, u8 digest[4])
        byte_position = context->position & 3;
        if (byte_position) {
                /* have a partial word in part to deal with */
-               val = htonl(context->part.d32);
+               val = ntohl(context->part.d32);
                MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */
        }
 
@@ -1724,8 +1731,8 @@ static void emmh32_final(emmh32_context *context, u8 digest[4])
 }
 
 static int readBSSListRid(struct airo_info *ai, int first,
-                     BSSListRid *list) {
-       int rc;
+                     BSSListRid *list)
+{
        Cmd cmd;
        Resp rsp;
 
@@ -1742,75 +1749,43 @@ static int readBSSListRid(struct airo_info *ai, int first,
                schedule_timeout_uninterruptible(3 * HZ);
                ai->list_bss_task = NULL;
        }
-       rc = PC4500_readrid(ai, first ? ai->bssListFirst : ai->bssListNext,
+       return PC4500_readrid(ai, first ? ai->bssListFirst : ai->bssListNext,
                            list, ai->bssListRidLen, 1);
-
-       list->len = le16_to_cpu(list->len);
-       list->index = le16_to_cpu(list->index);
-       list->radioType = le16_to_cpu(list->radioType);
-       list->cap = le16_to_cpu(list->cap);
-       list->beaconInterval = le16_to_cpu(list->beaconInterval);
-       list->fh.dwell = le16_to_cpu(list->fh.dwell);
-       list->dsChannel = le16_to_cpu(list->dsChannel);
-       list->atimWindow = le16_to_cpu(list->atimWindow);
-       list->dBm = le16_to_cpu(list->dBm);
-       return rc;
 }
 
-static int readWepKeyRid(struct airo_info*ai, WepKeyRid *wkr, int temp, int lock) {
-       int rc = PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
+static int readWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int temp, int lock)
+{
+       return PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
                                wkr, sizeof(*wkr), lock);
-
-       wkr->len = le16_to_cpu(wkr->len);
-       wkr->kindex = le16_to_cpu(wkr->kindex);
-       wkr->klen = le16_to_cpu(wkr->klen);
-       return rc;
 }
-/* In the writeXXXRid routines we copy the rids so that we don't screwup
- * the originals when we endian them... */
-static int writeWepKeyRid(struct airo_info*ai, WepKeyRid *pwkr, int perm, int lock) {
-       int rc;
-       WepKeyRid wkr = *pwkr;
 
-       wkr.len = cpu_to_le16(wkr.len);
-       wkr.kindex = cpu_to_le16(wkr.kindex);
-       wkr.klen = cpu_to_le16(wkr.klen);
-       rc = PC4500_writerid(ai, RID_WEP_TEMP, &wkr, sizeof(wkr), lock);
-       if (rc!=SUCCESS) airo_print_err(ai->dev->name, "WEP_TEMP set %x", rc);
+static int writeWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int perm, int lock)
+{
+       int rc;
+       rc = PC4500_writerid(ai, RID_WEP_TEMP, wkr, sizeof(*wkr), lock);
+       if (rc!=SUCCESS)
+               airo_print_err(ai->dev->name, "WEP_TEMP set %x", rc);
        if (perm) {
-               rc = PC4500_writerid(ai, RID_WEP_PERM, &wkr, sizeof(wkr), lock);
-               if (rc!=SUCCESS) {
+               rc = PC4500_writerid(ai, RID_WEP_PERM, wkr, sizeof(*wkr), lock);
+               if (rc!=SUCCESS)
                        airo_print_err(ai->dev->name, "WEP_PERM set %x", rc);
-               }
        }
        return rc;
 }
 
-static int readSsidRid(struct airo_info*ai, SsidRid *ssidr) {
-       int i;
-       int rc = PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
-
-       ssidr->len = le16_to_cpu(ssidr->len);
-       for(i = 0; i < 3; i++) {
-               ssidr->ssids[i].len = le16_to_cpu(ssidr->ssids[i].len);
-       }
-       return rc;
+static int readSsidRid(struct airo_info*ai, SsidRid *ssidr)
+{
+       return PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
 }
-static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock) {
-       int rc;
-       int i;
-       SsidRid ssidr = *pssidr;
 
-       ssidr.len = cpu_to_le16(ssidr.len);
-       for(i = 0; i < 3; i++) {
-               ssidr.ssids[i].len = cpu_to_le16(ssidr.ssids[i].len);
-       }
-       rc = PC4500_writerid(ai, RID_SSID, &ssidr, sizeof(ssidr), lock);
-       return rc;
+static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock)
+{
+       return PC4500_writerid(ai, RID_SSID, pssidr, sizeof(*pssidr), lock);
 }
-static int readConfigRid(struct airo_info*ai, int lock) {
+
+static int readConfigRid(struct airo_info *ai, int lock)
+{
        int rc;
-       u16 *s;
        ConfigRid cfg;
 
        if (ai->config.len)
@@ -1820,24 +1795,12 @@ static int readConfigRid(struct airo_info*ai, int lock) {
        if (rc != SUCCESS)
                return rc;
 
-       for(s = &cfg.len; s <= &cfg.rtsThres; s++) *s = le16_to_cpu(*s);
-
-       for(s = &cfg.shortRetryLimit; s <= &cfg.radioType; s++)
-               *s = le16_to_cpu(*s);
-
-       for(s = &cfg.txPower; s <= &cfg.radioSpecific; s++)
-               *s = le16_to_cpu(*s);
-
-       for(s = &cfg.arlThreshold; s <= &cfg._reserved4[0]; s++)
-               *s = cpu_to_le16(*s);
-
-       for(s = &cfg.autoWake; s <= &cfg.autoWake; s++)
-               *s = cpu_to_le16(*s);
-
        ai->config = cfg;
        return SUCCESS;
 }
-static inline void checkThrottle(struct airo_info *ai) {
+
+static inline void checkThrottle(struct airo_info *ai)
+{
        int i;
 /* Old hardware had a limit on encryption speed */
        if (ai->config.authType != AUTH_OPEN && maxencrypt) {
@@ -1848,8 +1811,9 @@ static inline void checkThrottle(struct airo_info *ai) {
                }
        }
 }
-static int writeConfigRid(struct airo_info*ai, int lock) {
-       u16 *s;
+
+static int writeConfigRid(struct airo_info *ai, int lock)
+{
        ConfigRid cfgr;
 
        if (!test_bit (FLAG_COMMIT, &ai->flags))
@@ -1860,94 +1824,87 @@ static int writeConfigRid(struct airo_info*ai, int lock) {
        checkThrottle(ai);
        cfgr = ai->config;
 
-       if ((cfgr.opmode & 0xFF) == MODE_STA_IBSS)
+       if ((cfgr.opmode & MODE_CFG_MASK) == MODE_STA_IBSS)
                set_bit(FLAG_ADHOC, &ai->flags);
        else
                clear_bit(FLAG_ADHOC, &ai->flags);
 
-       for(s = &cfgr.len; s <= &cfgr.rtsThres; s++) *s = cpu_to_le16(*s);
-
-       for(s = &cfgr.shortRetryLimit; s <= &cfgr.radioType; s++)
-               *s = cpu_to_le16(*s);
-
-       for(s = &cfgr.txPower; s <= &cfgr.radioSpecific; s++)
-               *s = cpu_to_le16(*s);
-
-       for(s = &cfgr.arlThreshold; s <= &cfgr._reserved4[0]; s++)
-               *s = cpu_to_le16(*s);
-
-       for(s = &cfgr.autoWake; s <= &cfgr.autoWake; s++)
-               *s = cpu_to_le16(*s);
-
        return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock);
 }
-static int readStatusRid(struct airo_info*ai, StatusRid *statr, int lock) {
-       int rc = PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
-       u16 *s;
 
-       statr->len = le16_to_cpu(statr->len);
-       for(s = &statr->mode; s <= &statr->SSIDlen; s++) *s = le16_to_cpu(*s);
+static int readStatusRid(struct airo_info *ai, StatusRid *statr, int lock)
+{
+       return PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
+}
 
-       for(s = &statr->beaconPeriod; s <= &statr->shortPreamble; s++)
-               *s = le16_to_cpu(*s);
-       statr->load = le16_to_cpu(statr->load);
-       statr->assocStatus = le16_to_cpu(statr->assocStatus);
-       return rc;
+static int readAPListRid(struct airo_info *ai, APListRid *aplr)
+{
+       return PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1);
 }
-static int readAPListRid(struct airo_info*ai, APListRid *aplr) {
-       int rc =  PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1);
-       aplr->len = le16_to_cpu(aplr->len);
-       return rc;
+
+static int writeAPListRid(struct airo_info *ai, APListRid *aplr, int lock)
+{
+       return PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
 }
-static int writeAPListRid(struct airo_info*ai, APListRid *aplr, int lock) {
-       int rc;
-       aplr->len = cpu_to_le16(aplr->len);
-       rc = PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
-       return rc;
+
+static int readCapabilityRid(struct airo_info *ai, CapabilityRid *capr, int lock)
+{
+       return PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
 }
-static int readCapabilityRid(struct airo_info*ai, CapabilityRid *capr, int lock) {
-       int rc = PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
-       u16 *s;
 
-       capr->len = le16_to_cpu(capr->len);
-       capr->prodNum = le16_to_cpu(capr->prodNum);
-       capr->radioType = le16_to_cpu(capr->radioType);
-       capr->country = le16_to_cpu(capr->country);
-       for(s = &capr->txPowerLevels[0]; s <= &capr->requiredHard; s++)
-               *s = le16_to_cpu(*s);
-       return rc;
+static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock)
+{
+       return PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
 }
-static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock) {
-       int rc = PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
-       u32 *i;
 
-       sr->len = le16_to_cpu(sr->len);
-       for(i = &sr->vals[0]; i <= &sr->vals[99]; i++) *i = le32_to_cpu(*i);
-       return rc;
+static void try_auto_wep(struct airo_info *ai)
+{
+       if (auto_wep && !(ai->flags & FLAG_RADIO_DOWN)) {
+               ai->expires = RUN_AT(3*HZ);
+               wake_up_interruptible(&ai->thr_wait);
+       }
 }
 
 static int airo_open(struct net_device *dev) {
-       struct airo_info *info = dev->priv;
-       Resp rsp;
+       struct airo_info *ai = dev->priv;
+       int rc = 0;
 
-       if (test_bit(FLAG_FLASHING, &info->flags))
+       if (test_bit(FLAG_FLASHING, &ai->flags))
                return -EIO;
 
        /* Make sure the card is configured.
         * Wireless Extensions may postpone config changes until the card
         * is open (to pipeline changes and speed-up card setup). If
         * those changes are not yet commited, do it now - Jean II */
-       if (test_bit (FLAG_COMMIT, &info->flags)) {
-               disable_MAC(info, 1);
-               writeConfigRid(info, 1);
+       if (test_bit(FLAG_COMMIT, &ai->flags)) {
+               disable_MAC(ai, 1);
+               writeConfigRid(ai, 1);
        }
 
-       if (info->wifidev != dev) {
+       if (ai->wifidev != dev) {
+               clear_bit(JOB_DIE, &ai->jobs);
+               ai->airo_thread_task = kthread_run(airo_thread, dev, dev->name);
+               if (IS_ERR(ai->airo_thread_task))
+                       return (int)PTR_ERR(ai->airo_thread_task);
+
+               rc = request_irq(dev->irq, airo_interrupt, IRQF_SHARED,
+                       dev->name, dev);
+               if (rc) {
+                       airo_print_err(dev->name,
+                               "register interrupt %d failed, rc %d",
+                               dev->irq, rc);
+                       set_bit(JOB_DIE, &ai->jobs);
+                       kthread_stop(ai->airo_thread_task);
+                       return rc;
+               }
+
                /* Power on the MAC controller (which may have been disabled) */
-               clear_bit(FLAG_RADIO_DOWN, &info->flags);
-               enable_interrupts(info);
+               clear_bit(FLAG_RADIO_DOWN, &ai->flags);
+               enable_interrupts(ai);
+
+               try_auto_wep(ai);
        }
-       enable_MAC(info, &rsp, 1);
+       enable_MAC(ai, 1);
 
        netif_start_queue(dev);
        return 0;
@@ -1998,13 +1955,14 @@ static int mpi_send_packet (struct net_device *dev)
 {
        struct sk_buff *skb;
        unsigned char *buffer;
-       s16 len, *payloadLen;
+       s16 len;
+       __le16 *payloadLen;
        struct airo_info *ai = dev->priv;
        u8 *sendbuf;
 
        /* get a packet to send */
 
-       if ((skb = skb_dequeue(&ai->txq)) == 0) {
+       if ((skb = skb_dequeue(&ai->txq)) == NULL) {
                airo_print_err(dev->name,
                        "%s: Dequeue'd zero in send_packet()",
                        __FUNCTION__);
@@ -2031,7 +1989,7 @@ static int mpi_send_packet (struct net_device *dev)
        memcpy((char *)ai->txfids[0].virtual_host_addr,
                (char *)&wifictlhdr8023, sizeof(wifictlhdr8023));
 
-       payloadLen = (s16 *)(ai->txfids[0].virtual_host_addr +
+       payloadLen = (__le16 *)(ai->txfids[0].virtual_host_addr +
                sizeof(wifictlhdr8023));
        sendbuf = ai->txfids[0].virtual_host_addr +
                sizeof(wifictlhdr8023) + 2 ;
@@ -2041,7 +1999,7 @@ static int mpi_send_packet (struct net_device *dev)
         * we don't need to account for it in the length
         */
        if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
-               (ntohs(((u16 *)buffer)[6]) != 0x888E)) {
+               (ntohs(((__be16 *)buffer)[6]) != 0x888E)) {
                MICBuffer pMic;
 
                if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS)
@@ -2076,7 +2034,7 @@ static int mpi_send_packet (struct net_device *dev)
 
 static void get_tx_error(struct airo_info *ai, s32 fid)
 {
-       u16 status;
+       __le16 status;
 
        if (fid < 0)
                status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status;
@@ -2107,7 +2065,7 @@ static void get_tx_error(struct airo_info *ai, s32 fid)
                /* Faster to skip over useless data than to do
                 * another bap_setup(). We are at offset 0x6 and
                 * need to go to 0x18 and read 6 bytes - Jean II */
-               bap_read(ai, (u16 *) junk, 0x18, BAP0);
+               bap_read(ai, (__le16 *) junk, 0x18, BAP0);
 
                /* Copy 802.11 dest address.
                 * We use the 802.11 header because the frame may
@@ -2261,9 +2219,10 @@ static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
        return 0;
 }
 
-static void airo_read_stats(struct airo_info *ai) {
+static void airo_read_stats(struct airo_info *ai)
+{
        StatsRid stats_rid;
-       u32 *vals = stats_rid.vals;
+       __le32 *vals = stats_rid.vals;
 
        clear_bit(JOB_STATS, &ai->jobs);
        if (ai->power.event) {
@@ -2273,20 +2232,23 @@ static void airo_read_stats(struct airo_info *ai) {
        readStatsRid(ai, &stats_rid, RID_STATS, 0);
        up(&ai->sem);
 
-       ai->stats.rx_packets = vals[43] + vals[44] + vals[45];
-       ai->stats.tx_packets = vals[39] + vals[40] + vals[41];
-       ai->stats.rx_bytes = vals[92];
-       ai->stats.tx_bytes = vals[91];
-       ai->stats.rx_errors = vals[0] + vals[2] + vals[3] + vals[4];
-       ai->stats.tx_errors = vals[42] + ai->stats.tx_fifo_errors;
-       ai->stats.multicast = vals[43];
-       ai->stats.collisions = vals[89];
+       ai->stats.rx_packets = le32_to_cpu(vals[43]) + le32_to_cpu(vals[44]) +
+                              le32_to_cpu(vals[45]);
+       ai->stats.tx_packets = le32_to_cpu(vals[39]) + le32_to_cpu(vals[40]) +
+                              le32_to_cpu(vals[41]);
+       ai->stats.rx_bytes = le32_to_cpu(vals[92]);
+       ai->stats.tx_bytes = le32_to_cpu(vals[91]);
+       ai->stats.rx_errors = le32_to_cpu(vals[0]) + le32_to_cpu(vals[2]) +
+                             le32_to_cpu(vals[3]) + le32_to_cpu(vals[4]);
+       ai->stats.tx_errors = le32_to_cpu(vals[42]) + ai->stats.tx_fifo_errors;
+       ai->stats.multicast = le32_to_cpu(vals[43]);
+       ai->stats.collisions = le32_to_cpu(vals[89]);
 
        /* detailed rx_errors: */
-       ai->stats.rx_length_errors = vals[3];
-       ai->stats.rx_crc_errors = vals[4];
-       ai->stats.rx_frame_errors = vals[2];
-       ai->stats.rx_fifo_errors = vals[0];
+       ai->stats.rx_length_errors = le32_to_cpu(vals[3]);
+       ai->stats.rx_crc_errors = le32_to_cpu(vals[4]);
+       ai->stats.rx_frame_errors = le32_to_cpu(vals[2]);
+       ai->stats.rx_fifo_errors = le32_to_cpu(vals[0]);
 }
 
 static struct net_device_stats *airo_get_stats(struct net_device *dev)
@@ -2338,14 +2300,13 @@ static int airo_set_mac_address(struct net_device *dev, void *p)
 {
        struct airo_info *ai = dev->priv;
        struct sockaddr *addr = p;
-       Resp rsp;
 
        readConfigRid(ai, 1);
        memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
        set_bit (FLAG_COMMIT, &ai->flags);
        disable_MAC(ai, 1);
        writeConfigRid (ai, 1);
-       enable_MAC(ai, &rsp, 1);
+       enable_MAC(ai, 1);
        memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
        if (ai->wifidev)
                memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
@@ -2392,6 +2353,11 @@ static int airo_close(struct net_device *dev) {
                disable_MAC(ai, 1);
 #endif
                disable_interrupts( ai );
+
+               free_irq(dev->irq, dev);
+
+               set_bit(JOB_DIE, &ai->jobs);
+               kthread_stop(ai->airo_thread_task);
        }
        return 0;
 }
@@ -2403,7 +2369,6 @@ void stop_airo_card( struct net_device *dev, int freeres )
        set_bit(FLAG_RADIO_DOWN, &ai->flags);
        disable_MAC(ai, 1);
        disable_interrupts(ai);
-       free_irq( dev->irq, dev );
        takedown_proc_entry( dev, ai );
        if (test_bit(FLAG_REGISTERED, &ai->flags)) {
                unregister_netdev( dev );
@@ -2414,9 +2379,6 @@ void stop_airo_card( struct net_device *dev, int freeres )
                }
                clear_bit(FLAG_REGISTERED, &ai->flags);
        }
-       set_bit(JOB_DIE, &ai->jobs);
-       kthread_stop(ai->airo_thread_task);
-
        /*
         * Clean out tx queue
         */
@@ -2453,7 +2415,7 @@ void stop_airo_card( struct net_device *dev, int freeres )
 
 EXPORT_SYMBOL(stop_airo_card);
 
-static int wll_header_parse(struct sk_buff *skb, unsigned char *haddr)
+static int wll_header_parse(const struct sk_buff *skb, unsigned char *haddr)
 {
        memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN);
        return ETH_ALEN;
@@ -2554,8 +2516,7 @@ static int mpi_init_descriptors (struct airo_info *ai)
  * 2) Map PCI memory for issueing commands.
  * 3) Allocate memory (shared) to send and receive ethernet frames.
  */
-static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
-                   const char *name)
+static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci)
 {
        unsigned long mem_start, mem_len, aux_start, aux_len;
        int rc = -1;
@@ -2569,35 +2530,35 @@ static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
        aux_start = pci_resource_start(pci, 2);
        aux_len = AUXMEMSIZE;
 
-       if (!request_mem_region(mem_start, mem_len, name)) {
-               airo_print_err(ai->dev->name, "Couldn't get region %x[%x] for %s",
-                      (int)mem_start, (int)mem_len, name);
+       if (!request_mem_region(mem_start, mem_len, DRV_NAME)) {
+               airo_print_err("", "Couldn't get region %x[%x]",
+                       (int)mem_start, (int)mem_len);
                goto out;
        }
-       if (!request_mem_region(aux_start, aux_len, name)) {
-               airo_print_err(ai->dev->name, "Couldn't get region %x[%x] for %s",
-                      (int)aux_start, (int)aux_len, name);
+       if (!request_mem_region(aux_start, aux_len, DRV_NAME)) {
+               airo_print_err("", "Couldn't get region %x[%x]",
+                       (int)aux_start, (int)aux_len);
                goto free_region1;
        }
 
        ai->pcimem = ioremap(mem_start, mem_len);
        if (!ai->pcimem) {
-               airo_print_err(ai->dev->name, "Couldn't map region %x[%x] for %s",
-                      (int)mem_start, (int)mem_len, name);
+               airo_print_err("", "Couldn't map region %x[%x]",
+                       (int)mem_start, (int)mem_len);
                goto free_region2;
        }
        ai->pciaux = ioremap(aux_start, aux_len);
        if (!ai->pciaux) {
-               airo_print_err(ai->dev->name, "Couldn't map region %x[%x] for %s",
-                      (int)aux_start, (int)aux_len, name);
+               airo_print_err("", "Couldn't map region %x[%x]",
+                       (int)aux_start, (int)aux_len);
                goto free_memmap;
        }
 
        /* Reserve PKTSIZE for each fid and 2K for the Rids */
        ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
        if (!ai->shared) {
-               airo_print_err(ai->dev->name, "Couldn't alloc_consistent %d",
-                      PCI_SHARED_LEN);
+               airo_print_err("", "Couldn't alloc_consistent %d",
+                       PCI_SHARED_LEN);
                goto free_auxmap;
        }
 
@@ -2669,14 +2630,13 @@ static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
        return rc;
 }
 
+static const struct header_ops airo_header_ops = {
+       .parse = wll_header_parse,
+};
+
 static void wifi_setup(struct net_device *dev)
 {
-       dev->hard_header        = NULL;
-       dev->rebuild_header     = NULL;
-       dev->hard_header_cache  = NULL;
-       dev->header_cache_update= NULL;
-
-       dev->hard_header_parse  = wll_header_parse;
+       dev->header_ops = &airo_header_ops;
        dev->hard_start_xmit = &airo_start_xmit11;
        dev->get_stats = &airo_get_stats;
        dev->set_mac_address = &airo_set_mac_address;
@@ -2742,7 +2702,7 @@ static int airo_networks_allocate(struct airo_info *ai)
            kzalloc(AIRO_MAX_NETWORK_COUNT * sizeof(BSSListElement),
                    GFP_KERNEL);
        if (!ai->networks) {
-               airo_print_warn(ai->dev->name, "Out of memory allocating beacons");
+               airo_print_warn("", "Out of memory allocating beacons");
                return -ENOMEM;
        }
 
@@ -2770,20 +2730,20 @@ static int airo_test_wpa_capable(struct airo_info *ai)
 {
        int status;
        CapabilityRid cap_rid;
-       const char *name = ai->dev->name;
 
        status = readCapabilityRid(ai, &cap_rid, 1);
        if (status != SUCCESS) return 0;
 
        /* Only firmware versions 5.30.17 or better can do WPA */
-       if ((cap_rid.softVer > 0x530)
-         || ((cap_rid.softVer == 0x530) && (cap_rid.softSubVer >= 17))) {
-               airo_print_info(name, "WPA is supported.");
+       if (le16_to_cpu(cap_rid.softVer) > 0x530
+         || (le16_to_cpu(cap_rid.softVer) == 0x530
+             && le16_to_cpu(cap_rid.softSubVer) >= 17)) {
+               airo_print_info("", "WPA is supported.");
                return 1;
        }
 
        /* No WPA support */
-       airo_print_info(name, "WPA unsupported (only firmware versions 5.30.17"
+       airo_print_info("", "WPA unsupported (only firmware versions 5.30.17"
                " and greater support WPA.  Detected %s)", cap_rid.prodVer);
        return 0;
 }
@@ -2795,25 +2755,22 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
        struct net_device *dev;
        struct airo_info *ai;
        int i, rc;
+       DECLARE_MAC_BUF(mac);
 
        /* Create the network device object. */
-        dev = alloc_etherdev(sizeof(*ai));
-        if (!dev) {
+       dev = alloc_netdev(sizeof(*ai), "", ether_setup);
+       if (!dev) {
                airo_print_err("", "Couldn't alloc_etherdev");
                return NULL;
-        }
-       if (dev_alloc_name(dev, dev->name) < 0) {
-               airo_print_err("", "Couldn't get name!");
-               goto err_out_free;
        }
 
        ai = dev->priv;
        ai->wifidev = NULL;
-       ai->flags = 0;
+       ai->flags = 1 << FLAG_RADIO_DOWN;
        ai->jobs = 0;
        ai->dev = dev;
        if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
-               airo_print_dbg(dev->name, "Found an MPI350 card");
+               airo_print_dbg("", "Found an MPI350 card");
                set_bit(FLAG_MPI, &ai->flags);
        }
        spin_lock_init(&ai->aux_lock);
@@ -2821,14 +2778,11 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
        ai->config.len = 0;
        ai->pci = pci;
        init_waitqueue_head (&ai->thr_wait);
-       ai->airo_thread_task = kthread_run(airo_thread, dev, dev->name);
-       if (IS_ERR(ai->airo_thread_task))
-               goto err_out_free;
        ai->tfm = NULL;
        add_airo_dev(ai);
 
        if (airo_networks_allocate (ai))
-               goto err_out_thr;
+               goto err_out_free;
        airo_networks_initialize (ai);
 
        /* The Airo-specific entries in the device structure. */
@@ -2855,23 +2809,17 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
        reset_card (dev, 1);
        msleep(400);
 
-       rc = request_irq( dev->irq, airo_interrupt, IRQF_SHARED, dev->name, dev );
-       if (rc) {
-               airo_print_err(dev->name, "register interrupt %d failed, rc %d",
-                               irq, rc);
-               goto err_out_nets;
-       }
        if (!is_pcmcia) {
-               if (!request_region( dev->base_addr, 64, dev->name )) {
+               if (!request_region(dev->base_addr, 64, DRV_NAME)) {
                        rc = -EBUSY;
                        airo_print_err(dev->name, "Couldn't request region");
-                       goto err_out_irq;
+                       goto err_out_nets;
                }
        }
 
        if (test_bit(FLAG_MPI,&ai->flags)) {
-               if (mpi_map_card(ai, pci, dev->name)) {
-                       airo_print_err(dev->name, "Could not map memory");
+               if (mpi_map_card(ai, pci)) {
+                       airo_print_err("", "Could not map memory");
                        goto err_out_res;
                }
        }
@@ -2899,6 +2847,7 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
                ai->bssListRidLen = sizeof(BSSListRid) - sizeof(BSSListRidExtra);
        }
 
+       strcpy(dev->name, "eth%d");
        rc = register_netdev(dev);
        if (rc) {
                airo_print_err(dev->name, "Couldn't register_netdev");
@@ -2909,9 +2858,8 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
                goto err_out_reg;
 
        set_bit(FLAG_REGISTERED,&ai->flags);
-       airo_print_info(dev->name, "MAC enabled %x:%x:%x:%x:%x:%x",
-               dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
-               dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] );
+       airo_print_info(dev->name, "MAC enabled %s",
+                       print_mac(mac, dev->dev_addr));
 
        /* Allocate the transmit buffers */
        if (probe && !test_bit(FLAG_MPI,&ai->flags))
@@ -2921,8 +2869,6 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
        if (setup_proc_entry(dev, dev->priv) < 0)
                goto err_out_wifi;
 
-       netif_start_queue(dev);
-       SET_MODULE_OWNER(dev);
        return dev;
 
 err_out_wifi:
@@ -2940,14 +2886,9 @@ err_out_map:
 err_out_res:
        if (!is_pcmcia)
                release_region( dev->base_addr, 64 );
-err_out_irq:
-       free_irq(dev->irq, dev);
 err_out_nets:
        airo_networks_free(ai);
-err_out_thr:
        del_airo_dev(ai);
-       set_bit(JOB_DIE, &ai->jobs);
-       kthread_stop(ai->airo_thread_task);
 err_out_free:
        free_netdev(dev);
        return NULL;
@@ -2975,6 +2916,7 @@ int reset_airo_card( struct net_device *dev )
 {
        int i;
        struct airo_info *ai = dev->priv;
+       DECLARE_MAC_BUF(mac);
 
        if (reset_card (dev, 1))
                return -1;
@@ -2983,9 +2925,8 @@ int reset_airo_card( struct net_device *dev )
                airo_print_err(dev->name, "MAC could not be enabled");
                return -1;
        }
-       airo_print_info(dev->name, "MAC enabled %x:%x:%x:%x:%x:%x",
-                       dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
-                       dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
+       airo_print_info(dev->name, "MAC enabled %s",
+                       print_mac(mac, dev->dev_addr));
        /* Allocate the transmit buffers if needed */
        if (!test_bit(FLAG_MPI,&ai->flags))
                for( i = 0; i < MAX_FIDS; i++ )
@@ -3031,14 +2972,14 @@ static void airo_process_scan_results (struct airo_info *ai) {
 
        /* Try to read the first entry of the scan result */
        rc = PC4500_readrid(ai, ai->bssListFirst, &bss, ai->bssListRidLen, 0);
-       if((rc) || (bss.index == 0xffff)) {
+       if((rc) || (bss.index == cpu_to_le16(0xffff))) {
                /* No scan results */
                goto out;
        }
 
        /* Read and parse all entries */
        tmp_net = NULL;
-       while((!rc) && (bss.index != 0xffff)) {
+       while((!rc) && (bss.index != cpu_to_le16(0xffff))) {
                /* Grab a network off the free list */
                if (!list_empty(&ai->network_free_list)) {
                        tmp_net = list_entry(ai->network_free_list.next,
@@ -3078,7 +3019,8 @@ static int airo_thread(void *data) {
        struct net_device *dev = data;
        struct airo_info *ai = dev->priv;
        int locked;
-       
+
+       set_freezable();
        while(1) {
                /* make swsusp happy with our thread */
                try_to_freeze();
@@ -3170,8 +3112,24 @@ static int airo_thread(void *data) {
        return 0;
 }
 
-static irqreturn_t airo_interrupt ( int irq, void* dev_id) {
-       struct net_device *dev = (struct net_device *)dev_id;
+static int header_len(__le16 ctl)
+{
+       u16 fc = le16_to_cpu(ctl);
+       switch (fc & 0xc) {
+       case 4:
+               if ((fc & 0xe0) == 0xc0)
+                       return 10;      /* one-address control packet */
+               return 16;      /* two-address control packet */
+       case 8:
+               if ((fc & 0x300) == 0x300)
+                       return 30;      /* WDS packet */
+       }
+       return 24;
+}
+
+static irqreturn_t airo_interrupt(int irq, void *dev_id)
+{
+       struct net_device *dev = dev_id;
        u16 status;
        u16 fid;
        struct airo_info *apriv = dev->priv;
@@ -3274,19 +3232,20 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id) {
                /* Check to see if there is something to receive */
                if ( status & EV_RX  ) {
                        struct sk_buff *skb = NULL;
-                       u16 fc, len, hdrlen = 0;
+                       __le16 fc, v;
+                       u16 len, hdrlen = 0;
 #pragma pack(1)
                        struct {
-                               u16 status, len;
+                               __le16 status, len;
                                u8 rssi[2];
                                u8 rate;
                                u8 freq;
-                               u16 tmp[4];
+                               __le16 tmp[4];
                        } hdr;
 #pragma pack()
                        u16 gap;
-                       u16 tmpbuf[4];
-                       u16 *buffer;
+                       __le16 tmpbuf[4];
+                       __le16 *buffer;
 
                        if (test_bit(FLAG_MPI,&apriv->flags)) {
                                if (test_bit(FLAG_802_11, &apriv->flags))
@@ -3302,7 +3261,7 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id) {
                        /* Get the packet length */
                        if (test_bit(FLAG_802_11, &apriv->flags)) {
                                bap_setup (apriv, fid, 4, BAP0);
-                               bap_read (apriv, (u16*)&hdr, sizeof(hdr), BAP0);
+                               bap_read (apriv, (__le16*)&hdr, sizeof(hdr), BAP0);
                                /* Bad CRC. Ignore packet */
                                if (le16_to_cpu(hdr.status) & 2)
                                        hdr.len = 0;
@@ -3310,7 +3269,7 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id) {
                                        hdr.len = 0;
                        } else {
                                bap_setup (apriv, fid, 0x36, BAP0);
-                               bap_read (apriv, (u16*)&hdr.len, 2, BAP0);
+                               bap_read (apriv, &hdr.len, 2, BAP0);
                        }
                        len = le16_to_cpu(hdr.len);
 
@@ -3322,23 +3281,8 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id) {
                                goto badrx;
 
                        if (test_bit(FLAG_802_11, &apriv->flags)) {
-                               bap_read (apriv, (u16*)&fc, sizeof(fc), BAP0);
-                               fc = le16_to_cpu(fc);
-                               switch (fc & 0xc) {
-                                       case 4:
-                                               if ((fc & 0xe0) == 0xc0)
-                                                       hdrlen = 10;
-                                               else
-                                                       hdrlen = 16;
-                                               break;
-                                       case 8:
-                                               if ((fc&0x300)==0x300){
-                                                       hdrlen = 30;
-                                                       break;
-                                               }
-                                       default:
-                                               hdrlen = 24;
-                               }
+                               bap_read (apriv, &fc, sizeof(fc), BAP0);
+                               hdrlen = header_len(fc);
                        } else
                                hdrlen = ETH_ALEN * 2;
 
@@ -3348,15 +3292,15 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id) {
                                goto badrx;
                        }
                        skb_reserve(skb, 2); /* This way the IP header is aligned */
-                       buffer = (u16*)skb_put (skb, len + hdrlen);
+                       buffer = (__le16*)skb_put (skb, len + hdrlen);
                        if (test_bit(FLAG_802_11, &apriv->flags)) {
                                buffer[0] = fc;
                                bap_read (apriv, buffer + 1, hdrlen - 2, BAP0);
                                if (hdrlen == 24)
                                        bap_read (apriv, tmpbuf, 6, BAP0);
 
-                               bap_read (apriv, &gap, sizeof(gap), BAP0);
-                               gap = le16_to_cpu(gap);
+                               bap_read (apriv, &v, sizeof(v), BAP0);
+                               gap = le16_to_cpu(v);
                                if (gap) {
                                        if (gap <= 8) {
                                                bap_read (apriv, tmpbuf, gap, BAP0);
@@ -3370,7 +3314,7 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id) {
                                MICBuffer micbuf;
                                bap_read (apriv, buffer, ETH_ALEN*2, BAP0);
                                if (apriv->micstats.enabled) {
-                                       bap_read (apriv,(u16*)&micbuf,sizeof(micbuf),BAP0);
+                                       bap_read (apriv,(__le16*)&micbuf,sizeof(micbuf),BAP0);
                                        if (ntohs(micbuf.typelen) > 0x05DC)
                                                bap_setup (apriv, fid, 0x44, BAP0);
                                        else {
@@ -3398,7 +3342,7 @@ badrx:
                                if (!test_bit(FLAG_802_11, &apriv->flags)) {
                                        sa = (char*)buffer + 6;
                                        bap_setup (apriv, fid, 8, BAP0);
-                                       bap_read (apriv, (u16*)hdr.rssi, 2, BAP0);
+                                       bap_read (apriv, (__le16*)hdr.rssi, 2, BAP0);
                                } else
                                        sa = (char*)buffer + 10;
                                wstats.qual = hdr.rssi[0];
@@ -3529,9 +3473,11 @@ static u16 IN4500( struct airo_info *ai, u16 reg ) {
        return rc;
 }
 
-static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ) {
+static int enable_MAC(struct airo_info *ai, int lock)
+{
        int rc;
-        Cmd cmd;
+       Cmd cmd;
+       Resp rsp;
 
        /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions
         * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down"
@@ -3547,7 +3493,7 @@ static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ) {
        if (!test_bit(FLAG_ENABLED, &ai->flags)) {
                memset(&cmd, 0, sizeof(cmd));
                cmd.cmd = MAC_ENABLE;
-               rc = issuecommand(ai, &cmd, rsp);
+               rc = issuecommand(ai, &cmd, &rsp);
                if (rc == SUCCESS)
                        set_bit(FLAG_ENABLED, &ai->flags);
        } else
@@ -3557,8 +3503,12 @@ static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ) {
            up(&ai->sem);
 
        if (rc)
-               airo_print_err(ai->dev->name, "%s: Cannot enable MAC, err=%d",
-                       __FUNCTION__, rc);
+               airo_print_err(ai->dev->name, "Cannot enable MAC");
+       else if ((rsp.status & 0xFF00) != 0) {
+               airo_print_err(ai->dev->name, "Bad MAC enable reason=%x, "
+                       "rid=%x, offset=%d", rsp.rsp0, rsp.rsp1, rsp.rsp2);
+               rc = ERROR;
+       }
        return rc;
 }
 
@@ -3663,14 +3613,15 @@ void mpi_receive_802_11 (struct airo_info *ai)
 {
        RxFid rxd;
        struct sk_buff *skb = NULL;
-       u16 fc, len, hdrlen = 0;
+       u16 len, hdrlen = 0;
+       __le16 fc;
 #pragma pack(1)
        struct {
-               u16 status, len;
+               __le16 status, len;
                u8 rssi[2];
                u8 rate;
                u8 freq;
-               u16 tmp[4];
+               __le16 tmp[4];
        } hdr;
 #pragma pack()
        u16 gap;
@@ -3693,23 +3644,8 @@ void mpi_receive_802_11 (struct airo_info *ai)
        if (len == 0)
                goto badrx;
 
-       memcpy ((char *)&fc, ptr, sizeof(fc));
-       fc = le16_to_cpu(fc);
-       switch (fc & 0xc) {
-               case 4:
-                       if ((fc & 0xe0) == 0xc0)
-                               hdrlen = 10;
-                       else
-                               hdrlen = 16;
-                       break;
-               case 8:
-                       if ((fc&0x300)==0x300){
-                               hdrlen = 30;
-                               break;
-                       }
-               default:
-                       hdrlen = 24;
-       }
+       fc = get_unaligned((__le16 *)ptr);
+       hdrlen = header_len(fc);
 
        skb = dev_alloc_skb( len + hdrlen + 2 );
        if ( !skb ) {
@@ -3721,9 +3657,8 @@ void mpi_receive_802_11 (struct airo_info *ai)
        ptr += hdrlen;
        if (hdrlen == 24)
                ptr += 6;
-       memcpy ((char *)&gap, ptr, sizeof(gap));
-       ptr += sizeof(gap);
-       gap = le16_to_cpu(gap);
+       gap = le16_to_cpu(get_unaligned((__le16 *)ptr));
+       ptr += sizeof(__le16);
        if (gap) {
                if (gap <= 8)
                        ptr += gap;
@@ -3775,7 +3710,7 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
        int status;
        int i;
        SsidRid mySsid;
-       u16 lastindex;
+       __le16 lastindex;
        WepKeyRid wkr;
        int rc;
 
@@ -3837,7 +3772,7 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
                else {
                        kfree(ai->rssi);
                        ai->rssi = NULL;
-                       if (cap_rid.softCap & 8)
+                       if (cap_rid.softCap & cpu_to_le16(8))
                                ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
                        else
                                airo_print_warn(ai->dev->name, "unknown received signal "
@@ -3847,8 +3782,9 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
                ai->config.authType = AUTH_OPEN;
                ai->config.modulation = MOD_CCK;
 
-               if ((cap_rid.len>=sizeof(cap_rid)) && (cap_rid.extSoftCap&1) &&
-                   (micsetup(ai) == SUCCESS)) {
+               if (le16_to_cpu(cap_rid.len) >= sizeof(cap_rid) &&
+                   (cap_rid.extSoftCap & cpu_to_le16(1)) &&
+                   micsetup(ai) == SUCCESS) {
                        ai->config.opmode |= MODE_MIC;
                        set_bit(FLAG_MIC_CAPABLE, &ai->flags);
                }
@@ -3884,13 +3820,13 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
        if ( ssids[0] ) {
                int i;
                for( i = 0; i < 3 && ssids[i]; i++ ) {
-                       mySsid.ssids[i].len = strlen(ssids[i]);
-                       if ( mySsid.ssids[i].len > 32 )
-                               mySsid.ssids[i].len = 32;
-                       memcpy(mySsid.ssids[i].ssid, ssids[i],
-                              mySsid.ssids[i].len);
+                       size_t len = strlen(ssids[i]);
+                       if (len > 32)
+                               len = 32;
+                       mySsid.ssids[i].len = cpu_to_le16(len);
+                       memcpy(mySsid.ssids[i].ssid, ssids[i], len);
                }
-               mySsid.len = sizeof(mySsid);
+               mySsid.len = cpu_to_le16(sizeof(mySsid));
        }
 
        status = writeConfigRid(ai, lock);
@@ -3902,27 +3838,21 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
                if ( status != SUCCESS ) return ERROR;
        }
 
-       status = enable_MAC(ai, &rsp, lock);
-       if ( status != SUCCESS || (rsp.status & 0xFF00) != 0) {
-               airo_print_err(ai->dev->name, "Bad MAC enable reason = %x, rid = %x,"
-                       " offset = %d", rsp.rsp0, rsp.rsp1, rsp.rsp2 );
+       status = enable_MAC(ai, lock);
+       if (status != SUCCESS)
                return ERROR;
-       }
 
        /* Grab the initial wep key, we gotta save it for auto_wep */
        rc = readWepKeyRid(ai, &wkr, 1, lock);
        if (rc == SUCCESS) do {
                lastindex = wkr.kindex;
-               if (wkr.kindex == 0xffff) {
+               if (wkr.kindex == cpu_to_le16(0xffff)) {
                        ai->defindex = wkr.mac[0];
                }
                rc = readWepKeyRid(ai, &wkr, 0, lock);
        } while(lastindex != wkr.kindex);
 
-       if (auto_wep) {
-               ai->expires = RUN_AT(3*HZ);
-               wake_up_interruptible(&ai->thr_wait);
-       }
+       try_auto_wep(ai);
 
        return SUCCESS;
 }
@@ -4004,7 +3934,7 @@ static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
                }
                if ( !(max_tries--) ) {
                        airo_print_err(ai->dev->name,
-                               "airo: BAP setup error too many retries\n");
+                               "BAP setup error too many retries\n");
                        return ERROR;
                }
                // -- PC4500 missed it, try again
@@ -4031,7 +3961,7 @@ static u16 aux_setup(struct airo_info *ai, u16 page,
 }
 
 /* requires call to bap_setup() first */
-static int aux_bap_read(struct airo_info *ai, u16 *pu16Dst,
+static int aux_bap_read(struct airo_info *ai, __le16 *pu16Dst,
                        int bytelen, int whichbap)
 {
        u16 len;
@@ -4068,7 +3998,7 @@ static int aux_bap_read(struct airo_info *ai, u16 *pu16Dst,
 
 
 /* requires call to bap_setup() first */
-static int fast_bap_read(struct airo_info *ai, u16 *pu16Dst,
+static int fast_bap_read(struct airo_info *ai, __le16 *pu16Dst,
                         int bytelen, int whichbap)
 {
        bytelen = (bytelen + 1) & (~1); // round up to even value
@@ -4080,7 +4010,7 @@ static int fast_bap_read(struct airo_info *ai, u16 *pu16Dst,
 }
 
 /* requires call to bap_setup() first */
-static int bap_write(struct airo_info *ai, const u16 *pu16Src,
+static int bap_write(struct airo_info *ai, const __le16 *pu16Src,
                     int bytelen, int whichbap)
 {
        bytelen = (bytelen + 1) & (~1); // round up to even value
@@ -4156,7 +4086,7 @@ static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, in
                // read the rid length field
                bap_read(ai, pBuf, 2, BAP1);
                // length for remaining part of rid
-               len = min(len, (int)le16_to_cpu(*(u16*)pBuf)) - 2;
+               len = min(len, (int)le16_to_cpu(*(__le16*)pBuf)) - 2;
 
                if ( len <= 2 ) {
                        airo_print_err(ai->dev->name,
@@ -4166,7 +4096,7 @@ static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, in
                        goto done;
                }
                // read remainder of the rid
-               rc = bap_read(ai, ((u16*)pBuf)+1, len, BAP1);
+               rc = bap_read(ai, ((__le16*)pBuf)+1, len, BAP1);
        }
 done:
        if (lock)
@@ -4182,7 +4112,7 @@ static int PC4500_writerid(struct airo_info *ai, u16 rid,
        u16 status;
        int rc = SUCCESS;
 
-       *(u16*)pBuf = cpu_to_le16((u16)len);
+       *(__le16*)pBuf = cpu_to_le16((u16)len);
 
        if (lock) {
                if (down_interruptible(&ai->sem))
@@ -4256,7 +4186,7 @@ static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
        Cmd cmd;
        Resp rsp;
        u16 txFid;
-       u16 txControl;
+       __le16 txControl;
 
        cmd.cmd = CMD_ALLOCATETX;
        cmd.parm0 = lenPayload;
@@ -4310,7 +4240,7 @@ done:
    Make sure the BAP1 spinlock is held when this is called. */
 static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
 {
-       u16 payloadLen;
+       __le16 payloadLen;
        Cmd cmd;
        Resp rsp;
        int miclen = 0;
@@ -4326,7 +4256,7 @@ static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
        len -= ETH_ALEN * 2;
 
        if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled && 
-           (ntohs(((u16 *)pPacket)[6]) != 0x888E)) {
+           (ntohs(((__be16 *)pPacket)[6]) != 0x888E)) {
                if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
                        return ERROR;
                miclen = sizeof(pMic);
@@ -4338,10 +4268,10 @@ static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
         * we have to subtract the 12 bytes for the addresses off */
        payloadLen = cpu_to_le16(len + miclen);
        bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
-       bap_write(ai, (const u16*)pPacket, sizeof(etherHead), BAP1);
+       bap_write(ai, (__le16*)pPacket, sizeof(etherHead), BAP1);
        if (miclen)
-               bap_write(ai, (const u16*)&pMic, miclen, BAP1);
-       bap_write(ai, (const u16*)(pPacket + sizeof(etherHead)), len, BAP1);
+               bap_write(ai, (__le16*)&pMic, miclen, BAP1);
+       bap_write(ai, (__le16*)(pPacket + sizeof(etherHead)), len, BAP1);
        // issue the transmit command
        memset( &cmd, 0, sizeof( cmd ) );
        cmd.cmd = CMD_TRANSMIT;
@@ -4353,35 +4283,17 @@ static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
 
 static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
 {
-       u16 fc, payloadLen;
+       __le16 fc, payloadLen;
        Cmd cmd;
        Resp rsp;
        int hdrlen;
-       struct {
-               u8 addr4[ETH_ALEN];
-               u16 gaplen;
-               u8 gap[6];
-       } gap;
+       static u8 tail[(30-10) + 2 + 6] = {[30-10] = 6};
+       /* padding of header to full size + le16 gaplen (6) + gaplen bytes */
        u16 txFid = len;
        len >>= 16;
-       gap.gaplen = 6;
 
-       fc = le16_to_cpu(*(const u16*)pPacket);
-       switch (fc & 0xc) {
-               case 4:
-                       if ((fc & 0xe0) == 0xc0)
-                               hdrlen = 10;
-                       else
-                               hdrlen = 16;
-                       break;
-               case 8:
-                       if ((fc&0x300)==0x300){
-                               hdrlen = 30;
-                               break;
-                       }
-               default:
-                       hdrlen = 24;
-       }
+       fc = *(__le16*)pPacket;
+       hdrlen = header_len(fc);
 
        if (len < hdrlen) {
                airo_print_warn(ai->dev->name, "Short packet %d", len);
@@ -4396,11 +4308,10 @@ static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
        payloadLen = cpu_to_le16(len-hdrlen);
        bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
        if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
-       bap_write(ai, (const u16*)pPacket, hdrlen, BAP1);
-       bap_write(ai, hdrlen == 30 ?
-               (const u16*)&gap.gaplen : (const u16*)&gap, 38 - hdrlen, BAP1);
+       bap_write(ai, (__le16 *)pPacket, hdrlen, BAP1);
+       bap_write(ai, (__le16 *)(tail + (hdrlen - 10)), 38 - hdrlen, BAP1);
 
-       bap_write(ai, (const u16*)(pPacket + hdrlen), len - hdrlen, BAP1);
+       bap_write(ai, (__le16 *)(pPacket + hdrlen), len - hdrlen, BAP1);
        // issue the transmit command
        memset( &cmd, 0, sizeof( cmd ) );
        cmd.cmd = CMD_TRANSMIT;
@@ -4715,13 +4626,15 @@ static ssize_t proc_write( struct file *file,
        return len;
 }
 
-static int proc_status_open( struct inode *inode, struct file *file ) {
+static int proc_status_open(struct inode *inode, struct file *file)
+{
        struct proc_data *data;
        struct proc_dir_entry *dp = PDE(inode);
        struct net_device *dev = dp->data;
        struct airo_info *apriv = dev->priv;
        CapabilityRid cap_rid;
        StatusRid status_rid;
+       u16 mode;
        int i;
 
        if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
@@ -4735,16 +4648,18 @@ static int proc_status_open( struct inode *inode, struct file *file ) {
        readStatusRid(apriv, &status_rid, 1);
        readCapabilityRid(apriv, &cap_rid, 1);
 
+       mode = le16_to_cpu(status_rid.mode);
+
         i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n",
-                    status_rid.mode & 1 ? "CFG ": "",
-                    status_rid.mode & 2 ? "ACT ": "",
-                    status_rid.mode & 0x10 ? "SYN ": "",
-                    status_rid.mode & 0x20 ? "LNK ": "",
-                    status_rid.mode & 0x40 ? "LEAP ": "",
-                    status_rid.mode & 0x80 ? "PRIV ": "",
-                    status_rid.mode & 0x100 ? "KEY ": "",
-                    status_rid.mode & 0x200 ? "WEP ": "",
-                    status_rid.mode & 0x8000 ? "ERR ": "");
+                    mode & 1 ? "CFG ": "",
+                    mode & 2 ? "ACT ": "",
+                    mode & 0x10 ? "SYN ": "",
+                    mode & 0x20 ? "LNK ": "",
+                    mode & 0x40 ? "LEAP ": "",
+                    mode & 0x80 ? "PRIV ": "",
+                    mode & 0x100 ? "KEY ": "",
+                    mode & 0x200 ? "WEP ": "",
+                    mode & 0x8000 ? "ERR ": "");
        sprintf( data->rbuffer+i, "Mode: %x\n"
                 "Signal Strength: %d\n"
                 "Signal Quality: %d\n"
@@ -4757,24 +4672,24 @@ static int proc_status_open( struct inode *inode, struct file *file ) {
                 "Radio type: %x\nCountry: %x\nHardware Version: %x\n"
                 "Software Version: %x\nSoftware Subversion: %x\n"
                 "Boot block version: %x\n",
-                (int)status_rid.mode,
-                (int)status_rid.normalizedSignalStrength,
-                (int)status_rid.signalQuality,
-                (int)status_rid.SSIDlen,
+                le16_to_cpu(status_rid.mode),
+                le16_to_cpu(status_rid.normalizedSignalStrength),
+                le16_to_cpu(status_rid.signalQuality),
+                le16_to_cpu(status_rid.SSIDlen),
                 status_rid.SSID,
                 status_rid.apName,
-                (int)status_rid.channel,
-                (int)status_rid.currentXmitRate/2,
+                le16_to_cpu(status_rid.channel),
+                le16_to_cpu(status_rid.currentXmitRate) / 2,
                 version,
                 cap_rid.prodName,
                 cap_rid.manName,
                 cap_rid.prodVer,
-                cap_rid.radioType,
-                cap_rid.country,
-                cap_rid.hardVer,
-                (int)cap_rid.softVer,
-                (int)cap_rid.softSubVer,
-                (int)cap_rid.bootBlockVer );
+                le16_to_cpu(cap_rid.radioType),
+                le16_to_cpu(cap_rid.country),
+                le16_to_cpu(cap_rid.hardVer),
+                le16_to_cpu(cap_rid.softVer),
+                le16_to_cpu(cap_rid.softSubVer),
+                le16_to_cpu(cap_rid.bootBlockVer));
        data->readlen = strlen( data->rbuffer );
        return 0;
 }
@@ -4794,14 +4709,16 @@ static int proc_stats_open( struct inode *inode, struct file *file ) {
 
 static int proc_stats_rid_open( struct inode *inode,
                                struct file *file,
-                               u16 rid ) {
+                               u16 rid )
+{
        struct proc_data *data;
        struct proc_dir_entry *dp = PDE(inode);
        struct net_device *dev = dp->data;
        struct airo_info *apriv = dev->priv;
        StatsRid stats;
        int i, j;
-       u32 *vals = stats.vals;
+       __le32 *vals = stats.vals;
+       int len = le16_to_cpu(stats.len);
 
        if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
                return -ENOMEM;
@@ -4814,17 +4731,17 @@ static int proc_stats_rid_open( struct inode *inode,
        readStatsRid(apriv, &stats, rid, 1);
 
         j = 0;
-       for(i=0; statsLabels[i]!=(char *)-1 &&
-                   i*4<stats.len; i++){
+       for(i=0; statsLabels[i]!=(char *)-1 && i*4<len; i++) {
                if (!statsLabels[i]) continue;
                if (j+strlen(statsLabels[i])+16>4096) {
                        airo_print_warn(apriv->dev->name,
                               "Potentially disasterous buffer overflow averted!");
                        break;
                }
-               j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i], vals[i]);
+               j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i],
+                               le32_to_cpu(vals[i]));
        }
-       if (i*4>=stats.len){
+       if (i*4 >= len) {
                airo_print_warn(apriv->dev->name, "Got a short rid");
        }
        data->readlen = j;
@@ -4849,7 +4766,14 @@ static int airo_config_commit(struct net_device *dev,
                              struct iw_request_info *info, void *zwrq,
                              char *extra);
 
-static void proc_config_on_close( struct inode *inode, struct file *file ) {
+static inline int sniffing_mode(struct airo_info *ai)
+{
+       return le16_to_cpu(ai->config.rmode & RXMODE_MASK) >=
+               le16_to_cpu(RXMODE_RFMON);
+}
+
+static void proc_config_on_close(struct inode *inode, struct file *file)
+{
        struct proc_data *data = file->private_data;
        struct proc_dir_entry *dp = PDE(inode);
        struct net_device *dev = dp->data;
@@ -4866,16 +4790,16 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
 /*** Mode processing */
                if ( !strncmp( line, "Mode: ", 6 ) ) {
                        line += 6;
-                       if ((ai->config.rmode & 0xff) >= RXMODE_RFMON)
-                                       set_bit (FLAG_RESET, &ai->flags);
-                       ai->config.rmode &= 0xfe00;
+                       if (sniffing_mode(ai))
+                               set_bit (FLAG_RESET, &ai->flags);
+                       ai->config.rmode &= ~RXMODE_FULL_MASK;
                        clear_bit (FLAG_802_11, &ai->flags);
-                       ai->config.opmode &= 0xFF00;
+                       ai->config.opmode &= ~MODE_CFG_MASK;
                        ai->config.scanMode = SCANMODE_ACTIVE;
                        if ( line[0] == 'a' ) {
-                               ai->config.opmode |= 0;
+                               ai->config.opmode |= MODE_STA_IBSS;
                        } else {
-                               ai->config.opmode |= 1;
+                               ai->config.opmode |= MODE_STA_ESS;
                                if ( line[0] == 'r' ) {
                                        ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
                                        ai->config.scanMode = SCANMODE_PASSIVE;
@@ -4941,7 +4865,7 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
                        line += 9;
                        v = get_dec_u16(line, &i, i+3);
                        if ( v != -1 ) {
-                               ai->config.channelSet = (u16)v;
+                               ai->config.channelSet = cpu_to_le16(v);
                                set_bit (FLAG_COMMIT, &ai->flags);
                        }
                } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
@@ -4949,20 +4873,20 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
                        line += 11;
                        v = get_dec_u16(line, &i, i+3);
                        if ( v != -1 ) {
-                               ai->config.txPower = (u16)v;
+                               ai->config.txPower = cpu_to_le16(v);
                                set_bit (FLAG_COMMIT, &ai->flags);
                        }
                } else if ( !strncmp( line, "WEP: ", 5 ) ) {
                        line += 5;
                        switch( line[0] ) {
                        case 's':
-                               ai->config.authType = (u16)AUTH_SHAREDKEY;
+                               ai->config.authType = AUTH_SHAREDKEY;
                                break;
                        case 'e':
-                               ai->config.authType = (u16)AUTH_ENCRYPT;
+                               ai->config.authType = AUTH_ENCRYPT;
                                break;
                        default:
-                               ai->config.authType = (u16)AUTH_OPEN;
+                               ai->config.authType = AUTH_OPEN;
                                break;
                        }
                        set_bit (FLAG_COMMIT, &ai->flags);
@@ -4972,7 +4896,7 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
                        line += 16;
                        v = get_dec_u16(line, &i, 3);
                        v = (v<0) ? 0 : ((v>255) ? 255 : v);
-                       ai->config.longRetryLimit = (u16)v;
+                       ai->config.longRetryLimit = cpu_to_le16(v);
                        set_bit (FLAG_COMMIT, &ai->flags);
                } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
                        int v, i = 0;
@@ -4980,7 +4904,7 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
                        line += 17;
                        v = get_dec_u16(line, &i, 3);
                        v = (v<0) ? 0 : ((v>255) ? 255 : v);
-                       ai->config.shortRetryLimit = (u16)v;
+                       ai->config.shortRetryLimit = cpu_to_le16(v);
                        set_bit (FLAG_COMMIT, &ai->flags);
                } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
                        int v, i = 0;
@@ -4988,7 +4912,7 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
                        line += 14;
                        v = get_dec_u16(line, &i, 4);
                        v = (v<0) ? 0 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
-                       ai->config.rtsThres = (u16)v;
+                       ai->config.rtsThres = cpu_to_le16(v);
                        set_bit (FLAG_COMMIT, &ai->flags);
                } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
                        int v, i = 0;
@@ -4996,7 +4920,7 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
                        line += 16;
                        v = get_dec_u16(line, &i, 5);
                        v = (v<0) ? 0 : v;
-                       ai->config.txLifetime = (u16)v;
+                       ai->config.txLifetime = cpu_to_le16(v);
                        set_bit (FLAG_COMMIT, &ai->flags);
                } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
                        int v, i = 0;
@@ -5004,7 +4928,7 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
                        line += 16;
                        v = get_dec_u16(line, &i, 5);
                        v = (v<0) ? 0 : v;
-                       ai->config.rxLifetime = (u16)v;
+                       ai->config.rxLifetime = cpu_to_le16(v);
                        set_bit (FLAG_COMMIT, &ai->flags);
                } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
                        ai->config.txDiversity =
@@ -5023,7 +4947,7 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
                        v = get_dec_u16(line, &i, 4);
                        v = (v<256) ? 256 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
                        v = v & 0xfffe; /* Make sure its even */
-                       ai->config.fragThresh = (u16)v;
+                       ai->config.fragThresh = cpu_to_le16(v);
                        set_bit (FLAG_COMMIT, &ai->flags);
                } else if (!strncmp(line, "Modulation: ", 12)) {
                        line += 12;
@@ -5050,8 +4974,9 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
        airo_config_commit(dev, NULL, NULL, NULL);
 }
 
-static char *get_rmode(u16 mode) {
-        switch(mode&0xff) {
+static char *get_rmode(__le16 mode)
+{
+        switch(mode & RXMODE_MASK) {
         case RXMODE_RFMON:  return "rfmon";
         case RXMODE_RFMON_ANYBSS:  return "yna (any) bss rfmon";
         case RXMODE_LANMON:  return "lanmon";
@@ -5059,12 +4984,14 @@ static char *get_rmode(u16 mode) {
         return "ESS";
 }
 
-static int proc_config_open( struct inode *inode, struct file *file ) {
+static int proc_config_open(struct inode *inode, struct file *file)
+{
        struct proc_data *data;
        struct proc_dir_entry *dp = PDE(inode);
        struct net_device *dev = dp->data;
        struct airo_info *ai = dev->priv;
        int i;
+       __le16 mode;
 
        if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
                return -ENOMEM;
@@ -5083,6 +5010,7 @@ static int proc_config_open( struct inode *inode, struct file *file ) {
 
        readConfigRid(ai, 1);
 
+       mode = ai->config.opmode & MODE_CFG_MASK;
        i = sprintf( data->rbuffer,
                     "Mode: %s\n"
                     "Radio: %s\n"
@@ -5091,15 +5019,16 @@ static int proc_config_open( struct inode *inode, struct file *file ) {
                     "DataRates: %d %d %d %d %d %d %d %d\n"
                     "Channel: %d\n"
                     "XmitPower: %d\n",
-                    (ai->config.opmode & 0xFF) == 0 ? "adhoc" :
-                    (ai->config.opmode & 0xFF) == 1 ? get_rmode(ai->config.rmode):
-                    (ai->config.opmode & 0xFF) == 2 ? "AP" :
-                    (ai->config.opmode & 0xFF) == 3 ? "AP RPTR" : "Error",
+                    mode == MODE_STA_IBSS ? "adhoc" :
+                    mode == MODE_STA_ESS ? get_rmode(ai->config.rmode):
+                    mode == MODE_AP ? "AP" :
+                    mode == MODE_AP_RPTR ? "AP RPTR" : "Error",
                     test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on",
                     ai->config.nodeName,
-                    ai->config.powerSaveMode == 0 ? "CAM" :
-                    ai->config.powerSaveMode == 1 ? "PSP" :
-                    ai->config.powerSaveMode == 2 ? "PSPCAM" : "Error",
+                    ai->config.powerSaveMode == POWERSAVE_CAM ? "CAM" :
+                    ai->config.powerSaveMode == POWERSAVE_PSP ? "PSP" :
+                    ai->config.powerSaveMode == POWERSAVE_PSPCAM ? "PSPCAM" :
+                    "Error",
                     (int)ai->config.rates[0],
                     (int)ai->config.rates[1],
                     (int)ai->config.rates[2],
@@ -5108,8 +5037,8 @@ static int proc_config_open( struct inode *inode, struct file *file ) {
                     (int)ai->config.rates[5],
                     (int)ai->config.rates[6],
                     (int)ai->config.rates[7],
-                    (int)ai->config.channelSet,
-                    (int)ai->config.txPower
+                    le16_to_cpu(ai->config.channelSet),
+                    le16_to_cpu(ai->config.txPower)
                );
        sprintf( data->rbuffer + i,
                 "LongRetryLimit: %d\n"
@@ -5123,19 +5052,19 @@ static int proc_config_open( struct inode *inode, struct file *file ) {
                 "WEP: %s\n"
                 "Modulation: %s\n"
                 "Preamble: %s\n",
-                (int)ai->config.longRetryLimit,
-                (int)ai->config.shortRetryLimit,
-                (int)ai->config.rtsThres,
-                (int)ai->config.txLifetime,
-                (int)ai->config.rxLifetime,
+                le16_to_cpu(ai->config.longRetryLimit),
+                le16_to_cpu(ai->config.shortRetryLimit),
+                le16_to_cpu(ai->config.rtsThres),
+                le16_to_cpu(ai->config.txLifetime),
+                le16_to_cpu(ai->config.rxLifetime),
                 ai->config.txDiversity == 1 ? "left" :
                 ai->config.txDiversity == 2 ? "right" : "both",
                 ai->config.rxDiversity == 1 ? "left" :
                 ai->config.rxDiversity == 2 ? "right" : "both",
-                (int)ai->config.fragThresh,
+                le16_to_cpu(ai->config.fragThresh),
                 ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
                 ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
-                ai->config.modulation == 0 ? "default" :
+                ai->config.modulation == MOD_DEFAULT ? "default" :
                 ai->config.modulation == MOD_CCK ? "cck" :
                 ai->config.modulation == MOD_MOK ? "mok" : "error",
                 ai->config.preamble == PREAMBLE_AUTO ? "auto" :
@@ -5146,38 +5075,41 @@ static int proc_config_open( struct inode *inode, struct file *file ) {
        return 0;
 }
 
-static void proc_SSID_on_close( struct inode *inode, struct file *file ) {
+static void proc_SSID_on_close(struct inode *inode, struct file *file)
+{
        struct proc_data *data = (struct proc_data *)file->private_data;
        struct proc_dir_entry *dp = PDE(inode);
        struct net_device *dev = dp->data;
        struct airo_info *ai = dev->priv;
        SsidRid SSID_rid;
-       Resp rsp;
        int i;
-       int offset = 0;
+       char *p = data->wbuffer;
+       char *end = p + data->writelen;
 
-       if ( !data->writelen ) return;
+       if (!data->writelen)
+               return;
 
-       memset( &SSID_rid, 0, sizeof( SSID_rid ) );
+       *end = '\n'; /* sentinel; we have space for it */
 
-       for( i = 0; i < 3; i++ ) {
-               int j;
-               for( j = 0; j+offset < data->writelen && j < 32 &&
-                            data->wbuffer[offset+j] != '\n'; j++ ) {
-                       SSID_rid.ssids[i].ssid[j] = data->wbuffer[offset+j];
-               }
-               if ( j == 0 ) break;
-               SSID_rid.ssids[i].len = j;
-               offset += j;
-               while( data->wbuffer[offset] != '\n' &&
-                      offset < data->writelen ) offset++;
-               offset++;
+       memset(&SSID_rid, 0, sizeof(SSID_rid));
+
+       for (i = 0; i < 3 && p < end; i++) {
+               int j = 0;
+               /* copy up to 32 characters from this line */
+               while (*p != '\n' && j < 32)
+                       SSID_rid.ssids[i].ssid[j++] = *p++;
+               if (j == 0)
+                       break;
+               SSID_rid.ssids[i].len = cpu_to_le16(j);
+               /* skip to the beginning of the next line */
+               while (*p++ != '\n')
+                       ;
        }
        if (i)
-               SSID_rid.len = sizeof(SSID_rid);
+               SSID_rid.len = cpu_to_le16(sizeof(SSID_rid));
        disable_MAC(ai, 1);
        writeSsidRid(ai, &SSID_rid, 1);
-       enable_MAC(ai, &rsp, 1);
+       enable_MAC(ai, 1);
 }
 
 static inline u8 hexVal(char c) {
@@ -5193,13 +5125,12 @@ static void proc_APList_on_close( struct inode *inode, struct file *file ) {
        struct net_device *dev = dp->data;
        struct airo_info *ai = dev->priv;
        APListRid APList_rid;
-       Resp rsp;
        int i;
 
        if ( !data->writelen ) return;
 
        memset( &APList_rid, 0, sizeof(APList_rid) );
-       APList_rid.len = sizeof(APList_rid);
+       APList_rid.len = cpu_to_le16(sizeof(APList_rid));
 
        for( i = 0; i < 4 && data->writelen >= (i+1)*6*3; i++ ) {
                int j;
@@ -5218,18 +5149,17 @@ static void proc_APList_on_close( struct inode *inode, struct file *file ) {
        }
        disable_MAC(ai, 1);
        writeAPListRid(ai, &APList_rid, 1);
-       enable_MAC(ai, &rsp, 1);
+       enable_MAC(ai, 1);
 }
 
 /* This function wraps PC4500_writerid with a MAC disable */
 static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
                        int len, int dummy ) {
        int rc;
-       Resp rsp;
 
        disable_MAC(ai, 1);
        rc = PC4500_writerid(ai, rid, rid_data, len, 1);
-       enable_MAC(ai, &rsp, 1);
+       enable_MAC(ai, 1);
        return rc;
 }
 
@@ -5240,47 +5170,47 @@ static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
 static int get_wep_key(struct airo_info *ai, u16 index) {
        WepKeyRid wkr;
        int rc;
-       u16 lastindex;
+       __le16 lastindex;
 
        rc = readWepKeyRid(ai, &wkr, 1, 1);
        if (rc == SUCCESS) do {
                lastindex = wkr.kindex;
-               if (wkr.kindex == index) {
+               if (wkr.kindex == cpu_to_le16(index)) {
                        if (index == 0xffff) {
                                return wkr.mac[0];
                        }
-                       return wkr.klen;
+                       return le16_to_cpu(wkr.klen);
                }
                readWepKeyRid(ai, &wkr, 0, 1);
-       } while(lastindex != wkr.kindex);
+       } while (lastindex != wkr.kindex);
        return -1;
 }
 
 static int set_wep_key(struct airo_info *ai, u16 index,
-                      const char *key, u16 keylen, int perm, int lock ) {
+                      const char *key, u16 keylen, int perm, int lock )
+{
        static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
        WepKeyRid wkr;
-       Resp rsp;
 
        memset(&wkr, 0, sizeof(wkr));
        if (keylen == 0) {
 // We are selecting which key to use
-               wkr.len = sizeof(wkr);
-               wkr.kindex = 0xffff;
+               wkr.len = cpu_to_le16(sizeof(wkr));
+               wkr.kindex = cpu_to_le16(0xffff);
                wkr.mac[0] = (char)index;
                if (perm) ai->defindex = (char)index;
        } else {
 // We are actually setting the key
-               wkr.len = sizeof(wkr);
-               wkr.kindex = index;
-               wkr.klen = keylen;
+               wkr.len = cpu_to_le16(sizeof(wkr));
+               wkr.kindex = cpu_to_le16(index);
+               wkr.klen = cpu_to_le16(keylen);
                memcpy( wkr.key, key, keylen );
                memcpy( wkr.mac, macaddr, ETH_ALEN );
        }
 
        if (perm) disable_MAC(ai, lock);
        writeWepKeyRid(ai, &wkr, perm, lock);
-       if (perm) enable_MAC(ai, &rsp, lock);
+       if (perm) enable_MAC(ai, lock);
        return 0;
 }
 
@@ -5325,14 +5255,15 @@ static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
        set_wep_key(ai, index, key, i/3, 1, 1);
 }
 
-static int proc_wepkey_open( struct inode *inode, struct file *file ) {
+static int proc_wepkey_open( struct inode *inode, struct file *file )
+{
        struct proc_data *data;
        struct proc_dir_entry *dp = PDE(inode);
        struct net_device *dev = dp->data;
        struct airo_info *ai = dev->priv;
        char *ptr;
        WepKeyRid wkr;
-       u16 lastindex;
+       __le16 lastindex;
        int j=0;
        int rc;
 
@@ -5358,12 +5289,13 @@ static int proc_wepkey_open( struct inode *inode, struct file *file ) {
        rc = readWepKeyRid(ai, &wkr, 1, 1);
        if (rc == SUCCESS) do {
                lastindex = wkr.kindex;
-               if (wkr.kindex == 0xffff) {
+               if (wkr.kindex == cpu_to_le16(0xffff)) {
                        j += sprintf(ptr+j, "Tx key = %d\n",
                                     (int)wkr.mac[0]);
                } else {
                        j += sprintf(ptr+j, "Key %d set with length = %d\n",
-                                    (int)wkr.kindex, (int)wkr.klen);
+                                    le16_to_cpu(wkr.kindex),
+                                    le16_to_cpu(wkr.klen));
                }
                readWepKeyRid(ai, &wkr, 0, 1);
        } while((lastindex != wkr.kindex) && (j < 180-30));
@@ -5372,7 +5304,8 @@ static int proc_wepkey_open( struct inode *inode, struct file *file ) {
        return 0;
 }
 
-static int proc_SSID_open( struct inode *inode, struct file *file ) {
+static int proc_SSID_open(struct inode *inode, struct file *file)
+{
        struct proc_data *data;
        struct proc_dir_entry *dp = PDE(inode);
        struct net_device *dev = dp->data;
@@ -5390,7 +5323,8 @@ static int proc_SSID_open( struct inode *inode, struct file *file ) {
        }
        data->writelen = 0;
        data->maxwritelen = 33*3;
-       if ((data->wbuffer = kzalloc( 33*3, GFP_KERNEL )) == NULL) {
+       /* allocate maxwritelen + 1; we'll want a sentinel */
+       if ((data->wbuffer = kzalloc(33*3 + 1, GFP_KERNEL)) == NULL) {
                kfree (data->rbuffer);
                kfree (file->private_data);
                return -ENOMEM;
@@ -5399,14 +5333,15 @@ static int proc_SSID_open( struct inode *inode, struct file *file ) {
 
        readSsidRid(ai, &SSID_rid);
        ptr = data->rbuffer;
-       for( i = 0; i < 3; i++ ) {
+       for (i = 0; i < 3; i++) {
                int j;
-               if ( !SSID_rid.ssids[i].len ) break;
-               for( j = 0; j < 32 &&
-                            j < SSID_rid.ssids[i].len &&
-                            SSID_rid.ssids[i].ssid[j]; j++ ) {
+               size_t len = le16_to_cpu(SSID_rid.ssids[i].len);
+               if (!len)
+                       break;
+               if (len > 32)
+                       len = 32;
+               for (j = 0; j < len && SSID_rid.ssids[i].ssid[j]; j++)
                        *ptr++ = SSID_rid.ssids[i].ssid[j];
-               }
                *ptr++ = '\n';
        }
        *ptr = '\0';
@@ -5422,6 +5357,7 @@ static int proc_APList_open( struct inode *inode, struct file *file ) {
        int i;
        char *ptr;
        APListRid APList_rid;
+       DECLARE_MAC_BUF(mac);
 
        if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
                return -ENOMEM;
@@ -5445,13 +5381,8 @@ static int proc_APList_open( struct inode *inode, struct file *file ) {
 // We end when we find a zero MAC
                if ( !*(int*)APList_rid.ap[i] &&
                     !*(int*)&APList_rid.ap[i][2]) break;
-               ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x\n",
-                              (int)APList_rid.ap[i][0],
-                              (int)APList_rid.ap[i][1],
-                              (int)APList_rid.ap[i][2],
-                              (int)APList_rid.ap[i][3],
-                              (int)APList_rid.ap[i][4],
-                              (int)APList_rid.ap[i][5]);
+               ptr += sprintf(ptr, "%s\n",
+                              print_mac(mac, APList_rid.ap[i]));
        }
        if (i==0) ptr += sprintf(ptr, "Not using specific APs\n");
 
@@ -5470,6 +5401,7 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
        int rc;
        /* If doLoseSync is not 1, we won't do a Lose Sync */
        int doLoseSync = -1;
+       DECLARE_MAC_BUF(mac);
 
        if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
                return -ENOMEM;
@@ -5505,19 +5437,14 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
            Since it is a rare condition, we'll just live with it, otherwise
            we have to add a spin lock... */
        rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
-       while(rc == 0 && BSSList_rid.index != 0xffff) {
-               ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x %*s rssi = %d",
-                               (int)BSSList_rid.bssid[0],
-                               (int)BSSList_rid.bssid[1],
-                               (int)BSSList_rid.bssid[2],
-                               (int)BSSList_rid.bssid[3],
-                               (int)BSSList_rid.bssid[4],
-                               (int)BSSList_rid.bssid[5],
+       while(rc == 0 && BSSList_rid.index != cpu_to_le16(0xffff)) {
+               ptr += sprintf(ptr, "%s %*s rssi = %d",
+                              print_mac(mac, BSSList_rid.bssid),
                                (int)BSSList_rid.ssidLen,
                                BSSList_rid.ssid,
-                               (int)BSSList_rid.dBm);
+                               le16_to_cpu(BSSList_rid.dBm));
                ptr += sprintf(ptr, " channel = %d %s %s %s %s\n",
-                               (int)BSSList_rid.dsChannel,
+                               le16_to_cpu(BSSList_rid.dsChannel),
                                BSSList_rid.cap & CAP_ESS ? "ESS" : "",
                                BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
                                BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
@@ -5548,7 +5475,6 @@ static int proc_close( struct inode *inode, struct file *file )
    changed. */
 static void timer_func( struct net_device *dev ) {
        struct airo_info *apriv = dev->priv;
-       Resp rsp;
 
 /* We don't have a link so try changing the authtype */
        readConfigRid(apriv, 0);
@@ -5575,7 +5501,7 @@ static void timer_func( struct net_device *dev ) {
        }
        set_bit (FLAG_COMMIT, &apriv->flags);
        writeConfigRid(apriv, 0);
-       enable_MAC(apriv, &rsp, 0);
+       enable_MAC(apriv, 0);
        up(&apriv->sem);
 
 /* Schedule check to see if the change worked */
@@ -5597,8 +5523,10 @@ static int __devinit airo_pci_probe(struct pci_dev *pdev,
                        dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev, &pdev->dev);
        else
                        dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev, &pdev->dev);
-       if (!dev)
+       if (!dev) {
+               pci_disable_device(pdev);
                return -ENODEV;
+       }
 
        pci_set_drvdata(pdev, dev);
        return 0;
@@ -5610,6 +5538,8 @@ static void __devexit airo_pci_remove(struct pci_dev *pdev)
 
        airo_print_info(dev->name, "Unregistering...");
        stop_airo_card(dev, 1);
+       pci_disable_device(pdev);
+       pci_set_drvdata(pdev, NULL);
 }
 
 static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
@@ -5646,7 +5576,6 @@ static int airo_pci_resume(struct pci_dev *pdev)
 {
        struct net_device *dev = pci_get_drvdata(pdev);
        struct airo_info *ai = dev->priv;
-       Resp rsp;
        pci_power_t prev_state = pdev->current_state;
 
        pci_set_power_state(pdev, PCI_D0);
@@ -5679,7 +5608,7 @@ static int airo_pci_resume(struct pci_dev *pdev)
                ai->APList = NULL;
        }
        writeConfigRid(ai, 0);
-       enable_MAC(ai, &rsp, 0);
+       enable_MAC(ai, 0);
        ai->power = PMSG_ON;
        netif_device_attach(dev);
        netif_wake_queue(dev);
@@ -5783,21 +5712,27 @@ static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm)
 static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid)
 {
        int quality = 0;
+       u16 sq;
 
-       if ((status_rid->mode & 0x3f) == 0x3f && (cap_rid->hardCap & 8)) {
-               if (memcmp(cap_rid->prodName, "350", 3))
-                       if (status_rid->signalQuality > 0x20)
-                               quality = 0;
-                       else
-                               quality = 0x20 - status_rid->signalQuality;
+       if ((status_rid->mode & cpu_to_le16(0x3f)) != cpu_to_le16(0x3f))
+               return 0;
+
+       if (!(cap_rid->hardCap & cpu_to_le16(8)))
+               return 0;
+
+       sq = le16_to_cpu(status_rid->signalQuality);
+       if (memcmp(cap_rid->prodName, "350", 3))
+               if (sq > 0x20)
+                       quality = 0;
                else
-                       if (status_rid->signalQuality > 0xb0)
-                               quality = 0;
-                       else if (status_rid->signalQuality < 0x10)
-                               quality = 0xa0;
-                       else
-                               quality = 0xb0 - status_rid->signalQuality;
-       }
+                       quality = 0x20 - sq;
+       else
+               if (sq > 0xb0)
+                       quality = 0;
+               else if (sq < 0x10)
+                       quality = 0xa0;
+               else
+                       quality = 0xb0 - sq;
        return quality;
 }
 
@@ -5855,7 +5790,7 @@ static int airo_set_freq(struct net_device *dev,
                } else {
                        readConfigRid(local, 1);
                        /* Yes ! We can set it !!! */
-                       local->config.channelSet = (u16) channel;
+                       local->config.channelSet = cpu_to_le16(channel);
                        set_bit (FLAG_COMMIT, &local->flags);
                }
        }
@@ -5876,12 +5811,12 @@ static int airo_get_freq(struct net_device *dev,
        int ch;
 
        readConfigRid(local, 1);
-       if ((local->config.opmode & 0xFF) == MODE_STA_ESS)
+       if ((local->config.opmode & MODE_CFG_MASK) == MODE_STA_ESS)
                status_rid.channel = local->config.channelSet;
        else
                readStatusRid(local, &status_rid, 1);
 
-       ch = (int)status_rid.channel;
+       ch = le16_to_cpu(status_rid.channel);
        if((ch > 0) && (ch < 15)) {
                fwrq->m = frequency_list[ch - 1] * 100000;
                fwrq->e = 1;
@@ -5903,7 +5838,6 @@ static int airo_set_essid(struct net_device *dev,
                          char *extra)
 {
        struct airo_info *local = dev->priv;
-       Resp rsp;
        SsidRid SSID_rid;               /* SSIDs */
 
        /* Reload the list of current SSID */
@@ -5929,13 +5863,13 @@ static int airo_set_essid(struct net_device *dev,
                memset(SSID_rid.ssids[index].ssid, 0,
                       sizeof(SSID_rid.ssids[index].ssid));
                memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
-               SSID_rid.ssids[index].len = dwrq->length;
+               SSID_rid.ssids[index].len = cpu_to_le16(dwrq->length);
        }
-       SSID_rid.len = sizeof(SSID_rid);
+       SSID_rid.len = cpu_to_le16(sizeof(SSID_rid));
        /* Write it to the card */
        disable_MAC(local, 1);
        writeSsidRid(local, &SSID_rid, 1);
-       enable_MAC(local, &rsp, 1);
+       enable_MAC(local, 1);
 
        return 0;
 }
@@ -5958,11 +5892,11 @@ static int airo_get_essid(struct net_device *dev,
         * get the relevant SSID from the SSID list... */
 
        /* Get the current SSID */
-       memcpy(extra, status_rid.SSID, status_rid.SSIDlen);
+       memcpy(extra, status_rid.SSID, le16_to_cpu(status_rid.SSIDlen));
        /* If none, we may want to get the one that was set */
 
        /* Push it out ! */
-       dwrq->length = status_rid.SSIDlen;
+       dwrq->length = le16_to_cpu(status_rid.SSIDlen);
        dwrq->flags = 1; /* active */
 
        return 0;
@@ -5996,11 +5930,11 @@ static int airo_set_wap(struct net_device *dev,
                up(&local->sem);
        } else {
                memset(&APList_rid, 0, sizeof(APList_rid));
-               APList_rid.len = sizeof(APList_rid);
+               APList_rid.len = cpu_to_le16(sizeof(APList_rid));
                memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN);
                disable_MAC(local, 1);
                writeAPListRid(local, &APList_rid, 1);
-               enable_MAC(local, &rsp, 1);
+               enable_MAC(local, 1);
        }
        return 0;
 }
@@ -6152,7 +6086,7 @@ static int airo_get_rate(struct net_device *dev,
 
        readStatusRid(local, &status_rid, 1);
 
-       vwrq->value = status_rid.currentXmitRate * 500000;
+       vwrq->value = le16_to_cpu(status_rid.currentXmitRate) * 500000;
        /* If more than one rate, set auto */
        readConfigRid(local, 1);
        vwrq->fixed = (local->config.rates[1] == 0);
@@ -6178,7 +6112,7 @@ static int airo_set_rts(struct net_device *dev,
                return -EINVAL;
        }
        readConfigRid(local, 1);
-       local->config.rtsThres = rthr;
+       local->config.rtsThres = cpu_to_le16(rthr);
        set_bit (FLAG_COMMIT, &local->flags);
 
        return -EINPROGRESS;            /* Call commit handler */
@@ -6196,7 +6130,7 @@ static int airo_get_rts(struct net_device *dev,
        struct airo_info *local = dev->priv;
 
        readConfigRid(local, 1);
-       vwrq->value = local->config.rtsThres;
+       vwrq->value = le16_to_cpu(local->config.rtsThres);
        vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
        vwrq->fixed = 1;
 
@@ -6222,7 +6156,7 @@ static int airo_set_frag(struct net_device *dev,
        }
        fthr &= ~0x1;   /* Get an even value - is it really needed ??? */
        readConfigRid(local, 1);
-       local->config.fragThresh = (u16)fthr;
+       local->config.fragThresh = cpu_to_le16(fthr);
        set_bit (FLAG_COMMIT, &local->flags);
 
        return -EINPROGRESS;            /* Call commit handler */
@@ -6240,7 +6174,7 @@ static int airo_get_frag(struct net_device *dev,
        struct airo_info *local = dev->priv;
 
        readConfigRid(local, 1);
-       vwrq->value = local->config.fragThresh;
+       vwrq->value = le16_to_cpu(local->config.fragThresh);
        vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
        vwrq->fixed = 1;
 
@@ -6260,42 +6194,42 @@ static int airo_set_mode(struct net_device *dev,
        int reset = 0;
 
        readConfigRid(local, 1);
-       if ((local->config.rmode & 0xff) >= RXMODE_RFMON)
+       if (sniffing_mode(local))
                reset = 1;
 
        switch(*uwrq) {
                case IW_MODE_ADHOC:
-                       local->config.opmode &= 0xFF00;
+                       local->config.opmode &= ~MODE_CFG_MASK;
                        local->config.opmode |= MODE_STA_IBSS;
-                       local->config.rmode &= 0xfe00;
+                       local->config.rmode &= ~RXMODE_FULL_MASK;
                        local->config.scanMode = SCANMODE_ACTIVE;
                        clear_bit (FLAG_802_11, &local->flags);
                        break;
                case IW_MODE_INFRA:
-                       local->config.opmode &= 0xFF00;
+                       local->config.opmode &= ~MODE_CFG_MASK;
                        local->config.opmode |= MODE_STA_ESS;
-                       local->config.rmode &= 0xfe00;
+                       local->config.rmode &= ~RXMODE_FULL_MASK;
                        local->config.scanMode = SCANMODE_ACTIVE;
                        clear_bit (FLAG_802_11, &local->flags);
                        break;
                case IW_MODE_MASTER:
-                       local->config.opmode &= 0xFF00;
+                       local->config.opmode &= ~MODE_CFG_MASK;
                        local->config.opmode |= MODE_AP;
-                       local->config.rmode &= 0xfe00;
+                       local->config.rmode &= ~RXMODE_FULL_MASK;
                        local->config.scanMode = SCANMODE_ACTIVE;
                        clear_bit (FLAG_802_11, &local->flags);
                        break;
                case IW_MODE_REPEAT:
-                       local->config.opmode &= 0xFF00;
+                       local->config.opmode &= ~MODE_CFG_MASK;
                        local->config.opmode |= MODE_AP_RPTR;
-                       local->config.rmode &= 0xfe00;
+                       local->config.rmode &= ~RXMODE_FULL_MASK;
                        local->config.scanMode = SCANMODE_ACTIVE;
                        clear_bit (FLAG_802_11, &local->flags);
                        break;
                case IW_MODE_MONITOR:
-                       local->config.opmode &= 0xFF00;
+                       local->config.opmode &= ~MODE_CFG_MASK;
                        local->config.opmode |= MODE_STA_ESS;
-                       local->config.rmode &= 0xfe00;
+                       local->config.rmode &= ~RXMODE_FULL_MASK;
                        local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
                        local->config.scanMode = SCANMODE_PASSIVE;
                        set_bit (FLAG_802_11, &local->flags);
@@ -6323,7 +6257,7 @@ static int airo_get_mode(struct net_device *dev,
 
        readConfigRid(local, 1);
        /* If not managed, assume it's ad-hoc */
-       switch (local->config.opmode & 0xFF) {
+       switch (local->config.opmode & MODE_CFG_MASK) {
                case MODE_STA_ESS:
                        *uwrq = IW_MODE_INFRA;
                        break;
@@ -6340,6 +6274,13 @@ static int airo_get_mode(struct net_device *dev,
        return 0;
 }
 
+static inline int valid_index(CapabilityRid *p, int index)
+{
+       if (index < 0)
+               return 0;
+       return index < (p->softCap & cpu_to_le16(0x80) ? 4 : 1);
+}
+
 /*------------------------------------------------------------------*/
 /*
  * Wireless Handler : set Encryption Key
@@ -6352,12 +6293,12 @@ static int airo_set_encode(struct net_device *dev,
        struct airo_info *local = dev->priv;
        CapabilityRid cap_rid;          /* Card capability info */
        int perm = ( dwrq->flags & IW_ENCODE_TEMP ? 0 : 1 );
-       u16 currentAuthType = local->config.authType;
+       __le16 currentAuthType = local->config.authType;
 
        /* Is WEP supported ? */
        readCapabilityRid(local, &cap_rid, 1);
        /* Older firmware doesn't support this...
-       if(!(cap_rid.softCap & 2)) {
+       if(!(cap_rid.softCap & cpu_to_le16(2))) {
                return -EOPNOTSUPP;
        } */
        readConfigRid(local, 1);
@@ -6377,7 +6318,7 @@ static int airo_set_encode(struct net_device *dev,
                        return -EINVAL;
                }
                /* Check the index (none -> use current) */
-               if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4:1)))
+               if (!valid_index(&cap_rid, index))
                        index = current_index;
                /* Set the length */
                if (dwrq->length > MIN_KEY_SIZE)
@@ -6407,13 +6348,12 @@ static int airo_set_encode(struct net_device *dev,
        } else {
                /* Do we want to just set the transmit key index ? */
                int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
-               if ((index >= 0) && (index < ((cap_rid.softCap & 0x80)?4:1))) {
+               if (valid_index(&cap_rid, index)) {
                        set_wep_key(local, index, NULL, 0, perm, 1);
                } else
                        /* Don't complain if only change the mode */
-                       if(!dwrq->flags & IW_ENCODE_MODE) {
+                       if (!(dwrq->flags & IW_ENCODE_MODE))
                                return -EINVAL;
-                       }
        }
        /* Read the flags */
        if(dwrq->flags & IW_ENCODE_DISABLED)
@@ -6443,7 +6383,7 @@ static int airo_get_encode(struct net_device *dev,
 
        /* Is it supported ? */
        readCapabilityRid(local, &cap_rid, 1);
-       if(!(cap_rid.softCap & 2)) {
+       if(!(cap_rid.softCap & cpu_to_le16(2))) {
                return -EOPNOTSUPP;
        }
        readConfigRid(local, 1);
@@ -6465,7 +6405,7 @@ static int airo_get_encode(struct net_device *dev,
        memset(extra, 0, 16);
 
        /* Which key do we want ? -1 -> tx index */
-       if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4 : 1)))
+       if (!valid_index(&cap_rid, index))
                index = get_wep_key(local, 0xffff);
        dwrq->flags |= index + 1;
        /* Copy the key to the user buffer */
@@ -6490,14 +6430,14 @@ static int airo_set_encodeext(struct net_device *dev,
        struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
        CapabilityRid cap_rid;          /* Card capability info */
        int perm = ( encoding->flags & IW_ENCODE_TEMP ? 0 : 1 );
-       u16 currentAuthType = local->config.authType;
+       __le16 currentAuthType = local->config.authType;
        int idx, key_len, alg = ext->alg, set_key = 1;
        wep_key_t key;
 
        /* Is WEP supported ? */
        readCapabilityRid(local, &cap_rid, 1);
        /* Older firmware doesn't support this...
-       if(!(cap_rid.softCap & 2)) {
+       if(!(cap_rid.softCap & cpu_to_le16(2))) {
                return -EOPNOTSUPP;
        } */
        readConfigRid(local, 1);
@@ -6505,7 +6445,7 @@ static int airo_set_encodeext(struct net_device *dev,
        /* Determine and validate the key index */
        idx = encoding->flags & IW_ENCODE_INDEX;
        if (idx) {
-               if (idx < 1 || idx > ((cap_rid.softCap & 0x80) ? 4:1))
+               if (!valid_index(&cap_rid, idx - 1))
                        return -EINVAL;
                idx--;
        } else
@@ -6579,7 +6519,7 @@ static int airo_get_encodeext(struct net_device *dev,
 
        /* Is it supported ? */
        readCapabilityRid(local, &cap_rid, 1);
-       if(!(cap_rid.softCap & 2)) {
+       if(!(cap_rid.softCap & cpu_to_le16(2))) {
                return -EOPNOTSUPP;
        }
        readConfigRid(local, 1);
@@ -6590,7 +6530,7 @@ static int airo_get_encodeext(struct net_device *dev,
 
        idx = encoding->flags & IW_ENCODE_INDEX;
        if (idx) {
-               if (idx < 1 || idx > ((cap_rid.softCap & 0x80) ? 4:1))
+               if (!valid_index(&cap_rid, idx - 1))
                        return -EINVAL;
                idx--;
        } else
@@ -6636,7 +6576,7 @@ static int airo_set_auth(struct net_device *dev,
 {
        struct airo_info *local = dev->priv;
        struct iw_param *param = &wrqu->param;
-       u16 currentAuthType = local->config.authType;
+       __le16 currentAuthType = local->config.authType;
 
        switch (param->flags & IW_AUTH_INDEX) {
        case IW_AUTH_WPA_VERSION:
@@ -6704,7 +6644,7 @@ static int airo_get_auth(struct net_device *dev,
 {
        struct airo_info *local = dev->priv;
        struct iw_param *param = &wrqu->param;
-       u16 currentAuthType = local->config.authType;
+       __le16 currentAuthType = local->config.authType;
 
        switch (param->flags & IW_AUTH_INDEX) {
        case IW_AUTH_DROP_UNENCRYPTED:
@@ -6755,6 +6695,7 @@ static int airo_set_txpow(struct net_device *dev,
        CapabilityRid cap_rid;          /* Card capability info */
        int i;
        int rc = -EINVAL;
+       __le16 v = cpu_to_le16(vwrq->value);
 
        readCapabilityRid(local, &cap_rid, 1);
 
@@ -6768,9 +6709,9 @@ static int airo_set_txpow(struct net_device *dev,
        }
        clear_bit (FLAG_RADIO_OFF, &local->flags);
        for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++)
-               if ((vwrq->value==cap_rid.txPowerLevels[i])) {
+               if (v == cap_rid.txPowerLevels[i]) {
                        readConfigRid(local, 1);
-                       local->config.txPower = vwrq->value;
+                       local->config.txPower = v;
                        set_bit (FLAG_COMMIT, &local->flags);
                        rc = -EINPROGRESS;      /* Call commit handler */
                        break;
@@ -6790,7 +6731,7 @@ static int airo_get_txpow(struct net_device *dev,
        struct airo_info *local = dev->priv;
 
        readConfigRid(local, 1);
-       vwrq->value = local->config.txPower;
+       vwrq->value = le16_to_cpu(local->config.txPower);
        vwrq->fixed = 1;        /* No power control */
        vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags);
        vwrq->flags = IW_TXPOW_MWATT;
@@ -6815,20 +6756,21 @@ static int airo_set_retry(struct net_device *dev,
        }
        readConfigRid(local, 1);
        if(vwrq->flags & IW_RETRY_LIMIT) {
+               __le16 v = cpu_to_le16(vwrq->value);
                if(vwrq->flags & IW_RETRY_LONG)
-                       local->config.longRetryLimit = vwrq->value;
+                       local->config.longRetryLimit = v;
                else if (vwrq->flags & IW_RETRY_SHORT)
-                       local->config.shortRetryLimit = vwrq->value;
+                       local->config.shortRetryLimit = v;
                else {
                        /* No modifier : set both */
-                       local->config.longRetryLimit = vwrq->value;
-                       local->config.shortRetryLimit = vwrq->value;
+                       local->config.longRetryLimit = v;
+                       local->config.shortRetryLimit = v;
                }
                set_bit (FLAG_COMMIT, &local->flags);
                rc = -EINPROGRESS;              /* Call commit handler */
        }
        if(vwrq->flags & IW_RETRY_LIFETIME) {
-               local->config.txLifetime = vwrq->value / 1024;
+               local->config.txLifetime = cpu_to_le16(vwrq->value / 1024);
                set_bit (FLAG_COMMIT, &local->flags);
                rc = -EINPROGRESS;              /* Call commit handler */
        }
@@ -6852,14 +6794,14 @@ static int airo_get_retry(struct net_device *dev,
        /* Note : by default, display the min retry number */
        if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
                vwrq->flags = IW_RETRY_LIFETIME;
-               vwrq->value = (int)local->config.txLifetime * 1024;
+               vwrq->value = le16_to_cpu(local->config.txLifetime) * 1024;
        } else if((vwrq->flags & IW_RETRY_LONG)) {
                vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
-               vwrq->value = (int)local->config.longRetryLimit;
+               vwrq->value = le16_to_cpu(local->config.longRetryLimit);
        } else {
                vwrq->flags = IW_RETRY_LIMIT;
-               vwrq->value = (int)local->config.shortRetryLimit;
-               if((int)local->config.shortRetryLimit != (int)local->config.longRetryLimit)
+               vwrq->value = le16_to_cpu(local->config.shortRetryLimit);
+               if(local->config.shortRetryLimit != local->config.longRetryLimit)
                        vwrq->flags |= IW_RETRY_SHORT;
        }
 
@@ -6940,16 +6882,17 @@ static int airo_get_range(struct net_device *dev,
        range->min_frag = 256;
        range->max_frag = AIRO_DEF_MTU;
 
-       if(cap_rid.softCap & 2) {
+       if(cap_rid.softCap & cpu_to_le16(2)) {
                // WEP: RC4 40 bits
                range->encoding_size[0] = 5;
                // RC4 ~128 bits
-               if (cap_rid.softCap & 0x100) {
+               if (cap_rid.softCap & cpu_to_le16(0x100)) {
                        range->encoding_size[1] = 13;
                        range->num_encoding_sizes = 2;
                } else
                        range->num_encoding_sizes = 1;
-               range->max_encoding_tokens = (cap_rid.softCap & 0x80) ? 4 : 1;
+               range->max_encoding_tokens =
+                       cap_rid.softCap & cpu_to_le16(0x80) ? 4 : 1;
        } else {
                range->num_encoding_sizes = 0;
                range->max_encoding_tokens = 0;
@@ -6964,7 +6907,7 @@ static int airo_get_range(struct net_device *dev,
 
        /* Transmit Power - values are in mW */
        for(i = 0 ; i < 8 ; i++) {
-               range->txpower[i] = cap_rid.txPowerLevels[i];
+               range->txpower[i] = le16_to_cpu(cap_rid.txPowerLevels[i]);
                if(range->txpower[i] == 0)
                        break;
        }
@@ -7003,38 +6946,37 @@ static int airo_set_power(struct net_device *dev,
 
        readConfigRid(local, 1);
        if (vwrq->disabled) {
-               if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
+               if (sniffing_mode(local))
                        return -EINVAL;
-               }
                local->config.powerSaveMode = POWERSAVE_CAM;
-               local->config.rmode &= 0xFF00;
+               local->config.rmode &= ~RXMODE_MASK;
                local->config.rmode |= RXMODE_BC_MC_ADDR;
                set_bit (FLAG_COMMIT, &local->flags);
                return -EINPROGRESS;            /* Call commit handler */
        }
        if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
-               local->config.fastListenDelay = (vwrq->value + 500) / 1024;
+               local->config.fastListenDelay = cpu_to_le16((vwrq->value + 500) / 1024);
                local->config.powerSaveMode = POWERSAVE_PSPCAM;
                set_bit (FLAG_COMMIT, &local->flags);
        } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
-               local->config.fastListenInterval = local->config.listenInterval = (vwrq->value + 500) / 1024;
+               local->config.fastListenInterval =
+               local->config.listenInterval =
+                       cpu_to_le16((vwrq->value + 500) / 1024);
                local->config.powerSaveMode = POWERSAVE_PSPCAM;
                set_bit (FLAG_COMMIT, &local->flags);
        }
        switch (vwrq->flags & IW_POWER_MODE) {
                case IW_POWER_UNICAST_R:
-                       if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
+                       if (sniffing_mode(local))
                                return -EINVAL;
-                       }
-                       local->config.rmode &= 0xFF00;
+                       local->config.rmode &= ~RXMODE_MASK;
                        local->config.rmode |= RXMODE_ADDR;
                        set_bit (FLAG_COMMIT, &local->flags);
                        break;
                case IW_POWER_ALL_R:
-                       if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
+                       if (sniffing_mode(local))
                                return -EINVAL;
-                       }
-                       local->config.rmode &= 0xFF00;
+                       local->config.rmode &= ~RXMODE_MASK;
                        local->config.rmode |= RXMODE_BC_MC_ADDR;
                        set_bit (FLAG_COMMIT, &local->flags);
                case IW_POWER_ON:
@@ -7058,20 +7000,20 @@ static int airo_get_power(struct net_device *dev,
                          char *extra)
 {
        struct airo_info *local = dev->priv;
-       int mode;
+       __le16 mode;
 
        readConfigRid(local, 1);
        mode = local->config.powerSaveMode;
        if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
                return 0;
        if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
-               vwrq->value = (int)local->config.fastListenDelay * 1024;
+               vwrq->value = le16_to_cpu(local->config.fastListenDelay) * 1024;
                vwrq->flags = IW_POWER_TIMEOUT;
        } else {
-               vwrq->value = (int)local->config.fastListenInterval * 1024;
+               vwrq->value = le16_to_cpu(local->config.fastListenInterval) * 1024;
                vwrq->flags = IW_POWER_PERIOD;
        }
-       if ((local->config.rmode & 0xFF) == RXMODE_ADDR)
+       if ((local->config.rmode & RXMODE_MASK) == RXMODE_ADDR)
                vwrq->flags |= IW_POWER_UNICAST_R;
        else
                vwrq->flags |= IW_POWER_ALL_R;
@@ -7091,7 +7033,8 @@ static int airo_set_sens(struct net_device *dev,
        struct airo_info *local = dev->priv;
 
        readConfigRid(local, 1);
-       local->config.rssiThreshold = vwrq->disabled ? RSSI_DEFAULT : vwrq->value;
+       local->config.rssiThreshold =
+               cpu_to_le16(vwrq->disabled ? RSSI_DEFAULT : vwrq->value);
        set_bit (FLAG_COMMIT, &local->flags);
 
        return -EINPROGRESS;            /* Call commit handler */
@@ -7109,7 +7052,7 @@ static int airo_get_sens(struct net_device *dev,
        struct airo_info *local = dev->priv;
 
        readConfigRid(local, 1);
-       vwrq->value = local->config.rssiThreshold;
+       vwrq->value = le16_to_cpu(local->config.rssiThreshold);
        vwrq->disabled = (vwrq->value == 0);
        vwrq->fixed = 1;
 
@@ -7134,26 +7077,28 @@ static int airo_get_aplist(struct net_device *dev,
        int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
 
        for (i = 0; i < IW_MAX_AP; i++) {
+               u16 dBm;
                if (readBSSListRid(local, loseSync, &BSSList))
                        break;
                loseSync = 0;
                memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
                address[i].sa_family = ARPHRD_ETHER;
+               dBm = le16_to_cpu(BSSList.dBm);
                if (local->rssi) {
-                       qual[i].level = 0x100 - BSSList.dBm;
-                       qual[i].qual = airo_dbm_to_pct( local->rssi, BSSList.dBm );
+                       qual[i].level = 0x100 - dBm;
+                       qual[i].qual = airo_dbm_to_pct(local->rssi, dBm);
                        qual[i].updated = IW_QUAL_QUAL_UPDATED
                                        | IW_QUAL_LEVEL_UPDATED
                                        | IW_QUAL_DBM;
                } else {
-                       qual[i].level = (BSSList.dBm + 321) / 2;
+                       qual[i].level = (dBm + 321) / 2;
                        qual[i].qual = 0;
                        qual[i].updated = IW_QUAL_QUAL_INVALID
                                        | IW_QUAL_LEVEL_UPDATED
                                        | IW_QUAL_DBM;
                }
                qual[i].noise = local->wstats.qual.noise;
-               if (BSSList.index == 0xffff)
+               if (BSSList.index == cpu_to_le16(0xffff))
                        break;
        }
        if (!i) {
@@ -7244,10 +7189,11 @@ static inline char *airo_translate_scan(struct net_device *dev,
 {
        struct airo_info *ai = dev->priv;
        struct iw_event         iwe;            /* Temporary buffer */
-       u16                     capabilities;
+       __le16                  capabilities;
        char *                  current_val;    /* For rates */
        int                     i;
        char *          buf;
+       u16 dBm;
 
        /* First entry *MUST* be the AP MAC address */
        iwe.cmd = SIOCGIWAP;
@@ -7267,7 +7213,7 @@ static inline char *airo_translate_scan(struct net_device *dev,
 
        /* Add mode */
        iwe.cmd = SIOCGIWMODE;
-       capabilities = le16_to_cpu(bss->cap);
+       capabilities = bss->cap;
        if(capabilities & (CAP_ESS | CAP_IBSS)) {
                if(capabilities & CAP_ESS)
                        iwe.u.mode = IW_MODE_MASTER;
@@ -7286,16 +7232,18 @@ static inline char *airo_translate_scan(struct net_device *dev,
        iwe.u.freq.e = 1;
        current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
 
+       dBm = le16_to_cpu(bss->dBm);
+
        /* Add quality statistics */
        iwe.cmd = IWEVQUAL;
        if (ai->rssi) {
-               iwe.u.qual.level = 0x100 - bss->dBm;
-               iwe.u.qual.qual = airo_dbm_to_pct( ai->rssi, bss->dBm );
+               iwe.u.qual.level = 0x100 - dBm;
+               iwe.u.qual.qual = airo_dbm_to_pct(ai->rssi, dBm);
                iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED
                                | IW_QUAL_LEVEL_UPDATED
                                | IW_QUAL_DBM;
        } else {
-               iwe.u.qual.level = (bss->dBm + 321) / 2;
+               iwe.u.qual.level = (dBm + 321) / 2;
                iwe.u.qual.qual = 0;
                iwe.u.qual.updated = IW_QUAL_QUAL_INVALID
                                | IW_QUAL_LEVEL_UPDATED
@@ -7454,7 +7402,6 @@ static int airo_config_commit(struct net_device *dev,
                              char *extra)                      /* NULL */
 {
        struct airo_info *local = dev->priv;
-       Resp rsp;
 
        if (!test_bit (FLAG_COMMIT, &local->flags))
                return 0;
@@ -7479,7 +7426,7 @@ static int airo_config_commit(struct net_device *dev,
        if (down_interruptible(&local->sem))
                return -ERESTARTSYS;
        writeConfigRid(local, 0);
-       enable_MAC(local, &rsp, 0);
+       enable_MAC(local, 0);
        if (test_bit (FLAG_RESET, &local->flags))
                airo_set_promisc(local);
        else
@@ -7574,9 +7521,9 @@ static const iw_handler           airo_private_handler[] =
 
 static const struct iw_handler_def     airo_handler_def =
 {
-       .num_standard   = sizeof(airo_handler)/sizeof(iw_handler),
-       .num_private    = sizeof(airo_private_handler)/sizeof(iw_handler),
-       .num_private_args = sizeof(airo_private_args)/sizeof(struct iw_priv_args),
+       .num_standard   = ARRAY_SIZE(airo_handler),
+       .num_private    = ARRAY_SIZE(airo_private_handler),
+       .num_private_args = ARRAY_SIZE(airo_private_args),
        .standard       = airo_handler,
        .private        = airo_private_handler,
        .private_args   = airo_private_args,
@@ -7675,7 +7622,7 @@ static void airo_read_wireless_stats(struct airo_info *local)
        StatusRid status_rid;
        StatsRid stats_rid;
        CapabilityRid cap_rid;
-       u32 *vals = stats_rid.vals;
+       __le32 *vals = stats_rid.vals;
 
        /* Get stats out of the card */
        clear_bit(JOB_WSTATS, &local->jobs);
@@ -7689,18 +7636,22 @@ static void airo_read_wireless_stats(struct airo_info *local)
        up(&local->sem);
 
        /* The status */
-       local->wstats.status = status_rid.mode;
+       local->wstats.status = le16_to_cpu(status_rid.mode);
 
        /* Signal quality and co */
        if (local->rssi) {
-               local->wstats.qual.level = airo_rssi_to_dbm( local->rssi, status_rid.sigQuality );
+               local->wstats.qual.level =
+                       airo_rssi_to_dbm(local->rssi,
+                                        le16_to_cpu(status_rid.sigQuality));
                /* normalizedSignalStrength appears to be a percentage */
-               local->wstats.qual.qual = status_rid.normalizedSignalStrength;
+               local->wstats.qual.qual =
+                       le16_to_cpu(status_rid.normalizedSignalStrength);
        } else {
-               local->wstats.qual.level = (status_rid.normalizedSignalStrength + 321) / 2;
+               local->wstats.qual.level =
+                       (le16_to_cpu(status_rid.normalizedSignalStrength) + 321) / 2;
                local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid);
        }
-       if (status_rid.len >= 124) {
+       if (le16_to_cpu(status_rid.len) >= 124) {
                local->wstats.qual.noise = 0x100 - status_rid.noisedBm;
                local->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
        } else {
@@ -7710,12 +7661,15 @@ static void airo_read_wireless_stats(struct airo_info *local)
 
        /* Packets discarded in the wireless adapter due to wireless
         * specific problems */
-       local->wstats.discard.nwid = vals[56] + vals[57] + vals[58];/* SSID Mismatch */
-       local->wstats.discard.code = vals[6];/* RxWepErr */
-       local->wstats.discard.fragment = vals[30];
-       local->wstats.discard.retries = vals[10];
-       local->wstats.discard.misc = vals[1] + vals[32];
-       local->wstats.miss.beacon = vals[34];
+       local->wstats.discard.nwid = le32_to_cpu(vals[56]) +
+                                    le32_to_cpu(vals[57]) +
+                                    le32_to_cpu(vals[58]); /* SSID Mismatch */
+       local->wstats.discard.code = le32_to_cpu(vals[6]);/* RxWepErr */
+       local->wstats.discard.fragment = le32_to_cpu(vals[30]);
+       local->wstats.discard.retries = le32_to_cpu(vals[10]);
+       local->wstats.discard.misc = le32_to_cpu(vals[1]) +
+                                    le32_to_cpu(vals[32]);
+       local->wstats.miss.beacon = le32_to_cpu(vals[34]);
 }
 
 static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
@@ -7746,7 +7700,6 @@ static int readrids(struct net_device *dev, aironet_ioctl *comp) {
        unsigned char *iobuf;
        int len;
        struct airo_info *ai = dev->priv;
-       Resp rsp;
 
        if (test_bit(FLAG_FLASHING, &ai->flags))
                return -EIO;
@@ -7758,7 +7711,7 @@ static int readrids(struct net_device *dev, aironet_ioctl *comp) {
                if (test_bit(FLAG_COMMIT, &ai->flags)) {
                        disable_MAC (ai, 1);
                        writeConfigRid (ai, 1);
-                       enable_MAC (ai, &rsp, 1);
+                       enable_MAC(ai, 1);
                }
                break;
        case AIROGSLIST:    ridcode = RID_SSID;         break;
@@ -7815,7 +7768,6 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
        struct airo_info *ai = dev->priv;
        int  ridcode;
         int  enabled;
-       Resp      rsp;
        static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
        unsigned char *iobuf;
 
@@ -7849,7 +7801,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
                 * same with MAC off
                 */
        case AIROPMACON:
-               if (enable_MAC(ai, &rsp, 1) != 0)
+               if (enable_MAC(ai, 1) != 0)
                        return -EIO;
                return 0;
 
@@ -7903,7 +7855,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
                if (test_bit(FLAG_MIC_CAPABLE, &ai->flags))
                        cfg->opmode |= MODE_MIC;
 
-               if ((cfg->opmode & 0xFF) == MODE_STA_IBSS)
+               if ((cfg->opmode & MODE_CFG_MASK) == MODE_STA_IBSS)
                        set_bit (FLAG_ADHOC, &ai->flags);
                else
                        clear_bit (FLAG_ADHOC, &ai->flags);