view uicc/hlread.c @ 33:8a4f3d00d997

more refactoring of (select reader by number) logic
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 17:28:05 +0000
parents 1b1468869ccf
children d4b5a6e547ca
line wrap: on
line source

/*
 * This module implements some high-level or user-friendly read commands.
 */

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

cmd_iccid()
{
	int rc;
	unsigned len;
	char buf[21];

	rc = select_op(FILEID_MF);
	if (rc < 0)
		return(rc);
	rc = select_op(EF_ICCID);
	if (rc < 0)
		return(rc);
	rc = select_resp_get_transparent(&len);
	if (rc < 0)
		return(rc);
	if (len != 10) {
		fprintf(stderr, "error: expected transparent EF of 10 bytes\n");
		return(-1);
	}
	rc = readbin_op(0, 10);
	if (rc < 0)
		return(rc);
	decode_reversed_nibbles(sim_resp_data, 10, buf);
	buf[20] = '\0';
	printf("%s\n", buf);
	return(0);
}