Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the dependency error and some changed requested by reviewer #34764

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 74 additions & 4 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,71 @@ class SampleTestEventTriggerHandler : public TestEventTriggerHandler
}
};

#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
void int_array_add_unique(uint16_t ** res, uint16_t a)
{
size_t reslen, max_size;
uint16_t * n;

for (reslen = 0; *res && (*res)[reslen]; reslen++)
{
if ((*res)[reslen] == a)
return; /* already in the list */
}
max_size = (size_t) -1;
if (reslen > max_size - 2)
{
/* This should not really happen in practice, but if it did,
* something would overflow. Do not try to add the new value;
* instead, make this behave like memory allocation failure to
* avoid messing up memory. */
free(*res);
*res = NULL;
return;
}
n = (uint16_t *) realloc(*res, (reslen + 2) * sizeof(uint16_t));
if (n == NULL)
{
free(*res);
*res = NULL;
return;
}
n[reslen] = a;
n[reslen + 1] = 0;
*res = n;
}

static uint16_t WiFiPAFGet_FreqList(char * ArgStrn, uint16_t ** pfreq_list)
{
char * token;
uint16_t * freq_list = NULL;
uint16_t len = 0;

while ((token = strtok(ArgStrn, " ")))
{
if (strncmp(token, "freq_list=", 10) == 0)
{
char * pos = token + 10;
if (strcmp(pos, "all") == 0)
{
return NAN_FREQ_LIST_ALL;
}
while (pos && pos[0])
{
int_array_add_unique(&freq_list, atoi(pos));
len++;
pos = strchr(pos, ',');
if (pos)
pos++;
}
*pfreq_list = freq_list;
break;
}
}
return len;
}
#endif

