Zephyr API Documentation 4.5.0-rc1
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
31
32/* Alignment needed for various parts of the buffer definition */
33#if CONFIG_NET_BUF_ALIGNMENT == 0
34#define __net_buf_align __aligned(sizeof(void *))
35#else
36#define __net_buf_align __aligned(CONFIG_NET_BUF_ALIGNMENT)
37#endif
38
48#define NET_BUF_SIMPLE_DEFINE(_name, _size) \
49 uint8_t net_buf_data_##_name[_size]; \
50 struct net_buf_simple _name = { \
51 .data = net_buf_data_##_name, \
52 .len = 0, \
53 .size = _size, \
54 .__buf = net_buf_data_##_name, \
55 }
56
67#define NET_BUF_SIMPLE_DEFINE_STATIC(_name, _size) \
68 static __noinit uint8_t net_buf_data_##_name[_size]; \
69 static struct net_buf_simple _name = { \
70 .data = net_buf_data_##_name, \
71 .len = 0, \
72 .size = _size, \
73 .__buf = net_buf_data_##_name, \
74 }
75
92
100
103
107 uint8_t *__buf;
108};
109
126#define NET_BUF_SIMPLE(_size) \
127 ((struct net_buf_simple *)(&(struct { \
128 struct net_buf_simple buf; \
129 uint8_t data[_size]; \
130 }) { \
131 .buf.size = _size, \
132 }))
133
143static inline void net_buf_simple_init(struct net_buf_simple *buf,
144 size_t reserve_head)
145{
146 if (!buf->__buf) {
147 buf->__buf = (uint8_t *)buf + sizeof(*buf);
148 }
149
150 buf->data = buf->__buf + reserve_head;
151 buf->len = 0U;
152}
153
164 void *data, size_t size);
165
173static inline void net_buf_simple_reset(struct net_buf_simple *buf)
174{
175 buf->len = 0U;
176 buf->data = buf->__buf;
177}
178
189void net_buf_simple_clone(const struct net_buf_simple *original,
190 struct net_buf_simple *clone);
191
203void *net_buf_simple_add(struct net_buf_simple *buf, size_t len);
204
217void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem,
218 size_t len);
219
232
244
256
268
280
292
304
316
328
340
352
364
376
387void *net_buf_simple_remove_mem(struct net_buf_simple *buf, size_t len);
388
400
412
424
436
448
460
472
484
496
508
520
532
544
556void *net_buf_simple_push(struct net_buf_simple *buf, size_t len);
557
570void *net_buf_simple_push_mem(struct net_buf_simple *buf, const void *mem,
571 size_t len);
572
583
594
604
615
626
637
648
659
670
681
692
703
714
726void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len);
727
739void *net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len);
740
752
764
776
788
800
812
824
836
848
860
872
884
896
906static inline uint8_t *net_buf_simple_tail(const struct net_buf_simple *buf)
907{
908 return buf->data + buf->len;
909}
910
920static inline size_t net_buf_simple_headroom(const struct net_buf_simple *buf)
921{
922 return buf->data - buf->__buf;
923}
924
934static inline size_t net_buf_simple_tailroom(const struct net_buf_simple *buf)
935{
936 return buf->size - net_buf_simple_headroom(buf) - buf->len;
937}
938
953__deprecated static inline uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf)
954{
955 return buf->size - net_buf_simple_headroom(buf);
956}
957
975static inline bool net_buf_simple_is_valid(const struct net_buf_simple *buf)
976{
977 size_t headroom;
978
979 if (buf == NULL || buf->__buf == NULL || buf->data < buf->__buf) {
980 return false;
981 }
982
983 headroom = net_buf_simple_headroom(buf);
984 if (headroom > buf->size) {
985 return false;
986 }
987
988 return (size_t)buf->len <= (size_t)(buf->size - headroom);
989}
990
1004
1013static inline void net_buf_simple_save(const struct net_buf_simple *buf,
1015{
1016 state->offset = (uint16_t)net_buf_simple_headroom(buf);
1017 state->len = buf->len;
1018}
1019
1029static inline void net_buf_simple_restore(struct net_buf_simple *buf,
1031{
1032 buf->data = buf->__buf + state->offset;
1033 buf->len = state->len;
1034}
1035
1045#define NET_BUF_EXTERNAL_DATA BIT(0)
1046
1054struct net_buf {
1057
1060
1092 union {
1094 atomic_t ref_word;
1096 struct {
1097#if defined(CONFIG_BIG_ENDIAN)
1098 /* atomic_t is typedef'd as long (BUILD_ASSERTed in
1099 * lib/net_buf/buf.c); on a 64-bit big-endian build
1100 * the byte struct needs 4 bytes of padding so that
1101 * `ref` lands on the least-significant byte of
1102 * ref_word.
1103 */
1104#if (__SIZEOF_LONG__ == 8)
1106 uint8_t _ref_word_pad[4];
1108#endif
1111
1114
1116 uint8_t flags;
1117
1119 uint8_t ref;
1120#else
1123
1126
1129
1132#endif
1133 };
1134 };
1135
1139 union {
1140 /* The ABI of this struct must match net_buf_simple */
1141 struct {
1144
1147
1150
1155 uint8_t *__buf;
1156 };
1157
1159 struct net_buf_simple b;
1161 };
1162
1164 uint8_t user_data[] __net_buf_align;
1165};
1166
1168
1169struct net_buf_data_cb {
1170 uint8_t * __must_check (*alloc)(struct net_buf *buf, size_t *size,
1171 k_timeout_t timeout);
1172 uint8_t * __must_check (*ref)(struct net_buf *buf, uint8_t *data);
1173 void (*unref)(struct net_buf *buf, uint8_t *data);
1174};
1175
1176struct net_buf_data_alloc {
1177 const struct net_buf_data_cb *cb;
1178 void *alloc_data;
1179 size_t max_alloc_size;
1180 size_t alignment;
1181};
1182
1184
1192 struct k_lifo free;
1193
1196
1199
1202
1205
1206#if defined(CONFIG_NET_BUF_POOL_USAGE)
1208 atomic_t avail_count;
1209
1211 const uint16_t pool_size;
1212
1214 uint16_t max_used;
1215
1217 const char *name;
1218#endif /* CONFIG_NET_BUF_POOL_USAGE */
1219
1221 void (*const destroy)(struct net_buf *buf);
1222
1224 const struct net_buf_data_alloc *alloc;
1225
1227 struct net_buf * const __bufs;
1228};
1229
1231#define NET_BUF_POOL_USAGE_INIT(_pool, _count) \
1232 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.avail_count = ATOMIC_INIT(_count),)) \
1233 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.max_used = 0,)) \
1234 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.name = STRINGIFY(_pool),))
1235
1236#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \
1237 { \
1238 .free = Z_LIFO_INITIALIZER(_pool.free), \
1239 .lock = { }, \
1240 .buf_count = _count, \
1241 .uninit_count = _count, \
1242 .user_data_size = _ud_size, \
1243 NET_BUF_POOL_USAGE_INIT(_pool, _count) \
1244 .destroy = _destroy, \
1245 .alloc = _alloc, \
1246 .__bufs = (struct net_buf *)_bufs, \
1247 }
1248
1249#define _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size) \
1250 struct _net_buf_##_name { uint8_t b[sizeof(struct net_buf)]; \
1251 uint8_t ud[_ud_size]; } __net_buf_align; \
1252 BUILD_ASSERT(_ud_size <= UINT8_MAX); \
1253 BUILD_ASSERT(offsetof(struct net_buf, user_data) == \
1254 offsetof(struct _net_buf_##_name, ud), "Invalid offset"); \
1255 BUILD_ASSERT(__alignof__(struct net_buf) == \
1256 __alignof__(struct _net_buf_##_name), "Invalid alignment"); \
1257 BUILD_ASSERT(sizeof(struct _net_buf_##_name) == \
1258 ROUND_UP(sizeof(struct net_buf) + _ud_size, __alignof__(struct net_buf)), \
1259 "Size cannot be determined"); \
1260 static struct _net_buf_##_name _net_buf_##_name[_count] __noinit
1261
1262extern const struct net_buf_data_alloc net_buf_heap_alloc;
1264
1292#define NET_BUF_POOL_HEAP_DEFINE(_name, _count, _ud_size, _destroy) \
1293 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1294 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1295 NET_BUF_POOL_INITIALIZER(_name, &net_buf_heap_alloc, \
1296 _net_buf_##_name, _count, _ud_size, \
1297 _destroy)
1298
1300
1301struct net_buf_pool_fixed {
1302 uint8_t *data_pool;
1303};
1304
1305extern const struct net_buf_data_cb net_buf_fixed_cb;
1306
1308
1337#define NET_BUF_POOL_FIXED_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1338 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1339 static uint8_t __noinit net_buf_data_##_name[_count][_data_size] __net_buf_align; \
1340 static const struct net_buf_pool_fixed net_buf_fixed_##_name = { \
1341 .data_pool = (uint8_t *)net_buf_data_##_name, \
1342 }; \
1343 static const struct net_buf_data_alloc net_buf_fixed_alloc_##_name = { \
1344 .cb = &net_buf_fixed_cb, \
1345 .alloc_data = (void *)&net_buf_fixed_##_name, \
1346 .max_alloc_size = _data_size, \
1347 }; \
1348 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1349 NET_BUF_POOL_INITIALIZER(_name, &net_buf_fixed_alloc_##_name, \
1350 _net_buf_##_name, _count, _ud_size, \
1351 _destroy)
1352
1354extern const struct net_buf_data_cb net_buf_var_cb;
1356
1381#define NET_BUF_POOL_VAR_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1382 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1383 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1384 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1385 .cb = &net_buf_var_cb, \
1386 .alloc_data = &net_buf_mem_pool_##_name, \
1387 .max_alloc_size = 0, \
1388 }; \
1389 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1390 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1391 _net_buf_##_name, _count, _ud_size, \
1392 _destroy)
1393
1424#define NET_BUF_POOL_VAR_ALIGN_DEFINE(_name, _count, _data_size, _ud_size, \
1425 _destroy, _align) \
1426 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1427 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1428 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1429 .cb = &net_buf_var_cb, \
1430 .alloc_data = &net_buf_mem_pool_##_name, \
1431 .max_alloc_size = 0, \
1432 .alignment = _align, \
1433 }; \
1434 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1435 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1436 _net_buf_##_name, _count, _ud_size, \
1437 _destroy)
1438
1460#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy) \
1461 NET_BUF_POOL_FIXED_DEFINE(_name, _count, _size, _ud_size, _destroy)
1462
1471
1484int net_buf_id(const struct net_buf *buf);
1485
1486#if defined(CONFIG_NET_BUF_POOL_USAGE) || defined(__DOXYGEN__)
1500static inline size_t net_buf_get_available(struct net_buf_pool *pool)
1501{
1502 return (size_t)atomic_get(&pool->avail_count);
1503}
1504
1514static inline size_t net_buf_get_max_used(struct net_buf_pool *pool)
1515{
1516 return (size_t)pool->max_used;
1517}
1518#endif /* defined(CONFIG_NET_BUF_POOL_USAGE) || defined(__DOXYGEN__) */
1519
1534#if defined(CONFIG_NET_BUF_LOG)
1535struct net_buf * __must_check net_buf_alloc_fixed_debug(struct net_buf_pool *pool,
1536 k_timeout_t timeout,
1537 const char *func,
1538 int line);
1539#define net_buf_alloc_fixed(_pool, _timeout) \
1540 net_buf_alloc_fixed_debug(_pool, _timeout, __func__, __LINE__)
1541#else
1542struct net_buf * __must_check net_buf_alloc_fixed(struct net_buf_pool *pool,
1543 k_timeout_t timeout);
1544#endif
1545
1549static inline struct net_buf * __must_check net_buf_alloc(struct net_buf_pool *pool,
1550 k_timeout_t timeout)
1551{
1552 return net_buf_alloc_fixed(pool, timeout);
1553}
1554
1570#if defined(CONFIG_NET_BUF_LOG)
1571struct net_buf * __must_check net_buf_alloc_len_debug(struct net_buf_pool *pool,
1572 size_t size,
1573 k_timeout_t timeout,
1574 const char *func,
1575 int line);
1576#define net_buf_alloc_len(_pool, _size, _timeout) \
1577 net_buf_alloc_len_debug(_pool, _size, _timeout, __func__, __LINE__)
1578#else
1579struct net_buf * __must_check net_buf_alloc_len(struct net_buf_pool *pool,
1580 size_t size,
1581 k_timeout_t timeout);
1582#endif
1583
1603#if defined(CONFIG_NET_BUF_LOG)
1604struct net_buf * __must_check net_buf_alloc_with_data_debug(struct net_buf_pool *pool,
1605 void *data, size_t size,
1606 k_timeout_t timeout,
1607 const char *func, int line);
1608#define net_buf_alloc_with_data(_pool, _data_, _size, _timeout) \
1609 net_buf_alloc_with_data_debug(_pool, _data_, _size, _timeout, \
1610 __func__, __LINE__)
1611#else
1612struct net_buf * __must_check net_buf_alloc_with_data(struct net_buf_pool *pool,
1613 void *data, size_t size,
1614 k_timeout_t timeout);
1615#endif
1616
1626static inline void net_buf_destroy(struct net_buf *buf)
1627{
1628 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id);
1629
1630 if (buf->__buf) {
1631 if (!(buf->flags & NET_BUF_EXTERNAL_DATA)) {
1632 pool->alloc->cb->unref(buf, buf->__buf);
1633 }
1634 buf->__buf = NULL;
1635 }
1636
1637 k_lifo_put(&pool->free, buf);
1638}
1639
1647void net_buf_reset(struct net_buf *buf);
1648
1657void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve);
1658
1665void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf);
1666
1674struct net_buf * __must_check net_buf_slist_get(sys_slist_t *list);
1675
1683#if defined(CONFIG_NET_BUF_LOG)
1684void net_buf_unref_debug(struct net_buf *buf, const char *func, int line);
1685#define net_buf_unref(_buf) \
1686 net_buf_unref_debug(_buf, __func__, __LINE__)
1687#else
1688void net_buf_unref(struct net_buf *buf);
1689#endif
1690
1698struct net_buf * __must_check net_buf_ref(struct net_buf *buf);
1699
1723static inline struct net_buf *__must_check net_buf_take(struct net_buf **orig)
1724{
1725 return (struct net_buf *)atomic_ptr_clear((atomic_ptr_t *)orig);
1726}
1727
1736static inline void net_buf_drop(struct net_buf **orig)
1737{
1738 struct net_buf *buf = net_buf_take(orig);
1739
1740 if (buf != NULL) {
1741 net_buf_unref(buf);
1742 }
1743}
1744
1758struct net_buf * __must_check net_buf_clone(struct net_buf *buf,
1759 k_timeout_t timeout);
1760
1768static inline void * __must_check net_buf_user_data(const struct net_buf *buf)
1769{
1770 return (void *)buf->user_data;
1771}
1772
1782int net_buf_user_data_copy(struct net_buf *dst, const struct net_buf *src);
1783
1792static inline void net_buf_reserve(struct net_buf *buf, size_t reserve)
1793{
1794 net_buf_simple_reserve(&buf->b, reserve);
1795}
1796
1808static inline void *net_buf_add(struct net_buf *buf, size_t len)
1809{
1810 return net_buf_simple_add(&buf->b, len);
1811}
1812
1825static inline void *net_buf_add_mem(struct net_buf *buf, const void *mem,
1826 size_t len)
1827{
1828 return net_buf_simple_add_mem(&buf->b, mem, len);
1829}
1830
1842static inline uint8_t *net_buf_add_u8(struct net_buf *buf, uint8_t val)
1843{
1844 return net_buf_simple_add_u8(&buf->b, val);
1845}
1846
1857static inline void net_buf_add_le16(struct net_buf *buf, uint16_t val)
1858{
1859 net_buf_simple_add_le16(&buf->b, val);
1860}
1861
1872static inline void net_buf_add_be16(struct net_buf *buf, uint16_t val)
1873{
1874 net_buf_simple_add_be16(&buf->b, val);
1875}
1876
1887static inline void net_buf_add_le24(struct net_buf *buf, uint32_t val)
1888{
1889 net_buf_simple_add_le24(&buf->b, val);
1890}
1891
1902static inline void net_buf_add_be24(struct net_buf *buf, uint32_t val)
1903{
1904 net_buf_simple_add_be24(&buf->b, val);
1905}
1906
1917static inline void net_buf_add_le32(struct net_buf *buf, uint32_t val)
1918{
1919 net_buf_simple_add_le32(&buf->b, val);
1920}
1921
1932static inline void net_buf_add_be32(struct net_buf *buf, uint32_t val)
1933{
1934 net_buf_simple_add_be32(&buf->b, val);
1935}
1936
1947static inline void net_buf_add_le40(struct net_buf *buf, uint64_t val)
1948{
1949 net_buf_simple_add_le40(&buf->b, val);
1950}
1951
1962static inline void net_buf_add_be40(struct net_buf *buf, uint64_t val)
1963{
1964 net_buf_simple_add_be40(&buf->b, val);
1965}
1966
1977static inline void net_buf_add_le48(struct net_buf *buf, uint64_t val)
1978{
1979 net_buf_simple_add_le48(&buf->b, val);
1980}
1981
1992static inline void net_buf_add_be48(struct net_buf *buf, uint64_t val)
1993{
1994 net_buf_simple_add_be48(&buf->b, val);
1995}
1996
2007static inline void net_buf_add_le64(struct net_buf *buf, uint64_t val)
2008{
2009 net_buf_simple_add_le64(&buf->b, val);
2010}
2011
2022static inline void net_buf_add_be64(struct net_buf *buf, uint64_t val)
2023{
2024 net_buf_simple_add_be64(&buf->b, val);
2025}
2026
2037static inline void *net_buf_remove_mem(struct net_buf *buf, size_t len)
2038{
2039 return net_buf_simple_remove_mem(&buf->b, len);
2040}
2041
2052static inline uint8_t net_buf_remove_u8(struct net_buf *buf)
2053{
2054 return net_buf_simple_remove_u8(&buf->b);
2055}
2056
2067static inline uint16_t net_buf_remove_le16(struct net_buf *buf)
2068{
2069 return net_buf_simple_remove_le16(&buf->b);
2070}
2071
2082static inline uint16_t net_buf_remove_be16(struct net_buf *buf)
2083{
2084 return net_buf_simple_remove_be16(&buf->b);
2085}
2086
2097static inline uint32_t net_buf_remove_be24(struct net_buf *buf)
2098{
2099 return net_buf_simple_remove_be24(&buf->b);
2100}
2101
2112static inline uint32_t net_buf_remove_le24(struct net_buf *buf)
2113{
2114 return net_buf_simple_remove_le24(&buf->b);
2115}
2116
2127static inline uint32_t net_buf_remove_le32(struct net_buf *buf)
2128{
2129 return net_buf_simple_remove_le32(&buf->b);
2130}
2131
2142static inline uint32_t net_buf_remove_be32(struct net_buf *buf)
2143{
2144 return net_buf_simple_remove_be32(&buf->b);
2145}
2146
2157static inline uint64_t net_buf_remove_le40(struct net_buf *buf)
2158{
2159 return net_buf_simple_remove_le40(&buf->b);
2160}
2161
2172static inline uint64_t net_buf_remove_be40(struct net_buf *buf)
2173{
2174 return net_buf_simple_remove_be40(&buf->b);
2175}
2176
2187static inline uint64_t net_buf_remove_le48(struct net_buf *buf)
2188{
2189 return net_buf_simple_remove_le48(&buf->b);
2190}
2191
2202static inline uint64_t net_buf_remove_be48(struct net_buf *buf)
2203{
2204 return net_buf_simple_remove_be48(&buf->b);
2205}
2206
2217static inline uint64_t net_buf_remove_le64(struct net_buf *buf)
2218{
2219 return net_buf_simple_remove_le64(&buf->b);
2220}
2221
2232static inline uint64_t net_buf_remove_be64(struct net_buf *buf)
2233{
2234 return net_buf_simple_remove_be64(&buf->b);
2235}
2236
2248static inline void *net_buf_push(struct net_buf *buf, size_t len)
2249{
2250 return net_buf_simple_push(&buf->b, len);
2251}
2252
2265static inline void *net_buf_push_mem(struct net_buf *buf, const void *mem,
2266 size_t len)
2267{
2268 return net_buf_simple_push_mem(&buf->b, mem, len);
2269}
2270
2279static inline void net_buf_push_u8(struct net_buf *buf, uint8_t val)
2280{
2281 net_buf_simple_push_u8(&buf->b, val);
2282}
2283
2293static inline void net_buf_push_le16(struct net_buf *buf, uint16_t val)
2294{
2295 net_buf_simple_push_le16(&buf->b, val);
2296}
2297
2307static inline void net_buf_push_be16(struct net_buf *buf, uint16_t val)
2308{
2309 net_buf_simple_push_be16(&buf->b, val);
2310}
2311
2321static inline void net_buf_push_le24(struct net_buf *buf, uint32_t val)
2322{
2323 net_buf_simple_push_le24(&buf->b, val);
2324}
2325
2335static inline void net_buf_push_be24(struct net_buf *buf, uint32_t val)
2336{
2337 net_buf_simple_push_be24(&buf->b, val);
2338}
2339
2349static inline void net_buf_push_le32(struct net_buf *buf, uint32_t val)
2350{
2351 net_buf_simple_push_le32(&buf->b, val);
2352}
2353
2363static inline void net_buf_push_be32(struct net_buf *buf, uint32_t val)
2364{
2365 net_buf_simple_push_be32(&buf->b, val);
2366}
2367
2377static inline void net_buf_push_le40(struct net_buf *buf, uint64_t val)
2378{
2379 net_buf_simple_push_le40(&buf->b, val);
2380}
2381
2391static inline void net_buf_push_be40(struct net_buf *buf, uint64_t val)
2392{
2393 net_buf_simple_push_be40(&buf->b, val);
2394}
2395
2405static inline void net_buf_push_le48(struct net_buf *buf, uint64_t val)
2406{
2407 net_buf_simple_push_le48(&buf->b, val);
2408}
2409
2419static inline void net_buf_push_be48(struct net_buf *buf, uint64_t val)
2420{
2421 net_buf_simple_push_be48(&buf->b, val);
2422}
2423
2433static inline void net_buf_push_le64(struct net_buf *buf, uint64_t val)
2434{
2435 net_buf_simple_push_le64(&buf->b, val);
2436}
2437
2447static inline void net_buf_push_be64(struct net_buf *buf, uint64_t val)
2448{
2449 net_buf_simple_push_be64(&buf->b, val);
2450}
2451
2463static inline void *net_buf_pull(struct net_buf *buf, size_t len)
2464{
2465 return net_buf_simple_pull(&buf->b, len);
2466}
2467
2479static inline void *net_buf_pull_mem(struct net_buf *buf, size_t len)
2480{
2481 return net_buf_simple_pull_mem(&buf->b, len);
2482}
2483
2494static inline uint8_t net_buf_pull_u8(struct net_buf *buf)
2495{
2496 return net_buf_simple_pull_u8(&buf->b);
2497}
2498
2509static inline uint16_t net_buf_pull_le16(struct net_buf *buf)
2510{
2511 return net_buf_simple_pull_le16(&buf->b);
2512}
2513
2524static inline uint16_t net_buf_pull_be16(struct net_buf *buf)
2525{
2526 return net_buf_simple_pull_be16(&buf->b);
2527}
2528
2539static inline uint32_t net_buf_pull_le24(struct net_buf *buf)
2540{
2541 return net_buf_simple_pull_le24(&buf->b);
2542}
2543
2554static inline uint32_t net_buf_pull_be24(struct net_buf *buf)
2555{
2556 return net_buf_simple_pull_be24(&buf->b);
2557}
2558
2569static inline uint32_t net_buf_pull_le32(struct net_buf *buf)
2570{
2571 return net_buf_simple_pull_le32(&buf->b);
2572}
2573
2584static inline uint32_t net_buf_pull_be32(struct net_buf *buf)
2585{
2586 return net_buf_simple_pull_be32(&buf->b);
2587}
2588
2599static inline uint64_t net_buf_pull_le40(struct net_buf *buf)
2600{
2601 return net_buf_simple_pull_le40(&buf->b);
2602}
2603
2614static inline uint64_t net_buf_pull_be40(struct net_buf *buf)
2615{
2616 return net_buf_simple_pull_be40(&buf->b);
2617}
2618
2629static inline uint64_t net_buf_pull_le48(struct net_buf *buf)
2630{
2631 return net_buf_simple_pull_le48(&buf->b);
2632}
2633
2644static inline uint64_t net_buf_pull_be48(struct net_buf *buf)
2645{
2646 return net_buf_simple_pull_be48(&buf->b);
2647}
2648
2659static inline uint64_t net_buf_pull_le64(struct net_buf *buf)
2660{
2661 return net_buf_simple_pull_le64(&buf->b);
2662}
2663
2674static inline uint64_t net_buf_pull_be64(struct net_buf *buf)
2675{
2676 return net_buf_simple_pull_be64(&buf->b);
2677}
2678
2688static inline size_t net_buf_tailroom(const struct net_buf *buf)
2689{
2690 return net_buf_simple_tailroom(&buf->b);
2691}
2692
2702static inline size_t net_buf_headroom(const struct net_buf *buf)
2703{
2704 return net_buf_simple_headroom(&buf->b);
2705}
2706
2721__deprecated static inline uint16_t net_buf_max_len(const struct net_buf *buf)
2722{
2723 return buf->size - net_buf_headroom(buf);
2724}
2725
2741static inline bool net_buf_is_valid(const struct net_buf *buf)
2742{
2743 return buf != NULL && buf->ref > 0 && net_buf_simple_is_valid(&buf->b);
2744}
2745
2755static inline uint8_t *net_buf_tail(const struct net_buf *buf)
2756{
2757 return net_buf_simple_tail(&buf->b);
2758}
2759
2766
2778void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag);
2779
2796struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag);
2797
2807#if defined(CONFIG_NET_BUF_LOG)
2808struct net_buf *net_buf_frag_del_debug(struct net_buf *parent,
2809 struct net_buf *frag,
2810 const char *func, int line);
2811#define net_buf_frag_del(_parent, _frag) \
2812 net_buf_frag_del_debug(_parent, _frag, __func__, __LINE__)
2813#else
2814struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag);
2815#endif
2816
2832size_t net_buf_linearize(void *dst, size_t dst_len,
2833 const struct net_buf *src, size_t offset, size_t len);
2834
2849typedef struct net_buf * __must_check (*net_buf_allocator_cb)(k_timeout_t timeout,
2850 void *user_data);
2851
2873size_t net_buf_append_bytes(struct net_buf *buf, size_t len,
2874 const void *value, k_timeout_t timeout,
2875 net_buf_allocator_cb allocate_cb, void *user_data);
2876
2891size_t net_buf_data_match(const struct net_buf *buf, size_t offset, const void *data, size_t len);
2892
2906static inline struct net_buf *net_buf_skip(struct net_buf *buf, size_t len)
2907{
2908 while (buf != NULL && len > 0U) {
2909 size_t to_skip = MIN(len, buf->len);
2910
2911 /* A zero-capacity fragment has no data buffer to pull from */
2912 if (to_skip > 0U) {
2913 net_buf_pull(buf, to_skip);
2914 len -= to_skip;
2915 }
2916
2917 if (buf->len == 0U) {
2918 buf = net_buf_frag_del(NULL, buf);
2919 }
2920 }
2921
2922 return buf;
2923}
2924
2935static inline size_t net_buf_frags_len(const struct net_buf *buf)
2936{
2937 size_t bytes = 0;
2938
2939 while (buf) {
2940 bytes += buf->len;
2941 buf = buf->frags;
2942 }
2943
2944 return bytes;
2945}
2946
2950
2951#ifdef __cplusplus
2952}
2953#endif
2954
2955#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:3267
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:143
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:2614
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:2022
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:2187
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:1902
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:2906
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:1808
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:1887
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:2599
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:2674
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:2447
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:2217
static void net_buf_simple_reset(struct net_buf_simple *buf)
Reset buffer.
Definition net_buf.h:173
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:1723
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:2391
static struct net_buf * net_buf_alloc(struct net_buf_pool *pool, k_timeout_t timeout)
Definition net_buf.h:1549
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:1932
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:2157
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:975
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:2082
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:2569
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:2584
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:1872
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:1947
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:2721
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:2644
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:1736
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:2307
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:2097
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:1962
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:2494
static void net_buf_destroy(struct net_buf *buf)
Destroy buffer from custom destroy callback.
Definition net_buf.h:1626
static size_t net_buf_simple_tailroom(const struct net_buf_simple *buf)
Check buffer tailroom.
Definition net_buf.h:934
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:953
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:2265
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:2629
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:2405
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:2539
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:1842
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:2335
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:2321
static void net_buf_reserve(struct net_buf *buf, size_t reserve)
Initialize buffer with the given headroom.
Definition net_buf.h:1792
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:2232
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:2741
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:2554
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:1992
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:2112
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:2279
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:2248
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:2524
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:2349
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:2659
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:2849
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:1500
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:906
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 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:2202
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:1045
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:2067
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:2293
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:1013
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:2419
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:2007
static size_t net_buf_headroom(const struct net_buf *buf)
Check buffer headroom.
Definition net_buf.h:2702
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:2142
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:2037
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:1825
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_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:2433
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:1514
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:2052
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:920
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:1857
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:2172
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:2363
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:1917
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:2127
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition net_buf.h:2935
static size_t net_buf_tailroom(const struct net_buf *buf)
Check buffer tailroom.
Definition net_buf.h:2688
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:2509
static uint8_t * net_buf_tail(const struct net_buf *buf)
Get the tail pointer for a buffer.
Definition net_buf.h:2755
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:2479
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:1029
static void * net_buf_pull(struct net_buf *buf, size_t len)
Remove data from the beginning of the buffer.
Definition net_buf.h:2463
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:2377
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:1977
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:1768
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:406
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 LIFO structure.
Definition kernel.h:3209
Kernel Spin Lock.
Definition spinlock.h:45
Kernel timeout type.
Definition clock.h:65
Network buffer pool representation.
Definition net_buf.h:1190
void(*const destroy)(struct net_buf *buf)
Optional destroy callback when buffer is freed.
Definition net_buf.h:1221
uint16_t uninit_count
Number of uninitialized buffers.
Definition net_buf.h:1201
uint8_t user_data_size
Size of user data allocated to this pool.
Definition net_buf.h:1204
const uint16_t buf_count
Number of buffers in pool.
Definition net_buf.h:1198
const struct net_buf_data_alloc * alloc
Data allocation handlers.
Definition net_buf.h:1224
struct k_lifo free
LIFO to place the buffer into when free.
Definition net_buf.h:1192
struct k_spinlock lock
To prevent concurrent access/modifications.
Definition net_buf.h:1195
Parsing state of a buffer.
Definition net_buf.h:998
uint16_t offset
Offset of the data pointer from the beginning of the storage.
Definition net_buf.h:1000
uint16_t len
Length of data.
Definition net_buf.h:1002
Simple network buffer representation.
Definition net_buf.h:89
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:91
uint16_t size
Amount of data that net_buf_simple::__buf can store.
Definition net_buf.h:102
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:99
Network buffer representation.
Definition net_buf.h:1054
uint16_t size
Amount of data that this buffer can store.
Definition net_buf.h:1149
struct net_buf * frags
Fragments associated with this buffer.
Definition net_buf.h:1059
uint8_t ref
Reference count.
Definition net_buf.h:1122
uint8_t pool_id
Where the buffer should go when freed up.
Definition net_buf.h:1128
sys_snode_t node
Allow placing the buffer into sys_slist_t.
Definition net_buf.h:1056
uint8_t user_data_size
Size of user data on this buffer.
Definition net_buf.h:1131
uint8_t flags
Bit-field of buffer flags.
Definition net_buf.h:1125
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1143
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1164
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1146
Iterable sections helpers.
Misc utilities.