Bluetooth: Refactor existing connection states

Applies new bt_conn_set_state() internal API that now participate in
tracking connections. It concerns only connected and disconnected
events from controller.
Remove bt_conn_del() internal API.

Change-Id: Ic8da46785a7b5e19cae2186047e84e1a5a45a78a
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
Arkadiusz Lichwa 2015-06-19 18:56:13 +02:00 committed by Anas Nashif
commit 83dab3854d
3 changed files with 27 additions and 29 deletions

View file

@ -263,15 +263,10 @@ struct bt_conn *bt_conn_add(struct bt_dev *dev, uint16_t handle, uint8_t role)
memset(conn, 0, sizeof(*conn)); memset(conn, 0, sizeof(*conn));
conn->ref = 1; conn->ref = 1;
bt_conn_set_state(conn, BT_CONN_CONNECTED);
conn->handle = handle; conn->handle = handle;
conn->dev = dev; conn->dev = dev;
conn->role = role; conn->role = role;
bt_conn_set_state(conn, BT_CONN_CONNECTED);
nano_fifo_init(&conn->tx_queue);
fiber_start(conn->tx_stack, sizeof(conn->tx_stack), conn_tx_fiber,
(int)bt_conn_get(conn), 0, 7, 0);
if (role == BT_HCI_ROLE_SLAVE) { if (role == BT_HCI_ROLE_SLAVE) {
bt_l2cap_update_conn_param(conn); bt_l2cap_update_conn_param(conn);
@ -280,25 +275,9 @@ struct bt_conn *bt_conn_add(struct bt_dev *dev, uint16_t handle, uint8_t role)
return conn; return conn;
} }
void bt_conn_del(struct bt_conn *conn)
{
BT_DBG("handle %u\n", conn->handle);
if (conn->state != BT_CONN_CONNECTED) {
return;
}
bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
/* Send dummy buffer to wake up and kill the tx fiber */
nano_fifo_put(&conn->tx_queue, bt_buf_get(BT_DUMMY, 0));
bt_conn_put(conn);
}
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state) void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
{ {
BT_DBG("%u -> %u", conn->state, state); BT_DBG("%u -> %u\n", conn->state, state);
if (conn->state == state) { if (conn->state == state) {
BT_WARN("no transition\n"); BT_WARN("no transition\n");
@ -307,7 +286,29 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
conn->state = state; conn->state = state;
/* TODO: Validate states and make certain actions based on set state */ switch (conn->state){
case BT_CONN_CONNECTED:
nano_fifo_init(&conn->tx_queue);
fiber_start(conn->tx_stack, sizeof(conn->tx_stack),
conn_tx_fiber, (int)bt_conn_get(conn), 0, 7, 0);
break;
case BT_CONN_DISCONNECTED:
/* Send dummy buffer to wake up and kill the tx fiber */
nano_fifo_put(&conn->tx_queue, bt_buf_get(BT_DUMMY, 0));
bt_conn_put(conn);
break;
case BT_CONN_CONNECT:
case BT_CONN_DISCONNECT:
break;
default:
BT_WARN("no valid (%u) state was set\n", state);
break;
}
} }
struct bt_conn *bt_conn_lookup_handle(uint16_t handle) struct bt_conn *bt_conn_lookup_handle(uint16_t handle)

View file

@ -88,11 +88,8 @@ void bt_conn_send(struct bt_conn *conn, struct bt_buf *buf);
/* Add a new connection */ /* Add a new connection */
struct bt_conn *bt_conn_add(struct bt_dev *dev, uint16_t handle, uint8_t role); struct bt_conn *bt_conn_add(struct bt_dev *dev, uint16_t handle, uint8_t role);
/* Delete an existing connection */
void bt_conn_del(struct bt_conn *conn);
/* Look up an existing connection */ /* Look up an existing connection */
struct bt_conn *bt_conn_lookup_handle(uint16_t handle); struct bt_conn *bt_conn_lookup_handle(uint16_t handle);
/* Set connection object in certain state */ /* Set connection object in certain state and perform action related to state */
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state); void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state);

View file

@ -363,7 +363,7 @@ static void hci_disconn_complete(struct bt_buf *buf)
/* Check stack usage (no-op if not enabled) */ /* Check stack usage (no-op if not enabled) */
analyze_stacks(conn, &conn); analyze_stacks(conn, &conn);
bt_conn_del(conn); bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
bt_conn_put(conn); bt_conn_put(conn);
if (dev.adv_enable) { if (dev.adv_enable) {