EAP-SIM/AKA/AKA' requires the SIM's NAI to authenticate. If available, this can be obtained from the ISIM AID. If the ISIM AID is found a new AID based context will be created and the EFIMPI file will be read from the SIM which contains the NAI. --- src/sim.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/sim.c b/src/sim.c index 8b466c9..f09c550 100644 --- a/src/sim.c +++ b/src/sim.c @@ -125,6 +125,7 @@ struct ofono_sim { struct sim_fs *simfs_isim; struct ofono_sim_context *context; struct ofono_sim_context *early_context; + struct ofono_sim_context *isim_context; unsigned char *iidf_image; unsigned int *iidf_watch_ids; @@ -136,6 +137,7 @@ struct ofono_sim { unsigned int hfp_watch; GSList *aid_sessions; + char *nai; }; struct msisdn_set_request { @@ -407,6 +409,10 @@ static DBusMessage *sim_get_properties(DBusConnection *conn, ofono_dbus_dict_append(&dict, "ServiceProviderName", DBUS_TYPE_STRING, &sim->spn); + if (sim->nai) + ofono_dbus_dict_append(&dict, "NetworkAccessIdentifier", + DBUS_TYPE_STRING, &sim->nai); + fdn = sim->fixed_dialing; ofono_dbus_dict_append(&dict, "FixedDialing", DBUS_TYPE_BOOLEAN, &fdn); @@ -1456,6 +1462,25 @@ static void sim_set_ready(struct ofono_sim *sim) call_state_watches(sim); } +static void impi_read_cb(int ok, int total_length, int record, + const unsigned char *data, + int record_length, void *userdata) +{ + struct ofono_sim *sim = userdata; + + if (!ok) { + DBG("error reading IMPI"); + return; + } + + if (data[0] != 0x80) { + DBG("invalid TLV tag 0x%02x", data[0]); + return; + } + + sim->nai = g_strndup((const char *)data + 2, data[1]); +} + static void discover_apps_cb(const struct ofono_error *error, const unsigned char *dataobj, int len, void *data) @@ -1484,6 +1509,12 @@ static void discover_apps_cb(const struct ofono_error *error, * the FS structure so the ISIM EF's can be accessed. */ sim->simfs_isim = sim_fs_new(sim, sim->driver); + sim->isim_context = ofono_sim_context_create_isim( + sim); + /* attempt to get the NAI from EFimpi */ + ofono_sim_read_bytes(sim->isim_context, + SIM_ISIM_EFIMPI_FILEID, 0, 255, NULL, + 0, impi_read_cb, sim); } g_free(app); @@ -2547,6 +2578,14 @@ static void sim_free_main_state(struct ofono_sim *sim) sim->context = NULL; } + if (sim->isim_context) { + ofono_sim_context_free(sim->isim_context); + sim->isim_context = NULL; + } + + if (sim->nai) + g_free(sim->nai); + if (sim->aid_sessions) g_slist_free(sim->aid_sessions); } -- 2.7.4