lpac/driver/apdu/qmi_helpers.h
Robert Marko 3bde4a1d3d
driver(APDU): add QMI backend (#131)
* driver: pass EUICC APDU or HTTP struct to driver fini OP

Currently, the .fini driver OP can only be used with global variables, but
that will be an issue when we cant use global variables.

This will be used with direct QMI in order to free the memory used by the
driver private structure instead of global variables.

Signed-off-by: Robert Marko <robert.marko@sartura.hr>

* driver: apdu: rename QRTR QMI helpers to QMI helpers

Almost all of the QRTR QMI helpers will be reused for direct QMI so,
lets rename the sources to indicate that.

Signed-off-by: Robert Marko <robert.marko@sartura.hr>

* driver: apdu: extract common QMI code

Support for using QMI directly and not over QRTR would use a lot of the
same code as QMI over QRTR, so in order to prevent code duplication lets
extract that common code so it can be reused.

Signed-off-by: Robert Marko <robert.marko@sartura.hr>

* driver: apdu: qmi-helpers: allow compiling without libqrtr

Direct QMI backend wont use any of the libqmi QRTR functionality so it
wont depend on libqrtr and thus we need to make sure QMI helpers still
compile without libqrtr in the system.

Signed-off-by: Robert Marko <robert.marko@sartura.hr>

* driver: apdu: dont use global variables for QMI

Since we split out the common QMI code then we cannot be using global
variables since existing QRTR and the coming QMI drivers will clash
by trying to use the same global variable names with the common code.

So, lets move to passing a structure which is driver specific instead.

Since we are not using global variables anymore, we cannot be using atexit
anymore, so lets move that cleanup step to driver finish OP instead.

Signed-off-by: Robert Marko <robert.marko@sartura.hr>

* driver: apdu: add QMI backend

Previously QMI over QRTR support was added, however that is only present in
modern Qualcomm modems and only when running in PCIe mode and its quite
common to still only use even the latest modems via USB.

In that case, they are all still controllable via QMI but it is directly
exposed as a character device in Linux so we can reuse most of the code
from QMI over QRTR support but drop the support for libqrtr to talk to
the modems.

We require the QMI device path to be passed via QMI_DEVICE env variable
for the backend to operate.

Signed-off-by: Robert Marko <robert.marko@sartura.hr>

* docs: ENVVARS: document QMI backend

Document the new direct QMI backend ENV variables as well as make it
clear that UIM_SLOT is not a QMI QRTR only variable.

Signed-off-by: Robert Marko <robert.marko@sartura.hr>

* driver: apdu: qmi-helpers: support opening QMI device in proxy mode

Currently, we are using QMI_DEVICE_OPEN_FLAGS_NONE to open the QMI device
and thus we are requesting exclusive access to the device while we need
to talk to it.

This will work fine as long as we are the only thing trying to use that
QMI device at the same time or the device was not already opened in proxy
mode.

This is an issue since ModemManager will open the device in proxy mode so
that qmicli or other applications can still talk to the same QMI device
but it will break lpac from trying to use QMI.

So, lets try and open the device in proxy mode, libqmi will the start the
qmi-proxy service automatically as its built and installed as part of it.

Signed-off-by: Robert Marko <robert.marko@sartura.hr>

---------

Signed-off-by: Robert Marko <robert.marko@sartura.hr>
2024-07-24 15:59:37 +08:00

68 lines
1.4 KiB
C

// SPDX-License-Identifier: MIT
/*
* Copyright (c) 2024, Luca Weiss <luca.weiss@fairphone.com>
*/
#include <libqmi-glib.h>
#ifdef LPAC_WITH_APDU_QMI_QRTR
#include <libqrtr-glib.h>
QrtrBus *qrtr_bus_new_sync(
GMainContext *context,
GError **error);
QmiDevice *
qmi_device_new_from_node_sync(
QrtrNode *node,
GMainContext *context,
GError **error);
#endif
#ifdef LPAC_WITH_APDU_QMI
QmiDevice *
qmi_device_new_from_path(
GFile *file,
GMainContext *context,
GError **error);
#endif
gboolean
qmi_device_open_sync(
QmiDevice *device,
GMainContext *context,
GError **error);
QmiClient *
qmi_device_allocate_client_sync(
QmiDevice *device,
GMainContext *context,
GError **error);
gboolean
qmi_device_release_client_sync(
QmiDevice *device,
QmiClient *client,
GMainContext *context,
GError **error);
QmiMessageUimOpenLogicalChannelOutput *
qmi_client_uim_open_logical_channel_sync(
QmiClientUim *client,
QmiMessageUimOpenLogicalChannelInput *input,
GMainContext *context,
GError **error);
QmiMessageUimLogicalChannelOutput *
qmi_client_uim_logical_channel_sync(
QmiClientUim *client,
QmiMessageUimLogicalChannelInput *input,
GMainContext *context,
GError **error);
QmiMessageUimSendApduOutput *
qmi_client_uim_send_apdu_sync(
QmiClientUim *client,
QmiMessageUimSendApduInput *input,
GMainContext *context,
GError **error);