2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Contact: Suresh Kumar N (suresh.n@samsung.com)
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include "zigbee_service_interface_common.h"
21 #include <zblib_driver_zcl_global_control.h>
24 static void *_service_interface_ref_zigbee_zcl_global_control(ZigBeeServiceInterface *service_interface)
26 ZigbeeObjectSkeleton *zigbee_object = NULL;
27 ZigbeeCustomData_t *custom_data = NULL;
28 ZigbeeZcl_global_control *global_control_object = NULL;
30 custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
31 if (NULL == custom_data) {
32 Z_LOGE("D-BUS service interface custom_data is NULL!");
36 /* Get zigbee object */
37 zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
38 if (NULL == zigbee_object) {
39 Z_LOGW("Cannot find ZigBee D-BUS interface object!");
43 global_control_object = zigbee_object_get_zcl_global_control(ZIGBEE_OBJECT(zigbee_object));
44 return global_control_object;
47 static void on_zclglobal_control_read_attributes_req_resp(ZigBeeServiceInterface *service_interface,
48 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
50 ZigbeeServiceInterfaceRespCbData_t *cb_data =
51 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
53 ZigbeeZcl_global_control *global_control_object;
54 GDBusMethodInvocation *invocation;
56 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
58 NOT_USED(service_interface);
61 if (NULL == resp_data || 0 == resp_data_len) {
62 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
67 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
68 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
70 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
71 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
73 zigbee_zcl_global_control_complete_read_attributes_req(global_control_object,
74 invocation, payload->result);
79 static gboolean on_zclglobal_control_read_attributes_req(ZigbeeZcl_global_control *zclglobal_control_object,
80 GDBusMethodInvocation *invocation,
81 GVariant *attribute_id,
82 gint attribute_ids_length,
89 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
90 ZigbeeZclGlobalControlReadAttributesRequest_t req;
91 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
93 GVariantIter *iter = NULL;
98 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlReadAttributesRequest_t));
100 req.attribute_id = g_try_malloc0_n(attribute_ids_length, sizeof(unsigned short));
101 if (NULL == req.attribute_id) {
102 Z_LOGE("Failed to allocation !");
104 /* Send failure response */
105 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
110 /* Update request structure */
111 g_variant_get(attribute_id, "a(y)", &iter);
112 while (g_variant_iter_loop(iter, "(y)", &(req.attribute_id[i]))) {
114 if (i >= (attribute_ids_length * sizeof(unsigned short)))
117 req.attribute_id_len = attribute_ids_length;
118 req.node_id = node_id;
119 req.cluster_id = cluster_id;
120 req.zcl_frame_ctrl = zcl_frame_ctrl;
121 req.dest_ep = dest_ep;
123 /* Allocate response callback data */
125 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
126 invocation, NULL, 0);
127 if (NULL == resp_cb_data) {
128 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
130 /* Send failure response */
131 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
136 /* Dispatch request */
137 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
138 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
139 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_READ_ATTRIBUTES_REQ,
141 on_zclglobal_control_read_attributes_req_resp, resp_cb_data);
143 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
145 /* Free response callback data */
146 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
148 /* Send failure response */
149 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
157 static void on_zclglobal_control_write_attributes_req_resp(ZigBeeServiceInterface *service_interface,
158 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
160 ZigbeeServiceInterfaceRespCbData_t *cb_data =
161 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
163 ZigbeeZcl_global_control *global_control_object;
164 GDBusMethodInvocation *invocation;
166 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
168 NOT_USED(service_interface);
169 NOT_USED(request_id);
171 if (NULL == resp_data || 0 == resp_data_len) {
172 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
177 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
178 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
180 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
181 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
183 zigbee_zcl_global_control_complete_write_attributes_req(global_control_object,
184 invocation, payload->result);
189 static gboolean on_zclglobal_control_write_attributes_req(ZigbeeZcl_global_control *zclglobal_control_object,
190 GDBusMethodInvocation *invocation,
191 GVariant *write_attribute,
195 gchar zcl_frame_ctrl,
200 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
201 ZigbeeZclGlobalControlWriteAttributesRequest_t req;
202 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
204 GVariantIter *iter = NULL;
209 Z_LOGI("DBus Service interface: [%p]", service_interface);
211 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesRequest_t));
213 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
214 if (NULL == req.write_records) {
215 Z_LOGE("Failed to allocation !");
217 /* Send failure response */
218 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
220 g_free(req.write_records);
224 Z_LOGI("DBus Service interface: [%p]", service_interface);
226 /* Update request structure */
227 g_variant_get(write_attribute, "a(y)", &iter);
228 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
230 if (i >= records_length)
233 req.records_len = records_length;
234 req.node_id = node_id;
235 req.cluster_id = cluster_id;
236 req.zcl_frame_ctrl = zcl_frame_ctrl;
238 req.dest_ep = dest_ep;
240 /* Allocate response callback data */
242 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
243 invocation, NULL, 0);
244 if (NULL == resp_cb_data) {
245 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
247 /* Send failure response */
248 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
250 g_free(req.write_records);
254 /* Dispatch request */
255 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
256 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
257 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_REQ,
259 on_zclglobal_control_write_attributes_req_resp, resp_cb_data);
262 g_free(req.write_records);
265 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
267 /* Free response callback data */
268 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
270 /* Send failure response */
271 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
279 static void on_zclglobal_control_write_attributes_undivided_req_resp(ZigBeeServiceInterface *service_interface,
280 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
282 ZigbeeServiceInterfaceRespCbData_t *cb_data =
283 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
285 ZigbeeZcl_global_control *global_control_object;
286 GDBusMethodInvocation *invocation;
288 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
290 NOT_USED(service_interface);
291 NOT_USED(request_id);
293 if (NULL == resp_data || 0 == resp_data_len) {
294 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
299 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
300 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
302 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
303 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
305 zigbee_zcl_global_control_complete_write_attributes_undivided_req(global_control_object,
306 invocation, payload->result);
311 static gboolean on_zclglobal_control_write_attributes_undivided_req(ZigbeeZcl_global_control *zclglobal_control_object,
312 GDBusMethodInvocation *invocation,
313 GVariant *write_attribute,
317 gchar zcl_frame_ctrl,
322 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
323 ZigbeeZclGlobalControlWriteAttributesUndividedRequest_t req;
324 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
326 GVariantIter *iter = NULL;
331 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesUndividedRequest_t));
333 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
334 if (NULL == req.write_records) {
335 Z_LOGE("Failed to allocation !");
337 /* Send failure response */
338 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
340 g_free(req.write_records);
344 /* Update request structure */
345 g_variant_get(write_attribute, "a(y)", &iter);
346 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
348 if (i >= records_length)
351 req.records_len = records_length;
352 req.node_id = node_id;
353 req.cluster_id = cluster_id;
354 req.zcl_frame_ctrl = zcl_frame_ctrl;
356 req.dest_ep = dest_ep;
358 /* Allocate response callback data */
360 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
361 invocation, NULL, 0);
362 if (NULL == resp_cb_data) {
363 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
365 /* Send failure response */
366 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
368 g_free(req.write_records);
372 /* Dispatch request */
373 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
374 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
375 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_UNDIVIDED_REQ,
377 on_zclglobal_control_write_attributes_undivided_req_resp, resp_cb_data);
380 g_free(req.write_records);
383 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
385 /* Free response callback data */
386 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
388 /* Send failure response */
389 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
397 static void on_zclglobal_control_write_attributes_no_resp_resp(ZigBeeServiceInterface *service_interface,
398 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
400 ZigbeeServiceInterfaceRespCbData_t *cb_data =
401 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
403 ZigbeeZcl_global_control *global_control_object;
404 GDBusMethodInvocation *invocation;
406 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
408 NOT_USED(service_interface);
409 NOT_USED(request_id);
411 if (NULL == resp_data || 0 == resp_data_len) {
412 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
417 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
418 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
420 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
421 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
423 zigbee_zcl_global_control_complete_write_attributes_no_resp(global_control_object,
424 invocation, payload->result);
429 static gboolean on_zclglobal_control_write_attributes_no_resp(ZigbeeZcl_global_control *zclglobal_control_object,
430 GDBusMethodInvocation *invocation,
431 GVariant *write_attribute,
435 gchar zcl_frame_ctrl,
440 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
441 ZigbeeZclGlobalControlWriteAttributesNoResponse_t req;
442 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
444 GVariantIter *iter = NULL;
449 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesNoResponse_t));
451 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
452 if (NULL == req.write_records) {
453 Z_LOGE("Failed to allocation !");
455 /* Send failure response */
456 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
458 g_free(req.write_records);
462 /* Update request structure */
463 g_variant_get(write_attribute, "a(y)", &iter);
464 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
466 if (i >= records_length)
469 req.records_len = records_length;
470 req.node_id = node_id;
471 req.cluster_id = cluster_id;
472 req.zcl_frame_ctrl = zcl_frame_ctrl;
474 req.dest_ep = dest_ep;
476 /* Allocate response callback data */
478 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
479 invocation, NULL, 0);
480 if (NULL == resp_cb_data) {
481 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
483 /* Send failure response */
484 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
486 g_free(req.write_records);
490 /* Dispatch request */
491 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
492 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
493 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_NO_RESP,
495 on_zclglobal_control_write_attributes_no_resp_resp, resp_cb_data);
498 g_free(req.write_records);
501 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
503 /* Free response callback data */
504 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
506 /* Send failure response */
507 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
515 static void on_zclglobal_control_write_attributes_structured_resp(ZigBeeServiceInterface *service_interface,
516 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
518 ZigbeeServiceInterfaceRespCbData_t *cb_data =
519 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
521 ZigbeeZcl_global_control *global_control_object;
522 GDBusMethodInvocation *invocation;
524 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
526 NOT_USED(service_interface);
527 NOT_USED(request_id);
529 if (NULL == resp_data || 0 == resp_data_len) {
530 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
535 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
536 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
538 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
539 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
541 zigbee_zcl_global_control_complete_write_attributes_structured(global_control_object,
542 invocation, payload->result);
547 static gboolean on_zclglobal_control_write_attributes_structured(ZigbeeZcl_global_control *zclglobal_control_object,
548 GDBusMethodInvocation *invocation,
549 GVariant *write_attribute,
553 gchar zcl_frame_ctrl,
558 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
559 ZigbeeZclGlobalControlWriteAttributesStructed_t req;
560 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
562 GVariantIter *iter = NULL;
567 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesStructed_t));
569 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
570 if (NULL == req.write_records) {
571 Z_LOGE("Failed to allocation !");
573 /* Send failure response */
574 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
576 g_free(req.write_records);
580 /* Update request structure */
581 g_variant_get(write_attribute, "a(y)", &iter);
582 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
584 if (i >= records_length)
587 req.records_len = records_length;
588 req.node_id = node_id;
589 req.cluster_id = cluster_id;
590 req.zcl_frame_ctrl = zcl_frame_ctrl;
592 req.dest_ep = dest_ep;
594 /* Allocate response callback data */
596 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
597 invocation, NULL, 0);
598 if (NULL == resp_cb_data) {
599 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
601 /* Send failure response */
602 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
604 g_free(req.write_records);
608 /* Dispatch request */
609 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
610 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
611 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_STRUCTURED,
613 on_zclglobal_control_write_attributes_structured_resp, resp_cb_data);
616 g_free(req.write_records);
619 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
621 /* Free response callback data */
622 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
624 /* Send failure response */
625 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
633 static void on_zclglobal_control_read_attributes_structured_resp(ZigBeeServiceInterface *service_interface,
634 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
636 ZigbeeServiceInterfaceRespCbData_t *cb_data =
637 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
639 ZigbeeZcl_global_control *global_control_object;
640 GDBusMethodInvocation *invocation;
642 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
644 NOT_USED(service_interface);
645 NOT_USED(request_id);
647 if (NULL == resp_data || 0 == resp_data_len) {
648 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
653 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
654 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
656 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
657 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
659 zigbee_zcl_global_control_complete_read_attributes_structured(global_control_object,
660 invocation, payload->result);
665 static gboolean on_zclglobal_control_read_attributes_structured(ZigbeeZcl_global_control *zclglobal_control_object,
666 GDBusMethodInvocation *invocation,
667 GVariant *read_attribute,
671 gchar zcl_frame_ctrl,
676 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
677 ZigbeeZclGlobalControlReadAttributesStructed_t req;
678 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
680 GVariantIter *iter = NULL;
685 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlReadAttributesStructed_t));
687 req.read_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
688 if (NULL == req.read_records) {
689 Z_LOGE("Failed to allocation !");
691 /* Send failure response */
692 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
694 g_free(req.read_records);
698 /* Update request structure */
699 g_variant_get(read_attribute, "a(y)", &iter);
700 while (g_variant_iter_loop(iter, "(y)", &(req.read_records[i]))) {
702 if (i >= records_length)
705 req.records_len = records_length;
706 req.node_id = node_id;
707 req.cluster_id = cluster_id;
708 req.zcl_frame_ctrl = zcl_frame_ctrl;
710 req.dest_ep = dest_ep;
712 /* Allocate response callback data */
714 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
715 invocation, NULL, 0);
716 if (NULL == resp_cb_data) {
717 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
719 /* Send failure response */
720 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
722 g_free(req.read_records);
726 /* Dispatch request */
727 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
728 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
729 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_READ_ATTRIBUTES_STRUCTURED,
731 on_zclglobal_control_read_attributes_structured_resp, resp_cb_data);
734 g_free(req.read_records);
737 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
739 /* Free response callback data */
740 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
742 /* Send failure response */
743 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
751 static void on_zclglobal_control_configure_reporting_req_resp(ZigBeeServiceInterface *service_interface,
752 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
754 ZigbeeServiceInterfaceRespCbData_t *cb_data =
755 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
757 ZigbeeZcl_global_control *global_control_object;
758 GDBusMethodInvocation *invocation;
760 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
762 NOT_USED(service_interface);
763 NOT_USED(request_id);
765 if (NULL == resp_data || 0 == resp_data_len) {
766 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
771 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
772 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
774 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
775 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
777 zigbee_zcl_global_control_complete_configure_reporting_req(global_control_object,
778 invocation, payload->result);
783 static gboolean on_zclglobal_control_configure_reporting_req(ZigbeeZcl_global_control *zclglobal_control_object,
784 GDBusMethodInvocation *invocation,
785 GVariant *read_attribute,
789 gchar zcl_frame_ctrl,
794 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
795 ZigbeeZclGlobalControlConfigureReportingReq_t req;
796 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
798 GVariantIter *iter = NULL;
803 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlConfigureReportingReq_t));
805 req.read_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
806 if (NULL == req.read_records) {
807 Z_LOGE("Failed to allocation !");
809 /* Send failure response */
810 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
812 g_free(req.read_records);
816 /* Update request structure */
817 g_variant_get(read_attribute, "a(y)", &iter);
818 while (g_variant_iter_loop(iter, "(y)", &(req.read_records[i]))) {
820 if (i >= records_length)
823 req.records_len = records_length;
824 req.node_id = node_id;
825 req.cluster_id = cluster_id;
826 req.zcl_frame_ctrl = zcl_frame_ctrl;
828 req.dest_ep = dest_ep;
830 /* Allocate response callback data */
832 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
833 invocation, NULL, 0);
834 if (NULL == resp_cb_data) {
835 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
837 /* Send failure response */
838 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
840 g_free(req.read_records);
844 /* Dispatch request */
845 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
846 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
847 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_CONFIGURE_REPORTING_REQ,
849 on_zclglobal_control_configure_reporting_req_resp, resp_cb_data);
852 g_free(req.read_records);
855 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
857 /* Free response callback data */
858 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
860 /* Send failure response */
861 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
869 static void on_zclglobal_control_read_configure_reporting_resp(ZigBeeServiceInterface *service_interface,
870 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
872 ZigbeeServiceInterfaceRespCbData_t *cb_data =
873 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
875 ZigbeeZcl_global_control *global_control_object;
876 GDBusMethodInvocation *invocation;
878 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
880 NOT_USED(service_interface);
881 NOT_USED(request_id);
883 if (NULL == resp_data || 0 == resp_data_len) {
884 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
889 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
890 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
892 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
893 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
895 zigbee_zcl_global_control_complete_read_configure_reporting(global_control_object,
896 invocation, payload->result);
901 static gboolean on_zclglobal_control_read_configure_reporting(ZigbeeZcl_global_control *zclglobal_control_object,
902 GDBusMethodInvocation *invocation,
903 GVariant *read_attribute,
907 gchar zcl_frame_ctrl,
912 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
913 ZigbeeZclGlobalControlReadConfigureReporting_t req;
914 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
916 GVariantIter *iter = NULL;
921 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlReadConfigureReporting_t));
923 req.read_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
924 if (NULL == req.read_records) {
925 Z_LOGE("Failed to allocation !");
927 /* Send failure response */
928 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
930 g_free(req.read_records);
934 /* Update request structure */
935 g_variant_get(read_attribute, "a(y)", &iter);
936 while (g_variant_iter_loop(iter, "(y)", &(req.read_records[i]))) {
938 if (i >= records_length)
941 req.records_len = records_length;
942 req.node_id = node_id;
943 req.cluster_id = cluster_id;
944 req.zcl_frame_ctrl = zcl_frame_ctrl;
946 req.dest_ep = dest_ep;
948 /* Allocate response callback data */
950 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
951 invocation, NULL, 0);
952 if (NULL == resp_cb_data) {
953 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
955 /* Send failure response */
956 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
958 g_free(req.read_records);
962 /* Dispatch request */
963 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
964 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
965 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_READ_CONFIGURE_REPORTING,
967 on_zclglobal_control_read_configure_reporting_resp, resp_cb_data);
970 g_free(req.read_records);
973 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
975 /* Free response callback data */
976 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
978 /* Send failure response */
979 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
987 static void on_zclglobal_control_discover_attributes_resp(ZigBeeServiceInterface *service_interface,
988 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
990 ZigbeeServiceInterfaceRespCbData_t *cb_data =
991 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
993 ZigbeeZcl_global_control *global_control_object;
994 GDBusMethodInvocation *invocation;
996 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
998 NOT_USED(service_interface);
999 NOT_USED(request_id);
1001 if (NULL == resp_data || 0 == resp_data_len) {
1002 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1007 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1008 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1010 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1011 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1013 zigbee_zcl_global_control_complete_discover_attributes(global_control_object,
1014 invocation, payload->result);
1019 static gboolean on_zclglobal_control_discover_attributes(ZigbeeZcl_global_control *zclglobal_control_object,
1020 GDBusMethodInvocation *invocation,
1023 gchar zcl_frame_ctrl,
1026 gchar max_attribute_count,
1029 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1030 ZigbeeZclGlobalControlDiscoverAttributes_t req;
1031 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1035 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverAttributes_t));
1037 /* Update request structure */
1038 req.node_id = node_id;
1039 req.dest_ep = dest_ep;
1040 req.zcl_frame_ctrl = zcl_frame_ctrl;
1041 req.cluster_id = cluster_id;
1042 req.start_attribute = start_attr;
1043 req.max_attribute_count = max_attribute_count;
1045 /* Allocate response callback data */
1047 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1048 invocation, NULL, 0);
1049 if (NULL == resp_cb_data) {
1050 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1052 /* Send failure response */
1053 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1058 /* Dispatch request */
1059 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1060 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1061 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_ATTRIBUTES,
1063 on_zclglobal_control_discover_attributes_resp, resp_cb_data);
1065 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1067 /* Free response callback data */
1068 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1070 /* Send failure response */
1071 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1079 static void on_zclglobal_control_discover_attributes_extended_resp(ZigBeeServiceInterface *service_interface,
1080 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1082 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1083 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1085 ZigbeeZcl_global_control *global_control_object;
1086 GDBusMethodInvocation *invocation;
1088 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
1090 NOT_USED(service_interface);
1091 NOT_USED(request_id);
1093 if (NULL == resp_data || 0 == resp_data_len) {
1094 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1099 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1100 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1102 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1103 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1105 zigbee_zcl_global_control_complete_discover_attributes_extended(global_control_object,
1106 invocation, payload->result);
1111 static gboolean on_zclglobal_control_discover_attributes_extended(ZigbeeZcl_global_control *zclglobal_control_object,
1112 GDBusMethodInvocation *invocation,
1115 gchar zcl_frame_ctrl,
1118 gchar max_attribute_count,
1121 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1122 ZigbeeZclGlobalControlDiscoverAttributesExtended_t req;
1123 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1127 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverAttributesExtended_t));
1129 /* Update request structure */
1130 req.node_id = node_id;
1131 req.dest_ep = dest_ep;
1132 req.zcl_frame_ctrl = zcl_frame_ctrl;
1133 req.cluster_id = cluster_id;
1134 req.start_attribute = start_attr;
1135 req.max_attribute_count = max_attribute_count;
1137 /* Allocate response callback data */
1139 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1140 invocation, NULL, 0);
1141 if (NULL == resp_cb_data) {
1142 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1144 /* Send failure response */
1145 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1150 /* Dispatch request */
1151 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1152 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1153 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_ATTRIBUTES_EXTENDED,
1155 on_zclglobal_control_discover_attributes_extended_resp, resp_cb_data);
1157 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1159 /* Free response callback data */
1160 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1162 /* Send failure response */
1163 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1171 static void on_zclglobal_control_discover_commands_received_resp(ZigBeeServiceInterface *service_interface,
1172 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1174 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1175 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1177 ZigbeeZcl_global_control *global_control_object;
1178 GDBusMethodInvocation *invocation;
1180 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
1182 NOT_USED(service_interface);
1183 NOT_USED(request_id);
1185 if (NULL == resp_data || 0 == resp_data_len) {
1186 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1191 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1192 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1194 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1195 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1197 zigbee_zcl_global_control_complete_discover_commands_received(global_control_object,
1198 invocation, payload->result);
1203 static gboolean on_zclglobal_control_discover_commands_received(ZigbeeZcl_global_control *zclglobal_control_object,
1204 GDBusMethodInvocation *invocation,
1207 gchar zcl_frame_ctrl,
1209 gshort start_command,
1210 gchar max_command_count,
1213 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1214 ZigbeeZclGlobalControlDiscoverCommandsReceived_t req;
1215 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1219 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverCommandsReceived_t));
1221 /* Update request structure */
1222 req.node_id = node_id;
1223 req.dest_ep = dest_ep;
1224 req.zcl_frame_ctrl = zcl_frame_ctrl;
1225 req.cluster_id = cluster_id;
1226 req.start_command = start_command;
1227 req.max_command_count = max_command_count;
1229 /* Allocate response callback data */
1231 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1232 invocation, NULL, 0);
1233 if (NULL == resp_cb_data) {
1234 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1236 /* Send failure response */
1237 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1242 /* Dispatch request */
1243 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1244 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1245 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_COMMANDS_RECEIVED,
1247 on_zclglobal_control_discover_commands_received_resp, resp_cb_data);
1249 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1251 /* Free response callback data */
1252 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1254 /* Send failure response */
1255 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1263 static void on_zclglobal_control_discover_commands_generated_resp(ZigBeeServiceInterface *service_interface,
1264 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1266 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1267 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1269 ZigbeeZcl_global_control *global_control_object;
1270 GDBusMethodInvocation *invocation;
1272 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
1274 NOT_USED(service_interface);
1275 NOT_USED(request_id);
1277 if (NULL == resp_data || 0 == resp_data_len) {
1278 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1283 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1284 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1286 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1287 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1289 zigbee_zcl_global_control_complete_discover_commands_generated(global_control_object,
1290 invocation, payload->result);
1295 static gboolean on_zclglobal_control_discover_commands_generated(ZigbeeZcl_global_control *zclglobal_control_object,
1296 GDBusMethodInvocation *invocation,
1299 gchar zcl_frame_ctrl,
1301 gshort start_command,
1302 gchar max_command_count,
1305 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1306 ZigbeeZclGlobalControlDiscoverCommandsGenerated_t req;
1307 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1311 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverCommandsGenerated_t));
1313 /* Update request structure */
1314 req.node_id = node_id;
1315 req.dest_ep = dest_ep;
1316 req.zcl_frame_ctrl = zcl_frame_ctrl;
1317 req.cluster_id = cluster_id;
1318 req.start_command = start_command;
1319 req.max_command_count = max_command_count;
1321 /* Allocate response callback data */
1323 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1324 invocation, NULL, 0);
1325 if (NULL == resp_cb_data) {
1326 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1328 /* Send failure response */
1329 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1334 /* Dispatch request */
1335 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1336 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1337 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_COMMANDS_GENERATED,
1339 on_zclglobal_control_discover_commands_generated_resp, resp_cb_data);
1341 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1343 /* Free response callback data */
1344 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1346 /* Send failure response */
1347 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1355 void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeServiceInterface *service_interface,
1356 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
1358 ZigbeeZcl_global_control *global_control_object = NULL;
1360 zblib_check_null_ret("service_interface", service_interface);
1362 if (NULL == noti_data || 0 == noti_data_len) {
1363 Z_LOGE("noti_data is NULL");
1367 global_control_object = _service_interface_ref_zigbee_zcl_global_control(service_interface);
1368 zblib_check_null_ret("global_control_object", global_control_object);
1370 NOT_USED(noti_cb_data);
1373 case ZBLIB_ZCL_GLOBAL_NOTI_READ_ATTR_RSP: {
1374 ZigbeeZclGlobalControlReadAttributesResp_t *attr_t =
1375 (ZigbeeZclGlobalControlReadAttributesResp_t*)noti_data;
1377 GVariant *v_values = NULL;
1378 v_values = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1379 attr_t->values, attr_t->record_length, TRUE, NULL, NULL);
1380 if (NULL == v_values) {
1381 Z_LOGE("Failed to create variant!");
1383 Z_LOGD("Read attributes resp");
1384 zigbee_zcl_global_control_emit_read_attributes_rsp(global_control_object,
1385 attr_t->node_id, attr_t->src_ep, v_values, attr_t->attribute_id,
1386 attr_t->cluster_id, attr_t->status, attr_t->type,
1387 attr_t->record_length, attr_t->is_string);
1390 g_variant_unref(v_values);
1393 case ZBLIB_ZCL_GLOBAL_NOTI_WRITE_ATTR_RSP: {
1394 ZigbeeZclGlobalControlWriteAttributesResp_t *attr_t =
1395 (ZigbeeZclGlobalControlWriteAttributesResp_t*)noti_data;
1397 GVariant *v_values = NULL;
1398 GVariant *v_attrs = NULL;
1399 v_values = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1400 attr_t->values, attr_t->record_length, TRUE, NULL, NULL);
1401 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1402 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1404 if (NULL == v_values || NULL == v_attrs) {
1405 Z_LOGE("Failed to create variant!");
1407 Z_LOGD("Write attributes resp");
1408 zigbee_zcl_global_control_emit_write_attributes_rsp(global_control_object,
1409 attr_t->node_id, attr_t->src_ep, v_values, v_attrs,
1410 attr_t->cluster_id, attr_t->record_length);
1413 g_variant_unref(v_values);
1415 g_variant_unref(v_attrs);
1418 case ZBLIB_ZCL_GLOBAL_NOTI_CONFIG_REPORT_RSP: {
1419 ZigbeeZclGlobalControlConfigReportResp_t *attr_t =
1420 (ZigbeeZclGlobalControlConfigReportResp_t*)noti_data;
1422 GVariant *v_status = NULL;
1423 GVariant *v_attrs = NULL;
1424 GVariant *v_dirs = NULL;
1425 v_status = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1426 attr_t->status_list, attr_t->record_length, TRUE, NULL, NULL);
1427 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1428 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1430 v_dirs = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1431 attr_t->dir_list, attr_t->record_length, TRUE, NULL, NULL);
1432 if (NULL == v_status || NULL == v_attrs || NULL == v_dirs) {
1433 Z_LOGE("Failed to create variant!");
1435 g_variant_unref(v_status);
1437 g_variant_unref(v_attrs);
1439 g_variant_unref(v_dirs);
1441 Z_LOGD("Configure reporting resp");
1442 zigbee_zcl_global_control_emit_configure_reporting_rsp(global_control_object,
1443 v_status, v_attrs, v_dirs, attr_t->cluster_id,
1444 attr_t->record_length, attr_t->node_id, attr_t->src_ep);
1448 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_ATTR_RSP: {
1449 ZigbeeZclGlobalControlDiscoverAttributeResp_t *attr_t =
1450 (ZigbeeZclGlobalControlDiscoverAttributeResp_t*)noti_data;
1452 GVariant *v_types = NULL;
1453 GVariant *v_attrs = NULL;
1454 v_types = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1455 attr_t->type_list, attr_t->record_length, TRUE, NULL, NULL);
1456 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1457 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1459 if (NULL == v_types || NULL == v_attrs) {
1460 Z_LOGE("Failed to create variant!");
1462 Z_LOGD("Discover attribute resp");
1463 zigbee_zcl_global_control_emit_discover_attribute_rsp(global_control_object,
1464 attr_t->node_id, attr_t->src_ep, v_types, v_attrs,
1465 attr_t->cluster_id, attr_t->record_length, attr_t->discovery_completed);
1468 g_variant_unref(v_types);
1470 g_variant_unref(v_attrs);
1473 case ZBLIB_ZCL_GLOBAL_NOTI_WRITE_ATTR_STRUCTURED_RSP: {
1474 ZigbeeZclGlobalControlWriteAttributeStructuredResp_t *attr_t =
1475 (ZigbeeZclGlobalControlWriteAttributeStructuredResp_t*)noti_data;
1477 GVariant *v_status = NULL;
1478 GVariant *v_attrs = NULL;
1479 GVariant *v_indicator = NULL;
1480 GVariantBuilder *index_builder = NULL;
1481 GVariant *v_index = NULL;
1484 v_status = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1485 attr_t->status_list, attr_t->record_length, TRUE, NULL, NULL);
1486 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1487 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1489 v_indicator = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1490 attr_t->indicator_list, attr_t->record_length, TRUE, NULL, NULL);
1492 if (NULL == v_status || NULL == v_attrs || NULL == v_indicator) {
1493 Z_LOGE("Failed to create variant!");
1495 g_variant_unref(v_status);
1497 g_variant_unref(v_attrs);
1499 g_variant_unref(v_indicator);
1503 index_builder = g_variant_builder_new(G_VARIANT_TYPE("aq"));
1504 if (NULL == index_builder) {
1505 Z_LOGE("Failed to create variant builder!");
1506 g_variant_unref(v_status);
1507 g_variant_unref(v_attrs);
1508 g_variant_unref(v_indicator);
1511 for (i = 0; i < attr_t->record_length; i++) {
1512 for (j = 0; j < attr_t->indicator_list[i]; j++)
1513 g_variant_builder_add(index_builder, "q", attr_t->index_list[i][j]);
1515 v_index = g_variant_builder_end(index_builder);
1516 g_variant_builder_unref(index_builder);
1518 Z_LOGD("Write attribute structured resp");
1519 zigbee_zcl_global_control_emit_write_attribute_structured_rsp(
1520 global_control_object,
1521 v_status, v_attrs, v_indicator, v_index,
1522 attr_t->cluster_id, attr_t->record_length,
1523 attr_t->node_id, attr_t->src_ep);
1525 g_variant_unref(v_status);
1527 g_variant_unref(v_attrs);
1529 g_variant_unref(v_indicator);
1532 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_CMDS_RECEIVED_RSP: {
1533 ZigbeeZclGlobalControlDiscoverCommandsReceivedResp_t *attr_t =
1534 (ZigbeeZclGlobalControlDiscoverCommandsReceivedResp_t*)noti_data;
1536 GVariant *v_commands = NULL;
1537 v_commands = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1538 attr_t->command_list, attr_t->list_count, TRUE, NULL, NULL);
1539 if (NULL == v_commands) {
1540 Z_LOGE("Failed to create variant!");
1542 Z_LOGD("Discover commands received resp");
1543 zigbee_zcl_global_control_emit_discover_commands_received_rsp(
1544 global_control_object,
1545 v_commands, attr_t->cluster_id, attr_t->list_count,
1546 attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
1549 g_variant_unref(v_commands);
1552 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_CMDS_GENERATED_RSP: {
1553 ZigbeeZclGlobalControlDiscoverCommandsGeneratedResp_t *attr_t =
1554 (ZigbeeZclGlobalControlDiscoverCommandsGeneratedResp_t*)noti_data;
1556 GVariant *v_commands = NULL;
1557 v_commands = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1558 attr_t->command_list, attr_t->list_count, TRUE, NULL, NULL);
1559 if (NULL == v_commands) {
1560 Z_LOGE("Failed to create variant!");
1562 Z_LOGD("Discover commands generated resp");
1563 zigbee_zcl_global_control_emit_discover_commands_generated_rsp(
1564 global_control_object,
1565 v_commands, attr_t->cluster_id, attr_t->list_count,
1566 attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
1569 g_variant_unref(v_commands);
1572 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_ATTR_EXT_RSP: {
1573 ZigbeeZclGlobalControlDiscoverAttributesExtendedResp_t *attr_t =
1574 (ZigbeeZclGlobalControlDiscoverAttributesExtendedResp_t*)noti_data;
1576 GVariant *v_attrs = NULL;
1577 GVariant *v_attrs_type = NULL;
1578 GVariant *v_access = NULL;
1579 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1580 attr_t->attribute_list, (sizeof(gushort) * attr_t->list_count),
1582 v_attrs_type = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1583 attr_t->attribute_type_list, attr_t->list_count, TRUE, NULL, NULL);
1584 v_access = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1585 attr_t->access_list, attr_t->list_count, TRUE, NULL, NULL);
1586 if (NULL == v_attrs_type || NULL == v_attrs || NULL == v_access) {
1587 Z_LOGE("Failed to create variant!");
1589 Z_LOGD("Discover attributes extended resp");
1590 zigbee_zcl_global_control_emit_discover_attributes_extended_rsp(
1591 global_control_object,
1592 v_attrs, v_attrs_type, v_access,
1593 attr_t->cluster_id, attr_t->list_count,
1594 attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
1597 g_variant_unref(v_attrs_type);
1599 g_variant_unref(v_attrs);
1601 g_variant_unref(v_access);
1604 case ZBLIB_ZCL_GLOBAL_NOTI_DEFAULT_RSP: {
1605 ZigbeeZclGlobalControlDefaultResp_t *attr_t =
1606 (ZigbeeZclGlobalControlDefaultResp_t*)noti_data;
1608 Z_LOGD("Global default resp");
1609 zigbee_zcl_global_control_emit_zcl_global_default_response(
1610 global_control_object,
1611 attr_t->node_id, attr_t->src_ep, attr_t->cluster_id,
1612 attr_t->command_id, attr_t->status);
1615 case ZBLIB_ZCL_GLOBAL_NOTI_REPORT_ATTR_HANDLER_RSP: {
1616 ZigbeeZclGlobalControlReportAttributeHandlerResp_t *attr_t =
1617 (ZigbeeZclGlobalControlReportAttributeHandlerResp_t*)noti_data;
1619 GVariant *v_attrs = NULL;
1620 GVariant *v_data_type = NULL;
1621 GVariant *v_values = NULL;
1622 GVariantBuilder *values_builder = NULL;
1625 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1626 attr_t->attribute_list, (sizeof(gushort) * attr_t->list_count),
1628 if (NULL == v_attrs) {
1629 Z_LOGE("Failed to create variant!");
1632 v_data_type = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1633 attr_t->data_type_list, attr_t->list_count, TRUE, NULL, NULL);
1634 if (NULL == v_data_type) {
1635 Z_LOGE("Failed to create variant!");
1637 g_variant_unref(v_attrs);
1641 values_builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
1642 if (NULL == values_builder) {
1643 Z_LOGE("Failed to create variant builder!");
1645 g_variant_unref(v_attrs);
1647 g_variant_unref(v_data_type);
1650 for (i = 0; i < attr_t->list_count; i++) {
1651 for (j = 0; j < attr_t->values_count[i]; j++)
1652 g_variant_builder_add(values_builder, "(y)", attr_t->values[i][j]);
1654 v_values = g_variant_builder_end(values_builder);
1655 g_variant_builder_unref(values_builder);
1657 Z_LOGD("Report attributes handler resp");
1658 zigbee_zcl_global_control_emit_report_attr_handler_rsp(
1659 global_control_object,
1660 attr_t->node_id, attr_t->src_ep, attr_t->cluster_id,
1661 v_attrs, v_data_type, v_values,
1662 attr_t->list_count);
1664 g_variant_unref(v_attrs);
1666 g_variant_unref(v_data_type);
1668 g_variant_unref(v_values);
1671 case ZBLIB_ZCL_GLOBAL_NOTI_READ_CONFIG_REPORT_RSP: {
1672 ZigbeeZclGlobalControlReadConfigureReportingResp_t *resp_t =
1673 (ZigbeeZclGlobalControlReadConfigureReportingResp_t *)noti_data;
1677 GVariant *v_entries = NULL;
1678 GVariantBuilder *entry_builder =
1679 g_variant_builder_new(G_VARIANT_TYPE("a(yyqyqqayq)"));
1680 if (NULL == entry_builder) {
1681 Z_LOGE("Failed to create variant builder!");
1685 for (i = 0; i < resp_t->record_count ; i++) {
1686 GVariantBuilder *change_builder =
1687 g_variant_builder_new(G_VARIANT_TYPE("ay"));
1688 if (NULL == change_builder) {
1689 Z_LOGE("Failed to create variant builder!");
1690 g_variant_builder_unref(entry_builder);
1694 for (v = 0; v < resp_t->entry_list[i].change_count; v++) {
1695 g_variant_builder_add(change_builder, "y",
1696 resp_t->entry_list[i].change[v]);
1699 g_variant_builder_add(entry_builder, "(yyqyqqayq)",
1700 resp_t->entry_list[i].status,
1701 resp_t->entry_list[i].dir,
1702 resp_t->entry_list[i].attribute_id,
1703 resp_t->entry_list[i].data_type,
1704 resp_t->entry_list[i].min_interval,
1705 resp_t->entry_list[i].max_interval,
1707 resp_t->entry_list[i].change_count,
1708 resp_t->entry_list[i].timeout);
1710 g_variant_builder_unref(change_builder);
1712 v_entries = g_variant_builder_end(entry_builder);
1713 g_variant_builder_unref(entry_builder);
1715 Z_LOGD("Read configure reporting resp");
1716 zigbee_zcl_global_control_emit_read_configure_reporting_rsp(
1717 global_control_object, resp_t->node_id, resp_t->src_ep,
1718 resp_t->cluster_id, resp_t->record_count, v_entries);
1721 g_variant_unref(v_entries);
1725 Z_LOGE("Unexpected notification [%x]", noti_id);
1729 /* ZigbeeZcl_global_control should be dereferenced */
1730 g_object_unref(global_control_object);
1732 /* LCOV_EXCL_STOP */
1734 gboolean zigbee_service_dbus_interface_zcl_global_control_init(ZigBeeServiceInterface *service_interface,
1735 ZigbeeObjectSkeleton *zigbee_object)
1737 ZigbeeZcl_global_control *zclglobal_control_object;
1739 if (NULL == service_interface) {
1740 /* LCOV_EXCL_START */
1741 Z_LOGE("service_interface is NULL");
1743 /* LCOV_EXCL_STOP */
1746 zclglobal_control_object = zigbee_zcl_global_control_skeleton_new();
1747 zigbee_object_skeleton_set_zcl_global_control(zigbee_object, zclglobal_control_object);
1748 g_object_unref(zclglobal_control_object);
1750 Z_LOGI("zclglobal_control_object: [%p]", zclglobal_control_object);
1753 * Register signal handlers for 'zclglobal_control' interface
1755 g_signal_connect(zclglobal_control_object,
1756 "handle-read-attributes-req",
1757 G_CALLBACK(on_zclglobal_control_read_attributes_req), service_interface);
1759 g_signal_connect(zclglobal_control_object,
1760 "handle-write-attributes-req",
1761 G_CALLBACK(on_zclglobal_control_write_attributes_req), service_interface);
1763 g_signal_connect(zclglobal_control_object,
1764 "handle-write-attributes-undivided-req",
1765 G_CALLBACK(on_zclglobal_control_write_attributes_undivided_req), service_interface);
1767 g_signal_connect(zclglobal_control_object,
1768 "handle-write-attributes-no-resp",
1769 G_CALLBACK(on_zclglobal_control_write_attributes_no_resp), service_interface);
1771 g_signal_connect(zclglobal_control_object,
1772 "handle-write-attributes-structured",
1773 G_CALLBACK(on_zclglobal_control_write_attributes_structured), service_interface);
1775 g_signal_connect(zclglobal_control_object,
1776 "handle-read-attributes-structured",
1777 G_CALLBACK(on_zclglobal_control_read_attributes_structured), service_interface);
1779 g_signal_connect(zclglobal_control_object,
1780 "handle-configure-reporting-req",
1781 G_CALLBACK(on_zclglobal_control_configure_reporting_req), service_interface);
1783 g_signal_connect(zclglobal_control_object,
1784 "handle-read-configure-reporting",
1785 G_CALLBACK(on_zclglobal_control_read_configure_reporting), service_interface);
1787 g_signal_connect(zclglobal_control_object,
1788 "handle-discover-attributes",
1789 G_CALLBACK(on_zclglobal_control_discover_attributes), service_interface);
1791 g_signal_connect(zclglobal_control_object,
1792 "handle-discover-attributes-extended",
1793 G_CALLBACK(on_zclglobal_control_discover_attributes_extended), service_interface);
1795 g_signal_connect(zclglobal_control_object,
1796 "handle-discover-commands-received",
1797 G_CALLBACK(on_zclglobal_control_discover_commands_received), service_interface);
1799 g_signal_connect(zclglobal_control_object,
1800 "handle-discover-commands-generated",
1801 G_CALLBACK(on_zclglobal_control_discover_commands_generated), service_interface);