Snap for 10453563 from c3547db081935aaf334d82eb29f562039bcc23b9 to mainline-tzdata5-release

Change-Id: Ibfc8c29e5c1bc23b9ef5aec30105c08752dec129
diff --git a/src/drivers/driver_nl80211_event.c b/src/drivers/driver_nl80211_event.c
index 8b0275a..14d7842 100644
--- a/src/drivers/driver_nl80211_event.c
+++ b/src/drivers/driver_nl80211_event.c
@@ -3185,6 +3185,8 @@
 {
 	const u8 *addr;
 	union wpa_event_data event;
+	const u8 *connected_addr = drv->sta_mlo_info.valid_links ?
+				drv->sta_mlo_info.ap_mld_addr : drv->bssid;
 
 	os_memset(&event, 0, sizeof(event));
 
@@ -3196,11 +3198,11 @@
 	}
 
 	addr = nla_data(tb[NL80211_ATTR_MAC]);
-	if (os_memcmp(addr, drv->bssid, ETH_ALEN) != 0) {
+	if (os_memcmp(addr, connected_addr, ETH_ALEN) != 0) {
 		wpa_printf(MSG_DEBUG,
 			   "nl80211: Ignore port authorized event for " MACSTR
 			   " (not the currently connected BSSID " MACSTR ")",
-			   MAC2STR(addr), MAC2STR(drv->bssid));
+			   MAC2STR(addr), MAC2STR(connected_addr));
 		return;
 	}
 
diff --git a/wpa_supplicant/aidl/aidl.cpp b/wpa_supplicant/aidl/aidl.cpp
index 614d66d..6a22a2a 100644
--- a/wpa_supplicant/aidl/aidl.cpp
+++ b/wpa_supplicant/aidl/aidl.cpp
@@ -1074,6 +1074,17 @@
 	return aidl_manager->getCertificate(alias, value);
 }
 
+ssize_t wpas_aidl_list_aliases(const char *prefix, char ***aliases)
+{
+	AidlManager *aidl_manager = AidlManager::getInstance();
+	if (!aidl_manager)
+		return -1;
+
+	wpa_printf(MSG_INFO, "Requesting aliases from framework");
+
+	return aidl_manager->listAliases(prefix, aliases);
+}
+
 void wpas_aidl_notify_qos_policy_scs_response(struct wpa_supplicant *wpa_s,
 		unsigned int count, int **scs_resp)
 {
diff --git a/wpa_supplicant/aidl/aidl.h b/wpa_supplicant/aidl/aidl.h
index f4afc7e..f9b374e 100644
--- a/wpa_supplicant/aidl/aidl.h
+++ b/wpa_supplicant/aidl/aidl.h
@@ -146,6 +146,7 @@
 	void wpas_aidl_notify_qos_policy_request(struct wpa_supplicant *wpa_s,
 		struct dscp_policy_data *policies, int num_policies);
 	ssize_t wpas_aidl_get_certificate(const char* alias, uint8_t** value);
+	ssize_t wpas_aidl_list_aliases(const char *prefix, char ***aliases);
 	void wpas_aidl_notify_qos_policy_scs_response(struct wpa_supplicant *wpa_s,
 		unsigned int count, int **scs_resp);
 #else   // CONFIG_CTRL_IFACE_AIDL
@@ -334,6 +335,10 @@
 {
 	return -1;
 }
+static ssize_t wpas_aidl_list_aliases(const char *prefix, char ***aliases)
+{
+	return -1;
+}
 static void wpas_aidl_notify_qos_policy_scs_response(struct wpa_supplicant *wpa_s,
 	unsigned int count, int **scs_resp) {}
 #endif  // CONFIG_CTRL_IFACE_AIDL
diff --git a/wpa_supplicant/aidl/aidl_manager.cpp b/wpa_supplicant/aidl/aidl_manager.cpp
index 89b5432..4d5ac29 100644
--- a/wpa_supplicant/aidl/aidl_manager.cpp
+++ b/wpa_supplicant/aidl/aidl_manager.cpp
@@ -646,6 +646,59 @@
 	return 0;
 }
 
+// Some of the undefined AKMs in AIDL (Mostly extension AKMs like FT AKMs)
+// are mapped to the main AKM. This is for the framework to map the AKM to
+// correct security type.
+KeyMgmtMask convertSupplicantSelectedKeyMgmtForConnectionToAidl(int key_mgmt)
+{
+	switch (key_mgmt) {
+		case WPA_KEY_MGMT_IEEE8021X:
+			return KeyMgmtMask::WPA_EAP;
+		case WPA_KEY_MGMT_PSK:
+			return KeyMgmtMask::WPA_PSK;
+		case WPA_KEY_MGMT_NONE:
+			return KeyMgmtMask::NONE;
+		case WPA_KEY_MGMT_IEEE8021X_NO_WPA:
+			return KeyMgmtMask::IEEE8021X;
+		case WPA_KEY_MGMT_FT_IEEE8021X:
+			return KeyMgmtMask::FT_EAP;
+		case WPA_KEY_MGMT_FT_PSK:
+			return KeyMgmtMask::FT_PSK;
+		case WPA_KEY_MGMT_IEEE8021X_SHA256:
+			return KeyMgmtMask::WPA_EAP_SHA256;
+		case WPA_KEY_MGMT_PSK_SHA256:
+			return KeyMgmtMask::WPA_PSK_SHA256;
+		case WPA_KEY_MGMT_SAE:
+		case WPA_KEY_MGMT_FT_SAE:
+		case WPA_KEY_MGMT_SAE_EXT_KEY:
+		case WPA_KEY_MGMT_FT_SAE_EXT_KEY:
+			return KeyMgmtMask::SAE;
+		case WPA_KEY_MGMT_WAPI_PSK:
+			return KeyMgmtMask::WAPI_PSK;
+		case WPA_KEY_MGMT_WAPI_CERT:
+			return KeyMgmtMask::WAPI_CERT;
+		case WPA_KEY_MGMT_OSEN:
+			return KeyMgmtMask::OSEN;
+		case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
+		case WPA_KEY_MGMT_FT_IEEE8021X_SHA384:
+			return KeyMgmtMask::SUITE_B_192;
+		case WPA_KEY_MGMT_FILS_SHA256:
+		case WPA_KEY_MGMT_FT_FILS_SHA256:
+			return KeyMgmtMask::FILS_SHA256;
+		case WPA_KEY_MGMT_FILS_SHA384:
+		case WPA_KEY_MGMT_FT_FILS_SHA384:
+			return KeyMgmtMask::FILS_SHA384;
+		case WPA_KEY_MGMT_OWE:
+			return KeyMgmtMask::OWE;
+		case WPA_KEY_MGMT_DPP:
+			return KeyMgmtMask::DPP;
+		default:
+			wpa_printf(MSG_INFO, "Unable to convert supplicant key_mgmt 0x%x to AIDL",
+				    key_mgmt);
+			return (KeyMgmtMask) key_mgmt;
+	}
+}
+
 /**
  * Notify all listeners about any state changes on a particular interface.
  *
@@ -690,10 +743,17 @@
 		(wpa_auth_alg_fils(wpa_s->auth_alg) &&
 		 !dl_list_empty(&wpa_s->fils_hlp_req) &&
 		 (wpa_s->wpa_state == WPA_COMPLETED)) ? true : false;
-	aidl_state_change_data.keyMgmtMask = (KeyMgmtMask) wpa_s->key_mgmt;
-	// wpa_supplicant sets the frequency on receiving the EVENT_ASSOC.
-	aidl_state_change_data.frequencyMhz =
-		wpa_s->wpa_state >= WPA_ASSOCIATED ? wpa_s->assoc_freq : 0;
+	if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
+		// wpa_supplicant sets the frequency on receiving the EVENT_ASSOC.
+		aidl_state_change_data.frequencyMhz = wpa_s->assoc_freq;
+		// The key_mgmt is selected prior to sending the connect command
+		// to driver. But in case of CROSS-AKM Connection/Roaming, the
+		// key_mgmt is updated with the one from association IE. So the
+		// selected key_mgmt is accurate only after moving to
+		// associated state.
+		aidl_state_change_data.keyMgmtMask =
+			convertSupplicantSelectedKeyMgmtForConnectionToAidl(wpa_s->key_mgmt);
+	}
 
 	// Invoke the |onStateChanged| method on all registered callbacks.
 	std::function<
@@ -2607,6 +2667,41 @@
 	return -1;
 }
 
+ssize_t AidlManager::listAliases(const char *prefix, char ***aliases) {
+	if (prefix == nullptr || aliases == nullptr) {
+		wpa_printf(MSG_ERROR, "Null pointer argument was passed to listAliases");
+		return -1;
+	}
+
+	if (auto results =
+			certificate_utils::listAliases(prefix, non_standard_cert_callback_)) {
+		int count = results->size();
+		*aliases = (char **) os_malloc(sizeof(char *) * count);
+		if (*aliases == nullptr) {
+			wpa_printf(MSG_ERROR, "listAliases: os_malloc alias array error");
+			return -1;
+		}
+		os_memset(*aliases, 0, sizeof(char *) * count);
+
+		int index = 0;
+		for (auto it = results->begin(); it != results->end(); ++it) {
+			int alias_len = it->length();
+			char *alias = (char *) os_malloc(alias_len + 1);
+			if (alias == nullptr) {
+				wpa_printf(MSG_ERROR, "listAliases: os_malloc alias string error");
+				for (int i = 0; i < index; ++i) os_free((*aliases)[i]);
+				os_free(*aliases);
+				return -1;
+			}
+			os_memcpy(alias, it->data(), alias_len + 1);
+			(*aliases)[index] = alias;
+			index++;
+		}
+		return count;
+	}
+	return -1;
+}
+
 QosPolicyScsResponseStatusCode getQosPolicyScsResponseStatusCode(int scsResponseCode)
 {
 	QosPolicyScsResponseStatusCode status = QosPolicyScsResponseStatusCode::TIMEOUT;
diff --git a/wpa_supplicant/aidl/aidl_manager.h b/wpa_supplicant/aidl/aidl_manager.h
index 2173a0d..fcea1f7 100644
--- a/wpa_supplicant/aidl/aidl_manager.h
+++ b/wpa_supplicant/aidl/aidl_manager.h
@@ -164,6 +164,7 @@
 			struct dscp_policy_data *policies,
 			int num_policies);
 	ssize_t getCertificate(const char* alias, uint8_t** value);
+	ssize_t listAliases(const char *prefix, char ***aliases);
 	void notifyQosPolicyScsResponse(struct wpa_supplicant *wpa_s,
 			unsigned int count, int **scs_resp);
 
diff --git a/wpa_supplicant/aidl/sta_iface.cpp b/wpa_supplicant/aidl/sta_iface.cpp
index 238a092..4620538 100644
--- a/wpa_supplicant/aidl/sta_iface.cpp
+++ b/wpa_supplicant/aidl/sta_iface.cpp
@@ -2089,8 +2089,6 @@
 				      struct type4_params *param)
 {
 	u8 classifier_mask = 0;
-	int ret;
-	char addr[INET6_ADDRSTRLEN];
 	uint32_t inMask = static_cast<uint32_t>(qos_policy_data.classifierParams.classifierParamMask);
 
 	if (qos_policy_data.classifierParams.ipVersion ==
@@ -2114,24 +2112,14 @@
 				wpa_printf(MSG_ERROR, "Invalid source IP");
 				return -1;
 			}
-			os_memcpy(addr, qos_policy_data.classifierParams.srcIp.data(), 4);
-			ret = inet_pton(AF_INET, addr,
-					&param->ip_params.v4.src_ip);
+			os_memcpy(&param->ip_params.v4.src_ip, qos_policy_data.classifierParams.srcIp.data(), 4);
 		} else {
 			if (qos_policy_data.classifierParams.srcIp.size() !=
 			    sizeof(param->ip_params.v6.src_ip)) {
 				wpa_printf(MSG_ERROR, "Invalid source IP");
 				return -1;
 			}
-			os_memcpy(addr, qos_policy_data.classifierParams.srcIp.data(), 16);
-			ret = inet_pton(AF_INET6, addr,
-					&param->ip_params.v6.src_ip);
-		}
-		if (ret != 1) {
-			wpa_printf(MSG_ERROR,
-				   "Error converting src IP address to binary ret=%d",
-				   ret);
-			return -1;
+			os_memcpy(&param->ip_params.v6.src_ip, qos_policy_data.classifierParams.srcIp.data(), 16);
 		}
 
 		/* Classifier Mask - bit 1 = Source IP Address */
@@ -2145,25 +2133,14 @@
 				wpa_printf(MSG_ERROR, "Invalid destination IP");
 				return -1;
 			}
-			os_memcpy(addr, qos_policy_data.classifierParams.dstIp.data(), 4);
-			ret = inet_pton(AF_INET, addr,
-					&param->ip_params.v4.dst_ip);
+			os_memcpy(&param->ip_params.v4.dst_ip, qos_policy_data.classifierParams.dstIp.data(), 4);
 		} else {
 			if (qos_policy_data.classifierParams.dstIp.size() !=
 			    sizeof(param->ip_params.v6.dst_ip)) {
 				wpa_printf(MSG_ERROR, "Invalid destination IP");
 				return -1;
 			}
-			os_memcpy(addr, qos_policy_data.classifierParams.dstIp.data(), 16);
-			ret = inet_pton(AF_INET6, addr,
-					&param->ip_params.v6.dst_ip);
-		}
-
-		if (ret != 1) {
-			wpa_printf(MSG_ERROR,
-				   "Error converting dst IP address to binary ret=%d",
-				   ret);
-			return -1;
+			os_memcpy(&param->ip_params.v6.dst_ip, qos_policy_data.classifierParams.dstIp.data(), 16);
 		}
 
 		/* Classifier Mask - bit 2 = Destination IP Address */
diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
index cd272e3..89a0389 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -37,6 +37,16 @@
 	}
 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
 
+#ifdef CONFIG_AIDL
+	// Initialize AIDL here if daemonize is disabled.
+	// Otherwise initialize it later.
+	if (!global->params.daemonize) {
+		global->aidl = wpas_aidl_init(global);
+		if (!global->aidl)
+			return -1;
+	}
+#endif /* CONFIG_AIDL */
+
 	return 0;
 }
 
@@ -63,13 +73,14 @@
 	}
 
 #ifdef CONFIG_AIDL
-	/* AIDL initialization may not be complete at this point.
+	/*
+	 * AIDL initialization may not be complete here if daemonize is enabled.
 	 * Initialization is done after daemonizing in order to avoid
 	 * issues with the file descriptor.
 	 */
-	if (!wpa_s || !wpa_s->global->aidl)
+	if (!wpa_s->global->aidl)
 		return 0;
-	/* HIDL interface wants to keep track of the P2P mgmt iface. */
+	/* AIDL interface wants to keep track of the P2P mgmt iface. */
 	if (wpas_aidl_register_interface(wpa_s))
 		return -1;
 #endif
@@ -85,7 +96,7 @@
 		wpas_dbus_unregister_interface(wpa_s);
 	}
 
-	/* HIDL interface wants to keep track of the P2P mgmt iface. */
+	/* AIDL interface wants to keep track of the P2P mgmt iface. */
 	wpas_aidl_unregister_interface(wpa_s);
 }
 
@@ -1372,6 +1383,10 @@
 	return wpas_aidl_get_certificate(alias, value);
 }
 
+ssize_t wpas_list_aliases(const char *prefix, char ***aliases)
+{
+	return wpas_aidl_list_aliases(prefix, aliases);
+}
 
 void wpas_notify_signal_change(struct wpa_supplicant *wpa_s)
 {
diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h
index 84ef898..bc2bd64 100644
--- a/wpa_supplicant/notify.h
+++ b/wpa_supplicant/notify.h
@@ -223,6 +223,7 @@
 		struct dscp_policy_data *policies, int num_policies);
 void wpas_notify_frequency_changed(struct wpa_supplicant *wpa_s, int frequency);
 ssize_t wpas_get_certificate(const char *alias, uint8_t** value);
+ssize_t wpas_list_aliases(const char *prefix, char ***aliases);
 void wpas_notify_pmk_cache_added(struct wpa_supplicant *wpa_s,
 				 struct rsn_pmksa_cache_entry *entry);
 void wpas_notify_signal_change(struct wpa_supplicant *wpa_s);
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 99ecef8..287bc9e 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -7920,9 +7920,12 @@
 	}
 
 #ifdef CONFIG_AIDL
-	global->aidl = wpas_aidl_init(global);
-	if (!global->aidl)
-		return -1;
+	// If daemonize is enabled, initialize AIDL here.
+	if (global->params.daemonize) {
+		global->aidl = wpas_aidl_init(global);
+		if (!global->aidl)
+			return -1;
+	}
 #endif /* CONFIG_AIDL */
 
 	eloop_register_signal_terminate(wpa_supplicant_terminate, global);