FreeCalypso > hg > freecalypso-hwlab
changeset 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 | ce2a880ab704 |
children | 1232dea1d66a |
files | uicc/Makefile uicc/dispatch.c uicc/pberase.c |
diffstat | 3 files changed, 93 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/uicc/Makefile Sat Feb 06 02:45:29 2021 +0000 +++ b/uicc/Makefile Sat Feb 06 02:54:16 2021 +0000 @@ -3,8 +3,8 @@ PROG= fc-uicc-tool OBJS= alpha_decode.o alpha_valid.o apdu.o atr.o cardconnect.o dispatch.o \ dumpdir.o exit.o globals.o hexdump.o hexread.o hexstr.o hlread.o main.o\ - names.o pbcommon.o pbdump.o pbupdate.o readcmd.o readops.o script.o \ - select.o telsum.o writecmd.o writeops.o + names.o pbcommon.o pbdump.o pberase.o pbupdate.o readcmd.o readops.o \ + script.o select.o telsum.o writecmd.o writeops.o INSTBIN=/opt/freecalypso/bin all: ${PROG}
--- a/uicc/dispatch.c Sat Feb 06 02:45:29 2021 +0000 +++ b/uicc/dispatch.c Sat Feb 06 02:54:16 2021 +0000 @@ -13,6 +13,9 @@ extern int cmd_iccid(); extern int cmd_pb_dump(); extern int cmd_pb_dump_rec(); +extern int cmd_pb_erase(); +extern int cmd_pb_erase_one(); +extern int cmd_pb_erase_range(); extern int cmd_pb_update(); extern int cmd_pb_update_imm(); extern int cmd_pb_update_imm_hex(); @@ -42,6 +45,9 @@ {"iccid", 0, 0, cmd_iccid}, {"pb-dump", 1, 2, cmd_pb_dump}, {"pb-dump-rec", 2, 3, cmd_pb_dump_rec}, + {"pb-erase", 1, 1, cmd_pb_erase}, + {"pb-erase-one", 2, 2, cmd_pb_erase_one}, + {"pb-erase-range", 3, 3, cmd_pb_erase_range}, {"pb-update", 2, 2, cmd_pb_update}, {"pb-update-imm", 3, 4, cmd_pb_update_imm}, {"pb-update-imm-hex", 4, 4, cmd_pb_update_imm_hex},
--- /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); +}