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:
parent
2db5a0d0b9
commit
967f2f6830
3 changed files with 36 additions and 27 deletions
|
@ -83,8 +83,12 @@ typedef struct _patty_ax25_sock {
|
|||
timer_t2,
|
||||
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,
|
||||
pending;
|
||||
|
@ -129,9 +133,9 @@ char *patty_ax25_sock_pty(patty_ax25_sock *sock);
|
|||
int patty_ax25_sock_bind_if(patty_ax25_sock *sock,
|
||||
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,
|
||||
enum patty_ax25_frame_cr cr,
|
||||
|
|
12
src/server.c
12
src/server.c
|
@ -1340,8 +1340,8 @@ static int handle_i(patty_ax25_server *server,
|
|||
return frame->pf? reply_dm(iface, frame, PATTY_AX25_FRAME_FINAL): 0;
|
||||
}
|
||||
|
||||
if (sock->seq_recv == frame->ns) {
|
||||
patty_ax25_sock_seq_recv_incr(sock);
|
||||
if (sock->vr == frame->ns) {
|
||||
patty_ax25_sock_vr_incr(sock);
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
sock->va = frame->ns + 1;
|
||||
|
||||
if (++sock->pending == sock->n_window_rx / 2) {
|
||||
sock->pending = 0;
|
||||
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);
|
||||
|
||||
case PATTY_AX25_FRAME_RESPONSE:
|
||||
sock->vs = frame->nr;
|
||||
|
||||
patty_timer_start(&sock->timer_t3, PATTY_AX25_SOCK_DEFAULT_KEEPALIVE);
|
||||
|
||||
default:
|
||||
|
@ -1418,7 +1422,7 @@ static int handle_rej(patty_ax25_server *server,
|
|||
patty_ax25_sock *sock,
|
||||
patty_ax25_frame *frame) {
|
||||
unsigned int i,
|
||||
end = sock->seq_send;
|
||||
end = sock->vs;
|
||||
|
||||
if (sock == NULL) {
|
||||
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"
|
||||
*/
|
||||
if (sock->seq_recv + sock->n_window_tx == sock->seq_send) {
|
||||
if (sock->vs + sock->n_window_tx == sock->vs) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
39
src/sock.c
39
src/sock.c
|
@ -183,10 +183,11 @@ void patty_ax25_sock_init(patty_ax25_sock *sock) {
|
|||
* AX.25 v2.2 Specification, Section 6.5 "Resetting Procedure"
|
||||
*/
|
||||
void patty_ax25_sock_reset(patty_ax25_sock *sock) {
|
||||
sock->seq_send = 0;
|
||||
sock->seq_recv = 0;
|
||||
sock->retries = sock->n_retry;
|
||||
sock->pending = 0;
|
||||
sock->vs = 0;
|
||||
sock->vr = 0;
|
||||
sock->va = 0;
|
||||
sock->retries = sock->n_retry;
|
||||
sock->pending = 0;
|
||||
|
||||
patty_timer_clear(&sock->timer_t1);
|
||||
patty_timer_clear(&sock->timer_t2);
|
||||
|
@ -329,19 +330,19 @@ error_if_promisc_add:
|
|||
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) {
|
||||
sock->seq_send = (sock->seq_send + 1) & 0x07;
|
||||
sock->vs = (sock->vs + 1) & 0x07;
|
||||
} 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) {
|
||||
sock->seq_recv = (sock->seq_recv + 1) & 0x07;
|
||||
sock->vr = (sock->vr + 1) & 0x07;
|
||||
} 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;
|
||||
|
||||
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) {
|
||||
errno = ENETDOWN;
|
||||
|
@ -437,7 +438,7 @@ ssize_t patty_ax25_sock_send(patty_ax25_sock *sock,
|
|||
|
||||
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);
|
||||
|
@ -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) {
|
||||
switch (sock->mode) {
|
||||
case PATTY_AX25_SOCK_SABM:
|
||||
return ((sock->seq_recv & 0x07) << 5)
|
||||
| ((sock->seq_send & 0x07) << 1)
|
||||
return ((sock->vr & 0x07) << 5)
|
||||
| ((sock->vs & 0x07) << 1)
|
||||
| (flag << 4);
|
||||
|
||||
case PATTY_AX25_SOCK_SABME:
|
||||
return ((sock->seq_recv & 0x7f) << 9)
|
||||
| ((sock->seq_send & 0x7f) << 1)
|
||||
return ((sock->vr & 0x7f) << 9)
|
||||
| ((sock->vs & 0x7f) << 1)
|
||||
| (flag << 8);
|
||||
|
||||
default:
|
||||
|
@ -481,12 +482,12 @@ static uint16_t control_s(patty_ax25_sock *sock,
|
|||
int flag) {
|
||||
switch (sock->mode) {
|
||||
case PATTY_AX25_SOCK_SABM:
|
||||
return ((sock->seq_recv & 0x07) << 5)
|
||||
return ((sock->vr & 0x07) << 5)
|
||||
| (type & 0x0f)
|
||||
| (flag << 4);
|
||||
|
||||
case PATTY_AX25_SOCK_SABME:
|
||||
return ((sock->seq_recv & 0x7f) << 9)
|
||||
return ((sock->vr & 0x7f) << 9)
|
||||
| (type & 0x0f)
|
||||
| (flag << 8);
|
||||
|
||||
|
@ -634,7 +635,7 @@ ssize_t patty_ax25_sock_write(patty_ax25_sock *sock,
|
|||
goto error_send;
|
||||
}
|
||||
|
||||
patty_ax25_sock_seq_send_incr(sock);
|
||||
patty_ax25_sock_vs_incr(sock);
|
||||
|
||||
return len;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue