diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 42db676520a..472f3023ea7 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -2845,6 +2845,7 @@ Networking: - jukkar files: - include/zephyr/net/buf.h + - include/zephyr/net_buf.h - lib/net_buf/ - tests/net/buf/ labels: diff --git a/doc/connectivity/networking/api/net_buf.rst b/doc/connectivity/networking/api/net_buf.rst index 88948ac8007..b09ee914ea5 100644 --- a/doc/connectivity/networking/api/net_buf.rst +++ b/doc/connectivity/networking/api/net_buf.rst @@ -13,7 +13,7 @@ Overview Network buffers are a core concept of how the networking stack (as well as the Bluetooth stack) pass data around. The API for them is -defined in :zephyr_file:`include/zephyr/net/buf.h`:. +defined in :zephyr_file:`include/zephyr/net_buf.h`:. Creating buffers **************** diff --git a/doc/services/zbus/index.rst b/doc/services/zbus/index.rst index eb8b9ad7099..1b685bb2bbf 100644 --- a/doc/services/zbus/index.rst +++ b/doc/services/zbus/index.rst @@ -397,7 +397,7 @@ rate by following design tips: * Consider using message queues or pipes for intensive byte transfers. .. warning:: - ZBus uses :zephyr_file:`include/zephyr/net/buf.h` (network buffers) to exchange data with message + ZBus uses :zephyr_file:`include/zephyr/net_buf.h` (network buffers) to exchange data with message subscribers. Thus, choose carefully the configurations :kconfig:option:`CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_SIZE` and :kconfig:option:`CONFIG_HEAP_MEM_POOL_SIZE`. They are crucial to a proper VDED execution diff --git a/drivers/modem/modem_cmd_handler.c b/drivers/modem/modem_cmd_handler.c index 02306554d30..8bc84f5c5f2 100644 --- a/drivers/modem/modem_cmd_handler.c +++ b/drivers/modem/modem_cmd_handler.c @@ -15,7 +15,7 @@ LOG_MODULE_REGISTER(modem_cmd_handler, CONFIG_MODEM_LOG_LEVEL); #include #include -#include +#include #include "modem_context.h" #include "modem_cmd_handler.h" diff --git a/drivers/modem/modem_context.h b/drivers/modem/modem_context.h index de76b0a4c60..8c75e24aeb1 100644 --- a/drivers/modem/modem_context.h +++ b/drivers/modem/modem_context.h @@ -15,7 +15,7 @@ #define ZEPHYR_INCLUDE_DRIVERS_MODEM_MODEM_CONTEXT_H_ #include -#include +#include #include #include #include diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 0f07b0af65e..4340c07df2b 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -18,7 +18,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include -#include +#include #include #include #include diff --git a/drivers/net/ppp.c b/drivers/net/ppp.c index 24a046e8d19..99d3eef881f 100644 --- a/drivers/net/ppp.c +++ b/drivers/net/ppp.c @@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(net_ppp, LOG_LEVEL); #include #include #include -#include +#include #include #include #include diff --git a/drivers/net/slip.h b/drivers/net/slip.h index 94c5c85302e..554cf3956bb 100644 --- a/drivers/net/slip.h +++ b/drivers/net/slip.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include diff --git a/drivers/usb/udc/udc_common.c b/drivers/usb/udc/udc_common.c index 53ae5a3f407..86f5a7f854a 100644 --- a/drivers/usb/udc/udc_common.c +++ b/drivers/usb/udc/udc_common.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/zephyr/bluetooth/audio/bap.h b/include/zephyr/bluetooth/audio/bap.h index ccae126e0bc..3de92a88ae9 100644 --- a/include/zephyr/bluetooth/audio/bap.h +++ b/include/zephyr/bluetooth/audio/bap.h @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/audio/cap.h b/include/zephyr/bluetooth/audio/cap.h index 3409e000d9c..50c29640a73 100644 --- a/include/zephyr/bluetooth/audio/cap.h +++ b/include/zephyr/bluetooth/audio/cap.h @@ -41,7 +41,7 @@ #include #include #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/include/zephyr/bluetooth/audio/mcc.h b/include/zephyr/bluetooth/audio/mcc.h index 6b6d0dcfdb9..a6c35afc2d6 100644 --- a/include/zephyr/bluetooth/audio/mcc.h +++ b/include/zephyr/bluetooth/audio/mcc.h @@ -30,7 +30,7 @@ #include #include -#include +#include #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/audio/pbp.h b/include/zephyr/bluetooth/audio/pbp.h index d577bfe7e15..db649e523ab 100644 --- a/include/zephyr/bluetooth/audio/pbp.h +++ b/include/zephyr/bluetooth/audio/pbp.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/zephyr/bluetooth/bluetooth.h b/include/zephyr/bluetooth/bluetooth.h index 5cdd73857d8..6f565bd400f 100644 --- a/include/zephyr/bluetooth/bluetooth.h +++ b/include/zephyr/bluetooth/bluetooth.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/zephyr/bluetooth/buf.h b/include/zephyr/bluetooth/buf.h index b373ab5bd91..fe480196f58 100644 --- a/include/zephyr/bluetooth/buf.h +++ b/include/zephyr/bluetooth/buf.h @@ -20,7 +20,7 @@ #include -#include +#include #include #include diff --git a/include/zephyr/bluetooth/hci.h b/include/zephyr/bluetooth/hci.h index decc856d7ec..7687abdb631 100644 --- a/include/zephyr/bluetooth/hci.h +++ b/include/zephyr/bluetooth/hci.h @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/zephyr/bluetooth/mesh.h b/include/zephyr/bluetooth/mesh.h index fc84814fa44..fe1fd728fa3 100644 --- a/include/zephyr/bluetooth/mesh.h +++ b/include/zephyr/bluetooth/mesh.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/include/zephyr/bluetooth/mesh/msg.h b/include/zephyr/bluetooth/mesh/msg.h index 8a7ce1a7128..d5d93111ea9 100644 --- a/include/zephyr/bluetooth/mesh/msg.h +++ b/include/zephyr/bluetooth/mesh/msg.h @@ -18,7 +18,7 @@ */ #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/include/zephyr/canbus/isotp.h b/include/zephyr/canbus/isotp.h index 222cef70a31..d2fc859127a 100644 --- a/include/zephyr/canbus/isotp.h +++ b/include/zephyr/canbus/isotp.h @@ -23,7 +23,7 @@ #include #include -#include +#include /* * Abbreviations diff --git a/include/zephyr/drivers/bluetooth.h b/include/zephyr/drivers/bluetooth.h index 2f969c40595..cdf62e618dd 100644 --- a/include/zephyr/drivers/bluetooth.h +++ b/include/zephyr/drivers/bluetooth.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/zephyr/drivers/bluetooth/hci_driver.h b/include/zephyr/drivers/bluetooth/hci_driver.h index a142d8698cc..c2eae9d90cb 100644 --- a/include/zephyr/drivers/bluetooth/hci_driver.h +++ b/include/zephyr/drivers/bluetooth/hci_driver.h @@ -21,7 +21,7 @@ */ #include -#include +#include #include #include #include diff --git a/include/zephyr/drivers/usb/udc_buf.h b/include/zephyr/drivers/usb/udc_buf.h index 69b85da94db..ac101e3bacb 100644 --- a/include/zephyr/drivers/usb/udc_buf.h +++ b/include/zephyr/drivers/usb/udc_buf.h @@ -13,7 +13,7 @@ #define ZEPHYR_INCLUDE_UDC_BUF_H #include -#include +#include #if defined(CONFIG_DCACHE) && !defined(CONFIG_UDC_BUF_FORCE_NOCACHE) /* diff --git a/include/zephyr/drivers/usb/uhc.h b/include/zephyr/drivers/usb/uhc.h index 5f499af6c1d..01e505adead 100644 --- a/include/zephyr/drivers/usb/uhc.h +++ b/include/zephyr/drivers/usb/uhc.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include diff --git a/include/zephyr/mgmt/mcumgr/smp/smp.h b/include/zephyr/mgmt/mcumgr/smp/smp.h index c72461a939a..cc72e801a95 100644 --- a/include/zephyr/mgmt/mcumgr/smp/smp.h +++ b/include/zephyr/mgmt/mcumgr/smp/smp.h @@ -26,7 +26,7 @@ #ifndef H_SMP_ #define H_SMP_ -#include +#include #include #include diff --git a/include/zephyr/mgmt/mcumgr/smp/smp_client.h b/include/zephyr/mgmt/mcumgr/smp/smp_client.h index 2e0eee2cfe6..35685fd945b 100644 --- a/include/zephyr/mgmt/mcumgr/smp/smp_client.h +++ b/include/zephyr/mgmt/mcumgr/smp/smp_client.h @@ -8,7 +8,7 @@ #define H_SMP_CLIENT_ #include -#include +#include #include #include #include diff --git a/include/zephyr/mgmt/mcumgr/transport/smp_dummy.h b/include/zephyr/mgmt/mcumgr/transport/smp_dummy.h index 02e974ea8aa..5247b8e7de7 100644 --- a/include/zephyr/mgmt/mcumgr/transport/smp_dummy.h +++ b/include/zephyr/mgmt/mcumgr/transport/smp_dummy.h @@ -12,7 +12,7 @@ #define ZEPHYR_INCLUDE_MGMT_MCUMGR_TRANSPORT_DUMMY_H_ #include -#include +#include #include #include diff --git a/include/zephyr/net/buf.h b/include/zephyr/net/buf.h index 88152bc9905..c537c03057f 100644 --- a/include/zephyr/net/buf.h +++ b/include/zephyr/net/buf.h @@ -1,2731 +1,14 @@ -/** @file - * @brief Buffer management. - */ - /* * Copyright (c) 2015 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef ZEPHYR_INCLUDE_NET_BUF_H_ -#define ZEPHYR_INCLUDE_NET_BUF_H_ -#include -#include -#include -#include -#include +#ifndef ZEPHYR_INCLUDE_NET_BUF_DEPRECATED_H_ +#define ZEPHYR_INCLUDE_NET_BUF_DEPRECATED_H_ -#ifdef __cplusplus -extern "C" { -#endif +#include -/** - * @brief Network buffer library - * @defgroup net_buf Network Buffer Library - * @since 1.0 - * @version 1.0.0 - * @ingroup networking - * @{ - */ +#warning This header is deprecated, include instead -/* Alignment needed for various parts of the buffer definition */ -#if CONFIG_NET_BUF_ALIGNMENT == 0 -#define __net_buf_align __aligned(sizeof(void *)) -#else -#define __net_buf_align __aligned(CONFIG_NET_BUF_ALIGNMENT) -#endif - -/** - * @brief Define a net_buf_simple stack variable. - * - * This is a helper macro which is used to define a net_buf_simple object - * on the stack. - * - * @param _name Name of the net_buf_simple object. - * @param _size Maximum data storage for the buffer. - */ -#define NET_BUF_SIMPLE_DEFINE(_name, _size) \ - uint8_t net_buf_data_##_name[_size]; \ - struct net_buf_simple _name = { \ - .data = net_buf_data_##_name, \ - .len = 0, \ - .size = _size, \ - .__buf = net_buf_data_##_name, \ - } - -/** - * - * @brief Define a static net_buf_simple variable. - * - * This is a helper macro which is used to define a static net_buf_simple - * object. - * - * @param _name Name of the net_buf_simple object. - * @param _size Maximum data storage for the buffer. - */ -#define NET_BUF_SIMPLE_DEFINE_STATIC(_name, _size) \ - static __noinit uint8_t net_buf_data_##_name[_size]; \ - static struct net_buf_simple _name = { \ - .data = net_buf_data_##_name, \ - .len = 0, \ - .size = _size, \ - .__buf = net_buf_data_##_name, \ - } - -/** - * @brief Simple network buffer representation. - * - * This is a simpler variant of the net_buf object (in fact net_buf uses - * net_buf_simple internally). It doesn't provide any kind of reference - * counting, user data, dynamic allocation, or in general the ability to - * pass through kernel objects such as FIFOs. - * - * The main use of this is for scenarios where the meta-data of the normal - * net_buf isn't needed and causes too much overhead. This could be e.g. - * when the buffer only needs to be allocated on the stack or when the - * access to and lifetime of the buffer is well controlled and constrained. - */ -struct net_buf_simple { - /** Pointer to the start of data in the buffer. */ - uint8_t *data; - - /** - * Length of the data behind the data pointer. - * - * To determine the max length, use net_buf_simple_max_len(), not #size! - */ - uint16_t len; - - /** Amount of data that net_buf_simple#__buf can store. */ - uint16_t size; - - /** Start of the data storage. Not to be accessed directly - * (the data pointer should be used instead). - */ - uint8_t *__buf; -}; - -/** - * - * @brief Define a net_buf_simple stack variable and get a pointer to it. - * - * This is a helper macro which is used to define a net_buf_simple object on - * the stack and the get a pointer to it as follows: - * - * struct net_buf_simple *my_buf = NET_BUF_SIMPLE(10); - * - * After creating the object it needs to be initialized by calling - * net_buf_simple_init(). - * - * @param _size Maximum data storage for the buffer. - * - * @return Pointer to stack-allocated net_buf_simple object. - */ -#define NET_BUF_SIMPLE(_size) \ - ((struct net_buf_simple *)(&(struct { \ - struct net_buf_simple buf; \ - uint8_t data[_size]; \ - }) { \ - .buf.size = _size, \ - })) - -/** - * @brief Initialize a net_buf_simple object. - * - * This needs to be called after creating a net_buf_simple object using - * the NET_BUF_SIMPLE macro. - * - * @param buf Buffer to initialize. - * @param reserve_head Headroom to reserve. - */ -static inline void net_buf_simple_init(struct net_buf_simple *buf, - size_t reserve_head) -{ - if (!buf->__buf) { - buf->__buf = (uint8_t *)buf + sizeof(*buf); - } - - buf->data = buf->__buf + reserve_head; - buf->len = 0U; -} - -/** - * @brief Initialize a net_buf_simple object with data. - * - * Initialized buffer object with external data. - * - * @param buf Buffer to initialize. - * @param data External data pointer - * @param size Amount of data the pointed data buffer if able to fit. - */ -void net_buf_simple_init_with_data(struct net_buf_simple *buf, - void *data, size_t size); - -/** - * @brief Reset buffer - * - * Reset buffer data so it can be reused for other purposes. - * - * @param buf Buffer to reset. - */ -static inline void net_buf_simple_reset(struct net_buf_simple *buf) -{ - buf->len = 0U; - buf->data = buf->__buf; -} - -/** - * Clone buffer state, using the same data buffer. - * - * Initializes a buffer to point to the same data as an existing buffer. - * Allows operations on the same data without altering the length and - * offset of the original. - * - * @param original Buffer to clone. - * @param clone The new clone. - */ -void net_buf_simple_clone(const struct net_buf_simple *original, - struct net_buf_simple *clone); - -/** - * @brief Prepare data to be added at the end of the buffer - * - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param len Number of bytes to increment the length with. - * - * @return The original tail of the buffer. - */ -void *net_buf_simple_add(struct net_buf_simple *buf, size_t len); - -/** - * @brief Copy given number of bytes from memory to the end of the buffer - * - * Increments the data length of the buffer to account for more data at the - * end. - * - * @param buf Buffer to update. - * @param mem Location of data to be added. - * @param len Length of data to be added - * - * @return The original tail of the buffer. - */ -void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem, - size_t len); - -/** - * @brief Add (8-bit) byte at the end of the buffer - * - * Increments the data length of the buffer to account for more data at the - * end. - * - * @param buf Buffer to update. - * @param val byte value to be added. - * - * @return Pointer to the value added - */ -uint8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, uint8_t val); - -/** - * @brief Add 16-bit value at the end of the buffer - * - * Adds 16-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 16-bit value to be added. - */ -void net_buf_simple_add_le16(struct net_buf_simple *buf, uint16_t val); - -/** - * @brief Add 16-bit value at the end of the buffer - * - * Adds 16-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 16-bit value to be added. - */ -void net_buf_simple_add_be16(struct net_buf_simple *buf, uint16_t val); - -/** - * @brief Add 24-bit value at the end of the buffer - * - * Adds 24-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 24-bit value to be added. - */ -void net_buf_simple_add_le24(struct net_buf_simple *buf, uint32_t val); - -/** - * @brief Add 24-bit value at the end of the buffer - * - * Adds 24-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 24-bit value to be added. - */ -void net_buf_simple_add_be24(struct net_buf_simple *buf, uint32_t val); - -/** - * @brief Add 32-bit value at the end of the buffer - * - * Adds 32-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 32-bit value to be added. - */ -void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val); - -/** - * @brief Add 32-bit value at the end of the buffer - * - * Adds 32-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 32-bit value to be added. - */ -void net_buf_simple_add_be32(struct net_buf_simple *buf, uint32_t val); - -/** - * @brief Add 40-bit value at the end of the buffer - * - * Adds 40-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 40-bit value to be added. - */ -void net_buf_simple_add_le40(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Add 40-bit value at the end of the buffer - * - * Adds 40-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 40-bit value to be added. - */ -void net_buf_simple_add_be40(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Add 48-bit value at the end of the buffer - * - * Adds 48-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 48-bit value to be added. - */ -void net_buf_simple_add_le48(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Add 48-bit value at the end of the buffer - * - * Adds 48-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 48-bit value to be added. - */ -void net_buf_simple_add_be48(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Add 64-bit value at the end of the buffer - * - * Adds 64-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 64-bit value to be added. - */ -void net_buf_simple_add_le64(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Add 64-bit value at the end of the buffer - * - * Adds 64-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 64-bit value to be added. - */ -void net_buf_simple_add_be64(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Remove data from the end of the buffer. - * - * Removes data from the end of the buffer by modifying the buffer length. - * - * @param buf Buffer to update. - * @param len Number of bytes to remove. - * - * @return New end of the buffer data. - */ -void *net_buf_simple_remove_mem(struct net_buf_simple *buf, size_t len); - -/** - * @brief Remove a 8-bit value from the end of the buffer - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 8-bit values. - * - * @param buf A valid pointer on a buffer. - * - * @return The 8-bit removed value - */ -uint8_t net_buf_simple_remove_u8(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 16 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 16-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 16-bit value converted from little endian to host endian. - */ -uint16_t net_buf_simple_remove_le16(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 16 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 16-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 16-bit value converted from big endian to host endian. - */ -uint16_t net_buf_simple_remove_be16(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 24 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 24-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 24-bit value converted from little endian to host endian. - */ -uint32_t net_buf_simple_remove_le24(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 24 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 24-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 24-bit value converted from big endian to host endian. - */ -uint32_t net_buf_simple_remove_be24(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 32 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 32-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 32-bit value converted from little endian to host endian. - */ -uint32_t net_buf_simple_remove_le32(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 32 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 32-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 32-bit value converted from big endian to host endian. - */ -uint32_t net_buf_simple_remove_be32(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 40 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 40-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 40-bit value converted from little endian to host endian. - */ -uint64_t net_buf_simple_remove_le40(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 40 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 40-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 40-bit value converted from big endian to host endian. - */ -uint64_t net_buf_simple_remove_be40(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 48 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 48-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 48-bit value converted from little endian to host endian. - */ -uint64_t net_buf_simple_remove_le48(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 48 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 48-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 48-bit value converted from big endian to host endian. - */ -uint64_t net_buf_simple_remove_be48(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 64 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 64-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 64-bit value converted from little endian to host endian. - */ -uint64_t net_buf_simple_remove_le64(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 64 bits from the end of the buffer. - * - * Same idea as with net_buf_simple_remove_mem(), but a helper for operating - * on 64-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 64-bit value converted from big endian to host endian. - */ -uint64_t net_buf_simple_remove_be64(struct net_buf_simple *buf); - -/** - * @brief Prepare data to be added to the start of the buffer - * - * Modifies the data pointer and buffer length to account for more data - * in the beginning of the buffer. - * - * @param buf Buffer to update. - * @param len Number of bytes to add to the beginning. - * - * @return The new beginning of the buffer data. - */ -void *net_buf_simple_push(struct net_buf_simple *buf, size_t len); - -/** - * @brief Copy given number of bytes from memory to the start of the buffer. - * - * Modifies the data pointer and buffer length to account for more data - * in the beginning of the buffer. - * - * @param buf Buffer to update. - * @param mem Location of data to be added. - * @param len Length of data to be added. - * - * @return The new beginning of the buffer data. - */ -void *net_buf_simple_push_mem(struct net_buf_simple *buf, const void *mem, - size_t len); - -/** - * @brief Push 16-bit value to the beginning of the buffer - * - * Adds 16-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 16-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_le16(struct net_buf_simple *buf, uint16_t val); - -/** - * @brief Push 16-bit value to the beginning of the buffer - * - * Adds 16-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 16-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_be16(struct net_buf_simple *buf, uint16_t val); - -/** - * @brief Push 8-bit value to the beginning of the buffer - * - * Adds 8-bit value the beginning of the buffer. - * - * @param buf Buffer to update. - * @param val 8-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_u8(struct net_buf_simple *buf, uint8_t val); - -/** - * @brief Push 24-bit value to the beginning of the buffer - * - * Adds 24-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 24-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_le24(struct net_buf_simple *buf, uint32_t val); - -/** - * @brief Push 24-bit value to the beginning of the buffer - * - * Adds 24-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 24-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_be24(struct net_buf_simple *buf, uint32_t val); - -/** - * @brief Push 32-bit value to the beginning of the buffer - * - * Adds 32-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 32-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_le32(struct net_buf_simple *buf, uint32_t val); - -/** - * @brief Push 32-bit value to the beginning of the buffer - * - * Adds 32-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 32-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_be32(struct net_buf_simple *buf, uint32_t val); - -/** - * @brief Push 40-bit value to the beginning of the buffer - * - * Adds 40-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 40-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_le40(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Push 40-bit value to the beginning of the buffer - * - * Adds 40-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 40-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_be40(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Push 48-bit value to the beginning of the buffer - * - * Adds 48-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 48-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_le48(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Push 48-bit value to the beginning of the buffer - * - * Adds 48-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 48-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_be48(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Push 64-bit value to the beginning of the buffer - * - * Adds 64-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 64-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_le64(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Push 64-bit value to the beginning of the buffer - * - * Adds 64-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 64-bit value to be pushed to the buffer. - */ -void net_buf_simple_push_be64(struct net_buf_simple *buf, uint64_t val); - -/** - * @brief Remove data from the beginning of the buffer. - * - * Removes data from the beginning of the buffer by modifying the data - * pointer and buffer length. - * - * @param buf Buffer to update. - * @param len Number of bytes to remove. - * - * @return New beginning of the buffer data. - */ -void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len); - -/** - * @brief Remove data from the beginning of the buffer. - * - * Removes data from the beginning of the buffer by modifying the data - * pointer and buffer length. - * - * @param buf Buffer to update. - * @param len Number of bytes to remove. - * - * @return Pointer to the old location of the buffer data. - */ -void *net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len); - -/** - * @brief Remove a 8-bit value from the beginning of the buffer - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 8-bit values. - * - * @param buf A valid pointer on a buffer. - * - * @return The 8-bit removed value - */ -uint8_t net_buf_simple_pull_u8(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 16 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 16-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 16-bit value converted from little endian to host endian. - */ -uint16_t net_buf_simple_pull_le16(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 16 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 16-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 16-bit value converted from big endian to host endian. - */ -uint16_t net_buf_simple_pull_be16(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 24 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 24-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 24-bit value converted from little endian to host endian. - */ -uint32_t net_buf_simple_pull_le24(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 24 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 24-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 24-bit value converted from big endian to host endian. - */ -uint32_t net_buf_simple_pull_be24(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 32 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 32-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 32-bit value converted from little endian to host endian. - */ -uint32_t net_buf_simple_pull_le32(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 32 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 32-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 32-bit value converted from big endian to host endian. - */ -uint32_t net_buf_simple_pull_be32(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 40 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 40-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 40-bit value converted from little endian to host endian. - */ -uint64_t net_buf_simple_pull_le40(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 40 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 40-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 40-bit value converted from big endian to host endian. - */ -uint64_t net_buf_simple_pull_be40(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 48 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 48-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 48-bit value converted from little endian to host endian. - */ -uint64_t net_buf_simple_pull_le48(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 48 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 48-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 48-bit value converted from big endian to host endian. - */ -uint64_t net_buf_simple_pull_be48(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 64 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 64-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 64-bit value converted from little endian to host endian. - */ -uint64_t net_buf_simple_pull_le64(struct net_buf_simple *buf); - -/** - * @brief Remove and convert 64 bits from the beginning of the buffer. - * - * Same idea as with net_buf_simple_pull(), but a helper for operating - * on 64-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 64-bit value converted from big endian to host endian. - */ -uint64_t net_buf_simple_pull_be64(struct net_buf_simple *buf); - -/** - * @brief Get the tail pointer for a buffer. - * - * Get a pointer to the end of the data in a buffer. - * - * @param buf Buffer. - * - * @return Tail pointer for the buffer. - */ -static inline uint8_t *net_buf_simple_tail(const struct net_buf_simple *buf) -{ - return buf->data + buf->len; -} - -/** - * @brief Check buffer headroom. - * - * Check how much free space there is in the beginning of the buffer. - * - * buf A valid pointer on a buffer - * - * @return Number of bytes available in the beginning of the buffer. - */ -size_t net_buf_simple_headroom(const struct net_buf_simple *buf); - -/** - * @brief Check buffer tailroom. - * - * Check how much free space there is at the end of the buffer. - * - * @param buf A valid pointer on a buffer - * - * @return Number of bytes available at the end of the buffer. - */ -size_t net_buf_simple_tailroom(const struct net_buf_simple *buf); - -/** - * @brief Check maximum net_buf_simple::len value. - * - * This value is depending on the number of bytes being reserved as headroom. - * - * @param buf A valid pointer on a buffer - * - * @return Number of bytes usable behind the net_buf_simple::data pointer. - */ -uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf); - -/** - * @brief Parsing state of a buffer. - * - * This is used for temporarily storing the parsing state of a buffer - * while giving control of the parsing to a routine which we don't - * control. - */ -struct net_buf_simple_state { - /** Offset of the data pointer from the beginning of the storage */ - uint16_t offset; - /** Length of data */ - uint16_t len; -}; - -/** - * @brief Save the parsing state of a buffer. - * - * Saves the parsing state of a buffer so it can be restored later. - * - * @param buf Buffer from which the state should be saved. - * @param state Storage for the state. - */ -static inline void net_buf_simple_save(const struct net_buf_simple *buf, - struct net_buf_simple_state *state) -{ - state->offset = (uint16_t)net_buf_simple_headroom(buf); - state->len = buf->len; -} - -/** - * @brief Restore the parsing state of a buffer. - * - * Restores the parsing state of a buffer from a state previously stored - * by net_buf_simple_save(). - * - * @param buf Buffer to which the state should be restored. - * @param state Stored state. - */ -static inline void net_buf_simple_restore(struct net_buf_simple *buf, - struct net_buf_simple_state *state) -{ - buf->data = buf->__buf + state->offset; - buf->len = state->len; -} - -/** - * Flag indicating that the buffer's associated data pointer, points to - * externally allocated memory. Therefore once ref goes down to zero, the - * pointed data will not need to be deallocated. This never needs to be - * explicitly set or unset by the net_buf API user. Such net_buf is - * exclusively instantiated via net_buf_alloc_with_data() function. - * Reference count mechanism however will behave the same way, and ref - * count going to 0 will free the net_buf but no the data pointer in it. - */ -#define NET_BUF_EXTERNAL_DATA BIT(0) - -/** - * @brief Network buffer representation. - * - * This struct is used to represent network buffers. Such buffers are - * normally defined through the NET_BUF_POOL_*_DEFINE() APIs and allocated - * using the net_buf_alloc() API. - */ -struct net_buf { - /** Allow placing the buffer into sys_slist_t */ - sys_snode_t node; - - /** Fragments associated with this buffer. */ - struct net_buf *frags; - - /** Reference count. */ - uint8_t ref; - - /** Bit-field of buffer flags. */ - uint8_t flags; - - /** Where the buffer should go when freed up. */ - uint8_t pool_id; - - /** Size of user data on this buffer */ - uint8_t user_data_size; - - /** Union for convenience access to the net_buf_simple members, also - * preserving the old API. - */ - union { - /* The ABI of this struct must match net_buf_simple */ - struct { - /** Pointer to the start of data in the buffer. */ - uint8_t *data; - - /** Length of the data behind the data pointer. */ - uint16_t len; - - /** Amount of data that this buffer can store. */ - uint16_t size; - - /** Start of the data storage. Not to be accessed - * directly (the data pointer should be used - * instead). - */ - uint8_t *__buf; - }; - - /** @cond INTERNAL_HIDDEN */ - struct net_buf_simple b; - /** @endcond */ - }; - - /** System metadata for this buffer. Cleared on allocation. */ - uint8_t user_data[] __net_buf_align; -}; - -/** @cond INTERNAL_HIDDEN */ - -struct net_buf_data_cb { - uint8_t * __must_check (*alloc)(struct net_buf *buf, size_t *size, - k_timeout_t timeout); - uint8_t * __must_check (*ref)(struct net_buf *buf, uint8_t *data); - void (*unref)(struct net_buf *buf, uint8_t *data); -}; - -struct net_buf_data_alloc { - const struct net_buf_data_cb *cb; - void *alloc_data; - size_t max_alloc_size; -}; - -/** @endcond */ - -/** - * @brief Network buffer pool representation. - * - * This struct is used to represent a pool of network buffers. - */ -struct net_buf_pool { - /** LIFO to place the buffer into when free */ - struct k_lifo free; - - /** To prevent concurrent access/modifications */ - struct k_spinlock lock; - - /** Number of buffers in pool */ - const uint16_t buf_count; - - /** Number of uninitialized buffers */ - uint16_t uninit_count; - - /** Size of user data allocated to this pool */ - uint8_t user_data_size; - -#if defined(CONFIG_NET_BUF_POOL_USAGE) - /** Amount of available buffers in the pool. */ - atomic_t avail_count; - - /** Total size of the pool. */ - const uint16_t pool_size; - - /** Name of the pool. Used when printing pool information. */ - const char *name; -#endif /* CONFIG_NET_BUF_POOL_USAGE */ - - /** Optional destroy callback when buffer is freed. */ - void (*const destroy)(struct net_buf *buf); - - /** Data allocation handlers. */ - const struct net_buf_data_alloc *alloc; - - /** Start of buffer storage array */ - struct net_buf * const __bufs; -}; - -/** @cond INTERNAL_HIDDEN */ -#define NET_BUF_POOL_USAGE_INIT(_pool, _count) \ - IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.avail_count = ATOMIC_INIT(_count),)) \ - IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.name = STRINGIFY(_pool),)) - -#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \ - { \ - .free = Z_LIFO_INITIALIZER(_pool.free), \ - .lock = { }, \ - .buf_count = _count, \ - .uninit_count = _count, \ - .user_data_size = _ud_size, \ - NET_BUF_POOL_USAGE_INIT(_pool, _count) \ - .destroy = _destroy, \ - .alloc = _alloc, \ - .__bufs = (struct net_buf *)_bufs, \ - } - -#define _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size) \ - struct _net_buf_##_name { uint8_t b[sizeof(struct net_buf)]; \ - uint8_t ud[_ud_size]; } __net_buf_align; \ - BUILD_ASSERT(_ud_size <= UINT8_MAX); \ - BUILD_ASSERT(offsetof(struct net_buf, user_data) == \ - offsetof(struct _net_buf_##_name, ud), "Invalid offset"); \ - BUILD_ASSERT(__alignof__(struct net_buf) == \ - __alignof__(struct _net_buf_##_name), "Invalid alignment"); \ - BUILD_ASSERT(sizeof(struct _net_buf_##_name) == \ - ROUND_UP(sizeof(struct net_buf) + _ud_size, __alignof__(struct net_buf)), \ - "Size cannot be determined"); \ - static struct _net_buf_##_name _net_buf_##_name[_count] __noinit - -extern const struct net_buf_data_alloc net_buf_heap_alloc; -/** @endcond */ - -/** - * - * @brief Define a new pool for buffers using the heap for the data. - * - * Defines a net_buf_pool struct and the necessary memory storage (array of - * structs) for the needed amount of buffers. After this, the buffers can be - * accessed from the pool through net_buf_alloc. The pool is defined as a - * static variable, so if it needs to be exported outside the current module - * this needs to happen with the help of a separate pointer rather than an - * extern declaration. - * - * The data payload of the buffers will be allocated from the heap using - * k_malloc, so CONFIG_HEAP_MEM_POOL_SIZE must be set to a positive value. - * This kind of pool does not support blocking on the data allocation, so - * the timeout passed to net_buf_alloc will be always treated as K_NO_WAIT - * when trying to allocate the data. This means that allocation failures, - * i.e. NULL returns, must always be handled cleanly. - * - * If provided with a custom destroy callback, this callback is - * responsible for eventually calling net_buf_destroy() to complete the - * process of returning the buffer to the pool. - * - * @param _name Name of the pool variable. - * @param _count Number of buffers in the pool. - * @param _ud_size User data space to reserve per buffer. - * @param _destroy Optional destroy callback when buffer is freed. - */ -#define NET_BUF_POOL_HEAP_DEFINE(_name, _count, _ud_size, _destroy) \ - _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \ - static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \ - NET_BUF_POOL_INITIALIZER(_name, &net_buf_heap_alloc, \ - _net_buf_##_name, _count, _ud_size, \ - _destroy) - -/** @cond INTERNAL_HIDDEN */ - -struct net_buf_pool_fixed { - uint8_t *data_pool; -}; - -extern const struct net_buf_data_cb net_buf_fixed_cb; - -/** @endcond */ - -/** - * - * @brief Define a new pool for buffers based on fixed-size data - * - * Defines a net_buf_pool struct and the necessary memory storage (array of - * structs) for the needed amount of buffers. After this, the buffers can be - * accessed from the pool through net_buf_alloc. The pool is defined as a - * static variable, so if it needs to be exported outside the current module - * this needs to happen with the help of a separate pointer rather than an - * extern declaration. - * - * The data payload of the buffers will be allocated from a byte array - * of fixed sized chunks. This kind of pool does not support blocking on - * the data allocation, so the timeout passed to net_buf_alloc will be - * always treated as K_NO_WAIT when trying to allocate the data. This means - * that allocation failures, i.e. NULL returns, must always be handled - * cleanly. - * - * If provided with a custom destroy callback, this callback is - * responsible for eventually calling net_buf_destroy() to complete the - * process of returning the buffer to the pool. - * - * @param _name Name of the pool variable. - * @param _count Number of buffers in the pool. - * @param _data_size Maximum data payload per buffer. - * @param _ud_size User data space to reserve per buffer. - * @param _destroy Optional destroy callback when buffer is freed. - */ -#define NET_BUF_POOL_FIXED_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \ - _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \ - static uint8_t __noinit net_buf_data_##_name[_count][_data_size] __net_buf_align; \ - static const struct net_buf_pool_fixed net_buf_fixed_##_name = { \ - .data_pool = (uint8_t *)net_buf_data_##_name, \ - }; \ - static const struct net_buf_data_alloc net_buf_fixed_alloc_##_name = { \ - .cb = &net_buf_fixed_cb, \ - .alloc_data = (void *)&net_buf_fixed_##_name, \ - .max_alloc_size = _data_size, \ - }; \ - static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \ - NET_BUF_POOL_INITIALIZER(_name, &net_buf_fixed_alloc_##_name, \ - _net_buf_##_name, _count, _ud_size, \ - _destroy) - -/** @cond INTERNAL_HIDDEN */ -extern const struct net_buf_data_cb net_buf_var_cb; -/** @endcond */ - -/** - * - * @brief Define a new pool for buffers with variable size payloads - * - * Defines a net_buf_pool struct and the necessary memory storage (array of - * structs) for the needed amount of buffers. After this, the buffers can be - * accessed from the pool through net_buf_alloc. The pool is defined as a - * static variable, so if it needs to be exported outside the current module - * this needs to happen with the help of a separate pointer rather than an - * extern declaration. - * - * The data payload of the buffers will be based on a memory pool from which - * variable size payloads may be allocated. - * - * If provided with a custom destroy callback, this callback is - * responsible for eventually calling net_buf_destroy() to complete the - * process of returning the buffer to the pool. - * - * @param _name Name of the pool variable. - * @param _count Number of buffers in the pool. - * @param _data_size Total amount of memory available for data payloads. - * @param _ud_size User data space to reserve per buffer. - * @param _destroy Optional destroy callback when buffer is freed. - */ -#define NET_BUF_POOL_VAR_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \ - _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \ - K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \ - static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \ - .cb = &net_buf_var_cb, \ - .alloc_data = &net_buf_mem_pool_##_name, \ - .max_alloc_size = 0, \ - }; \ - static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \ - NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \ - _net_buf_##_name, _count, _ud_size, \ - _destroy) - -/** - * - * @brief Define a new pool for buffers - * - * Defines a net_buf_pool struct and the necessary memory storage (array of - * structs) for the needed amount of buffers. After this,the buffers can be - * accessed from the pool through net_buf_alloc. The pool is defined as a - * static variable, so if it needs to be exported outside the current module - * this needs to happen with the help of a separate pointer rather than an - * extern declaration. - * - * If provided with a custom destroy callback this callback is - * responsible for eventually calling net_buf_destroy() to complete the - * process of returning the buffer to the pool. - * - * @param _name Name of the pool variable. - * @param _count Number of buffers in the pool. - * @param _size Maximum data size for each buffer. - * @param _ud_size Amount of user data space to reserve. - * @param _destroy Optional destroy callback when buffer is freed. - */ -#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy) \ - NET_BUF_POOL_FIXED_DEFINE(_name, _count, _size, _ud_size, _destroy) - -/** - * @brief Looks up a pool based on its ID. - * - * @param id Pool ID (e.g. from buf->pool_id). - * - * @return Pointer to pool. - */ -struct net_buf_pool *net_buf_pool_get(int id); - -/** - * @brief Get a zero-based index for a buffer. - * - * This function will translate a buffer into a zero-based index, - * based on its placement in its buffer pool. This can be useful if you - * want to associate an external array of meta-data contexts with the - * buffers of a pool. - * - * @param buf Network buffer. - * - * @return Zero-based index for the buffer. - */ -int net_buf_id(const struct net_buf *buf); - -/** - * @brief Allocate a new fixed buffer from a pool. - * - * @note Some types of data allocators do not support - * blocking (such as the HEAP type). In this case it's still possible - * for net_buf_alloc() to fail (return NULL) even if it was given - * K_FOREVER. - * - * @note The timeout value will be overridden to K_NO_WAIT if called from the - * system workqueue. - * - * @param pool Which pool to allocate the buffer from. - * @param timeout Affects the action taken should the pool be empty. - * If K_NO_WAIT, then return immediately. If K_FOREVER, then - * wait as long as necessary. Otherwise, wait until the specified - * timeout. - * - * @return New buffer or NULL if out of buffers. - */ -#if defined(CONFIG_NET_BUF_LOG) -struct net_buf * __must_check net_buf_alloc_fixed_debug(struct net_buf_pool *pool, - k_timeout_t timeout, - const char *func, - int line); -#define net_buf_alloc_fixed(_pool, _timeout) \ - net_buf_alloc_fixed_debug(_pool, _timeout, __func__, __LINE__) -#else -struct net_buf * __must_check net_buf_alloc_fixed(struct net_buf_pool *pool, - k_timeout_t timeout); -#endif - -/** - * @copydetails net_buf_alloc_fixed - */ -static inline struct net_buf * __must_check net_buf_alloc(struct net_buf_pool *pool, - k_timeout_t timeout) -{ - return net_buf_alloc_fixed(pool, timeout); -} - -/** - * @brief Allocate a new variable length buffer from a pool. - * - * @note Some types of data allocators do not support - * blocking (such as the HEAP type). In this case it's still possible - * for net_buf_alloc() to fail (return NULL) even if it was given - * K_FOREVER. - * - * @note The timeout value will be overridden to K_NO_WAIT if called from the - * system workqueue. - * - * @param pool Which pool to allocate the buffer from. - * @param size Amount of data the buffer must be able to fit. - * @param timeout Affects the action taken should the pool be empty. - * If K_NO_WAIT, then return immediately. If K_FOREVER, then - * wait as long as necessary. Otherwise, wait until the specified - * timeout. - * - * @return New buffer or NULL if out of buffers. - */ -#if defined(CONFIG_NET_BUF_LOG) -struct net_buf * __must_check net_buf_alloc_len_debug(struct net_buf_pool *pool, - size_t size, - k_timeout_t timeout, - const char *func, - int line); -#define net_buf_alloc_len(_pool, _size, _timeout) \ - net_buf_alloc_len_debug(_pool, _size, _timeout, __func__, __LINE__) -#else -struct net_buf * __must_check net_buf_alloc_len(struct net_buf_pool *pool, - size_t size, - k_timeout_t timeout); -#endif - -/** - * @brief Allocate a new buffer from a pool but with external data pointer. - * - * Allocate a new buffer from a pool, where the data pointer comes from the - * user and not from the pool. - * - * @note Some types of data allocators do not support - * blocking (such as the HEAP type). In this case it's still possible - * for net_buf_alloc() to fail (return NULL) even if it was given - * K_FOREVER. - * - * @note The timeout value will be overridden to K_NO_WAIT if called from the - * system workqueue. - * - * @param pool Which pool to allocate the buffer from. - * @param data External data pointer - * @param size Amount of data the pointed data buffer if able to fit. - * @param timeout Affects the action taken should the pool be empty. - * If K_NO_WAIT, then return immediately. If K_FOREVER, then - * wait as long as necessary. Otherwise, wait until the specified - * timeout. - * - * @return New buffer or NULL if out of buffers. - */ -#if defined(CONFIG_NET_BUF_LOG) -struct net_buf * __must_check net_buf_alloc_with_data_debug(struct net_buf_pool *pool, - void *data, size_t size, - k_timeout_t timeout, - const char *func, int line); -#define net_buf_alloc_with_data(_pool, _data_, _size, _timeout) \ - net_buf_alloc_with_data_debug(_pool, _data_, _size, _timeout, \ - __func__, __LINE__) -#else -struct net_buf * __must_check net_buf_alloc_with_data(struct net_buf_pool *pool, - void *data, size_t size, - k_timeout_t timeout); -#endif - -/** - * @brief Get a buffer from a FIFO. - * - * @deprecated Use @a k_fifo_get() instead. - * - * @param fifo Which FIFO to take the buffer from. - * @param timeout Affects the action taken should the FIFO be empty. - * If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as - * long as necessary. Otherwise, wait until the specified timeout. - * - * @return New buffer or NULL if the FIFO is empty. - */ -#if defined(CONFIG_NET_BUF_LOG) -__deprecated struct net_buf * __must_check net_buf_get_debug(struct k_fifo *fifo, - k_timeout_t timeout, - const char *func, int line); -#define net_buf_get(_fifo, _timeout) \ - net_buf_get_debug(_fifo, _timeout, __func__, __LINE__) -#else -__deprecated struct net_buf * __must_check net_buf_get(struct k_fifo *fifo, - k_timeout_t timeout); -#endif - -/** - * @brief Destroy buffer from custom destroy callback - * - * This helper is only intended to be used from custom destroy callbacks. - * If no custom destroy callback is given to NET_BUF_POOL_*_DEFINE() then - * there is no need to use this API. - * - * @param buf Buffer to destroy. - */ -static inline void net_buf_destroy(struct net_buf *buf) -{ - struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id); - - if (buf->__buf) { - if (!(buf->flags & NET_BUF_EXTERNAL_DATA)) { - pool->alloc->cb->unref(buf, buf->__buf); - } - buf->__buf = NULL; - } - - k_lifo_put(&pool->free, buf); -} - -/** - * @brief Reset buffer - * - * Reset buffer data and flags so it can be reused for other purposes. - * - * @param buf Buffer to reset. - */ -void net_buf_reset(struct net_buf *buf); - -/** - * @brief Initialize buffer with the given headroom. - * - * The buffer is not expected to contain any data when this API is called. - * - * @param buf Buffer to initialize. - * @param reserve How much headroom to reserve. - */ -void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve); - -/** - * @brief Put a buffer into a list - * - * @param list Which list to append the buffer to. - * @param buf Buffer. - */ -void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf); - -/** - * @brief Get a buffer from a list. - * - * @param list Which list to take the buffer from. - * - * @return New buffer or NULL if the FIFO is empty. - */ -struct net_buf * __must_check net_buf_slist_get(sys_slist_t *list); - -/** - * @brief Put a buffer to the end of a FIFO. - * - * @deprecated Use @a k_fifo_put() instead. - * - * @param fifo Which FIFO to put the buffer to. - * @param buf Buffer. - */ -__deprecated void net_buf_put(struct k_fifo *fifo, struct net_buf *buf); - -/** - * @brief Decrements the reference count of a buffer. - * - * The buffer is put back into the pool if the reference count reaches zero. - * - * @param buf A valid pointer on a buffer - */ -#if defined(CONFIG_NET_BUF_LOG) -void net_buf_unref_debug(struct net_buf *buf, const char *func, int line); -#define net_buf_unref(_buf) \ - net_buf_unref_debug(_buf, __func__, __LINE__) -#else -void net_buf_unref(struct net_buf *buf); -#endif - -/** - * @brief Increment the reference count of a buffer. - * - * @param buf A valid pointer on a buffer - * - * @return the buffer newly referenced - */ -struct net_buf * __must_check net_buf_ref(struct net_buf *buf); - -/** - * @brief Clone buffer - * - * Duplicate given buffer including any (user) data and headers currently stored. - * - * @param buf A valid pointer on a buffer - * @param timeout Affects the action taken should the pool be empty. - * If K_NO_WAIT, then return immediately. If K_FOREVER, then - * wait as long as necessary. Otherwise, wait until the specified - * timeout. - * - * @return Cloned buffer or NULL if out of buffers. - */ -struct net_buf * __must_check net_buf_clone(struct net_buf *buf, - k_timeout_t timeout); - -/** - * @brief Get a pointer to the user data of a buffer. - * - * @param buf A valid pointer on a buffer - * - * @return Pointer to the user data of the buffer. - */ -static inline void * __must_check net_buf_user_data(const struct net_buf *buf) -{ - return (void *)buf->user_data; -} - -/** - * @brief Copy user data from one to another buffer. - * - * @param dst A valid pointer to a buffer gettings its user data overwritten. - * @param src A valid pointer to a buffer gettings its user data copied. User data size must be - * equal to or exceed @a dst. - * - * @return 0 on success or negative error number on failure. - */ -int net_buf_user_data_copy(struct net_buf *dst, const struct net_buf *src); - -/** - * @brief Initialize buffer with the given headroom. - * - * The buffer is not expected to contain any data when this API is called. - * - * @param buf Buffer to initialize. - * @param reserve How much headroom to reserve. - */ -static inline void net_buf_reserve(struct net_buf *buf, size_t reserve) -{ - net_buf_simple_reserve(&buf->b, reserve); -} - -/** - * @brief Prepare data to be added at the end of the buffer - * - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param len Number of bytes to increment the length with. - * - * @return The original tail of the buffer. - */ -static inline void *net_buf_add(struct net_buf *buf, size_t len) -{ - return net_buf_simple_add(&buf->b, len); -} - -/** - * @brief Copies the given number of bytes to the end of the buffer - * - * Increments the data length of the buffer to account for more data at - * the end. - * - * @param buf Buffer to update. - * @param mem Location of data to be added. - * @param len Length of data to be added - * - * @return The original tail of the buffer. - */ -static inline void *net_buf_add_mem(struct net_buf *buf, const void *mem, - size_t len) -{ - return net_buf_simple_add_mem(&buf->b, mem, len); -} - -/** - * @brief Add (8-bit) byte at the end of the buffer - * - * Increments the data length of the buffer to account for more data at - * the end. - * - * @param buf Buffer to update. - * @param val byte value to be added. - * - * @return Pointer to the value added - */ -static inline uint8_t *net_buf_add_u8(struct net_buf *buf, uint8_t val) -{ - return net_buf_simple_add_u8(&buf->b, val); -} - -/** - * @brief Add 16-bit value at the end of the buffer - * - * Adds 16-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 16-bit value to be added. - */ -static inline void net_buf_add_le16(struct net_buf *buf, uint16_t val) -{ - net_buf_simple_add_le16(&buf->b, val); -} - -/** - * @brief Add 16-bit value at the end of the buffer - * - * Adds 16-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 16-bit value to be added. - */ -static inline void net_buf_add_be16(struct net_buf *buf, uint16_t val) -{ - net_buf_simple_add_be16(&buf->b, val); -} - -/** - * @brief Add 24-bit value at the end of the buffer - * - * Adds 24-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 24-bit value to be added. - */ -static inline void net_buf_add_le24(struct net_buf *buf, uint32_t val) -{ - net_buf_simple_add_le24(&buf->b, val); -} - -/** - * @brief Add 24-bit value at the end of the buffer - * - * Adds 24-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 24-bit value to be added. - */ -static inline void net_buf_add_be24(struct net_buf *buf, uint32_t val) -{ - net_buf_simple_add_be24(&buf->b, val); -} - -/** - * @brief Add 32-bit value at the end of the buffer - * - * Adds 32-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 32-bit value to be added. - */ -static inline void net_buf_add_le32(struct net_buf *buf, uint32_t val) -{ - net_buf_simple_add_le32(&buf->b, val); -} - -/** - * @brief Add 32-bit value at the end of the buffer - * - * Adds 32-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 32-bit value to be added. - */ -static inline void net_buf_add_be32(struct net_buf *buf, uint32_t val) -{ - net_buf_simple_add_be32(&buf->b, val); -} - -/** - * @brief Add 40-bit value at the end of the buffer - * - * Adds 40-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 40-bit value to be added. - */ -static inline void net_buf_add_le40(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_add_le40(&buf->b, val); -} - -/** - * @brief Add 40-bit value at the end of the buffer - * - * Adds 40-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 40-bit value to be added. - */ -static inline void net_buf_add_be40(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_add_be40(&buf->b, val); -} - -/** - * @brief Add 48-bit value at the end of the buffer - * - * Adds 48-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 48-bit value to be added. - */ -static inline void net_buf_add_le48(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_add_le48(&buf->b, val); -} - -/** - * @brief Add 48-bit value at the end of the buffer - * - * Adds 48-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 48-bit value to be added. - */ -static inline void net_buf_add_be48(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_add_be48(&buf->b, val); -} - -/** - * @brief Add 64-bit value at the end of the buffer - * - * Adds 64-bit value in little endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 64-bit value to be added. - */ -static inline void net_buf_add_le64(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_add_le64(&buf->b, val); -} - -/** - * @brief Add 64-bit value at the end of the buffer - * - * Adds 64-bit value in big endian format at the end of buffer. - * Increments the data length of a buffer to account for more data - * at the end. - * - * @param buf Buffer to update. - * @param val 64-bit value to be added. - */ -static inline void net_buf_add_be64(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_add_be64(&buf->b, val); -} - -/** - * @brief Remove data from the end of the buffer. - * - * Removes data from the end of the buffer by modifying the buffer length. - * - * @param buf Buffer to update. - * @param len Number of bytes to remove. - * - * @return New end of the buffer data. - */ -static inline void *net_buf_remove_mem(struct net_buf *buf, size_t len) -{ - return net_buf_simple_remove_mem(&buf->b, len); -} - -/** - * @brief Remove a 8-bit value from the end of the buffer - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 8-bit values. - * - * @param buf A valid pointer on a buffer. - * - * @return The 8-bit removed value - */ -static inline uint8_t net_buf_remove_u8(struct net_buf *buf) -{ - return net_buf_simple_remove_u8(&buf->b); -} - -/** - * @brief Remove and convert 16 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 16-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 16-bit value converted from little endian to host endian. - */ -static inline uint16_t net_buf_remove_le16(struct net_buf *buf) -{ - return net_buf_simple_remove_le16(&buf->b); -} - -/** - * @brief Remove and convert 16 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 16-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 16-bit value converted from big endian to host endian. - */ -static inline uint16_t net_buf_remove_be16(struct net_buf *buf) -{ - return net_buf_simple_remove_be16(&buf->b); -} - -/** - * @brief Remove and convert 24 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 24-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 24-bit value converted from big endian to host endian. - */ -static inline uint32_t net_buf_remove_be24(struct net_buf *buf) -{ - return net_buf_simple_remove_be24(&buf->b); -} - -/** - * @brief Remove and convert 24 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 24-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 24-bit value converted from little endian to host endian. - */ -static inline uint32_t net_buf_remove_le24(struct net_buf *buf) -{ - return net_buf_simple_remove_le24(&buf->b); -} - -/** - * @brief Remove and convert 32 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 32-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 32-bit value converted from little endian to host endian. - */ -static inline uint32_t net_buf_remove_le32(struct net_buf *buf) -{ - return net_buf_simple_remove_le32(&buf->b); -} - -/** - * @brief Remove and convert 32 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 32-bit big endian data. - * - * @param buf A valid pointer on a buffer - * - * @return 32-bit value converted from big endian to host endian. - */ -static inline uint32_t net_buf_remove_be32(struct net_buf *buf) -{ - return net_buf_simple_remove_be32(&buf->b); -} - -/** - * @brief Remove and convert 40 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 40-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 40-bit value converted from little endian to host endian. - */ -static inline uint64_t net_buf_remove_le40(struct net_buf *buf) -{ - return net_buf_simple_remove_le40(&buf->b); -} - -/** - * @brief Remove and convert 40 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 40-bit big endian data. - * - * @param buf A valid pointer on a buffer - * - * @return 40-bit value converted from big endian to host endian. - */ -static inline uint64_t net_buf_remove_be40(struct net_buf *buf) -{ - return net_buf_simple_remove_be40(&buf->b); -} - -/** - * @brief Remove and convert 48 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 48-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 48-bit value converted from little endian to host endian. - */ -static inline uint64_t net_buf_remove_le48(struct net_buf *buf) -{ - return net_buf_simple_remove_le48(&buf->b); -} - -/** - * @brief Remove and convert 48 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 48-bit big endian data. - * - * @param buf A valid pointer on a buffer - * - * @return 48-bit value converted from big endian to host endian. - */ -static inline uint64_t net_buf_remove_be48(struct net_buf *buf) -{ - return net_buf_simple_remove_be48(&buf->b); -} - -/** - * @brief Remove and convert 64 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 64-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 64-bit value converted from little endian to host endian. - */ -static inline uint64_t net_buf_remove_le64(struct net_buf *buf) -{ - return net_buf_simple_remove_le64(&buf->b); -} - -/** - * @brief Remove and convert 64 bits from the end of the buffer. - * - * Same idea as with net_buf_remove_mem(), but a helper for operating on - * 64-bit big endian data. - * - * @param buf A valid pointer on a buffer - * - * @return 64-bit value converted from big endian to host endian. - */ -static inline uint64_t net_buf_remove_be64(struct net_buf *buf) -{ - return net_buf_simple_remove_be64(&buf->b); -} - -/** - * @brief Prepare data to be added at the start of the buffer - * - * Modifies the data pointer and buffer length to account for more data - * in the beginning of the buffer. - * - * @param buf Buffer to update. - * @param len Number of bytes to add to the beginning. - * - * @return The new beginning of the buffer data. - */ -static inline void *net_buf_push(struct net_buf *buf, size_t len) -{ - return net_buf_simple_push(&buf->b, len); -} - -/** - * @brief Copies the given number of bytes to the start of the buffer - * - * Modifies the data pointer and buffer length to account for more data - * in the beginning of the buffer. - * - * @param buf Buffer to update. - * @param mem Location of data to be added. - * @param len Length of data to be added. - * - * @return The new beginning of the buffer data. - */ -static inline void *net_buf_push_mem(struct net_buf *buf, const void *mem, - size_t len) -{ - return net_buf_simple_push_mem(&buf->b, mem, len); -} - -/** - * @brief Push 8-bit value to the beginning of the buffer - * - * Adds 8-bit value the beginning of the buffer. - * - * @param buf Buffer to update. - * @param val 8-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_u8(struct net_buf *buf, uint8_t val) -{ - net_buf_simple_push_u8(&buf->b, val); -} - -/** - * @brief Push 16-bit value to the beginning of the buffer - * - * Adds 16-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 16-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_le16(struct net_buf *buf, uint16_t val) -{ - net_buf_simple_push_le16(&buf->b, val); -} - -/** - * @brief Push 16-bit value to the beginning of the buffer - * - * Adds 16-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 16-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_be16(struct net_buf *buf, uint16_t val) -{ - net_buf_simple_push_be16(&buf->b, val); -} - -/** - * @brief Push 24-bit value to the beginning of the buffer - * - * Adds 24-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 24-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_le24(struct net_buf *buf, uint32_t val) -{ - net_buf_simple_push_le24(&buf->b, val); -} - -/** - * @brief Push 24-bit value to the beginning of the buffer - * - * Adds 24-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 24-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_be24(struct net_buf *buf, uint32_t val) -{ - net_buf_simple_push_be24(&buf->b, val); -} - -/** - * @brief Push 32-bit value to the beginning of the buffer - * - * Adds 32-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 32-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_le32(struct net_buf *buf, uint32_t val) -{ - net_buf_simple_push_le32(&buf->b, val); -} - -/** - * @brief Push 32-bit value to the beginning of the buffer - * - * Adds 32-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 32-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_be32(struct net_buf *buf, uint32_t val) -{ - net_buf_simple_push_be32(&buf->b, val); -} - -/** - * @brief Push 40-bit value to the beginning of the buffer - * - * Adds 40-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 40-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_le40(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_push_le40(&buf->b, val); -} - -/** - * @brief Push 40-bit value to the beginning of the buffer - * - * Adds 40-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 40-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_be40(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_push_be40(&buf->b, val); -} - -/** - * @brief Push 48-bit value to the beginning of the buffer - * - * Adds 48-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 48-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_le48(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_push_le48(&buf->b, val); -} - -/** - * @brief Push 48-bit value to the beginning of the buffer - * - * Adds 48-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 48-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_be48(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_push_be48(&buf->b, val); -} - -/** - * @brief Push 64-bit value to the beginning of the buffer - * - * Adds 64-bit value in little endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 64-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_le64(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_push_le64(&buf->b, val); -} - -/** - * @brief Push 64-bit value to the beginning of the buffer - * - * Adds 64-bit value in big endian format to the beginning of the - * buffer. - * - * @param buf Buffer to update. - * @param val 64-bit value to be pushed to the buffer. - */ -static inline void net_buf_push_be64(struct net_buf *buf, uint64_t val) -{ - net_buf_simple_push_be64(&buf->b, val); -} - -/** - * @brief Remove data from the beginning of the buffer. - * - * Removes data from the beginning of the buffer by modifying the data - * pointer and buffer length. - * - * @param buf Buffer to update. - * @param len Number of bytes to remove. - * - * @return New beginning of the buffer data. - */ -static inline void *net_buf_pull(struct net_buf *buf, size_t len) -{ - return net_buf_simple_pull(&buf->b, len); -} - -/** - * @brief Remove data from the beginning of the buffer. - * - * Removes data from the beginning of the buffer by modifying the data - * pointer and buffer length. - * - * @param buf Buffer to update. - * @param len Number of bytes to remove. - * - * @return Pointer to the old beginning of the buffer data. - */ -static inline void *net_buf_pull_mem(struct net_buf *buf, size_t len) -{ - return net_buf_simple_pull_mem(&buf->b, len); -} - -/** - * @brief Remove a 8-bit value from the beginning of the buffer - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 8-bit values. - * - * @param buf A valid pointer on a buffer. - * - * @return The 8-bit removed value - */ -static inline uint8_t net_buf_pull_u8(struct net_buf *buf) -{ - return net_buf_simple_pull_u8(&buf->b); -} - -/** - * @brief Remove and convert 16 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 16-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 16-bit value converted from little endian to host endian. - */ -static inline uint16_t net_buf_pull_le16(struct net_buf *buf) -{ - return net_buf_simple_pull_le16(&buf->b); -} - -/** - * @brief Remove and convert 16 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 16-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 16-bit value converted from big endian to host endian. - */ -static inline uint16_t net_buf_pull_be16(struct net_buf *buf) -{ - return net_buf_simple_pull_be16(&buf->b); -} - -/** - * @brief Remove and convert 24 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 24-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 24-bit value converted from little endian to host endian. - */ -static inline uint32_t net_buf_pull_le24(struct net_buf *buf) -{ - return net_buf_simple_pull_le24(&buf->b); -} - -/** - * @brief Remove and convert 24 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 24-bit big endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 24-bit value converted from big endian to host endian. - */ -static inline uint32_t net_buf_pull_be24(struct net_buf *buf) -{ - return net_buf_simple_pull_be24(&buf->b); -} - -/** - * @brief Remove and convert 32 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 32-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 32-bit value converted from little endian to host endian. - */ -static inline uint32_t net_buf_pull_le32(struct net_buf *buf) -{ - return net_buf_simple_pull_le32(&buf->b); -} - -/** - * @brief Remove and convert 32 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 32-bit big endian data. - * - * @param buf A valid pointer on a buffer - * - * @return 32-bit value converted from big endian to host endian. - */ -static inline uint32_t net_buf_pull_be32(struct net_buf *buf) -{ - return net_buf_simple_pull_be32(&buf->b); -} - -/** - * @brief Remove and convert 40 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 40-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 40-bit value converted from little endian to host endian. - */ -static inline uint64_t net_buf_pull_le40(struct net_buf *buf) -{ - return net_buf_simple_pull_le40(&buf->b); -} - -/** - * @brief Remove and convert 40 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 40-bit big endian data. - * - * @param buf A valid pointer on a buffer - * - * @return 40-bit value converted from big endian to host endian. - */ -static inline uint64_t net_buf_pull_be40(struct net_buf *buf) -{ - return net_buf_simple_pull_be40(&buf->b); -} - -/** - * @brief Remove and convert 48 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 48-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 48-bit value converted from little endian to host endian. - */ -static inline uint64_t net_buf_pull_le48(struct net_buf *buf) -{ - return net_buf_simple_pull_le48(&buf->b); -} - -/** - * @brief Remove and convert 48 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 48-bit big endian data. - * - * @param buf A valid pointer on a buffer - * - * @return 48-bit value converted from big endian to host endian. - */ -static inline uint64_t net_buf_pull_be48(struct net_buf *buf) -{ - return net_buf_simple_pull_be48(&buf->b); -} - -/** - * @brief Remove and convert 64 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 64-bit little endian data. - * - * @param buf A valid pointer on a buffer. - * - * @return 64-bit value converted from little endian to host endian. - */ -static inline uint64_t net_buf_pull_le64(struct net_buf *buf) -{ - return net_buf_simple_pull_le64(&buf->b); -} - -/** - * @brief Remove and convert 64 bits from the beginning of the buffer. - * - * Same idea as with net_buf_pull(), but a helper for operating on - * 64-bit big endian data. - * - * @param buf A valid pointer on a buffer - * - * @return 64-bit value converted from big endian to host endian. - */ -static inline uint64_t net_buf_pull_be64(struct net_buf *buf) -{ - return net_buf_simple_pull_be64(&buf->b); -} - -/** - * @brief Check buffer tailroom. - * - * Check how much free space there is at the end of the buffer. - * - * @param buf A valid pointer on a buffer - * - * @return Number of bytes available at the end of the buffer. - */ -static inline size_t net_buf_tailroom(const struct net_buf *buf) -{ - return net_buf_simple_tailroom(&buf->b); -} - -/** - * @brief Check buffer headroom. - * - * Check how much free space there is in the beginning of the buffer. - * - * buf A valid pointer on a buffer - * - * @return Number of bytes available in the beginning of the buffer. - */ -static inline size_t net_buf_headroom(const struct net_buf *buf) -{ - return net_buf_simple_headroom(&buf->b); -} - -/** - * @brief Check maximum net_buf::len value. - * - * This value is depending on the number of bytes being reserved as headroom. - * - * @param buf A valid pointer on a buffer - * - * @return Number of bytes usable behind the net_buf::data pointer. - */ -static inline uint16_t net_buf_max_len(const struct net_buf *buf) -{ - return net_buf_simple_max_len(&buf->b); -} - -/** - * @brief Get the tail pointer for a buffer. - * - * Get a pointer to the end of the data in a buffer. - * - * @param buf Buffer. - * - * @return Tail pointer for the buffer. - */ -static inline uint8_t *net_buf_tail(const struct net_buf *buf) -{ - return net_buf_simple_tail(&buf->b); -} - -/** - * @brief Find the last fragment in the fragment list. - * - * @return Pointer to last fragment in the list. - */ -struct net_buf *net_buf_frag_last(struct net_buf *frags); - -/** - * @brief Insert a new fragment to a chain of bufs. - * - * Insert a new fragment into the buffer fragments list after the parent. - * - * Note: This function takes ownership of the fragment reference so the - * caller is not required to unref. - * - * @param parent Parent buffer/fragment. - * @param frag Fragment to insert. - */ -void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag); - -/** - * @brief Add a new fragment to the end of a chain of bufs. - * - * Append a new fragment into the buffer fragments list. - * - * Note: This function takes ownership of the fragment reference so the - * caller is not required to unref. - * - * @param head Head of the fragment chain. - * @param frag Fragment to add. - * - * @return New head of the fragment chain. Either head (if head - * was non-NULL) or frag (if head was NULL). - */ -struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag); - -/** - * @brief Delete existing fragment from a chain of bufs. - * - * @param parent Parent buffer/fragment, or NULL if there is no parent. - * @param frag Fragment to delete. - * - * @return Pointer to the buffer following the fragment, or NULL if it - * had no further fragments. - */ -#if defined(CONFIG_NET_BUF_LOG) -struct net_buf *net_buf_frag_del_debug(struct net_buf *parent, - struct net_buf *frag, - const char *func, int line); -#define net_buf_frag_del(_parent, _frag) \ - net_buf_frag_del_debug(_parent, _frag, __func__, __LINE__) -#else -struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag); -#endif - -/** - * @brief Copy bytes from net_buf chain starting at offset to linear buffer - * - * Copy (extract) @a len bytes from @a src net_buf chain, starting from @a - * offset in it, to a linear buffer @a dst. Return number of bytes actually - * copied, which may be less than requested, if net_buf chain doesn't have - * enough data, or destination buffer is too small. - * - * @param dst Destination buffer - * @param dst_len Destination buffer length - * @param src Source net_buf chain - * @param offset Starting offset to copy from - * @param len Number of bytes to copy - * @return number of bytes actually copied - */ -size_t net_buf_linearize(void *dst, size_t dst_len, - const struct net_buf *src, size_t offset, size_t len); - -/** - * @typedef net_buf_allocator_cb - * @brief Network buffer allocator callback. - * - * @details The allocator callback is called when net_buf_append_bytes - * needs to allocate a new net_buf. - * - * @param timeout Affects the action taken should the net buf pool be empty. - * If K_NO_WAIT, then return immediately. If K_FOREVER, then - * wait as long as necessary. Otherwise, wait until the specified - * timeout. - * @param user_data The user data given in net_buf_append_bytes call. - * @return pointer to allocated net_buf or NULL on error. - */ -typedef struct net_buf * __must_check (*net_buf_allocator_cb)(k_timeout_t timeout, - void *user_data); - -/** - * @brief Append data to a list of net_buf - * - * @details Append data to a net_buf. If there is not enough space in the - * net_buf then more net_buf will be added, unless there are no free net_buf - * and timeout occurs. If not allocator is provided it attempts to allocate from - * the same pool as the original buffer. - * - * @param buf Network buffer. - * @param len Total length of input data - * @param value Data to be added - * @param timeout Timeout is passed to the net_buf allocator callback. - * @param allocate_cb When a new net_buf is required, use this callback. - * @param user_data A user data pointer to be supplied to the allocate_cb. - * This pointer is can be anything from a mem_pool or a net_pkt, the - * logic is left up to the allocate_cb function. - * - * @return Length of data actually added. This may be less than input - * length if other timeout than K_FOREVER was used, and there - * were no free fragments in a pool to accommodate all data. - */ -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); - -/** - * @brief Match data with a net_buf's content - * - * @details Compare data with a content of a net_buf. Provide information about - * the number of bytes matching between both. If needed, traverse - * through multiple buffer fragments. - * - * @param buf Network buffer - * @param offset Starting offset to compare from - * @param data Data buffer for comparison - * @param len Number of bytes to compare - * - * @return The number of bytes compared before the first difference. - */ -size_t net_buf_data_match(const struct net_buf *buf, size_t offset, const void *data, size_t len); - -/** - * @brief Skip N number of bytes in a net_buf - * - * @details Skip N number of bytes starting from fragment's offset. If the total - * length of data is placed in multiple fragments, this function will skip from - * all fragments until it reaches N number of bytes. Any fully skipped buffers - * are removed from the net_buf list. - * - * @param buf Network buffer. - * @param len Total length of data to be skipped. - * - * @return Pointer to the fragment or - * NULL and pos is 0 after successful skip, - * NULL and pos is 0xffff otherwise. - */ -static inline struct net_buf *net_buf_skip(struct net_buf *buf, size_t len) -{ - while (buf && len--) { - net_buf_pull_u8(buf); - if (!buf->len) { - buf = net_buf_frag_del(NULL, buf); - } - } - - return buf; -} - -/** - * @brief Calculate amount of bytes stored in fragments. - * - * Calculates the total amount of data stored in the given buffer and the - * fragments linked to it. - * - * @param buf Buffer to start off with. - * - * @return Number of bytes in the buffer and its fragments. - */ -static inline size_t net_buf_frags_len(const struct net_buf *buf) -{ - size_t bytes = 0; - - while (buf) { - bytes += buf->len; - buf = buf->frags; - } - - return bytes; -} - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_INCLUDE_NET_BUF_H_ */ +#endif /* ZEPHYR_INCLUDE_NET_BUF_DEPRECATED_H_ */ diff --git a/include/zephyr/net/ieee802154_ie.h b/include/zephyr/net/ieee802154_ie.h index a2378a38efa..ac520e65fec 100644 --- a/include/zephyr/net/ieee802154_ie.h +++ b/include/zephyr/net/ieee802154_ie.h @@ -23,7 +23,7 @@ #ifndef ZEPHYR_INCLUDE_NET_IEEE802154_IE_H_ #define ZEPHYR_INCLUDE_NET_IEEE802154_IE_H_ -#include +#include #include /** diff --git a/include/zephyr/net/mqtt_sn.h b/include/zephyr/net/mqtt_sn.h index 183564c6ce4..ec3f76e966e 100644 --- a/include/zephyr/net/mqtt_sn.h +++ b/include/zephyr/net/mqtt_sn.h @@ -24,7 +24,7 @@ #include -#include +#include #include #include diff --git a/include/zephyr/net/net_l2.h b/include/zephyr/net/net_l2.h index 6ae28d26600..37c9b083dd4 100644 --- a/include/zephyr/net/net_l2.h +++ b/include/zephyr/net/net_l2.h @@ -13,7 +13,7 @@ #define ZEPHYR_INCLUDE_NET_NET_L2_H_ #include -#include +#include #include #include diff --git a/include/zephyr/net/net_offload.h b/include/zephyr/net/net_offload.h index 1362658cb49..f1752672aec 100644 --- a/include/zephyr/net/net_offload.h +++ b/include/zephyr/net/net_offload.h @@ -21,7 +21,7 @@ * @{ */ -#include +#include #include #include diff --git a/include/zephyr/net/net_pkt.h b/include/zephyr/net/net_pkt.h index 71d203a7aa7..79ff34c9ae9 100644 --- a/include/zephyr/net/net_pkt.h +++ b/include/zephyr/net/net_pkt.h @@ -19,7 +19,7 @@ #include #include -#include +#include #if defined(CONFIG_IEEE802154) #include diff --git a/include/zephyr/net_buf.h b/include/zephyr/net_buf.h new file mode 100644 index 00000000000..02c041e9dca --- /dev/null +++ b/include/zephyr/net_buf.h @@ -0,0 +1,2731 @@ +/** @file + * @brief Buffer management. + */ + +/* + * Copyright (c) 2015 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_INCLUDE_NET_BUF_H_ +#define ZEPHYR_INCLUDE_NET_BUF_H_ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Network buffer library + * @defgroup net_buf Network Buffer Library + * @since 1.0 + * @version 1.0.0 + * @ingroup os_services + * @{ + */ + +/* Alignment needed for various parts of the buffer definition */ +#if CONFIG_NET_BUF_ALIGNMENT == 0 +#define __net_buf_align __aligned(sizeof(void *)) +#else +#define __net_buf_align __aligned(CONFIG_NET_BUF_ALIGNMENT) +#endif + +/** + * @brief Define a net_buf_simple stack variable. + * + * This is a helper macro which is used to define a net_buf_simple object + * on the stack. + * + * @param _name Name of the net_buf_simple object. + * @param _size Maximum data storage for the buffer. + */ +#define NET_BUF_SIMPLE_DEFINE(_name, _size) \ + uint8_t net_buf_data_##_name[_size]; \ + struct net_buf_simple _name = { \ + .data = net_buf_data_##_name, \ + .len = 0, \ + .size = _size, \ + .__buf = net_buf_data_##_name, \ + } + +/** + * + * @brief Define a static net_buf_simple variable. + * + * This is a helper macro which is used to define a static net_buf_simple + * object. + * + * @param _name Name of the net_buf_simple object. + * @param _size Maximum data storage for the buffer. + */ +#define NET_BUF_SIMPLE_DEFINE_STATIC(_name, _size) \ + static __noinit uint8_t net_buf_data_##_name[_size]; \ + static struct net_buf_simple _name = { \ + .data = net_buf_data_##_name, \ + .len = 0, \ + .size = _size, \ + .__buf = net_buf_data_##_name, \ + } + +/** + * @brief Simple network buffer representation. + * + * This is a simpler variant of the net_buf object (in fact net_buf uses + * net_buf_simple internally). It doesn't provide any kind of reference + * counting, user data, dynamic allocation, or in general the ability to + * pass through kernel objects such as FIFOs. + * + * The main use of this is for scenarios where the meta-data of the normal + * net_buf isn't needed and causes too much overhead. This could be e.g. + * when the buffer only needs to be allocated on the stack or when the + * access to and lifetime of the buffer is well controlled and constrained. + */ +struct net_buf_simple { + /** Pointer to the start of data in the buffer. */ + uint8_t *data; + + /** + * Length of the data behind the data pointer. + * + * To determine the max length, use net_buf_simple_max_len(), not #size! + */ + uint16_t len; + + /** Amount of data that net_buf_simple#__buf can store. */ + uint16_t size; + + /** Start of the data storage. Not to be accessed directly + * (the data pointer should be used instead). + */ + uint8_t *__buf; +}; + +/** + * + * @brief Define a net_buf_simple stack variable and get a pointer to it. + * + * This is a helper macro which is used to define a net_buf_simple object on + * the stack and the get a pointer to it as follows: + * + * struct net_buf_simple *my_buf = NET_BUF_SIMPLE(10); + * + * After creating the object it needs to be initialized by calling + * net_buf_simple_init(). + * + * @param _size Maximum data storage for the buffer. + * + * @return Pointer to stack-allocated net_buf_simple object. + */ +#define NET_BUF_SIMPLE(_size) \ + ((struct net_buf_simple *)(&(struct { \ + struct net_buf_simple buf; \ + uint8_t data[_size]; \ + }) { \ + .buf.size = _size, \ + })) + +/** + * @brief Initialize a net_buf_simple object. + * + * This needs to be called after creating a net_buf_simple object using + * the NET_BUF_SIMPLE macro. + * + * @param buf Buffer to initialize. + * @param reserve_head Headroom to reserve. + */ +static inline void net_buf_simple_init(struct net_buf_simple *buf, + size_t reserve_head) +{ + if (!buf->__buf) { + buf->__buf = (uint8_t *)buf + sizeof(*buf); + } + + buf->data = buf->__buf + reserve_head; + buf->len = 0U; +} + +/** + * @brief Initialize a net_buf_simple object with data. + * + * Initialized buffer object with external data. + * + * @param buf Buffer to initialize. + * @param data External data pointer + * @param size Amount of data the pointed data buffer if able to fit. + */ +void net_buf_simple_init_with_data(struct net_buf_simple *buf, + void *data, size_t size); + +/** + * @brief Reset buffer + * + * Reset buffer data so it can be reused for other purposes. + * + * @param buf Buffer to reset. + */ +static inline void net_buf_simple_reset(struct net_buf_simple *buf) +{ + buf->len = 0U; + buf->data = buf->__buf; +} + +/** + * Clone buffer state, using the same data buffer. + * + * Initializes a buffer to point to the same data as an existing buffer. + * Allows operations on the same data without altering the length and + * offset of the original. + * + * @param original Buffer to clone. + * @param clone The new clone. + */ +void net_buf_simple_clone(const struct net_buf_simple *original, + struct net_buf_simple *clone); + +/** + * @brief Prepare data to be added at the end of the buffer + * + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param len Number of bytes to increment the length with. + * + * @return The original tail of the buffer. + */ +void *net_buf_simple_add(struct net_buf_simple *buf, size_t len); + +/** + * @brief Copy given number of bytes from memory to the end of the buffer + * + * Increments the data length of the buffer to account for more data at the + * end. + * + * @param buf Buffer to update. + * @param mem Location of data to be added. + * @param len Length of data to be added + * + * @return The original tail of the buffer. + */ +void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem, + size_t len); + +/** + * @brief Add (8-bit) byte at the end of the buffer + * + * Increments the data length of the buffer to account for more data at the + * end. + * + * @param buf Buffer to update. + * @param val byte value to be added. + * + * @return Pointer to the value added + */ +uint8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, uint8_t val); + +/** + * @brief Add 16-bit value at the end of the buffer + * + * Adds 16-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 16-bit value to be added. + */ +void net_buf_simple_add_le16(struct net_buf_simple *buf, uint16_t val); + +/** + * @brief Add 16-bit value at the end of the buffer + * + * Adds 16-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 16-bit value to be added. + */ +void net_buf_simple_add_be16(struct net_buf_simple *buf, uint16_t val); + +/** + * @brief Add 24-bit value at the end of the buffer + * + * Adds 24-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 24-bit value to be added. + */ +void net_buf_simple_add_le24(struct net_buf_simple *buf, uint32_t val); + +/** + * @brief Add 24-bit value at the end of the buffer + * + * Adds 24-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 24-bit value to be added. + */ +void net_buf_simple_add_be24(struct net_buf_simple *buf, uint32_t val); + +/** + * @brief Add 32-bit value at the end of the buffer + * + * Adds 32-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 32-bit value to be added. + */ +void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val); + +/** + * @brief Add 32-bit value at the end of the buffer + * + * Adds 32-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 32-bit value to be added. + */ +void net_buf_simple_add_be32(struct net_buf_simple *buf, uint32_t val); + +/** + * @brief Add 40-bit value at the end of the buffer + * + * Adds 40-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 40-bit value to be added. + */ +void net_buf_simple_add_le40(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Add 40-bit value at the end of the buffer + * + * Adds 40-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 40-bit value to be added. + */ +void net_buf_simple_add_be40(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Add 48-bit value at the end of the buffer + * + * Adds 48-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 48-bit value to be added. + */ +void net_buf_simple_add_le48(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Add 48-bit value at the end of the buffer + * + * Adds 48-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 48-bit value to be added. + */ +void net_buf_simple_add_be48(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Add 64-bit value at the end of the buffer + * + * Adds 64-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 64-bit value to be added. + */ +void net_buf_simple_add_le64(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Add 64-bit value at the end of the buffer + * + * Adds 64-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 64-bit value to be added. + */ +void net_buf_simple_add_be64(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Remove data from the end of the buffer. + * + * Removes data from the end of the buffer by modifying the buffer length. + * + * @param buf Buffer to update. + * @param len Number of bytes to remove. + * + * @return New end of the buffer data. + */ +void *net_buf_simple_remove_mem(struct net_buf_simple *buf, size_t len); + +/** + * @brief Remove a 8-bit value from the end of the buffer + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 8-bit values. + * + * @param buf A valid pointer on a buffer. + * + * @return The 8-bit removed value + */ +uint8_t net_buf_simple_remove_u8(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 16 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 16-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 16-bit value converted from little endian to host endian. + */ +uint16_t net_buf_simple_remove_le16(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 16 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 16-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 16-bit value converted from big endian to host endian. + */ +uint16_t net_buf_simple_remove_be16(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 24 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 24-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 24-bit value converted from little endian to host endian. + */ +uint32_t net_buf_simple_remove_le24(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 24 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 24-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 24-bit value converted from big endian to host endian. + */ +uint32_t net_buf_simple_remove_be24(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 32 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 32-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 32-bit value converted from little endian to host endian. + */ +uint32_t net_buf_simple_remove_le32(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 32 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 32-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 32-bit value converted from big endian to host endian. + */ +uint32_t net_buf_simple_remove_be32(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 40 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 40-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 40-bit value converted from little endian to host endian. + */ +uint64_t net_buf_simple_remove_le40(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 40 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 40-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 40-bit value converted from big endian to host endian. + */ +uint64_t net_buf_simple_remove_be40(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 48 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 48-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 48-bit value converted from little endian to host endian. + */ +uint64_t net_buf_simple_remove_le48(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 48 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 48-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 48-bit value converted from big endian to host endian. + */ +uint64_t net_buf_simple_remove_be48(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 64 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 64-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 64-bit value converted from little endian to host endian. + */ +uint64_t net_buf_simple_remove_le64(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 64 bits from the end of the buffer. + * + * Same idea as with net_buf_simple_remove_mem(), but a helper for operating + * on 64-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 64-bit value converted from big endian to host endian. + */ +uint64_t net_buf_simple_remove_be64(struct net_buf_simple *buf); + +/** + * @brief Prepare data to be added to the start of the buffer + * + * Modifies the data pointer and buffer length to account for more data + * in the beginning of the buffer. + * + * @param buf Buffer to update. + * @param len Number of bytes to add to the beginning. + * + * @return The new beginning of the buffer data. + */ +void *net_buf_simple_push(struct net_buf_simple *buf, size_t len); + +/** + * @brief Copy given number of bytes from memory to the start of the buffer. + * + * Modifies the data pointer and buffer length to account for more data + * in the beginning of the buffer. + * + * @param buf Buffer to update. + * @param mem Location of data to be added. + * @param len Length of data to be added. + * + * @return The new beginning of the buffer data. + */ +void *net_buf_simple_push_mem(struct net_buf_simple *buf, const void *mem, + size_t len); + +/** + * @brief Push 16-bit value to the beginning of the buffer + * + * Adds 16-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 16-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_le16(struct net_buf_simple *buf, uint16_t val); + +/** + * @brief Push 16-bit value to the beginning of the buffer + * + * Adds 16-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 16-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_be16(struct net_buf_simple *buf, uint16_t val); + +/** + * @brief Push 8-bit value to the beginning of the buffer + * + * Adds 8-bit value the beginning of the buffer. + * + * @param buf Buffer to update. + * @param val 8-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_u8(struct net_buf_simple *buf, uint8_t val); + +/** + * @brief Push 24-bit value to the beginning of the buffer + * + * Adds 24-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 24-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_le24(struct net_buf_simple *buf, uint32_t val); + +/** + * @brief Push 24-bit value to the beginning of the buffer + * + * Adds 24-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 24-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_be24(struct net_buf_simple *buf, uint32_t val); + +/** + * @brief Push 32-bit value to the beginning of the buffer + * + * Adds 32-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 32-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_le32(struct net_buf_simple *buf, uint32_t val); + +/** + * @brief Push 32-bit value to the beginning of the buffer + * + * Adds 32-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 32-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_be32(struct net_buf_simple *buf, uint32_t val); + +/** + * @brief Push 40-bit value to the beginning of the buffer + * + * Adds 40-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 40-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_le40(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Push 40-bit value to the beginning of the buffer + * + * Adds 40-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 40-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_be40(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Push 48-bit value to the beginning of the buffer + * + * Adds 48-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 48-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_le48(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Push 48-bit value to the beginning of the buffer + * + * Adds 48-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 48-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_be48(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Push 64-bit value to the beginning of the buffer + * + * Adds 64-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 64-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_le64(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Push 64-bit value to the beginning of the buffer + * + * Adds 64-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 64-bit value to be pushed to the buffer. + */ +void net_buf_simple_push_be64(struct net_buf_simple *buf, uint64_t val); + +/** + * @brief Remove data from the beginning of the buffer. + * + * Removes data from the beginning of the buffer by modifying the data + * pointer and buffer length. + * + * @param buf Buffer to update. + * @param len Number of bytes to remove. + * + * @return New beginning of the buffer data. + */ +void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len); + +/** + * @brief Remove data from the beginning of the buffer. + * + * Removes data from the beginning of the buffer by modifying the data + * pointer and buffer length. + * + * @param buf Buffer to update. + * @param len Number of bytes to remove. + * + * @return Pointer to the old location of the buffer data. + */ +void *net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len); + +/** + * @brief Remove a 8-bit value from the beginning of the buffer + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 8-bit values. + * + * @param buf A valid pointer on a buffer. + * + * @return The 8-bit removed value + */ +uint8_t net_buf_simple_pull_u8(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 16 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 16-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 16-bit value converted from little endian to host endian. + */ +uint16_t net_buf_simple_pull_le16(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 16 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 16-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 16-bit value converted from big endian to host endian. + */ +uint16_t net_buf_simple_pull_be16(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 24 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 24-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 24-bit value converted from little endian to host endian. + */ +uint32_t net_buf_simple_pull_le24(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 24 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 24-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 24-bit value converted from big endian to host endian. + */ +uint32_t net_buf_simple_pull_be24(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 32 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 32-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 32-bit value converted from little endian to host endian. + */ +uint32_t net_buf_simple_pull_le32(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 32 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 32-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 32-bit value converted from big endian to host endian. + */ +uint32_t net_buf_simple_pull_be32(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 40 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 40-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 40-bit value converted from little endian to host endian. + */ +uint64_t net_buf_simple_pull_le40(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 40 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 40-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 40-bit value converted from big endian to host endian. + */ +uint64_t net_buf_simple_pull_be40(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 48 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 48-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 48-bit value converted from little endian to host endian. + */ +uint64_t net_buf_simple_pull_le48(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 48 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 48-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 48-bit value converted from big endian to host endian. + */ +uint64_t net_buf_simple_pull_be48(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 64 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 64-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 64-bit value converted from little endian to host endian. + */ +uint64_t net_buf_simple_pull_le64(struct net_buf_simple *buf); + +/** + * @brief Remove and convert 64 bits from the beginning of the buffer. + * + * Same idea as with net_buf_simple_pull(), but a helper for operating + * on 64-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 64-bit value converted from big endian to host endian. + */ +uint64_t net_buf_simple_pull_be64(struct net_buf_simple *buf); + +/** + * @brief Get the tail pointer for a buffer. + * + * Get a pointer to the end of the data in a buffer. + * + * @param buf Buffer. + * + * @return Tail pointer for the buffer. + */ +static inline uint8_t *net_buf_simple_tail(const struct net_buf_simple *buf) +{ + return buf->data + buf->len; +} + +/** + * @brief Check buffer headroom. + * + * Check how much free space there is in the beginning of the buffer. + * + * buf A valid pointer on a buffer + * + * @return Number of bytes available in the beginning of the buffer. + */ +size_t net_buf_simple_headroom(const struct net_buf_simple *buf); + +/** + * @brief Check buffer tailroom. + * + * Check how much free space there is at the end of the buffer. + * + * @param buf A valid pointer on a buffer + * + * @return Number of bytes available at the end of the buffer. + */ +size_t net_buf_simple_tailroom(const struct net_buf_simple *buf); + +/** + * @brief Check maximum net_buf_simple::len value. + * + * This value is depending on the number of bytes being reserved as headroom. + * + * @param buf A valid pointer on a buffer + * + * @return Number of bytes usable behind the net_buf_simple::data pointer. + */ +uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf); + +/** + * @brief Parsing state of a buffer. + * + * This is used for temporarily storing the parsing state of a buffer + * while giving control of the parsing to a routine which we don't + * control. + */ +struct net_buf_simple_state { + /** Offset of the data pointer from the beginning of the storage */ + uint16_t offset; + /** Length of data */ + uint16_t len; +}; + +/** + * @brief Save the parsing state of a buffer. + * + * Saves the parsing state of a buffer so it can be restored later. + * + * @param buf Buffer from which the state should be saved. + * @param state Storage for the state. + */ +static inline void net_buf_simple_save(const struct net_buf_simple *buf, + struct net_buf_simple_state *state) +{ + state->offset = (uint16_t)net_buf_simple_headroom(buf); + state->len = buf->len; +} + +/** + * @brief Restore the parsing state of a buffer. + * + * Restores the parsing state of a buffer from a state previously stored + * by net_buf_simple_save(). + * + * @param buf Buffer to which the state should be restored. + * @param state Stored state. + */ +static inline void net_buf_simple_restore(struct net_buf_simple *buf, + struct net_buf_simple_state *state) +{ + buf->data = buf->__buf + state->offset; + buf->len = state->len; +} + +/** + * Flag indicating that the buffer's associated data pointer, points to + * externally allocated memory. Therefore once ref goes down to zero, the + * pointed data will not need to be deallocated. This never needs to be + * explicitly set or unset by the net_buf API user. Such net_buf is + * exclusively instantiated via net_buf_alloc_with_data() function. + * Reference count mechanism however will behave the same way, and ref + * count going to 0 will free the net_buf but no the data pointer in it. + */ +#define NET_BUF_EXTERNAL_DATA BIT(0) + +/** + * @brief Network buffer representation. + * + * This struct is used to represent network buffers. Such buffers are + * normally defined through the NET_BUF_POOL_*_DEFINE() APIs and allocated + * using the net_buf_alloc() API. + */ +struct net_buf { + /** Allow placing the buffer into sys_slist_t */ + sys_snode_t node; + + /** Fragments associated with this buffer. */ + struct net_buf *frags; + + /** Reference count. */ + uint8_t ref; + + /** Bit-field of buffer flags. */ + uint8_t flags; + + /** Where the buffer should go when freed up. */ + uint8_t pool_id; + + /** Size of user data on this buffer */ + uint8_t user_data_size; + + /** Union for convenience access to the net_buf_simple members, also + * preserving the old API. + */ + union { + /* The ABI of this struct must match net_buf_simple */ + struct { + /** Pointer to the start of data in the buffer. */ + uint8_t *data; + + /** Length of the data behind the data pointer. */ + uint16_t len; + + /** Amount of data that this buffer can store. */ + uint16_t size; + + /** Start of the data storage. Not to be accessed + * directly (the data pointer should be used + * instead). + */ + uint8_t *__buf; + }; + + /** @cond INTERNAL_HIDDEN */ + struct net_buf_simple b; + /** @endcond */ + }; + + /** System metadata for this buffer. Cleared on allocation. */ + uint8_t user_data[] __net_buf_align; +}; + +/** @cond INTERNAL_HIDDEN */ + +struct net_buf_data_cb { + uint8_t * __must_check (*alloc)(struct net_buf *buf, size_t *size, + k_timeout_t timeout); + uint8_t * __must_check (*ref)(struct net_buf *buf, uint8_t *data); + void (*unref)(struct net_buf *buf, uint8_t *data); +}; + +struct net_buf_data_alloc { + const struct net_buf_data_cb *cb; + void *alloc_data; + size_t max_alloc_size; +}; + +/** @endcond */ + +/** + * @brief Network buffer pool representation. + * + * This struct is used to represent a pool of network buffers. + */ +struct net_buf_pool { + /** LIFO to place the buffer into when free */ + struct k_lifo free; + + /** To prevent concurrent access/modifications */ + struct k_spinlock lock; + + /** Number of buffers in pool */ + const uint16_t buf_count; + + /** Number of uninitialized buffers */ + uint16_t uninit_count; + + /** Size of user data allocated to this pool */ + uint8_t user_data_size; + +#if defined(CONFIG_NET_BUF_POOL_USAGE) + /** Amount of available buffers in the pool. */ + atomic_t avail_count; + + /** Total size of the pool. */ + const uint16_t pool_size; + + /** Name of the pool. Used when printing pool information. */ + const char *name; +#endif /* CONFIG_NET_BUF_POOL_USAGE */ + + /** Optional destroy callback when buffer is freed. */ + void (*const destroy)(struct net_buf *buf); + + /** Data allocation handlers. */ + const struct net_buf_data_alloc *alloc; + + /** Start of buffer storage array */ + struct net_buf * const __bufs; +}; + +/** @cond INTERNAL_HIDDEN */ +#define NET_BUF_POOL_USAGE_INIT(_pool, _count) \ + IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.avail_count = ATOMIC_INIT(_count),)) \ + IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.name = STRINGIFY(_pool),)) + +#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \ + { \ + .free = Z_LIFO_INITIALIZER(_pool.free), \ + .lock = { }, \ + .buf_count = _count, \ + .uninit_count = _count, \ + .user_data_size = _ud_size, \ + NET_BUF_POOL_USAGE_INIT(_pool, _count) \ + .destroy = _destroy, \ + .alloc = _alloc, \ + .__bufs = (struct net_buf *)_bufs, \ + } + +#define _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size) \ + struct _net_buf_##_name { uint8_t b[sizeof(struct net_buf)]; \ + uint8_t ud[_ud_size]; } __net_buf_align; \ + BUILD_ASSERT(_ud_size <= UINT8_MAX); \ + BUILD_ASSERT(offsetof(struct net_buf, user_data) == \ + offsetof(struct _net_buf_##_name, ud), "Invalid offset"); \ + BUILD_ASSERT(__alignof__(struct net_buf) == \ + __alignof__(struct _net_buf_##_name), "Invalid alignment"); \ + BUILD_ASSERT(sizeof(struct _net_buf_##_name) == \ + ROUND_UP(sizeof(struct net_buf) + _ud_size, __alignof__(struct net_buf)), \ + "Size cannot be determined"); \ + static struct _net_buf_##_name _net_buf_##_name[_count] __noinit + +extern const struct net_buf_data_alloc net_buf_heap_alloc; +/** @endcond */ + +/** + * + * @brief Define a new pool for buffers using the heap for the data. + * + * Defines a net_buf_pool struct and the necessary memory storage (array of + * structs) for the needed amount of buffers. After this, the buffers can be + * accessed from the pool through net_buf_alloc. The pool is defined as a + * static variable, so if it needs to be exported outside the current module + * this needs to happen with the help of a separate pointer rather than an + * extern declaration. + * + * The data payload of the buffers will be allocated from the heap using + * k_malloc, so CONFIG_HEAP_MEM_POOL_SIZE must be set to a positive value. + * This kind of pool does not support blocking on the data allocation, so + * the timeout passed to net_buf_alloc will be always treated as K_NO_WAIT + * when trying to allocate the data. This means that allocation failures, + * i.e. NULL returns, must always be handled cleanly. + * + * If provided with a custom destroy callback, this callback is + * responsible for eventually calling net_buf_destroy() to complete the + * process of returning the buffer to the pool. + * + * @param _name Name of the pool variable. + * @param _count Number of buffers in the pool. + * @param _ud_size User data space to reserve per buffer. + * @param _destroy Optional destroy callback when buffer is freed. + */ +#define NET_BUF_POOL_HEAP_DEFINE(_name, _count, _ud_size, _destroy) \ + _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \ + static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \ + NET_BUF_POOL_INITIALIZER(_name, &net_buf_heap_alloc, \ + _net_buf_##_name, _count, _ud_size, \ + _destroy) + +/** @cond INTERNAL_HIDDEN */ + +struct net_buf_pool_fixed { + uint8_t *data_pool; +}; + +extern const struct net_buf_data_cb net_buf_fixed_cb; + +/** @endcond */ + +/** + * + * @brief Define a new pool for buffers based on fixed-size data + * + * Defines a net_buf_pool struct and the necessary memory storage (array of + * structs) for the needed amount of buffers. After this, the buffers can be + * accessed from the pool through net_buf_alloc. The pool is defined as a + * static variable, so if it needs to be exported outside the current module + * this needs to happen with the help of a separate pointer rather than an + * extern declaration. + * + * The data payload of the buffers will be allocated from a byte array + * of fixed sized chunks. This kind of pool does not support blocking on + * the data allocation, so the timeout passed to net_buf_alloc will be + * always treated as K_NO_WAIT when trying to allocate the data. This means + * that allocation failures, i.e. NULL returns, must always be handled + * cleanly. + * + * If provided with a custom destroy callback, this callback is + * responsible for eventually calling net_buf_destroy() to complete the + * process of returning the buffer to the pool. + * + * @param _name Name of the pool variable. + * @param _count Number of buffers in the pool. + * @param _data_size Maximum data payload per buffer. + * @param _ud_size User data space to reserve per buffer. + * @param _destroy Optional destroy callback when buffer is freed. + */ +#define NET_BUF_POOL_FIXED_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \ + _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \ + static uint8_t __noinit net_buf_data_##_name[_count][_data_size] __net_buf_align; \ + static const struct net_buf_pool_fixed net_buf_fixed_##_name = { \ + .data_pool = (uint8_t *)net_buf_data_##_name, \ + }; \ + static const struct net_buf_data_alloc net_buf_fixed_alloc_##_name = { \ + .cb = &net_buf_fixed_cb, \ + .alloc_data = (void *)&net_buf_fixed_##_name, \ + .max_alloc_size = _data_size, \ + }; \ + static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \ + NET_BUF_POOL_INITIALIZER(_name, &net_buf_fixed_alloc_##_name, \ + _net_buf_##_name, _count, _ud_size, \ + _destroy) + +/** @cond INTERNAL_HIDDEN */ +extern const struct net_buf_data_cb net_buf_var_cb; +/** @endcond */ + +/** + * + * @brief Define a new pool for buffers with variable size payloads + * + * Defines a net_buf_pool struct and the necessary memory storage (array of + * structs) for the needed amount of buffers. After this, the buffers can be + * accessed from the pool through net_buf_alloc. The pool is defined as a + * static variable, so if it needs to be exported outside the current module + * this needs to happen with the help of a separate pointer rather than an + * extern declaration. + * + * The data payload of the buffers will be based on a memory pool from which + * variable size payloads may be allocated. + * + * If provided with a custom destroy callback, this callback is + * responsible for eventually calling net_buf_destroy() to complete the + * process of returning the buffer to the pool. + * + * @param _name Name of the pool variable. + * @param _count Number of buffers in the pool. + * @param _data_size Total amount of memory available for data payloads. + * @param _ud_size User data space to reserve per buffer. + * @param _destroy Optional destroy callback when buffer is freed. + */ +#define NET_BUF_POOL_VAR_DEFINE(_name, _count, _data_size, _ud_size, _destroy) \ + _NET_BUF_ARRAY_DEFINE(_name, _count, _ud_size); \ + K_HEAP_DEFINE(net_buf_mem_pool_##_name, _data_size); \ + static const struct net_buf_data_alloc net_buf_data_alloc_##_name = { \ + .cb = &net_buf_var_cb, \ + .alloc_data = &net_buf_mem_pool_##_name, \ + .max_alloc_size = 0, \ + }; \ + static STRUCT_SECTION_ITERABLE(net_buf_pool, _name) = \ + NET_BUF_POOL_INITIALIZER(_name, &net_buf_data_alloc_##_name, \ + _net_buf_##_name, _count, _ud_size, \ + _destroy) + +/** + * + * @brief Define a new pool for buffers + * + * Defines a net_buf_pool struct and the necessary memory storage (array of + * structs) for the needed amount of buffers. After this,the buffers can be + * accessed from the pool through net_buf_alloc. The pool is defined as a + * static variable, so if it needs to be exported outside the current module + * this needs to happen with the help of a separate pointer rather than an + * extern declaration. + * + * If provided with a custom destroy callback this callback is + * responsible for eventually calling net_buf_destroy() to complete the + * process of returning the buffer to the pool. + * + * @param _name Name of the pool variable. + * @param _count Number of buffers in the pool. + * @param _size Maximum data size for each buffer. + * @param _ud_size Amount of user data space to reserve. + * @param _destroy Optional destroy callback when buffer is freed. + */ +#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy) \ + NET_BUF_POOL_FIXED_DEFINE(_name, _count, _size, _ud_size, _destroy) + +/** + * @brief Looks up a pool based on its ID. + * + * @param id Pool ID (e.g. from buf->pool_id). + * + * @return Pointer to pool. + */ +struct net_buf_pool *net_buf_pool_get(int id); + +/** + * @brief Get a zero-based index for a buffer. + * + * This function will translate a buffer into a zero-based index, + * based on its placement in its buffer pool. This can be useful if you + * want to associate an external array of meta-data contexts with the + * buffers of a pool. + * + * @param buf Network buffer. + * + * @return Zero-based index for the buffer. + */ +int net_buf_id(const struct net_buf *buf); + +/** + * @brief Allocate a new fixed buffer from a pool. + * + * @note Some types of data allocators do not support + * blocking (such as the HEAP type). In this case it's still possible + * for net_buf_alloc() to fail (return NULL) even if it was given + * K_FOREVER. + * + * @note The timeout value will be overridden to K_NO_WAIT if called from the + * system workqueue. + * + * @param pool Which pool to allocate the buffer from. + * @param timeout Affects the action taken should the pool be empty. + * If K_NO_WAIT, then return immediately. If K_FOREVER, then + * wait as long as necessary. Otherwise, wait until the specified + * timeout. + * + * @return New buffer or NULL if out of buffers. + */ +#if defined(CONFIG_NET_BUF_LOG) +struct net_buf * __must_check net_buf_alloc_fixed_debug(struct net_buf_pool *pool, + k_timeout_t timeout, + const char *func, + int line); +#define net_buf_alloc_fixed(_pool, _timeout) \ + net_buf_alloc_fixed_debug(_pool, _timeout, __func__, __LINE__) +#else +struct net_buf * __must_check net_buf_alloc_fixed(struct net_buf_pool *pool, + k_timeout_t timeout); +#endif + +/** + * @copydetails net_buf_alloc_fixed + */ +static inline struct net_buf * __must_check net_buf_alloc(struct net_buf_pool *pool, + k_timeout_t timeout) +{ + return net_buf_alloc_fixed(pool, timeout); +} + +/** + * @brief Allocate a new variable length buffer from a pool. + * + * @note Some types of data allocators do not support + * blocking (such as the HEAP type). In this case it's still possible + * for net_buf_alloc() to fail (return NULL) even if it was given + * K_FOREVER. + * + * @note The timeout value will be overridden to K_NO_WAIT if called from the + * system workqueue. + * + * @param pool Which pool to allocate the buffer from. + * @param size Amount of data the buffer must be able to fit. + * @param timeout Affects the action taken should the pool be empty. + * If K_NO_WAIT, then return immediately. If K_FOREVER, then + * wait as long as necessary. Otherwise, wait until the specified + * timeout. + * + * @return New buffer or NULL if out of buffers. + */ +#if defined(CONFIG_NET_BUF_LOG) +struct net_buf * __must_check net_buf_alloc_len_debug(struct net_buf_pool *pool, + size_t size, + k_timeout_t timeout, + const char *func, + int line); +#define net_buf_alloc_len(_pool, _size, _timeout) \ + net_buf_alloc_len_debug(_pool, _size, _timeout, __func__, __LINE__) +#else +struct net_buf * __must_check net_buf_alloc_len(struct net_buf_pool *pool, + size_t size, + k_timeout_t timeout); +#endif + +/** + * @brief Allocate a new buffer from a pool but with external data pointer. + * + * Allocate a new buffer from a pool, where the data pointer comes from the + * user and not from the pool. + * + * @note Some types of data allocators do not support + * blocking (such as the HEAP type). In this case it's still possible + * for net_buf_alloc() to fail (return NULL) even if it was given + * K_FOREVER. + * + * @note The timeout value will be overridden to K_NO_WAIT if called from the + * system workqueue. + * + * @param pool Which pool to allocate the buffer from. + * @param data External data pointer + * @param size Amount of data the pointed data buffer if able to fit. + * @param timeout Affects the action taken should the pool be empty. + * If K_NO_WAIT, then return immediately. If K_FOREVER, then + * wait as long as necessary. Otherwise, wait until the specified + * timeout. + * + * @return New buffer or NULL if out of buffers. + */ +#if defined(CONFIG_NET_BUF_LOG) +struct net_buf * __must_check net_buf_alloc_with_data_debug(struct net_buf_pool *pool, + void *data, size_t size, + k_timeout_t timeout, + const char *func, int line); +#define net_buf_alloc_with_data(_pool, _data_, _size, _timeout) \ + net_buf_alloc_with_data_debug(_pool, _data_, _size, _timeout, \ + __func__, __LINE__) +#else +struct net_buf * __must_check net_buf_alloc_with_data(struct net_buf_pool *pool, + void *data, size_t size, + k_timeout_t timeout); +#endif + +/** + * @brief Get a buffer from a FIFO. + * + * @deprecated Use @a k_fifo_get() instead. + * + * @param fifo Which FIFO to take the buffer from. + * @param timeout Affects the action taken should the FIFO be empty. + * If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as + * long as necessary. Otherwise, wait until the specified timeout. + * + * @return New buffer or NULL if the FIFO is empty. + */ +#if defined(CONFIG_NET_BUF_LOG) +__deprecated struct net_buf * __must_check net_buf_get_debug(struct k_fifo *fifo, + k_timeout_t timeout, + const char *func, int line); +#define net_buf_get(_fifo, _timeout) \ + net_buf_get_debug(_fifo, _timeout, __func__, __LINE__) +#else +__deprecated struct net_buf * __must_check net_buf_get(struct k_fifo *fifo, + k_timeout_t timeout); +#endif + +/** + * @brief Destroy buffer from custom destroy callback + * + * This helper is only intended to be used from custom destroy callbacks. + * If no custom destroy callback is given to NET_BUF_POOL_*_DEFINE() then + * there is no need to use this API. + * + * @param buf Buffer to destroy. + */ +static inline void net_buf_destroy(struct net_buf *buf) +{ + struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id); + + if (buf->__buf) { + if (!(buf->flags & NET_BUF_EXTERNAL_DATA)) { + pool->alloc->cb->unref(buf, buf->__buf); + } + buf->__buf = NULL; + } + + k_lifo_put(&pool->free, buf); +} + +/** + * @brief Reset buffer + * + * Reset buffer data and flags so it can be reused for other purposes. + * + * @param buf Buffer to reset. + */ +void net_buf_reset(struct net_buf *buf); + +/** + * @brief Initialize buffer with the given headroom. + * + * The buffer is not expected to contain any data when this API is called. + * + * @param buf Buffer to initialize. + * @param reserve How much headroom to reserve. + */ +void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve); + +/** + * @brief Put a buffer into a list + * + * @param list Which list to append the buffer to. + * @param buf Buffer. + */ +void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf); + +/** + * @brief Get a buffer from a list. + * + * @param list Which list to take the buffer from. + * + * @return New buffer or NULL if the FIFO is empty. + */ +struct net_buf * __must_check net_buf_slist_get(sys_slist_t *list); + +/** + * @brief Put a buffer to the end of a FIFO. + * + * @deprecated Use @a k_fifo_put() instead. + * + * @param fifo Which FIFO to put the buffer to. + * @param buf Buffer. + */ +__deprecated void net_buf_put(struct k_fifo *fifo, struct net_buf *buf); + +/** + * @brief Decrements the reference count of a buffer. + * + * The buffer is put back into the pool if the reference count reaches zero. + * + * @param buf A valid pointer on a buffer + */ +#if defined(CONFIG_NET_BUF_LOG) +void net_buf_unref_debug(struct net_buf *buf, const char *func, int line); +#define net_buf_unref(_buf) \ + net_buf_unref_debug(_buf, __func__, __LINE__) +#else +void net_buf_unref(struct net_buf *buf); +#endif + +/** + * @brief Increment the reference count of a buffer. + * + * @param buf A valid pointer on a buffer + * + * @return the buffer newly referenced + */ +struct net_buf * __must_check net_buf_ref(struct net_buf *buf); + +/** + * @brief Clone buffer + * + * Duplicate given buffer including any (user) data and headers currently stored. + * + * @param buf A valid pointer on a buffer + * @param timeout Affects the action taken should the pool be empty. + * If K_NO_WAIT, then return immediately. If K_FOREVER, then + * wait as long as necessary. Otherwise, wait until the specified + * timeout. + * + * @return Cloned buffer or NULL if out of buffers. + */ +struct net_buf * __must_check net_buf_clone(struct net_buf *buf, + k_timeout_t timeout); + +/** + * @brief Get a pointer to the user data of a buffer. + * + * @param buf A valid pointer on a buffer + * + * @return Pointer to the user data of the buffer. + */ +static inline void * __must_check net_buf_user_data(const struct net_buf *buf) +{ + return (void *)buf->user_data; +} + +/** + * @brief Copy user data from one to another buffer. + * + * @param dst A valid pointer to a buffer gettings its user data overwritten. + * @param src A valid pointer to a buffer gettings its user data copied. User data size must be + * equal to or exceed @a dst. + * + * @return 0 on success or negative error number on failure. + */ +int net_buf_user_data_copy(struct net_buf *dst, const struct net_buf *src); + +/** + * @brief Initialize buffer with the given headroom. + * + * The buffer is not expected to contain any data when this API is called. + * + * @param buf Buffer to initialize. + * @param reserve How much headroom to reserve. + */ +static inline void net_buf_reserve(struct net_buf *buf, size_t reserve) +{ + net_buf_simple_reserve(&buf->b, reserve); +} + +/** + * @brief Prepare data to be added at the end of the buffer + * + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param len Number of bytes to increment the length with. + * + * @return The original tail of the buffer. + */ +static inline void *net_buf_add(struct net_buf *buf, size_t len) +{ + return net_buf_simple_add(&buf->b, len); +} + +/** + * @brief Copies the given number of bytes to the end of the buffer + * + * Increments the data length of the buffer to account for more data at + * the end. + * + * @param buf Buffer to update. + * @param mem Location of data to be added. + * @param len Length of data to be added + * + * @return The original tail of the buffer. + */ +static inline void *net_buf_add_mem(struct net_buf *buf, const void *mem, + size_t len) +{ + return net_buf_simple_add_mem(&buf->b, mem, len); +} + +/** + * @brief Add (8-bit) byte at the end of the buffer + * + * Increments the data length of the buffer to account for more data at + * the end. + * + * @param buf Buffer to update. + * @param val byte value to be added. + * + * @return Pointer to the value added + */ +static inline uint8_t *net_buf_add_u8(struct net_buf *buf, uint8_t val) +{ + return net_buf_simple_add_u8(&buf->b, val); +} + +/** + * @brief Add 16-bit value at the end of the buffer + * + * Adds 16-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 16-bit value to be added. + */ +static inline void net_buf_add_le16(struct net_buf *buf, uint16_t val) +{ + net_buf_simple_add_le16(&buf->b, val); +} + +/** + * @brief Add 16-bit value at the end of the buffer + * + * Adds 16-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 16-bit value to be added. + */ +static inline void net_buf_add_be16(struct net_buf *buf, uint16_t val) +{ + net_buf_simple_add_be16(&buf->b, val); +} + +/** + * @brief Add 24-bit value at the end of the buffer + * + * Adds 24-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 24-bit value to be added. + */ +static inline void net_buf_add_le24(struct net_buf *buf, uint32_t val) +{ + net_buf_simple_add_le24(&buf->b, val); +} + +/** + * @brief Add 24-bit value at the end of the buffer + * + * Adds 24-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 24-bit value to be added. + */ +static inline void net_buf_add_be24(struct net_buf *buf, uint32_t val) +{ + net_buf_simple_add_be24(&buf->b, val); +} + +/** + * @brief Add 32-bit value at the end of the buffer + * + * Adds 32-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 32-bit value to be added. + */ +static inline void net_buf_add_le32(struct net_buf *buf, uint32_t val) +{ + net_buf_simple_add_le32(&buf->b, val); +} + +/** + * @brief Add 32-bit value at the end of the buffer + * + * Adds 32-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 32-bit value to be added. + */ +static inline void net_buf_add_be32(struct net_buf *buf, uint32_t val) +{ + net_buf_simple_add_be32(&buf->b, val); +} + +/** + * @brief Add 40-bit value at the end of the buffer + * + * Adds 40-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 40-bit value to be added. + */ +static inline void net_buf_add_le40(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_add_le40(&buf->b, val); +} + +/** + * @brief Add 40-bit value at the end of the buffer + * + * Adds 40-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 40-bit value to be added. + */ +static inline void net_buf_add_be40(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_add_be40(&buf->b, val); +} + +/** + * @brief Add 48-bit value at the end of the buffer + * + * Adds 48-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 48-bit value to be added. + */ +static inline void net_buf_add_le48(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_add_le48(&buf->b, val); +} + +/** + * @brief Add 48-bit value at the end of the buffer + * + * Adds 48-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 48-bit value to be added. + */ +static inline void net_buf_add_be48(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_add_be48(&buf->b, val); +} + +/** + * @brief Add 64-bit value at the end of the buffer + * + * Adds 64-bit value in little endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 64-bit value to be added. + */ +static inline void net_buf_add_le64(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_add_le64(&buf->b, val); +} + +/** + * @brief Add 64-bit value at the end of the buffer + * + * Adds 64-bit value in big endian format at the end of buffer. + * Increments the data length of a buffer to account for more data + * at the end. + * + * @param buf Buffer to update. + * @param val 64-bit value to be added. + */ +static inline void net_buf_add_be64(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_add_be64(&buf->b, val); +} + +/** + * @brief Remove data from the end of the buffer. + * + * Removes data from the end of the buffer by modifying the buffer length. + * + * @param buf Buffer to update. + * @param len Number of bytes to remove. + * + * @return New end of the buffer data. + */ +static inline void *net_buf_remove_mem(struct net_buf *buf, size_t len) +{ + return net_buf_simple_remove_mem(&buf->b, len); +} + +/** + * @brief Remove a 8-bit value from the end of the buffer + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 8-bit values. + * + * @param buf A valid pointer on a buffer. + * + * @return The 8-bit removed value + */ +static inline uint8_t net_buf_remove_u8(struct net_buf *buf) +{ + return net_buf_simple_remove_u8(&buf->b); +} + +/** + * @brief Remove and convert 16 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 16-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 16-bit value converted from little endian to host endian. + */ +static inline uint16_t net_buf_remove_le16(struct net_buf *buf) +{ + return net_buf_simple_remove_le16(&buf->b); +} + +/** + * @brief Remove and convert 16 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 16-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 16-bit value converted from big endian to host endian. + */ +static inline uint16_t net_buf_remove_be16(struct net_buf *buf) +{ + return net_buf_simple_remove_be16(&buf->b); +} + +/** + * @brief Remove and convert 24 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 24-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 24-bit value converted from big endian to host endian. + */ +static inline uint32_t net_buf_remove_be24(struct net_buf *buf) +{ + return net_buf_simple_remove_be24(&buf->b); +} + +/** + * @brief Remove and convert 24 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 24-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 24-bit value converted from little endian to host endian. + */ +static inline uint32_t net_buf_remove_le24(struct net_buf *buf) +{ + return net_buf_simple_remove_le24(&buf->b); +} + +/** + * @brief Remove and convert 32 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 32-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 32-bit value converted from little endian to host endian. + */ +static inline uint32_t net_buf_remove_le32(struct net_buf *buf) +{ + return net_buf_simple_remove_le32(&buf->b); +} + +/** + * @brief Remove and convert 32 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 32-bit big endian data. + * + * @param buf A valid pointer on a buffer + * + * @return 32-bit value converted from big endian to host endian. + */ +static inline uint32_t net_buf_remove_be32(struct net_buf *buf) +{ + return net_buf_simple_remove_be32(&buf->b); +} + +/** + * @brief Remove and convert 40 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 40-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 40-bit value converted from little endian to host endian. + */ +static inline uint64_t net_buf_remove_le40(struct net_buf *buf) +{ + return net_buf_simple_remove_le40(&buf->b); +} + +/** + * @brief Remove and convert 40 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 40-bit big endian data. + * + * @param buf A valid pointer on a buffer + * + * @return 40-bit value converted from big endian to host endian. + */ +static inline uint64_t net_buf_remove_be40(struct net_buf *buf) +{ + return net_buf_simple_remove_be40(&buf->b); +} + +/** + * @brief Remove and convert 48 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 48-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 48-bit value converted from little endian to host endian. + */ +static inline uint64_t net_buf_remove_le48(struct net_buf *buf) +{ + return net_buf_simple_remove_le48(&buf->b); +} + +/** + * @brief Remove and convert 48 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 48-bit big endian data. + * + * @param buf A valid pointer on a buffer + * + * @return 48-bit value converted from big endian to host endian. + */ +static inline uint64_t net_buf_remove_be48(struct net_buf *buf) +{ + return net_buf_simple_remove_be48(&buf->b); +} + +/** + * @brief Remove and convert 64 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 64-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 64-bit value converted from little endian to host endian. + */ +static inline uint64_t net_buf_remove_le64(struct net_buf *buf) +{ + return net_buf_simple_remove_le64(&buf->b); +} + +/** + * @brief Remove and convert 64 bits from the end of the buffer. + * + * Same idea as with net_buf_remove_mem(), but a helper for operating on + * 64-bit big endian data. + * + * @param buf A valid pointer on a buffer + * + * @return 64-bit value converted from big endian to host endian. + */ +static inline uint64_t net_buf_remove_be64(struct net_buf *buf) +{ + return net_buf_simple_remove_be64(&buf->b); +} + +/** + * @brief Prepare data to be added at the start of the buffer + * + * Modifies the data pointer and buffer length to account for more data + * in the beginning of the buffer. + * + * @param buf Buffer to update. + * @param len Number of bytes to add to the beginning. + * + * @return The new beginning of the buffer data. + */ +static inline void *net_buf_push(struct net_buf *buf, size_t len) +{ + return net_buf_simple_push(&buf->b, len); +} + +/** + * @brief Copies the given number of bytes to the start of the buffer + * + * Modifies the data pointer and buffer length to account for more data + * in the beginning of the buffer. + * + * @param buf Buffer to update. + * @param mem Location of data to be added. + * @param len Length of data to be added. + * + * @return The new beginning of the buffer data. + */ +static inline void *net_buf_push_mem(struct net_buf *buf, const void *mem, + size_t len) +{ + return net_buf_simple_push_mem(&buf->b, mem, len); +} + +/** + * @brief Push 8-bit value to the beginning of the buffer + * + * Adds 8-bit value the beginning of the buffer. + * + * @param buf Buffer to update. + * @param val 8-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_u8(struct net_buf *buf, uint8_t val) +{ + net_buf_simple_push_u8(&buf->b, val); +} + +/** + * @brief Push 16-bit value to the beginning of the buffer + * + * Adds 16-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 16-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_le16(struct net_buf *buf, uint16_t val) +{ + net_buf_simple_push_le16(&buf->b, val); +} + +/** + * @brief Push 16-bit value to the beginning of the buffer + * + * Adds 16-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 16-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_be16(struct net_buf *buf, uint16_t val) +{ + net_buf_simple_push_be16(&buf->b, val); +} + +/** + * @brief Push 24-bit value to the beginning of the buffer + * + * Adds 24-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 24-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_le24(struct net_buf *buf, uint32_t val) +{ + net_buf_simple_push_le24(&buf->b, val); +} + +/** + * @brief Push 24-bit value to the beginning of the buffer + * + * Adds 24-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 24-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_be24(struct net_buf *buf, uint32_t val) +{ + net_buf_simple_push_be24(&buf->b, val); +} + +/** + * @brief Push 32-bit value to the beginning of the buffer + * + * Adds 32-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 32-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_le32(struct net_buf *buf, uint32_t val) +{ + net_buf_simple_push_le32(&buf->b, val); +} + +/** + * @brief Push 32-bit value to the beginning of the buffer + * + * Adds 32-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 32-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_be32(struct net_buf *buf, uint32_t val) +{ + net_buf_simple_push_be32(&buf->b, val); +} + +/** + * @brief Push 40-bit value to the beginning of the buffer + * + * Adds 40-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 40-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_le40(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_push_le40(&buf->b, val); +} + +/** + * @brief Push 40-bit value to the beginning of the buffer + * + * Adds 40-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 40-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_be40(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_push_be40(&buf->b, val); +} + +/** + * @brief Push 48-bit value to the beginning of the buffer + * + * Adds 48-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 48-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_le48(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_push_le48(&buf->b, val); +} + +/** + * @brief Push 48-bit value to the beginning of the buffer + * + * Adds 48-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 48-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_be48(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_push_be48(&buf->b, val); +} + +/** + * @brief Push 64-bit value to the beginning of the buffer + * + * Adds 64-bit value in little endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 64-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_le64(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_push_le64(&buf->b, val); +} + +/** + * @brief Push 64-bit value to the beginning of the buffer + * + * Adds 64-bit value in big endian format to the beginning of the + * buffer. + * + * @param buf Buffer to update. + * @param val 64-bit value to be pushed to the buffer. + */ +static inline void net_buf_push_be64(struct net_buf *buf, uint64_t val) +{ + net_buf_simple_push_be64(&buf->b, val); +} + +/** + * @brief Remove data from the beginning of the buffer. + * + * Removes data from the beginning of the buffer by modifying the data + * pointer and buffer length. + * + * @param buf Buffer to update. + * @param len Number of bytes to remove. + * + * @return New beginning of the buffer data. + */ +static inline void *net_buf_pull(struct net_buf *buf, size_t len) +{ + return net_buf_simple_pull(&buf->b, len); +} + +/** + * @brief Remove data from the beginning of the buffer. + * + * Removes data from the beginning of the buffer by modifying the data + * pointer and buffer length. + * + * @param buf Buffer to update. + * @param len Number of bytes to remove. + * + * @return Pointer to the old beginning of the buffer data. + */ +static inline void *net_buf_pull_mem(struct net_buf *buf, size_t len) +{ + return net_buf_simple_pull_mem(&buf->b, len); +} + +/** + * @brief Remove a 8-bit value from the beginning of the buffer + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 8-bit values. + * + * @param buf A valid pointer on a buffer. + * + * @return The 8-bit removed value + */ +static inline uint8_t net_buf_pull_u8(struct net_buf *buf) +{ + return net_buf_simple_pull_u8(&buf->b); +} + +/** + * @brief Remove and convert 16 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 16-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 16-bit value converted from little endian to host endian. + */ +static inline uint16_t net_buf_pull_le16(struct net_buf *buf) +{ + return net_buf_simple_pull_le16(&buf->b); +} + +/** + * @brief Remove and convert 16 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 16-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 16-bit value converted from big endian to host endian. + */ +static inline uint16_t net_buf_pull_be16(struct net_buf *buf) +{ + return net_buf_simple_pull_be16(&buf->b); +} + +/** + * @brief Remove and convert 24 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 24-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 24-bit value converted from little endian to host endian. + */ +static inline uint32_t net_buf_pull_le24(struct net_buf *buf) +{ + return net_buf_simple_pull_le24(&buf->b); +} + +/** + * @brief Remove and convert 24 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 24-bit big endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 24-bit value converted from big endian to host endian. + */ +static inline uint32_t net_buf_pull_be24(struct net_buf *buf) +{ + return net_buf_simple_pull_be24(&buf->b); +} + +/** + * @brief Remove and convert 32 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 32-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 32-bit value converted from little endian to host endian. + */ +static inline uint32_t net_buf_pull_le32(struct net_buf *buf) +{ + return net_buf_simple_pull_le32(&buf->b); +} + +/** + * @brief Remove and convert 32 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 32-bit big endian data. + * + * @param buf A valid pointer on a buffer + * + * @return 32-bit value converted from big endian to host endian. + */ +static inline uint32_t net_buf_pull_be32(struct net_buf *buf) +{ + return net_buf_simple_pull_be32(&buf->b); +} + +/** + * @brief Remove and convert 40 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 40-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 40-bit value converted from little endian to host endian. + */ +static inline uint64_t net_buf_pull_le40(struct net_buf *buf) +{ + return net_buf_simple_pull_le40(&buf->b); +} + +/** + * @brief Remove and convert 40 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 40-bit big endian data. + * + * @param buf A valid pointer on a buffer + * + * @return 40-bit value converted from big endian to host endian. + */ +static inline uint64_t net_buf_pull_be40(struct net_buf *buf) +{ + return net_buf_simple_pull_be40(&buf->b); +} + +/** + * @brief Remove and convert 48 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 48-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 48-bit value converted from little endian to host endian. + */ +static inline uint64_t net_buf_pull_le48(struct net_buf *buf) +{ + return net_buf_simple_pull_le48(&buf->b); +} + +/** + * @brief Remove and convert 48 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 48-bit big endian data. + * + * @param buf A valid pointer on a buffer + * + * @return 48-bit value converted from big endian to host endian. + */ +static inline uint64_t net_buf_pull_be48(struct net_buf *buf) +{ + return net_buf_simple_pull_be48(&buf->b); +} + +/** + * @brief Remove and convert 64 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 64-bit little endian data. + * + * @param buf A valid pointer on a buffer. + * + * @return 64-bit value converted from little endian to host endian. + */ +static inline uint64_t net_buf_pull_le64(struct net_buf *buf) +{ + return net_buf_simple_pull_le64(&buf->b); +} + +/** + * @brief Remove and convert 64 bits from the beginning of the buffer. + * + * Same idea as with net_buf_pull(), but a helper for operating on + * 64-bit big endian data. + * + * @param buf A valid pointer on a buffer + * + * @return 64-bit value converted from big endian to host endian. + */ +static inline uint64_t net_buf_pull_be64(struct net_buf *buf) +{ + return net_buf_simple_pull_be64(&buf->b); +} + +/** + * @brief Check buffer tailroom. + * + * Check how much free space there is at the end of the buffer. + * + * @param buf A valid pointer on a buffer + * + * @return Number of bytes available at the end of the buffer. + */ +static inline size_t net_buf_tailroom(const struct net_buf *buf) +{ + return net_buf_simple_tailroom(&buf->b); +} + +/** + * @brief Check buffer headroom. + * + * Check how much free space there is in the beginning of the buffer. + * + * buf A valid pointer on a buffer + * + * @return Number of bytes available in the beginning of the buffer. + */ +static inline size_t net_buf_headroom(const struct net_buf *buf) +{ + return net_buf_simple_headroom(&buf->b); +} + +/** + * @brief Check maximum net_buf::len value. + * + * This value is depending on the number of bytes being reserved as headroom. + * + * @param buf A valid pointer on a buffer + * + * @return Number of bytes usable behind the net_buf::data pointer. + */ +static inline uint16_t net_buf_max_len(const struct net_buf *buf) +{ + return net_buf_simple_max_len(&buf->b); +} + +/** + * @brief Get the tail pointer for a buffer. + * + * Get a pointer to the end of the data in a buffer. + * + * @param buf Buffer. + * + * @return Tail pointer for the buffer. + */ +static inline uint8_t *net_buf_tail(const struct net_buf *buf) +{ + return net_buf_simple_tail(&buf->b); +} + +/** + * @brief Find the last fragment in the fragment list. + * + * @return Pointer to last fragment in the list. + */ +struct net_buf *net_buf_frag_last(struct net_buf *frags); + +/** + * @brief Insert a new fragment to a chain of bufs. + * + * Insert a new fragment into the buffer fragments list after the parent. + * + * Note: This function takes ownership of the fragment reference so the + * caller is not required to unref. + * + * @param parent Parent buffer/fragment. + * @param frag Fragment to insert. + */ +void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag); + +/** + * @brief Add a new fragment to the end of a chain of bufs. + * + * Append a new fragment into the buffer fragments list. + * + * Note: This function takes ownership of the fragment reference so the + * caller is not required to unref. + * + * @param head Head of the fragment chain. + * @param frag Fragment to add. + * + * @return New head of the fragment chain. Either head (if head + * was non-NULL) or frag (if head was NULL). + */ +struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag); + +/** + * @brief Delete existing fragment from a chain of bufs. + * + * @param parent Parent buffer/fragment, or NULL if there is no parent. + * @param frag Fragment to delete. + * + * @return Pointer to the buffer following the fragment, or NULL if it + * had no further fragments. + */ +#if defined(CONFIG_NET_BUF_LOG) +struct net_buf *net_buf_frag_del_debug(struct net_buf *parent, + struct net_buf *frag, + const char *func, int line); +#define net_buf_frag_del(_parent, _frag) \ + net_buf_frag_del_debug(_parent, _frag, __func__, __LINE__) +#else +struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag); +#endif + +/** + * @brief Copy bytes from net_buf chain starting at offset to linear buffer + * + * Copy (extract) @a len bytes from @a src net_buf chain, starting from @a + * offset in it, to a linear buffer @a dst. Return number of bytes actually + * copied, which may be less than requested, if net_buf chain doesn't have + * enough data, or destination buffer is too small. + * + * @param dst Destination buffer + * @param dst_len Destination buffer length + * @param src Source net_buf chain + * @param offset Starting offset to copy from + * @param len Number of bytes to copy + * @return number of bytes actually copied + */ +size_t net_buf_linearize(void *dst, size_t dst_len, + const struct net_buf *src, size_t offset, size_t len); + +/** + * @typedef net_buf_allocator_cb + * @brief Network buffer allocator callback. + * + * @details The allocator callback is called when net_buf_append_bytes + * needs to allocate a new net_buf. + * + * @param timeout Affects the action taken should the net buf pool be empty. + * If K_NO_WAIT, then return immediately. If K_FOREVER, then + * wait as long as necessary. Otherwise, wait until the specified + * timeout. + * @param user_data The user data given in net_buf_append_bytes call. + * @return pointer to allocated net_buf or NULL on error. + */ +typedef struct net_buf * __must_check (*net_buf_allocator_cb)(k_timeout_t timeout, + void *user_data); + +/** + * @brief Append data to a list of net_buf + * + * @details Append data to a net_buf. If there is not enough space in the + * net_buf then more net_buf will be added, unless there are no free net_buf + * and timeout occurs. If not allocator is provided it attempts to allocate from + * the same pool as the original buffer. + * + * @param buf Network buffer. + * @param len Total length of input data + * @param value Data to be added + * @param timeout Timeout is passed to the net_buf allocator callback. + * @param allocate_cb When a new net_buf is required, use this callback. + * @param user_data A user data pointer to be supplied to the allocate_cb. + * This pointer is can be anything from a mem_pool or a net_pkt, the + * logic is left up to the allocate_cb function. + * + * @return Length of data actually added. This may be less than input + * length if other timeout than K_FOREVER was used, and there + * were no free fragments in a pool to accommodate all data. + */ +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); + +/** + * @brief Match data with a net_buf's content + * + * @details Compare data with a content of a net_buf. Provide information about + * the number of bytes matching between both. If needed, traverse + * through multiple buffer fragments. + * + * @param buf Network buffer + * @param offset Starting offset to compare from + * @param data Data buffer for comparison + * @param len Number of bytes to compare + * + * @return The number of bytes compared before the first difference. + */ +size_t net_buf_data_match(const struct net_buf *buf, size_t offset, const void *data, size_t len); + +/** + * @brief Skip N number of bytes in a net_buf + * + * @details Skip N number of bytes starting from fragment's offset. If the total + * length of data is placed in multiple fragments, this function will skip from + * all fragments until it reaches N number of bytes. Any fully skipped buffers + * are removed from the net_buf list. + * + * @param buf Network buffer. + * @param len Total length of data to be skipped. + * + * @return Pointer to the fragment or + * NULL and pos is 0 after successful skip, + * NULL and pos is 0xffff otherwise. + */ +static inline struct net_buf *net_buf_skip(struct net_buf *buf, size_t len) +{ + while (buf && len--) { + net_buf_pull_u8(buf); + if (!buf->len) { + buf = net_buf_frag_del(NULL, buf); + } + } + + return buf; +} + +/** + * @brief Calculate amount of bytes stored in fragments. + * + * Calculates the total amount of data stored in the given buffer and the + * fragments linked to it. + * + * @param buf Buffer to start off with. + * + * @return Number of bytes in the buffer and its fragments. + */ +static inline size_t net_buf_frags_len(const struct net_buf *buf) +{ + size_t bytes = 0; + + while (buf) { + bytes += buf->len; + buf = buf->frags; + } + + return bytes; +} + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_NET_BUF_H_ */ diff --git a/include/zephyr/usb/class/usb_audio.h b/include/zephyr/usb/class/usb_audio.h index 9062af37206..4c1c4db55cc 100644 --- a/include/zephyr/usb/class/usb_audio.h +++ b/include/zephyr/usb/class/usb_audio.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include /** Audio Interface Subclass Codes. diff --git a/include/zephyr/usb/usbh.h b/include/zephyr/usb/usbh.h index 66ba43072c4..869f3007a48 100644 --- a/include/zephyr/usb/usbh.h +++ b/include/zephyr/usb/usbh.h @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include #include diff --git a/lib/net_buf/buf.c b/lib/net_buf/buf.c index 6f0ee42f5c2..a2f504ac06b 100644 --- a/lib/net_buf/buf.c +++ b/lib/net_buf/buf.c @@ -18,7 +18,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #include -#include +#include #if defined(CONFIG_NET_BUF_LOG) #define NET_BUF_DBG(fmt, ...) LOG_DBG("(%p) " fmt, k_current_get(), \ diff --git a/lib/net_buf/buf_simple.c b/lib/net_buf/buf_simple.c index 4c7c4d0c335..9fb0ced6dab 100644 --- a/lib/net_buf/buf_simple.c +++ b/lib/net_buf/buf_simple.c @@ -14,7 +14,7 @@ LOG_MODULE_REGISTER(net_buf_simple, CONFIG_NET_BUF_LOG_LEVEL); #include #include -#include +#include #if defined(CONFIG_NET_BUF_SIMPLE_LOG) #define NET_BUF_SIMPLE_DBG(fmt, ...) LOG_DBG("(%p) " fmt, k_current_get(), \ diff --git a/samples/bluetooth/bap_unicast_client/src/stream_lc3.c b/samples/bluetooth/bap_unicast_client/src/stream_lc3.c index fd8c0a1fcd1..ab61fc5627f 100644 --- a/samples/bluetooth/bap_unicast_client/src/stream_lc3.c +++ b/samples/bluetooth/bap_unicast_client/src/stream_lc3.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include diff --git a/samples/bluetooth/bap_unicast_client/src/stream_lc3.h b/samples/bluetooth/bap_unicast_client/src/stream_lc3.h index 28e921e7e05..c323372c329 100644 --- a/samples/bluetooth/bap_unicast_client/src/stream_lc3.h +++ b/samples/bluetooth/bap_unicast_client/src/stream_lc3.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include /* Since the lc3.h header file is not available when CONFIG_LIBLC3=n, we need to guard the include diff --git a/samples/bluetooth/bap_unicast_client/src/stream_tx.c b/samples/bluetooth/bap_unicast_client/src/stream_tx.c index 91f668db17a..06ea3a3c349 100644 --- a/samples/bluetooth/bap_unicast_client/src/stream_tx.c +++ b/samples/bluetooth/bap_unicast_client/src/stream_tx.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c b/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c index 9015eb40995..a9ae04039d9 100644 --- a/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c +++ b/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include diff --git a/samples/bluetooth/cap_initiator/src/cap_initiator_tx.c b/samples/bluetooth/cap_initiator/src/cap_initiator_tx.c index 500e2b70b56..3bcdea869f7 100644 --- a/samples/bluetooth/cap_initiator/src/cap_initiator_tx.c +++ b/samples/bluetooth/cap_initiator/src/cap_initiator_tx.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include "cap_initiator.h" diff --git a/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c b/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c index 5cb9b035f0f..39b7a68aef6 100644 --- a/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c +++ b/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/samples/bluetooth/encrypted_advertising/central/src/central_ead.c b/samples/bluetooth/encrypted_advertising/central/src/central_ead.c index 9c6361bb6d0..75a85927a70 100644 --- a/samples/bluetooth/encrypted_advertising/central/src/central_ead.c +++ b/samples/bluetooth/encrypted_advertising/central/src/central_ead.c @@ -9,7 +9,7 @@ #include -#include +#include #include #include diff --git a/samples/bluetooth/hci_ipc/src/main.c b/samples/bluetooth/hci_ipc/src/main.c index 38b8a1a433b..f0f71ca384f 100644 --- a/samples/bluetooth/hci_ipc/src/main.c +++ b/samples/bluetooth/hci_ipc/src/main.c @@ -16,7 +16,7 @@ #include -#include +#include #include #include #include diff --git a/samples/bluetooth/hci_spi/src/main.c b/samples/bluetooth/hci_spi/src/main.c index f7d477e03ba..8ecd0d06b4e 100644 --- a/samples/bluetooth/hci_spi/src/main.c +++ b/samples/bluetooth/hci_spi/src/main.c @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include #include diff --git a/samples/bluetooth/hci_uart/src/main.c b/samples/bluetooth/hci_uart/src/main.c index 2e4220592b7..a2baa89ba67 100644 --- a/samples/bluetooth/hci_uart/src/main.c +++ b/samples/bluetooth/hci_uart/src/main.c @@ -22,7 +22,7 @@ #include -#include +#include #include #include #include diff --git a/samples/bluetooth/hci_uart_3wire/src/main.c b/samples/bluetooth/hci_uart_3wire/src/main.c index 7e1f105c672..7f459061e89 100644 --- a/samples/bluetooth/hci_uart_3wire/src/main.c +++ b/samples/bluetooth/hci_uart_3wire/src/main.c @@ -22,7 +22,7 @@ #include -#include +#include #include #include #include diff --git a/samples/bluetooth/hci_uart_async/src/hci_uart_async.c b/samples/bluetooth/hci_uart_async/src/hci_uart_async.c index 69543275575..011d9206622 100644 --- a/samples/bluetooth/hci_uart_async/src/hci_uart_async.c +++ b/samples/bluetooth/hci_uart_async/src/hci_uart_async.c @@ -23,7 +23,7 @@ #include -#include +#include #include #include #include diff --git a/samples/boards/stm32/bluetooth/interactive_gui/src/main.c b/samples/boards/stm32/bluetooth/interactive_gui/src/main.c index fa41fd5b41d..9b31a1e69ff 100644 --- a/samples/boards/stm32/bluetooth/interactive_gui/src/main.c +++ b/samples/boards/stm32/bluetooth/interactive_gui/src/main.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/samples/net/wpan_serial/src/main.c b/samples/net/wpan_serial/src/main.c index 2f589aa33de..804e2cb6a48 100644 --- a/samples/net/wpan_serial/src/main.c +++ b/samples/net/wpan_serial/src/main.c @@ -20,7 +20,7 @@ LOG_MODULE_REGISTER(wpan_serial, CONFIG_USB_DEVICE_LOG_LEVEL); #include #include -#include +#include #include #include diff --git a/samples/subsys/dap/src/main.c b/samples/subsys/dap/src/main.c index d680f89a233..c8682f2e5c0 100644 --- a/samples/subsys/dap/src/main.c +++ b/samples/subsys/dap/src/main.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/samples/subsys/zbus/msg_subscriber/src/main.c b/samples/subsys/zbus/msg_subscriber/src/main.c index 3c384a7815a..48ce4a01650 100644 --- a/samples/subsys/zbus/msg_subscriber/src/main.c +++ b/samples/subsys/zbus/msg_subscriber/src/main.c @@ -170,7 +170,7 @@ ZBUS_CHAN_ADD_OBS(acc_data_chan, bar_msg_sub16, 3); static struct acc_msg acc = {.x = 1, .y = 10, .z = 100}; #if defined(CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_ISOLATION) -#include +#include #if defined(CONFIG_ZBUS_MSG_SUBSCRIBER_BUF_ALLOC_DYNAMIC) NET_BUF_POOL_HEAP_DEFINE(isolated_pool, (CONFIG_ZBUS_MSG_SUBSCRIBER_SAMPLE_ISOLATED_BUF_POOL_SIZE), diff --git a/samples/subsys/zbus/remote_mock/src/mock_proxy.c b/samples/subsys/zbus/remote_mock/src/mock_proxy.c index ea94910c196..485981e0c33 100644 --- a/samples/subsys/zbus/remote_mock/src/mock_proxy.c +++ b/samples/subsys/zbus/remote_mock/src/mock_proxy.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include LOG_MODULE_DECLARE(zbus, CONFIG_ZBUS_LOG_LEVEL); diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 17aeda10edb..113425728ff 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/bap_base.c b/subsys/bluetooth/audio/bap_base.c index 604c53186c7..cba23a66c8f 100644 --- a/subsys/bluetooth/audio/bap_base.c +++ b/subsys/bluetooth/audio/bap_base.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/bap_broadcast_assistant.c b/subsys/bluetooth/audio/bap_broadcast_assistant.c index eacbf48a325..be38718bfbd 100644 --- a/subsys/bluetooth/audio/bap_broadcast_assistant.c +++ b/subsys/bluetooth/audio/bap_broadcast_assistant.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/bap_broadcast_sink.c b/subsys/bluetooth/audio/bap_broadcast_sink.c index 746f24cdbed..020d504a6be 100644 --- a/subsys/bluetooth/audio/bap_broadcast_sink.c +++ b/subsys/bluetooth/audio/bap_broadcast_sink.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/bap_broadcast_source.c b/subsys/bluetooth/audio/bap_broadcast_source.c index b75bdc39429..fc39ae1b336 100644 --- a/subsys/bluetooth/audio/bap_broadcast_source.c +++ b/subsys/bluetooth/audio/bap_broadcast_source.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/bap_scan_delegator.c b/subsys/bluetooth/audio/bap_scan_delegator.c index c13da60581a..ec5ad3d46d5 100644 --- a/subsys/bluetooth/audio/bap_scan_delegator.c +++ b/subsys/bluetooth/audio/bap_scan_delegator.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/bap_stream.c b/subsys/bluetooth/audio/bap_stream.c index 1d082eae1b1..dbc6a6d5a18 100644 --- a/subsys/bluetooth/audio/bap_stream.c +++ b/subsys/bluetooth/audio/bap_stream.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index 9b51d43b2f0..a8f73e03e75 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/bap_unicast_client_internal.h b/subsys/bluetooth/audio/bap_unicast_client_internal.h index 8e279ad652d..962d7feb927 100644 --- a/subsys/bluetooth/audio/bap_unicast_client_internal.h +++ b/subsys/bluetooth/audio/bap_unicast_client_internal.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include int bt_bap_unicast_client_config(struct bt_bap_stream *stream, const struct bt_audio_codec_cfg *codec_cfg); diff --git a/subsys/bluetooth/audio/cap_initiator.c b/subsys/bluetooth/audio/cap_initiator.c index 552bc724e11..20d5011ebde 100644 --- a/subsys/bluetooth/audio/cap_initiator.c +++ b/subsys/bluetooth/audio/cap_initiator.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/cap_stream.c b/subsys/bluetooth/audio/cap_stream.c index 678068c0438..e1ee733a448 100644 --- a/subsys/bluetooth/audio/cap_stream.c +++ b/subsys/bluetooth/audio/cap_stream.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/codec.c b/subsys/bluetooth/audio/codec.c index 554004c4609..ea7ec0fa56a 100644 --- a/subsys/bluetooth/audio/codec.c +++ b/subsys/bluetooth/audio/codec.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/gmap_client.c b/subsys/bluetooth/audio/gmap_client.c index 8f4fb74ffa0..2dc66406141 100644 --- a/subsys/bluetooth/audio/gmap_client.c +++ b/subsys/bluetooth/audio/gmap_client.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/audio/has.c b/subsys/bluetooth/audio/has.c index f90c54159cd..ad72904ec43 100644 --- a/subsys/bluetooth/audio/has.c +++ b/subsys/bluetooth/audio/has.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/has_client.c b/subsys/bluetooth/audio/has_client.c index 0426cf9dbe3..7a31c3a6b4c 100644 --- a/subsys/bluetooth/audio/has_client.c +++ b/subsys/bluetooth/audio/has_client.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/mcc.c b/subsys/bluetooth/audio/mcc.c index 06bd9789a1e..3a3402a5ec3 100644 --- a/subsys/bluetooth/audio/mcc.c +++ b/subsys/bluetooth/audio/mcc.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/mpl.c b/subsys/bluetooth/audio/mpl.c index a80429ee80e..6f1db9e7c0b 100644 --- a/subsys/bluetooth/audio/mpl.c +++ b/subsys/bluetooth/audio/mpl.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/pacs.c b/subsys/bluetooth/audio/pacs.c index bbad4ee89da..30e5d64d9a4 100644 --- a/subsys/bluetooth/audio/pacs.c +++ b/subsys/bluetooth/audio/pacs.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/pbp.c b/subsys/bluetooth/audio/pbp.c index ab3ab4822e9..d985de463c8 100644 --- a/subsys/bluetooth/audio/pbp.c +++ b/subsys/bluetooth/audio/pbp.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/shell/bap.c b/subsys/bluetooth/audio/shell/bap.c index 64d2b8e1a9b..089dfcb4960 100644 --- a/subsys/bluetooth/audio/shell/bap.c +++ b/subsys/bluetooth/audio/shell/bap.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/shell/bap_broadcast_assistant.c b/subsys/bluetooth/audio/shell/bap_broadcast_assistant.c index 66e30f38d5e..34f6df38aad 100644 --- a/subsys/bluetooth/audio/shell/bap_broadcast_assistant.c +++ b/subsys/bluetooth/audio/shell/bap_broadcast_assistant.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/shell/bap_usb.c b/subsys/bluetooth/audio/shell/bap_usb.c index 5773f55245b..426ab59e932 100644 --- a/subsys/bluetooth/audio/shell/bap_usb.c +++ b/subsys/bluetooth/audio/shell/bap_usb.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/shell/cap_initiator.c b/subsys/bluetooth/audio/shell/cap_initiator.c index eda03773250..197c46059be 100644 --- a/subsys/bluetooth/audio/shell/cap_initiator.c +++ b/subsys/bluetooth/audio/shell/cap_initiator.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/shell/csip_set_coordinator.c b/subsys/bluetooth/audio/shell/csip_set_coordinator.c index 46479a85c37..816ca2cfe30 100644 --- a/subsys/bluetooth/audio/shell/csip_set_coordinator.c +++ b/subsys/bluetooth/audio/shell/csip_set_coordinator.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/shell/mcc.c b/subsys/bluetooth/audio/shell/mcc.c index 7d55b7adb42..302de6772d9 100644 --- a/subsys/bluetooth/audio/shell/mcc.c +++ b/subsys/bluetooth/audio/shell/mcc.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/shell/pbp.c b/subsys/bluetooth/audio/shell/pbp.c index 4904e466c71..a6a2b0259c5 100644 --- a/subsys/bluetooth/audio/shell/pbp.c +++ b/subsys/bluetooth/audio/shell/pbp.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/tbs.c b/subsys/bluetooth/audio/tbs.c index b4a08502ff4..c34810ecf9c 100644 --- a/subsys/bluetooth/audio/tbs.c +++ b/subsys/bluetooth/audio/tbs.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/tbs_client.c b/subsys/bluetooth/audio/tbs_client.c index 44771207f3f..e222cd8e52c 100644 --- a/subsys/bluetooth/audio/tbs_client.c +++ b/subsys/bluetooth/audio/tbs_client.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/audio/tbs_internal.h b/subsys/bluetooth/audio/tbs_internal.h index e066cc1de04..9b15195c355 100644 --- a/subsys/bluetooth/audio/tbs_internal.h +++ b/subsys/bluetooth/audio/tbs_internal.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #define BT_TBS_MAX_UCI_SIZE 6 diff --git a/subsys/bluetooth/host/buf_view.h b/subsys/bluetooth/host/buf_view.h index 6beef592365..1b9a78ec7b4 100644 --- a/subsys/bluetooth/host/buf_view.h +++ b/subsys/bluetooth/host/buf_view.h @@ -11,7 +11,7 @@ #ifndef ZEPHYR_SUBSYS_BLUETOOTH_HOST_BUF_VIEW_H_ #define ZEPHYR_SUBSYS_BLUETOOTH_HOST_BUF_VIEW_H_ -#include +#include struct bt_buf_view_meta { diff --git a/subsys/bluetooth/host/classic/at.c b/subsys/bluetooth/host/classic/at.c index 3bbf84df70e..fadeeab10fb 100644 --- a/subsys/bluetooth/host/classic/at.c +++ b/subsys/bluetooth/host/classic/at.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include "at.h" diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 1b2b1ac3704..c80f4cfd327 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/host/hci_raw_internal.h b/subsys/bluetooth/host/hci_raw_internal.h index af09144f785..6f1d711eedf 100644 --- a/subsys/bluetooth/host/hci_raw_internal.h +++ b/subsys/bluetooth/host/hci_raw_internal.h @@ -7,7 +7,7 @@ #define __BT_HCI_RAW_INTERNAL_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/subsys/bluetooth/host/iso.c b/subsys/bluetooth/host/iso.c index 7d04fed3db2..3a9c6e25800 100644 --- a/subsys/bluetooth/host/iso.c +++ b/subsys/bluetooth/host/iso.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 8eb8bc0f141..edf0e407c20 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index d2df6ba8031..2f3b93ef441 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index afad7d1ac6d..7cc163ba8f8 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index f6367a05258..2e78f14e426 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index 2e60ff423c1..c79a118cf15 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/beacon.c b/subsys/bluetooth/mesh/beacon.c index cdd5862330e..9752254c81e 100644 --- a/subsys/bluetooth/mesh/beacon.c +++ b/subsys/bluetooth/mesh/beacon.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/delayable_msg.c b/subsys/bluetooth/mesh/delayable_msg.c index a1a247bb9c9..5b2d1a241ab 100644 --- a/subsys/bluetooth/mesh/delayable_msg.c +++ b/subsys/bluetooth/mesh/delayable_msg.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include "msg.h" diff --git a/subsys/bluetooth/mesh/dfu_metadata.c b/subsys/bluetooth/mesh/dfu_metadata.c index 11bcd975521..51a2cd03063 100644 --- a/subsys/bluetooth/mesh/dfu_metadata.c +++ b/subsys/bluetooth/mesh/dfu_metadata.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include diff --git a/subsys/bluetooth/mesh/friend.c b/subsys/bluetooth/mesh/friend.c index 4e4df119bd3..7337765e424 100644 --- a/subsys/bluetooth/mesh/friend.c +++ b/subsys/bluetooth/mesh/friend.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/mesh/gatt_cli.c b/subsys/bluetooth/mesh/gatt_cli.c index 7814f32f27f..0f06cdce406 100644 --- a/subsys/bluetooth/mesh/gatt_cli.c +++ b/subsys/bluetooth/mesh/gatt_cli.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/lpn.c b/subsys/bluetooth/mesh/lpn.c index a7e48e841d1..862ab784890 100644 --- a/subsys/bluetooth/mesh/lpn.c +++ b/subsys/bluetooth/mesh/lpn.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 77ca15b2d61..10269ce11bf 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/net.c b/subsys/bluetooth/mesh/net.c index 07c6f1aa18a..d69ecf99edf 100644 --- a/subsys/bluetooth/mesh/net.c +++ b/subsys/bluetooth/mesh/net.c @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/net.h b/subsys/bluetooth/mesh/net.h index f6991db0142..e1553debe45 100644 --- a/subsys/bluetooth/mesh/net.h +++ b/subsys/bluetooth/mesh/net.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/mesh/pb_adv.c b/subsys/bluetooth/mesh/pb_adv.c index 74979c582d2..8e363c0dae9 100644 --- a/subsys/bluetooth/mesh/pb_adv.c +++ b/subsys/bluetooth/mesh/pb_adv.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include "testing.h" #include "net.h" #include "crypto.h" diff --git a/subsys/bluetooth/mesh/pb_gatt_cli.c b/subsys/bluetooth/mesh/pb_gatt_cli.c index bf7dc14029a..07d77483caf 100644 --- a/subsys/bluetooth/mesh/pb_gatt_cli.c +++ b/subsys/bluetooth/mesh/pb_gatt_cli.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/pb_gatt_srv.c b/subsys/bluetooth/mesh/pb_gatt_srv.c index f125bbb293c..85b60cbe0fd 100644 --- a/subsys/bluetooth/mesh/pb_gatt_srv.c +++ b/subsys/bluetooth/mesh/pb_gatt_srv.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/prov.c b/subsys/bluetooth/mesh/prov.c index ba177bf1981..d83485962a1 100644 --- a/subsys/bluetooth/mesh/prov.c +++ b/subsys/bluetooth/mesh/prov.c @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/provisionee.c b/subsys/bluetooth/mesh/provisionee.c index 10fdab49fa6..76581727455 100644 --- a/subsys/bluetooth/mesh/provisionee.c +++ b/subsys/bluetooth/mesh/provisionee.c @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index af7ee743b45..4f2232765bf 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/proxy_cli.c b/subsys/bluetooth/mesh/proxy_cli.c index 5dd6b02361f..64808eaa623 100644 --- a/subsys/bluetooth/mesh/proxy_cli.c +++ b/subsys/bluetooth/mesh/proxy_cli.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/proxy_msg.c b/subsys/bluetooth/mesh/proxy_msg.c index b2fa113d456..e2818f8634b 100644 --- a/subsys/bluetooth/mesh/proxy_msg.c +++ b/subsys/bluetooth/mesh/proxy_msg.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/proxy_srv.c b/subsys/bluetooth/mesh/proxy_srv.c index f17e98f11d2..ddd0f35faf7 100644 --- a/subsys/bluetooth/mesh/proxy_srv.c +++ b/subsys/bluetooth/mesh/proxy_srv.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/rpl.c b/subsys/bluetooth/mesh/rpl.c index 2170a946671..1a158df0469 100644 --- a/subsys/bluetooth/mesh/rpl.c +++ b/subsys/bluetooth/mesh/rpl.c @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/sar_cfg.c b/subsys/bluetooth/mesh/sar_cfg.c index 35e1283a2ca..8bead93a866 100644 --- a/subsys/bluetooth/mesh/sar_cfg.c +++ b/subsys/bluetooth/mesh/sar_cfg.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/subnet.c b/subsys/bluetooth/mesh/subnet.c index 16041920575..b17b9a49740 100644 --- a/subsys/bluetooth/mesh/subnet.c +++ b/subsys/bluetooth/mesh/subnet.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/mesh/subnet.h b/subsys/bluetooth/mesh/subnet.h index 23a9a417c54..bdc5bbf8377 100644 --- a/subsys/bluetooth/mesh/subnet.h +++ b/subsys/bluetooth/mesh/subnet.h @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/mesh/transport.c b/subsys/bluetooth/mesh/transport.c index 42b459e167a..b9c0babd4ea 100644 --- a/subsys/bluetooth/mesh/transport.c +++ b/subsys/bluetooth/mesh/transport.c @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/mesh/va.c b/subsys/bluetooth/mesh/va.c index b69c22f40e9..fb81f36251c 100644 --- a/subsys/bluetooth/mesh/va.c +++ b/subsys/bluetooth/mesh/va.c @@ -11,7 +11,7 @@ #include #include -#include +#include #include diff --git a/subsys/bluetooth/services/ias/ias.c b/subsys/bluetooth/services/ias/ias.c index 1df53cac098..6bb80606bac 100644 --- a/subsys/bluetooth/services/ias/ias.c +++ b/subsys/bluetooth/services/ias/ias.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/services/ots/ots_l2cap.c b/subsys/bluetooth/services/ots/ots_l2cap.c index 7f0bc024fda..47834336b87 100644 --- a/subsys/bluetooth/services/ots/ots_l2cap.c +++ b/subsys/bluetooth/services/ots/ots_l2cap.c @@ -13,7 +13,7 @@ #include #include -#include +#include #include "ots_l2cap_internal.h" diff --git a/subsys/canbus/isotp/isotp.c b/subsys/canbus/isotp/isotp.c index 289d5a866db..6df95afca8a 100644 --- a/subsys/canbus/isotp/isotp.c +++ b/subsys/canbus/isotp/isotp.c @@ -6,7 +6,7 @@ */ #include "isotp_internal.h" -#include +#include #include #include #include diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c b/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c index 9875ed3ee75..969fd7295a6 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c b/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c index 0bd174d1c97..90cb0d2880b 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c +++ b/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/mgmt/mcumgr/smp/src/smp.c b/subsys/mgmt/mcumgr/smp/src/smp.c index 364e5f006d4..693a26f4d1f 100644 --- a/subsys/mgmt/mcumgr/smp/src/smp.c +++ b/subsys/mgmt/mcumgr/smp/src/smp.c @@ -8,7 +8,7 @@ /** SMP - Simple Management Protocol. */ #include -#include +#include #include #include #include diff --git a/subsys/mgmt/mcumgr/smp_client/src/client.c b/subsys/mgmt/mcumgr/smp_client/src/client.c index 84449ea3a0d..77b09eb1828 100644 --- a/subsys/mgmt/mcumgr/smp_client/src/client.c +++ b/subsys/mgmt/mcumgr/smp_client/src/client.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/mgmt/mcumgr/transport/include/mgmt/mcumgr/transport/smp_internal.h b/subsys/mgmt/mcumgr/transport/include/mgmt/mcumgr/transport/smp_internal.h index 3a09da22e17..822ca2f5ace 100644 --- a/subsys/mgmt/mcumgr/transport/include/mgmt/mcumgr/transport/smp_internal.h +++ b/subsys/mgmt/mcumgr/transport/include/mgmt/mcumgr/transport/smp_internal.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include #ifdef __cplusplus diff --git a/subsys/mgmt/mcumgr/transport/src/serial_util.c b/subsys/mgmt/mcumgr/transport/src/serial_util.c index afe342e5098..bdae529fa9e 100644 --- a/subsys/mgmt/mcumgr/transport/src/serial_util.c +++ b/subsys/mgmt/mcumgr/transport/src/serial_util.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/mgmt/mcumgr/transport/src/smp.c b/subsys/mgmt/mcumgr/transport/src/smp.c index f2dc8252c8c..53aab569b23 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp.c +++ b/subsys/mgmt/mcumgr/transport/src/smp.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/mgmt/mcumgr/transport/src/smp_dummy.c b/subsys/mgmt/mcumgr/transport/src/smp_dummy.c index e0033cc0d2c..f5852ce8874 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp_dummy.c +++ b/subsys/mgmt/mcumgr/transport/src/smp_dummy.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/mgmt/mcumgr/transport/src/smp_reassembly.c b/subsys/mgmt/mcumgr/transport/src/smp_reassembly.c index e492da7bc15..be5c30bab75 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp_reassembly.c +++ b/subsys/mgmt/mcumgr/transport/src/smp_reassembly.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/mgmt/mcumgr/transport/src/smp_shell.c b/subsys/mgmt/mcumgr/transport/src/smp_shell.c index d58f5cbd860..0a8d483d60f 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp_shell.c +++ b/subsys/mgmt/mcumgr/transport/src/smp_shell.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/mgmt/mcumgr/transport/src/smp_uart.c b/subsys/mgmt/mcumgr/transport/src/smp_uart.c index 643caf6eb48..5bf4e9ade9f 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp_uart.c +++ b/subsys/mgmt/mcumgr/transport/src/smp_uart.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/net/ip/net_pkt.c b/subsys/net/ip/net_pkt.c index 061f875b36f..a5d776ad8ed 100644 --- a/subsys/net/ip/net_pkt.c +++ b/subsys/net/ip/net_pkt.c @@ -33,7 +33,7 @@ LOG_MODULE_REGISTER(net_pkt, CONFIG_NET_PKT_LOG_LEVEL); #include #include -#include +#include #include #include #include diff --git a/subsys/net/l2/ieee802154/ieee802154_priv.h b/subsys/net/l2/ieee802154/ieee802154_priv.h index 6a1da50fc9f..2d78f043699 100644 --- a/subsys/net/l2/ieee802154/ieee802154_priv.h +++ b/subsys/net/l2/ieee802154/ieee802154_priv.h @@ -17,7 +17,7 @@ #ifndef __IEEE802154_PRIV_H__ #define __IEEE802154_PRIV_H__ -#include +#include #include #include diff --git a/subsys/net/lib/dns/dispatcher.c b/subsys/net/lib/dns/dispatcher.c index 0e7e1ac39eb..402cf76e4d3 100644 --- a/subsys/net/lib/dns/dispatcher.c +++ b/subsys/net/lib/dns/dispatcher.c @@ -10,7 +10,7 @@ LOG_MODULE_REGISTER(net_dns_dispatcher, CONFIG_DNS_SOCKET_DISPATCHER_LOG_LEVEL); #include #include #include -#include +#include #include #include diff --git a/subsys/net/lib/dns/dns_internal.h b/subsys/net/lib/dns/dns_internal.h index bc4e479c404..9f71d994850 100644 --- a/subsys/net/lib/dns/dns_internal.h +++ b/subsys/net/lib/dns/dns_internal.h @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include "dns_pack.h" diff --git a/subsys/net/lib/dns/dns_pack.c b/subsys/net/lib/dns/dns_pack.c index 121f6b7a365..3362828d7dd 100644 --- a/subsys/net/lib/dns/dns_pack.c +++ b/subsys/net/lib/dns/dns_pack.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include "dns_pack.h" diff --git a/subsys/net/lib/dns/dns_pack.h b/subsys/net/lib/dns/dns_pack.h index 3fd2db67264..58041ed6e03 100644 --- a/subsys/net/lib/dns/dns_pack.h +++ b/subsys/net/lib/dns/dns_pack.h @@ -8,7 +8,7 @@ #define _DNS_PACK_H_ #include -#include +#include #include #include diff --git a/subsys/net/lib/mqtt_sn/mqtt_sn_msg.h b/subsys/net/lib/mqtt_sn/mqtt_sn_msg.h index 476b83ef9b4..db218e7bb91 100644 --- a/subsys/net/lib/mqtt_sn/mqtt_sn_msg.h +++ b/subsys/net/lib/mqtt_sn/mqtt_sn_msg.h @@ -13,7 +13,7 @@ #define MQTT_SN_MSG_H_ #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/subsys/shell/backends/shell_uart.c b/subsys/shell/backends/shell_uart.c index 7cf4bbf11d0..1d19ce19a31 100644 --- a/subsys/shell/backends/shell_uart.c +++ b/subsys/shell/backends/shell_uart.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #define LOG_MODULE_NAME shell_uart LOG_MODULE_REGISTER(shell_uart); diff --git a/subsys/usb/device/class/audio/audio.c b/subsys/usb/device/class/audio/audio.c index d293b834cab..80b92fd12c8 100644 --- a/subsys/usb/device/class/audio/audio.c +++ b/subsys/usb/device/class/audio/audio.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include LOG_MODULE_REGISTER(usb_audio, CONFIG_USB_AUDIO_LOG_LEVEL); diff --git a/subsys/usb/device/class/bluetooth.c b/subsys/usb/device/class/bluetooth.c index 59e5f31ca9a..942a1076156 100644 --- a/subsys/usb/device/class/bluetooth.c +++ b/subsys/usb/device/class/bluetooth.c @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include diff --git a/subsys/usb/device/class/bt_h4.c b/subsys/usb/device/class/bt_h4.c index 83a94a0e7e3..1aa82b5bbc5 100644 --- a/subsys/usb/device/class/bt_h4.c +++ b/subsys/usb/device/class/bt_h4.c @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include diff --git a/subsys/usb/device_next/class/bt_hci.c b/subsys/usb/device_next/class/bt_hci.c index debefa1fa1d..52eddc4e25b 100644 --- a/subsys/usb/device_next/class/bt_hci.c +++ b/subsys/usb/device_next/class/bt_hci.c @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include diff --git a/subsys/usb/host/usbh_ch9.c b/subsys/usb/host/usbh_ch9.c index e3f55e95eb1..9c2cf087bee 100644 --- a/subsys/usb/host/usbh_ch9.c +++ b/subsys/usb/host/usbh_ch9.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include "usbh_device.h" diff --git a/subsys/zbus/zbus.c b/subsys/zbus/zbus.c index 27008738fa4..110294b32a9 100644 --- a/subsys/zbus/zbus.c +++ b/subsys/zbus/zbus.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include LOG_MODULE_REGISTER(zbus, CONFIG_ZBUS_LOG_LEVEL); diff --git a/tests/bluetooth/at/src/main.c b/tests/bluetooth/at/src/main.c index 62391d874a0..61555017589 100644 --- a/tests/bluetooth/at/src/main.c +++ b/tests/bluetooth/at/src/main.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include "subsys/bluetooth/host/classic/at.h" diff --git a/tests/bluetooth/audio/mocks/src/net_buf.c b/tests/bluetooth/audio/mocks/src/net_buf.c index 70b85426673..2757e1d257b 100644 --- a/tests/bluetooth/audio/mocks/src/net_buf.c +++ b/tests/bluetooth/audio/mocks/src/net_buf.c @@ -5,7 +5,7 @@ */ #include -#include +#include void net_buf_unref(struct net_buf *buf) { diff --git a/tests/bluetooth/ctrl_user_ext/src/hci_user_ext.c b/tests/bluetooth/ctrl_user_ext/src/hci_user_ext.c index 97457ac3bc3..6266bcd1bf6 100644 --- a/tests/bluetooth/ctrl_user_ext/src/hci_user_ext.c +++ b/tests/bluetooth/ctrl_user_ext/src/hci_user_ext.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include "util/memq.h" diff --git a/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c b/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c index 96c472302ac..d30503ce216 100644 --- a/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c +++ b/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include diff --git a/tests/bluetooth/host/ecc/mocks/net_buf.c b/tests/bluetooth/host/ecc/mocks/net_buf.c index 3b0d5102d8d..5a64ac1459a 100644 --- a/tests/bluetooth/host/ecc/mocks/net_buf.c +++ b/tests/bluetooth/host/ecc/mocks/net_buf.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include diff --git a/tests/bluetooth/host/id/mocks/net_buf.c b/tests/bluetooth/host/id/mocks/net_buf.c index dbdba3f4a3a..187da686ee8 100644 --- a/tests/bluetooth/host/id/mocks/net_buf.c +++ b/tests/bluetooth/host/id/mocks/net_buf.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include diff --git a/tests/bluetooth/mesh/delayable_msg/src/main.c b/tests/bluetooth/mesh/delayable_msg/src/main.c index ce96c19c7a7..1d71c80f198 100644 --- a/tests/bluetooth/mesh/delayable_msg/src/main.c +++ b/tests/bluetooth/mesh/delayable_msg/src/main.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include diff --git a/tests/bluetooth/mesh/rpl/src/main.c b/tests/bluetooth/mesh/rpl/src/main.c index c959d4659c3..bd3980d172c 100644 --- a/tests/bluetooth/mesh/rpl/src/main.c +++ b/tests/bluetooth/mesh/rpl/src/main.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include "settings.h" diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c index a3f496bece6..f89f08c7820 100644 --- a/tests/bluetooth/tester/src/btp_core.c +++ b/tests/bluetooth/tester/src/btp_core.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index f45ec548285..f7dfad59418 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -17,7 +17,7 @@ #include #include -#include +#include #include diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index 2f71cef41e7..ee4f1b3cbd9 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #define LOG_MODULE_NAME bttester_gatt diff --git a/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c b/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c index 0a4e4b234d0..463a9e1e899 100644 --- a/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c b/tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c index 35f1c17dc35..6b14894c564 100644 --- a/tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c b/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c index f17753711e2..3508d74efb4 100644 --- a/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c b/tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c index 53ef4636728..395cfcf1149 100644 --- a/tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c index f96b3064186..0b8d47c6941 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c index c2f2fd2c3c5..337c6128020 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c index 6ef9ec7a92d..3d424eafa39 100644 --- a/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/cap_commander_test.c b/tests/bsim/bluetooth/audio/src/cap_commander_test.c index ed86bbc5cae..11e37bc4591 100644 --- a/tests/bsim/bluetooth/audio/src/cap_commander_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_commander_test.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c index d13a8a63706..eebffc06a73 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_broadcast_test.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c index 40fd5c37bff..24c697e0339 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/common.c b/tests/bsim/bluetooth/audio/src/common.c index 30a4ab0422a..9a8e41a5dcd 100644 --- a/tests/bsim/bluetooth/audio/src/common.c +++ b/tests/bsim/bluetooth/audio/src/common.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c b/tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c index 184e8afdd2c..37910d2ad25 100644 --- a/tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c +++ b/tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c b/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c index 2bb93d630f2..be16111858e 100644 --- a/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c +++ b/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/mcc_test.c b/tests/bsim/bluetooth/audio/src/mcc_test.c index 2c1145375b1..b6c0fedf522 100644 --- a/tests/bsim/bluetooth/audio/src/mcc_test.c +++ b/tests/bsim/bluetooth/audio/src/mcc_test.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include "bstests.h" diff --git a/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_sink_test.c b/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_sink_test.c index b12e9ff71aa..625e72a1a36 100644 --- a/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_sink_test.c +++ b/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_sink_test.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c b/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c index 57c02856d90..c9812f10b04 100644 --- a/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c +++ b/tests/bsim/bluetooth/audio/src/pbp_public_broadcast_source_test.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/audio/src/tmap_client_test.c b/tests/bsim/bluetooth/audio/src/tmap_client_test.c index d4c769d2de7..ba5bbb02ee8 100644 --- a/tests/bsim/bluetooth/audio/src/tmap_client_test.c +++ b/tests/bsim/bluetooth/audio/src/tmap_client_test.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/bsim/bluetooth/host/att/pipeline/tester/src/main.c b/tests/bsim/bluetooth/host/att/pipeline/tester/src/main.c index 803917c5ee3..c9af0b4a461 100644 --- a/tests/bsim/bluetooth/host/att/pipeline/tester/src/main.c +++ b/tests/bsim/bluetooth/host/att/pipeline/tester/src/main.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include diff --git a/tests/bsim/bluetooth/host/att/sequential/tester/src/main.c b/tests/bsim/bluetooth/host/att/sequential/tester/src/main.c index 57fbc424b94..5062417f70d 100644 --- a/tests/bsim/bluetooth/host/att/sequential/tester/src/main.c +++ b/tests/bsim/bluetooth/host/att/sequential/tester/src/main.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include diff --git a/tests/bsim/bluetooth/host/l2cap/reassembly/peer/src/peer.c b/tests/bsim/bluetooth/host/l2cap/reassembly/peer/src/peer.c index dce8ffbadb3..3af2f872a5e 100644 --- a/tests/bsim/bluetooth/host/l2cap/reassembly/peer/src/peer.c +++ b/tests/bsim/bluetooth/host/l2cap/reassembly/peer/src/peer.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include diff --git a/tests/bsim/bluetooth/host/l2cap/split/tester/src/main.c b/tests/bsim/bluetooth/host/l2cap/split/tester/src/main.c index 7339c913aae..ba4f23bd050 100644 --- a/tests/bsim/bluetooth/host/l2cap/split/tester/src/main.c +++ b/tests/bsim/bluetooth/host/l2cap/split/tester/src/main.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include diff --git a/tests/bsim/bluetooth/host/misc/disconnect/tester/src/main.c b/tests/bsim/bluetooth/host/misc/disconnect/tester/src/main.c index ebe1224a46a..fba4eeacf8a 100644 --- a/tests/bsim/bluetooth/host/misc/disconnect/tester/src/main.c +++ b/tests/bsim/bluetooth/host/misc/disconnect/tester/src/main.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include diff --git a/tests/bsim/bluetooth/host/misc/hfc_multilink/tester/src/tester.c b/tests/bsim/bluetooth/host/misc/hfc_multilink/tester/src/tester.c index 370f6fbe932..866899d7a38 100644 --- a/tests/bsim/bluetooth/host/misc/hfc_multilink/tester/src/tester.c +++ b/tests/bsim/bluetooth/host/misc/hfc_multilink/tester/src/tester.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include diff --git a/tests/bsim/bluetooth/ll/edtt/hci_test_app/src/main.c b/tests/bsim/bluetooth/ll/edtt/hci_test_app/src/main.c index 84ff767cdaf..33a9ed27b5d 100644 --- a/tests/bsim/bluetooth/ll/edtt/hci_test_app/src/main.c +++ b/tests/bsim/bluetooth/ll/edtt/hci_test_app/src/main.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include diff --git a/tests/lib/cpp/cxx/src/main.cpp b/tests/lib/cpp/cxx/src/main.cpp index 1f6864a3375..fe26eb5475e 100644 --- a/tests/lib/cpp/cxx/src/main.cpp +++ b/tests/lib/cpp/cxx/src/main.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/net/buf/src/main.c b/tests/net/buf/src/main.c index 5bf1c4ce31b..e29c4764763 100644 --- a/tests/net/buf/src/main.c +++ b/tests/net/buf/src/main.c @@ -11,7 +11,7 @@ #include #include -#include +#include #include diff --git a/tests/net/buf_simple/src/main.c b/tests/net/buf_simple/src/main.c index de5edd4dfe8..1355d893f6b 100644 --- a/tests/net/buf_simple/src/main.c +++ b/tests/net/buf_simple/src/main.c @@ -7,7 +7,7 @@ #include #include -#include +#include DEFINE_FFF_GLOBALS; diff --git a/tests/net/checksum_offload/src/main.c b/tests/net/checksum_offload/src/main.c index b41158f4ec3..cb86c98681e 100644 --- a/tests/net/checksum_offload/src/main.c +++ b/tests/net/checksum_offload/src/main.c @@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include #include -#include +#include #include #include #include diff --git a/tests/net/context/src/main.c b/tests/net/context/src/main.c index 793ce6022a8..47a553a5934 100644 --- a/tests/net/context/src/main.c +++ b/tests/net/context/src/main.c @@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_CONTEXT_LOG_LEVEL); #include #include -#include +#include #include #include #include diff --git a/tests/net/hostname/src/main.c b/tests/net/hostname/src/main.c index 1f007db4807..762bc0efbb1 100644 --- a/tests/net/hostname/src/main.c +++ b/tests/net/hostname/src/main.c @@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include #include -#include +#include #include #include diff --git a/tests/net/icmp/src/main.c b/tests/net/icmp/src/main.c index 1e1dd690a07..b8f077bdc10 100644 --- a/tests/net/icmp/src/main.c +++ b/tests/net/icmp/src/main.c @@ -30,7 +30,7 @@ LOG_MODULE_REGISTER(net_test, ICMP_LOG_LEVEL); #include #include #include -#include +#include #include #include #include diff --git a/tests/net/icmpv4/src/main.c b/tests/net/icmpv4/src/main.c index afa5c007280..36e9436065d 100644 --- a/tests/net/icmpv4/src/main.c +++ b/tests/net/icmpv4/src/main.c @@ -19,7 +19,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_ICMPV4_LOG_LEVEL); #include -#include +#include #include #include #include diff --git a/tests/net/icmpv6/src/main.c b/tests/net/icmpv6/src/main.c index 8594f628fc2..0ee9d3ba127 100644 --- a/tests/net/icmpv6/src/main.c +++ b/tests/net/icmpv6/src/main.c @@ -19,7 +19,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_ICMPV6_LOG_LEVEL); #include -#include +#include #include #include #include diff --git a/tests/net/iface/src/main.c b/tests/net/iface/src/main.c index 2d1be245b87..b4928d2d782 100644 --- a/tests/net/iface/src/main.c +++ b/tests/net/iface/src/main.c @@ -25,7 +25,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include #include -#include +#include #include #include diff --git a/tests/net/ipv4_fragment/src/main.c b/tests/net/ipv4_fragment/src/main.c index 2846e324a4d..9379af361a1 100644 --- a/tests/net/ipv4_fragment/src/main.c +++ b/tests/net/ipv4_fragment/src/main.c @@ -17,7 +17,7 @@ LOG_MODULE_REGISTER(net_ipv4_test, CONFIG_NET_IPV4_LOG_LEVEL); #include #include #include -#include +#include #include #include #include diff --git a/tests/net/ipv6_fragment/src/main.c b/tests/net/ipv6_fragment/src/main.c index 702723a5883..572d70d94d0 100644 --- a/tests/net/ipv6_fragment/src/main.c +++ b/tests/net/ipv6_fragment/src/main.c @@ -22,7 +22,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_IPV6_LOG_LEVEL); #include #include -#include +#include #include #include diff --git a/tests/net/lib/dns_addremove/src/main.c b/tests/net/lib/dns_addremove/src/main.c index 5d8d227dff9..eb8d25a5fa5 100644 --- a/tests/net/lib/dns_addremove/src/main.c +++ b/tests/net/lib/dns_addremove/src/main.c @@ -19,7 +19,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_DNS_RESOLVER_LOG_LEVEL); #include #include -#include +#include #include #include #include diff --git a/tests/net/lib/dns_resolve/src/main.c b/tests/net/lib/dns_resolve/src/main.c index 9d8696f545a..c5d17941087 100644 --- a/tests/net/lib/dns_resolve/src/main.c +++ b/tests/net/lib/dns_resolve/src/main.c @@ -19,7 +19,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_DNS_RESOLVER_LOG_LEVEL); #include #include -#include +#include #include #include #include diff --git a/tests/net/ppp/driver/src/main.c b/tests/net/ppp/driver/src/main.c index 1c7cad29c37..abedb53fb71 100644 --- a/tests/net/ppp/driver/src/main.c +++ b/tests/net/ppp/driver/src/main.c @@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include #include -#include +#include #include #include diff --git a/tests/net/ptp/clock/src/main.c b/tests/net/ptp/clock/src/main.c index 03a1e970b9e..53d46db76c6 100644 --- a/tests/net/ptp/clock/src/main.c +++ b/tests/net/ptp/clock/src/main.c @@ -27,7 +27,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include #include -#include +#include #include #include diff --git a/tests/net/route/src/main.c b/tests/net/route/src/main.c index 276bdc9a248..dcdf48cb12e 100644 --- a/tests/net/route/src/main.c +++ b/tests/net/route/src/main.c @@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_ROUTE_LOG_LEVEL); #include #include -#include +#include #include #include #include diff --git a/tests/net/route_mcast/src/main.c b/tests/net/route_mcast/src/main.c index 3947b9e274c..be30a79462d 100644 --- a/tests/net/route_mcast/src/main.c +++ b/tests/net/route_mcast/src/main.c @@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_ROUTE_LOG_LEVEL); #include #include -#include +#include #include #include #include diff --git a/tests/net/shell/src/main.c b/tests/net/shell/src/main.c index f7bb1a6437a..39ef093b4e3 100644 --- a/tests/net/shell/src/main.c +++ b/tests/net/shell/src/main.c @@ -22,7 +22,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include #include #include -#include +#include #include #include #include diff --git a/tests/net/socket/getaddrinfo/src/main.c b/tests/net/socket/getaddrinfo/src/main.c index 37d960cb4b7..a3f455dc4e1 100644 --- a/tests/net/socket/getaddrinfo/src/main.c +++ b/tests/net/socket/getaddrinfo/src/main.c @@ -13,7 +13,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL); #include #include #include -#include +#include #include "../../socket_helpers.h" diff --git a/tests/net/traffic_class/src/main.c b/tests/net/traffic_class/src/main.c index cc07c6173f7..3ef933e8e23 100644 --- a/tests/net/traffic_class/src/main.c +++ b/tests/net/traffic_class/src/main.c @@ -24,7 +24,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include #include -#include +#include #include #include #include diff --git a/tests/net/trickle/src/main.c b/tests/net/trickle/src/main.c index 86dfd01d844..5aae8c67ee4 100644 --- a/tests/net/trickle/src/main.c +++ b/tests/net/trickle/src/main.c @@ -20,7 +20,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_TRICKLE_LOG_LEVEL); #include -#include +#include #include #include diff --git a/tests/net/tx_timestamp/src/main.c b/tests/net/tx_timestamp/src/main.c index 4b072d1525a..05e670ec4ce 100644 --- a/tests/net/tx_timestamp/src/main.c +++ b/tests/net/tx_timestamp/src/main.c @@ -22,7 +22,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include -#include +#include #include #include #include diff --git a/tests/net/udp/src/main.c b/tests/net/udp/src/main.c index e87269d8295..f06ee2edc77 100644 --- a/tests/net/udp/src/main.c +++ b/tests/net/udp/src/main.c @@ -22,7 +22,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include #include #include -#include +#include #include #include #include diff --git a/tests/net/virtual/src/main.c b/tests/net/virtual/src/main.c index 20d0729c56e..12dacdaea06 100644 --- a/tests/net/virtual/src/main.c +++ b/tests/net/virtual/src/main.c @@ -22,7 +22,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include #include -#include +#include #include #include #include diff --git a/tests/net/vlan/src/main.c b/tests/net/vlan/src/main.c index a7851cc2fc6..a6d2f88a892 100644 --- a/tests/net/vlan/src/main.c +++ b/tests/net/vlan/src/main.c @@ -25,7 +25,7 @@ LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL); #include #include #include -#include +#include #include #include #include diff --git a/tests/subsys/canbus/isotp/implementation/src/main.c b/tests/subsys/canbus/isotp/implementation/src/main.c index bbc2cadb6ce..c08e9b7339c 100644 --- a/tests/subsys/canbus/isotp/implementation/src/main.c +++ b/tests/subsys/canbus/isotp/implementation/src/main.c @@ -7,7 +7,7 @@ #include #include #include "random_data.h" -#include +#include #define NUMBER_OF_REPETITIONS 5 #define DATA_SIZE_SF 7 diff --git a/tests/subsys/mgmt/mcumgr/cb_notifications/src/main.c b/tests/subsys/mgmt/mcumgr/cb_notifications/src/main.c index aa1bd143ed9..f76599532a9 100644 --- a/tests/subsys/mgmt/mcumgr/cb_notifications/src/main.c +++ b/tests/subsys/mgmt/mcumgr/cb_notifications/src/main.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c index 270f232af77..a1d8d893515 100644 --- a/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c @@ -6,7 +6,7 @@ #include "smp_test_util.h" #include -#include +#include #include #include diff --git a/tests/subsys/mgmt/mcumgr/enum_mgmt/src/main.c b/tests/subsys/mgmt/mcumgr/enum_mgmt/src/main.c index 2bf677e4019..d196817f140 100644 --- a/tests/subsys/mgmt/mcumgr/enum_mgmt/src/main.c +++ b/tests/subsys/mgmt/mcumgr/enum_mgmt/src/main.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/enum_mgmt/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/enum_mgmt/src/smp_test_util.c index 18e5847cb7e..9a0136067f3 100644 --- a/tests/subsys/mgmt/mcumgr/enum_mgmt/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/enum_mgmt/src/smp_test_util.c @@ -6,7 +6,7 @@ #include "smp_test_util.h" #include -#include +#include #include #include diff --git a/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c b/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c index 30575172a84..7c76c28ced0 100644 --- a/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c +++ b/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c index 9b12fd7b2b0..460b8a0a08c 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.h b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.h index 95fdbc8203b..029e7062e52 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.h +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.h @@ -7,7 +7,7 @@ #define H_IMG_GR_STUB_ #include -#include +#include #ifdef __cplusplus diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c index c724c72c2cc..561ad2f8299 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c index c7196874556..e5314a30ba5 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.h b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.h index ec6f3408979..5a21388e566 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.h +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.h @@ -7,7 +7,7 @@ #define H_OS_GR_STUB_ #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/smp_stub.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/smp_stub.c index 9b476082dd8..682991a05eb 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/smp_stub.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/smp_stub.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/smp_stub.h b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/smp_stub.h index c8668a033d2..df50eb42bf6 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/smp_stub.h +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/smp_stub.h @@ -7,7 +7,7 @@ #define H_SMP_STUB_ #include -#include +#include #include diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c index 47e8720cb63..a07635ddfea 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c @@ -6,7 +6,7 @@ */ #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c index d2b969999cd..a893c84cfdd 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c @@ -7,7 +7,7 @@ #include "smp_test_util.h" #include -#include +#include #include #include diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_echo/src/main.c b/tests/subsys/mgmt/mcumgr/os_mgmt_echo/src/main.c index 2f48fd1d215..9dde48cbe4c 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_echo/src/main.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_echo/src/main.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c index a1503e0f9cf..9ea5725b92a 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c index 9932d11b7a0..f9b6520525b 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c @@ -7,7 +7,7 @@ #if defined(CONFIG_LIMITED_TEST) #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c index f1828856ebb..69d05575884 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c @@ -7,7 +7,7 @@ #if !defined(CONFIG_BUILD_DATE_TIME_TEST) && !defined(CONFIG_LIMITED_TEST) #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c index b76ac1ad623..6822bbbfbda 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c @@ -6,7 +6,7 @@ #include "smp_test_util.h" #include -#include +#include #include #include diff --git a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c index 869a4f750d9..e5da57b4009 100644 --- a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c +++ b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c index dcabd0d08c3..df80c9c572f 100644 --- a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c @@ -6,7 +6,7 @@ #include "smp_test_util.h" #include -#include +#include #include #include diff --git a/tests/subsys/mgmt/mcumgr/smp_client/src/main.c b/tests/subsys/mgmt/mcumgr/smp_client/src/main.c index 7b6ad8eafa8..8f20cc92089 100644 --- a/tests/subsys/mgmt/mcumgr/smp_client/src/main.c +++ b/tests/subsys/mgmt/mcumgr/smp_client/src/main.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/smp_client/src/smp_transport_stub.c b/tests/subsys/mgmt/mcumgr/smp_client/src/smp_transport_stub.c index d3248755e5a..b7b6234292d 100644 --- a/tests/subsys/mgmt/mcumgr/smp_client/src/smp_transport_stub.c +++ b/tests/subsys/mgmt/mcumgr/smp_client/src/smp_transport_stub.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/smp_client/src/smp_transport_stub.h b/tests/subsys/mgmt/mcumgr/smp_client/src/smp_transport_stub.h index 9046aff622c..43c46b04267 100644 --- a/tests/subsys/mgmt/mcumgr/smp_client/src/smp_transport_stub.h +++ b/tests/subsys/mgmt/mcumgr/smp_client/src/smp_transport_stub.h @@ -7,7 +7,7 @@ #define H_OS_GR_STUB_ #include -#include +#include #include #ifdef __cplusplus diff --git a/tests/subsys/mgmt/mcumgr/smp_reassembly/src/main.c b/tests/subsys/mgmt/mcumgr/smp_reassembly/src/main.c index 2a4bab57993..d6bcaef97a6 100644 --- a/tests/subsys/mgmt/mcumgr/smp_reassembly/src/main.c +++ b/tests/subsys/mgmt/mcumgr/smp_reassembly/src/main.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/smp_version/src/main.c b/tests/subsys/mgmt/mcumgr/smp_version/src/main.c index ed596ae964e..704343b4208 100644 --- a/tests/subsys/mgmt/mcumgr/smp_version/src/main.c +++ b/tests/subsys/mgmt/mcumgr/smp_version/src/main.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include diff --git a/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c index 96d97a6b6fa..5f47f939457 100644 --- a/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c @@ -6,7 +6,7 @@ #include "smp_test_util.h" #include -#include +#include #include #include