Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rendezvous] Add initial support for IP rendezvous #3704

Merged
merged 24 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4cf3481
[rendezvous] Add initial support for IP rendezvous
erjiaqing Nov 5, 2020
0af05d0
Revert python device ctrl change
erjiaqing Nov 11, 2020
63ac557
Merge remote-tracking branch 'chip/master' into issue_3666_pr_1
erjiaqing Nov 11, 2020
ca625df
Change after merge
erjiaqing Nov 11, 2020
f9a8e72
Fix
erjiaqing Nov 11, 2020
e096d81
Fix
erjiaqing Nov 11, 2020
8ab65dc
Make code clearer
erjiaqing Nov 12, 2020
48217df
Rename variables in tests
erjiaqing Nov 12, 2020
b62d806
Restyled by clang-format
restyled-commits Nov 12, 2020
a79e5da
Add TransportMgrDelegate
erjiaqing Nov 17, 2020
f80eb17
Merge remote-tracking branch 'chip/master' into issue_3666_pr
erjiaqing Nov 17, 2020
2cc7ff4
remove BLEConnectionDelegate which shouldn't in this pr
erjiaqing Nov 17, 2020
1ab9edf
Fix nrf build
erjiaqing Nov 17, 2020
1733c52
Address comments
erjiaqing Nov 18, 2020
ef68193
update delegate code style
erjiaqing Nov 18, 2020
4d0c437
Fix
erjiaqing Nov 18, 2020
c5b32f4
Merge remote-tracking branch 'chip/master' into issue_3666_pr
erjiaqing Nov 18, 2020
6270ac4
Fix tests after merge
erjiaqing Nov 18, 2020
2b2fcbe
Fix ESP32 Build
erjiaqing Nov 18, 2020
38448cd
InitInternal -> Init
erjiaqing Nov 18, 2020
b14034a
Merge remote-tracking branch 'chip/master' into issue_3666_pr
erjiaqing Nov 19, 2020
ddd64be
Merge remote-tracking branch 'chip/master' into issue_3666_pr
erjiaqing Nov 19, 2020
3d208af
Merge remote-tracking branch 'chip/master' into issue_3666_pr
erjiaqing Nov 19, 2020
7fe5b6e
Merge remote-tracking branch 'chip/master' into issue_3666_pr
erjiaqing Nov 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions examples/all-clusters-app/esp32/main/EchoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
#include <transport/raw/Tuple.h>
#include <transport/raw/UDP.h>

Expand Down Expand Up @@ -122,7 +123,7 @@ class EchoServerCallback : public SecureSessionMgrDelegate
{
public:
void OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader, Transport::PeerConnectionState * state,
System::PacketBuffer * buffer, SecureSessionMgrBase * mgr) override
System::PacketBuffer * buffer, SecureSessionMgr * mgr) override
{
CHIP_ERROR err;
const size_t data_len = buffer->DataLength();
Expand Down Expand Up @@ -179,13 +180,13 @@ class EchoServerCallback : public SecureSessionMgrDelegate
}
}

void OnReceiveError(CHIP_ERROR error, const Transport::PeerAddress & source, SecureSessionMgrBase * mgr) override
void OnReceiveError(CHIP_ERROR error, const Transport::PeerAddress & source, SecureSessionMgr * mgr) override
{
ESP_LOGE(TAG, "ERROR: %s\n Got UDP error", ErrorStr(error));
statusLED1.BlinkOnError();
}

void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr) override
void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgr * mgr) override
{
ESP_LOGI(TAG, "Received a new connection.");
}
Expand Down Expand Up @@ -218,15 +219,16 @@ class EchoServerCallback : public SecureSessionMgrDelegate

EchoServerCallback gCallbacks;

SecureSessionMgr<Transport::UDP, // IPV6
Transport::UDP // IPV4
>
sessions;
TransportMgr<Transport::UDP, // IPV6
Transport::UDP // IPV4
>
gTransports;
SecureSessionMgr sessions;

} // namespace

namespace chip {
SecureSessionMgrBase & SessionManager()
SecureSessionMgr & SessionManager()
{
return sessions;
}
Expand All @@ -242,9 +244,11 @@ void PairingComplete(SecurePairingSession * pairing)
void startServer()
{
CHIP_ERROR err = CHIP_NO_ERROR;
err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(NULL),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv4));
err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer);
SuccessOrExit(err);
err = gTransports.Init(&sessions, nullptr,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(nullptr),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv4));
SuccessOrExit(err);

