2 * Routines for LAPDm frame disassembly
3 * Duncan Salerno <duncan.salerno@googlemail.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (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
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 * Mobile Station - Base Stations System (MS - BSS) Interface Data Link (DL) Layer Specification
29 * Base Station Controller - Base Transceiver Station (BSC - BTS) interface; Layer 2 specification
30 * http://www.3gpp.org/ftp/Specs/html-info/44006.htm
32 * From 3GPP TS 44.006:
34 * LAPDm is used for information sent on the control channels BCCH, AGCH, NCH,
35 * PCH, FACCH, SACCH and SDCCH as defined in 3GPP TS 44.003.
37 * AGCH, NCH and PCH are sometimes referred to by the collective name CCCH.
38 * FACCH, SACCH and SDCCH are, similarly, referred to by the collective name DCCH.
40 * Format A is used on DCCHs for frames where there is no information field.
41 * Formats B, Bter and B4 are used on DCCHs for frames containing an information field:
42 * Format Bter is used on request of higher layers if and only if short L2 header type 1 is
43 * supported and a UI command is to be transmitted on SAPI 0;
44 * Format B4 is used for UI frames transmitted by the network on SACCH;
45 * Format B is applied in all other cases.
46 * Format Bbis is used only on BCCH, PCH, NCH, and AGCH.
47 * In addition there is a Format C for transmission of random access signals.
49 * This module currently supports A, B, B4
50 * In the future will support Bter
51 * Bbis and C should be supported elsewhere
61 #include <epan/packet.h>
62 #include <epan/prefs.h>
63 #include <epan/xdlc.h>
64 #include <epan/reassemble.h>
66 static int proto_lapdm = -1;
67 static int hf_lapdm_address = -1;
68 static int hf_lapdm_ea = -1;
69 static int hf_lapdm_cr = -1;
70 static int hf_lapdm_sapi = -1;
71 static int hf_lapdm_lpd = -1;
73 static int hf_lapdm_control = -1;
74 static int hf_lapdm_n_r = -1;
75 static int hf_lapdm_n_s = -1;
76 static int hf_lapdm_p = -1;
77 static int hf_lapdm_f = -1;
78 static int hf_lapdm_s_ftype = -1;
79 static int hf_lapdm_u_modifier_cmd = -1;
80 static int hf_lapdm_u_modifier_resp = -1;
81 static int hf_lapdm_ftype_i = -1;
82 static int hf_lapdm_ftype_s_u = -1;
84 static int hf_lapdm_length = -1;
85 static int hf_lapdm_el = -1;
86 static int hf_lapdm_m = -1;
87 static int hf_lapdm_len = -1;
90 * LAPDm fragment handling
92 static int hf_lapdm_fragments = -1;
93 static int hf_lapdm_fragment = -1;
94 static int hf_lapdm_fragment_overlap = -1;
95 static int hf_lapdm_fragment_overlap_conflicts = -1;
96 static int hf_lapdm_fragment_multiple_tails = -1;
97 static int hf_lapdm_fragment_too_long_fragment = -1;
98 static int hf_lapdm_fragment_error = -1;
99 static int hf_lapdm_reassembled_in = -1;
101 static gint ett_lapdm = -1;
102 static gint ett_lapdm_address = -1;
103 static gint ett_lapdm_control = -1;
104 static gint ett_lapdm_length = -1;
105 static gint ett_lapdm_fragment = -1;
106 static gint ett_lapdm_fragments = -1;
108 static GHashTable *lapdm_fragment_table = NULL;
109 static GHashTable *lapdm_reassembled_table = NULL;
111 static dissector_table_t lapdm_sapi_dissector_table;
113 static dissector_handle_t data_handle;
115 static gboolean reassemble_lapdm = TRUE;
118 * Bits in the address field.
120 #define LAPDM_SAPI 0x1c /* Service Access Point Identifier */
121 #define LAPDM_SAPI_SHIFT 2
122 #define LAPDM_CR 0x02 /* Command/Response bit */
123 #define LAPDM_EA 0x01 /* First Address Extension bit */
124 #define LAPDM_LPD 0x60 /* Link Protocol Discriminator */
127 * Bits in the length field.
129 #define LAPDM_EL 0x01 /* Extended Length = 1 */
130 #define LAPDM_M 0x02 /* More fragments */
131 #define LAPDM_M_SHIFT 1
132 #define LAPDM_LEN 0xfc /* Length */
133 #define LAPDM_LEN_SHIFT 2
135 #define LAPDM_HEADER_LEN 3
137 #define LAPDM_SAPI_RR_CC_MM 0
138 #define LAPDM_SAPI_SMS 3
140 /* Used only for U frames */
141 static const xdlc_cf_items lapdm_cf_items = {
147 &hf_lapdm_u_modifier_cmd,
148 &hf_lapdm_u_modifier_resp,
153 static const value_string lapdm_ea_vals[] = {
154 { 0, "More octets" },
155 { 1, "Final octet" },
159 static const value_string lapdm_sapi_vals[] = {
160 { LAPDM_SAPI_RR_CC_MM, "RR/MM/CC" },
161 { LAPDM_SAPI_SMS, "SMS/SS" },
165 static const value_string lapdm_lpd_vals[] = {
167 { 1, "Cell broadcast service" },
171 static const value_string lapdm_m_vals[] = {
172 { 0, "Last segment" },
173 { 1, "More segments" },
177 static const value_string lapdm_el_vals[] = {
178 { 0, "More octets" },
179 { 1, "Final octet" },
184 static const fragment_items lapdm_frag_items = {
185 /* Fragment subtrees */
187 &ett_lapdm_fragments,
188 /* Fragment fields */
191 &hf_lapdm_fragment_overlap,
192 &hf_lapdm_fragment_overlap_conflicts,
193 &hf_lapdm_fragment_multiple_tails,
194 &hf_lapdm_fragment_too_long_fragment,
195 &hf_lapdm_fragment_error,
196 /* Reassembled in field */
197 &hf_lapdm_reassembled_in,
203 lapdm_defragment_init (void)
205 fragment_table_init (&lapdm_fragment_table);
206 reassembled_table_init(&lapdm_reassembled_table);
211 dissect_lapdm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
213 proto_tree *lapdm_tree, *addr_tree, *length_tree;
214 proto_item *lapdm_ti, *addr_ti, *length_ti;
215 guint8 address, length, cr, sapi, len, n_s;
219 int available_length;
220 gboolean is_response = FALSE;
222 /* Check that there's enough data */
223 if (tvb_length(tvb) < LAPDM_HEADER_LEN)
226 if (check_col(pinfo->cinfo, COL_PROTOCOL))
227 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LAPDm");
229 address = tvb_get_guint8(tvb, 0);
230 length = tvb_get_guint8(tvb, 2);
232 cr = address & LAPDM_CR;
233 if (pinfo->p2p_dir == P2P_DIR_RECV) {
234 is_response = cr ? FALSE : TRUE;
236 else if (pinfo->p2p_dir == P2P_DIR_SENT) {
237 is_response = cr ? TRUE : FALSE;
241 lapdm_ti = proto_tree_add_item(tree, proto_lapdm, tvb, 0, LAPDM_HEADER_LEN, FALSE);
242 lapdm_tree = proto_item_add_subtree(lapdm_ti, ett_lapdm);
244 addr_ti = proto_tree_add_uint(lapdm_tree, hf_lapdm_address, tvb, 0, 1, address);
245 addr_tree = proto_item_add_subtree(addr_ti, ett_lapdm_address);
247 proto_tree_add_uint(addr_tree, hf_lapdm_lpd, tvb, 0, 1, address);
248 proto_tree_add_uint(addr_tree, hf_lapdm_sapi, tvb, 0, 1, address);
249 proto_tree_add_uint(addr_tree, hf_lapdm_cr, tvb, 0, 1, address);
250 proto_tree_add_uint(addr_tree, hf_lapdm_ea, tvb, 0, 1, address);
257 control = dissect_xdlc_control(tvb, 1, pinfo, lapdm_tree, hf_lapdm_control,
258 ett_lapdm_control, &lapdm_cf_items, NULL /* LAPDm doesnt support extended */, NULL, NULL,
259 is_response, FALSE, FALSE);
262 length_ti = proto_tree_add_uint(lapdm_tree, hf_lapdm_length, tvb,
264 length_tree = proto_item_add_subtree(length_ti, ett_lapdm_length);
266 proto_tree_add_uint(length_tree, hf_lapdm_len, tvb, 2, 1, length);
267 proto_tree_add_uint(length_tree, hf_lapdm_m, tvb, 2, 1, length);
268 proto_tree_add_uint(length_tree, hf_lapdm_el, tvb, 2, 1, length);
271 sapi = (address & LAPDM_SAPI) >> LAPDM_SAPI_SHIFT;
272 len = (length & LAPDM_LEN) >> LAPDM_LEN_SHIFT;
273 n_s = (control & XDLC_N_S_MASK) >> XDLC_N_S_SHIFT;
274 m = (length & LAPDM_M) >> LAPDM_M_SHIFT;
275 available_length = tvb_length(tvb) - LAPDM_HEADER_LEN;
277 /* No point in doing anything if no payload
279 if( !MIN(len, available_length) )
282 payload = tvb_new_subset(tvb, LAPDM_HEADER_LEN, MIN(len,available_length), -1);
284 /* Potentially segmented I frame
286 if( (control & XDLC_I_MASK) == XDLC_I && reassemble_lapdm )
288 fragment_data *fd_m = NULL;
289 tvbuff_t *reassembled = NULL;
290 gboolean save_fragmented = pinfo->fragmented;
292 pinfo->fragmented = m;
293 /* This doesn't seem the best way of doing it as doesn't
294 take N(S) into account, but N(S) isn't always 0 for
297 fd_m = fragment_add_seq_next (payload, 0, pinfo,
298 0, /* guint32 ID for fragments belonging together */
299 lapdm_fragment_table, /* list of message fragments */
300 lapdm_reassembled_table, /* list of reassembled messages */
301 /*n_s guint32 fragment sequence number */
302 len, /* guint32 fragment length */
303 m); /* More fragments? */
305 reassembled = process_reassembled_data(payload, 0, pinfo,
306 "Reassembled Message", fd_m, &lapdm_frag_items,
309 /* Reassembled into this packet
311 if (fd_m && pinfo->fd->num == fd_m->reassembled_in) {
312 if (!dissector_try_port(lapdm_sapi_dissector_table, sapi,
313 reassembled, pinfo, tree))
314 call_dissector(data_handle, reassembled, pinfo, tree);
317 if (check_col(pinfo->cinfo, COL_INFO)) {
318 col_append_str(pinfo->cinfo, COL_INFO, " (Fragment)");
321 proto_tree_add_text(lapdm_tree, payload, 0, -1, "Fragment Data");
325 /* Now reset fragmentation information in pinfo
327 pinfo->fragmented = save_fragmented;
332 If we have some data, try and dissect it (only happens for UI, SABM, UA or I frames)
334 if (!dissector_try_port(lapdm_sapi_dissector_table, sapi,
335 payload, pinfo, tree))
336 call_dissector(data_handle,payload, pinfo, tree);
341 proto_register_lapdm(void)
343 static hf_register_info hf[] = {
346 { "Address Field", "lapdm.address_field", FT_UINT8, BASE_HEX, NULL, 0x0,
350 { "EA", "lapdm.ea", FT_UINT8, BASE_DEC, VALS(lapdm_ea_vals), LAPDM_EA,
351 "Address field extension bit", HFILL }},
354 { "C/R", "lapdm.cr", FT_UINT8, BASE_DEC, NULL, LAPDM_CR,
355 "Command/response field bit", HFILL }},
358 { "LPD", "lapdm.lpd", FT_UINT8, BASE_DEC, VALS(lapdm_lpd_vals), LAPDM_LPD,
359 "Link Protocol Discriminator", HFILL }},
362 { "SAPI", "lapdm.sapi", FT_UINT8, BASE_DEC, VALS(lapdm_sapi_vals), LAPDM_SAPI,
363 "Service access point identifier", HFILL }},
366 { "Control Field", "lapdm.control_field", FT_UINT8, BASE_HEX, NULL, 0x0,
367 "Control field", HFILL }},
370 { "N(R)", "lapdm.control.n_r", FT_UINT8, BASE_DEC,
371 NULL, XDLC_N_R_MASK, NULL, HFILL }},
374 { "N(S)", "lapdm.control.n_s", FT_UINT8, BASE_DEC,
375 NULL, XDLC_N_S_MASK, NULL, HFILL }},
378 { "Poll", "lapdm.control.p", FT_BOOLEAN, 8,
379 TFS(&tfs_true_false), XDLC_P_F, NULL, HFILL }},
382 { "Final", "lapdm.control.f", FT_BOOLEAN, 8,
383 TFS(&tfs_true_false), XDLC_P_F, NULL, HFILL }},
386 { "Supervisory frame type", "lapdm.control.s_ftype", FT_UINT8, BASE_HEX,
387 VALS(stype_vals), XDLC_S_FTYPE_MASK, NULL, HFILL }},
389 { &hf_lapdm_u_modifier_cmd,
390 { "Command", "lapdm.control.u_modifier_cmd", FT_UINT8, BASE_HEX,
391 VALS(modifier_vals_cmd), XDLC_U_MODIFIER_MASK, NULL, HFILL }},
393 { &hf_lapdm_u_modifier_resp,
394 { "Response", "lapdm.control.u_modifier_resp", FT_UINT8, BASE_HEX,
395 VALS(modifier_vals_resp), XDLC_U_MODIFIER_MASK, NULL, HFILL }},
398 { "Frame type", "lapdm.control.ftype", FT_UINT8, BASE_HEX,
399 VALS(ftype_vals), XDLC_I_MASK, NULL, HFILL }},
401 { &hf_lapdm_ftype_s_u,
402 { "Frame type", "lapdm.control.ftype", FT_UINT8, BASE_HEX,
403 VALS(ftype_vals), XDLC_S_U_MASK, NULL, HFILL }},
406 { "Length Field", "lapdm.length_field", FT_UINT8, BASE_HEX,
407 NULL, 0x0, "Length field", HFILL }},
410 { "EL", "lapdm.el", FT_UINT8, BASE_DEC,
411 VALS(lapdm_el_vals), LAPDM_EL, "Length indicator field extension bit", HFILL }},
414 { "M", "lapdm.m", FT_UINT8, BASE_DEC,
415 VALS(lapdm_m_vals), LAPDM_M, "More data bit", HFILL }},
418 { "Length", "lapdm.length", FT_UINT8, BASE_DEC,
419 NULL, LAPDM_LEN, "Length indicator", HFILL }},
421 /* Fragment reassembly
423 { &hf_lapdm_fragments,
424 { "Message fragments", "lapdm.fragments", FT_NONE, BASE_NONE,
425 NULL, 0x00, "LAPDm Message fragments", HFILL }},
427 { &hf_lapdm_fragment,
428 { "Message fragment", "lapdm.fragment", FT_FRAMENUM, BASE_NONE,
429 NULL, 0x00, "LAPDm Message fragment", HFILL }},
431 { &hf_lapdm_fragment_overlap,
432 { "Message fragment overlap", "lapdm.fragment.overlap", FT_BOOLEAN, BASE_NONE,
433 NULL, 0x0, "LAPDm Message fragment overlaps with other fragment(s)", HFILL }},
435 { &hf_lapdm_fragment_overlap_conflicts,
436 { "Message fragment overlapping with conflicting data", "lapdm.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE,
437 NULL, 0x0, "LAPDm Message fragment overlaps with conflicting data", HFILL }},
439 { &hf_lapdm_fragment_multiple_tails,
440 { "Message has multiple tail fragments", "lapdm.fragment.multiple_tails", FT_BOOLEAN, BASE_NONE,
441 NULL, 0x0, "LAPDm Message fragment has multiple tail fragments", HFILL }},
443 { &hf_lapdm_fragment_too_long_fragment,
444 { "Message fragment too long", "lapdm.fragment.too_long_fragment", FT_BOOLEAN, BASE_NONE,
445 NULL, 0x0, "LAPDm Message fragment data goes beyond the packet end", HFILL }},
447 { &hf_lapdm_fragment_error,
448 { "Message defragmentation error", "lapdm.fragment.error", FT_FRAMENUM, BASE_NONE,
449 NULL, 0x00, "LAPDm Message defragmentation error due to illegal fragments", HFILL }},
451 { &hf_lapdm_reassembled_in,
452 { "Reassembled in", "lapdm.reassembled.in", FT_FRAMENUM, BASE_NONE,
453 NULL, 0x00, "LAPDm Message has been reassembled in this packet.", HFILL }}
456 static gint *ett[] = {
465 module_t *lapdm_module;
467 proto_lapdm = proto_register_protocol("Link Access Procedure, Channel Dm (LAPDm)", "LAPDm", "lapdm");
468 proto_register_field_array (proto_lapdm, hf, array_length(hf));
469 proto_register_subtree_array(ett, array_length(ett));
471 register_dissector("lapdm", dissect_lapdm, proto_lapdm);
473 lapdm_sapi_dissector_table = register_dissector_table("lapdm.sapi", "LAPDm SAPI", FT_UINT8, BASE_DEC);
475 lapdm_module = prefs_register_protocol(proto_lapdm, NULL);
476 prefs_register_bool_preference(lapdm_module, "reassemble",
477 "Reassemble fragmented LAPDm packets",
478 "Whether the dissector should defragment LAPDm messages spanning multiple packets.",
480 register_init_routine (lapdm_defragment_init);
484 proto_reg_handoff_lapdm(void)
486 data_handle = find_dissector("data");