FreeCalypso > hg > fc-pcsc-tools
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/smsp_set.c Fri Feb 12 23:48:01 2021 +0000 @@ -0,0 +1,138 @@ +/* + * This module implements the user-oriented smsp-set and smsp-set-tag commands. + */ + +#include <sys/types.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> +#include "curfile.h" + +static +set_param_da(arg, fixp) + char *arg; + u_char *fixp; +{ + int rc; + + rc = encode_phone_number_arg(arg, fixp + 1, 1); + if (rc < 0) + return(rc); + fixp[0] &= 0xFE; + return(0); +} + +static +set_param_sc(arg, fixp) + char *arg; + u_char *fixp; +{ + int rc; + + rc = encode_phone_number_arg(arg, fixp + 13, 0); + if (rc < 0) + return(rc); + fixp[0] &= 0xFD; + return(0); +} + +static +set_param_pid(arg, fixp) + char *arg; + u_char *fixp; +{ + char *endp; + + if (!isdigit(*arg)) { +inv: fprintf(stderr, "error: invalid PID= parameter\n"); + return(-1); + } + fixp[25] = strtoul(arg, &endp, 0); + if (*endp) + goto inv; + fixp[0] &= 0xFB; + return(0); +} + +static +set_param_dcs(arg, fixp) + char *arg; + u_char *fixp; +{ + char *endp; + + if (!isdigit(*arg)) { +inv: fprintf(stderr, "error: invalid DCS= parameter\n"); + return(-1); + } + fixp[26] = strtoul(arg, &endp, 0); + if (*endp) + goto inv; + fixp[0] &= 0xF7; + return(0); +} + +static +set_param_vp(arg, fixp) + char *arg; + u_char *fixp; +{ + char *endp; + + if (!isdigit(*arg)) { +inv: fprintf(stderr, "error: invalid VP= parameter\n"); + return(-1); + } + fixp[27] = strtoul(arg, &endp, 0); + if (*endp) + goto inv; + fixp[0] &= 0xEF; + return(0); +} + +static +set_param(arg, fixp) + char *arg; + u_char *fixp; +{ + if (!strncasecmp(arg, "DA=", 3)) + return set_param_da(arg + 3, fixp); + if (!strncasecmp(arg, "SC=", 3)) + return set_param_sc(arg + 3, fixp); + if (!strncasecmp(arg, "PID=", 4)) + return set_param_pid(arg + 4, fixp); + if (!strncasecmp(arg, "DCS=", 4)) + return set_param_dcs(arg + 4, fixp); + if (!strncasecmp(arg, "VP=", 3)) + return set_param_vp(arg + 3, fixp); + fprintf(stderr, "error: non-understood parameter \"%s\"\n", arg); + return(-1); +} + +cmd_smsp_set(argc, argv) + char **argv; +{ + int rc; + unsigned recno; + u_char record[255], *fixp; + char **ap; + + rc = select_ef_smsp(); + if (rc < 0) + return(rc); + recno = strtoul(argv[1], 0, 0); + if (recno < 1 || recno > curfile_record_count) { + fprintf(stderr, "error: specified record number is invalid\n"); + return(-1); + } + memset(record, 0xFF, curfile_record_len); + fixp = record + curfile_record_len - 28; + for (ap = argv + 2; *ap; ap++) { + rc = set_param(*ap, fixp); + if (rc < 0) + return(rc); + } + return update_rec_op(recno, 0x04, record, curfile_record_len); +}