view uicc/pbcommon.c @ 158:65a2a96386cd

fc-uicc-tool: hex string parsing with min and max length, matching fc-simtool
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Feb 2021 04:00:27 +0000
parents 0b8a936f4542
children
line wrap: on
line source

/*
 * This module implements the common functions for all phonebook commands.
 */

#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <stdlib.h>
#include "file_id.h"

static struct map {
	char	*user_name;
	char	*canon_name;
	int	file_id;
} phonebook_map[] = {
	{"adn",		"EF_ADN",	EF_ADN},
	{"ADN",		"EF_ADN",	EF_ADN},
	{"EF_ADN",	"EF_ADN",	EF_ADN},
	{"fdn",		"EF_FDN",	EF_FDN},
	{"FDN",		"EF_FDN",	EF_FDN},
	{"EF_FDN",	"EF_FDN",	EF_FDN},
	{"sdn",		"EF_SDN",	EF_SDN},
	{"SDN",		"EF_SDN",	EF_SDN},
	{"EF_SDN",	"EF_SDN",	EF_SDN},
	{"msisdn",	"EF_MSISDN",	EF_MSISDN},
	{"MSISDN",	"EF_MSISDN",	EF_MSISDN},
	{"EF_MSISDN",	"EF_MSISDN",	EF_MSISDN},
	/* table search terminator */
	{0,		0,		-1}
};

phonebook_op_common(reqname, rec_len_ret, rec_count_ret)
	char *reqname;
	unsigned *rec_len_ret, *rec_count_ret;
{
	struct map *tp;
	int rc;

	for (tp = phonebook_map; tp->user_name; tp++)
		if (!strcmp(tp->user_name, reqname))
			break;
	if (!tp->canon_name) {
		fprintf(stderr, "error: phone book name \"%s\" not known\n",
			reqname);
		return(-1);
	}
	rc = select_op(FILEID_MF);
	if (rc < 0)
		return(rc);
	rc = select_op(DF_TELECOM);
	if (rc < 0)
		return(rc);
	rc = select_op(tp->file_id);
	if (rc < 0)
		return(rc);
	rc = select_resp_get_linear_fixed(rec_len_ret, rec_count_ret);
	if (rc < 0)
		return(rc);
	if (rec_len_ret && *rec_len_ret < 14) {
		fprintf(stderr,
	"error: %s has record length of %u bytes, less than minimum 14\n",
			tp->canon_name, *rec_len_ret);
		return(-1);
	}
	return(0);
}