mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-05 09:40:00 +00:00
track HCI Connection roles for BR/EDR and LE
This commit is contained in:
parent
e21192ab89
commit
5cf766e823
13
src/hci.c
13
src/hci.c
@ -1313,6 +1313,7 @@ static void event_handler(uint8_t *packet, int size){
|
|||||||
BD_ADDR_COPY(hci_stack->decline_addr, addr);
|
BD_ADDR_COPY(hci_stack->decline_addr, addr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
conn->role = HCI_ROLE_SLAVE;
|
||||||
conn->state = RECEIVED_CONNECTION_REQUEST;
|
conn->state = RECEIVED_CONNECTION_REQUEST;
|
||||||
hci_run();
|
hci_run();
|
||||||
break;
|
break;
|
||||||
@ -1550,6 +1551,14 @@ static void event_handler(uint8_t *packet, int size){
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case HCI_EVENT_ROLE_CHANGE:
|
||||||
|
if (packet[2]) break; // status != 0
|
||||||
|
handle = READ_BT_16(packet, 3);
|
||||||
|
conn = hci_connection_for_handle(handle);
|
||||||
|
if (!conn) break; // no conn
|
||||||
|
conn->role = packet[9];
|
||||||
|
break;
|
||||||
|
|
||||||
case DAEMON_EVENT_HCI_PACKET_SENT:
|
case DAEMON_EVENT_HCI_PACKET_SENT:
|
||||||
// release packet buffer only for asynchronous transport and if there are not further fragements
|
// release packet buffer only for asynchronous transport and if there are not further fragements
|
||||||
if (hci_transport_synchronous()) {
|
if (hci_transport_synchronous()) {
|
||||||
@ -1590,7 +1599,7 @@ static void event_handler(uint8_t *packet, int size){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// on success, both hosts receive connection complete event
|
// on success, both hosts receive connection complete event
|
||||||
if (packet[6] == 0){
|
if (packet[6] == HCI_ROLE_MASTER){
|
||||||
// if we're master, it was an outgoing connection and we're done with it
|
// if we're master, it was an outgoing connection and we're done with it
|
||||||
hci_stack->le_connecting_state = LE_CONNECTING_IDLE;
|
hci_stack->le_connecting_state = LE_CONNECTING_IDLE;
|
||||||
} else {
|
} else {
|
||||||
@ -1607,6 +1616,7 @@ static void event_handler(uint8_t *packet, int size){
|
|||||||
}
|
}
|
||||||
|
|
||||||
conn->state = OPEN;
|
conn->state = OPEN;
|
||||||
|
conn->role = packet[6];
|
||||||
conn->con_handle = READ_BT_16(packet, 4);
|
conn->con_handle = READ_BT_16(packet, 4);
|
||||||
|
|
||||||
// TODO: store - role, peer address type, conn_interval, conn_latency, supervision timeout, master clock
|
// TODO: store - role, peer address type, conn_interval, conn_latency, supervision timeout, master clock
|
||||||
@ -2286,6 +2296,7 @@ void hci_run(void){
|
|||||||
case RECEIVED_CONNECTION_REQUEST:
|
case RECEIVED_CONNECTION_REQUEST:
|
||||||
log_info("sending hci_accept_connection_request");
|
log_info("sending hci_accept_connection_request");
|
||||||
connection->state = ACCEPTED_CONNECTION_REQUEST;
|
connection->state = ACCEPTED_CONNECTION_REQUEST;
|
||||||
|
connection->role = HCI_ROLE_SLAVE;
|
||||||
if (connection->address_type == BD_ADDR_TYPE_CLASSIC){
|
if (connection->address_type == BD_ADDR_TYPE_CLASSIC){
|
||||||
hci_send_cmd(&hci_accept_connection_request, connection->address, 1);
|
hci_send_cmd(&hci_accept_connection_request, connection->address, 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -62,6 +62,10 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// HCI roles
|
||||||
|
#define HCI_ROLE_MASTER 0
|
||||||
|
#define HCI_ROLE_SLAVE 1
|
||||||
|
|
||||||
// packet header sizes
|
// packet header sizes
|
||||||
#define HCI_CMD_HEADER_SIZE 3
|
#define HCI_CMD_HEADER_SIZE 3
|
||||||
#define HCI_ACL_HEADER_SIZE 4
|
#define HCI_ACL_HEADER_SIZE 4
|
||||||
@ -493,6 +497,9 @@ typedef struct {
|
|||||||
// le public, le random, classic
|
// le public, le random, classic
|
||||||
bd_addr_type_t address_type;
|
bd_addr_type_t address_type;
|
||||||
|
|
||||||
|
// role: 0 - master, 1 - slave
|
||||||
|
uint8_t role;
|
||||||
|
|
||||||
// connection state
|
// connection state
|
||||||
CONNECTION_STATE state;
|
CONNECTION_STATE state;
|
||||||
|
|
||||||
|
@ -197,7 +197,15 @@ extern "C" {
|
|||||||
#define HCI_EVENT_HARDWARE_ERROR 0x10
|
#define HCI_EVENT_HARDWARE_ERROR 0x10
|
||||||
|
|
||||||
#define HCI_EVENT_FLUSH_OCCURED 0x11
|
#define HCI_EVENT_FLUSH_OCCURED 0x11
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @format 1B1
|
||||||
|
* @param status
|
||||||
|
* @param bd_addr
|
||||||
|
* @param role
|
||||||
|
*/
|
||||||
#define HCI_EVENT_ROLE_CHANGE 0x12
|
#define HCI_EVENT_ROLE_CHANGE 0x12
|
||||||
|
|
||||||
#define HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS 0x13
|
#define HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS 0x13
|
||||||
#define HCI_EVENT_MODE_CHANGE_EVENT 0x14
|
#define HCI_EVENT_MODE_CHANGE_EVENT 0x14
|
||||||
#define HCI_EVENT_RETURN_LINK_KEYS 0x15
|
#define HCI_EVENT_RETURN_LINK_KEYS 0x15
|
||||||
|
Loading…
x
Reference in New Issue
Block a user