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_zb_hw_reset_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 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
56 NOT_USED(service_interface);
59 if (NULL == resp_data || 0 == resp_data_len) {
60 Z_LOGE("resp_data is null");
65 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
66 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
68 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
69 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
71 zigbee_service_complete_zb_hw_reset(service_object, invocation, payload->result);
76 static gboolean on_service_zb_hw_reset(ZigbeeService *service_object,
77 GDBusMethodInvocation *invocation,
80 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
81 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
85 /* Allocate response callback data */
87 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
89 if (NULL == resp_cb_data) {
90 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
92 /* Send failure response */
93 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
98 /* Dispatch request */
99 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
100 ZBLIB_DRIVER_TYPE_SERVICE,
101 ZBLIB_SERVICE_OPS_ZB_HW_RESET,
103 on_service_zb_hw_reset_resp, resp_cb_data);
105 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
107 /* Free response callback data */
108 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
110 /* Send failure response */
111 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
119 static void on_service_form_network_resp(ZigBeeServiceInterface *service_interface,
120 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
122 ZigbeeServiceInterfaceRespCbData_t *cb_data =
123 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
125 ZigbeeService *service_object;
126 GDBusMethodInvocation *invocation;
127 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
129 NOT_USED(service_interface);
130 NOT_USED(request_id);
132 if (NULL == resp_data || 0 == resp_data_len) {
133 Z_LOGE("resp_data is null");
138 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
139 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
141 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
142 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
144 zigbee_service_complete_form_network(service_object, invocation, payload->result);
149 static gboolean on_service_form_network(ZigbeeService *service_object,
150 GDBusMethodInvocation *invocation,
153 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
154 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
158 /* Allocate response callback data */
160 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
161 invocation, NULL, 0);
162 if (NULL == resp_cb_data) {
163 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
165 /* Send failure response */
166 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
171 /* Dispatch request */
172 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
173 ZBLIB_DRIVER_TYPE_SERVICE,
174 ZBLIB_SERVICE_OPS_FORM_NETWORK,
176 on_service_form_network_resp, resp_cb_data);
178 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
180 /* Free response callback data */
181 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
183 /* Send failure response */
184 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
192 static void on_service_coex_start_resp(ZigBeeServiceInterface *service_interface,
193 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
195 ZigbeeServiceInterfaceRespCbData_t *cb_data =
196 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
198 ZigbeeService *service_object;
199 GDBusMethodInvocation *invocation;
200 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
202 NOT_USED(service_interface);
203 NOT_USED(request_id);
205 if (NULL == resp_data || 0 == resp_data_len) {
206 Z_LOGE("resp_data is null");
211 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
212 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
214 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
215 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
217 zigbee_service_complete_coex_start(service_object, invocation, payload->result);
222 static gboolean on_service_coex_start(ZigbeeService *service_object,
223 GDBusMethodInvocation *invocation,
227 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
228 ZigbeeServiceCoexStart_t req;
229 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
233 memset(&req, 0x0, sizeof(ZigbeeServiceCoexStart_t));
235 /* Update request structure */
236 req.channel = channel;
238 /* Allocate response callback data */
240 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
241 invocation, NULL, 0);
242 if (NULL == resp_cb_data) {
243 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
245 /* Send failure response */
246 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
251 /* Dispatch request */
252 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
253 ZBLIB_DRIVER_TYPE_SERVICE,
254 ZBLIB_SERVICE_OPS_COEX_START,
256 on_service_coex_start_resp, resp_cb_data);
258 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
260 /* Free response callback data */
261 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
263 /* Send failure response */
264 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
272 static void on_service_coex_stop_resp(ZigBeeServiceInterface *service_interface,
273 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
275 ZigbeeServiceInterfaceRespCbData_t *cb_data =
276 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
278 ZigbeeService *service_object;
279 GDBusMethodInvocation *invocation;
280 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
282 NOT_USED(service_interface);
283 NOT_USED(request_id);
285 if (NULL == resp_data || 0 == resp_data_len) {
286 Z_LOGE("resp_data is null");
291 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
292 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
294 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
295 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
297 zigbee_service_complete_coex_stop(service_object, invocation, payload->result);
302 static gboolean on_service_coex_stop(ZigbeeService *service_object,
303 GDBusMethodInvocation *invocation,
306 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
307 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
311 /* Allocate response callback data */
313 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
314 invocation, NULL, 0);
315 if (NULL == resp_cb_data) {
316 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
318 /* Send failure response */
319 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
324 /* Dispatch request */
325 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
326 ZBLIB_DRIVER_TYPE_SERVICE,
327 ZBLIB_SERVICE_OPS_COEX_STOP,
329 on_service_coex_stop_resp, resp_cb_data);
331 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
333 /* Free response callback data */
334 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
336 /* Send failure response */
337 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
345 static void on_service_leave_network_resp(ZigBeeServiceInterface *service_interface,
346 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
348 ZigbeeServiceInterfaceRespCbData_t *cb_data =
349 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
351 ZigbeeService *service_object;
352 GDBusMethodInvocation *invocation;
353 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
355 NOT_USED(service_interface);
356 NOT_USED(request_id);
358 if (NULL == resp_data || 0 == resp_data_len) {
359 Z_LOGE("resp_data is null");
364 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
365 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
367 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
368 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
370 zigbee_service_complete_leave_network(service_object, invocation, payload->result);
375 static gboolean on_service_leave_network(ZigbeeService *service_object,
376 GDBusMethodInvocation *invocation,
379 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
380 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
384 /* Allocate response callback data */
386 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
387 invocation, NULL, 0);
388 if (NULL == resp_cb_data) {
389 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
391 /* Send failure response */
392 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
397 /* Dispatch request */
398 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
399 ZBLIB_DRIVER_TYPE_SERVICE,
400 ZBLIB_SERVICE_OPS_LEAVE_NETWORK,
402 on_service_leave_network_resp, resp_cb_data);
404 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
406 /* Free response callback data */
407 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
409 /* Send failure response */
410 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
418 static void on_service_get_network_info_resp(ZigBeeServiceInterface *service_interface,
419 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
421 ZigbeeServiceInterfaceRespCbData_t *cb_data =
422 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
424 ZigbeeService *service_object;
425 GDBusMethodInvocation *invocation;
427 ZigbeeServiceGetNetworkInfoResp_t *payload =
428 (ZigbeeServiceGetNetworkInfoResp_t*)resp_data;
430 GVariant *v_eui64 = NULL;
432 NOT_USED(service_interface);
433 NOT_USED(request_id);
435 if (NULL == resp_data || 0 == resp_data_len) {
436 Z_LOGE("resp_data is null");
441 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
442 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
444 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
445 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
447 v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
448 payload->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
450 zigbee_service_complete_get_network_info(service_object, invocation,
451 payload->result, v_eui64, payload->node_id,
452 payload->pan_id, payload->channel, payload->radio_tx_power);
457 static gboolean on_service_get_network_info(ZigbeeService *service_object,
458 GDBusMethodInvocation *invocation,
461 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
462 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
466 /* Allocate response callback data */
468 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
469 invocation, NULL, 0);
470 if (NULL == resp_cb_data) {
471 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
473 /* Send failure response */
474 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
479 /* Dispatch request */
480 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
481 ZBLIB_DRIVER_TYPE_SERVICE,
482 ZBLIB_SERVICE_OPS_GET_NETWORK_INFO,
484 on_service_get_network_info_resp, resp_cb_data);
486 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
488 /* Free response callback data */
489 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
491 /* Send failure response */
492 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
500 static void on_service_permit_join_resp(ZigBeeServiceInterface *service_interface,
501 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
503 ZigbeeServiceInterfaceRespCbData_t *cb_data =
504 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
506 ZigbeeService *service_object;
507 GDBusMethodInvocation *invocation;
508 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
510 NOT_USED(service_interface);
511 NOT_USED(request_id);
513 if (NULL == resp_data || 0 == resp_data_len) {
514 Z_LOGE("resp_data is null");
519 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
520 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
522 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
523 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
525 zigbee_service_complete_permit_join(service_object, invocation, payload->result);
530 static gboolean on_service_permit_join(ZigbeeService *service_object,
531 GDBusMethodInvocation *invocation,
533 gboolean permit_join,
536 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
537 ZigbeeServicePermitJoin_t req;
538 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
542 memset(&req, 0x0, sizeof(ZigbeeServicePermitJoin_t));
544 /* Update request structure */
545 req.duration = duration;
546 req.permit_join = permit_join;
548 /* Allocate response callback data */
550 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
551 invocation, NULL, 0);
552 if (NULL == resp_cb_data) {
553 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
555 /* Send failure response */
556 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
561 /* Dispatch request */
562 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
563 ZBLIB_DRIVER_TYPE_SERVICE,
564 ZBLIB_SERVICE_OPS_PERMIT_JOIN,
566 on_service_permit_join_resp, resp_cb_data);
568 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
570 /* Free response callback data */
571 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
573 /* Send failure response */
574 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
582 static void on_service_leave_request_resp(ZigBeeServiceInterface *service_interface,
583 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
585 ZigbeeServiceInterfaceRespCbData_t *cb_data =
586 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
588 ZigbeeService *service_object;
589 GDBusMethodInvocation *invocation;
590 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
592 NOT_USED(service_interface);
593 NOT_USED(request_id);
595 if (NULL == resp_data || 0 == resp_data_len) {
596 Z_LOGE("resp_data is null");
601 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
602 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
604 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
605 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
607 zigbee_service_complete_leave_request(service_object, invocation, payload->result);
612 static gboolean on_service_leave_request(ZigbeeService *service_object,
613 GDBusMethodInvocation *invocation,
619 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
620 ZigbeeServiceLeaveRequest_t req;
621 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
623 GVariantIter *iter = NULL;
628 memset(&req, 0x0, sizeof(ZigbeeServiceLeaveRequest_t));
630 /* Update request structure */
631 g_variant_get(eui64, "a(y)", &iter);
632 while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
634 if (i >= ZIGBEE_EUI64_SIZE)
637 req.remove_child = remove_child;
640 Z_LOGD("IEEE Address = %X:%X:%X:%X:%X:%X:%X:%X",
641 req.eui64[0], req.eui64[1], req.eui64[2], req.eui64[3],
642 req.eui64[4], req.eui64[5], req.eui64[6], req.eui64[7]);
643 Z_LOGD("remove_child [%d]", remove_child);
644 Z_LOGD("rejoin [%d]", rejoin);
646 /* Allocate response callback data */
648 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
649 invocation, NULL, 0);
650 if (NULL == resp_cb_data) {
651 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
653 /* Send failure response */
654 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
659 /* Dispatch request */
660 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
661 ZBLIB_DRIVER_TYPE_SERVICE,
662 ZBLIB_SERVICE_OPS_LEAVE_REQUEST,
664 on_service_leave_request_resp, resp_cb_data);
666 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
668 /* Free response callback data */
669 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
671 /* Send failure response */
672 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
680 static void on_service_get_device_list_resp(ZigBeeServiceInterface *service_interface,
681 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
683 ZigbeeServiceInterfaceRespCbData_t *cb_data =
684 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
686 ZigbeeService *service_object;
687 GDBusMethodInvocation *invocation;
689 NOT_USED(service_interface);
690 NOT_USED(request_id);
692 if (NULL == resp_data || 0 == resp_data_len) {
693 Z_LOGE("resp_data is null");
698 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
699 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
701 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
702 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
704 /* TODO : zigbee_service_complete_get_device_list */
705 /* zigbee_service_complete_get_device_list(service_object, invocation, resp_data); */
710 static gboolean on_service_get_device_list(ZigbeeService *service_object,
711 GDBusMethodInvocation *invocation,
714 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
715 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
719 /* Allocate response callback data */
721 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
722 invocation, NULL, 0);
723 if (NULL == resp_cb_data) {
724 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
726 /* Send failure response */
727 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
732 /* Dispatch request */
733 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
734 ZBLIB_DRIVER_TYPE_SERVICE,
735 ZBLIB_SERVICE_OPS_GET_DEVICE_LIST,
737 on_service_get_device_list_resp, resp_cb_data);
739 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
741 /* Free response callback data */
742 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
744 /* Send failure response */
745 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
753 static void on_service_get_mac_resp(ZigBeeServiceInterface *service_interface,
754 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
756 ZigbeeServiceInterfaceRespCbData_t *cb_data =
757 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
759 ZigbeeService *service_object;
760 GDBusMethodInvocation *invocation;
761 ZigbeeServiceGetMacResp_t *payload =
762 (ZigbeeServiceGetMacResp_t*)resp_data;
764 GVariant *v_eui64 = NULL;
766 NOT_USED(service_interface);
767 NOT_USED(request_id);
769 if (NULL == resp_data || 0 == resp_data_len) {
770 Z_LOGE("resp_data is null");
775 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
776 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
778 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
779 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
781 v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
782 payload->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
784 zigbee_service_complete_get_mac(service_object, invocation, payload->result,
790 static gboolean on_service_get_mac(ZigbeeService *service_object,
791 GDBusMethodInvocation *invocation,
794 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
795 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
799 /* Allocate response callback data */
801 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
802 invocation, NULL, 0);
803 if (NULL == resp_cb_data) {
804 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
806 /* Send failure response */
807 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
812 /* Dispatch request */
813 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
814 ZBLIB_DRIVER_TYPE_SERVICE,
815 ZBLIB_SERVICE_OPS_GET_MAC,
817 on_service_get_mac_resp, resp_cb_data);
819 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
821 /* Free response callback data */
822 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
824 /* Send failure response */
825 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
833 static void on_service_get_device_info_resp(ZigBeeServiceInterface *service_interface,
834 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
836 ZigbeeServiceInterfaceRespCbData_t *cb_data =
837 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
839 ZigbeeService *service_object;
840 GDBusMethodInvocation *invocation;
841 ZigbeeServiceGetDeviceInfoResp_t *payload =
842 (ZigbeeServiceGetDeviceInfoResp_t*)resp_data;
844 GVariant *variant = NULL;
845 GVariantBuilder* builder = NULL;
849 NOT_USED(service_interface);
850 NOT_USED(request_id);
852 if (NULL == resp_data || 0 == resp_data_len) {
853 Z_LOGE("resp_data is null");
858 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
859 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
861 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
862 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
864 builder = g_variant_builder_new(G_VARIANT_TYPE("a(qyayyay)"));
865 for (index = 0; index < payload->count; index++) {
866 ZigbeeServiceGetDeviceInfoDetailResp_t *device = &(payload->list[index]);
867 GVariantBuilder* mac_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
868 GVariantBuilder* endpoint_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
870 for (i = 0; i < ZIGBEE_EUI64_SIZE; i++)
871 g_variant_builder_add(mac_builder, "y", device->eui64[i]);
872 for (i = 0; i < device->endpoint_count; i++)
873 g_variant_builder_add(endpoint_builder, "y", device->endpoints[i]);
875 g_variant_builder_add(builder, "(qyayyay)",
876 device->node_id, device->node_type,
877 mac_builder, device->endpoint_count, endpoint_builder);
879 g_variant_builder_unref(mac_builder);
880 g_variant_builder_unref(endpoint_builder);
883 variant = g_variant_builder_end(builder);
884 zigbee_service_complete_get_device_info(service_object, invocation,
885 payload->result, variant);
890 static gboolean on_service_get_device_info(ZigbeeService *service_object,
891 GDBusMethodInvocation *invocation,
894 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
895 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
899 /* Allocate response callback data */
901 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
902 invocation, NULL, 0);
903 if (NULL == resp_cb_data) {
904 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
906 /* Send failure response */
907 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
912 /* Dispatch request */
913 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
914 ZBLIB_DRIVER_TYPE_SERVICE,
915 ZBLIB_SERVICE_OPS_GET_DEVICE_INFO,
917 on_service_get_device_info_resp, resp_cb_data);
919 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
921 /* Free response callback data */
922 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
924 /* Send failure response */
925 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
933 static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_interface,
934 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
936 ZigbeeServiceInterfaceRespCbData_t *cb_data =
937 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
939 ZigbeeService *service_object;
940 GDBusMethodInvocation *invocation;
941 ZigbeeServiceGetEndpointListResp_t *payload =
942 (ZigbeeServiceGetEndpointListResp_t*)resp_data;
943 GVariant *v_endpoints = NULL;
945 NOT_USED(service_interface);
946 NOT_USED(request_id);
948 if (NULL == resp_data || 0 == resp_data_len) {
949 Z_LOGE("resp_data is null");
954 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
955 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
957 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
958 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
960 v_endpoints = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
961 payload->endpoints, payload->endpoint_count, TRUE, NULL, NULL);
963 zigbee_service_complete_get_endpoint_list(service_object, invocation,
964 payload->result, v_endpoints);
969 static gboolean on_service_get_endpoint_list(ZigbeeService *service_object,
970 GDBusMethodInvocation *invocation,
974 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
975 ZigbeeServiceGetEndpointList_t req;
976 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
978 GVariantIter *iter = NULL;
983 memset(&req, 0x0, sizeof(ZigbeeServiceGetEndpointList_t));
985 /* Update request structure */
986 g_variant_get(eui64, "a(y)", &iter);
987 while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
989 if (i >= ZIGBEE_EUI64_SIZE)
993 /* Allocate response callback data */
995 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
996 invocation, NULL, 0);
997 if (NULL == resp_cb_data) {
998 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1000 /* Send failure response */
1001 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1006 /* Dispatch request */
1007 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1008 ZBLIB_DRIVER_TYPE_SERVICE,
1009 ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST,
1011 on_service_get_endpoint_list_resp, resp_cb_data);
1013 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1015 /* Free response callback data */
1016 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1018 /* Send failure response */
1019 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1027 static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_interface,
1028 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1030 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1031 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1033 ZigbeeService *service_object;
1034 GDBusMethodInvocation *invocation;
1035 ZigbeeServiceGetClusterListResp_t *payload =
1036 (ZigbeeServiceGetClusterListResp_t*)resp_data;
1037 GVariant *v_in_clusters = NULL;
1038 GVariant *v_out_clusters = NULL;
1040 NOT_USED(service_interface);
1041 NOT_USED(request_id);
1043 if (NULL == resp_data || 0 == resp_data_len) {
1044 Z_LOGE("resp_data is null");
1049 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1050 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
1052 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1053 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1055 v_in_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1056 payload->in_clusters, (payload->in_cluster_count * sizeof(unsigned short)),
1058 v_out_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1059 payload->out_clusters, (payload->out_cluster_count * sizeof(unsigned short)),
1062 zigbee_service_complete_get_cluster_list(service_object, invocation,
1063 payload->result, v_in_clusters, v_out_clusters);
1068 static gboolean on_service_get_cluster_list(ZigbeeService *service_object,
1069 GDBusMethodInvocation *invocation,
1074 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1075 ZigbeeServiceGetClusterList_t req;
1076 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1078 GVariantIter *iter = NULL;
1083 memset(&req, 0x0, sizeof(ZigbeeServiceGetClusterList_t));
1085 /* Update request structure */
1086 g_variant_get(eui64, "a(y)", &iter);
1087 while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
1089 if (i >= ZIGBEE_EUI64_SIZE)
1092 req.endpoint = endpoint;
1094 /* Allocate response callback data */
1096 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1097 invocation, NULL, 0);
1098 if (NULL == resp_cb_data) {
1099 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1101 /* Send failure response */
1102 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1107 /* Dispatch request */
1108 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1109 ZBLIB_DRIVER_TYPE_SERVICE,
1110 ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST,
1112 on_service_get_cluster_list_resp, resp_cb_data);
1114 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1116 /* Free response callback data */
1117 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1119 /* Send failure response */
1120 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1128 static void on_service_get_node_type_resp(ZigBeeServiceInterface *service_interface,
1129 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1131 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1132 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1134 ZigbeeService *service_object;
1135 GDBusMethodInvocation *invocation;
1136 ZigbeeServiceServiceNodeTypeResp_t *payload =
1137 (ZigbeeServiceServiceNodeTypeResp_t *)resp_data;
1139 NOT_USED(service_interface);
1140 NOT_USED(request_id);
1142 if (NULL == resp_data || 0 == resp_data_len) {
1143 Z_LOGE("resp_data is null");
1148 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1149 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
1151 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1152 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1154 zigbee_service_complete_get_node_type(service_object, invocation,
1155 payload->result, payload->node_type);
1160 static gboolean on_service_get_node_type(ZigbeeService *service_object,
1161 GDBusMethodInvocation *invocation,
1165 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1166 ZigbeeServiceGetNodeType_t req;
1167 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1169 GVariantIter *iter = NULL;
1174 memset(&req, 0x0, sizeof(ZigbeeServiceGetNodeType_t));
1176 /* Update request structure */
1177 g_variant_get(eui64, "a(y)", &iter);
1178 while (g_variant_iter_loop(iter, "(y)", req.eui64[i])) {
1180 if (i >= ZIGBEE_EUI64_SIZE)
1184 /* Allocate response callback data */
1186 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1187 invocation, NULL, 0);
1188 if (NULL == resp_cb_data) {
1189 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1191 /* Send failure response */
1192 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1197 /* Dispatch request */
1198 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1199 ZBLIB_DRIVER_TYPE_SERVICE,
1200 ZBLIB_SERVICE_OPS_GET_NODE_TYPE,
1202 on_service_get_node_type_resp, resp_cb_data);
1204 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1206 /* Free response callback data */
1207 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1209 /* Send failure response */
1210 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1218 static gboolean on_service_check_privilege(ZigbeeService *service_object,
1219 GDBusMethodInvocation *invocation,
1222 NOT_USED(user_data);
1224 zigbee_service_complete_check_privilege(service_object, invocation);
1229 void zigbee_service_dbus_interface_service_notification(ZigBeeServiceInterface *service_interface,
1230 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
1232 ZigbeeService *service_object;
1234 zblib_check_null_ret("service_interface", service_interface);
1236 if (NULL == noti_data || 0 == noti_data_len) {
1237 Z_LOGE("noti_data is NULL");
1241 service_object = _service_interface_ref_zigbee_service(service_interface);
1242 zblib_check_null_ret("service_object", service_object);
1244 NOT_USED(noti_cb_data);
1247 case ZBLIB_SERVICE_NOTI_FORM_NETWORK_DONE: {
1248 ZigbeeServiceServiceFormNetworkDone_t *panid_t =
1249 (ZigbeeServiceServiceFormNetworkDone_t*)noti_data;
1251 Z_LOGD("form_network_done : [0x%X]", panid_t->pan_id);
1253 zigbee_service_emit_form_network_done(service_object, panid_t->pan_id);
1256 case ZBLIB_SERVICE_NOTI_CHILD_JOINED: {
1257 ZigbeeServiceServiceChildJoined_t *child_t =
1258 (ZigbeeServiceServiceChildJoined_t*)noti_data;
1260 GVariant *v_eui64 = NULL;
1261 GVariant *v_endpoints = NULL;
1263 v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1264 child_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
1265 v_endpoints = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1266 child_t->endpoints, child_t->endpoint_count, TRUE, NULL, NULL);
1267 if (NULL == v_eui64 || NULL == v_endpoints) {
1268 Z_LOGE("Failed to create variant!");
1270 g_object_unref(v_eui64);
1272 g_object_unref(v_endpoints);
1274 zigbee_service_emit_child_joined(service_object,
1275 v_eui64, child_t->endpoint_count, v_endpoints, child_t->node_id);
1279 case ZBLIB_SERVICE_NOTI_CHILD_REJOINED: {
1280 ZigbeeServiceServiceChildRejoined_t *child_t =
1281 (ZigbeeServiceServiceChildRejoined_t*)noti_data;
1283 GVariant *v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1284 child_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
1285 if (NULL == v_eui64)
1286 Z_LOGE("Failed to create variant!");
1288 zigbee_service_emit_child_rejoined(service_object, v_eui64);
1291 case ZBLIB_SERVICE_NOTI_CHILD_LEFT: {
1292 ZigbeeServiceServiceChildLeft_t *child_left_t =
1293 (ZigbeeServiceServiceChildLeft_t*)noti_data;
1295 GVariant *v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1296 child_left_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
1297 if (NULL == v_eui64)
1298 Z_LOGE("Failed to create variant!");
1300 zigbee_service_emit_child_left(service_object,
1301 v_eui64, child_left_t->status);
1305 case ZBLIB_SERVICE_NOTI_LEAVE_NETWORK_DONE: {
1306 ZigbeeServiceServiceLeaveNetworkDone_t leave_net_t;
1307 memcpy(&leave_net_t, noti_data, noti_data_len);
1308 zigbee_service_emit_leave_network_done(service_object, leave_net_t.pan_id);
1312 Z_LOGE("Unexpected notification [%x]", noti_id);
1316 /* ZigbeeService should be dereferenced */
1317 g_object_unref(service_object);
1320 gboolean zigbee_service_dbus_interface_service_init(ZigBeeServiceInterface *service_interface,
1321 ZigbeeObjectSkeleton *zigbee_object)
1323 ZigbeeService *service_object;
1325 if (NULL == service_interface) {
1326 Z_LOGE("service_interface is NULL");
1330 service_object = zigbee_service_skeleton_new();
1331 zigbee_object_skeleton_set_service(zigbee_object, service_object);
1332 g_object_unref(service_object);
1334 Z_LOGI("service_object: [%p]", service_object);
1337 * Register signal handlers for 'service' interface
1339 g_signal_connect(service_object,
1340 "handle-zb-hw-reset",
1341 G_CALLBACK(on_service_zb_hw_reset), service_interface);
1343 g_signal_connect(service_object,
1344 "handle-form-network",
1345 G_CALLBACK(on_service_form_network), service_interface);
1347 g_signal_connect(service_object,
1348 "handle-coex-start",
1349 G_CALLBACK(on_service_coex_start), service_interface);
1351 g_signal_connect(service_object,
1353 G_CALLBACK(on_service_coex_stop), service_interface);
1355 g_signal_connect(service_object,
1356 "handle-leave-network",
1357 G_CALLBACK(on_service_leave_network), service_interface);
1359 g_signal_connect(service_object,
1360 "handle-get-network-info",
1361 G_CALLBACK(on_service_get_network_info), service_interface);
1363 g_signal_connect(service_object,
1364 "handle-permit-join",
1365 G_CALLBACK(on_service_permit_join), service_interface);
1367 g_signal_connect(service_object,
1368 "handle-leave-request",
1369 G_CALLBACK(on_service_leave_request), service_interface);
1371 g_signal_connect(service_object,
1372 "handle-get-device-list",
1373 G_CALLBACK(on_service_get_device_list), service_interface);
1375 g_signal_connect(service_object,
1377 G_CALLBACK(on_service_get_mac), service_interface);
1379 g_signal_connect(service_object,
1380 "handle-get-device-info",
1381 G_CALLBACK(on_service_get_device_info), service_interface);
1383 g_signal_connect(service_object,
1384 "handle-get-endpoint-list",
1385 G_CALLBACK(on_service_get_endpoint_list), service_interface);
1387 g_signal_connect(service_object,
1388 "handle-get-cluster-list",
1389 G_CALLBACK(on_service_get_cluster_list), service_interface);
1391 g_signal_connect(service_object,
1392 "handle-get-node-type",
1393 G_CALLBACK(on_service_get_node_type), service_interface);
1395 g_signal_connect(service_object,
1396 "handle-check-privilege",
1397 G_CALLBACK(on_service_check_privilege), service_interface);