Skip to content

Commit 378e034

Browse files
committed
fix(eppp): Support for channels
1 parent a0024df commit 378e034

File tree

8 files changed

+79
-4
lines changed

8 files changed

+79
-4
lines changed

components/eppp_link/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,21 @@ menu "eppp_link"
9393
default "06:00:00:00:00:02"
9494
depends on EPPP_LINK_DEVICE_ETH
9595

96+
config EPPP_LINK_CHANNELS_SUPPORT
97+
bool "Enable channel support (multiple logical channels)"
98+
default n
99+
depends on !EPPP_LINK_DEVICE_ETH
100+
help
101+
Enable support for multiple logical channels in the EPPP link layer.
102+
When enabled, you can configure the number of channels used for communication.
103+
104+
config EPPP_LINK_NR_OF_CHANNELS
105+
int "Number of logical channels"
106+
depends on EPPP_LINK_CHANNELS_SUPPORT && !EPPP_LINK_DEVICE_ETH
107+
range 1 8
108+
default 2
109+
help
110+
Set the number of logical channels for EPPP link communication.
111+
Each channel can be used for independent data streams.
112+
96113
endmenu

components/eppp_link/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ brings in the WiFi connectivity from the "SLAVE" microcontroller.
3636

3737
Use PPP netif for UART; Keep the default (TUN) for others
3838

39+
### Channel support (multiple logical channels)
40+
41+
* `CONFIG_EPPP_LINK_CHANNELS_SUPPORT` -- Enable support for multiple logical channels (default: disabled)
42+
* `CONFIG_EPPP_LINK_NR_OF_CHANNELS` -- Number of logical channels (default: 2, range: 1-8, only visible if channel support is enabled)
43+
44+
When channel support is enabled, the EPPP link can multiplex multiple logical data streams over the same transport. The number of channels is configurable. Channel support is not available for Ethernet transport.
45+
46+
To use channels in your application, use the `eppp_add_channels()` API and provide your own channel transmit/receive callbacks. These APIs and related types are only available when channel support is enabled in Kconfig.
3947

4048
## API
4149

@@ -54,6 +62,9 @@ Use PPP netif for UART; Keep the default (TUN) for others
5462
* `eppp_netif_start()` -- Starts the network, could be called after startup or whenever a connection is lost
5563
* `eppp_netif_stop()` -- Stops the network
5664
* `eppp_perform()` -- Perform one iteration of the PPP task (need to be called regularly in task-less configuration)
65+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
66+
* `eppp_add_channels()` -- Register channel transmit/receive callbacks (only available if channel support is enabled)
67+
#endif
5768

5869
## Throughput
5970

components/eppp_link/eppp_link.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ void eppp_close(esp_netif_t *netif)
362362
remove_handlers();
363363
}
364364

365+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
365366
esp_err_t eppp_add_channels(esp_netif_t *netif, int nr, eppp_channel_fn_t *tx, const eppp_channel_fn_t rx)
366367
{
367368
ESP_RETURN_ON_FALSE(netif != NULL && nr > 0 && nr < NR_OF_CHANNELS && tx != NULL && rx != NULL, ESP_ERR_INVALID_ARG, TAG, "Invalid arguments");
@@ -371,3 +372,4 @@ esp_err_t eppp_add_channels(esp_netif_t *netif, int nr, eppp_channel_fn_t *tx, c
371372
h->channel_rx = rx;
372373
return ESP_OK;
373374
}
375+
#endif

components/eppp_link/eppp_spi.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,15 @@ static esp_err_t transmit(void *h, void *buffer, size_t len)
112112
return transmit_generic(spi_handle, 0, buffer, len);
113113
}
114114

115+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
115116
static esp_err_t transmit_channel(esp_netif_t *netif, int channel, void *buffer, size_t len)
116117
{
117118
// printf("transmit_channel %d %p %zu\n", channel, buffer, len);
118119
struct eppp_handle *handle = esp_netif_get_io_driver(netif);
119120
struct eppp_spi *spi_handle = __containerof(handle, struct eppp_spi, parent);;
120121
return transmit_generic(spi_handle, channel, buffer, len);
121122
}
123+
#endif
122124

123125
static void IRAM_ATTR timer_callback(void *arg)
124126
{
@@ -394,11 +396,11 @@ esp_err_t eppp_perform(esp_netif_t *netif)
394396
if (head->channel == 0) {
395397
esp_netif_receive(netif, in_buf + sizeof(struct header), head->size, NULL);
396398
} else {
397-
// printf("channel receive %d\n", head->channel);
398-
// printf("channel_rx %p\n", h->parent.channel_rx);
399+
#if defined(CONFIG_EPPP_LINK_CHANNELS_SUPPORT)
399400
if (h->parent.channel_rx) {
400401
h->parent.channel_rx(netif, head->channel, in_buf + sizeof(struct header), head->size);
401402
}
403+
#endif
402404
}
403405
}
404406
h->transaction_size = NEXT_TRANSACTION_SIZE(next_tx_size, head->next_size);
@@ -435,7 +437,9 @@ eppp_transport_handle_t eppp_spi_init(struct eppp_config_spi_s *config)
435437
__attribute__((unused)) esp_err_t ret = ESP_OK;
436438
struct eppp_spi *h = calloc(1, sizeof(struct eppp_spi));
437439
ESP_RETURN_ON_FALSE(h, NULL, TAG, "Failed to allocate eppp_handle");
440+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
438441
h->parent.channel_tx = transmit_channel;
442+
#endif
439443
h->is_master = config->is_master;
440444
h->parent.base.post_attach = post_attach;
441445
h->out_queue = xQueueCreate(CONFIG_EPPP_LINK_PACKET_QUEUE_SIZE, sizeof(struct packet));

