3 * Dissector for the DECT (Digital Enhanced Cordless Telecommunications)
4 * DLC protocol layer as described in ETSI EN 300 175-4 V2.7.1 (2017-11)
6 * DLC is sometimes also called LAPC, which is a derivative of LAPDm (GSM),
7 * which is a derivative of LAPD (ISDN).
9 * Copyright 2018 by Harald Welte <laforge@gnumonks.org>
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * SPDX-License-Identifier: GPL-2.0-or-later
19 #include <epan/conversation.h>
20 #include <epan/packet.h>
21 #include <epan/prefs.h>
22 #include <epan/reassemble.h>
23 #include <epan/xdlc.h>
25 void proto_register_dect_dlc(void);
27 static int proto_dect_dlc
;
29 static int hf_dect_dlc_address
;
30 static int hf_dect_dlc_nlf
;
31 static int hf_dect_dlc_lln
;
32 static int hf_dect_dlc_sapi
;
33 static int hf_dect_dlc_cr
;
35 static int hf_dect_dlc_control
;
36 static int hf_dect_dlc_n_r
;
37 static int hf_dect_dlc_n_s
;
38 static int hf_dect_dlc_p
;
39 static int hf_dect_dlc_f
;
40 static int hf_dect_dlc_s_ftype
;
41 static int hf_dect_dlc_u_modifier_cmd
;
42 static int hf_dect_dlc_u_modifier_resp
;
43 static int hf_dect_dlc_ftype_i
;
44 static int hf_dect_dlc_ftype_s_u
;
46 static int hf_dect_dlc_length
;
47 static int hf_dect_dlc_el
;
48 static int hf_dect_dlc_m
;
49 static int hf_dect_dlc_len
;
51 static int ett_dect_dlc
;
52 static int ett_dect_dlc_address
;
53 static int ett_dect_dlc_control
;
54 static int ett_dect_dlc_length
;
56 static dissector_handle_t data_handle
;
58 static dissector_table_t dlc_sapi_dissector_table
;
60 static reassembly_table dect_dlc_reassembly_table
;
62 static int hf_dect_dlc_fragment_data
;
63 static int hf_dect_dlc_fragment
;
64 static int hf_dect_dlc_fragments
;
65 static int hf_dect_dlc_fragment_overlap
;
66 static int hf_dect_dlc_fragment_overlap_conflicts
;
67 static int hf_dect_dlc_fragment_multiple_tails
;
68 static int hf_dect_dlc_fragment_too_long_fragment
;
69 static int hf_dect_dlc_fragment_error
;
70 static int hf_dect_dlc_fragment_count
;
71 static int hf_dect_dlc_reassembled_in
;
72 static int hf_dect_dlc_reassembled_length
;
74 static int ett_dect_dlc_fragment
;
75 static int ett_dect_dlc_fragments
;
77 static const fragment_items dect_dlc_frag_items
= {
78 /* Fragment subtrees */
79 &ett_dect_dlc_fragment
,
80 &ett_dect_dlc_fragments
,
82 &hf_dect_dlc_fragments
,
83 &hf_dect_dlc_fragment
,
84 &hf_dect_dlc_fragment_overlap
,
85 &hf_dect_dlc_fragment_overlap_conflicts
,
86 &hf_dect_dlc_fragment_multiple_tails
,
87 &hf_dect_dlc_fragment_too_long_fragment
,
88 &hf_dect_dlc_fragment_error
,
89 &hf_dect_dlc_fragment_count
,
90 /* Reassembled in field */
91 &hf_dect_dlc_reassembled_in
,
92 /* Reassembled length field */
93 &hf_dect_dlc_reassembled_length
,
94 /* Reassembled data field */
100 static wmem_map_t
*dect_dlc_last_n_s_map
;
102 #define DECT_DLC_M 0x02
103 #define DECT_DLC_M_SHIFT 1
105 static bool reassemble_dect_dlc
= true;
107 static const xdlc_cf_items dect_dlc_cf_items
= {
112 &hf_dect_dlc_s_ftype
,
113 &hf_dect_dlc_u_modifier_cmd
,
114 &hf_dect_dlc_u_modifier_resp
,
115 &hf_dect_dlc_ftype_i
,
116 &hf_dect_dlc_ftype_s_u
119 static const value_string dect_dlc_sapi_vals
[] = {
120 { 0, "Connection oriented signalling" },
121 { 3, "Connectionless signalling" },
125 static const value_string dect_dlc_lln_vals
[] = {
137 static const value_string dect_dlc_m_vals
[] = {
138 { 0, "Last segment" },
139 { 1, "More segments" },
143 static const value_string dect_dlc_el_vals
[] = {
144 { 0, "More octets" },
145 { 1, "Final octet" },
150 static int dissect_dect_dlc(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void _U_
*data
)
152 proto_tree
*dlc_tree
, *addr_tree
, *length_tree
;
153 proto_item
*dlc_ti
, *addr_ti
, *length_ti
;
154 bool is_response
= false;
156 int available_length
;
159 uint8_t cr
, sapi
, length
, len
, n_s
;
161 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "DECT-DLC");
163 cr
= tvb_get_uint8(tvb
, 0) & 0x02;
164 if (pinfo
->p2p_dir
== P2P_DIR_RECV
)
165 is_response
= cr
? false : true;
166 else if (pinfo
->p2p_dir
== P2P_DIR_SENT
)
167 is_response
= cr
? true : false;
169 dlc_ti
= proto_tree_add_item(tree
, proto_dect_dlc
, tvb
, 0, 3, ENC_NA
);
170 dlc_tree
= proto_item_add_subtree(dlc_ti
, ett_dect_dlc
);
172 addr_ti
= proto_tree_add_item(dlc_tree
, hf_dect_dlc_address
, tvb
, 0, 1, ENC_NA
);
173 addr_tree
= proto_item_add_subtree(addr_ti
, ett_dect_dlc_address
);
175 sapi
= (tvb_get_uint8(tvb
, 0) & 0x0C) >> 2;
176 proto_tree_add_item(addr_tree
, hf_dect_dlc_nlf
, tvb
, 0, 1, ENC_NA
);
177 proto_tree_add_item(addr_tree
, hf_dect_dlc_lln
, tvb
, 0, 1, ENC_NA
);
178 proto_tree_add_item(addr_tree
, hf_dect_dlc_sapi
, tvb
, 0, 1, ENC_NA
);
179 proto_tree_add_item(addr_tree
, hf_dect_dlc_cr
, tvb
, 0, 1, ENC_NA
);
181 control
= dissect_xdlc_control(tvb
, 1, pinfo
, dlc_tree
, hf_dect_dlc_control
,
182 ett_dect_dlc_control
, &dect_dlc_cf_items
, NULL
, NULL
, NULL
,
183 is_response
, false, false);
184 n_s
= (control
& XDLC_N_S_MASK
) >> XDLC_N_S_SHIFT
;
186 length_ti
= proto_tree_add_item(dlc_tree
, hf_dect_dlc_length
, tvb
, 2, 1, ENC_NA
);
187 length_tree
= proto_item_add_subtree(length_ti
, ett_dect_dlc_length
);
188 length
= tvb_get_uint8(tvb
, 2);
189 proto_tree_add_uint(length_tree
, hf_dect_dlc_len
, tvb
, 2, 1, length
);
190 proto_tree_add_uint(length_tree
, hf_dect_dlc_m
, tvb
, 2, 1, length
);
191 proto_tree_add_uint(length_tree
, hf_dect_dlc_el
, tvb
, 2, 1, length
);
194 available_length
= tvb_captured_length(tvb
) - 3;
195 if (available_length
> 0) {
196 payload
= tvb_new_subset_length_caplen(tvb
, 3, MIN(len
, available_length
), len
);
198 /* Potentially segmented I frame */
199 if( (control
& XDLC_I_MASK
) == XDLC_I
&& reassemble_dect_dlc
&& !pinfo
->flags
.in_error_pkt
)
201 fragment_head
*fd_m
= NULL
;
202 tvbuff_t
*reassembled
= NULL
;
203 uint32_t fragment_id
;
204 bool save_fragmented
= pinfo
->fragmented
, add_frag
;
206 m
= (length
& DECT_DLC_M
) >> DECT_DLC_M_SHIFT
;
207 pinfo
->fragmented
= m
;
209 fragment_id
= (conversation_get_id_from_elements(pinfo
, CONVERSATION_NONE
, USE_LAST_ENDPOINT
) << 3) | ( sapi
<< 1) | pinfo
->p2p_dir
;
211 if (!PINFO_FD_VISITED(pinfo
)) {
212 /* Check if new N(S) is equal to previous N(S) (to avoid adding retransmissions in reassembly table)
213 As GUINT_TO_POINTER macro does not allow to differentiate NULL from 0, use 1-8 range instead of 0-7 */
214 unsigned *p_last_n_s
= (unsigned*)wmem_map_lookup(dect_dlc_last_n_s_map
, GUINT_TO_POINTER(fragment_id
));
215 if (GPOINTER_TO_UINT(p_last_n_s
) == (unsigned)(n_s
+1)) {
219 wmem_map_insert(dect_dlc_last_n_s_map
, GUINT_TO_POINTER(fragment_id
), GUINT_TO_POINTER(n_s
+1));
226 /* This doesn't seem the best way of doing it as doesn't
227 take N(S) into account, but N(S) isn't always 0 for
228 the first fragment! */
229 fd_m
= fragment_add_seq_next (&dect_dlc_reassembly_table
, payload
, 0,
231 fragment_id
, /* uint32_t ID for fragments belonging together */
233 /*n_s uint32_t fragment sequence number */
234 len
, /* uint32_t fragment length */
235 m
); /* More fragments? */
237 reassembled
= process_reassembled_data(payload
, 0, pinfo
,
238 "Reassembled DLC", fd_m
, &dect_dlc_frag_items
,
241 /* Reassembled into this packet */
242 if (fd_m
&& pinfo
->num
== fd_m
->reassembled_in
) {
243 if (!dissector_try_uint(dlc_sapi_dissector_table
, sapi
,
244 reassembled
, pinfo
, tree
))
245 call_data_dissector(reassembled
, pinfo
, tree
);
248 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Fragment)");
249 proto_tree_add_item(dlc_tree
, hf_dect_dlc_fragment_data
, payload
, 0, -1, ENC_NA
);
253 /* Now reset fragmentation information in pinfo */
254 pinfo
->fragmented
= save_fragmented
;
258 if (!PINFO_FD_VISITED(pinfo
) && ((control
& XDLC_S_U_MASK
) == XDLC_U
) && ((control
& XDLC_U_MODIFIER_MASK
) == XDLC_SABM
)) {
259 /* SABM frame; reset the last N(S) to an invalid value */
260 uint32_t fragment_id
= (conversation_get_id_from_elements(pinfo
, CONVERSATION_GSMTAP
, USE_LAST_ENDPOINT
) << 3) | (sapi
<< 1) | pinfo
->p2p_dir
;
261 wmem_map_insert(dect_dlc_last_n_s_map
, GUINT_TO_POINTER(fragment_id
), GUINT_TO_POINTER(0));
263 if (!dissector_try_uint(dlc_sapi_dissector_table
, sapi
, payload
, pinfo
, tree
))
264 call_data_dissector(payload
, pinfo
, tree
);
268 return tvb_captured_length(tvb
);
271 void proto_register_dect_dlc(void)
273 static hf_register_info hf
[] =
275 { &hf_dect_dlc_address
,
276 { "Address Field", "dect_dlc.address_field", FT_UINT8
, BASE_HEX
,
277 NULL
, 0x0, NULL
, HFILL
281 { "NLF", "dect_dlc.nlf", FT_UINT8
, BASE_DEC
,
282 NULL
, 0x80, "New Link Flag", HFILL
286 { "LLN", "dect_dlc.lln", FT_UINT8
, BASE_DEC
,
287 VALS(dect_dlc_lln_vals
), 0x70, "Logical Link Number", HFILL
291 { "SAPI", "dect_dlc.sapi", FT_UINT8
, BASE_DEC
,
292 VALS(dect_dlc_sapi_vals
), 0x0C, "Service Access Point Identifier", HFILL
296 { "C/R", "dect_dlc.cr", FT_UINT8
, BASE_DEC
,
297 NULL
, 0x02, "Command/Response field bit", HFILL
300 { &hf_dect_dlc_control
,
301 { "Control Field", "dect_dlc.control_field", FT_UINT8
, BASE_HEX
,
302 NULL
, 0x0, NULL
, HFILL
306 { "N(R)", "dect_dlc.control.n_r", FT_UINT8
, BASE_DEC
,
307 NULL
, 0xE0, NULL
, HFILL
311 { "N(S)", "dect_dlc.control.n_s", FT_UINT8
, BASE_DEC
,
312 NULL
, 0x0E, NULL
, HFILL
316 { "Poll", "dect_dlc.control.p", FT_BOOLEAN
, 8,
317 NULL
, 0x10, NULL
, HFILL
321 { "Final", "dect_dlc.control.f", FT_BOOLEAN
, 8,
322 NULL
, 0x10, NULL
, HFILL
325 { &hf_dect_dlc_s_ftype
,
326 { "Supervisory frame type", "dect_dlc.control.s_ftype", FT_UINT8
, BASE_HEX
,
327 VALS(stype_vals
), XDLC_S_FTYPE_MASK
, NULL
, HFILL
330 { &hf_dect_dlc_u_modifier_cmd
,
331 { "Command", "dect_dlc.control.u_modifier_cmd", FT_UINT8
, BASE_HEX
,
332 VALS(modifier_vals_cmd
), XDLC_U_MODIFIER_MASK
, NULL
, HFILL
335 { &hf_dect_dlc_u_modifier_resp
,
336 { "Response", "dect_dlc.control.u_modifier_resp", FT_UINT8
, BASE_HEX
,
337 VALS(modifier_vals_resp
), XDLC_U_MODIFIER_MASK
, NULL
, HFILL
340 { &hf_dect_dlc_ftype_i
,
341 { "Frame type", "dect_dlc.control.ftype", FT_UINT8
, BASE_HEX
,
342 VALS(ftype_vals
), XDLC_I_MASK
, NULL
, HFILL
345 { &hf_dect_dlc_ftype_s_u
,
346 { "Frame type", "dect_dlc.control.ftype", FT_UINT8
, BASE_HEX
,
347 VALS(ftype_vals
), XDLC_S_U_MASK
, NULL
, HFILL
350 { &hf_dect_dlc_length
,
351 { "Length Field", "dect_dlc.length_field", FT_UINT8
, BASE_HEX
,
352 NULL
, 0x0, NULL
, HFILL
356 { "EL", "dect_dlc.el", FT_UINT8
, BASE_DEC
,
357 VALS(dect_dlc_el_vals
), 0x01, "Length indicator field extension bit", HFILL
361 { "M", "dect_dlc.m", FT_UINT8
, BASE_DEC
,
362 VALS(dect_dlc_m_vals
), 0x02, "More data bit", HFILL
366 { "Length", "dect_dlc.length", FT_UINT8
, BASE_DEC
,
367 NULL
, 0xFC, "Length indicator", HFILL
371 /* Fragment reassembly */
372 { &hf_dect_dlc_fragment_data
,
373 { "Fragment Data", "dect_dlc.fragment_data", FT_NONE
, BASE_NONE
,
374 NULL
, 0x00, NULL
, HFILL
377 { &hf_dect_dlc_fragments
,
378 { "Message fragments", "dect_dlc.fragments",
379 FT_NONE
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
382 { &hf_dect_dlc_fragment
,
383 { "Message fragment", "dect_dlc.fragment",
384 FT_FRAMENUM
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
387 { &hf_dect_dlc_fragment_overlap
,
388 { "Message fragment overlap", "dect_dlc.fragment.overlap",
389 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
392 { &hf_dect_dlc_fragment_overlap_conflicts
,
393 { "Message fragment overlapping with conflicting data",
394 "dect_dlc.fragment.overlap.conflicts",
395 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
398 { &hf_dect_dlc_fragment_multiple_tails
,
399 { "Message has multiple tail fragments",
400 "dect_dlc.fragment.multiple_tails",
401 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
404 { &hf_dect_dlc_fragment_too_long_fragment
,
405 { "Message fragment too long", "dect_dlc.fragment.too_long_fragment",
406 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
409 { &hf_dect_dlc_fragment_error
,
410 { "Message defragmentation error", "dect_dlc.fragment.error",
411 FT_FRAMENUM
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
414 { &hf_dect_dlc_fragment_count
,
415 { "Message fragment count", "dect_dlc.fragment.count",
416 FT_UINT32
, BASE_DEC
, NULL
, 0x00, NULL
, HFILL
419 { &hf_dect_dlc_reassembled_in
,
420 { "Reassembled in", "dect_dlc.reassembled.in",
421 FT_FRAMENUM
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
424 { &hf_dect_dlc_reassembled_length
,
425 { "Reassembled length", "dect_dlc.reassembled.length",
426 FT_UINT32
, BASE_DEC
, NULL
, 0x00, NULL
, HFILL
431 static int *ett
[] = {
433 &ett_dect_dlc_address
,
434 &ett_dect_dlc_control
,
435 &ett_dect_dlc_length
,
436 &ett_dect_dlc_fragment
,
437 &ett_dect_dlc_fragments
,
440 /* Register protocol */
441 proto_dect_dlc
= proto_register_protocol("DECT DLC (LAPC)", "DECT-DLC", "dect_dlc");
443 proto_register_subtree_array(ett
, array_length(ett
));
444 proto_register_field_array(proto_dect_dlc
, hf
, array_length(hf
));
446 register_dissector("dect_dlc", dissect_dect_dlc
, proto_dect_dlc
);
448 dlc_sapi_dissector_table
= register_dissector_table("dect_dlc.sapi", "DECT DLC SAPI", proto_dect_dlc
, FT_UINT8
, BASE_DEC
);
450 data_handle
= find_dissector("data");
452 reassembly_table_register(&dect_dlc_reassembly_table
,
453 &addresses_reassembly_table_functions
);
454 dect_dlc_last_n_s_map
= wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), g_direct_hash
, g_direct_equal
);
458 * Editor modelines - http://www.wireshark.org/tools/modelines.html
463 * indent-tabs-mode: t
466 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
467 * :indentSize=8:tabSize=8:noTabs=false: