/**
* @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
*
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);
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,
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,
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)