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