xref: /FreeRTOS-Plus-TCP-v4.0.0/source/include/FreeRTOS_IPv4.h (revision f5ecc5f201ba569467d090b79b19c5e0baead322)
1 /*
2  * FreeRTOS+TCP <DEVELOPMENT BRANCH>
3  * Copyright (C) 2022 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * SPDX-License-Identifier: MIT
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of
8  * this software and associated documentation files (the "Software"), to deal in
9  * the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11  * the Software, and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * http://aws.amazon.com/freertos
25  * http://www.FreeRTOS.org
26  */
27 
28 #ifndef FREERTOS_IPV4_H
29 #define FREERTOS_IPV4_H
30 
31 #include "FreeRTOS.h"
32 #include "task.h"
33 
34 /* Application level configuration options. */
35 #include "FreeRTOSIPConfig.h"
36 #include "FreeRTOSIPConfigDefaults.h"
37 #include "IPTraceMacroDefaults.h"
38 
39 /* *INDENT-OFF* */
40 #ifdef __cplusplus
41     extern "C" {
42 #endif
43 /* *INDENT-ON* */
44 
45 /* Forward declarations. */
46 struct xNETWORK_BUFFER;
47 enum eFrameProcessingResult;
48 struct xIP_PACKET;
49 
50 #define ipSIZE_OF_IPv4_HEADER               20U
51 #define ipSIZE_OF_IPv4_ADDRESS              4U
52 #define ipSIZE_OF_ICMPv4_HEADER             8U
53 #define ipTYPE_IPv4                         ( 0x40U )
54 
55 #define ipFIRST_LOOPBACK_IPv4               0x7F000000UL         /**< Lowest IPv4 loopback address (including). */
56 #define ipLAST_LOOPBACK_IPv4                0x80000000UL         /**< Highest IPv4 loopback address (excluding). */
57 
58 /* The first byte in the IPv4 header combines the IP version (4) with
59  * with the length of the IP header. */
60 #define ipIPV4_VERSION_HEADER_LENGTH_MIN    0x45U /**< Minimum IPv4 header length. */
61 #define ipIPV4_VERSION_HEADER_LENGTH_MAX    0x4FU /**< Maximum IPv4 header length. */
62 
63 /*
64  *  These functions come from the IPv4-only library.
65  *  TODO : They should get an extra parameter, the end-point
66  *  void FreeRTOS_SetIPAddress( uint32_t ulIPAddress );
67  *  void FreeRTOS_SetNetmask( uint32_t ulNetmask );
68  *  void FreeRTOS_SetGatewayAddress( uint32_t ulGatewayAddress );
69  *  uint32_t FreeRTOS_GetGatewayAddress( void );
70  *  uint32_t FreeRTOS_GetDNSServerAddress( void );
71  *  uint32_t FreeRTOS_GetNetmask( void );
72  */
73 
74 void FreeRTOS_SetIPAddress( uint32_t ulIPAddress );
75 void FreeRTOS_SetNetmask( uint32_t ulNetmask );
76 void FreeRTOS_SetGatewayAddress( uint32_t ulGatewayAddress );
77 uint32_t FreeRTOS_GetGatewayAddress( void );
78 uint32_t FreeRTOS_GetDNSServerAddress( void );
79 uint32_t FreeRTOS_GetNetmask( void );
80 uint32_t FreeRTOS_GetIPAddress( void );
81 
82 /* Show all valid ARP entries
83  */
84 #if ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 )
85     void FreeRTOS_PrintARPCache( void );
86 #endif
87 
88 /* Return pdTRUE if the IPv4 address is a multicast address. */
89 BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress );
90 
91 /* The function 'prvAllowIPPacket()' checks if a packets should be processed. */
92 enum eFrameProcessingResult prvAllowIPPacketIPv4( const struct xIP_PACKET * const pxIPPacket,
93                                                   const struct xNETWORK_BUFFER * const pxNetworkBuffer,
94                                                   UBaseType_t uxHeaderLength );
95 
96 /* Check if the IP-header is carrying options. */
97 enum eFrameProcessingResult prvCheckIP4HeaderOptions( struct xNETWORK_BUFFER * const pxNetworkBuffer );
98 
99 
100 /* *INDENT-OFF* */
101 #ifdef __cplusplus
102     } /* extern "C" */
103 #endif
104 /* *INDENT-ON* */
105 
106 #endif /* FREERTOS_IP_H */
107