Skip to content

Commit

Permalink
fix(wifi_remote): Add example with esp_hosted=OFF (using eppp)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cermak committed Mar 25, 2024
1 parent 75e2a37 commit 5a91f52
Show file tree
Hide file tree
Showing 25 changed files with 1,003 additions and 4 deletions.
16 changes: 14 additions & 2 deletions components/esp_wifi_remote/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@ if(NOT CONFIG_ESP_WIFI_ENABLED)
set(src_wifi_is_remote esp_wifi_remote.c esp_wifi_with_remote.c)
endif()

if(CONFIG_ESP_WIFI_REMOTE_LIBRARY_HOSTED)
set(src_wifi_uses_esp_hosted wifi_remote_init.c wifi_remote_rpc.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} esp_wifi_remote_weak.c
SRCS wifi_remote_net.c
esp_wifi_remote_weak.c
eppp/wifi_remote_impl.cpp
eppp/wifi_remote_rpc_client.cpp
eppp/wifi_remote_rpc_server.cpp
eppp/eppp_init.c
${src_wifi_uses_esp_hosted}
${src_wifi_is_remote}
PRIV_INCLUDE_DIRS eppp
REQUIRES esp_event esp_netif
PRIV_REQUIRES esp_wifi esp_hosted)
PRIV_REQUIRES esp_wifi esp-tls)
1 change: 1 addition & 0 deletions components/esp_wifi_remote/Kconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is auto-generated
menu "Wi-Fi Remote"
orsource "./Kconfig.soc_wifi_caps.in"
orsource "./Kconfig.rpc.lib"

config ESP_WIFI_STATIC_RX_BUFFER_NUM
int "Max number of WiFi static RX buffers"
Expand Down
27 changes: 27 additions & 0 deletions components/esp_wifi_remote/eppp/eppp_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_log.h"
#include "esp_tls.h"
#include "esp_wifi.h"
//#include "wifi_remote_rpc_impl.hpp"
#include "eppp_link.h"

esp_netif_t *wifi_remote_eppp_init(eppp_type_t role)
{
if (role == EPPP_SERVER) {
eppp_config_t config = EPPP_DEFAULT_SERVER_CONFIG();
config.transport = EPPP_TRANSPORT_UART;
config.uart.tx_io = 22; // d2
config.uart.rx_io = 23; // d3
return eppp_open(role, &config, portMAX_DELAY);
} else {
eppp_config_t config = EPPP_DEFAULT_CLIENT_CONFIG();
config.transport = EPPP_TRANSPORT_UART;
config.uart.tx_io = 17;
config.uart.rx_io = 16;
return eppp_open(role, &config, portMAX_DELAY);
}
}
166 changes: 166 additions & 0 deletions components/esp_wifi_remote/eppp/wifi_remote_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_log.h"
#include "esp_tls.h"
#include "esp_wifi.h"
#include "wifi_remote_rpc_impl.hpp"
#include "eppp_link.h"

using namespace eppp_rpc;

static RpcEngine s_rpc(eppp_rpc::role::CLIENT);
static esp_netif_t *s_ppp_netif;
static const char *TAG = "rpc_impl";

extern "C" esp_netif_t *wifi_remote_eppp_init(eppp_type_t role);

extern "C" esp_err_t esp_wifi_remote_init(const wifi_init_config_t *config)
{
s_ppp_netif = wifi_remote_eppp_init(EPPP_CLIENT);
if (s_ppp_netif == nullptr) {
return ESP_FAIL;
}
s_rpc.init();
if (s_rpc.send(INIT, config) != ESP_OK) {
return ESP_FAIL;
}
auto header = s_rpc.get_header();
return s_rpc.get_payload<esp_err_t>(INIT, header);
}

#if 0


union wifi_config_t2 {
wifi_ap_config_t ap; /**< configuration of AP */
wifi_sta_config_t sta; /**< configuration of STA */
wifi_nan_config_t nan; /**< configuration of NAN */
void marshall(int type) {

}
} ;

struct marshaller {
template<typename T> uint8_t *marshall(uint8_t *ptr, T *t)
{
memcpy(ptr, t, sizeof(T));
ptr += sizeof(T);
return ptr;
}
};