sessions.SetDelegate(&gCallbacks);
Expand Down
2 changes: 1 addition & 1 deletion examples/common/chip-app-server/DataModelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
* @param [in] buffer The buffer holding the message. This function guarantees
* that it will free the buffer before returning.
*/
void HandleDataModelMessage(const PacketHeader & header, System::PacketBuffer * buffer, SecureSessionMgrBase * mgr)
void HandleDataModelMessage(const PacketHeader & header, System::PacketBuffer * buffer, SecureSessionMgr * mgr)
{
EmberApsFrame frame;
bool ok = extractApsFrame(buffer->Start(), buffer->DataLength(), &frame) > 0;
Expand Down
3 changes: 2 additions & 1 deletion examples/common/chip-app-server/RendezvousServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void RendezvousServer::OnRendezvousConnectionClosed()
ChipLogProgress(AppServer, "OnRendezvousConnectionClosed");
}

void RendezvousServer::OnRendezvousMessageReceived(PacketBuffer * buffer)
void RendezvousServer::OnRendezvousMessageReceived(const PacketHeader & packetHeader, const PeerAddress & peerAddress,
PacketBuffer * buffer)
{
chip::System::PacketBuffer::Free(buffer);
}
Expand Down
17 changes: 10 additions & 7 deletions examples/common/chip-app-server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ServerCallback : public SecureSessionMgrDelegate
{
public:
void OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader, Transport::PeerConnectionState * state,
System::PacketBuffer * buffer, SecureSessionMgrBase * mgr) override
System::PacketBuffer * buffer, SecureSessionMgr * mgr) override
{
const size_t data_len = buffer->DataLength();
char src_addr[PeerAddress::kMaxToStringSize];
Expand All @@ -77,20 +77,21 @@ class ServerCallback : public SecureSessionMgrDelegate
}
}

void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr) override
void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgr * mgr) override
{
ChipLogProgress(AppServer, "Received a new connection.");
}
};

DemoSessionManager gSessions;
DemoTransportMgr gTransports;
SecureSessionMgr gSessions;
ServerCallback gCallbacks;
SecurePairingUsingTestSecret gTestPairing;
RendezvousServer gRendezvousServer;

} // namespace

SecureSessionMgrBase & chip::SessionManager()
SecureSessionMgr & chip::SessionManager()
{
return gSessions;
}
Expand All @@ -104,8 +105,7 @@ void InitServer()

InitDataModelHandler();

err = gSessions.Init(EXAMPLE_SERVER_NODEID, &DeviceLayer::SystemLayer,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6));
err = gSessions.Init(EXAMPLE_SERVER_NODEID, &DeviceLayer::SystemLayer);
SuccessOrExit(err);

// This flag is used to bypass BLE in the cirque test
Expand All @@ -123,12 +123,15 @@ void InitServer()
}
#endif

// Init transport before operations with secure session mgr.
gTransports.Init(&gSessions, gRendezvousServer.GetRendezvousSession(),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6));

err = gSessions.NewPairing(peer, &gTestPairing);
SuccessOrExit(err);

gSessions.SetDelegate(&gCallbacks);
chip::Mdns::DiscoveryManager::GetInstance().StartPublishDevice(chip::Inet::kIPAddressType_IPv6);

