Skip to content

Commit 049fe6b

Browse files
committed
fix(eppp): Fixup UART transport
1 parent a264316 commit 049fe6b

File tree

11 files changed

+360
-367
lines changed

11 files changed

+360
-367
lines changed

components/eppp_link/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ if(CONFIG_EPPP_LINK_DEVICE_SDIO)
2020
set(transport_src eppp_sdio.c eppp_sdio_slave.c eppp_sdio_host.c)
2121
endif()
2222

23-
idf_component_register(SRCS eppp_link.c ${transport_src} eppp_slip.c
23+
if(NOT CONFIG_EPPP_LINK_USES_PPP)
24+
set(netif_src eppp_netif_tun.c)
25+
endif()
26+
27+
idf_component_register(SRCS eppp_link.c ${transport_src} ${netif_src}
2428
INCLUDE_DIRS "include"
2529
PRIV_REQUIRES esp_netif esp_timer esp_eth ${driver_deps})
2630

components/eppp_link/Kconfig

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
menu "eppp_link"
22

3-
config EPPP_LINK_USES_LWIP
4-
bool
5-
default "y"
3+
config EPPP_LINK_USES_PPP
4+
bool "Use PPP network interface"
5+
default "n"
66
select LWIP_PPP_SUPPORT
77
select LWIP_PPP_SERVER_SUPPORT
8+
help
9+
Enable this option to use PPP network interface.
10+
This is useful when pairing with another PPP device,
11+
e.g. pppd service on Linux.
12+
By default EPPP_LINK uses plain TUN interface,
13+
relying on transports to split on packet boundaries.
814

915
choice EPPP_LINK_DEVICE
1016
prompt "Choose PPP device"

components/eppp_link/eppp_link.c

Lines changed: 44 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,7 @@ static const char *TAG = "eppp_link";
3434
static int s_retry_num = 0;
3535
static int s_eppp_netif_count = 0; // used as a suffix for the netif key
3636

37-
#if CONFIG_EPPP_LINK_DEVICE_SDIO
38-
39-
#elif CONFIG_EPPP_LINK_DEVICE_ETH
40-
41-
#else
42-
#endif
43-
44-
static void netif_deinit(esp_netif_t *netif)
37+
void eppp_netif_deinit(esp_netif_t *netif)
4538
{
4639
if (netif == NULL) {
4740
return;
@@ -52,47 +45,43 @@ static void netif_deinit(esp_netif_t *netif)
5245
}
5346
}
5447

55-
extern esp_netif_netstack_config_t *netstack_default_slip;
48+
#ifdef CONFIG_EPPP_LINK_USES_PPP
49+
#define NETSTACK_CONFIG() ESP_NETIF_NETSTACK_DEFAULT_PPP
50+
#else
51+
#define NETSTACK_CONFIG() g_eppp_netif_config_tun
52+
extern esp_netif_netstack_config_t *g_eppp_netif_config_tun;
5653
#define ESP_NETIF_INHERENT_DEFAULT_SLIP() \
5754
{ \
5855
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
5956
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \
6057
.flags = ESP_NETIF_FLAG_EVENT_IP_MODIFIED, \
6158
.get_ip_event = IP_EVENT_PPP_GOT_IP, \
6259
.lost_ip_event = IP_EVENT_PPP_LOST_IP, \
63-
.if_key = "SLP_DEF", \
64-
.if_desc = "slip", \
60+
.if_key = "EPPP_TUN", \
61+
.if_desc = "eppp", \
6562
.route_prio = 1, \
6663
.bridge_info = NULL \
6764
};
65+
#endif // CONFIG_EPPP_LINK_USES_PPP
6866

69-
static esp_netif_t *netif_init(eppp_type_t role, eppp_transport_handle_t h, eppp_config_t *eppp_config)
67+
esp_netif_t *eppp_netif_init(eppp_type_t role, eppp_transport_handle_t h, eppp_config_t *eppp_config)
7068
{
7169
if (s_eppp_netif_count > 9) { // Limit to max 10 netifs, since we use "EPPPx" as the unique key (where x is 0-9)
7270
ESP_LOGE(TAG, "Cannot create more than 10 instances");
7371
return NULL;
7472
}
7573

7674
h->role = role;
77-
// esp_netif_driver_ifconfig_t driver_cfg = {
78-
// .handle = h,
79-
//#if CONFIG_EPPP_LINK_DEVICE_SDIO
80-
// .transmit = role == EPPP_CLIENT ? eppp_sdio_host_tx : eppp_sdio_slave_tx,
81-
//#elif CONFIG_EPPP_LINK_DEVICE_ETH
82-
// .transmit = eppp_transport_tx,
83-
//#else
84-
// .transmit = transmit,
85-
//#endif
86-
// };
87-
// const esp_netif_driver_ifconfig_t *ppp_driver_cfg = &driver_cfg;
75+
#ifdef CONFIG_EPPP_LINK_USES_PPP
76+
esp_netif_inherent_config_t base_netif_cfg = ESP_NETIF_INHERENT_DEFAULT_PPP();
77+
#else
78+
esp_netif_inherent_config_t base_netif_cfg = ESP_NETIF_INHERENT_DEFAULT_SLIP();
8879
esp_netif_ip_info_t slip_ip4 = {};
8980
slip_ip4.ip.addr = eppp_config->ppp.our_ip4_addr.addr;
9081
slip_ip4.gw.addr = eppp_config->ppp.their_ip4_addr.addr;
9182
slip_ip4.netmask.addr = ESP_IP4TOADDR(255, 255, 255, 0);
92-
93-
esp_netif_inherent_config_t base_netif_cfg = ESP_NETIF_INHERENT_DEFAULT_SLIP();
9483
base_netif_cfg.ip_info = &slip_ip4;
95-
84+
#endif
9685
char if_key[] = "EPPP0"; // netif key needs to be unique
9786
if_key[sizeof(if_key) - 2 /* 2 = two chars before the terminator */ ] += s_eppp_netif_count++;
9887
base_netif_cfg.if_key = if_key;
@@ -104,12 +93,27 @@ static esp_netif_t *netif_init(eppp_type_t role, eppp_transport_handle_t h, eppp
10493
if (eppp_config->ppp.netif_prio) {
10594
base_netif_cfg.route_prio = eppp_config->ppp.netif_prio;
10695
}
107-
esp_netif_config_t netif_ppp_config = { .base = &base_netif_cfg,
108-
.driver = NULL,
109-
.stack = netstack_default_slip,
110-
};
96+
esp_netif_config_t netif_config = { .base = &base_netif_cfg,
97+
.driver = NULL,
98+
.stack = NETSTACK_CONFIG(),
99+
};
111100

112-
return esp_netif_new(&netif_ppp_config);
101+
#ifdef CONFIG_EPPP_LINK_USES_PPP
102+
__attribute__((unused)) esp_err_t ret = ESP_OK;
103+
esp_netif_t *netif = esp_netif_new(&netif_config);
104+
esp_netif_ppp_config_t netif_params;
105+
ESP_GOTO_ON_ERROR(esp_netif_ppp_get_params(netif, &netif_params), err, TAG, "Failed to get PPP params");
106+
netif_params.ppp_our_ip4_addr = eppp_config->ppp.our_ip4_addr;
107+
netif_params.ppp_their_ip4_addr = eppp_config->ppp.their_ip4_addr;
108+
netif_params.ppp_error_event_enabled = true;
109+
ESP_GOTO_ON_ERROR(esp_netif_ppp_set_params(netif, &netif_params), err, TAG, "Failed to set PPP params");
110+
return netif;
111+
err:
112+
esp_netif_destroy(netif);
113+
return NULL;
114+
#else
115+
return esp_netif_new(&netif_config);
116+
#endif // CONFIG_EPPP_LINK_USES_PPP
113117
}
114118

115119
esp_err_t eppp_netif_stop(esp_netif_t *netif, int stop_timeout_ms)
@@ -130,14 +134,16 @@ esp_err_t eppp_netif_stop(esp_netif_t *netif, int stop_timeout_ms)
130134
return ESP_OK;
131135
}
132136

133-
void try_ping(esp_netif_t *netif);
134-
135137
esp_err_t eppp_netif_start(esp_netif_t *netif)
136138
{
137139
esp_netif_action_start(netif, 0, 0, 0);
138140
esp_netif_action_connected(netif, 0, 0, 0);
139-
try_ping(netif);
141+
#ifndef CONFIG_EPPP_LINK_USES_PPP
142+
// PPP provides address negotiation, if not PPP, we need to check connection manually
143+
return eppp_check_connection(netif);
144+
#else
140145
return ESP_OK;
146+
#endif
141147
}
142148

143149
static int get_netif_num(esp_netif_t *netif)
@@ -160,7 +166,6 @@ static int get_netif_num(esp_netif_t *netif)
160166
static void on_ppp_event(void *arg, esp_event_base_t base, int32_t event_id, void *data)
161167
{
162168
esp_netif_t **netif = data;
163-
ESP_LOGD(TAG, "PPP status event: %" PRId32, event_id);
164169
if (base == NETIF_PPP_STATUS && event_id == NETIF_PPP_ERRORUSER) {
165170
ESP_LOGI(TAG, "Disconnected %d", get_netif_num(*netif));
166171
struct eppp_handle *h = esp_netif_get_io_driver(*netif);
@@ -193,14 +198,6 @@ static void on_ip_event(void *arg, esp_event_base_t base, int32_t event_id, void
193198
}
194199
}
195200

196-
//#if CONFIG_EPPP_LINK_DEVICE_SPI
197-
198-
#if CONFIG_EPPP_LINK_DEVICE_SDIO
199-
200-
201-
202-
#endif // UART
203-
204201
#if EPPP_NEEDS_TASK
205202
static void ppp_task(void *args)
206203
{
@@ -221,7 +218,7 @@ static void remove_handlers(void)
221218
{
222219
esp_netif_t *netif = esp_netif_find_if(have_some_eppp_netif, NULL);
223220
if (netif == NULL) {
224-
// if EPPP netif in the system, we cleanup the statics
221+
// if EPPP netif in the system, we clean up the statics
225222
vEventGroupDelete(s_event_group);
226223
s_event_group = NULL;
227224
esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, on_ip_event);
@@ -235,23 +232,8 @@ void eppp_deinit(esp_netif_t *netif)
235232
return;
236233
}
237234
struct eppp_handle *h = esp_netif_get_io_driver(netif);
238-
#if CONFIG_EPPP_LINK_DEVICE_SPI
239-
EPPP_TRANSPORT_DEINIT(h);
240-
// if (h->role == EPPP_CLIENT) {
241-
// deinit_master(netif);
242-
// } else {
243-
// deinit_slave(netif);
244-
// }
245-
#elif CONFIG_EPPP_LINK_DEVICE_UART
246-
EPPP_TRANSPORT_DEINIT(h);
247-
// deinit_uart(esp_netif_get_io_driver(netif));
248-
#elif CONFIG_EPPP_LINK_DEVICE_SDIO
249-
// struct eppp_handle *h = esp_netif_get_io_driver(netif);
250235
EPPP_TRANSPORT_DEINIT(h);
251-
#elif CONFIG_EPPP_LINK_DEVICE_ETH
252-
EPPP_TRANSPORT_DEINIT(h);
253-
#endif
254-
netif_deinit(netif);
236+
eppp_netif_deinit(netif);
255237
}
256238

257239
esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config)
@@ -265,47 +247,15 @@ esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config)
265247

