PAL A Platform Abstraction Layer connects the mbed-client with the underlying platform.

- Main Page
- Data Structures
- Files

- File List
- Globals

Macros | Typedefs | Functions | Variables
pal_plat_network.cpp File Reference
`#include "pal.h"`
`#include "pal_plat_network.h"`
`#include "pal_rtos.h"`
`#include "mbed.h"`

## Macros
#define | PAL_SOCKET_OPTION_ERROR (-1)

## Typedefs
typedef void(* | palSelectCallbackFunction_t) ()

## Functions
palStatus_t | pal_plat_socketsInit (void *context)
palStatus_t | pal_plat_RegisterNetworkInterface (void *context, uint32_t *interfaceIndex)
palStatus_t | pal_plat_socketsTerminate (void *context)
palStatus_t | pal_plat_socket (palSocketDomain_t domain, palSocketType_t type, bool nonBlockingSocket, uint32_t interfaceNum, palSocket_t *socket)
palStatus_t | pal_plat_getSocketOptions (palSocket_t socket, palSocketOptionName_t optionName, void *optionValue, palSocketLength_t *optionLength)
palStatus_t | pal_plat_setSocketOptions (palSocket_t socket, int optionName, const void *optionValue, palSocketLength_t optionLength)
palStatus_t | pal_plat_bind (palSocket_t socket, palSocketAddress_t *myAddress, palSocketLength_t addressLength)
palStatus_t | pal_plat_receiveFrom (palSocket_t socket, void *buffer, size_t length, palSocketAddress_t *from, palSocketLength_t *fromLength, size_t *bytesReceived)
palStatus_t | pal_plat_sendTo (palSocket_t socket, const void *buffer, size_t length, const palSocketAddress_t *to, palSocketLength_t toLength, size_t *bytesSent)
palStatus_t | pal_plat_close (palSocket_t *socket)
palStatus_t | pal_plat_getNumberOfNetInterfaces (uint32_t *numInterfaces)
palStatus_t | pal_plat_getNetInterfaceInfo (uint32_t interfaceNum, palNetInterfaceInfo_t *interfaceInfo)
void | palSelectCallback0 ()
void | palSelectCallback1 ()
void | palSelectCallback2 ()
void | palSelectCallback3 ()
void | palSelectCallback4 ()
void | palSelectCallback5 ()
void | palSelectCallback6 ()
void | palSelectCallback7 ()
palStatus_t | pal_plat_socketMiniSelect (const palSocket_t socketsToCheck[PAL_NET_SOCKET_SELECT_MAX_SOCKETS], uint32_t numberOfSockets, pal_timeVal_t *timeout, uint8_t palSocketStatus[PAL_NET_SOCKET_SELECT_MAX_SOCKETS], uint32_t *numberOfSocketsSet)

## Variables
uint32_t | s_select_event_happened [PAL_NET_SOCKET_SELECT_MAX_SOCKETS]
palSelectCallbackFunction_t | s_palSelectPalCallbackFunctions [PAL_NET_SOCKET_SELECT_MAX_SOCKETS] = { palSelectCallback0, palSelectCallback1, palSelectCallback2, palSelectCallback3, palSelectCallback4, palSelectCallback5, palSelectCallback6, palSelectCallback7 }

## Macro Definition Documentation

#define PAL_SOCKET_OPTION_ERROR (-1)

## Typedef Documentation

typedef void(* palSelectCallbackFunction_t) ()

## Function Documentation

palStatus_t pal_plat_bind | ( | palSocket_t | socket,
|  | palSocketAddress_t * | myAddress,
|  | palSocketLength_t | addressLength
| ) |  |

Bind a given socket to a local address.

Parameters

  [in] | socket | The socket to bind.
  [in] | myAddress | The address to bind to.
  [in] | addressLength | The length of the address passed in myAddress.

Returns
  The status in the form of PalStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_close | ( | palSocket_t * | socket | ) |

Close a network socket. NOTE: recieves palSocket_t* and not palSocket_t so that it can zero the socket to avoid re-use.

Parameters

  [in,out] | socket | Release and zero socket pointed to by given pointer.

Returns
  The status in the form of PalStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_getNetInterfaceInfo | ( | uint32_t | interfaceNum,
|  | palNetInterfaceInfo_t * | interfaceInfo
| ) |  |

Get information regarding the socket at the index/interface number given (this number is returned when registering the socket).

Parameters

  [in] | interfaceNum | The number of the interface to get information for.
  [out] | interfaceInfo | The information for the given interface number.

Returns
  The status in the form of PalStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_getNumberOfNetInterfaces | ( | uint32_t * | numInterfaces | ) |

Get the number of current network interfaces (interfaces that have been registered through).

Parameters

  [out] | numInterfaces | The number of interfaces after a successful call.

Returns
  The status as in the form of PalStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_getSocketOptions | ( | palSocket_t | socket,
|  | palSocketOptionName_t | optionName,
|  | void * | optionValue,
|  | palSocketLength_t * | optionLength
| ) |  |

Get options for a given network socket. Only a few options are supported (see palSocketOptionName_t for supported options).

Parameters

  [in] | socket | The socket for which to get options.
  [in] | optionName | The name for which to set the option (see enum PAL_NET_SOCKET_OPTION for supported types).
  [out] | optionValue | The buffer holding the option value returned by the function.
  [in,out] | optionLength | The size of the buffer provided for optionValue when calling the function. After the call, it contains the length of data actually written to the optionValue buffer.

Returns
  The status in the form of PalStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_receiveFrom | ( | palSocket_t | socket,
|  | void * | buffer,
|  | size_t | length,
|  | palSocketAddress_t * | from,
|  | palSocketLength_t * | fromLength,
|  | size_t * | bytesReceived
| ) |  |

Receive a payload from the given socket.

Parameters

  [in] | socket | The socket to receive from [sockets passed to this function should be of type PAL_SOCK_DGRAM (the implementation may support other types as well)].
  [out] | buffer | The buffer for the payload data.
  [in] | length | The length of the buffer for the payload data.
  [out] | from | The address that sent the payload [optional - if not required pass NULL].
  [in,out] | fromLength | The length of the 'from' address. When completed, this contains the amount of data actually written to the from address [optional - if not required pass NULL].
  [out] | bytesReceived | The actual amount of payload data received to the buffer.

Returns
  The status in the form of PalStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_RegisterNetworkInterface | ( | void * | networkInterfaceContext,
|  | uint32_t * | interfaceIndex
| ) |  |

Register a network interface for use with PAL sockets - must be called before other socket functions - most APIs will not work before a single interface is added.

Parameters

  [in] | networkInterfaceContext | The context of the network interface to be added (OS specific. In mbed OS, this is the NetworkInterface object pointer for the network adapter [note: we assume connect has already been called on this]). - if not available use NULL (may not be required on some OSs).
  [out] | interfaceIndex | Contains the index assigned to the interface in case it has been assigned successfully. This index can be used when creating a socket to bind the socket to the interface.

Returns
  The status in the form of palStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_sendTo | ( | palSocket_t | socket,
|  | const void * | buffer,
|  | size_t | length,
|  | const palSocketAddress_t * | to,
|  | palSocketLength_t | toLength,
|  | size_t * | bytesSent
| ) |  |

Send a payload to the given address using the given socket.

Parameters

  [in] | socket | The socket to use for sending the payload [sockets passed to this function should be of type PAL_SOCK_DGRAM (the implementation may support other types as well)].
  [in] | buffer | The buffer for the payload data.
  [in] | length | The length of the buffer for the payload data.
  [in] | to | The address to which the payload should be sent.
  [in] | toLength | The length of the 'to' address.
  [out] | bytesSent | The actual amount of payload data sent.

Returns
  The status in the form of PalStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_setSocketOptions | ( | palSocket_t | socket,
|  | int | optionName,
|  | const void * | optionValue,
|  | palSocketLength_t | optionLength
| ) |  |

Set options for a given network socket. Only a few options are supported (see palSocketOptionName_t for supported options).

Parameters

  [in] | socket | The socket for which to get options.
  [in] | optionName | The name for which to set the option (see enum PAL_NET_SOCKET_OPTION for supported types).
  [in] | optionValue | The buffer holding the option value to set for the given option.
  [in] | optionLength | The size of the buffer provided for optionValue.

Returns
  The status in the form of PalStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_socket | ( | palSocketDomain_t | domain,
|  | palSocketType_t | type,
|  | bool | nonBlockingSocket,
|  | uint32_t | interfaceNum,
|  | palSocket_t * | socket
| ) |  |

Get a network socket.

Parameters

  [in] | domain | The domain of the created socket (see palSocketDomain_t for supported types).
  [in] | type | The type of the created socket (see palSocketType_t for supported types).
  [in] | nonBlockingSocket | If true, the socket is non-blocking (with O_NONBLOCK set).
  [in] | interfaceNum | The number of the network interface used for this socket (info in interfaces supported via pal_getNumberOfNetInterfaces and pal_getNetInterfaceInfo ), choose PAL_NET_DEFAULT_INTERFACE for default interface.
  [out] | socket | The socket is returned through this output parameter.

Returns
  The status in the form of PalStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_socketMiniSelect | ( | const palSocket_t | socketsToCheck[PAL_NET_SOCKET_SELECT_MAX_SOCKETS],
|  | uint32_t | numberOfSockets,
|  | pal_timeVal_t * | timeout,
|  | uint8_t | palSocketStatus[PAL_NET_SOCKET_SELECT_MAX_SOCKETS],
|  | uint32_t * | numberOfSocketsSet
| ) |  |

Check if one or more (up to PAL_NET_SOCKET_SELECT_MAX_SOCKETS) sockets has data available for reading/writing/error. The function blocks until data is available for one of the given sockets or the timeout expires. To use the function, set the sockets you want to check in the socketsToCheck array and set a timeout. When it returns the socketStatus output inidcates the status of each socket passed in. Note: The entry in index x in the socketStatus array corresponds to the socket at index x in the sockets to check array.

Parameters

  [in] | socketsToCheck | The array of up to 8 socket handles to check.
  [in] | numberOfSockets | The number of sockets set in the input socketsToCheck array.
  [in] | timeout | The time until timeout if no socket activity is detected.
  [out] | palSocketStatus | Information on each socket in the input array indicating which event was set (none, rx, tx, err). Check for a desired event using macros.
  [out] | numberOfSocketsSet | The total number of sockets set in all three data sets (tx, rx, err) after a completed function.

Returns
  The status in the form of PalStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_socketsInit | ( | void * | context | ) |

PAL network socket API PAL network sockets configurations options: define PAL_NET_TCP_AND_TLS_SUPPORT if TCP is supported by the platform and is required. define PAL_NET_ASYNCHRONOUS_SOCKET_API if asynchronous socket API is supported by the platform. Currently MANDATORY. define PAL_NET_DNS_SUPPORT if DNS name resolution is supported.

    Initialize sockets - must be called before other socket functions (is called from PAL init).

Parameters

  [in] | context | Optional context - if not available/applicable use NULL.

Returns
  The status in the form of palStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

palStatus_t pal_plat_socketsTerminate | ( | void * | context | ) |

Initialize terminate - can be called when sockets are no longer needed to free socket resources allocated by init.

Parameters

  [in] | context | Optional context - if not available use NULL.

Returns
  The status in the form of palStatus_t; PAL_SUCCESS (0) in case of success, a specific negative error code in case of failure.

void palSelectCallback0 | ( |  | ) |

void palSelectCallback1 | ( |  | ) |

void palSelectCallback2 | ( |  | ) |

void palSelectCallback3 | ( |  | ) |

void palSelectCallback4 | ( |  | ) |

void palSelectCallback5 | ( |  | ) |

void palSelectCallback6 | ( |  | ) |

void palSelectCallback7 | ( |  | ) |

## Variable Documentation

palSelectCallbackFunction_t s_palSelectPalCallbackFunctions[PAL_NET_SOCKET_SELECT_MAX_SOCKETS] = { palSelectCallback0, palSelectCallback1, palSelectCallback2, palSelectCallback3, palSelectCallback4, palSelectCallback5, palSelectCallback6, palSelectCallback7 }

uint32_t s_select_event_happened[PAL_NET_SOCKET_SELECT_MAX_SOCKETS]