Bluetooth: host: Make acl_data extension of bt_buf user data explicit
Clarify that the acl_data struct includes the bt_buf type as the
first variable in the user data struct.
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
diff --git a/include/bluetooth/buf.h b/include/bluetooth/buf.h
index 595cbbb..8ceacb7 100644
--- a/include/bluetooth/buf.h
+++ b/include/bluetooth/buf.h
@@ -40,6 +40,11 @@
BT_BUF_H4,
};
+/** @brief This is a base type for bt_buf user data. */
+struct bt_buf_data {
+ uint8_t type;
+};
+
/** Minimum amount of user data size for buffers passed to the stack. */
#define BT_BUF_USER_DATA_MIN __DEPRECATED_MACRO 4
@@ -114,7 +119,7 @@
*/
static inline void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)
{
- *(uint8_t *)net_buf_user_data(buf) = type;
+ ((struct bt_buf_data *)net_buf_user_data(buf))->type = type;
}
/** Get the buffer type
@@ -125,13 +130,7 @@
*/
static inline enum bt_buf_type bt_buf_get_type(struct net_buf *buf)
{
- /* De-referencing the pointer from net_buf_user_data(buf) as a
- * pointer to an enum causes issues on qemu_x86 because the true
- * size is 8-bit, but the enum is 32-bit on qemu_x86. So we put in
- * a temporary cast to 8-bit to ensure only 8 bits are read from
- * the pointer.
- */
- return (enum bt_buf_type)(*(uint8_t *)net_buf_user_data(buf));
+ return ((struct bt_buf_data *)net_buf_user_data(buf))->type;
}
/**
diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h
index 6a71f1c..4518c97 100644
--- a/subsys/bluetooth/host/conn_internal.h
+++ b/subsys/bluetooth/host/conn_internal.h
@@ -118,8 +118,8 @@
};
struct acl_data {
- /** BT_BUF_ACL_IN */
- uint8_t type;
+ /* Extend the bt_buf user data */
+ struct bt_buf_data buf_data;
/* Index into the bt_conn storage array */
uint8_t index;
diff --git a/subsys/bluetooth/host/sdp.c b/subsys/bluetooth/host/sdp.c
index f1371b8..bbf717a 100644
--- a/subsys/bluetooth/host/sdp.c
+++ b/subsys/bluetooth/host/sdp.c
@@ -13,6 +13,7 @@
#include <sys/byteorder.h>
#include <sys/__assert.h>
+#include <bluetooth/buf.h>
#include <bluetooth/sdp.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_SDP)
diff --git a/subsys/bluetooth/host/ssp.c b/subsys/bluetooth/host/ssp.c
index 453882b..5ece0dd 100644
--- a/subsys/bluetooth/host/ssp.c
+++ b/subsys/bluetooth/host/ssp.c
@@ -9,6 +9,7 @@
#include <sys/byteorder.h>
+#include <bluetooth/buf.h>
#include <bluetooth/hci.h>
#include <bluetooth/addr.h>