diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f60a43c21e..9b7ce9da4e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -61,8 +61,8 @@ repos: - repo: local hooks: - id: commit message scopes - name: "commit message must be scoped with: mdns, modem, websocket, asio, mqtt_cxx, console, common, eppp" - entry: '\A(?!(feat|fix|ci|bump|test|docs)\((mdns|modem|common|console|websocket|asio|mqtt_cxx|examples|eppp)\)\:)' + name: "commit message must be scoped with: mdns, modem, websocket, asio, mqtt_cxx, console, common, eppp, wifi_remote" + entry: '\A(?!(feat|fix|ci|bump|test|docs)\((mdns|modem|common|console|websocket|asio|mqtt_cxx|examples|eppp|wifi_remote)\)\:)' language: pygrep args: [--multiline] stages: [commit-msg] diff --git a/esp_wifi_remote/CMakeLists.txt b/components/esp_wifi_remote/CMakeLists.txt similarity index 62% rename from esp_wifi_remote/CMakeLists.txt rename to components/esp_wifi_remote/CMakeLists.txt index fd7d4a34fc..7d94483db5 100644 --- a/esp_wifi_remote/CMakeLists.txt +++ b/components/esp_wifi_remote/CMakeLists.txt @@ -1,11 +1,8 @@ - if(NOT CONFIG_ESP_WIFI_ENABLED) set(src_wifi_is_remote esp_wifi_remote.c) endif() idf_component_register(INCLUDE_DIRS include SRCS wifi_remote_rpc.c wifi_remote_net.c wifi_remote_init.c ${src_wifi_is_remote} - ${INTERNAL_SRCS} REQUIRES esp_event esp_netif - PRIV_INCLUDE_DIRS ${INTERNAL_INCLUDE_DIRS} - PRIV_REQUIRES esp_wifi esp_hosted_preview) + PRIV_REQUIRES esp_wifi esp_hosted) diff --git a/esp_wifi_remote/Kconfig b/components/esp_wifi_remote/Kconfig similarity index 100% rename from esp_wifi_remote/Kconfig rename to components/esp_wifi_remote/Kconfig diff --git a/esp_wifi_remote/LICENSE b/components/esp_wifi_remote/LICENSE similarity index 100% rename from esp_wifi_remote/LICENSE rename to components/esp_wifi_remote/LICENSE diff --git a/components/esp_wifi_remote/esp_wifi_remote.c b/components/esp_wifi_remote/esp_wifi_remote.c new file mode 100644 index 0000000000..7b9fb31510 --- /dev/null +++ b/components/esp_wifi_remote/esp_wifi_remote.c @@ -0,0 +1,215 @@ +/* + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "esp_wifi.h" +#include "esp_log.h" +#include "esp_wifi_remote.h" + +#define WEAK __attribute__((weak)) + +WEAK ESP_EVENT_DEFINE_BASE(WIFI_EVENT); + +WEAK wifi_osi_funcs_t g_wifi_osi_funcs; +WEAK const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs; +WEAK uint64_t g_wifi_feature_caps = +#if CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE + CONFIG_FEATURE_WPA3_SAE_BIT | +#endif +#if CONFIG_SPIRAM + CONFIG_FEATURE_CACHE_TX_BUF_BIT | +#endif +#if CONFIG_ESP_WIFI_FTM_INITIATOR_SUPPORT + CONFIG_FEATURE_FTM_INITIATOR_BIT | +#endif +#if CONFIG_ESP_WIFI_FTM_RESPONDER_SUPPORT + CONFIG_FEATURE_FTM_RESPONDER_BIT | +#endif + 0; + +WEAK esp_err_t esp_wifi_connect(void) +{ + return remote_esp_wifi_connect(); +} + +WEAK esp_err_t esp_wifi_disconnect(void) +{ + return remote_esp_wifi_disconnect(); +} + +WEAK esp_err_t esp_wifi_init(const wifi_init_config_t *config) +{ + return remote_esp_wifi_init(config); +} + +WEAK esp_err_t esp_wifi_deinit(void) +{ + return remote_esp_wifi_deinit(); +} + +WEAK esp_err_t esp_wifi_set_mode(wifi_mode_t mode) +{ + return remote_esp_wifi_set_mode(mode); +} + +WEAK esp_err_t esp_wifi_get_mode(wifi_mode_t *mode) +{ + return remote_esp_wifi_get_mode(mode); +} + +WEAK esp_err_t esp_wifi_set_config(wifi_interface_t interface, wifi_config_t *conf) +{ + return remote_esp_wifi_set_config(interface, conf); +} + +WEAK esp_err_t esp_wifi_get_config(wifi_interface_t interface, wifi_config_t *conf) +{ + return remote_esp_wifi_get_config(interface, conf); +} + +WEAK esp_err_t esp_wifi_start(void) +{ + return remote_esp_wifi_start(); +} + +WEAK esp_err_t esp_wifi_stop(void) +{ + return remote_esp_wifi_stop(); +} + +WEAK esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]) +{ + return remote_esp_wifi_get_mac(ifx, mac); +} + +WEAK esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, const uint8_t mac[6]) +{ + return remote_esp_wifi_set_mac(ifx, mac); +} + +WEAK esp_err_t esp_wifi_scan_start(const wifi_scan_config_t *config, bool block) +{ + return remote_esp_wifi_scan_start(config, block); +} + +WEAK esp_err_t esp_wifi_scan_stop(void) +{ + return remote_esp_wifi_scan_stop(); +} + +WEAK esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number) +{ + return remote_esp_wifi_scan_get_ap_num(number); +} + +WEAK esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records) +{ + return remote_esp_wifi_scan_get_ap_records(number, ap_records); +} + +WEAK esp_err_t esp_wifi_clear_ap_list(void) +{ + return remote_esp_wifi_clear_ap_list(); +} + +WEAK esp_err_t esp_wifi_restore(void) +{ + return remote_esp_wifi_restore(); +} + +WEAK esp_err_t esp_wifi_clear_fast_connect(void) +{ + return remote_esp_wifi_clear_fast_connect(); +} + +WEAK esp_err_t esp_wifi_deauth_sta(uint16_t aid) +{ + return remote_esp_wifi_deauth_sta(aid); +} + +WEAK esp_err_t esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info) +{ + return remote_esp_wifi_sta_get_ap_info(ap_info); +} + +WEAK esp_err_t esp_wifi_set_ps(wifi_ps_type_t type) +{ + return remote_esp_wifi_set_ps(type); +} + +WEAK esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type) +{ + return remote_esp_wifi_get_ps(type); +} + +WEAK esp_err_t esp_wifi_set_storage(wifi_storage_t storage) +{ + return remote_esp_wifi_set_storage(storage); +} + +WEAK esp_err_t esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw) +{ + return remote_esp_wifi_set_bandwidth(ifx, bw); +} + +WEAK esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw) +{ + return remote_esp_wifi_get_bandwidth(ifx, bw); +} + +WEAK esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second) +{ + return remote_esp_wifi_set_channel(primary, second); +} + +WEAK esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second) +{ + return remote_esp_wifi_get_channel(primary, second); +} + +WEAK esp_err_t esp_wifi_set_country_code(const char *country, bool ieee80211d_enabled) +{ + return remote_esp_wifi_set_country_code(country, ieee80211d_enabled); +} + +WEAK esp_err_t esp_wifi_get_country_code(char *country) +{ + return remote_esp_wifi_get_country_code(country); +} + +WEAK esp_err_t esp_wifi_set_country(const wifi_country_t *country) +{ + return remote_esp_wifi_set_country(country); +} + +WEAK esp_err_t esp_wifi_get_country(wifi_country_t *country) +{ + return remote_esp_wifi_get_country(country); +} + +WEAK esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta) +{ + return remote_esp_wifi_ap_get_sta_list(sta); +} + +WEAK esp_err_t esp_wifi_ap_get_sta_aid(const uint8_t mac[6], uint16_t *aid) +{ + return remote_esp_wifi_ap_get_sta_aid(mac, aid); +} + +WEAK esp_err_t esp_wifi_sta_get_rssi(int *rssi) +{ + return remote_esp_wifi_sta_get_rssi(rssi); +} + +WEAK esp_err_t esp_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap) +{ + return remote_esp_wifi_set_protocol(ifx, protocol_bitmap); +} + +WEAK esp_err_t esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap) +{ + return remote_esp_wifi_get_protocol(ifx, protocol_bitmap); +} diff --git a/components/esp_wifi_remote/idf_component.yml b/components/esp_wifi_remote/idf_component.yml new file mode 100644 index 0000000000..71e3fd1813 --- /dev/null +++ b/components/esp_wifi_remote/idf_component.yml @@ -0,0 +1 @@ +version: "1.0.0" diff --git a/esp_wifi_remote/include/esp_wifi_native.h b/components/esp_wifi_remote/include/esp_wifi_native.h similarity index 96% rename from esp_wifi_remote/include/esp_wifi_native.h rename to components/esp_wifi_remote/include/esp_wifi_native.h index 2064a17753..4c9f082bcb 100644 --- a/esp_wifi_remote/include/esp_wifi_native.h +++ b/components/esp_wifi_remote/include/esp_wifi_native.h @@ -13,4 +13,4 @@ typedef struct wifi_sta_list_t { wifi_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM]; /**< station list */ int num; /**< number of stations in the list (other entries are invalid) */ -} wifi_sta_list_t; \ No newline at end of file +} wifi_sta_list_t; diff --git a/components/esp_wifi_remote/include/esp_wifi_remote.h b/components/esp_wifi_remote/include/esp_wifi_remote.h new file mode 100644 index 0000000000..d04f468e2d --- /dev/null +++ b/components/esp_wifi_remote/include/esp_wifi_remote.h @@ -0,0 +1,63 @@ +/* + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once +#include "esp_wifi.h" + +typedef esp_err_t (*esp_remote_channel_rx_fn_t)(void *h, void *buffer, void *buff_to_free, size_t len); +typedef esp_err_t (*esp_remote_channel_tx_fn_t)(void *h, void *buffer, size_t len); + +typedef struct esp_remote_channel *esp_remote_channel_t; +typedef struct esp_remote_channel_config *esp_remote_channel_config_t; + +// Public API +esp_err_t remote_esp_wifi_connect(void); +esp_err_t remote_esp_wifi_disconnect(void); +esp_err_t remote_esp_wifi_init(const wifi_init_config_t *config); +esp_err_t remote_esp_wifi_deinit(void); +esp_err_t remote_esp_wifi_set_mode(wifi_mode_t mode); +esp_err_t remote_esp_wifi_get_mode(wifi_mode_t *mode); +esp_err_t remote_esp_wifi_set_config(wifi_interface_t ifx, wifi_config_t *conf); +esp_err_t remote_esp_wifi_get_config(wifi_interface_t interface, wifi_config_t *conf); +esp_err_t remote_esp_wifi_start(void); +esp_err_t remote_esp_wifi_stop(void); +esp_err_t remote_esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]); +esp_err_t remote_esp_wifi_set_mac(wifi_interface_t ifx, const uint8_t mac[6]); +esp_err_t remote_esp_wifi_scan_start(const wifi_scan_config_t *config, bool block); +esp_err_t remote_esp_wifi_scan_stop(void); +esp_err_t remote_esp_wifi_scan_get_ap_num(uint16_t *number); +esp_err_t remote_esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records); +esp_err_t remote_esp_wifi_clear_ap_list(void); +esp_err_t remote_esp_wifi_restore(void); +esp_err_t remote_esp_wifi_clear_fast_connect(void); +esp_err_t remote_esp_wifi_deauth_sta(uint16_t aid); +esp_err_t remote_esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info); +esp_err_t remote_esp_wifi_set_ps(wifi_ps_type_t type); +esp_err_t remote_esp_wifi_get_ps(wifi_ps_type_t *type); +esp_err_t remote_esp_wifi_set_storage(wifi_storage_t storage); +esp_err_t remote_esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw); +esp_err_t remote_esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw); +esp_err_t remote_esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second); +esp_err_t remote_esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second); +esp_err_t remote_esp_wifi_set_country_code(const char *country, bool ieee80211d_enabled); +esp_err_t remote_esp_wifi_get_country_code(char *country); +esp_err_t remote_esp_wifi_set_country(const wifi_country_t *country); +esp_err_t remote_esp_wifi_get_country(wifi_country_t *country); +esp_err_t remote_esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta); +esp_err_t remote_esp_wifi_ap_get_sta_aid(const uint8_t mac[6], uint16_t *aid); +esp_err_t remote_esp_wifi_sta_get_rssi(int *rssi); +esp_err_t remote_esp_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap); +esp_err_t remote_esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap); + + +// TODO: Move this to private include +// Private API +esp_err_t remote_esp_wifi_init_slave(void); + +// handling channels +esp_err_t esp_wifi_remote_channel_rx(void *h, void *buffer, void *buff_to_free, size_t len); +esp_err_t esp_wifi_remote_channel_set(wifi_interface_t ifx, void *h, esp_remote_channel_tx_fn_t tx_cb); +esp_err_t esp_wifi_remote_rpc_channel_rx(void *h, void *buffer, size_t len); +esp_err_t esp_wifi_remote_rpc_channel_set(void *h, esp_remote_channel_tx_fn_t tx_cb); diff --git a/components/esp_wifi_remote/wifi_remote_init.c b/components/esp_wifi_remote/wifi_remote_init.c new file mode 100644 index 0000000000..77be4069a5 --- /dev/null +++ b/components/esp_wifi_remote/wifi_remote_init.c @@ -0,0 +1,44 @@ +/* + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "esp_err.h" +#include "esp_log.h" +#include "esp_hosted_api.h" +#include "esp_wifi_remote.h" +const char *TAG = "esp_remote_wifi_init"; + +esp_err_t remote_esp_wifi_init_slave(void) +{ + ESP_LOGI(TAG, "** %s **", __func__); +#if 0 + if (esp_hosted_setup() != ESP_OK) { + return ESP_FAIL; + } +#endif + esp_remote_channel_tx_fn_t tx_cb; + esp_remote_channel_t ch; + + // Add an RPC channel with default config (i.e. secure=true) + struct esp_remote_channel_config config = ESP_HOSTED_CHANNEL_CONFIG_DEFAULT(); + config.if_type = ESP_SERIAL_IF; + //TODO: add rpc channel from here +//ch = esp_hosted_add_channel(&config, &tx_cb, esp_wifi_remote_rpc_channel_rx); +// esp_wifi_remote_rpc_channel_set(ch, tx_cb); + + // Add two other channels for the two WiFi interfaces (STA, softAP) in plain text + config.secure = false; + config.if_type = ESP_STA_IF; + ch = esp_hosted_add_channel(&config, &tx_cb, esp_wifi_remote_channel_rx); + esp_wifi_remote_channel_set(WIFI_IF_STA, ch, tx_cb); + + + config.secure = false; + config.if_type = ESP_AP_IF; + ch = esp_hosted_add_channel(&config, &tx_cb, esp_wifi_remote_channel_rx); + esp_wifi_remote_channel_set(WIFI_IF_AP, ch, tx_cb); + + return ESP_OK; +} diff --git a/esp_wifi_remote/wifi_remote_net.c b/components/esp_wifi_remote/wifi_remote_net.c similarity index 64% rename from esp_wifi_remote/wifi_remote_net.c rename to components/esp_wifi_remote/wifi_remote_net.c index b849cd8728..5bc3ec0cb0 100644 --- a/esp_wifi_remote/wifi_remote_net.c +++ b/components/esp_wifi_remote/wifi_remote_net.c @@ -1,31 +1,34 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ -#include "esp_wifi.h" #include #include "esp_err.h" -#include +#include "esp_wifi_remote.h" +#include "esp_log.h" #define CHANNELS 2 -static esp_hosted_channel_fn_t s_tx_cb[CHANNELS]; -static esp_hosted_channel_t *s_channel[CHANNELS]; +static esp_remote_channel_tx_fn_t s_tx_cb[CHANNELS]; +static esp_remote_channel_t s_channel[CHANNELS]; static wifi_rxcb_t s_rx_fn[CHANNELS]; -esp_err_t esp_wifi_remote_channel_rx(void *h, void *buffer, size_t len) +esp_err_t esp_wifi_remote_channel_rx(void *h, void *buffer, void *buff_to_free, size_t len) { + assert(h); if (h == s_channel[0]) { - return s_rx_fn[0](buffer, len, buffer); + assert(s_rx_fn[0]); + return s_rx_fn[0](buffer, len, buff_to_free); } if (h == s_channel[1]) { - return s_rx_fn[1](buffer, len, buffer); + assert(s_rx_fn[1]); + return s_rx_fn[1](buffer, len, buff_to_free); } return ESP_FAIL; } -esp_err_t esp_wifi_remote_channel_set(wifi_interface_t ifx, void *h, esp_err_t (*tx_cb)(void *, void *, size_t)) +esp_err_t esp_wifi_remote_channel_set(wifi_interface_t ifx, void *h, esp_remote_channel_tx_fn_t tx_cb) { if (ifx == WIFI_IF_STA) { s_channel[0] = h; @@ -51,14 +54,17 @@ esp_err_t esp_wifi_internal_reg_netstack_buf_cb(wifi_netstack_buf_ref_cb_t ref, return ESP_OK; } -void esp_wifi_internal_free_rx_buffer(void* buffer) +void esp_wifi_internal_free_rx_buffer(void *buffer) { -// free(buffer); + if (buffer) { + free(buffer); + } } int esp_wifi_internal_tx(wifi_interface_t ifx, void *buffer, uint16_t len) { if (ifx == WIFI_IF_STA) { + /* TODO: If not needed, remove arg3 */ return s_tx_cb[0](s_channel[0], buffer, len); } if (ifx == WIFI_IF_AP) { @@ -71,6 +77,7 @@ int esp_wifi_internal_tx(wifi_interface_t ifx, void *buffer, uint16_t len) esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn) { if (ifx == WIFI_IF_STA) { + ESP_LOGI("esp_wifi_remote", "%s: sta: %p", __func__, fn); s_rx_fn[0] = fn; return ESP_OK; } diff --git a/components/esp_wifi_remote/wifi_remote_rpc.c b/components/esp_wifi_remote/wifi_remote_rpc.c new file mode 100644 index 0000000000..5f2494dce7 --- /dev/null +++ b/components/esp_wifi_remote/wifi_remote_rpc.c @@ -0,0 +1,232 @@ +/* + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include "esp_log.h" +#include "esp_err.h" +#include "esp_wifi.h" +#include "esp_wifi_remote.h" +#include "esp_hosted_api.h" + +static esp_remote_channel_t s_params_channel; +static esp_remote_channel_tx_fn_t s_params_tx; +static wifi_config_t s_last_wifi_conf; + +esp_err_t esp_wifi_remote_rpc_channel_rx(void *h, void *buffer, size_t len) +{ + if (h == s_params_channel && len == sizeof(s_last_wifi_conf)) { + memcpy(&s_last_wifi_conf, buffer, len); // TODO: use queue + return ESP_OK; + } + return ESP_FAIL; +} + +esp_err_t esp_wifi_remote_rpc_channel_set(void *h, esp_err_t (*tx_cb)(void *, void *, size_t)) +{ + s_params_channel = h; + s_params_tx = tx_cb; + return ESP_OK; +} + +esp_err_t remote_esp_wifi_connect(void) +{ + return esp_hosted_wifi_connect(); +} + +esp_err_t remote_esp_wifi_disconnect(void) +{ + return esp_hosted_wifi_disconnect(); +} + +esp_err_t remote_esp_wifi_init(const wifi_init_config_t *config) +{ + if (remote_esp_wifi_init_slave() != ESP_OK) { + return ESP_FAIL; + } + return esp_hosted_wifi_init(config); +} + +esp_err_t remote_esp_wifi_deinit(void) +{ + return esp_hosted_wifi_deinit(); +} + +esp_err_t remote_esp_wifi_set_mode(wifi_mode_t mode) +{ + return esp_hosted_wifi_set_mode(mode); +} + +esp_err_t remote_esp_wifi_get_mode(wifi_mode_t *mode) +{ + return esp_hosted_wifi_get_mode(mode); +} + +esp_err_t remote_esp_wifi_set_config(wifi_interface_t interface, wifi_config_t *conf) +{ +#if 0 + uint8_t *param = (uint8_t *)conf; + uint32_t checksum = 0; // TODO: generate a random number and add it to both + for (int i = 0; i < sizeof(wifi_config_t); ++i) { + checksum += param[i]; + } + + // transmit the sensitive parameters over a secure channel +// s_params_tx(s_params_channel, param, sizeof(wifi_config_t)); + + // add only a checksum to the RPC + return esp_hosted_wifi_set_config(interface, checksum); +#endif + return esp_hosted_wifi_set_config(interface, conf); +} + +esp_err_t remote_esp_wifi_get_config(wifi_interface_t interface, wifi_config_t *conf) +{ + return esp_hosted_wifi_get_config(interface, conf); +} + +esp_err_t remote_esp_wifi_start(void) +{ + return esp_hosted_wifi_start(); +} + +esp_err_t remote_esp_wifi_stop(void) +{ + return esp_hosted_wifi_stop(); +} + +esp_err_t remote_esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]) +{ + return esp_hosted_wifi_get_mac(ifx, mac); +} + +esp_err_t remote_esp_wifi_set_mac(wifi_interface_t ifx, const uint8_t mac[6]) +{ + return esp_hosted_wifi_set_mac(ifx, mac); +} + +esp_err_t remote_esp_wifi_scan_start(const wifi_scan_config_t *config, bool block) +{ + return esp_hosted_wifi_scan_start(config, block); +} + +esp_err_t remote_esp_wifi_scan_stop(void) +{ + return esp_hosted_wifi_scan_stop(); +} + +esp_err_t remote_esp_wifi_scan_get_ap_num(uint16_t *number) +{ + return esp_hosted_wifi_scan_get_ap_num(number); +} + +esp_err_t remote_esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records) +{ + return esp_hosted_wifi_scan_get_ap_records(number, ap_records); +} + +esp_err_t remote_esp_wifi_clear_ap_list(void) +{ + return esp_hosted_wifi_clear_ap_list(); +} + +esp_err_t remote_esp_wifi_restore(void) +{ + return esp_hosted_wifi_restore(); +} + +esp_err_t remote_esp_wifi_clear_fast_connect(void) +{ + return esp_hosted_wifi_clear_fast_connect(); +} + +esp_err_t remote_esp_wifi_deauth_sta(uint16_t aid) +{ + return esp_hosted_wifi_deauth_sta(aid); +} + +esp_err_t remote_esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info) +{ + return esp_hosted_wifi_sta_get_ap_info(ap_info); +} + +esp_err_t remote_esp_wifi_set_ps(wifi_ps_type_t type) +{ + return esp_hosted_wifi_set_ps(type); +} + +esp_err_t remote_esp_wifi_get_ps(wifi_ps_type_t *type) +{ + return esp_hosted_wifi_get_ps(type); +} + +esp_err_t remote_esp_wifi_set_storage(wifi_storage_t storage) +{ + return esp_hosted_wifi_set_storage(storage); +} + +esp_err_t remote_esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw) +{ + return esp_hosted_wifi_set_bandwidth(ifx, bw); +} + +esp_err_t remote_esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw) +{ + return esp_hosted_wifi_get_bandwidth(ifx, bw); +} + +esp_err_t remote_esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second) +{ + return esp_hosted_wifi_set_channel(primary, second); +} + +esp_err_t remote_esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second) +{ + return esp_hosted_wifi_get_channel(primary, second); +} + +esp_err_t remote_esp_wifi_set_country_code(const char *country, bool ieee80211d_enabled) +{ + return esp_hosted_wifi_set_country_code(country, ieee80211d_enabled); +} + +esp_err_t remote_esp_wifi_get_country_code(char *country) +{ + return esp_hosted_wifi_get_country_code(country); +} + +esp_err_t remote_esp_wifi_set_country(const wifi_country_t *country) +{ + return esp_hosted_wifi_set_country(country); +} + +esp_err_t remote_esp_wifi_get_country(wifi_country_t *country) +{ + return esp_hosted_wifi_get_country(country); +} + +esp_err_t remote_esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta) +{ + return esp_hosted_wifi_ap_get_sta_list(sta); +} + +esp_err_t remote_esp_wifi_ap_get_sta_aid(const uint8_t mac[6], uint16_t *aid) +{ + return esp_hosted_wifi_ap_get_sta_aid(mac, aid); +} + +esp_err_t remote_esp_wifi_sta_get_rssi(int *rssi) +{ + return esp_hosted_wifi_sta_get_rssi(rssi); +} + +esp_err_t remote_esp_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap) +{ + return esp_hosted_wifi_set_protocol(ifx, protocol_bitmap); +} + +esp_err_t remote_esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap) +{ + return esp_hosted_wifi_get_protocol(ifx, protocol_bitmap); +} diff --git a/esp_wifi_remote/esp_wifi_remote.c b/esp_wifi_remote/esp_wifi_remote.c deleted file mode 100644 index 4c2347d0df..0000000000 --- a/esp_wifi_remote/esp_wifi_remote.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "esp_wifi.h" -#include "esp_private/wifi_os_adapter.h" -#include "esp_log.h" -#include "esp_wifi_remote.h" - -#define WEAK __attribute__((weak)) - -WEAK ESP_EVENT_DEFINE_BASE(WIFI_EVENT); - -WEAK wifi_osi_funcs_t g_wifi_osi_funcs; -WEAK const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs; -WEAK uint64_t g_wifi_feature_caps; - -WEAK esp_err_t esp_wifi_connect(void) -{ - return remote_esp_wifi_connect(); -} - -WEAK esp_err_t esp_wifi_init(const wifi_init_config_t *config) -{ - return remote_esp_wifi_init(config); -} - -WEAK esp_err_t esp_wifi_set_mode(wifi_mode_t mode) -{ - return remote_esp_wifi_set_mode(mode); -} - -WEAK esp_err_t esp_wifi_set_config(wifi_interface_t interface, wifi_config_t *conf) -{ - return remote_esp_wifi_set_config(interface, conf); -} - -WEAK esp_err_t esp_wifi_start(void) -{ - return remote_esp_wifi_start(); -} - -WEAK esp_err_t esp_wifi_stop(void) -{ - return remote_esp_wifi_stop(); -} - -WEAK esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]) -{ - return remote_esp_wifi_get_mac(ifx, mac); -} diff --git a/esp_wifi_remote/idf_component.yml b/esp_wifi_remote/idf_component.yml deleted file mode 100644 index f865f123af..0000000000 --- a/esp_wifi_remote/idf_component.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: "0.0.5" -dependencies: - esp_hosted_preview: - version: "*" -# override_path: ${PREVIEW_PATH}/components/esp_hosted_preview - service_url: "https://components-staging.espressif.com/api" diff --git a/esp_wifi_remote/include/esp_wifi_remote.h b/esp_wifi_remote/include/esp_wifi_remote.h deleted file mode 100644 index d324996107..0000000000 --- a/esp_wifi_remote/include/esp_wifi_remote.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#pragma once -#include "esp_wifi.h" - -// Public API -esp_err_t remote_esp_wifi_connect(void); -esp_err_t remote_esp_wifi_init(const wifi_init_config_t *config); -esp_err_t remote_esp_wifi_set_mode(wifi_mode_t mode); -esp_err_t remote_esp_wifi_set_config(wifi_interface_t ifx, wifi_config_t *conf); -esp_err_t remote_esp_wifi_start(void); -esp_err_t remote_esp_wifi_stop(void); -esp_err_t remote_esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]); - - -// TODO: Move this to private include -// Private API -esp_err_t remote_esp_wifi_init_slave(void); - -// handling channels -esp_err_t esp_wifi_remote_channel_rx(void *h, void *buffer, size_t len); -esp_err_t esp_wifi_remote_channel_set(wifi_interface_t ifx, void *h, esp_err_t (*tx_cb)(void *, void *, size_t)); -esp_err_t esp_wifi_remote_rpc_channel_rx(void *h, void *buffer, size_t len); -esp_err_t esp_wifi_remote_rpc_channel_set(void *h, esp_err_t (*tx_cb)(void *, void *, size_t)); diff --git a/esp_wifi_remote/wifi_remote_init.c b/esp_wifi_remote/wifi_remote_init.c deleted file mode 100644 index b0ec6ba502..0000000000 --- a/esp_wifi_remote/wifi_remote_init.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "esp_err.h" -#include -#include "esp_wifi_remote.h" - -esp_err_t remote_esp_wifi_init_slave(void) -{ - if (esp_hosted_setup() != ESP_OK) { - return ESP_FAIL; - } - esp_hosted_channel_fn_t tx_cb; - esp_hosted_channel_t * ch; - - // Add an RPC channel with default config (i.e. secure=true) - esp_hosted_channel_config_t config = ESP_HOSTED_CHANNEL_CONFIG_DEFAULT(); - ch = esp_hosted_add_channel(&config, &tx_cb, esp_wifi_remote_rpc_channel_rx); - esp_wifi_remote_rpc_channel_set(ch, tx_cb); - - // Add two other channels for the two WiFi interfaces (STA, softAP) in plain text - config.secure = false; - ch = esp_hosted_add_channel(&config, &tx_cb, esp_wifi_remote_channel_rx); // TODO: add checks for `ch` and `tx_cb` - esp_wifi_remote_channel_set(WIFI_IF_STA, ch, tx_cb); - ch = esp_hosted_add_channel(&config, &tx_cb, esp_wifi_remote_channel_rx); - esp_wifi_remote_channel_set(WIFI_IF_AP, ch, tx_cb); - - return ESP_OK; -} diff --git a/esp_wifi_remote/wifi_remote_rpc.c b/esp_wifi_remote/wifi_remote_rpc.c deleted file mode 100644 index cb27ded88a..0000000000 --- a/esp_wifi_remote/wifi_remote_rpc.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include -#include "esp_log.h" -#include "esp_err.h" -#include "esp_wifi.h" -#include "esp_wifi_remote.h" -#include "esp_hosted_api.h" - -static esp_hosted_channel_t *s_params_channel; -static esp_hosted_channel_fn_t s_params_tx; -static wifi_config_t s_last_wifi_conf; - -esp_err_t esp_wifi_remote_rpc_channel_rx(void *h, void *buffer, size_t len) -{ - if (h == s_params_channel && len == sizeof(s_last_wifi_conf)) { - memcpy(&s_last_wifi_conf, buffer, len); // TODO: use queue - return ESP_OK; - } - return ESP_FAIL; -} - -esp_err_t esp_wifi_remote_rpc_channel_set(void *h, esp_err_t (*tx_cb)(void *, void *, size_t)) -{ - s_params_channel =h; - s_params_tx = tx_cb; - return ESP_OK; -} - -esp_err_t remote_esp_wifi_connect(void) -{ - return esp_hosted_wifi_connect(); -} - -esp_err_t remote_esp_wifi_init(const wifi_init_config_t *config) -{ - if (remote_esp_wifi_init_slave() != ESP_OK) { - return ESP_FAIL; - } - return esp_hosted_wifi_init(config); -} - -esp_err_t remote_esp_wifi_set_mode(wifi_mode_t mode) -{ - return esp_hosted_wifi_set_mode(mode); -} - -esp_err_t remote_esp_wifi_set_config(wifi_interface_t interface, wifi_config_t *conf) -{ - uint8_t *param = (uint8_t*)conf; - uint32_t checksum = 0; // TODO: generate a random number and add it to both - for (int i=0; i