2 * FreeRTOS+UDP V1.0.4
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 #ifndef FREERTOS_UDP_H
\r
30 #define FREERTOS_UDP_H
\r
32 /* Standard includes. */
\r
35 /* Application level configuration options. */
\r
36 #include "FreeRTOSIPConfig.h"
\r
38 #ifndef INC_FREERTOS_H
\r
39 #error FreeRTOS.h must be included before FreeRTOS_Sockets.h.
\r
43 #ifndef TASK_H /* For compatibility with older FreeRTOS versions. */
\r
44 #error The FreeRTOS header file task.h must be included before FreeRTOS_Sockets.h.
\r
48 /* Assigned to an xSocket_t variable when the socket is not valid, probably
\r
49 because it could not be created. */
\r
50 #define FREERTOS_INVALID_SOCKET ( ( void * ) ~0U )
\r
52 /* API function error values. As errno is supported, the FreeRTOS sockets
\r
53 functions return error codes rather than just a pass or fail indication. */
\r
54 #define FREERTOS_SOCKET_ERROR ( -1 )
\r
55 #define FREERTOS_EWOULDBLOCK ( -2 )
\r
56 #define FREERTOS_EINVAL ( -4 )
\r
57 #define FREERTOS_EADDRNOTAVAIL ( -5 )
\r
58 #define FREERTOS_EADDRINUSE ( -6 )
\r
59 #define FREERTOS_ENOBUFS ( -7 )
\r
60 #define FREERTOS_ENOPROTOOPT ( -8 )
\r
62 /* Values for the parameters to FreeRTOS_socket(), inline with the Berkeley
\r
63 standard. See the documentation of FreeRTOS_socket() for more information. */
\r
64 #define FREERTOS_AF_INET ( 2 )
\r
65 #define FREERTOS_SOCK_DGRAM ( 2 )
\r
66 #define FREERTOS_IPPROTO_UDP ( 17 )
\r
68 /* A bit value that can be passed into the FreeRTOS_sendto() function as part of
\r
69 the flags parameter. Setting the FREERTOS_ZERO_COPY in the flags parameter
\r
70 indicates that the zero copy interface is being used. See the documentation for
\r
71 FreeRTOS_sockets() for more information. */
\r
72 #define FREERTOS_ZERO_COPY ( 0x01UL )
\r
74 /* Values that can be passed in the option name parameter of calls to
\r
75 FreeRTOS_setsockopt(). */
\r
76 #define FREERTOS_SO_RCVTIMEO ( 0 ) /* Used to set the receive time out. */
\r
77 #define FREERTOS_SO_SNDTIMEO ( 1 ) /* Used to set the send time out. */
\r
78 #define FREERTOS_SO_UDPCKSUM_OUT ( 0x02 ) /* Used to turn the use of the UDP checksum by a socket on or off. This also doubles as part of an 8-bit bitwise socket option. */
\r
79 #define FREERTOS_NOT_LAST_IN_FRAGMENTED_PACKET ( 0x80 ) /* For internal use only, but also part of an 8-bit bitwise value. */
\r
80 #define FREERTOS_FRAGMENTED_PACKET ( 0x40 ) /* For internal use only, but also part of an 8-bit bitwise value. */
\r
82 /* For compatibility with the expected Berkeley sockets naming. */
\r
83 #define socklen_t uint32_t
\r
85 /* For this limited implementation, only two members are required in the
\r
86 Berkeley style sockaddr structure. */
\r
87 struct freertos_sockaddr
\r
93 #if ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN
\r
95 #define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \
\r
96 ( ( ( ( uint32_t ) ( ucOctet3 ) ) << 24UL ) | \
\r
97 ( ( ( uint32_t ) ( ucOctet2 ) ) << 16UL ) | \
\r
98 ( ( ( uint32_t ) ( ucOctet1 ) ) << 8UL ) | \
\r
99 ( ( uint32_t ) ( ucOctet0 ) ) )
\r
101 #define FreeRTOS_inet_ntoa( ulIPAddress, pucBuffer ) \
\r
102 sprintf( ( char * ) ( pucBuffer ), "%d.%d.%d.%d", \
\r
103 ( int ) ( ( ulIPAddress ) & 0xffUL ), \
\r
104 ( int ) ( ( ( ulIPAddress ) >> 8UL ) & 0xffUL ),\
\r
105 ( int ) ( ( ( ulIPAddress ) >> 16UL ) & 0xffUL ),\
\r
106 ( int ) ( ( ( ulIPAddress ) >> 24UL ) & 0xffUL ) )
\r
108 #else /* ipconfigBYTE_ORDER */
\r
110 #define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \
\r
111 ( ( ( ( uint32_t ) ( ucOctet0 ) ) << 24UL ) | \
\r
112 ( ( ( uint32_t ) ( ucOctet1 ) ) << 16UL ) | \
\r
113 ( ( ( uint32_t ) ( ucOctet2 ) ) << 8UL ) | \
\r
114 ( ( uint32_t ) ( ucOctet3 ) ) )
\r
116 #define FreeRTOS_inet_ntoa( ulIPAddress, pucBuffer ) \
\r
117 sprintf( ( char * ) ( pucBuffer ), "%d.%d.%d.%d", \
\r
118 ( ( ( ulIPAddress ) >> 24UL ) & 0xffUL ), \
\r
119 ( ( ( ulIPAddress ) >> 16UL ) & 0xffUL ), \
\r
120 ( ( ( ulIPAddress ) >> 8UL ) & 0xffUL ), \
\r
121 ( ( ulIPAddress ) & 0xffUL ) )
\r
123 #endif /* ipconfigBYTE_ORDER */
\r
125 /* The socket type itself. */
\r
126 typedef void *xSocket_t;
\r
128 /* The xSocketSet_t type is the equivalent to the fd_set type used by the
\r
130 typedef void *xSocketSet_t;
\r
133 * FULL, UP-TO-DATE AND MAINTAINED REFERENCE DOCUMENTATION FOR ALL THESE
\r
134 * FUNCTIONS IS AVAILABLE ON THE FOLLOWING URL:
\r
135 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/FreeRTOS_UDP_API_Functions.shtml
\r
137 xSocket_t FreeRTOS_socket( BaseType_t xDomain, BaseType_t xType, BaseType_t xProtocol );
\r
138 int32_t FreeRTOS_recvfrom( xSocket_t xSocket, void *pvBuffer, size_t xBufferLength, uint32_t ulFlags, struct freertos_sockaddr *pxSourceAddress, socklen_t *pxSourceAddressLength );
\r
139 int32_t FreeRTOS_sendto( xSocket_t xSocket, const void *pvBuffer, size_t xTotalDataLength, uint32_t ulFlags, const struct freertos_sockaddr *pxDestinationAddress, socklen_t xDestinationAddressLength );
\r
140 BaseType_t FreeRTOS_bind( xSocket_t xSocket, struct freertos_sockaddr *pxAddress, socklen_t xAddressLength );
\r
141 BaseType_t FreeRTOS_setsockopt( xSocket_t xSocket, int32_t lLevel, int32_t lOptionName, const void *pvOptionValue, size_t xOptionLength );
\r
142 BaseType_t FreeRTOS_closesocket( xSocket_t xSocket );
\r
143 uint32_t FreeRTOS_gethostbyname( const char *pcHostName );
\r
144 uint32_t FreeRTOS_inet_addr( const char *pcIPAddress );
\r
146 #if ipconfigSUPPORT_SELECT_FUNCTION == 1
\r
147 xSocketSet_t FreeRTOS_CreateSocketSet( UBaseType_t uxEventQueueLength );
\r
148 BaseType_t FreeRTOS_FD_SET( xSocket_t xSocket, xSocketSet_t xSocketSet );
\r
149 BaseType_t FreeRTOS_FD_CLR( xSocket_t xSocket, xSocketSet_t xSocketSet );
\r
150 xSocket_t FreeRTOS_select( xSocketSet_t xSocketSet, TickType_t xBlockTimeTicks );
\r
151 #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
\r
153 #endif /* FREERTOS_UDP_H */
\r