From 4b3dcc20d051ab03ca774daf9e29143c2c4d65a4 Mon Sep 17 00:00:00 2001 From: Chris Osborn Date: Wed, 25 May 2016 08:05:41 -0700 Subject: [PATCH] Send terminal speed over telnet. --- src/bridge.c | 7 +++--- src/nvt.c | 43 ++++++++++++++++++++++++++------- src/nvt.h | 68 +++++++++++++++++++++++++++------------------------- 3 files changed, 75 insertions(+), 43 deletions(-) diff --git a/src/bridge.c b/src/bridge.c index 2535c91..4687843 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -78,14 +78,15 @@ int parse_ip_data(modem_config *cfg, char *data, int len) case NVT_DONT: /// again, overflow issues... LOG(LOG_INFO, "Parsing nvt command"); - parse_nvt_command(cfg->line_data.fd, &cfg->line_data.nvt_data, ch, data[i + 2]); + parse_nvt_command(cfg->line_data.fd, &cfg->line_data.nvt_data, ch, + data[i + 2], cfg->parity); i += 3; break; case NVT_SB: // sub negotiation // again, overflow... i += - parse_nvt_subcommand(cfg->line_data.fd, &cfg->line_data.nvt_data, data + i, - len - i); + parse_nvt_subcommand(cfg->line_data.fd, &cfg->line_data.nvt_data, + data + i, len - i, cfg->dce_speed); break; case NVT_IAC: if (cfg->line_data.nvt_data.binary_recv) diff --git a/src/nvt.c b/src/nvt.c index 8540efe..bcf319a 100644 --- a/src/nvt.c +++ b/src/nvt.c @@ -53,10 +53,10 @@ char get_nvt_cmd_response(char action, char type) return rc; } -int parse_nvt_subcommand(int fd, nvt_vars *vars, char *data, int len) +int parse_nvt_subcommand(int fd, nvt_vars *vars, char *data, int len, int speed) { // overflow issue, again... - int opt = data[2]; + nvtOption opt = data[2]; char resp[100]; char *response = resp + 3; int resp_len = 0; @@ -64,6 +64,7 @@ int parse_nvt_subcommand(int fd, nvt_vars *vars, char *data, int len) char tty_type[] = "VT100"; int rc; int slen = 0; + char buf[50]; for (rc = 2; rc < len - 1; rc++) { @@ -88,8 +89,21 @@ int parse_nvt_subcommand(int fd, nvt_vars *vars, char *data, int len) strncpy(response + response_len, tty_type, slen); response_len += slen; break; + + case NVT_OPT_TERMINAL_SPEED: + sprintf(buf, "%i,%i", speed, speed); + slen = strlen(buf); + strncpy(response + response_len, buf, slen); + response_len += slen; + break; + + default: + break; } break; + + default: + break; } } @@ -120,9 +134,10 @@ int send_nvt_command(int fd, nvt_vars *vars, char action, int opt) return 0; } -int parse_nvt_command(int fd, nvt_vars *vars, char action, int opt) +int parse_nvt_command(int fd, nvt_vars *vars, nvtCommand action, nvtOption opt, int parity) { char resp[3]; + int accept = FALSE; resp[0] = NVT_IAC; @@ -132,23 +147,35 @@ int parse_nvt_command(int fd, nvt_vars *vars, char action, int opt) case NVT_OPT_TRANSMIT_BINARY: switch (action) { case NVT_DO: - LOG(LOG_INFO, "Enabling telnet binary xmit"); - vars->binary_xmit = TRUE; + if (!parity) { + LOG(LOG_INFO, "Enabling telnet binary xmit"); + vars->binary_xmit = TRUE; + accept = TRUE; + } break; case NVT_DONT: LOG(LOG_INFO, "Disabling telnet binary xmit"); vars->binary_xmit = FALSE; + accept = TRUE; break; case NVT_WILL: - LOG(LOG_INFO, "Enabling telnet binary recv"); - vars->binary_recv = TRUE; + if (!parity) { + LOG(LOG_INFO, "Enabling telnet binary recv"); + vars->binary_recv = TRUE; + accept = TRUE; + } break; case NVT_WONT: LOG(LOG_INFO, "Disabling telnet binary recv"); vars->binary_recv = FALSE; + accept = TRUE; + break; + + default: break; } - // fall through to get response + resp[1] = get_nvt_cmd_response(action, accept); + break; case NVT_OPT_NAWS: case NVT_OPT_TERMINAL_TYPE: diff --git a/src/nvt.h b/src/nvt.h index c755dad..a99ded9 100644 --- a/src/nvt.h +++ b/src/nvt.h @@ -1,34 +1,38 @@ #ifndef NVT_H #define NVT_H 1 -#define NVT_SE 240 -#define NVT_NOP 241 -#define NVT_DM 242 -#define NVT_SB 250 -#define NVT_WILL 251 -#define NVT_WONT 252 -#define NVT_DO 253 -#define NVT_DONT 254 -#define NVT_IAC 255 -#define NVT_WILL_RESP 251 -#define NVT_WONT_RESP 252 -#define NVT_DO_RESP 253 -#define NVT_DONT_RESP 254 +typedef enum { + NVT_SE = 240, + NVT_NOP = 241, + NVT_DM = 242, + NVT_SB = 250, + NVT_WILL = 251, + NVT_WONT = 252, + NVT_DO = 253, + NVT_DONT = 254, + NVT_IAC = 255, + NVT_WILL_RESP = 251, + NVT_WONT_RESP = 252, + NVT_DO_RESP = 253, + NVT_DONT_RESP = 254, +} nvtCommand; -#define NVT_OPT_TRANSMIT_BINARY 0 -#define NVT_OPT_ECHO 1 -#define NVT_OPT_SUPPRESS_GO_AHEAD 3 -#define NVT_OPT_STATUS 5 -#define NVT_OPT_RCTE 7 -#define NVT_OPT_TIMING_MARK 6 -#define NVT_OPT_NAOCRD 10 -#define NVT_OPT_TERMINAL_TYPE 24 -#define NVT_OPT_NAWS 31 -#define NVT_OPT_TERMINAL_SPEED 32 -#define NVT_OPT_LINEMODE 34 -#define NVT_OPT_X_DISPLAY_LOCATION 35 -#define NVT_OPT_ENVIRON 36 -#define NVT_OPT_NEW_ENVIRON 39 +typedef enum { + NVT_OPT_TRANSMIT_BINARY = 0, + NVT_OPT_ECHO = 1, + NVT_OPT_SUPPRESS_GO_AHEAD = 3, + NVT_OPT_STATUS = 5, + NVT_OPT_RCTE = 7, + NVT_OPT_TIMING_MARK = 6, + NVT_OPT_NAOCRD = 10, + NVT_OPT_TERMINAL_TYPE = 24, + NVT_OPT_NAWS = 31, + NVT_OPT_TERMINAL_SPEED = 32, + NVT_OPT_LINEMODE = 34, + NVT_OPT_X_DISPLAY_LOCATION = 35, + NVT_OPT_ENVIRON = 36, + NVT_OPT_NEW_ENVIRON = 39, +} nvtOption; #define NVT_SB_IS 0 #define NVT_SB_SEND 1 @@ -44,10 +48,10 @@ typedef struct nvt_vars { char term[256]; } nvt_vars; -char get_nvt_cmd_response(char action, char type); -int parse_nvt_subcommand(int fd, nvt_vars *vars, char *data, int len); -int parse_nvt_command(int fd, nvt_vars *vars, char action, int opt); -int nvt_init_config(nvt_vars *vars); -int send_nvt_command(int fd, nvt_vars *vars, char action, int opt); +extern char get_nvt_cmd_response(char action, char type); +extern int parse_nvt_subcommand(int fd, nvt_vars *vars, char *data, int len, int speed); +extern int parse_nvt_command(int fd, nvt_vars *vars, nvtCommand action, nvtOption opt, int parity); +extern int nvt_init_config(nvt_vars *vars); +extern int send_nvt_command(int fd, nvt_vars *vars, char action, int opt); #endif