Module Name:    src
Committed By:   phil
Date:           Fri Jul 20 20:33:05 UTC 2018

Modified Files:
        src/sys/dev/usb [phil-wifi]: if_urtwn.c
        src/sys/net80211 [phil-wifi]: ieee80211.c ieee80211_amrr.c
            ieee80211_ioctl.c ieee80211_ioctl.h ieee80211_netbsd.c
            ieee80211_netbsd.h ieee80211_proto.c ieee80211_rssadapt.c
            ieee80211_scan_sw.c ieee80211_var.h

Log Message:
State save:
  urtwn: ifp->if_softc points to a vap, not the urtwn softc, fix code for this.
         add missing routines, need to get them filled out correctly.
  80211: Add back some NetBSD ioctls, start working on the sysctl tree.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.2 -r1.59.2.3 src/sys/dev/usb/if_urtwn.c
cvs rdiff -u -r1.56.18.3 -r1.56.18.4 src/sys/net80211/ieee80211.c
cvs rdiff -u -r1.3.18.3 -r1.3.18.4 src/sys/net80211/ieee80211_amrr.c
cvs rdiff -u -r1.60.18.3 -r1.60.18.4 src/sys/net80211/ieee80211_ioctl.c
cvs rdiff -u -r1.24.2.3 -r1.24.2.4 src/sys/net80211/ieee80211_ioctl.h
cvs rdiff -u -r1.31.2.3 -r1.31.2.4 src/sys/net80211/ieee80211_netbsd.c
cvs rdiff -u -r1.21.2.4 -r1.21.2.5 src/sys/net80211/ieee80211_netbsd.h
cvs rdiff -u -r1.34.14.3 -r1.34.14.4 src/sys/net80211/ieee80211_proto.c
cvs rdiff -u -r1.21.16.3 -r1.21.16.4 src/sys/net80211/ieee80211_rssadapt.c
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/net80211/ieee80211_scan_sw.c
cvs rdiff -u -r1.33.2.4 -r1.33.2.5 src/sys/net80211/ieee80211_var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.59.2.2 src/sys/dev/usb/if_urtwn.c:1.59.2.3
--- src/sys/dev/usb/if_urtwn.c:1.59.2.2	Mon Jul 16 20:11:11 2018
+++ src/sys/dev/usb/if_urtwn.c	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.2 2018/07/16 20:11:11 phil Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.3 2018/07/20 20:33:05 phil Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.2 2018/07/16 20:11:11 phil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.3 2018/07/20 20:33:05 phil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -311,6 +311,7 @@ static int	urtwn_reset(struct ieee80211v
 static void	urtwn_chip_stop(struct urtwn_softc *);
 static void	urtwn_newassoc(struct ieee80211_node *, int);
 static void	urtwn_delay_ms(struct urtwn_softc *, int ms);
+/* Functions for wifi refresh */
 static struct ieee80211vap *
 		urtwn_vap_create(struct ieee80211com *,
 		    const char [IFNAMSIZ], int, enum ieee80211_opmode, int,
@@ -318,6 +319,14 @@ static struct ieee80211vap *
 		    const uint8_t [IEEE80211_ADDR_LEN]);
 static void	urtwn_vap_delete(struct ieee80211vap *);
 static int	urtwn_ioctl(struct ifnet *, u_long, void *);
+static void	urtwn_parent(struct ieee80211com *);
+static void	urtwn_scan_start(struct ieee80211com *);
+static void	urtwn_scan_end(struct ieee80211com *);
+static void	urtwn_set_channel(struct ieee80211com *);
+static int	urtwn_transmit(struct ieee80211com *, struct mbuf *);
+static int	urtwn_raw_xmit(struct ieee80211_node *, struct mbuf *,
+		    const struct ieee80211_bpf_params *);
+
 
 /* Aliases. */
 #define	urtwn_bb_write	urtwn_write_4
@@ -357,6 +366,9 @@ urtwn_attach(device_t parent, device_t s
 	sc->sc_dev = self;
 	sc->sc_udev = uaa->uaa_device;
 
+	/* Name the ic. */
+	ic->ic_name = "urtwn";
+
 	sc->chip = 0;
 	dev = urtwn_lookup(urtwn_devs, uaa->uaa_vendor, uaa->uaa_product);
 	if (dev != NULL && ISSET(dev->flags, FLAG_RTL8188E))
@@ -491,6 +503,13 @@ urtwn_attach(device_t parent, device_t s
 	ic->ic_wme.wme_update = urtwn_wme_update;
 	ic->ic_vap_create = urtwn_vap_create;
 	ic->ic_vap_delete = urtwn_vap_delete;
+	ic->ic_parent = urtwn_parent;
+	ic->ic_scan_start = urtwn_scan_start;
+	ic->ic_scan_end = urtwn_scan_end;
+	ic->ic_set_channel = urtwn_set_channel;
+	ic->ic_transmit = urtwn_transmit;
+	ic->ic_raw_xmit = urtwn_raw_xmit;
+	
 
 	/* Shouldn't do it, but call vap_create??? */
 	uint8_t bssid[IEEE80211_ADDR_LEN] = {0};
@@ -507,6 +526,9 @@ urtwn_attach(device_t parent, device_t s
 		goto fail;
 	}
 
+	/* Debug all! NNN */
+	vap->iv_debug = IEEE80211_MSG_ANY;
+
 	bpf_attach2(vap->iv_ifp, DLT_IEEE802_11_RADIO,
 	    sizeof(struct ieee80211_frame) + IEEE80211_RADIOTAP_HDRLEN,
 	    &sc->sc_drvbpf);
@@ -1489,7 +1511,8 @@ static __unused int
 urtwn_media_change(struct ifnet *ifp)
 {
 #ifdef URTWN_DEBUG
-	struct urtwn_softc *sc = ifp->if_softc;
+	struct ieee80211vap *vap = ifp->if_softc;
+	struct urtwn_softc *sc = vap->iv_ic->ic_softc;
 #endif
 	int error;
 
@@ -1808,6 +1831,7 @@ urtwn_calib_to_cb(struct urtwn_softc *sc
 static void
 urtwn_next_scan(void *arg)
 {
+	printf ("urtwn_next_scan called....\n");
 #ifdef notyet
 	struct urtwn_softc *sc = arg;
 	int s;
@@ -1942,6 +1966,7 @@ urtwn_newstate_cb(struct urtwn_softc *sc
 	case IEEE80211_S_CAC:
 	case IEEE80211_S_CSA:
 	case IEEE80211_S_SLEEP:
+		printf ("URTWN UNKNOWN oSTATE: %d\n", ostate);
 		/* NNN what do we do in these states? XXX */
 		break;
 	}
@@ -2151,6 +2176,7 @@ urtwn_newstate_cb(struct urtwn_softc *sc
 	case IEEE80211_S_CSA:
 	case IEEE80211_S_SLEEP:
 		/* NNN what do we do in these states? XXX */
+		printf ("URTWN UNKNOWN nSTATE: %d\n", nstate);
 		break;
 	}
 
@@ -2824,12 +2850,12 @@ urtwn_get_tx_data(struct urtwn_softc *sc
 static void
 urtwn_start(struct ifnet *ifp)
 {
-	struct urtwn_softc *sc = ifp->if_softc;
-	struct ieee80211com *ic = &sc->sc_ic;
+	struct ieee80211vap *vap = ifp->if_softc;
+	struct ieee80211com *ic = vap->iv_ic;
+	struct urtwn_softc *sc = ic->ic_softc;
 	struct urtwn_tx_data *data;
 	struct ether_header *eh;
 	struct ieee80211_node *ni;
-	struct ieee80211vap *vap;
 	struct mbuf *m;
 
 	DPRINTFN(DBG_FN, ("%s: %s\n", device_xname(sc->sc_dev), __func__));
@@ -2837,15 +2863,6 @@ urtwn_start(struct ifnet *ifp)
 	if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
 		return;
 
-	/* Find the associated vap. NEED A BETTER WAY! */
-	vap = TAILQ_FIRST(&ic->ic_vaps);
-	while (vap != NULL) {
-		if (vap->iv_ifp == ifp)
-			break;
-		vap = TAILQ_NEXT(vap, iv_next);
-	}
-	KASSERT(vap != NULL);
-
 	data = NULL;
 	for (;;) {
 		/* Send pending management frames first. */
@@ -2939,7 +2956,8 @@ urtwn_start(struct ifnet *ifp)
 static void
 urtwn_watchdog(struct ifnet *ifp)
 {
-	struct urtwn_softc *sc = ifp->if_softc;
+	struct ieee80211vap *vap = ifp->if_softc;
+	struct urtwn_softc *sc = vap->iv_ic->ic_softc;
 
 	DPRINTFN(DBG_FN, ("%s: %s\n", device_xname(sc->sc_dev), __func__));
 
@@ -2955,7 +2973,7 @@ urtwn_watchdog(struct ifnet *ifp)
 		}
 		ifp->if_timer = 1;
 	}
-//NNN	ieee80211_watchdog(&sc->sc_ic);  Not sure what is happening!
+	//  ieee80211_watchdog(&sc->sc_ic); 
 }
 
 /*
@@ -2998,12 +3016,10 @@ urtwn_vap_create(struct ieee80211com *ic
 	ifp->if_ioctl = urtwn_ioctl;
 	ifp->if_start = urtwn_start;
 	ifp->if_watchdog = urtwn_watchdog;
+	ifp->if_extflags |= IFEF_MPSAFE;
 	IFQ_SET_READY(&ifp->if_snd);
 	memcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
 
-	/* NNN needed ??? */
-	/* if_attach(ifp); */
-
 	/* Override state transition machine. */
 	sc->sc_newstate = vap->iv_newstate;
 	vap->iv_newstate = urtwn_newstate;
@@ -3031,6 +3047,69 @@ urtwn_vap_delete(struct ieee80211vap *va
 	kmem_free(vap, sizeof(struct ieee80211vap));
 }
 
+static void
+urtwn_parent(struct ieee80211com *ic)
+{
+	struct urtwn_softc *sc __unused = ic->ic_softc;
+
+	DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
+
+	/* Not sure what to do here yet. */
+} 
+
+static void
+urtwn_scan_start(struct ieee80211com *ic)
+{
+	struct urtwn_softc *sc __unused = ic->ic_softc;
+
+	DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
+
+	/* Not sure what to do here yet. */
+} 
+
+static void
+urtwn_scan_end(struct ieee80211com *ic)
+{
+	struct urtwn_softc *sc __unused = ic->ic_softc;
+
+	DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
+
+	/* Not sure what to do here yet. */
+} 
+
+static void
+urtwn_set_channel(struct ieee80211com *ic)
+{
+	struct urtwn_softc *sc = ic->ic_softc;
+
+	DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
+
+	urtwn_set_chan(sc, ic->ic_curchan, IEEE80211_HTINFO_2NDCHAN_NONE);
+} 
+
+static int
+urtwn_transmit(struct ieee80211com *ic, struct mbuf *m)
+{
+	struct urtwn_softc *sc = ic->ic_softc;
+
+	DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
+
+	return EIO;
+}
+
+static int
+urtwn_raw_xmit(struct ieee80211_node *ni , struct mbuf *m,
+    const struct ieee80211_bpf_params *bpfp)
+{
+	struct ieee80211com *ic = ni->ni_ic;
+	struct urtwn_softc *sc = ic->ic_softc;
+
+	DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
+
+	return EIO;
+}
+
+
 static int
 urtwn_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
@@ -3050,11 +3129,14 @@ urtwn_ioctl(struct ifnet *ifp, u_long cm
 			break;
 		switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) {
 		case IFF_UP | IFF_RUNNING:
+			printf (" up and running...\n");
 			break;
 		case IFF_UP:
+			printf (" just up ... will start\n");
 			urtwn_init(ifp);
 			break;
 		case IFF_RUNNING:
+			printf (" just running .. will stop\n");
 			urtwn_stop(ifp, 1);
 			break;
 		case 0:
@@ -4765,9 +4847,9 @@ urtwn_temp_calib(struct urtwn_softc *sc)
 static int
 urtwn_init(struct ifnet *ifp)
 {
-	struct urtwn_softc *sc = ifp->if_softc;
-	struct ieee80211com *ic = &sc->sc_ic;
-	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
+	struct ieee80211vap *vap = ifp->if_softc;
+	struct ieee80211com *ic = vap->iv_ic;
+	struct urtwn_softc *sc = ic->ic_softc;
 	struct urtwn_rx_data *data;
 	uint32_t reg;
 	size_t i;
@@ -5036,9 +5118,9 @@ urtwn_init(struct ifnet *ifp)
 static void
 urtwn_stop(struct ifnet *ifp, int disable)
 {
-	struct urtwn_softc *sc = ifp->if_softc;
-	struct ieee80211com *ic = &sc->sc_ic;
-	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
+	struct ieee80211vap *vap = ifp->if_softc;
+	struct ieee80211com *ic = vap->iv_ic;
+	struct urtwn_softc *sc = ic->ic_softc;
 	size_t i;
 	int s;
 

Index: src/sys/net80211/ieee80211.c
diff -u src/sys/net80211/ieee80211.c:1.56.18.3 src/sys/net80211/ieee80211.c:1.56.18.4
--- src/sys/net80211/ieee80211.c:1.56.18.3	Mon Jul 16 20:11:11 2018
+++ src/sys/net80211/ieee80211.c	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.c,v 1.56.18.3 2018/07/16 20:11:11 phil Exp $ */
+/*	$NetBSD: ieee80211.c,v 1.56.18.4 2018/07/20 20:33:05 phil Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
 #ifdef __FreeBSD__
 #include <machine/stdarg.h>
 #elif __NetBSD__
+#include <sys/once.h>
 #include <sys/stdarg.h>
 #else
 #error
@@ -330,8 +331,6 @@ static struct mtx ic_list_mtx;
 MTX_SYSINIT(ic_list, &ic_list_mtx, "ieee80211com list", MTX_DEF);
 #elif __NetBSD__
 static kmutex_t ic_list_mtx;
-static uint     ic_list_mtx_needsinit = 1;
-static uint     ic_list_mtx_ready = 0;
 #endif
 
 #if notyet
@@ -365,6 +364,16 @@ SYSCTL_PROC(_net_wlan, OID_AUTO, devices
     sysctl_ieee80211coms, "A", "names of available 802.11 devices");
 #endif
 
+#if __NetBSD__
+static int
+ic_list_mtx_init (void)
+{
+	mutex_init(&ic_list_mtx, MUTEX_DEFAULT, IPL_NET);
+	ieee80211_auth_setup();
+	return 0;
+}		
+#endif
+
 /*
  * Attach/setup the common net80211 state.  Called by
  * the driver on attach to prior to creating any vap's.
@@ -373,21 +382,8 @@ void
 ieee80211_ifattach(struct ieee80211com *ic)
 {
 #if __NetBSD__
-	/* Initialize the ic_list_mtx the first time here.
-	 * Only want to use the big lock on first try to initialize.
-         * Once initialized, it won't use the big lock any more.
-         */
-	if (ic_list_mtx_needsinit) {
-		KERNEL_LOCK(1, NULL);
-		if (!ic_list_mtx_ready) {
-			mutex_init(&ic_list_mtx, MUTEX_DEFAULT, IPL_NET);
-			ic_list_mtx_ready = 1;
-			ic_list_mtx_needsinit = 0;
-			/* Doing this one-time initialization here also. */
-			ieee80211_auth_setup();
-		}
-		KERNEL_UNLOCK_ONE(NULL);
-	}
+	static ONCE_DECL(ic_list_mtx_once);
+	RUN_ONCE(&ic_list_mtx_once, ic_list_mtx_init);
 #endif
 
 	IEEE80211_LOCK_INIT(ic, ic->ic_name);
@@ -2011,6 +2007,7 @@ ieee80211_announce(struct ieee80211com *
 	for (mode = IEEE80211_MODE_AUTO+1; mode < IEEE80211_MODE_11NA; mode++) {
 		if (isclr(ic->ic_modecaps, mode))
 			continue;
+		printf ("[%d/%s]", mode, ieee80211_phymode_name[mode]);
 		ic_printf(ic, "%s rates: ", ieee80211_phymode_name[mode]);
 		rs = &ic->ic_sup_rates[mode];
 		for (i = 0; i < rs->rs_nrates; i++) {

Index: src/sys/net80211/ieee80211_amrr.c
diff -u src/sys/net80211/ieee80211_amrr.c:1.3.18.3 src/sys/net80211/ieee80211_amrr.c:1.3.18.4
--- src/sys/net80211/ieee80211_amrr.c:1.3.18.3	Mon Jul 16 20:11:11 2018
+++ src/sys/net80211/ieee80211_amrr.c	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_amrr.c,v 1.3.18.3 2018/07/16 20:11:11 phil Exp $ */
+/*	$NetBSD: ieee80211_amrr.c,v 1.3.18.4 2018/07/20 20:33:05 phil Exp $ */
 
 /*	$OpenBSD: ieee80211_amrr.c,v 1.1 2006/06/17 19:07:19 damien Exp $	*/
 
@@ -90,8 +90,10 @@ static void	amrr_tx_complete(const struc
 static void	amrr_tx_update_cb(void *, struct ieee80211_node *);
 static void	amrr_tx_update(struct ieee80211vap *vap,
 			struct ieee80211_ratectl_tx_stats *);
+#ifdef notyet
 static void	amrr_sysctlattach(struct ieee80211vap *,
 			struct sysctl_ctx_list *, struct sysctl_oid *);
+#endif
 static void	amrr_node_stats(struct ieee80211_node *ni, struct sbuf *s);
 
 /* number of references from net80211 layer */
@@ -149,7 +151,9 @@ amrr_init(struct ieee80211vap *vap)
 	amrr->amrr_min_success_threshold = IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD;
 	amrr->amrr_max_success_threshold = IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD;
 	amrr_setinterval(vap, 500 /* ms */);
+#ifdef notyet
 	amrr_sysctlattach(vap, vap->iv_sysctl, vap->iv_oid);
+#endif
 }
 
 static void
@@ -454,11 +458,11 @@ amrr_sysctl_interval(SYSCTL_HANDLER_ARGS
 }
 #endif
 
+#ifdef notyet
 static void
 amrr_sysctlattach(struct ieee80211vap *vap,
     struct sysctl_ctx_list *ctx, struct sysctl_oid *tree)
 {
-#ifdef notyet
 	struct ieee80211_amrr *amrr = vap->iv_rs;
 
 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
@@ -471,8 +475,8 @@ amrr_sysctlattach(struct ieee80211vap *v
 	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
 	    "amrr_min_sucess_threshold", CTLFLAG_RW,
 	    &amrr->amrr_min_success_threshold, 0, "");
-#endif
 }
+#endif
 
 static void
 amrr_node_stats(struct ieee80211_node *ni, struct sbuf *s)

Index: src/sys/net80211/ieee80211_ioctl.c
diff -u src/sys/net80211/ieee80211_ioctl.c:1.60.18.3 src/sys/net80211/ieee80211_ioctl.c:1.60.18.4
--- src/sys/net80211/ieee80211_ioctl.c:1.60.18.3	Mon Jul 16 20:11:11 2018
+++ src/sys/net80211/ieee80211_ioctl.c	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.c,v 1.60.18.3 2018/07/16 20:11:11 phil Exp $ */
+/*	$NetBSD: ieee80211_ioctl.c,v 1.60.18.4 2018/07/20 20:33:05 phil Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -784,9 +784,9 @@ IEEE80211_IOCTL_GET(dummy, dummy_ioctl_g
 static int
 ieee80211_ioctl_getdefault(struct ieee80211vap *vap, struct ieee80211req *ireq)
 {
+	int error;
 #if notyet
 	ieee80211_ioctl_getfunc * const *get;
-	int error;
 
 	SET_FOREACH(get, ieee80211_ioctl_getset) {
 		error = (*get)(vap, ireq);
@@ -794,9 +794,10 @@ ieee80211_ioctl_getdefault(struct ieee80
 			return error;
 	}
 #else
-	printf ("i33380211_ioctl_getdefault called\n");
+	printf ("ieee80211_ioctl_getdefault called\n");
+	error = dummy_ioctl_get(vap, ireq);
 #endif
-	return EINVAL;
+	return error;
 }
 
 static int
@@ -3044,7 +3045,14 @@ ieee80211_ioctl_set80211(struct ieee8021
 	case IEEE80211_IOC_SCAN_CANCEL:
 		IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN,
 		    "%s: cancel scan\n", __func__);
+#if __NetBSD__
+		/* Bug in FreeBSD? */
+		IEEE80211_LOCK(ic);
+#endif
 		ieee80211_cancel_scan(vap);
+#if __NetBSD__
+		IEEE80211_UNLOCK(ic);
+#endif
 		break;
 	case IEEE80211_IOC_HTCONF:
 		if (ireq->i_val & 1)
@@ -3519,11 +3527,23 @@ ieee80211_ioctl(struct ifnet *ifp, u_lon
 	int error = 0, wait = 0;
 	struct ifreq *ifr;
 	struct ifaddr *ifa;			/* XXX */
+#if __NetBSD__
+	struct ieee80211_nwid nwid;
+	//	struct ieee80211_nwkey *nwkey;
+	//	struct ieee80211_power *power;
+	//	struct ieee80211chanreq *chanreq;
+
+	ifr = (struct ifreq *)data;
+#endif
+
+	printf ("ieee80211_ioctl: cmd is 0x%lx. ('%c', %ld)\n", cmd,
+ 		(char) ((cmd>>8) & 0xff), cmd & 0xff );
 
 	switch (cmd) {
 	case SIOCSIFFLAGS:
 		IEEE80211_LOCK(ic);
 		if ((ifp->if_flags ^ vap->iv_ifflags) & IFF_PROMISC) {
+			printf ("    promisc mode\n");
 			/*
 			 * Enable promiscuous mode when:
 			 * 1. Interface is not a member of bridge, or
@@ -3541,10 +3561,12 @@ ieee80211_ioctl(struct ifnet *ifp, u_lon
 			}
 		}
 		if ((ifp->if_flags ^ vap->iv_ifflags) & IFF_ALLMULTI) {
+			printf ("    allmulti\n");
 			ieee80211_allmulti(vap, ifp->if_flags & IFF_ALLMULTI);
 			vap->iv_ifflags ^= IFF_ALLMULTI;
 		}
 		if (ifp->if_flags & IFF_UP) {
+			printf ("    up flag\n");
 			/*
 			 * Bring ourself up unless we're already operational.
 			 * If we're the first vap and the parent is not up
@@ -3554,7 +3576,9 @@ ieee80211_ioctl(struct ifnet *ifp, u_lon
 			if (vap->iv_state == IEEE80211_S_INIT) {
 				if (ic->ic_nrunning == 0)
 					wait = 1;
-				ieee80211_start_locked(vap);
+				printf ("Should call start_locked ...\n");
+				wait = 0;
+				// ieee80211_start_locked(vap);
 			}
 #if __FreeBSD__
 		} else if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
@@ -3649,6 +3673,45 @@ ieee80211_ioctl(struct ifnet *ifp, u_lon
 			break;
 		}
 		break;
+#if __NetBSD__
+	case SIOCS80211NWID:
+		if ((error = copyin(ifr->ifr_data, &nwid, sizeof(nwid))) != 0)
+			break;
+		if (nwid.i_len > IEEE80211_NWID_LEN) {
+			error = EINVAL;
+			break;
+		}
+		memset(vap->iv_des_ssid, 0, IEEE80211_NWID_LEN);
+		vap->iv_des_ssid[0].len = nwid.i_len;
+		memcpy(vap->iv_des_ssid[0].ssid, nwid.i_nwid, nwid.i_len);
+		error = ENETRESET;
+		break;
+	case SIOCG80211NWID:
+		memset(&nwid, 0, sizeof(nwid));
+		switch (vap->iv_state) {
+		case IEEE80211_S_INIT:
+		case IEEE80211_S_SCAN:
+			nwid.i_len  = vap->iv_des_ssid[0].len;
+			memcpy(nwid.i_nwid, vap->iv_des_ssid[0].ssid,
+			    nwid.i_len);
+			break;
+		default:
+			nwid.i_len = vap->iv_bss->ni_esslen;
+			memcpy(nwid.i_nwid, vap->iv_bss->ni_essid, nwid.i_len);
+			break;
+		}
+		error = copyout(&nwid, ifr->ifr_data, sizeof(nwid));
+		break;
+	case SIOCS80211NWKEY:
+	case SIOCG80211NWKEY:
+		printf ("NetBSD NWKEY ioctl\n");
+		error = ENOTTY;
+	        break;
+	case SIOCS80211POWER:
+		printf ("NEtBSD POWER ioctl\n");
+		error = ENOTTY;
+		break;
+#endif
 	default:
 		/*
 		 * Pass unknown ioctls first to the driver, and if it
@@ -3658,6 +3721,8 @@ ieee80211_ioctl(struct ifnet *ifp, u_lon
 		    (error = ic->ic_ioctl(ic, cmd, data)) != ENOTTY)
 			break;
 		error = ether_ioctl(ifp, cmd, data);
+		if (error == ENOTTY)
+			printf ("Unknown 802.11 IOCTL.\n"); /* NNN */
 		break;
 	}
 	return (error);

Index: src/sys/net80211/ieee80211_ioctl.h
diff -u src/sys/net80211/ieee80211_ioctl.h:1.24.2.3 src/sys/net80211/ieee80211_ioctl.h:1.24.2.4
--- src/sys/net80211/ieee80211_ioctl.h:1.24.2.3	Thu Jul 12 16:35:34 2018
+++ src/sys/net80211/ieee80211_ioctl.h	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.h,v 1.24.2.3 2018/07/12 16:35:34 phil Exp $ */
+/*	$NetBSD: ieee80211_ioctl.h,v 1.24.2.4 2018/07/20 20:33:05 phil Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -888,7 +888,7 @@ struct ieee80211_clone_params {
 #define	IEEE80211_CLONE_MACADDR		0x0008	/* use specified mac addr */
 #define	IEEE80211_CLONE_TDMA		0x0010	/* operate in TDMA mode */
 
-#ifdef __NetBSD__
+#if __NetBSD__
 /* nwid is pointed at by ifr.ifr_data */
 struct ieee80211_nwid {
 	u_int8_t	i_len;

Index: src/sys/net80211/ieee80211_netbsd.c
diff -u src/sys/net80211/ieee80211_netbsd.c:1.31.2.3 src/sys/net80211/ieee80211_netbsd.c:1.31.2.4
--- src/sys/net80211/ieee80211_netbsd.c:1.31.2.3	Mon Jul 16 20:11:11 2018
+++ src/sys/net80211/ieee80211_netbsd.c	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_netbsd.c,v 1.31.2.3 2018/07/16 20:11:11 phil Exp $ */
+/*	$NetBSD: ieee80211_netbsd.c,v 1.31.2.4 2018/07/20 20:33:05 phil Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 /*  __FBSDID("$FreeBSD$");  */
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.31.2.3 2018/07/16 20:11:11 phil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.31.2.4 2018/07/20 20:33:05 phil Exp $");
 
 /*
  * IEEE 802.11 support (NetBSD-specific code)
@@ -61,21 +61,31 @@ __KERNEL_RCSID(0, "$NetBSD: ieee80211_ne
 #include <net80211/ieee80211_var.h>
 #include <net80211/ieee80211_input.h>
 
-#ifdef notyet
-SYSCTL_NODE(_net, OID_AUTO, wlan, CTLFLAG_RD, 0, "IEEE 80211 parameters");
+static const struct sysctlnode *
+    ieee80211_sysctl_treetop(struct sysctllog **log);
+static void ieee80211_sysctl_setup(void);
+
+/* NNN in .h file? */
+#define SYSCTL_HANDLER_ARGS SYSCTLFN_ARGS
 
 #ifdef IEEE80211_DEBUG
 static int	ieee80211_debug = 0;
-SYSCTL_INT(_net_wlan, OID_AUTO, debug, CTLFLAG_RW, &ieee80211_debug,
-	    0, "debugging printfs");
 #endif
 
+#ifdef notyet
 static struct if_clone *wlan_cloner;
 #endif 
 /* notyet */
 
 static const char wlanname[] = "wlan";
 
+int
+ieee80211_init0(void)
+{
+	ieee80211_sysctl_setup();
+	return 0;
+}
+
 static __unused int
 wlan_clone_create(struct if_clone *ifc, int unit, void * params)
 {
@@ -166,15 +176,23 @@ ieee80211_sysctl_inact(SYSCTL_HANDLER_AR
 	*(int *)arg1 = inact / IEEE80211_INACT_WAIT;
 	return 0;
 }
+#endif
 
 static int
-ieee80211_sysctl_parent(SYSCTL_HANDLER_ARGS)
+ieee80211_sysctl_parent(SYSCTLFN_ARGS)
 {
-	struct ieee80211com *ic = arg1;
+	struct ieee80211vap *vap;
+	char pname[IFNAMSIZ];
+	struct sysctlnode node;
 
-	return SYSCTL_OUT_STR(req, ic->ic_name);
+	node = *rnode;
+	vap = node.sysctl_data;
+	strlcpy(pname, vap->iv_ifp->if_xname, IFNAMSIZ);
+	node.sysctl_data = pname;
+	return sysctl_lookup(SYSCTLFN_CALL(&node));
 }
 
+#ifdef notyet
 static int
 ieee80211_sysctl_radar(SYSCTL_HANDLER_ARGS)
 {
@@ -221,9 +239,99 @@ ieee80211_sysctl_detach(struct ieee80211
 {
 }
 
+/*
+ * Setup sysctl(3) MIB, net.ieee80211.*
+ *
+ * TBD condition CTLFLAG_PERMANENT on being a module or not
+ */
+static struct sysctllog *ieee80211_sysctllog;
+static void
+ieee80211_sysctl_setup(void)
+{
+	int rc;
+	const struct sysctlnode *rnode;
+
+	if ((rnode = ieee80211_sysctl_treetop(&ieee80211_sysctllog)) == NULL)
+		return;
+
+#ifdef notyet
+	if ((rc = sysctl_createv(&ieee80211_sysctllog, 0, &rnode, NULL,
+	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "nodes", "client/peer stations",
+	    ieee80211_sysctl_node, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+#endif
+
+#ifdef IEEE80211_DEBUG
+	/* control debugging printfs */
+	if ((rc = sysctl_createv(&ieee80211_sysctllog, 0, &rnode, NULL,
+	    CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT,
+	    "debug", SYSCTL_DESCR("control debugging printfs"),
+	    NULL, 0, &ieee80211_debug, 0, CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+#endif
+
+#ifdef notyet
+	ieee80211_rssadapt_sysctl_setup(&ieee80211_sysctllog);
+#endif
+
+	return;
+err:
+	printf("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
+}
+
+/*
+ * Create or get top of sysctl tree net.link.ieee80211.
+ */
+static const struct sysctlnode *
+ieee80211_sysctl_treetop(struct sysctllog **log)
+{
+	int rc;
+	const struct sysctlnode *rnode;
+
+	if ((rc = sysctl_createv(log, 0, NULL, &rnode,
+	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "link",
+	    "link-layer statistics and controls",
+	    NULL, 0, NULL, 0, CTL_NET, PF_LINK, CTL_EOL)) != 0)
+		goto err;
+
+	if ((rc = sysctl_createv(log, 0, &rnode, &rnode,
+	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "ieee80211",
+	    "IEEE 802.11 WLAN statistics and controls",
+	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+
+	return rnode;
+err:
+	printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc);
+	return NULL;
+}
+
 void
 ieee80211_sysctl_vattach(struct ieee80211vap *vap)
 {
+	int rc;
+	const struct sysctlnode *cnode, *rnode;
+	char num[sizeof("vap") + 14];		/* sufficient for 32 bits */
+
+	if ((rnode = ieee80211_sysctl_treetop(NULL)) == NULL)
+		return;
+
+	snprintf(num, sizeof(num), "vap%u", vap->iv_ifp->if_index);
+
+	if ((rc = sysctl_createv(&vap->iv_sysctllog, 0, &rnode, &rnode,
+	    CTLFLAG_PERMANENT, CTLTYPE_NODE, num, SYSCTL_DESCR("virtual AP"),
+	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+
+	/* control debugging printfs */
+	if ((rc = sysctl_createv(&vap->iv_sysctllog, 0, &rnode, &cnode,
+	    CTLFLAG_PERMANENT|CTLFLAG_READONLY, CTLTYPE_STRING,
+	    "parent", SYSCTL_DESCR("parent device"),
+	    ieee80211_sysctl_parent, 0, (void *)vap, IFNAMSIZ,
+	    CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+
+
 #ifdef notyet
 	struct ifnet *ifp = vap->iv_ifp;
 	struct sysctl_ctx_list *ctx;
@@ -305,6 +413,9 @@ ieee80211_sysctl_vattach(struct ieee8021
 	vap->iv_sysctl = ctx;
 	vap->iv_oid = oid;
 #endif
+	return;
+err:
+	printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc);
 }
 
 void

Index: src/sys/net80211/ieee80211_netbsd.h
diff -u src/sys/net80211/ieee80211_netbsd.h:1.21.2.4 src/sys/net80211/ieee80211_netbsd.h:1.21.2.5
--- src/sys/net80211/ieee80211_netbsd.h:1.21.2.4	Mon Jul 16 20:11:11 2018
+++ src/sys/net80211/ieee80211_netbsd.h	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_netbsd.h,v 1.21.2.4 2018/07/16 20:11:11 phil Exp $ */
+/*	$NetBSD: ieee80211_netbsd.h,v 1.21.2.5 2018/07/20 20:33:05 phil Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -825,6 +825,13 @@ struct ieee80211_channel_survey {
 /* XXX TODO: the type fields */
 
 /*
+ * Startup function for NetBSD
+ */
+
+int ieee80211_init0(void);
+
+
+/*
  * Functions FreeBSD uses that NetBSD doesn't have ...
  */
 

Index: src/sys/net80211/ieee80211_proto.c
diff -u src/sys/net80211/ieee80211_proto.c:1.34.14.3 src/sys/net80211/ieee80211_proto.c:1.34.14.4
--- src/sys/net80211/ieee80211_proto.c:1.34.14.3	Mon Jul 16 20:11:11 2018
+++ src/sys/net80211/ieee80211_proto.c	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_proto.c,v 1.34.14.3 2018/07/16 20:11:11 phil Exp $ */
+/*	$NetBSD: ieee80211_proto.c,v 1.34.14.4 2018/07/20 20:33:05 phil Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/malloc.h>
 #ifdef __NetBSD__
 #include <sys/mbuf.h>
+#include <sys/once.h>
 #endif
 
 #include <sys/socket.h>
@@ -1543,6 +1544,9 @@ ieee80211_start_locked(struct ieee80211v
 		IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
 		"start running, %d vaps running\n", ic->ic_nrunning);
 
+        printf ("returning from start_locked too soon.\n");
+        return;
+
 #if __FreeBSD__
 	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
 #elif __NetBSD__
@@ -1566,7 +1570,7 @@ ieee80211_start_locked(struct ieee80211v
 		 * to be brought up auto-up the parent if necessary.
 		 */
 		if (ic->ic_nrunning++ == 0) {
-
+			printf ("   calling start_check_reset_chan\n");
 			/* reset the channel to a known good channel */
 			if (ieee80211_start_check_reset_chan(vap))
 				ieee80211_start_reset_chan(vap);
@@ -1601,6 +1605,7 @@ ieee80211_start_locked(struct ieee80211v
 				ieee80211_new_state_locked(vap,
 				    IEEE80211_S_SCAN, 0);
 		} else {
+			printf ("   first vap??? \n");
 			/*
 			 * For monitor+wds mode there's nothing to do but
 			 * start running.  Otherwise if this is the first
@@ -1641,10 +1646,13 @@ int
 ieee80211_init(struct ifnet *ifp)
 {
 	struct ieee80211vap *vap = ifp->if_softc;
+	static ONCE_DECL(ieee80211_init_once);
 
 	IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
 	    "%s\n", __func__);
 
+	RUN_ONCE(&ieee80211_init_once, ieee80211_init0);
+
 	IEEE80211_LOCK(vap->iv_ic);
 	ieee80211_start_locked(vap);
 	IEEE80211_UNLOCK(vap->iv_ic);

Index: src/sys/net80211/ieee80211_rssadapt.c
diff -u src/sys/net80211/ieee80211_rssadapt.c:1.21.16.3 src/sys/net80211/ieee80211_rssadapt.c:1.21.16.4
--- src/sys/net80211/ieee80211_rssadapt.c:1.21.16.3	Mon Jul 16 20:11:11 2018
+++ src/sys/net80211/ieee80211_rssadapt.c	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_rssadapt.c,v 1.21.16.3 2018/07/16 20:11:11 phil Exp $ */
+/*	$NetBSD: ieee80211_rssadapt.c,v 1.21.16.4 2018/07/20 20:33:05 phil Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-3-Clause
@@ -107,8 +107,10 @@ static void	rssadapt_raise_rate(struct i
 			int, int);
 static void	rssadapt_tx_complete(const struct ieee80211_node *,
 			const struct ieee80211_ratectl_tx_status *);
+#ifdef notyet
 static void	rssadapt_sysctlattach(struct ieee80211vap *,
 			struct sysctl_ctx_list *, struct sysctl_oid *);
+#endif
 
 /* number of references from net80211 layer */
 static	int nrefs = 0;
@@ -164,7 +166,9 @@ rssadapt_init(struct ieee80211vap *vap)
 	}
 	rs->vap = vap;
 	rssadapt_setinterval(vap, 500 /* msecs */);
+#ifdef notyet
 	rssadapt_sysctlattach(vap, vap->iv_sysctl, vap->iv_oid);
+#endif
 }
 
 static void
@@ -376,15 +380,13 @@ rssadapt_sysctl_interval(SYSCTL_HANDLER_
 	rssadapt_setinterval(vap, msecs);
 	return 0;
 }
-#endif
 
 static void
 rssadapt_sysctlattach(struct ieee80211vap *vap,
     struct sysctl_ctx_list *ctx, struct sysctl_oid *tree)
 {
-#ifdef notyet
 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
 	    "rssadapt_rate_interval", CTLTYPE_INT | CTLFLAG_RW, vap,
 	    0, rssadapt_sysctl_interval, "I", "rssadapt operation interval (ms)");
-#endif
 }
+#endif

Index: src/sys/net80211/ieee80211_scan_sw.c
diff -u src/sys/net80211/ieee80211_scan_sw.c:1.1.2.2 src/sys/net80211/ieee80211_scan_sw.c:1.1.2.3
--- src/sys/net80211/ieee80211_scan_sw.c:1.1.2.2	Thu Jul 12 16:35:34 2018
+++ src/sys/net80211/ieee80211_scan_sw.c	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_scan_sw.c,v 1.1.2.2 2018/07/12 16:35:34 phil Exp $ */
+/*	$NetBSD: ieee80211_scan_sw.c,v 1.1.2.3 2018/07/20 20:33:05 phil Exp $ */
 
 /*-
  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
@@ -442,7 +442,12 @@ cancel_scan(struct ieee80211vap *vap, in
 	struct scan_state *ss_priv = SCAN_PRIVATE(ss);
 	int signal;
 
+#if __FreeBSD__
 	IEEE80211_LOCK(ic);
+#elif __NetBSD__
+	/* Is this a lock bug in FreeBSD? */
+	IEEE80211_LOCK_ASSERT(ic);
+#endif
 	signal = any ? ISCAN_PAUSE : ISCAN_CANCEL;
 	if ((ic->ic_flags & IEEE80211_F_SCAN) &&
 	    (any || ss->ss_vap == vap) &&
@@ -465,7 +470,9 @@ cancel_scan(struct ieee80211vap *vap, in
 			(ss->ss_vap == vap ? "match" : "nomatch"),
 			!! (ss_priv->ss_iflags & signal));
 	}
+#if __FreeBSD__
 	IEEE80211_UNLOCK(ic);
+#endif
 }
 
 /*

Index: src/sys/net80211/ieee80211_var.h
diff -u src/sys/net80211/ieee80211_var.h:1.33.2.4 src/sys/net80211/ieee80211_var.h:1.33.2.5
--- src/sys/net80211/ieee80211_var.h:1.33.2.4	Mon Jul 16 20:11:11 2018
+++ src/sys/net80211/ieee80211_var.h	Fri Jul 20 20:33:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_var.h,v 1.33.2.4 2018/07/16 20:11:11 phil Exp $ */
+/*	$NetBSD: ieee80211_var.h,v 1.33.2.5 2018/07/20 20:33:05 phil Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -387,8 +387,12 @@ struct ieee80211vap {
 	struct ifmedia		iv_media;	/* interface media config */
 	struct ifnet		*iv_ifp;	/* associated device */
 	struct bpf_if		*iv_rawbpf;	/* packet filter structure */
+#if __FreeBSD__
 	struct sysctl_ctx_list	*iv_sysctl;	/* dynamic sysctl context */
 	struct sysctl_oid	*iv_oid;	/* net.wlan.X sysctl oid */
+#elif __NetBSD__
+	struct sysctllog	*iv_sysctllog;	/* for destroying sysctl tree */
+#endif
 
 	TAILQ_ENTRY(ieee80211vap) iv_next;	/* list of vap instances */
 	struct ieee80211com	*iv_ic;		/* back ptr to common state */

Reply via email to