Cumulative patch from commit 2cebdee66de6a1c6befe327c2348610478e06032

2cebdee Fix MinGW build
e4fa8b1 wpa_supplicant: Add Wake-on-WLAN configuration support
959214b Android: Use extended P2P functionality (ANDROID_P2P) for all vendors
9a41232 TDLS: Fully tear down existing link before setup
c04b465 TDLS: Disable links during AP deauth in external flow
b19719a TDLS: Make wpa_tdls_send_teardown() static
52f5877 nl80211: Take ownership of dynamically added interfaces
e390df0 nl80211: Cancel rfkill timeout on deinit
fa258a3 HS 2.0 R2: Fix writing of domain_suffix_match cred parameter
bb24229 TDLS: Pass peer's capability info to the driver in open mode

Change-Id: I20b4dba96c07a85cf7b9c9c4ae51bbf9f6f88540
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/src/rsn_supp/tdls.c b/src/rsn_supp/tdls.c
index ea29369..3b14656 100644
--- a/src/rsn_supp/tdls.c
+++ b/src/rsn_supp/tdls.c
@@ -84,6 +84,8 @@
 static void wpa_tdls_peer_free(struct wpa_sm *sm, struct wpa_tdls_peer *peer);
 static void wpa_tdls_disable_peer_link(struct wpa_sm *sm,
 				       struct wpa_tdls_peer *peer);
+static int wpa_tdls_send_teardown(struct wpa_sm *sm, const u8 *addr,
+				  u16 reason_code);
 
 
 #define TDLS_MAX_IE_LEN 80
@@ -230,9 +232,9 @@
 	struct wpa_tdls_peer *peer;
 
 	wpa_printf(MSG_DEBUG, "TDLS: TPK send dest=" MACSTR " action_code=%u "
-		   "dialog_token=%u status_code=%u msg_len=%u",
+		   "dialog_token=%u status_code=%u peer_capab=%u msg_len=%u",
 		   MAC2STR(dest), action_code, dialog_token, status_code,
-		   (unsigned int) msg_len);
+		   peer_capab, (unsigned int) msg_len);
 
 	if (wpa_tdls_send_tpk_msg(sm, dest, action_code, dialog_token,
 				  status_code, peer_capab, msg, msg_len)) {
@@ -677,7 +679,8 @@
 }
 
 
-int wpa_tdls_send_teardown(struct wpa_sm *sm, const u8 *addr, u16 reason_code)
+static int wpa_tdls_send_teardown(struct wpa_sm *sm, const u8 *addr,
+				  u16 reason_code)
 {
 	struct wpa_tdls_peer *peer;
 	struct wpa_tdls_ftie *ftie;
@@ -759,9 +762,6 @@
 			  reason_code, 0, rbuf, pos - rbuf);
 	os_free(rbuf);
 
-	/* clear the Peerkey statemachine */
-	wpa_tdls_peer_free(sm, peer);
-
 	return 0;
 }
 
@@ -1310,14 +1310,15 @@
 	}
 #endif /* CONFIG_TDLS_TESTING */
 
+skip_ies:
+
 	if (peer->vht_capabilities)
 		peer_capab |= TDLS_PEER_VHT;
-	else if (peer->ht_capabilities)
+	if (peer->ht_capabilities)
 		peer_capab |= TDLS_PEER_HT;
-	else if (peer->wmm_capable)
+	if (peer->wmm_capable)
 		peer_capab |= TDLS_PEER_WMM;
 
-skip_ies:
 	status = wpa_tdls_tpk_send(sm, src_addr, WLAN_TDLS_SETUP_CONFIRM,
 				   dtoken, 0, peer_capab, rbuf, pos - rbuf);
 	os_free(rbuf);
@@ -2462,7 +2463,8 @@
 		 * Disable previous link to allow renegotiation to be completed
 		 * on AP path.
 		 */
-		wpa_tdls_disable_peer_link(sm, peer);
+		wpa_tdls_do_teardown(sm, peer,
+				     WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
 	}
 }
 
@@ -2588,8 +2590,8 @@
 		wpa_printf(MSG_DEBUG, "TDLS: Tear down peer " MACSTR,
 			   MAC2STR(peer->addr));
 		if (sm->tdls_external_setup)
-			wpa_tdls_send_teardown(sm, peer->addr,
-					       WLAN_REASON_DEAUTH_LEAVING);
+			wpa_tdls_do_teardown(sm, peer,
+					     WLAN_REASON_DEAUTH_LEAVING);
 		else
 			wpa_sm_tdls_oper(sm, TDLS_TEARDOWN, peer->addr);