struct esp_wifi_remote_config {
// struct wifi_interface_t {
// wifi_interface_t *ptr;
// } p1;
struct wifi_interface_t : public marshaller {
::wifi_interface_t *interface;
uint8_t *marshall(uint8_t *ptr)
{
return marshaller::marshall(ptr, (uint32_t *)interface);
}
// memcpy(ptr, interface, sizeof(*interface)); return ptr+sizeof(*interface); }
} wifi_interface_t;

// wifi_config_t2 *conf;
struct wifi_config_t2 {
::wifi_config_t2 *config;
struct wifi_ap_config_t {
::wifi_ap_config_t *ap;
struct wifi_pmf_config_t {
::wifi_pmf_config_t *pmf_cfg;
uint8_t *marshall(uint8_t *ptr)
{
if (pmf_cfg) {
*ptr = pmf_cfg->capable;
ptr++;
ptr++;
} return ptr;
}
} wifi_pmf_config_t;
uint8_t *marshall(uint8_t *ptr)
{
if (ap) {
marshar_true();
*ptr = ap->channel; ptr++; // ...
ptr = wifi_pmf_config_t.marshall(ptr);
} else {
marshall_false();
}
return ptr;
}
} wifi_ap_config_t;
uint8_t *marshall(uint8_t *ptr)
{
// nothing
ptr = wifi_ap_config_t.marshall(ptr);
// ptr = wifi_sta_config_t.marshall(ptr);
return ptr;
}
} wifi_config_t2_;

uint8_t *marshall(uint8_t *ptr)
{
ptr = wifi_interface_t.marshall(ptr);
ptr = wifi_config_t2_.marshall(ptr);
return ptr;
}
};
#endif

#if 0

extern "C" esp_err_t esp_wifi_remote_set_config(wifi_interface_t interface, wifi_config_t *conf)
{
esp_wifi_remote_config params =
esp_wifi_remote_config params = {
.wifi_interface_t = { .interface = &interface },
.wifi_config_t2_ = {
.config = nullptr,
.wifi_ap_config_t = {
.ap = &conf->ap,
.wifi_pmf_config_t = {
.pmf_cfg = &conf->ap.pmf_cfg,
}
}
}
}; // { .interface = &interface, .conf = {} };

esp_wifi_remote_config params2 = {
.wifi_interface_t = { .interface = interface },
.wifi_config_t2_ = {
.config = conf,
.wifi_ap_config_t = {
.ap = true,
.wifi_pmf_config_t = {
.pmf_cfg = true,
}
}
.wifi_sta_config_t = {
.ap = false,
.wifi_pmf_config_t = {
.pmf_cfg = false,
}
}

}
}; // { .interface = &interface, .conf = {} };

params.wifi_interface_t.interface = &interface;
params.wifi_config_t2_.config = nullptr;
params.wifi_config_t2_.wifi_ap_config_t.ap = &conf->ap;
params.wifi_config_t2_.wifi_ap_config_t.wifi_pmf_config_t.pmf_cfg = &conf->ap.pmf_cfg;
params.marshall(nullptr);
// params.wifi_config_t2.ap = nullptr;
// params.marshall(2);
// memcpy(&params.conf, conf, sizeof(wifi_config_t));
if (s_rpc.send(SET_CONFIG, &params) != ESP_OK) {
return ESP_FAIL;
}
auto header = s_rpc.get_header();
return s_rpc.get_payload<esp_err_t>(SET_CONFIG, header);
}
#endif
44 changes: 44 additions & 0 deletions components/esp_wifi_remote/eppp/wifi_remote_rpc_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_log.h"
#include "esp_tls.h"
#include "esp_wifi.h"
#include <sys/socket.h>
#include <netdb.h>
#include <memory>
#include "wifi_remote_rpc_impl.hpp"
#include "esp_wifi_remote.h"

#define PORT 3333

using namespace eppp_rpc;
static const char *TAG = "rpc_client";

esp_err_t RpcEngine::init_client()
{
esp_err_t ret = ESP_OK;
const char host[] = "192.168.11.1";
int port = 3333;
esp_tls_cfg_t cfg = {};
cfg.skip_common_name = true;

tls_ = esp_tls_init();
if (!tls_) {
ESP_LOGE(TAG, "Failed to allocate esp_tls handle!");
ret = ESP_FAIL;
goto exit;
}
if (esp_tls_conn_new_sync(host, strlen(host), port, &cfg, tls_) <= 0) {
ESP_LOGE(TAG, "Failed to open a new connection");
ret = ESP_FAIL;
goto exit;
}
return ESP_OK;
exit:
esp_tls_conn_destroy(tls_);
tls_ = nullptr;
return ret;
}
Loading

0 comments on commit 5a91f52

Please sign in to comment.