1 /* $Id: capiutil.c,v 1.1.1.1 2005/04/11 02:50:22 jack Exp $
3 * CAPI 2.0 convert capi message to capi message struct
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 #include <linux/module.h>
14 #include <linux/string.h>
15 #include <linux/ctype.h>
16 #include <linux/stddef.h>
17 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <asm/segment.h>
21 #include <linux/config.h>
24 MODULE_DESCRIPTION("CAPI4Linux: CAPI message conversion support");
25 MODULE_AUTHOR("Carsten Paeth");
26 MODULE_LICENSE("GPL");
28 /* from CAPI2.0 DDK AVM Berlin GmbH */
30 #ifndef CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON
31 char *capi_info2str(__u16 reason)
36 char *capi_info2str(__u16 reason)
40 /*-- informative values (corresponding message was processed) -----*/
42 return "NCPI not supported by current protocol, NCPI ignored";
44 return "Flags not supported by current protocol, flags ignored";
46 return "Alert already sent by another application";
48 /*-- error information concerning CAPI_REGISTER -----*/
50 return "Too many applications";
52 return "Logical block size too small, must be at least 128 Bytes";
54 return "Buffer exceeds 64 kByte";
56 return "Message buffer size too small, must be at least 1024 Bytes";
58 return "Max. number of logical connections not supported";
62 return "The message could not be accepted because of an internal busy condition";
64 return "OS resource error (no memory ?)";
66 return "CAPI not installed";
68 return "Controller does not support external equipment";
70 return "Controller does only support external equipment";
72 /*-- error information concerning message exchange functions -----*/
74 return "Illegal application number";
76 return "Illegal command or subcommand or message length less than 12 bytes";
78 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";
80 return "Queue is empty";
82 return "Queue overflow, a message was lost !! This indicates a configuration error. The only recovery from this error is to perform a CAPI_RELEASE";
84 return "Unknown notification parameter";
86 return "The Message could not be accepted because of an internal busy condition";
88 return "OS Resource error (no memory ?)";
90 return "CAPI not installed";
92 return "Controller does not support external equipment";
94 return "Controller does only support external equipment";
96 /*-- error information concerning resource / coding problems -----*/
98 return "Message not supported in current state";
100 return "Illegal Controller / PLCI / NCCI";
102 return "Out of PLCI";
104 return "Out of NCCI";
106 return "Out of LISTEN";
108 return "Out of FAX resources (protocol T.30)";
110 return "Illegal message parameter coding";
112 /*-- error information concerning requested services -----*/
114 return "B1 protocol not supported";
116 return "B2 protocol not supported";
118 return "B3 protocol not supported";
120 return "B1 protocol parameter not supported";
122 return "B2 protocol parameter not supported";
124 return "B3 protocol parameter not supported";
126 return "B protocol combination not supported";
128 return "NCPI not supported";
130 return "CIP Value unknown";
132 return "Flags not supported (reserved bits)";
134 return "Facility not supported";
136 return "Data length not supported by current protocol";
138 return "Reset procedure not supported by current protocol";
140 /*-- informations about the clearing of a physical connection -----*/
142 return "Protocol error layer 1 (broken line or B-channel removed by signalling protocol)";
144 return "Protocol error layer 2";
146 return "Protocol error layer 3";
148 return "Another application got that call";
149 /*-- T.30 specific reasons -----*/
151 return "Connecting not successful (remote station is no FAX G3 machine)";
153 return "Connecting not successful (training error)";
155 return "Disconnected before transfer (remote station does not support transfer mode, e.g. resolution)";
157 return "Disconnected during transfer (remote abort)";
159 return "Disconnected during transfer (remote procedure error, e.g. unsuccessful repetition of T.30 commands)";
161 return "Disconnected during transfer (local tx data underrun)";
163 return "Disconnected during transfer (local rx data overflow)";
165 return "Disconnected during transfer (local abort)";
167 return "Illegal parameter coding (e.g. SFF coding error)";
169 /*-- disconnect causes from the network according to ETS 300 102-1/Q.931 -----*/
170 case 0x3481: return "Unallocated (unassigned) number";
171 case 0x3482: return "No route to specified transit network";
172 case 0x3483: return "No route to destination";
173 case 0x3486: return "Channel unacceptable";
175 return "Call awarded and being delivered in an established channel";
176 case 0x3490: return "Normal call clearing";
177 case 0x3491: return "User busy";
178 case 0x3492: return "No user responding";
179 case 0x3493: return "No answer from user (user alerted)";
180 case 0x3495: return "Call rejected";
181 case 0x3496: return "Number changed";
182 case 0x349A: return "Non-selected user clearing";
183 case 0x349B: return "Destination out of order";
184 case 0x349C: return "Invalid number format";
185 case 0x349D: return "Facility rejected";
186 case 0x349E: return "Response to STATUS ENQUIRY";
187 case 0x349F: return "Normal, unspecified";
188 case 0x34A2: return "No circuit / channel available";
189 case 0x34A6: return "Network out of order";
190 case 0x34A9: return "Temporary failure";
191 case 0x34AA: return "Switching equipment congestion";
192 case 0x34AB: return "Access information discarded";
193 case 0x34AC: return "Requested circuit / channel not available";
194 case 0x34AF: return "Resources unavailable, unspecified";
195 case 0x34B1: return "Quality of service unavailable";
196 case 0x34B2: return "Requested facility not subscribed";
197 case 0x34B9: return "Bearer capability not authorized";
198 case 0x34BA: return "Bearer capability not presently available";
199 case 0x34BF: return "Service or option not available, unspecified";
200 case 0x34C1: return "Bearer capability not implemented";
201 case 0x34C2: return "Channel type not implemented";
202 case 0x34C5: return "Requested facility not implemented";
203 case 0x34C6: return "Only restricted digital information bearer capability is available";
204 case 0x34CF: return "Service or option not implemented, unspecified";
205 case 0x34D1: return "Invalid call reference value";
206 case 0x34D2: return "Identified channel does not exist";
207 case 0x34D3: return "A suspended call exists, but this call identity does not";
208 case 0x34D4: return "Call identity in use";
209 case 0x34D5: return "No call suspended";
210 case 0x34D6: return "Call having the requested call identity has been cleared";
211 case 0x34D8: return "Incompatible destination";
212 case 0x34DB: return "Invalid transit network selection";
213 case 0x34DF: return "Invalid message, unspecified";
214 case 0x34E0: return "Mandatory information element is missing";
215 case 0x34E1: return "Message type non-existent or not implemented";
216 case 0x34E2: return "Message not compatible with call state or message type non-existent or not implemented";
217 case 0x34E3: return "Information element non-existent or not implemented";
218 case 0x34E4: return "Invalid information element contents";
219 case 0x34E5: return "Message not compatible with call state";
220 case 0x34E6: return "Recovery on timer expiry";
221 case 0x34EF: return "Protocol error, unspecified";
222 case 0x34FF: return "Interworking, unspecified";
224 default: return "No additional information";
241 static _cdef cdef[] =
250 {_CDWORD, offsetof(_cmsg, adr.adrController)},
252 {_CMSTRUCT, offsetof(_cmsg, AdditionalInfo)},
254 {_CSTRUCT, offsetof(_cmsg, B1configuration)},
256 {_CWORD, offsetof(_cmsg, B1protocol)},
258 {_CSTRUCT, offsetof(_cmsg, B2configuration)},
260 {_CWORD, offsetof(_cmsg, B2protocol)},
262 {_CSTRUCT, offsetof(_cmsg, B3configuration)},
264 {_CWORD, offsetof(_cmsg, B3protocol)},
266 {_CSTRUCT, offsetof(_cmsg, BC)},
268 {_CSTRUCT, offsetof(_cmsg, BChannelinformation)},
270 {_CMSTRUCT, offsetof(_cmsg, BProtocol)},
272 {_CSTRUCT, offsetof(_cmsg, CalledPartyNumber)},
274 {_CSTRUCT, offsetof(_cmsg, CalledPartySubaddress)},
276 {_CSTRUCT, offsetof(_cmsg, CallingPartyNumber)},
278 {_CSTRUCT, offsetof(_cmsg, CallingPartySubaddress)},
280 {_CDWORD, offsetof(_cmsg, CIPmask)},
282 {_CDWORD, offsetof(_cmsg, CIPmask2)},
284 {_CWORD, offsetof(_cmsg, CIPValue)},
286 {_CDWORD, offsetof(_cmsg, Class)},
288 {_CSTRUCT, offsetof(_cmsg, ConnectedNumber)},
290 {_CSTRUCT, offsetof(_cmsg, ConnectedSubaddress)},
292 {_CDWORD, offsetof(_cmsg, Data)},
294 {_CWORD, offsetof(_cmsg, DataHandle)},
296 {_CWORD, offsetof(_cmsg, DataLength)},
298 {_CSTRUCT, offsetof(_cmsg, FacilityConfirmationParameter)},
300 {_CSTRUCT, offsetof(_cmsg, Facilitydataarray)},
302 {_CSTRUCT, offsetof(_cmsg, FacilityIndicationParameter)},
304 {_CSTRUCT, offsetof(_cmsg, FacilityRequestParameter)},
306 {_CWORD, offsetof(_cmsg, FacilitySelector)},
308 {_CWORD, offsetof(_cmsg, Flags)},
310 {_CDWORD, offsetof(_cmsg, Function)},
312 {_CSTRUCT, offsetof(_cmsg, HLC)},
314 {_CWORD, offsetof(_cmsg, Info)},
316 {_CSTRUCT, offsetof(_cmsg, InfoElement)},
318 {_CDWORD, offsetof(_cmsg, InfoMask)},
320 {_CWORD, offsetof(_cmsg, InfoNumber)},
322 {_CSTRUCT, offsetof(_cmsg, Keypadfacility)},
324 {_CSTRUCT, offsetof(_cmsg, LLC)},
326 {_CSTRUCT, offsetof(_cmsg, ManuData)},
328 {_CDWORD, offsetof(_cmsg, ManuID)},
330 {_CSTRUCT, offsetof(_cmsg, NCPI)},
332 {_CWORD, offsetof(_cmsg, Reason)},
334 {_CWORD, offsetof(_cmsg, Reason_B3)},
336 {_CWORD, offsetof(_cmsg, Reject)},
338 {_CSTRUCT, offsetof(_cmsg, Useruserdata)}
341 static unsigned char *cpars[] =
344 /*01 ALERT_REQ */ (unsigned char *) "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
345 /*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",
347 /*04 DISCONNECT_REQ */ (unsigned char *) "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
348 /*05 LISTEN_REQ */ (unsigned char *) "\x03\x25\x12\x13\x10\x11\x01",
351 /*08 INFO_REQ */ (unsigned char *) "\x03\x0e\x04\x0c\x27\x2f\x1c\x01\x01",
352 /*09 FACILITY_REQ */ (unsigned char *) "\x03\x1f\x1e\x01",
353 /*0a SELECT_B_PROTOCOL_REQ */ (unsigned char *) "\x03\x0d\x06\x08\x0a\x05\x07\x09\x01\x01",
354 /*0b CONNECT_B3_REQ */ (unsigned char *) "\x03\x2b\x01",
356 /*0d DISCONNECT_B3_REQ */ (unsigned char *) "\x03\x2b\x01",
358 /*0f DATA_B3_REQ */ (unsigned char *) "\x03\x18\x1a\x19\x20\x01",
359 /*10 RESET_B3_REQ */ (unsigned char *) "\x03\x2b\x01",
362 /*13 ALERT_CONF */ (unsigned char *) "\x03\x23\x01",
363 /*14 CONNECT_CONF */ (unsigned char *) "\x03\x23\x01",
365 /*16 DISCONNECT_CONF */ (unsigned char *) "\x03\x23\x01",
366 /*17 LISTEN_CONF */ (unsigned char *) "\x03\x23\x01",
367 /*18 MANUFACTURER_REQ */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
369 /*1a INFO_CONF */ (unsigned char *) "\x03\x23\x01",
370 /*1b FACILITY_CONF */ (unsigned char *) "\x03\x23\x1f\x1b\x01",
371 /*1c SELECT_B_PROTOCOL_CONF */ (unsigned char *) "\x03\x23\x01",
372 /*1d CONNECT_B3_CONF */ (unsigned char *) "\x03\x23\x01",
374 /*1f DISCONNECT_B3_CONF */ (unsigned char *) "\x03\x23\x01",
376 /*21 DATA_B3_CONF */ (unsigned char *) "\x03\x19\x23\x01",
377 /*22 RESET_B3_CONF */ (unsigned char *) "\x03\x23\x01",
381 /*26 CONNECT_IND */ (unsigned char *) "\x03\x14\x0e\x10\x0f\x11\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
382 /*27 CONNECT_ACTIVE_IND */ (unsigned char *) "\x03\x16\x17\x28\x01",
383 /*28 DISCONNECT_IND */ (unsigned char *) "\x03\x2c\x01",
385 /*2a MANUFACTURER_CONF */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
387 /*2c INFO_IND */ (unsigned char *) "\x03\x26\x24\x01",
388 /*2d FACILITY_IND */ (unsigned char *) "\x03\x1f\x1d\x01",
390 /*2f CONNECT_B3_IND */ (unsigned char *) "\x03\x2b\x01",
391 /*30 CONNECT_B3_ACTIVE_IND */ (unsigned char *) "\x03\x2b\x01",
392 /*31 DISCONNECT_B3_IND */ (unsigned char *) "\x03\x2d\x2b\x01",
394 /*33 DATA_B3_IND */ (unsigned char *) "\x03\x18\x1a\x19\x20\x01",
395 /*34 RESET_B3_IND */ (unsigned char *) "\x03\x2b\x01",
396 /*35 CONNECT_B3_T90_ACTIVE_IND */ (unsigned char *) "\x03\x2b\x01",
399 /*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",
400 /*39 CONNECT_ACTIVE_RESP */ (unsigned char *) "\x03\x01",
401 /*3a DISCONNECT_RESP */ (unsigned char *) "\x03\x01",
403 /*3c MANUFACTURER_IND */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
405 /*3e INFO_RESP */ (unsigned char *) "\x03\x01",
406 /*3f FACILITY_RESP */ (unsigned char *) "\x03\x1f\x01",
408 /*41 CONNECT_B3_RESP */ (unsigned char *) "\x03\x2e\x2b\x01",
409 /*42 CONNECT_B3_ACTIVE_RESP */ (unsigned char *) "\x03\x01",
410 /*43 DISCONNECT_B3_RESP */ (unsigned char *) "\x03\x01",
412 /*45 DATA_B3_RESP */ (unsigned char *) "\x03\x19\x01",
413 /*46 RESET_B3_RESP */ (unsigned char *) "\x03\x01",
414 /*47 CONNECT_B3_T90_ACTIVE_RESP */ (unsigned char *) "\x03\x01",
421 /*4e MANUFACTURER_RESP */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
424 /*-------------------------------------------------------*/
426 #define byteTLcpy(x,y) *(__u8 *)(x)=*(__u8 *)(y);
427 #define wordTLcpy(x,y) *(__u16 *)(x)=*(__u16 *)(y);
428 #define dwordTLcpy(x,y) memcpy(x,y,4);
429 #define structTLcpy(x,y,l) memcpy (x,y,l)
430 #define structTLcpyovl(x,y,l) memmove (x,y,l)
432 #define byteTRcpy(x,y) *(__u8 *)(y)=*(__u8 *)(x);
433 #define wordTRcpy(x,y) *(__u16 *)(y)=*(__u16 *)(x);
434 #define dwordTRcpy(x,y) memcpy(y,x,4);
435 #define structTRcpy(x,y,l) memcpy (y,x,l)
436 #define structTRcpyovl(x,y,l) memmove (y,x,l)
438 /*-------------------------------------------------------*/
439 static unsigned command_2_index(unsigned c, unsigned sc)
442 c = 0x9 + (c & 0x0f);
448 return (sc & 3) * (0x9 + 0x9) + c;
451 /*-------------------------------------------------------*/
452 #define TYP (cdef[cmsg->par[cmsg->p]].typ)
453 #define OFF (((__u8 *)cmsg)+cdef[cmsg->par[cmsg->p]].off)
455 static void jumpcstruct(_cmsg * cmsg)
458 for (cmsg->p++, layer = 1; layer;) {
459 /* $$$$$ assert (cmsg->p); */
471 /*-------------------------------------------------------*/
472 static void pars_2_message(_cmsg * cmsg)
475 for (; TYP != _CEND; cmsg->p++) {
478 byteTLcpy(cmsg->m + cmsg->l, OFF);
482 wordTLcpy(cmsg->m + cmsg->l, OFF);
486 dwordTLcpy(cmsg->m + cmsg->l, OFF);
490 if (*(__u8 **) OFF == 0) {
491 *(cmsg->m + cmsg->l) = '\0';
493 } else if (**(_cstruct *) OFF != 0xff) {
494 structTLcpy(cmsg->m + cmsg->l, *(_cstruct *) OFF, 1 + **(_cstruct *) OFF);
495 cmsg->l += 1 + **(_cstruct *) OFF;
497 _cstruct s = *(_cstruct *) OFF;
498 structTLcpy(cmsg->m + cmsg->l, s, 3 + *(__u16 *) (s + 1));
499 cmsg->l += 3 + *(__u16 *) (s + 1);
503 /*----- Metastruktur 0 -----*/
504 if (*(_cmstruct *) OFF == CAPI_DEFAULT) {
505 *(cmsg->m + cmsg->l) = '\0';
509 /*----- Metastruktur wird composed -----*/
511 unsigned _l = cmsg->l;
515 pars_2_message(cmsg);
516 _ls = cmsg->l - _l - 1;
518 (cmsg->m + _l)[0] = (__u8) _ls;
520 structTLcpyovl(cmsg->m + _l + 3, cmsg->m + _l + 1, _ls);
521 (cmsg->m + _l)[0] = 0xff;
522 wordTLcpy(cmsg->m + _l + 1, &_ls);
530 /*-------------------------------------------------------*/
531 unsigned capi_cmsg2message(_cmsg * cmsg, __u8 * msg)
536 cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)];
538 pars_2_message(cmsg);
540 wordTLcpy(msg + 0, &cmsg->l);
541 byteTLcpy(cmsg->m + 4, &cmsg->Command);
542 byteTLcpy(cmsg->m + 5, &cmsg->Subcommand);
543 wordTLcpy(cmsg->m + 2, &cmsg->ApplId);
544 wordTLcpy(cmsg->m + 6, &cmsg->Messagenumber);
549 /*-------------------------------------------------------*/
550 static void message_2_pars(_cmsg * cmsg)
552 for (; TYP != _CEND; cmsg->p++) {
556 byteTRcpy(cmsg->m + cmsg->l, OFF);
560 wordTRcpy(cmsg->m + cmsg->l, OFF);
564 dwordTRcpy(cmsg->m + cmsg->l, OFF);
568 *(__u8 **) OFF = cmsg->m + cmsg->l;
570 if (cmsg->m[cmsg->l] != 0xff)
571 cmsg->l += 1 + cmsg->m[cmsg->l];
573 cmsg->l += 3 + *(__u16 *) (cmsg->m + cmsg->l + 1);
576 /*----- Metastruktur 0 -----*/
577 if (cmsg->m[cmsg->l] == '\0') {
578 *(_cmstruct *) OFF = CAPI_DEFAULT;
582 unsigned _l = cmsg->l;
583 *(_cmstruct *) OFF = CAPI_COMPOSE;
584 cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1;
586 message_2_pars(cmsg);
593 /*-------------------------------------------------------*/
594 unsigned capi_message2cmsg(_cmsg * cmsg, __u8 * msg)
596 memset(cmsg, 0, sizeof(_cmsg));
600 byteTRcpy(cmsg->m + 4, &cmsg->Command);
601 byteTRcpy(cmsg->m + 5, &cmsg->Subcommand);
602 cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)];
604 message_2_pars(cmsg);
606 wordTRcpy(msg + 0, &cmsg->l);
607 wordTRcpy(cmsg->m + 2, &cmsg->ApplId);
608 wordTRcpy(cmsg->m + 6, &cmsg->Messagenumber);
613 /*-------------------------------------------------------*/
614 unsigned capi_cmsg_header(_cmsg * cmsg, __u16 _ApplId,
615 __u8 _Command, __u8 _Subcommand,
616 __u16 _Messagenumber, __u32 _Controller)
618 memset(cmsg, 0, sizeof(_cmsg));
619 cmsg->ApplId = _ApplId;
620 cmsg->Command = _Command;
621 cmsg->Subcommand = _Subcommand;
622 cmsg->Messagenumber = _Messagenumber;
623 cmsg->adr.adrController = _Controller;
627 /*-------------------------------------------------------*/
629 static char *mnames[] =
641 "SELECT_B_PROTOCOL_REQ",
659 "SELECT_B_PROTOCOL_CONF",
662 "DISCONNECT_B3_CONF",
670 "CONNECT_ACTIVE_IND",
679 "CONNECT_B3_ACTIVE_IND",
684 "CONNECT_B3_T90_ACTIVE_IND",
688 "CONNECT_ACTIVE_RESP",
697 "CONNECT_B3_ACTIVE_RESP",
698 "DISCONNECT_B3_RESP",
702 "CONNECT_B3_T90_ACTIVE_RESP",
712 char *capi_cmd2str(__u8 cmd, __u8 subcmd)
714 return mnames[command_2_index(cmd, subcmd)];
718 /*-------------------------------------------------------*/
719 /*-------------------------------------------------------*/
721 static char *pnames[] =
726 /*03 */ "Controller/PLCI/NCCI",
727 /*04 */ "AdditionalInfo",
728 /*05 */ "B1configuration",
729 /*06 */ "B1protocol",
730 /*07 */ "B2configuration",
731 /*08 */ "B2protocol",
732 /*09 */ "B3configuration",
733 /*0a */ "B3protocol",
735 /*0c */ "BChannelinformation",
737 /*0e */ "CalledPartyNumber",
738 /*0f */ "CalledPartySubaddress",
739 /*10 */ "CallingPartyNumber",
740 /*11 */ "CallingPartySubaddress",
745 /*16 */ "ConnectedNumber",
746 /*17 */ "ConnectedSubaddress",
748 /*19 */ "DataHandle",
749 /*1a */ "DataLength",
750 /*1b */ "FacilityConfirmationParameter",
751 /*1c */ "Facilitydataarray",
752 /*1d */ "FacilityIndicationParameter",
753 /*1e */ "FacilityRequestParameter",
754 /*1f */ "FacilitySelector",
759 /*24 */ "InfoElement",
761 /*26 */ "InfoNumber",
762 /*27 */ "Keypadfacility",
770 /*2f */ "Useruserdata"
774 static char buf[8192];
779 /*-------------------------------------------------------*/
780 static void bufprint(char *fmt,...)
789 static void printstructlen(__u8 * m, unsigned len)
792 for (; len; len--, m++)
793 if (isalnum(*m) || *m == ' ') {
800 bufprint("<%02x", *m);
802 bufprint(" %02x", *m);
809 static void printstruct(__u8 * m)
816 len = ((__u16 *) (m + 1))[0];
819 printstructlen(m, len);
822 /*-------------------------------------------------------*/
823 #define NAME (pnames[cmsg->par[cmsg->p]])
825 static void protocol_message_2_pars(_cmsg * cmsg, int level)
827 for (; TYP != _CEND; cmsg->p++) {
828 int slen = 29 + 3 - level;
832 for (i = 0; i < level - 1; i++)
837 bufprint("%-*s = 0x%x\n", slen, NAME, *(__u8 *) (cmsg->m + cmsg->l));
841 bufprint("%-*s = 0x%x\n", slen, NAME, *(__u16 *) (cmsg->m + cmsg->l));
845 bufprint("%-*s = 0x%lx\n", slen, NAME, *(__u32 *) (cmsg->m + cmsg->l));
849 bufprint("%-*s = ", slen, NAME);
850 if (cmsg->m[cmsg->l] == '\0')
853 printstruct(cmsg->m + cmsg->l);
855 if (cmsg->m[cmsg->l] != 0xff)
856 cmsg->l += 1 + cmsg->m[cmsg->l];
858 cmsg->l += 3 + *(__u16 *) (cmsg->m + cmsg->l + 1);
863 /*----- Metastruktur 0 -----*/
864 if (cmsg->m[cmsg->l] == '\0') {
865 bufprint("%-*s = default\n", slen, NAME);
870 unsigned _l = cmsg->l;
871 bufprint("%-*s\n", slen, name);
872 cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1;
874 protocol_message_2_pars(cmsg, level + 1);
880 /*-------------------------------------------------------*/
881 char *capi_message2str(__u8 * msg)
891 byteTRcpy(cmsg.m + 4, &cmsg.Command);
892 byteTRcpy(cmsg.m + 5, &cmsg.Subcommand);
893 cmsg.par = cpars[command_2_index(cmsg.Command, cmsg.Subcommand)];
895 bufprint("%-26s ID=%03d #0x%04x LEN=%04d\n",
896 mnames[command_2_index(cmsg.Command, cmsg.Subcommand)],
897 ((unsigned short *) msg)[1],
898 ((unsigned short *) msg)[3],
899 ((unsigned short *) msg)[0]);
901 protocol_message_2_pars(&cmsg, 1);
905 char *capi_cmsg2str(_cmsg * cmsg)
911 bufprint("%s ID=%03d #0x%04x LEN=%04d\n",
912 mnames[command_2_index(cmsg->Command, cmsg->Subcommand)],
913 ((__u16 *) cmsg->m)[1],
914 ((__u16 *) cmsg->m)[3],
915 ((__u16 *) cmsg->m)[0]);
916 protocol_message_2_pars(cmsg, 1);
920 EXPORT_SYMBOL(capi_cmsg2message);
921 EXPORT_SYMBOL(capi_message2cmsg);
922 EXPORT_SYMBOL(capi_cmsg_header);
923 EXPORT_SYMBOL(capi_cmd2str);
924 EXPORT_SYMBOL(capi_cmsg2str);
925 EXPORT_SYMBOL(capi_message2str);
926 EXPORT_SYMBOL(capi_info2str);
928 static int __init capiutil_init(void)
933 static void __exit capiutil_exit(void)
937 module_init(capiutil_init);
938 module_exit(capiutil_exit);