|
66 | 66 | #include <ble/Ble.h>
|
67 | 67 | #include <transport/raw/BLE.h>
|
68 | 68 | #endif
|
| 69 | +#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF |
| 70 | +#include <transport/raw/WiFiPAF.h> |
| 71 | +#endif |
69 | 72 |
|
70 | 73 | #include <errno.h>
|
71 | 74 | #include <inttypes.h>
|
@@ -466,6 +469,13 @@ DeviceCommissioner::DeviceCommissioner() :
|
466 | 469 | mDeviceNOCChainCallback(OnDeviceNOCChainGeneration, this), mSetUpCodePairer(this)
|
467 | 470 | {}
|
468 | 471 |
|
| 472 | +DeviceCommissioner::~DeviceCommissioner() |
| 473 | +{ |
| 474 | +#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF |
| 475 | + DeviceLayer::ConnectivityMgr().WiFiPAFCancelConnect(); |
| 476 | +#endif |
| 477 | +} |
| 478 | + |
469 | 479 | CHIP_ERROR DeviceCommissioner::Init(CommissionerInitParams params)
|
470 | 480 | {
|
471 | 481 | VerifyOrReturnError(params.operationalCredentialsDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
|
@@ -730,6 +740,12 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
|
730 | 740 | peerAddress = Transport::PeerAddress::UDP(params.GetPeerAddress().GetIPAddress(), params.GetPeerAddress().GetPort(),
|
731 | 741 | params.GetPeerAddress().GetInterface());
|
732 | 742 | }
|
| 743 | +#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF |
| 744 | + else if (params.GetPeerAddress().GetTransportType() == Transport::Type::kWiFiPAF) |
| 745 | + { |
| 746 | + peerAddress = Transport::PeerAddress::WiFiPAF(remoteDeviceId); |
| 747 | + } |
| 748 | +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF |
733 | 749 |
|
734 | 750 | current = FindCommissioneeDevice(peerAddress);
|
735 | 751 | if (current != nullptr)
|
@@ -804,6 +820,24 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
|
804 | 820 | ExitNow(err = CHIP_ERROR_INVALID_ARGUMENT);
|
805 | 821 | }
|
806 | 822 | }
|
| 823 | +#endif |
| 824 | +#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF |
| 825 | + if (params.GetPeerAddress().GetTransportType() == Transport::Type::kWiFiPAF) |
| 826 | + { |
| 827 | + if (DeviceLayer::ConnectivityMgr().GetWiFiPAF()->GetWiFiPAFState() != Transport::WiFiPAFBase::State::kConnected) |
| 828 | + { |
| 829 | + ChipLogProgress(Controller, "WiFi-PAF: Subscribing the NAN-USD devices"); |
| 830 | + if (!DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted()) |
| 831 | + { |
| 832 | + ChipLogError(Controller, "Wi-Fi Management should have be started now."); |
| 833 | + ExitNow(CHIP_ERROR_INTERNAL); |
| 834 | + } |
| 835 | + mRendezvousParametersForDeviceDiscoveredOverWiFiPAF = params; |
| 836 | + DeviceLayer::ConnectivityMgr().WiFiPAFConnect(params.GetSetupDiscriminator().value(), (void *) this, |
| 837 | + OnWiFiPAFSubscribeComplete, OnWiFiPAFSubscribeError); |
| 838 | + ExitNow(CHIP_NO_ERROR); |
| 839 | + } |
| 840 | + } |
807 | 841 | #endif
|
808 | 842 | session = mSystemState->SessionMgr()->CreateUnauthenticatedSession(params.GetPeerAddress(), params.GetMRPConfig());
|
809 | 843 | VerifyOrExit(session.HasValue(), err = CHIP_ERROR_NO_MEMORY);
|
@@ -872,6 +906,43 @@ void DeviceCommissioner::OnDiscoveredDeviceOverBleError(void * appState, CHIP_ER
|
872 | 906 | }
|
873 | 907 | #endif // CONFIG_NETWORK_LAYER_BLE
|
874 | 908 |
|
| 909 | +#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF |
| 910 | +void DeviceCommissioner::OnWiFiPAFSubscribeComplete(void * appState) |
| 911 | +{ |
| 912 | + auto self = (DeviceCommissioner *) appState; |
| 913 | + auto device = self->mDeviceInPASEEstablishment; |
| 914 | + |
| 915 | + if (nullptr != device && device->GetDeviceTransportType() == Transport::Type::kWiFiPAF) |
| 916 | + { |
| 917 | + ChipLogProgress(Controller, "WiFi-PAF: Subscription Completed, dev_id = %lu", device->GetDeviceId()); |
| 918 | + auto remoteId = device->GetDeviceId(); |
| 919 | + auto params = self->mRendezvousParametersForDeviceDiscoveredOverWiFiPAF; |
| 920 | + |
| 921 | + self->mRendezvousParametersForDeviceDiscoveredOverWiFiPAF = RendezvousParameters(); |
| 922 | + self->ReleaseCommissioneeDevice(device); |
| 923 | + LogErrorOnFailure(self->EstablishPASEConnection(remoteId, params)); |
| 924 | + } |
| 925 | +} |
| 926 | + |
| 927 | +void DeviceCommissioner::OnWiFiPAFSubscribeError(void * appState, CHIP_ERROR err) |
| 928 | +{ |
| 929 | + auto self = (DeviceCommissioner *) appState; |
| 930 | + auto device = self->mDeviceInPASEEstablishment; |
| 931 | + |
| 932 | + if (nullptr != device && device->GetDeviceTransportType() == Transport::Type::kWiFiPAF) |
| 933 | + { |
| 934 | + ChipLogError(Controller, "WiFi-PAF: Subscription Error, id = %lu, err = %" CHIP_ERROR_FORMAT, device->GetDeviceId(), |
| 935 | + err.Format()); |
| 936 | + self->ReleaseCommissioneeDevice(device); |
| 937 | + self->mRendezvousParametersForDeviceDiscoveredOverWiFiPAF = RendezvousParameters(); |
| 938 | + if (self->mPairingDelegate != nullptr) |
| 939 | + { |
| 940 | + self->mPairingDelegate->OnPairingComplete(err); |
| 941 | + } |
| 942 | + } |
| 943 | +} |
| 944 | +#endif |
| 945 | + |
875 | 946 | CHIP_ERROR DeviceCommissioner::Commission(NodeId remoteDeviceId, CommissioningParameters & params)
|
876 | 947 | {
|
877 | 948 | if (mDefaultCommissioner == nullptr)
|
|
0 commit comments