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 short));
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 * sizeof(unsigned short)))
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);
219 g_free(req.write_records);
223 Z_LOGI("DBus Service interface: [%p]", service_interface);
225 /* Update request structure */
226 g_variant_get(write_attribute, "a(y)", &iter);
227 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
229 if (i >= records_length)
232 req.records_len = records_length;
233 req.node_id = node_id;
234 req.cluster_id = cluster_id;
235 req.zcl_frame_ctrl = zcl_frame_ctrl;
237 req.dest_ep = dest_ep;
239 /* Allocate response callback data */
241 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
242 invocation, NULL, 0);
243 if (NULL == resp_cb_data) {
244 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
246 /* Send failure response */
247 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
249 g_free(req.write_records);
253 /* Dispatch request */
254 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
255 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
256 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_REQ,
258 on_zclglobal_control_write_attributes_req_resp, resp_cb_data);
261 g_free(req.write_records);
264 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
266 /* Free response callback data */
267 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
269 /* Send failure response */
270 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
278 static void on_zclglobal_control_write_attributes_undivided_req_resp(ZigBeeServiceInterface *service_interface,
279 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
281 ZigbeeServiceInterfaceRespCbData_t *cb_data =
282 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
284 ZigbeeZcl_global_control *global_control_object;
285 GDBusMethodInvocation *invocation;
287 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
289 NOT_USED(service_interface);
290 NOT_USED(request_id);
292 if (NULL == resp_data || 0 == resp_data_len) {
293 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
298 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
299 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
301 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
302 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
304 zigbee_zcl_global_control_complete_write_attributes_undivided_req(global_control_object,
305 invocation, payload->result);
310 static gboolean on_zclglobal_control_write_attributes_undivided_req(ZigbeeZcl_global_control *zclglobal_control_object,
311 GDBusMethodInvocation *invocation,
312 GVariant *write_attribute,
316 gchar zcl_frame_ctrl,
321 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
322 ZigbeeZclGlobalControlWriteAttributesUndividedRequest_t req;
323 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
325 GVariantIter *iter = NULL;
330 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesUndividedRequest_t));
332 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
333 if (NULL == req.write_records) {
334 Z_LOGE("Failed to allocation !");
336 /* Send failure response */
337 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
339 g_free(req.write_records);
343 /* Update request structure */
344 g_variant_get(write_attribute, "a(y)", &iter);
345 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
347 if (i >= records_length)
350 req.records_len = records_length;
351 req.node_id = node_id;
352 req.cluster_id = cluster_id;
353 req.zcl_frame_ctrl = zcl_frame_ctrl;
355 req.dest_ep = dest_ep;
357 /* Allocate response callback data */
359 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
360 invocation, NULL, 0);
361 if (NULL == resp_cb_data) {
362 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
364 /* Send failure response */
365 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
367 g_free(req.write_records);
371 /* Dispatch request */
372 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
373 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
374 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_UNDIVIDED_REQ,
376 on_zclglobal_control_write_attributes_undivided_req_resp, resp_cb_data);
379 g_free(req.write_records);
382 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
384 /* Free response callback data */
385 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
387 /* Send failure response */
388 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
396 static void on_zclglobal_control_write_attributes_no_resp_resp(ZigBeeServiceInterface *service_interface,
397 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
399 ZigbeeServiceInterfaceRespCbData_t *cb_data =
400 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
402 ZigbeeZcl_global_control *global_control_object;
403 GDBusMethodInvocation *invocation;
405 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
407 NOT_USED(service_interface);
408 NOT_USED(request_id);
410 if (NULL == resp_data || 0 == resp_data_len) {
411 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
416 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
417 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
419 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
420 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
422 zigbee_zcl_global_control_complete_write_attributes_no_resp(global_control_object,
423 invocation, payload->result);
428 static gboolean on_zclglobal_control_write_attributes_no_resp(ZigbeeZcl_global_control *zclglobal_control_object,
429 GDBusMethodInvocation *invocation,
430 GVariant *write_attribute,
434 gchar zcl_frame_ctrl,
439 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
440 ZigbeeZclGlobalControlWriteAttributesNoResponse_t req;
441 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
443 GVariantIter *iter = NULL;
448 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesNoResponse_t));
450 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
451 if (NULL == req.write_records) {
452 Z_LOGE("Failed to allocation !");
454 /* Send failure response */
455 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
457 g_free(req.write_records);
461 /* Update request structure */
462 g_variant_get(write_attribute, "a(y)", &iter);
463 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
465 if (i >= records_length)
468 req.records_len = records_length;
469 req.node_id = node_id;
470 req.cluster_id = cluster_id;
471 req.zcl_frame_ctrl = zcl_frame_ctrl;
473 req.dest_ep = dest_ep;
475 /* Allocate response callback data */
477 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
478 invocation, NULL, 0);
479 if (NULL == resp_cb_data) {
480 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
482 /* Send failure response */
483 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
485 g_free(req.write_records);
489 /* Dispatch request */
490 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
491 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
492 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_NO_RESP,
494 on_zclglobal_control_write_attributes_no_resp_resp, resp_cb_data);
497 g_free(req.write_records);
500 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
502 /* Free response callback data */
503 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
505 /* Send failure response */
506 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
514 static void on_zclglobal_control_write_attributes_structured_resp(ZigBeeServiceInterface *service_interface,
515 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
517 ZigbeeServiceInterfaceRespCbData_t *cb_data =
518 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
520 ZigbeeZcl_global_control *global_control_object;
521 GDBusMethodInvocation *invocation;
523 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
525 NOT_USED(service_interface);
526 NOT_USED(request_id);
528 if (NULL == resp_data || 0 == resp_data_len) {
529 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
534 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
535 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
537 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
538 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
540 zigbee_zcl_global_control_complete_write_attributes_structured(global_control_object,
541 invocation, payload->result);
546 static gboolean on_zclglobal_control_write_attributes_structured(ZigbeeZcl_global_control *zclglobal_control_object,
547 GDBusMethodInvocation *invocation,
548 GVariant *write_attribute,
552 gchar zcl_frame_ctrl,
557 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
558 ZigbeeZclGlobalControlWriteAttributesStructed_t req;
559 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
561 GVariantIter *iter = NULL;
566 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlWriteAttributesStructed_t));
568 req.write_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
569 if (NULL == req.write_records) {
570 Z_LOGE("Failed to allocation !");
572 /* Send failure response */
573 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
575 g_free(req.write_records);
579 /* Update request structure */
580 g_variant_get(write_attribute, "a(y)", &iter);
581 while (g_variant_iter_loop(iter, "(y)", &(req.write_records[i]))) {
583 if (i >= records_length)
586 req.records_len = records_length;
587 req.node_id = node_id;
588 req.cluster_id = cluster_id;
589 req.zcl_frame_ctrl = zcl_frame_ctrl;
591 req.dest_ep = dest_ep;
593 /* Allocate response callback data */
595 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
596 invocation, NULL, 0);
597 if (NULL == resp_cb_data) {
598 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
600 /* Send failure response */
601 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
603 g_free(req.write_records);
607 /* Dispatch request */
608 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
609 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
610 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_STRUCTURED,
612 on_zclglobal_control_write_attributes_structured_resp, resp_cb_data);
615 g_free(req.write_records);
618 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
620 /* Free response callback data */
621 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
623 /* Send failure response */
624 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
632 static void on_zclglobal_control_read_attributes_structured_resp(ZigBeeServiceInterface *service_interface,
633 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
635 ZigbeeServiceInterfaceRespCbData_t *cb_data =
636 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
638 ZigbeeZcl_global_control *global_control_object;
639 GDBusMethodInvocation *invocation;
641 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
643 NOT_USED(service_interface);
644 NOT_USED(request_id);
646 if (NULL == resp_data || 0 == resp_data_len) {
647 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
652 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
653 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
655 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
656 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
658 zigbee_zcl_global_control_complete_read_attributes_structured(global_control_object,
659 invocation, payload->result);
664 static gboolean on_zclglobal_control_read_attributes_structured(ZigbeeZcl_global_control *zclglobal_control_object,
665 GDBusMethodInvocation *invocation,
666 GVariant *read_attribute,
670 gchar zcl_frame_ctrl,
675 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
676 ZigbeeZclGlobalControlReadAttributesStructed_t req;
677 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
679 GVariantIter *iter = NULL;
684 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlReadAttributesStructed_t));
686 req.read_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
687 if (NULL == req.read_records) {
688 Z_LOGE("Failed to allocation !");
690 /* Send failure response */
691 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
693 g_free(req.read_records);
697 /* Update request structure */
698 g_variant_get(read_attribute, "a(y)", &iter);
699 while (g_variant_iter_loop(iter, "(y)", &(req.read_records[i]))) {
701 if (i >= records_length)
704 req.records_len = records_length;
705 req.node_id = node_id;
706 req.cluster_id = cluster_id;
707 req.zcl_frame_ctrl = zcl_frame_ctrl;
709 req.dest_ep = dest_ep;
711 /* Allocate response callback data */
713 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
714 invocation, NULL, 0);
715 if (NULL == resp_cb_data) {
716 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
718 /* Send failure response */
719 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
721 g_free(req.read_records);
725 /* Dispatch request */
726 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
727 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
728 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_READ_ATTRIBUTES_STRUCTURED,
730 on_zclglobal_control_read_attributes_structured_resp, resp_cb_data);
733 g_free(req.read_records);
736 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
738 /* Free response callback data */
739 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
741 /* Send failure response */
742 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
750 static void on_zclglobal_control_configure_reporting_req_resp(ZigBeeServiceInterface *service_interface,
751 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
753 ZigbeeServiceInterfaceRespCbData_t *cb_data =
754 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
756 ZigbeeZcl_global_control *global_control_object;
757 GDBusMethodInvocation *invocation;
759 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
761 NOT_USED(service_interface);
762 NOT_USED(request_id);
764 if (NULL == resp_data || 0 == resp_data_len) {
765 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
770 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
771 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
773 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
774 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
776 zigbee_zcl_global_control_complete_configure_reporting_req(global_control_object,
777 invocation, payload->result);
782 static gboolean on_zclglobal_control_configure_reporting_req(ZigbeeZcl_global_control *zclglobal_control_object,
783 GDBusMethodInvocation *invocation,
784 GVariant *read_attribute,
788 gchar zcl_frame_ctrl,
793 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
794 ZigbeeZclGlobalControlConfigureReportingReq_t req;
795 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
797 GVariantIter *iter = NULL;
802 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlConfigureReportingReq_t));
804 req.read_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
805 if (NULL == req.read_records) {
806 Z_LOGE("Failed to allocation !");
808 /* Send failure response */
809 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
811 g_free(req.read_records);
815 /* Update request structure */
816 g_variant_get(read_attribute, "a(y)", &iter);
817 while (g_variant_iter_loop(iter, "(y)", &(req.read_records[i]))) {
819 if (i >= records_length)
822 req.records_len = records_length;
823 req.node_id = node_id;
824 req.cluster_id = cluster_id;
825 req.zcl_frame_ctrl = zcl_frame_ctrl;
827 req.dest_ep = dest_ep;
829 /* Allocate response callback data */
831 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
832 invocation, NULL, 0);
833 if (NULL == resp_cb_data) {
834 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
836 /* Send failure response */
837 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
839 g_free(req.read_records);
843 /* Dispatch request */
844 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
845 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
846 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_CONFIGURE_REPORTING_REQ,
848 on_zclglobal_control_configure_reporting_req_resp, resp_cb_data);
851 g_free(req.read_records);
854 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
856 /* Free response callback data */
857 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
859 /* Send failure response */
860 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
868 static void on_zclglobal_control_read_configure_reporting_resp(ZigBeeServiceInterface *service_interface,
869 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
871 ZigbeeServiceInterfaceRespCbData_t *cb_data =
872 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
874 ZigbeeZcl_global_control *global_control_object;
875 GDBusMethodInvocation *invocation;
877 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
879 NOT_USED(service_interface);
880 NOT_USED(request_id);
882 if (NULL == resp_data || 0 == resp_data_len) {
883 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
888 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
889 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
891 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
892 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
894 zigbee_zcl_global_control_complete_read_configure_reporting(global_control_object,
895 invocation, payload->result);
900 static gboolean on_zclglobal_control_read_configure_reporting(ZigbeeZcl_global_control *zclglobal_control_object,
901 GDBusMethodInvocation *invocation,
902 GVariant *read_attribute,
906 gchar zcl_frame_ctrl,
911 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
912 ZigbeeZclGlobalControlReadConfigureReporting_t req;
913 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
915 GVariantIter *iter = NULL;
920 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlReadConfigureReporting_t));
922 req.read_records = g_try_malloc0_n(records_length, sizeof(unsigned char));
923 if (NULL == req.read_records) {
924 Z_LOGE("Failed to allocation !");
926 /* Send failure response */
927 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
929 g_free(req.read_records);
933 /* Update request structure */
934 g_variant_get(read_attribute, "a(y)", &iter);
935 while (g_variant_iter_loop(iter, "(y)", &(req.read_records[i]))) {
937 if (i >= records_length)
940 req.records_len = records_length;
941 req.node_id = node_id;
942 req.cluster_id = cluster_id;
943 req.zcl_frame_ctrl = zcl_frame_ctrl;
945 req.dest_ep = dest_ep;
947 /* Allocate response callback data */
949 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
950 invocation, NULL, 0);
951 if (NULL == resp_cb_data) {
952 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
954 /* Send failure response */
955 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
957 g_free(req.read_records);
961 /* Dispatch request */
962 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
963 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
964 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_READ_CONFIGURE_REPORTING,
966 on_zclglobal_control_read_configure_reporting_resp, resp_cb_data);
969 g_free(req.read_records);
972 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
974 /* Free response callback data */
975 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
977 /* Send failure response */
978 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
986 static void on_zclglobal_control_discover_attributes_resp(ZigBeeServiceInterface *service_interface,
987 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
989 ZigbeeServiceInterfaceRespCbData_t *cb_data =
990 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
992 ZigbeeZcl_global_control *global_control_object;
993 GDBusMethodInvocation *invocation;
995 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
997 NOT_USED(service_interface);
998 NOT_USED(request_id);
1000 if (NULL == resp_data || 0 == resp_data_len) {
1001 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1006 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1007 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1009 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1010 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1012 zigbee_zcl_global_control_complete_discover_attributes(global_control_object,
1013 invocation, payload->result);
1018 static gboolean on_zclglobal_control_discover_attributes(ZigbeeZcl_global_control *zclglobal_control_object,
1019 GDBusMethodInvocation *invocation,
1022 gchar zcl_frame_ctrl,
1025 gchar max_attribute_count,
1028 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1029 ZigbeeZclGlobalControlDiscoverAttributes_t req;
1030 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1034 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverAttributes_t));
1036 /* Update request structure */
1037 req.node_id = node_id;
1038 req.dest_ep = dest_ep;
1039 req.zcl_frame_ctrl = zcl_frame_ctrl;
1040 req.cluster_id = cluster_id;
1041 req.start_attribute = start_attr;
1042 req.max_attribute_count = max_attribute_count;
1044 /* Allocate response callback data */
1046 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1047 invocation, NULL, 0);
1048 if (NULL == resp_cb_data) {
1049 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1051 /* Send failure response */
1052 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1057 /* Dispatch request */
1058 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1059 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1060 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_ATTRIBUTES,
1062 on_zclglobal_control_discover_attributes_resp, resp_cb_data);
1064 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1066 /* Free response callback data */
1067 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1069 /* Send failure response */
1070 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1078 static void on_zclglobal_control_discover_attributes_extended_resp(ZigBeeServiceInterface *service_interface,
1079 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1081 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1082 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1084 ZigbeeZcl_global_control *global_control_object;
1085 GDBusMethodInvocation *invocation;
1087 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
1089 NOT_USED(service_interface);
1090 NOT_USED(request_id);
1092 if (NULL == resp_data || 0 == resp_data_len) {
1093 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1098 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1099 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1101 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1102 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1104 zigbee_zcl_global_control_complete_discover_attributes_extended(global_control_object,
1105 invocation, payload->result);
1110 static gboolean on_zclglobal_control_discover_attributes_extended(ZigbeeZcl_global_control *zclglobal_control_object,
1111 GDBusMethodInvocation *invocation,
1114 gchar zcl_frame_ctrl,
1117 gchar max_attribute_count,
1120 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1121 ZigbeeZclGlobalControlDiscoverAttributesExtended_t req;
1122 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1126 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverAttributesExtended_t));
1128 /* Update request structure */
1129 req.node_id = node_id;
1130 req.dest_ep = dest_ep;
1131 req.zcl_frame_ctrl = zcl_frame_ctrl;
1132 req.cluster_id = cluster_id;
1133 req.start_attribute = start_attr;
1134 req.max_attribute_count = max_attribute_count;
1136 /* Allocate response callback data */
1138 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1139 invocation, NULL, 0);
1140 if (NULL == resp_cb_data) {
1141 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1143 /* Send failure response */
1144 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1149 /* Dispatch request */
1150 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1151 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1152 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_ATTRIBUTES_EXTENDED,
1154 on_zclglobal_control_discover_attributes_extended_resp, resp_cb_data);
1156 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1158 /* Free response callback data */
1159 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1161 /* Send failure response */
1162 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1170 static void on_zclglobal_control_discover_commands_received_resp(ZigBeeServiceInterface *service_interface,
1171 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1173 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1174 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1176 ZigbeeZcl_global_control *global_control_object;
1177 GDBusMethodInvocation *invocation;
1179 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
1181 NOT_USED(service_interface);
1182 NOT_USED(request_id);
1184 if (NULL == resp_data || 0 == resp_data_len) {
1185 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1190 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1191 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1193 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1194 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1196 zigbee_zcl_global_control_complete_discover_commands_received(global_control_object,
1197 invocation, payload->result);
1202 static gboolean on_zclglobal_control_discover_commands_received(ZigbeeZcl_global_control *zclglobal_control_object,
1203 GDBusMethodInvocation *invocation,
1206 gchar zcl_frame_ctrl,
1208 gshort start_command,
1209 gchar max_command_count,
1212 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1213 ZigbeeZclGlobalControlDiscoverCommandsReceived_t req;
1214 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1218 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverCommandsReceived_t));
1220 /* Update request structure */
1221 req.node_id = node_id;
1222 req.dest_ep = dest_ep;
1223 req.zcl_frame_ctrl = zcl_frame_ctrl;
1224 req.cluster_id = cluster_id;
1225 req.start_command = start_command;
1226 req.max_command_count = max_command_count;
1228 /* Allocate response callback data */
1230 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1231 invocation, NULL, 0);
1232 if (NULL == resp_cb_data) {
1233 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1235 /* Send failure response */
1236 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1241 /* Dispatch request */
1242 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1243 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1244 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_COMMANDS_RECEIVED,
1246 on_zclglobal_control_discover_commands_received_resp, resp_cb_data);
1248 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1250 /* Free response callback data */
1251 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1253 /* Send failure response */
1254 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1262 static void on_zclglobal_control_discover_commands_generated_resp(ZigBeeServiceInterface *service_interface,
1263 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1265 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1266 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1268 ZigbeeZcl_global_control *global_control_object;
1269 GDBusMethodInvocation *invocation;
1271 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
1273 NOT_USED(service_interface);
1274 NOT_USED(request_id);
1276 if (NULL == resp_data || 0 == resp_data_len) {
1277 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
1282 global_control_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1283 zblib_check_null_free_and_ret("global_control_object", global_control_object, cb_data);
1285 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1286 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1288 zigbee_zcl_global_control_complete_discover_commands_generated(global_control_object,
1289 invocation, payload->result);
1294 static gboolean on_zclglobal_control_discover_commands_generated(ZigbeeZcl_global_control *zclglobal_control_object,
1295 GDBusMethodInvocation *invocation,
1298 gchar zcl_frame_ctrl,
1300 gshort start_command,
1301 gchar max_command_count,
1304 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1305 ZigbeeZclGlobalControlDiscoverCommandsGenerated_t req;
1306 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1310 memset(&req, 0x0, sizeof(ZigbeeZclGlobalControlDiscoverCommandsGenerated_t));
1312 /* Update request structure */
1313 req.node_id = node_id;
1314 req.dest_ep = dest_ep;
1315 req.zcl_frame_ctrl = zcl_frame_ctrl;
1316 req.cluster_id = cluster_id;
1317 req.start_command = start_command;
1318 req.max_command_count = max_command_count;
1320 /* Allocate response callback data */
1322 zigbee_service_dbus_interface_create_resp_cb_data(zclglobal_control_object,
1323 invocation, NULL, 0);
1324 if (NULL == resp_cb_data) {
1325 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1327 /* Send failure response */
1328 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1333 /* Dispatch request */
1334 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1335 ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL,
1336 ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_COMMANDS_GENERATED,
1338 on_zclglobal_control_discover_commands_generated_resp, resp_cb_data);
1340 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1342 /* Free response callback data */
1343 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1345 /* Send failure response */
1346 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1354 void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeServiceInterface *service_interface,
1355 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
1357 ZigbeeZcl_global_control *global_control_object = NULL;
1359 zblib_check_null_ret("service_interface", service_interface);
1361 if (NULL == noti_data || 0 == noti_data_len) {
1362 Z_LOGE("noti_data is NULL");
1366 global_control_object = _service_interface_ref_zigbee_zcl_global_control(service_interface);
1367 zblib_check_null_ret("global_control_object", global_control_object);
1369 NOT_USED(noti_cb_data);
1372 case ZBLIB_ZCL_GLOBAL_NOTI_READ_ATTR_RSP: {
1373 ZigbeeZclGlobalControlReadAttributesResp_t *attr_t =
1374 (ZigbeeZclGlobalControlReadAttributesResp_t*)noti_data;
1376 GVariant *v_values = NULL;
1377 v_values = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1378 attr_t->values, attr_t->record_length, TRUE, NULL, NULL);
1379 if (NULL == v_values) {
1380 Z_LOGE("Failed to create variant!");
1382 Z_LOGD("Read attributes resp");
1383 zigbee_zcl_global_control_emit_read_attributes_rsp(global_control_object,
1384 attr_t->node_id, attr_t->src_ep, v_values, attr_t->attribute_id,
1385 attr_t->cluster_id, attr_t->status, attr_t->type,
1386 attr_t->record_length, attr_t->is_string);
1389 g_variant_unref(v_values);
1392 case ZBLIB_ZCL_GLOBAL_NOTI_WRITE_ATTR_RSP: {
1393 ZigbeeZclGlobalControlWriteAttributesResp_t *attr_t =
1394 (ZigbeeZclGlobalControlWriteAttributesResp_t*)noti_data;
1396 GVariant *v_values = NULL;
1397 GVariant *v_attrs = NULL;
1398 v_values = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1399 attr_t->values, attr_t->record_length, TRUE, NULL, NULL);
1400 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1401 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1403 if (NULL == v_values || NULL == v_attrs) {
1404 Z_LOGE("Failed to create variant!");
1406 Z_LOGD("Write attributes resp");
1407 zigbee_zcl_global_control_emit_write_attributes_rsp(global_control_object,
1408 attr_t->node_id, attr_t->src_ep, v_values, v_attrs,
1409 attr_t->cluster_id, attr_t->record_length);
1412 g_variant_unref(v_values);
1414 g_variant_unref(v_attrs);
1417 case ZBLIB_ZCL_GLOBAL_NOTI_CONFIG_REPORT_RSP: {
1418 ZigbeeZclGlobalControlConfigReportResp_t *attr_t =
1419 (ZigbeeZclGlobalControlConfigReportResp_t*)noti_data;
1421 GVariant *v_status = NULL;
1422 GVariant *v_attrs = NULL;
1423 GVariant *v_dirs = NULL;
1424 v_status = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1425 attr_t->status_list, attr_t->record_length, TRUE, NULL, NULL);
1426 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1427 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1429 v_dirs = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1430 attr_t->dir_list, attr_t->record_length, TRUE, NULL, NULL);
1431 if (NULL == v_status || NULL == v_attrs || NULL == v_dirs) {
1432 Z_LOGE("Failed to create variant!");
1434 g_variant_unref(v_status);
1436 g_variant_unref(v_attrs);
1438 g_variant_unref(v_dirs);
1440 Z_LOGD("Configure reporting resp");
1441 zigbee_zcl_global_control_emit_configure_reporting_rsp(global_control_object,
1442 v_status, v_attrs, v_dirs, attr_t->cluster_id,
1443 attr_t->record_length, attr_t->node_id, attr_t->src_ep);
1447 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_ATTR_RSP: {
1448 ZigbeeZclGlobalControlDiscoverAttributeResp_t *attr_t =
1449 (ZigbeeZclGlobalControlDiscoverAttributeResp_t*)noti_data;
1451 GVariant *v_types = NULL;
1452 GVariant *v_attrs = NULL;
1453 v_types = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1454 attr_t->type_list, attr_t->record_length, TRUE, NULL, NULL);
1455 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1456 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1458 if (NULL == v_types || NULL == v_attrs) {
1459 Z_LOGE("Failed to create variant!");
1461 Z_LOGD("Discover attribute resp");
1462 zigbee_zcl_global_control_emit_discover_attribute_rsp(global_control_object,
1463 attr_t->node_id, attr_t->src_ep, v_types, v_attrs,
1464 attr_t->cluster_id, attr_t->record_length, attr_t->discovery_completed);
1467 g_variant_unref(v_types);
1469 g_variant_unref(v_attrs);
1472 case ZBLIB_ZCL_GLOBAL_NOTI_WRITE_ATTR_STRUCTURED_RSP: {
1473 ZigbeeZclGlobalControlWriteAttributeStructuredResp_t *attr_t =
1474 (ZigbeeZclGlobalControlWriteAttributeStructuredResp_t*)noti_data;
1476 GVariant *v_status = NULL;
1477 GVariant *v_attrs = NULL;
1478 GVariant *v_indicator = NULL;
1479 GVariantBuilder *index_builder = NULL;
1480 GVariant *v_index = NULL;
1483 v_status = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1484 attr_t->status_list, attr_t->record_length, TRUE, NULL, NULL);
1485 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1486 attr_t->attribute_list, (sizeof(gushort) * attr_t->record_length),
1488 v_indicator = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1489 attr_t->indicator_list, attr_t->record_length, TRUE, NULL, NULL);
1491 if (NULL == v_status || NULL == v_attrs || NULL == v_indicator) {
1492 Z_LOGE("Failed to create variant!");
1494 g_variant_unref(v_status);
1496 g_variant_unref(v_attrs);
1498 g_variant_unref(v_indicator);
1502 index_builder = g_variant_builder_new(G_VARIANT_TYPE("aq"));
1503 if (NULL == index_builder) {
1504 Z_LOGE("Failed to create variant builder!");
1505 g_variant_unref(v_status);
1506 g_variant_unref(v_attrs);
1507 g_variant_unref(v_indicator);
1510 for (i = 0; i < attr_t->record_length; i++) {
1511 for (j = 0; j < attr_t->indicator_list[i]; j++)
1512 g_variant_builder_add(index_builder, "q", attr_t->index_list[i][j]);
1514 v_index = g_variant_builder_end(index_builder);
1515 g_variant_builder_unref(index_builder);
1517 Z_LOGD("Write attribute structured resp");
1518 zigbee_zcl_global_control_emit_write_attribute_structured_rsp(
1519 global_control_object,
1520 v_status, v_attrs, v_indicator, v_index,
1521 attr_t->cluster_id, attr_t->record_length,
1522 attr_t->node_id, attr_t->src_ep);
1524 g_variant_unref(v_status);
1526 g_variant_unref(v_attrs);
1528 g_variant_unref(v_indicator);
1531 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_CMDS_RECEIVED_RSP: {
1532 ZigbeeZclGlobalControlDiscoverCommandsReceivedResp_t *attr_t =
1533 (ZigbeeZclGlobalControlDiscoverCommandsReceivedResp_t*)noti_data;
1535 GVariant *v_commands = NULL;
1536 v_commands = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1537 attr_t->command_list, attr_t->list_count, TRUE, NULL, NULL);
1538 if (NULL == v_commands) {
1539 Z_LOGE("Failed to create variant!");
1541 Z_LOGD("Discover commands received resp");
1542 zigbee_zcl_global_control_emit_discover_commands_received_rsp(
1543 global_control_object,
1544 v_commands, attr_t->cluster_id, attr_t->list_count,
1545 attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
1548 g_variant_unref(v_commands);
1551 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_CMDS_GENERATED_RSP: {
1552 ZigbeeZclGlobalControlDiscoverCommandsGeneratedResp_t *attr_t =
1553 (ZigbeeZclGlobalControlDiscoverCommandsGeneratedResp_t*)noti_data;
1555 GVariant *v_commands = NULL;
1556 v_commands = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1557 attr_t->command_list, attr_t->list_count, TRUE, NULL, NULL);
1558 if (NULL == v_commands) {
1559 Z_LOGE("Failed to create variant!");
1561 Z_LOGD("Discover commands generated resp");
1562 zigbee_zcl_global_control_emit_discover_commands_generated_rsp(
1563 global_control_object,
1564 v_commands, attr_t->cluster_id, attr_t->list_count,
1565 attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
1568 g_variant_unref(v_commands);
1571 case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_ATTR_EXT_RSP: {
1572 ZigbeeZclGlobalControlDiscoverAttributesExtendedResp_t *attr_t =
1573 (ZigbeeZclGlobalControlDiscoverAttributesExtendedResp_t*)noti_data;
1575 GVariant *v_attrs = NULL;
1576 GVariant *v_attrs_type = NULL;
1577 GVariant *v_access = 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_attrs_type = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1582 attr_t->attribute_type_list, attr_t->list_count, TRUE, NULL, NULL);
1583 v_access = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1584 attr_t->access_list, attr_t->list_count, TRUE, NULL, NULL);
1585 if (NULL == v_attrs_type || NULL == v_attrs || NULL == v_access) {
1586 Z_LOGE("Failed to create variant!");
1588 Z_LOGD("Discover attributes extended resp");
1589 zigbee_zcl_global_control_emit_discover_attributes_extended_rsp(
1590 global_control_object,
1591 v_attrs, v_attrs_type, v_access,
1592 attr_t->cluster_id, attr_t->list_count,
1593 attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
1596 g_variant_unref(v_attrs_type);
1598 g_variant_unref(v_attrs);
1600 g_variant_unref(v_access);
1603 case ZBLIB_ZCL_GLOBAL_NOTI_DEFAULT_RSP: {
1604 ZigbeeZclGlobalControlDefaultResp_t *attr_t =
1605 (ZigbeeZclGlobalControlDefaultResp_t*)noti_data;
1607 Z_LOGD("Global default resp");
1608 zigbee_zcl_global_control_emit_zcl_global_default_response(
1609 global_control_object,
1610 attr_t->node_id, attr_t->src_ep, attr_t->cluster_id,
1611 attr_t->command_id, attr_t->status);
1614 case ZBLIB_ZCL_GLOBAL_NOTI_REPORT_ATTR_HANDLER_RSP: {
1615 ZigbeeZclGlobalControlReportAttributeHandlerResp_t *attr_t =
1616 (ZigbeeZclGlobalControlReportAttributeHandlerResp_t*)noti_data;
1618 GVariant *v_attrs = NULL;
1619 GVariant *v_data_type = NULL;
1620 GVariant *v_values = NULL;
1621 GVariantBuilder *values_builder = NULL;
1624 v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1625 attr_t->attribute_list, (sizeof(gushort) * attr_t->list_count),
1627 if (NULL == v_attrs) {
1628 Z_LOGE("Failed to create variant!");
1631 v_data_type = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1632 attr_t->data_type_list, attr_t->list_count, TRUE, NULL, NULL);
1633 if (NULL == v_data_type) {
1634 Z_LOGE("Failed to create variant!");
1636 g_variant_unref(v_attrs);
1640 values_builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
1641 if (NULL == values_builder) {
1642 Z_LOGE("Failed to create variant builder!");
1644 g_variant_unref(v_attrs);
1646 g_variant_unref(v_data_type);
1649 for (i = 0; i < attr_t->list_count; i++) {
1650 for (j = 0; j < attr_t->values_count[i]; j++)
1651 g_variant_builder_add(values_builder, "(y)", attr_t->values[i][j]);
1653 v_values = g_variant_builder_end(values_builder);
1654 g_variant_builder_unref(values_builder);
1656 Z_LOGD("Report attributes handler resp");
1657 zigbee_zcl_global_control_emit_report_attr_handler_rsp(
1658 global_control_object,
1659 attr_t->node_id, attr_t->src_ep, attr_t->cluster_id,
1660 v_attrs, v_data_type, v_values,
1661 attr_t->list_count);
1663 g_variant_unref(v_attrs);
1665 g_variant_unref(v_data_type);
1667 g_variant_unref(v_values);
1670 case ZBLIB_ZCL_GLOBAL_NOTI_READ_CONFIG_REPORT_RSP: {
1671 ZigbeeZclGlobalControlReadConfigureReportingResp_t *resp_t =
1672 (ZigbeeZclGlobalControlReadConfigureReportingResp_t *)noti_data;
1676 GVariant *v_entries = NULL;
1677 GVariantBuilder *entry_builder =
1678 g_variant_builder_new(G_VARIANT_TYPE("a(yyqyqqayq)"));
1679 if (NULL == entry_builder) {
1680 Z_LOGE("Failed to create variant builder!");
1684 for (i = 0; i < resp_t->record_count ; i++) {
1685 GVariantBuilder *change_builder =
1686 g_variant_builder_new(G_VARIANT_TYPE("ay"));
1687 if (NULL == change_builder) {
1688 Z_LOGE("Failed to create variant builder!");
1689 g_variant_builder_unref(entry_builder);
1693 for (v = 0; v < resp_t->entry_list[i].change_count; v++) {
1694 g_variant_builder_add(change_builder, "y",
1695 resp_t->entry_list[i].change[v]);
1698 g_variant_builder_add(entry_builder, "(yyqyqqayq)",
1699 resp_t->entry_list[i].status,
1700 resp_t->entry_list[i].dir,
1701 resp_t->entry_list[i].attribute_id,
1702 resp_t->entry_list[i].data_type,
1703 resp_t->entry_list[i].min_interval,
1704 resp_t->entry_list[i].max_interval,
1706 resp_t->entry_list[i].change_count,
1707 resp_t->entry_list[i].timeout);
1709 g_variant_builder_unref(change_builder);
1711 v_entries = g_variant_builder_end(entry_builder);
1712 g_variant_builder_unref(entry_builder);
1714 Z_LOGD("Read configure reporting resp");
1715 zigbee_zcl_global_control_emit_read_configure_reporting_rsp(
1716 global_control_object, resp_t->node_id, resp_t->src_ep,
1717 resp_t->cluster_id, resp_t->record_count, v_entries);
1720 g_variant_unref(v_entries);
1724 Z_LOGE("Unexpected notification [%x]", noti_id);
1728 /* ZigbeeZcl_global_control should be dereferenced */
1729 g_object_unref(global_control_object);
1732 gboolean zigbee_service_dbus_interface_zcl_global_control_init(ZigBeeServiceInterface *service_interface,
1733 ZigbeeObjectSkeleton *zigbee_object)
1735 ZigbeeZcl_global_control *zclglobal_control_object;
1737 if (NULL == service_interface) {
1738 Z_LOGE("service_interface is NULL");
1742 zclglobal_control_object = zigbee_zcl_global_control_skeleton_new();
1743 zigbee_object_skeleton_set_zcl_global_control(zigbee_object, zclglobal_control_object);
1744 g_object_unref(zclglobal_control_object);
1746 Z_LOGI("zclglobal_control_object: [%p]", zclglobal_control_object);
1749 * Register signal handlers for 'zclglobal_control' interface
1751 g_signal_connect(zclglobal_control_object,
1752 "handle-read-attributes-req",
1753 G_CALLBACK(on_zclglobal_control_read_attributes_req), service_interface);
1755 g_signal_connect(zclglobal_control_object,
1756 "handle-write-attributes-req",
1757 G_CALLBACK(on_zclglobal_control_write_attributes_req), service_interface);
1759 g_signal_connect(zclglobal_control_object,
1760 "handle-write-attributes-undivided-req",
1761 G_CALLBACK(on_zclglobal_control_write_attributes_undivided_req), service_interface);
1763 g_signal_connect(zclglobal_control_object,
1764 "handle-write-attributes-no-resp",
1765 G_CALLBACK(on_zclglobal_control_write_attributes_no_resp), service_interface);
1767 g_signal_connect(zclglobal_control_object,
1768 "handle-write-attributes-structured",
1769 G_CALLBACK(on_zclglobal_control_write_attributes_structured), service_interface);
1771 g_signal_connect(zclglobal_control_object,
1772 "handle-read-attributes-structured",
1773 G_CALLBACK(on_zclglobal_control_read_attributes_structured), service_interface);
1775 g_signal_connect(zclglobal_control_object,
1776 "handle-configure-reporting-req",
1777 G_CALLBACK(on_zclglobal_control_configure_reporting_req), service_interface);
1779 g_signal_connect(zclglobal_control_object,
1780 "handle-read-configure-reporting",
1781 G_CALLBACK(on_zclglobal_control_read_configure_reporting), service_interface);
1783 g_signal_connect(zclglobal_control_object,
1784 "handle-discover-attributes",
1785 G_CALLBACK(on_zclglobal_control_discover_attributes), service_interface);
1787 g_signal_connect(zclglobal_control_object,
1788 "handle-discover-attributes-extended",
1789 G_CALLBACK(on_zclglobal_control_discover_attributes_extended), service_interface);
1791 g_signal_connect(zclglobal_control_object,
1792 "handle-discover-commands-received",
1793 G_CALLBACK(on_zclglobal_control_discover_commands_received), service_interface);
1795 g_signal_connect(zclglobal_control_object,
1796 "handle-discover-commands-generated",
1797 G_CALLBACK(on_zclglobal_control_discover_commands_generated), service_interface);