FreeCalypso > hg > freecalypso-sw
comparison 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 |
comparison
equal
deleted
inserted
replaced
262:577291a2ad76 | 263:b5b54feb111a |
---|---|
1 /* | |
2 * In this module we are going to implement some high-level FFS write | |
3 * operations, using the TMFFS2 protocol. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <ctype.h> | |
8 #include <stdio.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <stdlib.h> | |
12 #include "limits.h" | |
13 #include "localtypes.h" | |
14 #include "etm.h" | |
15 #include "ffs.h" | |
16 #include "tmffs2.h" | |
17 | |
18 void | |
19 cmd_set_imeisv(argc, argv) | |
20 char **argv; | |
21 { | |
22 char *filename, *cp, digits[16]; | |
23 u_char bytes[8], cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
24 int pcm_order, i; | |
25 | |
26 if (!strcmp(argv[1], "pcm")) { | |
27 filename = "/pcm/IMEI"; | |
28 pcm_order = 1; | |
29 } else if (!strcmp(argv[1], "fc")) { | |
30 filename = "/etc/IMEISV"; | |
31 pcm_order = 0; | |
32 } else { | |
33 printf( | |
34 "error: IMEISV storage type argument must be \"pcm\" or \"fc\"\n"); | |
35 return; | |
36 } | |
37 cp = argv[2]; | |
38 if (!isdigit(*cp)) { | |
39 inv: printf("error: 2nd argument must have 16 decimal digits\n"); | |
40 return; | |
41 } | |
42 for (i = 0; i < 16; i++) { | |
43 if (ispunct(*cp)) | |
44 cp++; | |
45 if (!isdigit(*cp)) | |
46 goto inv; | |
47 digits[i] = *cp++ - '0'; | |
48 } | |
49 if (*cp) | |
50 goto inv; | |
51 for (i = 0; i < 8; i++) | |
52 bytes[i] = pcm_order ? digits[i*2+1] << 4 | digits[i*2] | |
53 : digits[i*2] << 4 | digits[i*2+1]; | |
54 printf("Writing \"%02X %02X %02X %02X %02X %02X %02X %02X\" into %s\n", | |
55 bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], | |
56 bytes[6], bytes[7], filename); | |
57 dp = cmdpkt + 1; | |
58 *dp++ = ETM_FFS2; | |
59 *dp++ = TMFFS_FILE_WRITE; | |
60 *dp++ = strlen(filename) + 1; | |
61 strcpy(dp, filename); | |
62 dp += strlen(filename) + 1; | |
63 *dp++ = 8; /* data size in bytes */ | |
64 bcopy(bytes, dp, 8); | |
65 dp += 8; | |
66 *dp++ = FFS_O_CREATE | FFS_O_TRUNC; | |
67 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
68 } |