Skip to contentSkip to conversation

provisioning APN using mbpi plugin

PATCH In review Christophe Ronco 2 participants 8 messages Feb 8, 2017 – Feb 21, 2017 1 message not in the archive Kbuild

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hello,

I used to set APN manually (using DBUS interface) on my modems.

I am now trying to provision APNs using default values (depending on operator).
I have installed mobile-broadband-provider-info package and tried to use ofono mbpi plugin.
This fail on my current operator:
Feb 8 10:42:16 klk-lpbs-040070 daemon.err ofonod[3750]:
/usr/share/mobile-broadband-provider-info/serviceproviders.xml:4614 Duplicate context detected
Feb 8 10:42:16 klk-lpbs-040070 daemon.warn ofonod[3750]: Provisioning failed

Indeed, my operator (Orange, in France) has several APN of type "internet" declared in mobile-broadband-provider-info database. This is why it fails. And looking at the database, this is quite common. Allowing duplicates or not is just a parameter in function mbpi_lookup_apn. So I changed that in provision_get_settings function (plugins/provision.c).

With this change, provisionning using plugins provision.c and mbpi.c works. It creates 9 contexts for my SIM, 4 of them are internet type contexts.
In connman (I use connman above ofono), I see 4 services and I am able to connect at least 2 of them. So I wonder why duplicate context is considered an error by these plugins. Does anybody know ?

Christophe

#2 lore raw

Hi Christophe,

Quoted 6 lines

With this change, provisionning using plugins provision.c and mbpi.c works. It creates 9 contexts for my SIM, 4 of them are internet type contexts.
In connman (I use connman above ofono), I see 4 services and I am able to connect at least 2 of them. So I wonder why duplicate context is considered an error by these plugins. Does anybody know ?

This is done on purpose. oFono & ConnMan are designed with the assumption that the user will see what is being exposed by the D-Bus API. The UI is just a thin client which simply renders the state of ConnMan / oFono. Think of the D-Bus API as being user-visible. Thus it makes no sense for us to expose services that the user cannot use.

There are a couple of ways to get around this:

- Use a more up-to-date database
- Have a provisioning UI that detects that provisioning has failed, and guides the user through picking the right combination of operator / plan / etc and configures the context settings accordingly

There really should only be a single internet context configured for a given SIM for the vast majority of users in the world.

Regards,
-Denis

#3 lore raw

Hello Denis,

Quoted 17 lines · Denis Kenzior

Hi Christophe,

Quoted 6 lines

With this change, provisionning using plugins provision.c and mbpi.c works. It creates 9 contexts for my SIM, 4 of them are internet type contexts.
In connman (I use connman above ofono), I see 4 services and I am able to connect at least 2 of them. So I wonder why duplicate context is considered an error by these plugins. Does anybody know ?

This is done on purpose. oFono & ConnMan are designed with the assumption that the user will see what is being exposed by the D-Bus API. The UI is just a thin client which simply renders the state of ConnMan / oFono. Think of the D-Bus API as being user-visible. Thus it makes no sense for us to expose services that the user cannot use.

There are a couple of ways to get around this:

Quoted 8 lines

- Use a more up-to-date database
- Have a provisioning UI that detects that provisioning has failed, and guides the user through picking the right combination of operator / plan / etc and configures the context settings accordingly

There really should only be a single internet context configured for a given SIM for the vast majority of users in the world.

I am using private APNs. They should never be in mbpi database. And if they were, for sure, there would be more than one APN for this operator in database. So mbpi database is not something I can use on my board. My board does not have a UI, not even a user. It should leave factory configured to work with SIM(s) from this or that operator (with a private APN).
I can handle that with a configuration file, a daemon waiting for ofono DBUS interface to show up and reading file when it sees a context with an empty APN. But that's far more complicated than a plugin with a configuration file inside ofono.

So I have developed another provisioning plugin based on a configuration file. Patches are attached to this mail and plugin details are explained in commit message. Let me know if you think this can be useful for ofono. I'll rework patches in this case (plugin name maybe, documentation needed maybe, can I use storage.c functions in a plugin?....) and send them cleanly using git send-email.

