CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 07:38:25 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Software crypto definitions from FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.17 -r1.59.2.18 src/sys/dev/usb/if_urtwn.c

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.17 src/sys/dev/usb/if_urtwn.c:1.59.2.18
--- src/sys/dev/usb/if_urtwn.c:1.59.2.17	Mon Apr 27 07:37:01 2020
+++ src/sys/dev/usb/if_urtwn.c	Mon Apr 27 07:38:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.17 2020/04/27 07:37:01 nat Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.18 2020/04/27 07:38:25 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.17 2020/04/27 07:37:01 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.18 2020/04/27 07:38:25 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -527,6 +527,11 @@ urtwn_attach(device_t parent, device_t s
 	IEEE80211_HTCAP_SHORTGI40;		/* short GI in 40MHz */
 #endif
 
+	ic->ic_cryptocaps =
+		IEEE80211_CRYPTO_WEP |
+		IEEE80211_CRYPTO_TKIP |
+		IEEE80211_CRYPTO_AES_CCM;
+
 	ic->ic_txstream = sc->ntxchains;
 	ic->ic_rxstream = sc->nrxchains;
 



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 07:38:25 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Software crypto definitions from FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.17 -r1.59.2.18 src/sys/dev/usb/if_urtwn.c

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



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 07:37:01 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Fix resource leak in rx/tx free lists.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.16 -r1.59.2.17 src/sys/dev/usb/if_urtwn.c

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.16 src/sys/dev/usb/if_urtwn.c:1.59.2.17
--- src/sys/dev/usb/if_urtwn.c:1.59.2.16	Sat Apr 25 14:40:11 2020
+++ src/sys/dev/usb/if_urtwn.c	Mon Apr 27 07:37:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.16 2020/04/25 14:40:11 nat Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.17 2020/04/27 07:37:01 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.16 2020/04/25 14:40:11 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.17 2020/04/27 07:37:01 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -814,19 +814,23 @@ urtwn_alloc_rx_list(struct urtwn_softc *
 static void
 urtwn_free_rx_list(struct urtwn_softc *sc)
 {
+	struct urtwn_rx_data *data = NULL;
 	struct usbd_xfer *xfer;
-	size_t i;
 
 	DPRINTFN(DBG_FN, ("%s: %s\n", device_xname(sc->sc_dev), __func__));
 
 	/* NB: Caller must abort pipe first. */
 	for (size_t j = 0; j < sc->rx_npipe; j++) {
-		for (i = 0; i < URTWN_RX_LIST_COUNT; i++) {
+		mutex_enter(>sc_rx_mtx); 
+		while (!TAILQ_EMPTY(>rx_free_list[j])) {
+			data = TAILQ_FIRST(>rx_free_list[j]);
+			TAILQ_REMOVE(>rx_free_list[j], data, next);
 			CTASSERT(sizeof(xfer) == sizeof(void *));
-			xfer = atomic_swap_ptr(>rx_data[j][i].xfer, NULL);
+			xfer = atomic_swap_ptr(>xfer, NULL);
 			if (xfer != NULL)
 usbd_destroy_xfer(xfer);
 		}
+		mutex_exit(>sc_rx_mtx);
 	}
 }
 
@@ -875,19 +879,23 @@ urtwn_alloc_tx_list(struct urtwn_softc *
 static void
 urtwn_free_tx_list(struct urtwn_softc *sc)
 {
+	struct urtwn_tx_data *data = NULL;
 	struct usbd_xfer *xfer;
-	size_t i;
 
 	DPRINTFN(DBG_FN, ("%s: %s\n", device_xname(sc->sc_dev), __func__));
 
 	/* NB: Caller must abort pipe first. */
 	for (size_t j = 0; j < sc->tx_npipe; j++) {
-		for (i = 0; i < URTWN_TX_LIST_COUNT; i++) {
+		mutex_enter(>sc_tx_mtx); 
+		while (!TAILQ_EMPTY(>tx_free_list[j])) {
+			data = TAILQ_FIRST(>tx_free_list[j]);
+			TAILQ_REMOVE(>tx_free_list[j], data, next);
 			CTASSERT(sizeof(xfer) == sizeof(void *));
-			xfer = atomic_swap_ptr(>tx_data[j][i].xfer, NULL);
+			xfer = atomic_swap_ptr(>xfer, NULL);
 			if (xfer != NULL)
 usbd_destroy_xfer(xfer);
 		}
+		mutex_exit(>sc_tx_mtx);
 	}
 }
 



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 07:37:01 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Fix resource leak in rx/tx free lists.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.16 -r1.59.2.17 src/sys/dev/usb/if_urtwn.c

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



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-25 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Apr 25 14:40:12 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Remove configuring 40Mhz channels for now.

Avoid duplicate state transitions in urtwn_newstate.
Avoid changing channel parameters in urtwn_newstate.

Rework of tx desc parameters for all types of packets.

Don't create a percpuq as the stack is not expecting it //XXX not sure

Tested connections to an open 11n network with 8188CUS, 8192CU and 8192EU
usb adaptors.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.15 -r1.59.2.16 src/sys/dev/usb/if_urtwn.c

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.15 src/sys/dev/usb/if_urtwn.c:1.59.2.16
--- src/sys/dev/usb/if_urtwn.c:1.59.2.15	Sat Apr 25 09:32:16 2020
+++ src/sys/dev/usb/if_urtwn.c	Sat Apr 25 14:40:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.15 2020/04/25 09:32:16 nat Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.16 2020/04/25 14:40:11 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.15 2020/04/25 09:32:16 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.16 2020/04/25 14:40:11 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2173,7 +2173,7 @@ urtwn_newstate_cb(struct urtwn_softc *sc
 			/* 802.11b/g */
 			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 3);
 		} else /* IEEE_MODE_11NG */
-			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 12); /* MCS 0 */
+			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 11);
 
 		/* Enable Rx of data frames. */
 		urtwn_write_2(sc, R92C_RXFLTMAP2, 0x);
@@ -2227,7 +2227,7 @@ urtwn_newstate_cb(struct urtwn_softc *sc
 		urtwn_write_1(sc, R92C_T2T_SIFS + 1, sifs_time);
 
 		/* Initialize rate adaptation. */
-		if (ISSET(sc->chip, URTWN_CHIP_88E) ||
+		if (1 || ISSET(sc->chip, URTWN_CHIP_88E) ||
 		ISSET(sc->chip, URTWN_CHIP_92EU))
 			ni->ni_txrate = ni->ni_rates.rs_nrates - 1;
 		else
@@ -2311,6 +2311,8 @@ urtwn_newstate(struct ieee80211vap *vap,
 		break;
 
 	case IEEE80211_S_RUN:
+		if (nstate == IEEE80211_S_RUN)
+			break;
 		/* Turn link LED off. */
 		urtwn_set_led(sc, URTWN_LED_LINK, 0);
 
@@ -2328,9 +2330,11 @@ urtwn_newstate(struct ieee80211vap *vap,
 		urtwn_read_1(sc, R92C_BCN_CTRL) |
 		  R92C_BCN_CTRL_DIS_TSF_UDT0);
 
+#if 0
 		/* Back to 20MHz mode */
 		urtwn_set_chan(sc, ic->ic_curchan,
 		IEEE80211_HTINFO_2NDCHAN_NONE);
+#endif
 
 		if (ic->ic_opmode == IEEE80211_M_IBSS ||
 		ic->ic_opmode == IEEE80211_M_HOSTAP) {
@@ -2364,6 +2368,8 @@ urtwn_newstate(struct ieee80211vap *vap,
 		break;
 
 	case IEEE80211_S_SCAN:
+		if (ostate == IEEE80211_S_SCAN)
+			break;
 		if (ostate != IEEE80211_S_SCAN) {
 			/*
 			 * Begin of scanning
@@ -2404,8 +2410,10 @@ urtwn_newstate(struct ieee80211vap *vap,
 		urtwn_write_1(sc, R92C_TXPAUSE,
 		urtwn_read_1(sc, R92C_TXPAUSE) | 0x0f);
 
+#if 0
 		urtwn_set_chan(sc, ic->ic_curchan,
 		IEEE80211_HTINFO_2NDCHAN_NONE);
+#endif
 
 		/* Start periodic scan. */
 		if (!sc->sc_dying)
@@ -2413,6 +2421,8 @@ urtwn_newstate(struct ieee80211vap *vap,
 		break;
 
 	case IEEE80211_S_AUTH:
+		if (ostate == IEEE80211_S_AUTH)
+			break;
 		/* Set initial gain under link. */
 		reg = urtwn_bb_read(sc, R92C_OFDM0_AGCCORE1(0));
 		reg = RW(reg, R92C_OFDM0_AGCCORE1_GAIN, 0x32);
@@ -2432,24 +2442,32 @@ urtwn_newstate(struct ieee80211vap *vap,
 		urtwn_read_4(sc, R92C_RCR) &
 		  ~(R92C_RCR_CBSSID_DATA | R92C_RCR_CBSSID_BCN));
 
+#if 0
 		urtwn_set_chan(sc, ic->ic_curchan,
 		IEEE80211_HTINFO_2NDCHAN_NONE);
+#endif
 		break;
 
 	case IEEE80211_S_ASSOC:
 		break;
 
 	case IEEE80211_S_RUN:
+		if (ostate == IEEE80211_S_RUN)
+			break;
 		ni = vap->iv_bss;
 
+#if 0
 		/* XXX: Set 20MHz mode */
 		urtwn_set_chan(sc, ic->ic_curchan,
 		IEEE80211_HTINFO_2NDCHAN_NONE);
+#endif
 
 		if (ic->ic_opmode == IEEE80211_M_MONITOR) {
+#if 0
 			/* Back to 20MHz mode */
 			urtwn_set_chan(sc, ic->ic_curchan,
 			IEEE80211_HTINFO_2NDCHAN_NONE);
+#endif
 
 			/* Set media status to 'No Link'. */
 			urtwn_set_nettype0_msr(sc, R92C_CR_NETTYPE_NOLINK);
@@ -3108,9 +3126,6 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 		R92C_TXDW0_OWN | R92C_TXDW0_FSG | R92C_TXDW0_LSG);
 	}
 
-	if (ic->ic_curmode == IEEE80211_MODE_11NG)
-		txd->txdw5 |= htole32(R92C_TXDW5_SGI);
-
 	if (IEEE80211_IS_MULTICAST(wh->i_addr1))
 		txd->txdw0 |= htole32(R92C_TXDW0_BMCAST);
 
@@ -3120,15 +3135,21 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 		device_xname(sc->sc_dev), __func__, padsize));
 		txd->txdw1 |= htole32(SM(R92C_TXDW1_PKTOFF, (padsize / 8)));
 	}
+	if (ic->ic_curmode == IEEE80211_MODE_11B) {
+		raid = R92C_RAID_11B;
+		txd->txdw5 |= htole32(SM(R92C_TXDW5_DATARATE, 0));
+	} else if (ic->ic_curmode == IEEE80211_MODE_11G) {
+		

CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-25 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Apr 25 14:40:12 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Remove configuring 40Mhz channels for now.

Avoid duplicate state transitions in urtwn_newstate.
Avoid changing channel parameters in urtwn_newstate.

Rework of tx desc parameters for all types of packets.

Don't create a percpuq as the stack is not expecting it //XXX not sure

Tested connections to an open 11n network with 8188CUS, 8192CU and 8192EU
usb adaptors.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.15 -r1.59.2.16 src/sys/dev/usb/if_urtwn.c

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



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-25 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Apr 25 09:32:16 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Compete some more of 11n support.
htcaps and streams values from FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.14 -r1.59.2.15 src/sys/dev/usb/if_urtwn.c

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



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-25 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Apr 25 09:32:16 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Compete some more of 11n support.
htcaps and streams values from FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.14 -r1.59.2.15 src/sys/dev/usb/if_urtwn.c

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.14 src/sys/dev/usb/if_urtwn.c:1.59.2.15
--- src/sys/dev/usb/if_urtwn.c:1.59.2.14	Tue Apr 21 18:42:38 2020
+++ src/sys/dev/usb/if_urtwn.c	Sat Apr 25 09:32:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.14 2020/04/21 18:42:38 martin Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.15 2020/04/25 09:32:16 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.14 2020/04/21 18:42:38 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.15 2020/04/25 09:32:16 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -515,6 +515,21 @@ urtwn_attach(device_t parent, device_t s
 	IEEE80211_C_WME |		/* 802.11e */
 	IEEE80211_C_WPA;		/* 802.11i */
 
+	ic->ic_htcaps =
+	IEEE80211_HTC_HT |
+	IEEE80211_HTCAP_SHORTGI20 |		/* short GI in 20MHz */
+#if 0
+	IEEE80211_HTCAP_MAXAMSDU_3839 |	/* max A-MSDU length */
+#endif
+	IEEE80211_HTCAP_SMPS_OFF;		/* SM PS mode disabled */
+#if 0
+	IEEE80211_HTCAP_CHWIDTH40 |		/* 40 MHz channel width */
+	IEEE80211_HTCAP_SHORTGI40;		/* short GI in 40MHz */
+#endif
+
+	ic->ic_txstream = sc->ntxchains;
+	ic->ic_rxstream = sc->nrxchains;
+
 	ic->ic_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 
 #ifdef should_delete_NNN
@@ -3667,7 +3682,8 @@ urtwn_getradiocaps(struct ieee80211com *
 	setbit(bands, IEEE80211_MODE_11G);
 	setbit(bands, IEEE80211_MODE_11NG);
 	ieee80211_add_channel_list_2ghz(chans, maxchans, nchans,
-	urtwn_chan_2ghz, nitems(urtwn_chan_2ghz), bands, 0);
+	urtwn_chan_2ghz, nitems(urtwn_chan_2ghz), bands, IEEE80211_CHAN_HT20 |
+	IEEE80211_CHAN_HT40U | IEEE80211_CHAN_HT40D);
 }
 
 



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-19 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Apr 19 13:57:23 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Initial 11n support for urtwn.

Compile tested only... More to come.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.12 -r1.59.2.13 src/sys/dev/usb/if_urtwn.c

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.12 src/sys/dev/usb/if_urtwn.c:1.59.2.13
--- src/sys/dev/usb/if_urtwn.c:1.59.2.12	Fri Apr 17 13:44:37 2020
+++ src/sys/dev/usb/if_urtwn.c	Sun Apr 19 13:57:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.12 2020/04/17 13:44:37 martin Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.13 2020/04/19 13:57:23 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.12 2020/04/17 13:44:37 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.13 2020/04/19 13:57:23 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1651,9 +1651,10 @@ urtwn_ra_init(struct ieee80211vap *vap)
 	}
 	if (ic->ic_curmode == IEEE80211_MODE_11B) {
 		mode = R92C_RAID_11B;
-	} else {
+	} else if (ic->ic_curmode == IEEE80211_MODE_11G) {
 		mode = R92C_RAID_11BG;
-	}
+	} else /* mode = IEEE80211_MODE_11NG */
+		mode = R92C_RAID_11GN;
 	DPRINTFN(DBG_INIT, ("%s: %s: mode=%#x rates=%#x, basicrates=%#x, "
 	"maxrate=%zx, maxbasicrate=%zx\n",
 	device_xname(sc->sc_dev), __func__, mode, rates, basicrates,
@@ -2153,10 +2154,11 @@ urtwn_newstate_cb(struct urtwn_softc *sc
 
 		if (ic->ic_curmode == IEEE80211_MODE_11B) {
 			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 0);
-		} else {
+		} else if (ic->ic_curmode == IEEE80211_MODE_11G) {
 			/* 802.11b/g */
 			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 3);
-		}
+		} else /* IEEE_MODE_11NG */
+			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 12); /* MCS 0 */
 
 		/* Enable Rx of data frames. */
 		urtwn_write_2(sc, R92C_RXFLTMAP2, 0x);
@@ -2464,10 +2466,11 @@ urtwn_newstate(struct ieee80211vap *vap,
 
 		if (ic->ic_curmode == IEEE80211_MODE_11B) {
 			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 0);
-		} else {
+		} else if (ic->ic_curmode == IEEE80211_MODE_11G) {
 			/* 802.11b/g */
 			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 3);
-		}
+		} else /* IEEE_MODE_11NG */
+			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 12); /* MCS 0 */
 
 		/* Enable Rx of data frames. */
 		urtwn_write_2(sc, R92C_RXFLTMAP2, 0x);
