diff options
author | Harald Welte <laforge@osmocom.org> | 2019-12-16 14:23:02 +0100 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2019-12-16 14:49:56 +0100 |
commit | 6a3a714e2f327f6062f7bed07762a2133442865f (patch) | |
tree | 75fb8cb9b50515497a6815506e03e3144048d6cb | |
parent | e9f429d34c733d6b5fe2d6479fc9edbc02d9e9e3 (diff) |
card_emu: Always print state names in string representation
Change-Id: I81469e40f3720afdcb47048b45c63d6474887640
-rw-r--r-- | firmware/libcommon/source/card_emu.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/firmware/libcommon/source/card_emu.c b/firmware/libcommon/source/card_emu.c index 34fac1b..4c29d41 100644 --- a/firmware/libcommon/source/card_emu.c +++ b/firmware/libcommon/source/card_emu.c @@ -110,6 +110,22 @@ enum pts_state { PTS_S_WAIT_RESP_PCK = PTS_S_WAIT_REQ_PCK | 0x10, }; +const struct value_string pts_state_names[] = { + { PTS_S_WAIT_REQ_PTSS, "WAIT_REQ_PTSS" }, + { PTS_S_WAIT_REQ_PTS0, "WAIT_REQ_PTS0" }, + { PTS_S_WAIT_REQ_PTS1, "WAIT_REQ_PTS1" }, + { PTS_S_WAIT_REQ_PTS2, "WAIT_REQ_PTS2" }, + { PTS_S_WAIT_REQ_PTS3, "WAIT_REQ_PTS3" }, + { PTS_S_WAIT_REQ_PCK, "WAIT_REQ_PCK" }, + { PTS_S_WAIT_RESP_PTSS, "WAIT_RESP_PTSS" }, + { PTS_S_WAIT_RESP_PTS0, "WAIT_RESP_PTS0" }, + { PTS_S_WAIT_RESP_PTS1, "WAIT_RESP_PTS1" }, + { PTS_S_WAIT_RESP_PTS2, "WAIT_RESP_PTS2" }, + { PTS_S_WAIT_RESP_PTS3, "WAIT_RESP_PTS3" }, + { PTS_S_WAIT_RESP_PCK, "WAIT_RESP_PCK" }, + { 0, NULL } +}; + /* PTS field byte index */ #define _PTSS 0 #define _PTS0 1 @@ -542,8 +558,9 @@ static int tx_byte_atr(struct card_handle *ch) /* Update the PTS sub-state */ static void set_pts_state(struct card_handle *ch, enum pts_state new_ptss) { - TRACE_DEBUG("%u: 7816 PTS state %u -> %u\r\n", - ch->num, ch->pts.state, new_ptss); + TRACE_DEBUG("%u: 7816 PTS state %s -> %s\r\n", ch->num, + get_value_string(pts_state_names, ch->pts.state), + get_value_string(pts_state_names, new_ptss)); ch->pts.state = new_ptss; } @@ -623,8 +640,8 @@ process_byte_pts(struct card_handle *ch, uint8_t byte) memcpy(ch->pts.resp, ch->pts.req, sizeof(ch->pts.resp)); break; default: - TRACE_ERROR("%u: process_byte_pts() in invalid state %u\r\n", - ch->num, ch->pts.state); + TRACE_ERROR("%u: process_byte_pts() in invalid PTS state %s\r\n", ch->num, + get_value_string(pts_state_names, ch->pts.state)); break; } /* calculate the next state and set it */ @@ -674,8 +691,8 @@ static int tx_byte_pts(struct card_handle *ch) byte = ch->pts.resp[_PCK]; break; default: - TRACE_ERROR("%u: get_byte_pts() in invalid state %u\r\n", - ch->num, ch->pts.state); + TRACE_ERROR("%u: get_byte_pts() in invalid PTS state %s\r\n", ch->num, + get_value_string(pts_state_names, ch->pts.state)); return 0; } @@ -880,8 +897,8 @@ process_byte_tpdu(struct card_handle *ch, uint8_t byte) add_tpdu_byte(ch, byte); break; default: - TRACE_ERROR("%u: process_byte_tpdu() in invalid state %u\r\n", - ch->num, ch->tpdu.state); + TRACE_ERROR("%u: process_byte_tpdu() in invalid TPDU state %s\r\n", ch->num, + get_value_string(tpdu_state_names, ch->tpdu.state)); } /* ensure we stay in TPDU ISO state */ @@ -982,8 +999,8 @@ void card_emu_process_rx_byte(struct card_handle *ch, uint8_t byte) new_state = process_byte_pts(ch, byte); goto out_silent; default: - TRACE_ERROR("%u: Received UART char in invalid 7816 state " - "%u\r\n", ch->num, ch->state); + TRACE_ERROR("%u: Received UART char in invalid 7816 state %s\r\n", ch->num, + get_value_string(iso7816_3_card_state_names, ch->state)); break; } |