Skip to content

Commit

Permalink
* Add code-wifi to do WiFiPAF by using code.
Browse files Browse the repository at this point in the history
    example:
    - Linux DUT: sudo ./chip-all-clusters-app --wifi --wifipaf
    - Controller: sudo ./chip-tool pairing code-wifi 1 ap_ssid ap_pwd MT:-24J0SGJ10KA0648G00

Signed-off-by: Lo,Chin-Ran <[email protected]>
  • Loading branch information
crlonxp committed Jul 18, 2024
1 parent 93cf6d3 commit 1550388
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions,
#if CONFIG_NETWORK_LAYER_BLE
RendezvousInformationFlags rendezvousFlags = RendezvousInformationFlag::kBLE;
#else // CONFIG_NETWORK_LAYER_BLE
RendezvousInformationFlag rendezvousFlags = RendezvousInformationFlag::kOnNetwork;
RendezvousInformationFlags rendezvousFlags = RendezvousInformationFlag::kOnNetwork;
#endif // CONFIG_NETWORK_LAYER_BLE

#ifdef CONFIG_RENDEZVOUS_MODE
Expand Down
47 changes: 47 additions & 0 deletions src/controller/SetUpCodePairer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,22 @@ CHIP_ERROR SetUpCodePairer::StopConnectOverSoftAP()

CHIP_ERROR SetUpCodePairer::StartDiscoverOverWiFiPAF(SetupPayload & payload)
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
ChipLogProgress(Controller, "Starting commissioning discovery over WiFiPAF");

VerifyOrReturnError(mCommissioner != nullptr, CHIP_ERROR_INCORRECT_STATE);
mWaitingForDiscovery[kWiFiPAFTransport] = true;
CHIP_ERROR err = DeviceLayer::ConnectivityMgr().WiFiPAFConnect(payload.discriminator, this, OnWiFiPAFSubscribeComplete,
OnWiFiPAFSubscribeError);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Commissioning discovery over WiFiPAF failed, err = %" CHIP_ERROR_FORMAT, err.Format());
mWaitingForDiscovery[kWiFiPAFTransport] = false;
}
return err;
#else
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
#endif // CONFIG_NETWORK_LAYER_BLE
}

CHIP_ERROR SetUpCodePairer::StopConnectOverWiFiPAF()
Expand Down Expand Up @@ -355,6 +370,37 @@ void SetUpCodePairer::OnBLEDiscoveryError(CHIP_ERROR err)
}
#endif // CONFIG_NETWORK_LAYER_BLE

#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
void SetUpCodePairer::OnDiscoveredDeviceOverWifiPAF()
{
ChipLogProgress(Controller, "Discovered device to be commissioned over WiFiPAF, RemoteId: %lu", mRemoteId);

mWaitingForDiscovery[kWiFiPAFTransport] = false;
auto param = SetUpCodePairerParameters();
param.SetPeerAddress(Transport::PeerAddress(Transport::Type::kWiFiPAF, mRemoteId));
mDiscoveredParameters.emplace_front(param);
ConnectToDiscoveredDevice();
}

void SetUpCodePairer::OnWifiPAFDiscoveryError(CHIP_ERROR err)
{
ChipLogError(Controller, "Commissioning discovery over WiFiPAF failed: %" CHIP_ERROR_FORMAT, err.Format());
mWaitingForDiscovery[kWiFiPAFTransport] = false;
LogErrorOnFailure(err);
}

void SetUpCodePairer::OnWiFiPAFSubscribeComplete(void * appState)
{
(static_cast<SetUpCodePairer *>(appState))->OnDiscoveredDeviceOverWifiPAF();
}

void SetUpCodePairer::OnWiFiPAFSubscribeError(void * appState, CHIP_ERROR err)
{
static_cast<SetUpCodePairer *>(appState)->OnWifiPAFDiscoveryError(err);
}
#endif


bool SetUpCodePairer::IdIsPresent(uint16_t vendorOrProductID)
{
return vendorOrProductID != kNotAvailable;
Expand Down Expand Up @@ -493,6 +539,7 @@ void SetUpCodePairer::ResetDiscoveryState()
StopConnectOverBle();
StopConnectOverIP();
StopConnectOverSoftAP();
StopConnectOverWiFiPAF();

// Just in case any of those failed to reset the waiting state properly.
for (auto & waiting : mWaitingForDiscovery)
Expand Down
6 changes: 6 additions & 0 deletions src/controller/SetUpCodePairer.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ class DLL_EXPORT SetUpCodePairer : public DevicePairingDelegate
static void OnDiscoveredDeviceOverBleSuccess(void * appState, BLE_CONNECTION_OBJECT connObj);
static void OnDiscoveredDeviceOverBleError(void * appState, CHIP_ERROR err);
#endif // CONFIG_NETWORK_LAYER_BLE
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
void OnDiscoveredDeviceOverWifiPAF();
void OnWifiPAFDiscoveryError(CHIP_ERROR err);
static void OnWiFiPAFSubscribeComplete(void * appState);
static void OnWiFiPAFSubscribeError(void * appState, CHIP_ERROR err);
#endif

bool NodeMatchesCurrentFilter(const Dnssd::DiscoveredNodeData & nodeData) const;
static bool IdIsPresent(uint16_t vendorOrProductID);
Expand Down

0 comments on commit 1550388

Please sign in to comment.