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 #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 void show_nbp_tuples(uint8_t *, int, uint8_t *);
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate static char *nbp_short[] = {
38*7c478bd9Sstevel@tonic-gate "0", /* 0 */
39*7c478bd9Sstevel@tonic-gate "BRRQ ", /* 1 */
40*7c478bd9Sstevel@tonic-gate "LKUP C ", /* 2 */
41*7c478bd9Sstevel@tonic-gate "LKUP R ", /* 3 */
42*7c478bd9Sstevel@tonic-gate "FWD ", /* 4 */
43*7c478bd9Sstevel@tonic-gate "5 ",
44*7c478bd9Sstevel@tonic-gate "6 ",
45*7c478bd9Sstevel@tonic-gate "7 ",
46*7c478bd9Sstevel@tonic-gate "8 ",
47*7c478bd9Sstevel@tonic-gate "9 ",
48*7c478bd9Sstevel@tonic-gate "10 ",
49*7c478bd9Sstevel@tonic-gate "11 ",
50*7c478bd9Sstevel@tonic-gate "RGSTR ", /* 12 */
51*7c478bd9Sstevel@tonic-gate "UNRGSTR", /* 13 */
52*7c478bd9Sstevel@tonic-gate "OK ", /* 14 */
53*7c478bd9Sstevel@tonic-gate "ERROR ", /* 15 */
54*7c478bd9Sstevel@tonic-gate };
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate void
interpret_nbp(int flags,struct nbp_hdr * nbp,int len)57*7c478bd9Sstevel@tonic-gate interpret_nbp(int flags, struct nbp_hdr *nbp, int len)
58*7c478bd9Sstevel@tonic-gate {
59*7c478bd9Sstevel@tonic-gate uint8_t *data;
60*7c478bd9Sstevel@tonic-gate int nbp_cnt = nbp->nbp_fun_cnt & 0xf; /* lower four bits */
61*7c478bd9Sstevel@tonic-gate int nbp_op = (nbp->nbp_fun_cnt >> 4) & 0xf; /* upper four bits */
62*7c478bd9Sstevel@tonic-gate
63*7c478bd9Sstevel@tonic-gate data = (uint8_t *)(nbp + 1);
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
66*7c478bd9Sstevel@tonic-gate if (len < sizeof (struct nbp_hdr)) {
67*7c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE,
68*7c478bd9Sstevel@tonic-gate "NBP (short packet)");
69*7c478bd9Sstevel@tonic-gate return;
70*7c478bd9Sstevel@tonic-gate }
71*7c478bd9Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE,
72*7c478bd9Sstevel@tonic-gate "NBP F=%s CNT=%d ID=%d", nbp_short[nbp_op],
73*7c478bd9Sstevel@tonic-gate nbp_cnt, nbp->nbp_id);
74*7c478bd9Sstevel@tonic-gate }
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
77*7c478bd9Sstevel@tonic-gate show_header("NBP: ", "NBP Header", len);
78*7c478bd9Sstevel@tonic-gate show_space();
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gate if (len < sizeof (struct nbp_hdr)) {
81*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
82*7c478bd9Sstevel@tonic-gate "NBP (short packet)");
83*7c478bd9Sstevel@tonic-gate return;
84*7c478bd9Sstevel@tonic-gate }
85*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
86*7c478bd9Sstevel@tonic-gate "Length = %d", len);
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
89*7c478bd9Sstevel@tonic-gate "Func = %d (%s)", nbp_op, nbp_short[nbp_op]);
90*7c478bd9Sstevel@tonic-gate
91*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
92*7c478bd9Sstevel@tonic-gate "Tuple count = %d", nbp_cnt);
93*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
94*7c478bd9Sstevel@tonic-gate "Id = %d", nbp->nbp_id);
95*7c478bd9Sstevel@tonic-gate show_nbp_tuples(data, nbp_cnt, ((uint8_t *)nbp) + len);
96*7c478bd9Sstevel@tonic-gate }
97*7c478bd9Sstevel@tonic-gate }
98*7c478bd9Sstevel@tonic-gate
99*7c478bd9Sstevel@tonic-gate static void
show_nbp_tuples(uint8_t * p,int tuples,uint8_t * tail)100*7c478bd9Sstevel@tonic-gate show_nbp_tuples(uint8_t *p, int tuples, uint8_t *tail)
101*7c478bd9Sstevel@tonic-gate {
102*7c478bd9Sstevel@tonic-gate uint16_t net;
103*7c478bd9Sstevel@tonic-gate uint8_t node;
104*7c478bd9Sstevel@tonic-gate uint8_t sock;
105*7c478bd9Sstevel@tonic-gate uint8_t enumer;
106*7c478bd9Sstevel@tonic-gate char obj[100];
107*7c478bd9Sstevel@tonic-gate char *op;
108*7c478bd9Sstevel@tonic-gate char *otail = &obj[sizeof (obj)];
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gate while (tuples--) {
111*7c478bd9Sstevel@tonic-gate op = obj;
112*7c478bd9Sstevel@tonic-gate if ((p + 5) > tail)
113*7c478bd9Sstevel@tonic-gate goto out;
114*7c478bd9Sstevel@tonic-gate net = get_short(p);
115*7c478bd9Sstevel@tonic-gate p += 2;
116*7c478bd9Sstevel@tonic-gate node = *p++;
117*7c478bd9Sstevel@tonic-gate sock = *p++;
118*7c478bd9Sstevel@tonic-gate enumer = *p++;
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate if (p > tail || &p[1]+p[0] > tail)
121*7c478bd9Sstevel@tonic-gate goto out;
122*7c478bd9Sstevel@tonic-gate op += snprintf(op, otail-op, "%.*s", p[0], &p[1]);
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gate p = &p[1]+p[0];
125*7c478bd9Sstevel@tonic-gate if (p > tail || &p[1]+p[0] > tail)
126*7c478bd9Sstevel@tonic-gate goto out;
127*7c478bd9Sstevel@tonic-gate op += snprintf(op, otail-op, ":%.*s", p[0], &p[1]);
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate p = &p[1]+p[0];
130*7c478bd9Sstevel@tonic-gate if (p > tail || &p[1]+p[0] > tail)
131*7c478bd9Sstevel@tonic-gate goto out;
132*7c478bd9Sstevel@tonic-gate (void) snprintf(op, otail-op, "@%.*s", p[0], &p[1]);
133*7c478bd9Sstevel@tonic-gate p = &p[1]+p[0];
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
136*7c478bd9Sstevel@tonic-gate "Name = \"%s\"", obj);
137*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
138*7c478bd9Sstevel@tonic-gate "Net = %d, node = %d, sock = %d, enum = %d",
139*7c478bd9Sstevel@tonic-gate net, node, sock, enumer);
140*7c478bd9Sstevel@tonic-gate }
141*7c478bd9Sstevel@tonic-gate return;
142*7c478bd9Sstevel@tonic-gate out:
143*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
144*7c478bd9Sstevel@tonic-gate "NBP (short tuple)");
145*7c478bd9Sstevel@tonic-gate }
146