TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / epan / dissectors / packet-dtcp-ip.c
blobd61dc8f1c0cdf54404e76fd24e278d94053b18c0
1 /* packet-dtcp-ip.c
2 * Routines for DTCP-IP dissection
3 * (Digital Transmission Content Protection over IP)
5 * Copyright 2012, Martin Kaiser <martin@kaiser.cx>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
15 * quote from www.dtcp.com:
16 * "DTCP is a method of protecting audio and audiovisual entertainment
17 * content on home and personal networks over highbandwidth bidirectional
18 * digital interfaces"
20 * this dissector supports DTCP on top of TCP/IP
21 * for now, only the AKE (authentication and key exchange)
22 * messages are implemented
24 * the dissector is based on the publicly available (informative) specifications
25 * obtained from http://www.dtcp.com/specifications.aspx
26 * (complete specifications are available only to licensees)
29 #include "config.h"
31 #include <epan/packet.h>
33 static int proto_dtcp_ip;
35 void proto_register_dtcp_ip(void);
36 void proto_reg_handoff_dtcp_ip(void);
38 static dissector_handle_t dtcp_ip_handle;
40 static int ett_dtcp_ip;
41 static int ett_dtcp_ip_ctrl;
42 static int ett_dtcp_ip_ake_procedure;
44 static int hf_dtcp_ip_type;
45 static int hf_dtcp_ip_length;
46 static int hf_dtcp_ip_ctype;
47 static int hf_dtcp_ip_category;
48 static int hf_dtcp_ip_ake_id;
49 static int hf_dtcp_ip_subfct;
50 static int hf_dtcp_ip_ake_procedure;
51 static int hf_dtcp_ip_ake_proc_full;
52 static int hf_dtcp_ip_ake_proc_ex_full;
53 static int hf_dtcp_ip_ake_xchg_key;
54 static int hf_dtcp_ip_subfct_dep;
55 static int hf_dtcp_ip_ake_label;
56 static int hf_dtcp_ip_number;
57 static int hf_dtcp_ip_status;
58 static int hf_dtcp_ip_ake_info;
60 #define CTRL_LEN 8 /* control block is 8 bytes long */
62 /* these definitions are taken from the public DTCP specification
63 it sounds like the private version defines more subfunctions */
64 static const value_string subfct[] = {
65 { 0x01, "challenge" },
66 { 0x02, "response" },
67 { 0x03, "exchange_key" },
68 { 0, NULL }
71 static int * const ake_procedure_fields[] = {
72 &hf_dtcp_ip_ake_proc_full,
73 &hf_dtcp_ip_ake_proc_ex_full,
74 NULL
77 /* only one bit may be set in exchange_key, we can use a value string */
78 static const value_string xchg_key[] = {
79 { 0x00, "None" },
80 { 0x08, "Exchange key (K_X) for AES-128" },
81 { 0x20, "Session Exchange key (K_S) for AES-128" },
82 { 0x40, "Remote Exchange key (K_R) for AES-128" },
83 { 0, NULL }
86 static const value_string ctrl_status[] = {
87 { 0x0, "No error" },
88 { 0x1, "Support for no more authentication procedures is currently available" },
89 { 0x7, "Any other error" },
90 { 0xF, "No information" },
91 { 0, NULL }
95 /* check if the packet is actually DTCP-IP */
96 static bool
97 dtcp_ip_check_packet(tvbuff_t *tvb)
99 unsigned offset = 0;
100 uint8_t type;
101 uint16_t length;
103 /* a minimum DTCP-IP AKE packet has Type (1 byte),
104 Length (2 bytes) and Control (8 bytes) */
105 if (tvb_reported_length(tvb) < 1+2+CTRL_LEN)
106 return false;
108 type = tvb_get_uint8(tvb, offset);
109 /* all DTCP-IP AKE packets have type 1 */
110 if (type != 1)
111 return false;
112 offset++;
114 /* length field is length of the control block +
115 length of ake_info */
116 length = tvb_get_ntohs(tvb, offset);
117 if (length < CTRL_LEN)
118 return false;
120 return true;
123 static int
124 dissect_dtcp_ip(tvbuff_t *tvb, packet_info *pinfo,
125 proto_tree *tree, void *data _U_)
127 unsigned offset = 0;
128 uint16_t length;
129 proto_item *pi;
130 proto_tree *dtcp_ip_tree, *dtcp_ip_ctrl_tree;
131 uint8_t subfct_val;
132 const char *subfct_str;
133 int ake_info_len;
136 if (!dtcp_ip_check_packet(tvb))
137 return 0; /* not a DTCP-IP packet */
139 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DTCP-IP");
140 col_clear(pinfo->cinfo, COL_INFO);
142 pi = proto_tree_add_protocol_format(tree, proto_dtcp_ip,
143 tvb, 0, -1, "DTCP-IP");
144 dtcp_ip_tree = proto_item_add_subtree(pi, ett_dtcp_ip);
146 proto_tree_add_item(dtcp_ip_tree, hf_dtcp_ip_type,
147 tvb, offset, 1, ENC_BIG_ENDIAN);
148 offset++;
150 length = tvb_get_ntohs(tvb, 1);
151 /* overall packet length is 1 byte for tag + 2 bytes for length field +
152 the value encoded in the length field */
153 proto_item_set_len(pi, 1+2+length);
154 proto_tree_add_item(dtcp_ip_tree, hf_dtcp_ip_length,
155 tvb, offset, 2, ENC_BIG_ENDIAN);
156 offset += 2;
158 dtcp_ip_ctrl_tree = proto_tree_add_subtree(dtcp_ip_tree,
159 tvb, offset, CTRL_LEN, ett_dtcp_ip_ctrl, NULL, "Control");
161 /* for now, we don't display the 4 reserved bits */
162 proto_tree_add_item(dtcp_ip_ctrl_tree, hf_dtcp_ip_ctype,
163 tvb, offset, 1, ENC_BIG_ENDIAN);
164 offset++;
166 proto_tree_add_item(dtcp_ip_ctrl_tree, hf_dtcp_ip_category,
167 tvb, offset, 1, ENC_BIG_ENDIAN);
168 proto_tree_add_item(dtcp_ip_ctrl_tree, hf_dtcp_ip_ake_id,
169 tvb, offset, 1, ENC_BIG_ENDIAN);
170 offset++;
172 subfct_val = tvb_get_uint8(tvb, offset);
173 subfct_str = val_to_str_const(subfct_val, subfct, "unknown");
174 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL,
175 "%s (0x%x)", subfct_str, subfct_val);
176 proto_tree_add_item(dtcp_ip_ctrl_tree, hf_dtcp_ip_subfct,
177 tvb, offset, 1, ENC_BIG_ENDIAN);
178 offset++;
180 proto_tree_add_bitmask(dtcp_ip_ctrl_tree, tvb, offset,
181 hf_dtcp_ip_ake_procedure, ett_dtcp_ip_ake_procedure,
182 ake_procedure_fields, ENC_BIG_ENDIAN);
183 offset++;
185 proto_tree_add_item(dtcp_ip_ctrl_tree, hf_dtcp_ip_ake_xchg_key,
186 tvb, offset, 1, ENC_BIG_ENDIAN);
187 offset++;
189 proto_tree_add_item(dtcp_ip_ctrl_tree, hf_dtcp_ip_subfct_dep,
190 tvb, offset, 1, ENC_BIG_ENDIAN);
191 offset++;
193 proto_tree_add_item(dtcp_ip_ctrl_tree, hf_dtcp_ip_ake_label,
194 tvb, offset, 1, ENC_BIG_ENDIAN);
195 offset++;
197 proto_tree_add_item(dtcp_ip_ctrl_tree, hf_dtcp_ip_number,
198 tvb, offset, 1, ENC_BIG_ENDIAN);
199 proto_tree_add_item(dtcp_ip_ctrl_tree, hf_dtcp_ip_status,
200 tvb, offset, 1, ENC_BIG_ENDIAN);
201 offset++;
203 ake_info_len = length-CTRL_LEN;
204 if (ake_info_len > 0) {
205 proto_tree_add_item(dtcp_ip_tree, hf_dtcp_ip_ake_info,
206 tvb, offset, ake_info_len, ENC_NA);
207 offset += (unsigned)ake_info_len;
210 return offset;
214 void
215 proto_register_dtcp_ip(void)
217 static hf_register_info hf[] = {
218 { &hf_dtcp_ip_type,
219 { "Type", "dtcp-ip.type", FT_UINT8, BASE_HEX,
220 NULL, 0, NULL, HFILL } },
221 { &hf_dtcp_ip_length,
222 { "Length", "dtcp-ip.length", FT_UINT16, BASE_DEC,
223 NULL, 0, NULL, HFILL } },
224 /* it seems that / is not allowed in a filter name ... */
225 { &hf_dtcp_ip_ctype,
226 { "ctype/response", "dtcp-ip.ctrl.ctype_response", FT_UINT8,
227 BASE_HEX, NULL, 0x0F, NULL, HFILL } },
228 { &hf_dtcp_ip_category,
229 { "Category", "dtcp-ip.ctrl.category", FT_UINT8, BASE_HEX,
230 NULL, 0xF0, NULL, HFILL } },
231 { &hf_dtcp_ip_ake_id,
232 { "AKE_ID", "dtcp-ip.ctrl.ake_id", FT_UINT8, BASE_HEX,
233 NULL, 0x0F, NULL, HFILL } },
234 { &hf_dtcp_ip_subfct,
235 { "Subfunction", "dtcp-ip.ctrl.subfunction", FT_UINT8, BASE_HEX,
236 VALS(subfct), 0, NULL, HFILL } },
237 { &hf_dtcp_ip_ake_procedure,
238 { "AKE_procedure", "dtcp-ip.ctrl.ake_procedure", FT_UINT8,
239 BASE_HEX, NULL, 0, NULL, HFILL } },
240 /* 8 is the bit witdh of the field */
241 { &hf_dtcp_ip_ake_proc_full,
242 { "Full Authentication procedure",
243 "dtcp-ip.ctrl.ake_procedure.full_auth", FT_BOOLEAN, 8,
244 NULL, 0x04, NULL, HFILL } },
245 { &hf_dtcp_ip_ake_proc_ex_full,
246 { "Extended Full Authentication procedure",
247 "dtcp-ip.ctrl.ake_procedure.ex_full_auth", FT_BOOLEAN, 8,
248 NULL, 0x08, NULL, HFILL } },
249 { &hf_dtcp_ip_ake_xchg_key,
250 { "exchange_key", "dtcp-ip.ctrl.exchange_key", FT_UINT8, BASE_HEX,
251 VALS(xchg_key), 0, NULL, HFILL } },
252 { &hf_dtcp_ip_subfct_dep,
253 { "subfunction_dependent", "dtcp-ip.ctrl.subfunction_dependent",
254 FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } },
255 { &hf_dtcp_ip_ake_label,
256 { "AKE_label", "dtcp-ip.ctrl.ake_label", FT_UINT8, BASE_HEX,
257 NULL, 0, NULL, HFILL } },
258 { &hf_dtcp_ip_number,
259 { "number", "dtcp-ip.ctrl.number", FT_UINT8, BASE_HEX,
260 NULL, 0xF0, NULL, HFILL } },
261 { &hf_dtcp_ip_status,
262 { "Status", "dtcp-ip.ctrl.status", FT_UINT8, BASE_HEX,
263 VALS(ctrl_status), 0x0F, NULL, HFILL } },
264 { &hf_dtcp_ip_ake_info,
265 { "AKE_Info", "dtcp-ip.ake_info", FT_BYTES, BASE_NONE,
266 NULL, 0, NULL, HFILL } }
269 static int *ett[] = {
270 &ett_dtcp_ip,
271 &ett_dtcp_ip_ctrl,
272 &ett_dtcp_ip_ake_procedure
275 proto_dtcp_ip = proto_register_protocol("Digital Transmission Content Protection over IP", "DTCP-IP", "dtcp-ip");
277 proto_register_field_array(proto_dtcp_ip, hf, array_length(hf));
278 proto_register_subtree_array(ett, array_length(ett));
280 dtcp_ip_handle = register_dissector("dtcp-ip", dissect_dtcp_ip, proto_dtcp_ip);
283 void
284 proto_reg_handoff_dtcp_ip(void)
286 dissector_add_for_decode_as_with_preference("tcp.port", dtcp_ip_handle);
290 * Editor modelines - https://www.wireshark.org/tools/modelines.html
292 * Local variables:
293 * c-basic-offset: 4
294 * tab-width: 8
295 * indent-tabs-mode: nil
296 * End:
298 * vi: set shiftwidth=4 tabstop=8 expandtab:
299 * :indentSize=4:tabSize=8:noTabs=true: