Add new CAPIs and unittest to set/get ipv6 prefix for onmesh 73/276673/1
authorhyunuk.tak <hyunuk.tak@samsung.com>
Tue, 14 Jun 2022 07:43:18 +0000 (16:43 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Thu, 23 Jun 2022 02:22:41 +0000 (11:22 +0900)
Change-Id: Ibc0ffc494ef191be37312bbab5795090075d3e9c
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
include/thread.h
src/thread-br.c
tests/unittest/thread-unittest-br.cpp

index 7c6a811..7b0bee3 100644 (file)
@@ -637,6 +637,44 @@ int thread_onmesh_prefix_destroy(thread_instance_h instance,
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
+ * @brief Set ipv6 prefix to on-mesh prefix info
+ * @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_onmesh_prefix_create()
+ * @see thread_onmesh_prefix_destroy()
+ */
+int thread_onmesh_prefix_set_ipv6_prefix(thread_onmesh_prefix_info_h onmesh_prefix,
+       const uint8_t *ipv6_prefix, uint8_t ipv6_prefix_len);
+
+/**
+ * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
+ * @brief Get ipv6 prefix to on-mesh prefix info
+ * @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_onmesh_prefix_create()
+ * @see thread_onmesh_prefix_destroy()
+ */
+int thread_onmesh_prefix_get_ipv6_prefix(thread_onmesh_prefix_info_h onmesh_prefix,
+       uint8_t **ipv6_prefix, uint8_t *ipv6_prefix_len);
+
+/**
+ * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
  * @brief Add an on-mesh prefix to the network
  * @since_tizen 7.0
  *
index f587f7b..94a0ce1 100644 (file)
@@ -456,9 +456,7 @@ int thread_onmesh_prefix_create(thread_instance_h instance,
        THREAD_VALIDATE_INPUT_PARAMETER(onmesh_prefix);
 
        thread_instance_s *current_instance = instance;
-       retv_if(!current_instance->is_br_enabled, THREAD_ERROR_NOT_ENABLED);
-
-       thread_onmesh_prefix_info_s* new_onmesh_prefix =
+       thread_onmesh_prefix_info_s *new_onmesh_prefix =
                                        _create_new_onmesh_prefix();
        retv_if (!new_onmesh_prefix, THREAD_ERROR_OUT_OF_MEMORY);
 
@@ -482,8 +480,6 @@ int thread_onmesh_prefix_destroy(thread_instance_h instance,
        THREAD_VALIDATE_INPUT_PARAMETER(onmesh_prefix);
 
        thread_instance_s *current_instance = instance;
-       retv_if(!current_instance->is_br_enabled, THREAD_ERROR_NOT_ENABLED);
-
        if (g_slist_find(current_instance->onmesh_prefix_list, onmesh_prefix)) {
                current_instance->onmesh_prefix_list = g_slist_remove(
                                        current_instance->onmesh_prefix_list,
@@ -495,6 +491,49 @@ int thread_onmesh_prefix_destroy(thread_instance_h instance,
        return THREAD_ERROR_NONE;
 }
 
+int thread_onmesh_prefix_set_ipv6_prefix(thread_onmesh_prefix_info_h onmesh_prefix,
+       const uint8_t *ipv6_prefix, uint8_t ipv6_prefix_len)
+{
+       FUNC_ENTRY;
+       THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+       THREAD_CHECK_INIT_STATUS();
+       THREAD_VALIDATE_INPUT_PARAMETER(onmesh_prefix);
+       THREAD_VALIDATE_INPUT_PARAMETER(ipv6_prefix);
+
+       retv_if(ipv6_prefix_len > THREAD_IPV6_PREFIX_LEN,
+                                       THREAD_ERROR_INVALID_PARAMETER);
+
+       thread_onmesh_prefix_info_s *onmesh_prefix_info =
+                                       (thread_onmesh_prefix_info_s *)onmesh_prefix;
+       memcpy((onmesh_prefix_info->prefix).ipv6.fields.m8, ipv6_prefix,
+                               THREAD_IPV6_PREFIX_SIZE*sizeof(uint8_t));
+       (onmesh_prefix_info->prefix).length = ipv6_prefix_len;
+
+       FUNC_EXIT;
+       return THREAD_ERROR_NONE;
+}
+
+int thread_onmesh_prefix_get_ipv6_prefix(thread_onmesh_prefix_info_h onmesh_prefix,
+       uint8_t **ipv6_prefix, uint8_t *ipv6_prefix_len)
+{
+       FUNC_ENTRY;
+       THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+       THREAD_CHECK_INIT_STATUS();
+       THREAD_VALIDATE_INPUT_PARAMETER(onmesh_prefix);
+
+       thread_onmesh_prefix_info_s *onmesh_prefix_info =
+                                       (thread_onmesh_prefix_info_s *)onmesh_prefix;
+       *ipv6_prefix = g_malloc0(THREAD_IPV6_PREFIX_SIZE*sizeof(uint8_t));
+       retv_if (!ipv6_prefix, THREAD_ERROR_OUT_OF_MEMORY);
+
+       memcpy(*ipv6_prefix, (onmesh_prefix_info->prefix).ipv6.fields.m8,
+                               THREAD_IPV6_PREFIX_SIZE*sizeof(uint8_t));
+       *ipv6_prefix_len = (onmesh_prefix_info->prefix).length;
+
+       FUNC_EXIT;
+       return THREAD_ERROR_NONE;
+}
+
 int thread_br_add_onmesh_prefix(thread_instance_h instance,
        const uint8_t *ipv6_prefix, int ipv6_prefix_len, int8_t preference,
        bool preferred, bool slaac, bool dhcp, bool configure, bool default_route,
index 3e7dbc7..dfb76c7 100644 (file)
@@ -335,36 +335,47 @@ TEST_F(ThreadBRTest, BRAddOnmeshPrefixInvalidParameter)
                        dhcp, configure, defaultRoute, onMesh, stable, &onmeshPrefix));
 }
 
-TEST_F(ThreadBRTest, BRCreateOnmeshPrefixNotEnabled)
+TEST_F(ThreadBRTest, BRCreateOnmeshPrefixErrorNone)
 {
        EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
-       EXPECT_EQ(THREAD_ERROR_NOT_ENABLED,
+       EXPECT_EQ(THREAD_ERROR_NONE,
                thread_onmesh_prefix_create(instance, &onmeshPrefix));
 }
 
-TEST_F(ThreadBRTest, BRCreateOnmeshPrefixErrorNone)
+TEST_F(ThreadBRTest, BRDestroyOnmeshPrefixErrorNone)
 {
        EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
-       EXPECT_EQ(THREAD_ERROR_NONE, thread_br_enable(instance));
        EXPECT_EQ(THREAD_ERROR_NONE,
                thread_onmesh_prefix_create(instance, &onmeshPrefix));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_destroy(instance, onmeshPrefix));
 }
 
-TEST_F(ThreadBRTest, BRDestroyOnmeshPrefixNotEnabled)
+TEST_F(ThreadBRTest, BRSetOnmeshIpv6PrefixErrorNone)
 {
        EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
-       EXPECT_EQ(THREAD_ERROR_NOT_ENABLED,
-               thread_onmesh_prefix_destroy(instance, onmeshPrefix));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_create(instance, &onmeshPrefix));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_set_ipv6_prefix(onmeshPrefix,
+                       onmeshIpv6Prefix, onmeshIpv6PrefixLen));
 }
 
-TEST_F(ThreadBRTest, BRDestroyOnmeshPrefixErrorNone)
+TEST_F(ThreadBRTest, BRGetOnmeshIpv6PrefixErrorNone)
 {
+       uint8_t *ipv6Prefix = NULL;
+       uint8_t ipv6PrefixLen;
+
        EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
-       EXPECT_EQ(THREAD_ERROR_NONE, thread_br_enable(instance));
        EXPECT_EQ(THREAD_ERROR_NONE,
                thread_onmesh_prefix_create(instance, &onmeshPrefix));
        EXPECT_EQ(THREAD_ERROR_NONE,
-               thread_onmesh_prefix_destroy(instance, onmeshPrefix));
+               thread_onmesh_prefix_set_ipv6_prefix(onmeshPrefix,
+                       onmeshIpv6Prefix, onmeshIpv6PrefixLen));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_get_ipv6_prefix(onmeshPrefix,
+                       &ipv6Prefix, &ipv6PrefixLen));
+       g_free(ipv6Prefix);
 }
 
 TEST_F(ThreadBRTest, BRAddOnmeshPrefixNotEnabled)