mirror of
https://github.com/espressif/openthread.git
synced 2026-07-27 14:27:47 +00:00
[ip6] define Ip6::NetifIdentifier mirroring otNetifIdentifier (#8219)
This commit is contained in:
@@ -62,7 +62,7 @@ otError otUdpClose(otInstance *aInstance, otUdpSocket *aSocket)
|
||||
|
||||
otError otUdpBind(otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName, otNetifIdentifier aNetif)
|
||||
{
|
||||
return AsCoreType(aInstance).Get<Ip6::Udp>().Bind(AsCoreType(aSocket), AsCoreType(aSockName), aNetif);
|
||||
return AsCoreType(aInstance).Get<Ip6::Udp>().Bind(AsCoreType(aSocket), AsCoreType(aSockName), MapEnum(aNetif));
|
||||
}
|
||||
|
||||
otError otUdpConnect(otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName)
|
||||
|
||||
@@ -47,7 +47,7 @@ Error BackboneTmfAgent::Start(void)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
SuccessOrExit(error = Coap::Start(kBackboneUdpPort, OT_NETIF_BACKBONE));
|
||||
SuccessOrExit(error = Coap::Start(kBackboneUdpPort, Ip6::kNetifBackbone));
|
||||
SubscribeMulticast(Get<Local>().GetAllNetworkBackboneRoutersAddress());
|
||||
|
||||
exit:
|
||||
@@ -79,14 +79,14 @@ bool BackboneTmfAgent::IsBackboneTmfMessage(const Ip6::MessageInfo &aMessageInfo
|
||||
|
||||
void BackboneTmfAgent::SubscribeMulticast(const Ip6::Address &aAddress)
|
||||
{
|
||||
Error error = mSocket.JoinNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress);
|
||||
Error error = mSocket.JoinNetifMulticastGroup(Ip6::kNetifBackbone, aAddress);
|
||||
|
||||
LogError("Backbone TMF subscribes", aAddress, error);
|
||||
}
|
||||
|
||||
void BackboneTmfAgent::UnsubscribeMulticast(const Ip6::Address &aAddress)
|
||||
{
|
||||
Error error = mSocket.LeaveNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress);
|
||||
Error error = mSocket.LeaveNetifMulticastGroup(Ip6::kNetifBackbone, aAddress);
|
||||
|
||||
LogError("Backbone TMF unsubscribes", aAddress, error);
|
||||
}
|
||||
|
||||
@@ -1701,7 +1701,7 @@ Coap::Coap(Instance &aInstance)
|
||||
{
|
||||
}
|
||||
|
||||
Error Coap::Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier)
|
||||
Error Coap::Start(uint16_t aPort, Ip6::NetifIdentifier aNetifIdentifier)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
bool socketOpened = false;
|
||||
|
||||
@@ -906,7 +906,7 @@ public:
|
||||
* @retval kErrorFailed Failed to start CoAP agent.
|
||||
*
|
||||
*/
|
||||
Error Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier = OT_NETIF_UNSPECIFIED);
|
||||
Error Start(uint16_t aPort, Ip6::NetifIdentifier aNetifIdentifier = Ip6::kNetifUnspecified);
|
||||
|
||||
/**
|
||||
* This method stops the CoAP service.
|
||||
|
||||
@@ -226,7 +226,7 @@ Error Dtls::Bind(uint16_t aPort)
|
||||
VerifyOrExit(mState == kStateOpen, error = kErrorInvalidState);
|
||||
VerifyOrExit(mTransportCallback == nullptr, error = kErrorAlready);
|
||||
|
||||
SuccessOrExit(error = mSocket.Bind(aPort, OT_NETIF_UNSPECIFIED));
|
||||
SuccessOrExit(error = mSocket.Bind(aPort, Ip6::kNetifUnspecified));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
@@ -554,7 +554,7 @@ Error Client::Start(void)
|
||||
Error error;
|
||||
|
||||
SuccessOrExit(error = mSocket.Open(&Client::HandleUdpReceive, this));
|
||||
SuccessOrExit(error = mSocket.Bind(0, OT_NETIF_UNSPECIFIED));
|
||||
SuccessOrExit(error = mSocket.Bind(0, Ip6::kNetifUnspecified));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
@@ -75,7 +75,7 @@ Error Server::Start(void)
|
||||
VerifyOrExit(!IsRunning());
|
||||
|
||||
SuccessOrExit(error = mSocket.Open(&Server::HandleUdpReceive, this));
|
||||
SuccessOrExit(error = mSocket.Bind(kPort, kBindUnspecifiedNetif ? OT_NETIF_UNSPECIFIED : OT_NETIF_THREAD));
|
||||
SuccessOrExit(error = mSocket.Bind(kPort, kBindUnspecifiedNetif ? Ip6::kNetifUnspecified : Ip6::kNetifThread));
|
||||
|
||||
#if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
|
||||
Get<Srp::Server>().HandleDnssdServerStateChange();
|
||||
|
||||
@@ -105,7 +105,7 @@ Error Client::Start(void)
|
||||
Error error;
|
||||
|
||||
SuccessOrExit(error = mSocket.Open(&Client::HandleUdpReceive, this));
|
||||
SuccessOrExit(error = mSocket.Bind(0, OT_NETIF_UNSPECIFIED));
|
||||
SuccessOrExit(error = mSocket.Bind(0, Ip6::kNetifUnspecified));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
@@ -598,7 +598,7 @@ void Server::PrepareSocket(void)
|
||||
|
||||
VerifyOrExit(!mSocket.IsOpen());
|
||||
SuccessOrExit(error = mSocket.Open(HandleUdpReceive, this));
|
||||
error = mSocket.Bind(mPort, OT_NETIF_THREAD);
|
||||
error = mSocket.Bind(mPort, Ip6::kNetifThread);
|
||||
|
||||
exit:
|
||||
if (error != kErrorNone)
|
||||
|
||||
+11
-11
@@ -92,12 +92,12 @@ bool Udp::Socket::IsOpen(void) const
|
||||
return Get<Udp>().IsOpen(*this);
|
||||
}
|
||||
|
||||
Error Udp::Socket::Bind(const SockAddr &aSockAddr, otNetifIdentifier aNetifIdentifier)
|
||||
Error Udp::Socket::Bind(const SockAddr &aSockAddr, NetifIdentifier aNetifIdentifier)
|
||||
{
|
||||
return Get<Udp>().Bind(*this, aSockAddr, aNetifIdentifier);
|
||||
}
|
||||
|
||||
Error Udp::Socket::Bind(uint16_t aPort, otNetifIdentifier aNetifIdentifier)
|
||||
Error Udp::Socket::Bind(uint16_t aPort, NetifIdentifier aNetifIdentifier)
|
||||
{
|
||||
return Bind(SockAddr(aPort), aNetifIdentifier);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ Error Udp::Socket::SendTo(Message &aMessage, const MessageInfo &aMessageInfo)
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
Error Udp::Socket::JoinNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, const Address &aAddress)
|
||||
Error Udp::Socket::JoinNetifMulticastGroup(NetifIdentifier aNetifIdentifier, const Address &aAddress)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aNetifIdentifier);
|
||||
OT_UNUSED_VARIABLE(aAddress);
|
||||
@@ -133,14 +133,14 @@ Error Udp::Socket::JoinNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, c
|
||||
VerifyOrExit(aAddress.IsMulticast(), error = kErrorInvalidArgs);
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
|
||||
error = otPlatUdpJoinMulticastGroup(this, aNetifIdentifier, &aAddress);
|
||||
error = otPlatUdpJoinMulticastGroup(this, MapEnum(aNetifIdentifier), &aAddress);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Udp::Socket::LeaveNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, const Address &aAddress)
|
||||
Error Udp::Socket::LeaveNetifMulticastGroup(NetifIdentifier aNetifIdentifier, const Address &aAddress)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aNetifIdentifier);
|
||||
OT_UNUSED_VARIABLE(aAddress);
|
||||
@@ -150,7 +150,7 @@ Error Udp::Socket::LeaveNetifMulticastGroup(otNetifIdentifier aNetifIdentifier,
|
||||
VerifyOrExit(aAddress.IsMulticast(), error = kErrorInvalidArgs);
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
|
||||
error = otPlatUdpLeaveMulticastGroup(this, aNetifIdentifier, &aAddress);
|
||||
error = otPlatUdpLeaveMulticastGroup(this, MapEnum(aNetifIdentifier), &aAddress);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
@@ -209,18 +209,18 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Udp::Bind(SocketHandle &aSocket, const SockAddr &aSockAddr, otNetifIdentifier aNetifIdentifier)
|
||||
Error Udp::Bind(SocketHandle &aSocket, const SockAddr &aSockAddr, NetifIdentifier aNetifIdentifier)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aNetifIdentifier);
|
||||
|
||||
Error error = kErrorNone;
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
|
||||
SuccessOrExit(error = otPlatUdpBindToNetif(&aSocket, aNetifIdentifier));
|
||||
SuccessOrExit(error = otPlatUdpBindToNetif(&aSocket, MapEnum(aNetifIdentifier)));
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
if (aNetifIdentifier == OT_NETIF_BACKBONE)
|
||||
if (aNetifIdentifier == kNetifBackbone)
|
||||
{
|
||||
SetBackboneSocket(aSocket);
|
||||
}
|
||||
@@ -297,7 +297,7 @@ Error Udp::Connect(SocketHandle &aSocket, const SockAddr &aSockAddr)
|
||||
|
||||
if (!aSocket.IsBound())
|
||||
{
|
||||
SuccessOrExit(error = Bind(aSocket, aSocket.GetSockName(), OT_NETIF_THREAD));
|
||||
SuccessOrExit(error = Bind(aSocket, aSocket.GetSockName(), kNetifThread));
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
|
||||
@@ -360,7 +360,7 @@ Error Udp::SendTo(SocketHandle &aSocket, Message &aMessage, const MessageInfo &a
|
||||
|
||||
if (!aSocket.IsBound())
|
||||
{
|
||||
SuccessOrExit(error = Bind(aSocket, aSocket.GetSockName(), OT_NETIF_THREAD));
|
||||
SuccessOrExit(error = Bind(aSocket, aSocket.GetSockName(), kNetifThread));
|
||||
}
|
||||
|
||||
messageInfoLocal.SetSockPort(aSocket.GetSockName().mPort);
|
||||
|
||||
+17
-5
@@ -65,6 +65,17 @@ class Udp;
|
||||
#error "OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE and OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE must not both be set."
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This enumeration defines the network interface identifiers.
|
||||
*
|
||||
*/
|
||||
enum NetifIdentifier : uint8_t
|
||||
{
|
||||
kNetifUnspecified = OT_NETIF_UNSPECIFIED, ///< Unspecified network interface.
|
||||
kNetifThread = OT_NETIF_THREAD, ///< The Thread interface.
|
||||
kNetifBackbone = OT_NETIF_BACKBONE, ///< The Backbone interface.
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements core UDP message handling.
|
||||
*
|
||||
@@ -191,7 +202,7 @@ public:
|
||||
* @retval kErrorFailed Failed to bind UDP Socket.
|
||||
*
|
||||
*/
|
||||
Error Bind(const SockAddr &aSockAddr, otNetifIdentifier aNetifIdentifier = OT_NETIF_THREAD);
|
||||
Error Bind(const SockAddr &aSockAddr, NetifIdentifier aNetifIdentifier = kNetifThread);
|
||||
|
||||
/**
|
||||
* This method binds the UDP socket.
|
||||
@@ -203,7 +214,7 @@ public:
|
||||
* @retval kErrorFailed Failed to bind UDP Socket.
|
||||
*
|
||||
*/
|
||||
Error Bind(uint16_t aPort, otNetifIdentifier aNetifIdentifier = OT_NETIF_THREAD);
|
||||
Error Bind(uint16_t aPort, NetifIdentifier aNetifIdentifier = kNetifThread);
|
||||
|
||||
/**
|
||||
* This method binds the UDP socket.
|
||||
@@ -278,7 +289,7 @@ public:
|
||||
* @retval kErrorFailed Failed to join the multicast group.
|
||||
*
|
||||
*/
|
||||
Error JoinNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, const Address &aAddress);
|
||||
Error JoinNetifMulticastGroup(NetifIdentifier aNetifIdentifier, const Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method configures the UDP socket to leave a multicast group on a Host network interface.
|
||||
@@ -290,7 +301,7 @@ public:
|
||||
* @retval kErrorFailed Failed to leave the multicast group.
|
||||
*
|
||||
*/
|
||||
Error LeaveNetifMulticastGroup(otNetifIdentifier aNetifIdentifier, const Address &aAddress);
|
||||
Error LeaveNetifMulticastGroup(NetifIdentifier aNetifIdentifier, const Address &aAddress);
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -474,7 +485,7 @@ public:
|
||||
* @retval kErrorFailed Failed to bind UDP Socket.
|
||||
*
|
||||
*/
|
||||
Error Bind(SocketHandle &aSocket, const SockAddr &aSockAddr, otNetifIdentifier aNetifIdentifier);
|
||||
Error Bind(SocketHandle &aSocket, const SockAddr &aSockAddr, NetifIdentifier aNetifIdentifier);
|
||||
|
||||
/**
|
||||
* This method connects a UDP socket.
|
||||
@@ -655,6 +666,7 @@ private:
|
||||
|
||||
DefineCoreType(otUdpSocket, Ip6::Udp::SocketHandle);
|
||||
DefineCoreType(otUdpReceiver, Ip6::Udp::Receiver);
|
||||
DefineMapEnum(otNetifIdentifier, Ip6::NetifIdentifier);
|
||||
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ void MessageInfo::SetSockAddrToRlocPeerAddrTo(const Ip6::Address &aPeerAddress)
|
||||
|
||||
Error Agent::Start(void)
|
||||
{
|
||||
return Coap::Start(kUdpPort, OT_NETIF_THREAD);
|
||||
return Coap::Start(kUdpPort, Ip6::kNetifThread);
|
||||
}
|
||||
|
||||
Error Agent::Filter(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext)
|
||||
|
||||
Reference in New Issue
Block a user