From 2656839825b175964479cdde15a247c376f58be1 Mon Sep 17 00:00:00 2001 From: ElvenWang Date: Wed, 8 Sep 2021 06:47:56 +0800 Subject: [PATCH] support different dhcp client in Linux (#9490) Some Linux environment like Yocto has no dhclient tools. So add a macro named CHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD to config the command which used to query the IP address from the DHCP server. For example in Yocto cross compile : PLATFORM_CFLAGS='-DCHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME=\"mlan0\"", "-DCHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD=\"udhcpc -b -i %s & \"' Signed-off-by: Haoran Wang --- src/platform/Linux/ConnectivityManagerImpl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/platform/Linux/ConnectivityManagerImpl.cpp b/src/platform/Linux/ConnectivityManagerImpl.cpp index 93dcc841c45b17..5f2159b19212c4 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.cpp +++ b/src/platform/Linux/ConnectivityManagerImpl.cpp @@ -39,6 +39,10 @@ #include #endif +#ifndef CHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD +#define CHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD "dhclient -nw %s" +#endif + using namespace ::chip; using namespace ::chip::TLV; using namespace ::chip::DeviceLayer::Internal; @@ -945,7 +949,7 @@ CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, cons // Run dhclient for IP on WiFi. // TODO: The wifi can be managed by networkmanager on linux so we don't have to care about this. char cmdBuffer[128]; - sprintf(cmdBuffer, "dhclient -nw %s", CHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME); + sprintf(cmdBuffer, CHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD, CHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME); int dhclientSystemRet = system(cmdBuffer); if (dhclientSystemRet != 0) {