[WCNCR00144638] p2p: Add support to report all bss networks in p2p scan

[Description]
Add support to report all bss networks in p2p scan.

In mt7668 original design, when scan request is triggered from p2p
interface, only P2P networks will be reported to cfg80211 kernel in
scan result. For example "wpa_cli -i p2p0 scan" will only found P2P
devices in scan result.

And this change adds support to report all BSS networks found during scan
to cfg80211 kernel even scan request is trigger from p2p interface.
Usually it is fine to report all BSS networks to kernel as because
wpa_supplicant will filter P2P devices when doing P2P connections.
To set this feature, modify the new option: "CFG_P2P_SCAN_REPORT_ALL_BSS"
either in Makefile* or in config.h.
And the default behavior is "disable".

Change-Id: Ic6e3561ac7df2661ef7fb6261fa58b74ede63869
Signed-off-by: Sarick Jiang <sarick.jiang@mediatek.com>
CR-Id: WCNCR00144638
Feature: p2p
diff --git a/Makefile.ce b/Makefile.ce
index e2f0f2a..5045546 100644
--- a/Makefile.ce
+++ b/Makefile.ce
@@ -154,6 +154,9 @@
 
 CFG_SUPPORT_ROAMING=0
 
+# Report all bss networks to cfg80211 when do p2p scan
+CFG_P2P_SCAN_REPORT_ALL_BSS=0
+
 # Support to change sta, p2p, ap interface names
 # y: enable, n: disable
 # eg. insmod wlan_mt7668_usb.ko sta=wlan p2p=p2p ap=ap
@@ -228,6 +231,10 @@
 PLATFORM_FLAGS += -DCFG_SUPPORT_DFS_MASTER=$(CFG_SUPPORT_DFS_MASTER)
 endif
 
+ifneq ($(CFG_P2P_SCAN_REPORT_ALL_BSS),)
+PLATFORM_FLAGS += -DCFG_P2P_SCAN_REPORT_ALL_BSS=$(CFG_P2P_SCAN_REPORT_ALL_BSS)
+endif
+
 ##############################################################
 # Compile settings
 ##############################################################
diff --git a/Makefile.x86 b/Makefile.x86
index 102d793..81e3c66 100644
--- a/Makefile.x86
+++ b/Makefile.x86
@@ -68,6 +68,9 @@
 
 #CFG_SUPPORT_SINGLE_SKU_LOCAL_DB=0
 
+# Report all bss networks to cfg80211 when do p2p scan
+CFG_P2P_SCAN_REPORT_ALL_BSS=0
+
 # Support to change sta, p2p, ap interface names
 # y: enable, n: disable
 # eg. insmod wlan_mt76x8_usb.ko sta=wlan p2p=p2p ap=ap
@@ -133,6 +136,9 @@
 PLATFORM_FLAGS += -DCFG_DRIVER_INF_NAME_CHANGE
 endif
 
+ifneq ($(CFG_P2P_SCAN_REPORT_ALL_BSS),)
+PLATFORM_FLAGS += -DCFG_P2P_SCAN_REPORT_ALL_BSS=$(CFG_P2P_SCAN_REPORT_ALL_BSS)
+endif
 
 all: driver
 
diff --git a/include/config.h b/include/config.h
index 86fb9b4..3c4c318 100644
--- a/include/config.h
+++ b/include/config.h
@@ -530,6 +530,15 @@
  * Flags of Wi-Fi Direct support
  *------------------------------------------------------------------------------
  */
