2 * Routines for Subnetwork Dependent Convergence Protocol (SNDCP) dissection
3 * Copyright 2000, Christian Falckenberg <christian.falckenberg@nortelnetworks.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
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.
34 #include <epan/packet.h>
35 #include <epan/reassemble.h>
37 /* Bitmasks for the bits in the address field
44 /* Initialize the protocol and registered fields
46 static int proto_sndcp = -1;
47 static int hf_sndcp_x = -1;
48 static int hf_sndcp_f = -1;
49 static int hf_sndcp_t = -1;
50 static int hf_sndcp_m = -1;
51 static int hf_sndcp_nsapi = -1;
52 static int hf_sndcp_nsapib = -1;
53 static int hf_sndcp_dcomp = -1;
54 static int hf_sndcp_pcomp = -1;
55 static int hf_sndcp_segment = -1;
56 static int hf_sndcp_npdu1 = -1;
57 static int hf_sndcp_npdu2 = -1;
59 /* These fields are used when reassembling N-PDU fragments
61 static int hf_npdu_fragments = -1;
62 static int hf_npdu_fragment = -1;
63 static int hf_npdu_fragment_overlap = -1;
64 static int hf_npdu_fragment_overlap_conflict = -1;
65 static int hf_npdu_fragment_multiple_tails = -1;
66 static int hf_npdu_fragment_too_long_fragment = -1;
67 static int hf_npdu_fragment_error = -1;
68 static int hf_npdu_reassembled_in = -1;
69 static int hf_npdu_reassembled_length = -1;
71 /* Initialize the subtree pointers
73 static gint ett_sndcp = -1;
74 static gint ett_sndcp_address_field = -1;
75 static gint ett_sndcp_compression_field = -1;
76 static gint ett_sndcp_npdu_field = -1;
77 static gint ett_npdu_fragment = -1;
78 static gint ett_npdu_fragments = -1;
80 /* Structure needed for the fragmentation routines in reassemble.c
82 static const fragment_items npdu_frag_items = {
87 &hf_npdu_fragment_overlap,
88 &hf_npdu_fragment_overlap_conflict,
89 &hf_npdu_fragment_multiple_tails,
90 &hf_npdu_fragment_too_long_fragment,
91 &hf_npdu_fragment_error,
92 &hf_npdu_reassembled_in,
93 &hf_npdu_reassembled_length,
97 /* dissectors for the data portion of this protocol
99 static dissector_handle_t data_handle;
100 static dissector_handle_t ip_handle;
102 /* reassembly of N-PDU
104 static GHashTable *npdu_fragment_table = NULL;
105 static GHashTable *sndcp_reassembled_table = NULL;
108 sndcp_defragment_init(void)
110 fragment_table_init(&npdu_fragment_table);
111 reassembled_table_init(&sndcp_reassembled_table);
116 static const value_string nsapi_t[] = {
117 { 0, "Escape mechanism for future extensions"},
118 { 1, "Point-to-Multipoint (PTM-M) Information" },
119 { 2, "Reserved for future use" },
120 { 3, "Reserved for future use" },
121 { 4, "Reserved for future use" },
122 { 5, "Dynamically allocated"},
123 { 6, "Dynamically allocated"},
124 { 7, "Dynamically allocated"},
125 { 8, "Dynamically allocated"},
126 { 9, "Dynamically allocated"},
127 { 10, "Dynamically allocated"},
128 { 11, "Dynamically allocated"},
129 { 12, "Dynamically allocated"},
130 { 13, "Dynamically allocated"},
131 { 14, "Dynamically allocated"},
132 { 15, "Dynamically allocated"},
136 static const value_string nsapi_abrv[] = {
156 static const value_string compression_vals[] = {
157 { 0, "No compression"},
158 { 1, "Pointer to selected protocol/data compression mechanism" },
159 { 2, "Pointer to selected protocol/data compression mechanism" },
160 { 3, "Pointer to selected protocol/data compression mechanism" },
161 { 4, "Pointer to selected protocol/data compression mechanism" },
162 { 5, "Pointer to selected protocol/data compression mechanism" },
163 { 6, "Pointer to selected protocol/data compression mechanism" },
164 { 7, "Pointer to selected protocol/data compression mechanism" },
165 { 8, "Pointer to selected protocol/data compression mechanism" },
166 { 9, "Pointer to selected protocol/data compression mechanism" },
167 { 10, "Pointer to selected protocol/data compression mechanism" },
168 { 11, "Pointer to selected protocol/data compression mechanism" },
169 { 12, "Pointer to selected protocol/data compression mechanism" },
170 { 13, "Pointer to selected protocol/data compression mechanism" },
171 { 14, "Pointer to selected protocol/data compression mechanism" },
172 { 15, "Pointer to selected protocol/data compression mechanism" },
176 static const true_false_string x_bit = {
178 "Set to 0 by transmitting SNDCP entity (ignored by receiver)"
180 static const true_false_string f_bit = {
181 "This SN-PDU is the first segment of an N-PDU",
182 "This SN-PDU is not the first segment of an N-PDU"
184 static const true_false_string t_bit = {
188 static const true_false_string m_bit = {
189 "Not the last segment of N-PDU, more segments to follow",
190 "Last segment of N-PDU"
193 /* Code to actually dissect the packets
196 dissect_sndcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
198 guint8 addr_field, comp_field, npdu_field1, nsapi, dcomp=0, pcomp=0;
199 guint16 offset=0, npdu=0, segment=0, npdu_field2;
200 tvbuff_t *next_tvb, *npdu_tvb;
202 gboolean first, more_frags, unack;
204 /* Set up structures needed to add the protocol subtree and manage it
206 proto_item *ti, *address_field_item, *compression_field_item, *npdu_field_item;
207 proto_tree *sndcp_tree = NULL, *address_field_tree, *compression_field_tree, *npdu_field_tree;
209 /* Make entries in Protocol column and clear Info column on summary display
211 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SNDCP");
212 col_clear(pinfo->cinfo, COL_INFO);
214 /* create display subtree for the protocol
217 ti = proto_tree_add_item(tree, proto_sndcp, tvb, 0, -1, FALSE);
218 sndcp_tree = proto_item_add_subtree(ti, ett_sndcp);
221 /* get address field from next byte
223 addr_field = tvb_get_guint8(tvb,offset);
224 nsapi = addr_field & 0xF;
225 first = addr_field & MASK_F;
226 more_frags = addr_field & MASK_M;
227 unack = addr_field & MASK_T;
229 /* add subtree for the address field
232 address_field_item = proto_tree_add_uint_format(sndcp_tree,hf_sndcp_nsapi,
233 tvb, offset,1, nsapi,
234 "Address field NSAPI: %d", nsapi );
235 address_field_tree = proto_item_add_subtree(address_field_item, ett_sndcp_address_field);
236 proto_tree_add_boolean(address_field_tree, hf_sndcp_x, tvb,offset,1, addr_field );
237 proto_tree_add_boolean(address_field_tree, hf_sndcp_f, tvb,offset,1, addr_field );
238 proto_tree_add_boolean(address_field_tree, hf_sndcp_t, tvb,offset,1, addr_field );
239 proto_tree_add_boolean(address_field_tree, hf_sndcp_m, tvb,offset,1, addr_field );
240 proto_tree_add_uint(address_field_tree, hf_sndcp_nsapib, tvb, offset, 1, addr_field );
244 /* get compression pointers from next byte if this is the first segment
247 comp_field = tvb_get_guint8(tvb,offset);
248 dcomp = comp_field & 0xF0;
249 pcomp = comp_field & 0x0F;
251 /* add subtree for the compression field
256 compression_field_item = proto_tree_add_text(sndcp_tree, tvb, offset,1, "No compression");
259 compression_field_item = proto_tree_add_text(sndcp_tree, tvb, offset,1, "Data compression");
264 compression_field_item = proto_tree_add_text(sndcp_tree, tvb, offset,1, "Protocol compression");
267 compression_field_item = proto_tree_add_text(sndcp_tree, tvb, offset,1, "Data and Protocol compression");
270 compression_field_tree = proto_item_add_subtree(compression_field_item, ett_sndcp_compression_field);
271 proto_tree_add_uint(compression_field_tree, hf_sndcp_dcomp, tvb, offset, 1, comp_field );
272 proto_tree_add_uint(compression_field_tree, hf_sndcp_pcomp, tvb, offset, 1, comp_field );
276 /* get N-PDU number from next byte for acknowledged mode (only for first segment)
279 npdu = npdu_field1 = tvb_get_guint8(tvb,offset);
280 if (check_col(pinfo->cinfo, COL_INFO))
281 col_add_fstr(pinfo->cinfo, COL_INFO, "SN-DATA N-PDU %d", npdu_field1);
283 npdu_field_item = proto_tree_add_text(sndcp_tree, tvb, offset,1, "Acknowledged mode, N-PDU %d", npdu_field1 );
284 npdu_field_tree = proto_item_add_subtree(npdu_field_item, ett_sndcp_npdu_field);
285 proto_tree_add_uint(npdu_field_tree, hf_sndcp_npdu1, tvb, offset, 1, npdu_field1 );
291 /* get segment and N-PDU number from next two bytes for unacknowledged mode
294 npdu_field2 = tvb_get_ntohs(tvb, offset);
295 segment = (npdu_field2 & 0xF000) >> 12;
296 npdu = (npdu_field2 & 0x0FFF);
297 if (check_col(pinfo->cinfo, COL_INFO))
298 col_add_fstr(pinfo->cinfo, COL_INFO, "SN-UNITDATA N-PDU %d (segment %d)", npdu, segment);
300 npdu_field_item = proto_tree_add_text(sndcp_tree, tvb, offset,2, "Unacknowledged mode, N-PDU %d (segment %d)", npdu, segment );
301 npdu_field_tree = proto_item_add_subtree(npdu_field_item, ett_sndcp_npdu_field);
302 proto_tree_add_uint(npdu_field_tree, hf_sndcp_segment, tvb, offset, 2, npdu_field2 );
303 proto_tree_add_uint(npdu_field_tree, hf_sndcp_npdu2, tvb, offset, 2, npdu_field2 );
308 /* handle N-PDU data, reassemble if necessary
310 if (first && !more_frags) {
311 next_tvb = tvb_new_subset_remaining (tvb, offset);
313 if (!dcomp && !pcomp) {
314 call_dissector(ip_handle, next_tvb, pinfo, tree);
317 call_dissector(data_handle, next_tvb, pinfo, tree);
321 /* Try reassembling fragments
323 fragment_data *fd_npdu = NULL;
324 guint32 reassembled_in = 0;
325 gboolean save_fragmented = pinfo->fragmented;
327 len = tvb_length_remaining(tvb, offset);
332 pinfo->fragmented = TRUE;
335 fd_npdu = fragment_add_seq_check(tvb, offset, pinfo, npdu,
336 npdu_fragment_table, sndcp_reassembled_table, segment, len, more_frags);
338 fd_npdu = fragment_add(tvb, offset, pinfo, npdu,
339 npdu_fragment_table, offset, len, more_frags);
341 npdu_tvb = process_reassembled_data(tvb, offset, pinfo,
342 "Reassembled N-PDU", fd_npdu, &npdu_frag_items,
347 reassembled_in = fd_npdu->reassembled_in;
348 if (pinfo->fd->num == reassembled_in) {
349 /* Reassembled in this very packet:
350 * We can safely hand the tvb to the IP dissector
352 call_dissector(ip_handle, npdu_tvb, pinfo, tree);
355 /* Not reassembled in this packet
357 if (check_col(pinfo->cinfo, COL_INFO)) {
358 col_append_fstr(pinfo->cinfo, COL_INFO,
359 " (N-PDU payload reassembled in packet %u)",
360 fd_npdu->reassembled_in);
363 proto_tree_add_text(sndcp_tree, tvb, offset, -1, "Payload");
367 /* Not reassembled yet, or not reassembled at all
369 if (check_col(pinfo->cinfo, COL_INFO)) {
371 col_append_fstr(pinfo->cinfo, COL_INFO, " (Unreassembled fragment %u)", segment);
373 col_append_str(pinfo->cinfo, COL_INFO, " (Unreassembled fragment)");
376 proto_tree_add_text(sndcp_tree, tvb, offset, -1, "Payload");
379 /* Now reset fragmentation information in pinfo
381 pinfo->fragmented = save_fragmented;
386 /* Register the protocol with Wireshark
387 this format is required because a script is used to build the C function
388 that calls all the protocol registration.
392 proto_register_sndcp(void)
394 /* Setup list of header fields
396 static hf_register_info hf[] = {
400 FT_UINT8, BASE_DEC, VALS(nsapi_abrv), 0x0,
401 "Network Layer Service Access Point Identifier", HFILL
407 FT_BOOLEAN,8, TFS(&x_bit), MASK_X,
408 "Spare bit (should be 0)", HFILL
412 { "First segment indicator bit",
414 FT_BOOLEAN,8, TFS(&f_bit), MASK_F,
421 FT_BOOLEAN,8, TFS(&t_bit), MASK_T,
428 FT_BOOLEAN,8, TFS(&m_bit), MASK_M,
435 FT_UINT8, BASE_DEC, VALS(compression_vals), 0xF0,
436 "Data compression coding", HFILL
442 FT_UINT8, BASE_DEC, VALS(compression_vals), 0x0F,
443 "Protocol compression coding", HFILL
449 FT_UINT8, BASE_DEC , VALS(nsapi_t), 0xf,
450 "Network Layer Service Access Point Identifier",HFILL
456 FT_UINT16, BASE_DEC, NULL, 0xF000,
457 "Segment number", HFILL
463 FT_UINT8, BASE_DEC, NULL, 0,
470 FT_UINT16, BASE_DEC, NULL, 0x0FFF,
477 { &hf_npdu_fragment_overlap,
478 { "Fragment overlap",
479 "npdu.fragment.overlap",
480 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
481 "Fragment overlaps with other fragments", HFILL
484 { &hf_npdu_fragment_overlap_conflict,
485 { "Conflicting data in fragment overlap",
486 "npdu.fragment.overlap.conflict",
487 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
488 "Overlapping fragments contained conflicting data", HFILL
491 { &hf_npdu_fragment_multiple_tails,
492 { "Multiple tail fragments found",
493 "npdu.fragment.multipletails",
494 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
495 "Several tails were found when defragmenting the packet", HFILL
498 { &hf_npdu_fragment_too_long_fragment,
499 { "Fragment too long",
500 "npdu.fragment.toolongfragment",
501 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
502 "Fragment contained data past end of packet", HFILL
505 { &hf_npdu_fragment_error,
506 { "Defragmentation error",
507 "npdu.fragment.error",
508 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
509 "Defragmentation error due to illegal fragments", HFILL
512 { &hf_npdu_reassembled_in,
514 "npdu.reassembled.in",
515 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
516 "N-PDU fragments are reassembled in the given packet", HFILL
519 { &hf_npdu_reassembled_length,
520 { "Reassembled N-PDU length",
521 "npdu.reassembled.length",
522 FT_UINT32, BASE_DEC, NULL, 0x0,
523 "The total length of the reassembled payload", HFILL
529 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
533 { &hf_npdu_fragments,
536 FT_NONE, BASE_NONE, NULL, 0x0,
542 /* Setup protocol subtree array */
543 static gint *ett[] = {
545 &ett_sndcp_address_field,
546 &ett_sndcp_compression_field,
547 &ett_sndcp_npdu_field,
552 /* Register the protocol name and description */
553 proto_sndcp = proto_register_protocol("Subnetwork Dependent Convergence Protocol",
556 /* Required function calls to register the header fields and subtrees used */
557 proto_register_field_array(proto_sndcp, hf, array_length(hf));
558 proto_register_subtree_array(ett, array_length(ett));
559 register_dissector("sndcp", dissect_sndcp, proto_sndcp);
560 register_init_routine(sndcp_defragment_init);
563 /* If this dissector uses sub-dissector registration add a registration routine.
564 This format is required because a script is used to find these routines and
565 create the code that calls these routines.
568 proto_reg_handoff_sndcp(void)
570 dissector_handle_t sndcp_handle;
572 sndcp_handle = find_dissector("sndcp");
574 /* Register SNDCP dissector with LLC layer for SAPI 3,5,9 and 11
576 dissector_add("llcgprs.sapi", 3, sndcp_handle);
577 dissector_add("llcgprs.sapi", 5, sndcp_handle);
578 dissector_add("llcgprs.sapi", 9, sndcp_handle);
579 dissector_add("llcgprs.sapi", 11, sndcp_handle);
581 /* Find IP and data handle for upper layer dissectors
583 ip_handle = find_dissector("ip");
584 data_handle = find_dissector("data");