From Duncan Salerno:
authorjake <jake@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 7 Jan 2009 07:21:31 +0000 (07:21 +0000)
committerjake <jake@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 7 Jan 2009 07:21:31 +0000 (07:21 +0000)
Added LAPDm protocol dissector, GSM Um layer, and wiretap support for dct3trace
captures, generated by gammu (many available at http://wiki.thc.org/gsm).

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@27176 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/Makefile.common
epan/dissectors/packet-frame.c
epan/dissectors/packet-gsm_a_dtap.c
epan/dissectors/packet-gsm_um.c [new file with mode: 0644]
epan/dissectors/packet-lapdm.c [new file with mode: 0644]
wiretap/Makefile.common
wiretap/dct3trace.c [new file with mode: 0644]
wiretap/dct3trace.h [new file with mode: 0644]
wiretap/file_access.c
wiretap/wtap.c
wiretap/wtap.h

index 2ddb2041cb4ad1579f00080958c0c9d8cecda6ef..fe683a294707288f1e649d4a2111d21eb1645a41 100644 (file)
@@ -455,6 +455,7 @@ DISSECTOR_SRC = \
        packet-gsm_bssmap_le.c  \
        packet-gsm_sms.c        \
        packet-gsm_sms_ud.c     \
+       packet-gsm_um.c \
        packet-gssapi.c         \
        packet-gtp.c            \
        packet-gvrp.c           \
@@ -557,6 +558,7 @@ DISSECTOR_SRC = \
        packet-lapb.c           \
        packet-lapbether.c      \
        packet-lapd.c           \
+       packet-lapdm.c          \
        packet-laplink.c        \
        packet-l1-events.c      \
        packet-ldp.c            \
index a8d09790f11fd5e48dfadb0d09fc80f02d1207a1..024d2391562ba8fd8bae765b4d02368b2cae09b6 100644 (file)
@@ -173,6 +173,11 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
                        pinfo->annex_a_used = pinfo->pseudo_header->mtp2.annex_a_used;
                        break;
 
+               case WTAP_ENCAP_GSM_UM:
+                       pinfo->p2p_dir = pinfo->pseudo_header->gsm_um.uplink ?
+                           P2P_DIR_SENT : P2P_DIR_RECV;
+                       break;
+
                }
        }
 
index 6f171471f405ded4abef592faca0b652146bf7b8..3ebbe4055e041e7af158f23e3dc598931cb971c1 100644 (file)
@@ -6019,6 +6019,8 @@ proto_reg_handoff_gsm_a_dtap(void)
        dissector_add("ranap.nas_pdu", BSSAP_PDU_TYPE_DTAP, dtap_handle);
        dissector_add("llcgprs.sapi", 1 , dtap_handle); /* GPRS Mobility Management */
        dissector_add("llcgprs.sapi", 7 , dtap_handle); /* SMS */
+       dissector_add("lapdm.sapi", 0 , dtap_handle); /* LAPDm: CC/RR/MM */
+       dissector_add("lapdm.sapi", 3 , dtap_handle); /* LAPDm: SMS/SS */
 
        data_handle = find_dissector("data");
        gsm_map_handle = find_dissector("gsm_map");
