Skip to content

Commit

Permalink
Fix definition of IEEE80211_CHAN_MAX; it was defined as 255 but
Browse files Browse the repository at this point in the history
really was meant to be 256.  Adjust usage accordingly and replace
bogus usage of this value in checking IEEE channel #'s.

NB: this causes an ABI change; ifconfig must be recompiled
  • Loading branch information
sleffler committed Dec 15, 2008
1 parent 3ec60cf commit dc25688
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion sys/net80211/_ieee80211.h
Expand Up @@ -137,7 +137,7 @@ struct ieee80211_channel {
uint8_t ic_extieee; /* HT40 extension channel number */
};

#define IEEE80211_CHAN_MAX 255
#define IEEE80211_CHAN_MAX 256
#define IEEE80211_CHAN_BYTES 32 /* howmany(IEEE80211_CHAN_MAX, NBBY) */
#define IEEE80211_CHAN_ANY 0xffff /* token for ``any channel'' */
#define IEEE80211_CHAN_ANYC \
Expand Down
4 changes: 1 addition & 3 deletions sys/net80211/ieee80211.c
Expand Up @@ -118,16 +118,14 @@ ieee80211_chan_init(struct ieee80211com *ic)
struct ieee80211_channel *c;
int i;

KASSERT(0 < ic->ic_nchans && ic->ic_nchans < IEEE80211_CHAN_MAX,
KASSERT(0 < ic->ic_nchans && ic->ic_nchans <= IEEE80211_CHAN_MAX,
("invalid number of channels specified: %u", ic->ic_nchans));
memset(ic->ic_chan_avail, 0, sizeof(ic->ic_chan_avail));
memset(ic->ic_modecaps, 0, sizeof(ic->ic_modecaps));
setbit(ic->ic_modecaps, IEEE80211_MODE_AUTO);
for (i = 0; i < ic->ic_nchans; i++) {
c = &ic->ic_channels[i];
KASSERT(c->ic_flags != 0, ("channel with no flags"));
KASSERT(c->ic_ieee < IEEE80211_CHAN_MAX,
("channel with bogus ieee number %u", c->ic_ieee));
setbit(ic->ic_chan_avail, c->ic_ieee);
/*
* Identify mode capabilities.
Expand Down
2 changes: 1 addition & 1 deletion sys/net80211/ieee80211_ddb.c
Expand Up @@ -542,7 +542,7 @@ _db_show_com(const struct ieee80211com *ic, int showvaps, int showsta, int showp
*/
db_printf("\tnchans %d", ic->ic_nchans);
#if 0
struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX+1];
struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX];
uint8_t ic_chan_avail[IEEE80211_CHAN_BYTES];
uint8_t ic_chan_active[IEEE80211_CHAN_BYTES];
uint8_t ic_chan_scan[IEEE80211_CHAN_BYTES];
Expand Down
2 changes: 1 addition & 1 deletion sys/net80211/ieee80211_dfs.h
Expand Up @@ -32,7 +32,7 @@
*/

