From: Pekka Pessi <[email protected]>
Add device when IMSI (SubscriberIdentity) becomes available, remove device
if SIM is removed.
---
plugins/ofono.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/plugins/ofono.c b/plugins/ofono.c
index 74a8156..7cb1a00 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -1402,6 +1402,47 @@ static gboolean modem_changed(DBusConnection
*connection, DBusMessage *message,
return TRUE;
}
+static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
+ void *user_data)
+{
+ const char *path = dbus_message_get_path(message);
+ struct modem_data *modem;
+ DBusMessageIter iter, value;
+ const char *key;
+
+ DBG("path %s", path);
+
+ modem = g_hash_table_lookup(modem_hash, path);
+ if (modem == NULL)
+ return TRUE;
+
+ if (dbus_message_iter_init(message, &iter) == FALSE)
+ return TRUE;
+
+ dbus_message_iter_get_basic(&iter, &key);
+
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_recurse(&iter, &value);
+
+ if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
+ char *imsi;
+
+ dbus_message_iter_get_basic(&value, &imsi);
+
+ if (strlen(imsi) > 0)
+ add_device(path, imsi, NULL, NULL);
+ } else if (g_str_equal(key, "Present") == TRUE) {
+ dbus_bool_t present;
+
+ dbus_message_iter_get_basic(&value, &present);
+
+ if (!present && modem->device != NULL)
+ modem_remove_device(modem);
+ }
+
+ return TRUE;
+}
+
static gboolean gprs_changed(DBusConnection *connection, DBusMessage *message,
void *user_data)
{
@@ -1690,6 +1731,7 @@ static gboolean pri_context_changed(DBusConnection
*connection,
}
static guint watch;
+static guint sim_watch;
static guint gprs_watch;
static guint modem_watch;
static guint manager_watch;
@@ -1724,6 +1766,12 @@ static int ofono_init(void)
manager_changed,
NULL, NULL);
+ sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ OFONO_SIM_INTERFACE,
+ PROPERTY_CHANGED,
+ sim_changed,
+ NULL, NULL);
+
context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
OFONO_PRI_CONTEXT_INTERFACE,
PROPERTY_CHANGED,
@@ -1731,6 +1779,7 @@ static int ofono_init(void)
NULL, NULL);
if (watch == 0 || gprs_watch == 0 || modem_watch == 0 ||
+ sim_watch == 0 ||
manager_watch == 0 || context_watch == 0) {
err = -EIO;
goto remove;
@@ -1750,6 +1799,7 @@ static int ofono_init(void)
remove:
g_dbus_remove_watch(connection, watch);
+ g_dbus_remove_watch(connection, sim_watch);
g_dbus_remove_watch(connection, gprs_watch);
g_dbus_remove_watch(connection, modem_watch);
g_dbus_remove_watch(connection, manager_watch);
@@ -1763,6 +1813,7 @@ remove:
static void ofono_exit(void)
{
g_dbus_remove_watch(connection, watch);
+ g_dbus_remove_watch(connection, sim_watch);
g_dbus_remove_watch(connection, gprs_watch);
g_dbus_remove_watch(connection, modem_watch);
g_dbus_remove_watch(connection, manager_watch);
--
1.7.0.4
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman