Skip to content

Commit 7829e8f

Browse files
committed
fix(eppp): Make some common netif options configurable
1 parent fcb6080 commit 7829e8f

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

components/eppp_link/eppp_link.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static void netif_deinit(esp_netif_t *netif)
157157
}
158158
}
159159

160-
static esp_netif_t *netif_init(eppp_type_t role)
160+
static esp_netif_t *netif_init(eppp_type_t role, eppp_config_t *eppp_config)
161161
{
162162
if (s_eppp_netif_count > 9) { // Limit to max 10 netifs, since we use "EPPPx" as the unique key (where x is 0-9)
163163
ESP_LOGE(TAG, "Cannot create more than 10 instances");
@@ -217,10 +217,13 @@ static esp_netif_t *netif_init(eppp_type_t role)
217217
char if_key[] = "EPPP0"; // netif key needs to be unique
218218
if_key[sizeof(if_key) - 2 /* 2 = two chars before the terminator */ ] += s_eppp_netif_count++;
219219
base_netif_cfg.if_key = if_key;
220-
if (role == EPPP_CLIENT) {
221-
base_netif_cfg.if_desc = "pppos_client";
220+
if (eppp_config->ppp.netif_description) {
221+
base_netif_cfg.if_desc = eppp_config->ppp.netif_description;
222222
} else {
223-
base_netif_cfg.if_desc = "pppos_server";
223+
base_netif_cfg.if_desc = role == EPPP_CLIENT ? "pppos_client" : "pppos_server";
224+
}
225+
if (eppp_config->ppp.netif_prio) {
226+
base_netif_cfg.route_prio = eppp_config->ppp.netif_prio;
224227
}
225228
esp_netif_config_t netif_ppp_config = { .base = &base_netif_cfg,
226229
.driver = ppp_driver_cfg,
@@ -703,7 +706,12 @@ void eppp_deinit(esp_netif_t *netif)
703706

704707
esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config)
705708
{
706-
esp_netif_t *netif = netif_init(role);
709+
if (config == NULL || (role != EPPP_SERVER && role != EPPP_CLIENT)) {
710+
ESP_LOGE(TAG, "Invalid configuration or role");
711+
return NULL;
712+
}
713+
714+
esp_netif_t *netif = netif_init(role, config);
707715
if (!netif) {
708716
ESP_LOGE(TAG, "Failed to initialize PPP netif");
709717
remove_handlers();
@@ -730,6 +738,10 @@ esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config)
730738

731739
esp_netif_t *eppp_open(eppp_type_t role, eppp_config_t *config, int connect_timeout_ms)
732740
{
741+
if (config == NULL || (role != EPPP_SERVER && role != EPPP_CLIENT)) {
742+
ESP_LOGE(TAG, "Invalid configuration or role");
743+
return NULL;
744+
}
733745
#if CONFIG_EPPP_LINK_DEVICE_UART
734746
if (config->transport != EPPP_TRANSPORT_UART) {
735747
ESP_LOGE(TAG, "Invalid transport: UART device must be enabled in Kconfig");

components/eppp_link/include/eppp_link.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
. ppp = { \
3838
.our_ip4_addr = { .addr = our_ip }, \
3939
.their_ip4_addr = { .addr = their_ip }, \
40+
.netif_prio = 0, \
41+
.netif_description = NULL, \
4042
} \
4143
}
4244

@@ -88,6 +90,8 @@ typedef struct eppp_config_t {
8890
struct eppp_config_pppos_s {
8991
esp_ip4_addr_t our_ip4_addr;
9092
esp_ip4_addr_t their_ip4_addr;
93+
int netif_prio;
94+
const char *netif_description;
9195
} ppp;
9296

9397
} eppp_config_t;

0 commit comments

Comments
 (0)