diff uicc/sws.c @ 61:97646b363eaa

fc-uicc-tool: sws-lookup and sws-auth-* commands ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 23 Mar 2021 06:07:06 +0000
parents simtool/sws.c@c83ec3bd9d67
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uicc/sws.c	Tue Mar 23 06:07:06 2021 +0000
@@ -0,0 +1,94 @@
+/*
+ * This module implements a few high-level commands for working with
+ * Sysmocom webshop SIM cards, using sws-card-db to look up per-card data.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include "../libutil/dbread.h"
+
+static char sws_card_db_file[] = "/opt/freecalypso/sim-data/sws-card-db";
+
+static
+lookup_sws_card(dbs)
+	struct dbread_state *dbs;
+{
+	int rc;
+	char iccid[21];
+
+	rc = retrieve_iccid(iccid);
+	if (rc < 0)
+		return(rc);
+	return dbread_find_record(sws_card_db_file, dbs, "ICCID", iccid);
+}
+
+cmd_sws_lookup(argc, argv, outf)
+	char **argv;
+	FILE *outf;
+{
+	int rc;
+	struct dbread_state dbs;
+	char **kp, *val;
+
+	rc = lookup_sws_card(&dbs);
+	if (rc < 0)
+		return(rc);
+	if (argc == 2) {
+		val = dbread_find_key_req(&dbs, argv[1]);
+		if (!val)
+			return(-1);
+		fprintf(outf, "%s\n", val);
+		return(0);
+	}
+	for (kp = argv + 1; *kp; kp++) {
+		val = dbread_find_key(&dbs, *kp);
+		if (val)
+			fprintf(outf, "%s=%s\n", *kp, val);
+	}
+	return(0);
+}
+
+cmd_sws_auth_adm1()
+{
+	int rc;
+	struct dbread_state dbs;
+	char *pin;
+
+	rc = lookup_sws_card(&dbs);
+	if (rc < 0)
+		return(rc);
+	pin = dbread_find_key_req(&dbs, "ADM1");
+	if (!pin)
+		return(-1);
+	return verify_pin_func(0x0A, pin);
+}
+
+cmd_sws_auth_pin1()
+{
+	int rc;
+	struct dbread_state dbs;
+	char *pin;
+
+	rc = lookup_sws_card(&dbs);
+	if (rc < 0)
+		return(rc);
+	pin = dbread_find_key_req(&dbs, "PIN1");
+	if (!pin)
+		return(-1);
+	return verify_pin_func(0x01, pin);
+}
+
+cmd_sws_auth_pin2()
+{
+	int rc;
+	struct dbread_state dbs;
+	char *pin;
+
+	rc = lookup_sws_card(&dbs);
+	if (rc < 0)
+		return(rc);
+	pin = dbread_find_key_req(&dbs, "PIN2");
+	if (!pin)
+		return(-1);
+	return verify_pin_func(0x81, pin);
+}