mirror of
https://github.com/estkme-group/lpac
synced 2025-06-29 16:22:57 +02:00
* 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>
128 lines
2.8 KiB
C
128 lines
2.8 KiB
C
#include "driver.h"
|
|
#include "driver.private.h"
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#ifdef LPAC_WITH_APDU_GBINDER
|
|
#include "driver/apdu/gbinder_hidl.h"
|
|
#endif
|
|
|
|
#ifdef LPAC_WITH_APDU_QMI
|
|
#include "driver/apdu/qmi.h"
|
|
#endif
|
|
|
|
#ifdef LPAC_WITH_APDU_QMI_QRTR
|
|
#include "driver/apdu/qmi_qrtr.h"
|
|
#endif
|
|
|
|
#ifdef LPAC_WITH_APDU_PCSC
|
|
#include "driver/apdu/pcsc.h"
|
|
#endif
|
|
#ifdef LPAC_WITH_APDU_AT
|
|
#include "driver/apdu/at.h"
|
|
#endif
|
|
#ifdef LPAC_WITH_HTTP_CURL
|
|
#include "driver/http/curl.h"
|
|
#endif
|
|
#include "driver/apdu/stdio.h"
|
|
#include "driver/http/stdio.h"
|
|
|
|
static const struct euicc_driver *drivers[] = {
|
|
#ifdef LPAC_WITH_APDU_GBINDER
|
|
&driver_apdu_gbinder_hidl,
|
|
#endif
|
|
#ifdef LPAC_WITH_APDU_QMI
|
|
&driver_apdu_qmi,
|
|
#endif
|
|
#ifdef LPAC_WITH_APDU_QMI_QRTR
|
|
&driver_apdu_qmi_qrtr,
|
|
#endif
|
|
#ifdef LPAC_WITH_APDU_PCSC
|
|
&driver_apdu_pcsc,
|
|
#endif
|
|
#ifdef LPAC_WITH_APDU_AT
|
|
&driver_apdu_at,
|
|
#endif
|
|
#ifdef LPAC_WITH_HTTP_CURL
|
|
&driver_http_curl,
|
|
#endif
|
|
&driver_apdu_stdio,
|
|
&driver_http_stdio,
|
|
NULL,
|
|
};
|
|
|
|
static const struct euicc_driver *_driver_apdu = NULL;
|
|
static const struct euicc_driver *_driver_http = NULL;
|
|
|
|
struct euicc_apdu_interface euicc_driver_interface_apdu;
|
|
struct euicc_http_interface euicc_driver_interface_http;
|
|
int (*euicc_driver_main_apdu)(int argc, char **argv) = NULL;
|
|
int (*euicc_driver_main_http)(int argc, char **argv) = NULL;
|
|
|
|
static const struct euicc_driver *_find_driver(enum euicc_driver_type type, const char *name)
|
|
{
|
|
for (int i = 0; drivers[i] != NULL; i++)
|
|
{
|
|
const struct euicc_driver *d = drivers[i];
|
|
if (d->type != type)
|
|
{
|
|
continue;
|
|
}
|
|
if (name == NULL)
|
|
{
|
|
return d;
|
|
}
|
|
if (strcmp(d->name, name) == 0)
|
|
{
|
|
return d;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
int euicc_driver_init(const char *apdu_driver_name, const char *http_driver_name)
|
|
{
|
|
_driver_apdu = _find_driver(DRIVER_APDU, apdu_driver_name);
|
|
if (_driver_apdu == NULL)
|
|
{
|
|
fprintf(stderr, "No APDU driver found\n");
|
|
return -1;
|
|
}
|
|
|
|
_driver_http = _find_driver(DRIVER_HTTP, http_driver_name);
|
|
if (_driver_http == NULL)
|
|
{
|
|
fprintf(stderr, "No HTTP driver found\n");
|
|
return -1;
|
|
}
|
|
|
|
if (_driver_apdu->init(&euicc_driver_interface_apdu))
|
|
{
|
|
fprintf(stderr, "APDU driver init failed\n");
|
|
return -1;
|
|
}
|
|
|
|
if (_driver_http->init(&euicc_driver_interface_http))
|
|
{
|
|
fprintf(stderr, "HTTP driver init failed\n");
|
|
return -1;
|
|
}
|
|
|
|
euicc_driver_main_apdu = _driver_apdu->main;
|
|
euicc_driver_main_http = _driver_http->main;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void euicc_driver_fini()
|
|
{
|
|
if (_driver_apdu != NULL)
|
|
{
|
|
_driver_apdu->fini(&euicc_driver_interface_apdu);
|
|
}
|
|
if (_driver_http != NULL)
|
|
{
|
|
_driver_http->fini(&euicc_driver_interface_http);
|
|
}
|
|
}
|