Pause fix for mips64.
[linux-2.6/linux-mips.git] / net / ax25 / ax25_std_timer.c
blob4e97c51b8566893819292916ebd4519f699f620c
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 028a Jonathan(G4KLX) New state machine based on SDL diagrams.
14 * AX.25 028b Jonathan(G4KLX) Extracted AX25 control block from the
15 * sock structure.
16 * AX.25 029 Alan(GW4PTS) Switched to KA9Q constant names.
17 * AX.25 031 Joerg(DL1BKE) Added DAMA support
18 * AX.25 032 Joerg(DL1BKE) Fixed DAMA timeout bug
19 * AX.25 033 Jonathan(G4KLX) Modularisation functions.
20 * AX.25 035 Frederic(F1OAT) Support for pseudo-digipeating.
21 * AX.25 036 Jonathan(G4KLX) Split from ax25_timer.c.
22 * AX.25 037 Jonathan(G4KLX) New timer architecture.
25 #include <linux/config.h>
26 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
27 #include <linux/errno.h>
28 #include <linux/types.h>
29 #include <linux/socket.h>
30 #include <linux/in.h>
31 #include <linux/kernel.h>
32 #include <linux/sched.h>
33 #include <linux/timer.h>
34 #include <linux/string.h>
35 #include <linux/sockios.h>
36 #include <linux/net.h>
37 #include <net/ax25.h>
38 #include <linux/inet.h>
39 #include <linux/netdevice.h>
40 #include <linux/skbuff.h>
41 #include <net/sock.h>
42 #include <asm/uaccess.h>
43 #include <asm/system.h>
44 #include <linux/fcntl.h>
45 #include <linux/mm.h>
46 #include <linux/interrupt.h>
48 void ax25_std_heartbeat_expiry(ax25_cb *ax25)
50 switch (ax25->state) {
52 case AX25_STATE_0:
53 /* Magic here: If we listen() and a new link dies before it
54 is accepted() it isn't 'dead' so doesn't get removed. */
55 if (ax25->sk == NULL || ax25->sk->destroy || (ax25->sk->state == TCP_LISTEN && ax25->sk->dead)) {
56 ax25_destroy_socket(ax25);
57 return;
59 break;
61 case AX25_STATE_3:
62 case AX25_STATE_4:
64 * Check the state of the receive buffer.
66 if (ax25->sk != NULL) {
67 if (atomic_read(&ax25->sk->rmem_alloc) < (ax25->sk->rcvbuf / 2) &&
68 (ax25->condition & AX25_COND_OWN_RX_BUSY)) {
69 ax25->condition &= ~AX25_COND_OWN_RX_BUSY;
70 ax25->condition &= ~AX25_COND_ACK_PENDING;
71 ax25_send_control(ax25, AX25_RR, AX25_POLLOFF, AX25_RESPONSE);
72 break;
77 ax25_start_heartbeat(ax25);
80 void ax25_std_t2timer_expiry(ax25_cb *ax25)
82 if (ax25->condition & AX25_COND_ACK_PENDING) {
83 ax25->condition &= ~AX25_COND_ACK_PENDING;
84 ax25_std_timeout_response(ax25);
88 void ax25_std_t3timer_expiry(ax25_cb *ax25)
90 ax25->n2count = 0;
91 ax25_std_transmit_enquiry(ax25);
92 ax25->state = AX25_STATE_4;
95 void ax25_std_idletimer_expiry(ax25_cb *ax25)
97 ax25_clear_queues(ax25);
99 ax25->n2count = 0;
100 ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
101 ax25->state = AX25_STATE_2;
103 ax25_calculate_t1(ax25);
104 ax25_start_t1timer(ax25);
105 ax25_stop_t2timer(ax25);
106 ax25_stop_t3timer(ax25);
108 if (ax25->sk != NULL) {
109 ax25->sk->state = TCP_CLOSE;
110 ax25->sk->err = 0;
111 ax25->sk->shutdown |= SEND_SHUTDOWN;
112 if (!ax25->sk->dead)
113 ax25->sk->state_change(ax25->sk);
114 ax25->sk->dead = 1;
118 void ax25_std_t1timer_expiry(ax25_cb *ax25)
120 switch (ax25->state) {
121 case AX25_STATE_1:
122 if (ax25->n2count == ax25->n2) {
123 if (ax25->modulus == AX25_MODULUS) {
124 ax25_disconnect(ax25, ETIMEDOUT);
125 return;
126 } else {
127 ax25->modulus = AX25_MODULUS;
128 ax25->window = ax25->ax25_dev->values[AX25_VALUES_WINDOW];
129 ax25->n2count = 0;
130 ax25_send_control(ax25, AX25_SABM, AX25_POLLON, AX25_COMMAND);
132 } else {
133 ax25->n2count++;
134 if (ax25->modulus == AX25_MODULUS)
135 ax25_send_control(ax25, AX25_SABM, AX25_POLLON, AX25_COMMAND);
136 else
137 ax25_send_control(ax25, AX25_SABME, AX25_POLLON, AX25_COMMAND);
139 break;
141 case AX25_STATE_2:
142 if (ax25->n2count == ax25->n2) {
143 ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
144 ax25_disconnect(ax25, ETIMEDOUT);
145 return;
146 } else {
147 ax25->n2count++;
148 ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
150 break;
152 case AX25_STATE_3:
153 ax25->n2count = 1;
154 ax25_std_transmit_enquiry(ax25);
155 ax25->state = AX25_STATE_4;
156 break;
158 case AX25_STATE_4:
159 if (ax25->n2count == ax25->n2) {
160 ax25_send_control(ax25, AX25_DM, AX25_POLLON, AX25_RESPONSE);
161 ax25_disconnect(ax25, ETIMEDOUT);
162 return;
163 } else {
164 ax25->n2count++;
165 ax25_std_transmit_enquiry(ax25);
167 break;
170 ax25_calculate_t1(ax25);
171 ax25_start_t1timer(ax25);
174 #endif