diff options
author | Szymon Janc <ext.szymon.janc@tieto.com> | 2016-10-07 12:04:33 +0200 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2016-10-16 09:00:57 +0300 |
commit | 2caa5f1442f4dff8135a48cbb07f654bb66c13fb (patch) | |
tree | fabf901a6e2ebe2c3aef8dc5321ea57e3a969b12 /net | |
parent | ba3ab4d2bc35e4546a353a0162e19e184daf889d (diff) |
Bluetooth: Track role change for BR/EDR connections
This make sure conn object is using correct role.
< HCI Command: Create Connection (0x01|0x0005) plen 13
Address: 20:68:9D:60:A1:E4 (Liteon Technology Corporation)
Packet type: 0xcc18
DM1 may be used
DH1 may be used
DM3 may be used
DH3 may be used
DM5 may be used
DH5 may be used
Page scan repetition mode: R2 (0x02)
Page scan mode: Mandatory (0x00)
Clock offset: 0x0000
Role switch: Allow slave (0x01)
> HCI Event: Command Status (0x0f) plen 4
Create Connection (0x01|0x0005) ncmd 1
Status: Success (0x00)
> HCI Event: Role Change (0x12) plen 8
Status: Success (0x00)
Address: 20:68:9D:60:A1:E4 (Liteon Technology Corporation)
Role: Slave (0x01)
> HCI Event: Connect Complete (0x03) plen 11
Status: Success (0x00)
Handle: 11
Address: 20:68:9D:60:A1:E4 (Liteon Technology Corporation)
Link type: ACL (0x01)
Change-Id: I65cd8ba36f0e5317d79d7e4d884ee530e1f8b2a3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/bluetooth/hci_core.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index c38eda7d6..6c57fc787 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1918,6 +1918,32 @@ static void read_remote_ext_features_complete(struct net_buf *buf) bt_conn_unref(conn); } +static void role_change(struct net_buf *buf) +{ + struct bt_hci_evt_role_change *evt = (void *)buf->data; + struct bt_conn *conn; + + BT_DBG("status %u role %u addr %s", evt->status, evt->role, + bt_addr_str(&evt->bdaddr)); + + if (evt->status) { + return; + } + + conn = bt_conn_lookup_addr_br(&evt->bdaddr); + if (!conn) { + BT_ERR("Can't find conn for %s", bt_addr_str(&evt->bdaddr)); + return; + } + + if (evt->role) { + conn->role = BT_CONN_ROLE_SLAVE; + } else { + conn->role = BT_CONN_ROLE_MASTER; + } + + bt_conn_unref(conn); +} #endif /* CONFIG_BLUETOOTH_BREDR */ #if defined(CONFIG_BLUETOOTH_SMP) @@ -2686,6 +2712,9 @@ static void hci_event(struct net_buf *buf) case BT_HCI_EVT_REMOTE_EXT_FEATURES: read_remote_ext_features_complete(buf); break; + case BT_HCI_EVT_ROLE_CHANGE: + role_change(buf); + break; #endif #if defined(CONFIG_BLUETOOTH_CONN) case BT_HCI_EVT_DISCONN_COMPLETE: @@ -3224,6 +3253,7 @@ static int set_event_mask(void) ev->events[0] |= 0x20; /* Authentication Complete */ ev->events[0] |= 0x40; /* Remote Name Request Complete */ ev->events[1] |= 0x04; /* Read Remote Feature Complete */ + ev->events[2] |= 0x02; /* Role Change */ ev->events[2] |= 0x20; /* Pin Code Request */ ev->events[2] |= 0x40; /* Link Key Request */ ev->events[2] |= 0x80; /* Link Key Notif */ |