Report the EAP method failure up to the framework

This commit reports the EAP method failure code up to the framework.
The commit only defines EAP-SIM errors for now, but the solution
allows for other EAP methods to use it if needed.

Bug: 64612561
Test: Manual

Change-Id: I0b4b7c95720e72484b10fc3c33a090d878128239
Signed-off-by: Ahmed ElArabawy <arabawy@google.com>
diff --git a/wpa_supplicant/hidl/1.1/hidl.cpp b/wpa_supplicant/hidl/1.1/hidl.cpp
index 10fc36c..95194af 100644
--- a/wpa_supplicant/hidl/1.1/hidl.cpp
+++ b/wpa_supplicant/hidl/1.1/hidl.cpp
@@ -625,3 +625,21 @@
 
 	hidl_manager->notifyApStaDeauthorized(wpa_s, sta, p2p_dev_addr);
 }
+
+void wpas_hidl_notify_eap_error(
+    struct wpa_supplicant *wpa_s, int error_code)
+{
+	if (!wpa_s)
+		return;
+
+	wpa_printf(
+	    MSG_DEBUG,
+            "Notifying EAP Error: %d ", error_code);
+
+	HidlManager *hidl_manager = HidlManager::getInstance();
+	if (!hidl_manager)
+		return;
+
+	hidl_manager->notifyEapError(wpa_s, error_code);
+}
+
diff --git a/wpa_supplicant/hidl/1.1/hidl.h b/wpa_supplicant/hidl/1.1/hidl.h
index 96631f2..1dfadc6 100644
--- a/wpa_supplicant/hidl/1.1/hidl.h
+++ b/wpa_supplicant/hidl/1.1/hidl.h
@@ -91,6 +91,7 @@
     struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr);
 void wpas_hidl_notify_ap_sta_deauthorized(
     struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr);
+void wpas_hidl_notify_eap_error(struct wpa_supplicant *wpa_s, int error_code);
 #else   // CONFIG_CTRL_IFACE_HIDL
 static inline int wpas_hidl_register_interface(struct wpa_supplicant *wpa_s)
 {
@@ -212,6 +213,10 @@
     struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr)
 {
 }
+static void wpas_hidl_notify_eap_error(
+    struct wpa_supplicant *wpa_s, int error_code)
+{
+}
 #endif  // CONFIG_CTRL_IFACE_HIDL
 
 #ifdef _cplusplus
diff --git a/wpa_supplicant/hidl/1.1/hidl_manager.cpp b/wpa_supplicant/hidl/1.1/hidl_manager.cpp
index 5d09a22..ef239c1 100644
--- a/wpa_supplicant/hidl/1.1/hidl_manager.cpp
+++ b/wpa_supplicant/hidl/1.1/hidl_manager.cpp
@@ -1380,6 +1380,32 @@
 		std::placeholders::_1, id));
 }
 
