Cumulative patch from commit 594516b4c28a94ca686b17f1e463dfd6712b75a7

594516b Use monotonic clock for relative time for eloop if available
461e3eb Fix and work around some MinGW compilation issues
81cbc04 Fix compiler warning for OpenSSL without HAVE_OCSP
68d628a hostapd: Fix interface enabling/disabling and DFS
1cba9be STA: Cancel sched_scan while initiating wps_reassoc
215a02f Add Wi-Fi Direct to the build configuration example
ca9c14f dbus_new: Add documentation for D-Bus TDLS methods
6fc4848 P2P: Short scan wait to speed up the group re-invocation
93a06fe Fix QoS Map Configure frame use

Change-Id: Id76002ca7fa742b6533e7e592ffd3867886dc50e
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile
index 8dcb71b..f6a46d2 100644
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -113,6 +113,13 @@
 OBJS += ../src/utils/$(CONFIG_ELOOP).o
 OBJS_c += ../src/utils/$(CONFIG_ELOOP).o
 
+ifeq ($(CONFIG_ELOOP), eloop)
+# Using glibc < 2.17 requires -lrt for clock_gettime()
+LIBS += -lrt
+LIBS_c += -lrt
+LIBS_p += -lrt
+endif
+
 ifdef CONFIG_ELOOP_POLL
 CFLAGS += -DCONFIG_ELOOP_POLL
 endif
diff --git a/wpa_supplicant/android.config b/wpa_supplicant/android.config
index b3107ee..e9d6f2e 100644
--- a/wpa_supplicant/android.config
+++ b/wpa_supplicant/android.config
@@ -509,9 +509,12 @@
 # more information on P2P operations.
 CONFIG_P2P=y
 
+# Enable TDLS support
 CONFIG_TDLS=y
 
-#Enable Wifi Display
+# Wi-Fi Direct
+# This can be used to enable Wi-Fi Direct extensions for P2P using an external
+# program to control the additional information exchanges in the messages.
 CONFIG_WIFI_DISPLAY=y
 
 # Autoscan
diff --git a/wpa_supplicant/defconfig b/wpa_supplicant/defconfig
index 8ccff88..ea0db04 100644
--- a/wpa_supplicant/defconfig
+++ b/wpa_supplicant/defconfig
@@ -518,6 +518,11 @@
 # Enable TDLS support
 #CONFIG_TDLS=y
 
+# Wi-Fi Direct
+# This can be used to enable Wi-Fi Direct extensions for P2P using an external
+# program to control the additional information exchanges in the messages.
+#CONFIG_WIFI_DISPLAY=y
+
 # Autoscan
 # This can be used to enable automatic scan support in wpa_supplicant.
 # See wpa_supplicant.conf for more information on autoscan usage.
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 31c5baa..ed8cd23 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -1353,10 +1353,12 @@
 			if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
 				return 0;
 
-			if (wpa_s->p2p_in_provisioning) {
+			if (wpa_s->p2p_in_provisioning ||
+			    wpa_s->show_group_started) {
 				/*
 				 * Use shorter wait during P2P Provisioning
-				 * state to speed up group formation.
+				 * state and during P2P join-a-group operation
+				 * to speed up group formation.
 				 */
 				timeout_sec = 0;
 				timeout_usec = 250000;
@@ -3077,12 +3079,15 @@
 		if (data->rx_action.category == WLAN_ACTION_QOS &&
 		    data->rx_action.len >= 1 &&
 		    data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
+			const u8 *pos = data->rx_action.data + 1;
+			size_t len = data->rx_action.len - 1;
 			wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
 				MACSTR, MAC2STR(data->rx_action.sa));
-			if (os_memcmp(data->rx_action.sa, wpa_s->bssid, ETH_ALEN)
-			    == 0)
-				wpas_qos_map_set(wpa_s, data->rx_action.data + 1,
-						 data->rx_action.len - 1);
+			if (os_memcmp(data->rx_action.sa, wpa_s->bssid,
+				      ETH_ALEN) == 0 &&
+			    len > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
+			    pos[1] <= len - 2 && pos[1] >= 16)
+				wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
 			break;
 		}
 #endif /* CONFIG_INTERWORKING */
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index b877cf5..4a34b34 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -4824,10 +4824,10 @@
 	if (params->passphrase)
 		ssid->passphrase = os_strdup(params->passphrase);
 
-	wpa_supplicant_select_network(wpa_s, ssid);
-
 	wpa_s->show_group_started = 1;
 
+	wpa_supplicant_select_network(wpa_s, ssid);
+
 	return 0;
 }
 
diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c
index a9c53d7..6891083 100644
--- a/wpa_supplicant/scan.c
+++ b/wpa_supplicant/scan.c
@@ -884,7 +884,7 @@
 
 void wpa_supplicant_update_scan_int(struct wpa_supplicant *wpa_s, int sec)
 {
-	struct os_time remaining, new_int;
+	struct os_reltime remaining, new_int;
 	int cancelled;
 
 	cancelled = eloop_cancel_timeout_one(wpa_supplicant_scan, wpa_s, NULL,
@@ -892,7 +892,7 @@
 
 	new_int.sec = sec;
 	new_int.usec = 0;
-	if (cancelled && os_time_before(&remaining, &new_int)) {
+	if (cancelled && os_reltime_before(&remaining, &new_int)) {
 		new_int.sec = remaining.sec;
 		new_int.usec = remaining.usec;
 	}
diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c
index 4c40dac..0b3c892 100644
--- a/wpa_supplicant/wps_supplicant.c
+++ b/wpa_supplicant/wps_supplicant.c
@@ -1052,6 +1052,8 @@
 	wpa_s->normal_scans = 0;
 	wpa_s->wps_success = 0;
 	wpa_s->blacklist_cleared = 0;
+
+	wpa_supplicant_cancel_sched_scan(wpa_s);
 	wpa_supplicant_req_scan(wpa_s, 0, 0);
 }