Add new CAPIs and unittest to set/get dhcp for onmesh 77/276677/1
authorhyunuk.tak <hyunuk.tak@samsung.com>
Wed, 15 Jun 2022 00:06:09 +0000 (09:06 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Thu, 23 Jun 2022 02:23:15 +0000 (11:23 +0900)
Change-Id: Ib9c9f09fd3e4cea2377284075b01ee598522fa1b
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
include/thread.h
src/thread-br.c
tests/unittest/thread-unittest-br.cpp

index 20bcf9a..2949a0e 100644 (file)
@@ -789,6 +789,44 @@ int thread_onmesh_prefix_get_slaac(thread_onmesh_prefix_info_h onmesh_prefix,
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
+ * @brief Set dhcp 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_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
+       bool dhcp);
+
+/**
+ * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
+ * @brief Get dhcp 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_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
+       bool *dhcp);
+
+/**
+ * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
  * @brief Add an on-mesh prefix to the network
  * @since_tizen 7.0
  *
index fe341e7..eda713e 100644 (file)
@@ -630,6 +630,38 @@ int thread_onmesh_prefix_get_slaac(thread_onmesh_prefix_info_h onmesh_prefix,
        return THREAD_ERROR_NONE;
 }
 
+int thread_onmesh_prefix_set_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
+       bool dhcp)
+{
+       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;
+       onmesh_prefix_info->dhcp = dhcp;
+
+       FUNC_EXIT;
+       return THREAD_ERROR_NONE;
+}
+
+int thread_onmesh_prefix_get_dhcp(thread_onmesh_prefix_info_h onmesh_prefix,
+       bool *dhcp)
+{
+       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;
+       *dhcp = onmesh_prefix_info->dhcp;
+
+       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 e5ea49a..70c10ea 100644 (file)
@@ -438,6 +438,26 @@ TEST_F(ThreadBRTest, BRGetOnmeshSlaacErrorNone)
                thread_onmesh_prefix_get_slaac(onmeshPrefix, &slaac));
 }
 
+TEST_F(ThreadBRTest, BRSetOnmeshDhcpErrorNone)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_create(instance, &onmeshPrefix));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_set_dhcp(onmeshPrefix, dhcp));
+}
+
+TEST_F(ThreadBRTest, BRGetOnmeshDhcpErrorNone)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_create(instance, &onmeshPrefix));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_set_dhcp(onmeshPrefix, dhcp));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_get_dhcp(onmeshPrefix, &dhcp));
+}
+
 TEST_F(ThreadBRTest, BRAddOnmeshPrefixNotEnabled)
 {
        EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));