From 411428eb5e6f1187b0323cee8539188f0c5c2b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Redon?= Date: Sun, 8 Jul 2018 15:47:38 +0200 Subject: [PATCH] sniffer: move data print before USB send when the host software does not retrieve the USB messages the memory is filled and no new USB messages can be allocated, preventing the following code to print the message Change-Id: Ie8946894a84cb853b45555f7abb1ca6f32111425 --- firmware/libcommon/source/sniffer.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/firmware/libcommon/source/sniffer.c b/firmware/libcommon/source/sniffer.c index 4ec56d9f..07bc82d8 100644 --- a/firmware/libcommon/source/sniffer.c +++ b/firmware/libcommon/source/sniffer.c @@ -306,18 +306,6 @@ static void usb_send_data(enum simtrace_msg_type_sniff type, const uint8_t* data /* Show activity on LED */ led_blink(LED_GREEN, BLINK_2O_F); - /* Send data over USB */ - struct msgb *usb_msg = usb_msg_alloc_hdr(SIMTRACE_USB_EP_CARD_DATAIN, SIMTRACE_MSGC_SNIFF, type); - if (!usb_msg) { - return; - } - struct sniff_data *usb_sniff_data = (struct sniff_data *) msgb_put(usb_msg, sizeof(*usb_sniff_data)); - usb_sniff_data->flags = flags; - usb_sniff_data->length = length; - uint8_t *sniff_data = msgb_put(usb_msg, usb_sniff_data->length); - memcpy(sniff_data, data, length); - usb_msg_upd_len_and_submit(usb_msg); - /* Print message */ switch (type) { case SIMTRACE_MSGT_SNIFF_ATR: @@ -357,6 +345,19 @@ static void usb_send_data(enum simtrace_msg_type_sniff type, const uint8_t* data printf("%02x ", data[i]); } printf("\n\r"); + + /* Send data over USB */ + struct msgb *usb_msg = usb_msg_alloc_hdr(SIMTRACE_USB_EP_CARD_DATAIN, SIMTRACE_MSGC_SNIFF, type); + if (!usb_msg) { + return; + } + struct sniff_data *usb_sniff_data = (struct sniff_data *) msgb_put(usb_msg, sizeof(*usb_sniff_data)); + usb_sniff_data->flags = flags; + usb_sniff_data->length = length; + uint8_t *sniff_data = msgb_put(usb_msg, usb_sniff_data->length); + memcpy(sniff_data, data, length); + usb_msg_upd_len_and_submit(usb_msg); + } /*! Send current ATR over USB