view libcommon/dumpdirfunc.c @ 99:97ba63d9361a

scripts/fcsim1-sst: turn off STK & OTA services In the initial unprogrammed state of the cards from Grcard, SST has services 25 through 29 set to allocated and activated. However, these cards appear to not actually support OTA, ENVELOPE commands do nothing (just return SW 9000), and they were never observed issuing any proactive SIM commands, even after a feature-generous TERMINAL PROFILE. Therefore, let's list these STK & OTA services as allocated, but not activated in our FCSIM1 SST.
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 05 May 2021 04:26:07 +0000
parents c9ef9e91dd8e
children
line wrap: on
line source

/*
 * This module implements the common function for dumping EF_DIR.
 */

#include <sys/types.h>
#include <stdio.h>
#include "simresp.h"

static void
dump_aid(tlv, outf)
	u_char *tlv;
	FILE *outf;
{
	unsigned reclen, n;

	reclen = tlv[1];
	fputs(" AID:", outf);
	for (n = 0; n < reclen; n++)
		fprintf(outf, " %02X", tlv[n+2]);
	putc('\n', outf);
}

static void
dump_label(tlv, outf)
	u_char *tlv;
	FILE *outf;
{
	int rc;
	unsigned textlen;

	fputs(" Label: ", outf);
	rc = validate_alpha_field(tlv + 2, tlv[1], &textlen);
	if (rc < 0) {
		fputs("malformed\n", outf);
		return;
	}
	print_alpha_field(tlv + 2, textlen, outf);
	putc('\n', outf);
}

static void
dump_unknown_tlv(tlv, outf)
	u_char *tlv;
	FILE *outf;
{
	unsigned reclen, n;

	reclen = tlv[1] + 2;
	fputs(" TLV:", outf);
	for (n = 0; n < reclen; n++)
		fprintf(outf, " %02X", tlv[n]);
	putc('\n', outf);
}

void
dump_efdir_record(outf)
	FILE *outf;
{
	unsigned totlen, reclen;
	u_char *dp, *endp;

	if (sim_resp_data[0] != 0x61) {
		fprintf(outf, " bad: first byte != 0x61\n");
		return;
	}
	totlen = sim_resp_data[1];
	if (totlen < 3 || totlen > 0x7F) {
		fprintf(outf, " bad: global length byte 0x%02X is invalid\n",
			totlen);
		return;
	}
	if (totlen + 2 > sim_resp_data_len) {
		fprintf(outf,
			" bad: TLV global length exceeds EF record length\n");
		return;
	}
	dp = sim_resp_data + 2;
	endp = sim_resp_data + 2 + totlen;
	while (dp < endp) {
		if (endp - dp < 2) {
trunc_error:		fprintf(outf, " bad: truncated TLV record\n");
			return;
		}
		if ((dp[0] & 0x1F) == 0x1F) {
			fprintf(outf, " bad: extended tag not supported\n");
			return;
		}
		if (dp[1] & 0x80) {
			fprintf(outf, " bad: extended length not supported\n");
			return;
		}
		reclen = dp[1] + 2;
		if (endp - dp < reclen)
			goto trunc_error;
		switch (dp[0]) {
		case 0x4F:
			dump_aid(dp, outf);
			break;
		case 0x50:
			dump_label(dp, outf);
			break;
		default:
			dump_unknown_tlv(dp, outf);
		}
		dp += reclen;
	}
}