All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] gprs: add function to handle activated context
@ 2011-01-05 17:25 Soum, RedouaneX
  2011-01-06  0:12 ` Marcel Holtmann
  2011-01-06 12:02 ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
  0 siblings, 2 replies; 28+ messages in thread
From: Soum, RedouaneX @ 2011-01-05 17:25 UTC (permalink / raw)
  To: ofono

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

gprs: add function to handle activated context
ofono_gprs_context_activated : this function is symetric to ofono_gprs_context_deactivated.
This function must be call by any gprs-context driver when a context has been activated without explicit request.

Behavior of the function :

List all the context and try to find correct APN
If such context is not found create a new one with "Internet" type

For the context (found or created):
	Update the settings
	Set to active
---
 include/gprs-context.h |    6 +++
 src/gprs.c             |  105 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 111 insertions(+), 0 deletions(-)

diff --git a/include/gprs-context.h b/include/gprs-context.h
index c29c0dc..57cd60b 100644
--- a/include/gprs-context.h
+++ b/include/gprs-context.h
@@ -76,6 +76,12 @@ struct ofono_gprs_context_driver {
 					ofono_gprs_context_cb_t cb, void *data);
 };
 
+void ofono_gprs_context_activated(struct ofono_gprs_context *gc,
+				const int cid, const char *apn,
+				const char *interface, ofono_bool_t static_ip,
+				const char *address, const char *netmask,
+				const char *gw, const char **dns);
+
 void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc,
 					unsigned int id);
 
diff --git a/src/gprs.c b/src/gprs.c
index 58166f8..b7a4768 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -212,6 +212,11 @@ static unsigned int gprs_cid_alloc(struct ofono_gprs *gprs)
 	return idmap_alloc(gprs->cid_map);
 }
 
+static void gprs_cid_take(struct ofono_gprs *gprs, unsigned int id)
+{
+	idmap_take(gprs->cid_map, id);
+}
+
 static void gprs_cid_release(struct ofono_gprs *gprs, unsigned int id)
 {
 	idmap_put(gprs->cid_map, id);
@@ -1977,6 +1982,106 @@ void ofono_gprs_add_context(struct ofono_gprs *gprs,
 	__ofono_atom_register(gc->atom, gprs_context_unregister);
 }
 
+void ofono_gprs_context_activated(struct ofono_gprs_context *gc,
+		const int cid, const char *apn,
+		const char *interface, ofono_bool_t static_ip,
+		const char *address, const char *netmask,
+		const char *gw, const char **dns)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+	GSList *l;
+	dbus_bool_t value;
+	struct pri_context *context;
+	const char *path;
+	DBusMessage *signal;
+	GKeyFile *settings;
+
+	if (gc->gprs == NULL)
+		return;
+
+	for (l = gc->gprs->contexts; l; l = l->next) {
+		context = l->data;
+
+		if (strcmp(context->context.apn, apn) == 0)
+			break;
+	}
+
+	if (!l) {
+		context = add_context(gc->gprs, "Internet",
+				OFONO_GPRS_CONTEXT_TYPE_INTERNET);
+
+		path = __ofono_atom_get_path(gc->gprs->atom);
+		signal = dbus_message_new_signal(path,
+				OFONO_CONNECTION_MANAGER_INTERFACE,
+				"ContextAdded");
+
+		if (signal) {
+			DBusMessageIter iter;
+			DBusMessageIter dict;
+
+			dbus_message_iter_init_append(signal, &iter);
+
+			path = context->path;
+			dbus_message_iter_append_basic(&iter,
+					DBUS_TYPE_OBJECT_PATH,
+					&path);
+
+			dbus_message_iter_open_container(&iter,
+					DBUS_TYPE_ARRAY,
+					OFONO_PROPERTIES_ARRAY_SIGNATURE,
+					&dict);
+
+			append_context_properties(context, &dict);
+			dbus_message_iter_close_container(&iter, &dict);
+
+			g_dbus_send_message(conn, signal);
+		}
+
+		strcpy(context->context.apn, apn);
+		settings = context->gprs->settings;
+
+		if (settings) {
+			g_key_file_set_string(settings, context->key,
+					"AccessPointName", apn);
+			storage_sync(context->gprs->imsi,
+					SETTINGS_STORE, settings);
+		}
+
+		ofono_dbus_signal_property_changed(conn, context->path,
+					OFONO_CONNECTION_CONTEXT_INTERFACE,
+					"AccessPointName",
+					DBUS_TYPE_STRING, &apn);
+	}
+
+	gprs_cid_take(gc->gprs, cid);
+	context->context.cid = cid;
+	value = context->active = TRUE;
+
+	if (interface != NULL)
+		pri_update_context_settings(context, interface, static_ip,
+					address, netmask, gw, dns);
+
+	for (l = context->gprs->context_drivers; l; l = l->next) {
+		struct ofono_gprs_context *gc = l->data;
+
+		if (gc->inuse == TRUE)
+			continue;
+
+		if (gc->type == OFONO_GPRS_CONTEXT_TYPE_ANY ||
+						gc->type == context->type) {
+			context->context_driver = gc;
+			context->context_driver->inuse = TRUE;
+		}
+	}
+
+	ofono_dbus_signal_property_changed(conn, context->path,
+					OFONO_CONNECTION_CONTEXT_INTERFACE,
+					"Active", DBUS_TYPE_BOOLEAN, &value);
+
+}
+
+
+
 void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc,
 					unsigned int cid)
 {
-- 
1.7.0.4

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2011-01-17 23:15 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-05 17:25 [RFC PATCH] gprs: add function to handle activated context Soum, RedouaneX
2011-01-06  0:12 ` Marcel Holtmann
2011-01-06  0:17   ` Denis Kenzior
2011-01-07  8:52     ` =?unknown-8bit?q?R=C3=A9mi?= Denis-Courmont
2011-01-07 15:45       ` Joly, Frederic
2011-01-07 21:07       ` Denis Kenzior
2011-01-06 13:28   ` Soum, RedouaneX
2011-01-07  8:50   ` =?unknown-8bit?q?R=C3=A9mi?= Denis-Courmont
2011-01-07 10:38     ` Aki Niemi
2011-01-06 12:02 ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-06 14:59   ` Soum, RedouaneX
2011-01-06 16:47     ` Denis Kenzior
2011-01-06 17:14     ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-06 16:37   ` Denis Kenzior
2011-01-06 17:39   ` Marcel Holtmann
2011-01-06 17:45     ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-06 17:53       ` Marcel Holtmann
2011-01-06 18:10       ` Denis Kenzior
2011-01-07 15:14         ` Joly, Frederic
2011-01-07 15:38           ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-07 17:52             ` Joly, Frederic
2011-01-07 21:01               ` Denis Kenzior
2011-01-11 12:46                 ` Soum, RedouaneX
2011-01-17 14:21                 ` Pekka Pessi
2011-01-17 18:39                   ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-17 18:51                     ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2011-01-17 22:39                     ` Pekka Pessi
2011-01-17 23:15                       ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.