X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/91d032ddef9c198e4a78bccebbe33b38b6f5949b..d7b497cac78b6e22a66a6bae9bdec60a8044f67a:/print-rrcp.c diff --git a/print-rrcp.c b/print-rrcp.c index 5f24a43e..ddacf94c 100644 --- a/print-rrcp.c +++ b/print-rrcp.c @@ -21,13 +21,32 @@ * and Realtek Echo Protocol (RRCP-REP) packets. */ +/* \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 "interface.h" +#include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "ether.h" @@ -71,54 +90,54 @@ static const struct tok opcode_values[] = { void rrcp_print(netdissect_options *ndo, register const u_char *cp, - u_int length _U_) + u_int length _U_, + const struct lladdr_info *src, + const struct lladdr_info *dst) { - const u_char *rrcp; uint8_t rrcp_proto; uint8_t rrcp_opcode; - register const struct ether_header *ep; - - ep = (const struct ether_header *)cp; - rrcp = cp + ETHER_HDRLEN; - ND_TCHECK(*(rrcp + RRCP_PROTO_OFFSET)); - rrcp_proto = *(rrcp + RRCP_PROTO_OFFSET); - ND_TCHECK(*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET)); - rrcp_opcode = (*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_OPCODE_MASK; - ND_PRINT((ndo, "%s > %s, %s %s", - etheraddr_string(ndo, ESRC(ep)), - etheraddr_string(ndo, EDST(ep)), + ND_TCHECK(*(cp + RRCP_PROTO_OFFSET)); + rrcp_proto = EXTRACT_U_1(cp + RRCP_PROTO_OFFSET); + ND_TCHECK(*(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))); + } + ND_PRINT((ndo, "%s %s", tok2str(proto_values,"RRCP-0x%02x",rrcp_proto), - ((*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY) ? "reply" : "query")); + ((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))); } if (rrcp_opcode==1 || rrcp_opcode==2){ - ND_TCHECK2(*(rrcp + RRCP_REG_ADDR_OFFSET), 6); + ND_TCHECK_6(cp + RRCP_REG_ADDR_OFFSET); ND_PRINT((ndo, " addr=0x%04x, data=0x%08x", - EXTRACT_LE_16BITS(rrcp + RRCP_REG_ADDR_OFFSET), - EXTRACT_LE_32BITS(rrcp + RRCP_REG_DATA_OFFSET))); + EXTRACT_LE_U_2(cp + RRCP_REG_ADDR_OFFSET), + EXTRACT_LE_U_4(cp + RRCP_REG_DATA_OFFSET))); } if (rrcp_proto==1){ - ND_TCHECK2(*(rrcp + RRCP_AUTHKEY_OFFSET), 2); + ND_TCHECK_2(cp + RRCP_AUTHKEY_OFFSET); ND_PRINT((ndo, ", auth=0x%04x", - EXTRACT_16BITS(rrcp + RRCP_AUTHKEY_OFFSET))); + EXTRACT_BE_U_2(cp + RRCP_AUTHKEY_OFFSET))); } if (rrcp_proto==1 && rrcp_opcode==0 && - ((*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY)){ - ND_TCHECK2(*(rrcp + RRCP_VENDOR_ID_OFFSET), 4); + ((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 ", - *(rrcp + RRCP_DOWNLINK_PORT_OFFSET), - *(rrcp + RRCP_UPLINK_PORT_OFFSET), - etheraddr_string(ndo, rrcp + RRCP_UPLINK_MAC_OFFSET), - EXTRACT_32BITS(rrcp + RRCP_VENDOR_ID_OFFSET), - EXTRACT_16BITS(rrcp + RRCP_CHIP_ID_OFFSET))); + 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_TCHECK2(*(rrcp + RRCP_COOKIE2_OFFSET), 4); + ND_TCHECK_4(cp + RRCP_COOKIE2_OFFSET); ND_PRINT((ndo, ", cookie=0x%08x%08x ", - EXTRACT_32BITS(rrcp + RRCP_COOKIE2_OFFSET), - EXTRACT_32BITS(rrcp + RRCP_COOKIE1_OFFSET))); + EXTRACT_BE_U_4(cp + RRCP_COOKIE2_OFFSET), + EXTRACT_BE_U_4(cp + RRCP_COOKIE1_OFFSET))); } return;