2 * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
25 *---------------------------------------------------------------------------
27 * i4b_uframe.c - routines for handling U-frames
28 * -----------------------------------------------
30 * $Id: i4b_uframe.c,v 1.8 2007/01/24 13:08:15 hubertf Exp $
34 * last edit-date: [Fri Jan 5 11:33:47 2001]
36 *---------------------------------------------------------------------------*/
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: i4b_uframe.c,v 1.7 2005/12/11 12:25:06 christos Exp $");
48 #include <sys/param.h>
49 #include <sys/kernel.h>
50 #include <sys/systm.h>
52 #include <sys/socket.h>
55 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
56 #include <sys/callout.h>
60 #include <machine/i4b_debug.h>
61 #include <machine/i4b_ioctl.h>
63 #include <netisdn/i4b_debug.h>
64 #include <netisdn/i4b_ioctl.h>
67 #include <netisdn/i4b_l2.h>
68 #include <netisdn/i4b_l1l2.h>
69 #include <netisdn/i4b_isdnq931.h>
70 #include <netisdn/i4b_mbuf.h>
72 #include <netisdn/i4b_l2fsm.h>
74 /*---------------------------------------------------------------------------*
75 * process a received U-frame
76 *---------------------------------------------------------------------------*/
78 i4b_rxd_u_frame(l2_softc_t
*l2sc
, struct isdn_l3_driver
*drv
, struct mbuf
*m
)
80 u_char
*ptr
= m
->m_data
;
82 int sapi
= GETSAPI(*(ptr
+ OFF_SAPI
));
83 int tei
= GETTEI(*(ptr
+ OFF_TEI
));
84 int pfbit
= GETUPF(*(ptr
+ OFF_CNTL
));
86 switch(*(ptr
+ OFF_CNTL
) & ~UPFBIT
)
91 if((l2sc
->tei_valid
== TEI_VALID
) &&
92 (l2sc
->tei
== GETTEI(*(ptr
+OFF_TEI
))))
94 l2sc
->stat
.rx_sabme
++;
95 NDBGL2(L2_U_MSG
, "SABME, sapi = %d, tei = %d", sapi
, tei
);
97 i4b_next_l2state(l2sc
, drv
, EV_RXSABME
);
103 if(sapi
== SAPI_L2M
&&
105 *(ptr
+ OFF_MEI
) == MEI
)
107 /* layer 2 management (SAPI = 63) */
109 i4b_tei_rxframe(l2sc
, drv
, m
);
111 else if(sapi
== SAPI_CCP
&& tei
== GROUP_TEI
)
113 /* call control (SAPI = 0) */
115 /* strip ui header */
116 m_adj(m
, UI_HDR_LEN
);
118 i4b_dl_unit_data_ind(l2sc
->drv
, m
);
122 l2sc
->stat
.err_rx_badui
++;
123 NDBGL2(L2_U_ERR
, "unknown UI frame!");
129 if((l2sc
->tei_valid
== TEI_VALID
) &&
130 (l2sc
->tei
== GETTEI(*(ptr
+OFF_TEI
))))
132 l2sc
->stat
.rx_disc
++;
133 NDBGL2(L2_U_MSG
, "DISC, sapi = %d, tei = %d", sapi
, tei
);
134 l2sc
->rxd_PF
= pfbit
;
135 i4b_next_l2state(l2sc
, drv
, EV_RXDISC
);
141 if((l2sc
->tei_valid
== TEI_VALID
) &&
142 (l2sc
->tei
== GETTEI(*(ptr
+OFF_TEI
))))
145 NDBGL2(L2_U_MSG
, "XID, sapi = %d, tei = %d", sapi
, tei
);
153 if((l2sc
->tei_valid
== TEI_VALID
) &&
154 (l2sc
->tei
== GETTEI(*(ptr
+OFF_TEI
))))
157 NDBGL2(L2_U_MSG
, "DM, sapi = %d, tei = %d", sapi
, tei
);
158 i4b_print_frame(m
->m_len
, m
->m_data
);
159 l2sc
->rxd_PF
= pfbit
;
160 i4b_next_l2state(l2sc
, drv
, EV_RXDM
);
166 if((l2sc
->tei_valid
== TEI_VALID
) &&
167 (l2sc
->tei
== GETTEI(*(ptr
+OFF_TEI
))))
170 NDBGL2(L2_U_MSG
, "UA, sapi = %d, tei = %d", sapi
, tei
);
171 l2sc
->rxd_PF
= pfbit
;
172 i4b_next_l2state(l2sc
, drv
, EV_RXUA
);
178 if((l2sc
->tei_valid
== TEI_VALID
) &&
179 (l2sc
->tei
== GETTEI(*(ptr
+OFF_TEI
))))
181 l2sc
->stat
.rx_frmr
++;
182 NDBGL2(L2_U_MSG
, "FRMR, sapi = %d, tei = %d", sapi
, tei
);
183 l2sc
->rxd_PF
= pfbit
;
184 i4b_next_l2state(l2sc
, drv
, EV_RXFRMR
);
190 if((l2sc
->tei_valid
== TEI_VALID
) &&
191 (l2sc
->tei
== GETTEI(*(ptr
+OFF_TEI
))))
193 NDBGL2(L2_U_ERR
, "UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi
, tei
);
194 i4b_print_frame(m
->m_len
, m
->m_data
);
198 NDBGL2(L2_U_ERR
, "not mine - UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi
, tei
);
199 i4b_print_frame(m
->m_len
, m
->m_data
);
201 l2sc
->stat
.err_rx_badui
++;
207 /*---------------------------------------------------------------------------*
208 * build U-frame for sending
209 *---------------------------------------------------------------------------*/
211 i4b_build_u_frame(l2_softc_t
*l2sc
, crbit_to_nt_t crbit
, pbit_t pbit
, u_char type
)
215 if((m
= i4b_Dgetmbuf(U_FRAME_LEN
)) == NULL
)
218 PUTSAPI(SAPI_CCP
, crbit
, m
->m_data
[OFF_SAPI
]);
220 PUTTEI(l2sc
->tei
, m
->m_data
[OFF_TEI
]);
223 m
->m_data
[OFF_CNTL
] = type
| UPBITSET
;
225 m
->m_data
[OFF_CNTL
] = type
& ~UPBITSET
;
230 /*---------------------------------------------------------------------------*
231 * transmit SABME command
232 *---------------------------------------------------------------------------*/
234 i4b_tx_sabme(l2_softc_t
*l2sc
, pbit_t pbit
)
238 l2sc
->stat
.tx_sabme
++;
239 NDBGL2(L2_U_MSG
, "tx SABME, tei = %d", l2sc
->tei
);
240 m
= i4b_build_u_frame(l2sc
, CR_CMD_TO_NT
, pbit
, SABME
);
241 l2sc
->driver
->ph_data_req(l2sc
->l1_token
, m
, MBUF_FREE
);
244 /*---------------------------------------------------------------------------*
245 * transmit DM response
246 *---------------------------------------------------------------------------*/
248 i4b_tx_dm(l2_softc_t
*l2sc
, fbit_t fbit
)
253 NDBGL2(L2_U_MSG
, "tx DM, tei = %d", l2sc
->tei
);
254 m
= i4b_build_u_frame(l2sc
, CR_RSP_TO_NT
, fbit
, DM
);
255 l2sc
->driver
->ph_data_req(l2sc
->l1_token
, m
, MBUF_FREE
);
258 /*---------------------------------------------------------------------------*
259 * transmit DISC command
260 *---------------------------------------------------------------------------*/
262 i4b_tx_disc(l2_softc_t
*l2sc
, pbit_t pbit
)
266 l2sc
->stat
.tx_disc
++;
267 NDBGL2(L2_U_MSG
, "tx DISC, tei = %d", l2sc
->tei
);
268 m
= i4b_build_u_frame(l2sc
, CR_CMD_TO_NT
, pbit
, DISC
);
269 l2sc
->driver
->ph_data_req(l2sc
->l1_token
, m
, MBUF_FREE
);
272 /*---------------------------------------------------------------------------*
273 * transmit UA response
274 *---------------------------------------------------------------------------*/
276 i4b_tx_ua(l2_softc_t
*l2sc
, fbit_t fbit
)
281 NDBGL2(L2_U_MSG
, "tx UA, tei = %d", l2sc
->tei
);
282 m
= i4b_build_u_frame(l2sc
, CR_RSP_TO_NT
, fbit
, UA
);
283 l2sc
->driver
->ph_data_req(l2sc
->l1_token
, m
, MBUF_FREE
);
286 /*---------------------------------------------------------------------------*
287 * transmit FRMR response
288 *---------------------------------------------------------------------------*/
290 i4b_tx_frmr(l2_softc_t
*l2sc
, fbit_t fbit
)
294 l2sc
->stat
.tx_frmr
++;
295 NDBGL2(L2_U_MSG
, "tx FRMR, tei = %d", l2sc
->tei
);
296 m
= i4b_build_u_frame(l2sc
, CR_RSP_TO_NT
, fbit
, FRMR
);
297 l2sc
->driver
->ph_data_req(l2sc
->l1_token
, m
, MBUF_FREE
);
300 #endif /* NI4BQ921 > 0 */