From 4cf6583b9e5bc7fa5d6f6ac17cdc1f634ae1567e Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Fri, 26 Dec 2014 09:44:30 -0500 Subject: [PATCH] Remove proto_tree_add_text from ZigBee dissectors. Change-Id: I0488cb0ab33f2cc6dee227f1bfacec58eafc4190 Reviewed-on: https://code.wireshark.org/review/6055 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- epan/dissectors/packet-zbee-nwk-gp.c | 219 ++++++------ epan/dissectors/packet-zbee-nwk.c | 332 +++++++++---------- epan/dissectors/packet-zbee-zcl-general.c | 147 ++++---- epan/dissectors/packet-zbee-zdp-binding.c | 58 ++-- epan/dissectors/packet-zbee-zdp-management.c | 166 ++++------ epan/dissectors/packet-zbee-zdp.c | 169 +++++++++- epan/dissectors/packet-zbee-zdp.h | 29 +- 7 files changed, 638 insertions(+), 482 deletions(-) diff --git a/epan/dissectors/packet-zbee-nwk-gp.c b/epan/dissectors/packet-zbee-nwk-gp.c index e7db47d496..ce571bf27b 100644 --- a/epan/dissectors/packet-zbee-nwk-gp.c +++ b/epan/dissectors/packet-zbee-nwk-gp.c @@ -197,10 +197,12 @@ static int proto_zbee_nwk_gp = -1; /* GP NWK FC. */ static int hf_zbee_nwk_gp_auto_commissioning = -1; static int hf_zbee_nwk_gp_fc_ext = -1; +static int hf_zbee_nwk_gp_fcf = -1; static int hf_zbee_nwk_gp_frame_type = -1; static int hf_zbee_nwk_gp_proto_version = -1; /* GP NWK FC extension. */ +static int hf_zbee_nwk_gp_fc_ext_field = -1; static int hf_zbee_nwk_gp_fc_ext_app_id = -1; static int hf_zbee_nwk_gp_fc_ext_direction = -1; static int hf_zbee_nwk_gp_fc_ext_rx_after_tx = -1; @@ -222,13 +224,16 @@ static int hf_zbee_nwk_gp_command_id = -1; /* Commissioning. */ static int hf_zbee_nwk_gp_cmd_comm_device_id = -1; +static int hf_zbee_nwk_gp_cmd_comm_ext_opt = -1; static int hf_zbee_nwk_gp_cmd_comm_ext_opt_gpd_key_encr = -1; static int hf_zbee_nwk_gp_cmd_comm_ext_opt_gpd_key_present = -1; static int hf_zbee_nwk_gp_cmd_comm_ext_opt_key_type = -1; static int hf_zbee_nwk_gp_cmd_comm_ext_opt_outgoing_counter = -1; static int hf_zbee_nwk_gp_cmd_comm_ext_opt_sec_level_cap = -1; +static int hf_zbee_nwk_gp_cmd_comm_security_key = -1; static int hf_zbee_nwk_gp_cmd_comm_gpd_sec_key_mic = -1; static int hf_zbee_nwk_gp_cmd_comm_opt_ext_opt = -1; +static int hf_zbee_nwk_gp_cmd_comm_opt = -1; static int hf_zbee_nwk_gp_cmd_comm_opt_fixed_location = -1; static int hf_zbee_nwk_gp_cmd_comm_opt_mac_sec_num_cap = -1; static int hf_zbee_nwk_gp_cmd_comm_opt_ms_ext_present = -1; @@ -238,12 +243,14 @@ static int hf_zbee_nwk_gp_cmd_comm_opt_sec_key_req = -1; static int hf_zbee_nwk_gp_cmd_comm_outgoing_counter = -1; static int hf_zbee_nwk_gp_cmd_comm_manufacturer_greenpeak_dev_id = -1; static int hf_zbee_nwk_gp_cmd_comm_manufacturer_id = -1; +static int hf_zbee_nwk_gp_cmd_comm_ms_ext = -1; static int hf_zbee_nwk_gp_cmd_comm_ms_ext_crp = -1; static int hf_zbee_nwk_gp_cmd_comm_ms_ext_gclp = -1; static int hf_zbee_nwk_gp_cmd_comm_ms_ext_mip = -1; static int hf_zbee_nwk_gp_cmd_comm_ms_ext_mmip = -1; /* Commissioning reply. */ +static int hf_zbee_nwk_gp_cmd_comm_rep_opt = -1; static int hf_zbee_nwk_gp_cmd_comm_rep_opt_key_encr = -1; static int hf_zbee_nwk_gp_cmd_comm_rep_opt_panid_present = -1; static int hf_zbee_nwk_gp_cmd_comm_rep_opt_sec_key_present = -1; @@ -255,10 +262,12 @@ static int hf_zbee_nwk_gp_cmd_comm_rep_pan_id = -1; static int hf_zbee_nwk_gp_cmd_attr_report_cluster_id = -1; /* Channel request. */ +static int hf_zbee_nwk_gp_cmd_channel_request_toggling_behaviour = -1; static int hf_zbee_nwk_gp_cmd_channel_request_toggling_behaviour_1st = -1; static int hf_zbee_nwk_gp_cmd_channel_request_toggling_behaviour_2nd = -1; /* Channel Configuration command. */ +static int hf_zbee_nwk_gp_cmd_operational_channel = -1; static int hf_zbee_nwk_gp_cmd_channel_configuration = -1; /* Move Color command. */ @@ -649,47 +658,51 @@ static guint dissect_zbee_nwk_gp_cmd_commissioning(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, zbee_nwk_green_power_packet *packet _U_, guint offset) { - guint8 comm_options = 0; + guint8 comm_options; guint8 comm_ext_options = 0; guint8 ms_ext_options = 0; guint16 manufacturer_id = 0; - proto_item *ti = NULL; - proto_tree *field_tree = NULL; + static const int * options[] = { + &hf_zbee_nwk_gp_cmd_comm_opt_mac_sec_num_cap, + &hf_zbee_nwk_gp_cmd_comm_opt_rx_on_cap, + &hf_zbee_nwk_gp_cmd_comm_opt_ms_ext_present, + &hf_zbee_nwk_gp_cmd_comm_opt_panid_req, + &hf_zbee_nwk_gp_cmd_comm_opt_sec_key_req, + &hf_zbee_nwk_gp_cmd_comm_opt_fixed_location, + &hf_zbee_nwk_gp_cmd_comm_opt_ext_opt, + NULL + }; + static const int * ext_options[] = { + &hf_zbee_nwk_gp_cmd_comm_ext_opt_sec_level_cap, + &hf_zbee_nwk_gp_cmd_comm_ext_opt_key_type, + &hf_zbee_nwk_gp_cmd_comm_ext_opt_gpd_key_present, + &hf_zbee_nwk_gp_cmd_comm_ext_opt_gpd_key_encr, + &hf_zbee_nwk_gp_cmd_comm_ext_opt_outgoing_counter, + NULL + }; + static const int * ms_ext[] = { + &hf_zbee_nwk_gp_cmd_comm_ms_ext_mip, + &hf_zbee_nwk_gp_cmd_comm_ms_ext_mmip, + &hf_zbee_nwk_gp_cmd_comm_ms_ext_gclp, + &hf_zbee_nwk_gp_cmd_comm_ms_ext_crp, + NULL + }; /* Get Device ID and display it. */ proto_tree_add_item(tree, hf_zbee_nwk_gp_cmd_comm_device_id, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset += 1; /* Get Options Field, build subtree and display the results. */ comm_options = tvb_get_guint8(tvb, offset); - if (tree) { - ti = proto_tree_add_text(tree, tvb, offset, 1, "Options Field: 0x%02x", comm_options); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_cmd_options); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_opt_mac_sec_num_cap, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_opt_rx_on_cap, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_opt_ms_ext_present, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_opt_panid_req, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_opt_sec_key_req, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_opt_fixed_location, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_opt_ext_opt, tvb, offset, 1, ENC_NA); - } - offset += 1; + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_gp_cmd_comm_opt, ett_zbee_nwk_cmd_options, options, ENC_NA); + if (comm_options & ZBEE_NWK_GP_CMD_COMMISSIONING_OPT_EXT_OPTIONS) { /* Get extended Options Field, build subtree and display the results. */ comm_ext_options = tvb_get_guint8(tvb, offset); - if (tree) { - ti = proto_tree_add_text(tree, tvb, offset, 1, "Extended Options Field: 0x%02x", comm_ext_options); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_cmd_options); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_ext_opt_sec_level_cap, tvb, offset, 1, ENC_LITTLE_ENDIAN); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_ext_opt_key_type, tvb, offset, 1, ENC_LITTLE_ENDIAN); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_ext_opt_gpd_key_present, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_ext_opt_gpd_key_encr, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_ext_opt_outgoing_counter, tvb, offset, 1, ENC_NA); - } + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_gp_cmd_comm_ext_opt, ett_zbee_nwk_cmd_options, ext_options, ENC_NA); offset += 1; if (comm_ext_options & ZBEE_NWK_GP_CMD_COMMISSIONING_EXT_OPT_GPD_KEY_PRESENT) { /* Get security key and display it. */ - proto_tree_add_text(tree, tvb, offset, NWK_CMD_SECURITY_KEY_LEN, "Security Key: %s", - tvb_get_string_enc(wmem_packet_scope(), tvb, offset, NWK_CMD_SECURITY_KEY_LEN, ENC_ASCII)); + proto_tree_add_item(tree, hf_zbee_nwk_gp_cmd_comm_security_key, tvb, offset, NWK_CMD_SECURITY_KEY_LEN, ENC_ASCII|ENC_NA); offset += NWK_CMD_SECURITY_KEY_LEN; } if (comm_ext_options & ZBEE_NWK_GP_CMD_COMMISSIONING_EXT_OPT_GPD_KEY_ENCR) { @@ -707,14 +720,7 @@ dissect_zbee_nwk_gp_cmd_commissioning(tvbuff_t *tvb, packet_info *pinfo _U_, pro if (comm_options & ZBEE_NWK_GP_CMD_COMMISSIONING_OPT_MANUFACTURER_INFO) { /* Display MS extensions. */ ms_ext_options = tvb_get_guint8(tvb, offset); - if (tree) { - ti = proto_tree_add_text(tree, tvb, offset, 1, "MS Extensions Field: 0x%02x", ms_ext_options); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_cmd_ms_ext); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_ms_ext_mip, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_ms_ext_mmip, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_ms_ext_gclp, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_ms_ext_crp, tvb, offset, 1, ENC_NA); - } + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_gp_cmd_comm_ms_ext, ett_zbee_nwk_cmd_ms_ext, ms_ext, ENC_NA); offset += 1; if (ms_ext_options & ZBEE_NWK_GP_CMD_COMMISSIONING_MS_EXT_MIP) { /* Get Manufacturer ID. */ @@ -755,19 +761,14 @@ static guint dissect_zbee_nwk_gp_cmd_channel_request(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, zbee_nwk_green_power_packet *packet _U_, guint offset) { - proto_item *ti; - proto_tree *field_tree; + static const int * channels[] = { + &hf_zbee_nwk_gp_cmd_channel_request_toggling_behaviour_1st, + &hf_zbee_nwk_gp_cmd_channel_request_toggling_behaviour_2nd, + NULL + }; /* Get Command Options Field, build subtree and display the results. */ - if (tree) { - ti = proto_tree_add_text(tree, tvb, offset, 1, "Channel Toggling Behaviour: 0x%02x", tvb_get_guint8(tvb, - offset)); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_cmd_options); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_channel_request_toggling_behaviour_1st, tvb, offset, 1, - ENC_LITTLE_ENDIAN); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_channel_request_toggling_behaviour_2nd, tvb, offset, 1, - ENC_LITTLE_ENDIAN); - } + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_gp_cmd_channel_request_toggling_behaviour, ett_zbee_nwk_cmd_options, channels, ENC_NA); offset += 1; return offset; } /* dissect_zbee_nwk_gp_cmd_channel_request */ @@ -791,15 +792,14 @@ static guint dissect_zbee_nwk_gp_cmd_channel_configuration(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, zbee_nwk_green_power_packet *packet _U_, guint offset) { - proto_item *ti; - proto_tree *field_tree; + static const int * channels[] = { + &hf_zbee_nwk_gp_cmd_channel_configuration, + NULL + }; /* Get Command Options Field, build subtree and display the results. */ - if (tree) { - ti = proto_tree_add_text(tree, tvb, offset, 1, "Operational Channel: 0x%02x", tvb_get_guint8(tvb, offset)); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_cmd_options); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_channel_configuration, tvb, offset, 1, ENC_LITTLE_ENDIAN); - } + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_gp_cmd_operational_channel, ett_zbee_nwk_cmd_options, channels, ENC_NA); + offset += 1; return offset; } /* dissect_zbee_nwk_gp_cmd_channel_configuration */ @@ -858,22 +858,22 @@ static guint dissect_zbee_nwk_gp_cmd_commissioning_reply(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, zbee_nwk_green_power_packet *packet _U_, guint offset) { - guint8 cr_options = 0; - proto_item *ti = NULL; - proto_tree *field_tree = NULL; + guint8 cr_options; + + static const int * options[] = { + &hf_zbee_nwk_gp_cmd_comm_rep_opt_panid_present, + &hf_zbee_nwk_gp_cmd_comm_rep_opt_sec_key_present, + &hf_zbee_nwk_gp_cmd_comm_rep_opt_key_encr, + &hf_zbee_nwk_gp_cmd_comm_rep_opt_sec_level, + &hf_zbee_nwk_gp_cmd_comm_rep_opt_sec_type, + NULL + }; /* Get Options Field, build subtree and display the results. */ cr_options = tvb_get_guint8(tvb, offset); - if (tree) { - ti = proto_tree_add_text(tree, tvb, offset, 1, "Options Field: 0x%02x", cr_options); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_cmd_options); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_rep_opt_panid_present, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_rep_opt_sec_key_present, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_rep_opt_key_encr, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_rep_opt_sec_level, tvb, offset, 1, ENC_LITTLE_ENDIAN); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_cmd_comm_rep_opt_sec_type, tvb, offset, 1, ENC_LITTLE_ENDIAN); - } + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_gp_cmd_comm_rep_opt, ett_zbee_nwk_cmd_options, options, ENC_NA); offset += 1; + /* Parse and display security Pan ID value. */ if (cr_options & ZBEE_NWK_GP_CMD_COMMISSIONING_REP_OPT_PAN_ID_PRESENT) { proto_tree_add_item(tree, hf_zbee_nwk_gp_cmd_comm_rep_pan_id, tvb, offset, 2, ENC_LITTLE_ENDIAN); @@ -881,8 +881,7 @@ dissect_zbee_nwk_gp_cmd_commissioning_reply(tvbuff_t *tvb, packet_info *pinfo _U } /* Parse and display security key. */ if (cr_options & ZBEE_NWK_GP_CMD_COMMISSIONING_REP_OPT_SEC_KEY_PRESENT) { - proto_tree_add_text(tree, tvb, offset, NWK_CMD_SECURITY_KEY_LEN, "Security Key: %s", - tvb_get_string_enc(wmem_packet_scope(), tvb, offset, NWK_CMD_SECURITY_KEY_LEN, ENC_ASCII)); + proto_tree_add_item(tree, hf_zbee_nwk_gp_cmd_comm_security_key, tvb, offset, NWK_CMD_SECURITY_KEY_LEN, ENC_ASCII|ENC_NA); offset += NWK_CMD_SECURITY_KEY_LEN; } /* Parse and display security MIC. */ @@ -1247,12 +1246,26 @@ dissect_zbee_nwk_gp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d guint8 *dec_buffer; guint8 *enc_buffer; guint8 fcf; - proto_tree *field_tree = NULL; proto_tree *nwk_tree = NULL; proto_item *proto_root = NULL; proto_item *ti = NULL; tvbuff_t *payload_tvb; zbee_nwk_green_power_packet packet; + static const int * fields[] = { + &hf_zbee_nwk_gp_frame_type, + &hf_zbee_nwk_gp_proto_version, + &hf_zbee_nwk_gp_auto_commissioning, + &hf_zbee_nwk_gp_fc_ext, + NULL + }; + static const int * ext_fields[] = { + &hf_zbee_nwk_gp_fc_ext_app_id, + &hf_zbee_nwk_gp_fc_ext_sec_level, + &hf_zbee_nwk_gp_fc_ext_sec_key, + &hf_zbee_nwk_gp_fc_ext_rx_after_tx, + &hf_zbee_nwk_gp_fc_ext_direction, + NULL + }; memset(&packet, 0, sizeof(packet)); /* Add ourself to the protocol column, clear the info column and create the protocol tree. */ @@ -1268,44 +1281,25 @@ dissect_zbee_nwk_gp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d fcf = tvb_get_guint8(tvb, offset); packet.frame_type = zbee_get_bit_field(fcf, ZBEE_NWK_GP_FCF_FRAME_TYPE); packet.nwk_frame_control_extension = zbee_get_bit_field(fcf, ZBEE_NWK_GP_FCF_CONTROL_EXTENSION); + /* Display the FCF. */ - if (tree) { - /* Create a subtree for the FCF. */ - ti = proto_tree_add_text(nwk_tree, tvb, offset, 1, "Frame Control Field: %s (0x%02x)", - val_to_str(packet.frame_type, zbee_nwk_gp_frame_types, "Unknown Frame Type"), fcf); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_fcf); - proto_tree_add_uint(field_tree, hf_zbee_nwk_gp_frame_type, tvb, offset, 1, fcf & ZBEE_NWK_GP_FCF_FRAME_TYPE); - proto_tree_add_uint(field_tree, hf_zbee_nwk_gp_proto_version, tvb, offset, 1, fcf & ZBEE_NWK_GP_FCF_VERSION); - proto_tree_add_boolean(field_tree, hf_zbee_nwk_gp_auto_commissioning, tvb, offset, 1, fcf & - ZBEE_NWK_GP_FCF_AUTO_COMMISSIONING); - proto_tree_add_boolean(field_tree, hf_zbee_nwk_gp_fc_ext, tvb, offset, 1, fcf & - ZBEE_NWK_GP_FCF_CONTROL_EXTENSION); - } + ti = proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_gp_fcf, ett_zbee_nwk_fcf, fields, ENC_NA); + proto_item_append_text(ti, " %s", val_to_str(packet.frame_type, zbee_nwk_gp_frame_types, "Unknown Frame Type")); offset += 1; + /* Add the frame type to the info column and protocol root. */ - if (tree) { - proto_item_append_text(proto_root, " %s", val_to_str(packet.frame_type, zbee_nwk_gp_frame_types, - "Unknown type")); - } - col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(packet.frame_type, zbee_nwk_gp_frame_types, - "Reserved frame type")); + proto_item_append_text(proto_root, " %s", val_to_str(packet.frame_type, zbee_nwk_gp_frame_types, "Unknown type")); + col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(packet.frame_type, zbee_nwk_gp_frame_types, "Reserved frame type")); + if (packet.nwk_frame_control_extension) { /* Display ext FCF. */ fcf = tvb_get_guint8(tvb, offset); packet.application_id = zbee_get_bit_field(fcf, ZBEE_NWK_GP_FCF_EXT_APP_ID); packet.security_level = zbee_get_bit_field(fcf, ZBEE_NWK_GP_FCF_EXT_SECURITY_LEVEL); packet.direction = zbee_get_bit_field(fcf, ZBEE_NWK_GP_FCF_EXT_DIRECTION); + /* Create a subtree for the extended FCF. */ - if (tree) { - ti = proto_tree_add_text(nwk_tree, tvb, offset, 1, "Extended NWK Frame Control Field"); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_fcf_ext); - /* Add the fields. */ - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_fc_ext_app_id, tvb, offset, 1, ENC_LITTLE_ENDIAN); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_fc_ext_sec_level, tvb, offset, 1, ENC_LITTLE_ENDIAN); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_fc_ext_sec_key, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_fc_ext_rx_after_tx, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_gp_fc_ext_direction, tvb, offset, 1, ENC_LITTLE_ENDIAN); - } + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_gp_fc_ext_field, ett_zbee_nwk_fcf_ext, ext_fields, ENC_NA); offset += 1; } if ((packet.frame_type == ZBEE_NWK_GP_FCF_DATA && !packet.nwk_frame_control_extension) || (packet.frame_type == @@ -1493,6 +1487,10 @@ proto_register_zbee_nwk_gp(void) { "NWK Frame Extension", "zbee_nwk_gp.fc_extension", FT_BOOLEAN, 8, NULL, ZBEE_NWK_GP_FCF_CONTROL_EXTENSION, NULL, HFILL }}, + { &hf_zbee_nwk_gp_fcf, + { "Frame Control Field", "zbee_nwk_gp.fcf", FT_UINT8, BASE_HEX, NULL, + 0x0, NULL, HFILL }}, + { &hf_zbee_nwk_gp_frame_type, { "Frame Type", "zbee_nwk_gp.frame_type", FT_UINT8, BASE_HEX, VALS(zbee_nwk_gp_frame_types), ZBEE_NWK_GP_FCF_FRAME_TYPE, NULL, HFILL }}, @@ -1501,6 +1499,10 @@ proto_register_zbee_nwk_gp(void) { "Protocol Version", "zbee_nwk_gp.proto_version", FT_UINT8, BASE_DEC, NULL, ZBEE_NWK_GP_FCF_VERSION, NULL, HFILL }}, + { &hf_zbee_nwk_gp_fc_ext_field, + { "Extended NWK Frame Control Field", "zbee_nwk_gp.fc_ext", FT_UINT8, BASE_HEX, NULL, + 0x0, NULL, HFILL }}, + { &hf_zbee_nwk_gp_fc_ext_app_id, { "Application ID", "zbee_nwk_gp.fc_ext_app_id", FT_UINT8, BASE_HEX, VALS(zbee_nwk_gp_app_id_names), ZBEE_NWK_GP_FCF_EXT_APP_ID, NULL, HFILL }}, @@ -1564,6 +1566,9 @@ proto_register_zbee_nwk_gp(void) { "Security Level Capabilities", "zbee_nwk_gp.cmd.comm.ext_opt.seclevel_cap", FT_UINT8, BASE_HEX, NULL, ZBEE_NWK_GP_CMD_COMMISSIONING_EXT_OPT_SEC_LEVEL_CAP, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_comm_security_key, + { "Security Key", "zbee_nwk_gp.cmd.comm.security_key", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_comm_gpd_sec_key_mic, { "GPD Key MIC", "zbee_nwk_gp.cmd.comm.gpd_key_mic", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }}, @@ -1571,6 +1576,10 @@ proto_register_zbee_nwk_gp(void) { "Extended Option Field", "zbee_nwk_gp.cmd.comm.opt.ext_opt_field", FT_BOOLEAN, 8, NULL, ZBEE_NWK_GP_CMD_COMMISSIONING_OPT_EXT_OPTIONS, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_comm_opt, + { "Options Field", "zbee_nwk_gp.cmd.comm.opt", FT_UINT8, BASE_HEX, NULL, + 0x0, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_comm_opt_fixed_location, { "Fixed Location", "zbee_nwk_gp.cmd.comm.opt.fixed_location", FT_BOOLEAN, 8, NULL, ZBEE_NWK_GP_CMD_COMMISSIONING_OPT_FIXED_LOCATION, NULL, HFILL }}, @@ -1595,6 +1604,10 @@ proto_register_zbee_nwk_gp(void) { "GP Security Key Request", "zbee_nwk_gp.cmd.comm.opt.seq_key_req", FT_BOOLEAN, 8, NULL, ZBEE_NWK_GP_CMD_COMMISSIONING_OPT_GP_SEC_KEY_REQ, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_comm_ext_opt, + { "Extended Options Field", "zbee_nwk_gp.cmd.comm.ext_opt", FT_UINT8, BASE_HEX, NULL, + 0x0, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_comm_ext_opt_outgoing_counter, { "GPD Outgoing present", "zbee_nwk_gp.cmd.comm.ext_opt.outgoing_counter", FT_BOOLEAN, 8, NULL, ZBEE_NWK_GP_CMD_COMMISSIONING_EXT_OPT_OUT_COUNTER, NULL, HFILL }}, @@ -1615,6 +1628,10 @@ proto_register_zbee_nwk_gp(void) { "GP commands list present", "zbee_nwk_gp.cmd.comm.ms_ext.gclp", FT_BOOLEAN, 8, NULL, ZBEE_NWK_GP_CMD_COMMISSIONING_MS_EXT_GCLP , NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_comm_ms_ext, + { "MS Extensions Field", "zbee_nwk_gp.cmd.comm.ms_ext", FT_UINT8, BASE_HEX, NULL, + 0x0, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_comm_ms_ext_mip, { "Manufacturer ID present", "zbee_nwk_gp.cmd.comm.ms_ext.mip", FT_BOOLEAN, 8, NULL, ZBEE_NWK_GP_CMD_COMMISSIONING_MS_EXT_MIP , NULL, HFILL }}, @@ -1627,6 +1644,10 @@ proto_register_zbee_nwk_gp(void) { "GPD Key Encryption", "zbee_nwk_gp.cmd.comm_reply.opt.sec_key_encr", FT_BOOLEAN, 8, NULL, ZBEE_NWK_GP_CMD_COMMISSIONING_REP_OPT_KEY_ENCR, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_comm_rep_opt, + { "Options Field", "zbee_nwk_gp.cmd.comm_reply.opt", FT_UINT8, BASE_HEX, NULL, + 0x0, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_comm_rep_opt_panid_present, { "PANID Present", "zbee_nwk_gp.cmd.comm_reply.opt.pan_id_present", FT_BOOLEAN, 8, NULL, ZBEE_NWK_GP_CMD_COMMISSIONING_REP_OPT_PAN_ID_PRESENT, NULL, HFILL }}, @@ -1650,6 +1671,10 @@ proto_register_zbee_nwk_gp(void) { "ZigBee Cluster ID", "zbee_nwk_gp.cmd.comm.attr_report", FT_UINT16, BASE_HEX, VALS(zbee_aps_cid_names), 0x0, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_channel_request_toggling_behaviour, + { "Channel Toggling Behaviour", "zbee_nwk_gp.cmd.ch_req", FT_UINT8, BASE_HEX, NULL, + 0x0, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_channel_request_toggling_behaviour_1st, { "Rx channel in the next attempt", "zbee_nwk_gp.cmd.ch_req.1st", FT_UINT8, BASE_HEX, NULL, ZBEE_NWK_GP_CMD_CHANNEL_REQUEST_1ST, NULL, HFILL }}, @@ -1658,6 +1683,10 @@ proto_register_zbee_nwk_gp(void) { "Rx channel in the second next attempt", "zbee_nwk_gp.ch_req.2nd", FT_UINT8, BASE_HEX, NULL, ZBEE_NWK_GP_CMD_CHANNEL_REQUEST_2ND, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_operational_channel, + { "Operational Channel", "zbee_nwk_gp.cmd.configuration_ch", FT_UINT8, BASE_HEX, NULL, + 0x0, NULL, HFILL }}, + { &hf_zbee_nwk_gp_cmd_channel_configuration, { "Operation channel", "zbee_nwk_gp.cmd.configuration_ch.operation_ch", FT_UINT8, BASE_HEX, NULL, ZBEE_NWK_GP_CMD_CHANNEL_CONFIGURATION_OPERATION_CH, NULL, HFILL }}, diff --git a/epan/dissectors/packet-zbee-nwk.c b/epan/dissectors/packet-zbee-nwk.c index 35eaa4d907..9053efd02f 100644 --- a/epan/dissectors/packet-zbee-nwk.c +++ b/epan/dissectors/packet-zbee-nwk.c @@ -69,6 +69,7 @@ void proto_reg_handoff_zbee_nwk(void); static int proto_zbee_nwk = -1; static int proto_zbee_beacon = -1; static int proto_zbip_beacon = -1; +static int hf_zbee_nwk_fcf = -1; static int hf_zbee_nwk_frame_type = -1; static int hf_zbee_nwk_proto_version = -1; static int hf_zbee_nwk_discover_route = -1; @@ -81,6 +82,7 @@ static int hf_zbee_nwk_dst = -1; static int hf_zbee_nwk_src = -1; static int hf_zbee_nwk_radius = -1; static int hf_zbee_nwk_seqno = -1; +static int hf_zbee_nwk_mcast = -1; static int hf_zbee_nwk_mcast_mode = -1; static int hf_zbee_nwk_mcast_radius = -1; static int hf_zbee_nwk_mcast_max_radius = -1; @@ -89,6 +91,7 @@ static int hf_zbee_nwk_src64 = -1; static int hf_zbee_nwk_src64_origin = -1; static int hf_zbee_nwk_relay_count = -1; static int hf_zbee_nwk_relay_index = -1; +static int hf_zbee_nwk_relay = -1; static int hf_zbee_nwk_cmd_id = -1; static int hf_zbee_nwk_cmd_addr = -1; @@ -100,6 +103,7 @@ static int hf_zbee_nwk_cmd_route_dest_ext = -1; static int hf_zbee_nwk_cmd_route_orig_ext = -1; static int hf_zbee_nwk_cmd_route_resp_ext = -1; static int hf_zbee_nwk_cmd_route_cost = -1; +static int hf_zbee_nwk_cmd_route_options = -1; static int hf_zbee_nwk_cmd_route_opt_repair = -1; static int hf_zbee_nwk_cmd_route_opt_multicast = -1; static int hf_zbee_nwk_cmd_route_opt_dest_ext = -1; @@ -111,6 +115,7 @@ static int hf_zbee_nwk_cmd_leave_rejoin = -1; static int hf_zbee_nwk_cmd_leave_request = -1; static int hf_zbee_nwk_cmd_leave_children = -1; static int hf_zbee_nwk_cmd_relay_count = -1; +static int hf_zbee_nwk_cmd_relay_device = -1; static int hf_zbee_nwk_cmd_cinfo = -1; static int hf_zbee_nwk_cmd_cinfo_alt_coord = -1; static int hf_zbee_nwk_cmd_cinfo_type = -1; @@ -122,11 +127,15 @@ static int hf_zbee_nwk_cmd_rejoin_status = -1; static int hf_zbee_nwk_cmd_link_last = -1; static int hf_zbee_nwk_cmd_link_first = -1; static int hf_zbee_nwk_cmd_link_count = -1; +static int hf_zbee_nwk_cmd_link_address = -1; +static int hf_zbee_nwk_cmd_link_incoming_cost = -1; +static int hf_zbee_nwk_cmd_link_outgoing_cost = -1; static int hf_zbee_nwk_cmd_report_type = -1; static int hf_zbee_nwk_cmd_report_count = -1; static int hf_zbee_nwk_cmd_update_type = -1; static int hf_zbee_nwk_cmd_update_count = -1; static int hf_zbee_nwk_cmd_update_id = -1; +static int hf_zbee_nwk_panid = -1; static int hf_zbee_nwk_cmd_epid = -1; /* ZigBee Beacons */ @@ -155,6 +164,7 @@ static gint ett_zbee_nwk_route = -1; static gint ett_zbee_nwk_cmd = -1; static gint ett_zbee_nwk_cmd_options = -1; static gint ett_zbee_nwk_cmd_cinfo = -1; +static gint ett_zbee_nwk_cmd_link = -1; static expert_field ei_zbee_nwk_missing_payload = EI_INIT; @@ -356,7 +366,7 @@ dissect_zbee_nwk_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void ieee802154_packet *ieee_packet; guint offset = 0; - static gchar src_addr[32], dst_addr[32]; /* has to be static due to SET_ADDRESS */ + gchar *src_addr, *dst_addr; guint16 fcf; @@ -367,6 +377,26 @@ dissect_zbee_nwk_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void zbee_nwk_hints_t *nwk_hints; gboolean unicast_src; + static const int * fcf_flags_2007[] = { + &hf_zbee_nwk_frame_type, + &hf_zbee_nwk_proto_version, + &hf_zbee_nwk_discover_route, + &hf_zbee_nwk_multicast, + &hf_zbee_nwk_security, + &hf_zbee_nwk_source_route, + &hf_zbee_nwk_ext_dst, + &hf_zbee_nwk_ext_src, + NULL + }; + + static const int * fcf_flags[] = { + &hf_zbee_nwk_frame_type, + &hf_zbee_nwk_proto_version, + &hf_zbee_nwk_discover_route, + &hf_zbee_nwk_security, + NULL + }; + /* Reject the packet if data is NULL */ if (data == NULL) return 0; @@ -405,32 +435,16 @@ dissect_zbee_nwk_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void packet.ext_src = zbee_get_bit_field(fcf, ZBEE_NWK_FCF_EXT_SOURCE); /* Display the FCF. */ - if (tree) { - /* Create a subtree for the FCF. */ - ti = proto_tree_add_text(nwk_tree, tvb, offset, 2, "Frame Control Field: %s (0x%04x)", - val_to_str_const(packet.type, zbee_nwk_frame_types, "Unknown"), fcf); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_fcf); - proto_tree_add_item(field_tree, hf_zbee_nwk_frame_type, tvb, offset, 2, ENC_LITTLE_ENDIAN); - - /* Add the rest of the fcf fields to the subtree */ - proto_tree_add_item(field_tree, hf_zbee_nwk_proto_version, tvb, offset, 2, ENC_LITTLE_ENDIAN); - proto_tree_add_item(field_tree, hf_zbee_nwk_discover_route, tvb, offset, 2, ENC_LITTLE_ENDIAN); - if (packet.version >= ZBEE_VERSION_2007) { - proto_tree_add_item(field_tree, hf_zbee_nwk_multicast, tvb, offset, 2, ENC_LITTLE_ENDIAN); - } - proto_tree_add_item(field_tree, hf_zbee_nwk_security, tvb, offset, 2, ENC_LITTLE_ENDIAN); - if (packet.version >= ZBEE_VERSION_2007) { - proto_tree_add_item(field_tree, hf_zbee_nwk_source_route, tvb, offset, 2, ENC_LITTLE_ENDIAN); - proto_tree_add_item(field_tree, hf_zbee_nwk_ext_dst, tvb, offset, 2, ENC_LITTLE_ENDIAN); - proto_tree_add_item(field_tree, hf_zbee_nwk_ext_src, tvb, offset, 2, ENC_LITTLE_ENDIAN); - } + if (packet.version >= ZBEE_VERSION_2007) { + ti = proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_fcf, ett_zbee_nwk_fcf, fcf_flags_2007, ENC_LITTLE_ENDIAN); + } else { + ti = proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_fcf, ett_zbee_nwk_fcf, fcf_flags, ENC_LITTLE_ENDIAN); } + proto_item_append_text(ti, " %s", val_to_str_const(packet.type, zbee_nwk_frame_types, "Unknown")); offset += 2; /* Add the frame type to the info column and protocol root. */ - if (tree) { - proto_item_append_text(proto_root, " %s", val_to_str_const(packet.type, zbee_nwk_frame_types, "Unknown Type")); - } + proto_item_append_text(proto_root, " %s", val_to_str_const(packet.type, zbee_nwk_frame_types, "Unknown Type")); col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(packet.type, zbee_nwk_frame_types, "Reserved Frame Type")); /* Get the destination address. */ @@ -443,27 +457,24 @@ dissect_zbee_nwk_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void if ( (packet.dst == ZBEE_BCAST_ALL) || (packet.dst == ZBEE_BCAST_ACTIVE) || (packet.dst == ZBEE_BCAST_ROUTERS)){ - g_snprintf(dst_addr, 32, "Broadcast"); + dst_addr = wmem_strdup_printf(pinfo->pool, "Broadcast"); } else { - g_snprintf(dst_addr, 32, "0x%04x", packet.dst); + dst_addr = wmem_strdup_printf(pinfo->pool, "0x%04x", packet.dst); } SET_ADDRESS(&pinfo->dst, AT_STRINGZ, (int)strlen(dst_addr)+1, dst_addr); SET_ADDRESS(&pinfo->net_dst, AT_STRINGZ, (int)strlen(dst_addr)+1, dst_addr); - if (tree) { - proto_item_append_text(proto_root, ", Dst: %s", dst_addr); - } + proto_item_append_text(proto_root, ", Dst: %s", dst_addr); col_append_fstr(pinfo->cinfo, COL_INFO, ", Dst: %s", dst_addr); /* Get the short nwk source address and pass it to upper layers */ packet.src = tvb_get_letohs(tvb, offset); - if (nwk_hints) nwk_hints->src = packet.src; - if (tree) { - proto_tree_add_uint(nwk_tree, hf_zbee_nwk_src, tvb, offset, 2, packet.src); - } + if (nwk_hints) + nwk_hints->src = packet.src; + proto_tree_add_uint(nwk_tree, hf_zbee_nwk_src, tvb, offset, 2, packet.src); offset += 2; /* Display the source address. */ @@ -471,42 +482,34 @@ dissect_zbee_nwk_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void || (packet.src == ZBEE_BCAST_ACTIVE) || (packet.src == ZBEE_BCAST_ROUTERS)){ /* Source Broadcast doesn't make much sense. */ - g_snprintf(src_addr, 32, "Unexpected Source Broadcast"); + src_addr = wmem_strdup_printf(pinfo->pool, "Unexpected Source Broadcast"); unicast_src = FALSE; } else { - g_snprintf(src_addr, 32, "0x%04x", packet.src); + src_addr = wmem_strdup_printf(pinfo->pool, "0x%04x", packet.src); unicast_src = TRUE; } SET_ADDRESS(&pinfo->src, AT_STRINGZ, (int)strlen(src_addr)+1, src_addr); SET_ADDRESS(&pinfo->net_src, AT_STRINGZ, (int)strlen(src_addr)+1, src_addr); - if (tree) { - proto_item_append_text(proto_root, ", Src: %s", src_addr); - } + proto_item_append_text(proto_root, ", Src: %s", src_addr); col_append_fstr(pinfo->cinfo, COL_INFO, ", Src: %s", src_addr); /* Get and display the radius. */ packet.radius = tvb_get_guint8(tvb, offset); - if (tree) { - proto_tree_add_uint(nwk_tree, hf_zbee_nwk_radius, tvb, offset, 1, packet.radius); - } + proto_tree_add_uint(nwk_tree, hf_zbee_nwk_radius, tvb, offset, 1, packet.radius); offset += 1; /* Get and display the sequence number. */ packet.seqno = tvb_get_guint8(tvb, offset); - if (tree) { - proto_tree_add_uint(nwk_tree, hf_zbee_nwk_seqno, tvb, offset, 1, packet.seqno); - } + proto_tree_add_uint(nwk_tree, hf_zbee_nwk_seqno, tvb, offset, 1, packet.seqno); offset += 1; /* Add the extended destination address (ZigBee 2006 and later). */ if ((packet.version >= ZBEE_VERSION_2007) && packet.ext_dst) { packet.dst64 = tvb_get_letoh64(tvb, offset); - if (tree) { - proto_tree_add_item(nwk_tree, hf_zbee_nwk_dst64, tvb, offset, 8, ENC_LITTLE_ENDIAN); - } + proto_tree_add_item(nwk_tree, hf_zbee_nwk_dst64, tvb, offset, 8, ENC_LITTLE_ENDIAN); offset += 8; } @@ -559,7 +562,7 @@ dissect_zbee_nwk_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void nwk_hints->map_rec->start_fnum); } else { - ti = proto_tree_add_text(nwk_tree, tvb, 0, 0, "Origin: Pre-configured"); + ti = proto_tree_add_uint_format_value(nwk_tree, hf_zbee_nwk_src64_origin, tvb, 0, 0, 0, "Pre-configured"); } PROTO_ITEM_SET_GENERATED(ti); } @@ -584,26 +587,25 @@ dissect_zbee_nwk_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void /* Add multicast control field (ZigBee 2006 and later). */ if ((packet.version >= ZBEE_VERSION_2007) && packet.multicast) { + static const int * multicast_flags[] = { + &hf_zbee_nwk_mcast_mode, + &hf_zbee_nwk_mcast_radius, + &hf_zbee_nwk_mcast_max_radius, + NULL + }; + guint8 mcast_control = tvb_get_guint8(tvb, offset); packet.mcast_mode = zbee_get_bit_field(mcast_control, ZBEE_NWK_MCAST_MODE); packet.mcast_radius = zbee_get_bit_field(mcast_control, ZBEE_NWK_MCAST_RADIUS); packet.mcast_max_radius = zbee_get_bit_field(mcast_control, ZBEE_NWK_MCAST_MAX_RADIUS); - if (tree) { - /* Create a subtree for the multicast control field. */ - ti = proto_tree_add_text(nwk_tree, tvb, offset, 1, "Multicast Control Field"); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_mcast); - /* Add the fields. */ - proto_tree_add_item(field_tree, hf_zbee_nwk_mcast_mode, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_mcast_radius, tvb, offset, 1, ENC_NA); - proto_tree_add_item(field_tree, hf_zbee_nwk_mcast_max_radius, tvb, offset, 1, ENC_NA); - } + + proto_tree_add_bitmask(nwk_tree, tvb, offset, hf_zbee_nwk_mcast, ett_zbee_nwk_mcast, multicast_flags, ENC_NA); offset += 1; } /* Add the Source Route field. (ZigBee 2006 and later). */ if ((packet.version >= ZBEE_VERSION_2007) && packet.route) { guint8 relay_count; - guint8 relay_index; guint16 relay_addr; guint i; @@ -612,29 +614,21 @@ dissect_zbee_nwk_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void /* Get and display the relay count. */ relay_count = tvb_get_guint8(tvb, offset); - if (tree) { - proto_tree_add_uint(field_tree, hf_zbee_nwk_relay_count, tvb, offset, 1, relay_count); - proto_item_append_text(ti, ", Length: %d", relay_count); - } + proto_tree_add_uint(field_tree, hf_zbee_nwk_relay_count, tvb, offset, 1, relay_count); + proto_item_append_text(ti, ", Length: %d", relay_count); offset += 1; - if (tree) { - /* Correct the length of the source route fields. */ - proto_item_set_len(ti, 1 + relay_count*2); - } + /* Correct the length of the source route fields. */ + proto_item_set_len(ti, 1 + relay_count*2); /* Get and display the relay index. */ - relay_index = tvb_get_guint8(tvb, offset); - proto_tree_add_uint(field_tree, hf_zbee_nwk_relay_index, tvb, offset, 1, relay_index); - + proto_tree_add_item(field_tree, hf_zbee_nwk_relay_index, tvb, offset, 1, ENC_NA); offset += 1; /* Get and display the relay list. */ for (i=0; iversion >= ZBEE_VERSION_2007) { - proto_tree_add_boolean(field_tree, hf_zbee_nwk_cmd_route_opt_multicast, tvb, offset, - 1, route_options & ZBEE_NWK_CMD_ROUTE_OPTION_MCAST); - proto_tree_add_boolean(field_tree, hf_zbee_nwk_cmd_route_opt_dest_ext, tvb, offset, - 1, route_options & ZBEE_NWK_CMD_ROUTE_OPTION_DEST_EXT); - proto_tree_add_uint(field_tree, hf_zbee_nwk_cmd_route_opt_many_to_one, tvb, offset, - 1, route_options & ZBEE_NWK_CMD_ROUTE_OPTION_MANY_MASK); - } - else { - proto_tree_add_boolean(tree, hf_zbee_nwk_cmd_route_opt_repair, tvb, offset, 1, - route_options & ZBEE_NWK_CMD_ROUTE_OPTION_REPAIR); - } + if (packet->version >= ZBEE_VERSION_2007) { + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_cmd_route_options, ett_zbee_nwk_cmd_options, nwk_route_command_options_2007, ENC_NA); + } else { + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_cmd_route_options, ett_zbee_nwk_cmd_options, nwk_route_command_options, ENC_NA); } offset += 1; /* Get and display the route request ID. */ - route_id = tvb_get_guint8(tvb, offset); - if (tree) { - proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_id, tvb, offset, 1, route_id); - } + proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_id, tvb, offset, 1, ENC_NA); offset += 1; /* Get and display the destination address. */ dest_addr = tvb_get_letohs(tvb, offset); - if (tree) { - proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_dest, tvb, offset, 2, dest_addr); - } + proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_dest, tvb, offset, 2, dest_addr); offset += 2; /* Get and display the path cost. */ - path_cost = tvb_get_guint8(tvb, offset); - if (tree) { - proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_cost, tvb, offset, 1, path_cost); - } + proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_cost, tvb, offset, 1, ENC_NA); offset += 1; /* Get and display the extended destination address. */ if (route_options & ZBEE_NWK_CMD_ROUTE_OPTION_DEST_EXT) { - if (tree) { - proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_dest_ext, tvb, offset, 8, ENC_LITTLE_ENDIAN); - } + proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_dest_ext, tvb, offset, 8, ENC_LITTLE_ENDIAN); offset += 8; } @@ -918,74 +896,58 @@ dissect_zbee_nwk_route_req(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, static guint dissect_zbee_nwk_route_rep(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset, guint8 version) { - proto_tree *field_tree; - proto_item *ti; - guint8 route_options; - guint8 route_id; guint16 orig_addr; guint16 resp_addr; - guint8 path_cost; + + static const int * nwk_route_command_options_2007[] = { + &hf_zbee_nwk_cmd_route_opt_multicast, + &hf_zbee_nwk_cmd_route_opt_resp_ext, + &hf_zbee_nwk_cmd_route_opt_orig_ext, + NULL + }; + + static const int * nwk_route_command_options[] = { + &hf_zbee_nwk_cmd_route_opt_repair, + NULL + }; /* Get and display the route options field. */ route_options = tvb_get_guint8(tvb, offset); - if (tree) { - /* Create a subtree for the command options. */ - ti = proto_tree_add_text(tree, tvb, offset, 1, "Command Options (0x%02x)", route_options); - field_tree = proto_item_add_subtree(ti, ett_zbee_nwk_cmd_options); - - if (version >= ZBEE_VERSION_2007) { - proto_tree_add_boolean(field_tree, hf_zbee_nwk_cmd_route_opt_multicast, tvb, offset, 1, route_options & ZBEE_NWK_CMD_ROUTE_OPTION_MCAST); - proto_tree_add_boolean(field_tree, hf_zbee_nwk_cmd_route_opt_resp_ext, tvb, offset, 1, route_options & ZBEE_NWK_CMD_ROUTE_OPTION_RESP_EXT); - proto_tree_add_boolean(field_tree, hf_zbee_nwk_cmd_route_opt_orig_ext, tvb, offset, 1, route_options & ZBEE_NWK_CMD_ROUTE_OPTION_ORIG_EXT); - } - else { - proto_tree_add_boolean(tree, hf_zbee_nwk_cmd_route_opt_repair, tvb, offset, 1, route_options & ZBEE_NWK_CMD_ROUTE_OPTION_REPAIR); - } + if (version >= ZBEE_VERSION_2007) { + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_cmd_route_options, ett_zbee_nwk_cmd_options, nwk_route_command_options_2007, ENC_NA); + } else { + proto_tree_add_bitmask(tree, tvb, offset, hf_zbee_nwk_cmd_route_options, ett_zbee_nwk_cmd_options, nwk_route_command_options, ENC_NA); } offset += 1; /* Get and display the route request ID. */ - route_id = tvb_get_guint8(tvb, offset); - if (tree) { - proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_id, tvb, offset, 1, route_id); - } + proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_id, tvb, offset, 1, ENC_NA); offset += 1; /* Get and display the originator address. */ orig_addr = tvb_get_letohs(tvb, offset); - if (tree) { - proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_orig, tvb, offset, 2, orig_addr); - } + proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_orig, tvb, offset, 2, orig_addr); offset += 2; /* Get and display the responder address. */ resp_addr = tvb_get_letohs(tvb, offset); - if (tree) { - proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_resp, tvb, offset, 2, resp_addr); - } + proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_resp, tvb, offset, 2, resp_addr); offset += 2; /* Get and display the path cost. */ - path_cost = tvb_get_guint8(tvb, offset); - if (tree) { - proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_cost, tvb, offset, 1, path_cost); - } + proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_cost, tvb, offset, 1, ENC_NA); offset += 1; /* Get and display the originator extended address. */ if (route_options & ZBEE_NWK_CMD_ROUTE_OPTION_ORIG_EXT) { - if (tree) { - proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_orig_ext, tvb, offset, 8, ENC_LITTLE_ENDIAN); - } + proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_orig_ext, tvb, offset, 8, ENC_LITTLE_ENDIAN); offset += 8; } /* Get and display the responder extended address. */ if (route_options & ZBEE_NWK_CMD_ROUTE_OPTION_RESP_EXT) { - if (tree) { - proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_resp_ext, tvb, offset, 8, ENC_LITTLE_ENDIAN); - } + proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_resp_ext, tvb, offset, 8, ENC_LITTLE_ENDIAN); offset += 8; } @@ -1103,9 +1065,8 @@ dissect_zbee_nwk_route_rec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, /* Get and display the relay addresses. */ for (i=0; i>4); - } + subtree = proto_tree_add_subtree_format(tree, tvb, offset, 3, ett_zbee_nwk_cmd_link, NULL, "Link %d", i+1); + proto_tree_add_item(subtree, hf_zbee_nwk_cmd_link_address, tvb, offset, 2, ENC_LITTLE_ENDIAN); + proto_tree_add_item(subtree, hf_zbee_nwk_cmd_link_incoming_cost, tvb, offset+2, 1, ENC_NA); + proto_tree_add_item(subtree, hf_zbee_nwk_cmd_link_outgoing_cost, tvb, offset+2, 1, ENC_NA); offset += (2+1); } /* for */ @@ -1291,14 +1242,10 @@ dissect_zbee_nwk_report(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gui offset += 8; if (report_type == ZBEE_NWK_CMD_NWK_REPORT_ID_PAN_CONFLICT) { - guint16 panId; /* Report information contains a list of PANS with range of the sender. */ for (i=0; i= ZBEE_VERSION_2007) { - cluster = tvb_get_letohs(tvb, *offset + len); - len += (int)sizeof(guint16); + proto_tree_add_item(bind_tree, hf_zbee_zdp_cluster, tvb, *offset + len, 2, ENC_LITTLE_ENDIAN); + len += 2; } else { - cluster = tvb_get_guint8(tvb, *offset + len); - len += (int)sizeof(guint8); + proto_tree_add_item(bind_tree, hf_zbee_zdp_cluster, tvb, *offset + len, 1, ENC_LITTLE_ENDIAN); + len += 1; } - if (tree) proto_item_append_text(ti, ", Cluster: %d", cluster); /* Get the destination address mode. */ if (version >= ZBEE_VERSION_2007) { mode = tvb_get_guint8(tvb, *offset + len); - len += (int)sizeof(guint8); + len += 1; } else { /* Mode field doesn't exist and always uses unicast in 2003 & earlier. */ @@ -96,26 +89,17 @@ zdp_parse_bind_table_entry(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint /* Add the destination address. */ if (mode == ZBEE_ZDP_ADDR_MODE_GROUP) { - dst = tvb_get_letohs(tvb, *offset + len); - if (tree) proto_item_append_text(ti, ", Dst: 0x%04x}", dst); - len += (int)sizeof(guint16); + proto_tree_add_item(bind_tree, hf_zbee_zdp_bind_dst, tvb, *offset + len, 2, ENC_LITTLE_ENDIAN); + len += 2; } else if (mode == ZBEE_ZDP_ADDR_MODE_UNICAST) { - dst64 = tvb_get_letoh64(tvb, *offset + len); - if (tree) proto_item_append_text(ti, ", Dst: %s", ep_eui64_to_display(dst64)); - len += (int)sizeof(guint64); - - dst_ep = tvb_get_guint8(tvb, *offset + len); - if (tree) proto_item_append_text(ti, ", Dst Endpoint: %d}", dst_ep); - len += (int)sizeof(guint8); - } - else { - if (tree) proto_item_append_text(ti, "}"); + proto_tree_add_item(bind_tree, hf_zbee_zdp_bind_dst64, tvb, *offset + len, 8, ENC_LITTLE_ENDIAN); + len += 8; + proto_tree_add_item(bind_tree, hf_zbee_zdp_bind_dst_ep, tvb, *offset + len, 1, ENC_LITTLE_ENDIAN); + len += 1; } - if (tree) { - proto_item_set_len(ti, len); - } + proto_item_set_len(ti, len); *offset += len; } /* zdp_parse_bind_table_entry */ @@ -242,7 +226,7 @@ dissect_zbee_zdp_req_bind(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, g zbee_append_info(tree, pinfo, ", Dst: 0x%04x", dst); } else { - zbee_append_info(tree, pinfo, ", Dst: %s", eui64_to_str(dst64)); + zbee_append_info(tree, pinfo, ", Dst: %s", ep_eui64_to_display(dst64)); } /* Dump any leftover bytes. */ @@ -308,7 +292,7 @@ dissect_zbee_zdp_req_unbind(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, zbee_append_info(tree, pinfo, ", Dst: 0x%04x", dst); } else { - zbee_append_info(tree, pinfo, ", Dst: %s", eui64_to_str(dst64)); + zbee_append_info(tree, pinfo, ", Dst: %s", ep_eui64_to_display(dst64)); } /* Dump any leftover bytes. */ diff --git a/epan/dissectors/packet-zbee-zdp-management.c b/epan/dissectors/packet-zbee-zdp-management.c index 3bf1d00e8d..c4d9ae7c32 100644 --- a/epan/dissectors/packet-zbee-zdp-management.c +++ b/epan/dissectors/packet-zbee-zdp-management.c @@ -51,56 +51,42 @@ static void zdp_parse_nwk_desc(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint8 version) { - proto_item *ti = NULL; - guint len = 0; + proto_tree *network_tree; + proto_item *ti; - guint64 ext_pan; - guint16 pan; - guint8 channel; - guint8 profile; - guint8 profile_version; guint8 beacon; - guint8 superframe; - gboolean permit; if (version >= ZBEE_VERSION_2007) { + network_tree = proto_tree_add_subtree(tree, tvb, *offset, 12, ett_zbee_zdp_nwk_desc, NULL, "Network descriptor"); /* Extended PAN Identifiers are used in ZigBee 2006 & later. */ - ext_pan = tvb_get_letoh64(tvb, *offset + len); - if (tree) ti = proto_tree_add_text(tree, tvb, *offset, 0, "{Pan: %s", eui64_to_str(ext_pan)); - len += 8; + proto_tree_add_item(network_tree, hf_zbee_zdp_pan_eui64, tvb, *offset, 8, ENC_LITTLE_ENDIAN); + *offset += 8; } else { + network_tree = proto_tree_add_subtree(tree, tvb, *offset, 6, ett_zbee_zdp_nwk_desc, NULL, "Network descriptor"); /* Short PAN Identifiers are used in ZigBee 2003 and earlier. */ - pan = tvb_get_letohs(tvb, *offset + len); - if (tree) ti = proto_tree_add_text(tree, tvb, *offset, 0, "{Pan: 0x%04x", pan); - len += 2; + proto_tree_add_item(network_tree, hf_zbee_zdp_pan_uint, tvb, *offset, 2, ENC_LITTLE_ENDIAN); + *offset += 2; } - channel = tvb_get_guint8(tvb, *offset + len); - if (tree) proto_item_append_text(ti, ", Channel: %d", channel); - len += 1; + proto_tree_add_item(network_tree, hf_zbee_zdp_channel, tvb, *offset, 1, ENC_LITTLE_ENDIAN); + *offset += 1; - profile = (tvb_get_guint8(tvb, *offset + len) & 0x0f) >> 0; - profile_version = (tvb_get_guint8(tvb, *offset + len) & 0xf0) >> 4; - if (tree) proto_item_append_text(ti, ", Profile: 0x%01x, Version: %d", profile, profile_version); - len += 1; + proto_tree_add_item(network_tree, hf_zbee_zdp_profile, tvb, *offset, 1, ENC_LITTLE_ENDIAN); + proto_tree_add_item(network_tree, hf_zbee_zdp_profile_version, tvb, *offset, 1, ENC_LITTLE_ENDIAN); + *offset += 1; - beacon = (tvb_get_guint8(tvb, *offset + len) & 0x0f) >> 0; - superframe = (tvb_get_guint8(tvb, *offset + len) & 0xf0) >> 4; - if ((tree) && (beacon == 0xf)) { - proto_item_append_text(ti, ", Beacons Disabled"); + ti = proto_tree_add_item(network_tree, hf_zbee_zdp_beacon, tvb, *offset, 1, ENC_LITTLE_ENDIAN); + proto_tree_add_item(network_tree, hf_zbee_zdp_superframe, tvb, *offset, 1, ENC_LITTLE_ENDIAN); + beacon = tvb_get_guint8(tvb, *offset) & 0x0f; + if (beacon == 0xf) { + proto_item_append_text(ti, " (Beacons Disabled)"); } - else if (tree) { - proto_item_append_text(ti, ", BeaconOrder: %d, SuperframeOrder: %d", beacon, superframe); - } - len += 1; + *offset += 1; - permit = tvb_get_guint8(tvb, *offset) & 0x01; - if (tree) proto_item_append_text(ti, ", PermitJoining: %s}", permit?"True":"False"); - len += 1; + proto_tree_add_item(network_tree, hf_zbee_zdp_permit_joining, tvb, *offset, 1, ENC_LITTLE_ENDIAN); + *offset += 1; - if (tree) proto_item_set_len(ti, len); - *offset += len; } /* zdp_parse_nwk_desc */ /*FUNCTION:------------------------------------------------------ @@ -119,94 +105,57 @@ zdp_parse_nwk_desc(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint8 versio static void zdp_parse_neighbor_table_entry(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint8 version) { + proto_tree *table_tree; proto_item *ti = NULL; guint len = 0; - guint64 ext_pan; - guint16 pan; - guint64 ext_addr; - guint16 device; - guint8 type; - guint8 idle_rx; - guint8 rel; - guint8 permit_joining; - guint8 depth; - guint8 lqi; - if (version >= ZBEE_VERSION_2007) { + table_tree = proto_tree_add_subtree(tree, tvb, *offset, 8, ett_zbee_zdp_table_entry, &ti, "Table Entry"); /* ZigBee 2006 & later use an extended PAN Identifier. */ - ext_pan = tvb_get_letoh64(tvb, *offset + len); - if (tree) ti = proto_tree_add_text(tree, tvb, *offset, 0, "{Extended PAN: %s", eui64_to_str(ext_pan)); + proto_tree_add_item(table_tree, hf_zbee_zdp_extended_pan, tvb, *offset, 8, ENC_LITTLE_ENDIAN); len += 8; } else { + table_tree = proto_tree_add_subtree(tree, tvb, *offset, 2, ett_zbee_zdp_table_entry, &ti, "Table Entry"); /* ZigBee 2003 & earlier use a short PAN Identifier. */ - pan = tvb_get_letohs(tvb, *offset + len); - if (tree) ti = proto_tree_add_text(tree, tvb, *offset, 0, "{PAN: 0x%04x", pan); + proto_tree_add_item(table_tree, hf_zbee_zdp_pan_uint, tvb, *offset, 2, ENC_LITTLE_ENDIAN); len += 2; } - ext_addr = tvb_get_letoh64(tvb, *offset + len); - if (tree) proto_item_append_text(ti, ", Extended Addr: %s", ep_eui64_to_display(ext_addr)); + proto_tree_add_item(table_tree, hf_zbee_zdp_ext_addr, tvb, *offset + len, 8, ENC_LITTLE_ENDIAN); len += 8; - device = tvb_get_letohs(tvb, *offset + len); - if (tree) proto_item_append_text(ti, ", Addr: 0x%04x", device); + proto_tree_add_item(table_tree, hf_zbee_zdp_addr, tvb, *offset + len, 2, ENC_LITTLE_ENDIAN); len += 2; if (version >= ZBEE_VERSION_2007) { - type = (tvb_get_guint8(tvb, *offset + len) & 0x03) >> 0; - idle_rx = (tvb_get_guint8(tvb, *offset + len) & 0x0c) >> 2; - rel = (tvb_get_guint8(tvb, *offset + len) & 0x70) >> 4; + proto_tree_add_item(table_tree, hf_zbee_zdp_table_entry_type, tvb, *offset + len, 1, ENC_NA); + proto_tree_add_item(table_tree, hf_zbee_zdp_table_entry_idle_rx_0c, tvb, *offset + len, 1, ENC_NA); + proto_tree_add_item(table_tree, hf_zbee_zdp_table_entry_relationship_70, tvb, *offset + len, 1, ENC_NA); } else { - type = (tvb_get_guint8(tvb, *offset + len) & 0x03) >> 0; - idle_rx = (tvb_get_guint8(tvb, *offset + len) & 0x04) >> 2; - rel = (tvb_get_guint8(tvb, *offset + len) & 0x18) >> 3; - } - if (tree) { - if (type == 0x00) proto_item_append_text(ti, ", Type: Coordinator"); - else if (type == 0x01) proto_item_append_text(ti, ", Type: Router"); - else if (type == 0x02) proto_item_append_text(ti, ", Type: End Device"); - else proto_item_append_text(ti, ", Type: Unknown"); - - if (idle_rx == 0x00) proto_item_append_text(ti, ", Idle Rx: False"); - else if (idle_rx==0x01) proto_item_append_text(ti, ", Idle Rx: True"); - else proto_item_append_text(ti, ", Idle Rx: Unknown"); - - if (rel == 0x00) proto_item_append_text(ti, ", Relationship: Parent"); - else if (rel == 0x01) proto_item_append_text(ti, ", Relationship: Child"); - else if (rel == 0x02) proto_item_append_text(ti, ", Relationship: Sibling"); - else if (rel == 0x03) proto_item_append_text(ti, ", Relationship: None"); - else if (rel == 0x04) proto_item_append_text(ti, ", Relationship: Previous Child"); - else proto_item_append_text(ti, ", Relationship: Unknown"); + proto_tree_add_item(table_tree, hf_zbee_zdp_table_entry_type, tvb, *offset + len, 1, ENC_NA); + proto_tree_add_item(table_tree, hf_zbee_zdp_table_entry_idle_rx_04, tvb, *offset + len, 1, ENC_NA); + proto_tree_add_item(table_tree, hf_zbee_zdp_table_entry_relationship_18, tvb, *offset + len, 1, ENC_NA); } len += 1; if (version <= ZBEE_VERSION_2004) { /* In ZigBee 2003 & earlier, the depth field is before the permit joining field. */ - depth = tvb_get_guint8(tvb, *offset + len); - if (tree) proto_item_append_text(ti, ", Depth: %d", depth); + proto_tree_add_item(table_tree, hf_zbee_zdp_depth, tvb, *offset + len, 1, ENC_NA); len += 1; } - permit_joining = (tvb_get_guint8(tvb, *offset + len) & 0x03) >> 0; - if (tree) { - if (permit_joining == 0x00) proto_item_append_text(ti, ", Permit Joining: False"); - else if (permit_joining == 0x01)proto_item_append_text(ti, ", Permit Joining: True"); - else proto_item_append_text(ti, ", Permit Joining: Unknown"); - } + proto_tree_add_item(table_tree, hf_zbee_zdp_permit_joining_03, tvb, *offset + len, 1, ENC_NA); len += 1; if (version >= ZBEE_VERSION_2007) { /* In ZigBee 2006 & later, the depth field is after the permit joining field. */ - depth = tvb_get_guint8(tvb, *offset + len); - if (tree) proto_item_append_text(ti, ", Depth: %d", depth); + proto_tree_add_item(table_tree, hf_zbee_zdp_depth, tvb, *offset + len, 1, ENC_NA); len += 1; } - lqi = tvb_get_guint8(tvb, *offset + len); - if (tree) proto_item_append_text(ti, ", LQI: %d}", lqi); + proto_tree_add_item(table_tree, hf_zbee_zdp_lqi, tvb, *offset + len, 1, ENC_NA); len += 1; if (tree) proto_item_set_len(ti, len); @@ -275,7 +224,7 @@ zdp_parse_routing_table_entry(proto_tree *tree, tvbuff_t *tvb, guint *offset) *--------------------------------------------------------------- */ void -dissect_zbee_zdp_req_mgmt_nwk_disc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +dissect_zbee_zdp_req_mgmt_nwk_disc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int hf_channel) { proto_item *ti; guint i; @@ -289,7 +238,7 @@ dissect_zbee_zdp_req_mgmt_nwk_disc(tvbuff_t *tvb, packet_info *pinfo, proto_tree channels = tvb_get_letohl(tvb, offset); if (tree) { gboolean first = 1; - ti = proto_tree_add_text(tree, tvb, offset, 4, "Scan Channels: "); + ti = proto_tree_add_uint_format(tree, hf_channel, tvb, offset, 4, channels, "Scan Channels: "); for (i=0; i<27; i++) { if (channels & (1<