diff --git a/epan/dissectors/packet-gsm_um.c b/epan/dissectors/packet-gsm_um.c
new file mode 100644 (file)
index 0000000..1a758b5
--- /dev/null
@@ -0,0 +1,306 @@
+/* packet-gsm_um.c
+ * Routines for GSM Um packet disassembly
+ * Duncan Salerno <duncan.salerno@googlemail.com>
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <glib.h>
+#include <epan/packet.h>
+#include <epan/prefs.h>
+#include <epan/circuit.h>
+
+static int proto_gsm_um = -1;
+static int hf_gsm_um_direction = -1;
+static int hf_gsm_um_channel = -1;
+static int hf_gsm_um_bsic = -1;
+static int hf_gsm_um_arfcn = -1;
+static int hf_gsm_um_frame = -1;
+static int hf_gsm_um_error = -1;
+static int hf_gsm_um_timeshift = -1;
+static int hf_gsm_um_l2_pseudo_len = -1;
+
+static gint ett_gsm_um = -1;
+
+static dissector_handle_t lapdm_handle;
+static dissector_handle_t dtap_handle;
+static dissector_handle_t data_handle;
+
+static gboolean dcs1800_gsm = TRUE;
+
+#define        GSM_UM_L2_PSEUDO_LEN            0xfc
+
+
+static void
+decode_arfcn(guint16 arfcn, const char **band, guint *uplink, guint *downlink)
+{
+       /* Decode ARFCN to frequency using GSM 05.05 */
+       if( arfcn >= 1 && arfcn <= 124 ) {
+               *band = "P-GSM 900";
+               *uplink = 890000 + 200 * arfcn;
+               *downlink = *uplink + 45000;
+       }
+       else if( arfcn == 0 ) {
+               *band = "E-GSM 900";
+               *uplink = 890000 + 200 * arfcn;
+               *downlink = *uplink + 45000;
+       }
+       else if( arfcn >= 975 && arfcn <= 1023 ) {
+               *band = "E-GSM 900";
+               *uplink = 890000 + 200 * (arfcn - 1024);
+               *downlink = *uplink + 45000;
+       }
+       else if( arfcn >= 955 && arfcn <= 1023 ) {
+               *band = "R-GSM 900";
+               *uplink = 890000 + 200 * (arfcn - 1024);
+               *downlink = *uplink + 45000;
+       }
+       else if( arfcn >= 512 && arfcn <= 885 && dcs1800_gsm) {
+               *band = "DCS 1800";
+               *uplink = 1710200 + 200 * (arfcn - 512);
+               *downlink = *uplink + 95000;
+       }
+       else if( arfcn >= 512 && arfcn <= 810 && !dcs1800_gsm) {
+               *band = "PCS 1900";
+               *uplink = 1850200 + 200 * (arfcn - 512);
+               *downlink = *uplink + 80000;
+       }
+       else if( arfcn >= 259 && arfcn <= 293 ) {
+               *band = "GSM 450";
+               *uplink = 450600 + 200 * (arfcn - 259);
+               *downlink = *uplink + 10000;
+       }
+       else if( arfcn >= 306 && arfcn <= 340 ) {
+               *band = "GSM 480";
+               *uplink = 479000 + 200 * (arfcn - 306);
+               *downlink = *uplink + 10000;
+       }
+       else if( arfcn >= 128 && arfcn <= 251 ) {
+               *band = "GSM 850";
+               *uplink = 824200 + 200 * (arfcn - 128);
+               *downlink = *uplink + 45000;
+       }
+       else {
+               *band = "Unknown";
+               *uplink = *downlink = 0;
+       }
+}
+
+
+static void
+dissect_gsm_um(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+       proto_tree *gsm_um_tree = NULL;
+       proto_item *ti;
+
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "GSM Um");
+
+       if (pinfo->pseudo_header->gsm_um.uplink) {
+               if (check_col(pinfo->cinfo, COL_RES_DL_DST))
+                       col_set_str(pinfo->cinfo, COL_RES_DL_DST, "BTS");
+               if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
+                       col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "MS");
+       }
+       else {
+               switch (pinfo->pseudo_header->gsm_um.channel) {
+                       case GSM_UM_CHANNEL_BCCH:
+                       case GSM_UM_CHANNEL_CCCH:
+                       case GSM_UM_CHANNEL_PCH:
+                       case GSM_UM_CHANNEL_AGCH:
+                               if (check_col(pinfo->cinfo, COL_RES_DL_DST))
+                                   col_set_str(pinfo->cinfo, COL_RES_DL_DST, "Broadcast");
+                               break;
+                       default:
+                               if (check_col(pinfo->cinfo, COL_RES_DL_DST))
+                                   col_set_str(pinfo->cinfo, COL_RES_DL_DST, "MS");
+                               break;
+               }
+               if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
+                   col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "BTS");
+       }
+
+       if (tree) {
+               const char *channel;
+
+               ti = proto_tree_add_item(tree, proto_gsm_um, tvb, 0, 0, FALSE);
+               gsm_um_tree = proto_item_add_subtree(ti, ett_gsm_um);
+
+               switch( pinfo->pseudo_header->gsm_um.channel ) {
+                       case GSM_UM_CHANNEL_BCCH: channel = "BCCH"; break;
+                       case GSM_UM_CHANNEL_CCCH: channel = "CCCH"; break;
+                       case GSM_UM_CHANNEL_PCH: channel = "PCH"; break;
+                       case GSM_UM_CHANNEL_AGCH: channel = "AGCH"; break;
+                       case GSM_UM_CHANNEL_SACCH: channel = "SACCH"; break;
+                       case GSM_UM_CHANNEL_FACCH: channel = "FACCH"; break;
+                       case GSM_UM_CHANNEL_SDCCH: channel = "SDCCH"; break;
+                       default: channel = "Unknown"; break;
+               }
+
+               if( pinfo->pseudo_header->gsm_um.uplink ) {
+                       proto_tree_add_string(gsm_um_tree, hf_gsm_um_direction, tvb, 0, 0, "Uplink");
+               }
+               else {
+                       proto_tree_add_string(gsm_um_tree, hf_gsm_um_direction, tvb, 0, 0, "Downlink");
+               }
+
+               proto_tree_add_string(gsm_um_tree, hf_gsm_um_channel, tvb, 0, 0, channel);
+
+               /* Show the other fields, if we have them (ie. downlink, BTS->MS) */
+               if( !pinfo->pseudo_header->gsm_um.uplink ) {
+                       const char *band;
+                       guint downlink, uplink;
+
+                       decode_arfcn(pinfo->pseudo_header->gsm_um.arfcn, &band, &uplink, &downlink);
+
+                       proto_tree_add_uint(gsm_um_tree, hf_gsm_um_arfcn, tvb, 0, 0,
+                               pinfo->pseudo_header->gsm_um.arfcn);
+                       proto_tree_add_text(gsm_um_tree, tvb, 0, 0,
+                               "Band: %s, Frequency: %u.%03uMHz", band,
+                               downlink / 1000, downlink % 1000);
+                       proto_tree_add_uint(gsm_um_tree, hf_gsm_um_bsic, tvb, 0, 0,
+                               pinfo->pseudo_header->gsm_um.bsic);
+                       proto_tree_add_uint(gsm_um_tree, hf_gsm_um_frame, tvb, 0, 0,
+                               pinfo->pseudo_header->gsm_um.tdma_frame);
+                       proto_tree_add_uint(gsm_um_tree, hf_gsm_um_error, tvb, 0, 0,
+                               pinfo->pseudo_header->gsm_um.error);
+                       proto_tree_add_uint(gsm_um_tree, hf_gsm_um_timeshift, tvb, 0, 0,
+                               pinfo->pseudo_header->gsm_um.timeshift);
+               }
+       }
+
+       /* TODO: If CCCH downlink could work out of PCH or AGCH by peeking at next bytes, uplink is RACH */
+
+       switch( pinfo->pseudo_header->gsm_um.channel ) {
+               case GSM_UM_CHANNEL_BCCH:
+               case GSM_UM_CHANNEL_CCCH:
+               case GSM_UM_CHANNEL_PCH:
+               case GSM_UM_CHANNEL_AGCH:
+                       if( !pinfo->pseudo_header->gsm_um.uplink ) {
+                               tvbuff_t *next_tvb;
+                               guint8 pseudo_len, len_left, len_byte;
+
+                               len_left = tvb_length(tvb);
+                               len_byte = tvb_get_guint8(tvb, 0);
+                               pseudo_len = len_byte >> 2;
+                               next_tvb = tvb_new_subset(tvb, 1, MIN(len_left, pseudo_len), -1);
+
+                               if (tree) {
+                                       proto_tree_add_uint(gsm_um_tree, hf_gsm_um_l2_pseudo_len, tvb, 0, 1,
+                                               len_byte);
+                               }
+
+                               /* Only dissect non-empty frames */
+                               if( tvb_length(next_tvb) ) {
+                                       call_dissector(dtap_handle, next_tvb, pinfo, tree);
+                               }
+                       }
+                       else {
+                               /* Either RACH, or something invalid */
+                               call_dissector(data_handle, tvb, pinfo, tree);
+                       }
+                       break;
+               case GSM_UM_CHANNEL_SACCH:
+               case GSM_UM_CHANNEL_FACCH:
+               case GSM_UM_CHANNEL_SDCCH:
+                       call_dissector(lapdm_handle, tvb, pinfo, tree);
+                       break;
+               default:
+                       call_dissector(data_handle, tvb, pinfo, tree);
+                       break;
+       }
+}
+
+
+void
+proto_reg_handoff_gsm_um(void)
+{
+       dissector_handle_t gsm_um_handle;
+
+       lapdm_handle = find_dissector("lapdm");
+       dtap_handle = find_dissector("gsm_a_dtap");
+       data_handle = find_dissector("data");
+
+       gsm_um_handle = create_dissector_handle(dissect_gsm_um, proto_gsm_um);
+
+       dissector_add("wtap_encap", WTAP_ENCAP_GSM_UM, gsm_um_handle);
+}
+
+
+void
+proto_register_gsm_um(void)
+{
+       static hf_register_info hf[] = {
+               { &hf_gsm_um_direction,
+               { "Direction",  "gsm_um.direction", FT_STRINGZ, BASE_NONE,
+                 NULL, 0x0, NULL, HFILL }},
+
+               { &hf_gsm_um_channel,
+               { "Channel",    "gsm_um.channel", FT_STRINGZ, BASE_NONE,
+                 NULL, 0x0, NULL, HFILL }},
+
+               { &hf_gsm_um_bsic,
+               { "BSIC",       "gsm_um.bsic", FT_UINT8, BASE_DEC,
+                 NULL, 0x0, "Base station identity code", HFILL }},
+
+               { &hf_gsm_um_arfcn,
+               { "ARFCN",      "gsm_um.arfcn", FT_UINT16, BASE_DEC,
+                 NULL, 0x0, "Absolute radio frequency channel number", HFILL }},
+
+               { &hf_gsm_um_frame,
+               { "TDMA Frame", "gsm_um.frame", FT_UINT32, BASE_DEC,
+                 NULL, 0x0, NULL, HFILL }},
+
+               { &hf_gsm_um_error,
+               { "Error",      "gsm_um.error", FT_UINT8, BASE_DEC,
+                 NULL, 0x0, NULL, HFILL }},
+
+               { &hf_gsm_um_timeshift,
+               { "Timeshift",  "gsm_um.timeshift", FT_UINT16, BASE_DEC,
+                 NULL, 0x0, NULL, HFILL }},
+
+               { &hf_gsm_um_l2_pseudo_len,
+               { "L2 Pseudo Length",   "gsm_um.l2_pseudo_len", FT_UINT8, BASE_DEC,
+                 NULL, GSM_UM_L2_PSEUDO_LEN, NULL, HFILL }}
+
+       };
+       static gint *ett[] = {
+               &ett_gsm_um
+       };
+       module_t *gsm_um_module;
+
+       proto_gsm_um = proto_register_protocol("GSM Um Interface", "GSM Um", "gsm_um");
+       proto_register_field_array(proto_gsm_um, hf, array_length(hf));
+       proto_register_subtree_array(ett, array_length(ett));
+
+       gsm_um_module = prefs_register_protocol(proto_gsm_um, proto_reg_handoff_gsm_um);
+       prefs_register_bool_preference(gsm_um_module, "dcs1800",
+                                  "Treat ARFCN 512-810 as DCS 1800 rather than PCS 1900",
+                                  "Treat ARFCN 512-810 as DCS 1800 rather than PCS 1900",
+                                  &dcs1800_gsm);
+
+}
diff --git a/epan/dissectors/packet-lapdm.c b/epan/dissectors/packet-lapdm.c
new file mode 100644 (file)
index 0000000..0b7b86b
--- /dev/null
@@ -0,0 +1,492 @@
+/* packet-lapdm.c
+ * Routines for LAPDm frame disassembly
+ * Duncan Salerno <duncan.salerno@googlemail.com>
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/* LAPDm references:
+ *
+ * Mobile Station - Base Stations System (MS - BSS) Interface Data Link (DL) Layer Specification
+ * Base Station Controller - Base Transceiver Station (BSC - BTS) interface; Layer 2 specification
+ * http://www.3gpp.org/ftp/Specs/html-info/44006.htm
+ *
+ * From 3GPP TS 44.006:
+ *
+ * LAPDm is used for information sent on the control channels BCCH, AGCH, NCH,
+ * PCH, FACCH, SACCH and SDCCH as defined in 3GPP TS 44.003.
+ *
+ * AGCH, NCH and PCH are sometimes referred to by the collective name CCCH.
+ * FACCH, SACCH and SDCCH are, similarly, referred to by the collective name DCCH.
+ *
+ * Format A is used on DCCHs for frames where there is no information field.
+ * Formats B, Bter and B4 are used on DCCHs for frames containing an information field:
+ * Format Bter is used on request of higher layers if and only if short L2 header type 1 is
+ * supported and a UI command is to be transmitted on SAPI 0;
+ * Format B4 is used for UI frames transmitted by the network on SACCH;
+ * Format B is applied in all other cases.
+ * Format Bbis is used only on BCCH, PCH, NCH, and AGCH.
+ * In addition there is a Format C for transmission of random access signals.
+ *
+ * This module currently supports A, B, B4
+ * In the future will support Bter
+ * Bbis and C should be supported elsewhere
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <glib.h>
+#include <string.h>
+#include <epan/packet.h>
+#include <epan/prefs.h>
+#include <epan/xdlc.h>
+#include <epan/reassemble.h>
+
+static int proto_lapdm = -1;
+static int hf_lapdm_address = -1;
+static int hf_lapdm_ea = -1;
+static int hf_lapdm_cr = -1;
+static int hf_lapdm_sapi = -1;
+static int hf_lapdm_lpd = -1;
+
+static int hf_lapdm_control = -1;
+static int hf_lapdm_n_r = -1;
+static int hf_lapdm_n_s = -1;
+static int hf_lapdm_p = -1;
+static int hf_lapdm_f = -1;
+static int hf_lapdm_s_ftype = -1;
+static int hf_lapdm_u_modifier_cmd = -1;
+static int hf_lapdm_u_modifier_resp = -1;
+static int hf_lapdm_ftype_i = -1;
+static int hf_lapdm_ftype_s_u = -1;
+
+static int hf_lapdm_length = -1;
+static int hf_lapdm_el = -1;
+static int hf_lapdm_m = -1;
+static int hf_lapdm_len = -1;
+
+/*
+ * LAPDm fragment handling
+ */
+static int hf_lapdm_fragments = -1;
+static int hf_lapdm_fragment = -1;
+static int hf_lapdm_fragment_overlap = -1;
+static int hf_lapdm_fragment_overlap_conflicts = -1;
+static int hf_lapdm_fragment_multiple_tails = -1;
+static int hf_lapdm_fragment_too_long_fragment = -1;
+static int hf_lapdm_fragment_error = -1;
+static int hf_lapdm_reassembled_in = -1;
+
+static gint ett_lapdm = -1;
+static gint ett_lapdm_address = -1;
+static gint ett_lapdm_control = -1;
+static gint ett_lapdm_length = -1;
+static gint ett_lapdm_fragment = -1;
+static gint ett_lapdm_fragments = -1;
+
+static GHashTable *lapdm_fragment_table = NULL;
+static GHashTable *lapdm_reassembled_table = NULL;
+
+static dissector_table_t lapdm_sapi_dissector_table;
+
+static dissector_handle_t data_handle;
+
+static gboolean reassemble_lapdm = TRUE;
+
+/*
+ * Bits in the address field.
+ */
+#define        LAPDM_SAPI              0x1c    /* Service Access Point Identifier */
+#define        LAPDM_SAPI_SHIFT        2
+#define        LAPDM_CR                0x02    /* Command/Response bit */
+#define        LAPDM_EA                0x01    /* First Address Extension bit */
+#define        LAPDM_LPD               0x60    /* Link Protocol Discriminator */
+
+/*
+ * Bits in the length field.
+ */
+#define        LAPDM_EL                0x01    /* Extended Length = 1 */
+#define        LAPDM_M                 0x02    /* More fragments */
+#define        LAPDM_M_SHIFT           1
+#define        LAPDM_LEN               0xfc    /* Length */
+#define        LAPDM_LEN_SHIFT         2
+
+#define LAPDM_HEADER_LEN 3
+
+#define LAPDM_SAPI_RR_CC_MM    0
+#define LAPDM_SAPI_SMS         3
+
+/* Used only for U frames */
+static const xdlc_cf_items lapdm_cf_items = {
+    &hf_lapdm_n_r,
+    &hf_lapdm_n_s,
+    &hf_lapdm_p,
+    &hf_lapdm_f,
+    &hf_lapdm_s_ftype,
+    &hf_lapdm_u_modifier_cmd,
+    &hf_lapdm_u_modifier_resp,
+    &hf_lapdm_ftype_i,
+    &hf_lapdm_ftype_s_u
+};
+
+static const value_string lapdm_ea_vals[] = {
+    { 0,               "More octets" },
+    { 1,               "Final octet" },
+    { 0,               NULL }
+};
+
+static const value_string lapdm_sapi_vals[] = {
+    { LAPDM_SAPI_RR_CC_MM,     "RR/MM/CC" },
+    { LAPDM_SAPI_SMS,          "SMS/SS" },
+    { 0,                       NULL }
+};
+
+static const value_string lapdm_lpd_vals[] = {
+    { 0,               "Normal GSM" },
+    { 1,               "Cell broadcast service" },
+    { 0,               NULL }
+};
+
+static const value_string lapdm_m_vals[] = {
+    { 0,               "Last segment" },
+    { 1,               "More segments" },
+    { 0,               NULL }
+};
+
+static const value_string lapdm_el_vals[] = {
+    { 0,               "More octets" },
+    { 1,               "Final octet" },
+    { 0,               NULL }
+};
+
+
+static const fragment_items lapdm_frag_items = {
+    /* Fragment subtrees */
+    &ett_lapdm_fragment,
+    &ett_lapdm_fragments,
+    /* Fragment fields */
+    &hf_lapdm_fragments,
+    &hf_lapdm_fragment,
+    &hf_lapdm_fragment_overlap,
+    &hf_lapdm_fragment_overlap_conflicts,
+    &hf_lapdm_fragment_multiple_tails,
+    &hf_lapdm_fragment_too_long_fragment,
+    &hf_lapdm_fragment_error,
+    /* Reassembled in field */
+    &hf_lapdm_reassembled_in,
+    /* Tag */
+    "fragments"
+};
+
+static void
+lapdm_defragment_init (void)
+{
+    fragment_table_init (&lapdm_fragment_table);
+    reassembled_table_init(&lapdm_reassembled_table);
+}
+
+
+static void
+dissect_lapdm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+    proto_tree *lapdm_tree, *addr_tree, *length_tree;
+    proto_item *lapdm_ti, *addr_ti, *length_ti;
+    guint8 address, length, cr, sapi, len, n_s;
+    int control;
+    gboolean m;
+    tvbuff_t *payload;
+    int available_length;
+    gboolean is_response = FALSE;
+
+    /* Check that there's enough data */
+    if (tvb_length(tvb) < LAPDM_HEADER_LEN)
+        return;
+
+    if (check_col(pinfo->cinfo, COL_PROTOCOL))
+        col_set_str(pinfo->cinfo, COL_PROTOCOL, "LAPDm");
+
+    address = tvb_get_guint8(tvb, 0);
+    length = tvb_get_guint8(tvb, 2);
+
+    cr = address & LAPDM_CR;
+    if (pinfo->p2p_dir == P2P_DIR_RECV) {
+        is_response = cr ? FALSE : TRUE;
+    }
+    else if (pinfo->p2p_dir == P2P_DIR_SENT) {
+        is_response = cr ? TRUE : FALSE;
+    }
+
+    if (tree) {
+        lapdm_ti = proto_tree_add_item(tree, proto_lapdm, tvb, 0, LAPDM_HEADER_LEN, FALSE);
+        lapdm_tree = proto_item_add_subtree(lapdm_ti, ett_lapdm);
+
+        addr_ti = proto_tree_add_uint(lapdm_tree, hf_lapdm_address, tvb, 0, 1, address);
+        addr_tree = proto_item_add_subtree(addr_ti, ett_lapdm_address);
+
+        proto_tree_add_uint(addr_tree, hf_lapdm_lpd, tvb, 0, 1, address);
+        proto_tree_add_uint(addr_tree, hf_lapdm_sapi, tvb, 0, 1, address);
+        proto_tree_add_uint(addr_tree, hf_lapdm_cr, tvb, 0, 1, address);
+        proto_tree_add_uint(addr_tree, hf_lapdm_ea, tvb, 0, 1, address);
+    }
+    else {
+        lapdm_ti = NULL;
+        lapdm_tree = NULL;
+    }
+
+    control = dissect_xdlc_control(tvb, 1, pinfo, lapdm_tree, hf_lapdm_control,
+              ett_lapdm_control, &lapdm_cf_items, NULL /* LAPDm doesnt support extended */, NULL, NULL,
+              is_response, FALSE, FALSE);
+
+    if (tree) {
+        length_ti = proto_tree_add_uint(lapdm_tree, hf_lapdm_length, tvb,
+                    2, 1, length);
+        length_tree = proto_item_add_subtree(length_ti, ett_lapdm_length);
+
+        proto_tree_add_uint(length_tree, hf_lapdm_len, tvb, 2, 1, length);
+        proto_tree_add_uint(length_tree, hf_lapdm_m, tvb, 2, 1, length);
+        proto_tree_add_uint(length_tree, hf_lapdm_el, tvb, 2, 1, length);
+    }
+
+    sapi = (address & LAPDM_SAPI) >> LAPDM_SAPI_SHIFT;
+    len = (length & LAPDM_LEN) >> LAPDM_LEN_SHIFT;
+    n_s = (control & XDLC_N_S_MASK) >> XDLC_N_S_SHIFT;
+    m = (length & LAPDM_M) >> LAPDM_M_SHIFT;
+    available_length = tvb_length(tvb) - LAPDM_HEADER_LEN;
+
+    /* No point in doing anything if no payload
+     */
+    if( !MIN(len, available_length) )
+        return;
+
+    payload = tvb_new_subset(tvb, LAPDM_HEADER_LEN, MIN(len,available_length), -1);
+
+    /* Potentially segmented I frame
+     */
+    if( (control & XDLC_I_MASK) == XDLC_I && reassemble_lapdm )
+    {
+            fragment_data *fd_m = NULL;
+            tvbuff_t *reassembled = NULL;
+            gboolean save_fragmented = pinfo->fragmented;
+
+            pinfo->fragmented = m;
+            /* This doesn't seem the best way of doing it as doesn't
+               take N(S) into account, but N(S) isn't always 0 for
+               the first fragment!
+             */
+            fd_m = fragment_add_seq_next (payload, 0, pinfo,
+                                0, /* guint32 ID for fragments belonging together */
+                                lapdm_fragment_table, /* list of message fragments */
+                                lapdm_reassembled_table, /* list of reassembled messages */
+                                /*n_s guint32 fragment sequence number */
+                                len, /* guint32 fragment length */
+                                m); /* More fragments? */
+
+            reassembled = process_reassembled_data(payload, 0, pinfo,
+                    "Reassembled Message", fd_m, &lapdm_frag_items,
+                    NULL, lapdm_tree);
+
+            /* Reassembled into this packet
+             */
+            if (fd_m && pinfo->fd->num == fd_m->reassembled_in) {
+                    if (!dissector_try_port(lapdm_sapi_dissector_table, sapi,
+                                reassembled, pinfo, tree))
+                        call_dissector(data_handle, reassembled, pinfo, tree);
+            }
+            else {
+                if (check_col(pinfo->cinfo, COL_INFO)) {
+                    col_append_str(pinfo->cinfo, COL_INFO, " (Fragment)");
+                }
+                if (tree) {
+                    proto_tree_add_text(lapdm_tree, payload, 0, -1, "Fragment Data");
+                }
+            }
+
+            /* Now reset fragmentation information in pinfo 
+             */
+            pinfo->fragmented = save_fragmented;
+    }
+    else
+    {
+        /* Whole packet
+           If we have some data, try and dissect it (only happens for UI, SABM, UA or I frames)
+         */
+        if (!dissector_try_port(lapdm_sapi_dissector_table, sapi,
+                payload, pinfo, tree))
+            call_dissector(data_handle,payload, pinfo, tree);
+    }
+}
+
+void
+proto_reg_handoff_lapdm(void)
+{
+    dissector_handle_t lapdm_handle;
+
+    data_handle = find_dissector("data");
+
+    lapdm_handle = create_dissector_handle(dissect_lapdm, proto_lapdm);
+}
+
+void
+proto_register_lapdm(void)
+{
+    static hf_register_info hf[] = {
+
+        { &hf_lapdm_address,
+        { "Address Field", "lapdm.address_field", FT_UINT8, BASE_HEX, NULL, 0x0,
+        "Address", HFILL }},
+
+        { &hf_lapdm_ea,
+        { "EA", "lapdm.ea", FT_UINT8, BASE_DEC, VALS(lapdm_ea_vals), LAPDM_EA,
+        "Address field extension bit", HFILL }},
+
+        { &hf_lapdm_cr,
+        { "C/R", "lapdm.cr", FT_UINT8, BASE_DEC, NULL, LAPDM_CR,
+        "Command/response field bit", HFILL }},
+
+        { &hf_lapdm_lpd,
+        { "LPD", "lapdm.lpd", FT_UINT8, BASE_DEC, VALS(lapdm_lpd_vals), LAPDM_LPD,
+        "Link Protocol Discriminator", HFILL }},
+
+        { &hf_lapdm_sapi,
+        { "SAPI", "lapdm.sapi", FT_UINT8, BASE_DEC, VALS(lapdm_sapi_vals), LAPDM_SAPI,
+        "Service access point identifier", HFILL }},
+
+        { &hf_lapdm_control,
+        { "Control Field", "lapdm.control_field", FT_UINT8, BASE_HEX, NULL, 0x0,
+        "Control field", HFILL }},
+
+        { &hf_lapdm_n_r,
+        { "N(R)", "lapdm.control.n_r", FT_UINT8, BASE_DEC,
+        NULL, XDLC_N_R_MASK, NULL, HFILL }},
+
+        { &hf_lapdm_n_s,
+        { "N(S)", "lapdm.control.n_s", FT_UINT8, BASE_DEC,
+        NULL, XDLC_N_S_MASK, NULL, HFILL }},
+
+        { &hf_lapdm_p,
+        { "Poll", "lapdm.control.p", FT_BOOLEAN, 8,
+        TFS(&tfs_true_false), XDLC_P_F, NULL, HFILL }},
+
+        { &hf_lapdm_f,
+        { "Final", "lapdm.control.f", FT_BOOLEAN, 8,
+        TFS(&tfs_true_false), XDLC_P_F, NULL, HFILL }},
+
+        { &hf_lapdm_s_ftype,
+        { "Supervisory frame type", "lapdm.control.s_ftype", FT_UINT8, BASE_HEX,
+        VALS(stype_vals), XDLC_S_FTYPE_MASK, NULL, HFILL }},
+
+        { &hf_lapdm_u_modifier_cmd,
+        { "Command", "lapdm.control.u_modifier_cmd", FT_UINT8, BASE_HEX,
+        VALS(modifier_vals_cmd), XDLC_U_MODIFIER_MASK, NULL, HFILL }},
+
+        { &hf_lapdm_u_modifier_resp,
+        { "Response", "lapdm.control.u_modifier_resp", FT_UINT8, BASE_HEX,
+        VALS(modifier_vals_resp), XDLC_U_MODIFIER_MASK, NULL, HFILL }},
+
+        { &hf_lapdm_ftype_i,
+        { "Frame type", "lapdm.control.ftype", FT_UINT8, BASE_HEX,
+        VALS(ftype_vals), XDLC_I_MASK, NULL, HFILL }},
+
+        { &hf_lapdm_ftype_s_u,
+        { "Frame type", "lapdm.control.ftype", FT_UINT8, BASE_HEX,
+        VALS(ftype_vals), XDLC_S_U_MASK, NULL, HFILL }},
+
+        { &hf_lapdm_length,
+        { "Length Field", "lapdm.length_field", FT_UINT8, BASE_HEX,
+        NULL, 0x0, "Length field", HFILL }},
+
+        { &hf_lapdm_el,
+        { "EL", "lapdm.el", FT_UINT8, BASE_DEC,
+        VALS(lapdm_el_vals), LAPDM_EL, "Length indicator field extension bit", HFILL }},
+
+        { &hf_lapdm_m,
+        { "M", "lapdm.m", FT_UINT8, BASE_DEC,
+        VALS(lapdm_m_vals), LAPDM_M, "More data bit", HFILL }},
+
+        { &hf_lapdm_len,
+        { "Length", "lapdm.length", FT_UINT8, BASE_DEC,
+        NULL, LAPDM_LEN, "Length indicator", HFILL }},
+
+       /* Fragment reassembly
+        */
+        { &hf_lapdm_fragments,
+        { "Message fragments", "lapdm.fragments", FT_NONE, BASE_NONE,
+        NULL, 0x00, "LAPDm Message fragments", HFILL }},
+
+        { &hf_lapdm_fragment,
+        { "Message fragment", "lapdm.fragment", FT_FRAMENUM, BASE_NONE,
+        NULL, 0x00, "LAPDm Message fragment", HFILL }},
+
+        { &hf_lapdm_fragment_overlap,
+        { "Message fragment overlap", "lapdm.fragment.overlap", FT_BOOLEAN, BASE_NONE,
+        NULL, 0x00, "LAPDm Message fragment overlaps with other fragment(s)", HFILL }},
+
+        { &hf_lapdm_fragment_overlap_conflicts,
+        { "Message fragment overlapping with conflicting data", "lapdm.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE,
+        NULL, 0x00, "LAPDm Message fragment overlaps with conflicting data", HFILL }},
+
+        { &hf_lapdm_fragment_multiple_tails,
+        { "Message has multiple tail fragments", "lapdm.fragment.multiple_tails", FT_BOOLEAN, BASE_NONE,
+        NULL, 0x00, "LAPDm Message fragment has multiple tail fragments", HFILL }},
+
+        { &hf_lapdm_fragment_too_long_fragment,
+        { "Message fragment too long", "lapdm.fragment.too_long_fragment", FT_BOOLEAN, BASE_NONE,
+        NULL, 0x00, "LAPDm Message fragment data goes beyond the packet end", HFILL }},
+
+        { &hf_lapdm_fragment_error,
+        { "Message defragmentation error", "lapdm.fragment.error", FT_FRAMENUM, BASE_NONE,
+        NULL, 0x00, "LAPDm Message defragmentation error due to illegal fragments", HFILL }},
+
+        { &hf_lapdm_reassembled_in,
+        { "Reassembled in", "lapdm.reassembled.in", FT_FRAMENUM, BASE_NONE,
+        NULL, 0x00, "LAPDm Message has been reassembled in this packet.", HFILL }}
+
+    };
+    static gint *ett[] = {
+        &ett_lapdm,
+        &ett_lapdm_address,
+        &ett_lapdm_control,
+        &ett_lapdm_length,
+        &ett_lapdm_fragment,
+        &ett_lapdm_fragments
+    };
+
+    module_t *lapdm_module;
+
+    proto_lapdm = proto_register_protocol("Link Access Procedure, Channel Dm (LAPDm)", "LAPDm", "lapdm");
+    proto_register_field_array (proto_lapdm, hf, array_length(hf));
+    proto_register_subtree_array(ett, array_length(ett));
+
+    register_dissector("lapdm", dissect_lapdm, proto_lapdm);
+
+    lapdm_sapi_dissector_table = register_dissector_table("lapdm.sapi", "LAPDm SAPI", FT_UINT8, BASE_DEC);
+
+    lapdm_module = prefs_register_protocol(proto_lapdm, proto_reg_handoff_lapdm);
+    prefs_register_bool_preference(lapdm_module, "reassemble",
+        "Reassemble fragmented LAPDm packets",
+        "Whether the dissector should defragment LAPDm messages spanning multiple packets.",
+        &reassemble_lapdm);
+    register_init_routine (lapdm_defragment_init);
+}
+
index e56a3bf3a27b39df1313ee9e3de61ef0dfe034ca..68c411f1e87490c37bf074447448aa6a41414dd7 100644 (file)
@@ -41,6 +41,7 @@ NONGENERATED_C_FILES = \
        cosine.c                \
        csids.c                 \
        dbs-etherwatch.c        \
