X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/44b03896e9ebfa87fb5d60eb0ca2206707d595cf..1a04b92e365f5ed01ca38619b41bcc4fc9cbd63c:/print-rrcp.c diff --git a/print-rrcp.c b/print-rrcp.c index dfb536ab..0885f646 100644 --- a/print-rrcp.c +++ b/print-rrcp.c @@ -21,117 +21,125 @@ * and Realtek Echo Protocol (RRCP-REP) packets. */ -#ifndef lint -static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-rrcp.c,v 1.2 2008-04-11 17:21:34 gianluca Exp $"; -#endif +/* \summary: Realtek Remote Control Protocol (RRCP) printer */ + +/* + * 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. + */ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include - -#include -#include +#include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" -#include "ether.h" -#ifndef ETH_ALEN -#define ETH_ALEN 6 -#endif +#define RRCP_OPCODE_MASK 0x7F /* 0x00 = hello, 0x01 = get, 0x02 = set */ +#define RRCP_ISREPLY 0x80 /* 0 = request to switch, 0x80 = reply from switch */ -struct rrcp_packet_t -{ - u_int16_t rrcp_ethertype; /* 0x8899 */ - u_int8_t rrcp_proto; /* must be 0x01 */ - u_int8_t rrcp_opcode:7; /* 0x00 = hello, 0x01 = get, 0x02 = set */ - u_int8_t rrcp_isreply:1; /* 0 = request to switch, 1 = reply from switch */ - u_int16_t rrcp_authkey; /* 0x2379 by default */ - u_int16_t rrcp_reg_addr; /* register address */ - u_int32_t rrcp_reg_data; /* register data */ - u_int32_t cookie1; - u_int32_t cookie2; -}; +#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 */ -struct rrcp_helloreply_packet_t -{ - u_int16_t rrcp_ethertype; /* 0x8899 */ - u_int8_t rrcp_proto; /* must be 0x01 */ - u_int8_t rrcp_opcode:7; /* 0x00 = hello, 0x01 = get, 0x02 = set */ - u_int8_t rrcp_isreply:1; /* 0 = request to switch, 1 = reply from switch */ - u_int16_t rrcp_authkey; /* 0x2379 by default */ - u_int8_t rrcp_downlink_port; /* */ - u_int8_t rrcp_uplink_port; /* */ - u_int8_t rrcp_uplink_mac[ETH_ALEN]; /* */ - u_int16_t rrcp_chip_id; /* */ - u_int32_t rrcp_vendor_id; /* */ +/* 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 */ + +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 } +}; /* * Print RRCP requests */ void rrcp_print(netdissect_options *ndo, - register const u_char *cp, - u_int length _U_) + const u_char *cp, + u_int length _U_, + const struct lladdr_info *src, + const struct lladdr_info *dst) { - const struct rrcp_packet_t *rrcp; - const struct rrcp_helloreply_packet_t *rrcp_hello; - register const struct ether_header *ep; - char proto_str[16]; - char opcode_str[32]; - - ep = (const struct ether_header *)cp; - rrcp = (const struct rrcp_packet_t *)(cp+12); - rrcp_hello = (const struct rrcp_helloreply_packet_t *)(cp+12); + uint8_t rrcp_proto; + uint8_t rrcp_opcode; - if (rrcp->rrcp_proto==1){ - strcpy(proto_str,"RRCP"); - }else if ( rrcp->rrcp_proto==2 ){ - strcpy(proto_str,"RRCP-REP"); - }else{ - sprintf(proto_str,"RRCP-0x%02d",rrcp->rrcp_proto); + ND_TCHECK_1(cp + RRCP_PROTO_OFFSET); + rrcp_proto = EXTRACT_U_1(cp + RRCP_PROTO_OFFSET); + ND_TCHECK_1(cp + RRCP_OPCODE_ISREPLY_OFFSET); + rrcp_opcode = EXTRACT_U_1((cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_OPCODE_MASK; + if (src != NULL && dst != NULL) { + ND_PRINT((ndo, "%s > %s, ", + (src->addr_string)(ndo, src->addr), + (dst->addr_string)(ndo, dst->addr))); } - if (rrcp->rrcp_opcode==0){ - strcpy(opcode_str,"hello"); - }else if ( rrcp->rrcp_opcode==1 ){ - strcpy(opcode_str,"get"); - }else if ( rrcp->rrcp_opcode==2 ){ - strcpy(opcode_str,"set"); - }else{ - sprintf(opcode_str,"unknown opcode (0x%02d)",rrcp->rrcp_opcode); + ND_PRINT((ndo, "%s %s", + tok2str(proto_values,"RRCP-0x%02x",rrcp_proto), + ((EXTRACT_U_1(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY) ? "reply" : "query")); + if (rrcp_proto==1){ + ND_PRINT((ndo, ": %s", + tok2str(opcode_values,"unknown opcode (0x%02x)",rrcp_opcode))); } - ND_PRINT((ndo, "%s > %s, %s %s", - etheraddr_string(ESRC(ep)), - etheraddr_string(EDST(ep)), - proto_str, rrcp->rrcp_isreply ? "reply" : "query")); - if (rrcp->rrcp_proto==1){ - ND_PRINT((ndo, ": %s", opcode_str)); + if (rrcp_opcode==1 || rrcp_opcode==2){ + ND_TCHECK_6(cp + RRCP_REG_ADDR_OFFSET); + ND_PRINT((ndo, " addr=0x%04x, data=0x%08x", + EXTRACT_LE_U_2(cp + RRCP_REG_ADDR_OFFSET), + EXTRACT_LE_U_4(cp + RRCP_REG_DATA_OFFSET))); } - if (rrcp->rrcp_opcode==1 || rrcp->rrcp_opcode==2){ - ND_PRINT((ndo, " addr=0x%04x, data=0x%04x", - rrcp->rrcp_reg_addr, rrcp->rrcp_reg_data, rrcp->rrcp_authkey)); - } - if (rrcp->rrcp_proto==1){ + if (rrcp_proto==1){ + ND_TCHECK_2(cp + RRCP_AUTHKEY_OFFSET); ND_PRINT((ndo, ", auth=0x%04x", - ntohs(rrcp->rrcp_authkey))); + EXTRACT_BE_U_2(cp + RRCP_AUTHKEY_OFFSET))); } - if (rrcp->rrcp_proto==1 && rrcp->rrcp_opcode==0 && rrcp->rrcp_isreply){ - ND_PRINT((ndo, " downlink_port=%d, uplink_port=%d, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ", - rrcp_hello->rrcp_downlink_port, - rrcp_hello->rrcp_uplink_port, - etheraddr_string(rrcp_hello->rrcp_uplink_mac), - rrcp_hello->rrcp_vendor_id, - rrcp_hello->rrcp_chip_id)); - }else if (rrcp->rrcp_opcode==1 || rrcp->rrcp_opcode==2 || rrcp->rrcp_proto==2){ - ND_PRINT((ndo, ", cookie=0x%08x%08x ", - rrcp->cookie2, rrcp->cookie1)); + if (rrcp_proto==1 && rrcp_opcode==0 && + ((EXTRACT_U_1(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY)){ + ND_TCHECK_4(cp + RRCP_VENDOR_ID_OFFSET); + ND_PRINT((ndo, " downlink_port=%d, uplink_port=%d, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ", + EXTRACT_U_1(cp + RRCP_DOWNLINK_PORT_OFFSET), + EXTRACT_U_1(cp + RRCP_UPLINK_PORT_OFFSET), + etheraddr_string(ndo, cp + RRCP_UPLINK_MAC_OFFSET), + EXTRACT_BE_U_4(cp + RRCP_VENDOR_ID_OFFSET), + EXTRACT_BE_U_2(cp + RRCP_CHIP_ID_OFFSET))); + }else if (rrcp_opcode==1 || rrcp_opcode==2 || rrcp_proto==2){ + ND_TCHECK_4(cp + RRCP_COOKIE2_OFFSET); + ND_PRINT((ndo, ", cookie=0x%08x%08x ", + EXTRACT_BE_U_4(cp + RRCP_COOKIE2_OFFSET), + EXTRACT_BE_U_4(cp + RRCP_COOKIE1_OFFSET))); } - if (!ndo->ndo_vflag) - return; + return; + +trunc: + ND_PRINT((ndo, "[|rrcp]")); }