#include "zigbee_service_interface_common.h"
+#include <zblib_driver_custom.h>
+
+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);
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+ NOT_USED(resp_data);
+ NOT_USED(resp_data_len);
+}
+
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,
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;
+ g_variant_get(payload, "ay", &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;
+
+ NOT_USED(cb_data);
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+ NOT_USED(resp_data);
+ NOT_USED(resp_data_len);
+}
+
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,
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;
+ g_variant_get(payload, "ay", &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;
+
+ NOT_USED(cb_data);
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+ NOT_USED(resp_data);
+ NOT_USED(resp_data_len);
+}
+
static gboolean on_custom_send_to_local(ZigbeeCustom *custom_object,
GDBusMethodInvocation *invocation,
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 */
+ g_variant_get(data, "ay", &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)
+{
+ if (NULL == service_interface) {
+ Z_LOGE("service_interface is NULL");
+ return;
+ }
+
+ NOT_USED(noti_id);
+ NOT_USED(noti_data);
+ NOT_USED(noti_data_len);
+ NOT_USED(noti_cb_data);
+}
+
+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;
}