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