2 * X.25 Packet Layer release 002
4 * This is ALPHA test software. This code may break your machine,
5 * randomly fail to work with new releases, misbehave and/or generally
6 * screw up. It might even work.
8 * This code REQUIRES 2.1.15 or higher
11 * This module is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
17 * X.25 001 Jonathan Naylor Started coding.
18 * X.25 002 Jonathan Naylor New timer architecture.
19 * Centralised disconnection processing.
22 #include <linux/errno.h>
23 #include <linux/types.h>
24 #include <linux/socket.h>
26 #include <linux/kernel.h>
27 #include <linux/jiffies.h>
28 #include <linux/timer.h>
29 #include <linux/string.h>
30 #include <linux/sockios.h>
31 #include <linux/net.h>
32 #include <linux/inet.h>
33 #include <linux/netdevice.h>
34 #include <linux/skbuff.h>
37 #include <asm/system.h>
38 #include <linux/fcntl.h>
40 #include <linux/interrupt.h>
43 static void x25_heartbeat_expiry(unsigned long);
44 static void x25_timer_expiry(unsigned long);
46 void x25_init_timers(struct sock *sk)
48 struct x25_opt *x25 = x25_sk(sk);
50 init_timer(&x25->timer);
51 x25->timer.data = (unsigned long)sk;
52 x25->timer.function = &x25_timer_expiry;
54 /* initialized by sock_init_data */
55 sk->sk_timer.data = (unsigned long)sk;
56 sk->sk_timer.function = &x25_heartbeat_expiry;
59 void x25_start_heartbeat(struct sock *sk)
61 mod_timer(&sk->sk_timer, jiffies + 5 * HZ);
64 void x25_stop_heartbeat(struct sock *sk)
66 del_timer(&sk->sk_timer);
69 void x25_start_t2timer(struct sock *sk)
71 struct x25_opt *x25 = x25_sk(sk);
73 mod_timer(&x25->timer, jiffies + x25->t2);
76 void x25_start_t21timer(struct sock *sk)
78 struct x25_opt *x25 = x25_sk(sk);
80 mod_timer(&x25->timer, jiffies + x25->t21);
83 void x25_start_t22timer(struct sock *sk)
85 struct x25_opt *x25 = x25_sk(sk);
87 mod_timer(&x25->timer, jiffies + x25->t22);
90 void x25_start_t23timer(struct sock *sk)
92 struct x25_opt *x25 = x25_sk(sk);
94 mod_timer(&x25->timer, jiffies + x25->t23);
97 void x25_stop_timer(struct sock *sk)
99 del_timer(&x25_sk(sk)->timer);
102 unsigned long x25_display_timer(struct sock *sk)
104 struct x25_opt *x25 = x25_sk(sk);
106 if (!timer_pending(&x25->timer))
109 return x25->timer.expires - jiffies;
112 static void x25_heartbeat_expiry(unsigned long param)
114 struct sock *sk = (struct sock *)param;
117 if (sock_owned_by_user(sk)) /* can currently only occur in state 3 */
118 goto restart_heartbeat;
120 switch (x25_sk(sk)->state) {
124 * Magic here: If we listen() and a new link dies
125 * before it is accepted() it isn't 'dead' so doesn't
128 if (sock_flag(sk, SOCK_DESTROY) ||
129 (sk->sk_state == TCP_LISTEN &&
130 sock_flag(sk, SOCK_DEAD))) {
131 x25_destroy_socket(sk);
138 * Check for the state of the receive buffer.
144 x25_start_heartbeat(sk);
150 * Timer has expired, it may have been T2, T21, T22, or T23. We can tell
151 * by the state machine state.
153 static inline void x25_do_timer_expiry(struct sock * sk)
155 struct x25_opt *x25 = x25_sk(sk);
157 switch (x25->state) {
159 case X25_STATE_3: /* T2 */
160 if (x25->condition & X25_COND_ACK_PENDING) {
161 x25->condition &= ~X25_COND_ACK_PENDING;
162 x25_enquiry_response(sk);
166 case X25_STATE_1: /* T21 */
167 case X25_STATE_4: /* T22 */
168 x25_write_internal(sk, X25_CLEAR_REQUEST);
169 x25->state = X25_STATE_2;
170 x25_start_t23timer(sk);
173 case X25_STATE_2: /* T23 */
174 x25_disconnect(sk, ETIMEDOUT, 0, 0);
179 static void x25_timer_expiry(unsigned long param)
181 struct sock *sk = (struct sock *)param;
184 if (sock_owned_by_user(sk)) { /* can currently only occur in state 3 */
185 if (x25_sk(sk)->state == X25_STATE_3)
186 x25_start_t2timer(sk);
188 x25_do_timer_expiry(sk);