2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
8 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
9 * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
10 * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
12 #include <linux/errno.h>
13 #include <linux/types.h>
14 #include <linux/socket.h>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/timer.h>
19 #include <linux/string.h>
20 #include <linux/sockios.h>
21 #include <linux/net.h>
23 #include <linux/inet.h>
24 #include <linux/netdevice.h>
25 #include <linux/skbuff.h>
27 #include <net/tcp_states.h>
28 #include <asm/uaccess.h>
29 #include <asm/system.h>
30 #include <linux/fcntl.h>
32 #include <linux/interrupt.h>
34 void ax25_std_heartbeat_expiry(ax25_cb
*ax25
)
36 struct sock
*sk
=ax25
->sk
;
41 switch (ax25
->state
) {
43 /* Magic here: If we listen() and a new link dies before it
44 is accepted() it isn't 'dead' so doesn't get removed. */
45 if (!sk
|| sock_flag(sk
, SOCK_DESTROY
) ||
46 (sk
->sk_state
== TCP_LISTEN
&&
47 sock_flag(sk
, SOCK_DEAD
))) {
50 ax25_destroy_socket(ax25
);
54 ax25_destroy_socket(ax25
);
62 * Check the state of the receive buffer.
65 if (atomic_read(&sk
->sk_rmem_alloc
) <
66 (sk
->sk_rcvbuf
/ 2) &&
67 (ax25
->condition
& AX25_COND_OWN_RX_BUSY
)) {
68 ax25
->condition
&= ~AX25_COND_OWN_RX_BUSY
;
69 ax25
->condition
&= ~AX25_COND_ACK_PENDING
;
70 ax25_send_control(ax25
, AX25_RR
, AX25_POLLOFF
, AX25_RESPONSE
);
79 ax25_start_heartbeat(ax25
);
82 void ax25_std_t2timer_expiry(ax25_cb
*ax25
)
84 if (ax25
->condition
& AX25_COND_ACK_PENDING
) {
85 ax25
->condition
&= ~AX25_COND_ACK_PENDING
;
86 ax25_std_timeout_response(ax25
);
90 void ax25_std_t3timer_expiry(ax25_cb
*ax25
)
93 ax25_std_transmit_enquiry(ax25
);
94 ax25
->state
= AX25_STATE_4
;
97 void ax25_std_idletimer_expiry(ax25_cb
*ax25
)
99 ax25_clear_queues(ax25
);
102 ax25_send_control(ax25
, AX25_DISC
, AX25_POLLON
, AX25_COMMAND
);
103 ax25
->state
= AX25_STATE_2
;
105 ax25_calculate_t1(ax25
);
106 ax25_start_t1timer(ax25
);
107 ax25_stop_t2timer(ax25
);
108 ax25_stop_t3timer(ax25
);
110 if (ax25
->sk
!= NULL
) {
111 bh_lock_sock(ax25
->sk
);
112 ax25
->sk
->sk_state
= TCP_CLOSE
;
113 ax25
->sk
->sk_err
= 0;
114 ax25
->sk
->sk_shutdown
|= SEND_SHUTDOWN
;
115 if (!sock_flag(ax25
->sk
, SOCK_DEAD
)) {
116 ax25
->sk
->sk_state_change(ax25
->sk
);
117 sock_set_flag(ax25
->sk
, SOCK_DEAD
);
119 bh_unlock_sock(ax25
->sk
);
123 void ax25_std_t1timer_expiry(ax25_cb
*ax25
)
125 switch (ax25
->state
) {
127 if (ax25
->n2count
== ax25
->n2
) {
128 if (ax25
->modulus
== AX25_MODULUS
) {
129 ax25_disconnect(ax25
, ETIMEDOUT
);
132 ax25
->modulus
= AX25_MODULUS
;
133 ax25
->window
= ax25
->ax25_dev
->values
[AX25_VALUES_WINDOW
];
135 ax25_send_control(ax25
, AX25_SABM
, AX25_POLLON
, AX25_COMMAND
);
139 if (ax25
->modulus
== AX25_MODULUS
)
140 ax25_send_control(ax25
, AX25_SABM
, AX25_POLLON
, AX25_COMMAND
);
142 ax25_send_control(ax25
, AX25_SABME
, AX25_POLLON
, AX25_COMMAND
);
147 if (ax25
->n2count
== ax25
->n2
) {
148 ax25_send_control(ax25
, AX25_DISC
, AX25_POLLON
, AX25_COMMAND
);
149 ax25_disconnect(ax25
, ETIMEDOUT
);
153 ax25_send_control(ax25
, AX25_DISC
, AX25_POLLON
, AX25_COMMAND
);
159 ax25_std_transmit_enquiry(ax25
);
160 ax25
->state
= AX25_STATE_4
;
164 if (ax25
->n2count
== ax25
->n2
) {
165 ax25_send_control(ax25
, AX25_DM
, AX25_POLLON
, AX25_RESPONSE
);
166 ax25_disconnect(ax25
, ETIMEDOUT
);
170 ax25_std_transmit_enquiry(ax25
);
175 ax25_calculate_t1(ax25
);
176 ax25_start_t1timer(ax25
);