]> The Tcpdump Group git mirrors - tcpdump/blob - print-rrcp.c
remove tcpdump's own CVS keywords
[tcpdump] / print-rrcp.c
1 /*
2 * Copyright (c) 2007 - Andrey "nording" Chernyak <andrew@nording.ru>
3 *
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
15 * written permission.
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.
19 *
20 * Format and print Realtek Remote Control Protocol (RRCP)
21 * and Realtek Echo Protocol (RRCP-REP) packets.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <tcpdump-stdinc.h>
29
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "netdissect.h"
34 #include "addrtoname.h"
35 #include "extract.h"
36 #include "ether.h"
37
38 #define RRCP_OPCODE_MASK 0x7F /* 0x00 = hello, 0x01 = get, 0x02 = set */
39 #define RRCP_ISREPLY 0x80 /* 0 = request to switch, 0x80 = reply from switch */
40
41 #define RRCP_PROTO_OFFSET 0 /* proto - 1 byte, must be 1 */
42 #define RRCP_OPCODE_ISREPLY_OFFSET 1 /* opcode and isreply flag - 1 byte */
43 #define RRCP_AUTHKEY_OFFSET 2 /* authorization key - 2 bytes, 0x2379 by default */
44
45 /* most packets */
46 #define RRCP_REG_ADDR_OFFSET 4 /* register address - 2 bytes */
47 #define RRCP_REG_DATA_OFFSET 6 /* register data - 4 bytes */
48 #define RRCP_COOKIE1_OFFSET 10 /* 4 bytes */
49 #define RRCP_COOKIE2_OFFSET 14 /* 4 bytes */
50
51 /* hello reply packets */
52 #define RRCP_DOWNLINK_PORT_OFFSET 4 /* 1 byte */
53 #define RRCP_UPLINK_PORT_OFFSET 5 /* 1 byte */
54 #define RRCP_UPLINK_MAC_OFFSET 6 /* 6 byte MAC address */
55 #define RRCP_CHIP_ID_OFFSET 12 /* 2 bytes */
56 #define RRCP_VENDOR_ID_OFFSET 14 /* 4 bytes */
57
58 static const struct tok proto_values[] = {
59 { 1, "RRCP" },
60 { 2, "RRCP-REP" },
61 { 0, NULL }
62 };
63
64 static const struct tok opcode_values[] = {
65 { 0, "hello" },
66 { 1, "get" },
67 { 2, "set" },
68 { 0, NULL }
69 };
70
71 /*
72 * Print RRCP requests
73 */
74 void
75 rrcp_print(netdissect_options *ndo,
76 register const u_char *cp,
77 u_int length _U_)
78 {
79 const u_char *rrcp;
80 u_int8_t rrcp_proto;
81 u_int8_t rrcp_opcode;
82 register const struct ether_header *ep;
83 char proto_str[16];
84 char opcode_str[32];
85
86 ep = (const struct ether_header *)cp;
87 rrcp = cp + ETHER_HDRLEN;
88
89 ND_TCHECK(*(rrcp + RRCP_PROTO_OFFSET));
90 rrcp_proto = *(rrcp + RRCP_PROTO_OFFSET);
91 ND_TCHECK(*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET));
92 rrcp_opcode = (*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_OPCODE_MASK;
93 ND_PRINT((ndo, "%s > %s, %s %s",
94 etheraddr_string(ESRC(ep)),
95 etheraddr_string(EDST(ep)),
96 tok2strbuf(proto_values,"RRCP-0x%02x",rrcp_proto,proto_str,sizeof(proto_str)),
97 ((*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY) ? "reply" : "query"));
98 if (rrcp_proto==1){
99 ND_PRINT((ndo, ": %s",
100 tok2strbuf(opcode_values,"unknown opcode (0x%02x)",rrcp_opcode,opcode_str,sizeof(opcode_str))));
101 }
102 if (rrcp_opcode==1 || rrcp_opcode==2){
103 ND_TCHECK2(*(rrcp + RRCP_REG_ADDR_OFFSET), 6);
104 ND_PRINT((ndo, " addr=0x%04x, data=0x%08x",
105 EXTRACT_LE_16BITS(rrcp + RRCP_REG_ADDR_OFFSET),
106 EXTRACT_LE_32BITS(rrcp + RRCP_REG_DATA_OFFSET)));
107 }
108 if (rrcp_proto==1){
109 ND_TCHECK2(*(rrcp + RRCP_AUTHKEY_OFFSET), 2);
110 ND_PRINT((ndo, ", auth=0x%04x",
111 EXTRACT_16BITS(rrcp + RRCP_AUTHKEY_OFFSET)));
112 }
113 if (rrcp_proto==1 && rrcp_opcode==0 &&
114 ((*(rrcp + RRCP_OPCODE_ISREPLY_OFFSET)) & RRCP_ISREPLY)){
115 ND_TCHECK2(*(rrcp + RRCP_VENDOR_ID_OFFSET), 4);
116 ND_PRINT((ndo, " downlink_port=%d, uplink_port=%d, uplink_mac=%s, vendor_id=%08x ,chip_id=%04x ",
117 *(rrcp + RRCP_DOWNLINK_PORT_OFFSET),
118 *(rrcp + RRCP_UPLINK_PORT_OFFSET),
119 etheraddr_string(rrcp + RRCP_UPLINK_MAC_OFFSET),
120 EXTRACT_32BITS(rrcp + RRCP_VENDOR_ID_OFFSET),
121 EXTRACT_16BITS(rrcp + RRCP_CHIP_ID_OFFSET)));
122 }else if (rrcp_opcode==1 || rrcp_opcode==2 || rrcp_proto==2){
123 ND_TCHECK2(*(rrcp + RRCP_COOKIE2_OFFSET), 4);
124 ND_PRINT((ndo, ", cookie=0x%08x%08x ",
125 EXTRACT_32BITS(rrcp + RRCP_COOKIE2_OFFSET),
126 EXTRACT_32BITS(rrcp + RRCP_COOKIE1_OFFSET)));
127 }
128 if (!ndo->ndo_vflag)
129 return;
130 return;
131
132 trunc:
133 ND_PRINT((ndo, "[|rrcp]"));
134 }