2 * Routines for MACSEC dissection
3 * Copyright 2013, Allan W. Nielsen <anielsen@vitesse.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
31 #include <epan/etypes.h>
33 #define TCI_V_MASK 0x80
34 #define TCI_ES_MASK 0x40
35 #define TCI_SC_MASK 0x20
36 #define TCI_SCB_MASK 0x10
37 #define TCI_E_MASK 0x08
38 #define TCI_C_MASK 0x04
39 #define TCI_AN_MASK 0x03
42 static dissector_handle_t data_handle
;
44 static int proto_macsec
= -1;
45 static int hf_macsec_TCI
= -1;
46 static int hf_macsec_TCI_V
= -1;
47 static int hf_macsec_TCI_ES
= -1;
48 static int hf_macsec_TCI_SC
= -1;
49 static int hf_macsec_TCI_SCB
= -1;
50 static int hf_macsec_TCI_E
= -1;
51 static int hf_macsec_TCI_C
= -1;
52 static int hf_macsec_AN
= -1;
53 static int hf_macsec_SL
= -1;
54 static int hf_macsec_PN
= -1;
55 static int hf_macsec_SCI_System_identifier
= -1;
56 static int hf_macsec_SCI_port_number
= -1;
57 static int hf_macsec_ICV
= -1;
59 /* Initialize the subtree pointers */
60 static gint ett_macsec
= -1;
61 static gint ett_macsec_tci
= -1;
63 /* Code to actually dissect the packets */
64 static int dissect_macsec(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
) {
65 unsigned sectag_length
, data_length
, icv_length
= 16;
66 unsigned sectag_offset
= 0, data_offset
, icv_offset
;
69 proto_item
*macsec_item
, *tci_item
;
70 proto_tree
*macsec_tree
, *tci_tree
;
74 tci_an_field
= tvb_get_guint8(tvb
, 0);
76 if ((tci_an_field
& TCI_V_MASK
) != 0) { /* version must be zero */
80 if (tci_an_field
& TCI_SC_MASK
) {
86 /* Check for short length */
87 if (tvb_length(tvb
) <= (sectag_length
+ icv_length
)) {
91 data_offset
= sectag_length
;
92 data_length
= tvb_length(tvb
) - sectag_length
- icv_length
;
93 icv_offset
= data_length
+ data_offset
;
95 next_tvb
= tvb_new_subset(tvb
, data_offset
, data_length
, data_length
);
97 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "MACSEC");
98 col_set_str(pinfo
->cinfo
, COL_INFO
, "MACsec frame");
101 macsec_item
= proto_tree_add_item(tree
,
102 proto_macsec
, tvb
, 0, sectag_length
, ENC_NA
);
103 macsec_tree
= proto_item_add_subtree(macsec_item
, ett_macsec
);
105 tci_item
= proto_tree_add_uint_format(macsec_tree
, hf_macsec_TCI
, tvb
,
106 sectag_offset
, 1, tci_an_field
,
107 "TCI=0x%02x: V=%d, ES=%d, SC=%d, SCB=%d, E=%d, C=%d, AN=%d",
109 ((TCI_V_MASK
& tci_an_field
) ? 1:0),
110 ((TCI_ES_MASK
& tci_an_field
) ? 1:0),
111 ((TCI_SC_MASK
& tci_an_field
) ? 1:0),
112 ((TCI_SCB_MASK
& tci_an_field
) ? 1:0),
113 ((TCI_E_MASK
& tci_an_field
) ? 1:0),
114 ((TCI_C_MASK
& tci_an_field
) ? 1:0),
115 (TCI_AN_MASK
& tci_an_field
));
116 tci_tree
= proto_item_add_subtree(tci_item
, ett_macsec_tci
);
118 proto_tree_add_item(tci_tree
, hf_macsec_TCI_V
, tvb
, sectag_offset
, 1, ENC_NA
);
119 proto_tree_add_item(tci_tree
, hf_macsec_TCI_ES
, tvb
, sectag_offset
, 1, ENC_NA
);
120 proto_tree_add_item(tci_tree
, hf_macsec_TCI_SC
, tvb
, sectag_offset
, 1, ENC_NA
);
121 proto_tree_add_item(tci_tree
, hf_macsec_TCI_SCB
, tvb
, sectag_offset
, 1, ENC_NA
);
122 proto_tree_add_item(tci_tree
, hf_macsec_TCI_E
, tvb
, sectag_offset
, 1, ENC_NA
);
123 proto_tree_add_item(tci_tree
, hf_macsec_TCI_C
, tvb
, sectag_offset
, 1, ENC_NA
);
124 proto_tree_add_item(tci_tree
, hf_macsec_AN
, tvb
, sectag_offset
, 1, ENC_NA
);
125 proto_tree_add_item(macsec_tree
, hf_macsec_SL
, tvb
, sectag_offset
+ 1, 1, ENC_NA
);
126 proto_tree_add_item(macsec_tree
, hf_macsec_PN
, tvb
, sectag_offset
+ 2, 4, ENC_NA
);
128 if (sectag_length
== 14) {
129 proto_tree_add_item(macsec_tree
, hf_macsec_SCI_System_identifier
,
130 tvb
, sectag_offset
+ 6, 6, ENC_NA
);
131 proto_tree_add_item(macsec_tree
, hf_macsec_SCI_port_number
, tvb
,
132 sectag_offset
+ 12, 2, ENC_NA
);
135 call_dissector(data_handle
, next_tvb
, pinfo
, tree
);
137 proto_tree_add_item(macsec_tree
, hf_macsec_ICV
, tvb
, icv_offset
,
141 return tvb_length(tvb
);
145 proto_register_macsec(void)
147 static hf_register_info hf
[] = {
148 { &hf_macsec_TCI
, { "TAG Control Information", "macsec.TCI",FT_UINT8
,
149 BASE_HEX
, NULL
, 0xfc, NULL
, HFILL
} },
150 { &hf_macsec_TCI_V
, { "VER", "macsec.TCI.V", FT_UINT8
, BASE_HEX
,
151 NULL
, 0x80, NULL
, HFILL
} },
152 { &hf_macsec_TCI_ES
, { "ES", "macsec.TCI.ES", FT_UINT8
, BASE_HEX
, NULL
,
153 0x40, NULL
, HFILL
} },
154 { &hf_macsec_TCI_SC
, { "SC", "macsec.TCI.SC", FT_UINT8
, BASE_HEX
, NULL
,
155 0x20, NULL
, HFILL
} },
156 { &hf_macsec_TCI_SCB
, { "SCB", "macsec.TCI.SCB", FT_UINT8
, BASE_HEX
,
157 NULL
, 0x10, NULL
, HFILL
} },
158 { &hf_macsec_TCI_E
, { "E", "macsec.TCI.E", FT_UINT8
, BASE_HEX
, NULL
,
159 0x08, NULL
, HFILL
} },
160 { &hf_macsec_TCI_C
, { "C", "macsec.TCI.C", FT_UINT8
, BASE_HEX
, NULL
,
161 0x04, NULL
, HFILL
} },
162 { &hf_macsec_AN
, { "AN", "macsec.AN", FT_UINT8
,
163 BASE_HEX
, NULL
, 0x03, NULL
, HFILL
} },
164 { &hf_macsec_SL
, { "Short length", "macsec.SL", FT_UINT8
, BASE_DEC
,
165 NULL
, 0xFF, NULL
, HFILL
} },
166 { &hf_macsec_PN
, { "Packet number", "macsec.PN", FT_UINT32
, BASE_DEC
,
167 NULL
, 0xFFFFFFFF, NULL
, HFILL
} },
168 { &hf_macsec_SCI_System_identifier
,
169 { "System Identifier", "macsec.SCI.SytemIdentifier",
170 FT_ETHER
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
} },
171 { &hf_macsec_SCI_port_number
,
172 { "Port number", "macsec.SCI.port_number",
173 FT_UINT16
, BASE_DEC
, NULL
, 0xFFFF, NULL
, HFILL
} },
174 { &hf_macsec_ICV
, { "ICV", "macsec.ICV",
175 FT_BYTES
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
} }
178 /* Setup protocol subtree array */
179 static gint
*ett
[] = {
184 /* Register the protocol name and description */
185 proto_macsec
= proto_register_protocol("802.1AE Secure tag", "macsec", "macsec");
187 /* Required function calls to register the header fields and subtrees used */
188 proto_register_field_array(proto_macsec
, hf
, array_length(hf
));
189 proto_register_subtree_array(ett
, array_length(ett
));
193 proto_reg_handoff_macsec(void)
195 dissector_handle_t macsec_handle
;
196 data_handle
= find_dissector("data");
197 macsec_handle
= new_create_dissector_handle(dissect_macsec
, proto_macsec
);
198 dissector_add_uint("ethertype", ETHERTYPE_MACSEC
, macsec_handle
);
202 * Editor modelines - http://www.wireshark.org/tools/modelines.html
207 * indent-tabs-mode: nil
210 * vi: set shiftwidth=4 tabstop=8 expandtab:
211 * :indentSize=4:tabSize=8:noTabs=true: