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