FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:dbad57390bd1 1 /*
ram54288 0:dbad57390bd1 2 * Copyright (c) 2016 ARM Limited. All rights reserved.
ram54288 0:dbad57390bd1 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:dbad57390bd1 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:dbad57390bd1 5 * not use this file except in compliance with the License.
ram54288 0:dbad57390bd1 6 * You may obtain a copy of the License at
ram54288 0:dbad57390bd1 7 *
ram54288 0:dbad57390bd1 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:dbad57390bd1 9 *
ram54288 0:dbad57390bd1 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:dbad57390bd1 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:dbad57390bd1 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:dbad57390bd1 13 * See the License for the specific language governing permissions and
ram54288 0:dbad57390bd1 14 * limitations under the License.
ram54288 0:dbad57390bd1 15 */
ram54288 0:dbad57390bd1 16
ram54288 0:dbad57390bd1 17
ram54288 0:dbad57390bd1 18 #ifndef _PAL_SOCKET_H
ram54288 0:dbad57390bd1 19 #define _PAL_SOCKET_H
ram54288 0:dbad57390bd1 20
ram54288 0:dbad57390bd1 21 #ifdef __cplusplus
ram54288 0:dbad57390bd1 22 extern "C" {
ram54288 0:dbad57390bd1 23 #endif
ram54288 0:dbad57390bd1 24
ram54288 0:dbad57390bd1 25 #include "pal.h"
ram54288 0:dbad57390bd1 26 //! PAL network socket API
ram54288 0:dbad57390bd1 27 //! pal network sockets configurations options:
ram54288 0:dbad57390bd1 28 //! set PAL_NET_TCP_AND_TLS_SUPPORT to true TCP is supported by the platform and is required
ram54288 0:dbad57390bd1 29 //! set PAL_NET_ASYNCHRONOUS_SOCKET_API to true if asynchronous socket API supported by the platform and is required : CURRENTLY MANDATORY
ram54288 0:dbad57390bd1 30 //! set PAL_NET_DNS_SUPPORT to true if you DNS url lookup API is supported.
ram54288 0:dbad57390bd1 31
ram54288 0:dbad57390bd1 32 typedef uint32_t palSocketLength_t; /*! length of data */
ram54288 0:dbad57390bd1 33 typedef void* palSocket_t; /*! PAL socket handle type */
ram54288 0:dbad57390bd1 34
ram54288 0:dbad57390bd1 35 #define PAL_NET_MAX_ADDR_SIZE 32 // check if we can make this more efficient
ram54288 0:dbad57390bd1 36
ram54288 0:dbad57390bd1 37 typedef struct palSocketAddress {
ram54288 0:dbad57390bd1 38 unsigned short addressType; /*! address family for the socket*/
ram54288 0:dbad57390bd1 39 char addressData[PAL_NET_MAX_ADDR_SIZE]; /*! address (based on protocol)*/
ram54288 0:dbad57390bd1 40 } palSocketAddress_t; /*! address data structure with enough room to support IPV4 and IPV6*/
ram54288 0:dbad57390bd1 41
ram54288 0:dbad57390bd1 42 typedef struct palNetInterfaceInfo{
ram54288 0:dbad57390bd1 43 char interfaceName[16]; //15 + ‘\0’
ram54288 0:dbad57390bd1 44 palSocketAddress_t address;
ram54288 0:dbad57390bd1 45 uint32_t addressSize;
ram54288 0:dbad57390bd1 46 } palNetInterfaceInfo_t;
ram54288 0:dbad57390bd1 47
ram54288 0:dbad57390bd1 48 typedef enum {
ram54288 0:dbad57390bd1 49 PAL_AF_UNSPEC = 0,
ram54288 0:dbad57390bd1 50 PAL_AF_INET = 2, /*! Internet IP Protocol */
ram54288 0:dbad57390bd1 51 PAL_AF_INET6 = 10, /*! IP version 6 */
ram54288 0:dbad57390bd1 52 } palSocketDomain_t;/*! network domains supported by PAL*/
ram54288 0:dbad57390bd1 53
ram54288 0:dbad57390bd1 54 typedef enum {
ram54288 0:dbad57390bd1 55 #if PAL_NET_TCP_AND_TLS_SUPPORT
ram54288 0:dbad57390bd1 56 PAL_SOCK_STREAM = 1, /*! stream socket */
ram54288 0:dbad57390bd1 57 PAL_SOCK_STREAM_SERVER = 99, /*! stream socket */
ram54288 0:dbad57390bd1 58 #endif //PAL_NET_TCP_AND_TLS_SUPPORT
ram54288 0:dbad57390bd1 59 PAL_SOCK_DGRAM = 2 /*! datagram socket */
ram54288 0:dbad57390bd1 60 } palSocketType_t;/*! socket types supported by PAL */
ram54288 0:dbad57390bd1 61
ram54288 0:dbad57390bd1 62
ram54288 0:dbad57390bd1 63 typedef enum {
ram54288 0:dbad57390bd1 64 PAL_SO_REUSEADDR = 0x0004, /*! allow local address reuse */
ram54288 0:dbad57390bd1 65 #if PAL_NET_TCP_AND_TLS_SUPPORT // socket options below supported only if TCP is supported.
ram54288 0:dbad57390bd1 66 PAL_SO_KEEPALIVE = 0x0008, /*! keep TCP connection open even if idle using periodic messages*/
ram54288 0:dbad57390bd1 67 #endif //PAL_NET_TCP_AND_TLS_SUPPORT
ram54288 0:dbad57390bd1 68 PAL_SO_SNDTIMEO = 0x1005, /*! send timeout */
ram54288 0:dbad57390bd1 69 PAL_SO_RCVTIMEO = 0x1006, /*! receive timeout */
ram54288 0:dbad57390bd1 70 } palSocketOptionName_t;/*! socket options supported by PAL */
ram54288 0:dbad57390bd1 71
ram54288 0:dbad57390bd1 72 #define PAL_NET_DEFAULT_INTERFACE 0xFFFFFFFF
ram54288 0:dbad57390bd1 73
ram54288 0:dbad57390bd1 74 #define PAL_IPV4_ADDRESS_SIZE 4
ram54288 0:dbad57390bd1 75 #define PAL_IPV6_ADDRESS_SIZE 16
ram54288 0:dbad57390bd1 76
ram54288 0:dbad57390bd1 77 typedef uint8_t palIpV4Addr_t[PAL_IPV4_ADDRESS_SIZE];
ram54288 0:dbad57390bd1 78 typedef uint8_t palIpV6Addr_t[PAL_IPV6_ADDRESS_SIZE];
ram54288 0:dbad57390bd1 79
ram54288 0:dbad57390bd1 80 typedef struct pal_timeVal{
ram54288 0:dbad57390bd1 81 int32_t pal_tv_sec; /*! seconds */
ram54288 0:dbad57390bd1 82 int32_t pal_tv_usec; /*! microseconds */
ram54288 0:dbad57390bd1 83 } pal_timeVal_t;
ram54288 0:dbad57390bd1 84
ram54288 0:dbad57390bd1 85
ram54288 0:dbad57390bd1 86 /*! 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.
ram54288 0:dbad57390bd1 87 * @param[in] networkInterfaceContext of the network interface to be added (OS specific , e.g. in MbedOS 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 .
ram54288 0:dbad57390bd1 88 * @param[out] InterfaceIndex will contain 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.
ram54288 0:dbad57390bd1 89 \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 90 */
ram54288 0:dbad57390bd1 91 palStatus_t pal_registerNetworkInterface(void* networkInterfaceContext, uint32_t* interfaceIndex);
ram54288 0:dbad57390bd1 92
ram54288 0:dbad57390bd1 93 /*! set a port to a palSocketAddress_t
ram54288 0:dbad57390bd1 94 * setting it can be done either directly or via the palSetSockAddrIPV4Addr or palSetSockAddrIPV6Addr functions
ram54288 0:dbad57390bd1 95 * @param[in,out] address the address to set
ram54288 0:dbad57390bd1 96 * @param[in] port the port number to set
ram54288 0:dbad57390bd1 97 \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 98 \note for the socket to be set correctly the addressType field of the address must be set correctly.
ram54288 0:dbad57390bd1 99 */
ram54288 0:dbad57390bd1 100 palStatus_t pal_setSockAddrPort(palSocketAddress_t* address, uint16_t port);
ram54288 0:dbad57390bd1 101
ram54288 0:dbad57390bd1 102 /*! set an ipV4 address to a palSocketAddress_t and also set the addressType to ipv4
ram54288 0:dbad57390bd1 103 * @param[in,out] address the address to set
ram54288 0:dbad57390bd1 104 * @param[in] ipV4Addr the address value to set
ram54288 0:dbad57390bd1 105 \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 106 */
ram54288 0:dbad57390bd1 107 palStatus_t pal_setSockAddrIPV4Addr(palSocketAddress_t* address, palIpV4Addr_t ipV4Addr);
ram54288 0:dbad57390bd1 108
ram54288 0:dbad57390bd1 109 /*! set an ipV6 address to a palSocketAddress_t and also set the addressType to ipv6
ram54288 0:dbad57390bd1 110 * @param[in,out] address the address to set
ram54288 0:dbad57390bd1 111 * @param[in] ipV6Addr the address value to set
ram54288 0:dbad57390bd1 112 \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 113 */
ram54288 0:dbad57390bd1 114 palStatus_t pal_setSockAddrIPV6Addr(palSocketAddress_t* address, palIpV6Addr_t ipV6Addr);
ram54288 0:dbad57390bd1 115
ram54288 0:dbad57390bd1 116 /*! get an ipV4 address from a palSocketAddress_t
ram54288 0:dbad57390bd1 117 * @param[in] address the address to set
ram54288 0:dbad57390bd1 118 * @param[out] ipV4Addr the address that is set in the address
ram54288 0:dbad57390bd1 119 \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 120 */
ram54288 0:dbad57390bd1 121 palStatus_t pal_getSockAddrIPV4Addr(const palSocketAddress_t* address, palIpV4Addr_t ipV4Addr);
ram54288 0:dbad57390bd1 122
ram54288 0:dbad57390bd1 123 /*! get an ipV6 address from a palSocketAddress_t
ram54288 0:dbad57390bd1 124 * @param[in] address the address to set
ram54288 0:dbad57390bd1 125 * @param[out] ipV6Addr the address that is set in the address
ram54288 0:dbad57390bd1 126 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 127 */
ram54288 0:dbad57390bd1 128 palStatus_t pal_getSockAddrIPV6Addr(const palSocketAddress_t* address, palIpV6Addr_t ipV6Addr);
ram54288 0:dbad57390bd1 129
ram54288 0:dbad57390bd1 130 /*! get a port from a palSocketAddress_t
ram54288 0:dbad57390bd1 131 * @param[in] address the address to set
ram54288 0:dbad57390bd1 132 * @param[out] port the port that is set in the address
ram54288 0:dbad57390bd1 133 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 134 */
ram54288 0:dbad57390bd1 135 palStatus_t pal_getSockAddrPort(const palSocketAddress_t* address, uint16_t* port);
ram54288 0:dbad57390bd1 136
ram54288 0:dbad57390bd1 137 /*! get a network socket
ram54288 0:dbad57390bd1 138 * @param[in] domain the domain for the created socket (see palSocketDomain_t for supported types)
ram54288 0:dbad57390bd1 139 * @param[in] type the type for the created socket (see palSocketType_t for supported types)
ram54288 0:dbad57390bd1 140 * @param[in] nonBlockingSocket if true the socket created is created as non-blocking (i.e. with O_NONBLOCK set)
ram54288 0:dbad57390bd1 141 * @param[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.
ram54288 0:dbad57390bd1 142 * @param[out] socket socket is returned through this output parameter
ram54288 0:dbad57390bd1 143 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 144 */
ram54288 0:dbad57390bd1 145 palStatus_t pal_socket(palSocketDomain_t domain, palSocketType_t type, bool nonBlockingSocket, uint32_t interfaceNum, palSocket_t* socket);
ram54288 0:dbad57390bd1 146
ram54288 0:dbad57390bd1 147 /*! get options for a given network socket
ram54288 0:dbad57390bd1 148 * @param[in] socket the socket for which to get options
ram54288 0:dbad57390bd1 149 * @param[in] optionName for which we are setting the option (see enum PAL_NET_SOCKET_OPTION for supported types)
ram54288 0:dbad57390bd1 150 * @param[out] optionValue the buffer holding the option value returned by the function
ram54288 0:dbad57390bd1 151 * @param[in, out] optionLength the size of the buffer provided for optionValue when calling the function after the call it will contain the length of data actually written to the optionValue buffer.
ram54288 0:dbad57390bd1 152 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 153 */
ram54288 0:dbad57390bd1 154 palStatus_t pal_getSocketOptions(palSocket_t socket, palSocketOptionName_t optionName, void* optionValue, palSocketLength_t* optionLength);
ram54288 0:dbad57390bd1 155
ram54288 0:dbad57390bd1 156 /*! set options for a given network socket
ram54288 0:dbad57390bd1 157 * @param[in] socket the socket for which to get options
ram54288 0:dbad57390bd1 158 * @param[in] optionName for which we are setting the option (see enum PAL_NET_SOCKET_OPTION for supported types)
ram54288 0:dbad57390bd1 159 * @param[in] optionValue the buffer holding the option value to set for the given option
ram54288 0:dbad57390bd1 160 * @param[in] optionLength the size of the buffer provided for optionValue
ram54288 0:dbad57390bd1 161 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 162 */
ram54288 0:dbad57390bd1 163 palStatus_t pal_setSocketOptions(palSocket_t socket, int optionName, const void* optionValue, palSocketLength_t optionLength);
ram54288 0:dbad57390bd1 164
ram54288 0:dbad57390bd1 165 /*! bind a given socket to a local address
ram54288 0:dbad57390bd1 166 * @param[in] socket the socket to bind
ram54288 0:dbad57390bd1 167 * @param[in] myAddress the address to which to bind
ram54288 0:dbad57390bd1 168 * @param[in] addressLength the length of the address passed in myAddress
ram54288 0:dbad57390bd1 169 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 170 */
ram54288 0:dbad57390bd1 171 palStatus_t pal_bind(palSocket_t socket, palSocketAddress_t* myAddress, palSocketLength_t addressLength);
ram54288 0:dbad57390bd1 172
ram54288 0:dbad57390bd1 173 /*! receive a payload from the given socket
ram54288 0:dbad57390bd1 174 * @param[in] socket the socket to receive from [we expect sockets passed to this function to be of type PAL_SOCK_DGRAM ( the implementation may support other types as well) ]
ram54288 0:dbad57390bd1 175 * @param[out] buffer the buffer for the payload data
ram54288 0:dbad57390bd1 176 * @param[in] length of the buffer for the payload data
ram54288 0:dbad57390bd1 177 * @param[out] from the address which sent the payload
ram54288 0:dbad57390bd1 178 * @param[in, out] fromLength the length of the 'from' address, after completion will contain the amount of data actually written to the from address
ram54288 0:dbad57390bd1 179 * @param[out] bytesReceived after the call will contain the actual amount of payload data received to the buffer
ram54288 0:dbad57390bd1 180 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 181 */
ram54288 0:dbad57390bd1 182 palStatus_t pal_receiveFrom(palSocket_t socket, void* buffer, size_t length, palSocketAddress_t* from, palSocketLength_t* fromLength, size_t* bytesReceived);
ram54288 0:dbad57390bd1 183
ram54288 0:dbad57390bd1 184 /*! send a payload to the given address using the given socket
ram54288 0:dbad57390bd1 185 * @param[in] socket the socket to use for sending the payload [we expect sockets passed to this function to be of type PAL_SOCK_DGRAM ( the implementation may support other types as well) ]
ram54288 0:dbad57390bd1 186 * @param[in] buffer the buffer for the payload data
ram54288 0:dbad57390bd1 187 * @param[in] length of the buffer for the payload data
ram54288 0:dbad57390bd1 188 * @param[in] to the address to which to payload should be sent
ram54288 0:dbad57390bd1 189 * @param[in] toLength the length of the 'to' address
ram54288 0:dbad57390bd1 190 * @param[out] bytesSent after the call will contain the actual amount of payload data sent
ram54288 0:dbad57390bd1 191 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 192 */
ram54288 0:dbad57390bd1 193 palStatus_t pal_sendTo(palSocket_t socket, const void* buffer, size_t length, const palSocketAddress_t* to, palSocketLength_t toLength, size_t* bytesSent);
ram54288 0:dbad57390bd1 194
ram54288 0:dbad57390bd1 195 /*! close a network socket
ram54288 0:dbad57390bd1 196 * @param[in,out] socket release and zero socket pointed to by given pointer.
ram54288 0:dbad57390bd1 197 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 198 \note recieves palSocket_t* and not palSocket_t so that it can zero the socket to avoid re-use.
ram54288 0:dbad57390bd1 199 */
ram54288 0:dbad57390bd1 200 palStatus_t pal_close(palSocket_t* socket);
ram54288 0:dbad57390bd1 201
ram54288 0:dbad57390bd1 202 /*! get the number of current network interfaces
ram54288 0:dbad57390bd1 203 * @param[out] numInterfaces will hold the number of interfaces after a successful call
ram54288 0:dbad57390bd1 204 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 205 */
ram54288 0:dbad57390bd1 206 palStatus_t pal_getNumberOfNetInterfaces(uint32_t* numInterfaces);
ram54288 0:dbad57390bd1 207
ram54288 0:dbad57390bd1 208 /*! get information regarding the socket at the index/interface number given (this number is returned when registering the socket)
ram54288 0:dbad57390bd1 209 * @param[in] interfaceNum the number of the interface to get information for.
ram54288 0:dbad57390bd1 210 * @param[out] interfaceInfo will be set to the information for the given interface number.
ram54288 0:dbad57390bd1 211 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 212 */
ram54288 0:dbad57390bd1 213 palStatus_t pal_getNetInterfaceInfo(uint32_t interfaceNum, palNetInterfaceInfo_t* interfaceInfo);
ram54288 0:dbad57390bd1 214
ram54288 0:dbad57390bd1 215
ram54288 0:dbad57390bd1 216 #define PAL_NET_SOCKET_SELECT_MAX_SOCKETS 8
ram54288 0:dbad57390bd1 217 #define PAL_NET_SOCKET_SELECT_RX_BIT (1)
ram54288 0:dbad57390bd1 218 #define PAL_NET_SOCKET_SELECT_TX_BIT (2)
ram54288 0:dbad57390bd1 219 #define PAL_NET_SOCKET_SELECT_ERR_BIT (4)
ram54288 0:dbad57390bd1 220
ram54288 0:dbad57390bd1 221 #define PAL_NET_SELECT_IS_RX(socketStatus, index) ((socketStatus[index] | PAL_NET_SOCKET_SELECT_RX_BIT) != 0) /*! check if RX bit is set in select result for a given socket index*/
ram54288 0:dbad57390bd1 222 #define PAL_NET_SELECT_IS_TX(socketStatus, index) ((socketStatus[index] | PAL_NET_SOCKET_SELECT_TX_BIT) != 0) /*! check if TX bit is set in select result for a given socket index*/
ram54288 0:dbad57390bd1 223 #define PAL_NET_SELECT_IS_ERR(socketStatus, index) ((socketStatus[index] | PAL_NET_SOCKET_SELECT_ERR_BIT) != 0) /*! check if ERR bit is set in select result for a given socket index*/
ram54288 0:dbad57390bd1 224
ram54288 0:dbad57390bd1 225 /*! check if one or more (up to PAL_NET_SOCKET_SELECT_MAX_SOCKETS) sockets given has data available for reading/writing/error, the function will block until data is available for one of the given sockets or the timeout expires.
ram54288 0:dbad57390bd1 226 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 will indicate the status of each socket passed in.
ram54288 0:dbad57390bd1 227 * @param[in] socketsToCheck on input: the array of up to 8 sockets handles to check.
ram54288 0:dbad57390bd1 228 * @param[in] numberOfSockets the number of sockets set in the input socketsToCheck array.
ram54288 0:dbad57390bd1 229 * @param[in] timeout the amount of time till timeout if no socket activity is detected
ram54288 0:dbad57390bd1 230 * @param[out] socketStatus will provide information on each socket in the input array indicating which event was set (none, rx, tx, err) check for desired event using macros.
ram54288 0:dbad57390bd1 231 * @param[out] numberOfSocketsSet is the total number of sockets set in all three data sets (tx, rx, err)after the function completes
ram54288 0:dbad57390bd1 232 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 233 \note the entry in index x in the socketStatus array corresponds to the socket at index x in the sockets to check array.
ram54288 0:dbad57390bd1 234 */
ram54288 0:dbad57390bd1 235 palStatus_t pal_socketMiniSelect(const palSocket_t socketsToCheck[PAL_NET_SOCKET_SELECT_MAX_SOCKETS], uint32_t numberOfSockets, pal_timeVal_t* timeout,
ram54288 0:dbad57390bd1 236 uint8_t palSocketStatus[PAL_NET_SOCKET_SELECT_MAX_SOCKETS], uint32_t* numberOfSocketsSet);
ram54288 0:dbad57390bd1 237
ram54288 0:dbad57390bd1 238
ram54288 0:dbad57390bd1 239 #if PAL_NET_TCP_AND_TLS_SUPPORT // functionality below supported only in case TCP is supported.
ram54288 0:dbad57390bd1 240
ram54288 0:dbad57390bd1 241
ram54288 0:dbad57390bd1 242 /*! use given socket to listed for incoming connections, may also limit queue of incoming connections.
ram54288 0:dbad57390bd1 243 * @param[in] socket the socket to listen on [we expect sockets passed to this function to be of type PAL_SOCK_STREAM_SERVER ( the implementation may support other types as well) ]
ram54288 0:dbad57390bd1 244 * @param[in] backlog the amount connections of pending connections which can be saved for the socket
ram54288 0:dbad57390bd1 245 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 246 */
ram54288 0:dbad57390bd1 247 palStatus_t pal_listen(palSocket_t socket, int backlog);
ram54288 0:dbad57390bd1 248
ram54288 0:dbad57390bd1 249 /*! accept a connection on the given socket
ram54288 0:dbad57390bd1 250 * @param[in] socket the socket on which to accept the connection (prerequisite: socket already created and bind and listen have been called on it ) [we expect sockets passed to this function to be of type PAL_SOCK_STREAM_SERVER ( the implementation may support other types as well) ]
ram54288 0:dbad57390bd1 251 * @param[out] address the source address of the incoming connection
ram54288 0:dbad57390bd1 252 * @param[in, out] addressLen the length of the address field on input, the length of the data returned on output.
ram54288 0:dbad57390bd1 253 * @param[out] acceptedSocket the socket of the accepted connection will be returned here if connection accepted successfully.
ram54288 0:dbad57390bd1 254
ram54288 0:dbad57390bd1 255 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 256 */
ram54288 0:dbad57390bd1 257 palStatus_t pal_accept(palSocket_t socket, palSocketAddress_t* address, palSocketLength_t* addressLen, palSocket_t* acceptedSocket);
ram54288 0:dbad57390bd1 258
ram54288 0:dbad57390bd1 259 /*! open a connection from the given socket to the given address
ram54288 0:dbad57390bd1 260 * @param[in] socket the socket to use for connection to the given address [we expect sockets passed to this function to be of type PAL_SOCK_STREAM ( the implementation may support other types as well) ]
ram54288 0:dbad57390bd1 261 * @param[in] address the destination address of the connection
ram54288 0:dbad57390bd1 262 * @param[in] addressLen the length of the address field
ram54288 0:dbad57390bd1 263 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 264 */
ram54288 0:dbad57390bd1 265 palStatus_t pal_connect(palSocket_t socket, const palSocketAddress_t* address, palSocketLength_t addressLen);
ram54288 0:dbad57390bd1 266
ram54288 0:dbad57390bd1 267 /*! receive data from the given connected socket
ram54288 0:dbad57390bd1 268 * @param[in] socket the connected socket on which to receive data [we expect sockets passed to this function to be of type PAL_SOCK_STREAM ( the implementation may support other types as well) ]
ram54288 0:dbad57390bd1 269 * @param[out] buf the output buffer for the message data
ram54288 0:dbad57390bd1 270 * @param[in] len the length of the input data buffer
ram54288 0:dbad57390bd1 271 * @param[out] recievedDataSize the length of the data actually received
ram54288 0:dbad57390bd1 272 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 273 */
ram54288 0:dbad57390bd1 274 palStatus_t pal_recv(palSocket_t socket, void* buf, size_t len, size_t* recievedDataSize);
ram54288 0:dbad57390bd1 275
ram54288 0:dbad57390bd1 276 /*! send a given buffer via the given connected socket
ram54288 0:dbad57390bd1 277 * @param[in] socket the connected socket on which to send data [we expect sockets passed to this function to be of type PAL_SOCK_STREAM ( the implementation may support other types as well) ]
ram54288 0:dbad57390bd1 278 * @param[in] buf the output buffer for the message data
ram54288 0:dbad57390bd1 279 * @param[in] len the length of the input data buffer
ram54288 0:dbad57390bd1 280 * @param[out] sentDataSize the length of the data sent
ram54288 0:dbad57390bd1 281 \return the function returns the status as in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 282 */
ram54288 0:dbad57390bd1 283 palStatus_t pal_send(palSocket_t socket, const void* buf, size_t len, size_t* sentDataSize);
ram54288 0:dbad57390bd1 284
ram54288 0:dbad57390bd1 285
ram54288 0:dbad57390bd1 286 #endif //PAL_NET_TCP_AND_TLS_SUPPORT
ram54288 0:dbad57390bd1 287
ram54288 0:dbad57390bd1 288
ram54288 0:dbad57390bd1 289 #if PAL_NET_ASYNCHRONOUS_SOCKET_API
ram54288 0:dbad57390bd1 290
ram54288 0:dbad57390bd1 291 /*! callback function called when an even happens an asynchronous socket for which it was set using the pal_asynchronousSocket.
ram54288 0:dbad57390bd1 292 */
ram54288 0:dbad57390bd1 293 typedef void(*palAsyncSocketCallback_t)();
ram54288 0:dbad57390bd1 294
ram54288 0:dbad57390bd1 295 /*! get an asynchronous network socket
ram54288 0:dbad57390bd1 296 * @param[in] domain the domain for the created socket (see enum palSocketDomain_t for supported types)
ram54288 0:dbad57390bd1 297 * @param[in] type the type for the created socket (see enum palSocketType_t for supported types)
ram54288 0:dbad57390bd1 298 * @param[in] nonBlockingSocket if true the socket created is created as non-blocking (i.e. with O_NONBLOCK set)
ram54288 0:dbad57390bd1 299 * @param[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.
ram54288 0:dbad57390bd1 300 * @param[in] callback a callback function that will be called when any supported event happens to the given asynchronous socket (see palAsyncSocketCallbackType enum for the types of events supported)
ram54288 0:dbad57390bd1 301 * @param[out] socket socket is returned through this output parameter
ram54288 0:dbad57390bd1 302 \return the function returns the status in the form of PalStatus_t which will be PAL_SUCCESS (0) in case of success or a specific negative error code in case of failure
ram54288 0:dbad57390bd1 303 */
ram54288 0:dbad57390bd1 304 palStatus_t pal_asynchronousSocket(palSocketDomain_t domain, palSocketType_t type, bool nonBlockingSocket, uint32_t interfaceNum, palAsyncSocketCallback_t callback, palSocket_t* socket);
ram54288 0:dbad57390bd1 305
ram54288 0:dbad57390bd1 306 #endif
ram54288 0:dbad57390bd1 307
ram54288 0:dbad57390bd1 308 #if PAL_NET_DNS_SUPPORT
ram54288 0:dbad57390bd1 309
ram54288 0:dbad57390bd1 310 /*! this function will translate from a URL to a palSocketAddress_t which can be used with pal sockets. It supports both IP address as strings and URLs (using DNS lookup).
ram54288 0:dbad57390bd1 311 * @param[in] url the URL (or IP address sting) to be translated into a palSocketAddress_t.
ram54288 0:dbad57390bd1 312 * @param[out] address the address for the output of the translation.
ram54288 0:dbad57390bd1 313 */
ram54288 0:dbad57390bd1 314 palStatus_t pal_getAddressInfo(const char* url, palSocketAddress_t* address, palSocketLength_t* addressLength);
ram54288 0:dbad57390bd1 315
ram54288 0:dbad57390bd1 316 #endif
ram54288 0:dbad57390bd1 317
ram54288 0:dbad57390bd1 318 #ifdef __cplusplus
ram54288 0:dbad57390bd1 319 }
ram54288 0:dbad57390bd1 320 #endif
ram54288 0:dbad57390bd1 321 #endif //_PAL_SOCKET_H
ram54288 0:dbad57390bd1 322
ram54288 0:dbad57390bd1 323