aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/libcommon
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2018-06-06 16:13:48 +0200
committerHarald Welte <laforge@gnumonks.org>2018-07-04 11:24:13 +0000
commit7b734624428d65a7e15581c9f8af5837371c2cc6 (patch)
tree74a2cf1456a7d1b82c9ab4176c1caadc42813f81 /firmware/libcommon
parent36abece0b129f64934e6522f6d94cdf38213c5e7 (diff)
sniff mode: handle USART 1 RX interrupt to show sniffer data
Diffstat (limited to 'firmware/libcommon')
-rw-r--r--firmware/libcommon/include/simtrace.h2
-rw-r--r--firmware/libcommon/source/sniffer.c35
2 files changed, 35 insertions, 2 deletions
diff --git a/firmware/libcommon/include/simtrace.h b/firmware/libcommon/include/simtrace.h
index 348cc57..21921ca 100644
--- a/firmware/libcommon/include/simtrace.h
+++ b/firmware/libcommon/include/simtrace.h
@@ -108,6 +108,8 @@ extern void CCID_run( void );
extern void mode_cardemu_run(void);
extern void MITM_run( void );
+/* IRQ functions */
+extern void Sniffer_usart1_irq(void);
extern void mode_cardemu_usart0_irq(void);
extern void mode_cardemu_usart1_irq(void);
diff --git a/firmware/libcommon/source/sniffer.c b/firmware/libcommon/source/sniffer.c
index 06edb22..fa272eb 100644
--- a/firmware/libcommon/source/sniffer.c
+++ b/firmware/libcommon/source/sniffer.c
@@ -58,7 +58,7 @@ static const Pin pPwr[] = {
/* Enable power converter 4.5-6V to 3.3V; low: off */
{SIM_PWEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT},
- /* Enable second power converter: VCC_PHONE to VCC_SIM; high: on */
+ /* Enable power forwarding: VCC_PHONE to VCC_SIM; high: on */
{VCC_FWD, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
};
@@ -68,10 +68,37 @@ static struct Usart_info usart_info = {
.state = USART_RCV,
};
+/* Ring buffer to store sniffer communication data */
+static struct ringbuf sniff_buffer;
+
+/*------------------------------------------------------------------------------
+ * Global functions
+ *------------------------------------------------------------------------------*/
+
+void Sniffer_usart1_irq(void)
+{
+ /* Read channel status register */
+ uint32_t csr = usart_info.base->US_CSR & usart_info.base->US_IMR;
+ /* Verify if character has been received */
+ if (csr & US_CSR_RXRDY) {
+ /* Read communication data byte between phone and SIM */
+ uint8_t byte = usart_info.base->US_RHR;
+ /* Store sniffed data into buffer (also clear interrupt */
+ rbuf_write(&sniff_buffer, byte);
+ }
+}
+
+/*------------------------------------------------------------------------------
+ * Internal functions
+ *------------------------------------------------------------------------------*/
int check_data_from_phone(void)
{
- TRACE_INFO("check data from phone\n\r");
+ /* Display sniffed data */
+ while (!rbuf_is_empty(&sniff_buffer)) {
+ uint8_t byte = rbuf_read(&sniff_buffer);
+ TRACE_INFO_WP("0x%02x ", byte);
+ }
}
/*-----------------------------------------------------------------------------
@@ -97,6 +124,10 @@ void Sniffer_exit(void)
void Sniffer_init(void)
{
TRACE_INFO("Sniffer Init\n\r");
+
+ /* Clear ring buffer containing the sniffed data */
+ rbuf_reset(&sniff_buffer);
+
/* Configure ISO7816 driver */
PIO_Configure(pinsISO7816_sniff, PIO_LISTSIZE(pinsISO7816_sniff));
PIO_Configure(pins_bus, PIO_LISTSIZE(pins_bus));