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