Cumulative patch from commit b19c098e75d1dfa681960d9656d36001464a746e

b19c098 Send authentication failure reason in wpas_auth_failed()
5cd0e22 P2P: Iterate through full pref_chan list in search of a valid channel
f41d55d hostapd: Check for overlapping 20 MHz BSS before starting 20/40 MHz BSS
5516ed3 WPS: Deinit before wpas_p2p_disconnect()
c70c375 SCARD: Fix GSM authentication on USIM
c78c6b7 WPS: Fix return value when context is not valid
388444e P2P: Modify the timeout for GO Negotiation on no concurrent session
7e68be3 P2P: Refrain from performing extended listen during PD
e9eb648 P2P: Reject P2P_FIND and P2P_LISTEN on disabled interface
c71c241 P2P: Clear P2P state if active interface is disabled
ad12f2f Add DRIVER_EVENT ctrl_iface command for testing purposes
3e66f78 P2P: Make sure GO start does not miss connect_without_scan
c7caac5 nl80211: Fix send_frame freq for IBSS
28fa4eb P2P: Fix scan optimization for GO during persistent group invocation

Change-Id: I5b4d46322641de1a2d87e50a7f5fdc97f2f30c38
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/src/ap/hw_features.c b/src/ap/hw_features.c
index b361834..4e66d1b 100644
--- a/src/ap/hw_features.c
+++ b/src/ap/hw_features.c
@@ -395,6 +395,36 @@
 }
 
 
+static int ieee80211n_check_20mhz_bss(struct wpa_scan_res *bss, int pri_freq,
+				      int start, int end)
+{
+	struct ieee802_11_elems elems;
+	struct ieee80211_ht_operation *oper;
+
+	if (bss->freq < start || bss->freq > end || bss->freq == pri_freq)
+		return 0;
+
+	ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
+	if (!elems.ht_capabilities) {
+		wpa_printf(MSG_DEBUG, "Found overlapping legacy BSS: "
+			   MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
+		return 1;
+	}
+
+	if (elems.ht_operation &&
+	    elems.ht_operation_len >= sizeof(*oper)) {
+		oper = (struct ieee80211_ht_operation *) elems.ht_operation;
+		if (oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK)
+			return 0;
+
+		wpa_printf(MSG_DEBUG, "Found overlapping 20 MHz HT BSS: "
+			   MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
+		return 1;
+	}
+	return 0;
+}
+
+
 static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
 				      struct wpa_scan_results *scan_res)
 {
@@ -418,6 +448,14 @@
 		int sec_chan, pri_chan;
 		struct ieee802_11_elems elems;
 
+		/* Check for overlapping 20 MHz BSS */
+		if (ieee80211n_check_20mhz_bss(bss, pri_freq, affected_start,
+					       affected_end)) {
+			wpa_printf(MSG_DEBUG,
+				   "Overlapping 20 MHz BSS is found");
+			return 0;
+		}
+
 		ieee80211n_get_pri_sec_chan(bss, &pri_chan, &sec_chan);
 
 		if (sec_chan) {