FreeCalypso > hg > fc-pcsc-tools
annotate simtool/pnnprog.c @ 215:3a2f43460582
fc-simtool pnn-write command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Mar 2021 08:35:57 +0000 |
parents | |
children | cd66e13eccf3 |
rev | line source |
---|---|
215
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements functions for admin programming of EF_PNN. |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "curfile.h" |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 static u_char * |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 add_field(dp, bytes_avail, namearg, type) |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 u_char *dp; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 char *namearg; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 unsigned bytes_avail, type; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 u_char gsm7_buf[289]; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 unsigned nsept, noct; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 int rc; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (bytes_avail < 4) { |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 fprintf(stderr, |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 "error: PNN record is too short for name element\n"); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 return(0); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 } |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 rc = qstring_arg_to_gsm7(namearg, gsm7_buf, (bytes_avail-3) * 8 / 7); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (rc < 0) |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 return(0); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 nsept = rc; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 gsm7_buf[nsept] = 0; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 noct = (nsept * 7 + 7) / 8; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 *dp++ = type; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 *dp++ = noct + 1; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 *dp++ = 0x80 | (nsept & 7); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 gsm7_pack(gsm7_buf, dp, noct); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 dp += noct; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return dp; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 cmd_pnn_write(argc, argv) |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 char **argv; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 { |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 int rc; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 unsigned recno; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 u_char record[255], *dp, *endp; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 rc = select_ef_pnn(); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (rc < 0) |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return(rc); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 recno = strtoul(argv[1], 0, 0); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (recno < 1 || recno > curfile_record_count) { |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fprintf(stderr, "error: specified record number is invalid\n"); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 return(-1); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 dp = record; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 endp = record + curfile_record_len; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 dp = add_field(dp, endp - dp, argv[2], 0x43); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (!dp) |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 return(-1); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (argv[3]) { |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 dp = add_field(dp, endp - dp, argv[3], 0x45); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (!dp) |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 return(-1); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 while (dp < endp) |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 *dp++ = 0xFF; |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 return update_rec_op(recno, 0x04, record, curfile_record_len); |
3a2f43460582
fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |