Skip to content

Commit cbdedb7

Browse files
authored
Merge pull request #72 from david-cermak/feat/eppp_host_networking
[eppp]: Add support for host side networking
2 parents 5d307cc + 741316d commit cbdedb7

File tree

6 files changed

+98
-5
lines changed

6 files changed

+98
-5
lines changed

components/wifi_remote_over_eppp/.cz.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ commitizen:
33
bump_message: 'bump(eppp): $current_version -> $new_version'
44
pre_bump_hooks: python ../../ci/changelog.py wifi_remote_over_eppp
55
tag_format: wifi_rmt_eppp-v$version
6-
version: 0.1.4
6+
version: 0.2.0
77
version_files:
88
- idf_component.yml

components/wifi_remote_over_eppp/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## [0.2.0](https://github.com/espressif/esp-wifi-remote/commits/wifi_rmt_eppp-v0.2.0)
4+
5+
### Features
6+
7+
- Support host networking with EPPP channels ([f62ca01](https://github.com/espressif/esp-wifi-remote/commit/f62ca01))
8+
9+
### Bug Fixes
10+
11+
- Make server CN configurable ([e5d3fb2](https://github.com/espressif/esp-wifi-remote/commit/e5d3fb2))
12+
- Update READMEs with latest description ([798e6f0](https://github.com/espressif/esp-wifi-remote/commit/798e6f0))
13+
314
## [0.1.4](https://github.com/espressif/esp-wifi-remote/commits/wifi_rmt_eppp-v0.1.4)
415

516
### Bug Fixes

components/wifi_remote_over_eppp/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,20 @@ if ESP_WIFI_REMOTE_LIBRARY_EPPP
7676
SPI frequency in Hz.
7777
endif
7878

79+
config WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
80+
bool "Enable host side netif"
81+
default n
82+
select EPPP_LINK_CHANNELS_SUPPORT
83+
help
84+
Enable host side netifwork interface (Remote WiFi station) that uses EPPP channels
85+
for sending and receiving 802.3 frames over EPPP.
86+
Enable this if host behind NAT would cause issues.
87+
Downside is that the slave side does not have a direct access to the internet.
88+
7989
config WIFI_RMT_OVER_EPPP_NETIF_PRIORITY
8090
int "Routing priority of eppp netif"
8191
default 100
92+
default 50 if WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
8293
range 0 256
8394
help
8495
Set the priority of the wifi-remote netif.

components/wifi_remote_over_eppp/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 0.1.4
1+
version: 0.2.0
22
url: https://github.com/espressif/esp-wifi-remote/components/wifi_remote_over_eppp
33
description: EPPP based implementation of wifi_remote APIs
44
license: Apache-2.0

components/wifi_remote_over_eppp/src/wifi_remote_rpc_client.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include "freertos/FreeRTOS.h"
1616
#include "freertos/event_groups.h"
1717
#include "wifi_remote_rpc_params.h"
18+
#ifdef CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
19+
#include "esp_wifi_remote.h"
20+
#endif
1821

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

@@ -118,6 +121,12 @@ class RpcInstance {
118121
esp_err_t init()
119122
{
120123
ESP_RETURN_ON_FALSE(netif = wifi_remote_eppp_init(EPPP_CLIENT), ESP_FAIL, TAG, "Failed to connect to EPPP server");
124+
125+
#ifdef CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
126+
ESP_RETURN_ON_ERROR(eppp_add_channels(netif, &channel_tx, channel_rx, this), TAG, "Failed to add EPPP channel");
127+
ESP_RETURN_ON_ERROR(esp_wifi_remote_channel_set(WIFI_IF_STA, (void*)this, wifi_remote_tx), TAG, "Failed to configure WiFi remote channel");
128+
#endif
129+
121130
ESP_RETURN_ON_ERROR(esp_event_handler_register(IP_EVENT, IP_EVENT_PPP_GOT_IP, got_ip, this), TAG, "Failed to register event");
122131
ESP_RETURN_ON_ERROR(sync.init(), TAG, "Failed to init sync primitives");
123132
ESP_RETURN_ON_ERROR(rpc.init(), TAG, "Failed to init RPC engine");
@@ -151,6 +160,7 @@ class RpcInstance {
151160
esp_err_t process_wifi_event(RpcHeader &header)
152161
{
153162
auto event_id = rpc.get_payload<int32_t>(api_id::WIFI_EVENT, header);
163+
ESP_LOGI(TAG, "Processing WiFi event with id %" PRIi32, event_id);
154164
ESP_RETURN_ON_ERROR(esp_event_post(WIFI_REMOTE_EVENT, event_id, nullptr, 0, 0), TAG, "Failed to post WiFi event");
155165
return ESP_OK;
156166
}
@@ -200,6 +210,22 @@ class RpcInstance {
200210
auto instance = static_cast<RpcInstance *>(ctx);
201211
instance->sync.notify(instance->sync.restart);
202212
}
213+
#ifdef CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
214+
static esp_err_t channel_rx(esp_netif_t *netif, int nr, void *buffer, size_t len)
215+
{
216+
auto instance = static_cast<RpcInstance *>(eppp_get_context(netif));
217+
return esp_wifi_remote_channel_rx(instance, buffer, nullptr, len);
218+
}
219+
static esp_err_t wifi_remote_tx(void *h, void *buffer, size_t len)
220+
{
221+
auto instance = static_cast<RpcInstance *>(h);
222+
if (instance->channel_tx) {
223+
return instance->channel_tx(instance->netif, 1, buffer, len);
224+
}
225+
return ESP_FAIL;
226+
}
227+
eppp_channel_fn_t channel_tx{nullptr};
228+
#endif // CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
203229
esp_netif_t *netif{nullptr};
204230
};
205231

components/wifi_remote_over_eppp/src/wifi_remote_rpc_server.cpp

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#include <netdb.h>
77
#include <memory>
8-
#include <cerrno>
98
#include <sys/socket.h>
109
#include "esp_log.h"
1110
#include "esp_check.h"
@@ -17,6 +16,9 @@
1716
#include "lwip/apps/snmp.h"
1817
#include "esp_vfs.h"
1918
#include "esp_vfs_eventfd.h"
19+
#ifdef CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
20+
#include "esp_private/wifi.h"
21+
#endif
2022

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

@@ -30,6 +32,10 @@ const unsigned char crt[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_WIFI_RMT_OVER
3032
const unsigned char key[] = "-----BEGIN PRIVATE KEY-----\n" CONFIG_WIFI_RMT_OVER_EPPP_SERVER_KEY "\n-----END PRIVATE KEY-----";
3133
// TODO: Add option to supply keys and certs via a global symbol (file)
3234

35+
#ifdef CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
36+
RpcInstance* get_instance();
37+
#endif
38+
3339
}
3440

3541
using namespace server;
@@ -109,9 +115,16 @@ class RpcInstance {
109115
esp_err_t init()
110116
{
111117
ESP_RETURN_ON_FALSE(netif = wifi_remote_eppp_init(EPPP_SERVER), ESP_FAIL, TAG, "Failed to init EPPP connection");
118+
#ifdef CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
119+
ESP_RETURN_ON_ERROR(eppp_add_channels(netif, &channel_tx, channel_rx, this), TAG, "Failed to add EPPP channel");
120+
#endif
121+
112122
ESP_RETURN_ON_ERROR(start_server(), TAG, "Failed to start RPC server");
113123
ESP_RETURN_ON_ERROR(rpc.init(), TAG, "Failed to init RPC engine");
124+
#ifndef CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
125+
// No need to NAPT for client (host) side networking
114126
ESP_RETURN_ON_ERROR(esp_netif_napt_enable(netif), TAG, "Failed to enable NAPT");
127+
#endif
115128
ESP_RETURN_ON_ERROR(sync.init(), TAG, "Failed to init event queue");
116129
ESP_RETURN_ON_ERROR(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, handler, this), TAG, "Failed to register event");
117130
ESP_RETURN_ON_ERROR(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, handler, this), TAG, "Failed to register event");
@@ -120,6 +133,26 @@ class RpcInstance {
120133
Sync sync;
121134
private:
122135
esp_netif_t *netif{nullptr};
136+
#ifdef CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
137+
bool started{false};
138+
eppp_channel_fn_t channel_tx{nullptr};
139+
static esp_err_t channel_rx(esp_netif_t *netif, int nr, void *buffer, size_t len)
140+
{
141+
if (get_instance()->started) {
142+
return esp_wifi_internal_tx(WIFI_IF_STA, buffer, len);
143+
}
144+
return ESP_OK;
145+
}
146+
static esp_err_t wifi_receive(void *buffer, uint16_t len, void *eb)
147+
{
148+
if (get_instance()->channel_tx) {
149+
auto ret = get_instance()->channel_tx(get_instance()->netif, 1, buffer, len);
150+
esp_wifi_internal_free_rx_buffer(eb);
151+
return ret;
152+
}
153+
return ESP_OK;
154+
}
155+
#endif
123156
static void task(void *ctx)
124157
{
125158
auto instance = static_cast<RpcInstance *>(ctx);
@@ -289,7 +322,11 @@ class RpcInstance {
289322
if (header.size != 0) {
290323
return ESP_FAIL;
291324
}
292-
325+
#ifdef CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
326+
esp_wifi_internal_reg_rxcb(WIFI_IF_STA, wifi_receive);
327+
esp_wifi_internal_reg_netstack_buf_cb(esp_netif_netstack_buf_ref, esp_netif_netstack_buf_free);
328+
started = true;
329+
#endif
293330
auto ret = esp_wifi_start();
294331
if (rpc.send(api_id::START, &ret) != ESP_OK) {
295332
return ESP_FAIL;
@@ -356,6 +393,14 @@ class RpcInstance {
356393

357394
namespace server {
358395
constinit RpcInstance instance;
396+
397+
#ifdef CONFIG_WIFI_RMT_OVER_EPPP_HOST_SIDE_NETIF
398+
// This is needed in wifi-callbacks which lack context param
399+
RpcInstance* get_instance()
400+
{
401+
return &server::instance;
402+
}
403+
#endif
359404
}
360405

361406
RpcInstance *RpcEngine::init_server()

0 commit comments

Comments
 (0)