Replace the homegrown implementation of nitems() with calls to nitems()

(param.h).

Operating systems that don't have nitems() can easily define it on their own
net80211 OS-specific header file.

Discussed with:		adrian
This commit is contained in:
Rui Paulo 2013-08-14 04:24:25 +00:00
parent 12ede07ab8
commit a3e08d6f4c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=254315
6 changed files with 37 additions and 56 deletions

View File

@ -1518,7 +1518,6 @@ findmedia(const struct ratemedia rates[], int n, u_int match)
int
ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode mode)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
static const struct ratemedia rates[] = {
{ 2 | IFM_IEEE80211_FH, IFM_IEEE80211_FH1 },
{ 4 | IFM_IEEE80211_FH, IFM_IEEE80211_FH2 },
@ -1639,7 +1638,7 @@ ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode m
if (mode == IEEE80211_MODE_11NA) {
if (rate & IEEE80211_RATE_MCS) {
rate &= ~IEEE80211_RATE_MCS;
m = findmedia(htrates, N(htrates), rate);
m = findmedia(htrates, nitems(htrates), rate);
if (m != IFM_AUTO)
return m | IFM_IEEE80211_11NA;
}
@ -1647,7 +1646,7 @@ ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode m
/* NB: 12 is ambiguous, it will be treated as an MCS */
if (rate & IEEE80211_RATE_MCS) {
rate &= ~IEEE80211_RATE_MCS;
m = findmedia(htrates, N(htrates), rate);
m = findmedia(htrates, nitems(htrates), rate);
if (m != IFM_AUTO)
return m | IFM_IEEE80211_11NG;
}
@ -1660,31 +1659,32 @@ ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode m
case IEEE80211_MODE_11NA:
case IEEE80211_MODE_TURBO_A:
case IEEE80211_MODE_STURBO_A:
return findmedia(rates, N(rates), rate | IFM_IEEE80211_11A);
return findmedia(rates, nitems(rates),
rate | IFM_IEEE80211_11A);
case IEEE80211_MODE_11B:
return findmedia(rates, N(rates), rate | IFM_IEEE80211_11B);
return findmedia(rates, nitems(rates),
rate | IFM_IEEE80211_11B);
case IEEE80211_MODE_FH:
return findmedia(rates, N(rates), rate | IFM_IEEE80211_FH);
return findmedia(rates, nitems(rates),
rate | IFM_IEEE80211_FH);
case IEEE80211_MODE_AUTO:
/* NB: ic may be NULL for some drivers */
if (ic != NULL && ic->ic_phytype == IEEE80211_T_FH)
return findmedia(rates, N(rates),
return findmedia(rates, nitems(rates),
rate | IFM_IEEE80211_FH);
/* NB: hack, 11g matches both 11b+11a rates */
/* fall thru... */
case IEEE80211_MODE_11G:
case IEEE80211_MODE_11NG:
case IEEE80211_MODE_TURBO_G:
return findmedia(rates, N(rates), rate | IFM_IEEE80211_11G);
return findmedia(rates, nitems(rates), rate | IFM_IEEE80211_11G);
}
return IFM_AUTO;
#undef N
}
int
ieee80211_media2rate(int mword)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
static const int ieeerates[] = {
-1, /* IFM_AUTO */
0, /* IFM_MANUAL */
@ -1712,9 +1712,8 @@ ieee80211_media2rate(int mword)
54, /* IFM_IEEE80211_OFDM27 */
-1, /* IFM_IEEE80211_MCS */
};
return IFM_SUBTYPE(mword) < N(ieeerates) ?
return IFM_SUBTYPE(mword) < nitems(ieeerates) ?
ieeerates[IFM_SUBTYPE(mword)] : 0;
#undef N
}
/*

View File

@ -80,37 +80,35 @@ static ieee80211_send_action_func *vendor_send_action[8] = {
int
ieee80211_send_action_register(int cat, int act, ieee80211_send_action_func *f)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
switch (cat) {
case IEEE80211_ACTION_CAT_BA:
if (act >= N(ba_send_action))
if (act >= nitems(ba_send_action))
break;
ba_send_action[act] = f;
return 0;
case IEEE80211_ACTION_CAT_HT:
if (act >= N(ht_send_action))
if (act >= nitems(ht_send_action))
break;
ht_send_action[act] = f;
return 0;
case IEEE80211_ACTION_CAT_SELF_PROT:
if (act >= N(meshpl_send_action))
if (act >= nitems(meshpl_send_action))
break;
meshpl_send_action[act] = f;
return 0;
case IEEE80211_ACTION_CAT_MESH:
if (act >= N(meshaction_send_action))
if (act >= nitems(meshaction_send_action))
break;
meshaction_send_action[act] = f;
return 0;
break;
case IEEE80211_ACTION_CAT_VENDOR:
if (act >= N(vendor_send_action))
if (act >= nitems(vendor_send_action))
break;
vendor_send_action[act] = f;
return 0;
}
return EINVAL;
#undef N
}
void
@ -122,33 +120,31 @@ ieee80211_send_action_unregister(int cat, int act)
int
ieee80211_send_action(struct ieee80211_node *ni, int cat, int act, void *sa)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
ieee80211_send_action_func *f = send_inval;
switch (cat) {
case IEEE80211_ACTION_CAT_BA:
if (act < N(ba_send_action))
if (act < nitems(ba_send_action))
f = ba_send_action[act];
break;
case IEEE80211_ACTION_CAT_HT:
if (act < N(ht_send_action))
if (act < nitems(ht_send_action))
f = ht_send_action[act];
break;
case IEEE80211_ACTION_CAT_SELF_PROT:
if (act < N(meshpl_send_action))
if (act < nitems(meshpl_send_action))
f = meshpl_send_action[act];
break;
case IEEE80211_ACTION_CAT_MESH:
if (act < N(meshaction_send_action))
if (act < nitems(meshaction_send_action))
f = meshaction_send_action[act];
break;
case IEEE80211_ACTION_CAT_VENDOR:
if (act < N(vendor_send_action))
if (act < nitems(vendor_send_action))
f = vendor_send_action[act];
break;
}
return f(ni, cat, act, sa);
#undef N
}
static int
@ -183,36 +179,34 @@ static ieee80211_recv_action_func *vendor_recv_action[8] = {
int
ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
switch (cat) {
case IEEE80211_ACTION_CAT_BA:
if (act >= N(ba_recv_action))
if (act >= nitems(ba_recv_action))
break;
ba_recv_action[act] = f;
return 0;
case IEEE80211_ACTION_CAT_HT:
if (act >= N(ht_recv_action))
if (act >= nitems(ht_recv_action))
break;
ht_recv_action[act] = f;
return 0;
case IEEE80211_ACTION_CAT_SELF_PROT:
if (act >= N(meshpl_recv_action))
if (act >= nitems(meshpl_recv_action))
break;
meshpl_recv_action[act] = f;
return 0;
case IEEE80211_ACTION_CAT_MESH:
if (act >= N(meshaction_recv_action))
if (act >= nitems(meshaction_recv_action))
break;
meshaction_recv_action[act] = f;
return 0;
case IEEE80211_ACTION_CAT_VENDOR:
if (act >= N(vendor_recv_action))
if (act >= nitems(vendor_recv_action))
break;
vendor_recv_action[act] = f;
return 0;
}
return EINVAL;
#undef N
}
void
@ -226,7 +220,6 @@ ieee80211_recv_action(struct ieee80211_node *ni,
const struct ieee80211_frame *wh,
const uint8_t *frm, const uint8_t *efrm)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
ieee80211_recv_action_func *f = recv_inval;
struct ieee80211vap *vap = ni->ni_vap;
const struct ieee80211_action *ia =
@ -234,15 +227,15 @@ ieee80211_recv_action(struct ieee80211_node *ni,
switch (ia->ia_category) {
case IEEE80211_ACTION_CAT_BA:
if (ia->ia_action < N(ba_recv_action))
if (ia->ia_action < nitems(ba_recv_action))
f = ba_recv_action[ia->ia_action];
break;
case IEEE80211_ACTION_CAT_HT:
if (ia->ia_action < N(ht_recv_action))
if (ia->ia_action < nitems(ht_recv_action))
f = ht_recv_action[ia->ia_action];
break;
case IEEE80211_ACTION_CAT_SELF_PROT:
if (ia->ia_action < N(meshpl_recv_action))
if (ia->ia_action < nitems(meshpl_recv_action))
f = meshpl_recv_action[ia->ia_action];
break;
case IEEE80211_ACTION_CAT_MESH:
@ -255,14 +248,13 @@ ieee80211_recv_action(struct ieee80211_node *ni,
vap->iv_stats.is_mesh_nolink++;
break;
}
if (ia->ia_action < N(meshaction_recv_action))
if (ia->ia_action < nitems(meshaction_recv_action))
f = meshaction_recv_action[ia->ia_action];
break;
case IEEE80211_ACTION_CAT_VENDOR:
if (ia->ia_action < N(vendor_recv_action))
if (ia->ia_action < nitems(vendor_recv_action))
f = vendor_recv_action[ia->ia_action];
break;
}
return f(ni, wh, frm, efrm);
#undef N
}

View File

@ -985,7 +985,6 @@ ieee80211_ies_expand(struct ieee80211_ies *ies)
static void
node_cleanup(struct ieee80211_node *ni)
{
#define N(a) (sizeof(a)/sizeof(a[0]))
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211com *ic = ni->ni_ic;
int i;
@ -1052,7 +1051,7 @@ node_cleanup(struct ieee80211_node *ni)
*
* XXX does this leave us open to inheriting old state?
*/
for (i = 0; i < N(ni->ni_rxfrag); i++)
for (i = 0; i < nitems(ni->ni_rxfrag); i++)
if (ni->ni_rxfrag[i] != NULL) {
m_freem(ni->ni_rxfrag[i]);
ni->ni_rxfrag[i] = NULL;
@ -1061,7 +1060,6 @@ node_cleanup(struct ieee80211_node *ni)
* Must be careful here to remove any key map entry w/o a LOR.
*/
ieee80211_node_delucastkey(ni);
#undef N
}
static void

