+/*
+ * This file contains the softmac's association logic.
+ *
+ * Copyright (c) 2005, 2006 Johannes Berg <johannes@sipsolutions.net>
+ * Joseph Jezak <josejx@gentoo.org>
+ * Larry Finger <Larry.Finger@lwfinger.net>
+ * Danny van Dyk <kugelfang@gentoo.org>
+ * Michael Buesch <mbuesch@freenet.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * The full GNU General Public License is included in this distribution in the
+ * file called COPYING.
+ */
+
#include "ieee80211softmac_priv.h"
/*
ieee80211softmac_assoc(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net)
{
unsigned long flags;
- function_enter();
+
/* Switch to correct channel for this network */
mac->set_channel(mac->dev, net->channel);
/* Set a timer for timeout */
/* FIXME: make timeout configurable */
- queue_delayed_work(mac->workqueue, &mac->associnfo.timeout, 5 * HZ);
+ schedule_delayed_work(&mac->associnfo.timeout, 5 * HZ);
}
void
struct ieee80211softmac_device *mac = (struct ieee80211softmac_device *)d;
unsigned long flags;
- function_enter();
-
spin_lock_irqsave(&mac->lock, flags);
/* we might race against ieee80211softmac_handle_assoc_response,
* so make sure only one of us does something */
ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT, NULL);
}
-static void
-ieee80211softmac_reassoc(struct ieee80211softmac_device *mac)
-{
- function_enter();
-}
-
-
/* Sends out a disassociation request to the desired AP */
static void
ieee80211softmac_disassoc(struct ieee80211softmac_device *mac, u16 reason)
{
unsigned long flags;
struct ieee80211softmac_network *found;
- function_enter();
if (mac->associnfo.bssvalid && mac->associated) {
found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid);
struct ieee80211_network *net = NULL, *best = NULL;
unsigned long flags;
- function_enter();
-
/* meh */
if (mac->associated)
ieee80211softmac_disassoc(mac, WLAN_REASON_DISASSOC_STA_HAS_LEFT);
if (mac->associnfo.bssvalid)
found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid);
- /* Search the ieee80211 networks for this network if we didn't find it */
- if (!found)
+ /* 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
+ * invoked and will scan. */
+ if (!found && (mac->associnfo.scan_retry < IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT))
{
+ s8 rssi = -128; /* if I don't initialise, gcc emits an invalid warning
+ because it cannot follow the best pointer logic. */
spin_lock_irqsave(&mac->ieee->lock, flags);
list_for_each_entry(net, &mac->ieee->network_list, list) {
/* we're supposed to find the network with
* any network with a specific ESSID, and many
* different ones could have that.
*
- * I'll for now implement just finding one at all
+ * I'll for now just go with the reported rssi.
*
* We also should take into account the rateset
* here to find the best BSSID to try.
if (network_matches_request(mac, net)) {
if (!best) {
best = net;
+ rssi = best->stats.rssi;
continue;
}
/* we already had a matching network, so
* compare their properties to get the
* better of the two ... (see above)
*/
- /* TODO */
- /* for now, just */
- break;
+ if (rssi < net->stats.rssi) {
+ best = net;
+ rssi = best->stats.rssi;
+ }
}
}
/* if we unlock here, we might get interrupted and the `best'
* 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 ;)
*/
- dprintk(KERN_INFO PFX "Associate: Network not known, trying to initiate scan: ");
+ dprintk(KERN_INFO PFX "Associate: Scanning for networks first.\n");
ieee80211softmac_notify(mac->dev, IEEE80211SOFTMAC_EVENT_SCAN_FINISHED, ieee80211softmac_assoc_notify, NULL);
if (ieee80211softmac_start_scan(mac))
- dprintk("failed.\n");
- else
- dprintk("ok.\n");
+ dprintk(KERN_INFO PFX "Associate: failed to initiate scan. Is device up?\n");
return;
}
else {
mac->associated = 0;
spin_unlock_irqrestore(&mac->lock, flags);
- dprintk(KERN_INFO PFX "Unable to find network after scan!\n");
+ dprintk(KERN_INFO PFX "Unable to find matching network after scan!\n");
ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND, NULL);
return;
}
if (mac->set_bssid_filter)
mac->set_bssid_filter(mac->dev, net->bssid);
memcpy(mac->ieee->bssid, net->bssid, ETH_ALEN);
- mac->dev->flags |= IFF_RUNNING;
+ netif_carrier_on(mac->dev);
mac->association_id = le16_to_cpup(&resp->aid);
}
network->authenticated = 0;
/* we don't want to do this more than once ... */
network->auth_desynced_once = 1;
- queue_work(mac->workqueue, &mac->associnfo.work);
+ schedule_work(&mac->associnfo.work);
break;
}
default:
{
struct ieee80211softmac_device *mac = ieee80211_priv(dev);
unsigned long flags;
+ if (memcmp(disassoc->header.addr2, mac->associnfo.bssid, ETH_ALEN))
+ return 0;
+ if (memcmp(disassoc->header.addr1, mac->dev->dev_addr, ETH_ALEN))
+ return 0;
dprintk(KERN_INFO PFX "got disassoc frame\n");
-
+ netif_carrier_off(dev);
spin_lock_irqsave(&mac->lock, flags);
mac->associnfo.bssvalid = 0;
mac->associated = 0;
+ schedule_work(&mac->associnfo.work);
spin_unlock_irqrestore(&mac->lock, flags);
return 0;
}
+
+int
+ieee80211softmac_handle_reassoc_req(struct net_device * dev,
+ struct ieee80211_reassoc_request * resp)
+{
+ struct ieee80211softmac_device *mac = ieee80211_priv(dev);
+ struct ieee80211softmac_network *network;
+
+ network = ieee80211softmac_get_network_by_bssid(mac, resp->header.addr3);
+ if (!network) {
+ dprintkl(KERN_INFO PFX "reassoc request from unknown network\n");
+ return 0;
+ }
+ ieee80211softmac_assoc(mac, network);
+ return 0;
+}