Zephyr Project API  3.3.0
A Scalable Open Source RTOS
buf.h
Go to the documentation of this file.
1
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>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
29/* Alignment needed for various parts of the buffer definition */
30#define __net_buf_align __aligned(sizeof(void *))
31
41#define NET_BUF_SIMPLE_DEFINE(_name, _size) \
42 uint8_t net_buf_data_##_name[_size]; \
43 struct net_buf_simple _name = { \
44 .data = net_buf_data_##_name, \
45 .len = 0, \
46 .size = _size, \
47 .__buf = net_buf_data_##_name, \
48 }
49
60#define NET_BUF_SIMPLE_DEFINE_STATIC(_name, _size) \
61 static __noinit uint8_t net_buf_data_##_name[_size]; \
62 static struct net_buf_simple _name = { \
63 .data = net_buf_data_##_name, \
64 .len = 0, \
65 .size = _size, \
66 .__buf = net_buf_data_##_name, \
67 }
68
85
92
95
99 uint8_t *__buf;
100};
101
118#define NET_BUF_SIMPLE(_size) \
119 ((struct net_buf_simple *)(&(struct { \
120 struct net_buf_simple buf; \
121 uint8_t data[_size]; \
122 }) { \
123 .buf.size = _size, \
124 }))
125
135static inline void net_buf_simple_init(struct net_buf_simple *buf,
136 size_t reserve_head)
137{
138 if (!buf->__buf) {
139 buf->__buf = (uint8_t *)buf + sizeof(*buf);
140 }
141
142 buf->data = buf->__buf + reserve_head;
143 buf->len = 0U;
144}
145
156 void *data, size_t size);
157
165static inline void net_buf_simple_reset(struct net_buf_simple *buf)
166{
167 buf->len = 0U;
168 buf->data = buf->__buf;
169}
170
181void net_buf_simple_clone(const struct net_buf_simple *original,
182 struct net_buf_simple *clone);
183
195void *net_buf_simple_add(struct net_buf_simple *buf, size_t len);
196
209void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem,
210 size_t len);
211
224
236
248
260
272
284
296
308
320
332
344
355void *net_buf_simple_remove_mem(struct net_buf_simple *buf, size_t len);
356
368
380
392
404
416
428
440
452
464
476
488
500void *net_buf_simple_push(struct net_buf_simple *buf, size_t len);
501
514void *net_buf_simple_push_mem(struct net_buf_simple *buf, const void *mem,
515 size_t len);
516
527
538
548
559
570
581
592
603
614
625
636
648void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len);
649
661void *net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len);
662
674
686
698
710
722
734
746
758
770
782
794
804static inline uint8_t *net_buf_simple_tail(struct net_buf_simple *buf)
805{
806 return buf->data + buf->len;
807}
808
819
830
841
854};
855
864static inline void net_buf_simple_save(struct net_buf_simple *buf,
866{
867 state->offset = net_buf_simple_headroom(buf);
868 state->len = buf->len;
869}
870
880static inline void net_buf_simple_restore(struct net_buf_simple *buf,
882{
883 buf->data = buf->__buf + state->offset;
884 buf->len = state->len;
885}
886
896#define NET_BUF_EXTERNAL_DATA BIT(0)
897
905struct net_buf {
908
910 struct net_buf *frags;
911
914
917
920
921 /* Size of user data on this buffer */
923
924 /* Union for convenience access to the net_buf_simple members, also
925 * preserving the old API.
926 */
927 union {
928 /* The ABI of this struct must match net_buf_simple */
929 struct {
932
935
938
943 uint8_t *__buf;
944 };
945
947 };
948
950 uint8_t user_data[] __net_buf_align;
951};
952
954 uint8_t * __must_check (*alloc)(struct net_buf *buf, size_t *size,
956 uint8_t * __must_check (*ref)(struct net_buf *buf, uint8_t *data);
957 void (*unref)(struct net_buf *buf, uint8_t *data);
958};
959
961 const struct net_buf_data_cb *cb;
963};
964
972 struct k_lifo free;
973
974 /* to prevent concurrent access/modifications */
976
979
982
983 /* Size of user data allocated to this pool */
985
986#if defined(CONFIG_NET_BUF_POOL_USAGE)
988 atomic_t avail_count;
989
991 const uint16_t pool_size;
992
994 const char *name;
995#endif /* CONFIG_NET_BUF_POOL_USAGE */
996
998 void (*const destroy)(struct net_buf *buf);
999
1002
1004 struct net_buf * const __bufs;
1005};
1006
1008#if defined(CONFIG_NET_BUF_POOL_USAGE)
1009#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \
1010 { \
1011 .free = Z_LIFO_INITIALIZER(_pool.free), \
1012 .lock = { }, \
1013 .buf_count = _count, \
1014 .uninit_count = _count, \
1015 .user_data_size = _ud_size, \
1016 .avail_count = ATOMIC_INIT(_count), \
1017 .name = STRINGIFY(_pool), \
1018 .destroy = _destroy, \
1019 .alloc = _alloc, \
1020 .__bufs = (struct net_buf *)_bufs, \
1021 }
1022#else
1023#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \
1024 { \
1025 .free = Z_LIFO_INITIALIZER(_pool.free), \
1026 .lock = { }, \
1027 .buf_count = _count, \
1028 .uninit_count = _count, \
1029 .user_data_size = _ud_size, \
1030 .destroy = _destroy, \
1031 .alloc = _alloc, \
1032 .__bufs = (struct net_buf *)_bufs, \
1033 }
1034#endif /* CONFIG_NET_BUF_POOL_USAGE */
1035
1036#define _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size) \
1037 struct _net_buf_##_name { uint8_t b[sizeof(struct net_buf)]; \
1038 uint8_t ud[_ud_size]; } __net_buf_align; \
1039 BUILD_ASSERT(_ud_size <= UINT8_MAX); \
1040 BUILD_ASSERT(offsetof(struct net_buf, user_data) == \
1041 offsetof(struct _net_buf_##_name, ud), "Invalid offset"); \
1042 BUILD_ASSERT(__alignof__(struct net_buf) == \
1043 __alignof__(struct _net_buf_##_name), "Invalid alignment"); \
1044 BUILD_ASSERT(sizeof(struct _net_buf_##_name) == \
1045 ROUND_UP(sizeof(struct net_buf) + _ud_size, __alignof__(struct net_buf)), \
1046 "Size cannot be determined"); \
1047 static struct _net_buf_##_name _net_buf_##_name[_count] __noinit
1048
1049extern const struct net_buf_data_alloc net_buf_heap_alloc;
1079#define NET_BUF_POOL_HEAP_DEFINE(_name, _count, _ud_size, _destroy) \
1080 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1081 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1082 NET_BUF_POOL_INITIALIZER(_name, &net_buf_heap_alloc, \
1083 _net_buf_##_name, _count, _ud_size, \
1084 _destroy)
1085
1089};
1090
1092extern const struct net_buf_data_cb net_buf_fixed_cb;
1123#define NET_BUF_POOL_FIXED_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1124 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1125 static uint8_t __noinit net_buf_data_##_name[_count][_data_size] __net_buf_align; \
1126 static const struct net_buf_pool_fixed net_buf_fixed_##_name = { \
1127 .data_size = _data_size, \
1128 .data_pool = (uint8_t *)net_buf_data_##_name, \
1129 }; \
1130 static const struct net_buf_data_alloc net_buf_fixed_alloc_##_name = { \
1131 .cb = &net_buf_fixed_cb, \
1132 .alloc_data = (void *)&net_buf_fixed_##_name, \
1133 }; \
1134 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1135 NET_BUF_POOL_INITIALIZER(_name, &net_buf_fixed_alloc_##_name, \
1136 _net_buf_##_name, _count, _ud_size, \
1137 _destroy)
1138
1140extern const struct net_buf_data_cb net_buf_var_cb;
1167#define NET_BUF_POOL_VAR_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \
1168 _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \
1169 K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \
1170 static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \
1171 .cb = &net_buf_var_cb, \
1172 .alloc_data = &net_buf_mem_pool_##_name, \
1173 }; \
1174 static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \
1175 NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \
1176 _net_buf_##_name, _count, _ud_size, \
1177 _destroy)
1178
1200#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy) \
1201 NET_BUF_POOL_FIXED_DEFINE(_name, _count, _size, _ud_size, _destroy)
1202
1211
1224int net_buf_id(struct net_buf *buf);
1225
1240#if defined(CONFIG_NET_BUF_LOG)
1241struct net_buf * __must_check net_buf_alloc_fixed_debug(struct net_buf_pool *pool,
1243 const char *func,
1244 int line);
1245#define net_buf_alloc_fixed(_pool, _timeout) \
1246 net_buf_alloc_fixed_debug(_pool, _timeout, __func__, __LINE__)
1247#else
1248struct net_buf * __must_check net_buf_alloc_fixed(struct net_buf_pool *pool,
1250#endif
1251
1255static inline struct net_buf * __must_check net_buf_alloc(struct net_buf_pool *pool,
1257{
1258 return net_buf_alloc_fixed(pool, timeout);
1259}
1260
1276#if defined(CONFIG_NET_BUF_LOG)
1277struct net_buf * __must_check net_buf_alloc_len_debug(struct net_buf_pool *pool,
1278 size_t size,
1280 const char *func,
1281 int line);
1282#define net_buf_alloc_len(_pool, _size, _timeout) \
1283 net_buf_alloc_len_debug(_pool, _size, _timeout, __func__, __LINE__)
1284#else
1285struct net_buf * __must_check net_buf_alloc_len(struct net_buf_pool *pool,
1286 size_t size,
1288#endif
1289
1309#if defined(CONFIG_NET_BUF_LOG)
1310struct net_buf * __must_check net_buf_alloc_with_data_debug(struct net_buf_pool *pool,
1311 void *data, size_t size,
1313 const char *func, int line);
1314#define net_buf_alloc_with_data(_pool, _data_, _size, _timeout) \
1315 net_buf_alloc_with_data_debug(_pool, _data_, _size, _timeout, \
1316 __func__, __LINE__)
1317#else
1318struct net_buf * __must_check net_buf_alloc_with_data(struct net_buf_pool *pool,
1319 void *data, size_t size,
1321#endif
1322
1336#if defined(CONFIG_NET_BUF_LOG)
1337struct net_buf * __must_check net_buf_get_debug(struct k_fifo *fifo,
1339 const char *func, int line);
1340#define net_buf_get(_fifo, _timeout) \
1341 net_buf_get_debug(_fifo, _timeout, __func__, __LINE__)
1342#else
1343struct net_buf * __must_check net_buf_get(struct k_fifo *fifo,
1345#endif
1346
1356static inline void net_buf_destroy(struct net_buf *buf)
1357{
1358 struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id);
1359
1360 k_lifo_put(&pool->free, buf);
1361}
1362
1370void net_buf_reset(struct net_buf *buf);
1371
1380void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve);
1381
1391void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf);
1392
1403struct net_buf * __must_check net_buf_slist_get(sys_slist_t *list);
1404
1414void net_buf_put(struct k_fifo *fifo, struct net_buf *buf);
1415
1423#if defined(CONFIG_NET_BUF_LOG)
1424void net_buf_unref_debug(struct net_buf *buf, const char *func, int line);
1425#define net_buf_unref(_buf) \
1426 net_buf_unref_debug(_buf, __func__, __LINE__)
1427#else
1428void net_buf_unref(struct net_buf *buf);
1429#endif
1430
1438struct net_buf * __must_check net_buf_ref(struct net_buf *buf);
1439
1453struct net_buf * __must_check net_buf_clone(struct net_buf *buf,
1455
1463static inline void * __must_check net_buf_user_data(const struct net_buf *buf)
1464{
1465 return (void *)buf->user_data;
1466}
1467
1476static inline void net_buf_reserve(struct net_buf *buf, size_t reserve)
1477{
1478 net_buf_simple_reserve(&buf->b, reserve);
1479}
1480
1492static inline void *net_buf_add(struct net_buf *buf, size_t len)
1493{
1494 return net_buf_simple_add(&buf->b, len);
1495}
1496
1509static inline void *net_buf_add_mem(struct net_buf *buf, const void *mem,
1510 size_t len)
1511{
1512 return net_buf_simple_add_mem(&buf->b, mem, len);
1513}
1514
1526static inline uint8_t *net_buf_add_u8(struct net_buf *buf, uint8_t val)
1527{
1528 return net_buf_simple_add_u8(&buf->b, val);
1529}
1530
1541static inline void net_buf_add_le16(struct net_buf *buf, uint16_t val)
1542{
1543 net_buf_simple_add_le16(&buf->b, val);
1544}
1545
1556static inline void net_buf_add_be16(struct net_buf *buf, uint16_t val)
1557{
1558 net_buf_simple_add_be16(&buf->b, val);
1559}
1560
1571static inline void net_buf_add_le24(struct net_buf *buf, uint32_t val)
1572{
1573 net_buf_simple_add_le24(&buf->b, val);
1574}
1575
1586static inline void net_buf_add_be24(struct net_buf *buf, uint32_t val)
1587{
1588 net_buf_simple_add_be24(&buf->b, val);
1589}
1590
1601static inline void net_buf_add_le32(struct net_buf *buf, uint32_t val)
1602{
1603 net_buf_simple_add_le32(&buf->b, val);
1604}
1605
1616static inline void net_buf_add_be32(struct net_buf *buf, uint32_t val)
1617{
1618 net_buf_simple_add_be32(&buf->b, val);
1619}
1620
1631static inline void net_buf_add_le48(struct net_buf *buf, uint64_t val)
1632{
1633 net_buf_simple_add_le48(&buf->b, val);
1634}
1635
1646static inline void net_buf_add_be48(struct net_buf *buf, uint64_t val)
1647{
1648 net_buf_simple_add_be48(&buf->b, val);
1649}
1650
1661static inline void net_buf_add_le64(struct net_buf *buf, uint64_t val)
1662{
1663 net_buf_simple_add_le64(&buf->b, val);
1664}
1665
1676static inline void net_buf_add_be64(struct net_buf *buf, uint64_t val)
1677{
1678 net_buf_simple_add_be64(&buf->b, val);
1679}
1680
1691static inline void *net_buf_remove_mem(struct net_buf *buf, size_t len)
1692{
1693 return net_buf_simple_remove_mem(&buf->b, len);
1694}
1695
1706static inline uint8_t net_buf_remove_u8(struct net_buf *buf)
1707{
1708 return net_buf_simple_remove_u8(&buf->b);
1709}
1710
1721static inline uint16_t net_buf_remove_le16(struct net_buf *buf)
1722{
1723 return net_buf_simple_remove_le16(&buf->b);
1724}
1725
1736static inline uint16_t net_buf_remove_be16(struct net_buf *buf)
1737{
1738 return net_buf_simple_remove_be16(&buf->b);
1739}
1740
1751static inline uint32_t net_buf_remove_be24(struct net_buf *buf)
1752{
1753 return net_buf_simple_remove_be24(&buf->b);
1754}
1755
1766static inline uint32_t net_buf_remove_le24(struct net_buf *buf)
1767{
1768 return net_buf_simple_remove_le24(&buf->b);
1769}
1770
1781static inline uint32_t net_buf_remove_le32(struct net_buf *buf)
1782{
1783 return net_buf_simple_remove_le32(&buf->b);
1784}
1785
1796static inline uint32_t net_buf_remove_be32(struct net_buf *buf)
1797{
1798 return net_buf_simple_remove_be32(&buf->b);
1799}
1800
1811static inline uint64_t net_buf_remove_le48(struct net_buf *buf)
1812{
1813 return net_buf_simple_remove_le48(&buf->b);
1814}
1815
1826static inline uint64_t net_buf_remove_be48(struct net_buf *buf)
1827{
1828 return net_buf_simple_remove_be48(&buf->b);
1829}
1830
1841static inline uint64_t net_buf_remove_le64(struct net_buf *buf)
1842{
1843 return net_buf_simple_remove_le64(&buf->b);
1844}
1845
1856static inline uint64_t net_buf_remove_be64(struct net_buf *buf)
1857{
1858 return net_buf_simple_remove_be64(&buf->b);
1859}
1860
1872static inline void *net_buf_push(struct net_buf *buf, size_t len)
1873{
1874 return net_buf_simple_push(&buf->b, len);
1875}
1876
1889static inline void *net_buf_push_mem(struct net_buf *buf, const void *mem,
1890 size_t len)
1891{
1892 return net_buf_simple_push_mem(&buf->b, mem, len);
1893}
1894
1903static inline void net_buf_push_u8(struct net_buf *buf, uint8_t val)
1904{
1905 net_buf_simple_push_u8(&buf->b, val);
1906}
1907
1917static inline void net_buf_push_le16(struct net_buf *buf, uint16_t val)
1918{
1919 net_buf_simple_push_le16(&buf->b, val);
1920}
1921
1931static inline void net_buf_push_be16(struct net_buf *buf, uint16_t val)
1932{
1933 net_buf_simple_push_be16(&buf->b, val);
1934}
1935
1945static inline void net_buf_push_le24(struct net_buf *buf, uint32_t val)
1946{
1947 net_buf_simple_push_le24(&buf->b, val);
1948}
1949
1959static inline void net_buf_push_be24(struct net_buf *buf, uint32_t val)
1960{
1961 net_buf_simple_push_be24(&buf->b, val);
1962}
1963
1973static inline void net_buf_push_le32(struct net_buf *buf, uint32_t val)
1974{
1975 net_buf_simple_push_le32(&buf->b, val);
1976}
1977
1987static inline void net_buf_push_be32(struct net_buf *buf, uint32_t val)
1988{
1989 net_buf_simple_push_be32(&buf->b, val);
1990}
1991
2001static inline void net_buf_push_le48(struct net_buf *buf, uint64_t val)
2002{
2003 net_buf_simple_push_le48(&buf->b, val);
2004}
2005
2015static inline void net_buf_push_be48(struct net_buf *buf, uint64_t val)
2016{
2017 net_buf_simple_push_be48(&buf->b, val);
2018}
2019
2029static inline void net_buf_push_le64(struct net_buf *buf, uint64_t val)
2030{
2031 net_buf_simple_push_le64(&buf->b, val);
2032}
2033
2043static inline void net_buf_push_be64(struct net_buf *buf, uint64_t val)
2044{
2045 net_buf_simple_push_be64(&buf->b, val);
2046}
2047
2059static inline void *net_buf_pull(struct net_buf *buf, size_t len)
2060{
2061 return net_buf_simple_pull(&buf->b, len);
2062}
2063
2075static inline void *net_buf_pull_mem(struct net_buf *buf, size_t len)
2076{
2077 return net_buf_simple_pull_mem(&buf->b, len);
2078}
2079
2090static inline uint8_t net_buf_pull_u8(struct net_buf *buf)
2091{
2092 return net_buf_simple_pull_u8(&buf->b);
2093}
2094
2105static inline uint16_t net_buf_pull_le16(struct net_buf *buf)
2106{
2107 return net_buf_simple_pull_le16(&buf->b);
2108}
2109
2120static inline uint16_t net_buf_pull_be16(struct net_buf *buf)
2121{
2122 return net_buf_simple_pull_be16(&buf->b);
2123}
2124
2135static inline uint32_t net_buf_pull_le24(struct net_buf *buf)
2136{
2137 return net_buf_simple_pull_le24(&buf->b);
2138}
2139
2150static inline uint32_t net_buf_pull_be24(struct net_buf *buf)
2151{
2152 return net_buf_simple_pull_be24(&buf->b);
2153}
2154
2165static inline uint32_t net_buf_pull_le32(struct net_buf *buf)
2166{
2167 return net_buf_simple_pull_le32(&buf->b);
2168}
2169
2180static inline uint32_t net_buf_pull_be32(struct net_buf *buf)
2181{
2182 return net_buf_simple_pull_be32(&buf->b);
2183}
2184
2195static inline uint64_t net_buf_pull_le48(struct net_buf *buf)
2196{
2197 return net_buf_simple_pull_le48(&buf->b);
2198}
2199
2210static inline uint64_t net_buf_pull_be48(struct net_buf *buf)
2211{
2212 return net_buf_simple_pull_be48(&buf->b);
2213}
2214
2225static inline uint64_t net_buf_pull_le64(struct net_buf *buf)
2226{
2227 return net_buf_simple_pull_le64(&buf->b);
2228}
2229
2240static inline uint64_t net_buf_pull_be64(struct net_buf *buf)
2241{
2242 return net_buf_simple_pull_be64(&buf->b);
2243}
2244
2254static inline size_t net_buf_tailroom(struct net_buf *buf)
2255{
2256 return net_buf_simple_tailroom(&buf->b);
2257}
2258
2268static inline size_t net_buf_headroom(struct net_buf *buf)
2269{
2270 return net_buf_simple_headroom(&buf->b);
2271}
2272
2282static inline uint16_t net_buf_max_len(struct net_buf *buf)
2283{
2284 return net_buf_simple_max_len(&buf->b);
2285}
2286
2296static inline uint8_t *net_buf_tail(struct net_buf *buf)
2297{
2298 return net_buf_simple_tail(&buf->b);
2299}
2300
2307
2319void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag);
2320
2335struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag);
2336
2346#if defined(CONFIG_NET_BUF_LOG)
2347struct net_buf *net_buf_frag_del_debug(struct net_buf *parent,
2348 struct net_buf *frag,
2349 const char *func, int line);
2350#define net_buf_frag_del(_parent, _frag) \
2351 net_buf_frag_del_debug(_parent, _frag, __func__, __LINE__)
2352#else
2353struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag);
2354#endif
2355
2371size_t net_buf_linearize(void *dst, size_t dst_len,
2372 struct net_buf *src, size_t offset, size_t len);
2373
2388typedef struct net_buf * __must_check (*net_buf_allocator_cb)(k_timeout_t timeout,
2389 void *user_data);
2390
2412size_t net_buf_append_bytes(struct net_buf *buf, size_t len,
2413 const void *value, k_timeout_t timeout,
2414 net_buf_allocator_cb allocate_cb, void *user_data);
2415
2431static inline struct net_buf *net_buf_skip(struct net_buf *buf, size_t len)
2432{
2433 while (buf && len--) {
2434 net_buf_pull_u8(buf);
2435 if (!buf->len) {
2436 buf = net_buf_frag_del(NULL, buf);
2437 }
2438 }
2439
2440 return buf;
2441}
2442
2453static inline size_t net_buf_frags_len(struct net_buf *buf)
2454{
2455 size_t bytes = 0;
2456
2457 while (buf) {
2458 bytes += buf->len;
2459 buf = buf->frags;
2460 }
2461
2462 return bytes;
2463}
2464
2469#ifdef __cplusplus
2470}
2471#endif
2472
2473#endif /* ZEPHYR_INCLUDE_NET_BUF_H_ */
long atomic_t
Definition: atomic.h:22
ZTEST_BMEM int timeout
Definition: main.c:31
struct k_fifo fifo
Definition: errno.c:44
#define k_lifo_put(lifo, data)
Add an element to a LIFO queue.
Definition: kernel.h:2535
struct net_buf * net_buf_get(struct k_fifo *fifo, k_timeout_t timeout)
Get a buffer from a FIFO.
void net_buf_simple_clone(const struct net_buf_simple *original, struct net_buf_simple *clone)
static void net_buf_simple_init(struct net_buf_simple *buf, size_t reserve_head)
Initialize a net_buf_simple object.
Definition: buf.h:135
struct net_buf * net_buf_frag_last(struct net_buf *frags)
Find the last fragment in the fragment list.
static void net_buf_add_be64(struct net_buf *buf, uint64_t val)
Add 64-bit value at the end of the buffer.
Definition: buf.h:1676
static size_t net_buf_headroom(struct net_buf *buf)
Check buffer headroom.
Definition: buf.h:2268
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: buf.h:1811
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: buf.h:1586
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.
struct net_buf *(* net_buf_allocator_cb)(k_timeout_t timeout, void *user_data)
Network buffer allocator callback.
Definition: buf.h:2388
static struct net_buf * net_buf_skip(struct net_buf *buf, size_t len)
Skip N number of bytes in a net_buf.
Definition: buf.h:2431
static void * net_buf_add(struct net_buf *buf, size_t len)
Prepare data to be added at the end of the buffer.
Definition: buf.h:1492
static void net_buf_add_le24(struct net_buf *buf, uint32_t val)
Add 24-bit value at the end of the buffer.
Definition: buf.h:1571
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: buf.h:2240
static void net_buf_push_be64(struct net_buf *buf, uint64_t val)
Push 64-bit value to the beginning of the buffer.
Definition: buf.h:2043
static uint64_t net_buf_remove_le64(struct net_buf *buf)
Remove and convert 64 bits from the end of the buffer.
Definition: buf.h:1841
static void net_buf_simple_reset(struct net_buf_simple *buf)
Reset buffer.
Definition: buf.h:165
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.
uint32_t net_buf_simple_remove_le24(struct net_buf_simple *buf)
Remove and convert 24 bits from the end of the buffer.
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 struct net_buf * net_buf_alloc(struct net_buf_pool *pool, k_timeout_t timeout)
Definition: buf.h:1255
static void net_buf_add_be32(struct net_buf *buf, uint32_t val)
Add 32-bit value at the end of the buffer.
Definition: buf.h:1616
uint64_t net_buf_simple_remove_le64(struct net_buf_simple *buf)
Remove and convert 64 bits from the end of the buffer.
size_t net_buf_simple_tailroom(struct net_buf_simple *buf)
Check buffer tailroom.
static void net_buf_simple_save(struct net_buf_simple *buf, struct net_buf_simple_state *state)
Save the parsing state of a buffer.
Definition: buf.h:864
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: buf.h:1736
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: buf.h:2165
static uint32_t net_buf_pull_be32(struct net_buf *buf)
Remove and convert 32 bits from the beginning of the buffer.
Definition: buf.h:2180
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 size_t net_buf_tailroom(struct net_buf *buf)
Check buffer tailroom.
Definition: buf.h:2254
static void net_buf_add_be16(struct net_buf *buf, uint16_t val)
Add 16-bit value at the end of the buffer.
Definition: buf.h:1556
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.
void net_buf_simple_push_le48(struct net_buf_simple *buf, uint64_t val)
Push 48-bit value to the beginning 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: buf.h:2210
uint64_t net_buf_simple_pull_le48(struct net_buf_simple *buf)
Remove and convert 48 bits from the beginning of the buffer.
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: buf.h:1931
static uint32_t net_buf_remove_be24(struct net_buf *buf)
Remove and convert 24 bits from the end of the buffer.
Definition: buf.h:1751
static uint8_t net_buf_pull_u8(struct net_buf *buf)
Remove a 8-bit value from the beginning of the buffer.
Definition: buf.h:2090
static void net_buf_destroy(struct net_buf *buf)
Destroy buffer from custom destroy callback.
Definition: buf.h:1356
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.
uint16_t net_buf_simple_max_len(struct net_buf_simple *buf)
Check maximum net_buf_simple::len value.
uint64_t net_buf_simple_pull_le64(struct net_buf_simple *buf)
Remove and convert 64 bits from the beginning of the buffer.
void net_buf_put(struct k_fifo *fifo, struct net_buf *buf)
Put a buffer to the end of a FIFO.
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: buf.h:1889
static uint64_t net_buf_pull_le48(struct net_buf *buf)
Remove and convert 48 bits from the beginning of the buffer.
Definition: buf.h:2195
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: buf.h:2001
static uint32_t net_buf_pull_le24(struct net_buf *buf)
Remove and convert 24 bits from the beginning of the buffer.
Definition: buf.h:2135
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: buf.h:1526
static void net_buf_push_be24(struct net_buf *buf, uint32_t val)
Push 24-bit value to the beginning of the buffer.
Definition: buf.h:1959
static void net_buf_push_le24(struct net_buf *buf, uint32_t val)
Push 24-bit value to the beginning of the buffer.
Definition: buf.h:1945
static void net_buf_reserve(struct net_buf *buf, size_t reserve)
Initialize buffer with the given headroom.
Definition: buf.h:1476
static uint64_t net_buf_remove_be64(struct net_buf *buf)
Remove and convert 64 bits from the end of the buffer.
Definition: buf.h:1856
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 uint8_t * net_buf_simple_tail(struct net_buf_simple *buf)
Get the tail pointer for a buffer.
Definition: buf.h:804
static uint32_t net_buf_pull_be24(struct net_buf *buf)
Remove and convert 24 bits from the beginning of the buffer.
Definition: buf.h:2150
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: buf.h:1646
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: buf.h:1766
static void net_buf_push_u8(struct net_buf *buf, uint8_t val)
Push 8-bit value to the beginning of the buffer.
Definition: buf.h:1903
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: buf.h:1872
static uint16_t net_buf_pull_be16(struct net_buf *buf)
Remove and convert 16 bits from the beginning of the buffer.
Definition: buf.h:2120
static void net_buf_push_le32(struct net_buf *buf, uint32_t val)
Push 32-bit value to the beginning of the buffer.
Definition: buf.h:1973
static uint64_t net_buf_pull_le64(struct net_buf *buf)
Remove and convert 64 bits from the beginning of the buffer.
Definition: buf.h:2225
uint32_t net_buf_simple_remove_be24(struct net_buf_simple *buf)
Remove and convert 24 bits from the end of the buffer.
void * net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len)
Remove data from the beginning of the buffer.
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.
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: buf.h:1826
static uint16_t net_buf_max_len(struct net_buf *buf)
Check maximum net_buf::len value.
Definition: buf.h:2282
void net_buf_simple_add_be32(struct net_buf_simple *buf, uint32_t val)
Add 32-bit value at the end of the buffer.
static uint16_t net_buf_remove_le16(struct net_buf *buf)
Remove and convert 16 bits from the end of the buffer.
Definition: buf.h:1721
static void net_buf_push_le16(struct net_buf *buf, uint16_t val)
Push 16-bit value to the beginning of the buffer.
Definition: buf.h:1917
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_push_be48(struct net_buf *buf, uint64_t val)
Push 48-bit value to the beginning of the buffer.
Definition: buf.h:2015
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: buf.h:1661
static uint8_t * net_buf_tail(struct net_buf *buf)
Get the tail pointer for a buffer.
Definition: buf.h:2296
static uint32_t net_buf_remove_be32(struct net_buf *buf)
Remove and convert 32 bits from the end of the buffer.
Definition: buf.h:1796
static void * net_buf_remove_mem(struct net_buf *buf, size_t len)
Remove data from the end of the buffer.
Definition: buf.h:1691
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: buf.h:1509
size_t net_buf_simple_headroom(struct net_buf_simple *buf)
Check buffer headroom.
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: buf.h:2029
uint16_t net_buf_simple_pull_le16(struct net_buf_simple *buf)
Remove and convert 16 bits from the beginning of the buffer.
int net_buf_id(struct net_buf *buf)
Get a zero-based index for a buffer.
static uint8_t net_buf_remove_u8(struct net_buf *buf)
Remove a 8-bit value from the end of the buffer.
Definition: buf.h:1706
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 void net_buf_add_le16(struct net_buf *buf, uint16_t val)
Add 16-bit value at the end of the buffer.
Definition: buf.h:1541
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: buf.h:1987
static void net_buf_add_le32(struct net_buf *buf, uint32_t val)
Add 32-bit value at the end of the buffer.
Definition: buf.h:1601
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: buf.h:1781
static size_t net_buf_frags_len(struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition: buf.h:2453
static uint16_t net_buf_pull_le16(struct net_buf *buf)
Remove and convert 16 bits from the beginning of the buffer.
Definition: buf.h:2105
static void * net_buf_pull_mem(struct net_buf *buf, size_t len)
Remove data from the beginning of the buffer.
Definition: buf.h:2075
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: buf.h:880
static void * net_buf_pull(struct net_buf *buf, size_t len)
Remove data from the beginning of the buffer.
Definition: buf.h:2059
static void net_buf_add_le48(struct net_buf *buf, uint64_t val)
Add 48-bit value at the end of the buffer.
Definition: buf.h:1631
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: buf.h:1463
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.
size_t net_buf_linearize(void *dst, size_t dst_len, struct net_buf *src, size_t offset, size_t len)
Copy bytes from net_buf chain starting at offset to linear 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.
Public kernel APIs.
state
Definition: parser_state.h:29
struct _slist sys_slist_t
Definition: slist.h:40
struct _snode sys_snode_t
Definition: slist.h:33
__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
Definition: kernel.h:2252
Definition: kernel.h:2486
Kernel Spin Lock.
Definition: spinlock.h:43
Kernel timeout type.
Definition: sys_clock.h:65
Definition: buf.h:960
const struct net_buf_data_cb * cb
Definition: buf.h:961
void * alloc_data
Definition: buf.h:962
Definition: buf.h:953
uint8_t *(* ref)(struct net_buf *buf, uint8_t *data)
Definition: buf.h:956
uint8_t *(* alloc)(struct net_buf *buf, size_t *size, k_timeout_t timeout)
Definition: buf.h:954
void(* unref)(struct net_buf *buf, uint8_t *data)
Definition: buf.h:957
Definition: buf.h:1086
size_t data_size
Definition: buf.h:1087
uint8_t * data_pool
Definition: buf.h:1088
Network buffer pool representation.
Definition: buf.h:970
void(*const destroy)(struct net_buf *buf)
Definition: buf.h:998
uint16_t uninit_count
Definition: buf.h:981
uint8_t user_data_size
Definition: buf.h:984
const uint16_t buf_count
Definition: buf.h:978
const struct net_buf_data_alloc * alloc
Definition: buf.h:1001
struct k_lifo free
Definition: buf.h:972
struct k_spinlock lock
Definition: buf.h:975
Parsing state of a buffer.
Definition: buf.h:849
uint16_t offset
Definition: buf.h:851
uint16_t len
Definition: buf.h:853
Simple network buffer representation.
Definition: buf.h:82
uint8_t * data
Definition: buf.h:84
uint16_t size
Definition: buf.h:94
uint16_t len
Definition: buf.h:91
Network buffer representation.
Definition: buf.h:905
uint16_t size
Definition: buf.h:937
struct net_buf * frags
Definition: buf.h:910
uint8_t ref
Definition: buf.h:913
uint8_t pool_id
Definition: buf.h:919
sys_snode_t node
Definition: buf.h:907
uint8_t user_data_size
Definition: buf.h:922
uint8_t flags
Definition: buf.h:916
uint8_t * data
Definition: buf.h:931
uint8_t user_data[]
Definition: buf.h:950
struct net_buf_simple b
Definition: buf.h:946
uint16_t len
Definition: buf.h:934
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
static const intptr_t user_data[5]
Definition: main.c:588
Misc utilities.