Best Regards,

Christophe

Quoted 1 line

From 167ab49e14566bcd63b4ceb737b0f5f12a6f3516 Mon Sep 17 00:00:00 2001

From: Christophe Ronco <[email protected]>
Date: Thu, 16 Feb 2017 16:41:30 +0100
Subject: [PATCH 1/2] provision: add plugin to provision from config file

This plugin allows to provision gprs-context data based on MCC and MNC. This is useful when provisioning using mbpi fails (either because you are using a private APN or because there are multiple internet type context for your operator in mbpi database).
Config file is STORAGEDIR/provisioning.
Config file should look like that:
[MCC1,MNC1]
internet.AccessPointName=apn1
internet.Username=myUsername
internet.Password=myPassword
internet.AuthenticationMethod=pap
internet.Protocol=ipv6
[MCC2,MNC2]
internet.AccessPointName=apn2

The only mandatory parameter for each operator is internet.AccessPointName.

Parameter description:
internet.AccessPointName: APN internet.Username: Username internet.Password: Password internet.AuthenticationMethod: authentication method.
Possible values are:
- pap
- chap
Default is chap if unset.
internet.Protocol: protocol
Possible values are:
- ip: ipv4
- ipv6
- dual
Default is ip if not set.

All parameters are prefixed with internet to be able to extend this plugin to other type of contexts (MMS, ...).

---
 plugins/file-provision.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 170 insertions(+)
 create mode 100644 plugins/file-provision.c
plugins/file-provision.c new file +170 -0
new file mode 100644
index 00000000..0fc5acb9
@@ -0,0 +1,170 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2017  Kerlink SA.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <storage.h>
+#include <ofono/modem.h>
+#include <ofono/gprs-provision.h>
+#include <ofono/log.h>
+#include <ofono/plugin.h>
+
+#define SETTINGS_STORE "provisioning"
+
+static int config_file_provision_get_settings(const char *mcc,
+				const char *mnc, const char *spn,
+				struct ofono_gprs_provision_data **settings,
+				int *count)
+{
+	int result = 0;
+	GKeyFile *key_file = NULL;
+	char *setting_group = NULL;
+	char *value;
+
+	DBG("Finding settings for MCC %s, MNC %s, SPN '%s'", mcc, mnc, spn);
+
+	*count = 0;
+	*settings = NULL;
+
+	key_file = storage_open(NULL, SETTINGS_STORE);
+
+	if (key_file == NULL) {
+		result = -ENOENT;
+		goto error;
+	}
+
+	setting_group = g_try_malloc(strlen(mcc) + strlen(mnc) + 2);
+	if (setting_group == NULL) {
+		result = -ENOMEM;
+		goto error;
+	}
+
+	sprintf(setting_group, "%s,%s", mcc, mnc);
+
+	value = g_key_file_get_string(key_file, setting_group,
+					"internet.AccessPointName", NULL);
+
+	if (value == NULL)
+		goto error;
+
+	*settings = g_try_new0(struct ofono_gprs_provision_data, 1);
+	if (*settings == NULL) {
+		result = -ENOMEM;
+		goto error;
+	}
+
+	*count = 1;
+
+	(*settings)[0].type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
+	(*settings)[0].apn = value;
+
+	value = g_key_file_get_string(key_file, setting_group,
+					"internet.Username", NULL);
+
+	if (value != NULL)
+		(*settings)[0].username = value;
+
+	value = g_key_file_get_string(key_file, setting_group,
+					"internet.Password", NULL);
+
+	if (value != NULL)
+		(*settings)[0].password = value;
+
+	(*settings)[0].auth_method = OFONO_GPRS_AUTH_METHOD_CHAP;
+	value = g_key_file_get_string(key_file, setting_group,
+					"internet.AuthenticationMethod", NULL);
+
+	if (value != NULL) {
+		if (g_strcmp0(value, "chap") == 0)
+			(*settings)[0].auth_method =
+						OFONO_GPRS_AUTH_METHOD_CHAP;
+		else if (g_strcmp0(value, "pap") == 0)
+			(*settings)[0].auth_method =
+						OFONO_GPRS_AUTH_METHOD_PAP;
+		else
+			DBG("Unknown auth method: %s", value);
+
+		g_free(value);
+	}
+
+	(*settings)[0].proto = OFONO_GPRS_PROTO_IP;
+	value = g_key_file_get_string(key_file, setting_group,
+					"internet.Protocol", NULL);
+
+	if (value != NULL) {
+		DBG("CRO value:%s", value);
+		if (g_strcmp0(value, "ip") == 0) {
+			DBG("CRO value=ip");
+			(*settings)[0].proto = OFONO_GPRS_PROTO_IP;
+		} else if (g_strcmp0(value, "ipv6") == 0) {
+			DBG("CRO value=ipv6");
+			(*settings)[0].proto = OFONO_GPRS_PROTO_IPV6;
+		} else if (g_strcmp0(value, "dual") == 0)
+			(*settings)[0].proto = OFONO_GPRS_PROTO_IPV4V6;
+		else
+			DBG("Unknown protocol: %s", value);
+
+		g_free(value);
+	}
+
+error:
+	if (key_file != NULL)
+		storage_close(NULL, SETTINGS_STORE, key_file, FALSE);
+
+	if (setting_group != NULL)
+		g_free(setting_group);
+
+	if (result == 0 && *count > 0)
+		DBG("Found. APN:%s, proto:%d, auth_method:%d",
+				(*settings)[0].apn, (*settings)[0].proto,
+				(*settings)[0].auth_method);
+	else
+		DBG("Not found. Result:%d", result);
+
+	return result;
+}
+
+static struct ofono_gprs_provision_driver config_file_provision_driver = {
+	.name		= "GPRS context provisioning",
+	.get_settings	= config_file_provision_get_settings,
+};
+
+static int config_file_provision_init(void)
+{
+	return ofono_gprs_provision_driver_register(
+						&config_file_provision_driver);
+}
+
+static void config_file_provision_exit(void)
+{
+	ofono_gprs_provision_driver_unregister(
+						&config_file_provision_driver);
+}
+
+OFONO_PLUGIN_DEFINE(file_provision, "Gprs Provisioning Plugin",
+			VERSION, OFONO_PLUGIN_PRIORITY_HIGH,
+			config_file_provision_init,
+			config_file_provision_exit)
Signature · 1 line
2.11.0
Quoted 1 line

From 3949f19fba4c4615ff42853dae5b0858b8add675 Mon Sep 17 00:00:00 2001

From: Christophe Ronco <[email protected]>
Date: Thu, 16 Feb 2017 16:43:48 +0100
Subject: [PATCH 2/2] plugins: support for provisioning from config file

---
 Makefile.am | 4 ++++
 1 file changed, 4 insertions(+)
Makefile.am +4 -0
index e1579745..d9f9b086 100644
@@ -555,6 +555,10 @@ builtin_sources += plugins/provision.c
 
 builtin_modules += cdma_provision
 builtin_sources += plugins/cdma-provision.c
+
+builtin_modules += file_provision
+builtin_sources += plugins/file-provision.c
+
 endif
 
 if MAINTAINER_MODE
Signature · 1 line
2.11.0
#4 lore raw

Hi Christophe,

Quoted 4 lines

So I have developed another provisioning plugin based on a configuration file. Patches are attached to this mail and plugin details are explained in commit message. Let me know if you think this can be useful for ofono. I'll rework patches in this case (plugin name maybe,

What you have done is exactly why we have provisioning plugins. mbpi is not the best database in the world. Especially if you're shipping a niche device and know your settings / operators ahead of time.

Quoted 2 lines

documentation needed maybe, can I use storage.c functions in a plugin?....) and send them cleanly using git send-email.

I'm fine carrying this upstream if you want. Generally storage is not meant to be used outside the core. Nor is there a big advantage for you to use these functions anyway. So maybe convert storage_open/close to simple open/close calls would be enough.

Regards,
-Denis

#5 lore raw

cover Add provisioning plugin from configuration file

