Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fnet_netbuf.h Source File

fnet_netbuf.h

00001 /**************************************************************************
00002 *
00003 * Copyright 2011-2016 by Andrey Butok. FNET Community.
00004 * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc.
00005 *
00006 ***************************************************************************
00007 *
00008 *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00009 *  not use this file except in compliance with the License.
00010 *  You may obtain a copy of the License at
00011 *
00012 *  http://www.apache.org/licenses/LICENSE-2.0
00013 *
00014 *  Unless required by applicable law or agreed to in writing, software
00015 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00016 *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017 *  See the License for the specific language governing permissions and
00018 *  limitations under the License.
00019 *
00020 **********************************************************************/
00021 /*!
00022 * @brief Private. FNET Buffer and memory management definitions.
00023 *
00024 ***************************************************************************/
00025 
00026 #ifndef _FNET_NETBUF_H_
00027 
00028 #define _FNET_NETBUF_H_
00029 
00030 #include "fnet_mempool.h"
00031 
00032 /**************************************************************************/ /*!
00033  * @internal
00034  * @brief    netbuf flags.
00035  ******************************************************************************/
00036 typedef enum
00037 {
00038     FNET_NETBUF_FLAG_NONE                   = 0x00u,     /* None. */
00039     FNET_NETBUF_FLAG_BROADCAST              = 0x02u,     /* Send/received as link-level broadcast. */
00040     FNET_NETBUF_FLAG_MULTICAST              = 0x04u,     /* Send/received as link-level multicast. */
00041     FNET_NETBUF_FLAG_HW_IP_CHECKSUM         = 0x10u,     /* IPv4 header checksum is calculated/checked by HW.*/
00042     FNET_NETBUF_FLAG_HW_PROTOCOL_CHECKSUM   = 0x20u      /* Protocol (UDP, TCP, ICMP) checksum is calculated/checked by HW.*/
00043 } fnet_netbuf_flag_t;
00044 
00045 /**************************************************************************/ /*!
00046  * @internal
00047  * @brief    netbuf types.
00048  ******************************************************************************/
00049 typedef enum
00050 {
00051     FNET_NETBUF_TYPE_DATA    = 0,       /**< dynamic (data) allocation.*/
00052     FNET_NETBUF_TYPE_HEADER  = 1,
00053     FNET_NETBUF_TYPE_ADDRESS = 2,       /**< address of the message.*/
00054     FNET_NETBUF_TYPE_OPTION  = 3        /**< options.*/
00055 } fnet_netbuf_type_t;
00056 
00057 /**************************************************************************/ /*!
00058  * @internal
00059  * @brief    Header at beginning of each net_buf.
00060  ******************************************************************************/
00061 typedef struct fnet_netbuf
00062 {
00063     struct fnet_netbuf  *next;          /**< next buffer in chain */
00064     struct fnet_netbuf  *next_chain;    /**< next chain in queue/record */
00065     void                *data;          /**< pointer to the beginning of the data buffer */
00066     void                *data_ptr;      /**< pointer to actual data */
00067     fnet_size_t         length;         /**< amount of actual data in this net_buf */
00068     fnet_size_t         total_length;   /**< length of buffer + additionally chained buffers (only for first netbuf)*/
00069     fnet_flag_t         flags;
00070 } fnet_netbuf_t;
00071 
00072 #define FNET_NETBUF_COPYALL   ((fnet_size_t)(-1))
00073 
00074 #if defined(__cplusplus)
00075 extern "C" {
00076 #endif
00077 
00078 /* Memory management functions */
00079 fnet_return_t fnet_heap_init( void *heap_ptr, fnet_size_t heap_size );
00080 void fnet_free( void *ap );
00081 void *fnet_malloc( fnet_size_t nbytes );
00082 void *fnet_malloc_zero( fnet_size_t nbytes );
00083 fnet_size_t fnet_free_mem_status( void );
00084 fnet_size_t fnet_malloc_max( void );
00085 void fnet_mem_release( void );
00086 
00087 void fnet_free_netbuf( void *ap );
00088 void *fnet_malloc_netbuf( fnet_size_t nbytes );
00089 fnet_size_t fnet_free_mem_status_netbuf( void );
00090 fnet_size_t fnet_malloc_max_netbuf( void );
00091 void fnet_mem_release_netbuf( void );
00092 
00093 /* Netbuf service routines */
00094 fnet_netbuf_t *fnet_netbuf_new( fnet_size_t len, fnet_bool_t drain );
00095 fnet_netbuf_t *fnet_netbuf_free( fnet_netbuf_t *nb );
00096 fnet_netbuf_t *fnet_netbuf_copy( fnet_netbuf_t *nb, fnet_size_t offset, fnet_size_t len, fnet_bool_t drain );
00097 fnet_netbuf_t *fnet_netbuf_from_buf( void *data_ptr, fnet_size_t len, fnet_bool_t drain );
00098 fnet_netbuf_t *fnet_netbuf_concat( fnet_netbuf_t *nb1, fnet_netbuf_t *nb2 );
00099 void fnet_netbuf_to_buf( fnet_netbuf_t *nb, fnet_size_t offset, fnet_size_t len, void *data_ptr );
00100 fnet_return_t fnet_netbuf_pullup( fnet_netbuf_t **nb_ptr, fnet_size_t len);
00101 void fnet_netbuf_trim( fnet_netbuf_t **nb_ptr, fnet_int32_t len );
00102 fnet_netbuf_t *fnet_netbuf_cut_center( fnet_netbuf_t **nb_ptr, fnet_size_t offset, fnet_size_t len);
00103 void fnet_netbuf_add_chain( fnet_netbuf_t **nb_ptr, fnet_netbuf_t *nb_chain );
00104 void fnet_netbuf_del_chain( fnet_netbuf_t **nb_ptr, fnet_netbuf_t *nb_chain );
00105 void fnet_netbuf_free_chain( fnet_netbuf_t *nb );
00106 
00107 #if 0 /* For Debug needs.*/
00108 fnet_return_t fnet_netbuf_mempool_check( void );
00109 void FNET_DEBUG_NETBUF_print_chain( fnet_netbuf_t *nb, fnet_uint8_t *str, fnrt_index_t max);
00110 #endif
00111 
00112 #if 0 /* For Debug needs.*/
00113 void fnet_free_netbuf_low( void *ap );
00114 #define fnet_free_netbuf(ap )   do{ fnet_free_netbuf_low( ap ); \
00115         ap = (void *)0x0; \
00116     } while(0)
00117 #endif
00118 
00119 #if defined(__cplusplus)
00120 }
00121 #endif
00122 
00123 #endif