]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-UDP/include/FreeRTOS_Sockets.h
c2d9b7b087ed2526af6bd79fa03c7e431def9b6c
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-UDP / include / FreeRTOS_Sockets.h
1 /*\r
2  * FreeRTOS+UDP V1.0.1 (C) 2013 Real Time Engineers ltd.\r
3  * All rights reserved\r
4  *\r
5  * This file is part of the FreeRTOS+UDP distribution.  The FreeRTOS+UDP license\r
6  * terms are different to the FreeRTOS license terms.\r
7  *\r
8  * FreeRTOS+UDP uses a dual license model that allows the software to be used \r
9  * under a standard GPL open source license, or a commercial license.  The \r
10  * standard GPL license (unlike the modified GPL license under which FreeRTOS \r
11  * itself is distributed) requires that all software statically linked with \r
12  * FreeRTOS+UDP is also distributed under the same GPL V2 license terms.  \r
13  * Details of both license options follow:\r
14  *\r
15  * - Open source licensing -\r
16  * FreeRTOS+UDP is a free download and may be used, modified, evaluated and\r
17  * distributed without charge provided the user adheres to version two of the\r
18  * GNU General Public License (GPL) and does not remove the copyright notice or\r
19  * this text.  The GPL V2 text is available on the gnu.org web site, and on the\r
20  * following URL: http://www.FreeRTOS.org/gpl-2.0.txt.\r
21  *\r
22  * - Commercial licensing -\r
23  * Businesses and individuals that for commercial or other reasons cannot comply\r
24  * with the terms of the GPL V2 license must obtain a commercial license before \r
25  * incorporating FreeRTOS+UDP into proprietary software for distribution in any \r
26  * form.  Commercial licenses can be purchased from http://shop.freertos.org/udp \r
27  * and do not require any source files to be changed.\r
28  *\r
29  * FreeRTOS+UDP is distributed in the hope that it will be useful.  You cannot\r
30  * use FreeRTOS+UDP unless you agree that you use the software 'as is'.\r
31  * FreeRTOS+UDP is provided WITHOUT ANY WARRANTY; without even the implied\r
32  * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR\r
33  * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they\r
34  * implied, expressed, or statutory.\r
35  *\r
36  * 1 tab == 4 spaces!\r
37  *\r
38  * http://www.FreeRTOS.org\r
39  * http://www.FreeRTOS.org/udp\r
40  *\r
41  */\r
42 \r
43 #ifndef FREERTOS_UDP_H\r
44 #define FREERTOS_UDP_H\r
45 \r
46 /* Standard includes. */\r
47 #include <string.h>\r
48 \r
49 /* Application level configuration options. */\r
50 #include "FreeRTOSIPConfig.h"\r
51 \r
52 #ifndef INC_FREERTOS_H\r
53         #error FreeRTOS.h must be included before FreeRTOS_Sockets.h.\r
54 #endif\r
55 \r
56 #ifndef INC_TASK_H\r
57         #ifndef TASK_H /* For compatibility with older FreeRTOS versions. */\r
58                 #error The FreeRTOS header file task.h must be included before FreeRTOS_Sockets.h.\r
59         #endif\r
60 #endif\r
61 \r
62 /* Assigned to an xSocket_t variable when the socket is not valid, probably\r
63 because it could not be created. */\r
64 #define FREERTOS_INVALID_SOCKET ( ( void * ) ~0U )\r
65 \r
66 /* API function error values.  As errno is supported, the FreeRTOS sockets\r
67 functions return error codes rather than just a pass or fail indication. */\r
68 #define FREERTOS_SOCKET_ERROR   ( -1 )\r
69 #define FREERTOS_EWOULDBLOCK    ( -2 )\r
70 #define FREERTOS_EINVAL                 ( -4 )\r
71 #define FREERTOS_EADDRNOTAVAIL  ( -5 )\r
72 #define FREERTOS_EADDRINUSE             ( -6 )\r
73 #define FREERTOS_ENOBUFS                ( -7 )\r
74 #define FREERTOS_ENOPROTOOPT    ( -8 )\r
75 \r
76 /* Values for the parameters to FreeRTOS_socket(), inline with the Berkeley\r
77 standard.  See the documentation of FreeRTOS_socket() for more information. */\r
78 #define FREERTOS_AF_INET                ( 2 )\r
79 #define FREERTOS_SOCK_DGRAM             ( 2 )\r
80 #define FREERTOS_IPPROTO_UDP    ( 17 )\r
81 \r
82 /* A bit value that can be passed into the FreeRTOS_sendto() function as part of\r
83 the flags parameter.  Setting the FREERTOS_ZERO_COPY in the flags parameter\r
84 indicates that the zero copy interface is being used.  See the documentation for\r
85 FreeRTOS_sockets() for more information. */\r
86 #define FREERTOS_ZERO_COPY              ( 0x01UL )\r
87 \r
88 /* Values that can be passed in the option name parameter of calls to\r
89 FreeRTOS_setsockopt(). */\r
90 #define FREERTOS_SO_RCVTIMEO            ( 0 )           /* Used to set the receive time out. */\r
91 #define FREERTOS_SO_SNDTIMEO            ( 1 )           /* Used to set the send time out. */\r
92 #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
93 #define FREERTOS_NOT_LAST_IN_FRAGMENTED_PACKET  ( 0x80 )  /* For internal use only, but also part of an 8-bit bitwise value. */\r
94 #define FREERTOS_FRAGMENTED_PACKET                              ( 0x40 )  /* For internal use only, but also part of an 8-bit bitwise value. */\r
95 \r
96 /* For compatibility with the expected Berkeley sockets naming. */\r
97 #define socklen_t uint32_t\r
98 \r
99 /* For this limited implementation, only two members are required in the\r
100 Berkeley style sockaddr structure. */\r
101 struct freertos_sockaddr\r
102 {\r
103         uint16_t sin_port;\r
104         uint32_t sin_addr;\r
105 };\r
106 \r
107 #if ipconfigBYTE_ORDER == FREERTOS_LITTLE_ENDIAN\r
108 \r
109         #define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 )                              \\r
110                                                                                 ( ( ( uint32_t ) ( ucOctet3 ) ) << 24UL ) |                     \\r
111                                                                                 ( ( ( uint32_t ) ( ucOctet2 ) ) << 16UL ) |                     \\r
112                                                                                 ( ( ( uint32_t ) ( ucOctet1 ) ) <<  8UL ) |                     \\r
113                                                                                 ( ( uint32_t ) ( ucOctet0 ) )\r
114 \r
115         #define FreeRTOS_inet_ntoa( ulIPAddress, pucBuffer )                                                                    \\r
116                                                                                 sprintf( ( char * ) ( pucBuffer ), "%d.%d.%d.%d",       \\r
117                                                                                         ( ( ulIPAddress ) & 0xffUL ),                                   \\r
118                                                                                         ( ( ( ulIPAddress ) >> 8UL ) & 0xffUL ),                \\r
119                                                                                         ( ( ( ulIPAddress ) >> 16UL ) & 0xffUL ),               \\r
120                                                                                         ( ( ( ulIPAddress ) >> 24UL ) & 0xffUL ) )\r
121 \r
122 #else /* ipconfigBYTE_ORDER */\r
123 \r
124         #define FreeRTOS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 )                              \\r
125                                                                                 ( ( ( uint32_t ) ( ucOctet0 ) ) << 24UL ) |                     \\r
126                                                                                 ( ( ( uint32_t ) ( ucOctet1 ) ) << 16UL ) |                     \\r
127                                                                                 ( ( ( uint32_t ) ( ucOctet2 ) ) <<  8UL ) |                     \\r
128                                                                                 ( ( uint32_t ) ( ucOctet3 ) )\r
129 \r
130         #define FreeRTOS_inet_ntoa( ulIPAddress, pucBuffer )                                                                    \\r
131                                                                                 sprintf( ( char * ) ( pucBuffer ), "%d.%d.%d.%d",       \\r
132                                                                                         ( ( ( ulIPAddress ) >> 24UL ) & 0xffUL ) ),             \\r
133                                                                                         ( ( ( ulIPAddress ) >> 16UL ) & 0xffUL ),               \\r
134                                                                                         ( ( ( ulIPAddress ) >> 8UL ) & 0xffUL ),                \\r
135                                                                                         ( ( ulIPAddress ) & 0xffUL )\r
136 \r
137 #endif /* ipconfigBYTE_ORDER */\r
138 \r
139 /* The socket type itself. */\r
140 typedef void *xSocket_t;\r
141 \r
142 /* The xSocketSet_t type is the equivalent to the fd_set type used by the \r
143 Berkeley API. */\r
144 typedef void *xSocketSet_t;\r
145 \r
146 /**\r
147  * FULL, UP-TO-DATE AND MAINTAINED REFERENCE DOCUMENTATION FOR ALL THESE\r
148  * FUNCTIONS IS AVAILABLE ON THE FOLLOWING URL:\r
149  * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/FreeRTOS_UDP_API_Functions.shtml\r
150  */\r
151 xSocket_t FreeRTOS_socket( portBASE_TYPE xDomain, portBASE_TYPE xType, portBASE_TYPE xProtocol );\r
152 int32_t FreeRTOS_recvfrom( xSocket_t xSocket, void *pvBuffer, size_t xBufferLength, uint32_t ulFlags, struct freertos_sockaddr *pxSourceAddress, socklen_t *pxSourceAddressLength );\r
153 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
154 portBASE_TYPE FreeRTOS_bind( xSocket_t xSocket, struct freertos_sockaddr *pxAddress, socklen_t xAddressLength );\r
155 portBASE_TYPE FreeRTOS_setsockopt( xSocket_t xSocket, int32_t lLevel, int32_t lOptionName, const void *pvOptionValue, size_t xOptionLength );\r
156 portBASE_TYPE FreeRTOS_closesocket( xSocket_t xSocket );\r
157 uint32_t FreeRTOS_gethostbyname( const uint8_t *pcHostName );\r
158 uint32_t FreeRTOS_inet_addr( const uint8_t * pucIPAddress );\r
159 \r
160 #if ipconfigSUPPORT_SELECT_FUNCTION == 1\r
161         xSocketSet_t FreeRTOS_CreateSocketSet( unsigned portBASE_TYPE uxEventQueueLength );\r
162         portBASE_TYPE FreeRTOS_FD_SET( xSocket_t xSocket, xSocketSet_t xSocketSet );\r
163         portBASE_TYPE FreeRTOS_FD_CLR( xSocket_t xSocket, xSocketSet_t xSocketSet );\r
164         xSocket_t FreeRTOS_select( xSocketSet_t xSocketSet, portTickType xBlockTimeTicks );\r
165 #endif /* ipconfigSUPPORT_SELECT_FUNCTION */\r
166 \r
167 #endif /* FREERTOS_UDP_H */\r
168 \r
169 \r
170 \r
171 \r
172 \r
173 \r
174 \r
175 \r
176 \r
177 \r
178 \r
179 \r
180 \r