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