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 */
30 #include "netdissect-stdinc.h"
32 #include "netdissect.h"
33 #include "addrtoname.h"
36 #define RTL_PROTOCOL_OFFSET 0 /* Protocol and possibly other data - 1 byte */
38 #define RTL_PROTOCOL_RRCP 0x01 /* RRCP */
39 #define RTL_PROTOCOL_REP 0x02 /* REP */
40 #define RTL_PROTOCOL_RLDP 0x03 /* RLDP */
41 #define RTL_PROTOCOL_RLDP2 0x23 /* also RLDP */
42 #define RTL_PROTOCOL_XXX_DSA 0x04 /* DSA protocol for some chip(s) */
45 * Values for the upper 4 bits of the protocol field, for
46 * protocols where the lower 4 bits contain protocol data.
48 * See section 8.10 "CPU Tag Function" of
50 * http://realtek.info/pdf/rtl8306sd%28m%29_datasheet_1.1.pdf
52 * for the RTL8306 DSA protocol tag format.
54 #define RTL_PROTOCOL_8306_DSA 0x90 /* RTL8306 DSA protocol */
55 #define RTL_PROTOCOL_8366RB_DSA 0xA0 /* RTL8366RB DSA protocol */
57 #define RRCP_OPCODE_ISREPLY_OFFSET 1 /* opcode and isreply flag - 1 byte */
59 #define RRCP_OPCODE_MASK 0x7F /* 0x00 = hello, 0x01 = get, 0x02 = set */
60 #define RRCP_ISREPLY 0x80 /* 0 = request to switch, 0x80 = reply from switch */
62 #define RRCP_OPCODE_HELLO 0x00
63 #define RRCP_OPCODE_GET_CONFIGURATION 0x01
64 #define RRCP_OPCODE_SET_CONFIGURATION 0x02
66 #define RRCP_AUTHKEY_OFFSET 2 /* authorization key - 2 bytes, 0x2379 by default */
69 #define RRCP_REG_ADDR_OFFSET 4 /* register address - 2 bytes */
70 #define RRCP_REG_DATA_OFFSET 6 /* register data - 4 bytes */
71 #define RRCP_COOKIE1_OFFSET 10 /* 4 bytes */
72 #define RRCP_COOKIE2_OFFSET 14 /* 4 bytes */
74 /* hello reply packets */
75 #define RRCP_DOWNLINK_PORT_OFFSET 4 /* 1 byte */
76 #define RRCP_UPLINK_PORT_OFFSET 5 /* 1 byte */
77 #define RRCP_UPLINK_MAC_OFFSET 6 /* 6 byte MAC address */
78 #define RRCP_CHIP_ID_OFFSET 12 /* 2 bytes */
79 #define RRCP_VENDOR_ID_OFFSET 14 /* 4 bytes */
81 static const struct tok opcode_values
[] = {
82 { RRCP_OPCODE_HELLO
, "hello" },
83 { RRCP_OPCODE_GET_CONFIGURATION
, "get" },
84 { RRCP_OPCODE_SET_CONFIGURATION
, "set" },
91 * See, for example, section 8.20 "Realtek Remote Control Protocol" of
93 * http://realtek.info/pdf/rtl8324.pdf
95 * and section 7.22 "Realtek Remote Control Protocol" of
97 * http://realtek.info/pdf/rtl8326.pdf
99 * and this page on the OpenRRCP Wiki:
101 * http://openrrcp.org.ru/wiki/rrcp_protocol
103 * for information on RRCP.
106 rrcp_print(netdissect_options
*ndo
,
111 ndo
->ndo_protocol
= "rrcp";
112 rrcp_opcode
= GET_U_1((cp
+ RRCP_OPCODE_ISREPLY_OFFSET
)) & RRCP_OPCODE_MASK
;
113 ND_PRINT("RRCP %s: %s",
114 ((GET_U_1(cp
+ RRCP_OPCODE_ISREPLY_OFFSET
)) & RRCP_ISREPLY
) ? "reply" : "query",
115 tok2str(opcode_values
,"unknown opcode (0x%02x)",rrcp_opcode
));
116 if (rrcp_opcode
==RRCP_OPCODE_GET_CONFIGURATION
||
117 rrcp_opcode
==RRCP_OPCODE_SET_CONFIGURATION
){
118 ND_PRINT(" addr=0x%04x, data=0x%08x",
119 GET_LE_U_2(cp
+ RRCP_REG_ADDR_OFFSET
),
120 GET_LE_U_4(cp
+ RRCP_REG_DATA_OFFSET
));
122 ND_PRINT(", auth=0x%04x",
123 GET_BE_U_2(cp
+ RRCP_AUTHKEY_OFFSET
));
124 if (rrcp_opcode
==RRCP_OPCODE_HELLO
&&
125 ((GET_U_1(cp
+ RRCP_OPCODE_ISREPLY_OFFSET
)) & RRCP_ISREPLY
)){
126 ND_PRINT(" downlink_port=%u, uplink_port=%u, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ",
127 GET_U_1(cp
+ RRCP_DOWNLINK_PORT_OFFSET
),
128 GET_U_1(cp
+ RRCP_UPLINK_PORT_OFFSET
),
129 GET_MAC48_STRING(cp
+ RRCP_UPLINK_MAC_OFFSET
),
130 GET_BE_U_4(cp
+ RRCP_VENDOR_ID_OFFSET
),
131 GET_BE_U_2(cp
+ RRCP_CHIP_ID_OFFSET
));
132 }else if (rrcp_opcode
==RRCP_OPCODE_GET_CONFIGURATION
||
133 rrcp_opcode
==RRCP_OPCODE_SET_CONFIGURATION
){
134 ND_PRINT(", cookie=0x%08x%08x ",
135 GET_BE_U_4(cp
+ RRCP_COOKIE2_OFFSET
),
136 GET_BE_U_4(cp
+ RRCP_COOKIE1_OFFSET
));
141 * Print Realtek packets.
143 * See, for example, section 8.22 "Realtek Echo Protocol" of
145 * http://realtek.info/pdf/rtl8324.pdf
147 * and section 7.24 "Realtek Echo Protocol" of
149 * http://realtek.info/pdf/rtl8326.pdf
151 * for information on REP.
153 * See section 8.21 "Network Loop Connection Fault Detection" of
155 * http://realtek.info/pdf/rtl8324.pdf
157 * and section 7.23 "Network Loop Connection Fault Detection" of
159 * http://realtek.info/pdf/rtl8326.pdf
161 * for information on RLDP.
163 * See also section 7.3.8 "Loop Detection" of
165 * http://www.ibselectronics.com/ibsstore/datasheet/RTL8306E-CG.pdf
167 * (revision 1.1 of the RTL8306E-CG datasheet), which describes a loop
168 * detection protocol for which the payload has a 16-bit (presumably
169 * big-endian) field containing the value 0x0300, followed by what is
170 * presumably a 16-bit big-endian field the upper 12 bits of which are 0
171 * and the lower 4 bits of which are a TTL value, followed by zeroes to
172 * pad the packet out to the minimum Ethernet packet size.
174 * See also section 7.3.13 "Loop Detection" of
176 * http://realtek.info/pdf/rtl8305sb.pdf
178 * (revision 1.3 of the RTL8305SB datasheet), which describes a similar
179 * loop detection protocol that lacks the TTL field - all the bytes
180 * after 0x0300 are zero.
182 * See also section 7.3.7 "Loop Detection" of
184 * https://datasheet.lcsc.com/lcsc/1810221720_Realtek-Semicon-RTL8305NB-CG_C52146.pdf
186 * (revision 1.0 of the RTL8305NB-CT datasheet), which describes a loop
187 * detection protocol similar to the one from the RTL8306E-CG datasheet,
188 * except that the first value is 0x2300, not 0x0300.
190 * And, on top of all that, I've seen packets where the first octet of
191 * the packet is 0x23, and that's followed by 6 unknown octets (a MAC
192 * address of some sort? It differs from packet to packet in a capture),
193 * followed by the MAC address that appears in the source address in the
194 * Ethernet header (possibly the originator, in case the packet is forwarded,
195 * in which case the forwarded packets won't have the source address from
196 * the Ethernet header there), followed by unknown stuff (0x0d followed by
197 * zeroes for all such packets in one capture, 0x01 followed by zeroes for
198 * all such packets in another capture, 0x07 followed by 0x20's for all
199 * such packets in yet another capture). The OpenRRCP issue at
200 * https://github.com/illarionov/OpenRRCP/issues/3 shows a capture
201 * similar to the last of those, but with 0x02 instead of 0x07. Or is that
202 * just crap in the buffer in which the chip constructed the packet, left
203 * over from something else?
206 rtl_print(netdissect_options
*ndo
,
209 const struct lladdr_info
*src
,
210 const struct lladdr_info
*dst
)
214 ndo
->ndo_protocol
= "rtl";
216 if (src
!= NULL
&& dst
!= NULL
) {
217 ND_PRINT("%s > %s, ",
218 (src
->addr_string
)(ndo
, src
->addr
),
219 (dst
->addr_string
)(ndo
, dst
->addr
));
222 rtl_proto
= GET_U_1(cp
+ RTL_PROTOCOL_OFFSET
);
224 if (rtl_proto
== RTL_PROTOCOL_RRCP
)
226 else if (rtl_proto
== RTL_PROTOCOL_REP
) {
228 * REP packets have no payload.
231 } else if (rtl_proto
== RTL_PROTOCOL_RLDP
||
232 rtl_proto
== RTL_PROTOCOL_RLDP2
) {
234 * RLDP packets have no payload.
235 * (XXX - except when they do? See above.)
238 } else if (rtl_proto
== RTL_PROTOCOL_XXX_DSA
)
239 ND_PRINT("Realtek 8-byte DSA tag");
240 else if ((rtl_proto
& 0xF0) == RTL_PROTOCOL_8306_DSA
)
241 ND_PRINT("Realtek RTL8306 4-byte DSA tag");
242 else if ((rtl_proto
& 0xF0) == RTL_PROTOCOL_8366RB_DSA
)
243 ND_PRINT("Realtek RTL8366RB 4-byte DSA tag");
245 ND_PRINT("Realtek unknown type 0x%02x", rtl_proto
);