Update to Version 0.8.24 from BRCM

- Add 'conc_priority' command
- Fix handling a single channel concurrency case: If conc_priority
  is not set, advertise the frequency conflict to the framework and
  disable the new connection attempted
- When P2P Interface gets removed due to single channel frequency
  conflict, show GROUP_REMOVE reason=FREQ_CONFLICT
- Fix sched scan processing

Change-Id: Ie6fe105cebd379a0a9c49ace62d2e48e71571107
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index ff3486e..d75b8fb 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -3169,7 +3169,21 @@
 		}
 		return 0;
 	}
-
+#ifdef ANDROID_P2P
+	if (os_strcmp(cmd, "conc_priority") == 0) {
+		if(os_strncmp(cmd+strlen("conc_priority")+1, "sta", 3) == 0)
+			os_strncpy(wpa_s->global->conc_priority, "sta", 3);
+		else if(os_strncmp(cmd+strlen("conc_priority")+1, "p2p", 3) == 0)
+			os_strncpy(wpa_s->global->conc_priority, "p2p", 3);
+		else {
+			wpa_printf(MSG_ERROR, " conc_priority arg should be either sta or p2p");
+			return -1;
+		}
+		wpa_printf(MSG_DEBUG, "Single Channel Concurrency: Prioritize %s",
+			   wpa_s->global->conc_priority);
+		return 0;
+	}
+#endif
 	if (os_strcmp(cmd, "force_long_sd") == 0) {
 		wpa_s->force_long_sd = atoi(param);
 		return 0;
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 3aba246..5e7edc8 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -257,6 +257,11 @@
 	case P2P_GROUP_REMOVAL_UNAVAILABLE:
 		reason = " reason=UNAVAILABLE";
 		break;
+#ifdef ANDROID_P2P
+	case P2P_GROUP_REMOVAL_FREQ_CONFLICT:
+		reason = " reason=FREQ_CONFLICT";
+		break;
+#endif
 	default:
 		reason = "";
 		break;
@@ -805,9 +810,6 @@
 
 #define C(n) if (s->n) d->n = os_strdup(s->n)
 	C(device_name);
-#ifdef ANDROID_P2P
-	C(prioritize);
-#endif
 	C(manufacturer);
 	C(model_name);
 	C(model_number);
@@ -4458,10 +4460,13 @@
 			/* If GO cannot be moved or if the conflicting interface is a
 			 * P2P Client, remove the interface depending up on the connection
 			 * priority */
-			if(wpas_is_interface_prioritized(wpa_s)) {
-				/* Newly requested connection has priority over existing 
+			if(!wpas_is_p2p_prioritized(wpa_s)) {
+				/* STA connection has priority over existing 
 				 * P2P connection. So remove the interface */
-				wpas_p2p_disconnect(iface);
+				wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to Single channel"
+						"concurrent mode frequency conflict");
+				iface->removal_reason = P2P_GROUP_REMOVAL_FREQ_CONFLICT;
+				wpas_p2p_group_delete(iface);
 			} else {
 				/* Existing connection has the priority. Disable the newly
                  * selected network and let the application know about it.
diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c
index 21cde92..5aee7ff 100644
--- a/wpa_supplicant/scan.c
+++ b/wpa_supplicant/scan.c
@@ -238,13 +238,18 @@
 				int interval)
 {
 	int ret;
-
+#ifndef ANDROID_P2P
 	wpa_supplicant_notify_scanning(wpa_s, 1);
+#endif
 	ret = wpa_drv_sched_scan(wpa_s, params, interval * 1000);
 	if (ret)
 		wpa_supplicant_notify_scanning(wpa_s, 0);
-	else
+	else {
 		wpa_s->sched_scanning = 1;
+#ifdef ANDROID_P2P
+		wpa_supplicant_notify_scanning(wpa_s, 1);
+#endif
+	}
 
 	return ret;
 }
@@ -782,9 +787,11 @@
 					sizeof(struct wpa_driver_scan_filter));
 
 	prev_state = wpa_s->wpa_state;
+#ifndef ANDROID_P2P
 	if (wpa_s->wpa_state == WPA_DISCONNECTED ||
 	    wpa_s->wpa_state == WPA_INACTIVE)
 		wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
+#endif
 
 	/* Find the starting point from which to continue scanning */
 	ssid = wpa_s->conf->ssid;
@@ -939,7 +946,12 @@
 				    int scanning)
 {
 	if (wpa_s->scanning != scanning) {
+#ifdef ANDROID_P2P
+		if(!wpa_s->sched_scanning)
+			wpa_s->scanning = scanning;
+#else
 		wpa_s->scanning = scanning;
+#endif
 		wpas_notify_scanning(wpa_s);
 	}
 }
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index d5e5000..81d00f3 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -1420,6 +1420,7 @@
 			wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_FREQ_CONFLICT
 				" id=%d", ssid->id);
 			os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
+			return;
 		}
 	}
 #endif
@@ -3123,15 +3124,14 @@
 }
 
 #ifdef ANDROID_P2P
-int wpas_is_interface_prioritized(struct wpa_supplicant *wpa_s)
+int wpas_is_p2p_prioritized(struct wpa_supplicant *wpa_s)
 {
-	if(wpa_s->conf->prioritize &&
-		!os_strncmp(wpa_s->conf->prioritize, wpa_s->ifname, sizeof(wpa_s->ifname))) {
-		/* The given interface is prioritized */
-		wpa_printf(MSG_DEBUG, "Given interface (%s) is prioritized" , wpa_s->ifname);
+	if(os_strncmp(wpa_s->global->conc_priority, "p2p", 3) == 0)
 		return 1;
-	}
-	wpa_printf(MSG_DEBUG, "Given interface (%s) is not prioritized" , wpa_s->ifname);
-	return 0;
+	else if(os_strncmp(wpa_s->global->conc_priority, "sta", 3) == 0)
+		return 0;
+
+	/* IF conc_priority is not set, return -1 */
+	return -1;
 }
 #endif
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 484b650..74a0dde 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -219,6 +219,9 @@
 	struct dl_list p2p_srv_bonjour; /* struct p2p_srv_bonjour */
 	struct dl_list p2p_srv_upnp; /* struct p2p_srv_upnp */
 	int p2p_disabled;
+#ifdef ANDROID_P2P
+	char conc_priority[5]; /* "sta" or "p2p" */
+#endif
 	int cross_connection;
 };
 
@@ -600,7 +603,7 @@
 void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid);
 int wpas_driver_bss_selection(struct wpa_supplicant *wpa_s);
 #ifdef ANDROID_P2P
-int wpas_is_interface_prioritized(struct wpa_supplicant *wpa_s);
+int wpas_is_p2p_prioritized(struct wpa_supplicant *wpa_s);
 #endif
 
 /* events.c */