/*
* cfg80211 scan result handling
*
* Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/wireless.h>
#include <linux/nl80211.h>
#include <linux/etherdevice.h>
#include <net/arp.h>
#include <net/cfg80211.h>
#include <net/iw_handler.h>
#include "core.h"
#include "nl80211.h"
#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted)
{
struct net_device *dev;
#ifdef CONFIG_WIRELESS_EXT
union iwreq_data wrqu;
#endif
dev = dev_get_by_index(&init_net, request->ifidx);
if (!dev)
goto out;
WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req);
wiphy_to_dev(request->wiphy)->scan_req = NULL;
if (aborted)
nl80211_send_scan_aborted(wiphy_to_dev(request->wiphy), dev);
else
nl80211_send_scan_done(wiphy_to_dev(request->wiphy), dev);
#ifdef CONFIG_WIRELESS_EXT
if (!aborted) {
memset(&wrqu, 0, sizeof(wrqu));
wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
}
#endif
dev_put(dev);
out:
kfree(request);
}
EXPORT_SYMBOL(cfg80211_scan_done);
static void bss_release(struct kref *ref)
{
struct cfg80211_internal_bss *bss;
bss = container_of(ref, struct cfg80211_internal_bss, ref);
if (bss->pub.free_priv)
bss->pub.free_priv(&bss->pub);
kfree(bss);
}
/* must hold dev->bss_lock! */
void cfg80211_bss_age(struct cfg80211_registered_device *dev,
unsigned long age_secs)
{
struct cfg80211_internal_bss *bss;
unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC);
list_for_each_entry(bss, &dev->bss_list, list) {
bss->ts -= age_jiffies;
}
}
/* must hold dev->bss_lock! */
void cfg80211_bss_expire(struct cfg80211_registered_device *dev)
{
struct cfg80211_internal_bss *bss, *tmp;
bool expired = false;
list_for_each_entry_safe(bss, tmp, &dev->bss_list, list) {
if (!time_after(jiffies, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE))
continue;
list_del(&bss->list);
rb_erase(&bss->rbn, &dev->bss_tree);
kref_put(&bss->ref, bss_release);
expired = true;
}
if (expired)
dev->bss_generation++;
}
static u8 *find_ie(u8 num, u8 *ies, size_t len)
{
while (len > 2 && ies[0] != num) {
len -= ies[1] + 2;
ies += ies[1] + 2;
}
if (len < 2)
return NULL;
if (len < 2 + ies[1])
return NULL;
return ies;
}
static int cmp_ies(u8 num, u8 *ies1, size_t len1, u8 *ies2, size_t len2)
{
const u8 *ie1 = find_ie(num, ies1, len1);
const u8 *ie2 = find_ie(num, ies2, len2);
int r;
if (!ie1 && !ie2)
return 0;
if (!ie1)
return -1;
r = memcmp(ie1 + 2, ie2 + 2, min(ie1[1], ie2[1]));
if (r == 0 && ie1[1] != ie2[1])
return ie2[1] - ie1[1];
return r;
}
static bool is_bss(struct cfg80211_bss *a,
const u8 *bssid,
const u8 *ssid, size_t ssid_len)
{
const u8 *ssidie;
if (bssid && compare_ether_addr(a->bssid, bssid))
return false;
if (!ssid)
return true;
ssidie = find_ie(WLAN_EID_SSID,
a->information_elements,
a->len_information_elements);
if (!ssidie)
return false;
if (ssidie[1] != ssid_len)
return false;
return memcmp(ssidie + 2, ssid, ssid_len) == 0;
}
static bool is_mesh(struct cfg80211_bss *a,
const u8 *meshid, size_t meshidlen,
const u8 *meshcfg)
{
const u8 *ie;
if (!is_zero_ether_addr(a->bssid))
return false;
ie = find_ie(WLAN_EID_MESH_ID,
a->information_elements,
a->len_information_elements);
if (!ie)
return false;
if (ie[1] != meshidlen)
<