# HG changeset patch # User Space Falcon # Date 1432968152 0 # Node ID 5e46679bdb6a0f6a1eeb0804fcd5d5836b33e326 # Parent a5c8f48003cdab2c9bfa3ba26940c771cad6f81f fc-shell skeleton created diff -r a5c8f48003cd -r 5e46679bdb6a .hgignore --- a/.hgignore Fri May 29 06:29:38 2015 +0000 +++ b/.hgignore Sat May 30 06:42:32 2015 +0000 @@ -24,6 +24,7 @@ ^miscutil/fc-serterm$ ^miscutil/imei-luhn$ +^rvinterf/asyncshell/fc-shell$ ^rvinterf/ctracedec/ctracedec$ ^rvinterf/etmsync/fc-fsio$ ^rvinterf/g23sh/g23sh$ diff -r a5c8f48003cd -r 5e46679bdb6a rvinterf/asyncshell/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/asyncshell/Makefile Sat May 30 06:42:32 2015 +0000 @@ -0,0 +1,18 @@ +CC= gcc +CFLAGS= -O2 -I../include +PROG= fc-shell +OBJS= init.o main.o pktsort.o usercmd.o +LIBS= ../libasync/libasync.a ../libg23/libg23.a +INSTBIN=/usr/local/bin + +all: ${PROG} + +${PROG}: ${OBJS} ${LIBS} + ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} + +install: ${PROG} + mkdir -p ${INSTBIN} + install -c ${PROG} ${INSTBIN} + +clean: + rm -f *.o *.out *errs ${PROG} diff -r a5c8f48003cd -r 5e46679bdb6a rvinterf/asyncshell/init.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/asyncshell/init.c Sat May 30 06:42:32 2015 +0000 @@ -0,0 +1,23 @@ +/* + * This module contains the initialization code for fc-shell. + */ + +#include +#include +#include +#include +#include +#include "pktmux.h" +#include "localsock.h" + +extern int sock; + +init() +{ + static u_char want_rvt_lost[9] = {CLI2RVI_WANT_RVTRACE, + 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00}; + + localsock_prep_for_length_rx(); + send_init_command(want_rvt_lost, 9); +} diff -r a5c8f48003cd -r 5e46679bdb6a rvinterf/asyncshell/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/asyncshell/main.c Sat May 30 06:42:32 2015 +0000 @@ -0,0 +1,93 @@ +/* + * This module contains the main() function for fc-shell. + */ + +#include +#include +#include +#include +#include + +char *socket_pathname = "/tmp/rvinterf_socket"; +char *rvinterf_ttyport; +int ttyhacks, dflag; + +int sock; + +extern char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt; + +main(argc, argv) + char **argv; +{ + extern int optind; + extern char *optarg; + int c, sopt = 0; + fd_set fds; + + while ((c = getopt(argc, argv, "B:dl:p:s:w:")) != EOF) + switch (c) { + case 'B': + rvinterf_Bopt = optarg; + continue; + case 'd': + dflag++; + continue; + case 'l': + rvinterf_lopt = optarg; + continue; + case 'p': + rvinterf_ttyport = optarg; + continue; + case 's': + socket_pathname = optarg; + sopt++; + continue; + case 'w': + rvinterf_wopt = optarg; + continue; + case '?': + default: +usage: fprintf(stderr, + "usage: %s [options] [command]\n", argv[0]); + exit(1); + } + if (rvinterf_ttyport) { + if (sopt) { + fprintf(stderr, + "%s error: -p and -s options are mutually exclusive\n", + argv[0]); + exit(1); + } + launch_rvinterf(rvinterf_ttyport); + } else { + if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) { + fprintf(stderr, +"%s error: -B, -l and -w options are meaningful only when launching rvinterf\n", + argv[0]); + exit(1); + } + connect_local_socket(); + } + + ttyhacks = isatty(0) && !dflag; + init(); + tty_init(); + for (;;) { + FD_ZERO(&fds); + FD_SET(0, &fds); + FD_SET(sock, &fds); + c = select(sock+1, &fds, 0, 0, 0); + if (c < 0) { + if (errno == EINTR) + continue; + tty_cleanup(); + perror("select"); + exit(1); + } + if (FD_ISSET(0, &fds)) + handle_tty_input(); + if (FD_ISSET(sock, &fds)) + handle_rvinterf_input(); + fflush(stdout); + } +} diff -r a5c8f48003cd -r 5e46679bdb6a rvinterf/asyncshell/pktsort.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/asyncshell/pktsort.c Sat May 30 06:42:32 2015 +0000 @@ -0,0 +1,80 @@ +/* + * Here we sort out incoming packets from the target relayed via rvinterf. + */ + +#include +#include +#include +#include +#include +#include "pktmux.h" +#include "limits.h" +#include "localsock.h" +#include "localtypes.h" + +extern u_char rvi_msg[]; +extern int rvi_msg_len; + +static void +process_rvt() +{ + u32 useid; + + if (rvi_msg_len < 7) { + tty_cleanup(); + fprintf(stderr, "Error: rvinterf sent us an invalid RVT msg\n"); + exit(1); + } + useid = rvi_msg[2] << 24 | rvi_msg[3] << 16 | rvi_msg[4] << 8 + | rvi_msg[5]; + switch (useid) { + case 0: + handle_useid_0(); + return; + default: + tty_cleanup(); + fprintf(stderr, "unexpected fwd of USEID %08X from rvinterf\n", + useid); + exit(1); + } +} + +void +gpf_packet_rx() +{ + char fmtbuf[MAX_PKT_FROM_TARGET*8]; /* size it generously */ + + format_g23_packet(rvi_msg + 1, rvi_msg_len - 1, fmtbuf); + async_msg_output(fmtbuf); +} + +void +response_from_ati() +{ + char buf[MAX_PKT_FROM_TARGET*4+2]; + + strcpy(buf, "ATI: "); + safe_print_trace(rvi_msg + 2, rvi_msg_len - 2, buf); + async_msg_output(buf); +} + +void +process_pkt_from_target() +{ + switch (rvi_msg[1]) { + case RVT_RV_HEADER: + process_rvt(); + return; + case RVT_L23_HEADER: + gpf_packet_rx(); + return; + case RVT_AT_HEADER: + response_from_ati(); + return; + default: + tty_cleanup(); + fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n", + rvi_msg[1]); + exit(1); + } +} diff -r a5c8f48003cd -r 5e46679bdb6a rvinterf/asyncshell/usercmd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/asyncshell/usercmd.c Sat May 30 06:42:32 2015 +0000 @@ -0,0 +1,51 @@ +/* + * This module implements interactive fc-shell command dispatch. + */ + +#include +#include +#include +#include +#include +#include + +extern char usercmd[]; + +void +cmd_exit() +{ + tty_cleanup(); + exit(0); +} + +static struct cmdtab { + char *cmd; + void (*func)(); +} cmdtab[] = { + {"exit", cmd_exit}, + {"quit", cmd_exit}, + {0, 0} +}; + +void +dispatch_user_cmd() +{ + char *cp, *np; + struct cmdtab *tp; + + for (cp = usercmd; isspace(*cp); cp++) + ; + if (!*cp || *cp == '#') + return; + for (np = cp; *cp && !isspace(*cp); cp++) + ; + if (*cp) + *cp++ = '\0'; + for (tp = cmdtab; tp->cmd; tp++) + if (!strcmp(tp->cmd, np)) + break; + if (tp->func) + tp->func(cp); + else + printf("error: no such command\n"); +}