Change in simtrace2[master]: USB: add flags for sniff data and centralise transfer

2018-07-11 Thread Harald Welte
Harald Welte has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/9920 )

Change subject: USB: add flags for sniff data and centralise transfer
..

USB: add flags for sniff data and centralise transfer

Also fix issue in usb_msg_alloc_hdr and add cosmetic spaces around
operations.

Change-Id: I768a0ad639aa5e648a630af72d01f7b68082b6b6
---
M firmware/libcommon/include/simtrace_prot.h
M firmware/libcommon/source/sniffer.c
M host/simtrace2-sniff.c
3 files changed, 140 insertions(+), 142 deletions(-)

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



diff --git a/firmware/libcommon/include/simtrace_prot.h 
b/firmware/libcommon/include/simtrace_prot.h
index 1e9d72f..f1f736b 100644
--- a/firmware/libcommon/include/simtrace_prot.h
+++ b/firmware/libcommon/include/simtrace_prot.h
@@ -294,6 +294,9 @@
 #define SNIFF_CHANGE_FLAG_RESET_HOLD (1<<2)
 #define SNIFF_CHANGE_FLAG_RESET_RELEASE (1<<3)
 #define SNIFF_CHANGE_FLAG_TIMEOUT_WT (1<<4)
+/* SIMTRACE_MSGT_SNIFF_ATR, SIMTRACE_MSGT_SNIFF_PPS, SIMTRACE_MSGT_SNIFF_TPDU 
flags */
+#define SNIFF_DATA_FLAG_ERROR_INCOMPLETE (1<<5)
+#define SNIFF_DATA_FLAG_ERROR_MALFORMED (1<<6)

 /* SIMTRACE_MSGT_SNIFF_CHANGE */
 struct sniff_change {
@@ -309,8 +312,8 @@

 /* SIMTRACE_MSGT_SNIFF_ATR, SIMTRACE_MSGT_SNIFF_PPS, SIMTRACE_MSGT_SNIFF_TPDU 
*/
 struct sniff_data {
-   /* if the data is complete (an error might have occurred during 
transmission */
-   bool complete;
+   /* data flags */
+   uint32_t flags;
/* data length */
uint16_t length;
/* data */
diff --git a/firmware/libcommon/source/sniffer.c 
b/firmware/libcommon/source/sniffer.c
index 81a6712..4ec56d9 100644
--- a/firmware/libcommon/source/sniffer.c
+++ b/firmware/libcommon/source/sniffer.c
@@ -234,8 +234,8 @@
usb_msg->l1h = msgb_put(usb_msg, sizeof(*usb_msg_header));
usb_msg_header = (struct simtrace_msg_hdr *) usb_msg->l1h;
memset(usb_msg_header, 0, sizeof(*usb_msg_header));
-   usb_msg_header->msg_class = SIMTRACE_MSGC_SNIFF;
-   usb_msg_header->msg_type = SIMTRACE_MSGT_SNIFF_CHANGE;
+   usb_msg_header->msg_class = msg_class;
+   usb_msg_header->msg_type = msg_type;
usb_msg->l2h = usb_msg->l1h + sizeof(*usb_msg_header);

return usb_msg;
@@ -296,11 +296,74 @@
//TRACE_INFO("Changed to ISO 7816-3 state %u\n\r", iso_state); /* don't 
print since this is function is also called by ISRs */
 }

+static void usb_send_data(enum simtrace_msg_type_sniff type, const uint8_t* 
data, uint16_t length, uint32_t flags)
+{
+   /* Sanity check */
+   if (type != SIMTRACE_MSGT_SNIFF_ATR && type != SIMTRACE_MSGT_SNIFF_PPS 
&& type != SIMTRACE_MSGT_SNIFF_TPDU) {
+   return;
+   }
+
+   /* 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:
+   printf("ATR");
+   break;
+   case SIMTRACE_MSGT_SNIFF_PPS:
+   printf("PPS");
+   break;
+   case SIMTRACE_MSGT_SNIFF_TPDU:
+   printf("TPDU");
+   break;
+   default:
+   printf("???");
+   break;
+   }
+   if (flags) {
+   printf(" (");
+   if (flags & SNIFF_DATA_FLAG_ERROR_INCOMPLETE) {
+   printf("incomplete");
+   flags &= ~SNIFF_DATA_FLAG_ERROR_INCOMPLETE;
+   if (flags) {
+   printf(", ");
+   }
+   }
+   if (flags & SNIFF_DATA_FLAG_ERROR_MALFORMED) {
+   printf("malformed");
+   flags &= ~SNIFF_DATA_FLAG_ERROR_MALFORMED;
+   if (flags) {
+   printf(", ");
+   }
+   }
+   printf(")");
+   }
+   printf(": ");
+   uint16_t i;
+   for (i = 0; i < length; i++) {
+   printf("%02x ", data[i]);
+   }
+   printf("\n\r");
+}
+
 /*! Send current ATR over USB
- *  @param[in] complete if the ATR is complete
+ *  @param[in] flags SNIFF_DATA_FLAG_ data flags
  *  @note Also print the ATR to debug console
  */
-static void usb_send_atr(bool complete)
+static void 

Change in simtrace2[master]: USB: add flags for sniff data and centralise transfer

2018-07-11 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/9920 )

Change subject: USB: add flags for sniff data and centralise transfer
..


Patch Set 5: Code-Review+2


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

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I768a0ad639aa5e648a630af72d01f7b68082b6b6
Gerrit-Change-Number: 9920
Gerrit-PatchSet: 5
Gerrit-Owner: Kévin Redon 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Comment-Date: Wed, 11 Jul 2018 19:53:44 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in simtrace2[master]: USB: add flags for sniff data and centralise transfer

2018-07-11 Thread Kévin Redon
Hello Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/9920

to look at the new patch set (#5).

Change subject: USB: add flags for sniff data and centralise transfer
..

USB: add flags for sniff data and centralise transfer

Also fix issue in usb_msg_alloc_hdr and add cosmetic spaces around
operations.

Change-Id: I768a0ad639aa5e648a630af72d01f7b68082b6b6
---
M firmware/libcommon/include/simtrace_prot.h
M firmware/libcommon/source/sniffer.c
M host/simtrace2-sniff.c
3 files changed, 140 insertions(+), 142 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/20/9920/5
--
To view, visit https://gerrit.osmocom.org/9920
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I768a0ad639aa5e648a630af72d01f7b68082b6b6
Gerrit-Change-Number: 9920
Gerrit-PatchSet: 5
Gerrit-Owner: Kévin Redon 
Gerrit-Reviewer: Jenkins Builder


Change in simtrace2[master]: USB: add flags for sniff data and centralise transfer

2018-07-10 Thread Kévin Redon
Hello Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/9920

to look at the new patch set (#2).

Change subject: USB: add flags for sniff data and centralise transfer
..

USB: add flags for sniff data and centralise transfer

Also fix issue in usb_msg_alloc_hdr and add cosmetic spaces around
operations.

Change-Id: I768a0ad639aa5e648a630af72d01f7b68082b6b6
---
M firmware/libcommon/include/simtrace_prot.h
M firmware/libcommon/source/sniffer.c
M host/simtrace2-sniff.c
3 files changed, 140 insertions(+), 142 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/20/9920/2
--
To view, visit https://gerrit.osmocom.org/9920
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I768a0ad639aa5e648a630af72d01f7b68082b6b6
Gerrit-Change-Number: 9920
Gerrit-PatchSet: 2
Gerrit-Owner: Kévin Redon 
Gerrit-Reviewer: Jenkins Builder


Change in simtrace2[master]: USB: add flags for sniff data and centralise transfer

2018-07-08 Thread Kévin Redon
Kévin Redon has uploaded this change for review. ( 
https://gerrit.osmocom.org/9920


Change subject: USB: add flags for sniff data and centralise transfer
..

USB: add flags for sniff data and centralise transfer

Also fix issue in usb_msg_alloc_hdr and add cosmetic spaces around
operations.

Change-Id: I768a0ad639aa5e648a630af72d01f7b68082b6b6
---
M firmware/libcommon/include/simtrace_prot.h
M firmware/libcommon/source/sniffer.c
M host/simtrace2-sniff.c
3 files changed, 139 insertions(+), 141 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/20/9920/1

diff --git a/firmware/libcommon/include/simtrace_prot.h 
b/firmware/libcommon/include/simtrace_prot.h
index 1e9d72f..f1f736b 100644
--- a/firmware/libcommon/include/simtrace_prot.h
+++ b/firmware/libcommon/include/simtrace_prot.h
@@ -294,6 +294,9 @@
 #define SNIFF_CHANGE_FLAG_RESET_HOLD (1<<2)
 #define SNIFF_CHANGE_FLAG_RESET_RELEASE (1<<3)
 #define SNIFF_CHANGE_FLAG_TIMEOUT_WT (1<<4)
+/* SIMTRACE_MSGT_SNIFF_ATR, SIMTRACE_MSGT_SNIFF_PPS, SIMTRACE_MSGT_SNIFF_TPDU 
flags */
+#define SNIFF_DATA_FLAG_ERROR_INCOMPLETE (1<<5)
+#define SNIFF_DATA_FLAG_ERROR_MALFORMED (1<<6)

 /* SIMTRACE_MSGT_SNIFF_CHANGE */
 struct sniff_change {
@@ -309,8 +312,8 @@

 /* SIMTRACE_MSGT_SNIFF_ATR, SIMTRACE_MSGT_SNIFF_PPS, SIMTRACE_MSGT_SNIFF_TPDU 
*/
 struct sniff_data {
-   /* if the data is complete (an error might have occurred during 
transmission */
-   bool complete;
+   /* data flags */
+   uint32_t flags;
/* data length */
uint16_t length;
/* data */
diff --git a/firmware/libcommon/source/sniffer.c 
b/firmware/libcommon/source/sniffer.c
index 81a6712..b78339b 100644
--- a/firmware/libcommon/source/sniffer.c
+++ b/firmware/libcommon/source/sniffer.c
@@ -235,7 +235,7 @@
usb_msg_header = (struct simtrace_msg_hdr *) usb_msg->l1h;
memset(usb_msg_header, 0, sizeof(*usb_msg_header));
usb_msg_header->msg_class = SIMTRACE_MSGC_SNIFF;
-   usb_msg_header->msg_type = SIMTRACE_MSGT_SNIFF_CHANGE;
+   usb_msg_header->msg_type = msg_class;
usb_msg->l2h = usb_msg->l1h + sizeof(*usb_msg_header);

return usb_msg;
@@ -296,11 +296,74 @@
//TRACE_INFO("Changed to ISO 7816-3 state %u\n\r", iso_state); /* don't 
print since this is function is also called by ISRs */
 }

+static void usb_send_data(enum simtrace_msg_type_sniff type, const uint8_t* 
data, uint16_t length, uint32_t flags)
+{
+   /* Sanity check */
+   if (type != SIMTRACE_MSGT_SNIFF_ATR && type != SIMTRACE_MSGT_SNIFF_PPS 
&& type != SIMTRACE_MSGT_SNIFF_TPDU) {
+   return;
+   }
+
+   /* 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:
+   printf("ATR");
+   break;
+   case SIMTRACE_MSGT_SNIFF_PPS:
+   printf("PPS");
+   break;
+   case SIMTRACE_MSGT_SNIFF_TPDU:
+   printf("TPDU");
+   break;
+   default:
+   printf("???");
+   break;
+   }
+   if (flags) {
+   printf(" (");
+   if (flags & SNIFF_DATA_FLAG_ERROR_INCOMPLETE) {
+   printf("incomplete");
+   flags &= ~SNIFF_DATA_FLAG_ERROR_INCOMPLETE;
+   if (flags) {
+   printf(", ");
+   }
+   }
+   if (flags & SNIFF_DATA_FLAG_ERROR_MALFORMED) {
+   printf("malformed");
+   flags &= ~SNIFF_DATA_FLAG_ERROR_MALFORMED;
+   if (flags) {
+   printf(", ");
+   }
+   }
+   printf(")");
+   }
+   printf(": ");
+   uint16_t i;
+   for (i = 0; i < length; i++) {
+   printf("%02x ", data[i]);
+   }
+   printf("\n\r");
+}
+
 /*! Send current ATR over USB
- *  @param[in] complete if the ATR is complete
+ *  @param[in] flags SNIFF_DATA_FLAG_ data flags
  *  @note Also print the ATR to debug console
  */
-static void usb_send_atr(bool complete)
+static void usb_send_atr(uint32_t flags)
 {
/* Check state */
if (ISO7816_S_IN_ATR != iso_state) {
@@ -312,28 +375,8 @@
return;