1/*	$NetBSD: i4b_capi_msgs.h,v 1.3 2005/12/24 20:45:09 perry Exp $	*/
2
3/*
4 * Copyright (c) 2001-2003 Cubical Solutions Ltd. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * capi/capi_msgs.h	The CAPI i4b message and handler declarations.
28 *
29 * $FreeBSD: src/sys/i4b/capi/capi_msgs.h,v 1.1 2001/05/25 08:39:31 hm Exp $
30 */
31
32#ifndef _NETISDN_I4B_CAPI_MSGS_H_
33#define _NETISDN_I4B_CAPI_MSGS_H_
34
35/* CAPI commands */
36
37#define CAPI_ALERT                   0x01
38#define CAPI_CONNECT                 0x02
39#define CAPI_CONNECT_ACTIVE          0x03
40#define CAPI_CONNECT_B3              0x82
41#define CAPI_CONNECT_B3_ACTIVE       0x83
42#define CAPI_CONNECT_B3_T90_ACTIVE   0x88
43#define CAPI_DATA_B3                 0x86
44#define CAPI_DISCONNECT_B3           0x84
45#define CAPI_DISCONNECT              0x04
46#define CAPI_FACILITY                0x80
47#define CAPI_INFO                    0x08
48#define CAPI_LISTEN                  0x05
49#define CAPI_MANUFACTURER            0xff
50#define CAPI_RESET_B3                0x87
51#define CAPI_SELECT_B_PROTOCOL       0x41
52
53/* CAPI subcommands */
54
55#define CAPI_REQ                     0x80
56#define CAPI_CONF                    0x81
57#define CAPI_IND                     0x82
58#define CAPI_RESP                    0x83
59
60/* CAPI combined commands */
61
62#define CAPICMD(cmd,subcmd)          (((subcmd)<<8)|(cmd))
63
64#define CAPI_DISCONNECT_REQ          CAPICMD(CAPI_DISCONNECT,CAPI_REQ)
65#define CAPI_DISCONNECT_CONF         CAPICMD(CAPI_DISCONNECT,CAPI_CONF)
66#define CAPI_DISCONNECT_IND          CAPICMD(CAPI_DISCONNECT,CAPI_IND)
67#define CAPI_DISCONNECT_RESP         CAPICMD(CAPI_DISCONNECT,CAPI_RESP)
68
69#define CAPI_ALERT_REQ               CAPICMD(CAPI_ALERT,CAPI_REQ)
70#define CAPI_ALERT_CONF              CAPICMD(CAPI_ALERT,CAPI_CONF)
71
72#define CAPI_CONNECT_REQ             CAPICMD(CAPI_CONNECT,CAPI_REQ)
73#define CAPI_CONNECT_CONF            CAPICMD(CAPI_CONNECT,CAPI_CONF)
74#define CAPI_CONNECT_IND             CAPICMD(CAPI_CONNECT,CAPI_IND)
75#define CAPI_CONNECT_RESP            CAPICMD(CAPI_CONNECT,CAPI_RESP)
76
77#define CAPI_CONNECT_ACTIVE_REQ      CAPICMD(CAPI_CONNECT_ACTIVE,CAPI_REQ)
78#define CAPI_CONNECT_ACTIVE_CONF     CAPICMD(CAPI_CONNECT_ACTIVE,CAPI_CONF)
79#define CAPI_CONNECT_ACTIVE_IND      CAPICMD(CAPI_CONNECT_ACTIVE,CAPI_IND)
80#define CAPI_CONNECT_ACTIVE_RESP     CAPICMD(CAPI_CONNECT_ACTIVE,CAPI_RESP)
81
82#define CAPI_SELECT_B_PROTOCOL_REQ   CAPICMD(CAPI_SELECT_B_PROTOCOL,CAPI_REQ)
83#define CAPI_SELECT_B_PROTOCOL_CONF  CAPICMD(CAPI_SELECT_B_PROTOCOL,CAPI_CONF)
84
85#define CAPI_CONNECT_B3_REQ          CAPICMD(CAPI_CONNECT_B3,CAPI_REQ)
86#define CAPI_CONNECT_B3_CONF         CAPICMD(CAPI_CONNECT_B3,CAPI_CONF)
87#define CAPI_CONNECT_B3_IND          CAPICMD(CAPI_CONNECT_B3,CAPI_IND)
88#define CAPI_CONNECT_B3_RESP         CAPICMD(CAPI_CONNECT_B3,CAPI_RESP)
89
90#define CAPI_CONNECT_B3_ACTIVE_REQ   CAPICMD(CAPI_CONNECT_B3_ACTIVE,CAPI_REQ)
91#define CAPI_CONNECT_B3_ACTIVE_CONF  CAPICMD(CAPI_CONNECT_B3_ACTIVE,CAPI_CONF)
92#define CAPI_CONNECT_B3_ACTIVE_IND   CAPICMD(CAPI_CONNECT_B3_ACTIVE,CAPI_IND)
93#define CAPI_CONNECT_B3_ACTIVE_RESP  CAPICMD(CAPI_CONNECT_B3_ACTIVE,CAPI_RESP)
94
95#define CAPI_CONNECT_B3_T90_ACTIVE_IND CAPICMD(CAPI_CONNECT_B3_T90_ACTIVE,CAPI_IND)
96#define CAPI_CONNECT_B3_T90_ACTIVE_RESP CAPICMD(CAPI_CONNECT_B3_T90_ACTIVE,CAPI_RESP)
97
98#define CAPI_DATA_B3_REQ             CAPICMD(CAPI_DATA_B3,CAPI_REQ)
99#define CAPI_DATA_B3_CONF            CAPICMD(CAPI_DATA_B3,CAPI_CONF)
100#define CAPI_DATA_B3_IND             CAPICMD(CAPI_DATA_B3,CAPI_IND)
101#define CAPI_DATA_B3_RESP            CAPICMD(CAPI_DATA_B3,CAPI_RESP)
102
103#define CAPI_DISCONNECT_B3_REQ       CAPICMD(CAPI_DISCONNECT_B3,CAPI_REQ)
104#define CAPI_DISCONNECT_B3_CONF      CAPICMD(CAPI_DISCONNECT_B3,CAPI_CONF)
105#define CAPI_DISCONNECT_B3_IND       CAPICMD(CAPI_DISCONNECT_B3,CAPI_IND)
106#define CAPI_DISCONNECT_B3_RESP      CAPICMD(CAPI_DISCONNECT_B3,CAPI_RESP)
107
108#define CAPI_RESET_B3_REQ            CAPICMD(CAPI_RESET_B3,CAPI_REQ)
109#define CAPI_RESET_B3_CONF           CAPICMD(CAPI_RESET_B3,CAPI_CONF)
110#define CAPI_RESET_B3_IND            CAPICMD(CAPI_RESET_B3,CAPI_IND)
111#define CAPI_RESET_B3_RESP           CAPICMD(CAPI_RESET_B3,CAPI_RESP)
112
113#define CAPI_LISTEN_REQ              CAPICMD(CAPI_LISTEN,CAPI_REQ)
114#define CAPI_LISTEN_CONF             CAPICMD(CAPI_LISTEN,CAPI_CONF)
115
116#define CAPI_MANUFACTURER_REQ        CAPICMD(CAPI_MANUFACTURER,CAPI_REQ)
117#define CAPI_MANUFACTURER_CONF       CAPICMD(CAPI_MANUFACTURER,CAPI_CONF)
118#define CAPI_MANUFACTURER_IND        CAPICMD(CAPI_MANUFACTURER,CAPI_IND)
119#define CAPI_MANUFACTURER_RESP       CAPICMD(CAPI_MANUFACTURER,CAPI_RESP)
120
121#define CAPI_FACILITY_REQ            CAPICMD(CAPI_FACILITY,CAPI_REQ)
122#define CAPI_FACILITY_CONF           CAPICMD(CAPI_FACILITY,CAPI_CONF)
123#define CAPI_FACILITY_IND            CAPICMD(CAPI_FACILITY,CAPI_IND)
124#define CAPI_FACILITY_RESP           CAPICMD(CAPI_FACILITY,CAPI_RESP)
125
126#define CAPI_INFO_REQ                CAPICMD(CAPI_INFO,CAPI_REQ)
127#define CAPI_INFO_CONF               CAPICMD(CAPI_INFO,CAPI_CONF)
128#define CAPI_INFO_IND                CAPICMD(CAPI_INFO,CAPI_IND)
129#define CAPI_INFO_RESP               CAPICMD(CAPI_INFO,CAPI_RESP)
130
131/* CAPI message access helpers */
132
133/*
134 * CAPI message header:
135 * word   Length
136 * word   ApplId
137 * byte   Command
138 * byte   Subcommand
139 * word   MsgId
140 *
141 * Note that in the following, Controller/PLCI/NCCI is coded as follows:
142 * bits 0..6 = controller, bit 7 = ext/int, bits 8..15 = PLCI, and
143 * bits 16..31 = NCCI value.
144 *
145 * ALERT_REQ, 01 80:
146 * dword  PLCI
147 * struct Additional Info
148 *
149 * ALERT_CONF, 01 81:
150 * dword  PLCI
151 * word   Info (0 = OK, other = cause)
152 *
153 * CONNECT_REQ, 02 80:
154 * dword  controller
155 * word   CIP
156 * struct Called party number
157 * struct Calling party number
158 * struct Called party subaddress
159 * struct Calling party subaddress
160 * struct Bearer Capability
161 * struct Low Layer Compatibility
162 * struct High Layer Compatibility
163 * struct Additional Info
164 *
165 * CONNECT_CONF, 02 81:
166 * dword  PLCI
167 * word   Info (0 = OK, other = cause)
168 *
169 * CONNECT_IND, 02 82:
170 * dword  PLCI
171 * word   CIP
172 * struct Called party number
173 * struct Calling party number
174 * struct Called party subaddress
175 * struct Calling party subaddress
176 * struct Bearer Capability
177 * struct Low Layer Compatibility
178 * struct High Layer Compatibility
179 * struct Additional Info
180 * struct Second Calling party number
181 *
182 * CONNECT_RESP, 02 83:
183 * dword  PLCI
184 * word   Reject (0 = accept, 1 = ignore, 2 = reject/normal clearing)
185 * struct B protocol
186 * struct Connected number
187 * struct Connected subaddress
188 * struct Low Layer Compatibility
189 * struct Additional Info
190 *
191 * CONNECT_ACTIVE_IND, 03 82:
192 * dword  PLCI
193 * struct Connected number
194 * struct Connected subaddress
195 * struct Low Layer Compatibility
196 *
197 * CONNECT_ACTIVE_RESP, 03 83:
198 * dword  PLCI
199 *
200 * CONNECT_B3_REQ, 82 80:
201 * dword  PLCI
202 * struct NCPI
203 *
204 * CONNECT_B3_CONF, 82 81:
205 * dword  NCCI
206 * word   Info (0 = connected, other = cause)
207 *
208 * CONNECT_B3_IND, 82 82:
209 * dword  NCCI
210 * struct NCPI
211 *
212 * CONNECT_B3_RESP, 82 83:
213 * dword  NCCI
214 * word   Reject (0 = accept, 2 = reject/normal clearing)
215 * struct NCPI
216 *
217 * CONNECT_B3_ACTIVE_IND, 83 82:
218 * dword  NCCI
219 * struct NCPI
220 *
221 * CONNECT_B3_ACTIVE_RESP, 83  83:
222 * dword  NCCI
223 *
224 * DATA_B3_REQ, 86 80:
225 * dword  NCCI
226 * dword  Data pointer
227 * word   Data length
228 * word   Data handle (packet id)
229 * word   Flags (02 = more)
230 *
231 * DATA_B3_CONF, 86 81:
232 * dword  NCCI
233 * word   Data handle (packet id)
234 * word   Info (0 = OK, other = cause)
235 *
236 * DATA_B3_IND, 86 82:
237 * dword  NCCI
238 * dword  Data pointer
239 * word   Data length
240 * word   Data handle (packet id)
241 * word   Flags (02 = more)
242 *
243 * DATA_B3_RESP, 86 83:
244 * dword  NCCI
245 * word   Data handle (packet id)
246 *
247 * DISCONNECT_B3_REQ, 84 80:
248 * dword  NCCI
249 * struct NCPI
250 *
251 * DISCONNECT_B3_CONF, 84 81:
252 * dword  NCCI
253 * word   Info (0 = OK, other = cause)
254 *
255 * DISCONNECT_B3_IND, 84 82:
256 * dword  NCCI
257 * word   Reason
258 * struct NCPI
259 *
260 * DISCONNECT_B3_RESP, 84 83:
261 * dword  NCCI
262 *
263 * DISCONNECT_REQ, 04 80:
264 * dword  PLCI
265 * struct Additional Info
266 *
267 * DISCONNECT_CONF, 04 81:
268 * dword  PLCI
269 * word   Info (0 = OK, other = cause)
270 *
271 * DISCONNECT_IND, 04 82:
272 * dword  PLCI
273 * word   Reason
274 *
275 * DISCONNECT_RESP, 04 83:
276 * dword  PLCI
277 *
278 * LISTEN_REQ, 05 80:
279 * dword  Controller
280 * dword  Info mask (bits 0..9 used)
281 * dword  CIP Mask (bit 0 = any match)
282 * dword  CIP Mask 2 (bit 0 = any match)
283 * struct Calling party number
284 * struct Calling party subaddress
285 *
286 * LISTEN_CONF, 05 81:
287 * dword  Controller
288 * word   Info (0 = OK, other = cause)
289 *
290 * INFO_REQ, 08 80:
291 * dword  Controller/PLCI
292 * struct Called party number
293 * struct Additional Info
294 *
295 * INFO_CONF, 08 81:
296 * dword  Controller/PLCI
297 * word   Info (0 = OK, other = cause)
298 *
299 * INFO_IND, 08 82:
300 * dword  Controller/PLCI
301 * word   Info number
302 * struct Info element
303 *
304 * INFO_RESP, 08 83:
305 * dword  Controller/PLCI
306 */
307
308#define CAPIMSG_LEN(msg)             (msg[0]|(msg[1]<<8))
309#define CAPIMSG_DATALEN(msg)         (msg[16]|(msg[17]<<8))
310
311static __inline u_int8_t* capimsg_getu8(u_int8_t *msg, u_int8_t *val)
312{
313    *val = *msg;
314    return (msg + 1);
315}
316
317static __inline u_int8_t* capimsg_getu16(u_int8_t *msg, u_int16_t *val)
318{
319    *val = (msg[0]|(msg[1]<<8));
320    return (msg + 2);
321}
322
323static __inline u_int8_t* capimsg_getu32(u_int8_t *msg, u_int32_t *val)
324{
325    *val = (msg[0]|(msg[1]<<8)|(msg[2]<<16)|(msg[3]<<24));
326    return (msg + 4);
327}
328
329static __inline u_int8_t* capimsg_setu8(u_int8_t *msg, u_int8_t val)
330{
331    msg[0] = val;
332    return (msg + 1);
333}
334
335static __inline u_int8_t* capimsg_setu16(u_int8_t *msg, u_int16_t val)
336{
337    msg[0] = (val & 0xff);
338    msg[1] = (val >> 8) & 0xff;
339    return (msg + 2);
340}
341
342static __inline u_int8_t* capimsg_setu32(u_int8_t *msg, u_int32_t val)
343{
344    msg[0] = (val & 0xff);
345    msg[1] = (val >> 8) & 0xff;
346    msg[2] = (val >> 16) & 0xff;
347    msg[3] = (val >> 24) & 0xff;
348    return (msg + 4);
349}
350
351/*
352//  CAPI message handlers called by higher layers
353*/
354
355extern void capi_listen_req(capi_softc_t *sc, u_int32_t CIP);
356extern void capi_alert_req(capi_softc_t *sc, call_desc_t *cd);
357extern void capi_connect_req(capi_softc_t *sc, call_desc_t *cd);
358extern void capi_connect_b3_req(capi_softc_t *sc, call_desc_t *cd);
359extern void capi_connect_resp(capi_softc_t *sc, call_desc_t *cd);
360extern void capi_data_b3_req(capi_softc_t *sc, int chan, struct mbuf *m);
361extern void capi_disconnect_req(capi_softc_t *sc, call_desc_t *cd);
362
363/*
364//  CAPI message handlers called by the receive routine
365*/
366
367extern void capi_listen_conf(capi_softc_t *sc, struct mbuf *m);
368extern void capi_info_ind(capi_softc_t *sc, struct mbuf *m);
369extern void capi_alert_conf(capi_softc_t *sc, struct mbuf *m);
370extern void capi_connect_conf(capi_softc_t *sc, struct mbuf *m);
371extern void capi_connect_active_ind(capi_softc_t *sc, struct mbuf *m);
372extern void capi_connect_b3_conf(capi_softc_t *sc, struct mbuf *m);
373extern void capi_connect_b3_active_ind(capi_softc_t *sc, struct mbuf *m);
374extern void capi_connect_ind(capi_softc_t *sc, struct mbuf *m);
375extern void capi_connect_b3_ind(capi_softc_t *sc, struct mbuf *m);
376extern void capi_data_b3_conf(capi_softc_t *sc, struct mbuf *m);
377extern void capi_data_b3_ind(capi_softc_t *sc, struct mbuf *m);
378extern void capi_disconnect_conf(capi_softc_t *sc, struct mbuf *m);
379extern void capi_disconnect_b3_ind(capi_softc_t *sc, struct mbuf *m);
380extern void capi_disconnect_ind(capi_softc_t *sc, struct mbuf *m);
381
382#endif /* !_NETISDN_I4B_CAPI_MSGS_H_ */
383