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>
23 static void *_service_interface_ref_zigbee_zcl_global_control(ZigBeeServiceInterface *service_interface)
25 ZigbeeObjectSkeleton *zigbee_object = NULL;
26 ZigbeeCustomData_t *custom_data = NULL;
27 ZigbeeZcl_global_control *global_control_object = NULL;
29 custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
30 if (NULL == custom_data) {
31 Z_LOGE("D-BUS service interface custom_data is NULL!");
35 /* Get zigbee object */
36 zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
37 if (NULL == zigbee_object) {
38 Z_LOGW("Cannot find ZigBee D-BUS interface object!", zigbee_object);
42 global_control_object = zigbee_object_get_zcl_global_control(ZIGBEE_OBJECT(zigbee_object));
43 return global_control_object;
46 static void on_zclglobal_control_read_attributes_req_resp(ZigBeeServiceInterface *service_interface,
47 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
49 ZigbeeServiceInterfaceRespCbData_t *cb_data =
50 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
52 ZigbeeZcl_global_control *global_control_object;
53 GDBusMethodInvocation *invocation;
55 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
57 NOT_USED(service_interface);
60 if (NULL == resp_data || 0 == resp_data_len) {
61 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
66 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
67 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
69 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
70 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
72 zigbee_zcl_global_control_complete_read_attributes_req(global_control_object,
73 invocation, payload->result);
78 static gboolean on_zclglobal_control_read_attributes_req(ZigbeeZcl_global_control *zclglobal_control_object,
79 GDBusMethodInvocation *invocation,
80 GVariant *attribute_id,
81 gint attribute_ids_length,
88 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
89 ZigbeeZclGlobalControlReadAttributesRequest_t req;
90 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
92 GVariantIter *iter = NULL;
97 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlReadAttributesRequest_t));
99 req.attribute_id = g_try_malloc0_n(attribute_ids_length, sizeof(unsigned char));
100 if (NULL == req.attribute_id) {
101 Z_LOGE("Failed to allocation !");
103 /* Send failure response */
104 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
109 /* Update request structure */
110 g_variant_get(attribute_id, "a(y)", &iter);
111 while (g_variant_iter_loop(iter, "(y)", &(req.attribute_id[i]))) {
113 if (i >= attribute_ids_length)
116 req.attribute_id_len = attribute_ids_length;
117 req.node_id = node_id;
118 req.cluster_id = cluster_id;
119 req.zcl_frame_ctrl = zcl_frame_ctrl;
120 req.dest_ep = dest_ep;
122 /* Allocate response callback data */
124 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
125 invocation, NULL, 0);
126 if (NULL == resp_cb_data) {
127 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
129 /* Send failure response */
130 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
135 /* Dispatch request */
136 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
137 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
138 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_READ_ATTRIBUTES_REQ,
140 on_zclglobal_control_read_attributes_req_resp, resp_cb_data);
142 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
144 /* Free response callback data */
145 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
147 /* Send failure response */
148 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
156 static void on_zclglobal_control_write_attributes_req_resp(ZigBeeServiceInterface *service_interface,
157 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
159 ZigbeeServiceInterfaceRespCbData_t *cb_data =
160 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
162 ZigbeeZcl_global_control *global_control_object;
163 GDBusMethodInvocation *invocation;
165 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
167 NOT_USED(service_interface);
168 NOT_USED(request_id);
170 if (NULL == resp_data || 0 == resp_data_len) {
171 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
176 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
177 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
179 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
180 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
182 zigbee_zcl_global_control_complete_write_attributes_req(global_control_object,
183 invocation, payload->result);
188 static gboolean on_zclglobal_control_write_attributes_req(ZigbeeZcl_global_control *zclglobal_control_object,
189 GDBusMethodInvocation *invocation,
190 GVariant *write_attribute,
194 gchar zcl_frame_ctrl,
199 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
200 ZigbeeZclGlobalControlWriteAttributesRequest_t req;
201 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
203 GVariantIter *iter = NULL;
208 Z_LOGI("DBus Service interface: [%p]", service_interface);
210 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesRequest_t));
212 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
213 if (NULL == req.write_records) {
214 Z_LOGE("Failed to allocation !");
216 /* Send failure response */
217 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
222 Z_LOGI("DBus Service interface: [%p]", service_interface);
224 /* Update request structure */
225 g_variant_get(write_attribute, "a(y)", &iter);
226 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
228 if (i >= records_length)
231 req.records_len = records_length;
232 req.node_id = node_id;
233 req.cluster_id = cluster_id;
234 req.zcl_frame_ctrl = zcl_frame_ctrl;
236 req.dest_ep = dest_ep;
238 /* Allocate response callback data */
240 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
241 invocation, NULL, 0);
242 if (NULL == resp_cb_data) {
243 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
245 /* Send failure response */
246 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
251 /* Dispatch request */
252 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
253 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
254 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_REQ,
256 on_zclglobal_control_write_attributes_req_resp, resp_cb_data);
258 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
260 /* Free response callback data */
261 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
263 /* Send failure response */
264 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
272 static void on_zclglobal_control_write_attributes_undivided_req_resp(ZigBeeServiceInterface *service_interface,
273 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
275 ZigbeeServiceInterfaceRespCbData_t *cb_data =
276 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
278 ZigbeeZcl_global_control *global_control_object;
279 GDBusMethodInvocation *invocation;
281 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
283 NOT_USED(service_interface);
284 NOT_USED(request_id);
286 if (NULL == resp_data || 0 == resp_data_len) {
287 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
292 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
293 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
295 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
296 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
298 zigbee_zcl_global_control_complete_write_attributes_undivided_req(global_control_object,
299 invocation, payload->result);
304 static gboolean on_zclglobal_control_write_attributes_undivided_req(ZigbeeZcl_global_control *zclglobal_control_object,
305 GDBusMethodInvocation *invocation,
306 GVariant *write_attribute,
310 gchar zcl_frame_ctrl,
315 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
316 ZigbeeZclGlobalControlWriteAttributesUndividedRequest_t req;
317 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
319 GVariantIter *iter = NULL;
324 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesUndividedRequest_t));
326 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
327 if (NULL == req.write_records) {
328 Z_LOGE("Failed to allocation !");
330 /* Send failure response */
331 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
336 /* Update request structure */
337 g_variant_get(write_attribute, "a(y)", &iter);
338 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
340 if (i >= records_length)
343 req.records_len = records_length;
344 req.node_id = node_id;
345 req.cluster_id = cluster_id;
346 req.zcl_frame_ctrl = zcl_frame_ctrl;
348 req.dest_ep = dest_ep;
350 /* Allocate response callback data */
352 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
353 invocation, NULL, 0);
354 if (NULL == resp_cb_data) {
355 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
357 /* Send failure response */
358 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
363 /* Dispatch request */
364 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
365 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
366 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_UNDIVIDED_REQ,
368 on_zclglobal_control_write_attributes_undivided_req_resp, resp_cb_data);
370 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
372 /* Free response callback data */
373 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
375 /* Send failure response */
376 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
384 static void on_zclglobal_control_write_attributes_no_resp_resp(ZigBeeServiceInterface *service_interface,
385 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
387 ZigbeeServiceInterfaceRespCbData_t *cb_data =
388 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
390 ZigbeeZcl_global_control *global_control_object;
391 GDBusMethodInvocation *invocation;
393 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
395 NOT_USED(service_interface);
396 NOT_USED(request_id);
398 if (NULL == resp_data || 0 == resp_data_len) {
399 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
404 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
405 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
407 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
408 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
410 zigbee_zcl_global_control_complete_write_attributes_no_resp(global_control_object,
411 invocation, payload->result);
416 static gboolean on_zclglobal_control_write_attributes_no_resp(ZigbeeZcl_global_control *zclglobal_control_object,
417 GDBusMethodInvocation *invocation,
418 GVariant *write_attribute,
422 gchar zcl_frame_ctrl,
427 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
428 ZigbeeZclGlobalControlWriteAttributesNoResponse_t req;
429 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
431 GVariantIter *iter = NULL;
436 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesNoResponse_t));
438 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
439 if (NULL == req.write_records) {
440 Z_LOGE("Failed to allocation !");
442 /* Send failure response */
443 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
448 /* Update request structure */
449 g_variant_get(write_attribute, "a(y)", &iter);
450 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
452 if (i >= records_length)
455 req.records_len = records_length;
456 req.node_id = node_id;
457 req.cluster_id = cluster_id;
458 req.zcl_frame_ctrl = zcl_frame_ctrl;
460 req.dest_ep = dest_ep;
462 /* Allocate response callback data */
464 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
465 invocation, NULL, 0);
466 if (NULL == resp_cb_data) {
467 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
469 /* Send failure response */
470 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
475 /* Dispatch request */
476 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
477 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
478 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_NO_RESP,
480 on_zclglobal_control_write_attributes_no_resp_resp, resp_cb_data);
482 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
484 /* Free response callback data */
485 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
487 /* Send failure response */
488 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
496 static void on_zclglobal_control_write_attributes_structured_resp(ZigBeeServiceInterface *service_interface,
497 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
499 ZigbeeServiceInterfaceRespCbData_t *cb_data =
500 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
502 ZigbeeZcl_global_control *global_control_object;
503 GDBusMethodInvocation *invocation;
505 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
507 NOT_USED(service_interface);
508 NOT_USED(request_id);
510 if (NULL == resp_data || 0 == resp_data_len) {
511 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
516 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
517 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
519 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
520 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
522 zigbee_zcl_global_control_complete_write_attributes_structured(global_control_object,
523 invocation, payload->result);
528 static gboolean on_zclglobal_control_write_attributes_structured(ZigbeeZcl_global_control *zclglobal_control_object,
529 GDBusMethodInvocation *invocation,
530 GVariant *write_attribute,
534 gchar zcl_frame_ctrl,
539 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
540 ZigbeeZclGlobalControlWriteAttributesStructed_t req;
541 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
543 GVariantIter *iter = NULL;
548 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesStructed_t));
550 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
551 if (NULL == req.write_records) {
552 Z_LOGE("Failed to allocation !");
554 /* Send failure response */
555 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
560 /* Update request structure */
561 g_variant_get(write_attribute, "a(y)", &iter);
562 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
564 if (i >= records_length)
567 req.records_len = records_length;
568 req.node_id = node_id;
569 req.cluster_id = cluster_id;
570 req.zcl_frame_ctrl = zcl_frame_ctrl;
572 req.dest_ep = dest_ep;
574 /* Allocate response callback data */
576 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
577 invocation, NULL, 0);
578 if (NULL == resp_cb_data) {
579 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
581 /* Send failure response */
582 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
587 /* Dispatch request */
588 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
589 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
590 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_STRUCTURED,
592 on_zclglobal_control_write_attributes_structured_resp, resp_cb_data);
594 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
596 /* Free response callback data */
597 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
599 /* Send failure response */
600 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
608 static void on_zclglobal_control_read_attributes_structured_resp(ZigBeeServiceInterface *service_interface,
609 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
611 ZigbeeServiceInterfaceRespCbData_t *cb_data =
612 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
614 ZigbeeZcl_global_control *global_control_object;
615 GDBusMethodInvocation *invocation;
617 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
619 NOT_USED(service_interface);
620 NOT_USED(request_id);
622 if (NULL == resp_data || 0 == resp_data_len) {
623 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
628 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
629 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
631 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
632 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
634 zigbee_zcl_global_control_complete_read_attributes_structured(global_control_object,
635 invocation, payload->result);
640 static gboolean on_zclglobal_control_read_attributes_structured(ZigbeeZcl_global_control *zclglobal_control_object,
641 GDBusMethodInvocation *invocation,
642 GVariant *read_attribute,
646 gchar zcl_frame_ctrl,
651 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
652 ZigbeeZclGlobalControlReadAttributesStructed_t req;
653 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
655 GVariantIter *iter = NULL;
660 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlReadAttributesStructed_t));
662 req.read_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
663 if (NULL == req.read_records) {
664 Z_LOGE("Failed to allocation !");
666 /* Send failure response */
667 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
672 /* Update request structure */
673 g_variant_get(read_attribute, "a(y)", &iter);
674 while (g_variant_iter_loop(iter, "(y)", &(req.read_records[i]))) {
676 if (i >= records_length)
679 req.records_len = records_length;
680 req.node_id = node_id;
681 req.cluster_id = cluster_id;
682 req.zcl_frame_ctrl = zcl_frame_ctrl;
684 req.dest_ep = dest_ep;
686 /* Allocate response callback data */
688 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
689 invocation, NULL, 0);
690 if (NULL == resp_cb_data) {
691 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
693 /* Send failure response */
694 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
699 /* Dispatch request */
700 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
701 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
702 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_READ_ATTRIBUTES_STRUCTURED,
704 on_zclglobal_control_read_attributes_structured_resp, resp_cb_data);
706 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
708 /* Free response callback data */
709 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
711 /* Send failure response */
712 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
720 static void on_zclglobal_control_configure_reporting_req_resp(ZigBeeServiceInterface *service_interface,
721 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
723 ZigbeeServiceInterfaceRespCbData_t *cb_data =
724 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
726 ZigbeeZcl_global_control *global_control_object;
727 GDBusMethodInvocation *invocation;
729 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
731 NOT_USED(service_interface);
732 NOT_USED(request_id);
734 if (NULL == resp_data || 0 == resp_data_len) {
735 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
740 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
741 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
743 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
744 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
746 zigbee_zcl_global_control_complete_configure_reporting_req(global_control_object,
747 invocation, payload->result);
752 static gboolean on_zclglobal_control_configure_reporting_req(ZigbeeZcl_global_control *zclglobal_control_object,
753 GDBusMethodInvocation *invocation,
754 GVariant *read_attribute,
758 gchar zcl_frame_ctrl,
763 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
764 ZigbeeZclGlobalControlConfigureReportingReq_t req;
765 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
767 GVariantIter *iter = NULL;
772 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlConfigureReportingReq_t));
774 req.read_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
775 if (NULL == req.read_records) {
776 Z_LOGE("Failed to allocation !");
778 /* Send failure response */
779 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
784 /* Update request structure */
785 g_variant_get(read_attribute, "a(y)", &iter);
786 while (g_variant_iter_loop(iter, "(y)", &(req.read_records[i]))) {
788 if (i >= records_length)
791 req.records_len = records_length;
792 req.node_id = node_id;
793 req.cluster_id = cluster_id;
794 req.zcl_frame_ctrl = zcl_frame_ctrl;
796 req.dest_ep = dest_ep;
798 /* Allocate response callback data */
800 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
801 invocation, NULL, 0);
802 if (NULL == resp_cb_data) {
803 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
805 /* Send failure response */
806 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
811 /* Dispatch request */
812 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
813 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
814 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_CONFIGURE_REPORTING_REQ,
816 on_zclglobal_control_configure_reporting_req_resp, resp_cb_data);
818 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
820 /* Free response callback data */
821 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
823 /* Send failure response */
824 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
832 static void on_zclglobal_control_read_configure_reporting_resp(ZigBeeServiceInterface *service_interface,
833 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
835 ZigbeeServiceInterfaceRespCbData_t *cb_data =
836 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
838 ZigbeeZcl_global_control *global_control_object;
839 GDBusMethodInvocation *invocation;
841 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
843 NOT_USED(service_interface);
844 NOT_USED(request_id);
846 if (NULL == resp_data || 0 == resp_data_len) {
847 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
852 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
853 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
855 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
856 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
858 zigbee_zcl_global_control_complete_read_configure_reporting(global_control_object,
859 invocation, payload->result);
864 static gboolean on_zclglobal_control_read_configure_reporting(ZigbeeZcl_global_control *zclglobal_control_object,
865 GDBusMethodInvocation *invocation,
866 GVariant *read_attribute,
870 gchar zcl_frame_ctrl,
875 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
876 ZigbeeZclGlobalControlReadConfigureReporting_t req;
877 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
879 GVariantIter *iter = NULL;
884 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlReadConfigureReporting_t));
886 req.read_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
887 if (NULL == req.read_records) {
888 Z_LOGE("Failed to allocation !");
890 /* Send failure response */
891 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
896 /* Update request structure */
897 g_variant_get(read_attribute, "a(y)", &iter);
898 while (g_variant_iter_loop(iter, "(y)", &(req.read_records[i]))) {
900 if (i >= records_length)
903 req.records_len = records_length;
904 req.node_id = node_id;
905 req.cluster_id = cluster_id;
906 req.zcl_frame_ctrl = zcl_frame_ctrl;
908 req.dest_ep = dest_ep;
910 /* Allocate response callback data */
912 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
913 invocation, NULL, 0);
914 if (NULL == resp_cb_data) {
915 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
917 /* Send failure response */
918 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
923 /* Dispatch request */
924 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
925 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
926 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_READ_CONFIGURE_REPORTING,
928 on_zclglobal_control_read_configure_reporting_resp, resp_cb_data);
930 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
932 /* Free response callback data */
933 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
935 /* Send failure response */
936 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
944 static void on_zclglobal_control_discover_attributes_resp(ZigBeeServiceInterface *service_interface,
945 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
947 ZigbeeServiceInterfaceRespCbData_t *cb_data =
948 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
950 ZigbeeZcl_global_control *global_control_object;
951 GDBusMethodInvocation *invocation;
953 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
955 NOT_USED(service_interface);
956 NOT_USED(request_id);
958 if (NULL == resp_data || 0 == resp_data_len) {
959 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
964 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
965 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
967 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
968 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
970 zigbee_zcl_global_control_complete_discover_attributes(global_control_object,
971 invocation, payload->result);
976 static gboolean on_zclglobal_control_discover_attributes(ZigbeeZcl_global_control *zclglobal_control_object,
977 GDBusMethodInvocation *invocation,
980 gchar zcl_frame_ctrl,
983 gchar max_attribute_count,
986 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
987 ZigbeeZclGlobalControlDiscoverAttributes_t req;
988 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
992 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverAttributes_t));
994 /* Update request structure */
995 req.node_id = node_id;
996 req.dest_ep = dest_ep;
997 req.zcl_frame_ctrl = zcl_frame_ctrl;
998 req.cluster_id = cluster_id;
999 req.start_attribute = start_attr;
1000 req.max_attribute_count = max_attribute_count;
1002 /* Allocate response callback data */
1004 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1005 invocation, NULL, 0);
1006 if (NULL == resp_cb_data) {
1007 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1009 /* Send failure response */
1010 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1015 /* Dispatch request */
1016 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1017 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1018 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_ATTRIBUTES,
1020 on_zclglobal_control_discover_attributes_resp, resp_cb_data);
1022 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1024 /* Free response callback data */
1025 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1027 /* Send failure response */
1028 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1036 static void on_zclglobal_control_discover_attributes_extended_resp(ZigBeeServiceInterface *service_interface,
1037 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1039 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1040 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1042 ZigbeeZcl_global_control *global_control_object;
1043 GDBusMethodInvocation *invocation;
1045 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
1047 NOT_USED(service_interface);
1048 NOT_USED(request_id);
1050 if (NULL == resp_data || 0 == resp_data_len) {
1051 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1056 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1057 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1059 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1060 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1062 zigbee_zcl_global_control_complete_discover_attributes_extended(global_control_object,
1063 invocation, payload->result);
1068 static gboolean on_zclglobal_control_discover_attributes_extended(ZigbeeZcl_global_control *zclglobal_control_object,
1069 GDBusMethodInvocation *invocation,
1072 gchar zcl_frame_ctrl,
1075 gchar max_attribute_count,
1078 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1079 ZigbeeZclGlobalControlDiscoverAttributesExtended_t req;
1080 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1084 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverAttributesExtended_t));
1086 /* Update request structure */
1087 req.node_id = node_id;
1088 req.dest_ep = dest_ep;
1089 req.zcl_frame_ctrl = zcl_frame_ctrl;
1090 req.cluster_id = cluster_id;
1091 req.start_attribute = start_attr;
1092 req.max_attribute_count = max_attribute_count;
1094 /* Allocate response callback data */
1096 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1097 invocation, NULL, 0);
1098 if (NULL == resp_cb_data) {
1099 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1101 /* Send failure response */
1102 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1107 /* Dispatch request */
1108 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1109 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1110 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_ATTRIBUTES_EXTENDED,
1112 on_zclglobal_control_discover_attributes_extended_resp, resp_cb_data);
1114 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1116 /* Free response callback data */
1117 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1119 /* Send failure response */
1120 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1128 static void on_zclglobal_control_discover_commands_received_resp(ZigBeeServiceInterface *service_interface,
1129 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1131 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1132 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1134 ZigbeeZcl_global_control *global_control_object;
1135 GDBusMethodInvocation *invocation;
1137 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
1139 NOT_USED(service_interface);
1140 NOT_USED(request_id);
1142 if (NULL == resp_data || 0 == resp_data_len) {
1143 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1148 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1149 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1151 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1152 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1154 zigbee_zcl_global_control_complete_discover_commands_received(global_control_object,
1155 invocation, payload->result);
1160 static gboolean on_zclglobal_control_discover_commands_received(ZigbeeZcl_global_control *zclglobal_control_object,
1161 GDBusMethodInvocation *invocation,
1164 gchar zcl_frame_ctrl,
1166 gshort start_command,
1167 gchar max_command_count,
1170 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1171 ZigbeeZclGlobalControlDiscoverCommandsReceived_t req;
1172 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1176 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverCommandsReceived_t));
1178 /* Update request structure */
1179 req.node_id = node_id;
1180 req.dest_ep = dest_ep;
1181 req.zcl_frame_ctrl = zcl_frame_ctrl;
1182 req.cluster_id = cluster_id;
1183 req.start_command = start_command;
1184 req.max_command_count = max_command_count;
1186 /* Allocate response callback data */
1188 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1189 invocation, NULL, 0);
1190 if (NULL == resp_cb_data) {
1191 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1193 /* Send failure response */
1194 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1199 /* Dispatch request */
1200 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1201 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1202 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_COMMANDS_RECEIVED,
1204 on_zclglobal_control_discover_commands_received_resp, resp_cb_data);
1206 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1208 /* Free response callback data */
1209 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1211 /* Send failure response */
1212 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1220 static void on_zclglobal_control_discover_commands_generated_resp(ZigBeeServiceInterface *service_interface,
1221 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1223 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1224 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1226 ZigbeeZcl_global_control *global_control_object;
1227 GDBusMethodInvocation *invocation;
1229 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
1231 NOT_USED(service_interface);
1232 NOT_USED(request_id);
1234 if (NULL == resp_data || 0 == resp_data_len) {
1235 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1240 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1241 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1243 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1244 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1246 zigbee_zcl_global_control_complete_discover_commands_generated(global_control_object,
1247 invocation, payload->result);
1252 static gboolean on_zclglobal_control_discover_commands_generated(ZigbeeZcl_global_control *zclglobal_control_object,
1253 GDBusMethodInvocation *invocation,
1256 gchar zcl_frame_ctrl,
1258 gshort start_command,
1259 gchar max_command_count,
1262 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1263 ZigbeeZclGlobalControlDiscoverCommandsGenerated_t req;
1264 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1268 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverCommandsGenerated_t));
1270 /* Update request structure */
1271 req.node_id = node_id;
1272 req.dest_ep = dest_ep;
1273 req.zcl_frame_ctrl = zcl_frame_ctrl;
1274 req.cluster_id = cluster_id;
1275 req.start_command = start_command;
1276 req.max_command_count = max_command_count;
1278 /* Allocate response callback data */
1280 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1281 invocation, NULL, 0);
1282 if (NULL == resp_cb_data) {
1283 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1285 /* Send failure response */
1286 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1291 /* Dispatch request */
1292 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1293 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1294 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_COMMANDS_GENERATED,
1296 on_zclglobal_control_discover_commands_generated_resp, resp_cb_data);
1298 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1300 /* Free response callback data */
1301 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1303 /* Send failure response */
1304 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1312 void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeServiceInterface *service_interface,
1313 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
1315 ZigbeeZcl_global_control *global_control_object = NULL;
1317 zblib_check_null_ret("service_interface", service_interface);
1319 if (NULL == noti_data || 0 == noti_data_len) {
1320 Z_LOGE("noti_data is NULL");
1324 global_control_object = _service_interface_ref_zigbee_zcl_global_control(service_interface);
1325 zblib_check_null_ret("global_control_object", global_control_object);
1327 NOT_USED(noti_cb_data);
1330 case ZBLIB_ZCL_GLOBAL_NOTI_READ_ATTR_RSP: {
1331 ZigbeeZclGlobalControlReadAttributesResp_t *attr_t =
1332 (ZigbeeZclGlobalControlReadAttributesResp_t*)noti_data;
1334 GVariant *v_values = NULL;
1335 v_values = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1336 attr_t->values, attr_t->record_length, TRUE, NULL, NULL);
1337 if (NULL == v_values) {
1338 Z_LOGE("Failed to create variant!");
1340 Z_LOGD("Read attributes resp");
1341 zigbee_zcl_global_control_emit_read_attributes_rsp(global_control_object,
1342 attr_t->node_id, attr_t->src_ep, v_values, attr_t->attribute_id,
1343 attr_t->cluster_id, attr_t->status, attr_t->type,
1344 attr_t->record_length, attr_t->is_string);
1348 case ZBLIB_ZCL_GLOBAL_NOTI_WRITE_ATTR_RSP: {
1349 ZigbeeZclGlobalControlWriteAttributesResp_t *attr_t =
1350 (ZigbeeZclGlobalControlWriteAttributesResp_t*)noti_data;
1352 GVariant *v_values = NULL;
1353 GVariant *v_attrs = NULL;
1354 v_values = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1355 attr_t->values, attr_t->record_length, TRUE, NULL, NULL);
1356 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1357 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1359 if (NULL == v_values || NULL == v_attrs) {
1360 Z_LOGE("Failed to create variant!");
1362 g_variant_unref(v_values);
1364 g_variant_unref(v_attrs);
1366 Z_LOGD("Write attributes resp");
1367 zigbee_zcl_global_control_emit_write_attributes_rsp(global_control_object,
1368 attr_t->node_id, attr_t->src_ep, v_values, v_attrs,
1369 attr_t->cluster_id, attr_t->record_length);
1373 case ZBLIB_ZCL_GLOBAL_NOTI_CONFIG_REPORT_RSP: {
1374 ZigbeeZclGlobalControlConfigReportResp_t *attr_t =
1375 (ZigbeeZclGlobalControlConfigReportResp_t*)noti_data;
1377 GVariant *v_status = NULL;
1378 GVariant *v_attrs = NULL;
1379 GVariant *v_dirs = NULL;
1380 v_status = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1381 attr_t->status_list, attr_t->record_length, TRUE, NULL, NULL);
1382 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1383 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1385 v_dirs = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1386 attr_t->dir_list, attr_t->record_length, TRUE, NULL, NULL);
1387 if (NULL == v_status || NULL == v_attrs || NULL == v_dirs) {
1388 Z_LOGE("Failed to create variant!");
1390 g_variant_unref(v_status);
1392 g_variant_unref(v_attrs);
1394 g_variant_unref(v_dirs);
1396 Z_LOGD("Configure reporting resp");
1397 zigbee_zcl_global_control_emit_configure_reporting_rsp(global_control_object,
1398 v_status, v_attrs, v_dirs, attr_t->cluster_id,
1399 attr_t->record_length, attr_t->node_id, attr_t->src_ep);
1403 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_ATTR_RSP: {
1404 ZigbeeZclGlobalControlDiscoverAttributeResp_t *attr_t =
1405 (ZigbeeZclGlobalControlDiscoverAttributeResp_t*)noti_data;
1407 GVariant *v_types = NULL;
1408 GVariant *v_attrs = NULL;
1409 v_types = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1410 attr_t->type_list, attr_t->record_length, TRUE, NULL, NULL);
1411 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1412 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1414 if (NULL == v_types || NULL == v_attrs) {
1415 Z_LOGE("Failed to create variant!");
1417 g_variant_unref(v_types);
1419 g_variant_unref(v_attrs);
1421 Z_LOGD("Discover attribute resp");
1422 zigbee_zcl_global_control_emit_discover_attribute_rsp(global_control_object,
1423 attr_t->node_id, attr_t->src_ep, v_types, v_attrs,
1424 attr_t->cluster_id, attr_t->record_length, attr_t->discovery_completed);
1428 case ZBLIB_ZCL_GLOBAL_NOTI_WRITE_ATTR_STRUCTURED_RSP: {
1429 ZigbeeZclGlobalControlWriteAttributeStructuredResp_t *attr_t =
1430 (ZigbeeZclGlobalControlWriteAttributeStructuredResp_t*)noti_data;
1432 GVariant *v_status = NULL;
1433 GVariant *v_attrs = NULL;
1434 GVariant *v_indicator = NULL;
1435 GVariantBuilder *index_builder = NULL;
1436 GVariant *v_index = NULL;
1439 v_status = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1440 attr_t->status_list, attr_t->record_length, TRUE, NULL, NULL);
1441 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1442 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1444 v_indicator = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1445 attr_t->indicator_list, attr_t->record_length, TRUE, NULL, NULL);
1447 if (NULL == v_status || NULL == v_attrs || NULL == v_indicator) {
1448 Z_LOGE("Failed to create variant!");
1450 g_variant_unref(v_status);
1452 g_variant_unref(v_attrs);
1454 g_variant_unref(v_indicator);
1458 index_builder = g_variant_builder_new (G_VARIANT_TYPE ("aq"));
1459 if (NULL == index_builder) {
1460 Z_LOGE("Failed to create variant builder!");
1461 g_variant_unref(v_status);
1462 g_variant_unref(v_attrs);
1463 g_variant_unref(v_indicator);
1466 for(i = 0; i < attr_t->record_length; i++) {
1467 for(j = 0; j < attr_t->indicator_list[i]; j++) {
1468 g_variant_builder_add (index_builder, "q", attr_t->index_list[i][j]);
1471 v_index = g_variant_builder_end (index_builder);
1472 g_variant_builder_unref(index_builder);
1473 if (NULL == index_builder) {
1474 Z_LOGE("Failed to create variant!");
1475 g_variant_unref(v_status);
1476 g_variant_unref(v_attrs);
1477 g_variant_unref(v_indicator);
1481 Z_LOGD("Write attribute structured resp");
1482 zigbee_zcl_global_control_emit_write_attribute_structured_rsp(
1483 global_control_object,
1484 v_status, v_attrs, v_indicator, v_index,
1485 attr_t->cluster_id, attr_t->record_length,
1486 attr_t->node_id, attr_t->src_ep);
1489 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_CMDS_RECEIVED_RSP: {
1490 ZigbeeZclGlobalControlDiscoverCommandsReceivedResp_t *attr_t =
1491 (ZigbeeZclGlobalControlDiscoverCommandsReceivedResp_t*)noti_data;
1493 GVariant *v_commands = NULL;
1494 v_commands = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1495 attr_t->command_list, attr_t->list_count, TRUE, NULL, NULL);
1496 if (NULL == v_commands) {
1497 Z_LOGE("Failed to create variant!");
1499 Z_LOGD("Discover commands received resp");
1500 zigbee_zcl_global_control_emit_discover_commands_received_rsp(
1501 global_control_object,
1502 v_commands, attr_t->cluster_id, attr_t->list_count,
1503 attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
1507 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_CMDS_GENERATED_RSP: {
1508 ZigbeeZclGlobalControlDiscoverCommandsGeneratedResp_t *attr_t =
1509 (ZigbeeZclGlobalControlDiscoverCommandsGeneratedResp_t*)noti_data;
1511 GVariant *v_commands = NULL;
1512 v_commands = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1513 attr_t->command_list, attr_t->list_count, TRUE, NULL, NULL);
1514 if (NULL == v_commands) {
1515 Z_LOGE("Failed to create variant!");
1517 Z_LOGD("Discover commands generated resp");
1518 zigbee_zcl_global_control_emit_discover_commands_generated_rsp(
1519 global_control_object,
1520 v_commands, attr_t->cluster_id, attr_t->list_count,
1521 attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
1525 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_ATTR_EXT_RSP: {
1526 ZigbeeZclGlobalControlDiscoverAttributesExtendedResp_t *attr_t =
1527 (ZigbeeZclGlobalControlDiscoverAttributesExtendedResp_t*)noti_data;
1529 GVariant *v_attrs = NULL;
1530 GVariant *v_attrs_type = NULL;
1531 GVariant *v_access = NULL;
1532 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1533 attr_t->attribute_list, (sizeof(gushort) * attr_t->list_count),
1535 v_attrs_type = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1536 attr_t->attribute_type_list, attr_t->list_count, TRUE, NULL, NULL);
1537 v_access = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1538 attr_t->access_list, attr_t->list_count, TRUE, NULL, NULL);
1539 if (NULL == v_attrs_type || NULL == v_attrs || NULL == v_access) {
1540 Z_LOGE("Failed to create variant!");
1542 g_variant_unref(v_attrs_type);
1544 g_variant_unref(v_attrs);
1546 g_variant_unref(v_access);
1548 Z_LOGD("Discover attributes extended resp");
1549 zigbee_zcl_global_control_emit_discover_attributes_extended_rsp(
1550 global_control_object,
1551 v_attrs, v_attrs_type, v_access,
1552 attr_t->cluster_id, attr_t->list_count,
1553 attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
1557 case ZBLIB_ZCL_GLOBAL_NOTI_DEFAULT_RSP: {
1558 ZigbeeZclGlobalControlDefaultResp_t *attr_t =
1559 (ZigbeeZclGlobalControlDefaultResp_t*)noti_data;
1561 Z_LOGD("Global default resp");
1562 zigbee_zcl_global_control_emit_zcl_global_default_response(
1563 global_control_object,
1564 attr_t->node_id, attr_t->src_ep, attr_t->cluster_id,
1565 attr_t->command_id, attr_t->status);
1568 case ZBLIB_ZCL_GLOBAL_NOTI_REPORT_ATTR_HANDLER_RSP: {
1569 ZigbeeZclGlobalControlReportAttributeHandlerResp_t *attr_t =
1570 (ZigbeeZclGlobalControlReportAttributeHandlerResp_t*)noti_data;
1572 GVariant *v_attrs = NULL;
1573 GVariant *v_data_type = NULL;
1574 GVariant *v_values = NULL;
1575 GVariantBuilder *values_builder = NULL;
1578 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1579 attr_t->attribute_list, (sizeof(gushort) * attr_t->list_count),
1581 v_data_type = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1582 attr_t->data_type_list, attr_t->list_count, TRUE, NULL, NULL);
1583 if (NULL == v_data_type || NULL == v_attrs) {
1584 Z_LOGE("Failed to create variant!");
1586 g_variant_unref(v_data_type);
1588 g_variant_unref(v_attrs);
1592 values_builder = g_variant_builder_new (G_VARIANT_TYPE ("a(y)"));
1593 if (NULL == values_builder) {
1594 Z_LOGE("Failed to create variant builder!");
1595 g_variant_unref(v_data_type);
1596 g_variant_unref(v_attrs);
1599 for(i = 0; i < attr_t->list_count; i++) {
1600 for(j = 0; j < attr_t->values_count[i]; j++) {
1601 g_variant_builder_add (values_builder, "(y)", attr_t->values[i][j]);
1604 v_values = g_variant_builder_end (values_builder);
1605 g_variant_builder_unref(values_builder);
1606 if (NULL == values_builder) {
1607 Z_LOGE("Failed to create variant!");
1608 g_variant_unref(v_data_type);
1609 g_variant_unref(v_attrs);
1613 Z_LOGD("Report attributes handler resp");
1614 zigbee_zcl_global_control_emit_report_attr_handler_rsp(
1615 global_control_object,
1616 attr_t->node_id, attr_t->src_ep, attr_t->cluster_id,
1617 v_attrs, v_data_type, v_values,
1618 attr_t->list_count);
1621 case ZBLIB_ZCL_GLOBAL_NOTI_READ_CONFIG_REPORT_RSP: {
1622 ZigbeeZclGlobalControlReadConfigureReportingResp_t *resp_t =
1623 (ZigbeeZclGlobalControlReadConfigureReportingResp_t *)noti_data;
1627 GVariant *v_entries = NULL;
1628 GVariantBuilder *entry_builder =
1629 g_variant_builder_new (G_VARIANT_TYPE ("a(yyqyqqayq)"));
1630 if (NULL == entry_builder) {
1631 Z_LOGE("Failed to create variant builder!");
1635 for(i = 0; i < resp_t->record_count ; i++) {
1636 GVariantBuilder *change_builder =
1637 g_variant_builder_new (G_VARIANT_TYPE ("ay"));
1638 if (NULL == change_builder) {
1639 Z_LOGE("Failed to create variant builder!");
1640 g_variant_builder_unref(entry_builder);
1644 for (v = 0; v < resp_t->entry_list[i].change_count; v++) {
1645 g_variant_builder_add (change_builder, "y",
1646 resp_t->entry_list[i].change[v]);
1649 g_variant_builder_add (entry_builder, "(yyqyqqayq)",
1650 resp_t->entry_list[i].status,
1651 resp_t->entry_list[i].dir,
1652 resp_t->entry_list[i].attribute_id,
1653 resp_t->entry_list[i].data_type,
1654 resp_t->entry_list[i].min_interval,
1655 resp_t->entry_list[i].max_interval,
1657 resp_t->entry_list[i].change_count,
1658 resp_t->entry_list[i].timeout);
1660 g_variant_builder_unref(change_builder);
1662 v_entries = g_variant_builder_end(entry_builder);
1663 g_variant_builder_unref(entry_builder);
1665 Z_LOGD("Read configure reporting resp");
1666 zigbee_zcl_global_control_emit_read_configure_reporting_rsp(
1667 global_control_object, resp_t->node_id, resp_t->src_ep,
1668 resp_t->cluster_id, resp_t->record_count, v_entries);
1672 Z_LOGE("Unexpected notification [%x]", noti_id);
1676 /* ZigbeeZcl_global_control should be dereferenced */
1677 g_object_unref(global_control_object);
1680 gboolean zigbee_service_dbus_interface_zcl_global_control_init(ZigBeeServiceInterface *service_interface,
1681 ZigbeeObjectSkeleton *zigbee_object)
1683 ZigbeeZcl_global_control *zclglobal_control_object;
1685 if (NULL == service_interface) {
1686 Z_LOGE("service_interface is NULL");
1690 zclglobal_control_object = zigbee_zcl_global_control_skeleton_new();
1691 zigbee_object_skeleton_set_zcl_global_control(zigbee_object, zclglobal_control_object);
1692 g_object_unref(zclglobal_control_object);
1694 Z_LOGI("zclglobal_control_object: [%p]", zclglobal_control_object);
1697 * Register signal handlers for 'zclglobal_control' interface
1699 g_signal_connect(zclglobal_control_object,
1700 "handle-read-attributes-req",
1701 G_CALLBACK(on_zclglobal_control_read_attributes_req), service_interface);
1703 g_signal_connect(zclglobal_control_object,
1704 "handle-write-attributes-req",
1705 G_CALLBACK(on_zclglobal_control_write_attributes_req), service_interface);
1707 g_signal_connect(zclglobal_control_object,
1708 "handle-write-attributes-undivided-req",
1709 G_CALLBACK(on_zclglobal_control_write_attributes_undivided_req), service_interface);
1711 g_signal_connect(zclglobal_control_object,
1712 "handle-write-attributes-no-resp",
1713 G_CALLBACK(on_zclglobal_control_write_attributes_no_resp), service_interface);
1715 g_signal_connect(zclglobal_control_object,
1716 "handle-write-attributes-structured",
1717 G_CALLBACK(on_zclglobal_control_write_attributes_structured), service_interface);
1719 g_signal_connect(zclglobal_control_object,
1720 "handle-read-attributes-structured",
1721 G_CALLBACK(on_zclglobal_control_read_attributes_structured), service_interface);
1723 g_signal_connect(zclglobal_control_object,
1724 "handle-configure-reporting-req",
1725 G_CALLBACK(on_zclglobal_control_configure_reporting_req), service_interface);
1727 g_signal_connect(zclglobal_control_object,
1728 "handle-read-configure-reporting",
1729 G_CALLBACK(on_zclglobal_control_read_configure_reporting), service_interface);
1731 g_signal_connect(zclglobal_control_object,
1732 "handle-discover-attributes",
1733 G_CALLBACK(on_zclglobal_control_discover_attributes), service_interface);
1735 g_signal_connect(zclglobal_control_object,
1736 "handle-discover-attributes-extended",
1737 G_CALLBACK(on_zclglobal_control_discover_attributes_extended), service_interface);
1739 g_signal_connect(zclglobal_control_object,
1740 "handle-discover-commands-received",
1741 G_CALLBACK(on_zclglobal_control_discover_commands_received), service_interface);
1743 g_signal_connect(zclglobal_control_object,
1744 "handle-discover-commands-generated",
1745 G_CALLBACK(on_zclglobal_control_discover_commands_generated), service_interface);