Add support to indicate link info changes to framework am: bc2fa4992e am: d2c3ef1b3e

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/wpa_supplicant_8/+/23849993

Change-Id: I6f479315f523bc5967a6fc1aac1e3a15ed620def
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/common/defs.h b/src/common/defs.h
index c0c6dbe..aa3c5cf 100644
--- a/src/common/defs.h
+++ b/src/common/defs.h
@@ -521,6 +521,11 @@
 
 #define MAX_NUM_MLD_LINKS 15
 
+enum mlo_info_change_reason {
+	MLO_TID_TO_LINK_MAP = 0,
+	MLO_LINK_RECONFIG_AP_REMOVAL = 1
+};
+
 enum sae_pwe {
 	SAE_PWE_HUNT_AND_PECK = 0,
 	SAE_PWE_HASH_TO_ELEMENT = 1,
diff --git a/wpa_supplicant/aidl/aidl.cpp b/wpa_supplicant/aidl/aidl.cpp
index 6a22a2a..f221862 100644
--- a/wpa_supplicant/aidl/aidl.cpp
+++ b/wpa_supplicant/aidl/aidl.cpp
@@ -312,6 +312,22 @@
 	aidl_manager->notifyDisconnectReason(wpa_s);
 }
 
+void wpas_aidl_notify_mlo_info_change_reason(struct wpa_supplicant *wpa_s,
+					     enum mlo_info_change_reason reason)
+{
+	if (!wpa_s)
+		return;
+
+	wpa_printf(MSG_DEBUG, "Notifying MLO info change reason to aidl control: %d",
+		   reason);
+
+	AidlManager *aidl_manager = AidlManager::getInstance();
+	if (!aidl_manager)
+		return;
+
+	aidl_manager->notifyMloLinksInfoChanged(wpa_s, reason);
+}
+
 void wpas_aidl_notify_assoc_reject(struct wpa_supplicant *wpa_s,
 	const u8 *bssid, u8 timed_out, const u8 *assoc_resp_ie, size_t assoc_resp_ie_len)
 {
diff --git a/wpa_supplicant/aidl/aidl.h b/wpa_supplicant/aidl/aidl.h
index f9b374e..dfe5c74 100644
--- a/wpa_supplicant/aidl/aidl.h
+++ b/wpa_supplicant/aidl/aidl.h
@@ -52,6 +52,10 @@
 	void wpas_aidl_notify_hs20_rx_terms_and_conditions_acceptance(
 			struct wpa_supplicant *wpa_s, const char *url);
 	void wpas_aidl_notify_disconnect_reason(struct wpa_supplicant *wpa_s);
+	void wpas_aidl_notify_mlo_info_change_reason(
+		struct wpa_supplicant *wpa_s,
+		enum mlo_info_change_reason reason);
+
 	void wpas_aidl_notify_assoc_reject(struct wpa_supplicant *wpa_s, const u8 *bssid,
 		u8 timed_out, const u8 *assoc_resp_ie, size_t assoc_resp_ie_len);
 	void wpas_aidl_notify_auth_timeout(struct wpa_supplicant *wpa_s);
@@ -198,6 +202,9 @@
 		struct wpa_supplicant *wpa_s, const char *url)
 {}
 static void wpas_aidl_notify_disconnect_reason(struct wpa_supplicant *wpa_s) {}
+static void wpas_aidl_notify_mlo_info_change_reason(
+	struct wpa_supplicant *wpa_s, enum mlo_info_change_reason reason)
+{}
 static void wpas_aidl_notify_assoc_reject(struct wpa_supplicant *wpa_s, const u8 *bssid,
 	u8 timed_out, const u8 *assoc_resp_ie, size_t assoc_resp_ie_len) {}
 static void wpas_aidl_notify_auth_timeout(struct wpa_supplicant *wpa_s) {}
diff --git a/wpa_supplicant/aidl/aidl_manager.cpp b/wpa_supplicant/aidl/aidl_manager.cpp
index db566ab..b3baf5b 100644
--- a/wpa_supplicant/aidl/aidl_manager.cpp
+++ b/wpa_supplicant/aidl/aidl_manager.cpp
@@ -2666,6 +2666,23 @@
 			std::placeholders::_1, wpa_s->dscp_req_dialog_token, qosPolicyData));
 }
 
