[PATCH] CDMA devinfo: send AT+GCAP to check devinfo.

2011-07-21 Thread Bertrand Aygon
---
 drivers/cdmamodem/devinfo.c |   10 ++
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/cdmamodem/devinfo.c b/drivers/cdmamodem/devinfo.c
index 9603e05..2a5813c 100644
--- a/drivers/cdmamodem/devinfo.c
+++ b/drivers/cdmamodem/devinfo.c
@@ -36,6 +36,8 @@
 
 #include "cdmamodem.h"
 
+static const char *gcap_prefix[] = { "+GCAP:", NULL };
+
 static void attr_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
  struct cb_data *cbd = user_data;
@@ -123,13 +125,11 @@ static void cdma_query_serial(struct ofono_devinfo *info,
CALLBACK_WITH_FAILURE(cb, NULL, data);
 }
 
-static gboolean cdma_devinfo_register(gpointer user_data)
+static void capability_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
struct ofono_devinfo *info = user_data;
 
ofono_devinfo_register(info);
-
-   return FALSE;
 }
 
 static int cdma_devinfo_probe(struct ofono_devinfo *info,
@@ -138,7 +138,9 @@ static int cdma_devinfo_probe(struct ofono_devinfo *info,
GAtChat *chat = data;
 
ofono_devinfo_set_data(info, g_at_chat_clone(chat));
-   g_idle_add(cdma_devinfo_register, info);
+
+   g_at_chat_send(chat, "AT+GCAP", gcap_prefix,
+   capability_cb, info, NULL);
 
return 0;
 }
-- 
1.7.4.1

-
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH] SpeedUp CDMA: querying SIM state during powering on phase.

2011-07-21 Thread Bertrand Aygon
---
 plugins/speedupcdma.c |  102 -
 1 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/plugins/speedupcdma.c b/plugins/speedupcdma.c
index b7e54a1..1dcff88 100644
--- a/plugins/speedupcdma.c
+++ b/plugins/speedupcdma.c
@@ -41,11 +41,25 @@
 #include 
 
 static const char *none_prefix[] = { NULL };
+static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
+
+enum speedupcdma_sim_state {
+   SPEEDUPCDMA_SIM_STATE_VALID =   1,
+   SPEEDUPCDMA_SIM_STATE_ROMSIM =  240,
+   SPEEDUPCDMA_SIM_STATE_NOT_EXISTENT =255
+};
 
 struct speedupcdma_data {
GAtChat *chat;
+   enum speedupcdma_sim_state sim_state;
+   guint sim_poll_timeout;
+   guint sim_poll_count;
 };
 
+#define MAX_SIM_POLL_COUNT 5
+
+static gboolean query_sim_state(gpointer user_data);
+
 static void speedupcdma_debug(const char *str, void *data)
 {
const char *prefix = data;
@@ -79,6 +93,90 @@ static void speedupcdma_remove(struct ofono_modem *modem)
g_free(data);
 }
 
