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