changeset 301:8dd522a8d60e

fc-fsio: set-imeisv and set-pcm-string added from fc-tmsh
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 02 Mar 2014 02:04:51 +0000
parents 19b846c8abed
children cd5068cf0551
files rvinterf/etmsync/fscmdtab.c rvinterf/etmsync/fsmisc.c
diffstat 2 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/fscmdtab.c	Sun Mar 02 01:32:55 2014 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Sun Mar 02 02:04:51 2014 +0000
@@ -18,6 +18,8 @@
 extern int cmd_ls();
 extern int cmd_mkdir();
 extern int cmd_preformat();
+extern int cmd_set_imeisv();
+extern int cmd_set_pcm_string();
 extern int cmd_stat();
 extern int cmd_uploadfs();
 extern int cmd_upload_file();
@@ -38,6 +40,8 @@
 	{"ls", 1, 1, cmd_ls},
 	{"mkdir", 1, 1, cmd_mkdir},
 	{"preformat", 0, 0, cmd_preformat},
+	{"set-imeisv", 2, 2, cmd_set_imeisv},
+	{"set-pcm-string", 2, 2, cmd_set_pcm_string},
 	{"stat", 1, 1, cmd_stat},
 	{"upload-file", 2, 2, cmd_upload_file},
 	{"upload-fs", 1, 1, cmd_uploadfs},
--- a/rvinterf/etmsync/fsmisc.c	Sun Mar 02 01:32:55 2014 +0000
+++ b/rvinterf/etmsync/fsmisc.c	Sun Mar 02 02:04:51 2014 +0000
@@ -3,6 +3,7 @@
  */
 
 #include <sys/types.h>
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -76,3 +77,67 @@
 	}
 	return(0);
 }
+
+cmd_set_imeisv(argc, argv)
+	char **argv;
+{
+	char *filename, *cp, digits[16];
+	u_char bytes[8];
+	int pcm_order, i;
+
+	if (!strcmp(argv[1], "pcm")) {
+		filename = "/pcm/IMEI";
+		pcm_order = 1;
+	} else if (!strcmp(argv[1], "fc")) {
+		filename = "/etc/IMEISV";
+		pcm_order = 0;
+	} else {
+		fprintf(stderr,
+	"error: IMEISV storage type argument must be \"pcm\" or \"fc\"\n");
+		return(ERROR_USAGE);
+	}
+	cp = argv[2];
+	if (!isdigit(*cp)) {
+inv:		fprintf(stderr,
+			"error: 2nd argument must have 16 decimal digits\n");
+		return(ERROR_USAGE);
+	}
+	for (i = 0; i < 16; i++) {
+		if (ispunct(*cp))
+			cp++;
+		if (!isdigit(*cp))
+			goto inv;
+		digits[i] = *cp++ - '0';
+	}
+	if (*cp)
+		goto inv;
+	for (i = 0; i < 8; i++)
+		bytes[i] = pcm_order ? digits[i*2+1] << 4 | digits[i*2]
+				     : digits[i*2] << 4 | digits[i*2+1];
+	printf("Writing \"%02X %02X %02X %02X %02X %02X %02X %02X\" into %s\n",
+		bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5],
+		bytes[6], bytes[7], filename);
+	return do_short_fwrite(filename, bytes, 8);
+}
+
+cmd_set_pcm_string(argc, argv)
+	char **argv;
+{
+	char filename[16];
+
+	if (strcmp(argv[1], "CGMI") && strcmp(argv[1], "CGMM") &&
+	    strcmp(argv[1], "CGMR") && strcmp(argv[1], "CGSN")) {
+		fprintf(stderr,
+		"error: \"%s\" is not a recognized PCM string file name\n",
+			argv[1]);
+		return(ERROR_USAGE);
+	}
+	sprintf(filename, "/pcm/%s", argv[1]);
+	if (strlen(argv[2]) > 20) {
+		fprintf(stderr,
+			"error: %s string may not exceed 20 characters\n",
+			filename);
+		return(ERROR_USAGE);
+	}
+	return do_short_fwrite(filename, argv[2], strlen(argv[2]));
+}