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