2 * Copyright (c) 2014 The TCPDUMP project
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
17 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
18 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
28 /* \summary: ATA over Ethernet (AoE) protocol printer */
30 /* specification: http://brantleycoilecompany.com/AoEr11.pdf */
36 #include <netdissect-stdinc.h>
38 #include "netdissect.h"
40 #include "addrtoname.h"
43 static const char tstr[] = " [|aoe]";
46 #define ATA_SECTOR_SIZE 512
48 #define AOEV1_CMD_ISSUE_ATA_COMMAND 0
49 #define AOEV1_CMD_QUERY_CONFIG_INFORMATION 1
50 #define AOEV1_CMD_MAC_MASK_LIST 2
51 #define AOEV1_CMD_RESERVE_RELEASE 3
53 static const struct tok cmdcode_str[] = {
54 { AOEV1_CMD_ISSUE_ATA_COMMAND, "Issue ATA Command" },
55 { AOEV1_CMD_QUERY_CONFIG_INFORMATION, "Query Config Information" },
56 { AOEV1_CMD_MAC_MASK_LIST, "MAC Mask List" },
57 { AOEV1_CMD_RESERVE_RELEASE, "Reserve/Release" },
61 #define AOEV1_COMMON_HDR_LEN 10U /* up to but w/o Arg */
62 #define AOEV1_ISSUE_ARG_LEN 12U /* up to but w/o Data */
63 #define AOEV1_QUERY_ARG_LEN 8U /* up to but w/o Config String */
64 #define AOEV1_MAC_ARG_LEN 4U /* up to but w/o Directive 0 */
65 #define AOEV1_RESERVE_ARG_LEN 2U /* up to but w/o Ethernet address 0 */
66 #define AOEV1_MAX_CONFSTR_LEN 1024U
68 #define AOEV1_FLAG_R 0x08
69 #define AOEV1_FLAG_E 0x04
71 static const struct tok aoev1_flag_str[] = {
72 { AOEV1_FLAG_R, "Response" },
73 { AOEV1_FLAG_E, "Error" },
79 static const struct tok aoev1_errcode_str[] = {
80 { 1, "Unrecognized command code" },
81 { 2, "Bad argument parameter" },
82 { 3, "Device unavailable" },
83 { 4, "Config string present" },
84 { 5, "Unsupported version" },
85 { 6, "Target is reserved" },
89 #define AOEV1_AFLAG_E 0x40
90 #define AOEV1_AFLAG_D 0x10
91 #define AOEV1_AFLAG_A 0x02
92 #define AOEV1_AFLAG_W 0x01
94 static const struct tok aoev1_aflag_str[] = {
96 { AOEV1_AFLAG_E, "Ext48" },
98 { AOEV1_AFLAG_D, "Device" },
100 { 0x03, "MBZ-0x03" },
101 { AOEV1_AFLAG_A, "Async" },
102 { AOEV1_AFLAG_W, "Write" },
106 static const struct tok aoev1_ccmd_str[] = {
107 { 0, "read config string" },
108 { 1, "test config string" },
109 { 2, "test config string prefix" },
110 { 3, "set config string" },
111 { 4, "force set config string" },
115 static const struct tok aoev1_mcmd_str[] = {
116 { 0, "Read Mac Mask List" },
117 { 1, "Edit Mac Mask List" },
121 static const struct tok aoev1_merror_str[] = {
122 { 1, "Unspecified Error" },
123 { 2, "Bad DCmd directive" },
124 { 3, "Mask list full" },
128 static const struct tok aoev1_dcmd_str[] = {
129 { 0, "No Directive" },
130 { 1, "Add mac address to mask list" },
131 { 2, "Delete mac address from mask list" },
135 static const struct tok aoev1_rcmd_str[] = {
136 { 0, "Read reserve list" },
137 { 1, "Set reserve list" },
138 { 2, "Force set reserve list" },
143 aoev1_issue_print(netdissect_options *ndo,
144 const u_char *cp, const u_int len)
146 const u_char *ep = cp + len;
148 if (len < AOEV1_ISSUE_ARG_LEN)
152 ND_PRINT((ndo, "\n\tAFlags: [%s]", bittok2str(aoev1_aflag_str, "none", *cp)));
156 ND_PRINT((ndo, ", Err/Feature: %u", *cp));
158 /* Sector Count (not correlated with the length) */
160 ND_PRINT((ndo, ", Sector Count: %u", *cp));
164 ND_PRINT((ndo, ", Cmd/Status: %u", *cp));
168 ND_PRINT((ndo, "\n\tlba0: %u", *cp));
172 ND_PRINT((ndo, ", lba1: %u", *cp));
176 ND_PRINT((ndo, ", lba2: %u", *cp));
180 ND_PRINT((ndo, ", lba3: %u", *cp));
184 ND_PRINT((ndo, ", lba4: %u", *cp));
188 ND_PRINT((ndo, ", lba5: %u", *cp));
194 if (len > AOEV1_ISSUE_ARG_LEN)
195 ND_PRINT((ndo, "\n\tData: %u bytes", len - AOEV1_ISSUE_ARG_LEN));
199 ND_PRINT((ndo, "%s", istr));
200 ND_TCHECK2(*cp, ep - cp);
203 ND_PRINT((ndo, "%s", tstr));
207 aoev1_query_print(netdissect_options *ndo,
208 const u_char *cp, const u_int len)
210 const u_char *ep = cp + len;
213 if (len < AOEV1_QUERY_ARG_LEN)
217 ND_PRINT((ndo, "\n\tBuffer Count: %u", EXTRACT_16BITS(cp)));
219 /* Firmware Version */
221 ND_PRINT((ndo, ", Firmware Version: %u", EXTRACT_16BITS(cp)));
225 ND_PRINT((ndo, ", Sector Count: %u", *cp));
229 ND_PRINT((ndo, ", AoE: %u, CCmd: %s", (*cp & 0xF0) >> 4,
230 tok2str(aoev1_ccmd_str, "Unknown (0x02x)", *cp & 0x0F)));
232 /* Config String Length */
234 cslen = EXTRACT_16BITS(cp);
236 if (cslen > AOEV1_MAX_CONFSTR_LEN || AOEV1_QUERY_ARG_LEN + cslen > len)
239 ND_TCHECK2(*cp, cslen);
241 ND_PRINT((ndo, "\n\tConfig String (length %u): ", cslen));
242 if (fn_printn(ndo, cp, cslen, ndo->ndo_snapend))
248 ND_PRINT((ndo, "%s", istr));
249 ND_TCHECK2(*cp, ep - cp);
252 ND_PRINT((ndo, "%s", tstr));
256 aoev1_mac_print(netdissect_options *ndo,
257 const u_char *cp, const u_int len)
259 const u_char *ep = cp + len;
262 if (len < AOEV1_MAC_ARG_LEN)
269 ND_PRINT((ndo, "\n\tMCmd: %s", tok2str(aoev1_mcmd_str, "Unknown (0x%02x)", *cp)));
273 ND_PRINT((ndo, ", MError: %s", tok2str(aoev1_merror_str, "Unknown (0x%02x)", *cp)));
279 ND_PRINT((ndo, ", Dir Count: %u", dircount));
280 if (AOEV1_MAC_ARG_LEN + dircount * 8 > len)
283 for (i = 0; i < dircount; i++) {
289 ND_PRINT((ndo, "\n\t DCmd: %s", tok2str(aoev1_dcmd_str, "Unknown (0x%02x)", *cp)));
291 /* Ethernet Address */
292 ND_TCHECK2(*cp, ETHER_ADDR_LEN);
293 ND_PRINT((ndo, ", Ethernet Address: %s", etheraddr_string(ndo, cp)));
294 cp += ETHER_ADDR_LEN;
299 ND_PRINT((ndo, "%s", istr));
300 ND_TCHECK2(*cp, ep - cp);
303 ND_PRINT((ndo, "%s", tstr));
307 aoev1_reserve_print(netdissect_options *ndo,
308 const u_char *cp, const u_int len)
310 const u_char *ep = cp + len;
313 if (len < AOEV1_RESERVE_ARG_LEN || (len - AOEV1_RESERVE_ARG_LEN) % ETHER_ADDR_LEN)
317 ND_PRINT((ndo, "\n\tRCmd: %s", tok2str(aoev1_rcmd_str, "Unknown (0x%02x)", *cp)));
319 /* NMacs (correlated with the length) */
323 ND_PRINT((ndo, ", NMacs: %u", nmacs));
324 if (AOEV1_RESERVE_ARG_LEN + nmacs * ETHER_ADDR_LEN != len)
327 for (i = 0; i < nmacs; i++) {
328 ND_PRINT((ndo, "\n\tEthernet Address %u: %s", i, etheraddr_string(ndo, cp)));
329 cp += ETHER_ADDR_LEN;
334 ND_PRINT((ndo, "%s", istr));
335 ND_TCHECK2(*cp, ep - cp);
338 ND_PRINT((ndo, "%s", tstr));
341 /* cp points to the Ver/Flags octet */
343 aoev1_print(netdissect_options *ndo,
344 const u_char *cp, const u_int len)
346 const u_char *ep = cp + len;
347 uint8_t flags, command;
348 void (*cmd_decoder)(netdissect_options *, const u_char *, const u_int);
350 if (len < AOEV1_COMMON_HDR_LEN)
354 ND_PRINT((ndo, ", Flags: [%s]", bittok2str(aoev1_flag_str, "none", flags)));
356 if (! ndo->ndo_vflag)
360 if (flags & AOEV1_FLAG_E)
361 ND_PRINT((ndo, "\n\tError: %s", tok2str(aoev1_errcode_str, "Invalid (%u)", *cp)));
365 ND_PRINT((ndo, "\n\tMajor: 0x%04x", EXTRACT_16BITS(cp)));
369 ND_PRINT((ndo, ", Minor: 0x%02x", *cp));
375 ND_PRINT((ndo, ", Command: %s", tok2str(cmdcode_str, "Unknown (0x%02x)", command)));
378 ND_PRINT((ndo, ", Tag: 0x%08x", EXTRACT_32BITS(cp)));
382 command == AOEV1_CMD_ISSUE_ATA_COMMAND ? aoev1_issue_print :
383 command == AOEV1_CMD_QUERY_CONFIG_INFORMATION ? aoev1_query_print :
384 command == AOEV1_CMD_MAC_MASK_LIST ? aoev1_mac_print :
385 command == AOEV1_CMD_RESERVE_RELEASE ? aoev1_reserve_print :
387 if (cmd_decoder != NULL)
388 cmd_decoder(ndo, cp, len - AOEV1_COMMON_HDR_LEN);
392 ND_PRINT((ndo, "%s", istr));
393 ND_TCHECK2(*cp, ep - cp);
396 ND_PRINT((ndo, "%s", tstr));
400 aoe_print(netdissect_options *ndo,
401 const u_char *cp, const u_int len)
403 const u_char *ep = cp + len;
406 ND_PRINT((ndo, "AoE length %u", len));
412 ver = (*cp & 0xF0) >> 4;
413 /* Don't advance cp yet: low order 4 bits are version-specific. */
414 ND_PRINT((ndo, ", Ver %u", ver));
418 aoev1_print(ndo, cp, len);
424 ND_PRINT((ndo, "%s", istr));
425 ND_TCHECK2(*cp, ep - cp);
428 ND_PRINT((ndo, "%s", tstr));