+void HidlManager::notifyEapError(struct wpa_supplicant *wpa_s, int error_code)
+{
+	typedef ISupplicantStaIfaceCallback::EapErrorCode EapErrorCode;
+
+	if (!wpa_s)
+		return;
+
+	switch (static_cast<EapErrorCode>(error_code)) {
+		case EapErrorCode::SIM_GENERAL_FAILURE_AFTER_AUTH:
+		case EapErrorCode::SIM_TEMPORARILY_DENIED:
+		case EapErrorCode::SIM_NOT_SUBSCRIBED:
+		case EapErrorCode::SIM_GENERAL_FAILURE_BEFORE_AUTH:
+		case EapErrorCode::SIM_VENDOR_SPECIFIC_EXPIRED_CERT:
+			break;
+		default:
+			return;
+	}
+
+	callWithEachStaIfaceCallback(
+	    wpa_s->ifname,
+	    std::bind(
+		&ISupplicantStaIfaceCallback::onEapFailure_1_1,
+		std::placeholders::_1,
+		static_cast<EapErrorCode>(error_code)));
+}
+
 /**
  * Retrieve the |ISupplicantP2pIface| hidl object reference using the provided
  * ifname.
diff --git a/wpa_supplicant/hidl/1.1/hidl_manager.h b/wpa_supplicant/hidl/1.1/hidl_manager.h
index 821011b..b596a38 100644
--- a/wpa_supplicant/hidl/1.1/hidl_manager.h
+++ b/wpa_supplicant/hidl/1.1/hidl_manager.h
@@ -16,7 +16,7 @@
 #include <android/hardware/wifi/supplicant/1.0/ISupplicantCallback.h>
 #include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pIfaceCallback.h>
 #include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pNetworkCallback.h>
-#include <android/hardware/wifi/supplicant/1.0/ISupplicantStaIfaceCallback.h>
+#include <android/hardware/wifi/supplicant/1.1/ISupplicantStaIfaceCallback.h>
 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetworkCallback.h>
 
 #include "p2p_iface.h"
@@ -122,6 +122,8 @@
 	void notifyApStaDeauthorized(
 	    struct wpa_supplicant *wpa_s, const u8 *sta,
 	    const u8 *p2p_dev_addr);
+	void notifyEapError(
+	    struct wpa_supplicant *wpa_s, int error_code);
 
 	// Methods called from hidl objects.
 	void notifyExtRadioWorkStart(struct wpa_supplicant *wpa_s, uint32_t id);
diff --git a/wpa_supplicant/hidl/1.1/sta_iface.cpp b/wpa_supplicant/hidl/1.1/sta_iface.cpp
index 08b484c..54c4007 100644
--- a/wpa_supplicant/hidl/1.1/sta_iface.cpp
+++ b/wpa_supplicant/hidl/1.1/sta_iface.cpp
@@ -22,7 +22,7 @@
 }
 
 namespace {
-using android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface;
+using android::hardware::wifi::supplicant::V1_1::ISupplicantStaIface;
 using android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
 using android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
 using android::hardware::wifi::supplicant::V1_1::implementation::HidlManager;
@@ -215,12 +215,21 @@
 }
 
 Return<void> StaIface::registerCallback(
+    const sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaIfaceCallback>
+    & callback, registerCallback_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::registerCallbackInternal, _hidl_cb, callback);
+}
+
+Return<void> StaIface::registerCallback_1_1(
     const sp<ISupplicantStaIfaceCallback> &callback,
     registerCallback_cb _hidl_cb)
 {
 	return validateAndCall(
 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
-	    &StaIface::registerCallbackInternal, _hidl_cb, callback);
+	    &StaIface::registerCallbackInternal_1_1, _hidl_cb, callback);
 }
 
 Return<void> StaIface::reassociate(reassociate_cb _hidl_cb)
@@ -570,6 +579,12 @@
 }
 
 SupplicantStatus StaIface::registerCallbackInternal(
+    const sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaIfaceCallback> &callback)
+{
+	return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
+}
+
+SupplicantStatus StaIface::registerCallbackInternal_1_1(
     const sp<ISupplicantStaIfaceCallback> &callback)
 {
 	HidlManager *hidl_manager = HidlManager::getInstance();
diff --git a/wpa_supplicant/hidl/1.1/sta_iface.h b/wpa_supplicant/hidl/1.1/sta_iface.h
index 8288ce2..1f1e64b 100644
--- a/wpa_supplicant/hidl/1.1/sta_iface.h
+++ b/wpa_supplicant/hidl/1.1/sta_iface.h
@@ -15,8 +15,8 @@
 
 #include <android-base/macros.h>
 
-#include <android/hardware/wifi/supplicant/1.0/ISupplicantStaIface.h>
-#include <android/hardware/wifi/supplicant/1.0/ISupplicantStaIfaceCallback.h>
+#include <android/hardware/wifi/supplicant/1.1/ISupplicantStaIface.h>
+#include <android/hardware/wifi/supplicant/1.1/ISupplicantStaIfaceCallback.h>
 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetwork.h>
 
 extern "C" {
@@ -71,6 +71,9 @@
 	    SupplicantNetworkId id, getNetwork_cb _hidl_cb) override;
 	Return<void> listNetworks(listNetworks_cb _hidl_cb) override;
 	Return<void> registerCallback(
+	    const sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaIfaceCallback>
+	    & callback, registerCallback_cb _hidl_cb) override;
+	Return<void> registerCallback_1_1(
 	    const sp<ISupplicantStaIfaceCallback>& callback,
 	    registerCallback_cb _hidl_cb) override;
 	Return<void> reassociate(reassociate_cb _hidl_cb) override;
@@ -168,6 +171,9 @@
 	std::pair<SupplicantStatus, std::vector<SupplicantNetworkId>>
 	listNetworksInternal();
 	SupplicantStatus registerCallbackInternal(
+	    const sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaIfaceCallback>
+	    & callback);
+	SupplicantStatus registerCallbackInternal_1_1(
 	    const sp<ISupplicantStaIfaceCallback>& callback);
 	SupplicantStatus reassociateInternal();
 	SupplicantStatus reconnectInternal();
diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
index 8b62a6d..3832a33 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -891,6 +891,7 @@
 {
 	wpa_dbg(wpa_s, MSG_ERROR,
 		"EAP Error code = %d", error_code);
+	wpas_hidl_notify_eap_error(wpa_s, error_code);
 }
 
 void wpas_notify_network_bssid_set_changed(struct wpa_supplicant *wpa_s,