1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
5 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
6 * Copyright (C) Tomi Manninen OH2BNS (oh2bns@sral.fi)
7 * Copyright (C) Darryl Miles G7LED (dlm@g7led.demon.co.uk)
8 * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
9 * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
10 * Copyright (C) 2002 Ralf Baechle DO1GRB (ralf@gnu.org)
12 #include <linux/errno.h>
13 #include <linux/types.h>
14 #include <linux/socket.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/jiffies.h>
19 #include <linux/timer.h>
20 #include <linux/string.h>
21 #include <linux/sockios.h>
22 #include <linux/net.h>
24 #include <linux/inet.h>
25 #include <linux/netdevice.h>
26 #include <linux/skbuff.h>
28 #include <linux/uaccess.h>
29 #include <linux/fcntl.h>
31 #include <linux/interrupt.h>
33 static void ax25_heartbeat_expiry(struct timer_list
*);
34 static void ax25_t1timer_expiry(struct timer_list
*);
35 static void ax25_t2timer_expiry(struct timer_list
*);
36 static void ax25_t3timer_expiry(struct timer_list
*);
37 static void ax25_idletimer_expiry(struct timer_list
*);
39 void ax25_setup_timers(ax25_cb
*ax25
)
41 timer_setup(&ax25
->timer
, ax25_heartbeat_expiry
, 0);
42 timer_setup(&ax25
->t1timer
, ax25_t1timer_expiry
, 0);
43 timer_setup(&ax25
->t2timer
, ax25_t2timer_expiry
, 0);
44 timer_setup(&ax25
->t3timer
, ax25_t3timer_expiry
, 0);
45 timer_setup(&ax25
->idletimer
, ax25_idletimer_expiry
, 0);
48 void ax25_start_heartbeat(ax25_cb
*ax25
)
50 mod_timer(&ax25
->timer
, jiffies
+ 5 * HZ
);
53 void ax25_start_t1timer(ax25_cb
*ax25
)
55 mod_timer(&ax25
->t1timer
, jiffies
+ ax25
->t1
);
58 void ax25_start_t2timer(ax25_cb
*ax25
)
60 mod_timer(&ax25
->t2timer
, jiffies
+ ax25
->t2
);
63 void ax25_start_t3timer(ax25_cb
*ax25
)
66 mod_timer(&ax25
->t3timer
, jiffies
+ ax25
->t3
);
68 del_timer(&ax25
->t3timer
);
71 void ax25_start_idletimer(ax25_cb
*ax25
)
74 mod_timer(&ax25
->idletimer
, jiffies
+ ax25
->idle
);
76 del_timer(&ax25
->idletimer
);
79 void ax25_stop_heartbeat(ax25_cb
*ax25
)
81 del_timer(&ax25
->timer
);
84 void ax25_stop_t1timer(ax25_cb
*ax25
)
86 del_timer(&ax25
->t1timer
);
89 void ax25_stop_t2timer(ax25_cb
*ax25
)
91 del_timer(&ax25
->t2timer
);
94 void ax25_stop_t3timer(ax25_cb
*ax25
)
96 del_timer(&ax25
->t3timer
);
99 void ax25_stop_idletimer(ax25_cb
*ax25
)
101 del_timer(&ax25
->idletimer
);
104 int ax25_t1timer_running(ax25_cb
*ax25
)
106 return timer_pending(&ax25
->t1timer
);
109 unsigned long ax25_display_timer(struct timer_list
*timer
)
111 long delta
= timer
->expires
- jiffies
;
113 if (!timer_pending(timer
))
116 return max(0L, delta
);
119 EXPORT_SYMBOL(ax25_display_timer
);
121 static void ax25_heartbeat_expiry(struct timer_list
*t
)
123 int proto
= AX25_PROTO_STD_SIMPLEX
;
124 ax25_cb
*ax25
= from_timer(ax25
, t
, timer
);
127 proto
= ax25
->ax25_dev
->values
[AX25_VALUES_PROTOCOL
];
130 case AX25_PROTO_STD_SIMPLEX
:
131 case AX25_PROTO_STD_DUPLEX
:
132 ax25_std_heartbeat_expiry(ax25
);
135 #ifdef CONFIG_AX25_DAMA_SLAVE
136 case AX25_PROTO_DAMA_SLAVE
:
137 if (ax25
->ax25_dev
->dama
.slave
)
138 ax25_ds_heartbeat_expiry(ax25
);
140 ax25_std_heartbeat_expiry(ax25
);
146 static void ax25_t1timer_expiry(struct timer_list
*t
)
148 ax25_cb
*ax25
= from_timer(ax25
, t
, t1timer
);
150 switch (ax25
->ax25_dev
->values
[AX25_VALUES_PROTOCOL
]) {
151 case AX25_PROTO_STD_SIMPLEX
:
152 case AX25_PROTO_STD_DUPLEX
:
153 ax25_std_t1timer_expiry(ax25
);
156 #ifdef CONFIG_AX25_DAMA_SLAVE
157 case AX25_PROTO_DAMA_SLAVE
:
158 if (!ax25
->ax25_dev
->dama
.slave
)
159 ax25_std_t1timer_expiry(ax25
);
165 static void ax25_t2timer_expiry(struct timer_list
*t
)
167 ax25_cb
*ax25
= from_timer(ax25
, t
, t2timer
);
169 switch (ax25
->ax25_dev
->values
[AX25_VALUES_PROTOCOL
]) {
170 case AX25_PROTO_STD_SIMPLEX
:
171 case AX25_PROTO_STD_DUPLEX
:
172 ax25_std_t2timer_expiry(ax25
);
175 #ifdef CONFIG_AX25_DAMA_SLAVE
176 case AX25_PROTO_DAMA_SLAVE
:
177 if (!ax25
->ax25_dev
->dama
.slave
)
178 ax25_std_t2timer_expiry(ax25
);
184 static void ax25_t3timer_expiry(struct timer_list
*t
)
186 ax25_cb
*ax25
= from_timer(ax25
, t
, t3timer
);
188 switch (ax25
->ax25_dev
->values
[AX25_VALUES_PROTOCOL
]) {
189 case AX25_PROTO_STD_SIMPLEX
:
190 case AX25_PROTO_STD_DUPLEX
:
191 ax25_std_t3timer_expiry(ax25
);
194 #ifdef CONFIG_AX25_DAMA_SLAVE
195 case AX25_PROTO_DAMA_SLAVE
:
196 if (ax25
->ax25_dev
->dama
.slave
)
197 ax25_ds_t3timer_expiry(ax25
);
199 ax25_std_t3timer_expiry(ax25
);
205 static void ax25_idletimer_expiry(struct timer_list
*t
)
207 ax25_cb
*ax25
= from_timer(ax25
, t
, idletimer
);
209 switch (ax25
->ax25_dev
->values
[AX25_VALUES_PROTOCOL
]) {
210 case AX25_PROTO_STD_SIMPLEX
:
211 case AX25_PROTO_STD_DUPLEX
:
212 ax25_std_idletimer_expiry(ax25
);
215 #ifdef CONFIG_AX25_DAMA_SLAVE
216 case AX25_PROTO_DAMA_SLAVE
:
217 if (ax25
->ax25_dev
->dama
.slave
)
218 ax25_ds_idletimer_expiry(ax25
);
220 ax25_std_idletimer_expiry(ax25
);