Move ble to commissioning state machine (#12909)
* Add network setup commands to commissioning parameters.
* Use full commissioning state machine for BLE.
Includes network setup, so removed manual network setup from
PairingCommand and tests.
* Add check for network parameters for BLE
* Move CommissioningParameters to CommissioingDelegate
* Restyled by autopep8
* Add command to TV app
* Wrong function call on cirque.
* Try again for cirque
* fix Incorrect error checking for networking states
* Debugging on CI becuase I can't get cirque workign locally.
* Pass size with thread TLV.
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
index c16ea81..7eed756 100644
--- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp
+++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
@@ -52,6 +52,7 @@
#include <app/server/Dnssd.h>
#include <controller/CHIPDeviceController.h>
#include <controller/CHIPDeviceControllerFactory.h>
+#include <controller/CommissioningDelegate.h>
#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <credentials/DeviceAttestationVerifier.h>
#include <credentials/examples/DefaultDeviceAttestationVerifier.h>
@@ -87,6 +88,10 @@
chip::Controller::ScriptDeviceAddressUpdateDelegate sDeviceAddressUpdateDelegate;
chip::Controller::ExampleOperationalCredentialsIssuer sOperationalCredentialsIssuer;
chip::SimpleFabricStorage sFabricStorage;
+chip::Platform::ScopedMemoryBuffer<uint8_t> sSsidBuf;
+chip::Platform::ScopedMemoryBuffer<uint8_t> sCredsBuf;
+chip::Platform::ScopedMemoryBuffer<uint8_t> sThreadBuf;
+chip::Controller::CommissioningParameters sCommissioningParameters;
} // namespace
// NOTE: Remote device ID is in sync with the echo server device id
@@ -111,6 +116,8 @@
uint32_t setupPINCode, chip::NodeId nodeid);
ChipError::StorageType pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommissioner * devCtrl, const char * peerAddrStr,
uint32_t setupPINCode, chip::NodeId nodeid);
+ChipError::StorageType pychip_DeviceController_SetThreadOperationalDataset(const char * threadOperationalDataset, uint32_t size);
+ChipError::StorageType pychip_DeviceController_SetWifiCredentials(const char * ssid, const char * credentials);
ChipError::StorageType pychip_DeviceController_CloseSession(chip::Controller::DeviceCommissioner * devCtrl, chip::NodeId nodeid);
ChipError::StorageType pychip_DeviceController_EstablishPASESessionIP(chip::Controller::DeviceCommissioner * devCtrl,
const char * peerAddrStr, uint32_t setupPINCode,
@@ -316,7 +323,8 @@
chip::RendezvousParameters()
.SetPeerAddress(Transport::PeerAddress(Transport::Type::kBle))
.SetSetupPINCode(setupPINCode)
- .SetDiscriminator(discriminator))
+ .SetDiscriminator(discriminator),
+ sCommissioningParameters)
.AsInteger();
}
@@ -331,7 +339,31 @@
// TODO: IP rendezvous should use TCP connection.
addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr);
params.SetPeerAddress(addr).SetDiscriminator(0);
- return devCtrl->PairDevice(nodeid, params).AsInteger();
+ return devCtrl->PairDevice(nodeid, params, sCommissioningParameters).AsInteger();
+}
+
+ChipError::StorageType pychip_DeviceController_SetThreadOperationalDataset(const char * threadOperationalDataset, uint32_t size)
+{
+ ReturnErrorCodeIf(!sThreadBuf.Alloc(size), CHIP_ERROR_NO_MEMORY.AsInteger());
+ memcpy(sThreadBuf.Get(), threadOperationalDataset, size);
+ sCommissioningParameters.SetThreadOperationalDataset(ByteSpan(sThreadBuf.Get(), size));
+ return CHIP_NO_ERROR.AsInteger();
+}
+ChipError::StorageType pychip_DeviceController_SetWifiCredentials(const char * ssid, const char * credentials)
+{
+ size_t ssidSize = strlen(ssid);
+ ReturnErrorCodeIf(!sSsidBuf.Alloc(ssidSize), CHIP_ERROR_NO_MEMORY.AsInteger());
+ memcpy(sSsidBuf.Get(), ssid, ssidSize);
+
+ size_t credsSize = strlen(credentials);
+ ReturnErrorCodeIf(!sCredsBuf.Alloc(credsSize), CHIP_ERROR_NO_MEMORY.AsInteger());
+ memcpy(sCredsBuf.Get(), credentials, credsSize);
+
+ sCommissioningParameters.SetWifiCredentials(
+ chip::Controller::WifiCredentials(ByteSpan(sSsidBuf.Get(), ssidSize), ByteSpan(sCredsBuf.Get(), credsSize)));
+ char tmp[128];
+ chip::Platform::CopyString(tmp, sCommissioningParameters.GetWifiCredentials().Value().ssid);
+ return CHIP_NO_ERROR.AsInteger();
}
void CloseSessionCallback(DeviceProxy * device, ChipError::StorageType err)