2 * Routines for FLIP packet dissection
4 * Copyright 2009, Juha Siltanen <juha.siltanen@nsn.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
14 * FLIP (Flow Layer Internal Protocol) is a proprietary protocol
15 * developed by Nokia Solutions and Networks (previous was 'Nokia Siemens Networks').
21 * Version 0.0.1, November 23rd, 2009.
23 * Support for the basic and checksum headers.
25 * Version 0.0.2, August 26th, 2010.
27 * Support for payload dissecting.
29 * Version 0.0.3, September 14th, 2010.
31 * Bugfix: sorting by protocol didn't always fill in the protocol column.
36 #include <epan/packet.h>
37 #include <epan/etypes.h>
38 #include <epan/decode_as.h>
39 #include <epan/in_cksum.h>
41 #include <epan/prefs.h>
43 void proto_register_flip(void);
44 void proto_reg_handoff_flip(void);
46 static dissector_handle_t flip_handle
;
48 static int proto_flip
;
51 static int hf_flip_basic_e
;
52 static int hf_flip_basic_reserved
;
53 static int hf_flip_basic_flowid
;
54 static int hf_flip_basic_seqnum
;
55 static int hf_flip_basic_len
;
58 static int hf_flip_chksum_etype
;
59 static int hf_flip_chksum_spare
;
60 static int hf_flip_chksum_e
;
61 static int hf_flip_chksum_chksum
;
63 #define FLIP_BASIC (0)
64 #define FLIP_CHKSUM (1)
66 #define FLIP_BASIC_HDR_LEN (8)
67 #define FLIP_CHKSUM_HDR_LEN (4)
68 #define FLIP_EXTENSION_HDR_MIN_LEN (4)
70 static const value_string flip_etype
[] = {
71 { FLIP_CHKSUM
, "Checksum" },
75 static dissector_table_t subdissector_table
;
78 static int ett_flip_basic
;
79 static int ett_flip_chksum
;
80 static int ett_flip_payload
;
82 static void flip_prompt(packet_info
*pinfo _U_
, char* result
)
84 snprintf(result
, MAX_DECODE_AS_PROMPT_LEN
, "Decode FLIP payload protocol as");
87 /* Dissect the checksum extension header. */
89 dissect_flip_chksum_hdr(tvbuff_t
*tvb
,
92 uint16_t computed_chksum
,
93 bool *ext_hdr_follows_ptr
)
95 proto_tree
*chksum_hdr_tree
;
97 uint8_t chksum_hdr_etype
;
98 uint8_t chksum_hdr_ext
;
99 uint16_t chksum_hdr_chksum
;
104 chksum_hdr_tree
= NULL
;
109 dw
= tvb_get_ntohl(tvb
, offset
);
110 chksum_hdr_etype
= (uint8_t) ((dw
& 0xFF000000) >> 24);
111 chksum_hdr_ext
= (uint8_t) ((dw
& 0x00010000) >> 16);
112 chksum_hdr_chksum
= (uint16_t) (dw
& 0x0000FFFF);
114 /* The actually shouldn't be any headers after checksum. */
115 if (chksum_hdr_ext
== 1) {
116 *ext_hdr_follows_ptr
= true;
119 *ext_hdr_follows_ptr
= false;
123 chksum_hdr_tree
= proto_tree_add_subtree(tree
, tvb
, offset
+ 0, 4,
124 ett_flip_chksum
, NULL
, "Checksum Header");
127 proto_tree_add_uint_format_value(chksum_hdr_tree
, hf_flip_chksum_etype
,
128 tvb
, offset
+ 0, 1, dw
,
129 "%s", val_to_str_const(chksum_hdr_etype
,
133 proto_tree_add_item(chksum_hdr_tree
, hf_flip_chksum_spare
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
136 proto_tree_add_item(chksum_hdr_tree
, hf_flip_chksum_e
,
137 tvb
, offset
, 4, ENC_BIG_ENDIAN
);
138 /* CHKSUM: 16 bits. */
139 proto_tree_add_uint_format_value(
141 hf_flip_chksum_chksum
,
144 "0x%04x [%s] (computed 0x%04x)",
146 ((chksum_hdr_chksum
== computed_chksum
) ? "Correct" : "Incorrect"),
150 /* Show faulty checksums. */
151 if (computed_chksum
!= chksum_hdr_chksum
) {
152 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
153 "Checksum 0x%04x [%s] (computed 0x%04x)",
159 bytes_dissected
+= FLIP_CHKSUM_HDR_LEN
;
161 return bytes_dissected
;
163 } /* dissect_flip_chksum_hdr() */
165 /* Protocol dissection */
167 dissect_flip(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
169 proto_item
*ti
= NULL
;
170 proto_tree
*flip_tree
= NULL
;
171 proto_tree
*basic_hdr_tree
= NULL
;
176 /* Basic header fields. */
177 uint8_t basic_hdr_ext
;
178 uint32_t basic_hdr_flow_id
;
179 uint16_t basic_hdr_len
;
181 bool ext_hdr
= false;
183 int bytes_dissected
= 0;
189 /* Error handling for basic header. */
190 bool is_faulty_frame
= false;
192 /* Show this protocol as FLIP. */
193 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "FLIP");
196 * The frame can be faulty in several ways:
197 * - too short (even for the basic header)
198 * - length inconsistent (header and frame info different)
199 * - checksum doesn't check out
200 * - extension header is indicated, but the frame is too short for it
201 * - unknown extension header type
204 /* Check that there's enough data at least for the basic header. */
205 frame_len
= tvb_captured_length(tvb
);
206 if (frame_len
< FLIP_BASIC_HDR_LEN
) {
210 bytes_dissected
+= FLIP_BASIC_HDR_LEN
;
212 /* Process the first 32 bits of the basic header. */
213 dw1
= tvb_get_ntohl(tvb
, offset
+ 0);
214 basic_hdr_ext
= ((dw1
& 0x80000000) >> 31);
215 basic_hdr_flow_id
= (dw1
& 0x0FFFFFFF);
217 /* Process the second 32 bits of the basic header. */
218 basic_hdr_len
= (uint16_t) (tvb_get_ntohl(tvb
, offset
+ 4) & 0x0000FFFF);
221 /* Does the basic header indicate that an extension is next? */
222 if (basic_hdr_ext
== 1) {
226 flip_len
= basic_hdr_len
;
229 * Check the length value.
231 if ((flip_len
< FLIP_BASIC_HDR_LEN
) || (flip_len
> frame_len
)) {
232 /* Faulty frame. Show the basic header anyway for debugging. */
233 is_faulty_frame
= true;
236 /* Fill in the info column. */
237 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
238 "FlowID %s", val_to_str(basic_hdr_flow_id
, NULL
, "0x%08x"));
240 flip_tvb
= tvb_new_subset_length(tvb
, 0, frame_len
);
242 /* We are asked for details. */
244 ti
= proto_tree_add_protocol_format(
245 tree
, proto_flip
, flip_tvb
, 0, flip_len
,
246 "NSN FLIP, FlowID %s",
247 val_to_str(basic_hdr_flow_id
, NULL
, "0x%08x"));
248 flip_tree
= proto_item_add_subtree(ti
, ett_flip
);
251 basic_hdr_tree
= proto_tree_add_subtree(flip_tree
, flip_tvb
, offset
, 8, ett_flip_basic
, NULL
, "Basic Header");
253 /* Extension header follows? 1 bit. */
254 proto_tree_add_item(basic_hdr_tree
, hf_flip_basic_e
, flip_tvb
, offset
, 4, ENC_BIG_ENDIAN
);
256 /* Reserved: 3 bits. */
257 proto_tree_add_item(basic_hdr_tree
, hf_flip_basic_reserved
, flip_tvb
, offset
, 4, ENC_BIG_ENDIAN
);
259 /* Flow ID: 28 bits. */
260 proto_tree_add_item(basic_hdr_tree
, hf_flip_basic_flowid
, flip_tvb
, offset
, 4, ENC_BIG_ENDIAN
);
262 /* Sequence number: 16 bits. */
263 proto_tree_add_item(basic_hdr_tree
, hf_flip_basic_seqnum
, flip_tvb
, offset
+ 4, 2, ENC_BIG_ENDIAN
);
265 /* Packet length: 16 bits. */
266 proto_tree_add_item(basic_hdr_tree
, hf_flip_basic_len
, flip_tvb
, offset
+ 6, 2, ENC_BIG_ENDIAN
);
269 offset
+= FLIP_BASIC_HDR_LEN
;
272 * Process faults found when parsing the basic header.
274 if (is_faulty_frame
== true) {
275 if (flip_len
> frame_len
) {
276 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
277 "Length mismatch: frame %d bytes, hdr %d bytes",
278 frame_len
, flip_len
);
280 else if (flip_len
< FLIP_BASIC_HDR_LEN
) {
281 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
282 "Invalid length in basic header: %d bytes", flip_len
);
285 goto DISSECT_FLIP_EXIT
;
289 * Now we know that the basic header is sensible.
291 payload_len
= basic_hdr_len
- FLIP_BASIC_HDR_LEN
;
294 * Dissect extension headers (if any).
296 if ((ext_hdr
== true) && (payload_len
< FLIP_EXTENSION_HDR_MIN_LEN
)) {
297 col_set_str(pinfo
->cinfo
, COL_INFO
,
298 "Extension header indicated, but not enough data");
299 goto DISSECT_FLIP_EXIT
;
302 while ((ext_hdr
== true) && (payload_len
>= FLIP_EXTENSION_HDR_MIN_LEN
)) {
303 /* Detect the next header type. */
304 uint8_t ext_hdr_type
;
306 uint16_t computed_chksum
;
308 tvbuff_t
*chksum_tvb
;
310 ext_hdr_type
= tvb_get_uint8(flip_tvb
, offset
);
312 switch (ext_hdr_type
) {
314 /* Calculate checksum, let the chksum dissector verify it. */
318 SET_CKSUM_VEC_TVB(vec
[0], flip_tvb
, 0, bytes_dissected
+ 2);
319 SET_CKSUM_VEC_TVB(vec
[1], flip_tvb
, bytes_dissected
+ 4,
320 flip_len
- (bytes_dissected
+ 4));
321 computed_chksum
= in_cksum(&vec
[0], 2);
323 /* Checksums handled in network order. */
324 computed_chksum
= g_htons(computed_chksum
);
327 chksum_tvb
= tvb_new_subset_length(flip_tvb
, offset
,
328 FLIP_CHKSUM_HDR_LEN
);
330 /* Note that flip_tree is NULL if no details are requested. */
331 bytes_handled
= dissect_flip_chksum_hdr(chksum_tvb
,
336 bytes_dissected
+= bytes_handled
;
337 payload_len
-= bytes_handled
;
338 offset
+= bytes_handled
;
342 /* Unknown header type. */
343 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
344 "Invalid extension header type 0x%02x", ext_hdr_type
);
345 goto DISSECT_FLIP_EXIT
;
351 * Show payload (if any) as bytes.
353 if (payload_len
> 0) {
355 tvbuff_t
*payload_tvb
;
358 payload_tvb
= tvb_new_subset_length(flip_tvb
, offset
, payload_len
);
360 data_len
= dissector_try_payload_with_data(subdissector_table
, payload_tvb
, pinfo
, tree
, true, NULL
);
363 data_len
= call_data_dissector(payload_tvb
, pinfo
, tree
);
366 bytes_dissected
+= data_len
;
368 } /* if (payload_len > 0) */
371 return bytes_dissected
;
373 } /* dissect_flip() */
376 /* Protocol initialization */
378 proto_register_flip(void)
380 static hf_register_info hf
[] = {
385 {"Extension Header Follows", "flip.basic.e", FT_BOOLEAN
, 32,
386 TFS(&tfs_yes_no
), 0x80000000, NULL
, HFILL
}
388 {&hf_flip_basic_reserved
,
389 {"Reserved", "flip.basic.reserved", FT_UINT32
, BASE_DEC
,
390 NULL
, 0x70000000, "Basic Header Reserved", HFILL
}
392 {&hf_flip_basic_flowid
,
393 {"FlowID", "flip.basic.flowid", FT_UINT32
, BASE_HEX
,
394 NULL
, 0x0FFFFFFF, "Basic Header Flow ID", HFILL
}
396 {&hf_flip_basic_seqnum
,
397 {"Seqnum", "flip.basic.seqnum", FT_UINT16
, BASE_DEC_HEX
,
398 NULL
, 0x0, "Basic Header Sequence Number", HFILL
}
401 {"Len", "flip.basic.len", FT_UINT16
, BASE_DEC_HEX
,
402 NULL
, 0x0, "Basic Header Packet Length", HFILL
}
407 {&hf_flip_chksum_etype
,
408 {"Extension Type", "flip.chksum.etype", FT_UINT32
, BASE_DEC
,
409 VALS(flip_etype
), 0xFF000000, "Checksum Header Extension Type", HFILL
}
411 {&hf_flip_chksum_spare
,
412 {"Spare", "flip.chksum.spare", FT_UINT32
, BASE_DEC_HEX
,
413 NULL
, 0x00FE0000, "Checksum Header Spare", HFILL
}
416 {"Extension Header Follows", "flip.chksum.e", FT_BOOLEAN
, 32,
417 TFS(&tfs_yes_no
), 0x00010000, NULL
, HFILL
}
419 {&hf_flip_chksum_chksum
,
420 {"Checksum", "flip.chksum.chksum", FT_UINT32
, BASE_HEX
,
421 NULL
, 0x0000FFFF, NULL
, HFILL
}
425 static int *ett
[] = {
432 module_t
*flip_module
;
434 proto_flip
= proto_register_protocol("NSN FLIP", "FLIP", "flip");
435 flip_handle
= register_dissector("flip", dissect_flip
, proto_flip
);
437 proto_register_field_array(proto_flip
, hf
, array_length(hf
));
438 proto_register_subtree_array(ett
, array_length(ett
));
440 flip_module
= prefs_register_protocol_obsolete(proto_flip
);
442 /* Register preferences - now obsolete because of Decode As*/
443 prefs_register_obsolete_preference(flip_module
, "decoding_mode");
444 prefs_register_obsolete_preference(flip_module
, "heur_enabled_protocols");
445 prefs_register_obsolete_preference(flip_module
, "heur_decode_rtp");
446 prefs_register_obsolete_preference(flip_module
, "heur_decode_rtcp");
447 prefs_register_obsolete_preference(flip_module
, "forced_protocol");
448 prefs_register_obsolete_preference(flip_module
, "forced_decode");
450 subdissector_table
= register_decode_as_next_proto(proto_flip
, "flip.payload", "FLIP payload", flip_prompt
);
452 } /* proto_register_flip() */
454 /* Protocol handoff */
456 proto_reg_handoff_flip(void)
458 dissector_add_uint("ethertype", ETHERTYPE_FLIP
, flip_handle
);
459 } /* proto_reg_handoff_flip() */
462 * Editor modelines - https://www.wireshark.org/tools/modelines.html
467 * indent-tabs-mode: nil
470 * vi: set shiftwidth=4 tabstop=8 expandtab:
471 * :indentSize=4:tabSize=8:noTabs=true: