From 901aac2ba8c64c35811424425bbeb01c895484e3 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Mon, 9 May 2016 19:54:32 +0100 Subject: Fix EAP-SIM fallback identity generation outside of North America There are only a few MCCs in which the MNC is expected to be 3-digit long. However, the fallback path for REQ-IDENTITY was assuming that length all the time, which resulted in us getting the wrong realm for the fallback path (which is kicked in when, for example, wifi starts up faster than mobile) Also, SIM states are indexed by slot, not subId Ref CYNGNOS-2768 Change-Id: I3ea01d45e62689075b62df7a169f8734d0c9f5e6 --- service/java/com/android/server/wifi/WifiStateMachine.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'service/java') diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 0ce8dd4..1c06e71 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -7730,19 +7730,21 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno mContext.getSystemService(Context.TELEPHONY_SERVICE); if (tm != null) { int subId = SubscriptionManager.getDefaultSubId(); + int slotId = tm.getDefaultSim(); if (targetWificonfiguration != null && targetWificonfiguration.SIMNum > 0 && tm.getDefault().getPhoneCount() >= 2) { int[] subIds = SubscriptionManager.getSubId(targetWificonfiguration.SIMNum - 1); if (subIds != null) { subId = subIds[0]; + slotId = SubscriptionManager.getSlotId(subId); } } String imsi = tm.getSubscriberId(subId); String mccMnc = ""; - if (tm.getSimState(subId) == TelephonyManager.SIM_STATE_READY) + if (tm.getSimState(slotId) == TelephonyManager.SIM_STATE_READY) mccMnc = tm.getSimOperator(subId); String identity = buildIdentity(eapMethod, imsi, mccMnc); @@ -8413,9 +8415,17 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno if (mnc.length() == 2) mnc = "0" + mnc; } else { - // extract mcc & mnc from IMSI, assume mnc size is 3 + // extract mcc & mnc from IMSI, assume mnc size is 3 if in this list, 2 otherwise + String ThreeDigitMnc[] = {"302", "310", "311", "312", "313", "314", "315", "316", "334", "348"}; + mcc = imsi.substring(0, 3); mnc = imsi.substring(3, 6); + + if (!Arrays.asList(ThreeDigitMnc).contains(mcc)) + mnc = mnc.substring(0, 2); + + if (mnc.length() == 2) + mnc = "0" + mnc; } return prefix + imsi + "@wlan.mnc" + mnc + ".mcc" + mcc + ".3gppnetwork.org"; -- cgit v1.2.3