aboutsummaryrefslogtreecommitdiff
path: root/src/mm-sim.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2011-11-22 18:41:55 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:23 +0100
commitbdd1d23ed25cf9539db13052547cce7a62db840c (patch)
tree68032c2f81db01edcd59fb2dd51e768408f1232b /src/mm-sim.c
parent87823387f458efc60afe1147f72ea6609006f180 (diff)
sim: load IMSI during init
Diffstat (limited to 'src/mm-sim.c')
-rw-r--r--src/mm-sim.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/mm-sim.c b/src/mm-sim.c
index 5da91986..3935e0f0 100644
--- a/src/mm-sim.c
+++ b/src/mm-sim.c
@@ -65,6 +65,26 @@ struct _MMSimPrivate {
gchar *path;
};
+static gboolean
+common_parse_string_reply (MMSim *self,
+ gpointer none,
+ const gchar *command,
+ const gchar *response,
+ const GError *error,
+ GVariant **result,
+ GError **result_error)
+{
+ if (error) {
+ *result_error = g_error_copy (error);
+ return FALSE;
+ }
+
+ *result = g_variant_new_string (response);;
+ return TRUE;
+}
+
+/*****************************************************************************/
+
static void
mm_sim_export (MMSim *self)
{
@@ -240,10 +260,52 @@ load_sim_identifier (MMSim *self,
}
/*****************************************************************************/
+/* IMSI */
+
+static gchar *
+load_imsi_finish (MMSim *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ GVariant *result;
+ gchar *imsi;
+
+ result = mm_at_command_finish (G_OBJECT (self), res, error);
+ if (!result)
+ return NULL;
+
+ imsi = g_variant_dup_string (result, NULL);
+ mm_dbg ("loaded IMSI: %s", imsi);
+ g_variant_unref (result);
+ return imsi;
+}
+
+static void
+load_imsi (MMSim *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ mm_dbg ("loading IMSI...");
+
+ mm_at_command (G_OBJECT (self),
+ mm_base_modem_get_port_primary (MM_BASE_MODEM (self->priv->modem)),
+ "+CIMI",
+ 3,
+ (MMAtResponseProcessor)common_parse_string_reply,
+ NULL, /* response_processor_context */
+ "s",
+ NULL, /*TODO: cancellable */
+ callback,
+ user_data);
+}
+
+/*****************************************************************************/
+
typedef enum {
INITIALIZATION_STEP_FIRST,
INITIALIZATION_STEP_SIM_IDENTIFIER,
+ INITIALIZATION_STEP_IMSI,
INITIALIZATION_STEP_LAST
} InitializationStep;
@@ -322,6 +384,31 @@ load_sim_identifier_ready (MMSim *self,
interface_initialization_step (ctx);
}
+#define STR_REPLY_READY_FN(NAME,DISPLAY) \
+ static void \
+ load_##NAME##_ready (MMSim *self, \
+ GAsyncResult *res, \
+ InitAsyncContext *ctx) \
+ { \
+ GError *error = NULL; \
+ gchar *val; \
+ \
+ val = load_##NAME##_finish (self, res, &error); \
+ mm_gdbus_sim_set_##NAME (MM_GDBUS_SIM (self), val); \
+ g_free (val); \
+ \
+ if (error) { \
+ mm_warn ("couldn't load %s: '%s'", DISPLAY, error->message); \
+ g_error_free (error); \
+ } \
+ \
+ /* Go on to next step */ \
+ ctx->step++; \
+ interface_initialization_step (ctx); \
+ }
+
+STR_REPLY_READY_FN (imsi, "IMSI")
+
static void
interface_initialization_step (InitAsyncContext *ctx)
{
@@ -343,6 +430,19 @@ interface_initialization_step (InitAsyncContext *ctx)
}
break;
+ case INITIALIZATION_STEP_IMSI:
+ /* IMSI is meant to be loaded only once during the whole
+ * lifetime of the modem. Therefore, if we already have them loaded,
+ * don't try to load them again. */
+ if (mm_gdbus_sim_get_imsi (MM_GDBUS_SIM (ctx->self)) == NULL) {
+ load_imsi (
+ ctx->self,
+ (GAsyncReadyCallback)load_imsi_ready,
+ ctx);
+ return;
+ }
+ break;
+
case INITIALIZATION_STEP_LAST:
/* We are done without errors! */
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);