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;
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);
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;
55 NOT_USED(service_interface);
58 NOT_USED(resp_data_len);
60 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
61 zblib_check_null_ret("service_object", service_object);
63 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
64 zblib_check_null_ret("invocation", invocation);
66 zigbee_service_complete_enable(service_object, invocation, TRUE);
71 static gboolean on_service_enable(ZigbeeService *service_object,
72 GDBusMethodInvocation *invocation,
75 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
76 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
82 /* Allocate response callback data */
84 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
86 if (NULL == resp_cb_data) {
87 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
89 /* Send failure response */
90 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
95 /* Dispatch request */
96 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
97 ZBLIB_DRIVER_TYPE_SERVICE,
98 ZBLIB_SERVICE_OPS_ENABLE,
100 on_service_enable_resp, resp_cb_data);
102 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
104 /* Free response callback data */
105 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
107 /* Send failure response */
108 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
116 static void on_service_disable_resp(ZigBeeServiceInterface *service_interface,
117 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
119 ZigbeeServiceInterfaceRespCbData_t *cb_data =
120 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
122 ZigbeeService *service_object;
123 GDBusMethodInvocation *invocation;
125 NOT_USED(service_interface);
126 NOT_USED(request_id);
128 NOT_USED(resp_data_len);
130 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
131 zblib_check_null_ret("service_object", service_object);
133 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
134 zblib_check_null_ret("invocation", invocation);
136 zigbee_service_complete_disable(service_object, invocation);
141 static gboolean on_service_disable(ZigbeeService *service_object,
142 GDBusMethodInvocation *invocation,
145 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
146 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
150 /* Allocate response callback data */
152 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
153 invocation, NULL, 0);
154 if (NULL == resp_cb_data) {
155 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
157 /* Send failure response */
158 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
163 /* Dispatch request */
164 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
165 ZBLIB_DRIVER_TYPE_SERVICE,
166 ZBLIB_SERVICE_OPS_DISABLE,
168 on_service_disable_resp, resp_cb_data);
170 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
172 /* Free response callback data */
173 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
175 /* Send failure response */
176 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
184 static void on_service_zb_hw_reset_resp(ZigBeeServiceInterface *service_interface,
185 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
187 ZigbeeServiceInterfaceRespCbData_t *cb_data =
188 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
190 ZigbeeService *service_object;
191 GDBusMethodInvocation *invocation;
193 NOT_USED(service_interface);
194 NOT_USED(request_id);
196 NOT_USED(resp_data_len);
198 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
199 zblib_check_null_ret("service_object", service_object);
201 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
202 zblib_check_null_ret("invocation", invocation);
204 zigbee_service_complete_zb_hw_reset(service_object, invocation);
209 static gboolean on_service_zb_hw_reset(ZigbeeService *service_object,
210 GDBusMethodInvocation *invocation,
213 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
214 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
218 /* Allocate response callback data */
220 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
221 invocation, NULL, 0);
222 if (NULL == resp_cb_data) {
223 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
225 /* Send failure response */
226 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
231 /* Dispatch request */
232 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
233 ZBLIB_DRIVER_TYPE_SERVICE,
234 ZBLIB_SERVICE_OPS_ZB_HW_RESET,
236 on_service_zb_hw_reset_resp, resp_cb_data);
238 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
240 /* Free response callback data */
241 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
243 /* Send failure response */
244 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
252 static void on_service_form_network_resp(ZigBeeServiceInterface *service_interface,
253 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
255 ZigbeeServiceInterfaceRespCbData_t *cb_data =
256 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
258 ZigbeeService *service_object;
259 GDBusMethodInvocation *invocation;
261 NOT_USED(service_interface);
262 NOT_USED(request_id);
264 NOT_USED(resp_data_len);
266 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
267 zblib_check_null_ret("service_object", service_object);
269 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
270 zblib_check_null_ret("invocation", invocation);
272 zigbee_service_complete_form_network(service_object, invocation);
277 static gboolean on_service_form_network(ZigbeeService *service_object,
278 GDBusMethodInvocation *invocation,
281 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
282 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
286 /* Allocate response callback data */
288 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
289 invocation, NULL, 0);
290 if (NULL == resp_cb_data) {
291 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
293 /* Send failure response */
294 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
299 /* Dispatch request */
300 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
301 ZBLIB_DRIVER_TYPE_SERVICE,
302 ZBLIB_SERVICE_OPS_FORM_NETWORK,
304 on_service_form_network_resp, resp_cb_data);
306 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
308 /* Free response callback data */
309 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
311 /* Send failure response */
312 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
320 static void on_service_coex_start_resp(ZigBeeServiceInterface *service_interface,
321 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
323 ZigbeeServiceInterfaceRespCbData_t *cb_data =
324 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
326 ZigbeeService *service_object;
327 GDBusMethodInvocation *invocation;
329 NOT_USED(service_interface);
330 NOT_USED(request_id);
332 NOT_USED(resp_data_len);
334 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
335 zblib_check_null_ret("service_object", service_object);
337 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
338 zblib_check_null_ret("invocation", invocation);
340 zigbee_service_complete_coex_start(service_object, invocation);
345 static gboolean on_service_coex_start(ZigbeeService *service_object,
346 GDBusMethodInvocation *invocation,
350 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
351 ZigbeeServiceCoexStart_t req;
352 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
356 memset(&req, 0x0, sizeof(ZigbeeServiceCoexStart_t));
358 /* Update request structure */
359 req.channel = channel;
361 /* Allocate response callback data */
363 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
364 invocation, NULL, 0);
365 if (NULL == resp_cb_data) {
366 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
368 /* Send failure response */
369 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
374 /* Dispatch request */
375 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
376 ZBLIB_DRIVER_TYPE_SERVICE,
377 ZBLIB_SERVICE_OPS_COEX_START,
379 on_service_coex_start_resp, resp_cb_data);
381 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
383 /* Free response callback data */
384 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
386 /* Send failure response */
387 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
395 static void on_service_coex_stop_resp(ZigBeeServiceInterface *service_interface,
396 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
398 ZigbeeServiceInterfaceRespCbData_t *cb_data =
399 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
401 ZigbeeService *service_object;
402 GDBusMethodInvocation *invocation;
404 NOT_USED(service_interface);
405 NOT_USED(request_id);
407 NOT_USED(resp_data_len);
409 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
410 zblib_check_null_ret("service_object", service_object);
412 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
413 zblib_check_null_ret("invocation", invocation);
415 zigbee_service_complete_coex_stop(service_object, invocation);
420 static gboolean on_service_coex_stop(ZigbeeService *service_object,
421 GDBusMethodInvocation *invocation,
424 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
425 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
429 /* Allocate response callback data */
431 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
432 invocation, NULL, 0);
433 if (NULL == resp_cb_data) {
434 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
436 /* Send failure response */
437 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
442 /* Dispatch request */
443 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
444 ZBLIB_DRIVER_TYPE_SERVICE,
445 ZBLIB_SERVICE_OPS_COEX_STOP,
447 on_service_coex_stop_resp, resp_cb_data);
449 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
451 /* Free response callback data */
452 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
454 /* Send failure response */
455 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
463 static void on_service_leave_network_resp(ZigBeeServiceInterface *service_interface,
464 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
466 ZigbeeServiceInterfaceRespCbData_t *cb_data =
467 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
469 ZigbeeService *service_object;
470 GDBusMethodInvocation *invocation;
472 NOT_USED(service_interface);
473 NOT_USED(request_id);
475 NOT_USED(resp_data_len);
477 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
478 zblib_check_null_ret("service_object", service_object);
480 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
481 zblib_check_null_ret("invocation", invocation);
483 zigbee_service_complete_leave_network(service_object, invocation);
488 static gboolean on_service_leave_network(ZigbeeService *service_object,
489 GDBusMethodInvocation *invocation,
492 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
493 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
497 /* Allocate response callback data */
499 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
500 invocation, NULL, 0);
501 if (NULL == resp_cb_data) {
502 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
504 /* Send failure response */
505 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
510 /* Dispatch request */
511 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
512 ZBLIB_DRIVER_TYPE_SERVICE,
513 ZBLIB_SERVICE_OPS_LEAVE_NETWORK,
515 on_service_leave_network_resp, resp_cb_data);
517 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
519 /* Free response callback data */
520 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
522 /* Send failure response */
523 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
531 static void on_service_get_network_info_resp(ZigBeeServiceInterface *service_interface,
532 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
534 ZigbeeServiceInterfaceRespCbData_t *cb_data =
535 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
537 ZigbeeService *service_object;
538 GDBusMethodInvocation *invocation;
540 ZigbeeServiceGetNetworkInfo_t payload;
542 NOT_USED(service_interface);
543 NOT_USED(request_id);
545 NOT_USED(resp_data_len);
547 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
548 zblib_check_null_ret("service_object", service_object);
550 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
551 zblib_check_null_ret("invocation", invocation);
553 memcpy(&payload, resp_data, resp_data_len);
554 zigbee_service_complete_get_network_info(service_object, invocation,
555 payload.eui64, payload.node_id, payload.pan_id, payload.channel,
556 payload.radio_tx_power);
561 static gboolean on_service_get_network_info(ZigbeeService *service_object,
562 GDBusMethodInvocation *invocation,
565 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
566 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
570 /* Allocate response callback data */
572 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
573 invocation, NULL, 0);
574 if (NULL == resp_cb_data) {
575 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
577 /* Send failure response */
578 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
583 /* Dispatch request */
584 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
585 ZBLIB_DRIVER_TYPE_SERVICE,
586 ZBLIB_SERVICE_OPS_GET_NETWORK_INFO,
588 on_service_get_network_info_resp, resp_cb_data);
590 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
592 /* Free response callback data */
593 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
595 /* Send failure response */
596 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
604 static void on_service_permit_join_resp(ZigBeeServiceInterface *service_interface,
605 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
607 ZigbeeServiceInterfaceRespCbData_t *cb_data =
608 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
610 ZigbeeService *service_object;
611 GDBusMethodInvocation *invocation;
613 NOT_USED(service_interface);
614 NOT_USED(request_id);
616 NOT_USED(resp_data_len);
618 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
619 zblib_check_null_ret("service_object", service_object);
621 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
622 zblib_check_null_ret("invocation", invocation);
624 zigbee_service_complete_permit_join(service_object, invocation);
629 static gboolean on_service_permit_join(ZigbeeService *service_object,
630 GDBusMethodInvocation *invocation,
632 gboolean permit_join,
635 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
636 ZigbeeServicePermitJoin_t req;
637 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
641 memset(&req, 0x0, sizeof(ZigbeeServicePermitJoin_t));
643 /* Update request structure */
644 req.duration = duration;
645 req.permit_join = permit_join;
647 /* Allocate response callback data */
649 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
650 invocation, NULL, 0);
651 if (NULL == resp_cb_data) {
652 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
654 /* Send failure response */
655 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
660 /* Dispatch request */
661 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
662 ZBLIB_DRIVER_TYPE_SERVICE,
663 ZBLIB_SERVICE_OPS_PERMIT_JOIN,
665 on_service_permit_join_resp, resp_cb_data);
667 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
669 /* Free response callback data */
670 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
672 /* Send failure response */
673 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
681 static void on_service_leave_request_resp(ZigBeeServiceInterface *service_interface,
682 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
684 ZigbeeServiceInterfaceRespCbData_t *cb_data =
685 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
687 ZigbeeService *service_object;
688 GDBusMethodInvocation *invocation;
690 NOT_USED(service_interface);
691 NOT_USED(request_id);
693 NOT_USED(resp_data_len);
695 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
696 zblib_check_null_ret("service_object", service_object);
698 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
699 zblib_check_null_ret("invocation", invocation);
701 zigbee_service_complete_leave_request(service_object, invocation);
706 static gboolean on_service_leave_request(ZigbeeService *service_object,
707 GDBusMethodInvocation *invocation,
713 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
714 ZigbeeServiceLeaveRequest_t req;
715 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
717 GVariantIter *iter = NULL;
722 memset(&req, 0x0, sizeof(ZigbeeServiceLeaveRequest_t));
724 /* Update request structure */
725 g_variant_get(eui64, "ay", &iter);
726 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
728 if (i >= ZIGBEE_EUI64_SIZE)
731 req.remove_child = remove_child;
734 /* Allocate response callback data */
736 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
737 invocation, NULL, 0);
738 if (NULL == resp_cb_data) {
739 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
741 /* Send failure response */
742 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
747 /* Dispatch request */
748 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
749 ZBLIB_DRIVER_TYPE_SERVICE,
750 ZBLIB_SERVICE_OPS_LEAVE_REQUEST,
752 on_service_leave_request_resp, resp_cb_data);
754 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
756 /* Free response callback data */
757 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
759 /* Send failure response */
760 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
768 static void on_service_get_device_list_resp(ZigBeeServiceInterface *service_interface,
769 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
771 ZigbeeServiceInterfaceRespCbData_t *cb_data =
772 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
774 ZigbeeService *service_object;
775 GDBusMethodInvocation *invocation;
777 NOT_USED(service_interface);
778 NOT_USED(request_id);
780 if (NULL == resp_data || 0 == resp_data_len) {
781 Z_LOGE("resp_data is null");
786 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
787 zblib_check_null_ret("service_object", service_object);
789 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
790 zblib_check_null_ret("invocation", invocation);
792 zigbee_service_complete_get_device_list(service_object, invocation, resp_data);
797 static gboolean on_service_get_device_list(ZigbeeService *service_object,
798 GDBusMethodInvocation *invocation,
801 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
802 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
806 /* Allocate response callback data */
808 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
809 invocation, NULL, 0);
810 if (NULL == resp_cb_data) {
811 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
813 /* Send failure response */
814 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
819 /* Dispatch request */
820 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
821 ZBLIB_DRIVER_TYPE_SERVICE,
822 ZBLIB_SERVICE_OPS_GET_DEVICE_LIST,
824 on_service_get_device_list_resp, resp_cb_data);
826 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
828 /* Free response callback data */
829 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
831 /* Send failure response */
832 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
840 static void on_service_get_mac_resp(ZigBeeServiceInterface *service_interface,
841 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
843 ZigbeeServiceInterfaceRespCbData_t *cb_data =
844 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
846 ZigbeeService *service_object;
847 GDBusMethodInvocation *invocation;
850 NOT_USED(service_interface);
851 NOT_USED(request_id);
853 if (NULL == resp_data || 0 == resp_data_len) {
854 Z_LOGE("resp_data is null");
859 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
860 zblib_check_null_ret("service_object", service_object);
862 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
863 zblib_check_null_ret("invocation", invocation);
865 /* Todo : plugin must load resp_data as char pointer */
866 zigbee_service_complete_get_mac(service_object, invocation, resp_data);
872 static gboolean on_service_get_mac(ZigbeeService *service_object,
873 GDBusMethodInvocation *invocation,
876 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
877 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
881 /* Allocate response callback data */
883 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
884 invocation, NULL, 0);
885 if (NULL == resp_cb_data) {
886 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
888 /* Send failure response */
889 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
894 /* Dispatch request */
895 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
896 ZBLIB_DRIVER_TYPE_SERVICE,
897 ZBLIB_SERVICE_OPS_GET_MAC,
899 on_service_get_mac_resp, resp_cb_data);
901 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
903 /* Free response callback data */
904 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
906 /* Send failure response */
907 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
915 static void on_service_get_device_info_resp(ZigBeeServiceInterface *service_interface,
916 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
918 ZigbeeServiceInterfaceRespCbData_t *cb_data =
919 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
921 ZigbeeService *service_object;
922 GDBusMethodInvocation *invocation;
925 NOT_USED(service_interface);
926 NOT_USED(request_id);
928 if (NULL == resp_data || 0 == resp_data_len) {
929 Z_LOGE("resp_data is null");
934 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
935 zblib_check_null_ret("service_object", service_object);
937 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
938 zblib_check_null_ret("invocation", invocation);
940 zigbee_service_complete_get_device_info(service_object, invocation, resp_data);
945 static gboolean on_service_get_device_info(ZigbeeService *service_object,
946 GDBusMethodInvocation *invocation,
949 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
950 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
954 /* Allocate response callback data */
956 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
957 invocation, NULL, 0);
958 if (NULL == resp_cb_data) {
959 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
961 /* Send failure response */
962 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
967 /* Dispatch request */
968 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
969 ZBLIB_DRIVER_TYPE_SERVICE,
970 ZBLIB_SERVICE_OPS_GET_DEVICE_INFO,
972 on_service_get_device_info_resp, resp_cb_data);
974 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
976 /* Free response callback data */
977 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
979 /* Send failure response */
980 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
988 static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_interface,
989 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
991 ZigbeeServiceInterfaceRespCbData_t *cb_data =
992 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
994 ZigbeeService *service_object;
995 GDBusMethodInvocation *invocation;
998 NOT_USED(service_interface);
999 NOT_USED(request_id);
1001 if (NULL == resp_data || 0 == resp_data_len) {
1002 Z_LOGE("resp_data is null");
1007 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1008 zblib_check_null_ret("service_object", service_object);
1010 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1011 zblib_check_null_ret("invocation", invocation);
1013 /* To fix : end-points must be changed gchar* -> GVariant ay */
1014 zigbee_service_complete_get_endpoint_list(service_object, invocation, resp_data);
1019 static gboolean on_service_get_endpoint_list(ZigbeeService *service_object,
1020 GDBusMethodInvocation *invocation,
1024 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1025 ZigbeeServiceGetEndpointList_t req;
1026 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1028 GVariantIter *iter = NULL;
1033 memset(&req, 0x0, sizeof(ZigbeeServiceGetEndpointList_t));
1035 /* Update request structure */
1036 g_variant_get(eui64, "ay", &iter);
1037 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
1039 if (i >= ZIGBEE_EUI64_SIZE)
1043 /* Allocate response callback data */
1045 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1046 invocation, NULL, 0);
1047 if (NULL == resp_cb_data) {
1048 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1050 /* Send failure response */
1051 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1056 /* Dispatch request */
1057 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1058 ZBLIB_DRIVER_TYPE_SERVICE,
1059 ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST,
1061 on_service_get_endpoint_list_resp, resp_cb_data);
1063 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1065 /* Free response callback data */
1066 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1068 /* Send failure response */
1069 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1077 static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_interface,
1078 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1080 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1081 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1083 ZigbeeService *service_object;
1084 GDBusMethodInvocation *invocation;
1087 NOT_USED(service_interface);
1088 NOT_USED(request_id);
1090 if (NULL == resp_data || 0 == resp_data_len) {
1091 Z_LOGE("resp_data is null");
1096 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1097 zblib_check_null_ret("service_object", service_object);
1099 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1100 zblib_check_null_ret("invocation", invocation);
1102 zigbee_service_complete_get_cluster_list(service_object, invocation, resp_data);
1107 static gboolean on_service_get_cluster_list(ZigbeeService *service_object,
1108 GDBusMethodInvocation *invocation,
1113 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1114 ZigbeeServiceGetClusterList_t req;
1115 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1117 GVariantIter *iter = NULL;
1122 memset(&req, 0x0, sizeof(ZigbeeServiceGetClusterList_t));
1124 /* Update request structure */
1125 g_variant_get(eui64, "ay", &iter);
1126 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
1128 if (i >= ZIGBEE_EUI64_SIZE)
1131 req.endpoint = endpoint;
1133 /* Allocate response callback data */
1135 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1136 invocation, NULL, 0);
1137 if (NULL == resp_cb_data) {
1138 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1140 /* Send failure response */
1141 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1146 /* Dispatch request */
1147 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1148 ZBLIB_DRIVER_TYPE_SERVICE,
1149 ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST,
1151 on_service_get_cluster_list_resp, resp_cb_data);
1153 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1155 /* Free response callback data */
1156 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1158 /* Send failure response */
1159 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1167 static void on_service_get_node_type_resp(ZigBeeServiceInterface *service_interface,
1168 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1170 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1171 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1173 ZigbeeService *service_object;
1174 GDBusMethodInvocation *invocation;
1175 ZigbeeServiceServiceNodeType_t payload;
1178 NOT_USED(service_interface);
1179 NOT_USED(request_id);
1181 if (NULL == resp_data || 0 == resp_data_len) {
1182 Z_LOGE("resp_data is null");
1187 memcpy(&payload, resp_data, resp_data_len);
1189 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1190 zblib_check_null_ret("service_object", service_object);
1192 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1193 zblib_check_null_ret("invocation", invocation);
1195 zigbee_service_complete_get_node_type(service_object, invocation, payload.node_type);
1200 static gboolean on_service_get_node_type(ZigbeeService *service_object,
1201 GDBusMethodInvocation *invocation,
1205 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1206 ZigbeeServiceGetNodeType_t req;
1207 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1209 GVariantIter *iter = NULL;
1214 memset(&req, 0x0, sizeof(ZigbeeServiceGetNodeType_t));
1216 /* Update request structure */
1217 g_variant_get(eui64, "ay", &iter);
1218 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
1220 if (i >= ZIGBEE_EUI64_SIZE)
1224 /* Allocate response callback data */
1226 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1227 invocation, NULL, 0);
1228 if (NULL == resp_cb_data) {
1229 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1231 /* Send failure response */
1232 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1237 /* Dispatch request */
1238 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1239 ZBLIB_DRIVER_TYPE_SERVICE,
1240 ZBLIB_SERVICE_OPS_GET_NODE_TYPE,
1242 on_service_get_node_type_resp, resp_cb_data);
1244 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1246 /* Free response callback data */
1247 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1249 /* Send failure response */
1250 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1258 void zigbee_service_dbus_interface_service_notification(ZigBeeServiceInterface *service_interface,
1259 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
1261 ZigbeeService *service_object;
1263 zblib_check_null_ret("service_interface", service_interface);
1265 if (NULL == noti_data || 0 == noti_data_len) {
1266 Z_LOGE("noti_data is NULL");
1270 service_object = _service_interface_ref_zigbee_service(service_interface);
1271 zblib_check_null_ret("service_object", service_object);
1273 NOT_USED(noti_cb_data);
1276 case ZBLIB_SERVICE_NOTI_FORM_NETWORK_DONE: {
1277 ZigbeeServiceServiceFormNetworkDone_t panid_t;
1278 memcpy(&panid_t, noti_data, noti_data_len);
1279 zigbee_service_emit_form_network_done(service_object, panid_t.pan_id);
1282 case ZBLIB_SERVICE_NOTI_CHILD_JOINED: {
1283 zigbee_service_emit_child_joined(service_object, (GVariant *)noti_data);
1286 case ZBLIB_SERVICE_NOTI_CHILD_REJOINED: {
1287 ZigbeeServiceServiceChildRejoined_t ieee_addr_t;
1288 memcpy(&ieee_addr_t, noti_data, noti_data_len);
1289 zigbee_service_emit_child_rejoined(service_object, ieee_addr_t.eui64);
1292 case ZBLIB_SERVICE_NOTI_CHILD_LEFT: {
1293 ZigbeeServiceServiceChildLeft_t child_left_t;
1294 memcpy(&child_left_t, noti_data, noti_data_len);
1295 zigbee_service_emit_child_left(service_object, child_left_t.eui64, child_left_t.status);
1298 case ZBLIB_SERVICE_NOTI_LEAVE_NETWORK_DONE: {
1299 ZigbeeServiceServiceLeaveNetworkDone_t leave_net_t;
1300 memcpy(&leave_net_t, noti_data, noti_data_len);
1301 zigbee_service_emit_leave_network_done(service_object, leave_net_t.pan_id);
1305 Z_LOGE("Unexpected notification [%x]", noti_id);
1309 /* ZigbeeService should be dereferenced */
1310 g_object_unref(service_object);
1313 gboolean zigbee_service_dbus_interface_service_init(ZigBeeServiceInterface *service_interface,
1314 ZigbeeObjectSkeleton *zigbee_object)
1316 ZigbeeService *service_object;
1318 if (NULL == service_interface) {
1319 Z_LOGE("service_interface is NULL");
1323 service_object = zigbee_service_skeleton_new();
1324 zigbee_object_skeleton_set_service(zigbee_object, service_object);
1325 g_object_unref(service_object);
1327 Z_LOGI("service_object: [%p]", service_object);
1330 * Register signal handlers for 'service' interface
1332 g_signal_connect(service_object,
1334 G_CALLBACK(on_service_enable), service_interface);
1336 g_signal_connect(service_object,
1338 G_CALLBACK(on_service_disable), service_interface);
1340 g_signal_connect(service_object,
1341 "handle-zb-hw-reset",
1342 G_CALLBACK(on_service_zb_hw_reset), service_interface);
1344 g_signal_connect(service_object,
1345 "handle-form-network",
1346 G_CALLBACK(on_service_form_network), service_interface);
1348 g_signal_connect(service_object,
1349 "handle-coex-start",
1350 G_CALLBACK(on_service_coex_start), service_interface);
1352 g_signal_connect(service_object,
1354 G_CALLBACK(on_service_coex_stop), service_interface);
1356 g_signal_connect(service_object,
1357 "handle-leave-network",
1358 G_CALLBACK(on_service_leave_network), service_interface);
1360 g_signal_connect(service_object,
1361 "handle-get-network-info",
1362 G_CALLBACK(on_service_get_network_info), service_interface);
1364 g_signal_connect(service_object,
1365 "handle-permit-join",
1366 G_CALLBACK(on_service_permit_join), service_interface);
1368 g_signal_connect(service_object,
1369 "handle-leave-request",
1370 G_CALLBACK(on_service_leave_request), service_interface);
1372 g_signal_connect(service_object,
1373 "handle-get-device-list",
1374 G_CALLBACK(on_service_get_device_list), service_interface);
1376 g_signal_connect(service_object,
1378 G_CALLBACK(on_service_get_mac), service_interface);
1380 g_signal_connect(service_object,
1381 "handle-get-device-info",
1382 G_CALLBACK(on_service_get_device_info), service_interface);
1384 g_signal_connect(service_object,
1385 "handle-get-endpoint-list",
1386 G_CALLBACK(on_service_get_endpoint_list), service_interface);
1388 g_signal_connect(service_object,
1389 "handle-get-cluster-list",
1390 G_CALLBACK(on_service_get_cluster_list), service_interface);
1392 g_signal_connect(service_object,
1393 "handle-get-node-type",
1394 G_CALLBACK(on_service_get_node_type), service_interface);