1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 // ATR information lookup
17 //-----------------------------------------------------------------------------
21 #include "commonutil.h" // ARRAYLEN
22 #include "ui.h" // PrintAndLogEx
24 // get a ATR description based on the atr bytes
25 // returns description of the best match
26 const char *getAtrInfo(const char *atr_str
) {
27 size_t slen
= strlen(atr_str
);
29 // skip last element of AtrTable
30 for (int i
= 0; i
< ARRAYLEN(AtrTable
) - 1; ++i
) {
32 if (strlen(AtrTable
[i
].bytes
) != slen
)
35 if (strstr(AtrTable
[i
].bytes
, ".") != NULL
) {
36 char *tmp_atr
= calloc(slen
, sizeof(uint8_t));
37 if (tmp_atr
== NULL
) {
38 PrintAndLogEx(FAILED
, "failed to allocate memory");
42 for (int j
= 0; j
< slen
; j
++) {
43 tmp_atr
[j
] = (AtrTable
[i
].bytes
[j
] == '.') ? '.' : atr_str
[j
];
46 if (strncmp(tmp_atr
, AtrTable
[i
].bytes
, slen
) == 0) {
47 // record partial match but continue looking for full match
53 if (strncmp(atr_str
, AtrTable
[i
].bytes
, slen
) == 0) {
54 return AtrTable
[i
].desc
;
60 return AtrTable
[match
].desc
;
62 //No match, return default = last element of AtrTable
63 return AtrTable
[ARRAYLEN(AtrTable
) - 1].desc
;