summaryrefslogtreecommitdiffstats
path: root/src/sim.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2010-04-15 12:32:05 -0500
committerDenis Kenzior <denkenz@gmail.com>2010-04-15 16:49:40 -0500
commitc63b2c9d4481b141ec3caab69456afbd77b80ff1 (patch)
tree5b7157eb5b50b1bf8b4f6a6163b70a0c84f04365 /src/sim.c
parent6dc4799d1bbd9594cc8adb13b18135f9e08957da (diff)
downloadofono-c63b2c9d4481b141ec3caab69456afbd77b80ff1.tar.bz2
Fix: Uncomplicate the logic for SIM initialization
If we get a sim inserted notify before we are registered, we need to initialize the SIM once ofono_sim_register is called. The logic for doing so is rather twisted, simplify it.
Diffstat (limited to 'src/sim.c')
-rw-r--r--src/sim.c59
1 files changed, 29 insertions, 30 deletions
diff --git a/src/sim.c b/src/sim.c
index 8701e0ec..69e0a89e 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -1319,6 +1319,30 @@ static void sim_determine_phase(struct ofono_sim *sim)
sim_efphase_read_cb, sim);
}
+static void sim_initialize(struct ofono_sim *sim)
+{
+ /* Perform SIM initialization according to 3GPP 31.102 Section 5.1.1.2
+ * The assumption here is that if sim manager is being initialized,
+ * then sim commands are implemented, and the sim manager is then
+ * responsible for checking the PIN, reading the IMSI and signaling
+ * SIM ready condition.
+ *
+ * The procedure according to 31.102 is roughly:
+ * Read EFecc
+ * Read EFli and EFpl
+ * SIM Pin check
+ * Request SIM phase (only in 51.011)
+ * Read EFust
+ * Read EFest
+ * Read IMSI
+ *
+ * At this point we signal the SIM ready condition and allow
+ * arbitrary files to be written or read, assuming their presence
+ * in the EFust
+ */
+ sim_determine_phase(sim);
+}
+
static void sim_op_error(struct ofono_sim *sim)
{
struct sim_file_op *op = g_queue_pop_head(sim->simop_q);
@@ -1873,32 +1897,10 @@ void ofono_sim_inserted_notify(struct ofono_sim *sim, ofono_bool_t inserted)
notify(item->notify_data, sim->state);
}
- if (!inserted) {
+ if (inserted)
+ sim_initialize(sim);
+ else
sim_free_state(sim);
-
- return;
- }
-
- /* Perform SIM initialization according to 3GPP 31.102 Section 5.1.1.2
- * The assumption here is that if sim manager is being initialized,
- * then sim commands are implemented, and the sim manager is then
- * responsible for checking the PIN, reading the IMSI and signaling
- * SIM ready condition.
- *
- * The procedure according to 31.102 is roughly:
- * Read EFecc
- * Read EFli and EFpl
- * SIM Pin check
- * Request SIM phase (only in 51.011)
- * Read EFust
- * Read EFest
- * Read IMSI
- *
- * At this point we signal the SIM ready condition and allow
- * arbitrary files to be written or read, assuming their presence
- * in the EFust
- */
- sim_determine_phase(sim);
}
unsigned int ofono_sim_add_state_watch(struct ofono_sim *sim,
@@ -2085,7 +2087,6 @@ void ofono_sim_register(struct ofono_sim *sim)
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(sim->atom);
const char *path = __ofono_atom_get_path(sim->atom);
- ofono_bool_t inserted;
if (!g_dbus_register_interface(conn, path,
OFONO_SIM_MANAGER_INTERFACE,
@@ -2104,10 +2105,8 @@ void ofono_sim_register(struct ofono_sim *sim)
ofono_sim_add_state_watch(sim, sim_ready, sim, NULL);
- inserted = sim->state != OFONO_SIM_STATE_NOT_PRESENT;
- sim->state = OFONO_SIM_STATE_NOT_PRESENT;
-
- ofono_sim_inserted_notify(sim, inserted);
+ if (sim->state > OFONO_SIM_STATE_NOT_PRESENT)
+ sim_initialize(sim);
}
void ofono_sim_remove(struct ofono_sim *sim)