2 * $Id: capiutil.h,v 1.2 1997/05/18 09:24:19 calle Exp $
4 * CAPI 2.0 defines & types
6 * From CAPI 2.0 Development Kit AVM 1995 (capi20.h)
7 * Rewritten for Linux 1996 by Carsten Paeth (calle@calle.in-berlin.de)
10 * Revision 1.2 1997/05/18 09:24:19 calle
11 * added verbose disconnect reason reporting to avmb1.
12 * some fixes in capi20 interface.
13 * changed info messages for B1-PCI
15 * Revision 1.1 1997/03/04 21:50:35 calle
16 * Frirst version in isdn4linux
18 * Revision 2.2 1997/02/12 09:31:39 calle
21 * Revision 1.1 1997/01/31 10:32:20 calle
26 #ifndef __CAPIUTIL_H__
27 #define __CAPIUTIL_H__
29 #include <asm/types.h>
31 #define CAPIMSG_LEN(m) (m[0] | (m[1] << 8))
32 #define CAPIMSG_APPID(m) (m[2] | (m[3] << 8))
33 #define CAPIMSG_COMMAND(m) (m[4])
34 #define CAPIMSG_SUBCOMMAND(m) (m[5])
35 #define CAPIMSG_MSGID(m) (m[6] | (m[7] << 8))
36 #define CAPIMSG_CONTROLLER(m) (m[8] & 0x7f)
37 #define CAPIMSG_CONTROL(m) (m[8]|(m[9]<<8)|(m[10]<<16)|(m[11]<<24))
38 #define CAPIMSG_NCCI(m) CAPIMSG_CONTROL(m)
39 #define CAPIMSG_DATA(m) (m[12]|(m[13]<<8)|(m[14]<<16)|(m[15]<<24))
40 #define CAPIMSG_DATALEN(m) (m[16] | (m[17]<<8))
42 #define CAPIMSG_SETAPPID(m, applid) \
44 ((__u8 *)m)[2] = (__u16)(applid) & 0xff; \
45 ((__u8 *)m)[3] = ((__u16)(applid) >> 8) & 0xff; \
48 #define CAPIMSG_SETDATA(m, data) \
50 ((__u8 *)m)[12] = (__u32)(data) & 0xff; \
51 ((__u8 *)m)[13] = ((__u32)(data) >> 8) & 0xff; \
52 ((__u8 *)m)[14] = ((__u32)(data) >> 16) & 0xff; \
53 ((__u8 *)m)[15] = ((__u32)(data) >> 24) & 0xff; \
56 /*----- basic-type definitions -----*/
58 typedef __u8
*_cstruct
;
66 The _cmsg structure contains all possible CAPI 2.0 parameter.
67 All parameters are stored here first. The function CAPI_CMSG_2_MESSAGE
68 assembles the parameter and builds CAPI2.0 conform messages.
69 CAPI_MESSAGE_2_CMSG disassembles CAPI 2.0 messages and stores the
70 parameter in the _cmsg structure
87 _cmstruct AdditionalInfo
;
88 _cstruct B1configuration
;
90 _cstruct B2configuration
;
92 _cstruct B3configuration
;
95 _cstruct BChannelinformation
;
97 _cstruct CalledPartyNumber
;
98 _cstruct CalledPartySubaddress
;
99 _cstruct CallingPartyNumber
;
100 _cstruct CallingPartySubaddress
;
105 _cstruct ConnectedNumber
;
106 _cstruct ConnectedSubaddress
;
110 _cstruct FacilityConfirmationParameter
;
111 _cstruct Facilitydataarray
;
112 _cstruct FacilityIndicationParameter
;
113 _cstruct FacilityRequestParameter
;
114 __u16 FacilitySelector
;
119 _cstruct InfoElement
;
122 _cstruct Keypadfacility
;
130 _cstruct Useruserdata
;
137 /* buffer to construct message */
143 * capi_cmsg2message() assembles the parameter from _cmsg to a CAPI 2.0
146 unsigned capi_cmsg2message(_cmsg
* cmsg
, __u8
* msg
);
149 * capi_message2cmsg disassembles a CAPI message an writes the parameter
150 * into _cmsg for easy access
152 unsigned capi_message2cmsg(_cmsg
* cmsg
, __u8
* msg
);
155 * capi_cmsg_header() fills the _cmsg structure with default values, so only
156 * parameter with non default values must be changed before sending the
159 unsigned capi_cmsg_header(_cmsg
* cmsg
, __u16 _ApplId
,
160 __u8 _Command
, __u8 _Subcommand
,
161 __u16 _Messagenumber
, __u32 _Controller
);
164 * capi_info2str generated a readable string for Capi2.0 reasons.
166 char *capi_info2str(__u16 reason
);
168 /*-----------------------------------------------------------------------*/
171 * Debugging / Tracing functions
173 char *capi_cmd2str(__u8 cmd
, __u8 subcmd
);
174 char *capi_cmsg2str(_cmsg
* cmsg
);
175 char *capi_message2str(__u8
* msg
);
177 /*-----------------------------------------------------------------------*/
179 static inline void capi_cmsg_answer(_cmsg
* cmsg
)
181 cmsg
->Subcommand
|= 0x01;
184 /*-----------------------------------------------------------------------*/
186 static inline void capi_fill_CONNECT_B3_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
190 capi_cmsg_header(cmsg
, ApplId
, 0x82, 0x80, Messagenumber
, adr
);
194 static inline void capi_fill_FACILITY_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
196 __u16 FacilitySelector
,
197 _cstruct FacilityRequestParameter
)
199 capi_cmsg_header(cmsg
, ApplId
, 0x80, 0x80, Messagenumber
, adr
);
200 cmsg
->FacilitySelector
= FacilitySelector
;
201 cmsg
->FacilityRequestParameter
= FacilityRequestParameter
;
204 static inline void capi_fill_INFO_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
206 _cstruct CalledPartyNumber
,
207 _cstruct BChannelinformation
,
208 _cstruct Keypadfacility
,
209 _cstruct Useruserdata
,
210 _cstruct Facilitydataarray
)
212 capi_cmsg_header(cmsg
, ApplId
, 0x08, 0x80, Messagenumber
, adr
);
213 cmsg
->CalledPartyNumber
= CalledPartyNumber
;
214 cmsg
->BChannelinformation
= BChannelinformation
;
215 cmsg
->Keypadfacility
= Keypadfacility
;
216 cmsg
->Useruserdata
= Useruserdata
;
217 cmsg
->Facilitydataarray
= Facilitydataarray
;
220 static inline void capi_fill_LISTEN_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
225 _cstruct CallingPartyNumber
,
226 _cstruct CallingPartySubaddress
)
228 capi_cmsg_header(cmsg
, ApplId
, 0x05, 0x80, Messagenumber
, adr
);
229 cmsg
->InfoMask
= InfoMask
;
230 cmsg
->CIPmask
= CIPmask
;
231 cmsg
->CIPmask2
= CIPmask2
;
232 cmsg
->CallingPartyNumber
= CallingPartyNumber
;
233 cmsg
->CallingPartySubaddress
= CallingPartySubaddress
;
236 static inline void capi_fill_ALERT_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
238 _cstruct BChannelinformation
,
239 _cstruct Keypadfacility
,
240 _cstruct Useruserdata
,
241 _cstruct Facilitydataarray
)
243 capi_cmsg_header(cmsg
, ApplId
, 0x01, 0x80, Messagenumber
, adr
);
244 cmsg
->BChannelinformation
= BChannelinformation
;
245 cmsg
->Keypadfacility
= Keypadfacility
;
246 cmsg
->Useruserdata
= Useruserdata
;
247 cmsg
->Facilitydataarray
= Facilitydataarray
;
250 static inline void capi_fill_CONNECT_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
253 _cstruct CalledPartyNumber
,
254 _cstruct CallingPartyNumber
,
255 _cstruct CalledPartySubaddress
,
256 _cstruct CallingPartySubaddress
,
260 _cstruct B1configuration
,
261 _cstruct B2configuration
,
262 _cstruct B3configuration
,
266 _cstruct BChannelinformation
,
267 _cstruct Keypadfacility
,
268 _cstruct Useruserdata
,
269 _cstruct Facilitydataarray
)
272 capi_cmsg_header(cmsg
, ApplId
, 0x02, 0x80, Messagenumber
, adr
);
273 cmsg
->CIPValue
= CIPValue
;
274 cmsg
->CalledPartyNumber
= CalledPartyNumber
;
275 cmsg
->CallingPartyNumber
= CallingPartyNumber
;
276 cmsg
->CalledPartySubaddress
= CalledPartySubaddress
;
277 cmsg
->CallingPartySubaddress
= CallingPartySubaddress
;
278 cmsg
->B1protocol
= B1protocol
;
279 cmsg
->B2protocol
= B2protocol
;
280 cmsg
->B3protocol
= B3protocol
;
281 cmsg
->B1configuration
= B1configuration
;
282 cmsg
->B2configuration
= B2configuration
;
283 cmsg
->B3configuration
= B3configuration
;
287 cmsg
->BChannelinformation
= BChannelinformation
;
288 cmsg
->Keypadfacility
= Keypadfacility
;
289 cmsg
->Useruserdata
= Useruserdata
;
290 cmsg
->Facilitydataarray
= Facilitydataarray
;
293 static inline void capi_fill_DATA_B3_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
301 capi_cmsg_header(cmsg
, ApplId
, 0x86, 0x80, Messagenumber
, adr
);
303 cmsg
->DataLength
= DataLength
;
304 cmsg
->DataHandle
= DataHandle
;
308 static inline void capi_fill_DISCONNECT_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
310 _cstruct BChannelinformation
,
311 _cstruct Keypadfacility
,
312 _cstruct Useruserdata
,
313 _cstruct Facilitydataarray
)
316 capi_cmsg_header(cmsg
, ApplId
, 0x04, 0x80, Messagenumber
, adr
);
317 cmsg
->BChannelinformation
= BChannelinformation
;
318 cmsg
->Keypadfacility
= Keypadfacility
;
319 cmsg
->Useruserdata
= Useruserdata
;
320 cmsg
->Facilitydataarray
= Facilitydataarray
;
323 static inline void capi_fill_DISCONNECT_B3_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
328 capi_cmsg_header(cmsg
, ApplId
, 0x84, 0x80, Messagenumber
, adr
);
332 static inline void capi_fill_MANUFACTURER_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
340 capi_cmsg_header(cmsg
, ApplId
, 0xff, 0x80, Messagenumber
, adr
);
341 cmsg
->ManuID
= ManuID
;
343 cmsg
->Function
= Function
;
344 cmsg
->ManuData
= ManuData
;
347 static inline void capi_fill_RESET_B3_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
352 capi_cmsg_header(cmsg
, ApplId
, 0x87, 0x80, Messagenumber
, adr
);
356 static inline void capi_fill_SELECT_B_PROTOCOL_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
361 _cstruct B1configuration
,
362 _cstruct B2configuration
,
363 _cstruct B3configuration
)
366 capi_cmsg_header(cmsg
, ApplId
, 0x41, 0x80, Messagenumber
, adr
);
367 cmsg
->B1protocol
= B1protocol
;
368 cmsg
->B2protocol
= B2protocol
;
369 cmsg
->B3protocol
= B3protocol
;
370 cmsg
->B1configuration
= B1configuration
;
371 cmsg
->B2configuration
= B2configuration
;
372 cmsg
->B3configuration
= B3configuration
;
375 static inline void capi_fill_CONNECT_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
381 _cstruct B1configuration
,
382 _cstruct B2configuration
,
383 _cstruct B3configuration
,
384 _cstruct ConnectedNumber
,
385 _cstruct ConnectedSubaddress
,
387 _cstruct BChannelinformation
,
388 _cstruct Keypadfacility
,
389 _cstruct Useruserdata
,
390 _cstruct Facilitydataarray
)
392 capi_cmsg_header(cmsg
, ApplId
, 0x02, 0x83, Messagenumber
, adr
);
393 cmsg
->Reject
= Reject
;
394 cmsg
->B1protocol
= B1protocol
;
395 cmsg
->B2protocol
= B2protocol
;
396 cmsg
->B3protocol
= B3protocol
;
397 cmsg
->B1configuration
= B1configuration
;
398 cmsg
->B2configuration
= B2configuration
;
399 cmsg
->B3configuration
= B3configuration
;
400 cmsg
->ConnectedNumber
= ConnectedNumber
;
401 cmsg
->ConnectedSubaddress
= ConnectedSubaddress
;
403 cmsg
->BChannelinformation
= BChannelinformation
;
404 cmsg
->Keypadfacility
= Keypadfacility
;
405 cmsg
->Useruserdata
= Useruserdata
;
406 cmsg
->Facilitydataarray
= Facilitydataarray
;
409 static inline void capi_fill_CONNECT_ACTIVE_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
413 capi_cmsg_header(cmsg
, ApplId
, 0x03, 0x83, Messagenumber
, adr
);
416 static inline void capi_fill_CONNECT_B3_ACTIVE_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
420 capi_cmsg_header(cmsg
, ApplId
, 0x83, 0x83, Messagenumber
, adr
);
423 static inline void capi_fill_CONNECT_B3_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
428 capi_cmsg_header(cmsg
, ApplId
, 0x82, 0x83, Messagenumber
, adr
);
429 cmsg
->Reject
= Reject
;
433 static inline void capi_fill_CONNECT_B3_T90_ACTIVE_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
437 capi_cmsg_header(cmsg
, ApplId
, 0x88, 0x83, Messagenumber
, adr
);
440 static inline void capi_fill_DATA_B3_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
445 capi_cmsg_header(cmsg
, ApplId
, 0x86, 0x83, Messagenumber
, adr
);
446 cmsg
->DataHandle
= DataHandle
;
449 static inline void capi_fill_DISCONNECT_B3_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
453 capi_cmsg_header(cmsg
, ApplId
, 0x84, 0x83, Messagenumber
, adr
);
456 static inline void capi_fill_DISCONNECT_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
460 capi_cmsg_header(cmsg
, ApplId
, 0x04, 0x83, Messagenumber
, adr
);
463 static inline void capi_fill_FACILITY_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
465 __u16 FacilitySelector
)
468 capi_cmsg_header(cmsg
, ApplId
, 0x80, 0x83, Messagenumber
, adr
);
469 cmsg
->FacilitySelector
= FacilitySelector
;
472 static inline void capi_fill_INFO_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
476 capi_cmsg_header(cmsg
, ApplId
, 0x08, 0x83, Messagenumber
, adr
);
479 static inline void capi_fill_MANUFACTURER_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
487 capi_cmsg_header(cmsg
, ApplId
, 0xff, 0x83, Messagenumber
, adr
);
488 cmsg
->ManuID
= ManuID
;
490 cmsg
->Function
= Function
;
491 cmsg
->ManuData
= ManuData
;
494 static inline void capi_fill_RESET_B3_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
498 capi_cmsg_header(cmsg
, ApplId
, 0x87, 0x83, Messagenumber
, adr
);
501 #endif /* __CAPIUTIL_H__ */