4 * This code REQUIRES 2.1.15 or higher/ NET3.038
7 * This module is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 * AX.25 036 Jonathan(G4KLX) Cloned from ax25_timer.c.
14 * Joerg(DL1BKE) Added DAMA Slave Timeout timer
15 * AX.25 037 Jonathan(G4KLX) New timer architecture.
18 #include <linux/config.h>
19 #if defined(CONFIG_AX25_DAMA_SLAVE)
20 #include <linux/errno.h>
21 #include <linux/types.h>
22 #include <linux/socket.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <linux/timer.h>
27 #include <linux/string.h>
28 #include <linux/sockios.h>
29 #include <linux/net.h>
31 #include <linux/inet.h>
32 #include <linux/netdevice.h>
33 #include <linux/skbuff.h>
35 #include <asm/uaccess.h>
36 #include <asm/system.h>
37 #include <linux/fcntl.h>
39 #include <linux/interrupt.h>
41 static void ax25_ds_timeout(unsigned long);
44 * Add DAMA slave timeout timer to timer list.
45 * Unlike the connection based timers the timeout function gets
46 * triggered every second. Please note that NET_AX25_DAMA_SLAVE_TIMEOUT
47 * (aka /proc/sys/net/ax25/{dev}/dama_slave_timeout) is still in
51 static void ax25_ds_add_timer(ax25_dev
*ax25_dev
)
53 struct timer_list
*t
= &ax25_dev
->dama
.slave_timer
;
54 t
->data
= (unsigned long) ax25_dev
;
55 t
->function
= &ax25_ds_timeout
;
56 t
->expires
= jiffies
+ HZ
;
60 void ax25_ds_del_timer(ax25_dev
*ax25_dev
)
62 if (ax25_dev
) del_timer(&ax25_dev
->dama
.slave_timer
);
65 void ax25_ds_set_timer(ax25_dev
*ax25_dev
)
67 if (ax25_dev
== NULL
) /* paranoia */
70 del_timer(&ax25_dev
->dama
.slave_timer
);
71 ax25_dev
->dama
.slave_timeout
= ax25_dev
->values
[AX25_VALUES_DS_TIMEOUT
] / 10;
72 ax25_ds_add_timer(ax25_dev
);
77 * Silently discard all (slave) connections in case our master forgot us...
80 static void ax25_ds_timeout(unsigned long arg
)
82 ax25_dev
*ax25_dev
= (struct ax25_dev
*) arg
;
85 if (ax25_dev
== NULL
|| !ax25_dev
->dama
.slave
)
88 if (!ax25_dev
->dama
.slave_timeout
|| --ax25_dev
->dama
.slave_timeout
) {
89 ax25_ds_set_timer(ax25_dev
);
93 for (ax25
=ax25_list
; ax25
!= NULL
; ax25
= ax25
->next
) {
94 if (ax25
->ax25_dev
!= ax25_dev
|| !(ax25
->condition
& AX25_COND_DAMA_MODE
))
97 ax25_send_control(ax25
, AX25_DISC
, AX25_POLLON
, AX25_COMMAND
);
98 ax25_disconnect(ax25
, ETIMEDOUT
);
101 ax25_dev_dama_off(ax25_dev
);
104 void ax25_ds_heartbeat_expiry(ax25_cb
*ax25
)
106 switch (ax25
->state
) {
109 /* Magic here: If we listen() and a new link dies before it
110 is accepted() it isn't 'dead' so doesn't get removed. */
111 if (ax25
->sk
== NULL
|| ax25
->sk
->destroy
|| (ax25
->sk
->state
== TCP_LISTEN
&& ax25
->sk
->dead
)) {
112 ax25_destroy_socket(ax25
);
119 * Check the state of the receive buffer.
121 if (ax25
->sk
!= NULL
) {
122 if (atomic_read(&ax25
->sk
->rmem_alloc
) < (ax25
->sk
->rcvbuf
/ 2) &&
123 (ax25
->condition
& AX25_COND_OWN_RX_BUSY
)) {
124 ax25
->condition
&= ~AX25_COND_OWN_RX_BUSY
;
125 ax25
->condition
&= ~AX25_COND_ACK_PENDING
;
132 ax25_start_heartbeat(ax25
);
135 /* dl1bke 960114: T3 works much like the IDLE timeout, but
136 * gets reloaded with every frame for this
139 void ax25_ds_t3timer_expiry(ax25_cb
*ax25
)
141 ax25_send_control(ax25
, AX25_DISC
, AX25_POLLON
, AX25_COMMAND
);
143 ax25_disconnect(ax25
, ETIMEDOUT
);
146 /* dl1bke 960228: close the connection when IDLE expires.
147 * unlike T3 this timer gets reloaded only on
150 void ax25_ds_idletimer_expiry(ax25_cb
*ax25
)
152 ax25_clear_queues(ax25
);
155 ax25
->state
= AX25_STATE_2
;
157 ax25_calculate_t1(ax25
);
158 ax25_start_t1timer(ax25
);
159 ax25_stop_t3timer(ax25
);
161 if (ax25
->sk
!= NULL
) {
162 ax25
->sk
->state
= TCP_CLOSE
;
164 ax25
->sk
->shutdown
|= SEND_SHUTDOWN
;
166 ax25
->sk
->state_change(ax25
->sk
);
171 /* dl1bke 960114: The DAMA protocol requires to send data and SABM/DISC
172 * within the poll of any connected channel. Remember
173 * that we are not allowed to send anything unless we
174 * get polled by the Master.
176 * Thus we'll have to do parts of our T1 handling in
177 * ax25_enquiry_response().
179 void ax25_ds_t1_timeout(ax25_cb
*ax25
)
181 switch (ax25
->state
) {
184 if (ax25
->n2count
== ax25
->n2
) {
185 if (ax25
->modulus
== AX25_MODULUS
) {
186 ax25_disconnect(ax25
, ETIMEDOUT
);
189 ax25
->modulus
= AX25_MODULUS
;
190 ax25
->window
= ax25
->ax25_dev
->values
[AX25_VALUES_WINDOW
];
192 ax25_send_control(ax25
, AX25_SABM
, AX25_POLLOFF
, AX25_COMMAND
);
196 if (ax25
->modulus
== AX25_MODULUS
)
197 ax25_send_control(ax25
, AX25_SABM
, AX25_POLLOFF
, AX25_COMMAND
);
199 ax25_send_control(ax25
, AX25_SABME
, AX25_POLLOFF
, AX25_COMMAND
);
204 if (ax25
->n2count
== ax25
->n2
) {
205 ax25_send_control(ax25
, AX25_DISC
, AX25_POLLON
, AX25_COMMAND
);
206 ax25_disconnect(ax25
, ETIMEDOUT
);
214 if (ax25
->n2count
== ax25
->n2
) {
215 ax25_send_control(ax25
, AX25_DM
, AX25_POLLON
, AX25_RESPONSE
);
216 ax25_disconnect(ax25
, ETIMEDOUT
);
224 ax25_calculate_t1(ax25
);
225 ax25_start_t1timer(ax25
);