From 22e1b270551eeb990461b066ab2f30dfcc129b2c Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Wed, 20 Mar 2024 18:42:20 -0400 Subject: [PATCH 1/5] Move drivers back to their own (optionally dynamic) This allows for reuse from projects dynamically linked to libeuicc. Note that we don't reintroduce dlopen() based drivers here. All backends except stdio have been made optional using CMake options. C-side macros in driver.c have been adjusted to always mean enabling the corresponding backend when defined. Note that the GBinder backend does not need to distinguish between the current HIDL version and a future AIDL implementation. Both will have the same dependencies and will probably fall back on to each other automatically. --- CMakeLists.txt | 1 + README.md | 4 +- driver/CMakeLists.txt | 56 ++++++++++++++++++ {src/driver => driver}/apdu/at.c | 0 {src/driver => driver}/apdu/at.h | 0 {src/driver => driver}/apdu/gbinder_hidl.c | 0 {src/driver => driver}/apdu/gbinder_hidl.h | 0 {src/driver => driver}/apdu/pcsc.c | 0 {src/driver => driver}/apdu/pcsc.h | 0 {src/driver => driver}/apdu/stdio.c | 0 {src/driver => driver}/apdu/stdio.h | 0 {src => driver}/driver.c | 51 +++++----------- {src => driver}/driver.h | 4 +- {src/driver => driver}/http/curl.c | 0 {src/driver => driver}/http/curl.h | 0 {src/driver => driver}/http/stdio.c | 0 {src/driver => driver}/http/stdio.h | 0 src/CMakeLists.txt | 13 +--- src/driver/apdu/CMakeLists.txt | 69 ---------------------- src/driver/http/CMakeLists.txt | 29 --------- src/main.c | 28 ++++++++- 21 files changed, 104 insertions(+), 151 deletions(-) create mode 100644 driver/CMakeLists.txt rename {src/driver => driver}/apdu/at.c (100%) rename {src/driver => driver}/apdu/at.h (100%) rename {src/driver => driver}/apdu/gbinder_hidl.c (100%) rename {src/driver => driver}/apdu/gbinder_hidl.h (100%) rename {src/driver => driver}/apdu/pcsc.c (100%) rename {src/driver => driver}/apdu/pcsc.h (100%) rename {src/driver => driver}/apdu/stdio.c (100%) rename {src/driver => driver}/apdu/stdio.h (100%) rename {src => driver}/driver.c (68%) rename {src => driver}/driver.h (81%) rename {src/driver => driver}/http/curl.c (100%) rename {src/driver => driver}/http/curl.h (100%) rename {src/driver => driver}/http/stdio.c (100%) rename {src/driver => driver}/http/stdio.h (100%) delete mode 100644 src/driver/apdu/CMakeLists.txt delete mode 100644 src/driver/http/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 40ae580..f43709d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,4 +44,5 @@ endif() add_subdirectory(cjson) add_subdirectory(euicc) +add_subdirectory(driver) add_subdirectory(src) diff --git a/README.md b/README.md index 6a3e819..75c9d3f 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ then execute `./output/lpac` to use. - Droidian -Same as normal Debian/Ubuntu, however, in order to build the GBinder backends, you will need `libgbinder-dev`, `glib2.0-dev`, and you will have to set `-DLPAC_APDU_INTERFACE_GBINDER=ON` when invoking `cmake`. +Same as normal Debian/Ubuntu, however, in order to build the GBinder backends, you will need `libgbinder-dev`, `glib2.0-dev`, and you will have to set `-DLPAC_WITH_APDU_GBINDER=ON` when invoking `cmake`. @@ -487,7 +487,7 @@ A: The verification of SM-DP+ servers of telecom operators is diverse. Please ch ## License -- lpac (/src): AGPL-3.0 +- lpac (/src, /driver): AGPL-3.0 - libeuicc (/euicc): LGPL-v2 Copyright (c) 2023-2024 eSTKme Group diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt new file mode 100644 index 0000000..03412c6 --- /dev/null +++ b/driver/CMakeLists.txt @@ -0,0 +1,56 @@ +option(LPAC_DYNAMIC_DRIVERS "Build lpac/libeuicc driver backends as a dynamic library" OFF) + +option(LPAC_WITH_APDU_PCSC "Build APDU PCSC Backend (requires PCSC libraries)" ON) +option(LPAC_WITH_APDU_AT "Build APDU AT Backend" ON) +option(LPAC_WITH_APDU_GBINDER "Build APDU Gbinder backend for libhybris devices (requires gbinder headers)" OFF) + +option(LPAC_WITH_HTTP_CURL "Build HTTP Curl interface" ON) + +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} DIR_INTERFACE_SRCS) +if(LPAC_DYNAMIC_DRIVERS) + add_library(euicc-drivers SHARED ${DIR_INTERFACE_SRCS}) +else() + add_library(euicc-drivers STATIC ${DIR_INTERFACE_SRCS}) +endif() +target_link_libraries(euicc-drivers euicc cjson-static) +target_include_directories(euicc-drivers PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +target_sources(euicc-drivers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/apdu/stdio.c) +target_sources(euicc-drivers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/http/stdio.c) + +if(LPAC_WITH_APDU_PCSC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLPAC_WITH_APDU_PCSC") + target_sources(euicc-drivers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/apdu/pcsc.c) + if(WIN32) + target_link_libraries(euicc-drivers winscard) + elseif(APPLE) + target_link_libraries(euicc-drivers "-framework PCSC") + else() + find_package(PCSCLite) + target_link_libraries(euicc-drivers PCSCLite::PCSCLite) + endif() +endif() + +if(LPAC_WITH_APDU_AT) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLPAC_WITH_APDU_AT") + target_sources(euicc-drivers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/apdu/at.c) +endif() + +if(LPAC_WITH_APDU_GBINDER) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLPAC_WITH_APDU_GBINDER") + target_sources(euicc-drivers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/apdu/gbinder_hidl.c) + find_package(PkgConfig REQUIRED) + pkg_check_modules(GBINDER REQUIRED IMPORTED_TARGET libgbinder) + pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) + target_link_libraries(euicc-drivers PkgConfig::GBINDER PkgConfig::GLIB) +endif() + +if(LPAC_WITH_HTTP_CURL) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLPAC_WITH_HTTP_CURL") + target_sources(euicc-drivers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/http/curl.c) + find_package(curl) + target_link_libraries(euicc-drivers curl) + if(WIN32) + target_link_libraries(euicc-drivers ${DL_LIBRARY}) + endif() +endif() diff --git a/src/driver/apdu/at.c b/driver/apdu/at.c similarity index 100% rename from src/driver/apdu/at.c rename to driver/apdu/at.c diff --git a/src/driver/apdu/at.h b/driver/apdu/at.h similarity index 100% rename from src/driver/apdu/at.h rename to driver/apdu/at.h diff --git a/src/driver/apdu/gbinder_hidl.c b/driver/apdu/gbinder_hidl.c similarity index 100% rename from src/driver/apdu/gbinder_hidl.c rename to driver/apdu/gbinder_hidl.c diff --git a/src/driver/apdu/gbinder_hidl.h b/driver/apdu/gbinder_hidl.h similarity index 100% rename from src/driver/apdu/gbinder_hidl.h rename to driver/apdu/gbinder_hidl.h diff --git a/src/driver/apdu/pcsc.c b/driver/apdu/pcsc.c similarity index 100% rename from src/driver/apdu/pcsc.c rename to driver/apdu/pcsc.c diff --git a/src/driver/apdu/pcsc.h b/driver/apdu/pcsc.h similarity index 100% rename from src/driver/apdu/pcsc.h rename to driver/apdu/pcsc.h diff --git a/src/driver/apdu/stdio.c b/driver/apdu/stdio.c similarity index 100% rename from src/driver/apdu/stdio.c rename to driver/apdu/stdio.c diff --git a/src/driver/apdu/stdio.h b/driver/apdu/stdio.h similarity index 100% rename from src/driver/apdu/stdio.h rename to driver/apdu/stdio.h diff --git a/src/driver.c b/driver/driver.c similarity index 68% rename from src/driver.c rename to driver/driver.c index 2d7f524..a49bc94 100644 --- a/src/driver.c +++ b/driver/driver.c @@ -4,33 +4,33 @@ #include #include -#ifdef LPAC_WITH_APDU_GBINDER_HIDL +#ifdef LPAC_WITH_APDU_GBINDER #include "driver/apdu/gbinder_hidl.h" #endif -#ifndef LPAC_WITHOUT_APDU_PCSC +#ifdef LPAC_WITH_APDU_PCSC #include "driver/apdu/pcsc.h" #endif -#ifndef LPAC_WITHOUT_APDU_AT +#ifdef LPAC_WITH_APDU_AT #include "driver/apdu/at.h" #endif -#ifndef LPAC_WITHOUT_HTTP_CURL +#ifdef LPAC_WITH_HTTP_CURL #include "driver/http/curl.h" #endif #include "driver/apdu/stdio.h" #include "driver/http/stdio.h" static const struct lpac_driver *drivers[] = { -#ifdef LPAC_WITH_APDU_GBINDER_HIDL +#ifdef LPAC_WITH_APDU_GBINDER &driver_apdu_gbinder_hidl, #endif -#ifndef LPAC_WITHOUT_APDU_PCSC +#ifdef LPAC_WITH_APDU_PCSC &driver_apdu_pcsc, #endif -#ifndef LPAC_WITHOUT_APDU_AT +#ifdef LPAC_WITH_APDU_AT &driver_apdu_at, #endif -#ifndef LPAC_WITHOUT_HTTP_CURL +#ifdef LPAC_WITH_HTTP_CURL &driver_http_curl, #endif &driver_apdu_stdio, @@ -38,20 +38,14 @@ static const struct lpac_driver *drivers[] = { NULL, }; -struct euicc_apdu_interface driver_interface_apdu; -struct euicc_http_interface driver_interface_http; -static struct applet_entry applet_apdu = { - .name = "apdu", - .main = NULL, -}; -static struct applet_entry applet_http = { - .name = "http", - .main = NULL, -}; - static const struct lpac_driver *_driver_apdu = NULL; static const struct lpac_driver *_driver_http = NULL; +struct euicc_apdu_interface driver_interface_apdu; +struct euicc_http_interface driver_interface_http; +int (*driver_main_apdu)(int argc, char **argv) = NULL; +int (*driver_main_http)(int argc, char **argv) = NULL; + static const struct lpac_driver *_find_driver(enum lpac_driver_type type, const char *name) { for (int i = 0; drivers[i] != NULL; i++) @@ -92,8 +86,8 @@ int driver_init() _driver_apdu->init(&driver_interface_apdu); _driver_http->init(&driver_interface_http); - applet_apdu.main = _driver_apdu->main; - applet_http.main = _driver_http->main; + driver_main_apdu = _driver_apdu->main; + driver_main_http = _driver_http->main; return 0; } @@ -109,18 +103,3 @@ void driver_fini() _driver_http->fini(); } } - -static int dlsym_interface_applet_main(int argc, char **argv) -{ - static const struct applet_entry *applets[] = { - &applet_apdu, - &applet_http, - NULL, - }; - return applet_entry(argc, argv, applets); -} - -struct applet_entry driver_applet = { - .name = "driver", - .main = dlsym_interface_applet_main, -}; diff --git a/src/driver.h b/driver/driver.h similarity index 81% rename from src/driver.h rename to driver/driver.h index 1d95d81..942100b 100644 --- a/src/driver.h +++ b/driver/driver.h @@ -2,7 +2,6 @@ #include #include #include -#include enum lpac_driver_type { @@ -21,7 +20,8 @@ struct lpac_driver extern struct euicc_apdu_interface driver_interface_apdu; extern struct euicc_http_interface driver_interface_http; -extern struct applet_entry driver_applet; +extern int (*driver_main_apdu)(int argc, char **argv); +extern int (*driver_main_http)(int argc, char **argv); int driver_init(void); void driver_fini(void); diff --git a/src/driver/http/curl.c b/driver/http/curl.c similarity index 100% rename from src/driver/http/curl.c rename to driver/http/curl.c diff --git a/src/driver/http/curl.h b/driver/http/curl.h similarity index 100% rename from src/driver/http/curl.h rename to driver/http/curl.h diff --git a/src/driver/http/stdio.c b/driver/http/stdio.c similarity index 100% rename from src/driver/http/stdio.c rename to driver/http/stdio.c diff --git a/src/driver/http/stdio.h b/driver/http/stdio.h similarity index 100% rename from src/driver/http/stdio.h rename to driver/http/stdio.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4bdb7b0..531815d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,19 +11,8 @@ aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/applet/chip DIR_LPAC_SRCS) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/applet/notification DIR_LPAC_SRCS) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/applet/profile DIR_LPAC_SRCS) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/driver DIR_LPAC_SRCS) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/driver/apdu DIR_LPAC_SRCS) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/driver/http DIR_LPAC_SRCS) - -find_package(PCSCLite) -find_package(curl) - add_executable(lpac ${DIR_LPAC_SRCS}) -set_target_properties(lpac PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output" - BUILD_RPATH "${RPATH_BINARY_PATH}" -) -target_link_libraries(lpac euicc PCSCLite::PCSCLite curl ${DL_LIBRARY}) +target_link_libraries(lpac euicc euicc-drivers) target_include_directories(lpac PUBLIC $) find_package(Git) diff --git a/src/driver/apdu/CMakeLists.txt b/src/driver/apdu/CMakeLists.txt deleted file mode 100644 index 805893c..0000000 --- a/src/driver/apdu/CMakeLists.txt +++ /dev/null @@ -1,69 +0,0 @@ -option(LPAC_APDU_INTERFACE_PCSC "Build PCSC backend (requires PCSC libraries)" ON) -option(LPAC_APDU_INTERFACE_GBINDER "Build GBinder backend for libhybris devices (requires gbinder headers)" OFF) - -if(LPAC_APDU_INTERFACE_PCSC) - add_library(apduinterface_pcsc SHARED pcsc.c) - target_link_libraries(apduinterface_pcsc euicc cjson-static) - set_target_properties(apduinterface_pcsc PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") - set_target_properties(apduinterface_pcsc PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") - if(UNIX) - install(TARGETS apduinterface_pcsc LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/lpac") - endif() - - if(WIN32) - target_link_libraries(apduinterface_pcsc winscard) - elseif(APPLE) - target_link_libraries(apduinterface_pcsc "-framework PCSC") - else() - find_package(PCSCLite) - target_link_libraries(apduinterface_pcsc PCSCLite::PCSCLite) - endif() -endif() - -add_library(apduinterface_at SHARED at.c) -target_link_libraries(apduinterface_at euicc) -set_target_properties(apduinterface_at PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") -set_target_properties(apduinterface_at PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") -if(UNIX) - install(TARGETS apduinterface_at LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/lpac") -endif() - -add_library(apduinterface_stdio SHARED stdio.c) -target_link_libraries(apduinterface_stdio euicc cjson-static) -set_target_properties(apduinterface_stdio PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") -set_target_properties(apduinterface_stdio PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") -if(UNIX) - install(TARGETS apduinterface_stdio LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/lpac") -endif() - -if(LPAC_APDU_INTERFACE_GBINDER) - add_library(apduinterface_gbinder_hidl SHARED gbinder_hidl.c) - target_link_libraries(apduinterface_gbinder_hidl euicc) - set_target_properties(apduinterface_gbinder_hidl PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") - set_target_properties(apduinterface_gbinder_hidl PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") - install(TARGETS apduinterface_gbinder_hidl LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/lpac") - - find_package(PkgConfig REQUIRED) - pkg_check_modules(GBINDER REQUIRED IMPORTED_TARGET libgbinder) - target_link_libraries(apduinterface_gbinder_hidl PkgConfig::GBINDER) -endif() - -if(CYGWIN) - if(LPAC_APDU_INTERFACE_PCSC) - add_custom_command(TARGET apduinterface_pcsc POST_BUILD - COMMAND ${CMAKE_COMMAND} -E rename - ${CMAKE_BINARY_DIR}/output/cygapduinterface_pcsc.dll ${CMAKE_BINARY_DIR}/output/libapduinterface_pcsc.dll - COMMAND ${CMAKE_COMMAND} -E echo - "Renamed ${CMAKE_BINARY_DIR}/output/cygapduinterface_pcsc.dll to ${CMAKE_BINARY_DIR}/output/libapduinterface_pcsc.dll") - endif() - add_custom_command(TARGET apduinterface_at POST_BUILD - COMMAND ${CMAKE_COMMAND} -E rename - ${CMAKE_BINARY_DIR}/output/cygapduinterface_at.dll ${CMAKE_BINARY_DIR}/output/libapduinterface_at.dll - COMMAND ${CMAKE_COMMAND} -E echo - "Renamed ${CMAKE_BINARY_DIR}/output/cygapduinterface_at.dll to ${CMAKE_BINARY_DIR}/output/libapduinterface_at.dll") - add_custom_command(TARGET apduinterface_stdio POST_BUILD - COMMAND ${CMAKE_COMMAND} -E rename - ${CMAKE_BINARY_DIR}/output/cygapduinterface_stdio.dll ${CMAKE_BINARY_DIR}/output/libapduinterface_stdio.dll - COMMAND ${CMAKE_COMMAND} -E echo - "Renamed ${CMAKE_BINARY_DIR}/output/cygapduinterface_stdio.dll to ${CMAKE_BINARY_DIR}/output/libapduinterface_stdio.dll") -endif() diff --git a/src/driver/http/CMakeLists.txt b/src/driver/http/CMakeLists.txt deleted file mode 100644 index ffc158b..0000000 --- a/src/driver/http/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -add_library(httpinterface_curl SHARED curl.c) -target_link_libraries(httpinterface_curl euicc ${DL_LIBRARY}) -set_target_properties(httpinterface_curl PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") -set_target_properties(httpinterface_curl PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") -if(UNIX) - install(TARGETS httpinterface_curl LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/lpac") -endif() - - -add_library(httpinterface_stdio SHARED stdio.c) -target_link_libraries(httpinterface_stdio euicc cjson-static) -set_target_properties(httpinterface_stdio PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") -set_target_properties(httpinterface_stdio PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output") -if(UNIX) - install(TARGETS httpinterface_stdio LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/lpac") -endif() - -if(CYGWIN) - add_custom_command(TARGET httpinterface_curl POST_BUILD - COMMAND ${CMAKE_COMMAND} -E rename - ${CMAKE_BINARY_DIR}/output/cyghttpinterface_curl.dll ${CMAKE_BINARY_DIR}/output/libhttpinterface_curl.dll - COMMAND ${CMAKE_COMMAND} -E echo - "Renamed ${CMAKE_BINARY_DIR}/output/cyghttpinterface_curl.dll to ${CMAKE_BINARY_DIR}/output/libhttpinterface_curl.dll") - add_custom_command(TARGET httpinterface_stdio POST_BUILD - COMMAND ${CMAKE_COMMAND} -E rename - ${CMAKE_BINARY_DIR}/output/cyghttpinterface_stdio.dll ${CMAKE_BINARY_DIR}/output/libhttpinterface_stdio.dll - COMMAND ${CMAKE_COMMAND} -E echo - "Renamed ${CMAKE_BINARY_DIR}/output/cyghttpinterface_stdio.dll to ${CMAKE_BINARY_DIR}/output/libhttpinterface_stdio.dll") -endif() diff --git a/src/main.c b/src/main.c index 6f554c1..42fc630 100644 --- a/src/main.c +++ b/src/main.c @@ -7,14 +7,40 @@ #include #include +#include -#include "driver.h" #include "applet.h" #include "applet/chip.h" #include "applet/profile.h" #include "applet/notification.h" #include "applet/version.h" +static struct applet_entry applet_apdu = { + .name = "apdu", + .main = NULL, +}; +static struct applet_entry applet_http = { + .name = "http", + .main = NULL, +}; + +static int driver_applet_main(int argc, char **argv) +{ + applet_apdu.main = driver_main_apdu; + applet_http.main = driver_main_http; + static const struct applet_entry *applets[] = { + &applet_apdu, + &applet_http, + NULL, + }; + return applet_entry(argc, argv, applets); +} + +struct applet_entry driver_applet = { + .name = "driver", + .main = driver_applet_main, +}; + static const struct applet_entry *applets[] = { &driver_applet, &applet_chip, From 75acafeee4a9312cfd0b13650c8060c294f68ed4 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Wed, 20 Mar 2024 19:03:01 -0400 Subject: [PATCH 2/5] Set up installed headers and pkg-config for libeuicc-drivers.so Also separate lpac_driver struct from the installed version --- driver.private.h | 16 ++++++++++++++++ driver/CMakeLists.txt | 20 +++++++++++++++++++- driver/apdu/at.h | 2 +- driver/apdu/gbinder_hidl.h | 2 +- driver/apdu/pcsc.h | 2 +- driver/apdu/stdio.h | 2 +- driver/driver.c | 1 + driver/driver.h | 15 --------------- driver/driver.private.h | 17 +++++++++++++++++ driver/http/curl.h | 2 +- driver/http/stdio.h | 2 +- driver/libeuicc-drivers.pc.in | 11 +++++++++++ 12 files changed, 70 insertions(+), 22 deletions(-) create mode 100644 driver.private.h create mode 100644 driver/driver.private.h create mode 100644 driver/libeuicc-drivers.pc.in diff --git a/driver.private.h b/driver.private.h new file mode 100644 index 0000000..4eb5e3f --- /dev/null +++ b/driver.private.h @@ -0,0 +1,16 @@ +#pragma once + +enum lpac_driver_type +{ + DRIVER_APDU, + DRIVER_HTTP, +}; + +struct lpac_driver +{ + enum lpac_driver_type type; + const char *name; + int (*init)(void *interface); + int (*main)(int argc, char **argv); + void (*fini)(void); +}; diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt index 03412c6..4a181c1 100644 --- a/driver/CMakeLists.txt +++ b/driver/CMakeLists.txt @@ -1,4 +1,5 @@ -option(LPAC_DYNAMIC_DRIVERS "Build lpac/libeuicc driver backends as a dynamic library" OFF) +include(CMakeDependentOption) +cmake_dependent_option(LPAC_DYNAMIC_DRIVERS "Build lpac/libeuicc driver backends as a dynamic library" OFF "LPAC_DYNAMIC_LIBEUICC" OFF) option(LPAC_WITH_APDU_PCSC "Build APDU PCSC Backend (requires PCSC libraries)" ON) option(LPAC_WITH_APDU_AT "Build APDU AT Backend" ON) @@ -54,3 +55,20 @@ if(LPAC_WITH_HTTP_CURL) target_link_libraries(euicc-drivers ${DL_LIBRARY}) endif() endif() + +if(LPAC_DYNAMIC_DRIVERS) + # Install headers + file(GLOB ALL_HEADERS "*.h") + foreach(header ${ALL_HEADERS}) + if(${header} MATCHES "^.*\.private\.h$") + list(REMOVE_ITEM ALL_HEADERS ${header}) + endif() + endforeach() + set_target_properties(euicc-drivers PROPERTIES PUBLIC_HEADER "${ALL_HEADERS}") + # Install a pkg-config file + configure_file(libeuicc-drivers.pc.in libeuicc-drivers.pc @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libeuicc-drivers.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + set_target_properties(euicc-drivers PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}) + install(TARGETS euicc-drivers LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/euicc) +endif() diff --git a/driver/apdu/at.h b/driver/apdu/at.h index 70d6d40..1105d24 100644 --- a/driver/apdu/at.h +++ b/driver/apdu/at.h @@ -1,4 +1,4 @@ #pragma once -#include +#include extern const struct lpac_driver driver_apdu_at; diff --git a/driver/apdu/gbinder_hidl.h b/driver/apdu/gbinder_hidl.h index 113404f..5907fa0 100644 --- a/driver/apdu/gbinder_hidl.h +++ b/driver/apdu/gbinder_hidl.h @@ -1,4 +1,4 @@ #pragma once -#include +#include extern const struct lpac_driver driver_apdu_gbinder_hidl; diff --git a/driver/apdu/pcsc.h b/driver/apdu/pcsc.h index 23b9b81..56f2cc9 100644 --- a/driver/apdu/pcsc.h +++ b/driver/apdu/pcsc.h @@ -1,4 +1,4 @@ #pragma once -#include +#include extern const struct lpac_driver driver_apdu_pcsc; diff --git a/driver/apdu/stdio.h b/driver/apdu/stdio.h index 48c42fa..c507020 100644 --- a/driver/apdu/stdio.h +++ b/driver/apdu/stdio.h @@ -1,4 +1,4 @@ #pragma once -#include +#include extern const struct lpac_driver driver_apdu_stdio; diff --git a/driver/driver.c b/driver/driver.c index a49bc94..2cbea5c 100644 --- a/driver/driver.c +++ b/driver/driver.c @@ -1,4 +1,5 @@ #include "driver.h" +#include "driver.private.h" #include #include diff --git a/driver/driver.h b/driver/driver.h index 942100b..d934d90 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -3,21 +3,6 @@ #include #include -enum lpac_driver_type -{ - DRIVER_APDU, - DRIVER_HTTP, -}; - -struct lpac_driver -{ - enum lpac_driver_type type; - const char *name; - int (*init)(void *interface); - int (*main)(int argc, char **argv); - void (*fini)(void); -}; - extern struct euicc_apdu_interface driver_interface_apdu; extern struct euicc_http_interface driver_interface_http; extern int (*driver_main_apdu)(int argc, char **argv); diff --git a/driver/driver.private.h b/driver/driver.private.h new file mode 100644 index 0000000..44b99c0 --- /dev/null +++ b/driver/driver.private.h @@ -0,0 +1,17 @@ +#pragma once + +enum lpac_driver_type +{ + DRIVER_APDU, + DRIVER_HTTP, +}; + +struct lpac_driver +{ + enum lpac_driver_type type; + const char *name; + int (*init)(void *interface); + int (*main)(int argc, char **argv); + void (*fini)(void); +}; + diff --git a/driver/http/curl.h b/driver/http/curl.h index 83515fa..b070a58 100644 --- a/driver/http/curl.h +++ b/driver/http/curl.h @@ -1,4 +1,4 @@ #pragma once -#include +#include extern const struct lpac_driver driver_http_curl; diff --git a/driver/http/stdio.h b/driver/http/stdio.h index 83f530d..c6b9836 100644 --- a/driver/http/stdio.h +++ b/driver/http/stdio.h @@ -1,4 +1,4 @@ #pragma once -#include +#include extern const struct lpac_driver driver_http_stdio; diff --git a/driver/libeuicc-drivers.pc.in b/driver/libeuicc-drivers.pc.in new file mode 100644 index 0000000..e99ba8e --- /dev/null +++ b/driver/libeuicc-drivers.pc.in @@ -0,0 +1,11 @@ +prefix="@CMAKE_INSTALL_PREFIX@" +exec_prefix="${prefix}" +libdir="${prefix}/lib" +includedir="${prefix}/include" + +Name: libeuicc-drivers +Description: An "official" collection of drivers (backends) and their loader for use with libeuicc +Version: @PROJECT_VERSION@ +Requires: libeuicc = @PROJECT_VERSION@ +Cflags: -I${includedir} +Libs: -L${libdir} -leuicc-drivers From e347ae12ed22ac02829a759fb96c16d6dd581bc1 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Wed, 20 Mar 2024 19:06:24 -0400 Subject: [PATCH 3/5] Namespace all exposed symbols in libeuicc-drivers.so --- driver/driver.c | 20 ++++++++++---------- driver/driver.h | 12 ++++++------ src/main.c | 12 ++++++------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/driver/driver.c b/driver/driver.c index 2cbea5c..9be8ec3 100644 --- a/driver/driver.c +++ b/driver/driver.c @@ -42,10 +42,10 @@ static const struct lpac_driver *drivers[] = { static const struct lpac_driver *_driver_apdu = NULL; static const struct lpac_driver *_driver_http = NULL; -struct euicc_apdu_interface driver_interface_apdu; -struct euicc_http_interface driver_interface_http; -int (*driver_main_apdu)(int argc, char **argv) = NULL; -int (*driver_main_http)(int argc, char **argv) = 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 lpac_driver *_find_driver(enum lpac_driver_type type, const char *name) { @@ -68,7 +68,7 @@ static const struct lpac_driver *_find_driver(enum lpac_driver_type type, const return NULL; } -int driver_init() +int euicc_driver_init() { _driver_apdu = _find_driver(DRIVER_APDU, getenv("LPAC_APDU")); if (_driver_apdu == NULL) @@ -84,16 +84,16 @@ int driver_init() return -1; } - _driver_apdu->init(&driver_interface_apdu); - _driver_http->init(&driver_interface_http); + _driver_apdu->init(&euicc_driver_interface_apdu); + _driver_http->init(&euicc_driver_interface_http); - driver_main_apdu = _driver_apdu->main; - driver_main_http = _driver_http->main; + euicc_driver_main_apdu = _driver_apdu->main; + euicc_driver_main_http = _driver_http->main; return 0; } -void driver_fini() +void euicc_driver_fini() { if (_driver_apdu != NULL) { diff --git a/driver/driver.h b/driver/driver.h index d934d90..512049d 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -3,10 +3,10 @@ #include #include -extern struct euicc_apdu_interface driver_interface_apdu; -extern struct euicc_http_interface driver_interface_http; -extern int (*driver_main_apdu)(int argc, char **argv); -extern int (*driver_main_http)(int argc, char **argv); +extern struct euicc_apdu_interface euicc_driver_interface_apdu; +extern struct euicc_http_interface euicc_driver_interface_http; +extern int (*euicc_driver_main_apdu)(int argc, char **argv); +extern int (*euicc_driver_main_http)(int argc, char **argv); -int driver_init(void); -void driver_fini(void); +int euicc_driver_init(void); +void euicc_driver_fini(void); diff --git a/src/main.c b/src/main.c index 42fc630..79606f6 100644 --- a/src/main.c +++ b/src/main.c @@ -26,8 +26,8 @@ static struct applet_entry applet_http = { static int driver_applet_main(int argc, char **argv) { - applet_apdu.main = driver_main_apdu; - applet_http.main = driver_main_http; + applet_apdu.main = euicc_driver_main_apdu; + applet_http.main = euicc_driver_main_http; static const struct applet_entry *applets[] = { &applet_apdu, &applet_http, @@ -79,19 +79,19 @@ int main(int argc, char **argv) memset(&euicc_ctx, 0, sizeof(euicc_ctx)); - if (driver_init()) + if (euicc_driver_init()) { return -1; } - euicc_ctx.apdu.interface = &driver_interface_apdu; - euicc_ctx.http.interface = &driver_interface_http; + euicc_ctx.apdu.interface = &euicc_driver_interface_apdu; + euicc_ctx.http.interface = &euicc_driver_interface_http; ret = applet_entry(argc, argv, applets); main_fini_euicc(); - driver_fini(); + euicc_driver_fini(); return ret; } From 3292931e2bb289184fdcf6a8085f9640ab396a0c Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Wed, 20 Mar 2024 19:14:04 -0400 Subject: [PATCH 4/5] Add back output directory config This is needed by github actions --- src/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 531815d..4c831ec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,10 @@ add_custom_target(version -P ${CMAKE_MODULE_PATH}/git-version.cmake ) add_dependencies(lpac version) +set_target_properties(lpac PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output" + BUILD_RPATH "${RPATH_BINARY_PATH}" +) if(UNIX) install(TARGETS lpac RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") From 1413258fa7acb8f637b67263f1d66d2df7d735e5 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Wed, 20 Mar 2024 19:17:01 -0400 Subject: [PATCH 5/5] curl is dlopen()'d on Windows --- driver/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt index 4a181c1..848d835 100644 --- a/driver/CMakeLists.txt +++ b/driver/CMakeLists.txt @@ -49,10 +49,11 @@ endif() if(LPAC_WITH_HTTP_CURL) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLPAC_WITH_HTTP_CURL") target_sources(euicc-drivers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/http/curl.c) - find_package(curl) - target_link_libraries(euicc-drivers curl) if(WIN32) target_link_libraries(euicc-drivers ${DL_LIBRARY}) + else() + find_package(curl) + target_link_libraries(euicc-drivers curl) endif() endif()