components/eppp_link/eppp_transport.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55
*/
66
#pragma once
77
#include "esp_netif_types.h"
8+
#include "sdkconfig.h"
89

9-
#define NR_OF_CHANNELS 2
10+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
11+
#define NR_OF_CHANNELS CONFIG_EPPP_LINK_NR_OF_CHANNELS
12+
#else
13+
#define NR_OF_CHANNELS 1
14+
#endif
1015

1116
struct eppp_handle {
1217
esp_netif_driver_base_t base;
1318
eppp_type_t role;
1419
bool stop;
1520
bool exited;
1621
bool netif_stop;
17-
#if NR_OF_CHANNELS > 0
22+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
1823
eppp_channel_fn_t channel_tx;
1924
eppp_channel_fn_t channel_rx;
2025
#endif

components/eppp_link/examples/host/main/app_main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,19 @@ static void mqtt_app_start(void)
8787
esp_mqtt_client_start(client);
8888
}
8989
#endif // MQTT
90+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
9091
static esp_err_t recv(esp_netif_t *netif, int nr, void *buffer, size_t len)
9192
{
9293
printf("recv %d %p %zu\n", nr, buffer, len);
9394
return ESP_OK;
9495
}
96+
#endif
9597

9698
void app_main(void)
9799
{
100+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
98101
static eppp_channel_fn_t transmit = NULL;
102+
#endif
99103
ESP_LOGI(TAG, "[APP] Startup..");
100104
ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
101105
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
@@ -161,11 +165,13 @@ void app_main(void)
161165
// start console REPL
162166
ESP_ERROR_CHECK(console_cmd_start());
163167

168+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
164169
eppp_add_channels(eppp_netif, 1, &transmit, recv);
165170
while (1) {
166171
transmit(eppp_netif, 1, "Hi three", 3);
167172
vTaskDelay(1000 / portTICK_PERIOD_MS);
168173
}
174+
#endif
169175
#if CONFIG_EXAMPLE_MQTT
170176
mqtt_app_start();
171177
#endif

components/eppp_link/include/eppp_link.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ void eppp_netif_deinit(esp_netif_t *netif);
198198

199199
esp_err_t eppp_perform(esp_netif_t *netif);
200200

201+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
201202
typedef esp_err_t (*eppp_channel_fn_t)(esp_netif_t *netif, int nr, void *buffer, size_t len);
202203

203204
esp_err_t eppp_add_channels(esp_netif_t *netif, int nr, eppp_channel_fn_t *tx, const eppp_channel_fn_t rx);
205+
#endif

components/eppp_link/plan.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Plan: Make Number of Channels Configurable in eppp_link
2+
3+
## 1. Update Kconfig ✅ (completed)
4+
- Add a new boolean configuration option (e.g., `CONFIG_EPPP_LINK_CHANNELS_SUPPORT`) to enable channel support in the `components/eppp_link/Kconfig` file.
5+
- Add a new integer configuration option (e.g., `CONFIG_EPPP_LINK_NR_OF_CHANNELS`) that is only visible when the boolean option is enabled.
6+
- Set reasonable defaults (e.g., boolean disabled by default, integer default of 2) and provide help text for both options.
7+
- Ensure both options are properly documented in the menu with appropriate dependencies.
8+
- **Note:** Channel support options are not available when Ethernet transport is selected (`!EPPP_LINK_DEVICE_ETH`).
9+
10+
## 2. Update Code to Use Config Value ✅ (completed)
11+
- Replace all hardcoded uses of `#define NR_OF_CHANNELS 2` in `eppp_transport.h` with a macro that uses the Kconfig value (e.g., `#define NR_OF_CHANNELS CONFIG_EPPP_LINK_NR_OF_CHANNELS`).
12+
- Update all `.c` files that reference `NR_OF_CHANNELS` to ensure they use the new configurable value.
13+
- Add `#include "sdkconfig.h"` where needed to access the Kconfig value.
14+
- Use `#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT` for all channel-related code:
15+
- The typedef for `eppp_channel_fn_t` and the `eppp_add_channels` API in `eppp_link.h` are now conditionally compiled.
16+
- The `channel_tx` and `channel_rx` members in the handle struct are also conditionally compiled.
17+
- Ensure that all channel-related APIs and struct members are only available when channel support is enabled in Kconfig.
18+
19+
## 3. Update Documentation
20+
- Update `components/eppp_link/README.md` to document the new configuration option and its effect.
21+
- Mention the new option in the "Configuration" section, with usage notes.
22+
23+
## 4. Update Example Projects
24+
- Optionally, update example `sdkconfig.defaults` files in `examples/host` and `examples/slave` to show how to set the number of channels.
25+
- Add a note in example READMEs if relevant.
26+
27+
## 5. Test and Validate
28+
- Build and run the examples with different values for the number of channels to ensure the configuration is respected and works as intended.

0 commit comments

Comments
 (0)