diff --git a/src/gap.h b/src/gap.h index 09907e963..9ac54dd85 100644 --- a/src/gap.h +++ b/src/gap.h @@ -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 */ /** diff --git a/src/hci.c b/src/hci.c index 932f55d3e..ad7dea58c 100644 --- a/src/hci.c +++ b/src/hci.c @@ -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 diff --git a/src/hci.h b/src/hci.h index 7a250c557..f9df0d819 100644 --- a/src/hci.h +++ b/src/hci.h @@ -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;