struct ieee80211_dfs_state {
int nol_event[IEEE80211_CHAN_MAX+1];
int nol_event[IEEE80211_CHAN_MAX];
struct callout nol_timer; /* NOL list processing */
struct callout cac_timer; /* CAC timer */
struct timeval lastevent; /* time of last radar event */
Expand Down
8 changes: 0 additions & 8 deletions sys/net80211/ieee80211_input.c
Expand Up @@ -673,14 +673,6 @@ ieee80211_parse_beacon(struct ieee80211_node *ni, struct mbuf *m,
}
IEEE80211_VERIFY_ELEMENT(scan->ssid, IEEE80211_NWID_LEN,
scan->status |= IEEE80211_BPARSE_SSID_INVALID);
#if IEEE80211_CHAN_MAX < 255
if (scan->chan > IEEE80211_CHAN_MAX) {
IEEE80211_DISCARD(vap, IEEE80211_MSG_ELEMID,
wh, NULL, "invalid channel %u", scan->chan);
vap->iv_stats.is_rx_badchan++;
scan->status |= IEEE80211_BPARSE_CHAN_INVALID;
}
#endif
if (scan->chan != scan->bchan && ic->ic_phytype != IEEE80211_T_FH) {
/*
* Frame was received on a channel different from the
Expand Down
24 changes: 8 additions & 16 deletions sys/net80211/ieee80211_ioctl.c
Expand Up @@ -1556,30 +1556,24 @@ ieee80211_ioctl_setchanlist(struct ieee80211vap *vap, struct ieee80211req *ireq)
struct ieee80211com *ic = vap->iv_ic;
struct ieee80211req_chanlist list;
u_char chanlist[IEEE80211_CHAN_BYTES];
int i, j, nchan, error;
int i, nchan, error;

if (ireq->i_len != sizeof(list))
return EINVAL;
error = copyin(ireq->i_data, &list, sizeof(list));
if (error)
return error;
memset(chanlist, 0, sizeof(chanlist));
/*
* Since channel 0 is not available for DS, channel 1
* is assigned to LSB on WaveLAN.
*/
if (ic->ic_phytype == IEEE80211_T_DS)
i = 1;
else
i = 0;
nchan = 0;
for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) {
for (i = 0; i < ic->ic_nchans; i++) {
const struct ieee80211_channel *c = &ic->ic_channels[i];
/*
* NB: silently discard unavailable channels so users
* can specify 1-255 to get all available channels.
* Calculate the intersection of the user list and the
* available channels so users can do things like specify
* 1-255 to get all available channels.
*/
if (isset(list.ic_channels, j) && isset(ic->ic_chan_avail, i)) {
setbit(chanlist, i);
if (isset(list.ic_channels, c->ic_ieee)) {
setbit(chanlist, c->ic_ieee);
nchan++;
}
}
Expand Down Expand Up @@ -1890,8 +1884,6 @@ ieee80211_ioctl_setchannel(struct ieee80211vap *vap,
if (ireq->i_val == 0 ||
ireq->i_val == (int16_t) IEEE80211_CHAN_ANY) {
c = IEEE80211_CHAN_ANYC;
} else if ((u_int) ireq->i_val > IEEE80211_CHAN_MAX) {
return EINVAL;
} else {
struct ieee80211_channel *c2;

Expand Down
2 changes: 1 addition & 1 deletion sys/net80211/ieee80211_regdomain.c
Expand Up @@ -338,7 +338,7 @@ ieee80211_setregdomain(struct ieee80211vap *vap,
reg->rd.isocc[0], reg->rd.isocc[1]);
return EINVAL;
}
if (reg->chaninfo.ic_nchans >= IEEE80211_CHAN_MAX) {
if (reg->chaninfo.ic_nchans > IEEE80211_CHAN_MAX) {
IEEE80211_DPRINTF(vap, IEEE80211_MSG_IOCTL,
"%s: too many channels %u, max %u\n", __func__,
reg->chaninfo.ic_nchans, IEEE80211_CHAN_MAX);
Expand Down
7 changes: 6 additions & 1 deletion sys/net80211/ieee80211_scan_sta.c
Expand Up @@ -87,6 +87,9 @@ struct sta_entry {
#define STA_HASH(addr) \
(((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % STA_HASHSIZE)

#define MAX_IEEE_CHAN 256 /* max acceptable IEEE chan # */
CTASSERT(MAX_IEEE_CHAN >= 256);

struct sta_table {
struct mtx st_lock; /* on scan table */
TAILQ_HEAD(, sta_entry) st_entry; /* all entries */
Expand All @@ -96,7 +99,7 @@ struct sta_table {
u_int st_scangen; /* scan generation # */
int st_newscan;
/* ap-related state */
int st_maxrssi[IEEE80211_CHAN_MAX];
int st_maxrssi[MAX_IEEE_CHAN];
};

static void sta_flush_table(struct sta_table *);
Expand Down Expand Up @@ -343,6 +346,7 @@ sta_add(struct ieee80211_scan_state *ss,
se->se_seen = 1;
se->se_notseen = 0;

KASSERT(sizeof(sp->bchan) == 1, ("bchan size"));
if (rssi > st->st_maxrssi[sp->bchan])
st->st_maxrssi[sp->bchan] = rssi;

Expand Down Expand Up @@ -1604,6 +1608,7 @@ ap_pick_channel(struct ieee80211_scan_state *ss, int flags)
/* check channel attributes for band compatibility */
if (flags != 0 && (chan->ic_flags & flags) != flags)
continue;
KASSERT(sizeof(chan->ic_ieee) == 1, ("ic_chan size"));
/* XXX channel have interference */
if (st->st_maxrssi[chan->ic_ieee] == 0) {
/* XXX use other considerations */
Expand Down
2 changes: 1 addition & 1 deletion sys/net80211/ieee80211_var.h
Expand Up @@ -156,7 +156,7 @@ struct ieee80211com {
* (e.g. for dynamic turbo)
*/
int ic_nchans; /* # entries in ic_channels */
struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX+1];
struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX];
uint8_t ic_chan_avail[IEEE80211_CHAN_BYTES];
uint8_t ic_chan_active[IEEE80211_CHAN_BYTES];
uint8_t ic_chan_scan[IEEE80211_CHAN_BYTES];
Expand Down

0 comments on commit dc25688

Please sign in to comment.