urtwn and hostap

Matthew Grooms mgrooms at shrew.net
Thu Sep 24 02:42:16 UTC 2015


On 9/21/2015 9:06 AM, Matthew Grooms wrote:
> On 9/21/2015 7:19 AM, Andriy Voskoboinyk wrote:
>>
>>> This patch doesn't manually generate a beacon frame using
>>> ieee80211_beacon_alloc so I assume that setting the MSR register using
>>> the appropriate value instructs the chip to handle that in hardware. I
>>> tested this on both my ESXi VM using USB passthru and my raspberry 
>>> pi 2.
>>> Both appear to work as expected but the connection seemed less 
>>> stable on
>>> the latter.
>>
>> Can you check this with tcpdump(1) or dumpcap(1) on the sta side?
>> (I have seen configurations, where STA's were associated with an AP
>> without beaconing).
>>
>
> I'll give that a try and report back.
>

I tried to look for beacon frames using tcpdump on another urtwn adapter 
but unfortunately it doesn't appear to be working. I see a "need 
promiscuous mode update callback" printed out on the console every time 
I try. I assume that's indicative of a problem. Is there something else 
I should try besides running the second adapter in monitor mode and then 
running tcpdump on the interface? I did see these when running tcpdump 
on the wlan0 hostap adapter itself ...

21:32:57.340541 8c:3a:e3:43:9a:b8 > ff:ff:ff:ff:ff:ff, 802.3, length 20: 
LLC, dsap Null (0x00) Individual, ssap Null (0x00) Command, ctrl 0x81f5: 
Supervisory, Receiver not Ready, rcv seq 64, Flags [Poll], length 6
21:32:57.340558 8c:3a:e3:43:9a:b8 > ff:ff:ff:ff:ff:ff, 802.3, length 20: 
LLC, dsap Null (0x00) Individual, ssap Null (0x00) Command, ctrl 0x81f5: 
Supervisory, Receiver not Ready, rcv seq 64, Flags [Poll], length 6

... so I wonder if your right about it not sending beacon frames 
properly or maybe I'd see them there as well.

