diff --git a/src/hci.c b/src/hci.c index a0e551521..c9266044f 100644 --- a/src/hci.c +++ b/src/hci.c @@ -1504,7 +1504,9 @@ static void event_handler(uint8_t *packet, int size){ break; case HCI_EVENT_HARDWARE_ERROR: - if(hci_stack->control && hci_stack->control->hw_error){ + if (hci_stack->hardware_error_callback){ + (*hci_stack->hardware_error_callback)(); + } else if(hci_stack->control && hci_stack->control->hw_error){ (*hci_stack->control->hw_error)(); } else { // if no special requests, just reboot stack @@ -2915,6 +2917,14 @@ le_command_status_t gap_disconnect(hci_con_handle_t handle){ return BLE_PERIPHERAL_OK; } +/** + * @brief Set callback for Bluetooth Hardware Error + */ +void hci_set_hardware_error_callback(void (*fn)(void)){ + hci_stack->hardware_error_callback = fn; +} + + void hci_disconnect_all(void){ linked_list_iterator_t it; linked_list_iterator_init(&it, &hci_stack->connections); diff --git a/src/hci.h b/src/hci.h index 3617e9460..9ea6541c2 100644 --- a/src/hci.h +++ b/src/hci.h @@ -679,6 +679,9 @@ typedef struct { bd_addr_t custom_bd_addr; uint8_t custom_bd_addr_set; + // hardware error handler + void (*hardware_error_callback)(void); + } hci_stack_t; /** @@ -854,6 +857,12 @@ void hci_ssp_set_auto_accept(int auto_accept); * @brief Get addr type and address used in advertisement packets. */ void hci_le_advertisement_address(uint8_t * addr_type, bd_addr_t addr); + +/** + * @brief Set callback for Bluetooth Hardware Error + */ +void hci_set_hardware_error_callback(void (*fn)(void)); + /* API_END */ #if defined __cplusplus