annotate rvinterf/tmsh/ffs2wr.c @ 263:b5b54feb111a

fc-tmsh: set-imeisv command implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 05 Feb 2014 07:32:42 +0000
parents
children 0c938d8b5ba3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
263
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * In this module we are going to implement some high-level FFS write
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * operations, using the TMFFS2 protocol.
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <ctype.h>
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <stdlib.h>
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "limits.h"
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "localtypes.h"
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "etm.h"
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include "ffs.h"
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #include "tmffs2.h"
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 void
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 cmd_set_imeisv(argc, argv)
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 char **argv;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 char *filename, *cp, digits[16];
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 u_char bytes[8], cmdpkt[MAX_PKT_TO_TARGET], *dp;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 int pcm_order, i;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 if (!strcmp(argv[1], "pcm")) {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 filename = "/pcm/IMEI";
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 pcm_order = 1;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 } else if (!strcmp(argv[1], "fc")) {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 filename = "/etc/IMEISV";
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 pcm_order = 0;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 } else {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 printf(
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 "error: IMEISV storage type argument must be \"pcm\" or \"fc\"\n");
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 return;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 }
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 cp = argv[2];
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 if (!isdigit(*cp)) {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 inv: printf("error: 2nd argument must have 16 decimal digits\n");
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 return;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 }
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 for (i = 0; i < 16; i++) {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 if (ispunct(*cp))
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 cp++;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 if (!isdigit(*cp))
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 goto inv;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 digits[i] = *cp++ - '0';
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 }
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 if (*cp)
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 goto inv;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 for (i = 0; i < 8; i++)
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 bytes[i] = pcm_order ? digits[i*2+1] << 4 | digits[i*2]
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 : digits[i*2] << 4 | digits[i*2+1];
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 printf("Writing \"%02X %02X %02X %02X %02X %02X %02X %02X\" into %s\n",
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5],
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 bytes[6], bytes[7], filename);
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 dp = cmdpkt + 1;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 *dp++ = ETM_FFS2;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 *dp++ = TMFFS_FILE_WRITE;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 *dp++ = strlen(filename) + 1;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 strcpy(dp, filename);
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 dp += strlen(filename) + 1;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 *dp++ = 8; /* data size in bytes */
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 bcopy(bytes, dp, 8);
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 dp += 8;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 *dp++ = FFS_O_CREATE | FFS_O_TRUNC;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 }