1 /** @file 2 * @brief Network core definitions 3 * 4 * Definitions for networking support. 5 */ 6 7 /* 8 * Copyright (c) 2015 Intel Corporation 9 * 10 * SPDX-License-Identifier: Apache-2.0 11 */ 12 13 #ifndef ZEPHYR_INCLUDE_NET_NET_CORE_H_ 14 #define ZEPHYR_INCLUDE_NET_NET_CORE_H_ 15 16 #include <stdbool.h> 17 #include <string.h> 18 19 #include <zephyr/logging/log.h> 20 #include <zephyr/sys/__assert.h> 21 #include <zephyr/kernel.h> 22 23 #include <zephyr/net/net_timeout.h> 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /** 30 * @brief Networking 31 * @defgroup networking Networking 32 * @since 1.0 33 * @version 1.0.0 34 * @ingroup connectivity 35 * @{ 36 * @} 37 */ 38 39 /** 40 * @brief Network core library 41 * @defgroup net_core Network Core Library 42 * @since 1.0 43 * @version 1.0.0 44 * @ingroup networking 45 * @{ 46 */ 47 48 /** @cond INTERNAL_HIDDEN */ 49 50 /* Network subsystem logging helpers */ 51 #ifdef CONFIG_THREAD_NAME 52 #define NET_DBG(fmt, ...) LOG_DBG("(%s): " fmt, \ 53 k_thread_name_get(k_current_get()), \ 54 ##__VA_ARGS__) 55 #else 56 #define NET_DBG(fmt, ...) LOG_DBG("(%p): " fmt, k_current_get(), \ 57 ##__VA_ARGS__) 58 #endif /* CONFIG_THREAD_NAME */ 59 #define NET_ERR(fmt, ...) LOG_ERR(fmt, ##__VA_ARGS__) 60 #define NET_WARN(fmt, ...) LOG_WRN(fmt, ##__VA_ARGS__) 61 #define NET_INFO(fmt, ...) LOG_INF(fmt, ##__VA_ARGS__) 62 63 #define NET_HEXDUMP_DBG(_data, _length, _str) LOG_HEXDUMP_DBG(_data, _length, _str) 64 #define NET_HEXDUMP_ERR(_data, _length, _str) LOG_HEXDUMP_ERR(_data, _length, _str) 65 #define NET_HEXDUMP_WARN(_data, _length, _str) LOG_HEXDUMP_WRN(_data, _length, _str) 66 #define NET_HEXDUMP_INFO(_data, _length, _str) LOG_HEXDUMP_INF(_data, _length, _str) 67 68 #define NET_ASSERT(cond, ...) __ASSERT(cond, "" __VA_ARGS__) 69 70 /* This needs to be here in order to avoid circular include dependency between 71 * net_pkt.h and net_if.h 72 */ 73 #if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \ 74 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL) 75 #if !defined(NET_PKT_DETAIL_STATS_COUNT) 76 #if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) 77 78 #if defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL) 79 #define NET_PKT_DETAIL_STATS_COUNT 4 80 #else 81 #define NET_PKT_DETAIL_STATS_COUNT 3 82 #endif /* CONFIG_NET_PKT_RXTIME_STATS_DETAIL */ 83 84 #else 85 #define NET_PKT_DETAIL_STATS_COUNT 4 86 #endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL */ 87 88 #endif /* !NET_PKT_DETAIL_STATS_COUNT */ 89 #endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL || 90 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */ 91 92 /** @endcond */ 93 94 struct net_buf; 95 struct net_pkt; 96 struct net_context; 97 struct net_if; 98 99 /** 100 * @brief Net Verdict 101 */ 102 enum net_verdict { 103 /** Packet has been taken care of. */ 104 NET_OK, 105 /** Packet has not been touched, other part should decide about its 106 * fate. 107 */ 108 NET_CONTINUE, 109 /** Packet must be dropped. */ 110 NET_DROP, 111 }; 112 113 /** 114 * @brief Called by lower network stack or network device driver when 115 * a network packet has been received. The function will push the packet up in 116 * the network stack for further processing. 117 * 118 * @param iface Network interface where the packet was received. 119 * @param pkt Network packet data. 120 * 121 * @return 0 if ok, <0 if error. 122 */ 123 int net_recv_data(struct net_if *iface, struct net_pkt *pkt); 124 125 /** 126 * @brief Send data to network. 127 * 128 * @details Send data to network. This should not be used normally by 129 * applications as it requires that the network packet is properly 130 * constructed. 131 * 132 * @param pkt Network packet. 133 * 134 * @return 0 if ok, <0 if error. If <0 is returned, then the caller needs 135 * to unref the pkt in order to avoid memory leak. 136 */ 137 int net_send_data(struct net_pkt *pkt); 138 139 /** @cond INTERNAL_HIDDEN */ 140 141 /* Some helper defines for traffic class support */ 142 #if defined(CONFIG_NET_TC_TX_COUNT) && defined(CONFIG_NET_TC_RX_COUNT) 143 #define NET_TC_TX_COUNT CONFIG_NET_TC_TX_COUNT 144 #define NET_TC_RX_COUNT CONFIG_NET_TC_RX_COUNT 145 146 #if NET_TC_TX_COUNT > NET_TC_RX_COUNT 147 #define NET_TC_COUNT NET_TC_TX_COUNT 148 #else 149 #define NET_TC_COUNT NET_TC_RX_COUNT 150 #endif 151 #else /* CONFIG_NET_TC_TX_COUNT && CONFIG_NET_TC_RX_COUNT */ 152 #define NET_TC_TX_COUNT 0 153 #define NET_TC_RX_COUNT 0 154 #define NET_TC_COUNT 0 155 #endif /* CONFIG_NET_TC_TX_COUNT && CONFIG_NET_TC_RX_COUNT */ 156 157 /* @endcond */ 158 159 /** 160 * @} 161 */ 162 163 #ifdef __cplusplus 164 } 165 #endif 166 167 #endif /* ZEPHYR_INCLUDE_NET_NET_CORE_H_ */ 168