266248
eppp_transport_handle_t h = EPPP_TRANSPORT_INIT(config);
267249
ESP_GOTO_ON_FALSE(h, ESP_ERR_NO_MEM, err, TAG, "Failed to init EPPP transport");
268-
ESP_GOTO_ON_FALSE(netif = netif_init(role, h, config), ESP_ERR_NO_MEM, err, TAG, "Failed to init EPPP netif");
269-
270-
#ifdef CONFIG_EPPP_OVER_PPP
271-
esp_netif_ppp_config_t netif_params;
272-
ESP_ERROR_CHECK(esp_netif_ppp_get_params(netif, &netif_params));
273-
netif_params.ppp_our_ip4_addr = config->ppp.our_ip4_addr;
274-
netif_params.ppp_their_ip4_addr = config->ppp.their_ip4_addr;
275-
netif_params.ppp_error_event_enabled = true;
276-
ESP_ERROR_CHECK(esp_netif_ppp_set_params(netif, &netif_params));
277-
#endif
278-
279-
#if CONFIG_EPPP_LINK_DEVICE_UART
280-
// init_uart(esp_netif_get_io_driver(netif), config);
281-
#elif CONFIG_EPPP_LINK_DEVICE_SDIO
282-
// esp_err_t ret;
283-
//// if (role == EPPP_SERVER) {
284-
//// ret = eppp_sdio_slave_init();
285-
//// } else {
286-
//// ret = eppp_sdio_host_init(&config->sdio);
287-
//// }
288-
//
289-
// if (ret != ESP_OK) {
290-
// ESP_LOGE(TAG, "Failed to initialize SDIO %d", ret);
291-
// return NULL;
292-
// }
293-
#elif CONFIG_EPPP_LINK_DEVICE_ETH
294-
// ret = eppp_transport_init(config, netif);
295-
// if (ret != ESP_OK) {
296-
// ESP_LOGE(TAG, "Failed to initialize SDIO %d", ret);
297-
// return NULL;
298-
// }
299-
300-
#endif
250+
ESP_GOTO_ON_FALSE(netif = eppp_netif_init(role, h, config), ESP_ERR_NO_MEM, err, TAG, "Failed to init EPPP netif");
301251
ESP_GOTO_ON_ERROR(esp_netif_attach(netif, h), err, TAG, "Failed to attach netif to EPPP transport");
302252
return netif;
303253
err:
304254
if (h) {
305255
EPPP_TRANSPORT_DEINIT(h);
306256
}
307257
if (netif) {
308-
netif_deinit(netif);
258+
eppp_netif_deinit(netif);
309259
}
310260
return NULL;
311261
}

0 commit comments

Comments
 (0)