[udp] expose an API to send UDP datagram (#3822)

This commit exposes an API to send UDP datagram, this is usefully when the
UDP receiver handler needs to send messages.
This commit is contained in:
Yakun Xu
2019-05-16 14:22:03 -07:00
committed by Jonathan Hui
parent 1284384bd8
commit 6d155bebd2
2 changed files with 21 additions and 0 deletions
+13
View File
@@ -97,6 +97,19 @@ otError otUdpAddReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver);
*/
otError otUdpRemoveReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver);
/**
* This function sends a UDP message without socket.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aMessage A pointer to a message without UDP header.
* @param[in] aMessageInfo A pointer to a message info associated with @p aMessage.
*
* @retval OT_ERROR_NONE Successfully enqueued the message into an output interface.
* @retval OT_ERROR_NO_BUFS Insufficient available buffer to add the IPv6 headers.
*
*/
otError otUdpSendDatagram(otInstance *aInstance, otMessage *aMessage, otMessageInfo *aMessageInfo);
/**
* This callback allows OpenThread to inform the application of a received UDP message.
*
+8
View File
@@ -150,3 +150,11 @@ otError otUdpRemoveReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver)
return instance.Get<Ip6::Udp>().RemoveReceiver(*static_cast<Ip6::UdpReceiver *>(aUdpReceiver));
}
otError otUdpSendDatagram(otInstance *aInstance, otMessage *aMessage, otMessageInfo *aMessageInfo)
{
Instance &instance = *static_cast<Instance *>(aInstance);
return instance.Get<Ip6::Udp>().SendDatagram(*static_cast<ot::Message *>(aMessage),
*static_cast<Ip6::MessageInfo *>(aMessageInfo), Ip6::kProtoUdp);
}