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.13 2000/08/24 11:48:58 hm Exp $
32 * $FreeBSD: src/sys/i4b/layer2/i4b_uframe.c,v 1.6.2.1 2001/08/10 14:08:41 obrien Exp $
34 * last edit-date: [Mon May 29 16:55:30 2000]
36 *---------------------------------------------------------------------------*/
45 #include <sys/param.h>
46 #include <sys/systm.h>
48 #include <sys/socket.h>
51 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
52 #include <sys/callout.h>
56 #include <machine/i4b_debug.h>
58 #include <i4b/i4b_debug.h>
59 #include <i4b/i4b_ioctl.h>
62 #include <i4b/include/i4b_l1l2.h>
63 #include <i4b/include/i4b_l2l3.h>
64 #include <i4b/include/i4b_mbuf.h>
66 #include <i4b/layer2/i4b_l2.h>
67 #include <i4b/layer2/i4b_l2fsm.h>
69 /*---------------------------------------------------------------------------*
70 * process a received U-frame
71 *---------------------------------------------------------------------------*/
73 i4b_rxd_u_frame(int unit, struct mbuf *m)
75 l2_softc_t *l2sc = &l2_softc[unit];
76 u_char *ptr = m->m_data;
78 int sapi = GETSAPI(*(ptr + OFF_SAPI));
79 int tei = GETTEI(*(ptr + OFF_TEI));
80 int pfbit = GETUPF(*(ptr + OFF_CNTL));
82 switch(*(ptr + OFF_CNTL) & ~UPFBIT)
87 if((l2sc->tei_valid == TEI_VALID) &&
88 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
90 l2sc->stat.rx_sabme++;
91 NDBGL2(L2_U_MSG, "SABME, sapi = %d, tei = %d", sapi, tei);
93 i4b_next_l2state(l2sc, EV_RXSABME);
99 if(sapi == SAPI_L2M &&
101 *(ptr + OFF_MEI) == MEI)
103 /* layer 2 management (SAPI = 63) */
105 i4b_tei_rxframe(unit, m);
107 else if(sapi == SAPI_CCP && tei == GROUP_TEI)
109 /* call control (SAPI = 0) */
111 /* strip ui header */
112 m_adj(m, UI_HDR_LEN);
114 DL_Unit_Data_Ind(unit, m);
118 l2sc->stat.err_rx_badui++;
119 NDBGL2(L2_U_ERR, "unknown UI frame!");
125 if((l2sc->tei_valid == TEI_VALID) &&
126 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
128 l2sc->stat.rx_disc++;
129 NDBGL2(L2_U_MSG, "DISC, sapi = %d, tei = %d", sapi, tei);
130 l2sc->rxd_PF = pfbit;
131 i4b_next_l2state(l2sc, EV_RXDISC);
137 if((l2sc->tei_valid == TEI_VALID) &&
138 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
141 NDBGL2(L2_U_MSG, "XID, sapi = %d, tei = %d", sapi, tei);
149 if((l2sc->tei_valid == TEI_VALID) &&
150 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
153 NDBGL2(L2_U_MSG, "DM, sapi = %d, tei = %d", sapi, tei);
154 i4b_print_frame(m->m_len, m->m_data);
155 l2sc->rxd_PF = pfbit;
156 i4b_next_l2state(l2sc, EV_RXDM);
162 if((l2sc->tei_valid == TEI_VALID) &&
163 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
166 NDBGL2(L2_U_MSG, "UA, sapi = %d, tei = %d", sapi, tei);
167 l2sc->rxd_PF = pfbit;
168 i4b_next_l2state(l2sc, EV_RXUA);
174 if((l2sc->tei_valid == TEI_VALID) &&
175 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
177 l2sc->stat.rx_frmr++;
178 NDBGL2(L2_U_MSG, "FRMR, sapi = %d, tei = %d", sapi, tei);
179 l2sc->rxd_PF = pfbit;
180 i4b_next_l2state(l2sc, EV_RXFRMR);
186 if((l2sc->tei_valid == TEI_VALID) &&
187 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
189 NDBGL2(L2_U_ERR, "UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi, tei);
190 i4b_print_frame(m->m_len, m->m_data);
194 NDBGL2(L2_U_ERR, "not mine - UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi, tei);
195 i4b_print_frame(m->m_len, m->m_data);
197 l2sc->stat.err_rx_badui++;
203 /*---------------------------------------------------------------------------*
204 * build U-frame for sending
205 *---------------------------------------------------------------------------*/
207 i4b_build_u_frame(l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type)
211 if((m = i4b_Dgetmbuf(U_FRAME_LEN)) == NULL)
214 PUTSAPI(SAPI_CCP, crbit, m->m_data[OFF_SAPI]);
216 PUTTEI(l2sc->tei, m->m_data[OFF_TEI]);
219 m->m_data[OFF_CNTL] = type | UPBITSET;
221 m->m_data[OFF_CNTL] = type & ~UPBITSET;
226 /*---------------------------------------------------------------------------*
227 * transmit SABME command
228 *---------------------------------------------------------------------------*/
230 i4b_tx_sabme(l2_softc_t *l2sc, pbit_t pbit)
234 l2sc->stat.tx_sabme++;
235 NDBGL2(L2_U_MSG, "tx SABME, tei = %d", l2sc->tei);
236 m = i4b_build_u_frame(l2sc, CR_CMD_TO_NT, pbit, SABME);
237 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
240 /*---------------------------------------------------------------------------*
241 * transmit DM response
242 *---------------------------------------------------------------------------*/
244 i4b_tx_dm(l2_softc_t *l2sc, fbit_t fbit)
249 NDBGL2(L2_U_MSG, "tx DM, tei = %d", l2sc->tei);
250 m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, DM);
251 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
254 /*---------------------------------------------------------------------------*
255 * transmit DISC command
256 *---------------------------------------------------------------------------*/
258 i4b_tx_disc(l2_softc_t *l2sc, pbit_t pbit)
262 l2sc->stat.tx_disc++;
263 NDBGL2(L2_U_MSG, "tx DISC, tei = %d", l2sc->tei);
264 m = i4b_build_u_frame(l2sc, CR_CMD_TO_NT, pbit, DISC);
265 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
268 /*---------------------------------------------------------------------------*
269 * transmit UA response
270 *---------------------------------------------------------------------------*/
272 i4b_tx_ua(l2_softc_t *l2sc, fbit_t fbit)
277 NDBGL2(L2_U_MSG, "tx UA, tei = %d", l2sc->tei);
278 m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, UA);
279 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
282 /*---------------------------------------------------------------------------*
283 * transmit FRMR response
284 *---------------------------------------------------------------------------*/
286 i4b_tx_frmr(l2_softc_t *l2sc, fbit_t fbit)
290 l2sc->stat.tx_frmr++;
291 NDBGL2(L2_U_MSG, "tx FRMR, tei = %d", l2sc->tei);
292 m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, FRMR);
293 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
296 #endif /* NI4BQ921 > 0 */