Support for decorated anonymous identity prefix

Support for decorated anonymous identity prefix as per RFC 7542,
for SIM-based EAP networks.

Bug: 182510351
Test: Verify decorated identity in AAA log
Test: Unit test, verified multiple inputs
Change-Id: I719bc3df0b62471b3cd670e8c42a968b019446f9
diff --git a/src/eap_common/eap_sim_common.c b/src/eap_common/eap_sim_common.c
index 4a93244..58861cd 100644
--- a/src/eap_common/eap_sim_common.c
+++ b/src/eap_common/eap_sim_common.c
@@ -1209,10 +1209,10 @@
 	}
 }
 
-
 int eap_sim_anonymous_username(const u8 *id, size_t id_len)
 {
 	static const char *anonymous_id_prefix = "anonymous@";
+	const char *decorated;
 	size_t anonymous_id_len = os_strlen(anonymous_id_prefix);
 
 	if (id_len > anonymous_id_len &&
@@ -1226,5 +1226,12 @@
 	if (id_len > 1 && id[0] == '@')
 		return 1; /* '@realm' */
 
+	/* RFC 7542 decorated username, for example;
+	   homerealm.example.org!anonymous@otherrealm.example.net */
+	decorated = os_strrchr((const char *)id, '!');
+	if (decorated && os_strlen(decorated + 1) > 1) {
+		return eap_sim_anonymous_username((const u8 *)(decorated + 1),
+				os_strlen(decorated + 1));
+	}
 	return 0;
 }