[PATCH] isiusb: add message-waiting

2011-03-03 Thread Jukka Saunamaki
---
 plugins/isiusb.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/plugins/isiusb.c b/plugins/isiusb.c
index c036604..cf31756 100644
--- a/plugins/isiusb.c
+++ b/plugins/isiusb.c
@@ -54,6 +54,7 @@
 #include ofono/radio-settings.h
 #include ofono/gprs.h
 #include ofono/gprs-context.h
+#include ofono/message-waiting.h
 
 #include drivers/isimodem/isimodem.h
 #include drivers/isimodem/isiutil.h
@@ -421,6 +422,7 @@ static void isiusb_post_sim(struct ofono_modem *modem)
 static void isiusb_post_online(struct ofono_modem *modem)
 {
struct isi_data *isi = ofono_modem_get_data(modem);
+   struct ofono_message_waiting *mw;
 
DBG((%p) with %s, modem, isi-ifname);
 
@@ -434,6 +436,9 @@ static void isiusb_post_online(struct ofono_modem *modem)
ofono_call_barring_create(modem, 0, isimodem, isi-modem);
ofono_call_meter_create(modem, 0, isimodem, isi-modem);
ofono_gprs_create(modem, 0, isimodem, isi-modem);
+   mw = ofono_message_waiting_create(modem);
+   if (mw)
+   ofono_message_waiting_register(mw);
 }
 
 static int isiusb_enable(struct ofono_modem *modem)
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH] Gprs context settings provisioning plugin

2011-02-10 Thread Jukka Saunamaki
---
 Makefile.am|3 +
 plugins/context-provisioning.c |  418 
 2 files changed, 421 insertions(+), 0 deletions(-)
 create mode 100644 plugins/context-provisioning.c

diff --git a/Makefile.am b/Makefile.am
index 42ad86f..18938b6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -347,6 +347,9 @@ builtin_sources += plugins/smart-messaging.c
 builtin_modules += push_notification
 builtin_sources += plugins/push-notification.c
 
+builtin_modules += context_provisioning
+builtin_sources += plugins/context-provisioning.c
+
 sbin_PROGRAMS = src/ofonod
 
 src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) src/ofono.ver \
diff --git a/plugins/context-provisioning.c b/plugins/context-provisioning.c
new file mode 100644
index 000..4dcb373
--- /dev/null
+++ b/plugins/context-provisioning.c
@@ -0,0 +1,418 @@
+/*
+ *
+ *  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 stdlib.h
+#include string.h
+#include glib.h
+
+#include errno.h
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+
+#include ofono.h
+#include ofono/modem.h
+#include ofono/gprs-provision.h
+#include ofono/types.h
+#include ofono/plugin.h
+#include ofono/log.h
+
+#define OPERATOR_SETTINGS_DIR operator-settings
+
+struct parser_data {
+   const gchar *mcc;
+   const gchar *mnc;
+   GSList *candidates;
+};
+
+struct candidate_data {
+   struct ofono_gprs_provision_data *entry;
+   gchar *spn;
+};
+
+static void candidate_data_free(struct candidate_data *cand)
+{
+   if (cand == NULL)
+   return;
+
+   if (cand-entry)
+   __ofono_gprs_provision_free_settings(cand-entry, 1);
+
+   g_free(cand-spn);
+   g_free(cand);
+}
+
+static enum ofono_gprs_context_type string_to_gprs_context_type(const char 
*str)
+{
+   if (str != NULL) {
+   if (strcasecmp(str, internet) == 0)
+   return OFONO_GPRS_CONTEXT_TYPE_INTERNET;
+   if (strcasecmp(str, mms) == 0)
+   return OFONO_GPRS_CONTEXT_TYPE_MMS;
+   if (strcasecmp(str, wap) == 0)
+   return OFONO_GPRS_CONTEXT_TYPE_WAP;
+   if (strcasecmp(str, ims) == 0)
+   return OFONO_GPRS_CONTEXT_TYPE_IMS;
+   }
+
+   return OFONO_GPRS_CONTEXT_TYPE_ANY;
+}
+
+static enum ofono_gprs_proto string_to_gprs_proto(const char *str)
+{
+   if (str != NULL) {
+   if (strcasecmp(str, ipv6) == 0)
+   return OFONO_GPRS_PROTO_IPV6;
+   if (strcasecmp(str, ipv4v6) == 0)
+   return OFONO_GPRS_PROTO_IPV6; // FIXME when possible
+   }
+
+   return OFONO_GPRS_PROTO_IP;
+}
+
+static struct candidate_data *candidate_data_new(const char *spn,
+   const struct ofono_gprs_provision_data *data)
+{
+   struct candidate_data *cand;
+   cand = g_try_malloc0(sizeof(*cand));
+   if (cand == NULL)
+   return NULL;
+
+   cand-entry = g_try_malloc0(sizeof(*cand-entry));
+   if (cand-entry == NULL) {
+   g_free(cand);
+   return NULL;
+   }
+
+   cand-spn = g_strdup(spn);
+   cand-entry-type = data-type;
+   cand-entry-apn = g_strdup(data-apn);
+   cand-entry-name = g_strdup(data-name);
+   cand-entry-username = g_strdup(data-username);
+   cand-entry-password = g_strdup(data-password);
+   cand-entry-proto = data-proto;
+   cand-entry-message_proxy = g_strdup(data-message_proxy);
+   cand-entry-message_center = g_strdup(data-message_center);
+
+   return cand;
+}
+
+/*
+ * Parse access element.
+ * Mandatory attributes in access: mcc, mnc, type, name
+ * If MCC/MNC matches, add entry to candidate entry list.
+ */
+static void settings_start_element_handler (GMarkupParseContext *context,
+   const gchar *element_name,
+   const gchar **attribute_names,
+   const gchar **attribute_values,
+   gpointer user_data,
+  

[PATCH 0/3] gprs-provision: Add SPN to provision API

2011-02-08 Thread Jukka Saunamaki
Hello

This patchset adds Service Provider Name (SPN) into GPRS context provisioning 
API.
SPN is read (asynchronously) in the middle of gprs atom registration, if 
provisioning is needed.

--Jukka

Jukka Saunamaki (3):
  gprs-provision: add SPN to provisioning API header
  gprs,gprs-provision: add SPN to provisioning API
  gprs-provision: update example with SPN

 examples/provision.c |8 +++--
 include/gprs-provision.h |2 +-
 src/gprs-provision.c |4 +-
 src/gprs.c   |   87 ++---
 src/ofono.h  |2 +-
 5 files changed, 74 insertions(+), 29 deletions(-)


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/3] gprs-provision: add SPN to provisioning API header

2011-02-08 Thread Jukka Saunamaki
---
 include/gprs-provision.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/gprs-provision.h b/include/gprs-provision.h
index bc021a8..e9eec61 100644
--- a/include/gprs-provision.h
+++ b/include/gprs-provision.h
@@ -42,7 +42,7 @@ struct ofono_gprs_provision_data {
 struct ofono_gprs_provision_driver {
const char *name;
int priority;
-   int (*get_settings)(const char *mcc, const char *mnc,
+   int (*get_settings)(const char *mcc, const char *mnc, const char *spn,
struct ofono_gprs_provision_data **settings,
int *count);
 };
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/3] gprs,gprs-provision: add SPN to provisioning API

2011-02-08 Thread Jukka Saunamaki
---
 src/gprs-provision.c |4 +-
 src/gprs.c   |   87 +
 src/ofono.h  |2 +-
 3 files changed, 68 insertions(+), 25 deletions(-)

diff --git a/src/gprs-provision.c b/src/gprs-provision.c
index 3cd84e8..011d5a8 100644
--- a/src/gprs-provision.c
+++ b/src/gprs-provision.c
@@ -48,7 +48,7 @@ void  __ofono_gprs_provision_free_settings(
 }
 
 ofono_bool_t __ofono_gprs_provision_get_settings(const char *mcc,
-   const char *mnc,
+   const char *mnc, const char *spn,
struct ofono_gprs_provision_data **settings,
int *count)
 {
@@ -65,7 +65,7 @@ ofono_bool_t __ofono_gprs_provision_get_settings(const char 
*mcc,
 
DBG(Calling provisioning plugin '%s', driver-name);
 
-   if (driver-get_settings(mcc, mnc, settings, count)  0)
+   if (driver-get_settings(mcc, mnc, spn, settings, count)  0)
continue;
 
return TRUE;
diff --git a/src/gprs.c b/src/gprs.c
index 5ea864c..bb1b173 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -97,6 +97,7 @@ struct ofono_gprs {
const struct ofono_gprs_driver *driver;
void *driver_data;
struct ofono_atom *atom;
+   struct ofono_sim_context *sim_context;
 };
 
 struct ofono_gprs_context {
@@ -2291,6 +2292,9 @@ static void gprs_remove(struct ofono_atom *atom)
if (gprs-driver  gprs-driver-remove)
gprs-driver-remove(gprs);
 
+   if (gprs-sim_context)
+   ofono_sim_context_free(gprs-sim_context);
+
g_free(gprs);
 }
 
@@ -2627,14 +2631,14 @@ static void provision_context(const struct 
ofono_gprs_provision_data *ap,
gprs-contexts = g_slist_append(gprs-contexts, context);
 }
 
-static void provision_contexts(struct ofono_gprs *gprs, struct ofono_sim *sim)
+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(ofono_sim_get_mcc(sim),
-   ofono_sim_get_mnc(sim),
+   if (__ofono_gprs_provision_get_settings(mcc, mnc, spn,
settings, count) == FALSE) {
ofono_warn(Provisioning failed);
return;
@@ -2646,13 +2650,15 @@ static void provision_contexts(struct ofono_gprs *gprs, 
struct ofono_sim *sim)
__ofono_gprs_provision_free_settings(settings, count);
 }
 
-void ofono_gprs_register(struct ofono_gprs *gprs)
+static void ofono_gprs_finish_register(struct ofono_gprs *gprs)
 {
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(gprs-atom);
const char *path = __ofono_atom_get_path(gprs-atom);
struct ofono_atom *netreg_atom;
-   struct ofono_atom *sim_atom;
+
+   if (gprs-contexts == NULL) /* Automatic provisioning failed */
+   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
 
if (!g_dbus_register_interface(conn, path,
OFONO_CONNECTION_MANAGER_INTERFACE,
@@ -2661,29 +2667,13 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
ofono_error(Could not create %s interface,
OFONO_CONNECTION_MANAGER_INTERFACE);
 
+   gprs_unregister(gprs-atom);
return;
}
 
ofono_modem_add_interface(modem,
OFONO_CONNECTION_MANAGER_INTERFACE);
 
-   sim_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SIM);
-
-   if (sim_atom) {
-   const char *imsi;
-   struct ofono_sim *sim = __ofono_atom_get_data(sim_atom);
-
-   imsi = ofono_sim_get_imsi(sim);
-   gprs_load_settings(gprs, imsi);
-
-   if (gprs-contexts == NULL)
-   provision_contexts(gprs, sim);
-
-   }
-
-   if (gprs-contexts == NULL)
-   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
-
gprs-netreg_watch = __ofono_modem_add_atom_watch(modem,
OFONO_ATOM_TYPE_NETREG,
netreg_watch, gprs, NULL);
@@ -2697,6 +2687,59 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
__ofono_atom_register(gprs-atom, gprs_unregister);
 }
 
+static void sim_spn_read_cb(int ok, int length, int record,
+   const unsigned char *data,
+   int record_length, void *userdata)
+{
+   struct ofono_gprs *gprs = userdata;
+   char *spn = NULL;
+   struct ofono_atom *sim_atom;
+   struct ofono_sim *sim = NULL;
+
+   if (ok)
+   spn = 

[PATCH 3/3] gprs-provision: update example with SPN

2011-02-08 Thread Jukka Saunamaki
---
 examples/provision.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/examples/provision.c b/examples/provision.c
index 356b0b3..546a161 100644
--- a/examples/provision.c
+++ b/examples/provision.c
@@ -37,6 +37,7 @@
 #include ofono/log.h
 
 static int example_provision_get_settings(const char *mcc, const char *mnc,
+   const char *spn,
struct ofono_gprs_provision_data **settings,
int *count)
 {
@@ -44,10 +45,11 @@ static int example_provision_get_settings(const char *mcc, 
const char *mnc,
*count = 0;
*settings = NULL;
 
-   ofono_debug(Finding settings for MCC %s, MNC %s,
-   mcc, mnc);
+   ofono_debug(Finding settings for MCC %s, MNC %s, SPN '%s',
+   mcc, mnc, spn);
 
-   if (strcmp(mcc, 246) != 0 || strcmp(mnc, 81) != 0)
+   if (strcmp(mcc, 246) != 0 || strcmp(mnc, 81) != 0 ||
+   strcmp(spn, oFono) != 0)
return -ENOENT;
 
ofono_debug(Creating example settings for phonesim);
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH 0/3] EF-SPN API to sim-atom

2011-02-01 Thread Jukka Saunamaki
Hi

On Tue, 2011-02-01 at 22:38 +0200, ext Aki Niemi wrote:
 That reminds me, I think there are SIMs out there that use the CPHS ONS
 instead of SPN, and these can be used interchangeably.
 
 Jukka, don't you actually also need the ONS?

In theory maybe, but in practice so far all cases where operator/service
provider name is needed for provisioning have had SPN.

--Jukka
 

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH 0/3] EF-SPN API to sim-atom

2011-01-30 Thread Jukka Saunamaki
Hello

On Thu, 2011-01-27 at 15:22 +0200, Jukka Saunamaki wrote:
 Here is an asynchronous implementation of SIM Service Provider Name (EF-SPN) 
 getter API.
 The trick is to delay setting sim ready until spn reading is finished.

Any comments about this? 
So, yes, it slightly delays SIM initialisation (usually SPN value should
come from disk cache), but then netreg can use it immediately when it
registers. 
Alternative is still to create an asyncronous API now that there is a
patch for safe SIM file reading.

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 0/3] EF-SPN API to sim-atom

2011-01-27 Thread Jukka Saunamaki
Hello

Here is an asynchronous implementation of SIM Service Provider Name (EF-SPN) 
getter API.
The trick is to delay setting sim ready until spn reading is finished.

Patch to use the new API in netreg is included.

--Jukka

Jukka Saunamaki (3):
  sim: add ofono_sim_get_spn API header
  sim: add ofono_sim_get_spn API implementation
  netreg: use ofono_sim_get_spn()

 include/sim.h |2 +
 src/network.c |   46 +--
 src/sim.c |   73 -
 3 files changed, 81 insertions(+), 40 deletions(-)

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/3] sim: add ofono_sim_get_spn API header

2011-01-27 Thread Jukka Saunamaki
---
 include/sim.h |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 5e3ba5b..7e573fd 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -180,6 +180,8 @@ void *ofono_sim_get_data(struct ofono_sim *sim);
 const char *ofono_sim_get_imsi(struct ofono_sim *sim);
 const char *ofono_sim_get_mcc(struct ofono_sim *sim);
 const char *ofono_sim_get_mnc(struct ofono_sim *sim);
+const char *ofono_sim_get_spn(struct ofono_sim *sim);
+unsigned char ofono_sim_get_spn_dc(struct ofono_sim *sim);
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
 
 enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase(struct ofono_sim *sim);
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 3/3] netreg: use ofono_sim_get_spn()

2011-01-27 Thread Jukka Saunamaki
---
 src/network.c |   46 +++---
 1 files changed, 7 insertions(+), 39 deletions(-)

diff --git a/src/network.c b/src/network.c
index b5450ee..f602db4 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1507,51 +1507,21 @@ static void sim_spdi_read_cb(int ok, int length, int 
record,
}
 }
 
-static void sim_spn_read_cb(int ok, int length, int record,
-   const unsigned char *data,
-   int record_length, void *user_data)
+static void get_spn(struct ofono_netreg *netreg)
 {
-   struct ofono_netreg *netreg = user_data;
unsigned char dcbyte;
-   char *spn;
-
-   if (!ok)
-   return;
-
-   dcbyte = data[0];
+   const char *spn = ofono_sim_get_spn(netreg-sim);
 
-   /*
-* TS 31.102 says:
-*
-* the string shall use:
-*
-* - either the SMS default 7-bit coded alphabet as defined in
-*   TS 23.038 [5] with bit 8 set to 0. The string shall be left
-*   justified. Unused bytes shall be set to 'FF'.
-*
-* - or one of the UCS2 code options defined in the annex of TS
-*   31.101 [11].
-*
-* 31.101 has no such annex though.  51.101 refers to Annex B of
-* itself which is not there either.  11.11 contains the same
-* paragraph as 51.101 and has an Annex B which we implement.
-*/
-   spn = sim_string_to_utf8(data + 1, length - 1);
-   if (spn == NULL) {
-   ofono_error(EFspn read successfully, but couldn't parse);
+   if (spn == NULL)
return;
-   }
 
-   if (strlen(spn) == 0) {
-   g_free(spn);
-   return;
-   }
-
-   netreg-spname = spn;
+   netreg-spname = g_strdup(spn);
ofono_sim_read(netreg-sim, SIM_EFSPDI_FILEID,
OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
sim_spdi_read_cb, netreg);
 
+   dcbyte = ofono_sim_get_spn_dc(netreg-sim);
+
if (dcbyte  SIM_EFSPN_DC_HOME_PLMN_BIT)
netreg-flags |= NETWORK_REGISTRATION_FLAG_HOME_SHOW_PLMN;
 
@@ -1816,9 +1786,7 @@ void ofono_netreg_register(struct ofono_netreg *netreg)
ofono_sim_read(netreg-sim, SIM_EFPNN_FILEID,
OFONO_SIM_FILE_STRUCTURE_FIXED,
sim_pnn_read_cb, netreg);
-   ofono_sim_read(netreg-sim, SIM_EFSPN_FILEID,
-   OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
-   sim_spn_read_cb, netreg);
+   get_spn(netreg);
}
 
__ofono_atom_register(netreg-atom, netreg_unregister);
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: Hi, use qtdbus to access Ofono method

2011-01-27 Thread Jukka Saunamaki
Hi

On Fri, 2011-01-28 at 13:47 +0800, cy xie wrote:
  Has anybody used qtdbus to access Ofono interface?
 I have faced some problem on it, the qdbusinterface create OK, but
 when call the ofono api, it will note the signature doesn't exist.
 please give me some info or show me and example.

Have you checked libofono-qt at
http://meego.gitorious.org/meego-cellular/ofono-qt

--Jukka



___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/5] ofono.h: add gprs-provision

2011-01-26 Thread Jukka Saunamaki
---
 src/ofono.h |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/ofono.h b/src/ofono.h
index e48dbf6..056c7f1 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -420,3 +420,12 @@ void __ofono_nettime_info_received(struct ofono_modem 
*modem,
 
 #include ofono/cdma-voicecall.h
 #include ofono/sim-auth.h
+
+#include ofono/gprs-provision.h
+void __ofono_gprs_provision_get_settings(const char *mcc, const char *mnc,
+   struct ofono_gprs_provision_data **settings,
+   int *count);
+void __ofono_gprs_provision_free_settings(
+   struct ofono_gprs_provision_data *settings,
+   int count);
+
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/5] gprs-provision: add driver API header

2011-01-26 Thread Jukka Saunamaki
---
 Makefile.am  |3 +-
 include/gprs-provision.h |   59 ++
 2 files changed, 61 insertions(+), 1 deletions(-)
 create mode 100644 include/gprs-provision.h

diff --git a/Makefile.am b/Makefile.am
index f941a19..f543135 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,7 +13,8 @@ pkginclude_HEADERS = include/log.h include/plugin.h 
include/history.h \
include/radio-settings.h include/stk.h \
include/audio-settings.h include/nettime.h \
include/ctm.h include/cdma-voicecall.h \
-   include/cdma-sms.h include/sim-auth.h
+   include/cdma-sms.h include/sim-auth.h \
+   include/gprs-provision.h
 
 nodist_pkginclude_HEADERS = include/version.h
 
diff --git a/include/gprs-provision.h b/include/gprs-provision.h
new file mode 100644
index 000..efde892
--- /dev/null
+++ b/include/gprs-provision.h
@@ -0,0 +1,59 @@
+/*
+ *
+ *  oFono - Open Telephony stack for Linux
+ *
+ *  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
+ *
+ */
+
+#ifndef __OFONO_GPRS_PROVISION_H
+#define __OFONO_GPRS_PROVISION_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#include gprs-context.h
+
+struct ofono_gprs_provision_data {
+   enum ofono_gprs_context_type type;
+   enum ofono_gprs_proto proto;
+   char *name;
+   char *apn;
+   char *username;
+   char *password;
+   char *message_proxy;
+   char *message_center;
+};
+
+struct ofono_gprs_provision_driver {
+   const char *name;
+   int priority;
+   void (*get_settings)(const char *mcc, const char *mnc,
+   struct ofono_gprs_provision_data **settings,
+   int *count);
+};
+
+int ofono_gprs_provision_driver_register(
+   const struct ofono_gprs_provision_driver *driver);
+void ofono_gprs_provision_driver_unregister(
+   const struct ofono_gprs_provision_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_GPRS_PROVISION_H */
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 5/5] gprs-provision: add example context provisioning driver

2011-01-26 Thread Jukka Saunamaki
---
 Makefile.am  |3 ++
 examples/provision.c |   95 ++
 2 files changed, 98 insertions(+), 0 deletions(-)
 create mode 100644 examples/provision.c

diff --git a/Makefile.am b/Makefile.am
index 9c4f383..c70dcbf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -329,6 +329,9 @@ builtin_sources += examples/history.c
 
 builtin_modules += example_nettime
 builtin_sources += examples/nettime.c
+
+builtin_modules += example_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 000..80688a4
--- /dev/null
+++ b/examples/provision.c
@@ -0,0 +1,95 @@
+/*
+ *
+ *  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/gprs-provision.h
+#include ofono/types.h
+#include ofono/plugin.h
+#include ofono/log.h
+
+static void example_provision_get_settings(const char *mcc, const char *mnc,
+   struct ofono_gprs_provision_data **settings,
+   int *count)
+{
+   ofono_debug(Provisioning...);
+   *count = 0;
+   *settings = NULL;
+
+   ofono_debug(Finding settings for MCC %s, MNC %s,
+   mcc, mnc);
+
+   if (strcmp(mcc, 246) != 0 || strcmp(mnc, 81) != 0)
+   return;
+
+   ofono_debug(Creating example settings for phonesim);
+
+   *settings = g_try_new0(struct ofono_gprs_provision_data, 2);
+   if (*settings == NULL)
+   return;
+
+   *count = 2;
+
+   /* Internet context settings */
+   (*settings)[0].proto = OFONO_GPRS_PROTO_IP;
+   (*settings)[0].type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
+   (*settings)[0].name = g_strdup(Phonesim Internet);
+   (*settings)[0].apn = g_strdup(internetapn);
+
+   /* MMS context settings */
+   (*settings)[1].proto = OFONO_GPRS_PROTO_IP;
+   (*settings)[1].type = OFONO_GPRS_CONTEXT_TYPE_MMS;
+   (*settings)[1].name = g_strdup(Phonesim MMS);
+   (*settings)[1].apn = g_strdup(mmsapn);
+   (*settings)[1].username = g_strdup(mmsuser);
+   (*settings)[1].password = g_strdup(mmspass);
+   (*settings)[1].message_proxy = g_strdup(10.11.12.13:8080);
+   (*settings)[1].message_center = g_strdup(http://mms.example.com:8000;);
+}
+
+static struct ofono_gprs_provision_driver example_driver = {
+   .name   = Example GPRS context provisioning,
+   .priority   = OFONO_PLUGIN_PRIORITY_LOW,
+   .get_settings   = example_provision_get_settings,
+};
+
+static int example_provision_init(void)
+{
+   return ofono_gprs_provision_driver_register(example_driver);
+}
+
+static void example_provision_exit(void)
+{
+   ofono_gprs_provision_driver_unregister(example_driver);
+}
+
+OFONO_PLUGIN_DEFINE(example_provision, Example Provisioning Plugin,
+   VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
+   example_provision_init,
+   example_provision_exit)
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 4/5] gprs: add gprs context provisioning

2011-01-26 Thread Jukka Saunamaki
---
 src/gprs.c |   99 +--
 1 files changed, 95 insertions(+), 4 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 92d0b1a..7fad23b 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -43,6 +43,8 @@
 #include common.h
 #include storage.h
 #include idmap.h
+#include simutil.h
+#include util.h
 
 #define GPRS_FLAG_ATTACHING 0x1
 #define GPRS_FLAG_RECHECK 0x2
@@ -2531,6 +2533,75 @@ 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 || ap-name == NULL)
+   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);
+   DBG(%s context%d '%s' %s, gprs_context_default_name(ap-type),
+   id, ap-name, context ? created : creation failed);
+
+   if (context == NULL)
+   return;
+
+   context-id = id;
+
+   if (ap-username != NULL)
+   strncpy(context-context.username, ap-username,
+   OFONO_GPRS_MAX_USERNAME_LENGTH);
+
+   if (ap-password != NULL)
+   strncpy(context-context.password, ap-password,
+   OFONO_GPRS_MAX_PASSWORD_LENGTH);
+
+   if (ap-apn != NULL)
+   strncpy(context-context.apn, ap-apn,
+   OFONO_GPRS_MAX_APN_LENGTH);
+
+   context-context.proto = ap-proto;
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-message_proxy != NULL)
+   strncpy(context-message_proxy, ap-message_proxy,
+   MAX_MESSAGE_PROXY_LENGTH);
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-message_center != NULL)
+   strncpy(context-message_center, ap-message_center,
+   MAX_MESSAGE_CENTER_LENGTH);
+
+   if (context_dbus_register(context) == TRUE) {
+   gprs-last_context_id = id;
+   gprs-contexts = g_slist_append(gprs-contexts, context);
+   write_context_settings(gprs, context);
+
+   if (context-type == OFONO_GPRS_CONTEXT_TYPE_MMS) {
+   g_key_file_set_string(gprs-settings, context-key,
+   MessageProxy,
+   context-message_proxy);
+   g_key_file_set_string(gprs-settings, context-key,
+   MessageCenter,
+   context-message_center);
+   }
+
+   storage_sync(gprs-imsi, SETTINGS_STORE, gprs-settings);
+   }
+}
+
 void ofono_gprs_register(struct ofono_gprs *gprs)
 {
DBusConnection *conn = ofono_dbus_get_connection();
@@ -2538,6 +2609,7 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
const char *path = __ofono_atom_get_path(gprs-atom);
struct ofono_atom *netreg_atom;
struct ofono_atom *sim_atom;
+   struct ofono_sim *sim = NULL;
 
if (!g_dbus_register_interface(conn, path,
OFONO_CONNECTION_MANAGER_INTERFACE,
@@ -2555,14 +2627,33 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
sim_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SIM);
 
if (sim_atom) {
-   struct ofono_sim *sim = __ofono_atom_get_data(sim_atom);
-   const char *imsi = ofono_sim_get_imsi(sim);
+   const char *imsi;
 
+   sim = __ofono_atom_get_data(sim_atom);
+   imsi = ofono_sim_get_imsi(sim);
gprs_load_settings(gprs, imsi);
}
 
-   if (gprs-contexts == NULL)
-   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
+   if (gprs-contexts == NULL) {
+   struct ofono_gprs_provision_data *settings = NULL;
+   int count = 0;
+   int i;
+
+   __ofono_gprs_provision_get_settings(ofono_sim_get_mcc(sim),
+   ofono_sim_get_mnc(sim),
+   settings, count);
+
+   if (count  0) {
+   for (i = 0; i  count; i++)
+   provision_context(settings[i], gprs);
+
+   __ofono_gprs_provision_free_settings(settings, count);
+   } else {
+   ofono_warn(Context settings provisioning failed);
+   add_context(gprs, NULL,
+

[PATCH 3/5] gprs-provision: add driver API sources

2011-01-26 Thread Jukka Saunamaki
---
 Makefile.am  |2 +-
 src/gprs-provision.c |  104 ++
 2 files changed, 105 insertions(+), 1 deletions(-)
 create mode 100644 src/gprs-provision.c

diff --git a/Makefile.am b/Makefile.am
index f543135..9c4f383 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -356,7 +356,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) 
src/ofono.ver \
src/simfs.c src/simfs.h src/audio-settings.c \
src/smsagent.c src/smsagent.h src/ctm.c \
src/cdma-voicecall.c src/sim-auth.c \
-   src/message.h src/message.c
+   src/message.h src/message.c src/gprs-provision.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/src/gprs-provision.c b/src/gprs-provision.c
new file mode 100644
index 000..cc1f589
--- /dev/null
+++ b/src/gprs-provision.c
@@ -0,0 +1,104 @@
+/*
+ *
+ *  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
+#include ofono.h
+
+static GSList *g_drivers = NULL;
+
+void  __ofono_gprs_provision_free_settings(
+   struct ofono_gprs_provision_data *settings,
+   int count)
+{
+   int i;
+
+   for (i = 0; i  count; i++) {
+   g_free(settings[i].name);
+   g_free(settings[i].apn);
+   g_free(settings[i].username);
+   g_free(settings[i].password);
+   g_free(settings[i].message_proxy);
+   g_free(settings[i].message_center);
+   }
+
+   g_free(settings);
+}
+
+void __ofono_gprs_provision_get_settings(const char *mcc, const char *mnc,
+   struct ofono_gprs_provision_data **settings,
+   int *count)
+{
+   GSList *d;
+
+   *settings = NULL;
+   *count = 0;
+
+   if (mcc == NULL || strlen(mcc) == 0 || mnc == NULL || strlen(mnc) == 0)
+   return;
+
+   for (d = g_drivers; d != NULL; d = d-next) {
+   const struct ofono_gprs_provision_driver *driver = d-data;
+
+   DBG(Calling provisioning plugin '%s', driver-name);
+
+   driver-get_settings(mcc, mnc, settings, count);
+
+   if (*count  0) {
+   DBG(Plugin '%s' returned %d context settings,
+   driver-name, *count);
+   return;
+   }
+
+   ofono_warn(Provisioning plugin '%s' returned no settings,
+   driver-name);
+   }
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+   const struct ofono_gprs_provision_driver *plugin1 = a;
+   const struct ofono_gprs_provision_driver *plugin2 = b;
+
+   return plugin2-priority - plugin1-priority;
+}
+
+int ofono_gprs_provision_driver_register(
+   const struct ofono_gprs_provision_driver *driver)
+{
+   DBG(driver: %p name: %s, driver, driver-name);
+
+   g_drivers = g_slist_insert_sorted(g_drivers, (void *) driver,
+   compare_priority);
+   return 0;
+}
+
+void ofono_gprs_provision_driver_unregister(
+   const struct ofono_gprs_provision_driver *driver)
+{
+   DBG(driver: %p name: %s, driver, driver-name);
+
+   g_drivers = g_slist_remove(g_drivers, driver);
+}
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[gprs-provision PATCHv7 0/5] Plugin API for provisioning of GPRS context settings

2011-01-26 Thread Jukka Saunamaki
Hello

And again a patchset about automatic provisioning of GPRS context settings.

Since the safe reading of EF-SPN turned out to be impossible until general 
solution is implemented, I must temporary give up my insistence on it.

So the following provisioning driver API must be considered as provisional. 
When proper solution for SPN comes up, we should redesign the API. Without SPN, 
correct settings cannot be provisioned for all service providers, but at least 
for now most cases should work with just the MCC and MNC values provided with 
this API.


--Jukka

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [gprs-provision PATCHv7 0/5] Plugin API for provisioning of GPRS context settings

2011-01-26 Thread Jukka Saunamaki
Hello Denis,

On Wed, 2011-01-26 at 14:56 -0600, ext Denis Kenzior wrote:
  And again a patchset about automatic provisioning of GPRS context settings.
  
  Since the safe reading of EF-SPN turned out to be impossible until general 
  solution is implemented, I must temporary give up my insistence on it.
  
  So the following provisioning driver API must be considered as provisional. 
  When proper solution for SPN comes up, we should redesign the API. Without 
  SPN, correct settings cannot be provisioned for all service providers, but 
  at least for now most cases should work with just the MCC and MNC values 
  provided with this API.
  
 
 I've applied all of your patches but have refactored them heavily
 afterward.  Let me know if I broke anything.

Excellent. Seems to work OK, thanks.

So, now while waiting for some solution to SIM reading issue, I can
start looking at proper provisioning plugin. And looking forward to
interesting discussions regarding merits of various XML-file formats for
settings database...

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: EF-SPN API (was: [gprs-provision PATCHv7 0/5] Plugin API for provisioning of GPRS context settings)

2011-01-26 Thread Jukka Saunamaki
Hi Marcel,

On Thu, 2011-01-27 at 08:37 +0100, ext Marcel Holtmann wrote:
   you can have a look on what it would take to store a) read SPN in the
   SIM atom and store it and b) let netreg atom use that value.
  
  Simple solution for this would be something like:
  ... 
 don't make this asynchronous. Just read the SPN and store it. Then it
 can be easily accessed similar to MCC and MNC.
 
 The GPRS atom and netreg for that matter will not be available before
 the SIM atom has been fully initialized anyway.
 
 If there is any race condition with this one, the we need to be really
 really careful since it has a lot of consequences.

This is the hard part of this, how to be sure SPN reading is ready early
enough. I am not yet familiar enough with SIM initialisation to say how
to do it. But I can start looking at it.

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[gprs-provision RFCPATCHv6 0/4] Plugin API for provisioning of GPRS context settings

2011-01-25 Thread Jukka Saunamaki
Hello

Another patchset about automatic provisioning of GPRS context settings.

This time, provisioning driver API is synchronous, and 
__ofono_gprs_provision_get_settings includes MCC,MNC and SPN as in parameters. 
Per modem probing and all related complexity was removed, since there was 
really no need for it. 

It is now the gprs-atom that queries SPN from SIM before calling provisioning. 
Cases when gprs-atom is unregistered or removed while SPN query is in progress, 
should be handled gracefully (unlike e.g. in netreg atom...)


--Jukka Saunamäki

Jukka Saunamaki (4):
  gprs-provision: add driver API header
  gprs-provision: add driver API sources
  gprs: add gprs context provisioning
  gprs-provision: add example context provisioning driver

 Makefile.am  |8 ++-
 examples/provision.c |   97 ++
 include/gprs-provision.h |   69 ++
 src/gprs-provision.c |  104 
 src/gprs.c   |  172 +++---
 5 files changed, 438 insertions(+), 12 deletions(-)
 create mode 100644 examples/provision.c
 create mode 100644 include/gprs-provision.h
 create mode 100644 src/gprs-provision.c


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/4] gprs-provision: add driver API header

2011-01-25 Thread Jukka Saunamaki
---
 Makefile.am  |3 +-
 include/gprs-provision.h |   69 ++
 2 files changed, 71 insertions(+), 1 deletions(-)
 create mode 100644 include/gprs-provision.h

diff --git a/Makefile.am b/Makefile.am
index f941a19..f543135 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,7 +13,8 @@ pkginclude_HEADERS = include/log.h include/plugin.h 
include/history.h \
include/radio-settings.h include/stk.h \
include/audio-settings.h include/nettime.h \
include/ctm.h include/cdma-voicecall.h \
-   include/cdma-sms.h include/sim-auth.h
+   include/cdma-sms.h include/sim-auth.h \
+   include/gprs-provision.h
 
 nodist_pkginclude_HEADERS = include/version.h
 
diff --git a/include/gprs-provision.h b/include/gprs-provision.h
new file mode 100644
index 000..cc9f5b5
--- /dev/null
+++ b/include/gprs-provision.h
@@ -0,0 +1,69 @@
+/*
+ *
+ *  oFono - Open Telephony stack for Linux
+ *
+ *  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
+ *
+ */
+
+#ifndef __OFONO_GPRS_PROVISION_H
+#define __OFONO_GPRS_PROVISION_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#include gprs-context.h
+
+struct ofono_gprs_provision_data {
+   enum ofono_gprs_context_type type;
+   enum ofono_gprs_proto proto;
+   char *name;
+   char *apn;
+   char *username;
+   char *password;
+   char *message_proxy;
+   char *message_center;
+};
+
+struct ofono_gprs_provision_driver {
+   const char *name;
+   int priority;
+   void (*get_settings)(const char *mcc, const char *mnc, const char *spn,
+   struct ofono_gprs_provision_data **settings,
+   int *count);
+};
+
+int ofono_gprs_provision_driver_register(
+   const struct ofono_gprs_provision_driver *driver);
+void ofono_gprs_provision_driver_unregister(
+   const struct ofono_gprs_provision_driver *driver);
+
+/* For gprs */
+void __ofono_gprs_provision_get_settings(const char *mcc, const char *mnc,
+   const char *spn,
+   struct ofono_gprs_provision_data **settings,
+   int *count);
+void provision_settings_free(struct ofono_gprs_provision_data *settings,
+   int count);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_GPRS_PROVISION_H */
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 3/4] gprs: add gprs context provisioning

2011-01-25 Thread Jukka Saunamaki
---
 src/gprs.c |  172 
 1 files changed, 162 insertions(+), 10 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 92d0b1a..3e281e5 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -44,6 +44,11 @@
 #include storage.h
 #include idmap.h
 
+#include sim.h
+#include simutil.h
+#include util.h
+#include gprs-provision.h
+
 #define GPRS_FLAG_ATTACHING 0x1
 #define GPRS_FLAG_RECHECK 0x2
 
@@ -95,6 +100,7 @@ struct ofono_gprs {
const struct ofono_gprs_driver *driver;
void *driver_data;
struct ofono_atom *atom;
+   struct spn_read_request *reading_spn;
 };
 
 struct ofono_gprs_context {
@@ -135,6 +141,12 @@ struct pri_context {
struct ofono_gprs *gprs;
 };
 
+struct spn_read_request {
+   struct ofono_gprs *gprs;
+   char mcc[OFONO_MAX_MCC_LENGTH + 1];
+   char mnc[OFONO_MAX_MNC_LENGTH + 1];
+};
+
 static void gprs_netreg_update(struct ofono_gprs *gprs);
 static void gprs_deactivate_next(struct ofono_gprs *gprs);
 
@@ -2251,10 +2263,15 @@ static void gprs_unregister(struct ofono_atom *atom)
gprs-netreg = NULL;
}
 
-   ofono_modem_remove_interface(modem,
+   if (gprs-reading_spn == NULL) {
+   ofono_modem_remove_interface(modem,
OFONO_CONNECTION_MANAGER_INTERFACE);
-   g_dbus_unregister_interface(conn, path,
+   g_dbus_unregister_interface(conn, path,
OFONO_CONNECTION_MANAGER_INTERFACE);
+   } else {
+   gprs-reading_spn-gprs = NULL;
+   gprs-reading_spn = NULL;
+   }
 }
 
 static void gprs_remove(struct ofono_atom *atom)
@@ -2279,6 +2296,9 @@ static void gprs_remove(struct ofono_atom *atom)
if (gprs-driver  gprs-driver-remove)
gprs-driver-remove(gprs);
 
+   if (gprs-reading_spn != NULL)
+   gprs-reading_spn-gprs = NULL;
+
g_free(gprs);
 }
 
@@ -2531,13 +2551,14 @@ remove:
storage_sync(imsi, SETTINGS_STORE, gprs-settings);
 }
 
-void ofono_gprs_register(struct ofono_gprs *gprs)
+static void ofono_gprs_finish_register(struct ofono_gprs *gprs)
 {
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(gprs-atom);
const char *path = __ofono_atom_get_path(gprs-atom);
-   struct ofono_atom *netreg_atom;
-   struct ofono_atom *sim_atom;
+
+   if (gprs-contexts == NULL) /* Automatic provisioning failed */
+   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
 
if (!g_dbus_register_interface(conn, path,
OFONO_CONNECTION_MANAGER_INTERFACE,
@@ -2546,24 +2567,134 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
ofono_error(Could not create %s interface,
OFONO_CONNECTION_MANAGER_INTERFACE);
 
+   gprs_unregister(gprs-atom);
return;
}
 
ofono_modem_add_interface(modem,
OFONO_CONNECTION_MANAGER_INTERFACE);
+}
+
+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 || ap-name == NULL)
+   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);
+   DBG(%s context%d '%s' %s, gprs_context_default_name(ap-type),
+   id, ap-name, context ? created : creation failed);
+
+   if (context == NULL)
+   return;
+
+   context-id = id;
+
+   if (ap-username != NULL)
+   strncpy(context-context.username, ap-username,
+   OFONO_GPRS_MAX_USERNAME_LENGTH);
+
+   if (ap-password != NULL)
+   strncpy(context-context.password, ap-password,
+   OFONO_GPRS_MAX_PASSWORD_LENGTH);
+
+   if (ap-apn != NULL)
+   strncpy(context-context.apn, ap-apn,
+   OFONO_GPRS_MAX_APN_LENGTH);
+
+   context-context.proto = ap-proto;
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-message_proxy != NULL)
+   strncpy(context-message_proxy, ap-message_proxy,
+   MAX_MESSAGE_PROXY_LENGTH);
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-message_center != NULL)
+   strncpy(context-message_center, ap-message_center,
+   MAX_MESSAGE_CENTER_LENGTH);
+
+   if (context_dbus_register(context) == TRUE) {
+   

[PATCH 2/4] gprs-provision: add driver API sources

2011-01-25 Thread Jukka Saunamaki
---
 Makefile.am  |2 +-
 src/gprs-provision.c |  104 ++
 2 files changed, 105 insertions(+), 1 deletions(-)
 create mode 100644 src/gprs-provision.c

diff --git a/Makefile.am b/Makefile.am
index f543135..9c4f383 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -356,7 +356,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) 
src/ofono.ver \
src/simfs.c src/simfs.h src/audio-settings.c \
src/smsagent.c src/smsagent.h src/ctm.c \
src/cdma-voicecall.c src/sim-auth.c \
-   src/message.h src/message.c
+   src/message.h src/message.c src/gprs-provision.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/src/gprs-provision.c b/src/gprs-provision.c
new file mode 100644
index 000..75af59b
--- /dev/null
+++ b/src/gprs-provision.c
@@ -0,0 +1,104 @@
+/*
+ *
+ *  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 stdlib.h
+#include glib.h
+
+#include ofono.h
+#include gprs-provision.h
+
+static GSList *g_drivers = NULL;
+
+
+void provision_settings_free(struct ofono_gprs_provision_data *settings,
+   int count)
+{
+   int i;
+
+   for (i = 0; i  count; i++) {
+   g_free(settings[i].name);
+   g_free(settings[i].apn);
+   g_free(settings[i].username);
+   g_free(settings[i].password);
+   g_free(settings[i].message_proxy);
+   g_free(settings[i].message_center);
+   }
+
+   g_free(settings);
+}
+
+void __ofono_gprs_provision_get_settings(const char *mcc, const char *mnc,
+   const char *spn,
+   struct ofono_gprs_provision_data **settings,
+   int *count)
+{
+   GSList *d;
+
+   *settings = NULL;
+   *count = 0;
+
+   for (d = g_drivers; d != NULL; d = d-next) {
+   const struct ofono_gprs_provision_driver *driver = d-data;
+
+   DBG(Calling provisioning plugin '%s', driver-name);
+
+   driver-get_settings(mcc, mnc, spn, settings, count);
+
+   if (*count  0) {
+   DBG(Plugin '%s' returned %d context settings,
+   driver-name, *count);
+   return;
+   }
+
+   ofono_warn(Provisioning plugin '%s' returned no settings,
+   driver-name);
+   }
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+   const struct ofono_gprs_provision_driver *plugin1 = a;
+   const struct ofono_gprs_provision_driver *plugin2 = b;
+
+   return plugin2-priority - plugin1-priority;
+}
+
+int ofono_gprs_provision_driver_register(
+   const struct ofono_gprs_provision_driver *driver)
+{
+   DBG(driver: %p name: %s, driver, driver-name);
+
+   g_drivers = g_slist_insert_sorted(g_drivers, (void *) driver,
+   compare_priority);
+   return 0;
+}
+
+void ofono_gprs_provision_driver_unregister(
+   const struct ofono_gprs_provision_driver *driver)
+{
+   DBG(driver: %p name: %s, driver, driver-name);
+
+   g_drivers = g_slist_remove(g_drivers, driver);
+}
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 4/4] gprs-provision: add example context provisioning driver

2011-01-25 Thread Jukka Saunamaki
---
 Makefile.am  |3 ++
 examples/provision.c |   97 ++
 2 files changed, 100 insertions(+), 0 deletions(-)
 create mode 100644 examples/provision.c

diff --git a/Makefile.am b/Makefile.am
index 9c4f383..c70dcbf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -329,6 +329,9 @@ builtin_sources += examples/history.c
 
 builtin_modules += example_nettime
 builtin_sources += examples/nettime.c
+
+builtin_modules += example_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 000..5a6103b
--- /dev/null
+++ b/examples/provision.c
@@ -0,0 +1,97 @@
+/*
+ *
+ *  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/gprs-provision.h
+#include ofono/types.h
+
+#include ofono.h
+
+static void example_provision_get_settings(const char *mcc, const char *mnc,
+   const char *spn,
+   struct ofono_gprs_provision_data **settings,
+   int *count)
+{
+   ofono_debug(Provisioning...);
+   *count = 0;
+   *settings = NULL;
+
+   ofono_debug(Finding settings for MCC %s, MNC %s, SPN '%s',
+   mcc, mnc, spn);
+
+   if (strcmp(mcc, 246) != 0 || strcmp(mnc, 81) != 0 ||
+   spn == NULL || strcmp(spn, oFono) != 0)
+   return;
+
+   ofono_debug(Creating example settings for phonesim);
+
+   *settings = g_try_new0(struct ofono_gprs_provision_data, 2);
+   if (*settings == NULL)
+   return;
+
+   *count = 2;
+
+   /* Internet context settings */
+   (*settings)[0].proto = OFONO_GPRS_PROTO_IP;
+   (*settings)[0].type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
+   (*settings)[0].name = g_strdup(Phonesim Internet);
+   (*settings)[0].apn = g_strdup(internetapn);
+
+   /* MMS context settings */
+   (*settings)[1].proto = OFONO_GPRS_PROTO_IP;
+   (*settings)[1].type = OFONO_GPRS_CONTEXT_TYPE_MMS;
+   (*settings)[1].name = g_strdup(Phonesim MMS);
+   (*settings)[1].apn = g_strdup(mmsapn);
+   (*settings)[1].username = g_strdup(mmsuser);
+   (*settings)[1].password = g_strdup(mmspass);
+   (*settings)[1].message_proxy = g_strdup(10.11.12.13:8080);
+   (*settings)[1].message_center = g_strdup(http://mms.example.com:8000;);
+}
+
+static struct ofono_gprs_provision_driver example_driver = {
+   .name   = Example GPRS context provisioning,
+   .priority   = OFONO_PLUGIN_PRIORITY_LOW,
+   .get_settings   = example_provision_get_settings,
+};
+
+static int example_provision_init(void)
+{
+   return ofono_gprs_provision_driver_register(example_driver);
+}
+
+static void example_provision_exit(void)
+{
+   ofono_gprs_provision_driver_unregister(example_driver);
+}
+
+OFONO_PLUGIN_DEFINE(example_provision, Example Provisioning Plugin,
+   VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
+   example_provision_init,
+   example_provision_exit)
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [gprs-provision RFCPATCHv6 0/4] Plugin API for provisioning of GPRS context settings

2011-01-25 Thread Jukka Saunamaki
Hi

On Tue, 2011-01-25 at 13:28 +0100, ext Marcel Holtmann wrote:
 I think that our only leftover is how we handle the SPN detail.
 
 Denis, what is your preference here? My take would be that we store it
 inside network registration and provide it to external modules. I don't
 see a point in reading it twice.

New SPN specific API in SIM atom? Asynchronous with callback, but SIM
would need to read it only once.
Unless there is some simple way to start reading it right after SIM is
ready/unlocked and netreg and gprs are registered only after SPN read
returns?

--Jukka




___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: SAT support in oFono

2011-01-24 Thread Jukka Saunamaki
Hello

- BIP (Bearer independent protocol), including commands like OPEN 
CHANNEL, CLOSE CHANNEL, SEND/RECEIVE DATA
  BIP is on many operators' wish list of supported SAT features. Even it
  is optional in 3GPP, some market areas will probably require BIP. I
  don't have an example to give right now.
 
 I think the important phrase is wish list. So far nobody could really
 showed me the exact use case for BIP. I am actually really interested in
 understanding what the operators wanna use it for. I prefer to have hard
 facts here and not just wish list and probably. If this is not a
 requirement for certification and the operator is not actually using
 such a feature at all, then why bother. Feel free to convince me
 otherwise here.

Sorry, still quite anecdotal, but I heard about a case related to RFC
payment system, where operator wants to use BIP for loading payment
application into SIM (I guess SMS-PP-data-download was not good enough
for that). Also, at least some NFC plans use Smart Card Web Server
(SCWS), that needs at least part of BIP.

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[gprs-provision PATCHv5 0/6] Plugin API for provisioning of GPRS context setting

2011-01-20 Thread Jukka Saunamaki
Hello

And again, here is a new patchset about implementing automatic provisioning of 
GPRS context settings.

Since last time, driver API should be cleaner now. Some whitespace issues 
fixed, and probably some new ones introduced :)

Example driver patch requires ofono_sim_get_mcc/mnc in SIM atom API patches, 
that I mailed earlier.

[copy from earlier mail]
Provisioning data for gprs contexts is returned by gprs-provisioning 
plugins/drivers. Different kind of provisioning modules may be created for 
different platforms or use cases.
It is up to the module what settings database it uses, and how many, and what 
type of contexts (with settings) it returns.
Several plugins may be loaded in oFono, and they will be called in priority 
order until first plugin returns non-empty result.

Provisioning modules are called in case there are no previously configured 
contexts found during gprs atom registration.
 
These patches add new gprs-provision.[hc] API for provisioning plugins to 
register into, and __ofono_gprs_provision_get_settings for gprs.c to call when 
needed.
gprs.c is modified to use provisioning if reading existing context settings 
fails.

A dummy example provisioning plugin is included. In case it is called when 
using phonesim with default.xml configuration, the plugin returns dummy 
settings for two contexts, one type Internet and one type MMS. 

--Jukka Saunamäki


