Interworking: Read IMSI if not read at supplicant start
authorJean Trivelly <jean.trivelly@intel.com>
Fri, 28 Mar 2014 16:30:32 +0000 (17:30 +0100)
committerJouni Malinen <j@w1.fi>
Mon, 31 Mar 2014 20:44:59 +0000 (23:44 +0300)
It is required to read IMSI from SIM if it has not already been done
when comparing HS 2.0 AP 3GPP information with the local credentials.

Signed-off-by: Jean Trivelly <jean.trivelly@intel.com>
wpa_supplicant/interworking.c

index bb96113..3450ffe 100644 (file)
@@ -1750,6 +1750,31 @@ int interworking_connect(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
 }
 
 
+#ifdef PCSC_FUNCS
+static int interworking_pcsc_read_imsi(struct wpa_supplicant *wpa_s)
+{
+       size_t len;
+
+       if (wpa_s->imsi[0] && wpa_s->mnc_len)
+               return 0;
+
+       len = sizeof(wpa_s->imsi) - 1;
+       if (scard_get_imsi(wpa_s->scard, wpa_s->imsi, &len)) {
+               scard_deinit(wpa_s->scard);
+               wpa_s->scard = NULL;
+               wpa_msg(wpa_s, MSG_ERROR, "Could not read IMSI");
+               return -1;
+       }
+       wpa_s->imsi[len] = '\0';
+       wpa_s->mnc_len = scard_get_mnc_len(wpa_s->scard);
+       wpa_printf(MSG_DEBUG, "SCARD: IMSI %s (MNC length %d)",
+                  wpa_s->imsi, wpa_s->mnc_len);
+
+       return 0;
+}
+#endif /* PCSC_FUNCS */
+
+
 static struct wpa_cred * interworking_credentials_available_3gpp(
        struct wpa_supplicant *wpa_s, struct wpa_bss *bss, int ignore_bw,
        int *excluded)
@@ -1788,8 +1813,9 @@ static struct wpa_cred * interworking_credentials_available_3gpp(
                size_t msin_len;
 
 #ifdef PCSC_FUNCS
-               if (cred->pcsc && wpa_s->conf->pcsc_reader && wpa_s->scard &&
-                   wpa_s->imsi[0]) {
+               if (cred->pcsc && wpa_s->scard) {
+                       if (interworking_pcsc_read_imsi(wpa_s) < 0)
+                               continue;
                        imsi = wpa_s->imsi;
                        mnc_len = wpa_s->mnc_len;
                        goto compare;
@@ -2046,8 +2072,9 @@ int interworking_home_sp_cred(struct wpa_supplicant *wpa_s,
        if (cred->imsi)
                imsi = cred->imsi;
 #ifdef PCSC_FUNCS
-       else if (cred->pcsc && wpa_s->conf->pcsc_reader &&
-                wpa_s->scard && wpa_s->imsi[0]) {
+       else if (cred->pcsc && wpa_s->scard) {
+               if (interworking_pcsc_read_imsi(wpa_s) < 0)
+                       return -1;
                imsi = wpa_s->imsi;
                mnc_len = wpa_s->mnc_len;
        }