FreeCalypso > hg > fc-sim-tools
diff simtool/oplprog.c @ 10:ddd767f6e15b
fc-simtool ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 07:11:25 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/oplprog.c Sun Mar 14 07:11:25 2021 +0000 @@ -0,0 +1,84 @@ +/* + * This module implements functions for admin programming of EF_OPL. + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "curfile.h" + +cmd_opl_write(argc, argv) + char **argv; +{ + int rc; + unsigned recno, lac; + u_char record[255]; + + rc = select_ef_opl(); + 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); + } + rc = encode_plmn_3bytes(argv[2], record); + if (rc < 0) { + fprintf(stderr, "error: invalid MCC-MNC argument\n"); + return(rc); + } + lac = strtoul(argv[3], 0, 16); + record[3] = lac >> 8; + record[4] = lac; + lac = strtoul(argv[4], 0, 16); + record[5] = lac >> 8; + record[6] = lac; + record[7] = strtoul(argv[5], 0, 0); + if (curfile_record_len > 8) + memset(record + 8, 0xFF, curfile_record_len - 8); + return update_rec_op(recno, 0x04, record, curfile_record_len); +} + +cmd_opl_erase(argc, argv) + char **argv; +{ + int rc; + unsigned recno, startrec, endrec; + u_char record[255]; + + rc = select_ef_opl(); + 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); + } + if (!argv[2]) + endrec = startrec; + else if (!strcmp(argv[2], "end")) + endrec = curfile_record_count; + else { + 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, curfile_record_len); + for (recno = startrec; recno <= endrec; recno++) { + rc = update_rec_op(recno, 0x04, record, curfile_record_len); + if (rc < 0) + return(rc); + } + return(0); +}