diff options
author | Evan Huus <eapache@gmail.com> | 2013-03-25 17:06:11 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2013-03-25 17:06:11 +0000 |
commit | 0834a38bad2edd4546f144e8f2d812df3249554f (patch) | |
tree | c8dde66456d510b9a75f37d97c04b0d7d204fcbd | |
parent | 83558494fbb1b06085bf588e71c6dbcea8ad6dea (diff) |
From Dario Lombardo, Alexander Chemeris and Ivan Klyuchnikovhis via
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8506
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8507
Dissectors for the VRT (VITA 49 Radio Transport) and UHD protocols.
From me: modelines and misc trivial cleanups.
svn path=/trunk/; revision=48550
-rw-r--r-- | AUTHORS | 3 | ||||
-rw-r--r-- | epan/CMakeLists.txt | 2 | ||||
-rw-r--r-- | epan/dissectors/Makefile.common | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-uhd.c | 318 | ||||
-rw-r--r-- | epan/dissectors/packet-vrt.c | 682 |
5 files changed, 1007 insertions, 0 deletions
@@ -3721,6 +3721,9 @@ Alex Gaertner <gaertner.alex[AT]gmx.de> Sebastiano Di Paola <sebastiano.dipaola[AT]gmail.com> Steven J. Magnani <steve[AT]digidescorp.com> David Arnold <davida[AT]pobox.com> +Dario Lombardo <lomato[AT]gmail.com> +Alexander Chemeris <alexander.chemeris[AT]gmail.com> +Ivan Klyuchnikov <kluchnikovi[AT]gmail.com> Dan Lasley <dlasley[AT]promus.com> gave permission for his diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index 0d30d0a9df..78be11874d 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1205,6 +1205,7 @@ set(DISSECTOR_SRC dissectors/packet-ucp.c dissectors/packet-udld.c dissectors/packet-udp.c + dissectors/packet-uhd.c dissectors/packet-uma.c dissectors/packet-umts_fp.c dissectors/packet-umts_mac.c @@ -1232,6 +1233,7 @@ set(DISSECTOR_SRC dissectors/packet-vnc.c dissectors/packet-vntag.c dissectors/packet-vrrp.c + dissectors/packet-vrt.c dissectors/packet-vssmonitoring.c dissectors/packet-vtp.c dissectors/packet-vuze-dht.c diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common index f95b28f70e..830bd53961 100644 --- a/epan/dissectors/Makefile.common +++ b/epan/dissectors/Makefile.common @@ -1126,6 +1126,7 @@ DISSECTOR_SRC = \ packet-ucp.c \ packet-udld.c \ packet-udp.c \ + packet-uhd.c \ packet-uma.c \ packet-umts_fp.c \ packet-umts_mac.c \ @@ -1153,6 +1154,7 @@ DISSECTOR_SRC = \ packet-vnc.c \ packet-vntag.c \ packet-vrrp.c \ + packet-vrt.c \ packet-vssmonitoring.c \ packet-vtp.c \ packet-vuze-dht.c \ diff --git a/epan/dissectors/packet-uhd.c b/epan/dissectors/packet-uhd.c new file mode 100644 index 0000000000..50d8bf0988 --- /dev/null +++ b/epan/dissectors/packet-uhd.c @@ -0,0 +1,318 @@ +/* packet-uhd.c + * Routines for UHD captures + * + * (C) 2013 by Klyuchnikov Ivan <kluchnikovi@gmail.com>, Dario Lombardo <lomato@gmail.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. + * + */ + +/* + * Original dissector can be found here + * https://github.com/chemeris/uhd_dissector +*/ + + +#include "config.h" + +#include <glib.h> +#include <epan/packet.h> +#include <epan/prefs.h> + +static gint dissector_port_pref = 0; + +/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */ + +#define USRP2_CTRL_ID_HUH_WHAT 0x20 /* ' ' */ +#define UMTRX_CTRL_ID_REQUEST 0x75 /* 'u' */ +#define UMTRX_CTRL_ID_RESPONSE 0x55 /* 'U' */ +#define USRP2_CTRL_ID_WAZZUP_BRO 0x61 /* 'a' */ +#define USRP2_CTRL_ID_WAZZUP_DUDE 0x41 /* 'A' */ +#define USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO 0x73 /* 's' */ +#define USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE 0x53 /* 'S' */ +#define USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO 0x69 /* 'i' */ +#define USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE 0x49 /* 'I' */ +#define USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO 0x68 /* 'h' */ +#define USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE 0x48 /* 'H' */ +#define USRP2_CTRL_ID_GET_THIS_REGISTER_FOR_ME_BRO 0x72 /* 'r' */ +#define USRP2_CTRL_ID_OMG_GOT_REGISTER_SO_BAD_DUDE 0x52 /* 'R' */ +#define USRP2_CTRL_ID_HOLLER_AT_ME_BRO 0x6c /* 'l' */ +#define USRP2_CTRL_ID_HOLLER_BACK_DUDE 0x4c /* 'L' */ +#define USRP2_CTRL_ID_PEACE_OUT 0x7e /* '~' */ + +#define USRP2_REG_ACTION_FPGA_PEEK32 1 +#define USRP2_REG_ACTION_FPGA_PEEK16 2 +#define USRP2_REG_ACTION_FPGA_POKE32 3 +#define USRP2_REG_ACTION_FPGA_POKE16 4 +#define USRP2_REG_ACTION_FW_PEEK32 5 +#define USRP2_REG_ACTION_FW_POKE32 6 + +#define UHD_UDP_PORT 49152 + +/* This is the header as it is used by uhd-generating software. + * It is not used by the wireshark dissector and provided for reference only. +typedef struct{ + uint32_t proto_ver; + uint32_t id; + uint32_t seq; + union{ + uint32_t ip_addr; + struct { + uint32_t dev; + uint32_t data; + uint8_t miso_edge; + uint8_t mosi_edge; + uint8_t num_bits; + uint8_t readback; + } spi_args; + struct { + uint8_t addr; + uint8_t bytes; + uint8_t data[20]; + } i2c_args; + struct { + uint32_t addr; + uint32_t data; + uint8_t action; + } reg_args; + struct { + uint32_t len; + } echo_args; + } data; +} usrp2_ctrl_data_t; + */ + +static int proto_uhd = -1; + +static int hf_uhd_version = -1; +static int hf_uhd_id = -1; +static int hf_uhd_seq = -1; +static int hf_uhd_ip_addr = -1; +static int hf_uhd_i2c_addr = -1; +static int hf_uhd_i2c_bytes = -1; +static int hf_uhd_i2c_data = -1; +static int hf_uhd_spi_dev = -1; +static int hf_uhd_spi_data = -1; +static int hf_uhd_spi_miso_edge = -1; +static int hf_uhd_spi_mosi_edge = -1; +static int hf_uhd_spi_num_bits = -1; +static int hf_uhd_spi_readback = -1; +static int hf_uhd_reg_addr = -1; +static int hf_uhd_reg_data = -1; +static int hf_uhd_reg_action = -1; +static int hf_uhd_echo_len = -1; + + +static gint ett_uhd = -1; + + +static const value_string uhd_ids[] = { + { USRP2_CTRL_ID_HUH_WHAT, "HUH WHAT" }, + { UMTRX_CTRL_ID_REQUEST, "UMTRX REQUEST" }, + { UMTRX_CTRL_ID_RESPONSE, "UMTRX RESPONSE" }, + { USRP2_CTRL_ID_WAZZUP_BRO, "WAZZUP BRO" }, + { USRP2_CTRL_ID_WAZZUP_DUDE, "WAZZUP DUDE" }, + { USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO, "TRANSACT ME SOME SPI BRO" }, + { USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE, "OMG TRANSACTED SPI DUDE" }, + { USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO, "DO AN I2C READ FOR ME BRO" }, + { USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE, "HERES THE I2C DATA DUDE" }, + { USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO, "WRITE THESE I2C VALUES BRO" }, + { USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE, "COOL IM DONE I2C WRITE DUDE" }, + { USRP2_CTRL_ID_GET_THIS_REGISTER_FOR_ME_BRO, "GET THIS REGISTER FOR ME BRO" }, + { USRP2_CTRL_ID_OMG_GOT_REGISTER_SO_BAD_DUDE, "OMG GOT REGISTER SO BAD DUDE" }, + { USRP2_CTRL_ID_HOLLER_AT_ME_BRO, "HOLLER AT ME BRO" }, + { USRP2_CTRL_ID_HOLLER_BACK_DUDE, "HOLLER BACK DUDE" }, + { USRP2_CTRL_ID_PEACE_OUT, "PEACE OUT" }, + { 0, NULL } +}; + +static const value_string uhd_reg_actions[] = { + { USRP2_REG_ACTION_FPGA_PEEK32, "FPGA PEEK32" }, + { USRP2_REG_ACTION_FPGA_PEEK16, "FPGA PEEK16" }, + { USRP2_REG_ACTION_FPGA_POKE32, "FPGA POKE32" }, + { USRP2_REG_ACTION_FPGA_POKE16, "FPGA POKE16" }, + { USRP2_REG_ACTION_FW_PEEK32, "FW PEEK32" }, + { USRP2_REG_ACTION_FW_POKE32, "FW POKE32" }, + { 0, NULL } +}; + +void proto_reg_handoff_uhd(void); + +/* dissect a UHD header and hand payload off to respective dissector */ +static void +dissect_uhd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + int ind; + proto_item *ti; + proto_tree *uhd_tree = NULL; + guint32 id; + guint8 i2c_bytes; + + id = tvb_get_ntohl(tvb, 4); + + col_clear(pinfo->cinfo, COL_INFO); + col_set_str(pinfo->cinfo, COL_PROTOCOL, "UHD"); + col_set_str(pinfo->cinfo, COL_INFO, val_to_str(id, uhd_ids, "Unknown UHD message type '%c'")); + + if (tree) { + + ti = proto_tree_add_protocol_format(tree, proto_uhd, tvb, 0, 34, "UHD id = %c ", id); + uhd_tree = proto_item_add_subtree(ti, ett_uhd); + proto_tree_add_item(uhd_tree, hf_uhd_version, + tvb, 0, 4, ENC_BIG_ENDIAN); + proto_tree_add_item(uhd_tree, hf_uhd_id, + tvb, 4, 4, ENC_BIG_ENDIAN); + proto_tree_add_item(uhd_tree, hf_uhd_seq, + tvb, 8, 4, ENC_BIG_ENDIAN); + } + + switch (id) { + case UMTRX_CTRL_ID_REQUEST: + case UMTRX_CTRL_ID_RESPONSE: + case USRP2_CTRL_ID_WAZZUP_BRO: + case USRP2_CTRL_ID_WAZZUP_DUDE: + proto_tree_add_item(uhd_tree, hf_uhd_ip_addr, tvb, 12, 4, ENC_BIG_ENDIAN); + break; + case USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO: + case USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE: + proto_tree_add_item(uhd_tree, hf_uhd_spi_dev, tvb, 12, 4, ENC_BIG_ENDIAN); + proto_tree_add_item(uhd_tree, hf_uhd_spi_data, tvb, 16, 4, ENC_BIG_ENDIAN); + proto_tree_add_item(uhd_tree, hf_uhd_spi_miso_edge, tvb, 20, 1, ENC_BIG_ENDIAN); + proto_tree_add_item(uhd_tree, hf_uhd_spi_mosi_edge, tvb, 21, 1, ENC_BIG_ENDIAN); + proto_tree_add_item(uhd_tree, hf_uhd_spi_num_bits, tvb, 22, 1, ENC_BIG_ENDIAN); + proto_tree_add_item(uhd_tree, hf_uhd_spi_readback, tvb, 23, 1, ENC_BIG_ENDIAN); + break; + case USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO: + case USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE: + case USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO: + case USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE: + proto_tree_add_item(uhd_tree, hf_uhd_i2c_addr, tvb, 12, 1, ENC_BIG_ENDIAN); + i2c_bytes = tvb_get_guint8(tvb, 13); + proto_tree_add_item(uhd_tree, hf_uhd_i2c_bytes, tvb, 13, 1, ENC_BIG_ENDIAN); + for (ind = 0; ind < i2c_bytes; ind++) { + proto_tree_add_item(uhd_tree, hf_uhd_i2c_data, tvb, 14 + ind, 1, ENC_BIG_ENDIAN); + } + break; + case USRP2_CTRL_ID_GET_THIS_REGISTER_FOR_ME_BRO: + case USRP2_CTRL_ID_OMG_GOT_REGISTER_SO_BAD_DUDE: + proto_tree_add_item(uhd_tree, hf_uhd_reg_addr, tvb, 12, 4, ENC_BIG_ENDIAN); + proto_tree_add_item(uhd_tree, hf_uhd_reg_data, tvb, 16, 4, ENC_BIG_ENDIAN); + proto_tree_add_item(uhd_tree, hf_uhd_reg_action, tvb, 20, 1, ENC_BIG_ENDIAN); + break; + case USRP2_CTRL_ID_HOLLER_AT_ME_BRO: + case USRP2_CTRL_ID_HOLLER_BACK_DUDE: + case USRP2_CTRL_ID_HUH_WHAT: + case USRP2_CTRL_ID_PEACE_OUT: + proto_tree_add_item(uhd_tree, hf_uhd_echo_len, tvb, 12, 4, ENC_BIG_ENDIAN); + break; + } +} + +void +proto_register_uhd(void) +{ + static hf_register_info hf[] = { + { &hf_uhd_version, { "VERSION", "uhd.version", + FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL } }, + { &hf_uhd_id, { "ID", "uhd.id", + FT_UINT32, BASE_HEX, VALS(uhd_ids), 0, NULL, HFILL } }, + { &hf_uhd_seq, { "SEQ", "uhd.seq", + FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL } }, + { &hf_uhd_ip_addr, { "IP ADDR", "uhd.ip_addr", + FT_IPv4, BASE_NONE, NULL, 0x0,"", HFILL } }, + { &hf_uhd_i2c_addr, { "I2C ADDR", "uhd.i2c_addr", + FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } }, + { &hf_uhd_i2c_bytes, { "I2C BYTES", "uhd.i2c_bytes", + FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } }, + { &hf_uhd_i2c_data, { "I2C DATA", "uhd.i2c_data", + FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } }, + { &hf_uhd_spi_dev, { "SPI DEV", "uhd.spi_dev", + FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL } }, + { &hf_uhd_spi_data, { "SPI DATA", "uhd.spi_data", + FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL } }, + { &hf_uhd_spi_miso_edge, { "SPI MISO EDGE", "uhd.spi_miso_edge", + FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } }, + { &hf_uhd_spi_mosi_edge, { "SPI MOSI EDGE", "uhd.spi_mosi_edge", + FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } }, + { &hf_uhd_spi_num_bits, { "SPI NUM BITS", "uhd.spi_num_bits", + FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } }, + { &hf_uhd_spi_readback, { "SPI READBACK", "uhd.spi_readback", + FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } }, + { &hf_uhd_reg_addr, { "REG ADDR", "uhd.reg_addr", + FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL } }, + { &hf_uhd_reg_data, { "REG DATA", "uhd.reg_data", + FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL } }, + { &hf_uhd_reg_action, { "REG ACTION", "uhd.reg_action", + FT_UINT8, BASE_HEX, VALS(uhd_reg_actions), 0, NULL, HFILL } }, + { &hf_uhd_echo_len, { "ECHO LEN", "uhd.echo_len", + FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL } }, + }; + + static gint *ett[] = { + &ett_uhd + }; + + module_t *uhd_module; + + proto_uhd = proto_register_protocol("UHD", "UHD", "uhd"); + proto_register_field_array(proto_uhd, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); + + uhd_module = prefs_register_protocol(proto_uhd, proto_reg_handoff_uhd); + prefs_register_uint_preference(uhd_module, + "dissector_port", + "Dissector UDP port", + "The UDP port used by this dissector", + 10, &dissector_port_pref); +} + +void +proto_reg_handoff_uhd(void) +{ + static gboolean uhd_prefs_initialized = FALSE; + static dissector_handle_t uhd_handle; + static gint dissector_port; + + if (!uhd_prefs_initialized) { + uhd_handle = create_dissector_handle(dissect_uhd, proto_uhd); + uhd_prefs_initialized = TRUE; + } else { + dissector_delete_uint("udp.port", dissector_port, uhd_handle); + } + + dissector_port = dissector_port_pref; + + dissector_add_uint("udp.port", dissector_port, uhd_handle); +} + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 8 + * tab-width: 8 + * indent-tabs-mode: t + * End: + * + * vi: set shiftwidth=8 tabstop=8 noexpandtab: + * :indentSize=8:tabSize=8:noTabs=false: + */ diff --git a/epan/dissectors/packet-vrt.c b/epan/dissectors/packet-vrt.c new file mode 100644 index 0000000000..f29b4080ef --- /dev/null +++ b/epan/dissectors/packet-vrt.c @@ -0,0 +1,682 @@ +/* packet-vrt.c + * Routines for VRT (VITA 49) packet disassembly + * Copyright 2013, Alexander Chemeris (alexander.chemeris@gmail.com), Dario Lombardo (lomato@gmail.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +/* + * Original dissector can be found here + * https://github.com/chemeris/vrt-dissector +*/ + + +#include "config.h" +#include <epan/packet.h> +#include <epan/prefs.h> + +static gint dissector_port_pref = 4991; + +static int proto_vrt = -1; + +/* fields */ +static int hf_vrt_header = -1; /* 32-bit header */ +static int hf_vrt_type = -1; /* 4-bit pkt type */ +static int hf_vrt_cidflag = -1; /* 1-bit class ID flag */ +static int hf_vrt_tflag = -1; /* 1-bit trailer flag */ +static int hf_vrt_tsmflag = -1; /* 1-bit timestamp mode */ +static int hf_vrt_tsi = -1; /* 2-bit timestamp type */ +static int hf_vrt_tsf = -1; /* 2-bit fractional timestamp type */ +static int hf_vrt_seq = -1; /* 4-bit sequence number */ +static int hf_vrt_len = -1; /* 16-bit length */ +static int hf_vrt_sid = -1; /* 32-bit stream ID (opt.) */ +static int hf_vrt_cid = -1; /* 64-bit class ID (opt.) */ +static int hf_vrt_cid_oui = -1; /* 24-bit class ID OUI */ +static int hf_vrt_cid_icc = -1; /* 16-bit class ID ICC */ +static int hf_vrt_cid_pcc = -1; /* 16-bit class ID PCC */ +static int hf_vrt_ts_int = -1; /* 32-bit integer timestamp (opt.) */ +static int hf_vrt_ts_frac_picosecond = -1; /* 64-bit fractional timestamp (opt.) */ +static int hf_vrt_ts_frac_sample = -1; /* 64-bit fractional timestamp (opt.) */ +static int hf_vrt_data = -1; /* data */ +static int hf_vrt_trailer = -1; /* 32-bit trailer (opt.) */ +static int hf_vrt_trailer_enables = -1; /* trailer indicator enables */ +static int hf_vrt_trailer_ind = -1; /* trailer indicators */ +static int hf_vrt_trailer_e = -1; /* ass con pac cnt enable */ +static int hf_vrt_trailer_acpc = -1; /* associated context packet count */ +static int hf_vrt_trailer_en_caltime = -1; /* calibrated time indicator */ +static int hf_vrt_trailer_en_valid = -1; /* valid data ind */ +static int hf_vrt_trailer_en_reflock = -1; /* reference locked ind */ +static int hf_vrt_trailer_en_agc = -1; /* AGC/MGC enabled ind */ +static int hf_vrt_trailer_en_sig = -1; /* signal detected ind */ +static int hf_vrt_trailer_en_inv = -1; /* spectral inversion ind */ +static int hf_vrt_trailer_en_overrng = -1; /* overrange indicator */ +static int hf_vrt_trailer_en_sampleloss = -1; /* sample loss indicator */ +static int hf_vrt_trailer_en_user0 = -1; /* User indicator 0 */ +static int hf_vrt_trailer_en_user1 = -1; /* User indicator 1 */ +static int hf_vrt_trailer_en_user2 = -1; /* User indicator 2 */ +static int hf_vrt_trailer_en_user3 = -1; /* User indicator 3 */ +static int hf_vrt_trailer_ind_caltime = -1; /* calibrated time indicator */ +static int hf_vrt_trailer_ind_valid = -1; /* valid data ind */ +static int hf_vrt_trailer_ind_reflock = -1; /* reference locked ind */ +static int hf_vrt_trailer_ind_agc = -1; /* AGC/MGC enabled ind */ +static int hf_vrt_trailer_ind_sig = -1; /* signal detected ind */ +static int hf_vrt_trailer_ind_inv = -1; /* spectral inversion ind */ +static int hf_vrt_trailer_ind_overrng = -1; /* overrange indicator */ +static int hf_vrt_trailer_ind_sampleloss = -1; /* sample loss indicator */ +static int hf_vrt_trailer_ind_user0 = -1; /* User indicator 0 */ +static int hf_vrt_trailer_ind_user1 = -1; /* User indicator 1 */ +static int hf_vrt_trailer_ind_user2 = -1; /* User indicator 2 */ +static int hf_vrt_trailer_ind_user3 = -1; /* User indicator 3 */ + +/* subtree state variables */ +static gint ett_vrt = -1; +static gint ett_header = -1; +static gint ett_trailer = -1; +static gint ett_indicators = -1; +static gint ett_ind_enables = -1; +static gint ett_cid = -1; + +static const value_string packet_types[] = { + {0x00, "IF data packet without stream ID"}, + {0x01, "IF data packet with stream ID"}, + {0x02, "Extension data packet without stream ID"}, + {0x03, "Extension data packet with stream ID"}, + {0x04, "IF context packet"}, + {0x05, "Extension context packet"}, + {0, NULL} +}; + +static const value_string tsi_types[] = { + {0x00, "No integer-seconds timestamp field included"}, + {0x01, "Coordinated Universal Time (UTC)"}, + {0x02, "GPS time"}, + {0x03, "Other"}, + {0, NULL} +}; + +static const value_string tsf_types[] = { + {0x00, "No fractional-seconds timestamp field included"}, + {0x01, "Sample count timestamp"}, + {0x02, "Real time (picoseconds) timestamp"}, + {0x03, "Free running count timestamp"}, + {0, NULL} +}; + +static const value_string tsm_types[] = { + {0x00, "Precise timestamp resolution"}, + {0x01, "General timestamp resolution"}, + {0, NULL} +}; + +static const int *enable_hfs[] = { + &hf_vrt_trailer_en_user3, + &hf_vrt_trailer_en_user2, + &hf_vrt_trailer_en_user1, + &hf_vrt_trailer_en_user0, + &hf_vrt_trailer_en_sampleloss, + &hf_vrt_trailer_en_overrng, + &hf_vrt_trailer_en_inv, + &hf_vrt_trailer_en_sig, + &hf_vrt_trailer_en_agc, + &hf_vrt_trailer_en_reflock, + &hf_vrt_trailer_en_valid, + &hf_vrt_trailer_en_caltime +}; + +static const int *ind_hfs[] = { + &hf_vrt_trailer_ind_user3, + &hf_vrt_trailer_ind_user2, + &hf_vrt_trailer_ind_user1, + &hf_vrt_trailer_ind_user0, + &hf_vrt_trailer_ind_sampleloss, + &hf_vrt_trailer_ind_overrng, + &hf_vrt_trailer_ind_inv, + &hf_vrt_trailer_ind_sig, + &hf_vrt_trailer_ind_agc, + &hf_vrt_trailer_ind_reflock, + &hf_vrt_trailer_ind_valid, + &hf_vrt_trailer_ind_caltime +}; + +void dissect_header(tvbuff_t *tvb, proto_tree *tree, int type, int offset); +void dissect_trailer(tvbuff_t *tvb, proto_tree *tree, int offset); +void dissect_cid(tvbuff_t *tvb, proto_tree *tree, int offset); +void proto_reg_handoff_vrt(void); + +static void dissect_vrt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + int offset = 0; + guint8 type; + guint8 sidflag; + guint8 cidflag; + guint8 tflag; + guint8 tsiflag; + guint8 tsfflag; + guint16 len; + gint16 nsamps; + + proto_tree *vrt_tree; + proto_item *ti; + + col_set_str(pinfo->cinfo, COL_PROTOCOL, "VITA 49"); + col_clear(pinfo->cinfo,COL_INFO); + + /* HACK to support UHD's weird header offset on data packets. */ + if (tvb_get_guint8(tvb, 0) == 0) offset += 4; + + /* get packet type */ + type = tvb_get_guint8(tvb, offset) >> 4; + col_set_str(pinfo->cinfo, COL_INFO, val_to_str(type, packet_types, "Reserved packet type (0x%02x)")); + + /* get SID, CID, T, TSI, and TSF flags */ + sidflag = (type & 1) || (type == 4); + cidflag = (tvb_get_guint8(tvb, offset) >> 3) & 0x01; + /* tflag is in data packets but not context packets */ + tflag = (tvb_get_guint8(tvb, offset) >> 2) & 0x01; + if(type == 4) tflag = 0; /* this should be unnecessary but we do it + just in case */ + /* tsmflag is in context packets but not data packets + tsmflag = (tvb_get_guint8(tvb, offset) >> 0) & 0x01; */ + tsiflag = (tvb_get_guint8(tvb, offset+1) >> 6) & 0x03; + tsfflag = (tvb_get_guint8(tvb, offset+1) >> 4) & 0x03; + len = tvb_get_ntohs(tvb, offset+2); + nsamps = len - 1 - sidflag - cidflag*2 - tsiflag - tsfflag*2 - tflag; + + if (tree) { /* we're being asked for details */ + ti = proto_tree_add_item(tree, proto_vrt, tvb, offset, -1, ENC_NA); + vrt_tree = proto_item_add_subtree(ti, ett_vrt); + + dissect_header(tvb, vrt_tree, type, offset); + offset += 4; + + /* header's done! if SID (last bit of type), put the stream ID here */ + if(sidflag) { + proto_tree_add_item(vrt_tree, hf_vrt_sid, tvb, offset, 4, ENC_BIG_ENDIAN); + offset += 4; + } + + /* if there's a class ID (cidflag), put the class ID here */ + if(cidflag) { + dissect_cid(tvb, vrt_tree, offset); + offset += 8; + } + + /* if TSI and/or TSF, populate those here */ + if(tsiflag != 0) { + proto_tree_add_item(vrt_tree, hf_vrt_ts_int, tvb, offset, 4, ENC_BIG_ENDIAN); + offset += 4; + } + if(tsfflag != 0) { + if(tsfflag == 1 || tsfflag == 3) { + proto_tree_add_item(vrt_tree, hf_vrt_ts_frac_sample, tvb, offset, 8, ENC_BIG_ENDIAN); + } else if(tsfflag == 2) { + proto_tree_add_item(vrt_tree, hf_vrt_ts_frac_picosecond, tvb, offset, 8, ENC_BIG_ENDIAN); + } + offset += 8; + } + + /* now we've got either a context packet or a data packet + TODO: parse context packet fully instead of just spewing data */ + + /* we're into the data */ + if(nsamps > 0) + { + proto_tree_add_item(vrt_tree, hf_vrt_data, tvb, offset, nsamps*4, ENC_NA); + } + + offset += nsamps*4; + + if(tflag) { + dissect_trailer(tvb, vrt_tree, offset); + } + + + } else { /* we're being asked for a summary */ + + } +} + +void dissect_header(tvbuff_t *tvb, proto_tree *tree, int type, int _offset) +{ + int offset; + proto_item *hdr_item; + proto_tree *hdr_tree; + + offset = _offset; + + hdr_item = proto_tree_add_item(tree, hf_vrt_header, tvb, offset, 4, ENC_BIG_ENDIAN); + + hdr_tree = proto_item_add_subtree(hdr_item, ett_header); + proto_tree_add_item(hdr_tree, hf_vrt_type, tvb, offset, 1, ENC_NA); + proto_tree_add_item(hdr_tree, hf_vrt_cidflag, tvb, offset, 1, ENC_NA); + if(type == 4) { + proto_tree_add_item(hdr_tree, hf_vrt_tsmflag, tvb, offset, 1, ENC_NA); + } else { + proto_tree_add_item(hdr_tree, hf_vrt_tflag, tvb, offset, 1, ENC_NA); + } + offset += 1; + proto_tree_add_item(hdr_tree, hf_vrt_tsi, tvb, offset, 1, ENC_NA); + proto_tree_add_item(hdr_tree, hf_vrt_tsf, tvb, offset, 1, ENC_NA); + proto_tree_add_item(hdr_tree, hf_vrt_seq, tvb, offset, 1, ENC_NA); + offset += 1; + proto_tree_add_item(hdr_tree, hf_vrt_len, tvb, offset, 2, ENC_BIG_ENDIAN); +} + +void dissect_trailer(tvbuff_t *tvb, proto_tree *tree, int offset) +{ + proto_item *enable_item, *ind_item, *trailer_item; + proto_tree *enable_tree; + proto_tree *ind_tree; + proto_tree *trailer_tree; + guint16 en_bits; + gint16 i; + + trailer_item = proto_tree_add_item(tree, hf_vrt_trailer, tvb, offset, 4, ENC_BIG_ENDIAN); + trailer_tree = proto_item_add_subtree(trailer_item, ett_trailer); + + /* grab the indicator enables and the indicators + only display enables, indicators which are enabled */ + enable_item = proto_tree_add_item(trailer_tree, hf_vrt_trailer_enables, tvb, offset, 2, ENC_NA); + ind_item = proto_tree_add_item(trailer_tree, hf_vrt_trailer_ind, tvb, offset + 1, 2, ENC_NA); + /* grab enable bits */ + en_bits = (tvb_get_ntohs(tvb, offset) & 0xFFF0) >> 4; + + /* if there's any enables, start trees for enable bits and for indicators + only enables and indicators which are enabled get printed. */ + if(en_bits) { + enable_tree = proto_item_add_subtree(enable_item, ett_ind_enables); + ind_tree = proto_item_add_subtree(ind_item, ett_indicators); + for(i = 11; i >= 0; i--) { + if(en_bits & (1<<i)) { + proto_tree_add_bits_item(enable_tree, *enable_hfs[i], tvb, (offset+(i<3)) * 8 + (i+1), 1, ENC_NA); + proto_tree_add_bits_item(ind_tree, *ind_hfs[i], tvb, (offset+(i<8)+1) * 8 + (i+5), 1, ENC_NA); + } + } + } + offset += 3; + proto_tree_add_item(trailer_tree, hf_vrt_trailer_e, tvb, offset, 1, ENC_NA); + proto_tree_add_item(trailer_tree, hf_vrt_trailer_acpc, tvb, offset, 1, ENC_NA); +} + +void dissect_cid(tvbuff_t *tvb, proto_tree *tree, int offset) +{ + proto_item *cid_item; + proto_tree *cid_tree; + + cid_item = proto_tree_add_item(tree, hf_vrt_cid, tvb, offset, 8, ENC_BIG_ENDIAN); + cid_tree = proto_item_add_subtree(cid_item, ett_cid); + + offset += 1; + proto_tree_add_item(cid_tree, hf_vrt_cid_oui, tvb, offset, 3, ENC_BIG_ENDIAN); + offset += 3; + proto_tree_add_item(cid_tree, hf_vrt_cid_icc, tvb, offset, 2, ENC_BIG_ENDIAN); + offset += 2; + proto_tree_add_item(cid_tree, hf_vrt_cid_pcc, tvb, offset, 2, ENC_BIG_ENDIAN); +} + +void +proto_register_vrt(void) +{ + static hf_register_info hf[] = { + { &hf_vrt_header, + { "VRT header", "vrt.hdr", + FT_UINT32, BASE_HEX, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_type, + { "Packet type", "vrt.type", + FT_UINT8, 4, + VALS(packet_types), 0xF0, + NULL, HFILL } + }, + { &hf_vrt_cidflag, + { "Class ID included", "vrt.cidflag", + FT_BOOLEAN, 1, + NULL, 0x08, + NULL, HFILL } + }, + { &hf_vrt_tflag, + { "Trailer included", "vrt.tflag", + FT_BOOLEAN, 1, + NULL, 0x04, + NULL, HFILL } + }, + { &hf_vrt_tsmflag, + { "Timestamp mode", "vrt.tsmflag", + FT_UINT8, 1, + VALS(tsm_types), 0x01, + NULL, HFILL } + }, + { &hf_vrt_tsi, + { "Integer timestamp type", "vrt.tsi", + FT_UINT8, 2, + VALS(tsi_types), 0xC0, + NULL, HFILL } + }, + { &hf_vrt_tsf, + { "Fractional timestamp type", "vrt.tsf", + FT_UINT8, 2, + VALS(tsf_types), 0x30, + NULL, HFILL } + }, + { &hf_vrt_seq, + { "Sequence number", "vrt.seq", + FT_UINT8, 4, + NULL, 0x0F, + NULL, HFILL } + }, + { &hf_vrt_len, + { "Length", "vrt.len", + FT_UINT16, BASE_DEC, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_ts_int, + { "Integer timestamp", "vrt.ts_int", + FT_UINT32, BASE_DEC, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_ts_frac_sample, + { "Fractional timestamp (samples)", "vrt.ts_frac", + FT_UINT64, BASE_DEC, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_ts_frac_picosecond, + { "Fractional timestamp (picoseconds)", "vrt.ts_frac", + FT_DOUBLE, BASE_NONE, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_sid, + { "Stream ID", "vrt.sid", + FT_UINT32, BASE_HEX, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_cid, + { "Class ID", "vrt.cid", + FT_UINT64, BASE_HEX, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_data, + { "Data", "vrt.data", + FT_BYTES, BASE_NONE, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_trailer, + { "Trailer", "vrt.trailer", + FT_UINT32, BASE_HEX, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_trailer_enables, + { "Indicator enable bits", "vrt.enables", + FT_UINT16, BASE_HEX, + NULL, 0xFFF0, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind, + { "Indicator bits", "vrt.indicators", + FT_UINT16, BASE_HEX, + NULL, 0x0FFF, + NULL, HFILL } + }, + { &hf_vrt_trailer_e, + { "Associated context packet count enabled", "vrt.e", + FT_BOOLEAN, 1, + NULL, 0x80, + NULL, HFILL } + }, + { &hf_vrt_trailer_acpc, + { "Associated context packet count", "vrt.acpc", + FT_UINT8, BASE_DEC, + NULL, 0x7F, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_caltime, + { "Calibrated time indicator", "vrt.caltime", + FT_BOOLEAN, 1, + NULL, 0x08, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_valid, + { "Valid signal indicator", "vrt.valid", + FT_BOOLEAN, 1, + NULL, 0x04, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_reflock, + { "Reference lock indicator", "vrt.reflock", + FT_BOOLEAN, 1, + NULL, 0x02, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_agc, + { "AGC/MGC indicator", "vrt.agc", + FT_BOOLEAN, 1, + NULL, 0x01, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_sig, + { "Signal detected indicator", "vrt.sig", + FT_BOOLEAN, 1, + NULL, 0x80, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_inv, + { "Spectral inversion indicator", "vrt.inv", + FT_BOOLEAN, 1, + NULL, 0x40, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_overrng, + { "Overrange indicator", "vrt.overrng", + FT_BOOLEAN, 1, + NULL, 0x20, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_sampleloss, + { "Lost sample indicator", "vrt.sampleloss", + FT_BOOLEAN, 1, + NULL, 0x10, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_user0, + { "User indicator 0", "vrt.user0", + FT_BOOLEAN, 1, + NULL, 0x000, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_user1, + { "User indicator 1", "vrt.user1", + FT_BOOLEAN, 1, + NULL, 0x0000, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_user2, + { "User indicator 2", "vrt.user2", + FT_BOOLEAN, 1, + NULL, 0x000, + NULL, HFILL } + }, + { &hf_vrt_trailer_ind_user3, + { "User indicator 3", "vrt.user3", + FT_BOOLEAN, 1, + NULL, 0x0000, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_caltime, + { "Calibrated time indicator enable", "vrt.caltime_en", + FT_BOOLEAN, 1, + NULL, 0x80, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_valid, + { "Valid signal indicator enable", "vrt.valid_en", + FT_BOOLEAN, 1, + NULL, 0x40, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_reflock, + { "Reference lock indicator enable", "vrt.reflock_en", + FT_BOOLEAN, 1, + NULL, 0x20, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_agc, + { "AGC/MGC indicator enable", "vrt.agc_en", + FT_BOOLEAN, 1, + NULL, 0x10, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_sig, + { "Signal detected indicator enable", "vrt.sig_en", + FT_BOOLEAN, 1, + NULL, 0x08, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_inv, + { "Spectral inversion indicator enable", "vrt.inv_en", + FT_BOOLEAN, 1, + NULL, 0x04, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_overrng, + { "Overrange indicator enable", "vrt.overrng_en", + FT_BOOLEAN, 1, + NULL, 0x02, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_sampleloss, + { "Lost sample indicator enable", "vrt.sampleloss_en", + FT_BOOLEAN, 1, + NULL, 0x01, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_user0, + { "User indicator 0 enable", "vrt.user0_en", + FT_BOOLEAN, 1, + NULL, 0x80, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_user1, + { "User indicator 1 enable", "vrt.user1_en", + FT_BOOLEAN, 1, + NULL, 0x0000, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_user2, + { "User indicator 2 enable", "vrt.user2_en", + FT_BOOLEAN, 1, + NULL, 0x20, + NULL, HFILL } + }, + { &hf_vrt_trailer_en_user3, + { "User indicator 3 enable", "vrt.user3_en", + FT_BOOLEAN, 1, + NULL, 0x0000, + NULL, HFILL } + }, + { &hf_vrt_cid_oui, + { "Class ID Organizationally Unique ID", "vrt.oui", + FT_UINT24, BASE_HEX, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_cid_icc, + { "Class ID Information Class Code", "vrt.icc", + FT_UINT16, BASE_DEC, + NULL, 0x00, + NULL, HFILL } + }, + { &hf_vrt_cid_pcc, + { "Class ID Packet Class Code", "vrt.pcc", + FT_UINT16, BASE_DEC, + NULL, 0x00, + NULL, HFILL } + } + }; + + static gint *ett[] = { + &ett_vrt, + &ett_header, + &ett_trailer, + &ett_indicators, + &ett_ind_enables, + &ett_cid + }; + + module_t *vrt_module; + + proto_vrt = proto_register_protocol ( + "VITA 49 radio transport protocol", /* name */ + "VITA 49", /* short name */ + "vrt" /* abbrev */ + ); + + proto_register_field_array(proto_vrt, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); + + vrt_module = prefs_register_protocol(proto_vrt, proto_reg_handoff_vrt); + prefs_register_uint_preference(vrt_module, + "dissector_port", + "Dissector UDP port", + "The UDP port used by this dissector", + 10, &dissector_port_pref); +} + +void +proto_reg_handoff_vrt(void) +{ + static gboolean vrt_prefs_initialized = FALSE; + static dissector_handle_t vrt_handle; + static gint dissector_port; + + if (!vrt_prefs_initialized) { + vrt_handle = create_dissector_handle(dissect_vrt, proto_vrt); + vrt_prefs_initialized = TRUE; + } else { + dissector_delete_uint("udp.port", dissector_port, vrt_handle); + } + + dissector_port = dissector_port_pref; + + dissector_add_uint("udp.port", dissector_port, vrt_handle); +} + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ |