comparison simtool/pnndump.c @ 114:2c07684a3980

fc-simtool pnn-dump: support output redirection
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Feb 2021 07:22:56 +0000
parents dc8a2e6fa03e
children 8b1eecb56cb5
comparison
equal deleted inserted replaced
113:32acef9d20ff 114:2c07684a3980
8 #include "simresp.h" 8 #include "simresp.h"
9 #include "curfile.h" 9 #include "curfile.h"
10 #include "file_id.h" 10 #include "file_id.h"
11 11
12 static void 12 static void
13 dump_record(recno) 13 dump_record(recno, outf)
14 unsigned recno; 14 unsigned recno;
15 FILE *outf;
15 { 16 {
16 u_char *dp, *endp; 17 u_char *dp, *endp;
17 char *name_kw; 18 char *name_kw;
18 unsigned ielen, code_byte, nsept; 19 unsigned ielen, code_byte, nsept;
19 u_char gsm7_buf[288]; 20 u_char gsm7_buf[288];
20 21
21 printf("#%u:", recno); 22 fprintf(outf, "#%u:", recno);
22 dp = sim_resp_data; 23 dp = sim_resp_data;
23 endp = sim_resp_data + sim_resp_data_len; 24 endp = sim_resp_data + sim_resp_data_len;
24 while (dp < endp) { 25 while (dp < endp) {
25 if (*dp == 0xFF) 26 if (*dp == 0xFF)
26 break; 27 break;
30 break; 31 break;
31 case 0x45: 32 case 0x45:
32 name_kw = "Sn"; 33 name_kw = "Sn";
33 break; 34 break;
34 default: 35 default:
35 printf(" unknown-IEI\n"); 36 fprintf(outf, " unknown-IEI\n");
36 return; 37 return;
37 } 38 }
38 if (dp >= endp) { 39 if (dp >= endp) {
39 printf(" truncated-IE\n"); 40 fprintf(outf, " truncated-IE\n");
40 return; 41 return;
41 } 42 }
42 ielen = *dp++; 43 ielen = *dp++;
43 if (ielen < 1 || ielen > (endp - dp)) { 44 if (ielen < 1 || ielen > (endp - dp)) {
44 printf(" bad-length\n"); 45 fprintf(outf, " bad-length\n");
45 return; 46 return;
46 } 47 }
47 code_byte = *dp++; 48 code_byte = *dp++;
48 ielen--; 49 ielen--;
49 printf(" %s=0x%02X", name_kw, code_byte); 50 fprintf(outf, " %s=0x%02X", name_kw, code_byte);
50 if (!ielen) 51 if (!ielen)
51 continue; 52 continue;
52 putchar(','); 53 putc(',', outf);
53 if ((code_byte & 0x70) == 0) { 54 if ((code_byte & 0x70) == 0) {
54 nsept = ielen * 8 / 7; 55 nsept = ielen * 8 / 7;
55 gsm7_unpack(dp, gsm7_buf, nsept); 56 gsm7_unpack(dp, gsm7_buf, nsept);
56 dp += ielen; 57 dp += ielen;
57 print_gsm7_string_to_file(gsm7_buf, nsept, stdout); 58 print_gsm7_string_to_file(gsm7_buf, nsept, outf);
58 } else { 59 } else {
59 for (; ielen; ielen--) 60 for (; ielen; ielen--)
60 printf("%02X", *dp++); 61 fprintf(outf, "%02X", *dp++);
61 } 62 }
62 } 63 }
63 for (; dp < endp; dp++) { 64 for (; dp < endp; dp++) {
64 if (*dp != 0xFF) { 65 if (*dp != 0xFF) {
65 printf(" bad-padding\n"); 66 fprintf(outf, " bad-padding\n");
66 return; 67 return;
67 } 68 }
68 } 69 }
69 putchar('\n'); 70 putc('\n', outf);
70 } 71 }
71 72
72 cmd_pnn_dump() 73 cmd_pnn_dump(argc, argv, outf)
74 char **argv;
75 FILE *outf;
73 { 76 {
74 int rc; 77 int rc;
75 unsigned recno; 78 unsigned recno;
76 79
77 rc = select_op(DF_GSM); 80 rc = select_op(DF_GSM);
96 rc = readrec_op(recno, 0x04, curfile_record_len); 99 rc = readrec_op(recno, 0x04, curfile_record_len);
97 if (rc < 0) 100 if (rc < 0)
98 return(rc); 101 return(rc);
99 if (check_simresp_all_blank()) 102 if (check_simresp_all_blank())
100 continue; 103 continue;
101 dump_record(recno); 104 dump_record(recno, outf);
102 } 105 }
103 return(0); 106 return(0);
104 } 107 }