Skip to content

Commit b2e6e0b

Browse files
committed
fix(eppp): Final fixes to SDIO transport
1 parent 051e185 commit b2e6e0b

File tree

12 files changed

+89
-274
lines changed

12 files changed

+89
-274
lines changed

components/eppp_link/eppp_sdio.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "eppp_link.h"
1414
#include "eppp_transport.h"
1515
#include "eppp_transport_sdio.h"
16+
#include "eppp_sdio.h"
1617

1718
#define TAG "eppp_sdio"
1819

@@ -65,6 +66,9 @@ eppp_transport_handle_t eppp_sdio_init(struct eppp_config_sdio_s *config)
6566
__attribute__((unused)) esp_err_t ret = ESP_OK;
6667
struct eppp_sdio *h = calloc(1, sizeof(struct eppp_sdio));
6768
ESP_RETURN_ON_FALSE(h, NULL, TAG, "Failed to allocate eppp_handle");
69+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
70+
h->parent.channel_tx = eppp_sdio_transmit_channel;
71+
#endif
6872
h->parent.base.post_attach = post_attach;
6973
h->is_host = config->is_host;
7074
esp_err_t (*init_fn)(struct eppp_config_sdio_s * eppp_config) = h->is_host ? eppp_sdio_host_init : eppp_sdio_slave_init;

components/eppp_link/eppp_sdio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ struct header {
2525
uint8_t channel;
2626
uint16_t size;
2727
} __attribute__((packed));
28+
29+
esp_err_t eppp_sdio_transmit_channel(esp_netif_t *netif, int channel, void *buffer, size_t len);

components/eppp_link/eppp_sdio_host.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "sdmmc_cmd.h"
1616
#include "esp_check.h"
1717
#include "eppp_link.h"
18+
#include "eppp_transport.h"
1819

1920
#if CONFIG_EPPP_LINK_DEVICE_SDIO_HOST
2021

@@ -31,7 +32,7 @@ static sdmmc_card_t *s_card = NULL;
3132
static DRAM_DMA_ALIGNED_ATTR uint8_t send_buffer[SDIO_PACKET_SIZE];
3233
static DMA_ATTR uint8_t rcv_buffer[SDIO_PACKET_SIZE];
3334

34-
esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len)
35+
static esp_err_t eppp_sdio_host_tx_generic(int channel, void *buffer, size_t len)
3536
{
3637
if (s_essl == NULL || s_essl_mutex == NULL) {
3738
// silently skip the Tx if the SDIO not fully initialized
@@ -41,7 +42,7 @@ esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len)
4142

4243
struct header *head = (void *)send_buffer;
4344
head->magic = PPP_SOF;
44-
head->channel = 0;
45+
head->channel = channel;
4546
head->size = len;
4647
memcpy(send_buffer + sizeof(struct header), buffer, len);
4748
size_t send_len = SDIO_ALIGN(len + sizeof(struct header));
@@ -61,6 +62,19 @@ esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len)
6162
return ret;
6263
}
6364

