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"
44 #define ATA_SECTOR_SIZE 512
46 #define AOEV1_CMD_ISSUE_ATA_COMMAND 0
47 #define AOEV1_CMD_QUERY_CONFIG_INFORMATION 1
48 #define AOEV1_CMD_MAC_MASK_LIST 2
49 #define AOEV1_CMD_RESERVE_RELEASE 3
51 static const struct tok cmdcode_str
[] = {
52 { AOEV1_CMD_ISSUE_ATA_COMMAND
, "Issue ATA Command" },
53 { AOEV1_CMD_QUERY_CONFIG_INFORMATION
, "Query Config Information" },
54 { AOEV1_CMD_MAC_MASK_LIST
, "MAC Mask List" },
55 { AOEV1_CMD_RESERVE_RELEASE
, "Reserve/Release" },
59 #define AOEV1_COMMON_HDR_LEN 10U /* up to but w/o Arg */
60 #define AOEV1_ISSUE_ARG_LEN 12U /* up to but w/o Data */
61 #define AOEV1_QUERY_ARG_LEN 8U /* up to but w/o Config String */
62 #define AOEV1_MAC_ARG_LEN 4U /* up to but w/o Directive 0 */
63 #define AOEV1_RESERVE_ARG_LEN 2U /* up to but w/o Ethernet address 0 */
64 #define AOEV1_MAX_CONFSTR_LEN 1024U
66 #define AOEV1_FLAG_R 0x08
67 #define AOEV1_FLAG_E 0x04
69 static const struct tok aoev1_flag_str
[] = {
70 { AOEV1_FLAG_R
, "Response" },
71 { AOEV1_FLAG_E
, "Error" },
77 static const struct tok aoev1_errcode_str
[] = {
78 { 1, "Unrecognized command code" },
79 { 2, "Bad argument parameter" },
80 { 3, "Device unavailable" },
81 { 4, "Config string present" },
82 { 5, "Unsupported version" },
83 { 6, "Target is reserved" },
87 #define AOEV1_AFLAG_E 0x40
88 #define AOEV1_AFLAG_D 0x10
89 #define AOEV1_AFLAG_A 0x02
90 #define AOEV1_AFLAG_W 0x01
92 static const struct tok aoev1_aflag_str
[] = {
94 { AOEV1_AFLAG_E
, "Ext48" },
96 { AOEV1_AFLAG_D
, "Device" },
99 { AOEV1_AFLAG_A
, "Async" },
100 { AOEV1_AFLAG_W
, "Write" },
104 static const struct tok aoev1_ccmd_str
[] = {
105 { 0, "read config string" },
106 { 1, "test config string" },
107 { 2, "test config string prefix" },
108 { 3, "set config string" },
109 { 4, "force set config string" },
113 static const struct tok aoev1_mcmd_str
[] = {
114 { 0, "Read Mac Mask List" },
115 { 1, "Edit Mac Mask List" },
119 static const struct tok aoev1_merror_str
[] = {
120 { 1, "Unspecified Error" },
121 { 2, "Bad DCmd directive" },
122 { 3, "Mask list full" },
126 static const struct tok aoev1_dcmd_str
[] = {
127 { 0, "No Directive" },
128 { 1, "Add mac address to mask list" },
129 { 2, "Delete mac address from mask list" },
133 static const struct tok aoev1_rcmd_str
[] = {
134 { 0, "Read reserve list" },
135 { 1, "Set reserve list" },
136 { 2, "Force set reserve list" },
141 aoev1_issue_print(netdissect_options
*ndo
,
142 const u_char
*cp
, const u_int len
)
144 const u_char
*ep
= ndo
->ndo_snapend
;
146 if (len
< AOEV1_ISSUE_ARG_LEN
)
150 ND_PRINT("\n\tAFlags: [%s]",
151 bittok2str(aoev1_aflag_str
, "none", GET_U_1(cp
)));
155 ND_PRINT(", Err/Feature: %u", GET_U_1(cp
));
157 /* Sector Count (not correlated with the length) */
159 ND_PRINT(", Sector Count: %u", GET_U_1(cp
));
163 ND_PRINT(", Cmd/Status: %u", GET_U_1(cp
));
167 ND_PRINT("\n\tlba0: %u", GET_U_1(cp
));
171 ND_PRINT(", lba1: %u", GET_U_1(cp
));
175 ND_PRINT(", lba2: %u", GET_U_1(cp
));
179 ND_PRINT(", lba3: %u", GET_U_1(cp
));
183 ND_PRINT(", lba4: %u", GET_U_1(cp
));
187 ND_PRINT(", lba5: %u", GET_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_invalid(ndo
);
199 ND_TCHECK_LEN(cp
, ep
- cp
);
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", GET_BE_U_2(cp
));
218 /* Firmware Version */
220 ND_PRINT(", Firmware Version: %u", GET_BE_U_2(cp
));
224 ND_PRINT(", Sector Count: %u", GET_U_1(cp
));
228 ND_PRINT(", AoE: %u, CCmd: %s", (GET_U_1(cp
) & 0xF0) >> 4,
229 tok2str(aoev1_ccmd_str
, "Unknown (0x02x)", GET_U_1(cp
) & 0x0F));
231 /* Config String Length */
233 cslen
= GET_BE_U_2(cp
);
235 if (cslen
> AOEV1_MAX_CONFSTR_LEN
|| AOEV1_QUERY_ARG_LEN
+ cslen
> len
)
239 ND_TCHECK_LEN(cp
, cslen
);
240 ND_PRINT("\n\tConfig String (length %u): ", cslen
);
241 if (nd_printn(ndo
, cp
, cslen
, ndo
->ndo_snapend
))
247 nd_print_invalid(ndo
);
248 ND_TCHECK_LEN(cp
, ep
- cp
);
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",
269 tok2str(aoev1_mcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
273 ND_PRINT(", MError: %s",
274 tok2str(aoev1_merror_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
278 dircount
= GET_U_1(cp
);
280 ND_PRINT(", Dir Count: %u", dircount
);
281 if (AOEV1_MAC_ARG_LEN
+ dircount
* 8 > len
)
284 for (i
= 0; i
< dircount
; i
++) {
290 ND_PRINT("\n\t DCmd: %s",
291 tok2str(aoev1_dcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
293 /* Ethernet Address */
294 ND_TCHECK_LEN(cp
, MAC_ADDR_LEN
);
295 ND_PRINT(", Ethernet Address: %s", GET_ETHERADDR_STRING(cp
));
301 nd_print_invalid(ndo
);
302 ND_TCHECK_LEN(cp
, ep
- cp
);
309 aoev1_reserve_print(netdissect_options
*ndo
,
310 const u_char
*cp
, const u_int len
)
312 const u_char
*ep
= ndo
->ndo_snapend
;
315 if (len
< AOEV1_RESERVE_ARG_LEN
|| (len
- AOEV1_RESERVE_ARG_LEN
) % MAC_ADDR_LEN
)
319 ND_PRINT("\n\tRCmd: %s",
320 tok2str(aoev1_rcmd_str
, "Unknown (0x%02x)", GET_U_1(cp
)));
322 /* NMacs (correlated with the length) */
326 ND_PRINT(", NMacs: %u", nmacs
);
327 if (AOEV1_RESERVE_ARG_LEN
+ nmacs
* MAC_ADDR_LEN
!= len
)
330 for (i
= 0; i
< nmacs
; i
++) {
331 ND_TCHECK_LEN(cp
, MAC_ADDR_LEN
);
332 ND_PRINT("\n\tEthernet Address %u: %s", i
, GET_ETHERADDR_STRING(cp
));
338 nd_print_invalid(ndo
);
339 ND_TCHECK_LEN(cp
, ep
- cp
);
345 /* cp points to the Ver/Flags octet */
347 aoev1_print(netdissect_options
*ndo
,
348 const u_char
*cp
, const u_int len
)
350 const u_char
*ep
= ndo
->ndo_snapend
;
351 uint8_t flags
, command
;
352 void (*cmd_decoder
)(netdissect_options
*, const u_char
*, const u_int
);
354 if (len
< AOEV1_COMMON_HDR_LEN
)
357 flags
= GET_U_1(cp
) & 0x0F;
358 ND_PRINT(", Flags: [%s]", bittok2str(aoev1_flag_str
, "none", flags
));
360 if (! ndo
->ndo_vflag
)
364 if (flags
& AOEV1_FLAG_E
)
365 ND_PRINT("\n\tError: %s",
366 tok2str(aoev1_errcode_str
, "Invalid (%u)", GET_U_1(cp
)));
370 ND_PRINT("\n\tMajor: 0x%04x", GET_BE_U_2(cp
));
374 ND_PRINT(", Minor: 0x%02x", GET_U_1(cp
));
378 command
= GET_U_1(cp
);
380 ND_PRINT(", Command: %s", tok2str(cmdcode_str
, "Unknown (0x%02x)", command
));
383 ND_PRINT(", Tag: 0x%08x", GET_BE_U_4(cp
));
387 command
== AOEV1_CMD_ISSUE_ATA_COMMAND
? aoev1_issue_print
:
388 command
== AOEV1_CMD_QUERY_CONFIG_INFORMATION
? aoev1_query_print
:
389 command
== AOEV1_CMD_MAC_MASK_LIST
? aoev1_mac_print
:
390 command
== AOEV1_CMD_RESERVE_RELEASE
? aoev1_reserve_print
:
392 if (cmd_decoder
!= NULL
)
393 cmd_decoder(ndo
, cp
, len
- AOEV1_COMMON_HDR_LEN
);
397 nd_print_invalid(ndo
);
398 ND_TCHECK_LEN(cp
, ep
- cp
);
405 aoe_print(netdissect_options
*ndo
,
406 const u_char
*cp
, const u_int len
)
408 const u_char
*ep
= ndo
->ndo_snapend
;
411 ndo
->ndo_protocol
= "aoe";
412 ND_PRINT("AoE length %u", len
);
418 ver
= (GET_U_1(cp
) & 0xF0) >> 4;
419 /* Don't advance cp yet: low order 4 bits are version-specific. */
420 ND_PRINT(", Ver %u", ver
);
424 aoev1_print(ndo
, cp
, len
);
430 nd_print_invalid(ndo
);
431 ND_TCHECK_LEN(cp
, ep
- cp
);