+void AidlManager::notifyMloLinksInfoChanged(struct wpa_supplicant *wpa_s,
+					    enum mlo_info_change_reason reason)
+{
+	if (!wpa_s)
+		return;
+
+	if (sta_iface_object_map_.find(wpa_s->ifname) ==
+		sta_iface_object_map_.end())
+		return;
+
+	callWithEachStaIfaceCallback(
+		misc_utils::charBufToString(wpa_s->ifname),
+		std::bind(&ISupplicantStaIfaceCallback::onMloLinksInfoChanged,
+			  std::placeholders::_1,
+			  static_cast<ISupplicantStaIfaceCallback::MloLinkInfoChangeReason>(reason)));
+}
+
 ssize_t AidlManager::getCertificate(const char* alias, uint8_t** value) {
 	if (alias == nullptr || value == nullptr) {
 		wpa_printf(MSG_ERROR, "Null pointer argument was passed to getCertificate");
diff --git a/wpa_supplicant/aidl/aidl_manager.h b/wpa_supplicant/aidl/aidl_manager.h
index fcea1f7..8f1f177 100644
--- a/wpa_supplicant/aidl/aidl_manager.h
+++ b/wpa_supplicant/aidl/aidl_manager.h
@@ -167,6 +167,8 @@
 	ssize_t listAliases(const char *prefix, char ***aliases);
 	void notifyQosPolicyScsResponse(struct wpa_supplicant *wpa_s,
 			unsigned int count, int **scs_resp);
+	void notifyMloLinksInfoChanged(struct wpa_supplicant *wpa_s,
+				       enum mlo_info_change_reason reason);
 
 	// Methods called from aidl objects.
 	void notifyExtRadioWorkStart(struct wpa_supplicant *wpa_s, uint32_t id);
diff --git a/wpa_supplicant/aidl/sta_iface.cpp b/wpa_supplicant/aidl/sta_iface.cpp
index afcd4b5..fb3ebcd 100644
--- a/wpa_supplicant/aidl/sta_iface.cpp
+++ b/wpa_supplicant/aidl/sta_iface.cpp
@@ -2021,6 +2021,7 @@
 std::pair<MloLinksInfo, ndk::ScopedAStatus> StaIface::getConnectionMloLinksInfoInternal()
 {
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
+	struct driver_sta_mlo_info mlo;
 	MloLinksInfo linksInfo;
 	MloLink link;
 
@@ -2028,6 +2029,7 @@
 	if (!wpa_s->valid_links)
 		 return {linksInfo, ndk::ScopedAStatus::ok()};
 
+	wpas_drv_get_sta_mlo_info(wpa_s, &mlo);
 	for (int i = 0; i < MAX_NUM_MLD_LINKS; i++) {
 		if (!(wpa_s->valid_links & BIT(i)))
 			continue;
@@ -2055,8 +2057,13 @@
 		// mapping by the AP, a default TID-to-link mapping is assumed
 		// unless an individual TID-to-link mapping is successfully
 		// negotiated.
-		link.tidsUplinkMap = 0xFF;
-		link.tidsDownlinkMap = 0xFF;
+		if (!mlo.default_map) {
+			link.tidsUplinkMap = mlo.links[i].t2lmap.uplink;
+			link.tidsDownlinkMap = mlo.links[i].t2lmap.downlink;
+		} else {
+			link.tidsUplinkMap = 0xFF;
+			link.tidsDownlinkMap = 0xFF;
+		}
 		linksInfo.links.push_back(link);
 	}
 
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index e83d877..b09d51d 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -5451,6 +5451,7 @@
 		}
 	}
 
+	wpas_notify_mlo_info_change_reason(wpa_s, MLO_TID_TO_LINK_MAP);
 	wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
 }
 
@@ -5488,6 +5489,7 @@
 		return;
 	}
 
+	wpas_notify_mlo_info_change_reason(wpa_s, MLO_LINK_RECONFIG_AP_REMOVAL);
 	wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
 		wpa_s->valid_links);
 }
diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
index 89a0389..c6e2dbe 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -154,6 +154,16 @@
 }
 
 
+void wpas_notify_mlo_info_change_reason(struct wpa_supplicant *wpa_s,
+					enum mlo_info_change_reason reason)
+{
+	if (wpa_s->p2p_mgmt)
+		return;
+
+	wpas_aidl_notify_mlo_info_change_reason(wpa_s, reason);
+}
+
+
 void wpas_notify_auth_status_code(struct wpa_supplicant *wpa_s)
 {
 	if (wpa_s->p2p_mgmt)
diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h
index bc2bd64..c41aa6e 100644
--- a/wpa_supplicant/notify.h
+++ b/wpa_supplicant/notify.h
@@ -229,5 +229,7 @@
 void wpas_notify_signal_change(struct wpa_supplicant *wpa_s);
 void wpas_notify_qos_policy_scs_response(struct wpa_supplicant *wpa_s,
 		unsigned int num_scs_resp, int **scs_resp);
+void wpas_notify_mlo_info_change_reason(struct wpa_supplicant *wpa_s,
+					enum mlo_info_change_reason reason);
 
 #endif /* NOTIFY_H */