2 * Routines for GSM Um packet disassembly
3 * Duncan Salerno <duncan.salerno@googlemail.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/packet.h>
34 #include <epan/prefs.h>
35 #include <epan/circuit.h>
37 static int proto_gsm_um = -1;
38 static int hf_gsm_um_direction = -1;
39 static int hf_gsm_um_channel = -1;
40 static int hf_gsm_um_bsic = -1;
41 static int hf_gsm_um_arfcn = -1;
42 static int hf_gsm_um_frame = -1;
43 static int hf_gsm_um_error = -1;
44 static int hf_gsm_um_timeshift = -1;
45 static int hf_gsm_um_l2_pseudo_len = -1;
47 static gint ett_gsm_um = -1;
49 static dissector_handle_t lapdm_handle;
50 static dissector_handle_t dtap_handle;
51 static dissector_handle_t data_handle;
53 static gboolean dcs1800_gsm = TRUE;
55 #define GSM_UM_L2_PSEUDO_LEN 0xfc
59 decode_arfcn(guint16 arfcn, const char **band, guint *uplink, guint *downlink)
61 /* Decode ARFCN to frequency using GSM 05.05 */
62 if( arfcn >= 1 && arfcn <= 124 ) {
64 *uplink = 890000 + 200 * arfcn;
65 *downlink = *uplink + 45000;
67 else if( arfcn == 0 ) {
69 *uplink = 890000 + 200 * arfcn;
70 *downlink = *uplink + 45000;
72 else if( arfcn >= 975 && arfcn <= 1023 ) {
74 *uplink = 890000 + 200 * (arfcn - 1024);
75 *downlink = *uplink + 45000;
77 else if( arfcn >= 955 && arfcn <= 1023 ) {
79 *uplink = 890000 + 200 * (arfcn - 1024);
80 *downlink = *uplink + 45000;
82 else if( arfcn >= 512 && arfcn <= 885 && dcs1800_gsm) {
84 *uplink = 1710200 + 200 * (arfcn - 512);
85 *downlink = *uplink + 95000;
87 else if( arfcn >= 512 && arfcn <= 810 && !dcs1800_gsm) {
89 *uplink = 1850200 + 200 * (arfcn - 512);
90 *downlink = *uplink + 80000;
92 else if( arfcn >= 259 && arfcn <= 293 ) {
94 *uplink = 450600 + 200 * (arfcn - 259);
95 *downlink = *uplink + 10000;
97 else if( arfcn >= 306 && arfcn <= 340 ) {
99 *uplink = 479000 + 200 * (arfcn - 306);
100 *downlink = *uplink + 10000;
102 else if( arfcn >= 128 && arfcn <= 251 ) {
104 *uplink = 824200 + 200 * (arfcn - 128);
105 *downlink = *uplink + 45000;
109 *uplink = *downlink = 0;
115 dissect_gsm_um(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
117 proto_tree *gsm_um_tree = NULL;
120 if (check_col(pinfo->cinfo, COL_PROTOCOL))
121 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GSM Um");
123 if (pinfo->pseudo_header->gsm_um.uplink) {
124 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
125 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "BTS");
126 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
127 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "MS");
130 switch (pinfo->pseudo_header->gsm_um.channel) {
131 case GSM_UM_CHANNEL_BCCH:
132 case GSM_UM_CHANNEL_CCCH:
133 case GSM_UM_CHANNEL_PCH:
134 case GSM_UM_CHANNEL_AGCH:
135 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
136 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "Broadcast");
139 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
140 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "MS");
143 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
144 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "BTS");
150 ti = proto_tree_add_item(tree, proto_gsm_um, tvb, 0, 0, FALSE);
151 gsm_um_tree = proto_item_add_subtree(ti, ett_gsm_um);
153 switch( pinfo->pseudo_header->gsm_um.channel ) {
154 case GSM_UM_CHANNEL_BCCH: channel = "BCCH"; break;
155 case GSM_UM_CHANNEL_CCCH: channel = "CCCH"; break;
156 case GSM_UM_CHANNEL_PCH: channel = "PCH"; break;
157 case GSM_UM_CHANNEL_AGCH: channel = "AGCH"; break;
158 case GSM_UM_CHANNEL_SACCH: channel = "SACCH"; break;
159 case GSM_UM_CHANNEL_FACCH: channel = "FACCH"; break;
160 case GSM_UM_CHANNEL_SDCCH: channel = "SDCCH"; break;
161 default: channel = "Unknown"; break;
164 if( pinfo->pseudo_header->gsm_um.uplink ) {
165 proto_tree_add_string(gsm_um_tree, hf_gsm_um_direction, tvb, 0, 0, "Uplink");
168 proto_tree_add_string(gsm_um_tree, hf_gsm_um_direction, tvb, 0, 0, "Downlink");
171 proto_tree_add_string(gsm_um_tree, hf_gsm_um_channel, tvb, 0, 0, channel);
173 /* Show the other fields, if we have them (ie. downlink, BTS->MS) */
174 if( !pinfo->pseudo_header->gsm_um.uplink ) {
176 guint downlink, uplink;
178 decode_arfcn(pinfo->pseudo_header->gsm_um.arfcn, &band, &uplink, &downlink);
180 proto_tree_add_uint(gsm_um_tree, hf_gsm_um_arfcn, tvb, 0, 0,
181 pinfo->pseudo_header->gsm_um.arfcn);
182 proto_tree_add_text(gsm_um_tree, tvb, 0, 0,
183 "Band: %s, Frequency: %u.%03uMHz", band,
184 downlink / 1000, downlink % 1000);
185 proto_tree_add_uint(gsm_um_tree, hf_gsm_um_bsic, tvb, 0, 0,
186 pinfo->pseudo_header->gsm_um.bsic);
187 proto_tree_add_uint(gsm_um_tree, hf_gsm_um_frame, tvb, 0, 0,
188 pinfo->pseudo_header->gsm_um.tdma_frame);
189 proto_tree_add_uint(gsm_um_tree, hf_gsm_um_error, tvb, 0, 0,
190 pinfo->pseudo_header->gsm_um.error);
191 proto_tree_add_uint(gsm_um_tree, hf_gsm_um_timeshift, tvb, 0, 0,
192 pinfo->pseudo_header->gsm_um.timeshift);
196 /* TODO: If CCCH downlink could work out of PCH or AGCH by peeking at next bytes, uplink is RACH */
198 switch( pinfo->pseudo_header->gsm_um.channel ) {
199 case GSM_UM_CHANNEL_BCCH:
200 case GSM_UM_CHANNEL_CCCH:
201 case GSM_UM_CHANNEL_PCH:
202 case GSM_UM_CHANNEL_AGCH:
203 if( !pinfo->pseudo_header->gsm_um.uplink ) {
205 guint8 pseudo_len, len_left, len_byte;
207 len_left = tvb_length(tvb);
208 len_byte = tvb_get_guint8(tvb, 0);
209 pseudo_len = len_byte >> 2;
210 next_tvb = tvb_new_subset(tvb, 1, MIN(len_left, pseudo_len), -1);
213 proto_tree_add_uint(gsm_um_tree, hf_gsm_um_l2_pseudo_len, tvb, 0, 1,
217 /* Only dissect non-empty frames */
218 if( tvb_length(next_tvb) ) {
219 call_dissector(dtap_handle, next_tvb, pinfo, tree);
223 /* Either RACH, or something invalid */
224 call_dissector(data_handle, tvb, pinfo, tree);
227 case GSM_UM_CHANNEL_SACCH:
228 case GSM_UM_CHANNEL_FACCH:
229 case GSM_UM_CHANNEL_SDCCH:
230 call_dissector(lapdm_handle, tvb, pinfo, tree);
233 call_dissector(data_handle, tvb, pinfo, tree);
239 proto_register_gsm_um(void)
241 static hf_register_info hf[] = {
242 { &hf_gsm_um_direction,
243 { "Direction", "gsm_um.direction", FT_STRINGZ, BASE_NONE,
244 NULL, 0x0, NULL, HFILL }},
246 { &hf_gsm_um_channel,
247 { "Channel", "gsm_um.channel", FT_STRINGZ, BASE_NONE,
248 NULL, 0x0, NULL, HFILL }},
251 { "BSIC", "gsm_um.bsic", FT_UINT8, BASE_DEC,
252 NULL, 0x0, "Base station identity code", HFILL }},
255 { "ARFCN", "gsm_um.arfcn", FT_UINT16, BASE_DEC,
256 NULL, 0x0, "Absolute radio frequency channel number", HFILL }},
259 { "TDMA Frame", "gsm_um.frame", FT_UINT32, BASE_DEC,
260 NULL, 0x0, NULL, HFILL }},
263 { "Error", "gsm_um.error", FT_UINT8, BASE_DEC,
264 NULL, 0x0, NULL, HFILL }},
266 { &hf_gsm_um_timeshift,
267 { "Timeshift", "gsm_um.timeshift", FT_UINT16, BASE_DEC,
268 NULL, 0x0, NULL, HFILL }},
270 { &hf_gsm_um_l2_pseudo_len,
271 { "L2 Pseudo Length", "gsm_um.l2_pseudo_len", FT_UINT8, BASE_DEC,
272 NULL, GSM_UM_L2_PSEUDO_LEN, NULL, HFILL }}
275 static gint *ett[] = {
278 module_t *gsm_um_module;
280 proto_gsm_um = proto_register_protocol("GSM Um Interface", "GSM Um", "gsm_um");
281 proto_register_field_array(proto_gsm_um, hf, array_length(hf));
282 proto_register_subtree_array(ett, array_length(ett));
284 gsm_um_module = prefs_register_protocol(proto_gsm_um, NULL);
285 prefs_register_bool_preference(gsm_um_module, "dcs1800",
286 "Treat ARFCN 512-810 as DCS 1800 rather than PCS 1900",
287 "Treat ARFCN 512-810 as DCS 1800 rather than PCS 1900",
293 proto_reg_handoff_gsm_um(void)
295 dissector_handle_t gsm_um_handle;
297 lapdm_handle = find_dissector("lapdm");
298 dtap_handle = find_dissector("gsm_a_dtap");
299 data_handle = find_dissector("data");
301 gsm_um_handle = create_dissector_handle(dissect_gsm_um, proto_gsm_um);
303 dissector_add("wtap_encap", WTAP_ENCAP_GSM_UM, gsm_um_handle);