comparison rvinterf/etmsync/fsmisc.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 869ce9f61a67
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * Miscellaneous (dangerous!) FFS2 operations
3 */
4
5 #include <sys/types.h>
6 #include <ctype.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <strings.h>
11 #include "etm.h"
12 #include "ffs.h"
13 #include "tmffs2.h"
14 #include "limits.h"
15 #include "ffslimits.h"
16 #include "localtypes.h"
17 #include "localstruct.h"
18 #include "exitcodes.h"
19
20 extern u_char rvi_msg[];
21 extern int rvi_msg_len;
22
23 cmd_format(argc, argv)
24 char **argv;
25 {
26 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
27 int rc, slen;
28
29 slen = strlen(argv[1]);
30 if (slen >= TMFFS_STRING_SIZE) {
31 printf("error: argument exceeds string length limit\n");
32 return;
33 }
34 dp = cmdpkt + 1;
35 *dp++ = ETM_FFS2;
36 *dp++ = TMFFS_FORMAT;
37 *dp++ = slen + 1;
38 strcpy(dp, argv[1]);
39 dp += slen + 1;
40 /* magic is 0x2BAD, 16-bit little-endian */
41 *dp++ = 0xAD;
42 *dp++ = 0x2B;
43 rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
44 if (rc)
45 return(rc);
46 if (rvi_msg_len != 5) {
47 printf("error: TMFFS_FORMAT response has wrong length\n");
48 return(ERROR_TARGET);
49 }
50 if (rvi_msg[3]) {
51 report_ffs_err("format", rvi_msg[3]);
52 return(ERROR_TARGET);
53 }
54 return(0);
55 }
56
57 cmd_preformat()
58 {
59 u_char cmdpkt[6];
60 int rc;
61
62 cmdpkt[1] = ETM_FFS2;
63 cmdpkt[2] = TMFFS_PREFORMAT;
64 /* magic is 0xDEAD, 16-bit little-endian */
65 cmdpkt[3] = 0xAD;
66 cmdpkt[4] = 0xDE;
67 rc = etm_pkt_exch(cmdpkt, 4);
68 if (rc)
69 return(rc);
70 if (rvi_msg_len != 5) {
71 printf("error: TMFFS_PREFORMAT response has wrong length\n");
72 return(ERROR_TARGET);
73 }
74 if (rvi_msg[3]) {
75 report_ffs_err("preformat", rvi_msg[3]);
76 return(ERROR_TARGET);
77 }
78 return(0);
79 }
80
81 cmd_set_imeisv(argc, argv)
82 char **argv;
83 {
84 char *filename, *cp, digits[16];
85 u_char bytes[8];
86 int pcm_order, i;
87
88 if (!strcmp(argv[1], "pcm")) {
89 filename = "/pcm/IMEI";
90 pcm_order = 1;
91 } else if (!strcmp(argv[1], "fc")) {
92 filename = "/etc/IMEISV";
93 pcm_order = 0;
94 } else {
95 fprintf(stderr,
96 "error: IMEISV storage type argument must be \"pcm\" or \"fc\"\n");
97 return(ERROR_USAGE);
98 }
99 cp = argv[2];
100 if (!isdigit(*cp)) {
101 inv: fprintf(stderr,
102 "error: 2nd argument must have 16 decimal digits\n");
103 return(ERROR_USAGE);
104 }
105 for (i = 0; i < 16; i++) {
106 if (ispunct(*cp))
107 cp++;
108 if (!isdigit(*cp))
109 goto inv;
110 digits[i] = *cp++ - '0';
111 }
112 if (*cp)
113 goto inv;
114 for (i = 0; i < 8; i++)
115 bytes[i] = pcm_order ? digits[i*2+1] << 4 | digits[i*2]
116 : digits[i*2] << 4 | digits[i*2+1];
117 printf("Writing \"%02X %02X %02X %02X %02X %02X %02X %02X\" into %s\n",
118 bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5],
119 bytes[6], bytes[7], filename);
120 return do_short_fwrite(filename, bytes, 8);
121 }
122
123 cmd_set_pcm_string(argc, argv)
124 char **argv;
125 {
126 char filename[16];
127
128 if (strcmp(argv[1], "CGMI") && strcmp(argv[1], "CGMM") &&
129 strcmp(argv[1], "CGMR") && strcmp(argv[1], "CGSN")) {
130 fprintf(stderr,
131 "error: \"%s\" is not a recognized PCM string file name\n",
132 argv[1]);
133 return(ERROR_USAGE);
134 }
135 sprintf(filename, "/pcm/%s", argv[1]);
136 if (strlen(argv[2]) > 20) {
137 fprintf(stderr,
138 "error: %s string may not exceed 20 characters\n",
139 filename);
140 return(ERROR_USAGE);
141 }
142 return do_short_fwrite(filename, argv[2], strlen(argv[2]));
143 }
144
145 cmd_set_rfcap(argc, argv)
146 char **argv;
147 {
148 return set_rfcap(argv[1]);
149 }