UDP#

This module includes functions that control UDP communication.

Modules#

otUdpReceiver

otUdpSocket

Enumerations#

enum
OT_NETIF_UNSPECIFIED = 0
OT_NETIF_THREAD_HOST
OT_NETIF_THREAD_INTERNAL
OT_NETIF_BACKBONE
}

Defines the OpenThread network interface identifiers.

Typedefs#

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

Represents a callback to handle a received UDP message.

typedef struct otUdpReceiver

Represents a UDP receiver.

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

Callback function pointer to notify the application of a received UDP message on a UDP socket.

typedef enum otNetifIdentifier

Defines the OpenThread network interface identifiers.

typedef struct otUdpSocket

Represents a UDP socket.

Functions#

otUdpAddReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver)

Adds a UDP receiver.

otUdpRemoveReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver)

Removes a UDP receiver.

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

Sends a UDP message without socket.

otUdpNewMessage(otInstance *aInstance, const otMessageSettings *aSettings)

Allocate a new message buffer for sending a UDP message.

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.

otUdpClose(otInstance *aInstance, otUdpSocket *aSocket)

Close a UDP/IPv6 socket.

otUdpBind(otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName, otNetifIdentifier aNetif)

Bind a UDP/IPv6 socket.

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

Connect a UDP/IPv6 socket.

otUdpSend(otInstance *aInstance, otUdpSocket *aSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo)

Send a UDP/IPv6 message.

otUdpGetSockets(otInstance *aInstance)

Gets the head of linked list of UDP Sockets.

Enumeration Documentation#

otNetifIdentifier#

otNetifIdentifier

Defines the OpenThread network interface identifiers.

Enumerator
OT_NETIF_UNSPECIFIED

Unspecified network interface.

OT_NETIF_THREAD_HOST

The host Thread interface - allow use of platform UDP.

OT_NETIF_THREAD_INTERNAL

The internal Thread interface (within OpenThread) - do not use platform UDP.

OT_NETIF_BACKBONE

The Backbone interface.


Typedef Documentation#

otUdpHandler#

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

Represents a callback to handle a received UDP message.

Parameters
TypeDirectionArgument NameDescription
[in]aContext

A pointer to the application-specific context.

[in]aMessage

A pointer to the received UDP message.

[in]aMessageInfo

A pointer to the IPv6 message info structure.

This callback is used by a UDP receiver (see otUdpAddReceiver()) to process an incoming UDP message.

This callback does not transfer ownership of aMessage. The callback implementation must not modify the message content. The message is guaranteed to be valid only within the context of the callback.


otUdpReceiver#

typedef struct otUdpReceiver otUdpReceiver

Represents a UDP receiver.


otUdpReceive#

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

Callback function pointer to notify the application of a received UDP message on a UDP socket.

Parameters
TypeDirectionArgument NameDescription
[in]aContext

A pointer to the application-specific context.

[in]aMessage

A pointer to the received UDP message.

[in]aMessageInfo

A pointer to the IPv6 message info structure.

This callback does not transfer ownership of aMessage. The callback implementation must not modify the message content. The message is guaranteed to be valid only within the context of the callback.


otNetifIdentifier#

typedef enum otNetifIdentifier otNetifIdentifier

Defines the OpenThread network interface identifiers.


otUdpSocket#

typedef struct otUdpSocket otUdpSocket

Represents a UDP socket.


Function Documentation#

otUdpAddReceiver#

otError otUdpAddReceiver (otInstance * aInstance, otUdpReceiver * aUdpReceiver)

Adds a UDP receiver.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

otUdpReceiver *[in]aUdpReceiver

A pointer to the UDP receiver.


otUdpRemoveReceiver#

otError otUdpRemoveReceiver (otInstance * aInstance, otUdpReceiver * aUdpReceiver)

Removes a UDP receiver.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

otUdpReceiver *[in]aUdpReceiver

A pointer to the UDP receiver.


otUdpSendDatagram#

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

Sends a UDP message without socket.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

otMessage *[in]aMessage

A pointer to a message without UDP header.

otMessageInfo *[in]aMessageInfo

A pointer to a message info associated with aMessage.


otUdpNewMessage#

otMessage * otUdpNewMessage (otInstance * aInstance, const otMessageSettings * aSettings)

Allocate a new message buffer for sending a UDP message.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

const otMessageSettings *[in]aSettings

A pointer to the message settings or NULL to use default settings.

Note

  • If aSettings is 'NULL', the link layer security is enabled and the message priority is set to OT_MESSAGE_PRIORITY_NORMAL by default.

Returns

  • A pointer to the message buffer or NULL if no message buffers are available or parameters are invalid.

See Also


otUdpOpen#

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

Open a UDP/IPv6 socket.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

otUdpSocket *[in]aSocket

A pointer to a UDP socket structure.

otUdpReceive[in]aCallback

A pointer to the application callback function.

void *[in]aContext

A pointer to application-specific context.


otUdpIsOpen#

bool otUdpIsOpen (otInstance * aInstance, const otUdpSocket * aSocket)

Check if a UDP socket is open.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

const otUdpSocket *[in]aSocket

A pointer to a UDP socket structure.

Returns

  • Whether the UDP socket is open.


otUdpClose#

otError otUdpClose (otInstance * aInstance, otUdpSocket * aSocket)

Close a UDP/IPv6 socket.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

otUdpSocket *[in]aSocket

A pointer to a UDP socket structure.


otUdpBind#

otError otUdpBind (otInstance * aInstance, otUdpSocket * aSocket, const otSockAddr * aSockName, otNetifIdentifier aNetif)

Bind a UDP/IPv6 socket.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

otUdpSocket *[in]aSocket

A pointer to a UDP socket structure.

const otSockAddr *[in]aSockName

A pointer to an IPv6 socket address structure.

otNetifIdentifier[in]aNetif

The network interface to bind.


otUdpConnect#

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

Connect a UDP/IPv6 socket.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

otUdpSocket *[in]aSocket

A pointer to a UDP socket structure.

const otSockAddr *[in]aSockName

A pointer to an IPv6 socket address structure.


otUdpSend#

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

Send a UDP/IPv6 message.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

otUdpSocket *[in]aSocket

A pointer to a UDP socket structure.

otMessage *[in]aMessage

A pointer to a message buffer.

const otMessageInfo *[in]aMessageInfo

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


otUdpGetSockets#

otUdpSocket * otUdpGetSockets (otInstance * aInstance)

Gets the head of linked list of UDP Sockets.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

Returns

  • A pointer to the head of UDP Socket linked list.