int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions,
const Optional<EndpointId> secondaryNetworkCommissioningEndpoint)
{
Expand Down Expand Up @@ -484,16 +549,21 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions,
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
#if CHIP_DEVICE_CONFIG_ENABLE_WPA && CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
ChipLogProgress(NotSpecified, "WiFi-PAF: initialzing");
if (LinuxDeviceOptions::GetInstance().mWiFi)
if (LinuxDeviceOptions::GetInstance().mWiFi && LinuxDeviceOptions::GetInstance().mWiFiPAF)
{
ChipLogProgress(NotSpecified, "WiFi-PAF: initialzing");
if (EnsureWiFiIsStarted())
{
ChipLogProgress(NotSpecified, "Wi-Fi Management started");
DeviceLayer::ConnectivityManager::WiFiPAFAdvertiseParam args;
args.enable = LinuxDeviceOptions::GetInstance().mWiFiPAF;
args.ExtCmds = LinuxDeviceOptions::GetInstance().mWiFiPAFExtCmds;
args.enable = LinuxDeviceOptions::GetInstance().mWiFiPAF;
args.freq_list_len = WiFiPAFGet_FreqList((char *) LinuxDeviceOptions::GetInstance().mWiFiPAFExtCmds, &args.pfreq_list);
DeviceLayer::ConnectivityMgr().SetWiFiPAFAdvertisingEnabled(args);
if ((args.freq_list_len > 0) && (args.freq_list_len != NAN_FREQ_LIST_ALL))
{
free(args.pfreq_list);
args.pfreq_list = nullptr;
}
}
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/app/server/CommissioningWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ void CommissioningWindowManager::OnPlatformEvent(const DeviceLayer::ChipDeviceEv
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
DeviceLayer::ConnectivityManager::WiFiPAFAdvertiseParam args;
args.enable = false;
args.ExtCmds = nullptr;
args.enable = false;
args.freq_list_len = 0;
DeviceLayer::ConnectivityMgr().SetWiFiPAFAdvertisingEnabled(args);
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
,
Transport::WiFiPAFListenParameters(DeviceLayer::ConnectivityMgr().GetWiFiPAF())
Transport::WiFiPAFListenParameters(static_cast<Transport::WiFiPAFBase *>(
DeviceLayer::ConnectivityMgr().GetWiFiPAF()->mWiFiPAFTransport))
#endif
);

Expand Down
20 changes: 8 additions & 12 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,6 @@ DeviceCommissioner::DeviceCommissioner() :
mDeviceNOCChainCallback(OnDeviceNOCChainGeneration, this), mSetUpCodePairer(this)
{}

DeviceCommissioner::~DeviceCommissioner()
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
DeviceLayer::ConnectivityMgr().WiFiPAFCancelConnect();
#endif
}

CHIP_ERROR DeviceCommissioner::Init(CommissionerInitParams params)
{
VerifyOrReturnError(params.operationalCredentialsDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
Expand Down Expand Up @@ -574,6 +567,9 @@ void DeviceCommissioner::Shutdown()
mUdcServer = nullptr;
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
DeviceLayer::ConnectivityMgr().WiFiPAFCancelConnect();
#endif

// Release everything from the commissionee device pool here.
// Make sure to use ReleaseCommissioneeDevice so we don't keep dangling
Expand Down Expand Up @@ -827,16 +823,16 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
if (params.GetPeerAddress().GetTransportType() == Transport::Type::kWiFiPAF)
{
if (DeviceLayer::ConnectivityMgr().GetWiFiPAF()->GetWiFiPAFState() != Transport::WiFiPAFBase::State::kConnected)
if (DeviceLayer::ConnectivityMgr().GetWiFiPAF()->GetWiFiPAFState() != WiFiPAF::State::kConnected)
{
ChipLogProgress(Controller, "WiFi-PAF: Subscribing the NAN-USD devices");
ChipLogProgress(Controller, "WiFi-PAF: Subscribing to the NAN-USD devices");
if (!DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted())
{
ChipLogError(Controller, "Wi-Fi Management should have be started now.");
ChipLogError(Controller, "Wi-Fi Management should have been started now.");
ExitNow(CHIP_ERROR_INTERNAL);
}
mRendezvousParametersForDeviceDiscoveredOverWiFiPAF = params;
DeviceLayer::ConnectivityMgr().WiFiPAFConnect(params.GetSetupDiscriminator().value(), (void *) this,
DeviceLayer::ConnectivityMgr().WiFiPAFConnect(params.GetSetupDiscriminator().value(), reinterpret_cast<void *>(this),
OnWiFiPAFSubscribeComplete, OnWiFiPAFSubscribeError);
ExitNow(CHIP_NO_ERROR);
}
Expand Down Expand Up @@ -912,7 +908,7 @@ void DeviceCommissioner::OnDiscoveredDeviceOverBleError(void * appState, CHIP_ER
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
void DeviceCommissioner::OnWiFiPAFSubscribeComplete(void * appState)
{
auto self = (DeviceCommissioner *) appState;
auto self = reinterpret_cast<DeviceCommissioner *>(appState);
auto device = self->mDeviceInPASEEstablishment;

if (nullptr != device && device->GetDeviceTransportType() == Transport::Type::kWiFiPAF)
Expand Down
3 changes: 2 additions & 1 deletion src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
{
public:
DeviceCommissioner();
~DeviceCommissioner() override;
~DeviceCommissioner() override {}

#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY // make this commissioner discoverable
/**
Expand Down Expand Up @@ -720,6 +720,7 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
*/
void CloseBleConnection();
#endif

/**
* @brief
* Discover all devices advertising as commissionable.
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceControllerFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct FactoryInitParams
Ble::BleLayer * bleLayer = nullptr;
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
Transport::WiFiPAFLayer * wifipaf_layer = nullptr;
WiFiPAF::WiFiPAFLayer * wifipaf_layer = nullptr;
#endif

//
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceControllerSystemState.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct DeviceControllerSystemStateParams
Ble::BleLayer * bleLayer = nullptr;
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
Transport::WiFiPAFLayer * wifipaf_layer = nullptr;
WiFiPAF::WiFiPAFLayer * wifipaf_layer = nullptr;
#endif
Credentials::GroupDataProvider * groupDataProvider = nullptr;
Crypto::SessionKeystore * sessionKeystore = nullptr;
Expand Down
14 changes: 5 additions & 9 deletions src/controller/SetUpCodePairer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ CHIP_ERROR GetPayload(const char * setUpCode, SetupPayload & payload)
}
} // namespace

SetUpCodePairer::~SetUpCodePairer()
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
DeviceLayer::ConnectivityMgr().WiFiPAFCancelConnect();
#endif
}

CHIP_ERROR SetUpCodePairer::PairDevice(NodeId remoteId, const char * setUpCode, SetupCodePairerBehaviour commission,
DiscoveryType discoveryType, Optional<Dnssd::CommonResolutionData> resolutionData)
{
Expand Down Expand Up @@ -282,6 +275,9 @@ CHIP_ERROR SetUpCodePairer::StartDiscoverOverWiFiPAF(SetupPayload & payload)
CHIP_ERROR SetUpCodePairer::StopConnectOverWiFiPAF()
{
mWaitingForDiscovery[kWiFiPAFTransport] = false;
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
DeviceLayer::ConnectivityMgr().WiFiPAFCancelIncompleteConnect();
#endif
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -397,13 +393,13 @@ void SetUpCodePairer::OnWifiPAFDiscoveryError(CHIP_ERROR err)

void SetUpCodePairer::OnWiFiPAFSubscribeComplete(void * appState)
{
auto self = (SetUpCodePairer *) appState;
auto self = reinterpret_cast<SetUpCodePairer *>(appState);
self->OnDiscoveredDeviceOverWifiPAF();
}

void SetUpCodePairer::OnWiFiPAFSubscribeError(void * appState, CHIP_ERROR err)
{
auto self = (SetUpCodePairer *) appState;
auto self = reinterpret_cast<SetUpCodePairer *>(appState);
self->OnWifiPAFDiscoveryError(err);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/controller/SetUpCodePairer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DLL_EXPORT SetUpCodePairer : public DevicePairingDelegate
{
public:
SetUpCodePairer(DeviceCommissioner * commissioner) : mCommissioner(commissioner) {}
~SetUpCodePairer();
virtual ~SetUpCodePairer() {}

CHIP_ERROR PairDevice(chip::NodeId remoteId, const char * setUpCode,
SetupCodePairerBehaviour connectionType = SetupCodePairerBehaviour::kCommission,
Expand Down
54 changes: 54 additions & 0 deletions src/include/platform/CHIPDeviceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,60 @@
#define CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF 0
#endif

/**
* CHIP_DEVICE_CONFIG_WIFIPAF_MIN_ADVERTISING_TIMEOUT
*
* The min amount of time (in seconds) after which the chip platform will stop PAF advertisement
*/
#ifndef CHIP_DEVICE_CONFIG_WIFIPAF_MIN_ADVERTISING_TIMEOUT
#define CHIP_DEVICE_CONFIG_WIFIPAF_MIN_ADVERTISING_TIMEOUT (3 * 60)
#endif

/**
* CHIP_DEVICE_CONFIG_WIFIPAF_MAX_ADVERTISING_TIMEOUT
*
* The max amount of time (in seconds) after which the chip platform will stop PAF advertisement
*/
#ifndef CHIP_DEVICE_CONFIG_WIFIPAF_MAX_ADVERTISING_TIMEOUT
#define CHIP_DEVICE_CONFIG_WIFIPAF_MAX_ADVERTISING_TIMEOUT (15 * 60)
#endif

/**
* CHIP_DEVICE_CONFIG_WIFIPAF_DISCOVERY_TIMEOUT
*
* The max amount of time (in seconds) the chip controller will discovery Wi-Fi PAF
*/
#ifndef CHIP_DEVICE_CONFIG_WIFIPAF_DISCOVERY_TIMEOUT
#define CHIP_DEVICE_CONFIG_WIFIPAF_DISCOVERY_TIMEOUT (15 * 60)
#endif

/**
* CHIP_DEVICE_CONFIG_WIFIPAF_24G_DEFAUTL_CHNL
*
* The default channel of Wi-Fi PAF in 2.4G band (channel#6)
*/
#ifndef CHIP_DEVICE_CONFIG_WIFIPAF_24G_DEFAUTL_CHNL
#define CHIP_DEVICE_CONFIG_WIFIPAF_24G_DEFAUTL_CHNL 2437
#endif

/**
* CHIP_DEVICE_CONFIG_WIFIPAF_5G_LOW_DEFAUTL_CHNL
*
* The default channel of Wi-Fi PAF in 5G lower band (channel#44)
*/
#ifndef CHIP_DEVICE_CONFIG_WIFIPAF_5G_LOW_DEFAUTL_CHNL
#define CHIP_DEVICE_CONFIG_WIFIPAF_5G_LOW_DEFAUTL_CHNL 5220
#endif

/**
* CHIP_DEVICE_CONFIG_WIFIPAF_5G_HI_DEFAUTL_CHNL
*
* The default channel of Wi-Fi PAF in 5G upper band (channel#149)
*/
#ifndef CHIP_DEVICE_CONFIG_WIFIPAF_5G_UP_DEFAUTL_CHNL
#define CHIP_DEVICE_CONFIG_WIFIPAF_5G_UP_DEFAUTL_CHNL 5745
#endif

// -------------------- WiFi AP Configuration --------------------

/**
Expand Down
25 changes: 14 additions & 11 deletions src/include/platform/ConnectivityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <inet/TCPEndPoint.h>
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
#include <transport/raw/WiFiPAF.h>
#include <wifipaf/WiFiPAFLayer.h>
#endif

namespace chip {
Expand Down Expand Up @@ -185,9 +185,9 @@ class ConnectivityManager
CHIP_ERROR WiFiPAFConnect(const SetupDiscriminator & connDiscriminator, void * appState, OnConnectionCompleteFunct onSuccess,
OnConnectionErrorFunct onError);
CHIP_ERROR WiFiPAFCancelConnect();
CHIP_ERROR WiFiPAFCancelIncompleteConnect();
CHIP_ERROR WiFiPAFSend(System::PacketBufferHandle && msgBuf);
Transport::WiFiPAFBase * GetWiFiPAF();
void SetWiFiPAF(Transport::WiFiPAFBase * pmWiFiPAF);
WiFiPAF::WiFiPAFLayer * GetWiFiPAF();
#endif

// WiFi AP methods
Expand Down Expand Up @@ -289,12 +289,15 @@ struct ConnectivityManager::SEDIntervalsConfig
};

#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
#define NAN_FREQ_LIST_ALL 0xff
struct ConnectivityManager::WiFiPAFAdvertiseParam
{
/* To enable/disable WiFiPAF Commissioning */
bool enable;
/* The optional commands */
const char * ExtCmds;

/* Frequency list */
uint16_t freq_list_len;
uint16_t * pfreq_list;
};
#endif

Expand Down Expand Up @@ -454,6 +457,11 @@ inline CHIP_ERROR ConnectivityManager::WiFiPAFCancelConnect()
return static_cast<ImplClass *>(this)->_WiFiPAFCancelConnect();
}

inline CHIP_ERROR ConnectivityManager::WiFiPAFCancelIncompleteConnect()
{
return static_cast<ImplClass *>(this)->_WiFiPAFCancelIncompleteConnect();
}

inline CHIP_ERROR ConnectivityManager::WiFiPAFSend(chip::System::PacketBufferHandle && msgBuf)
{
return static_cast<ImplClass *>(this)->_WiFiPAFSend(std::move(msgBuf));
Expand Down Expand Up @@ -505,15 +513,10 @@ inline void ConnectivityManager::ResetThreadNetworkDiagnosticsCounts()
}

#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
inline Transport::WiFiPAFBase * ConnectivityManager::GetWiFiPAF()
inline WiFiPAF::WiFiPAFLayer * ConnectivityManager::GetWiFiPAF()
{
return static_cast<ImplClass *>(this)->_GetWiFiPAF();
}

inline void ConnectivityManager::SetWiFiPAF(Transport::WiFiPAFBase * pWiFiPAF)
{
return static_cast<ImplClass *>(this)->_SetWiFiPAF(pWiFiPAF);
}
#endif

inline Ble::BleLayer * ConnectivityManager::GetBleLayer()
Expand Down
4 changes: 4 additions & 0 deletions src/lib/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ source_set("without-logging") {
"${chip_root}/src/transport",
]

if (chip_device_config_enable_wifipaf == true) {
public_deps += [ "${chip_root}/src/wifipaf" ]
}

# See src/lib/lib.gni for declaration of this build arg.
if (chip_build_controller) {
public_deps += [ "${chip_root}/src/controller" ]
Expand Down
Loading
Loading