aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-zbee-zdp.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2015-05-21 22:20:29 -0400
committerAnders Broman <a.broman58@gmail.com>2015-05-27 11:02:30 +0000
commit4963c772852134b75561290d152be2acbe0597d9 (patch)
treec6e6f2f683587e58aea96355cdadd2472215c4c4 /epan/dissectors/packet-zbee-zdp.c
parenta25c46bc7b3d2ba2a3674cdcf9cfc1cc79bfc022 (diff)
Convert proto_tree_add_boolean to proto_tree_add_bitmask_[value|value_with_flags|list]
Final part. While there change deprecated tvb_length-xxx() calls Change-Id: I8b0cf823c2d37a92c58fcb653f7fe1e8fdad5a79 Reviewed-on: https://code.wireshark.org/review/8642 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/dissectors/packet-zbee-zdp.c')
-rw-r--r--epan/dissectors/packet-zbee-zdp.c183
1 files changed, 93 insertions, 90 deletions
diff --git a/epan/dissectors/packet-zbee-zdp.c b/epan/dissectors/packet-zbee-zdp.c
index a7ebbef4f6..0a4cecf8c3 100644
--- a/epan/dissectors/packet-zbee-zdp.c
+++ b/epan/dissectors/packet-zbee-zdp.c
@@ -74,6 +74,7 @@ static int hf_zbee_zdp_status = -1;
int hf_zbee_zdp_cache_address = -1;
/* Capability information indicies. */
+static int hf_zbee_zdp_cinfo = -1;
static int hf_zbee_zdp_cinfo_alloc = -1;
static int hf_zbee_zdp_cinfo_security = -1;
static int hf_zbee_zdp_cinfo_idle_rx = -1;
@@ -82,6 +83,7 @@ static int hf_zbee_zdp_cinfo_ffd = -1;
static int hf_zbee_zdp_cinfo_alt_coord = -1;
/* Server mode flag indicies. */
+static int hf_zbee_zdp_server = -1;
static int hf_zbee_zdp_server_pri_trust = -1;
static int hf_zbee_zdp_server_bak_trust = -1;
static int hf_zbee_zdp_server_pri_bind = -1;
@@ -100,10 +102,12 @@ static int hf_zbee_zdp_node_manufacturer = -1;
static int hf_zbee_zdp_node_max_buffer = -1;
static int hf_zbee_zdp_node_max_incoming_transfer = -1;
static int hf_zbee_zdp_node_max_outgoing_transfer = -1;
+static int hf_zbee_zdp_dcf = -1;
static int hf_zbee_zdp_dcf_eaela = -1;
static int hf_zbee_zdp_dcf_esdla = -1;
/* Power descriptor indicies. */
+static int hf_zbee_zdp_power = -1;
static int hf_zbee_zdp_power_mode = -1;
static int hf_zbee_zdp_power_avail_ac = -1;
static int hf_zbee_zdp_power_avail_recharge = -1;
@@ -695,27 +699,21 @@ zdp_parse_chanmask(proto_tree *tree, tvbuff_t *tvb, guint *offset, int hf_channe
guint8
zdp_parse_cinfo(proto_tree *tree, gint ettindex, tvbuff_t *tvb, guint *offset)
{
- proto_tree *field_tree;
guint8 flags;
+ static const int * cinfo[] = {
+ &hf_zbee_zdp_cinfo_alt_coord,
+ &hf_zbee_zdp_cinfo_ffd,
+ &hf_zbee_zdp_cinfo_power,
+ &hf_zbee_zdp_cinfo_idle_rx,
+ &hf_zbee_zdp_cinfo_security,
+ &hf_zbee_zdp_cinfo_alloc,
+ NULL
+ };
/* Get and display the flags. */
+ proto_tree_add_bitmask_with_flags(tree, tvb, *offset, hf_zbee_zdp_cinfo, ettindex, cinfo, ENC_NA, BMT_NO_APPEND);
flags = tvb_get_guint8(tvb, *offset);
- if (tree) {
- if (ettindex != -1) {
- field_tree = proto_tree_add_subtree(tree, tvb, *offset, (int)sizeof(guint8),
- ettindex, NULL, "Capability Information");
- }
- else
- field_tree = tree;
-
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_cinfo_alt_coord, tvb, *offset, (int)sizeof(guint8), flags & ZBEE_CINFO_ALT_COORD);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_cinfo_ffd, tvb, *offset, (int)sizeof(guint8), flags & ZBEE_CINFO_FFD);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_cinfo_power, tvb, *offset, (int)sizeof(guint8), flags & ZBEE_CINFO_POWER);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_cinfo_idle_rx, tvb, *offset, (int)sizeof(guint8), flags & ZBEE_CINFO_IDLE_RX);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_cinfo_security, tvb, *offset, (int)sizeof(guint8), flags & ZBEE_CINFO_SECURITY);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_cinfo_alloc, tvb, *offset, (int)sizeof(guint8), flags & ZBEE_CINFO_ALLOC);
- }
- *offset += (int)sizeof(guint8);
+ *offset += 1;
return flags;
} /* zdp_parse_cinfo */
@@ -738,26 +736,21 @@ zdp_parse_cinfo(proto_tree *tree, gint ettindex, tvbuff_t *tvb, guint *offset)
guint16
zdp_parse_server_flags(proto_tree *tree, gint ettindex, tvbuff_t *tvb, guint *offset)
{
- proto_tree *field_tree;
guint16 flags;
+ static const int * server_flags[] = {
+ &hf_zbee_zdp_server_pri_trust,
+ &hf_zbee_zdp_server_bak_trust,
+ &hf_zbee_zdp_server_pri_bind,
+ &hf_zbee_zdp_server_bak_bind,
+ &hf_zbee_zdp_server_pri_disc,
+ &hf_zbee_zdp_server_bak_disc,
+ NULL
+ };
/* Get and display the flags. */
flags = tvb_get_letohs(tvb, *offset);
- if (tree) {
- if (ettindex != -1) {
- field_tree = proto_tree_add_subtree(tree, tvb, *offset, 2, ettindex, NULL, "Server Flags");
- }
- else
- field_tree = tree;
-
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_server_pri_trust, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_SERVER_PRIMARY_TRUST);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_server_bak_trust, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_SERVER_BACKUP_TRUST);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_server_pri_bind, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_SERVER_PRIMARY_BIND);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_server_bak_bind, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_SERVER_BACKUP_BIND);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_server_pri_disc, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_SERVER_PRIMARY_DISC);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_server_bak_disc, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_SERVER_BACKUP_DISC);
- }
- *offset += (int)sizeof(guint16);
+ proto_tree_add_bitmask_with_flags(tree, tvb, *offset, hf_zbee_zdp_server, ettindex, server_flags, ENC_LITTLE_ENDIAN, BMT_NO_APPEND);
+ *offset += 2;
return flags;
} /* zdp_parse_server_flags */
@@ -786,12 +779,19 @@ zdp_parse_node_desc(proto_tree *tree, gint ettindex, tvbuff_t *tvb, guint *offse
proto_item *field_root = NULL;
proto_tree *field_tree = NULL;
- guint8 d_c_field;
guint16 flags;
/*guint8 capability;*/
/*guint16 mfr_code;*/
/*guint8 max_buff;*/
/*guint16 max_transfer;*/
+ static const int * nodes[] = {
+ &hf_zbee_zdp_node_complex,
+ &hf_zbee_zdp_node_user,
+ &hf_zbee_zdp_node_freq_868,
+ &hf_zbee_zdp_node_freq_900,
+ &hf_zbee_zdp_node_freq_2400,
+ NULL
+ };
if ((tree) && (ettindex != -1)) {
field_tree = proto_tree_add_subtree(tree, tvb, *offset, -1, ettindex, &field_root, "Node Descriptor");
@@ -803,12 +803,9 @@ zdp_parse_node_desc(proto_tree *tree, gint ettindex, tvbuff_t *tvb, guint *offse
flags = tvb_get_letohs(tvb, *offset);
if (tree) {
guint16 type = flags & ZBEE_ZDP_NODE_TYPE;
- ti = proto_tree_add_uint(field_tree, hf_zbee_zdp_node_type, tvb, *offset, (int)sizeof(guint16), type);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_node_complex, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_COMPLEX);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_node_user, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_USER);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_node_freq_868, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_FREQ_868MHZ);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_node_freq_900, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_FREQ_900MHZ);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_node_freq_2400, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_NODE_FREQ_2400MHZ);
+ ti = proto_tree_add_uint(field_tree, hf_zbee_zdp_node_type, tvb, *offset, 2, type);
+ /* XXX - should probably be converted to proto_tree_add_bitmask */
+ proto_tree_add_bitmask_list(field_tree, tvb, *offset, 2, nodes, ENC_LITTLE_ENDIAN);
/* Enumerate the type field. */
if (type == ZBEE_ZDP_NODE_TYPE_COORD) proto_item_append_text(ti, " (Coordinator)");
@@ -816,7 +813,7 @@ zdp_parse_node_desc(proto_tree *tree, gint ettindex, tvbuff_t *tvb, guint *offse
else if (type == ZBEE_ZDP_NODE_TYPE_RFD) proto_item_append_text(ti, " (End Device)");
else proto_item_append_text(ti, " (Reserved)");
}
- *offset += (int)sizeof(guint16);
+ *offset += 2;
/* Get and display the capability flags. */
/*capability =*/ zdp_parse_cinfo(field_tree, ett_zbee_zdp_cinfo, tvb, offset);
@@ -826,15 +823,15 @@ zdp_parse_node_desc(proto_tree *tree, gint ettindex, tvbuff_t *tvb, guint *offse
/* Get and display the server flags. */
if (version >= ZBEE_VERSION_2007) {
+ const int * descriptors[] = {
+ &hf_zbee_zdp_dcf_eaela,
+ &hf_zbee_zdp_dcf_esdla,
+ NULL
+ };
+
zdp_parse_server_flags(field_tree, ett_zbee_zdp_server, tvb, offset);
zbee_parse_uint(field_tree, hf_zbee_zdp_node_max_outgoing_transfer, tvb, offset, 2, NULL);
- d_c_field = tvb_get_guint8(tvb, *offset);
-
- field_tree = proto_tree_add_subtree(field_tree, tvb, *offset, 1,
- ett_zbee_zdp_descriptor_capability_field, NULL, "Descriptor Capability Field");
-
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_dcf_eaela, tvb, *offset, 1, d_c_field & ZBEE_ZDP_DCF_EAELA);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_dcf_esdla, tvb, *offset, 1, d_c_field & ZBEE_ZDP_DCF_ESDLA);
+ proto_tree_add_bitmask_with_flags(field_tree, tvb, *offset, hf_zbee_zdp_dcf, ett_zbee_zdp_descriptor_capability_field, descriptors, ENC_NA, BMT_NO_APPEND);
*offset += 1;
}
@@ -862,50 +859,40 @@ zdp_parse_node_desc(proto_tree *tree, gint ettindex, tvbuff_t *tvb, guint *offse
* void
*---------------------------------------------------------------
*/
-void
-zdp_parse_power_desc(proto_tree *tree, gint ettindex, tvbuff_t *tvb, guint *offset)
-{
- proto_item *ti;
- proto_tree *field_tree;
+static const value_string zbee_zdp_power_mode_vals[] = {
+ { ZBEE_ZDP_POWER_MODE_RX_ON, "Receiver Always On" },
+ { ZBEE_ZDP_POWER_MODE_RX_PERIODIC, "Receiver Periodically On" },
+ { ZBEE_ZDP_POWER_MODE_RX_STIMULATE, "Receiver On When Stimulated" },
- guint16 flags;
- guint16 mode;
- guint16 level;
+ { 0, NULL }
+};
- if ((tree) && (ettindex != -1)) {
- field_tree = proto_tree_add_subtree(tree, tvb, *offset, (int)sizeof(guint16), ettindex, NULL, "Power Descriptor");
- }
- else field_tree = tree;
+static const value_string zbee_zdp_power_level_vals[] = {
+ { ZBEE_ZDP_POWER_LEVEL_FULL, "Full" },
+ { ZBEE_ZDP_POWER_LEVEL_OK, "OK" },
+ { ZBEE_ZDP_POWER_LEVEL_LOW, "Low" },
+ { ZBEE_ZDP_POWER_LEVEL_CRITICAL, "Critical" },
- flags = tvb_get_letohs(tvb, *offset);
- mode = flags & ZBEE_ZDP_POWER_MODE;
- level = flags & ZBEE_ZDP_POWER_LEVEL;
- if (tree) {
- ti = proto_tree_add_uint(field_tree, hf_zbee_zdp_power_mode, tvb, *offset, (int)sizeof(guint16), mode);
- if (mode == ZBEE_ZDP_POWER_MODE_RX_ON) proto_item_append_text(ti, " (Receiver Always On)");
- else if (mode == ZBEE_ZDP_POWER_MODE_RX_PERIODIC) proto_item_append_text(ti, " (Receiver Periodically On)");
- else if (mode == ZBEE_ZDP_POWER_MODE_RX_STIMULATE) proto_item_append_text(ti, " (Receiver On When Stimulated)");
- else proto_item_append_text(ti, " (Reserved)");
+ { 0, NULL }
+};
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_power_avail_ac, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_POWER_AVAIL_AC);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_power_avail_recharge, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_POWER_AVAIL_RECHARGEABLE);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_power_avail_dispose, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_POWER_AVAIL_DISPOSEABLE);
-
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_power_source_ac, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_POWER_SOURCE_AC);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_power_source_recharge, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_POWER_SOURCE_RECHARGEABLE);
- proto_tree_add_boolean(field_tree, hf_zbee_zdp_power_source_dispose, tvb, *offset, (int)sizeof(guint16), flags & ZBEE_ZDP_POWER_SOURCE_DISPOSEABLE);
-
- if (level == ZBEE_ZDP_POWER_LEVEL_FULL)
- proto_tree_add_uint_format_value(field_tree, hf_zbee_zdp_power_level, tvb, *offset, (int)sizeof(guint16), level, "Full");
- else if (level == ZBEE_ZDP_POWER_LEVEL_OK)
- proto_tree_add_uint_format_value(field_tree, hf_zbee_zdp_power_level, tvb, *offset, (int)sizeof(guint16), level, "OK");
- else if (level == ZBEE_ZDP_POWER_LEVEL_LOW)
- proto_tree_add_uint_format_value(field_tree, hf_zbee_zdp_power_level, tvb, *offset, (int)sizeof(guint16), level, "Low");
- else if (level == ZBEE_ZDP_POWER_LEVEL_CRITICAL)
- proto_tree_add_uint_format_value(field_tree, hf_zbee_zdp_power_level, tvb, *offset, (int)sizeof(guint16), level, "Critical");
- else proto_tree_add_uint_format_value(field_tree, hf_zbee_zdp_power_level, tvb, *offset, (int)sizeof(guint16), level, "Reserved");
- }
- *offset += (int)sizeof(guint16);
+void
+zdp_parse_power_desc(proto_tree *tree, gint ettindex, tvbuff_t *tvb, guint *offset)
+{
+ static const int * power_desc[] = {
+ &hf_zbee_zdp_power_mode,
+ &hf_zbee_zdp_power_avail_ac,
+ &hf_zbee_zdp_power_avail_recharge,
+ &hf_zbee_zdp_power_avail_dispose,
+ &hf_zbee_zdp_power_source_ac,
+ &hf_zbee_zdp_power_source_recharge,
+ &hf_zbee_zdp_power_source_dispose,
+ &hf_zbee_zdp_power_level,
+ NULL
+ };
+
+ proto_tree_add_bitmask_with_flags(tree, tvb, *offset, hf_zbee_zdp_power, ettindex, power_desc, ENC_LITTLE_ENDIAN, BMT_NO_APPEND);
+ *offset += 2;
} /* zdp_parse_power_desc */
/*FUNCTION:------------------------------------------------------
@@ -1485,6 +1472,10 @@ void proto_register_zbee_zdp(void)
{ "Associated Device", "zbee_zdp.assoc_device", FT_UINT16, BASE_HEX, NULL, 0x0,
NULL, HFILL }},
+ { &hf_zbee_zdp_cinfo,
+ { "Capability Information", "zbee_zdp.cinfo", FT_UINT8, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }},
+
{ &hf_zbee_zdp_cinfo_alt_coord,
{ "Alternate Coordinator", "zbee_zdp.cinfo.alt_coord", FT_BOOLEAN, 8, NULL, ZBEE_CINFO_ALT_COORD,
"Indicates that the device is able to operate as a PAN coordinator.", HFILL }},
@@ -1509,6 +1500,10 @@ void proto_register_zbee_zdp(void)
{ "Allocate Short Address", "zbee_zdp.cinfo.alloc", FT_BOOLEAN, 8, NULL, ZBEE_CINFO_ALLOC,
"Flag requesting the parent to allocate a short address for this device.", HFILL }},
+ { &hf_zbee_zdp_dcf,
+ { "Descriptor Capability Field", "zbee_zdp.dcf", FT_UINT8, BASE_HEX, NULL, 0,
+ NULL, HFILL }},
+
{ &hf_zbee_zdp_dcf_eaela,
{ "Extended Active Endpoint List Available", "zbee_zdp.dcf.eaela", FT_BOOLEAN, 8, NULL, ZBEE_ZDP_DCF_EAELA,
NULL, HFILL }},
@@ -1517,6 +1512,10 @@ void proto_register_zbee_zdp(void)
{ "Extended Simple Descriptor List Available", "zbee_zdp.dcf.esdla", FT_BOOLEAN, 8, NULL, ZBEE_ZDP_DCF_ESDLA,
NULL, HFILL }},
+ { &hf_zbee_zdp_server,
+ { "Server Flags", "zbee_zdp.server", FT_UINT16, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }},
+
{ &hf_zbee_zdp_server_pri_trust,
{ "Primary Trust Center", "zbee_zdp.server.pri_trust", FT_BOOLEAN, 16, NULL, ZBEE_ZDP_NODE_SERVER_PRIMARY_TRUST,
NULL, HFILL }},
@@ -1581,8 +1580,12 @@ void proto_register_zbee_zdp(void)
{ "Max Outgoing Transfer Size", "zbee_zdp.node.max_outgoing_transfer", FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }},
+ { &hf_zbee_zdp_power,
+ { "Power Descriptor", "zbee_zdp.power", FT_UINT16, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }},
+
{ &hf_zbee_zdp_power_mode,
- { "Mode", "zbee_zdp.power.mode", FT_UINT16, BASE_DEC, NULL, ZBEE_ZDP_POWER_MODE,
+ { "Mode", "zbee_zdp.power.mode", FT_UINT16, BASE_DEC, VALS(zbee_zdp_power_mode_vals), ZBEE_ZDP_POWER_MODE,
NULL, HFILL }},
{ &hf_zbee_zdp_power_avail_ac,
@@ -1610,7 +1613,7 @@ void proto_register_zbee_zdp(void)
NULL, HFILL }},
{ &hf_zbee_zdp_power_level,
- { "Level", "zbee_zdp.power.level", FT_UINT16, BASE_DEC, NULL, ZBEE_ZDP_POWER_LEVEL,
+ { "Level", "zbee_zdp.power.level", FT_UINT16, BASE_DEC, VALS(zbee_zdp_power_level_vals), ZBEE_ZDP_POWER_LEVEL,
NULL, HFILL }},
{ &hf_zbee_zdp_simple_app_device,