Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src-draft/trunk]: src/sys/net80211 Implement VAP support for NetBSD.



details:   https://anonhg.NetBSD.org/src-all/rev/10ad3b2b2a21
branches:  trunk
changeset: 949070:10ad3b2b2a21
user:      Martin Husemann <martin%NetBSD.org@localhost>
date:      Fri Sep 25 19:54:08 2020 +0200

description:
Implement VAP support for NetBSD.

Fix a few locking issues, get rid of some now unused _locked() variants.
Pass a flag to ieee80211_check_scan_current() and friends telling
it whethere we have the radio IC already locked.

diffstat:

 sys/net80211/ieee80211.c         |   88 ++++-
 sys/net80211/ieee80211_adhoc.c   |    6 +-
 sys/net80211/ieee80211_dfs.c     |    8 +-
 sys/net80211/ieee80211_hostap.c  |   26 +-
 sys/net80211/ieee80211_input.c   |   25 +-
 sys/net80211/ieee80211_ioctl.c   |   39 +-
 sys/net80211/ieee80211_mesh.c    |    4 +-
 sys/net80211/ieee80211_netbsd.c  |  539 +++++++++++++++++++++-----------------
 sys/net80211/ieee80211_netbsd.h  |   68 ++--
 sys/net80211/ieee80211_output.c  |    2 +-
 sys/net80211/ieee80211_proto.c   |   21 +-
 sys/net80211/ieee80211_scan.c    |   13 +-
 sys/net80211/ieee80211_scan.h    |    4 +-
 sys/net80211/ieee80211_scan_sw.c |   27 +-
 sys/net80211/ieee80211_sta.c     |   10 +-
 sys/net80211/ieee80211_tdma.c    |    4 +-
 sys/net80211/ieee80211_var.h     |    5 +-
 sys/net80211/ieee80211_wds.c     |    2 +-
 18 files changed, 494 insertions(+), 397 deletions(-)

diffs (truncated from 1702 to 300 lines):

diff -r 5df89d484724 -r 10ad3b2b2a21 sys/net80211/ieee80211.c
--- a/sys/net80211/ieee80211.c  Fri Sep 25 19:50:15 2020 +0200
+++ b/sys/net80211/ieee80211.c  Fri Sep 25 19:54:08 2020 +0200
@@ -114,6 +114,10 @@
 #endif
 };
 
+#ifdef __NetBSD__
+int sysctl_ieee80211coms(SYSCTLFN_ARGS);
+#endif
+
 const uint8_t ieee80211broadcastaddr[IEEE80211_ADDR_LEN] =
        { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
@@ -126,8 +130,9 @@
                ifm_change_cb_t media_change, ifm_stat_cb_t media_stat);
 static int media_status(enum ieee80211_opmode,
                const struct ieee80211_channel *);
+#ifdef __FreeBSD__
 static uint64_t ieee80211_get_counter(struct ifnet *, ift_counter);
-
+#endif
 
 MALLOC_DEFINE(M_80211_VAP, "80211vap", "802.11 vap state");
 
@@ -319,7 +324,7 @@
 static kmutex_t ic_list_mtx;
 #endif
 
-#if notyet
+#if defined(__FreeBSD__)
 static int
 sysctl_ieee80211coms(SYSCTL_HANDLER_ARGS)
 {
@@ -348,6 +353,34 @@
 SYSCTL_PROC(_net_wlan, OID_AUTO, devices,
     CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
     sysctl_ieee80211coms, "A", "names of available 802.11 devices");
+#elif defined(__NetBSD__)
+int
+sysctl_ieee80211coms(SYSCTLFN_ARGS)
+{
+       struct ieee80211com *ic;
+       struct sbuf *sb;
+       const char *sp = "";
+       int error, len, cnt = 0;
+
+       sb = sbuf_new_auto();
+       mtx_lock(&ic_list_mtx);
+       LIST_FOREACH(ic, &ic_head, ic_next) {
+               sbuf_printf(sb, "%s%s", sp, ic->ic_name);
+               sp = " ";
+               cnt++;
+       }
+       mtx_unlock(&ic_list_mtx);
+       error = sbuf_finish(sb);
+       sp = sbuf_data(sb);
+       len = sbuf_len(sb)+1;
+       if (oldp != NULL && len >= *oldlenp)
+               error = EINVAL;
+       else if (oldp != NULL)
+               error = copyout(sp, oldp, len);
+       sbuf_delete(sb);
+       *oldlenp = len;
+       return error;
+}
 #endif
 
 #if __NetBSD__
@@ -357,7 +390,7 @@
        mutex_init(&ic_list_mtx, MUTEX_DEFAULT, IPL_NET);
        ieee80211_auth_setup();
        return 0;
-}              
+}
 #endif
 
 /*
@@ -370,6 +403,8 @@
 #if __NetBSD__
        static ONCE_DECL(ic_list_mtx_once);
        RUN_ONCE(&ic_list_mtx_once, ic_list_mtx_init);
+       static ONCE_DECL(clone_init_once);
+       RUN_ONCE(&clone_init_once, ieee80211_clone_attach);
 #endif
 
        IEEE80211_LOCK_INIT(ic, ic->ic_name);
@@ -392,8 +427,6 @@
        if (workqueue_create(&ic->ic_tq, "net80211_wq",
            ieee80211_runwork, ic, PRI_SOFTNET, IPL_NET, WQ_MPSAFE))
                panic("net80211 workqueue not created");
-       ic->ic_ierrors = 0;
-       ic->ic_oerrors = 0;
 #endif
 
        /*
@@ -485,8 +518,10 @@
        ieee80211_power_detach(ic);
        ieee80211_node_detach(ic);
 
+#if __FreeBSD__        
        counter_u64_free(ic->ic_ierrors);
        counter_u64_free(ic->ic_oerrors);
+#endif
 
        taskqueue_free(ic->ic_tq);
        IEEE80211_TX_LOCK_DESTROY(ic);
@@ -549,6 +584,7 @@
        vap->iv_def_txkey = kid;
 }
 
+#ifdef __FreeBSD__
 /*
  * Add underlying device errors to vap errors.
  */
