Index: madwifi-ng-r2568-20070710/ath/if_ath.c
===================================================================
--- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:45.406567742 +0200
+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:45.690583928 +0200
@@ -3384,7 +3384,9 @@
 		rfilt |= HAL_RX_FILTER_PROM;
 	if (ic->ic_opmode == IEEE80211_M_STA ||
 	    sc->sc_opmode == HAL_M_IBSS ||	/* NB: AHDEMO too */
-	    (sc->sc_nostabeacons) || sc->sc_scanning)
+	    (sc->sc_nostabeacons) || sc->sc_scanning ||
+		((ic->ic_opmode == IEEE80211_M_HOSTAP) &&
+		 (ic->ic_protmode != IEEE80211_PROT_NONE)))
 		rfilt |= HAL_RX_FILTER_BEACON;
 	if ((sc->sc_nmonvaps > 0) || ((sc->sc_nvaps > 0) && (sc->sc_nibssvaps > 0)))
 		rfilt |= (HAL_RX_FILTER_CONTROL | HAL_RX_FILTER_BEACON |
Index: madwifi-ng-r2568-20070710/net80211/ieee80211_input.c
===================================================================
--- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_input.c	2007-07-23 01:48:45.030546315 +0200
+++ madwifi-ng-r2568-20070710/net80211/ieee80211_input.c	2007-07-23 01:48:45.690583928 +0200
@@ -321,11 +321,12 @@
 				bssid = wh->i_addr3;
 			}
 			/*
-			 * Validate the bssid.
+			 * Validate the bssid. Let beacons get through though for 11g protection mode.
 			 */
 #ifdef ATH_SUPERG_XR
 			if (!IEEE80211_ADDR_EQ(bssid, vap->iv_bss->ni_bssid) &&
-			    !IEEE80211_ADDR_EQ(bssid, dev->broadcast)) {
+			    !IEEE80211_ADDR_EQ(bssid, dev->broadcast) &&
+				(subtype != IEEE80211_FC0_SUBTYPE_BEACON)) {
 				/*
 				 * allow MGT frames to vap->iv_xrvap.
 				 * this will allow roaming between  XR and normal vaps
@@ -344,7 +345,8 @@
 			}
 #else
 			if (!IEEE80211_ADDR_EQ(bssid, vap->iv_bss->ni_bssid) &&
-			    !IEEE80211_ADDR_EQ(bssid, dev->broadcast)) {
+			    !IEEE80211_ADDR_EQ(bssid, dev->broadcast) &&
+				(subtype != IEEE80211_FC0_SUBTYPE_BEACON)) {
 				/* not interested in */
 				IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
 					bssid, NULL, "%s", "not to bss");
@@ -2541,7 +2543,7 @@
 	u_int8_t *frm, *efrm;
 	u_int8_t *ssid, *rates, *xrates, *wpa, *rsn, *wme, *ath;
 	u_int8_t rate;
-	int reassoc, resp, allocbs = 0;
+	int reassoc, resp, allocbs = 0, has_erp = 0;
 	u_int8_t qosinfo;
 
 	wh = (struct ieee80211_frame *) skb->data;
@@ -2563,11 +2565,15 @@
 		 *    o station mode when associated (to collect state
 		 *      updates such as 802.11g slot time), or
 		 *    o adhoc mode (to discover neighbors)
+		 *    o ap mode in protection mode (beacons only)
 		 * Frames otherwise received are discarded.
 		 */
 		if (!((ic->ic_flags & IEEE80211_F_SCAN) ||
 		    (vap->iv_opmode == IEEE80211_M_STA && ni->ni_associd) ||
-		    vap->iv_opmode == IEEE80211_M_IBSS)) {
+		    (vap->iv_opmode == IEEE80211_M_IBSS) ||
+			((subtype == IEEE80211_FC0_SUBTYPE_BEACON) &&
+			 (vap->iv_opmode == IEEE80211_M_HOSTAP) &&
+			 (ic->ic_protmode != IEEE80211_PROT_NONE)))) {
 			vap->iv_stats.is_rx_mgtdiscard++;
 			return;
 		}
@@ -2650,6 +2656,7 @@
 					break;
 				}
 				scan.erp = frm[2];
+				has_erp = 1;
 				break;
 			case IEEE80211_ELEMID_RSN:
 				scan.rsn = frm;
@@ -2867,6 +2874,20 @@
 				ieee80211_bg_scan(vap);
 			return;
 		}
+
+		/* Update AP protection mode when in 11G mode */
+		if ((vap->iv_opmode == IEEE80211_M_HOSTAP) &&
+			IEEE80211_IS_CHAN_ANYG(ic->ic_curchan)) {
+
+			/* Assume no ERP IE == 11b AP */
+			if ((!has_erp || (has_erp && (scan.erp & IEEE80211_ERP_NON_ERP_PRESENT))) &&
+				!(ic->ic_flags & IEEE80211_F_USEPROT)) {
+
+				ic->ic_flags |= IEEE80211_F_USEPROT;
+				ic->ic_flags_ext |= IEEE80211_FEXT_ERPUPDATE;
+			}
+		}
+
 		/*
 		 * If scanning, just pass information to the scan module.
 		 */
Index: madwifi-ng-r2568-20070710/net80211/ieee80211_node.c
===================================================================
--- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_node.c	2007-07-23 01:48:42.330392441 +0200
+++ madwifi-ng-r2568-20070710/net80211/ieee80211_node.c	2007-07-23 01:48:45.694584154 +0200
@@ -332,10 +332,16 @@
 	/* Update country ie information */
 	ieee80211_build_countryie(ic);
 
-	if (IEEE80211_IS_CHAN_HALF(chan))
+	if (IEEE80211_IS_CHAN_HALF(chan)) {
 		ni->ni_rates = ic->ic_sup_half_rates;
-	else if (IEEE80211_IS_CHAN_QUARTER(chan))
+	} else if (IEEE80211_IS_CHAN_QUARTER(chan)) {
 		ni->ni_rates = ic->ic_sup_quarter_rates;
+	}
+
+	if ((vap->iv_flags & IEEE80211_F_PUREG) &&
+		IEEE80211_IS_CHAN_ANYG(chan)) {
+		ieee80211_setpuregbasicrates(&ni->ni_rates);
+	}
 
 	(void) ieee80211_sta_join1(PASS_NODE(ni));
 }
Index: madwifi-ng-r2568-20070710/net80211/ieee80211_proto.c
===================================================================
--- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_proto.c	2007-07-23 01:48:44.570520097 +0200
+++ madwifi-ng-r2568-20070710/net80211/ieee80211_proto.c	2007-07-23 01:48:45.718585522 +0200
@@ -586,6 +586,28 @@
 	{ 4, { 2, 4, 11, 22 } },	/* IEEE80211_MODE_TURBO_G (mixed b/g) */
 };
 
+static const struct ieee80211_rateset basicpureg[] = {
+    { 7, {2, 4, 11, 22, 12, 24, 48 } },
+};
+
+/*
+ * Mark basic rates for the 11g rate table based on the pureg setting
+ */
+void
+ieee80211_setpuregbasicrates(struct ieee80211_rateset *rs)
+{
+	int i, j;
+
+	for (i = 0; i < rs->rs_nrates; i++) {
+		rs->rs_rates[i] &= IEEE80211_RATE_VAL;
+		for (j = 0; j < basicpureg[0].rs_nrates; j++)
+			if (basicpureg[0].rs_rates[j] == rs->rs_rates[i]) {
+				rs->rs_rates[i] |= IEEE80211_RATE_BASIC;
+				break;
+			}
+	}
+}
+
 /*
  * Mark the basic rates for the 11g rate table based on the
  * specified mode.  For 11b compatibility we mark only 11b
Index: madwifi-ng-r2568-20070710/net80211/ieee80211_var.h
===================================================================
--- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_var.h	2007-07-23 01:48:44.622523064 +0200
+++ madwifi-ng-r2568-20070710/net80211/ieee80211_var.h	2007-07-23 01:48:45.734586433 +0200
@@ -592,6 +592,8 @@
 void ieee80211_build_countryie(struct ieee80211com *);
 int ieee80211_media_setup(struct ieee80211com *, struct ifmedia *, u_int32_t,
 	ifm_change_cb_t, ifm_stat_cb_t);
+void ieee80211_setpuregbasicrates(struct ieee80211_rateset *rs);
+
 
 /* Key update synchronization methods.  XXX should not be visible. */
 static __inline void