Date: Fri, 6 Apr 2007 16:41:56 GMT From: Sam Leffler <sam@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 117517 for review Message-ID: <200704061641.l36GfuHB065204@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=117517 Change 117517 by sam@sam_ebb on 2007/04/06 16:41:15 Media-related cleanups in preparation for 11n support: o factor out code to add media entries to a new addmedia routine o when announcing tx rates, cvt media word back to a rate to print o factor out rate lookup logic used in mapping rate -> media word Also avoid call to ieee80211_chan2mode unless result is needed. Affected files ... .. //depot/projects/wifi/sys/net80211/ieee80211.c#46 edit Differences ... ==== //depot/projects/wifi/sys/net80211/ieee80211.c#46 (text+ko) ==== @@ -423,6 +423,36 @@ return NULL; } +static void +addmedia(struct ieee80211com *ic, int mode, int mword) +{ +#define ADD(_ic, _s, _o) \ + ifmedia_add(&(_ic)->ic_media, \ + IFM_MAKEWORD(IFM_IEEE80211, (_s), (_o), 0), 0, NULL) + static const u_int mopts[IEEE80211_MODE_MAX] = { + IFM_AUTO, + IFM_IEEE80211_11A, + IFM_IEEE80211_11B, + IFM_IEEE80211_11G, + IFM_IEEE80211_FH, + IFM_IEEE80211_11A | IFM_IEEE80211_TURBO, + IFM_IEEE80211_11G | IFM_IEEE80211_TURBO, + }; + u_int mopt; + + mopt = mopts[mode]; + ADD(ic, mword, mopt); /* e.g. 11a auto */ + if (ic->ic_caps & IEEE80211_C_IBSS) + ADD(ic, mword, mopt | IFM_IEEE80211_ADHOC); + 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 | IFM_FLAG0); + if (ic->ic_caps & IEEE80211_C_MONITOR) + ADD(ic, mword, mopt | IFM_IEEE80211_MONITOR); +#undef ADD +} + /* * Setup the media data structures according to the channel and * rate tables. This must be called by the driver after @@ -432,12 +462,9 @@ ieee80211_media_init(struct ieee80211com *ic, 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 ifnet *ifp = ic->ic_ifp; - int i, j, mode, rate, maxrate, mword, mopt, r; - struct ieee80211_rateset *rs; + int i, j, mode, rate, maxrate, mword, r; + const struct ieee80211_rateset *rs; struct ieee80211_rateset allrates; /* NB: this works because the structure is initialized to zero */ @@ -463,29 +490,14 @@ */ ifmedia_init(&ic->ic_media, 0, media_change, media_stat); maxrate = 0; + /* + * Add media for legacy operating modes. + */ 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, - IFM_IEEE80211_11G | IFM_IEEE80211_TURBO, - }; if (isclr(ic->ic_modecaps, mode)) 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_ADHOC); - 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 | IFM_FLAG0); - if (ic->ic_caps & IEEE80211_C_MONITOR) - ADD(ic, IFM_AUTO, mopt | IFM_IEEE80211_MONITOR); + addmedia(ic, mode, IFM_AUTO); if (mode == IEEE80211_MODE_AUTO) continue; rs = &ic->ic_sup_rates[mode]; @@ -494,17 +506,9 @@ 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_ADHOC); - 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 | IFM_FLAG0); - if (ic->ic_caps & IEEE80211_C_MONITOR) - ADD(ic, mword, mopt | IFM_IEEE80211_MONITOR); + addmedia(ic, mode, mword); /* - * Add rate to the collection of all rates. + * Add legacy rate to the collection of all rates. */ r = rate & IEEE80211_RATE_VAL; for (j = 0; j < allrates.rs_nrates; j++) @@ -525,16 +529,8 @@ 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_ADHOC); - 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 | IFM_FLAG0); - if (ic->ic_caps & IEEE80211_C_MONITOR) - ADD(ic, mword, IFM_IEEE80211_MONITOR); + /* NB: remove media options from mword */ + addmedia(ic, IEEE80211_MODE_AUTO, IFM_SUBTYPE(mword)); } /* NB: strip explicit mode; we're actually in autoselect */ ifmedia_set(&ic->ic_media, @@ -542,19 +538,16 @@ if (maxrate) ifp->if_baudrate = IF_Mbps(maxrate); -#undef ADD } const struct ieee80211_rateset * ieee80211_get_suprates(struct ieee80211com *ic, const struct ieee80211_channel *c) { - enum ieee80211_phymode mode = ieee80211_chan2mode(c); - if (IEEE80211_IS_CHAN_HALF(c)) return &ieee80211_rateset_half; if (IEEE80211_IS_CHAN_QUARTER(c)) return &ieee80211_rateset_quarter; - return &ic->ic_sup_rates[mode]; + return &ic->ic_sup_rates[ieee80211_chan2mode(c)]; } void @@ -562,7 +555,7 @@ { struct ifnet *ifp = ic->ic_ifp; int i, mode, rate, mword; - struct ieee80211_rateset *rs; + const struct ieee80211_rateset *rs; for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) { if (isclr(ic->ic_modecaps, mode)) @@ -574,9 +567,9 @@ mword = ieee80211_rate2media(ic, rate, mode); if (mword == 0) continue; + rate = ieee80211_media2rate(mword); printf("%s%d%sMbps", (i != 0 ? " " : ""), - (rate & IEEE80211_RATE_VAL) / 2, - ((rate & 0x1) != 0 ? ".5" : "")); + rate / 2, ((rate & 0x1) != 0 ? ".5" : "")); } printf("\n"); } @@ -986,18 +979,31 @@ return IEEE80211_MODE_11B; } +struct ratemedia { + u_int match; /* rate + mode */ + u_int media; /* if_media rate */ +}; + +static int +findmedia(const struct ratemedia rates[], int n, u_int match) +{ + int i; + + for (i = 0; i < n; i++) + if (rates[i].match == match) + return rates[i].media; + return IFM_AUTO; +} + /* - * convert IEEE80211 rate value to ifmedia subtype. - * ieee80211 rate is in unit of 0.5Mbps. + * Convert IEEE80211 rate value to ifmedia subtype. + * Rate is a legacy rate in units of 0.5Mbps. */ int ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode mode) { #define N(a) (sizeof(a) / sizeof(a[0])) - static const struct { - u_int m; /* rate + mode */ - u_int r; /* if_media rate */ - } rates[] = { + static const struct ratemedia rates[] = { { 2 | IFM_IEEE80211_FH, IFM_IEEE80211_FH1 }, { 4 | IFM_IEEE80211_FH, IFM_IEEE80211_FH2 }, { 2 | IFM_IEEE80211_11B, IFM_IEEE80211_DS1 }, @@ -1030,37 +1036,28 @@ { 54 | IFM_IEEE80211_11A, IFM_IEEE80211_OFDM27 }, /* NB: OFDM72 doesn't realy exist so we don't handle it */ }; - u_int mask, i; - mask = rate & IEEE80211_RATE_VAL; + rate &= IEEE80211_RATE_VAL; switch (mode) { case IEEE80211_MODE_11A: case IEEE80211_MODE_TURBO_A: case IEEE80211_MODE_STURBO_A: - mask |= IFM_IEEE80211_11A; - break; + return findmedia(rates, N(rates), rate | IFM_IEEE80211_11A); case IEEE80211_MODE_11B: - mask |= IFM_IEEE80211_11B; - break; + return findmedia(rates, N(rates), rate | IFM_IEEE80211_11B); case IEEE80211_MODE_FH: - mask |= IFM_IEEE80211_FH; - break; + return findmedia(rates, N(rates), rate | IFM_IEEE80211_FH); case IEEE80211_MODE_AUTO: /* NB: ic may be NULL for some drivers */ - if (ic && ic->ic_phytype == IEEE80211_T_FH) { - mask |= IFM_IEEE80211_FH; - break; - } + if (ic && ic->ic_phytype == IEEE80211_T_FH) + return findmedia(rates, N(rates), + rate | IFM_IEEE80211_FH); /* NB: hack, 11g matches both 11b+11a rates */ /* fall thru... */ case IEEE80211_MODE_11G: case IEEE80211_MODE_TURBO_G: - mask |= IFM_IEEE80211_11G; - break; + return findmedia(rates, N(rates), rate | IFM_IEEE80211_11G); } - for (i = 0; i < N(rates); i++) - if (rates[i].m == mask) - return rates[i].r; return IFM_AUTO; #undef N }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200704061641.l36GfuHB065204>