FreeCalypso > hg > fc-sim-tools
comparison uicc/savebin.c @ 90:3afa61d98961
fc-uicc-tool: savebin ported over from fc-simtool
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 11 Apr 2021 04:32:26 +0000 |
| parents | simtool/savebin.c@ddd767f6e15b |
| children |
comparison
equal
deleted
inserted
replaced
| 89:db131929ee96 | 90:3afa61d98961 |
|---|---|
| 1 /* | |
| 2 * This module implements the savebin command for saving SIM file content | |
| 3 * in UNIX host files. | |
| 4 */ | |
| 5 | |
| 6 #include <sys/types.h> | |
| 7 #include <ctype.h> | |
| 8 #include <stdio.h> | |
| 9 #include <stdlib.h> | |
| 10 #include "simresp.h" | |
| 11 #include "efstruct.h" | |
| 12 | |
| 13 static | |
| 14 savebin_transparent(efs, outf) | |
| 15 struct ef_struct *efs; | |
| 16 FILE *outf; | |
| 17 { | |
| 18 unsigned off, cc; | |
| 19 int rc; | |
| 20 | |
| 21 for (off = 0; off < efs->total_size; off += cc) { | |
| 22 cc = efs->total_size - off; | |
| 23 if (cc > 256) | |
| 24 cc = 256; | |
| 25 rc = readbin_op(off, cc); | |
| 26 if (rc < 0) | |
| 27 return(rc); | |
| 28 fwrite(sim_resp_data, 1, cc, outf); | |
| 29 } | |
| 30 return(0); | |
| 31 } | |
| 32 | |
| 33 static | |
| 34 savebin_records(efs, outf) | |
| 35 struct ef_struct *efs; | |
| 36 FILE *outf; | |
| 37 { | |
| 38 unsigned recno; | |
| 39 int rc; | |
| 40 | |
| 41 for (recno = 1; recno <= efs->record_count; recno++) { | |
| 42 rc = readrec_op(recno, 0x04, efs->record_len); | |
| 43 if (rc < 0) | |
| 44 return(rc); | |
| 45 fwrite(sim_resp_data, efs->record_len, 1, outf); | |
| 46 } | |
| 47 return(0); | |
| 48 } | |
| 49 | |
| 50 cmd_savebin(argc, argv) | |
| 51 char **argv; | |
| 52 { | |
| 53 int file_id, rc; | |
| 54 struct ef_struct efs; | |
| 55 FILE *of; | |
| 56 | |
| 57 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) && | |
| 58 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4]) | |
| 59 file_id = strtoul(argv[1], 0, 16); | |
| 60 else | |
| 61 file_id = find_symbolic_file_name(argv[1]); | |
| 62 if (file_id < 0) { | |
| 63 fprintf(stderr, | |
| 64 "error: file ID argument is not a hex value or a recognized symbolic name\n"); | |
| 65 return(-1); | |
| 66 } | |
| 67 rc = select_op(file_id); | |
| 68 if (rc < 0) | |
| 69 return(rc); | |
| 70 rc = select_resp_get_ef_struct(&efs); | |
| 71 if (rc < 0) | |
| 72 return(rc); | |
| 73 of = fopen(argv[2], "w"); | |
| 74 if (!of) { | |
| 75 perror(argv[2]); | |
| 76 return(-1); | |
| 77 } | |
| 78 switch (efs.structure) { | |
| 79 case 0x01: | |
| 80 /* transparent */ | |
| 81 rc = savebin_transparent(&efs, of); | |
| 82 break; | |
| 83 case 0x02: | |
| 84 case 0x06: | |
| 85 /* record-based */ | |
| 86 rc = savebin_records(&efs, of); | |
| 87 break; | |
| 88 } | |
| 89 fclose(of); | |
| 90 return(rc); | |
| 91 } |