+/*------------------------------------------------------------------------------
+ * Support reporting all BSS networks to cfg80211 kernel when scan
+ * request is from P2P interface
+ * Originally only P2P networks will be reported when scan request is from p2p0
+ *------------------------------------------------------------------------------
+ */
+#ifndef CFG_P2P_SCAN_REPORT_ALL_BSS
+#define CFG_P2P_SCAN_REPORT_ALL_BSS            0
+#endif
 
 /*------------------------------------------------------------------------------
  * Flags for GTK rekey offload
diff --git a/include/nic/adapter.h b/include/nic/adapter.h
index 18dcf95..f60e48d 100644
--- a/include/nic/adapter.h
+++ b/include/nic/adapter.h
@@ -1053,6 +1053,7 @@
 
 #if CFG_ENABLE_WIFI_DIRECT
 	BOOLEAN fgIsP2PRegistered;
+	BOOLEAN p2p_scan_report_all_bss; /* flag to report all networks in p2p scan */
 	ENUM_NET_REG_STATE_T rP2PNetRegState;
 	/* BOOLEAN             fgIsWlanLaunched; */
 	P_P2P_INFO_T prP2pInfo;
diff --git a/mgmt/p2p_scan.c b/mgmt/p2p_scan.c
index d4d3fad..c15e9e5 100644
--- a/mgmt/p2p_scan.c
+++ b/mgmt/p2p_scan.c
@@ -118,7 +118,11 @@
 {
 	BOOLEAN fgIsSkipThisBeacon = FALSE;
 
-	if (prBssDesc->fgIsP2PPresent) {
+	/* Indicate network to kernel for P2P interface when:
+	  *     1. This is P2P network
+	  *     2. Driver is configured to report all networks
+	  */
+	if (prBssDesc->fgIsP2PPresent || prAdapter->p2p_scan_report_all_bss) {
 		if ((prBssDesc->fgIsConnected) &&	/* P2P GC connected. */
 		    ((prWlanBeaconFrame->u2FrameCtrl & MASK_FRAME_TYPE) == MAC_FRAME_BEACON)	/* TX Beacon */
 		    ) {
diff --git a/mgmt/scan.c b/mgmt/scan.c
index 67be935..c38a6c4 100644
--- a/mgmt/scan.c
+++ b/mgmt/scan.c
@@ -2544,7 +2544,9 @@
 
 			if ((prBssDesc->eBSSType == eBSSType)
 #if CFG_ENABLE_WIFI_DIRECT
-			    || ((eBSSType == BSS_TYPE_P2P_DEVICE) && (prBssDesc->fgIsP2PReport == TRUE))
+			    || ((eBSSType == BSS_TYPE_P2P_DEVICE) &&
+				    (prBssDesc->fgIsP2PReport == TRUE ||
+				     prAdapter->p2p_scan_report_all_bss))
 #endif
 			    ) {
 
@@ -2567,7 +2569,7 @@
 					}
 				} else {
 #if CFG_ENABLE_WIFI_DIRECT
-					if (prBssDesc->fgIsP2PReport == TRUE) {
+					if (prBssDesc->fgIsP2PReport == TRUE || prAdapter->p2p_scan_report_all_bss) {
 #endif
 						rChannelInfo.ucChannelNum = prBssDesc->ucChannelNum;
 						rChannelInfo.eBand = prBssDesc->eBand;
diff --git a/os/linux/gl_p2p_init.c b/os/linux/gl_p2p_init.c
index daa686e..ee6854d 100644
--- a/os/linux/gl_p2p_init.c
+++ b/os/linux/gl_p2p_init.c
@@ -157,6 +157,7 @@
 	}
 
 	prGlueInfo->prAdapter->fgIsP2PRegistered = TRUE;
+	prGlueInfo->prAdapter->p2p_scan_report_all_bss = CFG_P2P_SCAN_REPORT_ALL_BSS;
 	DBGLOG(P2P, INFO, "Launch success, fgIsP2PRegistered TRUE\n");
 	return TRUE;
 }
@@ -218,6 +219,7 @@
 
 	DBGLOG(P2P, INFO, "fgIsP2PRegistered FALSE\n");
 	prGlueInfo->prAdapter->fgIsP2PRegistered = FALSE;
+	prGlueInfo->prAdapter->p2p_scan_report_all_bss = FALSE;
 	glUnregisterP2P(prGlueInfo);
 	return TRUE;
 }