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
36 #include "netdissect-stdinc.h"
38 #define ND_LONGJMP_FROM_TCHECK
39 #include "netdissect.h"
41 #include "addrtoname.h"
45 #define ATA_SECTOR_SIZE 512
47 #define AOEV1_CMD_ISSUE_ATA_COMMAND 0
48 #define AOEV1_CMD_QUERY_CONFIG_INFORMATION 1
49 #define AOEV1_CMD_MAC_MASK_LIST 2
50 #define AOEV1_CMD_RESERVE_RELEASE 3
52 static const struct tok cmdcode_str
[] = {
53 { AOEV1_CMD_ISSUE_ATA_COMMAND
, "Issue ATA Command" },
54 { AOEV1_CMD_QUERY_CONFIG_INFORMATION
, "Query Config Information" },
55 { AOEV1_CMD_MAC_MASK_LIST
, "MAC Mask List" },
56 { AOEV1_CMD_RESERVE_RELEASE
, "Reserve/Release" },
60 #define AOEV1_COMMON_HDR_LEN 10U /* up to but w/o Arg */
61 #define AOEV1_ISSUE_ARG_LEN 12U /* up to but w/o Data */
62 #define AOEV1_QUERY_ARG_LEN 8U /* up to but w/o Config String */
63 #define AOEV1_MAC_ARG_LEN 4U /* up to but w/o Directive 0 */
64 #define AOEV1_RESERVE_ARG_LEN 2U /* up to but w/o Ethernet address 0 */
65 #define AOEV1_MAX_CONFSTR_LEN 1024U
67 #define AOEV1_FLAG_R 0x08
68 #define AOEV1_FLAG_E 0x04
70 static const struct tok aoev1_flag_str
[] = {
71 { AOEV1_FLAG_R
, "Response" },
72 { AOEV1_FLAG_E
, "Error" },
78 static const struct tok aoev1_errcode_str
[] = {
79 { 1, "Unrecognized command code" },
80 { 2, "Bad argument parameter" },
81 { 3, "Device unavailable" },
82 { 4, "Config string present" },
83 { 5, "Unsupported version" },
84 { 6, "Target is reserved" },
88 #define AOEV1_AFLAG_E 0x40
89 #define AOEV1_AFLAG_D 0x10
90 #define AOEV1_AFLAG_A 0x02
91 #define AOEV1_AFLAG_W 0x01
93 static const struct tok aoev1_aflag_bitmap_str
[] = {
95 { AOEV1_AFLAG_E
, "Ext48" },
97 { AOEV1_AFLAG_D
, "Device" },
100 { AOEV1_AFLAG_A
, "Async" },
101 { AOEV1_AFLAG_W
, "Write" },
105 static const struct tok aoev1_ccmd_str
[] = {
106 { 0, "read config string" },
107 { 1, "test config string" },
108 { 2, "test config string prefix" },
109 { 3, "set config string" },
110 { 4, "force set config string" },
114 static const struct tok aoev1_mcmd_str
[] = {
115 { 0, "Read Mac Mask List" },
116 { 1, "Edit Mac Mask List" },
120 static const struct tok aoev1_merror_str
[] = {
121 { 1, "Unspecified Error" },
122 { 2, "Bad DCmd directive" },
123 { 3, "Mask list full" },
127 static const struct tok aoev1_dcmd_str
[] = {
128 { 0, "No Directive" },
129 { 1, "Add mac address to mask list" },
130 { 2, "Delete mac address from mask list" },
134 static const struct tok aoev1_rcmd_str
[] = {
135 { 0, "Read reserve list" },
136 { 1, "Set reserve list" },
137 { 2, "Force set reserve list" },
142 aoev1_issue_print(netdissect_options
*ndo
,
143 const u_char
*cp
, u_int len
)
145 if (len
< AOEV1_ISSUE_ARG_LEN
)
148 ND_PRINT("\n\tAFlags: [%s]",
149 bittok2str(aoev1_aflag_bitmap_str
, "none", GET_U_1(cp
)));
153 ND_PRINT(", Err/Feature: %u", GET_U_1(cp
));
156 /* Sector Count (not correlated with the length) */
157 ND_PRINT(", Sector Count: %u", GET_U_1(cp
));
161 ND_PRINT(", Cmd/Status: %u", GET_U_1(cp
));
165 ND_PRINT("\n\tlba0: %u", GET_U_1(cp
));
169 ND_PRINT(", lba1: %u", GET_U_1(cp
));
173 ND_PRINT(", lba2: %u", GET_U_1(cp
));
177 ND_PRINT(", lba3: %u", GET_U_1(cp
));
181 ND_PRINT(", lba4: %u", GET_U_1(cp
));
185 ND_PRINT(", lba5: %u", GET_U_1(cp
));
194 ND_PRINT("\n\tData: %u bytes", len
);
198 nd_print_invalid(ndo
);
199 ND_TCHECK_LEN(cp
, len
);
203 aoev1_query_print(netdissect_options
*ndo
,
204 const u_char
*cp
, u_int len
)
208 if (len
< AOEV1_QUERY_ARG_LEN
)
211 ND_PRINT("\n\tBuffer Count: %u", GET_BE_U_2(cp
));
214 /* Firmware Version */
215 ND_PRINT(", Firmware Version: %u", GET_BE_U_2(cp
));
219 ND_PRINT(", Sector Count: %u", GET_U_1(cp
));
223 ND_PRINT(", AoE: %u, CCmd: %s", (GET_U_1(cp
) & 0xF0) >> 4,
224 tok2str(aoev1_ccmd_str
, "Unknown (0x02x)", GET_U_1(cp
) & 0x0F));
227 /* Config String Length */
228 cslen
= GET_BE_U_2(cp
);
231 if (cslen
> AOEV1_MAX_CONFSTR_LEN
|| cslen
> len
)
235 ND_PRINT("\n\tConfig String (length %u): ", cslen
);
236 nd_printjn(ndo
, cp
, cslen
);
241 nd_print_invalid(ndo
);
242 ND_TCHECK_LEN(cp
, len
);
246 aoev1_mac_print(netdissect_options
*ndo
,
247 const u_char
*cp
, u_int len
)
251 if (len
< AOEV1_MAC_ARG_LEN
)
257 ND_PRINT("\n\tMCmd: %s",
258 tok2str(aoev1_mcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
262 ND_PRINT(", MError: %s",
263 tok2str(aoev1_merror_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
267 dircount
= GET_U_1(cp
);
270 ND_PRINT(", Dir Count: %u", dircount
);
271 if (dircount
* 8U > len
)
274 for (i
= 0; i
< dircount
; i
++) {
279 ND_PRINT("\n\t DCmd: %s",
280 tok2str(aoev1_dcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
283 /* Ethernet Address */
284 ND_PRINT(", Ethernet Address: %s", GET_MAC48_STRING(cp
));
291 nd_print_invalid(ndo
);
292 ND_TCHECK_LEN(cp
, len
);
296 aoev1_reserve_print(netdissect_options
*ndo
,
297 const u_char
*cp
, u_int len
)
301 if (len
< AOEV1_RESERVE_ARG_LEN
|| (len
- AOEV1_RESERVE_ARG_LEN
) % MAC48_LEN
)
304 ND_PRINT("\n\tRCmd: %s",
305 tok2str(aoev1_rcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
308 /* NMacs (correlated with the length) */
312 ND_PRINT(", NMacs: %u", nmacs
);
313 if (nmacs
* MAC48_LEN
!= len
)
316 for (i
= 0; i
< nmacs
; i
++) {
317 ND_PRINT("\n\tEthernet Address %u: %s", i
, GET_MAC48_STRING(cp
));
324 nd_print_invalid(ndo
);
325 ND_TCHECK_LEN(cp
, len
);
328 /* cp points to the Ver/Flags octet */
330 aoev1_print(netdissect_options
*ndo
,
331 const u_char
*cp
, u_int len
)
333 uint8_t flags
, command
;
334 void (*cmd_decoder
)(netdissect_options
*, const u_char
*, u_int
);
336 if (len
< AOEV1_COMMON_HDR_LEN
)
339 flags
= GET_U_1(cp
) & 0x0F;
340 ND_PRINT(", Flags: [%s]", bittok2str(aoev1_flag_str
, "none", flags
));
343 if (! ndo
->ndo_vflag
)
346 if (flags
& AOEV1_FLAG_E
)
347 ND_PRINT("\n\tError: %s",
348 tok2str(aoev1_errcode_str
, "Invalid (%u)", GET_U_1(cp
)));
352 ND_PRINT("\n\tMajor: 0x%04x", GET_BE_U_2(cp
));
356 ND_PRINT(", Minor: 0x%02x", GET_U_1(cp
));
360 command
= GET_U_1(cp
);
363 ND_PRINT(", Command: %s", tok2str(cmdcode_str
, "Unknown (0x%02x)", command
));
365 ND_PRINT(", Tag: 0x%08x", GET_BE_U_4(cp
));
370 command
== AOEV1_CMD_ISSUE_ATA_COMMAND
? aoev1_issue_print
:
371 command
== AOEV1_CMD_QUERY_CONFIG_INFORMATION
? aoev1_query_print
:
372 command
== AOEV1_CMD_MAC_MASK_LIST
? aoev1_mac_print
:
373 command
== AOEV1_CMD_RESERVE_RELEASE
? aoev1_reserve_print
:
375 if (cmd_decoder
!= NULL
)
376 cmd_decoder(ndo
, cp
, len
);
380 nd_print_invalid(ndo
);
381 ND_TCHECK_LEN(cp
, len
);
385 aoe_print(netdissect_options
*ndo
,
386 const u_char
*cp
, const u_int len
)
390 ndo
->ndo_protocol
= "aoe";
391 ND_PRINT("AoE length %u", len
);
396 ver
= (GET_U_1(cp
) & 0xF0) >> 4;
397 /* Don't advance cp yet: low order 4 bits are version-specific. */
398 ND_PRINT(", Ver %u", ver
);
402 aoev1_print(ndo
, cp
, len
);
408 nd_print_invalid(ndo
);
409 ND_TCHECK_LEN(cp
, len
);