Change in simtrace2[master]: sniff mode: handle USART 1 RX interrupt to show sniffer data

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Jul 4 11:24:15 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/9843 )

Change subject: sniff mode: handle USART 1 RX interrupt to show sniffer data
......................................................................

sniff mode: handle USART 1 RX interrupt to show sniffer data

Change-Id: I5504369aed39844b7cf21e5b3ccb542daa6b946e
---
M firmware/apps/trace/main.c
M firmware/libcommon/include/simtrace.h
M firmware/libcommon/source/sniffer.c
3 files changed, 36 insertions(+), 2 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/firmware/apps/trace/main.c b/firmware/apps/trace/main.c
index aabaa41..06c4176 100644
--- a/firmware/apps/trace/main.c
+++ b/firmware/apps/trace/main.c
@@ -36,6 +36,7 @@
 		.init = Sniffer_init,
 		.exit = Sniffer_exit,
 		.run = Sniffer_run,
+		.usart1_irq = Sniffer_usart1_irq,
 	},
 #endif
 #ifdef HAVE_CCID
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 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 @@
 	/* 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 @@
 	.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_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));

-- 
To view, visit https://gerrit.osmocom.org/9843
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I5504369aed39844b7cf21e5b3ccb542daa6b946e
Gerrit-Change-Number: 9843
Gerrit-PatchSet: 3
Gerrit-Owner: Kévin Redon <kredon at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180704/4e898d0d/attachment.htm>


More information about the gerrit-log mailing list