Jukka Saunamaki (6):
  gprs-provision: add driver API header
  ofono.h: add new atom type for gprs-provision
  gprs-provision: add driver API sources
  modem: probe gprs_provision drivers
  gprs: add gprs context provisioning
  gprs-provision: add example context provisioning driver

 Makefile.am  |7 +-
 examples/provision.c |  221 ++
 include/gprs-provision.h |   74 +++
 src/gprs-provision.c |  219 +
 src/gprs.c   |  147 ---
 src/modem.c  |1 +
 src/ofono.h  |8 ++
 7 files changed, 661 insertions(+), 16 deletions(-)
 create mode 100644 examples/provision.c
 create mode 100644 include/gprs-provision.h
 create mode 100644 src/gprs-provision.c

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/6] gprs-provision: add driver API header

2011-01-20 Thread Jukka Saunamaki
---
 Makefile.am  |2 +-
 include/gprs-provision.h |   74 ++
 2 files changed, 75 insertions(+), 1 deletions(-)
 create mode 100644 include/gprs-provision.h

diff --git a/Makefile.am b/Makefile.am
index c1c34ca..7a03f08 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,7 +13,7 @@ pkginclude_HEADERS = include/log.h include/plugin.h 
include/history.h \
include/radio-settings.h include/stk.h \
include/audio-settings.h include/nettime.h \
include/ctm.h include/cdma-voicecall.h \
-   include/cdma-sms.h
+   include/cdma-sms.h include/gprs-provision.h
 
 nodist_pkginclude_HEADERS = include/version.h
 
diff --git a/include/gprs-provision.h b/include/gprs-provision.h
new file mode 100644
index 000..cc751d2
--- /dev/null
+++ b/include/gprs-provision.h
@@ -0,0 +1,74 @@
+/*
+ *
+ *  oFono - Open Telephony stack for Linux
+ *
+ *  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
+ *
+ */
+
+#ifndef __OFONO_GPRS_PROVISION_H
+#define __OFONO_GPRS_PROVISION_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#include gprs-context.h
+
+struct ofono_gprs_provision_context {
+   struct ofono_gprs_provision_driver *driver;
+   struct ofono_modem *modem;
+   void *data;
+};
+
+struct ofono_gprs_provision_data {
+   enum ofono_gprs_context_type type;
+   enum ofono_gprs_proto proto;
+   char *name;
+   char *apn;
+   char *username;
+   char *password;
+   char *message_proxy;
+   char *message_center;
+};
+
+/*
+ * Callback from provisioning plugin.
+ */
+typedef void (*ofono_gprs_provision_cb_t)(
+   const struct ofono_gprs_provision_data settings[],
+   int count, void *user_data);
+
+struct ofono_gprs_provision_driver {
+   const char *name;
+   int priority;
+   int (*probe)(struct ofono_gprs_provision_context *context);
+   void (*remove)(struct ofono_gprs_provision_context *context);
+   void (*get_settings)(struct ofono_gprs_provision_context *context,
+   ofono_gprs_provision_cb_t cb,
+   void *user_data);
+};
+
+int ofono_gprs_provision_driver_register(
+   const struct ofono_gprs_provision_driver *driver);
+void ofono_gprs_provision_driver_unregister(
+   const struct ofono_gprs_provision_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_GPRS_PROVISION_H */
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/6] ofono.h: add new atom type for gprs-provision

2011-01-20 Thread Jukka Saunamaki
---
 src/ofono.h |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/ofono.h b/src/ofono.h
index 77567c2..43a703f 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -127,6 +127,7 @@ enum ofono_atom_type {
OFONO_ATOM_TYPE_NETTIME = 21,
OFONO_ATOM_TYPE_CTM = 22,
OFONO_ATOM_TYPE_CDMA_VOICECALL_MANAGER = 23,
+   OFONO_ATOM_TYPE_GPRS_PROVISION = 24,
 };
 
 enum ofono_atom_watch_condition {
@@ -417,4 +418,11 @@ void __ofono_nettime_probe_drivers(struct ofono_modem 
*modem);
 void __ofono_nettime_info_received(struct ofono_modem *modem,
struct ofono_network_time *info);
 
+#include ofono/gprs-provision.h
+
+void __ofono_gprs_provision_probe_drivers(struct ofono_modem *modem);
+
+void __ofono_gprs_provision_get_settings(struct ofono_modem *modem,
+   ofono_gprs_provision_cb_t cb,
+   void *user_data);
 #include ofono/cdma-voicecall.h
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 5/6] gprs: add gprs context provisioning

2011-01-20 Thread Jukka Saunamaki
---
 src/gprs.c |  147 ++--
 1 files changed, 133 insertions(+), 14 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 7ef81d5..06f6555 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -43,6 +43,7 @@
 #include common.h
 #include storage.h
 #include idmap.h
+#include gprs-provision.h
 
 #define GPRS_FLAG_ATTACHING 0x1
 #define GPRS_FLAG_RECHECK 0x2
@@ -83,6 +84,7 @@ struct ofono_gprs {
const struct ofono_gprs_driver *driver;
void *driver_data;
struct ofono_atom *atom;
+   struct provision_request *provision;
 };
 
 struct ofono_gprs_context {
@@ -123,6 +125,10 @@ struct pri_context {
struct ofono_gprs *gprs;
 };
 
+struct provision_request {
+   struct ofono_gprs *gprs;
+};
+
 static void gprs_netreg_update(struct ofono_gprs *gprs);
 static void gprs_deactivate_next(struct ofono_gprs *gprs);
 
@@ -2230,6 +2236,9 @@ static void gprs_remove(struct ofono_atom *atom)
if (gprs-driver  gprs-driver-remove)
gprs-driver-remove(gprs);
 
+   if (gprs-provision != NULL)
+   gprs-provision-gprs = NULL;
+
g_free(gprs);
 }
 
@@ -2483,13 +2492,15 @@ remove:
storage_sync(imsi, SETTINGS_STORE, gprs-settings);
 }
 
-void ofono_gprs_register(struct ofono_gprs *gprs)
+static void ofono_gprs_finish_register(struct ofono_gprs *gprs)
 {
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(gprs-atom);
const char *path = __ofono_atom_get_path(gprs-atom);
struct ofono_atom *netreg_atom;
-   struct ofono_atom *sim_atom;
+
+   if (gprs-contexts == NULL) /* Automatic provisioning failed */
+   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
 
if (!g_dbus_register_interface(conn, path,
OFONO_CONNECTION_MANAGER_INTERFACE,
@@ -2504,18 +2515,6 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
ofono_modem_add_interface(modem,
OFONO_CONNECTION_MANAGER_INTERFACE);
 
-   sim_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SIM);
-
-   if (sim_atom) {
-   struct ofono_sim *sim = __ofono_atom_get_data(sim_atom);
-   const char *imsi = ofono_sim_get_imsi(sim);
-
-   gprs_load_settings(gprs, imsi);
-   }
-
-   if (gprs-contexts == NULL)
-   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
-
gprs-netreg_watch = __ofono_modem_add_atom_watch(modem,
OFONO_ATOM_TYPE_NETREG,
netreg_watch, gprs, NULL);
@@ -2529,6 +2528,126 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
__ofono_atom_register(gprs-atom, gprs_unregister);
 }
 
+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 || ap-name == NULL)
+   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);
+   DBG(%s context%d '%s' %s, gprs_context_default_name(ap-type),
+   id, ap-name, context ? created : creation failed);
+
+   if (context == NULL)
+   return;
+
+   context-id = id;
+
+   if (ap-username != NULL)
+   strncpy(context-context.username, ap-username,
+   OFONO_GPRS_MAX_USERNAME_LENGTH);
+
+   if (ap-password != NULL)
+   strncpy(context-context.password, ap-password,
+   OFONO_GPRS_MAX_PASSWORD_LENGTH);
+
+   if (ap-apn != NULL)
+   strncpy(context-context.apn, ap-apn,
+   OFONO_GPRS_MAX_APN_LENGTH);
+
+   context-context.proto = ap-proto;
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-message_proxy != NULL)
+   strncpy(context-message_proxy, ap-message_proxy,
+   MAX_MESSAGE_PROXY_LENGTH);
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-message_center != NULL)
+   strncpy(context-message_center, ap-message_center,
+   MAX_MESSAGE_CENTER_LENGTH);
+
+   if (context_dbus_register(context) == TRUE) {
+   gprs-last_context_id = id;
+   gprs-contexts = g_slist_append(gprs-contexts, context);
+   write_context_settings(gprs, context);
+
+   if (context-type == OFONO_GPRS_CONTEXT_TYPE_MMS) {
+   g_key_file_set_string(gprs-settings, context-key,
+

[PATCH 6/6] gprs-provision: add example context provisioning driver

2011-01-20 Thread Jukka Saunamaki
---
 Makefile.am  |3 +
 examples/provision.c |  221 ++
 2 files changed, 224 insertions(+), 0 deletions(-)
 create mode 100644 examples/provision.c

diff --git a/Makefile.am b/Makefile.am
index 97480d5..7a87aee 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -327,6 +327,9 @@ builtin_sources += examples/history.c
 
 builtin_modules += example_nettime
 builtin_sources += examples/nettime.c
+
+builtin_modules += example_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 000..d84c4ba
--- /dev/null
+++ b/examples/provision.c
@@ -0,0 +1,221 @@
+/*
+ *
+ *  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 *user_data;
+};
+
+static int example_provision_probe(struct ofono_gprs_provision_context 
*context)
+{
+   ofono_debug(Example GPRS context provisioning Probe for modem: %p,
+   context-modem);
+   return 0;
+}
+
+static void example_provision_remove(
+   struct ofono_gprs_provision_context *context)
+{
+   ofono_debug(Example GPRS context provisioning Remove for modem: %p,
+   context-modem);
+}
+
+static void provision_settings_free(struct ofono_gprs_provision_data *settings,
+   int count)
+{
+   int i;
+
+   for (i = 0; i  count; i++) {
+   g_free(settings[i].name);
+   g_free(settings[i].apn);
+   g_free(settings[i].username);
+   g_free(settings[i].password);
+   g_free(settings[i].message_proxy);
+   g_free(settings[i].message_center);
+   }
+
+   g_free(settings);
+}
+
+/* Example settings for phonesim */
+static void example_settings(const char *mcc, const char *mnc, const char *spn,
+   struct ofono_gprs_provision_data **settings,
+   int *count)
+{
+   *count = 0;
+   *settings = NULL;
+
+   ofono_debug(Finding settings for MCC %s, MNC %s, SPN '%s',
+   mcc, mnc, spn);
+
+   if (strcmp(mcc, 246) != 0 || strcmp(mnc, 81) != 0 ||
+   spn == NULL || strcmp(spn, oFono) != 0)
+   return;
+
+   ofono_debug(Creating example settings for phonesim);
+
+   *settings = g_try_new0(struct ofono_gprs_provision_data, 2);
+   if (*settings == NULL)
+   return;
+
+   *count = 2;
+
+   /* Internet context settings */
+   (*settings)[0].proto = OFONO_GPRS_PROTO_IP;
+   (*settings)[0].type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
+   (*settings)[0].name = g_strdup(Phonesim Internet);
+   (*settings)[0].apn = g_strdup(internetapn);
+
+   /* MMS context settings */
+   (*settings)[1].proto = OFONO_GPRS_PROTO_IP;
+   (*settings)[1].type = OFONO_GPRS_CONTEXT_TYPE_MMS;
+   (*settings)[1].name = g_strdup(Phonesim MMS);
+   (*settings)[1].apn = g_strdup(mmsapn);
+   (*settings)[1].username = g_strdup(mmsuser);
+   (*settings)[1].password = g_strdup(mmspass);
+   (*settings)[1].message_proxy = g_strdup(10.11.12.13:8080);
+   (*settings)[1].message_center = g_strdup(http://mms.example.com:8000;);
+}
+
+static void sim_spn_read_cb(int ok, int length, int record,
+   const unsigned char *data,
+   int record_length, void *user_data)
+{
+   struct provisioning_request *req = user_data;
+
+   struct ofono_atom *sim_atom;
+   struct ofono_sim *sim;
+   const char *mcc;
+   const char *mnc;
+   char *spn = NULL;
+   struct ofono_gprs_provision_data *settings = NULL;
+   int count = 0;
+
+

[PATCH 4/6] modem: probe gprs_provision drivers

2011-01-20 Thread Jukka Saunamaki
---
 src/modem.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/modem.c b/src/modem.c
index e966a6e..a302590 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -424,6 +424,7 @@ static void modem_change_state(struct ofono_modem *modem,
driver-post_sim(modem);
__ofono_history_probe_drivers(modem);
__ofono_nettime_probe_drivers(modem);
+   __ofono_gprs_provision_probe_drivers(modem);
} else
notify_online_watches(modem);
 
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH 1/6] gprs-provision: add driver API header

2011-01-20 Thread Jukka Saunamaki
Hi

On Thu, 2011-01-20 at 15:51 -0600, Denis Kenzior wrote:
 So I don't really see the point in an asynchronous provisioning driver.
  If you want to do this over D-Bus or something then you might as well
 provision via the ConnectionManager interface.  The other problem with
 being async is that is nearly impossible to support multiple
 provisioning plugins properly.  I'd rather not deal with the race
 conditions.
 
 If we can't make the lookup fast enough to be done synchronously, then I
 think we should give up.

The reason for asyncronous API is still that SPN value reading from SIM.
Is there any way to make sure it is available synchronously when
provisioning is run?
And what do you mean with it being impossible to support multiple
provisioning plugins properly? Plugins are run one after another until
first returns something.
Race conditions I tried to address in gprs, so if gprs atom goes away
while provisioning is running nothing bad should happen. But sure, there
might something else, and hopefully someone could point them.

Of cause there is always the possibility to do all this provisioning
stuff outside of oFono, especially if we add SPN property to SIM API.

 I also don't see the point of instantiating these per modem.  The API
 already has all the information it needs in the get_settings call.  So
 having the plugin allocate its data in the plugin init function and free
 it there seems enough to me.

This I agree, earlier patches did it that way. I only changed this since
Marcel wished that all this kind of driver interfaces (like nettime)
would look similar. Or did I misunderstand that?

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/3] sim: getters for mcc and mnc definition

2011-01-19 Thread Jukka Saunamaki
---
 include/sim.h |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 830322a..81df60e 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -178,6 +178,8 @@ void ofono_sim_set_data(struct ofono_sim *sim, void *data);
 void *ofono_sim_get_data(struct ofono_sim *sim);
 
 const char *ofono_sim_get_imsi(struct ofono_sim *sim);
+const char *ofono_sim_get_mcc(struct ofono_sim *sim);
+const char *ofono_sim_get_mnc(struct ofono_sim *sim);
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
 
 enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase(struct ofono_sim *sim);
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[gprs-provision PATCHv4 0/8] plugin API for provisioning of GPRS context settings

2011-01-18 Thread Jukka Saunamaki
Hello

Here is a new patchset about implementing automatic provisioning of GPRS 
context settings. (Internet Access Provider database TODO item).

Compared to last one, this makes gprs-provision a pseudo atom similar to 
nettime. And possible races caused by a removed gprs-atom, while it is running 
asyncronous provisioning, should hopefully be fixed now.

Provisioning data for gprs contexts is returned by gprs-provisioning 
plugins/drivers. Different kind of provisioning modules may be created for 
different platforms or use cases.
It is up to the module what settings database it uses, and how many, and what 
type of contexts (with settings) it returns.
Several plugins may be loaded in oFono, and they will be called in priority 
order until first plugin returns non-empty result.

Provisioning modules are called in case there are no previously configured 
contexts found during gprs atom registration.
 
These patches add new gprs-provision.[hc] API for provisioning plugins to 
register into, and __ofono_gprs_provision_get_settings for gprs.c to call when 
needed.
gprs.c is modified to use provisioning if reading existing context settings 
fails.

A dummy example provisioning plugin is included. In case it is called when 
using phonesim with default.xml configuration, the plugin returns dummy 
settings for two contexts, one type Internet and one type MMS. 

Patches also add new functions ofono_sim_get_mcc/mnc to SIM atom API (typically 
needed by provisioning plugins).

--Jukka Saunamäki

Jukka Saunamaki (8):
  gprs-provision: add driver API header
  gprs-provision: add new atom type
  gprs-provision: add driver API sources
  gprs-provision: probe gprs_provision drivers
  gprs: add gprs context provisioning
  sim: getters for mcc and mnc definition
  sim: getters for mcc and mnc implementation
  gprs-provision: add example context provisioning driver

 Makefile.am  |7 +-
 examples/provision.c |  206 
 include/gprs-provision.h |   80 
 include/sim.h|2 +
 src/gprs-provision.c |  236 ++
 src/gprs.c   |  147 ++---
 src/modem.c  |1 +
 src/ofono.h  |9 ++
 src/sim.c|   50 ++
 9 files changed, 703 insertions(+), 35 deletions(-)
 create mode 100644 examples/provision.c
 create mode 100644 include/gprs-provision.h
 create mode 100644 src/gprs-provision.c


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 4/8] gprs-provision: probe gprs_provision drivers

2011-01-18 Thread Jukka Saunamaki
---
 src/modem.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/modem.c b/src/modem.c
index f587766..a835775 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -424,6 +424,7 @@ static void modem_change_state(struct ofono_modem *modem,
driver-post_sim(modem);
__ofono_history_probe_drivers(modem);
__ofono_nettime_probe_drivers(modem);
+   __ofono_gprs_provision_probe_drivers(modem);
} else
notify_online_watches(modem);
 
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/8] gprs-provision: add new atom type

2011-01-18 Thread Jukka Saunamaki
---
 src/ofono.h |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/ofono.h b/src/ofono.h
index 77567c2..873b688 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -127,6 +127,7 @@ enum ofono_atom_type {
OFONO_ATOM_TYPE_NETTIME = 21,
OFONO_ATOM_TYPE_CTM = 22,
OFONO_ATOM_TYPE_CDMA_VOICECALL_MANAGER = 23,
+   OFONO_ATOM_TYPE_GPRS_PROVISION = 24,
 };
 
 enum ofono_atom_watch_condition {
@@ -417,4 +418,12 @@ void __ofono_nettime_probe_drivers(struct ofono_modem 
*modem);
 void __ofono_nettime_info_received(struct ofono_modem *modem,
struct ofono_network_time *info);
 
+#include ofono/gprs-provision.h
+
+void __ofono_gprs_provision_probe_drivers(struct ofono_modem *modem);
+
+void __ofono_gprs_provision_get_settings(struct ofono_modem *modem,
+   ofono_gprs_provision_cb_t cb,
+   void *user_data);
+
 #include ofono/cdma-voicecall.h
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 5/8] gprs: add gprs context provisioning

2011-01-18 Thread Jukka Saunamaki
---
 src/gprs.c |  147 ++--
 1 files changed, 133 insertions(+), 14 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 0e86bdf..b0d58f6 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -43,6 +43,7 @@
 #include common.h
 #include storage.h
 #include idmap.h
+#include gprs-provision.h
 
 #define GPRS_FLAG_ATTACHING 0x1
 #define GPRS_FLAG_RECHECK 0x2
@@ -82,6 +83,7 @@ struct ofono_gprs {
const struct ofono_gprs_driver *driver;
void *driver_data;
struct ofono_atom *atom;
+   struct provision_request *provision;
 };
 
 struct ofono_gprs_context {
@@ -122,6 +124,10 @@ struct pri_context {
struct ofono_gprs *gprs;
 };
 
+struct provision_request {
+   struct ofono_gprs *gprs;
+};
+
 static void gprs_netreg_update(struct ofono_gprs *gprs);
 static void gprs_deactivate_next(struct ofono_gprs *gprs);
 
@@ -2203,6 +2209,9 @@ static void gprs_remove(struct ofono_atom *atom)
if (gprs-driver  gprs-driver-remove)
gprs-driver-remove(gprs);
 
+   if (gprs-provision != NULL)
+   gprs-provision-gprs = NULL;
+
g_free(gprs);
 }
 
@@ -2456,13 +2465,15 @@ remove:
storage_sync(imsi, SETTINGS_STORE, gprs-settings);
 }
 
