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/.

Kévin Redon gerrit-no-reply at lists.osmocom.org
Tue Jul 3 16:45:23 UTC 2018


Kévin Redon has uploaded this change for review. ( 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(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/43/9843/1

diff --git a/firmware/apps/trace/main.c b/firmware/apps/trace/main.c
index 54b4242..6096362 100644
--- a/firmware/apps/trace/main.c
+++ b/firmware/apps/trace/main.c
@@ -54,6 +54,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: newchange
Gerrit-Change-Id: I5504369aed39844b7cf21e5b3ccb542daa6b946e
Gerrit-Change-Number: 9843
Gerrit-PatchSet: 1
Gerrit-Owner: Kévin Redon <kredon at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180703/bd0db3c4/attachment.htm>


More information about the gerrit-log mailing list