@@ -3090,6 +3093,9 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 		R92C_TXDW0_OWN | R92C_TXDW0_FSG | R92C_TXDW0_LSG);
 	}
 
+	if (ic->ic_curmode == IEEE80211_MODE_11NG)
+		txd->txdw5 |= htole32(R92C_TXDW5_SGI);
+
 	if (IEEE80211_IS_MULTICAST(wh->i_addr1))
 		txd->txdw0 |= htole32(R92C_TXDW0_BMCAST);
 
@@ -3104,8 +3110,10 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 	type == IEEE80211_FC0_TYPE_DATA) {
 		if (ic->ic_curmode == IEEE80211_MODE_11B)
 			raid = R92C_RAID_11B;
-		else
+		else if (ic->ic_curmode == IEEE80211_MODE_11G)
 			raid = R92C_RAID_11BG;
+		else	/* IEEE80211_MODE_11NG */
+			raid = R92C_RAID_11GN;
 		DPRINTFN(DBG_TX,
 		("%s: %s: data packet: tid=%d, raid=%d\n",
 		device_xname(sc->sc_dev), __func__, tid, raid));
@@ -3657,6 +3665,7 @@ urtwn_getradiocaps(struct ieee80211com *
 	memset(bands, 0, sizeof(bands));
 	setbit(bands, IEEE80211_MODE_11B);
 	setbit(bands, IEEE80211_MODE_11G);
+	setbit(bands, IEEE80211_MODE_11NG);
 	ieee80211_add_channel_list_2ghz(chans, maxchans, nchans,
 	urtwn_chan_2ghz, nitems(urtwn_chan_2ghz), bands, 0);
 }



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-19 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Apr 19 13:57:23 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Initial 11n support for urtwn.

Compile tested only... More to come.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.12 -r1.59.2.13 src/sys/dev/usb/if_urtwn.c

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



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Apr 17 13:44:38 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Make it compilable with URTWN_DEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.11 -r1.59.2.12 src/sys/dev/usb/if_urtwn.c

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



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Apr 17 13:44:38 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Make it compilable with URTWN_DEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.11 -r1.59.2.12 src/sys/dev/usb/if_urtwn.c

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.11 src/sys/dev/usb/if_urtwn.c:1.59.2.12
--- src/sys/dev/usb/if_urtwn.c:1.59.2.11	Thu Apr 16 17:24:49 2020
+++ src/sys/dev/usb/if_urtwn.c	Fri Apr 17 13:44:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.11 2020/04/16 17:24:49 nat Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.12 2020/04/17 13:44:37 martin Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.11 2020/04/16 17:24:49 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.12 2020/04/17 13:44:37 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -3452,7 +3452,9 @@ urtwn_parent(struct ieee80211com *ic)
 static void
 urtwn_scan_start(struct ieee80211com *ic)
 {
-	//struct urtwn_softc *sc = ic->ic_softc;
+#ifdef URTWN_DEBUG
+	struct urtwn_softc *sc = ic->ic_softc;
+#endif
 	//uint32_t reg;
 	//int s;
 
@@ -3515,7 +3517,9 @@ urtwn_scan_start(struct ieee80211com *ic
 static void
 urtwn_scan_end(struct ieee80211com *ic)
 {
-	//struct urtwn_softc *sc = ic->ic_softc;
+#ifdef URTWN_DEBUG
+	struct urtwn_softc *sc = ic->ic_softc;
+#endif
 
 	DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
 



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Apr 16 15:33:08 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Use if_stat functions.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.9 -r1.59.2.10 src/sys/dev/usb/if_urtwn.c

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



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Apr 16 15:33:08 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Use if_stat functions.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.9 -r1.59.2.10 src/sys/dev/usb/if_urtwn.c

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.9 src/sys/dev/usb/if_urtwn.c:1.59.2.10
--- src/sys/dev/usb/if_urtwn.c:1.59.2.9	Mon Apr 13 08:04:49 2020
+++ src/sys/dev/usb/if_urtwn.c	Thu Apr 16 15:33:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.9 2020/04/13 08:04:49 martin Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.10 2020/04/16 15:33:07 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.9 2020/04/13 08:04:49 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.10 2020/04/16 15:33:07 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2762,7 +2762,7 @@ urtwn_rx_frame(struct urtwn_softc *sc, u
 		 */
 		DPRINTFN(DBG_RX, ("%s: %s: CRC error\n",
 		device_xname(sc->sc_dev), __func__));
-		ifp->if_ierrors++;
+		if_statinc(ifp, if_ierrors);
 		return;
 	}
 
@@ -2775,13 +2775,13 @@ urtwn_rx_frame(struct urtwn_softc *sc, u
 		DPRINTFN(DBG_RX, ("%s: %s: packet too short %d\n",
 		device_xname(sc->sc_dev), __func__, pktlen));
 		vap->iv_stats.is_rx_tooshort++;
-		ifp->if_ierrors++;
+		if_statinc(ifp,if_ierrors);
 		return;
 	}
 	if (__predict_false(pktlen > MCLBYTES)) {
 		DPRINTFN(DBG_RX, ("%s: %s: packet too big %d\n",
 		device_xname(sc->sc_dev), __func__, pktlen));
-		ifp->if_ierrors++;
+   	if_statinc(ifp, if_ierrors);
 		return;
 	}
 
@@ -2805,7 +2805,7 @@ urtwn_rx_frame(struct urtwn_softc *sc, u
 	if (__predict_false(m == NULL)) {
 		aprint_error_dev(sc->sc_dev, "couldn't allocate rx mbuf\n");
 		vap->iv_stats.is_rx_nobuf++;
-		ifp->if_ierrors++;
+   	if_statinc(ifp, if_ierrors);
 		return;
 	}
 	if (pktlen > (int)MHLEN) {
@@ -2815,7 +2815,7 @@ urtwn_rx_frame(struct urtwn_softc *sc, u
 			"couldn't allocate rx mbuf cluster\n");
 			m_freem(m);
 			vap->iv_stats.is_rx_nobuf++;
-			ifp->if_ierrors++;
+	if_statinc(ifp, if_ierrors);
 			return;
 		}
 	}
@@ -3000,13 +3000,13 @@ urtwn_txeof(struct usbd_xfer *xfer, void
 usbd_clear_endpoint_stall_async(pipe);
 			}
 			printf("ERROR1\n");
-			ifp->if_oerrors++;
+	if_statinc(ifp, if_oerrors);
 		}
 		splx(s);
 		return;
 	}
 
-	ifp->if_opackets++;
+	if_statinc(ifp, if_opackets);
 	urtwn_start(ifp); 
 	splx(s);
 
@@ -3308,7 +3308,7 @@ urtwn_start(struct ifnet *ifp)
 		if (m->m_len < (int)sizeof(*eh) &&
 		(m = m_pullup(m, sizeof(*eh))) == NULL) {
 			printf("ERROR6\n");
-			ifp->if_oerrors++;
+	if_statinc(ifp, if_oerrors);
 			continue;
 		}
 		eh = mtod(m, struct ether_header *);
@@ -3316,7 +3316,7 @@ urtwn_start(struct ifnet *ifp)
 		if (ni == NULL) {
 			m_freem(m);
 			printf("ERROR5\n");
-			ifp->if_oerrors++;
+	if_statinc(ifp, if_oerrors);
 			continue;
 		}
 
@@ -3327,7 +3327,7 @@ urtwn_start(struct ifnet *ifp)
 			m_freem(m);
 			ieee80211_free_node(ni);
 			printf("ERROR3\n");
-			ifp->if_oerrors++;
+	if_statinc(ifp, if_oerrors);
 			continue;
 		}
 		m_freem(m);
@@ -3352,7 +3352,7 @@ urtwn_watchdog(struct ifnet *ifp)
 			aprint_error_dev(sc->sc_dev, "device timeout\n");
 			/* urtwn_init(ifp); XXX needs a process context! */
 			printf("ERROR2\n");
-			ifp->if_oerrors++;
+	if_statinc(ifp, if_oerrors);
 			return;
 		}
 		ifp->if_timer = 1;