65+
esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len)
66+
{
67+
return eppp_sdio_host_tx_generic(0, buffer, len);
68+
}
69+
70+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
71+
esp_err_t eppp_sdio_transmit_channel(esp_netif_t *netif, int channel, void *buffer, size_t len)
72+
{
73+
return eppp_sdio_host_tx_generic(channel, buffer, len);
74+
}
75+
#endif
76+
77+
6478
static esp_err_t request_slave_reset(void)
6579
{
6680
esp_err_t ret = ESP_OK;
@@ -162,7 +176,7 @@ esp_err_t eppp_sdio_host_rx(esp_netif_t *netif)
162176
ESP_LOGE(TAG, "invalid magic %x", head->magic);
163177
break;
164178
}
165-
if (head->channel >= NR_OF_CHANNELS) {
179+
if (head->channel > NR_OF_CHANNELS) {
166180
ESP_LOGE(TAG, "invalid channel %x", head->channel);
167181
break;
168182
}
@@ -171,7 +185,16 @@ esp_err_t eppp_sdio_host_rx(esp_netif_t *netif)
171185
break;
172186
}
173187
ESP_LOG_BUFFER_HEXDUMP(TAG, rcv_buffer, size_read, ESP_LOG_VERBOSE);
174-
esp_netif_receive(netif, rcv_buffer + sizeof(struct header), head->size, NULL);
188+
if (head->channel == 0) {
189+
esp_netif_receive(netif, rcv_buffer + sizeof(struct header), head->size, NULL);
190+
} else {
191+
#if defined(CONFIG_EPPP_LINK_CHANNELS_SUPPORT)
192+
struct eppp_handle *h = esp_netif_get_io_driver(netif);
193+
if (h->channel_rx) {
194+
h->channel_rx(netif, head->channel, rcv_buffer + sizeof(struct header), head->size);
195+
}
196+
#endif
197+
}
175198
break;
176199
} else {
177200
ESP_LOGE(TAG, "rx packet error: %08X", ret);

components/eppp_link/eppp_sdio_slave.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "esp_netif.h"
1111
#include "driver/sdio_slave.h"
1212
#include "eppp_link.h"
13+
#include "eppp_transport.h"
1314
#include "eppp_sdio.h"
1415
#include "esp_check.h"
15-
1616
#if CONFIG_EPPP_LINK_DEVICE_SDIO_SLAVE
1717
#define BUFFER_NUM 4
1818
#define BUFFER_SIZE SDIO_PAYLOAD
@@ -21,23 +21,18 @@ static DMA_ATTR uint8_t sdio_slave_rx_buffer[BUFFER_NUM][BUFFER_SIZE];
2121
static DMA_ATTR uint8_t sdio_slave_tx_buffer[SDIO_PAYLOAD];
2222
static int s_slave_request = 0;
2323

24-
esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len)
24+
static esp_err_t eppp_sdio_host_tx_generic(int channel, void *buffer, size_t len)
2525
{
2626
if (s_slave_request != REQ_INIT) {
2727
// silently skip the Tx if the SDIO not fully initialized
2828
return ESP_OK;
2929
}
3030
struct header *head = (void *)sdio_slave_tx_buffer;
3131
head->magic = PPP_SOF;
32-
head->channel = 0;
32+
head->channel = channel;
3333
head->size = len;
3434
memcpy(sdio_slave_tx_buffer + sizeof(struct header), buffer, len);
3535
size_t send_len = SDIO_ALIGN(len + sizeof(struct header));
36-
// if (send_len > len) {
37-
// // pad with SOF's if the size is not 4 bytes aligned
38-
// memset(&sdio_slave_tx_buffer[len], PPP_SOF, send_len - len);
39-
// }
40-
4136
ESP_LOG_BUFFER_HEXDUMP(TAG, sdio_slave_tx_buffer, send_len, ESP_LOG_VERBOSE);
4237
esp_err_t ret = sdio_slave_transmit(sdio_slave_tx_buffer, send_len);
4338
if (ret != ESP_OK) {
@@ -48,6 +43,18 @@ esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len)
4843
return ESP_OK;
4944
}
5045

46+
esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len)
47+
{
48+
return eppp_sdio_host_tx_generic(0, buffer, len);
49+
}
50+
51+
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
52+
esp_err_t eppp_sdio_transmit_channel(esp_netif_t *netif, int channel, void *buffer, size_t len)
53+
{
54+
return eppp_sdio_host_tx_generic(channel, buffer, len);
55+
}
56+
#endif
57+
5158
static esp_err_t slave_reset(void)
5259
{
5360
esp_err_t ret = ESP_OK;
@@ -91,16 +98,24 @@ esp_err_t eppp_sdio_slave_rx(esp_netif_t *netif)
9198
ESP_LOGE(TAG, "invalid magic %x", head->magic);
9299
return ESP_FAIL;
93100
}
94-
if (head->channel >= NR_OF_CHANNELS) {
101+
if (head->channel > NR_OF_CHANNELS) {
95102
ESP_LOGE(TAG, "invalid channel %x", head->channel);
96103
return ESP_FAIL;
97104
}
98105
if (head->size > SDIO_PAYLOAD || head->size > length) {
99106
ESP_LOGE(TAG, "invalid size %x", head->size);
100107
return ESP_FAIL;
101108
}
102-
103-
esp_netif_receive(netif, ptr + sizeof(struct header), head->size, NULL);
109+
if (head->channel == 0) {
110+
esp_netif_receive(netif, ptr + sizeof(struct header), head->size, NULL);
111+
} else {
112+
#if defined(CONFIG_EPPP_LINK_CHANNELS_SUPPORT)
113+
struct eppp_handle *h = esp_netif_get_io_driver(netif);
114+
if (h->channel_rx) {
115+
h->channel_rx(netif, head->channel, ptr + sizeof(struct header), head->size);
116+
}
117+
#endif
118+
}
104119
if (sdio_slave_recv_load_buf(handle) != ESP_OK) {
105120
ESP_LOGE(TAG, "Failed to recycle packet buffer");
106121
return ESP_FAIL;
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
if(CONFIG_EXAMPLE_WIFI_OVER_EPPP_CHANNEL)
2+
set(wifi_over_channels channel_wifi_station.c)
3+
endif()
14
idf_component_register(SRCS app_main.c register_iperf.c
2-
channel_wifi_station.c
3-
INCLUDE_DIRS ".")
5+
${wifi_over_channels}
6+
INCLUDE_DIRS ".")

components/eppp_link/examples/host/main/Kconfig.projbuild

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,14 @@ menu "Example Configuration"
5050
help
5151
Baudrate used by the PPP over UART
5252

53+
config EXAMPLE_WIFI_OVER_EPPP_CHANNEL
54+
bool "Use WiFi over EPPP channel"
55+
default n
56+
depends on EPPP_LINK_CHANNELS_SUPPORT && ESP_WIFI_REMOTE_ENABLED
57+
help
58+
Enable this option to use WiFi over EPPP channel.
59+
If this option is enabled, the example will only start the Wi-Fi driver,
60+
but the Wi-Fi netif will reside on client's end and will channel
61+
the Rx and Tx data via EPPP channels.
62+
5363
endmenu

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

Lines changed: 1 addition & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717
#include "esp_check.h"
1818
#include "mqtt_client.h"
1919
#include "console_ping.h"
20-
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
21-
#if __has_include("esp_wifi_remote.h")
22-
#include "esp_wifi_remote.h"
23-
#define HAVE_WIFI_REMOTE
24-
#endif
25-
#endif
26-
2720

2821
void register_iperf(void);
2922

@@ -96,119 +89,6 @@ static void mqtt_app_start(void)
9689
}
9790
#endif // MQTT
9891

