# HG changeset patch # User Mychaela Falconia # Date 1684819399 0 # Node ID 65953c172f243b3c13cc6c515933ef29118a345b # Parent 4e243402f453e60954ef5c3977d49faa6194c37a rvinterf/lowlevel: new hex dump format diff -r 4e243402f453 -r 65953c172f24 rvinterf/libprint/Makefile --- a/rvinterf/libprint/Makefile Tue May 23 03:59:42 2023 +0000 +++ b/rvinterf/libprint/Makefile Tue May 23 05:23:19 2023 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= back_esc.o +OBJS= back_esc.o hexdump.o LIB= libprint.a all: ${LIB} diff -r 4e243402f453 -r 65953c172f24 rvinterf/libprint/hexdump.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/libprint/hexdump.c Tue May 23 05:23:19 2023 +0000 @@ -0,0 +1,52 @@ +/* + * The function contained in this module implements hex dump functionality: + * an arbitrary binary packet is dumped in hex, line by line, calling an output + * function for each line. + */ + +#include +#include +#include +#include + +void +packet_hex_dump(src, srclen, outfunc) + u_char *src; + unsigned srclen; + void (*outfunc)(); +{ + u_char *sp = src; + unsigned remain = srclen; + unsigned offset = 0; + unsigned chunk; + char line[80], *dp; + int i, c; + + while (remain) { + sprintf(line, "%04X: ", offset); + dp = line + 7; + chunk = remain; + if (chunk > 16) + chunk = 16; + for (i = 0; i < 16; i++) { + if (i < chunk) + sprintf(dp, "%02X ", sp[i]); + else + strcpy(dp, " "); + dp += 3; + if (i == 7 || i == 15) + *dp++ = ' '; + } + for (i = 0; i < chunk; i++) { + c = sp[i]; + if (c < ' ' || c > '~') + c = '.'; + *dp++ = c; + } + *dp = '\0'; + outfunc(line); + sp += chunk; + remain -= chunk; + offset += chunk; + } +} diff -r 4e243402f453 -r 65953c172f24 rvinterf/lowlevel/format.c --- a/rvinterf/lowlevel/format.c Tue May 23 03:59:42 2023 +0000 +++ b/rvinterf/lowlevel/format.c Tue May 23 05:23:19 2023 +0000 @@ -14,6 +14,8 @@ extern u_char rxpkt[]; extern size_t rxpkt_len; +extern void output_cont(); + static char fmtbuf[MAX_PKT_FROM_TARGET*8]; /* size it generously */ void @@ -33,7 +35,7 @@ /* severity level */ sprintf(dp, " %d ", rxpkt[5]); dp = index(dp, '\0'); - safe_print_trace(rxpkt + 6, rxpkt_len - 6, dp); + safe_print_trace(rxpkt + 6, (int)rxpkt_len - 6, dp); output_line(fmtbuf); } @@ -101,33 +103,13 @@ void print_tm_output_raw() { - int i; - char *dp; - - dp = fmtbuf; - strcpy(dp, "TM:"); - dp += 3; - for (i = 1; i < rxpkt_len; i++) { - sprintf(dp, " %02X", rxpkt[i]); - dp += 3; - } - *dp = '\0'; - output_line(fmtbuf); + output_line("Rx Test Mode packet"); + packet_hex_dump(rxpkt, (unsigned) rxpkt_len, output_cont); } void print_unknown_packet() { - int i; - char *dp; - - dp = fmtbuf; - strcpy(dp, "UNK:"); - dp += 4; - for (i = 0; i < rxpkt_len; i++) { - sprintf(dp, " %02X", rxpkt[i]); - dp += 3; - } - *dp = '\0'; - output_line(fmtbuf); + output_line("Rx unknown packet format"); + packet_hex_dump(rxpkt, (unsigned) rxpkt_len, output_cont); } diff -r 4e243402f453 -r 65953c172f24 rvinterf/lowlevel/format_fc.c --- a/rvinterf/lowlevel/format_fc.c Tue May 23 03:59:42 2023 +0000 +++ b/rvinterf/lowlevel/format_fc.c Tue May 23 05:23:19 2023 +0000 @@ -13,13 +13,15 @@ extern u_char rxpkt[]; extern size_t rxpkt_len; +extern void output_cont(); + static char fmtbuf[MAX_PKT_FROM_TARGET*8]; /* size it generously */ void print_ati_output() { strcpy(fmtbuf, "ATI: "); - safe_print_trace(rxpkt + 1, rxpkt_len - 1, fmtbuf + 5); + safe_print_trace(rxpkt + 1, (int)rxpkt_len - 1, fmtbuf + 5); output_line(fmtbuf); } @@ -27,25 +29,15 @@ print_fc_lld_msg() { strcpy(fmtbuf, "LLD: "); - safe_print_trace(rxpkt + 1, rxpkt_len - 1, fmtbuf + 5); + safe_print_trace(rxpkt + 1, (int)rxpkt_len - 1, fmtbuf + 5); output_line(fmtbuf); } void print_tch_output_raw() { - int i; - char *dp; - - dp = fmtbuf; - strcpy(dp, "TCH:"); - dp += 4; - for (i = 1; i < rxpkt_len; i++) { - sprintf(dp, " %02X", rxpkt[i]); - dp += 3; - } - *dp = '\0'; - output_line(fmtbuf); + output_line("Rx TCH packet"); + packet_hex_dump(rxpkt, (unsigned) rxpkt_len, output_cont); } void diff -r 4e243402f453 -r 65953c172f24 rvinterf/lowlevel/logsent.c --- a/rvinterf/lowlevel/logsent.c Tue May 23 03:59:42 2023 +0000 +++ b/rvinterf/lowlevel/logsent.c Tue May 23 05:23:19 2023 +0000 @@ -12,6 +12,8 @@ extern int no_output, verbose; extern FILE *logF; +extern void output_cont(); + static void log_sent_ati(pkt, pktlen) u_char *pkt; @@ -34,25 +36,6 @@ output_line(buf); } -static void -log_sent_other(pkt, pktlen) - u_char *pkt; -{ - char buf[MAX_PKT_TO_TARGET*3+5]; - int i; - char *dp; - - dp = buf; - strcpy(dp, "Sent"); - dp += 4; - for (i = 0; i < pktlen; i++) { - sprintf(dp, " %02X", pkt[i]); - dp += 3; - } - *dp = '\0'; - output_line(buf); -} - log_sent_packet(pkt, pktlen) u_char *pkt; { @@ -62,16 +45,23 @@ case RVT_L23_HEADER: log_sent_gpf(pkt, pktlen); return; + case RVT_TM_HEADER: + output_line("Sent Test Mode packet"); + packet_hex_dump(pkt, pktlen, output_cont); + return; case RVT_AT_HEADER: log_sent_ati(pkt, pktlen); return; case RVT_TCH_HEADER: - if (verbose) - goto generic; - tch_inc_count_tx(); + if (verbose) { + output_line("Sent TCH packet"); + packet_hex_dump(pkt, pktlen, output_cont); + } else { + tch_inc_count_tx(); + } return; default: - generic: - log_sent_other(pkt, pktlen); + output_line("Sent misc packet"); + packet_hex_dump(pkt, pktlen, output_cont); } } diff -r 4e243402f453 -r 65953c172f24 rvinterf/lowlevel/output.c --- a/rvinterf/lowlevel/output.c Tue May 23 03:59:42 2023 +0000 +++ b/rvinterf/lowlevel/output.c Tue May 23 05:23:19 2023 +0000 @@ -40,3 +40,13 @@ curtm->tm_sec, item); bcopy(curtm, &last_tm, sizeof(struct tm)); } + +void +output_cont(item) + char *item; +{ + if (!no_output) + printf("%s\n", item); + if (logF) + fprintf(logF, "%s\n", item); +}