Rename patty_ax25_sock sequences per Section 4.2.4

Changes:

    * Rename seq_send to vs, ie, V(S)

    * Rename seq_recv to vr, ie, V(R)

    * Ensure handling RR responses updates V(S) with the N(R) value of
      the received frame
This commit is contained in:
XANTRONIX Development 2020-08-03 18:47:48 -04:00 committed by XANTRONIX Industrial
parent 2db5a0d0b9
commit 967f2f6830
3 changed files with 36 additions and 27 deletions

View file

@ -83,8 +83,12 @@ typedef struct _patty_ax25_sock {
timer_t2, timer_t2,
timer_t3; timer_t3;
unsigned int seq_send, /*
seq_recv; * AX.25 v2.2 Section 4.2.4 "Frame Variables and Sequence Numbers"
*/
unsigned int vs,
vr,
va;
size_t retries, size_t retries,
pending; pending;
@ -129,9 +133,9 @@ char *patty_ax25_sock_pty(patty_ax25_sock *sock);
int patty_ax25_sock_bind_if(patty_ax25_sock *sock, int patty_ax25_sock_bind_if(patty_ax25_sock *sock,
patty_ax25_if *iface); patty_ax25_if *iface);
void patty_ax25_sock_seq_send_incr(patty_ax25_sock *sock); void patty_ax25_sock_vs_incr(patty_ax25_sock *sock);
void patty_ax25_sock_seq_recv_incr(patty_ax25_sock *sock); void patty_ax25_sock_vr_incr(patty_ax25_sock *sock);
ssize_t patty_ax25_sock_send(patty_ax25_sock *sock, ssize_t patty_ax25_sock_send(patty_ax25_sock *sock,
enum patty_ax25_frame_cr cr, enum patty_ax25_frame_cr cr,

View file

@ -1340,8 +1340,8 @@ static int handle_i(patty_ax25_server *server,
return frame->pf? reply_dm(iface, frame, PATTY_AX25_FRAME_FINAL): 0; return frame->pf? reply_dm(iface, frame, PATTY_AX25_FRAME_FINAL): 0;
} }
if (sock->seq_recv == frame->ns) { if (sock->vr == frame->ns) {
patty_ax25_sock_seq_recv_incr(sock); patty_ax25_sock_vr_incr(sock);
} else { } else {
return patty_ax25_sock_send_rej(sock, PATTY_AX25_FRAME_RESPONSE, 1); return patty_ax25_sock_send_rej(sock, PATTY_AX25_FRAME_RESPONSE, 1);
} }
@ -1350,6 +1350,8 @@ static int handle_i(patty_ax25_server *server,
goto error_write; goto error_write;
} }
sock->va = frame->ns + 1;
if (++sock->pending == sock->n_window_rx / 2) { if (++sock->pending == sock->n_window_rx / 2) {
sock->pending = 0; sock->pending = 0;
patty_timer_stop(&sock->timer_t2); patty_timer_stop(&sock->timer_t2);
@ -1405,6 +1407,8 @@ static int handle_rr(patty_ax25_server *server,
return patty_ax25_sock_send_rr(sock, PATTY_AX25_FRAME_RESPONSE, 1); return patty_ax25_sock_send_rr(sock, PATTY_AX25_FRAME_RESPONSE, 1);
case PATTY_AX25_FRAME_RESPONSE: case PATTY_AX25_FRAME_RESPONSE:
sock->vs = frame->nr;
patty_timer_start(&sock->timer_t3, PATTY_AX25_SOCK_DEFAULT_KEEPALIVE); patty_timer_start(&sock->timer_t3, PATTY_AX25_SOCK_DEFAULT_KEEPALIVE);
default: default:
@ -1418,7 +1422,7 @@ static int handle_rej(patty_ax25_server *server,
patty_ax25_sock *sock, patty_ax25_sock *sock,
patty_ax25_frame *frame) { patty_ax25_frame *frame) {
unsigned int i, unsigned int i,
end = sock->seq_send; end = sock->vs;
if (sock == NULL) { if (sock == NULL) {
return 0; return 0;
@ -1777,7 +1781,7 @@ static int handle_sock(uint32_t key,
/* /*
* NOTE: See AX.25 2.2, Section 6.4.1, "Sending I Frames" * NOTE: See AX.25 2.2, Section 6.4.1, "Sending I Frames"
*/ */
if (sock->seq_recv + sock->n_window_tx == sock->seq_send) { if (sock->vs + sock->n_window_tx == sock->vs) {
goto done; goto done;
} }
} }

View file

@ -183,10 +183,11 @@ void patty_ax25_sock_init(patty_ax25_sock *sock) {
* AX.25 v2.2 Specification, Section 6.5 "Resetting Procedure" * AX.25 v2.2 Specification, Section 6.5 "Resetting Procedure"
*/ */
void patty_ax25_sock_reset(patty_ax25_sock *sock) { void patty_ax25_sock_reset(patty_ax25_sock *sock) {
sock->seq_send = 0; sock->vs = 0;
sock->seq_recv = 0; sock->vr = 0;
sock->retries = sock->n_retry; sock->va = 0;
sock->pending = 0; sock->retries = sock->n_retry;
sock->pending = 0;
patty_timer_clear(&sock->timer_t1); patty_timer_clear(&sock->timer_t1);
patty_timer_clear(&sock->timer_t2); patty_timer_clear(&sock->timer_t2);
@ -329,19 +330,19 @@ error_if_promisc_add:
return -1; return -1;
} }
void patty_ax25_sock_seq_send_incr(patty_ax25_sock *sock) { void patty_ax25_sock_vs_incr(patty_ax25_sock *sock) {
if (sock->mode == PATTY_AX25_SOCK_SABM) { if (sock->mode == PATTY_AX25_SOCK_SABM) {
sock->seq_send = (sock->seq_send + 1) & 0x07; sock->vs = (sock->vs + 1) & 0x07;
} else { } else {
sock->seq_send = (sock->seq_send + 1) & 0x7f; sock->vs = (sock->vs + 1) & 0x7f;
} }
} }
void patty_ax25_sock_seq_recv_incr(patty_ax25_sock *sock) { void patty_ax25_sock_vr_incr(patty_ax25_sock *sock) {
if (sock->mode == PATTY_AX25_SOCK_SABM) { if (sock->mode == PATTY_AX25_SOCK_SABM) {
sock->seq_recv = (sock->seq_recv + 1) & 0x07; sock->vr = (sock->vr + 1) & 0x07;
} else { } else {
sock->seq_recv = (sock->seq_recv + 1) & 0x7f; sock->vr = (sock->vr + 1) & 0x7f;
} }
} }
@ -398,7 +399,7 @@ ssize_t patty_ax25_sock_send(patty_ax25_sock *sock,
ssize_t encoded; ssize_t encoded;
uint8_t *buf = PATTY_AX25_FRAME_CONTROL_I(control)? uint8_t *buf = PATTY_AX25_FRAME_CONTROL_I(control)?
tx_slot_buf(sock, sock->seq_send): sock->tx_buf; tx_slot_buf(sock, sock->vs): sock->tx_buf;
if (sock->iface == NULL) { if (sock->iface == NULL) {
errno = ENETDOWN; errno = ENETDOWN;
@ -437,7 +438,7 @@ ssize_t patty_ax25_sock_send(patty_ax25_sock *sock,
offset += infolen; offset += infolen;
tx_slot_save_len(sock, sock->seq_send, offset); tx_slot_save_len(sock, sock->vs, offset);
} }
return patty_ax25_if_send(sock->iface, buf, offset); return patty_ax25_if_send(sock->iface, buf, offset);
@ -462,13 +463,13 @@ ssize_t patty_ax25_sock_resend(patty_ax25_sock *sock,
static uint16_t control_i(patty_ax25_sock *sock, int flag) { static uint16_t control_i(patty_ax25_sock *sock, int flag) {
switch (sock->mode) { switch (sock->mode) {
case PATTY_AX25_SOCK_SABM: case PATTY_AX25_SOCK_SABM:
return ((sock->seq_recv & 0x07) << 5) return ((sock->vr & 0x07) << 5)
| ((sock->seq_send & 0x07) << 1) | ((sock->vs & 0x07) << 1)
| (flag << 4); | (flag << 4);
case PATTY_AX25_SOCK_SABME: case PATTY_AX25_SOCK_SABME:
return ((sock->seq_recv & 0x7f) << 9) return ((sock->vr & 0x7f) << 9)
| ((sock->seq_send & 0x7f) << 1) | ((sock->vs & 0x7f) << 1)
| (flag << 8); | (flag << 8);
default: default:
@ -481,12 +482,12 @@ static uint16_t control_s(patty_ax25_sock *sock,
int flag) { int flag) {
switch (sock->mode) { switch (sock->mode) {
case PATTY_AX25_SOCK_SABM: case PATTY_AX25_SOCK_SABM:
return ((sock->seq_recv & 0x07) << 5) return ((sock->vr & 0x07) << 5)
| (type & 0x0f) | (type & 0x0f)
| (flag << 4); | (flag << 4);
case PATTY_AX25_SOCK_SABME: case PATTY_AX25_SOCK_SABME:
return ((sock->seq_recv & 0x7f) << 9) return ((sock->vr & 0x7f) << 9)
| (type & 0x0f) | (type & 0x0f)
| (flag << 8); | (flag << 8);
@ -634,7 +635,7 @@ ssize_t patty_ax25_sock_write(patty_ax25_sock *sock,
goto error_send; goto error_send;
} }
patty_ax25_sock_seq_send_incr(sock); patty_ax25_sock_vs_incr(sock);
return len; return len;