FreeCalypso > hg > fc-sim-tools
comparison libcommon/dumpdirfunc.c @ 9:c9ef9e91dd8e
new libcommon, initial version
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 14 Mar 2021 06:55:38 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 8:34bbb0585cab | 9:c9ef9e91dd8e |
|---|---|
| 1 /* | |
| 2 * This module implements the common function for dumping EF_DIR. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <stdio.h> | |
| 7 #include "simresp.h" | |
| 8 | |
| 9 static void | |
| 10 dump_aid(tlv, outf) | |
| 11 u_char *tlv; | |
| 12 FILE *outf; | |
| 13 { | |
| 14 unsigned reclen, n; | |
| 15 | |
| 16 reclen = tlv[1]; | |
| 17 fputs(" AID:", outf); | |
| 18 for (n = 0; n < reclen; n++) | |
| 19 fprintf(outf, " %02X", tlv[n+2]); | |
| 20 putc('\n', outf); | |
| 21 } | |
| 22 | |
| 23 static void | |
| 24 dump_label(tlv, outf) | |
| 25 u_char *tlv; | |
| 26 FILE *outf; | |
| 27 { | |
| 28 int rc; | |
| 29 unsigned textlen; | |
| 30 | |
| 31 fputs(" Label: ", outf); | |
| 32 rc = validate_alpha_field(tlv + 2, tlv[1], &textlen); | |
| 33 if (rc < 0) { | |
| 34 fputs("malformed\n", outf); | |
| 35 return; | |
| 36 } | |
| 37 print_alpha_field(tlv + 2, textlen, outf); | |
| 38 putc('\n', outf); | |
| 39 } | |
| 40 | |
| 41 static void | |
| 42 dump_unknown_tlv(tlv, outf) | |
| 43 u_char *tlv; | |
| 44 FILE *outf; | |
| 45 { | |
| 46 unsigned reclen, n; | |
| 47 | |
| 48 reclen = tlv[1] + 2; | |
| 49 fputs(" TLV:", outf); | |
| 50 for (n = 0; n < reclen; n++) | |
| 51 fprintf(outf, " %02X", tlv[n]); | |
| 52 putc('\n', outf); | |
| 53 } | |
| 54 | |
| 55 void | |
| 56 dump_efdir_record(outf) | |
| 57 FILE *outf; | |
| 58 { | |
| 59 unsigned totlen, reclen; | |
| 60 u_char *dp, *endp; | |
| 61 | |
| 62 if (sim_resp_data[0] != 0x61) { | |
| 63 fprintf(outf, " bad: first byte != 0x61\n"); | |
| 64 return; | |
| 65 } | |
| 66 totlen = sim_resp_data[1]; | |
| 67 if (totlen < 3 || totlen > 0x7F) { | |
| 68 fprintf(outf, " bad: global length byte 0x%02X is invalid\n", | |
| 69 totlen); | |
| 70 return; | |
| 71 } | |
| 72 if (totlen + 2 > sim_resp_data_len) { | |
| 73 fprintf(outf, | |
| 74 " bad: TLV global length exceeds EF record length\n"); | |
| 75 return; | |
| 76 } | |
| 77 dp = sim_resp_data + 2; | |
| 78 endp = sim_resp_data + 2 + totlen; | |
| 79 while (dp < endp) { | |
| 80 if (endp - dp < 2) { | |
| 81 trunc_error: fprintf(outf, " bad: truncated TLV record\n"); | |
| 82 return; | |
| 83 } | |
| 84 if ((dp[0] & 0x1F) == 0x1F) { | |
| 85 fprintf(outf, " bad: extended tag not supported\n"); | |
| 86 return; | |
| 87 } | |
| 88 if (dp[1] & 0x80) { | |
| 89 fprintf(outf, " bad: extended length not supported\n"); | |
| 90 return; | |
| 91 } | |
| 92 reclen = dp[1] + 2; | |
| 93 if (endp - dp < reclen) | |
| 94 goto trunc_error; | |
| 95 switch (dp[0]) { | |
| 96 case 0x4F: | |
| 97 dump_aid(dp, outf); | |
| 98 break; | |
| 99 case 0x50: | |
| 100 dump_label(dp, outf); | |
| 101 break; | |
| 102 default: | |
| 103 dump_unknown_tlv(dp, outf); | |
| 104 } | |
| 105 dp += reclen; | |
| 106 } | |
| 107 } |
