All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] - oFono v1.31 stuck in loop when unplugging a USB dongle connected via PPP
@ 2019-11-19 10:53 Jimmy Gysens
  2019-11-22  3:23 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Jimmy Gysens @ 2019-11-19 10:53 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2698 bytes --]

Hi,

After unplugging a Huawei USB dongle, the 'atoms' in oFono are removed via 'flush_atoms'.
Every atom has a destruct function pointer, used as a - yes - destructor.

When unplugging a dongle, connected via PPP, oFono will remove the current GPRS context (= data connection).

The function calls are:

flush_atoms -> destruct -> gprs_context_remove -> at_gprs_context_remove -> modem_disconnect

Because the device is physically removed, the IO channel for the AT port is gone.

In 'at_gprs_context_remove', there is an attempt to resume communication over that AT port, but that
is not possible. This is detected, and 'io_disconnect' (pointer to 'modem_disconnect') is called.

'modem_disconnect' has the same atom and tries to remove it again, so it calls the same destructor.

modem_disconnect -> destruct -> gprs_context_remove -> at_gprs_context_remove -> modem_disconnect

And the loop is started.

The easiest way to fix this, is to move the GPRS context removal. After a disconnect, oFono tries to
re-open the AT port. If that fails (and it will in this case), we're done, since 'modem_disconnect' returns.

In case the AT port can be opened, for example, when setting up a new connection, the previous GPRS context
is removed.

The old GPRS context is removed via:
 - 'flush_atoms' in case the USB device is physically removed.
 - 'modem_disconnect' in case a new connection is being set up.

The loop hereby is fixed, without altering general functionality of oFono. This fix is limited to Huawei devices and has been tested using the following devices:

- E3531i-2
- E3372
- E3531s-2
- E369
- E1552

The patch itself:

---
 ofono-1.31/plugins/huawei.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/ofono-1.31/plugins/huawei.c b/ofono-1.31/plugins/huawei.c
index bdf7bc3..bb87670 100644
--- a/ofono-1.31/plugins/huawei.c
+++ b/ofono-1.31/plugins/huawei.c
@@ -583,9 +583,6 @@ static void modem_disconnect(gpointer user_data)
 	g_at_chat_unref(data->modem);
 	data->modem = NULL;
 
-	/* close gprs context driver */
-	ofono_gprs_context_remove(data->gc);
-
 	/* reopen modem channel */
 	data->modem = open_device(modem, "Modem", "Modem: ");
 
@@ -594,6 +591,10 @@ static void modem_disconnect(gpointer user_data)
 		return;
 	}
 
+	/* close previous gprs context driver */
+	if (data->gc)
+		ofono_gprs_context_remove(data->gc);
+
 	/* configure modem channel */
 	g_at_chat_set_disconnect_function(data->modem, modem_disconnect, modem);
 	g_at_chat_set_slave(data->modem, data->pcui);
-- 
2.17.1

A review and upstream fix would be appreciated.

Thank you.

Best regards,
Jimmy

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] - oFono v1.31 stuck in loop when unplugging a USB dongle connected via PPP
  2019-11-19 10:53 [PATCH] - oFono v1.31 stuck in loop when unplugging a USB dongle connected via PPP Jimmy Gysens
@ 2019-11-22  3:23 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2019-11-22  3:23 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2070 bytes --]

Hi Jimmy,

On 11/19/19 4:53 AM, Jimmy Gysens wrote:
> Hi,
> 
> After unplugging a Huawei USB dongle, the 'atoms' in oFono are removed via 'flush_atoms'.
> Every atom has a destruct function pointer, used as a - yes - destructor.
> 
> When unplugging a dongle, connected via PPP, oFono will remove the current GPRS context (= data connection).
> 
> The function calls are:
> 
> flush_atoms -> destruct -> gprs_context_remove -> at_gprs_context_remove -> modem_disconnect
> 
> Because the device is physically removed, the IO channel for the AT port is gone.
> 
> In 'at_gprs_context_remove', there is an attempt to resume communication over that AT port, but that
> is not possible. This is detected, and 'io_disconnect' (pointer to 'modem_disconnect') is called.
> 
> 'modem_disconnect' has the same atom and tries to remove it again, so it calls the same destructor.
> 
> modem_disconnect -> destruct -> gprs_context_remove -> at_gprs_context_remove -> modem_disconnect
> 
> And the loop is started.
> 
> The easiest way to fix this, is to move the GPRS context removal. After a disconnect, oFono tries to
> re-open the AT port. If that fails (and it will in this case), we're done, since 'modem_disconnect' returns.
> 
> In case the AT port can be opened, for example, when setting up a new connection, the previous GPRS context
> is removed.
> 
> The old GPRS context is removed via:
>   - 'flush_atoms' in case the USB device is physically removed.
>   - 'modem_disconnect' in case a new connection is being set up.
> 
> The loop hereby is fixed, without altering general functionality of oFono. This fix is limited to Huawei devices and has been tested using the following devices:
> 
> - E3531i-2
> - E3372
> - E3531s-2
> - E369
> - E1552
> 
> The patch itself:
> 
> ---
>   ofono-1.31/plugins/huawei.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 

Thanks for the detailed report!  I went ahead and applied this fix 
upstream after massaging the commit description a bit.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-22  3:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-19 10:53 [PATCH] - oFono v1.31 stuck in loop when unplugging a USB dongle connected via PPP Jimmy Gysens
2019-11-22  3:23 ` 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.