Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / netisdn / i4b_uframe.c
blob0f0b75ea6a96cd1aaa10b5444607c00d5fb18989
1 /*
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
6 * are met:
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
23 * SUCH DAMAGE.
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 $
32 * $FreeBSD$
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 $");
41 #ifdef __FreeBSD__
42 #include "i4bq921.h"
43 #else
44 #define NI4BQ921 1
45 #endif
46 #if NI4BQ921 > 0
48 #include <sys/param.h>
49 #include <sys/kernel.h>
50 #include <sys/systm.h>
51 #include <sys/mbuf.h>
52 #include <sys/socket.h>
53 #include <net/if.h>
55 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
56 #include <sys/callout.h>
57 #endif
59 #ifdef __FreeBSD__
60 #include <machine/i4b_debug.h>
61 #include <machine/i4b_ioctl.h>
62 #else
63 #include <netisdn/i4b_debug.h>
64 #include <netisdn/i4b_ioctl.h>
65 #endif
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 *---------------------------------------------------------------------------*/
77 void
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)
88 /* commands */
90 case SABME:
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);
96 l2sc->rxd_PF = pfbit;
97 i4b_next_l2state(l2sc, drv, EV_RXSABME);
99 i4b_Dfreembuf(m);
100 break;
102 case UI:
103 if(sapi == SAPI_L2M &&
104 tei == GROUP_TEI &&
105 *(ptr + OFF_MEI) == MEI)
107 /* layer 2 management (SAPI = 63) */
108 l2sc->stat.rx_tei++;
109 i4b_tei_rxframe(l2sc, drv, m);
111 else if(sapi == SAPI_CCP && tei == GROUP_TEI)
113 /* call control (SAPI = 0) */
114 l2sc->stat.rx_ui++;
115 /* strip ui header */
116 m_adj(m, UI_HDR_LEN);
117 /* to upper layer */
118 i4b_dl_unit_data_ind(l2sc->drv, m);
120 else
122 l2sc->stat.err_rx_badui++;
123 NDBGL2(L2_U_ERR, "unknown UI frame!");
124 i4b_Dfreembuf(m);
126 break;
128 case DISC:
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);
137 i4b_Dfreembuf(m);
138 break;
140 case XID:
141 if((l2sc->tei_valid == TEI_VALID) &&
142 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
144 l2sc->stat.rx_xid++;
145 NDBGL2(L2_U_MSG, "XID, sapi = %d, tei = %d", sapi, tei);
147 i4b_Dfreembuf(m);
148 break;
150 /* responses */
152 case DM:
153 if((l2sc->tei_valid == TEI_VALID) &&
154 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
156 l2sc->stat.rx_dm++;
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);
162 i4b_Dfreembuf(m);
163 break;
165 case UA:
166 if((l2sc->tei_valid == TEI_VALID) &&
167 (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
169 l2sc->stat.rx_ua++;
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);
174 i4b_Dfreembuf(m);
175 break;
177 case FRMR:
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);
186 i4b_Dfreembuf(m);
187 break;
189 default:
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);
196 else
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++;
202 i4b_Dfreembuf(m);
203 break;
207 /*---------------------------------------------------------------------------*
208 * build U-frame for sending
209 *---------------------------------------------------------------------------*/
210 struct mbuf *
211 i4b_build_u_frame(l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type)
213 struct mbuf *m;
215 if((m = i4b_Dgetmbuf(U_FRAME_LEN)) == NULL)
216 return(NULL);
218 PUTSAPI(SAPI_CCP, crbit, m->m_data[OFF_SAPI]);
220 PUTTEI(l2sc->tei, m->m_data[OFF_TEI]);
222 if(pbit)
223 m->m_data[OFF_CNTL] = type | UPBITSET;
224 else
225 m->m_data[OFF_CNTL] = type & ~UPBITSET;
227 return(m);
230 /*---------------------------------------------------------------------------*
231 * transmit SABME command
232 *---------------------------------------------------------------------------*/
233 void
234 i4b_tx_sabme(l2_softc_t *l2sc, pbit_t pbit)
236 struct mbuf *m;
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 *---------------------------------------------------------------------------*/
247 void
248 i4b_tx_dm(l2_softc_t *l2sc, fbit_t fbit)
250 struct mbuf *m;
252 l2sc->stat.tx_dm++;
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 *---------------------------------------------------------------------------*/
261 void
262 i4b_tx_disc(l2_softc_t *l2sc, pbit_t pbit)
264 struct mbuf *m;
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 *---------------------------------------------------------------------------*/
275 void
276 i4b_tx_ua(l2_softc_t *l2sc, fbit_t fbit)
278 struct mbuf *m;
280 l2sc->stat.tx_ua++;
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 *---------------------------------------------------------------------------*/
289 void
290 i4b_tx_frmr(l2_softc_t *l2sc, fbit_t fbit)
292 struct mbuf *m;
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 */