How to detect that connection got lost? Disconnected USB connection as well as disconnected mobile connection...

Aleksander Morgado aleksandermj at chromium.org
Wed Nov 15 00:04:08 UTC 2023


Hey,

>
> I am using the Python API. I allocate CIDs (e.g. for WDS) and keep them
> till python program is finished.
>
> Does someone know how I can detect that established connection got
> disconnected?
>
> I think there are at least two cases: USB got disconnected (1) and
> mobile connection got disconnected (2).
>
> (1) (e.g. by removing USB cable)
>
> (process:8148): Qmi-WARNING **: 19:54:05.330: Cannot read from istream:
> connection broken
>

The whole cdc-wdm control port goes away in this case. This should be
easy to detect.

> (2)
>
> Via WDS get_packet_service_status
>
> get_connection_status
> <enum QMI_WDS_CONNECTION_STATUS_CONNECTED of type Qmi.WdsConnectionStatus>
>
> Details here:
>
> https://lazka.github.io/pgi-docs/Qmi-1.0/classes/MessageWdsGetPacketServiceStatusOutput.html#Qmi.MessageWdsGetPacketServiceStatusOutput
>
> and
>
> https://lazka.github.io/pgi-docs/Qmi-1.0/enums.html#Qmi.WdsConnectionStatus
>
>
> I want to get informed via Python code.
>

Yes, WDS Get Packet Service Status query/responses (run with the same
WDS client as the Start Network) will give you the current connection
state info.
You also have Packet Service Status indications that you could register for.

> (1) I can perhaps detect via Linux calls (when USB device goes away),
> but I assume there is also a mechanism with libqmi,
>
> because I assume "QMI-WARNING" comes from inside libqmi.
>

When using libqmi only, you can detect this kind of device removal via
the "device-removed" signal emitted by the QmiDevice, see
https://www.freedesktop.org/software/libqmi/libqmi-glib/latest/QmiDevice.html#QmiDevice-device-removed


> There is
>
> https://lazka.github.io/pgi-docs/Qmi-1.0/classes/ClientWds.html#Qmi.ClientWds.indication_register
>
> Does it help me for the case (1) and (2)?
>

That would help for (1) only.

> I was not yet able to use indication_register for this task...I am
> registering it but callback is never called (at least for (1)).
>
> Or only polling possible (e.g. every 1s), call (WDS)
> get_packet_service_status in a loop to see if still connected?
>

Polling is a possibility, but registering for async indications is the
"nice" solution.

-- 
Aleksander


More information about the libqmi-devel mailing list