Bluetooth: Introduce set connection object state
Typedef so far anonymous enum values allowable connection states to be set. Adds interface to allow track connection state. Update struct bt_conn definition using introduced enum's typedef. Change-Id: Id91f5a814e4801438f1dcef36fff058faab7beda Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
parent
d9c0bc65ee
commit
86001d81f4
2 changed files with 22 additions and 5 deletions
|
@ -263,7 +263,7 @@ 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;
|
||||||
conn->state = BT_CONN_CONNECTED;
|
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;
|
||||||
|
@ -288,7 +288,7 @@ void bt_conn_del(struct bt_conn *conn)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->state = BT_CONN_DISCONNECTED;
|
bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
|
||||||
|
|
||||||
/* Send dummy buffer to wake up and kill the tx fiber */
|
/* Send dummy buffer to wake up and kill the tx fiber */
|
||||||
nano_fifo_put(&conn->tx_queue, bt_buf_get(BT_DUMMY, 0));
|
nano_fifo_put(&conn->tx_queue, bt_buf_get(BT_DUMMY, 0));
|
||||||
|
@ -296,6 +296,20 @@ void bt_conn_del(struct bt_conn *conn)
|
||||||
bt_conn_put(conn);
|
bt_conn_put(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
|
||||||
|
{
|
||||||
|
BT_DBG("%u -> %u", conn->state, state);
|
||||||
|
|
||||||
|
if (conn->state == state) {
|
||||||
|
BT_WARN("no transition\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
conn->state = state;
|
||||||
|
|
||||||
|
/* TODO: Validate states and make certain actions based on set state */
|
||||||
|
}
|
||||||
|
|
||||||
struct bt_conn *bt_conn_lookup_handle(uint16_t handle)
|
struct bt_conn *bt_conn_lookup_handle(uint16_t handle)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -34,10 +34,10 @@
|
||||||
|
|
||||||
#include <bluetooth/conn.h>
|
#include <bluetooth/conn.h>
|
||||||
|
|
||||||
enum {
|
typedef enum {
|
||||||
BT_CONN_DISCONNECTED,
|
BT_CONN_DISCONNECTED,
|
||||||
BT_CONN_CONNECTED,
|
BT_CONN_CONNECTED,
|
||||||
};
|
} bt_conn_state_t;
|
||||||
|
|
||||||
/* L2CAP signaling channel specific context */
|
/* L2CAP signaling channel specific context */
|
||||||
struct bt_conn_l2cap {
|
struct bt_conn_l2cap {
|
||||||
|
@ -71,7 +71,7 @@ struct bt_conn {
|
||||||
|
|
||||||
uint8_t ref;
|
uint8_t ref;
|
||||||
|
|
||||||
uint8_t state;
|
bt_conn_state_t state;
|
||||||
|
|
||||||
/* TX fiber stack */
|
/* TX fiber stack */
|
||||||
BT_STACK(tx_stack, 256);
|
BT_STACK(tx_stack, 256);
|
||||||
|
@ -91,3 +91,6 @@ 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 */
|
||||||
|
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue