Bridging ethernet and wifi

pascal21
Posts: 6
Joined: Wed Sep 09, 2020 10:46 am

Bridging ethernet and wifi

Postby pascal21 » Tue Sep 15, 2020 8:21 am

Hello everyone,

After to have estblish connection sucessfull with ethernet i would like to bridge with wifi,
In the examples i see eth2ap example but in this net_if library is not use ,

Following documentation of version 4.1 The purpose of ESP-NETIF library is twofold:

It provides an abstraction layer for the application on top of the TCP/IP stack. This will allow applications to choose between IP stacks
in the future.
The APIs it provides are thread safe, even if the underlying TCP/IP stack APIs are not.

Is it possible to use net_if and in that case how with 2 interfaces , is it necessary to define 2 instances?

esp_netif_config_t netif_config = ESP_NETIF_DEFAULT_WIFI_STA();
esp_netif_config_t netif_config = ESP_NETIF_DEFAULT_ETH();...........

Thanks,

ESP_cermak
Posts: 69
Joined: Thu Nov 01, 2018 8:32 am

Re: Bridging ethernet and wifi

Postby ESP_cermak » Tue Sep 15, 2020 2:43 pm

Hi pascal21

Yes, that's correct. The IDF example "eth2ap" doesn't use network interfaces at all. It just connects the wifi driver to the ethernet driver, so the packets are directly passed from one to another without going through the TCP/IP stack (which has its benefits).

Yes, it is possible to use standard network interfaces for ethernet and WiFi AP netif to do the same, but there's no such example in IDF. I think you have two options:
1) bridge mode: setup ethernet netif with static IP, setup default AP with the same subnet, enable IP forwarding in lwip
2) NAT mode: setup default ethernet netif (dhcp client), setup default AP (with dhcp server) with arbitrary local subnet, enable NAPT in lwip

pascal21
Posts: 6
Joined: Wed Sep 09, 2020 10:46 am

Re: Bridging ethernet and wifi

Postby pascal21 » Wed Sep 16, 2020 1:58 pm

Hi,

1) bridge mode: setup ethernet netif with static IP, setup default AP with the same subnet, enable IP forwarding in lwip

Can you give me some more information how to setup default ap with the same subnet in the process of wifi setting

esp_netif_create_default_wifi_ap();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));


ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));

wifi_config_t wifi_config = {
.ap = {
.ssid = ESP_WIFI_SSID,
.ssid_len = strlen(ESP_WIFI_SSID),
.channel = ESP_WIFI_CHANNEL,
.password = ESP_WIFI_PASS,
.max_connection = MAX_STA_CONN,
.authmode = WIFI_AUTH_WPA_WPA2_PSK
},
};
if (strlen(ESP_WIFI_PASS) == 0) {
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
}

ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());

Regards,

pascal21
Posts: 6
Joined: Wed Sep 09, 2020 10:46 am

Re: Bridging ethernet and wifi

Postby pascal21 » Thu Sep 17, 2020 3:25 pm

Hi,

After some test it begin to work (see file joint) but bridge doesn't work

Connection with ethernet ok
Connection wifi ok
Test Dialog socket with wifi ok
Test Dialog socket with ethernet problem

as soon i try to dialog with socket on ethernet there is problem ,
I'm not sure if the process to init and run wifi is good because i create a new instance net_if for wifi ,
it seems to overlead net_if of ethernet in transfer of packet see (see subroutine wifi_init_softap) ?
connect.c
(8.29 KiB) Downloaded 480 times
Regards,
Attachments
tcp_client.c
(3.45 KiB) Downloaded 422 times

Who is online

Users browsing this forum: Google [Bot] and 137 guests