]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add preliminary MNC length determination based on IMSI
authorJouni Malinen <j@w1.fi>
Sun, 22 Jan 2012 19:33:57 +0000 (21:33 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 22 Jan 2012 19:54:24 +0000 (21:54 +0200)
Some SIM cards do not include MNC length with in EF_AD. Try to figure
out the MNC length based on the MCC/MNC values in the beginning of the
IMSI. This covers a prepaid Elisa/Kolumbus card that would have ended
up using incorrect MNC length based on the 3-digit default.

Signed-hostap: Jouni Malinen <j@w1.fi>

src/eap_peer/eap.c

index 50ac98fa19bad7b4295eccfbd6db57f1b465d74b..b1db6cdfd07ba33f642a1700fca6db9cffbf82b7 100644 (file)
@@ -879,6 +879,26 @@ static void eap_sm_processIdentity(struct eap_sm *sm, const struct wpabuf *req)
 
 #ifdef PCSC_FUNCS
 
+/*
+ * Rules for figuring out MNC length based on IMSI for SIM cards that do not
+ * include MNC length field.
+ */
+static int mnc_len_from_imsi(const char *imsi)
+{
+       char mcc_str[4];
+       unsigned int mcc;
+
+       os_memcpy(mcc_str, imsi, 3);
+       mcc_str[3] = '\0';
+       mcc = atoi(mcc_str);
+
+       if (mcc == 244)
+               return 2; /* Networks in Finland use 2-digit MNC */
+
+       return -1;
+}
+
+
 static int eap_sm_append_3gpp_realm(struct eap_sm *sm, char *imsi,
                                    size_t max_len, size_t *imsi_len)
 {
@@ -892,6 +912,8 @@ static int eap_sm_append_3gpp_realm(struct eap_sm *sm, char *imsi,
 
        /* MNC (2 or 3 digits) */
        mnc_len = scard_get_mnc_len(sm->scard_ctx);
+       if (mnc_len < 0)
+               mnc_len = mnc_len_from_imsi(imsi);
        if (mnc_len < 0) {
                wpa_printf(MSG_INFO, "Failed to get MNC length from (U)SIM "
                           "assuming 3");