]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/i4b/layer2/i4b_l2timer.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / i4b / layer2 / i4b_l2timer.c
1 /*-
2  * Copyright (c) 1997, 2002 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  *
28  *      i4b_l2timer.c - layer 2 timer handling
29  *      --------------------------------------
30  *      last edit-date: [Sat Mar  9 17:48:58 2002]
31  *
32  *---------------------------------------------------------------------------*/
33
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
36
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/systm.h>
40 #include <sys/socket.h>
41 #include <net/if.h>
42
43 #include <i4b/include/i4b_debug.h>
44
45 #include <i4b/include/i4b_global.h>
46
47 #include <i4b/layer2/i4b_l2.h>
48 #include <i4b/layer2/i4b_l2fsm.h>
49
50 /*---------------------------------------------------------------------------*
51  *      Q.921 timer T200 timeout function
52  *---------------------------------------------------------------------------*/
53 static void
54 i4b_T200_timeout(l2_softc_t *l2sc)
55 {
56         NDBGL2(L2_T_ERR, "unit %d, RC = %d", l2sc->unit, l2sc->RC);
57         i4b_next_l2state(l2sc, EV_T200EXP);
58 }
59
60 /*---------------------------------------------------------------------------*
61  *      Q.921 timer T200 start
62  *---------------------------------------------------------------------------*/
63 void
64 i4b_T200_start(l2_softc_t *l2sc)
65 {
66         if(l2sc->T200 == TIMER_ACTIVE)
67                 return;
68                 
69         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
70         l2sc->T200 = TIMER_ACTIVE;
71
72         START_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc, T200DEF);
73 }
74
75 /*---------------------------------------------------------------------------*
76  *      Q.921 timer T200 stop
77  *---------------------------------------------------------------------------*/
78 void
79 i4b_T200_stop(l2_softc_t *l2sc)
80 {
81         CRIT_VAR;
82         CRIT_BEG;
83         if(l2sc->T200 != TIMER_IDLE)
84         {
85                 STOP_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc);
86                 l2sc->T200 = TIMER_IDLE;
87         }
88         CRIT_END;
89         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
90 }
91
92 /*---------------------------------------------------------------------------*
93  *      Q.921 timer T200 restart
94  *---------------------------------------------------------------------------*/
95 void
96 i4b_T200_restart(l2_softc_t *l2sc)
97 {
98         CRIT_VAR;
99         CRIT_BEG;
100         if(l2sc->T200 != TIMER_IDLE)
101         {
102                 STOP_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc);
103         }
104         else
105         {
106                 l2sc->T200 = TIMER_ACTIVE;
107         }
108
109         START_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc, T200DEF);
110         CRIT_END;
111         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
112 }
113
114 /*---------------------------------------------------------------------------*
115  *      Q.921 timer T202 timeout function
116  *---------------------------------------------------------------------------*/
117 static void
118 i4b_T202_timeout(l2_softc_t *l2sc)
119 {
120         NDBGL2(L2_T_ERR, "unit %d, N202 = %d", l2sc->unit, l2sc->N202);
121         
122         if(--(l2sc->N202))
123         {
124                 (*l2sc->T202func)(l2sc);
125         }
126 }
127
128 /*---------------------------------------------------------------------------*
129  *      Q.921 timer T202 start
130  *---------------------------------------------------------------------------*/
131 void
132 i4b_T202_start(l2_softc_t *l2sc)
133 {
134         if (l2sc->N202 == TIMER_ACTIVE)
135                 return;
136
137         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
138         l2sc->N202 = N202DEF;   
139         l2sc->T202 = TIMER_ACTIVE;
140
141         START_TIMER(l2sc->T202_callout, i4b_T202_timeout, l2sc, T202DEF);
142 }
143
144 /*---------------------------------------------------------------------------*
145  *      Q.921 timer T202 stop
146  *---------------------------------------------------------------------------*/
147 void
148 i4b_T202_stop(l2_softc_t *l2sc)
149 {
150         CRIT_VAR;
151         CRIT_BEG;
152         if(l2sc->T202 != TIMER_IDLE)
153         {
154                 STOP_TIMER(l2sc->T202_callout, i4b_T202_timeout, l2sc);
155                 l2sc->T202 = TIMER_IDLE;
156         }
157         CRIT_END;
158         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
159 }
160
161 /*---------------------------------------------------------------------------*
162  *      Q.921 timer T203 timeout function
163  *---------------------------------------------------------------------------*/
164 #if defined(I4B_T203_ACTIVE) && I4B_T203_ACTIVE
165 static void
166 i4b_T203_timeout(l2_softc_t *l2sc)
167 {
168         NDBGL2(L2_T_ERR, "unit %d", l2sc->unit);
169         i4b_next_l2state(l2sc, EV_T203EXP);
170 }
171 #endif
172
173 /*---------------------------------------------------------------------------*
174  *      Q.921 timer T203 start
175  *---------------------------------------------------------------------------*/
176 void
177 i4b_T203_start(l2_softc_t *l2sc)
178 {
179 #if defined(I4B_T203_ACTIVE) && I4B_T203_ACTIVE
180         if (l2sc->T203 == TIMER_ACTIVE)
181                 return;
182                 
183         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
184         l2sc->T203 = TIMER_ACTIVE;
185
186         START_TIMER(l2sc->T203_callout, i4b_T203_timeout, l2sc, T203DEF);
187 #endif
188 }
189
190 /*---------------------------------------------------------------------------*
191  *      Q.921 timer T203 stop
192  *---------------------------------------------------------------------------*/
193 void
194 i4b_T203_stop(l2_softc_t *l2sc)
195 {
196 #if defined(I4B_T203_ACTIVE) && I4B_T203_ACTIVE
197         CRIT_VAR;
198         CRIT_BEG;
199         if(l2sc->T203 != TIMER_IDLE)
200         {
201                 STOP_TIMER(l2sc->T203_callout, i4b_T203_timeout, l2sc);
202                 l2sc->T203 = TIMER_IDLE;
203         }
204         CRIT_END;
205         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
206 #endif
207 }
208
209 /*---------------------------------------------------------------------------*
210  *      Q.921 timer T203 restart
211  *---------------------------------------------------------------------------*/
212 void
213 i4b_T203_restart(l2_softc_t *l2sc)
214 {
215 #if defined(I4B_T203_ACTIVE) && I4B_T203_ACTIVE
216         CRIT_VAR;
217         CRIT_BEG;
218
219         if(l2sc->T203 != TIMER_IDLE)
220         {
221                 STOP_TIMER(l2sc->T203_callout, i4b_T203_timerout, l2sc);
222         }
223         else
224         {
225                 l2sc->T203 = TIMER_ACTIVE;
226         }
227
228         START_TIMER(l2sc->T203_callout, i4b_T203_timerout, l2sc, T203DEF);      
229         CRIT_END;
230         NDBGL2(L2_T_MSG, "unit %d", l2sc->unit);
231 #endif
232 }