From: saerome kim Date: Fri, 3 Feb 2017 06:09:18 +0000 (+0900) Subject: Implement ZCL Identify Cluster X-Git-Tag: submit/tizen/20170512.045637~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=c959f25e752d428134ed682a96a495308a8ddc79;p=platform%2Fcore%2Fconnectivity%2Fzigbee-manager.git Implement ZCL Identify Cluster Change-Id: I7bba239e0f92b4dea1ff2e1b86041dcd3df8a213 Signed-off-by: saerome kim --- diff --git a/common/include/zigbee_zcl_identify_type.h b/common/include/zigbee_zcl_identify_type.h index 484edf9..8ce55c8 100644 --- a/common/include/zigbee_zcl_identify_type.h +++ b/common/include/zigbee_zcl_identify_type.h @@ -21,6 +21,10 @@ #include +/* -------------------------------------------------------------------------------------- + * For Request + * -------------------------------------------------------------------------------------*/ + /** * @brief Definition for ZCL Identify identify structure. * @since_tizen 3.0 @@ -40,4 +44,17 @@ typedef struct { char dest_ep; /**< Destination endpoint */ } ZigbeeZclIdentifyQuery_t; +/* -------------------------------------------------------------------------------------- + * For Notifications + * -------------------------------------------------------------------------------------*/ + +/** + * @brief Definition for ZCL Identify query response structure. + * @since_tizen 3.0 + */ +typedef struct { + short node_id; /**< Node ID */ + short identify_time; /**< Identify time */ +} ZigbeeZclIdentifyQueryNoti_t; + #endif /* __ZIGBEE_ZCL_IDENTIFY_TYPE_H__ */ diff --git a/zigbee-daemon/zigbee-interface/introspection/zcl-identify.xml b/zigbee-daemon/zigbee-interface/introspection/zcl-identify.xml index 5b0d093..7f05c3e 100644 --- a/zigbee-daemon/zigbee-interface/introspection/zcl-identify.xml +++ b/zigbee-daemon/zigbee-interface/introspection/zcl-identify.xml @@ -4,10 +4,12 @@ + + diff --git a/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zcl_identify.c b/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zcl_identify.c index 8afeadf..25d9fbf 100644 --- a/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zcl_identify.c +++ b/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zcl_identify.c @@ -20,17 +20,59 @@ #include +static void *_service_interface_ref_zigbee_zcl_identify(ZigBeeServiceInterface *service_interface) +{ + ZigbeeObjectSkeleton *zigbee_object = NULL; + ZigbeeCustomData_t *custom_data = NULL; + ZigbeeZcl_identify *id_object = NULL; + + custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface); + if (NULL == custom_data) { + Z_LOGE("D-BUS service interface custom_data is NULL!"); + return NULL; + } + + /* Get zigbee object */ + zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH); + if (NULL == zigbee_object) { + Z_LOGW("Cannot find ZigBee D-BUS interface object!", zigbee_object); + return NULL; + } + + id_object = zigbee_object_get_zcl_identify(ZIGBEE_OBJECT(zigbee_object)); + return id_object; +} + + static void on_zclidentify_control_identify_resp(ZigBeeServiceInterface *service_interface, guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data) { ZigbeeServiceInterfaceRespCbData_t *cb_data = (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data; - NOT_USED(cb_data); + ZigbeeZcl_identify *id_object = NULL; + GDBusMethodInvocation *invocation = NULL; + + ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data; + NOT_USED(service_interface); NOT_USED(request_id); - NOT_USED(resp_data); - NOT_USED(resp_data_len); + + if (NULL == resp_data || 0 == resp_data_len) { + Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len); + g_free(cb_data); + return; + } + + id_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); + zblib_check_null_free_and_ret("id_object", id_object, cb_data); + + invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); + + zigbee_zcl_identify_complete_identify(id_object, invocation, payload->result); + + g_free(cb_data); } static gboolean on_zclidentify_control_identify(ZigbeeZcl_identify *zclidentify_control_object, @@ -93,11 +135,29 @@ static void on_zclidentify_control_query_resp(ZigBeeServiceInterface *service_in ZigbeeServiceInterfaceRespCbData_t *cb_data = (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data; - NOT_USED(cb_data); + ZigbeeZcl_identify *id_object = NULL; + GDBusMethodInvocation *invocation = NULL; + + ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data; + NOT_USED(service_interface); NOT_USED(request_id); - NOT_USED(resp_data); - NOT_USED(resp_data_len); + + if (NULL == resp_data || 0 == resp_data_len) { + Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len); + g_free(cb_data); + return; + } + + id_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); + zblib_check_null_free_and_ret("id_object", id_object, cb_data); + + invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); + + zigbee_zcl_identify_complete_query(id_object, invocation, payload->result); + + g_free(cb_data); } static gboolean on_zclidentify_control_query(ZigbeeZcl_identify *zclidentify_control_object, @@ -155,15 +215,36 @@ static gboolean on_zclidentify_control_query(ZigbeeZcl_identify *zclidentify_con void zigbee_service_dbus_interface_zcl_identify_notification(ZigBeeServiceInterface *service_interface, guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data) { - if (NULL == service_interface) { - Z_LOGE("service_interface is NULL"); + ZigbeeZcl_identify *id_object; + + zblib_check_null_ret("service_interface", service_interface); + + if (NULL == noti_data || 0 == noti_data_len) { + Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len); return; } - NOT_USED(noti_id); - NOT_USED(noti_data); - NOT_USED(noti_data_len); + id_object = _service_interface_ref_zigbee_zcl_identify(service_interface); + zblib_check_null_ret("id_object", id_object); + NOT_USED(noti_cb_data); + + switch(noti_id) { + case ZBLIB_ZCL_IDENTIFY_NOTI_QUERY_RSP: { + ZigbeeZclIdentifyQueryNoti_t *rsp = (ZigbeeZclIdentifyQueryNoti_t*)noti_data; + + Z_LOGD("query_rsp from : [0x%X]", rsp->node_id); + + zigbee_zcl_identify_emit_query_rsp(id_object, rsp->node_id, rsp->identify_time); + } + break; + default: + Z_LOGE("Unexpected notification [%x]", noti_id); + break; + } + + /* ZigbeeZcl_identify should be dereferenced */ + g_object_unref(id_object); } gboolean zigbee_service_dbus_interface_zcl_identify_init(ZigBeeServiceInterface *service_interface, diff --git a/zigbee-daemon/zigbee-lib/include/zblib_driver_zcl_identify.h b/zigbee-daemon/zigbee-lib/include/zblib_driver_zcl_identify.h index db9ab26..44eb123 100644 --- a/zigbee-daemon/zigbee-lib/include/zblib_driver_zcl_identify.h +++ b/zigbee-daemon/zigbee-lib/include/zblib_driver_zcl_identify.h @@ -31,6 +31,12 @@ typedef enum { ZBLIB_ZCL_IDENTIFY_OPS_QUERY, /**< Query */ } ZblibZclIdentifyOps_e; +/**< ZigBee 'ZCL Identify' notification IDs */ +typedef enum { + ZBLIB_ZCL_IDENTIFY_NOTI_QUERY_RSP = 1, /**< Identify Query Response */ +} ZblibZclIdentifyNoti_e; + + /* ZigBee 'ZCL Identify' driver APIs */ ZigBeeDriver *zblib_driver_zcl_identify_new(ZigBeePlugin *plugin, const gchar *driver_name, diff --git a/zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_zcl_identify.c b/zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_zcl_identify.c index 8bb5d70..5013b11 100644 --- a/zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_zcl_identify.c +++ b/zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_zcl_identify.c @@ -18,6 +18,7 @@ #include #include +#include #include #include "zblib_driver_zcl_identify.h" @@ -98,6 +99,7 @@ ZigBeeDriver *zblib_driver_zcl_identify_new(ZigBeePlugin *plugin, ZblibDriverZclIdentifyOps_t *ops) { ZigBeeDriver *driver = NULL; + ZigBeeService *service = NULL; ZblibDriverZclIdentifyPrivData_t *priv_data = NULL; gboolean ret; @@ -113,6 +115,19 @@ ZigBeeDriver *zblib_driver_zcl_identify_new(ZigBeePlugin *plugin, /* Update private data */ priv_data->ops = ops; + /* Link service to driver */ + service = zblib_plugin_ref_service(plugin); + if (NULL == service) { + Z_LOGE("zblib_plugin_ref_service failed!"); + + /* Free allocated resources */ + g_free(priv_data); + g_free(driver); + + return NULL; + } + zblib_driver_link_service(driver, service); + /* Link private data to driver */ ret = zblib_driver_link_object(driver, priv_data); if (FALSE == ret) {