FreeBSD/sbin/ifconfig/ifieee80211.c
/*
 * Given the channel at index i with attributes from,
 * check if there is a channel with attributes to in
 * the channel table.  With suitable attributes this
 * allows the caller to look for promotion; e.g. from
 * 11b > 11g.
 */
Given the channel at index i with attributes from,
check if there is a channel with attributes to in
the channel table.  With suitable attributes this
allows the caller to look for promotion; e.g.
Given the channel at index i with attributes from check if there is a channel with attributes to in the channel table . With suitable attributes this allows the caller to look for promotion ; e . g .
static int
canpromote(int i, int from, int to)
{
	const struct ieee80211_channel *fc = &chaninfo->ic_chans[i];
	u_int j;
	if ((fc->ic_flags & from) != from)
		return i;
	if (i+1 < chaninfo->ic_nchans &&
	    chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq &&
	    (chaninfo->ic_chans[i+1].ic_flags & to) == to)
		return i+1;
	for (j = 0; j < chaninfo->ic_nchans; j++) {
		const struct ieee80211_channel *tc = &chaninfo->ic_chans[j];
		if (j != i &&
		    tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to)
		return j;
	}
	return i;
}
static int canpromote ( int i , int from , int to ) { const struct ieee80211_channel * fc = & chaninfo -> ic_chans [ i ] ; u_int j ; if ( ( fc -> ic_flags & from ) != from ) return i ; if ( i + 1 < chaninfo -> ic_nchans && chaninfo -> ic_chans [ i + 1 ] . ic_freq == fc -> ic_freq && ( chaninfo -> ic_chans [ i + 1 ] . ic_flags & to ) == to ) return i + 1 ; for ( j = 0 ; j < chaninfo -> ic_nchans ; j ++ ) { const struct ieee80211_channel * tc = & chaninfo -> ic_chans [ j ] ; if ( j != i && tc -> ic_freq == fc -> ic_freq && ( tc -> ic_flags & to ) == to ) return j ; } return i ; }
Given the channel at index i with attributes from,
 check if there is a channel with attributes to in
 the channel table.
Given the channel at index i with attributes from check if there is a channel with attributes to in the channel table .
/* NB: quick check exploiting ordering of chans w/ same frequency */ /* brute force search in case channel list is not ordered */