Add new CAPIs and unittest to get onmesh prefixes 83/276683/1
authorhyunuk.tak <hyunuk.tak@samsung.com>
Fri, 17 Jun 2022 04:18:56 +0000 (13:18 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Thu, 23 Jun 2022 02:24:47 +0000 (11:24 +0900)
Change-Id: I9d2d4476926c5b7c16f761f22d26dffea4c41527
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
include/thread-dbus-handler.h
include/thread-private.h
include/thread-type.h
include/thread.h
src/thread-br.c
tests/unittest/mocks/thread-mock-dummy.cpp
tests/unittest/thread-unittest-br.cpp

index 28b6a25..53ba5c7 100644 (file)
@@ -74,7 +74,7 @@ extern "C" {
 #define THREAD_DBUS_PROPERTY_EXTERNAL_ROUTES "ExternalRoutes"
 #define THREAD_DBUS_PROPERTY_ACTIVE_DATASET_TLVS "ActiveDatasetTlvs"
 #define THREAD_DBUS_PROPERTY_RADIO_REGION "RadioRegion"
-
+#define THREAD_DBUS_PROPERTY_ON_MESH_PREFIXES "OnMeshPrefixes"
 
 typedef void (*thread_async_request_cb)(gboolean res, const char *method, GVariant *val, void *user_data);
 
index ccc9062..8017556 100755 (executable)
@@ -268,14 +268,17 @@ typedef struct {
  */
 typedef struct {
        thread_ipv6_prefix_s prefix;
+       uint16_t rloc;
        uint8_t preference;
-       bool preferred;
-       bool slaac;
-       bool dhcp;
-       bool configure;
-       bool default_route;
-       bool on_mesh;
-       bool stable;
+       bool is_preferred;
+       bool is_slaac;
+       bool is_dhcp;
+       bool is_configure;
+       bool is_default_route;
+       bool is_on_mesh;
+       bool is_stable;
+       bool is_nd_dns;
+       bool is_dp;
 } thread_onmesh_prefix_info_s;
 
 /**
index bb0bbe8..5dd11f4 100755 (executable)
@@ -213,6 +213,16 @@ typedef void *thread_scan_param_h;
  */
 typedef void *thread_onmesh_prefix_info_h;
 
+/**
+ * @ingroup CAPI_NETWORK_THREAD_MODULE
+ * @since_tizen 7.0
+ *
+ * @see thread_br_get_onmesh_prefixes()
+ *
+ */
+typedef bool (*thread_onmesh_prefix_foreach_cb) (int total,
+       thread_onmesh_prefix_info_h onmesh_prefix, void *user_data);
+
 #ifdef __cplusplus
 }
 #endif
index 1da04a3..d56eea3 100644 (file)
@@ -728,7 +728,7 @@ int thread_onmesh_prefix_get_preference(thread_onmesh_prefix_info_h onmesh_prefi
  * @see thread_onmesh_prefix_destroy()
  */
 int thread_onmesh_prefix_set_preferred(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool preferred);
+       bool is_preferred);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
@@ -747,7 +747,7 @@ int thread_onmesh_prefix_set_preferred(thread_onmesh_prefix_info_h onmesh_prefix
  * @see thread_onmesh_prefix_destroy()
  */
 int thread_onmesh_prefix_get_preferred(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *preferred);
+       bool *is_preferred);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
@@ -766,7 +766,7 @@ int thread_onmesh_prefix_get_preferred(thread_onmesh_prefix_info_h onmesh_prefix
  * @see thread_onmesh_prefix_destroy()
  */
 int thread_onmesh_prefix_set_slaac(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool slaac);
+       bool is_slaac);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
@@ -785,7 +785,7 @@ int thread_onmesh_prefix_set_slaac(thread_onmesh_prefix_info_h onmesh_prefix,
  * @see thread_onmesh_prefix_destroy()
  */
 int thread_onmesh_prefix_get_slaac(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *slaac);
+       bool *is_slaac);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
@@ -804,7 +804,7 @@ int thread_onmesh_prefix_get_slaac(thread_onmesh_prefix_info_h onmesh_prefix,
  * @see thread_onmesh_prefix_destroy()
  */
 int thread_onmesh_prefix_set_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool dhcp);
+       bool is_dhcp);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
@@ -823,7 +823,7 @@ int thread_onmesh_prefix_set_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
  * @see thread_onmesh_prefix_destroy()
  */
 int thread_onmesh_prefix_get_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *dhcp);