-void ofono_gprs_register(struct ofono_gprs *gprs)
+static void ofono_gprs_finish_register(struct ofono_gprs *gprs)
 {
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(gprs-atom);
const char *path = __ofono_atom_get_path(gprs-atom);
struct ofono_atom *netreg_atom;
-   struct ofono_atom *sim_atom;
+
+   if (gprs-contexts == NULL) /* Automatic provisioning failed */
+   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
 
if (!g_dbus_register_interface(conn, path,
OFONO_CONNECTION_MANAGER_INTERFACE,
@@ -2477,18 +2488,6 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
ofono_modem_add_interface(modem,
OFONO_CONNECTION_MANAGER_INTERFACE);
 
-   sim_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SIM);
-
-   if (sim_atom) {
-   struct ofono_sim *sim = __ofono_atom_get_data(sim_atom);
-   const char *imsi = ofono_sim_get_imsi(sim);
-
-   gprs_load_settings(gprs, imsi);
-   }
-
-   if (gprs-contexts == NULL)
-   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
-
gprs-netreg_watch = __ofono_modem_add_atom_watch(modem,
OFONO_ATOM_TYPE_NETREG,
netreg_watch, gprs, NULL);
@@ -2502,6 +2501,126 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
__ofono_atom_register(gprs-atom, gprs_unregister);
 }
 
+static void provision_context(gpointer data, gpointer user_data)
+{
+   struct ofono_gprs_provision_data *ap = data;
+   struct ofono_gprs *gprs = user_data;
+
+   unsigned int id;
+   struct pri_context *context = NULL;
+
+   /* Sanity check */
+   if (ap == NULL || ap-name == NULL)
+   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);
+   DBG(%s context%d '%s' %s, gprs_context_default_name(ap-type),
+   id, ap-name, context ? created : creation failed);
+
+   if (context == NULL)
+   return;
+
+   context-id = id;
+
+   if (ap-username != NULL)
+   strncpy(context-context.username, ap-username,
+   OFONO_GPRS_MAX_USERNAME_LENGTH);
+
+   if (ap-password != NULL)
+   strncpy(context-context.password, ap-password,
+   OFONO_GPRS_MAX_PASSWORD_LENGTH);
+
+   if (ap-apn != NULL)
+   strncpy(context-context.apn, ap-apn,
+   OFONO_GPRS_MAX_APN_LENGTH);
+
+   context-context.proto = ap-proto;
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-message_proxy != NULL)
+   strncpy(context-message_proxy, ap-message_proxy,
+   MAX_MESSAGE_PROXY_LENGTH);
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-message_center != NULL)
+   strncpy(context-message_center, ap-message_center,
+   MAX_MESSAGE_CENTER_LENGTH);
+
+   if (context_dbus_register(context) == TRUE) {
+   gprs-last_context_id = id;
+   gprs-contexts = g_slist_append(gprs-contexts, context);
+   write_context_settings(gprs, context);
+
+   if (context-type == OFONO_GPRS_CONTEXT_TYPE_MMS) {
+   

[PATCH 3/8] gprs-provision: add driver API sources

2011-01-18 Thread Jukka Saunamaki
---
 Makefile.am  |2 +-
 src/gprs-provision.c |  236 ++
 2 files changed, 237 insertions(+), 1 deletions(-)
 create mode 100644 src/gprs-provision.c

diff --git a/Makefile.am b/Makefile.am
index 22ec95d..e792851 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -354,7 +354,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) 
src/ofono.ver \
src/nettime.c src/stkagent.c src/stkagent.h \
src/simfs.c src/simfs.h src/audio-settings.c \
src/smsagent.c src/smsagent.h src/ctm.c \
-   src/cdma-voicecall.c
+   src/cdma-voicecall.c src/gprs-provision.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/src/gprs-provision.c b/src/gprs-provision.c
new file mode 100644
index 000..1690bc7
--- /dev/null
+++ b/src/gprs-provision.c
@@ -0,0 +1,236 @@
+/*
+ *
+ *  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 stdlib.h
+#include glib.h
+
+#include ofono.h
+#include gprs-provision.h
+
+static GSList *g_drivers = NULL;
+static GSList *provision_requests = NULL;
+
+struct gprs_provision_request {
+   GSList *drivers; /* Provisioning drivers to be called */
+   struct ofono_modem *modem;
+   ofono_gprs_provision_cb_t cb;
+   void *user_data;
+};
+
+static void settings_cb(GSList *settings, void *user_data);
+
+static struct ofono_gprs_provision_context *gprs_provision_context_create(
+   struct ofono_modem *modem,
+   struct ofono_gprs_provision_driver *driver)
+{
+   struct ofono_gprs_provision_context *context;
+
+   if (driver-probe == NULL)
+   return NULL;
+
+   context = g_try_new0(struct ofono_gprs_provision_context, 1);
+
+   if (context == NULL)
+   return NULL;
+
+   context-driver = driver;
+   context-modem = modem;
+
+   if (driver-probe(context)  0) {
+   g_free(context);
+   return NULL;
+   }
+
+   return context;
+}
+
+static void clean_active_requests(gpointer data, gpointer user_data)
+{
+   struct gprs_provision_request *req = data;
+   struct ofono_gprs_provision_context *context = user_data;
+
+   req-drivers = g_slist_remove(req-drivers, context);
+}
+
+static void context_remove(struct ofono_atom *atom)
+{
+   struct ofono_gprs_provision_context *context =
+   __ofono_atom_get_data(atom);
+
+   g_slist_foreach(provision_requests, clean_active_requests, context);
+
+   if (context-driver-remove)
+   context-driver-remove(context);
+
+   g_free(context);
+}
+
+void __ofono_gprs_provision_probe_drivers(struct ofono_modem *modem)
+{
+   struct ofono_gprs_provision_driver *driver;
+   struct ofono_gprs_provision_context *context;
+   GSList *l;
+
+   for (l = g_drivers; l; l = l-next) {
+   driver = l-data;
+
+   context = gprs_provision_context_create(modem, driver);
+   if (context == NULL)
+   continue;
+
+   __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_GPRS_PROVISION,
+   context_remove, context);
+   }
+}
+
+void ofono_gprs_provision_data_free(struct ofono_gprs_provision_data *data)
+{
+   if (data == NULL)
+   return;
+
+   free(data-name);
+   free(data-apn);
+   free(data-username);
+   free(data-password);
+   free(data-message_proxy);
+   free(data-message_center);
+   g_free(data);
+}
+
+/*
+ * Calls next driver that has callable get_settings()
+ * Returns TRUE if a driver was called.
+ */
+static gboolean call_driver_get_settings(struct gprs_provision_request *req,
+   ofono_gprs_provision_cb_t cb)
+{
+   struct ofono_gprs_provision_context *context;
+
+   if (req-drivers == NULL)
+   return FALSE;
+
+   do {
+   context = req-drivers-data;
+   req-drivers = g_slist_delete_link(req-drivers, req-drivers);
+
+   if 

[PATCH 1/8] gprs-provision: add driver API header

2011-01-18 Thread Jukka Saunamaki
---
 Makefile.am  |2 +-
 include/gprs-provision.h |   80 ++
 2 files changed, 81 insertions(+), 1 deletions(-)
 create mode 100644 include/gprs-provision.h

diff --git a/Makefile.am b/Makefile.am
index da59be7..22ec95d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,7 +15,7 @@ include_HEADERS = include/log.h include/plugin.h 
include/history.h \
include/radio-settings.h include/stk.h \
include/audio-settings.h include/nettime.h \
include/ctm.h include/cdma-voicecall.h \
-   include/cdma-sms.h
+   include/cdma-sms.h include/gprs-provision.h
 
 nodist_include_HEADERS = include/version.h
 
diff --git a/include/gprs-provision.h b/include/gprs-provision.h
new file mode 100644
index 000..70152b4
--- /dev/null
+++ b/include/gprs-provision.h
@@ -0,0 +1,80 @@
+/*
+ *
+ *  oFono - Open Telephony stack for Linux
+ *
+ *  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
+ *
+ */
+
+#ifndef __OFONO_GPRS_PROVISION_H
+#define __OFONO_GPRS_PROVISION_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#include gprs-context.h
+
+struct ofono_gprs_provision_context {
+   struct ofono_gprs_provision_driver *driver;
+   struct ofono_modem *modem;
+   void *data;
+};
+
+struct ofono_gprs_provision_data {
+   enum ofono_gprs_context_type type;
+   enum ofono_gprs_proto proto;
+   char *name;
+   char *apn;
+   char *username;
+   char *password;
+   char *message_proxy;
+   char *message_center;
+};
+
+/*
+ * Callback from provisioning plugin.
+ * settings: list of struct ofono_gprs_provision_data
+ *
+ * It is responsibility of callback function to free settings-list
+ * settings-list elements must be freed with ofono_gprs_provision_data_free()
+ */
+typedef void (*ofono_gprs_provision_cb_t)(GSList *settings, void *userdata);
+
+struct ofono_gprs_provision_driver {
+   const char *name;
+   int priority;
+   int (*probe)(struct ofono_gprs_provision_context *context);
+   void (*remove)(struct ofono_gprs_provision_context *context);
+   void (*get_settings) (struct ofono_gprs_provision_context *context,
+   ofono_gprs_provision_cb_t cb,
+   void *user_data);
+};
+
+/* For provisioning drivers/plugins */
+int ofono_gprs_provision_driver_register(
+   const struct ofono_gprs_provision_driver *driver);
+void ofono_gprs_provision_driver_unregister(
+   const struct ofono_gprs_provision_driver *driver);
+
+/* For gprs */
+void ofono_gprs_provision_data_free(struct ofono_gprs_provision_data *data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_GPRS_PROVISION_H */
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 6/8] sim: getters for mcc and mnc definition

2011-01-18 Thread Jukka Saunamaki
---
 include/sim.h |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 830322a..81df60e 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -178,6 +178,8 @@ void ofono_sim_set_data(struct ofono_sim *sim, void *data);
 void *ofono_sim_get_data(struct ofono_sim *sim);
 
 const char *ofono_sim_get_imsi(struct ofono_sim *sim);
+const char *ofono_sim_get_mcc(struct ofono_sim *sim);
+const char *ofono_sim_get_mnc(struct ofono_sim *sim);
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
 
 enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase(struct ofono_sim *sim);
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 7/8] sim: getters for mcc and mnc implementation

2011-01-18 Thread Jukka Saunamaki
---
 src/sim.c |   50 +++---
 1 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/src/sim.c b/src/sim.c
index d627647..86c3f13 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -78,6 +78,8 @@ struct ofono_sim {
gboolean barred_dialing;
 
char *imsi;
+   char mcc[OFONO_MAX_MCC_LENGTH + 1];
+   char mnc[OFONO_MAX_MNC_LENGTH + 1];
 
GSList *own_numbers;
GSList *new_numbers;
@@ -348,21 +350,13 @@ static DBusMessage *sim_get_properties(DBusConnection 
*conn,
bdn = sim-barred_dialing;
ofono_dbus_dict_append(dict, BarredDialing, DBUS_TYPE_BOOLEAN, bdn);
 
-   if (sim-mnc_length  sim-imsi) {
-   char mcc[OFONO_MAX_MCC_LENGTH + 1];
-   char mnc[OFONO_MAX_MNC_LENGTH + 1];
+   if (sim-mcc[0] != '\0'  sim-mnc[0] != '\0') {
const char *str;
-
-   strncpy(mcc, sim-imsi, OFONO_MAX_MCC_LENGTH);
-   mcc[OFONO_MAX_MCC_LENGTH] = '\0';
-   strncpy(mnc, sim-imsi + OFONO_MAX_MCC_LENGTH, sim-mnc_length);
-   mnc[sim-mnc_length] = '\0';
-
-   str = mcc;
+   str = sim-mcc;
ofono_dbus_dict_append(dict, MobileCountryCode,
DBUS_TYPE_STRING, str);
 
-   str = mnc;
+   str = sim-mnc;
ofono_dbus_dict_append(dict, MobileNetworkCode,
DBUS_TYPE_STRING, str);
}
@@ -1299,22 +1293,21 @@ static void sim_imsi_cb(const struct ofono_error 
*error, const char *imsi,
DBUS_TYPE_STRING, sim-imsi);
 
if (sim-mnc_length) {
-   char mcc[OFONO_MAX_MCC_LENGTH + 1];
-   char mnc[OFONO_MAX_MNC_LENGTH + 1];
const char *str;
 
-   strncpy(mcc, sim-imsi, OFONO_MAX_MCC_LENGTH);
-   mcc[OFONO_MAX_MCC_LENGTH] = '\0';
-   strncpy(mnc, sim-imsi + OFONO_MAX_MCC_LENGTH, sim-mnc_length);
-   mnc[sim-mnc_length] = '\0';
+   strncpy(sim-mcc, sim-imsi, OFONO_MAX_MCC_LENGTH);
+   sim-mcc[OFONO_MAX_MCC_LENGTH] = '\0';
+   strncpy(sim-mnc, sim-imsi + OFONO_MAX_MCC_LENGTH,
+   sim-mnc_length);
+   sim-mnc[sim-mnc_length] = '\0';
 
-   str = mcc;
+   str = sim-mcc;
ofono_dbus_signal_property_changed(conn, path,
OFONO_SIM_MANAGER_INTERFACE,
MobileCountryCode,
DBUS_TYPE_STRING, str);
 
-   str = mnc;
+   str = sim-mnc;
ofono_dbus_signal_property_changed(conn, path,
OFONO_SIM_MANAGER_INTERFACE,
MobileNetworkCode,
@@ -1997,6 +1990,22 @@ const char *ofono_sim_get_imsi(struct ofono_sim *sim)
return sim-imsi;
 }
 
+const char *ofono_sim_get_mcc(struct ofono_sim *sim)
+{
+   if (sim == NULL)
+   return NULL;
+
+   return sim-mcc;
+}
+
+const char *ofono_sim_get_mnc(struct ofono_sim *sim)
+{
+   if (sim == NULL)
+   return NULL;
+
+   return sim-mnc;
+}
+
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim)
 {
if (sim == NULL)
@@ -2060,6 +2069,9 @@ static void sim_free_state(struct ofono_sim *sim)
sim-imsi = NULL;
}
 
+   sim-mcc[0] = '\0';
+   sim-mnc[0] = '\0';
+
if (sim-own_numbers) {
g_slist_foreach(sim-own_numbers, (GFunc)g_free, NULL);
g_slist_free(sim-own_numbers);
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 8/8] gprs-provision: add example context provisioning driver

2011-01-18 Thread Jukka Saunamaki
---
 Makefile.am  |3 +
 examples/provision.c |  206 ++
 2 files changed, 209 insertions(+), 0 deletions(-)
 create mode 100644 examples/provision.c

diff --git a/Makefile.am b/Makefile.am
index e792851..a74f75e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -328,6 +328,9 @@ builtin_sources += examples/history.c
 
 builtin_modules += example_nettime
 builtin_sources += examples/nettime.c
+
+builtin_modules += example_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 000..d39fc3c
--- /dev/null
+++ b/examples/provision.c
@@ -0,0 +1,206 @@
+/*
+ *
+ *  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 *user_data;
+};
+
+static int example_provision_probe(struct ofono_gprs_provision_context 
*context)
+{
+   ofono_debug(Example GPRS context provisioning Probe for modem: %p,
+   context-modem);
+   return 0;
+}
+
+static void example_provision_remove(
+   struct ofono_gprs_provision_context *context)
+{
+   ofono_debug(Example GPRS context provisioning Remove for modem: %p,
+   context-modem);
+}
+
+static void sim_spn_read_cb(int ok, int length, int record,
+   const unsigned char *data,
+   int record_length, void *user_data)
+{
+   struct provisioning_request *req = user_data;
+   char *spn = NULL;
+
+   struct ofono_atom *sim_atom;
+   struct ofono_sim *sim;
+   const char *mcc;
+   const char *mnc;
+
+   GSList *settings = NULL;
+   struct ofono_gprs_provision_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);
+   mcc = ofono_sim_get_mcc(sim);
+   if (mcc == NULL) {
+   ofono_debug(No MCC available);
+   goto finish;
+   }
+
+   mnc = ofono_sim_get_mnc(sim);
+   if (mnc == NULL) {
+   ofono_debug(No MNC available);
+   goto finish;
+   }
+
+   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);
+
+   /* Example settings for phonesim */
+   if (strcmp(mcc, 246) != 0 || strcmp(mnc, 81) != 0 ||
+   spn == NULL || strcmp(spn, oFono) != 0)
+   goto finish;
+
+   ofono_debug(Creating example settings for phonesim);
+
+   /* MMS context settings */
+   entry = g_try_new0(struct ofono_gprs_provision_data, 1);
+   if (entry == NULL)
+   goto finish;
+
+   entry-proto = OFONO_GPRS_PROTO_IP;
+   entry-type = OFONO_GPRS_CONTEXT_TYPE_MMS;
+   entry-name = strdup(Phonesim MMS);
+   entry-apn = strdup(mmsapn);
+   entry-username = strdup(mmsuser);
+   entry-password = strdup(mmspass);
+   entry-message_proxy = strdup(10.11.12.13:8080);
+   entry-message_center = strdup(http://mms.example.com:8000;);
+   settings = g_slist_prepend(settings, entry);
+
+   /* Internet context settings */
+   entry = g_try_new0(struct ofono_gprs_provision_data, 1);
+   if (entry == NULL)
+   goto finish;
+
+   entry-proto = OFONO_GPRS_PROTO_IP;
+   entry-type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
+   entry-name = strdup(Phonesim Internet);
+   entry-apn = strdup(internetapn);
+   settings = g_slist_prepend(settings, entry);
+
+finish:
+   g_free(spn);
+
+   if 

Re: [PATCH 1/8] gprs-provision: add driver API header

2011-01-18 Thread Jukka Saunamaki
Hi Marcel,

  +/*
  + * Callback from provisioning plugin.
  + * settings: list of struct ofono_gprs_provision_data
  + *
  + * It is responsibility of callback function to free settings-list
  + * settings-list elements must be freed with 
  ofono_gprs_provision_data_free()
  + */
  +typedef void (*ofono_gprs_provision_cb_t)(GSList *settings, void 
  *userdata);
 
 so our general rule is no GLib types in oFono public APIs.

OK. Do you have any preferences for the best type here? Linked list of
'struct ofono_gprs_provision_data's, array of structs + count, array of
pointers (+count)?

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 0/3] sim: add getters for mcc and mnc

2011-01-18 Thread Jukka Saunamaki
These patches add getter functions for home PLMN MCC and MCC values to SIM atom.

Jukka Saunamaki (3):
  sim: store mcc and mnc separate from imsi
  sim: getters for mcc and mnc definition
  sim: getters for mcc and mnc implementation

 include/sim.h |2 ++
 src/sim.c |   50 +++---
 2 files changed, 33 insertions(+), 19 deletions(-)

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 3/3] sim: getters for mcc and mnc implementation

2011-01-18 Thread Jukka Saunamaki
---
 src/sim.c |   16 
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/sim.c b/src/sim.c
index 891116b..86c3f13 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -1990,6 +1990,22 @@ const char *ofono_sim_get_imsi(struct ofono_sim *sim)
return sim-imsi;
 }
 
+const char *ofono_sim_get_mcc(struct ofono_sim *sim)
+{
+   if (sim == NULL)
+   return NULL;
+
+   return sim-mcc;
+}
+
+const char *ofono_sim_get_mnc(struct ofono_sim *sim)
+{
+   if (sim == NULL)
+   return NULL;
+
+   return sim-mnc;
+}
+
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim)
 {
if (sim == NULL)
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCH 4/4] Dummy example GPRS context provisioning driver

2011-01-16 Thread Jukka Saunamaki
Hello

On Sat, 2011-01-15 at 02:30 +0100, Marcel Holtmann wrote:
   I would advise the UI against using the name from the context
   information and better using the one from the network registration
   instead.
  
  Well that would make sense... Therefore the operators don't do it ;-)
  
  For instance my provider shows as Elisa in the network registration but 
  the 
  access points are expected to be shown as Elisa Internet and Elisa MMS 
  WAP 
  if I recall correctly.
  
  It only makes sense to have this data in the provisioning plugin. It would 
  be 
  silly to have to provision just the names in a different component.
 
 just to make this clear, oFono takes care of potential operator renames
 and displays them accordingly, but the provision names would stay the
 same.
 
 So if Elisa renames themselves into Gwendula, the context names would
 still say Elisa Internet etc. Has anybody thought about this part?

Well, there is always OMA Client Provisioning for that purpose.

However, I would leave this question to UX designers and someone that
actually knows operator requirements regarding which name (network
provided or provisioning/gprs-context name) to show for Internet access
selection.
Also, by the way, when roaming, network name is different from normal
home name, and this may or may not be desirable for internet access
name...

In any case, regarding the original issue if reading SPN is really
needed for provisioning, the answer is still yes. There are cases where
different SPN means different gprs context settings (other than 'Name'
too).

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCH 4/4] Dummy example GPRS context provisioning driver

