* [PATCH 0/2] huawei: PIN unlock working with E1552
@ 2010-08-10 9:57 Kalle Valo
2010-08-10 9:57 ` [PATCH 1/2] huawei: poll sim state Kalle Valo
2010-08-10 9:57 ` [PATCH 2/2] huawei: postpone post_sim until SIM is ready Kalle Valo
0 siblings, 2 replies; 8+ messages in thread
From: Kalle Valo @ 2010-08-10 9:57 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 319 bytes --]
After these two patches PIN unlock works always with my Huawei E1552.
---
Kalle Valo (2):
huawei: poll sim state
huawei: postpone post_sim until SIM is ready
plugins/huawei.c | 136 ++++++++++++++++++++++++++++++++++--------------------
1 files changed, 86 insertions(+), 50 deletions(-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] huawei: poll sim state
2010-08-10 9:57 [PATCH 0/2] huawei: PIN unlock working with E1552 Kalle Valo
@ 2010-08-10 9:57 ` Kalle Valo
2010-08-11 23:08 ` Denis Kenzior
2010-08-10 9:57 ` [PATCH 2/2] huawei: postpone post_sim until SIM is ready Kalle Valo
1 sibling, 1 reply; 8+ messages in thread
From: Kalle Valo @ 2010-08-10 9:57 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2766 bytes --]
On my Huawei E1552 when I plug in the modem (ie. cold start) with PIN locked
SIM, the sim state is 255 (HUAWEI_SIM_STATE_NOT_EXISTENT). As the modem
doesn't send ^SIMST notifications, poll the sim state until it's ready.
In theory it might be possible to do this better, for example follow
^BOOT notifications or something, but it's unknown what parameter we
should check for.
---
plugins/huawei.c | 34 ++++++++++++++++++++++++++++++----
1 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/plugins/huawei.c b/plugins/huawei.c
index f8ada24..ba66513 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -73,8 +73,11 @@ struct huawei_data {
enum huawei_sim_state sim_state;
struct ofono_gprs *gprs;
struct ofono_gprs_context *gc;
+ guint query_sim_state;
};
+static gboolean query_sim_state(gpointer user_data);
+
static int huawei_probe(struct ofono_modem *modem)
{
struct huawei_data *data;
@@ -114,8 +117,15 @@ static void notify_sim_state(struct ofono_modem *modem,
{
struct huawei_data *data = ofono_modem_get_data(modem);
- if (sim_state == HUAWEI_SIM_STATE_NOT_EXISTENT)
+ DBG("%d", sim_state);
+
+ if (sim_state == HUAWEI_SIM_STATE_NOT_EXISTENT) {
ofono_sim_inserted_notify(data->sim, FALSE);
+
+ /* SIM is not ready, try again a bit later */
+ data->query_sim_state =
+ g_timeout_add_seconds(2, query_sim_state, modem);
+ }
else
ofono_sim_inserted_notify(data->sim, TRUE);
@@ -154,6 +164,21 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
notify_sim_state(modem, (enum huawei_sim_state) sim_state);
}
+static gboolean query_sim_state(gpointer user_data)
+{
+ struct ofono_modem *modem = user_data;
+ struct huawei_data *data = ofono_modem_get_data(modem);
+
+ DBG("");
+
+ data->query_sim_state = 0;
+
+ g_at_chat_send(data->pcui, "AT^SYSINFO", sysinfo_prefix,
+ sysinfo_cb, modem, NULL);
+
+ return FALSE;
+}
+
static void simst_notify(GAtResult *result, gpointer user_data)
{
struct ofono_modem *modem = user_data;
@@ -187,9 +212,7 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
g_at_chat_register(data->pcui, "^SIMST:", simst_notify,
FALSE, modem, NULL);
- /* query current sim state */
- g_at_chat_send(data->pcui, "AT^SYSINFO", sysinfo_prefix,
- sysinfo_cb, modem, NULL);
+ query_sim_state(modem);
}
static GAtChat *create_port(const char *device)
@@ -319,6 +342,9 @@ static int huawei_disable(struct ofono_modem *modem)
DBG("%p", modem);
+ if (data->query_sim_state)
+ g_source_remove(data->query_sim_state);
+
if (data->modem) {
g_at_chat_cancel_all(data->modem);
g_at_chat_unregister_all(data->modem);
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] huawei: postpone post_sim until SIM is ready
2010-08-10 9:57 [PATCH 0/2] huawei: PIN unlock working with E1552 Kalle Valo
2010-08-10 9:57 ` [PATCH 1/2] huawei: poll sim state Kalle Valo
@ 2010-08-10 9:57 ` Kalle Valo
2010-08-11 23:23 ` Denis Kenzior
1 sibling, 1 reply; 8+ messages in thread
From: Kalle Valo @ 2010-08-10 9:57 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 5295 bytes --]
On my Huawei E1552 with PIN locked SIM sim_state is 0 when calling
huawei_post_sim() and gprs context is not registered. This is because
^SIMST notification is received only after huawei_post_sim() is called:
Aug 10 12:38:33 tukki ofonod[6565]: plugins/huawei.c:huawei_post_sim() 0x6cdb50
[...]
Aug 10 12:38:34 tukki ofonod[6565]: Pcui:< \r\n^SIMST:1\r\n\r\n^SRVST:2\r\n
Aug 10 12:38:34 tukki ofonod[6565]: plugins/huawei.c:notify_sim_state() 1
Add a test to wait for sim_state to be ready and also a call to
notify_sim_state() to call huawei_post_sim() whenever needed.
---
plugins/huawei.c | 102 ++++++++++++++++++++++++++++++------------------------
1 files changed, 56 insertions(+), 46 deletions(-)
diff --git a/plugins/huawei.c b/plugins/huawei.c
index ba66513..582cba6 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -74,6 +74,7 @@ struct huawei_data {
struct ofono_gprs *gprs;
struct ofono_gprs_context *gc;
guint query_sim_state;
+ gboolean post_sim;
};
static gboolean query_sim_state(gpointer user_data);
@@ -112,6 +113,58 @@ static void huawei_debug(const char *str, void *user_data)
ofono_info("%s%s", prefix, str);
}
+static void huawei_post_sim(struct ofono_modem *modem)
+{
+ struct huawei_data *data = ofono_modem_get_data(modem);
+ struct ofono_netreg *netreg;
+ struct ofono_message_waiting *mw;
+
+ DBG("%p sim_state %d", modem, data->sim_state);
+
+ if (data->sim_state == HUAWEI_SIM_STATE_INVALID_OR_LOCKED) {
+ /* let's wait for ^SIMST notification so that SIM is ready */
+ data->post_sim = TRUE;
+ return;
+ }
+
+ if (data->sim_state == HUAWEI_SIM_STATE_INVALID_PS_AND_CS) {
+ ofono_phonebook_create(modem, 0, "atmodem", data->pcui);
+ return;
+ }
+
+ netreg = ofono_netreg_create(modem, OFONO_VENDOR_HUAWEI, "atmodem",
+ data->pcui);
+
+ ofono_sms_create(modem, OFONO_VENDOR_HUAWEI, "atmodem", data->pcui);
+ ofono_cbs_create(modem, OFONO_VENDOR_QUALCOMM_MSM, "atmodem",
+ data->pcui);
+ ofono_ussd_create(modem, 0, "atmodem", data->pcui);
+ ofono_phonebook_create(modem, 0, "atmodem", data->pcui);
+
+ if (data->sim_state == HUAWEI_SIM_STATE_VALID ||
+ data->sim_state == HUAWEI_SIM_STATE_INVALID_CS) {
+ data->gprs = ofono_gprs_create(modem, 0, "atmodem", data->pcui);
+ data->gc = ofono_gprs_context_create(modem, 0, "atmodem",
+ data->modem);
+
+ if (data->gprs && data->gc)
+ ofono_gprs_add_context(data->gprs, data->gc);
+ }
+
+ if ((data->sim_state == HUAWEI_SIM_STATE_VALID ||
+ data->sim_state == HUAWEI_SIM_STATE_INVALID_PS) &&
+ ofono_modem_get_boolean(modem, "HasVoice") == TRUE) {
+ ofono_call_forwarding_create(modem, 0, "atmodem", data->pcui);
+ ofono_call_settings_create(modem, 0, "atmodem", data->pcui);
+ ofono_call_barring_create(modem, 0, "atmodem", data->pcui);
+ ofono_ssn_create(modem, 0, "atmodem", data->pcui);
+
+ mw = ofono_message_waiting_create(modem);
+ if (mw)
+ ofono_message_waiting_register(mw);
+ }
+}
+
static void notify_sim_state(struct ofono_modem *modem,
enum huawei_sim_state sim_state)
{
@@ -130,6 +183,9 @@ static void notify_sim_state(struct ofono_modem *modem,
ofono_sim_inserted_notify(data->sim, TRUE);
data->sim_state = sim_state;
+
+ if (data->post_sim)
+ huawei_post_sim(modem);
}
static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
@@ -378,52 +434,6 @@ static void huawei_pre_sim(struct ofono_modem *modem)
ofono_voicecall_create(modem, 0, "atmodem", data->pcui);
}
-static void huawei_post_sim(struct ofono_modem *modem)
-{
- struct huawei_data *data = ofono_modem_get_data(modem);
- struct ofono_netreg *netreg;
- struct ofono_message_waiting *mw;
-
- DBG("%p", modem);
-
- if (data->sim_state == HUAWEI_SIM_STATE_INVALID_PS_AND_CS) {
- ofono_phonebook_create(modem, 0, "atmodem", data->pcui);
- return;
- }
-
- netreg = ofono_netreg_create(modem, OFONO_VENDOR_HUAWEI, "atmodem",
- data->pcui);
-
- ofono_sms_create(modem, OFONO_VENDOR_HUAWEI, "atmodem", data->pcui);
- ofono_cbs_create(modem, OFONO_VENDOR_QUALCOMM_MSM, "atmodem",
- data->pcui);
- ofono_ussd_create(modem, 0, "atmodem", data->pcui);
- ofono_phonebook_create(modem, 0, "atmodem", data->pcui);
-
- if (data->sim_state == HUAWEI_SIM_STATE_VALID ||
- data->sim_state == HUAWEI_SIM_STATE_INVALID_CS) {
- data->gprs = ofono_gprs_create(modem, 0, "atmodem", data->pcui);
- data->gc = ofono_gprs_context_create(modem, 0, "atmodem",
- data->modem);
-
- if (data->gprs && data->gc)
- ofono_gprs_add_context(data->gprs, data->gc);
- }
-
- if ((data->sim_state == HUAWEI_SIM_STATE_VALID ||
- data->sim_state == HUAWEI_SIM_STATE_INVALID_PS) &&
- ofono_modem_get_boolean(modem, "HasVoice") == TRUE) {
- ofono_call_forwarding_create(modem, 0, "atmodem", data->pcui);
- ofono_call_settings_create(modem, 0, "atmodem", data->pcui);
- ofono_call_barring_create(modem, 0, "atmodem", data->pcui);
- ofono_ssn_create(modem, 0, "atmodem", data->pcui);
-
- mw = ofono_message_waiting_create(modem);
- if (mw)
- ofono_message_waiting_register(mw);
- }
-}
-
static struct ofono_modem_driver huawei_driver = {
.name = "huawei",
.probe = huawei_probe,
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] huawei: poll sim state
2010-08-10 9:57 ` [PATCH 1/2] huawei: poll sim state Kalle Valo
@ 2010-08-11 23:08 ` Denis Kenzior
2010-08-13 8:11 ` Kalle Valo
0 siblings, 1 reply; 8+ messages in thread
From: Denis Kenzior @ 2010-08-11 23:08 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 3208 bytes --]
Hi Kalle,
On 08/10/2010 04:57 AM, Kalle Valo wrote:
> On my Huawei E1552 when I plug in the modem (ie. cold start) with PIN locked
> SIM, the sim state is 255 (HUAWEI_SIM_STATE_NOT_EXISTENT). As the modem
> doesn't send ^SIMST notifications, poll the sim state until it's ready.
>
> In theory it might be possible to do this better, for example follow
> ^BOOT notifications or something, but it's unknown what parameter we
> should check for.
> ---
> plugins/huawei.c | 34 ++++++++++++++++++++++++++++++----
> 1 files changed, 30 insertions(+), 4 deletions(-)
>
> diff --git a/plugins/huawei.c b/plugins/huawei.c
> index f8ada24..ba66513 100644
> --- a/plugins/huawei.c
> +++ b/plugins/huawei.c
> @@ -73,8 +73,11 @@ struct huawei_data {
> enum huawei_sim_state sim_state;
> struct ofono_gprs *gprs;
> struct ofono_gprs_context *gc;
> + guint query_sim_state;
> };
>
> +static gboolean query_sim_state(gpointer user_data);
> +
> static int huawei_probe(struct ofono_modem *modem)
> {
> struct huawei_data *data;
> @@ -114,8 +117,15 @@ static void notify_sim_state(struct ofono_modem *modem,
> {
> struct huawei_data *data = ofono_modem_get_data(modem);
>
> - if (sim_state == HUAWEI_SIM_STATE_NOT_EXISTENT)
> + DBG("%d", sim_state);
> +
> + if (sim_state == HUAWEI_SIM_STATE_NOT_EXISTENT) {
> ofono_sim_inserted_notify(data->sim, FALSE);
> +
> + /* SIM is not ready, try again a bit later */
> + data->query_sim_state =
> + g_timeout_add_seconds(2, query_sim_state, modem);
> + }
Polling the sim state forever might not be a good idea if the SIM is not
inserted in the first place. You might want to give up after several
tries or so.
> else
> ofono_sim_inserted_notify(data->sim, TRUE);
>
> @@ -154,6 +164,21 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
> notify_sim_state(modem, (enum huawei_sim_state) sim_state);
> }
>
> +static gboolean query_sim_state(gpointer user_data)
> +{
> + struct ofono_modem *modem = user_data;
> + struct huawei_data *data = ofono_modem_get_data(modem);
> +
> + DBG("");
> +
> + data->query_sim_state = 0;
> +
> + g_at_chat_send(data->pcui, "AT^SYSINFO", sysinfo_prefix,
> + sysinfo_cb, modem, NULL);
> +
> + return FALSE;
> +}
> +
> static void simst_notify(GAtResult *result, gpointer user_data)
> {
> struct ofono_modem *modem = user_data;
> @@ -187,9 +212,7 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
> g_at_chat_register(data->pcui, "^SIMST:", simst_notify,
> FALSE, modem, NULL);
>
> - /* query current sim state */
> - g_at_chat_send(data->pcui, "AT^SYSINFO", sysinfo_prefix,
> - sysinfo_cb, modem, NULL);
> + query_sim_state(modem);
> }
>
> static GAtChat *create_port(const char *device)
> @@ -319,6 +342,9 @@ static int huawei_disable(struct ofono_modem *modem)
>
> DBG("%p", modem);
>
> + if (data->query_sim_state)
> + g_source_remove(data->query_sim_state);
> +
> if (data->modem) {
> g_at_chat_cancel_all(data->modem);
> g_at_chat_unregister_all(data->modem);
Otherwise patch looks good.
Regards,
-Denis
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] huawei: postpone post_sim until SIM is ready
2010-08-10 9:57 ` [PATCH 2/2] huawei: postpone post_sim until SIM is ready Kalle Valo
@ 2010-08-11 23:23 ` Denis Kenzior
2010-08-13 8:15 ` Kalle Valo
0 siblings, 1 reply; 8+ messages in thread
From: Denis Kenzior @ 2010-08-11 23:23 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1354 bytes --]
Hi Kalle,
On 08/10/2010 04:57 AM, Kalle Valo wrote:
> On my Huawei E1552 with PIN locked SIM sim_state is 0 when calling
> huawei_post_sim() and gprs context is not registered. This is because
> ^SIMST notification is received only after huawei_post_sim() is called:
>
> Aug 10 12:38:33 tukki ofonod[6565]: plugins/huawei.c:huawei_post_sim() 0x6cdb50
> [...]
> Aug 10 12:38:34 tukki ofonod[6565]: Pcui:< \r\n^SIMST:1\r\n\r\n^SRVST:2\r\n
> Aug 10 12:38:34 tukki ofonod[6565]: plugins/huawei.c:notify_sim_state() 1
>
> Add a test to wait for sim_state to be ready and also a call to
> notify_sim_state() to call huawei_post_sim() whenever needed.
So this problem affects multiple modem families and I think we should
solve it a bit better. What I'm proposing is to introduce a new
function to include/sim.h. Something like:
void ofono_sim_ready_notify(struct ofono_sim *sim);
The way it should work is as follows:
When oFono determines the SIM PIN is READY, it checks whether
ofono_sim_ready_notify has been called. If it hasn't, then it stalls
the initialization procedure (and calling post_sim) until
ofono_sim_ready_notify is called.
This way if the SIM is not PIN locked, the driver can call sim_inserted
and sim_ready at once. If the PIN is locked, the driver can notify
sim_ready later.
Regards,
-Denis
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] huawei: poll sim state
2010-08-11 23:08 ` Denis Kenzior
@ 2010-08-13 8:11 ` Kalle Valo
0 siblings, 0 replies; 8+ messages in thread
From: Kalle Valo @ 2010-08-13 8:11 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 868 bytes --]
Denis Kenzior <denkenz@gmail.com> writes:
> Hi Kalle,
Hi Denis,
> On 08/10/2010 04:57 AM, Kalle Valo wrote:
>
>> In theory it might be possible to do this better, for example follow
>> ^BOOT notifications or something, but it's unknown what parameter we
>> should check for.
Do you know if I can use BOOT messages (or something else) here? Polling
usually creates a load of problems and I would like to avoid it at all
costs.
>> + /* SIM is not ready, try again a bit later */
>> + data->query_sim_state =
>> + g_timeout_add_seconds(2, query_sim_state, modem);
>> + }
>
> Polling the sim state forever might not be a good idea if the SIM is not
> inserted in the first place. You might want to give up after several
> tries or so.
Good point. I'll add a counter for this (unless I can think of something
else).
--
Kalle Valo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] huawei: postpone post_sim until SIM is ready
2010-08-11 23:23 ` Denis Kenzior
@ 2010-08-13 8:15 ` Kalle Valo
2010-08-13 15:38 ` Denis Kenzior
0 siblings, 1 reply; 8+ messages in thread
From: Kalle Valo @ 2010-08-13 8:15 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 916 bytes --]
Hi Denis,
Denis Kenzior <denkenz@gmail.com> writes:
> So this problem affects multiple modem families and I think we should
> solve it a bit better. What I'm proposing is to introduce a new
> function to include/sim.h. Something like:
>
> void ofono_sim_ready_notify(struct ofono_sim *sim);
>
> The way it should work is as follows:
>
> When oFono determines the SIM PIN is READY, it checks whether
> ofono_sim_ready_notify has been called. If it hasn't, then it stalls
> the initialization procedure (and calling post_sim) until
> ofono_sim_ready_notify is called.
>
> This way if the SIM is not PIN locked, the driver can call sim_inserted
> and sim_ready at once. If the PIN is locked, the driver can notify
> sim_ready later.
Sounds good to me. Do you want to implement it? ;) I'm a bit busy right
now and it might take some time before I can find time for this.
--
Kalle Valo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] huawei: postpone post_sim until SIM is ready
2010-08-13 8:15 ` Kalle Valo
@ 2010-08-13 15:38 ` Denis Kenzior
0 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2010-08-13 15:38 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1107 bytes --]
Hi Kalle,
On 08/13/2010 03:15 AM, Kalle Valo wrote:
> Hi Denis,
>
> Denis Kenzior <denkenz@gmail.com> writes:
>
>> So this problem affects multiple modem families and I think we should
>> solve it a bit better. What I'm proposing is to introduce a new
>> function to include/sim.h. Something like:
>>
>> void ofono_sim_ready_notify(struct ofono_sim *sim);
>>
>> The way it should work is as follows:
>>
>> When oFono determines the SIM PIN is READY, it checks whether
>> ofono_sim_ready_notify has been called. If it hasn't, then it stalls
>> the initialization procedure (and calling post_sim) until
>> ofono_sim_ready_notify is called.
>>
>> This way if the SIM is not PIN locked, the driver can call sim_inserted
>> and sim_ready at once. If the PIN is locked, the driver can notify
>> sim_ready later.
>
> Sounds good to me. Do you want to implement it? ;) I'm a bit busy right
> now and it might take some time before I can find time for this.
>
I'm a bit swamped at the moment. I have added a TODO task for this
feature so we don't forget.
Regards,
-Denis
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-08-13 15:38 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-10 9:57 [PATCH 0/2] huawei: PIN unlock working with E1552 Kalle Valo
2010-08-10 9:57 ` [PATCH 1/2] huawei: poll sim state Kalle Valo
2010-08-11 23:08 ` Denis Kenzior
2010-08-13 8:11 ` Kalle Valo
2010-08-10 9:57 ` [PATCH 2/2] huawei: postpone post_sim until SIM is ready Kalle Valo
2010-08-11 23:23 ` Denis Kenzior
2010-08-13 8:15 ` Kalle Valo
2010-08-13 15:38 ` Denis Kenzior
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.