mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 21:35:16 +00:00
Adds functionality for setting the master-slave role policy. Fixes bug when handling HCI_EVENT_ROLE_CHANGE.
This commit is contained in:
parent
658d4117be
commit
c4c88f1bc9
22
src/hci.c
22
src/hci.c
@ -2133,9 +2133,10 @@ static void event_handler(uint8_t *packet, int size){
|
||||
#ifdef ENABLE_CLASSIC
|
||||
case HCI_EVENT_ROLE_CHANGE:
|
||||
if (packet[2]) break; // status != 0
|
||||
handle = little_endian_read_16(packet, 3);
|
||||
conn = hci_connection_for_handle(handle);
|
||||
if (!conn) break; // no conn
|
||||
reverse_bd_addr(&packet[3], addr);
|
||||
addr_type = BD_ADDR_TYPE_CLASSIC;
|
||||
conn = hci_connection_for_bd_addr_and_type(addr, addr_type);
|
||||
if (!conn) break;
|
||||
conn->role = packet[9];
|
||||
break;
|
||||
#endif
|
||||
@ -2429,6 +2430,9 @@ void hci_init(const hci_transport_t *transport, const void *config){
|
||||
#ifdef ENABLE_CLASSIC
|
||||
// classic name
|
||||
hci_stack->local_name = default_classic_name;
|
||||
|
||||
// Master slave policy
|
||||
hci_stack->master_slave_policy = 1;
|
||||
#endif
|
||||
|
||||
// Secure Simple Pairing default: enable, no I/O capabilities, general bonding, mitm not required, auto accept
|
||||
@ -3144,7 +3148,7 @@ static void hci_run(void){
|
||||
connection->state = ACCEPTED_CONNECTION_REQUEST;
|
||||
connection->role = HCI_ROLE_SLAVE;
|
||||
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, hci_stack->master_slave_policy);
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
@ -4496,8 +4500,16 @@ int hci_get_sco_packet_length(void){
|
||||
if (hci_stack->sco_voice_setting & 0x0020) return 51;
|
||||
return 27;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Sets the master/slave policy
|
||||
* @param policy (0: attempt to become master, 1: let connecting device decide)
|
||||
*/
|
||||
void hci_set_master_slave_policy(uint8_t policy){
|
||||
hci_stack->master_slave_policy = policy;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
HCI_STATE hci_get_state(void){
|
||||
return hci_stack->state;
|
||||
|
@ -848,6 +848,10 @@ typedef struct {
|
||||
bd_addr_t custom_bd_addr;
|
||||
uint8_t custom_bd_addr_set;
|
||||
|
||||
#ifdef ENABLE_CLASSIC
|
||||
uint8_t master_slave_policy;
|
||||
#endif
|
||||
|
||||
} hci_stack_t;
|
||||
|
||||
|
||||
@ -998,6 +1002,11 @@ uint8_t* hci_get_outgoing_packet_buffer(void);
|
||||
*/
|
||||
void hci_release_packet_buffer(void);
|
||||
|
||||
/**
|
||||
* @brief Sets the master/slave policy
|
||||
* @param policy (0: attempt to become master, 1: let connecting device decide)
|
||||
*/
|
||||
void hci_set_master_slave_policy(uint8_t policy);
|
||||
|
||||
/* API_END */
|
||||
|
||||
|
@ -547,6 +547,13 @@ const hci_cmd_t hci_write_link_policy_settings = {
|
||||
OPCODE(OGF_LINK_POLICY, 0x0d), "H2"
|
||||
};
|
||||
|
||||
/**
|
||||
* @param policy
|
||||
*/
|
||||
const hci_cmd_t hci_write_default_link_policy_setup = {
|
||||
OPCODE(OGF_LINK_POLICY, 0x0F), "2"
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Controller & Baseband Commands
|
||||
|
@ -148,6 +148,7 @@ extern const hci_cmd_t hci_write_extended_inquiry_response;
|
||||
extern const hci_cmd_t hci_write_inquiry_mode;
|
||||
extern const hci_cmd_t hci_write_le_host_supported;
|
||||
extern const hci_cmd_t hci_write_link_policy_settings;
|
||||
extern const hci_cmd_t hci_write_default_link_policy_setup;
|
||||
extern const hci_cmd_t hci_write_link_supervision_timeout;
|
||||
extern const hci_cmd_t hci_write_local_name;
|
||||
extern const hci_cmd_t hci_write_loopback_mode;
|
||||
|
Loading…
x
Reference in New Issue
Block a user