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, ...).
This commit is contained in:
Christophe Ronco 2017-02-17 15:44:47 +01:00 committed by Denis Kenzior
parent 89c92e7277
commit 94fd4d804d
2 changed files with 174 additions and 0 deletions

View File

@ -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

170
plugins/file-provision.c Normal file
View File

@ -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)