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.
 
typedef enum otNetifIdentifier otNetifIdentifier
 This enumeration defines the OpenThread network interface identifiers.

Enumerations

enum  otNetifIdentifier {
  OT_NETIF_UNSPECIFIED = 0,
  OT_NETIF_THREAD,
  OT_NETIF_BACKBONE
}
 This enumeration defines the OpenThread network interface identifiers.

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.
 
bool otUdpIsOpen (otInstance *aInstance, const otUdpSocket *aSocket)
 Check if a UDP socket is open.
 
otError otUdpClose (otInstance *aInstance, otUdpSocket *aSocket)
 Close a UDP/IPv6 socket.
 
otError otUdpBind (otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName, otNetifIdentifier aNetif)
 Bind a UDP/IPv6 socket.
 
otError otUdpConnect (otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName)
 Connect a UDP/IPv6 socket.
 
otError otUdpSend (otInstance *aInstance, otUdpSocket *aSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo)
 Send a UDP/IPv6 message.
 
otUdpSocketotUdpGetSockets (otInstance *aInstance)
 This function gets the head of linked list of UDP Sockets.

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.

Enumeration Type Documentation

◆ otNetifIdentifier

This enumeration defines the OpenThread network interface identifiers.

Enumerator
OT_NETIF_UNSPECIFIED 

Unspecified network interface.

OT_NETIF_THREAD 

The Thread interface.

OT_NETIF_BACKBONE 

The Backbone interface.

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 ( otInstance aInstance,
otUdpSocket aSocket,
const otSockAddr aSockName,
otNetifIdentifier  aNetif 
)

Bind a UDP/IPv6 socket.

Parameters
[in]aInstanceA pointer to an OpenThread instance.
[in]aSocketA pointer to a UDP socket structure.
[in]aSockNameA pointer to an IPv6 socket address structure.
[in]aNetifThe network interface to bind.
Return values
OT_ERROR_NONEBind operation was successful.
OT_ERROR_FAILEDFailed to bind UDP socket.

◆ otUdpClose()

otError otUdpClose ( otInstance aInstance,
otUdpSocket aSocket 
)

Close a UDP/IPv6 socket.

Parameters
[in]aInstanceA pointer to an OpenThread instance.
[in]aSocketA pointer to a UDP socket structure.
Return values
OT_ERROR_NONESuccessfully closed the socket.
OT_ERROR_FAILEDFailed to close UDP Socket.

◆ otUdpConnect()

otError otUdpConnect ( otInstance aInstance,
otUdpSocket aSocket,
const otSockAddr aSockName 
)

Connect a UDP/IPv6 socket.

Parameters
[in]aInstanceA pointer to an OpenThread instance.
[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.
OT_ERROR_FAILEDFailed to connect UDP socket.

◆ otUdpGetSockets()

otUdpSocket* otUdpGetSockets ( otInstance aInstance)

This function gets the head of linked list of UDP Sockets.

Parameters
[in]aInstanceA pointer to an OpenThread instance.
Returns
A pointer to the head of UDP Socket linked list.

◆ otUdpIsOpen()

bool otUdpIsOpen ( otInstance aInstance,
const otUdpSocket aSocket 
)

Check if a UDP socket is open.

Parameters
[in]aInstanceA pointer to an OpenThread instance.
[in]aSocketA pointer to a UDP socket structure.
Returns
Whether the UDP socket is open.

◆ 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 use 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.

◆ 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 ( otInstance aInstance,
otUdpSocket aSocket,
otMessage aMessage,
const otMessageInfo aMessageInfo 
)

Send a UDP/IPv6 message.

Parameters
[in]aInstanceA pointer to an OpenThread instance.
[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.
OT_ERROR_NO_BUFSInsufficient available buffer to add the UDP and IPv6 headers.

◆ 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.