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) 2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #include <stdio.h>
28*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #include <at.h>
31*7c478bd9Sstevel@tonic-gate #include <snoop.h>
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate static char *atp_ci(uint8_t);
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate static char *atp_trel[8] = {
36*7c478bd9Sstevel@tonic-gate 	"30s",
37*7c478bd9Sstevel@tonic-gate 	"1m",
38*7c478bd9Sstevel@tonic-gate 	"2m",
39*7c478bd9Sstevel@tonic-gate 	"4m",
40*7c478bd9Sstevel@tonic-gate 	"8m",
41*7c478bd9Sstevel@tonic-gate 	"(undef 5)",
42*7c478bd9Sstevel@tonic-gate 	"(undef 6)",
43*7c478bd9Sstevel@tonic-gate 	"(undef 7)"
44*7c478bd9Sstevel@tonic-gate };
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate void
interpret_atp(int flags,struct ddp_hdr * ddp,int len)47*7c478bd9Sstevel@tonic-gate interpret_atp(int flags, struct ddp_hdr *ddp, int len)
48*7c478bd9Sstevel@tonic-gate {
49*7c478bd9Sstevel@tonic-gate 	struct atp_hdr *atp = (struct atp_hdr *)ddp;
50*7c478bd9Sstevel@tonic-gate 	int atplen = len - (DDPHDR_SIZE + ATPHDR_SIZE);
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate 	if (flags & F_SUM) {
53*7c478bd9Sstevel@tonic-gate 		if (atplen < 0) {
54*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_sum_line(), MAXLINE,
55*7c478bd9Sstevel@tonic-gate 			    "ATP (short packet)");
56*7c478bd9Sstevel@tonic-gate 			return;
57*7c478bd9Sstevel@tonic-gate 		}
58*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_sum_line(), MAXLINE,
59*7c478bd9Sstevel@tonic-gate 		    "ATP (%s), TID=%d, L=%d",
60*7c478bd9Sstevel@tonic-gate 		    atp_ci(atp->atp_ctrl),
61*7c478bd9Sstevel@tonic-gate 		    get_short((uint8_t *)&atp->atp_tid),
62*7c478bd9Sstevel@tonic-gate 		    len);
63*7c478bd9Sstevel@tonic-gate 	}
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
66*7c478bd9Sstevel@tonic-gate 		show_header("ATP:  ", "ATP Header", 8);
67*7c478bd9Sstevel@tonic-gate 		show_space();
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate 		if (atplen < 0) {
70*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
71*7c478bd9Sstevel@tonic-gate 			    "ATP (short packet)");
72*7c478bd9Sstevel@tonic-gate 			return;
73*7c478bd9Sstevel@tonic-gate 		}
74*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
75*7c478bd9Sstevel@tonic-gate 		    "Length = %d", len);
76*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
77*7c478bd9Sstevel@tonic-gate 		    "Ctrl = 0x%x (%s), bitmap/seq = 0x%x",
78*7c478bd9Sstevel@tonic-gate 		    atp->atp_ctrl,
79*7c478bd9Sstevel@tonic-gate 		    atp_ci(atp->atp_ctrl),
80*7c478bd9Sstevel@tonic-gate 		    atp->atp_seq);
81*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
82*7c478bd9Sstevel@tonic-gate 		    "TID = %d, user bytes 0x%x 0x%x 0x%x 0x%x",
83*7c478bd9Sstevel@tonic-gate 		    get_short((uint8_t *)&atp->atp_tid),
84*7c478bd9Sstevel@tonic-gate 		    atp->atp_user[0], atp->atp_user[1],
85*7c478bd9Sstevel@tonic-gate 		    atp->atp_user[2], atp->atp_user[3]);
86*7c478bd9Sstevel@tonic-gate 		show_space();
87*7c478bd9Sstevel@tonic-gate 	}
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 	if (ddp->ddp_dest_sock == DDP_TYPE_ZIP ||
90*7c478bd9Sstevel@tonic-gate 	    ddp->ddp_src_sock == DDP_TYPE_ZIP)
91*7c478bd9Sstevel@tonic-gate 		interpret_atp_zip(flags, atp, atplen);
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate static char *
atp_ci(uint8_t ci)95*7c478bd9Sstevel@tonic-gate atp_ci(uint8_t ci)
96*7c478bd9Sstevel@tonic-gate {
97*7c478bd9Sstevel@tonic-gate 	static char buf[50];
98*7c478bd9Sstevel@tonic-gate 	char *p = buf;
99*7c478bd9Sstevel@tonic-gate 	char *to = NULL;
100*7c478bd9Sstevel@tonic-gate 	char *tail = &buf[sizeof (buf)];
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	switch (atp_fun(ci)) {
103*7c478bd9Sstevel@tonic-gate 	case ATP_TREQ:
104*7c478bd9Sstevel@tonic-gate 		p += snprintf(p, tail-p, "TReq");
105*7c478bd9Sstevel@tonic-gate 		to = atp_trel[atp_tmo(ci)];
106*7c478bd9Sstevel@tonic-gate 		break;
107*7c478bd9Sstevel@tonic-gate 	case ATP_TRESP:
108*7c478bd9Sstevel@tonic-gate 		p += snprintf(p, tail-p, "TResp");
109*7c478bd9Sstevel@tonic-gate 		break;
110*7c478bd9Sstevel@tonic-gate 	case ATP_TREL:
111*7c478bd9Sstevel@tonic-gate 		p += snprintf(p, tail-p, "TRel");
112*7c478bd9Sstevel@tonic-gate 		break;
113*7c478bd9Sstevel@tonic-gate 	}
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 	p += snprintf(p, tail-p, ci & ATP_FLG_XO ? " XO" : " ALO");
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 	if (ci & ATP_FLG_EOM)
118*7c478bd9Sstevel@tonic-gate 		p += snprintf(p, tail-p, " EOM");
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 	if (ci & ATP_FLG_STS)
121*7c478bd9Sstevel@tonic-gate 		p += snprintf(p, tail-p, " STS");
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate 	if (to != NULL)
124*7c478bd9Sstevel@tonic-gate 		(void) snprintf(p, tail-p, " %s", to);
125*7c478bd9Sstevel@tonic-gate 	return (buf);
126*7c478bd9Sstevel@tonic-gate }
127