Bluetooth: Introduce BT_CONN_CONNECT_SCAN state

This state will be used for connection establishment during passive scan.
This additional state is necessary, because only one connection can be
in BT_CONN_CONNECT state (LE Create Connection has been sent).
It's because the LE Create Connection Cancel looks for connection in this
state (we cannot look by address, if some controllers respond with
LE Create Connection with address set to 00:00:00:00:00:00).

If connection is BT_CONN_CONNECT_SCAN state it means that we wait for
an advertisement from remote to send LE Create Connection and then we
can change the bt_conn state to BT_CONN_CONNECT.

Change-Id: I48b0352fe08e438f7bfbb1dd12de3d1719f994d8
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
This commit is contained in:
Mariusz Skamra 2015-07-02 11:16:55 +02:00 committed by Anas Nashif
commit 7ec1617b9f
3 changed files with 11 additions and 0 deletions

View file

@ -62,6 +62,8 @@ static const char *state2str(bt_conn_state_t state)
switch (state) {
case BT_CONN_DISCONNECTED:
return "disconnected";
case BT_CONN_CONNECT_SCAN:
return "connect-scan";
case BT_CONN_CONNECT:
return "connect";
case BT_CONN_CONNECTED:
@ -327,6 +329,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
bt_conn_put(conn);
break;
case BT_CONN_CONNECT_SCAN:
case BT_CONN_CONNECT:
case BT_CONN_DISCONNECT:

View file

@ -37,6 +37,7 @@
typedef enum {
BT_CONN_DISCONNECTED,
BT_CONN_CONNECT_SCAN,
BT_CONN_CONNECT,
BT_CONN_CONNECTED,
BT_CONN_DISCONNECT,

View file

@ -1482,6 +1482,7 @@ struct bt_conn *bt_connect_le(const bt_addr_le_t *peer)
conn = bt_conn_lookup_addr_le(peer);
if (conn) {
switch (conn->state) {
case BT_CONN_CONNECT_SCAN:
case BT_CONN_CONNECT:
case BT_CONN_CONNECTED:
return conn;
@ -1548,6 +1549,12 @@ static int bt_hci_disconnect(struct bt_conn *conn, uint8_t reason)
int bt_disconnect(struct bt_conn *conn, uint8_t reason)
{
switch (conn->state) {
case BT_CONN_CONNECT_SCAN:
/* TODO
* 1. set bt_conn state to BT_CONN_DISCONNECTED
* 2. stop passive scanning if there is no more conns
* in BT_CONN_CONNECT_SCAN state
*/
case BT_CONN_CONNECT:
return bt_hci_connect_le_cancel(conn);
case BT_CONN_CONNECTED: