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

- Main Page
- Data Structures
- Files

- File List
- Globals

pal_network.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016 ARM Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 * Licensed under the Apache License, Version 2.0 (the License); you may
5 * not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #ifndef _PAL_SOCKET_H
19 #define _PAL_SOCKET_H
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #include "pal.h"
31
32 typedef uint32_t palSocketLength_t;
33 typedef void* palSocket_t;
35 #define PAL_NET_MAX_ADDR_SIZE 32 // check if we can make this more efficient
36
37 typedef struct palSocketAddress {
38 unsigned short addressType;
39 char addressData[PAL_NET_MAX_ADDR_SIZE];
40 } palSocketAddress_t;
42 typedef struct palNetInterfaceInfo{
43 char interfaceName[16]; //15 + ‘\0’
44 palSocketAddress_t address;
45 uint32_t addressSize;
46 } palNetInterfaceInfo_t;
47
48 typedef enum {
49 PAL_AF_UNSPEC = 0,
50 PAL_AF_INET = 2,
51 PAL_AF_INET6 = 10,
52 } palSocketDomain_t;
54 typedef enum {
55 #if PAL_NET_TCP_AND_TLS_SUPPORT
56 PAL_SOCK_STREAM = 1,
57 PAL_SOCK_STREAM_SERVER = 99,
58 #endif //PAL_NET_TCP_AND_TLS_SUPPORT
59 PAL_SOCK_DGRAM = 2
60 } palSocketType_t;
63 typedef enum {
64 PAL_SO_REUSEADDR = 0x0004,
65 #if PAL_NET_TCP_AND_TLS_SUPPORT // socket options below supported only if TCP is supported.
66 PAL_SO_KEEPALIVE = 0x0008,
67 #endif //PAL_NET_TCP_AND_TLS_SUPPORT
68 PAL_SO_SNDTIMEO = 0x1005,
69 PAL_SO_RCVTIMEO = 0x1006,
70 } palSocketOptionName_t;
72 #define PAL_NET_DEFAULT_INTERFACE 0xFFFFFFFF
73
74 #define PAL_IPV4_ADDRESS_SIZE 4
75 #define PAL_IPV6_ADDRESS_SIZE 16
76
77 typedef uint8_t palIpV4Addr_t[PAL_IPV4_ADDRESS_SIZE];
78 typedef uint8_t palIpV6Addr_t[PAL_IPV6_ADDRESS_SIZE];
79
80 typedef struct pal_timeVal{
81 int32_t pal_tv_sec;
82 int32_t pal_tv_usec;
83 } pal_timeVal_t;
84
85
91 palStatus_t pal_registerNetworkInterface(void* networkInterfaceContext, uint32_t* interfaceIndex);
92
100 palStatus_t pal_setSockAddrPort(palSocketAddress_t* address, uint16_t port);
101
107 palStatus_t pal_setSockAddrIPV4Addr(palSocketAddress_t* address, palIpV4Addr_t ipV4Addr);
108
114 palStatus_t pal_setSockAddrIPV6Addr(palSocketAddress_t* address, palIpV6Addr_t ipV6Addr);
115
121 palStatus_t pal_getSockAddrIPV4Addr(const palSocketAddress_t* address, palIpV4Addr_t ipV4Addr);
122
128 palStatus_t pal_getSockAddrIPV6Addr(const palSocketAddress_t* address, palIpV6Addr_t ipV6Addr);
129
135 palStatus_t pal_getSockAddrPort(const palSocketAddress_t* address, uint16_t* port);
136
145 palStatus_t pal_socket(palSocketDomain_t domain, palSocketType_t type, bool nonBlockingSocket, uint32_t interfaceNum, palSocket_t* socket);
146
154 palStatus_t pal_getSocketOptions(palSocket_t socket, palSocketOptionName_t optionName, void* optionValue, palSocketLength_t* optionLength);
155
163 palStatus_t pal_setSocketOptions(palSocket_t socket, int optionName, const void* optionValue, palSocketLength_t optionLength);
164
171 palStatus_t pal_bind(palSocket_t socket, palSocketAddress_t* myAddress, palSocketLength_t addressLength);
172
182 palStatus_t pal_receiveFrom(palSocket_t socket, void* buffer, size_t length, palSocketAddress_t* from, palSocketLength_t* fromLength, size_t* bytesReceived);
183
193 palStatus_t pal_sendTo(palSocket_t socket, const void* buffer, size_t length, const palSocketAddress_t* to, palSocketLength_t toLength, size_t* bytesSent);
194
200 palStatus_t pal_close(palSocket_t* socket);
201
206 palStatus_t pal_getNumberOfNetInterfaces(uint32_t* numInterfaces);
207
213 palStatus_t pal_getNetInterfaceInfo(uint32_t interfaceNum, palNetInterfaceInfo_t* interfaceInfo);
214
215
216 #define PAL_NET_SOCKET_SELECT_MAX_SOCKETS 8
217 #define PAL_NET_SOCKET_SELECT_RX_BIT (1)
218 #define PAL_NET_SOCKET_SELECT_TX_BIT (2)
219 #define PAL_NET_SOCKET_SELECT_ERR_BIT (4)
220
221 #define PAL_NET_SELECT_IS_RX(socketStatus, index) ((socketStatus[index] | PAL_NET_SOCKET_SELECT_RX_BIT) != 0)
222 #define PAL_NET_SELECT_IS_TX(socketStatus, index) ((socketStatus[index] | PAL_NET_SOCKET_SELECT_TX_BIT) != 0)
223 #define PAL_NET_SELECT_IS_ERR(socketStatus, index) ((socketStatus[index] | PAL_NET_SOCKET_SELECT_ERR_BIT) != 0)
235 palStatus_t pal_socketMiniSelect(const palSocket_t socketsToCheck[PAL_NET_SOCKET_SELECT_MAX_SOCKETS], uint32_t numberOfSockets, pal_timeVal_t* timeout,
236 uint8_t palSocketStatus[PAL_NET_SOCKET_SELECT_MAX_SOCKETS], uint32_t* numberOfSocketsSet);
237
238
239 #if PAL_NET_TCP_AND_TLS_SUPPORT // functionality below supported only in case TCP is supported.
240
241
247 palStatus_t pal_listen(palSocket_t socket, int backlog);
248
257 palStatus_t pal_accept(palSocket_t socket, palSocketAddress_t* address, palSocketLength_t* addressLen, palSocket_t* acceptedSocket);
258
265 palStatus_t pal_connect(palSocket_t socket, const palSocketAddress_t* address, palSocketLength_t addressLen);
266
274 palStatus_t pal_recv(palSocket_t socket, void* buf, size_t len, size_t* recievedDataSize);
275
283 palStatus_t pal_send(palSocket_t socket, const void* buf, size_t len, size_t* sentDataSize);
284
285
286 #endif //PAL_NET_TCP_AND_TLS_SUPPORT
287
288
289 #if PAL_NET_ASYNCHRONOUS_SOCKET_API
290
293 typedef void(*palAsyncSocketCallback_t)();
294
304 palStatus_t pal_asynchronousSocket(palSocketDomain_t domain, palSocketType_t type, bool nonBlockingSocket, uint32_t interfaceNum, palAsyncSocketCallback_t callback, palSocket_t* socket);
305
306 #endif
307
308 #if PAL_NET_DNS_SUPPORT
309
314 palStatus_t pal_getAddressInfo(const char* url, palSocketAddress_t* address, palSocketLength_t* addressLength);
315
316 #endif
317
318 #ifdef __cplusplus
319 }
320 #endif
321 #endif //_PAL_SOCKET_H
322
323
pal_getSockAddrPort
palStatus_t pal_getSockAddrPort(const palSocketAddress_t *address, uint16_t *port)
Definition: pal_network.c:153
pal.h
pal_sendTo
palStatus_t pal_sendTo(palSocket_t socket, const void *buffer, size_t length, const palSocketAddress_t *to, palSocketLength_t toLength, size_t *bytesSent)
Definition: pal_network.c:240
pal_timeVal::pal_tv_usec
int32_t pal_tv_usec
Definition: pal_network.h:82
pal_close
palStatus_t pal_close(palSocket_t *socket)
Definition: pal_network.c:252
pal_getSockAddrIPV6Addr
palStatus_t pal_getSockAddrIPV6Addr(const palSocketAddress_t *address, palIpV6Addr_t ipV6Addr)
Definition: pal_network.c:133
PAL_AF_UNSPEC
Definition: pal_network.h:49
pal_registerNetworkInterface
palStatus_t pal_registerNetworkInterface(void *networkInterfaceContext, uint32_t *interfaceIndex)
Definition: pal_network.c:43
palNetInterfaceInfo_t
struct palNetInterfaceInfo palNetInterfaceInfo_t
palSocketLength_t
uint32_t palSocketLength_t
Definition: pal_network.h:32
pal_getNetInterfaceInfo
palStatus_t pal_getNetInterfaceInfo(uint32_t interfaceNum, palNetInterfaceInfo_t *interfaceInfo)
Definition: pal_network.c:276
palIpV4Addr_t
uint8_t palIpV4Addr_t[PAL_IPV4_ADDRESS_SIZE]
Definition: pal_network.h:77
PAL_SOCK_DGRAM
Definition: pal_network.h:59
palNetInterfaceInfo::address
palSocketAddress_t address
Definition: pal_network.h:44
palSocket_t
void * palSocket_t
Definition: pal_network.h:33
pal_setSocketOptions
palStatus_t pal_setSocketOptions(palSocket_t socket, int optionName, const void *optionValue, palSocketLength_t optionLength)
Definition: pal_network.c:204
pal_getSocketOptions
palStatus_t pal_getSocketOptions(palSocket_t socket, palSocketOptionName_t optionName, void *optionValue, palSocketLength_t *optionLength)
Definition: pal_network.c:192
pal_setSockAddrIPV6Addr
palStatus_t pal_setSockAddrIPV6Addr(palSocketAddress_t *address, palIpV6Addr_t ipV6Addr)
Definition: pal_network.c:91
PAL_AF_INET6
Definition: pal_network.h:51
palSocketAddress::addressType
unsigned short addressType
Definition: pal_network.h:38
pal_timeVal::pal_tv_sec
int32_t pal_tv_sec
Definition: pal_network.h:81
palSocketType_t
palSocketType_t
Definition: pal_network.h:54
palNetInterfaceInfo
Definition: pal_network.h:42
pal_setSockAddrPort
palStatus_t pal_setSockAddrPort(palSocketAddress_t *address, uint16_t port)
Definition: pal_network.c:51
PAL_SO_RCVTIMEO
Definition: pal_network.h:69
palSocketOptionName_t
palSocketOptionName_t
Definition: pal_network.h:63
palSocketAddress_t
struct palSocketAddress palSocketAddress_t
PAL_SO_REUSEADDR
Definition: pal_network.h:64
palNetInterfaceInfo::addressSize
uint32_t addressSize
Definition: pal_network.h:45
pal_bind
palStatus_t pal_bind(palSocket_t socket, palSocketAddress_t *myAddress, palSocketLength_t addressLength)
Definition: pal_network.c:216
palIpV6Addr_t
uint8_t palIpV6Addr_t[PAL_IPV6_ADDRESS_SIZE]
Definition: pal_network.h:78
pal_getSockAddrIPV4Addr
palStatus_t pal_getSockAddrIPV4Addr(const palSocketAddress_t *address, palIpV4Addr_t ipV4Addr)
Definition: pal_network.c:109
PAL_IPV4_ADDRESS_SIZE
#define PAL_IPV4_ADDRESS_SIZE
Definition: pal_network.h:74
PAL_IPV6_ADDRESS_SIZE
#define PAL_IPV6_ADDRESS_SIZE
Definition: pal_network.h:75
pal_setSockAddrIPV4Addr
palStatus_t pal_setSockAddrIPV4Addr(palSocketAddress_t *address, palIpV4Addr_t ipV4Addr)
Definition: pal_network.c:78
PAL_NET_SOCKET_SELECT_MAX_SOCKETS
#define PAL_NET_SOCKET_SELECT_MAX_SOCKETS
Definition: pal_network.h:216
pal_getNumberOfNetInterfaces
palStatus_t pal_getNumberOfNetInterfaces(uint32_t *numInterfaces)
Definition: pal_network.c:264
PAL_NET_MAX_ADDR_SIZE
#define PAL_NET_MAX_ADDR_SIZE
Definition: pal_network.h:35
PAL_SO_SNDTIMEO
Definition: pal_network.h:68
palSocketAddress::addressData
char addressData[PAL_NET_MAX_ADDR_SIZE]
Definition: pal_network.h:39
pal_timeVal_t
struct pal_timeVal pal_timeVal_t
palStatus_t
int32_t palStatus_t
Definition: pal_types.h:31
pal_timeVal
Definition: pal_network.h:80
pal_socket
palStatus_t pal_socket(palSocketDomain_t domain, palSocketType_t type, bool nonBlockingSocket, uint32_t interfaceNum, palSocket_t *socket)
Definition: pal_network.c:180
PAL_AF_INET
Definition: pal_network.h:50
pal_receiveFrom
palStatus_t pal_receiveFrom(palSocket_t socket, void *buffer, size_t length, palSocketAddress_t *from, palSocketLength_t *fromLength, size_t *bytesReceived)
Definition: pal_network.c:228
palSocketDomain_t
palSocketDomain_t
Definition: pal_network.h:48
palSocketAddress
Definition: pal_network.h:37