aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-rmt-alc.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2013-05-24 17:06:23 +0000
committerMichael Mann <mmann78@netscape.net>2013-05-24 17:06:23 +0000
commitd12fc51afd1bca6c0b7b2858a18772b29f514c0c (patch)
tree5eb7bb6d3e41973905bbd8fb7dc50701336d1a3c /epan/dissectors/packet-rmt-alc.c
parent7dddfb1784667e65616b02834469b834819161cb (diff)
Overhauled the RMT dissectors. Not sure each needs its own file, but since this involves multiple RFCs, they remain split out by that. More are now a "pure" dissector and not a "decoding function hook".
Some Notes: 1. Converted to "new style" dissectors with data being passed between dissectors 2. Combined header files into one since there wasn't much that should have really been in the header files. Implemented functionality is in c module of respective dissector. Not sure if LCT preferences should just be in the LCT dissector and not the RMT-ALC "parent", but kept for backwards compatibility. svn path=/trunk/; revision=49555
Diffstat (limited to 'epan/dissectors/packet-rmt-alc.c')
-rw-r--r--epan/dissectors/packet-rmt-alc.c287
1 files changed, 131 insertions, 156 deletions
diff --git a/epan/dissectors/packet-rmt-alc.c b/epan/dissectors/packet-rmt-alc.c
index 1913a0d904..298db469aa 100644
--- a/epan/dissectors/packet-rmt-alc.c
+++ b/epan/dissectors/packet-rmt-alc.c
@@ -40,90 +40,51 @@
#include "config.h"
-#include <string.h>
-
#include <glib.h>
#include <epan/packet.h>
#include <epan/prefs.h>
+#include <epan/expert.h>
-#include "packet-rmt-alc.h"
+#include "packet-rmt-common.h"
/* Initialize the protocol and registered fields */
/* ============================================= */
-static int proto = -1;
-
-static struct _alc_hf hf;
-static struct _alc_ett ett;
-
-static struct _alc_prefs preferences;
-static dissector_handle_t xml_handle;
+static int proto_rmt_alc = -1;
+static int hf_version = -1;
+static int hf_payload = -1;
-/* Preferences */
-/* =========== */
+static int ett_main = -1;
-/* Set/Reset preferences to default values */
-static void alc_prefs_set_default(struct _alc_prefs *alc_prefs)
-{
- alc_prefs->use_default_udp_port = FALSE;
- alc_prefs->default_udp_port = 4001;
-
- lct_prefs_set_default(&alc_prefs->lct);
- fec_prefs_set_default(&alc_prefs->fec);
-}
-
-/* Register preferences */
-static void alc_prefs_register(struct _alc_prefs *alc_prefs, module_t *module)
-{
- prefs_register_bool_preference(module,
- "default.udp_port.enabled",
- "Use default UDP port",
- "Whether that payload of UDP packets with a specific destination port should be automatically dissected as ALC packets",
- &alc_prefs->use_default_udp_port);
-
- prefs_register_uint_preference(module,
- "default.udp_port",
- "Default UDP destination port",
- "Specifies the UDP destination port for automatic dissection of ALC packets",
- 10, &alc_prefs->default_udp_port);
-
- lct_prefs_register(&alc_prefs->lct, module);
- fec_prefs_register(&alc_prefs->fec, module);
-}
+static dissector_handle_t xml_handle;
+static dissector_handle_t rmt_lct_handle;
+static dissector_handle_t rmt_fec_handle;
-/* Save preferences to alc_prefs_old */
-static void alc_prefs_save(struct _alc_prefs *p, struct _alc_prefs *p_old)
-{
- *p_old = *p;
-}
+static guint g_default_udp_port = 0; /* 4001 */
+static gboolean g_codepoint_as_fec_encoding = TRUE;
+static gint g_ext_192 = LCT_PREFS_EXT_192_FLUTE;
+static gint g_ext_193 = LCT_PREFS_EXT_193_FLUTE;
/* Code to actually dissect the packets */
/* ==================================== */
-
-static void dissect_alc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+static int
+dissect_alc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
- /* Logical packet representation */
- struct _alc alc;
+ guint8 version;
+ lct_data_exchange_t lct;
+ fec_data_exchange_t fec;
+ int len;
/* Offset for subpacket dissection */
- guint offset;
+ guint offset = 0;
/* Set up structures needed to add the protocol subtree and manage it */
proto_item *ti;
proto_tree *alc_tree;
- /* Flute or not */
tvbuff_t *new_tvb;
- gboolean is_flute = FALSE;
-
- /* Structures and variables initialization */
- offset = 0;
- memset(&alc, 0, sizeof(struct _alc));
-
- /* Update packet info */
- pinfo->current_proto = "ALC";
/* Make entries in Protocol column and Info column on summary display */
col_set_str(pinfo->cinfo, COL_PROTOCOL, "ALC");
@@ -132,110 +93,96 @@ static void dissect_alc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* ALC header dissection */
/* --------------------- */
- alc.version = hi_nibble(tvb_get_guint8(tvb, offset));
-
- if (tree)
- {
- /* Create subtree for the ALC protocol */
- ti = proto_tree_add_item(tree, proto, tvb, offset, -1, ENC_NA);
- alc_tree = proto_item_add_subtree(ti, ett.main);
+ version = hi_nibble(tvb_get_guint8(tvb, offset));
- /* Fill the ALC subtree */
- proto_tree_add_uint(alc_tree, hf.version, tvb, offset, 1, alc.version);
+ /* Create subtree for the ALC protocol */
+ ti = proto_tree_add_item(tree, proto_rmt_alc, tvb, offset, -1, ENC_NA);
+ alc_tree = proto_item_add_subtree(ti, ett_main);
- } else
- alc_tree = NULL;
+ /* Fill the ALC subtree */
+ ti = proto_tree_add_uint(alc_tree, hf_version, tvb, offset, 1, version);
/* This dissector supports only ALCv1 packets.
- * If alc.version > 1 print only version field and quit.
+ * If version > 1 print only version field and quit.
*/
- if (alc.version == 1) {
-
- struct _lct_ptr l;
- struct _fec_ptr f;
-
- l.lct = &alc.lct;
- l.hf = &hf.lct;
- l.ett = &ett.lct;
- l.prefs = &preferences.lct;
-
- f.fec = &alc.fec;
- f.hf = &hf.fec;
- f.ett = &ett.fec;
- f.prefs = &preferences.fec;
-
- /* LCT header dissection */
- /* --------------------- */
-
- is_flute = lct_dissector(l, f, tvb, alc_tree, &offset);
-
- /* FEC header dissection */
- /* --------------------- */
-
- /* Only if it's present and if LCT dissector has determined FEC Encoding ID
- * FEC dissector should be called with fec->encoding_id* and fec->instance_id* filled
- */
- if (alc.fec.encoding_id_present && tvb_length(tvb) > offset)
- fec_dissector(f, tvb, alc_tree, &offset);
-
- /* Add the Payload item */
- if (tvb_length(tvb) > offset){
- if(is_flute){
- new_tvb = tvb_new_subset_remaining(tvb,offset);
- call_dissector(xml_handle, new_tvb, pinfo, alc_tree);
- }else{
- proto_tree_add_none_format(alc_tree, hf.payload, tvb, offset, -1, "Payload (%u bytes)", tvb_length(tvb) - offset);
- }
- }
+ if (version != 1) {
+ expert_add_info_format(pinfo, ti, PI_PROTOCOL, PI_WARN, "Sorry, this dissector supports ALC version 1 only");
/* Complete entry in Info column on summary display */
- /* ------------------------------------------------ */
+ col_add_fstr(pinfo->cinfo, COL_INFO, "Version: %u (not supported)", version);
+ return 0;
+ }
- if (check_col(pinfo->cinfo, COL_INFO))
- {
- lct_info_column(&alc.lct, pinfo);
- fec_info_column(&alc.fec, pinfo);
- }
+ /* LCT header dissection */
+ /* --------------------- */
+ new_tvb = tvb_new_subset_remaining(tvb,offset);
+
+ lct.ext_192 = g_ext_192;
+ lct.ext_193 = g_ext_193;
+ lct.codepoint = 0;
+ lct.is_flute = FALSE;
+ len = call_dissector_with_data(rmt_lct_handle, new_tvb, pinfo, alc_tree, &lct);
+ if (len < 0)
+ return offset;
- /* Free g_allocated memory */
- lct_dissector_free(&alc.lct);
- fec_dissector_free(&alc.fec);
+ offset += len;
- } else {
+ /* FEC header dissection */
+ /* --------------------- */
- if (tree)
- proto_tree_add_text(alc_tree, tvb, 0, -1, "Sorry, this dissector supports ALC version 1 only");
+ /* Only if LCT dissector has determined FEC Encoding ID */
+ /* FEC dissector needs to be called with encoding_id filled */
+ if (g_codepoint_as_fec_encoding && tvb_reported_length(tvb) > offset)
+ {
+ fec.encoding_id = lct.codepoint;
- /* Complete entry in Info column on summary display */
- if (check_col(pinfo->cinfo, COL_INFO))
- col_add_fstr(pinfo->cinfo, COL_INFO, "Version: %u (not supported)", alc.version);
+ new_tvb = tvb_new_subset_remaining(tvb,offset);
+ len = call_dissector_with_data(rmt_fec_handle, new_tvb, pinfo, alc_tree, &fec);
+ if (len < 0)
+ return offset;
+
+ offset += len;
+ }
+
+ /* Add the Payload item */
+ if (tvb_reported_length(tvb) > offset){
+ if(lct.is_flute){
+ new_tvb = tvb_new_subset_remaining(tvb,offset);
+ call_dissector(xml_handle, new_tvb, pinfo, alc_tree);
+ }else{
+ proto_tree_add_item(alc_tree, hf_payload, tvb, offset, -1, ENC_NA);
+ }
}
+
+ return tvb_reported_length(tvb);
}
void proto_reg_handoff_alc(void)
{
static dissector_handle_t handle;
static gboolean preferences_initialized = FALSE;
- static struct _alc_prefs preferences_old;
+ static guint old_udp_port = 0;
if (!preferences_initialized)
{
preferences_initialized = TRUE;
- handle = create_dissector_handle(dissect_alc, proto);
+ handle = new_create_dissector_handle(dissect_alc, proto_rmt_alc);
dissector_add_handle("udp.port", handle);
xml_handle = find_dissector("xml");
+ rmt_lct_handle = find_dissector("rmt-lct");
+ rmt_fec_handle = find_dissector("rmt-fec");
+ }
- } else {
-
- if (preferences_old.use_default_udp_port)
- dissector_delete_uint("udp.port", preferences_old.default_udp_port, handle);
+ /* Register UDP port for dissection */
+ if(old_udp_port != 0 && old_udp_port != g_default_udp_port){
+ dissector_delete_uint("udp.port", old_udp_port, handle);
}
- if (preferences.use_default_udp_port)
- dissector_add_uint("udp.port", preferences.default_udp_port, handle);
-
- alc_prefs_save(&preferences, &preferences_old);
+ if(g_default_udp_port != 0 && old_udp_port != g_default_udp_port) {
+ dissector_add_uint("udp.port", g_default_udp_port, handle);
+ }
+ old_udp_port = g_default_udp_port;
}
void proto_register_alc(void)
@@ -243,43 +190,71 @@ void proto_register_alc(void)
/* Setup ALC header fields */
static hf_register_info hf_ptr[] = {
- { &hf.version,
+ { &hf_version,
{ "Version", "alc.version", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
- LCT_FIELD_ARRAY(hf.lct, "alc"),
- FEC_FIELD_ARRAY(hf.fec, "alc"),
-
- { &hf.payload,
- { "Payload", "alc.payload", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }}
+ { &hf_payload,
+ { "Payload", "alc.payload", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }}
};
/* Setup protocol subtree array */
static gint *ett_ptr[] = {
- &ett.main,
-
- LCT_SUBTREE_ARRAY(ett.lct),
- FEC_SUBTREE_ARRAY(ett.fec)
+ &ett_main,
};
module_t *module;
- /* Clear hf and ett fields */
- memset(&hf, 0xff, sizeof(struct _alc_hf));
- memset(&ett, 0xff, sizeof(struct _alc_ett));
-
/* Register the protocol name and description */
- proto = proto_register_protocol("Asynchronous Layered Coding", "ALC", "alc");
+ proto_rmt_alc = proto_register_protocol("Asynchronous Layered Coding", "ALC", "alc");
+ new_register_dissector("alc", dissect_alc, proto_rmt_alc);
/* Register the header fields and subtrees used */
- proto_register_field_array(proto, hf_ptr, array_length(hf_ptr));
+ proto_register_field_array(proto_rmt_alc, hf_ptr, array_length(hf_ptr));
proto_register_subtree_array(ett_ptr, array_length(ett_ptr));
- /* Reset preferences */
- alc_prefs_set_default(&preferences);
-
/* Register preferences */
- module = prefs_register_protocol(proto, proto_reg_handoff_alc);
- alc_prefs_register(&preferences, module);
+ module = prefs_register_protocol(proto_rmt_alc, proto_reg_handoff_alc);
- register_dissector("alc", dissect_alc, proto);
+ prefs_register_obsolete_preference(module, "default.udp_port.enabled");
+
+ prefs_register_uint_preference(module,
+ "default.udp_port",
+ "UDP destination port",
+ "Specifies the UDP destination port for automatic dissection of ALC packets",
+ 10, &g_default_udp_port);
+
+ prefs_register_bool_preference(module,
+ "lct.codepoint_as_fec_id",
+ "LCT Codepoint as FEC Encoding ID",
+ "Whether the LCT header Codepoint field should be considered the FEC Encoding ID of carried object",
+ &g_codepoint_as_fec_encoding);
+
+ prefs_register_enum_preference(module,
+ "lct.ext.192",
+ "LCT header extension 192",
+ "How to decode LCT header extension 192",
+ &g_ext_192,
+ enum_lct_ext_192,
+ FALSE);
+
+ prefs_register_enum_preference(module,
+ "lct.ext.193",
+ "LCT header extension 193",
+ "How to decode LCT header extension 193",
+ &g_ext_193,
+ enum_lct_ext_193,
+ FALSE);
}
+
+/*
+* Editor modelines - http://www.wireshark.org/tools/modelines.html
+*
+* Local variables:
+* c-basic-offset: 4
+* tab-width: 8
+* indent-tabs-mode: nil
+* End:
+*
+* ex: set shiftwidth=4 tabstop=8 expandtab:
+* :indentSize=4:tabSize=8:noTabs=true:
+*/