From e84a571c048925354c982ba967651b168fb33bc9 Mon Sep 17 00:00:00 2001 From: Eric Wild Date: Thu, 28 Nov 2019 17:30:30 +0100 Subject: [PATCH] fix the host/emulation build Going for __ARM__ to distinguish host and firmware builds is not sufficient here, since we might be building on a ARM host, so there is now a OCTSIMFWBUILD define. Change-Id: Ib07a58b6102b1709f295d08a764c6f118a2d0b9e --- ccid_common/ccid_slot_fsm.c | 39 +++++++++++++++++++++++-------------- ccid_common/iso7816_3.c | 2 +- ccid_common/iso7816_fsm.c | 6 ++++-- ccid_host/Makefile | 2 ++ sysmoOCTSIM/gcc/Makefile | 2 +- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/ccid_common/ccid_slot_fsm.c b/ccid_common/ccid_slot_fsm.c index 3a591d7..08cbbad 100644 --- a/ccid_common/ccid_slot_fsm.c +++ b/ccid_common/ccid_slot_fsm.c @@ -98,7 +98,11 @@ static void iso_fsm_slot_icc_power_on_async(struct ccid_slot *cs, struct msgb *m osmo_fsm_inst_dispatch(ss->fi, ISO7816_E_POWER_UP_IND, NULL); cs->icc_powered = true; card_uart_ctrl(ss->cuart, CUART_CTL_CLOCK, true); +#ifdef OCTSIMFWBUILD delay_us(10000); +#else + usleep(10000); +#endif osmo_fsm_inst_dispatch(ss->fi, ISO7816_E_RESET_REL_IND, NULL); card_uart_ctrl(ss->cuart, CUART_CTL_RST, false); @@ -119,7 +123,9 @@ static void iso_fsm_clot_user_cb(struct osmo_fsm_inst *fi, int event, int cause, case ISO7816_E_PPS_DONE_IND: case ISO7816_E_PPS_FAILED_IND: cs->event_data = data; +#ifdef OCTSIMFWBUILD asm volatile("dmb st": : :"memory"); +#endif cs->event = event; break; default: @@ -329,35 +335,38 @@ static int iso_fsm_slot_init(struct ccid_slot *cs) void *ctx = g_tall_ctx; /* FIXME */ struct iso_fsm_slot *ss = ccid_slot2iso_fsm_slot(cs); struct card_uart *cuart = talloc_zero(ctx, struct card_uart); - char id_buf[16] = "SIM0"; - char devname[] = "foobar"; + char id_buf[3+3+1]; + char devname[2+1]; + char *devnamep = 0; + char *drivername = "asf4"; int rc; LOGPCS(cs, LOGL_DEBUG, "%s\n", __func__); - /* HACK: make this in some way configurable so it works both in the firmware - * and on the host (functionfs) */ -// if (cs->slot_nr == 0) { -// cs->icc_present = true; -// devname = "/dev/ttyUSB5"; -// } - devname[0] = cs->slot_nr +0x30; - devname[1] = 0; - //sprintf(devname, "%d", cs->slot_nr); + snprintf(id_buf, sizeof(id_buf), "SIM%d", cs->slot_nr); +#ifdef OCTSIMFWBUILD + snprintf(devname, sizeof(devname), "%d", cs->slot_nr); + devnamep = devname; +#else + if (cs->slot_nr == 0) { + cs->icc_present = true; + devnamep = "/dev/ttyUSB5"; + } + drivername = "tty"; +#endif if (!cuart) return -ENOMEM; - //snprintf(id_buf, sizeof(id_buf), "SIM%d", cs->slot_nr); - id_buf[3] = cs->slot_nr +0x30; - if (devname) { - rc = card_uart_open(cuart, "asf4", devname); + if (devnamep) { + rc = card_uart_open(cuart, drivername, devnamep); if (rc < 0) { LOGPCS(cs, LOGL_ERROR, "Cannot open UART %s: %d\n", devname, rc); talloc_free(cuart); return rc; } } + ss->fi = iso7816_fsm_alloc(ctx, LOGL_DEBUG, id_buf, cuart, iso_fsm_clot_user_cb, ss); if (!ss->fi) { LOGPCS(cs, LOGL_ERROR, "Cannot allocate ISO FSM\n"); diff --git a/ccid_common/iso7816_3.c b/ccid_common/iso7816_3.c index f7262fb..9a3a7cb 100644 --- a/ccid_common/iso7816_3.c +++ b/ccid_common/iso7816_3.c @@ -18,7 +18,7 @@ #include #include -#include "utils.h" +#include #include "iso7816_3.h" const uint16_t iso7816_3_fi_table[16] = { diff --git a/ccid_common/iso7816_fsm.c b/ccid_common/iso7816_fsm.c index c9eba8d..c76d97d 100644 --- a/ccid_common/iso7816_fsm.c +++ b/ccid_common/iso7816_fsm.c @@ -1193,7 +1193,7 @@ static void tpdu_s_init_action(struct osmo_fsm_inst *fi, uint32_t event, void *d } } -#include + static void tpdu_s_tx_hdr_action(struct osmo_fsm_inst *fi, uint32_t event, void *data) { struct osmo_fsm_inst *parent_fi = fi->proc.parent; @@ -1213,7 +1213,9 @@ static void tpdu_s_tx_hdr_action(struct osmo_fsm_inst *fi, uint32_t event, void } - +#if 0 +#include +#endif static void tpdu_s_procedure_action(struct osmo_fsm_inst *fi, uint32_t event, void *data) { struct tpdu_fsm_priv *tfp = get_tpdu_fsm_priv(fi); diff --git a/ccid_host/Makefile b/ccid_host/Makefile index e9f34cc..7625177 100644 --- a/ccid_host/Makefile +++ b/ccid_host/Makefile @@ -11,6 +11,7 @@ ccid_functionfs: ccid_main_functionfs.o \ ../ccid_common/ccid_proto.o \ ../ccid_common/ccid_device.o \ ../ccid_common/ccid_slot_fsm.o \ + ../ccid_common/iso7816_3.o \ ../ccid_common/iso7816_fsm.o $(CC) $(CFLAGS) -o $@ $^ $(LIBS) -laio @@ -28,6 +29,7 @@ cuart_fsm_test: cuart_fsm_test.o \ cuart_driver_tty.o \ utils_ringbuffer.o \ ../ccid_common/iso7816_fsm.o \ + ../ccid_common/iso7816_3.o \ ../ccid_common/cuart.o $(CC) $(CFLAGS) -o $@ $^ $(LIBS) $(shell pkg-config --libs libosmosim) diff --git a/sysmoOCTSIM/gcc/Makefile b/sysmoOCTSIM/gcc/Makefile index 7a37036..6c0974f 100644 --- a/sysmoOCTSIM/gcc/Makefile +++ b/sysmoOCTSIM/gcc/Makefile @@ -9,7 +9,7 @@ CROSS_COMPILE= arm-none-eabi- CFLAGS_CPU=-D__SAME54N19A__ -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 CFLAGS=-x c -mthumb -DDEBUG -Os -ffunction-sections -fdata-sections -mlong-calls \ - -g3 -Wall -c -std=gnu99 $(CFLAGS_CPU) + -g3 -Wall -c -std=gnu99 $(CFLAGS_CPU) -DOCTSIMFWBUILD CC = $(CROSS_COMPILE)gcc LD = $(CROSS_COMPILE)ld