nvi - Work around problem with git
[dragonfly.git] / contrib / tcpdump / print-rrcp.c
blobdc3045793be9db9a40b21b6ea68d49ee14b03183
1 /*
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
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.
20 * Format and print Realtek Remote Control Protocol (RRCP)
21 * and Realtek Echo Protocol (RRCP-REP) packets.
24 #ifndef lint
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 $";
27 #endif
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
33 #include <tcpdump-stdinc.h>
35 #include <stdio.h>
36 #include <string.h>
38 #include "netdissect.h"
39 #include "addrtoname.h"
40 #include "extract.h"
41 #include "ether.h"
43 #ifndef ETH_ALEN
44 #define ETH_ALEN 6
45 #endif
47 struct rrcp_packet_t
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 */
56 u_int32_t cookie1;
57 u_int32_t cookie2;
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; /* */
76 * Print RRCP requests
78 void
79 rrcp_print(netdissect_options *ndo,
80 register const u_char *cp,
81 u_int length _U_)
83 const struct rrcp_packet_t *rrcp;
84 const struct rrcp_helloreply_packet_t *rrcp_hello;
85 register const struct ether_header *ep;
86 char proto_str[16];
87 char opcode_str[32];
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");
97 }else{
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");
106 }else{
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));
135 if (!ndo->ndo_vflag)
136 return;