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.
27 #include <linux/config.h>
28 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
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 (ax25
->t1timer
.prev
!= NULL
|| ax25
->t1timer
.next
!= NULL
);
145 unsigned long ax25_display_timer(struct timer_list
*timer
)
147 if (timer
->prev
== NULL
&& timer
->next
== NULL
)
150 return timer
->expires
- jiffies
;
153 static void ax25_heartbeat_expiry(unsigned long param
)
155 ax25_cb
*ax25
= (ax25_cb
*)param
;
157 switch (ax25
->ax25_dev
->values
[AX25_VALUES_PROTOCOL
]) {
158 case AX25_PROTO_STD_SIMPLEX
:
159 case AX25_PROTO_STD_DUPLEX
:
160 ax25_std_heartbeat_expiry(ax25
);
163 #ifdef CONFIG_AX25_DAMA_SLAVE
164 case AX25_PROTO_DAMA_SLAVE
:
165 if (ax25
->ax25_dev
->dama
.slave
)
166 ax25_ds_heartbeat_expiry(ax25
);
168 ax25_std_heartbeat_expiry(ax25
);
174 static void ax25_t1timer_expiry(unsigned long param
)
176 ax25_cb
*ax25
= (ax25_cb
*)param
;
178 switch (ax25
->ax25_dev
->values
[AX25_VALUES_PROTOCOL
]) {
179 case AX25_PROTO_STD_SIMPLEX
:
180 case AX25_PROTO_STD_DUPLEX
:
181 ax25_std_t1timer_expiry(ax25
);
184 #ifdef CONFIG_AX25_DAMA_SLAVE
185 case AX25_PROTO_DAMA_SLAVE
:
186 if (!ax25
->ax25_dev
->dama
.slave
)
187 ax25_std_t1timer_expiry(ax25
);
193 static void ax25_t2timer_expiry(unsigned long param
)
195 ax25_cb
*ax25
= (ax25_cb
*)param
;
197 switch (ax25
->ax25_dev
->values
[AX25_VALUES_PROTOCOL
]) {
198 case AX25_PROTO_STD_SIMPLEX
:
199 case AX25_PROTO_STD_DUPLEX
:
200 ax25_std_t2timer_expiry(ax25
);
203 #ifdef CONFIG_AX25_DAMA_SLAVE
204 case AX25_PROTO_DAMA_SLAVE
:
205 if (!ax25
->ax25_dev
->dama
.slave
)
206 ax25_std_t2timer_expiry(ax25
);
212 static void ax25_t3timer_expiry(unsigned long param
)
214 ax25_cb
*ax25
= (ax25_cb
*)param
;
216 switch (ax25
->ax25_dev
->values
[AX25_VALUES_PROTOCOL
]) {
217 case AX25_PROTO_STD_SIMPLEX
:
218 case AX25_PROTO_STD_DUPLEX
:
219 ax25_std_t3timer_expiry(ax25
);
222 #ifdef CONFIG_AX25_DAMA_SLAVE
223 case AX25_PROTO_DAMA_SLAVE
:
224 if (ax25
->ax25_dev
->dama
.slave
)
225 ax25_ds_t3timer_expiry(ax25
);
227 ax25_std_t3timer_expiry(ax25
);
233 static void ax25_idletimer_expiry(unsigned long param
)
235 ax25_cb
*ax25
= (ax25_cb
*)param
;
237 switch (ax25
->ax25_dev
->values
[AX25_VALUES_PROTOCOL
]) {
238 case AX25_PROTO_STD_SIMPLEX
:
239 case AX25_PROTO_STD_DUPLEX
:
240 ax25_std_idletimer_expiry(ax25
);
243 #ifdef CONFIG_AX25_DAMA_SLAVE
244 case AX25_PROTO_DAMA_SLAVE
:
245 if (ax25
->ax25_dev
->dama
.slave
)
246 ax25_ds_idletimer_expiry(ax25
);
248 ax25_std_idletimer_expiry(ax25
);