From 644c2131ca7b8711b9f92772ab836030c4da0050 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 1 Jun 2021 19:56:27 +0200 Subject: [PATCH] simtrace2-cardem-pcsc: Decode STATUS flags to strings SIMtrace IRQ STATUS: flags=0x13, fi=9, di=6, wi=10 wtime=9600 (RESET VCC CLK ) is more understandable than SIMtrace IRQ STATUS: flags=0x13, fi=9, di=6, wi=10 wtime=9600 Change-Id: I5bbfa1d99ebee4b297d894a5f444dbe743c7ab70 --- host/src/simtrace2-cardem-pcsc.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/host/src/simtrace2-cardem-pcsc.c b/host/src/simtrace2-cardem-pcsc.c index 66e3e7a9..532c5ba1 100644 --- a/host/src/simtrace2-cardem-pcsc.c +++ b/host/src/simtrace2-cardem-pcsc.c @@ -64,6 +64,16 @@ static void atr_update_csum(uint8_t *atr, unsigned int atr_len) atr[atr_len-1] = csum; } +static void cemu_flags2str(char *out, unsigned int out_len, uint32_t flags) +{ + snprintf(out, out_len, "%s%s%s%s%s", + flags & CEMU_STATUS_F_RESET_ACTIVE ? "RESET " : "", + flags & CEMU_STATUS_F_VCC_PRESENT ? "VCC " : "", + flags & CEMU_STATUS_F_CLK_ACTIVE ? "CLK " : "", + flags & CEMU_STATUS_F_CARD_INSERT ? "CARD_PRES " : "", + flags & CEMU_STATUS_F_RCEMU_ACTIVE ? "RCEMU " : ""); +} + /*********************************************************************** * Incoming Messages ***********************************************************************/ @@ -71,12 +81,13 @@ static void atr_update_csum(uint8_t *atr, unsigned int atr_len) /*! \brief Process a STATUS message from the SIMtrace2 */ static int process_do_status(struct osmo_st2_cardem_inst *ci, uint8_t *buf, int len) { - struct cardemu_usb_msg_status *status; - status = (struct cardemu_usb_msg_status *) buf; + struct cardemu_usb_msg_status *status = (struct cardemu_usb_msg_status *) buf; + char fbuf[80]; - printf("=> STATUS: flags=0x%x, fi=%u, di=%u, wi=%u wtime=%u\n", + cemu_flags2str(fbuf, sizeof(fbuf), status->flags); + printf("=> STATUS: flags=0x%x, fi=%u, di=%u, wi=%u wtime=%u (%s)\n", status->flags, status->fi, status->di, status->wi, - status->waiting_time); + status->waiting_time, fbuf); return 0; } @@ -177,10 +188,12 @@ static int process_usb_msg(struct osmo_st2_cardem_inst *ci, uint8_t *buf, int le static int process_irq_status(struct osmo_st2_cardem_inst *ci, const uint8_t *buf, int len) { const struct cardemu_usb_msg_status *status = (struct cardemu_usb_msg_status *) buf; + char fbuf[80]; - LOGCI(ci, LOGL_INFO, "SIMtrace IRQ STATUS: flags=0x%x, fi=%u, di=%u, wi=%u wtime=%u\n", + cemu_flags2str(fbuf, sizeof(fbuf), status->flags); + LOGCI(ci, LOGL_INFO, "SIMtrace IRQ STATUS: flags=0x%x, fi=%u, di=%u, wi=%u wtime=%u (%s)\n", status->flags, status->fi, status->di, status->wi, - status->waiting_time); + status->waiting_time, fbuf); return 0; }