diff uicc/select.c @ 135:51d6aaa43a7b

fc-uicc-tool: telecom-sum command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 04 Feb 2021 02:55:31 +0000
parents 69628bcfec17
children baf5bd698764
line wrap: on
line diff
--- a/uicc/select.c	Thu Feb 04 02:28:52 2021 +0000
+++ b/uicc/select.c	Thu Feb 04 02:55:31 2021 +0000
@@ -223,3 +223,35 @@
 		*lenp = (tlv[2] << 8) | tlv[3];
 	return(0);
 }
+
+select_resp_get_linear_fixed(rec_len_ret, rec_count_ret)
+	unsigned *rec_len_ret, *rec_count_ret;
+{
+	u_char *tlv;
+	unsigned reclen;
+
+	tlv = extract_select_resp_tag(0x82);
+	if (!tlv)
+		return(-1);
+	if (tlv[1] != 5) {
+bad_file_desc:	fprintf(stderr, "error: file type is not linear fixed EF\n");
+		return(-1);
+	}
+	if (tlv[2] & 0x80)
+		goto bad_file_desc;
+	if ((tlv[2] & 0x38) == 0x38)
+		goto bad_file_desc;
+	if ((tlv[2] & 0x07) != 0x02)
+		goto bad_file_desc;
+	reclen = (tlv[4] << 8) | tlv[5];
+	if (reclen < 1 || reclen > 255) {
+		fprintf(stderr,
+			"error: SELECT response gives invalid record length\n");
+		return(-1);
+	}
+	if (rec_len_ret)
+		*rec_len_ret = reclen;
+	if (rec_count_ret)
+		*rec_count_ret = tlv[6];
+	return(0);
+}