Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_buf.h
Go to the documentation of this file.
1
4
5/*
6 * Copyright (c) 2015 Intel Corporation
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10#ifndef ZEPHYR_INCLUDE_NET_BUF_H_
11#define ZEPHYR_INCLUDE_NET_BUF_H_
12
13#include <stddef.h>
14#include <zephyr/types.h>
15#include <zephyr/sys/util.h>
16#include <zephyr/kernel.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
39
40/* Alignment needed for various parts of the buffer definition */
41#if CONFIG_NET_BUF_ALIGNMENT == 0
42#define __net_buf_align __aligned(sizeof(void *))
43#else
44#define __net_buf_align __aligned(CONFIG_NET_BUF_ALIGNMENT)
45#endif
46
56#define NET_BUF_SIMPLE_DEFINE(_name, _size) \
57 uint8_t net_buf_data_##_name[_size]; \
58 struct net_buf_simple _name = { \
59 .data = net_buf_data_##_name, \
60 .len = 0, \
61 .size = _size, \
62 .__buf = net_buf_data_##_name, \
63 }
64
75#define NET_BUF_SIMPLE_DEFINE_STATIC(_name, _size) \
76 static __noinit uint8_t net_buf_data_##_name[_size]; \
77 static struct net_buf_simple _name = { \
78 .data = net_buf_data_##_name, \
79 .len = 0, \
80 .size = _size, \
81 .__buf = net_buf_data_##_name, \
82 }
83
100
108
111
115 uint8_t *__buf;
116};
117
134#define NET_BUF_SIMPLE(_size) \
135 ((struct net_buf_simple *)(&(struct { \
136 struct net_buf_simple buf; \
137 uint8_t data[_size]; \
138 }) { \
139 .buf.size = _size, \
140 }))
141
151static inline void net_buf_simple_init(struct net_buf_simple *buf,
152 size_t reserve_head)
153{
154 if (!buf->__buf) {
155 buf->__buf = (uint8_t *)buf + sizeof(*buf);
156 }
157
158 buf->data = buf->__buf + reserve_head;
159 buf->len = 0U;
160}
161
172 void *data, size_t size);
173
181static inline void net_buf_simple_reset(struct net_buf_simple *buf)
182{
183 buf->len = 0U;
184 buf->data = buf->__buf;
185}
186
197void net_buf_simple_clone(const struct net_buf_simple *original,
198 struct net_buf_simple *clone);
199
211void *net_buf_simple_add(struct net_buf_simple *buf, size_t len);
212
225void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem,
226 size_t len);
227
240
252
264
276
288
300
312
324
336
348
360
372
384
395void *net_buf_simple_remove_mem(struct net_buf_simple *buf, size_t len);
396
408
420
432
444
456
468
480
492
504
516
528
540
552
564void *net_buf_simple_push(struct net_buf_simple *buf, size_t len);
565
578void *net_buf_simple_push_mem(struct net_buf_simple *buf, const void *mem,
579 size_t len);
580
591
602
612
623
634
645
656
667
678
689
700
711
722
734void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len);
735
747void *net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len);
748
760
772
784
796
808
820
832
844
856
868
880
892
904
914static inline uint8_t *net_buf_simple_tail(const struct net_buf_simple *buf)
915{
916 return buf->data + buf->len;
917}
918
928static inline size_t net_buf_simple_headroom(const struct net_buf_simple *buf)
929{
930 return buf->data - buf->__buf;
931}
932
942static inline size_t net_buf_simple_tailroom(const struct net_buf_simple *buf)
943{
944 return buf->size - net_buf_simple_headroom(buf) - buf->len;
945}
946
961__deprecated static inline uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf)
962{
963 return buf->size - net_buf_simple_headroom(buf);
964}
965
983static inline bool net_buf_simple_is_valid(const struct net_buf_simple *buf)
984{
985 size_t headroom;
986
987 if (buf == NULL || buf->__buf == NULL || buf->data < buf->__buf) {
988 return false;
989 }
990
991 headroom = net_buf_simple_headroom(buf);
992 if (headroom > buf->size) {
993 return false;
994 }
995
996 return (size_t)buf->len <= (size_t)(buf->size - headroom);
997}
998
1012
1021static inline void net_buf_simple_save(const struct net_buf_simple *buf,
1023{
1024 state->offset = (uint16_t)net_buf_simple_headroom(buf);
1025 state->len = buf->len;
1026}
1027
1037static inline void net_buf_simple_restore(struct net_buf_simple *buf,
1039{
1040 buf->data = buf->__buf + state->offset;
1041 buf->len = state->len;
1042}
1043
1053#define NET_BUF_EXTERNAL_DATA BIT(0)
1054
1062struct net_buf {
1065
1068
1101 union {
1103 atomic_t ref_word;
1105 struct {
1106#if defined(CONFIG_BIG_ENDIAN)
1107 /* atomic_t is typedef'd as long (BUILD_ASSERTed in
1108 * lib/net_buf/buf.c); on a 64-bit big-endian build
1109 * the byte struct needs 4 bytes of padding so that
1110 * `ref` lands on the least-significant byte of
1111 * ref_word.
1112 */
1113#if (__SIZEOF_LONG__ == 8)
1115 uint8_t _ref_word_pad[4];
1117#endif
1120
1123
1125 uint8_t flags;
1126
1128 uint8_t ref;
1129#else
1132
1135
1138
1141#endif
1142 };
1143 };
1144
1148 union {
1149 /* The ABI of this struct must match net_buf_simple */
1150 struct {
1153
1156
1159
1164 uint8_t *__buf;
1165 };
1166
1168 struct net_buf_simple b;
1170 };
1171
1173 uint8_t user_data[] __net_buf_align;
1174};
1175
1177
1178struct net_buf_data_cb {
1179 uint8_t * __must_check (*alloc)(struct net_buf *buf, size_t *size,
1180 k_timeout_t timeout);
1181 uint8_t * __must_check (*ref)(struct net_buf *buf, uint8_t *data);
1182 void (*unref)(struct net_buf *buf, uint8_t *data);
1183};
1184
1185struct net_buf_data_alloc {
1186 const struct net_buf_data_cb *cb;
1187 void *alloc_data;
1188 size_t max_alloc_size;
1189 size_t alignment;
1190};
1191
1193
1201 struct k_lifo free;
1202
1205
1208
1211
1214
1215#if defined(CONFIG_NET_BUF_POOL_USAGE)
1217 atomic_t avail_count;
1218
1220 const uint16_t pool_size;
1221
1223 uint16_t max_used;
1224
1226 const char *name;
1227#endif /* CONFIG_NET_BUF_POOL_USAGE */
1228
1230 void (*const destroy)(struct net_buf *buf);
1231
1233 const struct net_buf_data_alloc *alloc;
1234
1236 struct net_buf * const __bufs;
1237};
1238
1240#define NET_BUF_POOL_USAGE_INIT(_pool, _count) \
1241 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.avail_count = ATOMIC_INIT(_count),)) \
1242 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.max_used = 0,)) \
1243 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.name = STRINGIFY(_pool),))
1244
1245#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \
1246 { \
1247 .free = Z_LIFO_INITIALIZER(_pool.free), \
1248 .lock = { }, \
1249 .buf_count = _count, \
1250 .uninit_count = _count, \
1251 .user_data_size = _ud_size, \
1252 NET_BUF_POOL_USAGE_INIT(_pool, _count) \
1253 .destroy = _destroy, \
1254 .alloc = _alloc, \
1255 .__bufs = (struct net_buf *)_bufs, \
1256 }
1257
1258#define _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size) \
1259 struct _net_buf_##_name { uint8_t b[sizeof(struct net_buf)]; \
1260 uint8_t ud[_ud_size]; } __net_buf_align; \
1261 BUILD_ASSERT(_ud_size <= UINT8_MAX); \
1262 BUILD_ASSERT(offsetof(struct net_buf, user_data) == \
1263 offsetof(struct _net_buf_##_name, ud), "Invalid offset"); \
1264 BUILD_ASSERT(__alignof__(struct net_buf) == \
1265 __alignof__(struct _net_buf_##_name), "Invalid alignment"); \
1266 BUILD_ASSERT(sizeof(struct _net_buf_##_name) == \
1267 ROUND_UP(sizeof(struct net_buf) + _ud_size, __alignof__(struct net_buf)), \
1268 "Size cannot be determined"); \
1269 static struct _net_buf_##_name _net_buf_##_name[_count] __noinit
1270
1271extern const struct net_buf_data_alloc net_buf_heap_alloc;
1273
1301#define NET_BUF_POOL_HEAP_DEFINE(_name, _count, _ud_size, _destroy) \
1302 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1303 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1304 NET_BUF_POOL_INITIALIZER(_name, &net_buf_heap_alloc, \
1305 _net_buf_##_name, _count, _ud_size, \
1306 _destroy)
1307
1309
1310struct net_buf_pool_fixed {
1311 uint8_t *data_pool;
1312};
1313
1314extern const struct net_buf_data_cb net_buf_fixed_cb;
1315
1317
1346#define NET_BUF_POOL_FIXED_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1347 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1348 static uint8_t __noinit net_buf_data_##_name[_count][_data_size] __net_buf_align; \
1349 static const struct net_buf_pool_fixed net_buf_fixed_##_name = { \
1350 .data_pool = (uint8_t *)net_buf_data_##_name, \
1351 }; \
1352 static const struct net_buf_data_alloc net_buf_fixed_alloc_##_name = { \
1353 .cb = &net_buf_fixed_cb, \
1354 .alloc_data = (void *)&net_buf_fixed_##_name, \
1355 .max_alloc_size = _data_size, \
1356 }; \
1357 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1358 NET_BUF_POOL_INITIALIZER(_name, &net_buf_fixed_alloc_##_name, \
1359 _net_buf_##_name, _count, _ud_size, \
1360 _destroy)
1361
1363extern const struct net_buf_data_cb net_buf_var_cb;
1365
1390#define NET_BUF_POOL_VAR_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1391 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1392 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1393 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1394 .cb = &net_buf_var_cb, \
1395 .alloc_data = &net_buf_mem_pool_##_name, \
1396 .max_alloc_size = 0, \
1397 }; \
1398 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1399 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1400 _net_buf_##_name, _count, _ud_size, \
1401 _destroy)
1402
1433#define NET_BUF_POOL_VAR_ALIGN_DEFINE(_name, _count, _data_size, _ud_size, \
1434 _destroy, _align) \
1435 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1436 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1437 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1438 .cb = &net_buf_var_cb, \
1439 .alloc_data = &net_buf_mem_pool_##_name, \
1440 .max_alloc_size = 0, \
1441 .alignment = _align, \
1442 }; \
1443 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1444 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1445 _net_buf_##_name, _count, _ud_size, \
1446 _destroy)
1447
1469#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy) \
1470 NET_BUF_POOL_FIXED_DEFINE(_name, _count, _size, _ud_size, _destroy)
1471
1480
1493int net_buf_id(const struct net_buf *buf);
1494
1495#if defined(CONFIG_NET_BUF_POOL_USAGE) || defined(__DOXYGEN__)
1509static inline size_t net_buf_get_available(struct net_buf_pool *pool)
1510{
1511 return (size_t)atomic_get(&pool->avail_count);
1512}
1513
1523static inline size_t net_buf_get_max_used(struct net_buf_pool *pool)
1524{
1525 return (size_t)pool->max_used;
1526}
1527#endif /* defined(CONFIG_NET_BUF_POOL_USAGE) || defined(__DOXYGEN__) */
1528
1543#if defined(CONFIG_NET_BUF_LOG)
1544struct net_buf * __must_check net_buf_alloc_fixed_debug(struct net_buf_pool *pool,
1545 k_timeout_t timeout,
1546 const char *func,
1547 int line);
1548#define net_buf_alloc_fixed(_pool, _timeout) \
1549 net_buf_alloc_fixed_debug(_pool, _timeout, __func__, __LINE__)
1550#else
1551struct net_buf * __must_check net_buf_alloc_fixed(struct net_buf_pool *pool,
1552 k_timeout_t timeout);
1553#endif
1554
1558static inline struct net_buf * __must_check net_buf_alloc(struct net_buf_pool *pool,
1559 k_timeout_t timeout)
1560{
1561 return net_buf_alloc_fixed(pool, timeout);
1562}
1563
1579#if defined(CONFIG_NET_BUF_LOG)
1580struct net_buf * __must_check net_buf_alloc_len_debug(struct net_buf_pool *pool,
1581 size_t size,
1582 k_timeout_t timeout,
1583 const char *func,
1584 int line);
1585#define net_buf_alloc_len(_pool, _size, _timeout) \
1586 net_buf_alloc_len_debug(_pool, _size, _timeout, __func__, __LINE__)
1587#else
1588struct net_buf * __must_check net_buf_alloc_len(struct net_buf_pool *pool,
1589 size_t size,
1590 k_timeout_t timeout);
1591#endif
1592
1614#if defined(CONFIG_NET_BUF_LOG)
1615struct net_buf * __must_check net_buf_alloc_with_data_debug(struct net_buf_pool *pool,
1616 void *data, size_t size,
1617 k_timeout_t timeout,
1618 const char *func, int line);
1619#define net_buf_alloc_with_data(_pool, _data_, _size, _timeout) \
1620 net_buf_alloc_with_data_debug(_pool, _data_, _size, _timeout, \
1621 __func__, __LINE__)
1622#else
1623struct net_buf * __must_check net_buf_alloc_with_data(struct net_buf_pool *pool,
1624 void *data, size_t size,
1625 k_timeout_t timeout);
1626#endif
1627
1637static inline void net_buf_destroy(struct net_buf *buf)
1638{
1639 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id);
1640
1641 if (buf->__buf) {
1642 if (!(buf->flags & NET_BUF_EXTERNAL_DATA)) {
1643 pool->alloc->cb->unref(buf, buf->__buf);
1644 }
1645 buf->__buf = NULL;
1646 }
1647
1648 k_lifo_put(&pool->free, buf);
1649}
1650
1679struct net_buf *__must_check net_buf_reuse(struct net_buf **orig);
1680
1688void net_buf_reset(struct net_buf *buf);
1689
1698void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve);
1699
1711void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf);
1712
1722struct net_buf * __must_check net_buf_slist_get(sys_slist_t *list);
1723
1733#if defined(CONFIG_NET_BUF_LOG)
1734void net_buf_slist_purge_debug(sys_slist_t *list, const char *func, int line);
1735#define net_buf_slist_purge(_list) net_buf_slist_purge_debug(_list, __func__, __LINE__)
1736#else
1738#endif
1739
1748#if defined(CONFIG_NET_BUF_LOG)
1749void net_buf_fifo_purge_debug(struct k_fifo *fifo, const char *func, int line);
1750#define net_buf_fifo_purge(_fifo) net_buf_fifo_purge_debug(_fifo, __func__, __LINE__)
1751#else
1752void net_buf_fifo_purge(struct k_fifo *fifo);
1753#endif
1754
1764#if defined(CONFIG_NET_BUF_LOG)
1765void net_buf_unref_debug(struct net_buf *buf, const char *func, int line);
1766#define net_buf_unref(_buf) \
1767 net_buf_unref_debug(_buf, __func__, __LINE__)
1768#else
1769void net_buf_unref(struct net_buf *buf);
1770#endif
1771
1782struct net_buf * __must_check net_buf_ref(struct net_buf *buf);
1783
1812static inline struct net_buf *__must_check net_buf_take(struct net_buf **orig)
1813{
1814 return (struct net_buf *)atomic_ptr_clear((atomic_ptr_t *)orig);
1815}
1816
1838static inline struct net_buf *__must_check net_buf_take_plain(struct net_buf **orig)
1839{
1840 struct net_buf *buf = *orig;
1841
1842 *orig = NULL;
1843
1844 return buf;
1845}
1846
1855static inline void net_buf_drop(struct net_buf **orig)
1856{
1857 struct net_buf *buf = net_buf_take(orig);
1858
1859 if (buf != NULL) {
1860 net_buf_unref(buf);
1861 }
1862}
1863
1877struct net_buf * __must_check net_buf_clone(struct net_buf *buf,
1878 k_timeout_t timeout);
1879
1887static inline void * __must_check net_buf_user_data(const struct net_buf *buf)
1888{
1889 return (void *)buf->user_data;
1890}
1891
1901int net_buf_user_data_copy(struct net_buf *dst, const struct net_buf *src);
1902
1911static inline void net_buf_reserve(struct net_buf *buf, size_t reserve)
1912{
1913 net_buf_simple_reserve(&buf->b, reserve);
1914}
1915
1927static inline void *net_buf_add(struct net_buf *buf, size_t len)
1928{
1929 return net_buf_simple_add(&buf->b, len);
1930}
1931
1944static inline void *net_buf_add_mem(struct net_buf *buf, const void *mem,
1945 size_t len)
1946{
1947 return net_buf_simple_add_mem(&buf->b, mem, len);
1948}
1949
1961static inline uint8_t *net_buf_add_u8(struct net_buf *buf, uint8_t val)
1962{
1963 return net_buf_simple_add_u8(&buf->b, val);
1964}
1965
1976static inline void net_buf_add_le16(struct net_buf *buf, uint16_t val)
1977{
1978 net_buf_simple_add_le16(&buf->b, val);
1979}
1980
1991static inline void net_buf_add_be16(struct net_buf *buf, uint16_t val)
1992{
1993 net_buf_simple_add_be16(&buf->b, val);
1994}
1995
2006static inline void net_buf_add_le24(struct net_buf *buf, uint32_t val)
2007{
2008 net_buf_simple_add_le24(&buf->b, val);
2009}
2010
2021static inline void net_buf_add_be24(struct net_buf *buf, uint32_t val)
2022{
2023 net_buf_simple_add_be24(&buf->b, val);
2024}
2025
2036static inline void net_buf_add_le32(struct net_buf *buf, uint32_t val)
2037{
2038 net_buf_simple_add_le32(&buf->b, val);
2039}
2040
2051static inline void net_buf_add_be32(struct net_buf *buf, uint32_t val)
2052{
2053 net_buf_simple_add_be32(&buf->b, val);
2054}
2055
2066static inline void net_buf_add_le40(struct net_buf *buf, uint64_t val)
2067{
2068 net_buf_simple_add_le40(&buf->b, val);
2069}
2070
2081static inline void net_buf_add_be40(struct net_buf *buf, uint64_t val)
2082{
2083 net_buf_simple_add_be40(&buf->b, val);
2084}
2085
2096static inline void net_buf_add_le48(struct net_buf *buf, uint64_t val)
2097{
2098 net_buf_simple_add_le48(&buf->b, val);
2099}
2100
2111static inline void net_buf_add_be48(struct net_buf *buf, uint64_t val)
2112{
2113 net_buf_simple_add_be48(&buf->b, val);
2114}
2115
2126static inline void net_buf_add_le64(struct net_buf *buf, uint64_t val)
2127{
2128 net_buf_simple_add_le64(&buf->b, val);
2129}
2130
2141static inline void net_buf_add_be64(struct net_buf *buf, uint64_t val)
2142{
2143 net_buf_simple_add_be64(&buf->b, val);
2144}
2145
2156static inline void *net_buf_remove_mem(struct net_buf *buf, size_t len)
2157{
2158 return net_buf_simple_remove_mem(&buf->b, len);
2159}
2160
2171static inline uint8_t net_buf_remove_u8(struct net_buf *buf)
2172{
2173 return net_buf_simple_remove_u8(&buf->b);
2174}
2175
2186static inline uint16_t net_buf_remove_le16(struct net_buf *buf)
2187{
2188 return net_buf_simple_remove_le16(&buf->b);
2189}
2190
2201static inline uint16_t net_buf_remove_be16(struct net_buf *buf)
2202{
2203 return net_buf_simple_remove_be16(&buf->b);
2204}
2205
2216static inline uint32_t net_buf_remove_be24(struct net_buf *buf)
2217{
2218 return net_buf_simple_remove_be24(&buf->b);
2219}
2220
2231static inline uint32_t net_buf_remove_le24(struct net_buf *buf)
2232{
2233 return net_buf_simple_remove_le24(&buf->b);
2234}
2235
2246static inline uint32_t net_buf_remove_le32(struct net_buf *buf)
2247{
2248 return net_buf_simple_remove_le32(&buf->b);
2249}
2250
2261static inline uint32_t net_buf_remove_be32(struct net_buf *buf)
2262{
2263 return net_buf_simple_remove_be32(&buf->b);
2264}
2265
2276static inline uint64_t net_buf_remove_le40(struct net_buf *buf)
2277{
2278 return net_buf_simple_remove_le40(&buf->b);
2279}
2280
2291static inline uint64_t net_buf_remove_be40(struct net_buf *buf)
2292{
2293 return net_buf_simple_remove_be40(&buf->b);
2294}
2295
2306static inline uint64_t net_buf_remove_le48(struct net_buf *buf)
2307{
2308 return net_buf_simple_remove_le48(&buf->b);
2309}
2310
2321static inline uint64_t net_buf_remove_be48(struct net_buf *buf)
2322{
2323 return net_buf_simple_remove_be48(&buf->b);
2324}
2325
2336static inline uint64_t net_buf_remove_le64(struct net_buf *buf)
2337{
2338 return net_buf_simple_remove_le64(&buf->b);
2339}
2340
2351static inline uint64_t net_buf_remove_be64(struct net_buf *buf)
2352{
2353 return net_buf_simple_remove_be64(&buf->b);
2354}
2355
2367static inline void *net_buf_push(struct net_buf *buf, size_t len)
2368{
2369 return net_buf_simple_push(&buf->b, len);
2370}
2371
2384static inline void *net_buf_push_mem(struct net_buf *buf, const void *mem,
2385 size_t len)
2386{
2387 return net_buf_simple_push_mem(&buf->b, mem, len);
2388}
2389
2398static inline void net_buf_push_u8(struct net_buf *buf, uint8_t val)
2399{
2400 net_buf_simple_push_u8(&buf->b, val);
2401}
2402
2412static inline void net_buf_push_le16(struct net_buf *buf, uint16_t val)
2413{
2414 net_buf_simple_push_le16(&buf->b, val);
2415}
2416
2426static inline void net_buf_push_be16(struct net_buf *buf, uint16_t val)
2427{
2428 net_buf_simple_push_be16(&buf->b, val);
2429}
2430
2440static inline void net_buf_push_le24(struct net_buf *buf, uint32_t val)
2441{
2442 net_buf_simple_push_le24(&buf->b, val);
2443}
2444
2454static inline void net_buf_push_be24(struct net_buf *buf, uint32_t val)
2455{
2456 net_buf_simple_push_be24(&buf->b, val);
2457}
2458
2468static inline void net_buf_push_le32(struct net_buf *buf, uint32_t val)
2469{
2470 net_buf_simple_push_le32(&buf->b, val);
2471}
2472
2482static inline void net_buf_push_be32(struct net_buf *buf, uint32_t val)
2483{
2484 net_buf_simple_push_be32(&buf->b, val);
2485}
2486
2496static inline void net_buf_push_le40(struct net_buf *buf, uint64_t val)
2497{
2498 net_buf_simple_push_le40(&buf->b, val);
2499}
2500
2510static inline void net_buf_push_be40(struct net_buf *buf, uint64_t val)
2511{
2512 net_buf_simple_push_be40(&buf->b, val);
2513}
2514
2524static inline void net_buf_push_le48(struct net_buf *buf, uint64_t val)
2525{
2526 net_buf_simple_push_le48(&buf->b, val);
2527}
2528
2538static inline void net_buf_push_be48(struct net_buf *buf, uint64_t val)
2539{
2540 net_buf_simple_push_be48(&buf->b, val);
2541}
2542
2552static inline void net_buf_push_le64(struct net_buf *buf, uint64_t val)
2553{
2554 net_buf_simple_push_le64(&buf->b, val);
2555}
2556
2566static inline void net_buf_push_be64(struct net_buf *buf, uint64_t val)
2567{
2568 net_buf_simple_push_be64(&buf->b, val);
2569}
2570
2582static inline void *net_buf_pull(struct net_buf *buf, size_t len)
2583{
2584 return net_buf_simple_pull(&buf->b, len);
2585}
2586
2598static inline void *net_buf_pull_mem(struct net_buf *buf, size_t len)
2599{
2600 return net_buf_simple_pull_mem(&buf->b, len);
2601}
2602
2613static inline uint8_t net_buf_pull_u8(struct net_buf *buf)
2614{
2615 return net_buf_simple_pull_u8(&buf->b);
2616}
2617
2628static inline uint16_t net_buf_pull_le16(struct net_buf *buf)
2629{
2630 return net_buf_simple_pull_le16(&buf->b);
2631}
2632
2643static inline uint16_t net_buf_pull_be16(struct net_buf *buf)
2644{
2645 return net_buf_simple_pull_be16(&buf->b);
2646}
2647
2658static inline uint32_t net_buf_pull_le24(struct net_buf *buf)
2659{
2660 return net_buf_simple_pull_le24(&buf->b);
2661}
2662
2673static inline uint32_t net_buf_pull_be24(struct net_buf *buf)
2674{
2675 return net_buf_simple_pull_be24(&buf->b);
2676}
2677
2688static inline uint32_t net_buf_pull_le32(struct net_buf *buf)
2689{
2690 return net_buf_simple_pull_le32(&buf->b);
2691}
2692
2703static inline uint32_t net_buf_pull_be32(struct net_buf *buf)
2704{
2705 return net_buf_simple_pull_be32(&buf->b);
2706}
2707
2718static inline uint64_t net_buf_pull_le40(struct net_buf *buf)
2719{
2720 return net_buf_simple_pull_le40(&buf->b);
2721}
2722
2733static inline uint64_t net_buf_pull_be40(struct net_buf *buf)
2734{
2735 return net_buf_simple_pull_be40(&buf->b);
2736}
2737
2748static inline uint64_t net_buf_pull_le48(struct net_buf *buf)
2749{
2750 return net_buf_simple_pull_le48(&buf->b);
2751}
2752
2763static inline uint64_t net_buf_pull_be48(struct net_buf *buf)
2764{
2765 return net_buf_simple_pull_be48(&buf->b);
2766}
2767
2778static inline uint64_t net_buf_pull_le64(struct net_buf *buf)
2779{
2780 return net_buf_simple_pull_le64(&buf->b);
2781}
2782
2793static inline uint64_t net_buf_pull_be64(struct net_buf *buf)
2794{
2795 return net_buf_simple_pull_be64(&buf->b);
2796}
2797
2807static inline size_t net_buf_tailroom(const struct net_buf *buf)
2808{
2809 return net_buf_simple_tailroom(&buf->b);
2810}
2811
2821static inline size_t net_buf_headroom(const struct net_buf *buf)
2822{
2823 return net_buf_simple_headroom(&buf->b);
2824}
2825
2840__deprecated static inline uint16_t net_buf_max_len(const struct net_buf *buf)
2841{
2842 return buf->size - net_buf_headroom(buf);
2843}
2844
2860static inline bool net_buf_is_valid(const struct net_buf *buf)
2861{
2862 return buf != NULL && buf->ref > 0 && net_buf_simple_is_valid(&buf->b);
2863}
2864
2874static inline uint8_t *net_buf_tail(const struct net_buf *buf)
2875{
2876 return net_buf_simple_tail(&buf->b);
2877}
2878
2885
2897void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag);
2898
2915struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag);
2916
2926#if defined(CONFIG_NET_BUF_LOG)
2927struct net_buf *net_buf_frag_del_debug(struct net_buf *parent,
2928 struct net_buf *frag,
2929 const char *func, int line);
2930#define net_buf_frag_del(_parent, _frag) \
2931 net_buf_frag_del_debug(_parent, _frag, __func__, __LINE__)
2932#else
2933struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag);
2934#endif
2935
2951size_t net_buf_linearize(void *dst, size_t dst_len,
2952 const struct net_buf *src, size_t offset, size_t len);
2953
2968typedef struct net_buf * __must_check (*net_buf_allocator_cb)(k_timeout_t timeout,
2969 void *user_data);
2970
2994size_t net_buf_append_bytes(struct net_buf *buf, size_t len,
2995 const void *value, k_timeout_t timeout,
2996 net_buf_allocator_cb allocate_cb, void *user_data);
2997
3012size_t net_buf_data_match(const struct net_buf *buf, size_t offset, const void *data, size_t len);
3013
3027static inline struct net_buf *net_buf_skip(struct net_buf *buf, size_t len)
3028{
3029 while (buf != NULL && len > 0U) {
3030 size_t to_skip = MIN(len, buf->len);
3031
3032 /* A zero-capacity fragment has no data buffer to pull from */
3033 if (to_skip > 0U) {
3034 net_buf_pull(buf, to_skip);
3035 len -= to_skip;
3036 }
3037
3038 if (buf->len == 0U) {
3039 buf = net_buf_frag_del(NULL, buf);
3040 }
3041 }
3042
3043 return buf;
3044}
3045
3056static inline size_t net_buf_frags_len(const struct net_buf *buf)
3057{
3058 size_t bytes = 0;
3059
3060 while (buf) {
3061 bytes += buf->len;
3062 buf = buf->frags;
3063 }
3064
3065 return bytes;
3066}
3067
3071
3072#ifdef __cplusplus
3073}
3074#endif
3075
3076#endif /* ZEPHYR_INCLUDE_NET_BUF_H_ */
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
atomic_val_t atomic_get(const atomic_t *target)
Atomic get.
atomic_ptr_val_t atomic_ptr_clear(atomic_ptr_t *target)
Atomic clear of a pointer value.
void * atomic_ptr_t
Atomic pointer variable.
Definition atomic_types.h:49
#define k_lifo_put(lifo, data)
Add an element to a LIFO queue.
Definition kernel.h:3507
void net_buf_simple_clone(const struct net_buf_simple *original, struct net_buf_simple *clone)
Clone buffer state, using the same data buffer.
static void net_buf_simple_init(struct net_buf_simple *buf, size_t reserve_head)
Initialize a net_buf_simple object.
Definition net_buf.h:151
struct net_buf * net_buf_frag_last(struct net_buf *frags)
Find the last fragment in the fragment list.
static uint64_t net_buf_pull_be40(struct net_buf *buf)
Remove and convert 40 bits from the beginning of the buffer.
Definition net_buf.h:2733
static void net_buf_add_be64(struct net_buf *buf, uint64_t val)
Add 64-bit value at the end of the buffer.
Definition net_buf.h:2141
uint8_t net_buf_simple_pull_u8(struct net_buf_simple *buf)
Remove a 8-bit value from the beginning of the buffer.
uint16_t net_buf_simple_remove_le16(struct net_buf_simple *buf)
Remove and convert 16 bits from the end of the buffer.
static uint64_t net_buf_remove_le48(struct net_buf *buf)
Remove and convert 48 bits from the end of the buffer.
Definition net_buf.h:2306
struct net_buf * net_buf_frag_add(struct net_buf *head, struct net_buf *frag)
Add a new fragment to the end of a chain of bufs.
void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve)
Initialize buffer with the given headroom.
void net_buf_simple_push_u8(struct net_buf_simple *buf, uint8_t val)
Push 8-bit value to the beginning of the buffer.
static void net_buf_add_be24(struct net_buf *buf, uint32_t val)
Add 24-bit value at the end of the buffer.
Definition net_buf.h:2021
struct net_buf * net_buf_alloc_len(struct net_buf_pool *pool, size_t size, k_timeout_t timeout)
Allocate a new variable length buffer from a pool.
void net_buf_reset(struct net_buf *buf)
Reset buffer.
struct net_buf_pool * net_buf_pool_get(int id)
Looks up a pool based on its ID.
void * net_buf_simple_add(struct net_buf_simple *buf, size_t len)
Prepare data to be added at the end of the buffer.
uint64_t net_buf_simple_pull_be48(struct net_buf_simple *buf)
Remove and convert 48 bits from the beginning of the buffer.
uint32_t net_buf_simple_pull_be32(struct net_buf_simple *buf)
Remove and convert 32 bits from the beginning of the buffer.
void net_buf_simple_push_be48(struct net_buf_simple *buf, uint64_t val)
Push 48-bit value to the beginning of the buffer.
struct net_buf * net_buf_slist_get(sys_slist_t *list)
Get a buffer from a list.
struct net_buf * net_buf_ref(struct net_buf *buf)
Increment the reference count of a buffer.
uint64_t net_buf_simple_remove_le40(struct net_buf_simple *buf)
Remove and convert 40 bits from the end of the buffer.
static struct net_buf * net_buf_skip(struct net_buf *buf, size_t len)
Skip N number of bytes in a net_buf.
Definition net_buf.h:3027
static void * net_buf_add(struct net_buf *buf, size_t len)
Prepare data to be added at the end of the buffer.
Definition net_buf.h:1927
static void net_buf_add_le24(struct net_buf *buf, uint32_t val)
Add 24-bit value at the end of the buffer.
Definition net_buf.h:2006
static uint64_t net_buf_pull_le40(struct net_buf *buf)
Remove and convert 40 bits from the beginning of the buffer.
Definition net_buf.h:2718
uint32_t net_buf_simple_pull_le32(struct net_buf_simple *buf)
Remove and convert 32 bits from the beginning of the buffer.
void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val)
Add 32-bit value at the end of the buffer.
static uint64_t net_buf_pull_be64(struct net_buf *buf)
Remove and convert 64 bits from the beginning of the buffer.
Definition net_buf.h:2793
static void net_buf_push_be64(struct net_buf *buf, uint64_t val)
Push 64-bit value to the beginning of the buffer.
Definition net_buf.h:2566
static uint64_t net_buf_remove_le64(struct net_buf *buf)
Remove and convert 64 bits from the end of the buffer.
Definition net_buf.h:2336
static void net_buf_simple_reset(struct net_buf_simple *buf)
Reset buffer.
Definition net_buf.h:181
uint32_t net_buf_simple_pull_be24(struct net_buf_simple *buf)
Remove and convert 24 bits from the beginning of the buffer.
uint32_t net_buf_simple_pull_le24(struct net_buf_simple *buf)
Remove and convert 24 bits from the beginning of the buffer.
int net_buf_user_data_copy(struct net_buf *dst, const struct net_buf *src)
Copy user data from one to another buffer.
uint32_t net_buf_simple_remove_le24(struct net_buf_simple *buf)
Remove and convert 24 bits from the end of the buffer.
static struct net_buf * net_buf_take(struct net_buf **orig)
Move a buffer pointer, setting the orig to NULL.
Definition net_buf.h:1812
void net_buf_simple_push_le16(struct net_buf_simple *buf, uint16_t val)
Push 16-bit value to the beginning of the buffer.
static void net_buf_push_be40(struct net_buf *buf, uint64_t val)
Push 40-bit value to the beginning of the buffer.
Definition net_buf.h:2510
static struct net_buf * net_buf_alloc(struct net_buf_pool *pool, k_timeout_t timeout)
Definition net_buf.h:1558
static void net_buf_add_be32(struct net_buf *buf, uint32_t val)
Add 32-bit value at the end of the buffer.
Definition net_buf.h:2051
uint64_t net_buf_simple_remove_le64(struct net_buf_simple *buf)
Remove and convert 64 bits from the end of the buffer.
static uint64_t net_buf_remove_le40(struct net_buf *buf)
Remove and convert 40 bits from the end of the buffer.
Definition net_buf.h:2276
void net_buf_simple_add_le48(struct net_buf_simple *buf, uint64_t val)
Add 48-bit value at the end of the buffer.
static bool net_buf_simple_is_valid(const struct net_buf_simple *buf)
Check that a buffer's length and pointers are self-consistent.
Definition net_buf.h:983
static uint16_t net_buf_remove_be16(struct net_buf *buf)
Remove and convert 16 bits from the end of the buffer.
Definition net_buf.h:2201
void net_buf_simple_add_be24(struct net_buf_simple *buf, uint32_t val)
Add 24-bit value at the end of the buffer.
static uint32_t net_buf_pull_le32(struct net_buf *buf)
Remove and convert 32 bits from the beginning of the buffer.
Definition net_buf.h:2688
static uint32_t net_buf_pull_be32(struct net_buf *buf)
Remove and convert 32 bits from the beginning of the buffer.
Definition net_buf.h:2703
struct net_buf * net_buf_frag_del(struct net_buf *parent, struct net_buf *frag)
Delete existing fragment from a chain of bufs.
uint64_t net_buf_simple_remove_be64(struct net_buf_simple *buf)
Remove and convert 64 bits from the end of the buffer.
static void net_buf_add_be16(struct net_buf *buf, uint16_t val)
Add 16-bit value at the end of the buffer.
Definition net_buf.h:1991
static void net_buf_add_le40(struct net_buf *buf, uint64_t val)
Add 40-bit value at the end of the buffer.
Definition net_buf.h:2066
struct net_buf * net_buf_reuse(struct net_buf **orig)
Take a buffer back into use instead of destroying it.
size_t net_buf_append_bytes(struct net_buf *buf, size_t len, const void *value, k_timeout_t timeout, net_buf_allocator_cb allocate_cb, void *user_data)
Append data to a list of net_buf.
void * net_buf_simple_push(struct net_buf_simple *buf, size_t len)
Prepare data to be added to the start of the buffer.
static uint16_t net_buf_max_len(const struct net_buf *buf)
Check maximum net_buf::len value.
Definition net_buf.h:2840
void net_buf_simple_push_le48(struct net_buf_simple *buf, uint64_t val)
Push 48-bit value to the beginning of the buffer.
void net_buf_simple_add_le40(struct net_buf_simple *buf, uint64_t val)
Add 40-bit value at the end of the buffer.
struct net_buf * net_buf_alloc_fixed(struct net_buf_pool *pool, k_timeout_t timeout)
Allocate a new fixed buffer from a pool.
static uint64_t net_buf_pull_be48(struct net_buf *buf)
Remove and convert 48 bits from the beginning of the buffer.
Definition net_buf.h:2763
void net_buf_simple_add_be40(struct net_buf_simple *buf, uint64_t val)
Add 40-bit value at the end of the buffer.
uint64_t net_buf_simple_pull_le48(struct net_buf_simple *buf)
Remove and convert 48 bits from the beginning of the buffer.
static void net_buf_drop(struct net_buf **orig)
Drop a buffer reference and clear the pointer.
Definition net_buf.h:1855
void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf)
Put a buffer into a list.
static void net_buf_push_be16(struct net_buf *buf, uint16_t val)
Push 16-bit value to the beginning of the buffer.
Definition net_buf.h:2426
static uint32_t net_buf_remove_be24(struct net_buf *buf)
Remove and convert 24 bits from the end of the buffer.
Definition net_buf.h:2216
static void net_buf_add_be40(struct net_buf *buf, uint64_t val)
Add 40-bit value at the end of the buffer.
Definition net_buf.h:2081
static uint8_t net_buf_pull_u8(struct net_buf *buf)
Remove a 8-bit value from the beginning of the buffer.
Definition net_buf.h:2613
static void net_buf_destroy(struct net_buf *buf)
Destroy buffer from custom destroy callback.
Definition net_buf.h:1637
static size_t net_buf_simple_tailroom(const struct net_buf_simple *buf)
Check buffer tailroom.
Definition net_buf.h:942
void net_buf_simple_push_le40(struct net_buf_simple *buf, uint64_t val)
Push 40-bit value to the beginning of the buffer.
static uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf)
Check maximum net_buf_simple::len value.
Definition net_buf.h:961
void net_buf_simple_push_le64(struct net_buf_simple *buf, uint64_t val)
Push 64-bit value to the beginning of the buffer.
void net_buf_simple_add_le64(struct net_buf_simple *buf, uint64_t val)
Add 64-bit value at the end of the buffer.
uint64_t net_buf_simple_pull_le64(struct net_buf_simple *buf)
Remove and convert 64 bits from the beginning of the buffer.
static void * net_buf_push_mem(struct net_buf *buf, const void *mem, size_t len)
Copies the given number of bytes to the start of the buffer.
Definition net_buf.h:2384
static uint64_t net_buf_pull_le48(struct net_buf *buf)
Remove and convert 48 bits from the beginning of the buffer.
Definition net_buf.h:2748
void net_buf_simple_init_with_data(struct net_buf_simple *buf, void *data, size_t size)
Initialize a net_buf_simple object with data.
void net_buf_simple_push_be16(struct net_buf_simple *buf, uint16_t val)
Push 16-bit value to the beginning of the buffer.
void * net_buf_simple_remove_mem(struct net_buf_simple *buf, size_t len)
Remove data from the end of the buffer.
static void net_buf_push_le48(struct net_buf *buf, uint64_t val)
Push 48-bit value to the beginning of the buffer.
Definition net_buf.h:2524
static uint32_t net_buf_pull_le24(struct net_buf *buf)
Remove and convert 24 bits from the beginning of the buffer.
Definition net_buf.h:2658
void net_buf_simple_push_le32(struct net_buf_simple *buf, uint32_t val)
Push 32-bit value to the beginning of the buffer.
static uint8_t * net_buf_add_u8(struct net_buf *buf, uint8_t val)
Add (8-bit) byte at the end of the buffer.
Definition net_buf.h:1961
static void net_buf_push_be24(struct net_buf *buf, uint32_t val)
Push 24-bit value to the beginning of the buffer.
Definition net_buf.h:2454
static void net_buf_push_le24(struct net_buf *buf, uint32_t val)
Push 24-bit value to the beginning of the buffer.
Definition net_buf.h:2440
static void net_buf_reserve(struct net_buf *buf, size_t reserve)
Initialize buffer with the given headroom.
Definition net_buf.h:1911
static uint64_t net_buf_remove_be64(struct net_buf *buf)
Remove and convert 64 bits from the end of the buffer.
Definition net_buf.h:2351
struct net_buf * net_buf_alloc_with_data(struct net_buf_pool *pool, void *data, size_t size, k_timeout_t timeout)
Allocate a new buffer from a pool but with external data pointer.
static bool net_buf_is_valid(const struct net_buf *buf)
Check that a buffer's length and pointers are self-consistent.
Definition net_buf.h:2860
static uint32_t net_buf_pull_be24(struct net_buf *buf)
Remove and convert 24 bits from the beginning of the buffer.
Definition net_buf.h:2673
void net_buf_simple_add_be64(struct net_buf_simple *buf, uint64_t val)
Add 64-bit value at the end of the buffer.
static void net_buf_add_be48(struct net_buf *buf, uint64_t val)
Add 48-bit value at the end of the buffer.
Definition net_buf.h:2111
uint8_t * net_buf_simple_add_u8(struct net_buf_simple *buf, uint8_t val)
Add (8-bit) byte at the end of the buffer.
static uint32_t net_buf_remove_le24(struct net_buf *buf)
Remove and convert 24 bits from the end of the buffer.
Definition net_buf.h:2231
static void net_buf_push_u8(struct net_buf *buf, uint8_t val)
Push 8-bit value to the beginning of the buffer.
Definition net_buf.h:2398
void net_buf_simple_add_be16(struct net_buf_simple *buf, uint16_t val)
Add 16-bit value at the end of the buffer.
uint16_t net_buf_simple_remove_be16(struct net_buf_simple *buf)
Remove and convert 16 bits from the end of the buffer.
static void * net_buf_push(struct net_buf *buf, size_t len)
Prepare data to be added at the start of the buffer.
Definition net_buf.h:2367
static uint16_t net_buf_pull_be16(struct net_buf *buf)
Remove and convert 16 bits from the beginning of the buffer.
Definition net_buf.h:2643
static void net_buf_push_le32(struct net_buf *buf, uint32_t val)
Push 32-bit value to the beginning of the buffer.
Definition net_buf.h:2468
static uint64_t net_buf_pull_le64(struct net_buf *buf)
Remove and convert 64 bits from the beginning of the buffer.
Definition net_buf.h:2778
uint64_t net_buf_simple_remove_be40(struct net_buf_simple *buf)
Remove and convert 40 bits from the end of the buffer.
uint32_t net_buf_simple_remove_be24(struct net_buf_simple *buf)
Remove and convert 24 bits from the end of the buffer.
struct net_buf *(* net_buf_allocator_cb)(k_timeout_t timeout, void *user_data)
Network buffer allocator callback.
Definition net_buf.h:2968
void * net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len)
Remove data from the beginning of the buffer.
static size_t net_buf_get_available(struct net_buf_pool *pool)
Get the number of buffers currently available to claim from a pool.
Definition net_buf.h:1509
uint32_t net_buf_simple_remove_le32(struct net_buf_simple *buf)
Remove and convert 32 bits from the end of the buffer.
void net_buf_simple_add_le16(struct net_buf_simple *buf, uint16_t val)
Add 16-bit value at the end of the buffer.
uint64_t net_buf_simple_pull_be40(struct net_buf_simple *buf)
Remove and convert 40 bits from the beginning of the buffer.
static uint8_t * net_buf_simple_tail(const struct net_buf_simple *buf)
Get the tail pointer for a buffer.
Definition net_buf.h:914
void * net_buf_simple_push_mem(struct net_buf_simple *buf, const void *mem, size_t len)
Copy given number of bytes from memory to the start of the buffer.
static struct net_buf * net_buf_take_plain(struct net_buf **orig)
Move a buffer pointer without an atomic exchange.
Definition net_buf.h:1838
static uint64_t net_buf_remove_be48(struct net_buf *buf)
Remove and convert 48 bits from the end of the buffer.
Definition net_buf.h:2321
void net_buf_simple_add_be32(struct net_buf_simple *buf, uint32_t val)
Add 32-bit value at the end of the buffer.
#define NET_BUF_EXTERNAL_DATA
Flag indicating that the buffer's associated data pointer, points to externally allocated memory.
Definition net_buf.h:1053
static uint16_t net_buf_remove_le16(struct net_buf *buf)
Remove and convert 16 bits from the end of the buffer.
Definition net_buf.h:2186
static void net_buf_push_le16(struct net_buf *buf, uint16_t val)
Push 16-bit value to the beginning of the buffer.
Definition net_buf.h:2412
uint64_t net_buf_simple_remove_be48(struct net_buf_simple *buf)
Remove and convert 48 bits from the end of the buffer.
void net_buf_simple_push_le24(struct net_buf_simple *buf, uint32_t val)
Push 24-bit value to the beginning of the buffer.
void net_buf_unref(struct net_buf *buf)
Decrements the reference count of a buffer.
static void net_buf_simple_save(const struct net_buf_simple *buf, struct net_buf_simple_state *state)
Save the parsing state of a buffer.
Definition net_buf.h:1021
static void net_buf_push_be48(struct net_buf *buf, uint64_t val)
Push 48-bit value to the beginning of the buffer.
Definition net_buf.h:2538
void net_buf_simple_push_be24(struct net_buf_simple *buf, uint32_t val)
Push 24-bit value to the beginning of the buffer.
void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag)
Insert a new fragment to a chain of bufs.
uint64_t net_buf_simple_remove_le48(struct net_buf_simple *buf)
Remove and convert 48 bits from the end of the buffer.
void * net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem, size_t len)
Copy given number of bytes from memory to the end of the buffer.
static void net_buf_add_le64(struct net_buf *buf, uint64_t val)
Add 64-bit value at the end of the buffer.
Definition net_buf.h:2126
static size_t net_buf_headroom(const struct net_buf *buf)
Check buffer headroom.
Definition net_buf.h:2821
static uint32_t net_buf_remove_be32(struct net_buf *buf)
Remove and convert 32 bits from the end of the buffer.
Definition net_buf.h:2261
int net_buf_id(const struct net_buf *buf)
Get a zero-based index for a buffer.
static void * net_buf_remove_mem(struct net_buf *buf, size_t len)
Remove data from the end of the buffer.
Definition net_buf.h:2156
static void * net_buf_add_mem(struct net_buf *buf, const void *mem, size_t len)
Copies the given number of bytes to the end of the buffer.
Definition net_buf.h:1944
uint64_t net_buf_simple_pull_be64(struct net_buf_simple *buf)
Remove and convert 64 bits from the beginning of the buffer.
void net_buf_fifo_purge(struct k_fifo *fifo)
Unreference all buffers in a FIFO.
void net_buf_simple_push_be32(struct net_buf_simple *buf, uint32_t val)
Push 32-bit value to the beginning of the buffer.
static void net_buf_push_le64(struct net_buf *buf, uint64_t val)
Push 64-bit value to the beginning of the buffer.
Definition net_buf.h:2552
uint16_t net_buf_simple_pull_le16(struct net_buf_simple *buf)
Remove and convert 16 bits from the beginning of the buffer.
static size_t net_buf_get_max_used(struct net_buf_pool *pool)
Get the maximum number of buffers simultaneously claimed from a pool.
Definition net_buf.h:1523
void net_buf_simple_push_be40(struct net_buf_simple *buf, uint64_t val)
Push 40-bit value to the beginning of the buffer.
uint64_t net_buf_simple_pull_le40(struct net_buf_simple *buf)
Remove and convert 40 bits from the beginning of the buffer.
static uint8_t net_buf_remove_u8(struct net_buf *buf)
Remove a 8-bit value from the end of the buffer.
Definition net_buf.h:2171
void net_buf_simple_add_be48(struct net_buf_simple *buf, uint64_t val)
Add 48-bit value at the end of the buffer.
static size_t net_buf_simple_headroom(const struct net_buf_simple *buf)
Check buffer headroom.
Definition net_buf.h:928
static void net_buf_add_le16(struct net_buf *buf, uint16_t val)
Add 16-bit value at the end of the buffer.
Definition net_buf.h:1976
static uint64_t net_buf_remove_be40(struct net_buf *buf)
Remove and convert 40 bits from the end of the buffer.
Definition net_buf.h:2291
uint16_t net_buf_simple_pull_be16(struct net_buf_simple *buf)
Remove and convert 16 bits from the beginning of the buffer.
static void net_buf_push_be32(struct net_buf *buf, uint32_t val)
Push 32-bit value to the beginning of the buffer.
Definition net_buf.h:2482
void net_buf_slist_purge(sys_slist_t *list)
Unreference all buffers in a list.
static void net_buf_add_le32(struct net_buf *buf, uint32_t val)
Add 32-bit value at the end of the buffer.
Definition net_buf.h:2036
uint32_t net_buf_simple_remove_be32(struct net_buf_simple *buf)
Remove and convert 32 bits from the end of the buffer.
static uint32_t net_buf_remove_le32(struct net_buf *buf)
Remove and convert 32 bits from the end of the buffer.
Definition net_buf.h:2246
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition net_buf.h:3056
static size_t net_buf_tailroom(const struct net_buf *buf)
Check buffer tailroom.
Definition net_buf.h:2807
static uint16_t net_buf_pull_le16(struct net_buf *buf)
Remove and convert 16 bits from the beginning of the buffer.
Definition net_buf.h:2628
static uint8_t * net_buf_tail(const struct net_buf *buf)
Get the tail pointer for a buffer.
Definition net_buf.h:2874
static void * net_buf_pull_mem(struct net_buf *buf, size_t len)
Remove data from the beginning of the buffer.
Definition net_buf.h:2598
static void net_buf_simple_restore(struct net_buf_simple *buf, struct net_buf_simple_state *state)
Restore the parsing state of a buffer.
Definition net_buf.h:1037
static void * net_buf_pull(struct net_buf *buf, size_t len)
Remove data from the beginning of the buffer.
Definition net_buf.h:2582
size_t net_buf_data_match(const struct net_buf *buf, size_t offset, const void *data, size_t len)
Match data with a net_buf's content.
static void net_buf_push_le40(struct net_buf *buf, uint64_t val)
Push 40-bit value to the beginning of the buffer.
Definition net_buf.h:2496
static void net_buf_add_le48(struct net_buf *buf, uint64_t val)
Add 48-bit value at the end of the buffer.
Definition net_buf.h:2096
void net_buf_simple_add_le24(struct net_buf_simple *buf, uint32_t val)
Add 24-bit value at the end of the buffer.
static void * net_buf_user_data(const struct net_buf *buf)
Get a pointer to the user data of a buffer.
Definition net_buf.h:1887
struct net_buf * net_buf_clone(struct net_buf *buf, k_timeout_t timeout)
Clone buffer.
uint8_t net_buf_simple_remove_u8(struct net_buf_simple *buf)
Remove a 8-bit value from the end of the buffer.
void * net_buf_simple_pull(struct net_buf_simple *buf, size_t len)
Remove data from the beginning of the buffer.
void net_buf_simple_push_be64(struct net_buf_simple *buf, uint64_t val)
Push 64-bit value to the beginning of the buffer.
size_t net_buf_linearize(void *dst, size_t dst_len, const struct net_buf *src, size_t offset, size_t len)
Copy bytes from net_buf chain starting at offset to linear buffer.
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:54
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:44
#define MIN(a, b)
Obtain the minimum of two values.
Definition util.h:394
Public kernel APIs.
state
Definition parser_state.h:29
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Kernel FIFO structure.
Definition kernel.h:3107
Kernel LIFO structure.
Definition kernel.h:3430
Kernel Spin Lock.
Definition spinlock.h:45
Kernel timeout type.
Definition clock.h:65
Network buffer pool representation.
Definition net_buf.h:1199
void(*const destroy)(struct net_buf *buf)
Optional destroy callback when buffer is freed.
Definition net_buf.h:1230
uint16_t uninit_count
Number of uninitialized buffers.
Definition net_buf.h:1210
uint8_t user_data_size
Size of user data allocated to this pool.
Definition net_buf.h:1213
const uint16_t buf_count
Number of buffers in pool.
Definition net_buf.h:1207
const struct net_buf_data_alloc * alloc
Data allocation handlers.
Definition net_buf.h:1233
struct k_lifo free
LIFO to place the buffer into when free.
Definition net_buf.h:1201
struct k_spinlock lock
To prevent concurrent access/modifications.
Definition net_buf.h:1204
Parsing state of a buffer.
Definition net_buf.h:1006
uint16_t offset
Offset of the data pointer from the beginning of the storage.
Definition net_buf.h:1008
uint16_t len
Length of data.
Definition net_buf.h:1010
Simple network buffer representation.
Definition net_buf.h:97
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:99
uint16_t size
Amount of data that net_buf_simple::__buf can store.
Definition net_buf.h:110
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:107
Network buffer representation.
Definition net_buf.h:1062
uint16_t size
Amount of data that this buffer can store.
Definition net_buf.h:1158
struct net_buf * frags
Fragments associated with this buffer.
Definition net_buf.h:1067
uint8_t ref
Reference count.
Definition net_buf.h:1131
uint8_t pool_id
Where the buffer should go when freed up.
Definition net_buf.h:1137
sys_snode_t node
Allow placing the buffer into sys_slist_t.
Definition net_buf.h:1064
uint8_t user_data_size
Size of user data on this buffer.
Definition net_buf.h:1140
uint8_t flags
Bit-field of buffer flags.
Definition net_buf.h:1134
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1152
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1173
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1155
Iterable sections helpers.
Misc utilities.