[PATCH] voicecall: Add check in dial_request_finish

2010-08-30 Thread Zhenhua Zhang
To avoid signal 11 if no dial_req exists.
---
 src/voicecall.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/voicecall.c b/src/voicecall.c
index 6ad58ad..1313129 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -220,6 +220,9 @@ static void dial_request_finish(struct ofono_voicecall *vc, 
gboolean callback)
 {
struct dial_request *dial_req = vc-dial_req;
 
+   if (dial_req == NULL)
+   return;
+
if (callback  dial_req-cb)
dial_req-cb(dial_req-call ? dial_req-call-call : NULL,
dial_req-user_data);
-- 
1.7.0.4

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


[PATCH 1/1] hfp: Add faked sim driver to support SIM ready

2010-08-30 Thread Zhenhua Zhang
HFP modem doesn't have IMSI at all. In order to notify SIM ready to the
core, we create a special sim driver with a faked IMSI number.
---
 Makefile.am |3 +-
 drivers/hfpmodem/hfpmodem.c |2 +
 drivers/hfpmodem/hfpmodem.h |3 +
 drivers/hfpmodem/sim.c  |  114 +++
 plugins/hfp.c   |6 ++
 5 files changed, 127 insertions(+), 1 deletions(-)
 create mode 100644 drivers/hfpmodem/sim.c

diff --git a/Makefile.am b/Makefile.am
index f31180e..a1ec0e7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -187,7 +187,8 @@ builtin_sources += drivers/atmodem/atutil.h \
drivers/hfpmodem/hfpmodem.c \
drivers/hfpmodem/voicecall.c \
drivers/hfpmodem/network-registration.c \
-   drivers/hfpmodem/call-volume.c
+   drivers/hfpmodem/call-volume.c \
+   drivers/hfpmodem/sim.c
 
 builtin_modules += mbmmodem
 builtin_sources += drivers/atmodem/atutil.h \
diff --git a/drivers/hfpmodem/hfpmodem.c b/drivers/hfpmodem/hfpmodem.c
index 4471a7b..ecbabe3 100644
--- a/drivers/hfpmodem/hfpmodem.c
+++ b/drivers/hfpmodem/hfpmodem.c
@@ -44,6 +44,7 @@ static int hfpmodem_init(void)
hfp_voicecall_init();
hfp_netreg_init();
hfp_call_volume_init();
+   hfp_sim_init();
 
return 0;
 }
