diff uicc/pbcommon.c @ 136:a21d348e01db

fc-uicc-tool: pb-dump command ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 04 Feb 2021 03:40:55 +0000
parents
children 0b8a936f4542
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uicc/pbcommon.c	Thu Feb 04 03:40:55 2021 +0000
@@ -0,0 +1,63 @@
+/*
+ * 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(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);
+}