summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gprs.c62
1 files changed, 39 insertions, 23 deletions
diff --git a/src/gprs.c b/src/gprs.c
index 46e61e9f..0472f90a 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -1150,25 +1150,12 @@ static void write_context_settings(struct ofono_gprs *gprs,
gprs_proto_to_string(context->context.proto));
}
-static DBusMessage *gprs_add_context(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static struct pri_context *add_context(struct ofono_gprs *gprs,
+ const char *name,
+ enum gprs_context_type type)
{
- struct ofono_gprs *gprs = data;
- struct pri_context *context;
- const char *typestr;
- const char *path;
- enum gprs_context_type type;
unsigned int id;
- DBusMessage *signal;
-
- if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &typestr,
- DBUS_TYPE_INVALID))
- return __ofono_error_invalid_args(msg);
-
- type = gprs_context_string_to_type(typestr);
-
- if (type == GPRS_CONTEXT_TYPE_INVALID)
- return __ofono_error_invalid_format(msg);
+ struct pri_context *context;
if (gprs->last_context_id)
id = idmap_alloc_next(gprs->pid_map, gprs->last_context_id);
@@ -1176,21 +1163,21 @@ static DBusMessage *gprs_add_context(DBusConnection *conn,
id = idmap_alloc(gprs->pid_map);
if (id > idmap_get_max(gprs->pid_map))
- return __ofono_error_not_supported(msg);
-
- context = pri_context_create(gprs, typestr, type);
- context->id = id;
+ return NULL;
+ context = pri_context_create(gprs, name, type);
if (!context) {
ofono_error("Unable to allocate context struct");
- return __ofono_error_failed(msg);
+ return NULL;
}
+ context->id = id;
+
DBG("Registering new context");
if (!context_dbus_register(context)) {
ofono_error("Unable to register primary context");
- return __ofono_error_failed(msg);
+ return NULL;
}
gprs->last_context_id = id;
@@ -1202,6 +1189,32 @@ static DBusMessage *gprs_add_context(DBusConnection *conn,
gprs->contexts = g_slist_append(gprs->contexts, context);
+ return context;
+}
+
+static DBusMessage *gprs_add_context(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct ofono_gprs *gprs = data;
+ struct pri_context *context;
+ const char *typestr;
+ const char *path;
+ enum gprs_context_type type;
+ DBusMessage *signal;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &typestr,
+ DBUS_TYPE_INVALID))
+ return __ofono_error_invalid_args(msg);
+
+ type = gprs_context_string_to_type(typestr);
+
+ if (type == GPRS_CONTEXT_TYPE_INVALID)
+ return __ofono_error_invalid_format(msg);
+
+ context = add_context(gprs, typestr, type);
+ if (context == NULL)
+ return __ofono_error_failed(msg);
+
path = context->path;
g_dbus_send_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &path,
@@ -1953,6 +1966,9 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
gprs_load_settings(gprs, imsi);
}
+ if (gprs->contexts == NULL)
+ add_context(gprs, "internet", GPRS_CONTEXT_TYPE_INTERNET);
+
gprs->netreg_watch = __ofono_modem_add_atom_watch(modem,
OFONO_ATOM_TYPE_NETREG,
netreg_watch, gprs, NULL);