@@ -573,6 +609,7 @@
 
        return (rv);
 }
+#endif
 
 /*
  * Prepare a vap for use.  Drivers use this call to
@@ -592,9 +629,6 @@
                    __func__);
                return ENOMEM;
        }
-#if __NetBSD__
-       if_initialize(ifp);
-#endif
        if_initname(ifp, name, unit);
        ifp->if_softc = vap;                    /* back pointer */
        ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
@@ -605,9 +639,12 @@
        ifp->if_ioctl = ieee80211_ioctl;
        ifp->if_init = ieee80211_init;
 
-#if notyet
+#if __FreeBSD__
        ifp->if_get_counter = ieee80211_get_counter;
 #endif
+#if __NetBSD__
+       if_initialize(ifp);
+#endif
        vap->iv_ifp = ifp;
        vap->iv_ic = ic;
        vap->iv_flags = ic->ic_flags;           /* propagate common flags */
@@ -759,7 +796,11 @@
        if (maxrate)
                ifp->if_baudrate = IF_Mbps(maxrate);
 
+#if __FreeBSD__
        ether_ifattach(ifp, macaddr);
+#else
+       ieee80211_if_attach(ifp, macaddr);
+#endif
        /* NNN also done in vap_setup, which is correct? */
        IEEE80211_ADDR_COPY(vap->iv_myaddr, IF_LLADDR(ifp));
 
@@ -771,6 +812,7 @@
 
        IEEE80211_LOCK(ic);
        TAILQ_INSERT_TAIL(&ic->ic_vaps, vap, iv_next);
+
        ieee80211_syncflag_locked(ic, IEEE80211_F_WME);
 #ifdef IEEE80211_SUPPORT_SUPERG
        ieee80211_syncflag_locked(ic, IEEE80211_F_TURBOP);
@@ -788,7 +830,6 @@
        IEEE80211_UNLOCK(ic);
 
 #if __NetBSD__
-
        if_register(ifp);
 #endif
 
@@ -812,9 +853,12 @@
        IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s parent %s\n",
            __func__, ieee80211_opmode_name[vap->iv_opmode], ic->ic_name);
 
-       /* NB: bpfdetach is called by ether_ifdetach and claims all taps */
+       KASSERT(!TAILQ_EMPTY(&ic->ic_vaps));
+#if __FreeBSD__
        ether_ifdetach(ifp);
-
+#else
+       bpf_detach(ifp);
+#endif
        ieee80211_stop(vap);
 
        /*
@@ -823,7 +867,7 @@
        ieee80211_draintask(ic, &vap->iv_nstate_task);
        ieee80211_draintask(ic, &vap->iv_swbmiss_task);
        ieee80211_draintask(ic, &vap->iv_wme_task);
-       ieee80211_draintask(ic, &ic->ic_parent_task);
+       ieee80211_draintask(ic, &vap->iv_slot_task);
 
 #if __FreeBSD__        
        /* XXX band-aid until ifnet handles this for us */
@@ -873,6 +917,9 @@
        ieee80211_node_vdetach(vap);
        ieee80211_sysctl_vdetach(vap);
 
