1 /* $Id: capiutil.c,v 1.13.6.4 2001/09/23 22:24:33 kai 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 <linux/isdn/capiutil.h>
22 /* from CAPI2.0 DDK AVM Berlin GmbH */
24 #ifndef CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON
25 char *capi_info2str(u16 reason
)
30 char *capi_info2str(u16 reason
)
34 /*-- informative values (corresponding message was processed) -----*/
36 return "NCPI not supported by current protocol, NCPI ignored";
38 return "Flags not supported by current protocol, flags ignored";
40 return "Alert already sent by another application";
42 /*-- error information concerning CAPI_REGISTER -----*/
44 return "Too many applications";
46 return "Logical block size too small, must be at least 128 Bytes";
48 return "Buffer exceeds 64 kByte";
50 return "Message buffer size too small, must be at least 1024 Bytes";
52 return "Max. number of logical connections not supported";
56 return "The message could not be accepted because of an internal busy condition";
58 return "OS resource error (no memory ?)";
60 return "CAPI not installed";
62 return "Controller does not support external equipment";
64 return "Controller does only support external equipment";
66 /*-- error information concerning message exchange functions -----*/
68 return "Illegal application number";
70 return "Illegal command or subcommand or message length less than 12 bytes";
72 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";
74 return "Queue is empty";
76 return "Queue overflow, a message was lost !! This indicates a configuration error. The only recovery from this error is to perform a CAPI_RELEASE";
78 return "Unknown notification parameter";
80 return "The Message could not be accepted because of an internal busy condition";
82 return "OS Resource error (no memory ?)";
84 return "CAPI not installed";
86 return "Controller does not support external equipment";
88 return "Controller does only support external equipment";
90 /*-- error information concerning resource / coding problems -----*/
92 return "Message not supported in current state";
94 return "Illegal Controller / PLCI / NCCI";
100 return "Out of LISTEN";
102 return "Out of FAX resources (protocol T.30)";
104 return "Illegal message parameter coding";
106 /*-- error information concerning requested services -----*/
108 return "B1 protocol not supported";
110 return "B2 protocol not supported";
112 return "B3 protocol not supported";
114 return "B1 protocol parameter not supported";
116 return "B2 protocol parameter not supported";
118 return "B3 protocol parameter not supported";
120 return "B protocol combination not supported";
122 return "NCPI not supported";
124 return "CIP Value unknown";
126 return "Flags not supported (reserved bits)";
128 return "Facility not supported";
130 return "Data length not supported by current protocol";
132 return "Reset procedure not supported by current protocol";
134 /*-- informations about the clearing of a physical connection -----*/
136 return "Protocol error layer 1 (broken line or B-channel removed by signalling protocol)";
138 return "Protocol error layer 2";
140 return "Protocol error layer 3";
142 return "Another application got that call";
143 /*-- T.30 specific reasons -----*/
145 return "Connecting not successful (remote station is no FAX G3 machine)";
147 return "Connecting not successful (training error)";
149 return "Disconnected before transfer (remote station does not support transfer mode, e.g. resolution)";
151 return "Disconnected during transfer (remote abort)";
153 return "Disconnected during transfer (remote procedure error, e.g. unsuccessful repetition of T.30 commands)";
155 return "Disconnected during transfer (local tx data underrun)";
157 return "Disconnected during transfer (local rx data overflow)";
159 return "Disconnected during transfer (local abort)";
161 return "Illegal parameter coding (e.g. SFF coding error)";
163 /*-- disconnect causes from the network according to ETS 300 102-1/Q.931 -----*/
164 case 0x3481: return "Unallocated (unassigned) number";
165 case 0x3482: return "No route to specified transit network";
166 case 0x3483: return "No route to destination";
167 case 0x3486: return "Channel unacceptable";
169 return "Call awarded and being delivered in an established channel";
170 case 0x3490: return "Normal call clearing";
171 case 0x3491: return "User busy";
172 case 0x3492: return "No user responding";
173 case 0x3493: return "No answer from user (user alerted)";
174 case 0x3495: return "Call rejected";
175 case 0x3496: return "Number changed";
176 case 0x349A: return "Non-selected user clearing";
177 case 0x349B: return "Destination out of order";
178 case 0x349C: return "Invalid number format";
179 case 0x349D: return "Facility rejected";
180 case 0x349E: return "Response to STATUS ENQUIRY";
181 case 0x349F: return "Normal, unspecified";
182 case 0x34A2: return "No circuit / channel available";
183 case 0x34A6: return "Network out of order";
184 case 0x34A9: return "Temporary failure";
185 case 0x34AA: return "Switching equipment congestion";
186 case 0x34AB: return "Access information discarded";
187 case 0x34AC: return "Requested circuit / channel not available";
188 case 0x34AF: return "Resources unavailable, unspecified";
189 case 0x34B1: return "Quality of service unavailable";
190 case 0x34B2: return "Requested facility not subscribed";
191 case 0x34B9: return "Bearer capability not authorized";
192 case 0x34BA: return "Bearer capability not presently available";
193 case 0x34BF: return "Service or option not available, unspecified";
194 case 0x34C1: return "Bearer capability not implemented";
195 case 0x34C2: return "Channel type not implemented";
196 case 0x34C5: return "Requested facility not implemented";
197 case 0x34C6: return "Only restricted digital information bearer capability is available";
198 case 0x34CF: return "Service or option not implemented, unspecified";
199 case 0x34D1: return "Invalid call reference value";
200 case 0x34D2: return "Identified channel does not exist";
201 case 0x34D3: return "A suspended call exists, but this call identity does not";
202 case 0x34D4: return "Call identity in use";
203 case 0x34D5: return "No call suspended";
204 case 0x34D6: return "Call having the requested call identity has been cleared";
205 case 0x34D8: return "Incompatible destination";
206 case 0x34DB: return "Invalid transit network selection";
207 case 0x34DF: return "Invalid message, unspecified";
208 case 0x34E0: return "Mandatory information element is missing";
209 case 0x34E1: return "Message type non-existent or not implemented";
210 case 0x34E2: return "Message not compatible with call state or message type non-existent or not implemented";
211 case 0x34E3: return "Information element non-existent or not implemented";
212 case 0x34E4: return "Invalid information element contents";
213 case 0x34E5: return "Message not compatible with call state";
214 case 0x34E6: return "Recovery on timer expiry";
215 case 0x34EF: return "Protocol error, unspecified";
216 case 0x34FF: return "Interworking, unspecified";
218 default: return "No additional information";
235 static _cdef cdef
[] =
244 {_CDWORD
, offsetof(_cmsg
, adr
.adrController
)},
246 {_CMSTRUCT
, offsetof(_cmsg
, AdditionalInfo
)},
248 {_CSTRUCT
, offsetof(_cmsg
, B1configuration
)},
250 {_CWORD
, offsetof(_cmsg
, B1protocol
)},
252 {_CSTRUCT
, offsetof(_cmsg
, B2configuration
)},
254 {_CWORD
, offsetof(_cmsg
, B2protocol
)},
256 {_CSTRUCT
, offsetof(_cmsg
, B3configuration
)},
258 {_CWORD
, offsetof(_cmsg
, B3protocol
)},
260 {_CSTRUCT
, offsetof(_cmsg
, BC
)},
262 {_CSTRUCT
, offsetof(_cmsg
, BChannelinformation
)},
264 {_CMSTRUCT
, offsetof(_cmsg
, BProtocol
)},
266 {_CSTRUCT
, offsetof(_cmsg
, CalledPartyNumber
)},
268 {_CSTRUCT
, offsetof(_cmsg
, CalledPartySubaddress
)},
270 {_CSTRUCT
, offsetof(_cmsg
, CallingPartyNumber
)},
272 {_CSTRUCT
, offsetof(_cmsg
, CallingPartySubaddress
)},
274 {_CDWORD
, offsetof(_cmsg
, CIPmask
)},
276 {_CDWORD
, offsetof(_cmsg
, CIPmask2
)},
278 {_CWORD
, offsetof(_cmsg
, CIPValue
)},
280 {_CDWORD
, offsetof(_cmsg
, Class
)},
282 {_CSTRUCT
, offsetof(_cmsg
, ConnectedNumber
)},
284 {_CSTRUCT
, offsetof(_cmsg
, ConnectedSubaddress
)},
286 {_CDWORD
, offsetof(_cmsg
, Data
)},
288 {_CWORD
, offsetof(_cmsg
, DataHandle
)},
290 {_CWORD
, offsetof(_cmsg
, DataLength
)},
292 {_CSTRUCT
, offsetof(_cmsg
, FacilityConfirmationParameter
)},
294 {_CSTRUCT
, offsetof(_cmsg
, Facilitydataarray
)},
296 {_CSTRUCT
, offsetof(_cmsg
, FacilityIndicationParameter
)},
298 {_CSTRUCT
, offsetof(_cmsg
, FacilityRequestParameter
)},
300 {_CWORD
, offsetof(_cmsg
, FacilitySelector
)},
302 {_CWORD
, offsetof(_cmsg
, Flags
)},
304 {_CDWORD
, offsetof(_cmsg
, Function
)},
306 {_CSTRUCT
, offsetof(_cmsg
, HLC
)},
308 {_CWORD
, offsetof(_cmsg
, Info
)},
310 {_CSTRUCT
, offsetof(_cmsg
, InfoElement
)},
312 {_CDWORD
, offsetof(_cmsg
, InfoMask
)},
314 {_CWORD
, offsetof(_cmsg
, InfoNumber
)},
316 {_CSTRUCT
, offsetof(_cmsg
, Keypadfacility
)},
318 {_CSTRUCT
, offsetof(_cmsg
, LLC
)},
320 {_CSTRUCT
, offsetof(_cmsg
, ManuData
)},
322 {_CDWORD
, offsetof(_cmsg
, ManuID
)},
324 {_CSTRUCT
, offsetof(_cmsg
, NCPI
)},
326 {_CWORD
, offsetof(_cmsg
, Reason
)},
328 {_CWORD
, offsetof(_cmsg
, Reason_B3
)},
330 {_CWORD
, offsetof(_cmsg
, Reject
)},
332 {_CSTRUCT
, offsetof(_cmsg
, Useruserdata
)}
335 static unsigned char *cpars
[] =
337 /* ALERT_REQ */ [0x01] = "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
338 /* CONNECT_REQ */ [0x02] = "\x03\x14\x0e\x10\x0f\x11\x0d\x06\x08\x0a\x05\x07\x09\x01\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
339 /* DISCONNECT_REQ */ [0x04] = "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
340 /* LISTEN_REQ */ [0x05] = "\x03\x25\x12\x13\x10\x11\x01",
341 /* INFO_REQ */ [0x08] = "\x03\x0e\x04\x0c\x27\x2f\x1c\x01\x01",
342 /* FACILITY_REQ */ [0x09] = "\x03\x1f\x1e\x01",
343 /* SELECT_B_PROTOCOL_REQ */ [0x0a] = "\x03\x0d\x06\x08\x0a\x05\x07\x09\x01\x01",
344 /* CONNECT_B3_REQ */ [0x0b] = "\x03\x2b\x01",
345 /* DISCONNECT_B3_REQ */ [0x0d] = "\x03\x2b\x01",
346 /* DATA_B3_REQ */ [0x0f] = "\x03\x18\x1a\x19\x20\x01",
347 /* RESET_B3_REQ */ [0x10] = "\x03\x2b\x01",
348 /* ALERT_CONF */ [0x13] = "\x03\x23\x01",
349 /* CONNECT_CONF */ [0x14] = "\x03\x23\x01",
350 /* DISCONNECT_CONF */ [0x16] = "\x03\x23\x01",
351 /* LISTEN_CONF */ [0x17] = "\x03\x23\x01",
352 /* MANUFACTURER_REQ */ [0x18] = "\x03\x2a\x15\x21\x29\x01",
353 /* INFO_CONF */ [0x1a] = "\x03\x23\x01",
354 /* FACILITY_CONF */ [0x1b] = "\x03\x23\x1f\x1b\x01",
355 /* SELECT_B_PROTOCOL_CONF */ [0x1c] = "\x03\x23\x01",
356 /* CONNECT_B3_CONF */ [0x1d] = "\x03\x23\x01",
357 /* DISCONNECT_B3_CONF */ [0x1f] = "\x03\x23\x01",
358 /* DATA_B3_CONF */ [0x21] = "\x03\x19\x23\x01",
359 /* RESET_B3_CONF */ [0x22] = "\x03\x23\x01",
360 /* CONNECT_IND */ [0x26] = "\x03\x14\x0e\x10\x0f\x11\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
361 /* CONNECT_ACTIVE_IND */ [0x27] = "\x03\x16\x17\x28\x01",
362 /* DISCONNECT_IND */ [0x28] = "\x03\x2c\x01",
363 /* MANUFACTURER_CONF */ [0x2a] = "\x03\x2a\x15\x21\x29\x01",
364 /* INFO_IND */ [0x2c] = "\x03\x26\x24\x01",
365 /* FACILITY_IND */ [0x2d] = "\x03\x1f\x1d\x01",
366 /* CONNECT_B3_IND */ [0x2f] = "\x03\x2b\x01",
367 /* CONNECT_B3_ACTIVE_IND */ [0x30] = "\x03\x2b\x01",
368 /* DISCONNECT_B3_IND */ [0x31] = "\x03\x2d\x2b\x01",
369 /* DATA_B3_IND */ [0x33] = "\x03\x18\x1a\x19\x20\x01",
370 /* RESET_B3_IND */ [0x34] = "\x03\x2b\x01",
371 /* CONNECT_B3_T90_ACTIVE_IND */ [0x35] = "\x03\x2b\x01",
372 /* CONNECT_RESP */ [0x38] = "\x03\x2e\x0d\x06\x08\x0a\x05\x07\x09\x01\x16\x17\x28\x04\x0c\x27\x2f\x1c\x01\x01",
373 /* CONNECT_ACTIVE_RESP */ [0x39] = "\x03\x01",
374 /* DISCONNECT_RESP */ [0x3a] = "\x03\x01",
375 /* MANUFACTURER_IND */ [0x3c] = "\x03\x2a\x15\x21\x29\x01",
376 /* INFO_RESP */ [0x3e] = "\x03\x01",
377 /* FACILITY_RESP */ [0x3f] = "\x03\x1f\x01",
378 /* CONNECT_B3_RESP */ [0x41] = "\x03\x2e\x2b\x01",
379 /* CONNECT_B3_ACTIVE_RESP */ [0x42] = "\x03\x01",
380 /* DISCONNECT_B3_RESP */ [0x43] = "\x03\x01",
381 /* DATA_B3_RESP */ [0x45] = "\x03\x19\x01",
382 /* RESET_B3_RESP */ [0x46] = "\x03\x01",
383 /* CONNECT_B3_T90_ACTIVE_RESP */ [0x47] = "\x03\x01",
384 /* MANUFACTURER_RESP */ [0x4e] = "\x03\x2a\x15\x21\x29\x01",
387 /*-------------------------------------------------------*/
389 #define byteTLcpy(x,y) *(u8 *)(x)=*(u8 *)(y);
390 #define wordTLcpy(x,y) *(u16 *)(x)=*(u16 *)(y);
391 #define dwordTLcpy(x,y) memcpy(x,y,4);
392 #define structTLcpy(x,y,l) memcpy (x,y,l)
393 #define structTLcpyovl(x,y,l) memmove (x,y,l)
395 #define byteTRcpy(x,y) *(u8 *)(y)=*(u8 *)(x);
396 #define wordTRcpy(x,y) *(u16 *)(y)=*(u16 *)(x);
397 #define dwordTRcpy(x,y) memcpy(y,x,4);
398 #define structTRcpy(x,y,l) memcpy (y,x,l)
399 #define structTRcpyovl(x,y,l) memmove (y,x,l)
401 /*-------------------------------------------------------*/
402 static unsigned command_2_index(unsigned c
, unsigned sc
)
405 c
= 0x9 + (c
& 0x0f);
411 return (sc
& 3) * (0x9 + 0x9) + c
;
414 /*-------------------------------------------------------*/
415 #define TYP (cdef[cmsg->par[cmsg->p]].typ)
416 #define OFF (((u8 *)cmsg)+cdef[cmsg->par[cmsg->p]].off)
418 static void jumpcstruct(_cmsg
* cmsg
)
421 for (cmsg
->p
++, layer
= 1; layer
;) {
422 /* $$$$$ assert (cmsg->p); */
434 /*-------------------------------------------------------*/
435 static void pars_2_message(_cmsg
* cmsg
)
438 for (; TYP
!= _CEND
; cmsg
->p
++) {
441 byteTLcpy(cmsg
->m
+ cmsg
->l
, OFF
);
445 wordTLcpy(cmsg
->m
+ cmsg
->l
, OFF
);
449 dwordTLcpy(cmsg
->m
+ cmsg
->l
, OFF
);
453 if (*(u8
**) OFF
== NULL
) {
454 *(cmsg
->m
+ cmsg
->l
) = '\0';
456 } else if (**(_cstruct
*) OFF
!= 0xff) {
457 structTLcpy(cmsg
->m
+ cmsg
->l
, *(_cstruct
*) OFF
, 1 + **(_cstruct
*) OFF
);
458 cmsg
->l
+= 1 + **(_cstruct
*) OFF
;
460 _cstruct s
= *(_cstruct
*) OFF
;
461 structTLcpy(cmsg
->m
+ cmsg
->l
, s
, 3 + *(u16
*) (s
+ 1));
462 cmsg
->l
+= 3 + *(u16
*) (s
+ 1);
466 /*----- Metastruktur 0 -----*/
467 if (*(_cmstruct
*) OFF
== CAPI_DEFAULT
) {
468 *(cmsg
->m
+ cmsg
->l
) = '\0';
472 /*----- Metastruktur wird composed -----*/
474 unsigned _l
= cmsg
->l
;
478 pars_2_message(cmsg
);
479 _ls
= cmsg
->l
- _l
- 1;
481 (cmsg
->m
+ _l
)[0] = (u8
) _ls
;
483 structTLcpyovl(cmsg
->m
+ _l
+ 3, cmsg
->m
+ _l
+ 1, _ls
);
484 (cmsg
->m
+ _l
)[0] = 0xff;
485 wordTLcpy(cmsg
->m
+ _l
+ 1, &_ls
);
493 /*-------------------------------------------------------*/
494 unsigned capi_cmsg2message(_cmsg
* cmsg
, u8
* msg
)
499 cmsg
->par
= cpars
[command_2_index(cmsg
->Command
, cmsg
->Subcommand
)];
501 pars_2_message(cmsg
);
503 wordTLcpy(msg
+ 0, &cmsg
->l
);
504 byteTLcpy(cmsg
->m
+ 4, &cmsg
->Command
);
505 byteTLcpy(cmsg
->m
+ 5, &cmsg
->Subcommand
);
506 wordTLcpy(cmsg
->m
+ 2, &cmsg
->ApplId
);
507 wordTLcpy(cmsg
->m
+ 6, &cmsg
->Messagenumber
);
512 /*-------------------------------------------------------*/
513 static void message_2_pars(_cmsg
* cmsg
)
515 for (; TYP
!= _CEND
; cmsg
->p
++) {
519 byteTRcpy(cmsg
->m
+ cmsg
->l
, OFF
);
523 wordTRcpy(cmsg
->m
+ cmsg
->l
, OFF
);
527 dwordTRcpy(cmsg
->m
+ cmsg
->l
, OFF
);
531 *(u8
**) OFF
= cmsg
->m
+ cmsg
->l
;
533 if (cmsg
->m
[cmsg
->l
] != 0xff)
534 cmsg
->l
+= 1 + cmsg
->m
[cmsg
->l
];
536 cmsg
->l
+= 3 + *(u16
*) (cmsg
->m
+ cmsg
->l
+ 1);
539 /*----- Metastruktur 0 -----*/
540 if (cmsg
->m
[cmsg
->l
] == '\0') {
541 *(_cmstruct
*) OFF
= CAPI_DEFAULT
;
545 unsigned _l
= cmsg
->l
;
546 *(_cmstruct
*) OFF
= CAPI_COMPOSE
;
547 cmsg
->l
= (cmsg
->m
+ _l
)[0] == 255 ? cmsg
->l
+ 3 : cmsg
->l
+ 1;
549 message_2_pars(cmsg
);
556 /*-------------------------------------------------------*/
557 unsigned capi_message2cmsg(_cmsg
* cmsg
, u8
* msg
)
559 memset(cmsg
, 0, sizeof(_cmsg
));
563 byteTRcpy(cmsg
->m
+ 4, &cmsg
->Command
);
564 byteTRcpy(cmsg
->m
+ 5, &cmsg
->Subcommand
);
565 cmsg
->par
= cpars
[command_2_index(cmsg
->Command
, cmsg
->Subcommand
)];
567 message_2_pars(cmsg
);
569 wordTRcpy(msg
+ 0, &cmsg
->l
);
570 wordTRcpy(cmsg
->m
+ 2, &cmsg
->ApplId
);
571 wordTRcpy(cmsg
->m
+ 6, &cmsg
->Messagenumber
);
576 /*-------------------------------------------------------*/
577 unsigned capi_cmsg_header(_cmsg
* cmsg
, u16 _ApplId
,
578 u8 _Command
, u8 _Subcommand
,
579 u16 _Messagenumber
, u32 _Controller
)
581 memset(cmsg
, 0, sizeof(_cmsg
));
582 cmsg
->ApplId
= _ApplId
;
583 cmsg
->Command
= _Command
;
584 cmsg
->Subcommand
= _Subcommand
;
585 cmsg
->Messagenumber
= _Messagenumber
;
586 cmsg
->adr
.adrController
= _Controller
;
590 /*-------------------------------------------------------*/
592 static char *mnames
[] =
594 [0x01] = "ALERT_REQ",
595 [0x02] = "CONNECT_REQ",
596 [0x04] = "DISCONNECT_REQ",
597 [0x05] = "LISTEN_REQ",
599 [0x09] = "FACILITY_REQ",
600 [0x0a] = "SELECT_B_PROTOCOL_REQ",
601 [0x0b] = "CONNECT_B3_REQ",
602 [0x0d] = "DISCONNECT_B3_REQ",
603 [0x0f] = "DATA_B3_REQ",
604 [0x10] = "RESET_B3_REQ",
605 [0x13] = "ALERT_CONF",
606 [0x14] = "CONNECT_CONF",
607 [0x16] = "DISCONNECT_CONF",
608 [0x17] = "LISTEN_CONF",
609 [0x18] = "MANUFACTURER_REQ",
610 [0x1a] = "INFO_CONF",
611 [0x1b] = "FACILITY_CONF",
612 [0x1c] = "SELECT_B_PROTOCOL_CONF",
613 [0x1d] = "CONNECT_B3_CONF",
614 [0x1f] = "DISCONNECT_B3_CONF",
615 [0x21] = "DATA_B3_CONF",
616 [0x22] = "RESET_B3_CONF",
617 [0x26] = "CONNECT_IND",
618 [0x27] = "CONNECT_ACTIVE_IND",
619 [0x28] = "DISCONNECT_IND",
620 [0x2a] = "MANUFACTURER_CONF",
622 [0x2d] = "FACILITY_IND",
623 [0x2f] = "CONNECT_B3_IND",
624 [0x30] = "CONNECT_B3_ACTIVE_IND",
625 [0x31] = "DISCONNECT_B3_IND",
626 [0x33] = "DATA_B3_IND",
627 [0x34] = "RESET_B3_IND",
628 [0x35] = "CONNECT_B3_T90_ACTIVE_IND",
629 [0x38] = "CONNECT_RESP",
630 [0x39] = "CONNECT_ACTIVE_RESP",
631 [0x3a] = "DISCONNECT_RESP",
632 [0x3c] = "MANUFACTURER_IND",
633 [0x3e] = "INFO_RESP",
634 [0x3f] = "FACILITY_RESP",
635 [0x41] = "CONNECT_B3_RESP",
636 [0x42] = "CONNECT_B3_ACTIVE_RESP",
637 [0x43] = "DISCONNECT_B3_RESP",
638 [0x45] = "DATA_B3_RESP",
639 [0x46] = "RESET_B3_RESP",
640 [0x47] = "CONNECT_B3_T90_ACTIVE_RESP",
641 [0x4e] = "MANUFACTURER_RESP"
644 char *capi_cmd2str(u8 cmd
, u8 subcmd
)
646 return mnames
[command_2_index(cmd
, subcmd
)];
650 /*-------------------------------------------------------*/
652 #ifdef CONFIG_CAPI_TRACE
654 /*-------------------------------------------------------*/
656 static char *pnames
[] =
661 /*03 */ "Controller/PLCI/NCCI",
662 /*04 */ "AdditionalInfo",
663 /*05 */ "B1configuration",
664 /*06 */ "B1protocol",
665 /*07 */ "B2configuration",
666 /*08 */ "B2protocol",
667 /*09 */ "B3configuration",
668 /*0a */ "B3protocol",
670 /*0c */ "BChannelinformation",
672 /*0e */ "CalledPartyNumber",
673 /*0f */ "CalledPartySubaddress",
674 /*10 */ "CallingPartyNumber",
675 /*11 */ "CallingPartySubaddress",
680 /*16 */ "ConnectedNumber",
681 /*17 */ "ConnectedSubaddress",
683 /*19 */ "DataHandle",
684 /*1a */ "DataLength",
685 /*1b */ "FacilityConfirmationParameter",
686 /*1c */ "Facilitydataarray",
687 /*1d */ "FacilityIndicationParameter",
688 /*1e */ "FacilityRequestParameter",
689 /*1f */ "FacilitySelector",
694 /*24 */ "InfoElement",
696 /*26 */ "InfoNumber",
697 /*27 */ "Keypadfacility",
705 /*2f */ "Useruserdata"
712 /*-------------------------------------------------------*/
713 static _cdebbuf
*bufprint(_cdebbuf
*cdb
, char *fmt
,...)
721 r
= cdb
->size
- cdb
->pos
;
722 n
= vsnprintf(cdb
->p
, r
, fmt
, f
);
725 /* truncated, need bigger buffer */
726 size_t ns
= 2 * cdb
->size
;
729 while ((ns
- cdb
->pos
) <= n
)
731 nb
= kmalloc(ns
, GFP_ATOMIC
);
736 memcpy(nb
, cdb
->buf
, cdb
->pos
);
740 cdb
->p
= cdb
->buf
+ cdb
->pos
;
743 r
= cdb
->size
- cdb
->pos
;
744 n
= vsnprintf(cdb
->p
, r
, fmt
, f
);
752 static _cdebbuf
*printstructlen(_cdebbuf
*cdb
, u8
* m
, unsigned len
)
758 for (; len
; len
--, m
++)
759 if (isalnum(*m
) || *m
== ' ') {
761 cdb
= bufprint(cdb
, ">");
762 cdb
= bufprint(cdb
, "%c", *m
);
766 cdb
= bufprint(cdb
, "<%02x", *m
);
768 cdb
= bufprint(cdb
, " %02x", *m
);
772 cdb
= bufprint(cdb
, ">");
776 static _cdebbuf
*printstruct(_cdebbuf
*cdb
, u8
* m
)
784 len
= ((u16
*) (m
+ 1))[0];
787 cdb
= printstructlen(cdb
, m
, len
);
791 /*-------------------------------------------------------*/
792 #define NAME (pnames[cmsg->par[cmsg->p]])
794 static _cdebbuf
*protocol_message_2_pars(_cdebbuf
*cdb
, _cmsg
*cmsg
, int level
)
796 for (; TYP
!= _CEND
; cmsg
->p
++) {
797 int slen
= 29 + 3 - level
;
802 cdb
= bufprint(cdb
, " ");
803 for (i
= 0; i
< level
- 1; i
++)
804 cdb
= bufprint(cdb
, " ");
808 cdb
= bufprint(cdb
, "%-*s = 0x%x\n", slen
, NAME
, *(u8
*) (cmsg
->m
+ cmsg
->l
));
812 cdb
= bufprint(cdb
, "%-*s = 0x%x\n", slen
, NAME
, *(u16
*) (cmsg
->m
+ cmsg
->l
));
816 cdb
= bufprint(cdb
, "%-*s = 0x%lx\n", slen
, NAME
, *(u32
*) (cmsg
->m
+ cmsg
->l
));
820 cdb
= bufprint(cdb
, "%-*s = ", slen
, NAME
);
821 if (cmsg
->m
[cmsg
->l
] == '\0')
822 cdb
= bufprint(cdb
, "default");
824 cdb
= printstruct(cdb
, cmsg
->m
+ cmsg
->l
);
825 cdb
= bufprint(cdb
, "\n");
826 if (cmsg
->m
[cmsg
->l
] != 0xff)
827 cmsg
->l
+= 1 + cmsg
->m
[cmsg
->l
];
829 cmsg
->l
+= 3 + *(u16
*) (cmsg
->m
+ cmsg
->l
+ 1);
834 /*----- Metastruktur 0 -----*/
835 if (cmsg
->m
[cmsg
->l
] == '\0') {
836 cdb
= bufprint(cdb
, "%-*s = default\n", slen
, NAME
);
841 unsigned _l
= cmsg
->l
;
842 cdb
= bufprint(cdb
, "%-*s\n", slen
, name
);
843 cmsg
->l
= (cmsg
->m
+ _l
)[0] == 255 ? cmsg
->l
+ 3 : cmsg
->l
+ 1;
845 cdb
= protocol_message_2_pars(cdb
, cmsg
, level
+ 1);
852 /*-------------------------------------------------------*/
854 static _cdebbuf
*g_debbuf
;
855 static u_long g_debbuf_lock
;
856 static _cmsg
*g_cmsg
;
858 static _cdebbuf
*cdebbuf_alloc(void)
862 if (likely(!test_and_set_bit(1, &g_debbuf_lock
))) {
866 cdb
= kmalloc(sizeof(_cdebbuf
), GFP_ATOMIC
);
869 cdb
->buf
= kmalloc(CDEBUG_SIZE
, GFP_ATOMIC
);
874 cdb
->size
= CDEBUG_SIZE
;
882 void cdebbuf_free(_cdebbuf
*cdb
)
884 if (likely(cdb
== g_debbuf
)) {
885 test_and_clear_bit(1, &g_debbuf_lock
);
894 _cdebbuf
*capi_message2str(u8
* msg
)
899 cdb
= cdebbuf_alloc();
902 if (likely(cdb
== g_debbuf
))
905 cmsg
= kmalloc(sizeof(_cmsg
), GFP_ATOMIC
);
906 if (unlikely(!cmsg
)) {
913 byteTRcpy(cmsg
->m
+ 4, &cmsg
->Command
);
914 byteTRcpy(cmsg
->m
+ 5, &cmsg
->Subcommand
);
915 cmsg
->par
= cpars
[command_2_index(cmsg
->Command
, cmsg
->Subcommand
)];
917 cdb
= bufprint(cdb
, "%-26s ID=%03d #0x%04x LEN=%04d\n",
918 mnames
[command_2_index(cmsg
->Command
, cmsg
->Subcommand
)],
919 ((unsigned short *) msg
)[1],
920 ((unsigned short *) msg
)[3],
921 ((unsigned short *) msg
)[0]);
923 cdb
= protocol_message_2_pars(cdb
, cmsg
, 1);
924 if (unlikely(cmsg
!= g_cmsg
))
929 _cdebbuf
*capi_cmsg2str(_cmsg
* cmsg
)
933 cdb
= cdebbuf_alloc();
938 cdb
= bufprint(cdb
, "%s ID=%03d #0x%04x LEN=%04d\n",
939 mnames
[command_2_index(cmsg
->Command
, cmsg
->Subcommand
)],
940 ((u16
*) cmsg
->m
)[1],
941 ((u16
*) cmsg
->m
)[3],
942 ((u16
*) cmsg
->m
)[0]);
943 cdb
= protocol_message_2_pars(cdb
, cmsg
, 1);
947 int __init
cdebug_init(void)
949 g_cmsg
= kmalloc(sizeof(_cmsg
), GFP_KERNEL
);
952 g_debbuf
= kmalloc(sizeof(_cdebbuf
), GFP_KERNEL
);
957 g_debbuf
->buf
= kmalloc(CDEBUG_GSIZE
, GFP_KERNEL
);
958 if (!g_debbuf
->buf
) {
963 g_debbuf
->size
= CDEBUG_GSIZE
;
964 g_debbuf
->buf
[0] = 0;
965 g_debbuf
->p
= g_debbuf
->buf
;
970 void __exit
cdebug_exit(void)
973 kfree(g_debbuf
->buf
);
978 #else /* !CONFIG_CAPI_TRACE */
980 static _cdebbuf g_debbuf
= {"CONFIG_CAPI_TRACE not enabled", NULL
, 0, 0};
982 _cdebbuf
*capi_message2str(u8
* msg
)
987 _cdebbuf
*capi_cmsg2str(_cmsg
* cmsg
)
992 void cdebbuf_free(_cdebbuf
*cdb
)
996 int __init
cdebug_init(void)
1001 void __exit
cdebug_exit(void)
1007 EXPORT_SYMBOL(cdebbuf_free
);
1008 EXPORT_SYMBOL(capi_cmsg2message
);
1009 EXPORT_SYMBOL(capi_message2cmsg
);
1010 EXPORT_SYMBOL(capi_cmsg_header
);
1011 EXPORT_SYMBOL(capi_cmd2str
);
1012 EXPORT_SYMBOL(capi_cmsg2str
);
1013 EXPORT_SYMBOL(capi_message2str
);
1014 EXPORT_SYMBOL(capi_info2str
);