+static gboolean notify_sim_state(struct ofono_modem *modem,
+   enum speedupcdma_sim_state sim_state)
+{
+   struct speedupcdma_data *data = ofono_modem_get_data(modem);
+
+   DBG("%d", sim_state);
+
+   data->sim_state = sim_state;
+
+   switch (sim_state) {
+   case SPEEDUPCDMA_SIM_STATE_NOT_EXISTENT:
+   /* SIM is not ready, try again a bit later */
+   return TRUE;
+   case SPEEDUPCDMA_SIM_STATE_VALID:
+   case SPEEDUPCDMA_SIM_STATE_ROMSIM:
+   if (data->sim_poll_timeout) {
+   g_source_remove(data->sim_poll_timeout);
+   data->sim_poll_timeout = 0;
+   }
+
+   ofono_modem_set_powered(modem, TRUE);
+
+   return FALSE;
+   }
+
+   return FALSE;
+}
+
+static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+   struct ofono_modem *modem = user_data;
+   struct speedupcdma_data *data = ofono_modem_get_data(modem);
+   gboolean rerun;
+   gint sim_state;
+   GAtResultIter iter;
+
+   if (!ok)
+   return;
+
+   g_at_result_iter_init(&iter, result);
+
+   if (!g_at_result_iter_next(&iter, "^SYSINFO:"))
+   return;
+
+   if (!g_at_result_iter_skip_next(&iter))
+   return;
+
+   if (!g_at_result_iter_skip_next(&iter))
+   return;
+
+   if (!g_at_result_iter_skip_next(&iter))
+   return;
+
+   if (!g_at_result_iter_skip_next(&iter))
+   return;
+
+   if (!g_at_result_iter_next_number(&iter, &sim_state))
+   return;
+
+   rerun = notify_sim_state(modem, (enum speedupcdma_sim_state) sim_state);
+
+   if (rerun && data->sim_poll_count < MAX_SIM_POLL_COUNT) {
+   data->sim_poll_count++;
+   data->sim_poll_timeout = g_timeout_add_seconds(2,
+   query_sim_state,
+   modem);
+   }
+}
+
+static gboolean query_sim_state(gpointer user_data)
+{
+   struct ofono_modem *modem = user_data;
+   struct speedupcdma_data *data = ofono_modem_get_data(modem);
+
+   DBG("");
+
+   data->sim_poll_timeout = 0;
+
+   g_at_chat_send(data->chat, "AT^SYSINFO", sysinfo_prefix,
+   sysinfo_cb, modem, NULL);
+
+   return FALSE;
+}
+
 static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 {
struct ofono_modem *modem = user_data;
@@ -93,8 +191,6 @@ static void cfun_enable(gboolean ok, GAtResult *result, 
gpointer user_data)
ofono_modem_set_powered(modem, FALSE);
return;
}
-
-   ofono_modem_set_powered(modem, TRUE);
 }
 
 static int speedupcdma_enable(struct ofono_modem *modem)
@@ -132,6 +228,8 @@ static int speedupcdma_enable(struct ofono_modem *modem)
g_at_chat_send(data->chat, "AT+CFUN=1", none_prefix,
cfun_enable, modem, NULL);
 
+   query_sim_state(modem);
+
return -EINPROGRESS;
 }
 
-- 
1.7.4.1

-
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH] udev: add support for SpeedUp CDMA dongles.

2011-07-21 Thread Bertrand Aygon
---
 plugins/udev.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/plugins/udev.c b/plugins/udev.c
index a28bea7..b50ca2f 100644
--- a/plugins/udev.c
+++ b/plugins/udev.c
@@ -793,6 +793,8 @@ done:
add_linktop(modem, udev_device);
 else if (g_strcmp0(driver, "speedup") == 0)
add_speedup(modem, udev_device);
+   else if (g_strcmp0(driver, "speedupcdma") == 0)
+   add_speedup(modem, udev_device);
 }
 
 static gboolean devpath_remove(gpointer key, gpointer value, gpointer 
user_data)
-- 
1.7.4.1

-
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH v3 2/2] voicecall: remove usage of em_atd_number

2011-07-21 Thread Denis Kenzior
Hi Frédéric,

On 07/21/2011 09:58 AM, Frédéric Danis wrote:
> as emulator atom can only run with a 'ready' SIM,
> use saved number instead of em_atd_number
> ---
>  src/voicecall.c |   19 +--
>  1 files changed, 9 insertions(+), 10 deletions(-)
> 

Patch has been applied, thanks.

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


Re: [PATCH v3 1/2] hfp_ag: start server on sim 'ready' state

2011-07-21 Thread Denis Kenzior
Hi Frédéric,

On 07/21/2011 09:58 AM, Frédéric Danis wrote:
> update HFP AG server to start only when a modem has its SIM atom
> in 'ready' state and has voice call capability
> ---
>  plugins/hfp_ag.c |   69 
> +++---
>  1 files changed, 55 insertions(+), 14 deletions(-)
> 

Patch has been applied, thanks.

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


