/src/wireshark/epan/dissectors/packet-tdmoe.c
Line | Count | Source |
1 | | /* packet-tdmoe.c |
2 | | * Routines for TDM over Ethernet packet disassembly |
3 | | * Copyright 2010, Haakon Nessjoen <haakon.nessjoen@gmail.com> |
4 | | * |
5 | | * Wireshark - Network traffic analyzer |
6 | | * By Gerald Combs <gerald@wireshark.org> |
7 | | * Copyright 1998 Gerald Combs |
8 | | * |
9 | | * SPDX-License-Identifier: GPL-2.0-or-later |
10 | | */ |
11 | | |
12 | | #include "config.h" |
13 | | |
14 | | #include <epan/packet.h> |
15 | | #include <epan/etypes.h> |
16 | | #include <epan/prefs.h> |
17 | | |
18 | | /* Bitmasks for the flags in the fourth byte of the packet */ |
19 | 78 | #define TDMOE_YELLOW_ALARM_BITMASK 0x01 |
20 | 78 | #define TDMOE_SIGBITS_BITMASK 0x02 |
21 | | |
22 | | void proto_reg_handoff_tdmoe(void); |
23 | | void proto_register_tdmoe(void); |
24 | | |
25 | | static dissector_handle_t tdmoe_handle; |
26 | | |
27 | | /* protocols and header fields */ |
28 | | static int proto_tdmoe; |
29 | | |
30 | | static int hf_tdmoe_subaddress; |
31 | | static int hf_tdmoe_samples; |
32 | | static int hf_tdmoe_flags; |
33 | | static int hf_tdmoe_yellow_alarm; |
34 | | static int hf_tdmoe_sig_bits_present; |
35 | | static int hf_tdmoe_packet_counter; |
36 | | static int hf_tdmoe_channels; |
37 | | static int hf_tdmoe_sig_bits; |
38 | | |
39 | | static int ett_tdmoe; |
40 | | static int ett_tdmoe_flags; |
41 | | |
42 | | static dissector_handle_t lapd_handle; |
43 | | |
44 | | static unsigned pref_tdmoe_d_channel = 24; |
45 | | |
46 | | static int |
47 | | dissect_tdmoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) |
48 | 63 | { |
49 | 63 | proto_item *ti; |
50 | 63 | proto_tree *tdmoe_tree; |
51 | 63 | tvbuff_t *next_client; |
52 | 63 | uint16_t channels; |
53 | 63 | uint16_t subaddress; |
54 | 63 | int32_t offset = 0; |
55 | 63 | static int * const flags[] = { &hf_tdmoe_yellow_alarm, &hf_tdmoe_sig_bits_present, NULL }; |
56 | | |
57 | | /* Check that there's enough data */ |
58 | 63 | if (tvb_captured_length(tvb) < 8) |
59 | 1 | return 0; |
60 | | |
61 | 62 | subaddress = tvb_get_ntohs(tvb, 0); |
62 | 62 | channels = tvb_get_ntohs(tvb, 6); |
63 | | |
64 | 62 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "TDMoE"); |
65 | 62 | col_add_fstr(pinfo->cinfo, COL_INFO, "Subaddress: %d Channels: %d %s", |
66 | 62 | subaddress, |
67 | 62 | channels, |
68 | 62 | (tvb_get_uint8(tvb, 3) & TDMOE_YELLOW_ALARM_BITMASK ? "[YELLOW ALARM]" : "") |
69 | 62 | ); |
70 | | |
71 | | |
72 | | /* create display subtree for the protocol */ |
73 | 62 | ti = proto_tree_add_item(tree, proto_tdmoe, tvb, 0, -1, ENC_NA); |
74 | 62 | tdmoe_tree = proto_item_add_subtree(ti, ett_tdmoe); |
75 | | |
76 | | /* Subaddress */ |
77 | 62 | proto_tree_add_item(tdmoe_tree, hf_tdmoe_subaddress, tvb, offset, 2, ENC_BIG_ENDIAN); |
78 | 62 | offset+=2; |
79 | | |
80 | | /* Samples (1 byte) */ |
81 | 62 | proto_tree_add_item(tdmoe_tree, hf_tdmoe_samples, tvb, offset, 1, ENC_BIG_ENDIAN); |
82 | 62 | offset++; |
83 | | |
84 | | /* Yellow alarm & "Sig bits present" bits (1 byte) */ |
85 | 62 | proto_tree_add_bitmask(tdmoe_tree, tvb, offset, hf_tdmoe_flags, ett_tdmoe_flags, flags, ENC_BIG_ENDIAN); |
86 | 62 | offset++; |
87 | | |
88 | | /* Packet counter (2 bytes) */ |
89 | 62 | proto_tree_add_item(tdmoe_tree, hf_tdmoe_packet_counter, tvb, offset, 2, ENC_BIG_ENDIAN); |
90 | 62 | offset+=2; |
91 | | |
92 | | /* Number of channels in packet (2 bytes) */ |
93 | 62 | proto_tree_add_item(tdmoe_tree, hf_tdmoe_channels, tvb, offset, 2, ENC_BIG_ENDIAN); |
94 | 62 | offset+=2; |
95 | | |
96 | 62 | if (tvb_get_uint8(tvb, 3) & TDMOE_SIGBITS_BITMASK) { |
97 | | /* 4 sigbits per channel. Might be different on other sub-protocols? */ |
98 | 16 | uint16_t length = (channels >> 1) + ((channels & 0x01) ? 1 : 0); |
99 | | |
100 | 16 | proto_tree_add_item(tdmoe_tree, hf_tdmoe_sig_bits, tvb, offset, length, ENC_NA); |
101 | 16 | offset += length; |
102 | 16 | } |
103 | | |
104 | | /* The rest is SAMPLES * CHANNELS bytes of channel data */ |
105 | 1.74k | for (unsigned chan = 1; chan <= channels; chan++) { |
106 | 1.68k | next_client = tvb_new_subset_length(tvb, offset + ((chan - 1) * 8), 8); |
107 | 1.68k | if (chan == pref_tdmoe_d_channel) { |
108 | 46 | call_dissector(lapd_handle, next_client, pinfo, tree); |
109 | 1.63k | } else { |
110 | 1.63k | call_data_dissector(next_client, pinfo, tree); |
111 | 1.63k | } |
112 | 1.68k | } |
113 | 62 | return 1; |
114 | 63 | } |
115 | | |
116 | | void |
117 | | proto_register_tdmoe(void) |
118 | 16 | { |
119 | 16 | static hf_register_info hf[] = { |
120 | | |
121 | 16 | { &hf_tdmoe_subaddress, |
122 | 16 | { "Subaddress", "tdmoe.subaddress", FT_UINT16, BASE_DEC, NULL, 0x0, |
123 | 16 | NULL, HFILL }}, |
124 | 16 | { &hf_tdmoe_samples, |
125 | 16 | { "Samples", "tdmoe.samples", FT_UINT8, BASE_DEC, NULL, 0x0, |
126 | 16 | "Samples per channel", HFILL }}, |
127 | 16 | { &hf_tdmoe_flags, |
128 | 16 | { "Flags", "tdmoe.flags", FT_UINT8, BASE_HEX, NULL, 0x0, |
129 | 16 | NULL, HFILL }}, |
130 | 16 | { &hf_tdmoe_yellow_alarm, |
131 | 16 | { "Yellow Alarm", "tdmoe.yellowalarm", FT_BOOLEAN, 8, NULL, TDMOE_YELLOW_ALARM_BITMASK, |
132 | 16 | NULL, HFILL }}, |
133 | 16 | { &hf_tdmoe_sig_bits_present, |
134 | 16 | { "Sig bits present", "tdmoe.sig_bits_present", FT_BOOLEAN, 8, NULL, TDMOE_SIGBITS_BITMASK, |
135 | 16 | NULL, HFILL }}, |
136 | 16 | { &hf_tdmoe_packet_counter, |
137 | 16 | { "Counter", "tdmoe.counter", FT_UINT16, BASE_DEC, NULL, 0x0, |
138 | 16 | "Packet number", HFILL }}, |
139 | 16 | { &hf_tdmoe_channels, |
140 | 16 | { "Channels", "tdmoe.channels", FT_UINT16, BASE_DEC, NULL, 0x0, |
141 | 16 | NULL, HFILL }}, |
142 | 16 | { &hf_tdmoe_sig_bits, |
143 | 16 | { "Sig bits", "tdmoe.sig_bits", FT_BYTES, BASE_NONE, NULL, 0x0, |
144 | 16 | NULL, HFILL }}, |
145 | 16 | }; |
146 | 16 | static int *ett[] = { |
147 | 16 | &ett_tdmoe, |
148 | 16 | &ett_tdmoe_flags |
149 | 16 | }; |
150 | 16 | module_t *tdmoe_module; |
151 | | |
152 | 16 | proto_tdmoe = proto_register_protocol("Digium TDMoE Protocol", "TDMoE", "tdmoe"); |
153 | 16 | proto_register_field_array(proto_tdmoe, hf, array_length(hf)); |
154 | 16 | proto_register_subtree_array(ett, array_length(ett)); |
155 | 16 | tdmoe_handle = register_dissector("tdmoe", dissect_tdmoe, proto_tdmoe); |
156 | 16 | tdmoe_module = prefs_register_protocol(proto_tdmoe, NULL); |
157 | 16 | prefs_register_uint_preference(tdmoe_module, "d_channel", |
158 | 16 | "TDMoE D-Channel", |
159 | 16 | "The TDMoE channel that contains the D-Channel.", |
160 | 16 | 10, &pref_tdmoe_d_channel); |
161 | 16 | } |
162 | | |
163 | | void |
164 | | proto_reg_handoff_tdmoe(void) |
165 | 16 | { |
166 | 16 | dissector_add_uint("ethertype", ETHERTYPE_TDMOE, tdmoe_handle); |
167 | | |
168 | 16 | lapd_handle = find_dissector_add_dependency("lapd-bitstream", proto_tdmoe); |
169 | 16 | } |
170 | | |
171 | | /* |
172 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
173 | | * |
174 | | * Local variables: |
175 | | * c-basic-offset: 8 |
176 | | * tab-width: 8 |
177 | | * indent-tabs-mode: t |
178 | | * End: |
179 | | * |
180 | | * vi: set shiftwidth=8 tabstop=8 noexpandtab: |
181 | | * :indentSize=8:tabSize=8:noTabs=false: |
182 | | */ |