From: Pekka Pessi <Pekka.Pessi(a)nokia.com>
---
plugins/mbm.c | 39 +++++++++++++++++++++++++++++++++++----
1 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/plugins/mbm.c b/plugins/mbm.c
index 864b0df..9e63005 100644
--- a/plugins/mbm.c
+++ b/plugins/mbm.c
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
+#include <string.h>
#include <glib.h>
#include <gatchat.h>
@@ -54,6 +55,8 @@ static const char *none_prefix[] = { NULL };
struct mbm_data {
GAtChat *modem_port;
GAtChat *data_port;
+ guint sim_poll;
+ guint sim_polled;
gboolean have_sim;
};
@@ -82,6 +85,10 @@ static void mbm_remove(struct ofono_modem *modem)
g_at_chat_unref(data->data_port);
g_at_chat_unref(data->modem_port);
+
+ if (data->sim_poll > 0)
+ g_source_remove(data->sim_poll);
+
g_free(data);
}
@@ -92,6 +99,8 @@ static void mbm_debug(const char *str, void *user_data)
ofono_info("%s %s", prefix, str);
}
+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;
@@ -99,17 +108,40 @@ static void simpin_check(gboolean ok, GAtResult *result, gpointer
user_data)
DBG("");
- /* Modem returns error if there is no SIM in slot */
+ /* Modem returns +CME ERROR: 10 if SIM is not ready. */
+ if (!ok && result->final_or_pdu &&
+ !strcmp(result->final_or_pdu, "+CME ERROR: 10") &&
+ data->sim_polled++ < 5) {
+ data->sim_poll =
+ g_timeout_add_seconds(1, init_simpin_check, modem);
+ return;
+ }
+
+ data->sim_polled = 0;
+
+ /* Modem returns ERROR if there is no SIM in slot. */
data->have_sim = ok;
ofono_modem_set_powered(modem, TRUE);
}
-static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
+static gboolean init_simpin_check(gpointer user_data)
{
struct ofono_modem *modem = user_data;
struct mbm_data *data = ofono_modem_get_data(modem);
+ data->sim_poll = 0;
+
+ g_at_chat_send(data->modem_port, "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("");
if (!ok) {
@@ -117,8 +149,7 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer
user_data)
return;
}
- g_at_chat_send(data->modem_port, "AT+CPIN?", cpin_prefix,
- simpin_check, modem, NULL);
+ init_simpin_check(modem);
}
static void cfun_query(gboolean ok, GAtResult *result, gpointer user_data)
--
1.7.0.4
Show replies by date
Hi Pekka,
@@ -54,6 +55,8 @@ static const char *none_prefix[] = { NULL };
struct mbm_data {
GAtChat *modem_port;
GAtChat *data_port;
+ guint sim_poll;
+ guint sim_polled;
gboolean have_sim;
};
Can we rename sim_poll to cpin_poll_source?
Can we rename sim_polled to cpin_poll_retry or cpin_poll_retries?
- /* Modem returns error if there is no SIM in slot */
+ /* Modem returns +CME ERROR: 10 if SIM is not ready. */
+ if (!ok && result->final_or_pdu &&
+ !strcmp(result->final_or_pdu, "+CME ERROR: 10") &&
+ data->sim_polled++ < 5) {
+ data->sim_poll =
+ g_timeout_add_seconds(1, init_simpin_check, modem);
+ return;
+ }
+
Please note that whenever you have a multi-line if condition like the
one above, the conditions after the if should be indented one more level
than the if body block. E.g. put an extra indent before !strcmp and
data->sim_polled.
Regards,
-Denis
From: Pekka Pessi <Pekka.Pessi(a)nokia.com>
---
plugins/mbm.c | 39 +++++++++++++++++++++++++++++++++++----
1 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/plugins/mbm.c b/plugins/mbm.c
index 864b0df..4f6b46e 100644
--- a/plugins/mbm.c
+++ b/plugins/mbm.c
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
+#include <string.h>
#include <glib.h>
#include <gatchat.h>
@@ -54,6 +55,8 @@ static const char *none_prefix[] = { NULL };
struct mbm_data {
GAtChat *modem_port;
GAtChat *data_port;
+ guint cpin_poll_source;
+ guint cpin_poll_count;
gboolean have_sim;
};
@@ -82,6 +85,10 @@ static void mbm_remove(struct ofono_modem *modem)
g_at_chat_unref(data->data_port);
g_at_chat_unref(data->modem_port);
+
+ if (data->cpin_poll_source > 0)
+ g_source_remove(data->cpin_poll_source);
+
g_free(data);
}
@@ -92,6 +99,8 @@ static void mbm_debug(const char *str, void *user_data)
ofono_info("%s %s", prefix, str);
}
+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;
@@ -99,17 +108,40 @@ static void simpin_check(gboolean ok, GAtResult *result, gpointer
user_data)
DBG("");
- /* Modem returns error if there is no SIM in slot */
+ /* Modem returns +CME ERROR: 10 if SIM is not ready. */
+ if (!ok && result->final_or_pdu &&
+ !strcmp(result->final_or_pdu, "+CME ERROR: 10") &&
+ data->cpin_poll_count++ < 5) {
+ data->cpin_poll_source =
+ g_timeout_add_seconds(1, init_simpin_check, modem);
+ return;
+ }
+
+ data->cpin_poll_count = 0;
+
+ /* Modem returns ERROR if there is no SIM in slot. */
data->have_sim = ok;
ofono_modem_set_powered(modem, TRUE);
}
-static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
+static gboolean init_simpin_check(gpointer user_data)
{
struct ofono_modem *modem = user_data;
struct mbm_data *data = ofono_modem_get_data(modem);
+ data->cpin_poll_source = 0;
+
+ g_at_chat_send(data->modem_port, "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("");
if (!ok) {
@@ -117,8 +149,7 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer
user_data)
return;
}
- g_at_chat_send(data->modem_port, "AT+CPIN?", cpin_prefix,
- simpin_check, modem, NULL);
+ init_simpin_check(modem);
}
static void cfun_query(gboolean ok, GAtResult *result, gpointer user_data)
--
1.7.0.4
Hi Pekka,
On 07/15/2010 09:05 AM, Pekka.Pessi(a)nokia.com wrote:
From: Pekka Pessi <Pekka.Pessi(a)nokia.com>
---
plugins/mbm.c | 39 +++++++++++++++++++++++++++++++++++----
1 files changed, 35 insertions(+), 4 deletions(-)
Patch has been applied, thanks.
Regards,
-Denis