FreeCalypso > hg > freecalypso-hwlab
diff uicc/pberase.c @ 147:43463dc91431
fc-uicc-tool: pb-erase commands ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 Feb 2021 02:54:16 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uicc/pberase.c Sat Feb 06 02:54:16 2021 +0000 @@ -0,0 +1,85 @@ +/* + * This module implements the pb-erase command. + */ + +#include <sys/types.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> + +cmd_pb_erase(argc, argv) + char **argv; +{ + int rc; + unsigned recno; + u_char record[255]; + unsigned pb_record_len, pb_record_count; + + rc = phonebook_op_common(argv[1], &pb_record_len, &pb_record_count); + if (rc < 0) + return(rc); + memset(record, 0xFF, pb_record_len); + for (recno = 1; recno <= pb_record_count; recno++) { + rc = update_rec_op(recno, 0x04, record, pb_record_len); + if (rc < 0) + return(rc); + } + return(0); +} + +cmd_pb_erase_one(argc, argv) + char **argv; +{ + int rc; + unsigned recno; + u_char record[255]; + unsigned pb_record_len, pb_record_count; + + rc = phonebook_op_common(argv[1], &pb_record_len, &pb_record_count); + if (rc < 0) + return(rc); + recno = strtoul(argv[2], 0, 0); + if (recno < 1 || recno > pb_record_count) { + fprintf(stderr, "error: specified record number is invalid\n"); + return(-1); + } + memset(record, 0xFF, pb_record_len); + return update_rec_op(recno, 0x04, record, pb_record_len); +} + +cmd_pb_erase_range(argc, argv) + char **argv; +{ + int rc; + unsigned recno, startrec, endrec; + u_char record[255]; + unsigned pb_record_len, pb_record_count; + + rc = phonebook_op_common(argv[1], &pb_record_len, &pb_record_count); + if (rc < 0) + return(rc); + startrec = strtoul(argv[2], 0, 0); + if (startrec < 1 || startrec > pb_record_count) { + fprintf(stderr, + "error: specified starting record number is invalid\n"); + return(-1); + } + endrec = strtoul(argv[3], 0, 0); + if (endrec < 1 || endrec > pb_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, pb_record_len); + for (recno = startrec; recno <= endrec; recno++) { + rc = update_rec_op(recno, 0x04, record, pb_record_len); + if (rc < 0) + return(rc); + } + return(0); +}