Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-opa-snc.c
blob8d139f49072bd3fc10b1b6114bdc804dd3a6a86e
1 /* packet-opa-snc.c
2 * Routines for Omni-Path SnC header dissection
3 * Copyright (c) 2016, Intel Corporation.
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/expert.h>
16 #include <epan/tfs.h>
17 #include <wsutil/array.h>
18 #include <wiretap/erf_record.h>
20 void proto_reg_handoff_opa_snc(void);
21 void proto_register_opa_snc(void);
23 static const value_string vals_opa_snc_direction[] = {
24 { 0, "Outbound" },
25 { 1, "Inbound" },
26 { 2, "Internal Debugging Tool" },
27 { 0, NULL }
29 /* PBC */
30 static const true_false_string tfs_opa_snc_pbc_isBypass = {
31 "Bypass (8B/10B/16B) Packet",
32 "9B Packet"
34 static const value_string vals_opa_snc_pbc_insertHcrc[] = {
35 { 0x0, "KDETH Hcrc calculated assuming GRH is not present" },
36 { 0x1, "KDETH Hcrc calculated assuming GRH is present" },
37 { 0x2, "KDETH Hcrc is not inserted" },
38 { 0x3, "Reserved" },
39 { 0, NULL }
41 /* RHF */
42 static const value_string vals_opa_snc_rhf_rcvtypeerr[] = {
43 { 0x0, "No Error" },
44 { 0x1, "OpCode Error" },
45 { 0x2, "KDETH Min Length Error" },
46 { 0x3, "KDETH Hcrc Error" },
47 { 0x4, "KDETH Version Error" },
48 { 0x5, "Context Error" },
49 { 0x6, "KDETH TID Error" },
50 { 0x7, "Reserved" },
51 { 0, NULL }
53 static const value_string vals_opa_snc_rhf_rcvtype[] = {
54 { 0, "Expected Receive" },
55 { 1, "Eager Receive" },
56 { 2, "IB" },
57 { 3, "error" },
58 { 4, "bypass" },
59 { 0, NULL }
62 /* Wireshark ID */
63 static int proto_opa_snc;
65 /* Variables to hold expansion values between packets */
66 static int ett_snc;
67 static int ett_sncpbc;
68 static int ett_sncrhf;
70 /* SnC Fields */
71 static int hf_opa_snc_direction;
72 static int hf_opa_snc_portnumber;
73 static int hf_opa_snc_Reserved16;
74 static int hf_opa_snc_Reserved32;
75 static int hf_opa_snc_Reserved64;
76 static int hf_opa_snc_pbc_reserved_63_48;
77 static int hf_opa_snc_pbc_pbcstaticratecontrolcnt;
78 static int hf_opa_snc_pbc_pbcintr;
79 static int hf_opa_snc_pbc_pbcdcinfo;
80 static int hf_opa_snc_pbc_pbctestebp;
81 static int hf_opa_snc_pbc_pbcpacketbypass;
82 static int hf_opa_snc_pbc_pbcinserthcrc;
83 static int hf_opa_snc_pbc_pbccreditreturn;
84 static int hf_opa_snc_pbc_pbcinsertbypassicrc;
85 static int hf_opa_snc_pbc_pbctestbadicrc;
86 static int hf_opa_snc_pbc_pbcfecn;
87 static int hf_opa_snc_pbc_reserved_21_16;
88 static int hf_opa_snc_pbc_pbcvl;
89 static int hf_opa_snc_pbc_pbclengthdws;
90 static int * const _snc_pbc_1[] = {
91 &hf_opa_snc_pbc_reserved_63_48,
92 &hf_opa_snc_pbc_pbcstaticratecontrolcnt,
93 NULL
95 static int * const _snc_pbc_2[] = {
96 &hf_opa_snc_pbc_pbcintr,
97 &hf_opa_snc_pbc_pbcdcinfo,
98 &hf_opa_snc_pbc_pbctestebp,
99 &hf_opa_snc_pbc_pbcpacketbypass,
100 &hf_opa_snc_pbc_pbcinserthcrc,
101 &hf_opa_snc_pbc_pbccreditreturn,
102 &hf_opa_snc_pbc_pbcinsertbypassicrc,
103 &hf_opa_snc_pbc_pbctestbadicrc,
104 &hf_opa_snc_pbc_pbcfecn,
105 &hf_opa_snc_pbc_reserved_21_16,
106 &hf_opa_snc_pbc_pbcvl,
107 &hf_opa_snc_pbc_pbclengthdws,
108 NULL
110 static int hf_opa_snc_rhf_icrcerr;
111 static int hf_opa_snc_rhf_reserved_62;
112 static int hf_opa_snc_rhf_eccerr;
113 static int hf_opa_snc_rhf_lenerr;
114 static int hf_opa_snc_rhf_tiderr;
115 static int hf_opa_snc_rhf_rcvtypeerr;
116 static int hf_opa_snc_rhf_dcerr;
117 static int hf_opa_snc_rhf_dcuncerr;
118 static int hf_opa_snc_rhf_khdrlenerr;
119 static int hf_opa_snc_rhf_hdrqoffset;
120 static int hf_opa_snc_rhf_egroffset;
121 static int hf_opa_snc_rhf_rcvseq;
122 static int hf_opa_snc_rhf_dcinfo;
123 static int hf_opa_snc_rhf_egrindex;
124 static int hf_opa_snc_rhf_useegrbfr;
125 static int hf_opa_snc_rhf_rcvtype;
126 static int hf_opa_snc_rhf_pktlen;
127 static int * const _snc_rhf_1[] = {
128 &hf_opa_snc_rhf_icrcerr,
129 &hf_opa_snc_rhf_reserved_62,
130 &hf_opa_snc_rhf_eccerr,
131 &hf_opa_snc_rhf_lenerr,
132 &hf_opa_snc_rhf_tiderr,
133 &hf_opa_snc_rhf_rcvtypeerr,
134 &hf_opa_snc_rhf_dcerr,
135 &hf_opa_snc_rhf_dcuncerr,
136 &hf_opa_snc_rhf_khdrlenerr,
137 &hf_opa_snc_rhf_hdrqoffset,
138 &hf_opa_snc_rhf_egroffset,
139 NULL
141 static int * const _snc_rhf_2[] = {
142 &hf_opa_snc_rhf_rcvseq,
143 &hf_opa_snc_rhf_dcinfo,
144 &hf_opa_snc_rhf_egrindex,
145 &hf_opa_snc_rhf_useegrbfr,
146 &hf_opa_snc_rhf_rcvtype,
147 &hf_opa_snc_rhf_pktlen,
148 NULL
151 static expert_field ei_opa_snc_nobypass;
153 static void cf_opa_snc_dw_to_b(char *buf, uint32_t value)
155 snprintf(buf, ITEM_LABEL_LENGTH, "%u DWORDS, %u Bytes", value, value * 4);
157 static void cf_opa_snc_qw_to_b(char *buf, uint32_t value)
159 snprintf(buf, ITEM_LABEL_LENGTH, "%u QWORDS, %u Bytes", value, value * 8);
162 /* Dissector Declarations */
163 static dissector_handle_t opa_snc_handle;
164 static dissector_handle_t opa_9b_handle;
166 static int dissect_opa_snc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
168 int offset = 0; /* Current Offset */
170 bool isBypass = true; /* Tracks if we are parsing a bypass packet or Not */
171 uint8_t Direction = tvb_get_uint8(tvb, offset + 1);
172 uint64_t RHF_PBC;
173 proto_item *SnC_item;
174 proto_tree * SnC_tree,*PBC_tree,*RHF_tree;
176 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Omni-Path");
177 col_clear(pinfo->cinfo, COL_INFO);
179 tree = proto_tree_get_parent_tree(tree);
181 SnC_item = proto_tree_add_item(tree, proto_opa_snc, tvb, offset, 16, ENC_NA);
182 SnC_tree = proto_item_add_subtree(SnC_item, ett_snc);
184 proto_tree_add_item(SnC_tree, hf_opa_snc_portnumber, tvb, offset, 1, ENC_LITTLE_ENDIAN);
185 offset += 1;
186 proto_tree_add_item(SnC_tree, hf_opa_snc_direction, tvb, offset, 1, ENC_LITTLE_ENDIAN);
187 offset += 1;
188 proto_tree_add_item(SnC_tree, hf_opa_snc_Reserved16, tvb, offset, 2, ENC_NA);
189 offset += 2;
190 proto_tree_add_item(SnC_tree, hf_opa_snc_Reserved32, tvb, offset, 4, ENC_NA);
191 offset += 4;
193 RHF_PBC = tvb_get_letoh64(tvb, offset);
194 switch (Direction) {
195 case 0:
196 PBC_tree = proto_tree_add_subtree(SnC_tree, tvb, offset, 8, ett_sncpbc, NULL, "PBC - Per Buffer Control");
197 proto_tree_add_bitmask_list(PBC_tree, tvb, offset + 4, 4, _snc_pbc_1, ENC_LITTLE_ENDIAN);
198 proto_tree_add_bitmask_list(PBC_tree, tvb, offset, 4, _snc_pbc_2, ENC_LITTLE_ENDIAN);
199 isBypass = (((RHF_PBC >> 28) & 1) == 1);
200 break;
201 case 1:
202 RHF_tree = proto_tree_add_subtree(SnC_tree, tvb, offset, 8, ett_sncrhf, NULL, "RHF - Receive Header Flags");
203 proto_tree_add_bitmask_list(RHF_tree, tvb, offset + 4, 4, _snc_rhf_1, ENC_LITTLE_ENDIAN);
204 proto_tree_add_bitmask_list(RHF_tree, tvb, offset, 4, _snc_rhf_2, ENC_LITTLE_ENDIAN);
205 isBypass = (((RHF_PBC >> 12) & 7) == 4);
206 break;
207 case 2: /* For use with internal debugging tools */
208 proto_tree_add_item(SnC_tree, hf_opa_snc_Reserved64, tvb, offset, 8, ENC_NA);
209 isBypass = false;
210 break;
211 default:
212 isBypass = false;
214 offset += 8;
216 if (isBypass) {
217 /* Bypass packets not implemented in this version */
218 expert_add_info(pinfo, NULL, &ei_opa_snc_nobypass);
219 } else {
220 call_dissector(opa_9b_handle, tvb_new_subset_remaining(tvb, offset), pinfo, tree);
222 return tvb_captured_length(tvb);
225 void proto_register_opa_snc(void)
227 expert_module_t *expert_opa_snc;
229 static hf_register_info hf[] = {
230 { &hf_opa_snc_direction, {
231 "Direction", "opa.snc.direction",
232 FT_UINT8, BASE_HEX, VALS(vals_opa_snc_direction), 0x0, NULL, HFILL }
234 { &hf_opa_snc_portnumber, {
235 "Port Number", "opa.snc.portnumber",
236 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
238 { &hf_opa_snc_Reserved32, {
239 "Reserved (32 bits)", "opa.snc.reserved32",
240 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
242 { &hf_opa_snc_Reserved64, {
243 "Reserved (64 bits)", "opa.snc.reserved64",
244 FT_UINT64, BASE_HEX, NULL, 0x0, NULL, HFILL }
246 { &hf_opa_snc_Reserved16, {
247 "Reserved (16 bits)", "opa.snc.reserved16",
248 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
250 { &hf_opa_snc_pbc_reserved_63_48, {
251 "Reserved (16 bits)", "opa.snc.pbc.reserved_63_48",
252 FT_UINT32, BASE_HEX, NULL, 0xFFFF0000, NULL, HFILL }
254 { &hf_opa_snc_pbc_pbcstaticratecontrolcnt, {
255 "Static Rate Control Counter", "opa.snc.pbc.pbcstaticratecontrolcnt",
256 FT_UINT32, BASE_HEX, NULL, 0x0000FFFF, NULL, HFILL }
258 { &hf_opa_snc_pbc_pbcintr, {
259 "Interrupt", "opa.snc.pbc.pbcintr",
260 FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x80000000, NULL, HFILL }
262 { &hf_opa_snc_pbc_pbcdcinfo, {
263 "DC Info", "opa.snc.pbc.pbcdcinfo",
264 FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x40000000, NULL, HFILL }
266 { &hf_opa_snc_pbc_pbctestebp, {
267 "Test End Bad Packet", "opa.snc.pbc.pbctestebp",
268 FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x20000000, NULL, HFILL }
270 { &hf_opa_snc_pbc_pbcpacketbypass, {
271 "Packet Type", "opa.snc.pbc.pbcpacketbypass",
272 FT_BOOLEAN, 32, TFS(&tfs_opa_snc_pbc_isBypass), 0x10000000, NULL, HFILL }
274 { &hf_opa_snc_pbc_pbcinserthcrc, {
275 "Insert Hcrc", "opa.snc.pbc.pbcinserthcrc",
276 FT_UINT32, BASE_HEX, VALS(vals_opa_snc_pbc_insertHcrc), 0x0C000000, NULL, HFILL }
278 { &hf_opa_snc_pbc_pbccreditreturn, {
279 "Request Credit Return", "opa.snc.pbc.pbccreditreturn",
280 FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x02000000, NULL, HFILL }
282 { &hf_opa_snc_pbc_pbcinsertbypassicrc, {
283 "Insert ICRC for bypass packets", "opa.snc.pbc.pbcinsertbypassicrc",
284 FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x01000000, NULL, HFILL }
286 { &hf_opa_snc_pbc_pbctestbadicrc, {
287 "Insert a bad ICRC", "opa.snc.pbc.pbctestbadicrc",
288 FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x00800000, NULL, HFILL }
290 { &hf_opa_snc_pbc_pbcfecn, {
291 "Set FECN bit", "opa.snc.pbc.pbcfecn",
292 FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x00400000, NULL, HFILL }
294 { &hf_opa_snc_pbc_reserved_21_16, {
295 "Reserved (6 bits)", "opa.snc.pbc.reserved_21_16",
296 FT_UINT32, BASE_HEX, NULL, 0x003F0000, NULL, HFILL }
298 { &hf_opa_snc_pbc_pbcvl, {
299 "VL", "opa.snc.pbc.pbcvl",
300 FT_UINT32, BASE_DEC, NULL, 0x0000F000, NULL, HFILL }
302 { &hf_opa_snc_pbc_pbclengthdws, {
303 "pbclengthdws", "opa.snc.pbc.pbclengthdws",
304 FT_UINT32, BASE_CUSTOM, CF_FUNC(cf_opa_snc_dw_to_b), 0x00000FFF, NULL, HFILL }
307 { &hf_opa_snc_rhf_icrcerr, {
308 "ICRC error", "opa.snc.rhf.icrcerr",
309 FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x80000000, NULL, HFILL }
311 { &hf_opa_snc_rhf_reserved_62, {
312 "Reserved (1 bit)", "opa.snc.rhf.reserved_62",
313 FT_UINT32, BASE_HEX, NULL, 0x40000000, NULL, HFILL }
315 { &hf_opa_snc_rhf_eccerr, {
316 "Internal memory Uncorrectable error", "opa.snc.rhf.eccerr",
317 FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x20000000, NULL, HFILL }
319 { &hf_opa_snc_rhf_lenerr, {
320 "Length Error", "opa.snc.rhf.lenerr",
321 FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x10000000, NULL, HFILL }
323 { &hf_opa_snc_rhf_tiderr, {
324 "TID Error", "opa.snc.rhf.tiderr",
325 FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x08000000, NULL, HFILL }
327 { &hf_opa_snc_rhf_rcvtypeerr, {
328 "Receive Type Error", "opa.snc.rhf.rcvtypeerr",
329 FT_UINT32, BASE_HEX, VALS(vals_opa_snc_rhf_rcvtypeerr), 0x07000000, NULL, HFILL }
331 { &hf_opa_snc_rhf_dcerr, {
332 "End Bad Packet Error", "opa.snc.rhf.dcerr",
333 FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x00800000, NULL, HFILL }
335 { &hf_opa_snc_rhf_dcuncerr, {
336 "Uncorrectable or parity error", "opa.snc.rhf.dcuncerr",
337 FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x00400000, NULL, HFILL }
339 { &hf_opa_snc_rhf_khdrlenerr, {
340 "KDETH Length Error", "opa.snc.rhf.khdrlenerr",
341 FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x00200000, NULL, HFILL }
343 { &hf_opa_snc_rhf_hdrqoffset, {
344 "Receive Header Offset", "opa.snc.rhf.hdrqoffset",
345 FT_UINT32, BASE_CUSTOM, CF_FUNC(cf_opa_snc_dw_to_b), 0x001FF000, NULL, HFILL }
347 { &hf_opa_snc_rhf_egroffset, {
348 "Eager Buffer Offset", "opa.snc.rhf.egroffset",
349 FT_UINT32, BASE_CUSTOM, CF_FUNC(cf_opa_snc_qw_to_b), 0x00000FFF, NULL, HFILL }
351 { &hf_opa_snc_rhf_rcvseq, {
352 "Receive Sequence", "opa.snc.rhf.rcvseq",
353 FT_UINT32, BASE_DEC, NULL, 0xF0000000, NULL, HFILL }
355 { &hf_opa_snc_rhf_dcinfo, {
356 "DC Info", "opa.snc.rhf.dcinfo",
357 FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x08000000, NULL, HFILL }
359 { &hf_opa_snc_rhf_egrindex, {
360 "Eager Buffer Index", "opa.snc.rhf.egrindex",
361 FT_UINT32, BASE_HEX, NULL, 0x07FF0000, NULL, HFILL }
363 { &hf_opa_snc_rhf_useegrbfr, {
364 "Use Eager Buffer", "opa.snc.rhf.useegrbfr",
365 FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x00008000, NULL, HFILL }
367 { &hf_opa_snc_rhf_rcvtype, {
368 "Packet Receive Type", "opa.snc.rhf.rcvtype",
369 FT_UINT32, BASE_DEC_HEX, VALS(vals_opa_snc_rhf_rcvtype), 0x00007000, NULL, HFILL }
371 { &hf_opa_snc_rhf_pktlen, {
372 "Packet Length", "opa.snc.rhf.pktlen",
373 FT_UINT32, BASE_CUSTOM, CF_FUNC(cf_opa_snc_dw_to_b), 0x00000FFF, NULL, HFILL }
377 static int *ett[] = {
378 &ett_snc,
379 &ett_sncpbc,
380 &ett_sncrhf,
383 static ei_register_info ei[] = {
384 { &ei_opa_snc_nobypass, {
385 "opa.snc.nobypass", PI_PROTOCOL, PI_WARN,
386 "Bypass packets not implemented in this version", EXPFILL }
390 proto_opa_snc = proto_register_protocol("Intel Omni-Path SnC - Omni-Path Snoop and Capture MetaData Header", "OPA SnC", "opa.snc");
391 opa_snc_handle = register_dissector("opa.snc", dissect_opa_snc, proto_opa_snc);
393 proto_register_field_array(proto_opa_snc, hf, array_length(hf));
394 proto_register_subtree_array(ett, array_length(ett));
396 expert_opa_snc = expert_register_protocol(proto_opa_snc);
397 expert_register_field_array(expert_opa_snc, ei, array_length(ei));
400 void proto_reg_handoff_opa_snc(void)
402 opa_9b_handle = find_dissector("opa");
404 /* announce an anonymous Omni-Path SnC dissector */
405 dissector_add_uint("erf.types.type", ERF_TYPE_OPA_SNC, opa_snc_handle);
410 * Editor modelines - https://www.wireshark.org/tools/modelines.html
412 * Local variables:
413 * c-basic-offset: 4
414 * tab-width: 8
415 * indent-tabs-mode: nil
416 * End:
418 * vi: set shiftwidth=4 tabstop=8 expandtab:
419 * :indentSize=4:tabSize=8:noTabs=true: