view rvinterf/tmsh/ffs2wr.c @ 575:1d7a12925b8e

gsm-fw/L1/cfile: iramcode.o and xipcode.o built
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 11 Aug 2014 03:59:26 +0000
parents 0c938d8b5ba3
children
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
send_file_write(filename, data, size)
	char *filename;
	u_char *data;
{
	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;

	dp = cmdpkt + 1;
	*dp++ = ETM_FFS2;
	*dp++ = TMFFS_FILE_WRITE;
	*dp++ = strlen(filename) + 1;
	strcpy(dp, filename);
	dp += strlen(filename) + 1;
	*dp++ = size;		/* data size in bytes */
	bcopy(data, dp, size);
	dp += size;
	*dp++ = FFS_O_CREATE | FFS_O_TRUNC;
	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
}

void
cmd_set_imeisv(argc, argv)
	char **argv;
{
	char *filename, *cp, digits[16];
	u_char bytes[8];
	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);
	send_file_write(filename, bytes, 8);
}

void
cmd_set_pcm_string(argc, argv)
	char **argv;
{
	char filename[16];

	if (strcmp(argv[1], "CGMI") && strcmp(argv[1], "CGMM") &&
	    strcmp(argv[1], "CGMR") && strcmp(argv[1], "CGSN")) {
	      printf("error: \"%s\" is not a recognized PCM string file name\n",
			argv[1]);
		return;
	}
	sprintf(filename, "/pcm/%s", argv[1]);
	if (strlen(argv[2]) > 20) {
		printf("error: %s string may not exceed 20 characters\n",
			filename);
		return;
	}
	send_file_write(filename, argv[2], strlen(argv[2]));
}

void
cmd_set_rfcap(argc, argv)
	char **argv;
{
	u_char bytes[16];
	int i;

	for (i = 0; i < 16; i++)
		bytes[i] = strtoul(argv[i+1], 0, 16);
	send_file_write("/gsm/com/rfcap", bytes, 16);
}