summaryrefslogtreecommitdiff
path: root/plugins/ofono.c
diff options
context:
space:
mode:
authorMartin Xu <martin.xu@intel.com>2010-01-22 13:30:46 +0800
committerMarcel Holtmann <marcel@holtmann.org>2010-01-23 10:45:19 +0100
commit02dc82ffa4bf38a0bf33b33f4832bd50d13d6124 (patch)
treed70f5696b8c70eb4cf08dde42faef5b4e1b1dd0e /plugins/ofono.c
parent5fe8b42f0d0405cb34d11bf4cf74392fa7224e3a (diff)
downloadconnman-02dc82ffa4bf38a0bf33b33f4832bd50d13d6124.tar.gz
connman-02dc82ffa4bf38a0bf33b33f4832bd50d13d6124.tar.bz2
connman-02dc82ffa4bf38a0bf33b33f4832bd50d13d6124.zip
Add default context if no context exists
Diffstat (limited to 'plugins/ofono.c')
-rw-r--r--plugins/ofono.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/plugins/ofono.c b/plugins/ofono.c
index 65ca5ddf..a35ae3fd 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -48,9 +48,13 @@
#define PROPERTY_CHANGED "PropertyChanged"
#define GET_PROPERTIES "GetProperties"
#define SET_PROPERTY "SetProperty"
+#define CREATE_CONTEXT "CreateContext"
#define TIMEOUT 5000
+#define CONTEXT_NAME "3G Connection"
+#define CONTEXT_TYPE "internet"
+
static DBusConnection *connection;
static GHashTable *modem_hash = NULL;
@@ -489,6 +493,75 @@ static void add_networks(struct connman_device *device, DBusMessageIter *array)
}
}
+static void create_context_reply(DBusPendingCall *call, void *user_data)
+{
+ DBusMessage *reply;
+ DBusError error;
+
+ DBG("");
+
+ dbus_error_init(&error);
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ if (dbus_set_error_from_message(&error, reply)) {
+ connman_error("%s", error.message);
+ dbus_error_free(&error);
+ }
+
+ dbus_message_unref(reply);
+
+ dbus_pending_call_unref(call);
+}
+
+static void add_default_context(DBusMessageIter *array,
+ const char *path, const char *name, const char *type)
+{
+ DBusMessageIter entry;
+ DBusMessage *message;
+ DBusPendingCall *call;
+
+ if (path == NULL)
+ return;
+
+ DBG("");
+
+ dbus_message_iter_recurse(array, &entry);
+
+ if (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_OBJECT_PATH)
+ return;
+
+ DBG("path %s, name %s, type %s", path, name, type);
+
+ message = dbus_message_new_method_call(OFONO_SERVICE, path,
+ OFONO_GPRS_INTERFACE, CREATE_CONTEXT);
+ if (message == NULL)
+ return;
+
+ dbus_message_set_auto_start(message, FALSE);
+
+ dbus_message_append_args(message, DBUS_TYPE_STRING,
+ &name, DBUS_TYPE_STRING,
+ &type, DBUS_TYPE_INVALID);
+
+ if (dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT) == FALSE) {
+ connman_error("Failed to create default context");
+ dbus_message_unref(message);
+ return;
+ }
+
+ if (call == NULL) {
+ connman_error("D-Bus connection not available");
+ dbus_message_unref(message);
+ return;
+ }
+
+ dbus_pending_call_set_notify(call, create_context_reply, NULL, NULL);
+
+ dbus_message_unref(message);
+}
+
static void check_networks_reply(DBusPendingCall *call, void *user_data)
{
struct connman_device *device = user_data;
@@ -524,7 +597,12 @@ static void check_networks_reply(DBusPendingCall *call, void *user_data)
dbus_message_iter_get_basic(&value, &attached);
DBG("Attached %d", attached);
} else if (g_str_equal(key, "PrimaryContexts") == TRUE) {
+ const char *path;
+
+ path = connman_device_get_string(device, "Path");
contexts = value;
+ add_default_context(&contexts, path,
+ CONTEXT_NAME, CONTEXT_TYPE);
} else if (g_str_equal(key, "Status") == TRUE) {
const char *status;