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