1 /* $Id: capiutil.h,v 1.5.6.2 2001/09/23 22:24:33 kai Exp $
3 * CAPI 2.0 defines & types
5 * From CAPI 2.0 Development Kit AVM 1995 (msg.c)
6 * Rewritten for Linux 1996 by Carsten Paeth <calle@calle.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
13 #ifndef __CAPIUTIL_H__
14 #define __CAPIUTIL_H__
16 #include <asm/types.h>
18 #define CAPIMSG_BASELEN 8
19 #define CAPIMSG_U8(m, off) (m[off])
20 #define CAPIMSG_U16(m, off) (m[off]|(m[(off)+1]<<8))
21 #define CAPIMSG_U32(m, off) (m[off]|(m[(off)+1]<<8)|(m[(off)+2]<<16)|(m[(off)+3]<<24))
22 #define CAPIMSG_LEN(m) CAPIMSG_U16(m,0)
23 #define CAPIMSG_APPID(m) CAPIMSG_U16(m,2)
24 #define CAPIMSG_COMMAND(m) CAPIMSG_U8(m,4)
25 #define CAPIMSG_SUBCOMMAND(m) CAPIMSG_U8(m,5)
26 #define CAPIMSG_CMD(m) (((m[4])<<8)|(m[5]))
27 #define CAPIMSG_MSGID(m) CAPIMSG_U16(m,6)
28 #define CAPIMSG_CONTROLLER(m) (m[8] & 0x7f)
29 #define CAPIMSG_CONTROL(m) CAPIMSG_U32(m, 8)
30 #define CAPIMSG_NCCI(m) CAPIMSG_CONTROL(m)
31 #define CAPIMSG_DATALEN(m) CAPIMSG_U16(m,16) /* DATA_B3_REQ */
33 static inline void capimsg_setu8(void *m
, int off
, __u8 val
)
35 ((__u8
*)m
)[off
] = val
;
38 static inline void capimsg_setu16(void *m
, int off
, __u16 val
)
40 ((__u8
*)m
)[off
] = val
& 0xff;
41 ((__u8
*)m
)[off
+1] = (val
>> 8) & 0xff;
44 static inline void capimsg_setu32(void *m
, int off
, __u32 val
)
46 ((__u8
*)m
)[off
] = val
& 0xff;
47 ((__u8
*)m
)[off
+1] = (val
>> 8) & 0xff;
48 ((__u8
*)m
)[off
+2] = (val
>> 16) & 0xff;
49 ((__u8
*)m
)[off
+3] = (val
>> 24) & 0xff;
52 #define CAPIMSG_SETLEN(m, len) capimsg_setu16(m, 0, len)
53 #define CAPIMSG_SETAPPID(m, applid) capimsg_setu16(m, 2, applid)
54 #define CAPIMSG_SETCOMMAND(m,cmd) capimsg_setu8(m, 4, cmd)
55 #define CAPIMSG_SETSUBCOMMAND(m, cmd) capimsg_setu8(m, 5, cmd)
56 #define CAPIMSG_SETMSGID(m, msgid) capimsg_setu16(m, 6, msgid)
57 #define CAPIMSG_SETCONTROL(m, contr) capimsg_setu32(m, 8, contr)
58 #define CAPIMSG_SETDATALEN(m, len) capimsg_setu16(m, 16, len)
60 /*----- basic-type definitions -----*/
62 typedef __u8
*_cstruct
;
70 The _cmsg structure contains all possible CAPI 2.0 parameter.
71 All parameters are stored here first. The function CAPI_CMSG_2_MESSAGE
72 assembles the parameter and builds CAPI2.0 conform messages.
73 CAPI_MESSAGE_2_CMSG disassembles CAPI 2.0 messages and stores the
74 parameter in the _cmsg structure
91 _cmstruct AdditionalInfo
;
92 _cstruct B1configuration
;
94 _cstruct B2configuration
;
96 _cstruct B3configuration
;
99 _cstruct BChannelinformation
;
101 _cstruct CalledPartyNumber
;
102 _cstruct CalledPartySubaddress
;
103 _cstruct CallingPartyNumber
;
104 _cstruct CallingPartySubaddress
;
109 _cstruct ConnectedNumber
;
110 _cstruct ConnectedSubaddress
;
114 _cstruct FacilityConfirmationParameter
;
115 _cstruct Facilitydataarray
;
116 _cstruct FacilityIndicationParameter
;
117 _cstruct FacilityRequestParameter
;
118 __u16 FacilitySelector
;
123 _cstruct InfoElement
;
126 _cstruct Keypadfacility
;
134 _cstruct Useruserdata
;
141 /* buffer to construct message */
147 * capi_cmsg2message() assembles the parameter from _cmsg to a CAPI 2.0
150 unsigned capi_cmsg2message(_cmsg
* cmsg
, __u8
* msg
);
153 * capi_message2cmsg disassembles a CAPI message an writes the parameter
154 * into _cmsg for easy access
156 unsigned capi_message2cmsg(_cmsg
* cmsg
, __u8
* msg
);
159 * capi_cmsg_header() fills the _cmsg structure with default values, so only
160 * parameter with non default values must be changed before sending the
163 unsigned capi_cmsg_header(_cmsg
* cmsg
, __u16 _ApplId
,
164 __u8 _Command
, __u8 _Subcommand
,
165 __u16 _Messagenumber
, __u32 _Controller
);
167 /*-----------------------------------------------------------------------*/
170 * Debugging / Tracing functions
173 char *capi_cmd2str(__u8 cmd
, __u8 subcmd
);
182 #define CDEBUG_SIZE 1024
183 #define CDEBUG_GSIZE 4096
185 void cdebbuf_free(_cdebbuf
*cdb
);
186 int cdebug_init(void);
187 void cdebug_exit(void);
189 _cdebbuf
*capi_cmsg2str(_cmsg
*cmsg
);
190 _cdebbuf
*capi_message2str(__u8
*msg
);
192 /*-----------------------------------------------------------------------*/
194 static inline void capi_cmsg_answer(_cmsg
* cmsg
)
196 cmsg
->Subcommand
|= 0x01;
199 /*-----------------------------------------------------------------------*/
201 static inline void capi_fill_CONNECT_B3_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
205 capi_cmsg_header(cmsg
, ApplId
, 0x82, 0x80, Messagenumber
, adr
);
209 static inline void capi_fill_FACILITY_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
211 __u16 FacilitySelector
,
212 _cstruct FacilityRequestParameter
)
214 capi_cmsg_header(cmsg
, ApplId
, 0x80, 0x80, Messagenumber
, adr
);
215 cmsg
->FacilitySelector
= FacilitySelector
;
216 cmsg
->FacilityRequestParameter
= FacilityRequestParameter
;
219 static inline void capi_fill_INFO_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
221 _cstruct CalledPartyNumber
,
222 _cstruct BChannelinformation
,
223 _cstruct Keypadfacility
,
224 _cstruct Useruserdata
,
225 _cstruct Facilitydataarray
)
227 capi_cmsg_header(cmsg
, ApplId
, 0x08, 0x80, Messagenumber
, adr
);
228 cmsg
->CalledPartyNumber
= CalledPartyNumber
;
229 cmsg
->BChannelinformation
= BChannelinformation
;
230 cmsg
->Keypadfacility
= Keypadfacility
;
231 cmsg
->Useruserdata
= Useruserdata
;
232 cmsg
->Facilitydataarray
= Facilitydataarray
;
235 static inline void capi_fill_LISTEN_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
240 _cstruct CallingPartyNumber
,
241 _cstruct CallingPartySubaddress
)
243 capi_cmsg_header(cmsg
, ApplId
, 0x05, 0x80, Messagenumber
, adr
);
244 cmsg
->InfoMask
= InfoMask
;
245 cmsg
->CIPmask
= CIPmask
;
246 cmsg
->CIPmask2
= CIPmask2
;
247 cmsg
->CallingPartyNumber
= CallingPartyNumber
;
248 cmsg
->CallingPartySubaddress
= CallingPartySubaddress
;
251 static inline void capi_fill_ALERT_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
253 _cstruct BChannelinformation
,
254 _cstruct Keypadfacility
,
255 _cstruct Useruserdata
,
256 _cstruct Facilitydataarray
)
258 capi_cmsg_header(cmsg
, ApplId
, 0x01, 0x80, Messagenumber
, adr
);
259 cmsg
->BChannelinformation
= BChannelinformation
;
260 cmsg
->Keypadfacility
= Keypadfacility
;
261 cmsg
->Useruserdata
= Useruserdata
;
262 cmsg
->Facilitydataarray
= Facilitydataarray
;
265 static inline void capi_fill_CONNECT_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
268 _cstruct CalledPartyNumber
,
269 _cstruct CallingPartyNumber
,
270 _cstruct CalledPartySubaddress
,
271 _cstruct CallingPartySubaddress
,
275 _cstruct B1configuration
,
276 _cstruct B2configuration
,
277 _cstruct B3configuration
,
281 _cstruct BChannelinformation
,
282 _cstruct Keypadfacility
,
283 _cstruct Useruserdata
,
284 _cstruct Facilitydataarray
)
287 capi_cmsg_header(cmsg
, ApplId
, 0x02, 0x80, Messagenumber
, adr
);
288 cmsg
->CIPValue
= CIPValue
;
289 cmsg
->CalledPartyNumber
= CalledPartyNumber
;
290 cmsg
->CallingPartyNumber
= CallingPartyNumber
;
291 cmsg
->CalledPartySubaddress
= CalledPartySubaddress
;
292 cmsg
->CallingPartySubaddress
= CallingPartySubaddress
;
293 cmsg
->B1protocol
= B1protocol
;
294 cmsg
->B2protocol
= B2protocol
;
295 cmsg
->B3protocol
= B3protocol
;
296 cmsg
->B1configuration
= B1configuration
;
297 cmsg
->B2configuration
= B2configuration
;
298 cmsg
->B3configuration
= B3configuration
;
302 cmsg
->BChannelinformation
= BChannelinformation
;
303 cmsg
->Keypadfacility
= Keypadfacility
;
304 cmsg
->Useruserdata
= Useruserdata
;
305 cmsg
->Facilitydataarray
= Facilitydataarray
;
308 static inline void capi_fill_DATA_B3_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
316 capi_cmsg_header(cmsg
, ApplId
, 0x86, 0x80, Messagenumber
, adr
);
318 cmsg
->DataLength
= DataLength
;
319 cmsg
->DataHandle
= DataHandle
;
323 static inline void capi_fill_DISCONNECT_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
325 _cstruct BChannelinformation
,
326 _cstruct Keypadfacility
,
327 _cstruct Useruserdata
,
328 _cstruct Facilitydataarray
)
331 capi_cmsg_header(cmsg
, ApplId
, 0x04, 0x80, Messagenumber
, adr
);
332 cmsg
->BChannelinformation
= BChannelinformation
;
333 cmsg
->Keypadfacility
= Keypadfacility
;
334 cmsg
->Useruserdata
= Useruserdata
;
335 cmsg
->Facilitydataarray
= Facilitydataarray
;
338 static inline void capi_fill_DISCONNECT_B3_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
343 capi_cmsg_header(cmsg
, ApplId
, 0x84, 0x80, Messagenumber
, adr
);
347 static inline void capi_fill_MANUFACTURER_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
355 capi_cmsg_header(cmsg
, ApplId
, 0xff, 0x80, Messagenumber
, adr
);
356 cmsg
->ManuID
= ManuID
;
358 cmsg
->Function
= Function
;
359 cmsg
->ManuData
= ManuData
;
362 static inline void capi_fill_RESET_B3_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
367 capi_cmsg_header(cmsg
, ApplId
, 0x87, 0x80, Messagenumber
, adr
);
371 static inline void capi_fill_SELECT_B_PROTOCOL_REQ(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
376 _cstruct B1configuration
,
377 _cstruct B2configuration
,
378 _cstruct B3configuration
)
381 capi_cmsg_header(cmsg
, ApplId
, 0x41, 0x80, Messagenumber
, adr
);
382 cmsg
->B1protocol
= B1protocol
;
383 cmsg
->B2protocol
= B2protocol
;
384 cmsg
->B3protocol
= B3protocol
;
385 cmsg
->B1configuration
= B1configuration
;
386 cmsg
->B2configuration
= B2configuration
;
387 cmsg
->B3configuration
= B3configuration
;
390 static inline void capi_fill_CONNECT_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
396 _cstruct B1configuration
,
397 _cstruct B2configuration
,
398 _cstruct B3configuration
,
399 _cstruct ConnectedNumber
,
400 _cstruct ConnectedSubaddress
,
402 _cstruct BChannelinformation
,
403 _cstruct Keypadfacility
,
404 _cstruct Useruserdata
,
405 _cstruct Facilitydataarray
)
407 capi_cmsg_header(cmsg
, ApplId
, 0x02, 0x83, Messagenumber
, adr
);
408 cmsg
->Reject
= Reject
;
409 cmsg
->B1protocol
= B1protocol
;
410 cmsg
->B2protocol
= B2protocol
;
411 cmsg
->B3protocol
= B3protocol
;
412 cmsg
->B1configuration
= B1configuration
;
413 cmsg
->B2configuration
= B2configuration
;
414 cmsg
->B3configuration
= B3configuration
;
415 cmsg
->ConnectedNumber
= ConnectedNumber
;
416 cmsg
->ConnectedSubaddress
= ConnectedSubaddress
;
418 cmsg
->BChannelinformation
= BChannelinformation
;
419 cmsg
->Keypadfacility
= Keypadfacility
;
420 cmsg
->Useruserdata
= Useruserdata
;
421 cmsg
->Facilitydataarray
= Facilitydataarray
;
424 static inline void capi_fill_CONNECT_ACTIVE_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
428 capi_cmsg_header(cmsg
, ApplId
, 0x03, 0x83, Messagenumber
, adr
);
431 static inline void capi_fill_CONNECT_B3_ACTIVE_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
435 capi_cmsg_header(cmsg
, ApplId
, 0x83, 0x83, Messagenumber
, adr
);
438 static inline void capi_fill_CONNECT_B3_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
443 capi_cmsg_header(cmsg
, ApplId
, 0x82, 0x83, Messagenumber
, adr
);
444 cmsg
->Reject
= Reject
;
448 static inline void capi_fill_CONNECT_B3_T90_ACTIVE_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
452 capi_cmsg_header(cmsg
, ApplId
, 0x88, 0x83, Messagenumber
, adr
);
455 static inline void capi_fill_DATA_B3_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
460 capi_cmsg_header(cmsg
, ApplId
, 0x86, 0x83, Messagenumber
, adr
);
461 cmsg
->DataHandle
= DataHandle
;
464 static inline void capi_fill_DISCONNECT_B3_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
468 capi_cmsg_header(cmsg
, ApplId
, 0x84, 0x83, Messagenumber
, adr
);
471 static inline void capi_fill_DISCONNECT_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
475 capi_cmsg_header(cmsg
, ApplId
, 0x04, 0x83, Messagenumber
, adr
);
478 static inline void capi_fill_FACILITY_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
480 __u16 FacilitySelector
)
483 capi_cmsg_header(cmsg
, ApplId
, 0x80, 0x83, Messagenumber
, adr
);
484 cmsg
->FacilitySelector
= FacilitySelector
;
487 static inline void capi_fill_INFO_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
491 capi_cmsg_header(cmsg
, ApplId
, 0x08, 0x83, Messagenumber
, adr
);
494 static inline void capi_fill_MANUFACTURER_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
502 capi_cmsg_header(cmsg
, ApplId
, 0xff, 0x83, Messagenumber
, adr
);
503 cmsg
->ManuID
= ManuID
;
505 cmsg
->Function
= Function
;
506 cmsg
->ManuData
= ManuData
;
509 static inline void capi_fill_RESET_B3_RESP(_cmsg
* cmsg
, __u16 ApplId
, __u16 Messagenumber
,
513 capi_cmsg_header(cmsg
, ApplId
, 0x87, 0x83, Messagenumber
, adr
);
516 #endif /* __CAPIUTIL_H__ */