From: Pekka Pessi <[email protected]>
Try to obtain IMSI when SIM interface is available. If SIM card is missing
or SIM is PIN locked there may be no IMSI.
Previously plugin tried to obtain IMSI and created the device when the gprs
interface became available. However, the gprs interface is expected to be
available only when modem is online and plugin needs the cellular device in
order to change the modem to the online state.
---
plugins/ofono.c | 94 ++++++++++++++++++++++++++++++++-----------------------
1 files changed, 55 insertions(+), 39 deletions(-)
diff --git a/plugins/ofono.c b/plugins/ofono.c
index 22682fb..74a8156 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -192,10 +192,35 @@ static struct connman_device_driver modem_driver = {
.disable = modem_disable,
};
+static void modem_remove_device(struct modem_data *modem)
+{
+ if (modem->device == NULL)
+ return;
+
+ connman_device_unregister(modem->device);
+ connman_device_unref(modem->device);
+
+ modem->device = NULL;
+}
+
+static void remove_modem(gpointer data)
+{
+ struct modem_data *modem = data;
+
+ g_free(modem->path);
+
+ modem_remove_device(modem);
+
+ g_free(modem);
+}
+
static char *get_ident(const char *path)
{
char *pos;
+ if (path == NULL)
+ return NULL;
+
if (*path != '/')
return NULL;
@@ -875,7 +900,7 @@ static void add_device(const char *path, const char *imsi,
struct modem_data *modem;
struct connman_device *device;
- DBG("path %s imsi %s", path, imsi);
+ DBG("path %s imsi %s", path, imsi ? imsi : "<missing>");
if (path == NULL)
return;
@@ -887,6 +912,16 @@ static void add_device(const char *path, const char *imsi,
if (modem == NULL)
return;
+ if (modem->device) {
+ char const *ident;
+
+ ident = connman_device_get_string(modem->device, "IMSI");
+ if (g_str_equal(ident, imsi))
+ return;
+
+ modem_remove_device(modem);
+ }
+
device = connman_device_create(imsi, CONNMAN_DEVICE_TYPE_CELLULAR);
if (device == NULL)
return;
@@ -896,6 +931,7 @@ static void add_device(const char *path, const char *imsi,
connman_device_set_mode(device, CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE);
connman_device_set_string(device, "Path", path);
+ connman_device_set_string(device, "IMSI", imsi); /* XXX */
if (mcc != NULL)
connman_device_set_string(device, "MCC", mcc);
if (mnc != NULL)
@@ -914,7 +950,7 @@ static void add_device(const char *path, const char *imsi,
static void sim_properties_reply(DBusPendingCall *call, void *user_data)
{
const char *path = user_data;
- const char *imsi;
+ const char *imsi = NULL;
char *mcc = NULL;
char *mnc = NULL;
/* If MobileNetworkCodeLength is not provided, mnc_length is 0 */
@@ -1047,18 +1083,19 @@ static struct modem_data *add_modem(const char *path)
return modem;
}
-static gboolean modem_has_gprs(DBusMessageIter *array)
+static gboolean modem_has_interface(DBusMessageIter *array,
+ char const *interface)
{
DBusMessageIter entry;
dbus_message_iter_recurse(array, &entry);
while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
- const char *interface;
+ const char *element;
- dbus_message_iter_get_basic(&entry, &interface);
+ dbus_message_iter_get_basic(&entry, &element);
- if (g_strcmp0(OFONO_GPRS_INTERFACE, interface) == 0)
+ if (g_strcmp0(element, interface) == 0)
return TRUE;
dbus_message_iter_next(&entry);
@@ -1074,7 +1111,7 @@ static void modem_properties_reply(DBusPendingCall *call,
void *user_data)
DBusMessageIter array, dict;
const char *path = user_data;
dbus_bool_t powered = FALSE;
- dbus_bool_t has_gprs = FALSE;
+ dbus_bool_t has_sim = FALSE;
struct modem_data *new_modem;
DBG("path %s", path);
@@ -1112,8 +1149,8 @@ static void modem_properties_reply(DBusPendingCall *call,
void *user_data)
if (g_str_equal(key, "Powered") == TRUE) {
dbus_message_iter_get_basic(&value, &powered);
} else if (g_str_equal(key, "Interfaces") == TRUE) {
- if (modem_has_gprs(&value) == TRUE)
- has_gprs = TRUE;
+ if (modem_has_interface(&value, OFONO_SIM_INTERFACE))
+ has_sim = TRUE;
}
dbus_message_iter_next(&dict);
@@ -1123,7 +1160,7 @@ static void modem_properties_reply(DBusPendingCall *call,
void *user_data)
if (new_modem) {
if (!powered)
modem_change_powered(path, TRUE);
- if (has_gprs)
+ if (has_sim)
get_imsi(path);
}
@@ -1275,28 +1312,6 @@ done:
dbus_pending_call_unref(call);
}
-static void modem_remove_device(struct modem_data *modem)
-{
- if (modem->device == NULL)
- return;
-
- connman_device_unregister(modem->device);
- connman_device_unref(modem->device);
-
- modem->device = NULL;
-}
-
-static void remove_modem(gpointer data)
-{
- struct modem_data *modem = data;
-
- g_free(modem->path);
-
- modem_remove_device(modem);
-
- g_free(modem);
-}
-
static void ofono_connect(DBusConnection *connection, void *user_data)
{
DBusMessage *message;
@@ -1371,16 +1386,17 @@ static gboolean modem_changed(DBusConnection
*connection, DBusMessage *message,
dbus_bool_t powered;
dbus_message_iter_get_basic(&value, &powered);
- if (powered == TRUE)
- return TRUE;
- modem_remove_device(modem);
+ if (powered == FALSE)
+ modem_remove_device(modem);
} else if (g_str_equal(key, "Interfaces") == TRUE) {
- if (modem_has_gprs(&value) == TRUE) {
+ if (modem_has_interface(&value, OFONO_SIM_INTERFACE)) {
if (modem->device == NULL)
- get_imsi(modem->path);
- } else if (modem->device != NULL)
- modem_remove_device(modem);
+ get_imsi(path);
+ } else {
+ if (modem->device != NULL)
+ modem_remove_device(modem);
+ }
}
return TRUE;
--
1.7.0.4
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman