From c5fbfaa55fea50d89bfd7df30170baec7ac101a9 Mon Sep 17 00:00:00 2001 From: Christophe Ronco Date: Mon, 9 Jan 2017 09:34:06 +0100 Subject: [PATCH] sim: backup driver read_imsi by IMSI via EF read If read_imsi driver function fails, try to obtain IMSI via EF read --- src/sim.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/sim.c b/src/sim.c index 63c7b3c8..ac5b6fde 100644 --- a/src/sim.c +++ b/src/sim.c @@ -1472,19 +1472,6 @@ static void sim_imsi_obtained(struct ofono_sim *sim, const char *imsi) } -static void sim_imsi_cb(const struct ofono_error *error, const char *imsi, - void *data) -{ - struct ofono_sim *sim = data; - - if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { - ofono_error("Unable to read IMSI, emergency calls only"); - return; - } - - sim_imsi_obtained(sim, imsi); -} - static void sim_efimsi_cb(const struct ofono_error *error, const unsigned char *data, int len, void *user) { @@ -1524,6 +1511,26 @@ error: ofono_error("Unable to read IMSI, emergency calls only"); } +static void sim_imsi_cb(const struct ofono_error *error, const char *imsi, + void *data) +{ + struct ofono_sim *sim = data; + + if (error->type == OFONO_ERROR_TYPE_NO_ERROR) { + sim_imsi_obtained(sim, imsi); + return; + } + + /* Driver function failed, try via EF reads if possible */ + if (sim->driver->read_file_transparent == NULL) { + ofono_error("Unable to read IMSI, emergency calls only"); + return; + } + + sim->driver->read_file_transparent(sim, SIM_EFIMSI_FILEID, 0, 9, + NULL, 0, sim_efimsi_cb, sim); +} + static void sim_retrieve_imsi(struct ofono_sim *sim) { if (sim->driver->read_imsi) {