Open Source Telephony
 help / color / mirror / Atom feed
From: Dragos Tatulea <dragos@endocode.com>
To: ofono@ofono.org
Subject: [PATCH 3/5] gprs: implement ofono_gprs_cid_activated
Date: Fri, 18 Mar 2016 12:58:52 +0100	[thread overview]
Message-ID: <1458302334-6149-4-git-send-email-dragos@endocode.com> (raw)
In-Reply-To: <1458302334-6149-1-git-send-email-dragos@endocode.com>

[-- Attachment #1: Type: text/plain, Size: 4455 bytes --]

It works by looking for a context with the same APN and tries to use
that. Otherwise it will create it's own.

Then it assigns a gprs context driver and calls it's read_settings if
it exists.
---
 src/gprs.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 114 insertions(+)

diff --git a/src/gprs.c b/src/gprs.c
index e956a23..9a85121 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -293,6 +293,11 @@ static void gprs_cid_release(struct ofono_gprs *gprs, unsigned int id)
 	idmap_put(gprs->cid_map, id);
 }
 
+static gboolean gprs_cid_taken(struct ofono_gprs *gprs, unsigned int id)
+{
+	return idmap_find(gprs->cid_map, id) != 0;
+}
+
 static gboolean assign_context(struct pri_context *ctx, int use_cid)
 {
 	struct idmap *cidmap = ctx->gprs->cid_map;
@@ -943,6 +948,39 @@ static void pri_deactivate_callback(const struct ofono_error *error, void *data)
 					"Active", DBUS_TYPE_BOOLEAN, &value);
 }
 
+static void pri_read_settings_callback(const struct ofono_error *error,
+					void *data)
+{
+	struct pri_context *pri_ctx = data;
+	struct ofono_gprs_context *gc = pri_ctx->context_driver;
+	DBusConnection *conn = ofono_dbus_get_connection();
+	dbus_bool_t value;
+
+	DBG("%p", pri_ctx);
+
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+		DBG("Reading context settings failed with error: %s",
+				telephony_error_to_str(error));
+		context_settings_free(pri_ctx->context_driver->settings);
+		release_context(pri_ctx);
+		return;
+	}
+
+	pri_ctx->active = TRUE;
+
+	if (gc->settings->interface != NULL) {
+		pri_ifupdown(gc->settings->interface, TRUE);
+
+		pri_context_signal_settings(pri_ctx, gc->settings->ipv4 != NULL,
+						gc->settings->ipv6 != NULL);
+	}
+
+	value = pri_ctx->active;
+	ofono_dbus_signal_property_changed(conn, pri_ctx->path,
+					OFONO_CONNECTION_CONTEXT_INTERFACE,
+					"Active", DBUS_TYPE_BOOLEAN, &value);
+}
+
 static DBusMessage *pri_set_apn(struct pri_context *ctx, DBusConnection *conn,
 				DBusMessage *msg, const char *apn)
 {
@@ -1840,6 +1878,35 @@ static void write_context_settings(struct ofono_gprs *gprs,
 	}
 }
 
+static struct pri_context *find_usable_context(struct ofono_gprs *gprs,
+					const char *apn)
+{
+	GSList *l;
+	struct pri_context *pri_ctx;
+
+	/* Look for matching APN: */
+	for (l = gprs->contexts; l; l = l->next) {
+		pri_ctx = l->data;
+
+		/* Looking only at prefix for the LTE case when a user APN is
+		 * web.provider.com but it apepars as
+		 * web.provider.com.mncX.mccY.gprs .
+		 */
+		if (g_str_has_prefix(apn, pri_ctx->context.apn))
+			return pri_ctx;
+	}
+
+	/* Look for a provision failed pri context: */
+	for (l = gprs->contexts; l; l = l->next) {
+		pri_ctx = l->data;
+
+		if (pri_ctx->context.apn == NULL)
+			return pri_ctx;
+	}
+
+	return NULL;
+}
+
 static struct pri_context *add_context(struct ofono_gprs *gprs,
 					const char *name,
 					enum ofono_gprs_context_type type)
@@ -1883,6 +1950,53 @@ static struct pri_context *add_context(struct ofono_gprs *gprs,
 	return context;
 }
 
+void ofono_gprs_cid_activated(struct ofono_gprs  *gprs, unsigned int cid,
+				const char *apn)
+{
+	struct pri_context *pri_ctx;
+	struct ofono_gprs_context *gc;
+
+	DBG("");
+
+	if (gprs_cid_taken(gprs, cid)) {
+		DBG("cid %u already activated", cid);
+		return;
+	}
+
+	pri_ctx = find_usable_context(gprs, apn);
+
+	if (!pri_ctx) {
+		pri_ctx = add_context(gprs, apn,
+					OFONO_GPRS_CONTEXT_TYPE_INTERNET);
+		if (!pri_ctx) {
+			ofono_error("Can't find/create automatic context %d "
+					"with APN %s.", cid, apn);
+			return;
+		}
+	}
+
+	if (assign_context(pri_ctx, cid) == FALSE) {
+		ofono_warn("Can't assign context to driver for APN.");
+		release_context(pri_ctx);
+		return;
+	}
+
+	gc = pri_ctx->context_driver;
+
+	if (gc->driver->read_settings == NULL) {
+		ofono_warn("Context activated for driver that doesn't support "
+				"automatic context activation.");
+		release_context(pri_ctx);
+	}
+
+	if (strlen(pri_ctx->context.apn) == 0) {
+		DBusConnection *conn = ofono_dbus_get_connection();
+		pri_set_apn(pri_ctx, conn, NULL, apn);
+	}
+
+	gc->driver->read_settings(gc, cid, pri_read_settings_callback, pri_ctx);
+}
+
 static void send_context_added_signal(struct ofono_gprs *gprs,
 					struct pri_context *context,
 					DBusConnection *conn)
-- 
2.5.0


  parent reply	other threads:[~2016-03-18 11:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-18 11:58 [PATCH v4 0/5] allow automatic context activation Dragos Tatulea
2016-03-18 11:58 ` [PATCH 1/5] idmap: add api for finding a certain id in map Dragos Tatulea
2016-03-18 15:03   ` Denis Kenzior
2016-03-18 11:58 ` [PATCH 2/5] gprs-context.h: add op for reading context config Dragos Tatulea
2016-03-18 15:04   ` Denis Kenzior
2016-03-18 11:58 ` Dragos Tatulea [this message]
2016-03-18 15:10   ` [PATCH 3/5] gprs: implement ofono_gprs_cid_activated Denis Kenzior
2016-03-18 11:58 ` [PATCH 4/5] atmodem: gprs: handle automatic context activation Dragos Tatulea
2016-03-18 15:11   ` Denis Kenzior
2016-03-18 11:58 ` [PATCH 5/5] ubloxmodem: support automatic ctx activation Dragos Tatulea
2016-03-18 15:13   ` Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2016-03-18 11:53 [PATCH v3 0/9] allow automatic context activation Dragos Tatulea
2016-03-18 11:53 ` [PATCH 3/5] gprs: implement ofono_gprs_cid_activated Dragos Tatulea
2016-03-18 10:47 [PATCH v2 0/9] allow automatic context activation Dragos Tatulea
2016-03-18 10:47 ` [PATCH 3/5] gprs: implement ofono_gprs_cid_activated Dragos Tatulea

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458302334-6149-4-git-send-email-dragos@endocode.com \
    --to=dragos@endocode.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox