diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index c22841355d3422..1d478c6b7801e5 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -118,28 +118,9 @@ void PairingCommand::OnStatusUpdate(RendezvousSessionDelegate::Status status) case RendezvousSessionDelegate::Status::SecurePairingFailed: ChipLogError(chipTool, "Secure Pairing Failed"); break; - case RendezvousSessionDelegate::Status::NetworkProvisioningSuccess: - ChipLogProgress(chipTool, "Network Provisioning Success"); - break; - case RendezvousSessionDelegate::Status::NetworkProvisioningFailed: - ChipLogError(chipTool, "Network Provisioning Failed"); - break; } } -void PairingCommand::OnNetworkCredentialsRequested(RendezvousDeviceCredentialsDelegate * callback) -{ - ChipLogProgress(chipTool, "OnNetworkCredentialsRequested"); - callback->SendNetworkCredentials(mSSID, mPassword); -} - -void PairingCommand::OnOperationalCredentialsRequested(const char * csr, size_t csr_length, - RendezvousDeviceCredentialsDelegate * callback) -{ - // TODO Implement this - ChipLogProgress(chipTool, "OnOperationalCredentialsRequested"); -} - void PairingCommand::OnPairingComplete(CHIP_ERROR err) { if (err == CHIP_NO_ERROR) diff --git a/examples/chip-tool/commands/pairing/PairingCommand.h b/examples/chip-tool/commands/pairing/PairingCommand.h index c03c299353f955..485156a9170413 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.h +++ b/examples/chip-tool/commands/pairing/PairingCommand.h @@ -98,9 +98,6 @@ class PairingCommand : public Command, /////////// DevicePairingDelegate Interface ///////// void OnStatusUpdate(chip::RendezvousSessionDelegate::Status status) override; - void OnNetworkCredentialsRequested(chip::RendezvousDeviceCredentialsDelegate * callback) override; - void OnOperationalCredentialsRequested(const char * csr, size_t csr_length, - chip::RendezvousDeviceCredentialsDelegate * callback) override; void OnPairingComplete(CHIP_ERROR error) override; void OnPairingDeleted(CHIP_ERROR error) override; diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/GenericChipDeviceListener.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/GenericChipDeviceListener.kt index 26a7d1740d1d21..c5f96e4671a096 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/GenericChipDeviceListener.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/GenericChipDeviceListener.kt @@ -11,14 +11,6 @@ open class GenericChipDeviceListener : ChipDeviceController.CompletionListener { // No op } - override fun onNetworkCredentialsRequested() { - // No op - } - - override fun onOperationalCredentialsRequested(opCreds: ByteArray?) { - // No op - } - override fun onStatusUpdate(status: Int) { // No op } diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt index 52a042e9497bab..31d9dcd0da6a2a 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt @@ -129,12 +129,6 @@ class DeviceProvisioningFragment : Fragment() { } } - override fun onNetworkCredentialsRequested() { - childFragmentManager.beginTransaction() - .add(R.id.fragment_container, EnterNetworkFragment.newInstance(networkType)) - .commit() - } - override fun onPairingComplete(code: Int) { Log.d(TAG, "onPairingComplete: $code") } diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt index 9517724496f2c8..9d71b0ba3b3db0 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/EnterNetworkFragment.kt @@ -75,9 +75,7 @@ class EnterNetworkFragment : Fragment() { return } - ChipClient.getDeviceController().apply { - sendWiFiCredentials(ssid.toString(), pwd.toString()) - } + // Do something with the credentials } private fun saveThreadNetwork() { @@ -116,11 +114,7 @@ class EnterNetworkFragment : Fragment() { return } - ChipClient.getDeviceController().sendThreadCredentials( - channelStr.toString().toInt(), - panIdStr.toString().toInt(16), - xpanIdStr.hexToByteArray(), - masterKeyStr.hexToByteArray()) + // Do something with the credentials } private fun String.hexToByteArray(): ByteArray { diff --git a/src/app/clusters/network-commissioning/network-commissioning.cpp b/src/app/clusters/network-commissioning/network-commissioning.cpp index 3a8479e31f4d7e..8277f685ddfbbe 100644 --- a/src/app/clusters/network-commissioning/network-commissioning.cpp +++ b/src/app/clusters/network-commissioning/network-commissioning.cpp @@ -42,8 +42,6 @@ #include #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD -#include - // Include DeviceNetworkProvisioningDelegateImpl for WiFi provisioning. // TODO: Enable wifi network should be done by ConnectivityManager. (Or other platform neutral interfaces) #if defined(CHIP_DEVICE_LAYER_TARGET) diff --git a/src/app/server/RendezvousServer.cpp b/src/app/server/RendezvousServer.cpp index 1e4f75ffcece18..89f66f65929bb4 100644 --- a/src/app/server/RendezvousServer.cpp +++ b/src/app/server/RendezvousServer.cpp @@ -98,26 +98,6 @@ void RendezvousServer::OnRendezvousStatusUpdate(Status status, CHIP_ERROR err) } break; - case RendezvousSessionDelegate::NetworkProvisioningSuccess: - ChipLogProgress(AppServer, "Device was assigned network credentials"); - if (chip::Mdns::ServiceAdvertiser::Instance().Start(&DeviceLayer::InetLayer, chip::Mdns::kMdnsPort) != CHIP_NO_ERROR) - { - ChipLogError(AppServer, "Failed to start mDNS advertisement"); - } - if (mDelegate != nullptr) - { - mDelegate->OnRendezvousStopped(); - } - break; - - case RendezvousSessionDelegate::NetworkProvisioningFailed: - ChipLogProgress(AppServer, "Failed in network provisioning"); - if (mDelegate != nullptr) - { - mDelegate->OnRendezvousStopped(); - } - break; - default: break; }; diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index de7717bcb296f0..315fc515af7444 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -44,6 +44,10 @@ #include #include +#if CONFIG_DEVICE_LAYER +#include +#endif + #if CONFIG_NETWORK_LAYER_BLE #include #endif @@ -89,25 +93,6 @@ class DLL_EXPORT DevicePairingDelegate */ virtual void OnStatusUpdate(RendezvousSessionDelegate::Status status) {} - /** - * @brief - * Called when the network credentials are needed for the remote device - * - * @param callback Callback delegate that provisions the network credentials - */ - virtual void OnNetworkCredentialsRequested(RendezvousDeviceCredentialsDelegate * callback) = 0; - - /** - * @brief - * Called when the operational credentials are needed for the remote device - * - * @param csr Certificate signing request from the device - * @param csr_length The length of CSR - * @param callback Callback delegate that provisions the operational credentials - */ - virtual void OnOperationalCredentialsRequested(const char * csr, size_t csr_length, - RendezvousDeviceCredentialsDelegate * callback) = 0; - /** * @brief * Called when the pairing is complete (with success or error) diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 0917afb769d9df..965d8f7d813f7d 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -215,84 +215,6 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(Jav return wrapper.release(); } -void AndroidDeviceControllerWrapper::SendNetworkCredentials(const char * ssid, const char * password) -{ - if (mCredentialsDelegate == nullptr) - { - ChipLogError(Controller, "No credential callback available to send Wi-Fi credentials."); - return; - } - - ChipLogProgress(Controller, "Sending network credentials for %s...", ssid); - mCredentialsDelegate->SendNetworkCredentials(ssid, password); -} - -void AndroidDeviceControllerWrapper::SendThreadCredentials(chip::ByteSpan threadData) -{ - if (mCredentialsDelegate == nullptr) - { - ChipLogError(Controller, "No credential callback available to send Thread credentials."); - return; - } - - chip::Thread::OperationalDataset dataset{}; - - if (!dataset.Init(threadData)) - { - ChipLogError(Controller, "Failed to parse Thread credentials."); - return; - } - - uint16_t channel = chip::Thread::kChannel_NotSpecified; - uint16_t panid = chip::Thread::kPANId_NotSpecified; - - dataset.GetChannel(channel); - dataset.GetPanId(panid); - - ChipLogProgress(Controller, "Sending Thread credentials for channel %u, PAN ID 0x%04x...", channel, panid); - mCredentialsDelegate->SendThreadCredentials(threadData); -} - -void AndroidDeviceControllerWrapper::OnNetworkCredentialsRequested(chip::RendezvousDeviceCredentialsDelegate * callback) -{ - mCredentialsDelegate = callback; - - JNIEnv * env = GetJavaEnv(); - - jmethodID method; - if (!FindMethod(env, mJavaObjectRef, "onNetworkCredentialsRequested", "()V", &method)) - { - return; - } - - env->ExceptionClear(); - env->CallVoidMethod(mJavaObjectRef, method); -} - -void AndroidDeviceControllerWrapper::OnOperationalCredentialsRequested(const char * csr, size_t csr_length, - chip::RendezvousDeviceCredentialsDelegate * callback) -{ - mCredentialsDelegate = callback; - - JNIEnv * env = GetJavaEnv(); - - jbyteArray jCsr; - if (!N2J_ByteArray(env, reinterpret_cast(csr), csr_length, jCsr)) - { - ChipLogError(Controller, "Failed to build byte array for operational credential request"); - return; - } - - jmethodID method; - if (!FindMethod(env, mJavaObjectRef, "onOperationalCredentialsRequested", "([B)V", &method)) - { - return; - } - - env->ExceptionClear(); - env->CallVoidMethod(mJavaObjectRef, method, jCsr); -} - void AndroidDeviceControllerWrapper::OnStatusUpdate(chip::RendezvousSessionDelegate::Status status) { CallVoidInt(GetJavaEnv(), mJavaObjectRef, "onStatusUpdate", static_cast(status)); diff --git a/src/controller/java/AndroidDeviceControllerWrapper.h b/src/controller/java/AndroidDeviceControllerWrapper.h index 563239f238976b..23ee074b386b4c 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.h +++ b/src/controller/java/AndroidDeviceControllerWrapper.h @@ -40,13 +40,7 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel chip::Controller::DeviceCommissioner * Controller() { return mController.get(); } void SetJavaObjectRef(JavaVM * vm, jobject obj); - void SendNetworkCredentials(const char * ssid, const char * password); - void SendThreadCredentials(chip::ByteSpan threadData); - // DevicePairingDelegate implementation - void OnNetworkCredentialsRequested(chip::RendezvousDeviceCredentialsDelegate * callback) override; - void OnOperationalCredentialsRequested(const char * csr, size_t csr_length, - chip::RendezvousDeviceCredentialsDelegate * callback) override; void OnStatusUpdate(chip::RendezvousSessionDelegate::Status status) override; void OnPairingComplete(CHIP_ERROR error) override; void OnPairingDeleted(CHIP_ERROR error) override; @@ -82,8 +76,7 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel using ChipDeviceControllerPtr = std::unique_ptr; ChipDeviceControllerPtr mController; - chip::RendezvousDeviceCredentialsDelegate * mCredentialsDelegate = nullptr; - chip::PersistentStorageResultDelegate * mStorageResultDelegate = nullptr; + chip::PersistentStorageResultDelegate * mStorageResultDelegate = nullptr; JavaVM * mJavaVM = nullptr; jobject mJavaObjectRef = nullptr; diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 6c7ef31cc04662..73b33a9c43f98c 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -322,65 +322,6 @@ JNI_METHOD(void, stopDevicePairing)(JNIEnv * env, jobject self, jlong handle, jl } } -JNI_METHOD(void, sendWiFiCredentials)(JNIEnv * env, jobject self, jlong handle, jstring ssid, jstring password) -{ - JniUtfString ssidStr(env, ssid); - JniUtfString passwordStr(env, password); - - ChipLogProgress(Controller, "Sending Wi-Fi credentials for: %s", ssidStr.c_str()); - { - ScopedPthreadLock lock(&sStackLock); - AndroidDeviceControllerWrapper::FromJNIHandle(handle)->SendNetworkCredentials(ssidStr.c_str(), passwordStr.c_str()); - } -} - -JNI_METHOD(void, sendThreadCredentials) -(JNIEnv * env, jobject self, jlong handle, jint channel, jint panId, jbyteArray xpanId, jbyteArray masterKey) -{ - using namespace chip::DeviceLayer::Internal; - - JniByteArray xpanIdBytes(env, xpanId); - JniByteArray masterKeyBytes(env, masterKey); - - VerifyOrReturn(CanCastTo(channel), ChipLogError(Controller, "sendThreadCredentials() called with invalid Channel")); - VerifyOrReturn(CanCastTo(panId), ChipLogError(Controller, "sendThreadCredentials() called with invalid PAN ID")); - VerifyOrReturn(xpanIdBytes.size() == static_cast(Thread::kSizeExtendedPanId), - ChipLogError(Controller, "sendThreadCredentials() called with invalid XPAN ID")); - VerifyOrReturn(masterKeyBytes.size() == static_cast(Thread::kSizeMasterKey), - ChipLogError(Controller, "sendThreadCredentials() called with invalid Master Key")); - - Thread::OperationalDataset dataset{}; - - dataset.SetChannel(channel); - dataset.SetPanId(panId); - - // TODO network name is required, need to add UI - { - char networkName[Thread::kSizeNetworkName + 1]; - - snprintf(networkName, sizeof(networkName), "CHIP-%04X", panId); - dataset.SetNetworkName(networkName); - } - - { - uint8_t value[Thread::kSizeMasterKey]; - - memcpy(value, masterKeyBytes.data(), sizeof(value)); - - dataset.SetMasterKey(value); - } - { - uint8_t value[Thread::kSizeExtendedPanId]; - - memcpy(value, xpanIdBytes.data(), sizeof(value)); - - dataset.SetExtendedPanId(value); - } - - ScopedPthreadLock lock(&sStackLock); - AndroidDeviceControllerWrapper::FromJNIHandle(handle)->SendThreadCredentials(dataset.AsByteSpan()); -} - JNI_METHOD(void, pairTestDeviceWithoutSecurity)(JNIEnv * env, jobject self, jlong handle, jstring deviceAddr) { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 2872fc3fff8075..b53e62c38f22ae 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -78,14 +78,6 @@ public void pairDevice(long deviceId, int connectionId, long pinCode) { pairDevice(deviceControllerPtr, deviceId, connectionId, pinCode); } - public void sendWiFiCredentials(String ssid, String password) { - sendWiFiCredentials(deviceControllerPtr, ssid, password); - } - - public void sendThreadCredentials(int channel, int panId, byte[] xpanId, byte[] masterKey) { - sendThreadCredentials(deviceControllerPtr, channel, panId, xpanId, masterKey); - } - public boolean disconnectDevice(long deviceId) { return disconnectDevice(deviceControllerPtr, deviceId); } @@ -98,18 +90,6 @@ public void onSendMessageComplete(String message) { completionListener.onSendMessageComplete(message); } - public void onNetworkCredentialsRequested() { - if (completionListener != null) { - completionListener.onNetworkCredentialsRequested(); - } - } - - public void onOperationalCredentialsRequested(byte[] csr) { - if (completionListener != null) { - completionListener.onOperationalCredentialsRequested(csr); - } - } - public void onStatusUpdate(int status) { if (completionListener != null) { completionListener.onStatusUpdate(status); @@ -201,11 +181,6 @@ private native void pairDevice( private native void pairTestDeviceWithoutSecurity(long deviceControllerPtr, String ipAddress); - private native void sendWiFiCredentials(long deviceControllerPtr, String ssid, String password); - - private native void sendThreadCredentials( - long deviceControllerPtr, int channel, int panId, byte[] xpanId, byte[] masterKey); - private native boolean disconnectDevice(long deviceControllerPtr, long deviceId); private native void deleteDeviceController(long deviceControllerPtr); @@ -244,12 +219,6 @@ public interface CompletionListener { /** Notifies the completion of "SendMessage" echo command. */ void onSendMessageComplete(String message); - /** Notifies that the device is ready to receive Wi-Fi network credentials. */ - void onNetworkCredentialsRequested(); - - /** Notifies that the device is ready to receive operational credentials. */ - void onOperationalCredentialsRequested(byte[] csr); - /** Notifies the pairing status. */ void onStatusUpdate(int status); diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index ba1d14009c031d..0e2fb3ec26f4f3 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -92,12 +92,6 @@ CHIP_ERROR pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommissione // Pairing Delegate CHIP_ERROR -pychip_ScriptDevicePairingDelegate_SetWifiCredential(chip::Controller::DeviceCommissioner * devCtrl, const char * ssid, - const char * password); -CHIP_ERROR -pychip_ScriptDevicePairingDelegate_SetThreadCredential(chip::Controller::DeviceCommissioner * devCtrl, int channel, int panId, - const char * masterKey); -CHIP_ERROR pychip_ScriptDevicePairingDelegate_SetKeyExchangeCallback(chip::Controller::DeviceCommissioner * devCtrl, chip::Controller::DevicePairingDelegate_OnPairingCompleteFunct callback); @@ -229,41 +223,6 @@ CHIP_ERROR pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommissione return devCtrl->PairDevice(nodeid, params); } -CHIP_ERROR -pychip_ScriptDevicePairingDelegate_SetWifiCredential(chip::Controller::DeviceCommissioner * devCtrl, const char * ssid, - const char * password) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - (void) devCtrl; - - VerifyOrExit(ssid != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrExit(password != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); - - sPairingDelegate.SetWifiCredential(ssid, password); - -exit: - return err; -} - -CHIP_ERROR -pychip_ScriptDevicePairingDelegate_SetThreadCredential(chip::Controller::DeviceCommissioner * devCtrl, int channel, int panId, - const char * masterKeyStr) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - uint8_t masterKey[chip::Thread::kSizeMasterKey]; - (void) devCtrl; - - VerifyOrExit(strlen(masterKeyStr) == 2 * chip::Thread::kSizeMasterKey, err = CHIP_ERROR_INVALID_ARGUMENT); - - for (size_t i = 0; i < chip::Thread::kSizeMasterKey; i++) - VerifyOrExit(sscanf(&masterKeyStr[2 * i], "%2hhx", &masterKey[i]) == 1, err = CHIP_ERROR_INVALID_ARGUMENT); - - sPairingDelegate.SetThreadCredential(channel, panId, masterKey); - -exit: - return err; -} - CHIP_ERROR pychip_ScriptDevicePairingDelegate_SetKeyExchangeCallback(chip::Controller::DeviceCommissioner * devCtrl, chip::Controller::DevicePairingDelegate_OnPairingCompleteFunct callback) diff --git a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp index 578248b3785e71..4217c4d218838c 100644 --- a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp +++ b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp @@ -24,37 +24,6 @@ namespace chip { namespace Controller { -void ScriptDevicePairingDelegate::SetWifiCredential(const char * ssid, const char * password) -{ - strncpy(mWifiSSID, ssid, sizeof(mWifiSSID)); - strncpy(mWifiPassword, password, sizeof(mWifiPassword)); - mMode = Mode::Wifi; -} - -void ScriptDevicePairingDelegate::SetThreadCredential(uint8_t channel, uint16_t panId, - uint8_t (&masterKey)[chip::Thread::kSizeMasterKey]) -{ - mThreadInfo.SetChannel(channel); - mThreadInfo.SetPanId(panId); - mThreadInfo.SetMasterKey(masterKey); - mMode = Mode::Thread; -} - -void ScriptDevicePairingDelegate::OnNetworkCredentialsRequested(RendezvousDeviceCredentialsDelegate * callback) -{ - if (mMode == Mode::Wifi) - callback->SendNetworkCredentials(mWifiSSID, mWifiPassword); - else - callback->SendThreadCredentials(mThreadInfo.AsByteSpan()); -} - -void ScriptDevicePairingDelegate::OnOperationalCredentialsRequested(const char * csr, size_t csr_length, - RendezvousDeviceCredentialsDelegate * callback) -{ - // TODO: Implement this - ChipLogDetail(Controller, "ScriptDevicePairingDelegate::OnOperationalCredentialsRequested\n"); -} - void ScriptDevicePairingDelegate::SetKeyExchangeCallback(DevicePairingDelegate_OnPairingCompleteFunct callback) { mOnPairingCompleteCallback = callback; diff --git a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h index cca5365db99498..a08e8f877b803d 100644 --- a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h +++ b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h @@ -26,9 +26,6 @@ #pragma once #include - -#include -#include #include namespace chip { @@ -42,32 +39,10 @@ class ScriptDevicePairingDelegate final : public Controller::DevicePairingDelega { public: ~ScriptDevicePairingDelegate() = default; - void SetWifiCredential(const char * ssid, const char * password); - void SetThreadCredential(uint8_t channel, uint16_t panId, uint8_t (&masterKey)[chip::Thread::kSizeMasterKey]); void SetKeyExchangeCallback(DevicePairingDelegate_OnPairingCompleteFunct callback); - - void OnNetworkCredentialsRequested(RendezvousDeviceCredentialsDelegate * callback) override; - - void OnOperationalCredentialsRequested(const char * csr, size_t csr_length, - RendezvousDeviceCredentialsDelegate * callback) override; - void OnPairingComplete(CHIP_ERROR error) override; private: - // WiFi Provisioning Data - char mWifiSSID[chip::DeviceLayer::Internal::kMaxWiFiSSIDLength + 1]; - char mWifiPassword[chip::DeviceLayer::Internal::kMaxWiFiKeyLength]; - - // Thread Provisioning Data - chip::Thread::OperationalDataset mThreadInfo = {}; - - enum class Mode - { - Wifi, - Thread - }; - - Mode mMode = Mode::Wifi; DevicePairingDelegate_OnPairingCompleteFunct mOnPairingCompleteCallback = nullptr; }; diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index f51f5855575d0c..b87047356f9a94 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -249,18 +249,6 @@ def GetLogFilter(self): def SetBlockingCB(self, blockingCB): self._ChipStack.blockingCB = blockingCB - def SetWifiCredential(self, ssid, password): - ret = self._dmLib.pychip_ScriptDevicePairingDelegate_SetWifiCredential( - self.devCtrl, ssid.encode("utf-8") + b'\0', password.encode("utf-8") + b'\0') - if ret != 0: - raise self._ChipStack.ErrorToException(res) - - def SetThreadCredential(self, channel, panid, masterKey): - ret = self._dmLib.pychip_ScriptDevicePairingDelegate_SetThreadCredential( - self.devCtrl, channel, panid, masterKey.encode("utf-8") + b'\0') - if ret != 0: - raise self._ChipStack.ErrorToException(ret) - # ----- Private Members ----- def _InitLib(self): if self._dmLib is None: @@ -286,10 +274,6 @@ def _InitLib(self): c_void_p, c_uint64, c_char_p, c_uint64, POINTER(c_uint16)] self._dmLib.pychip_DeviceController_GetAddressAndPort.restype = c_uint32 - self._dmLib.pychip_ScriptDevicePairingDelegate_SetWifiCredential.argtypes = [ - c_void_p, c_char_p, c_char_p] - self._dmLib.pychip_ScriptDevicePairingDelegate_SetWifiCredential.restype = c_uint32 - self._dmLib.pychip_ScriptDevicePairingDelegate_SetKeyExchangeCallback.argtypes = [ c_void_p, _DevicePairingDelegate_OnPairingCompleteFunct] self._dmLib.pychip_ScriptDevicePairingDelegate_SetKeyExchangeCallback.restype = c_uint32 diff --git a/src/controller/python/chip/internal/CommissionerImpl.cpp b/src/controller/python/chip/internal/CommissionerImpl.cpp index af207f78abcec7..ee6b72efb9adad 100644 --- a/src/controller/python/chip/internal/CommissionerImpl.cpp +++ b/src/controller/python/chip/internal/CommissionerImpl.cpp @@ -64,36 +64,10 @@ class ServerStorageDelegate : public chip::PersistentStorageDelegate class ScriptDevicePairingDelegate final : public chip::Controller::DevicePairingDelegate { public: - using OnNetworkCredentialsRequestedCallback = void (*)(); - using OnOperationalCredentialsRequestedCallback = void (*)(const char * csr, size_t length); - using OnPairingCompleteCallback = void (*)(CHIP_ERROR err); + using OnPairingCompleteCallback = void (*)(CHIP_ERROR err); ~ScriptDevicePairingDelegate() = default; - void OnNetworkCredentialsRequested(chip::RendezvousDeviceCredentialsDelegate * callback) override - { - mCredentialsDelegate = callback; - if (mNetworkCredentialsRequested == nullptr) - { - ChipLogError(Controller, "Callback for network credentials is not defined."); - return; - } - mNetworkCredentialsRequested(); - } - - void OnOperationalCredentialsRequested(const char * csr, size_t csr_length, - chip::RendezvousDeviceCredentialsDelegate * callback) override - { - mCredentialsDelegate = callback; - if (mOperationalCredentialsRequested == nullptr) - { - ChipLogError(Controller, "Callback for operational credentials is not defined."); - return; - } - - mOperationalCredentialsRequested(csr, csr_length); - } - void OnPairingComplete(CHIP_ERROR error) override { if (mPairingComplete == nullptr) @@ -104,47 +78,10 @@ class ScriptDevicePairingDelegate final : public chip::Controller::DevicePairing mPairingComplete(error); } - void SetNetworkCredentialsRequestedCallback(OnNetworkCredentialsRequestedCallback callback) - { - mNetworkCredentialsRequested = callback; - } - - void SetOperatioonalCredentialsRequestedCallback(OnOperationalCredentialsRequestedCallback callback) - { - mOperationalCredentialsRequested = callback; - } - void SetPairingCompleteCallback(OnPairingCompleteCallback callback) { mPairingComplete = callback; } - void SetWifiCredentials(const char * ssid, const char * password) - { - if (mCredentialsDelegate == nullptr) - { - ChipLogError(Controller, "Wifi credentials received before delegate available."); - return; - } - - mCredentialsDelegate->SendNetworkCredentials(ssid, password); - } - - void SetThreadCredentials(chip::ByteSpan threadData) - { - if (mCredentialsDelegate == nullptr) - { - ChipLogError(Controller, "Thread credentials received before delegate available."); - return; - } - - mCredentialsDelegate->SendThreadCredentials(threadData); - } - private: - OnNetworkCredentialsRequestedCallback mNetworkCredentialsRequested = nullptr; - OnOperationalCredentialsRequestedCallback mOperationalCredentialsRequested = nullptr; - OnPairingCompleteCallback mPairingComplete = nullptr; - - /// Delegate is set during request callbacks - chip::RendezvousDeviceCredentialsDelegate * mCredentialsDelegate = nullptr; + OnPairingCompleteCallback mPairingComplete = nullptr; }; ServerStorageDelegate gServerStorage; @@ -152,69 +89,6 @@ ScriptDevicePairingDelegate gPairingDelegate; } // namespace -extern "C" void pychip_internal_PairingDelegate_SetWifiCredentials(const char * ssid, const char * password) -{ - chip::python::ChipMainThreadScheduleAndWait([&]() { gPairingDelegate.SetWifiCredentials(ssid, password); }); -} - -extern "C" CHIP_ERROR pychip_internal_PairingDelegate_SetThreadCredentials(const void * data, uint32_t length) -{ - chip::Thread::OperationalDataset dataset{}; - CHIP_ERROR err = CHIP_NO_ERROR; - - struct - { - uint64_t mActiveTimestamp; - uint8_t mMasterKey[chip::Thread::kSizeMasterKey]; - uint8_t mPSKc[chip::Thread::kSizePSKc]; - uint8_t mExtendedPanId[chip::Thread::kSizeExtendedPanId]; - uint8_t mMeshLocalPrefix[chip::Thread::kSizeMeshLocalPrefix]; - uint16_t mPanId; - char mNetworkName[chip::Thread::kSizeNetworkName + 1]; - uint8_t mChannel; - } netInfo; - - assert(length == sizeof(netInfo)); - - memcpy(&netInfo, data, length); - - if (netInfo.mNetworkName[0] != 0) - { - SuccessOrExit(err = dataset.SetNetworkName(netInfo.mNetworkName)); - } - - SuccessOrExit(err = dataset.SetExtendedPanId(netInfo.mExtendedPanId)); - SuccessOrExit(err = dataset.SetMeshLocalPrefix(netInfo.mMeshLocalPrefix)); - SuccessOrExit(err = dataset.SetMasterKey(netInfo.mMasterKey)); - SuccessOrExit(err = dataset.SetPSKc(netInfo.mPSKc)); - SuccessOrExit(err = dataset.SetPanId(netInfo.mPanId)); - SuccessOrExit(err = dataset.SetChannel(netInfo.mChannel)); - SuccessOrExit(err = dataset.SetActiveTimestamp(netInfo.mActiveTimestamp)); - - if (!dataset.IsCommissioned()) - { - ChipLogError(Controller, "Invalid Thread operational dataset"); - return CHIP_ERROR_INVALID_ARGUMENT; - } - - chip::python::ChipMainThreadScheduleAndWait([&]() { gPairingDelegate.SetThreadCredentials(dataset.AsByteSpan()); }); - -exit: - return CHIP_NO_ERROR; -} - -extern "C" void pychip_internal_PairingDelegate_SetNetworkCredentialsRequestedCallback( - ScriptDevicePairingDelegate::OnNetworkCredentialsRequestedCallback callback) -{ - gPairingDelegate.SetNetworkCredentialsRequestedCallback(callback); -} - -extern "C" void pychip_internal_PairingDelegate_SetOperationalCredentialsRequestedCallback( - ScriptDevicePairingDelegate::OnOperationalCredentialsRequestedCallback callback) -{ - gPairingDelegate.SetOperatioonalCredentialsRequestedCallback(callback); -} - extern "C" void pychip_internal_PairingDelegate_SetPairingCompleteCallback(ScriptDevicePairingDelegate::OnPairingCompleteCallback callback) { diff --git a/src/controller/python/chip/internal/commissioner.py b/src/controller/python/chip/internal/commissioner.py index 2cdbb1c1a79815..07b004bfe0278c 100644 --- a/src/controller/python/chip/internal/commissioner.py +++ b/src/controller/python/chip/internal/commissioner.py @@ -69,8 +69,6 @@ def __init__(self, handle: ctypes.CDLL, native: Commissioner_p): self._handle = handle self._native = native self.pairing_state = PairingState.INITIALIZED - self.on_network_credentials_requested = None - self.on_operational_credentials_requested = None self.on_pairing_complete = None @@ -81,45 +79,11 @@ def BlePair(self, remoteDeviceId: int, pinCode: int, discriminator: int): self.pairing_state = PairingState.PAIRING - def PairSendWifiCredentials(self, ssid: str, password: str): - """Send wifi credentials to the actively connected device.""" - - if self.pairing_state != PairingState.NEEDS_NETCREDS: - raise Exception("Not in a state requiring network credentials") - - self._handle.pychip_internal_PairingDelegate_SetWifiCredentials(c_char_p(ssid.encode('utf8')), c_char_p(password.encode('utf8'))) - - def PairSendThreadCredentials(self, threadBlob: bytes): - """Send thread credentials. Thread credentials is an opaque blob from the API perspective.""" - - if self.pairing_state != PairingState.NEEDS_NETCREDS: - raise Exception("Not in a state requiring network credentials") - - if type(threadBlob) != bytes: - raise Exception("Thread credentials MUST be of type bytes") - - result = self._handle.pychip_internal_PairingDelegate_SetThreadCredentials(threadBlob, len(threadBlob)) - - if result != 0: - raise Exception("Failed to send thread credentials. CHIP Error code %d" % result) - - def Unpair(self, remoteDeviceId: int): result = self._handle.pychip_internal_Commissioner_Unpair(self._native, remoteDeviceId) if result != 0: raise Exception("Failed to unpair. CHIP Error code %d" % result) - - def _OnNetworkCredentialsRequested(self): - self.pairing_state = PairingState.NEEDS_NETCREDS - if self.on_network_credentials_requested: - self.on_network_credentials_requested() - - def _OnOperationalCredentialsRequested(self, csr: bytes): - self.pairing_state = PairingState.NEEDS_OPCREDS - if self.on_operational_credentials_requested: - self.on_operational_credentials_requested(csr) - def _OnPairingComplete(self, err: int): self.pairing_state = PairingState.INITIALIZED if self.on_pairing_complete: @@ -134,12 +98,7 @@ def _SetNativeCallSignatues(handle: ctypes.CDLL): setter.Set('pychip_internal_Commissioner_Unpair', c_uint32, [Commissioner_p, c_uint64]) setter.Set('pychip_internal_Commissioner_BleConnectForPairing', c_uint32, [Commissioner_p, c_uint64, c_uint32, c_uint16]) - setter.Set('pychip_internal_PairingDelegate_SetNetworkCredentialsRequestedCallback', None, [NetworkCredentialsRequested]) - setter.Set('pychip_internal_PairingDelegate_SetOperationalCredentialsRequestedCallback', None, [OperationalCredentialsRequested]) setter.Set('pychip_internal_PairingDelegate_SetPairingCompleteCallback', None, [PairingComplete]) - setter.Set('pychip_internal_PairingDelegate_SetWifiCredentials', None, [c_char_p, c_char_p]) - setter.Set('pychip_internal_PairingDelegate_SetThreadCredentials', c_uint32, [ThreadBlob_p, c_uint32]) - commissionerSingleton: Optional[Commissioner] = None @@ -159,8 +118,6 @@ def GetCommissioner() -> Commissioner: if not native: raise Exception('Failed to create commissioner object.') - handle.pychip_internal_PairingDelegate_SetNetworkCredentialsRequestedCallback(OnNetworkCredentialsRequested) - handle.pychip_internal_PairingDelegate_SetOperationalCredentialsRequestedCallback(OnOperationalCredentialsRequested) handle.pychip_internal_PairingDelegate_SetPairingCompleteCallback(OnPairingComplete) commissionerSingleton = Commissioner(handle, native) diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m index 747c480cf90573..caf939dc654e1b 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m @@ -599,10 +599,6 @@ - (void)onAddressUpdated:(NSError *)error } } -- (void)onNetworkCredentialsRequested:(CHIPNetworkCredentialType)type -{ -} - - (void)updateUIFields:(CHIPSetupPayload *)payload decimalString:(nullable NSString *)decimalString { if (decimalString) { diff --git a/src/darwin/Framework/CHIP/CHIPDevicePairingDelegate.h b/src/darwin/Framework/CHIP/CHIPDevicePairingDelegate.h index d6009f3075623b..28a88add1b9840 100644 --- a/src/darwin/Framework/CHIP/CHIPDevicePairingDelegate.h +++ b/src/darwin/Framework/CHIP/CHIPDevicePairingDelegate.h @@ -22,30 +22,15 @@ NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(NSUInteger, CHIPPairingStatus) { kSecurePairingSuccess = 0, kSecurePairingFailed, - kNetworkProvisioningSuccess, - kNetworkProvisioningFailed, kUnknownStatus, }; -typedef NS_ENUM(NSUInteger, CHIPNetworkCredentialType) { - kNetworkCredentialTypeWiFi = 0, - kNetworkCredentialTypeThread, - kNetworkCredentialTypeAll, -}; - /** * The protocol definition for the CHIPDevicePairingDelegate * * All delegate methods will be called on the supplied Delegate Queue. */ @protocol CHIPDevicePairingDelegate -@required -/** - * Notify the delegate when pairing requires network credentials along with the NetworkCredentialType requested - * - */ -- (void)onNetworkCredentialsRequested:(CHIPNetworkCredentialType)type; - @optional /** * Notify the delegate when pairing status gets updated diff --git a/src/darwin/Framework/CHIP/CHIPDevicePairingDelegateBridge.h b/src/darwin/Framework/CHIP/CHIPDevicePairingDelegateBridge.h index 59c9fa5aa383df..be73e3b3e1838f 100644 --- a/src/darwin/Framework/CHIP/CHIPDevicePairingDelegateBridge.h +++ b/src/darwin/Framework/CHIP/CHIPDevicePairingDelegateBridge.h @@ -24,24 +24,16 @@ NS_ASSUME_NONNULL_BEGIN class CHIPDevicePairingDelegateBridge : public chip::Controller::DevicePairingDelegate, - public chip::Controller::DeviceAddressUpdateDelegate { + public chip::Controller::DeviceAddressUpdateDelegate +{ public: CHIPDevicePairingDelegateBridge(); ~CHIPDevicePairingDelegateBridge(); void setDelegate(id delegate, dispatch_queue_t queue); - void SendWiFiCredentials(NSString * ssid, NSString * password); - - void SendThreadCredentials(NSData * threadDataSet); - void OnStatusUpdate(chip::RendezvousSessionDelegate::Status status) override; - void OnNetworkCredentialsRequested(chip::RendezvousDeviceCredentialsDelegate * callback) override; - - void OnOperationalCredentialsRequested( - const char * csr, size_t csr_length, chip::RendezvousDeviceCredentialsDelegate * callback) override; - void OnPairingComplete(CHIP_ERROR error) override; void OnPairingDeleted(CHIP_ERROR error) override; diff --git a/src/darwin/Framework/CHIP/CHIPDevicePairingDelegateBridge.mm b/src/darwin/Framework/CHIP/CHIPDevicePairingDelegateBridge.mm index 67d070cc99798f..11e69b1e067790 100644 --- a/src/darwin/Framework/CHIP/CHIPDevicePairingDelegateBridge.mm +++ b/src/darwin/Framework/CHIP/CHIPDevicePairingDelegateBridge.mm @@ -46,12 +46,6 @@ case chip::RendezvousSessionDelegate::Status::SecurePairingFailed: rv = kSecurePairingFailed; break; - case chip::RendezvousSessionDelegate::Status::NetworkProvisioningSuccess: - rv = kNetworkProvisioningSuccess; - break; - case chip::RendezvousSessionDelegate::Status::NetworkProvisioningFailed: - rv = kNetworkProvisioningFailed; - break; } return rv; } @@ -71,24 +65,6 @@ } } -void CHIPDevicePairingDelegateBridge::OnNetworkCredentialsRequested(chip::RendezvousDeviceCredentialsDelegate * callback) -{ - NSLog(@"DevicePairingDelegate Requesting network credentials"); -} - -void CHIPDevicePairingDelegateBridge::SendWiFiCredentials(NSString * ssid, NSString * password) {} - -void CHIPDevicePairingDelegateBridge::SendThreadCredentials(NSData * threadDataSet) -{ - NSLog(@"Thread Provisioning is still a WIP, pairing will timeout..."); -} - -void CHIPDevicePairingDelegateBridge::OnOperationalCredentialsRequested( - const char * csr, size_t csr_length, chip::RendezvousDeviceCredentialsDelegate * callback) -{ - NSLog(@"DevicePairingDelegate Requesting operational credentials"); -} - void CHIPDevicePairingDelegateBridge::OnPairingComplete(CHIP_ERROR error) { NSLog(@"DevicePairingDelegate Pairing complete. Status %d", error); diff --git a/src/protocols/secure_channel/BUILD.gn b/src/protocols/secure_channel/BUILD.gn index 1c0b89f9543861..07fee9e4cf55c3 100644 --- a/src/protocols/secure_channel/BUILD.gn +++ b/src/protocols/secure_channel/BUILD.gn @@ -6,8 +6,6 @@ static_library("secure_channel") { sources = [ "CASESession.cpp", "CASESession.h", - "NetworkProvisioning.cpp", - "NetworkProvisioning.h", "PASESession.cpp", "PASESession.h", "RendezvousParameters.h", diff --git a/src/protocols/secure_channel/NetworkProvisioning.cpp b/src/protocols/secure_channel/NetworkProvisioning.cpp deleted file mode 100644 index a3a2777ac80edf..00000000000000 --- a/src/protocols/secure_channel/NetworkProvisioning.cpp +++ /dev/null @@ -1,335 +0,0 @@ -/* - * - * Copyright (c) 2020-2021 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if CONFIG_DEVICE_LAYER -#include -#if defined(CHIP_DEVICE_LAYER_TARGET) -#define DEVICENETWORKPROVISIONING_HEADER -#include DEVICENETWORKPROVISIONING_HEADER -#endif -#endif - -namespace chip { - -constexpr char kAPInterfaceNamePrefix[] = "ap"; -constexpr char kLoobackInterfaceNamePrefix[] = "lo"; - -void NetworkProvisioning::Init(Messaging::ExchangeManager * exchangeMgr, SecureSessionHandle session, - NetworkProvisioningDelegate * delegate) -{ - mExchangeMgr = exchangeMgr; - mDelegate = delegate; -#if CONFIG_DEVICE_LAYER -#if defined(CHIP_DEVICE_LAYER_TARGET) - DeviceLayer::PlatformMgr().AddEventHandler(ConnectivityHandler, reinterpret_cast(this)); -#endif -#endif - exchangeMgr->RegisterUnsolicitedMessageHandlerForProtocol(Protocols::NetworkProvisioning::Id, this); - mSession = session; -} - -NetworkProvisioning::~NetworkProvisioning() -{ -#if CONFIG_DEVICE_LAYER -#if defined(CHIP_DEVICE_LAYER_TARGET) - DeviceLayer::PlatformMgr().RemoveEventHandler(ConnectivityHandler, reinterpret_cast(this)); -#endif -#endif -} - -void NetworkProvisioning::OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle payload) -{ - HandleNetworkProvisioningMessage(payloadHeader.GetMessageType(), payload); - - // Currently, the only mechanism to get this callback is via unsolicited message handler. - // That means that we now own the reference to exchange context. Let's free the reference since we no longer - // need it. - exchangeContext->Close(); -} - -CHIP_ERROR NetworkProvisioning::HandleNetworkProvisioningMessage(uint8_t msgType, const System::PacketBufferHandle & msgBuf) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - switch (msgType) - { - case NetworkProvisioning::MsgTypes::kWiFiAssociationRequest: { - char SSID[chip::DeviceLayer::Internal::kMaxWiFiSSIDLength]; - char passwd[chip::DeviceLayer::Internal::kMaxWiFiKeyLength]; - Encoding::LittleEndian::BufferWriter bbufSSID(Uint8::from_char(SSID), chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); - Encoding::LittleEndian::BufferWriter bbufPW(Uint8::from_char(passwd), chip::DeviceLayer::Internal::kMaxWiFiKeyLength); - - const uint8_t * buffer = msgBuf->Start(); - size_t len = msgBuf->DataLength(); - size_t offset = 0; - - ChipLogProgress(NetworkProvisioning, "Received kWiFiAssociationRequest.\n"); - - err = DecodeString(&buffer[offset], len - offset, bbufSSID, offset); - // TODO: Check for the error once network provisioning is moved to delegate calls - - err = DecodeString(&buffer[offset], len - offset, bbufPW, offset); - // TODO: Check for the error once network provisioning is moved to delegate calls - -#if CONFIG_DEVICE_LAYER -#if defined(CHIP_DEVICE_LAYER_TARGET) - DeviceLayer::DeviceNetworkProvisioningDelegateImpl deviceDelegate; - err = deviceDelegate.ProvisionWiFi(SSID, passwd); - SuccessOrExit(err); - - if (DeviceLayer::ConnectivityMgr().IsWiFiStationConnected()) - { - err = SendCurrentIPv4Address(); - } -#endif -#endif - } - break; - - case NetworkProvisioning::MsgTypes::kThreadAssociationRequest: - ChipLogProgress(NetworkProvisioning, "Received kThreadAssociationRequest"); - err = DecodeThreadAssociationRequest(msgBuf); - break; - - case NetworkProvisioning::MsgTypes::kIPAddressAssigned: { - ChipLogProgress(NetworkProvisioning, "Received kIPAddressAssigned"); - if (!Inet::IPAddress::FromString(Uint8::to_const_char(msgBuf->Start()), msgBuf->DataLength(), mDeviceAddress)) - { - ExitNow(err = CHIP_ERROR_INVALID_ADDRESS); - } - } - break; - - default: - ExitNow(err = CHIP_ERROR_INVALID_MESSAGE_TYPE); - break; - }; - -exit: - if (mDelegate != nullptr) - { - if (err != CHIP_NO_ERROR) - { - ChipLogError(NetworkProvisioning, "Failed in HandleNetworkProvisioningMessage. error %s\n", ErrorStr(err)); - mDelegate->OnNetworkProvisioningError(err); - } - else - { - // Network provisioning handshake requires only one message exchange in either direction. - // If the current message handling did not result in an error, network provisioning is - // complete. - mDelegate->OnNetworkProvisioningComplete(); - } - } - return err; -} - -size_t NetworkProvisioning::EncodedStringSize(const char * str) -{ - return strlen(str) + sizeof(uint16_t); -} - -CHIP_ERROR NetworkProvisioning::EncodeString(const char * str, Encoding::LittleEndian::BufferWriter & bbuf) -{ - const size_t length = strlen(str); - VerifyOrReturnError(CanCastTo(length), CHIP_ERROR_INVALID_ARGUMENT); - const uint16_t u16len = static_cast(length); - - bbuf.Put16(u16len); - bbuf.Put(str); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR NetworkProvisioning::DecodeString(const uint8_t * input, size_t input_len, Encoding::LittleEndian::BufferWriter & bbuf, - size_t & consumed) -{ - VerifyOrReturnError(input_len >= sizeof(uint16_t), CHIP_ERROR_BUFFER_TOO_SMALL); - const uint16_t length = chip::Encoding::LittleEndian::Get16(input); - consumed = sizeof(uint16_t); - - VerifyOrReturnError(input_len - consumed >= length, CHIP_ERROR_BUFFER_TOO_SMALL); - bbuf.Put(&input[consumed], length); - - consumed += bbuf.Needed(); - bbuf.Put(static_cast('\0')); - - VerifyOrReturnError(bbuf.Fit(), CHIP_ERROR_BUFFER_TOO_SMALL); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR NetworkProvisioning::SendMessageUsingExchange(uint8_t msgType, System::PacketBufferHandle msgPayload) -{ - Messaging::ExchangeContext * exchangeContext = mExchangeMgr->NewContext(mSession, this); - VerifyOrReturnError(exchangeContext != nullptr, CHIP_ERROR_INTERNAL); - CHIP_ERROR err = exchangeContext->SendMessage(Protocols::NetworkProvisioning::Id, msgType, std::move(msgPayload), - Messaging::SendMessageFlags::kNoAutoRequestAck); - exchangeContext->Close(); - return err; -} - -CHIP_ERROR NetworkProvisioning::SendIPAddress(const Inet::IPAddress & addr) -{ - char * addrStr; - CHIP_ERROR err = CHIP_NO_ERROR; - System::PacketBufferHandle buffer = System::PacketBufferHandle::New(Inet::kMaxIPAddressStringLength); - VerifyOrExit(!buffer.IsNull(), err = CHIP_ERROR_NO_MEMORY); - addrStr = addr.ToString(Uint8::to_char(buffer->Start()), buffer->AvailableDataLength()); - buffer->SetDataLength(static_cast(strlen(addrStr) + 1)); - - ChipLogProgress(NetworkProvisioning, "Sending IP Address\n"); - VerifyOrExit(addrStr != nullptr, err = CHIP_ERROR_INVALID_ADDRESS); - - err = SendMessageUsingExchange(NetworkProvisioning::MsgTypes::kIPAddressAssigned, std::move(buffer)); - SuccessOrExit(err); - -exit: - if (CHIP_NO_ERROR != err) - ChipLogError(NetworkProvisioning, "Failed in sending IP address. error %s\n", ErrorStr(err)); - return err; -} - -CHIP_ERROR NetworkProvisioning::SendCurrentIPv4Address() -{ - for (chip::Inet::InterfaceAddressIterator it; it.HasCurrent(); it.Next()) - { - char ifName[chip::Inet::InterfaceIterator::kMaxIfNameLength]; - if (it.IsUp() && CHIP_NO_ERROR == it.GetInterfaceName(ifName, sizeof(ifName)) && - memcmp(ifName, kAPInterfaceNamePrefix, sizeof(kAPInterfaceNamePrefix) - 1) && - memcmp(ifName, kLoobackInterfaceNamePrefix, sizeof(kLoobackInterfaceNamePrefix) - 1)) - { - chip::Inet::IPAddress addr = it.GetAddress(); - if (addr.IsIPv4()) - { - return SendIPAddress(addr); - } - } - } - - return CHIP_NO_ERROR; -} - -CHIP_ERROR NetworkProvisioning::SendNetworkCredentials(const char * ssid, const char * passwd) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - const size_t bufferSize = EncodedStringSize(ssid) + EncodedStringSize(passwd); - VerifyOrExit(CanCastTo(bufferSize), err = CHIP_ERROR_INVALID_ARGUMENT); - { - Encoding::LittleEndian::PacketBufferWriter bbuf(MessagePacketBuffer::New(bufferSize), bufferSize); - - ChipLogProgress(NetworkProvisioning, "Sending Network Creds\n"); - VerifyOrExit(!bbuf.IsNull(), err = CHIP_ERROR_NO_MEMORY); - SuccessOrExit(EncodeString(ssid, bbuf)); - SuccessOrExit(EncodeString(passwd, bbuf)); - VerifyOrExit(bbuf.Fit(), err = CHIP_ERROR_BUFFER_TOO_SMALL); - - err = SendMessageUsingExchange(NetworkProvisioning::MsgTypes::kWiFiAssociationRequest, bbuf.Finalize()); - SuccessOrExit(err); - } - -exit: - if (CHIP_NO_ERROR != err) - ChipLogError(NetworkProvisioning, "Failed in sending Network Creds. error %s\n", ErrorStr(err)); - return err; -} - -CHIP_ERROR NetworkProvisioning::SendThreadCredentials(ByteSpan threadData) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - Encoding::LittleEndian::PacketBufferWriter bbuf(MessagePacketBuffer::New(threadData.size()), threadData.size()); - - ChipLogProgress(NetworkProvisioning, "Sending Thread Credentials"); - VerifyOrExit(!bbuf.IsNull(), err = CHIP_ERROR_NO_MEMORY); - - bbuf.Put(threadData.data(), threadData.size()); - - VerifyOrExit(bbuf.Fit(), err = CHIP_ERROR_BUFFER_TOO_SMALL); - - err = SendMessageUsingExchange(NetworkProvisioning::MsgTypes::kThreadAssociationRequest, bbuf.Finalize()); - -exit: - if (CHIP_NO_ERROR != err) - ChipLogError(NetworkProvisioning, "Failed to send Thread Credentials: %s", ErrorStr(err)); - return err; -} - -#ifdef CHIP_ENABLE_OPENTHREAD -CHIP_ERROR NetworkProvisioning::DecodeThreadAssociationRequest(const System::PacketBufferHandle & msgBuf) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - -#if CONFIG_DEVICE_LAYER - // Start listening for OpenThread changes to be able to respond with SLAAC/On-Mesh IP Address - DeviceLayer::PlatformMgr().AddEventHandler(ConnectivityHandler, reinterpret_cast(this)); -#if defined(CHIP_DEVICE_LAYER_TARGET) - { - DeviceLayer::DeviceNetworkProvisioningDelegateImpl deviceDelegate; - err = deviceDelegate.ProvisionThread(ByteSpan(msgBuf->Start(), msgBuf->DataLength())); - } -#endif -#endif - - return err; -} -#else // CHIP_ENABLE_OPENTHREAD -CHIP_ERROR NetworkProvisioning::DecodeThreadAssociationRequest(const System::PacketBufferHandle &) -{ - return CHIP_ERROR_INVALID_MESSAGE_TYPE; -} -#endif // CHIP_ENABLE_OPENTHREAD - -#if CONFIG_DEVICE_LAYER -void NetworkProvisioning::ConnectivityHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg) -{ - NetworkProvisioning * session = reinterpret_cast(arg); - - VerifyOrReturn(session != nullptr); - - if (event->Type == DeviceLayer::DeviceEventType::kInternetConnectivityChange && - event->InternetConnectivityChange.IPv4 == DeviceLayer::kConnectivity_Established) - { - Inet::IPAddress addr; - Inet::IPAddress::FromString(event->InternetConnectivityChange.address, addr); - (void) session->SendIPAddress(addr); - } - -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD - if (event->Type == DeviceLayer::DeviceEventType::kThreadStateChange && event->ThreadStateChange.AddressChanged) - { - Inet::IPAddress addr; - ReturnOnFailure(DeviceLayer::ThreadStackMgr().GetExternalIPv6Address(addr)); - (void) session->SendIPAddress(addr); - } -#endif -} -#endif - -} // namespace chip diff --git a/src/protocols/secure_channel/NetworkProvisioning.h b/src/protocols/secure_channel/NetworkProvisioning.h deleted file mode 100644 index 7f4f4f76bffe1b..00000000000000 --- a/src/protocols/secure_channel/NetworkProvisioning.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * - * Copyright (c) 2020-2021 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file defines the CHIP Device Network Provisioning object. - * - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if CONFIG_DEVICE_LAYER -#include -#endif - -namespace chip { - -class DLL_EXPORT NetworkProvisioningDelegate -{ -public: - /** - * @brief - * Called when network provisioning generates a new message that should be sent to peer. - * - * @param protocol Protocol ID for the message - * @param msgType Message type - * @param msgBuf the new message that should be sent to the peer - * @return CHIP_ERROR Error thrown when sending the message - */ - virtual CHIP_ERROR SendSecureMessage(Protocols::Id protocol, uint8_t msgType, System::PacketBufferHandle msgBuf) - { - return CHIP_NO_ERROR; - } - - /** - * @brief - * Called when network provisioning fails with an error - * - * @param error error code - */ - virtual void OnNetworkProvisioningError(CHIP_ERROR error) {} - - /** - * @brief - * Called when the network provisioning is complete - */ - virtual void OnNetworkProvisioningComplete() {} - - virtual ~NetworkProvisioningDelegate() {} -}; - -class DLL_EXPORT NetworkProvisioning : public Messaging::ExchangeDelegate -{ -public: - enum MsgTypes : uint8_t - { - kWiFiAssociationRequest = 0, - kIPAddressAssigned = 1, - kThreadAssociationRequest = 2 - }; - - void Init(Messaging::ExchangeManager * exchangeMgr, SecureSessionHandle session, NetworkProvisioningDelegate * delegate); - - ~NetworkProvisioning(); - - CHIP_ERROR SendNetworkCredentials(const char * ssid, const char * passwd); - CHIP_ERROR SendThreadCredentials(ByteSpan threadData); - - CHIP_ERROR HandleNetworkProvisioningMessage(uint8_t msgType, const System::PacketBufferHandle & msgBuf); - - /** - * @brief - * Get the IP address assigned to the device during network provisioning - * process. - * - * @return The IP address of the device - */ - const Inet::IPAddress & GetIPAddress() const { return mDeviceAddress; } - - //// ExchangeDelegate Implementation //// - void OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle payload) override; - void OnResponseTimeout(Messaging::ExchangeContext * exchangeContext) override {} - -private: - NetworkProvisioningDelegate * mDelegate = nullptr; - - Messaging::ExchangeManager * mExchangeMgr = nullptr; - - Inet::IPAddress mDeviceAddress = Inet::IPAddress::Any; - - SecureSessionHandle mSession; - - /** - * @brief - * The device can use this function to send its IP address to - * commissioner. This would generally be called during network - * provisioning of the device, after the IP address assignment. - * - * @param addr The IP address of the device - */ - CHIP_ERROR SendIPAddress(const Inet::IPAddress & addr); - - /** - * @brief - * The device can use this function to send its current IP address to - * commissioner. This would generally be called during network - * provisioning of the device, when the device already has an IP address. - */ - CHIP_ERROR SendCurrentIPv4Address(); - - static size_t EncodedStringSize(const char * str); - static CHIP_ERROR EncodeString(const char * str, Encoding::LittleEndian::BufferWriter & bbuf); - static CHIP_ERROR DecodeString(const uint8_t * input, size_t input_len, Encoding::LittleEndian::BufferWriter & bbuf, - size_t & consumed); - - CHIP_ERROR DecodeThreadAssociationRequest(const System::PacketBufferHandle & msgBuf); - - CHIP_ERROR SendMessageUsingExchange(uint8_t msgType, System::PacketBufferHandle msgPayload); - -#if CONFIG_DEVICE_LAYER - static void ConnectivityHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg); -#endif // CONFIG_DEVICE_LAYER -}; - -} // namespace chip diff --git a/src/protocols/secure_channel/RendezvousSession.cpp b/src/protocols/secure_channel/RendezvousSession.cpp index 6b5c44bc586278..04a599003f539c 100644 --- a/src/protocols/secure_channel/RendezvousSession.cpp +++ b/src/protocols/secure_channel/RendezvousSession.cpp @@ -149,10 +149,6 @@ void RendezvousSession::Cleanup() } } -void RendezvousSession::OnNetworkProvisioningError(CHIP_ERROR err) {} - -void RendezvousSession::OnNetworkProvisioningComplete() {} - void RendezvousSession::OnRendezvousConnectionOpened() { if (!mParams.IsController()) diff --git a/src/protocols/secure_channel/RendezvousSession.h b/src/protocols/secure_channel/RendezvousSession.h index 3598ef55c819a1..106a6de39034be 100644 --- a/src/protocols/secure_channel/RendezvousSession.h +++ b/src/protocols/secure_channel/RendezvousSession.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -65,10 +64,7 @@ class SecureSessionHandle; * * @dotfile dots/Rendezvous/RendezvousSessionInit.dot */ -class RendezvousSession : public SessionEstablishmentDelegate, - public RendezvousSessionDelegate, - public NetworkProvisioningDelegate, - public TransportMgrDelegate +class RendezvousSession : public SessionEstablishmentDelegate, public RendezvousSessionDelegate, public TransportMgrDelegate { public: RendezvousSession(RendezvousSessionDelegate * delegate) : mDelegate(delegate) {} @@ -107,23 +103,10 @@ class RendezvousSession : public SessionEstablishmentDelegate, void OnRendezvousConnectionClosed() override; void OnRendezvousError(CHIP_ERROR err) override; - //////////// NetworkProvisioningDelegate Implementation /////////////// - void OnNetworkProvisioningError(CHIP_ERROR error) override; - void OnNetworkProvisioningComplete() override; - //////////// TransportMgrDelegate Implementation /////////////// void OnMessageReceived(const PacketHeader & header, const Transport::PeerAddress & source, System::PacketBufferHandle msgBuf) override; - /** - * @brief - * Get the IP address assigned to the device during network provisioning - * process. - * - * @return The IP address of the device - */ - const Inet::IPAddress & GetIPAddress() const { return mNetworkProvision.GetIPAddress(); } - Transport::AdminId GetAdminId() const { return (mAdmin != nullptr) ? mAdmin->GetAdminId() : Transport::kUndefinedAdminId; } uint16_t GetNextKeyId() const { return mNextKeyId; } @@ -138,7 +121,6 @@ class RendezvousSession : public SessionEstablishmentDelegate, RendezvousParameters mParams; ///< Rendezvous configuration PASESession mPairingSession; - NetworkProvisioning mNetworkProvision; Messaging::ExchangeManager * mExchangeManager = nullptr; TransportMgrBase * mTransportMgr; uint16_t mNextKeyId = 0; diff --git a/src/transport/RendezvousSessionDelegate.h b/src/transport/RendezvousSessionDelegate.h index af2542dd806605..ee9c60b052d842 100644 --- a/src/transport/RendezvousSessionDelegate.h +++ b/src/transport/RendezvousSessionDelegate.h @@ -34,8 +34,6 @@ class RendezvousSessionDelegate { SecurePairingSuccess = 0, SecurePairingFailed, - NetworkProvisioningSuccess, - NetworkProvisioningFailed, }; virtual void OnRendezvousConnectionOpened() {} @@ -46,15 +44,4 @@ class RendezvousSessionDelegate System::PacketBufferHandle buffer){}; virtual void OnRendezvousStatusUpdate(Status status, CHIP_ERROR err) {} }; - -class DLL_EXPORT RendezvousDeviceCredentialsDelegate -{ -public: - virtual ~RendezvousDeviceCredentialsDelegate() {} - - virtual void SendNetworkCredentials(const char * ssid, const char * passwd) = 0; - virtual void SendThreadCredentials(ByteSpan threadDataset) = 0; - virtual void SendOperationalCredentials() = 0; -}; - } // namespace chip