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 028a Jonathan(G4KLX) New state machine based on SDL diagrams.
14 * AX.25 028b Jonathan(G4KLX) Extracted AX25 control block from the
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 Standard and DAMA code into separate files.
22 * Joerg(DL1BKE) Fixed DAMA Slave. We are *required* to start with
23 * standard AX.25 mode.
24 * AX.25 037 Jonathan(G4KLX) New timer architecture.
25 * Tomi(OH2BNS) Fixed heartbeat expiry (check ax25_dev).
28 #include <linux/config.h>
29 #include <linux/errno.h>
30 #include <linux/types.h>
31 #include <linux/socket.h>
33 #include <linux/kernel.h>
34 #include <linux/sched.h>
35 #include <linux/timer.h>
36 #include <linux/string.h>
37 #include <linux/sockios.h>
38 #include <linux/net.h>
40 #include <linux/inet.h>
41 #include <linux/netdevice.h>
42 #include <linux/skbuff.h>
44 #include <asm/uaccess.h>
45 #include <asm/system.h>
46 #include <linux/fcntl.h>
48 #include <linux/interrupt.h>
50 static void ax25_heartbeat_expiry(unsigned long);
51 static void ax25_t1timer_expiry(unsigned long);
52 static void ax25_t2timer_expiry(unsigned long);
53 static void ax25_t3timer_expiry(unsigned long);
54 static void ax25_idletimer_expiry(unsigned long);
56 void ax25_start_heartbeat(ax25_cb *ax25)
58 del_timer(&ax25->timer);
60 ax25->timer.data = (unsigned long)ax25;
61 ax25->timer.function = &ax25_heartbeat_expiry;
62 ax25->timer.expires = jiffies + 5 * HZ;
64 add_timer(&ax25->timer);
67 void ax25_start_t1timer(ax25_cb *ax25)
69 del_timer(&ax25->t1timer);
71 ax25->t1timer.data = (unsigned long)ax25;
72 ax25->t1timer.function = &ax25_t1timer_expiry;
73 ax25->t1timer.expires = jiffies + ax25->t1;
75 add_timer(&ax25->t1timer);
78 void ax25_start_t2timer(ax25_cb *ax25)
80 del_timer(&ax25->t2timer);
82 ax25->t2timer.data = (unsigned long)ax25;
83 ax25->t2timer.function = &ax25_t2timer_expiry;
84 ax25->t2timer.expires = jiffies + ax25->t2;
86 add_timer(&ax25->t2timer);
89 void ax25_start_t3timer(ax25_cb *ax25)
91 del_timer(&ax25->t3timer);
94 ax25->t3timer.data = (unsigned long)ax25;
95 ax25->t3timer.function = &ax25_t3timer_expiry;
96 ax25->t3timer.expires = jiffies + ax25->t3;
98 add_timer(&ax25->t3timer);
102 void ax25_start_idletimer(ax25_cb *ax25)
104 del_timer(&ax25->idletimer);
106 if (ax25->idle > 0) {
107 ax25->idletimer.data = (unsigned long)ax25;
108 ax25->idletimer.function = &ax25_idletimer_expiry;
109 ax25->idletimer.expires = jiffies + ax25->idle;
111 add_timer(&ax25->idletimer);
115 void ax25_stop_heartbeat(ax25_cb *ax25)
117 del_timer(&ax25->timer);
120 void ax25_stop_t1timer(ax25_cb *ax25)
122 del_timer(&ax25->t1timer);
125 void ax25_stop_t2timer(ax25_cb *ax25)
127 del_timer(&ax25->t2timer);
130 void ax25_stop_t3timer(ax25_cb *ax25)
132 del_timer(&ax25->t3timer);
135 void ax25_stop_idletimer(ax25_cb *ax25)
137 del_timer(&ax25->idletimer);
140 int ax25_t1timer_running(ax25_cb *ax25)
142 return timer_pending(&ax25->t1timer);
145 unsigned long ax25_display_timer(struct timer_list *timer)
147 if (!timer_pending(timer))
150 return timer->expires - jiffies;
153 static void ax25_heartbeat_expiry(unsigned long param)
155 ax25_cb *ax25 = (ax25_cb *)param;
156 int proto = AX25_PROTO_STD_SIMPLEX;
159 proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL];
162 case AX25_PROTO_STD_SIMPLEX:
163 case AX25_PROTO_STD_DUPLEX:
164 ax25_std_heartbeat_expiry(ax25);
167 #ifdef CONFIG_AX25_DAMA_SLAVE
168 case AX25_PROTO_DAMA_SLAVE:
169 if (ax25->ax25_dev->dama.slave)
170 ax25_ds_heartbeat_expiry(ax25);
172 ax25_std_heartbeat_expiry(ax25);
178 static void ax25_t1timer_expiry(unsigned long param)
180 ax25_cb *ax25 = (ax25_cb *)param;
182 switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
183 case AX25_PROTO_STD_SIMPLEX:
184 case AX25_PROTO_STD_DUPLEX:
185 ax25_std_t1timer_expiry(ax25);
188 #ifdef CONFIG_AX25_DAMA_SLAVE
189 case AX25_PROTO_DAMA_SLAVE:
190 if (!ax25->ax25_dev->dama.slave)
191 ax25_std_t1timer_expiry(ax25);
197 static void ax25_t2timer_expiry(unsigned long param)
199 ax25_cb *ax25 = (ax25_cb *)param;
201 switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
202 case AX25_PROTO_STD_SIMPLEX:
203 case AX25_PROTO_STD_DUPLEX:
204 ax25_std_t2timer_expiry(ax25);
207 #ifdef CONFIG_AX25_DAMA_SLAVE
208 case AX25_PROTO_DAMA_SLAVE:
209 if (!ax25->ax25_dev->dama.slave)
210 ax25_std_t2timer_expiry(ax25);
216 static void ax25_t3timer_expiry(unsigned long param)
218 ax25_cb *ax25 = (ax25_cb *)param;
220 switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
221 case AX25_PROTO_STD_SIMPLEX:
222 case AX25_PROTO_STD_DUPLEX:
223 ax25_std_t3timer_expiry(ax25);
226 #ifdef CONFIG_AX25_DAMA_SLAVE
227 case AX25_PROTO_DAMA_SLAVE:
228 if (ax25->ax25_dev->dama.slave)
229 ax25_ds_t3timer_expiry(ax25);
231 ax25_std_t3timer_expiry(ax25);
237 static void ax25_idletimer_expiry(unsigned long param)
239 ax25_cb *ax25 = (ax25_cb *)param;
241 switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
242 case AX25_PROTO_STD_SIMPLEX:
243 case AX25_PROTO_STD_DUPLEX:
244 ax25_std_idletimer_expiry(ax25);
247 #ifdef CONFIG_AX25_DAMA_SLAVE
248 case AX25_PROTO_DAMA_SLAVE:
249 if (ax25->ax25_dev->dama.slave)
250 ax25_ds_idletimer_expiry(ax25);
252 ax25_std_idletimer_expiry(ax25);