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/82ad099d0846
branches:  trunk
changeset: 361390:82ad099d0846
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 cfc698c24c63 -r 82ad099d0846 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
@@ -113,6 +113,10 @@
 #endif
 };
 
+#ifdef __NetBSD__
+int sysctl_ieee80211coms(SYSCTLFN_ARGS);
+#endif
+
 const uint8_t ieee80211broadcastaddr[IEEE80211_ADDR_LEN] =
        { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
@@ -125,8 +129,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");
 
@@ -318,7 +323,7 @@
 static kmutex_t ic_list_mtx;
 #endif
 
-#if notyet
+#if defined(__FreeBSD__)
 static int
 sysctl_ieee80211coms(SYSCTL_HANDLER_ARGS)
 {
@@ -347,6 +352,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__
@@ -356,7 +389,7 @@
        mutex_init(&ic_list_mtx, MUTEX_DEFAULT, IPL_NET);
        ieee80211_auth_setup();
        return 0;
-}              
+}
 #endif
 
 /*
@@ -369,6 +402,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);
@@ -391,8 +426,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
 
        /*
@@ -484,8 +517,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);
@@ -548,6 +583,7 @@
        vap->iv_def_txkey = kid;
 }
 
+#ifdef __FreeBSD__
 /*
  * Add underlying device errors to vap errors.
  */
@@ -572,6 +608,7 @@
 
        return (rv);
 }
+#endif
 
 /*
  * Prepare a vap for use.  Drivers use this call to
@@ -591,9 +628,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;
@@ -604,9 +638,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 */
@@ -758,7 +795,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));
 
@@ -770,6 +811,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);
@@ -787,7 +829,6 @@
        IEEE80211_UNLOCK(ic);
 
 #if __NetBSD__
-
        if_register(ifp);
 #endif
 
@@ -811,9 +852,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);
 
        /*
@@ -822,7 +866,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 */
@@ -872,6 +916,9 @@
        ieee80211_node_vdetach(vap);
        ieee80211_sysctl_vdetach(vap);
 
+#if __NetBSD__
+       if_detach(ifp);
+#endif
        if_free(ifp);
 
        CURVNET_RESTORE();
@@ -1867,6 +1914,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,
@@ -2027,20 +2075,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 cfc698c24c63 -r 82ad099d0846 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 cfc698c24c63 -r 82ad099d0846 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 cfc698c24c63 -r 82ad099d0846 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