* [PATCH 1/4] gprs: Add DBus method to reset contexts
@ 2015-05-18 6:47 Alfonso Sanchez-Beato
2015-05-18 6:47 ` [PATCH 2/4] doc: Add description for ResetContexts method Alfonso Sanchez-Beato
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Alfonso Sanchez-Beato @ 2015-05-18 6:47 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 5852 bytes --]
Add DBus method that removes the current contexts and re-provisions
using the APN database.
---
src/gprs.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 118 insertions(+), 24 deletions(-)
diff --git a/src/gprs.c b/src/gprs.c
index 05ab499..64fa6f1 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -149,6 +149,8 @@ struct pri_context {
static void gprs_netreg_update(struct ofono_gprs *gprs);
static void gprs_deactivate_next(struct ofono_gprs *gprs);
+static void provision_contexts(struct ofono_gprs *gprs, const char *mcc,
+ const char *mnc, const char *spn);
static GSList *g_drivers = NULL;
static GSList *g_context_drivers = NULL;
@@ -1885,6 +1887,36 @@ static struct pri_context *add_context(struct ofono_gprs *gprs,
return context;
}
+static void send_context_added_signal(struct ofono_gprs *gprs,
+ struct pri_context *context,
+ DBusConnection *conn)
+{
+ const char *path;
+ DBusMessage *signal;
+ DBusMessageIter iter;
+ DBusMessageIter dict;
+
+ path = __ofono_atom_get_path(gprs->atom);
+ signal = dbus_message_new_signal(path,
+ OFONO_CONNECTION_MANAGER_INTERFACE,
+ "ContextAdded");
+ if (!signal)
+ return;
+
+ 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);
+}
+
static DBusMessage *gprs_add_context(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -1894,7 +1926,6 @@ static DBusMessage *gprs_add_context(DBusConnection *conn,
const char *name;
const char *path;
enum ofono_gprs_context_type type;
- DBusMessage *signal;
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &typestr,
DBUS_TYPE_INVALID))
@@ -1916,29 +1947,7 @@ static DBusMessage *gprs_add_context(DBusConnection *conn,
g_dbus_send_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
- path = __ofono_atom_get_path(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);
- }
+ send_context_added_signal(gprs, context, conn);
return NULL;
}
@@ -2173,6 +2182,89 @@ static DBusMessage *gprs_get_contexts(DBusConnection *conn,
return reply;
}
+static void remove_non_active_context(struct ofono_gprs *gprs,
+ struct pri_context *ctx, DBusConnection *conn)
+{
+ char *path;
+ const char *atompath;
+
+ if (gprs->settings) {
+ g_key_file_remove_group(gprs->settings, ctx->key, NULL);
+ storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
+ }
+
+ /* Make a backup copy of path for signal emission below */
+ path = g_strdup(ctx->path);
+
+ context_dbus_unregister(ctx);
+ gprs->contexts = g_slist_remove(gprs->contexts, ctx);
+
+ atompath = __ofono_atom_get_path(gprs->atom);
+ g_dbus_emit_signal(conn, atompath, OFONO_CONNECTION_MANAGER_INTERFACE,
+ "ContextRemoved", DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+ g_free(path);
+}
+
+static DBusMessage *gprs_reset_contexts(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct ofono_gprs *gprs = data;
+ struct ofono_modem *modem = __ofono_atom_get_modem(gprs->atom);
+ struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
+ DBusMessage *reply;
+ GSList *l;
+
+ if (gprs->pending)
+ return __ofono_error_busy(msg);
+
+ for (l = gprs->contexts; l; l = l->next) {
+ struct pri_context *ctx = l->data;
+
+ if (ctx->pending)
+ return __ofono_error_busy(msg);
+ }
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID))
+ return __ofono_error_invalid_args(msg);
+
+ if (gprs->powered)
+ return __ofono_error_not_allowed(msg);
+
+ for (l = gprs->contexts; l; l = l->next) {
+ struct pri_context *ctx = l->data;
+
+ if (ctx->active)
+ return __ofono_error_not_allowed(msg);
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ /* Remove first the current contexts, re-provision after */
+
+ while (gprs->contexts != NULL) {
+ struct pri_context *ctx = gprs->contexts->data;
+ remove_non_active_context(gprs, ctx, conn);
+ }
+
+ gprs->last_context_id = 0;
+
+ provision_contexts(gprs, ofono_sim_get_mcc(sim),
+ ofono_sim_get_mnc(sim), ofono_sim_get_spn(sim));
+
+ if (gprs->contexts == NULL) /* Automatic provisioning failed */
+ add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
+
+ for (l = gprs->contexts; l; l = l->next) {
+ struct pri_context *ctx = l->data;
+ send_context_added_signal(gprs, ctx, conn);
+ }
+
+ return reply;
+}
+
static const GDBusMethodTable manager_methods[] = {
{ GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
@@ -2192,6 +2284,8 @@ static const GDBusMethodTable manager_methods[] = {
{ GDBUS_METHOD("GetContexts", NULL,
GDBUS_ARGS({ "contexts_with_properties", "a(oa{sv})" }),
gprs_get_contexts) },
+ { GDBUS_ASYNC_METHOD("ResetContexts", NULL, NULL,
+ gprs_reset_contexts) },
{ }
};
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/4] doc: Add description for ResetContexts method
2015-05-18 6:47 [PATCH 1/4] gprs: Add DBus method to reset contexts Alfonso Sanchez-Beato
@ 2015-05-18 6:47 ` Alfonso Sanchez-Beato
2015-05-18 6:47 ` [PATCH 3/4] test: Add script for resetting contexts Alfonso Sanchez-Beato
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Alfonso Sanchez-Beato @ 2015-05-18 6:47 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 798 bytes --]
---
doc/connman-api.txt | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/doc/connman-api.txt b/doc/connman-api.txt
index 8f72087..1ce1d61 100644
--- a/doc/connman-api.txt
+++ b/doc/connman-api.txt
@@ -60,6 +60,16 @@ Methods dict GetProperties()
[service].Error.NotFound
[service].Error.Failed
+ void ResetContexts()
+
+ Removes all contexts and re-provisions from the APN
+ database. Contexts must all be deactivated for this
+ method to work, and the atom must not be powered.
+
+ Possible Errors: [service].Error.InProgress
+ [service].Error.InvalidArguments
+ [service].Error.NotAllowed
+
Signals PropertyChanged(string property, variant value)
This signal indicates a changed value of the given
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/4] test: Add script for resetting contexts
2015-05-18 6:47 [PATCH 1/4] gprs: Add DBus method to reset contexts Alfonso Sanchez-Beato
2015-05-18 6:47 ` [PATCH 2/4] doc: Add description for ResetContexts method Alfonso Sanchez-Beato
@ 2015-05-18 6:47 ` Alfonso Sanchez-Beato
2015-05-18 6:47 ` [PATCH 4/4] gprs: Refactor to remove forward declaration Alfonso Sanchez-Beato
2015-05-18 14:09 ` [PATCH 1/4] gprs: Add DBus method to reset contexts Denis Kenzior
3 siblings, 0 replies; 5+ messages in thread
From: Alfonso Sanchez-Beato @ 2015-05-18 6:47 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 766 bytes --]
---
test/reset-contexts | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 test/reset-contexts
diff --git a/test/reset-contexts b/test/reset-contexts
new file mode 100644
index 0000000..1676636
--- /dev/null
+++ b/test/reset-contexts
@@ -0,0 +1,20 @@
+#!/usr/bin/python3
+
+import dbus
+import sys
+
+bus = dbus.SystemBus()
+
+if len(sys.argv) == 2:
+ path = sys.argv[1]
+else:
+ manager = dbus.Interface(bus.get_object('org.ofono', '/'),
+ 'org.ofono.Manager')
+ modems = manager.GetModems()
+ path = modems[0][0]
+
+print("Resetting contexts for SIM on modem %s..." % path)
+cm = dbus.Interface(bus.get_object('org.ofono', path),
+ 'org.ofono.ConnectionManager')
+
+cm.ResetContexts()
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 4/4] gprs: Refactor to remove forward declaration
2015-05-18 6:47 [PATCH 1/4] gprs: Add DBus method to reset contexts Alfonso Sanchez-Beato
2015-05-18 6:47 ` [PATCH 2/4] doc: Add description for ResetContexts method Alfonso Sanchez-Beato
2015-05-18 6:47 ` [PATCH 3/4] test: Add script for resetting contexts Alfonso Sanchez-Beato
@ 2015-05-18 6:47 ` Alfonso Sanchez-Beato
2015-05-18 14:09 ` [PATCH 1/4] gprs: Add DBus method to reset contexts Denis Kenzior
3 siblings, 0 replies; 5+ messages in thread
From: Alfonso Sanchez-Beato @ 2015-05-18 6:47 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 6197 bytes --]
---
src/gprs.c | 206 ++++++++++++++++++++++++++++++-------------------------------
1 file changed, 102 insertions(+), 104 deletions(-)
diff --git a/src/gprs.c b/src/gprs.c
index 64fa6f1..9c15abf 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -149,8 +149,6 @@ struct pri_context {
static void gprs_netreg_update(struct ofono_gprs *gprs);
static void gprs_deactivate_next(struct ofono_gprs *gprs);
-static void provision_contexts(struct ofono_gprs *gprs, const char *mcc,
- const char *mnc, const char *spn);
static GSList *g_drivers = NULL;
static GSList *g_context_drivers = NULL;
@@ -2182,6 +2180,108 @@ static DBusMessage *gprs_get_contexts(DBusConnection *conn,
return reply;
}
+static void provision_context(const struct ofono_gprs_provision_data *ap,
+ struct ofono_gprs *gprs)
+{
+ unsigned int id;
+ struct pri_context *context = NULL;
+
+ /* Sanity check */
+ if (ap == NULL)
+ return;
+
+ if (ap->name && strlen(ap->name) > MAX_CONTEXT_NAME_LENGTH)
+ return;
+
+ if (ap->apn == NULL || strlen(ap->apn) > OFONO_GPRS_MAX_APN_LENGTH)
+ return;
+
+ if (is_valid_apn(ap->apn) == FALSE)
+ return;
+
+ if (ap->username &&
+ strlen(ap->username) > OFONO_GPRS_MAX_USERNAME_LENGTH)
+ return;
+
+ if (ap->password &&
+ strlen(ap->password) > OFONO_GPRS_MAX_PASSWORD_LENGTH)
+ return;
+
+ if (ap->message_proxy &&
+ strlen(ap->message_proxy) > MAX_MESSAGE_PROXY_LENGTH)
+ return;
+
+ if (ap->message_center &&
+ strlen(ap->message_center) > MAX_MESSAGE_CENTER_LENGTH)
+ return;
+
+ if (gprs->last_context_id)
+ id = idmap_alloc_next(gprs->pid_map, gprs->last_context_id);
+ else
+ id = idmap_alloc(gprs->pid_map);
+
+ if (id > idmap_get_max(gprs->pid_map))
+ return;
+
+ context = pri_context_create(gprs, ap->name, ap->type);
+ if (context == NULL) {
+ idmap_put(gprs->pid_map, id);
+ return;
+ }
+
+ context->id = id;
+
+ if (ap->username != NULL)
+ strcpy(context->context.username, ap->username);
+
+ if (ap->password != NULL)
+ strcpy(context->context.password, ap->password);
+
+ context->context.auth_method = ap->auth_method;
+
+ strcpy(context->context.apn, ap->apn);
+ context->context.proto = ap->proto;
+
+ if (ap->type == OFONO_GPRS_CONTEXT_TYPE_MMS) {
+ if (ap->message_proxy != NULL)
+ strcpy(context->message_proxy, ap->message_proxy);
+
+ if (ap->message_center != NULL)
+ strcpy(context->message_center, ap->message_center);
+ }
+
+ if (context_dbus_register(context) == FALSE)
+ return;
+
+ gprs->last_context_id = id;
+
+ if (gprs->settings) {
+ write_context_settings(gprs, context);
+ storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
+ }
+
+ gprs->contexts = g_slist_append(gprs->contexts, context);
+}
+
+static void provision_contexts(struct ofono_gprs *gprs, const char *mcc,
+ const char *mnc, const char *spn)
+{
+ struct ofono_gprs_provision_data *settings;
+ int count;
+ int i;
+
+ if (__ofono_gprs_provision_get_settings(mcc, mnc, spn,
+ &settings, &count) == FALSE) {
+ ofono_warn("Provisioning failed");
+ return;
+ }
+
+ for (i = 0; i < count; i++)
+ provision_context(&settings[i], gprs);
+
+ __ofono_gprs_provision_free_settings(settings, count);
+}
+
static void remove_non_active_context(struct ofono_gprs *gprs,
struct pri_context *ctx, DBusConnection *conn)
{
@@ -3067,108 +3167,6 @@ remove:
storage_sync(imsi, SETTINGS_STORE, gprs->settings);
}
-static void provision_context(const struct ofono_gprs_provision_data *ap,
- struct ofono_gprs *gprs)
-{
- unsigned int id;
- struct pri_context *context = NULL;
-
- /* Sanity check */
- if (ap == NULL)
- return;
-
- if (ap->name && strlen(ap->name) > MAX_CONTEXT_NAME_LENGTH)
- return;
-
- if (ap->apn == NULL || strlen(ap->apn) > OFONO_GPRS_MAX_APN_LENGTH)
- return;
-
- if (is_valid_apn(ap->apn) == FALSE)
- return;
-
- if (ap->username &&
- strlen(ap->username) > OFONO_GPRS_MAX_USERNAME_LENGTH)
- return;
-
- if (ap->password &&
- strlen(ap->password) > OFONO_GPRS_MAX_PASSWORD_LENGTH)
- return;
-
- if (ap->message_proxy &&
- strlen(ap->message_proxy) > MAX_MESSAGE_PROXY_LENGTH)
- return;
-
- if (ap->message_center &&
- strlen(ap->message_center) > MAX_MESSAGE_CENTER_LENGTH)
- return;
-
- if (gprs->last_context_id)
- id = idmap_alloc_next(gprs->pid_map, gprs->last_context_id);
- else
- id = idmap_alloc(gprs->pid_map);
-
- if (id > idmap_get_max(gprs->pid_map))
- return;
-
- context = pri_context_create(gprs, ap->name, ap->type);
- if (context == NULL) {
- idmap_put(gprs->pid_map, id);
- return;
- }
-
- context->id = id;
-
- if (ap->username != NULL)
- strcpy(context->context.username, ap->username);
-
- if (ap->password != NULL)
- strcpy(context->context.password, ap->password);
-
- context->context.auth_method = ap->auth_method;
-
- strcpy(context->context.apn, ap->apn);
- context->context.proto = ap->proto;
-
- if (ap->type == OFONO_GPRS_CONTEXT_TYPE_MMS) {
- if (ap->message_proxy != NULL)
- strcpy(context->message_proxy, ap->message_proxy);
-
- if (ap->message_center != NULL)
- strcpy(context->message_center, ap->message_center);
- }
-
- if (context_dbus_register(context) == FALSE)
- return;
-
- gprs->last_context_id = id;
-
- if (gprs->settings) {
- write_context_settings(gprs, context);
- storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
- }
-
- gprs->contexts = g_slist_append(gprs->contexts, context);
-}
-
-static void provision_contexts(struct ofono_gprs *gprs, const char *mcc,
- const char *mnc, const char *spn)
-{
- struct ofono_gprs_provision_data *settings;
- int count;
- int i;
-
- if (__ofono_gprs_provision_get_settings(mcc, mnc, spn,
- &settings, &count) == FALSE) {
- ofono_warn("Provisioning failed");
- return;
- }
-
- for (i = 0; i < count; i++)
- provision_context(&settings[i], gprs);
-
- __ofono_gprs_provision_free_settings(settings, count);
-}
-
static void ofono_gprs_finish_register(struct ofono_gprs *gprs)
{
DBusConnection *conn = ofono_dbus_get_connection();
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 1/4] gprs: Add DBus method to reset contexts
2015-05-18 6:47 [PATCH 1/4] gprs: Add DBus method to reset contexts Alfonso Sanchez-Beato
` (2 preceding siblings ...)
2015-05-18 6:47 ` [PATCH 4/4] gprs: Refactor to remove forward declaration Alfonso Sanchez-Beato
@ 2015-05-18 14:09 ` Denis Kenzior
3 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2015-05-18 14:09 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 398 bytes --]
Hi Alfonso,
On 05/18/2015 01:47 AM, Alfonso Sanchez-Beato wrote:
> Add DBus method that removes the current contexts and re-provisions
> using the APN database.
> ---
> src/gprs.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 118 insertions(+), 24 deletions(-)
>
All 4 patches in this series have been applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-05-18 14:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-18 6:47 [PATCH 1/4] gprs: Add DBus method to reset contexts Alfonso Sanchez-Beato
2015-05-18 6:47 ` [PATCH 2/4] doc: Add description for ResetContexts method Alfonso Sanchez-Beato
2015-05-18 6:47 ` [PATCH 3/4] test: Add script for resetting contexts Alfonso Sanchez-Beato
2015-05-18 6:47 ` [PATCH 4/4] gprs: Refactor to remove forward declaration Alfonso Sanchez-Beato
2015-05-18 14:09 ` [PATCH 1/4] gprs: Add DBus method to reset contexts Denis Kenzior
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox