Revert to Fedora kernel-2.6.17-1.2187_FC5 patched with vs2.0.2.1; there are too many...
[linux-2.6.git] / net / ieee80211 / softmac / ieee80211softmac_assoc.c
index 44215ce..57ea9f6 100644 (file)
@@ -47,7 +47,9 @@ ieee80211softmac_assoc(struct ieee80211softmac_device *mac, struct ieee80211soft
        
        dprintk(KERN_INFO PFX "sent association request!\n");
 
+       /* Change the state to associating */
        spin_lock_irqsave(&mac->lock, flags);
+       mac->associnfo.associating = 1;
        mac->associated = 0; /* just to make sure */
 
        /* Set a timer for timeout */
@@ -61,7 +63,6 @@ void
 ieee80211softmac_assoc_timeout(void *d)
 {
        struct ieee80211softmac_device *mac = (struct ieee80211softmac_device *)d;
-       struct ieee80211softmac_network *n;
        unsigned long flags;
 
        spin_lock_irqsave(&mac->lock, flags);
@@ -74,60 +75,58 @@ ieee80211softmac_assoc_timeout(void *d)
        mac->associnfo.associating = 0;
        mac->associnfo.bssvalid = 0;
        mac->associated = 0;
-
-       n = ieee80211softmac_get_network_by_bssid_locked(mac, mac->associnfo.bssid);
        spin_unlock_irqrestore(&mac->lock, flags);
 
        dprintk(KERN_INFO PFX "assoc request timed out!\n");
-       ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT, n);
-}
-
-void
-ieee80211softmac_disassoc(struct ieee80211softmac_device *mac)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&mac->lock, flags);
-       if (mac->associnfo.associating)
-               cancel_delayed_work(&mac->associnfo.timeout);
-
-       netif_carrier_off(mac->dev);
-
-       mac->associated = 0;
-       mac->associnfo.bssvalid = 0;
-       mac->associnfo.associating = 0;
-       ieee80211softmac_init_txrates(mac);
-       ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_DISASSOCIATED, NULL);
-       spin_unlock_irqrestore(&mac->lock, flags);
+       /* FIXME: we need to know the network here. that requires a bit of restructuring */
+       ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT, NULL);
 }
 
 /* Sends out a disassociation request to the desired AP */
-void
-ieee80211softmac_send_disassoc_req(struct ieee80211softmac_device *mac, u16 reason)
+static void
+ieee80211softmac_disassoc(struct ieee80211softmac_device *mac, u16 reason)
 {
+       unsigned long flags;
        struct ieee80211softmac_network *found;
 
        if (mac->associnfo.bssvalid && mac->associated) {
                found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid);
                if (found)
                        ieee80211softmac_send_mgt_frame(mac, found, IEEE80211_STYPE_DISASSOC, reason);
+       } else if (mac->associnfo.associating) {
+               cancel_delayed_work(&mac->associnfo.timeout);
        }
 
-       ieee80211softmac_disassoc(mac);
+       /* Change our state */
+       spin_lock_irqsave(&mac->lock, flags);
+       /* Do NOT clear bssvalid as that will break ieee80211softmac_assoc_work! */
+       mac->associated = 0;
+       mac->associnfo.associating = 0;
+       ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_DISASSOCIATED, NULL);
+       spin_unlock_irqrestore(&mac->lock, flags);
 }
 
 static inline int
 we_support_all_basic_rates(struct ieee80211softmac_device *mac, u8 *from, u8 from_len)
 {
-       int idx;
-       u8 rate;
+       int idx, search, found;
+       u8 rate, search_rate;
 
        for (idx = 0; idx < (from_len); idx++) {
                rate = (from)[idx];
                if (!(rate & IEEE80211_BASIC_RATE_MASK))
                        continue;
+               found = 0;
                rate &= ~IEEE80211_BASIC_RATE_MASK;
-               if (!ieee80211softmac_ratesinfo_rate_supported(&mac->ratesinfo, rate))
+               for (search = 0; search < mac->ratesinfo.count; search++) {
+                       search_rate = mac->ratesinfo.rates[search];
+                       search_rate &= ~IEEE80211_BASIC_RATE_MASK;
+                       if (rate == search_rate) {
+                               found = 1;
+                               break;
+                       }
+               }
+               if (!found)
                        return 0;
        }
        return 1;
@@ -164,28 +163,12 @@ network_matches_request(struct ieee80211softmac_device *mac, struct ieee80211_ne
 }
 
 static void
-ieee80211softmac_assoc_notify_scan(struct net_device *dev, int event_type, void *context)
+ieee80211softmac_assoc_notify(struct net_device *dev, void *context)
 {
        struct ieee80211softmac_device *mac = ieee80211_priv(dev);
        ieee80211softmac_assoc_work((void*)mac);
 }
 
-static void
-ieee80211softmac_assoc_notify_auth(struct net_device *dev, int event_type, void *context)
-{
-       struct ieee80211softmac_device *mac = ieee80211_priv(dev);
-
-       switch (event_type) {
-       case IEEE80211SOFTMAC_EVENT_AUTHENTICATED:
-               ieee80211softmac_assoc_work((void*)mac);
-               break;
-       case IEEE80211SOFTMAC_EVENT_AUTH_FAILED:
-       case IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT:
-               ieee80211softmac_disassoc(mac);
-               break;
-       }
-}
-
 /* This function is called to handle userspace requests (asynchronously) */
 void
 ieee80211softmac_assoc_work(void *d)
@@ -193,22 +176,14 @@ ieee80211softmac_assoc_work(void *d)
        struct ieee80211softmac_device *mac = (struct ieee80211softmac_device *)d;
        struct ieee80211softmac_network *found = NULL;
        struct ieee80211_network *net = NULL, *best = NULL;
-       int bssvalid;
        unsigned long flags;
-
-       /* ieee80211_disassoc might clear this */
-       bssvalid = mac->associnfo.bssvalid;
-
+       
        /* meh */
        if (mac->associated)
-               ieee80211softmac_send_disassoc_req(mac, WLAN_REASON_DISASSOC_STA_HAS_LEFT);
-
-       spin_lock_irqsave(&mac->lock, flags);
-       mac->associnfo.associating = 1;
-       spin_unlock_irqrestore(&mac->lock, flags);
+               ieee80211softmac_disassoc(mac, WLAN_REASON_DISASSOC_STA_HAS_LEFT);
 
        /* try to find the requested network in our list, if we found one already */
-       if (bssvalid || mac->associnfo.bssfixed)
+       if (mac->associnfo.bssvalid || mac->associnfo.bssfixed)
                found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid);       
        
        /* Search the ieee80211 networks for this network if we didn't find it by bssid,
@@ -269,7 +244,7 @@ ieee80211softmac_assoc_work(void *d)
                         * Maybe we can hope to have more memory after scanning finishes ;)
                         */
                        dprintk(KERN_INFO PFX "Associate: Scanning for networks first.\n");
