xref: /titanic_52/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_atp.c (revision c40d696f8f0e05103b3795dd37198e00ae7ef955)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <stdio.h>
30 #include <sys/types.h>
31 
32 #include <at.h>
33 #include <snoop.h>
34 
35 static char *atp_ci(uint8_t);
36 
37 static char *atp_trel[8] = {
38 	"30s",
39 	"1m",
40 	"2m",
41 	"4m",
42 	"8m",
43 	"(undef 5)",
44 	"(undef 6)",
45 	"(undef 7)"
46 };
47 
48 void
49 interpret_atp(int flags, struct ddp_hdr *ddp, int len)
50 {
51 	struct atp_hdr *atp = (struct atp_hdr *)ddp;
52 	int atplen = len - (DDPHDR_SIZE + ATPHDR_SIZE);
53 
54 	if (flags & F_SUM) {
55 		if (atplen < 0) {
56 			(void) snprintf(get_sum_line(), MAXLINE,
57 			    "ATP (short packet)");
58 			return;
59 		}
60 		(void) snprintf(get_sum_line(), MAXLINE,
61 		    "ATP (%s), TID=%d, L=%d",
62 		    atp_ci(atp->atp_ctrl),
63 		    get_short((uint8_t *)&atp->atp_tid),
64 		    len);
65 	}
66 
67 	if (flags & F_DTAIL) {
68 		show_header("ATP:  ", "ATP Header", 8);
69 		show_space();
70 
71 		if (atplen < 0) {
72 			(void) snprintf(get_line(0, 0), get_line_remain(),
73 			    "ATP (short packet)");
74 			return;
75 		}
76 		(void) snprintf(get_line(0, 0), get_line_remain(),
77 		    "Length = %d", len);
78 		(void) snprintf(get_line(0, 0), get_line_remain(),
79 		    "Ctrl = 0x%x (%s), bitmap/seq = 0x%x",
80 		    atp->atp_ctrl,
81 		    atp_ci(atp->atp_ctrl),
82 		    atp->atp_seq);
83 		(void) snprintf(get_line(0, 0), get_line_remain(),
84 		    "TID = %d, user bytes 0x%x 0x%x 0x%x 0x%x",
85 		    get_short((uint8_t *)&atp->atp_tid),
86 		    atp->atp_user[0], atp->atp_user[1],
87 		    atp->atp_user[2], atp->atp_user[3]);
88 		show_space();
89 	}
90 
91 	if (ddp->ddp_dest_sock == DDP_TYPE_ZIP ||
92 	    ddp->ddp_src_sock == DDP_TYPE_ZIP)
93 		interpret_atp_zip(flags, atp, atplen);
94 }
95 
96 static char *
97 atp_ci(uint8_t ci)
98 {
99 	static char buf[50];
100 	char *p = buf;
101 	char *to = NULL;
102 	char *tail = &buf[sizeof (buf)];
103 
104 	switch (atp_fun(ci)) {
105 	case ATP_TREQ:
106 		p += snprintf(p, tail-p, "TReq");
107 		to = atp_trel[atp_tmo(ci)];
108 		break;
109 	case ATP_TRESP:
110 		p += snprintf(p, tail-p, "TResp");
111 		break;
112 	case ATP_TREL:
113 		p += snprintf(p, tail-p, "TRel");
114 		break;
115 	}
116 
117 	p += snprintf(p, tail-p, ci & ATP_FLG_XO ? " XO" : " ALO");
118 
119 	if (ci & ATP_FLG_EOM)
120 		p += snprintf(p, tail-p, " EOM");
121 
122 	if (ci & ATP_FLG_STS)
123 		p += snprintf(p, tail-p, " STS");
124 
125 	if (to != NULL)
126 		(void) snprintf(p, tail-p, " %s", to);
127 	return (buf);
128 }
129