* better
[mascara-docs.git] / i386 / linux-2.3.21 / net / ax25 / ax25_ds_timer.c
blob06135e9de491c8dfb81b7e04f5bffeededf0863b
1 /*
2 * AX.25 release 037
4 * This code REQUIRES 2.1.15 or higher/ NET3.038
6 * This module:
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.
12 * History
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>
23 #include <linux/in.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>
30 #include <net/ax25.h>
31 #include <linux/inet.h>
32 #include <linux/netdevice.h>
33 #include <linux/skbuff.h>
34 #include <net/sock.h>
35 #include <asm/uaccess.h>
36 #include <asm/system.h>
37 #include <linux/fcntl.h>
38 #include <linux/mm.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
48 * 1/10th of a second.
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;
57 add_timer(t);
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 */
68 return;
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);
76 * DAMA Slave Timeout
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;
83 ax25_cb *ax25;
85 if (ax25_dev == NULL || !ax25_dev->dama.slave)
86 return; /* Yikes! */
88 if (!ax25_dev->dama.slave_timeout || --ax25_dev->dama.slave_timeout) {
89 ax25_ds_set_timer(ax25_dev);
90 return;
93 for (ax25=ax25_list; ax25 != NULL; ax25 = ax25->next) {
94 if (ax25->ax25_dev != ax25_dev || !(ax25->condition & AX25_COND_DAMA_MODE))
95 continue;
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) {
108 case AX25_STATE_0:
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);
113 return;
115 break;
117 case AX25_STATE_3:
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;
126 break;
129 break;
132 ax25_start_heartbeat(ax25);
135 /* dl1bke 960114: T3 works much like the IDLE timeout, but
136 * gets reloaded with every frame for this
137 * connection.
139 void ax25_ds_t3timer_expiry(ax25_cb *ax25)
141 ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
142 ax25_dama_off(ax25);
143 ax25_disconnect(ax25, ETIMEDOUT);
146 /* dl1bke 960228: close the connection when IDLE expires.
147 * unlike T3 this timer gets reloaded only on
148 * I frames.
150 void ax25_ds_idletimer_expiry(ax25_cb *ax25)
152 ax25_clear_queues(ax25);
154 ax25->n2count = 0;
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;
163 ax25->sk->err = 0;
164 ax25->sk->shutdown |= SEND_SHUTDOWN;
165 if (!ax25->sk->dead)
166 ax25->sk->state_change(ax25->sk);
167 ax25->sk->dead = 1;
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) {
183 case AX25_STATE_1:
184 if (ax25->n2count == ax25->n2) {
185 if (ax25->modulus == AX25_MODULUS) {
186 ax25_disconnect(ax25, ETIMEDOUT);
187 return;
188 } else {
189 ax25->modulus = AX25_MODULUS;
190 ax25->window = ax25->ax25_dev->values[AX25_VALUES_WINDOW];
191 ax25->n2count = 0;
192 ax25_send_control(ax25, AX25_SABM, AX25_POLLOFF, AX25_COMMAND);
194 } else {
195 ax25->n2count++;
196 if (ax25->modulus == AX25_MODULUS)
197 ax25_send_control(ax25, AX25_SABM, AX25_POLLOFF, AX25_COMMAND);
198 else
199 ax25_send_control(ax25, AX25_SABME, AX25_POLLOFF, AX25_COMMAND);
201 break;
203 case AX25_STATE_2:
204 if (ax25->n2count == ax25->n2) {
205 ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
206 ax25_disconnect(ax25, ETIMEDOUT);
207 return;
208 } else {
209 ax25->n2count++;
211 break;
213 case AX25_STATE_3:
214 if (ax25->n2count == ax25->n2) {
215 ax25_send_control(ax25, AX25_DM, AX25_POLLON, AX25_RESPONSE);
216 ax25_disconnect(ax25, ETIMEDOUT);
217 return;
218 } else {
219 ax25->n2count++;
221 break;
224 ax25_calculate_t1(ax25);
225 ax25_start_t1timer(ax25);
228 #endif