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 NETWORK_BUFFER_MANAGEMENT_H
29 #define NETWORK_BUFFER_MANAGEMENT_H
30 
31 /* *INDENT-OFF* */
32 #ifdef __cplusplus
33     extern "C" {
34 #endif
35 /* *INDENT-ON* */
36 
37 #include "FreeRTOS_IP.h"
38 
39 /* _HT_ Two macro's needed while debugging/testing, please ignore. */
40 
41 #define BUFFER_FROM_WHERE_DECL
42 #define BUFFER_FROM_WHERE_CALL( aWhere )
43 
44 /* NOTE PUBLIC API FUNCTIONS. */
45 BaseType_t xNetworkBuffersInitialise( void );
46 NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes,
47                                                               TickType_t xBlockTimeTicks );
48 
49 /* The definition of the below function is only available if BufferAllocation_2.c has been linked into the source. */
50 NetworkBufferDescriptor_t * pxNetworkBufferGetFromISR( size_t xRequestedSizeBytes );
51 void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer );
52 
53 /* The definition of the below function is only available if BufferAllocation_2.c has been linked into the source. */
54 BaseType_t vNetworkBufferReleaseFromISR( NetworkBufferDescriptor_t * const pxNetworkBuffer );
55 uint8_t * pucGetNetworkBuffer( size_t * pxRequestedSizeBytes );
56 void vReleaseNetworkBuffer( uint8_t * pucEthernetBuffer );
57 
58 /* Get the current number of free network buffers. */
59 UBaseType_t uxGetNumberOfFreeNetworkBuffers( void );
60 
61 /* Get the lowest number of free network buffers. */
62 UBaseType_t uxGetMinimumFreeNetworkBuffers( void );
63 
64 /* Copy a network buffer into a bigger buffer. */
65 NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer,
66                                                                     size_t uxNewLength );
67 
68 /* Increase the size of a Network Buffer.
69  * In case BufferAllocation_2.c is used, the new space must be allocated. */
70 NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer,
71                                                                  size_t xNewSizeBytes );
72 
73 #if ipconfigTCP_IP_SANITY
74 
75 /*
76  * Check if an address is a valid pointer to a network descriptor
77  * by looking it up in the array of network descriptors
78  */
79     UBaseType_t bIsValidNetworkDescriptor( const NetworkBufferDescriptor_t * pxDesc );
80     BaseType_t prvIsFreeBuffer( const NetworkBufferDescriptor_t * pxDescr );
81 #endif
82 
83 /* *INDENT-OFF* */
84 #ifdef __cplusplus
85     } /* extern "C" */
86 #endif
87 /* *INDENT-ON* */
88 
89 
90 #endif /* NETWORK_BUFFER_MANAGEMENT_H */
91