+#if __NetBSD__
+       if_detach(ifp);
+#endif
        if_free(ifp);
 
        CURVNET_RESTORE();
@@ -1868,6 +1915,7 @@
 #define        ADD(_ic, _s, _o) \
        ifmedia_add(media, \
                IFM_MAKEWORD(IFM_IEEE80211, (_s), (_o), 0), 0, NULL)
+
        static const u_int mopts[IEEE80211_MODE_MAX] = {
            [IEEE80211_MODE_AUTO]       = IFM_AUTO,
            [IEEE80211_MODE_11A]        = IFM_IEEE80211_11A,
@@ -2028,20 +2076,6 @@
 }
 
 void
-ieee80211_media_init(struct ieee80211com *ic,
-       ifm_change_cb_t media_change, ifm_stat_cb_t media_stat)
-{
-
-       struct ieee80211vap *vap;
-
-       vap = TAILQ_FIRST(&ic->ic_vaps);
-       KASSERTMSG(vap != NULL, "media vap is null");
-
-       ifmedia_init_with_lock(&vap->iv_media, 0, media_change,
-           media_stat, NULL);
-}
-
-void
 ieee80211_announce(struct ieee80211com *ic)
 {
        int i, rate, mword;
diff -r 5df89d484724 -r 10ad3b2b2a21 sys/net80211/ieee80211_adhoc.c
--- a/sys/net80211/ieee80211_adhoc.c    Fri Sep 25 19:50:15 2020 +0200
+++ b/sys/net80211/ieee80211_adhoc.c    Fri Sep 25 19:54:08 2020 +0200
@@ -205,7 +205,7 @@
                         * in iv_scanreq.  Otherwise we do the default.
                         */
                        if (vap->iv_flags_ext & IEEE80211_FEXT_SCANREQ) {
-                               ieee80211_check_scan(vap,
+                               ieee80211_check_scan(vap, 1,
                                    vap->iv_scanreq_flags,
                                    vap->iv_scanreq_duration,
                                    vap->iv_scanreq_mindwell,
@@ -213,7 +213,7 @@
                                    vap->iv_scanreq_nssid, vap->iv_scanreq_ssid);
                                vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ;
                        } else
-                               ieee80211_check_scan_current(vap);
+                               ieee80211_check_scan_current(vap, 1);
                        break;
                case IEEE80211_S_SCAN:
                        /*
@@ -223,7 +223,7 @@
                         * case an application must issue an explicit request.
                         */
                        if (vap->iv_roaming == IEEE80211_ROAMING_AUTO)
-                               ieee80211_check_scan_current(vap);
+                               ieee80211_check_scan_current(vap, 1);
                        break;
                default:
                        goto invalid;
diff -r 5df89d484724 -r 10ad3b2b2a21 sys/net80211/ieee80211_dfs.c
--- a/sys/net80211/ieee80211_dfs.c      Fri Sep 25 19:50:15 2020 +0200
+++ b/sys/net80211/ieee80211_dfs.c      Fri Sep 25 19:54:08 2020 +0200
@@ -121,12 +121,12 @@
 {
        struct ieee80211_dfs_state *dfs = &ic->ic_dfs;
 
-#ifdef __FreeBSD__
+#if __FreeBSD__
        callout_init_mtx(&dfs->nol_timer, IEEE80211_LOCK_OBJ(ic), 0);
        callout_init_mtx(&dfs->cac_timer, IEEE80211_LOCK_OBJ(ic), 0);
-#else
-       callout_init(&dfs->nol_timer, 0);
-       callout_init(&dfs->cac_timer, 0);
+#elif __NetBSD__
+       callout_init(&dfs->nol_timer, CALLOUT_MPSAFE);
+       callout_init(&dfs->cac_timer, CALLOUT_MPSAFE);
 #endif
 
        ic->ic_set_quiet = null_set_quiet;
diff -r 5df89d484724 -r 10ad3b2b2a21 sys/net80211/ieee80211_hostap.c
--- a/sys/net80211/ieee80211_hostap.c   Fri Sep 25 19:50:15 2020 +0200
+++ b/sys/net80211/ieee80211_hostap.c   Fri Sep 25 19:54:08 2020 +0200
@@ -254,7 +254,7 @@
                         * in iv_scanreq.  Otherwise we do the default.
                         */
                        if (vap->iv_flags_ext & IEEE80211_FEXT_SCANREQ) {
-                               ieee80211_check_scan(vap,
+                               ieee80211_check_scan(vap, 1,
                                    vap->iv_scanreq_flags,
                                    vap->iv_scanreq_duration,
                                    vap->iv_scanreq_mindwell,



Home | Main Index | Thread Index | Old Index