Commit 1af31671 authored by Luiz Augusto von Dentz's avatar Luiz Augusto von Dentz Committed by Carles Cufi
Browse files

Bluetooth: conn: Add bt_conn_create_pdu_timeout



This adds bt_conn_create_pdu_timeout function which can be used
to provide a timeout when allocating a buffer.

Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
parent dbc21424
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -2312,7 +2312,8 @@ int bt_conn_le_conn_update(struct bt_conn *conn,
	return bt_hci_cmd_send(BT_HCI_OP_LE_CONN_UPDATE, buf);
}

struct net_buf *bt_conn_create_pdu(struct net_buf_pool *pool, size_t reserve)
struct net_buf *bt_conn_create_pdu_timeout(struct net_buf_pool *pool,
					   size_t reserve, s32_t timeout)
{
	struct net_buf *buf;

@@ -2327,24 +2328,29 @@ struct net_buf *bt_conn_create_pdu(struct net_buf_pool *pool, size_t reserve)
	}

	if (IS_ENABLED(CONFIG_BT_DEBUG_CONN) ||
	    k_current_get() == &k_sys_work_q.thread) {
	    (k_current_get() == &k_sys_work_q.thread && timeout == K_FOREVER)) {
		buf = net_buf_alloc(pool, K_NO_WAIT);
		if (!buf) {
			BT_WARN("Unable to allocate buffer");
			BT_WARN("Unable to allocate buffer with K_NO_WAIT");
			/* Cannot block with K_FOREVER on k_sys_work_q as that
			 * can cause a deadlock when trying to dispatch TX
			 * notification.
			 */
			if (k_current_get() == &k_sys_work_q.thread) {
				BT_WARN("Unable to allocate buffer: timeout %d",
					 timeout);
				return NULL;
			}
			buf = net_buf_alloc(pool, K_FOREVER);
			buf = net_buf_alloc(pool, timeout);
		}
	} else {
		buf = net_buf_alloc(pool, K_FOREVER);
		buf = net_buf_alloc(pool, timeout);
	}

	__ASSERT_NO_MSG(buf);
	if (!buf) {
		BT_WARN("Unable to allocate buffer: timeout %d", timeout);
		return NULL;
	}

	reserve += sizeof(struct bt_hci_acl_hdr) + CONFIG_BT_HCI_RESERVE;
	net_buf_reserve(buf, reserve);
+5 −1
Original line number Diff line number Diff line
@@ -223,7 +223,11 @@ 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 */
struct net_buf *bt_conn_create_pdu(struct net_buf_pool *pool, size_t reserve);
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)

/* Initialize connection management */
int bt_conn_init(void);
+5 −2
Original line number Diff line number Diff line
@@ -467,9 +467,12 @@ void bt_l2cap_encrypt_change(struct bt_conn *conn, u8_t hci_status)
	}
}

struct net_buf *bt_l2cap_create_pdu(struct net_buf_pool *pool, size_t reserve)
struct net_buf *bt_l2cap_create_pdu_timeout(struct net_buf_pool *pool,
					    size_t reserve, s32_t timeout)
{
	return bt_conn_create_pdu(pool, sizeof(struct bt_l2cap_hdr) + reserve);
	return bt_conn_create_pdu_timeout(pool,
					  sizeof(struct bt_l2cap_hdr) + reserve,
					  timeout);
}

void bt_l2cap_send_cb(struct bt_conn *conn, u16_t cid, struct net_buf *buf,
+5 −1
Original line number Diff line number Diff line
@@ -260,7 +260,11 @@ void bt_l2cap_chan_set_state(struct bt_l2cap_chan *chan,
void bt_l2cap_encrypt_change(struct bt_conn *conn, u8_t hci_status);

/* Prepare an L2CAP PDU to be sent over a connection */
struct net_buf *bt_l2cap_create_pdu(struct net_buf_pool *pool, size_t reserve);
struct net_buf *bt_l2cap_create_pdu_timeout(struct net_buf_pool *pool,
					    size_t reserve, s32_t timeout);

#define bt_l2cap_create_pdu(_pool, _reserve) \
	bt_l2cap_create_pdu_timeout(_pool, _reserve, K_FOREVER)

/* Prepare a L2CAP Response PDU to be sent over a connection */
struct net_buf *bt_l2cap_create_rsp(struct net_buf *buf, size_t reserve);