The goal of this plugin is to provision APN and other internet context details from a configuration file.

The modification from what I sent yesterday:
- do not use storage functions anymore
- changed section names to be able to add other type of sections in the future

Christophe Ronco (2):
provision: add plugin to provision from config file
plugins: support for provisioning from config file

 Makefile.am              |   4 ++
 plugins/file-provision.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 174 insertions(+)
 create mode 100644 plugins/file-provision.c
Signature · 1 line
2.11.0
#6 lore raw

PATCH 1/2 provision: add plugin to provision from config file

This plugin allows to provision gprs-context data based on MCC and MNC. This is useful when provisioning using mbpi fails (either because you are using a private APN or because there are multiple internet type context for your operator in mbpi database).
Config file is STORAGEDIR/provisioning.
Config file should look like that:
[operator:MCC1,MNC1]
internet.AccessPointName=apn1
internet.Username=myUsername
internet.Password=myPassword
internet.AuthenticationMethod=pap
internet.Protocol=ipv6
[operator:MCC2,MNC2]
internet.AccessPointName=apn2

The only mandatory parameter for each operator is internet.AccessPointName.

Parameter description:
internet.AccessPointName: APN internet.Username: Username internet.Password: Password internet.AuthenticationMethod: authentication method.
Possible values are:
- pap
- chap
Default is chap if unset.
internet.Protocol: protocol
Possible values are:
- ip: ipv4
- ipv6
- dual
Default is ip if not set.

All parameters are prefixed with internet to be able to extend this plugin to other type of contexts (MMS, ...).

---
 plugins/file-provision.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 170 insertions(+)
 create mode 100644 plugins/file-provision.c
