Initial import from FreeBSD RELENG_4:
[games.git] / sys / net / i4b / layer3 / i4b_l3timer.c
1 /*
2  * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      i4b_l3timer.c - timer and timeout handling for layer 3
28  *      ------------------------------------------------------
29  *
30  *      $Id: i4b_l3timer.c,v 1.17 2000/08/24 11:48:58 hm Exp $ 
31  *
32  * $FreeBSD: src/sys/i4b/layer3/i4b_l3timer.c,v 1.6.2.1 2001/08/10 14:08:42 obrien Exp $
33  *
34  *      last edit-date: [Thu Aug 24 12:49:50 2000]
35  *
36  *---------------------------------------------------------------------------*/
37
38 #ifdef __FreeBSD__
39 #include "i4bq931.h"
40 #else
41 #define NI4BQ931        1
42 #endif
43 #if NI4BQ931 > 0
44
45 #include <sys/param.h>
46 #include <sys/kernel.h>
47 #include <sys/systm.h>
48 #include <sys/mbuf.h>
49
50 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
51 #include <sys/callout.h>
52 #endif
53
54 #ifdef __FreeBSD__
55 #include <machine/i4b_debug.h>
56 #include <machine/i4b_ioctl.h>
57 #else
58 #include <i4b/i4b_debug.h>
59 #include <i4b/i4b_ioctl.h>
60 #endif
61
62 #include <i4b/include/i4b_global.h>
63 #include <i4b/include/i4b_l3l4.h>
64
65 #include <i4b/layer3/i4b_l3.h>
66 #include <i4b/layer3/i4b_l3fsm.h>
67
68
69 /*---------------------------------------------------------------------------*
70  *      stop all layer 3 timers
71  *---------------------------------------------------------------------------*/
72 void i4b_l3_stop_all_timers(call_desc_t *cd)
73 {
74         T303_stop(cd);
75         T305_stop(cd);
76         T308_stop(cd);
77         T309_stop(cd);
78         T310_stop(cd);
79         T313_stop(cd);  
80 }
81         
82 /*---------------------------------------------------------------------------*
83  *      timer T303 timeout function
84  *---------------------------------------------------------------------------*/
85 static void
86 T303_timeout(call_desc_t *cd)
87 {
88         NDBGL3(L3_T_ERR, "SETUP not answered, cr = %d", cd->cr);
89         next_l3state(cd, EV_T303EXP);
90 }
91
92 /*---------------------------------------------------------------------------*
93  *      timer T303 start
94  *---------------------------------------------------------------------------*/
95 void
96 T303_start(call_desc_t *cd)
97 {
98         if (cd->T303 == TIMER_ACTIVE)
99                 return;
100                 
101         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
102         cd->T303 = TIMER_ACTIVE;
103
104         START_TIMER(cd->T303_callout, T303_timeout, cd, T303VAL);
105 }
106
107 /*---------------------------------------------------------------------------*
108  *      timer T303 stop
109  *---------------------------------------------------------------------------*/
110 void
111 T303_stop(call_desc_t *cd)
112 {
113         CRIT_VAR;
114         CRIT_BEG;
115         
116         if(cd->T303 != TIMER_IDLE)
117         {
118                 STOP_TIMER(cd->T303_callout, T303_timeout, cd);
119                 cd->T303 = TIMER_IDLE;
120         }
121         CRIT_END;
122         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
123 }
124
125 /*---------------------------------------------------------------------------*
126  *      timer T305 timeout function
127  *---------------------------------------------------------------------------*/
128 static void
129 T305_timeout(call_desc_t *cd)
130 {
131         NDBGL3(L3_T_ERR, "DISC not answered, cr = %d", cd->cr);
132         next_l3state(cd, EV_T305EXP);
133 }
134
135 /*---------------------------------------------------------------------------*
136  *      timer T305 start
137  *---------------------------------------------------------------------------*/
138 void
139 T305_start(call_desc_t *cd)
140 {
141         if (cd->T305 == TIMER_ACTIVE)
142                 return;
143                 
144         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
145         cd->T305 = TIMER_ACTIVE;
146
147         START_TIMER(cd->T305_callout, T305_timeout, cd, T305VAL);
148 }
149
150 /*---------------------------------------------------------------------------*
151  *      timer T305 stop
152  *---------------------------------------------------------------------------*/
153 void
154 T305_stop(call_desc_t *cd)
155 {
156         CRIT_VAR;
157         CRIT_BEG;
158         
159         if(cd->T305 != TIMER_IDLE)
160         {
161                 STOP_TIMER(cd->T305_callout, T305_timeout, cd);
162                 cd->T305 = TIMER_IDLE;
163         }
164         CRIT_END;
165         
166         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
167 }
168
169 /*---------------------------------------------------------------------------*
170  *      timer T308 timeout function
171  *---------------------------------------------------------------------------*/
172 static void
173 T308_timeout(call_desc_t *cd)
174 {
175         NDBGL3(L3_T_ERR, "REL not answered, cr = %d", cd->cr);
176         next_l3state(cd, EV_T308EXP);
177 }
178
179 /*---------------------------------------------------------------------------*
180  *      timer T308 start
181  *---------------------------------------------------------------------------*/
182 void
183 T308_start(call_desc_t *cd)
184 {
185         if(cd->T308 == TIMER_ACTIVE)
186                 return;
187                 
188         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
189         cd->T308 = TIMER_ACTIVE;
190
191         START_TIMER(cd->T308_callout, T308_timeout, cd, T308VAL);
192 }
193
194 /*---------------------------------------------------------------------------*
195  *      timer T308 stop
196  *---------------------------------------------------------------------------*/
197 void
198 T308_stop(call_desc_t *cd)
199 {
200         CRIT_VAR;
201         CRIT_BEG;
202         
203         if(cd->T308 != TIMER_IDLE)
204         {
205                 STOP_TIMER(cd->T308_callout, T308_timeout, cd);
206                 cd->T308 = TIMER_IDLE;
207         }
208         CRIT_END;
209         
210         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
211 }
212
213 /*---------------------------------------------------------------------------*
214  *      timer T309 timeout function
215  *---------------------------------------------------------------------------*/
216 static void
217 T309_timeout(call_desc_t *cd)
218 {
219         NDBGL3(L3_T_ERR, "datalink not reconnected, cr = %d", cd->cr);
220         next_l3state(cd, EV_T309EXP);
221 }
222
223 /*---------------------------------------------------------------------------*
224  *      timer T309 start
225  *---------------------------------------------------------------------------*/
226 void
227 T309_start(call_desc_t *cd)
228 {
229         if (cd->T309 == TIMER_ACTIVE)
230                 return;
231
232         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
233         cd->T309 = TIMER_ACTIVE;
234
235         START_TIMER(cd->T309_callout, T309_timeout, cd, T309VAL);
236 }
237
238 /*---------------------------------------------------------------------------*
239  *      timer T309 stop
240  *---------------------------------------------------------------------------*/
241 void
242 T309_stop(call_desc_t *cd)
243 {
244         CRIT_VAR;
245         CRIT_BEG;
246         
247         if(cd->T309 != TIMER_IDLE)
248         {
249                 STOP_TIMER(cd->T309_callout, T309_timeout, cd);
250                 cd->T309 = TIMER_IDLE;
251         }
252         CRIT_END;
253         
254         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
255 }
256
257 /*---------------------------------------------------------------------------*
258  *      timer T310 timeout function
259  *---------------------------------------------------------------------------*/
260 static void
261 T310_timeout(call_desc_t *cd)
262 {
263         NDBGL3(L3_T_ERR, "CALL PROC timeout, cr = %d", cd->cr);
264         next_l3state(cd, EV_T310EXP);
265 }
266
267 /*---------------------------------------------------------------------------*
268  *      timer T310 start
269  *---------------------------------------------------------------------------*/
270 void
271 T310_start(call_desc_t *cd)
272 {
273         if (cd->T310 == TIMER_ACTIVE)
274                 return;
275                 
276         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
277         cd->T310 = TIMER_ACTIVE;
278
279         START_TIMER(cd->T310_callout, T310_timeout, cd, T310VAL);
280 }
281
282 /*---------------------------------------------------------------------------*
283  *      timer T310 stop
284  *---------------------------------------------------------------------------*/
285 void
286 T310_stop(call_desc_t *cd)
287 {
288         CRIT_VAR;
289         CRIT_BEG;
290         
291         if(cd->T310 != TIMER_IDLE)
292         {
293                 STOP_TIMER(cd->T310_callout, T310_timeout, cd);
294                 cd->T310 = TIMER_IDLE;
295         }
296         CRIT_END;
297
298         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
299 }
300
301 /*---------------------------------------------------------------------------*
302  *      timer T313 timeout function
303  *---------------------------------------------------------------------------*/
304 static void
305 T313_timeout(call_desc_t *cd)
306 {
307         NDBGL3(L3_T_ERR, "CONN ACK not received, cr = %d", cd->cr);
308         next_l3state(cd, EV_T313EXP);
309 }
310
311 /*---------------------------------------------------------------------------*
312  *      timer T313 start
313  *---------------------------------------------------------------------------*/
314 void
315 T313_start(call_desc_t *cd)
316 {
317         if (cd->T313 == TIMER_ACTIVE)
318                 return;
319                 
320         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
321         cd->T313 = TIMER_ACTIVE;
322
323         START_TIMER(cd->T313_callout, T313_timeout, cd, T313VAL);
324 }
325
326 /*---------------------------------------------------------------------------*
327  *      timer T313 stop
328  *---------------------------------------------------------------------------*/
329 void
330 T313_stop(call_desc_t *cd)
331 {
332         CRIT_VAR;
333         CRIT_BEG;
334         
335         if(cd->T313 != TIMER_IDLE)
336         {
337                 cd->T313 = TIMER_IDLE;
338                 STOP_TIMER(cd->T313_callout, T313_timeout, cd);
339         }
340         CRIT_END;
341         
342         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
343 }
344
345 #endif /* NI4BQ931 > 0 */
346