2011-01-14 Thread Jukka Saunamaki
Hi ,

  I was not sure if all MVNOs have their own MNC, but in any case some
  operators use different trade names. Off the top of my hat I know our
  local Finnish operators Elisa and Sonera use trade names like Kolumbus
  and TeleFinland, and their name shown in UI needs to be correct.
 
 what does the name showing in the UI has to do with the provision data
 for the GPRS contexts? I am missing your point here.

Isn't the 'name' property of a context shown in some UI (when user
selects connection to open)?
And there might be cases where other context settings like APN is
different with different trade names.

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCH 4/4] Dummy example GPRS context provisioning driver

2011-01-14 Thread Jukka Saunamaki
Hi

On Fri, 2011-01-14 at 14:44 +0100, ext Marcel Holtmann wrote:
 Hi Jukka,
 
I was not sure if all MVNOs have their own MNC, but in any case some
operators use different trade names. Off the top of my hat I know our
local Finnish operators Elisa and Sonera use trade names like Kolumbus
and TeleFinland, and their name shown in UI needs to be correct.
   
   what does the name showing in the UI has to do with the provision data
   for the GPRS contexts? I am missing your point here.
  
  Isn't the 'name' property of a context shown in some UI (when user
  selects connection to open)?
 
 so you wanna use the SPN to set the nice friendly name of the Context.
 So far we just defaulted to Internet and MMS and did not bother any
 further.

Yes, that is how our previous UIs have done it, and I guess our UX
designers like it in the future too.

 For example ConnMan actually takes that information from the network
 registration and not from the context.

  And there might be cases where other context settings like APN is
  different with different trade names.
 
 Is that really the case? Can this be used reliably?

Quick look at our operator database does indeed confirm that, there are
cases where different SPN maps to different APN.

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCH 4/4] Dummy example GPRS context provisioning driver

2011-01-13 Thread Jukka Saunamaki
Hello Denis,

On Thu, 2011-01-13 at 09:57 -0600, Denis Kenzior wrote:
  Some virtual operators are using the same MCC/MNC as their host, or some
  operators have several different trade names, and these can have
  different access settings (at least different UI visible name). 
  SPN in SIM typically tells these cases apart. This is why I included
  reading SPN to that example provisioning.
 
 Do you have specific examples?  To my knowledge the MVNOs should be
 provisioning the SIM with a different MNC from the host but the network
 used (and thus the network's MCC/MNC) are their host's.

I was not sure if all MVNOs have their own MNC, but in any case some
operators use different trade names. Off the top of my hat I know our
local Finnish operators Elisa and Sonera use trade names like Kolumbus
and TeleFinland, and their name shown in UI needs to be correct.

  All provisioning plugins might not care about SPN (e.g. the previously
  discussed one using mobile-broadband-provider-info?), so I would suggest
  not creating specific SIM API yet. Of cause it can be added later, if so
  wished.
 
 You might be able to get away with reading of EFspn just because it is
 cached nicely on disk.  But you will have to carefully consider your
 plugin design if you wish to do so to avoid any race conditions and be
 able to properly clean up.

You mean that if plugin gets removed/unregistered before SPN-reading
callback comes in? 
That is a good point, and I also have to check how to handle this in
GPRS atom, since calling provisioning is asynchronous, and GPRS might
get removed while provisioning is running... I might need some help
figuring out solution to that. 
Alternative is of cause to make provisioning synchronous, but that would
limit what plugin can do (like asking SPN with ofono_sim_read())

--Jukka
 

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCH 4/4] Dummy example GPRS context provisioning driver

2011-01-12 Thread Jukka Saunamaki
Hello

On Wed, 2011-01-12 at 10:46 -0600, Denis Kenzior wrote:
  ...SIM EF-SPN... 
 
 You're correct that netreg is the only consumer.  There was no need for
 anyone else to see this information.  However, this begs the question,
 why do you need the SPN data?

Some virtual operators are using the same MCC/MNC as their host, or some
operators have several different trade names, and these can have
different access settings (at least different UI visible name). 
SPN in SIM typically tells these cases apart. This is why I included
reading SPN to that example provisioning.

All provisioning plugins might not care about SPN (e.g. the previously
discussed one using mobile-broadband-provider-info?), so I would suggest
not creating specific SIM API yet. Of cause it can be added later, if so
wished.

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCH 2/4] gprs: add automatic context settings provisioning

2011-01-11 Thread Jukka Saunamaki
Hello Marcel,

On Tue, 2011-01-11 at 22:51 -0800, ext Marcel Holtmann wrote:
   
  -void ofono_gprs_register(struct ofono_gprs *gprs)
  +static void ofono_gprs_finish_register(struct ofono_gprs *gprs)
   {
  DBusConnection *conn = ofono_dbus_get_connection();
  struct ofono_modem *modem = __ofono_atom_get_modem(gprs-atom);
  const char *path = __ofono_atom_get_path(gprs-atom);
  struct ofono_atom *netreg_atom;
  -   struct ofono_atom *sim_atom;
  +
  +   if (gprs-contexts == NULL) /* Automatic provisioning failed */
  +   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
 
 so I see a potential race here between the UI trying to provision and us
 trying to provision.
 
 We don't wanna end up with duplicated contexts here. Any ideas on how we
 could prevent that nicely? Or should we just fail any attempts to create
 new contexts if provisioning is still ongoing?

Code continues there with:
if (!g_dbus_register_interface(conn, path,
OFONO_CONNECTION_MANAGER_INTERFACE,
manager_methods, manager_signals, NULL,
gprs, NULL)) {
ofono_error(Could not create %s interface,
OFONO_CONNECTION_MANAGER_INTERFACE);

return;
}

ofono_modem_add_interface(modem,
OFONO_CONNECTION_MANAGER_INTERFACE);

Patch rearranges the initial context creation and interface
registration, so there is no DBUS interface for UI to use until
provisioning is ready. Or have misunderstood something?

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCH 4/4] Dummy example GPRS context provisioning driver

2011-01-11 Thread Jukka Saunamaki
Hello

On Tue, 2011-01-11 at 22:48 -0800, ext Marcel Holtmann wrote:
  +   if (sim != NULL) {
  +   ofono_sim_read(sim, SIM_EFSPN_FILEID,
  +   OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
  +   sim_spn_read_cb, req);
  +   return;
  +   }
 
 Should this not be provided somehow by the SIM atom?
 
 Denis, any idea why we are not keeping this information available?
 

I would guess there was no need for it, since netreg was the only user
for EFSPN data.

I though of patching the SIM atom to read this during some phase of SIM
initialization, but was not sure exactly when, and what kind of
interface (syncronous, asyncronous?) to provide.

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[RFC PATCHv3 0/4] Plugin API for provisioning of GPRS context settings

2011-01-10 Thread Jukka Saunamaki
Hello

Here is another RFC patchset about implementing automatic provisioning GPRS 
context settings. (Internet Access Provider database TODO item).

This time the approach is to add a new driver/plugin API for provisioning 
modules. Different kind of provisioning modules may be created for different 
platforms or use cases.
It is up to the module what settings database it uses, and how many, and what 
type of contexts (with settings) it returns.
Several plugins may be loaded in oFono, and they will be called in priority 
order until first plugin returns non-empty result.

Provisioning modules are called in case there are no previously configured 
contexts found during gprs atom registration.
 
These patches add new gprs-provision.[hc] API for provisioning plugins to 
register into, and get_settings() for gprs.c to call when needed.
gprs.c is modified to use provisioning if reading existing context settings 
fails.

A dummy example provisioning plugin is included. In case it is called when 
using phonesim with default.xml configuration, the plugin returns dummy 
settings for two contexts, one type Internet and one type MMS. 

Patches also add new function ofono_sim_get_mnc_length to SIM atom API for 
figuring out MNC value (typically needed by provisioning plugins).

--Jukka Saunamäki

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[RFC PATCH 2/4] gprs: add automatic context settings provisioning

2011-01-10 Thread Jukka Saunamaki
---
 src/gprs.c |  116 ---
 1 files changed, 102 insertions(+), 14 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 58166f8..7d188a3 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -43,6 +43,7 @@
 #include common.h
 #include storage.h
 #include idmap.h
+#include gprs-provision.h
 
 #define GPRS_FLAG_ATTACHING 0x1
 #define GPRS_FLAG_RECHECK 0x2
@@ -2454,13 +2455,15 @@ remove:
storage_sync(imsi, SETTINGS_STORE, gprs-settings);
 }
 
