2 * Copyright (c) 2007 - Andrey "nording" Chernyak <andrew@nording.ru>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code distributions
6 * retain the above copyright notice and this paragraph in its entirety, (2)
7 * distributions including binary code include the above copyright notice and
8 * this paragraph in its entirety in the documentation or other materials
9 * provided with the distribution, and (3) all advertising materials mentioning
10 * features or use of this software display the following acknowledgement:
11 * ``This product includes software developed by the University of California,
12 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13 * the University nor the names of its contributors may be used to endorse
14 * or promote products derived from this software without specific prior
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 * Format and print Realtek Remote Control Protocol (RRCP), Realtek
21 * Loop Detection Protocol (RLDP), and Realtek Echo Protocol (REP) packets,
22 * as well as tag formats used by some Realtek switch chips to supply
23 * tag information to a host CPU for a switch.
26 /* \summary: printer for various Realtek protocols */
29 * See, for example, section 8.20 "Realtek Remote Control Protocol" of
31 * http://realtek.info/pdf/rtl8324.pdf
33 * and section 7.22 "Realtek Remote Control Protocol" of
35 * http://realtek.info/pdf/rtl8326.pdf
37 * and this page on the OpenRRCP Wiki:
39 * http://openrrcp.org.ru/wiki/rrcp_protocol
41 * for information on RRCP.
43 * See, for example, section 8.21 "Network Loop Connection Fault
46 * http://realtek.info/pdf/rtl8324.pdf
48 * and section 7.23 "Network Loop Connection Fault Detection" of
50 * http://realtek.info/pdf/rtl8326.pdf
52 * for information on RLDP.
54 * See, for example, section 8.22 "Realtek Echo Protocol" of
56 * http://realtek.info/pdf/rtl8324.pdf
58 * and section 7.24 "Realtek Echo Protocol" of
60 * http://realtek.info/pdf/rtl8326.pdf
62 * for information on REP.
64 * NOTE: none of them indicate the byte order of multi-byte fields in any
67 * See section 8.10 "CPU Tag Function" of
69 * http://realtek.info/pdf/rtl8306sd%28m%29_datasheet_1.1.pdf
71 * for the RTL8306 DSA protocol tag format.
78 #include "netdissect-stdinc.h"
80 #include "netdissect.h"
81 #include "addrtoname.h"
84 #define RTL_FRAME_TYPE_OFFSET 0 /* frame type and other data - 1 byte */
87 * The upper 4 bits of the first octet of Realtek 0x8899 frames indicates
90 #define RTL_FRAME_TYPE_MASK 0xF0
91 #define RTL_FRAME_TYPE_SUBTYPE 0x00 /* lower 4 bits are a subtype */
92 #define RTL_FRAME_TYPE_8306_DSA 0x90 /* RTL8306 DSA protocol */
93 #define RTL_FRAME_TYPE_8366RB_DSA 0xA0 /* RTL8366RB DSA protocol */
94 #define RTL_FRAME_TYPE_SHIFT 4
97 * The lower 4 bits are a subtype if the upper 4 bits are 0.
99 #define RTL_FRAME_SUBTYPE_MASK 0x0F
100 #define RTL_FRAME_SUBTYPE_RRCP 0x01 /* RRCP */
101 #define RTL_FRAME_SUBTYPE_REP 0x02 /* REP */
102 #define RTL_FRAME_SUBTYPE_RLDP 0x03 /* RLDP */
103 #define RTL_FRAME_SUBTYPE_XXX_DSA 0x04 /* DSA protocol for some chip(s) */
105 #define RRCP_OPCODE_ISREPLY_OFFSET 1 /* opcode and isreply flag - 1 byte */
107 #define RRCP_OPCODE_MASK 0x7F /* 0x00 = hello, 0x01 = get, 0x02 = set */
108 #define RRCP_ISREPLY 0x80 /* 0 = request to switch, 0x80 = reply from switch */
110 #define RRCP_OPCODE_HELLO 0x00
111 #define RRCP_OPCODE_GET_CONFIGURATION 0x01
112 #define RRCP_OPCODE_SET_CONFIGURATION 0x02
114 #define RRCP_AUTHKEY_OFFSET 2 /* authorization key - 2 bytes, 0x2379 by default */
117 #define RRCP_REG_ADDR_OFFSET 4 /* register address - 2 bytes */
118 #define RRCP_REG_DATA_OFFSET 6 /* register data - 4 bytes */
119 #define RRCP_COOKIE1_OFFSET 10 /* 4 bytes */
120 #define RRCP_COOKIE2_OFFSET 14 /* 4 bytes */
122 /* hello reply packets */
123 #define RRCP_DOWNLINK_PORT_OFFSET 4 /* 1 byte */
124 #define RRCP_UPLINK_PORT_OFFSET 5 /* 1 byte */
125 #define RRCP_UPLINK_MAC_OFFSET 6 /* 6 byte MAC address */
126 #define RRCP_CHIP_ID_OFFSET 12 /* 2 bytes */
127 #define RRCP_VENDOR_ID_OFFSET 14 /* 4 bytes */
129 static const struct tok opcode_values
[] = {
130 { RRCP_OPCODE_HELLO
, "hello" },
131 { RRCP_OPCODE_GET_CONFIGURATION
, "get" },
132 { RRCP_OPCODE_SET_CONFIGURATION
, "set" },
140 rrcp_print(netdissect_options
*ndo
,
145 ndo
->ndo_protocol
= "rrcp";
146 rrcp_opcode
= GET_U_1((cp
+ RRCP_OPCODE_ISREPLY_OFFSET
)) & RRCP_OPCODE_MASK
;
147 ND_PRINT("RRCP %s: %s",
148 ((GET_U_1(cp
+ RRCP_OPCODE_ISREPLY_OFFSET
)) & RRCP_ISREPLY
) ? "reply" : "query",
149 tok2str(opcode_values
,"unknown opcode (0x%02x)",rrcp_opcode
));
150 if (rrcp_opcode
==RRCP_OPCODE_GET_CONFIGURATION
||
151 rrcp_opcode
==RRCP_OPCODE_SET_CONFIGURATION
){
152 ND_PRINT(" addr=0x%04x, data=0x%08x",
153 GET_LE_U_2(cp
+ RRCP_REG_ADDR_OFFSET
),
154 GET_LE_U_4(cp
+ RRCP_REG_DATA_OFFSET
));
156 ND_PRINT(", auth=0x%04x",
157 GET_BE_U_2(cp
+ RRCP_AUTHKEY_OFFSET
));
158 if (rrcp_opcode
==RRCP_OPCODE_HELLO
&&
159 ((GET_U_1(cp
+ RRCP_OPCODE_ISREPLY_OFFSET
)) & RRCP_ISREPLY
)){
160 ND_PRINT(" downlink_port=%u, uplink_port=%u, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ",
161 GET_U_1(cp
+ RRCP_DOWNLINK_PORT_OFFSET
),
162 GET_U_1(cp
+ RRCP_UPLINK_PORT_OFFSET
),
163 GET_ETHERADDR_STRING(cp
+ RRCP_UPLINK_MAC_OFFSET
),
164 GET_BE_U_4(cp
+ RRCP_VENDOR_ID_OFFSET
),
165 GET_BE_U_2(cp
+ RRCP_CHIP_ID_OFFSET
));
166 }else if (rrcp_opcode
==RRCP_OPCODE_GET_CONFIGURATION
||
167 rrcp_opcode
==RRCP_OPCODE_SET_CONFIGURATION
){
168 ND_PRINT(", cookie=0x%08x%08x ",
169 GET_BE_U_4(cp
+ RRCP_COOKIE2_OFFSET
),
170 GET_BE_U_4(cp
+ RRCP_COOKIE1_OFFSET
));
175 * Print Realtek packets
178 rtl_print(netdissect_options
*ndo
,
181 const struct lladdr_info
*src
,
182 const struct lladdr_info
*dst
)
186 ndo
->ndo_protocol
= "rtl";
188 if (src
!= NULL
&& dst
!= NULL
) {
189 ND_PRINT("%s > %s, ",
190 (src
->addr_string
)(ndo
, src
->addr
),
191 (dst
->addr_string
)(ndo
, dst
->addr
));
194 rtl_proto
= GET_U_1(cp
+ RTL_FRAME_TYPE_OFFSET
);
196 switch (rtl_proto
& RTL_FRAME_TYPE_MASK
) {
198 case RTL_FRAME_TYPE_SUBTYPE
:
202 switch (rtl_proto
& RTL_FRAME_SUBTYPE_MASK
) {
204 case RTL_FRAME_SUBTYPE_RRCP
:
208 case RTL_FRAME_SUBTYPE_REP
:
210 * REP packets have no payload.
215 case RTL_FRAME_SUBTYPE_RLDP
:
217 * RLDP packets have no payload.
222 case RTL_FRAME_SUBTYPE_XXX_DSA
:
223 ND_PRINT("Realtek 8-byte DSA tag");
227 ND_PRINT("Realtek unknown subtype 0x%01x",
228 rtl_proto
& RTL_FRAME_SUBTYPE_MASK
);
233 case RTL_FRAME_TYPE_8306_DSA
:
234 ND_PRINT("Realtek RTL8306 4-byte DSA tag");
237 case RTL_FRAME_TYPE_8366RB_DSA
:
238 ND_PRINT("Realtek RTL8366RB 4-byte DSA tag");
242 ND_PRINT("Realtek unknown type 0x%01x",
243 (rtl_proto
& RTL_FRAME_TYPE_MASK
) >> RTL_FRAME_TYPE_SHIFT
);