2 * Routines for TDM over Ethernet packet disassembly
3 * Copyright 2010, Haakon Nessjoen <haakon.nessjoen@gmail.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <epan/packet.h>
29 #include <epan/etypes.h>
30 #include <epan/prefs.h>
32 /* Bitmasks for the flags in the fourth byte of the packet */
33 #define TDMOE_YELLOW_ALARM_BITMASK 0x01
34 #define TDMOE_SIGBITS_BITMASK 0x02
36 void proto_reg_handoff_tdmoe(void);
37 void proto_register_tdmoe(void);
39 /* protocols and header fields */
40 static int proto_tdmoe = -1;
42 static int hf_tdmoe_subaddress = -1;
43 static int hf_tdmoe_samples = -1;
44 static int hf_tdmoe_flags = -1;
45 static int hf_tdmoe_yellow_alarm = -1;
46 static int hf_tdmoe_sig_bits_present = -1;
47 static int hf_tdmoe_packet_counter = -1;
48 static int hf_tdmoe_channels = -1;
49 static int hf_tdmoe_sig_bits = -1;
51 static gint ett_tdmoe = -1;
52 static gint ett_tdmoe_flags = -1;
54 static dissector_handle_t lapd_handle;
55 static dissector_handle_t data_handle;
57 static gint pref_tdmoe_d_channel = 24;
60 dissect_tdmoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
63 proto_tree *tdmoe_tree;
64 tvbuff_t *next_client;
68 static const gint *flags[] = { &hf_tdmoe_yellow_alarm, &hf_tdmoe_sig_bits_present, NULL };
71 /* Check that there's enough data */
72 if (tvb_length(tvb) < 8)
75 subaddress = tvb_get_ntohs(tvb, 0);
76 channels = tvb_get_ntohs(tvb, 6);
78 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TDMoE");
79 col_add_fstr(pinfo->cinfo, COL_INFO, "Subaddress: %d Channels: %d %s",
82 (tvb_get_guint8(tvb, 3) & TDMOE_YELLOW_ALARM_BITMASK ? "[YELLOW ALARM]" : "")
86 /* create display subtree for the protocol */
87 ti = proto_tree_add_item(tree, proto_tdmoe, tvb, 0, -1, ENC_NA);
88 tdmoe_tree = proto_item_add_subtree(ti, ett_tdmoe);
91 proto_tree_add_item(tdmoe_tree, hf_tdmoe_subaddress, tvb, offset, 2, ENC_BIG_ENDIAN);
94 /* Samples (1 byte) */
95 proto_tree_add_item(tdmoe_tree, hf_tdmoe_samples, tvb, offset, 1, ENC_NA);
98 /* Yellow alarm & "Sig bits present" bits (1 byte) */
99 proto_tree_add_bitmask(tdmoe_tree, tvb, offset, hf_tdmoe_flags, ett_tdmoe_flags, flags, ENC_BIG_ENDIAN);
102 /* Packet counter (2 bytes) */
103 proto_tree_add_item(tdmoe_tree, hf_tdmoe_packet_counter, tvb, offset, 2, ENC_BIG_ENDIAN);
106 /* Number of channels in packet (2 bytes) */
107 proto_tree_add_item(tdmoe_tree, hf_tdmoe_channels, tvb, offset, 2, ENC_BIG_ENDIAN);
110 if (tvb_get_guint8(tvb, 3) & TDMOE_SIGBITS_BITMASK) {
111 /* 4 sigbits per channel. Might be different on other sub-protocols? */
112 guint16 length = (channels >> 1) + ((channels & 0x01) ? 1 : 0);
114 proto_tree_add_item(tdmoe_tree, hf_tdmoe_sig_bits, tvb, offset, length, ENC_NA);
118 /* The rest is SAMPLES * CHANNELS bytes of channel data */
119 for (chan = 1; chan <= channels; chan++) {
120 next_client = tvb_new_subset_length(tvb, offset + ((chan - 1) * 8), 8);
121 if (chan == pref_tdmoe_d_channel) {
122 call_dissector(lapd_handle, next_client, pinfo, tree);
124 call_dissector(data_handle, next_client, pinfo, tree);
131 proto_register_tdmoe(void)
133 static hf_register_info hf[] = {
135 { &hf_tdmoe_subaddress,
136 { "Subaddress", "tdmoe.subaddress", FT_UINT8, BASE_DEC, NULL, 0x0,
139 { "Samples", "tdmoe.samples", FT_UINT8, BASE_DEC, NULL, 0x0,
140 "Samples per channel", HFILL }},
142 { "Flags", "tdmoe.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
144 { &hf_tdmoe_yellow_alarm,
145 { "Yellow Alarm", "tdmoe.yellowalarm", FT_BOOLEAN, 8, NULL, TDMOE_YELLOW_ALARM_BITMASK,
147 { &hf_tdmoe_sig_bits_present,
148 { "Sig bits present", "tdmoe.sig_bits_present", FT_BOOLEAN, 8, NULL, TDMOE_SIGBITS_BITMASK,
150 { &hf_tdmoe_packet_counter,
151 { "Counter", "tdmoe.counter", FT_UINT16, BASE_DEC, NULL, 0x0,
152 "Packet number", HFILL }},
153 { &hf_tdmoe_channels,
154 { "Channels", "tdmoe.channels", FT_UINT16, BASE_DEC, NULL, 0x0,
156 { &hf_tdmoe_sig_bits,
157 { "Sig bits", "tdmoe.sig_bits", FT_BYTES, BASE_NONE, NULL, 0x0,
160 static gint *ett[] = {
164 module_t *tdmoe_module;
166 proto_tdmoe = proto_register_protocol("Digium TDMoE Protocol", "TDMoE", "tdmoe");
167 proto_register_field_array(proto_tdmoe, hf, array_length(hf));
168 proto_register_subtree_array(ett, array_length(ett));
169 tdmoe_module = prefs_register_protocol(proto_tdmoe, proto_reg_handoff_tdmoe);
170 prefs_register_uint_preference(tdmoe_module, "d_channel",
172 "The TDMoE channel that contains the D-Channel.",
173 10, &pref_tdmoe_d_channel);
177 proto_reg_handoff_tdmoe(void)
179 dissector_handle_t tdmoe_handle;
181 tdmoe_handle = new_create_dissector_handle(dissect_tdmoe, proto_tdmoe);
182 dissector_add_uint("ethertype", ETHERTYPE_TDMOE, tdmoe_handle);
184 lapd_handle = find_dissector("lapd-bitstream");
185 data_handle = find_dissector("data");