-void ofono_gprs_register(struct ofono_gprs *gprs)
+static void ofono_gprs_finish_register(struct ofono_gprs *gprs)
 {
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(gprs-atom);
const char *path = __ofono_atom_get_path(gprs-atom);
struct ofono_atom *netreg_atom;
-   struct ofono_atom *sim_atom;
+
+   if (gprs-contexts == NULL) /* Automatic provisioning failed */
+   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
 
if (!g_dbus_register_interface(conn, path,
OFONO_CONNECTION_MANAGER_INTERFACE,
@@ -2475,18 +2478,6 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
ofono_modem_add_interface(modem,
OFONO_CONNECTION_MANAGER_INTERFACE);
 
-   sim_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SIM);
-
-   if (sim_atom) {
-   struct ofono_sim *sim = __ofono_atom_get_data(sim_atom);
-   const char *imsi = ofono_sim_get_imsi(sim);
-
-   gprs_load_settings(gprs, imsi);
-   }
-
-   if (gprs-contexts == NULL)
-   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
-
gprs-netreg_watch = __ofono_modem_add_atom_watch(modem,
OFONO_ATOM_TYPE_NETREG,
netreg_watch, gprs, NULL);
@@ -2500,6 +2491,103 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
__ofono_atom_register(gprs-atom, gprs_unregister);
 }
 
+static void provision_context(gpointer data, gpointer user_data)
+{
+   struct ofono_gprs_provisioning_data *ap = data;
+   struct ofono_gprs *gprs = user_data;
+
+   unsigned int id;
+   struct pri_context *context = NULL;
+
+   /* Sanity check */
+   if (ap == NULL || ap-name == NULL)
+   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);
+   DBG(%s context%d '%s' %s, gprs_context_default_name(ap-type),
+   id, ap-name, context ? created : creation failed);
+
+   if (context == NULL)
+   return;
+
+   context-id = id;
+
+   if (ap-username != NULL)
+   strncpy(context-context.username, ap-username,
+   OFONO_GPRS_MAX_USERNAME_LENGTH);
+
+   if (ap-password != NULL)
+   strncpy(context-context.password, ap-password,
+   OFONO_GPRS_MAX_PASSWORD_LENGTH);
+
+   if (ap-apn != NULL)
+   strncpy(context-context.apn, ap-apn,
+   OFONO_GPRS_MAX_APN_LENGTH);
+
+   context-context.proto = ap-proto;
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-message_proxy != NULL)
+   strncpy(context-message_proxy, ap-message_proxy,
+   MAX_MESSAGE_PROXY_LENGTH);
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-message_center != NULL)
+   strncpy(context-message_center, ap-message_center,
+   MAX_MESSAGE_CENTER_LENGTH);
+
+   if (context_dbus_register(context) == TRUE) {
+   gprs-last_context_id = id;
+   gprs-contexts = g_slist_append(gprs-contexts,
+   context);
+   write_context_settings(gprs, context);
+   }
+}
+
+
+static void provision_cb(GSList *settings, void *userdata)
+{
+   struct ofono_gprs *gprs = userdata;
+
+   g_slist_foreach(settings, provision_context, gprs);
+   g_slist_foreach(settings, (GFunc) ofono_gprs_provisioning_data_free,
+   NULL);
+   g_slist_free(settings);
+
+   ofono_gprs_finish_register(gprs);
+}
+
+void ofono_gprs_register(struct ofono_gprs *gprs)
+{
+   struct ofono_modem *modem = __ofono_atom_get_modem(gprs-atom);
+   struct ofono_atom *sim_atom;
+   struct ofono_sim *sim = NULL;
+
+   sim_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SIM);
+
+   if (sim_atom != NULL) {
+   const char *imsi = ofono_sim_get_imsi(sim);
+   sim = __ofono_atom_get_data(sim_atom);
+   

[RFC PATCH 1/4] Added GPRS context provisioning driver API sources

2011-01-10 Thread Jukka Saunamaki
---
 Makefile.am  |4 +-
 include/gprs-provision.h |   73 +
 src/gprs-provision.c |  133 ++
 3 files changed, 208 insertions(+), 2 deletions(-)
 create mode 100644 include/gprs-provision.h
 create mode 100644 src/gprs-provision.c

diff --git a/Makefile.am b/Makefile.am
index 8ad01cd..0f330a7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,7 +15,7 @@ include_HEADERS = include/log.h include/plugin.h 
include/history.h \
include/radio-settings.h include/stk.h \
include/audio-settings.h include/nettime.h \
include/ctm.h include/cdma-voicecall.h \
-   include/cdma-sms.h
+   include/cdma-sms.h include/gprs-provision.h
 
 nodist_include_HEADERS = include/version.h
 
@@ -331,7 +331,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) 
src/ofono.ver \
src/nettime.c src/stkagent.c src/stkagent.h \
src/simfs.c src/simfs.h src/audio-settings.c \
src/smsagent.c src/smsagent.h src/ctm.c \
-   src/cdma-voicecall.c
+   src/cdma-voicecall.c src/gprs-provision.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/include/gprs-provision.h b/include/gprs-provision.h
new file mode 100644
index 000..97e356b
--- /dev/null
+++ b/include/gprs-provision.h
@@ -0,0 +1,73 @@
+/*
+ *
+ *  oFono - Open Telephony stack for Linux
+ *
+ *  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
+ *
+ */
+
+#ifndef __OFONO_GPRS_PROVISION_H
+#define __OFONO_GPRS_PROVISION_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#include gprs-context.h
+
+struct ofono_gprs_provisioning_data {
+   enum ofono_gprs_context_type type;
+   enum ofono_gprs_proto proto;
+   gchar *name;
+   gchar *apn;
+   gchar *username;
+   gchar *password;
+   gchar *message_proxy;
+   gchar *message_center;
+};
+
+/*
+ * Callback from provisioning plugin.
+ * settings: list of struct ofono_gprs_provisioning_data
+ *
+ * It is responsibility of callback function to free settings-list
+ * settings-list elements must be freed with 
ofono_gprs_provisioning_data_free()
+ */
+typedef void (*ofono_gprs_provision_cb_t)(GSList *settings, void *userdata);
+
+struct ofono_gprs_provision_driver {
+   const char *name;
+   int priority;
+   void (*get_settings) (struct ofono_modem *modem,
+   ofono_gprs_provision_cb_t cb,
+   void *userdata);
+};
+
+/* For provisioning drivers/plugins */
+int ofono_gprs_provision_driver_register(const struct 
ofono_gprs_provision_driver *driver);
+void ofono_gprs_provision_driver_unregister(const struct 
ofono_gprs_provision_driver *driver);
+
+/* For gprs */
+void ofono_gprs_provision_get_settings(struct ofono_modem *modem,
+   ofono_gprs_provision_cb_t cb,
+   void *data);
+void ofono_gprs_provisioning_data_free(struct ofono_gprs_provisioning_data 
*data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_GPRS_PROVISION_H */
diff --git a/src/gprs-provision.c b/src/gprs-provision.c
new file mode 100644
index 000..c143fb6
--- /dev/null
+++ b/src/gprs-provision.c
@@ -0,0 +1,133 @@
+/*
+ *
+ *  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 glib.h

[RFC PATCH 3/4] sim: add ofono_sim_get_mnc_length

2011-01-10 Thread Jukka Saunamaki
---
 include/sim.h |1 +
 src/sim.c |8 
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 7860e24..9b21f2e 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -173,6 +173,7 @@ void ofono_sim_set_data(struct ofono_sim *sim, void *data);
 void *ofono_sim_get_data(struct ofono_sim *sim);
 
 const char *ofono_sim_get_imsi(struct ofono_sim *sim);
+unsigned int ofono_sim_get_mnc_length(struct ofono_sim *sim);
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
 
 enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase(struct ofono_sim *sim);
diff --git a/src/sim.c b/src/sim.c
index 335f611..e9b1688 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -1913,6 +1913,14 @@ const char *ofono_sim_get_imsi(struct ofono_sim *sim)
return sim-imsi;
 }
 
+unsigned int ofono_sim_get_mnc_length(struct ofono_sim *sim)
+{
+   if (sim == NULL)
+   return 0;
+
+   return sim-mnc_length;
+}
+
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim)
 {
if (sim == NULL)
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCHv2 1/4] Automatic provisioning of GPRS context settings

2011-01-04 Thread Jukka Saunamaki
Hello Marcel,

 the oFono plugins work like kernel modules. They are pretty much
 generic. Inside the init function you can a driver register function and
 inside the exit function, you call the driver unregister function.

Right, that seems clear enough.

 static int setup_context(struct ofono_gprs_primary_context *context)
 {
   ...
 
   return 0;
 }
 
 static const ofono_gprs_provision_driver driver {
   .name = test,
   .setup_context = setup_context,
 };

I guess that current struct ofono_gprs_primary_context* is not enough
for provisioning data, it is missing at least name, MMS proxy and server
information. Should those (and whatever might be needed in future) be
added into that struct, or should we define some 
struct ofono_gprs_provisioning_data {
struct ofono_gprs_primary_context pri;
char name[MAX_CONTEXT_NAME_LENGTH + 1];
char message_proxy[MAX_MESSAGE_PROXY_LENGTH + 1];
char message_center[MAX_MESSAGE_CENTER_LENGTH + 1]; 
}
struct pri_context in gprs.c contains everything, but has extra
gprs-internal stuff.  

Also setup_context() needs ofono_gprs_context_type as in-parameter.


And a question about the priorities, if there is more than one
provisioning plugin: would plugins be called in priority order, and
after first returns something, rest would not be called?

--Jukka


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCHv2 1/4] Automatic provisioning of GPRS context settings

2011-01-03 Thread Jukka Saunamaki
Hello

On Mon, 2011-01-03 at 10:57 +0200, Kalle Valo wrote:
 Jukka Saunamaki jukka.saunam...@nokia.com writes:
  Settings database is an XML formatted file (combination of all
  xml-files in a directory), containing one element per settings for a
  specific type of GPRS context (internet, mms)
 
  Example:
  ?xml version=1.0?
  settings
  access type=internet mcc=246 mnc=81 spn=oFono name=Phonesim 
  Internet-GPRS apn=internet.apn/
  access type=mms mcc=246 mnc=81 spn=oFono name=Phonesim MMS-GPRS 
  apn=mms.apn protocol=ipv4 username=mmsuser password=mmspass 
  proxy=10.11.12.13:8080 mmsserver=http://mms.example.com:8000/
  /settings
 
 The format here doesn't look very extensible to me, more like csv with
 steroids and not proper xml. Any particular reason why you can't use the
 same format as in mobile-broadband-provider-info?
 
 http://git.gnome.org/browse/mobile-broadband-provider-info/tree/serviceproviders.xml

Well, my intention was to make format simple and fast to parse, but
still be extensible enough, which I think my proposed format fulfills. 

These access-elements contain just data needed for GPRS context
settings (as attributes), and if there is need for any other operator
specific provisioning information, you can always add separate elements,
this is still proper XML.

--Jukka
 


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCHv2 1/4] Automatic provisioning of GPRS context settings

2011-01-03 Thread Jukka Saunamaki
Hello

  Well, my intention was to make format simple and fast to parse, but
  still be extensible enough, which I think my proposed format fulfills. 
 
  These access-elements contain just data needed for GPRS context
  settings (as attributes), and if there is need for any other operator
  specific provisioning information, you can always add separate elements,
  this is still proper XML.
 
 But IMHO it is really ugly and not a properly designed XML.

Well, to me it looks simple, compact and clean, and most certainly
provides all necessary extensibility any XML format provides.  

 Again, why not use mobile-broadband-provider-info DTD? If there's something
 missing, I'm sure maintainers are willing to extend it. No need to
 reinvent the wheel.

In this format biggest thing that I see missing is type of access point
(internet,mms,lte), protocol (for IPv6) and mms-server (or
homepage). And I assume name of provider could be interpreted as
SPN for provisioning.

The good point of using mobile-broadband-provider-info is that it would
indeed provide existing database for testing purposes. For product
creation, manufacturers will anyway create their own databases, and
there the format does not matter much.

The problem using this format is, as I mentioned, more complex parsing. 
And also do we want to bind oFono into some externally defined data
format?

--Jukka
 



___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC PATCHv2 1/4] Automatic provisioning of GPRS context settings

2011-01-03 Thread Jukka Saunamaki
Hello Marcel,

On Mon, 2011-01-03 at 15:03 -0800, ext Marcel Holtmann wrote:
 thinking about this a bit more and with the background that there is
 already an existing public database, we might should just enable a
 provision driver inside the oFono core.
 
 Meaning that we can have multiple implementations of different databases
 with just different priorities. Each nicely separated in their own
 plugin and we don't bother the oFono core with where to get the data
 from. So my idea would be that the oFono core just asks to provision a
 new context. If a plugin feels responsible, then it does so. If not then
 it stays empty.

 Running oFono on the desktop/netbook etc. it makes sense to use the
 current mobile broadband provider database. However on a phone that is a
 not so good database. And for you guys it would also be possible to
 continue using a CSV based format.

This sounds very good to me. Making provisioning modular makes a lot of
sense.

But I am not yet very familiar with oFono plugin architecture. Is there
some pattern in oFono code I could follow when implementing this, or
could you or someone provide some skeleton code how this should go?

In my patch (3/4) for gprs.c, I call get_operator_settings() (in
operator-settings.c), which returns list of gprs_access_settings, that
are then created as contexts. I assume now this  get_operator_settings()
would somehow call registered provisioning modules, that similarly would
return list of gprs_access_settings? Or should these plugins directly
call some new gprs atom interface to create the contexts?

--Jukka



___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[RFC PATCHv2 1/4] Automatic provisioning of GPRS context settings

2011-01-02 Thread Jukka Saunamaki
Hello

Here is another RFC patchset about implementing automatic provisioning of 
Internet and MMS GPRS context settings. (Internet Access Provider database 
TODO item).

In case there are no previously configured contexts found during gprs atom 
registration, this code tries to provision Internet and MMS contexts based on 
MCC, MNC and SPN (Service Provider Name) values read from SIM. Settings are 
read from an operator settings database.

Settings database is an XML formatted file (combination of all xml-files in a 
directory), containing one element per settings for a specific type of GPRS 
context (internet, mms)
Example:
?xml version=1.0?
settings
access type=internet mcc=246 mnc=81 spn=oFono name=Phonesim 
Internet-GPRS apn=internet.apn/
access type=mms mcc=246 mnc=81 spn=oFono name=Phonesim MMS-GPRS 
apn=mms.apn protocol=ipv4 username=mmsuser password=mmspass 
proxy=10.11.12.13:8080 mmsserver=http://mms.example.com:8000/
/settings


Provisioning logic: first try to find exact match for type,MCC,MNC and SPN. If 
that fails (or if SPN read from SIM is missing/empty), we select first match 
for type/MCC/MNC. If also that fails, an empty context is created (as 
currently).

Patches also add new function ofono_sim_get_mnc_length to SIM atom API
for figuring out MNC value.

--Jukka Saunamäki


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[RFC PATCHv2 2/4] operator-settings: Add GPRS context provisioning sources

2011-01-02 Thread Jukka Saunamaki
---
 Makefile.am |3 +-
 src/operator-settings.c |  314 +++
 src/operator-settings.h |   37 ++
 3 files changed, 353 insertions(+), 1 deletions(-)
 create mode 100644 src/operator-settings.c
 create mode 100644 src/operator-settings.h

diff --git a/Makefile.am b/Makefile.am
index 8a8555d..d0e47e5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -328,7 +328,8 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) 
src/ofono.ver \
src/nettime.c src/stkagent.c src/stkagent.h \
src/simfs.c src/simfs.h src/audio-settings.c \
src/smsagent.c src/smsagent.h src/ctm.c \
-   src/cdma-voicecall.c
+   src/cdma-voicecall.c \
+   src/operator-settings.c src/operator-settings.h
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/src/operator-settings.c b/src/operator-settings.c
new file mode 100644
index 000..4cc90d6
--- /dev/null
+++ b/src/operator-settings.c
@@ -0,0 +1,314 @@
+/*
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2009-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 stdio.h
+#include unistd.h
+#include stdlib.h
+#include glib.h
+
+#include ofono.h
+#include operator-settings.h
+
+#define MAX_PROXY_NAME_LENGTH 255
+
+struct parser_data {
+   const gchar *mcc;
+   const gchar *mnc;
+   GSList *candidates;
+};
+
+void gprs_access_settings_free(struct gprs_access_settings *settings)
+{
+   if (settings == NULL)
+   return;
+
+   g_free(settings-name);
+   g_free(settings-apn);
+   g_free(settings-username);
+   g_free(settings-password);
+   g_free(settings-proxy);
+   g_free(settings-mms_server);
+   g_free(settings-spn);
+   g_free(settings);
+}
+
+static enum ofono_gprs_context_type string_to_gprs_context_type(const char 
*str)
+{
+   if (str) {
+   if (strcasecmp(str, INTERNET) == 0)
+   return OFONO_GPRS_CONTEXT_TYPE_INTERNET;
+   if (strcasecmp(str, MMS) == 0)
+   return OFONO_GPRS_CONTEXT_TYPE_MMS;
+   }
+
+   return OFONO_GPRS_CONTEXT_TYPE_ANY;
+}
+
+/*
+ * Parse access element.
+ * Mandatory attributes in access: mcc, mnc, type, name
+ * If MCC/MNC matches, add entry to candidate setting list.
+ */
+static void settings_start_element_handler (GMarkupParseContext *context,
+   const gchar *element_name,
+   const gchar **attribute_names,
+   const gchar **attribute_values,
+   gpointer user_data,
+   GError **error)
+{
+   int i;
+   struct parser_data *parser = user_data;
+   struct gprs_access_settings *entry;
+   const char *mcc = NULL, *mnc = NULL;
+
+   if (strcasecmp(element_name, access) != 0)
+   return;
+
+   entry = g_try_malloc0(sizeof(*entry));
+   if (entry == NULL)
+   return;
+
+   for (i = 0; attribute_names[i]; i++) {
+
+   if (strcasecmp(attribute_names[i], mcc) == 0)
+   mcc = attribute_values[i];
+
+   if (strcasecmp(attribute_names[i], mnc) == 0)
+   mnc = attribute_values[i];
+
+   if (strcasecmp(attribute_names[i], spn) == 0)
+   entry-spn = g_strdup(attribute_values[i]);
+
+   if (strcasecmp(attribute_names[i], type) == 0)
+   entry-type = 
string_to_gprs_context_type(attribute_values[i]);
+
+   if (strcasecmp(attribute_names[i], apn) == 0)
+   entry-apn = g_strdup(attribute_values[i]);
+
+   if (strcasecmp(attribute_names[i], name) == 0)
+   entry-name = g_strdup(attribute_values[i]);
+
+   if (strcasecmp(attribute_names[i], username) == 0)
+   entry-username = g_strdup(attribute_values[i]);
+
+   if (strcasecmp(attribute_names[i], 

[RFC PATCHv2 1/4] sim: add ofono_sim_get_mnc_length

2011-01-02 Thread Jukka Saunamaki
---
 include/sim.h |1 +
 src/sim.c |8 
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 7860e24..3d0c6b7 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -173,6 +173,7 @@ void ofono_sim_set_data(struct ofono_sim *sim, void *data);
 void *ofono_sim_get_data(struct ofono_sim *sim);
 
 const char *ofono_sim_get_imsi(struct ofono_sim *sim);
+int ofono_sim_get_mnc_length(struct ofono_sim *sim);
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
 
 enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase(struct ofono_sim *sim);
diff --git a/src/sim.c b/src/sim.c
index 335f611..8210972 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -1913,6 +1913,14 @@ const char *ofono_sim_get_imsi(struct ofono_sim *sim)
return sim-imsi;
 }
 
+int ofono_sim_get_mnc_length(struct ofono_sim *sim)
+{
+   if (sim == NULL)
+   return 0;
+
+   return sim-mnc_length;
+}
+
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim)
 {
if (sim == NULL)
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[RFC PATCHv2 4/4] operator-settings: Example GPRS context settings file

2011-01-02 Thread Jukka Saunamaki
---
 examples/example-operator-settings.xml |   15 +++
 1 files changed, 15 insertions(+), 0 deletions(-)
 create mode 100644 examples/example-operator-settings.xml

diff --git a/examples/example-operator-settings.xml 
b/examples/example-operator-settings.xml
new file mode 100644
index 000..8927656
--- /dev/null
+++ b/examples/example-operator-settings.xml
@@ -0,0 +1,15 @@
+?xml version=1.0?
+!--
+   Example GPRS access point settings.
+   access-element must contain required attributes type=internet|mms,
+ mcc, mnc and name.
+   others: spn (Service Provider Name from SIM), apn (GPRS Access Point Name),
+ protocol=ipv4|ipv6 (others may be added), username, password, 
+ proxy (as address:port, for now mms only), mmsserver (as http-url, 
+ mms only).
+--
+
+settings
+access type=internet mcc=246 mnc=81 spn=oFono name=Phonesim 
Internet-GPRS apn=internet.apn/
+access type=mms mcc=246 mnc=81 spn=oFono name=Phonesim MMS-GPRS 
apn=mms.apn protocol=ipv4 username=mmsuser password=mmspass 
proxy=10.11.12.13:8080 mmsserver=http://mms.example.com:8000/
+/settings
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[RFC PATCHv2 3/4] gprs: add automatic context settings provisioning

2011-01-02 Thread Jukka Saunamaki
---
 src/gprs.c |  176 +++-
 1 files changed, 162 insertions(+), 14 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 58166f8..c9d4fb3 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -43,6 +43,9 @@
 #include common.h
 #include storage.h
 #include idmap.h
+#include util.h
+#include simutil.h
+#include operator-settings.h
 
 #define GPRS_FLAG_ATTACHING 0x1
 #define GPRS_FLAG_RECHECK 0x2
@@ -2261,6 +2264,84 @@ static void netreg_watch(struct ofono_atom *atom,
gprs_netreg_update(gprs);
 }
 
+static gboolean provision_contexts(struct ofono_gprs *gprs,
+   const char *mcc,
+   const char *mnc,
+   const char *spn)
+{
+   gboolean ret = FALSE;
+   GSList *settings, *sp;
+
+   settings = get_operator_settings(mcc, mnc, spn);
+
+   for (sp = settings; sp != NULL; sp = sp-next) {
+   unsigned int id;
+   struct pri_context *context = NULL;
+   struct gprs_access_settings *ap = sp-data;
+
+   /* Sanity check */
+   if (ap == NULL || ap-name == NULL) {
+   sp = sp-next;
+   continue;
+   }
+
+   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))
+   break;
+
+   context = pri_context_create(gprs, ap-name, ap-type);
+   DBG(Provisioned context %d '%s' %s, id, ap-name,
+   context ? created : creation failed);
+
+   if (context == NULL)
+   continue;
+
+   context-id = id;
+
+   if (ap-username != NULL)
+   strncpy(context-context.username, ap-username,
+   OFONO_GPRS_MAX_USERNAME_LENGTH);
+
+   if (ap-password != NULL)
+   strncpy(context-context.password, ap-password,
+   OFONO_GPRS_MAX_PASSWORD_LENGTH);
+
+   if (ap-apn != NULL)
+   strncpy(context-context.apn, ap-apn,
+   OFONO_GPRS_MAX_APN_LENGTH);
+
+   context-context.proto = ap-proto;
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-proxy != NULL)
+   strncpy(context-message_proxy, ap-proxy,
+   MAX_MESSAGE_PROXY_LENGTH);
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-mms_server != NULL)
+   strncpy(context-message_center, ap-mms_server,
+   MAX_MESSAGE_CENTER_LENGTH);
+
+   if (context_dbus_register(context) == TRUE) {
+   gprs-last_context_id = id;
+   gprs-contexts = g_slist_append(gprs-contexts,
+   context);
+   write_context_settings(gprs, context);
+   ret = TRUE;
+   }
+   }
+
+   g_slist_foreach(settings, (GFunc) gprs_access_settings_free, NULL);
+   g_slist_free(settings);
+
+   return ret;
+}
+
 static gboolean load_context(struct ofono_gprs *gprs, const char *group)
 {
char *name = NULL;
@@ -2454,13 +2535,16 @@ remove:
storage_sync(imsi, SETTINGS_STORE, gprs-settings);
 }
 
