1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
5 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
6 * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
7 * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
9 #include <linux/errno.h>
10 #include <linux/types.h>
11 #include <linux/socket.h>
13 #include <linux/kernel.h>
14 #include <linux/timer.h>
15 #include <linux/string.h>
16 #include <linux/sockios.h>
17 #include <linux/net.h>
19 #include <linux/inet.h>
20 #include <linux/netdevice.h>
21 #include <linux/skbuff.h>
23 #include <net/tcp_states.h>
24 #include <linux/uaccess.h>
25 #include <linux/fcntl.h>
27 #include <linux/interrupt.h>
29 void ax25_std_heartbeat_expiry(ax25_cb *ax25)
31 struct sock *sk = ax25->sk;
36 switch (ax25->state) {
39 /* Magic here: If we listen() and a new link dies before it
40 is accepted() it isn't 'dead' so doesn't get removed. */
41 if (!sk || sock_flag(sk, SOCK_DESTROY) ||
42 (sk->sk_state == TCP_LISTEN &&
43 sock_flag(sk, SOCK_DEAD))) {
46 ax25_destroy_socket(ax25);
48 /* Ungrab socket and destroy it */
51 ax25_destroy_socket(ax25);
59 * Check the state of the receive buffer.
62 if (atomic_read(&sk->sk_rmem_alloc) <
63 (sk->sk_rcvbuf >> 1) &&
64 (ax25->condition & AX25_COND_OWN_RX_BUSY)) {
65 ax25->condition &= ~AX25_COND_OWN_RX_BUSY;
66 ax25->condition &= ~AX25_COND_ACK_PENDING;
67 ax25_send_control(ax25, AX25_RR, AX25_POLLOFF, AX25_RESPONSE);
76 ax25_start_heartbeat(ax25);
79 void ax25_std_t2timer_expiry(ax25_cb *ax25)
81 if (ax25->condition & AX25_COND_ACK_PENDING) {
82 ax25->condition &= ~AX25_COND_ACK_PENDING;
83 ax25_std_timeout_response(ax25);
87 void ax25_std_t3timer_expiry(ax25_cb *ax25)
90 ax25_std_transmit_enquiry(ax25);
91 ax25->state = AX25_STATE_4;
94 void ax25_std_idletimer_expiry(ax25_cb *ax25)
96 ax25_clear_queues(ax25);
99 ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
100 ax25->state = AX25_STATE_2;
102 ax25_calculate_t1(ax25);
103 ax25_start_t1timer(ax25);
104 ax25_stop_t2timer(ax25);
105 ax25_stop_t3timer(ax25);
107 if (ax25->sk != NULL) {
108 bh_lock_sock(ax25->sk);
109 ax25->sk->sk_state = TCP_CLOSE;
110 ax25->sk->sk_err = 0;
111 ax25->sk->sk_shutdown |= SEND_SHUTDOWN;
112 if (!sock_flag(ax25->sk, SOCK_DEAD)) {
113 ax25->sk->sk_state_change(ax25->sk);
114 sock_set_flag(ax25->sk, SOCK_DEAD);
116 bh_unlock_sock(ax25->sk);
120 void ax25_std_t1timer_expiry(ax25_cb *ax25)
122 switch (ax25->state) {
124 if (ax25->n2count == ax25->n2) {
125 if (ax25->modulus == AX25_MODULUS) {
126 ax25_disconnect(ax25, ETIMEDOUT);
129 ax25->modulus = AX25_MODULUS;
130 ax25->window = ax25->ax25_dev->values[AX25_VALUES_WINDOW];
132 ax25_send_control(ax25, AX25_SABM, AX25_POLLON, AX25_COMMAND);
136 if (ax25->modulus == AX25_MODULUS)
137 ax25_send_control(ax25, AX25_SABM, AX25_POLLON, AX25_COMMAND);
139 ax25_send_control(ax25, AX25_SABME, AX25_POLLON, AX25_COMMAND);
144 if (ax25->n2count == ax25->n2) {
145 ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
146 if (!sock_flag(ax25->sk, SOCK_DESTROY))
147 ax25_disconnect(ax25, ETIMEDOUT);
151 ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
157 ax25_std_transmit_enquiry(ax25);
158 ax25->state = AX25_STATE_4;
162 if (ax25->n2count == ax25->n2) {
163 ax25_send_control(ax25, AX25_DM, AX25_POLLON, AX25_RESPONSE);
164 ax25_disconnect(ax25, ETIMEDOUT);
168 ax25_std_transmit_enquiry(ax25);
173 ax25_calculate_t1(ax25);
174 ax25_start_t1timer(ax25);