From 2db5a0d0b9bf4eaf15f91c561d9f7da62970192a Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 3 Aug 2020 15:09:32 -0400 Subject: [PATCH] Fix issues with TX slots in src/sock.c Fix issues with TX slots in src/sock.c wherein packets saved for resend would not be able to be resent, as their total length was not encoded properly into the slot structure --- src/sock.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/sock.c b/src/sock.c index 43f5f17..f8ba5be 100644 --- a/src/sock.c +++ b/src/sock.c @@ -66,7 +66,21 @@ static inline void *tx_slot(patty_ax25_sock *sock, size_t seq) { return (uint8_t *)sock->tx_slots + (i * tx_slot_size(sock)); } +static inline void tx_slot_save_len(patty_ax25_sock *sock, + size_t seq, + size_t len) { + size_t *size = (size_t *)tx_slot(sock, seq); + + *size = len; +} + +static inline void *tx_slot_buf(patty_ax25_sock *sock, size_t seq) { + return (uint8_t *)tx_slot(sock, seq) + sizeof(size_t); +} + static int init_bufs(patty_ax25_sock *sock) { + size_t i; + if ((sock->tx_buf = realloc(sock->tx_buf, tx_bufsz(sock))) == NULL) { goto error_realloc_tx_buf; } @@ -79,6 +93,10 @@ static int init_bufs(patty_ax25_sock *sock) { goto error_realloc_tx_slots; } + for (i=0; in_window_tx; i++) { + tx_slot_save_len(sock, i, 0); + } + return 0; error_realloc_tx_slots: @@ -380,7 +398,7 @@ ssize_t patty_ax25_sock_send(patty_ax25_sock *sock, ssize_t encoded; uint8_t *buf = PATTY_AX25_FRAME_CONTROL_I(control)? - tx_slot(sock, sock->seq_send): sock->tx_buf; + tx_slot_buf(sock, sock->seq_send): sock->tx_buf; if (sock->iface == NULL) { errno = ENETDOWN; @@ -418,6 +436,8 @@ ssize_t patty_ax25_sock_send(patty_ax25_sock *sock, memcpy(buf + offset, info, infolen); offset += infolen; + + tx_slot_save_len(sock, sock->seq_send, offset); } return patty_ax25_if_send(sock->iface, buf, offset); @@ -436,7 +456,7 @@ ssize_t patty_ax25_sock_resend(patty_ax25_sock *sock, size_t len = *((size_t *)slot); - return patty_ax25_if_send(sock->iface, buf, len); + return len > 0? patty_ax25_if_send(sock->iface, buf, len): 0; } static uint16_t control_i(patty_ax25_sock *sock, int flag) {