From 4ff733620919738190eace6eadd9112f43d6acaf Mon Sep 17 00:00:00 2001 From: Kenneth Soerensen Date: Fri, 30 Jun 2017 13:14:56 +0200 Subject: ZigBee: Add attribute and command names from Calendar cluster Change-Id: I2e543a39a21d3fc71c0da80ce1cd9ca9e50a3bfc Reviewed-on: https://code.wireshark.org/review/22472 Petri-Dish: Anders Broman Tested-by: Petri Dish Buildbot Reviewed-by: Martin Boye Petersen Reviewed-by: Michael Mann --- epan/dissectors/packet-zbee-zcl-se.c | 279 +++++++++++++++++++++++++++++++++++ epan/dissectors/packet-zbee.h | 2 +- 2 files changed, 280 insertions(+), 1 deletion(-) diff --git a/epan/dissectors/packet-zbee-zcl-se.c b/epan/dissectors/packet-zbee-zcl-se.c index 1d82e5cea5..f3bf97fbe2 100644 --- a/epan/dissectors/packet-zbee-zcl-se.c +++ b/epan/dissectors/packet-zbee-zcl-se.c @@ -2397,6 +2397,285 @@ proto_reg_handoff_zbee_zcl_pp(void) ); } /*proto_reg_handoff_zbee_zcl_pp*/ +/* ########################################################################## */ +/* #### (0x0707) CALENDAR CLUSTER ########################################### */ +/* ########################################################################## */ + +/* Attributes */ +#define zbee_zcl_calendar_attr_names_VALUE_STRING_LIST(XXX) \ +/* Auxiliary Switch Label Attribute Set */ \ + XXX(ZBEE_ZCL_ATTR_ID_CAL_AUX_SWITCH_1_LABEL, 0x0000, "Aux Switch 1 Label" ) \ + XXX(ZBEE_ZCL_ATTR_ID_CAL_AUX_SWITCH_2_LABEL, 0x0001, "Aux Switch 2 Label" ) \ + XXX(ZBEE_ZCL_ATTR_ID_CAL_AUX_SWITCH_3_LABEL, 0x0002, "Aux Switch 3 Label" ) \ + XXX(ZBEE_ZCL_ATTR_ID_CAL_AUX_SWITCH_4_LABEL, 0x0003, "Aux Switch 4 Label" ) \ + XXX(ZBEE_ZCL_ATTR_ID_CAL_AUX_SWITCH_5_LABEL, 0x0004, "Aux Switch 5 Label" ) \ + XXX(ZBEE_ZCL_ATTR_ID_CAL_AUX_SWITCH_6_LABEL, 0x0005, "Aux Switch 6 Label" ) \ + XXX(ZBEE_ZCL_ATTR_ID_CAL_AUX_SWITCH_7_LABEL, 0x0006, "Aux Switch 7 Label" ) \ + XXX(ZBEE_ZCL_ATTR_ID_CAL_AUX_SWITCH_8_LABEL, 0x0007, "Aux Switch 8 Label" ) \ +/* Smart Energy */ \ + XXX(ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_CAL, 0xFFFE, "Attribute Reporting Status" ) + +VALUE_STRING_ENUM(zbee_zcl_calendar_attr_names); +VALUE_STRING_ARRAY(zbee_zcl_calendar_attr_names); + +/* Server Commands Received */ +#define zbee_zcl_calendar_srv_rx_cmd_names_VALUE_STRING_LIST(XXX) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_GET_CALENDAR, 0x00, "Get Calendar" ) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_GET_DAY_PROFILES, 0x01, "Get Day Profiles" ) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_GET_WEEK_PROFILES, 0x02, "Get Week Profiles" ) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_GET_SEASONS, 0x03, "Get Seasons" ) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_GET_SPECIAL_DAYS, 0x04, "Get Special Days" ) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_GET_CALENDAR_CANCELLATION, 0x05, "Get Calendar Cancellation" ) + +VALUE_STRING_ENUM(zbee_zcl_calendar_srv_rx_cmd_names); +VALUE_STRING_ARRAY(zbee_zcl_calendar_srv_rx_cmd_names); + +/* Server Commands Generated */ +#define zbee_zcl_calendar_srv_tx_cmd_names_VALUE_STRING_LIST(XXX) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_PUBLISH_CALENDAR, 0x00, "Publish Calendar" ) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_PUBLISH_DAY_PROFILE, 0x01, "Publish Day Profile" ) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_PUBLISH_WEEK_PROFILE, 0x02, "Publish Week Profile" ) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_PUBLISH_SEASONS, 0x03, "Publish Seasons" ) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_PUBLISH_SPECIAL_DAYS, 0x04, "Publish Special Days" ) \ + XXX(ZBEE_ZCL_CMD_ID_CAL_CANCEL_CALENDAR, 0x05, "Cancel Calendar" ) + +VALUE_STRING_ENUM(zbee_zcl_calendar_srv_tx_cmd_names); +VALUE_STRING_ARRAY(zbee_zcl_calendar_srv_tx_cmd_names); + +/*************************/ +/* Function Declarations */ +/*************************/ +void proto_register_zbee_zcl_calendar(void); +void proto_reg_handoff_zbee_zcl_calendar(void); + +/* Attribute Dissector Helpers */ +static void dissect_zcl_calendar_attr_data (proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type); + +/*************************/ +/* Global Variables */ +/*************************/ + +static dissector_handle_t calendar_handle; + +/* Initialize the protocol and registered fields */ +static int proto_zbee_zcl_calendar = -1; + +static int hf_zbee_zcl_calendar_srv_tx_cmd_id = -1; +static int hf_zbee_zcl_calendar_srv_rx_cmd_id = -1; +static int hf_zbee_zcl_calendar_attr_id = -1; +static int hf_zbee_zcl_calendar_attr_reporting_status = -1; + +/* Initialize the subtree pointers */ +static gint ett_zbee_zcl_calendar = -1; + +/*************************/ +/* Function Bodies */ +/*************************/ + +/** + *This function is called by ZCL foundation dissector in order to decode + * + *@param tree pointer to data tree Wireshark uses to display packet. + *@param tvb pointer to buffer containing raw packet. + *@param offset pointer to buffer offset + *@param attr_id attribute identifier + *@param data_type attribute data type +*/ +static void +dissect_zcl_calendar_attr_data(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint16 attr_id, guint data_type) +{ + switch (attr_id) { + /* applies to all SE clusters */ + case ZBEE_ZCL_ATTR_ID_SE_ATTR_REPORT_STATUS_CAL: + proto_tree_add_item(tree, hf_zbee_zcl_calendar_attr_reporting_status, tvb, *offset, 1, ENC_NA); + *offset += 1; + break; + + default: /* Catch all */ + dissect_zcl_attr_data(tvb, tree, offset, data_type); + break; + } +} /*dissect_zcl_calendar_attr_data*/ + +/** + *ZigBee ZCL Calendar cluster dissector for wireshark. + * + *@param tvb pointer to buffer containing raw packet. + *@param pinfo pointer to packet information fields + *@param tree pointer to data tree Wireshark uses to display packet. +*/ +static int +dissect_zbee_zcl_calendar(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) +{ + zbee_zcl_packet *zcl; + guint offset = 0; + guint8 cmd_id; + gint rem_len; + + /* Reject the packet if data is NULL */ + if (data == NULL) + return 0; + zcl = (zbee_zcl_packet *)data; + cmd_id = zcl->cmd_id; + + /* Create a subtree for the ZCL Command frame, and add the command ID to it. */ + if (zcl->direction == ZBEE_ZCL_FCF_TO_SERVER) { + /* Append the command name to the info column. */ + col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u", + val_to_str_const(cmd_id, zbee_zcl_calendar_srv_rx_cmd_names, "Unknown Command"), + zcl->tran_seqno); + + /* Add the command ID. */ + proto_tree_add_uint(tree, hf_zbee_zcl_calendar_srv_rx_cmd_id, tvb, offset, 1, cmd_id); + + /* Check is this command has a payload, than add the payload tree */ + rem_len = tvb_reported_length_remaining(tvb, ++offset); + if (rem_len > 0) { + proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_calendar, NULL, "Payload"); + + /* Call the appropriate command dissector */ + switch (cmd_id) { + + case ZBEE_ZCL_CMD_ID_CAL_GET_CALENDAR: + /* Add function to dissect payload */ + break; + + case ZBEE_ZCL_CMD_ID_CAL_GET_DAY_PROFILES: + /* Add function to dissect payload */ + break; + + case ZBEE_ZCL_CMD_ID_CAL_GET_WEEK_PROFILES: + /* Add function to dissect payload */ + break; + + case ZBEE_ZCL_CMD_ID_CAL_GET_SEASONS: + /* Add function to dissect payload */ + break; + + case ZBEE_ZCL_CMD_ID_CAL_GET_SPECIAL_DAYS: + /* Add function to dissect payload */ + break; + + case ZBEE_ZCL_CMD_ID_CAL_GET_CALENDAR_CANCELLATION: + /* Add function to dissect payload */ + break; + + default: + break; + } + } + } + else { /* ZBEE_ZCL_FCF_TO_CLIENT */ + /* Append the command name to the info column. */ + col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u", + val_to_str_const(cmd_id, zbee_zcl_calendar_srv_tx_cmd_names, "Unknown Command"), + zcl->tran_seqno); + + /* Add the command ID. */ + proto_tree_add_uint(tree, hf_zbee_zcl_calendar_srv_tx_cmd_id, tvb, offset, 1, cmd_id); + + /* Check is this command has a payload, than add the payload tree */ + rem_len = tvb_reported_length_remaining(tvb, ++offset); + if (rem_len > 0) { + proto_tree_add_subtree(tree, tvb, offset, rem_len, ett_zbee_zcl_calendar, NULL, "Payload"); + + /* Call the appropriate command dissector */ + switch (cmd_id) { + + case ZBEE_ZCL_CMD_ID_CAL_PUBLISH_CALENDAR: + /* Add function to dissect payload */ + break; + + case ZBEE_ZCL_CMD_ID_CAL_PUBLISH_DAY_PROFILE: + /* Add function to dissect payload */ + break; + + case ZBEE_ZCL_CMD_ID_CAL_PUBLISH_WEEK_PROFILE: + /* Add function to dissect payload */ + break; + + case ZBEE_ZCL_CMD_ID_CAL_PUBLISH_SEASONS: + /* Add function to dissect payload */ + break; + + case ZBEE_ZCL_CMD_ID_CAL_PUBLISH_SPECIAL_DAYS: + /* Add function to dissect payload */ + break; + + case ZBEE_ZCL_CMD_ID_CAL_CANCEL_CALENDAR: + /* Add function to dissect payload */ + break; + + default: + break; + } + } + } + + return tvb_captured_length(tvb); +} /*dissect_zbee_zcl_calendar*/ + +/** + *This function registers the ZCL Calendar dissector + * +*/ +void +proto_register_zbee_zcl_calendar(void) +{ + static hf_register_info hf[] = { + + { &hf_zbee_zcl_calendar_attr_id, + { "Attribute", "zbee_zcl_se.calendar.attr_id", FT_UINT16, BASE_HEX, VALS(zbee_zcl_calendar_attr_names), + 0x0, NULL, HFILL } }, + + { &hf_zbee_zcl_calendar_attr_reporting_status, /* common to all SE clusters */ + { "Attribute Reporting Status", "zbee_zcl_se.calendar.attr.attr_reporting_status", + FT_UINT8, BASE_HEX, VALS(zbee_zcl_se_reporting_status_names), 0x00, NULL, HFILL } }, + + { &hf_zbee_zcl_calendar_srv_tx_cmd_id, + { "Command", "zbee_zcl_se.calendar.cmd.srv_tx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_calendar_srv_tx_cmd_names), + 0x00, NULL, HFILL } }, + + { &hf_zbee_zcl_calendar_srv_rx_cmd_id, + { "Command", "zbee_zcl_se.calendar.cmd.srv_rx.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_calendar_srv_rx_cmd_names), + 0x00, NULL, HFILL } }, + + }; + + /* ZCL Calendar subtrees */ + gint *ett[] = { + &ett_zbee_zcl_calendar, + }; + + /* Register the ZigBee ZCL Calendar cluster protocol name and description */ + proto_zbee_zcl_calendar = proto_register_protocol("ZigBee ZCL Calendar", "ZCL Calendar", ZBEE_PROTOABBREV_ZCL_CALENDAR); + proto_register_field_array(proto_zbee_zcl_calendar, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); + + /* Register the ZigBee ZCL Calendar dissector. */ + calendar_handle = register_dissector(ZBEE_PROTOABBREV_ZCL_CALENDAR, dissect_zbee_zcl_calendar, proto_zbee_zcl_calendar); +} /*proto_register_zbee_zcl_calendar*/ + +/** + *Hands off the Zcl Calendar dissector. + * +*/ +void +proto_reg_handoff_zbee_zcl_calendar(void) +{ + /* Register our dissector with the ZigBee application dissectors. */ + dissector_add_uint("zbee.zcl.cluster", ZBEE_ZCL_CID_CALENDAR, calendar_handle); + + zbee_zcl_init_cluster( proto_zbee_zcl_calendar, + ett_zbee_zcl_calendar, + ZBEE_ZCL_CID_CALENDAR, + hf_zbee_zcl_calendar_attr_id, + hf_zbee_zcl_calendar_srv_rx_cmd_id, + hf_zbee_zcl_calendar_srv_tx_cmd_id, + (zbee_zcl_fn_attr_data)dissect_zcl_calendar_attr_data + ); +} /*proto_reg_handoff_zbee_zcl_calendar*/ + /* ########################################################################## */ /* #### (0x0709) EVENTS CLUSTER ############################################# */ /* ########################################################################## */ diff --git a/epan/dissectors/packet-zbee.h b/epan/dissectors/packet-zbee.h index a91d3fa2c8..60492bb207 100644 --- a/epan/dissectors/packet-zbee.h +++ b/epan/dissectors/packet-zbee.h @@ -1169,12 +1169,12 @@ #define ZBEE_PROTOABBREV_ZCL_RELHUMMEAS "zbee_zcl_meas_sensing.relhummeas" #define ZBEE_PROTOABBREV_ZCL_TEMPMEAS "zbee_zcl_meas_sensing.tempmeas" #define ZBEE_PROTOABBREV_ZCL_OCCSEN "zbee_zcl_meas_sensing.occsen" -#define ZBEE_PROTOABBREV_ZCL_CAL "zbee_zcl_se.cal" #define ZBEE_PROTOABBREV_ZCL_KE "zbee_zcl_se.ke" #define ZBEE_PROTOABBREV_ZCL_MET "zbee_zcl_se.met" #define ZBEE_PROTOABBREV_ZCL_MSG "zbee_zcl_se.msg" #define ZBEE_PROTOABBREV_ZCL_TUN "zbee_zcl_se.tun" #define ZBEE_PROTOABBREV_ZCL_PRE_PAYMENT "zbee_zcl_se.pp" +#define ZBEE_PROTOABBREV_ZCL_CALENDAR "zbee_zcl_se.calendar" #define ZBEE_PROTOABBREV_ZCL_EVENTS "zbee_zcl_se.events" #define ZBEE_PROTOABBREV_ZCL_SHADE_CONFIG "zbee_zcl_closures.shade_config" #define ZBEE_PROTOABBREV_ZCL_DOOR_LOCK "zbee_zcl_closures.door_lock" -- cgit v1.2.1