From adf5f2b5737d3c1c509fcc7e3d03b8818ed63438 Mon Sep 17 00:00:00 2001 From: "hyunuk.tak" Date: Mon, 30 May 2022 15:46:44 +0900 Subject: [PATCH] Add a new CAPI and test for thread_br_get_ipv6_prefix Change-Id: I899a64ea8b0e1ffdeef511b074ac918c804c2d01 Signed-off-by: hyunuk.tak --- include/thread.h | 18 ++++++++++++++++++ src/thread-br.c | 4 +++- tests/unittest/thread-unittest-br.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/include/thread.h b/include/thread.h index 400f606..f2c6a2c 100644 --- a/include/thread.h +++ b/include/thread.h @@ -492,6 +492,24 @@ int thread_br_get_route_info(thread_route_info_h route, uint8_t *ipv6_prefix, /** * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE + * @brief Get ipv6 prefix for route + * @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_external_route_foreach_cb() + */ +int thread_br_get_ipv6_prefix(thread_route_info_h route, + uint8_t *ipv6_prefix, uint8_t *ipv6_prefix_len); + +/** + * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE * @brief Add an external border routing rule to the network. * @since_tizen 7.0 * diff --git a/src/thread-br.c b/src/thread-br.c index 791a13b..08682f9 100644 --- a/src/thread-br.c +++ b/src/thread-br.c @@ -277,17 +277,19 @@ int thread_br_get_route_info(thread_route_info_h route, } int thread_br_get_ipv6_prefix(thread_route_info_h route, - uint8_t *ipv6_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(route); THREAD_VALIDATE_INPUT_PARAMETER(ipv6_prefix); + THREAD_VALIDATE_INPUT_PARAMETER(ipv6_prefix_len); thread_route_info_s *route_info = (thread_route_info_s*)route; memcpy(ipv6_prefix, (route_info->prefix).ipv6.fields.m8, THREAD_IPV6_PREFIX_SIZE*sizeof(uint8_t)); + *ipv6_prefix_len = (route_info->prefix).length; FUNC_EXIT; return THREAD_ERROR_NONE; diff --git a/tests/unittest/thread-unittest-br.cpp b/tests/unittest/thread-unittest-br.cpp index f4f458d..554bced 100644 --- a/tests/unittest/thread-unittest-br.cpp +++ b/tests/unittest/thread-unittest-br.cpp @@ -23,6 +23,10 @@ class ThreadBRTest : public ::testing::Test { public: + enum class RouteInfo { + kIpv6Prefix, + }; + uint8_t ipv6Prefix[THREAD_IPV6_PREFIX_SIZE]; uint8_t ipv6PrefixLen; uint16_t rloc16; @@ -48,6 +52,20 @@ public: static bool GetExternalRoutesCallback(int total, thread_route_info_h route_info, void *user_data) { + RouteInfo routeInfo = static_cast(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; + default: + break; + } + return true; }; @@ -164,6 +182,15 @@ TEST_F(ThreadBRTest, BRGetExternalRoutesErrorNone) thread_br_get_external_routes(instance, GetExternalRoutesCallback, nullptr)); } +TEST_F(ThreadBRTest, BRGetIpv6PrefixErrorNone) +{ + 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_external_routes(instance, GetExternalRoutesCallback, + GUINT_TO_POINTER(static_cast(RouteInfo::kIpv6Prefix)))); +} + TEST_F(ThreadBRTest, BRAddExternalRouteNotInitialized) { EXPECT_EQ(THREAD_ERROR_NONE, thread_deinitialize()); -- 2.7.4