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.5 2005/06/14 21:19:19 joerg Exp $
35 * last edit-date: [Mon May 29 16:55:30 2000]
37 *---------------------------------------------------------------------------*/
39 #include "use_i4bq921.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
45 #include <sys/socket.h>
48 #include <net/i4b/include/machine/i4b_debug.h>
50 #include "../include/i4b_l1l2.h"
51 #include "../include/i4b_l2l3.h"
52 #include "../include/i4b_mbuf.h"
55 #include "i4b_l2fsm.h"
57 /*---------------------------------------------------------------------------*
58 * process a received U-frame
59 *---------------------------------------------------------------------------*/
61 i4b_rxd_u_frame(int unit, struct mbuf *m)
63 l2_softc_t *l2sc = &l2_softc[unit];
64 u_char *ptr = m->m_data;
66 int sapi = GETSAPI(*(ptr + OFF_SAPI));
67 int tei = GETTEI(*(ptr + OFF_TEI));
68 int pfbit = GETUPF(*(ptr + OFF_CNTL));
70 switch(*(ptr + OFF_CNTL) & ~UPFBIT)
75 if((l2sc->tei_valid == TEI_VALID) &&
76 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
78 l2sc->stat.rx_sabme++;
79 NDBGL2(L2_U_MSG, "SABME, sapi = %d, tei = %d", sapi, tei);
81 i4b_next_l2state(l2sc, EV_RXSABME);
87 if(sapi == SAPI_L2M &&
89 *(ptr + OFF_MEI) == MEI)
91 /* layer 2 management (SAPI = 63) */
93 i4b_tei_rxframe(unit, m);
95 else if(sapi == SAPI_CCP && tei == GROUP_TEI)
97 /* call control (SAPI = 0) */
100 m_adj(m, UI_HDR_LEN);
102 DL_Unit_Data_Ind(unit, m);
106 l2sc->stat.err_rx_badui++;
107 NDBGL2(L2_U_ERR, "unknown UI frame!");
113 if((l2sc->tei_valid == TEI_VALID) &&
114 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
116 l2sc->stat.rx_disc++;
117 NDBGL2(L2_U_MSG, "DISC, sapi = %d, tei = %d", sapi, tei);
118 l2sc->rxd_PF = pfbit;
119 i4b_next_l2state(l2sc, EV_RXDISC);
125 if((l2sc->tei_valid == TEI_VALID) &&
126 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
129 NDBGL2(L2_U_MSG, "XID, sapi = %d, tei = %d", sapi, tei);
137 if((l2sc->tei_valid == TEI_VALID) &&
138 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
141 NDBGL2(L2_U_MSG, "DM, sapi = %d, tei = %d", sapi, tei);
142 i4b_print_frame(m->m_len, m->m_data);
143 l2sc->rxd_PF = pfbit;
144 i4b_next_l2state(l2sc, EV_RXDM);
150 if((l2sc->tei_valid == TEI_VALID) &&
151 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
154 NDBGL2(L2_U_MSG, "UA, sapi = %d, tei = %d", sapi, tei);
155 l2sc->rxd_PF = pfbit;
156 i4b_next_l2state(l2sc, EV_RXUA);
162 if((l2sc->tei_valid == TEI_VALID) &&
163 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
165 l2sc->stat.rx_frmr++;
166 NDBGL2(L2_U_MSG, "FRMR, sapi = %d, tei = %d", sapi, tei);
167 l2sc->rxd_PF = pfbit;
168 i4b_next_l2state(l2sc, EV_RXFRMR);
174 if((l2sc->tei_valid == TEI_VALID) &&
175 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
177 NDBGL2(L2_U_ERR, "UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi, tei);
178 i4b_print_frame(m->m_len, m->m_data);
182 NDBGL2(L2_U_ERR, "not mine - UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi, tei);
183 i4b_print_frame(m->m_len, m->m_data);
185 l2sc->stat.err_rx_badui++;
191 /*---------------------------------------------------------------------------*
192 * build U-frame for sending
193 *---------------------------------------------------------------------------*/
195 i4b_build_u_frame(l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type)
199 if((m = i4b_Dgetmbuf(U_FRAME_LEN)) == NULL)
202 PUTSAPI(SAPI_CCP, crbit, m->m_data[OFF_SAPI]);
204 PUTTEI(l2sc->tei, m->m_data[OFF_TEI]);
207 m->m_data[OFF_CNTL] = type | UPBITSET;
209 m->m_data[OFF_CNTL] = type & ~UPBITSET;
214 /*---------------------------------------------------------------------------*
215 * transmit SABME command
216 *---------------------------------------------------------------------------*/
218 i4b_tx_sabme(l2_softc_t *l2sc, pbit_t pbit)
222 l2sc->stat.tx_sabme++;
223 NDBGL2(L2_U_MSG, "tx SABME, tei = %d", l2sc->tei);
224 m = i4b_build_u_frame(l2sc, CR_CMD_TO_NT, pbit, SABME);
225 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
228 /*---------------------------------------------------------------------------*
229 * transmit DM response
230 *---------------------------------------------------------------------------*/
232 i4b_tx_dm(l2_softc_t *l2sc, fbit_t fbit)
237 NDBGL2(L2_U_MSG, "tx DM, tei = %d", l2sc->tei);
238 m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, DM);
239 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
242 /*---------------------------------------------------------------------------*
243 * transmit DISC command
244 *---------------------------------------------------------------------------*/
246 i4b_tx_disc(l2_softc_t *l2sc, pbit_t pbit)
250 l2sc->stat.tx_disc++;
251 NDBGL2(L2_U_MSG, "tx DISC, tei = %d", l2sc->tei);
252 m = i4b_build_u_frame(l2sc, CR_CMD_TO_NT, pbit, DISC);
253 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
256 /*---------------------------------------------------------------------------*
257 * transmit UA response
258 *---------------------------------------------------------------------------*/
260 i4b_tx_ua(l2_softc_t *l2sc, fbit_t fbit)
265 NDBGL2(L2_U_MSG, "tx UA, tei = %d", l2sc->tei);
266 m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, UA);
267 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
270 /*---------------------------------------------------------------------------*
271 * transmit FRMR response
272 *---------------------------------------------------------------------------*/
274 i4b_tx_frmr(l2_softc_t *l2sc, fbit_t fbit)
278 l2sc->stat.tx_frmr++;
279 NDBGL2(L2_U_MSG, "tx FRMR, tei = %d", l2sc->tei);
280 m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, FRMR);
281 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
284 #endif /* NI4BQ921 > 0 */