+       dct3trace.c             \
        erf.c                   \
        etherpeek.c             \
        eyesdn.c                \
@@ -85,6 +86,7 @@ NONGENERATED_HEADER_FILES = \
        cosine.h                \
        csids.h                 \
        dbs-etherwatch.h        \
+       dct3trace.h             \
        erf.h                   \
        etherpeek.h             \
        eyesdn.h                \
diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c
new file mode 100644 (file)
index 0000000..2697609
--- /dev/null
@@ -0,0 +1,390 @@
+/* dct3trace.c
+ * Routines for reading signalling traces generated by Gammu (www.gammu.org)
+ * from Nokia DCT3 phones in Netmonitor mode.
+ *
+ * gammu --nokiadebug nhm5_587.txt v20-25,v18-19
+ *
+ * Duncan Salerno <duncan.salerno@googlemail.com>
+ *
+ * $Id$
+ *
+ * Wiretap Library
+ * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "wtap-int.h"
+#include "buffer.h"
+#include "dct3trace.h"
+#include "file_wrappers.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+
+/*
+   Example downlink data:
+
+<?xml version="1.0"?>
+<dump>
+<l1 direction="down" logicalchannel="96" physicalchannel="19" sequence="268116" error="0" timeshift="2992" bsic="22" data="31063F100DD0297A53E1020103C802398E0B2B2B2B2B2B" >
+<l2 data="063F100DD0297A53E1020103" rest="C802398E0B2B2B2B2B2B" >
+</l2>
+</l1>
+</dump>
+
+   Example uplink data (no raw L1):
+
+<?xml version="1.0"?>
+<dump>
+<l1 direction="up" logicalchannel="112" >
+<l2 type="U" subtype="Unknown" p="0" data="061500400000000000000000000000000000" >
+</l2>
+</l1>
+</dump>
+
+ */
+
+
+/* Magic text to check */
+static const char dct3trace_magic_line1[] = "<?xml version=\"1.0\"?>";
+static const char dct3trace_magic_line2[] = "<dump>";
+static const char dct3trace_magic_record_start[]  = "<l1 ";
+static const char dct3trace_magic_record_end[]  = "</l1>";
+static const char dct3trace_magic_l2_start[]  = "<l2 ";
+static const char dct3trace_magic_l2_end[]  = "</l2>";
+static const char dct3trace_magic_end[]  = "</dump>";
+
+
+static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info,
+       gint64 *data_offset);
+static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off,
+       union wtap_pseudo_header *pseudo_header, guint8 *pd, int len,
+       int *err, gchar **err_info);
+
+/*
+ * Following 3 functions taken from gsmdecode-0.7bis, with permission - http://wiki.thc.org/gsm
+ */
+
+static int
+hc2b(unsigned char hex)
+{
+       hex = tolower(hex);
+       if ((hex >= '0') && (hex <= '9'))
+               return hex - '0';
+       if ((hex >= 'a') && (hex <= 'f'))
+               return hex - 'a' + 10;
+       return -1;
+}
+
+static int
+hex2bin(unsigned char *out, unsigned char *in)
+{
+       unsigned char *out_start = out;
+       unsigned char *end = in + strlen((char *)in);
+       int is_low = 0;
+       int c;
+
+       while (in < end)
+       {
+               c = hc2b(in[0]);
+               if (c < 0)
+               {
+                       in++;
+                       continue;
+               }
+               if (is_low == 0)
+               {
+                       out[0] = c << 4;
+                       is_low = 1;
+               } else {
+                       out[0] |= (c & 0x0f);
+                       is_low = 0;
+                       out++;
+               }
+               in++;
+       }
+
+       return out - out_start;
+}
+
+static int
+xml_get_int(int *val, const unsigned char *str, const unsigned char *pattern)
+{
+       char *ptr;
+       char *start, *end;
+       char buf[32];
+
+       ptr = strstr((char *)str, (char *)pattern);
+       if (ptr == NULL)
+               return -1;
+       start = strchr(ptr, '"');
+       if (start == NULL)
+               return -2;
+       start++;
+       end = strchr(start, '"');
+       if (end == NULL)
+               return -3;
+
+       memcpy(buf, start, end - start);
+       buf[end - start] = '\0';
+       *val = atoi(buf);
+       return 0;
+}
+
+
+/* Look through the first part of a file to see if this is
+ * a DCT3 trace file.
+ *
+ * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error;
+ * if we get an I/O error, "*err" will be set to a non-zero value.
+ */
+static gboolean dct3trace_check_file_type(wtap *wth, int *err)
+{
+       char line1[64], line2[64];
+
+       if (file_gets(line1, sizeof(line1), wth->fh) != NULL &&
+               file_gets(line2, sizeof(line2), wth->fh) != NULL)
+       {
+               /* Don't compare line endings */
+               if( strncmp(dct3trace_magic_line1, line1, strlen(dct3trace_magic_line1)) == 0 &&
+                       strncmp(dct3trace_magic_line2, line2, strlen(dct3trace_magic_line2)) == 0)
+               {
+                       return TRUE;
+               }
+       }
+       /* EOF or error. */
+       else
+       {
+               if (file_eof(wth->fh))
+                       *err = 0;
+               else
+                       *err = file_error(wth->fh);
+       }
+
+       return FALSE;
+}
+
+
+int dct3trace_open(wtap *wth, int *err, gchar **err_info _U_)
+{
+       /* Look for Gammu DCT3 trace header */
+       if (!dct3trace_check_file_type(wth, err))
+       {
+               if (*err == 0)
+                       return 0;
+               else
+                       return -1;
+       }
+
+       wth->data_offset = 0;
+       wth->file_encap = WTAP_ENCAP_GSM_UM;
+       wth->file_type = WTAP_FILE_DCT3TRACE;
+       wth->snapshot_length = 0; /* not known */
+       wth->subtype_read = dct3trace_read;
+       wth->subtype_seek_read = dct3trace_seek_read;
+       wth->tsprecision = WTAP_FILE_TSPREC_SEC;
+
+       return 1;
+}
+
+
+static gboolean dct3trace_get_packet(FILE *fh, union wtap_pseudo_header *pseudo_header,
+       unsigned char *buf, int *len, int *err, gchar **err_info)
+{
+       unsigned char line[1024];
+       gboolean have_data = FALSE;
+
+       while (file_gets(line, sizeof(line), fh) != NULL)
+       {
+               if( memcmp(dct3trace_magic_end, line, strlen(dct3trace_magic_end)) == 0 )
+               {
+                       /* Return on end of file </dump> */
+                       *err = 0;
+                       return FALSE;
+               }
+               else if( memcmp(dct3trace_magic_record_end, line, strlen(dct3trace_magic_record_end)) == 0 )
+               {
+                       /* Return on end of record </l1> */
+                       if( have_data )
+                       {
+                               *err = 0;
+                               return TRUE;
+                       }
+                       else
+                       {
+                               /* If not got any data return error */
+                               *err = WTAP_ERR_BAD_RECORD;
+                               *err_info = g_strdup_printf("dct3trace: record without data");
+                               return FALSE;
+                       }
+               }
+               else if( memcmp(dct3trace_magic_record_start, line, strlen(dct3trace_magic_record_start)) == 0 )
+               {
+                       /* Parse L1 header <l1 ...>*/
+                       int channel, tmp, ret = 0;
+                       char *ptr;
+
+                       pseudo_header->gsm_um.uplink = !strstr(line, "direction=\"down\"");
+                       ret |= xml_get_int(&channel, line, "logicalchannel");
+
+                       /* Parse downlink only fields */
+                       if( !pseudo_header->gsm_um.uplink )
+                       {
+                               ret |= xml_get_int(&tmp, line, "physicalchannel");
+                               pseudo_header->gsm_um.arfcn = tmp;
+                               ret |= xml_get_int(&tmp, line, "sequence");
+                               pseudo_header->gsm_um.tdma_frame = tmp;
+                               ret |= xml_get_int(&tmp, line, "bsic");
+                               pseudo_header->gsm_um.bsic = tmp;
+                               ret |= xml_get_int(&tmp, line, "error");
+                               pseudo_header->gsm_um.error = tmp;
+                               ret |= xml_get_int(&tmp, line, "timeshift");
+                               pseudo_header->gsm_um.timeshift = tmp;
+                       }
+
+                       if( ret != 0 )
+                       {
+                               *err = WTAP_ERR_BAD_RECORD;
+                               *err_info = g_strdup_printf("dct3trace: record missing mandatory attributes");
+                               return FALSE;
+                       }
+
+                       switch( channel )
+                       {
+                               case 128: pseudo_header->gsm_um.channel = GSM_UM_CHANNEL_SDCCH; break;
+                               case 112: pseudo_header->gsm_um.channel = GSM_UM_CHANNEL_SACCH; break;
+                               case 176: pseudo_header->gsm_um.channel = GSM_UM_CHANNEL_FACCH; break;
+                               case 96: pseudo_header->gsm_um.channel = GSM_UM_CHANNEL_CCCH; break;
+                               case 80: pseudo_header->gsm_um.channel = GSM_UM_CHANNEL_BCCH; break;
+                               default: pseudo_header->gsm_um.channel = GSM_UM_CHANNEL_UNKNOWN; break;
+                       }
+
+                       /* Read data (if have it) into buf */
+                       ptr = strstr(line, "data=\"");
+                       if( ptr )
+                       {
+                               have_data = TRUE; /* If has data... */
+                               *len = hex2bin(buf, ptr+6);
+                       }
+               }
+               else if( !have_data && memcmp(dct3trace_magic_l2_start, line, strlen(dct3trace_magic_l2_start)) == 0 )
+               {
+                       /* For uplink packets we don't get the raw L1, so have to recreate it from the L2 */
+                       /* Parse L2 header if didn't get data from L1 <l2 ...> */
+                       int data_len = 0;
+                       char *ptr = strstr(line, "data=\"");
+
+                       if( !ptr )
+                       {
+                               continue;
+                       }
+
+                       have_data = TRUE;
+
+                       if( pseudo_header->gsm_um.channel == GSM_UM_CHANNEL_SACCH || pseudo_header->gsm_um.channel == GSM_UM_CHANNEL_FACCH || pseudo_header->gsm_um.channel == GSM_UM_CHANNEL_SDCCH )
+                       {
+                               /* Add LAPDm B header */
+                               memset(buf, 0x1, 2);
+                               *len = 3;
+                       }
+                       else
+                       {
+                               /* Add LAPDm Bbis header */
+                               *len = 1;
+                       }
+                       buf += *len;
+
+                       data_len = hex2bin(buf, ptr+6);
+                       *len += data_len;
+
+                       /* Add LAPDm length byte */
+                       *(buf - 1) = data_len << 2 | 0x1;
+               }
+       }
+
+       *err = file_error(fh);
+       if (*err == 0)
+       {
+               *err = WTAP_ERR_SHORT_READ;
+       }
+       return FALSE;
+}
+
+
+/* Find the next packet and parse it; called from wtap_read(). */
+static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info,
+    gint64 *data_offset)
+{
+       guint64 offset = file_tell(wth->fh);
+       int buf_len;
+       char buf[23];
+
+       if( !dct3trace_get_packet(wth->fh, &wth->pseudo_header, buf, &buf_len, err, err_info) )
+       {
+               return FALSE;
+       }
+
+       /* We've got a full packet! */
+       wth->phdr.ts.secs = 0;
+       wth->phdr.ts.nsecs = 0;
+       wth->phdr.caplen = buf_len;
+       wth->phdr.len = buf_len;
+
+       /* Make sure we have enough room for the packet */
+       buffer_assure_space(wth->frame_buffer, buf_len);
+       memcpy( buffer_start_ptr(wth->frame_buffer), buf, buf_len );
+
+       wth->data_offset = *data_offset = offset;
+
+       return TRUE;
+}
+
+
+/* Used to read packets in random-access fashion */
+static gboolean dct3trace_seek_read (wtap *wth, gint64 seek_off,
+       union wtap_pseudo_header *pseudo_header, guint8 *pd, int len,
+       int *err, gchar **err_info)
+{
+       int buf_len;
+       char buf[23];
+
+       if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
+       {
+               return FALSE;
+       }
+
+       if( !dct3trace_get_packet(wth->random_fh, pseudo_header, buf, &buf_len, err, err_info) )
+       {
+               return FALSE;
+       }
+
+       if( len != buf_len && len != -1 )
+       {
+               *err = WTAP_ERR_BAD_RECORD;
+               *err_info = g_strdup_printf("dct3trace: requested length %d doesn't match record length %d",
+                   len, buf_len);
+               return FALSE;
+       }
+
+       memcpy( pd, buf, buf_len );
+       return TRUE;
+}
diff --git a/wiretap/dct3trace.h b/wiretap/dct3trace.h
new file mode 100644 (file)
index 0000000..184d003
--- /dev/null
@@ -0,0 +1,28 @@
+/* dct3trace.h
+ *
+ * $Id$
+ *
+ * Wiretap Library
+ * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef __W_DCT3TRACE_H__
+#define __W_DCT3TRACE_H__
+
+int dct3trace_open(wtap *wth, int *err, gchar **err_info);
+
+#endif
index 60d1db407ee13ba586d61f23178cae668a9bd045..e69df0b46fceffc4b78e6071bdafba8b08c759d4 100644 (file)
@@ -78,6 +78,7 @@
 #include "pcapng.h"
 #include "btsnoop.h"
 #include "tnef.h"
+#include "dct3trace.h"
 
 
 /* The open_file_* routines should return:
@@ -123,6 +124,7 @@ static wtap_open_routine_t open_routines_base[] = {
        pcapng_open,
        btsnoop_open,
        tnef_open,
+       dct3trace_open,
        /* Files that don't have magic bytes at a fixed location,
         * but that instead require a heuristic of some sort to
         * identify them.  This includes the ASCII trace files that
@@ -590,7 +592,10 @@ static const struct file_type_info dump_open_table_base[] = {
        { NULL, NULL, NULL, NULL, FALSE, NULL, NULL },
 
        /* WTAP_FILE_TNEF */
