Zephyr Project API 4.5.0-rc2
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
1100 union {
1102 atomic_t ref_word;
1104 struct {
1105#if defined(CONFIG_BIG_ENDIAN)
1106 /* atomic_t is typedef'd as long (BUILD_ASSERTed in
1107 * lib/net_buf/buf.c); on a 64-bit big-endian build
1108 * the byte struct needs 4 bytes of padding so that
1109 * `ref` lands on the least-significant byte of
1110 * ref_word.
1111 */
1112#if (__SIZEOF_LONG__ == 8)
1114 uint8_t _ref_word_pad[4];
1116#endif
1119
1122
1124 uint8_t flags;
1125
1127 uint8_t ref;
1128#else
1131
1134
1137
1140#endif
1141 };
1142 };
1143
1147 union {
1148 /* The ABI of this struct must match net_buf_simple */
1149 struct {
1152
1155
1158
1163 uint8_t *__buf;
1164 };
1165
1167 struct net_buf_simple b;
1169 };
1170
1172 uint8_t user_data[] __net_buf_align;
1173};
1174
1176
1177struct net_buf_data_cb {
1178 uint8_t * __must_check (*alloc)(struct net_buf *buf, size_t *size,
1179 k_timeout_t timeout);
1180 uint8_t * __must_check (*ref)(struct net_buf *buf, uint8_t *data);
1181 void (*unref)(struct net_buf *buf, uint8_t *data);
1182};
1183
1184struct net_buf_data_alloc {
1185 const struct net_buf_data_cb *cb;
1186 void *alloc_data;
1187 size_t max_alloc_size;
1188 size_t alignment;
1189};
1190
1192
1200 struct k_lifo free;
1201
1204
1207
1210
1213
1214#if defined(CONFIG_NET_BUF_POOL_USAGE)
1216 atomic_t avail_count;
1217
1219 const uint16_t pool_size;
1220
1222 uint16_t max_used;
1223
1225 const char *name;
1226#endif /* CONFIG_NET_BUF_POOL_USAGE */
1227
1229 void (*const destroy)(struct net_buf *buf);
1230
1232 const struct net_buf_data_alloc *alloc;
1233
1235 struct net_buf * const __bufs;
1236};
1237
1239#define NET_BUF_POOL_USAGE_INIT(_pool, _count) \
1240 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.avail_count = ATOMIC_INIT(_count),)) \
1241 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.max_used = 0,)) \
1242 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.name = STRINGIFY(_pool),))
1243
1244#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \
1245 { \
1246 .free = Z_LIFO_INITIALIZER(_pool.free), \
1247 .lock = { }, \
1248 .buf_count = _count, \
1249 .uninit_count = _count, \
1250 .user_data_size = _ud_size, \
1251 NET_BUF_POOL_USAGE_INIT(_pool, _count) \
1252 .destroy = _destroy, \
1253 .alloc = _alloc, \
1254 .__bufs = (struct net_buf *)_bufs, \
1255 }
1256
1257#define _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size) \
1258 struct _net_buf_##_name { uint8_t b[sizeof(struct net_buf)]; \
1259 uint8_t ud[_ud_size]; } __net_buf_align; \
1260 BUILD_ASSERT(_ud_size <= UINT8_MAX); \
1261 BUILD_ASSERT(offsetof(struct net_buf, user_data) == \
1262 offsetof(struct _net_buf_##_name, ud), "Invalid offset"); \
1263 BUILD_ASSERT(__alignof__(struct net_buf) == \
1264 __alignof__(struct _net_buf_##_name), "Invalid alignment"); \
1265 BUILD_ASSERT(sizeof(struct _net_buf_##_name) == \
1266 ROUND_UP(sizeof(struct net_buf) + _ud_size, __alignof__(struct net_buf)), \
1267 "Size cannot be determined"); \
1268 static struct _net_buf_##_name _net_buf_##_name[_count] __noinit
1269
1270extern const struct net_buf_data_alloc net_buf_heap_alloc;
1272
1300#define NET_BUF_POOL_HEAP_DEFINE(_name, _count, _ud_size, _destroy) \
1301 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1302 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1303 NET_BUF_POOL_INITIALIZER(_name, &net_buf_heap_alloc, \
1304 _net_buf_##_name, _count, _ud_size, \
1305 _destroy)
1306
1308
1309struct net_buf_pool_fixed {
1310 uint8_t *data_pool;
1311};
1312
1313extern const struct net_buf_data_cb net_buf_fixed_cb;
1314
1316
1345#define NET_BUF_POOL_FIXED_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1346 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1347 static uint8_t __noinit net_buf_data_##_name[_count][_data_size] __net_buf_align; \
1348 static const struct net_buf_pool_fixed net_buf_fixed_##_name = { \
1349 .data_pool = (uint8_t *)net_buf_data_##_name, \
1350 }; \
1351 static const struct net_buf_data_alloc net_buf_fixed_alloc_##_name = { \
1352 .cb = &net_buf_fixed_cb, \
1353 .alloc_data = (void *)&net_buf_fixed_##_name, \
1354 .max_alloc_size = _data_size, \
1355 }; \
1356 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1357 NET_BUF_POOL_INITIALIZER(_name, &net_buf_fixed_alloc_##_name, \
1358 _net_buf_##_name, _count, _ud_size, \
1359 _destroy)
1360
1362extern const struct net_buf_data_cb net_buf_var_cb;
1364
1389#define NET_BUF_POOL_VAR_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1390 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1391 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1392 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1393 .cb = &net_buf_var_cb, \
1394 .alloc_data = &net_buf_mem_pool_##_name, \
1395 .max_alloc_size = 0, \
1396 }; \
1397 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1398 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1399 _net_buf_##_name, _count, _ud_size, \
1400 _destroy)
1401
1432#define NET_BUF_POOL_VAR_ALIGN_DEFINE(_name, _count, _data_size, _ud_size, \
1433 _destroy, _align) \
1434 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1435 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1436 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1437 .cb = &net_buf_var_cb, \
1438 .alloc_data = &net_buf_mem_pool_##_name, \
1439 .max_alloc_size = 0, \
1440 .alignment = _align, \
1441 }; \
1442 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1443 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1444 _net_buf_##_name, _count, _ud_size, \
1445 _destroy)
1446
1468#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy) \
1469 NET_BUF_POOL_FIXED_DEFINE(_name, _count, _size, _ud_size, _destroy)
1470
1479
1492int net_buf_id(const struct net_buf *buf);
1493
1494#if defined(CONFIG_NET_BUF_POOL_USAGE) || defined(__DOXYGEN__)
1508static inline size_t net_buf_get_available(struct net_buf_pool *pool)
1509{
1510 return (size_t)atomic_get(&pool->avail_count);
1511}
1512
1522static inline size_t net_buf_get_max_used(struct net_buf_pool *pool)
1523{
1524 return (size_t)pool->max_used;
1525}
1526#endif /* defined(CONFIG_NET_BUF_POOL_USAGE) || defined(__DOXYGEN__) */
1527
1542#if defined(CONFIG_NET_BUF_LOG)
1543struct net_buf * __must_check net_buf_alloc_fixed_debug(struct net_buf_pool *pool,
1544 k_timeout_t timeout,
1545 const char *func,
1546 int line);
1547#define net_buf_alloc_fixed(_pool, _timeout) \
1548 net_buf_alloc_fixed_debug(_pool, _timeout, __func__, __LINE__)
1549#else
1550struct net_buf * __must_check net_buf_alloc_fixed(struct net_buf_pool *pool,
1551 k_timeout_t timeout);
1552#endif
1553
1557static inline struct net_buf * __must_check net_buf_alloc(struct net_buf_pool *pool,
1558 k_timeout_t timeout)
1559{
1560 return net_buf_alloc_fixed(pool, timeout);
1561}
1562
1578#if defined(CONFIG_NET_BUF_LOG)
1579struct net_buf * __must_check net_buf_alloc_len_debug(struct net_buf_pool *pool,
1580 size_t size,
1581 k_timeout_t timeout,
1582 const char *func,
1583 int line);
1584#define net_buf_alloc_len(_pool, _size, _timeout) \
1585 net_buf_alloc_len_debug(_pool, _size, _timeout, __func__, __LINE__)
1586#else
1587struct net_buf * __must_check net_buf_alloc_len(struct net_buf_pool *pool,
1588 size_t size,
1589 k_timeout_t timeout);
1590#endif
1591
1613#if defined(CONFIG_NET_BUF_LOG)
1614struct net_buf * __must_check net_buf_alloc_with_data_debug(struct net_buf_pool *pool,
1615 void *data, size_t size,
1616 k_timeout_t timeout,
1617 const char *func, int line);
1618#define net_buf_alloc_with_data(_pool, _data_, _size, _timeout) \
1619 net_buf_alloc_with_data_debug(_pool, _data_, _size, _timeout, \
1620 __func__, __LINE__)
1621#else
1622struct net_buf * __must_check net_buf_alloc_with_data(struct net_buf_pool *pool,
1623 void *data, size_t size,
1624 k_timeout_t timeout);
1625#endif
1626
1636static inline void net_buf_destroy(struct net_buf *buf)
1637{
1638 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id);
1639
1640 if (buf->__buf) {
1641 if (!(buf->flags & NET_BUF_EXTERNAL_DATA)) {
1642 pool->alloc->cb->unref(buf, buf->__buf);
1643 }
1644 buf->__buf = NULL;
1645 }
1646
1647 k_lifo_put(&pool->free, buf);
1648}
1649
1657void net_buf_reset(struct net_buf *buf);
1658
1667void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve);
1668
1679void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf);
1680
1690struct net_buf * __must_check net_buf_slist_get(sys_slist_t *list);
1691
1699#if defined(CONFIG_NET_BUF_LOG)
1700void net_buf_unref_debug(struct net_buf *buf, const char *func, int line);
1701#define net_buf_unref(_buf) \
1702 net_buf_unref_debug(_buf, __func__, __LINE__)
1703#else
1704void net_buf_unref(struct net_buf *buf);
1705#endif
1706
1714struct net_buf * __must_check net_buf_ref(struct net_buf *buf);
1715
1739static inline struct net_buf *__must_check net_buf_take(struct net_buf **orig)
1740{
1741 return (struct net_buf *)atomic_ptr_clear((atomic_ptr_t *)orig);
1742}
1743
1752static inline void net_buf_drop(struct net_buf **orig)
1753{
1754 struct net_buf *buf = net_buf_take(orig);
1755
1756 if (buf != NULL) {
1757 net_buf_unref(buf);
1758 }
1759}
1760
1774struct net_buf * __must_check net_buf_clone(struct net_buf *buf,
1775 k_timeout_t timeout);
1776
1784static inline void * __must_check net_buf_user_data(const struct net_buf *buf)
1785{
1786 return (void *)buf->user_data;
1787}
1788
1798int net_buf_user_data_copy(struct net_buf *dst, const struct net_buf *src);
1799
1808static inline void net_buf_reserve(struct net_buf *buf, size_t reserve)
1809{
1810 net_buf_simple_reserve(&buf->b, reserve);
1811}
1812
1824static inline void *net_buf_add(struct net_buf *buf, size_t len)
1825{
1826 return net_buf_simple_add(&buf->b, len);
1827}
1828
1841static inline void *net_buf_add_mem(struct net_buf *buf, const void *mem,
1842 size_t len)
1843{
1844 return net_buf_simple_add_mem(&buf->b, mem, len);
1845}
1846
1858static inline uint8_t *net_buf_add_u8(struct net_buf *buf, uint8_t val)
1859{
1860 return net_buf_simple_add_u8(&buf->b, val);
1861}
1862
1873static inline void net_buf_add_le16(struct net_buf *buf, uint16_t val)
1874{
1875 net_buf_simple_add_le16(&buf->b, val);
1876}
1877
1888static inline void net_buf_add_be16(struct net_buf *buf, uint16_t val)
1889{
1890 net_buf_simple_add_be16(&buf->b, val);
1891}
1892
1903static inline void net_buf_add_le24(struct net_buf *buf, uint32_t val)
1904{
1905 net_buf_simple_add_le24(&buf->b, val);
1906}
1907
1918static inline void net_buf_add_be24(struct net_buf *buf, uint32_t val)
1919{
1920 net_buf_simple_add_be24(&buf->b, val);
1921}
1922
1933static inline void net_buf_add_le32(struct net_buf *buf, uint32_t val)
1934{
1935 net_buf_simple_add_le32(&buf->b, val);
1936}
1937
1948static inline void net_buf_add_be32(struct net_buf *buf, uint32_t val)
1949{
1950 net_buf_simple_add_be32(&buf->b, val);
1951}
1952
1963static inline void net_buf_add_le40(struct net_buf *buf, uint64_t val)
1964{
1965 net_buf_simple_add_le40(&buf->b, val);
1966}
1967
1978static inline void net_buf_add_be40(struct net_buf *buf, uint64_t val)
1979{
1980 net_buf_simple_add_be40(&buf->b, val);
1981}
1982
1993static inline void net_buf_add_le48(struct net_buf *buf, uint64_t val)
1994{
1995 net_buf_simple_add_le48(&buf->b, val);
1996}
1997
2008static inline void net_buf_add_be48(struct net_buf *buf, uint64_t val)
2009{
2010 net_buf_simple_add_be48(&buf->b, val);
2011}
2012
2023static inline void net_buf_add_le64(struct net_buf *buf, uint64_t val)
2024{
2025 net_buf_simple_add_le64(&buf->b, val);
2026}
2027
2038static inline void net_buf_add_be64(struct net_buf *buf, uint64_t val)
2039{
2040 net_buf_simple_add_be64(&buf->b, val);
2041}
2042
2053static inline void *net_buf_remove_mem(struct net_buf *buf, size_t len)
2054{
2055 return net_buf_simple_remove_mem(&buf->b, len);
2056}
2057
2068static inline uint8_t net_buf_remove_u8(struct net_buf *buf)
2069{
2070 return net_buf_simple_remove_u8(&buf->b);
2071}
2072
2083static inline uint16_t net_buf_remove_le16(struct net_buf *buf)
2084{
2085 return net_buf_simple_remove_le16(&buf->b);
2086}
2087
2098static inline uint16_t net_buf_remove_be16(struct net_buf *buf)
2099{
2100 return net_buf_simple_remove_be16(&buf->b);
2101}
2102
2113static inline uint32_t net_buf_remove_be24(struct net_buf *buf)
2114{
2115 return net_buf_simple_remove_be24(&buf->b);
2116}
2117
2128static inline uint32_t net_buf_remove_le24(struct net_buf *buf)
2129{
2130 return net_buf_simple_remove_le24(&buf->b);
2131}
2132
2143static inline uint32_t net_buf_remove_le32(struct net_buf *buf)
2144{
2145 return net_buf_simple_remove_le32(&buf->b);
2146}
2147
2158static inline uint32_t net_buf_remove_be32(struct net_buf *buf)
2159{
2160 return net_buf_simple_remove_be32(&buf->b);
2161}
2162
2173static inline uint64_t net_buf_remove_le40(struct net_buf *buf)
2174{
2175 return net_buf_simple_remove_le40(&buf->b);
2176}
2177
2188static inline uint64_t net_buf_remove_be40(struct net_buf *buf)
2189{
2190 return net_buf_simple_remove_be40(&buf->b);
2191}
2192
2203static inline uint64_t net_buf_remove_le48(struct net_buf *buf)
2204{
2205 return net_buf_simple_remove_le48(&buf->b);
2206}
2207
2218static inline uint64_t net_buf_remove_be48(struct net_buf *buf)
2219{
2220 return net_buf_simple_remove_be48(&buf->b);
2221}
2222
2233static inline uint64_t net_buf_remove_le64(struct net_buf *buf)
2234{
2235 return net_buf_simple_remove_le64(&buf->b);
2236}
2237
2248static inline uint64_t net_buf_remove_be64(struct net_buf *buf)
2249{
2250 return net_buf_simple_remove_be64(&buf->b);
2251}
2252
2264static inline void *net_buf_push(struct net_buf *buf, size_t len)
2265{
2266 return net_buf_simple_push(&buf->b, len);
2267}
2268
2281static inline void *net_buf_push_mem(struct net_buf *buf, const void *mem,
2282 size_t len)
2283{
2284 return net_buf_simple_push_mem(&buf->b, mem, len);
2285}
2286
2295static inline void net_buf_push_u8(struct net_buf *buf, uint8_t val)
2296{
2297 net_buf_simple_push_u8(&buf->b, val);
2298}
2299
2309static inline void net_buf_push_le16(struct net_buf *buf, uint16_t val)
2310{
2311 net_buf_simple_push_le16(&buf->b, val);
2312}
2313
2323static inline void net_buf_push_be16(struct net_buf *buf, uint16_t val)
2324{
2325 net_buf_simple_push_be16(&buf->b, val);
2326}
2327
2337static inline void net_buf_push_le24(struct net_buf *buf, uint32_t val)
2338{
2339 net_buf_simple_push_le24(&buf->b, val);
2340}
2341
2351static inline void net_buf_push_be24(struct net_buf *buf, uint32_t val)
2352{
2353 net_buf_simple_push_be24(&buf->b, val);
2354}
2355
2365static inline void net_buf_push_le32(struct net_buf *buf, uint32_t val)
2366{
2367 net_buf_simple_push_le32(&buf->b, val);
2368}
2369
2379static inline void net_buf_push_be32(struct net_buf *buf, uint32_t val)
2380{
2381 net_buf_simple_push_be32(&buf->b, val);
2382}
2383
2393static inline void net_buf_push_le40(struct net_buf *buf, uint64_t val)
2394{
2395 net_buf_simple_push_le40(&buf->b, val);
2396}
2397
2407static inline void net_buf_push_be40(struct net_buf *buf, uint64_t val)
2408{
2409 net_buf_simple_push_be40(&buf->b, val);
2410}
2411
2421static inline void net_buf_push_le48(struct net_buf *buf, uint64_t val)
2422{
2423 net_buf_simple_push_le48(&buf->b, val);
2424}
2425
2435static inline void net_buf_push_be48(struct net_buf *buf, uint64_t val)
2436{
2437 net_buf_simple_push_be48(&buf->b, val);
2438}
2439
2449static inline void net_buf_push_le64(struct net_buf *buf, uint64_t val)
2450{
2451 net_buf_simple_push_le64(&buf->b, val);
2452}
2453
2463static inline void net_buf_push_be64(struct net_buf *buf, uint64_t val)
2464{
2465 net_buf_simple_push_be64(&buf->b, val);
2466}
2467
2479static inline void *net_buf_pull(struct net_buf *buf, size_t len)
2480{
2481 return net_buf_simple_pull(&buf->b, len);
2482}
2483
2495static inline void *net_buf_pull_mem(struct net_buf *buf, size_t len)
2496{
2497 return net_buf_simple_pull_mem(&buf->b, len);
2498}
2499
2510static inline uint8_t net_buf_pull_u8(struct net_buf *buf)
2511{
2512 return net_buf_simple_pull_u8(&buf->b);
2513}
2514
2525static inline uint16_t net_buf_pull_le16(struct net_buf *buf)
2526{
2527 return net_buf_simple_pull_le16(&buf->b);
2528}
2529
2540static inline uint16_t net_buf_pull_be16(struct net_buf *buf)
2541{
2542 return net_buf_simple_pull_be16(&buf->b);
2543}
2544
2555static inline uint32_t net_buf_pull_le24(struct net_buf *buf)
2556{
2557 return net_buf_simple_pull_le24(&buf->b);
2558}
2559
2570static inline uint32_t net_buf_pull_be24(struct net_buf *buf)
2571{
2572 return net_buf_simple_pull_be24(&buf->b);
2573}
2574
2585static inline uint32_t net_buf_pull_le32(struct net_buf *buf)
2586{
2587 return net_buf_simple_pull_le32(&buf->b);
2588}
2589
2600static inline uint32_t net_buf_pull_be32(struct net_buf *buf)
2601{
2602 return net_buf_simple_pull_be32(&buf->b);
2603}
2604
2615static inline uint64_t net_buf_pull_le40(struct net_buf *buf)
2616{
2617 return net_buf_simple_pull_le40(&buf->b);
2618}
2619
2630static inline uint64_t net_buf_pull_be40(struct net_buf *buf)
2631{
2632 return net_buf_simple_pull_be40(&buf->b);
2633}
2634
2645static inline uint64_t net_buf_pull_le48(struct net_buf *buf)
2646{
2647 return net_buf_simple_pull_le48(&buf->b);
2648}
2649
2660static inline uint64_t net_buf_pull_be48(struct net_buf *buf)
2661{
2662 return net_buf_simple_pull_be48(&buf->b);
2663}
2664
2675static inline uint64_t net_buf_pull_le64(struct net_buf *buf)
2676{
2677 return net_buf_simple_pull_le64(&buf->b);
2678}
2679
2690static inline uint64_t net_buf_pull_be64(struct net_buf *buf)
2691{
2692 return net_buf_simple_pull_be64(&buf->b);
2693}
2694
2704static inline size_t net_buf_tailroom(const struct net_buf *buf)
2705{
2706 return net_buf_simple_tailroom(&buf->b);
2707}
2708
2718static inline size_t net_buf_headroom(const struct net_buf *buf)
2719{
2720 return net_buf_simple_headroom(&buf->b);
2721}
2722
2737__deprecated static inline uint16_t net_buf_max_len(const struct net_buf *buf)
2738{
2739 return buf->size - net_buf_headroom(buf);
2740}
2741
2757static inline bool net_buf_is_valid(const struct net_buf *buf)
2758{
2759 return buf != NULL && buf->ref > 0 && net_buf_simple_is_valid(&buf->b);
2760}
2761
2771static inline uint8_t *net_buf_tail(const struct net_buf *buf)
2772{
2773 return net_buf_simple_tail(&buf->b);
2774}
2775
2782
2794void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag);
2795
2812struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag);
2813
2823#if defined(CONFIG_NET_BUF_LOG)
2824struct net_buf *net_buf_frag_del_debug(struct net_buf *parent,
2825 struct net_buf *frag,
2826 const char *func, int line);
2827#define net_buf_frag_del(_parent, _frag) \
2828 net_buf_frag_del_debug(_parent, _frag, __func__, __LINE__)
2829#else
2830struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag);
2831#endif
2832
2848size_t net_buf_linearize(void *dst, size_t dst_len,
2849 const struct net_buf *src, size_t offset, size_t len);
2850
2865typedef struct net_buf * __must_check (*net_buf_allocator_cb)(k_timeout_t timeout,
2866 void *user_data);
2867
2891size_t net_buf_append_bytes(struct net_buf *buf, size_t len,
2892 const void *value, k_timeout_t timeout,
2893 net_buf_allocator_cb allocate_cb, void *user_data);
2894
2909size_t net_buf_data_match(const struct net_buf *buf, size_t offset, const void *data, size_t len);
2910
2924static inline struct net_buf *net_buf_skip(struct net_buf *buf, size_t len)
2925{
2926 while (buf != NULL && len > 0U) {
2927 size_t to_skip = MIN(len, buf->len);
2928
2929 /* A zero-capacity fragment has no data buffer to pull from */
2930 if (to_skip > 0U) {
2931 net_buf_pull(buf, to_skip);
2932 len -= to_skip;
2933 }
2934
2935 if (buf->len == 0U) {
2936 buf = net_buf_frag_del(NULL, buf);
2937 }
2938 }
2939
2940 return buf;
2941}
2942
2953static inline size_t net_buf_frags_len(const struct net_buf *buf)
2954{
2955 size_t bytes = 0;
2956
2957 while (buf) {
2958 bytes += buf->len;
2959 buf = buf->frags;
2960 }
2961
2962 return bytes;
2963}
2964
2968
2969#ifdef __cplusplus
2970}
2971#endif
2972
2973#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: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:2630
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:2038
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:2203
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:1918
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:2924
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:1824
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:1903
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:2615
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:2690
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:2463
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:2233
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:1739
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:2407
static struct net_buf * net_buf_alloc(struct net_buf_pool *pool, k_timeout_t timeout)
Definition net_buf.h:1557
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:1948
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:2173
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:2098
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:2585
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:2600
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:1888
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:1963
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:2737
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:2660
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:1752
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:2323
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:2113
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:1978
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:2510
static void net_buf_destroy(struct net_buf *buf)
Destroy buffer from custom destroy callback.
Definition net_buf.h:1636
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:2281
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:2645
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:2421
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:2555
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:1858
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:2351
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:2337
static void net_buf_reserve(struct net_buf *buf, size_t reserve)
Initialize buffer with the given headroom.
Definition net_buf.h:1808
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:2248
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:2757
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:2570
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:2008
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:2128
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:2295
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:2264
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:2540
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:2365
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:2675
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:2865
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:1508
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 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:2218
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:2083
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:2309
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:2435
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:2023
static size_t net_buf_headroom(const struct net_buf *buf)
Check buffer headroom.
Definition net_buf.h:2718
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:2158
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:2053
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:1841
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:2449
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:1522
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:2068
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:1873
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:2188
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:2379
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:1933
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:2143
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition net_buf.h:2953
static size_t net_buf_tailroom(const struct net_buf *buf)
Check buffer tailroom.
Definition net_buf.h:2704
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:2525
static uint8_t * net_buf_tail(const struct net_buf *buf)
Get the tail pointer for a buffer.
Definition net_buf.h:2771
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:2495
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:2479
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:2393
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:1993
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:1784
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
#define NULL
Definition iar_missing_defs.h:20
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:1198
void(*const destroy)(struct net_buf *buf)
Optional destroy callback when buffer is freed.
Definition net_buf.h:1229
uint16_t uninit_count
Number of uninitialized buffers.
Definition net_buf.h:1209
uint8_t user_data_size
Size of user data allocated to this pool.
Definition net_buf.h:1212
const uint16_t buf_count
Number of buffers in pool.
Definition net_buf.h:1206
const struct net_buf_data_alloc * alloc
Data allocation handlers.
Definition net_buf.h:1232
struct k_lifo free
LIFO to place the buffer into when free.
Definition net_buf.h:1200
struct k_spinlock lock
To prevent concurrent access/modifications.
Definition net_buf.h:1203
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:1157
struct net_buf * frags
Fragments associated with this buffer.
Definition net_buf.h:1067
uint8_t ref
Reference count.
Definition net_buf.h:1130
uint8_t pool_id
Where the buffer should go when freed up.
Definition net_buf.h:1136
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:1139
uint8_t flags
Bit-field of buffer flags.
Definition net_buf.h:1133
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1151
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1172
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1154
Iterable sections helpers.
Misc utilities.