From: saerome kim Date: Mon, 6 Feb 2017 23:24:35 +0000 (+0900) Subject: Impelement Custom cluster X-Git-Tag: submit/tizen/20170512.045637~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=830fd190b41bcc67f5371d5de674ae9876e5650c;p=platform%2Fcore%2Fconnectivity%2Fzigbee-manager.git Impelement Custom cluster Change-Id: Iae3bf86bef7ecdaf5df31cc72def83e3ae674db0 Signed-off-by: saerome kim --- diff --git a/common/include/zigbee_custom_type.h b/common/include/zigbee_custom_type.h index 9347614..4fd8832 100644 --- a/common/include/zigbee_custom_type.h +++ b/common/include/zigbee_custom_type.h @@ -21,6 +21,10 @@ #include +/* -------------------------------------------------------------------------------------- + * For Request + * -------------------------------------------------------------------------------------*/ + /** * @brief Definition for APS send structure. * @since_tizen 3.0 @@ -34,6 +38,8 @@ typedef struct { short profile_id; char zcl_frame_ctrl; short mfg_code; + char cmd_id; + short payload_len; char payload[ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN]; } ZigbeeCustomApsSend_t; @@ -48,6 +54,7 @@ typedef struct { short cluster_id; char zcl_frame_ctrl; char cmd_id; + short payload_len; char payload[ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN]; } ZigbeeCustomZclSend_t; @@ -56,7 +63,51 @@ typedef struct { * @since_tizen 3.0 */ typedef struct { + short length; char data[ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN]; } ZigbeeCustomSendToLocal_t; +/* -------------------------------------------------------------------------------------- + * For Notifications + * -------------------------------------------------------------------------------------*/ + +/** + * @brief Definition for send to APS send response structure. + * @since_tizen 3.0 + */ +typedef struct { + short node_id; + char src_ep; + char dest_ep; + short cluster_id; + short profile_id; + char cmd_id; + short payload_len; + char payload[ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN]; +} ZigbeeCustomApsSendNoti_t; + +/** + * @brief Definition for send to ZCL send response structure. + * @since_tizen 3.0 + */ +typedef struct { + short node_id; + char src_ep; + char dest_ep; + short cluster_id; + short profile_id; + char cmd_id; + short payload_len; + char payload[ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN]; +} ZigbeeCustomZclSendNoti_t; + +/** + * @brief Definition for send to local response structure. + * @since_tizen 3.0 + */ +typedef struct { + short length; + char data[ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN]; +} ZigbeeCustomSendToLocalNoti_t; + #endif /* __ZIGBEE_CUSTOM_TYPE_H__ */ diff --git a/zigbee-daemon/zigbee-interface/introspection/custom.xml b/zigbee-daemon/zigbee-interface/introspection/custom.xml index 8b62eec..d39b237 100644 --- a/zigbee-daemon/zigbee-interface/introspection/custom.xml +++ b/zigbee-daemon/zigbee-interface/introspection/custom.xml @@ -9,7 +9,9 @@ - + + + @@ -19,12 +21,13 @@ - + + - - + + @@ -34,8 +37,8 @@ - + @@ -43,12 +46,12 @@ - + - + diff --git a/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_custom.c b/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_custom.c index 1e8416e..19404db 100644 --- a/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_custom.c +++ b/zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_custom.c @@ -20,17 +20,59 @@ #include +static void *_service_interface_ref_zigbee_custom( + ZigBeeServiceInterface *service_interface) +{ + ZigbeeObjectSkeleton *zigbee_object = NULL; + ZigbeeCustomData_t *custom_data = NULL; + ZigbeeCustom *custom_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; + } + + custom_object = zigbee_object_get_custom(ZIGBEE_OBJECT(zigbee_object)); + return custom_object; +} + static void on_custom_aps_send_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); + ZigbeeCustom *custom_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; + } + + custom_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); + zblib_check_null_free_and_ret("custom_object", custom_object, cb_data); + + invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); + + zigbee_custom_complete_aps_send(custom_object, invocation, payload->result); + + g_free(cb_data); } static gboolean on_custom_aps_send(ZigbeeCustom *custom_object, @@ -43,6 +85,8 @@ static gboolean on_custom_aps_send(ZigbeeCustom *custom_object, gshort profile_id, gchar zcl_frame_ctrl, gshort mfg_code, + gchar cmd_id, + gshort payload_len, GVariant *payload, gpointer user_data) { @@ -66,8 +110,10 @@ static gboolean on_custom_aps_send(ZigbeeCustom *custom_object, req.profile_id = profile_id; req.zcl_frame_ctrl = zcl_frame_ctrl; req.mfg_code = mfg_code; - g_variant_get(payload, "ay", &iter); - while (g_variant_iter_loop(iter, "y", req.payload[i])) { + req.cmd_id = cmd_id; + req.payload_len = payload_len; + g_variant_get(payload, "a(y)", &iter); + while (g_variant_iter_loop(iter, "(y)", req.payload[i])) { i++; if (i >= ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN) break; @@ -113,11 +159,29 @@ static void on_custom_zcl_send_resp(ZigBeeServiceInterface *service_interface, ZigbeeServiceInterfaceRespCbData_t *cb_data = (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data; - NOT_USED(cb_data); + ZigbeeCustom *custom_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; + } + + custom_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); + zblib_check_null_free_and_ret("custom_object", custom_object, cb_data); + + invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); + + zigbee_custom_complete_zcl_send(custom_object, invocation, payload->result); + + g_free(cb_data); } static gboolean on_custom_zcl_send(ZigbeeCustom *custom_object, @@ -128,6 +192,7 @@ static gboolean on_custom_zcl_send(ZigbeeCustom *custom_object, gshort cluster_id, gchar zcl_frame_ctrl, gchar cmd_id, + gshort payload_len, GVariant *payload, gpointer user_data) { @@ -149,8 +214,9 @@ static gboolean on_custom_zcl_send(ZigbeeCustom *custom_object, req.cluster_id = cluster_id; req.zcl_frame_ctrl = zcl_frame_ctrl; req.cmd_id = cmd_id; - g_variant_get(payload, "ay", &iter); - while (g_variant_iter_loop(iter, "y", req.payload[i])) { + req.payload_len = payload_len; + g_variant_get(payload, "a(y)", &iter); + while (g_variant_iter_loop(iter, "(y)", req.payload[i])) { i++; if (i >= ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN) break; @@ -196,15 +262,34 @@ static void on_custom_send_to_local_resp(ZigBeeServiceInterface *service_interfa ZigbeeServiceInterfaceRespCbData_t *cb_data = (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data; - NOT_USED(cb_data); + ZigbeeCustom *custom_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; + } + + custom_object = zigbee_service_dbus_interface_ref_interface_object(cb_data); + zblib_check_null_free_and_ret("custom_object", custom_object, cb_data); + + invocation = zigbee_service_dbus_interface_ref_invocation(cb_data); + zblib_check_null_free_and_ret("invocation", invocation, cb_data); + + zigbee_custom_complete_send_to_local(custom_object, invocation, payload->result); + + g_free(cb_data); } static gboolean on_custom_send_to_local(ZigbeeCustom *custom_object, GDBusMethodInvocation *invocation, + gshort length, GVariant *data, gpointer user_data) { @@ -220,8 +305,9 @@ static gboolean on_custom_send_to_local(ZigbeeCustom *custom_object, memset(&req, 0x0, sizeof(ZigbeeCustomSendToLocal_t)); /* Update request structure */ - g_variant_get(data, "ay", &iter); - while (g_variant_iter_loop(iter, "y", req.data[i])) { + req.length = length; + g_variant_get(data, "a(y)", &iter); + while (g_variant_iter_loop(iter, "(y)", req.data[i])) { i++; if (i >= ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN) break; @@ -264,15 +350,106 @@ static gboolean on_custom_send_to_local(ZigbeeCustom *custom_object, void zigbee_service_dbus_interface_custom_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"); + ZigbeeCustom *custom_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); + custom_object = _service_interface_ref_zigbee_custom(service_interface); + zblib_check_null_ret("custom_object", custom_object); + NOT_USED(noti_cb_data); + + switch(noti_id) { + case ZBLIB_CUSTOM_NOTI_APS_SEND: { + int i; + GVariant* payload = NULL; + GVariantBuilder *attr_builder = NULL; + ZigbeeCustomApsSendNoti_t *rsp = (ZigbeeCustomApsSendNoti_t*)noti_data; + + Z_LOGD("'aps_send_rsp' from : [0x%X]", rsp->node_id); + + Z_LOGD("rsp->node_id=%x", rsp->node_id); + Z_LOGD("rsp->src_ep = %x", rsp->src_ep); + Z_LOGD("rsp->dest_ep = %x", rsp->dest_ep); + Z_LOGD("rsp->cluster_id = %x", rsp->cluster_id); + Z_LOGD("rsp->profile_id = %x", rsp->profile_id); + Z_LOGD("rsp->cmd_id = %x", rsp->cmd_id); + Z_LOGD("rsp->payload_len = %x", rsp->payload_len); + + attr_builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); + for (i = 0; i < rsp->payload_len; i++) { + g_variant_builder_add(attr_builder, "(y)", rsp->payload[i]); + Z_LOGD("rsp->payload[%d] = %x", i, rsp->payload[i]); + } + payload = g_variant_builder_end(attr_builder); + g_variant_builder_unref(attr_builder); + + zigbee_custom_emit_aps_send_rsp(custom_object, rsp->node_id, rsp->src_ep, + rsp->dest_ep, rsp->cluster_id, rsp->profile_id, rsp->payload_len, + payload); + } + break; + case ZBLIB_CUSTOM_NOTI_ZCL_SEND: { + int i; + GVariant* payload = NULL; + GVariantBuilder *attr_builder = NULL; + ZigbeeCustomZclSendNoti_t *rsp = (ZigbeeCustomZclSendNoti_t*)noti_data; + + Z_LOGD("'zcl_send_rsp' from : [0x%X]", rsp->node_id); + + Z_LOGD("rsp->node_id=%x", rsp->node_id); + Z_LOGD("rsp->src_ep = %x", rsp->src_ep); + Z_LOGD("rsp->dest_ep = %x", rsp->dest_ep); + Z_LOGD("rsp->cluster_id = %x", rsp->cluster_id); + Z_LOGD("rsp->profile_id = %x", rsp->profile_id); + Z_LOGD("rsp->cmd_id = %x", rsp->cmd_id); + Z_LOGD("rsp->payload_len = %x", rsp->payload_len); + + attr_builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); + for (i = 0; i < rsp->payload_len; i++) { + g_variant_builder_add(attr_builder, "(y)", rsp->payload[i]); + Z_LOGD("rsp->payload[%d] = %x", i, rsp->payload[i]); + } + payload = g_variant_builder_end(attr_builder); + g_variant_builder_unref(attr_builder); + + zigbee_custom_emit_zcl_send_rsp(custom_object, rsp->node_id, rsp->src_ep, + rsp->dest_ep, rsp->cluster_id, rsp->profile_id, rsp->payload_len, payload); + } + break; + case ZBLIB_CUSTOM_NOTI_SEND_TO_LOCAL: { + int i; + GVariant* data = NULL; + GVariantBuilder *attr_builder = NULL; + ZigbeeCustomSendToLocalNoti_t *rsp = (ZigbeeCustomSendToLocalNoti_t*)noti_data; + + Z_LOGD("'send_to_local_rsp' length : [0x%X]", rsp->length); + + attr_builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)")); + for (i = 0; i < rsp->length; i++) { + g_variant_builder_add(attr_builder, "(y)", rsp->data[i]); + Z_LOGD("rsp->data[%d] = %x", i, rsp->data[i]); + } + data = g_variant_builder_end(attr_builder); + g_variant_builder_unref(attr_builder); + + zigbee_custom_emit_send_to_local_rsp(custom_object, rsp->length, data); + + if (data) g_variant_unref(data); + } + break; + default: + Z_LOGE("Unexpected notification [%x]", noti_id); + break; + } + + /* ZigbeeCustom should be dereferenced */ + g_object_unref(custom_object); } gboolean zigbee_service_dbus_interface_custom_init(ZigBeeServiceInterface *service_interface, diff --git a/zigbee-daemon/zigbee-lib/include/zblib_driver_custom.h b/zigbee-daemon/zigbee-lib/include/zblib_driver_custom.h index 6f172f6..79585cc 100644 --- a/zigbee-daemon/zigbee-lib/include/zblib_driver_custom.h +++ b/zigbee-daemon/zigbee-lib/include/zblib_driver_custom.h @@ -33,6 +33,13 @@ typedef enum { ZBLIB_CUSTOM_OPS_SEND_TO_LOCAL, /**< Send to local */ } ZblibCustomOps_e; +/**< ZigBee 'ZCL bind' notification IDs */ +typedef enum { + ZBLIB_CUSTOM_NOTI_APS_SEND = 1, /**< APS send response notification */ + ZBLIB_CUSTOM_NOTI_ZCL_SEND, /**< ZCL send response notification */ + ZBLIB_CUSTOM_NOTI_SEND_TO_LOCAL, /**< Send to local response notification */ +} ZblibCustomNoti_e; + /* ZigBee 'custom' driver APIs */ ZigBeeDriver *zblib_driver_custom_new(ZigBeePlugin *plugin, const gchar *driver_name, diff --git a/zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_custom.c b/zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_custom.c index 1e52591..0271352 100644 --- a/zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_custom.c +++ b/zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_custom.c @@ -18,6 +18,7 @@ #include #include +#include #include #include "zblib_driver_custom.h" @@ -106,6 +107,7 @@ ZigBeeDriver *zblib_driver_custom_new(ZigBeePlugin *plugin, ZblibDriverCustomOps_t *ops) { ZigBeeDriver *driver = NULL; + ZigBeeService *service = NULL; ZblibDriverCustomPrivData_t *priv_data = NULL; gboolean ret; @@ -121,6 +123,19 @@ ZigBeeDriver *zblib_driver_custom_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) { diff --git a/zigbee-daemon/zigbee-lib/src/zblib_request.c b/zigbee-daemon/zigbee-lib/src/zblib_request.c index f7c1cba..a32c2e3 100644 --- a/zigbee-daemon/zigbee-lib/src/zblib_request.c +++ b/zigbee-daemon/zigbee-lib/src/zblib_request.c @@ -300,8 +300,10 @@ static gpointer __zblib_request_create_custom_request_data(guint request_type, req->profile_id = in_req->profile_id; req->zcl_frame_ctrl = in_req->zcl_frame_ctrl; req->mfg_code = in_req->mfg_code; + req->cmd_id = in_req->cmd_id; + req->payload_len = in_req->payload_len; memcpy(req->payload, - in_req->payload, ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN); + in_req->payload, req->payload_len); } custom_request_data = (gpointer)req; @@ -325,8 +327,9 @@ static gpointer __zblib_request_create_custom_request_data(guint request_type, req->cluster_id = in_req->cluster_id; req->zcl_frame_ctrl = in_req->zcl_frame_ctrl; req->cmd_id = in_req->cmd_id; + req->payload_len = in_req->payload_len; memcpy(req->payload, - in_req->payload, ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN); + in_req->payload, req->payload_len); } custom_request_data = (gpointer)req; @@ -344,8 +347,9 @@ static gpointer __zblib_request_create_custom_request_data(guint request_type, g_malloc0(sizeof(ZigbeeCustomSendToLocal_t)); /* Copy data */ + req->length = in_req->length; memcpy(req->data, - in_req->data, ZIGBEE_CUSTOM_SEND_PAYLOAD_LEN); + in_req->data, req->length); } custom_request_data = (gpointer)req;