[meshcop] border agent of native commissioner (#3535)

This commit enables a node serve as the border agent of native commissioner
by adding the border agent UDP port to unsecure port when the security
policy allows.

To fully test verify this commit, we need a native commissioner, which I
will submit a separate commit to enable that.
This commit is contained in:
Yakun Xu
2019-01-31 08:48:27 -08:00
committed by Jonathan Hui
parent da12dca4d9
commit 8dcdc2cf31
8 changed files with 80 additions and 3 deletions
+1
View File
@@ -238,6 +238,7 @@ typedef enum otMeshcopTlvType
OT_MESHCOP_TLV_SECURITYPOLICY = 12, ///< meshcop Security Policy TLV OT_MESHCOP_TLV_SECURITYPOLICY = 12, ///< meshcop Security Policy TLV
OT_MESHCOP_TLV_GET = 13, ///< meshcop Get TLV OT_MESHCOP_TLV_GET = 13, ///< meshcop Get TLV
OT_MESHCOP_TLV_ACTIVETIMESTAMP = 14, ///< meshcop Active Timestamp TLV OT_MESHCOP_TLV_ACTIVETIMESTAMP = 14, ///< meshcop Active Timestamp TLV
OT_MESHCOP_TLV_COMMISSIONER_UDP_PORT = 15, ///< meshcop Commissioner UDP Port TLV
OT_MESHCOP_TLV_STATE = 16, ///< meshcop State TLV OT_MESHCOP_TLV_STATE = 16, ///< meshcop State TLV
OT_MESHCOP_TLV_JOINER_DTLS = 17, ///< meshcop Joiner DTLS Encapsulation TLV OT_MESHCOP_TLV_JOINER_DTLS = 17, ///< meshcop Joiner DTLS Encapsulation TLV
OT_MESHCOP_TLV_JOINER_UDP_PORT = 18, ///< meshcop Joiner UDP Port TLV OT_MESHCOP_TLV_JOINER_UDP_PORT = 18, ///< meshcop Joiner UDP Port TLV
+2 -3
View File
@@ -127,9 +127,8 @@ private:
enum enum
{ {
kBorderAgentUdpPort = 49191, ///< UDP port of border agent service. kKeepAliveTimeout = 50 * 1000, ///< Timeout to reject a commissioner.
kKeepAliveTimeout = 50 * 1000, ///< Timeout to reject a commissioner. kRestartDelay = 1 * 1000, ///< Delay to restart border agent service.
kRestartDelay = 1 * 1000, ///< Delay to restart border agent service.
}; };
Ip6::MessageInfo mMessageInfo; Ip6::MessageInfo mMessageInfo;
+1
View File
@@ -49,6 +49,7 @@ namespace MeshCoP {
enum enum
{ {
kMeshCoPMessagePriority = Message::kPriorityNet, ///< The priority for MeshCoP message kMeshCoPMessagePriority = Message::kPriorityNet, ///< The priority for MeshCoP message
kBorderAgentUdpPort = 49191, ///< UDP port of border agent service.
}; };
/** /**
+48
View File
@@ -85,6 +85,7 @@ public:
kSecurityPolicy = OT_MESHCOP_TLV_SECURITYPOLICY, ///< Security Policy TLV kSecurityPolicy = OT_MESHCOP_TLV_SECURITYPOLICY, ///< Security Policy TLV
kGet = OT_MESHCOP_TLV_GET, ///< Get TLV kGet = OT_MESHCOP_TLV_GET, ///< Get TLV
kActiveTimestamp = OT_MESHCOP_TLV_ACTIVETIMESTAMP, ///< Active Timestamp TLV kActiveTimestamp = OT_MESHCOP_TLV_ACTIVETIMESTAMP, ///< Active Timestamp TLV
kCommissionerUdpPort = OT_MESHCOP_TLV_COMMISSIONER_UDP_PORT, ///< Commissioner UDP Port TLV
kState = OT_MESHCOP_TLV_STATE, ///< State TLV kState = OT_MESHCOP_TLV_STATE, ///< State TLV
kJoinerDtlsEncapsulation = OT_MESHCOP_TLV_JOINER_DTLS, ///< Joiner DTLS Encapsulation TLV kJoinerDtlsEncapsulation = OT_MESHCOP_TLV_JOINER_DTLS, ///< Joiner DTLS Encapsulation TLV
kJoinerUdpPort = OT_MESHCOP_TLV_JOINER_UDP_PORT, ///< Joiner UDP Port TLV kJoinerUdpPort = OT_MESHCOP_TLV_JOINER_UDP_PORT, ///< Joiner UDP Port TLV
@@ -977,6 +978,53 @@ public:
bool IsValid(void) const { return GetLength() == sizeof(*this) - sizeof(Tlv); } bool IsValid(void) const { return GetLength() == sizeof(*this) - sizeof(Tlv); }
} OT_TOOL_PACKED_END; } OT_TOOL_PACKED_END;
/**
* This class implements Commissioner UDP Port TLV generation and parsing.
*
*/
OT_TOOL_PACKED_BEGIN
class CommissionerUdpPortTlv : public Tlv
{
public:
/**
* This method initializes the TLV.
*
*/
void Init(void)
{
SetType(kCommissionerUdpPort);
SetLength(sizeof(*this) - sizeof(Tlv));
}
/**
* This method indicates whether or not the TLV appears to be well-formed.
*
* @retval TRUE If the TLV appears to be well-formed.
* @retval FALSE If the TLV does not appear to be well-formed.
*
*/
bool IsValid(void) const { return GetLength() == sizeof(*this) - sizeof(Tlv); }
/**
* This method returns the UDP Port value.
*
* @returns The UDP Port value.
*
*/
uint16_t GetUdpPort(void) const { return HostSwap16(mUdpPort); }
/**
* This method sets the UDP Port value.
*
* @param[in] aUdpPort The UDP Port value.
*
*/
void SetUdpPort(uint16_t aUdpPort) { mUdpPort = HostSwap16(aUdpPort); }
private:
uint16_t mUdpPort;
} OT_TOOL_PACKED_END;
/** /**
* This class implements State TLV generation and parsing. * This class implements State TLV generation and parsing.
* *
+7
View File
@@ -37,6 +37,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/instance.hpp" #include "common/instance.hpp"
#include "meshcop/meshcop.hpp"
#include "net/ip6.hpp" #include "net/ip6.hpp"
#include "net/tcp.hpp" #include "net/tcp.hpp"
#include "net/udp6.hpp" #include "net/udp6.hpp"
@@ -46,6 +47,7 @@ namespace ot {
namespace Ip6 { namespace Ip6 {
Filter::Filter(void) Filter::Filter(void)
: mAllowNativeCommissioner(true)
{ {
memset(mUnsecurePorts, 0, sizeof(mUnsecurePorts)); memset(mUnsecurePorts, 0, sizeof(mUnsecurePorts));
} }
@@ -84,6 +86,11 @@ bool Filter::Accept(Message &aMessage) const
ExitNow(rval = true); ExitNow(rval = true);
} }
// Allow native commissioner traffic
if (mAllowNativeCommissioner && dstport == MeshCoP::kBorderAgentUdpPort)
{
ExitNow(rval = true);
}
break; break;
case kProtoTcp: case kProtoTcp:
+9
View File
@@ -115,12 +115,21 @@ public:
*/ */
const uint16_t *GetUnsecurePorts(uint8_t &aNumEntries) const; const uint16_t *GetUnsecurePorts(uint8_t &aNumEntries) const;
/**
* This method sets whether to allow native commissioner traffic.
*
* @param[in] aAllow Whether to allow native commissioner traffic.
*
*/
void AllowNativeCommissioner(bool aAllow) { mAllowNativeCommissioner = aAllow; }
private: private:
enum enum
{ {
kMaxUnsecurePorts = 2, kMaxUnsecurePorts = 2,
}; };
uint16_t mUnsecurePorts[kMaxUnsecurePorts]; uint16_t mUnsecurePorts[kMaxUnsecurePorts];
bool mAllowNativeCommissioner;
}; };
} // namespace Ip6 } // namespace Ip6
+6
View File
@@ -1530,6 +1530,12 @@ void Mle::HandleStateChanged(otChangedFlags aFlags)
Store(); Store();
} }
if (aFlags & OT_CHANGED_SECURITY_POLICY)
{
GetNetif().GetIp6Filter().AllowNativeCommissioner(
(GetNetif().GetKeyManager().GetSecurityPolicyFlags() & OT_SECURITY_POLICY_NATIVE_COMMISSIONING) != 0);
}
exit: exit:
return; return;
} }
+6
View File
@@ -2742,6 +2742,12 @@ otError MleRouter::SendDiscoveryResponse(const Ip6::Address &aDestination, uint1
if (netif.GetKeyManager().GetSecurityPolicyFlags() & OT_SECURITY_POLICY_NATIVE_COMMISSIONING) if (netif.GetKeyManager().GetSecurityPolicyFlags() & OT_SECURITY_POLICY_NATIVE_COMMISSIONING)
{ {
MeshCoP::CommissionerUdpPortTlv commissionerUdpPort;
commissionerUdpPort.Init();
commissionerUdpPort.SetUdpPort(MeshCoP::kBorderAgentUdpPort);
SuccessOrExit(error = message->Append(&commissionerUdpPort, sizeof(commissionerUdpPort)));
discoveryResponse.SetNativeCommissioner(true); discoveryResponse.SetNativeCommissioner(true);
} }
else else