@@ -53,6 +54,7 @@ static void hfpmodem_exit(void)
hfp_voicecall_exit();
hfp_netreg_exit();
hfp_call_volume_exit();
+   hfp_sim_exit();
 }
 
 OFONO_PLUGIN_DEFINE(hfpmodem, Hands-Free Profile Driver, VERSION,
diff --git a/drivers/hfpmodem/hfpmodem.h b/drivers/hfpmodem/hfpmodem.h
index bf5d563..631f773 100644
--- a/drivers/hfpmodem/hfpmodem.h
+++ b/drivers/hfpmodem/hfpmodem.h
@@ -80,3 +80,6 @@ extern void hfp_call_volume_exit();
 
 extern void hfp_voicecall_init();
 extern void hfp_voicecall_exit();
+
+extern void hfp_sim_init();
+extern void hfp_sim_exit();
diff --git a/drivers/hfpmodem/sim.c b/drivers/hfpmodem/sim.c
new file mode 100644
index 000..e42cfb9
--- /dev/null
+++ b/drivers/hfpmodem/sim.c
@@ -0,0 +1,114 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
+ *
+ *  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
+
+#define _GNU_SOURCE
+#include string.h
+#include stdlib.h
+#include stdio.h
+
+#include glib.h
+
+#include ofono/log.h
+#include ofono/modem.h
+#include ofono/sim.h
+
+#include gatchat.h
+#include gatresult.h
+#include hfpmodem.h
+
+static void hfp_read_imsi(struct ofono_sim *sim, ofono_sim_imsi_cb_t cb,
+   void *data)
+{
+   struct ofono_error error;
+   const char *imsi = 1234567890123456;
+
+   DBG(%s, imsi);
+
+   /*
+* Return the faked IMSI since HFP doesn't have IMSI.
+*/
+   error.type = OFONO_ERROR_TYPE_NO_ERROR;
+   cb(error, imsi, data);
+}
+
+static void hfp_sim_read_binary(struct ofono_sim *sim, int fileid,
+   int start, int length,
+   ofono_sim_read_cb_t cb, void *data)
+{
+   DBG();
+
+   CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
+}
+
+static void hfp_sim_read_info(struct ofono_sim *sim, int fileid,
+   ofono_sim_file_info_cb_t cb,
+   void *data)
+{
+   DBG();
+
+   CALLBACK_WITH_FAILURE(cb, -1, -1, -1, NULL, data);
+}
+
+static int hfp_sim_probe(struct ofono_sim *sim, unsigned int vendor,
+   void *data)
+{
+   ofono_sim_register(sim);
+
+   return 0;
+}
+
+static void hfp_sim_remove(struct ofono_sim *sim)
+{
+}
+
+static struct ofono_sim_driver driver = {
+   .name   = hfpmodem,
+   .probe  = hfp_sim_probe,
+   .remove = hfp_sim_remove,
+   .read_file_info = hfp_sim_read_info,
+   .read_file_transparent  = hfp_sim_read_binary,
+   .read_file_linear   = NULL,
+   .read_file_cyclic   = NULL,
+   .write_file_transparent = NULL,
+   .write_file_linear  = NULL,
+   .write_file_cyclic  = NULL,
+   .read_imsi  = hfp_read_imsi,
+   .query_passwd_state 

[PATCH 0/1] Add faked sim driver for hfp modem

2010-08-30 Thread Zhenhua Zhang
Hi,

The hfp modem driver doesn't work after recent sim related changes. So that I 
fake a sim driver for hfpmodem.

Please review it. Thanks!

Regards,
Zhenhua

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


Re: [PATCH 2/2] Add: n900modem driver

2010-08-30 Thread Aki Niemi
Hi,

2010/8/17 Denis Kenzior denk...@gmail.com:
 Why are we doing this inside n900modem?  Can't we simply:

 1. Make isimodem/isimodem.c register these (just like atmodem, stemodem,
 mbmmodem, etc does)
 2. Rip out the actual modem driver out of isimodem/isimodem.c
 3. Have plugins/n900.c contain the modem driver?

I think you mean rip out the modem driver in isimodem/isimodem.c, and
put it in usbpnmodem.c? I think that makes sense.

 -     /* Expect phonet interface name usbpnidx */
 -     if (strncmp(ifname, usbpn, 5) ||
 -             ifname[5 + strspn(ifname + 5, 0123456789)])
 +     if (match_ifname(usbpn, ifname)) {
 +             driver = isimodem;
 +             address = PN_DEV_PC;
 +     } else if (strcmp(phonet0, ifname) == 0) {
 +#if HAVE_N900MODEM
 +             driver = n900modem;
 +#else
 +             driver = isimodem;
 +#endif

 And this really needs to go...

Couldn't we rather either build support for native modem or USB
modems, but not both at the same time? In other words, build only one
or the other of these two plugins.

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


[PATCH] Fix crash in voicecall atom

2010-08-30 Thread Aki Niemi
Hot-unplugging isimodem causes a crash in the voicecall atom.
---
 src/voicecall.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/voicecall.c b/src/voicecall.c
index 6ad58ad..52311b9 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -220,6 +220,9 @@ static void dial_request_finish(struct ofono_voicecall *vc, 
gboolean callback)
 {
struct dial_request *dial_req = vc-dial_req;
 
+   if (!dial_req)
+   return;
+
if (callback  dial_req-cb)
dial_req-cb(dial_req-call ? dial_req-call-call : NULL,
dial_req-user_data);
-- 
1.7.0.4

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


[g_isi_send RFC 1/3] gisi: added g_isi_send() and g_isi_vsend()

2010-08-30 Thread Pekka . Pessi
From: Pekka Pessi pekka.pe...@nokia.com

Include a finalize function in GIsiRequest
---
 gisi/client.c |   97 ++--
 gisi/client.h |   12 +++
 2 files changed, 98 insertions(+), 11 deletions(-)

diff --git a/gisi/client.c b/gisi/client.c
index 640484d..a1aa709 100644
--- a/gisi/client.c
+++ b/gisi/client.c
@@ -52,6 +52,7 @@ struct _GIsiRequest {
guint timeout;
GIsiResponseFunc func;
void *data;
+   GDestroyNotify notify;
 };
 
 struct _GIsiIndication {
@@ -240,6 +241,9 @@ static void g_isi_cleanup_req(void *data)
req-func(req-client, NULL, 0, 0, req-data);
req-client-error = 0;
 
+   if (req-notify)
+   req-notify(req-data);
+
if (req-timeout  0)
g_source_remove(req-timeout);
 
@@ -329,31 +333,90 @@ GIsiRequest *g_isi_request_make(GIsiClient *client, const 
void *__restrict buf,
size_t len, unsigned timeout,
GIsiResponseFunc cb, void *opaque)
 {
+   return g_isi_send(client, buf, len, timeout, cb, opaque, NULL);
+}
+
+/**
+ * Make an ISI request and register a callback to process the response(s) to
+ * the resulting transaction.
+ * @param cl ISI client (from g_isi_client_create())
+ * @param iov scatter-gather array to the request payload
+ * @param iovlen number of vectors in the scatter-gather array
+ * @param timeout timeout in seconds
+ * @param cb callback to process response(s)
+ * @param opaque data for the callback
+ */
+GIsiRequest *g_isi_request_vmake(GIsiClient *client, const struct iovec *iov,
+   size_t iovlen, unsigned timeout,
+   GIsiResponseFunc func, void *opaque)
+{
+   return g_isi_vsend(client, iov, iovlen, timeout, func, opaque, NULL);
+}
+
+/**
+ * Send an ISI request and register a callback to process the response(s) to
+ * the resulting transaction.
+ *
+ * If @a notify is non-NULL but @a opaque is NULL, @a errno is not set and a
+ * NULL pointer is returned.
+ *
+ * @param cl ISI client (from g_isi_client_create())
+ * @param buf pointer to request payload
+ * @param len request payload byte length
+ * @param timeout timeout in seconds
+ * @param cb callback to process response(s)
+ * @param opaque data for the callback
+ * @param notify finalizer function for the @a opaque data (may be NULL)
+ *
+ * @return
+ * A pointer to a newly created GIsiRequest.
+ *
+ * @errors
+ * If an error occurs, @a notify is called, @a errno is set accordingly and
+ * a NULL pointer is returned.
+ */
+GIsiRequest *g_isi_send(GIsiClient *client,
+   const void *__restrict buf, size_t len,
+   unsigned timeout,
+   GIsiResponseFunc cb, void *opaque,
+   GDestroyNotify notify)
+{
const struct iovec iov = {
.iov_base = (void *)buf,
.iov_len = len,
};
 
-   if (!client)
-   return NULL;
-
-   return g_isi_request_vmake(client, iov, 1, timeout, cb, opaque);
+   return g_isi_vsend(client, iov, 1, timeout, cb, opaque, notify);
 }
 
+
 /**
- * Make an ISI request and register a callback to process the response(s) to
+ * Send an ISI request and register a callback to process the response(s) to
  * the resulting transaction.
+ *
+ * If @a notify is non-NULL but @a opaque is NULL, @a errno is not set and a
+ * NULL pointer is returned.
+ *
  * @param cl ISI client (from g_isi_client_create())
  * @param iov scatter-gather array to the request payload
  * @param iovlen number of vectors in the scatter-gather array
  * @param timeout timeout in seconds
  * @param cb callback to process response(s)
  * @param opaque data for the callback
+ * @param notify finalizer function for the @a opaque data (may be NULL)
+ *
+ * @return
+ * A pointer to a newly created GIsiRequest.
+ *
+ * @errors
+ * If an error occurs, @a notify is called, @a errno is set accordingly and
+ * a NULL pointer is returned.
  */
-GIsiRequest *g_isi_request_vmake(GIsiClient *client,
-   const struct iovec *__restrict iov,
-   size_t iovlen, unsigned timeout,
-   GIsiResponseFunc cb, void *opaque)
+GIsiRequest *g_isi_vsend(GIsiClient *client,
+   const struct iovec *__restrict iov,
+   size_t iovlen, unsigned timeout,
+   GIsiResponseFunc cb, void *opaque,
+   GDestroyNotify notify)
 {
struct iovec _iov[1 + iovlen];
struct sockaddr_pn dst = {
@@ -375,21 +438,25 @@ GIsiRequest *g_isi_request_vmake(GIsiClient *client,
GIsiRequest *req;
GIsiRequest **old;
 
+   if (opaque == NULL  notify != NULL)
+   return NULL;
+
if (!client) {
  

[sim-reset-pin-v2 1/3] sim: pass reset password type to driver

2010-08-30 Thread Pekka . Pessi
From: Pekka Pessi pekka.pe...@nokia.com

---
 include/sim.h |5 +++--
 src/sim.c |9 +++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 36a99b9..d3e564c 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -143,8 +143,9 @@ struct ofono_sim_driver {
ofono_sim_passwd_cb_t cb, void *data);
void (*send_passwd)(struct ofono_sim *sim, const char *passwd,
ofono_sim_lock_unlock_cb_t cb, void *data);
-   void (*reset_passwd)(struct ofono_sim *sim, const char *puk,
-   const char *passwd,
+   void (*reset_passwd)(struct ofono_sim *sim,
+   enum ofono_sim_password_type type,
+   const char *puk, const char *passwd,
ofono_sim_lock_unlock_cb_t cb, void *data);
void (*change_passwd)(struct ofono_sim *sim,
enum ofono_sim_password_type type,
diff --git a/src/sim.c b/src/sim.c
index d0b5988..5e918f2 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -747,8 +747,13 @@ static DBusMessage *sim_reset_pin(DBusConnection *conn, 
DBusMessage *msg,
 
type = sim_string_to_passwd(typestr);
 
-   if (type == OFONO_SIM_PASSWORD_NONE || type != sim-pin_type)
+   switch (type) {
+   case OFONO_SIM_PASSWORD_SIM_PIN:
+   case OFONO_SIM_PASSWORD_SIM_PIN2:
+   break;
+   default:
return __ofono_error_invalid_format(msg);
+   }
 
if (!is_valid_pin(puk, PIN_TYPE_PUK))
return __ofono_error_invalid_format(msg);
@@ -757,7 +762,7 @@ static DBusMessage *sim_reset_pin(DBusConnection *conn, 
DBusMessage *msg,
return __ofono_error_invalid_format(msg);
 
sim-pending = dbus_message_ref(msg);
-   sim-driver-reset_passwd(sim, puk, pin, sim_enter_pin_cb, sim);
+   sim-driver-reset_passwd(sim, type, puk, pin, sim_enter_pin_cb, sim);
 
return NULL;
 }
-- 
1.7.0.4

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


[sim-reset-pin-v2 0/3] pass reset password type to driver

2010-08-30 Thread Pekka . Pessi
Hi all,

Here is a less controversial version of the SIM API change.

The reset password type is passed down to the driver.

The generic atmodem sim driver caches the pin type from last CPIN?, and if
it is not PUK, returns an error.

A quirk is added for mbm so it will try to trigger the +CPIN: SIM PUK/PUK2
response.

--Pekka

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


[sim-reset-pin-v2 3/3] atmodem/sim: add mbm quirk for PIN/PIN2 reset

2010-08-30 Thread Pekka . Pessi
From: Pekka Pessi pekka.pe...@nokia.com

Trigger prompt for the correct PUK on mbm.
---
 drivers/atmodem/sim.c |  169 +++--
 1 files changed, 136 insertions(+), 33 deletions(-)

diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index a80891c..1ef4342 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -621,39 +621,6 @@ error:
CALLBACK_WITH_FAILURE(cb, data);
 }
 
-static void at_pin_send_puk(struct ofono_sim *sim,
-   enum ofono_sim_password_type type,
-   const char *puk, const char *passwd,
-   ofono_sim_lock_unlock_cb_t cb, void *data)
-{
-   struct sim_data *sd = ofono_sim_get_data(sim);
-   struct cb_data *cbd = cb_data_new(cb, data);
-   char buf[64];
-   int ret;
-
-   if (!cbd)
-   goto error;
-
-   if (type != OFONO_SIM_PASSWORD_SIM_PIN ||
-   sd-cpin_type != OFONO_SIM_PASSWORD_SIM_PUK)
-   goto error;
-
-   snprintf(buf, sizeof(buf), AT+CPIN=\%s\,\%s\, puk, passwd);
-
-   ret = g_at_chat_send(sd-chat, buf, none_prefix,
-   at_lock_unlock_cb, cbd, g_free);
-
-   memset(buf, 0, sizeof(buf));
-
-   if (ret  0)
-   return;
-
-error:
-   g_free(cbd);
-
-   CALLBACK_WITH_FAILURE(cb, data);
-}
-
 static const char *const at_clck_cpwd_fac[] = {
[OFONO_SIM_PASSWORD_SIM_PIN] = SC,
[OFONO_SIM_PASSWORD_SIM_PIN2] = P2,
@@ -699,6 +666,142 @@ error:
CALLBACK_WITH_FAILURE(cb, data);
 }
 
+struct at_pin_reset_data {
+   struct cb_data base;
+   enum ofono_sim_password_type type;
+   char puk[9];
+   char pin[9];
+};
+
+static void at_pin_query_result(const struct ofono_error *error,
+   enum ofono_sim_password_type pin_type,
+   void *data)
+{
+   struct at_pin_reset_data *cbd = data;
+   struct sim_data *sd = ofono_sim_get_data(cbd-base.user);
+   ofono_sim_lock_unlock_cb_t cb = cbd-base.cb;
+   void *user_data = cbd-base.data;
+   char buf[64];
+   int ret;
+
+   if (error-type != OFONO_ERROR_TYPE_NO_ERROR)
+   goto failed;
+
+   switch (pin_type) {
+   case OFONO_SIM_PASSWORD_SIM_PUK:
+   if (cbd-type != OFONO_SIM_PASSWORD_SIM_PIN)
+   goto failed;
+   break;
+   case OFONO_SIM_PASSWORD_SIM_PUK2:
+   if (cbd-type != OFONO_SIM_PASSWORD_SIM_PIN2)
+   goto failed;
+   break;
+   default:
+   goto failed;
+   }
+
+   snprintf(buf, sizeof(buf), AT+CPIN=\%s\,\%s\, cbd-puk, cbd-pin);
+
+   memset(cbd-pin, 0, sizeof(cbd-pin));
+   memset(cbd-puk, 0, sizeof(cbd-puk));
+
+   ret = g_at_chat_send(sd-chat, buf, none_prefix,
+   at_lock_unlock_cb, cbd, g_free);
+
+   memset(buf, 0, sizeof(buf));
+
+   if (ret  0)
+   return;
+
+failed:
+   g_free(cbd);
+   CALLBACK_WITH_FAILURE(cb, user_data);
+}
+
+static void at_trigger_puk(struct ofono_sim *sim,
+   enum ofono_sim_password_type type,
+   const char *puk, const char *pin,
+   ofono_sim_lock_unlock_cb_t cb, void *data)
+{
+   struct sim_data *sd = ofono_sim_get_data(sim);
+   struct at_pin_reset_data *cbd;
+   char buf[64];
+
+   if (type != OFONO_SIM_PASSWORD_SIM_PIN 
+   type == OFONO_SIM_PASSWORD_SIM_PIN2)
+   goto error;
+
+   cbd = g_new0(struct at_pin_reset_data, 1);
+   if (!cbd)
+   goto error;
+
+   cbd-base.cb = cb;
+   cbd-base.data = data;
+   cbd-base.user = sim;
+   cbd-type = type;
+   strcpy(cbd-puk, puk);
+   strcpy(cbd-pin, pin);
+
+   /* We need to trigger AT+CPIN? to return SIM PUK or SIM PUK2 */
+
+   snprintf(buf, sizeof(buf), AT+CPWD=\%s\,\%s\,\%s\,
+   at_clck_cpwd_fac[type], pin, pin);
+
+   g_at_chat_send(sd-chat, buf, none_prefix, NULL, NULL, NULL);
+
+   memset(buf, 0, sizeof(buf));
+
+   at_pin_query(sim, at_pin_query_result, cbd);
+
+   return;
+
+error:
+   CALLBACK_WITH_FAILURE(cb, data);
+}
+
+static void at_pin_send_puk(struct ofono_sim *sim,
+   enum ofono_sim_password_type type,
+   const char *puk, const char *passwd,
+   ofono_sim_lock_unlock_cb_t cb, void *data)
+{
+   struct sim_data *sd = ofono_sim_get_data(sim);
+   struct cb_data *cbd = NULL;
+   char buf[64];
+   int ret;
+
+   if (type != OFONO_SIM_PASSWORD_SIM_PIN ||
+   sd-cpin_type != OFONO_SIM_PASSWORD_SIM_PUK) {
+   switch (sd-vendor) {
+   case OFONO_VENDOR_MBM:
+   

Re: [PATCH 1/1] hfp: Add faked sim driver to support SIM ready

2010-08-30 Thread Gustavo F. Padovan
Hi Zhenhua,

* Zhenhua Zhang zhenhua.zh...@intel.com [2010-08-30 17:50:17 +0800]:

 HFP modem doesn't have IMSI at all. In order to notify SIM ready to the
 core, we create a special sim driver with a faked IMSI number.
 ---
  Makefile.am |3 +-
  drivers/hfpmodem/hfpmodem.c |2 +
  drivers/hfpmodem/hfpmodem.h |3 +
  drivers/hfpmodem/sim.c  |  114 
 +++
  plugins/hfp.c   |6 ++
  5 files changed, 127 insertions(+), 1 deletions(-)
  create mode 100644 drivers/hfpmodem/sim.c
 
 diff --git a/Makefile.am b/Makefile.am
 index f31180e..a1ec0e7 100644
 --- a/Makefile.am
 +++ b/Makefile.am
 @@ -187,7 +187,8 @@ builtin_sources += drivers/atmodem/atutil.h \
   drivers/hfpmodem/hfpmodem.c \
   drivers/hfpmodem/voicecall.c \
   drivers/hfpmodem/network-registration.c \
 - drivers/hfpmodem/call-volume.c
 + drivers/hfpmodem/call-volume.c \
 + drivers/hfpmodem/sim.c
  
  builtin_modules += mbmmodem
  builtin_sources += drivers/atmodem/atutil.h \
 diff --git a/drivers/hfpmodem/hfpmodem.c b/drivers/hfpmodem/hfpmodem.c
 index 4471a7b..ecbabe3 100644
 --- a/drivers/hfpmodem/hfpmodem.c
 +++ b/drivers/hfpmodem/hfpmodem.c
 @@ -44,6 +44,7 @@ static int hfpmodem_init(void)
   hfp_voicecall_init();
   hfp_netreg_init();
   hfp_call_volume_init();
 + hfp_sim_init();
  
   return 0;
  }
 @@ -53,6 +54,7 @@ static void hfpmodem_exit(void)
   hfp_voicecall_exit();
   hfp_netreg_exit();
   hfp_call_volume_exit();
 + hfp_sim_exit();
  }
  
  OFONO_PLUGIN_DEFINE(hfpmodem, Hands-Free Profile Driver, VERSION,
 diff --git a/drivers/hfpmodem/hfpmodem.h b/drivers/hfpmodem/hfpmodem.h
 index bf5d563..631f773 100644
 --- a/drivers/hfpmodem/hfpmodem.h
 +++ b/drivers/hfpmodem/hfpmodem.h
 @@ -80,3 +80,6 @@ extern void hfp_call_volume_exit();
  
  extern void hfp_voicecall_init();
  extern void hfp_voicecall_exit();
 +
 +extern void hfp_sim_init();
 +extern void hfp_sim_exit();
 diff --git a/drivers/hfpmodem/sim.c b/drivers/hfpmodem/sim.c
 new file mode 100644
 index 000..e42cfb9
 --- /dev/null
 +++ b/drivers/hfpmodem/sim.c
 @@ -0,0 +1,114 @@
 +/*
 + *
 + *  oFono - Open Source Telephony
 + *
 + *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
 + *
 + *  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
 +
 +#define _GNU_SOURCE
 +#include string.h
 +#include stdlib.h
 +#include stdio.h
 +
 +#include glib.h
 +
 +#include ofono/log.h
 +#include ofono/modem.h
 +#include ofono/sim.h
 +
 +#include gatchat.h
 +#include gatresult.h
 +#include hfpmodem.h
 +
 +static void hfp_read_imsi(struct ofono_sim *sim, ofono_sim_imsi_cb_t cb,
 + void *data)
 +{
 + struct ofono_error error;
 + const char *imsi = 1234567890123456;
 +
 + DBG(%s, imsi);
 +
 + /*
 +  * Return the faked IMSI since HFP doesn't have IMSI.
 +  */
 + error.type = OFONO_ERROR_TYPE_NO_ERROR;
 + cb(error, imsi, data);
 +}
 +
 +static void hfp_sim_read_binary(struct ofono_sim *sim, int fileid,
 + int start, int length,
 + ofono_sim_read_cb_t cb, void *data)
 +{
 + DBG();
 +
 + CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
 +}
 +
 +static void hfp_sim_read_info(struct ofono_sim *sim, int fileid,
 + ofono_sim_file_info_cb_t cb,
 + void *data)
 +{
 + DBG();
 +
 + CALLBACK_WITH_FAILURE(cb, -1, -1, -1, NULL, data);
 +}
 +
 +static int hfp_sim_probe(struct ofono_sim *sim, unsigned int vendor,
 + void *data)
 +{
 + ofono_sim_register(sim);
 +
 + return 0;
 +}
 +
 +static void hfp_sim_remove(struct ofono_sim *sim)
 +{
 +}
 +
 +static struct ofono_sim_driver driver = {
 + .name   = hfpmodem,
 + .probe  = hfp_sim_probe,
 + .remove = hfp_sim_remove,
 + .read_file_info = hfp_sim_read_info,
 + .read_file_transparent  = hfp_sim_read_binary,
 + .read_file_linear   = NULL,
 + .read_file_cyclic   = NULL,
 + .write_file_transparent = NULL,
 +  

Re: [RFC PATCH v3 2/4] smsutil: storing/loading sms status report over reboot

2010-08-30 Thread Denis Kenzior
Hi Petteri,

On 08/27/2010 01:09 PM, Petteri Tikander wrote:
 ---
  src/smsutil.c |  176 
 +++--
  src/smsutil.h |   10 +++-
  2 files changed, 180 insertions(+), 6 deletions(-)
 
 diff --git a/src/smsutil.c b/src/smsutil.c
 index c60b8ec..88c567c 100644
 --- a/src/smsutil.c
 +++ b/src/smsutil.c
 @@ -33,6 +33,7 @@
  #include unistd.h
  
  #include glib.h
 +#include errno.h

Remove this if strtoul is no longer used.

  
  #include util.h
  #include storage.h
 @@ -45,6 +46,9 @@
  #define SMS_BACKUP_PATH_DIR SMS_BACKUP_PATH /%s-%i-%i
  #define SMS_BACKUP_PATH_FILE SMS_BACKUP_PATH_DIR /%03i
  
 +#define SMS_SR_BACKUP_PATH STORAGEDIR /%s/sms_sr
 +#define SMS_SR_BACKUP_PATH_FILE SMS_SR_BACKUP_PATH /%s-%i
 +
  #define SMS_ADDR_FMT %24[0-9A-F]
  
  static GSList *sms_assembly_add_fragment_backup(struct sms_assembly 
 *assembly,
 @@ -2413,7 +2417,7 @@ static void sms_assembly_backup_free(struct 
 sms_assembly *assembly,
  {
   char *path;
   int seq;
 - char straddr[25];
 + DECLARE_SMS_ADDR_STR(straddr);

Please send this chunk as a separate patch, it doesn't belong to status
report assembly.

  
   if (!assembly-imsi)
   return;
 @@ -2529,7 +2533,8 @@ static GSList *sms_assembly_add_fragment_backup(struct 
 sms_assembly *assembly,
   if (ref != node-ref)
   continue;
  
 - /* Message Reference and address the same, but max is not
 + /*
 +  * Message Reference and address the same, but max is not
* ignore the SMS completely
*/

Again, please send this as a separate cleanup patch.

   if (max != node-max_fragments)
 @@ -2642,20 +2647,163 @@ void sms_assembly_expire(struct sms_assembly 
 *assembly, time_t before)
   }
  }
  
 +static void sr_assembly_load_backup(GHashTable *assembly_table,
 + const char *imsi,
 + const struct dirent *addr_dir)
 +{
 + struct sms_address addr;
 + DECLARE_SMS_ADDR_STR(straddr);
 + struct id_table_node *node;
 + GHashTable *id_table;
 + int r;
 + char *assembly_table_key;
 + unsigned int *id_table_key;
 + DECLARE_SMS_MSGID_STR(str_msg_id);
 + char *endp;
 + unsigned int msg_id;
 +
 + if (addr_dir-d_type != DT_REG)
 + return;
 +
 + /*
 +  * All SMS-messages under the same IMSI-code are
 +  * included in the same directory.
 +  * So, SMS-address and message ID are included in the same file name
 +  * Max of SMS address size is 12 bytes, hex encoded
 +  */
 + if (sscanf(addr_dir-d_name, SMS_ADDR_FMT - SMS_MSGID_FMT,
 + straddr, str_msg_id)  2)
 + return;

Using -%u should be sufficient here instead of SMS_MSGID_FMT.  Let us
hold off being too pedantic.  The directory is only readable / writeable
by root on properly configured systems, so we don't have to be too clever.

Also, we will be migrating away from unsigned int message ids to SHA-160
strings in the future, so lets not invest too much time getting this
part right.

 +
 + if (sms_assembly_extract_address(straddr, addr) == FALSE)
 + return;
 +

This looks fine...

 + errno = 0;
 + msg_id = strtoul(str_msg_id, endp, 10);
 +
 + if (*endp != '\0')
 + return;
 +
 + if (errno == ERANGE  msg_id == UINT_MAX)
 + return;
 +

So this part is no longer needed, remember to remove the errno.h include
above.

 + id_table = g_hash_table_lookup(assembly_table,
 + sms_address_to_string(addr));
 +
 + /* Create hashtable keyed by the to address if required */
 + if (id_table == NULL) {
 + id_table = g_hash_table_new_full(g_int_hash, g_int_equal,
 + g_free, g_free);
 +
 + assembly_table_key = g_strdup(sms_address_to_string(addr));
 + g_hash_table_insert(assembly_table, assembly_table_key,
 + id_table);
 + }
 +
 + node = g_new0(struct id_table_node, 1);
 +
 + r = read_file((unsigned char *) node,
 + sizeof(struct id_table_node),
 + SMS_SR_BACKUP_PATH /%s,
 + imsi, addr_dir-d_name);
 +
 + if (r  0) {
 + g_free(node);
 + return;
 + }

So I suggest turning the order around here slightly.  If (id_table ==
NULL) and we fail to read the file, the assembly_table now has an
address hash table with no elements.

If we try to read the node first and fail, we won't have this issue.

 +
 + /* Node ready, create key and add them to the table */
 + id_table_key = g_new0(unsigned int, 1);
 + *id_table_key = msg_id;
 +
 + g_hash_table_insert(id_table, id_table_key, node);
 +}
 +
  struct status_report_assembly 

Re: [PATCH v2 1/1] sim: Read EFsst

2010-08-30 Thread Denis Kenzior
Hi Yang,

On 08/29/2010 03:51 AM, Yang Gu wrote:
 ---
  src/sim.c |   34 --
  src/simutil.c |   18 
  src/simutil.h |   63 
 +
  3 files changed, 112 insertions(+), 3 deletions(-)
 
 diff --git a/src/sim.c b/src/sim.c
 index f8884a2..6cbb2eb 100644
 --- a/src/sim.c
 +++ b/src/sim.c
 @@ -101,6 +101,8 @@ struct ofono_sim {
   unsigned char efust_length;
   unsigned char *efest;
   unsigned char efest_length;
 + unsigned char *efsst;
 + unsigned char efsst_length;
  };
  
  struct msisdn_set_request {
 @@ -1072,6 +1074,27 @@ static void sim_retrieve_imsi(struct ofono_sim *sim)
   sim-driver-read_imsi(sim, sim_imsi_cb, sim);
  }
  
 +static void sim_efsst_read_cb(int ok, int length, int record,
 + const unsigned char *data,
 + int record_length, void *userdata)
 +{
 + struct ofono_sim *sim = userdata;
 +
 + if (!ok)
 + goto out;
 +
 + if (length  2) {
 + ofono_error(EFsst shall contain at least two bytes);
 + goto out;
 + }
 +
 + sim-efsst = g_memdup(data, length);

Has this been run through valgrind? Where's the g_free?

 + sim-efsst_length = length;
 +
 +out:
 + sim_retrieve_imsi(sim);
 +}
 +
  static void sim_efest_read_cb(int ok, int length, int record,
   const unsigned char *data,
   int record_length, void *userdata)
 @@ -1192,9 +1215,14 @@ static void sim_initialize_after_pin(struct ofono_sim 
 *sim)
   sim_cphs_information_read_cb, sim);
  
   /* Also retrieve the GSM service table */
 - ofono_sim_read(sim, SIM_EFUST_FILEID,
 - OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 - sim_efust_read_cb, sim);
 + if (sim-phase = OFONO_SIM_PHASE_3G)
 + ofono_sim_read(sim, SIM_EFUST_FILEID,
 + OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 + sim_efust_read_cb, sim);
 + else
 + ofono_sim_read(sim, SIM_EFSST_FILEID,
 + OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 + sim_efsst_read_cb, sim);
  }
  
  static void sim_pin_query_cb(const struct ofono_error *error,
 diff --git a/src/simutil.c b/src/simutil.c
 index ac054ae..4af6810 100644
 --- a/src/simutil.c
 +++ b/src/simutil.c
 @@ -1434,3 +1434,21 @@ gboolean sim_est_is_active(unsigned char *efest, 
 unsigned char len,
  
   return (efest[index / 8]  (index % 8))  1;
  }
 +
 +gboolean sim_sst_is_available(unsigned char *efsst, unsigned char len,
 + enum sim_sst_service index)
 +{
 + if (index = len * 4u)
 + return FALSE;
 +
 + return (efsst[index / 4]  ((index % 4) * 2))  1;
 +}
 +
 +gboolean sim_sst_is_active(unsigned char *efsst, unsigned char len,
 + enum sim_sst_service index)
 +{
 + if (index = len * 4u)
 + return FALSE;
 +
 + return (efsst[index / 4]  (((index % 4) * 2) + 1))  1;
 +}
 diff --git a/src/simutil.h b/src/simutil.h
 index 65e651a..0a94c67 100644
 --- a/src/simutil.h
 +++ b/src/simutil.h
 @@ -28,6 +28,7 @@ enum sim_fileid {
   SIM_EF_CPHS_INFORMATION_FILEID = 0x6f16,
   SIM_EF_CPHS_MBDN_FILEID = 0x6f17,
   SIM_EFUST_FILEID = 0x6f38,
 + SIM_EFSST_FILEID = 0x6f38, /* same as EFust */
   SIM_EFMSISDN_FILEID = 0x6f40,
   SIM_EFSPN_FILEID = 0x6f46,
   SIM_EFSDN_FILEID = 0x6f49,
 @@ -154,6 +155,64 @@ enum sim_est_service {
   SIM_EST_SERVICE_ACL = 2
  };
  
 +/* 51.011 Section 10.3.7 */
 +enum sim_sst_service {
 + SIM_SST_SERVICE_CHV1_DISABLE= 0,
 + SIM_SST_SERVICE_ADN = 1,
 + SIM_SST_SERVICE_FDN = 2,
 + SIM_SST_SERVICE_SMS = 3,
 + SIM_SST_SERVICE_AOC = 4,
 + SIM_SST_SERVICE_CCP = 5,
 + SIM_SST_SERVICE_PLMN_SELECTOR   = 6,
 + SIM_SST_SERVICE_MSISDN  = 8,
 + SIM_SST_SERVICE_EXT_1   = 9,
 + SIM_SST_SERVICE_EXT_2   = 10,
 + SIM_SST_SERVICE_SMSP= 11,
 + SIM_SST_SERVICE_LND = 12,
 + SIM_SST_SERVICE_CBS_ID  = 13,
 + SIM_SST_SERVICE_GROUP_ID_LEVEL_1= 14,
 + SIM_SST_SERVICE_GROUP_ID_LEVEL_2= 15,
 + SIM_SST_SERVICE_PROVIDER_NAME   = 16,
 + SIM_SST_SERVICE_SDN = 17,
 + SIM_SST_SERVICE_EXT_3   = 18,
 + SIM_SST_SERVICE_EFVGCS_EFVGCSS  = 20,
 + SIM_SST_SERVICE_EFVBS_EFVBSS   

Re: [PATCH v3] atmodem/phonebook: parse text as hexstring

2010-08-30 Thread Denis Kenzior
Hi Thadeu,

On 08/28/2010 02:27 AM, Thadeu Lima de Souza Cascardo wrote:
 Some modems omit the quotes when dumping strings in UCS2. Parsing
 them as hexstring already does the hex decoding and accepts missing
 quotes.
 ---

Patch has been applied.  Thanks.

Regards,
-Denis
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [RFC] Add agent API to message atom

2010-08-30 Thread Marcel Holtmann
Hi Aki,

  doc/message-api.txt |   97 
 +++
  1 files changed, 97 insertions(+), 0 deletions(-)
 
 diff --git a/doc/message-api.txt b/doc/message-api.txt
 index 693a111..ce96315 100644
 --- a/doc/message-api.txt
 +++ b/doc/message-api.txt
 @@ -26,6 +26,66 @@ Methodsdict GetProperties()
  
   Send the message in text to the number in to.
  
 + void RegisterTextAgent(object path, string match)
 +
 + Registers an agent to receive messages.
 +
 + The object path defines the path of the agent that
 + will be called when a message is ready to be
 + dispatched.  The match parameter takes an optional
 + matching rule in a restricted subset of regular
 + expression syntax.
 +
 + TODO: accepted regexp syntax.  Perhaps only allow
 + simple match rules for the beginning and end of a
 + message, as well as a free text token match for the
 + entire message.
 +
 + Possible Errors: [service].Error.InvalidArguments
 +  [service].Error.InvalidFormat
 +  [service].Error.InUse
 +
 + void RegisterPushAgent(object path, string id)
 +
 + Registers an agent to receive push messages.
 +
 + The object path defines the path of the agent that
 + will be called when a push message is ready to be
 + dispatched.  The id parameter takes an optional
 + WAP application ID that is used to match incoming
 + push messages.
 +
 + Possible Errors: [service].Error.InvalidArguments
 +  [service].Error.InvalidFormat
 +  [service].Error.InUse
 +
 + void RegisterApplicationAgent(object path, uint dest, uint src)
 +
 + Registers an agent to receive application messages.
 +
 + The object path defines the path of the agent that
 + will be called when an application message is ready
 + to be dispatched.
 +
 + The dest parameter is the destination application
 + port number, and the src parameter is the optional
 + source application port number.
 +
 + Possible Errors: [service].Error.InvalidArguments
 +  [service].Error.InvalidFormat
 +  [service].Error.InUse
 +
 + void UnregisterAgent(object path)
 +
 + Unregisters an agent.  If no agent is registered
 + that matches the type of an arriving message, it is
 + silently dropped.
 +
 + Possible Errors: [service].Error.InvalidArguments
 +  [service].Error.InvalidFormat
 +  [service].Error.NotFound
 +  [service].Error.NotAuthorized
 +

I prefer if we can do a RegisterAgent and UnregisterAgent like we have
in the STK interface. This makes it a lot more consistent throughout the
whole oFono APIs.

This of course means that we need a bit more intelligent matching of the
handled types. In general I am against the overhead of regex for this. I
prefer glob style matching with just * and ?. That should be good
enough. If you really need regex pattern matching then then I think a
specialized oFono plugin with its own APIs is the way to go.


 +MessageAgent Hierarchy [experimental]
 +===
 +
 +Service  unique name
 +Interfaceorg.ofono.MessageAgent
 +Object path  freely definable
 +
 +Methods  void ImmediateMessage(string message, dict info)
 +
 + New immediate (class 0) SMS received.  Info has Sender,
 + LocalSentTime, and SentTime information.  Sender
 + address is given in string format.  LocalSentTime and
 + SentTime are given in string form using ISO8601 format.

Should these really be delivered via an agent?

 + void IncomingMessage(string message, dict info)
 +
 + New incoming text SMS received.  Info has Sender,
 + LocalSentTime, and SentTime information.
 +
 + void IncomingPush(array{byte} message, dict info)
 +
 + New incoming push message received.  Info has Sender,
 + LocalSentTime, SentTime, and ApplicationId information.
 +
 + void IncomingApplication(array{byte} message, dict info)
 +
 + New incoming application message 

RE: [PATCH 1/1] hfp: Add faked sim driver to support SIM ready

2010-08-30 Thread Zhang, Zhenhua
Hi, Denis,

Denis Kenzior wrote:
 Hi Zhenhua,
 
 On 08/30/2010 04:50 AM, Zhenhua Zhang wrote:
 HFP modem doesn't have IMSI at all. In order to notify SIM ready to
 the core, we create a special sim driver with a faked IMSI number.
 
 Can you try after commit 88024972df46d4ababbaf39354615e8a8d603cfc?  I
 added magic which will skip sim_ready stuff completely for modems
 that do not add a sim atom. 

Yes. Your patch works well and fixes the problem in a generic way.

 Regards,
 -Denis

Regards,
Zhenhua

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


RE: [RFC] Add agent API to message atom

2010-08-30 Thread Zhang, Caiwen
Hi Aki,


 ---
  doc/message-api.txt |   97
 +++
  1 files changed, 97 insertions(+), 0 deletions(-)
 
 diff --git a/doc/message-api.txt b/doc/message-api.txt
 index 693a111..ce96315 100644
 --- a/doc/message-api.txt
 +++ b/doc/message-api.txt
 @@ -26,6 +26,66 @@ Methodsdict GetProperties()
 
   Send the message in text to the number in to.
 
 + void RegisterTextAgent(object path, string match)
 +
 + Registers an agent to receive messages.
 +
 + The object path defines the path of the agent that
 + will be called when a message is ready to be
 + dispatched.  The match parameter takes an optional
 + matching rule in a restricted subset of regular
 + expression syntax.
 +
 + TODO: accepted regexp syntax.  Perhaps only allow
 + simple match rules for the beginning and end of a
 + message, as well as a free text token match for the
 + entire message.
 +
 + Possible Errors: [service].Error.InvalidArguments
 +  [service].Error.InvalidFormat
 +  [service].Error.InUse
 +
 + void RegisterPushAgent(object path, string id)
 +
 + Registers an agent to receive push messages.
 +
 + The object path defines the path of the agent that
 + will be called when a push message is ready to be
 + dispatched.  The id parameter takes an optional
 + WAP application ID that is used to match incoming
 + push messages.
 +
 + Possible Errors: [service].Error.InvalidArguments
 +  [service].Error.InvalidFormat
 +  [service].Error.InUse
 +
 + void RegisterApplicationAgent(object path, uint dest, uint
 src)
 +
 + Registers an agent to receive application messages.
 +
 + The object path defines the path of the agent that
 + will be called when an application message is ready
 + to be dispatched.
 +
 + The dest parameter is the destination application
 + port number, and the src parameter is the optional
 + source application port number.
 +
 + Possible Errors: [service].Error.InvalidArguments
 +  [service].Error.InvalidFormat
 +  [service].Error.InUse
 +
Push message is a kind of application message. If an agent register both
RegisterPushAgent and RegisterApplicationAgent, will the message be processed
Twice. Will you offer same way to avoid this?

 + void UnregisterAgent(object path)
 +
 + Unregisters an agent.  If no agent is registered
 + that matches the type of an arriving message, it is
 + silently dropped.
 +
 + Possible Errors: [service].Error.InvalidArguments
 +  [service].Error.InvalidFormat
 +  [service].Error.NotFound
 +  [service].Error.NotAuthorized
 +
  Signals  PropertyChanged(string name, variant value)
 
   This signal indicates a changed value of the given
 @@ -64,3 +124,40 @@ Propertiesstring ServiceCenterAddress
   ps-preferred - Use CS if PS is unavailable
 
   By default oFono uses cs-preferred setting.
 +
 +
 +MessageAgent Hierarchy [experimental]
 +===
 +
 +Service  unique name
 +Interfaceorg.ofono.MessageAgent
 +Object path  freely definable
 +
 +Methods  void ImmediateMessage(string message, dict info)
 +
 + New immediate (class 0) SMS received.  Info has
 Sender,
 + LocalSentTime, and SentTime information.  Sender
 + address is given in string format.  LocalSentTime and
 + SentTime are given in string form using ISO8601
 format.
 +
 + void IncomingMessage(string message, dict info)
 +
 + New incoming text SMS received.  Info has Sender,
 + LocalSentTime, and SentTime information.
 +

Is the 'message' the text content of the income message(I mean the decoded user 
data)?

 + void IncomingPush(array{byte} message, dict info)
 +
 + New incoming push message received.  Info has Sender,
 + LocalSentTime, SentTime, and ApplicationId
 information.
 +
 + void