gap: Register filter for rejecting classic connections

This commit is contained in:
Milanka Ringwald 2019-09-02 10:12:56 +02:00
parent d7e6933a33
commit 07e010b651
3 changed files with 25 additions and 1 deletions

View File

@ -176,6 +176,13 @@ void gap_set_bondable_mode(int enabled);
*/
int gap_get_bondable_mode(void);
/**
* @brief Register filter for rejecting classic connections. Callback will return 1 accept connection, 0 on reject.
*/
void gap_register_classic_connection_filter(int (*accept_callback)(bd_addr_t addr));
/* Configure Secure Simple Pairing */
/**

View File

@ -2104,6 +2104,14 @@ static void event_handler(uint8_t *packet, int size){
break;
case HCI_EVENT_CONNECTION_REQUEST:
reverse_bd_addr(&packet[2], addr);
if (hci_stack->gap_classic_accept_callback != NULL){
if ((*hci_stack->gap_classic_accept_callback)(addr) == 0){
hci_stack->decline_reason = 0x0d;
bd_addr_copy(hci_stack->decline_addr, addr);
break;
}
}
// TODO: eval COD 8-10
link_type = packet[11];
log_info("Connection_incoming: %s, type %u", bd_addr_to_str(addr), link_type);
@ -5101,6 +5109,11 @@ HCI_STATE hci_get_state(void){
return hci_stack->state;
}
#ifdef ENABLE_CLASSIC
void gap_register_classic_connection_filter(int (*accept_callback)(bd_addr_t addr)){
hci_stack->gap_classic_accept_callback = accept_callback;
}
#endif
/**
* @brief Set callback for Bluetooth Hardware Error

View File

@ -730,6 +730,11 @@ typedef struct {
/* callbacks for events */
btstack_linked_list_t event_handlers;
#ifdef ENABLE_CLASSIC
/* callback for reject classic connection */
int (*gap_classic_accept_callback)(bd_addr_t addr);
#endif
// hardware error callback
void (*hardware_error_callback)(uint8_t error);
@ -910,7 +915,6 @@ typedef struct {
// address and address_type of active create connection command (ACL, SCO, LE)
bd_addr_t outgoing_addr;
bd_addr_type_t outgoing_addr_type;
} hci_stack_t;