FreeCalypso > hg > freecalypso-sw
comparison rvinterf/etmsync/fsmisc.c @ 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 | 091ebd46a9cc |
comparison
equal
deleted
inserted
replaced
300:19b846c8abed | 301:8dd522a8d60e |
---|---|
1 /* | 1 /* |
2 * Miscellaneous (dangerous!) FFS2 operations | 2 * Miscellaneous (dangerous!) FFS2 operations |
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <ctype.h> | |
6 #include <stdio.h> | 7 #include <stdio.h> |
7 #include <stdlib.h> | 8 #include <stdlib.h> |
8 #include <string.h> | 9 #include <string.h> |
9 #include <strings.h> | 10 #include <strings.h> |
10 #include "etm.h" | 11 #include "etm.h" |
74 report_ffs_err("preformat", rvi_msg[3]); | 75 report_ffs_err("preformat", rvi_msg[3]); |
75 return(ERROR_TARGET); | 76 return(ERROR_TARGET); |
76 } | 77 } |
77 return(0); | 78 return(0); |
78 } | 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 } |