Skip to content

Commit

Permalink
Merge branch 'feat/support_br_wifi_disconnect' into 'main'
Browse files Browse the repository at this point in the history
feat(ext_cli): support wifi disconnect

Closes TZ-971

See merge request espressif/esp-thread-br!118
  • Loading branch information
chshu committed Aug 21, 2024
2 parents aa68a59 + 87c907e commit 5f29e7d
Show file tree
Hide file tree
Showing 12 changed files with 434 additions and 176 deletions.
3 changes: 3 additions & 0 deletions components/esp_ot_cli_extension/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ if(CONFIG_OPENTHREAD_RCP_COMMAND)
endif()

set(include "include")
if(CONFIG_OPENTHREAD_CLI_WIFI)
list(APPEND include $ENV{IDF_PATH}/examples/common_components/protocol_examples_common/include)
endif()
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "${include}"
PRIV_REQUIRES lwip openthread iperf esp_netif esp_wifi http_parser esp_http_client esp_coex heap mbedtls nvs_flash)
Expand Down
2 changes: 1 addition & 1 deletion components/esp_ot_cli_extension/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ menu "OpenThread Extension CLI"
config OPENTHREAD_CLI_WIFI
bool "Enable wifi connection command"
depends on OPENTHREAD_CLI_ESP_EXTENSION && OPENTHREAD_BORDER_ROUTER
default y
default y if ESP_WIFI_ENABLED

config OPENTHREAD_CLI_OTA
bool "Enable OTA command"
Expand Down
10 changes: 6 additions & 4 deletions components/esp_ot_cli_extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,11 @@ Used for connecting the border router to the Wi-Fi network.
---wifi parameter---
connect -s <ssid> -p <psk> : connect to a wifi network with an ssid and a psk
connect -s <ssid> : connect to a wifi network with an ssid
disconnect : wifi disconnect once, only for test
disconnect <delay> : wifi disconnect, and reconnect after delay(ms), only for test
disconnect : wifi disconnect
state : get wifi state, disconnect or connect
mac <role> : get mac address of wifi netif, <role> can be "sta" or "ap"
config : get stored wifi configurations
config clear : clear stored wifi configurations
---example---
join a wifi:
ssid: threadcertAP
Expand All @@ -647,10 +648,11 @@ join a wifi:
ssid: threadAP
does not have a psk : wifi connect -s threadAP
get wifi state : wifi state
wifi disconnect once : wifi disconnect
wifi disconnect, and reconnect after 2s : wifi disconnect 2000
wifi disconnect : wifi disconnect
get mac address of Wi-Fi station : wifi mac sta
get mac address of Wi-Fi soft-AP : wifi mac ap
get stored wifi configurations : wifi config
clear stored wifi configurations : wifi config clear
```

To join a Wi-Fi network, please use the `wifi connect` command:
Expand Down
2 changes: 1 addition & 1 deletion components/esp_ot_cli_extension/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.1.4"
version: "1.2.0"
description: Espressif OpenThread CLI Extension
url: https://github.com/espressif/esp-thread-br/tree/main/components/esp_ot_cli_extension
dependencies:
Expand Down
85 changes: 82 additions & 3 deletions components/esp_ot_cli_extension/include/esp_ot_wifi_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,98 @@
extern "C" {
#endif

typedef enum {
OT_WIFI_DISCONNECTED,
OT_WIFI_CONNECTED,
OT_WIFI_RECONNECTING,
} esp_ot_wifi_state_t;

/**
* @brief User command "wifi" process.
*
*/
otError esp_ot_process_wifi_cmd(void *aContext, uint8_t aArgsLength, char *aArgs[]);

void handle_wifi_addr_init(void);
/**
* @brief This function set or clear the border router initalization flag.
*
* @param[in] initialized border router is or not initalized.
*/
void esp_ot_wifi_border_router_init_flag_set(bool initialized);

/**
* @brief This function connect the wifi.
*
* @param[in] ssid ssid of wifi
* @param[in] password password of wifi
*
* @return
* - ESP_OK on success
* - others on failure
*/
esp_err_t esp_ot_wifi_connect(const char *ssid, const char *password);

/**
* @brief This function initalize the nvs for wifi configurations.
*
* @return
* - ESP_OK on success
* - others on failure
*/
esp_err_t esp_ot_wifi_config_init(void);

/**
* @brief This function set the wifi ssid.
*
* @param[in] ssid pointer to ssid of wifi
*
* @return
* - ESP_OK on success
* - others on failure
*/
esp_err_t esp_ot_wifi_config_set_ssid(const char *ssid);

/**
* @brief This function get the wifi ssid.
*
* @param[in] password pointer to password of wifi
*
* @return
* - ESP_OK on success
* - others on failure
*/
esp_err_t esp_ot_wifi_config_get_ssid(char *ssid);

/**
* @brief This function set the wifi password.
*
* @param[in] ssid pointer to ssid of wifi
*
* @return
* - ESP_OK on success
* - others on failure
*/
esp_err_t esp_ot_wifi_config_set_password(const char *password);

/**
* @brief This function get the wifi password.
*
* @param[in] password pointer to password of wifi
*
* @return
* - ESP_OK on success
* - others on failure
*/
esp_err_t esp_ot_wifi_config_get_password(char *password);

/**
* @brief Wifi netif init.
* @brief This function clear the wifi configurations stored in nvs.
*
* @return
* - ESP_OK on success
* - others on failure
*/
void esp_ot_wifi_netif_init(void);
esp_err_t esp_ot_wifi_config_clear(void);

#ifdef __cplusplus
}
Expand Down
14 changes: 0 additions & 14 deletions components/esp_ot_cli_extension/src/esp_ot_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#include "openthread/cli.h"

#if CONFIG_OPENTHREAD_CLI_WIFI
#if CONFIG_OPENTHREAD_BR_AUTO_START
static bool wifi_addr_handle_init = false;
#endif
ESP_EVENT_DECLARE_BASE(WIFI_ADDRESS_EVENT);
#endif

Expand Down Expand Up @@ -124,17 +121,6 @@ void esp_lwip_add_del_ip(ip_event_add_ip6_t *add_addr, const char *if_name, bool

otError esp_ot_process_ip(void *aContext, uint8_t aArgsLength, char *aArgs[])
{
#if CONFIG_OPENTHREAD_BR_AUTO_START
esp_openthread_task_switching_lock_release();
esp_netif_t *esp_netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
esp_openthread_task_switching_lock_acquire(portMAX_DELAY);
if (esp_netif != NULL && !wifi_addr_handle_init) {
handle_wifi_addr_init();
wifi_addr_handle_init = true;
}
#endif // CONFIG_OPENTHREAD_BR_AUTO_START

(void)(aContext);
if (aArgsLength == 0) {
otCliOutputFormat("---ip parameter---\n");
otCliOutputFormat("print : print all ip on each interface of lwip\n");
Expand Down
Loading

0 comments on commit 5f29e7d

Please sign in to comment.