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