Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/bluetooth/l2cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ typedef enum bt_l2cap_chan_status {
/** Channel output status */
BT_L2CAP_STATUS_OUT,

/** Channel shutdown status
*
* Once this status is notified it means the channel will no longer be
* able to transmit or receive data.
*/
BT_L2CAP_STATUS_SHUTDOWN,

/* Total number of status - must be at the end of the enum */
BT_L2CAP_NUM_STATUS,
} __packed bt_l2cap_chan_status_t;
Expand Down Expand Up @@ -126,6 +133,8 @@ struct bt_l2cap_le_chan {
struct k_fifo tx_queue;
/** Channel Pending Transmission buffer */
struct net_buf *tx_buf;
/** Channel Transmission work */
struct k_work tx_work;
/** Segment SDU packet from upper layer */
struct net_buf *_sdu;
u16_t _sdu_len;
Expand Down
2 changes: 2 additions & 0 deletions subsys/bluetooth/host/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ config BT_HCI_CMD_COUNT

config BT_RX_BUF_COUNT
int "Number of HCI RX buffers"
default NET_BUF_RX_COUNT if NET_L2_BT
default 3 if BT_RECV_IS_RX_THREAD
default 20 if (BT_MESH && !(BT_DISCARDABLE_BUF_COUNT > 0))
default 10
Expand Down Expand Up @@ -233,6 +234,7 @@ if BT_HCI_ACL_FLOW_CONTROL
config BT_ACL_RX_COUNT
int "Number of incoming ACL data buffers"
default BT_CTLR_RX_BUFFERS if BT_CTLR
default NET_BUF_RX_COUNT if NET_L2_BT
default 6
range 1 64
help
Expand Down
2 changes: 2 additions & 0 deletions subsys/bluetooth/host/Kconfig.l2cap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ endif # BT_HCI_ACL_FLOW_CONTROL

config BT_L2CAP_TX_BUF_COUNT
int "Number of L2CAP TX buffers"
default NET_BUF_TX_COUNT if NET_L2_BT
default BT_CTLR_TX_BUFFERS if BT_CTLR
default 3
range 2 255
Expand All @@ -27,6 +28,7 @@ config BT_L2CAP_TX_BUF_COUNT

config BT_L2CAP_TX_FRAG_COUNT
int "Number of L2CAP TX fragment buffers"
default NET_BUF_TX_COUNT if NET_L2_BT
default 2
range 0 255
help
Expand Down
47 changes: 42 additions & 5 deletions subsys/bluetooth/host/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,11 +1385,7 @@ static struct net_buf *create_frag(struct bt_conn *conn, struct net_buf *buf)
struct net_buf *frag;
u16_t frag_len;

#if CONFIG_BT_L2CAP_TX_FRAG_COUNT > 0
frag = bt_conn_create_pdu(&frag_pool, 0);
#else
frag = bt_conn_create_pdu(NULL, 0);
#endif
frag = bt_conn_create_frag(0);

if (conn->state != BT_CONN_CONNECTED) {
net_buf_unref(frag);
Expand Down Expand Up @@ -2305,8 +2301,35 @@ int bt_conn_le_conn_update(struct bt_conn *conn,
return bt_hci_cmd_send_sync(BT_HCI_OP_LE_CONN_UPDATE, buf, NULL);
}

#if defined(CONFIG_NET_BUF_LOG)
struct net_buf *bt_conn_create_frag_timeout_debug(size_t reserve, s32_t timeout,
const char *func, int line)
#else
struct net_buf *bt_conn_create_frag_timeout(size_t reserve, s32_t timeout)
#endif
{
struct net_buf_pool *pool = NULL;

#if CONFIG_BT_L2CAP_TX_FRAG_COUNT > 0
pool = &frag_pool;
#endif

#if defined(CONFIG_NET_BUF_LOG)
return bt_conn_create_pdu_timeout_debug(pool, reserve, timeout,
func, line);
#else
return bt_conn_create_pdu_timeout(pool, reserve, timeout);
#endif /* CONFIG_NET_BUF_LOG */
}

#if defined(CONFIG_NET_BUF_LOG)
struct net_buf *bt_conn_create_pdu_timeout_debug(struct net_buf_pool *pool,
size_t reserve, s32_t timeout,
const char *func, int line)
#else
struct net_buf *bt_conn_create_pdu_timeout(struct net_buf_pool *pool,
size_t reserve, s32_t timeout)
#endif
{
struct net_buf *buf;

Expand All @@ -2321,13 +2344,27 @@ struct net_buf *bt_conn_create_pdu_timeout(struct net_buf_pool *pool,
}

if (IS_ENABLED(CONFIG_BT_DEBUG_CONN)) {
#if defined(CONFIG_NET_BUF_LOG)
buf = net_buf_alloc_fixed_debug(pool, K_NO_WAIT, func, line);
Copy link
Contributor

@joerchan joerchan Dec 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create a define for this? It would make the code more readable if we could avoid all those #ifs in the code.
Similar to the definition of this function itself.

#else
buf = net_buf_alloc(pool, K_NO_WAIT);
#endif
if (!buf) {
BT_WARN("Unable to allocate buffer with K_NO_WAIT");
#if defined(CONFIG_NET_BUF_LOG)
buf = net_buf_alloc_fixed_debug(pool, timeout, func,
line);
#else
buf = net_buf_alloc(pool, timeout);
#endif
}
} else {
#if defined(CONFIG_NET_BUF_LOG)
buf = net_buf_alloc_fixed_debug(pool, timeout, func,
line);
#else
buf = net_buf_alloc(pool, timeout);
#endif
}

if (!buf) {
Expand Down
32 changes: 32 additions & 0 deletions subsys/bluetooth/host/conn_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,43 @@ void bt_conn_security_changed(struct bt_conn *conn, enum bt_security_err err);
#endif /* CONFIG_BT_SMP || CONFIG_BT_BREDR */

/* Prepare a PDU to be sent over a connection */
#if defined(CONFIG_NET_BUF_LOG)
struct net_buf *bt_conn_create_pdu_timeout_debug(struct net_buf_pool *pool,
size_t reserve, s32_t timeout,
const char *func, int line);
#define bt_conn_create_pdu_timeout(_pool, _reserve, _timeout) \
bt_conn_create_pdu_timeout_debug(_pool, _reserve, _timeout, \
__func__, __LINE__)

#define bt_conn_create_pdu(_pool, _reserve) \
bt_conn_create_pdu_timeout_debug(_pool, _reserve, K_FOREVER, \
__func__, __line__)
#else
struct net_buf *bt_conn_create_pdu_timeout(struct net_buf_pool *pool,
size_t reserve, s32_t timeout);

#define bt_conn_create_pdu(_pool, _reserve) \
bt_conn_create_pdu_timeout(_pool, _reserve, K_FOREVER)
#endif

/* Prepare a PDU to be sent over a connection */
#if defined(CONFIG_NET_BUF_LOG)
struct net_buf *bt_conn_create_frag_timeout_debug(size_t reserve, s32_t timeout,
const char *func, int line);

#define bt_conn_create_frag_timeout(_reserve, _timeout) \
bt_conn_create_frag_timeout_debug(_reserve, _timeout, \
__func__, __LINE__)

#define bt_conn_create_frag(_reserve) \
bt_conn_create_frag_timeout_debug(_reserve, K_FOREVER, \
__func__, __LINE__)
#else
struct net_buf *bt_conn_create_frag_timeout(size_t reserve, s32_t timeout);

#define bt_conn_create_frag(_reserve) \
bt_conn_create_frag_timeout(_reserve, K_FOREVER)
#endif

/* Initialize connection management */
int bt_conn_init(void);
Expand Down
Loading