Skip to content

Commit

Permalink
[ESP32] Compilation fix when IPV4 is disabled. (#33085)
Browse files Browse the repository at this point in the history
* Compilation fix when IPV4 is disabled.

* Addressed review comments and documented the IPv4 disabled change

* Update docs/guides/esp32/config_options.md

Co-authored-by: Shubham Patil <[email protected]>

* Update docs/guides/esp32/config_options.md

Co-authored-by: Shubham Patil <[email protected]>

* Resolved the build failure for m5-stack ipv6 only test

---------

Co-authored-by: Shubham Patil <[email protected]>
  • Loading branch information
shripad621git and shubhamdp authored Jul 1, 2024
1 parent 3185ae1 commit 1919112
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ chip_gn_arg_append("chip_config_network_layer_ble" "false")
endif()

if(CONFIG_DISABLE_IPV4)
chip_gn_arg_append("chip_inet_config_enable_ipv4" "false")
if(NOT CONFIG_LWIP_IPV4)
chip_gn_arg_append("chip_inet_config_enable_ipv4" "false")
else()
message(FATAL_ERROR "Please also disable config option CONFIG_LWIP_IPV4")
endif()
endif()

if(CONFIG_DISABLE_READ_CLIENT)
Expand Down
1 change: 1 addition & 0 deletions docs/guides/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ example on ESP32 series of SoCs
- [Generating and Using ESP Secure Cert Partition](secure_cert_partition.md)
- [BLE Settings](ble_settings.md)
- [Providers](providers.md)
- [Configuration Options](config_options.md)
13 changes: 13 additions & 0 deletions docs/guides/esp32/config_options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Configuration options

This file lists down few config options to be configured through menuconfig for
specific scenarios.

### Building with IPV4 Disabled

Configure below options through `idf.py menuconfig` and build the app.

```
CONFIG_DISABLE_IPV4=y
CONFIG_LWIP_IPV4=n
```
4 changes: 4 additions & 0 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,13 @@ def main() -> int:
if sys.platform == "darwin":
shell.run_cmd(
"sed -i '' 's/#\\ CONFIG_DISABLE_IPV4\\ is\\ not\\ set/CONFIG_DISABLE_IPV4=y/g' sdkconfig ")
shell.run_cmd(
"sed -i '' 's/CONFIG_LWIP_IPV4=y/#\\ CONFIG_LWIP_IPV4\\ is\\ not\\ set/g' sdkconfig ")
else:
shell.run_cmd(
"sed -i 's/#\\ CONFIG_DISABLE_IPV4\\ is\\ not\\ set/CONFIG_DISABLE_IPV4=y/g' sdkconfig ")
shell.run_cmd(
"sed -i 's/CONFIG_LWIP_IPV4=y/#\\ CONFIG_LWIP_IPV4\\ is\\ not\\ set/g' sdkconfig ")

shell.run_cmd("idf.py build")
shell.run_cmd("idf.py build flashing_script")
Expand Down
3 changes: 3 additions & 0 deletions examples/chef/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ CONFIG_LWIP_IPV6_AUTOCONFIG=y
# disable IPV4
# CONFIG_DISABLE_IPV4 is not set

# lwip IPV4 config
CONFIG_LWIP_IPV4=y

# Use a custom partition table
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
Expand Down
3 changes: 3 additions & 0 deletions examples/chef/esp32/sdkconfig_rpc.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ CONFIG_LWIP_IPV6_AUTOCONFIG=y
# disable IPV4
# CONFIG_DISABLE_IPV4 is not set

# lwip configuration
CONFIG_LWIP_IPV4=y

# Use a custom partition table
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
Expand Down
2 changes: 2 additions & 0 deletions examples/platform/esp32/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,15 @@ class Esp32WiFi final : public WiFi
return pw::OkStatus();
}

#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
pw::Status GetIP4Address(const pw_protobuf_Empty & request, chip_rpc_IP4Address & response) override
{
esp_netif_ip_info_t ip_info;
PW_TRY(EspToPwStatus(esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), &ip_info)));
snprintf(response.address, sizeof(response.address), IPSTR, IP2STR(&ip_info.ip));
return pw::OkStatus();
}
#endif

pw::Status GetIP6Address(const pw_protobuf_Empty & request, chip_rpc_IP6Address & response) override
{
Expand Down
2 changes: 2 additions & 0 deletions scripts/build/builders/esp32.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ def generate(self):
if not self.enable_ipv4:
self._Execute(
['bash', '-c', 'echo -e "\\nCONFIG_DISABLE_IPV4=y\\n" >>%s' % shlex.quote(defaults_out)])
self._Execute(
['bash', '-c', 'echo -e "\\nCONFIG_LWIP_IPV4=n\\n" >>%s' % shlex.quote(defaults_out)])

if self.enable_insights_trace:
insights_flag = 'y'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ rm -f examples/all-clusters-minimal-app/esp32/sdkconfig

bash -c 'echo -e "\nCONFIG_DISABLE_IPV4=y\n" >>{out}/esp32-m5stack-all-clusters-minimal-rpc-ipv6only/sdkconfig.defaults'

bash -c 'echo -e "\nCONFIG_LWIP_IPV4=n\n" >>{out}/esp32-m5stack-all-clusters-minimal-rpc-ipv6only/sdkconfig.defaults'

bash -c 'echo -e "\nCONFIG_ESP_INSIGHTS_ENABLED=n\nCONFIG_ENABLE_ESP_INSIGHTS_TRACE=n\n" >>{out}/esp32-m5stack-all-clusters-minimal-rpc-ipv6only/sdkconfig.defaults'

bash -c 'source $IDF_PATH/export.sh; source scripts/activate.sh;
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import("//build_overrides/chip.gni")

import("${chip_root}/src/inet/inet.gni")
import("${chip_root}/src/platform/device.gni")

assert(chip_device_platform == "esp32")
Expand All @@ -36,6 +37,7 @@ declare_args() {

defines = [
"CHIP_CONFIG_SOFTWARE_VERSION_NUMBER=${chip_config_software_version_number}",
"CHIP_DEVICE_CONFIG_ENABLE_IPV4=${chip_inet_config_enable_ipv4}",
]

static_library("ESP32") {
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ void ConnectivityManagerImpl::UpdateInternetConnectivityState(void)
// If the station interface has been assigned an IPv4 address, and has
// an IPv4 gateway, then presume that the device has IPv4 Internet
// connectivity.
#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
if (!ip4_addr_isany_val(*netif_ip4_addr(netif)) && !ip4_addr_isany_val(*netif_ip4_gw(netif)))
{
haveIPv4Conn = true;
Expand All @@ -1013,6 +1014,7 @@ void ConnectivityManagerImpl::UpdateInternetConnectivityState(void)
IPAddress::FromString(addrStr, addr);
}
}
#endif

// Search among the IPv6 addresses assigned to the interface for a Global Unicast
// address (2000::/3) that is in the valid state. If such an address is found...
Expand Down

0 comments on commit 1919112

Please sign in to comment.