huawei: PIN unlock working with E1552
cover huawei: PIN unlock working with E1552
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(-)
PATCH 1/2 huawei: poll sim state
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(-)
plugins/huawei.c +30 -4
@@ -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);
Re: [PATCH 1/2] huawei: poll sim state
Hi Kalle,
Quoted 31 lines · Kalle Valo
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(-)plugins/huawei.c +3
-0@@ -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);
plugins/huawei.c static void notify_sim_state(struct ofono_modem *modem, · line 128
Quoted 10 lines
plugins/huawei.c +8
-1-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.
Quoted 37 lines
plugins/huawei.c +16
-3else 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)
plugins/huawei.c static int huawei_disable(struct ofono_modem *modem) · line 350
Quoted 9 lines
plugins/huawei.c +3
-0@@ -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
Re: [PATCH 1/2] huawei: poll sim state
Quoted 1 line · Denis Kenzior
Hi Kalle,
Hi Denis,
Quoted 5 lines · Kalle Valo
Quoted 4 lines
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.
Quoted 8 lines
plugins/huawei.c static void notify_sim_state(struct ofono_modem *modem, · line 128
Quoted 4 lines
plugins/huawei.c +4
-0+/* 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).
Signature · 1 line
Kalle Valo
PATCH 2/2 huawei: postpone post_sim until SIM is ready
In reply to Kalle ValoOn 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(-)
plugins/huawei.c +56 -46
@@ -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,
Re: [PATCH 2/2] huawei: postpone post_sim until SIM is ready
Hi Kalle,
Quoted 11 lines · Kalle Valo
On my Huawei E1552 with PIN locked SIM
sim_stateis 0 when callinghuawei_post_sim()and gprs context is not registered. This is because ^SIMST notification is received only afterhuawei_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() 1Add a test to wait for
sim_stateto be ready and also a call tonotify_sim_state()to callhuawei_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
Re: [PATCH 2/2] huawei: postpone post_sim until SIM is ready
Hi Denis,
Quoted 8 lines · Denis Kenzior
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:
Quoted 8 lines
When oFono determines the SIM PIN is READY, it checks whether
ofono_sim_ready_notifyhas been called. If it hasn't, then it stalls the initialization procedure (and callingpost_sim) untilofono_sim_ready_notifyis called.This way if the SIM is not PIN locked, the driver can call
sim_insertedandsim_readyat once. If the PIN is locked, the driver can notifysim_readylater.
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.
Signature · 1 line
Kalle Valo
Re: [PATCH 2/2] huawei: postpone post_sim until SIM is ready
Hi Kalle,
Quoted 17 lines · Kalle Valo
Hi Denis,
Quoted 13 lines · Denis Kenzior
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_notifyhas been called. If it hasn't, then it stalls the initialization procedure (and callingpost_sim) untilofono_sim_ready_notifyis called.
Quoted 7 lines
Quoted 3 lines
This way if the SIM is not PIN locked, the driver can call
sim_insertedandsim_readyat once. If the PIN is locked, the driver can notifysim_readylater.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