2 * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * 1tr6.c - print 1TR6 protocol traces
28 * -----------------------------------
30 * $Id: 1tr6.c,v 1.3 2003/10/06 09:43:28 itojun Exp $
34 * last edit-date: [Mon Dec 13 21:55:31 1999]
36 *---------------------------------------------------------------------------*/
40 static int p_1tr6address(char *pbuf
, unsigned char buf
[]);
41 static int p_1tr6cause(char *pbuf
, unsigned char buf
[]);
43 /*---------------------------------------------------------------------------*
44 * decode the (german) national specific 1TR6 protocol
45 *---------------------------------------------------------------------------*/
47 decode_1tr6(char *pbuf
, int n
, int off
, unsigned char *buf
, int raw
)
65 for (i
= 0; i
< n
; i
+= 16)
67 sprintf((pbuf
+strlen(pbuf
)),"Dump:%.3d ", i
+off
);
68 for (j
= 0; j
< 16; j
++)
70 sprintf((pbuf
+strlen(pbuf
)),"%02x ", buf
[i
+ j
]);
72 sprintf((pbuf
+strlen(pbuf
))," ");
73 sprintf((pbuf
+strlen(pbuf
))," ");
74 for (j
= 0; j
< 16 && i
+ j
< n
; j
++)
75 if (isprint(buf
[i
+ j
]))
76 sprintf((pbuf
+strlen(pbuf
)),"%c", buf
[i
+ j
]);
78 sprintf((pbuf
+strlen(pbuf
)),".");
79 sprintf((pbuf
+strlen(pbuf
)),"\n");
83 sprintf((pbuf
+strlen(pbuf
)), "1TR6: ");
85 /* protocol discriminator */
94 sprintf((pbuf
+strlen(pbuf
)), "pd=N0, ");
97 sprintf((pbuf
+strlen(pbuf
)), "pd=N1, ");
100 sprintf((pbuf
+strlen(pbuf
)), "pd=UNDEF (0x%02x), ",pd
);
113 sprintf((pbuf
+strlen(pbuf
)), "cr=0x%02x %s, ", (buf
[i
+1] & 0x7f), (buf
[i
+1] & 0x80) ? "(from destination)" : "(from origination)");
116 sprintf((pbuf
+strlen(pbuf
)), "cr: LEN=%d %s 0x%02x 0x%02x, ", len
, (buf
[i
+1] & 0x80) ? "org" : "dst", (buf
[i
+1] & 0x7f), (buf
[i
+2] & 0x7f));
124 sprintf((pbuf
+strlen(pbuf
)), "message=");
126 if (pd
== 0x40) /* protocol discriminator N0 */
131 sprintf((pbuf
+strlen(pbuf
)), "REGISTER INDICATION: ");
134 sprintf((pbuf
+strlen(pbuf
)), "CANCEL INDICATION: ");
137 sprintf((pbuf
+strlen(pbuf
)), "FACILITY STATUS: ");
140 sprintf((pbuf
+strlen(pbuf
)), "STATUS ACKNOWLEDGE: ");
143 sprintf((pbuf
+strlen(pbuf
)), "STATUS REJECT: ");
146 sprintf((pbuf
+strlen(pbuf
)), "FACILITY INFORMATION: ");
149 sprintf((pbuf
+strlen(pbuf
)), "INFORMATION ACKNOWLEDGE: ");
152 sprintf((pbuf
+strlen(pbuf
)), "INFORMATION REJECT: ");
155 sprintf((pbuf
+strlen(pbuf
)), "CLOSE: ");
158 sprintf((pbuf
+strlen(pbuf
)), "CLOSE ACKNOWLEDGE: ");
161 sprintf((pbuf
+strlen(pbuf
)), "ERROR: PD=0x40 MSG=0x%02x, ", buf
[i
]);
170 sprintf((pbuf
+strlen(pbuf
)), "ESCAPE: ");
173 sprintf((pbuf
+strlen(pbuf
)), "ALERT: ");
176 sprintf((pbuf
+strlen(pbuf
)), "CALL SENT: ");
179 sprintf((pbuf
+strlen(pbuf
)), "CONNECT: ");
182 sprintf((pbuf
+strlen(pbuf
)), "CONNECT ACKNOWLEDGE: ");
185 sprintf((pbuf
+strlen(pbuf
)), "SETUP: ");
188 sprintf((pbuf
+strlen(pbuf
)), "SETUP ACKNOWLEDGE: ");
192 sprintf((pbuf
+strlen(pbuf
)), "RESUME: ");
195 sprintf((pbuf
+strlen(pbuf
)), "RESUME ACKNOWLEDGE: ");
198 sprintf((pbuf
+strlen(pbuf
)), "RESUME REJECT: ");
201 sprintf((pbuf
+strlen(pbuf
)), "SUSPEND: ");
204 sprintf((pbuf
+strlen(pbuf
)), "SUSPEND ACKNOWLEDGE: ");
207 sprintf((pbuf
+strlen(pbuf
)), "SUSPEND REJECT: ");
210 sprintf((pbuf
+strlen(pbuf
)), "USER INFORMATION: ");
214 sprintf((pbuf
+strlen(pbuf
)), "DETACH");
217 sprintf((pbuf
+strlen(pbuf
)), "DISCONNECT: ");
220 sprintf((pbuf
+strlen(pbuf
)), "RELEASE: ");
223 sprintf((pbuf
+strlen(pbuf
)), "RELEASE ACKNOWLEDGE");
227 sprintf((pbuf
+strlen(pbuf
)), "CANCEL ACKNOWLEDGE: ");
230 sprintf((pbuf
+strlen(pbuf
)), "CANCEL REJECT: ");
233 sprintf((pbuf
+strlen(pbuf
)), "CONGESTION CONTROL: ");
236 sprintf((pbuf
+strlen(pbuf
)), "FACILITY: ");
239 sprintf((pbuf
+strlen(pbuf
)), "FACILITY ACKNOWLEDGE: ");
242 sprintf((pbuf
+strlen(pbuf
)), "FACILITY CANCEL: ");
245 sprintf((pbuf
+strlen(pbuf
)), "FACILITY REGISTER: ");
248 sprintf((pbuf
+strlen(pbuf
)), "FACILITY REJECT: ");
251 sprintf((pbuf
+strlen(pbuf
)), "INFORMATION: ");
254 sprintf((pbuf
+strlen(pbuf
)), "REGISTER ACKNOWLEDGE: ");
257 sprintf((pbuf
+strlen(pbuf
)), "REGISTER REJECT: ");
260 sprintf((pbuf
+strlen(pbuf
)), "STATUS: ");
264 sprintf((pbuf
+strlen(pbuf
)), "ERROR: PD=0x41 MSG=0x%02x, ", buf
[i
]);
270 sprintf((pbuf
+strlen(pbuf
)), "ERROR: PD=0x%02x MSG=0x%02x, ", pd
, buf
[i
]);
273 /* other information elements */
279 sprintf((pbuf
+strlen(pbuf
)), "\n ");
283 /* single octett info element */
285 switch (buf
[i
] & 0x70)
287 case 0x00: /* reserved */
288 sprintf((pbuf
+strlen(pbuf
)), "[reserved single octett info]");
291 case 0x10: /* shift */
292 oldcodeset
= codeset
;
293 codeset
= buf
[i
] & 0x07;
298 sprintf((pbuf
+strlen(pbuf
)), "[shift: codeset=%d lock=%d]", codeset
, codelock
);
301 case 0x20: /* more data */
302 sprintf((pbuf
+strlen(pbuf
)), "[more data]");
305 case 0x30: /* congestion level */
306 sprintf((pbuf
+strlen(pbuf
)), "[congestion level = %d]", buf
[i
] & 0x0f);
310 sprintf((pbuf
+strlen(pbuf
)), "[UNDEF SINGLE OCTET ELEMENT 0x%02x]", buf
[i
]);
319 /* variable length info element */
326 sprintf((pbuf
+strlen(pbuf
)), "[cause: ");
327 i
+= p_1tr6cause(pbuf
, &buf
[i
]);
332 sprintf((pbuf
+strlen(pbuf
)), "[connected address: ");
333 i
+= p_1tr6address(pbuf
, &buf
[i
]);
338 sprintf((pbuf
+strlen(pbuf
)), "[call identity: ");
341 sprintf((pbuf
+strlen(pbuf
)), "[channel id: channel=");
343 switch (buf
[i
] & 0x03)
346 sprintf((pbuf
+strlen(pbuf
)), "no channel");
349 sprintf((pbuf
+strlen(pbuf
)), "B-1");
352 sprintf((pbuf
+strlen(pbuf
)), "B-2");
355 sprintf((pbuf
+strlen(pbuf
)), "any channel");
359 sprintf((pbuf
+strlen(pbuf
)), " (exclusive)]");
361 sprintf((pbuf
+strlen(pbuf
)), " (preferred)]");
366 sprintf((pbuf
+strlen(pbuf
)), "[network specific facilities: ");
373 sprintf((pbuf
+strlen(pbuf
)), "Sperre");
376 sprintf((pbuf
+strlen(pbuf
)), "AWS 1");
379 sprintf((pbuf
+strlen(pbuf
)), "AWS 2");
382 sprintf((pbuf
+strlen(pbuf
)), "Konferenz");
385 sprintf((pbuf
+strlen(pbuf
)), "B-Kan uebern.");
388 sprintf((pbuf
+strlen(pbuf
)), "aktvrg. ghlt. Vbdg.");
391 sprintf((pbuf
+strlen(pbuf
)), "3er Konf");
394 sprintf((pbuf
+strlen(pbuf
)), "1seitg D/G Wechsel");
397 sprintf((pbuf
+strlen(pbuf
)), "2seitig D/G Wechsel");
400 sprintf((pbuf
+strlen(pbuf
)), "Rufnr. identifiz.");
403 sprintf((pbuf
+strlen(pbuf
)), "GBG");
406 sprintf((pbuf
+strlen(pbuf
)), "ueberg. Ruf");
409 sprintf((pbuf
+strlen(pbuf
)), "um/weitergel. Ruf");
412 sprintf((pbuf
+strlen(pbuf
)), "unterdr. A-Rufnr.");
415 sprintf((pbuf
+strlen(pbuf
)), "Verbdg. deaktivieren");
418 sprintf((pbuf
+strlen(pbuf
)), "Verbdg. aktivieren");
421 sprintf((pbuf
+strlen(pbuf
)), "SPV");
424 sprintf((pbuf
+strlen(pbuf
)), "Rueckw. 2seitg. DW");
427 sprintf((pbuf
+strlen(pbuf
)), "Anrufumltg. priv. Netz");
430 sprintf((pbuf
+strlen(pbuf
)), "undefined");
434 sprintf((pbuf
+strlen(pbuf
)), ", serv=%d", buf
[i
]);
436 sprintf((pbuf
+strlen(pbuf
)), ", ainfo=%d", buf
[i
]);
439 for (j
= 0; j
< len
; j
++)
441 sprintf((pbuf
+strlen(pbuf
))," 0x%02x", buf
[j
+i
]);
443 sprintf((pbuf
+strlen(pbuf
)),"]");
448 sprintf((pbuf
+strlen(pbuf
)), "[display: ");
451 sprintf((pbuf
+strlen(pbuf
)), "[keypad: ");
454 sprintf((pbuf
+strlen(pbuf
)), "[origination address: ");
455 i
+= p_1tr6address(pbuf
, &buf
[i
]);
459 sprintf((pbuf
+strlen(pbuf
)), "[destination address: ");
460 i
+= p_1tr6address(pbuf
, &buf
[i
]);
464 sprintf((pbuf
+strlen(pbuf
)), "[user-user information: ");
467 sprintf((pbuf
+strlen(pbuf
)), "[reserved: ");
470 sprintf((pbuf
+strlen(pbuf
)), "[UNKNOWN INFO-ELEMENT-ID");
474 else if (codeset
== 6)
479 sprintf((pbuf
+strlen(pbuf
)), "[service ind: serv=");
484 sprintf((pbuf
+strlen(pbuf
)), "phone");
487 sprintf((pbuf
+strlen(pbuf
)), "a/b");
490 sprintf((pbuf
+strlen(pbuf
)), "X.21");
493 sprintf((pbuf
+strlen(pbuf
)), "fax g4");
496 sprintf((pbuf
+strlen(pbuf
)), "btx");
499 sprintf((pbuf
+strlen(pbuf
)), "64k data");
502 sprintf((pbuf
+strlen(pbuf
)), "X.25");
505 sprintf((pbuf
+strlen(pbuf
)), "teletex");
508 sprintf((pbuf
+strlen(pbuf
)), "mixed");
511 sprintf((pbuf
+strlen(pbuf
)), "temex");
514 sprintf((pbuf
+strlen(pbuf
)), "picturephone");
517 sprintf((pbuf
+strlen(pbuf
)), "btx (new)");
520 sprintf((pbuf
+strlen(pbuf
)), "videophone");
523 sprintf((pbuf
+strlen(pbuf
)), "undefined");
527 sprintf((pbuf
+strlen(pbuf
)), ", ainfo=0x%02x]", buf
[i
]);
532 sprintf((pbuf
+strlen(pbuf
)), "[charging information: ");
535 sprintf((pbuf
+strlen(pbuf
)), "[date: ");
539 for (j
= 0; j
< len
; j
++)
541 sprintf((pbuf
+strlen(pbuf
)),"%c", buf
[j
+i
]);
543 sprintf((pbuf
+strlen(pbuf
)),"]");
548 sprintf((pbuf
+strlen(pbuf
)), "[facility select: ");
551 sprintf((pbuf
+strlen(pbuf
)), "[status of facilities: ");
554 sprintf((pbuf
+strlen(pbuf
)), "[status of called party: ");
559 sprintf((pbuf
+strlen(pbuf
)), "no information]");
562 sprintf((pbuf
+strlen(pbuf
)), "is being called]");
565 sprintf((pbuf
+strlen(pbuf
)), "undefined (0x%02x)]", buf
[i
]);
572 sprintf((pbuf
+strlen(pbuf
)), "[additional tx attributes: ");
576 for (j
= 0; j
< len
; j
++)
578 switch (buf
[j
+i
] &0x70)
581 sprintf((pbuf
+strlen(pbuf
)), "no satellite link");
584 sprintf((pbuf
+strlen(pbuf
)), "one satellite link");
587 sprintf((pbuf
+strlen(pbuf
)), "two satellite links");
590 sprintf((pbuf
+strlen(pbuf
)), "three satellite links");
593 sprintf((pbuf
+strlen(pbuf
)), "undefined value");
597 sprintf((pbuf
+strlen(pbuf
)),"(flag=req)]");
599 sprintf((pbuf
+strlen(pbuf
)),"(flag=ind)]");
605 sprintf((pbuf
+strlen(pbuf
)), "[UNKNOWN INFO-ELEMENT-ID");
611 sprintf((pbuf
+strlen(pbuf
)), "[ILLEGAL CODESET = 0x%02x", codeset
);
614 i
++; /* index -> length */
618 i
++; /* index -> 1st param */
620 for (j
= 0; j
< len
; j
++)
622 sprintf((pbuf
+strlen(pbuf
))," 0x%02x", buf
[j
+i
]);
625 sprintf((pbuf
+strlen(pbuf
)),"]");
631 if (!codelock
&& (codeset
!= oldcodeset
))
632 codeset
= oldcodeset
;
635 sprintf((pbuf
+strlen(pbuf
)),"\n");
638 /*---------------------------------------------------------------------------*
639 * decode and print the cause
640 *---------------------------------------------------------------------------*/
642 p_1tr6cause(char *pbuf
, unsigned char buf
[])
648 i
++; /* index -> length */
655 sprintf((pbuf
+strlen(pbuf
)), "%s", print_cause_1tr6(0));
659 sprintf((pbuf
+strlen(pbuf
)), "%s", print_cause_1tr6(buf
[i
] & 0x7f));
663 sprintf((pbuf
+strlen(pbuf
)), "%s, location: ", print_cause_1tr6(buf
[i
] & 0x7f));
665 switch (buf
[i
] & 0x0f)
668 sprintf((pbuf
+strlen(pbuf
)), "public network");
671 sprintf((pbuf
+strlen(pbuf
)), "private network");
674 sprintf((pbuf
+strlen(pbuf
)), "no information");
677 sprintf((pbuf
+strlen(pbuf
)), "reserved (0x%02x)", buf
[i
] & 0x0f);
682 i
++; /* index -> length */
684 i
++; /* index -> 1st param */
685 for (j
= 0; j
< len
; j
++)
687 sprintf((pbuf
+strlen(pbuf
))," 0x%02x", buf
[j
+i
]);
692 sprintf((pbuf
+strlen(pbuf
)),"]");
696 /*---------------------------------------------------------------------------*
697 * decode and print the ISDN (telephone) number
698 *---------------------------------------------------------------------------*/
700 p_1tr6address(char *pbuf
, unsigned char buf
[])
707 i
++; /* index -> length */
709 i
++; /* index -> 1st param */
715 for (j
= 0; j
< len
; j
++)
717 sprintf((pbuf
+strlen(pbuf
)),"%c", buf
[j
+i
]);
720 switch ((tp
& 0x70) >> 4)
723 sprintf((pbuf
+strlen(pbuf
)), " (type=unknown, ");
726 sprintf((pbuf
+strlen(pbuf
)), " (type=international, ");
729 sprintf((pbuf
+strlen(pbuf
)), " (type=national, ");
732 sprintf((pbuf
+strlen(pbuf
)), " (type=%d, ", ((tp
& 0x70) >> 4));
739 sprintf((pbuf
+strlen(pbuf
)), "plan=unknown)");
742 sprintf((pbuf
+strlen(pbuf
)), "plan=ISDN)");
745 sprintf((pbuf
+strlen(pbuf
)), "plan=%d)", (tp
& 0x0f));
749 sprintf((pbuf
+strlen(pbuf
)),"]");