added tlv tree navigation

This commit is contained in:
merlokk 2018-10-03 17:31:01 +03:00
commit 7fecd489cf
3 changed files with 34 additions and 4 deletions

View file

@ -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));

View file

@ -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;
}

View file

@ -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);