lynxis lazus has submitted this change. ( 
https://gerrit.osmocom.org/c/simtrace2/+/43003?usp=email )

Change subject: firmware: Drop CEMU_TX_DATA when emulated sim is in-active
......................................................................

firmware: Drop CEMU_TX_DATA when emulated sim is in-active

When the emulated sim is in reset or without power, drop
CEMU_TX_DATA.

Change-Id: I796e548225a742cddfde12bd6a60e4d2e5c04c8f
---
M firmware/libcommon/include/card_emu.h
M firmware/libcommon/source/card_emu.c
M firmware/libcommon/source/mode_cardemu.c
3 files changed, 20 insertions(+), 0 deletions(-)

Approvals:
  pespin: Looks good to me, approved
  Jenkins Builder: Verified
  laforge: Looks good to me, but someone else must approve




diff --git a/firmware/libcommon/include/card_emu.h 
b/firmware/libcommon/include/card_emu.h
index c2d3b68..a5e4d97 100644
--- a/firmware/libcommon/include/card_emu.h
+++ b/firmware/libcommon/include/card_emu.h
@@ -72,6 +72,7 @@
 void card_emu_uart_interrupt(uint8_t uart_chan);

 int card_emu_get_vcc(uint8_t uart_chan);
+bool card_emu_ch_ready(const struct card_handle *ch);

 struct cardemu_usb_msg_config;
 int card_emu_set_config(struct card_handle *ch, const struct 
cardemu_usb_msg_config *scfg,
diff --git a/firmware/libcommon/source/card_emu.c 
b/firmware/libcommon/source/card_emu.c
index 72da9d8..cda8cf9 100644
--- a/firmware/libcommon/source/card_emu.c
+++ b/firmware/libcommon/source/card_emu.c
@@ -215,6 +215,19 @@
        } stats;
 };

+/* if the card emu is ready to handle TPDUs */
+bool card_emu_ch_ready(const struct card_handle *ch)
+{
+       switch (ch->state) {
+       case ISO_S_IN_PTS:
+       case ISO_S_WAIT_TPDU:
+       case ISO_S_IN_TPDU:
+               return true;
+       default:
+               return false;
+       }
+}
+
 /* reset all the 'dynamic' state of the card handle to the initial/default 
values */
 static void card_handle_reset(struct card_handle *ch)
 {
diff --git a/firmware/libcommon/source/mode_cardemu.c 
b/firmware/libcommon/source/mode_cardemu.c
index 6c1ac8d..215cd45 100644
--- a/firmware/libcommon/source/mode_cardemu.c
+++ b/firmware/libcommon/source/mode_cardemu.c
@@ -736,6 +736,12 @@
        hdr = (struct simtrace_msg_hdr *) msg->l1h;
        switch (hdr->msg_type) {
        case SIMTRACE_MSGT_DT_CEMU_TX_DATA:
+               /* drop message when the card emu channel is in-active */
+               if (!card_emu_ch_ready(ci->ch)) {
+                       /* FIXME: enqueue an error message for IN */
+                       usb_buf_free(msg);
+                       return;
+               }
                queue = card_emu_get_uart_tx_queue(ci->ch);
                /* drained from the USART IRQ handler at highest NVIC prio */
                llist_add_tail_irqsafe(&msg->list, queue);

--
To view, visit https://gerrit.osmocom.org/c/simtrace2/+/43003?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-Change-Id: I796e548225a742cddfde12bd6a60e4d2e5c04c8f
Gerrit-Change-Number: 43003
Gerrit-PatchSet: 7
Gerrit-Owner: lynxis lazus <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: lynxis lazus <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>

Reply via email to