FreeCalypso > hg > freecalypso-sw
view rvinterf/tmsh/ffs2.c @ 260:c146f38d2b5f
rvinterf subdir structure made a little more sensible
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Wed, 05 Feb 2014 04:02:13 +0000 |
parents | rvinterf/etm/ffs2.c@35113b1964d3 |
children | 7f14d7c789a7 |
line wrap: on
line source
/* * In this module we are going to implement TMFFS2 functionality. */ #include <sys/types.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "pktmux.h" #include "limits.h" #include "localtypes.h" #include "etm.h" #include "tmffs2.h" void cmd_ffs2_close(argc, argv) char **argv; { u_char cmdpkt[5]; cmdpkt[1] = ETM_FFS2; cmdpkt[2] = TMFFS_CLOSE; cmdpkt[3] = strtoul(argv[1], 0, 0); send_etm_cmd(cmdpkt, 3); } void cmd_ffs2_delete(argc, argv) char **argv; { u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; int slen; slen = strlen(argv[1]); if (slen >= TMFFS_STRING_SIZE) { printf("error: argument exceeds string length limit\n"); return; } dp = cmdpkt + 1; *dp++ = ETM_FFS2; *dp++ = TMFFS_REMOVE; *dp++ = slen + 1; strcpy(dp, argv[1]); dp += slen + 1; send_etm_cmd(cmdpkt, dp - cmdpkt - 1); } void cmd_ffs2_format(argc, argv) char **argv; { u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; int slen; slen = strlen(argv[1]); if (slen >= TMFFS_STRING_SIZE) { printf("error: argument exceeds string length limit\n"); return; } dp = cmdpkt + 1; *dp++ = ETM_FFS2; *dp++ = TMFFS_FORMAT; *dp++ = slen + 1; strcpy(dp, argv[1]); dp += slen + 1; /* magic is 0x2BAD, 16-bit little-endian */ *dp++ = 0xAD; *dp++ = 0x2B; send_etm_cmd(cmdpkt, dp - cmdpkt - 1); } void cmd_ffs2_open(argc, argv) char **argv; { u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; int slen; slen = strlen(argv[1]); if (slen >= TMFFS_STRING_SIZE) { printf("error: argument exceeds string length limit\n"); return; } dp = cmdpkt + 1; *dp++ = ETM_FFS2; *dp++ = TMFFS_OPEN; *dp++ = slen + 1; strcpy(dp, argv[1]); dp += slen + 1; *dp++ = strtoul(argv[2], 0, 16); send_etm_cmd(cmdpkt, dp - cmdpkt - 1); } void cmd_ffs2_preformat() { u_char cmdpkt[6]; cmdpkt[1] = ETM_FFS2; cmdpkt[2] = TMFFS_PREFORMAT; /* magic is 0xDEAD, 16-bit little-endian */ cmdpkt[3] = 0xAD; cmdpkt[4] = 0xDE; send_etm_cmd(cmdpkt, 4); } void cmd_ffs2_version() { u_char cmdpkt[4]; cmdpkt[1] = ETM_FFS2; cmdpkt[2] = TMFFS_VERSION; send_etm_cmd(cmdpkt, 2); } static struct cmdtab { char *cmd; int minargs; int maxargs; void (*func)(); } ffs2_cmds[] = { {"close", 1, 1, cmd_ffs2_close}, {"delete", 1, 1, cmd_ffs2_delete}, {"format", 1, 1, cmd_ffs2_format}, {"open", 2, 2, cmd_ffs2_open}, {"preformat", 0, 0, cmd_ffs2_preformat}, {"version", 0, 0, cmd_ffs2_version}, {0, 0, 0, 0} }; void cmd_ffs2(argc, argv) char **argv; { struct cmdtab *tp; int extargs; for (tp = ffs2_cmds; tp->cmd; tp++) if (!strcmp(tp->cmd, argv[1])) break; if (!tp->func) { printf("error: no such ffs2 command\n"); return; } extargs = argc - 2; if (extargs > tp->maxargs) { printf("error: too many arguments\n"); return; } if (extargs < tp->minargs) { printf("error: too few arguments\n"); return; } tp->func(argc - 1, argv + 1); }