99-
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
100-
#define HELLO_DONE BIT0
101-
#define WIFI_MAC BIT1
102-
#define CONNECT BIT2
103-
104-
typedef enum {
105-
UNKNOWN,
106-
HELLO,
107-
START,
108-
ERROR,
109-
} state_t;
110-
static state_t s_state = UNKNOWN;
111-
static esp_netif_t *s_wifi_netif = NULL;
112-
static EventGroupHandle_t s_events;
113-
static eppp_channel_fn_t s_transmit = {NULL};
114-
static esp_err_t recv(esp_netif_t *netif, int nr, void *buffer, size_t len)
115-
{
116-
if (nr == 1) {
117-
printf("Received channel=%d len=%d %.*s\n", nr, (int)len, (int)len, (char *)buffer);
118-
if (s_state == HELLO) {
119-
const char hello[] = "Hello client";
120-
const char mac[] = "MAC: ";
121-
size_t mac_len = 5 /* MAC: */ + 6 * 2 /* 6 bytes per char */ + 5 /* : */ + 1 /* \0 */;
122-
if (len == sizeof(hello) && memcmp(buffer, hello, len) == 0) {
123-
xEventGroupSetBits(s_events, HELLO_DONE);
124-
} else if (len == mac_len && memcmp(buffer, mac, 5) == 0) {
125-
uint8_t mac_addr[6];
126-
sscanf((char *)buffer + 5, "%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8 ":%2" PRIx8,
127-
&mac_addr[0], &mac_addr[1], &mac_addr[2], &mac_addr[3], &mac_addr[4], &mac_addr[5]);
128-
printf("Parsed MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
129-
esp_netif_set_mac(s_wifi_netif, mac_addr);
130-
xEventGroupSetBits(s_events, WIFI_MAC);
131-
}
132-
} else if (s_state == START) {
133-
const char connected[] = "Connected";
134-
if (len == sizeof(connected) && memcmp(buffer, connected, len) == 0) {
135-
xEventGroupSetBits(s_events, CONNECT);
136-
}
137-
}
138-
} else if (nr == 2) {
139-
printf("Received WIFI channel=%d len=%d\n", nr, (int)len);
140-
// ESP_LOG_BUFFER_HEXDUMP(TAG, buffer, len, ESP_LOG_INFO);
141-
return esp_wifi_remote_channel_rx(NULL, buffer, NULL, len);
142-
}
143-
return ESP_OK;
144-
}
145-
146-
static void task_transmit(void *arg)
147-
{
148-
int counter = 0;
149-
esp_netif_t *eppp_netif = (esp_netif_t *)arg;
150-
while (1) {
151-
EventBits_t bits = xEventGroupWaitBits(s_events,
152-
HELLO_DONE | WIFI_MAC | CONNECT,
153-
pdTRUE,
154-
pdFALSE,
155-
pdMS_TO_TICKS(1000));
156-
// if (bits & HELLO_SERVER) {
157-
// const char hello[] = "Hello server";
158-
// s_transmit(eppp_netif, 1, hello, sizeof(hello));
159-
// } else
160-
if (bits & HELLO_DONE) {
161-
ESP_LOGI(TAG, "Hello done");
162-
const char command[] = "Get MAC";
163-
s_transmit(eppp_netif, 1, (void*)command, sizeof(command));
164-
// s_state = CONNECTED;
165-
} else if (bits & WIFI_MAC) {
166-
s_state = START;
167-
ESP_LOGI(TAG, "Starting WIFI");
168-
esp_netif_action_start(s_wifi_netif, 0, 0, 0);
169-
} else if (bits & CONNECT) {
170-
ESP_LOGI(TAG, "WIFI connected");
171-
esp_netif_action_connected(s_wifi_netif, 0, 0, 0);
172-
} else if (s_state != START) {
173-
const char hello[] = "Hello server";
174-
s_transmit(eppp_netif, 1, (void*)hello, sizeof(hello));
175-
s_state = HELLO;
176-
}
177-
}
178-
179-
while (1) {
180-
181-
char data[32];
182-
sprintf(data, "Message from host #%d", counter++);
183-
s_transmit(eppp_netif, 1, data, strlen(data));
184-
vTaskDelay(1000 / portTICK_PERIOD_MS);
185-
}
186-
}
187-
188-
esp_netif_t* esp_wifi_remote_create_default_sta(void);
189-
190-
// move to netif2
191-
ESP_EVENT_DEFINE_BASE(WIFI_REMOTE_EVENT);
192-
193-
static esp_err_t wifi_remote_tx(void *h, void *buffer, size_t len)
194-
{
195-
esp_netif_t *eppp_netif = (esp_netif_t *)h;
196-
// ESP_LOG_BUFFER_HEXDUMP(TAG, buffer, len, ESP_LOG_INFO);
197-
return s_transmit(eppp_netif, 2, buffer, len);
198-
}
199-
200-
static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
201-
{
202-
ESP_LOGI(TAG, "IP event_handler: event_base=%s event_id=%d", event_base, event_id);
203-
if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
204-
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
205-
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
206-
xEventGroupSetBits(s_events, CONNECT);
207-
}
208-
}
209-
210-
#endif // CONFIG_EPPP_LINK_CHANNELS_SUPPORT
211-
21292
void station_over_eppp_channel(void *arg);
21393

