view simtool/pberase.c @ 19:72a24b8538eb

meaty function of pb-dump moved back into simtool, out of libcommon Upon further reflection, I am not going to keep any of the pb-* commands in the new version of fc-uicc-tool: they are logically incorrect for UICC/USIM anyway, as they access phonebook files via old classic SIM paths, rather than their USIM paths. OTOH, I am going to implement new SMSP commands in fc-simtool, and I do not plan to replicate them in fc-uicc-tool either. Guts of fc-simtool pb-dump belong in simtool/pbdump.c, not in libcommon, just like the guts of the future smsp-dump command will belong in its own respective implementation module.
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 03:33:26 +0000
parents c34ecbbdf05e
children 10030acba82f
line wrap: on
line source

/*
 * This module implements the pb-erase family of commands.
 */

#include <sys/types.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <stdlib.h>
#include "simresp.h"
#include "curfile.h"

cmd_pb_erase(argc, argv)
	char **argv;
{
	int rc;
	unsigned recno;
	u_char record[255];

	rc = phonebook_op_common(argv[1]);
	if (rc < 0)
		return(rc);
	memset(record, 0xFF, curfile_record_len);
	for (recno = 1; recno <= curfile_record_count; recno++) {
		rc = update_rec_op(recno, 0x04, record, curfile_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];

	rc = phonebook_op_common(argv[1]);
	if (rc < 0)
		return(rc);
	recno = strtoul(argv[2], 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);
	return update_rec_op(recno, 0x04, record, curfile_record_len);
}

cmd_pb_erase_range(argc, argv)
	char **argv;
{
	int rc;
	unsigned recno, startrec, endrec;
	u_char record[255];

	rc = phonebook_op_common(argv[1]);
	if (rc < 0)
		return(rc);
	startrec = strtoul(argv[2], 0, 0);
	if (startrec < 1 || startrec > curfile_record_count) {
		fprintf(stderr,
			"error: specified starting record number is invalid\n");
		return(-1);
	}
	endrec = strtoul(argv[3], 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);
}