From 76507508d7b3c31935a641e87bf93709812049e1 Mon Sep 17 00:00:00 2001 From: Vincent JARDIN Date: Thu, 4 Mar 2021 21:01:37 +0000 Subject: [PATCH] IASECC/CPX: code factorization There are two flavours of CPX cards: - contact mode, - contactless mode --- src/libopensc/card-iasecc.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/libopensc/card-iasecc.c b/src/libopensc/card-iasecc.c index 7d367762..492b6396 100644 --- a/src/libopensc/card-iasecc.c +++ b/src/libopensc/card-iasecc.c @@ -610,6 +610,19 @@ iasecc_init_amos_or_sagem(struct sc_card *card) LOG_FUNC_RETURN(ctx, SC_SUCCESS); } +inline static int +iasecc_is_cpx(const struct sc_card *card) +{ + switch(card->type) { + case SC_CARD_TYPE_IASECC_CPX: + case SC_CARD_TYPE_IASECC_CPXCL: + return 1; + default: + return 0; + } + + return 0; +} static int iasecc_init_cpx(struct sc_card *card) @@ -663,9 +676,7 @@ iasecc_init(struct sc_card *card) rv = iasecc_init_amos_or_sagem(card); else if (card->type == SC_CARD_TYPE_IASECC_MI) rv = iasecc_init_amos_or_sagem(card); - else if (card->type == SC_CARD_TYPE_IASECC_CPX) - rv = iasecc_init_cpx(card); - else if (card->type == SC_CARD_TYPE_IASECC_CPXCL) + else if (iasecc_is_cpx(card)) rv = iasecc_init_cpx(card); else { LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_CARD, ""); @@ -990,8 +1001,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path, && card->type != SC_CARD_TYPE_IASECC_AMOS && card->type != SC_CARD_TYPE_IASECC_MI && card->type != SC_CARD_TYPE_IASECC_MI2 - && card->type != SC_CARD_TYPE_IASECC_CPX - && card->type != SC_CARD_TYPE_IASECC_CPXCL) { + && !iasecc_is_cpx(card)) { rv = SC_ERROR_NOT_SUPPORTED; LOG_TEST_GOTO_ERR(ctx, rv, "Unsupported card"); } @@ -1004,8 +1014,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path, card->type == SC_CARD_TYPE_IASECC_AMOS || card->type == SC_CARD_TYPE_IASECC_MI || card->type == SC_CARD_TYPE_IASECC_MI2 || - card->type == SC_CARD_TYPE_IASECC_CPX || - card->type == SC_CARD_TYPE_IASECC_CPXCL + iasecc_is_cpx(card) ) { apdu.p2 = 0x04; } @@ -1016,8 +1025,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path, card->type == SC_CARD_TYPE_IASECC_AMOS || card->type == SC_CARD_TYPE_IASECC_MI || card->type == SC_CARD_TYPE_IASECC_MI2 || - card->type == SC_CARD_TYPE_IASECC_CPX || - card->type == SC_CARD_TYPE_IASECC_CPXCL) { + iasecc_is_cpx(card)) { apdu.p2 = 0x04; } }