2 * $Id: capiutil.c,v 1.13.6.1 2001/02/13 11:43:29 kai Exp $
4 * CAPI 2.0 convert capi message to capi message struct
6 * From CAPI 2.0 Development Kit AVM 1995 (msg.c)
7 * Rewritten for Linux 1996 by Carsten Paeth (calle@calle.in-berlin.de)
10 * Revision 1.13.6.1 2001/02/13 11:43:29 kai
11 * more compatility changes for 2.2.19
13 * Revision 1.13 2000/11/23 20:45:14 kai
14 * fixed module_init/exit stuff
15 * Note: compiled-in kernel doesn't work pre 2.2.18 anymore.
17 * Revision 1.12 2000/11/01 14:05:02 calle
18 * - use module_init/module_exit from linux/init.h.
19 * - all static struct variables are initialized with "membername:" now.
20 * - avm_cs.c, let it work with newer pcmcia-cs.
22 * Revision 1.11 2000/03/03 15:50:42 calle
24 * - Changed parameter "param" in capi_signal from __u32 to void *.
25 * - rewrote notifier handling in kcapi.c
26 * - new notifier NCCI_UP and NCCI_DOWN
28 * - /dev/capi20 is now a cloning device.
29 * - middleware extentions prepared.
31 * - locking of list operations and module count updates.
33 * Revision 1.10 1999/08/31 11:19:54 paul
34 * various spelling corrections (new checksums may be needed, Karsten!)
36 * Revision 1.9 1999/07/09 15:05:46 keil
37 * compat.h is now isdn_compat.h
39 * Revision 1.8 1999/07/01 15:26:37 calle
40 * complete new version (I love it):
41 * + new hardware independed "capi_driver" interface that will make it easy to:
42 * - support other controllers with CAPI-2.0 (i.e. USB Controller)
43 * - write a CAPI-2.0 for the passive cards
44 * - support serial link CAPI-2.0 boxes.
45 * + wrote "capi_driver" for all supported cards.
46 * + "capi_driver" (supported cards) now have to be configured with
47 * make menuconfig, in the past all supported cards where included
49 * + new and better informations in /proc/capi/
50 * + new ioctl to switch trace of capi messages per controller
51 * using "avmcapictrl trace [contr] on|off|...."
52 * + complete testcircle with all supported cards and also the
53 * PCMCIA cards (now patch for pcmcia-cs-3.0.13 needed) done.
55 * Revision 1.7 1999/07/01 08:23:01 keil
56 * compatibility macros now in <linux/isdn_compat.h>
58 * Revision 1.6 1997/11/04 06:12:12 calle
59 * capi.c: new read/write in file_ops since 2.1.60
60 * capidrv.c: prepared isdnlog interface for d2-trace in newer firmware.
61 * capiutil.c: needs config.h (CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON)
62 * compat.h: added #define LinuxVersionCode
64 * Revision 1.5 1997/10/01 09:21:19 fritz
65 * Removed old compatibility stuff for 2.0.X kernels.
66 * From now on, this code is for 2.1.X ONLY!
67 * Old stuff is still in the separate branch.
69 * Revision 1.4 1997/08/10 07:43:55 calle
70 * forgot to export symbol capi_info2str for 2.1.x
72 * Revision 1.3 1997/05/18 09:24:18 calle
73 * added verbose disconnect reason reporting to avmb1.
74 * some fixes in capi20 interface.
75 * changed info messages for B1-PCI
77 * Revision 1.2 1997/03/05 21:22:13 fritz
78 * Fix: Symbols have to be exported unconditionally.
80 * Revision 1.1 1997/03/04 21:50:34 calle
81 * Frirst version in isdn4linux
83 * Revision 2.2 1997/02/12 09:31:39 calle
86 * Revision 1.1 1997/01/31 10:32:20 calle
90 #include <linux/module.h>
91 #include <linux/string.h>
92 #include <linux/ctype.h>
93 #include <linux/stddef.h>
94 #include <linux/kernel.h>
96 #include <linux/init.h>
97 #include <asm/segment.h>
98 #include <linux/config.h>
100 #include "capiutil.h"
102 /* from CAPI2.0 DDK AVM Berlin GmbH */
104 #ifndef CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON
105 char *capi_info2str(__u16 reason)
110 char *capi_info2str(__u16 reason)
114 /*-- informative values (corresponding message was processed) -----*/
116 return "NCPI not supported by current protocol, NCPI ignored";
118 return "Flags not supported by current protocol, flags ignored";
120 return "Alert already sent by another application";
122 /*-- error information concerning CAPI_REGISTER -----*/
124 return "Too many applications";
126 return "Logical block size too small, must be at least 128 Bytes";
128 return "Buffer exceeds 64 kByte";
130 return "Message buffer size too small, must be at least 1024 Bytes";
132 return "Max. number of logical connections not supported";
136 return "The message could not be accepted because of an internal busy condition";
138 return "OS resource error (no memory ?)";
140 return "CAPI not installed";
142 return "Controller does not support external equipment";
144 return "Controller does only support external equipment";
146 /*-- error information concerning message exchange functions -----*/
148 return "Illegal application number";
150 return "Illegal command or subcommand or message length less than 12 bytes";
152 return "The message could not be accepted because of a queue full condition !! The error code does not imply that CAPI cannot receive messages directed to another controller, PLCI or NCCI";
154 return "Queue is empty";
156 return "Queue overflow, a message was lost !! This indicates a configuration error. The only recovery from this error is to perform a CAPI_RELEASE";
158 return "Unknown notification parameter";
160 return "The Message could not be accepted because of an internal busy condition";
162 return "OS Resource error (no memory ?)";
164 return "CAPI not installed";
166 return "Controller does not support external equipment";
168 return "Controller does only support external equipment";
170 /*-- error information concerning resource / coding problems -----*/
172 return "Message not supported in current state";
174 return "Illegal Controller / PLCI / NCCI";
176 return "Out of PLCI";
178 return "Out of NCCI";
180 return "Out of LISTEN";
182 return "Out of FAX resources (protocol T.30)";
184 return "Illegal message parameter coding";
186 /*-- error information concerning requested services -----*/
188 return "B1 protocol not supported";
190 return "B2 protocol not supported";
192 return "B3 protocol not supported";
194 return "B1 protocol parameter not supported";
196 return "B2 protocol parameter not supported";
198 return "B3 protocol parameter not supported";
200 return "B protocol combination not supported";
202 return "NCPI not supported";
204 return "CIP Value unknown";
206 return "Flags not supported (reserved bits)";
208 return "Facility not supported";
210 return "Data length not supported by current protocol";
212 return "Reset procedure not supported by current protocol";
214 /*-- informations about the clearing of a physical connection -----*/
216 return "Protocol error layer 1 (broken line or B-channel removed by signalling protocol)";
218 return "Protocol error layer 2";
220 return "Protocol error layer 3";
222 return "Another application got that call";
223 /*-- T.30 specific reasons -----*/
225 return "Connecting not successful (remote station is no FAX G3 machine)";
227 return "Connecting not successful (training error)";
229 return "Disconnected before transfer (remote station does not support transfer mode, e.g. resolution)";
231 return "Disconnected during transfer (remote abort)";
233 return "Disconnected during transfer (remote procedure error, e.g. unsuccessful repetition of T.30 commands)";
235 return "Disconnected during transfer (local tx data underrun)";
237 return "Disconnected during transfer (local rx data overflow)";
239 return "Disconnected during transfer (local abort)";
241 return "Illegal parameter coding (e.g. SFF coding error)";
243 /*-- disconnect causes from the network according to ETS 300 102-1/Q.931 -----*/
244 case 0x3481: return "Unallocated (unassigned) number";
245 case 0x3482: return "No route to specified transit network";
246 case 0x3483: return "No route to destination";
247 case 0x3486: return "Channel unacceptable";
249 return "Call awarded and being delivered in an established channel";
250 case 0x3490: return "Normal call clearing";
251 case 0x3491: return "User busy";
252 case 0x3492: return "No user responding";
253 case 0x3493: return "No answer from user (user alerted)";
254 case 0x3495: return "Call rejected";
255 case 0x3496: return "Number changed";
256 case 0x349A: return "Non-selected user clearing";
257 case 0x349B: return "Destination out of order";
258 case 0x349C: return "Invalid number format";
259 case 0x349D: return "Facility rejected";
260 case 0x349E: return "Response to STATUS ENQUIRY";
261 case 0x349F: return "Normal, unspecified";
262 case 0x34A2: return "No circuit / channel available";
263 case 0x34A6: return "Network out of order";
264 case 0x34A9: return "Temporary failure";
265 case 0x34AA: return "Switching equipment congestion";
266 case 0x34AB: return "Access information discarded";
267 case 0x34AC: return "Requested circuit / channel not available";
268 case 0x34AF: return "Resources unavailable, unspecified";
269 case 0x34B1: return "Quality of service unavailable";
270 case 0x34B2: return "Requested facility not subscribed";
271 case 0x34B9: return "Bearer capability not authorized";
272 case 0x34BA: return "Bearer capability not presently available";
273 case 0x34BF: return "Service or option not available, unspecified";
274 case 0x34C1: return "Bearer capability not implemented";
275 case 0x34C2: return "Channel type not implemented";
276 case 0x34C5: return "Requested facility not implemented";
277 case 0x34C6: return "Only restricted digital information bearer capability is available";
278 case 0x34CF: return "Service or option not implemented, unspecified";
279 case 0x34D1: return "Invalid call reference value";
280 case 0x34D2: return "Identified channel does not exist";
281 case 0x34D3: return "A suspended call exists, but this call identity does not";
282 case 0x34D4: return "Call identity in use";
283 case 0x34D5: return "No call suspended";
284 case 0x34D6: return "Call having the requested call identity has been cleared";
285 case 0x34D8: return "Incompatible destination";
286 case 0x34DB: return "Invalid transit network selection";
287 case 0x34DF: return "Invalid message, unspecified";
288 case 0x34E0: return "Mandatory information element is missing";
289 case 0x34E1: return "Message type non-existent or not implemented";
290 case 0x34E2: return "Message not compatible with call state or message type non-existent or not implemented";
291 case 0x34E3: return "Information element non-existent or not implemented";
292 case 0x34E4: return "Invalid information element contents";
293 case 0x34E5: return "Message not compatible with call state";
294 case 0x34E6: return "Recovery on timer expiry";
295 case 0x34EF: return "Protocol error, unspecified";
296 case 0x34FF: return "Interworking, unspecified";
298 default: return "No additional information";
315 static _cdef cdef[] =
324 {_CDWORD, offsetof(_cmsg, adr.adrController)},
326 {_CMSTRUCT, offsetof(_cmsg, AdditionalInfo)},
328 {_CSTRUCT, offsetof(_cmsg, B1configuration)},
330 {_CWORD, offsetof(_cmsg, B1protocol)},
332 {_CSTRUCT, offsetof(_cmsg, B2configuration)},
334 {_CWORD, offsetof(_cmsg, B2protocol)},
336 {_CSTRUCT, offsetof(_cmsg, B3configuration)},
338 {_CWORD, offsetof(_cmsg, B3protocol)},
340 {_CSTRUCT, offsetof(_cmsg, BC)},
342 {_CSTRUCT, offsetof(_cmsg, BChannelinformation)},
344 {_CMSTRUCT, offsetof(_cmsg, BProtocol)},
346 {_CSTRUCT, offsetof(_cmsg, CalledPartyNumber)},
348 {_CSTRUCT, offsetof(_cmsg, CalledPartySubaddress)},
350 {_CSTRUCT, offsetof(_cmsg, CallingPartyNumber)},
352 {_CSTRUCT, offsetof(_cmsg, CallingPartySubaddress)},
354 {_CDWORD, offsetof(_cmsg, CIPmask)},
356 {_CDWORD, offsetof(_cmsg, CIPmask2)},
358 {_CWORD, offsetof(_cmsg, CIPValue)},
360 {_CDWORD, offsetof(_cmsg, Class)},
362 {_CSTRUCT, offsetof(_cmsg, ConnectedNumber)},
364 {_CSTRUCT, offsetof(_cmsg, ConnectedSubaddress)},
366 {_CDWORD, offsetof(_cmsg, Data)},
368 {_CWORD, offsetof(_cmsg, DataHandle)},
370 {_CWORD, offsetof(_cmsg, DataLength)},
372 {_CSTRUCT, offsetof(_cmsg, FacilityConfirmationParameter)},
374 {_CSTRUCT, offsetof(_cmsg, Facilitydataarray)},
376 {_CSTRUCT, offsetof(_cmsg, FacilityIndicationParameter)},
378 {_CSTRUCT, offsetof(_cmsg, FacilityRequestParameter)},
380 {_CWORD, offsetof(_cmsg, FacilitySelector)},
382 {_CWORD, offsetof(_cmsg, Flags)},
384 {_CDWORD, offsetof(_cmsg, Function)},
386 {_CSTRUCT, offsetof(_cmsg, HLC)},
388 {_CWORD, offsetof(_cmsg, Info)},
390 {_CSTRUCT, offsetof(_cmsg, InfoElement)},
392 {_CDWORD, offsetof(_cmsg, InfoMask)},
394 {_CWORD, offsetof(_cmsg, InfoNumber)},
396 {_CSTRUCT, offsetof(_cmsg, Keypadfacility)},
398 {_CSTRUCT, offsetof(_cmsg, LLC)},
400 {_CSTRUCT, offsetof(_cmsg, ManuData)},
402 {_CDWORD, offsetof(_cmsg, ManuID)},
404 {_CSTRUCT, offsetof(_cmsg, NCPI)},
406 {_CWORD, offsetof(_cmsg, Reason)},
408 {_CWORD, offsetof(_cmsg, Reason_B3)},
410 {_CWORD, offsetof(_cmsg, Reject)},
412 {_CSTRUCT, offsetof(_cmsg, Useruserdata)}
415 static unsigned char *cpars[] =
418 /*01 ALERT_REQ */ (unsigned char *) "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
419 /*02 CONNECT_REQ */ (unsigned char *) "\x03\x14\x0e\x10\x0f\x11\x0d\x06\x08\x0a\x05\x07\x09\x01\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
421 /*04 DISCONNECT_REQ */ (unsigned char *) "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
422 /*05 LISTEN_REQ */ (unsigned char *) "\x03\x25\x12\x13\x10\x11\x01",
425 /*08 INFO_REQ */ (unsigned char *) "\x03\x0e\x04\x0c\x27\x2f\x1c\x01\x01",
426 /*09 FACILITY_REQ */ (unsigned char *) "\x03\x1f\x1e\x01",
427 /*0a SELECT_B_PROTOCOL_REQ */ (unsigned char *) "\x03\x0d\x06\x08\x0a\x05\x07\x09\x01\x01",
428 /*0b CONNECT_B3_REQ */ (unsigned char *) "\x03\x2b\x01",
430 /*0d DISCONNECT_B3_REQ */ (unsigned char *) "\x03\x2b\x01",
432 /*0f DATA_B3_REQ */ (unsigned char *) "\x03\x18\x1a\x19\x20\x01",
433 /*10 RESET_B3_REQ */ (unsigned char *) "\x03\x2b\x01",
436 /*13 ALERT_CONF */ (unsigned char *) "\x03\x23\x01",
437 /*14 CONNECT_CONF */ (unsigned char *) "\x03\x23\x01",
439 /*16 DISCONNECT_CONF */ (unsigned char *) "\x03\x23\x01",
440 /*17 LISTEN_CONF */ (unsigned char *) "\x03\x23\x01",
441 /*18 MANUFACTURER_REQ */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
443 /*1a INFO_CONF */ (unsigned char *) "\x03\x23\x01",
444 /*1b FACILITY_CONF */ (unsigned char *) "\x03\x23\x1f\x1b\x01",
445 /*1c SELECT_B_PROTOCOL_CONF */ (unsigned char *) "\x03\x23\x01",
446 /*1d CONNECT_B3_CONF */ (unsigned char *) "\x03\x23\x01",
448 /*1f DISCONNECT_B3_CONF */ (unsigned char *) "\x03\x23\x01",
450 /*21 DATA_B3_CONF */ (unsigned char *) "\x03\x19\x23\x01",
451 /*22 RESET_B3_CONF */ (unsigned char *) "\x03\x23\x01",
455 /*26 CONNECT_IND */ (unsigned char *) "\x03\x14\x0e\x10\x0f\x11\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
456 /*27 CONNECT_ACTIVE_IND */ (unsigned char *) "\x03\x16\x17\x28\x01",
457 /*28 DISCONNECT_IND */ (unsigned char *) "\x03\x2c\x01",
459 /*2a MANUFACTURER_CONF */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
461 /*2c INFO_IND */ (unsigned char *) "\x03\x26\x24\x01",
462 /*2d FACILITY_IND */ (unsigned char *) "\x03\x1f\x1d\x01",
464 /*2f CONNECT_B3_IND */ (unsigned char *) "\x03\x2b\x01",
465 /*30 CONNECT_B3_ACTIVE_IND */ (unsigned char *) "\x03\x2b\x01",
466 /*31 DISCONNECT_B3_IND */ (unsigned char *) "\x03\x2d\x2b\x01",
468 /*33 DATA_B3_IND */ (unsigned char *) "\x03\x18\x1a\x19\x20\x01",
469 /*34 RESET_B3_IND */ (unsigned char *) "\x03\x2b\x01",
470 /*35 CONNECT_B3_T90_ACTIVE_IND */ (unsigned char *) "\x03\x2b\x01",
473 /*38 CONNECT_RESP */ (unsigned char *) "\x03\x2e\x0d\x06\x08\x0a\x05\x07\x09\x01\x16\x17\x28\x04\x0c\x27\x2f\x1c\x01\x01",
474 /*39 CONNECT_ACTIVE_RESP */ (unsigned char *) "\x03\x01",
475 /*3a DISCONNECT_RESP */ (unsigned char *) "\x03\x01",
477 /*3c MANUFACTURER_IND */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
479 /*3e INFO_RESP */ (unsigned char *) "\x03\x01",
480 /*3f FACILITY_RESP */ (unsigned char *) "\x03\x1f\x01",
482 /*41 CONNECT_B3_RESP */ (unsigned char *) "\x03\x2e\x2b\x01",
483 /*42 CONNECT_B3_ACTIVE_RESP */ (unsigned char *) "\x03\x01",
484 /*43 DISCONNECT_B3_RESP */ (unsigned char *) "\x03\x01",
486 /*45 DATA_B3_RESP */ (unsigned char *) "\x03\x19\x01",
487 /*46 RESET_B3_RESP */ (unsigned char *) "\x03\x01",
488 /*47 CONNECT_B3_T90_ACTIVE_RESP */ (unsigned char *) "\x03\x01",
495 /*4e MANUFACTURER_RESP */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
498 /*-------------------------------------------------------*/
500 #define byteTLcpy(x,y) *(__u8 *)(x)=*(__u8 *)(y);
501 #define wordTLcpy(x,y) *(__u16 *)(x)=*(__u16 *)(y);
502 #define dwordTLcpy(x,y) memcpy(x,y,4);
503 #define structTLcpy(x,y,l) memcpy (x,y,l)
504 #define structTLcpyovl(x,y,l) memmove (x,y,l)
506 #define byteTRcpy(x,y) *(__u8 *)(y)=*(__u8 *)(x);
507 #define wordTRcpy(x,y) *(__u16 *)(y)=*(__u16 *)(x);
508 #define dwordTRcpy(x,y) memcpy(y,x,4);
509 #define structTRcpy(x,y,l) memcpy (y,x,l)
510 #define structTRcpyovl(x,y,l) memmove (y,x,l)
512 /*-------------------------------------------------------*/
513 static unsigned command_2_index(unsigned c, unsigned sc)
516 c = 0x9 + (c & 0x0f);
522 return (sc & 3) * (0x9 + 0x9) + c;
525 /*-------------------------------------------------------*/
526 #define TYP (cdef[cmsg->par[cmsg->p]].typ)
527 #define OFF (((__u8 *)cmsg)+cdef[cmsg->par[cmsg->p]].off)
529 static void jumpcstruct(_cmsg * cmsg)
532 for (cmsg->p++, layer = 1; layer;) {
533 /* $$$$$ assert (cmsg->p); */
545 /*-------------------------------------------------------*/
546 static void pars_2_message(_cmsg * cmsg)
549 for (; TYP != _CEND; cmsg->p++) {
552 byteTLcpy(cmsg->m + cmsg->l, OFF);
556 wordTLcpy(cmsg->m + cmsg->l, OFF);
560 dwordTLcpy(cmsg->m + cmsg->l, OFF);
564 if (*(__u8 **) OFF == 0) {
565 *(cmsg->m + cmsg->l) = '\0';
567 } else if (**(_cstruct *) OFF != 0xff) {
568 structTLcpy(cmsg->m + cmsg->l, *(_cstruct *) OFF, 1 + **(_cstruct *) OFF);
569 cmsg->l += 1 + **(_cstruct *) OFF;
571 _cstruct s = *(_cstruct *) OFF;
572 structTLcpy(cmsg->m + cmsg->l, s, 3 + *(__u16 *) (s + 1));
573 cmsg->l += 3 + *(__u16 *) (s + 1);
577 /*----- Metastruktur 0 -----*/
578 if (*(_cmstruct *) OFF == CAPI_DEFAULT) {
579 *(cmsg->m + cmsg->l) = '\0';
583 /*----- Metastruktur wird composed -----*/
585 unsigned _l = cmsg->l;
589 pars_2_message(cmsg);
590 _ls = cmsg->l - _l - 1;
592 (cmsg->m + _l)[0] = (__u8) _ls;
594 structTLcpyovl(cmsg->m + _l + 3, cmsg->m + _l + 1, _ls);
595 (cmsg->m + _l)[0] = 0xff;
596 wordTLcpy(cmsg->m + _l + 1, &_ls);
604 /*-------------------------------------------------------*/
605 unsigned capi_cmsg2message(_cmsg * cmsg, __u8 * msg)
610 cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)];
612 pars_2_message(cmsg);
614 wordTLcpy(msg + 0, &cmsg->l);
615 byteTLcpy(cmsg->m + 4, &cmsg->Command);
616 byteTLcpy(cmsg->m + 5, &cmsg->Subcommand);
617 wordTLcpy(cmsg->m + 2, &cmsg->ApplId);
618 wordTLcpy(cmsg->m + 6, &cmsg->Messagenumber);
623 /*-------------------------------------------------------*/
624 static void message_2_pars(_cmsg * cmsg)
626 for (; TYP != _CEND; cmsg->p++) {
630 byteTRcpy(cmsg->m + cmsg->l, OFF);
634 wordTRcpy(cmsg->m + cmsg->l, OFF);
638 dwordTRcpy(cmsg->m + cmsg->l, OFF);
642 *(__u8 **) OFF = cmsg->m + cmsg->l;
644 if (cmsg->m[cmsg->l] != 0xff)
645 cmsg->l += 1 + cmsg->m[cmsg->l];
647 cmsg->l += 3 + *(__u16 *) (cmsg->m + cmsg->l + 1);
650 /*----- Metastruktur 0 -----*/
651 if (cmsg->m[cmsg->l] == '\0') {
652 *(_cmstruct *) OFF = CAPI_DEFAULT;
656 unsigned _l = cmsg->l;
657 *(_cmstruct *) OFF = CAPI_COMPOSE;
658 cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1;
660 message_2_pars(cmsg);
667 /*-------------------------------------------------------*/
668 unsigned capi_message2cmsg(_cmsg * cmsg, __u8 * msg)
670 memset(cmsg, 0, sizeof(_cmsg));
674 byteTRcpy(cmsg->m + 4, &cmsg->Command);
675 byteTRcpy(cmsg->m + 5, &cmsg->Subcommand);
676 cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)];
678 message_2_pars(cmsg);
680 wordTRcpy(msg + 0, &cmsg->l);
681 wordTRcpy(cmsg->m + 2, &cmsg->ApplId);
682 wordTRcpy(cmsg->m + 6, &cmsg->Messagenumber);
687 /*-------------------------------------------------------*/
688 unsigned capi_cmsg_header(_cmsg * cmsg, __u16 _ApplId,
689 __u8 _Command, __u8 _Subcommand,
690 __u16 _Messagenumber, __u32 _Controller)
692 memset(cmsg, 0, sizeof(_cmsg));
693 cmsg->ApplId = _ApplId;
694 cmsg->Command = _Command;
695 cmsg->Subcommand = _Subcommand;
696 cmsg->Messagenumber = _Messagenumber;
697 cmsg->adr.adrController = _Controller;
701 /*-------------------------------------------------------*/
703 static char *mnames[] =
715 "SELECT_B_PROTOCOL_REQ",
733 "SELECT_B_PROTOCOL_CONF",
736 "DISCONNECT_B3_CONF",
744 "CONNECT_ACTIVE_IND",
753 "CONNECT_B3_ACTIVE_IND",
758 "CONNECT_B3_T90_ACTIVE_IND",
762 "CONNECT_ACTIVE_RESP",
771 "CONNECT_B3_ACTIVE_RESP",
772 "DISCONNECT_B3_RESP",
776 "CONNECT_B3_T90_ACTIVE_RESP",
786 char *capi_cmd2str(__u8 cmd, __u8 subcmd)
788 return mnames[command_2_index(cmd, subcmd)];
792 /*-------------------------------------------------------*/
793 /*-------------------------------------------------------*/
795 static char *pnames[] =
800 /*03 */ "Controller/PLCI/NCCI",
801 /*04 */ "AdditionalInfo",
802 /*05 */ "B1configuration",
803 /*06 */ "B1protocol",
804 /*07 */ "B2configuration",
805 /*08 */ "B2protocol",
806 /*09 */ "B3configuration",
807 /*0a */ "B3protocol",
809 /*0c */ "BChannelinformation",
811 /*0e */ "CalledPartyNumber",
812 /*0f */ "CalledPartySubaddress",
813 /*10 */ "CallingPartyNumber",
814 /*11 */ "CallingPartySubaddress",
819 /*16 */ "ConnectedNumber",
820 /*17 */ "ConnectedSubaddress",
822 /*19 */ "DataHandle",
823 /*1a */ "DataLength",
824 /*1b */ "FacilityConfirmationParameter",
825 /*1c */ "Facilitydataarray",
826 /*1d */ "FacilityIndicationParameter",
827 /*1e */ "FacilityRequestParameter",
828 /*1f */ "FacilitySelector",
833 /*24 */ "InfoElement",
835 /*26 */ "InfoNumber",
836 /*27 */ "Keypadfacility",
844 /*2f */ "Useruserdata"
848 static char buf[8192];
853 /*-------------------------------------------------------*/
854 static void bufprint(char *fmt,...)
863 static void printstructlen(__u8 * m, unsigned len)
866 for (; len; len--, m++)
867 if (isalnum(*m) || *m == ' ') {
874 bufprint("<%02x", *m);
876 bufprint(" %02x", *m);
883 static void printstruct(__u8 * m)
890 len = ((__u16 *) (m + 1))[0];
893 printstructlen(m, len);
896 /*-------------------------------------------------------*/
897 #define NAME (pnames[cmsg->par[cmsg->p]])
899 static void protocol_message_2_pars(_cmsg * cmsg, int level)
901 for (; TYP != _CEND; cmsg->p++) {
902 int slen = 29 + 3 - level;
906 for (i = 0; i < level - 1; i++)
911 bufprint("%-*s = 0x%x\n", slen, NAME, *(__u8 *) (cmsg->m + cmsg->l));
915 bufprint("%-*s = 0x%x\n", slen, NAME, *(__u16 *) (cmsg->m + cmsg->l));
919 bufprint("%-*s = 0x%lx\n", slen, NAME, *(__u32 *) (cmsg->m + cmsg->l));
923 bufprint("%-*s = ", slen, NAME);
924 if (cmsg->m[cmsg->l] == '\0')
927 printstruct(cmsg->m + cmsg->l);
929 if (cmsg->m[cmsg->l] != 0xff)
930 cmsg->l += 1 + cmsg->m[cmsg->l];
932 cmsg->l += 3 + *(__u16 *) (cmsg->m + cmsg->l + 1);
937 /*----- Metastruktur 0 -----*/
938 if (cmsg->m[cmsg->l] == '\0') {
939 bufprint("%-*s = default\n", slen, NAME);
944 unsigned _l = cmsg->l;
945 bufprint("%-*s\n", slen, name);
946 cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1;
948 protocol_message_2_pars(cmsg, level + 1);
954 /*-------------------------------------------------------*/
955 char *capi_message2str(__u8 * msg)
965 byteTRcpy(cmsg.m + 4, &cmsg.Command);
966 byteTRcpy(cmsg.m + 5, &cmsg.Subcommand);
967 cmsg.par = cpars[command_2_index(cmsg.Command, cmsg.Subcommand)];
969 bufprint("%-26s ID=%03d #0x%04x LEN=%04d\n",
970 mnames[command_2_index(cmsg.Command, cmsg.Subcommand)],
971 ((unsigned short *) msg)[1],
972 ((unsigned short *) msg)[3],
973 ((unsigned short *) msg)[0]);
975 protocol_message_2_pars(&cmsg, 1);
979 char *capi_cmsg2str(_cmsg * cmsg)
985 bufprint("%s ID=%03d #0x%04x LEN=%04d\n",
986 mnames[command_2_index(cmsg->Command, cmsg->Subcommand)],
987 ((__u16 *) cmsg->m)[1],
988 ((__u16 *) cmsg->m)[3],
989 ((__u16 *) cmsg->m)[0]);
990 protocol_message_2_pars(cmsg, 1);
994 EXPORT_SYMBOL(capi_cmsg2message);
995 EXPORT_SYMBOL(capi_message2cmsg);
996 EXPORT_SYMBOL(capi_cmsg_header);
997 EXPORT_SYMBOL(capi_cmd2str);
998 EXPORT_SYMBOL(capi_cmsg2str);
999 EXPORT_SYMBOL(capi_message2str);
1000 EXPORT_SYMBOL(capi_info2str);
1002 static int __init capiutil_init(void)
1007 static void __exit capiutil_exit(void)
1011 module_init(capiutil_init);
1012 module_exit(capiutil_exit);