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