Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-drm-fsl-dcu.git] / net / ieee80211 / softmac / ieee80211softmac_assoc.c
index 589f6d2c548a7ba0167598def59daab5b7eb13c4..cc8110bdd5799359e95be983db36ba1616b6dff1 100644 (file)
@@ -30,7 +30,7 @@
  * Overview
  *
  * Before you can associate, you have to authenticate.
- * 
+ *
  */
 
 /* Sends out an association request to the desired AP */
@@ -41,14 +41,14 @@ ieee80211softmac_assoc(struct ieee80211softmac_device *mac, struct ieee80211soft
 
        /* Switch to correct channel for this network */
        mac->set_channel(mac->dev, net->channel);
-       
+
        /* Send association request */
        ieee80211softmac_send_mgt_frame(mac, net, IEEE80211_STYPE_ASSOC_REQ, 0);
-       
+
        dprintk(KERN_INFO PFX "sent association request!\n");
 
        spin_lock_irqsave(&mac->lock, flags);
-       mac->associated = 0; /* just to make sure */
+       mac->associnfo.associated = 0; /* just to make sure */
 
        /* Set a timer for timeout */
        /* FIXME: make timeout configurable */
@@ -58,28 +58,28 @@ ieee80211softmac_assoc(struct ieee80211softmac_device *mac, struct ieee80211soft
 }
 
 void
-ieee80211softmac_assoc_timeout(void *d)
+ieee80211softmac_assoc_timeout(struct work_struct *work)
 {
-       struct ieee80211softmac_device *mac = (struct ieee80211softmac_device *)d;
+       struct ieee80211softmac_device *mac =
+               container_of(work, struct ieee80211softmac_device,
+                            associnfo.timeout.work);
        struct ieee80211softmac_network *n;
-       unsigned long flags;
 
-       spin_lock_irqsave(&mac->lock, flags);
+       mutex_lock(&mac->associnfo.mutex);
        /* we might race against ieee80211softmac_handle_assoc_response,
         * so make sure only one of us does something */
-       if (!mac->associnfo.associating) {
-               spin_unlock_irqrestore(&mac->lock, flags);
-               return;
-       }
+       if (!mac->associnfo.associating)
+               goto out;
        mac->associnfo.associating = 0;
        mac->associnfo.bssvalid = 0;
-       mac->associated = 0;
+       mac->associnfo.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);
+out:
+       mutex_unlock(&mac->associnfo.mutex);
 }
 
 void
@@ -93,7 +93,7 @@ ieee80211softmac_disassoc(struct ieee80211softmac_device *mac)
 
        netif_carrier_off(mac->dev);
 
-       mac->associated = 0;
+       mac->associnfo.associated = 0;
        mac->associnfo.bssvalid = 0;
        mac->associnfo.associating = 0;
        ieee80211softmac_init_bss(mac);
@@ -107,7 +107,7 @@ ieee80211softmac_send_disassoc_req(struct ieee80211softmac_device *mac, u16 reas
 {
        struct ieee80211softmac_network *found;
 
-       if (mac->associnfo.bssvalid && mac->associated) {
+       if (mac->associnfo.bssvalid && mac->associnfo.associated) {
                found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid);
                if (found)
                        ieee80211softmac_send_mgt_frame(mac, found, IEEE80211_STYPE_DISASSOC, reason);
@@ -153,7 +153,7 @@ network_matches_request(struct ieee80211softmac_device *mac, struct ieee80211_ne
        }
 
        /* if 'ANY' network requested, take any that doesn't have privacy enabled */
-       if (mac->associnfo.req_essid.len == 0 
+       if (mac->associnfo.req_essid.len == 0
            && !(net->capability & WLAN_CAPABILITY_PRIVACY))
                return 1;
        if (net->ssid_len != mac->associnfo.req_essid.len)
@@ -167,7 +167,7 @@ static void
 ieee80211softmac_assoc_notify_scan(struct net_device *dev, int event_type, void *context)
 {
        struct ieee80211softmac_device *mac = ieee80211_priv(dev);
-       ieee80211softmac_assoc_work((void*)mac);
+       ieee80211softmac_assoc_work(&mac->associnfo.work.work);
 }
 
 static void
@@ -177,7 +177,7 @@ ieee80211softmac_assoc_notify_auth(struct net_device *dev, int event_type, void
 
        switch (event_type) {
        case IEEE80211SOFTMAC_EVENT_AUTHENTICATED:
-               ieee80211softmac_assoc_work((void*)mac);
+               ieee80211softmac_assoc_work(&mac->associnfo.work.work);
                break;
        case IEEE80211SOFTMAC_EVENT_AUTH_FAILED:
        case IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT:
@@ -188,29 +188,32 @@ ieee80211softmac_assoc_notify_auth(struct net_device *dev, int event_type, void
 
 /* This function is called to handle userspace requests (asynchronously) */
 void
-ieee80211softmac_assoc_work(void *d)
+ieee80211softmac_assoc_work(struct work_struct *work)
 {
-       struct ieee80211softmac_device *mac = (struct ieee80211softmac_device *)d;
+       struct ieee80211softmac_device *mac =
+               container_of(work, struct ieee80211softmac_device,
+                            associnfo.work.work);
        struct ieee80211softmac_network *found = NULL;
        struct ieee80211_network *net = NULL, *best = NULL;
        int bssvalid;
        unsigned long flags;
 
+       mutex_lock(&mac->associnfo.mutex);
+
+       if (!mac->associnfo.associating)
+               goto out;
+
        /* ieee80211_disassoc might clear this */
        bssvalid = mac->associnfo.bssvalid;
 
        /* meh */
-       if (mac->associated)
+       if (mac->associnfo.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);
-
        /* try to find the requested network in our list, if we found one already */
        if (bssvalid || mac->associnfo.bssfixed)
-               found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid);       
-       
+               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,
         * but only if we've scanned at least once (to get a better list of networks to
         * select from). If we have not scanned before, the !found logic below will be
@@ -260,11 +263,9 @@ ieee80211softmac_assoc_work(void *d)
 
        if (!found) {
                if (mac->associnfo.scan_retry > 0) {
-                       spin_lock_irqsave(&mac->lock, flags);
                        mac->associnfo.scan_retry--;
-                       spin_unlock_irqrestore(&mac->lock, flags);
-               
-                       /* We know of no such network. Let's scan. 
+
+                       /* We know of no such network. Let's scan.
                         * NB: this also happens if we had no memory to copy the network info...
                         * Maybe we can hope to have more memory after scanning finishes ;)
                         */
@@ -272,19 +273,17 @@ ieee80211softmac_assoc_work(void *d)
                        ieee80211softmac_notify(mac->dev, IEEE80211SOFTMAC_EVENT_SCAN_FINISHED, ieee80211softmac_assoc_notify_scan, NULL);
                        if (ieee80211softmac_start_scan(mac))
                                dprintk(KERN_INFO PFX "Associate: failed to initiate scan. Is device up?\n");
-                       return;
+                       goto out;
                } else {
-                       spin_lock_irqsave(&mac->lock, flags);
                        mac->associnfo.associating = 0;
-                       mac->associated = 0;
-                       spin_unlock_irqrestore(&mac->lock, flags);
+                       mac->associnfo.associated = 0;
 
                        dprintk(KERN_INFO PFX "Unable to find matching network after scan!\n");
                        /* reset the retry counter for the next user request since we
                         * break out and don't reschedule ourselves after this point. */
                        mac->associnfo.scan_retry = IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT;
                        ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND, NULL);
-                       return;
+                       goto out;
                }
        }
 
@@ -297,7 +296,7 @@ ieee80211softmac_assoc_work(void *d)
        /* copy the ESSID for displaying it */
        mac->associnfo.associate_essid.len = found->essid.len;
        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");
@@ -305,7 +304,7 @@ ieee80211softmac_assoc_work(void *d)
                        mac->associnfo.assoc_wait = 1;
                        ieee80211softmac_notify_internal(mac, IEEE80211SOFTMAC_EVENT_ANY, found, ieee80211softmac_assoc_notify_auth, NULL, GFP_KERNEL);
                }
-               return;
+               goto out;
        }
        if (!found->authenticated && !found->authenticating) {
                /* This relies on the fact that _auth_req only queues the work,
@@ -321,11 +320,14 @@ ieee80211softmac_assoc_work(void *d)
                        mac->associnfo.assoc_wait = 0;
                        ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED, found);
                }
-               return;
+               goto out;
        }
        /* finally! now we can start associating */
        mac->associnfo.assoc_wait = 0;
        ieee80211softmac_assoc(mac, found);
+
+out:
+       mutex_unlock(&mac->associnfo.mutex);
 }
 
 /* call this to do whatever is necessary when we're associated */
@@ -341,7 +343,7 @@ ieee80211softmac_associated(struct ieee80211softmac_device *mac,
        mac->bssinfo.supported_rates = net->supported_rates;
        ieee80211softmac_recalc_txrates(mac);
 
-       mac->associated = 1;
+       mac->associnfo.associated = 1;
 
        mac->associnfo.short_preamble_available =
                (cap & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0;
@@ -351,7 +353,7 @@ ieee80211softmac_associated(struct ieee80211softmac_device *mac,
                mac->set_bssid_filter(mac->dev, net->bssid);
        memcpy(mac->ieee->bssid, net->bssid, ETH_ALEN);
        netif_carrier_on(mac->dev);
-       
+
        mac->association_id = le16_to_cpup(&resp->aid);
 }
 
@@ -372,7 +374,7 @@ ieee80211softmac_handle_assoc_response(struct net_device * dev,
 
        if (unlikely(!mac->running))
                return -ENODEV;
-       
+
        spin_lock_irqsave(&mac->lock, flags);
 
        if (!mac->associnfo.associating) {
@@ -414,21 +416,32 @@ ieee80211softmac_handle_assoc_response(struct net_device * dev,
                                network->authenticated = 0;
                                /* we don't want to do this more than once ... */
                                network->auth_desynced_once = 1;
-                               schedule_work(&mac->associnfo.work);
+                               schedule_delayed_work(&mac->associnfo.work, 0);
                                break;
                        }
                default:
                        dprintk(KERN_INFO PFX "associating failed (reason: 0x%x)!\n", status);
                        mac->associnfo.associating = 0;
                        mac->associnfo.bssvalid = 0;
-                       mac->associated = 0;
+                       mac->associnfo.associated = 0;
                        ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED, network);
        }
-       
+
        spin_unlock_irqrestore(&mac->lock, flags);
        return 0;
 }
 
+void
+ieee80211softmac_try_reassoc(struct ieee80211softmac_device *mac)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&mac->lock, flags);
+       mac->associnfo.associating = 1;
+       schedule_delayed_work(&mac->associnfo.work, 0);
+       spin_unlock_irqrestore(&mac->lock, flags);
+}
+
 int
 ieee80211softmac_handle_disassoc(struct net_device * dev,
                                 struct ieee80211_disassoc *disassoc)
@@ -447,8 +460,7 @@ ieee80211softmac_handle_disassoc(struct net_device * dev,
        dprintk(KERN_INFO PFX "got disassoc frame\n");
        ieee80211softmac_disassoc(mac);
 
-       /* try to reassociate */
-       schedule_work(&mac->associnfo.work);
+       ieee80211softmac_try_reassoc(mac);
 
        return 0;
 }
@@ -468,7 +480,7 @@ ieee80211softmac_handle_reassoc_req(struct net_device * dev,
                dprintkl(KERN_INFO PFX "reassoc request from unknown network\n");
                return 0;
        }
-       schedule_work(&mac->associnfo.work);
+       schedule_delayed_work(&mac->associnfo.work, 0);
 
        return 0;
 }