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
, const u_int len
)
146 const u_char
*ep
= ndo
->ndo_snapend
;
148 if (len
< AOEV1_ISSUE_ARG_LEN
)
152 ND_PRINT("\n\tAFlags: [%s]",
153 bittok2str(aoev1_aflag_str
, "none", GET_U_1(cp
)));
157 ND_PRINT(", Err/Feature: %u", GET_U_1(cp
));
159 /* Sector Count (not correlated with the length) */
161 ND_PRINT(", Sector Count: %u", GET_U_1(cp
));
165 ND_PRINT(", Cmd/Status: %u", GET_U_1(cp
));
169 ND_PRINT("\n\tlba0: %u", GET_U_1(cp
));
173 ND_PRINT(", lba1: %u", GET_U_1(cp
));
177 ND_PRINT(", lba2: %u", GET_U_1(cp
));
181 ND_PRINT(", lba3: %u", GET_U_1(cp
));
185 ND_PRINT(", lba4: %u", GET_U_1(cp
));
189 ND_PRINT(", lba5: %u", GET_U_1(cp
));
195 if (len
> AOEV1_ISSUE_ARG_LEN
)
196 ND_PRINT("\n\tData: %u bytes", len
- AOEV1_ISSUE_ARG_LEN
);
200 nd_print_invalid(ndo
);
201 ND_TCHECK_LEN(cp
, ep
- cp
);
208 aoev1_query_print(netdissect_options
*ndo
,
209 const u_char
*cp
, const u_int len
)
211 const u_char
*ep
= ndo
->ndo_snapend
;
214 if (len
< AOEV1_QUERY_ARG_LEN
)
218 ND_PRINT("\n\tBuffer Count: %u", GET_BE_U_2(cp
));
220 /* Firmware Version */
222 ND_PRINT(", Firmware Version: %u", GET_BE_U_2(cp
));
226 ND_PRINT(", Sector Count: %u", GET_U_1(cp
));
230 ND_PRINT(", AoE: %u, CCmd: %s", (GET_U_1(cp
) & 0xF0) >> 4,
231 tok2str(aoev1_ccmd_str
, "Unknown (0x02x)", GET_U_1(cp
) & 0x0F));
233 /* Config String Length */
235 cslen
= GET_BE_U_2(cp
);
237 if (cslen
> AOEV1_MAX_CONFSTR_LEN
|| AOEV1_QUERY_ARG_LEN
+ cslen
> len
)
241 ND_TCHECK_LEN(cp
, cslen
);
242 ND_PRINT("\n\tConfig String (length %u): ", cslen
);
243 if (nd_printn(ndo
, cp
, cslen
, ndo
->ndo_snapend
))
249 nd_print_invalid(ndo
);
250 ND_TCHECK_LEN(cp
, ep
- cp
);
257 aoev1_mac_print(netdissect_options
*ndo
,
258 const u_char
*cp
, const u_int len
)
260 const u_char
*ep
= ndo
->ndo_snapend
;
263 if (len
< AOEV1_MAC_ARG_LEN
)
270 ND_PRINT("\n\tMCmd: %s",
271 tok2str(aoev1_mcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
275 ND_PRINT(", MError: %s",
276 tok2str(aoev1_merror_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
280 dircount
= GET_U_1(cp
);
282 ND_PRINT(", Dir Count: %u", dircount
);
283 if (AOEV1_MAC_ARG_LEN
+ dircount
* 8 > len
)
286 for (i
= 0; i
< dircount
; i
++) {
292 ND_PRINT("\n\t DCmd: %s",
293 tok2str(aoev1_dcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
295 /* Ethernet Address */
296 ND_TCHECK_LEN(cp
, MAC_ADDR_LEN
);
297 ND_PRINT(", Ethernet Address: %s", GET_ETHERADDR_STRING(cp
));
303 nd_print_invalid(ndo
);
304 ND_TCHECK_LEN(cp
, ep
- cp
);
311 aoev1_reserve_print(netdissect_options
*ndo
,
312 const u_char
*cp
, const u_int len
)
314 const u_char
*ep
= ndo
->ndo_snapend
;
317 if (len
< AOEV1_RESERVE_ARG_LEN
|| (len
- AOEV1_RESERVE_ARG_LEN
) % MAC_ADDR_LEN
)
321 ND_PRINT("\n\tRCmd: %s",
322 tok2str(aoev1_rcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
324 /* NMacs (correlated with the length) */
328 ND_PRINT(", NMacs: %u", nmacs
);
329 if (AOEV1_RESERVE_ARG_LEN
+ nmacs
* MAC_ADDR_LEN
!= len
)
332 for (i
= 0; i
< nmacs
; i
++) {
333 ND_TCHECK_LEN(cp
, MAC_ADDR_LEN
);
334 ND_PRINT("\n\tEthernet Address %u: %s", i
, GET_ETHERADDR_STRING(cp
));
340 nd_print_invalid(ndo
);
341 ND_TCHECK_LEN(cp
, ep
- cp
);
347 /* cp points to the Ver/Flags octet */
349 aoev1_print(netdissect_options
*ndo
,
350 const u_char
*cp
, const u_int len
)
352 const u_char
*ep
= ndo
->ndo_snapend
;
353 uint8_t flags
, command
;
354 void (*cmd_decoder
)(netdissect_options
*, const u_char
*, const u_int
);
356 if (len
< AOEV1_COMMON_HDR_LEN
)
359 flags
= GET_U_1(cp
) & 0x0F;
360 ND_PRINT(", Flags: [%s]", bittok2str(aoev1_flag_str
, "none", flags
));
362 if (! ndo
->ndo_vflag
)
366 if (flags
& AOEV1_FLAG_E
)
367 ND_PRINT("\n\tError: %s",
368 tok2str(aoev1_errcode_str
, "Invalid (%u)", GET_U_1(cp
)));
372 ND_PRINT("\n\tMajor: 0x%04x", GET_BE_U_2(cp
));
376 ND_PRINT(", Minor: 0x%02x", GET_U_1(cp
));
380 command
= GET_U_1(cp
);
382 ND_PRINT(", Command: %s", tok2str(cmdcode_str
, "Unknown (0x%02x)", command
));
385 ND_PRINT(", Tag: 0x%08x", GET_BE_U_4(cp
));
389 command
== AOEV1_CMD_ISSUE_ATA_COMMAND
? aoev1_issue_print
:
390 command
== AOEV1_CMD_QUERY_CONFIG_INFORMATION
? aoev1_query_print
:
391 command
== AOEV1_CMD_MAC_MASK_LIST
? aoev1_mac_print
:
392 command
== AOEV1_CMD_RESERVE_RELEASE
? aoev1_reserve_print
:
394 if (cmd_decoder
!= NULL
)
395 cmd_decoder(ndo
, cp
, len
- AOEV1_COMMON_HDR_LEN
);
399 nd_print_invalid(ndo
);
400 ND_TCHECK_LEN(cp
, ep
- cp
);
407 aoe_print(netdissect_options
*ndo
,
408 const u_char
*cp
, const u_int len
)
410 const u_char
*ep
= ndo
->ndo_snapend
;
413 ndo
->ndo_protocol
= "aoe";
414 ND_PRINT("AoE length %u", len
);
420 ver
= (GET_U_1(cp
) & 0xF0) >> 4;
421 /* Don't advance cp yet: low order 4 bits are version-specific. */
422 ND_PRINT(", Ver %u", ver
);
426 aoev1_print(ndo
, cp
, len
);
432 nd_print_invalid(ndo
);
433 ND_TCHECK_LEN(cp
, ep
- cp
);