*/
int thread_ifconfig_up(thread_instance_h instance);
+/**
+ * @ingroup CAPI_NETWORK_THREAD_SRP_MODULE
+ * @brief Add Ipv6 address to the thread node.
+ * @since_tizen 7.0
+ *
+ * @param[in] ipv6_address Byte list
+ *
+ * @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_add_ipaddr(thread_instance_h instance, const uint8_t *ipv6_address);
+
+/**
+ * @ingroup CAPI_NETWORK_THREAD_SRP_MODULE
+ * @brief Remove Ipv6 address from the thread node.
+ * @since_tizen 7.0
+ *
+ * @param[in] ipv6_address Byte list
+ *
+ * @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_remove_ipaddr(thread_instance_h instance, const uint8_t *ipv6_address);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
FUNC_EXIT;
return ret;
}
+
+static bool __is_valid_ipv6(const uint8_t* ipv6_address)
+{
+ FUNC_ENTRY;
+
+ int index = 0;
+ while (index < THREAD_IPV6_ADDRESS_SIZE) {
+ char buffer[THREAD_NETWORK_BUFFER_MAX];
+ snprintf(buffer, THREAD_NETWORK_BUFFER_MAX, "%02x", ipv6_address[index]);
+ if ((buffer[0] < '0' || buffer[0] > '9') &&
+ (buffer[0] < 'a' || buffer[0] > 'f'))
+ return FALSE;
+ if ((buffer[1] < '0' || buffer[1] > '9') &&
+ (buffer[1] < 'a' || buffer[1] > 'f'))
+ return FALSE;
+
+ index++;
+ }
+ THREAD_DBG("DEBUG: NETWORK MESSAGE -> return true");
+
+ FUNC_EXIT;
+ return TRUE;
+}
+
+int thread_add_ipaddr(thread_instance_h instance, const uint8_t *ipv6_address)
+{
+ FUNC_ENTRY;
+ THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+ THREAD_CHECK_INIT_STATUS();
+ THREAD_VALIDATE_INPUT_PARAMETER(instance);
+ THREAD_VALIDATE_INPUT_PARAMETER(ipv6_address);
+
+ int ret = THREAD_ERROR_NONE;
+ char msg[THREAD_NETWORK_BUFFER_MAX];
+
+ retv_if(!__is_valid_ipv6(ipv6_address), THREAD_ERROR_INVALID_PARAMETER);
+
+ snprintf(msg, THREAD_NETWORK_BUFFER_MAX,
+ "ipaddr add %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
+ ipv6_address[0], ipv6_address[1], ipv6_address[2], ipv6_address[3],
+ ipv6_address[4], ipv6_address[5], ipv6_address[6], ipv6_address[7],
+ ipv6_address[8], ipv6_address[9], ipv6_address[10], ipv6_address[11],
+ ipv6_address[12], ipv6_address[13], ipv6_address[14], ipv6_address[15]);
+
+ ret = _thread_socket_client_execute(_thread_get_socket_fd(), msg, strlen(msg));
+ retv_if(ret != THREAD_ERROR_NONE, ret);
+ THREAD_DBG("Successfully added address");
+
+ FUNC_EXIT;
+ return ret;
+}
+
+int thread_remove_ipaddr(thread_instance_h instance, const uint8_t *ipv6_address)
+{
+ FUNC_ENTRY;
+ THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+ THREAD_CHECK_INIT_STATUS();
+ THREAD_VALIDATE_INPUT_PARAMETER(instance);
+ THREAD_VALIDATE_INPUT_PARAMETER(ipv6_address);
+
+ int ret = THREAD_ERROR_NONE;
+ char msg[THREAD_NETWORK_BUFFER_MAX];
+
+ retv_if(!__is_valid_ipv6(ipv6_address), THREAD_ERROR_INVALID_PARAMETER);
+
+ snprintf(msg, THREAD_BORDER_ROUTER_BUFFER_MAX,
+ "ipaddr del %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
+ ipv6_address[0], ipv6_address[1], ipv6_address[2], ipv6_address[3],
+ ipv6_address[4], ipv6_address[5], ipv6_address[6], ipv6_address[7],
+ ipv6_address[8], ipv6_address[9], ipv6_address[10], ipv6_address[11],
+ ipv6_address[12], ipv6_address[13], ipv6_address[14], ipv6_address[15]);
+
+ ret = _thread_socket_client_execute(_thread_get_socket_fd(), msg, strlen(msg));
+ retv_if(ret != THREAD_ERROR_NONE, ret);
+ THREAD_DBG("Successfully removed address");
+
+ FUNC_EXIT;
+ return ret;
+}
+
uint16_t g_panid;
static char g_str_ipaddr_type[MENU_DATA_SIZE + 1] = "0";
+static char g_str_ipaddr[MENU_DATA_SIZE + 1];
+
+uint8_t g_ipv6_address[THREAD_IPV6_ADDRESS_SIZE];
static int run_thread_network_destroy_operational_network(MManager *mm, struct menu_data *menu)
{
return RET_SUCCESS;
}
+static int run_thread_add_ipaddr(MManager *mm, struct menu_data *menu)
+{
+ FUNC_ENTRY;
+ thread_instance_h g_instance = mm->t_instance;
+ if (g_instance == NULL)
+ goto OUT;
+
+ int ret = _preprocess_ipv6_prefix(g_str_ipaddr, g_ipv6_address);
+ retv_if(ret != THREAD_ERROR_NONE, ret);
+
+ ret = thread_add_ipaddr(g_instance, g_ipv6_address);
+ if (ret == THREAD_ERROR_NONE)
+ msg("thread_add_ipaddr success");
+ else
+ msg("thread_add_ipaddr failed");
+OUT:
+ FUNC_EXIT;
+ return RET_SUCCESS;
+}
+
+static int run_thread_remove_ipaddr(MManager *mm, struct menu_data *menu)
+{
+ FUNC_ENTRY;
+ thread_instance_h g_instance = mm->t_instance;
+ if (g_instance == NULL)
+ goto OUT;
+
+ int ret = _preprocess_ipv6_prefix(g_str_ipaddr, g_ipv6_address);
+ retv_if(ret != THREAD_ERROR_NONE, ret);
+
+ ret = thread_remove_ipaddr(g_instance, g_ipv6_address);
+ if (ret == THREAD_ERROR_NONE)
+ msg("thread_remove_ipaddr success");
+ else
+ msg("thread_remove_ipaddr 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},
{ NULL, NULL, },
};
+static struct menu_data menu_thread_add_ipaddr[] = {
+ { "1", "Type IPv6 address", NULL, NULL, g_str_ipaddr},
+ { "2", "run", NULL, run_thread_add_ipaddr, NULL},
+ { NULL, NULL, },
+};
+
+static struct menu_data menu_thread_remove_ipaddr[] = {
+ { "1", "Type IPv6 address", NULL, NULL, g_str_ipaddr},
+ { "2", "run", NULL, run_thread_remove_ipaddr, NULL},
+ { NULL, NULL, },
+};
+
struct menu_data menu_thread_network[] = {
{ "1", "thread_network_create_operational_network",
menu_thread_network_create_operational_network, NULL, NULL},
NULL, run_thread_network_attach, NULL},
{ "6", "thread_get_ipaddr",
menu_thread_get_ipaddr, NULL, NULL},
+ { "7", "thread_add_ipaddr",
+ menu_thread_add_ipaddr, NULL, NULL},
+ { "8", "thread_remove_ipaddr",
+ menu_thread_remove_ipaddr, NULL, NULL},
{ NULL, NULL, },
};
+