-       { "Transport-Neutral Encapsulation Format", "tnef", "*.*", NULL, FALSE, NULL, NULL }
+       { "Transport-Neutral Encapsulation Format", "tnef", "*.*", NULL, FALSE, NULL, NULL },
+
+       /* WTAP_FILE_DCT3TRACE */
+       { "Gammu DCT3 trace", "dct3trace", "*.xml", NULL, FALSE, NULL, NULL }
 };
 
 gint wtap_num_file_types = sizeof(dump_open_table_base) / sizeof(struct file_type_info);
index 1041e85de6273dfc40c333b0e887b63d7cec2053..ab20d5b5b574879bbc9f7b284bf666bc3b73c1ba 100644 (file)
@@ -437,6 +437,9 @@ static struct encap_type_info encap_table_base[] = {
 
        /* WTAP_ENCAP_USB_LINUX_MMAP */
        { "USB packets with Linux header and padding", "usb-linux-mmap" },
+
+       /* WTAP_ENCAP_GSM_UM */
+       { "GSM Um Interface", "gsm_um" }
 };
 
 gint wtap_num_encap_types = sizeof(encap_table_base) / sizeof(struct encap_type_info);
index 7fe8b04c5850bfa3c78694ea341869cf6ea677d1..ab0237b3acdbb22b2a5a3fd7c299a9a5b61f71ab 100644 (file)
@@ -206,6 +206,7 @@ extern "C" {
 #define WTAP_ENCAP_IEEE802_15_4_NONASK_PHY      113
 #define WTAP_ENCAP_TNEF                         114
 #define WTAP_ENCAP_USB_LINUX_MMAPPED            115
+#define WTAP_ENCAP_GSM_UM                       116
 
 #define WTAP_NUM_ENCAP_TYPES                    wtap_get_num_encap_types()
 
@@ -266,6 +267,7 @@ extern "C" {
 #define WTAP_FILE_BTSNOOP                       51
 #define WTAP_FILE_X2E_XORAYA                    52
 #define WTAP_FILE_TNEF                          53
+#define WTAP_FILE_DCT3TRACE                     54
 
 #define WTAP_NUM_FILE_TYPES                     wtap_get_num_file_types()
 
@@ -751,6 +753,28 @@ struct i2c_phdr {
        guint8 bus;
        guint32 flags;
 };
+
+/* pseudo header for WTAP_ENCAP_GSM_UM */
+struct gsm_um_phdr {
+       gboolean uplink;
+       guint8 channel;
+       /* The following are only populated for downlink */
+       guint8 bsic;
+       guint16 arfcn;
+       guint32 tdma_frame;
+       guint8 error;
+       guint16 timeshift;
+};
+
+#define GSM_UM_CHANNEL_UNKNOWN 0
+#define GSM_UM_CHANNEL_BCCH    1
+#define GSM_UM_CHANNEL_SDCCH   2
+#define GSM_UM_CHANNEL_SACCH   3
+#define GSM_UM_CHANNEL_FACCH   4
+#define GSM_UM_CHANNEL_CCCH    5
+#define GSM_UM_CHANNEL_RACH    6
+#define GSM_UM_CHANNEL_AGCH    7
+#define GSM_UM_CHANNEL_PCH     8
   
 union wtap_pseudo_header {
        struct eth_phdr         eth;
@@ -773,6 +797,7 @@ union wtap_pseudo_header {
        struct bthci_phdr       bthci;
        struct l1event_phdr     l1event;
        struct i2c_phdr         i2c;
+       struct gsm_um_phdr      gsm_um;
 };
 
 struct wtap_nstime {