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 /* To-To : 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]);
873 for (i = 0; i < device->endpoint_count; i++) {
874 g_variant_builder_add (endpoint_builder, "y", device->endpoints[i]);
877 g_variant_builder_add (builder, "(qyayyay)",
878 device->node_id, device->node_type,
879 mac_builder, device->endpoint_count, endpoint_builder);
881 g_variant_builder_unref (mac_builder);
882 g_variant_builder_unref (endpoint_builder);
885 variant = g_variant_builder_end(builder);
886 zigbee_service_complete_get_device_info(service_object, invocation,
887 payload->result, variant);
892 static gboolean on_service_get_device_info(ZigbeeService *service_object,
893 GDBusMethodInvocation *invocation,
896 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
897 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
901 /* Allocate response callback data */
903 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
904 invocation, NULL, 0);
905 if (NULL == resp_cb_data) {
906 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
908 /* Send failure response */
909 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
914 /* Dispatch request */
915 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
916 ZBLIB_DRIVER_TYPE_SERVICE,
917 ZBLIB_SERVICE_OPS_GET_DEVICE_INFO,
919 on_service_get_device_info_resp, resp_cb_data);
921 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
923 /* Free response callback data */
924 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
926 /* Send failure response */
927 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
935 static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_interface,
936 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
938 ZigbeeServiceInterfaceRespCbData_t *cb_data =
939 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
941 ZigbeeService *service_object;
942 GDBusMethodInvocation *invocation;
943 ZigbeeServiceGetEndpointListResp_t *payload =
944 (ZigbeeServiceGetEndpointListResp_t*)resp_data;
945 GVariant *v_endpoints = NULL;
947 NOT_USED(service_interface);
948 NOT_USED(request_id);
950 if (NULL == resp_data || 0 == resp_data_len) {
951 Z_LOGE("resp_data is null");
956 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
957 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
959 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
960 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
962 v_endpoints = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
963 payload->endpoints, payload->endpoint_count, TRUE, NULL, NULL);
965 zigbee_service_complete_get_endpoint_list(service_object, invocation,
966 payload->result, v_endpoints);
971 static gboolean on_service_get_endpoint_list(ZigbeeService *service_object,
972 GDBusMethodInvocation *invocation,
976 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
977 ZigbeeServiceGetEndpointList_t req;
978 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
980 GVariantIter *iter = NULL;
985 memset(&req, 0x0, sizeof(ZigbeeServiceGetEndpointList_t));
987 /* Update request structure */
988 g_variant_get(eui64, "a(y)", &iter);
989 while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
991 if (i >= ZIGBEE_EUI64_SIZE)
995 /* Allocate response callback data */
997 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
998 invocation, NULL, 0);
999 if (NULL == resp_cb_data) {
1000 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1002 /* Send failure response */
1003 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1008 /* Dispatch request */
1009 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1010 ZBLIB_DRIVER_TYPE_SERVICE,
1011 ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST,
1013 on_service_get_endpoint_list_resp, resp_cb_data);
1015 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1017 /* Free response callback data */
1018 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1020 /* Send failure response */
1021 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1029 static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_interface,
1030 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1032 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1033 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1035 ZigbeeService *service_object;
1036 GDBusMethodInvocation *invocation;
1037 ZigbeeServiceGetClusterListResp_t *payload =
1038 (ZigbeeServiceGetClusterListResp_t*)resp_data;
1039 GVariant *v_in_clusters = NULL;
1040 GVariant *v_out_clusters = NULL;
1042 NOT_USED(service_interface);
1043 NOT_USED(request_id);
1045 if (NULL == resp_data || 0 == resp_data_len) {
1046 Z_LOGE("resp_data is null");
1051 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1052 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
1054 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1055 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1057 v_in_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1058 payload->in_clusters, (payload->in_cluster_count * sizeof(unsigned short)),
1060 v_out_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
1061 payload->out_clusters, (payload->out_cluster_count * sizeof(unsigned short)),
1064 zigbee_service_complete_get_cluster_list(service_object, invocation,
1065 payload->result, v_in_clusters, v_out_clusters);
1070 static gboolean on_service_get_cluster_list(ZigbeeService *service_object,
1071 GDBusMethodInvocation *invocation,
1076 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1077 ZigbeeServiceGetClusterList_t req;
1078 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1080 GVariantIter *iter = NULL;
1085 memset(&req, 0x0, sizeof(ZigbeeServiceGetClusterList_t));
1087 /* Update request structure */
1088 g_variant_get(eui64, "a(y)", &iter);
1089 while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
1091 if (i >= ZIGBEE_EUI64_SIZE)
1094 req.endpoint = endpoint;
1096 /* Allocate response callback data */
1098 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1099 invocation, NULL, 0);
1100 if (NULL == resp_cb_data) {
1101 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1103 /* Send failure response */
1104 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1109 /* Dispatch request */
1110 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1111 ZBLIB_DRIVER_TYPE_SERVICE,
1112 ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST,
1114 on_service_get_cluster_list_resp, resp_cb_data);
1116 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1118 /* Free response callback data */
1119 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1121 /* Send failure response */
1122 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1130 static void on_service_get_node_type_resp(ZigBeeServiceInterface *service_interface,
1131 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
1133 ZigbeeServiceInterfaceRespCbData_t *cb_data =
1134 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
1136 ZigbeeService *service_object;
1137 GDBusMethodInvocation *invocation;
1138 ZigbeeServiceServiceNodeTypeResp_t *payload =
1139 (ZigbeeServiceServiceNodeTypeResp_t *)resp_data;
1141 NOT_USED(service_interface);
1142 NOT_USED(request_id);
1144 if (NULL == resp_data || 0 == resp_data_len) {
1145 Z_LOGE("resp_data is null");
1150 service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
1151 zblib_check_null_free_and_ret("service_object", service_object, cb_data);
1153 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
1154 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
1156 zigbee_service_complete_get_node_type(service_object, invocation,
1157 payload->result, payload->node_type);
1162 static gboolean on_service_get_node_type(ZigbeeService *service_object,
1163 GDBusMethodInvocation *invocation,
1167 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
1168 ZigbeeServiceGetNodeType_t req;
1169 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
1171 GVariantIter *iter = NULL;
1176 memset(&req, 0x0, sizeof(ZigbeeServiceGetNodeType_t));
1178 /* Update request structure */
1179 g_variant_get(eui64, "a(y)", &iter);
1180 while (g_variant_iter_loop(iter, "(y)", req.eui64[i])) {
1182 if (i >= ZIGBEE_EUI64_SIZE)
1186 /* Allocate response callback data */
1188 zigbee_service_dbus_interface_create_resp_cb_data(service_object,
1189 invocation, NULL, 0);
1190 if (NULL == resp_cb_data) {
1191 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1193 /* Send failure response */
1194 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1199 /* Dispatch request */
1200 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1201 ZBLIB_DRIVER_TYPE_SERVICE,
1202 ZBLIB_SERVICE_OPS_GET_NODE_TYPE,
1204 on_service_get_node_type_resp, resp_cb_data);
1206 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1208 /* Free response callback data */
1209 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1211 /* Send failure response */
1212 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1220 void zigbee_service_dbus_interface_service_notification(ZigBeeServiceInterface *service_interface,
1221 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
1223 ZigbeeService *service_object;
1225 zblib_check_null_ret("service_interface", service_interface);
1227 if (NULL == noti_data || 0 == noti_data_len) {
1228 Z_LOGE("noti_data is NULL");
1232 service_object = _service_interface_ref_zigbee_service(service_interface);
1233 zblib_check_null_ret("service_object", service_object);
1235 NOT_USED(noti_cb_data);
1238 case ZBLIB_SERVICE_NOTI_FORM_NETWORK_DONE: {
1239 ZigbeeServiceServiceFormNetworkDone_t *panid_t =
1240 (ZigbeeServiceServiceFormNetworkDone_t*)noti_data;
1242 Z_LOGD("form_network_done : [0x%X]", panid_t->pan_id);
1244 zigbee_service_emit_form_network_done(service_object, panid_t->pan_id);
1247 case ZBLIB_SERVICE_NOTI_CHILD_JOINED: {
1248 ZigbeeServiceServiceChildJoined_t *child_t =
1249 (ZigbeeServiceServiceChildJoined_t*)noti_data;
1251 GVariant *v_eui64 = NULL;
1252 GVariant *v_endpoints = NULL;
1254 v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1255 child_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
1256 v_endpoints = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1257 child_t->endpoints, child_t->endpoint_count, TRUE, NULL, NULL);
1258 if (NULL == v_eui64 || NULL == v_endpoints) {
1259 Z_LOGE("Failed to create variant!");
1261 g_object_unref(v_eui64);
1263 g_object_unref(v_endpoints);
1265 zigbee_service_emit_child_joined(service_object,
1266 v_eui64, child_t->endpoint_count, v_endpoints, child_t->node_id);
1270 case ZBLIB_SERVICE_NOTI_CHILD_REJOINED: {
1271 ZigbeeServiceServiceChildRejoined_t *child_t =
1272 (ZigbeeServiceServiceChildRejoined_t*)noti_data;
1274 GVariant *v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1275 child_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
1276 if (NULL == v_eui64) {
1277 Z_LOGE("Failed to create variant!");
1279 zigbee_service_emit_child_rejoined(service_object, v_eui64);
1283 case ZBLIB_SERVICE_NOTI_CHILD_LEFT: {
1284 ZigbeeServiceServiceChildLeft_t *child_left_t =
1285 (ZigbeeServiceServiceChildLeft_t*)noti_data;
1287 GVariant *v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
1288 child_left_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
1289 if (NULL == v_eui64) {
1290 Z_LOGE("Failed to create variant!");
1292 zigbee_service_emit_child_left(service_object,
1293 v_eui64, child_left_t->status);
1297 case ZBLIB_SERVICE_NOTI_LEAVE_NETWORK_DONE: {
1298 ZigbeeServiceServiceLeaveNetworkDone_t leave_net_t;
1299 memcpy(&leave_net_t, noti_data, noti_data_len);
1300 zigbee_service_emit_leave_network_done(service_object, leave_net_t.pan_id);
1304 Z_LOGE("Unexpected notification [%x]", noti_id);
1308 /* ZigbeeService should be dereferenced */
1309 g_object_unref(service_object);
1312 gboolean zigbee_service_dbus_interface_service_init(ZigBeeServiceInterface *service_interface,
1313 ZigbeeObjectSkeleton *zigbee_object)
1315 ZigbeeService *service_object;
1317 if (NULL == service_interface) {
1318 Z_LOGE("service_interface is NULL");
1322 service_object = zigbee_service_skeleton_new();
1323 zigbee_object_skeleton_set_service(zigbee_object, service_object);
1324 g_object_unref(service_object);
1326 Z_LOGI("service_object: [%p]", service_object);
1329 * Register signal handlers for 'service' interface
1331 g_signal_connect(service_object,
1332 "handle-zb-hw-reset",
1333 G_CALLBACK(on_service_zb_hw_reset), service_interface);
1335 g_signal_connect(service_object,
1336 "handle-form-network",
1337 G_CALLBACK(on_service_form_network), service_interface);
1339 g_signal_connect(service_object,
1340 "handle-coex-start",
1341 G_CALLBACK(on_service_coex_start), service_interface);
1343 g_signal_connect(service_object,
1345 G_CALLBACK(on_service_coex_stop), service_interface);
1347 g_signal_connect(service_object,
1348 "handle-leave-network",
1349 G_CALLBACK(on_service_leave_network), service_interface);
1351 g_signal_connect(service_object,
1352 "handle-get-network-info",
1353 G_CALLBACK(on_service_get_network_info), service_interface);
1355 g_signal_connect(service_object,
1356 "handle-permit-join",
1357 G_CALLBACK(on_service_permit_join), service_interface);
1359 g_signal_connect(service_object,
1360 "handle-leave-request",
1361 G_CALLBACK(on_service_leave_request), service_interface);
1363 g_signal_connect(service_object,
1364 "handle-get-device-list",
1365 G_CALLBACK(on_service_get_device_list), service_interface);
1367 g_signal_connect(service_object,
1369 G_CALLBACK(on_service_get_mac), service_interface);
1371 g_signal_connect(service_object,
1372 "handle-get-device-info",
1373 G_CALLBACK(on_service_get_device_info), service_interface);
1375 g_signal_connect(service_object,
1376 "handle-get-endpoint-list",
1377 G_CALLBACK(on_service_get_endpoint_list), service_interface);
1379 g_signal_connect(service_object,
1380 "handle-get-cluster-list",
1381 G_CALLBACK(on_service_get_cluster_list), service_interface);
1383 g_signal_connect(service_object,
1384 "handle-get-node-type",
1385 G_CALLBACK(on_service_get_node_type), service_interface);