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 $
33 * $DragonFly: src/sys/net/i4b/layer2/i4b_uframe.c,v 1.4 2004/02/13 17:45:50 joerg Exp $
35 * last edit-date: [Mon May 29 16:55:30 2000]
37 *---------------------------------------------------------------------------*/
39 #if defined(__DragonFly__) || defined(__FreeBSD__)
40 #include "use_i4bq921.h"
46 #include <sys/param.h>
47 #include <sys/systm.h>
49 #include <sys/socket.h>
52 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
53 #include <sys/callout.h>
56 #if defined(__DragonFly__) || defined(__FreeBSD__)
57 #include <net/i4b/include/machine/i4b_debug.h>
59 #include <i4b/i4b_debug.h>
60 #include <i4b/i4b_ioctl.h>
63 #include "../include/i4b_l1l2.h"
64 #include "../include/i4b_l2l3.h"
65 #include "../include/i4b_mbuf.h"
68 #include "i4b_l2fsm.h"
70 /*---------------------------------------------------------------------------*
71 * process a received U-frame
72 *---------------------------------------------------------------------------*/
74 i4b_rxd_u_frame(int unit, struct mbuf *m)
76 l2_softc_t *l2sc = &l2_softc[unit];
77 u_char *ptr = m->m_data;
79 int sapi = GETSAPI(*(ptr + OFF_SAPI));
80 int tei = GETTEI(*(ptr + OFF_TEI));
81 int pfbit = GETUPF(*(ptr + OFF_CNTL));
83 switch(*(ptr + OFF_CNTL) & ~UPFBIT)
88 if((l2sc->tei_valid == TEI_VALID) &&
89 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
91 l2sc->stat.rx_sabme++;
92 NDBGL2(L2_U_MSG, "SABME, sapi = %d, tei = %d", sapi, tei);
94 i4b_next_l2state(l2sc, EV_RXSABME);
100 if(sapi == SAPI_L2M &&
102 *(ptr + OFF_MEI) == MEI)
104 /* layer 2 management (SAPI = 63) */
106 i4b_tei_rxframe(unit, m);
108 else if(sapi == SAPI_CCP && tei == GROUP_TEI)
110 /* call control (SAPI = 0) */
112 /* strip ui header */
113 m_adj(m, UI_HDR_LEN);
115 DL_Unit_Data_Ind(unit, m);
119 l2sc->stat.err_rx_badui++;
120 NDBGL2(L2_U_ERR, "unknown UI frame!");
126 if((l2sc->tei_valid == TEI_VALID) &&
127 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
129 l2sc->stat.rx_disc++;
130 NDBGL2(L2_U_MSG, "DISC, sapi = %d, tei = %d", sapi, tei);
131 l2sc->rxd_PF = pfbit;
132 i4b_next_l2state(l2sc, EV_RXDISC);
138 if((l2sc->tei_valid == TEI_VALID) &&
139 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
142 NDBGL2(L2_U_MSG, "XID, sapi = %d, tei = %d", sapi, tei);
150 if((l2sc->tei_valid == TEI_VALID) &&
151 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
154 NDBGL2(L2_U_MSG, "DM, sapi = %d, tei = %d", sapi, tei);
155 i4b_print_frame(m->m_len, m->m_data);
156 l2sc->rxd_PF = pfbit;
157 i4b_next_l2state(l2sc, EV_RXDM);
163 if((l2sc->tei_valid == TEI_VALID) &&
164 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
167 NDBGL2(L2_U_MSG, "UA, sapi = %d, tei = %d", sapi, tei);
168 l2sc->rxd_PF = pfbit;
169 i4b_next_l2state(l2sc, EV_RXUA);
175 if((l2sc->tei_valid == TEI_VALID) &&
176 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
178 l2sc->stat.rx_frmr++;
179 NDBGL2(L2_U_MSG, "FRMR, sapi = %d, tei = %d", sapi, tei);
180 l2sc->rxd_PF = pfbit;
181 i4b_next_l2state(l2sc, EV_RXFRMR);
187 if((l2sc->tei_valid == TEI_VALID) &&
188 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
190 NDBGL2(L2_U_ERR, "UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi, tei);
191 i4b_print_frame(m->m_len, m->m_data);
195 NDBGL2(L2_U_ERR, "not mine - UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi, tei);
196 i4b_print_frame(m->m_len, m->m_data);
198 l2sc->stat.err_rx_badui++;
204 /*---------------------------------------------------------------------------*
205 * build U-frame for sending
206 *---------------------------------------------------------------------------*/
208 i4b_build_u_frame(l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type)
212 if((m = i4b_Dgetmbuf(U_FRAME_LEN)) == NULL)
215 PUTSAPI(SAPI_CCP, crbit, m->m_data[OFF_SAPI]);
217 PUTTEI(l2sc->tei, m->m_data[OFF_TEI]);
220 m->m_data[OFF_CNTL] = type | UPBITSET;
222 m->m_data[OFF_CNTL] = type & ~UPBITSET;
227 /*---------------------------------------------------------------------------*
228 * transmit SABME command
229 *---------------------------------------------------------------------------*/
231 i4b_tx_sabme(l2_softc_t *l2sc, pbit_t pbit)
235 l2sc->stat.tx_sabme++;
236 NDBGL2(L2_U_MSG, "tx SABME, tei = %d", l2sc->tei);
237 m = i4b_build_u_frame(l2sc, CR_CMD_TO_NT, pbit, SABME);
238 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
241 /*---------------------------------------------------------------------------*
242 * transmit DM response
243 *---------------------------------------------------------------------------*/
245 i4b_tx_dm(l2_softc_t *l2sc, fbit_t fbit)
250 NDBGL2(L2_U_MSG, "tx DM, tei = %d", l2sc->tei);
251 m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, DM);
252 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
255 /*---------------------------------------------------------------------------*
256 * transmit DISC command
257 *---------------------------------------------------------------------------*/
259 i4b_tx_disc(l2_softc_t *l2sc, pbit_t pbit)
263 l2sc->stat.tx_disc++;
264 NDBGL2(L2_U_MSG, "tx DISC, tei = %d", l2sc->tei);
265 m = i4b_build_u_frame(l2sc, CR_CMD_TO_NT, pbit, DISC);
266 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
269 /*---------------------------------------------------------------------------*
270 * transmit UA response
271 *---------------------------------------------------------------------------*/
273 i4b_tx_ua(l2_softc_t *l2sc, fbit_t fbit)
278 NDBGL2(L2_U_MSG, "tx UA, tei = %d", l2sc->tei);
279 m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, UA);
280 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
283 /*---------------------------------------------------------------------------*
284 * transmit FRMR response
285 *---------------------------------------------------------------------------*/
287 i4b_tx_frmr(l2_softc_t *l2sc, fbit_t fbit)
291 l2sc->stat.tx_frmr++;
292 NDBGL2(L2_U_MSG, "tx FRMR, tei = %d", l2sc->tei);
293 m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, FRMR);
294 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
297 #endif /* NI4BQ921 > 0 */