[PATCH v3 2/2] voicecall: remove usage of em_atd_number

2011-07-21 Thread Frédéric Danis
as emulator atom can only run with a 'ready' SIM,
use saved number instead of em_atd_number
---
 src/voicecall.c |   19 +--
 1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/voicecall.c b/src/voicecall.c
index 9160ce8..f4c2358 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -74,7 +74,6 @@ struct ofono_voicecall {
ofono_voicecall_cb_t release_queue_done_cb;
struct ofono_emulator *pending_em;
unsigned int pending_id;
-   char *em_atd_number;
 };
 
 struct voicecall {
@@ -1506,14 +1505,14 @@ static int voicecall_dial(struct ofono_voicecall *vc, 
const char *number,
 
string_to_phone_number(number, &ph);
 
-   vc->driver->dial(vc, &ph, clir, cb, vc);
-
if (vc->settings) {
g_key_file_set_string(vc->settings, SETTINGS_GROUP,
"Number", number);
storage_sync(vc->imsi, SETTINGS_STORE, vc->settings);
}
 
+   vc->driver->dial(vc, &ph, clir, cb, vc);
+
return 0;
 }
 
@@ -3154,13 +3153,18 @@ static void emulator_dial_callback(const struct 
ofono_error *error, void *data)
struct ofono_voicecall *vc = data;
gboolean need_to_emit;
struct voicecall *v;
+   const char *number;
+   GError *err = NULL;
+
+   number = g_key_file_get_string(vc->settings, SETTINGS_GROUP,
+   "Number", &err);
 
-   v = dial_handle_result(vc, error, vc->em_atd_number, &need_to_emit);
+   v = dial_handle_result(vc, error, number, &need_to_emit);
 
if (v == NULL) {
struct ofono_modem *modem = __ofono_atom_get_modem(vc->atom);
 
-   if (is_emergency_number(vc, vc->em_atd_number) == TRUE)
+   if (is_emergency_number(vc, number) == TRUE)
__ofono_modem_dec_emergency_mode(modem);
}
 
@@ -3168,8 +3172,6 @@ static void emulator_dial_callback(const struct 
ofono_error *error, void *data)
ofono_emulator_send_final(vc->pending_em, error);
 
vc->pending_em = NULL;
-   g_free(vc->em_atd_number);
-   vc->em_atd_number = NULL;
 
notify_emulator_call_status(vc);
 
@@ -3191,7 +3193,6 @@ static void emulator_dial(struct ofono_emulator *em, 
struct ofono_voicecall *vc,
}
 
vc->pending_em = em;
-   vc->em_atd_number = g_strdup(number);
 
err = voicecall_dial(vc, number, OFONO_CLIR_OPTION_DEFAULT,
emulator_dial_callback, vc);
@@ -3200,8 +3201,6 @@ static void emulator_dial(struct ofono_emulator *em, 
struct ofono_voicecall *vc,
return;
 
vc->pending_em = NULL;
-   g_free(vc->em_atd_number);
-   vc->em_atd_number = NULL;
 
switch (err) {
case -ENETDOWN:
-- 
1.7.1

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


[PATCH v3 1/2] hfp_ag: start server on sim 'ready' state

2011-07-21 Thread Frédéric Danis
update HFP AG server to start only when a modem has its SIM atom
in 'ready' state and has voice call capability
---
 plugins/hfp_ag.c |   69 +++---
 1 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/plugins/hfp_ag.c b/plugins/hfp_ag.c
index 191708b..a97b3d0 100644
--- a/plugins/hfp_ag.c
+++ b/plugins/hfp_ag.c
@@ -40,6 +40,7 @@
 static struct server *server;
 static guint modemwatch_id;
 static GList *modems;
+static GHashTable *sim_hash = NULL;
 
 static const gchar *hfp_ag_record =
 "\n"
@@ -115,27 +116,63 @@ static void hfp_ag_connect_cb(GIOChannel *io, GError 
*err, gpointer user_data)
ofono_emulator_register(em, fd);
 }
 
-static void voicecall_watch(struct ofono_atom *atom,
-   enum ofono_atom_watch_condition cond,
-   void *data)
+static void sim_state_watch(enum ofono_sim_state new_state, void *data)
 {
struct ofono_modem *modem = data;
 
-   if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
-   modems = g_list_append(modems, modem);
-
-   if (modems->next == NULL)
-   server = bluetooth_register_server(HFP_AG_CHANNEL,
-   hfp_ag_record,
-   hfp_ag_connect_cb,
-   NULL);
-   } else {
+   if (new_state != OFONO_SIM_STATE_READY) {
modems = g_list_remove(modems, modem);
if (modems == NULL && server != NULL) {
bluetooth_unregister_server(server);
server = NULL;
}
+
+   return;
}
+
+   if (__ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_VOICECALL)
+   == NULL)
+   return;
+
+   modems = g_list_append(modems, modem);
+
+   if (modems->next == NULL)
+   server = bluetooth_register_server(HFP_AG_CHANNEL,
+   hfp_ag_record,
+   hfp_ag_connect_cb,
+   NULL);
+}
+
+static gboolean sim_watch_remove(gpointer key, gpointer value,
+   gpointer user_data)
+{
+   struct ofono_sim *sim = key;
+
+   ofono_sim_remove_state_watch(sim, GPOINTER_TO_UINT(value));
+
+   return TRUE;
+}
+
+static void sim_watch(struct ofono_atom *atom,
+   enum ofono_atom_watch_condition cond,
+   void *data)
+{
+   struct ofono_sim *sim = __ofono_atom_get_data(atom);
+   struct ofono_modem *modem = data;
+   int watch;
+
+   if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
+   sim_state_watch(OFONO_SIM_STATE_NOT_PRESENT, modem);
+
+   sim_watch_remove(sim, g_hash_table_lookup(sim_hash, sim), NULL);
+   g_hash_table_remove(sim_hash, sim);
+
+   return;
+   }
+
+   watch = ofono_sim_add_state_watch(sim, sim_state_watch, modem, NULL);
+   g_hash_table_insert(sim_hash, sim, GUINT_TO_POINTER(watch));
+   sim_state_watch(ofono_sim_get_state(sim), modem);
 }
 
 static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
