Added support for AP mode scan results to be updated and returned to

wireless tools and other clients.  This fixes:

bgscan
iwlist <iface> scan
wlanconfig <iface> list scan
wlanconfig <iface> list peers

etc...




git-svn-id: http://madwifi-project.org/svn/madwifi/trunk@2724 0192ed92-7a03-0410-a25b-9323aeb14dbd
This commit is contained in:
mtaylor 2007-10-05 05:52:42 +00:00
parent 2c0d8db912
commit d9ca43629b
2 changed files with 464 additions and 102 deletions

View File

@ -51,8 +51,67 @@
#include <net80211/ieee80211_var.h> #include <net80211/ieee80211_var.h>
#define AP_PURGE_SCANS 2 /* age for purging entries (scans) */
#define RSSI_LPF_LEN 10
#define RSSI_EP_MULTIPLIER (1<<7) /* pow2 to optimize out * and / */
#define RSSI_IN(x) ((x) * RSSI_EP_MULTIPLIER)
#define LPF_RSSI(x, y, len) (((x) * ((len) - 1) + (y)) / (len))
#define RSSI_LPF(x, y) do { \
if ((y) >= -20) \
x = LPF_RSSI((x), RSSI_IN((y)), RSSI_LPF_LEN); \
} while (0)
#define EP_RND(x, mul) \
((((x)%(mul)) >= ((mul)/2)) ? howmany(x, mul) : (x)/(mul))
#define RSSI_GET(x) EP_RND(x, RSSI_EP_MULTIPLIER)
#define AP_HASHSIZE 32
/* simple hash is enough for variation of macaddr */
#define AP_HASH(addr) \
(((const u_int8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % AP_HASHSIZE)
#define SCAN_AP_LOCK_INIT(_st, _name) \
spin_lock_init(&(_st)->as_lock)
#define SCAN_AP_LOCK_DESTROY(_st)
#define SCAN_AP_LOCK_IRQ(_st) do { \
unsigned long __stlockflags; \
spin_lock_irqsave(&(_st)->as_lock, __stlockflags);
#define SCAN_AP_UNLOCK_IRQ(_st) \
spin_unlock_irqrestore(&(_st)->as_lock, __stlockflags); \
} while (0)
#define SCAN_AP_UNLOCK_IRQ_EARLY(_st) \
spin_unlock_irqrestore(&(_st)->as_lock, __stlockflags);
#define SCAN_AP_GEN_LOCK_INIT(_st, _name) \
spin_lock_init(&(_st)->as_scanlock)
#define SCAN_AP_GEN_LOCK_DESTROY(_st)
#define SCAN_AP_GEN_LOCK(_st) spin_lock(&(_st)->as_scanlock);
#define SCAN_AP_GEN_UNLOCK(_st) spin_unlock(&(_st)->as_scanlock);
struct scan_entry {
struct ieee80211_scan_entry base;
TAILQ_ENTRY(scan_entry) se_list;
LIST_ENTRY(scan_entry) se_hash;
u_int8_t se_seen; /* seen during current scan */
u_int8_t se_notseen; /* not seen in previous scans */
u_int32_t se_avgrssi; /* LPF rssi state */
unsigned long se_lastupdate; /* time of last update */
unsigned long se_lastfail; /* time of last failure */
unsigned long se_lastassoc; /* time of last association */
u_int se_scangen; /* iterator scan gen# */
};
struct ap_state { struct ap_state {
int as_maxrssi[IEEE80211_CHAN_MAX]; unsigned int as_vap_desired_mode; /* Used for channel selection, vap->iv_des_mode */
unsigned int as_required_mode; /* Used for channel selection, filtered version of as_vap_desired_mode */
int as_maxrssi[IEEE80211_CHAN_MAX]; /* Used for channel selection */
/* These fields are just for scan caching for returning responses to
* wireless extensions. i.e. show peers, APs, etc. */
spinlock_t as_lock; /* on scan table */
int as_newscan; /* trigger for updating seen/not-seen for aging */
TAILQ_HEAD(, scan_entry) as_entry; /* all entries */
ATH_LIST_HEAD(, scan_entry) as_hash[AP_HASHSIZE];
spinlock_t as_scanlock; /* on as_scangen */
u_int as_scangen; /* gen# for iterator */
struct IEEE80211_TQ_STRUCT as_actiontq; /* tasklet for "action" */ struct IEEE80211_TQ_STRUCT as_actiontq; /* tasklet for "action" */
struct ieee80211_scan_entry as_selbss; /* selected bss for action tasklet */ struct ieee80211_scan_entry as_selbss; /* selected bss for action tasklet */
int (*as_action)(struct ieee80211vap *, const struct ieee80211_scan_entry *); int (*as_action)(struct ieee80211vap *, const struct ieee80211_scan_entry *);
@ -60,6 +119,128 @@ struct ap_state {
static int ap_flush(struct ieee80211_scan_state *); static int ap_flush(struct ieee80211_scan_state *);
static void action_tasklet(IEEE80211_TQUEUE_ARG); static void action_tasklet(IEEE80211_TQUEUE_ARG);
static struct ieee80211_channel *find11gchannel(struct ieee80211com *ic, int i, int freq);
static const u_int chanflags[] = {
IEEE80211_CHAN_B, /* IEEE80211_MODE_AUTO */
IEEE80211_CHAN_A, /* IEEE80211_MODE_11A */
IEEE80211_CHAN_B, /* IEEE80211_MODE_11B */
IEEE80211_CHAN_PUREG, /* IEEE80211_MODE_11G */
IEEE80211_CHAN_FHSS, /* IEEE80211_MODE_FH */
IEEE80211_CHAN_A, /* IEEE80211_MODE_TURBO_A */ /* for turbo mode look for AP in normal channel */
IEEE80211_CHAN_PUREG, /* IEEE80211_MODE_TURBO_G */
IEEE80211_CHAN_ST, /* IEEE80211_MODE_TURBO_STATIC_A */
};
static const u_int16_t rcl1[] = /* 8 FCC channel: 52, 56, 60, 64, 36, 40, 44, 48 */
{ 5260, 5280, 5300, 5320, 5180, 5200, 5220, 5240 };
static const u_int16_t rcl2[] = /* 4 MKK channels: 34, 38, 42, 46 */
{ 5170, 5190, 5210, 5230 };
static const u_int16_t rcl3[] = /* 2.4Ghz ch: 1,6,11,7,13 */
{ 2412, 2437, 2462, 2442, 2472 };
static const u_int16_t rcl4[] = /* 5 FCC channel: 149, 153, 161, 165 */
{ 5745, 5765, 5785, 5805, 5825 };
static const u_int16_t rcl7[] = /* 11 ETSI channel: 100,104,108,112,116,120,124,128,132,136,140 */
{ 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680, 5700 };
static const u_int16_t rcl8[] = /* 2.4Ghz ch: 2,3,4,5,8,9,10,12 */
{ 2417, 2422, 2427, 2432, 2447, 2452, 2457, 2467 };
static const u_int16_t rcl9[] = /* 2.4Ghz ch: 14 */
{ 2484 };
static const u_int16_t rcl10[] = /* Added Korean channels 2312-2372 */
{ 2312, 2317, 2322, 2327, 2332, 2337, 2342, 2347, 2352, 2357, 2362, 2367, 2372 };
static const u_int16_t rcl11[] = /* Added Japan channels in 4.9/5.0 spectrum */
{ 5040, 5060, 5080, 4920, 4940, 4960, 4980 };
#ifdef ATH_TURBO_SCAN
static const u_int16_t rcl5[] = /* 3 static turbo channels */
{ 5210, 5250, 5290 };
static const u_int16_t rcl6[] = /* 2 static turbo channels */
{ 5760, 5800 };
static const u_int16_t rcl6x[] = /* 4 FCC3 turbo channels */
{ 5540, 5580, 5620, 5660 };
static const u_int16_t rcl12[] = /* 2.4Ghz Turbo channel 6 */
{ 2437 };
static const u_int16_t rcl13[] = /* dynamic Turbo channels */
{ 5200, 5240, 5280, 5765, 5805 };
#endif /* ATH_TURBO_SCAN */
struct scanlist {
u_int16_t mode;
u_int16_t count;
const u_int16_t *list;
};
#define IEEE80211_MODE_TURBO_STATIC_A IEEE80211_MODE_MAX
#define X(a) .count = sizeof(a)/sizeof(a[0]), .list = a
static const struct scanlist staScanTable[] = {
{ IEEE80211_MODE_11B, X(rcl3) },
{ IEEE80211_MODE_11A, X(rcl1) },
{ IEEE80211_MODE_11A, X(rcl2) },
{ IEEE80211_MODE_11B, X(rcl8) },
{ IEEE80211_MODE_11B, X(rcl9) },
{ IEEE80211_MODE_11A, X(rcl4) },
#ifdef ATH_TURBO_SCAN
{ IEEE80211_MODE_TURBO_STATIC_A, X(rcl5) },
{ IEEE80211_MODE_TURBO_STATIC_A, X(rcl6) },
{ IEEE80211_MODE_TURBO_A, X(rcl6x) },
{ IEEE80211_MODE_TURBO_A, X(rcl13) },
#endif /* ATH_TURBO_SCAN */
{ IEEE80211_MODE_11A, X(rcl7) },
{ IEEE80211_MODE_11B, X(rcl10) },
{ IEEE80211_MODE_11A, X(rcl11) },
#ifdef ATH_TURBO_SCAN
{ IEEE80211_MODE_TURBO_G, X(rcl12) },
#endif /* ATH_TURBO_SCAN */
{ .list = NULL }
};
#undef X
/* This function must be invoked with locks acquired */
static void
add_channels(struct ieee80211com *ic,
struct ieee80211_scan_state *ss,
enum ieee80211_phymode mode, const u_int16_t freq[], int nfreq)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
struct ieee80211_channel *c, *cg;
u_int modeflags;
int i;
KASSERT(mode < N(chanflags), ("Unexpected mode %u", mode));
modeflags = chanflags[mode];
for (i = 0; i < nfreq; i++) {
c = ieee80211_find_channel(ic, freq[i], modeflags);
if (c == NULL || isclr(ic->ic_chan_active, c->ic_ieee))
continue;
if (mode == IEEE80211_MODE_AUTO) {
/*
* XXX special-case 11b/g channels so we select
* the g channel if both are present.
*/
if (IEEE80211_IS_CHAN_B(c) &&
(cg = find11gchannel(ic, i, c->ic_freq)) != NULL)
c = cg;
}
if (ss->ss_last >= IEEE80211_SCAN_MAX)
break;
ss->ss_chans[ss->ss_last++] = c;
}
#undef N
}
/* This function must be invoked with locks acquired */
static int
checktable(const struct scanlist *scan, const struct ieee80211_channel *c)
{
int i;
for (; scan->list != NULL; scan++) {
for (i = 0; i < scan->count; i++)
if (scan->list[i] == c->ic_freq)
return 1;
}
return 0;
}
/* /*
* Attach prior to any scanning work. * Attach prior to any scanning work.
@ -72,9 +253,14 @@ ap_attach(struct ieee80211_scan_state *ss)
_MOD_INC_USE(THIS_MODULE, return 0); _MOD_INC_USE(THIS_MODULE, return 0);
MALLOC(as, struct ap_state *, sizeof(struct ap_state), MALLOC(as, struct ap_state *, sizeof(struct ap_state),
M_SCANCACHE, M_NOWAIT); M_80211_SCAN, M_NOWAIT | M_ZERO);
ss->ss_priv = as; if (as == NULL)
return 0;
SCAN_AP_LOCK_INIT(as, "scan_ap");
SCAN_AP_GEN_LOCK_INIT(as, "scan_ap_gen");
TAILQ_INIT(&as->as_entry);
IEEE80211_INIT_TQUEUE(&as->as_actiontq, action_tasklet, ss); IEEE80211_INIT_TQUEUE(&as->as_actiontq, action_tasklet, ss);
ss->ss_priv = as;
ap_flush(ss); ap_flush(ss);
return 1; return 1;
} }
@ -87,8 +273,11 @@ ap_detach(struct ieee80211_scan_state *ss)
{ {
struct ap_state *as = ss->ss_priv; struct ap_state *as = ss->ss_priv;
if (as != NULL) if (as != NULL) {
FREE(as, M_SCANCACHE); ap_flush(ss);
IEEE80211_CANCEL_TQUEUE(&as->as_actiontq);
FREE(as, M_80211_SCAN);
}
_MOD_DEC_USE(THIS_MODULE); _MOD_DEC_USE(THIS_MODULE);
return 1; return 1;
@ -101,16 +290,35 @@ static int
ap_flush(struct ieee80211_scan_state *ss) ap_flush(struct ieee80211_scan_state *ss)
{ {
struct ap_state *as = ss->ss_priv; struct ap_state *as = ss->ss_priv;
struct scan_entry *se, *next;
SCAN_AP_LOCK_IRQ(as);
memset(as->as_maxrssi, 0, sizeof(as->as_maxrssi)); memset(as->as_maxrssi, 0, sizeof(as->as_maxrssi));
TAILQ_FOREACH_SAFE(se, &as->as_entry, se_list, next) {
TAILQ_REMOVE(&as->as_entry, se, se_list);
LIST_REMOVE(se, se_hash);
FREE(se, M_80211_SCAN);
}
ss->ss_last = 0; /* ensure no channel will be picked */ ss->ss_last = 0; /* ensure no channel will be picked */
SCAN_AP_UNLOCK_IRQ(as);
return 0; return 0;
} }
static int /* This function must be invoked with locks acquired */
static void
saveie(u_int8_t **iep, const u_int8_t *ie)
{
if (ie == NULL)
*iep = NULL;
else
ieee80211_saveie(iep, ie);
}
/* This function must be invoked with locks acquired */
static struct ieee80211_channel *
find11gchannel(struct ieee80211com *ic, int i, int freq) find11gchannel(struct ieee80211com *ic, int i, int freq)
{ {
const struct ieee80211_channel *c; struct ieee80211_channel *c;
int j; int j;
/* /*
@ -121,14 +329,14 @@ find11gchannel(struct ieee80211com *ic, int i, int freq)
for (j = i+1; j < ic->ic_nchans; j++) { for (j = i+1; j < ic->ic_nchans; j++) {
c = &ic->ic_channels[j]; c = &ic->ic_channels[j];
if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c)) if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c))
return 1; return c;
} }
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
c = &ic->ic_channels[j]; c = &ic->ic_channels[j];
if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c)) if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c))
return 1; return c;
} }
return 0; return NULL;
} }
/* /*
@ -137,75 +345,89 @@ find11gchannel(struct ieee80211com *ic, int i, int freq)
static int static int
ap_start(struct ieee80211_scan_state *ss, struct ieee80211vap *vap) ap_start(struct ieee80211_scan_state *ss, struct ieee80211vap *vap)
{ {
struct ieee80211com *ic = vap->iv_ic; struct ap_state *as = ss->ss_priv;
struct ieee80211_channel *c; struct ieee80211com *ic = NULL;
const struct scanlist *sl = NULL;
struct ieee80211_channel *c = NULL;
int i; int i;
unsigned int mode = 0;
SCAN_AP_LOCK_IRQ(as);
ic = vap->iv_ic;
/* Determine mode flags to match, or leave zero for auto mode */
as->as_vap_desired_mode = vap->iv_des_mode;
as->as_required_mode = 0;
if (as->as_vap_desired_mode != IEEE80211_MODE_AUTO) {
as->as_required_mode = chanflags[as->as_vap_desired_mode];
if (vap->iv_ath_cap & IEEE80211_ATHC_TURBOP &&
as->as_required_mode != IEEE80211_CHAN_ST) {
/* Fixup for dynamic turbo flags */
if (as->as_vap_desired_mode == IEEE80211_MODE_11G)
as->as_required_mode = IEEE80211_CHAN_108G;
else
as->as_required_mode = IEEE80211_CHAN_108A;
}
}
ss->ss_last = 0; ss->ss_last = 0;
if (vap->iv_des_mode == IEEE80211_MODE_AUTO) { /* Use the table of ordered channels to construct the list
for (i = 0; i < ic->ic_nchans; i++) { * of channels for scanning. Any channels in the ordered
c = &ic->ic_channels[i]; * list not in the master list will be discarded. */
if (IEEE80211_IS_CHAN_TURBO(c)) { for (sl = staScanTable; sl->list != NULL; sl++) {
/* XR is not supported on turbo channels */ mode = sl->mode;
if (vap->iv_ath_cap & IEEE80211_ATHC_XR) /* The scan table marks 2.4Ghz channels as b
continue; * so if the desired mode is 11g, then use
/* dynamic channels are scanned in base mode */ * the 11b channel list but upgrade the mode. */
if (!IEEE80211_IS_CHAN_ST(c)) if (as->as_vap_desired_mode &&
continue; as->as_vap_desired_mode != mode &&
} else { as->as_vap_desired_mode == IEEE80211_MODE_11G &&
/* mode == IEEE80211_MODE_11B)
* Use any 11g channel instead of 11b one. mode = IEEE80211_MODE_11G;
*/ /* If we are in "AUTO" mode, upgrade the mode to auto.
if (IEEE80211_IS_CHAN_B(c) && * This lets add_channels upgrade an 11b channel to
find11gchannel(ic, i, c->ic_freq)) * 11g if available. */
continue; if(!as->as_vap_desired_mode && mode == IEEE80211_MODE_11B)
} mode = IEEE80211_MODE_AUTO;
if (c->ic_flags & IEEE80211_CHAN_RADAR) /* Add the list of the channels; any that are not
continue; * in the master channel list will be discarded. */
if (ss->ss_last >= IEEE80211_SCAN_MAX) add_channels(ic, ss, mode, sl->list, sl->count);
break; }
ss->ss_chans[ss->ss_last++] = c;
}
} else {
static const u_int chanflags[] = {
0, /* IEEE80211_MODE_AUTO */
IEEE80211_CHAN_A, /* IEEE80211_MODE_11A */
IEEE80211_CHAN_B, /* IEEE80211_MODE_11B */
IEEE80211_CHAN_PUREG, /* IEEE80211_MODE_11G */
IEEE80211_CHAN_FHSS, /* IEEE80211_MODE_FH */
IEEE80211_CHAN_108A, /* IEEE80211_MODE_TURBO_A */
IEEE80211_CHAN_108G, /* IEEE80211_MODE_TURBO_G */
IEEE80211_CHAN_ST, /* IEEE80211_MODE_TURBO_STATIC_A */
};
u_int modeflags;
modeflags = chanflags[vap->iv_des_mode]; /*
if (vap->iv_ath_cap & IEEE80211_ATHC_TURBOP && modeflags != IEEE80211_CHAN_ST) { * Add the channels from the ic (from HAL) that are not present
if (vap->iv_des_mode == IEEE80211_MODE_11G) * in the staScanTable, assuming they pass the sanity checks...
modeflags = IEEE80211_CHAN_108G; */
else for (i = 0; i < ic->ic_nchans; i++) {
modeflags = IEEE80211_CHAN_108A; c = &ic->ic_channels[i];
} /* XR is not supported on turbo channels */
for (i = 0; i < ic->ic_nchans; i++) { if (IEEE80211_IS_CHAN_TURBO(c) && vap->iv_flags & IEEE80211_F_XR)
c = &ic->ic_channels[i]; continue;
if ((c->ic_flags & modeflags) != modeflags)
continue; /* Dynamic channels are scanned in base mode */
/* XR is not supported on turbo channels */ if (!as->as_required_mode && !IEEE80211_IS_CHAN_ST(c))
if (IEEE80211_IS_CHAN_TURBO(c) && vap->iv_ath_cap & IEEE80211_ATHC_XR) continue;
continue;
if (ss->ss_last >= IEEE80211_SCAN_MAX) /* Use any 11g channel instead of 11b one. */
break; if (vap->iv_des_mode == IEEE80211_MODE_AUTO &&
/* IEEE80211_IS_CHAN_B(c) &&
* do not select static turbo channels if the mode is not find11gchannel(ic, i, c->ic_freq))
* static turbo . continue;
*/
if (IEEE80211_IS_CHAN_STURBO(c) && vap->iv_des_mode != IEEE80211_MODE_MAX ) /* Do not add channels already put into the scan list by the
continue; * scan table - these have already been filtered by mode
/* No dfs interference detected channels */ * and for whether they are in the active channel list. */
if (c->ic_flags & IEEE80211_CHAN_RADAR) if (checktable(staScanTable, c))
continue; continue;
ss->ss_chans[ss->ss_last++] = c;
} /* Make sure the channel is active */
if (c == NULL || isclr(ic->ic_chan_active, c->ic_ieee))
continue;
/* Don't overrun */
if (ss->ss_last >= IEEE80211_SCAN_MAX)
break;
ss->ss_chans[ss->ss_last++] = c;
} }
ss->ss_next = 0; ss->ss_next = 0;
/* XXX tunables */ /* XXX tunables */
@ -221,6 +443,8 @@ ap_start(struct ieee80211_scan_state *ss, struct ieee80211vap *vap)
} }
#endif /* IEEE80211_DEBUG */ #endif /* IEEE80211_DEBUG */
as->as_newscan = 1;
SCAN_AP_UNLOCK_IRQ(as);
return 0; return 0;
} }
@ -230,6 +454,8 @@ ap_start(struct ieee80211_scan_state *ss, struct ieee80211vap *vap)
static int static int
ap_restart(struct ieee80211_scan_state *ss, struct ieee80211vap *vap) ap_restart(struct ieee80211_scan_state *ss, struct ieee80211vap *vap)
{ {
struct ap_state *as = ss->ss_priv;
as->as_newscan = 1;
return 0; return 0;
} }
@ -240,7 +466,6 @@ static int
ap_cancel(struct ieee80211_scan_state *ss, struct ieee80211vap *vap) ap_cancel(struct ieee80211_scan_state *ss, struct ieee80211vap *vap)
{ {
struct ap_state *as = ss->ss_priv; struct ap_state *as = ss->ss_priv;
IEEE80211_CANCEL_TQUEUE(&as->as_actiontq); IEEE80211_CANCEL_TQUEUE(&as->as_actiontq);
return 0; return 0;
} }
@ -252,17 +477,92 @@ static int
ap_add(struct ieee80211_scan_state *ss, const struct ieee80211_scanparams *sp, ap_add(struct ieee80211_scan_state *ss, const struct ieee80211_scanparams *sp,
const struct ieee80211_frame *wh, int subtype, int rssi, u_int64_t rtsf) const struct ieee80211_frame *wh, int subtype, int rssi, u_int64_t rtsf)
{ {
struct ap_state *as = ss->ss_priv; struct ap_state *as = ss->ss_priv;
struct ieee80211vap *vap = ss->ss_vap; const u_int8_t *macaddr = wh->i_addr2;
struct ieee80211com *ic = vap->iv_ic; struct ieee80211vap *vap = NULL;
int chan; struct ieee80211com *ic = NULL;
struct scan_entry *se = NULL;
struct ieee80211_scan_entry *ise = NULL;
int hash;
int chan = 0;
chan = ieee80211_chan2ieee(ic, ic->ic_curchan); /* This section provides scan results to wireless extensions */
/* XXX better quantification of channel use? */ SCAN_AP_LOCK_IRQ(as);
/* XXX: count BSSs? */ /* This is the only information used for channel selection by AP */
if (rssi > as->as_maxrssi[chan]) if (rssi > as->as_maxrssi[chan])
as->as_maxrssi[chan] = rssi; as->as_maxrssi[chan] = rssi;
/* XXX interference, turbo requirements */ vap = ss->ss_vap;
ic = vap->iv_ic;
hash = AP_HASH(macaddr);
chan = ieee80211_chan2ieee(ic, ic->ic_curchan);
LIST_FOREACH(se, &as->as_hash[hash], se_hash)
if (IEEE80211_ADDR_EQ(se->base.se_macaddr, macaddr) &&
sp->ssid[1] == se->base.se_ssid[1] &&
!memcmp(se->base.se_ssid+2, sp->ssid+2, se->base.se_ssid[1]))
goto found;
MALLOC(se, struct scan_entry *, sizeof(struct scan_entry),
M_80211_SCAN, M_NOWAIT | M_ZERO);
if (se == NULL) {
SCAN_AP_UNLOCK_IRQ_EARLY(as);
return 0;
}
se->se_scangen = as->as_scangen-1;
IEEE80211_ADDR_COPY(se->base.se_macaddr, macaddr);
TAILQ_INSERT_TAIL(&as->as_entry, se, se_list);
LIST_INSERT_HEAD(&as->as_hash[hash], se, se_hash);
found:
ise = &se->base;
/* XXX ap beaconing multiple ssid w/ same bssid */
if (sp->ssid[1] != 0 &&
((subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) || ise->se_ssid[1] == 0))
{
memcpy(ise->se_ssid, sp->ssid, 2 + sp->ssid[1]);
}
KASSERT(sp->rates[1] <= IEEE80211_RATE_MAXSIZE,
("rate set too large: %u", sp->rates[1]));
memcpy(ise->se_rates, sp->rates, 2 + sp->rates[1]);
if (sp->xrates != NULL) {
/* XXX validate xrates[1] */
KASSERT(sp->xrates[1] <= IEEE80211_RATE_MAXSIZE,
("xrate set too large: %u", sp->xrates[1]));
memcpy(ise->se_xrates, sp->xrates, 2 + sp->xrates[1]);
} else
ise->se_xrates[1] = 0;
IEEE80211_ADDR_COPY(ise->se_bssid, wh->i_addr3);
/*
* Record rssi data using extended precision LPF filter.
*/
if (se->se_lastupdate == 0) /* first sample */
se->se_avgrssi = RSSI_IN(rssi);
else /* avg w/ previous samples */
RSSI_LPF(se->se_avgrssi, rssi);
se->base.se_rssi = RSSI_GET(se->se_avgrssi);
ise->se_rtsf = rtsf;
memcpy(ise->se_tstamp.data, sp->tstamp, sizeof(ise->se_tstamp));
ise->se_intval = sp->bintval;
ise->se_capinfo = sp->capinfo;
ise->se_chan = ic->ic_curchan;
ise->se_fhdwell = sp->fhdwell;
ise->se_fhindex = sp->fhindex;
ise->se_erp = sp->erp;
ise->se_timoff = sp->timoff;
if (sp->tim != NULL) {
const struct ieee80211_tim_ie *tim =
(const struct ieee80211_tim_ie *) sp->tim;
ise->se_dtimperiod = tim->tim_period;
}
saveie(&ise->se_wme_ie, sp->wme);
saveie(&ise->se_wpa_ie, sp->wpa);
saveie(&ise->se_rsn_ie, sp->rsn);
saveie(&ise->se_ath_ie, sp->ath);
se->se_lastupdate = jiffies; /* update time */
se->se_seen = 1;
se->se_notseen = 0;
SCAN_AP_UNLOCK_IRQ(as);
return 1; return 1;
} }
@ -271,15 +571,20 @@ ap_add(struct ieee80211_scan_state *ss, const struct ieee80211_scanparams *sp,
*/ */
static int static int
ap_end(struct ieee80211_scan_state *ss, struct ieee80211vap *vap, ap_end(struct ieee80211_scan_state *ss, struct ieee80211vap *vap,
int (*action)(struct ieee80211vap *, const struct ieee80211_scan_entry *), int (*action)(struct ieee80211vap *, const struct ieee80211_scan_entry *),
u_int32_t flags) u_int32_t flags)
{ {
struct ap_state *as = ss->ss_priv; struct ap_state *as = ss->ss_priv;
struct ieee80211com *ic = vap->iv_ic; struct ieee80211com *ic = NULL;
int res = 1;
int i, chan, bestchan, bestchanix; int i, chan, bestchan, bestchanix;
SCAN_AP_LOCK_IRQ(as);
KASSERT(vap->iv_opmode == IEEE80211_M_HOSTAP, KASSERT(vap->iv_opmode == IEEE80211_M_HOSTAP,
("wrong opmode %u", vap->iv_opmode)); ("wrong opmode %u", vap->iv_opmode));
ic = vap->iv_ic;
/* XXX select channel more intelligently, e.g. channel spread, power */ /* XXX select channel more intelligently, e.g. channel spread, power */
bestchan = -1; bestchan = -1;
bestchanix = 0; /* NB: silence compiler */ bestchanix = 0; /* NB: silence compiler */
@ -333,7 +638,7 @@ ap_end(struct ieee80211_scan_state *ss, struct ieee80211vap *vap,
"%s: no suitable channel! (should not happen)\n", __func__); "%s: no suitable channel! (should not happen)\n", __func__);
/* XXX print something? */ /* XXX print something? */
} }
return 0; /* restart scan */ res = 0; /* restart scan */
} else { } else {
struct ieee80211_channel *c; struct ieee80211_channel *c;
struct ieee80211_scan_entry se; struct ieee80211_scan_entry se;
@ -361,22 +666,65 @@ ap_end(struct ieee80211_scan_state *ss, struct ieee80211vap *vap,
* state machine, which would result in recursive locking. * state machine, which would result in recursive locking.
*/ */
IEEE80211_SCHEDULE_TQUEUE(&as->as_actiontq); IEEE80211_SCHEDULE_TQUEUE(&as->as_actiontq);
return 1; res = 1;
} }
SCAN_AP_UNLOCK_IRQ(as);
return res;
} }
static void static void
ap_age(struct ieee80211_scan_state *ss) ap_age(struct ieee80211_scan_state *ss)
{ {
/* XXX is there anything meaningful to do? */ struct ap_state *as = ss->ss_priv;
struct scan_entry *se, *next;
SCAN_AP_LOCK_IRQ(as);
TAILQ_FOREACH_SAFE(se, &as->as_entry, se_list, next) {
if (se->se_notseen > AP_PURGE_SCANS) {
TAILQ_REMOVE(&as->as_entry, se, se_list);
LIST_REMOVE(se, se_hash);
FREE(se, M_80211_SCAN);
}
}
SCAN_AP_UNLOCK_IRQ(as);
} }
static int static int
ap_iterate(struct ieee80211_scan_state *ss, ap_iterate(struct ieee80211_scan_state *ss,
ieee80211_scan_iter_func *f, void *arg) ieee80211_scan_iter_func *f, void *arg)
{ {
/* NB: nothing meaningful we can do */ struct ap_state *as = ss->ss_priv;
return 0; struct scan_entry *se;
u_int gen;
int res = 0;
SCAN_AP_GEN_LOCK(as);
gen = as->as_scangen++;
restart:
SCAN_AP_LOCK_IRQ(as);
TAILQ_FOREACH(se, &as->as_entry, se_list) {
if (se->se_scangen != gen) {
se->se_scangen = gen;
/* update public state */
se->base.se_age = jiffies - se->se_lastupdate;
SCAN_AP_UNLOCK_IRQ_EARLY(as);
res = (*f)(arg, &se->base);
/* We probably ran out of buffer space. */
if (res != 0)
goto done;
goto restart;
}
}
SCAN_AP_UNLOCK_IRQ(as);
done:
SCAN_AP_GEN_UNLOCK(as);
return res;
} }
static void static void
@ -402,6 +750,7 @@ ap_default_action(struct ieee80211vap *vap,
const struct ieee80211_scan_entry *se) const struct ieee80211_scan_entry *se)
{ {
ieee80211_create_ibss(vap, se->se_chan); ieee80211_create_ibss(vap, se->se_chan);
return 1; return 1;
} }
@ -411,6 +760,25 @@ action_tasklet(IEEE80211_TQUEUE_ARG data)
struct ieee80211_scan_state *ss = (struct ieee80211_scan_state *)data; struct ieee80211_scan_state *ss = (struct ieee80211_scan_state *)data;
struct ap_state *as = (struct ap_state *)ss->ss_priv; struct ap_state *as = (struct ap_state *)ss->ss_priv;
struct ieee80211vap *vap = ss->ss_vap; struct ieee80211vap *vap = ss->ss_vap;
SCAN_AP_LOCK_IRQ(as);
if (as->as_newscan) {
struct scan_entry *se;
TAILQ_FOREACH(se, &as->as_entry, se_list) {
/*
* If seen then reset and don't bump the count;
* otherwise bump the ``not seen'' count. Note
* that this ensures that stations for which we
* see frames while not scanning but not during
* this scan will not be penalized.
*/
if (se->se_seen)
se->se_seen = 0;
else
se->se_notseen++;
}
as->as_newscan = 0;
}
SCAN_AP_UNLOCK_IRQ(as);
(*ss->ss_ops->scan_default)(vap, &as->as_selbss); (*ss->ss_ops->scan_default)(vap, &as->as_selbss);
} }
@ -441,6 +809,7 @@ static const struct ieee80211_scanner ap_default = {
.scan_default = ap_default_action, .scan_default = ap_default_action,
}; };
static int __init static int __init
init_scanner_ap(void) init_scanner_ap(void)
{ {

View File

@ -1647,16 +1647,9 @@ giwscan_cb(void *arg, const struct ieee80211_scan_entry *se)
last_ev = current_ev; last_ev = current_ev;
iwe.cmd = SIOCGIWESSID; iwe.cmd = SIOCGIWESSID;
iwe.u.data.flags = 1; iwe.u.data.flags = 1;
if (vap->iv_opmode == IEEE80211_M_HOSTAP) { iwe.u.data.length = se->se_ssid[1];
iwe.u.data.length = vap->iv_des_nssid > 0 ? current_ev = iwe_stream_add_point(current_ev,
vap->iv_des_ssid[0].len : 0; end_buf, &iwe, (char *) se->se_ssid+2);
current_ev = iwe_stream_add_point(current_ev,
end_buf, &iwe, vap->iv_des_ssid[0].ssid);
} else {
iwe.u.data.length = se->se_ssid[1];
current_ev = iwe_stream_add_point(current_ev,
end_buf, &iwe, (char *) se->se_ssid+2);
}
/* We ran out of space in the buffer. */ /* We ran out of space in the buffer. */
if (last_ev == current_ev) if (last_ev == current_ev)