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