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_l2timer.c - layer 2 timer handling
28 * --------------------------------------
29 *
30 * $Id: i4b_l2timer.c,v 1.1 2003/04/06 04:37:48 tg Exp $
31 *
32 * $FreeBSD$
33 *
34 * last edit-date: [Fri Jan 5 11:33:47 2001]
35 *
36 *---------------------------------------------------------------------------*/
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: i4b_l2timer.c,v 1.6 2002/05/21 10:31:11 martin Exp $");
40
41 #ifdef __FreeBSD__
42 #include "i4bq921.h"
43 #else
44 #define NI4BQ921 1
45 #endif
46 #if NI4BQ921 > 0
47
48 #include <sys/param.h>
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 #include <sys/timeout.h>
56
57 #ifdef __FreeBSD__
58 #include <machine/i4b_debug.h>
59 #include <machine/i4b_ioctl.h>
60 #else
61 #include <netisdn/i4b_debug.h>
62 #include <netisdn/i4b_ioctl.h>
63 #endif
64
65 #include <netisdn/i4b_global.h>
66 #include <netisdn/i4b_l2.h>
67 #include <netisdn/i4b_l1l2.h>
68 #include <netisdn/i4b_isdnq931.h>
69 #include <netisdn/i4b_mbuf.h>
70 #include <netisdn/i4b_l2fsm.h>
71 #include <netisdn/i4b_l3l4.h>
72
73 /*---------------------------------------------------------------------------*
74 * Q.921 timer T200 timeout function
75 *---------------------------------------------------------------------------*/
76 static void
i4b_T200_timeout(l2_softc_t * l2sc)77 i4b_T200_timeout(l2_softc_t *l2sc)
78 {
79 NDBGL2(L2_T_ERR, "isdnif %d, RC = %d", l2sc->drv->isdnif, l2sc->RC);
80 i4b_next_l2state(l2sc, l2sc->drv, EV_T200EXP);
81 }
82
83 /*---------------------------------------------------------------------------*
84 * Q.921 timer T200 start
85 *---------------------------------------------------------------------------*/
86 void
i4b_T200_start(l2_softc_t * l2sc)87 i4b_T200_start(l2_softc_t *l2sc)
88 {
89 if(l2sc->T200 == TIMER_ACTIVE)
90 return;
91
92 NDBGL2(L2_T_MSG, "isdnif %d", l2sc->drv->isdnif);
93 l2sc->T200 = TIMER_ACTIVE;
94
95 START_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc, T200DEF);
96 }
97
98 /*---------------------------------------------------------------------------*
99 * Q.921 timer T200 stop
100 *---------------------------------------------------------------------------*/
101 void
i4b_T200_stop(l2_softc_t * l2sc)102 i4b_T200_stop(l2_softc_t *l2sc)
103 {
104 int s;
105 s = splnet();
106 if(l2sc->T200 != TIMER_IDLE)
107 {
108 STOP_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc);
109 l2sc->T200 = TIMER_IDLE;
110 }
111 splx(s);
112 NDBGL2(L2_T_MSG, "isdnif %d", l2sc->drv->isdnif);
113 }
114
115 /*---------------------------------------------------------------------------*
116 * Q.921 timer T200 restart
117 *---------------------------------------------------------------------------*/
118 void
i4b_T200_restart(l2_softc_t * l2sc)119 i4b_T200_restart(l2_softc_t *l2sc)
120 {
121 int s;
122 s = splnet();
123 if(l2sc->T200 != TIMER_IDLE)
124 {
125 STOP_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc);
126 }
127 else
128 {
129 l2sc->T200 = TIMER_ACTIVE;
130 }
131
132 START_TIMER(l2sc->T200_callout, i4b_T200_timeout, l2sc, T200DEF);
133 splx(s);
134 NDBGL2(L2_T_MSG, "isdnif %d", l2sc->drv->isdnif);
135 }
136
137 /*---------------------------------------------------------------------------*
138 * Q.921 timer T202 timeout function
139 *---------------------------------------------------------------------------*/
140 static void
i4b_T202_timeout(l2_softc_t * l2sc)141 i4b_T202_timeout(l2_softc_t *l2sc)
142 {
143 NDBGL2(L2_T_ERR, "isdnif %d, N202 = %d", l2sc->drv->isdnif, l2sc->N202);
144
145 if(--(l2sc->N202))
146 {
147 (*l2sc->T202func)(l2sc);
148 }
149 }
150
151 /*---------------------------------------------------------------------------*
152 * Q.921 timer T202 start
153 *---------------------------------------------------------------------------*/
154 void
i4b_T202_start(l2_softc_t * l2sc)155 i4b_T202_start(l2_softc_t *l2sc)
156 {
157 if (l2sc->N202 == TIMER_ACTIVE)
158 return;
159
160 NDBGL2(L2_T_MSG, "isdnif %d", l2sc->drv->isdnif);
161 l2sc->N202 = N202DEF;
162 l2sc->T202 = TIMER_ACTIVE;
163
164 START_TIMER(l2sc->T202_callout, i4b_T202_timeout, l2sc, T202DEF);
165 }
166
167 /*---------------------------------------------------------------------------*
168 * Q.921 timer T202 stop
169 *---------------------------------------------------------------------------*/
170 void
i4b_T202_stop(l2_softc_t * l2sc)171 i4b_T202_stop(l2_softc_t *l2sc)
172 {
173 int s;
174 s = splnet();
175 if(l2sc->T202 != TIMER_IDLE)
176 {
177 STOP_TIMER(l2sc->T202_callout, i4b_T202_timeout, l2sc);
178 l2sc->T202 = TIMER_IDLE;
179 }
180 splx(s);
181 NDBGL2(L2_T_MSG, "isdnif %d", l2sc->drv->isdnif);
182 }
183
184 /*---------------------------------------------------------------------------*
185 * Q.921 timer T203 timeout function
186 *---------------------------------------------------------------------------*/
187 #if I4B_T203_ACTIVE
188 static void
i4b_T203_timeout(l2_softc_t * l2sc)189 i4b_T203_timeout(l2_softc_t *l2sc)
190 {
191 NDBGL2(L2_T_ERR, "isdnif %d", l2sc->isdnif);
192 i4b_next_l2state(l2sc, EV_T203EXP);
193 }
194 #endif
195
196 /*---------------------------------------------------------------------------*
197 * Q.921 timer T203 start
198 *---------------------------------------------------------------------------*/
199 void
i4b_T203_start(l2_softc_t * l2sc)200 i4b_T203_start(l2_softc_t *l2sc)
201 {
202 #if I4B_T203_ACTIVE
203 if (l2sc->T203 == TIMER_ACTIVE)
204 return;
205
206 NDBGL2(L2_T_MSG, "isdnif %d", l2sc->isdnif);
207 l2sc->T203 = TIMER_ACTIVE;
208
209 START_TIMER(l2sc->T203_callout, i4b_T203_timeout, l2sc, T203DEF);
210 #endif
211 }
212
213 /*---------------------------------------------------------------------------*
214 * Q.921 timer T203 stop
215 *---------------------------------------------------------------------------*/
216 void
i4b_T203_stop(l2_softc_t * l2sc)217 i4b_T203_stop(l2_softc_t *l2sc)
218 {
219 #if I4B_T203_ACTIVE
220 int s;
221 s = splnet();
222 if(l2sc->T203 != TIMER_IDLE)
223 {
224 STOP_TIMER(l2sc->T203_callout, i4b_T203_timeout, l2sc);
225 l2sc->T203 = TIMER_IDLE;
226 }
227 splx(s);
228 NDBGL2(L2_T_MSG, "isdnif %d", l2sc->isdnif);
229 #endif
230 }
231
232 /*---------------------------------------------------------------------------*
233 * Q.921 timer T203 restart
234 *---------------------------------------------------------------------------*/
235 void
i4b_T203_restart(l2_softc_t * l2sc)236 i4b_T203_restart(l2_softc_t *l2sc)
237 {
238 #if I4B_T203_ACTIVE
239 int s;
240 s = splnet();
241
242 if(l2sc->T203 != TIMER_IDLE)
243 {
244 STOP_TIMER(l2sc->T203_callout, i4b_T203_timerout, l2sc);
245 }
246 else
247 {
248 l2sc->T203 = TIMER_ACTIVE;
249 }
250
251 START_TIMER(l2sc->T203_callout, i4b_T203_timerout, l2sc, T203DEF);
252 splx(s);
253 NDBGL2(L2_T_MSG, "isdnif %d", l2sc->isdnif);
254 #endif
255 }
256
257 #endif /* NI4BQ921 > 0 */
258