2 * Copyright (c) 2007 - Andrey "nording" Chernyak <andrew@nording.ru>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code distributions
6 * retain the above copyright notice and this paragraph in its entirety, (2)
7 * distributions including binary code include the above copyright notice and
8 * this paragraph in its entirety in the documentation or other materials
9 * provided with the distribution, and (3) all advertising materials mentioning
10 * features or use of this software display the following acknowledgement:
11 * ``This product includes software developed by the University of California,
12 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13 * the University nor the names of its contributors may be used to endorse
14 * or promote products derived from this software without specific prior
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 * Format and print Realtek Remote Control Protocol (RRCP)
21 * and Realtek Echo Protocol (RRCP-REP) packets.
25 static const char rcsid
[] _U_
=
26 "@(#) $Header: /tcpdump/master/tcpdump/print-rrcp.c,v 1.1.2.2 2008-04-11 17:00:00 gianluca Exp $";
33 #include <tcpdump-stdinc.h>
38 #include "netdissect.h"
39 #include "addrtoname.h"
49 u_int16_t rrcp_ethertype
; /* 0x8899 */
50 u_int8_t rrcp_proto
; /* must be 0x01 */
51 u_int8_t rrcp_opcode
:7; /* 0x00 = hello, 0x01 = get, 0x02 = set */
52 u_int8_t rrcp_isreply
:1; /* 0 = request to switch, 1 = reply from switch */
53 u_int16_t rrcp_authkey
; /* 0x2379 by default */
54 u_int16_t rrcp_reg_addr
; /* register address */
55 u_int32_t rrcp_reg_data
; /* register data */
60 struct rrcp_helloreply_packet_t
62 u_int16_t rrcp_ethertype
; /* 0x8899 */
63 u_int8_t rrcp_proto
; /* must be 0x01 */
64 u_int8_t rrcp_opcode
:7; /* 0x00 = hello, 0x01 = get, 0x02 = set */
65 u_int8_t rrcp_isreply
:1; /* 0 = request to switch, 1 = reply from switch */
66 u_int16_t rrcp_authkey
; /* 0x2379 by default */
67 u_int8_t rrcp_downlink_port
; /* */
68 u_int8_t rrcp_uplink_port
; /* */
69 u_int8_t rrcp_uplink_mac
[ETH_ALEN
]; /* */
70 u_int16_t rrcp_chip_id
; /* */
71 u_int32_t rrcp_vendor_id
; /* */
79 rrcp_print(netdissect_options
*ndo
,
80 register const u_char
*cp
,
83 const struct rrcp_packet_t
*rrcp
;
84 const struct rrcp_helloreply_packet_t
*rrcp_hello
;
85 register const struct ether_header
*ep
;
89 ep
= (const struct ether_header
*)cp
;
90 rrcp
= (const struct rrcp_packet_t
*)(cp
+12);
91 rrcp_hello
= (const struct rrcp_helloreply_packet_t
*)(cp
+12);
93 if (rrcp
->rrcp_proto
==1){
94 strcpy(proto_str
,"RRCP");
95 }else if ( rrcp
->rrcp_proto
==2 ){
96 strcpy(proto_str
,"RRCP-REP");
98 sprintf(proto_str
,"RRCP-0x%02d",rrcp
->rrcp_proto
);
100 if (rrcp
->rrcp_opcode
==0){
101 strcpy(opcode_str
,"hello");
102 }else if ( rrcp
->rrcp_opcode
==1 ){
103 strcpy(opcode_str
,"get");
104 }else if ( rrcp
->rrcp_opcode
==2 ){
105 strcpy(opcode_str
,"set");
107 sprintf(opcode_str
,"unknown opcode (0x%02d)",rrcp
->rrcp_opcode
);
109 ND_PRINT((ndo
, "%s > %s, %s %s",
110 etheraddr_string(ESRC(ep
)),
111 etheraddr_string(EDST(ep
)),
112 proto_str
, rrcp
->rrcp_isreply
? "reply" : "query"));
113 if (rrcp
->rrcp_proto
==1){
114 ND_PRINT((ndo
, ": %s", opcode_str
));
116 if (rrcp
->rrcp_opcode
==1 || rrcp
->rrcp_opcode
==2){
117 ND_PRINT((ndo
, " addr=0x%04x, data=0x%04x",
118 rrcp
->rrcp_reg_addr
, rrcp
->rrcp_reg_data
, rrcp
->rrcp_authkey
));
120 if (rrcp
->rrcp_proto
==1){
121 ND_PRINT((ndo
, ", auth=0x%04x",
122 ntohs(rrcp
->rrcp_authkey
)));
124 if (rrcp
->rrcp_proto
==1 && rrcp
->rrcp_opcode
==0 && rrcp
->rrcp_isreply
){
125 ND_PRINT((ndo
, " downlink_port=%d, uplink_port=%d, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ",
126 rrcp_hello
->rrcp_downlink_port
,
127 rrcp_hello
->rrcp_uplink_port
,
128 etheraddr_string(rrcp_hello
->rrcp_uplink_mac
),
129 rrcp_hello
->rrcp_vendor_id
,
130 rrcp_hello
->rrcp_chip_id
));
131 }else if (rrcp
->rrcp_opcode
==1 || rrcp
->rrcp_opcode
==2 || rrcp
->rrcp_proto
==2){
132 ND_PRINT((ndo
, ", cookie=0x%08x%08x ",
133 rrcp
->cookie2
, rrcp
->cookie1
));