-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wifi_remote): Add example with esp_hosted=OFF (using eppp)
- Loading branch information
1 parent
75e2a37
commit 5a91f52
Showing
25 changed files
with
1,003 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(¶ms.conf, conf, sizeof(wifi_config_t)); | ||
if (s_rpc.send(SET_CONFIG, ¶ms) != 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
44
components/esp_wifi_remote/eppp/wifi_remote_rpc_client.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.