Skip to content

Commit

Permalink
support different dhcp client in Linux (#9490)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
TE-N-ElvenWang authored and pull[bot] committed Sep 17, 2021
1 parent 7c24702 commit 2656839
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/platform/Linux/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#include <platform/internal/GenericConnectivityManagerImpl_WiFi.cpp>
#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;
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 2656839

Please sign in to comment.