Author: avos
Date: Thu May 19 22:14:35 2016
New Revision: 300238
URL: https://svnweb.freebsd.org/changeset/base/300238

Log:
  wi: switch to ieee80211_add_channel()
  
  - Convert to ieee80211_add_channel().
  - Add ic_getradiocaps() method.
  
  Differential Revision:        https://reviews.freebsd.org/D6235

Modified:
  head/sys/dev/wi/if_wi.c
  head/sys/dev/wi/if_wivar.h

Modified: head/sys/dev/wi/if_wi.c
==============================================================================
--- head/sys/dev/wi/if_wi.c     Thu May 19 22:02:03 2016        (r300237)
+++ head/sys/dev/wi/if_wi.c     Thu May 19 22:14:35 2016        (r300238)
@@ -155,9 +155,12 @@ static int  wi_mwrite_bap(struct wi_soft
 static int  wi_read_rid(struct wi_softc *, int, void *, int *);
 static int  wi_write_rid(struct wi_softc *, int, const void *, int);
 static int  wi_write_appie(struct wi_softc *, int, const struct 
ieee80211_appie *);
+static u_int16_t wi_read_chanmask(struct wi_softc *);
 
 static void wi_scan_start(struct ieee80211com *);
 static void wi_scan_end(struct ieee80211com *);
+static void wi_getradiocaps(struct ieee80211com *, int, int *,
+               struct ieee80211_channel[]);
 static void wi_set_channel(struct ieee80211com *);
        
 static __inline int
@@ -335,23 +338,9 @@ wi_attach(device_t dev)
         * Query the card for available channels and setup the
         * channel table.  We assume these are all 11b channels.
         */
-       buflen = sizeof(val);
-       if (wi_read_rid(sc, WI_RID_CHANNEL_LIST, &val, &buflen) != 0)
-               val = htole16(0x1fff);  /* assume 1-13 */
-       KASSERT(val != 0, ("wi_attach: no available channels listed!"));
-
-       val <<= 1;                      /* shift for base 1 indices */
-       for (i = 1; i < 16; i++) {
-               struct ieee80211_channel *c;
-
-               if (!isset((u_int8_t*)&val, i))
-                       continue;
-               c = &ic->ic_channels[ic->ic_nchans++];
-               c->ic_freq = ieee80211_ieee2mhz(i, IEEE80211_CHAN_B);
-               c->ic_flags = IEEE80211_CHAN_B;
-               c->ic_ieee = i;
-               /* XXX txpowers? */
-       }
+       sc->sc_chanmask = wi_read_chanmask(sc);
+       wi_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans,
+           ic->ic_channels);
 
        /*
         * Set flags based on firmware version.
@@ -439,6 +428,7 @@ wi_attach(device_t dev)
        ic->ic_raw_xmit = wi_raw_xmit;
        ic->ic_scan_start = wi_scan_start;
        ic->ic_scan_end = wi_scan_end;
+       ic->ic_getradiocaps = wi_getradiocaps;
        ic->ic_set_channel = wi_set_channel;
        ic->ic_vap_create = wi_vap_create;
        ic->ic_vap_delete = wi_vap_delete;
@@ -697,6 +687,26 @@ wi_stop(struct wi_softc *sc, int disable
 }
 
 static void
+wi_getradiocaps(struct ieee80211com *ic,
+    int maxchans, int *nchans, struct ieee80211_channel chans[])
+{
+       struct wi_softc *sc = ic->ic_softc;
+       u_int8_t bands[IEEE80211_MODE_MAX];
+       int i;
+
+       memset(bands, 0, sizeof(bands));
+       setbit(bands, IEEE80211_MODE_11B);
+
+       for (i = 1; i < 16; i++) {
+               if (sc->sc_chanmask & (1 << i)) {
+                       /* XXX txpowers? */
+                       ieee80211_add_channel(chans, maxchans, nchans,
+                           i, 0, 0, 0, bands);
+               }
+       }
+}
+
+static void
 wi_set_channel(struct ieee80211com *ic)
 {
        struct wi_softc *sc = ic->ic_softc;
@@ -1988,6 +1998,22 @@ wi_write_appie(struct wi_softc *sc, int 
        return wi_write_rid(sc, rid, buf, ie->ie_len + sizeof(uint16_t));
 }
 
+static u_int16_t
+wi_read_chanmask(struct wi_softc *sc)
+{
+       u_int16_t val;
+       int buflen;
+
+       buflen = sizeof(val);
+       if (wi_read_rid(sc, WI_RID_CHANNEL_LIST, &val, &buflen) != 0)
+               val = htole16(0x1fff);  /* assume 1-13 */
+       KASSERT(val != 0, ("%s: no available channels listed!", __func__));
+
+       val <<= 1;                      /* shift for base 1 indices */
+
+       return (val);
+}
+
 int
 wi_alloc(device_t dev, int rid)
 {

Modified: head/sys/dev/wi/if_wivar.h
==============================================================================
--- head/sys/dev/wi/if_wivar.h  Thu May 19 22:02:03 2016        (r300237)
+++ head/sys/dev/wi/if_wivar.h  Thu May 19 22:14:35 2016        (r300238)
@@ -114,6 +114,7 @@ struct wi_softc     {
        u_int16_t               sc_portnum;
        u_int16_t               sc_encryption;
        u_int16_t               sc_monitor_port;
+       u_int16_t               sc_chanmask;
 
        /* RSSI interpretation */
        u_int16_t               sc_min_rssi;    /* clamp sc_min_rssi < RSSI */
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to