Skip to content

Commit c409099

Browse files
lylezhu2012kartben
authored andcommitted
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 <[email protected]>
1 parent e8b29aa commit c409099

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

include/zephyr/bluetooth/classic/rfcomm.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,27 @@
1919

2020
#include <zephyr/bluetooth/buf.h>
2121
#include <zephyr/bluetooth/conn.h>
22+
#include <zephyr/bluetooth/l2cap.h>
2223

2324
#ifdef __cplusplus
2425
extern "C" {
2526
#endif
2627

28+
/** RFCOMM Maximum Header Size. The length could be 2 bytes, it depends on information length. */
29+
#define BT_RFCOMM_HDR_MAX_SIZE 4
30+
/** RFCOMM FCS Size */
31+
#define BT_RFCOMM_FCS_SIZE 1
32+
33+
/** @brief Helper to calculate needed buffer size for RFCOMM PDUs.
34+
* Useful for creating buffer pools.
35+
*
36+
* @param mtu Needed RFCOMM PDU MTU.
37+
*
38+
* @return Needed buffer size to match the requested RFCOMM PDU MTU.
39+
*/
40+
#define BT_RFCOMM_BUF_SIZE(mtu) \
41+
BT_L2CAP_BUF_SIZE(BT_RFCOMM_HDR_MAX_SIZE + BT_RFCOMM_FCS_SIZE + (mtu))
42+
2743
/* RFCOMM channels (1-30): pre-allocated for profiles to avoid conflicts */
2844
enum {
2945
BT_RFCOMM_CHAN_HFP_HF = 1,

subsys/bluetooth/host/classic/rfcomm_internal.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@ struct bt_rfcomm_rpn {
133133
#define BT_RFCOMM_CHECK_MTU(mtu) (!!((mtu) >= BT_RFCOMM_SIG_MIN_MTU && \
134134
(mtu) <= BT_RFCOMM_SIG_MAX_MTU))
135135

136-
/* Helper to calculate needed outgoing buffer size.
137-
* Length in rfcomm header can be two bytes depending on user data length.
138-
* One byte in the tail should be reserved for FCS.
139-
*/
140-
#define BT_RFCOMM_BUF_SIZE(mtu) (BT_BUF_RESERVE + \
141-
BT_HCI_ACL_HDR_SIZE + BT_L2CAP_HDR_SIZE + \
142-
sizeof(struct bt_rfcomm_hdr) + 1 + (mtu) + \
143-
BT_RFCOMM_FCS_SIZE)
144-
145136
#define BT_RFCOMM_GET_DLCI(addr) (((addr) & 0xfc) >> 2)
146137
#define BT_RFCOMM_GET_FRAME_TYPE(ctrl) ((ctrl) & 0xef)
147138
#define BT_RFCOMM_GET_MSG_TYPE(type) (((type) & 0xfc) >> 2)
@@ -192,7 +183,6 @@ struct bt_rfcomm_rpn {
192183

193184
/* Length can be 2 bytes depending on data size */
194185
#define BT_RFCOMM_HDR_SIZE (sizeof(struct bt_rfcomm_hdr) + 1)
195-
#define BT_RFCOMM_FCS_SIZE 1
196186

197187
#define BT_RFCOMM_FCS_LEN_UIH 2
198188
#define BT_RFCOMM_FCS_LEN_NON_UIH 3

0 commit comments

Comments
 (0)