Skip to content

Commit

Permalink
* Fix the dependency error
Browse files Browse the repository at this point in the history
* Change the default setting of WiFiPAF as enabled if running on Linux system
* Change to use C++ casting
* Move the paf cancel function from desctructor to shutdown

Signed-off-by: Lo,Chin-Ran <[email protected]>
  • Loading branch information
crlonxp committed Aug 21, 2024
1 parent 229df0c commit f1c2418
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 93 deletions.
6 changes: 6 additions & 0 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ source_set("chip-all-clusters-common") {
"${chip_root}/src/app/tests/suites/credentials:dac_provider",
"${chip_root}/src/lib",
"${chip_root}/third_party/jsoncpp",
"${chip_root}/src/wifipaf:wifipaf",
]
if (chip_device_config_enable_wifipaf) {
deps += [
"${chip_root}/src/wifipaf:wifipaf",
]
}

include_dirs = [
"${chip_root}/examples/all-clusters-app/all-clusters-common/include",
Expand Down
5 changes: 5 additions & 0 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ executable("chip-tool") {
":chip-tool-utils",
"${chip_root}/src/platform/logging:stdio",
]
if (chip_device_config_enable_wifipaf) {
deps += [
"${chip_root}/src/wifipaf:wifipaf",
]
}

output_dir = root_out_dir
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ 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
32 changes: 20 additions & 12 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,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 @@ -571,6 +564,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 @@ -743,6 +739,7 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
else if (params.GetPeerAddress().GetTransportType() == Transport::Type::kWiFiPAF)
{
ConnectWiFiPAFTransportToSelf();
peerAddress = Transport::PeerAddress::WiFiPAF(remoteDeviceId);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
Expand Down Expand Up @@ -824,16 +821,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 @@ -909,7 +906,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 Expand Up @@ -1823,6 +1820,17 @@ void DeviceCommissioner::CloseBleConnection()
}
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
void DeviceCommissioner::ConnectWiFiPAFTransportToSelf()
{
Transport::WiFiPAFBase & transport = std::get<Transport::WiFiPAF<1>>(mSystemState->TransportMgr()->GetTransport().GetTransports());
if (!transport.IsWiFiPAFLayerTransportSetToSelf())
{
transport.SetWiFiPAFLayerTransportToSelf();
}
}
#endif

CHIP_ERROR DeviceCommissioner::DiscoverCommissionableNodes(Dnssd::DiscoveryFilter filter)
{
ReturnErrorOnFailure(SetUpNodeDiscovery());
Expand Down
6 changes: 5 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,10 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
*/
void CloseBleConnection();
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
void ConnectWiFiPAFTransportToSelf();
#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
18 changes: 9 additions & 9 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 @@ -183,9 +183,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 @@ -450,6 +450,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 @@ -501,15 +506,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/platform/Linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ static_library("Linux") {
if (chip_enable_ble) {
public_deps += [ "dbus/bluez" ]
}

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

source_set("logging") {
Expand Down
27 changes: 15 additions & 12 deletions src/platform/Linux/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@
#include <credentials/CHIPCert.h>
#include <platform/GLibTypeDeleter.h>
#include <platform/internal/GenericConnectivityManagerImpl_WiFi.ipp>
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
#include <transport/raw/WiFiPAF.h>
#endif
#endif

using namespace ::chip;
Expand Down Expand Up @@ -146,6 +143,9 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
ChipLogError(DeviceLayer, "Failed to reset WiFi statistic counts");
}
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
pmWiFiPAF = WiFiPAF::WiFiPAFLayer::GetWiFiPAFLayer();
#endif

return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -912,16 +912,10 @@ CHIP_ERROR ConnectivityManagerImpl::_SetWiFiPAFAdvertisingEnabled(WiFiPAFAdverti
}
}

Transport::WiFiPAFBase * ConnectivityManagerImpl::_GetWiFiPAF()
WiFiPAF::WiFiPAFLayer * ConnectivityManagerImpl::_GetWiFiPAF()
{
return pmWiFiPAF;
}

void ConnectivityManagerImpl::_SetWiFiPAF(Transport::WiFiPAFBase * pWiFiPAF)
{
pmWiFiPAF = pWiFiPAF;
return;
}
#endif

void ConnectivityManagerImpl::StartNonConcurrentWiFiManagement()
Expand Down Expand Up @@ -1385,7 +1379,7 @@ void ConnectivityManagerImpl::OnDiscoveryResult(gboolean success, GVariant * dis
ChipLogProgress(DeviceLayer, "WiFi-PAF: peer_addr: [%02x:%02x:%02x:%02x:%02x:%02x]", mpaf_info.peer_addr[0],
mpaf_info.peer_addr[1], mpaf_info.peer_addr[2], mpaf_info.peer_addr[3], mpaf_info.peer_addr[4],
mpaf_info.peer_addr[5]);
GetWiFiPAF()->SetWiFiPAFState(Transport::WiFiPAFBase::State::kConnected);
GetWiFiPAF()->SetWiFiPAFState(WiFiPAF::State::kConnected);

// Read the ssi
GAutoPtr<GVariant> ssiValue(g_variant_lookup_value(discov_info, "ssi", G_VARIANT_TYPE_BYTESTRING));
Expand All @@ -1398,7 +1392,7 @@ void ConnectivityManagerImpl::OnDiscoveryResult(gboolean success, GVariant * dis
}
else
{
GetWiFiPAF()->SetWiFiPAFState(Transport::WiFiPAFBase::State::kInitialized);
GetWiFiPAF()->SetWiFiPAFState(WiFiPAF::State::kInitialized);
if (mOnPafSubscribeError != nullptr)
{
mOnPafSubscribeError(mAppState, CHIP_ERROR_TIMEOUT);
Expand Down Expand Up @@ -1526,6 +1520,15 @@ CHIP_ERROR ConnectivityManagerImpl::_WiFiPAFCancelConnect()

snprintf(args, sizeof(args), "subscribe_id=%d", mpresubscribe_id);
wpa_fi_w1_wpa_supplicant1_interface_call_nancancel_subscribe_sync(mWpaSupplicant.iface, args, nullptr, &err.GetReceiver());
mOnPafSubscribeComplete = nullptr;
mOnPafSubscribeError = nullptr;
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_WiFiPAFCancelIncompleteConnect()
{
mOnPafSubscribeComplete = nullptr;
mOnPafSubscribeError = nullptr;
return CHIP_NO_ERROR;
}

Expand Down
8 changes: 4 additions & 4 deletions src/platform/Linux/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

#include <mutex>
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
#include <transport/raw/WiFiPAF.h>
#include <wifipaf/WiFiPAFLayer.h>
#endif
#endif

Expand Down Expand Up @@ -144,12 +144,12 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
CHIP_ERROR _WiFiPAFConnect(const SetupDiscriminator & connDiscriminator, void * appState, OnConnectionCompleteFunct onSuccess,
OnConnectionErrorFunct onError);
CHIP_ERROR _WiFiPAFCancelConnect();
CHIP_ERROR _WiFiPAFCancelIncompleteConnect();
void OnDiscoveryResult(gboolean success, GVariant * obj);
void OnNanReceive(GVariant * obj);
void OnNanSubscribeTerminated(gint term_subscribe_id, gint reason);
CHIP_ERROR _WiFiPAFSend(chip::System::PacketBufferHandle && msgBuf);
Transport::WiFiPAFBase * _GetWiFiPAF();
void _SetWiFiPAF(Transport::WiFiPAFBase * pWiFiPAF);
WiFiPAF::WiFiPAFLayer * _GetWiFiPAF();
#endif

void PostNetworkConnect();
Expand Down Expand Up @@ -250,7 +250,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,

OnConnectionCompleteFunct mOnPafSubscribeComplete;
OnConnectionErrorFunct mOnPafSubscribeError;
Transport::WiFiPAFBase * pmWiFiPAF;
WiFiPAF::WiFiPAFLayer * pmWiFiPAF;
void * mAppState;
CHIP_ERROR _SetWiFiPAFAdvertisingEnabled(WiFiPAFAdvertiseParam & args);
CHIP_ERROR _WiFiPAFPublish(WiFiPAFAdvertiseParam & args);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/device.gni
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ declare_args() {
chip_fake_platform = false

# Include wifi-paf to commission the device or not
chip_device_config_enable_wifipaf = false
chip_device_config_enable_wifipaf = current_os == "linux"
}

if (chip_device_platform == "auto") {
Expand Down
Loading

0 comments on commit f1c2418

Please sign in to comment.