FreeCalypso > hg > freecalypso-sw
view 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 |
line wrap: on
line source
/* * In this module we are going to implement some high-level FFS write * operations, using the TMFFS2 protocol. */ #include <sys/types.h> #include <ctype.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "limits.h" #include "localtypes.h" #include "etm.h" #include "ffs.h" #include "tmffs2.h" void cmd_set_imeisv(argc, argv) char **argv; { char *filename, *cp, digits[16]; u_char bytes[8], cmdpkt[MAX_PKT_TO_TARGET], *dp; int pcm_order, i; if (!strcmp(argv[1], "pcm")) { filename = "/pcm/IMEI"; pcm_order = 1; } else if (!strcmp(argv[1], "fc")) { filename = "/etc/IMEISV"; pcm_order = 0; } else { printf( "error: IMEISV storage type argument must be \"pcm\" or \"fc\"\n"); return; } cp = argv[2]; if (!isdigit(*cp)) { inv: printf("error: 2nd argument must have 16 decimal digits\n"); return; } for (i = 0; i < 16; i++) { if (ispunct(*cp)) cp++; if (!isdigit(*cp)) goto inv; digits[i] = *cp++ - '0'; } if (*cp) goto inv; for (i = 0; i < 8; i++) bytes[i] = pcm_order ? digits[i*2+1] << 4 | digits[i*2] : digits[i*2] << 4 | digits[i*2+1]; printf("Writing \"%02X %02X %02X %02X %02X %02X %02X %02X\" into %s\n", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], filename); dp = cmdpkt + 1; *dp++ = ETM_FFS2; *dp++ = TMFFS_FILE_WRITE; *dp++ = strlen(filename) + 1; strcpy(dp, filename); dp += strlen(filename) + 1; *dp++ = 8; /* data size in bytes */ bcopy(bytes, dp, 8); dp += 8; *dp++ = FFS_O_CREATE | FFS_O_TRUNC; send_etm_cmd(cmdpkt, dp - cmdpkt - 1); }