View File

@ -294,13 +294,12 @@ static struct ieee80211_rate_table ieee80211_11na_table = {
static void
ieee80211_setup_ratetable(struct ieee80211_rate_table *rt)
{
#define N(a) (sizeof(a)/sizeof(a[0]))
#define WLAN_CTRL_FRAME_SIZE \
(sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN)
int i;
for (i = 0; i < N(rt->rateCodeToIndex); i++)
for (i = 0; i < nitems(rt->rateCodeToIndex); i++)
rt->rateCodeToIndex[i] = (uint8_t) -1;
for (i = 0; i < rt->rateCount; i++) {
uint8_t code = rt->info[i].dot11Rate;
@ -341,14 +340,12 @@ ieee80211_setup_ratetable(struct ieee80211_rate_table *rt)
}
#undef WLAN_CTRL_FRAME_SIZE
#undef N
}
/* Setup all rate tables */
static void
ieee80211_phy_init(void)
{
#define N(arr) (int)(sizeof(arr) / sizeof(arr[0]))
static struct ieee80211_rate_table * const ratetables[] = {
&ieee80211_half_table,
&ieee80211_quarter_table,
@ -362,10 +359,9 @@ ieee80211_phy_init(void)
};
int i;
for (i = 0; i < N(ratetables); ++i)
for (i = 0; i < nitems(ratetables); ++i)
ieee80211_setup_ratetable(ratetables[i]);
#undef N
}
SYSINIT(wlan_phy, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_phy_init, NULL);

View File

@ -662,13 +662,12 @@ ieee80211_set_shortslottime(struct ieee80211com *ic, int onoff)
int
ieee80211_iserp_rateset(const struct ieee80211_rateset *rs)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
static const int rates[] = { 2, 4, 11, 22, 12, 24, 48 };
int i, j;
if (rs->rs_nrates < N(rates))
if (rs->rs_nrates < nitems(rates))
return 0;
for (i = 0; i < N(rates); i++) {
for (i = 0; i < nitems(rates); i++) {
for (j = 0; j < rs->rs_nrates; j++) {
int r = rs->rs_rates[j] & IEEE80211_RATE_VAL;
if (rates[i] == r)
@ -681,7 +680,6 @@ ieee80211_iserp_rateset(const struct ieee80211_rateset *rs)
;
}
return 1;
#undef N
}
/*

View File

@ -450,13 +450,12 @@ add_channels(struct ieee80211vap *vap,
struct ieee80211_scan_state *ss,
enum ieee80211_phymode mode, const uint16_t freq[], int nfreq)
{
#define N(a) (sizeof(a) / sizeof(a[0]))
struct ieee80211com *ic = vap->iv_ic;
struct ieee80211_channel *c, *cg;
u_int modeflags;
int i;
KASSERT(mode < N(chanflags), ("Unexpected mode %u", mode));
KASSERT(mode < nitems(chanflags), ("Unexpected mode %u", mode));
modeflags = chanflags[mode];
for (i = 0; i < nfreq; i++) {
if (ss->ss_last >= IEEE80211_SCAN_MAX)
@ -476,7 +475,6 @@ add_channels(struct ieee80211vap *vap,
}
ss->ss_chans[ss->ss_last++] = c;
}
#undef N
}
struct scanlist {