#include "zigbee_service_interface_common.h"
+#include <zblib_driver_custom.h>
+
+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;
+
+ ZigbeeCustom *custom_object = NULL;
+ GDBusMethodInvocation *invocation = NULL;
+
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ 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,
GDBusMethodInvocation *invocation,
gshort node_id,
gchar aps_frame_ctrl,
gchar src_ep,
- gchar dst_ep,
+ gchar dest_ep,
gshort cluster_id,
gshort profile_id,
gchar zcl_frame_ctrl,
gshort mfg_code,
+ gchar cmd_id,
+ gshort payload_len,
GVariant *payload,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
-
- NOT_USED(custom_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(node_id);
- NOT_USED(aps_frame_ctrl);
- NOT_USED(src_ep);
- NOT_USED(dst_ep);
- NOT_USED(cluster_id);
- NOT_USED(profile_id);
- NOT_USED(zcl_frame_ctrl);
- NOT_USED(mfg_code);
- NOT_USED(payload);
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeCustomApsSend_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- /*
- * TODO -
- * Create and send request for processing
- */
+ GVariantIter *iter = NULL;
+ guint i = 0;
+
+ gboolean ret;
+
+ memset(&req, 0x0, sizeof(ZigbeeCustomApsSend_t));
+
+ /* Update request structure */
+ req.node_id = node_id;
+ req.aps_frame_ctrl = aps_frame_ctrl;
+ req.src_ep = src_ep;
+ req.dest_ep = dest_ep;
+ req.cluster_id = cluster_id;
+ req.profile_id = profile_id;
+ req.zcl_frame_ctrl = zcl_frame_ctrl;
+ req.mfg_code = mfg_code;
+ 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;
+ }
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(custom_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_CUSTOM,
+ ZBLIB_CUSTOM_OPS_APS_SEND,
+ &req, sizeof(req),
+ on_custom_aps_send_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_custom_zcl_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;
+
+ ZigbeeCustom *custom_object = NULL;
+ GDBusMethodInvocation *invocation = NULL;
+
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ 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,
GDBusMethodInvocation *invocation,
gshort node_id,
gchar src_ep,
- gchar dst_ep,
+ gchar dest_ep,
gshort cluster_id,
gchar zcl_frame_ctrl,
gchar cmd_id,
+ gshort payload_len,
GVariant *payload,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
-
- NOT_USED(custom_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(node_id);
- NOT_USED(src_ep);
- NOT_USED(dst_ep);
- NOT_USED(cluster_id);
- NOT_USED(zcl_frame_ctrl);
- NOT_USED(cmd_id);
- NOT_USED(payload);
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeCustomZclSend_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- /*
- * TODO -
- * Create and send request for processing
- */
+ GVariantIter *iter = NULL;
+ guint i = 0;
+
+ gboolean ret;
+
+ memset(&req, 0x0, sizeof(ZigbeeCustomZclSend_t));
+
+ /* Update request structure */
+ req.node_id = node_id;
+ req.src_ep = src_ep;
+ req.dest_ep = dest_ep;
+ req.cluster_id = cluster_id;
+ req.zcl_frame_ctrl = zcl_frame_ctrl;
+ 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;
+ }
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(custom_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_CUSTOM,
+ ZBLIB_CUSTOM_OPS_ZCL_SEND,
+ &req, sizeof(req),
+ on_custom_zcl_send_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_custom_send_to_local_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;
+
+ ZigbeeCustom *custom_object = NULL;
+ GDBusMethodInvocation *invocation = NULL;
+
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ 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)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeCustomSendToLocal_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(custom_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(data);
+ GVariantIter *iter = NULL;
+ guint i = 0;
- /*
- * TODO -
- * Create and send request for processing
- */
+ gboolean ret;
+
+ memset(&req, 0x0, sizeof(ZigbeeCustomSendToLocal_t));
+
+ /* Update request structure */
+ 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;
+ }
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(custom_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_CUSTOM,
+ ZBLIB_CUSTOM_OPS_SEND_TO_LOCAL,
+ &req, sizeof(req),
+ on_custom_send_to_local_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
-gboolean zigbee_service_dbus_interface_custom_init(ZigBeeService *service,
+void zigbee_service_dbus_interface_custom_notification(ZigBeeServiceInterface *service_interface,
+ guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
+{
+ 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;
+ }
+
+ 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,
ZigbeeObjectSkeleton *zigbee_object)
{
ZigbeeCustom *custom_object;
- if (NULL == service) {
- Z_LOGE("service is NULL");
+ if (NULL == service_interface) {
+ Z_LOGE("service_interface is NULL");
return FALSE;
}
*/
g_signal_connect(custom_object,
"handle-aps-send",
- G_CALLBACK(on_custom_aps_send), service);
+ G_CALLBACK(on_custom_aps_send), service_interface);
g_signal_connect(custom_object,
"handle-zcl-send",
- G_CALLBACK(on_custom_zcl_send), service);
+ G_CALLBACK(on_custom_zcl_send), service_interface);
g_signal_connect(custom_object,
"handle-send-to-local",
- G_CALLBACK(on_custom_send_to_local), service);
+ G_CALLBACK(on_custom_send_to_local), service_interface);
return TRUE;
}