<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Ciao Aleksander,</div><div class="gmail_extra"><br><div class="gmail_quote">On 22 May 2017 at 13:18, Aleksander Morgado <span dir="ltr"><<a href="mailto:aleksander@aleksander.es" target="_blank">aleksander@aleksander.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">---<br>
<br>
Hey Carlo,<br>
<br>
It's never too late :)<br>
<br>
I couldn't reproduce the issue with the SIM hot swap changes you were trying, because none of my Telit modems here were able to support it properly, so I ended up re-reviewing the logs you sent and I believe I found the issue.<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
When the SIM is already unlocked, the "initialization" sequence is run only once. When the SIM is locked, though, the "initialization" sequence is run twice: one until it detects that the SIM is locked, and the second one after the SIM is unlocked. The INITIALIZE_STEP_SIM_HOT_SWAP step was therefore running twice and unconditionally creating a new PortsContext each time, and that would have a nice side-effect apart from the memleak: the "port open count" was incorrectly increased by one for the TTYs...<br>
<br>
When SIM was removed ModemManager would close and remove all ports. These are the logs when we have run the initialization sequence only once, you can see that the open count goes to 0 for both ttyACM0 and ttyACM3:<br>
<debug> (ttyACM3) device open count is 1 (close)<br>
<debug> (ttyACM0) device open count is 0 (close)<br>
<debug> (ttyACM0) closing serial port...<br>
<debug> (ttyACM0) serial port closed<br>
<debug> (ttyACM3) device open count is 0 (close)<br>
<debug> (ttyACM3) closing serial port...<br>
<debug> (ttyACM3) serial port closed<br>
<info> Modem /org/freedesktop/<wbr>ModemManager1/Modem/0: state changed (disabling -> disabled)<br>
<debug> [device /sys/devices/pci0000:00/0000:<wbr>00:1a.7/usb1/1-3] unexported modem from path '/org/freedesktop/<wbr>ModemManager1/Modem/0'<br>
<debug> (ttyACM3) forced to close port<br>
<debug> (ttyACM0) forced to close port<br>
<br>
These are the logs when we have run the initialization sequence twice and the PortsContext was created twice, you can see how the open count didn't go to 0:<br>
<info> Modem /org/freedesktop/<wbr>ModemManager1/Modem/0: 3GPP Registration state changed (home -> unknown)<br>
<debug> (ttyACM3) device open count is 2 (close)<br>
<debug> (ttyACM0) device open count is 1 (close)<br>
<debug> (ttyACM3) device open count is 1 (close)<br>
<info> Modem /org/freedesktop/<wbr>ModemManager1/Modem/0: state changed (disabling -> disabled)<br>
<debug> [device /sys/devices/pci0000:00/0000:<wbr>00:1a.7/usb1/1-3] unexported modem from path '/org/freedesktop/<wbr>ModemManager1/Modem/0'<br>
<br>
When the modem was re-created you said you would get NULL strings as response in the AT commands sent, even if you saw the responses in the logs.. well, it was the port objects from the previous modem run, which were not fully closed, the ones receiving the responses :) Your new serial port objects in the new modem run would fail and get NULL strings as response as you said.<br>
<br>
Could you take a look at the patch, which just avoids to re-create the ports context, and see if it really fixes the issue you were seeing in your tests?<br>
<br>
Cheers!<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">This is weird, but I couldn't reproduce the "modem not recognized" part myself.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"> </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">What I can reproduce is the crash, and I can also confirm that this patch fix it very well. Thank you!</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"></div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
---<br>
src/mm-broadband-modem.c | 10 +++++++---<br>
1 file changed, 7 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c<br>
index 4a14d33d..68242e5c 100644<br>
--- a/src/mm-broadband-modem.c<br>
+++ b/src/mm-broadband-modem.c<br>
@@ -10154,7 +10154,9 @@ initialize_step (InitializeContext *ctx)<br>
return;<br>
<br>
case INITIALIZE_STEP_SIM_HOT_SWAP:<br>
- {<br>
+ /* Create the SIM hot swap ports context only if not already done before<br>
+ * (we may be re-running the initialization step after SIM-PIN unlock) */<br>
+ if (!ctx->self->priv->sim_hot_<wbr>swap_ports_ctx) {<br>
gboolean is_sim_hot_swap_supported = FALSE;<br>
<br>
g_object_get (ctx->self,<br>
@@ -10165,7 +10167,7 @@ initialize_step (InitializeContext *ctx)<br>
PortsContext *ports;<br>
GError *error = NULL;<br>
<br>
- mm_dbg ("Creating PortsContext for SIM hot swap.");<br>
+ mm_dbg ("Creating ports context for SIM hot swap");<br>
<br>
ports = g_new0 (PortsContext, 1);<br>
ports->ref_count = 1;<br>
@@ -10178,7 +10180,9 @@ initialize_step (InitializeContext *ctx)<br>
<br>
ports_context_unref (ports);<br>
}<br>
- }<br>
+ } else<br>
+ mm_dbg ("Ports context for SIM hot swap already available");<br>
+<br>
/* Fall down to next step */<br>
ctx->step++;<br>
<br>
--<br>
2.12.2<br>
</blockquote></div><br></div></div>