#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;
- 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,
gshort profile_id,
gchar zcl_frame_ctrl,
gshort mfg_code,
+ gchar cmd_id,
+ gshort payload_len,
GVariant *payload,
gpointer user_data)
{
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;
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,
gshort cluster_id,
gchar zcl_frame_ctrl,
gchar cmd_id,
+ gshort payload_len,
GVariant *payload,
gpointer user_data)
{
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;
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)
{
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;
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,