Implement ZDO Bind cluster
authorsaerome kim <saerome.kim@samsung.com>
Mon, 6 Feb 2017 00:24:36 +0000 (09:24 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 11 May 2017 09:10:25 +0000 (18:10 +0900)
Change-Id: I0455770fc501b90165cdb443b49aa854537a31ba
Signed-off-by: saerome kim <saerome.kim@samsung.com>
common/include/zigbee_zdo_bind_type.h
zigbee-daemon/zigbee-interface/introspection/zdo-bind.xml
zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zdo_bind.c
zigbee-daemon/zigbee-lib/include/zblib_driver_zdo_bind.h
zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_zdo_bind.c

index 9aae196..dddc126 100644 (file)
 
 #include <zigbee_types.h>
 
+/* -----------------------------------------------------------------------------
+ * For Request
+ * ---------------------------------------------------------------------------*/
+
 /**
  * @brief Definition for ZDO bind bind request structure.
  * @since_tizen 3.0
@@ -51,4 +55,17 @@ typedef struct {
        char dst_ep; /**< Destination endpoint */
 } ZigbeeZdoBindUnbindReq_t;
 
+/* -----------------------------------------------------------------------------
+ * For Notification
+ * ---------------------------------------------------------------------------*/
+
+/**
+ * @brief Definition for ZDO bind / unbind response structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       char status; /**< Status */
+} ZigbeeZdoBindUnbindNoti_t;
+
+
 #endif /* __ZIGBEE_ZDO_BIND_TYPE_H__ */
index 0dd47b0..11b578b 100644 (file)
@@ -2,10 +2,10 @@
        <interface name='org.tizen.zigbee.zdo_bind'>
                <method name='bind_req'>
                        <arg type='q' name='nodeId' direction='in'/>
-                       <arg type='ay' name='src_addr' direction='in'/>
+                       <arg type='a(y)' name='src_addr' direction='in'/>
                        <arg type='y' name='src_ep' direction='in'/>
                        <arg type='q' name='cluster_id' direction='in'/>
-                       <arg type='ay' name='dst_addr' direction='in'/>
+                       <arg type='a(y)' name='dst_addr' direction='in'/>
                        <arg type='y' name='bind_type' direction='in'/>
                        <arg type='q' name='group_addr' direction='in'/>
                        <arg type='y' name='dst_ep' direction='in'/>
                </method>
                <method name='unbind_req'>
                        <arg type='q' name='nodeId' direction='in'/>
-                       <arg type='ay' name='src_addr' direction='in'/>
+                       <arg type='a(y)' name='src_addr' direction='in'/>
                        <arg type='y' name='src_ep' direction='in'/>
                        <arg type='q' name='cluster_id' direction='in'/>
-                       <arg type='ay' name='dst_addr' direction='in'/>
+                       <arg type='a(y)' name='dst_addr' direction='in'/>
                        <arg type='y' name='bind_type' direction='in'/>
                        <arg type='q' name='group_addr' direction='in'/>
                        <arg type='y' name='dst_ep' direction='in'/>
                        <arg type='i' name='result' direction='out'/>
                </method>
 
-               <signal name='binding_rsp'>
+               <signal name='bind_rsp'>
                        <arg type='y' name='status'/>
                </signal>
-               <signal name='unbinding_rsp'>
+               <signal name='unbind_rsp'>
                        <arg type='y' name='status'/>
                </signal>
        </interface>
index d099772..9f56332 100644 (file)
 
 #include <zblib_driver_zdo_bind.h>
 
+static void *_service_interface_ref_zigbee_zdo_bind(
+       ZigBeeServiceInterface *service_interface)
+{
+       ZigbeeObjectSkeleton *zigbee_object = NULL;
+       ZigbeeCustomData_t *custom_data = NULL;
+       ZigbeeZdo_bind *bind_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;
+       }
+
+       bind_object = zigbee_object_get_zdo_bind(ZIGBEE_OBJECT(zigbee_object));
+       return bind_object;
+}
+
 static void on_zdo_bind_bind_req_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);
+       ZigbeeZdo_bind *bind_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;
+       }
+
+       bind_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("bind_object", bind_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zdo_bind_complete_bind_req(bind_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zdo_bind_bind_req(ZigbeeZdo_bind *zdo_bind_object,
@@ -58,16 +100,16 @@ static gboolean on_zdo_bind_bind_req(ZigbeeZdo_bind *zdo_bind_object,
 
        /* Update request structure */
        req.node_id = node_id;
-       g_variant_get(src_addr, "ay", &iter);
-       while (g_variant_iter_loop(iter, "y", req.src_addr[i])) {
+       g_variant_get(src_addr, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", req.src_addr[i])) {
                i++;
                if (i >= ZIGBEE_ZDO_BIND_ADDRESS_MAX_LEN + 1)
                        break;
        }
        req.src_ep = src_ep;
        req.cluster_id = cluster_id;
-       g_variant_get(dst_addr, "ay", &iter);
-       while (g_variant_iter_loop(iter, "y", req.dst_addr[i])) {
+       g_variant_get(dst_addr, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", req.dst_addr[i])) {
                i++;
                if (i >= ZIGBEE_ZDO_BIND_ADDRESS_MAX_LEN + 1)
                        break;
@@ -116,11 +158,29 @@ static void on_zdo_bind_unbind_req_resp(ZigBeeServiceInterface *service_interfac
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZdo_bind *bind_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;
+       }
+
+       bind_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("bind_object", bind_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zdo_bind_complete_unbind_req(bind_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zdo_bind_unbind_req(ZigbeeZdo_bind *zdo_bind_object,
@@ -148,16 +208,16 @@ static gboolean on_zdo_bind_unbind_req(ZigbeeZdo_bind *zdo_bind_object,
 
        /* Update request structure */
        req.node_id = node_id;
-       g_variant_get(src_addr, "ay", &iter);
-       while (g_variant_iter_loop(iter, "y", req.src_addr[i])) {
+       g_variant_get(src_addr, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", req.src_addr[i])) {
                i++;
                if (i >= ZIGBEE_ZDO_BIND_ADDRESS_MAX_LEN + 1)
                        break;
        }
        req.src_ep = src_ep;
        req.cluster_id = cluster_id;
-       g_variant_get(dst_addr, "ay", &iter);
-       while (g_variant_iter_loop(iter, "y", req.dst_addr[i])) {
+       g_variant_get(dst_addr, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", req.dst_addr[i])) {
                i++;
                if (i >= ZIGBEE_ZDO_BIND_ADDRESS_MAX_LEN + 1)
                        break;
@@ -203,15 +263,44 @@ static gboolean on_zdo_bind_unbind_req(ZigbeeZdo_bind *zdo_bind_object,
 void zigbee_service_dbus_interface_zdo_bind_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");
+       ZigbeeZdo_bind *bind_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);
+       bind_object = _service_interface_ref_zigbee_zdo_bind(service_interface);
+       zblib_check_null_ret("bind_object", bind_object);
+
        NOT_USED(noti_cb_data);
+
+       switch(noti_id) {
+       case ZBLIB_ZDO_BIND_NOTI_BIND_REQ: {
+               ZigbeeZdoBindUnbindNoti_t *rsp = (ZigbeeZdoBindUnbindNoti_t*)noti_data;
+
+               Z_LOGD("'bind_rsp' status : [0x%X]", rsp->status);
+
+               zigbee_zdo_bind_emit_bind_rsp(bind_object, rsp->status);
+       }
+       break;
+       case ZBLIB_ZDO_BIND_NOTI_UNBIND_REQ: {
+               ZigbeeZdoBindUnbindNoti_t *rsp = (ZigbeeZdoBindUnbindNoti_t*)noti_data;
+
+               Z_LOGD("'unbind_rsp' status : [0x%X]", rsp->status);
+
+               zigbee_zdo_bind_emit_unbind_rsp(bind_object, rsp->status);
+       }
+       break;
+       default:
+               Z_LOGE("Unexpected notification [%x]", noti_id);
+       break;
+       }
+
+       /* ZigbeeZdo_bind should be dereferenced */
+       g_object_unref(bind_object);
 }
 
 gboolean zigbee_service_dbus_interface_zdo_bind_init(ZigBeeServiceInterface *service_interface,
index 158ee08..95d7f8c 100644 (file)
@@ -31,6 +31,12 @@ typedef enum {
        ZBLIB_ZDO_BIND_OPS_UNBIND_REQ, /**< Unbind req */
 } ZblibZdoBindOps_e;
 
+/**< ZigBee 'ZCL bind' notification IDs */
+typedef enum {
+       ZBLIB_ZDO_BIND_NOTI_BIND_REQ = 1, /**< bind request response notification */
+       ZBLIB_ZDO_BIND_NOTI_UNBIND_REQ, /**< unbind request response notification */
+} ZblibZdoBindNoti_e;
+
 /* ZigBee 'ZDO bind' driver APIs */
 ZigBeeDriver *zblib_driver_zdo_bind_new(ZigBeePlugin *plugin,
        const gchar *driver_name,
index bd76f87..c2f7385 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <zblib.h>
 #include <zblib_driver.h>
+#include <zblib_plugin.h>
 #include <zblib_request.h>
 
 #include "zblib_driver_zdo_bind.h"
@@ -98,6 +99,7 @@ ZigBeeDriver *zblib_driver_zdo_bind_new(ZigBeePlugin *plugin,
        ZblibDriverZdoBindOps_t *ops)
 {
        ZigBeeDriver *driver = NULL;
+       ZigBeeService *service = NULL;
        ZblibDriverZdoBindPrivData_t *priv_data = NULL;
        gboolean ret;
 
@@ -113,6 +115,19 @@ ZigBeeDriver *zblib_driver_zdo_bind_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) {