-void ofono_gprs_register(struct ofono_gprs *gprs)
+static void ofono_gprs_finish_register(struct ofono_gprs *gprs)
 {
+
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(gprs-atom);
const char *path = __ofono_atom_get_path(gprs-atom);
struct ofono_atom *netreg_atom;
-   struct ofono_atom *sim_atom;
+
+   if (gprs-contexts == NULL) /* Automatic provisioning failed */
+   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
 
if (!g_dbus_register_interface(conn, path,
OFONO_CONNECTION_MANAGER_INTERFACE,
@@ -2475,18 +2559,6 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
ofono_modem_add_interface(modem,
OFONO_CONNECTION_MANAGER_INTERFACE);
 
-   sim_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SIM);
-
-   if (sim_atom) {
-   struct ofono_sim *sim = __ofono_atom_get_data(sim_atom);
-   const char *imsi = ofono_sim_get_imsi(sim);
-
-   gprs_load_settings(gprs, imsi);
-   }
-
-   if (gprs-contexts == NULL)
-   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
-
gprs-netreg_watch = 

Re: [RFC PATCH 0/4] Automatic provisioning of GPRS context settings

2010-12-22 Thread Jukka Saunamaki

Hi

On 21/12/10 16:11, ext Marcel Holtmann wrote:

Settings database is CSV (comma separated values) formatted file(s)
with fields for: (type=INTERNET|MMS protocol=ipv4|ipv6)
MCC,MNC,SPN,type,UI name, APN, username, password, protocol, proxy IP address, 
proxy port, MMS server URL

e.g. file /etc/ofono/operator-settings/50-default.csv:
001,01,test,INTERNET,Network Tester GPRS,internet,,
246,81,oFono,INTERNET,Phonesim Internet,internet.apn,,,ipv4,,,
246,81,oFono,MMS,Phonesim 
MMS,mms.apn,mmsuser,mmspass,ipv4,10.10.10.10,8080,http://192.168.0.111:8002

This format is loosely based on what was used in Nokia N900 for
similar use.

I am really not set on a file format, but my obvious question is if we
don't wanna better use keyfile or XML based database since that are the
file formats we are currently using inside oFono. We have not used CSV
at all so far.

My vote would go for keyfile or XML since it is a bit more self
explanatory with its fields. And the order of values doesn't really
matter.

The one thing that I don't like about CSV is that you have no real
flexibility with its format. Especially coming think about that we might
have to extend this additional information for IMS or operator specific
behavior.


Good points. I suggested csv, because it is very simple and fast to 
parse, and it has proven to be good enough for this specific purpose. 
But, true, it is also very inflexible.
So, how about something like this XML format: (better element name 
suggestions welcome)


?xml version=1.0?
settings
access type=internet mcc=001 mnc=01 spn=test name=Example 
Internet GPRS apn=internet protocol=ipv4/
access type=mms mcc=001 mnc=01 spn=test name=Example MMS GPRS 
apn=mms proxy=10.11.12.13:8080 mmsserver=http://mms.example.com:8000/

access ... /
...
/settings

This would still be quite easy and fast to parse (using glib simple XML 
parser), would not be hugely larger in size and would allow easy adding 
of new attributes/values.


Also, do you or anybody have comments about the logic of provisioning, 
and changes to sim and gprs parts?


--Jukka Saunamäki

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[RFC PATCH 2/4] sim: add ofono_sim_get_mnc_length

2010-12-21 Thread Jukka Saunamaki
---
 include/sim.h |1 +
 src/sim.c |8 
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 7860e24..3d0c6b7 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -173,6 +173,7 @@ void ofono_sim_set_data(struct ofono_sim *sim, void *data);
 void *ofono_sim_get_data(struct ofono_sim *sim);
 
 const char *ofono_sim_get_imsi(struct ofono_sim *sim);
+int ofono_sim_get_mnc_length(struct ofono_sim *sim);
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
 
 enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase(struct ofono_sim *sim);
diff --git a/src/sim.c b/src/sim.c
index 6217a25..4cfce4a 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -1911,6 +1911,14 @@ const char *ofono_sim_get_imsi(struct ofono_sim *sim)
return sim-imsi;
 }
 
+int ofono_sim_get_mnc_length(struct ofono_sim *sim)
+{
+   if (sim == NULL)
+   return 0;
+
+   return sim-mnc_length;
+}
+
 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim)
 {
if (sim == NULL)
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[RFC PATCH 4/4] operator-settings: Example GPRS context settings file

2010-12-21 Thread Jukka Saunamaki
---
 examples/example-operator-settings.csv |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)
 create mode 100644 examples/example-operator-settings.csv

diff --git a/examples/example-operator-settings.csv 
b/examples/example-operator-settings.csv
new file mode 100644
index 000..7493894
--- /dev/null
+++ b/examples/example-operator-settings.csv
@@ -0,0 +1,9 @@
+# Example GPRS access point settings
+# Format: (type=INTERNET|MMS protocol=ipv4|ipv6)
+# MCC,MNC,SPN,type,UI name, APN, username, password, protocol, proxy IP 
address, proxy port, MMS server URL
+#
+001,01,TEST,INTERNET,Network Tester GPRS,internet,,
+246,81,oFono,INTERNET,Phonesim Internet-GPRS,internet.apn,,,ipv4,,,
+246,81,oFono,MMS,Phonesim 
MMS-GPRS,mms.apn,mmsuser,mmspass,ipv4,10.10.10.10,8080,http://192.168.0.111:8002
+888,009,Example,INTERNET,Example Operator Internet,internet
+888,009,Example,MMS,Example Operator 
MMS,mms,,,ipv4,10.11.12.13,8081,http://mms.example.com:8000
-- 
1.7.1

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[RFC PATCH 0/4] Automatic provisioning of GPRS context settings

2010-12-21 Thread Jukka Saunamaki
Hello

Here is a first attempt to implement automatic provisioning of
Internet and MMS GPRS context settings. (Internet Access Provider
database TODO item).

In case there are no previously configured contexts found during gprs
atom registration, this code tries to provision Internet and MMS
contexts based on MCC, MNC and SPN (Service Provider Name) values read
from SIM. Settings are read from an operator settings database.

Settings database is CSV (comma separated values) formatted file(s)
with fields for: (type=INTERNET|MMS protocol=ipv4|ipv6)
MCC,MNC,SPN,type,UI name, APN, username, password, protocol, proxy IP address, 
proxy port, MMS server URL

e.g. file /etc/ofono/operator-settings/50-default.csv:
001,01,test,INTERNET,Network Tester GPRS,internet,,
246,81,oFono,INTERNET,Phonesim Internet,internet.apn,,,ipv4,,,
246,81,oFono,MMS,Phonesim 
MMS,mms.apn,mmsuser,mmspass,ipv4,10.10.10.10,8080,http://192.168.0.111:8002

This format is loosely based on what was used in Nokia N900 for
similar use.

Provisioning logic goes, that first we try to find exact match for
type,MCC,MNC and SPN. If that fails (or if SPN read from SIM is
missing/empty), we select first match for type/MCC/MNC. If also that
fails, an empty context is created (as currently).

Patches also add new function ofono_sim_get_mnc_length to SIM atom API
for figuring out MNC value.

--Jukka Saunamäki


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[RFC PATCH 3/4] gprs: add automatic context settings provisioning

2010-12-21 Thread Jukka Saunamaki
---
 src/gprs.c |  169 +++-
 1 files changed, 155 insertions(+), 14 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 58166f8..f2f2c9f 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -43,6 +43,9 @@
 #include common.h
 #include storage.h
 #include idmap.h
+#include util.h
+#include simutil.h
+#include operator-settings.h
 
 #define GPRS_FLAG_ATTACHING 0x1
 #define GPRS_FLAG_RECHECK 0x2
@@ -2261,6 +2264,77 @@ static void netreg_watch(struct ofono_atom *atom,
gprs_netreg_update(gprs);
 }
 
+static gboolean provision_contexts(struct ofono_gprs *gprs,
+   const char *mcc,
+   const char *mnc,
+   const char *spn)
+{
+   gboolean ret = FALSE;
+   GSList *settings, *sp;
+
+   settings = get_operator_settings(mcc, mnc, spn);
+
+   for (sp = settings; sp != NULL; sp = sp-next) {
+   unsigned int id;
+   struct pri_context *context = NULL;
+   struct gprs_access_settings *ap = sp-data;
+
+   /* Sanity check */
+   if (ap == NULL || ap-name == NULL || ap-username == NULL ||
+   ap-password == NULL || ap-apn == NULL) {
+   sp = sp-next;
+   continue;
+   }
+
+   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))
+   break;
+
+   context = pri_context_create(gprs, ap-name, ap-type);
+   DBG(Provisioned context %d '%s' %s, id, ap-name,
+   context ? created : creation failed);
+
+   if (context == NULL)
+   continue;
+
+   context-id = id;
+   strncpy(context-context.username, ap-username,
+   OFONO_GPRS_MAX_USERNAME_LENGTH);
+   strncpy(context-context.password, ap-password,
+   OFONO_GPRS_MAX_PASSWORD_LENGTH);
+   strncpy(context-context.apn, ap-apn,
+   OFONO_GPRS_MAX_APN_LENGTH);
+   context-context.proto = ap-proto;
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-proxy != NULL)
+   strncpy(context-message_proxy, ap-proxy,
+   MAX_MESSAGE_PROXY_LENGTH);
+
+   if (ap-type == OFONO_GPRS_CONTEXT_TYPE_MMS 
+   ap-mms_server != NULL)
+   strncpy(context-message_center, ap-mms_server,
+   MAX_MESSAGE_CENTER_LENGTH);
+
+   if (context_dbus_register(context) == TRUE) {
+   gprs-last_context_id = id;
+   gprs-contexts = g_slist_append(gprs-contexts,
+   context);
+   write_context_settings(gprs, context);
+   ret = TRUE;
+   }
+   }
+   g_slist_foreach(settings, (GFunc) gprs_access_settings_free, NULL);
+   g_slist_free(settings);
+
+   return ret;
+}
+
 static gboolean load_context(struct ofono_gprs *gprs, const char *group)
 {
char *name = NULL;
@@ -2454,13 +2528,16 @@ remove:
storage_sync(imsi, SETTINGS_STORE, gprs-settings);
 }
 
-void ofono_gprs_register(struct ofono_gprs *gprs)
+static void ofono_gprs_finish_register(struct ofono_gprs *gprs)
 {
+
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(gprs-atom);
const char *path = __ofono_atom_get_path(gprs-atom);
struct ofono_atom *netreg_atom;
-   struct ofono_atom *sim_atom;
+
+   if (gprs-contexts == NULL) /* Automatic provisioning failed */
+   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
 
if (!g_dbus_register_interface(conn, path,
OFONO_CONNECTION_MANAGER_INTERFACE,
@@ -2475,18 +2552,6 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
ofono_modem_add_interface(modem,
OFONO_CONNECTION_MANAGER_INTERFACE);
 
-   sim_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SIM);
-
-   if (sim_atom) {
-   struct ofono_sim *sim = __ofono_atom_get_data(sim_atom);
-   const char *imsi = ofono_sim_get_imsi(sim);
-
-   gprs_load_settings(gprs, imsi);
-   }
-
-   if (gprs-contexts == NULL)
-   add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
-
gprs-netreg_watch = __ofono_modem_add_atom_watch(modem,
OFONO_ATOM_TYPE_NETREG,