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 */
31 * https://web.archive.org/web/20161025044402/http://brantleycoilecompany.com/AoEr11.pdf
38 #include "netdissect-stdinc.h"
40 #include "netdissect.h"
42 #include "addrtoname.h"
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
, u_int len
)
146 if (len
< AOEV1_ISSUE_ARG_LEN
)
149 ND_PRINT("\n\tAFlags: [%s]",
150 bittok2str(aoev1_aflag_str
, "none", GET_U_1(cp
)));
154 ND_PRINT(", Err/Feature: %u", GET_U_1(cp
));
157 /* Sector Count (not correlated with the length) */
158 ND_PRINT(", Sector Count: %u", GET_U_1(cp
));
162 ND_PRINT(", Cmd/Status: %u", GET_U_1(cp
));
166 ND_PRINT("\n\tlba0: %u", GET_U_1(cp
));
170 ND_PRINT(", lba1: %u", GET_U_1(cp
));
174 ND_PRINT(", lba2: %u", GET_U_1(cp
));
178 ND_PRINT(", lba3: %u", GET_U_1(cp
));
182 ND_PRINT(", lba4: %u", GET_U_1(cp
));
186 ND_PRINT(", lba5: %u", GET_U_1(cp
));
195 ND_PRINT("\n\tData: %u bytes", len
);
199 nd_print_invalid(ndo
);
200 ND_TCHECK_LEN(cp
, len
);
207 aoev1_query_print(netdissect_options
*ndo
,
208 const u_char
*cp
, u_int len
)
212 if (len
< AOEV1_QUERY_ARG_LEN
)
215 ND_PRINT("\n\tBuffer Count: %u", GET_BE_U_2(cp
));
218 /* Firmware Version */
219 ND_PRINT(", Firmware Version: %u", GET_BE_U_2(cp
));
223 ND_PRINT(", Sector Count: %u", GET_U_1(cp
));
227 ND_PRINT(", AoE: %u, CCmd: %s", (GET_U_1(cp
) & 0xF0) >> 4,
228 tok2str(aoev1_ccmd_str
, "Unknown (0x02x)", GET_U_1(cp
) & 0x0F));
231 /* Config String Length */
232 cslen
= GET_BE_U_2(cp
);
235 if (cslen
> AOEV1_MAX_CONFSTR_LEN
|| cslen
> len
)
239 ND_PRINT("\n\tConfig String (length %u): ", cslen
);
240 (void)nd_printn(ndo
, cp
, cslen
, NULL
);
245 nd_print_invalid(ndo
);
246 ND_TCHECK_LEN(cp
, len
);
253 aoev1_mac_print(netdissect_options
*ndo
,
254 const u_char
*cp
, u_int len
)
258 if (len
< AOEV1_MAC_ARG_LEN
)
264 ND_PRINT("\n\tMCmd: %s",
265 tok2str(aoev1_mcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
269 ND_PRINT(", MError: %s",
270 tok2str(aoev1_merror_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
274 dircount
= GET_U_1(cp
);
277 ND_PRINT(", Dir Count: %u", dircount
);
278 if (dircount
* 8 > len
)
281 for (i
= 0; i
< dircount
; i
++) {
286 ND_PRINT("\n\t DCmd: %s",
287 tok2str(aoev1_dcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
290 /* Ethernet Address */
291 ND_PRINT(", Ethernet Address: %s", GET_ETHERADDR_STRING(cp
));
298 nd_print_invalid(ndo
);
299 ND_TCHECK_LEN(cp
, len
);
306 aoev1_reserve_print(netdissect_options
*ndo
,
307 const u_char
*cp
, u_int len
)
311 if (len
< AOEV1_RESERVE_ARG_LEN
|| (len
- AOEV1_RESERVE_ARG_LEN
) % MAC_ADDR_LEN
)
314 ND_PRINT("\n\tRCmd: %s",
315 tok2str(aoev1_rcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
318 /* NMacs (correlated with the length) */
322 ND_PRINT(", NMacs: %u", nmacs
);
323 if (nmacs
* MAC_ADDR_LEN
!= len
)
326 for (i
= 0; i
< nmacs
; i
++) {
327 ND_PRINT("\n\tEthernet Address %u: %s", i
, GET_ETHERADDR_STRING(cp
));
334 nd_print_invalid(ndo
);
335 ND_TCHECK_LEN(cp
, len
);
341 /* cp points to the Ver/Flags octet */
343 aoev1_print(netdissect_options
*ndo
,
344 const u_char
*cp
, u_int len
)
346 uint8_t flags
, command
;
347 void (*cmd_decoder
)(netdissect_options
*, const u_char
*, u_int
);
349 if (len
< AOEV1_COMMON_HDR_LEN
)
352 flags
= GET_U_1(cp
) & 0x0F;
353 ND_PRINT(", Flags: [%s]", bittok2str(aoev1_flag_str
, "none", flags
));
356 if (! ndo
->ndo_vflag
)
359 if (flags
& AOEV1_FLAG_E
)
360 ND_PRINT("\n\tError: %s",
361 tok2str(aoev1_errcode_str
, "Invalid (%u)", GET_U_1(cp
)));
365 ND_PRINT("\n\tMajor: 0x%04x", GET_BE_U_2(cp
));
369 ND_PRINT(", Minor: 0x%02x", GET_U_1(cp
));
373 command
= GET_U_1(cp
);
376 ND_PRINT(", Command: %s", tok2str(cmdcode_str
, "Unknown (0x%02x)", command
));
378 ND_PRINT(", Tag: 0x%08x", GET_BE_U_4(cp
));
383 command
== AOEV1_CMD_ISSUE_ATA_COMMAND
? aoev1_issue_print
:
384 command
== AOEV1_CMD_QUERY_CONFIG_INFORMATION
? aoev1_query_print
:
385 command
== AOEV1_CMD_MAC_MASK_LIST
? aoev1_mac_print
:
386 command
== AOEV1_CMD_RESERVE_RELEASE
? aoev1_reserve_print
:
388 if (cmd_decoder
!= NULL
)
389 cmd_decoder(ndo
, cp
, len
);
393 nd_print_invalid(ndo
);
394 ND_TCHECK_LEN(cp
, len
);
401 aoe_print(netdissect_options
*ndo
,
402 const u_char
*cp
, const u_int len
)
406 ndo
->ndo_protocol
= "aoe";
407 ND_PRINT("AoE length %u", len
);
412 ver
= (GET_U_1(cp
) & 0xF0) >> 4;
413 /* Don't advance cp yet: low order 4 bits are version-specific. */
414 ND_PRINT(", Ver %u", ver
);
418 aoev1_print(ndo
, cp
, len
);
424 nd_print_invalid(ndo
);
425 ND_TCHECK_LEN(cp
, len
);