From 2786490059cee42ed9911e65327010b1ccbb0c6d Mon Sep 17 00:00:00 2001 From: Lyle Zhu Date: Fri, 10 Jan 2025 10:36:18 +0800 Subject: [PATCH] Bluetooth: RFCOMM: Move BT_RFCOMM_BUF_SIZE to rfcomm.h The buffer `BT_RFCOMM_BUF_SIZE` is used to define the TX buffer size of TX pool. In current implementation, the TX buffer size of RFCOMM cannot be calculated due to the macro `BT_RFCOMM_BUF_SIZE` is defined in internal header file `rfcomm_internal.h`. Move the macro `BT_RFCOMM_BUF_SIZE` form internal header file `rfcomm_internal.h` to interface `rfcomm.h`. Signed-off-by: Lyle Zhu --- include/zephyr/bluetooth/classic/rfcomm.h | 16 ++++++++++++++++ subsys/bluetooth/host/classic/rfcomm_internal.h | 10 ---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/zephyr/bluetooth/classic/rfcomm.h b/include/zephyr/bluetooth/classic/rfcomm.h index 1d3056643bd0b6..d2ce71ce645604 100644 --- a/include/zephyr/bluetooth/classic/rfcomm.h +++ b/include/zephyr/bluetooth/classic/rfcomm.h @@ -19,11 +19,27 @@ #include #include +#include #ifdef __cplusplus extern "C" { #endif +/** RFCOMM Maximum Header Size. The length could be 2 bytes, it depends on information length. */ +#define BT_RFCOMM_HDR_MAX_SIZE 4 +/** RFCOMM FCS Size */ +#define BT_RFCOMM_FCS_SIZE 1 + +/** @brief Helper to calculate needed buffer size for RFCOMM PDUs. + * Useful for creating buffer pools. + * + * @param mtu Needed RFCOMM PDU MTU. + * + * @return Needed buffer size to match the requested RFCOMM PDU MTU. + */ +#define BT_RFCOMM_BUF_SIZE(mtu) \ + BT_L2CAP_BUF_SIZE(BT_RFCOMM_HDR_MAX_SIZE + BT_RFCOMM_FCS_SIZE + (mtu)) + /* RFCOMM channels (1-30): pre-allocated for profiles to avoid conflicts */ enum { BT_RFCOMM_CHAN_HFP_HF = 1, diff --git a/subsys/bluetooth/host/classic/rfcomm_internal.h b/subsys/bluetooth/host/classic/rfcomm_internal.h index 07ff13bd0e9b3d..afc7b366d15334 100644 --- a/subsys/bluetooth/host/classic/rfcomm_internal.h +++ b/subsys/bluetooth/host/classic/rfcomm_internal.h @@ -133,15 +133,6 @@ struct bt_rfcomm_rpn { #define BT_RFCOMM_CHECK_MTU(mtu) (!!((mtu) >= BT_RFCOMM_SIG_MIN_MTU && \ (mtu) <= BT_RFCOMM_SIG_MAX_MTU)) -/* Helper to calculate needed outgoing buffer size. - * Length in rfcomm header can be two bytes depending on user data length. - * One byte in the tail should be reserved for FCS. - */ -#define BT_RFCOMM_BUF_SIZE(mtu) (BT_BUF_RESERVE + \ - BT_HCI_ACL_HDR_SIZE + BT_L2CAP_HDR_SIZE + \ - sizeof(struct bt_rfcomm_hdr) + 1 + (mtu) + \ - BT_RFCOMM_FCS_SIZE) - #define BT_RFCOMM_GET_DLCI(addr) (((addr) & 0xfc) >> 2) #define BT_RFCOMM_GET_FRAME_TYPE(ctrl) ((ctrl) & 0xef) #define BT_RFCOMM_GET_MSG_TYPE(type) (((type) & 0xfc) >> 2) @@ -192,7 +183,6 @@ struct bt_rfcomm_rpn { /* Length can be 2 bytes depending on data size */ #define BT_RFCOMM_HDR_SIZE (sizeof(struct bt_rfcomm_hdr) + 1) -#define BT_RFCOMM_FCS_SIZE 1 #define BT_RFCOMM_FCS_LEN_UIH 2 #define BT_RFCOMM_FCS_LEN_NON_UIH 3