diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index e7cd03fa..5c1befbe 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -1173,7 +1173,7 @@ int JsonSaveHex(json_t *elm, char *path, uint64_t data, int datalen) { int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveValue) { json_error_t error; - if (strlen(path) < 1) + if (strlen(path) < 1 || !tlvelm) return 1; if (path[0] == '$') { @@ -1197,7 +1197,18 @@ int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveValue) } int JsonSaveTLVTreeElm(json_t *elm, char *path, struct tlvdb *tlvdbelm, bool saveValue) { - JsonSaveTLVElm(elm, path, (struct tlv *)tlvdb_get_tlv(tlvdbelm), saveValue); + return JsonSaveTLVElm(elm, path, (struct tlv *)tlvdb_get_tlv(tlvdbelm), saveValue); +} +int JsonSaveTLVTree(json_t *elm, char *path, struct tlvdb *tlvdbelm) { + struct tlvdb *tlvp = tlvdbelm; + while (tlvp) { + JsonSaveTLVTreeElm(elm, path, tlvp, true); + if (tlvdb_elm_get_children(tlvp)) { + + } + + tlvp = tlvdb_elm_get_next(tlvp); + } return 0; } @@ -1301,7 +1312,7 @@ int CmdHFEMVScan(const char *cmd) { TLVPrintAIDlistFromSelectTLV(tlvSelect); JsonSaveBufAsHex(root, "$.PPSE.AID", (uint8_t *)"2PAY.SYS.DDF01", 14); - JsonSaveTLVTreeElm(root, "$.PPSE.FCITemplate", tlvdb_find(tlvSelect, 0x6f), true); + JsonSaveTLVTree(root, "$.PPSE.FCITemplate", tlvdb_find(tlvSelect, 0x6f)); // here save PSE result to JSON } else { @@ -1343,7 +1354,7 @@ int CmdHFEMVScan(const char *cmd) { if (decodeTLV) TLVPrintFromBuffer(buf, len); - // here save Select result to JSON + JsonSaveTLVTree(root, "$.Application.FCITemplate", tlvdb_parse_multi(buf, len)); diff --git a/client/emv/tlv.c b/client/emv/tlv.c index f2c60970..540c33e4 100644 --- a/client/emv/tlv.c +++ b/client/emv/tlv.c @@ -520,3 +520,18 @@ bool tlv_equal(const struct tlv *a, const struct tlv *b) return a->tag == b->tag && a->len == b->len && !memcmp(a->value, b->value, a->len); } + +struct tlvdb *tlvdb_elm_get_next(struct tlvdb *tlvdb) +{ + return tlvdb->next; +} + +struct tlvdb *tlvdb_elm_get_children(struct tlvdb *tlvdb) +{ + return tlvdb->children; +} + +struct tlvdb *tlvdb_elm_get_parent(struct tlvdb *tlvdb) +{ + return tlvdb->parent; +} diff --git a/client/emv/tlv.h b/client/emv/tlv.h index 3c3fde79..b25b51de 100644 --- a/client/emv/tlv.h +++ b/client/emv/tlv.h @@ -39,6 +39,10 @@ struct tlvdb *tlvdb_parse(const unsigned char *buf, size_t len); struct tlvdb *tlvdb_parse_multi(const unsigned char *buf, size_t len); void tlvdb_free(struct tlvdb *tlvdb); +struct tlvdb *tlvdb_elm_get_next(struct tlvdb *tlvdb); +struct tlvdb *tlvdb_elm_get_children(struct tlvdb *tlvdb); +struct tlvdb *tlvdb_elm_get_parent(struct tlvdb *tlvdb); + struct tlvdb *tlvdb_find_full(struct tlvdb *tlvdb, tlv_tag_t tag); // search also in childrens struct tlvdb *tlvdb_find(struct tlvdb *tlvdb, tlv_tag_t tag); struct tlvdb *tlvdb_find_next(struct tlvdb *tlvdb, tlv_tag_t tag);