net: buf: Add support for 64 bit data type
This enables pulling and pushing values in 64 bit format. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
e0a55796b2
commit
8724f4a2ee
|
@ -315,6 +315,30 @@ void net_buf_simple_add_le48(struct net_buf_simple *buf, u64_t val);
|
|||
*/
|
||||
void net_buf_simple_add_be48(struct net_buf_simple *buf, u64_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, u64_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, u64_t val);
|
||||
|
||||
/**
|
||||
* @brief Push data to the beginning of the buffer.
|
||||
*
|
||||
|
@ -494,6 +518,30 @@ u64_t net_buf_simple_pull_le48(struct net_buf_simple *buf);
|
|||
*/
|
||||
u64_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.
|
||||
*/
|
||||
u64_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.
|
||||
*/
|
||||
u64_t net_buf_simple_pull_be64(struct net_buf_simple *buf);
|
||||
|
||||
/**
|
||||
* @brief Get the tail pointer for a buffer.
|
||||
*
|
||||
|
@ -1286,6 +1334,32 @@ static inline void *net_buf_user_data(const struct net_buf *buf)
|
|||
*/
|
||||
#define net_buf_add_be48(buf, val) net_buf_simple_add_be48(&(buf)->b, val)
|
||||
|
||||
/**
|
||||
* @def net_buf_add_le64
|
||||
* @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.
|
||||
*/
|
||||
#define net_buf_add_le64(buf, val) net_buf_simple_add_le64(&(buf)->b, val)
|
||||
|
||||
/**
|
||||
* @def net_buf_add_be64
|
||||
* @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.
|
||||
*/
|
||||
#define net_buf_add_be64(buf, val) net_buf_simple_add_be64(&(buf)->b, val)
|
||||
|
||||
/**
|
||||
* @def net_buf_push
|
||||
* @brief Push data to the beginning of the buffer.
|
||||
|
@ -1480,6 +1554,32 @@ static inline void *net_buf_user_data(const struct net_buf *buf)
|
|||
*/
|
||||
#define net_buf_pull_be48(buf) net_buf_simple_pull_be48(&(buf)->b)
|
||||
|
||||
/**
|
||||
* @def net_buf_pull_le64
|
||||
* @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.
|
||||
*/
|
||||
#define net_buf_pull_le64(buf) net_buf_simple_pull_le64(&(buf)->b)
|
||||
|
||||
/**
|
||||
* @def net_buf_pull_be64
|
||||
* @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.
|
||||
*/
|
||||
#define net_buf_pull_be64(buf) net_buf_simple_pull_be64(&(buf)->b)
|
||||
|
||||
/**
|
||||
* @def net_buf_tailroom
|
||||
* @brief Check buffer tailroom.
|
||||
|
|
|
@ -860,6 +860,20 @@ void net_buf_simple_add_be48(struct net_buf_simple *buf, u64_t val)
|
|||
sys_put_be48(val, net_buf_simple_add(buf, 6));
|
||||
}
|
||||
|
||||
void net_buf_simple_add_le64(struct net_buf_simple *buf, u64_t val)
|
||||
{
|
||||
NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val);
|
||||
|
||||
sys_put_le64(val, net_buf_simple_add(buf, sizeof(val)));
|
||||
}
|
||||
|
||||
void net_buf_simple_add_be64(struct net_buf_simple *buf, u64_t val)
|
||||
{
|
||||
NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val);
|
||||
|
||||
sys_put_be64(val, net_buf_simple_add(buf, sizeof(val)));
|
||||
}
|
||||
|
||||
void *net_buf_simple_push(struct net_buf_simple *buf, size_t len)
|
||||
{
|
||||
NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len);
|
||||
|
@ -1014,6 +1028,26 @@ u64_t net_buf_simple_pull_be48(struct net_buf_simple *buf)
|
|||
return sys_be48_to_cpu(val.u48);
|
||||
}
|
||||
|
||||
u64_t net_buf_simple_pull_le64(struct net_buf_simple *buf)
|
||||
{
|
||||
u64_t val;
|
||||
|
||||
val = UNALIGNED_GET((u64_t *)buf->data);
|
||||
net_buf_simple_pull(buf, sizeof(val));
|
||||
|
||||
return sys_le64_to_cpu(val);
|
||||
}
|
||||
|
||||
u64_t net_buf_simple_pull_be64(struct net_buf_simple *buf)
|
||||
{
|
||||
u64_t val;
|
||||
|
||||
val = UNALIGNED_GET((u64_t *)buf->data);
|
||||
net_buf_simple_pull(buf, sizeof(val));
|
||||
|
||||
return sys_be64_to_cpu(val);
|
||||
}
|
||||
|
||||
size_t net_buf_simple_headroom(struct net_buf_simple *buf)
|
||||
{
|
||||
return buf->data - buf->__buf;
|
||||
|
|
Loading…
Reference in a new issue