Skip to content

Commit a5b84cf

Browse files
committed
Add generic IP utilities
Add: softAPBroadcastIP() => Retrieve the network id (e.g. 192.168.0.0) softAPNetwrokID() => Retrieve the broadcast IP (e.g. 192.168.0.255) softAPSubnetCIDR() => Retrieve the subnet CIDR (e.g. 24)
1 parent 52cd613 commit a5b84cf

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

libraries/WiFi/src/WiFiAP.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,47 @@ IPAddress WiFiAPClass::softAPIP()
235235
return IPAddress(ip.ip.addr);
236236
}
237237

238+
/**
239+
* Get the softAP broadcast IP address.
240+
* @return IPAddress softAP broadcastIP
241+
*/
242+
IPAddress WiFiAPClass::softAPBroadcastIP()
243+
{
244+
tcpip_adapter_ip_info_t ip;
245+
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
246+
return IPAddress();
247+
}
248+
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ip);
249+
return WiFiGenericClass::calculateBroadcast(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr));
250+
}
251+
252+
/**
253+
* Get the softAP network ID.
254+
* @return IPAddress softAP networkID
255+
*/
256+
IPAddress WiFiAPClass::softAPNetwrokID()
257+
{
258+
tcpip_adapter_ip_info_t ip;
259+
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
260+
return IPAddress();
261+
}
262+
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ip);
263+
return WiFiGenericClass::calculateNetworkID(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr));
264+
}
265+
266+
/**
267+
* Get the softAP subnet CIDR.
268+
* @return uint8_t softAP subnetCIDR
269+
*/
270+
uint8_t WiFiAPClass::softAPSubnetCIDR()
271+
{
272+
tcpip_adapter_ip_info_t ip;
273+
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
274+
return (uint8_t)0;
275+
}
276+
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ip);
277+
return WiFiGenericClass::calculateSubnetCIDR(IPAddress(ip.netmask.addr));
278+
}
238279

239280
/**
240281
* Get the softAP interface MAC address.

libraries/WiFi/src/WiFiAP.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class WiFiAPClass
4545

4646
IPAddress softAPIP();
4747

48+
IPAddress softAPBroadcastIP();
49+
IPAddress softAPNetwrokID();
50+
uint8_t softAPSubnetCIDR();
51+
4852
bool softAPenableIpV6();
4953
IPv6Address softAPIPv6();
5054

0 commit comments

Comments
 (0)