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_sframe.c - s frame handling routines
28 * ----------------------------------------
30 * $Id: i4b_sframe.c,v 1.15 2000/08/24 11:48:58 hm Exp $
32 * $FreeBSD: src/sys/i4b/layer2/i4b_sframe.c,v 1.6.2.1 2001/08/10 14:08:41 obrien Exp $
33 * $DragonFly: src/sys/net/i4b/layer2/i4b_sframe.c,v 1.5 2005/06/14 21:19:19 joerg Exp $
35 * last edit-date: [Mon May 29 16:55:23 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>
49 #include "../include/i4b_l1l2.h"
50 #include "../include/i4b_mbuf.h"
53 #include "i4b_l2fsm.h"
55 /*---------------------------------------------------------------------------*
57 *---------------------------------------------------------------------------*/
59 i4b_rxd_s_frame(int unit, struct mbuf *m)
61 l2_softc_t *l2sc = &l2_softc[unit];
62 u_char *ptr = m->m_data;
64 if(!((l2sc->tei_valid == TEI_VALID) &&
65 (l2sc->tei == GETTEI(*(ptr+OFF_TEI)))))
71 l2sc->rxd_CR = GETCR(*(ptr + OFF_SAPI));
72 l2sc->rxd_PF = GETSPF(*(ptr + OFF_SNR));
73 l2sc->rxd_NR = GETSNR(*(ptr + OFF_SNR));
75 i4b_rxd_ack(l2sc, l2sc->rxd_NR);
77 switch(*(ptr + OFF_SRCR))
80 l2sc->stat.rx_rr++; /* update statistics */
81 NDBGL2(L2_S_MSG, "rx'd RR, N(R) = %d", l2sc->rxd_NR);
82 i4b_next_l2state(l2sc, EV_RXRR);
86 l2sc->stat.rx_rnr++; /* update statistics */
87 NDBGL2(L2_S_MSG, "rx'd RNR, N(R) = %d", l2sc->rxd_NR);
88 i4b_next_l2state(l2sc, EV_RXRNR);
92 l2sc->stat.rx_rej++; /* update statistics */
93 NDBGL2(L2_S_MSG, "rx'd REJ, N(R) = %d", l2sc->rxd_NR);
94 i4b_next_l2state(l2sc, EV_RXREJ);
98 l2sc->stat.err_rx_bads++; /* update statistics */
99 NDBGL2(L2_S_ERR, "ERROR, unknown code, frame = ");
100 i4b_print_frame(m->m_len, m->m_data);
106 /*---------------------------------------------------------------------------*
107 * transmit RR command
108 *---------------------------------------------------------------------------*/
110 i4b_tx_rr_command(l2_softc_t *l2sc, pbit_t pbit)
114 NDBGL2(L2_S_MSG, "tx RR, unit = %d", l2sc->unit);
116 m = i4b_build_s_frame(l2sc, CR_CMD_TO_NT, pbit, RR);
118 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
120 l2sc->stat.tx_rr++; /* update statistics */
123 /*---------------------------------------------------------------------------*
124 * transmit RR response
125 *---------------------------------------------------------------------------*/
127 i4b_tx_rr_response(l2_softc_t *l2sc, fbit_t fbit)
131 NDBGL2(L2_S_MSG, "tx RR, unit = %d", l2sc->unit);
133 m = i4b_build_s_frame(l2sc, CR_RSP_TO_NT, fbit, RR);
135 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
137 l2sc->stat.tx_rr++; /* update statistics */
140 /*---------------------------------------------------------------------------*
141 * transmit RNR command
142 *---------------------------------------------------------------------------*/
144 i4b_tx_rnr_command(l2_softc_t *l2sc, pbit_t pbit)
148 NDBGL2(L2_S_MSG, "tx RNR, unit = %d", l2sc->unit);
150 m = i4b_build_s_frame(l2sc, CR_CMD_TO_NT, pbit, RNR);
152 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
154 l2sc->stat.tx_rnr++; /* update statistics */
157 /*---------------------------------------------------------------------------*
158 * transmit RNR response
159 *---------------------------------------------------------------------------*/
161 i4b_tx_rnr_response(l2_softc_t *l2sc, fbit_t fbit)
165 NDBGL2(L2_S_MSG, "tx RNR, unit = %d", l2sc->unit);
167 m = i4b_build_s_frame(l2sc, CR_RSP_TO_NT, fbit, RNR);
169 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
171 l2sc->stat.tx_rnr++; /* update statistics */
174 /*---------------------------------------------------------------------------*
175 * transmit REJ response
176 *---------------------------------------------------------------------------*/
178 i4b_tx_rej_response(l2_softc_t *l2sc, fbit_t fbit)
182 NDBGL2(L2_S_MSG, "tx REJ, unit = %d", l2sc->unit);
184 m = i4b_build_s_frame(l2sc, CR_RSP_TO_NT, fbit, REJ);
186 PH_Data_Req(l2sc->unit, m, MBUF_FREE);
188 l2sc->stat.tx_rej++; /* update statistics */
191 /*---------------------------------------------------------------------------*
192 * build S-frame for sending
193 *---------------------------------------------------------------------------*/
195 i4b_build_s_frame(l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type)
199 if((m = i4b_Dgetmbuf(S_FRAME_LEN)) == NULL)
202 PUTSAPI(SAPI_CCP, crbit, m->m_data[OFF_SAPI]);
204 PUTTEI(l2sc->tei, m->m_data[OFF_TEI]);
206 m->m_data[OFF_SRCR] = type;
208 m->m_data[OFF_SNR] = (l2sc->vr << 1) | (pbit & 0x01);
213 #endif /* NI4BQ921 > 0 */