---
src/gprs.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/ofono.h | 18 +++++
2 files changed, 246 insertions(+), 0 deletions(-)
diff --git a/src/gprs.c b/src/gprs.c
index acbfa56..f6090ba 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -149,6 +149,19 @@ struct pri_context {
struct ofono_gprs *gprs;
};
+struct gprs_private_context {
+ unsigned int cid;
+ struct ofono_gprs_context *context_driver;
+ union {
+ __ofono_gprs_private_context_activate_cb_t act;
+ __ofono_gprs_private_context_deactivate_cb_t deact;
+ };
+ void *cb_data;
+};
+
+static struct gprs_private_context *stk_context = NULL;
+
+static void gprs_private_context_release(struct gprs_private_context *ctx);
static void gprs_netreg_update(struct ofono_gprs *gprs);
static void gprs_deactivate_next(struct ofono_gprs *gprs);
@@ -346,6 +359,20 @@ static struct pri_context *gprs_context_by_path(struct ofono_gprs
*gprs,
return NULL;
}
+static struct pri_context *gprs_get_default_context(struct ofono_gprs *gprs)
+{
+ GSList *l;
+
+ for (l = gprs->contexts; l; l = l->next) {
+ struct pri_context *ctx = l->data;
+
+ if (ctx->type == OFONO_GPRS_CONTEXT_TYPE_INTERNET)
+ return ctx;
+ }
+
+ return NULL;
+}
+
static void context_settings_free(struct context_settings *settings)
{
if (settings->ipv4) {
@@ -872,6 +899,8 @@ static void pri_activate_callback(const struct ofono_error *error,
void *data)
dbus_message_new_method_return(ctx->pending));
if (gc->settings->interface != NULL) {
+ DBG("Interface %s", gc->settings->interface);
+
pri_ifupdown(gc->settings->interface, TRUE);
if (ctx->type == OFONO_GPRS_CONTEXT_TYPE_MMS &&
@@ -1471,6 +1500,12 @@ static void gprs_attached_update(struct ofono_gprs *gprs)
"Active", DBUS_TYPE_BOOLEAN, &value);
}
+ if (stk_context) {
+ gprs_private_context_release(stk_context);
+ g_free(stk_context);
+ stk_context = NULL;
+ }
+
gprs->bearer = -1;
}
@@ -2173,6 +2208,12 @@ static void gprs_context_unregister(struct ofono_atom *atom)
"Active", DBUS_TYPE_BOOLEAN, &value);
}
+ if (stk_context && stk_context->context_driver == gc) {
+ gprs_private_context_release(stk_context);
+ g_free(stk_context);
+ stk_context = NULL;
+ }
+
gc->gprs->context_drivers = g_slist_remove(gc->gprs->context_drivers,
gc);
gc->gprs = NULL;
@@ -2243,6 +2284,12 @@ void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc,
OFONO_CONNECTION_CONTEXT_INTERFACE,
"Active", DBUS_TYPE_BOOLEAN, &value);
}
+
+ if (stk_context && stk_context->context_driver == gc) {
+ gprs_private_context_release(stk_context);
+ g_free(stk_context);
+ stk_context = NULL;
+ }
}
int ofono_gprs_context_driver_register(const struct ofono_gprs_context_driver *d)
@@ -3012,3 +3059,184 @@ void *ofono_gprs_get_data(struct ofono_gprs *gprs)
{
return gprs->driver_data;
}
+
+static void gprs_private_context_release(struct gprs_private_context *ctx)
+{
+ struct context_settings *settings = ctx->context_driver->settings;
+
+ if (settings->interface != NULL) {
+ pri_set_ipv4_addr(settings->interface, NULL);
+ pri_ifupdown(settings->interface, FALSE);
+ }
+
+ context_settings_free(settings);
+
+ DBG("Release private context cid %d", ctx->cid);
+
+ gprs_cid_release(ctx->context_driver->gprs, ctx->cid);
+ ctx->context_driver->inuse = FALSE;
+}
+
+static void activate_request_callback(const struct ofono_error *error,
+ void *data)
+{
+ struct gprs_private_context *ctx = data;
+ struct context_settings *settings = ctx->context_driver->settings;
+
+ if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+ DBG("Activating context failed with error: %s",
+ telephony_error_to_str(error));
+ gprs_private_context_release(ctx);
+
+ if (ctx->act)
+ ctx->act(-ENOSYS, NULL, NULL, ctx->cb_data);
+
+ g_free(ctx);
+ stk_context = NULL;
+ return;
+ }
+
+ if (settings->interface != NULL) {
+ pri_ifupdown(settings->interface, TRUE);
+
+ if (settings->ipv4)
+ pri_set_ipv4_addr(settings->interface,
+ settings->ipv4->ip);
+ }
+
+ if (ctx->act && settings->ipv4)
+ ctx->act(0, settings->interface, settings->ipv4->ip,
+ ctx->cb_data);
+}
+
+int __ofono_gprs_private_context_activate(struct ofono_gprs *gprs,
+ struct ofono_gprs_primary_context *context,
+ __ofono_gprs_private_context_activate_cb_t cb,
+ void *data)
+{
+ struct pri_context *default_ctx = NULL;
+ struct ofono_gprs_context *gc = NULL;
+ struct idmap *cidmap = gprs->cid_map;
+ GSList *l;
+
+ if (stk_context)
+ return -EBUSY;
+
+ if (context->apn[0] == '\0' || (context->username[0] == '\0'
&&
+ context->password[0] == '\0')) {
+ /* take the default primary internet context */
+ default_ctx = gprs_get_default_context(gprs);
+
+ if (default_ctx == NULL && context->apn[0] == '\0')
+ return -ENOENT;
+ }
+
+ if (context->apn[0] != '\0' && is_valid_apn(context->apn) ==
FALSE)
+ return -EINVAL;
+
+ if (context->proto != OFONO_GPRS_PROTO_IPV4V6 &&
+ context->proto != OFONO_GPRS_PROTO_IP)
+ return -ENOSYS;
+
+ if (cidmap == NULL)
+ return -ENOSYS;
+
+ if (context->apn[0] == '\0') {
+ strcpy(context->apn, default_ctx->context.apn);
+ strcpy(context->username, default_ctx->context.username);
+ strcpy(context->password, default_ctx->context.password);
+ }
+
+ stk_context = g_try_new0(struct gprs_private_context, 1);
+ if (stk_context == NULL)
+ return -ENOMEM;
+
+ stk_context->cid = gprs_cid_alloc(gprs);
+ if (stk_context->cid == 0) {
+ g_free(stk_context);
+ stk_context = NULL;
+ return -EBUSY;
+ }
+
+ context->cid = stk_context->cid;
+
+ for (l = gprs->context_drivers; l; l = l->next) {
+ gc = l->data;
+
+ if (gc->inuse == TRUE)
+ continue;
+
+ if (gc->driver == NULL)
+ continue;
+
+ if (gc->driver->activate_primary == NULL ||
+ gc->driver->deactivate_primary == NULL)
+ continue;
+
+ if (gc->type != OFONO_GPRS_CONTEXT_TYPE_ANY &&
+ gc->type != OFONO_GPRS_CONTEXT_TYPE_INTERNET)
+ continue;
+
+ break;
+ }
+
+ if (gc == NULL) {
+ g_free(stk_context);
+ stk_context = NULL;
+ return -EBUSY;
+ }
+
+ gc->inuse = TRUE;
+ gc->settings->ipv4 = g_new0(struct ipv4_settings, 1);
+ stk_context->context_driver = gc;
+ stk_context->act = cb;
+ stk_context->cb_data = data;
+
+ gc->driver->activate_primary(gc, context, activate_request_callback,
+ stk_context);
+ return 0;
+}
+
+static void deactivate_request_callback(const struct ofono_error *error,
+ void *data)
+{
+ struct gprs_private_context *ctx = data;
+ int err = 0;
+
+ if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+ DBG("Deactivating context failed with error: %s",
+ telephony_error_to_str(error));
+ err = -ENOSYS;
+ }
+
+ gprs_private_context_release(ctx);
+
+ if (ctx->deact)
+ ctx->deact(err, ctx->cb_data);
+
+ g_free(ctx);
+ stk_context = NULL;
+}
+
+int __ofono_gprs_private_context_deactivate(struct ofono_gprs *gprs,
+ __ofono_gprs_private_context_deactivate_cb_t cb,
+ void *data)
+{
+ struct ofono_gprs_context *gc;
+
+ if (stk_context == NULL)
+ return -ENOENT;
+
+ if (stk_context->context_driver->gprs != gprs)
+ return -EINVAL;
+
+ DBG("Deactivate context with cid %d", stk_context->cid);
+
+ stk_context->deact = cb;
+ stk_context->cb_data = data;
+
+ gc = stk_context->context_driver;
+ gc->driver->deactivate_primary(gc, stk_context->cid,
+ deactivate_request_callback, stk_context);
+ return 0;
+}
diff --git a/src/ofono.h b/src/ofono.h
index 6524806..274912d 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -240,6 +240,24 @@ gboolean __ofono_call_settings_is_busy(struct ofono_call_settings
*cs);
#include <ofono/phonebook.h>
#include <ofono/gprs.h>
#include <ofono/gprs-context.h>
+
+typedef void (*__ofono_gprs_private_context_deactivate_cb_t)(int error,
+ void *data);
+
+typedef void (*__ofono_gprs_private_context_activate_cb_t)(int error,
+ const char *interface,
+ const char *ip,
+ void *data);
+
+int __ofono_gprs_private_context_deactivate(struct ofono_gprs *gprs,
+ __ofono_gprs_private_context_deactivate_cb_t cb,
+ void *data);
+
+int __ofono_gprs_private_context_activate(struct ofono_gprs *gprs,
+ struct ofono_gprs_primary_context *context,
+ __ofono_gprs_private_context_activate_cb_t cb,
+ void *data);
+
#include <ofono/radio-settings.h>
#include <ofono/audio-settings.h>
#include <ofono/ctm.h>
--
1.7.1