BRCM P2P update

- IFNAME for monitor interface is changed to m. from mon. This will
  give extra space for incrementing X in IFNAME (p2p-wlan0-X). Also, we
  have synced the reset of IFNAME w.r.t. monitor interface name.
- Fixed continuous P2P_DEV_FOUND events coming from GO. Removed the
  BRCM specific change for this.
- Fixed STATUS command for p2p interface.

Change-Id: I04210dd0b2bdba06b0192c0a61edfa0e5b47ab72
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/src/ap/wpa_auth.c b/src/ap/wpa_auth.c
index 3fbb88b..0836887 100644
--- a/src/ap/wpa_auth.c
+++ b/src/ap/wpa_auth.c
@@ -349,6 +349,10 @@
 		wpa_printf(MSG_INFO, "WPA: Not enough entropy in random pool "
 			   "for secure operations - update keys later when "
 			   "the first station connects");
+#ifdef ANDROID_BRCM_P2P_PATCH
+		os_free(group);
+		return NULL;
+#endif
 	}
 
 	/*
diff --git a/src/drivers/driver.h b/src/drivers/driver.h
index 232f31a..19f732d 100644
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -35,6 +35,14 @@
 #define HOSTAPD_CHAN_HT40MINUS 0x00000020
 #define HOSTAPD_CHAN_HT40 0x00000040
 
+#ifdef ANDROID_BRCM_P2P_PATCH
+/**
+ * Monitor interface name is derived from p2p interface name
+ * We need to reset p2p interface name early to take care of extra character in
+ */
+#define WPA_MONITOR_IFNAME_PREFIX	"m."
+#endif
+
 /**
  * struct hostapd_channel_data - Channel information
  */
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index ab20e8a..7b7e3fa 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -644,12 +644,12 @@
 	const struct ieee80211_mgmt *mgmt;
 	union wpa_event_data event;
 	u16 status;
-#ifdef ANDROID_BRCM_P2P_PATCH	
+#ifdef ANDROID_BRCM_P2P_PATCH
 	struct wpa_supplicant *wpa_s = drv->ctx;
 #endif
 
 	mgmt = (const struct ieee80211_mgmt *) frame;
-#if (defined (CONFIG_AP) || defined (HOSTAPD) ) && defined (ANDROID_BRCM_P2P_PATCH)	
+#if (defined (CONFIG_AP) || defined (HOSTAPD) ) && defined (ANDROID_BRCM_P2P_PATCH)
 	if (drv->nlmode == NL80211_IFTYPE_AP || drv->nlmode == NL80211_IFTYPE_P2P_GO) {
 		if (len < 24 + sizeof(mgmt->u.assoc_req)) {
 			wpa_printf(MSG_DEBUG, "nl80211: Too short association event "
@@ -696,7 +696,7 @@
 	}
 
 	event.assoc_info.freq = drv->assoc_freq;
-#if (defined (CONFIG_AP) || defined(HOSTAPD)) && defined (ANDROID_BRCM_P2P_PATCH)	
+#if (defined (CONFIG_AP) || defined(HOSTAPD)) && defined (ANDROID_BRCM_P2P_PATCH)
 	}
 #endif
 	wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event);
@@ -886,7 +886,7 @@
 		reason_code = le_to_host16(mgmt->u.deauth.reason_code);
 
 	if (type == EVENT_DISASSOC) {
-#ifdef ANDROID_BRCM_P2P_PATCH 
+#ifdef ANDROID_BRCM_P2P_PATCH
 		if (drv->nlmode == NL80211_IFTYPE_AP ||
 			drv->nlmode == NL80211_IFTYPE_P2P_GO) {
 			event.disassoc_info.addr = mgmt->sa;
@@ -900,7 +900,7 @@
 				mgmt->u.disassoc.variable;
 		}
 	} else {
-#ifdef ANDROID_BRCM_P2P_PATCH 		
+#ifdef ANDROID_BRCM_P2P_PATCH
 		if (drv->nlmode == NL80211_IFTYPE_AP ||
 			drv->nlmode == NL80211_IFTYPE_P2P_GO) {
 		event.deauth_info.addr = mgmt->sa;
@@ -3767,7 +3767,7 @@
 	int ret;
 	int beacon_set;
 	int ifindex = if_nametoindex(bss->ifname);
-#ifdef ANDROID_BRCM_P2P_PATCH 		
+#ifdef ANDROID_BRCM_P2P_PATCH
 		beacon_set = 1;
 #else
 		beacon_set = bss->beacon_set;
@@ -3833,7 +3833,7 @@
 				    NL80211_CHAN_HT40PLUS);
 			break;
 		default:
-#ifndef ANDROID_BRCM_P2P_PATCH 
+#ifndef ANDROID_BRCM_P2P_PATCH
 /* Should be change to HT20 as a default value because P2P firmware does not support 11n for BCM4329 */
 			NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
 				    NL80211_CHAN_HT20);
@@ -4346,8 +4346,11 @@
 	struct sockaddr_ll ll;
 	int optval;
 	socklen_t optlen;
-
+#ifdef ANDROID_BRCM_P2P_PATCH
+	snprintf(buf, IFNAMSIZ, "%s%s", WPA_MONITOR_IFNAME_PREFIX, drv->first_bss.ifname);
+#else
 	snprintf(buf, IFNAMSIZ, "mon.%s", drv->first_bss.ifname);
+#endif
 	buf[IFNAMSIZ - 1] = '\0';
 
 	drv->monitor_ifidx =
@@ -6138,7 +6141,7 @@
 
 	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
 	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
-#ifndef ANDROID_BRCM_P2P_PATCH	
+#ifndef ANDROID_BRCM_P2P_PATCH
 	NLA_PUT_U32(msg, NL80211_ATTR_DURATION, wait);
 #endif	
 	NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
@@ -6370,7 +6373,7 @@
 		goto out_err3;
 	}
 
-#ifdef ANDROID_BRCM_P2P_PATCH 
+#ifdef ANDROID_BRCM_P2P_PATCH
 	if (drv->nlmode != NL80211_IFTYPE_AP &&
 		drv->nlmode != NL80211_IFTYPE_P2P_GO) {
 		wpa_printf(MSG_DEBUG, "nl80211: probe_req_report control only "
diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index 7147e5c..bef3926 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -464,10 +464,6 @@
 
 	if (msg->capability) {
 		dev->info.dev_capab = msg->capability[0];
-#ifdef ANDROID_BRCM_P2P_PATCH
-	if( dev->info.group_capab != msg->capability[1])
-		dev->flags &= ~P2P_DEV_REPORTED;
-#endif	
 		dev->info.group_capab = msg->capability[1];
 	}
 
diff --git a/src/p2p/p2p_sd.c b/src/p2p/p2p_sd.c
index 926fc03..9e26873 100644
--- a/src/p2p/p2p_sd.c
+++ b/src/p2p/p2p_sd.c
@@ -451,7 +451,11 @@
 
 	p2p->pending_action_state = P2P_NO_PENDING_ACTION;
 	if (p2p_send_action(p2p, freq, dst, p2p->cfg->dev_addr,
+		#ifdef ANDROID_BRCM_P2P_PATCH
+			   p2p->cfg->p2p_dev_addr,
+		#else
 			    p2p->cfg->dev_addr,
+		#endif
 			    wpabuf_head(resp), wpabuf_len(resp), 200) < 0)
 		wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
 			"P2P: Failed to send Action frame");