@@ -3449,7 +3449,7 @@ urtwn_parent(struct ieee80211com *ic)
 static void
 urtwn_scan_start(struct ieee80211com *ic)
 {
-	struct urtwn_softc *sc = ic->ic_softc;
+	//struct urtwn_softc *sc = ic->ic_softc;
 	//uint32_t reg;
 	//int s;
 
@@ -3512,7 +3512,7 @@ urtwn_scan_start(struct ieee80211com *ic
 static void
 urtwn_scan_end(struct ieee80211com *ic)
 {
-	struct urtwn_softc *sc = ic->ic_softc;
+	//struct urtwn_softc *sc = ic->ic_softc;
 
 	DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
 
@@ -3565,9 +3565,9 @@ urtwn_transmit(struct ieee80211com *ic, 
 
 IF_ENQUEUE(>sc_sendq, m);
 
-vap->iv_ifp->if_obytes += pktlen;
+if_statadd(vap->iv_ifp, if_obytes, pktlen);
 if (mcast)
-vap->iv_ifp->if_omcasts++;
+if_statinc(vap->iv_ifp, if_omcasts);
 
 if ((vap->iv_ifp->if_flags & IFF_OACTIVE) == 0)
 if_start_lock(vap->iv_ifp);
@@ -3626,7 +3626,7 @@ urtwn_raw_xmit(struct ieee80211_node *ni
 	error = urtwn_tx(sc, m, ni, data);
 	if (error != 0) {
 		printf("ERROR3\n");
-		vap->iv_ifp->if_oerrors++;
+if_statinc(vap->iv_ifp, if_oerrors);
 	} else {
 		sc->tx_timer = 5;
 		

CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Apr 16 15:32:24 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwnvar.h

Log Message:
Pull in 


To generate a diff of this commit:
cvs rdiff -u -r1.10.16.5 -r1.10.16.6 src/sys/dev/usb/if_urtwnvar.h

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



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Apr 16 15:32:24 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwnvar.h

Log Message:
Pull in 


To generate a diff of this commit:
cvs rdiff -u -r1.10.16.5 -r1.10.16.6 src/sys/dev/usb/if_urtwnvar.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_urtwnvar.h
diff -u src/sys/dev/usb/if_urtwnvar.h:1.10.16.5 src/sys/dev/usb/if_urtwnvar.h:1.10.16.6
--- src/sys/dev/usb/if_urtwnvar.h:1.10.16.5	Mon Apr 13 08:04:49 2020
+++ src/sys/dev/usb/if_urtwnvar.h	Thu Apr 16 15:32:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwnvar.h,v 1.10.16.5 2020/04/13 08:04:49 martin Exp $	*/
+/*	$NetBSD: if_urtwnvar.h,v 1.10.16.6 2020/04/16 15:32:24 nat Exp $	*/
 /*	$OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $	*/
 
 /*-
@@ -19,6 +19,8 @@
 #ifndef _IF_URTWNVAR_H_
 #define _IF_URTWNVAR_H_
 
+#include 
+
 /*
  * Driver definitions.
  */



CVS commit: [phil-wifi] src/sys/dev/usb

2019-06-26 Thread Phil Nelson
Module Name:src
Committed By:   phil
Date:   Wed Jun 26 16:51:29 UTC 2019

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Remove extra if_register() call.
Move temporary call to vap_create() to end of attach to make sure
attach works when vap_create() will not be called as part of attach.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.7 -r1.59.2.8 src/sys/dev/usb/if_urtwn.c

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



CVS commit: [phil-wifi] src/sys/dev/usb

2019-06-26 Thread Phil Nelson
Module Name:src
Committed By:   phil
Date:   Wed Jun 26 16:51:29 UTC 2019

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Remove extra if_register() call.
Move temporary call to vap_create() to end of attach to make sure
attach works when vap_create() will not be called as part of attach.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.7 -r1.59.2.8 src/sys/dev/usb/if_urtwn.c

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.7 src/sys/dev/usb/if_urtwn.c:1.59.2.8
--- src/sys/dev/usb/if_urtwn.c:1.59.2.7	Mon Jun 10 22:07:34 2019
+++ src/sys/dev/usb/if_urtwn.c	Wed Jun 26 16:51:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.7 2019/06/10 22:07:34 christos Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.8 2019/06/26 16:51:29 phil Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.7 2019/06/10 22:07:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.8 2019/06/26 16:51:29 phil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -529,8 +529,8 @@ urtwn_attach(device_t parent, device_t s
 #else
 	urtwn_getradiocaps(ic, IEEE80211_CHAN_MAX, >ic_nchans, 
 	ic->ic_channels);
-#endif	
-
+#endif
+	/* XXX issues here ...  Figure out proper attach and vap creation */
 	ieee80211_ifattach(ic);
 
 	/* override default methods NNN Need more here? */
@@ -547,29 +547,6 @@ urtwn_attach(device_t parent, device_t s
 	ic->ic_raw_xmit = urtwn_raw_xmit;
 	ic->ic_getradiocaps = urtwn_getradiocaps;
 	
-
-	/* How should this get called the first time?  Not here? */
-	// uint8_t bssid[IEEE80211_ADDR_LEN] = {0};
-
-	struct ieee80211vap *vap =
-	urtwn_vap_create(ic, device_xname(sc->sc_dev),
-	device_unit(sc->sc_dev), IEEE80211_M_STA,
-	IEEE80211_CLONE_MACADDR, ic->ic_macaddr, ic->ic_macaddr);
-
-	if (vap == NULL) {
-		/* Didn't work ... now what! */
-		printf ("NNN vap_create didn't work ...\n");
-		ieee80211_ifdetach(ic);
-		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_drvbpf);
-
 	sc->sc_rxtap_len = sizeof(sc->sc_rxtapu);
 	sc->sc_rxtap.wr_ihdr.it_len = htole16(sc->sc_rxtap_len);
 	sc->sc_rxtap.wr_ihdr.it_present = htole32(URTWN_RX_RADIOTAP_PRESENT);
@@ -578,10 +555,6 @@ urtwn_attach(device_t parent, device_t s
 	sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len);
 	sc->sc_txtap.wt_ihdr.it_present = htole32(URTWN_TX_RADIOTAP_PRESENT);
 
-	struct ifnet *ifp = vap->iv_ifp;
-	ifp->if_percpuq = if_percpuq_create(ifp);
-	if_register(ifp);
-
 	ieee80211_announce(ic);
 
 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
@@ -590,6 +563,21 @@ urtwn_attach(device_t parent, device_t s
 		aprint_error_dev(self, "couldn't establish power handler\n");
 
 	SET(sc->sc_flags, URTWN_FLAG_ATTACHED);
+
+	/* Should be called via an IOCTL.  Temp call here for now. */
+
+	struct ieee80211vap *vap =
+	urtwn_vap_create(ic, device_xname(sc->sc_dev),
+	device_unit(sc->sc_dev), IEEE80211_M_STA,
+	IEEE80211_CLONE_MACADDR, ic->ic_macaddr, ic->ic_macaddr);
+
+	if (vap == NULL) {
+		/* Didn't work ... now what! */
+		printf ("NNN vap_create didn't work ...\n");
+		ieee80211_ifdetach(ic);
+		goto fail;
+	}
+	
 	return;
 
  fail:
@@ -3403,6 +3391,7 @@ urtwn_vap_create(struct ieee80211com *ic
 	vap->iv_reset = urtwn_reset;
 
 	ifp = vap->iv_ifp;
+if_initialize(ifp);
 	ifp->if_init = urtwn_init;
 	ifp->if_ioctl = urtwn_ioctl;
 	ifp->if_start = urtwn_start;
@@ -3411,6 +3400,8 @@ urtwn_vap_create(struct ieee80211com *ic
 	// IFQ_SET_READY(>if_snd);
 	memcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
 
+	ifp->if_percpuq = if_percpuq_create(ifp);
+
 	/* Override state transition machine. */
 	/* NNN --- many possible newstate machines ... issue! */
 	sc->sc_newstate = vap->iv_newstate;
@@ -3421,6 +3412,11 @@ urtwn_vap_create(struct ieee80211com *ic
 	ieee80211_media_status, macaddr);
 	ic->ic_opmode = opmode;
 
+	/* Attach the packet filter */
+	bpf_attach2(vap->iv_ifp, DLT_IEEE802_11_RADIO,
+	sizeof(struct ieee80211_frame) + IEEE80211_RADIOTAP_HDRLEN,
+	>sc_drvbpf);
+
 	return vap;
 }
 
@@ -3610,7 +3606,7 @@ urtwn_raw_xmit(struct ieee80211_node *ni
 
 	DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
 
-	KASSERT(vap != NULL);  // NNN need these?
+	KASSERT(vap != NULL);   /*  NNN need these? */
 	KASSERT(ic != NULL);
 	KASSERT(sc != NULL);
 	KASSERT(m != NULL);
@@ -3628,8 +3624,8 @@ urtwn_raw_xmit(struct ieee80211_node *ni
 
 	error = urtwn_tx(sc, m, ni, data);
 	if (error != 0) {
-			printf("ERROR3\n");
-			vap->iv_ifp->if_oerrors++;
+		printf("ERROR3\n");
+