]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i4b/layer2/i4b_l2timer.c
This commit was generated by cvs2svn to compensate for changes in r62914,
[FreeBSD/FreeBSD.git] / sys / i4b / layer2 / i4b_l2timer.c
1 /*
2  * Copyright (c) 1997, 1999 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_l2timer.c - layer 2 timer handling
28  *      --------------------------------------
29  *
30  *      $Id: i4b_l2timer.c,v 1.17 1999/12/13 21:25:27 hm Exp $ 
31  *
32  * $FreeBSD$
33  *
34  *      last edit-date: [Mon Dec 13 22:03:56 1999]
35  *
36  *---------------------------------------------------------------------------*/
37
38 #ifdef __FreeBSD__
39 #include "i4bq921.h"
40 #else
41 #define NI4BQ921        1
42 #endif
43 #if NI4BQ921 > 0
44
45 #include <sys/param.h>
46
47 #if defined(__FreeBSD__)
48 #else
49 #include <sys/ioctl.h>
50 #endif
51 #include <sys/kernel.h>
52 #include <sys/systm.h>
53 #include <sys/mbuf.h>
54 #include <sys/socket.h>
55 #include <net/if.h>
56
57 #ifdef __FreeBSD__
58 #include <machine/i4b_debug.h>
59 #include <machine/i4b_ioctl.h>
60 #else
61 #include <i4b/i4b_debug.h>
62 #include <i4b/i4b_ioctl.h>
63 #endif
64
65 #include <i4b/include/i4b_global.h>
66 #include <i4b/include/i4b_l1l2.h>
67 #include <i4b/include/i4b_l2l3.h>
68 #include <i4b/include/i4b_isdnq931.h>
69 #include <i4b/include/i4b_mbuf.h>
70
71 #include <i4b/layer2/i4b_l2.h>
72 #include <i4b/layer2/i4b_l2fsm.h>
73
74 /*---------------------------------------------------------------------------*
75  *      Q.921 timer T200 timeout function
76  *---------------------------------------------------------------------------*/
77 static void
78 i4b_T200_timeout(l2_softc_t *l2sc)
79 {
80         DBGL2(L2_T_ERR, "i4b_T200_timeout", ("unit %d, RC = %d\n", l2sc->unit, l2sc->RC));
81         i4b_next_l2state(l2sc, EV_T200EXP);
82 }
83
84 /*---------------------------------------------------------------------------*
85  *      Q.921 timer T200 start
86  *---------------------------------------------------------------------------*/
87 void
88 i4b_T200_start(l2_softc_t *l2sc)
89 {
90         if(l2sc->T200 == TIMER_ACTIVE)
91                 return;
92                 
93         DBGL2(L2_T_MSG, "i4b_T200_start", ("unit %d\n", l2sc->unit));
94         l2sc->T200 = TIMER_ACTIVE;
95
96 #if defined(__FreeBSD__)
97         l2sc->T200_callout = timeout((TIMEOUT_FUNC_T)i4b_T200_timeout, (void *)l2sc, T200DEF);
98 #else
99         timeout((TIMEOUT_FUNC_T)i4b_T200_timeout, (void *)l2sc, T200DEF);
100 #endif
101 }
102
103 /*---------------------------------------------------------------------------*
104  *      Q.921 timer T200 stop
105  *---------------------------------------------------------------------------*/
106 void
107 i4b_T200_stop(l2_softc_t *l2sc)
108 {
109         CRIT_VAR;
110         CRIT_BEG;
111         if(l2sc->T200 != TIMER_IDLE)
112         {
113 #if defined(__FreeBSD__)
114                 untimeout((TIMEOUT_FUNC_T)i4b_T200_timeout, (void *)l2sc, l2sc->T200_callout);
115 #else
116                 untimeout((TIMEOUT_FUNC_T)i4b_T200_timeout, (void *)l2sc);
117 #endif
118                 l2sc->T200 = TIMER_IDLE;
119         }
120         CRIT_END;
121         DBGL2(L2_T_MSG, "i4b_T200_stop", ("unit %d\n", l2sc->unit));
122 }
123
124 /*---------------------------------------------------------------------------*
125  *      Q.921 timer T200 restart
126  *---------------------------------------------------------------------------*/
127 void
128 i4b_T200_restart(l2_softc_t *l2sc)
129 {
130         CRIT_VAR;
131         CRIT_BEG;
132         if(l2sc->T200 != TIMER_IDLE)
133         {
134 #if defined(__FreeBSD__)
135                 untimeout((TIMEOUT_FUNC_T)i4b_T200_timeout, (void *)l2sc, l2sc->T200_callout);
136 #else
137                 untimeout((TIMEOUT_FUNC_T)i4b_T200_timeout, (void *)l2sc);
138 #endif
139         }
140         else
141         {
142                 l2sc->T200 = TIMER_ACTIVE;
143         }
144
145 #if defined(__FreeBSD__)
146         l2sc->T200_callout = timeout((TIMEOUT_FUNC_T)i4b_T200_timeout, (void *)l2sc, T200DEF);
147 #else
148         timeout((TIMEOUT_FUNC_T)i4b_T200_timeout, (void *)l2sc, T200DEF);
149 #endif
150         CRIT_END;
151         DBGL2(L2_T_MSG, "i4b_T200_restart", ("unit %d\n", l2sc->unit));
152 }
153
154 /*---------------------------------------------------------------------------*
155  *      Q.921 timer T202 timeout function
156  *---------------------------------------------------------------------------*/
157 static void
158 i4b_T202_timeout(l2_softc_t *l2sc)
159 {
160         DBGL2(L2_T_ERR, "i4b_T202_timeout", ("unit %d, N202 = %d\n", l2sc->unit, l2sc->N202));
161         
162         if(--(l2sc->N202))
163         {
164                 (*l2sc->T202func)(l2sc);
165         }
166 }
167
168 /*---------------------------------------------------------------------------*
169  *      Q.921 timer T202 start
170  *---------------------------------------------------------------------------*/
171 void
172 i4b_T202_start(l2_softc_t *l2sc)
173 {
174         if (l2sc->N202 == TIMER_ACTIVE)
175                 return;
176
177         DBGL2(L2_T_MSG, "i4b_T202_start", ("unit %d\n", l2sc->unit));
178         l2sc->N202 = N202DEF;   
179         l2sc->T202 = TIMER_ACTIVE;
180
181 #if defined(__FreeBSD__)
182         l2sc->T202_callout = timeout((TIMEOUT_FUNC_T)i4b_T202_timeout, (void *)l2sc, T202DEF);
183 #else
184         timeout((TIMEOUT_FUNC_T)i4b_T202_timeout, (void *)l2sc, T202DEF);
185 #endif
186 }
187
188 /*---------------------------------------------------------------------------*
189  *      Q.921 timer T202 stop
190  *---------------------------------------------------------------------------*/
191 void
192 i4b_T202_stop(l2_softc_t *l2sc)
193 {
194         CRIT_VAR;
195         CRIT_BEG;
196         if(l2sc->T202 != TIMER_IDLE)
197         {
198 #if defined(__FreeBSD__)
199                 untimeout((TIMEOUT_FUNC_T)i4b_T202_timeout, (void *)l2sc, l2sc->T202_callout);
200 #else
201                 untimeout((TIMEOUT_FUNC_T)i4b_T202_timeout, (void *)l2sc);
202 #endif
203                 l2sc->T202 = TIMER_IDLE;
204         }
205         CRIT_END;
206         DBGL2(L2_T_MSG, "i4b_T202_stop", ("unit %d\n", l2sc->unit));
207 }
208
209 /*---------------------------------------------------------------------------*
210  *      Q.921 timer T203 timeout function
211  *---------------------------------------------------------------------------*/
212 #if I4B_T203_ACTIVE
213 static void
214 i4b_T203_timeout(l2_softc_t *l2sc)
215 {
216         DBGL2(L2_T_ERR, "i4b_T203_timeout", ("unit %d\n", l2sc->unit));
217         i4b_next_l2state(l2sc, EV_T203EXP);
218 }
219 #endif
220
221 /*---------------------------------------------------------------------------*
222  *      Q.921 timer T203 start
223  *---------------------------------------------------------------------------*/
224 void
225 i4b_T203_start(l2_softc_t *l2sc)
226 {
227 #if I4B_T203_ACTIVE
228         if (l2sc->T203 == TIMER_ACTIVE)
229                 return;
230                 
231         DBGL2(L2_T_MSG, "i4b_T203_start", ("unit %d\n", l2sc->unit));
232         l2sc->T203 = TIMER_ACTIVE;
233
234 #if defined(__FreeBSD__)
235         l2sc->T203_callout = timeout((TIMEOUT_FUNC_T)i4b_T203_timeout, (void *)l2sc, T203DEF);
236 #else
237         timeout((TIMEOUT_FUNC_T)i4b_T203_timeout, (void *)l2sc, T203DEF);
238 #endif
239 #endif
240 }
241
242 /*---------------------------------------------------------------------------*
243  *      Q.921 timer T203 stop
244  *---------------------------------------------------------------------------*/
245 void
246 i4b_T203_stop(l2_softc_t *l2sc)
247 {
248 #if I4B_T203_ACTIVE
249         CRIT_VAR;
250         CRIT_BEG;
251         if(l2sc->T203 != TIMER_IDLE)
252         {
253 #if defined(__FreeBSD__)
254                 untimeout((TIMEOUT_FUNC_T)i4b_T203_timeout, (void *)l2sc, l2sc->T203_callout);
255 #else
256                 untimeout((TIMEOUT_FUNC_T)i4b_T203_timeout, (void *)l2sc);
257 #endif
258                 l2sc->T203 = TIMER_IDLE;
259         }
260         CRIT_END;
261         DBGL2(L2_T_MSG, "i4b_T203_stop", ("unit %d\n", l2sc->unit));
262 #endif
263 }
264
265 /*---------------------------------------------------------------------------*
266  *      Q.921 timer T203 restart
267  *---------------------------------------------------------------------------*/
268 void
269 i4b_T203_restart(l2_softc_t *l2sc)
270 {
271 #if I4B_T203_ACTIVE
272         CRIT_VAR;
273         CRIT_BEG;
274
275         if(l2sc->T203 != TIMER_IDLE)
276         {
277 #if defined(__FreeBSD__)
278                 untimeout((TIMEOUT_FUNC_T)i4b_T203_timeout, (void *)l2sc, l2sc->T203_callout);
279 #else
280                 untimeout((TIMEOUT_FUNC_T)i4b_T203_timeout, (void *)l2sc);
281 #endif
282         }
283         else
284         {
285                 l2sc->T203 = TIMER_ACTIVE;
286         }
287         
288 #if defined(__FreeBSD__)
289         l2sc->T203_callout = timeout((TIMEOUT_FUNC_T)i4b_T203_timeout, (void *)l2sc, T203DEF);
290 #else
291         timeout((TIMEOUT_FUNC_T)i4b_T203_timeout, (void *)l2sc, T203DEF);
292 #endif
293         CRIT_END;
294         DBGL2(L2_T_MSG, "i4b_T203_restart", ("unit %d\n", l2sc->unit));
295 #endif
296 }
297
298 #endif /* NI4BQ921 > 0 */