diff --git a/include/bluetooth/buf.h b/include/bluetooth/buf.h index 595cbbbd9b1..8ceacb76314 100644 --- a/include/bluetooth/buf.h +++ b/include/bluetooth/buf.h @@ -40,6 +40,11 @@ enum bt_buf_type { 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 @@ struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeou */ 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 void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type) */ 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 6a71f1cebf6..4518c97eaf4 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -118,8 +118,8 @@ struct bt_conn_tx { }; 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 f1371b879c1..bbf717a4d08 100644 --- a/subsys/bluetooth/host/sdp.c +++ b/subsys/bluetooth/host/sdp.c @@ -13,6 +13,7 @@ #include #include +#include #include #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 453882b309a..5ece0dda8cb 100644 --- a/subsys/bluetooth/host/ssp.c +++ b/subsys/bluetooth/host/ssp.c @@ -9,6 +9,7 @@ #include +#include #include #include