2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include <uwb-private.h>
26 #include <uwb-gdbus.h>
30 #define UWB_DBUS_SERVICE "org.tizen.uwb" /**< For uwb dbus */
31 #define UWB_DBUS_MANAGER_PATH "/org/tizen/uwb/manager" /**< For manager dbus */
34 static struct _uwb_ctx {
35 Manager *manager_proxy;
36 uwb_message_received_cb message_received_cb;
37 void *message_received_user_data;
38 uwb_position_changed_cb position_changed_cb;
39 void *position_changed_user_data;
40 uwb_get_network_finished_cb get_network_finished_cb;
41 uwb_network_foreach_remote_node_cb foreach_remote_node_cb;
45 static inline void __handle_error(GError *error, int *ret)
50 if (NULL == g_strrstr(error->message, "org.tizen.uwb.Error")) {
51 if (NULL != g_strrstr(error->message, ".AccessDenied")) {
52 _DBG("Client doesn't have nmdaemon privilege");
53 *ret = UWB_ERROR_PERMISSION_DENIED;
56 *ret = UWB_ERROR_OPERATION_FAILED;
59 if (NULL != g_strrstr(error->message, ".NotPermitted")) {
60 _DBG("Client doesn't have uwb daemon privilege");
61 *ret = UWB_ERROR_PERMISSION_DENIED;
62 } else if (NULL != g_strrstr(error->message, ".InvalidParameter")) {
63 _DBG("Invalid Parameter");
64 *ret = UWB_ERROR_INVALID_PARAMETER;
65 } else if (NULL != g_strrstr(error->message, ".OutOfMemory")) {
66 _DBG("Out of memory");
67 *ret = UWB_ERROR_OUT_OF_MEMORY;
69 _DBG("Operation Failed");
70 *ret = UWB_ERROR_OPERATION_FAILED;
76 static void __message_received(GObject *source_object,
77 guint16 node_id, GVariant *message, gint message_length)
80 unsigned char element;
81 unsigned char *buf = NULL;
84 buf = (unsigned char *)malloc(sizeof(unsigned char) * size + 1);
90 g_variant_get(message, "a(y)", &iter);
91 size = g_variant_iter_n_children(iter);
93 for (int i = 0; g_variant_iter_loop(iter, "(y)", &element); i++)
99 g_variant_iter_free(iter);
101 if (uwb_ctx.message_received_cb != NULL) {
102 uwb_ctx.message_received_cb(node_id, buf, message_length,
103 uwb_ctx.message_received_user_data);
109 static void __position_changed(GObject *source_object,
110 guint16 node_id, gint x, gint y, gint z)
112 if (uwb_ctx.position_changed_cb != NULL)
113 uwb_ctx.position_changed_cb(node_id, x, y, z, uwb_ctx.position_changed_user_data);
117 static int manager_proxy_init(void)
119 GError *error = NULL;
121 uwb_ctx.manager_proxy = manager_proxy_new_for_bus_sync(
123 G_DBUS_PROXY_FLAGS_NONE,
125 UWB_DBUS_MANAGER_PATH,
128 if (NULL == uwb_ctx.manager_proxy) {
129 /* LCOV_EXCL_START */
131 _ERR("Failed to connect to the D-BUS daemon [%s]", error->message);
134 return UWB_ERROR_IO_ERROR;
138 g_signal_connect(uwb_ctx.manager_proxy, "message-received",
139 G_CALLBACK(__message_received), NULL);
141 g_signal_connect(uwb_ctx.manager_proxy, "position-changed",
142 G_CALLBACK(__position_changed), NULL);
144 return UWB_ERROR_NONE;
147 static void manager_proxy_deinit(void)
149 g_object_unref(uwb_ctx.manager_proxy);
150 uwb_ctx.manager_proxy = NULL;
153 EXPORT_API int uwb_initialize(void)
155 int ret = UWB_ERROR_NONE;
157 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
158 CHECK_ALREADY_INITIALIZED();
162 ret = manager_proxy_init();
169 EXPORT_API int uwb_deinitialize(void)
171 int ret = UWB_ERROR_NONE;
173 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
174 CHECK_NOT_INITIALIZED();
178 manager_proxy_deinit();
185 EXPORT_API int uwb_reset(void)
187 int ret = UWB_ERROR_NONE;
188 GError *error = NULL;
190 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
191 CHECK_NOT_INITIALIZED();
195 if (manager_call_reset_sync(uwb_ctx.manager_proxy, NULL, &error) == FALSE) {
196 /* LCOV_EXCL_START */
197 _ERR("manager_call_reset_sync failed : %s", error->message);
198 __handle_error(error, &ret);
207 EXPORT_API int uwb_factory_reset(void)
209 int ret = UWB_ERROR_NONE;
210 GError *error = NULL;
212 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
213 CHECK_NOT_INITIALIZED();
217 if (manager_call_factory_reset_sync(uwb_ctx.manager_proxy, NULL, &error) == FALSE) {
218 /* LCOV_EXCL_START */
219 _ERR("manager_call_factory_reset_sync failed : %s", error->message);
220 __handle_error(error, &ret);
229 EXPORT_API int uwb_set_message_received_cb(uwb_message_received_cb message_received_cb, void *user_data)
231 int ret = UWB_ERROR_NONE;
233 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
234 uwb_check_null_ret_error("message_received_cb", message_received_cb, UWB_ERROR_INVALID_PARAMETER);
238 uwb_ctx.message_received_cb = message_received_cb;
239 uwb_ctx.message_received_user_data = user_data;
246 EXPORT_API int uwb_set_position_changed_cb(uwb_position_changed_cb position_changed_cb, void *user_data)
248 int ret = UWB_ERROR_NONE;
250 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
251 uwb_check_null_ret_error("position_changed_cb", position_changed_cb, UWB_ERROR_INVALID_PARAMETER);
255 uwb_ctx.position_changed_cb = position_changed_cb;
256 uwb_ctx.position_changed_user_data = user_data;
263 EXPORT_API int uwb_unset_message_received_cb(void)
265 int ret = UWB_ERROR_NONE;
267 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
271 uwb_ctx.message_received_cb = NULL;
272 uwb_ctx.message_received_user_data = NULL;
279 EXPORT_API int uwb_unset_position_changed_cb(void)
281 int ret = UWB_ERROR_NONE;
283 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
287 uwb_ctx.position_changed_cb = NULL;
288 uwb_ctx.position_changed_user_data = NULL;
295 EXPORT_API int uwb_get_own_node(uwb_node_h *own_node)
297 int ret = UWB_ERROR_NONE;
298 GError *error = NULL;
299 GVariant *own_node_va = NULL;
300 uwb_node_s **_own_node = (uwb_node_s **)own_node;
302 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
303 CHECK_NOT_INITIALIZED();
307 uwb_check_null_ret_error("own_node", own_node, UWB_ERROR_INVALID_PARAMETER);
309 if (manager_call_get_own_node_sync(uwb_ctx.manager_proxy,
310 &own_node_va, NULL, &error) == FALSE) {
311 /* LCOV_EXCL_START */
312 __handle_error(error, &ret);
316 /* LCOV_EXCL_START */
317 if (ret == UWB_ERROR_NONE && own_node_va != NULL)
318 *_own_node = uwb_util_get_node_from_variant(own_node_va);
328 EXPORT_API int uwb_node_set_position(uwb_node_h node, int x, int y, int z)
330 int ret = UWB_ERROR_NONE;
331 GError *error = NULL;
333 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
334 CHECK_NOT_INITIALIZED();
338 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
340 if (manager_call_set_position_sync(uwb_ctx.manager_proxy,
341 ((uwb_node_s *)node)->node_id, x, y, z, NULL, &error) == FALSE) {
342 /* LCOV_EXCL_START */
343 _ERR("manager_call_set_position_sync failed : %s", error->message);
344 __handle_error(error, &ret);
353 static GVariant *__data_to_variant(const unsigned char *data, int length)
355 GVariantBuilder builder;
357 g_variant_builder_init(&builder, G_VARIANT_TYPE("a(y)"));
359 if (data && length > 0)
361 for(int i = 0; i < length; i++)
362 g_variant_builder_add(&builder, "(y)", *(data + i));
365 return g_variant_builder_end(&builder);
368 EXPORT_API int uwb_node_send_message(const unsigned char *message, int len)
370 int ret = UWB_ERROR_NONE;
371 GVariant *msg = NULL;
372 GError *error = NULL;
374 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
375 CHECK_NOT_INITIALIZED();
379 uwb_check_null_ret_error("message", message, UWB_ERROR_INVALID_PARAMETER);
380 cond_expr_ret(len <= 0, UWB_ERROR_INVALID_PARAMETER);
382 msg = __data_to_variant(message, len);
384 if (manager_call_send_message_sync(uwb_ctx.manager_proxy,
385 msg, len, NULL, &error) == FALSE) {
386 /* LCOV_EXCL_START */
387 _ERR("manager_call_send_message_sync failed : %s", error->message);
388 __handle_error(error, &ret);
397 EXPORT_API int uwb_node_send_message_to(uwb_node_h node, const unsigned char *message, int len)
399 int ret = UWB_ERROR_NONE;
400 GVariant *msg = NULL;
401 GError *error = NULL;
403 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
404 CHECK_NOT_INITIALIZED();
408 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
409 uwb_check_null_ret_error("message", message, UWB_ERROR_INVALID_PARAMETER);
410 cond_expr_ret(len <= 0, UWB_ERROR_INVALID_PARAMETER);
412 msg = __data_to_variant(message, len);
414 if (manager_call_send_message_to_sync(uwb_ctx.manager_proxy, ((uwb_node_s *)node)->node_id,
415 msg, len, NULL, &error) == FALSE) {
416 /* LCOV_EXCL_START */
417 _ERR("manager_call_send_message_to_sync failed : %s", error->message);
418 __handle_error(error, &ret);
427 static int __get_configurations(uwb_node_h node, const char *key,
428 const GVariantType *va_type, GVariant **va_out)
430 int ret = UWB_ERROR_NONE;
431 GError *error = NULL;
434 if (manager_call_get_configurations_sync(uwb_ctx.manager_proxy,
435 ((uwb_node_s *)node)->node_id, &va, NULL, &error) == FALSE) {
436 /* LCOV_EXCL_START */
437 _ERR("__get_configurations failed : %s", error->message);
438 __handle_error(error, &ret);
441 *va_out = g_variant_lookup_value(va, key, va_type);
447 EXPORT_API int uwb_node_get_configuration_int32(uwb_node_h node, const char *key, int32_t *value)
449 int ret = UWB_ERROR_NONE;
450 GVariant *value_va = NULL;
452 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
453 CHECK_NOT_INITIALIZED();
457 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
459 ret = __get_configurations(node, key, G_VARIANT_TYPE_INT32, &value_va);
461 /* LCOV_EXCL_START */
462 if (value_va != NULL)
463 *value = g_variant_get_int32(value_va);
473 EXPORT_API int uwb_node_get_configuration_int64(uwb_node_h node, const char *key, int64_t *value)
475 int ret = UWB_ERROR_NONE;
476 GVariant *value_va = NULL;
478 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
479 CHECK_NOT_INITIALIZED();
483 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
485 ret = __get_configurations(node, key, G_VARIANT_TYPE_INT64, &value_va);
487 /* LCOV_EXCL_START */
488 if (value_va != NULL)
489 *value = g_variant_get_int64(value_va);
499 EXPORT_API int uwb_node_get_configuration_string(uwb_node_h node, const char *key, char **value)
501 int ret = UWB_ERROR_NONE;
502 GVariant *value_va = NULL;
503 const char *value_str = NULL;
505 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
506 CHECK_NOT_INITIALIZED();
510 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
512 ret = __get_configurations(node, key, G_VARIANT_TYPE_STRING, &value_va);
514 if (value_va != NULL)
515 value_str = g_variant_get_string(value_va, NULL);
521 if (value_str && strlen(value_str) != 0)
522 *value = strdup(value_str);
526 static int __set_configuration(uwb_node_h node, GVariant *va)
528 int ret = UWB_ERROR_NONE;
529 GError *error = NULL;
531 if (manager_call_set_configurations_sync(uwb_ctx.manager_proxy, ((uwb_node_s *)node)->node_id,
532 va, NULL, &error) == FALSE) {
533 /* LCOV_EXCL_START */
534 _ERR("__set_configurations : %s", error->message);
535 __handle_error(error, &ret);
542 static GVariant *__build_configuration(const char *key, GVariant *value)
545 GVariantBuilder *builder;
547 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
548 g_variant_builder_add(builder, "{sv}", key, value);
549 va = g_variant_new("a{sv}", builder);
550 g_variant_builder_unref(builder);
555 EXPORT_API int uwb_node_set_configuration_int32(uwb_node_h node, const char *key, int32_t value)
557 int ret = UWB_ERROR_NONE;
558 GVariant *configuration = NULL;
560 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
561 CHECK_NOT_INITIALIZED();
565 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
566 uwb_check_null_ret_error("key", key, UWB_ERROR_INVALID_PARAMETER);
568 configuration = __build_configuration(key, g_variant_new_int32(value));
570 ret = __set_configuration(node, configuration);
577 EXPORT_API int uwb_node_set_configuration_int64(uwb_node_h node, const char *key, int64_t value)
579 int ret = UWB_ERROR_NONE;
580 GVariant *configuration = NULL;
582 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
583 CHECK_NOT_INITIALIZED();
587 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
588 uwb_check_null_ret_error("key", key, UWB_ERROR_INVALID_PARAMETER);
590 configuration = __build_configuration(key, g_variant_new_int64(value));
592 ret = __set_configuration(node, configuration);
599 EXPORT_API int uwb_node_set_configuration_string(uwb_node_h node, const char *key, const char *value)
601 int ret = UWB_ERROR_NONE;
602 GVariant *configuration = NULL;
604 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
605 CHECK_NOT_INITIALIZED();
609 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
610 uwb_check_null_ret_error("key", key, UWB_ERROR_INVALID_PARAMETER);
611 uwb_check_null_ret_error("value", value, UWB_ERROR_INVALID_PARAMETER);
613 configuration = __build_configuration(key, g_variant_new_string(value));
615 ret = __set_configuration(node, configuration);
622 EXPORT_API int uwb_node_clone(uwb_node_h src, uwb_node_h *dst)
624 int ret = UWB_ERROR_NONE;
626 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
630 uwb_check_null_ret_error("source", src, UWB_ERROR_INVALID_PARAMETER);
631 uwb_check_null_ret_error("target", dst, UWB_ERROR_INVALID_PARAMETER);
633 uwb_node_s *_src = (uwb_node_s *)src;
634 *dst = (uwb_node_s *)malloc(sizeof(uwb_node_s));
635 uwb_node_s *_dst = *dst;
637 _dst->node_id = _src->node_id;
638 _dst->pan_id = _src->pan_id;
639 _dst->is_remote = _src->is_remote;
640 _dst->distance = _src->distance;
650 EXPORT_API int uwb_node_destroy(uwb_node_h node)
652 int ret = UWB_ERROR_NONE;
654 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
658 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
667 EXPORT_API int uwb_node_get_distance(uwb_node_h node, uint64_t *distance)
669 int ret = UWB_ERROR_NONE;
671 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
675 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
676 uwb_check_null_ret_error("distance", distance, UWB_ERROR_INVALID_PARAMETER);
678 *distance = ((uwb_node_s *)node)->distance;
685 EXPORT_API int uwb_node_get_node_id(uwb_node_h node, uint64_t *node_id)
687 int ret = UWB_ERROR_NONE;
689 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
693 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
694 uwb_check_null_ret_error("node_id", node_id, UWB_ERROR_INVALID_PARAMETER);
696 *node_id = ((uwb_node_s *)node)->node_id;
703 EXPORT_API int uwb_node_get_pan_id(uwb_node_h node, uint64_t *pan_id)
705 int ret = UWB_ERROR_NONE;
707 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
711 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
712 uwb_check_null_ret_error("pan_id", pan_id, UWB_ERROR_INVALID_PARAMETER);
714 *pan_id = ((uwb_node_s *)node)->pan_id;
721 EXPORT_API int uwb_node_get_is_remote(uwb_node_h node, bool *is_remote)
723 int ret = UWB_ERROR_NONE;
725 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
729 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
730 uwb_check_null_ret_error("is_remote", is_remote, UWB_ERROR_INVALID_PARAMETER);
732 *is_remote = ((uwb_node_s *)node)->is_remote;
739 EXPORT_API int uwb_node_get_position(uwb_node_h node, int *x, int *y, int *z)
741 int ret = UWB_ERROR_NONE;
743 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
747 uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
748 uwb_check_null_ret_error("x", x, UWB_ERROR_INVALID_PARAMETER);
749 uwb_check_null_ret_error("y", y, UWB_ERROR_INVALID_PARAMETER);
750 uwb_check_null_ret_error("z", z, UWB_ERROR_INVALID_PARAMETER);
752 *x = ((uwb_node_s *)node)->x;
753 *y = ((uwb_node_s *)node)->y;
754 *z = ((uwb_node_s *)node)->z;
761 static void __get_network_cb(GObject *source_object, GAsyncResult *res, gpointer user_data)
763 int ret = UWB_ERROR_NONE;
765 GVariant *remote_node_list_va = NULL;
766 GError *error = NULL;
767 uwb_network_s *network_s;
769 if (manager_call_get_network_info_finish(
770 MANAGER(source_object),
772 &remote_node_list_va,
775 /* LCOV_EXCL_START */
776 _ERR("manager_call_get_network_info_finish failed : %s", error->message);
777 __handle_error(error, &ret);
779 if (uwb_ctx.get_network_finished_cb != NULL) {
780 uwb_ctx.get_network_finished_cb(ret, NULL, user_data);
787 /* create network handle */
788 network_s = (uwb_network_s *)malloc(sizeof(uwb_network_s));
790 if (ret == UWB_ERROR_NONE) {
791 GSList *remote_node_list = NULL;
792 network_s->pan_id = pan_id;
793 network_s->remote_node_count = g_variant_n_children(remote_node_list_va);
795 if (network_s->remote_node_count > 0) {
796 /* LCOV_EXCL_START */
797 GVariantIter *iter = NULL;
798 GVariant *nodes_va = NULL;
800 g_variant_get(remote_node_list_va, "aa{sv}", &iter);
801 while ((nodes_va = g_variant_iter_next_value(iter)) != NULL) {
804 node = uwb_util_get_node_from_variant(nodes_va);
805 node->is_remote = true;
807 _DBG("(%d, %d, %d)", node->x, node->y, node->z);
808 remote_node_list = g_slist_append(remote_node_list, node);
810 g_variant_iter_free(iter);
813 network_s->remote_node_list = remote_node_list;
815 g_variant_unref(remote_node_list_va);
818 if (uwb_ctx.get_network_finished_cb != NULL) {
819 uwb_ctx.get_network_finished_cb(ret, (uwb_network_h)network_s, user_data);
823 EXPORT_API int uwb_get_network(uwb_get_network_finished_cb finished_cb, void *user_data)
825 int ret = UWB_ERROR_NONE;
827 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
828 CHECK_NOT_INITIALIZED();
832 uwb_check_null_ret_error("finished_cb", finished_cb, UWB_ERROR_INVALID_PARAMETER);
834 uwb_ctx.get_network_finished_cb = finished_cb;
836 manager_call_get_network_info(uwb_ctx.manager_proxy, NULL, __get_network_cb, user_data);
843 /* LCOV_EXCL_START */
844 static gpointer __copy_node(gconstpointer src, gpointer data)
849 uwb_node_s *src_ptr = (uwb_node_s *)src;
850 uwb_node_s *dst_ptr = (uwb_node_s *)malloc(sizeof(uwb_node_s));
854 dst_ptr->node_id = src_ptr->node_id;
855 dst_ptr->pan_id = src_ptr->pan_id;
856 dst_ptr->is_remote = src_ptr->is_remote;
857 dst_ptr->distance = src_ptr->distance;
858 dst_ptr->x = src_ptr->x;
859 dst_ptr->y = src_ptr->y;
860 dst_ptr->z = src_ptr->z;
862 return (gpointer)dst_ptr;
866 EXPORT_API int uwb_network_clone(uwb_network_h source, uwb_network_h *target)
868 uwb_network_s *result_network = NULL;
869 uwb_network_s *src_network = (uwb_network_s *)source;
870 GSList *remote_node_list = NULL;
871 int ret = UWB_ERROR_NONE;
873 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
877 uwb_check_null_ret_error("source", source, UWB_ERROR_INVALID_PARAMETER);
879 result_network = (uwb_network_s *)malloc(sizeof(uwb_network_s));
880 if (result_network == NULL) {
881 /* LCOV_EXCL_START */
882 _ERR("malloc failed");
883 return UWB_ERROR_OPERATION_FAILED;
887 result_network->pan_id = src_network->pan_id;
888 result_network->remote_node_count = src_network->remote_node_count;
889 remote_node_list = src_network->remote_node_list;
890 result_network->remote_node_list = g_slist_copy_deep(remote_node_list,
896 *target = result_network;
900 EXPORT_API int uwb_network_destroy(uwb_network_h network)
902 int ret = UWB_ERROR_NONE;
904 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
908 uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
910 uwb_util_destroy_network(network);
917 EXPORT_API int uwb_network_get_pan_id(uwb_network_h network, uint64_t *pan_id)
919 int ret = UWB_ERROR_NONE;
921 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
925 uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
926 uwb_check_null_ret_error("pan_id", pan_id, UWB_ERROR_INVALID_PARAMETER);
928 *pan_id = ((uwb_network_s *)network)->pan_id;
935 EXPORT_API int uwb_network_get_remote_node_count(uwb_network_h network, int *remote_node_count)
937 int ret = UWB_ERROR_NONE;
939 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
943 uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
944 uwb_check_null_ret_error("remote_node_count", remote_node_count, UWB_ERROR_INVALID_PARAMETER);
946 *remote_node_count = ((uwb_network_s *)network)->remote_node_count;
953 /* LCOV_EXCL_START */
954 static void __foreach_node(gpointer data, gpointer user_data)
956 uwb_node_s *node = (uwb_node_s *)data;
957 _DBG("panid : 0x%X, nodeid : 0x%04"PRIX64", distance : %"PRId64"", node->pan_id, node->node_id, node->distance);
959 if (uwb_ctx.foreach_remote_node_cb != NULL)
960 uwb_ctx.foreach_remote_node_cb((uwb_node_h)node, user_data);
963 EXPORT_API int uwb_network_foreach_remote_node(uwb_network_h network,
964 uwb_network_foreach_remote_node_cb node_cb, void *user_data)
966 int ret = UWB_ERROR_NONE;
968 CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
972 uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
974 uwb_network_s *network_s = (uwb_network_s *)network;
975 if (network_s->remote_node_count == 0) {
976 _DBG("remote_node_count is 0");
980 uwb_ctx.foreach_remote_node_cb = node_cb;
981 g_slist_foreach(network_s->remote_node_list, __foreach_node, user_data);