153f17a9db278d33517d9888dd77848f554522a38JP Abgrall/* 253f17a9db278d33517d9888dd77848f554522a38JP Abgrall * Copyright (c) 2007 - Andrey "nording" Chernyak <andrew@nording.ru> 353f17a9db278d33517d9888dd77848f554522a38JP Abgrall * 453f17a9db278d33517d9888dd77848f554522a38JP Abgrall * Redistribution and use in source and binary forms, with or without 553f17a9db278d33517d9888dd77848f554522a38JP Abgrall * modification, are permitted provided that: (1) source code distributions 653f17a9db278d33517d9888dd77848f554522a38JP Abgrall * retain the above copyright notice and this paragraph in its entirety, (2) 753f17a9db278d33517d9888dd77848f554522a38JP Abgrall * distributions including binary code include the above copyright notice and 853f17a9db278d33517d9888dd77848f554522a38JP Abgrall * this paragraph in its entirety in the documentation or other materials 953f17a9db278d33517d9888dd77848f554522a38JP Abgrall * provided with the distribution, and (3) all advertising materials mentioning 1053f17a9db278d33517d9888dd77848f554522a38JP Abgrall * features or use of this software display the following acknowledgement: 1153f17a9db278d33517d9888dd77848f554522a38JP Abgrall * ``This product includes software developed by the University of California, 1253f17a9db278d33517d9888dd77848f554522a38JP Abgrall * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 1353f17a9db278d33517d9888dd77848f554522a38JP Abgrall * the University nor the names of its contributors may be used to endorse 1453f17a9db278d33517d9888dd77848f554522a38JP Abgrall * or promote products derived from this software without specific prior 1553f17a9db278d33517d9888dd77848f554522a38JP Abgrall * written permission. 1653f17a9db278d33517d9888dd77848f554522a38JP Abgrall * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 1753f17a9db278d33517d9888dd77848f554522a38JP Abgrall * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 1853f17a9db278d33517d9888dd77848f554522a38JP Abgrall * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1953f17a9db278d33517d9888dd77848f554522a38JP Abgrall * 2053f17a9db278d33517d9888dd77848f554522a38JP Abgrall * Format and print Realtek Remote Control Protocol (RRCP) 2153f17a9db278d33517d9888dd77848f554522a38JP Abgrall * and Realtek Echo Protocol (RRCP-REP) packets. 2253f17a9db278d33517d9888dd77848f554522a38JP Abgrall */ 2353f17a9db278d33517d9888dd77848f554522a38JP Abgrall 24e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes/* \summary: Realtek Remote Control Protocol (RRCP) printer */ 25e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes 2653f17a9db278d33517d9888dd77848f554522a38JP Abgrall#ifdef HAVE_CONFIG_H 2753f17a9db278d33517d9888dd77848f554522a38JP Abgrall#include "config.h" 2853f17a9db278d33517d9888dd77848f554522a38JP Abgrall#endif 2953f17a9db278d33517d9888dd77848f554522a38JP Abgrall 30e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include <netdissect-stdinc.h> 3153f17a9db278d33517d9888dd77848f554522a38JP Abgrall 32e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include "netdissect.h" 3353f17a9db278d33517d9888dd77848f554522a38JP Abgrall#include "addrtoname.h" 3453f17a9db278d33517d9888dd77848f554522a38JP Abgrall#include "extract.h" 3553f17a9db278d33517d9888dd77848f554522a38JP Abgrall#include "ether.h" 3653f17a9db278d33517d9888dd77848f554522a38JP Abgrall 3753f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_OPCODE_MASK 0x7F /* 0x00 = hello, 0x01 = get, 0x02 = set */ 3853f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_ISREPLY 0x80 /* 0 = request to switch, 0x80 = reply from switch */ 3953f17a9db278d33517d9888dd77848f554522a38JP Abgrall 4053f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_PROTO_OFFSET 0 /* proto - 1 byte, must be 1 */ 4153f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_OPCODE_ISREPLY_OFFSET 1 /* opcode and isreply flag - 1 byte */ 4253f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_AUTHKEY_OFFSET 2 /* authorization key - 2 bytes, 0x2379 by default */ 4353f17a9db278d33517d9888dd77848f554522a38JP Abgrall 4453f17a9db278d33517d9888dd77848f554522a38JP Abgrall/* most packets */ 4553f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_REG_ADDR_OFFSET 4 /* register address - 2 bytes */ 4653f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_REG_DATA_OFFSET 6 /* register data - 4 bytes */ 4753f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_COOKIE1_OFFSET 10 /* 4 bytes */ 4853f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_COOKIE2_OFFSET 14 /* 4 bytes */ 4953f17a9db278d33517d9888dd77848f554522a38JP Abgrall 5053f17a9db278d33517d9888dd77848f554522a38JP Abgrall/* hello reply packets */ 5153f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_DOWNLINK_PORT_OFFSET 4 /* 1 byte */ 5253f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_UPLINK_PORT_OFFSET 5 /* 1 byte */ 5353f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_UPLINK_MAC_OFFSET 6 /* 6 byte MAC address */ 5453f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_CHIP_ID_OFFSET 12 /* 2 bytes */ 5553f17a9db278d33517d9888dd77848f554522a38JP Abgrall#define RRCP_VENDOR_ID_OFFSET 14 /* 4 bytes */ 5653f17a9db278d33517d9888dd77848f554522a38JP Abgrall 5753f17a9db278d33517d9888dd77848f554522a38JP Abgrallstatic const struct tok proto_values[] = { 5853f17a9db278d33517d9888dd77848f554522a38JP Abgrall { 1, "RRCP" }, 5953f17a9db278d33517d9888dd77848f554522a38JP Abgrall { 2, "RRCP-REP" }, 6053f17a9db278d33517d9888dd77848f554522a38JP Abgrall { 0, NULL } 6153f17a9db278d33517d9888dd77848f554522a38JP Abgrall}; 6253f17a9db278d33517d9888dd77848f554522a38JP Abgrall 6353f17a9db278d33517d9888dd77848f554522a38JP Abgrallstatic const struct tok opcode_values[] = { 6453f17a9db278d33517d9888dd77848f554522a38JP Abgrall { 0, "hello" }, 6553f17a9db278d33517d9888dd77848f554522a38JP Abgrall { 1, "get" }, 6653f17a9db278d33517d9888dd77848f554522a38JP Abgrall { 2, "set" }, 6753f17a9db278d33517d9888dd77848f554522a38JP Abgrall { 0, NULL } 6853f17a9db278d33517d9888dd77848f554522a38JP Abgrall}; 6953f17a9db278d33517d9888dd77848f554522a38JP Abgrall 7053f17a9db278d33517d9888dd77848f554522a38JP Abgrall/* 7153f17a9db278d33517d9888dd77848f554522a38JP Abgrall * Print RRCP requests 7253f17a9db278d33517d9888dd77848f554522a38JP Abgrall */ 7353f17a9db278d33517d9888dd77848f554522a38JP Abgrallvoid 7453f17a9db278d33517d9888dd77848f554522a38JP Abgrallrrcp_print(netdissect_options *ndo, 7553f17a9db278d33517d9888dd77848f554522a38JP Abgrall register const u_char *cp, 76e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes u_int length _U_, 77e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes const struct lladdr_info *src, 78e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes const struct lladdr_info *dst) 7953f17a9db278d33517d9888dd77848f554522a38JP Abgrall{ 80892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughes uint8_t rrcp_proto; 81892a68bdf2f50b40781212e4d7ee7369c8165953Elliott Hughes uint8_t rrcp_opcode; 8253f17a9db278d33517d9888dd77848f554522a38JP Abgrall 83e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes ND_TCHECK(*(cp + RRCP_PROTO_OFFSET)); 84e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes rrcp_proto = *(cp + RRCP_PROTO_OFFSET); 85e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes ND_TCHECK(*(cp + RRCP_OPCODE_ISREPLY_OFFSET)); 86e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes rrcp_opcode = (*(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_OPCODE_MASK; 87e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes if (src != NULL && dst != NULL) { 88e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes ND_PRINT((ndo, "%s > %s, ", 89e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes (src->addr_string)(ndo, src->addr), 90e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes (dst->addr_string)(ndo, dst->addr))); 91e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes } 92e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes ND_PRINT((ndo, "%s %s", 93e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes tok2str(proto_values,"RRCP-0x%02x",rrcp_proto), 94e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes ((*(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY) ? "reply" : "query")); 9553f17a9db278d33517d9888dd77848f554522a38JP Abgrall if (rrcp_proto==1){ 9653f17a9db278d33517d9888dd77848f554522a38JP Abgrall ND_PRINT((ndo, ": %s", 97e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes tok2str(opcode_values,"unknown opcode (0x%02x)",rrcp_opcode))); 9853f17a9db278d33517d9888dd77848f554522a38JP Abgrall } 9953f17a9db278d33517d9888dd77848f554522a38JP Abgrall if (rrcp_opcode==1 || rrcp_opcode==2){ 100e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes ND_TCHECK2(*(cp + RRCP_REG_ADDR_OFFSET), 6); 10153f17a9db278d33517d9888dd77848f554522a38JP Abgrall ND_PRINT((ndo, " addr=0x%04x, data=0x%08x", 102e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes EXTRACT_LE_16BITS(cp + RRCP_REG_ADDR_OFFSET), 103e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes EXTRACT_LE_32BITS(cp + RRCP_REG_DATA_OFFSET))); 10453f17a9db278d33517d9888dd77848f554522a38JP Abgrall } 10553f17a9db278d33517d9888dd77848f554522a38JP Abgrall if (rrcp_proto==1){ 106e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes ND_TCHECK2(*(cp + RRCP_AUTHKEY_OFFSET), 2); 10753f17a9db278d33517d9888dd77848f554522a38JP Abgrall ND_PRINT((ndo, ", auth=0x%04x", 108e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes EXTRACT_16BITS(cp + RRCP_AUTHKEY_OFFSET))); 10953f17a9db278d33517d9888dd77848f554522a38JP Abgrall } 11053f17a9db278d33517d9888dd77848f554522a38JP Abgrall if (rrcp_proto==1 && rrcp_opcode==0 && 111e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes ((*(cp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY)){ 112e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes ND_TCHECK2(*(cp + RRCP_VENDOR_ID_OFFSET), 4); 11353f17a9db278d33517d9888dd77848f554522a38JP Abgrall ND_PRINT((ndo, " downlink_port=%d, uplink_port=%d, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ", 114e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *(cp + RRCP_DOWNLINK_PORT_OFFSET), 115e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *(cp + RRCP_UPLINK_PORT_OFFSET), 116e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes etheraddr_string(ndo, cp + RRCP_UPLINK_MAC_OFFSET), 117e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes EXTRACT_32BITS(cp + RRCP_VENDOR_ID_OFFSET), 118e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes EXTRACT_16BITS(cp + RRCP_CHIP_ID_OFFSET))); 11953f17a9db278d33517d9888dd77848f554522a38JP Abgrall }else if (rrcp_opcode==1 || rrcp_opcode==2 || rrcp_proto==2){ 120e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes ND_TCHECK2(*(cp + RRCP_COOKIE2_OFFSET), 4); 12153f17a9db278d33517d9888dd77848f554522a38JP Abgrall ND_PRINT((ndo, ", cookie=0x%08x%08x ", 122e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes EXTRACT_32BITS(cp + RRCP_COOKIE2_OFFSET), 123e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes EXTRACT_32BITS(cp + RRCP_COOKIE1_OFFSET))); 12453f17a9db278d33517d9888dd77848f554522a38JP Abgrall } 12553f17a9db278d33517d9888dd77848f554522a38JP Abgrall return; 12653f17a9db278d33517d9888dd77848f554522a38JP Abgrall 12753f17a9db278d33517d9888dd77848f554522a38JP Abgralltrunc: 12853f17a9db278d33517d9888dd77848f554522a38JP Abgrall ND_PRINT((ndo, "[|rrcp]")); 12953f17a9db278d33517d9888dd77848f554522a38JP Abgrall} 130