cardem: add more debug information for TPDU state

this just adds the name of the TPDU state on top of the state number.

the ISO state is cleaned up accordingly

Change-Id: Id5104a2c3579dedb092c179748e9ed525673841c
This commit is contained in:
Kévin Redon
2018-10-15 19:43:15 +02:00
parent 7e5cda5732
commit 2fdcf3b38d

View File

@@ -55,14 +55,38 @@ enum iso7816_3_card_state {
}; };
const struct value_string iso7816_3_card_state_names[] = { const struct value_string iso7816_3_card_state_names[] = {
OSMO_VALUE_STRING(ISO_S_WAIT_POWER), {
OSMO_VALUE_STRING(ISO_S_WAIT_CLK), .value = ISO_S_WAIT_POWER,
OSMO_VALUE_STRING(ISO_S_WAIT_RST), .str = "WAIT_POWER",
OSMO_VALUE_STRING(ISO_S_WAIT_ATR), },
OSMO_VALUE_STRING(ISO_S_IN_ATR), {
OSMO_VALUE_STRING(ISO_S_IN_PTS), .value = ISO_S_WAIT_CLK,
OSMO_VALUE_STRING(ISO_S_WAIT_TPDU), .str = "WAIT_CLK",
OSMO_VALUE_STRING(ISO_S_IN_TPDU), },
{
.value = ISO_S_WAIT_RST,
.str = "WAIT_RST",
},
{
.value = ISO_S_WAIT_ATR,
.str = "WAIT_ATR",
},
{
.value = ISO_S_IN_ATR,
.str = "IN_ATR",
},
{
.value = ISO_S_IN_PTS,
.str = "IN_PTS",
},
{
.value = ISO_S_WAIT_TPDU,
.str = "WAIT_TPDU",
},
{
.value = ISO_S_IN_TPDU,
.str = "IN_TPDU",
},
{ {
.value = 0, .value = 0,
.str = NULL, .str = NULL,
@@ -86,6 +110,7 @@ enum pts_state {
PTS_S_WAIT_RESP_PCK = PTS_S_WAIT_REQ_PCK | 0x10, PTS_S_WAIT_RESP_PCK = PTS_S_WAIT_REQ_PCK | 0x10,
}; };
/* PTS field byte index */
#define _PTSS 0 #define _PTSS 0
#define _PTS0 1 #define _PTS0 1
#define _PTS1 2 #define _PTS1 2
@@ -105,6 +130,46 @@ enum tpdu_state {
TPDU_S_WAIT_TX, /* waiting for more data to reader */ TPDU_S_WAIT_TX, /* waiting for more data to reader */
}; };
const struct value_string tpdu_state_names[] = {
{
.value = TPDU_S_WAIT_CLA,
.str = "WAIT_CLA",
},
{
.value = TPDU_S_WAIT_INS,
.str = "WAIT_INS",
},
{
.value = TPDU_S_WAIT_P1,
.str = "WAIT_P1",
},
{
.value = TPDU_S_WAIT_P2,
.str = "WAIT_P2",
},
{
.value = TPDU_S_WAIT_P3,
.str = "WAIT_P3",
},
{
.value = TPDU_S_WAIT_PB,
.str = "WAIT_PB",
},
{
.value = TPDU_S_WAIT_RX,
.str = "WAIT_RX",
},
{
.value = TPDU_S_WAIT_TX,
.str = "WAIT_TX",
},
{
.value = 0,
.str = NULL,
},
};
/* TPDU field byte index */
#define _CLA 0 #define _CLA 0
#define _INS 1 #define _INS 1
#define _P1 2 #define _P1 2
@@ -304,9 +369,9 @@ static void card_set_state(struct card_handle *ch,
if (ch->state == new_state) if (ch->state == new_state)
return; return;
TRACE_DEBUG("%u: 7816 card state %u (%s) -> %u (%s)\r\n", ch->num, TRACE_DEBUG("%u: 7816 card state %s -> %s\r\n", ch->num,
ch->state, get_value_string(iso7816_3_card_state_names, ch->state), get_value_string(iso7816_3_card_state_names, ch->state),
new_state, get_value_string(iso7816_3_card_state_names, new_state)); get_value_string(iso7816_3_card_state_names, new_state));
ch->state = new_state; ch->state = new_state;
switch (new_state) { switch (new_state) {
@@ -651,9 +716,9 @@ static void set_tpdu_state(struct card_handle *ch, enum tpdu_state new_ts)
if (ch->tpdu.state == new_ts) if (ch->tpdu.state == new_ts)
return; return;
TRACE_DEBUG("%u: 7816 TPDU state %u -> %u\r\n", ch->num, TRACE_DEBUG("%u: 7816 TPDU state %s -> %s\r\n", ch->num,
ch->tpdu.state, new_ts); get_value_string(tpdu_state_names, ch->tpdu.state),
get_value_string(tpdu_state_names, new_ts));
ch->tpdu.state = new_ts; ch->tpdu.state = new_ts;
switch (new_ts) { switch (new_ts) {