From 3428e415b3274bffcb216e473e84e54a609cd9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Redon?= Date: Thu, 11 Oct 2018 19:14:00 +0200 Subject: [PATCH] add sim switch and modem reset for OWHW Change-Id: I9d395c2c7e10a0e7e5f7c84bc7d951431bfc68ba --- src/simtrace2-remsim_client.c | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/simtrace2-remsim_client.c b/src/simtrace2-remsim_client.c index 4e9b0a9..3fc5da0 100644 --- a/src/simtrace2-remsim_client.c +++ b/src/simtrace2-remsim_client.c @@ -18,6 +18,9 @@ #include #include +#include +#include +#include #include #include @@ -25,6 +28,7 @@ #include "simtrace2/libusb_util.h" #include "simtrace2/simtrace_prot.h" +#include "simtrace2/simtrace_usb.h" #include "simtrace2/apdu_dispatch.h" #include "simtrace2/simtrace2-discovery.h" @@ -797,6 +801,52 @@ int main(int argc, char **argv) goto close_exit; } + // switch modem SIM port to emulated SIM on OWHW + if (USB_VENDOR_OPENMOKO == ifm->vendor && USB_PRODUCT_OWHW_SAM3 == ifm->product) { // we are on the OWHW + int modem = -1; + switch (ifm->interface) { // the USB interface indicates for which modem we want to emulate the SIM + case 0: + modem = 1; + break; + case 1: + modem = 2; + break; + default: + fprintf(stderr, "unknown GPIO for SIMtrace interface %d\n", ifm->interface); + goto close_exit; + } + // + char gpio_path[PATH_MAX]; + snprintf(gpio_path, sizeof(gpio_path), "/dev/gpio/connect_st_usim%d/value", modem); + int connec_st_usim = open(gpio_path, O_WRONLY); + if (-1 == connec_st_usim) { + fprintf(stderr, "can't open GPIO %s to switch modem %d to emulated USIM\n", gpio_path, modem); + goto close_exit; + } + if (1 != write(connec_st_usim, "1", 1)) { + fprintf(stderr, "can't write GPIO %s to switch modem %d to emulated USIM\n", gpio_path, modem); + goto close_exit; + } + printf("switched modem %d to emulated USIM\n", modem); + + snprintf(gpio_path, sizeof(gpio_path), "/dev/gpio/mdm%d_rst/value", modem); + int mdm_rst = open(gpio_path, O_WRONLY); + if (-1 == mdm_rst) { + fprintf(stderr, "can't open GPIO %s to reset modem %d\n", gpio_path, modem); + goto close_exit; + } + if (1 != write(mdm_rst, "1", 1)) { + fprintf(stderr, "can't write GPIO %s to reset modem %d\n", gpio_path, modem); + goto close_exit; + } + sleep(1); // wait a bit to ensure reset is effective + if (1 != write(mdm_rst, "0", 1)) { + fprintf(stderr, "can't write GPIO %s to reset modem %d\n", gpio_path, modem); + goto close_exit; + } + printf("modem %d reset\n", modem); + } + /* simulate card-insert to modem (owhw, not qmod) */ cardem_request_card_insert(ci, true);