view gen/ota-set-msisdn.c @ 9:b6331ae4eea9

Note-about-padding added
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 Feb 2021 02:19:43 +0000
parents a33d4d8079d2
children
line wrap: on
line source

/*
 * This program generates the OTA RFM payload (to be fed to ota-smswrap-*
 * tools) for programming the MSISDN record.
 */

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

main(argc, argv)
	char **argv;
{
	int rc;
	u_char record[80], *fixp;
	unsigned record_len, n;

	if (argc < 3 || argc > 4) {
		fprintf(stderr,
			"usage: %s record-len phone-number [alpha-tag]\n",
			argv[0]);
		exit(1);
	}
	record_len = strtoul(argv[1], 0, 0);
	if (record_len < 14 || record_len > 80) {
		fprintf(stderr,
		"error: specified MSISDN record length is out of range\n");
		exit(1);
	}
	memset(record, 0xFF, record_len);
	fixp = record + record_len - 14;
	rc = encode_phone_number_arg(argv[2], fixp, 0);
	if (rc < 0)
		exit(1);	/* error msg already printed */
	if (argv[3]) {
		rc = qstring_arg_to_gsm7(argv[3], record, record_len - 14);
		if (rc < 0)
			exit(1);	/* error msg already printed */
	}
	/* emit output */
	printf("A0A40000023F00\n");	/* SELECT MF */
	printf("A0A40000027F10\n");	/* SELECT DF_TELECOM */
	printf("A0A40000026F40\n");	/* SELECT EF_MSISDN */
	printf("A0DC0104%02X\n", record_len);	/* UPDATE RECORD */
	for (n = 0; n < record_len; n++)
		printf("%02X", record[n]);
	putchar('\n');
	exit(0);
}