2008-02-06 18:47:53 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 - Andrey "nording" Chernyak <andrew@nording.ru>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code distributions
|
|
|
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
|
|
|
* distributions including binary code include the above copyright notice and
|
|
|
|
* this paragraph in its entirety in the documentation or other materials
|
|
|
|
* provided with the distribution, and (3) all advertising materials mentioning
|
|
|
|
* features or use of this software display the following acknowledgement:
|
|
|
|
* ``This product includes software developed by the University of California,
|
|
|
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
|
|
* the University nor the names of its contributors may be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* Format and print Realtek Remote Control Protocol (RRCP)
|
|
|
|
* and Realtek Echo Protocol (RRCP-REP) packets.
|
|
|
|
*/
|
|
|
|
|
2016-08-14 21:42:19 +08:00
|
|
|
/* \summary: Realtek Remote Control Protocol (RRCP) printer */
|
|
|
|
|
2017-11-19 08:48:34 +08:00
|
|
|
/*
|
|
|
|
* See, for example, section 8.20 "Realtek Remote Control Protocol" of
|
|
|
|
*
|
|
|
|
* http://realtek.info/pdf/rtl8324.pdf
|
|
|
|
*
|
|
|
|
* and section 7.22 "Realtek Remote Control Protocol" of
|
|
|
|
*
|
|
|
|
* http://realtek.info/pdf/rtl8326.pdf
|
|
|
|
*
|
|
|
|
* and this page on the OpenRRCP Wiki:
|
|
|
|
*
|
|
|
|
* http://openrrcp.org.ru/wiki/rrcp_protocol
|
|
|
|
*
|
|
|
|
* NOTE: none of them indicate the byte order of multi-byte fields in any
|
|
|
|
* obvious fashion.
|
|
|
|
*/
|
|
|
|
|
2008-02-06 18:47:53 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
2008-02-06 18:47:53 +08:00
|
|
|
#endif
|
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2008-02-06 18:47:53 +08:00
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
2008-02-06 18:47:53 +08:00
|
|
|
#include "addrtoname.h"
|
|
|
|
#include "extract.h"
|
|
|
|
|
2009-05-25 05:06:10 +08:00
|
|
|
#define RRCP_OPCODE_MASK 0x7F /* 0x00 = hello, 0x01 = get, 0x02 = set */
|
|
|
|
#define RRCP_ISREPLY 0x80 /* 0 = request to switch, 0x80 = reply from switch */
|
2008-02-06 18:47:53 +08:00
|
|
|
|
2009-05-25 05:06:10 +08:00
|
|
|
#define RRCP_PROTO_OFFSET 0 /* proto - 1 byte, must be 1 */
|
|
|
|
#define RRCP_OPCODE_ISREPLY_OFFSET 1 /* opcode and isreply flag - 1 byte */
|
|
|
|
#define RRCP_AUTHKEY_OFFSET 2 /* authorization key - 2 bytes, 0x2379 by default */
|
2008-02-06 18:47:53 +08:00
|
|
|
|
2009-05-25 05:06:10 +08:00
|
|
|
/* most packets */
|
|
|
|
#define RRCP_REG_ADDR_OFFSET 4 /* register address - 2 bytes */
|
|
|
|
#define RRCP_REG_DATA_OFFSET 6 /* register data - 4 bytes */
|
|
|
|
#define RRCP_COOKIE1_OFFSET 10 /* 4 bytes */
|
|
|
|
#define RRCP_COOKIE2_OFFSET 14 /* 4 bytes */
|
|
|
|
|
|
|
|
/* hello reply packets */
|
|
|
|
#define RRCP_DOWNLINK_PORT_OFFSET 4 /* 1 byte */
|
|
|
|
#define RRCP_UPLINK_PORT_OFFSET 5 /* 1 byte */
|
|
|
|
#define RRCP_UPLINK_MAC_OFFSET 6 /* 6 byte MAC address */
|
|
|
|
#define RRCP_CHIP_ID_OFFSET 12 /* 2 bytes */
|
|
|
|
#define RRCP_VENDOR_ID_OFFSET 14 /* 4 bytes */
|
2008-02-06 18:47:53 +08:00
|
|
|
|
2009-10-12 03:49:05 +08:00
|
|
|
static const struct tok proto_values[] = {
|
|
|
|
{ 1, "RRCP" },
|
|
|
|
{ 2, "RRCP-REP" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tok opcode_values[] = {
|
|
|
|
{ 0, "hello" },
|
|
|
|
{ 1, "get" },
|
|
|
|
{ 2, "set" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2008-02-06 18:47:53 +08:00
|
|
|
/*
|
|
|
|
* Print RRCP requests
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rrcp_print(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *cp,
|
2015-07-04 06:54:14 +08:00
|
|
|
u_int length _U_,
|
|
|
|
const struct lladdr_info *src,
|
|
|
|
const struct lladdr_info *dst)
|
2008-02-06 18:47:53 +08:00
|
|
|
{
|
2014-04-23 15:20:40 +08:00
|
|
|
uint8_t rrcp_proto;
|
|
|
|
uint8_t rrcp_opcode;
|
2008-02-06 18:47:53 +08:00
|
|
|
|
2018-03-14 23:54:17 +08:00
|
|
|
ndo->ndo_protocol = "rrcp";
|
2017-12-05 03:21:48 +08:00
|
|
|
ND_TCHECK_1(cp + RRCP_PROTO_OFFSET);
|
2017-11-23 06:54:09 +08:00
|
|
|
rrcp_proto = EXTRACT_U_1(cp + RRCP_PROTO_OFFSET);
|
2017-12-05 03:21:48 +08:00
|
|
|
ND_TCHECK_1(cp + RRCP_OPCODE_ISREPLY_OFFSET);
|
2017-11-23 06:54:09 +08:00
|
|
|
rrcp_opcode = EXTRACT_U_1((cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_OPCODE_MASK;
|
2015-07-04 06:54:14 +08:00
|
|
|
if (src != NULL && dst != NULL) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s > %s, ",
|
2015-07-04 06:54:14 +08:00
|
|
|
(src->addr_string)(ndo, src->addr),
|
2018-01-07 18:47:30 +08:00
|
|
|
(dst->addr_string)(ndo, dst->addr));
|
2015-07-04 06:54:14 +08:00
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s %s",
|
2015-06-29 22:53:06 +08:00
|
|
|
tok2str(proto_values,"RRCP-0x%02x",rrcp_proto),
|
2018-01-07 18:47:30 +08:00
|
|
|
((EXTRACT_U_1(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY) ? "reply" : "query");
|
2009-05-25 05:06:10 +08:00
|
|
|
if (rrcp_proto==1){
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(": %s",
|
|
|
|
tok2str(opcode_values,"unknown opcode (0x%02x)",rrcp_opcode));
|
2008-02-06 18:47:53 +08:00
|
|
|
}
|
2009-05-25 05:06:10 +08:00
|
|
|
if (rrcp_opcode==1 || rrcp_opcode==2){
|
2017-11-25 05:48:55 +08:00
|
|
|
ND_TCHECK_6(cp + RRCP_REG_ADDR_OFFSET);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" addr=0x%04x, data=0x%08x",
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_LE_U_2(cp + RRCP_REG_ADDR_OFFSET),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_LE_U_4(cp + RRCP_REG_DATA_OFFSET));
|
2008-02-06 18:47:53 +08:00
|
|
|
}
|
2009-05-25 05:06:10 +08:00
|
|
|
if (rrcp_proto==1){
|
2017-11-25 05:48:55 +08:00
|
|
|
ND_TCHECK_2(cp + RRCP_AUTHKEY_OFFSET);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", auth=0x%04x",
|
|
|
|
EXTRACT_BE_U_2(cp + RRCP_AUTHKEY_OFFSET));
|
2008-02-06 18:47:53 +08:00
|
|
|
}
|
2009-05-25 05:06:10 +08:00
|
|
|
if (rrcp_proto==1 && rrcp_opcode==0 &&
|
2017-11-29 15:00:50 +08:00
|
|
|
((EXTRACT_U_1(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY)){
|
2017-11-25 05:48:55 +08:00
|
|
|
ND_TCHECK_4(cp + RRCP_VENDOR_ID_OFFSET);
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(" downlink_port=%u, uplink_port=%u, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ",
|
2017-11-27 04:33:24 +08:00
|
|
|
EXTRACT_U_1(cp + RRCP_DOWNLINK_PORT_OFFSET),
|
|
|
|
EXTRACT_U_1(cp + RRCP_UPLINK_PORT_OFFSET),
|
2015-07-04 06:54:14 +08:00
|
|
|
etheraddr_string(ndo, cp + RRCP_UPLINK_MAC_OFFSET),
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_BE_U_4(cp + RRCP_VENDOR_ID_OFFSET),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_BE_U_2(cp + RRCP_CHIP_ID_OFFSET));
|
2009-05-25 05:06:10 +08:00
|
|
|
}else if (rrcp_opcode==1 || rrcp_opcode==2 || rrcp_proto==2){
|
2017-11-25 05:48:55 +08:00
|
|
|
ND_TCHECK_4(cp + RRCP_COOKIE2_OFFSET);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", cookie=0x%08x%08x ",
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_BE_U_4(cp + RRCP_COOKIE2_OFFSET),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_BE_U_4(cp + RRCP_COOKIE1_OFFSET));
|
2008-02-06 18:47:53 +08:00
|
|
|
}
|
2009-05-25 05:06:10 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
trunc:
|
2018-05-11 00:05:56 +08:00
|
|
|
nd_print_trunc(ndo);
|
2008-02-06 18:47:53 +08:00
|
|
|
}
|