Skip to content

Commit

Permalink
feat(rest api): add api to delete node information
Browse files Browse the repository at this point in the history
  • Loading branch information
gytxxsy committed Oct 16, 2023
1 parent 89fade5 commit ddffc8a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/esp_ot_br_server/private_include/esp_br_web_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ extern "C" {
*/
cJSON *handle_ot_resource_node_information_request(void);

/**
* @brief Provides an entry to delete the Thread device's node information
*
* @return
* - OT_ERROR_NONE : On success.
* - Other : Fail to delete the node information .
*/
otError handle_ot_resource_node_delete_information_request(void);

/**
* @brief Provide a entry to collect the Thread network topology message.
*
Expand Down
24 changes: 24 additions & 0 deletions components/esp_ot_br_server/src/esp_br_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct request_url {
-----------------------------------------------------*/
static esp_err_t esp_otbr_network_diagnostics_get_handler(httpd_req_t *req);
static esp_err_t esp_otbr_network_node_get_handler(httpd_req_t *req);
static esp_err_t esp_otbr_network_node_delete_handler(httpd_req_t *req);
static esp_err_t esp_otbr_network_node_rloc_get_handler(httpd_req_t *req);
static esp_err_t esp_otbr_network_node_rloc16_get_handler(httpd_req_t *req);
static esp_err_t esp_otbr_network_node_state_get_handler(httpd_req_t *req);
Expand All @@ -104,6 +105,12 @@ static httpd_uri_t s_resource_handlers[] = {
.handler = esp_otbr_network_node_get_handler,
.user_ctx = NULL,
},
{
.uri = ESP_OT_REST_API_NODE_PATH,
.method = HTTP_DELETE,
.handler = esp_otbr_network_node_delete_handler,
.user_ctx = NULL,
},
{
.uri = ESP_OT_REST_API_NODE_RLOC_PATH,
.method = HTTP_GET,
Expand Down Expand Up @@ -359,6 +366,23 @@ static esp_err_t esp_otbr_network_node_get_handler(httpd_req_t *req)
return ret;
}

static esp_err_t esp_otbr_network_node_delete_handler(httpd_req_t *req)
{
ESP_RETURN_ON_FALSE(req, ESP_FAIL, WEB_TAG, "Failed to parse the node information of http request");
esp_err_t ret = ESP_OK;
otError error = handle_ot_resource_node_delete_information_request();
if (error == OT_ERROR_NONE) {
httpd_resp_set_status(req, HTTPD_200);
} else if (error == OT_ERROR_INVALID_STATE) {
httpd_resp_set_status(req, "409 Conflict");
} else {
httpd_resp_set_status(req, HTTPD_500);
}
ESP_GOTO_ON_ERROR(httpd_resp_send(req, NULL, 0), exit, WEB_TAG, "Failed to response %s", req->uri);
exit:
return ret;
}

static esp_err_t esp_otbr_network_node_rloc_get_handler(httpd_req_t *req)
{
esp_err_t ret = ESP_OK;
Expand Down
13 changes: 13 additions & 0 deletions components/esp_ot_br_server/src/esp_br_web_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,19 @@ cJSON *handle_ot_resource_node_information_request()
return thread_node_struct_convert2_json(&node);
}

otError handle_ot_resource_node_delete_information_request(void)
{
otError ret = OT_ERROR_NONE;
esp_openthread_lock_acquire(portMAX_DELAY);
otInstance *ins = esp_openthread_get_instance();
ERROR_EXIT(otThreadSetEnabled(ins, false), exit, API_TAG, "Failed to stop Thread");
ERROR_EXIT(otIp6SetEnabled(ins, false), exit, API_TAG, "Failed to execute config down");
ERROR_EXIT(otInstanceErasePersistentInfo(ins), exit, API_TAG, "Failed to delete node information");
exit:
esp_openthread_lock_release();
return ret;
}

cJSON *handle_ot_resource_network_diagnostics_request()
{
destroy_thread_diagnosticTlv_set(s_diagnosticTlv_set);
Expand Down

0 comments on commit ddffc8a

Please sign in to comment.