blob: 9803f75fe4fabc7af0ab0661a7c55b9a394a9b40 [file] [log] [blame]
JP Abgrall53f17a92014-02-12 14:02:41 -08001/*
2 * Copyright (c) 2007 - Andrey "nording" Chernyak <andrew@nording.ru>
3 *
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
15 * written permission.
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.
19 *
20 * Format and print Realtek Remote Control Protocol (RRCP)
21 * and Realtek Echo Protocol (RRCP-REP) packets.
22 */
23
Elliott Hughese2e3bd12017-05-15 10:59:29 -070024/* \summary: Realtek Remote Control Protocol (RRCP) printer */
25
Elliott Hughes820eced2021-08-20 18:00:50 -070026/*
27 * See, for example, section 8.20 "Realtek Remote Control Protocol" of
28 *
29 * http://realtek.info/pdf/rtl8324.pdf
30 *
31 * and section 7.22 "Realtek Remote Control Protocol" of
32 *
33 * http://realtek.info/pdf/rtl8326.pdf
34 *
35 * and this page on the OpenRRCP Wiki:
36 *
37 * http://openrrcp.org.ru/wiki/rrcp_protocol
38 *
39 * NOTE: none of them indicate the byte order of multi-byte fields in any
40 * obvious fashion.
41 */
42
JP Abgrall53f17a92014-02-12 14:02:41 -080043#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070044#include <config.h>
JP Abgrall53f17a92014-02-12 14:02:41 -080045#endif
46
Elliott Hughes820eced2021-08-20 18:00:50 -070047#include "netdissect-stdinc.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080048
Elliott Hughese2e3bd12017-05-15 10:59:29 -070049#include "netdissect.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080050#include "addrtoname.h"
51#include "extract.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080052
JP Abgrall53f17a92014-02-12 14:02:41 -080053#define RRCP_OPCODE_MASK 0x7F /* 0x00 = hello, 0x01 = get, 0x02 = set */
54#define RRCP_ISREPLY 0x80 /* 0 = request to switch, 0x80 = reply from switch */
55
56#define RRCP_PROTO_OFFSET 0 /* proto - 1 byte, must be 1 */
57#define RRCP_OPCODE_ISREPLY_OFFSET 1 /* opcode and isreply flag - 1 byte */
58#define RRCP_AUTHKEY_OFFSET 2 /* authorization key - 2 bytes, 0x2379 by default */
59
60/* most packets */
61#define RRCP_REG_ADDR_OFFSET 4 /* register address - 2 bytes */
62#define RRCP_REG_DATA_OFFSET 6 /* register data - 4 bytes */
63#define RRCP_COOKIE1_OFFSET 10 /* 4 bytes */
64#define RRCP_COOKIE2_OFFSET 14 /* 4 bytes */
65
66/* hello reply packets */
67#define RRCP_DOWNLINK_PORT_OFFSET 4 /* 1 byte */
68#define RRCP_UPLINK_PORT_OFFSET 5 /* 1 byte */
69#define RRCP_UPLINK_MAC_OFFSET 6 /* 6 byte MAC address */
70#define RRCP_CHIP_ID_OFFSET 12 /* 2 bytes */
71#define RRCP_VENDOR_ID_OFFSET 14 /* 4 bytes */
72
73static const struct tok proto_values[] = {
74 { 1, "RRCP" },
75 { 2, "RRCP-REP" },
76 { 0, NULL }
77};
78
79static const struct tok opcode_values[] = {
80 { 0, "hello" },
81 { 1, "get" },
82 { 2, "set" },
83 { 0, NULL }
84};
85
86/*
87 * Print RRCP requests
88 */
89void
90rrcp_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -070091 const u_char *cp,
Elliott Hughese2e3bd12017-05-15 10:59:29 -070092 u_int length _U_,
93 const struct lladdr_info *src,
94 const struct lladdr_info *dst)
JP Abgrall53f17a92014-02-12 14:02:41 -080095{
Elliott Hughes892a68b2015-10-19 14:43:53 -070096 uint8_t rrcp_proto;
97 uint8_t rrcp_opcode;
JP Abgrall53f17a92014-02-12 14:02:41 -080098
Elliott Hughes820eced2021-08-20 18:00:50 -070099 ndo->ndo_protocol = "rrcp";
100 rrcp_proto = GET_U_1(cp + RRCP_PROTO_OFFSET);
101 rrcp_opcode = GET_U_1((cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_OPCODE_MASK;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700102 if (src != NULL && dst != NULL) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700103 ND_PRINT("%s > %s, ",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700104 (src->addr_string)(ndo, src->addr),
Elliott Hughes820eced2021-08-20 18:00:50 -0700105 (dst->addr_string)(ndo, dst->addr));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700106 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700107 ND_PRINT("%s %s",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700108 tok2str(proto_values,"RRCP-0x%02x",rrcp_proto),
Elliott Hughes820eced2021-08-20 18:00:50 -0700109 ((GET_U_1(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY) ? "reply" : "query");
JP Abgrall53f17a92014-02-12 14:02:41 -0800110 if (rrcp_proto==1){
Elliott Hughes820eced2021-08-20 18:00:50 -0700111 ND_PRINT(": %s",
112 tok2str(opcode_values,"unknown opcode (0x%02x)",rrcp_opcode));
JP Abgrall53f17a92014-02-12 14:02:41 -0800113 }
114 if (rrcp_opcode==1 || rrcp_opcode==2){
Elliott Hughes820eced2021-08-20 18:00:50 -0700115 ND_PRINT(" addr=0x%04x, data=0x%08x",
116 GET_LE_U_2(cp + RRCP_REG_ADDR_OFFSET),
117 GET_LE_U_4(cp + RRCP_REG_DATA_OFFSET));
JP Abgrall53f17a92014-02-12 14:02:41 -0800118 }
119 if (rrcp_proto==1){
Elliott Hughes820eced2021-08-20 18:00:50 -0700120 ND_PRINT(", auth=0x%04x",
121 GET_BE_U_2(cp + RRCP_AUTHKEY_OFFSET));
JP Abgrall53f17a92014-02-12 14:02:41 -0800122 }
123 if (rrcp_proto==1 && rrcp_opcode==0 &&
Elliott Hughes820eced2021-08-20 18:00:50 -0700124 ((GET_U_1(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY)){
125 ND_PRINT(" downlink_port=%u, uplink_port=%u, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ",
126 GET_U_1(cp + RRCP_DOWNLINK_PORT_OFFSET),
127 GET_U_1(cp + RRCP_UPLINK_PORT_OFFSET),
128 GET_ETHERADDR_STRING(cp + RRCP_UPLINK_MAC_OFFSET),
129 GET_BE_U_4(cp + RRCP_VENDOR_ID_OFFSET),
130 GET_BE_U_2(cp + RRCP_CHIP_ID_OFFSET));
JP Abgrall53f17a92014-02-12 14:02:41 -0800131 }else if (rrcp_opcode==1 || rrcp_opcode==2 || rrcp_proto==2){
Elliott Hughes820eced2021-08-20 18:00:50 -0700132 ND_PRINT(", cookie=0x%08x%08x ",
133 GET_BE_U_4(cp + RRCP_COOKIE2_OFFSET),
134 GET_BE_U_4(cp + RRCP_COOKIE1_OFFSET));
JP Abgrall53f17a92014-02-12 14:02:41 -0800135 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800136}