atmodem: remove CGACT command
PATCH v4 1/2 atmodem: remove CGACT command
It's enough that we shutdown PPP, no need to send CGACT after that. Recommended by Denis.
---
drivers/atmodem/gprs-context.c | 51 +++++++++++++--------------------------- 1 files changed, 16 insertions(+), 35 deletions(-)
drivers/atmodem/gprs-context.c +16 -35
@@ -65,22 +65,6 @@ struct gprs_context_data {void *cb_data;/* Callback data */ }; -static void at_cgact_down_cb (gboolean ok,GAtResult *result,gpointer user_data) -{ -struct cb_data *cbd = user_data; -ofono_gprs_context_cb_t cb = cbd->cb; -struct ofono_gprs_context *gc = cbd->user; -struct gprs_context_data *gcd =ofono_gprs_context_get_data (gc); -struct ofono_error error; - -if (ok) - gcd->active_context =0 ; - -decode_at_error (&error,g_at_result_final_response (result)); - -cb (&error, cbd->data); -} -static void ppp_connect (const char *interface,const char *ip,const char *dns1,const char *dns2,gpointer user_data)
@@ -104,13 +88,21 @@ static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)struct ofono_gprs_context *gc = user_data;struct gprs_context_data *gcd =ofono_gprs_context_get_data (gc); -if (gcd->state ==STATE_ENABLING ) { +DBG ("" ); + +switch (gcd->state) { +case STATE_ENABLING :CALLBACK_WITH_FAILURE (gcd->up_cb,NULL , FALSE,NULL ,NULL ,NULL ,NULL , gcd->cb_data); -return ; +break ; +case STATE_DISABLING : +CALLBACK_WITH_SUCCESS (gcd->down_cb, gcd->cb_data); +break ; +default : +ofono_gprs_context_deactivated (gc, gcd->active_context); +break ; } -ofono_gprs_context_deactivated (gc, gcd->active_context); gcd->active_context =0 ; gcd->state =STATE_IDLE ; }
@@ -227,25 +219,14 @@ static void at_gprs_deactivate_primary(struct ofono_gprs_context *gc, ofono_gprs_context_cb_t cb, void *data) { struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc); -struct cb_data *cbd =cb_data_new (cb, data); -char buf[64 ]; - -if (!cbd) - goto error; - - cbd->user = gc; -snprintf (buf,sizeof (buf),"AT+CGACT=0,%u" , id); +DBG ("" ); -if (g_at_chat_send (gcd->chat, buf, none_prefix, - at_cgact_down_cb, cbd, g_free) >0 ) -return ; - -error: -if (cbd) -g_free (cbd); + gcd->state =STATE_DISABLING ; + gcd->down_cb = cb; + gcd->cb_data = data; -CALLBACK_WITH_FAILURE (cb, data); +g_at_ppp_shutdown (gcd->ppp); } static int at_gprs_context_probe(struct ofono_gprs_context *gc,
PATCH v4 2/2 atmodem: fix crash during context deactivation
Ofono either crashed or busy looped with my Huawei E1552 3G modem when I tried to deactivate GPRS context. The reason was that gcd->chat was unreferenced already in setup_ppp() but the chat was still accessed later in at_gprs_deactivate_primary().
To fix the problem, change the logic instead to suspend chat session for PPP and resume when PPP has disconnected. Now it doesn't crash anymore.
Deactivation still doesn't work properly with Huawei E1552, and most probably with other Huawei modems, because the modem hangs up the chat line after PPP deactivation. This needs to be fixed separately. The workaround is to reboot the modem, for example physically unplug and plug it in again.
---
drivers/atmodem/gprs-context.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-)
drivers/atmodem/gprs-context.c +10 -5
@@ -90,6 +90,8 @@ static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)DBG ("" ); +g_at_chat_resume (gcd->chat); +switch (gcd->state) {case STATE_ENABLING : CALLBACK_WITH_FAILURE(gcd->up_cb, NULL, FALSE, NULL,
@@ -110,16 +112,19 @@ static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)static gboolean setup_ppp (struct ofono_gprs_context *gc) {struct gprs_context_data *gcd =ofono_gprs_context_get_data (gc); -GIOChannel *channel; +GAtIO *io; + + io =g_at_chat_get_io (gcd->chat); - channel =g_at_chat_get_channel (gcd->chat); -g_at_chat_unref (gcd->chat); +g_at_chat_suspend (gcd->chat);/* open ppp */ - gcd->ppp =g_at_ppp_new (channel); + gcd->ppp =g_at_ppp_new_from_io (io); -if (gcd->ppp ==NULL ) +if (gcd->ppp ==NULL ) { +g_at_chat_resume (gcd->chat);return FALSE; + }g_at_ppp_set_credentials (gcd->ppp, gcd->username, gcd->password);
Re: [PATCH v4 2/2] atmodem: fix crash during context deactivation
Hi Kalle,
Quoted 9 lines
Ofono either crashed or busy looped with my Huawei E1552 3G modem when I tried to deactivate GPRS context. The reason was that
gcd->chatwas unreferenced already insetup_ppp()but the chat was still accessed later inat_gprs_deactivate_primary().To fix the problem, change the logic instead to suspend chat session for PPP and resume when PPP has disconnected. Now it doesn't crash anymore.
Quoted 6 lines
Deactivation still doesn't work properly with Huawei E1552, and most probably with other Huawei modems, because the modem hangs up the chat line after PPP deactivation. This needs to be fixed separately. The workaround is to reboot the modem, for example physically unplug and plug it in again.
---
Patch has been applied, thanks.
Regards,
-Denis
Hi Kalle,
Quoted 37 lines
It's enough that we shutdown PPP, no need to send CGACT after that. Recommended by Denis.
---drivers/atmodem/gprs-context.c | 51 +++++++++++++--------------------------- 1 files changed, 16 insertions(+), 35 deletions(-)drivers/atmodem/gprs-context.c +0
-16@@ -65,22 +65,6 @@ struct gprs_context_data {void *cb_data;/* Callback data */ }; -static void at_cgact_down_cb (gboolean ok,GAtResult *result,gpointer user_data) -{ -struct cb_data *cbd = user_data; -ofono_gprs_context_cb_t cb = cbd->cb; -struct ofono_gprs_context *gc = cbd->user; -struct gprs_context_data *gcd =ofono_gprs_context_get_data (gc); -struct ofono_error error; - -if (ok) - gcd->active_context =0 ; - -decode_at_error (&error,g_at_result_final_response (result)); - -cb (&error, cbd->data); -} -static void ppp_connect (const char *interface,const char *ip,const char *dns1,const char *dns2,gpointer user_data)@@ -104,13 +88,21 @@ static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)struct ofono_gprs_context *gc = user_data;struct gprs_context_data *gcd =ofono_gprs_context_get_data (gc);
drivers/atmodem/gprs-context.c static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data) · line 97
Quoted 10 lines
drivers/atmodem/gprs-context.c +5
-2-if (gcd->state ==STATE_ENABLING ) { +DBG ("" ); + +switch (gcd->state) { +case STATE_ENABLING :CALLBACK_WITH_FAILURE (gcd->up_cb,NULL , FALSE,NULL ,NULL ,NULL ,NULL , gcd->cb_data); -return ; +break ;
just double-checking that you really wanna have break; and not return; here. So that gcd->state gets reset to STATE_IDLE.
drivers/atmodem/gprs-context.c static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data) · line 108
Quoted 12 lines
drivers/atmodem/gprs-context.c +6
-1+case STATE_DISABLING : +CALLBACK_WITH_SUCCESS (gcd->down_cb, gcd->cb_data); +break ; +default : +ofono_gprs_context_deactivated (gc, gcd->active_context); +break ; } -ofono_gprs_context_deactivated (gc, gcd->active_context); gcd->active_context =0 ; gcd->state =STATE_IDLE ; }
Regards
Marcel
Quoted 1 line · Marcel Holtmann
Hi Kalle,
Hi Marcel,
Quoted 3 lines
Quoted 3 lines
It's enough that we shutdown PPP, no need to send CGACT after that. Recommended by Denis.
---
[...]
Quoted 4 lines
Quoted 4 lines
drivers/atmodem/gprs-context.c +0
-0@@ -104,13 +88,21 @@ static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)struct ofono_gprs_context *gc = user_data;struct gprs_context_data *gcd =ofono_gprs_context_get_data (gc);
Quoted 12 lines
drivers/atmodem/gprs-context.c static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data) · line 97
Quoted 9 lines
drivers/atmodem/gprs-context.c +5
-2-if (gcd->state ==STATE_ENABLING ) { +DBG ("" ); + +switch (gcd->state) { +case STATE_ENABLING :CALLBACK_WITH_FAILURE (gcd->up_cb,NULL , FALSE,NULL ,NULL ,NULL ,NULL , gcd->cb_data); -return ; +break ;just double-checking that you really wanna have break; and not return; here. So that
gcd->stategets reset toSTATE_IDLE.
Yes, my intention was really to use break here.
Signature · 1 line
Kalle Valo
Hi Kalle,
Quoted 3 lines
It's enough that we shutdown PPP, no need to send CGACT after that. Recommended by Denis.
---
Patch has been applied, I did change the commit message slightly.
Regards,
-Denis