1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate * All rights reserved.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <sys/types.h>
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate #include <at.h>
33*0Sstevel@tonic-gate #include <snoop.h>
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate static void show_nbp_tuples(uint8_t *, int, uint8_t *);
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate static char *nbp_short[] = {
38*0Sstevel@tonic-gate "0", /* 0 */
39*0Sstevel@tonic-gate "BRRQ ", /* 1 */
40*0Sstevel@tonic-gate "LKUP C ", /* 2 */
41*0Sstevel@tonic-gate "LKUP R ", /* 3 */
42*0Sstevel@tonic-gate "FWD ", /* 4 */
43*0Sstevel@tonic-gate "5 ",
44*0Sstevel@tonic-gate "6 ",
45*0Sstevel@tonic-gate "7 ",
46*0Sstevel@tonic-gate "8 ",
47*0Sstevel@tonic-gate "9 ",
48*0Sstevel@tonic-gate "10 ",
49*0Sstevel@tonic-gate "11 ",
50*0Sstevel@tonic-gate "RGSTR ", /* 12 */
51*0Sstevel@tonic-gate "UNRGSTR", /* 13 */
52*0Sstevel@tonic-gate "OK ", /* 14 */
53*0Sstevel@tonic-gate "ERROR ", /* 15 */
54*0Sstevel@tonic-gate };
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate void
interpret_nbp(int flags,struct nbp_hdr * nbp,int len)57*0Sstevel@tonic-gate interpret_nbp(int flags, struct nbp_hdr *nbp, int len)
58*0Sstevel@tonic-gate {
59*0Sstevel@tonic-gate uint8_t *data;
60*0Sstevel@tonic-gate int nbp_cnt = nbp->nbp_fun_cnt & 0xf; /* lower four bits */
61*0Sstevel@tonic-gate int nbp_op = (nbp->nbp_fun_cnt >> 4) & 0xf; /* upper four bits */
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate data = (uint8_t *)(nbp + 1);
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate if (flags & F_SUM) {
66*0Sstevel@tonic-gate if (len < sizeof (struct nbp_hdr)) {
67*0Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE,
68*0Sstevel@tonic-gate "NBP (short packet)");
69*0Sstevel@tonic-gate return;
70*0Sstevel@tonic-gate }
71*0Sstevel@tonic-gate (void) snprintf(get_sum_line(), MAXLINE,
72*0Sstevel@tonic-gate "NBP F=%s CNT=%d ID=%d", nbp_short[nbp_op],
73*0Sstevel@tonic-gate nbp_cnt, nbp->nbp_id);
74*0Sstevel@tonic-gate }
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate if (flags & F_DTAIL) {
77*0Sstevel@tonic-gate show_header("NBP: ", "NBP Header", len);
78*0Sstevel@tonic-gate show_space();
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gate if (len < sizeof (struct nbp_hdr)) {
81*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
82*0Sstevel@tonic-gate "NBP (short packet)");
83*0Sstevel@tonic-gate return;
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
86*0Sstevel@tonic-gate "Length = %d", len);
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
89*0Sstevel@tonic-gate "Func = %d (%s)", nbp_op, nbp_short[nbp_op]);
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
92*0Sstevel@tonic-gate "Tuple count = %d", nbp_cnt);
93*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
94*0Sstevel@tonic-gate "Id = %d", nbp->nbp_id);
95*0Sstevel@tonic-gate show_nbp_tuples(data, nbp_cnt, ((uint8_t *)nbp) + len);
96*0Sstevel@tonic-gate }
97*0Sstevel@tonic-gate }
98*0Sstevel@tonic-gate
99*0Sstevel@tonic-gate static void
show_nbp_tuples(uint8_t * p,int tuples,uint8_t * tail)100*0Sstevel@tonic-gate show_nbp_tuples(uint8_t *p, int tuples, uint8_t *tail)
101*0Sstevel@tonic-gate {
102*0Sstevel@tonic-gate uint16_t net;
103*0Sstevel@tonic-gate uint8_t node;
104*0Sstevel@tonic-gate uint8_t sock;
105*0Sstevel@tonic-gate uint8_t enumer;
106*0Sstevel@tonic-gate char obj[100];
107*0Sstevel@tonic-gate char *op;
108*0Sstevel@tonic-gate char *otail = &obj[sizeof (obj)];
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gate while (tuples--) {
111*0Sstevel@tonic-gate op = obj;
112*0Sstevel@tonic-gate if ((p + 5) > tail)
113*0Sstevel@tonic-gate goto out;
114*0Sstevel@tonic-gate net = get_short(p);
115*0Sstevel@tonic-gate p += 2;
116*0Sstevel@tonic-gate node = *p++;
117*0Sstevel@tonic-gate sock = *p++;
118*0Sstevel@tonic-gate enumer = *p++;
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate if (p > tail || &p[1]+p[0] > tail)
121*0Sstevel@tonic-gate goto out;
122*0Sstevel@tonic-gate op += snprintf(op, otail-op, "%.*s", p[0], &p[1]);
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate p = &p[1]+p[0];
125*0Sstevel@tonic-gate if (p > tail || &p[1]+p[0] > tail)
126*0Sstevel@tonic-gate goto out;
127*0Sstevel@tonic-gate op += snprintf(op, otail-op, ":%.*s", p[0], &p[1]);
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate p = &p[1]+p[0];
130*0Sstevel@tonic-gate if (p > tail || &p[1]+p[0] > tail)
131*0Sstevel@tonic-gate goto out;
132*0Sstevel@tonic-gate (void) snprintf(op, otail-op, "@%.*s", p[0], &p[1]);
133*0Sstevel@tonic-gate p = &p[1]+p[0];
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
136*0Sstevel@tonic-gate "Name = \"%s\"", obj);
137*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
138*0Sstevel@tonic-gate "Net = %d, node = %d, sock = %d, enum = %d",
139*0Sstevel@tonic-gate net, node, sock, enumer);
140*0Sstevel@tonic-gate }
141*0Sstevel@tonic-gate return;
142*0Sstevel@tonic-gate out:
143*0Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
144*0Sstevel@tonic-gate "NBP (short tuple)");
145*0Sstevel@tonic-gate }
146