view utils/sws-card-lookup.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 fa81221ac9b6
children
line wrap: on
line source

/*
 * This program is a simple command line utility for looking up a card
 * in sws-card-db (database generated with sws-email2db) by either
 * ICCID or IMSI and retrieving other associated database fields.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "../libutil/dbread.h"

static char sws_card_db_file[] = "/opt/freecalypso/sim-data/sws-card-db";

static char *match_key, match_value[20];
static struct dbread_state dbs;

static void
preen_iccid(arg)
	char *arg;
{
	u_char nibbles[19];

	if (parse_decimal_shorthand(arg, nibbles, 19) < 0)
		exit(1);	/* error msg already printed */
	if (nibbles[18] != compute_iccid_luhn(nibbles)) {
		fprintf(stderr, "error: Luhn check digit mismatch\n");
		exit(1);
	}
	nibbles_to_ascii(nibbles, 19, match_value);
}

static void
preen_imsi(arg)
	char *arg;
{
	u_char nibbles[15];

	if (parse_decimal_shorthand(arg, nibbles, 15) < 0)
		exit(1);	/* error msg already printed */
	nibbles_to_ascii(nibbles, 15, match_value);
}

static void
lookup_one_key(key)
	char *key;
{
	char *val;

	val = dbread_find_key_req(&dbs, key);
	if (!val)
		exit(1);	/* error msg already printed */
	puts(val);
}

static void
lookup_mult_keys(keys)
	char **keys;
{
	char *key, *val;

	for (; *keys; keys++) {
		key = *keys;
		val = dbread_find_key(&dbs, key);
		if (val)
			printf("%s=%s\n", key, val);
	}
}

main(argc, argv)
	char **argv;
{
	int rc;

	if (argc < 4) {
		fprintf(stderr,
			"usage: %s {iccid|imsi} card-number retrieve-key\n",
			argv[0]);
		exit(1);
	}
	match_key = argv[1];
	if (!strcmp(match_key, "iccid"))
		preen_iccid(argv[2]);
	else if (!strcmp(match_key, "imsi"))
		preen_imsi(argv[2]);
	else {
		fprintf(stderr, "error: look-up key must be iccid or imsi\n");
		exit(1);
	}
	rc = dbread_find_record(sws_card_db_file, &dbs, match_key, match_value);
	if (rc < 0)
		exit(1);	/* error msg already printed */
	if (argc == 4)
		lookup_one_key(argv[3]);
	else
		lookup_mult_keys(argv + 3);
	exit(0);
}