-                       ieee80211softmac_notify(mac->dev, IEEE80211SOFTMAC_EVENT_SCAN_FINISHED, ieee80211softmac_assoc_notify_scan, NULL);
+                       ieee80211softmac_notify(mac->dev, IEEE80211SOFTMAC_EVENT_SCAN_FINISHED, ieee80211softmac_assoc_notify, NULL);
                        if (ieee80211softmac_start_scan(mac))
                                dprintk(KERN_INFO PFX "Associate: failed to initiate scan. Is device up?\n");
                        return;
@@ -299,32 +274,19 @@ ieee80211softmac_assoc_work(void *d)
        memcpy(mac->associnfo.associate_essid.data, found->essid.data, IW_ESSID_MAX_SIZE + 1);
        
        /* we found a network! authenticate (if necessary) and associate to it. */
-       if (found->authenticating) {
-               dprintk(KERN_INFO PFX "Already requested authentication, waiting...\n");
-               if(!mac->associnfo.assoc_wait) {
-                       mac->associnfo.assoc_wait = 1;
-                       ieee80211softmac_notify_internal(mac, IEEE80211SOFTMAC_EVENT_ANY, found, ieee80211softmac_assoc_notify_auth, NULL, GFP_KERNEL);
-               }
-               return;
-       }
-       if (!found->authenticated && !found->authenticating) {
+       if (!found->authenticated) {
                /* This relies on the fact that _auth_req only queues the work,
                 * otherwise adding the notification would be racy. */
                if (!ieee80211softmac_auth_req(mac, found)) {
-                       if(!mac->associnfo.assoc_wait) {
-                               dprintk(KERN_INFO PFX "Cannot associate without being authenticated, requested authentication\n");
-                               mac->associnfo.assoc_wait = 1;
-                               ieee80211softmac_notify_internal(mac, IEEE80211SOFTMAC_EVENT_ANY, found, ieee80211softmac_assoc_notify_auth, NULL, GFP_KERNEL);
-                       }
+                       dprintk(KERN_INFO PFX "cannot associate without being authenticated, requested authentication\n");
+                       ieee80211softmac_notify_internal(mac, IEEE80211SOFTMAC_EVENT_ANY, found, ieee80211softmac_assoc_notify, NULL, GFP_KERNEL);
                } else {
                        printkl(KERN_WARNING PFX "Not authenticated, but requesting authentication failed. Giving up to associate\n");
-                       mac->associnfo.assoc_wait = 0;
                        ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED, found);
                }
                return;
        }
        /* finally! now we can start associating */
-       mac->associnfo.assoc_wait = 0;
        ieee80211softmac_assoc(mac, found);
 }
 
@@ -335,9 +297,6 @@ ieee80211softmac_associated(struct ieee80211softmac_device *mac,
        struct ieee80211softmac_network *net)
 {
        mac->associnfo.associating = 0;
-       mac->associnfo.supported_rates = net->supported_rates;
-       ieee80211softmac_recalc_txrates(mac);
-
        mac->associated = 1;
        if (mac->set_bssid_filter)
                mac->set_bssid_filter(mac->dev, net->bssid);
@@ -421,6 +380,7 @@ ieee80211softmac_handle_disassoc(struct net_device * dev,
                                 struct ieee80211_disassoc *disassoc)
 {
        struct ieee80211softmac_device *mac = ieee80211_priv(dev);
+       unsigned long flags;
 
        if (unlikely(!mac->running))
                return -ENODEV;
@@ -432,11 +392,14 @@ ieee80211softmac_handle_disassoc(struct net_device * dev,
                return 0;
 
        dprintk(KERN_INFO PFX "got disassoc frame\n");
-       ieee80211softmac_disassoc(mac);
-
-       /* try to reassociate */
+       netif_carrier_off(dev);
+       spin_lock_irqsave(&mac->lock, flags);
+       mac->associnfo.bssvalid = 0;
+       mac->associated = 0;
+       ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_DISASSOCIATED, NULL);
        schedule_work(&mac->associnfo.work);
-
+       spin_unlock_irqrestore(&mac->lock, flags);
+       
        return 0;
 }