exit:
if (err != CHIP_NO_ERROR)
{
Expand Down
3 changes: 1 addition & 2 deletions examples/common/chip-app-server/include/DataModelHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ extern "C" {
* @param [in] buffer The buffer holding the message. This function guarantees
* that it will free the buffer before returning.
*/
void HandleDataModelMessage(const chip::PacketHeader & header, chip::System::PacketBuffer * buffer,
chip::SecureSessionMgrBase * mgr);
void HandleDataModelMessage(const chip::PacketHeader & header, chip::System::PacketBuffer * buffer, chip::SecureSessionMgr * mgr);
void InitDataModelHandler();
}
4 changes: 3 additions & 1 deletion examples/common/chip-app-server/include/RendezvousServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ class RendezvousServer : public RendezvousSessionDelegate
void OnRendezvousConnectionOpened() override;
void OnRendezvousConnectionClosed() override;
void OnRendezvousError(CHIP_ERROR err) override;
void OnRendezvousMessageReceived(System::PacketBuffer * buffer) override;
void OnRendezvousMessageReceived(const PacketHeader & packetHeader, const Transport::PeerAddress & peerAddress,
System::PacketBuffer * buffer) override;
void OnRendezvousStatusUpdate(Status status, CHIP_ERROR err) override;
RendezvousSession * GetRendezvousSession() { return &mRendezvousSession; };

private:
RendezvousSession mRendezvousSession;
Expand Down
4 changes: 2 additions & 2 deletions examples/common/chip-app-server/include/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

#pragma once

#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
#include <transport/raw/UDP.h>

using DemoSessionManager = chip::SecureSessionMgr<chip::Transport::UDP>;
using DemoTransportMgr = chip::TransportMgr<chip::Transport::UDP>;

/**
* Initialize DataModelHandler and start CHIP datamodel server, the server
Expand Down
2 changes: 1 addition & 1 deletion examples/common/chip-app-server/include/SessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
#include <transport/SecureSessionMgr.h>

namespace chip {
SecureSessionMgrBase & SessionManager();
SecureSessionMgr & SessionManager();
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
#include <transport/raw/Tuple.h>
#include <transport/raw/UDP.h>

Expand All @@ -61,7 +62,7 @@ class ResponseServerCallback : public SecureSessionMgrDelegate
{
public:
void OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader, Transport::PeerConnectionState * state,
System::PacketBuffer * buffer, SecureSessionMgrBase * mgr) override
System::PacketBuffer * buffer, SecureSessionMgr * mgr) override
{
CHIP_ERROR err;
const size_t data_len = buffer->DataLength();
Expand Down Expand Up @@ -90,12 +91,12 @@ class ResponseServerCallback : public SecureSessionMgrDelegate
}
}

void OnReceiveError(CHIP_ERROR error, const Transport::PeerAddress & source, SecureSessionMgrBase * mgr) override
void OnReceiveError(CHIP_ERROR error, const Transport::PeerAddress & source, SecureSessionMgr * mgr) override
{
ESP_LOGE(TAG, "ERROR: %s\n Got UDP error", ErrorStr(error));
}

void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr) override
void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgr * mgr) override
{
ESP_LOGI(TAG, "Received a new connection.");
}
Expand Down Expand Up @@ -127,16 +128,16 @@ class ResponseServerCallback : public SecureSessionMgrDelegate
};

ResponseServerCallback gCallbacks;

SecureSessionMgr<Transport::UDP, // IPV6
Transport::UDP // IPV4
>
sessions;
TransportMgr<Transport::UDP, // IPV6
Transport::UDP // IPV4
>
gTransports;
SecureSessionMgr sessions;

} // namespace

namespace chip {
SecureSessionMgrBase & SessionManager()
SecureSessionMgr & SessionManager()
{
return sessions;
}
Expand All @@ -152,9 +153,11 @@ void PairingComplete(SecurePairingSession * pairing)
void startServer()
{
CHIP_ERROR err = CHIP_NO_ERROR;
err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(nullptr),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv4));
err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer);
SuccessOrExit(err);
err = gTransports.Init(&sessions, nullptr,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(nullptr),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv4));
SuccessOrExit(err);

sessions.SetDelegate(&gCallbacks);
Expand Down
4 changes: 2 additions & 2 deletions src/app/util/chip-message-send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <assert.h>
#include <inet/InetLayer.h> // PacketBuffer and the like
#include <support/logging/CHIPLogging.h>
#include <transport/SecureSessionMgr.h> // For SecureSessionMgrBase
#include <transport/SecureSessionMgr.h> // For SecureSessionMgr

using namespace chip;

Expand All @@ -35,7 +35,7 @@ using namespace chip;
//
// https://github.com/project-chip/connectedhomeip/issues/2566 tracks that API.
namespace chip {
extern SecureSessionMgrBase & SessionManager();
extern SecureSessionMgr & SessionManager();
}

extern "C" {
Expand Down
4 changes: 2 additions & 2 deletions src/controller/CHIPDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ CHIP_ERROR Device::Deserialize(const SerializedDevice & input)
}

void Device::OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader,
Transport::PeerConnectionState * state, System::PacketBuffer * msgBuf, SecureSessionMgrBase * mgr)
Transport::PeerConnectionState * state, System::PacketBuffer * msgBuf, SecureSessionMgr * mgr)
{
if (mState == ConnectionState::SecureConnected && mStatusDelegate != nullptr)
{
Expand All @@ -186,7 +186,7 @@ CHIP_ERROR Device::LoadSecureSessionParameters()
err = pairingSession.FromSerializable(mPairing);
SuccessOrExit(err);

err = mSessionManager->ResetTransport(Transport::UdpListenParameters(mInetLayer).SetAddressType(mDeviceAddr.Type()));
err = mTransportMgr->ResetTransport(Transport::UdpListenParameters(mInetLayer).SetAddressType(mDeviceAddr.Type()));
SuccessOrExit(err);

err = mSessionManager->NewPairing(
Expand Down
20 changes: 14 additions & 6 deletions src/controller/CHIPDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <support/DLLUtil.h>
#include <transport/SecurePairingSession.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
#include <transport/raw/MessageHeader.h>
#include <transport/raw/UDP.h>

Expand All @@ -41,6 +42,8 @@ class DeviceController;
class DeviceStatusDelegate;
struct SerializedDevice;

using DeviceTransportMgr = TransportMgr<Transport::UDP>;

class DLL_EXPORT Device
{
public:
Expand Down Expand Up @@ -93,11 +96,13 @@ class DLL_EXPORT Device
* that of this device object. If these objects are freed, while the device object is
* still using them, it can lead to unknown behavior and crashes.
*
* @param[in] transportMgr Transport manager object pointer
* @param[in] sessionMgr Secure session manager object pointer
* @param[in] inetLayer InetLayer object pointer
*/
void Init(SecureSessionMgr<Transport::UDP> * sessionMgr, Inet::InetLayer * inetLayer)
void Init(DeviceTransportMgr * transportMgr, SecureSessionMgr * sessionMgr, Inet::InetLayer * inetLayer)
{
mTransportMgr = transportMgr;
mSessionManager = sessionMgr;
mInetLayer = inetLayer;
}
Expand All @@ -113,16 +118,17 @@ class DLL_EXPORT Device
* uninitialzed/unpaired device objects. The object is initialized only when the device
* is actually paired.
*
* @param[in] transportMgr Transport manager object pointer
* @param[in] sessionMgr Secure session manager object pointer
* @param[in] inetLayer InetLayer object pointer
* @param[in] deviceId Node ID of the device
* @param[in] devicePort Port on which device is listening (typically CHIP_PORT)
* @param[in] interfaceId Local Interface ID that should be used to talk to the device
*/
void Init(SecureSessionMgr<Transport::UDP> * sessionMgr, Inet::InetLayer * inetLayer, NodeId deviceId, uint16_t devicePort,
Inet::InterfaceId interfaceId)
void Init(DeviceTransportMgr * transportMgr, SecureSessionMgr * sessionMgr, Inet::InetLayer * inetLayer, NodeId deviceId,
uint16_t devicePort, Inet::InterfaceId interfaceId)
{
Init(sessionMgr, inetLayer);
Init(transportMgr, sessionMgr, inetLayer);
mDeviceId = deviceId;
mDevicePort = devicePort;
mInterface = interfaceId;
Expand Down Expand Up @@ -156,7 +162,7 @@ class DLL_EXPORT Device
* @param[in] mgr Pointer to secure session manager which received the message
*/
void OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader, Transport::PeerConnectionState * state,
System::PacketBuffer * msgBuf, SecureSessionMgrBase * mgr);
System::PacketBuffer * msgBuf, SecureSessionMgr * mgr);

/**
* @brief
Expand Down Expand Up @@ -202,7 +208,9 @@ class DLL_EXPORT Device

DeviceStatusDelegate * mStatusDelegate;

SecureSessionMgr<Transport::UDP> * mSessionManager;
SecureSessionMgr * mSessionManager;

DeviceTransportMgr * mTransportMgr;

/**
* @brief
Expand Down
Loading