diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/libcommon/include/card_emu.h | 14 | ||||
-rw-r--r-- | firmware/libcommon/source/card_emu.c | 16 | ||||
-rw-r--r-- | firmware/libcommon/source/mode_cardemu.c | 15 | ||||
-rw-r--r-- | firmware/test/card_emu_tests.c | 2 |
4 files changed, 27 insertions, 20 deletions
diff --git a/firmware/libcommon/include/card_emu.h b/firmware/libcommon/include/card_emu.h index a3c1cf2..e545593 100644 --- a/firmware/libcommon/include/card_emu.h +++ b/firmware/libcommon/include/card_emu.h @@ -29,8 +29,18 @@ enum card_io { CARD_IO_CLK, }; -struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan, - uint8_t in_ep, uint8_t irq_ep); +/** initialise card slot + * @param[in] slot_num slot number (arbitrary number) + * @param[in] tc_chan timer counter channel (to measure the ETU) + * @param[in] uart_chan UART peripheral channel + * @param[in] in_ep USB IN end point number + * @param[in] irq_ep USB INTerrupt end point number + * @param[in] vcc_active initial VCC signal state (true = on) + * @param[in] in_reset initial RST signal state (true = reset asserted) + * @param[in] clocked initial CLK signat state (true = active) + * @return main card handle reference + */ +struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan, uint8_t in_ep, uint8_t irq_ep, bool vcc_active, bool in_reset, bool clocked); /* process a single byte received from the reader */ void card_emu_process_rx_byte(struct card_handle *ch, uint8_t byte); diff --git a/firmware/libcommon/source/card_emu.c b/firmware/libcommon/source/card_emu.c index b7d0e1f..087867f 100644 --- a/firmware/libcommon/source/card_emu.c +++ b/firmware/libcommon/source/card_emu.c @@ -182,9 +182,9 @@ struct card_handle { enum iso7816_3_card_state state; /* signal levels */ - uint8_t vcc_active; /* 1 = on, 0 = off */ - uint8_t in_reset; /* 1 = RST low, 0 = RST high */ - uint8_t clocked; /* 1 = active, 0 = inactive */ + bool vcc_active; /*< if VCC is active (true = active/ON) */ + bool in_reset; /*< if card is in reset (true = RST low/asserted, false = RST high/ released) */ + bool clocked; /*< if clock is active ( true = active, false = inactive) */ /* timing parameters, from PTS */ uint8_t fi; @@ -1126,8 +1126,7 @@ static const uint8_t default_atr[] = { 0x3B, 0x02, 0x14, 0x50 }; static struct card_handle card_handles[NUM_SLOTS]; -struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan, - uint8_t in_ep, uint8_t irq_ep) +struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan, uint8_t in_ep, uint8_t irq_ep, bool vcc_active, bool in_reset, bool clocked) { struct card_handle *ch; @@ -1140,14 +1139,13 @@ struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uar INIT_LLIST_HEAD(&ch->uart_tx_queue); - /* initialize the card_handle with reasonable defaults */ ch->num = slot_num; ch->irq_ep = irq_ep; ch->in_ep = in_ep; ch->state = ISO_S_WAIT_POWER; - ch->vcc_active = 0; - ch->in_reset = 1; - ch->clocked = 0; + ch->vcc_active = vcc_active; + ch->in_reset = in_reset; + ch->clocked = clocked; ch->fi = 0; ch->di = 1; diff --git a/firmware/libcommon/source/mode_cardemu.c b/firmware/libcommon/source/mode_cardemu.c index 98818e1..2d1a687 100644 --- a/firmware/libcommon/source/mode_cardemu.c +++ b/firmware/libcommon/source/mode_cardemu.c @@ -44,7 +44,7 @@ static const Pin pin_usim1_rst = PIN_USIM1_nRST; static const Pin pin_usim1_vcc = PIN_USIM1_VCC; #ifdef CARDEMU_SECOND_UART -static const Pin pins_usim2[] = {PINS_USIM2}; +static const Pin pins_usim2[] = {PINS_USIM2}; static const Pin pin_usim2_rst = PIN_USIM2_nRST; static const Pin pin_usim2_vcc = PIN_USIM2_VCC; #endif @@ -357,14 +357,14 @@ void ADC_IrqHandler(void) static void usim1_rst_irqhandler(const Pin *pPin) { - int active = PIO_Get(&pin_usim1_rst) ? 0 : 1; + bool active = PIO_Get(&pin_usim1_rst) ? false : true; card_emu_io_statechg(cardem_inst[0].ch, CARD_IO_RST, active); } #ifndef DETECT_VCC_BY_ADC static void usim1_vcc_irqhandler(const Pin *pPin) { - int active = PIO_Get(&pin_usim1_vcc) ? 1 : 0; + bool active = PIO_Get(&pin_usim1_vcc) ? true : false; card_emu_io_statechg(cardem_inst[0].ch, CARD_IO_VCC, active); /* FIXME do this for real */ card_emu_io_statechg(cardem_inst[0].ch, CARD_IO_CLK, active); @@ -374,14 +374,14 @@ static void usim1_vcc_irqhandler(const Pin *pPin) #ifdef CARDEMU_SECOND_UART static void usim2_rst_irqhandler(const Pin *pPin) { - int active = PIO_Get(&pin_usim2_rst) ? 0 : 1; + bool active = PIO_Get(&pin_usim2_rst) ? false : true; card_emu_io_statechg(cardem_inst[1].ch, CARD_IO_RST, active); } #ifndef DETECT_VCC_BY_ADC static void usim2_vcc_irqhandler(const Pin *pPin) { - int active = PIO_Get(&pin_usim2_vcc) ? 1 : 0; + bool active = PIO_Get(&pin_usim2_vcc) ? true : false; card_emu_io_statechg(cardem_inst[1].ch, CARD_IO_VCC, active); /* FIXME do this for real */ card_emu_io_statechg(cardem_inst[1].ch, CARD_IO_CLK, active); @@ -420,7 +420,7 @@ void mode_cardemu_init(void) PIO_ConfigureIt(&pin_usim1_vcc, usim1_vcc_irqhandler); PIO_EnableIt(&pin_usim1_vcc); #endif /* DETECT_VCC_BY_ADC */ - cardem_inst[0].ch = card_emu_init(0, 2, 0, SIMTRACE_CARDEM_USB_EP_USIM1_DATAIN, SIMTRACE_CARDEM_USB_EP_USIM1_INT); + cardem_inst[0].ch = card_emu_init(0, 2, 0, SIMTRACE_CARDEM_USB_EP_USIM1_DATAIN, SIMTRACE_CARDEM_USB_EP_USIM1_INT, PIO_Get(&pin_usim1_vcc) ? true : false, PIO_Get(&pin_usim1_rst) ? false : true, PIO_Get(&pin_usim1_vcc) ? true : false); sim_switch_use_physical(0, 1); #ifdef CARDEMU_SECOND_UART @@ -435,10 +435,9 @@ void mode_cardemu_init(void) PIO_ConfigureIt(&pin_usim2_vcc, usim2_vcc_irqhandler); PIO_EnableIt(&pin_usim2_vcc); #endif /* DETECT_VCC_BY_ADC */ - cardem_inst[1].ch = card_emu_init(1, 0, 1, SIMTRACE_CARDEM_USB_EP_USIM2_DATAIN, SIMTRACE_CARDEM_USB_EP_USIM2_INT); + cardem_inst[1].ch = card_emu_init(1, 0, 1, SIMTRACE_CARDEM_USB_EP_USIM2_DATAIN, SIMTRACE_CARDEM_USB_EP_USIM2_INT, PIO_Get(&pin_usim2_vcc) ? true : false, PIO_Get(&pin_usim2_rst) ? false : true, PIO_Get(&pin_usim2_vcc) ? true : false); sim_switch_use_physical(1, 1); #endif /* CARDEMU_SECOND_UART */ - } /* called if config is deactivated */ diff --git a/firmware/test/card_emu_tests.c b/firmware/test/card_emu_tests.c index 09b2e0d..fe1739b 100644 --- a/firmware/test/card_emu_tests.c +++ b/firmware/test/card_emu_tests.c @@ -397,7 +397,7 @@ int main(int argc, char **argv) struct card_handle *ch; unsigned int i; - ch = card_emu_init(0, 23, 42, PHONE_DATAIN, PHONE_INT); + ch = card_emu_init(0, 23, 42, PHONE_DATAIN, PHONE_INT, false, true, false); assert(ch); usb_buf_init(); |