@@ -145,8 +182,8 @@ static void modem_watch(struct ofono_modem *modem, gboolean 
added, void *user)
if (added == FALSE)
return;
 
-   __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_VOICECALL,
-   voicecall_watch, modem, NULL);
+   __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SIM,
+   sim_watch, modem, NULL);
 }
 
 static void call_modemwatch(struct ofono_modem *modem, void *user)
@@ -156,6 +193,8 @@ static void call_modemwatch(struct ofono_modem *modem, void 
*user)
 
 static int hfp_ag_init()
 {
+   sim_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
+
modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
__ofono_modem_foreach(call_modemwatch, NULL);
 
@@ -166,6 +205,8 @@ static void hfp_ag_exit()
 {
__ofono_modemwatch_remove(modemwatch_id);
g_list_free(modems);
+   g_hash_table_foreach_remove(sim_hash, sim_watch_remove, NULL);
+   g_hash_table_destroy(sim_hash);
 
if (server) {
bluetooth_unregister_server(server);
-- 
1.7.1

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


[PATCHv2 2/2] zte: add cpin polling mechanism

2011-07-21 Thread Nicolas Bertrand
Make sure that the SIM card is ready before sending commands
---
 plugins/zte.c |   67 +++-
 1 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/plugins/zte.c b/plugins/zte.c
index 4bac3cf..9964a44 100644
--- a/plugins/zte.c
+++ b/plugins/zte.c
@@ -49,10 +49,14 @@
 #include 
 
 static const char *none_prefix[] = { NULL };
+static const char *cpin_prefix[] = { "+CPIN:", NULL };
 
 struct zte_data {
GAtChat *modem;
GAtChat *aux;
+   guint cpin_poll_source;
+   guint cpin_poll_count;
+   gboolean have_sim;
struct ofono_gprs *gprs;
struct ofono_gprs_context *gc;
 };
@@ -83,6 +87,9 @@ static void zte_remove(struct ofono_modem *modem)
g_at_chat_unref(data->modem);
g_at_chat_unref(data->aux);
 
+   if (data->cpin_poll_source > 0)
+   g_source_remove(data->cpin_poll_source);
+
g_free(data);
 }
 
@@ -152,13 +159,69 @@ static void zte_disconnect(gpointer user_data)
ofono_gprs_add_context(data->gprs, data->gc);
 }
 
+static gboolean init_simpin_check(gpointer user_data);
+
+static void simpin_check(gboolean ok, GAtResult *result, gpointer user_data)
+{
+   struct ofono_modem *modem = user_data;
+   struct zte_data *data = ofono_modem_get_data(modem);
+   struct ofono_error error;
+
+   DBG("");
+
+   decode_at_error(&error, g_at_result_final_response(result));
+
+   /* Modem returns an error if SIM is not ready. */
+   switch (error.error) {
+   case 10:
+   case 13:
+   data->have_sim = FALSE;
+   break;
+   case 14: /* SIM Busy, wait and check again the card status */
+   if (data->cpin_poll_count++ < 20) {
+   data->cpin_poll_source =
+   g_timeout_add_seconds(1, init_simpin_check,
+   modem);
+   return;
+   }
+   /*SIM card is present but not accessible*/
+   data->have_sim = FALSE;
+   break;
+   default:
+   data->have_sim = TRUE;
+   }
+
+   data->cpin_poll_count = 0;
+
+   ofono_modem_set_powered(modem, TRUE);
+}
+
+static gboolean init_simpin_check(gpointer user_data)
+{
+   struct ofono_modem *modem = user_data;
+   struct zte_data *data = ofono_modem_get_data(modem);
+
+   data->cpin_poll_source = 0;
+
+   g_at_chat_send(data->aux, "AT+CPIN?", cpin_prefix,
+   simpin_check, modem, NULL);
+
+   return FALSE;
+}
+
+
 static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 {
struct ofono_modem *modem = user_data;
 
DBG("");
 
-   ofono_modem_set_powered(modem, ok);
+   if (!ok) {
+   ofono_modem_set_powered(modem, FALSE);
+   return;
+   }
+
+   init_simpin_check(modem);
 }
 
 static int zte_enable(struct ofono_modem *modem)
@@ -273,7 +336,7 @@ static void zte_pre_sim(struct ofono_modem *modem)
"atmodem", data->aux);
 
