fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / net / wireless / airo.c
index 00764dd..44a2270 100644 (file)
@@ -19,7 +19,7 @@
 
 ======================================================================*/
 
-#include <linux/config.h>
+#include <linux/err.h>
 #include <linux/init.h>
 
 #include <linux/kernel.h>
@@ -47,6 +47,9 @@
 #include <linux/ioport.h>
 #include <linux/pci.h>
 #include <asm/uaccess.h>
+#include <net/ieee80211.h>
+#include <linux/kthread.h>
+#include <linux/freezer.h>
 
 #include "airo.h"
 
@@ -467,6 +470,8 @@ static int do8bitIO = 0;
 #define RID_ECHOTEST_RESULTS 0xFF71
 #define RID_BSSLISTFIRST 0xFF72
 #define RID_BSSLISTNEXT  0xFF73
+#define RID_WPA_BSSLISTFIRST 0xFF74
+#define RID_WPA_BSSLISTNEXT  0xFF75
 
 typedef struct {
        u16 cmd;
@@ -739,6 +744,14 @@ typedef struct {
        u16 extSoftCap;
 } CapabilityRid;
 
+
+/* Only present on firmware >= 5.30.17 */
+typedef struct {
+  u16 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 */
@@ -767,6 +780,9 @@ typedef struct {
   } fh;
   u16 dsChannel;
   u16 atimWindow;
+
+  /* Only present on firmware >= 5.30.17 */
+  BSSListRidExtra extra;
 } BSSListRid;
 
 typedef struct {
@@ -1105,8 +1121,7 @@ static void mpi_receive_802_3(struct airo_info *ai);
 static void mpi_receive_802_11(struct airo_info *ai);
 static int waitbusy (struct airo_info *ai);
 
-static irqreturn_t airo_interrupt( int irq, void* dev_id, struct pt_regs
-                           *regs);
+static irqreturn_t airo_interrupt( int irq, void* dev_id);
 static int airo_thread(void *data);
 static void timer_func( struct net_device *dev );
 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -1140,8 +1155,6 @@ struct airo_info {
        char defindex; // Used with auto wep
        struct proc_dir_entry *proc_entry;
         spinlock_t aux_lock;
-        unsigned long flags;
-#define FLAG_PROMISC   8       /* IFF_PROMISC 0x100 - include/linux/if.h */
 #define FLAG_RADIO_OFF 0       /* User disabling of MAC */
 #define FLAG_RADIO_DOWN        1       /* ifup/ifdown disabling of MAC */
 #define FLAG_RADIO_MASK 0x03
@@ -1151,6 +1164,7 @@ struct airo_info {
 #define FLAG_UPDATE_MULTI 5
 #define FLAG_UPDATE_UNI 6
 #define FLAG_802_11    7
+#define FLAG_PROMISC   8       /* IFF_PROMISC 0x100 - include/linux/if.h */
 #define FLAG_PENDING_XMIT 9
 #define FLAG_PENDING_XMIT11 10
 #define FLAG_MPI       11
@@ -1158,26 +1172,27 @@ struct airo_info {
 #define FLAG_COMMIT    13
 #define FLAG_RESET     14
 #define FLAG_FLASHING  15
-#define JOB_MASK       0x2ff0000
-#define JOB_DIE                16
-#define JOB_XMIT       17
-#define JOB_XMIT11     18
-#define JOB_STATS      19
-#define JOB_PROMISC    20
-#define JOB_MIC                21
-#define JOB_EVENT      22
-#define JOB_AUTOWEP    23
-#define JOB_WSTATS     24
-#define JOB_SCAN_RESULTS  25
+#define FLAG_WPA_CAPABLE       16
+       unsigned long flags;
+#define JOB_DIE        0
+#define JOB_XMIT       1
+#define JOB_XMIT11     2
+#define JOB_STATS      3
+#define JOB_PROMISC    4
+#define JOB_MIC        5
+#define JOB_EVENT      6
+#define JOB_AUTOWEP    7
+#define JOB_WSTATS     8
+#define JOB_SCAN_RESULTS  9
+       unsigned long jobs;
        int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen,
                        int whichbap);
        unsigned short *flash;
        tdsRssiEntry *rssi;
-       struct task_struct *task;
+       struct task_struct *list_bss_task;
+       struct task_struct *airo_thread_task;
        struct semaphore sem;
-       pid_t thr_pid;
        wait_queue_head_t thr_wait;
-       struct completion thr_exited;
        unsigned long expires;
        struct {
                struct sk_buff *skb;
@@ -1189,7 +1204,7 @@ struct airo_info {
        struct iw_spy_data      spy_data;
        struct iw_public_data   wireless_data;
        /* MIC stuff */
-       struct crypto_tfm       *tfm;
+       struct crypto_cipher    *tfm;
        mic_module              mod[2];
        mic_statistics          micstats;
        HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors
@@ -1208,6 +1223,11 @@ struct airo_info {
 #define        PCI_SHARED_LEN          2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
        char                    proc_name[IFNAMSIZ];
 
+       /* WPA-related stuff */
+       unsigned int bssListFirst;
+       unsigned int bssListNext;
+       unsigned int bssListRidLen;
+
        struct list_head network_list;
        struct list_head network_free_list;
        BSSListElement *networks;
@@ -1252,7 +1272,8 @@ static int flashrestart(struct airo_info *ai,struct net_device *dev);
 
 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
 static void MoveWindow(miccntx *context, u32 micSeq);
-static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *);
+static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
+                          struct crypto_cipher *tfm);
 static void emmh32_init(emmh32_context *context);
 static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
 static void emmh32_final(emmh32_context *context, u8 digest[4]);
@@ -1264,7 +1285,7 @@ static void micinit(struct airo_info *ai)
 {
        MICRid mic_rid;
 
-       clear_bit(JOB_MIC, &ai->flags);
+       clear_bit(JOB_MIC, &ai->jobs);
        PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0);
        up(&ai->sem);
 
@@ -1320,10 +1341,11 @@ static int micsetup(struct airo_info *ai) {
        int i;
 
        if (ai->tfm == NULL)
-               ai->tfm = crypto_alloc_tfm("aes", CRYPTO_TFM_REQ_MAY_SLEEP);
+               ai->tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
 
-        if (ai->tfm == NULL) {
+        if (IS_ERR(ai->tfm)) {
                 airo_print_err(ai->dev->name, "failed to load transform for AES");
+                ai->tfm = NULL;
                 return ERROR;
         }
 
@@ -1589,7 +1611,8 @@ static void MoveWindow(miccntx *context, u32 micSeq)
 static unsigned char aes_counter[16];
 
 /* expand the key to fill the MMH coefficient array */
-static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm)
+static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
+                          struct crypto_cipher *tfm)
 {
   /* take the keying material, expand if necessary, truncate at 16-bytes */
   /* run through AES counter mode to generate context->coeff[] */
@@ -1597,7 +1620,6 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct
        int i,j;
        u32 counter;
        u8 *cipher, plain[16];
-       struct scatterlist sg[1];
 
        crypto_cipher_setkey(tfm, pkey, 16);
        counter = 0;
@@ -1608,9 +1630,8 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct
                aes_counter[12] = (u8)(counter >> 24);
                counter++;
                memcpy (plain, aes_counter, 16);
-               sg_set_buf(sg, plain, 16);
-               crypto_cipher_encrypt(tfm, sg, sg, 16);
-               cipher = kmap(sg->page) + sg->offset;
+               crypto_cipher_encrypt_one(tfm, plain, plain);
+               cipher = plain;
                for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
                        context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
                        j += 4;
@@ -1705,24 +1726,24 @@ static void emmh32_final(emmh32_context *context, u8 digest[4])
 static int readBSSListRid(struct airo_info *ai, int first,
                      BSSListRid *list) {
        int rc;
-                       Cmd cmd;
-                       Resp rsp;
+       Cmd cmd;
+       Resp rsp;
 
        if (first == 1) {
-                       if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
-                       memset(&cmd, 0, sizeof(cmd));
-                       cmd.cmd=CMD_LISTBSS;
-                       if (down_interruptible(&ai->sem))
-                               return -ERESTARTSYS;
-                       issuecommand(ai, &cmd, &rsp);
-                       up(&ai->sem);
-                       /* Let the command take effect */
-                       ai->task = current;
-                       ssleep(3);
-                       ai->task = NULL;
-               }
-       rc = PC4500_readrid(ai, first ? RID_BSSLISTFIRST : RID_BSSLISTNEXT,
-                           list, sizeof(*list), 1);
+               if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
+               memset(&cmd, 0, sizeof(cmd));
+               cmd.cmd=CMD_LISTBSS;
+               if (down_interruptible(&ai->sem))
+                       return -ERESTARTSYS;
+               ai->list_bss_task = current;
+               issuecommand(ai, &cmd, &rsp);
+               up(&ai->sem);
+               /* Let the command take effect */
+               schedule_timeout_uninterruptible(3 * HZ);
+               ai->list_bss_task = NULL;
+       }
+       rc = 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);
@@ -2112,7 +2133,7 @@ static void airo_end_xmit(struct net_device *dev) {
        int fid = priv->xmit.fid;
        u32 *fids = priv->fids;
 
-       clear_bit(JOB_XMIT, &priv->flags);
+       clear_bit(JOB_XMIT, &priv->jobs);
        clear_bit(FLAG_PENDING_XMIT, &priv->flags);
        status = transmit_802_3_packet (priv, fids[fid], skb->data);
        up(&priv->sem);
@@ -2162,7 +2183,7 @@ static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
        if (down_trylock(&priv->sem) != 0) {
                set_bit(FLAG_PENDING_XMIT, &priv->flags);
                netif_stop_queue(dev);
-               set_bit(JOB_XMIT, &priv->flags);
+               set_bit(JOB_XMIT, &priv->jobs);
                wake_up_interruptible(&priv->thr_wait);
        } else
                airo_end_xmit(dev);
@@ -2177,7 +2198,7 @@ static void airo_end_xmit11(struct net_device *dev) {
        int fid = priv->xmit11.fid;
        u32 *fids = priv->fids;
 
-       clear_bit(JOB_XMIT11, &priv->flags);
+       clear_bit(JOB_XMIT11, &priv->jobs);
        clear_bit(FLAG_PENDING_XMIT11, &priv->flags);
        status = transmit_802_11_packet (priv, fids[fid], skb->data);
        up(&priv->sem);
@@ -2233,7 +2254,7 @@ static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
        if (down_trylock(&priv->sem) != 0) {
                set_bit(FLAG_PENDING_XMIT11, &priv->flags);
                netif_stop_queue(dev);
-               set_bit(JOB_XMIT11, &priv->flags);
+               set_bit(JOB_XMIT11, &priv->jobs);
                wake_up_interruptible(&priv->thr_wait);
        } else
                airo_end_xmit11(dev);
@@ -2244,7 +2265,7 @@ static void airo_read_stats(struct airo_info *ai) {
        StatsRid stats_rid;
        u32 *vals = stats_rid.vals;
 
-       clear_bit(JOB_STATS, &ai->flags);
+       clear_bit(JOB_STATS, &ai->jobs);
        if (ai->power.event) {
                up(&ai->sem);
                return;
@@ -2272,10 +2293,10 @@ static struct net_device_stats *airo_get_stats(struct net_device *dev)
 {
        struct airo_info *local =  dev->priv;
 
-       if (!test_bit(JOB_STATS, &local->flags)) {
+       if (!test_bit(JOB_STATS, &local->jobs)) {
                /* Get stats out of the card if available */
                if (down_trylock(&local->sem) != 0) {
-                       set_bit(JOB_STATS, &local->flags);
+                       set_bit(JOB_STATS, &local->jobs);
                        wake_up_interruptible(&local->thr_wait);
                } else
                        airo_read_stats(local);
@@ -2290,7 +2311,7 @@ static void airo_set_promisc(struct airo_info *ai) {
 
        memset(&cmd, 0, sizeof(cmd));
        cmd.cmd=CMD_SETMODE;
-       clear_bit(JOB_PROMISC, &ai->flags);
+       clear_bit(JOB_PROMISC, &ai->jobs);
        cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
        issuecommand(ai, &cmd, &rsp);
        up(&ai->sem);
@@ -2302,7 +2323,7 @@ static void airo_set_multicast_list(struct net_device *dev) {
        if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
                change_bit(FLAG_PROMISC, &ai->flags);
                if (down_trylock(&ai->sem) != 0) {
-                       set_bit(JOB_PROMISC, &ai->flags);
+                       set_bit(JOB_PROMISC, &ai->jobs);
                        wake_up_interruptible(&ai->thr_wait);
                } else
                        airo_set_promisc(ai);
@@ -2380,9 +2401,8 @@ void stop_airo_card( struct net_device *dev, int freeres )
                }
                clear_bit(FLAG_REGISTERED, &ai->flags);
        }
-       set_bit(JOB_DIE, &ai->flags);
-       kill_proc(ai->thr_pid, SIGTERM, 1);
-       wait_for_completion(&ai->thr_exited);
+       set_bit(JOB_DIE, &ai->jobs);
+       kthread_stop(ai->airo_thread_task);
 
        /*
         * Clean out tx queue
@@ -2413,7 +2433,7 @@ void stop_airo_card( struct net_device *dev, int freeres )
                                ai->shared, ai->shared_dma);
                }
         }
-       crypto_free_tfm(ai->tfm);
+       crypto_free_cipher(ai->tfm);
        del_airo_dev( dev );
        free_netdev( dev );
 }
@@ -2701,14 +2721,14 @@ static int reset_card( struct net_device *dev , int lock) {
        return 0;
 }
 
-#define MAX_NETWORK_COUNT      64
+#define AIRO_MAX_NETWORK_COUNT 64
 static int airo_networks_allocate(struct airo_info *ai)
 {
        if (ai->networks)
                return 0;
 
        ai->networks =
-           kzalloc(MAX_NETWORK_COUNT * sizeof(BSSListElement),
+           kzalloc(AIRO_MAX_NETWORK_COUNT * sizeof(BSSListElement),
                    GFP_KERNEL);
        if (!ai->networks) {
                airo_print_warn(ai->dev->name, "Out of memory allocating beacons");
@@ -2732,11 +2752,33 @@ static void airo_networks_initialize(struct airo_info *ai)
 
        INIT_LIST_HEAD(&ai->network_free_list);
        INIT_LIST_HEAD(&ai->network_list);
-       for (i = 0; i < MAX_NETWORK_COUNT; i++)
+       for (i = 0; i < AIRO_MAX_NETWORK_COUNT; i++)
                list_add_tail(&ai->networks[i].list,
                              &ai->network_free_list);
 }
 
+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.");
+               return 1;
+       }
+
+       /* No WPA support */
+       airo_print_info(name, "WPA unsupported (only firmware versions 5.30.17"
+               " and greater support WPA.  Detected %s)", cap_rid.prodVer);
+       return 0;
+}
+
 static struct net_device *_init_airo_card( unsigned short irq, int port,
                                           int is_pcmcia, struct pci_dev *pci,
                                           struct device *dmdev )
@@ -2759,6 +2801,7 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
        ai = dev->priv;
        ai->wifidev = NULL;
        ai->flags = 0;
+       ai->jobs = 0;
        ai->dev = dev;
        if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
                airo_print_dbg(dev->name, "Found an MPI350 card");
@@ -2769,9 +2812,8 @@ 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);
-       init_completion (&ai->thr_exited);
-       ai->thr_pid = kernel_thread(airo_thread, dev, CLONE_FS | CLONE_FILES);
-       if (ai->thr_pid < 0)
+       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;
        rc = add_airo_dev( dev );
@@ -2806,7 +2848,7 @@ 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, SA_SHIRQ, dev->name, dev );
+       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);
@@ -2838,12 +2880,26 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
                set_bit(FLAG_FLASHING, &ai->flags);
        }
 
+       /* Test for WPA support */
+       if (airo_test_wpa_capable(ai)) {
+               set_bit(FLAG_WPA_CAPABLE, &ai->flags);
+               ai->bssListFirst = RID_WPA_BSSLISTFIRST;
+               ai->bssListNext = RID_WPA_BSSLISTNEXT;
+               ai->bssListRidLen = sizeof(BSSListRid);
+       } else {
+               ai->bssListFirst = RID_BSSLISTFIRST;
+               ai->bssListNext = RID_BSSLISTNEXT;
+               ai->bssListRidLen = sizeof(BSSListRid) - sizeof(BSSListRidExtra);
+       }
+
        rc = register_netdev(dev);
        if (rc) {
                airo_print_err(dev->name, "Couldn't register_netdev");
                goto err_out_map;
        }
        ai->wifidev = init_wifidev(ai, dev);
+       if (!ai->wifidev)
+               goto err_out_reg;
 
        set_bit(FLAG_REGISTERED,&ai->flags);
        airo_print_info(dev->name, "MAC enabled %x:%x:%x:%x:%x:%x",
@@ -2855,11 +2911,18 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
                for( i = 0; i < MAX_FIDS; i++ )
                        ai->fids[i] = transmit_allocate(ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
 
-       setup_proc_entry( dev, dev->priv ); /* XXX check for failure */
+       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:
+       unregister_netdev(ai->wifidev);
+       free_netdev(ai->wifidev);
+err_out_reg:
+       unregister_netdev(dev);
 err_out_map:
        if (test_bit(FLAG_MPI,&ai->flags) && pci) {
                pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
@@ -2875,9 +2938,8 @@ err_out_irq:
 err_out_unlink:
        del_airo_dev(dev);
 err_out_thr:
-       set_bit(JOB_DIE, &ai->flags);
-       kill_proc(ai->thr_pid, SIGTERM, 1);
-       wait_for_completion(&ai->thr_exited);
+       set_bit(JOB_DIE, &ai->jobs);
+       kthread_stop(ai->airo_thread_task);
 err_out_free:
        free_netdev(dev);
        return NULL;
@@ -2933,7 +2995,7 @@ static void airo_send_event(struct net_device *dev) {
        union iwreq_data wrqu;
        StatusRid status_rid;
 
-       clear_bit(JOB_EVENT, &ai->flags);
+       clear_bit(JOB_EVENT, &ai->jobs);
        PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0);
        up(&ai->sem);
        wrqu.data.length = 0;
@@ -2947,7 +3009,7 @@ static void airo_send_event(struct net_device *dev) {
 
 static void airo_process_scan_results (struct airo_info *ai) {
        union iwreq_data        wrqu;
-       BSSListRid BSSList;
+       BSSListRid bss;
        int rc;
        BSSListElement * loop_net;
        BSSListElement * tmp_net;
@@ -2960,15 +3022,15 @@ static void airo_process_scan_results (struct airo_info *ai) {
        }
 
        /* Try to read the first entry of the scan result */
-       rc = PC4500_readrid(ai, RID_BSSLISTFIRST, &BSSList, sizeof(BSSList), 0);
-       if((rc) || (BSSList.index == 0xffff)) {
+       rc = PC4500_readrid(ai, ai->bssListFirst, &bss, ai->bssListRidLen, 0);
+       if((rc) || (bss.index == 0xffff)) {
                /* No scan results */
                goto out;
        }
 
        /* Read and parse all entries */
        tmp_net = NULL;
-       while((!rc) && (BSSList.index != 0xffff)) {
+       while((!rc) && (bss.index != 0xffff)) {
                /* Grab a network off the free list */
                if (!list_empty(&ai->network_free_list)) {
                        tmp_net = list_entry(ai->network_free_list.next,
@@ -2977,19 +3039,19 @@ static void airo_process_scan_results (struct airo_info *ai) {
                }
 
                if (tmp_net != NULL) {
-                       memcpy(tmp_net, &BSSList, sizeof(tmp_net->bss));
+                       memcpy(tmp_net, &bss, sizeof(tmp_net->bss));
                        list_add_tail(&tmp_net->list, &ai->network_list);
                        tmp_net = NULL;
                }
 
                /* Read next entry */
-               rc = PC4500_readrid(ai, RID_BSSLISTNEXT,
-                                   &BSSList, sizeof(BSSList), 0);
+               rc = PC4500_readrid(ai, ai->bssListNext,
+                                   &bss, ai->bssListRidLen, 0);
        }
 
 out:
        ai->scan_timeout = 0;
-       clear_bit(JOB_SCAN_RESULTS, &ai->flags);
+       clear_bit(JOB_SCAN_RESULTS, &ai->jobs);
        up(&ai->sem);
 
        /* Send an empty event to user space.
@@ -3009,20 +3071,14 @@ static int airo_thread(void *data) {
        struct airo_info *ai = dev->priv;
        int locked;
        
-       daemonize("%s", dev->name);
-       allow_signal(SIGTERM);
-
        while(1) {
-               if (signal_pending(current))
-                       flush_signals(current);
-
                /* make swsusp happy with our thread */
                try_to_freeze();
 
-               if (test_bit(JOB_DIE, &ai->flags))
+               if (test_bit(JOB_DIE, &ai->jobs))
                        break;
 
-               if (ai->flags & JOB_MASK) {
+               if (ai->jobs) {
                        locked = down_interruptible(&ai->sem);
                } else {
                        wait_queue_t wait;
@@ -3031,19 +3087,20 @@ static int airo_thread(void *data) {
                        add_wait_queue(&ai->thr_wait, &wait);
                        for (;;) {
                                set_current_state(TASK_INTERRUPTIBLE);
-                               if (ai->flags & JOB_MASK)
+                               if (ai->jobs)
                                        break;
                                if (ai->expires || ai->scan_timeout) {
                                        if (ai->scan_timeout &&
                                                        time_after_eq(jiffies,ai->scan_timeout)){
-                                               set_bit(JOB_SCAN_RESULTS,&ai->flags);
+                                               set_bit(JOB_SCAN_RESULTS, &ai->jobs);
                                                break;
                                        } else if (ai->expires &&
                                                        time_after_eq(jiffies,ai->expires)){
-                                               set_bit(JOB_AUTOWEP,&ai->flags);
+                                               set_bit(JOB_AUTOWEP, &ai->jobs);
                                                break;
                                        }
-                                       if (!signal_pending(current)) {
+                                       if (!kthread_should_stop() &&
+                                           !freezing(current)) {
                                                unsigned long wake_at;
                                                if (!ai->expires || !ai->scan_timeout) {
                                                        wake_at = max(ai->expires,
@@ -3055,7 +3112,8 @@ static int airo_thread(void *data) {
                                                schedule_timeout(wake_at - jiffies);
                                                continue;
                                        }
-                               } else if (!signal_pending(current)) {
+                               } else if (!kthread_should_stop() &&
+                                          !freezing(current)) {
                                        schedule();
                                        continue;
                                }
@@ -3069,7 +3127,7 @@ static int airo_thread(void *data) {
                if (locked)
                        continue;
 
-               if (test_bit(JOB_DIE, &ai->flags)) {
+               if (test_bit(JOB_DIE, &ai->jobs)) {
                        up(&ai->sem);
                        break;
                }
@@ -3079,31 +3137,32 @@ static int airo_thread(void *data) {
                        continue;
                }
 
-               if (test_bit(JOB_XMIT, &ai->flags))
+               if (test_bit(JOB_XMIT, &ai->jobs))
                        airo_end_xmit(dev);
-               else if (test_bit(JOB_XMIT11, &ai->flags))
+               else if (test_bit(JOB_XMIT11, &ai->jobs))
                        airo_end_xmit11(dev);
-               else if (test_bit(JOB_STATS, &ai->flags))
+               else if (test_bit(JOB_STATS, &ai->jobs))
                        airo_read_stats(ai);
-               else if (test_bit(JOB_WSTATS, &ai->flags))
+               else if (test_bit(JOB_WSTATS, &ai->jobs))
                        airo_read_wireless_stats(ai);
-               else if (test_bit(JOB_PROMISC, &ai->flags))
+               else if (test_bit(JOB_PROMISC, &ai->jobs))
                        airo_set_promisc(ai);
-               else if (test_bit(JOB_MIC, &ai->flags))
+               else if (test_bit(JOB_MIC, &ai->jobs))
                        micinit(ai);
-               else if (test_bit(JOB_EVENT, &ai->flags))
+               else if (test_bit(JOB_EVENT, &ai->jobs))
                        airo_send_event(dev);
-               else if (test_bit(JOB_AUTOWEP, &ai->flags))
+               else if (test_bit(JOB_AUTOWEP, &ai->jobs))
                        timer_func(dev);
-               else if (test_bit(JOB_SCAN_RESULTS, &ai->flags))
+               else if (test_bit(JOB_SCAN_RESULTS, &ai->jobs))
                        airo_process_scan_results(ai);
                else  /* Shouldn't get here, but we make sure to unlock */
                        up(&ai->sem);
        }
-       complete_and_exit (&ai->thr_exited, 0);
+
+       return 0;
 }
 
-static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs) {
+static irqreturn_t airo_interrupt ( int irq, void* dev_id) {
        struct net_device *dev = (struct net_device *)dev_id;
        u16 status;
        u16 fid;
@@ -3133,7 +3192,7 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs)
                if ( status & EV_MIC ) {
                        OUT4500( apriv, EVACK, EV_MIC );
                        if (test_bit(FLAG_MIC_CAPABLE, &apriv->flags)) {
-                               set_bit(JOB_MIC, &apriv->flags);
+                               set_bit(JOB_MIC, &apriv->jobs);
                                wake_up_interruptible(&apriv->thr_wait);
                        }
                }
@@ -3181,13 +3240,13 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs)
                        if(newStatus == ASSOCIATED || newStatus == REASSOCIATED) {
                                if (auto_wep)
                                        apriv->expires = 0;
-                               if (apriv->task)
-                                       wake_up_process (apriv->task);
+                               if (apriv->list_bss_task)
+                                       wake_up_process(apriv->list_bss_task);
                                set_bit(FLAG_UPDATE_UNI, &apriv->flags);
                                set_bit(FLAG_UPDATE_MULTI, &apriv->flags);
 
                                if (down_trylock(&apriv->sem) != 0) {
-                                       set_bit(JOB_EVENT, &apriv->flags);
+                                       set_bit(JOB_EVENT, &apriv->jobs);
                                        wake_up_interruptible(&apriv->thr_wait);
                                } else
                                        airo_send_event(dev);
@@ -3896,13 +3955,11 @@ static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
        pRsp->rsp0 = IN4500(ai, RESP0);
        pRsp->rsp1 = IN4500(ai, RESP1);
        pRsp->rsp2 = IN4500(ai, RESP2);
-       if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET) {
-               airo_print_err(ai->dev->name, "cmd= %x\n", pCmd->cmd);
-               airo_print_err(ai->dev->name, "status= %x\n", pRsp->status);
-               airo_print_err(ai->dev->name, "Rsp0= %x\n", pRsp->rsp0);
-               airo_print_err(ai->dev->name, "Rsp1= %x\n", pRsp->rsp1);
-               airo_print_err(ai->dev->name, "Rsp2= %x\n", pRsp->rsp2);
-       }
+       if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET)
+               airo_print_err(ai->dev->name,
+                       "cmd:%x status:%x rsp0:%x rsp1:%x rsp2:%x",
+                       pCmd->cmd, pRsp->status, pRsp->rsp0, pRsp->rsp1,
+                       pRsp->rsp2);
 
        // clear stuck command busy if necessary
        if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
@@ -4450,91 +4507,128 @@ static int setup_proc_entry( struct net_device *dev,
        apriv->proc_entry = create_proc_entry(apriv->proc_name,
                                              S_IFDIR|airo_perm,
                                              airo_entry);
-        apriv->proc_entry->uid = proc_uid;
-        apriv->proc_entry->gid = proc_gid;
-        apriv->proc_entry->owner = THIS_MODULE;
+       if (!apriv->proc_entry)
+               goto fail;
+       apriv->proc_entry->uid = proc_uid;
+       apriv->proc_entry->gid = proc_gid;
+       apriv->proc_entry->owner = THIS_MODULE;
 
        /* Setup the StatsDelta */
        entry = create_proc_entry("StatsDelta",
                                  S_IFREG | (S_IRUGO&proc_perm),
                                  apriv->proc_entry);
-        entry->uid = proc_uid;
-        entry->gid = proc_gid;
+       if (!entry)
+               goto fail_stats_delta;
+       entry->uid = proc_uid;
+       entry->gid = proc_gid;
        entry->data = dev;
-        entry->owner = THIS_MODULE;
+       entry->owner = THIS_MODULE;
        SETPROC_OPS(entry, proc_statsdelta_ops);
 
        /* Setup the Stats */
        entry = create_proc_entry("Stats",
                                  S_IFREG | (S_IRUGO&proc_perm),
                                  apriv->proc_entry);
-        entry->uid = proc_uid;
-        entry->gid = proc_gid;
+       if (!entry)
+               goto fail_stats;
+       entry->uid = proc_uid;
+       entry->gid = proc_gid;
        entry->data = dev;
-        entry->owner = THIS_MODULE;
+       entry->owner = THIS_MODULE;
        SETPROC_OPS(entry, proc_stats_ops);
 
        /* Setup the Status */
        entry = create_proc_entry("Status",
                                  S_IFREG | (S_IRUGO&proc_perm),
                                  apriv->proc_entry);
-        entry->uid = proc_uid;
-        entry->gid = proc_gid;
+       if (!entry)
+               goto fail_status;
+       entry->uid = proc_uid;
+       entry->gid = proc_gid;
        entry->data = dev;
-        entry->owner = THIS_MODULE;
+       entry->owner = THIS_MODULE;
        SETPROC_OPS(entry, proc_status_ops);
 
        /* Setup the Config */
        entry = create_proc_entry("Config",
                                  S_IFREG | proc_perm,
                                  apriv->proc_entry);
-        entry->uid = proc_uid;
-        entry->gid = proc_gid;
+       if (!entry)
+               goto fail_config;
+       entry->uid = proc_uid;
+       entry->gid = proc_gid;
        entry->data = dev;
-        entry->owner = THIS_MODULE;
+       entry->owner = THIS_MODULE;
        SETPROC_OPS(entry, proc_config_ops);
 
        /* Setup the SSID */
        entry = create_proc_entry("SSID",
                                  S_IFREG | proc_perm,
                                  apriv->proc_entry);
-        entry->uid = proc_uid;
-        entry->gid = proc_gid;
+       if (!entry)
+               goto fail_ssid;
+       entry->uid = proc_uid;
+       entry->gid = proc_gid;
        entry->data = dev;
-        entry->owner = THIS_MODULE;
+       entry->owner = THIS_MODULE;
        SETPROC_OPS(entry, proc_SSID_ops);
 
        /* Setup the APList */
        entry = create_proc_entry("APList",
                                  S_IFREG | proc_perm,
                                  apriv->proc_entry);
-        entry->uid = proc_uid;
-        entry->gid = proc_gid;
+       if (!entry)
+               goto fail_aplist;
+       entry->uid = proc_uid;
+       entry->gid = proc_gid;
        entry->data = dev;
-        entry->owner = THIS_MODULE;
+       entry->owner = THIS_MODULE;
        SETPROC_OPS(entry, proc_APList_ops);
 
        /* Setup the BSSList */
        entry = create_proc_entry("BSSList",
                                  S_IFREG | proc_perm,
                                  apriv->proc_entry);
+       if (!entry)
+               goto fail_bsslist;
        entry->uid = proc_uid;
        entry->gid = proc_gid;
        entry->data = dev;
-        entry->owner = THIS_MODULE;
+       entry->owner = THIS_MODULE;
        SETPROC_OPS(entry, proc_BSSList_ops);
 
        /* Setup the WepKey */
        entry = create_proc_entry("WepKey",
                                  S_IFREG | proc_perm,
                                  apriv->proc_entry);
-        entry->uid = proc_uid;
-        entry->gid = proc_gid;
+       if (!entry)
+               goto fail_wepkey;
+       entry->uid = proc_uid;
+       entry->gid = proc_gid;
        entry->data = dev;
-        entry->owner = THIS_MODULE;
+       entry->owner = THIS_MODULE;
        SETPROC_OPS(entry, proc_wepkey_ops);
 
        return 0;
+
+fail_wepkey:
+       remove_proc_entry("BSSList", apriv->proc_entry);
+fail_bsslist:
+       remove_proc_entry("APList", apriv->proc_entry);
+fail_aplist:
+       remove_proc_entry("SSID", apriv->proc_entry);
+fail_ssid:
+       remove_proc_entry("Config", apriv->proc_entry);
+fail_config:
+       remove_proc_entry("Status", apriv->proc_entry);
+fail_status:
+       remove_proc_entry("Stats", apriv->proc_entry);
+fail_stats:
+       remove_proc_entry("StatsDelta", apriv->proc_entry);
+fail_stats_delta:
+       remove_proc_entry(apriv->proc_name, airo_entry);
+fail:
+       return -ENOMEM;
 }
 
 static int takedown_proc_entry( struct net_device *dev,
@@ -5485,7 +5579,7 @@ static void timer_func( struct net_device *dev ) {
        up(&apriv->sem);
 
 /* Schedule check to see if the change worked */
-       clear_bit(JOB_AUTOWEP, &apriv->flags);
+       clear_bit(JOB_AUTOWEP, &apriv->jobs);
        apriv->expires = RUN_AT(HZ*3);
 }
 
@@ -5613,25 +5707,40 @@ static int airo_pci_resume(struct pci_dev *pdev)
 
 static int __init airo_init_module( void )
 {
-       int i, have_isa_dev = 0;
+       int i;
+#if 0
+       int have_isa_dev = 0;
+#endif
 
        airo_entry = create_proc_entry("aironet",
                                       S_IFDIR | airo_perm,
                                       proc_root_driver);
-        airo_entry->uid = proc_uid;
-        airo_entry->gid = proc_gid;
+
+       if (airo_entry) {
+               airo_entry->uid = proc_uid;
+               airo_entry->gid = proc_gid;
+       }
 
        for( i = 0; i < 4 && io[i] && irq[i]; i++ ) {
                airo_print_info("", "Trying to configure ISA adapter at irq=%d "
                        "io=0x%x", irq[i], io[i] );
                if (init_airo_card( irq[i], io[i], 0, NULL ))
+#if 0
                        have_isa_dev = 1;
+#else
+                       /* do nothing */ ;
+#endif
        }
 
 #ifdef CONFIG_PCI
        airo_print_info("", "Probing for PCI adapters");
-       pci_register_driver(&airo_driver);
+       i = pci_register_driver(&airo_driver);
        airo_print_info("", "Finished probing for PCI adapters");
+
+       if (i) {
+               remove_proc_entry("aironet", proc_root_driver);
+               return i;
+       }
 #endif
 
        /* Always exit with success, as we are a library module
@@ -5822,7 +5931,7 @@ static int airo_set_essid(struct net_device *dev,
                int     index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
 
                /* Check the size of the string */
-               if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
+               if(dwrq->length > IW_ESSID_MAX_SIZE) {
                        return -E2BIG ;
                }
                /* Check if index is valid */
@@ -5834,7 +5943,7 @@ 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 - 1;
+               SSID_rid.ssids[index].len = dwrq->length;
        }
        SSID_rid.len = sizeof(SSID_rid);
        /* Write it to the card */
@@ -5864,7 +5973,6 @@ static int airo_get_essid(struct net_device *dev,
 
        /* Get the current SSID */
        memcpy(extra, status_rid.SSID, status_rid.SSIDlen);
-       extra[status_rid.SSIDlen] = '\0';
        /* If none, we may want to get the one that was set */
 
        /* Push it out ! */
@@ -5944,7 +6052,7 @@ static int airo_set_nick(struct net_device *dev,
        struct airo_info *local = dev->priv;
 
        /* Check the size of the string */
-       if(dwrq->length > 16 + 1) {
+       if(dwrq->length > 16) {
                return -E2BIG;
        }
        readConfigRid(local, 1);
@@ -5969,7 +6077,7 @@ static int airo_get_nick(struct net_device *dev,
        readConfigRid(local, 1);
        strncpy(extra, local->config.nodeName, 16);
        extra[16] = '\0';
-       dwrq->length = strlen(extra) + 1;
+       dwrq->length = strlen(extra);
 
        return 0;
 }
@@ -6721,9 +6829,9 @@ static int airo_set_retry(struct net_device *dev,
        }
        readConfigRid(local, 1);
        if(vwrq->flags & IW_RETRY_LIMIT) {
-               if(vwrq->flags & IW_RETRY_MAX)
+               if(vwrq->flags & IW_RETRY_LONG)
                        local->config.longRetryLimit = vwrq->value;
-               else if (vwrq->flags & IW_RETRY_MIN)
+               else if (vwrq->flags & IW_RETRY_SHORT)
                        local->config.shortRetryLimit = vwrq->value;
                else {
                        /* No modifier : set both */
@@ -6759,14 +6867,14 @@ static int airo_get_retry(struct net_device *dev,
        if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
                vwrq->flags = IW_RETRY_LIFETIME;
                vwrq->value = (int)local->config.txLifetime * 1024;
-       } else if((vwrq->flags & IW_RETRY_MAX)) {
-               vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
+       } else if((vwrq->flags & IW_RETRY_LONG)) {
+               vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
                vwrq->value = (int)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->flags |= IW_RETRY_MIN;
+                       vwrq->flags |= IW_RETRY_SHORT;
        }
 
        return 0;
@@ -6876,7 +6984,7 @@ static int airo_get_range(struct net_device *dev,
        }
        range->num_txpower = i;
        range->txpower_capa = IW_TXPOW_MWATT;
-       range->we_version_source = 12;
+       range->we_version_source = 19;
        range->we_version_compiled = WIRELESS_EXT;
        range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
        range->retry_flags = IW_RETRY_LIMIT;
@@ -6944,6 +7052,7 @@ static int airo_set_power(struct net_device *dev,
                        local->config.rmode |= RXMODE_BC_MC_ADDR;
                        set_bit (FLAG_COMMIT, &local->flags);
                case IW_POWER_ON:
+                       /* This is broken, fixme ;-) */
                        break;
                default:
                        return -EINVAL;
@@ -7152,6 +7261,7 @@ static inline char *airo_translate_scan(struct net_device *dev,
        u16                     capabilities;
        char *                  current_val;    /* For rates */
        int                     i;
+       char *          buf;
 
        /* First entry *MUST* be the AP MAC address */
        iwe.cmd = SIOCGIWAP;
@@ -7238,8 +7348,69 @@ static inline char *airo_translate_scan(struct net_device *dev,
        if((current_val - current_ev) > IW_EV_LCP_LEN)
                current_ev = current_val;
 
-       /* The other data in the scan result are not really
-        * interesting, so for now drop it - Jean II */
+       /* Beacon interval */
+       buf = kmalloc(30, GFP_KERNEL);
+       if (buf) {
+               iwe.cmd = IWEVCUSTOM;
+               sprintf(buf, "bcn_int=%d", bss->beaconInterval);
+               iwe.u.data.length = strlen(buf);
+               current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, buf);
+               kfree(buf);
+       }
+
+       /* Put WPA/RSN Information Elements into the event stream */
+       if (test_bit(FLAG_WPA_CAPABLE, &ai->flags)) {
+               unsigned int num_null_ies = 0;
+               u16 length = sizeof (bss->extra.iep);
+               struct ieee80211_info_element *info_element =
+                       (struct ieee80211_info_element *) &bss->extra.iep;
+
+               while ((length >= sizeof(*info_element)) && (num_null_ies < 2)) {
+                       if (sizeof(*info_element) + info_element->len > length) {
+                               /* Invalid element, don't continue parsing IE */
+                               break;
+                       }
+
+                       switch (info_element->id) {
+                       case MFIE_TYPE_SSID:
+                               /* Two zero-length SSID elements
+                                * mean we're done parsing elements */
+                               if (!info_element->len)
+                                       num_null_ies++;
+                               break;
+
+                       case MFIE_TYPE_GENERIC:
+                               if (info_element->len >= 4 &&
+                                   info_element->data[0] == 0x00 &&
+                                   info_element->data[1] == 0x50 &&
+                                   info_element->data[2] == 0xf2 &&
+                                   info_element->data[3] == 0x01) {
+                                       iwe.cmd = IWEVGENIE;
+                                       iwe.u.data.length = min(info_element->len + 2,
+                                                                 MAX_WPA_IE_LEN);
+                                       current_ev = iwe_stream_add_point(current_ev, end_buf,
+                                                       &iwe, (char *) info_element);
+                               }
+                               break;
+
+                       case MFIE_TYPE_RSN:
+                               iwe.cmd = IWEVGENIE;
+                               iwe.u.data.length = min(info_element->len + 2,
+                                                         MAX_WPA_IE_LEN);
+                               current_ev = iwe_stream_add_point(current_ev, end_buf,
+                                               &iwe, (char *) info_element);
+                               break;
+
+                       default:
+                               break;
+                       }
+
+                       length -= sizeof(*info_element) + info_element->len;
+                       info_element =
+                           (struct ieee80211_info_element *)&info_element->
+                           data[info_element->len];
+               }
+       }
        return current_ev;
 }
 
@@ -7521,7 +7692,7 @@ static void airo_read_wireless_stats(struct airo_info *local)
        u32 *vals = stats_rid.vals;
 
        /* Get stats out of the card */
-       clear_bit(JOB_WSTATS, &local->flags);
+       clear_bit(JOB_WSTATS, &local->jobs);
        if (local->power.event) {
                up(&local->sem);
                return;
@@ -7565,10 +7736,10 @@ static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
 {
        struct airo_info *local =  dev->priv;
 
-       if (!test_bit(JOB_WSTATS, &local->flags)) {
+       if (!test_bit(JOB_WSTATS, &local->jobs)) {
                /* Get stats out of the card if available */
                if (down_trylock(&local->sem) != 0) {
-                       set_bit(JOB_WSTATS, &local->flags);
+                       set_bit(JOB_WSTATS, &local->jobs);
                        wake_up_interruptible(&local->thr_wait);
                } else
                        airo_read_wireless_stats(local);