xref: /titanic_53/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_adsp.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1991-2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <at.h>
33*7c478bd9Sstevel@tonic-gate #include <snoop.h>
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate static char *adsp_ctrl(uint8_t);
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate void
interpret_adsp(int flags,struct ddp_adsphdr * adp,int len)38*7c478bd9Sstevel@tonic-gate interpret_adsp(int flags, struct ddp_adsphdr *adp, int len)
39*7c478bd9Sstevel@tonic-gate {
40*7c478bd9Sstevel@tonic-gate 	struct ddp_adsp_open *apo;
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate 	if (flags & F_SUM) {
43*7c478bd9Sstevel@tonic-gate 		if (len < sizeof (struct ddp_adsphdr)) {
44*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_sum_line(), MAXLINE,
45*7c478bd9Sstevel@tonic-gate 			    "ADSP (short packet)");
46*7c478bd9Sstevel@tonic-gate 			return;
47*7c478bd9Sstevel@tonic-gate 		}
48*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_sum_line(), MAXLINE,
49*7c478bd9Sstevel@tonic-gate 		    "ADSP ConnID=%u (%s)",
50*7c478bd9Sstevel@tonic-gate 		    get_short(adp->ad_connid),
51*7c478bd9Sstevel@tonic-gate 		    adsp_ctrl(adp->ad_desc));
52*7c478bd9Sstevel@tonic-gate 	}
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
55*7c478bd9Sstevel@tonic-gate 		show_header("ADSP: ", "ADSP Header",
56*7c478bd9Sstevel@tonic-gate 		    len - sizeof (struct ddp_adsphdr));
57*7c478bd9Sstevel@tonic-gate 		show_space();
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate 		if (len < sizeof (struct ddp_adsphdr)) {
60*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
61*7c478bd9Sstevel@tonic-gate 			    "(short packet)");
62*7c478bd9Sstevel@tonic-gate 			return;
63*7c478bd9Sstevel@tonic-gate 		}
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
66*7c478bd9Sstevel@tonic-gate 		    "ConnID = %u, ByteSeq = %u, RecvSeq = %u",
67*7c478bd9Sstevel@tonic-gate 		    get_short(adp->ad_connid),
68*7c478bd9Sstevel@tonic-gate 		    get_long(adp->ad_fbseq),
69*7c478bd9Sstevel@tonic-gate 		    get_long(adp->ad_nrseq));
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
72*7c478bd9Sstevel@tonic-gate 		    "RcvWin = %u, Ctrl = 0x%x (%s)",
73*7c478bd9Sstevel@tonic-gate 		    get_short(adp->ad_rcvwin),
74*7c478bd9Sstevel@tonic-gate 		    adp->ad_desc,
75*7c478bd9Sstevel@tonic-gate 		    adsp_ctrl(adp->ad_desc));
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate 		switch (adp->ad_desc) {
78*7c478bd9Sstevel@tonic-gate 		case AD_CREQ:		/* open requests */
79*7c478bd9Sstevel@tonic-gate 		case AD_CACK:
80*7c478bd9Sstevel@tonic-gate 		case AD_CREQ_ACK:
81*7c478bd9Sstevel@tonic-gate 		case AD_CDENY:
82*7c478bd9Sstevel@tonic-gate 			apo = (struct ddp_adsp_open *)adp;
83*7c478bd9Sstevel@tonic-gate 			if (len < sizeof (struct ddp_adsp_open)) {
84*7c478bd9Sstevel@tonic-gate 				(void) snprintf(get_line(0, 0),
85*7c478bd9Sstevel@tonic-gate 				    get_line_remain(),
86*7c478bd9Sstevel@tonic-gate 				    "(short packet)");
87*7c478bd9Sstevel@tonic-gate 				return;
88*7c478bd9Sstevel@tonic-gate 			}
89*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
90*7c478bd9Sstevel@tonic-gate 			    "Dest ConnID = %u, AttRcvSeq = %u",
91*7c478bd9Sstevel@tonic-gate 			    get_short(apo->ad_dconnid),
92*7c478bd9Sstevel@tonic-gate 			    get_long(apo->ad_attseq));
93*7c478bd9Sstevel@tonic-gate 			break;
94*7c478bd9Sstevel@tonic-gate 		}
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 		if (adp->ad_desc & AD_ATT) {
97*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
98*7c478bd9Sstevel@tonic-gate 			    "AttCode = 0x%x",
99*7c478bd9Sstevel@tonic-gate 			    get_short(((struct ddp_adsp_att *)adp)->
100*7c478bd9Sstevel@tonic-gate 				ad_att_code));
101*7c478bd9Sstevel@tonic-gate 		}
102*7c478bd9Sstevel@tonic-gate 	}
103*7c478bd9Sstevel@tonic-gate }
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate static char *adsp_ctrl_msg[] = {
106*7c478bd9Sstevel@tonic-gate 	"Probe/Ack",
107*7c478bd9Sstevel@tonic-gate 	"OpenConnReq",
108*7c478bd9Sstevel@tonic-gate 	"OpenConnAck",
109*7c478bd9Sstevel@tonic-gate 	"OpenConnReq+Ack",
110*7c478bd9Sstevel@tonic-gate 	"OpenConnDeny",
111*7c478bd9Sstevel@tonic-gate 	"CloseConnAdv",
112*7c478bd9Sstevel@tonic-gate 	"ForwReset",
113*7c478bd9Sstevel@tonic-gate 	"ForwReset Ack",
114*7c478bd9Sstevel@tonic-gate 	"RetransAdv",
115*7c478bd9Sstevel@tonic-gate 	"9", "10", "11", "12", "13", "14", "15",
116*7c478bd9Sstevel@tonic-gate };
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate static char *
adsp_ctrl(uint8_t ctrl)119*7c478bd9Sstevel@tonic-gate adsp_ctrl(uint8_t ctrl)
120*7c478bd9Sstevel@tonic-gate {
121*7c478bd9Sstevel@tonic-gate 	static char buf[50];
122*7c478bd9Sstevel@tonic-gate 	char *p = buf;
123*7c478bd9Sstevel@tonic-gate 	char *tail = &buf[sizeof (buf)];
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	if (ctrl & AD_ACKREQ)
126*7c478bd9Sstevel@tonic-gate 		p += snprintf(p, tail-p, "AckReq");
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	if (ctrl & AD_EOM) {
129*7c478bd9Sstevel@tonic-gate 		p += snprintf(p, tail-p, p == buf ? "EOM" : " EOM");
130*7c478bd9Sstevel@tonic-gate 	}
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 	if (ctrl & AD_ATT) {
133*7c478bd9Sstevel@tonic-gate 		p += snprintf(p, tail-p, p == buf ? "Att" : " Att");
134*7c478bd9Sstevel@tonic-gate 	}
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	if (ctrl & AD_CTRL) {
137*7c478bd9Sstevel@tonic-gate 		(void) snprintf(p, tail-p, "%s%s", p == buf ? "" : " ",
138*7c478bd9Sstevel@tonic-gate 		    adsp_ctrl_msg[ctrl & AD_CTRL_MASK]);
139*7c478bd9Sstevel@tonic-gate 	}
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	return (buf);
142*7c478bd9Sstevel@tonic-gate }
143