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/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;