summaryrefslogtreecommitdiffstats
path: root/src/sim.c
diff options
context:
space:
mode:
authorAndrzej Zaborowski <andrew.zaborowski@intel.com>2010-04-09 08:48:50 +0200
committerDenis Kenzior <denkenz@gmail.com>2010-04-15 16:49:40 -0500
commitddfe8acf11f351a5887ced8fedf736ee4b108c51 (patch)
tree77277e91bfbfe21b3c2d91a2e34d3e352edaa027 /src/sim.c
parent22cbe981468a1eeb5ea5f07e07c31b11da2507e0 (diff)
downloadofono-ddfe8acf11f351a5887ced8fedf736ee4b108c51.tar.bz2
Drivers can notify core of SIM insertion / removal
Add ofono_sim_inserted_notify function to notify the core of SIM insertion / removal. Make every plugin generate a sim inserted event on start. For devices with removable card, the event should be emitted after the plugin detects such event. For devices that need to wait for SIM card initialization, they can emit this event later.
Diffstat (limited to 'src/sim.c')
-rw-r--r--src/sim.c78
1 files changed, 55 insertions, 23 deletions
diff --git a/src/sim.c b/src/sim.c
index 58de1918..5559be48 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -55,6 +55,7 @@ static gboolean sim_op_next(gpointer user_data);
static gboolean sim_op_retrieve_next(gpointer user);
static void sim_own_numbers_update(struct ofono_sim *sim);
static void sim_pin_check(struct ofono_sim *sim);
+static void sim_set_ready(struct ofono_sim *sim);
struct sim_file_op {
int id;
@@ -1003,7 +1004,7 @@ static void sim_cphs_information_read_cb(int ok, int length, int record,
memcpy(sim->cphs_service_table, data + 1, 2);
ready:
- ofono_sim_set_ready(sim);
+ sim_set_ready(sim);
}
static void sim_imsi_cb(const struct ofono_error *error, const char *imsi,
@@ -1778,6 +1779,53 @@ const unsigned char *ofono_sim_get_cphs_service_table(struct ofono_sim *sim)
return sim->cphs_service_table;
}
+void ofono_sim_inserted_notify(struct ofono_sim *sim, ofono_bool_t inserted)
+{
+ ofono_sim_state_event_notify_cb_t notify;
+ GSList *l;
+
+ if (inserted && sim->state == OFONO_SIM_STATE_NOT_PRESENT)
+ sim->state = OFONO_SIM_STATE_INSERTED;
+ else if (!inserted && sim->state != OFONO_SIM_STATE_NOT_PRESENT)
+ sim->state = OFONO_SIM_STATE_NOT_PRESENT;
+ else
+ return;
+
+ if (!__ofono_atom_get_registered(sim->atom))
+ return;
+
+ for (l = sim->state_watches->items; l; l = l->next) {
+ struct ofono_watchlist_item *item = l->data;
+ notify = item->notify;
+
+ notify(item->notify_data, sim->state);
+ }
+
+ if (!inserted)
+ 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,
ofono_sim_state_event_notify_cb_t notify,
void *data, ofono_destroy_func destroy)
@@ -1814,7 +1862,7 @@ enum ofono_sim_state ofono_sim_get_state(struct ofono_sim *sim)
return sim->state;
}
-void ofono_sim_set_ready(struct ofono_sim *sim)
+static void sim_set_ready(struct ofono_sim *sim)
{
GSList *l;
ofono_sim_state_event_notify_cb_t notify;
@@ -2000,6 +2048,7 @@ 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,
@@ -2013,32 +2062,15 @@ void ofono_sim_register(struct ofono_sim *sim)
ofono_modem_add_interface(modem, OFONO_SIM_MANAGER_INTERFACE);
sim->state_watches = __ofono_watchlist_new(g_free);
- sim->state = OFONO_SIM_STATE_INSERTED;
__ofono_atom_register(sim->atom, sim_unregister);
ofono_sim_add_state_watch(sim, sim_ready, sim, NULL);
- /* 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);
+ inserted = sim->state != OFONO_SIM_STATE_NOT_PRESENT;
+ sim->state = OFONO_SIM_STATE_NOT_PRESENT;
+
+ ofono_sim_inserted_notify(sim, inserted);
}
void ofono_sim_remove(struct ofono_sim *sim)