Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
8c75c352
Unverified
Commit
8c75c352
authored
Apr 10, 2024
by
Me No Dev
Committed by
GitHub
Apr 10, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(wifi): Add support for NAPT to WIFI AP (#9478)
Allows another interface's connection to be shared to the AP
parent
8ceb4bac
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
8 deletions
+44
-8
libraries/Network/src/NetworkInterface.cpp
libraries/Network/src/NetworkInterface.cpp
+21
-5
libraries/WiFi/src/AP.cpp
libraries/WiFi/src/AP.cpp
+19
-0
libraries/WiFi/src/WiFiAP.cpp
libraries/WiFi/src/WiFiAP.cpp
+2
-2
libraries/WiFi/src/WiFiAP.h
libraries/WiFi/src/WiFiAP.h
+2
-1
No files found.
libraries/Network/src/NetworkInterface.cpp
View file @
8c75c352
...
...
@@ -357,6 +357,16 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s
esp_netif_flags_t
flags
=
esp_netif_get_flags
(
_esp_netif
);
if
(
flags
&
ESP_NETIF_DHCP_SERVER
){
// Set DNS Server
if
(
d2
.
ip
.
u_addr
.
ip4
.
addr
!=
0
){
err
=
esp_netif_set_dns_info
(
_esp_netif
,
ESP_NETIF_DNS_MAIN
,
&
d2
);
if
(
err
){
log_e
(
"Netif Set DNS Info Failed! 0x%04x: %s"
,
err
,
esp_err_to_name
(
err
));
return
false
;
}
}
// Stop DHCPS
err
=
esp_netif_dhcps_stop
(
_esp_netif
);
if
(
err
&&
err
!=
ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED
){
...
...
@@ -371,11 +381,6 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s
return
false
;
}
// Set DNS Server
if
(
d2
.
ip
.
u_addr
.
ip4
.
addr
!=
0
){
esp_netif_set_dns_info
(
_esp_netif
,
ESP_NETIF_DNS_MAIN
,
&
d2
);
}
dhcps_lease_t
lease
;
lease
.
enable
=
true
;
uint8_t
CIDR
=
calculateSubnetCIDR
(
subnet
);
...
...
@@ -438,6 +443,17 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s
log_e
(
"DHCPS Set Lease Failed! 0x%04x: %s"
,
err
,
esp_err_to_name
(
err
));
return
false
;
}
// Offer DNS to DHCP clients
if
(
d2
.
ip
.
u_addr
.
ip4
.
addr
!=
0
){
dhcps_offer_t
dhcps_dns_value
=
OFFER_DNS
;
err
=
esp_netif_dhcps_option
(
_esp_netif
,
ESP_NETIF_OP_SET
,
ESP_NETIF_DOMAIN_NAME_SERVER
,
&
dhcps_dns_value
,
sizeof
(
dhcps_dns_value
));
if
(
err
){
log_e
(
"Netif Set DHCP Option Failed! 0x%04x: %s"
,
err
,
esp_err_to_name
(
err
));
return
false
;
}
}
// Start DHCPS
err
=
esp_netif_dhcps_start
(
_esp_netif
);
if
(
err
){
...
...
libraries/WiFi/src/AP.cpp
View file @
8c75c352
...
...
@@ -20,6 +20,7 @@
#include <esp_event.h>
#include <lwip/ip_addr.h>
#include "dhcpserver/dhcpserver_options.h"
#include "esp_netif.h"
esp_netif_t
*
get_esp_interface_netif
(
esp_interface_t
interface
);
...
...
@@ -279,6 +280,24 @@ bool APClass::bandwidth(wifi_bandwidth_t bandwidth){
return
true
;
}
bool
APClass
::
enableNAPT
(
bool
enable
){
if
(
!
started
())
{
log_e
(
"AP must be first started to enable/disable NAPT"
);
return
false
;
}
esp_err_t
err
=
ESP_OK
;
if
(
enable
){
err
=
esp_netif_napt_enable
(
_esp_netif
);
}
else
{
err
=
esp_netif_napt_disable
(
_esp_netif
);
}
if
(
err
){
log_e
(
"Could not set enable/disable NAPT! 0x%x: %s"
,
err
,
esp_err_to_name
(
err
));
return
false
;
}
return
true
;
}
String
APClass
::
SSID
(
void
)
const
{
if
(
!
started
()){
return
String
();
...
...
libraries/WiFi/src/WiFiAP.cpp
View file @
8c75c352
...
...
@@ -67,9 +67,9 @@ String WiFiAPClass::softAPSSID() const
* @param gateway gateway IP
* @param subnet subnet mask
*/
bool
WiFiAPClass
::
softAPConfig
(
IPAddress
local_ip
,
IPAddress
gateway
,
IPAddress
subnet
,
IPAddress
dhcp_lease_start
)
bool
WiFiAPClass
::
softAPConfig
(
IPAddress
local_ip
,
IPAddress
gateway
,
IPAddress
subnet
,
IPAddress
dhcp_lease_start
,
IPAddress
dns
)
{
return
AP
.
config
(
local_ip
,
gateway
,
subnet
,
dhcp_lease_start
);
return
AP
.
begin
()
&&
AP
.
config
(
local_ip
,
gateway
,
subnet
,
dhcp_lease_start
,
dns
);
}
/**
...
...
libraries/WiFi/src/WiFiAP.h
View file @
8c75c352
...
...
@@ -48,6 +48,7 @@ class APClass: public NetworkInterface {
bool
clear
();
bool
bandwidth
(
wifi_bandwidth_t
bandwidth
);
bool
enableNAPT
(
bool
enable
=
true
);
String
SSID
(
void
)
const
;
uint8_t
stationCount
();
...
...
@@ -77,7 +78,7 @@ public:
return
softAP
(
ssid
.
c_str
(),
passphrase
.
c_str
(),
channel
,
ssid_hidden
,
max_connection
,
ftm_responder
,
auth_mode
,
cipher
);
}
bool
softAPConfig
(
IPAddress
local_ip
,
IPAddress
gateway
,
IPAddress
subnet
,
IPAddress
dhcp_lease_start
=
(
uint32_t
)
0
);
bool
softAPConfig
(
IPAddress
local_ip
,
IPAddress
gateway
,
IPAddress
subnet
,
IPAddress
dhcp_lease_start
=
(
uint32_t
)
0
,
IPAddress
dns
=
(
uint32_t
)
0
);
bool
softAPdisconnect
(
bool
wifioff
=
false
);
bool
softAPbandwidth
(
wifi_bandwidth_t
bandwidth
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment