From 34a534656604e112ae8ffa987f6c08b5455f5410 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 7 Nov 2019 16:34:19 +0100 Subject: [PATCH] Added outgoing packet capture --- protocol/KISS.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/protocol/KISS.c b/protocol/KISS.c index 5f0cd34..58ebbc3 100755 --- a/protocol/KISS.c +++ b/protocol/KISS.c @@ -151,7 +151,6 @@ void kiss_messageCallback(AX25Ctx *ctx) { } fputc(FEND, &serial->uart0); - ticks_t start_t = timer_clock(); if (config_log_packets && sd_mounted()) { if (log_ready || log_init()) { log_fr = f_open(&log_fp, log_filename, FA_OPEN_APPEND | FA_WRITE); @@ -160,14 +159,14 @@ void kiss_messageCallback(AX25Ctx *ctx) { UINT written = 0; uint32_t pcap_ts_sec = rtc_seconds(); uint32_t pcap_ts_usec = (rtc_milliseconds()*(uint32_t)1000); - uint32_t pcap_incl_len = ctx->frame_len; - uint32_t pcap_orig_len = ctx->frame_len; + uint32_t pcap_incl_len = ctx->frame_len-2; + uint32_t pcap_orig_len = ctx->frame_len-2; f_write(&log_fp, &pcap_ts_sec, sizeof(pcap_ts_sec), &written); f_write(&log_fp, &pcap_ts_usec, sizeof(pcap_ts_usec), &written); f_write(&log_fp, &pcap_incl_len, sizeof(pcap_incl_len), &written); f_write(&log_fp, &pcap_orig_len, sizeof(pcap_orig_len), &written); - f_write(&log_fp, ctx->buf, ctx->frame_len, &written); + f_write(&log_fp, ctx->buf, ctx->frame_len-2, &written); // Close handle and flush to disk f_close(&log_fp); @@ -411,6 +410,29 @@ void kiss_flushQueue(void) { tx_buffer[i] = packet_queue[pos]; } + if (config_log_packets && sd_mounted()) { + if (log_ready || log_init()) { + log_fr = f_open(&log_fp, log_filename, FA_OPEN_APPEND | FA_WRITE); + if (log_fr == FR_OK) { + // Write PCAP segment to file + UINT written = 0; + uint32_t pcap_ts_sec = rtc_seconds(); + uint32_t pcap_ts_usec = (rtc_milliseconds()*(uint32_t)1000); + uint32_t pcap_incl_len = length; + uint32_t pcap_orig_len = length; + + f_write(&log_fp, &pcap_ts_sec, sizeof(pcap_ts_sec), &written); + f_write(&log_fp, &pcap_ts_usec, sizeof(pcap_ts_usec), &written); + f_write(&log_fp, &pcap_incl_len, sizeof(pcap_incl_len), &written); + f_write(&log_fp, &pcap_orig_len, sizeof(pcap_orig_len), &written); + f_write(&log_fp, tx_buffer, length, &written); + + // Close handle and flush to disk + f_close(&log_fp); + } + } + } + ax25_sendRaw(ax25ctx, tx_buffer, length); processed++; }