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 then create a new one with "Internet" type only if 
we are in LTE with no Active context.

Otherwise deactivate the connection.

For the context (found or created):
        Update the settings
        Set to active
---
 src/gprs.c |  122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 0 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 0e86bdf..6506936 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -692,6 +692,10 @@ static void pri_activate_callback(const struct ofono_error 
*error,
                                        "Active", DBUS_TYPE_BOOLEAN, &value);
 }
 
+static void __ofono_gprs_context_activated_callback(const struct ofono_error 
*error, void *data)
+{
+}
+
 static void pri_deactivate_callback(const struct ofono_error *error, void 
*data)
 {
        struct pri_context *ctx = data;
@@ -1979,6 +1983,124 @@ 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;
+       int active_context = 0;
+       int technology = 0;
+
+       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 (context->active)
+                       active_context = 1;
+       }
+
+
+       if (gc->gprs->netreg)
+               technology = ofono_netreg_get_technology(gc->gprs->netreg);
+
+       if (!l && !(active_context == 1 && technology == 7)) {
+
+               for (l = context->gprs->context_drivers; l; l = l->next) {
+                       struct ofono_gprs_context *gc = l->data;
+
+                       if (gc->inuse != TRUE) {
+                               gc->driver->deactivate_primary(gc, cid,
+                               __ofono_gprs_context_activated_callback, 0);
+
+                               return ;
+                       }
+               }
+               return ;
+       }
+
+       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);
+       }
+
+       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.

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to