if (sim)
-   ofono_sim_inserted_notify(sim, TRUE);
+   ofono_sim_inserted_notify(sim, data->have_sim);
 }
 
 static void zte_post_sim(struct ofono_modem *modem)
-- 
1.7.4.1

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


[PATCHv2 1/2] speedup: add cpin polling mechanism

2011-07-21 Thread Nicolas Bertrand
Make sure that the SIM card is ready before sending commands
---
 plugins/speedup.c |   66 +++-
 1 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/plugins/speedup.c b/plugins/speedup.c
index 7e89b6f..afd9b40 100644
--- a/plugins/speedup.c
+++ b/plugins/speedup.c
@@ -49,10 +49,14 @@
 #include 
 
 static const char *none_prefix[] = { NULL };
+static const char *cpin_prefix[] = { "+CPIN:", NULL };
 
 struct speedup_data {
GAtChat *modem;
GAtChat *aux;
+   guint cpin_poll_source;
+   guint cpin_poll_count;
+   gboolean have_sim;
struct ofono_gprs *gprs;
struct ofono_gprs_context *gc;
 };
@@ -83,6 +87,9 @@ static void speedup_remove(struct ofono_modem *modem)
g_at_chat_unref(data->modem);
g_at_chat_unref(data->aux);
 
+   if (data->cpin_poll_source > 0)
+   g_source_remove(data->cpin_poll_source);
+
g_free(data);
 }
 
@@ -152,13 +159,68 @@ static void speedup_disconnect(gpointer user_data)
ofono_gprs_add_context(data->gprs, data->gc);
 }
 
+static gboolean init_simpin_check(gpointer user_data);
+
+static void simpin_check(gboolean ok, GAtResult *result, gpointer user_data)
+{
+   struct ofono_modem *modem = user_data;
+   struct speedup_data *data = ofono_modem_get_data(modem);
+   struct ofono_error error;
+
+   DBG("");
+
+   decode_at_error(&error, g_at_result_final_response(result));
+
+   /* Modem returns an error if SIM is not ready. */
+   switch (error.error) {
+   case 10:
+   case 13:
+   data->have_sim = FALSE;
+   break;
+   case 14: /* SIM Busy, wait and check again the SIM pin status */
+   if (data->cpin_poll_count++ < 20) {
+   data->cpin_poll_source =
+   g_timeout_add_seconds(1, init_simpin_check,
+   modem);
+   return;
+   }
+   /*SIM card is present but not accessible*/
+   data->have_sim = FALSE;
+   break;
+   default:
+   data->have_sim = TRUE;
+   }
+
+   data->cpin_poll_count = 0;
+
+   ofono_modem_set_powered(modem, TRUE);
+}
+
+static gboolean init_simpin_check(gpointer user_data)
+{
+   struct ofono_modem *modem = user_data;
+   struct speedup_data *data = ofono_modem_get_data(modem);
+
+   data->cpin_poll_source = 0;
+
+   g_at_chat_send(data->aux, "AT+CPIN?", cpin_prefix,
+   simpin_check, modem, NULL);
+
+   return FALSE;
+}
+
 static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 {
struct ofono_modem *modem = user_data;
 
DBG("");
 
-   ofono_modem_set_powered(modem, ok);
+   if (!ok) {
+   ofono_modem_set_powered(modem, FALSE);
+   return;
+   }
+
+   init_simpin_check(modem);
 }
 
 static int speedup_enable(struct ofono_modem *modem)
@@ -272,7 +334,7 @@ static void speedup_pre_sim(struct ofono_modem *modem)
"atmodem", data->aux);
 
if (sim)
-   ofono_sim_inserted_notify(sim, TRUE);
+   ofono_sim_inserted_notify(sim, data->have_sim);
 }
 
 static void speedup_post_sim(struct ofono_modem *modem)
-- 
1.7.4.1

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


[PATCHv2 0/2] CPIN polling mechanism

2011-07-21 Thread Nicolas Bertrand
v2 changes:
 - change AT channel from modem to aux
 - raise timeout to 20 since some dongle take a while to be
   operational
 - send sim inserted notify related to the current status

As no SIM card status urc is available with ZTE and Speedup, the SIM 
state is set by default to OFONO_SIM_STATE_INSERTED even if no SIM card 
is inserted. Also, we are facing with a modem latency after the ttyUSB 
is opened (first AT commands are failing and the PIN status query 
returns CME ERROR: 14 - SIM Busy).
So, to deal with those 2 issues, this patch set is introducing a 
preliminary PIN status polling in the ZTE/Speedup plugins. In practice, 
this polling is started after the modem is enabled and stopped when the 
CPIN query returns an other result than CME ERROR 14 or when the polling 
duration exceeds 5 seconds.
As a result, the SIM state is set according the result of the CPIN query 
and the update of the modem_powered state is postponed which delays the 
next AT commands.

Developed conjointly with philippe nunes.

Nicolas Bertrand (2):
  speedup: add cpin polling mechanism
  zte: add cpin polling mechanism

 plugins/speedup.c |   66 ++-
 plugins/zte.c |   67 +++-
 2 files changed, 129 insertions(+), 4 deletions(-)

-- 
1.7.4.1

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


Re: [PATCH_v4] speedupcdma: add speedup cdma skeleton plugin

2011-07-21 Thread Marcel Holtmann
Hi Guillaume,

I applied the patch and fixed up the last issues by myself. Please
review them closely.

> Free speedupcdma_data while removing modem.

Version and changelog comments have to come after the ---. Otherwise
they end up in the commit log. And without a previous commit they make
no sense then.

If in doubt, please check your patch with git am and see how it applies.

> ---
>  Makefile.am   |3 +
>  plugins/speedupcdma.c |  210 
> +
>  2 files changed, 213 insertions(+), 0 deletions(-)
>  create mode 100644 plugins/speedupcdma.c
> 
> diff --git a/Makefile.am b/Makefile.am
> index a4e6c95..4b72091 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -336,6 +336,9 @@ builtin_sources += plugins/telit.c
>  builtin_modules += speedup
>  builtin_sources += plugins/speedup.c
>  
> +builtin_modules += speedupcdma
> +builtin_sources += plugins/speedupcdma.c
> +
>  if BLUETOOTH
>  builtin_modules += bluetooth
>  builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
> diff --git a/plugins/speedupcdma.c b/plugins/speedupcdma.c
> new file mode 100644
> index 000..65da2f6
> --- /dev/null
> +++ b/plugins/speedupcdma.c
> @@ -0,0 +1,210 @@
> +/*
> + *
> + *  oFono - Open Source Telephony
> + *
> + *  Copyright (C) 2008-2011  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 
> +#endif
> +
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +
> +#define OFONO_API_SUBJECT_TO_CHANGE
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +static const char *none_prefix[] = { NULL };
> +
> +struct speedupcdma_data {
> + GAtChat *chat;
> +};
> +
> +static void speedupcdma_debug(const char *str, void *data)
> +{
> + const char *prefix = data;
> +
> + ofono_info("%s%s", prefix, str);
> +}
> +
> +static int speedupcdma_probe(struct ofono_modem *modem)
> +{
> + struct speedupcdma_data *data;
> +
> + DBG("%p", modem);
> +
> + data = g_try_new0(struct speedupcdma_data, 1);
> + if (data == NULL)
> + return -ENOMEM;
> +
> + ofono_modem_set_data(modem, data);
> +
> + return 0;
> +}
> +
> +static void speedupcdma_remove(struct ofono_modem *modem)
> +{
> + struct speedupcdma_data *data = ofono_modem_get_data(modem);
> +
> + DBG("%p", modem);
> +
> + g_free(data);
> + ofono_modem_set_data(modem, NULL);
> +}

The general rule here is to first call ofono_modem_set_data() in a
remove callback to set it back to NULL and then free the data. This is
how all of the other plugins do it as well.

It does not make a difference here since we are single threaded with a
mainloop, but it is style that we should keep.

If really in doubt, the IFX plugin is the best example since we spent a
lot of time to make it clean and be able to have it as a reference.

> +static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> + struct ofono_modem *modem = user_data;
> +
> + DBG("");
> +
> + if (!ok) {
> + struct speedupcdma_data *data = ofono_modem_get_data(modem);

While this is fine, the general style is to keep it at the top.

> +
> + g_at_chat_unref(data->chat);
> + data->chat == NULL;

And seriously? This even gives a compile error:

  CC plugins/speedupcdma.o
plugins/speedupcdma.c: In function ‘cfun_enable’:
plugins/speedupcdma.c:91:3: error: statement with no effect 
[-Werror=unused-value]
cc1: all warnings being treated as errors

I know that typos like this happen. Even I overlooked it in the v3
review, but the compiler warning should have been a big indication that
something is wrong here. That is why I insist that developers use
bootstrap-configure to enable maintainer-mode and we can catch these
ones.

In your previous code with the g_at_chat_unref() inside the remove
callback, this would have caused a crash when enabling of a modem failed
and you stop ofonod after.

> + ofono_modem_set_powered(modem, FALSE);
> + return;
> + }
> +
> + ofono_modem_set_powered(modem, TRUE);
> +}
> +
> +static int speedupcdma_enable(struct ofono_modem *modem)
> +{
> + struct speedupcdma_data *data = ofono_modem_get_data(modem)