Skip to content

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed Aug 25, 2020
1 parent cc3fae6 commit 2531608
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CHIP_ERROR RendezvousDeviceCallbacks::Init(Ble::BLEEndPoint * endPoint)
err = DeviceLayer::ConfigurationMgr().GetSetupPinCode(setupPINCode);
SuccessOrExit(err);

mRendezvousSession = new RendezvousSession(RendezvousParameters(kLocalNodeId, Transport::PeerAddress::BLE(), endPoint, setupPINCode));
mRendezvousSession = new RendezvousSession(RendezvousParameters(Optional<NodeId>(kLocalNodeId), Transport::PeerAddress::BLE(), endPoint, setupPINCode));
err = mRendezvousSession->Init(this);
SuccessOrExit(err);

Expand Down Expand Up @@ -89,8 +89,8 @@ void RendezvousDeviceCallbacks::OnRendezvousConnectionOpened()
{
ESP_LOGI(TAG, "OnRendezvousConnectionOpened");

SecurePairingSession pairing = mRendezvousSession.GetPairingSession();
PairingComplete(pairing.GetPeerNodeId(), pairing.GetPeerKeyId(), pairing.GetLocalPairedKeyId(), pairing);
SecurePairingSession pairing = mRendezvousSession->GetPairingSession();
PairingComplete(pairing.GetPeerNodeId(), pairing.GetPeerKeyId(), pairing.GetLocalPairedKeyId(), &pairing);
bluetoothLED.Set(true);
}

Expand Down
11 changes: 9 additions & 2 deletions src/transport/BLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ CHIP_ERROR BLE::SendMessage(const MessageHeader & header, const Transport::PeerA
if (msgBuf != NULL)
{
System::PacketBuffer::Free(msgBuf);
msgBuf = NULL;
msgBuf = nullptr;
}

return err;
Expand Down Expand Up @@ -194,7 +194,14 @@ void BLE::OnBleEndPointConnectionComplete(BLEEndPoint * endPoint, BLE_ERROR err)

if (ble->mBleCallbacks)
{
ble->mBleCallbacks->OnBLEConnectionComplete();
if (err != BLE_NO_ERROR)
{
ble->mBleCallbacks->OnBLEConnectionError(err);
}
else
{
ble->mBleCallbacks->OnBLEConnectionComplete();
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/transport/RendezvousSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ RendezvousSession::~RendezvousSession()

CHIP_ERROR RendezvousSession::SendMessage(System::PacketBuffer * buffer)
{
ChipLogProgress(Controller, "RendezvousSession::SendMessage");
// Rendezvous does not use a MessageHeader, but the Transport::Base API expects one, so
// let build an empty one for now.
MessageHeader header;
Expand All @@ -110,23 +111,23 @@ CHIP_ERROR RendezvousSession::SendMessage(System::PacketBuffer * buffer)
return err;
}

// XXX Should we just use SendMessage
CHIP_ERROR RendezvousSession::OnNewMessageForPeer(System::PacketBuffer * buffer)
{
ChipLogProgress(Controller, "RendezvousSession::OnNewMessageForPeer");
return SendMessage(buffer);
}

void RendezvousSession::OnPairingError(CHIP_ERROR err)
{
ChipLogError(Controller, "Failed to pair with accessory. Error %d", err);
ChipLogProgress(Controller, "RendezvousSession::OnPairingError: %s", ErrorStr(err));
mPairingInProgress = false;

mCallbacks->OnRendezvousError(err);
}

void RendezvousSession::OnPairingComplete()
{
ChipLogProgress(Controller, "Successfully paired with accessory.");
ChipLogProgress(Controller, "RendezvousSession::OnPairingComplete");
mPairingInProgress = false;

mCallbacks->OnRendezvousConnectionOpened();
Expand All @@ -140,6 +141,8 @@ void RendezvousSession::OnBLEConnectionError(BLE_ERROR err)

void RendezvousSession::OnBLEConnectionComplete()
{
ChipLogProgress(Controller, "RendezvousSession::OnBLEConnectionComplete");

CHIP_ERROR err = CHIP_NO_ERROR;
mPairingInProgress = true;

Expand All @@ -148,10 +151,12 @@ void RendezvousSession::OnBLEConnectionComplete()

if (mParams.HasEndPoint())
{
ChipLogProgress(Controller, "RendezvousSession::OnBLEConnectionComplete -> Calling WaitForPairing");
err = mPairingSession.WaitForPairing(setupPINCode, kSpake2p_Iteration_Count, (const unsigned char *) kSpake2pKeyExchangeSalt, strlen(kSpake2pKeyExchangeSalt), nodeId, 0, this);
}
else
{
ChipLogProgress(Controller, "RendezvousSession::OnBLEConnectionComplete -> Calling Pair");
err = mPairingSession.Pair(setupPINCode, kSpake2p_Iteration_Count, (const unsigned char *) kSpake2pKeyExchangeSalt, strlen(kSpake2pKeyExchangeSalt), nodeId, mNextKeyId++, this);
}

Expand All @@ -168,8 +173,10 @@ void RendezvousSession::OnBLEConnectionClosed(BLE_ERROR err)

void RendezvousSession::OnBLEPacketReceived(PacketBuffer * buffer)
{
ChipLogProgress(Controller, "RendezvousSession::OnBLEPacketReceived");
if (mPairingInProgress)
{
ChipLogProgress(Controller, "RendezvousSession::OnBLEPacketReceivedi -> mPairingInProgress");
MessageHeader header;
size_t headerSize = 0;
header.Decode(buffer->Start(), buffer->DataLength(), &headerSize);
Expand All @@ -179,6 +186,7 @@ void RendezvousSession::OnBLEPacketReceived(PacketBuffer * buffer)
}
else
{
ChipLogProgress(Controller, "RendezvousSession::OnBLEPacketReceivedi -> mPairingNotInProgress");
mCallbacks->OnRendezvousMessageReceived(buffer);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/transport/SecurePairingSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DLL_EXPORT SecurePairingSession
public:
SecurePairingSession(void);
SecurePairingSession(SecurePairingSession &&) = default;
SecurePairingSession(const SecurePairingSession &) = delete;
SecurePairingSession(const SecurePairingSession &) = default;
SecurePairingSession & operator=(const SecurePairingSession &) = default;
SecurePairingSession & operator=(SecurePairingSession &&) = default;

Expand Down

0 comments on commit 2531608

Please sign in to comment.