File: /usr/src/linux/drivers/isdn/avmb1/capiutil.h
1 /*
2 * $Id: capiutil.h,v 1.5.6.1 2001/05/17 20:41:51 kai Exp $
3 *
4 * CAPI 2.0 defines & types
5 *
6 * From CAPI 2.0 Development Kit AVM 1995 (capi20.h)
7 * Rewritten for Linux 1996 by Carsten Paeth (calle@calle.in-berlin.de)
8 *
9 */
10 #ifndef __CAPIUTIL_H__
11 #define __CAPIUTIL_H__
12
13 #include <asm/types.h>
14
15 #define CAPIMSG_BASELEN 8
16 #define CAPIMSG_U8(m, off) (m[off])
17 #define CAPIMSG_U16(m, off) (m[off]|(m[(off)+1]<<8))
18 #define CAPIMSG_U32(m, off) (m[off]|(m[(off)+1]<<8)|(m[(off)+2]<<16)|(m[(off)+3]<<24))
19 #define CAPIMSG_LEN(m) CAPIMSG_U16(m,0)
20 #define CAPIMSG_APPID(m) CAPIMSG_U16(m,2)
21 #define CAPIMSG_COMMAND(m) CAPIMSG_U8(m,4)
22 #define CAPIMSG_SUBCOMMAND(m) CAPIMSG_U8(m,5)
23 #define CAPIMSG_CMD(m) (((m[4])<<8)|(m[5]))
24 #define CAPIMSG_MSGID(m) CAPIMSG_U16(m,6)
25 #define CAPIMSG_CONTROLLER(m) (m[8] & 0x7f)
26 #define CAPIMSG_CONTROL(m) CAPIMSG_U32(m, 8)
27 #define CAPIMSG_NCCI(m) CAPIMSG_CONTROL(m)
28 #define CAPIMSG_DATALEN(m) CAPIMSG_U16(m,16) /* DATA_B3_REQ */
29
30 static inline void capimsg_setu8(void *m, int off, __u8 val)
31 {
32 ((__u8 *)m)[off] = val;
33 }
34
35 static inline void capimsg_setu16(void *m, int off, __u16 val)
36 {
37 ((__u8 *)m)[off] = val & 0xff;
38 ((__u8 *)m)[off+1] = (val >> 8) & 0xff;
39 }
40
41 static inline void capimsg_setu32(void *m, int off, __u32 val)
42 {
43 ((__u8 *)m)[off] = val & 0xff;
44 ((__u8 *)m)[off+1] = (val >> 8) & 0xff;
45 ((__u8 *)m)[off+2] = (val >> 16) & 0xff;
46 ((__u8 *)m)[off+3] = (val >> 24) & 0xff;
47 }
48
49 #define CAPIMSG_SETLEN(m, len) capimsg_setu16(m, 0, len)
50 #define CAPIMSG_SETAPPID(m, applid) capimsg_setu16(m, 2, applid)
51 #define CAPIMSG_SETCOMMAND(m,cmd) capimsg_setu8(m, 4, cmd)
52 #define CAPIMSG_SETSUBCOMMAND(m, cmd) capimsg_setu8(m, 5, cmd)
53 #define CAPIMSG_SETMSGID(m, msgid) capimsg_setu16(m, 6, msgid)
54 #define CAPIMSG_SETCONTROL(m, contr) capimsg_setu32(m, 8, contr)
55 #define CAPIMSG_SETDATALEN(m, len) capimsg_setu16(m, 16, len)
56
57 /*----- basic-type definitions -----*/
58
59 typedef __u8 *_cstruct;
60
61 typedef enum {
62 CAPI_COMPOSE,
63 CAPI_DEFAULT
64 } _cmstruct;
65
66 /*
67 The _cmsg structure contains all possible CAPI 2.0 parameter.
68 All parameters are stored here first. The function CAPI_CMSG_2_MESSAGE
69 assembles the parameter and builds CAPI2.0 conform messages.
70 CAPI_MESSAGE_2_CMSG disassembles CAPI 2.0 messages and stores the
71 parameter in the _cmsg structure
72 */
73
74 typedef struct {
75 /* Header */
76 __u16 ApplId;
77 __u8 Command;
78 __u8 Subcommand;
79 __u16 Messagenumber;
80
81 /* Parameter */
82 union {
83 __u32 adrController;
84 __u32 adrPLCI;
85 __u32 adrNCCI;
86 } adr;
87
88 _cmstruct AdditionalInfo;
89 _cstruct B1configuration;
90 __u16 B1protocol;
91 _cstruct B2configuration;
92 __u16 B2protocol;
93 _cstruct B3configuration;
94 __u16 B3protocol;
95 _cstruct BC;
96 _cstruct BChannelinformation;
97 _cmstruct BProtocol;
98 _cstruct CalledPartyNumber;
99 _cstruct CalledPartySubaddress;
100 _cstruct CallingPartyNumber;
101 _cstruct CallingPartySubaddress;
102 __u32 CIPmask;
103 __u32 CIPmask2;
104 __u16 CIPValue;
105 __u32 Class;
106 _cstruct ConnectedNumber;
107 _cstruct ConnectedSubaddress;
108 __u32 Data;
109 __u16 DataHandle;
110 __u16 DataLength;
111 _cstruct FacilityConfirmationParameter;
112 _cstruct Facilitydataarray;
113 _cstruct FacilityIndicationParameter;
114 _cstruct FacilityRequestParameter;
115 __u16 FacilitySelector;
116 __u16 Flags;
117 __u32 Function;
118 _cstruct HLC;
119 __u16 Info;
120 _cstruct InfoElement;
121 __u32 InfoMask;
122 __u16 InfoNumber;
123 _cstruct Keypadfacility;
124 _cstruct LLC;
125 _cstruct ManuData;
126 __u32 ManuID;
127 _cstruct NCPI;
128 __u16 Reason;
129 __u16 Reason_B3;
130 __u16 Reject;
131 _cstruct Useruserdata;
132
133 /* intern */
134 unsigned l, p;
135 unsigned char *par;
136 __u8 *m;
137
138 /* buffer to construct message */
139 __u8 buf[180];
140
141 } _cmsg;
142
143 /*
144 * capi_cmsg2message() assembles the parameter from _cmsg to a CAPI 2.0
145 * conform message
146 */
147 unsigned capi_cmsg2message(_cmsg * cmsg, __u8 * msg);
148
149 /*
150 * capi_message2cmsg disassembles a CAPI message an writes the parameter
151 * into _cmsg for easy access
152 */
153 unsigned capi_message2cmsg(_cmsg * cmsg, __u8 * msg);
154
155 /*
156 * capi_cmsg_header() fills the _cmsg structure with default values, so only
157 * parameter with non default values must be changed before sending the
158 * message.
159 */
160 unsigned capi_cmsg_header(_cmsg * cmsg, __u16 _ApplId,
161 __u8 _Command, __u8 _Subcommand,
162 __u16 _Messagenumber, __u32 _Controller);
163
164 /*
165 * capi_info2str generated a readable string for Capi2.0 reasons.
166 */
167 char *capi_info2str(__u16 reason);
168
169 /*-----------------------------------------------------------------------*/
170
171 /*
172 * Debugging / Tracing functions
173 */
174 char *capi_cmd2str(__u8 cmd, __u8 subcmd);
175 char *capi_cmsg2str(_cmsg * cmsg);
176 char *capi_message2str(__u8 * msg);
177
178 /*-----------------------------------------------------------------------*/
179
180 static inline void capi_cmsg_answer(_cmsg * cmsg)
181 {
182 cmsg->Subcommand |= 0x01;
183 }
184
185 /*-----------------------------------------------------------------------*/
186
187 static inline void capi_fill_CONNECT_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
188 __u32 adr,
189 _cstruct NCPI)
190 {
191 capi_cmsg_header(cmsg, ApplId, 0x82, 0x80, Messagenumber, adr);
192 cmsg->NCPI = NCPI;
193 }
194
195 static inline void capi_fill_FACILITY_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
196 __u32 adr,
197 __u16 FacilitySelector,
198 _cstruct FacilityRequestParameter)
199 {
200 capi_cmsg_header(cmsg, ApplId, 0x80, 0x80, Messagenumber, adr);
201 cmsg->FacilitySelector = FacilitySelector;
202 cmsg->FacilityRequestParameter = FacilityRequestParameter;
203 }
204
205 static inline void capi_fill_INFO_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
206 __u32 adr,
207 _cstruct CalledPartyNumber,
208 _cstruct BChannelinformation,
209 _cstruct Keypadfacility,
210 _cstruct Useruserdata,
211 _cstruct Facilitydataarray)
212 {
213 capi_cmsg_header(cmsg, ApplId, 0x08, 0x80, Messagenumber, adr);
214 cmsg->CalledPartyNumber = CalledPartyNumber;
215 cmsg->BChannelinformation = BChannelinformation;
216 cmsg->Keypadfacility = Keypadfacility;
217 cmsg->Useruserdata = Useruserdata;
218 cmsg->Facilitydataarray = Facilitydataarray;
219 }
220
221 static inline void capi_fill_LISTEN_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
222 __u32 adr,
223 __u32 InfoMask,
224 __u32 CIPmask,
225 __u32 CIPmask2,
226 _cstruct CallingPartyNumber,
227 _cstruct CallingPartySubaddress)
228 {
229 capi_cmsg_header(cmsg, ApplId, 0x05, 0x80, Messagenumber, adr);
230 cmsg->InfoMask = InfoMask;
231 cmsg->CIPmask = CIPmask;
232 cmsg->CIPmask2 = CIPmask2;
233 cmsg->CallingPartyNumber = CallingPartyNumber;
234 cmsg->CallingPartySubaddress = CallingPartySubaddress;
235 }
236
237 static inline void capi_fill_ALERT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
238 __u32 adr,
239 _cstruct BChannelinformation,
240 _cstruct Keypadfacility,
241 _cstruct Useruserdata,
242 _cstruct Facilitydataarray)
243 {
244 capi_cmsg_header(cmsg, ApplId, 0x01, 0x80, Messagenumber, adr);
245 cmsg->BChannelinformation = BChannelinformation;
246 cmsg->Keypadfacility = Keypadfacility;
247 cmsg->Useruserdata = Useruserdata;
248 cmsg->Facilitydataarray = Facilitydataarray;
249 }
250
251 static inline void capi_fill_CONNECT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
252 __u32 adr,
253 __u16 CIPValue,
254 _cstruct CalledPartyNumber,
255 _cstruct CallingPartyNumber,
256 _cstruct CalledPartySubaddress,
257 _cstruct CallingPartySubaddress,
258 __u16 B1protocol,
259 __u16 B2protocol,
260 __u16 B3protocol,
261 _cstruct B1configuration,
262 _cstruct B2configuration,
263 _cstruct B3configuration,
264 _cstruct BC,
265 _cstruct LLC,
266 _cstruct HLC,
267 _cstruct BChannelinformation,
268 _cstruct Keypadfacility,
269 _cstruct Useruserdata,
270 _cstruct Facilitydataarray)
271 {
272
273 capi_cmsg_header(cmsg, ApplId, 0x02, 0x80, Messagenumber, adr);
274 cmsg->CIPValue = CIPValue;
275 cmsg->CalledPartyNumber = CalledPartyNumber;
276 cmsg->CallingPartyNumber = CallingPartyNumber;
277 cmsg->CalledPartySubaddress = CalledPartySubaddress;
278 cmsg->CallingPartySubaddress = CallingPartySubaddress;
279 cmsg->B1protocol = B1protocol;
280 cmsg->B2protocol = B2protocol;
281 cmsg->B3protocol = B3protocol;
282 cmsg->B1configuration = B1configuration;
283 cmsg->B2configuration = B2configuration;
284 cmsg->B3configuration = B3configuration;
285 cmsg->BC = BC;
286 cmsg->LLC = LLC;
287 cmsg->HLC = HLC;
288 cmsg->BChannelinformation = BChannelinformation;
289 cmsg->Keypadfacility = Keypadfacility;
290 cmsg->Useruserdata = Useruserdata;
291 cmsg->Facilitydataarray = Facilitydataarray;
292 }
293
294 static inline void capi_fill_DATA_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
295 __u32 adr,
296 __u32 Data,
297 __u16 DataLength,
298 __u16 DataHandle,
299 __u16 Flags)
300 {
301
302 capi_cmsg_header(cmsg, ApplId, 0x86, 0x80, Messagenumber, adr);
303 cmsg->Data = Data;
304 cmsg->DataLength = DataLength;
305 cmsg->DataHandle = DataHandle;
306 cmsg->Flags = Flags;
307 }
308
309 static inline void capi_fill_DISCONNECT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
310 __u32 adr,
311 _cstruct BChannelinformation,
312 _cstruct Keypadfacility,
313 _cstruct Useruserdata,
314 _cstruct Facilitydataarray)
315 {
316
317 capi_cmsg_header(cmsg, ApplId, 0x04, 0x80, Messagenumber, adr);
318 cmsg->BChannelinformation = BChannelinformation;
319 cmsg->Keypadfacility = Keypadfacility;
320 cmsg->Useruserdata = Useruserdata;
321 cmsg->Facilitydataarray = Facilitydataarray;
322 }
323
324 static inline void capi_fill_DISCONNECT_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
325 __u32 adr,
326 _cstruct NCPI)
327 {
328
329 capi_cmsg_header(cmsg, ApplId, 0x84, 0x80, Messagenumber, adr);
330 cmsg->NCPI = NCPI;
331 }
332
333 static inline void capi_fill_MANUFACTURER_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
334 __u32 adr,
335 __u32 ManuID,
336 __u32 Class,
337 __u32 Function,
338 _cstruct ManuData)
339 {
340
341 capi_cmsg_header(cmsg, ApplId, 0xff, 0x80, Messagenumber, adr);
342 cmsg->ManuID = ManuID;
343 cmsg->Class = Class;
344 cmsg->Function = Function;
345 cmsg->ManuData = ManuData;
346 }
347
348 static inline void capi_fill_RESET_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
349 __u32 adr,
350 _cstruct NCPI)
351 {
352
353 capi_cmsg_header(cmsg, ApplId, 0x87, 0x80, Messagenumber, adr);
354 cmsg->NCPI = NCPI;
355 }
356
357 static inline void capi_fill_SELECT_B_PROTOCOL_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
358 __u32 adr,
359 __u16 B1protocol,
360 __u16 B2protocol,
361 __u16 B3protocol,
362 _cstruct B1configuration,
363 _cstruct B2configuration,
364 _cstruct B3configuration)
365 {
366
367 capi_cmsg_header(cmsg, ApplId, 0x41, 0x80, Messagenumber, adr);
368 cmsg->B1protocol = B1protocol;
369 cmsg->B2protocol = B2protocol;
370 cmsg->B3protocol = B3protocol;
371 cmsg->B1configuration = B1configuration;
372 cmsg->B2configuration = B2configuration;
373 cmsg->B3configuration = B3configuration;
374 }
375
376 static inline void capi_fill_CONNECT_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
377 __u32 adr,
378 __u16 Reject,
379 __u16 B1protocol,
380 __u16 B2protocol,
381 __u16 B3protocol,
382 _cstruct B1configuration,
383 _cstruct B2configuration,
384 _cstruct B3configuration,
385 _cstruct ConnectedNumber,
386 _cstruct ConnectedSubaddress,
387 _cstruct LLC,
388 _cstruct BChannelinformation,
389 _cstruct Keypadfacility,
390 _cstruct Useruserdata,
391 _cstruct Facilitydataarray)
392 {
393 capi_cmsg_header(cmsg, ApplId, 0x02, 0x83, Messagenumber, adr);
394 cmsg->Reject = Reject;
395 cmsg->B1protocol = B1protocol;
396 cmsg->B2protocol = B2protocol;
397 cmsg->B3protocol = B3protocol;
398 cmsg->B1configuration = B1configuration;
399 cmsg->B2configuration = B2configuration;
400 cmsg->B3configuration = B3configuration;
401 cmsg->ConnectedNumber = ConnectedNumber;
402 cmsg->ConnectedSubaddress = ConnectedSubaddress;
403 cmsg->LLC = LLC;
404 cmsg->BChannelinformation = BChannelinformation;
405 cmsg->Keypadfacility = Keypadfacility;
406 cmsg->Useruserdata = Useruserdata;
407 cmsg->Facilitydataarray = Facilitydataarray;
408 }
409
410 static inline void capi_fill_CONNECT_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
411 __u32 adr)
412 {
413
414 capi_cmsg_header(cmsg, ApplId, 0x03, 0x83, Messagenumber, adr);
415 }
416
417 static inline void capi_fill_CONNECT_B3_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
418 __u32 adr)
419 {
420
421 capi_cmsg_header(cmsg, ApplId, 0x83, 0x83, Messagenumber, adr);
422 }
423
424 static inline void capi_fill_CONNECT_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
425 __u32 adr,
426 __u16 Reject,
427 _cstruct NCPI)
428 {
429 capi_cmsg_header(cmsg, ApplId, 0x82, 0x83, Messagenumber, adr);
430 cmsg->Reject = Reject;
431 cmsg->NCPI = NCPI;
432 }
433
434 static inline void capi_fill_CONNECT_B3_T90_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
435 __u32 adr)
436 {
437
438 capi_cmsg_header(cmsg, ApplId, 0x88, 0x83, Messagenumber, adr);
439 }
440
441 static inline void capi_fill_DATA_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
442 __u32 adr,
443 __u16 DataHandle)
444 {
445
446 capi_cmsg_header(cmsg, ApplId, 0x86, 0x83, Messagenumber, adr);
447 cmsg->DataHandle = DataHandle;
448 }
449
450 static inline void capi_fill_DISCONNECT_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
451 __u32 adr)
452 {
453
454 capi_cmsg_header(cmsg, ApplId, 0x84, 0x83, Messagenumber, adr);
455 }
456
457 static inline void capi_fill_DISCONNECT_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
458 __u32 adr)
459 {
460
461 capi_cmsg_header(cmsg, ApplId, 0x04, 0x83, Messagenumber, adr);
462 }
463
464 static inline void capi_fill_FACILITY_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
465 __u32 adr,
466 __u16 FacilitySelector)
467 {
468
469 capi_cmsg_header(cmsg, ApplId, 0x80, 0x83, Messagenumber, adr);
470 cmsg->FacilitySelector = FacilitySelector;
471 }
472
473 static inline void capi_fill_INFO_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
474 __u32 adr)
475 {
476
477 capi_cmsg_header(cmsg, ApplId, 0x08, 0x83, Messagenumber, adr);
478 }
479
480 static inline void capi_fill_MANUFACTURER_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
481 __u32 adr,
482 __u32 ManuID,
483 __u32 Class,
484 __u32 Function,
485 _cstruct ManuData)
486 {
487
488 capi_cmsg_header(cmsg, ApplId, 0xff, 0x83, Messagenumber, adr);
489 cmsg->ManuID = ManuID;
490 cmsg->Class = Class;
491 cmsg->Function = Function;
492 cmsg->ManuData = ManuData;
493 }
494
495 static inline void capi_fill_RESET_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
496 __u32 adr)
497 {
498
499 capi_cmsg_header(cmsg, ApplId, 0x87, 0x83, Messagenumber, adr);
500 }
501
502 #endif /* __CAPIUTIL_H__ */
503