1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 /** 32 * @addtogroup WLAN 33 * @{ 34 * 35 * @brief Provides cross-OS migration, component adaptation, and modular assembly and compilation. 36 * 37 * Based on the unified APIs provided by the WLAN module, developers of the Hardware Driver Interface 38 * (HDI) are capable of creating, disabling, scanning for, and connecting to WLAN hotspots, managing WLAN chips, 39 * network devices, and power, and applying for, releasing, and moving network data buffers. 40 * 41 * @since 1.0 42 * @version 1.0 43 */ 44 45 #ifndef _HDF_NETBUF_ADAPTER_H 46 #define _HDF_NETBUF_ADAPTER_H 47 48 #include "osal_spinlock.h" 49 #include "hdf_dlist.h" 50 #include "lwip/pbuf.h" 51 52 #ifdef __cplusplus 53 #if __cplusplus 54 extern "C" { 55 #endif 56 #endif /* __cplusplus */ 57 58 /** 59 * @brief Enumerates the segments of a network data buffer. 60 * 61 * The entire network data buffer is divided into three segments: a header, data, and a tail. 62 * The header and tail are used to extend both ends of the data segment. 63 * 64 * @since 1.0 65 */ 66 enum { 67 E_HEAD_BUF, /**< Header buffer segment */ 68 E_DATA_BUF, /**< Data segment */ 69 E_TAIL_BUF, /**< Tail buffer segment */ 70 MAX_BUF_NUM /**< Maximum number of buffer segments */ 71 }; 72 73 /** 74 * @brief Defines the data buffer field. 75 * 76 * The data buffer field records the offset (based on the memory buffer address) and length of each buffer segment. 77 * 78 * @since 1.0 79 */ 80 struct BufField { 81 uint32_t offset; /**< Offset of the buffer segment */ 82 uint32_t len; /**< Length of the buffer segment */ 83 }; 84 85 /** 86 * @brief Defines the reserved field of a network data buffer used to store private information. 87 * 88 * The length of the reserved field is <b>68</b> bytes. 89 */ 90 #define MAX_NETBUF_RESEVER_SIZE 68 91 92 /** 93 * @brief Records and saves a network data buffer. 94 * 95 * This structure is used to transmit network data between the protocol stack and network driver. 96 * 97 * @since 1.0 98 */ 99 typedef struct NetBuf { 100 struct DListHead dlist; /**< Doubly linked list. Generally, multiple network data buffers are 101 linked by using a doubly linked list. */ 102 struct BufField bufs[MAX_BUF_NUM]; /**< Defines buffer segments used to record the offset address 103 (based on the memory buffer address) and length of each buffer segment, 104 including the header buffer segment, data segment, and tail buffer segment. 105 For details, see {@link MAX_BUF_NUM}. */ 106 uint8_t *mem; /**< Memory buffer address */ 107 uint32_t len; /**< Length of the memory buffer */ 108 uint32_t dataLen; /**< Actual data length of the network data buffer */ 109 void *dev; /**< Network device that receives the network data */ 110 uint32_t qmap; /**< Queue mappings of the network data buffer */ 111 uint8_t rsv[MAX_NETBUF_RESEVER_SIZE]; /**< Reserved field. For details, see {@link MAX_NETBUF_RESEVER_SIZE}. */ 112 } NetBuf; 113 114 /** 115 * @brief Indicates the queues for storing network data. 116 * 117 * Queues can be used to process multiple pieces of network data in a centralized manner, improving efficiency. 118 * 119 * @since 1.0 120 */ 121 typedef struct NetBufQueue { 122 struct DListHead dlist; /**< Doubly linked list. Generally, multiple network data buffers are linked 123 by using a doubly linked list. */ 124 uint32_t size; /**< Number of network data buffers in the queue */ 125 OsalSpinlock lock; /**< Queue operation lock */ 126 } NetBufQueue; 127 128 struct NetDevice; 129 130 /** 131 * @brief Converts the <b>pbuf</b> structure of Lightweight TCP/IP Stack (lwIP) to a network data buffer. 132 * 133 * When a network device is specified, the reserved space of the network device will be added to 134 * the size of the converted network data buffer. 135 * 136 * @param netdev Indicates the pointer to the network device. 137 * @param lwip_buf Indicates the pointer to the data buffer of lwIP. 138 * 139 * @return Returns the pointer to the network data buffer if the operation is successful; 140 * returns <b>NULL</b> otherwise. 141 * 142 * @since 1.0 143 */ 144 NetBuf *Pbuf2NetBuf(const struct NetDevice *netdev, struct pbuf *lwipBuf); 145 146 /** 147 * @brief Converts a network data buffer to the <b>pbuf</b> structure of Lightweight TCP/IP Stack (lwIP). 148 * 149 * @param nb Indicates the pointer to the network data buffer. 150 * 151 * @return Returns the pointer to the <b>pbuf</b> structure if the operation is successful; 152 * returns <b>NULL</b> otherwise. 153 * 154 * @since 1.0 155 */ 156 struct pbuf *NetBuf2Pbuf(const NetBuf *nb); 157 158 #ifdef __cplusplus 159 #if __cplusplus 160 } 161 #endif 162 #endif /* __cplusplus */ 163 164 #endif 165 /** @} */ 166