FreeCalypso > hg > fc-pcsc-tools
diff simtool/smserase.c @ 42:2714d379edc2
fc-simtool sms-erase-* command family implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Feb 2021 23:02:09 +0000 |
parents | simtool/smsp_erase.c@4c240a37e7c4 |
children | 10030acba82f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/smserase.c Fri Feb 12 23:02:09 2021 +0000 @@ -0,0 +1,116 @@ +/* + * This module implements the sms-erase family of commands. + */ + +#include <sys/types.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> +#include "curfile.h" +#include "file_id.h" + +#define SMS_RECORD_LEN 176 + +static +select_ef_sms() +{ + int rc; + + rc = select_op(DF_TELECOM); + if (rc < 0) + return(rc); + rc = select_op(EF_SMS); + if (rc < 0) + return(rc); + rc = parse_ef_select_response(); + if (rc < 0) + return(rc); + if (curfile_structure != 0x01) { + fprintf(stderr, "error: EF_SMS is not linear fixed\n"); + return(-1); + } + if (curfile_record_len != SMS_RECORD_LEN) { + fprintf(stderr, + "error: EF_SMS has record length of %u bytes, expected 176\n", + curfile_record_len); + return(-1); + } + return(0); +} + +cmd_sms_erase_all(argc, argv) + char **argv; +{ + int rc; + unsigned recno; + u_char record[SMS_RECORD_LEN]; + + rc = select_ef_sms(); + if (rc < 0) + return(rc); + memset(record, 0xFF, SMS_RECORD_LEN); + record[0] = 0; + for (recno = 1; recno <= curfile_record_count; recno++) { + rc = update_rec_op(recno, 0x04, record, SMS_RECORD_LEN); + if (rc < 0) + return(rc); + } + return(0); +} + +cmd_sms_erase_one(argc, argv) + char **argv; +{ + int rc; + unsigned recno; + u_char record[SMS_RECORD_LEN]; + + rc = select_ef_sms(); + 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, SMS_RECORD_LEN); + record[0] = 0; + return update_rec_op(recno, 0x04, record, SMS_RECORD_LEN); +} + +cmd_sms_erase_range(argc, argv) + char **argv; +{ + int rc; + unsigned recno, startrec, endrec; + u_char record[SMS_RECORD_LEN]; + + rc = select_ef_sms(); + if (rc < 0) + return(rc); + startrec = strtoul(argv[1], 0, 0); + if (startrec < 1 || startrec > curfile_record_count) { + fprintf(stderr, + "error: specified starting record number is invalid\n"); + return(-1); + } + endrec = strtoul(argv[2], 0, 0); + if (endrec < 1 || endrec > curfile_record_count) { + fprintf(stderr, + "error: specified final record number is invalid\n"); + return(-1); + } + if (startrec > endrec) { + fprintf(stderr, "error: reverse record range specified\n"); + return(-1); + } + memset(record, 0xFF, SMS_RECORD_LEN); + record[0] = 0; + for (recno = startrec; recno <= endrec; recno++) { + rc = update_rec_op(recno, 0x04, record, SMS_RECORD_LEN); + if (rc < 0) + return(rc); + } + return(0); +}