1ea7b4bf5SPeter Avalos /*
2ea7b4bf5SPeter Avalos * Copyright (c) 2007 - Andrey "nording" Chernyak <andrew@nording.ru>
3ea7b4bf5SPeter Avalos *
4ea7b4bf5SPeter Avalos * Redistribution and use in source and binary forms, with or without
5ea7b4bf5SPeter Avalos * modification, are permitted provided that: (1) source code distributions
6ea7b4bf5SPeter Avalos * retain the above copyright notice and this paragraph in its entirety, (2)
7ea7b4bf5SPeter Avalos * distributions including binary code include the above copyright notice and
8ea7b4bf5SPeter Avalos * this paragraph in its entirety in the documentation or other materials
9ea7b4bf5SPeter Avalos * provided with the distribution, and (3) all advertising materials mentioning
10ea7b4bf5SPeter Avalos * features or use of this software display the following acknowledgement:
11ea7b4bf5SPeter Avalos * ``This product includes software developed by the University of California,
12ea7b4bf5SPeter Avalos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13ea7b4bf5SPeter Avalos * the University nor the names of its contributors may be used to endorse
14ea7b4bf5SPeter Avalos * or promote products derived from this software without specific prior
15ea7b4bf5SPeter Avalos * written permission.
16ea7b4bf5SPeter Avalos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17ea7b4bf5SPeter Avalos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18ea7b4bf5SPeter Avalos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19ea7b4bf5SPeter Avalos *
20ea7b4bf5SPeter Avalos * Format and print Realtek Remote Control Protocol (RRCP)
21ea7b4bf5SPeter Avalos * and Realtek Echo Protocol (RRCP-REP) packets.
22ea7b4bf5SPeter Avalos */
23ea7b4bf5SPeter Avalos
24411677aeSAaron LI /* \summary: Realtek Remote Control Protocol (RRCP) printer */
25ea7b4bf5SPeter Avalos
26*ed775ee7SAntonio Huete Jimenez /*
27*ed775ee7SAntonio Huete Jimenez * See, for example, section 8.20 "Realtek Remote Control Protocol" of
28*ed775ee7SAntonio Huete Jimenez *
29*ed775ee7SAntonio Huete Jimenez * http://realtek.info/pdf/rtl8324.pdf
30*ed775ee7SAntonio Huete Jimenez *
31*ed775ee7SAntonio Huete Jimenez * and section 7.22 "Realtek Remote Control Protocol" of
32*ed775ee7SAntonio Huete Jimenez *
33*ed775ee7SAntonio Huete Jimenez * http://realtek.info/pdf/rtl8326.pdf
34*ed775ee7SAntonio Huete Jimenez *
35*ed775ee7SAntonio Huete Jimenez * and this page on the OpenRRCP Wiki:
36*ed775ee7SAntonio Huete Jimenez *
37*ed775ee7SAntonio Huete Jimenez * http://openrrcp.org.ru/wiki/rrcp_protocol
38*ed775ee7SAntonio Huete Jimenez *
39*ed775ee7SAntonio Huete Jimenez * NOTE: none of them indicate the byte order of multi-byte fields in any
40*ed775ee7SAntonio Huete Jimenez * obvious fashion.
41*ed775ee7SAntonio Huete Jimenez */
42*ed775ee7SAntonio Huete Jimenez
43ea7b4bf5SPeter Avalos #ifdef HAVE_CONFIG_H
44*ed775ee7SAntonio Huete Jimenez #include <config.h>
45ea7b4bf5SPeter Avalos #endif
46ea7b4bf5SPeter Avalos
47*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
48ea7b4bf5SPeter Avalos
49ea7b4bf5SPeter Avalos #include "netdissect.h"
50ea7b4bf5SPeter Avalos #include "addrtoname.h"
51ea7b4bf5SPeter Avalos #include "extract.h"
52ea7b4bf5SPeter Avalos
5327bfbee1SPeter Avalos #define RRCP_OPCODE_MASK 0x7F /* 0x00 = hello, 0x01 = get, 0x02 = set */
5427bfbee1SPeter Avalos #define RRCP_ISREPLY 0x80 /* 0 = request to switch, 0x80 = reply from switch */
5527bfbee1SPeter Avalos
5627bfbee1SPeter Avalos #define RRCP_PROTO_OFFSET 0 /* proto - 1 byte, must be 1 */
5727bfbee1SPeter Avalos #define RRCP_OPCODE_ISREPLY_OFFSET 1 /* opcode and isreply flag - 1 byte */
5827bfbee1SPeter Avalos #define RRCP_AUTHKEY_OFFSET 2 /* authorization key - 2 bytes, 0x2379 by default */
5927bfbee1SPeter Avalos
6027bfbee1SPeter Avalos /* most packets */
6127bfbee1SPeter Avalos #define RRCP_REG_ADDR_OFFSET 4 /* register address - 2 bytes */
6227bfbee1SPeter Avalos #define RRCP_REG_DATA_OFFSET 6 /* register data - 4 bytes */
6327bfbee1SPeter Avalos #define RRCP_COOKIE1_OFFSET 10 /* 4 bytes */
6427bfbee1SPeter Avalos #define RRCP_COOKIE2_OFFSET 14 /* 4 bytes */
6527bfbee1SPeter Avalos
6627bfbee1SPeter Avalos /* hello reply packets */
6727bfbee1SPeter Avalos #define RRCP_DOWNLINK_PORT_OFFSET 4 /* 1 byte */
6827bfbee1SPeter Avalos #define RRCP_UPLINK_PORT_OFFSET 5 /* 1 byte */
6927bfbee1SPeter Avalos #define RRCP_UPLINK_MAC_OFFSET 6 /* 6 byte MAC address */
7027bfbee1SPeter Avalos #define RRCP_CHIP_ID_OFFSET 12 /* 2 bytes */
7127bfbee1SPeter Avalos #define RRCP_VENDOR_ID_OFFSET 14 /* 4 bytes */
7227bfbee1SPeter Avalos
7327bfbee1SPeter Avalos static const struct tok proto_values[] = {
7427bfbee1SPeter Avalos { 1, "RRCP" },
7527bfbee1SPeter Avalos { 2, "RRCP-REP" },
7627bfbee1SPeter Avalos { 0, NULL }
77ea7b4bf5SPeter Avalos };
78ea7b4bf5SPeter Avalos
7927bfbee1SPeter Avalos static const struct tok opcode_values[] = {
8027bfbee1SPeter Avalos { 0, "hello" },
8127bfbee1SPeter Avalos { 1, "get" },
8227bfbee1SPeter Avalos { 2, "set" },
8327bfbee1SPeter Avalos { 0, NULL }
84ea7b4bf5SPeter Avalos };
85ea7b4bf5SPeter Avalos
86ea7b4bf5SPeter Avalos /*
87ea7b4bf5SPeter Avalos * Print RRCP requests
88ea7b4bf5SPeter Avalos */
89ea7b4bf5SPeter Avalos void
rrcp_print(netdissect_options * ndo,const u_char * cp,u_int length _U_,const struct lladdr_info * src,const struct lladdr_info * dst)90ea7b4bf5SPeter Avalos rrcp_print(netdissect_options *ndo,
91*ed775ee7SAntonio Huete Jimenez const u_char *cp,
92411677aeSAaron LI u_int length _U_,
93411677aeSAaron LI const struct lladdr_info *src,
94411677aeSAaron LI const struct lladdr_info *dst)
95ea7b4bf5SPeter Avalos {
96411677aeSAaron LI uint8_t rrcp_proto;
97411677aeSAaron LI uint8_t rrcp_opcode;
98ea7b4bf5SPeter Avalos
99*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "rrcp";
100*ed775ee7SAntonio Huete Jimenez rrcp_proto = GET_U_1(cp + RRCP_PROTO_OFFSET);
101*ed775ee7SAntonio Huete Jimenez rrcp_opcode = GET_U_1((cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_OPCODE_MASK;
102411677aeSAaron LI if (src != NULL && dst != NULL) {
103*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s > %s, ",
104411677aeSAaron LI (src->addr_string)(ndo, src->addr),
105*ed775ee7SAntonio Huete Jimenez (dst->addr_string)(ndo, dst->addr));
106411677aeSAaron LI }
107*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s %s",
108411677aeSAaron LI tok2str(proto_values,"RRCP-0x%02x",rrcp_proto),
109*ed775ee7SAntonio Huete Jimenez ((GET_U_1(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY) ? "reply" : "query");
11027bfbee1SPeter Avalos if (rrcp_proto==1){
111*ed775ee7SAntonio Huete Jimenez ND_PRINT(": %s",
112*ed775ee7SAntonio Huete Jimenez tok2str(opcode_values,"unknown opcode (0x%02x)",rrcp_opcode));
113ea7b4bf5SPeter Avalos }
11427bfbee1SPeter Avalos if (rrcp_opcode==1 || rrcp_opcode==2){
115*ed775ee7SAntonio Huete Jimenez ND_PRINT(" addr=0x%04x, data=0x%08x",
116*ed775ee7SAntonio Huete Jimenez GET_LE_U_2(cp + RRCP_REG_ADDR_OFFSET),
117*ed775ee7SAntonio Huete Jimenez GET_LE_U_4(cp + RRCP_REG_DATA_OFFSET));
118ea7b4bf5SPeter Avalos }
11927bfbee1SPeter Avalos if (rrcp_proto==1){
120*ed775ee7SAntonio Huete Jimenez ND_PRINT(", auth=0x%04x",
121*ed775ee7SAntonio Huete Jimenez GET_BE_U_2(cp + RRCP_AUTHKEY_OFFSET));
122ea7b4bf5SPeter Avalos }
12327bfbee1SPeter Avalos if (rrcp_proto==1 && rrcp_opcode==0 &&
124*ed775ee7SAntonio Huete Jimenez ((GET_U_1(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY)){
125*ed775ee7SAntonio Huete Jimenez ND_PRINT(" downlink_port=%u, uplink_port=%u, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ",
126*ed775ee7SAntonio Huete Jimenez GET_U_1(cp + RRCP_DOWNLINK_PORT_OFFSET),
127*ed775ee7SAntonio Huete Jimenez GET_U_1(cp + RRCP_UPLINK_PORT_OFFSET),
128*ed775ee7SAntonio Huete Jimenez GET_ETHERADDR_STRING(cp + RRCP_UPLINK_MAC_OFFSET),
129*ed775ee7SAntonio Huete Jimenez GET_BE_U_4(cp + RRCP_VENDOR_ID_OFFSET),
130*ed775ee7SAntonio Huete Jimenez GET_BE_U_2(cp + RRCP_CHIP_ID_OFFSET));
13127bfbee1SPeter Avalos }else if (rrcp_opcode==1 || rrcp_opcode==2 || rrcp_proto==2){
132*ed775ee7SAntonio Huete Jimenez ND_PRINT(", cookie=0x%08x%08x ",
133*ed775ee7SAntonio Huete Jimenez GET_BE_U_4(cp + RRCP_COOKIE2_OFFSET),
134*ed775ee7SAntonio Huete Jimenez GET_BE_U_4(cp + RRCP_COOKIE1_OFFSET));
135ea7b4bf5SPeter Avalos }
136ea7b4bf5SPeter Avalos }
137