annotate rvinterf/tmsh/ffs2wr.c @ 635:658a83ff7221

gsm-fw/sysglue/flashboot.S: buglet in the previous change
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 01 Sep 2014 18:45:37 +0000
parents 0c938d8b5ba3
children
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
264
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
19 send_file_write(filename, data, size)
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
20 char *filename;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
21 u_char *data;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
22 {
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
23 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
24
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
25 dp = cmdpkt + 1;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
26 *dp++ = ETM_FFS2;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
27 *dp++ = TMFFS_FILE_WRITE;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
28 *dp++ = strlen(filename) + 1;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
29 strcpy(dp, filename);
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
30 dp += strlen(filename) + 1;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
31 *dp++ = size; /* data size in bytes */
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
32 bcopy(data, dp, size);
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
33 dp += size;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
34 *dp++ = FFS_O_CREATE | FFS_O_TRUNC;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
35 send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
36 }
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
37
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
38 void
263
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 cmd_set_imeisv(argc, argv)
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 char **argv;
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 char *filename, *cp, digits[16];
264
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
43 u_char bytes[8];
263
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 int pcm_order, i;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 if (!strcmp(argv[1], "pcm")) {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 filename = "/pcm/IMEI";
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 pcm_order = 1;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 } else if (!strcmp(argv[1], "fc")) {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 filename = "/etc/IMEISV";
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 pcm_order = 0;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 } else {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 printf(
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 "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
55 return;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 }
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 cp = argv[2];
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 if (!isdigit(*cp)) {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 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
60 return;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 }
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 for (i = 0; i < 16; i++) {
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 if (ispunct(*cp))
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 cp++;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 if (!isdigit(*cp))
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 goto inv;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 digits[i] = *cp++ - '0';
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 }
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 if (*cp)
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 goto inv;
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 for (i = 0; i < 8; i++)
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 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
73 : digits[i*2] << 4 | digits[i*2+1];
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 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
75 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
76 bytes[6], bytes[7], filename);
264
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
77 send_file_write(filename, bytes, 8);
263
b5b54feb111a fc-tmsh: set-imeisv command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 }
264
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
79
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
80 void
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
81 cmd_set_pcm_string(argc, argv)
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
82 char **argv;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
83 {
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
84 char filename[16];
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
85
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
86 if (strcmp(argv[1], "CGMI") && strcmp(argv[1], "CGMM") &&
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
87 strcmp(argv[1], "CGMR") && strcmp(argv[1], "CGSN")) {
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
88 printf("error: \"%s\" is not a recognized PCM string file name\n",
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
89 argv[1]);
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
90 return;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
91 }
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
92 sprintf(filename, "/pcm/%s", argv[1]);
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
93 if (strlen(argv[2]) > 20) {
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
94 printf("error: %s string may not exceed 20 characters\n",
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
95 filename);
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
96 return;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
97 }
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
98 send_file_write(filename, argv[2], strlen(argv[2]));
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
99 }
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
100
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
101 void
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
102 cmd_set_rfcap(argc, argv)
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
103 char **argv;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
104 {
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
105 u_char bytes[16];
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
106 int i;
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
107
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
108 for (i = 0; i < 16; i++)
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
109 bytes[i] = strtoul(argv[i+1], 0, 16);
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
110 send_file_write("/gsm/com/rfcap", bytes, 16);
0c938d8b5ba3 fc-tmsh: set-pcm-string and set-rfcap implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 263
diff changeset
111 }