2507fe5abfeeb8523d9e057ac5be179c14239a23
[dragonfly.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  * $DragonFly: src/sys/net/i4b/layer3/i4b_l3timer.c,v 1.3 2003/08/07 21:17:29 dillon Exp $
34  *
35  *      last edit-date: [Thu Aug 24 12:49:50 2000]
36  *
37  *---------------------------------------------------------------------------*/
38
39 #ifdef __FreeBSD__
40 #include "use_i4bq931.h"
41 #else
42 #define NI4BQ931        1
43 #endif
44 #if NI4BQ931 > 0
45
46 #include <sys/param.h>
47 #include <sys/kernel.h>
48 #include <sys/systm.h>
49 #include <sys/mbuf.h>
50
51 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
52 #include <sys/callout.h>
53 #endif
54
55 #ifdef __FreeBSD__
56 #include <net/i4b/include/machine/i4b_debug.h>
57 #include <net/i4b/include/machine/i4b_ioctl.h>
58 #else
59 #include <i4b/i4b_debug.h>
60 #include <i4b/i4b_ioctl.h>
61 #endif
62
63 #include "../include/i4b_global.h"
64 #include "../include/i4b_l3l4.h"
65
66 #include "i4b_l3.h"
67 #include "i4b_l3fsm.h"
68
69
70 /*---------------------------------------------------------------------------*
71  *      stop all layer 3 timers
72  *---------------------------------------------------------------------------*/
73 void i4b_l3_stop_all_timers(call_desc_t *cd)
74 {
75         T303_stop(cd);
76         T305_stop(cd);
77         T308_stop(cd);
78         T309_stop(cd);
79         T310_stop(cd);
80         T313_stop(cd);  
81 }
82         
83 /*---------------------------------------------------------------------------*
84  *      timer T303 timeout function
85  *---------------------------------------------------------------------------*/
86 static void
87 T303_timeout(call_desc_t *cd)
88 {
89         NDBGL3(L3_T_ERR, "SETUP not answered, cr = %d", cd->cr);
90         next_l3state(cd, EV_T303EXP);
91 }
92
93 /*---------------------------------------------------------------------------*
94  *      timer T303 start
95  *---------------------------------------------------------------------------*/
96 void
97 T303_start(call_desc_t *cd)
98 {
99         if (cd->T303 == TIMER_ACTIVE)
100                 return;
101                 
102         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
103         cd->T303 = TIMER_ACTIVE;
104
105         START_TIMER(cd->T303_callout, T303_timeout, cd, T303VAL);
106 }
107
108 /*---------------------------------------------------------------------------*
109  *      timer T303 stop
110  *---------------------------------------------------------------------------*/
111 void
112 T303_stop(call_desc_t *cd)
113 {
114         CRIT_VAR;
115         CRIT_BEG;
116         
117         if(cd->T303 != TIMER_IDLE)
118         {
119                 STOP_TIMER(cd->T303_callout, T303_timeout, cd);
120                 cd->T303 = TIMER_IDLE;
121         }
122         CRIT_END;
123         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
124 }
125
126 /*---------------------------------------------------------------------------*
127  *      timer T305 timeout function
128  *---------------------------------------------------------------------------*/
129 static void
130 T305_timeout(call_desc_t *cd)
131 {
132         NDBGL3(L3_T_ERR, "DISC not answered, cr = %d", cd->cr);
133         next_l3state(cd, EV_T305EXP);
134 }
135
136 /*---------------------------------------------------------------------------*
137  *      timer T305 start
138  *---------------------------------------------------------------------------*/
139 void
140 T305_start(call_desc_t *cd)
141 {
142         if (cd->T305 == TIMER_ACTIVE)
143                 return;
144                 
145         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
146         cd->T305 = TIMER_ACTIVE;
147
148         START_TIMER(cd->T305_callout, T305_timeout, cd, T305VAL);
149 }
150
151 /*---------------------------------------------------------------------------*
152  *      timer T305 stop
153  *---------------------------------------------------------------------------*/
154 void
155 T305_stop(call_desc_t *cd)
156 {
157         CRIT_VAR;
158         CRIT_BEG;
159         
160         if(cd->T305 != TIMER_IDLE)
161         {
162                 STOP_TIMER(cd->T305_callout, T305_timeout, cd);
163                 cd->T305 = TIMER_IDLE;
164         }
165         CRIT_END;
166         
167         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
168 }
169
170 /*---------------------------------------------------------------------------*
171  *      timer T308 timeout function
172  *---------------------------------------------------------------------------*/
173 static void
174 T308_timeout(call_desc_t *cd)
175 {
176         NDBGL3(L3_T_ERR, "REL not answered, cr = %d", cd->cr);
177         next_l3state(cd, EV_T308EXP);
178 }
179
180 /*---------------------------------------------------------------------------*
181  *      timer T308 start
182  *---------------------------------------------------------------------------*/
183 void
184 T308_start(call_desc_t *cd)
185 {
186         if(cd->T308 == TIMER_ACTIVE)
187                 return;
188                 
189         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
190         cd->T308 = TIMER_ACTIVE;
191
192         START_TIMER(cd->T308_callout, T308_timeout, cd, T308VAL);
193 }
194
195 /*---------------------------------------------------------------------------*
196  *      timer T308 stop
197  *---------------------------------------------------------------------------*/
198 void
199 T308_stop(call_desc_t *cd)
200 {
201         CRIT_VAR;
202         CRIT_BEG;
203         
204         if(cd->T308 != TIMER_IDLE)
205         {
206                 STOP_TIMER(cd->T308_callout, T308_timeout, cd);
207                 cd->T308 = TIMER_IDLE;
208         }
209         CRIT_END;
210         
211         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
212 }
213
214 /*---------------------------------------------------------------------------*
215  *      timer T309 timeout function
216  *---------------------------------------------------------------------------*/
217 static void
218 T309_timeout(call_desc_t *cd)
219 {
220         NDBGL3(L3_T_ERR, "datalink not reconnected, cr = %d", cd->cr);
221         next_l3state(cd, EV_T309EXP);
222 }
223
224 /*---------------------------------------------------------------------------*
225  *      timer T309 start
226  *---------------------------------------------------------------------------*/
227 void
228 T309_start(call_desc_t *cd)
229 {
230         if (cd->T309 == TIMER_ACTIVE)
231                 return;
232
233         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
234         cd->T309 = TIMER_ACTIVE;
235
236         START_TIMER(cd->T309_callout, T309_timeout, cd, T309VAL);
237 }
238
239 /*---------------------------------------------------------------------------*
240  *      timer T309 stop
241  *---------------------------------------------------------------------------*/
242 void
243 T309_stop(call_desc_t *cd)
244 {
245         CRIT_VAR;
246         CRIT_BEG;
247         
248         if(cd->T309 != TIMER_IDLE)
249         {
250                 STOP_TIMER(cd->T309_callout, T309_timeout, cd);
251                 cd->T309 = TIMER_IDLE;
252         }
253         CRIT_END;
254         
255         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
256 }
257
258 /*---------------------------------------------------------------------------*
259  *      timer T310 timeout function
260  *---------------------------------------------------------------------------*/
261 static void
262 T310_timeout(call_desc_t *cd)
263 {
264         NDBGL3(L3_T_ERR, "CALL PROC timeout, cr = %d", cd->cr);
265         next_l3state(cd, EV_T310EXP);
266 }
267
268 /*---------------------------------------------------------------------------*
269  *      timer T310 start
270  *---------------------------------------------------------------------------*/
271 void
272 T310_start(call_desc_t *cd)
273 {
274         if (cd->T310 == TIMER_ACTIVE)
275                 return;
276                 
277         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
278         cd->T310 = TIMER_ACTIVE;
279
280         START_TIMER(cd->T310_callout, T310_timeout, cd, T310VAL);
281 }
282
283 /*---------------------------------------------------------------------------*
284  *      timer T310 stop
285  *---------------------------------------------------------------------------*/
286 void
287 T310_stop(call_desc_t *cd)
288 {
289         CRIT_VAR;
290         CRIT_BEG;
291         
292         if(cd->T310 != TIMER_IDLE)
293         {
294                 STOP_TIMER(cd->T310_callout, T310_timeout, cd);
295                 cd->T310 = TIMER_IDLE;
296         }
297         CRIT_END;
298
299         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
300 }
301
302 /*---------------------------------------------------------------------------*
303  *      timer T313 timeout function
304  *---------------------------------------------------------------------------*/
305 static void
306 T313_timeout(call_desc_t *cd)
307 {
308         NDBGL3(L3_T_ERR, "CONN ACK not received, cr = %d", cd->cr);
309         next_l3state(cd, EV_T313EXP);
310 }
311
312 /*---------------------------------------------------------------------------*
313  *      timer T313 start
314  *---------------------------------------------------------------------------*/
315 void
316 T313_start(call_desc_t *cd)
317 {
318         if (cd->T313 == TIMER_ACTIVE)
319                 return;
320                 
321         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
322         cd->T313 = TIMER_ACTIVE;
323
324         START_TIMER(cd->T313_callout, T313_timeout, cd, T313VAL);
325 }
326
327 /*---------------------------------------------------------------------------*
328  *      timer T313 stop
329  *---------------------------------------------------------------------------*/
330 void
331 T313_stop(call_desc_t *cd)
332 {
333         CRIT_VAR;
334         CRIT_BEG;
335         
336         if(cd->T313 != TIMER_IDLE)
337         {
338                 cd->T313 = TIMER_IDLE;
339                 STOP_TIMER(cd->T313_callout, T313_timeout, cd);
340         }
341         CRIT_END;
342         
343         NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
344 }
345
346 #endif /* NI4BQ931 > 0 */
347