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"
42 static const char tstr
[] = " [|aoe]";
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_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
, const u_int len
)
145 const u_char
*ep
= ndo
->ndo_snapend
;
147 if (len
< AOEV1_ISSUE_ARG_LEN
)
151 ND_PRINT("\n\tAFlags: [%s]", bittok2str(aoev1_aflag_str
, "none", EXTRACT_U_1(cp
)));
155 ND_PRINT(", Err/Feature: %u", EXTRACT_U_1(cp
));
157 /* Sector Count (not correlated with the length) */
159 ND_PRINT(", Sector Count: %u", EXTRACT_U_1(cp
));
163 ND_PRINT(", Cmd/Status: %u", EXTRACT_U_1(cp
));
167 ND_PRINT("\n\tlba0: %u", EXTRACT_U_1(cp
));
171 ND_PRINT(", lba1: %u", EXTRACT_U_1(cp
));
175 ND_PRINT(", lba2: %u", EXTRACT_U_1(cp
));
179 ND_PRINT(", lba3: %u", EXTRACT_U_1(cp
));
183 ND_PRINT(", lba4: %u", EXTRACT_U_1(cp
));
187 ND_PRINT(", lba5: %u", EXTRACT_U_1(cp
));
193 if (len
> AOEV1_ISSUE_ARG_LEN
)
194 ND_PRINT("\n\tData: %u bytes", len
- AOEV1_ISSUE_ARG_LEN
);
198 ND_PRINT("%s", istr
);
199 ND_TCHECK_LEN(cp
, ep
- cp
);
202 ND_PRINT("%s", tstr
);
206 aoev1_query_print(netdissect_options
*ndo
,
207 const u_char
*cp
, const u_int len
)
209 const u_char
*ep
= ndo
->ndo_snapend
;
212 if (len
< AOEV1_QUERY_ARG_LEN
)
216 ND_PRINT("\n\tBuffer Count: %u", EXTRACT_BE_U_2(cp
));
218 /* Firmware Version */
220 ND_PRINT(", Firmware Version: %u", EXTRACT_BE_U_2(cp
));
224 ND_PRINT(", Sector Count: %u", EXTRACT_U_1(cp
));
228 ND_PRINT(", AoE: %u, CCmd: %s", (EXTRACT_U_1(cp
) & 0xF0) >> 4,
229 tok2str(aoev1_ccmd_str
, "Unknown (0x02x)", EXTRACT_U_1(cp
) & 0x0F));
231 /* Config String Length */
233 cslen
= EXTRACT_BE_U_2(cp
);
235 if (cslen
> AOEV1_MAX_CONFSTR_LEN
|| AOEV1_QUERY_ARG_LEN
+ cslen
> len
)
238 ND_TCHECK_LEN(cp
, cslen
);
240 ND_PRINT("\n\tConfig String (length %u): ", cslen
);
241 if (fn_printn(ndo
, cp
, cslen
, ndo
->ndo_snapend
))
247 ND_PRINT("%s", istr
);
248 ND_TCHECK_LEN(cp
, ep
- cp
);
251 ND_PRINT("%s", tstr
);
255 aoev1_mac_print(netdissect_options
*ndo
,
256 const u_char
*cp
, const u_int len
)
258 const u_char
*ep
= ndo
->ndo_snapend
;
261 if (len
< AOEV1_MAC_ARG_LEN
)
268 ND_PRINT("\n\tMCmd: %s", tok2str(aoev1_mcmd_str
, "Unknown (0x%02x)", EXTRACT_U_1(cp
)));
272 ND_PRINT(", MError: %s", tok2str(aoev1_merror_str
, "Unknown (0x%02x)", EXTRACT_U_1(cp
)));
276 dircount
= EXTRACT_U_1(cp
);
278 ND_PRINT(", Dir Count: %u", dircount
);
279 if (AOEV1_MAC_ARG_LEN
+ dircount
* 8 > len
)
282 for (i
= 0; i
< dircount
; i
++) {
288 ND_PRINT("\n\t DCmd: %s", tok2str(aoev1_dcmd_str
, "Unknown (0x%02x)", EXTRACT_U_1(cp
)));
290 /* Ethernet Address */
291 ND_TCHECK_LEN(cp
, MAC_ADDR_LEN
);
292 ND_PRINT(", Ethernet Address: %s", etheraddr_string(ndo
, cp
));
298 ND_PRINT("%s", istr
);
299 ND_TCHECK_LEN(cp
, ep
- cp
);
302 ND_PRINT("%s", tstr
);
306 aoev1_reserve_print(netdissect_options
*ndo
,
307 const u_char
*cp
, const u_int len
)
309 const u_char
*ep
= ndo
->ndo_snapend
;
312 if (len
< AOEV1_RESERVE_ARG_LEN
|| (len
- AOEV1_RESERVE_ARG_LEN
) % MAC_ADDR_LEN
)
316 ND_PRINT("\n\tRCmd: %s", tok2str(aoev1_rcmd_str
, "Unknown (0x%02x)", EXTRACT_U_1(cp
)));
318 /* NMacs (correlated with the length) */
320 nmacs
= EXTRACT_U_1(cp
);
322 ND_PRINT(", NMacs: %u", nmacs
);
323 if (AOEV1_RESERVE_ARG_LEN
+ nmacs
* MAC_ADDR_LEN
!= len
)
326 for (i
= 0; i
< nmacs
; i
++) {
327 ND_PRINT("\n\tEthernet Address %u: %s", i
, etheraddr_string(ndo
, cp
));
333 ND_PRINT("%s", istr
);
334 ND_TCHECK_LEN(cp
, ep
- cp
);
337 ND_PRINT("%s", tstr
);
340 /* cp points to the Ver/Flags octet */
342 aoev1_print(netdissect_options
*ndo
,
343 const u_char
*cp
, const u_int len
)
345 const u_char
*ep
= ndo
->ndo_snapend
;
346 uint8_t flags
, command
;
347 void (*cmd_decoder
)(netdissect_options
*, const u_char
*, const u_int
);
349 if (len
< AOEV1_COMMON_HDR_LEN
)
352 flags
= EXTRACT_U_1(cp
) & 0x0F;
353 ND_PRINT(", Flags: [%s]", bittok2str(aoev1_flag_str
, "none", flags
));
355 if (! ndo
->ndo_vflag
)
359 if (flags
& AOEV1_FLAG_E
)
360 ND_PRINT("\n\tError: %s", tok2str(aoev1_errcode_str
, "Invalid (%u)", EXTRACT_U_1(cp
)));
364 ND_PRINT("\n\tMajor: 0x%04x", EXTRACT_BE_U_2(cp
));
368 ND_PRINT(", Minor: 0x%02x", EXTRACT_U_1(cp
));
372 command
= EXTRACT_U_1(cp
);
374 ND_PRINT(", Command: %s", tok2str(cmdcode_str
, "Unknown (0x%02x)", command
));
377 ND_PRINT(", Tag: 0x%08x", EXTRACT_BE_U_4(cp
));
381 command
== AOEV1_CMD_ISSUE_ATA_COMMAND
? aoev1_issue_print
:
382 command
== AOEV1_CMD_QUERY_CONFIG_INFORMATION
? aoev1_query_print
:
383 command
== AOEV1_CMD_MAC_MASK_LIST
? aoev1_mac_print
:
384 command
== AOEV1_CMD_RESERVE_RELEASE
? aoev1_reserve_print
:
386 if (cmd_decoder
!= NULL
)
387 cmd_decoder(ndo
, cp
, len
- AOEV1_COMMON_HDR_LEN
);
391 ND_PRINT("%s", istr
);
392 ND_TCHECK_LEN(cp
, ep
- cp
);
395 ND_PRINT("%s", tstr
);
399 aoe_print(netdissect_options
*ndo
,
400 const u_char
*cp
, const u_int len
)
402 const u_char
*ep
= ndo
->ndo_snapend
;
405 ndo
->ndo_protocol
= "aoe";
406 ND_PRINT("AoE length %u", len
);
412 ver
= (EXTRACT_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("%s", istr
);
425 ND_TCHECK_LEN(cp
, ep
- cp
);
428 ND_PRINT("%s", tstr
);