+       bool *is_dhcp);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
@@ -842,7 +842,7 @@ int thread_onmesh_prefix_get_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
  * @see thread_onmesh_prefix_destroy()
  */
 int thread_onmesh_prefix_set_configure(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool configure);
+       bool is_configure);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
@@ -861,11 +861,11 @@ int thread_onmesh_prefix_set_configure(thread_onmesh_prefix_info_h onmesh_prefix
  * @see thread_onmesh_prefix_destroy()
  */
 int thread_onmesh_prefix_get_configure(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *configure);
+       bool *is_configure);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
- * @brief Set default route to on-mesh prefix info
+ * @brief Get on mesh to on-mesh prefix info
  * @since_tizen 7.0
  *
  * @return 0 on success, otherwise a negative error value.
@@ -879,12 +879,12 @@ int thread_onmesh_prefix_get_configure(thread_onmesh_prefix_info_h onmesh_prefix
  * @see thread_onmesh_prefix_create()
  * @see thread_onmesh_prefix_destroy()
  */
-int thread_onmesh_prefix_set_default_route(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool default_route);
+int thread_onmesh_prefix_get_on_mesh(thread_onmesh_prefix_info_h onmesh_prefix,
+       bool *is_on_mesh);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
- * @brief Get on mesh to on-mesh prefix info
+ * @brief Set on mesh to on-mesh prefix info
  * @since_tizen 7.0
  *
  * @return 0 on success, otherwise a negative error value.
@@ -898,12 +898,12 @@ int thread_onmesh_prefix_set_default_route(thread_onmesh_prefix_info_h onmesh_pr
  * @see thread_onmesh_prefix_create()
  * @see thread_onmesh_prefix_destroy()
  */
-int thread_onmesh_prefix_get_on_mesh(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *on_mesh);
+int thread_onmesh_prefix_set_on_mesh(thread_onmesh_prefix_info_h onmesh_prefix,
+       bool is_on_mesh);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
- * @brief Set on mesh to on-mesh prefix info
+ * @brief Get stable to on-mesh prefix info
  * @since_tizen 7.0
  *
  * @return 0 on success, otherwise a negative error value.
@@ -917,12 +917,12 @@ int thread_onmesh_prefix_get_on_mesh(thread_onmesh_prefix_info_h onmesh_prefix,
  * @see thread_onmesh_prefix_create()
  * @see thread_onmesh_prefix_destroy()
  */
-int thread_onmesh_prefix_set_on_mesh(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool on_mesh);
+int thread_onmesh_prefix_get_stable(thread_onmesh_prefix_info_h onmesh_prefix,
+       bool *is_stable);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
- * @brief Get stable to on-mesh prefix info
+ * @brief Set stable to on-mesh prefix info
  * @since_tizen 7.0
  *
  * @return 0 on success, otherwise a negative error value.
@@ -936,12 +936,12 @@ int thread_onmesh_prefix_set_on_mesh(thread_onmesh_prefix_info_h onmesh_prefix,
  * @see thread_onmesh_prefix_create()
  * @see thread_onmesh_prefix_destroy()
  */
-int thread_onmesh_prefix_get_stable(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *stable);
+int thread_onmesh_prefix_set_stable(thread_onmesh_prefix_info_h onmesh_prefix,
+       bool is_stable);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
- * @brief Set stable to on-mesh prefix info
+ * @brief Get default route to on-mesh prefix info
  * @since_tizen 7.0
  *
  * @return 0 on success, otherwise a negative error value.
@@ -955,12 +955,12 @@ int thread_onmesh_prefix_get_stable(thread_onmesh_prefix_info_h onmesh_prefix,
  * @see thread_onmesh_prefix_create()
  * @see thread_onmesh_prefix_destroy()
  */
-int thread_onmesh_prefix_set_stable(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool stable);
+int thread_onmesh_prefix_get_default_route(thread_onmesh_prefix_info_h onmesh_prefix,
+       bool *is_default_route);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
- * @brief Get default route to on-mesh prefix info
+ * @brief Set default route to on-mesh prefix info
  * @since_tizen 7.0
  *
  * @return 0 on success, otherwise a negative error value.
@@ -974,8 +974,27 @@ int thread_onmesh_prefix_set_stable(thread_onmesh_prefix_info_h onmesh_prefix,
  * @see thread_onmesh_prefix_create()
  * @see thread_onmesh_prefix_destroy()
  */
-int thread_onmesh_prefix_get_default_route(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *default_route);
+int thread_onmesh_prefix_set_default_route(thread_onmesh_prefix_info_h onmesh_prefix,
+       bool is_default_route);
+
+/**
+ * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
+ * @brief Get on-mesh prefixes to the network
+ * @since_tizen 7.0
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #THREAD_ERROR_NONE  Successful
+ * @retval #THREAD_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #THREAD_ERROR_OPERATION_FAILED  Operation failed
+ * @retval #THREAD_ERROR_NOT_SUPPORTED  Not supported
+ *
+ * @pre thread API must be initialized with thread_initialize().
+ *
+ * @see thread_add_onmesh_prefix()
+ * @see thread_remove_onmesh_prefix()
+ */
+int thread_br_get_onmesh_prefixes(thread_instance_h instance,
+       thread_onmesh_prefix_foreach_cb callback, void *user_data);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
index 6d5ac3a..ecc0fa1 100644 (file)
@@ -87,6 +87,98 @@ thread_onmesh_prefix_info_s* _create_new_onmesh_prefix(void)
        return new_onmesh_prefix;
 }
 
+static int __thread_br_get_onmesh_prefix_cb(GVariant *val,
+                       thread_onmesh_prefix_foreach_cb callback,
+                       thread_instance_s* instance, void *user_data)
+{
+       FUNC_ENTRY;
+       THREAD_VALIDATE_INPUT_PARAMETER(callback);
+       THREAD_VALIDATE_INPUT_PARAMETER(instance);
+
+       GVariantIter iter;
+       uint8_t *prefix_address = NULL;
+       uint8_t prefix_len = 0;
+       uint16_t rloc = 0;
+       uint8_t preference = 0;
+       bool is_preferred = FALSE;
+       bool is_slaac = FALSE;
+       bool is_dhcp = FALSE;
+       bool is_configure = FALSE;
+       bool is_default_route = FALSE;
+       bool is_on_mesh = FALSE;
+       bool is_stable = FALSE;
+       bool is_nd_dns = FALSE;
+       bool is_dp = FALSE;
+       int count = 0;
+       thread_instance_s *current_instance = instance;
+
+       THREAD_DBG("Process callback for get onmesh prefix info");
+       g_variant_iter_init(&iter, val);
+
+       while (g_variant_iter_next(&iter, "((ayy)qybbbbbbbbb)",
+                       &prefix_address, &prefix_len, &rloc, &preference,
+                       &is_preferred, &is_slaac, &is_dhcp, &is_configure,
+                       &is_default_route, &is_on_mesh, &is_stable,
+                       &is_nd_dns, &is_dp)) {
+
+               thread_onmesh_prefix_info_s *onmesh_prefix_info =
+                                               _create_new_onmesh_prefix();
+               if (!onmesh_prefix_info)
+                       break;
+
+               THREAD_DBG("Got the onmesh prefix...");
+
+               THREAD_DBG("prefix_address: %02x%02x:%02x%02x:%02x%02x:%02x%02x",
+                       prefix_address[0], prefix_address[1], prefix_address[2],
+                       prefix_address[3], prefix_address[4], prefix_address[5],
+                       prefix_address[6], prefix_address[7]);
+
+               THREAD_DBG("prefix_len: %u", prefix_len);
+               THREAD_DBG("rloc: %u", rloc);
+               THREAD_DBG("preference: %u", preference);
+               THREAD_DBG("preferred: %s", is_preferred ? "TRUE" : "FALSE");
+               THREAD_DBG("slaac: %s", is_slaac ? "TRUE" : "FALSE");
+               THREAD_DBG("dhcp: %s", is_dhcp ? "TRUE" : "FALSE");
+               THREAD_DBG("configure: %s", is_configure ? "TRUE" : "FALSE");
+               THREAD_DBG("default_route: %s", is_default_route ? "TRUE" : "FALSE");
+               THREAD_DBG("on_mesh: %s", is_on_mesh ? "TRUE" : "FALSE");
+               THREAD_DBG("stable: %s", is_stable ? "TRUE" : "FALSE");
+               THREAD_DBG("nd_dns: %s", is_nd_dns ? "TRUE" : "FALSE");
+               THREAD_DBG("dp: %s", is_dp ? "TRUE" : "FALSE");
+
+               memcpy((onmesh_prefix_info->prefix).ipv6.fields.m8, prefix_address,
+                                       THREAD_IPV6_PREFIX_SIZE*sizeof(uint8_t));
+               (onmesh_prefix_info->prefix).length = prefix_len;
+               onmesh_prefix_info->preference = preference;
+               onmesh_prefix_info->is_preferred = is_preferred;
+               onmesh_prefix_info->is_slaac = is_slaac;
+               onmesh_prefix_info->is_dhcp = is_dhcp;
+               onmesh_prefix_info->is_configure = is_configure;
+               onmesh_prefix_info->is_default_route = is_default_route;
+               onmesh_prefix_info->is_on_mesh = is_on_mesh;
+               onmesh_prefix_info->is_stable = is_stable;
+               onmesh_prefix_info->is_nd_dns = is_nd_dns;
+               onmesh_prefix_info->is_dp = is_dp;
+
+               current_instance->onmesh_prefix_list = g_slist_append(
+                                               current_instance->onmesh_prefix_list,
+                                               onmesh_prefix_info);
+
+               if (callback)
+                       (callback)(++count, (thread_onmesh_prefix_info_h)onmesh_prefix_info,
+                                                               user_data);
+
+               current_instance->onmesh_prefix_list = g_slist_remove(
+                                               current_instance->onmesh_prefix_list,
+                                               onmesh_prefix_info);
+               g_free(onmesh_prefix_info);
+       }
+       THREAD_DBG("Exiting __thread_br_get_onmesh_prefix_cb ...");
+
+       FUNC_EXIT;
+       return THREAD_ERROR_NONE;
+}
+
 static int __thread_br_get_external_route_cb(GVariant *val,
                        thread_external_route_foreach_cb callback,
                        thread_instance_s* instance, void *user_data)
@@ -567,7 +659,7 @@ int thread_onmesh_prefix_get_preference(thread_onmesh_prefix_info_h onmesh_prefi
 }
 
 int thread_onmesh_prefix_set_preferred(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool preferred)
+       bool is_preferred)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -576,14 +668,14 @@ int thread_onmesh_prefix_set_preferred(thread_onmesh_prefix_info_h onmesh_prefix
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       onmesh_prefix_info->preferred = preferred;
+       onmesh_prefix_info->is_preferred = is_preferred;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_get_preferred(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *preferred)
+       bool *is_preferred)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -592,14 +684,14 @@ int thread_onmesh_prefix_get_preferred(thread_onmesh_prefix_info_h onmesh_prefix
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       *preferred = onmesh_prefix_info->preferred;
+       *is_preferred = onmesh_prefix_info->is_preferred;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_set_slaac(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool slaac)
+       bool is_slaac)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -608,14 +700,14 @@ int thread_onmesh_prefix_set_slaac(thread_onmesh_prefix_info_h onmesh_prefix,
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       onmesh_prefix_info->slaac = slaac;
+       onmesh_prefix_info->is_slaac = is_slaac;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_get_slaac(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *slaac)
+       bool *is_slaac)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -624,14 +716,14 @@ int thread_onmesh_prefix_get_slaac(thread_onmesh_prefix_info_h onmesh_prefix,
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       *slaac = onmesh_prefix_info->slaac;
+       *is_slaac = onmesh_prefix_info->is_slaac;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_set_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool dhcp)
+       bool is_dhcp)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -640,14 +732,14 @@ int thread_onmesh_prefix_set_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       onmesh_prefix_info->dhcp = dhcp;
+       onmesh_prefix_info->is_dhcp = is_dhcp;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_get_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *dhcp)
+       bool *is_dhcp)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -656,14 +748,14 @@ int thread_onmesh_prefix_get_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       *dhcp = onmesh_prefix_info->dhcp;
+       *is_dhcp = onmesh_prefix_info->is_dhcp;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_set_configure(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool configure)
+       bool is_configure)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -672,14 +764,14 @@ int thread_onmesh_prefix_set_configure(thread_onmesh_prefix_info_h onmesh_prefix
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       onmesh_prefix_info->configure = configure;
+       onmesh_prefix_info->is_configure = is_configure;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_get_configure(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *configure)
+       bool *is_configure)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -688,14 +780,14 @@ int thread_onmesh_prefix_get_configure(thread_onmesh_prefix_info_h onmesh_prefix
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       *configure = onmesh_prefix_info->configure;
+       *is_configure = onmesh_prefix_info->is_configure;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_set_default_route(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool default_route)
+       bool is_default_route)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -704,14 +796,14 @@ int thread_onmesh_prefix_set_default_route(thread_onmesh_prefix_info_h onmesh_pr
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       onmesh_prefix_info->default_route = default_route;
+       onmesh_prefix_info->is_default_route = is_default_route;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_get_default_route(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *default_route)
+       bool *is_default_route)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -720,14 +812,14 @@ int thread_onmesh_prefix_get_default_route(thread_onmesh_prefix_info_h onmesh_pr
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       *default_route = onmesh_prefix_info->default_route;
+       *is_default_route = onmesh_prefix_info->is_default_route;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_set_on_mesh(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool on_mesh)
+       bool is_on_mesh)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -736,14 +828,14 @@ int thread_onmesh_prefix_set_on_mesh(thread_onmesh_prefix_info_h onmesh_prefix,
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       onmesh_prefix_info->on_mesh = on_mesh;
+       onmesh_prefix_info->is_on_mesh = is_on_mesh;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_get_on_mesh(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *on_mesh)
+       bool *is_on_mesh)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -752,14 +844,14 @@ int thread_onmesh_prefix_get_on_mesh(thread_onmesh_prefix_info_h onmesh_prefix,
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       *on_mesh = onmesh_prefix_info->on_mesh;
+       *is_on_mesh = onmesh_prefix_info->is_on_mesh;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_set_stable(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool stable)
+       bool is_stable)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -768,14 +860,14 @@ int thread_onmesh_prefix_set_stable(thread_onmesh_prefix_info_h onmesh_prefix,
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       onmesh_prefix_info->stable = stable;
+       onmesh_prefix_info->is_stable = is_stable;
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
 }
 
 int thread_onmesh_prefix_get_stable(thread_onmesh_prefix_info_h onmesh_prefix,
-       bool *stable)
+       bool *is_stable)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
@@ -784,7 +876,36 @@ int thread_onmesh_prefix_get_stable(thread_onmesh_prefix_info_h onmesh_prefix,
 
        thread_onmesh_prefix_info_s *onmesh_prefix_info =
                                        (thread_onmesh_prefix_info_s *)onmesh_prefix;
-       *stable = onmesh_prefix_info->stable;
+       *is_stable = onmesh_prefix_info->is_stable;
+
+       FUNC_EXIT;
+       return THREAD_ERROR_NONE;
+}
+
+int thread_br_get_onmesh_prefixes(thread_instance_h instance,
+       thread_onmesh_prefix_foreach_cb callback, void *user_data)
+{
+       FUNC_ENTRY;
+       THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+       THREAD_CHECK_INIT_STATUS();
+       THREAD_VALIDATE_INPUT_PARAMETER(instance);
+       THREAD_VALIDATE_INPUT_PARAMETER(callback);
+
+       thread_instance_s *current_instance = instance;
+       retv_if(!current_instance->is_br_enabled, THREAD_ERROR_NOT_ENABLED);
+
+       int ret = THREAD_ERROR_NONE;
+       GVariant *out = NULL;
+
+       ret = _thread_dbus_get_property(
+               THREAD_DBUS_PROPERTY_ON_MESH_PREFIXES, &out);
+       retv_if(ret != THREAD_ERROR_NONE, ret);
+
+       __thread_br_get_onmesh_prefix_cb(out, callback,
+                                       current_instance, user_data);
+
+       g_variant_unref(out);
+       THREAD_DBG("Freed out...");
 
        FUNC_EXIT;
        return THREAD_ERROR_NONE;
@@ -821,17 +942,17 @@ int thread_br_add_onmesh_prefix(thread_instance_h instance,
        else if (onmesh_prefix_info->preference == 2)
                strncat(msg, " high ", 7);
 
-       if (onmesh_prefix_info->preferred)
+       if (onmesh_prefix_info->is_preferred)
                strncat(msg, "p", 2);
-       if (onmesh_prefix_info->slaac)
+       if (onmesh_prefix_info->is_slaac)
                strncat(msg, "a", 2);
-       if (onmesh_prefix_info->configure)
+       if (onmesh_prefix_info->is_configure)
                strncat(msg, "c", 2);
-       if (onmesh_prefix_info->default_route)
+       if (onmesh_prefix_info->is_default_route)
                strncat(msg, "r", 2);
-       if (onmesh_prefix_info->on_mesh)
+       if (onmesh_prefix_info->is_on_mesh)
                strncat(msg, "o", 2);
-       if (onmesh_prefix_info->stable)
+       if (onmesh_prefix_info->is_stable)
                strncat(msg, "s", 2);
 
        THREAD_DBG("DEBUG: BORDER ROUTER MESSAGE -> [%s]", msg);
index ee8fd98..c137154 100644 (file)
@@ -209,6 +209,49 @@ static GVariant *__property_get_external_routes()
        return g_variant_new("(v)", __make_external_routes_result());
 }
 
+static GVariant *__make_onmesh_prefixes_result()
+{
+       uint8_t prefixAddress[THREAD_IPV6_PREFIX_SIZE];
+       uint8_t prefixLen = THREAD_IPV6_PREFIX_SIZE;
+       uint16_t rloc = 0xb801;
+       uint8_t preference = 0;
+       bool is_preferred = FALSE;
+       bool is_slaac = FALSE;
+       bool is_dhcp = FALSE;
+       bool is_configure = FALSE;
+       bool is_default_route = FALSE;
+       bool is_on_mesh = FALSE;
+       bool is_stable = FALSE;
+       bool is_nd_dns = FALSE;
+       bool is_dp = FALSE;
+
+       GVariantBuilder *onmeshPrefixesBuilder =
+               g_variant_builder_new(G_VARIANT_TYPE("a((ayy)qybbbbbbbbb)"));
+
+       GVariantBuilder *prefixBuilder =
+               g_variant_builder_new(G_VARIANT_TYPE("ay"));
+       __make_ipv6_prefix(prefixAddress);
+       for (int i = 0; i < THREAD_IPV6_PREFIX_SIZE; ++i)
+               g_variant_builder_add(prefixBuilder, "y", prefixAddress[i]);
+
+       g_variant_builder_add(onmeshPrefixesBuilder, "((ayy)qybbbbbbbbb)",
+               prefixBuilder, prefixLen, rloc, preference, is_preferred, is_slaac,
+               is_dhcp, is_configure, is_default_route, is_on_mesh, is_stable,
+               is_nd_dns, is_dp);
+
+       GVariant *onmeshPrefixesResult = g_variant_new("a((ayy)qybbbbbbbbb)", onmeshPrefixesBuilder);
+
+       g_variant_builder_unref(prefixBuilder);
+       g_variant_builder_unref(onmeshPrefixesBuilder);
+
+       return onmeshPrefixesResult;
+}
+
+static GVariant *__property_get_onmesh_prefixes()
+{
+       return g_variant_new("(v)", __make_onmesh_prefixes_result());
+}
+
 struct {
        const gchar *interface_name;
        const gchar *signal_name;
@@ -320,6 +363,11 @@ struct {
                __property_get_external_routes,
        },
        {
+               "Get",
+               THREAD_DBUS_PROPERTY_ON_MESH_PREFIXES,
+               __property_get_onmesh_prefixes,
+       },
+       {
                NULL,
                NULL,
                NULL,
index 21514d1..c53251b 100644 (file)
@@ -53,49 +53,55 @@ public:
        thread_onmesh_prefix_info_h onmeshPrefix;
 
 public:
+       static bool GetOnmeshPrefixesCallback(int total,
+               thread_onmesh_prefix_info_h onmesh_prefix_info, void *user_data)
+       {
+               return true;
+       };
+
        static bool GetExternalRoutesCallback(int total,
                thread_route_info_h route_info, void *user_data)
-               {
-                       RouteInfo routeInfo = static_cast<RouteInfo>(GPOINTER_TO_UINT(user_data));
-
-                       switch (routeInfo) {
-                       case RouteInfo::kIpv6Prefix:
-                               {
-                                       uint8_t ipv6Prefix[THREAD_IPV6_ADDRESS_SIZE];
-                                       uint8_t ipv6PrefixLen;
-                                       EXPECT_EQ(THREAD_ERROR_NONE, thread_br_get_ipv6_prefix(route_info, ipv6Prefix, &ipv6PrefixLen));
-                               }
-                               break;
-                       case RouteInfo::kRloc16:
-                               {
-                                       uint16_t rloc16;
-                                       EXPECT_EQ(THREAD_ERROR_NONE, thread_br_get_rloc16(route_info, &rloc16));
-                               }
-                               break;
-                       case RouteInfo::kPreference:
-                               {
-                                       int8_t preference;
-                                       EXPECT_EQ(THREAD_ERROR_NONE, thread_br_get_preference(route_info, &preference));
-                               }
-                               break;
-                       case RouteInfo::kStable:
-                               {
-                                       bool isStable;
-                                       EXPECT_EQ(THREAD_ERROR_NONE, thread_br_check_stable(route_info, &isStable));
-                               }
-                               break;
-                       case RouteInfo::kDeviceNexthop:
-                               {
-                                       bool isDeviceNexthop;
-                                       EXPECT_EQ(THREAD_ERROR_NONE, thread_br_check_device_nexthop(route_info, &isDeviceNexthop));
-                               }
-                               break;
-                       default:
-                               break;
+       {
+               RouteInfo routeInfo = static_cast<RouteInfo>(GPOINTER_TO_UINT(user_data));
+
+               switch (routeInfo) {
+               case RouteInfo::kIpv6Prefix:
+                       {
+                               uint8_t ipv6Prefix[THREAD_IPV6_ADDRESS_SIZE];
+                               uint8_t ipv6PrefixLen;
+                               EXPECT_EQ(THREAD_ERROR_NONE, thread_br_get_ipv6_prefix(route_info, ipv6Prefix, &ipv6PrefixLen));
+                       }
+                       break;
+               case RouteInfo::kRloc16:
+                       {
+                               uint16_t rloc16;
+                               EXPECT_EQ(THREAD_ERROR_NONE, thread_br_get_rloc16(route_info, &rloc16));
+                       }
+                       break;
+               case RouteInfo::kPreference:
+                       {
+                               int8_t preference;
+                               EXPECT_EQ(THREAD_ERROR_NONE, thread_br_get_preference(route_info, &preference));
+                       }
+                       break;
+               case RouteInfo::kStable:
+                       {
+                               bool isStable;
+                               EXPECT_EQ(THREAD_ERROR_NONE, thread_br_check_stable(route_info, &isStable));
                        }
+                       break;
+               case RouteInfo::kDeviceNexthop:
+                       {
+                               bool isDeviceNexthop;
+                               EXPECT_EQ(THREAD_ERROR_NONE, thread_br_check_device_nexthop(route_info, &isDeviceNexthop));
+                       }
+                       break;
+               default:
+                       break;
+               }
 
-                       return true;
-               };
+               return true;
+       };
 
 protected:
        void SetUp() override
@@ -553,6 +559,38 @@ TEST_F(ThreadBRTest, BRAddOnmeshPrefixErrorNone)
                thread_br_add_onmesh_prefix(instance, onmeshPrefix));
 }
 
+TEST_F(ThreadBRTest, BRGetOnmeshPrefixesNotInitialized)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_deinitialize());
+       EXPECT_EQ(THREAD_ERROR_NOT_INITIALIZED,
+               thread_br_get_onmesh_prefixes(instance,
+                       GetOnmeshPrefixesCallback, nullptr));
+}
+
+TEST_F(ThreadBRTest, BRGetOnmeshPrefixesInvalidParameter)
+{
+       EXPECT_EQ(THREAD_ERROR_INVALID_PARAMETER,
+               thread_br_get_onmesh_prefixes(instance,
+                       GetOnmeshPrefixesCallback, nullptr));
+}
+
+TEST_F(ThreadBRTest, BRGetOnmeshPrefixesNotEnabled)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
+       EXPECT_EQ(THREAD_ERROR_NOT_ENABLED,
+               thread_br_get_onmesh_prefixes(instance,
+                       GetOnmeshPrefixesCallback, nullptr));
+}
+
+TEST_F(ThreadBRTest, BRGetOnmeshPrefixesErrorNone)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_br_enable(instance));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_br_get_onmesh_prefixes(instance,
+                       GetOnmeshPrefixesCallback, nullptr));
+}
+
 TEST_F(ThreadBRTest, BRRemoveOnmeshPrefixNotInitialized)
 {
        EXPECT_EQ(THREAD_ERROR_NONE, thread_deinitialize());