Zephyr Project API 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
969static inline bool net_buf_simple_is_valid(const struct net_buf_simple *buf)
970{
971 size_t headroom;
972
973 if (buf == NULL || buf->__buf == NULL || buf->data < buf->__buf) {
974 return false;
975 }
976
977 headroom = net_buf_simple_headroom(buf);
978 if (headroom > buf->size) {
979 return false;
980 }
981
982 return (size_t)buf->len <= (size_t)(buf->size - headroom);
983}
984
998
1007static inline void net_buf_simple_save(const struct net_buf_simple *buf,
1009{
1010 state->offset = (uint16_t)net_buf_simple_headroom(buf);
1011 state->len = buf->len;
1012}
1013
1023static inline void net_buf_simple_restore(struct net_buf_simple *buf,
1025{
1026 buf->data = buf->__buf + state->offset;
1027 buf->len = state->len;
1028}
1029
1039#define NET_BUF_EXTERNAL_DATA BIT(0)
1040
1048struct net_buf {
1051
1054
1086 union {
1088 atomic_t ref_word;
1090 struct {
1091#if defined(CONFIG_BIG_ENDIAN)
1092 /* atomic_t is typedef'd as long (BUILD_ASSERTed in
1093 * lib/net_buf/buf.c); on a 64-bit big-endian build
1094 * the byte struct needs 4 bytes of padding so that
1095 * `ref` lands on the least-significant byte of
1096 * ref_word.
1097 */
1098#if (__SIZEOF_LONG__ == 8)
1100 uint8_t _ref_word_pad[4];
1102#endif
1105
1108
1110 uint8_t flags;
1111
1113 uint8_t ref;
1114#else
1117
1120
1123
1126#endif
1127 };
1128 };
1129
1133 union {
1134 /* The ABI of this struct must match net_buf_simple */
1135 struct {
1138
1141
1144
1149 uint8_t *__buf;
1150 };
1151
1153 struct net_buf_simple b;
1155 };
1156
1158 uint8_t user_data[] __net_buf_align;
1159};
1160
1162
1163struct net_buf_data_cb {
1164 uint8_t * __must_check (*alloc)(struct net_buf *buf, size_t *size,
1165 k_timeout_t timeout);
1166 uint8_t * __must_check (*ref)(struct net_buf *buf, uint8_t *data);
1167 void (*unref)(struct net_buf *buf, uint8_t *data);
1168};
1169
1170struct net_buf_data_alloc {
1171 const struct net_buf_data_cb *cb;
1172 void *alloc_data;
1173 size_t max_alloc_size;
1174 size_t alignment;
1175};
1176
1178
1186 struct k_lifo free;
1187
1190
1193
1196
1199
1200#if defined(CONFIG_NET_BUF_POOL_USAGE)
1202 atomic_t avail_count;
1203
1205 const uint16_t pool_size;
1206
1208 uint16_t max_used;
1209
1211 const char *name;
1212#endif /* CONFIG_NET_BUF_POOL_USAGE */
1213
1215 void (*const destroy)(struct net_buf *buf);
1216
1218 const struct net_buf_data_alloc *alloc;
1219
1221 struct net_buf * const __bufs;
1222};
1223
1225#define NET_BUF_POOL_USAGE_INIT(_pool, _count) \
1226 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.avail_count = ATOMIC_INIT(_count),)) \
1227 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.max_used = 0,)) \
1228 IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.name = STRINGIFY(_pool),))
1229
1230#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \
1231 { \
1232 .free = Z_LIFO_INITIALIZER(_pool.free), \
1233 .lock = { }, \
1234 .buf_count = _count, \
1235 .uninit_count = _count, \
1236 .user_data_size = _ud_size, \
1237 NET_BUF_POOL_USAGE_INIT(_pool, _count) \
1238 .destroy = _destroy, \
1239 .alloc = _alloc, \
1240 .__bufs = (struct net_buf *)_bufs, \
1241 }
1242
1243#define _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size) \
1244 struct _net_buf_##_name { uint8_t b[sizeof(struct net_buf)]; \
1245 uint8_t ud[_ud_size]; } __net_buf_align; \
1246 BUILD_ASSERT(_ud_size <= UINT8_MAX); \
1247 BUILD_ASSERT(offsetof(struct net_buf, user_data) == \
1248 offsetof(struct _net_buf_##_name, ud), "Invalid offset"); \
1249 BUILD_ASSERT(__alignof__(struct net_buf) == \
1250 __alignof__(struct _net_buf_##_name), "Invalid alignment"); \
1251 BUILD_ASSERT(sizeof(struct _net_buf_##_name) == \
1252 ROUND_UP(sizeof(struct net_buf) + _ud_size, __alignof__(struct net_buf)), \
1253 "Size cannot be determined"); \
1254 static struct _net_buf_##_name _net_buf_##_name[_count] __noinit
1255
1256extern const struct net_buf_data_alloc net_buf_heap_alloc;
1258
1286#define NET_BUF_POOL_HEAP_DEFINE(_name, _count, _ud_size, _destroy) \
1287 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1288 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1289 NET_BUF_POOL_INITIALIZER(_name, &net_buf_heap_alloc, \
1290 _net_buf_##_name, _count, _ud_size, \
1291 _destroy)
1292
1294
1295struct net_buf_pool_fixed {
1296 uint8_t *data_pool;
1297};
1298
1299extern const struct net_buf_data_cb net_buf_fixed_cb;
1300
1302
1331#define NET_BUF_POOL_FIXED_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1332 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1333 static uint8_t __noinit net_buf_data_##_name[_count][_data_size] __net_buf_align; \
1334 static const struct net_buf_pool_fixed net_buf_fixed_##_name = { \
1335 .data_pool = (uint8_t *)net_buf_data_##_name, \
1336 }; \
1337 static const struct net_buf_data_alloc net_buf_fixed_alloc_##_name = { \
1338 .cb = &net_buf_fixed_cb, \
1339 .alloc_data = (void *)&net_buf_fixed_##_name, \
1340 .max_alloc_size = _data_size, \
1341 }; \
1342 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1343 NET_BUF_POOL_INITIALIZER(_name, &net_buf_fixed_alloc_##_name, \
1344 _net_buf_##_name, _count, _ud_size, \
1345 _destroy)
1346
1348extern const struct net_buf_data_cb net_buf_var_cb;
1350
1375#define NET_BUF_POOL_VAR_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1376 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1377 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1378 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1379 .cb = &net_buf_var_cb, \
1380 .alloc_data = &net_buf_mem_pool_##_name, \
1381 .max_alloc_size = 0, \
1382 }; \
1383 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1384 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1385 _net_buf_##_name, _count, _ud_size, \
1386 _destroy)
1387
1418#define NET_BUF_POOL_VAR_ALIGN_DEFINE(_name, _count, _data_size, _ud_size, \
1419 _destroy, _align) \
1420 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1421 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1422 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1423 .cb = &net_buf_var_cb, \
1424 .alloc_data = &net_buf_mem_pool_##_name, \
1425 .max_alloc_size = 0, \
1426 .alignment = _align, \
1427 }; \
1428 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1429 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1430 _net_buf_##_name, _count, _ud_size, \
1431 _destroy)
1432
1454#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy) \
1455 NET_BUF_POOL_FIXED_DEFINE(_name, _count, _size, _ud_size, _destroy)
1456
1465
1478int net_buf_id(const struct net_buf *buf);
1479
1480#if defined(CONFIG_NET_BUF_POOL_USAGE) || defined(__DOXYGEN__)
1494static inline size_t net_buf_get_available(struct net_buf_pool *pool)
1495{
1496 return (size_t)atomic_get(&pool->avail_count);
1497}
1498
1508static inline size_t net_buf_get_max_used(struct net_buf_pool *pool)
1509{
1510 return (size_t)pool->max_used;
1511}
1512#endif /* defined(CONFIG_NET_BUF_POOL_USAGE) || defined(__DOXYGEN__) */
1513
1528#if defined(CONFIG_NET_BUF_LOG)
1529struct net_buf * __must_check net_buf_alloc_fixed_debug(struct net_buf_pool *pool,
1530 k_timeout_t timeout,
1531 const char *func,
1532 int line);
1533#define net_buf_alloc_fixed(_pool, _timeout) \
1534 net_buf_alloc_fixed_debug(_pool, _timeout, __func__, __LINE__)
1535#else
1536struct net_buf * __must_check net_buf_alloc_fixed(struct net_buf_pool *pool,
1537 k_timeout_t timeout);
1538#endif
1539
1543static inline struct net_buf * __must_check net_buf_alloc(struct net_buf_pool *pool,
1544 k_timeout_t timeout)
1545{
1546 return net_buf_alloc_fixed(pool, timeout);
1547}
1548
1564#if defined(CONFIG_NET_BUF_LOG)
1565struct net_buf * __must_check net_buf_alloc_len_debug(struct net_buf_pool *pool,
1566 size_t size,
1567 k_timeout_t timeout,
1568 const char *func,
1569 int line);
1570#define net_buf_alloc_len(_pool, _size, _timeout) \
1571 net_buf_alloc_len_debug(_pool, _size, _timeout, __func__, __LINE__)
1572#else
1573struct net_buf * __must_check net_buf_alloc_len(struct net_buf_pool *pool,
1574 size_t size,
1575 k_timeout_t timeout);
1576#endif
1577
1597#if defined(CONFIG_NET_BUF_LOG)
1598struct net_buf * __must_check net_buf_alloc_with_data_debug(struct net_buf_pool *pool,
1599 void *data, size_t size,
1600 k_timeout_t timeout,
1601 const char *func, int line);
1602#define net_buf_alloc_with_data(_pool, _data_, _size, _timeout) \
1603 net_buf_alloc_with_data_debug(_pool, _data_, _size, _timeout, \
1604 __func__, __LINE__)
1605#else
1606struct net_buf * __must_check net_buf_alloc_with_data(struct net_buf_pool *pool,
1607 void *data, size_t size,
1608 k_timeout_t timeout);
1609#endif
1610
1620static inline void net_buf_destroy(struct net_buf *buf)
1621{
1622 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id);
1623
1624 if (buf->__buf) {
1625 if (!(buf->flags & NET_BUF_EXTERNAL_DATA)) {
1626 pool->alloc->cb->unref(buf, buf->__buf);
1627 }
1628 buf->__buf = NULL;
1629 }
1630
1631 k_lifo_put(&pool->free, buf);
1632}
1633
1641void net_buf_reset(struct net_buf *buf);
1642
1651void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve);
1652
1659void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf);
1660
1668struct net_buf * __must_check net_buf_slist_get(sys_slist_t *list);
1669
1677#if defined(CONFIG_NET_BUF_LOG)
1678void net_buf_unref_debug(struct net_buf *buf, const char *func, int line);
1679#define net_buf_unref(_buf) \
1680 net_buf_unref_debug(_buf, __func__, __LINE__)
1681#else
1682void net_buf_unref(struct net_buf *buf);
1683#endif
1684
1692struct net_buf * __must_check net_buf_ref(struct net_buf *buf);
1693
1705static inline struct net_buf *__must_check net_buf_take(struct net_buf **orig)
1706{
1707 return (struct net_buf *)atomic_ptr_clear((atomic_ptr_t *)orig);
1708}
1709
1718static inline void net_buf_drop(struct net_buf **orig)
1719{
1720 struct net_buf *buf = net_buf_take(orig);
1721
1722 if (buf != NULL) {
1723 net_buf_unref(buf);
1724 }
1725}
1726
1740struct net_buf * __must_check net_buf_clone(struct net_buf *buf,
1741 k_timeout_t timeout);
1742
1750static inline void * __must_check net_buf_user_data(const struct net_buf *buf)
1751{
1752 return (void *)buf->user_data;
1753}
1754
1764int net_buf_user_data_copy(struct net_buf *dst, const struct net_buf *src);
1765
1774static inline void net_buf_reserve(struct net_buf *buf, size_t reserve)
1775{
1776 net_buf_simple_reserve(&buf->b, reserve);
1777}
1778
1790static inline void *net_buf_add(struct net_buf *buf, size_t len)
1791{
1792 return net_buf_simple_add(&buf->b, len);
1793}
1794
1807static inline void *net_buf_add_mem(struct net_buf *buf, const void *mem,
1808 size_t len)
1809{
1810 return net_buf_simple_add_mem(&buf->b, mem, len);
1811}
1812
1824static inline uint8_t *net_buf_add_u8(struct net_buf *buf, uint8_t val)
1825{
1826 return net_buf_simple_add_u8(&buf->b, val);
1827}
1828
1839static inline void net_buf_add_le16(struct net_buf *buf, uint16_t val)
1840{
1841 net_buf_simple_add_le16(&buf->b, val);
1842}
1843
1854static inline void net_buf_add_be16(struct net_buf *buf, uint16_t val)
1855{
1856 net_buf_simple_add_be16(&buf->b, val);
1857}
1858
1869static inline void net_buf_add_le24(struct net_buf *buf, uint32_t val)
1870{
1871 net_buf_simple_add_le24(&buf->b, val);
1872}
1873
1884static inline void net_buf_add_be24(struct net_buf *buf, uint32_t val)
1885{
1886 net_buf_simple_add_be24(&buf->b, val);
1887}
1888
1899static inline void net_buf_add_le32(struct net_buf *buf, uint32_t val)
1900{
1901 net_buf_simple_add_le32(&buf->b, val);
1902}
1903
1914static inline void net_buf_add_be32(struct net_buf *buf, uint32_t val)
1915{
1916 net_buf_simple_add_be32(&buf->b, val);
1917}
1918
1929static inline void net_buf_add_le40(struct net_buf *buf, uint64_t val)
1930{
1931 net_buf_simple_add_le40(&buf->b, val);
1932}
1933
1944static inline void net_buf_add_be40(struct net_buf *buf, uint64_t val)
1945{
1946 net_buf_simple_add_be40(&buf->b, val);
1947}
1948
1959static inline void net_buf_add_le48(struct net_buf *buf, uint64_t val)
1960{
1961 net_buf_simple_add_le48(&buf->b, val);
1962}
1963
1974static inline void net_buf_add_be48(struct net_buf *buf, uint64_t val)
1975{
1976 net_buf_simple_add_be48(&buf->b, val);
1977}
1978
1989static inline void net_buf_add_le64(struct net_buf *buf, uint64_t val)
1990{
1991 net_buf_simple_add_le64(&buf->b, val);
1992}
1993
2004static inline void net_buf_add_be64(struct net_buf *buf, uint64_t val)
2005{
2006 net_buf_simple_add_be64(&buf->b, val);
2007}
2008
2019static inline void *net_buf_remove_mem(struct net_buf *buf, size_t len)
2020{
2021 return net_buf_simple_remove_mem(&buf->b, len);
2022}
2023
2034static inline uint8_t net_buf_remove_u8(struct net_buf *buf)
2035{
2036 return net_buf_simple_remove_u8(&buf->b);
2037}
2038
2049static inline uint16_t net_buf_remove_le16(struct net_buf *buf)
2050{
2051 return net_buf_simple_remove_le16(&buf->b);
2052}
2053
2064static inline uint16_t net_buf_remove_be16(struct net_buf *buf)
2065{
2066 return net_buf_simple_remove_be16(&buf->b);
2067}
2068
2079static inline uint32_t net_buf_remove_be24(struct net_buf *buf)
2080{
2081 return net_buf_simple_remove_be24(&buf->b);
2082}
2083
2094static inline uint32_t net_buf_remove_le24(struct net_buf *buf)
2095{
2096 return net_buf_simple_remove_le24(&buf->b);
2097}
2098
2109static inline uint32_t net_buf_remove_le32(struct net_buf *buf)
2110{
2111 return net_buf_simple_remove_le32(&buf->b);
2112}
2113
2124static inline uint32_t net_buf_remove_be32(struct net_buf *buf)
2125{
2126 return net_buf_simple_remove_be32(&buf->b);
2127}
2128
2139static inline uint64_t net_buf_remove_le40(struct net_buf *buf)
2140{
2141 return net_buf_simple_remove_le40(&buf->b);
2142}
2143
2154static inline uint64_t net_buf_remove_be40(struct net_buf *buf)
2155{
2156 return net_buf_simple_remove_be40(&buf->b);
2157}
2158
2169static inline uint64_t net_buf_remove_le48(struct net_buf *buf)
2170{
2171 return net_buf_simple_remove_le48(&buf->b);
2172}
2173
2184static inline uint64_t net_buf_remove_be48(struct net_buf *buf)
2185{
2186 return net_buf_simple_remove_be48(&buf->b);
2187}
2188
2199static inline uint64_t net_buf_remove_le64(struct net_buf *buf)
2200{
2201 return net_buf_simple_remove_le64(&buf->b);
2202}
2203
2214static inline uint64_t net_buf_remove_be64(struct net_buf *buf)
2215{
2216 return net_buf_simple_remove_be64(&buf->b);
2217}
2218
2230static inline void *net_buf_push(struct net_buf *buf, size_t len)
2231{
2232 return net_buf_simple_push(&buf->b, len);
2233}
2234
2247static inline void *net_buf_push_mem(struct net_buf *buf, const void *mem,
2248 size_t len)
2249{
2250 return net_buf_simple_push_mem(&buf->b, mem, len);
2251}
2252
2261static inline void net_buf_push_u8(struct net_buf *buf, uint8_t val)
2262{
2263 net_buf_simple_push_u8(&buf->b, val);
2264}
2265
2275static inline void net_buf_push_le16(struct net_buf *buf, uint16_t val)
2276{
2277 net_buf_simple_push_le16(&buf->b, val);
2278}
2279
2289static inline void net_buf_push_be16(struct net_buf *buf, uint16_t val)
2290{
2291 net_buf_simple_push_be16(&buf->b, val);
2292}
2293
2303static inline void net_buf_push_le24(struct net_buf *buf, uint32_t val)
2304{
2305 net_buf_simple_push_le24(&buf->b, val);
2306}
2307
2317static inline void net_buf_push_be24(struct net_buf *buf, uint32_t val)
2318{
2319 net_buf_simple_push_be24(&buf->b, val);
2320}
2321
2331static inline void net_buf_push_le32(struct net_buf *buf, uint32_t val)
2332{
2333 net_buf_simple_push_le32(&buf->b, val);
2334}
2335
2345static inline void net_buf_push_be32(struct net_buf *buf, uint32_t val)
2346{
2347 net_buf_simple_push_be32(&buf->b, val);
2348}
2349
2359static inline void net_buf_push_le40(struct net_buf *buf, uint64_t val)
2360{
2361 net_buf_simple_push_le40(&buf->b, val);
2362}
2363
2373static inline void net_buf_push_be40(struct net_buf *buf, uint64_t val)
2374{
2375 net_buf_simple_push_be40(&buf->b, val);
2376}
2377
2387static inline void net_buf_push_le48(struct net_buf *buf, uint64_t val)
2388{
2389 net_buf_simple_push_le48(&buf->b, val);
2390}
2391
2401static inline void net_buf_push_be48(struct net_buf *buf, uint64_t val)
2402{
2403 net_buf_simple_push_be48(&buf->b, val);
2404}
2405
2415static inline void net_buf_push_le64(struct net_buf *buf, uint64_t val)
2416{
2417 net_buf_simple_push_le64(&buf->b, val);
2418}
2419
2429static inline void net_buf_push_be64(struct net_buf *buf, uint64_t val)
2430{
2431 net_buf_simple_push_be64(&buf->b, val);
2432}
2433
2445static inline void *net_buf_pull(struct net_buf *buf, size_t len)
2446{
2447 return net_buf_simple_pull(&buf->b, len);
2448}
2449
2461static inline void *net_buf_pull_mem(struct net_buf *buf, size_t len)
2462{
2463 return net_buf_simple_pull_mem(&buf->b, len);
2464}
2465
2476static inline uint8_t net_buf_pull_u8(struct net_buf *buf)
2477{
2478 return net_buf_simple_pull_u8(&buf->b);
2479}
2480
2491static inline uint16_t net_buf_pull_le16(struct net_buf *buf)
2492{
2493 return net_buf_simple_pull_le16(&buf->b);
2494}
2495
2506static inline uint16_t net_buf_pull_be16(struct net_buf *buf)
2507{
2508 return net_buf_simple_pull_be16(&buf->b);
2509}
2510
2521static inline uint32_t net_buf_pull_le24(struct net_buf *buf)
2522{
2523 return net_buf_simple_pull_le24(&buf->b);
2524}
2525
2536static inline uint32_t net_buf_pull_be24(struct net_buf *buf)
2537{
2538 return net_buf_simple_pull_be24(&buf->b);
2539}
2540
2551static inline uint32_t net_buf_pull_le32(struct net_buf *buf)
2552{
2553 return net_buf_simple_pull_le32(&buf->b);
2554}
2555
2566static inline uint32_t net_buf_pull_be32(struct net_buf *buf)
2567{
2568 return net_buf_simple_pull_be32(&buf->b);
2569}
2570
2581static inline uint64_t net_buf_pull_le40(struct net_buf *buf)
2582{
2583 return net_buf_simple_pull_le40(&buf->b);
2584}
2585
2596static inline uint64_t net_buf_pull_be40(struct net_buf *buf)
2597{
2598 return net_buf_simple_pull_be40(&buf->b);
2599}
2600
2611static inline uint64_t net_buf_pull_le48(struct net_buf *buf)
2612{
2613 return net_buf_simple_pull_le48(&buf->b);
2614}
2615
2626static inline uint64_t net_buf_pull_be48(struct net_buf *buf)
2627{
2628 return net_buf_simple_pull_be48(&buf->b);
2629}
2630
2641static inline uint64_t net_buf_pull_le64(struct net_buf *buf)
2642{
2643 return net_buf_simple_pull_le64(&buf->b);
2644}
2645
2656static inline uint64_t net_buf_pull_be64(struct net_buf *buf)
2657{
2658 return net_buf_simple_pull_be64(&buf->b);
2659}
2660
2670static inline size_t net_buf_tailroom(const struct net_buf *buf)
2671{
2672 return net_buf_simple_tailroom(&buf->b);
2673}
2674
2684static inline size_t net_buf_headroom(const struct net_buf *buf)
2685{
2686 return net_buf_simple_headroom(&buf->b);
2687}
2688
2698static inline uint16_t net_buf_max_len(const struct net_buf *buf)
2699{
2700 return net_buf_simple_max_len(&buf->b);
2701}
2702
2718static inline bool net_buf_is_valid(const struct net_buf *buf)
2719{
2720 return buf != NULL && buf->ref > 0 && net_buf_simple_is_valid(&buf->b);
2721}
2722
2732static inline uint8_t *net_buf_tail(const struct net_buf *buf)
2733{
2734 return net_buf_simple_tail(&buf->b);
2735}
2736
2743
2755void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag);
2756
2771struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag);
2772
2782#if defined(CONFIG_NET_BUF_LOG)
2783struct net_buf *net_buf_frag_del_debug(struct net_buf *parent,
2784 struct net_buf *frag,
2785 const char *func, int line);
2786#define net_buf_frag_del(_parent, _frag) \
2787 net_buf_frag_del_debug(_parent, _frag, __func__, __LINE__)
2788#else
2789struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag);
2790#endif
2791
2807size_t net_buf_linearize(void *dst, size_t dst_len,
2808 const struct net_buf *src, size_t offset, size_t len);
2809
2824typedef struct net_buf * __must_check (*net_buf_allocator_cb)(k_timeout_t timeout,
2825 void *user_data);
2826
2848size_t net_buf_append_bytes(struct net_buf *buf, size_t len,
2849 const void *value, k_timeout_t timeout,
2850 net_buf_allocator_cb allocate_cb, void *user_data);
2851
2866size_t net_buf_data_match(const struct net_buf *buf, size_t offset, const void *data, size_t len);
2867
2883static inline struct net_buf *net_buf_skip(struct net_buf *buf, size_t len)
2884{
2885 while (buf && len--) {
2886 net_buf_pull_u8(buf);
2887 if (!buf->len) {
2888 buf = net_buf_frag_del(NULL, buf);
2889 }
2890 }
2891
2892 return buf;
2893}
2894
2905static inline size_t net_buf_frags_len(const struct net_buf *buf)
2906{
2907 size_t bytes = 0;
2908
2909 while (buf) {
2910 bytes += buf->len;
2911 buf = buf->frags;
2912 }
2913
2914 return bytes;
2915}
2916
2920
2921#ifdef __cplusplus
2922}
2923#endif
2924
2925#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:3338
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:2596
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:2004
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:2169
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:1884
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:2883
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:1790
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:1869
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:2581
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:2656
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:2429
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:2199
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:1705
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:2373
static struct net_buf * net_buf_alloc(struct net_buf_pool *pool, k_timeout_t timeout)
Definition net_buf.h:1543
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:1914
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:2139
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:969
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:2064
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:2551
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:2566
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:1854
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:1929
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:2698
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:2626
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:1718
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:2289
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:2079
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:1944
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:2476
static void net_buf_destroy(struct net_buf *buf)
Destroy buffer from custom destroy callback.
Definition net_buf.h:1620
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:2247
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:2611
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:2387
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:2521
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:1824
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:2317
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:2303
static void net_buf_reserve(struct net_buf *buf, size_t reserve)
Initialize buffer with the given headroom.
Definition net_buf.h:1774
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:2214
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:2718
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:2536
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:1974
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:2094
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:2261
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:2230
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:2506
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:2331
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:2641
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:2824
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:1494
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:2184
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:1039
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:2049
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:2275
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:1007
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:2401
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:1989
static size_t net_buf_headroom(const struct net_buf *buf)
Check buffer headroom.
Definition net_buf.h:2684
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:2124
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:2019
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:1807
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:2415
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:1508
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:2034
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:1839
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:2154
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:2345
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:1899
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:2109
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition net_buf.h:2905
static size_t net_buf_tailroom(const struct net_buf *buf)
Check buffer tailroom.
Definition net_buf.h:2670
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:2491
static uint8_t * net_buf_tail(const struct net_buf *buf)
Get the tail pointer for a buffer.
Definition net_buf.h:2732
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:2461
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:1023
static void * net_buf_pull(struct net_buf *buf, size_t len)
Remove data from the beginning of the buffer.
Definition net_buf.h:2445
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:2359
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:1959
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:1750
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 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:3280
Kernel Spin Lock.
Definition spinlock.h:45
Kernel timeout type.
Definition clock.h:65
Network buffer pool representation.
Definition net_buf.h:1184
void(*const destroy)(struct net_buf *buf)
Optional destroy callback when buffer is freed.
Definition net_buf.h:1215
uint16_t uninit_count
Number of uninitialized buffers.
Definition net_buf.h:1195
uint8_t user_data_size
Size of user data allocated to this pool.
Definition net_buf.h:1198
const uint16_t buf_count
Number of buffers in pool.
Definition net_buf.h:1192
const struct net_buf_data_alloc * alloc
Data allocation handlers.
Definition net_buf.h:1218
struct k_lifo free
LIFO to place the buffer into when free.
Definition net_buf.h:1186
struct k_spinlock lock
To prevent concurrent access/modifications.
Definition net_buf.h:1189
Parsing state of a buffer.
Definition net_buf.h:992
uint16_t offset
Offset of the data pointer from the beginning of the storage.
Definition net_buf.h:994
uint16_t len
Length of data.
Definition net_buf.h:996
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:1048
uint16_t size
Amount of data that this buffer can store.
Definition net_buf.h:1143
struct net_buf * frags
Fragments associated with this buffer.
Definition net_buf.h:1053
uint8_t ref
Reference count.
Definition net_buf.h:1116
uint8_t pool_id
Where the buffer should go when freed up.
Definition net_buf.h:1122
sys_snode_t node
Allow placing the buffer into sys_slist_t.
Definition net_buf.h:1050
uint8_t user_data_size
Size of user data on this buffer.
Definition net_buf.h:1125
uint8_t flags
Bit-field of buffer flags.
Definition net_buf.h:1119
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1137
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1158
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1140
Iterable sections helpers.
Misc utilities.