plugins/file-provision.c new file +170 -0
new file mode 100644
index 00000000..d4846a65
@@ -0,0 +1,170 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2017  Kerlink SA.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/modem.h>
+#include <ofono/gprs-provision.h>
+#include <ofono/log.h>
+#include <ofono/plugin.h>
+
+#define CONFIG_FILE STORAGEDIR "/provisioning"
+
+static int config_file_provision_get_settings(const char *mcc,
+				const char *mnc, const char *spn,
+				struct ofono_gprs_provision_data **settings,
+				int *count)
+{
+	int result = 0;
+	GKeyFile *key_file = NULL;
+	char *setting_group = NULL;
+	char *value;
+
+	DBG("Finding settings for MCC %s, MNC %s, SPN '%s'", mcc, mnc, spn);
+
+	*count = 0;
+	*settings = NULL;
+
+	key_file = g_key_file_new();
+
+	if (!g_key_file_load_from_file(key_file, CONFIG_FILE, 0, NULL)) {
+		result = -ENOENT;
+		goto error;
+	}
+
+	setting_group = g_try_malloc(strlen("operator:") + strlen(mcc) +
+							strlen(mnc) + 2);
+	if (setting_group == NULL) {
+		result = -ENOMEM;
+		goto error;
+	}
+
+	sprintf(setting_group, "operator:%s,%s", mcc, mnc);
+
+	value = g_key_file_get_string(key_file, setting_group,
+					"internet.AccessPointName", NULL);
+
+	if (value == NULL)
+		goto error;
+
+	*settings = g_try_new0(struct ofono_gprs_provision_data, 1);
+	if (*settings == NULL) {
+		result = -ENOMEM;
+		goto error;
+	}
+
+	*count = 1;
+
+	(*settings)[0].type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
+	(*settings)[0].apn = value;
+
+	value = g_key_file_get_string(key_file, setting_group,
+					"internet.Username", NULL);
+
+	if (value != NULL)
+		(*settings)[0].username = value;
+
+	value = g_key_file_get_string(key_file, setting_group,
+					"internet.Password", NULL);
+
+	if (value != NULL)
+		(*settings)[0].password = value;
+
+	(*settings)[0].auth_method = OFONO_GPRS_AUTH_METHOD_CHAP;
+	value = g_key_file_get_string(key_file, setting_group,
+					"internet.AuthenticationMethod", NULL);
+
+	if (value != NULL) {
+		if (g_strcmp0(value, "chap") == 0)
+			(*settings)[0].auth_method =
+						OFONO_GPRS_AUTH_METHOD_CHAP;
+		else if (g_strcmp0(value, "pap") == 0)
+			(*settings)[0].auth_method =
+						OFONO_GPRS_AUTH_METHOD_PAP;
+		else
+			DBG("Unknown auth method: %s", value);
+
+		g_free(value);
+	}
+
+	(*settings)[0].proto = OFONO_GPRS_PROTO_IP;
+	value = g_key_file_get_string(key_file, setting_group,
+					"internet.Protocol", NULL);
+
+	if (value != NULL) {
+		DBG("CRO value:%s", value);
+		if (g_strcmp0(value, "ip") == 0) {
+			DBG("CRO value=ip");
+			(*settings)[0].proto = OFONO_GPRS_PROTO_IP;
+		} else if (g_strcmp0(value, "ipv6") == 0) {
+			DBG("CRO value=ipv6");
+			(*settings)[0].proto = OFONO_GPRS_PROTO_IPV6;
+		} else if (g_strcmp0(value, "dual") == 0)
+			(*settings)[0].proto = OFONO_GPRS_PROTO_IPV4V6;
+		else
+			DBG("Unknown protocol: %s", value);
+
+		g_free(value);
+	}
+
+error:
+	if (key_file != NULL)
+		g_key_file_free(key_file);
+
+	if (setting_group != NULL)
+		g_free(setting_group);
+
+	if (result == 0 && *count > 0)
+		DBG("Found. APN:%s, proto:%d, auth_method:%d",
+				(*settings)[0].apn, (*settings)[0].proto,
+				(*settings)[0].auth_method);
+	else
+		DBG("Not found. Result:%d", result);
+
+	return result;
+}
+
+static struct ofono_gprs_provision_driver config_file_provision_driver = {
+	.name		= "GPRS context provisioning",
+	.get_settings	= config_file_provision_get_settings,
+};
+
+static int config_file_provision_init(void)
+{
+	return ofono_gprs_provision_driver_register(
+						&config_file_provision_driver);
+}
+
+static void config_file_provision_exit(void)
+{
+	ofono_gprs_provision_driver_unregister(
+						&config_file_provision_driver);
+}
+
+OFONO_PLUGIN_DEFINE(file_provision, "Gprs Provisioning Plugin",
+			VERSION, OFONO_PLUGIN_PRIORITY_HIGH,
+			config_file_provision_init,
+			config_file_provision_exit)
Signature · 1 line
2.11.0
#7 lore raw

PATCH 2/2 plugins: support for provisioning from config file

In reply to Christophe Ronco
---
 Makefile.am | 4 ++++
 1 file changed, 4 insertions(+)
Makefile.am +4 -0
index e1579745..d9f9b086 100644
@@ -555,6 +555,10 @@ builtin_sources += plugins/provision.c
 
 builtin_modules += cdma_provision
 builtin_sources += plugins/cdma-provision.c
+
+builtin_modules += file_provision
+builtin_sources += plugins/file-provision.c
+
 endif
 
 if MAINTAINER_MODE
Signature · 1 line
2.11.0
#8 lore raw

Re: [PATCH 0/2] Add provisioning plugin from configuration file

In reply to Christophe Ronco

Hi Christophe,

Quoted 7 lines · Christophe Ronco

The goal of this plugin is to provision APN and other internet context details from a configuration file.

The modification from what I sent yesterday:
- do not use storage functions anymore
- changed section names to be able to add other type of sections in the future

Quoted 6 lines

Christophe Ronco (2):
provision: add plugin to provision from config file
plugins: support for provisioning from config file

 Makefile.am              |   4 ++
 plugins/file-provision.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++

Strictly speaking there was no need to separate these into two patches. If you're adding a new plugin, then build system changes belong together with the code additions. Just for future reference.

Quoted 3 lines
 2 files changed, 174 insertions(+)
 create mode 100644 plugins/file-provision.c

I squished together patch 1 & 2 into a single commit and applied. Thanks!

Regards,
-Denis