epan/dissectors/pidl/ C99 drsuapi
[wireshark-sm.git] / epan / dissectors / packet-mac-nr-framed.c
blob8a91980b37241f0a11b3ed48961bc6befc545989
1 /* Routines for MAC NR format files with context info as header.
3 * Based on mac-lte-framed.c
5 * Martin Mathieson
6 * Pedro Alvarez
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
16 #include <epan/proto_data.h>
18 #include "config.h"
19 #include "packet-mac-nr.h"
21 void proto_register_mac_nr_framed(void);
23 /* Initialize the protocol and registered fields. */
24 static int proto_mac_nr_framed;
26 extern int proto_mac_nr;
28 /* Main dissection function. */
29 static int dissect_mac_nr_framed(tvbuff_t *tvb, packet_info *pinfo,
30 proto_tree *tree, void *data _U_) {
31 int offset = 0;
32 struct mac_nr_info *p_mac_nr_info;
33 tvbuff_t *mac_tvb;
34 bool infoAlreadySet = false;
36 /* Need to find enabled mac-nr dissector */
37 dissector_handle_t mac_nr_handle = find_dissector("mac-nr");
38 if (!mac_nr_handle) {
39 return 0;
42 /* Do this again on re-dissection to re-discover offset of actual PDU */
44 /* Needs to be at least as long as:
45 - fixed header bytes
46 - tag for data
47 - at least one byte of MAC PDU payload */
48 if ((size_t)tvb_reported_length_remaining(tvb, offset) < (3 + 2)) {
49 return 5;
52 /* If redissecting, use previous info struct (if available) */
53 p_mac_nr_info = (struct mac_nr_info *)p_get_proto_data(
54 wmem_file_scope(), pinfo, proto_mac_nr, 0);
55 if (p_mac_nr_info == NULL) {
56 /* Allocate new info struct for this frame */
57 p_mac_nr_info = wmem_new0(wmem_file_scope(), struct mac_nr_info);
58 } else {
59 infoAlreadySet = true;
62 /* Dissect the fields to populate p_mac_nr */
63 if (!dissect_mac_nr_context_fields(p_mac_nr_info, tvb, pinfo, tree,
64 &offset)) {
65 return offset;
68 /* Store info in packet (first time) */
69 if (!infoAlreadySet) {
70 p_add_proto_data(wmem_file_scope(), pinfo, proto_mac_nr, 0,
71 p_mac_nr_info);
74 /**************************************/
75 /* OK, now dissect as MAC NR */
77 /* Create tvb that starts at actual MAC PDU */
78 mac_tvb = tvb_new_subset_remaining(tvb, offset);
79 call_dissector_only(mac_nr_handle, mac_tvb, pinfo, tree, NULL);
80 return tvb_captured_length(tvb);
83 void proto_register_mac_nr_framed(void) {
84 /* Register protocol. */
85 proto_mac_nr_framed = proto_register_protocol(
86 "mac-nr-framed", "MAC-NR-FRAMED", "mac-nr-framed");
88 /* Allow other dissectors to find this one by name. */
89 register_dissector("mac-nr-framed", dissect_mac_nr_framed,
90 proto_mac_nr_framed);
94 * Editor modelines - https://www.wireshark.org/tools/modelines.html
96 * Local variables:
97 * c-basic-offset: 4
98 * tab-width: 8
99 * indent-tabs-mode: nil
100 * End:
102 * vi: set shiftwidth=4 tabstop=8 expandtab:
103 * :indentSize=4:tabSize=8:noTabs=true: