FreeCalypso > hg > freecalypso-hwlab
comparison uicc/hlread.c @ 134:69628bcfec17
fc-uicc-tool: iccid command implemented
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 04 Feb 2021 02:28:52 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 133:f3bdefbeae38 | 134:69628bcfec17 |
|---|---|
| 1 /* | |
| 2 * This module implements some high-level or user-friendly read commands. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <stdio.h> | |
| 7 #include <stdlib.h> | |
| 8 #include <pcsclite.h> | |
| 9 #include <winscard.h> | |
| 10 #include "globals.h" | |
| 11 #include "file_id.h" | |
| 12 | |
| 13 encode_hex_digit(d) | |
| 14 unsigned d; | |
| 15 { | |
| 16 if (d <= 9) | |
| 17 return(d + '0'); | |
| 18 else | |
| 19 return(d - 10 + 'A'); | |
| 20 } | |
| 21 | |
| 22 decode_reversed_nibbles(bytes, nbytes, dest) | |
| 23 u_char *bytes; | |
| 24 unsigned nbytes; | |
| 25 char *dest; | |
| 26 { | |
| 27 u_char *sp; | |
| 28 char *dp; | |
| 29 unsigned n, c; | |
| 30 | |
| 31 sp = bytes; | |
| 32 dp = dest; | |
| 33 for (n = 0; n < nbytes; n++) { | |
| 34 c = *sp & 0xF; | |
| 35 *dp++ = encode_hex_digit(c); | |
| 36 c = *sp >> 4; | |
| 37 *dp++ = encode_hex_digit(c); | |
| 38 sp++; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 cmd_iccid() | |
| 43 { | |
| 44 int rc; | |
| 45 unsigned len; | |
| 46 char buf[21]; | |
| 47 | |
| 48 rc = select_op(FILEID_MF); | |
| 49 if (rc < 0) | |
| 50 return(rc); | |
| 51 rc = select_op(EF_ICCID); | |
| 52 if (rc < 0) | |
| 53 return(rc); | |
| 54 rc = select_resp_get_transparent(&len); | |
| 55 if (rc < 0) | |
| 56 return(rc); | |
| 57 if (len != 10) { | |
| 58 fprintf(stderr, "error: expected transparent EF of 10 bytes\n"); | |
| 59 return(-1); | |
| 60 } | |
| 61 rc = readbin_op(0, 10); | |
| 62 if (rc < 0) | |
| 63 return(rc); | |
| 64 decode_reversed_nibbles(sim_resp_data, 10, buf); | |
| 65 buf[20] = '\0'; | |
| 66 printf("%s\n", buf); | |
| 67 return(0); | |
| 68 } |
