HTTPS (almost) everywhere.
[metze/wireshark/wip.git] / epan / dissectors / packet-gsm_abis_tfp.c
1 /* packet-gsm_abis_tfp.c
2  * Routines for packet dissection of Ericsson GSM A-bis TFP
3  * (Traffic Forwarding Protocol)
4  * Copyright 2010-2016 by Harald Welte <laforge@gnumonks.org>
5  *
6  * TFP is an Ericsson-specific packetized version of replacing TRAU
7  * frames on 8k/16k E1 sub-slots with a paketized frame format which
8  * can be transported over LAPD on a SuperChannel (E1 timeslot bundle)
9  * or L2TP.
10  *
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 1998 Gerald Combs
14  *
15  * SPDX-License-Identifier: GPL-2.0-or-later
16  */
17
18 #include "config.h"
19
20 #include <epan/packet.h>
21 #include <epan/prefs.h>
22
23 void proto_register_abis_tfp(void);
24 void proto_reg_handoff_abis_tfp(void);
25
26 enum {
27         SUB_DATA,
28
29         SUB_MAX
30 };
31
32 static dissector_handle_t sub_handles[SUB_MAX];
33
34 /* initialize the protocol and registered fields */
35 static int proto_abis_tfp = -1;
36
37 /* TFP header */
38 static int hf_tfp_hdr_atsr = -1;
39 static int hf_tfp_hdr_slot_rate = -1;
40 static int hf_tfp_hdr_seq_nr = -1;
41 static int hf_tfp_hdr_delay_info = -1;
42 static int hf_tfp_hdr_p = -1;
43 static int hf_tfp_hdr_s = -1;
44 static int hf_tfp_hdr_m = -1;
45 static int hf_tfp_hdr_frame_type = -1;
46 static int hf_tfp_amr_rate = -1;
47
48 /* initialize the subtree pointers */
49 static int ett_tfp = -1;
50
51 static const value_string tfp_slot_rate_vals[] = {
52         { 0,    "Full Rate (16kbps)" },
53         { 1,    "Sub-Channel 0 (8kbps)" },
54         { 2,    "Sub-Channel 1 (8kbps)" },
55         { 3,    "Reserved" },
56         { 0, NULL }
57 };
58
59 #define TFP_PACKED_NONE         0
60 #define TFP_PACKED_SCHEME_1     1
61
62 static const value_string tfp_packed_vals[] = {
63         { 0,    "Not Packed" },
64         { 1,    "Packing Scheme 1" },
65         { 0, NULL }
66 };
67
68 static const value_string tfp_frame_type_vals[] = {
69         /* 8k */
70         { 0,    "TFP-AMR-IND" },
71         { 1,    "TFP-SCCE-AMR-IND" },
72         { 2,    "TFP-HR-IND" },
73         /* 16k */
74         { 0x80, "TFP-AMR-IND" },
75         { 0x81, "TFP-SCCE-AMR-IND" },
76         { 0x82, "TFP-FR-IND" },
77         { 0x83, "TFP-EFR-IND" },
78         { 0x84, "TFP-SCCE-EFR-IND" },
79         { 0, NULL }
80 };
81
82 static const value_string tfp_amr_len_rate_vals[] = {
83         {  1, "SID_FIRST, ONSET, No speech/data" },
84         {  5, "SID_UPDATE, SID_BAD" },
85         { 12, "4.75k" },
86         { 13, "5.15k" },
87         { 15, "5.90k" },
88         { 17, "6.70k" },
89         { 19, "7.40k" },
90         { 20, "7.95k" },
91         { 26, "10.2k" },
92         { 31, "12.2k" },
93         { 0, NULL }
94 };
95
96 static int
97 dissect_abis_tfp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
98 {
99         proto_item *ti;
100         proto_tree *tfp_tree;
101         int offset = 0;
102         guint32 slot_rate, frame_bits, atsr, seq_nr;
103         guint8 ftype;
104         tvbuff_t *next_tvb;
105         gint len_remain;
106
107         col_set_str(pinfo->cinfo, COL_PROTOCOL, "TFP");
108
109         ti = proto_tree_add_item(tree, proto_abis_tfp, tvb, 0, -1, ENC_NA);
110         tfp_tree = proto_item_add_subtree(ti, ett_tfp);
111
112         proto_tree_add_item_ret_uint(tfp_tree, hf_tfp_hdr_atsr, tvb, offset, 2, ENC_BIG_ENDIAN, &atsr);
113         proto_tree_add_item_ret_uint(tfp_tree, hf_tfp_hdr_slot_rate, tvb, offset, 2, ENC_BIG_ENDIAN, &slot_rate);
114         proto_tree_add_item_ret_uint(tfp_tree, hf_tfp_hdr_seq_nr, tvb, offset, 2, ENC_BIG_ENDIAN, &seq_nr);
115         proto_tree_add_item(tfp_tree, hf_tfp_hdr_delay_info, tvb, offset+1, 2, ENC_BIG_ENDIAN);
116         proto_tree_add_item(tfp_tree, hf_tfp_hdr_p, tvb, offset+1, 2, ENC_BIG_ENDIAN);
117         proto_tree_add_item(tfp_tree, hf_tfp_hdr_s, tvb, offset+2, 1, ENC_NA);
118         proto_tree_add_item(tfp_tree, hf_tfp_hdr_m, tvb, offset+2, 1, ENC_NA);
119         /* Frame Type depends on Slot Rate */
120         ftype = tvb_get_guint8(tvb, offset+2) & 0x1E;
121         if (slot_rate == 0)
122                 ftype |= 0x80;
123         proto_tree_add_uint_format_value(tfp_tree, hf_tfp_hdr_frame_type, tvb, offset+2, 1, ftype, "%s",
124                                          val_to_str(ftype, tfp_frame_type_vals, "Unknown (%u)"));
125         offset += 2;
126
127         col_append_fstr(pinfo->cinfo, COL_INFO, "TS=%u, Seq=%u, %s, %s ", atsr, seq_nr,
128                         val_to_str(slot_rate, tfp_slot_rate_vals, "Unknown (%u)"),
129                         val_to_str(ftype, tfp_frame_type_vals, "Unknown (%u)"));
130
131         /* check for Tail bit == 1, iterate over further octests */
132         while ((tvb_get_guint8(tvb, offset) & 0x01) == 0)
133                 offset++;
134         offset++;
135
136         switch (ftype & 0x7F) {
137         case 0: /* TFP-AMR.ind */
138                 len_remain = tvb_captured_length_remaining(tvb, offset);
139                 proto_tree_add_uint(tfp_tree, hf_tfp_amr_rate, tvb, offset, 0, len_remain);
140                 break;
141         case 1: /* TFP-SCCE-AMR.ind */
142                 break;
143         case 2: /* TFP-HR.ind */
144                 break;
145         case 3: /* TFP-EFR.ind */
146                 break;
147         case 4: /* TFP-SCCE-EFR.ind */
148                 break;
149         }
150
151         /* FIXME: implement packed frame support */
152         if (slot_rate == 0)
153                 frame_bits = 320;
154         else
155                 frame_bits = 160;
156         next_tvb = tvb_new_subset_length(tvb, offset, frame_bits/8);
157         call_dissector(sub_handles[SUB_DATA], next_tvb, pinfo, tree);
158
159         return offset;
160 }
161
162 void
163 proto_register_abis_tfp(void)
164 {
165         static hf_register_info hf[] = {
166                 { &hf_tfp_hdr_atsr,
167                         { "Air Timeslot Resource", "gsm_abis_tfp.atsr",
168                           FT_UINT16, BASE_DEC, NULL, 0xe000,
169                           NULL, HFILL }
170                 },
171                 { &hf_tfp_hdr_slot_rate,
172                         { "Slot Rate", "gsm_abis_tfp.slot_rate",
173                           FT_UINT16, BASE_DEC, VALS(tfp_slot_rate_vals), 0x1800,
174                           NULL, HFILL }
175                 },
176                 { &hf_tfp_hdr_seq_nr,
177                         { "Sequence Number", "gsm_abis_tfp.seq_nr",
178                           FT_UINT16, BASE_DEC, NULL, 0x07c0,
179                           NULL, HFILL }
180                 },
181                 { &hf_tfp_hdr_delay_info,
182                         { "Delay Information (ms)", "gsm_abis_tfp.delay_info",
183                           FT_UINT16, BASE_DEC, NULL, 0x003e,
184                           NULL, HFILL }
185                 },
186                 { &hf_tfp_hdr_p,
187                         { "Packing Scheme", "gsm_abis_tfp.packing_scheme",
188                           FT_UINT16, BASE_DEC, VALS(tfp_packed_vals), 0x0180,
189                           NULL, HFILL }
190                 },
191                 { &hf_tfp_hdr_s,
192                         { "Silence Indicator", "gsm_abis_tfp.silence_ind",
193                           FT_BOOLEAN, 8, NULL, 0x40,
194                           NULL, HFILL }
195                 },
196                 { &hf_tfp_hdr_m,
197                         { "Marker bit", "gsm_abis_tfp.marker",
198                           FT_BOOLEAN, 8, NULL, 0x20,
199                           NULL, HFILL }
200                 },
201                 { &hf_tfp_hdr_frame_type,
202                         { "Frame Type", "gsm_abis_tfp.frame_type",
203                           FT_UINT8, BASE_DEC, VALS(tfp_frame_type_vals), 0x1e,
204                           NULL, HFILL }
205                 },
206                 { &hf_tfp_amr_rate,
207                         { "AMR Rate", "gsm_abis_tfp.amr.rate",
208                           FT_UINT8, BASE_DEC, VALS(tfp_amr_len_rate_vals), 0,
209                           NULL, HFILL }
210                 },
211         };
212         static gint *ett[] = {
213                 &ett_tfp,
214         };
215
216         /* assign our custom match functions */
217         proto_abis_tfp = proto_register_protocol("GSM A-bis TFP", "Ericsson GSM A-bis TFP",
218                                                  "gsm_abis_tfp");
219
220         proto_register_field_array(proto_abis_tfp, hf, array_length(hf));
221         proto_register_subtree_array(ett, array_length(ett));
222         register_dissector("gsm_abis_tfp", dissect_abis_tfp, proto_abis_tfp);
223 }
224
225 /* This function is called once at startup and every time the user hits
226  * 'apply' in the preferences dialogue */
227 void
228 proto_reg_handoff_abis_tfp(void)
229 {
230         sub_handles[SUB_DATA] = find_dissector("data");
231 }
232
233 /*
234  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
235  *
236  * Local variables:
237  * c-basic-offset: 8
238  * tab-width: 8
239  * indent-tabs-mode: t
240  * End:
241  *
242  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
243  * :indentSize=8:tabSize=8:noTabs=false:
244  */