Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_buf.h
Go to the documentation of this file.
1
4
5/*
6 * Copyright (c) 2015 Intel Corporation
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10#ifndef ZEPHYR_INCLUDE_NET_BUF_H_
11#define ZEPHYR_INCLUDE_NET_BUF_H_
12
13#include <stddef.h>
14#include <zephyr/types.h>
15#include <zephyr/sys/util.h>
16#include <zephyr/kernel.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
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
99
102
106 uint8_t *__buf;
107};
108
125#define NET_BUF_SIMPLE(_size) \
126 ((struct net_buf_simple *)(&(struct { \
127 struct net_buf_simple buf; \
128 uint8_t data[_size]; \
129 }) { \
130 .buf.size = _size, \
131 }))
132
142static inline void net_buf_simple_init(struct net_buf_simple *buf,
143 size_t reserve_head)
144{
145 if (!buf->__buf) {
146 buf->__buf = (uint8_t *)buf + sizeof(*buf);
147 }
148
149 buf->data = buf->__buf + reserve_head;
150 buf->len = 0U;
151}
152
163 void *data, size_t size);
164
172static inline void net_buf_simple_reset(struct net_buf_simple *buf)
173{
174 buf->len = 0U;
175 buf->data = buf->__buf;
176}
177
188void net_buf_simple_clone(const struct net_buf_simple *original,
189 struct net_buf_simple *clone);
190
202void *net_buf_simple_add(struct net_buf_simple *buf, size_t len);
203
216void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem,
217 size_t len);
218
231
243
255
267
279
291
303
315
327
339
351
363
375
386void *net_buf_simple_remove_mem(struct net_buf_simple *buf, size_t len);
387
399
411
423
435
447
459
471
483
495
507
519
531
543
555void *net_buf_simple_push(struct net_buf_simple *buf, size_t len);
556
569void *net_buf_simple_push_mem(struct net_buf_simple *buf, const void *mem,
570 size_t len);
571
582
593
603
614
625
636
647
658
669
680
691
702
713
725void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len);
726
738void *net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len);
739
751
763
775
787
799
811
823
835
847
859
871
883
895
905static inline uint8_t *net_buf_simple_tail(const struct net_buf_simple *buf)
906{
907 return buf->data + buf->len;
908}
909
919static inline size_t net_buf_simple_headroom(const struct net_buf_simple *buf)
920{
921 return buf->data - buf->__buf;
922}
923
933static inline size_t net_buf_simple_tailroom(const struct net_buf_simple *buf)
934{
935 return buf->size - net_buf_simple_headroom(buf) - buf->len;
936}
937
947static inline uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf)
948{
949 return buf->size - net_buf_simple_headroom(buf);
950}
951
965
974static inline void net_buf_simple_save(const struct net_buf_simple *buf,
976{
977 state->offset = (uint16_t)net_buf_simple_headroom(buf);
978 state->len = buf->len;
979}
980
990static inline void net_buf_simple_restore(struct net_buf_simple *buf,
992{
993 buf->data = buf->__buf + state->offset;
994 buf->len = state->len;
995}
996
1006#define NET_BUF_EXTERNAL_DATA BIT(0)
1007
1015struct net_buf {
1018
1021
1053 union {
1055 atomic_t ref_word;
1057 struct {
1058#if defined(CONFIG_BIG_ENDIAN)
1059 /* atomic_t is typedef'd as long (BUILD_ASSERTed in
1060 * lib/net_buf/buf.c); on a 64-bit big-endian build
1061 * the byte struct needs 4 bytes of padding so that
1062 * `ref` lands on the least-significant byte of
1063 * ref_word.
1064 */
1065#if (__SIZEOF_LONG__ == 8)
1067 uint8_t _ref_word_pad[4];
1069#endif
1072
1075
1077 uint8_t flags;
1078
1080 uint8_t ref;
1081#else
1084
1087
1090
1093#endif
1094 };
1095 };
1096
1100 union {
1101 /* The ABI of this struct must match net_buf_simple */
1102 struct {
1105
1108
1111
1116 uint8_t *__buf;
1117 };
1118
1120 struct net_buf_simple b;
1122 };
1123
1125 uint8_t user_data[] __net_buf_align;
1126};
1127
1129
1130struct net_buf_data_cb {
1131 uint8_t * __must_check (*alloc)(struct net_buf *buf, size_t *size,
1132 k_timeout_t timeout);
1133 uint8_t * __must_check (*ref)(struct net_buf *buf, uint8_t *data);
1134 void (*unref)(struct net_buf *buf, uint8_t *data);
1135};
1136
1137struct net_buf_data_alloc {
1138 const struct net_buf_data_cb *cb;
1139 void *alloc_data;
1140 size_t max_alloc_size;
1141 size_t alignment;
1142};
1143
1145
1153 struct k_lifo free;
1154
1157
1160
1163
1166
1167#if defined(CONFIG_NET_BUF_POOL_USAGE)
1169 atomic_t avail_count;
1170
1172 const uint16_t pool_size;
1173
1175 uint16_t max_used;
1176
1178 const char *name;
1179#endif /* CONFIG_NET_BUF_POOL_USAGE */
1180
1182 void (*const destroy)(struct net_buf *buf);
1183
1185 const struct net_buf_data_alloc *alloc;
1186
1188 struct net_buf * const __bufs;
1189};
1190
1192#define NET_BUF_POOL_USAGE_INIT(_pool, _count) \
1193 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.avail_count = ATOMIC_INIT(_count),)) \
1194 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.max_used = 0,)) \
1195 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.name = STRINGIFY(_pool),))
1196
1197#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \
1198 { \
1199 .free = Z_LIFO_INITIALIZER(_pool.free), \
1200 .lock = { }, \
1201 .buf_count = _count, \
1202 .uninit_count = _count, \
1203 .user_data_size = _ud_size, \
1204 NET_BUF_POOL_USAGE_INIT(_pool, _count) \
1205 .destroy = _destroy, \
1206 .alloc = _alloc, \
1207 .__bufs = (struct net_buf *)_bufs, \
1208 }
1209
1210#define _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size) \
1211 struct _net_buf_##_name { uint8_t b[sizeof(struct net_buf)]; \
1212 uint8_t ud[_ud_size]; } __net_buf_align; \
1213 BUILD_ASSERT(_ud_size <= UINT8_MAX); \
1214 BUILD_ASSERT(offsetof(struct net_buf, user_data) == \
1215 offsetof(struct _net_buf_##_name, ud), "Invalid offset"); \
1216 BUILD_ASSERT(__alignof__(struct net_buf) == \
1217 __alignof__(struct _net_buf_##_name), "Invalid alignment"); \
1218 BUILD_ASSERT(sizeof(struct _net_buf_##_name) == \
1219 ROUND_UP(sizeof(struct net_buf) + _ud_size, __alignof__(struct net_buf)), \
1220 "Size cannot be determined"); \
1221 static struct _net_buf_##_name _net_buf_##_name[_count] __noinit
1222
1223extern const struct net_buf_data_alloc net_buf_heap_alloc;
1225
1253#define NET_BUF_POOL_HEAP_DEFINE(_name, _count, _ud_size, _destroy) \
1254 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1255 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1256 NET_BUF_POOL_INITIALIZER(_name, &net_buf_heap_alloc, \
1257 _net_buf_##_name, _count, _ud_size, \
1258 _destroy)
1259
1261
1262struct net_buf_pool_fixed {
1263 uint8_t *data_pool;
1264};
1265
1266extern const struct net_buf_data_cb net_buf_fixed_cb;
1267
1269
1298#define NET_BUF_POOL_FIXED_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1299 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1300 static uint8_t __noinit net_buf_data_##_name[_count][_data_size] __net_buf_align; \
1301 static const struct net_buf_pool_fixed net_buf_fixed_##_name = { \
1302 .data_pool = (uint8_t *)net_buf_data_##_name, \
1303 }; \
1304 static const struct net_buf_data_alloc net_buf_fixed_alloc_##_name = { \
1305 .cb = &net_buf_fixed_cb, \
1306 .alloc_data = (void *)&net_buf_fixed_##_name, \
1307 .max_alloc_size = _data_size, \
1308 }; \
1309 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1310 NET_BUF_POOL_INITIALIZER(_name, &net_buf_fixed_alloc_##_name, \
1311 _net_buf_##_name, _count, _ud_size, \
1312 _destroy)
1313
1315extern const struct net_buf_data_cb net_buf_var_cb;
1317
1342#define NET_BUF_POOL_VAR_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1343 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1344 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1345 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1346 .cb = &net_buf_var_cb, \
1347 .alloc_data = &net_buf_mem_pool_##_name, \
1348 .max_alloc_size = 0, \
1349 }; \
1350 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1351 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1352 _net_buf_##_name, _count, _ud_size, \
1353 _destroy)
1354
1385#define NET_BUF_POOL_VAR_ALIGN_DEFINE(_name, _count, _data_size, _ud_size, \
1386 _destroy, _align) \
1387 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1388 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1389 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1390 .cb = &net_buf_var_cb, \
1391 .alloc_data = &net_buf_mem_pool_##_name, \
1392 .max_alloc_size = 0, \
1393 .alignment = _align, \
1394 }; \
1395 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1396 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1397 _net_buf_##_name, _count, _ud_size, \
1398 _destroy)
1399
1421#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy) \
1422 NET_BUF_POOL_FIXED_DEFINE(_name, _count, _size, _ud_size, _destroy)
1423
1432
1445int net_buf_id(const struct net_buf *buf);
1446
1447#if defined(CONFIG_NET_BUF_POOL_USAGE) || defined(__DOXYGEN__)
1461static inline size_t net_buf_get_available(struct net_buf_pool *pool)
1462{
1463 return (size_t)atomic_get(&pool->avail_count);
1464}
1465
1475static inline size_t net_buf_get_max_used(struct net_buf_pool *pool)
1476{
1477 return (size_t)pool->max_used;
1478}
1479#endif /* defined(CONFIG_NET_BUF_POOL_USAGE) || defined(__DOXYGEN__) */
1480
1495#if defined(CONFIG_NET_BUF_LOG)
1496struct net_buf * __must_check net_buf_alloc_fixed_debug(struct net_buf_pool *pool,
1497 k_timeout_t timeout,
1498 const char *func,
1499 int line);
1500#define net_buf_alloc_fixed(_pool, _timeout) \
1501 net_buf_alloc_fixed_debug(_pool, _timeout, __func__, __LINE__)
1502#else
1503struct net_buf * __must_check net_buf_alloc_fixed(struct net_buf_pool *pool,
1504 k_timeout_t timeout);
1505#endif
1506
1510static inline struct net_buf * __must_check net_buf_alloc(struct net_buf_pool *pool,
1511 k_timeout_t timeout)
1512{
1513 return net_buf_alloc_fixed(pool, timeout);
1514}
1515
1531#if defined(CONFIG_NET_BUF_LOG)
1532struct net_buf * __must_check net_buf_alloc_len_debug(struct net_buf_pool *pool,
1533 size_t size,
1534 k_timeout_t timeout,
1535 const char *func,
1536 int line);
1537#define net_buf_alloc_len(_pool, _size, _timeout) \
1538 net_buf_alloc_len_debug(_pool, _size, _timeout, __func__, __LINE__)
1539#else
1540struct net_buf * __must_check net_buf_alloc_len(struct net_buf_pool *pool,
1541 size_t size,
1542 k_timeout_t timeout);
1543#endif
1544
1564#if defined(CONFIG_NET_BUF_LOG)
1565struct net_buf * __must_check net_buf_alloc_with_data_debug(struct net_buf_pool *pool,
1566 void *data, size_t size,
1567 k_timeout_t timeout,
1568 const char *func, int line);
1569#define net_buf_alloc_with_data(_pool, _data_, _size, _timeout) \
1570 net_buf_alloc_with_data_debug(_pool, _data_, _size, _timeout, \
1571 __func__, __LINE__)
1572#else
1573struct net_buf * __must_check net_buf_alloc_with_data(struct net_buf_pool *pool,
1574 void *data, size_t size,
1575 k_timeout_t timeout);
1576#endif
1577
1587static inline void net_buf_destroy(struct net_buf *buf)
1588{
1589 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id);
1590
1591 if (buf->__buf) {
1592 if (!(buf->flags & NET_BUF_EXTERNAL_DATA)) {
1593 pool->alloc->cb->unref(buf, buf->__buf);
1594 }
1595 buf->__buf = NULL;
1596 }
1597
1598 k_lifo_put(&pool->free, buf);
1599}
1600
1608void net_buf_reset(struct net_buf *buf);
1609
1618void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve);
1619
1626void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf);
1627
1635struct net_buf * __must_check net_buf_slist_get(sys_slist_t *list);
1636
1644#if defined(CONFIG_NET_BUF_LOG)
1645void net_buf_unref_debug(struct net_buf *buf, const char *func, int line);
1646#define net_buf_unref(_buf) \
1647 net_buf_unref_debug(_buf, __func__, __LINE__)
1648#else
1649void net_buf_unref(struct net_buf *buf);
1650#endif
1651
1659struct net_buf * __must_check net_buf_ref(struct net_buf *buf);
1660
1672static inline struct net_buf *__must_check net_buf_take(struct net_buf **orig)
1673{
1674 return (struct net_buf *)atomic_ptr_clear((atomic_ptr_t *)orig);
1675}
1676
1685static inline void net_buf_drop(struct net_buf **orig)
1686{
1687 struct net_buf *buf = net_buf_take(orig);
1688
1689 if (buf != NULL) {
1690 net_buf_unref(buf);
1691 }
1692}
1693
1707struct net_buf * __must_check net_buf_clone(struct net_buf *buf,
1708 k_timeout_t timeout);
1709
1717static inline void * __must_check net_buf_user_data(const struct net_buf *buf)
1718{
1719 return (void *)buf->user_data;
1720}
1721
1731int net_buf_user_data_copy(struct net_buf *dst, const struct net_buf *src);
1732
1741static inline void net_buf_reserve(struct net_buf *buf, size_t reserve)
1742{
1743 net_buf_simple_reserve(&buf->b, reserve);
1744}
1745
1757static inline void *net_buf_add(struct net_buf *buf, size_t len)
1758{
1759 return net_buf_simple_add(&buf->b, len);
1760}
1761
1774static inline void *net_buf_add_mem(struct net_buf *buf, const void *mem,
1775 size_t len)
1776{
1777 return net_buf_simple_add_mem(&buf->b, mem, len);
1778}
1779
1791static inline uint8_t *net_buf_add_u8(struct net_buf *buf, uint8_t val)
1792{
1793 return net_buf_simple_add_u8(&buf->b, val);
1794}
1795
1806static inline void net_buf_add_le16(struct net_buf *buf, uint16_t val)
1807{
1808 net_buf_simple_add_le16(&buf->b, val);
1809}
1810
1821static inline void net_buf_add_be16(struct net_buf *buf, uint16_t val)
1822{
1823 net_buf_simple_add_be16(&buf->b, val);
1824}
1825
1836static inline void net_buf_add_le24(struct net_buf *buf, uint32_t val)
1837{
1838 net_buf_simple_add_le24(&buf->b, val);
1839}
1840
1851static inline void net_buf_add_be24(struct net_buf *buf, uint32_t val)
1852{
1853 net_buf_simple_add_be24(&buf->b, val);
1854}
1855
1866static inline void net_buf_add_le32(struct net_buf *buf, uint32_t val)
1867{
1868 net_buf_simple_add_le32(&buf->b, val);
1869}
1870
1881static inline void net_buf_add_be32(struct net_buf *buf, uint32_t val)
1882{
1883 net_buf_simple_add_be32(&buf->b, val);
1884}
1885
1896static inline void net_buf_add_le40(struct net_buf *buf, uint64_t val)
1897{
1898 net_buf_simple_add_le40(&buf->b, val);
1899}
1900
1911static inline void net_buf_add_be40(struct net_buf *buf, uint64_t val)
1912{
1913 net_buf_simple_add_be40(&buf->b, val);
1914}
1915
1926static inline void net_buf_add_le48(struct net_buf *buf, uint64_t val)
1927{
1928 net_buf_simple_add_le48(&buf->b, val);
1929}
1930
1941static inline void net_buf_add_be48(struct net_buf *buf, uint64_t val)
1942{
1943 net_buf_simple_add_be48(&buf->b, val);
1944}
1945
1956static inline void net_buf_add_le64(struct net_buf *buf, uint64_t val)
1957{
1958 net_buf_simple_add_le64(&buf->b, val);
1959}
1960
1971static inline void net_buf_add_be64(struct net_buf *buf, uint64_t val)
1972{
1973 net_buf_simple_add_be64(&buf->b, val);
1974}
1975
1986static inline void *net_buf_remove_mem(struct net_buf *buf, size_t len)
1987{
1988 return net_buf_simple_remove_mem(&buf->b, len);
1989}
1990
2001static inline uint8_t net_buf_remove_u8(struct net_buf *buf)
2002{
2003 return net_buf_simple_remove_u8(&buf->b);
2004}
2005
2016static inline uint16_t net_buf_remove_le16(struct net_buf *buf)
2017{
2018 return net_buf_simple_remove_le16(&buf->b);
2019}
2020
2031static inline uint16_t net_buf_remove_be16(struct net_buf *buf)
2032{
2033 return net_buf_simple_remove_be16(&buf->b);
2034}
2035
2046static inline uint32_t net_buf_remove_be24(struct net_buf *buf)
2047{
2048 return net_buf_simple_remove_be24(&buf->b);
2049}
2050
2061static inline uint32_t net_buf_remove_le24(struct net_buf *buf)
2062{
2063 return net_buf_simple_remove_le24(&buf->b);
2064}
2065
2076static inline uint32_t net_buf_remove_le32(struct net_buf *buf)
2077{
2078 return net_buf_simple_remove_le32(&buf->b);
2079}
2080
2091static inline uint32_t net_buf_remove_be32(struct net_buf *buf)
2092{
2093 return net_buf_simple_remove_be32(&buf->b);
2094}
2095
2106static inline uint64_t net_buf_remove_le40(struct net_buf *buf)
2107{
2108 return net_buf_simple_remove_le40(&buf->b);
2109}
2110
2121static inline uint64_t net_buf_remove_be40(struct net_buf *buf)
2122{
2123 return net_buf_simple_remove_be40(&buf->b);
2124}
2125
2136static inline uint64_t net_buf_remove_le48(struct net_buf *buf)
2137{
2138 return net_buf_simple_remove_le48(&buf->b);
2139}
2140
2151static inline uint64_t net_buf_remove_be48(struct net_buf *buf)
2152{
2153 return net_buf_simple_remove_be48(&buf->b);
2154}
2155
2166static inline uint64_t net_buf_remove_le64(struct net_buf *buf)
2167{
2168 return net_buf_simple_remove_le64(&buf->b);
2169}
2170
2181static inline uint64_t net_buf_remove_be64(struct net_buf *buf)
2182{
2183 return net_buf_simple_remove_be64(&buf->b);
2184}
2185
2197static inline void *net_buf_push(struct net_buf *buf, size_t len)
2198{
2199 return net_buf_simple_push(&buf->b, len);
2200}
2201
2214static inline void *net_buf_push_mem(struct net_buf *buf, const void *mem,
2215 size_t len)
2216{
2217 return net_buf_simple_push_mem(&buf->b, mem, len);
2218}
2219
2228static inline void net_buf_push_u8(struct net_buf *buf, uint8_t val)
2229{
2230 net_buf_simple_push_u8(&buf->b, val);
2231}
2232
2242static inline void net_buf_push_le16(struct net_buf *buf, uint16_t val)
2243{
2244 net_buf_simple_push_le16(&buf->b, val);
2245}
2246
2256static inline void net_buf_push_be16(struct net_buf *buf, uint16_t val)
2257{
2258 net_buf_simple_push_be16(&buf->b, val);
2259}
2260
2270static inline void net_buf_push_le24(struct net_buf *buf, uint32_t val)
2271{
2272 net_buf_simple_push_le24(&buf->b, val);
2273}
2274
2284static inline void net_buf_push_be24(struct net_buf *buf, uint32_t val)
2285{
2286 net_buf_simple_push_be24(&buf->b, val);
2287}
2288
2298static inline void net_buf_push_le32(struct net_buf *buf, uint32_t val)
2299{
2300 net_buf_simple_push_le32(&buf->b, val);
2301}
2302
2312static inline void net_buf_push_be32(struct net_buf *buf, uint32_t val)
2313{
2314 net_buf_simple_push_be32(&buf->b, val);
2315}
2316
2326static inline void net_buf_push_le40(struct net_buf *buf, uint64_t val)
2327{
2328 net_buf_simple_push_le40(&buf->b, val);
2329}
2330
2340static inline void net_buf_push_be40(struct net_buf *buf, uint64_t val)
2341{
2342 net_buf_simple_push_be40(&buf->b, val);
2343}
2344
2354static inline void net_buf_push_le48(struct net_buf *buf, uint64_t val)
2355{
2356 net_buf_simple_push_le48(&buf->b, val);
2357}
2358
2368static inline void net_buf_push_be48(struct net_buf *buf, uint64_t val)
2369{
2370 net_buf_simple_push_be48(&buf->b, val);
2371}
2372
2382static inline void net_buf_push_le64(struct net_buf *buf, uint64_t val)
2383{
2384 net_buf_simple_push_le64(&buf->b, val);
2385}
2386
2396static inline void net_buf_push_be64(struct net_buf *buf, uint64_t val)
2397{
2398 net_buf_simple_push_be64(&buf->b, val);
2399}
2400
2412static inline void *net_buf_pull(struct net_buf *buf, size_t len)
2413{
2414 return net_buf_simple_pull(&buf->b, len);
2415}
2416
2428static inline void *net_buf_pull_mem(struct net_buf *buf, size_t len)
2429{
2430 return net_buf_simple_pull_mem(&buf->b, len);
2431}
2432
2443static inline uint8_t net_buf_pull_u8(struct net_buf *buf)
2444{
2445 return net_buf_simple_pull_u8(&buf->b);
2446}
2447
2458static inline uint16_t net_buf_pull_le16(struct net_buf *buf)
2459{
2460 return net_buf_simple_pull_le16(&buf->b);
2461}
2462
2473static inline uint16_t net_buf_pull_be16(struct net_buf *buf)
2474{
2475 return net_buf_simple_pull_be16(&buf->b);
2476}
2477
2488static inline uint32_t net_buf_pull_le24(struct net_buf *buf)
2489{
2490 return net_buf_simple_pull_le24(&buf->b);
2491}
2492
2503static inline uint32_t net_buf_pull_be24(struct net_buf *buf)
2504{
2505 return net_buf_simple_pull_be24(&buf->b);
2506}
2507
2518static inline uint32_t net_buf_pull_le32(struct net_buf *buf)
2519{
2520 return net_buf_simple_pull_le32(&buf->b);
2521}
2522
2533static inline uint32_t net_buf_pull_be32(struct net_buf *buf)
2534{
2535 return net_buf_simple_pull_be32(&buf->b);
2536}
2537
2548static inline uint64_t net_buf_pull_le40(struct net_buf *buf)
2549{
2550 return net_buf_simple_pull_le40(&buf->b);
2551}
2552
2563static inline uint64_t net_buf_pull_be40(struct net_buf *buf)
2564{
2565 return net_buf_simple_pull_be40(&buf->b);
2566}
2567
2578static inline uint64_t net_buf_pull_le48(struct net_buf *buf)
2579{
2580 return net_buf_simple_pull_le48(&buf->b);
2581}
2582
2593static inline uint64_t net_buf_pull_be48(struct net_buf *buf)
2594{
2595 return net_buf_simple_pull_be48(&buf->b);
2596}
2597
2608static inline uint64_t net_buf_pull_le64(struct net_buf *buf)
2609{
2610 return net_buf_simple_pull_le64(&buf->b);
2611}
2612
2623static inline uint64_t net_buf_pull_be64(struct net_buf *buf)
2624{
2625 return net_buf_simple_pull_be64(&buf->b);
2626}
2627
2637static inline size_t net_buf_tailroom(const struct net_buf *buf)
2638{
2639 return net_buf_simple_tailroom(&buf->b);
2640}
2641
2651static inline size_t net_buf_headroom(const struct net_buf *buf)
2652{
2653 return net_buf_simple_headroom(&buf->b);
2654}
2655
2665static inline uint16_t net_buf_max_len(const struct net_buf *buf)
2666{
2667 return net_buf_simple_max_len(&buf->b);
2668}
2669
2679static inline uint8_t *net_buf_tail(const struct net_buf *buf)
2680{
2681 return net_buf_simple_tail(&buf->b);
2682}
2683
2690
2702void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag);
2703
2718struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag);
2719
2729#if defined(CONFIG_NET_BUF_LOG)
2730struct net_buf *net_buf_frag_del_debug(struct net_buf *parent,
2731 struct net_buf *frag,
2732 const char *func, int line);
2733#define net_buf_frag_del(_parent, _frag) \
2734 net_buf_frag_del_debug(_parent, _frag, __func__, __LINE__)
2735#else
2736struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag);
2737#endif
2738
2754size_t net_buf_linearize(void *dst, size_t dst_len,
2755 const struct net_buf *src, size_t offset, size_t len);
2756
2771typedef struct net_buf * __must_check (*net_buf_allocator_cb)(k_timeout_t timeout,
2772 void *user_data);
2773
2795size_t net_buf_append_bytes(struct net_buf *buf, size_t len,
2796 const void *value, k_timeout_t timeout,
2797 net_buf_allocator_cb allocate_cb, void *user_data);
2798
2813size_t net_buf_data_match(const struct net_buf *buf, size_t offset, const void *data, size_t len);
2814
2830static inline struct net_buf *net_buf_skip(struct net_buf *buf, size_t len)
2831{
2832 while (buf && len--) {
2833 net_buf_pull_u8(buf);
2834 if (!buf->len) {
2835 buf = net_buf_frag_del(NULL, buf);
2836 }
2837 }
2838
2839 return buf;
2840}
2841
2852static inline size_t net_buf_frags_len(const struct net_buf *buf)
2853{
2854 size_t bytes = 0;
2855
2856 while (buf) {
2857 bytes += buf->len;
2858 buf = buf->frags;
2859 }
2860
2861 return bytes;
2862}
2863
2867
2868#ifdef __cplusplus
2869}
2870#endif
2871
2872#endif /* ZEPHYR_INCLUDE_NET_BUF_H_ */
long atomic_t
Atomic integer variable.
Definition atomic_types.h:31
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:46
#define k_lifo_put(lifo, data)
Add an element to a LIFO queue.
Definition kernel.h:3244
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:142
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:2563
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:1971
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:2136
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:1851
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:2830
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:1757
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:1836
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:2548
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:2623
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:2396
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:2166
static void net_buf_simple_reset(struct net_buf_simple *buf)
Reset buffer.
Definition net_buf.h:172
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:1672
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:2340
static struct net_buf * net_buf_alloc(struct net_buf_pool *pool, k_timeout_t timeout)
Definition net_buf.h:1510
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:1881
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:2106
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 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:2031
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:2518
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:2533
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:1821
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:1896
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:2665
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:2593
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:1685
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:2256
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:2046
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:1911
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:2443
static void net_buf_destroy(struct net_buf *buf)
Destroy buffer from custom destroy callback.
Definition net_buf.h:1587
static size_t net_buf_simple_tailroom(const struct net_buf_simple *buf)
Check buffer tailroom.
Definition net_buf.h:933
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:947
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:2214
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:2578
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:2354
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:2488
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:1791
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:2284
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:2270
static void net_buf_reserve(struct net_buf *buf, size_t reserve)
Initialize buffer with the given headroom.
Definition net_buf.h:1741
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:2181
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 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:2503
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:1941
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:2061
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:2228
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:2197
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:2473
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:2298
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:2608
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:2771
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:1461
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:905
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:2151
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:1006
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:2016
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:2242
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:974
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:2368
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:1956
static size_t net_buf_headroom(const struct net_buf *buf)
Check buffer headroom.
Definition net_buf.h:2651
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:2091
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:1986
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:1774
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:2382
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:1475
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:2001
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:919
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:1806
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:2121
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:2312
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:1866
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:2076
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition net_buf.h:2852
static size_t net_buf_tailroom(const struct net_buf *buf)
Check buffer tailroom.
Definition net_buf.h:2637
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:2458
static uint8_t * net_buf_tail(const struct net_buf *buf)
Get the tail pointer for a buffer.
Definition net_buf.h:2679
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:2428
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:990
static void * net_buf_pull(struct net_buf *buf, size_t len)
Remove data from the beginning of the buffer.
Definition net_buf.h:2412
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:2326
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:1926
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:1717
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:52
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:42
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:3186
Kernel Spin Lock.
Definition spinlock.h:45
Kernel timeout type.
Definition clock.h:65
Network buffer pool representation.
Definition net_buf.h:1151
void(*const destroy)(struct net_buf *buf)
Optional destroy callback when buffer is freed.
Definition net_buf.h:1182
uint16_t uninit_count
Number of uninitialized buffers.
Definition net_buf.h:1162
uint8_t user_data_size
Size of user data allocated to this pool.
Definition net_buf.h:1165
const uint16_t buf_count
Number of buffers in pool.
Definition net_buf.h:1159
const struct net_buf_data_alloc * alloc
Data allocation handlers.
Definition net_buf.h:1185
struct k_lifo free
LIFO to place the buffer into when free.
Definition net_buf.h:1153
struct k_spinlock lock
To prevent concurrent access/modifications.
Definition net_buf.h:1156
Parsing state of a buffer.
Definition net_buf.h:959
uint16_t offset
Offset of the data pointer from the beginning of the storage.
Definition net_buf.h:961
uint16_t len
Length of data.
Definition net_buf.h:963
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:101
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:98
Network buffer representation.
Definition net_buf.h:1015
uint16_t size
Amount of data that this buffer can store.
Definition net_buf.h:1110
struct net_buf * frags
Fragments associated with this buffer.
Definition net_buf.h:1020
uint8_t ref
Reference count.
Definition net_buf.h:1083
uint8_t pool_id
Where the buffer should go when freed up.
Definition net_buf.h:1089
sys_snode_t node
Allow placing the buffer into sys_slist_t.
Definition net_buf.h:1017
uint8_t user_data_size
Size of user data on this buffer.
Definition net_buf.h:1092
uint8_t flags
Bit-field of buffer flags.
Definition net_buf.h:1086
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1104
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1125
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1107
Iterable sections helpers.
Misc utilities.