#define THREAD_SRP_CLIENT_REMOVE_HOST_CMD "srp client host remove"
#define THREAD_SRP_CLIENT_STOP_CMD "srp client stop"
#define THREAD_SRP_CLIENT_START_CMD "srp client autostart enable"
+#define THREAD_IPADDR_V "ipaddr -v"
int _thread_socket_client_init(int *session_fd, const char *if_name);
/**
* @ingroup CAPI_NETWORK_THREAD_SRP_MODULE
+ * @brief Get node global ip address of the thread network node
+ * @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() and
+ * enabled with thread_enable().
+ * @see thread_initialize() and thread_enable()
+ */
+int thread_get_global_ipaddr(thread_instance_h instance, const char **ipaddr);
+
+/**
+ * @ingroup CAPI_NETWORK_THREAD_SRP_MODULE
* @brief Up the netwotk interface for the thread node.
* @since_tizen 7.0
*
return ret;
}
+int thread_get_global_ipaddr(thread_instance_h instance, const char **ipaddr)
+{
+ FUNC_ENTRY;
+ THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+ THREAD_CHECK_INIT_STATUS();
+ THREAD_VALIDATE_INPUT_PARAMETER(instance);
+
+ int ret = THREAD_ERROR_NONE;
+ char buffer[THREAD_MAX_BUFFER_SIZE];
+ int session_fd = _thread_get_socket_fd();
+ const char *msg = THREAD_IPADDR_V;
+ char *ret_ptr, *next_ptr;
+
+ ret = _thread_socket_client_write(session_fd, msg, strlen(msg));
+ if (ret != THREAD_ERROR_NONE) {
+ THREAD_DBG("Failed to execute command %s", msg);
+ return ret;
+ }
+ THREAD_DBG("Executed command '%s' with size %zu", msg, strlen(msg));
+
+ /* Check response */
+ ret = _thread_socket_client_read(session_fd, buffer);
+ if (ret != THREAD_ERROR_NONE && ret != THREAD_ERROR_ALREADY_DONE) {
+ THREAD_DBG("Socket response failed..");
+ return ret;
+ }
+
+ /* result is like below:
+ * > ipaddr -v
+ * fdd6:54c2:ee47:f2d2:0:ff:fe00:9400 origin:thread
+ * fd0b:8d9c:ac8c:1:2c82:12dd:825b:70c4 origin:slaac
+ * fdd6:54c2:ee47:f2d2:b267:e8fa:5bd6:2891 origin:thread
+ * fe80:0:0:0:5857:6a63:d5f1:91b6 origin:thread
+ * Done
+ */
+ ret_ptr = strtok_r(buffer, "\n", &next_ptr);
+ while (ret_ptr) {
+ if (strstr(ret_ptr, "origin:slaac")) {
+ strtok_r(ret_ptr, " ", &next_ptr);
+ THREAD_DBG("Global Ipaddr: %s", ret_ptr);
+ *ipaddr = g_strdup(ret_ptr);
+ return THREAD_ERROR_NONE;
+ }
+ ret_ptr = strtok_r(NULL, "\n", &next_ptr);
+ }
+
+ FUNC_EXIT;
+ return ret;
+}
+
return RET_SUCCESS;
}
+static int run_thread_get_global_ipaddr(MManager *mm, struct menu_data *menu)
+{
+ FUNC_ENTRY;
+ thread_instance_h g_instance = mm->t_instance;
+ const char *ipaddr;
+ if (g_instance == NULL)
+ goto OUT;
+
+ int ret = thread_get_global_ipaddr(g_instance, &ipaddr);
+ if (ret == THREAD_ERROR_NONE) {
+ msg("thread_get_ipaddr_global success");
+ msg("ipaddr: %s", ipaddr);
+ } else {
+ msg("thread_get_ipaddr_global failed");
+ }
+OUT:
+ FUNC_EXIT;
+ return RET_SUCCESS;
+}
+
static struct menu_data menu_thread_network_set_active_dataset_tlvs[] = {
{ "1", "Tlvs_buffer len", NULL, NULL, g_str_buf_length},
{ "2", "Tlvs_buffer", NULL, NULL, g_str_tlvs_buffer},
menu_thread_add_ipaddr, NULL, NULL},
{ "9", "thread_remove_ipaddr",
menu_thread_remove_ipaddr, NULL, NULL},
+ { "10", "thread_get_global_ipaddr",
+ NULL, run_thread_get_global_ipaddr, NULL},
{ NULL, NULL, },
};
uint8_t tlvsBuffer[NETWORK_TLVS_SIZE];
int tlvsBufferLength;
uint8_t ipv6Address[THREAD_IPV6_ADDRESS_SIZE];
+ const char *globalIpaddr;
public:
static void getIpAddrCallback(int index, char* ipaddr,
thread_remove_ipaddr(instance, ipv6Address));
}
+TEST_F(ThreadNetworkTest, GetGlobalIpAddrNotInitialized)
+{
+ EXPECT_EQ(THREAD_ERROR_NONE, thread_deinitialize());
+ EXPECT_EQ(THREAD_ERROR_NOT_INITIALIZED,
+ thread_get_global_ipaddr(instance, &globalIpaddr));
+}
+
+TEST_F(ThreadNetworkTest, GetGlobalIpAddrInvalidParameter)
+{
+ EXPECT_EQ(THREAD_ERROR_INVALID_PARAMETER,
+ thread_get_global_ipaddr(instance, nullptr));
+}
+
+TEST_F(ThreadNetworkTest, GetGlobalIpAddrErrorNone)
+{
+ EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
+ EXPECT_EQ(THREAD_ERROR_NONE,
+ thread_get_global_ipaddr(instance, &globalIpaddr));
+ g_free((char *)globalIpaddr);
+}
+
TEST_F(ThreadNetworkTest, GetPanIdNotInitialized)
{
uint16_t panid;
const char *serviceName;
const char *address;
- uint64_t port;
+ uint16_t port;
bool isDeleted;
thread_instance_h instance;