if (ic->ic_max_aid == 0) ic->ic_max_aid = IEEE80211_MAX_AID;
ieee80211_media_init(struct ifnet *ifp,	ifm_change_cb_t media_change, ifm_stat_cb_t media_stat){#define	ADD(_ic, _s, _o) \	ifmedia_add(&(_ic)->ic_media, \		IFM_MAKEWORD(IFM_IEEE80211, (_s), (_o), 0), 0, NULL)	struct ieee80211com *ic = (void *)ifp;	struct ifmediareq imr;	int i, j, mode, rate, maxrate, mword, mopt, r;	struct ieee80211_rateset *rs;	struct ieee80211_rateset allrates;	/*	 * Do late attach work that must wait for any subclass	 * (i.e. driver) work such as overriding methods.	 */	ieee80211_node_lateattach(ifp);	/*	 * Fill in media characteristics.	 */	ifmedia_init(&ic->ic_media, 0, media_change, media_stat);	maxrate = 0;	memset(&allrates, 0, sizeof(allrates));	for (mode = IEEE80211_MODE_AUTO; mode < IEEE80211_MODE_MAX; mode++) {		static const u_int mopts[] = {			IFM_AUTO,			IFM_IEEE80211_11A,			IFM_IEEE80211_11B,			IFM_IEEE80211_11G,			IFM_IEEE80211_FH,			IFM_IEEE80211_11A | IFM_IEEE80211_TURBO,		};		if ((ic->ic_modecaps & (1<<mode)) == 0)			continue;		mopt = mopts[mode];		ADD(ic, IFM_AUTO, mopt);	/* e.g. 11a auto */		if (ic->ic_caps & IEEE80211_C_IBSS)			ADD(ic, IFM_AUTO, mopt | IFM_IEEE80211_IBSS);		if (ic->ic_caps & IEEE80211_C_HOSTAP)			ADD(ic, IFM_AUTO, mopt | IFM_IEEE80211_HOSTAP);		if (ic->ic_caps & IEEE80211_C_AHDEMO)			ADD(ic, IFM_AUTO, mopt | IFM_IEEE80211_ADHOC);		if (ic->ic_caps & IEEE80211_C_MONITOR)			ADD(ic, IFM_AUTO, mopt | IFM_IEEE80211_MONITOR);		if (mode == IEEE80211_MODE_AUTO)			continue;		rs = &ic->ic_sup_rates[mode];		for (i = 0; i < rs->rs_nrates; i++) {			rate = rs->rs_rates[i];			mword = ieee80211_rate2media(ic, rate, mode);			if (mword == 0)				continue;			ADD(ic, mword, mopt);			if (ic->ic_caps & IEEE80211_C_IBSS)				ADD(ic, mword, mopt | IFM_IEEE80211_IBSS);			if (ic->ic_caps & IEEE80211_C_HOSTAP)				ADD(ic, mword, mopt | IFM_IEEE80211_HOSTAP);			if (ic->ic_caps & IEEE80211_C_AHDEMO)				ADD(ic, mword, mopt | IFM_IEEE80211_ADHOC);			if (ic->ic_caps & IEEE80211_C_MONITOR)				ADD(ic, mword, mopt | IFM_IEEE80211_MONITOR);			/*			 * Add rate to the collection of all rates.			 */			r = rate & IEEE80211_RATE_VAL;			for (j = 0; j < allrates.rs_nrates; j++)				if (allrates.rs_rates[j] == r)					break;			if (j == allrates.rs_nrates) {				/* unique, add to the set */				allrates.rs_rates[j] = r;				allrates.rs_nrates++;			}			rate = (rate & IEEE80211_RATE_VAL) / 2;			if (rate > maxrate)				maxrate = rate;		}	}	for (i = 0; i < allrates.rs_nrates; i++) {		mword = ieee80211_rate2media(ic, allrates.rs_rates[i],				IEEE80211_MODE_AUTO);		if (mword == 0)			continue;		mword = IFM_SUBTYPE(mword);	/* remove media options */		ADD(ic, mword, 0);		if (ic->ic_caps & IEEE80211_C_IBSS)			ADD(ic, mword, IFM_IEEE80211_IBSS);		if (ic->ic_caps & IEEE80211_C_HOSTAP)			ADD(ic, mword, IFM_IEEE80211_HOSTAP);		if (ic->ic_caps & IEEE80211_C_AHDEMO)			ADD(ic, mword, IFM_IEEE80211_ADHOC);		if (ic->ic_caps & IEEE80211_C_MONITOR)			ADD(ic, mword, IFM_IEEE80211_MONITOR);	}	ieee80211_media_status(ifp, &imr);	ifmedia_set(&ic->ic_media, imr.ifm_active);	if (maxrate)		ifp->if_baudrate = IF_Mbps(maxrate);	if (ic->ic_max_aid == 0)		ic->ic_max_aid = IEEE80211_MAX_AID;#undef ADD}