21494
void app_main(void)
@@ -278,15 +158,8 @@ void app_main(void)
278158
// start console REPL
279159
ESP_ERROR_CHECK(console_cmd_start());
280160

281-
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
161+
#ifdef CONFIG_EXAMPLE_WIFI_OVER_EPPP_CHANNEL
282162
station_over_eppp_channel(eppp_netif);
283-
// ESP_RETURN_ON_FALSE(s_events = xEventGroupCreate(),, TAG, "Failed to create event group");
284-
// ESP_RETURN_ON_FALSE(eppp_add_channels(eppp_netif, &s_transmit, recv, NULL) == ESP_OK,, TAG, "Failed to add channels");
285-
// ESP_RETURN_ON_FALSE(s_transmit,, TAG, "Channel tx function is not set");
286-
// xTaskCreate(task_transmit, "task_transmit", 2048, eppp_netif, 5, NULL);
287-
// s_wifi_netif = esp_wifi_remote_create_default_sta();
288-
// esp_wifi_remote_channel_set(WIFI_IF_STA, eppp_netif, wifi_remote_tx);
289-
// esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, event_handler, NULL);
290163
#endif
291164
#if CONFIG_EXAMPLE_MQTT
292165
mqtt_app_start();

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
#include "eppp_link.h"
1414
#include "esp_log.h"
1515
#include "esp_check.h"
16-
#ifdef CONFIG_EPPP_LINK_CHANNELS_SUPPORT
17-
#if __has_include("esp_wifi_remote.h")
1816
#include "esp_wifi_remote.h"
19-
#define HAVE_WIFI_REMOTE
20-
#endif
21-
#endif
2217

2318
#define CHAT_CHANNEL 1
2419
#define WIFI_CHANNEL 2
@@ -34,7 +29,6 @@ typedef struct context {
3429
eppp_channel_fn_t transmit;
3530
EventGroupHandle_t flags;
3631
state_t state;
37-
// esp_netif_t *wifi;
3832
esp_netif_t *eppp;
3933
} context_t;
4034

components/eppp_link/examples/host/main/idf_component.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ dependencies:
55
override_path: ../../..
66
console_cmd_ping:
77
version: '*'
8-
espressif/esp_wifi_remote:
9-
version: '*'
10-
override_path: /home/david/repos/esp-wifi-remote/components/esp_wifi_remote
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
idf_component_register(SRCS "eppp_slave.c" "channel_wifi_station.c"
2-
INCLUDE_DIRS ".")
1+
if(CONFIG_EXAMPLE_WIFI_OVER_EPPP_CHANNEL)
2+
set(wifi_over_channels channel_wifi_station.c)
3+
endif()
4+
idf_component_register(SRCS eppp_slave.c
5+
${wifi_over_channels}
6+
INCLUDE_DIRS ".")

0 commit comments

Comments
 (0)