#include <gdbus.h>
#include <string.h>
+#include <stdint.h>
#define CONNMAN_API_SUBJECT_TO_CHANGE
#include <connman/plugin.h>
#include <connman/device.h>
#include <connman/network.h>
-#include <connman/ipconfig.h>
#include <connman/dbus.h>
-#include <connman/inet.h>
-#include <connman/technology.h>
#include <connman/log.h>
-#include "mcc.h"
+#define uninitialized_var(x) x = x
#define OFONO_SERVICE "org.ofono"
#define OFONO_MANAGER_INTERFACE OFONO_SERVICE ".Manager"
#define OFONO_MODEM_INTERFACE OFONO_SERVICE ".Modem"
-#define OFONO_GPRS_INTERFACE OFONO_SERVICE ".ConnectionManager"
-#define OFONO_CONTEXT_INTERFACE OFONO_SERVICE ".ConnectionContext"
#define OFONO_SIM_INTERFACE OFONO_SERVICE ".SimManager"
-#define OFONO_REGISTRATION_INTERFACE OFONO_SERVICE ".NetworkRegistration"
+#define OFONO_NETREG_INTERFACE OFONO_SERVICE ".NetworkRegistration"
+#define OFONO_CM_INTERFACE OFONO_SERVICE ".ConnectionManager"
+#define OFONO_CONTEXT_INTERFACE OFONO_SERVICE ".ConnectionContext"
+#define MODEM_ADDED "ModemAdded"
+#define MODEM_REMOVED "ModemRemoved"
#define PROPERTY_CHANGED "PropertyChanged"
-#define GET_PROPERTIES "GetProperties"
-#define SET_PROPERTY "SetProperty"
#define CONTEXT_ADDED "ContextAdded"
#define CONTEXT_REMOVED "ContextRemoved"
-#define ADD_CONTEXT "AddContext"
-#define GET_MODEMS "GetModems"
-#define MODEM_ADDED "ModemAdded"
-#define MODEM_REMOVED "ModemRemoved"
+#define GET_PROPERTIES "GetProperties"
+#define SET_PROPERTY "SetProperty"
+#define GET_MODEMS "GetModems"
#define TIMEOUT 40000
-static DBusConnection *connection;
+enum ofono_api {
+ OFONO_API_SIM = 0x1,
+ OFONO_API_NETREG = 0x2,
+ OFONO_API_CM = 0x4,
+};
-static GHashTable *modem_hash = NULL;
+static DBusConnection *connection;
-static GHashTable *network_hash;
+static GHashTable *modem_hash;
struct modem_data {
char *path;
+
struct connman_device *device;
- gboolean has_sim;
- gboolean has_reg;
- gboolean has_gprs;
- gboolean available;
- gboolean pending_online;
- dbus_bool_t requested_online;
- dbus_bool_t online;
-
- /* org.ofono.ConnectionManager properties */
- dbus_bool_t powered;
- dbus_bool_t attached;
- dbus_bool_t roaming_allowed;
-
- connman_bool_t registered;
- connman_bool_t roaming;
- uint8_t strength, has_strength;
- char *operator;
-};
-struct network_info {
- struct connman_network *network;
+ /* Modem Interface */
+ char *serial;
+ connman_bool_t powered;
+ connman_bool_t online;
+ uint8_t interfaces;
+
+ connman_bool_t set_powered;
+ connman_bool_t set_online;
- enum connman_ipconfig_method ipv4_method;
- struct connman_ipaddress ipv4_address;
+ /* ConnectionManager Interface */
+ connman_bool_t attached;
- enum connman_ipconfig_method ipv6_method;
- struct connman_ipaddress ipv6_address;
+ /* SimManager Interface */
+ char *imsi;
+
+ /* pending calls */
+ DBusPendingCall *call_set_property;
+ DBusPendingCall *call_get_properties;
};
-static int modem_probe(struct connman_device *device)
-{
- DBG("device %p", device);
+typedef void (*set_property_cb)(struct modem_data *data,
+ connman_bool_t success);
+typedef void (*get_properties_cb)(struct modem_data *data,
+ DBusMessageIter *dict);
- return 0;
-}
+struct property_info {
+ struct modem_data *modem;
+ const char *path;
+ const char *interface;
+ const char *property;
+ set_property_cb set_property_cb;
+ get_properties_cb get_properties_cb;
+};
-static void modem_remove(struct connman_device *device)
+static void set_property_reply(DBusPendingCall *call, void *user_data)
{
- DBG("device %p", device);
+ struct property_info *info = user_data;
+ DBusMessage *reply;
+ DBusError error;
+ connman_bool_t success = TRUE;
+
+ DBG("%s path %s %s.%s", info->modem->path,
+ info->path, info->interface, info->property);
+
+ info->modem->call_set_property = NULL;
+
+ dbus_error_init(&error);
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ if (dbus_set_error_from_message(&error, reply)) {
+ connman_error("Failed to change property: %s %s.%s: %s %s",
+ info->path, info->interface, info->property,
+ error.name, error.message);
+ dbus_error_free(&error);
+ success = FALSE;
+ }
+
+ if (info->set_property_cb != NULL)
+ (*info->set_property_cb)(info->modem, success);
+
+ dbus_message_unref(reply);
+
+ dbus_pending_call_unref(call);
}
-static int call_ofono(const char *path,
- const char *interface, const char *method,
- DBusPendingCallNotifyFunction notify, void *user_data,
- DBusFreeFunction free_function,
- int type, ...)
+static int set_property(struct modem_data *modem,
+ const char *path, const char *interface,
+ const char *property, int type, void *value,
+ set_property_cb notify)
{
DBusMessage *message;
- DBusPendingCall *call;
- dbus_bool_t ok;
- va_list va;
+ DBusMessageIter iter;
+ struct property_info *info;
- DBG("path %s %s.%s", path, interface, method);
+ DBG("%s path %s %s.%s", modem->path, path, interface, property);
- if (path == NULL)
- return -EINVAL;
+ if (modem->call_set_property != NULL) {
+ connman_error("Pending SetProperty");
+ return -EBUSY;
+ }
message = dbus_message_new_method_call(OFONO_SERVICE, path,
- interface, method);
+ interface, SET_PROPERTY);
if (message == NULL)
return -ENOMEM;
- dbus_message_set_auto_start(message, FALSE);
-
- va_start(va, type);
- ok = dbus_message_append_args_valist(message, type, va);
- va_end(va);
-
- if (!ok)
- return -ENOMEM;
+ dbus_message_iter_init_append(message, &iter);
+ connman_dbus_property_append_basic(&iter, property, type, value);
if (dbus_connection_send_with_reply(connection, message,
- &call, TIMEOUT) == FALSE) {
- connman_error("Failed to call %s.%s", interface, method);
+ &modem->call_set_property, TIMEOUT) == FALSE) {
+ connman_error("Failed to change property: %s %s.%s",
+ path, interface, property);
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (modem->call_set_property == NULL) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
}
- dbus_pending_call_set_notify(call, notify, user_data, free_function);
+ info = g_try_new0(struct property_info, 1);
+ if (info == NULL) {
+ dbus_message_unref(message);
+ return -ENOMEM;
+ }
+
+ info->modem = modem;
+ info->path = path;
+ info->interface = interface;
+ info->property = property;
+ info->set_property_cb = notify;
+
+ dbus_pending_call_set_notify(modem->call_set_property,
+ set_property_reply, info, g_free);
dbus_message_unref(message);
return -EINPROGRESS;
}
-static void set_property_reply(DBusPendingCall *call, void *user_data)
+static void get_properties_reply(DBusPendingCall *call, void *user_data)
{
+ struct property_info *info = user_data;
+ DBusMessageIter array, dict;
DBusMessage *reply;
DBusError error;
- char const *name = user_data;
- DBG("");
+ DBG("%s path %s %s", info->modem->path, info->path, info->interface);
+
+ info->modem->call_get_properties = NULL;
dbus_error_init(&error);
reply = dbus_pending_call_steal_reply(call);
if (dbus_set_error_from_message(&error, reply)) {
- connman_error("SetProperty(%s) %s %s", name,
+ connman_error("Failed to get properties: %s %s: %s %s",
+ info->path, info->interface,
error.name, error.message);
dbus_error_free(&error);
+
+ goto done;
}
+ if (dbus_message_iter_init(reply, &array) == FALSE)
+ goto done;
+
+ if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+ goto done;
+
+ dbus_message_iter_recurse(&array, &dict);
+
+ if (info->get_properties_cb != NULL)
+ (*info->get_properties_cb)(info->modem, &dict);
+
+done:
+
dbus_message_unref(reply);
dbus_pending_call_unref(call);
}
-static int set_property(const char *path, const char *interface,
- const char *property, int type, void *value,
- DBusPendingCallNotifyFunction notify, void *user_data,
- DBusFreeFunction free_function)
+static int get_properties(const char *path, const char *interface,
+ get_properties_cb notify,
+ struct modem_data *modem)
{
DBusMessage *message;
- DBusMessageIter iter;
- DBusPendingCall *call;
+ struct property_info *info;
- DBG("path %s %s.%s", path, interface, property);
+ DBG("%s path %s %s", modem->path, path, interface);
- g_assert(notify == NULL ? free_function == NULL : 1);
-
- if (path == NULL)
- return -EINVAL;
+ if (modem->call_get_properties != NULL) {
+ connman_error("Pending GetProperties");
+ return -EBUSY;
+ }
message = dbus_message_new_method_call(OFONO_SERVICE, path,
- interface, SET_PROPERTY);
+ interface, GET_PROPERTIES);
if (message == NULL)
return -ENOMEM;
- dbus_message_set_auto_start(message, FALSE);
-
- dbus_message_iter_init_append(message, &iter);
- connman_dbus_property_append_basic(&iter, property, type, value);
-
if (dbus_connection_send_with_reply(connection, message,
- &call, TIMEOUT) == FALSE) {
- connman_error("Failed to change \"%s\" property on %s",
- property, interface);
+ &modem->call_get_properties, TIMEOUT) == FALSE) {
+ connman_error("Failed to call %s.GetProperties()", interface);
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (modem->call_get_properties == NULL) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
}
- if (notify == NULL) {
- notify = set_property_reply;
- user_data = (void *)property;
- free_function = NULL;
+ info = g_try_new0(struct property_info, 1);
+ if (info == NULL) {
+ dbus_message_unref(message);
+ return -ENOMEM;
}
- dbus_pending_call_set_notify(call, notify, user_data, free_function);
+ info->modem = modem;
+ info->path = path;
+ info->interface = interface;
+ info->get_properties_cb = notify;
+
+ dbus_pending_call_set_notify(modem->call_get_properties,
+ get_properties_reply, info, g_free);
dbus_message_unref(message);
return -EINPROGRESS;
}
-static void update_modem_online(struct modem_data *modem,
- connman_bool_t online)
+static void modem_set_online_reply(struct modem_data *modem,
+ connman_bool_t success)
{
- DBG("modem %p path %s online %d", modem, modem->path, online);
+ DBG("%s", modem->path);
- modem->online = online;
- modem->requested_online = online;
- modem->pending_online = FALSE;
+ if (success == TRUE) {
+ /*
+ * Don't handle do anything on success here. oFono will send
+ * the change via PropertyChanged singal.
+ */
+ return;
+ }
- if (modem->device)
- connman_device_set_powered(modem->device, online);
+ modem->set_online = FALSE;
}
-static void set_online_reply(DBusPendingCall *call, void *user_data)
+static int modem_set_online(struct modem_data *modem)
{
- struct modem_data *modem;
- DBusMessage *reply;
- DBusError error;
- gboolean result;
+ DBG("%s", modem->path);
- DBG("path %s", (char *)user_data);
-
- if (modem_hash == NULL)
- return;
-
- modem = g_hash_table_lookup(modem_hash, user_data);
- if (modem == NULL)
- return;
-
- reply = dbus_pending_call_steal_reply(call);
+ modem->set_online = TRUE;
- dbus_error_init(&error);
+ return set_property(modem, modem->path,
+ OFONO_MODEM_INTERFACE,
+ "Online", DBUS_TYPE_BOOLEAN,
+ &modem->set_online,
+ modem_set_online_reply);
+}
- if (dbus_set_error_from_message(&error, reply)) {
- connman_error("SetProperty(Online) %s %s",
- error.name, error.message);
- dbus_error_free(&error);
+static int modem_set_powered(struct modem_data *modem)
+{
+ DBG("%s", modem->path);
- result = modem->online;
- } else
- result = modem->requested_online;
+ modem->set_powered = TRUE;
- if (modem->pending_online)
- update_modem_online(modem, result);
+ return set_property(modem, modem->path,
+ OFONO_MODEM_INTERFACE,
+ "Powered", DBUS_TYPE_BOOLEAN,
+ &modem->set_powered,
+ NULL);
+}
- dbus_message_unref(reply);
+static connman_bool_t has_interface(uint8_t interfaces,
+ enum ofono_api api)
+{
+ if ((interfaces & api) == api)
+ return TRUE;
- dbus_pending_call_unref(call);
+ return FALSE;
}
-static int modem_change_online(char const *path, dbus_bool_t online)
+static uint8_t extract_interfaces(DBusMessageIter *array)
{
- struct modem_data *modem = g_hash_table_lookup(modem_hash, path);
+ DBusMessageIter entry;
+ uint8_t interfaces = 0;
- if (modem == NULL)
- return -ENODEV;
+ dbus_message_iter_recurse(array, &entry);
+
+ while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+ const char *name;
+
+ dbus_message_iter_get_basic(&entry, &name);
- if (modem->online == online)
- return -EALREADY;
+ if (g_str_equal(name, OFONO_SIM_INTERFACE) == TRUE)
+ interfaces |= OFONO_API_SIM;
+ else if (g_str_equal(name, OFONO_NETREG_INTERFACE) == TRUE)
+ interfaces |= OFONO_API_NETREG;
+ else if (g_str_equal(name, OFONO_CM_INTERFACE) == TRUE)
+ interfaces |= OFONO_API_CM;
- modem->requested_online = online;
+ dbus_message_iter_next(&entry);
+ }
- return set_property(path, OFONO_MODEM_INTERFACE, "Online",
- DBUS_TYPE_BOOLEAN, &online,
- set_online_reply,
- (void *)g_strdup(path), g_free);
+ return interfaces;
}
-static int modem_enable(struct connman_device *device)
+static connman_bool_t ready_to_create_device(struct modem_data *modem)
{
- const char *path = connman_device_get_string(device, "Path");
+ /*
+ * There are three different modem types which behave slightly
+ * different:
+ * - GSM modems will expose the SIM interface then the
+ * CM interface.
+ * - DUN modems will expose first a unique serial number (BDADDR)
+ * and then the CM interface.
+ * - CDMA modems will expose CM first and sometime later
+ * a unique serial number.
+ *
+ * This functions tests if we have the necessary information gathered
+ * before we are able to create a device.
+ */
+
+ if (modem->device != NULL)
+ return FALSE;
- DBG("device %p, path, %s", device, path);
+ if (modem->imsi != NULL || modem->serial != NULL)
+ return TRUE;
- return modem_change_online(path, TRUE);
+ return FALSE;
}
-static int modem_disable(struct connman_device *device)
+static void create_device(struct modem_data *modem)
{
- const char *path = connman_device_get_string(device, "Path");
+ struct connman_device *device;
+ char *uninitialized_var(ident);
- DBG("device %p path %s", device, path);
+ DBG("%s", modem->path);
- return modem_change_online(path, FALSE);
-}
+ if (modem->imsi != NULL)
+ ident = modem->imsi;
+ else if (modem->serial != NULL)
+ ident = modem->serial;
-static struct connman_device_driver modem_driver = {
- .name = "modem",
- .type = CONNMAN_DEVICE_TYPE_CELLULAR,
- .probe = modem_probe,
- .remove = modem_remove,
- .enable = modem_enable,
- .disable = modem_disable,
-};
+ if (connman_dbus_validate_ident(ident) == FALSE)
+ ident = connman_dbus_encode_string(ident);
+ else
+ ident = g_strdup(ident);
-static void remove_device_networks(struct connman_device *device)
-{
- GHashTableIter iter;
- gpointer key, value;
- GSList *info_list = NULL;
- GSList *list;
+ device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_CELLULAR);
+ if (device == NULL)
+ goto out;
- if (network_hash == NULL)
- return;
+ DBG("device %p", device);
- g_hash_table_iter_init(&iter, network_hash);
+ connman_device_set_ident(device, ident);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
- struct network_info *info = value;
+ connman_device_set_string(device, "Path", modem->path);
- if (connman_network_get_device(info->network) != device)
- continue;
+ connman_device_set_data(device, modem);
- info_list = g_slist_append(info_list, info);
+ if (connman_device_register(device) < 0) {
+ connman_error("Failed to register cellular device");
+ connman_device_unref(device);
+ goto out;
}
- for (list = info_list; list != NULL; list = list->next) {
- struct network_info *info = list->data;
-
- connman_device_remove_network(device, info->network);
- }
+ modem->device = device;
- g_slist_free(info_list);
+out:
+ g_free(ident);
}
-static void modem_remove_device(struct modem_data *modem)
+static void destroy_device(struct modem_data *modem)
{
- DBG("modem %p path %s device %p", modem, modem->path, modem->device);
-
- if (modem->device == NULL)
- return;
+ DBG("%s", modem->path);
- remove_device_networks(modem->device);
+ connman_device_set_powered(modem->device, FALSE);
connman_device_unregister(modem->device);
connman_device_unref(modem->device);
modem->device = NULL;
}
-static void remove_modem(gpointer data)
+static gboolean context_changed(DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
{
- struct modem_data *modem = data;
+ return TRUE;
+}
- modem_remove_device(modem);
+static gboolean cm_context_added(DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ return TRUE;
+}
- g_free(modem->path);
- g_free(modem->operator);
+static gboolean cm_context_removed(DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ return TRUE;
+}
- g_free(modem);
+static gboolean netreg_changed(DBusConnection *connection, DBusMessage *message,
+ void *user_data)
+{
+ return TRUE;
}
-static void remove_network(gpointer data)
+static gboolean cm_changed(DBusConnection *connection, DBusMessage *message,
+ void *user_data)
{
- struct network_info *info = data;
- struct connman_device *device;
+ const char *path = dbus_message_get_path(message);
+ struct modem_data *modem;
+ DBusMessageIter iter, value;
+ const char *key;
- device = connman_network_get_device(info->network);
- if (device != NULL)
- connman_device_remove_network(device, info->network);
+ modem = g_hash_table_lookup(modem_hash, path);
+ if (modem == NULL)
+ return TRUE;
- connman_network_unref(info->network);
+ if (dbus_message_iter_init(message, &iter) == FALSE)
+ return TRUE;
- g_free(info);
-}
+ dbus_message_iter_get_basic(&iter, &key);
-static char *get_ident(const char *path)
-{
- char *pos;
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_recurse(&iter, &value);
- if (*path != '/')
- return NULL;
+ if (g_str_equal(key, "Attached") == TRUE) {
+ dbus_message_iter_get_basic(&value, &modem->attached);
- pos = strrchr(path, '/');
- if (pos == NULL)
- return NULL;
+ DBG("%s Attached %d", modem->path, modem->attached);
+ }
- return pos + 1;
+ return TRUE;
}
-static void create_service(struct connman_network *network)
+static void cm_properties_reply(struct modem_data *modem, DBusMessageIter *dict)
{
- const char *path;
- char *group;
+ DBG("%s", modem->path);
- DBG("");
+ while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
+ DBusMessageIter entry, value;
+ const char *key;
- path = connman_network_get_string(network, "Path");
+ dbus_message_iter_recurse(dict, &entry);
+ dbus_message_iter_get_basic(&entry, &key);
- group = get_ident(path);
+ dbus_message_iter_next(&entry);
+ dbus_message_iter_recurse(&entry, &value);
- connman_network_set_group(network, group);
-}
+ if (g_str_equal(key, "Attached") == TRUE) {
+ dbus_message_iter_get_basic(&value, &modem->attached);
-static int network_probe(struct connman_network *network)
-{
- return 0;
-}
+ DBG("%s Attached %d", modem->path,
+ modem->attached);
-static gboolean pending_network_is_available(struct connman_network *network)
-{
- /* Modem or network may be removed */
- if (network == NULL || connman_network_get_device(network) == NULL) {
- DBG("Modem or network was removed");
- return FALSE;
+ return;
+ }
+
+ dbus_message_iter_next(dict);
}
+}
- return TRUE;
+static int cm_get_properties(struct modem_data *modem)
+{
+ return get_properties(modem->path, OFONO_CM_INTERFACE,
+ cm_properties_reply, modem);
}
-static void set_connected(struct network_info *info,
- connman_bool_t connected)
+static void update_sim_imsi(struct modem_data *modem,
+ const char *imsi)
{
- gboolean setip = FALSE;
-
- DBG("network %p connected %d", info->network, connected);
-
- switch (info->ipv4_method) {
- case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
- case CONNMAN_IPCONFIG_METHOD_OFF:
- case CONNMAN_IPCONFIG_METHOD_MANUAL:
- case CONNMAN_IPCONFIG_METHOD_AUTO:
- break;
-
- case CONNMAN_IPCONFIG_METHOD_FIXED:
- connman_network_set_ipv4_method(info->network,
- info->ipv4_method);
- connman_network_set_ipaddress(info->network,
- &info->ipv4_address);
- setip = TRUE;
- break;
-
- case CONNMAN_IPCONFIG_METHOD_DHCP:
- connman_network_set_ipv4_method(info->network,
- info->ipv4_method);
- setip = TRUE;
- break;
- }
+ DBG("%s imsi %s", modem->path, imsi);
- switch (info->ipv6_method) {
- case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
- case CONNMAN_IPCONFIG_METHOD_OFF:
- case CONNMAN_IPCONFIG_METHOD_MANUAL:
- case CONNMAN_IPCONFIG_METHOD_DHCP:
- case CONNMAN_IPCONFIG_METHOD_AUTO:
- break;
-
- case CONNMAN_IPCONFIG_METHOD_FIXED:
- connman_network_set_ipv6_method(info->network,
- info->ipv6_method);
- connman_network_set_ipaddress(info->network,
- &info->ipv6_address);
- setip = TRUE;
- break;
- }
+ if (g_strcmp0(modem->imsi, imsi) == 0)
+ return;
- if (setip == TRUE)
- connman_network_set_connected(info->network, connected);
+ g_free(modem->imsi);
+ modem->imsi = g_strdup(imsi);
}
-static void set_active_reply(DBusPendingCall *call, void *user_data)
+static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
+ void *user_data)
{
- char const *path = user_data;
- DBusMessage *reply;
- DBusError error;
- struct network_info *info;
+ const char *path = dbus_message_get_path(message);
+ struct modem_data *modem;
+ DBusMessageIter iter, value;
+ const char *key;
- info = g_hash_table_lookup(network_hash, path);
+ modem = g_hash_table_lookup(modem_hash, path);
+ if (modem == NULL)
+ return TRUE;
- reply = dbus_pending_call_steal_reply(call);
+ if (dbus_message_iter_init(message, &iter) == FALSE)
+ return TRUE;
- if (info == NULL)
- goto done;
+ dbus_message_iter_get_basic(&iter, &key);
- DBG("path %s network %p", path, info->network);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_recurse(&iter, &value);
- if (!pending_network_is_available(info->network))
- goto done;
+ if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
+ char *imsi;
- dbus_error_init(&error);
+ dbus_message_iter_get_basic(&value, &imsi);
- if (dbus_set_error_from_message(&error, reply)) {
- connman_error("SetProperty(Active) %s %s",
- error.name, error.message);
+ update_sim_imsi(modem, imsi);
- if (connman_network_get_index(info->network) < 0)
- connman_network_set_error(info->network,
- CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
+ if (modem->online == FALSE) {
+ modem_set_online(modem);
+ } else if (has_interface(modem->interfaces,
+ OFONO_API_CM) == TRUE) {
+ if (ready_to_create_device(modem) == TRUE)
+ create_device(modem);
+ }
+ }
- dbus_error_free(&error);
- } else if (connman_network_get_index(info->network) >= 0)
- set_connected(info, TRUE);
+ return TRUE;
+}
-done:
- dbus_message_unref(reply);
+static void sim_properties_reply(struct modem_data *modem,
+ DBusMessageIter *dict)
+{
+ DBG("%s", modem->path);
- dbus_pending_call_unref(call);
-}
-
-static int set_network_active(struct connman_network *network)
-{
- dbus_bool_t value = TRUE;
- const char *path = connman_network_get_string(network, "Path");
-
- DBG("network %p, path %s", network, path);
-
- return set_property(path, OFONO_CONTEXT_INTERFACE,
- "Active", DBUS_TYPE_BOOLEAN, &value,
- set_active_reply, g_strdup(path), g_free);
-}
-
-static int set_network_inactive(struct connman_network *network)
-{
- int err;
- dbus_bool_t value = FALSE;
- const char *path = connman_network_get_string(network, "Path");
-
- DBG("network %p, path %s", network, path);
-
- err = set_property(path, OFONO_CONTEXT_INTERFACE,
- "Active", DBUS_TYPE_BOOLEAN, &value,
- NULL, NULL, NULL);
-
- if (err == -EINPROGRESS)
- err = 0;
-
- return err;
-}
-
-static int network_connect(struct connman_network *network)
-{
- struct connman_device *device;
- struct modem_data *modem;
-
- DBG("network %p", network);
-
- device = connman_network_get_device(network);
- if (device == NULL)
- return -ENODEV;
-
- modem = connman_device_get_data(device);
- if (modem == NULL)
- return -ENODEV;
-
- if (modem->registered == FALSE)
- return -ENOLINK;
-
- if (modem->powered == FALSE)
- return -ENOLINK;
-
- if (modem->roaming_allowed == FALSE && modem->roaming == TRUE)
- return -ENOLINK;
-
- return set_network_active(network);
-}
-
-static int network_disconnect(struct connman_network *network)
-{
- DBG("network %p", network);
-
- if (connman_network_get_index(network) < 0)
- return -ENOTCONN;
-
- connman_network_set_associating(network, FALSE);
-
- return set_network_inactive(network);
-}
-
-static void network_remove(struct connman_network *network)
-{
- char const *path = connman_network_get_string(network, "Path");
-
- DBG("network %p path %s", network, path);
-
- g_hash_table_remove(network_hash, path);
-}
-
-static struct connman_network_driver network_driver = {
- .name = "network",
- .type = CONNMAN_NETWORK_TYPE_CELLULAR,
- .probe = network_probe,
- .remove = network_remove,
- .connect = network_connect,
- .disconnect = network_disconnect,
-};
-
-static void get_dns(DBusMessageIter *array, struct network_info *info)
-{
- DBusMessageIter entry;
- gchar *nameservers = NULL, *nameservers_old = NULL;
-
- DBG("");
-
-
- dbus_message_iter_recurse(array, &entry);
-
- while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
- const char *dns;
-
- dbus_message_iter_get_basic(&entry, &dns);
-
- DBG("dns %s", dns);
-
- if (nameservers == NULL) {
-
- nameservers = g_strdup(dns);
- } else {
-
- nameservers_old = nameservers;
- nameservers = g_strdup_printf("%s %s",
- nameservers_old, dns);
- g_free(nameservers_old);
- }
-
- dbus_message_iter_next(&entry);
- }
-
- connman_network_set_nameservers(info->network, nameservers);
-
- g_free(nameservers);
-}
-
-static void update_ipv4_settings(DBusMessageIter *array,
- struct network_info *info)
-{
- DBusMessageIter dict;
- char *address = NULL, *netmask = NULL, *gateway = NULL;
- const char *interface = NULL;
-
- DBG("network %p", info->network);
-
- if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
- return;
-
- dbus_message_iter_recurse(array, &dict);
-
- while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter entry, value;
- const char *key, *val;
-
- dbus_message_iter_recurse(&dict, &entry);
- dbus_message_iter_get_basic(&entry, &key);
-
- DBG("key %s", key);
-
- dbus_message_iter_next(&entry);
- dbus_message_iter_recurse(&entry, &value);
-
- if (g_str_equal(key, "Interface") == TRUE) {
- int index;
-
- dbus_message_iter_get_basic(&value, &interface);
-
- DBG("interface %s", interface);
-
- index = connman_inet_ifindex(interface);
- if (index >= 0) {
- connman_network_set_index(info->network, index);
- } else {
- connman_error("Can not find interface %s",
- interface);
- break;
- }
- } else if (g_str_equal(key, "Method") == TRUE) {
- const char *method;
-
- dbus_message_iter_get_basic(&value, &method);
-
- if (g_strcmp0(method, "static") == 0) {
-
- info->ipv4_method =
- CONNMAN_IPCONFIG_METHOD_FIXED;
- } else if (g_strcmp0(method, "dhcp") == 0) {
-
- info->ipv4_method =
- CONNMAN_IPCONFIG_METHOD_DHCP;
- break;
- }
- } else if (g_str_equal(key, "Address") == TRUE) {
- dbus_message_iter_get_basic(&value, &val);
-
- address = g_strdup(val);
-
- DBG("address %s", address);
- } else if (g_str_equal(key, "Netmask") == TRUE) {
- dbus_message_iter_get_basic(&value, &val);
-
- netmask = g_strdup(val);
-
- DBG("netmask %s", netmask);
- } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
-
- get_dns(&value, info);
- } else if (g_str_equal(key, "Gateway") == TRUE) {
- dbus_message_iter_get_basic(&value, &val);
-
- gateway = g_strdup(val);
-
- DBG("gateway %s", gateway);
- }
-
- dbus_message_iter_next(&dict);
- }
-
-
- if (info->ipv4_method == CONNMAN_IPCONFIG_METHOD_FIXED) {
- connman_ipaddress_set_ipv4(&info->ipv4_address, address,
- netmask, gateway);
- }
-
- /* deactive, oFono send NULL inteface before deactive signal */
- if (interface == NULL)
- connman_network_set_index(info->network, -1);
-
- g_free(address);
- g_free(netmask);
- g_free(gateway);
-}
-
-static void update_ipv6_settings(DBusMessageIter *array,
- struct network_info *info)
-{
- DBusMessageIter dict;
- char *address = NULL, *gateway = NULL;
- unsigned char prefix_length;
- const char *interface = NULL;
-
- DBG("network %p", info->network);
-
- if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
- return;
-
- dbus_message_iter_recurse(array, &dict);
-
- info->ipv6_method = CONNMAN_IPCONFIG_METHOD_FIXED;
-
- while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter entry, value;
- const char *key, *val;
-
- dbus_message_iter_recurse(&dict, &entry);
- dbus_message_iter_get_basic(&entry, &key);
-
- DBG("key %s", key);
-
- dbus_message_iter_next(&entry);
- dbus_message_iter_recurse(&entry, &value);
-
- if (g_str_equal(key, "Interface") == TRUE) {
- int index;
-
- dbus_message_iter_get_basic(&value, &interface);
-
- DBG("interface %s", interface);
-
- index = connman_inet_ifindex(interface);
- if (index >= 0) {
- connman_network_set_index(info->network, index);
- } else {
- connman_error("Can not find interface %s",
- interface);
- break;
- }
- } else if (g_str_equal(key, "Address") == TRUE) {
- dbus_message_iter_get_basic(&value, &val);
-
- address = g_strdup(val);
-
- DBG("address %s", address);
- } else if (g_str_equal(key, "PrefixLength") == TRUE) {
- dbus_message_iter_get_basic(&value, &prefix_length);
-
- DBG("prefix length %d", prefix_length);
- } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
-
- get_dns(&value, info);
- } else if (g_str_equal(key, "Gateway") == TRUE) {
- dbus_message_iter_get_basic(&value, &val);
-
- gateway = g_strdup(val);
-
- DBG("gateway %s", gateway);
- }
-
- dbus_message_iter_next(&dict);
- }
-
- connman_ipaddress_set_ipv6(&info->ipv6_address, address,
- prefix_length, gateway);
-
- /* deactive, oFono send NULL inteface before deactive signal */
- if (interface == NULL)
- connman_network_set_index(info->network, -1);
-
- g_free(address);
- g_free(gateway);
-}
-
-static int add_network(struct connman_device *device,
- const char *path, DBusMessageIter *dict)
-{
- struct modem_data *modem = connman_device_get_data(device);
- struct connman_network *network;
- struct network_info *info;
- char *ident;
- dbus_bool_t active = FALSE;
-
- DBG("modem %p device %p path %s", modem, device, path);
-
- ident = get_ident(path);
-
- network = connman_device_get_network(device, ident);
- if (network != NULL)
- return -EALREADY;
-
- info = g_hash_table_lookup(network_hash, path);
- if (info != NULL) {
- DBG("path %p already exists with device %p", path,
- connman_network_get_device(info->network));
- if (connman_network_get_device(info->network))
- return -EALREADY;
- g_hash_table_remove(network_hash, path);
- }
-
- network = connman_network_create(ident, CONNMAN_NETWORK_TYPE_CELLULAR);
- if (network == NULL)
- return -ENOMEM;
-
- info = g_try_new0(struct network_info, 1);
- if (info == NULL) {
- connman_network_unref(network);
- return -ENOMEM;
- }
-
- connman_ipaddress_clear(&info->ipv4_address);
- connman_ipaddress_clear(&info->ipv6_address);
- info->network = network;
-
- connman_network_set_string(network, "Path", path);
-
- create_service(network);
-
- g_hash_table_insert(network_hash, g_strdup(path), info);
-
- connman_network_set_available(network, TRUE);
- connman_network_set_index(network, -1);
-
- if (modem->operator)
- connman_network_set_name(network, modem->operator);
- else
- connman_network_set_name(network, "");
-
- if (modem->has_strength)
- connman_network_set_strength(network, modem->strength);
-
- connman_network_set_roaming(network, modem->roaming);
-
- while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter entry, value;
- const char *key;
-
- dbus_message_iter_recurse(dict, &entry);
- dbus_message_iter_get_basic(&entry, &key);
-
- dbus_message_iter_next(&entry);
- dbus_message_iter_recurse(&entry, &value);
-
- if (g_str_equal(key, "Type")) {
- const char *type;
-
- dbus_message_iter_get_basic(&value, &type);
- if (g_strcmp0(type, "internet") != 0) {
- DBG("path %p type %s", path, type);
- g_hash_table_remove(network_hash, path);
- return -EIO;
- }
- } else if (g_str_equal(key, "Settings"))
- update_ipv4_settings(&value, info);
- else if (g_str_equal(key, "IPv6.Settings"))
- update_ipv6_settings(&value, info);
- else if (g_str_equal(key, "Active") == TRUE)
- dbus_message_iter_get_basic(&value, &active);
-
- dbus_message_iter_next(dict);
- }
-
- if (connman_device_add_network(device, network) != 0) {
- g_hash_table_remove(network_hash, path);
- return -EIO;
- }
-
- /* Connect only if requested to do so */
- if (active && connman_network_get_connecting(network) == TRUE)
- set_connected(info, active);
-
- return 0;
-}
-
-static void check_networks_reply(DBusPendingCall *call, void *user_data)
-{
- char *path = user_data;
- struct modem_data *modem;
- DBusMessage *reply;
- DBusMessageIter array, entry, value, properties;
-
- DBG("path %s", path);
-
- modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
- return;
- if (modem->device == NULL)
- return;
-
- reply = dbus_pending_call_steal_reply(call);
-
- if (dbus_message_has_signature(reply, "a(oa{sv})") == FALSE)
- goto done;
-
- dbus_message_iter_init(reply, &array);
-
- dbus_message_iter_recurse(&array, &entry);
-
- while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRUCT) {
- char const *network_path;
-
- dbus_message_iter_recurse(&entry, &value);
- dbus_message_iter_get_basic(&value, &network_path);
-
- dbus_message_iter_next(&value);
- dbus_message_iter_recurse(&value, &properties);
-
- add_network(modem->device, network_path, &properties);
-
- dbus_message_iter_next(&entry);
- }
-
-done:
- dbus_message_unref(reply);
-
- dbus_pending_call_unref(call);
-}
-
-static void check_networks(struct modem_data *modem)
-{
- char const *path = modem->path;
-
- DBG("modem %p path %s", modem, path);
-
- call_ofono(path, OFONO_GPRS_INTERFACE, "GetContexts",
- check_networks_reply, g_strdup(path), g_free,
- DBUS_TYPE_INVALID);
-}
-
-static void modem_clear_network_errors(struct modem_data *modem)
-{
- struct connman_device *device = modem->device;
- GHashTableIter i;
- gpointer value;
-
- if (device == NULL)
- return;
-
- g_hash_table_iter_init(&i, network_hash);
-
- while (g_hash_table_iter_next(&i, NULL, &value)) {
- struct network_info *info = value;
-
- if (connman_network_get_device(info->network) == device)
- connman_network_clear_error(info->network);
- }
-}
-
-static void modem_operator_name_changed(struct modem_data *modem,
- char const *name)
-{
- struct connman_device *device = modem->device;
- GHashTableIter i;
- gpointer value;
-
- if (device == NULL)
- return;
-
- if (modem->operator != NULL)
- g_free(modem->operator);
- modem->operator = g_strdup(name);
-
- for (g_hash_table_iter_init(&i, network_hash);
- g_hash_table_iter_next(&i, NULL, &value);) {
- struct network_info *info = value;
-
- if (connman_network_get_device(info->network) == device) {
- connman_network_set_name(info->network, name);
- connman_network_update(info->network);
- }
- }
-}
-
-static void modem_strength_changed(struct modem_data *modem, uint8_t strength)
-{
- struct connman_device *device = modem->device;
- GHashTableIter i;
- gpointer value;
-
- modem->strength = strength;
- modem->has_strength = TRUE;
-
- if (device == NULL)
- return;
-
- for (g_hash_table_iter_init(&i, network_hash);
- g_hash_table_iter_next(&i, NULL, &value);) {
- struct network_info *info = value;
-
- if (connman_network_get_device(info->network) == device) {
- connman_network_set_strength(info->network, strength);
- connman_network_update(info->network);
- }
- }
-}
-
-static void modem_roaming_changed(struct modem_data *modem,
- char const *status)
-{
- struct connman_device *device = modem->device;
- connman_bool_t roaming = FALSE;
- connman_bool_t registered = FALSE;
- connman_bool_t was_roaming = modem->roaming;
- GHashTableIter i;
- gpointer value;
-
- if (g_str_equal(status, "roaming"))
- roaming = TRUE;
- else if (g_str_equal(status, "registered"))
- registered = TRUE;
-
- registered = registered || roaming;
-
- if (modem->roaming == roaming && modem->registered == registered)
- return;
-
- modem->registered = registered;
- modem->roaming = roaming;
-
- if (roaming == was_roaming)
- return;
-
- if (device == NULL)
- return;
-
- g_hash_table_iter_init(&i, network_hash);
-
- while (g_hash_table_iter_next(&i, NULL, &value)) {
- struct network_info *info = value;
-
- if (connman_network_get_device(info->network) == device) {
- connman_network_set_roaming(info->network, roaming);
- connman_network_update(info->network);
- }
- }
-}
-
-static void modem_registration_removed(struct modem_data *modem)
-{
- modem->registered = FALSE;
- modem->roaming = FALSE;
-}
-
-static void modem_registration_changed(struct modem_data *modem,
- DBusMessageIter *entry)
-{
- DBusMessageIter iter;
- const char *key;
- int type;
- connman_uint8_t strength;
- char const *name, *status, *mcc_s;
-
- dbus_message_iter_get_basic(entry, &key);
-
- DBG("key %s", key);
-
- dbus_message_iter_next(entry);
-
- dbus_message_iter_recurse(entry, &iter);
-
- type = dbus_message_iter_get_arg_type(&iter);
- if (type != DBUS_TYPE_BYTE && type != DBUS_TYPE_STRING)
- return;
-
- if (g_str_equal(key, "Name") && type == DBUS_TYPE_STRING) {
- dbus_message_iter_get_basic(&iter, &name);
- modem_operator_name_changed(modem, name);
- } else if (g_str_equal(key, "Strength") && type == DBUS_TYPE_BYTE) {
- dbus_message_iter_get_basic(&iter, &strength);
- modem_strength_changed(modem, strength);
- } else if (g_str_equal(key, "Status") && type == DBUS_TYPE_STRING) {
- dbus_message_iter_get_basic(&iter, &status);
- modem_roaming_changed(modem, status);
- } else if (g_str_equal(key, "MobileCountryCode") &&
- type == DBUS_TYPE_STRING) {
- int mcc;
- char *alpha2;
-
- dbus_message_iter_get_basic(&iter, &mcc_s);
-
- mcc = atoi(mcc_s);
- if (mcc > 799)
- return;
-
- alpha2 = mcc_country_codes[mcc - 200];
- connman_technology_set_regdom(alpha2);
- }
-
-}
-
-static gboolean reg_changed(DBusConnection *connection,
- DBusMessage *message, void *user_data)
-{
- const char *path = dbus_message_get_path(message);
- struct modem_data *modem;
- DBusMessageIter iter;
-
- DBG("path %s", path);
-
- modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
- return TRUE;
-
- if (dbus_message_iter_init(message, &iter))
- modem_registration_changed(modem, &iter);
-
- return TRUE;
-}
-
-static void check_registration_reply(DBusPendingCall *call, void *user_data)
-{
- char const *path = user_data;
- struct modem_data *modem;
- DBusMessage *reply;
- DBusMessageIter array, dict, entry;
-
- DBG("path %s", path);
-
- modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
- return;
-
- reply = dbus_pending_call_steal_reply(call);
-
- if (dbus_message_iter_init(reply, &array) == FALSE)
- goto done;
-
- if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
- goto done;
-
- dbus_message_iter_recurse(&array, &dict);
- while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
- dbus_message_iter_recurse(&dict, &entry);
- modem_registration_changed(modem, &entry);
- dbus_message_iter_next(&dict);
- }
-
-done:
- dbus_message_unref(reply);
-
- dbus_pending_call_unref(call);
-}
-
-static void check_registration(struct modem_data *modem)
-{
- char const *path = modem->path;
-
- DBG("modem %p path %s", modem, path);
-
- call_ofono(path, OFONO_REGISTRATION_INTERFACE, GET_PROPERTIES,
- check_registration_reply, g_strdup(path), g_free,
- DBUS_TYPE_INVALID);
-}
-
-static void modem_gprs_changed(struct modem_data *modem,
- DBusMessageIter *entry)
-{
- DBusMessageIter iter;
- const char *key;
- int type;
- dbus_bool_t value;
-
- dbus_message_iter_get_basic(entry, &key);
-
- DBG("key %s", key);
-
- dbus_message_iter_next(entry);
-
- dbus_message_iter_recurse(entry, &iter);
-
- type = dbus_message_iter_get_arg_type(&iter);
-
- if (type != DBUS_TYPE_BOOLEAN)
- return;
-
- dbus_message_iter_get_basic(&iter, &value);
-
- if (g_str_equal(key, "Attached") == TRUE) {
- DBG("Attached %d", value);
-
- modem->attached = value;
-
- if (value)
- modem_clear_network_errors(modem);
- } else if (g_str_equal(key, "Powered") == TRUE) {
- DBG("Powered %d", value);
-
- modem->powered = value;
- } else if (g_str_equal(key, "RoamingAllowed") == TRUE) {
- DBG("RoamingAllowed %d", value);
-
- modem->roaming_allowed = value;
- }
-}
-
-static void check_gprs_reply(DBusPendingCall *call, void *user_data)
-{
- char const *path = user_data;
- struct modem_data *modem;
- DBusMessage *reply;
- DBusMessageIter array, dict, entry;
-
- DBG("path %s", path);
-
- modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
- return;
-
- reply = dbus_pending_call_steal_reply(call);
-
- if (dbus_message_iter_init(reply, &array) == FALSE)
- goto done;
-
- if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
- goto done;
-
- dbus_message_iter_recurse(&array, &dict);
- while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
- dbus_message_iter_recurse(&dict, &entry);
- modem_gprs_changed(modem, &entry);
- dbus_message_iter_next(&dict);
- }
-
-done:
- dbus_message_unref(reply);
-
- dbus_pending_call_unref(call);
-
- check_networks(modem);
-}
-
-static void check_gprs(struct modem_data *modem)
-{
- char const *path = modem->path;
-
- DBG("modem %p path %s", modem, path);
-
- call_ofono(path, OFONO_GPRS_INTERFACE, GET_PROPERTIES,
- check_gprs_reply, g_strdup(path), g_free,
- DBUS_TYPE_INVALID);
-}
-
-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);
-
- if (path == NULL)
- return;
-
- if (imsi == NULL)
- return;
-
- modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
- return;
-
- if (modem->device) {
- if (!g_strcmp0(imsi, connman_device_get_ident(modem->device)))
- return;
-
- modem_remove_device(modem);
- }
-
- if (strlen(imsi) == 0)
- return;
-
- device = connman_device_create(imsi, CONNMAN_DEVICE_TYPE_CELLULAR);
- if (device == NULL)
- return;
-
- connman_device_set_ident(device, imsi);
-
- connman_device_set_string(device, "Path", path);
-
- connman_device_set_data(device, modem);
-
- if (connman_device_register(device) < 0) {
- connman_device_unref(device);
- return;
- }
-
- modem->device = device;
-
- if (modem->has_reg)
- check_registration(modem);
-
- if (modem->has_gprs)
- check_gprs(modem);
-}
-
-static void sim_properties_reply(DBusPendingCall *call, void *user_data)
-{
- const char *path = user_data;
- const char *imsi = NULL;
- DBusMessage *reply;
- DBusMessageIter array, dict;
-
- DBG("path %s", path);
-
- reply = dbus_pending_call_steal_reply(call);
-
- if (dbus_message_iter_init(reply, &array) == FALSE)
- goto done;
-
- if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
- goto done;
-
- dbus_message_iter_recurse(&array, &dict);
-
- while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+ while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
DBusMessageIter entry, value;
const char *key;
- dbus_message_iter_recurse(&dict, &entry);
+ dbus_message_iter_recurse(dict, &entry);
dbus_message_iter_get_basic(&entry, &key);
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "SubscriberIdentity")) {
- dbus_message_iter_get_basic(&value, &imsi);
- add_device(path, imsi);
- }
-
- dbus_message_iter_next(&dict);
- }
-
-done:
- dbus_message_unref(reply);
-
- dbus_pending_call_unref(call);
-}
-
-static void get_imsi(const char *path)
-{
- DBG("path %s", path);
-
- call_ofono(path, OFONO_SIM_INTERFACE, GET_PROPERTIES,
- sim_properties_reply, g_strdup(path), g_free,
- DBUS_TYPE_INVALID);
-}
-
-static int gprs_change_powered(const char *path, dbus_bool_t powered)
-{
- DBG("path %s powered %d", path, powered);
-
- return set_property(path, OFONO_GPRS_INTERFACE, "Powered",
- DBUS_TYPE_BOOLEAN, &powered,
- NULL, NULL, NULL);
-}
-
-static int modem_change_powered(const char *path, dbus_bool_t powered)
-{
- DBG("path %s powered %d", path, powered);
-
- return set_property(path, OFONO_MODEM_INTERFACE, "Powered",
- DBUS_TYPE_BOOLEAN, &powered,
- NULL, NULL, NULL);
-}
-
-
-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 *element;
-
- dbus_message_iter_get_basic(&entry, &element);
-
- if (g_strcmp0(interface, element) == 0)
- return TRUE;
-
- dbus_message_iter_next(&entry);
- }
-
- return FALSE;
-}
-
-static gboolean modem_has_sim(DBusMessageIter *array)
-{
- return modem_has_interface(array, OFONO_SIM_INTERFACE);
-}
-
-static gboolean modem_has_reg(DBusMessageIter *array)
-{
- return modem_has_interface(array, OFONO_REGISTRATION_INTERFACE);
-}
-
-static gboolean modem_has_gprs(DBusMessageIter *array)
-{
- return modem_has_interface(array, OFONO_GPRS_INTERFACE);
-}
-
-static void add_modem(const char *path, DBusMessageIter *prop)
-{
- struct modem_data *modem;
- dbus_bool_t powered = FALSE;
- dbus_bool_t online = FALSE;
- dbus_bool_t locked = FALSE;
- gboolean has_sim = FALSE;
- gboolean has_reg = FALSE;
- gboolean has_gprs = FALSE;
-
- modem = g_hash_table_lookup(modem_hash, path);
-
- if (modem != NULL)
- return;
-
- modem = g_try_new0(struct modem_data, 1);
- if (modem == NULL)
- return;
-
- modem->path = g_strdup(path);
- modem->device = NULL;
- modem->available = TRUE;
-
- g_hash_table_insert(modem_hash, g_strdup(path), modem);
+ if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
+ char *imsi;
- while (dbus_message_iter_get_arg_type(prop) == DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter entry, value;
- const char *key;
+ dbus_message_iter_get_basic(&value, &imsi);
- dbus_message_iter_recurse(prop, &entry);
- dbus_message_iter_get_basic(&entry, &key);
+ update_sim_imsi(modem, imsi);
- dbus_message_iter_next(&entry);
- dbus_message_iter_recurse(&entry, &value);
+ if (modem->online == FALSE) {
+ modem_set_online(modem);
+ break;
+ }
- if (g_str_equal(key, "Powered") == TRUE)
- dbus_message_iter_get_basic(&value, &powered);
- else if (g_str_equal(key, "Lockdown") == TRUE)
- dbus_message_iter_get_basic(&value, &locked);
- else if (g_str_equal(key, "Interfaces") == TRUE) {
- has_sim = modem_has_sim(&value);
- has_reg = modem_has_reg(&value);
- has_gprs = modem_has_gprs(&value);
+ if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
+ if (ready_to_create_device(modem) == TRUE)
+ create_device(modem);
+ if (modem->device != NULL)
+ cm_get_properties(modem);
+ }
+ return;
}
- dbus_message_iter_next(prop);
- }
-
- if (locked)
- return;
-
- if (!powered)
- modem_change_powered(path, TRUE);
-
- modem->has_sim = has_sim;
- modem->has_reg = has_reg;
- modem->has_gprs = has_gprs;
-
- update_modem_online(modem, online);
-
- if (has_sim)
- get_imsi(path);
-}
-
-static void manager_modems_reply(DBusPendingCall *call, void *user_data)
-{
- DBusMessage *reply;
- DBusError error;
- DBusMessageIter array, dict;
-
- DBG("");
-
- reply = dbus_pending_call_steal_reply(call);
-
- if (dbus_message_has_signature(reply, "a(oa{sv})") == FALSE)
- goto done;
-
- dbus_error_init(&error);
-
- if (dbus_set_error_from_message(&error, reply)) {
- connman_error("ModemManager.GetModems() %s %s",
- error.name, error.message);
- dbus_error_free(&error);
- goto done;
- }
-
- if (dbus_message_iter_init(reply, &array) == FALSE)
- goto done;
-
- dbus_message_iter_recurse(&array, &dict);
-
- while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
- DBusMessageIter value, properties;
- const char *modem_path;
-
- dbus_message_iter_recurse(&dict, &value);
- dbus_message_iter_get_basic(&value, &modem_path);
-
- dbus_message_iter_next(&value);
- dbus_message_iter_recurse(&value, &properties);
-
- /* Add modem */
- add_modem(modem_path, &properties);
-
- dbus_message_iter_next(&dict);
+ dbus_message_iter_next(dict);
}
-
-done:
- dbus_message_unref(reply);
-
- dbus_pending_call_unref(call);
-}
-
-static void ofono_connect(DBusConnection *connection, void *user_data)
-{
- DBG("connection %p", connection);
-
- modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
- g_free, remove_modem);
-
- network_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
- g_free, remove_network);
-
- call_ofono("/", OFONO_MANAGER_INTERFACE, GET_MODEMS,
- manager_modems_reply, NULL, NULL,
- DBUS_TYPE_INVALID);
}
-static void ofono_disconnect(DBusConnection *connection, void *user_data)
+static int sim_get_properties(struct modem_data *modem)
{
- DBG("connection %p", connection);
-
- if (modem_hash != NULL) {
- g_hash_table_destroy(modem_hash);
- modem_hash = NULL;
- }
-
- if (network_hash != NULL) {
- g_hash_table_destroy(network_hash);
- network_hash = NULL;
- }
+ return get_properties(modem->path, OFONO_SIM_INTERFACE,
+ sim_properties_reply, modem);
}
static gboolean modem_changed(DBusConnection *connection, DBusMessage *message,
DBusMessageIter iter, value;
const char *key;
- DBG("path %s", path);
-
modem = g_hash_table_lookup(modem_hash, path);
if (modem == NULL)
return TRUE;
dbus_message_iter_recurse(&iter, &value);
if (g_str_equal(key, "Powered") == TRUE) {
- dbus_bool_t powered;
-
- dbus_message_iter_get_basic(&value, &powered);
- if (powered == TRUE)
- return TRUE;
+ dbus_message_iter_get_basic(&value, &modem->powered);
- modem->has_sim = FALSE;
- modem->has_reg = FALSE;
- modem->has_gprs = FALSE;
+ DBG("%s Powered %d", modem->path, modem->powered);
- modem_remove_device(modem);
+ if (modem->powered == FALSE)
+ modem_set_powered(modem);
} else if (g_str_equal(key, "Online") == TRUE) {
- dbus_bool_t online;
-
- dbus_message_iter_get_basic(&value, &online);
+ dbus_message_iter_get_basic(&value, &modem->online);
- update_modem_online(modem, online);
- } else if (g_str_equal(key, "Lockdown") == TRUE) {
- dbus_bool_t locked;
+ DBG("%s Online %d", modem->path, modem->online);
- dbus_message_iter_get_basic(&value, &locked);
-
- if (!locked)
- modem_change_powered(path, TRUE);
+ if (modem->online == FALSE)
+ return TRUE;
+ if (has_interface(modem->interfaces, OFONO_API_CM) == FALSE)
+ return TRUE;
+ if (ready_to_create_device(modem) == TRUE)
+ create_device(modem);
+ if (modem->device != NULL)
+ cm_get_properties(modem);
} else if (g_str_equal(key, "Interfaces") == TRUE) {
- gboolean has_sim = modem_has_sim(&value);
- gboolean has_reg = modem_has_reg(&value);
- gboolean had_reg = modem->has_reg;
- gboolean has_gprs = modem_has_gprs(&value);
- gboolean had_gprs = modem->has_gprs;
-
- modem->has_sim = has_sim;
- modem->has_reg = has_reg;
- modem->has_gprs = has_gprs;
-
- if (modem->device == NULL) {
- if (has_sim)
- get_imsi(modem->path);
- } else if (!has_sim) {
- modem_remove_device(modem);
- } else {
- if (has_reg && !had_reg)
- check_registration(modem);
- else if (had_reg && !has_reg)
- modem_registration_removed(modem);
-
- if (has_gprs && !had_gprs) {
- gprs_change_powered(modem->path, TRUE);
- check_gprs(modem);
+ modem->interfaces = extract_interfaces(&value);
+
+ DBG("%s Interfaces 0x%02x", modem->path,
+ modem->interfaces);
+
+ if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
+ if (modem->imsi == NULL &&
+ modem->set_powered == FALSE) {
+ /*
+ * Only use do GetProperties() when
+ * device has not been powered up.
+ */
+ sim_get_properties(modem);
+ return TRUE;
}
}
+
+ if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
+ if (ready_to_create_device(modem) == TRUE)
+ create_device(modem);
+ if (modem->device != NULL)
+ cm_get_properties(modem);
+ } else {
+ if (modem->device != NULL)
+ destroy_device(modem);
+ }
+ } else if (g_str_equal(key, "Serial") == TRUE) {
+ char *serial;
+
+ dbus_message_iter_get_basic(&value, &serial);
+
+ g_free(modem->serial);
+ modem->serial = g_strdup(serial);
+
+ DBG("%s Serial %s", modem->path, modem->serial);
+
+ if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
+ if (ready_to_create_device(modem) == TRUE)
+ create_device(modem);
+ if (modem->device != NULL)
+ cm_get_properties(modem);
+ }
}
return TRUE;
}
-static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
- void *user_data)
+static void add_modem(const char *path, DBusMessageIter *prop)
{
- const char *path = dbus_message_get_path(message);
struct modem_data *modem;
- DBusMessageIter iter, value;
- const char *key;
- DBG("path %s", path);
+ DBG("%s", path);
modem = g_hash_table_lookup(modem_hash, path);
+ if (modem != NULL) {
+ /*
+ * When oFono powers up we ask for the modems and oFono is
+ * reporting with modem_added signal the modems. Only
+ * handle them once.
+ */
+ return;
+ }
+
+ modem = g_try_new0(struct modem_data, 1);
if (modem == NULL)
- return TRUE;
+ return;
- if (dbus_message_iter_init(message, &iter) == FALSE)
- return TRUE;
+ modem->path = g_strdup(path);
- dbus_message_iter_get_basic(&iter, &key);
+ g_hash_table_insert(modem_hash, g_strdup(path), modem);
- dbus_message_iter_next(&iter);
- dbus_message_iter_recurse(&iter, &value);
+ while (dbus_message_iter_get_arg_type(prop) == DBUS_TYPE_DICT_ENTRY) {
+ DBusMessageIter entry, value;
+ const char *key;
- if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
- char *imsi;
+ dbus_message_iter_recurse(prop, &entry);
+ dbus_message_iter_get_basic(&entry, &key);
- dbus_message_iter_get_basic(&value, &imsi);
+ dbus_message_iter_next(&entry);
+ dbus_message_iter_recurse(&entry, &value);
- add_device(path, imsi);
- } else if (g_str_equal(key, "Present") == TRUE) {
- dbus_bool_t present;
+ if (g_str_equal(key, "Powered") == TRUE) {
+ dbus_message_iter_get_basic(&value, &modem->powered);
- dbus_message_iter_get_basic(&value, &present);
+ DBG("%s Powered %d", modem->path, modem->powered);
+ } else if (g_str_equal(key, "Online") == TRUE) {
+ dbus_message_iter_get_basic(&value, &modem->online);
- if (present)
- return TRUE;
+ DBG("%s Online %d", modem->path, modem->online);
+ } else if (g_str_equal(key, "Interfaces") == TRUE) {
+ modem->interfaces = extract_interfaces(&value);
- if (modem->device != NULL)
- modem_remove_device(modem);
+ DBG("%s Interfaces 0x%02x", modem->path,
+ modem->interfaces);
+ } else if (g_str_equal(key, "Serial") == TRUE) {
+ char *serial;
- modem->has_gprs = FALSE;
- modem->has_reg = FALSE;
+ dbus_message_iter_get_basic(&value, &serial);
+ modem->serial = g_strdup(serial);
+
+ DBG("%s Serial %s", modem->path, modem->serial);
+ }
+
+ dbus_message_iter_next(prop);
}
- return TRUE;
+ if (modem->powered == FALSE) {
+ modem_set_powered(modem);
+ } else if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
+ sim_get_properties(modem);
+ } else if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
+ if (ready_to_create_device(modem) == TRUE)
+ create_device(modem);
+ if (modem->device != NULL)
+ cm_get_properties(modem);
+ }
}
-static gboolean gprs_changed(DBusConnection *connection, DBusMessage *message,
- void *user_data)
-{
- const char *path = dbus_message_get_path(message);
- struct modem_data *modem;
- DBusMessageIter iter;
+static void remove_modem(gpointer data)
+{
+ struct modem_data *modem = data;
+
+ DBG("%s", modem->path);
+
+ if (modem->call_set_property != NULL)
+ dbus_pending_call_cancel(modem->call_set_property);
- DBG("path %s", path);
+ if (modem->call_get_properties != NULL)
+ dbus_pending_call_cancel(modem->call_get_properties);
- modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
- return TRUE;
+ if (modem->device != NULL)
+ destroy_device(modem);
- if (dbus_message_iter_init(message, &iter))
- modem_gprs_changed(modem, &iter);
+ g_free(modem->serial);
+ g_free(modem->imsi);
+ g_free(modem->path);
- return TRUE;
+ g_free(modem);
}
-static gboolean context_added(DBusConnection *connection,
+static gboolean modem_added(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
- const char *path = dbus_message_get_path(message);
- const char *network_path;
- struct modem_data *modem;
DBusMessageIter iter, properties;
+ const char *path;
- DBG("path %s", path);
-
- modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL || modem->device == NULL)
- return TRUE;
+ DBG("");
if (dbus_message_iter_init(message, &iter) == FALSE)
return TRUE;
- dbus_message_iter_get_basic(&iter, &network_path);
+ dbus_message_iter_get_basic(&iter, &path);
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &properties);
- add_network(modem->device, network_path, &properties);
+ add_modem(path, &properties);
return TRUE;
}
-static gboolean context_removed(DBusConnection *connection,
+static gboolean modem_removed(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
- const char *path = dbus_message_get_path(message);
- const char *network_path;
- struct modem_data *modem;
DBusMessageIter iter;
+ const char *path;
- DBG("path %s", path);
-
- modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL || modem->device == NULL)
- return TRUE;
+ DBG("");
if (dbus_message_iter_init(message, &iter) == FALSE)
return TRUE;
- dbus_message_iter_get_basic(&iter, &network_path);
+ dbus_message_iter_get_basic(&iter, &path);
+
+ g_hash_table_remove(modem_hash, path);
- g_hash_table_remove(network_hash, network_path);
return TRUE;
}
-static gboolean modem_added(DBusConnection *connection,
- DBusMessage *message, void *user_data)
+static void manager_get_modems_reply(DBusPendingCall *call, void *user_data)
{
- DBusMessageIter iter, properties;
- const char *modem_path;
+ DBusMessage *reply;
+ DBusError error;
+ DBusMessageIter array, dict;
DBG("");
- if (dbus_message_iter_init(message, &iter) == FALSE)
- return TRUE;
+ reply = dbus_pending_call_steal_reply(call);
- dbus_message_iter_get_basic(&iter, &modem_path);
+ dbus_error_init(&error);
- dbus_message_iter_next(&iter);
- dbus_message_iter_recurse(&iter, &properties);
+ if (dbus_set_error_from_message(&error, reply) == TRUE) {
+ connman_error("%s", error.message);
+ dbus_error_free(&error);
+ goto done;
+ }
+
+ if (dbus_message_iter_init(reply, &array) == FALSE)
+ goto done;
- add_modem(modem_path, &properties);
+ dbus_message_iter_recurse(&array, &dict);
- return TRUE;
+ while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
+ DBusMessageIter value, properties;
+ const char *path;
+
+ dbus_message_iter_recurse(&dict, &value);
+ dbus_message_iter_get_basic(&value, &path);
+
+ dbus_message_iter_next(&value);
+ dbus_message_iter_recurse(&value, &properties);
+
+ add_modem(path, &properties);
+
+ dbus_message_iter_next(&dict);
+ }
+
+done:
+ dbus_message_unref(reply);
+
+ dbus_pending_call_unref(call);
}
-static gboolean modem_removed(DBusConnection *connection,
- DBusMessage *message, void *user_data)
+static int manager_get_modems(void)
{
- DBusMessageIter iter;
- const char *modem_path;
+ DBusMessage *message;
+ DBusPendingCall *call;
DBG("");
- if (dbus_message_iter_init(message, &iter) == FALSE)
- return TRUE;
+ message = dbus_message_new_method_call(OFONO_SERVICE, "/",
+ OFONO_MANAGER_INTERFACE, GET_MODEMS);
+ if (message == NULL)
+ return -ENOMEM;
+
+ if (dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT) == FALSE) {
+ connman_error("Failed to call GetModems()");
+ dbus_message_unref(message);
+ return -EINVAL;
+ }
+
+ if (call == NULL) {
+ connman_error("D-Bus connection not available");
+ dbus_message_unref(message);
+ return -EINVAL;
+ }
- dbus_message_iter_get_basic(&iter, &modem_path);
+ dbus_pending_call_set_notify(call, manager_get_modems_reply,
+ NULL, NULL);
- g_hash_table_remove(modem_hash, modem_path);
+ dbus_message_unref(message);
- return TRUE;
+ return -EINPROGRESS;
}
-static gboolean context_changed(DBusConnection *connection,
- DBusMessage *message, void *user_data)
+static void ofono_connect(DBusConnection *conn, void *user_data)
{
- const char *path = dbus_message_get_path(message);
- struct network_info *info;
- DBusMessageIter iter, value;
- const char *key;
+ DBG("");
- DBG("path %s", path);
+ modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, remove_modem);
+ if (modem_hash == NULL)
+ return;
- info = g_hash_table_lookup(network_hash, path);
- if (info == NULL)
- return TRUE;
+ manager_get_modems();
+}
- if (!pending_network_is_available(info->network)) {
- g_hash_table_remove(network_hash, path);
- return TRUE;
- }
+static void ofono_disconnect(DBusConnection *conn, void *user_data)
+{
+ DBG("");
- if (dbus_message_iter_init(message, &iter) == FALSE)
- return TRUE;
+ if (modem_hash == NULL)
+ return;
- dbus_message_iter_get_basic(&iter, &key);
+ g_hash_table_destroy(modem_hash);
+ modem_hash = NULL;
+}
- dbus_message_iter_next(&iter);
- dbus_message_iter_recurse(&iter, &value);
+static int network_probe(struct connman_network *network)
+{
+ DBG("network %p", network);
- DBG("key %s", key);
+ return 0;
+}
- if (g_str_equal(key, "Settings") == TRUE)
- update_ipv4_settings(&value, info);
- else if (g_str_equal(key, "IPv6.Settings"))
- update_ipv6_settings(&value, info);
- else if (g_str_equal(key, "Active") == TRUE) {
- dbus_bool_t active;
+static void network_remove(struct connman_network *network)
+{
+ DBG("network %p", network);
+}
- dbus_message_iter_get_basic(&value, &active);
+static int network_connect(struct connman_network *network)
+{
+ DBG("network %p", network);
- if (active == FALSE)
- set_connected(info, active);
+ return 0;
+}
- /* Connect only if requested to do so */
- if (active == TRUE &&
- connman_network_get_connecting(info->network) == TRUE)
- set_connected(info, active);
- }
+static int network_disconnect(struct connman_network *network)
+{
+ DBG("network %p", network);
- return TRUE;
+ return 0;
+}
+
+static struct connman_network_driver network_driver = {
+ .name = "network",
+ .type = CONNMAN_NETWORK_TYPE_CELLULAR,
+ .probe = network_probe,
+ .remove = network_remove,
+ .connect = network_connect,
+ .disconnect = network_disconnect,
+};
+
+static int modem_probe(struct connman_device *device)
+{
+ struct modem_data *modem = connman_device_get_data(device);
+
+ DBG("%s device %p", modem->path, device);
+
+ return 0;
+}
+
+static void modem_remove(struct connman_device *device)
+{
+ struct modem_data *modem = connman_device_get_data(device);
+
+ DBG("%s device %p", modem->path, device);
+}
+
+static int modem_enable(struct connman_device *device)
+{
+ struct modem_data *modem = connman_device_get_data(device);
+
+ DBG("%s device %p", modem->path, device);
+
+ return 0;
+}
+
+static int modem_disable(struct connman_device *device)
+{
+ struct modem_data *modem = connman_device_get_data(device);
+
+ DBG("%s device %p", modem->path, device);
+
+ return 0;
}
+static struct connman_device_driver modem_driver = {
+ .name = "modem",
+ .type = CONNMAN_DEVICE_TYPE_CELLULAR,
+ .probe = modem_probe,
+ .remove = modem_remove,
+ .enable = modem_enable,
+ .disable = modem_disable,
+};
+
static guint watch;
-static guint reg_watch;
+static guint modem_added_watch;
+static guint modem_removed_watch;
+static guint modem_watch;
+static guint cm_watch;
static guint sim_watch;
-static guint gprs_watch;
static guint context_added_watch;
static guint context_removed_watch;
-static guint modem_watch;
-static guint modem_added_watch;
-static guint modem_removed_watch;
+static guint netreg_watch;
static guint context_watch;
static int ofono_init(void)
{
int err;
+ DBG("");
+
connection = connman_dbus_get_connection();
if (connection == NULL)
return -EIO;
- watch = g_dbus_add_service_watch(connection, OFONO_SERVICE,
- ofono_connect, ofono_disconnect, NULL, NULL);
-
- reg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
- OFONO_REGISTRATION_INTERFACE,
- PROPERTY_CHANGED,
- reg_changed,
- NULL, NULL);
-
- gprs_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
- OFONO_GPRS_INTERFACE,
- PROPERTY_CHANGED,
- gprs_changed,
- NULL, NULL);
+ watch = g_dbus_add_service_watch(connection,
+ OFONO_SERVICE, ofono_connect,
+ ofono_disconnect, NULL, NULL);
- context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
- OFONO_GPRS_INTERFACE,
- CONTEXT_ADDED,
- context_added,
+ modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ OFONO_MANAGER_INTERFACE,
+ MODEM_ADDED,
+ modem_added,
NULL, NULL);
- context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
- OFONO_GPRS_INTERFACE,
- CONTEXT_REMOVED,
- context_removed,
+ modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ OFONO_MANAGER_INTERFACE,
+ MODEM_REMOVED,
+ modem_removed,
NULL, NULL);
modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
modem_changed,
NULL, NULL);
+ cm_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ OFONO_CM_INTERFACE,
+ PROPERTY_CHANGED,
+ cm_changed,
+ NULL, NULL);
+
sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
OFONO_SIM_INTERFACE,
PROPERTY_CHANGED,
sim_changed,
NULL, NULL);
- modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
- OFONO_MANAGER_INTERFACE,
- MODEM_ADDED,
- modem_added,
+ context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ OFONO_CM_INTERFACE,
+ CONTEXT_ADDED,
+ cm_context_added,
NULL, NULL);
- modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
- OFONO_MANAGER_INTERFACE,
- MODEM_REMOVED,
- modem_removed,
+ context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ OFONO_CM_INTERFACE,
+ CONTEXT_REMOVED,
+ cm_context_removed,
NULL, NULL);
context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
context_changed,
NULL, NULL);
- if (watch == 0 || gprs_watch == 0 || context_added_watch == 0 ||
- context_removed_watch == 0 || modem_watch == 0 ||
- reg_watch == 0 || sim_watch == 0 ||
- modem_added_watch == 0 || modem_removed_watch == 0 ||
- context_watch == 0) {
+ netreg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ OFONO_NETREG_INTERFACE,
+ PROPERTY_CHANGED,
+ netreg_changed,
+ NULL, NULL);
+
+
+ if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
+ modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
+ context_added_watch == 0 ||
+ context_removed_watch == 0 ||
+ context_watch == 0 || netreg_watch == 0) {
err = -EIO;
goto remove;
}
return 0;
remove:
- g_dbus_remove_watch(connection, watch);
- g_dbus_remove_watch(connection, sim_watch);
- g_dbus_remove_watch(connection, reg_watch);
- g_dbus_remove_watch(connection, gprs_watch);
- g_dbus_remove_watch(connection, context_added_watch);
+ g_dbus_remove_watch(connection, netreg_watch);
+ g_dbus_remove_watch(connection, context_watch);
g_dbus_remove_watch(connection, context_removed_watch);
+ g_dbus_remove_watch(connection, context_added_watch);
+ g_dbus_remove_watch(connection, sim_watch);
+ g_dbus_remove_watch(connection, cm_watch);
g_dbus_remove_watch(connection, modem_watch);
- g_dbus_remove_watch(connection, modem_added_watch);
g_dbus_remove_watch(connection, modem_removed_watch);
- g_dbus_remove_watch(connection, context_watch);
-
+ g_dbus_remove_watch(connection, modem_added_watch);
+ g_dbus_remove_watch(connection, watch);
dbus_connection_unref(connection);
return err;
static void ofono_exit(void)
{
- g_dbus_remove_watch(connection, watch);
- g_dbus_remove_watch(connection, sim_watch);
- g_dbus_remove_watch(connection, reg_watch);
- g_dbus_remove_watch(connection, gprs_watch);
- g_dbus_remove_watch(connection, context_added_watch);
- g_dbus_remove_watch(connection, context_removed_watch);
- g_dbus_remove_watch(connection, modem_watch);
- g_dbus_remove_watch(connection, modem_added_watch);
- g_dbus_remove_watch(connection, modem_removed_watch);
- g_dbus_remove_watch(connection, context_watch);
+ DBG("");
- ofono_disconnect(connection, NULL);
+ if (modem_hash != NULL) {
+ g_hash_table_destroy(modem_hash);
+ modem_hash = NULL;
+ }
connman_device_driver_unregister(&modem_driver);
connman_network_driver_unregister(&network_driver);
+ g_dbus_remove_watch(connection, netreg_watch);
+ g_dbus_remove_watch(connection, context_watch);
+ g_dbus_remove_watch(connection, context_removed_watch);
+ g_dbus_remove_watch(connection, context_added_watch);
+ g_dbus_remove_watch(connection, sim_watch);
+ g_dbus_remove_watch(connection, cm_watch);
+ g_dbus_remove_watch(connection, modem_watch);
+ g_dbus_remove_watch(connection, modem_added_watch);
+ g_dbus_remove_watch(connection, modem_removed_watch);
+ g_dbus_remove_watch(connection, watch);
+
dbus_connection_unref(connection);
}