Linux v2.6.15-rc6
[pohmelfs.git] / include / linux / isdn / capiutil.h
blob2e79f816703be86b918b4797e74bde58ea9da63b
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;
64 typedef enum {
65 CAPI_COMPOSE,
66 CAPI_DEFAULT
67 } _cmstruct;
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
77 typedef struct {
78 /* Header */
79 __u16 ApplId;
80 __u8 Command;
81 __u8 Subcommand;
82 __u16 Messagenumber;
84 /* Parameter */
85 union {
86 __u32 adrController;
87 __u32 adrPLCI;
88 __u32 adrNCCI;
89 } adr;
91 _cmstruct AdditionalInfo;
92 _cstruct B1configuration;
93 __u16 B1protocol;
94 _cstruct B2configuration;
95 __u16 B2protocol;
96 _cstruct B3configuration;
97 __u16 B3protocol;
98 _cstruct BC;
99 _cstruct BChannelinformation;
100 _cmstruct BProtocol;
101 _cstruct CalledPartyNumber;
102 _cstruct CalledPartySubaddress;
103 _cstruct CallingPartyNumber;
104 _cstruct CallingPartySubaddress;
105 __u32 CIPmask;
106 __u32 CIPmask2;
107 __u16 CIPValue;
108 __u32 Class;
109 _cstruct ConnectedNumber;
110 _cstruct ConnectedSubaddress;
111 __u32 Data;
112 __u16 DataHandle;
113 __u16 DataLength;
114 _cstruct FacilityConfirmationParameter;
115 _cstruct Facilitydataarray;
116 _cstruct FacilityIndicationParameter;
117 _cstruct FacilityRequestParameter;
118 __u16 FacilitySelector;
119 __u16 Flags;
120 __u32 Function;
121 _cstruct HLC;
122 __u16 Info;
123 _cstruct InfoElement;
124 __u32 InfoMask;
125 __u16 InfoNumber;
126 _cstruct Keypadfacility;
127 _cstruct LLC;
128 _cstruct ManuData;
129 __u32 ManuID;
130 _cstruct NCPI;
131 __u16 Reason;
132 __u16 Reason_B3;
133 __u16 Reject;
134 _cstruct Useruserdata;
136 /* intern */
137 unsigned l, p;
138 unsigned char *par;
139 __u8 *m;
141 /* buffer to construct message */
142 __u8 buf[180];
144 } _cmsg;
147 * capi_cmsg2message() assembles the parameter from _cmsg to a CAPI 2.0
148 * conform message
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
161 * message.
163 unsigned capi_cmsg_header(_cmsg * cmsg, __u16 _ApplId,
164 __u8 _Command, __u8 _Subcommand,
165 __u16 _Messagenumber, __u32 _Controller);
168 * capi_info2str generated a readable string for Capi2.0 reasons.
170 char *capi_info2str(__u16 reason);
172 /*-----------------------------------------------------------------------*/
175 * Debugging / Tracing functions
177 char *capi_cmd2str(__u8 cmd, __u8 subcmd);
178 char *capi_cmsg2str(_cmsg * cmsg);
179 char *capi_message2str(__u8 * msg);
181 /*-----------------------------------------------------------------------*/
183 static inline void capi_cmsg_answer(_cmsg * cmsg)
185 cmsg->Subcommand |= 0x01;
188 /*-----------------------------------------------------------------------*/
190 static inline void capi_fill_CONNECT_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
191 __u32 adr,
192 _cstruct NCPI)
194 capi_cmsg_header(cmsg, ApplId, 0x82, 0x80, Messagenumber, adr);
195 cmsg->NCPI = NCPI;
198 static inline void capi_fill_FACILITY_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
199 __u32 adr,
200 __u16 FacilitySelector,
201 _cstruct FacilityRequestParameter)
203 capi_cmsg_header(cmsg, ApplId, 0x80, 0x80, Messagenumber, adr);
204 cmsg->FacilitySelector = FacilitySelector;
205 cmsg->FacilityRequestParameter = FacilityRequestParameter;
208 static inline void capi_fill_INFO_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
209 __u32 adr,
210 _cstruct CalledPartyNumber,
211 _cstruct BChannelinformation,
212 _cstruct Keypadfacility,
213 _cstruct Useruserdata,
214 _cstruct Facilitydataarray)
216 capi_cmsg_header(cmsg, ApplId, 0x08, 0x80, Messagenumber, adr);
217 cmsg->CalledPartyNumber = CalledPartyNumber;
218 cmsg->BChannelinformation = BChannelinformation;
219 cmsg->Keypadfacility = Keypadfacility;
220 cmsg->Useruserdata = Useruserdata;
221 cmsg->Facilitydataarray = Facilitydataarray;
224 static inline void capi_fill_LISTEN_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
225 __u32 adr,
226 __u32 InfoMask,
227 __u32 CIPmask,
228 __u32 CIPmask2,
229 _cstruct CallingPartyNumber,
230 _cstruct CallingPartySubaddress)
232 capi_cmsg_header(cmsg, ApplId, 0x05, 0x80, Messagenumber, adr);
233 cmsg->InfoMask = InfoMask;
234 cmsg->CIPmask = CIPmask;
235 cmsg->CIPmask2 = CIPmask2;
236 cmsg->CallingPartyNumber = CallingPartyNumber;
237 cmsg->CallingPartySubaddress = CallingPartySubaddress;
240 static inline void capi_fill_ALERT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
241 __u32 adr,
242 _cstruct BChannelinformation,
243 _cstruct Keypadfacility,
244 _cstruct Useruserdata,
245 _cstruct Facilitydataarray)
247 capi_cmsg_header(cmsg, ApplId, 0x01, 0x80, Messagenumber, adr);
248 cmsg->BChannelinformation = BChannelinformation;
249 cmsg->Keypadfacility = Keypadfacility;
250 cmsg->Useruserdata = Useruserdata;
251 cmsg->Facilitydataarray = Facilitydataarray;
254 static inline void capi_fill_CONNECT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
255 __u32 adr,
256 __u16 CIPValue,
257 _cstruct CalledPartyNumber,
258 _cstruct CallingPartyNumber,
259 _cstruct CalledPartySubaddress,
260 _cstruct CallingPartySubaddress,
261 __u16 B1protocol,
262 __u16 B2protocol,
263 __u16 B3protocol,
264 _cstruct B1configuration,
265 _cstruct B2configuration,
266 _cstruct B3configuration,
267 _cstruct BC,
268 _cstruct LLC,
269 _cstruct HLC,
270 _cstruct BChannelinformation,
271 _cstruct Keypadfacility,
272 _cstruct Useruserdata,
273 _cstruct Facilitydataarray)
276 capi_cmsg_header(cmsg, ApplId, 0x02, 0x80, Messagenumber, adr);
277 cmsg->CIPValue = CIPValue;
278 cmsg->CalledPartyNumber = CalledPartyNumber;
279 cmsg->CallingPartyNumber = CallingPartyNumber;
280 cmsg->CalledPartySubaddress = CalledPartySubaddress;
281 cmsg->CallingPartySubaddress = CallingPartySubaddress;
282 cmsg->B1protocol = B1protocol;
283 cmsg->B2protocol = B2protocol;
284 cmsg->B3protocol = B3protocol;
285 cmsg->B1configuration = B1configuration;
286 cmsg->B2configuration = B2configuration;
287 cmsg->B3configuration = B3configuration;
288 cmsg->BC = BC;
289 cmsg->LLC = LLC;
290 cmsg->HLC = HLC;
291 cmsg->BChannelinformation = BChannelinformation;
292 cmsg->Keypadfacility = Keypadfacility;
293 cmsg->Useruserdata = Useruserdata;
294 cmsg->Facilitydataarray = Facilitydataarray;
297 static inline void capi_fill_DATA_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
298 __u32 adr,
299 __u32 Data,
300 __u16 DataLength,
301 __u16 DataHandle,
302 __u16 Flags)
305 capi_cmsg_header(cmsg, ApplId, 0x86, 0x80, Messagenumber, adr);
306 cmsg->Data = Data;
307 cmsg->DataLength = DataLength;
308 cmsg->DataHandle = DataHandle;
309 cmsg->Flags = Flags;
312 static inline void capi_fill_DISCONNECT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
313 __u32 adr,
314 _cstruct BChannelinformation,
315 _cstruct Keypadfacility,
316 _cstruct Useruserdata,
317 _cstruct Facilitydataarray)
320 capi_cmsg_header(cmsg, ApplId, 0x04, 0x80, Messagenumber, adr);
321 cmsg->BChannelinformation = BChannelinformation;
322 cmsg->Keypadfacility = Keypadfacility;
323 cmsg->Useruserdata = Useruserdata;
324 cmsg->Facilitydataarray = Facilitydataarray;
327 static inline void capi_fill_DISCONNECT_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
328 __u32 adr,
329 _cstruct NCPI)
332 capi_cmsg_header(cmsg, ApplId, 0x84, 0x80, Messagenumber, adr);
333 cmsg->NCPI = NCPI;
336 static inline void capi_fill_MANUFACTURER_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
337 __u32 adr,
338 __u32 ManuID,
339 __u32 Class,
340 __u32 Function,
341 _cstruct ManuData)
344 capi_cmsg_header(cmsg, ApplId, 0xff, 0x80, Messagenumber, adr);
345 cmsg->ManuID = ManuID;
346 cmsg->Class = Class;
347 cmsg->Function = Function;
348 cmsg->ManuData = ManuData;
351 static inline void capi_fill_RESET_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
352 __u32 adr,
353 _cstruct NCPI)
356 capi_cmsg_header(cmsg, ApplId, 0x87, 0x80, Messagenumber, adr);
357 cmsg->NCPI = NCPI;
360 static inline void capi_fill_SELECT_B_PROTOCOL_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
361 __u32 adr,
362 __u16 B1protocol,
363 __u16 B2protocol,
364 __u16 B3protocol,
365 _cstruct B1configuration,
366 _cstruct B2configuration,
367 _cstruct B3configuration)
370 capi_cmsg_header(cmsg, ApplId, 0x41, 0x80, Messagenumber, adr);
371 cmsg->B1protocol = B1protocol;
372 cmsg->B2protocol = B2protocol;
373 cmsg->B3protocol = B3protocol;
374 cmsg->B1configuration = B1configuration;
375 cmsg->B2configuration = B2configuration;
376 cmsg->B3configuration = B3configuration;
379 static inline void capi_fill_CONNECT_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
380 __u32 adr,
381 __u16 Reject,
382 __u16 B1protocol,
383 __u16 B2protocol,
384 __u16 B3protocol,
385 _cstruct B1configuration,
386 _cstruct B2configuration,
387 _cstruct B3configuration,
388 _cstruct ConnectedNumber,
389 _cstruct ConnectedSubaddress,
390 _cstruct LLC,
391 _cstruct BChannelinformation,
392 _cstruct Keypadfacility,
393 _cstruct Useruserdata,
394 _cstruct Facilitydataarray)
396 capi_cmsg_header(cmsg, ApplId, 0x02, 0x83, Messagenumber, adr);
397 cmsg->Reject = Reject;
398 cmsg->B1protocol = B1protocol;
399 cmsg->B2protocol = B2protocol;
400 cmsg->B3protocol = B3protocol;
401 cmsg->B1configuration = B1configuration;
402 cmsg->B2configuration = B2configuration;
403 cmsg->B3configuration = B3configuration;
404 cmsg->ConnectedNumber = ConnectedNumber;
405 cmsg->ConnectedSubaddress = ConnectedSubaddress;
406 cmsg->LLC = LLC;
407 cmsg->BChannelinformation = BChannelinformation;
408 cmsg->Keypadfacility = Keypadfacility;
409 cmsg->Useruserdata = Useruserdata;
410 cmsg->Facilitydataarray = Facilitydataarray;
413 static inline void capi_fill_CONNECT_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
414 __u32 adr)
417 capi_cmsg_header(cmsg, ApplId, 0x03, 0x83, Messagenumber, adr);
420 static inline void capi_fill_CONNECT_B3_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
421 __u32 adr)
424 capi_cmsg_header(cmsg, ApplId, 0x83, 0x83, Messagenumber, adr);
427 static inline void capi_fill_CONNECT_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
428 __u32 adr,
429 __u16 Reject,
430 _cstruct NCPI)
432 capi_cmsg_header(cmsg, ApplId, 0x82, 0x83, Messagenumber, adr);
433 cmsg->Reject = Reject;
434 cmsg->NCPI = NCPI;
437 static inline void capi_fill_CONNECT_B3_T90_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
438 __u32 adr)
441 capi_cmsg_header(cmsg, ApplId, 0x88, 0x83, Messagenumber, adr);
444 static inline void capi_fill_DATA_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
445 __u32 adr,
446 __u16 DataHandle)
449 capi_cmsg_header(cmsg, ApplId, 0x86, 0x83, Messagenumber, adr);
450 cmsg->DataHandle = DataHandle;
453 static inline void capi_fill_DISCONNECT_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
454 __u32 adr)
457 capi_cmsg_header(cmsg, ApplId, 0x84, 0x83, Messagenumber, adr);
460 static inline void capi_fill_DISCONNECT_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
461 __u32 adr)
464 capi_cmsg_header(cmsg, ApplId, 0x04, 0x83, Messagenumber, adr);
467 static inline void capi_fill_FACILITY_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
468 __u32 adr,
469 __u16 FacilitySelector)
472 capi_cmsg_header(cmsg, ApplId, 0x80, 0x83, Messagenumber, adr);
473 cmsg->FacilitySelector = FacilitySelector;
476 static inline void capi_fill_INFO_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
477 __u32 adr)
480 capi_cmsg_header(cmsg, ApplId, 0x08, 0x83, Messagenumber, adr);
483 static inline void capi_fill_MANUFACTURER_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
484 __u32 adr,
485 __u32 ManuID,
486 __u32 Class,
487 __u32 Function,
488 _cstruct ManuData)
491 capi_cmsg_header(cmsg, ApplId, 0xff, 0x83, Messagenumber, adr);
492 cmsg->ManuID = ManuID;
493 cmsg->Class = Class;
494 cmsg->Function = Function;
495 cmsg->ManuData = ManuData;
498 static inline void capi_fill_RESET_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
499 __u32 adr)
502 capi_cmsg_header(cmsg, ApplId, 0x87, 0x83, Messagenumber, adr);
505 #endif /* __CAPIUTIL_H__ */