FreeCalypso > hg > fc-pcsc-tools
comparison simtool/smsp_set.c @ 44:f4eb1e83b4b3
fc-simtool smsp-set command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Feb 2021 23:48:01 +0000 |
parents | |
children | 5bca197e7495 |
comparison
equal
deleted
inserted
replaced
43:52ec2d3eb851 | 44:f4eb1e83b4b3 |
---|---|
1 /* | |
2 * This module implements the user-oriented smsp-set and smsp-set-tag commands. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <ctype.h> | |
7 #include <string.h> | |
8 #include <strings.h> | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 #include "curfile.h" | |
12 | |
13 static | |
14 set_param_da(arg, fixp) | |
15 char *arg; | |
16 u_char *fixp; | |
17 { | |
18 int rc; | |
19 | |
20 rc = encode_phone_number_arg(arg, fixp + 1, 1); | |
21 if (rc < 0) | |
22 return(rc); | |
23 fixp[0] &= 0xFE; | |
24 return(0); | |
25 } | |
26 | |
27 static | |
28 set_param_sc(arg, fixp) | |
29 char *arg; | |
30 u_char *fixp; | |
31 { | |
32 int rc; | |
33 | |
34 rc = encode_phone_number_arg(arg, fixp + 13, 0); | |
35 if (rc < 0) | |
36 return(rc); | |
37 fixp[0] &= 0xFD; | |
38 return(0); | |
39 } | |
40 | |
41 static | |
42 set_param_pid(arg, fixp) | |
43 char *arg; | |
44 u_char *fixp; | |
45 { | |
46 char *endp; | |
47 | |
48 if (!isdigit(*arg)) { | |
49 inv: fprintf(stderr, "error: invalid PID= parameter\n"); | |
50 return(-1); | |
51 } | |
52 fixp[25] = strtoul(arg, &endp, 0); | |
53 if (*endp) | |
54 goto inv; | |
55 fixp[0] &= 0xFB; | |
56 return(0); | |
57 } | |
58 | |
59 static | |
60 set_param_dcs(arg, fixp) | |
61 char *arg; | |
62 u_char *fixp; | |
63 { | |
64 char *endp; | |
65 | |
66 if (!isdigit(*arg)) { | |
67 inv: fprintf(stderr, "error: invalid DCS= parameter\n"); | |
68 return(-1); | |
69 } | |
70 fixp[26] = strtoul(arg, &endp, 0); | |
71 if (*endp) | |
72 goto inv; | |
73 fixp[0] &= 0xF7; | |
74 return(0); | |
75 } | |
76 | |
77 static | |
78 set_param_vp(arg, fixp) | |
79 char *arg; | |
80 u_char *fixp; | |
81 { | |
82 char *endp; | |
83 | |
84 if (!isdigit(*arg)) { | |
85 inv: fprintf(stderr, "error: invalid VP= parameter\n"); | |
86 return(-1); | |
87 } | |
88 fixp[27] = strtoul(arg, &endp, 0); | |
89 if (*endp) | |
90 goto inv; | |
91 fixp[0] &= 0xEF; | |
92 return(0); | |
93 } | |
94 | |
95 static | |
96 set_param(arg, fixp) | |
97 char *arg; | |
98 u_char *fixp; | |
99 { | |
100 if (!strncasecmp(arg, "DA=", 3)) | |
101 return set_param_da(arg + 3, fixp); | |
102 if (!strncasecmp(arg, "SC=", 3)) | |
103 return set_param_sc(arg + 3, fixp); | |
104 if (!strncasecmp(arg, "PID=", 4)) | |
105 return set_param_pid(arg + 4, fixp); | |
106 if (!strncasecmp(arg, "DCS=", 4)) | |
107 return set_param_dcs(arg + 4, fixp); | |
108 if (!strncasecmp(arg, "VP=", 3)) | |
109 return set_param_vp(arg + 3, fixp); | |
110 fprintf(stderr, "error: non-understood parameter \"%s\"\n", arg); | |
111 return(-1); | |
112 } | |
113 | |
114 cmd_smsp_set(argc, argv) | |
115 char **argv; | |
116 { | |
117 int rc; | |
118 unsigned recno; | |
119 u_char record[255], *fixp; | |
120 char **ap; | |
121 | |
122 rc = select_ef_smsp(); | |
123 if (rc < 0) | |
124 return(rc); | |
125 recno = strtoul(argv[1], 0, 0); | |
126 if (recno < 1 || recno > curfile_record_count) { | |
127 fprintf(stderr, "error: specified record number is invalid\n"); | |
128 return(-1); | |
129 } | |
130 memset(record, 0xFF, curfile_record_len); | |
131 fixp = record + curfile_record_len - 28; | |
132 for (ap = argv + 2; *ap; ap++) { | |
133 rc = set_param(*ap, fixp); | |
134 if (rc < 0) | |
135 return(rc); | |
136 } | |
137 return update_rec_op(recno, 0x04, record, curfile_record_len); | |
138 } |