diff --git a/net/bluetooth/conn.c b/net/bluetooth/conn.c index 23230a1992c..dfdb25dacf9 100644 --- a/net/bluetooth/conn.c +++ b/net/bluetooth/conn.c @@ -58,6 +58,7 @@ #define CONN_TIMEOUT (3 * sys_clock_ticks_per_sec) static struct bt_conn conns[CONFIG_BLUETOOTH_MAX_CONN]; +static struct bt_conn_cb *callback_list; #if defined(CONFIG_BLUETOOTH_DEBUG_CONN) static const char *state2str(bt_conn_state_t state) @@ -79,6 +80,34 @@ static const char *state2str(bt_conn_state_t state) } #endif +void bt_conn_connected(struct bt_conn *conn) +{ + struct bt_conn_cb *cb; + + for (cb = callback_list; cb; cb = cb->_next) { + if (cb->connected) { + cb->connected(conn); + } + } +} + +static void bt_conn_disconnected(struct bt_conn *conn) +{ + struct bt_conn_cb *cb; + + for (cb = callback_list; cb; cb = cb->_next) { + if (cb->disconnected) { + cb->disconnected(conn); + } + } +} + +void bt_conn_cb_register(struct bt_conn_cb *cb) +{ + cb->_next = callback_list; + callback_list = cb; +} + static void bt_conn_reset_rx_state(struct bt_conn *conn) { if (!conn->rx_len) { @@ -352,6 +381,8 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state) nano_fifo_init(&conn->tx_queue); fiber_start(conn->stack, sizeof(conn->stack), conn_tx_fiber, (int)bt_conn_get(conn), 0, 7, 0); + + bt_l2cap_connected(conn); break; case BT_CONN_DISCONNECTED: /* Send dummy buffer to wake up and stop the tx fiber @@ -359,6 +390,9 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state) */ if (old_state == BT_CONN_CONNECTED || old_state == BT_CONN_DISCONNECT) { + bt_l2cap_disconnected(conn); + bt_conn_disconnected(conn); + nano_fifo_put(&conn->tx_queue, bt_buf_get(BT_DUMMY, 0)); } diff --git a/net/bluetooth/conn_internal.h b/net/bluetooth/conn_internal.h index 1deef9f9870..3e117befcc7 100644 --- a/net/bluetooth/conn_internal.h +++ b/net/bluetooth/conn_internal.h @@ -123,3 +123,6 @@ int bt_conn_le_start_encryption(struct bt_conn *conn, uint64_t rand, int bt_conn_le_conn_update(struct bt_conn *conn, uint16_t min, uint16_t max, uint16_t latency, uint16_t timeout); + +/* Notify higher layers of a new connection */ +void bt_conn_connected(struct bt_conn *conn); diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 57bf4816662..b33fa00527b 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -69,7 +69,6 @@ static nano_thread_id_t rx_prio_fiber_id; struct bt_dev bt_dev; -static struct bt_conn_cb *callback_list; static bt_le_scan_cb_t *scan_dev_found_cb; #if defined(CONFIG_BLUETOOTH_DEBUG) @@ -100,34 +99,6 @@ const char *bt_addr_le_str(const bt_addr_le_t *addr) } #endif /* CONFIG_BLUETOOTH_DEBUG */ -static void bt_connected(struct bt_conn *conn) -{ - struct bt_conn_cb *cb; - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->connected) { - cb->connected(conn); - } - } -} - -static void bt_disconnected(struct bt_conn *conn) -{ - struct bt_conn_cb *cb; - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->disconnected) { - cb->disconnected(conn); - } - } -} - -void bt_conn_cb_register(struct bt_conn_cb *cb) -{ - cb->_next = callback_list; - callback_list = cb; -} - struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len) { struct bt_hci_cmd_hdr *hdr; @@ -732,9 +703,6 @@ static void hci_disconn_complete(struct bt_buf *buf) return; } - bt_l2cap_disconnected(conn); - bt_disconnected(conn); - /* Check stack usage (no-op if not enabled) */ analyze_stacks(conn, &conn); @@ -813,14 +781,12 @@ static void le_conn_complete(struct bt_buf *buf) bt_conn_set_state(conn, BT_CONN_CONNECTED); - bt_l2cap_connected(conn); - if ((evt->role == BT_HCI_ROLE_SLAVE) && !(bt_dev.le_features[0] & BT_HCI_LE_CONN_PARAM_REQ_PROC)) { bt_l2cap_update_conn_param(conn); } - bt_connected(conn); + bt_conn_connected(conn); bt_conn_put(conn); bt_le_scan_update(); }