# HG changeset patch # User Michael Spacefalcon # Date 1385276349 0 # Node ID 13a0348ffce448791e286eee837e9a02e7241b4a # Parent 6800c2cc8c51cc58cc6ce3632bb14397f8fc3158 rvinterf/etm: checkpointing not-yet-compilable code diff -r 6800c2cc8c51 -r 13a0348ffce4 rvinterf/etm/etm.h --- a/rvinterf/etm/etm.h Sun Nov 24 02:08:55 2013 +0000 +++ b/rvinterf/etm/etm.h Sun Nov 24 06:59:09 2013 +0000 @@ -2,3 +2,4 @@ * This header file contains various definitions for talking to ETM. */ +#define ETM_USE_ID 0x001E0004 diff -r 6800c2cc8c51 -r 13a0348ffce4 rvinterf/etm/init.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etm/init.c Sun Nov 24 06:59:09 2013 +0000 @@ -0,0 +1,83 @@ +/* + * This module contains the initialization code for fc-tmsh. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "../pktmux.h" +#include "../localsock.h" + +extern char *socket_pathname; +extern int sock; + +connect_local_socket() +{ + /* local socket binding voodoo copied from osmocon */ + struct sockaddr_un local; + unsigned int namelen; + int rc; + + sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock < 0) { + perror("socket(AF_UNIX, SOCK_STREAM, 0)"); + exit(1); + } + + local.sun_family = AF_UNIX; + strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path)); + local.sun_path[sizeof(local.sun_path) - 1] = '\0'; + + /* we use the same magic that X11 uses in Xtranssock.c for + * calculating the proper length of the sockaddr */ +#if defined(BSD44SOCKETS) || defined(__UNIXWARE__) + local.sun_len = strlen(local.sun_path); +#endif +#if defined(BSD44SOCKETS) || defined(SUN_LEN) + namelen = SUN_LEN(&local); +#else + namelen = strlen(local.sun_path) + + offsetof(struct sockaddr_un, sun_path) + 1; +#endif + + rc = connect(sock, (struct sockaddr *) &local, namelen); + if (rc != 0) { + perror(socket_pathname); + exit(1); + } + + return(0); +} + +send_init_command(cmdpkt, cmdlen) + u_char *cmdpkt; +{ + u_char lenbuf[2]; + + lenbuf[0] = 0; + lenbuf[1] = cmdlen; + write(sock, lenbuf, 2); + write(sock, cmdpkt, cmdlen); +} + +init() +{ + static u_char want_rvt_lost[9] = {CLI2RVI_WANT_RVTRACE, + 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00}; + static u_char want_rvt_etm[9] = {CLI2RVI_WANT_RVTRACE, + 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x1E, 0x00, 0x04}; + static u_char want_etm_mux[2] = {CLI2RVI_WANT_MUXPROTO, RVT_TM_HEADER}; + + connect_local_socket(); + localsock_prep_for_length_rx(); + send_init_command(want_rvt_lost, 9); + send_init_command(want_rvt_etm, 9); + send_init_command(want_etm_mux, 2); +} diff -r 6800c2cc8c51 -r 13a0348ffce4 rvinterf/etm/interf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etm/interf.c Sun Nov 24 06:59:09 2013 +0000 @@ -0,0 +1,72 @@ +/* + * This module implements the link to rvinterf. + */ + +#include +#include +#include +#include +#include "../localsock.h" + +extern int sock; + +u_char rvi_msg[LOCALSOCK_MAX_MSG]; +int rvi_msg_len; + +static int rx_state, rx_left; +static u_char *rx_ptr; + +void +localsock_prep_for_length_rx() +{ + rx_state = 0; + rx_ptr = rvi_msg; + rx_left = 2; +} + +static void +prep_for_message_rx() +{ + rx_state = 1; + rx_ptr = rvi_msg; + rx_left = rvi_msg_len; +} + +void +process_msg_from_rvinterf() +{ + + +} + +void +handle_rvinterf_input() +{ + int cc; + + cc = read(sock, rx_ptr, rx_left); + if (cc <= 0) { + tty_cleanup(); + perror("read from rvinterf socket"); + exit(1); + } + rx_ptr += cc; + rx_left -= cc; + if (rx_left) + return; + /* got the thing, process it */ + if (rx_state) { + process_msg_from_rvinterf(); + localsock_prep_for_length_rx(); + } else { + rvi_msg_len = rvi_msg[0] << 8 | rvi_msg[1]; + if (rvi_msg_len < 1 || rvi_msg_len > LOCALSOCK_MAX_MSG) { + tty_cleanup(); + fprintf(stderr, + "Invalid length from rvinterf: %02X%02X\n", + rvi_msg[0], rvi_msg[1]); + exit(1); + } + prep_for_message_rx(); + } +} diff -r 6800c2cc8c51 -r 13a0348ffce4 rvinterf/etm/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etm/main.c Sun Nov 24 06:59:09 2013 +0000 @@ -0,0 +1,56 @@ +/* + * This module contains the main() function for fc-tmsh. + */ + +#include +#include +#include +#include +#include + +char *socket_pathname = "/tmp/rvinterf_socket"; +int ttyhacks, dflag; + +int sock; + +main(argc, argv) + char **argv; +{ + extern char *optarg; + int c; + fd_set fds; + + while ((c = getopt(argc, argv, "ds:")) != EOF) + switch (c) { + case 'd': + dflag++; + continue; + case 's': + socket_pathname = optarg; + continue; + case '?': + default: + exit(1); + } + 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 6800c2cc8c51 -r 13a0348ffce4 rvinterf/etm/ttymagic.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etm/ttymagic.c Sun Nov 24 06:59:09 2013 +0000 @@ -0,0 +1,89 @@ +/* + * This module contains the tty "magic" code for fc-tmsh. + */ + +#include +#include +#include +#include +#include +#include +#include + +extern int ttyhacks; + +struct termios orig_termios, our_termios; + +#define MAX_USER_CMD 78 +char usercmd[MAX_USER_CMD+1]; +int usercmd_len; + +void +tty_init() +{ + if (!ttyhacks) + return; + tcgetattr(0, &orig_termios); + bcopy(&orig_termios, &our_termios, sizeof(struct termios)); + our_termios.c_oflag &= ~(OCRNL | ONOCR | ONLRET); + our_termios.c_lflag &= ~(ICANON | ECHO); + our_termios.c_cc[VMIN] = 1; + our_termios.c_cc[VTIME] = 0; + tcsetattr(0, TCSAFLUSH, &our_termios); + putchar('>'); + fflush(stdout); +} + +void +tty_cleanup() +{ + if (!ttyhacks) + return; + tcsetattr(0, TCSAFLUSH, &orig_termios); +} + +void +handle_tty_input() +{ + char buf[256]; + int i, c, cc; + + cc = read(0, buf, sizeof buf); + if (cc <= 0) { + tty_cleanup(); + exit(0); + } + for (i = 0; i < cc; i++) { + c = buf[i]; + if (c >= ' ' && c <= '~') { + if (usercmd_len >= MAX_USER_CMD) + continue; + usercmd[usercmd_len++] = c; + if (ttyhacks) + putchar(c); /* echo */ + continue; + } + switch (c) { + case '\b': + case 0x7F: + if (!usercmd_len) + continue; + usercmd_len--; + if (ttyhacks) { + putchar('\b'); + putchar(' '); + putchar('\b'); + } + continue; + case '\n': + case '\r': + usercmd[usercmd_len] = '\0'; + if (ttyhacks) + putchar('\n'); /* echo */ + dispatch_user_cmd(); + usercmd_len = 0; + if (ttyhacks) + putchar('>'); /* new prompt */ + } + } +} diff -r 6800c2cc8c51 -r 13a0348ffce4 rvinterf/etm/usercmd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etm/usercmd.c Sun Nov 24 06:59:09 2013 +0000 @@ -0,0 +1,79 @@ +/* + * This module implements fc-tmsh user command dispatch. + */ + +#include +#include +#include +#include +#include +#include + +extern char usercmd[]; + +extern void cmd_etmpkt(); + +void +cmd_exit() +{ + tty_cleanup(); + exit(0); +} + +static struct cmdtab { + char *cmd; + int minargs; + int maxargs; + void (*func)(); +} cmdtab[] = { + {"etmpkt", 1, 253, cmd_etmpkt}, + {"exit", 0, 0, cmd_exit}, + {"quit", 0, 0, cmd_exit}, + {0, 0, 0, 0} +}; + +void +dispatch_user_cmd() +{ + char *argv[257]; + char *cp, **ap; + struct cmdtab *tp; + + for (cp = usercmd; isspace(*cp); cp++) + ; + if (!*cp || *cp == '#') + return; + argv[0] = cp; + while (*cp && !isspace(*cp)) + cp++; + if (*cp) + *cp++ = '\0'; + for (tp = cmdtab; tp->cmd; tp++) + if (!strcmp(tp->cmd, argv[0])) + break; + if (!tp->func) { + printf("error: no such command\n"); + return; + } + for (ap = argv + 1; ; ) { + while (isspace(*cp)) + cp++; + if (!*cp || *cp == '#') + break; + if (ap - argv - 1 >= tp->maxargs) { + printf("error: too many arguments\n"); + return; + } + *ap++ = cp; + while (*cp && !isspace(*cp)) + cp++; + if (*cp) + *cp++ = '\0'; + } + if (ap - argv - 1 < tp->minargs) { + printf("error: too few arguments\n"); + return; + } + *ap = 0; + tp->func(ap - argv, argv); +}