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>
21 #include <linux/slab.h>
25 #ifndef CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON
37 return "NCPI not supported by current protocol, NCPI ignored";
39 return "Flags not supported by current protocol, flags ignored";
41 return "Alert already sent by another application";
45 return "Too many applications";
47 return "Logical block size too small, must be at least 128 Bytes";
49 return "Buffer exceeds 64 kByte";
51 return "Message buffer size too small, must be at least 1024 Bytes";
53 return "Max. number of logical connections not supported";
57 return "The message could not be accepted because of an internal busy condition";
59 return "OS resource error (no memory ?)";
61 return "CAPI not installed";
63 return "Controller does not support external equipment";
65 return "Controller does only support external equipment";
69 return "Illegal application number";
71 return "Illegal command or subcommand or message length less than 12 bytes";
73 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";
75 return "Queue is empty";
77 return "Queue overflow, a message was lost !! This indicates a configuration error. The only recovery from this error is to perform a CAPI_RELEASE";
79 return "Unknown notification parameter";
81 return "The Message could not be accepted because of an internal busy condition";
83 return "OS Resource error (no memory ?)";
85 return "CAPI not installed";
87 return "Controller does not support external equipment";
89 return "Controller does only support external equipment";
93 return "Message not supported in current state";
95 return "Illegal Controller / PLCI / NCCI";
101 return "Out of LISTEN";
103 return "Out of FAX resources (protocol T.30)";
105 return "Illegal message parameter coding";
109 return "B1 protocol not supported";
111 return "B2 protocol not supported";
113 return "B3 protocol not supported";
115 return "B1 protocol parameter not supported";
117 return "B2 protocol parameter not supported";
119 return "B3 protocol parameter not supported";
121 return "B protocol combination not supported";
123 return "NCPI not supported";
125 return "CIP Value unknown";
127 return "Flags not supported (reserved bits)";
129 return "Facility not supported";
131 return "Data length not supported by current protocol";
133 return "Reset procedure not supported by current protocol";
137 return "Protocol error layer 1 (broken line or B-channel removed by signalling protocol)";
139 return "Protocol error layer 2";
141 return "Protocol error layer 3";
143 return "Another application got that call";
146 return "Connecting not successful (remote station is no FAX G3 machine)";
148 return "Connecting not successful (training error)";
150 return "Disconnected before transfer (remote station does not support transfer mode, e.g. resolution)";
152 return "Disconnected during transfer (remote abort)";
154 return "Disconnected during transfer (remote procedure error, e.g. unsuccessful repetition of T.30 commands)";
156 return "Disconnected during transfer (local tx data underrun)";
158 return "Disconnected during transfer (local rx data overflow)";
160 return "Disconnected during transfer (local abort)";
162 return "Illegal parameter coding (e.g. SFF coding error)";
165 case 0x3481:
return "Unallocated (unassigned) number";
166 case 0x3482:
return "No route to specified transit network";
167 case 0x3483:
return "No route to destination";
168 case 0x3486:
return "Channel unacceptable";
170 return "Call awarded and being delivered in an established channel";
171 case 0x3490:
return "Normal call clearing";
172 case 0x3491:
return "User busy";
173 case 0x3492:
return "No user responding";
174 case 0x3493:
return "No answer from user (user alerted)";
175 case 0x3495:
return "Call rejected";
176 case 0x3496:
return "Number changed";
177 case 0x349A:
return "Non-selected user clearing";
178 case 0x349B:
return "Destination out of order";
179 case 0x349C:
return "Invalid number format";
180 case 0x349D:
return "Facility rejected";
181 case 0x349E:
return "Response to STATUS ENQUIRY";
182 case 0x349F:
return "Normal, unspecified";
183 case 0x34A2:
return "No circuit / channel available";
184 case 0x34A6:
return "Network out of order";
185 case 0x34A9:
return "Temporary failure";
186 case 0x34AA:
return "Switching equipment congestion";
187 case 0x34AB:
return "Access information discarded";
188 case 0x34AC:
return "Requested circuit / channel not available";
189 case 0x34AF:
return "Resources unavailable, unspecified";
190 case 0x34B1:
return "Quality of service unavailable";
191 case 0x34B2:
return "Requested facility not subscribed";
192 case 0x34B9:
return "Bearer capability not authorized";
193 case 0x34BA:
return "Bearer capability not presently available";
194 case 0x34BF:
return "Service or option not available, unspecified";
195 case 0x34C1:
return "Bearer capability not implemented";
196 case 0x34C2:
return "Channel type not implemented";
197 case 0x34C5:
return "Requested facility not implemented";
198 case 0x34C6:
return "Only restricted digital information bearer capability is available";
199 case 0x34CF:
return "Service or option not implemented, unspecified";
200 case 0x34D1:
return "Invalid call reference value";
201 case 0x34D2:
return "Identified channel does not exist";
202 case 0x34D3:
return "A suspended call exists, but this call identity does not";
203 case 0x34D4:
return "Call identity in use";
204 case 0x34D5:
return "No call suspended";
205 case 0x34D6:
return "Call having the requested call identity has been cleared";
206 case 0x34D8:
return "Incompatible destination";
207 case 0x34DB:
return "Invalid transit network selection";
208 case 0x34DF:
return "Invalid message, unspecified";
209 case 0x34E0:
return "Mandatory information element is missing";
210 case 0x34E1:
return "Message type non-existent or not implemented";
211 case 0x34E2:
return "Message not compatible with call state or message type non-existent or not implemented";
212 case 0x34E3:
return "Information element non-existent or not implemented";
213 case 0x34E4:
return "Invalid information element contents";
214 case 0x34E5:
return "Message not compatible with call state";
215 case 0x34E6:
return "Recovery on timer expiry";
216 case 0x34EF:
return "Protocol error, unspecified";
217 case 0x34FF:
return "Interworking, unspecified";
219 default:
return "No additional information";
236 static _cdef cdef[] =
336 static unsigned char *cpars[] =
338 [0x01] =
"\x03\x04\x0c\x27\x2f\x1c\x01\x01",
339 [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",
340 [0x04] =
"\x03\x04\x0c\x27\x2f\x1c\x01\x01",
341 [0x05] =
"\x03\x25\x12\x13\x10\x11\x01",
342 [0x08] =
"\x03\x0e\x04\x0c\x27\x2f\x1c\x01\x01",
343 [0x09] =
"\x03\x1f\x1e\x01",
344 [0x0a] =
"\x03\x0d\x06\x08\x0a\x05\x07\x09\x01\x01",
345 [0x0b] =
"\x03\x2b\x01",
346 [0x0d] =
"\x03\x2b\x01",
347 [0x0f] =
"\x03\x18\x1a\x19\x20\x01",
348 [0x10] =
"\x03\x2b\x01",
349 [0x13] =
"\x03\x23\x01",
350 [0x14] =
"\x03\x23\x01",
351 [0x16] =
"\x03\x23\x01",
352 [0x17] =
"\x03\x23\x01",
353 [0x18] =
"\x03\x2a\x15\x21\x29\x01",
354 [0x1a] =
"\x03\x23\x01",
355 [0x1b] =
"\x03\x23\x1f\x1b\x01",
356 [0x1c] =
"\x03\x23\x01",
357 [0x1d] =
"\x03\x23\x01",
358 [0x1f] =
"\x03\x23\x01",
359 [0x21] =
"\x03\x19\x23\x01",
360 [0x22] =
"\x03\x23\x01",
361 [0x26] =
"\x03\x14\x0e\x10\x0f\x11\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
362 [0x27] =
"\x03\x16\x17\x28\x01",
363 [0x28] =
"\x03\x2c\x01",
364 [0x2a] =
"\x03\x2a\x15\x21\x29\x01",
365 [0x2c] =
"\x03\x26\x24\x01",
366 [0x2d] =
"\x03\x1f\x1d\x01",
367 [0x2f] =
"\x03\x2b\x01",
368 [0x30] =
"\x03\x2b\x01",
369 [0x31] =
"\x03\x2d\x2b\x01",
370 [0x33] =
"\x03\x18\x1a\x19\x20\x01",
371 [0x34] =
"\x03\x2b\x01",
372 [0x35] =
"\x03\x2b\x01",
373 [0x38] =
"\x03\x2e\x0d\x06\x08\x0a\x05\x07\x09\x01\x16\x17\x28\x04\x0c\x27\x2f\x1c\x01\x01",
376 [0x3c] =
"\x03\x2a\x15\x21\x29\x01",
378 [0x3f] =
"\x03\x1f\x01",
379 [0x41] =
"\x03\x2e\x2b\x01",
382 [0x45] =
"\x03\x19\x01",
385 [0x4e] =
"\x03\x2a\x15\x21\x29\x01",
390 #define byteTLcpy(x, y) *(u8 *)(x) = *(u8 *)(y);
391 #define wordTLcpy(x, y) *(u16 *)(x) = *(u16 *)(y);
392 #define dwordTLcpy(x, y) memcpy(x, y, 4);
393 #define structTLcpy(x, y, l) memcpy(x, y, l)
394 #define structTLcpyovl(x, y, l) memmove(x, y, l)
396 #define byteTRcpy(x, y) *(u8 *)(y) = *(u8 *)(x);
397 #define wordTRcpy(x, y) *(u16 *)(y) = *(u16 *)(x);
398 #define dwordTRcpy(x, y) memcpy(y, x, 4);
399 #define structTRcpy(x, y, l) memcpy(y, x, l)
400 #define structTRcpyovl(x, y, l) memmove(y, x, l)
403 static unsigned command_2_index(
unsigned c,
unsigned sc)
406 c = 0x9 + (c & 0x0f);
412 return (sc & 3) * (0x9 + 0x9) + c;
416 #define TYP (cdef[cmsg->par[cmsg->p]].typ)
417 #define OFF (((u8 *)cmsg) + cdef[cmsg->par[cmsg->p]].off)
419 static void jumpcstruct(
_cmsg *cmsg)
422 for (cmsg->
p++, layer = 1; layer;) {
436 static void pars_2_message(
_cmsg *cmsg)
455 *(cmsg->
m + cmsg->
l) =
'\0';
463 cmsg->
l += 3 + *(
u16 *) (s + 1);
469 *(cmsg->
m + cmsg->
l) =
'\0';
475 unsigned _l = cmsg->
l;
479 pars_2_message(cmsg);
480 _ls = cmsg->
l - _l - 1;
482 (cmsg->
m + _l)[0] = (
u8) _ls;
485 (cmsg->
m + _l)[0] = 0xff;
509 pars_2_message(cmsg);
521 static void message_2_pars(
_cmsg *cmsg)
539 *(
u8 **)
OFF = cmsg->
m + cmsg->
l;
541 if (cmsg->
m[cmsg->
l] != 0xff)
542 cmsg->
l += 1 + cmsg->
m[cmsg->
l];
544 cmsg->
l += 3 + *(
u16 *) (cmsg->
m + cmsg->
l + 1);
548 if (cmsg->
m[cmsg->
l] ==
'\0') {
553 unsigned _l = cmsg->
l;
555 cmsg->
l = (cmsg->
m + _l)[0] == 255 ? cmsg->
l + 3 : cmsg->
l + 1;
557 message_2_pars(cmsg);
582 message_2_pars(cmsg);
604 u8 _Command,
u8 _Subcommand,
605 u16 _Messagenumber,
u32 _Controller)
618 static char *mnames[] =
620 [0x01] =
"ALERT_REQ",
621 [0x02] =
"CONNECT_REQ",
622 [0x04] =
"DISCONNECT_REQ",
623 [0x05] =
"LISTEN_REQ",
625 [0x09] =
"FACILITY_REQ",
626 [0x0a] =
"SELECT_B_PROTOCOL_REQ",
627 [0x0b] =
"CONNECT_B3_REQ",
628 [0x0d] =
"DISCONNECT_B3_REQ",
629 [0x0f] =
"DATA_B3_REQ",
630 [0x10] =
"RESET_B3_REQ",
631 [0x13] =
"ALERT_CONF",
632 [0x14] =
"CONNECT_CONF",
633 [0x16] =
"DISCONNECT_CONF",
634 [0x17] =
"LISTEN_CONF",
635 [0x18] =
"MANUFACTURER_REQ",
636 [0x1a] =
"INFO_CONF",
637 [0x1b] =
"FACILITY_CONF",
638 [0x1c] =
"SELECT_B_PROTOCOL_CONF",
639 [0x1d] =
"CONNECT_B3_CONF",
640 [0x1f] =
"DISCONNECT_B3_CONF",
641 [0x21] =
"DATA_B3_CONF",
642 [0x22] =
"RESET_B3_CONF",
643 [0x26] =
"CONNECT_IND",
644 [0x27] =
"CONNECT_ACTIVE_IND",
645 [0x28] =
"DISCONNECT_IND",
646 [0x2a] =
"MANUFACTURER_CONF",
648 [0x2d] =
"FACILITY_IND",
649 [0x2f] =
"CONNECT_B3_IND",
650 [0x30] =
"CONNECT_B3_ACTIVE_IND",
651 [0x31] =
"DISCONNECT_B3_IND",
652 [0x33] =
"DATA_B3_IND",
653 [0x34] =
"RESET_B3_IND",
654 [0x35] =
"CONNECT_B3_T90_ACTIVE_IND",
655 [0x38] =
"CONNECT_RESP",
656 [0x39] =
"CONNECT_ACTIVE_RESP",
657 [0x3a] =
"DISCONNECT_RESP",
658 [0x3c] =
"MANUFACTURER_IND",
659 [0x3e] =
"INFO_RESP",
660 [0x3f] =
"FACILITY_RESP",
661 [0x41] =
"CONNECT_B3_RESP",
662 [0x42] =
"CONNECT_B3_ACTIVE_RESP",
663 [0x43] =
"DISCONNECT_B3_RESP",
664 [0x45] =
"DATA_B3_RESP",
665 [0x46] =
"RESET_B3_RESP",
666 [0x47] =
"CONNECT_B3_T90_ACTIVE_RESP",
667 [0x4e] =
"MANUFACTURER_RESP"
680 return mnames[command_2_index(cmd, subcmd)];
686 #ifdef CONFIG_CAPI_TRACE
690 static char *pnames[] =
695 "Controller/PLCI/NCCI",
704 "BChannelinformation",
707 "CalledPartySubaddress",
708 "CallingPartyNumber",
709 "CallingPartySubaddress",
715 "ConnectedSubaddress",
719 "FacilityConfirmationParameter",
721 "FacilityIndicationParameter",
722 "FacilityRequestParameter",
760 size_t ns = 2 * cdb->
size;
763 while ((ns - cdb->
pos) <= n)
792 for (; len; len--, m++)
793 if (
isalnum(*m) || *m ==
' ') {
795 cdb = bufprint(cdb,
">");
796 cdb = bufprint(cdb,
"%c", *m);
800 cdb = bufprint(cdb,
"<%02x", *m);
802 cdb = bufprint(cdb,
" %02x", *m);
806 cdb = bufprint(cdb,
">");
818 len = ((
u16 *) (m + 1))[0];
821 cdb = printstructlen(cdb, m, len);
826 #define NAME (pnames[cmsg->par[cmsg->p]])
831 int slen = 29 + 3 -
level;
836 cdb = bufprint(cdb,
" ");
837 for (i = 0; i < level - 1; i++)
838 cdb = bufprint(cdb,
" ");
842 cdb = bufprint(cdb,
"%-*s = 0x%x\n", slen,
NAME, *(
u8 *) (cmsg->
m + cmsg->
l));
846 cdb = bufprint(cdb,
"%-*s = 0x%x\n", slen,
NAME, *(
u16 *) (cmsg->
m + cmsg->
l));
850 cdb = bufprint(cdb,
"%-*s = 0x%lx\n", slen,
NAME, *(
u32 *) (cmsg->
m + cmsg->
l));
854 cdb = bufprint(cdb,
"%-*s = ", slen,
NAME);
855 if (cmsg->
m[cmsg->
l] ==
'\0')
856 cdb = bufprint(cdb,
"default");
858 cdb = printstruct(cdb, cmsg->
m + cmsg->
l);
859 cdb = bufprint(cdb,
"\n");
860 if (cmsg->
m[cmsg->
l] != 0xff)
861 cmsg->
l += 1 + cmsg->
m[cmsg->
l];
863 cmsg->
l += 3 + *(
u16 *) (cmsg->
m + cmsg->
l + 1);
869 if (cmsg->
m[cmsg->
l] ==
'\0') {
870 cdb = bufprint(cdb,
"%-*s = default\n", slen,
NAME);
875 unsigned _l = cmsg->
l;
876 cdb = bufprint(cdb,
"%-*s\n", slen, name);
877 cmsg->
l = (cmsg->
m + _l)[0] == 255 ? cmsg->
l + 3 : cmsg->
l + 1;
879 cdb = protocol_message_2_pars(cdb, cmsg, level + 1);
889 static u_long g_debbuf_lock;
890 static _cmsg *g_cmsg;
892 static _cdebbuf *cdebbuf_alloc(
void)
923 if (
likely(cdb == g_debbuf)) {
948 cdb = cdebbuf_alloc();
951 if (
likely(cdb == g_debbuf))
966 cdb = bufprint(cdb,
"%-26s ID=%03d #0x%04x LEN=%04d\n",
968 ((
unsigned short *) msg)[1],
969 ((
unsigned short *) msg)[3],
970 ((
unsigned short *) msg)[0]);
972 cdb = protocol_message_2_pars(cdb, cmsg, 1);
995 cdb = cdebbuf_alloc();
1000 cdb = bufprint(cdb,
"%s ID=%03d #0x%04x LEN=%04d\n",
1002 ((
u16 *) cmsg->
m)[1],
1003 ((
u16 *) cmsg->
m)[3],
1004 ((
u16 *) cmsg->
m)[0]);
1005 cdb = protocol_message_2_pars(cdb, cmsg, 1);
1020 if (!g_debbuf->
buf) {
1026 g_debbuf->
buf[0] = 0;
1027 g_debbuf->
p = g_debbuf->
buf;
1042 static _cdebbuf g_debbuf = {
"CONFIG_CAPI_TRACE not enabled",
NULL, 0, 0};