Accumulative patch from commit 9e4d304ed7e2516b92081a5fba7288715ebb

nl80211: Add debug print for cancel-frame-wait command
Avoid partial BSS entries in control interface
Mark last BSS entry by #### instead of ====
Add WPA_BSS_MASK_DELIM flag to BSS command
nl80211: Fix WDS STA handling with multiple BSS interfaces
Use scan results for reconnection
Interworking: Remove unused variable warnings
wpa_cli: Increase receive buffer from 2048 to 4096 bytes

Change-Id: I518e7e374a98cec542b673dd27348f5b469e5826
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/src/common/wpa_ctrl.h b/src/common/wpa_ctrl.h
index 77c48cf..dbabe8c 100644
--- a/src/common/wpa_ctrl.h
+++ b/src/common/wpa_ctrl.h
@@ -155,7 +155,7 @@
 
 /* BSS command information masks */
 
-#define WPA_BSS_MASK_ALL		0xFFFFFFFF
+#define WPA_BSS_MASK_ALL		0xFFFDFFFF
 #define WPA_BSS_MASK_ID			BIT(0)
 #define WPA_BSS_MASK_BSSID		BIT(1)
 #define WPA_BSS_MASK_FREQ		BIT(2)
@@ -173,6 +173,7 @@
 #define WPA_BSS_MASK_P2P_SCAN		BIT(14)
 #define WPA_BSS_MASK_INTERNETW		BIT(15)
 #define WPA_BSS_MASK_WIFI_DISPLAY	BIT(16)
+#define WPA_BSS_MASK_DELIM		BIT(17)
 
 
 /* wpa_supplicant/hostapd control interface access */
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index a134992..759862e 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -7918,7 +7918,7 @@
 		if (!if_nametoindex(name)) {
 			if (nl80211_create_iface(drv, name,
 						 NL80211_IFTYPE_AP_VLAN,
-						 NULL, 1) < 0)
+						 bss->addr, 1) < 0)
 				return -1;
 			if (bridge_ifname &&
 			    linux_br_add_if(drv->global->ioctl_sock,
@@ -8469,6 +8469,8 @@
 	if (!msg)
 		return;
 
+	wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
+		   (long long unsigned int) drv->send_action_cookie);
 	nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME_WAIT_CANCEL);
 
 	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 940cd74..ea6395e 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -3153,7 +3153,7 @@
 		if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
 			ret = os_snprintf(pos, end - pos, "[HS20]");
 			if (ret < 0 || ret >= end - pos)
-				return -1;
+				return 0;
 			pos += ret;
 		}
 #endif /* CONFIG_HS20 */
@@ -3201,7 +3201,7 @@
 		if (wfd) {
 			ret = os_snprintf(pos, end - pos, "wfd_subelems=");
 			if (ret < 0 || ret >= end - pos)
-				return pos - buf;
+				return 0;
 			pos += ret;
 
 			pos += wpa_snprintf_hex(pos, end - pos,
@@ -3211,7 +3211,7 @@
 
 			ret = os_snprintf(pos, end - pos, "\n");
 			if (ret < 0 || ret >= end - pos)
-				return pos - buf;
+				return 0;
 			pos += ret;
 		}
 	}
@@ -3244,12 +3244,12 @@
 	}
 #endif /* CONFIG_INTERWORKING */
 
-#ifdef ANDROID
-	ret = os_snprintf(pos, end - pos, "====\n");
-	if (ret < 0 || ret >= end - pos)
-		return 0;
-	pos += ret;
-#endif
+	if (mask & WPA_BSS_MASK_DELIM) {
+		ret = os_snprintf(pos, end - pos, "====\n");
+		if (ret < 0 || ret >= end - pos)
+			return 0;
+		pos += ret;
+	}
 
 	return pos - buf;
 }
@@ -3372,8 +3372,13 @@
 		ret += len;
 		buf += len;
 		buflen -= len;
-		if (bss == bsslast)
+		if (bss == bsslast) {
+			if ((mask & WPA_BSS_MASK_DELIM) && len &&
+			    (bss == dl_list_last(&wpa_s->bss_id,
+						 struct wpa_bss, list_id)))
+				os_snprintf(buf - 5, 5, "####\n");
 			break;
+		}
 		next = bss->list_id.next;
 		if (next == &wpa_s->bss_id)
 			break;
diff --git a/wpa_supplicant/interworking.c b/wpa_supplicant/interworking.c
index 3602b07..6fe762f 100644
--- a/wpa_supplicant/interworking.c
+++ b/wpa_supplicant/interworking.c
@@ -1326,10 +1326,11 @@
 static struct wpa_cred * interworking_credentials_available_3gpp(
 	struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
 {
-	struct wpa_cred *cred, *selected = NULL;
+	struct wpa_cred *selected = NULL;
+#ifdef INTERWORKING_3GPP
+	struct wpa_cred *cred;
 	int ret;
 
-#ifdef INTERWORKING_3GPP
 	if (bss->anqp == NULL || bss->anqp->anqp_3gpp == NULL)
 		return NULL;
 
diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index 0630a4b..662a131 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -403,11 +403,7 @@
 
 static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, char *cmd, int print)
 {
-#ifdef ANDROID
 	char buf[4096];
-#else		
-	char buf[2048];
-#endif	
 #if defined(CONFIG_P2P) && defined(ANDROID_P2P)
 	char _cmd[256];
 #endif
@@ -3455,11 +3451,7 @@
 #endif /* CONFIG_CTRL_IFACE_UNIX */
 
 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
-#ifdef ANDROID
-	char buf[4096], *pos;
-#else
 	char buf[2048], *pos;
-#endif
 	size_t len;
 	struct wpa_ctrl *ctrl;
 	int ret;
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index a9af2d6..9ef932a 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -3778,5 +3778,7 @@
 	wpa_s->extra_blacklist_count = 0;
 	wpa_s->disconnected = 0;
 	wpa_s->reassociate = 1;
-	wpa_supplicant_req_scan(wpa_s, 0, 0);
+
+	if (wpa_supplicant_fast_associate(wpa_s) != 1)
+		wpa_supplicant_req_scan(wpa_s, 0, 0);
 }