Skip to content

Commit

Permalink
Remove NetworkProvising.[h|cpp] (#6349)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored Apr 29, 2021
1 parent 9a7285e commit 65c3982
Show file tree
Hide file tree
Showing 28 changed files with 12 additions and 1,121 deletions.
19 changes: 0 additions & 19 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions examples/chip-tool/commands/pairing/PairingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ class EnterNetworkFragment : Fragment() {
return
}

ChipClient.getDeviceController().apply {
sendWiFiCredentials(ssid.toString(), pwd.toString())
}
// Do something with the credentials
}

private fun saveThreadNetwork() {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
#include <platform/ThreadStackManager.h>
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD

#include <protocols/secure_channel/NetworkProvisioning.h>

// 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)
Expand Down
20 changes: 0 additions & 20 deletions src/app/server/RendezvousServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
23 changes: 4 additions & 19 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#include <transport/TransportMgr.h>
#include <transport/raw/UDP.h>

#if CONFIG_DEVICE_LAYER
#include <platform/CHIPDeviceLayer.h>
#endif

#if CONFIG_NETWORK_LAYER_BLE
#include <ble/BleLayer.h>
#endif
Expand Down Expand Up @@ -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)
Expand Down
78 changes: 0 additions & 78 deletions src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const uint8_t *>(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<jint>(status));
Expand Down
9 changes: 1 addition & 8 deletions src/controller/java/AndroidDeviceControllerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,8 +76,7 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
using ChipDeviceControllerPtr = std::unique_ptr<chip::Controller::DeviceCommissioner>;

ChipDeviceControllerPtr mController;
chip::RendezvousDeviceCredentialsDelegate * mCredentialsDelegate = nullptr;
chip::PersistentStorageResultDelegate * mStorageResultDelegate = nullptr;
chip::PersistentStorageResultDelegate * mStorageResultDelegate = nullptr;

JavaVM * mJavaVM = nullptr;
jobject mJavaObjectRef = nullptr;
Expand Down
59 changes: 0 additions & 59 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(channel), ChipLogError(Controller, "sendThreadCredentials() called with invalid Channel"));
VerifyOrReturn(CanCastTo<uint16_t>(panId), ChipLogError(Controller, "sendThreadCredentials() called with invalid PAN ID"));
VerifyOrReturn(xpanIdBytes.size() == static_cast<jsize>(Thread::kSizeExtendedPanId),
ChipLogError(Controller, "sendThreadCredentials() called with invalid XPAN ID"));
VerifyOrReturn(masterKeyBytes.size() == static_cast<jsize>(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
Loading

0 comments on commit 65c3982

Please sign in to comment.