>> About patch:
>>
>>> +        if (vap->iv_opmode ==IEEE80211_M_HOSTAP) {
>>> ...
>>> +            /* Allow Rx from any BSSID. */
>>> +            urtwn_write_4(sc, R92C_RCR,
>>> +                urtwn_read_4(sc, R92C_RCR) &
>>> +                ~(R92C_RCR_CBSSID_DATA | R92C_RCR_CBSSID_BCN));
>>
>> Is there any reason for that? (can be useful in ad-hoc mode,
>> but I'm not sure about hostap).
>>
>
> I'll try it without and report back. This came from the NetBSD patch.
>

The station wasn't able to associate with both bits stripped. It did 
work with the bssid data bit stripped, so the new patch reflects that. 
I'm not sure what the most appropriate comment update should be there so 
I left it as is.

>>> +            /* Set appropriate MSR bits */
>>> +            msr |= R92C_MSR_INFRA;
>>
>> Probably, R92C_MSR_AP should be used here instead.
>>
>
> Definitely. I must have fat fingered something when I was cleaning up 
> comments post testing. How embarrassing :/ I'll retest ( just to be 
> sure ) and then post a new patch.
>

Latest patch is attached.

-Matthew
-------------- next part --------------
Index: sys/dev/usb/wlan/if_urtwn.c
===================================================================
--- sys/dev/usb/wlan/if_urtwn.c	(revision 287980)
+++ sys/dev/usb/wlan/if_urtwn.c	(working copy)
@@ -430,6 +430,7 @@
 	ic->ic_caps =
 		  IEEE80211_C_STA		/* station mode */
 		| IEEE80211_C_MONITOR		/* monitor mode */
+		| IEEE80211_C_HOSTAP		/* HostAp mode supported */
 		| IEEE80211_C_SHPREAMBLE	/* short preamble supported */
 		| IEEE80211_C_SHSLOT		/* short slot time supported */
 		| IEEE80211_C_BGSCAN		/* capable of bg scanning */
@@ -1466,6 +1467,7 @@
 	struct ieee80211_node *ni;
 	enum ieee80211_state ostate;
 	uint32_t reg;
+	u_int8_t msr;
 
 	ostate = vap->iv_state;
 	DPRINTF("%s -> %s\n", ieee80211_state_name[ostate],
@@ -1547,6 +1549,16 @@
 			/* Enable Rx of data frames. */
 			urtwn_write_2(sc, R92C_RXFLTMAP2, 0xffff);
 
+			/* Allow Rx from any BSSID. */
+			urtwn_write_4(sc, R92C_RCR,
+			    urtwn_read_4(sc, R92C_RCR) &
+			    ~(R92C_RCR_CBSSID_DATA | R92C_RCR_CBSSID_BCN));
+
+			/* Accept Rx data/control/management frames */
+			urtwn_write_4(sc, R92C_RCR,
+			    urtwn_read_4(sc, R92C_RCR) |
+			    R92C_RCR_ADF | R92C_RCR_ACF | R92C_RCR_AMF);
+
 			/* Turn link LED on. */
 			urtwn_set_led(sc, URTWN_LED_LINK, 1);
 			break;
@@ -1553,6 +1565,7 @@
 		}
 
 		ni = ieee80211_ref_node(vap->iv_bss);
+
 		/* Set media status to 'Associated'. */
 		reg = urtwn_read_4(sc, R92C_CR);
 		reg = RW(reg, R92C_CR_NETTYPE, R92C_CR_NETTYPE_INFRA);
@@ -1576,14 +1589,48 @@
 		/* Set beacon interval. */
 		urtwn_write_2(sc, R92C_BCN_INTERVAL, ni->ni_intval);
 
-		/* Allow Rx from our BSSID only. */
-		urtwn_write_4(sc, R92C_RCR,
-		    urtwn_read_4(sc, R92C_RCR) |
-		    R92C_RCR_CBSSID_DATA | R92C_RCR_CBSSID_BCN);
+		/* Read current MSR value */
+		msr = urtwn_read_1(sc, R92C_MSR);
+		msr &= R92C_MSR_MASK;
 
-		/* Enable TSF synchronization. */
-		urtwn_tsf_sync_enable(sc);
+		if (vap->iv_opmode == IEEE80211_M_STA) {
+			/* Set station mode beacon parameter ??? */
+			urtwn_write_2(sc, R92C_BCNTCFG, 0x660f);
 
+			/* Allow Rx from our BSSID only. */
+			urtwn_write_4(sc, R92C_RCR,
+			    urtwn_read_4(sc, R92C_RCR) |
+			      R92C_RCR_CBSSID_DATA | R92C_RCR_CBSSID_BCN);
+
+			/* Enable TSF synchronization. */
+			urtwn_tsf_sync_enable(sc);
+
+			/* Set appropriate MSR bits */
+			msr |= R92C_MSR_INFRA;
+		}
+		if (vap->iv_opmode ==IEEE80211_M_HOSTAP) {
+			/* Set AP mode beacon parameter ??? */
+			urtwn_write_2(sc, R92C_BCNTCFG, 0x000f);
+
+			/* Allow Rx from any BSSID. */
+			urtwn_write_4(sc, R92C_RCR,
+			    urtwn_read_4(sc, R92C_RCR) &
+			      ~R92C_RCR_CBSSID_DATA);
+
+			/* Reset TSF timer to zero. */
+			reg = urtwn_read_4(sc, R92C_TCR);
+			reg &= ~0x01;
+			urtwn_write_4(sc, R92C_TCR, reg);
+			reg |= 0x01;
+			urtwn_write_4(sc, R92C_TCR, reg);
+
+			/* Set appropriate MSR bits */
+			msr |= R92C_MSR_AP;
+		}
+
+		/* Write modified MSR value */
+		urtwn_write_1(sc, R92C_MSR, msr);
+
 		urtwn_write_1(sc, R92C_SIFS_CCK + 1, 10);
 		urtwn_write_1(sc, R92C_SIFS_OFDM + 1, 10);
 		urtwn_write_1(sc, R92C_SPEC_SIFS + 1, 10);
@@ -1597,13 +1644,17 @@
 			    ni->ni_rates.rs_rates[ni->ni_rates.rs_nrates-1];
 		else
 			urtwn_ra_init(sc);
+
 		/* Turn link LED on. */
 		urtwn_set_led(sc, URTWN_LED_LINK, 1);
 
-		sc->avg_pwdb = -1;	/* Reset average RSSI. */
+		/* Reset average RSSI. */
+		sc->avg_pwdb = -1;
+
 		/* Reset temperature calibration state machine. */
 		sc->thcal_state = 0;
 		sc->thcal_lctemp = 0;
+
 		ieee80211_free_node(ni);
 		break;
 	default:
Index: sys/dev/usb/wlan/if_urtwnreg.h
===================================================================
--- sys/dev/usb/wlan/if_urtwnreg.h	(revision 287980)
+++ sys/dev/usb/wlan/if_urtwnreg.h	(working copy)
@@ -96,6 +96,7 @@
 #define R92C_SYS_CFG			0x0f0
 /* MAC General Configuration. */
 #define R92C_CR				0x100
+#define R92C_MSR			0x102
 #define R92C_PBP			0x104
 #define R92C_TRXDMA_CTRL		0x10c
 #define R92C_TRXFF_BNDY			0x114
@@ -203,6 +204,7 @@
 /* WMAC Configuration. */
 #define R92C_APSD_CTRL			0x600
 #define R92C_BWOPMODE			0x603
+#define R92C_TCR			0x604
 #define R92C_RCR			0x608
 #define R92C_RX_DRVINFO_SZ		0x60f
 #define R92C_MACID			0x610
@@ -394,6 +396,13 @@
 #define R92C_CR_NETTYPE_INFRA	2
 #define R92C_CR_NETTYPE_AP	3
 
+/* Bits for R92C_MSR. */
+#define R92C_MSR_NOLINK		0x00
+#define R92C_MSR_ADHOC		0x01
+#define R92C_MSR_INFRA		0x02
+#define R92C_MSR_AP		0x03
+#define R92C_MSR_MASK		(~R92C_MSR_AP)
+
 /* Bits for R92C_PBP. */
 #define R92C_PBP_PSRX_M		0x0f
 #define R92C_PBP_PSRX_S		0


More information about the freebsd-wireless mailing list