---
Makefile.am | 3 +
examples/provision.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 201 insertions(+), 0 deletions(-)
create mode 100644 examples/provision.c
diff --git a/Makefile.am b/Makefile.am
index 0f330a7..d57509d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -305,6 +305,9 @@ builtin_sources += examples/history.c
builtin_modules += example_nettime
builtin_sources += examples/nettime.c
+
+builtin_modules += example_gprs_provision
+builtin_sources += examples/provision.c
endif
builtin_modules += smart_messaging
diff --git a/examples/provision.c b/examples/provision.c
new file mode 100644
index 0000000..f075734
--- /dev/null
+++ b/examples/provision.c
@@ -0,0 +1,198 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <glib.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+
+#include <ofono/modem.h>
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/gprs-provision.h>
+#include <ofono/types.h>
+
+#include "ofono.h"
+#include "common.h"
+#include "sim.h"
+#include "simutil.h"
+#include "util.h"
+
+struct provisioning_request {
+ struct ofono_modem *modem;
+ ofono_gprs_provision_cb_t cb;
+ void *userdata;
+};
+
+static void sim_spn_read_cb(int ok, int length, int record,
+ const unsigned char *data,
+ int record_length, void *userdata)
+{
+ struct provisioning_request *req = userdata;
+ char *spn = NULL;
+
+ struct ofono_atom *sim_atom;
+ struct ofono_sim *sim;
+ const char *imsi;
+
+ unsigned char mnc_length;
+ char mcc[OFONO_MAX_MCC_LENGTH + 1];
+ char mnc[OFONO_MAX_MNC_LENGTH + 1];
+
+ GSList *settings = NULL;
+ struct ofono_gprs_provisioning_data *entry;
+
+ sim_atom = __ofono_modem_find_atom(req->modem, OFONO_ATOM_TYPE_SIM);
+
+ if (sim_atom == NULL) {
+ ofono_debug("No SIM atom");
+ goto finish;
+ }
+
+ sim = __ofono_atom_get_data(sim_atom);
+ imsi = ofono_sim_get_imsi(sim);
+ if (imsi == NULL) {
+ ofono_debug("No IMSI available");
+ goto finish;
+ }
+
+ mnc_length = ofono_sim_get_mnc_length(sim);
+ if (mnc_length == 0) {
+ ofono_debug("No MNC length available");
+ goto finish;
+ }
+
+ strncpy(mcc, imsi, OFONO_MAX_MCC_LENGTH);
+ mcc[OFONO_MAX_MCC_LENGTH] = '\0';
+ strncpy(mnc, imsi + OFONO_MAX_MCC_LENGTH, mnc_length);
+ mnc[mnc_length] = '\0';
+
+ if (ok)
+ spn = sim_string_to_utf8(data + 1, length - 1);
+
+ ofono_debug("Finding settings for MCC %s, MNC %s, SPN '%s'",
+ mcc, mnc, spn);
+
+ if (spn == NULL || strcmp(spn, "oFono") != 0)
+ goto finish;
+
+ /* Example settings for Phonesim */
+ ofono_debug("Creating example settings for phonesim");
+
+ /* MMS context settings */
+ entry = g_try_new0(struct ofono_gprs_provisioning_data, 1);
+ if (entry == NULL)
+ goto finish;
+
+ entry->proto = OFONO_GPRS_PROTO_IP;
+ entry->type = OFONO_GPRS_CONTEXT_TYPE_MMS;
+ entry->name = g_strdup("Phonesim MMS");
+ entry->apn = g_strdup("mmsapn");
+ entry->username = g_strdup("mmsuser");
+ entry->password = g_strdup("mmspass");
+ entry->message_proxy = g_strdup("10.11.12.13:8080");
+ entry->message_center = g_strdup("http://mms.example.com:8000");
+ settings = g_slist_prepend(settings, entry);
+
+ /* Internet context settings */
+ entry = g_try_new0(struct ofono_gprs_provisioning_data, 1);
+ if (entry == NULL)
+ goto finish;
+
+ entry->proto = OFONO_GPRS_PROTO_IP;
+ entry->type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
+ entry->name = g_strdup("Phonesim Internet");
+ entry->apn = g_strdup("internetapn");
+ settings = g_slist_prepend(settings, entry);
+
+finish:
+ g_free(spn);
+
+ if (req->cb != NULL)
+ req->cb(settings, req->userdata);
+
+ g_free(req);
+}
+
+
+
+static void example_gprs_provision_get_settings(
+ struct ofono_modem *modem,
+ ofono_gprs_provision_cb_t cb,
+ void *userdata)
+{
+ struct provisioning_request *req;
+ struct ofono_atom *sim_atom;
+ struct ofono_sim *sim = NULL;
+
+ ofono_debug("Provisioning...");
+
+ req = g_try_new0(struct provisioning_request, 1);
+ if (req == NULL)
+ goto error;
+
+ req->modem = modem;
+ req->cb = cb;
+ req->userdata = userdata;
+
+ /* Start SPN query from SIM */
+ sim_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SIM);
+
+ if (sim_atom != NULL)
+ sim = __ofono_atom_get_data(sim_atom);
+
+ if (sim != NULL) {
+ ofono_sim_read(sim, SIM_EFSPN_FILEID,
+ OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+ sim_spn_read_cb, req);
+ return;
+ }
+
+error:
+ if (cb != NULL)
+ cb(NULL, userdata);
+}
+
+
+static struct ofono_gprs_provision_driver example_driver = {
+ .name = "Example GPRS context provisioning",
+ .priority = OFONO_PLUGIN_PRIORITY_LOW,
+ .get_settings = example_gprs_provision_get_settings,
+};
+
+static int example_gprs_provision_init(void)
+{
+ return ofono_gprs_provision_driver_register(&example_driver);
+}
+
+static void example_gprs_provision_exit(void)
+{
+ ofono_gprs_provision_driver_unregister(&example_driver);
+}
+
+OFONO_PLUGIN_DEFINE(example_gprs_provision, "Example Network Time Plugin",
+ VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
+ example_gprs_provision_init,
+ example_gprs_provision_exit)
--
1.7.1
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono