This module includes functions that control UDP communication.

Classes

struct  otUdpReceiver
 This structure represents a UDP receiver.
 
struct  otUdpSocket
 This structure represents a UDP socket.

Typedefs

typedef bool(* otUdpHandler) (void *aContext, const otMessage *aMessage, const otMessageInfo *aMessageInfo)
 This callback allows OpenThread to provide specific handlers for certain UDP messages.
 
typedef struct otUdpReceiver otUdpReceiver
 This structure represents a UDP receiver.
 
typedef void(* otUdpReceive) (void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
 This callback allows OpenThread to inform the application of a received UDP message.
 
typedef struct otUdpSocket otUdpSocket
 This structure represents a UDP socket.

Functions

otError otUdpAddReceiver (otInstance *aInstance, otUdpReceiver *aUdpReceiver)
 This function adds a UDP receiver.
 
otError otUdpRemoveReceiver (otInstance *aInstance, otUdpReceiver *aUdpReceiver)
 This function removes a UDP receiver.
 
otError otUdpSendDatagram (otInstance *aInstance, otMessage *aMessage, otMessageInfo *aMessageInfo)
 This function sends a UDP message without socket.
 
otMessageotUdpNewMessage (otInstance *aInstance, const otMessageSettings *aSettings)
 Allocate a new message buffer for sending a UDP message.
 
otError otUdpOpen (otInstance *aInstance, otUdpSocket *aSocket, otUdpReceive aCallback, void *aContext)
 Open a UDP/IPv6 socket.
 
otError otUdpClose (otUdpSocket *aSocket)
 Close a UDP/IPv6 socket.
 
otError otUdpBind (otUdpSocket *aSocket, otSockAddr *aSockName)
 Bind a UDP/IPv6 socket.
 
otError otUdpConnect (otUdpSocket *aSocket, otSockAddr *aSockName)
 Connect a UDP/IPv6 socket.
 
otError otUdpSend (otUdpSocket *aSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo)
 Send a UDP/IPv6 message.

Detailed Description

This module includes functions that control UDP communication.

Typedef Documentation

◆ otUdpHandler

typedef bool(* otUdpHandler) (void *aContext, const otMessage *aMessage, const otMessageInfo *aMessageInfo)

This callback allows OpenThread to provide specific handlers for certain UDP messages.

Return values
trueThe message is handled by this receiver and should not be further processed.
falseThe message is not handled by this receiver.

Function Documentation

◆ otUdpAddReceiver()

otError otUdpAddReceiver ( otInstance aInstance,
otUdpReceiver aUdpReceiver 
)

This function adds a UDP receiver.

Parameters
[in]aInstanceA pointer to an OpenThread instance.
[in]aUdpReceiverA pointer to the UDP receiver.
Return values
OT_ERROR_NONEThe receiver is successfully added.
OT_ERROR_ALREADYThe UDP receiver was already added.

◆ otUdpBind()

otError otUdpBind ( otUdpSocket aSocket,
otSockAddr aSockName 
)

Bind a UDP/IPv6 socket.

Parameters
[in]aSocketA pointer to a UDP socket structure.
[in]aSockNameA pointer to an IPv6 socket address structure.
Return values
OT_ERROR_NONEBind operation was successful.
See also
otUdpNewMessage
otUdpOpen
otUdpConnect
otUdpClose
otUdpSend

◆ otUdpClose()

otError otUdpClose ( otUdpSocket aSocket)

Close a UDP/IPv6 socket.

Parameters
[in]aSocketA pointer to a UDP socket structure.
Return values
OT_ERROR_NONESuccessfully closed the socket.
See also
otUdpNewMessage
otUdpOpen
otUdpBind
otUdpConnect
otUdpSend

◆ otUdpConnect()

otError otUdpConnect ( otUdpSocket aSocket,
otSockAddr aSockName 
)

Connect a UDP/IPv6 socket.

Parameters
[in]aSocketA pointer to a UDP socket structure.
[in]aSockNameA pointer to an IPv6 socket address structure.
Return values
OT_ERROR_NONEConnect operation was successful.
See also
otUdpNewMessage
otUdpOpen
otUdpBind
otUdpClose
otUdpSend

◆ otUdpNewMessage()

otMessage* otUdpNewMessage ( otInstance aInstance,
const otMessageSettings aSettings 
)

Allocate a new message buffer for sending a UDP message.

Note
If aSettings is 'NULL', the link layer security is enabled and the message priority is set to OT_MESSAGE_PRIORITY_NORMAL by default.
Parameters
[in]aInstanceA pointer to an OpenThread instance.
[in]aSettingsA pointer to the message settings or NULL to set default settings.
Returns
A pointer to the message buffer or NULL if no message buffers are available or parameters are invalid.
See also
otMessageFree

◆ otUdpOpen()

otError otUdpOpen ( otInstance aInstance,
otUdpSocket aSocket,
otUdpReceive  aCallback,
void *  aContext 
)

Open a UDP/IPv6 socket.

Parameters
[in]aInstanceA pointer to an OpenThread instance.
[in]aSocketA pointer to a UDP socket structure.
[in]aCallbackA pointer to the application callback function.
[in]aContextA pointer to application-specific context.
Return values
OT_ERROR_NONESuccessfully opened the socket.
OT_ERROR_FAILEDFailed to open the socket.
See also
otUdpNewMessage
otUdpClose
otUdpBind
otUdpConnect
otUdpSend

◆ otUdpRemoveReceiver()

otError otUdpRemoveReceiver ( otInstance aInstance,
otUdpReceiver aUdpReceiver 
)

This function removes a UDP receiver.

Parameters
[in]aInstanceA pointer to an OpenThread instance.
[in]aUdpReceiverA pointer to the UDP receiver.
Return values
OT_ERROR_NONEThe receiver is successfully removed.
OT_ERROR_NOT_FOUNDThe UDP receiver was not added.

◆ otUdpSend()

otError otUdpSend ( otUdpSocket aSocket,
otMessage aMessage,
const otMessageInfo aMessageInfo 
)

Send a UDP/IPv6 message.

Parameters
[in]aSocketA pointer to a UDP socket structure.
[in]aMessageA pointer to a message buffer.
[in]aMessageInfoA pointer to a message info structure.

If the return value is OT_ERROR_NONE, OpenThread takes ownership of aMessage, and the caller should no longer reference aMessage. If the return value is not OT_ERROR_NONE, the caller retains ownership of aMessage, including freeing aMessage if the message buffer is no longer needed.

Return values
OT_ERROR_NONEThe message is successfully scheduled for sending.
OT_ERROR_INVALID_ARGSInvalid arguments are given.
See also
otUdpNewMessage
otUdpOpen
otUdpClose
otUdpBind
otUdpConnect
otUdpSend

◆ otUdpSendDatagram()

otError otUdpSendDatagram ( otInstance aInstance,
otMessage aMessage,
otMessageInfo aMessageInfo 
)

This function sends a UDP message without socket.

Parameters
[in]aInstanceA pointer to an OpenThread instance.
[in]aMessageA pointer to a message without UDP header.
[in]aMessageInfoA pointer to a message info associated with aMessage.
Return values
OT_ERROR_NONESuccessfully enqueued the message into an output interface.
OT_ERROR_NO_BUFSInsufficient available buffer to add the IPv6 headers.