]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Interworking: Support real SIM/USIM card for network selection
authorJouni Malinen <j@w1.fi>
Sun, 4 Mar 2012 14:02:56 +0000 (16:02 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 4 Mar 2012 14:02:56 +0000 (16:02 +0200)
Signed-hostap: Jouni Malinen <j@w1.fi>

wpa_supplicant/config.c
wpa_supplicant/config.h
wpa_supplicant/config_file.c
wpa_supplicant/interworking.c
wpa_supplicant/wpa_supplicant.conf

index fc3205e6a95cc848cc86666d44ec2d5f6af24f23..0350b8e0a5fae1a1f47fcffd03d516ff9fea4a5e 100644 (file)
@@ -2229,6 +2229,11 @@ int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
                return 0;
        }
 
+       if (os_strcmp(var, "pcsc") == 0) {
+               cred->pcsc = atoi(value);
+               return 0;
+       }
+
        val = wpa_config_parse_string(value, &len);
        if (val == NULL) {
                wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
index 0dcb4c853d8b18f5b4644f7064981725021ba5af..5b002a204f14717b99d88f2d7eff1f3d19e263ff 100644 (file)
@@ -60,6 +60,11 @@ struct wpa_cred {
         */
        int priority;
 
+       /**
+        * pcsc - Use PC/SC and SIM/USIM card
+        */
+       int pcsc;
+
        /**
         * realm - Home Realm for Interworking
         */
index 12e909ae4301e6b8cec98c41f9052c2e667e41d8..b3dd40e06afe72f081fe701d507b379b9c335334 100644 (file)
@@ -659,6 +659,8 @@ static void wpa_config_write_cred(FILE *f, struct wpa_cred *cred)
 {
        if (cred->priority)
                fprintf(f, "\tpriority=%d\n", cred->priority);
+       if (cred->pcsc)
+               fprintf(f, "\tpcsc=%d\n", cred->pcsc);
        if (cred->realm)
                fprintf(f, "\trealm=\"%s\"\n", cred->realm);
        if (cred->username)
index 74d9a1a67bdd52bb9cde48954d1ab41d5fdd98f9..a721e5d302dad1bddd4051e1597dc8fe5526faac 100644 (file)
@@ -599,6 +599,17 @@ static int interworking_connect_3gpp(struct wpa_supplicant *wpa_s,
 
        for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
                char *sep;
+               const char *imsi;
+               int mnc_len;
+
+#ifdef PCSC_FUNCS
+               if (cred->pcsc && wpa_s->conf->pcsc_reader && wpa_s->scard &&
+                   wpa_s->imsi[0]) {
+                       imsi = wpa_s->imsi;
+                       mnc_len = wpa_s->mnc_len;
+                       goto compare;
+               }
+#endif /* PCSC_FUNCS */
 
                if (cred->imsi == NULL || !cred->imsi[0] ||
                    cred->milenage == NULL || !cred->milenage[0])
@@ -608,9 +619,13 @@ static int interworking_connect_3gpp(struct wpa_supplicant *wpa_s,
                if (sep == NULL ||
                    (sep - cred->imsi != 5 && sep - cred->imsi != 6))
                        continue;
+               mnc_len = sep - cred->imsi - 3;
+               imsi = cred->imsi;
 
-               if (plmn_id_match(bss->anqp_3gpp, cred->imsi,
-                                 sep - cred->imsi - 3))
+#ifdef PCSC_FUNCS
+       compare:
+#endif /* PCSC_FUNCS */
+               if (plmn_id_match(bss->anqp_3gpp, imsi, mnc_len))
                        break;
        }
        if (cred == NULL)
@@ -641,7 +656,7 @@ static int interworking_connect_3gpp(struct wpa_supplicant *wpa_s,
                wpa_printf(MSG_DEBUG, "EAP-SIM not supported");
                goto fail;
        }
-       if (set_root_nai(ssid, cred->imsi, '1') < 0) {
+       if (!cred->pcsc && set_root_nai(ssid, cred->imsi, '1') < 0) {
                wpa_printf(MSG_DEBUG, "Failed to set Root NAI");
                goto fail;
        }
@@ -650,10 +665,13 @@ static int interworking_connect_3gpp(struct wpa_supplicant *wpa_s,
                if (wpa_config_set_quoted(ssid, "password",
                                          cred->milenage) < 0)
                        goto fail;
-       } else {
-               /* TODO: PIN */
+       } else if (cred->pcsc) {
                if (wpa_config_set_quoted(ssid, "pcsc", "") < 0)
                        goto fail;
+               if (wpa_s->conf->pcsc_pin &&
+                   wpa_config_set_quoted(ssid, "pin", wpa_s->conf->pcsc_pin)
+                   < 0)
+                       goto fail;
        }
 
        if (cred->password && cred->password[0] &&
@@ -871,6 +889,17 @@ static struct wpa_cred * interworking_credentials_available_3gpp(
 
        for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
                char *sep;
+               const char *imsi;
+               int mnc_len;
+
+#ifdef PCSC_FUNCS
+               if (cred->pcsc && wpa_s->conf->pcsc_reader && wpa_s->scard &&
+                   wpa_s->imsi[0]) {
+                       imsi = wpa_s->imsi;
+                       mnc_len = wpa_s->mnc_len;
+                       goto compare;
+               }
+#endif /* PCSC_FUNCS */
 
                if (cred->imsi == NULL || !cred->imsi[0] ||
                    cred->milenage == NULL || !cred->milenage[0])
@@ -880,11 +909,15 @@ static struct wpa_cred * interworking_credentials_available_3gpp(
                if (sep == NULL ||
                    (sep - cred->imsi != 5 && sep - cred->imsi != 6))
                        continue;
+               mnc_len = sep - cred->imsi - 3;
+               imsi = cred->imsi;
 
+#ifdef PCSC_FUNCS
+       compare:
+#endif /* PCSC_FUNCS */
                wpa_printf(MSG_DEBUG, "Interworking: Parsing 3GPP info from "
                           MACSTR, MAC2STR(bss->bssid));
-               ret = plmn_id_match(bss->anqp_3gpp, cred->imsi,
-                                   sep - cred->imsi - 3);
+               ret = plmn_id_match(bss->anqp_3gpp, imsi, mnc_len);
                wpa_printf(MSG_DEBUG, "PLMN match %sfound", ret ? "" : "not ");
                if (ret) {
                        if (selected == NULL ||
index 279991a7e4ac92271c5a07f6908894f40fd5fa17..70d3030e52e60b00ad1ffcea8a9e3d2748368b26 100644 (file)
@@ -255,6 +255,8 @@ fast_reauth=1
 #      network (based on either an enabled network block or a credential)
 #      with the highest priority value will be selected.
 #
+# pcsc: Use PC/SC and SIM/USIM card
+#
 # realm: Home Realm for Interworking
 #
 # username: Username for Interworking network selection