FreeCalypso > hg > fc-pcsc-tools
comparison simtool/usersum.c @ 61:633033af6fb8
fc-simtool user-sum command implemented,
a successor to telecom-sum
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 14 Feb 2021 03:27:56 +0000 |
| parents | simtool/telsum.c@2071b28cd0c7 |
| children | b89bc690dec4 |
comparison
equal
deleted
inserted
replaced
| 60:090704d1ddc1 | 61:633033af6fb8 |
|---|---|
| 1 /* | |
| 2 * This module implements the user-sum (summary info) command. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <stdio.h> | |
| 7 #include <stdlib.h> | |
| 8 #include <string.h> | |
| 9 #include <strings.h> | |
| 10 #include "simresp.h" | |
| 11 #include "curfile.h" | |
| 12 #include "file_id.h" | |
| 13 | |
| 14 #define SST_BYTES_USED 15 | |
| 15 | |
| 16 static | |
| 17 read_sst(sstbuf) | |
| 18 u_char *sstbuf; | |
| 19 { | |
| 20 int rc; | |
| 21 unsigned rdlen; | |
| 22 | |
| 23 rc = select_op(DF_GSM); | |
| 24 if (rc < 0) | |
| 25 return(rc); | |
| 26 rc = select_op(EF_SST); | |
| 27 if (rc < 0) | |
| 28 return(rc); | |
| 29 rc = parse_ef_select_response(); | |
| 30 if (rc < 0) | |
| 31 return(rc); | |
| 32 if (curfile_structure != 0x00) { | |
| 33 fprintf(stderr, "error: EF_SST is not transparent\n"); | |
| 34 return(-1); | |
| 35 } | |
| 36 if (curfile_total_size < 2) { | |
| 37 fprintf(stderr, | |
| 38 "error: EF_SST is shorter than spec minimum of 2 bytes\n"); | |
| 39 return(-1); | |
| 40 } | |
| 41 rdlen = curfile_total_size; | |
| 42 if (rdlen > SST_BYTES_USED) | |
| 43 rdlen = SST_BYTES_USED; | |
| 44 rc = readbin_op(0, rdlen); | |
| 45 if (rc < 0) | |
| 46 return(rc); | |
| 47 bcopy(sim_resp_data, sstbuf, rdlen); | |
| 48 if (rdlen < SST_BYTES_USED) | |
| 49 bzero(sstbuf + rdlen, SST_BYTES_USED - rdlen); | |
| 50 return(0); | |
| 51 } | |
| 52 | |
| 53 static | |
| 54 do_phonebook_file(file_id, ef_name, book_name) | |
| 55 unsigned file_id; | |
| 56 char *ef_name, *book_name; | |
| 57 { | |
| 58 int rc; | |
| 59 | |
| 60 rc = select_op(file_id); | |
| 61 if (rc < 0) | |
| 62 return(rc); | |
| 63 rc = parse_ef_select_response(); | |
| 64 if (rc < 0) | |
| 65 return(rc); | |
| 66 if (curfile_structure != 0x01 && curfile_structure != 0x03) { | |
| 67 fprintf(stderr, "error: %s is not record-structured\n", | |
| 68 ef_name); | |
| 69 return(-1); | |
| 70 } | |
| 71 if (curfile_record_len < 14) { | |
| 72 fprintf(stderr, | |
| 73 "error: %s has record length of %u bytes, less than minimum 14\n", | |
| 74 ef_name, curfile_record_len); | |
| 75 return(-1); | |
| 76 } | |
| 77 printf("%s: %u entries, %u bytes of alpha tag\n", book_name, | |
| 78 curfile_record_count, curfile_record_len - 14); | |
| 79 return(0); | |
| 80 } | |
| 81 | |
| 82 static | |
| 83 do_sms_store() | |
| 84 { | |
| 85 int rc; | |
| 86 | |
| 87 rc = select_op(EF_SMS); | |
| 88 if (rc < 0) | |
| 89 return(rc); | |
| 90 rc = parse_ef_select_response(); | |
| 91 if (rc < 0) | |
| 92 return(rc); | |
| 93 if (curfile_structure != 0x01 || curfile_record_len != 176) { | |
| 94 fprintf(stderr, | |
| 95 "error: EF_SMS is not linear fixed with 176-byte records\n"); | |
| 96 return(-1); | |
| 97 } | |
| 98 printf("SMS store: %u entries\n", curfile_record_count); | |
| 99 return(0); | |
| 100 } | |
| 101 | |
| 102 static | |
| 103 do_smsp_store() | |
| 104 { | |
| 105 int rc; | |
| 106 | |
| 107 rc = select_op(EF_SMSP); | |
| 108 if (rc < 0) | |
| 109 return(rc); | |
| 110 rc = parse_ef_select_response(); | |
| 111 if (rc < 0) | |
| 112 return(rc); | |
| 113 if (curfile_structure != 0x01) { | |
| 114 fprintf(stderr, "error: EF_SMSP is not linear fixed\n"); | |
| 115 return(-1); | |
| 116 } | |
| 117 if (curfile_record_len < 28) { | |
| 118 fprintf(stderr, | |
| 119 "error: EF_SMSP has record length of %u bytes, less than minimum 14\n", | |
| 120 curfile_record_len); | |
| 121 return(-1); | |
| 122 } | |
| 123 printf("SMS parameter store: %u entries, %u bytes of alpha tag\n", | |
| 124 curfile_record_count, curfile_record_len - 28); | |
| 125 return(0); | |
| 126 } | |
| 127 | |
| 128 cmd_user_sum() | |
| 129 { | |
| 130 int rc; | |
| 131 u_char sst[SST_BYTES_USED]; | |
| 132 | |
| 133 rc = read_sst(sst); | |
| 134 if (rc < 0) | |
| 135 return(rc); | |
| 136 rc = select_op(DF_TELECOM); | |
| 137 if (rc < 0) | |
| 138 return(rc); | |
| 139 if ((sst[0] & 0x0C) == 0x0C) { | |
| 140 rc = do_phonebook_file(EF_ADN, "EF_ADN", "ADN phonebook"); | |
| 141 if (rc < 0) | |
| 142 return(rc); | |
| 143 } | |
| 144 if ((sst[0] & 0x30) == 0x30) { | |
| 145 rc = do_phonebook_file(EF_FDN, "EF_FDN", "FDN phonebook"); | |
| 146 if (rc < 0) | |
| 147 return(rc); | |
| 148 } | |
| 149 if ((sst[0] & 0xC0) == 0xC0) { | |
| 150 rc = do_sms_store(); | |
| 151 if (rc < 0) | |
| 152 return(rc); | |
| 153 } | |
| 154 if ((sst[1] & 0x03) == 0x03) | |
| 155 printf("AoC service present\n"); | |
| 156 if ((sst[2] & 0x03) == 0x03) { | |
| 157 rc = do_phonebook_file(EF_MSISDN, "EF_MSISDN", "MSISDN record"); | |
| 158 if (rc < 0) | |
| 159 return(rc); | |
| 160 } | |
| 161 if ((sst[2] & 0xC0) == 0xC0) { | |
| 162 rc = do_smsp_store(); | |
| 163 if (rc < 0) | |
| 164 return(rc); | |
| 165 } | |
| 166 if ((sst[3] & 0x03) == 0x03) { | |
| 167 rc = do_phonebook_file(EF_LND, "EF_LND", "LND cyclic store"); | |
| 168 if (rc < 0) | |
| 169 return(rc); | |
| 170 } | |
| 171 if ((sst[4] & 0x0C) == 0x0C) { | |
| 172 rc = do_phonebook_file(EF_SDN, "EF_SDN", "SDN phonebook"); | |
| 173 if (rc < 0) | |
| 174 return(rc); | |
| 175 } | |
| 176 if ((sst[13] & 0x03) == 0x03) | |
| 177 printf("MBDN present\n"); | |
| 178 if ((sst[13] & 0x0C) == 0x0C) | |
| 179 printf("MWIS present\n"); | |
| 180 return(0); | |
| 181 } |
