changeset 916:8e1c55cf7989

fc-getpirimei implemented, compiles
author Space Falcon <falcon@ivan.Harhan.ORG>
date Tue, 08 Sep 2015 18:59:29 +0000
parents 7b805007dcfc
children 9b4b0fcddc77
files .hgignore rvinterf/etmsync/Makefile rvinterf/etmsync/pirimei.c rvinterf/etmsync/pirimeimain.c rvinterf/etmsync/simplemain.c
diffstat 5 files changed, 121 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Tue Sep 08 18:26:42 2015 +0000
+++ b/.hgignore	Tue Sep 08 18:59:29 2015 +0000
@@ -29,6 +29,7 @@
 ^rvinterf/asyncshell/fc-shell$
 ^rvinterf/ctracedec/ctracedec$
 ^rvinterf/etmsync/fc-fsio$
+^rvinterf/etmsync/fc-getpirimei$
 ^rvinterf/g23sh/g23sh$
 ^rvinterf/lowlevel/rvinterf$
 ^rvinterf/lowlevel/rvtdump$
--- a/rvinterf/etmsync/Makefile	Tue Sep 08 18:26:42 2015 +0000
+++ b/rvinterf/etmsync/Makefile	Tue Sep 08 18:59:29 2015 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2 -I../include
-PROGS=	fc-fsio
+PROGS=	fc-fsio fc-getpirimei
 INSTBIN=/usr/local/bin
 
 FSIO_OBJS=	connect.o dispatch.o fdcmd.o fileio.o fsbasics.o fscmdtab.o \
@@ -8,11 +8,17 @@
 		fswrite.o interf.o launchrvif.o memcmd.o memops.o rfcap.o \
 		stddirs.o symlink.o
 
+PIRIMEI_OBJS=	connect.o interf.o launchrvif.o memops.o pirimei.o \
+		pirimeimain.o simplemain.o
+
 all:	${PROGS}
 
 fc-fsio:	${FSIO_OBJS}
 	${CC} ${CFLAGS} -o $@ ${FSIO_OBJS}
 
+fc-getpirimei:	${PIRIMEI_OBJS}
+	${CC} ${CFLAGS} -o $@ ${PIRIMEI_OBJS} -lcrypto
+
 install:	${PROGS}
 	mkdir -p ${INSTBIN}
 	install -c ${PROGS} ${INSTBIN}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/pirimei.c	Tue Sep 08 18:59:29 2015 +0000
@@ -0,0 +1,44 @@
+/*
+ * Reading and decryption of Pirelli's factory IMEI record
+ */
+
+#include <sys/types.h>
+#include <openssl/des.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "exitcodes.h"
+
+u_char pirelli_imeisv[8];
+
+get_pirelli_imei()
+{
+	DES_cblock ciphertext[2], dieid_key, decrypted[2];
+	DES_key_schedule keysched;
+	int rc;
+	static char failmsg[] =
+	"decryption failed: no valid IMEI record or incompatible firmware\n";
+
+	printf("Requesting Calypso die ID\n");
+	rc = do_dieid_read(dieid_key);
+	if (rc)
+		return(rc);
+	printf("Reading IMEI record in Pirelli's factory data block\n");
+	rc = do_memory_read(0x027F0504, ciphertext, 16);
+	if (rc)
+		return(rc);
+	DES_set_key_unchecked(&dieid_key, &keysched);
+	DES_ecb_encrypt(&ciphertext[0], &decrypted[0], &keysched, DES_DECRYPT);
+	DES_ecb_encrypt(&ciphertext[1], &decrypted[1], &keysched, DES_DECRYPT);
+	if (bcmp(decrypted[1], dieid_key, 8)) {
+		printf(failmsg);
+		return(ERROR_TARGET);
+	}
+	bcopy(decrypted[1], pirelli_imeisv, 8);
+	printf("Factory IMEISV is %02X%02X%02X%02X-%02X%02X%02X-%02X\n",
+		pirelli_imeisv[0], pirelli_imeisv[1], pirelli_imeisv[2],
+		pirelli_imeisv[3], pirelli_imeisv[4], pirelli_imeisv[5],
+		pirelli_imeisv[6], pirelli_imeisv[7]);
+	return(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/pirimeimain.c	Tue Sep 08 18:59:29 2015 +0000
@@ -0,0 +1,6 @@
+/* just a rather silly wrapper */
+
+single_op_main()
+{
+	return get_pirelli_imei();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/simplemain.c	Tue Sep 08 18:59:29 2015 +0000
@@ -0,0 +1,63 @@
+/*
+ * This module contains the main() function for simple etmsync programs
+ * that execute a single operation without a command dispatcher.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "exitcodes.h"
+
+extern char *socket_pathname;
+extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
+
+main(argc, argv)
+	char **argv;
+{
+	extern int optind;
+	extern char *optarg;
+	int c, sopt = 0;
+
+	while ((c = getopt(argc, argv, "B:l:p:s:w:")) != EOF)
+		switch (c) {
+		case 'B':
+			rvinterf_Bopt = optarg;
+			continue;
+		case 'l':
+			rvinterf_lopt = optarg;
+			continue;
+		case 'p':
+			rvinterf_ttyport = optarg;
+			continue;
+		case 's':
+			socket_pathname = optarg;
+			sopt++;
+			continue;
+		case 'w':
+			rvinterf_wopt = optarg;
+			continue;
+		case '?':
+		default:
+			/* error msg already printed */
+			exit(ERROR_USAGE);
+		}
+	if (rvinterf_ttyport) {
+		if (sopt) {
+			fprintf(stderr,
+			"%s error: -p and -s options are mutually exclusive\n",
+				argv[0]);
+			exit(ERROR_USAGE);
+		}
+		launch_rvinterf();
+	} else {
+		if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
+			fprintf(stderr,
+"%s error: -B, -l and -w options are meaningful only when launching rvinterf\n",
+				argv[0]);
+			exit(ERROR_USAGE);
+		}
+		connect_local_socket();
+	}
+
+	return single_op_main(argc - optind, argv + optind);
+}