Bluetooth: Move connection callbacks to the conn.c

Since then bt_conn_connected as well as bt_l2cap_disconnected callback
can be called from bt_conn_set_state directly.
Also connected cb could be called from there, however
eg. introduction of some additional state is required TBD.

Change-Id: Ida6906272e1468ef5b41ba8dba2a936db049d308
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
This commit is contained in:
Mariusz Skamra 2015-08-23 20:47:29 +02:00 committed by Anas Nashif
commit 2b2e67a220
3 changed files with 38 additions and 35 deletions

View file

@ -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));
}

View file

@ -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);

View file

@ -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();
}