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_service.h>
23 static void *_service_interface_ref_zigbee_service(ZigBeeServiceInterface *service_interface)
25 ZigbeeObjectSkeleton *zigbee_object = NULL;
26 ZigbeeCustomData_t *custom_data = NULL;
27 ZigbeeService *service = 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 service = zigbee_object_get_service(ZIGBEE_OBJECT(zigbee_object));
46 static void on_service_enable_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 ZigbeeService *service_object;
53 GDBusMethodInvocation *invocation;
54 ZigbeeServiceServiceState_t *payload =
55 (ZigbeeServiceServiceState_t*)resp_data;
57 NOT_USED(service_interface);
60 if (NULL == resp_data || 0 == resp_data_len) {
61 Z_LOGE("resp_data is null");
65 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
66 zblib_check_null_ret("service_object", service_object);
68 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
69 zblib_check_null_ret("invocation", invocation);
71 zigbee_service_complete_enable(service_object, invocation,
72 payload->result, payload->enabled);
77 static gboolean on_service_enable(ZigbeeService *service_object,
78 GDBusMethodInvocation *invocation,
81 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
82 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
88 /* Allocate response callback data */
90 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
92 if (NULL == resp_cb_data) {
93 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
95 /* Send failure response */
96 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
101 /* Dispatch request */
102 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
103 ZBLIB_DRIVER_TYPE_SERVICE,
104 ZBLIB_SERVICE_OPS_ENABLE,
106 on_service_enable_resp, resp_cb_data);
108 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
110 /* Free response callback data */
111 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
113 /* Send failure response */
114 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
122 static void on_service_disable_resp(ZigBeeServiceInterface *service_interface,
123 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
125 ZigbeeServiceInterfaceRespCbData_t *cb_data =
126 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
128 ZigbeeService *service_object;
129 GDBusMethodInvocation *invocation;
130 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
132 NOT_USED(service_interface);
133 NOT_USED(request_id);
135 if (NULL == resp_data || 0 == resp_data_len) {
136 Z_LOGE("resp_data is null");
140 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
141 zblib_check_null_ret("service_object", service_object);
143 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
144 zblib_check_null_ret("invocation", invocation);
146 zigbee_service_complete_disable(service_object, invocation, payload->result);
151 static gboolean on_service_disable(ZigbeeService *service_object,
152 GDBusMethodInvocation *invocation,
155 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
156 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
160 /* Allocate response callback data */
162 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
163 invocation, NULL, 0);
164 if (NULL == resp_cb_data) {
165 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
167 /* Send failure response */
168 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
173 /* Dispatch request */
174 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
175 ZBLIB_DRIVER_TYPE_SERVICE,
176 ZBLIB_SERVICE_OPS_DISABLE,
178 on_service_disable_resp, resp_cb_data);
180 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
182 /* Free response callback data */
183 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
185 /* Send failure response */
186 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
194 static void on_service_zb_hw_reset_resp(ZigBeeServiceInterface *service_interface,
195 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
197 ZigbeeServiceInterfaceRespCbData_t *cb_data =
198 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
200 ZigbeeService *service_object;
201 GDBusMethodInvocation *invocation;
202 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
204 NOT_USED(service_interface);
205 NOT_USED(request_id);
207 if (NULL == resp_data || 0 == resp_data_len) {
208 Z_LOGE("resp_data is null");
212 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
213 zblib_check_null_ret("service_object", service_object);
215 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
216 zblib_check_null_ret("invocation", invocation);
218 zigbee_service_complete_zb_hw_reset(service_object, invocation, payload->result);
223 static gboolean on_service_zb_hw_reset(ZigbeeService *service_object,
224 GDBusMethodInvocation *invocation,
227 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
228 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
232 /* Allocate response callback data */
234 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
235 invocation, NULL, 0);
236 if (NULL == resp_cb_data) {
237 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
239 /* Send failure response */
240 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
245 /* Dispatch request */
246 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
247 ZBLIB_DRIVER_TYPE_SERVICE,
248 ZBLIB_SERVICE_OPS_ZB_HW_RESET,
250 on_service_zb_hw_reset_resp, resp_cb_data);
252 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
254 /* Free response callback data */
255 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
257 /* Send failure response */
258 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
266 static void on_service_form_network_resp(ZigBeeServiceInterface *service_interface,
267 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
269 ZigbeeServiceInterfaceRespCbData_t *cb_data =
270 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
272 ZigbeeService *service_object;
273 GDBusMethodInvocation *invocation;
274 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
276 NOT_USED(service_interface);
277 NOT_USED(request_id);
279 if (NULL == resp_data || 0 == resp_data_len) {
280 Z_LOGE("resp_data is null");
284 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
285 zblib_check_null_ret("service_object", service_object);
287 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
288 zblib_check_null_ret("invocation", invocation);
290 zigbee_service_complete_form_network(service_object, invocation, payload->result);
295 static gboolean on_service_form_network(ZigbeeService *service_object,
296 GDBusMethodInvocation *invocation,
299 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
300 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
304 /* Allocate response callback data */
306 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
307 invocation, NULL, 0);
308 if (NULL == resp_cb_data) {
309 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
311 /* Send failure response */
312 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
317 /* Dispatch request */
318 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
319 ZBLIB_DRIVER_TYPE_SERVICE,
320 ZBLIB_SERVICE_OPS_FORM_NETWORK,
322 on_service_form_network_resp, resp_cb_data);
324 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
326 /* Free response callback data */
327 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
329 /* Send failure response */
330 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
338 static void on_service_coex_start_resp(ZigBeeServiceInterface *service_interface,
339 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
341 ZigbeeServiceInterfaceRespCbData_t *cb_data =
342 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
344 ZigbeeService *service_object;
345 GDBusMethodInvocation *invocation;
346 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
348 NOT_USED(service_interface);
349 NOT_USED(request_id);
351 if (NULL == resp_data || 0 == resp_data_len) {
352 Z_LOGE("resp_data is null");
356 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
357 zblib_check_null_ret("service_object", service_object);
359 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
360 zblib_check_null_ret("invocation", invocation);
362 zigbee_service_complete_coex_start(service_object, invocation, payload->result);
367 static gboolean on_service_coex_start(ZigbeeService *service_object,
368 GDBusMethodInvocation *invocation,
372 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
373 ZigbeeServiceCoexStart_t req;
374 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
378 memset(&req, 0x0, sizeof(ZigbeeServiceCoexStart_t));
380 /* Update request structure */
381 req.channel = channel;
383 /* Allocate response callback data */
385 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
386 invocation, NULL, 0);
387 if (NULL == resp_cb_data) {
388 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
390 /* Send failure response */
391 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
396 /* Dispatch request */
397 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
398 ZBLIB_DRIVER_TYPE_SERVICE,
399 ZBLIB_SERVICE_OPS_COEX_START,
401 on_service_coex_start_resp, resp_cb_data);
403 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
405 /* Free response callback data */
406 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
408 /* Send failure response */
409 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
417 static void on_service_coex_stop_resp(ZigBeeServiceInterface *service_interface,
418 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
420 ZigbeeServiceInterfaceRespCbData_t *cb_data =
421 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
423 ZigbeeService *service_object;
424 GDBusMethodInvocation *invocation;
425 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
427 NOT_USED(service_interface);
428 NOT_USED(request_id);
430 if (NULL == resp_data || 0 == resp_data_len) {
431 Z_LOGE("resp_data is null");
435 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
436 zblib_check_null_ret("service_object", service_object);
438 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
439 zblib_check_null_ret("invocation", invocation);
441 zigbee_service_complete_coex_stop(service_object, invocation, payload->result);
446 static gboolean on_service_coex_stop(ZigbeeService *service_object,
447 GDBusMethodInvocation *invocation,
450 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
451 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
455 /* Allocate response callback data */
457 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
458 invocation, NULL, 0);
459 if (NULL == resp_cb_data) {
460 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
462 /* Send failure response */
463 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
468 /* Dispatch request */
469 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
470 ZBLIB_DRIVER_TYPE_SERVICE,
471 ZBLIB_SERVICE_OPS_COEX_STOP,
473 on_service_coex_stop_resp, resp_cb_data);
475 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
477 /* Free response callback data */
478 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
480 /* Send failure response */
481 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
489 static void on_service_leave_network_resp(ZigBeeServiceInterface *service_interface,
490 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
492 ZigbeeServiceInterfaceRespCbData_t *cb_data =
493 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
495 ZigbeeService *service_object;
496 GDBusMethodInvocation *invocation;
497 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
499 NOT_USED(service_interface);
500 NOT_USED(request_id);
502 if (NULL == resp_data || 0 == resp_data_len) {
503 Z_LOGE("resp_data is null");
507 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
508 zblib_check_null_ret("service_object", service_object);
510 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
511 zblib_check_null_ret("invocation", invocation);
513 zigbee_service_complete_leave_network(service_object, invocation, payload->result);
518 static gboolean on_service_leave_network(ZigbeeService *service_object,
519 GDBusMethodInvocation *invocation,
522 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
523 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
527 /* Allocate response callback data */
529 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
530 invocation, NULL, 0);
531 if (NULL == resp_cb_data) {
532 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
534 /* Send failure response */
535 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
540 /* Dispatch request */
541 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
542 ZBLIB_DRIVER_TYPE_SERVICE,
543 ZBLIB_SERVICE_OPS_LEAVE_NETWORK,
545 on_service_leave_network_resp, resp_cb_data);
547 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
549 /* Free response callback data */
550 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
552 /* Send failure response */
553 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
561 static void on_service_get_network_info_resp(ZigBeeServiceInterface *service_interface,
562 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
564 ZigbeeServiceInterfaceRespCbData_t *cb_data =
565 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
567 ZigbeeService *service_object;
568 GDBusMethodInvocation *invocation;
570 ZigbeeServiceGetNetworkInfo_t *payload =
571 (ZigbeeServiceGetNetworkInfo_t*)resp_data;
573 NOT_USED(service_interface);
574 NOT_USED(request_id);
576 if (NULL == resp_data || 0 == resp_data_len) {
577 Z_LOGE("resp_data is null");
581 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
582 zblib_check_null_ret("service_object", service_object);
584 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
585 zblib_check_null_ret("invocation", invocation);
587 zigbee_service_complete_get_network_info(service_object, invocation,
588 payload->result, payload->eui64, payload->node_id,
589 payload->pan_id, payload->channel, payload->radio_tx_power);
594 static gboolean on_service_get_network_info(ZigbeeService *service_object,
595 GDBusMethodInvocation *invocation,
598 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
599 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
603 /* Allocate response callback data */
605 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
606 invocation, NULL, 0);
607 if (NULL == resp_cb_data) {
608 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
610 /* Send failure response */
611 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
616 /* Dispatch request */
617 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
618 ZBLIB_DRIVER_TYPE_SERVICE,
619 ZBLIB_SERVICE_OPS_GET_NETWORK_INFO,
621 on_service_get_network_info_resp, resp_cb_data);
623 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
625 /* Free response callback data */
626 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
628 /* Send failure response */
629 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
637 static void on_service_permit_join_resp(ZigBeeServiceInterface *service_interface,
638 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
640 ZigbeeServiceInterfaceRespCbData_t *cb_data =
641 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
643 ZigbeeService *service_object;
644 GDBusMethodInvocation *invocation;
645 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
647 NOT_USED(service_interface);
648 NOT_USED(request_id);
650 if (NULL == resp_data || 0 == resp_data_len) {
651 Z_LOGE("resp_data is null");
655 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
656 zblib_check_null_ret("service_object", service_object);
658 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
659 zblib_check_null_ret("invocation", invocation);
661 zigbee_service_complete_permit_join(service_object, invocation, payload->result);
666 static gboolean on_service_permit_join(ZigbeeService *service_object,
667 GDBusMethodInvocation *invocation,
669 gboolean permit_join,
672 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
673 ZigbeeServicePermitJoin_t req;
674 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
678 memset(&req, 0x0, sizeof(ZigbeeServicePermitJoin_t));
680 /* Update request structure */
681 req.duration = duration;
682 req.permit_join = permit_join;
684 /* Allocate response callback data */
686 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
687 invocation, NULL, 0);
688 if (NULL == resp_cb_data) {
689 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
691 /* Send failure response */
692 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
697 /* Dispatch request */
698 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
699 ZBLIB_DRIVER_TYPE_SERVICE,
700 ZBLIB_SERVICE_OPS_PERMIT_JOIN,
702 on_service_permit_join_resp, resp_cb_data);
704 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
706 /* Free response callback data */
707 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
709 /* Send failure response */
710 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
718 static void on_service_leave_request_resp(ZigBeeServiceInterface *service_interface,
719 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
721 ZigbeeServiceInterfaceRespCbData_t *cb_data =
722 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
724 ZigbeeService *service_object;
725 GDBusMethodInvocation *invocation;
726 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
728 NOT_USED(service_interface);
729 NOT_USED(request_id);
731 if (NULL == resp_data || 0 == resp_data_len) {
732 Z_LOGE("resp_data is null");
736 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
737 zblib_check_null_ret("service_object", service_object);
739 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
740 zblib_check_null_ret("invocation", invocation);
742 zigbee_service_complete_leave_request(service_object, invocation, payload->result);
747 static gboolean on_service_leave_request(ZigbeeService *service_object,
748 GDBusMethodInvocation *invocation,
754 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
755 ZigbeeServiceLeaveRequest_t req;
756 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
758 GVariantIter *iter = NULL;
763 memset(&req, 0x0, sizeof(ZigbeeServiceLeaveRequest_t));
765 /* Update request structure */
766 g_variant_get(eui64, "ay", &iter);
767 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
769 if (i >= ZIGBEE_EUI64_SIZE)
772 req.remove_child = remove_child;
775 /* Allocate response callback data */
777 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
778 invocation, NULL, 0);
779 if (NULL == resp_cb_data) {
780 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
782 /* Send failure response */
783 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
788 /* Dispatch request */
789 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
790 ZBLIB_DRIVER_TYPE_SERVICE,
791 ZBLIB_SERVICE_OPS_LEAVE_REQUEST,
793 on_service_leave_request_resp, resp_cb_data);
795 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
797 /* Free response callback data */
798 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
800 /* Send failure response */
801 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
809 static void on_service_get_device_list_resp(ZigBeeServiceInterface *service_interface,
810 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
812 ZigbeeServiceInterfaceRespCbData_t *cb_data =
813 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
815 ZigbeeService *service_object;
816 GDBusMethodInvocation *invocation;
818 NOT_USED(service_interface);
819 NOT_USED(request_id);
821 if (NULL == resp_data || 0 == resp_data_len) {
822 Z_LOGE("resp_data is null");
827 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
828 zblib_check_null_ret("service_object", service_object);
830 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
831 zblib_check_null_ret("invocation", invocation);
833 /* To-To : zigbee_service_complete_get_device_list */
834 //zigbee_service_complete_get_device_list(service_object, invocation, resp_data);
839 static gboolean on_service_get_device_list(ZigbeeService *service_object,
840 GDBusMethodInvocation *invocation,
843 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
844 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
848 /* Allocate response callback data */
850 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
851 invocation, NULL, 0);
852 if (NULL == resp_cb_data) {
853 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
855 /* Send failure response */
856 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
861 /* Dispatch request */
862 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
863 ZBLIB_DRIVER_TYPE_SERVICE,
864 ZBLIB_SERVICE_OPS_GET_DEVICE_LIST,
866 on_service_get_device_list_resp, resp_cb_data);
868 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
870 /* Free response callback data */
871 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
873 /* Send failure response */
874 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
882 static void on_service_get_mac_resp(ZigBeeServiceInterface *service_interface,
883 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
885 ZigbeeServiceInterfaceRespCbData_t *cb_data =
886 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
888 ZigbeeService *service_object;
889 GDBusMethodInvocation *invocation;
892 NOT_USED(service_interface);
893 NOT_USED(request_id);
895 if (NULL == resp_data || 0 == resp_data_len) {
896 Z_LOGE("resp_data is null");
901 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
902 zblib_check_null_ret("service_object", service_object);
904 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
905 zblib_check_null_ret("invocation", invocation);
907 /* Todo : plugin must load resp_data as char pointer */
908 //zigbee_service_complete_get_mac(service_object, invocation, resp_data);
914 static gboolean on_service_get_mac(ZigbeeService *service_object,
915 GDBusMethodInvocation *invocation,
918 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
919 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
923 /* Allocate response callback data */
925 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
926 invocation, NULL, 0);
927 if (NULL == resp_cb_data) {
928 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
930 /* Send failure response */
931 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
936 /* Dispatch request */
937 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
938 ZBLIB_DRIVER_TYPE_SERVICE,
939 ZBLIB_SERVICE_OPS_GET_MAC,
941 on_service_get_mac_resp, resp_cb_data);
943 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
945 /* Free response callback data */
946 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
948 /* Send failure response */
949 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
957 static void on_service_get_device_info_resp(ZigBeeServiceInterface *service_interface,
958 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
960 ZigbeeServiceInterfaceRespCbData_t *cb_data =
961 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
963 ZigbeeService *service_object;
964 GDBusMethodInvocation *invocation;
967 NOT_USED(service_interface);
968 NOT_USED(request_id);
970 if (NULL == resp_data || 0 == resp_data_len) {
971 Z_LOGE("resp_data is null");
976 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
977 zblib_check_null_ret("service_object", service_object);
979 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
980 zblib_check_null_ret("invocation", invocation);
982 /* To-Do : zigbee_service_complete_get_device_list */
983 //zigbee_service_complete_get_device_info(service_object, invocation, resp_data);
988 static gboolean on_service_get_device_info(ZigbeeService *service_object,
989 GDBusMethodInvocation *invocation,
992 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
993 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
997 /* Allocate response callback data */
999 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1000 invocation, NULL, 0);
1001 if (NULL == resp_cb_data) {
1002 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1004 /* Send failure response */
1005 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1010 /* Dispatch request */
1011 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1012 ZBLIB_DRIVER_TYPE_SERVICE,
1013 ZBLIB_SERVICE_OPS_GET_DEVICE_INFO,
1015 on_service_get_device_info_resp, resp_cb_data);
1017 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1019 /* Free response callback data */
1020 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1022 /* Send failure response */
1023 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1031 static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_interface,
1032 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1034 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1035 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1037 ZigbeeService *service_object;
1038 GDBusMethodInvocation *invocation;
1041 NOT_USED(service_interface);
1042 NOT_USED(request_id);
1044 if (NULL == resp_data || 0 == resp_data_len) {
1045 Z_LOGE("resp_data is null");
1050 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1051 zblib_check_null_ret("service_object", service_object);
1053 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1054 zblib_check_null_ret("invocation", invocation);
1056 /* To fix : end-points must be changed gchar* -> GVariant ay */
1057 //zigbee_service_complete_get_endpoint_list(service_object, invocation, resp_data);
1062 static gboolean on_service_get_endpoint_list(ZigbeeService *service_object,
1063 GDBusMethodInvocation *invocation,
1067 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1068 ZigbeeServiceGetEndpointList_t req;
1069 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1071 GVariantIter *iter = NULL;
1076 memset(&req, 0x0, sizeof(ZigbeeServiceGetEndpointList_t));
1078 /* Update request structure */
1079 g_variant_get(eui64, "ay", &iter);
1080 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
1082 if (i >= ZIGBEE_EUI64_SIZE)
1086 /* Allocate response callback data */
1088 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1089 invocation, NULL, 0);
1090 if (NULL == resp_cb_data) {
1091 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1093 /* Send failure response */
1094 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1099 /* Dispatch request */
1100 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1101 ZBLIB_DRIVER_TYPE_SERVICE,
1102 ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST,
1104 on_service_get_endpoint_list_resp, resp_cb_data);
1106 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1108 /* Free response callback data */
1109 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1111 /* Send failure response */
1112 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1120 static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_interface,
1121 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1123 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1124 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1126 ZigbeeService *service_object;
1127 GDBusMethodInvocation *invocation;
1130 NOT_USED(service_interface);
1131 NOT_USED(request_id);
1133 if (NULL == resp_data || 0 == resp_data_len) {
1134 Z_LOGE("resp_data is null");
1139 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1140 zblib_check_null_ret("service_object", service_object);
1142 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1143 zblib_check_null_ret("invocation", invocation);
1145 /* To-Do : zigbee_service_complete_get_cluster_list */
1146 //zigbee_service_complete_get_cluster_list(service_object, invocation, resp_data);
1151 static gboolean on_service_get_cluster_list(ZigbeeService *service_object,
1152 GDBusMethodInvocation *invocation,
1157 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1158 ZigbeeServiceGetClusterList_t req;
1159 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1161 GVariantIter *iter = NULL;
1166 memset(&req, 0x0, sizeof(ZigbeeServiceGetClusterList_t));
1168 /* Update request structure */
1169 g_variant_get(eui64, "ay", &iter);
1170 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
1172 if (i >= ZIGBEE_EUI64_SIZE)
1175 req.endpoint = endpoint;
1177 /* Allocate response callback data */
1179 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1180 invocation, NULL, 0);
1181 if (NULL == resp_cb_data) {
1182 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1184 /* Send failure response */
1185 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1190 /* Dispatch request */
1191 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1192 ZBLIB_DRIVER_TYPE_SERVICE,
1193 ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST,
1195 on_service_get_cluster_list_resp, resp_cb_data);
1197 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1199 /* Free response callback data */
1200 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1202 /* Send failure response */
1203 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1211 static void on_service_get_node_type_resp(ZigBeeServiceInterface *service_interface,
1212 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1214 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1215 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1217 ZigbeeService *service_object;
1218 GDBusMethodInvocation *invocation;
1219 ZigbeeServiceServiceNodeType_t *payload =
1220 (ZigbeeServiceServiceNodeType_t *)resp_data;
1223 NOT_USED(service_interface);
1224 NOT_USED(request_id);
1226 if (NULL == resp_data || 0 == resp_data_len) {
1227 Z_LOGE("resp_data is null");
1232 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1233 zblib_check_null_ret("service_object", service_object);
1235 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1236 zblib_check_null_ret("invocation", invocation);
1238 zigbee_service_complete_get_node_type(service_object, invocation,
1239 payload->result, payload->node_type);
1244 static gboolean on_service_get_node_type(ZigbeeService *service_object,
1245 GDBusMethodInvocation *invocation,
1249 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1250 ZigbeeServiceGetNodeType_t req;
1251 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1253 GVariantIter *iter = NULL;
1258 memset(&req, 0x0, sizeof(ZigbeeServiceGetNodeType_t));
1260 /* Update request structure */
1261 g_variant_get(eui64, "ay", &iter);
1262 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
1264 if (i >= ZIGBEE_EUI64_SIZE)
1268 /* Allocate response callback data */
1270 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1271 invocation, NULL, 0);
1272 if (NULL == resp_cb_data) {
1273 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1275 /* Send failure response */
1276 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1281 /* Dispatch request */
1282 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1283 ZBLIB_DRIVER_TYPE_SERVICE,
1284 ZBLIB_SERVICE_OPS_GET_NODE_TYPE,
1286 on_service_get_node_type_resp, resp_cb_data);
1288 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1290 /* Free response callback data */
1291 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1293 /* Send failure response */
1294 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1302 void zigbee_service_dbus_interface_service_notification(ZigBeeServiceInterface *service_interface,
1303 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
1305 ZigbeeService *service_object;
1307 zblib_check_null_ret("service_interface", service_interface);
1309 if (NULL == noti_data || 0 == noti_data_len) {
1310 Z_LOGE("noti_data is NULL");
1314 service_object = _service_interface_ref_zigbee_service(service_interface);
1315 zblib_check_null_ret("service_object", service_object);
1317 NOT_USED(noti_cb_data);
1320 case ZBLIB_SERVICE_NOTI_FORM_NETWORK_DONE: {
1321 ZigbeeServiceServiceFormNetworkDone_t *panid_t =
1322 (ZigbeeServiceServiceFormNetworkDone_t*)noti_data;
1324 Z_LOGD("form_network_done : [0x%X]", panid_t->pan_id);
1326 zigbee_service_emit_form_network_done(service_object, panid_t->pan_id);
1329 case ZBLIB_SERVICE_NOTI_CHILD_JOINED: {
1330 zigbee_service_emit_child_joined(service_object, (GVariant *)noti_data);
1333 case ZBLIB_SERVICE_NOTI_CHILD_REJOINED: {
1334 ZigbeeServiceServiceChildRejoined_t ieee_addr_t;
1335 memcpy(&ieee_addr_t, noti_data, noti_data_len);
1336 zigbee_service_emit_child_rejoined(service_object, ieee_addr_t.eui64);
1339 case ZBLIB_SERVICE_NOTI_CHILD_LEFT: {
1340 ZigbeeServiceServiceChildLeft_t child_left_t;
1341 memcpy(&child_left_t, noti_data, noti_data_len);
1342 zigbee_service_emit_child_left(service_object, child_left_t.eui64, child_left_t.status);
1345 case ZBLIB_SERVICE_NOTI_LEAVE_NETWORK_DONE: {
1346 ZigbeeServiceServiceLeaveNetworkDone_t leave_net_t;
1347 memcpy(&leave_net_t, noti_data, noti_data_len);
1348 zigbee_service_emit_leave_network_done(service_object, leave_net_t.pan_id);
1352 Z_LOGE("Unexpected notification [%x]", noti_id);
1356 /* ZigbeeService should be dereferenced */
1357 g_object_unref(service_object);
1360 gboolean zigbee_service_dbus_interface_service_init(ZigBeeServiceInterface *service_interface,
1361 ZigbeeObjectSkeleton *zigbee_object)
1363 ZigbeeService *service_object;
1365 if (NULL == service_interface) {
1366 Z_LOGE("service_interface is NULL");
1370 service_object = zigbee_service_skeleton_new();
1371 zigbee_object_skeleton_set_service(zigbee_object, service_object);
1372 g_object_unref(service_object);
1374 Z_LOGI("service_object: [%p]", service_object);
1377 * Register signal handlers for 'service' interface
1379 g_signal_connect(service_object,
1381 G_CALLBACK(on_service_enable), service_interface);
1383 g_signal_connect(service_object,
1385 G_CALLBACK(on_service_disable), service_interface);
1387 g_signal_connect(service_object,
1388 "handle-zb-hw-reset",
1389 G_CALLBACK(on_service_zb_hw_reset), service_interface);
1391 g_signal_connect(service_object,
1392 "handle-form-network",
1393 G_CALLBACK(on_service_form_network), service_interface);
1395 g_signal_connect(service_object,
1396 "handle-coex-start",
1397 G_CALLBACK(on_service_coex_start), service_interface);
1399 g_signal_connect(service_object,
1401 G_CALLBACK(on_service_coex_stop), service_interface);
1403 g_signal_connect(service_object,
1404 "handle-leave-network",
1405 G_CALLBACK(on_service_leave_network), service_interface);
1407 g_signal_connect(service_object,
1408 "handle-get-network-info",
1409 G_CALLBACK(on_service_get_network_info), service_interface);
1411 g_signal_connect(service_object,
1412 "handle-permit-join",
1413 G_CALLBACK(on_service_permit_join), service_interface);
1415 g_signal_connect(service_object,
1416 "handle-leave-request",
1417 G_CALLBACK(on_service_leave_request), service_interface);
1419 g_signal_connect(service_object,
1420 "handle-get-device-list",
1421 G_CALLBACK(on_service_get_device_list), service_interface);
1423 g_signal_connect(service_object,
1425 G_CALLBACK(on_service_get_mac), service_interface);
1427 g_signal_connect(service_object,
1428 "handle-get-device-info",
1429 G_CALLBACK(on_service_get_device_info), service_interface);
1431 g_signal_connect(service_object,
1432 "handle-get-endpoint-list",
1433 G_CALLBACK(on_service_get_endpoint_list), service_interface);
1435 g_signal_connect(service_object,
1436 "handle-get-cluster-list",
1437 G_CALLBACK(on_service_get_cluster_list), service_interface);
1439 g_signal_connect(service_object,
1440 "handle-get-node-type",
1441 G_CALLBACK(on_service_get_node_type), service_interface);