mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-12 04:41:26 +04:00
[FL-3920] Fix lost BadBLE keystrokes (#3993)
* WIP: fix lost BadBLE keystrokes * Switch to semaphores for synchronization * Move checking to the gap level * Remove leftovers from hid_service * Remove more leftovers from hid_service * De-allocate the semaphore after use * Change the timeout to account for unforeseen situation * Update F18 API * Fix naming and unbump api version * Move away from semaphores * Remove the left over include * Ble: cleanup error handling in ble_gatt_characteristic_update * Fix PVS warning Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -157,6 +157,7 @@ static BleEventAckStatus ble_svc_hid_event_handler(void* event, void* context) {
|
|||||||
hci_event_pckt* event_pckt = (hci_event_pckt*)(((hci_uart_pckt*)event)->data);
|
hci_event_pckt* event_pckt = (hci_event_pckt*)(((hci_uart_pckt*)event)->data);
|
||||||
evt_blecore_aci* blecore_evt = (evt_blecore_aci*)event_pckt->data;
|
evt_blecore_aci* blecore_evt = (evt_blecore_aci*)event_pckt->data;
|
||||||
// aci_gatt_attribute_modified_event_rp0* attribute_modified;
|
// aci_gatt_attribute_modified_event_rp0* attribute_modified;
|
||||||
|
|
||||||
if(event_pckt->evt == HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE) {
|
if(event_pckt->evt == HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE) {
|
||||||
if(blecore_evt->ecode == ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE) {
|
if(blecore_evt->ecode == ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE) {
|
||||||
// Process modification events
|
// Process modification events
|
||||||
@@ -274,6 +275,7 @@ bool ble_svc_hid_update_input_report(
|
|||||||
.data_ptr = data,
|
.data_ptr = data,
|
||||||
.data_len = len,
|
.data_len = len,
|
||||||
};
|
};
|
||||||
|
|
||||||
return ble_gatt_characteristic_update(
|
return ble_gatt_characteristic_update(
|
||||||
hid_svc->svc_handle, &hid_svc->input_report_chars[input_report_num], &report_data);
|
hid_svc->svc_handle, &hid_svc->input_report_chars[input_report_num], &report_data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ static void mf_plus_poller_set_callback(
|
|||||||
|
|
||||||
static NfcCommand mf_plus_poller_run(NfcGenericEvent event, void* context) {
|
static NfcCommand mf_plus_poller_run(NfcGenericEvent event, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
furi_assert(event.protocol = NfcProtocolIso14443_4a);
|
furi_assert(event.protocol == NfcProtocolIso14443_4a);
|
||||||
furi_assert(event.event_data);
|
furi_assert(event.event_data);
|
||||||
|
|
||||||
MfPlusPoller* instance = context;
|
MfPlusPoller* instance = context;
|
||||||
@@ -178,7 +178,7 @@ void mf_plus_poller_free(MfPlusPoller* instance) {
|
|||||||
|
|
||||||
static bool mf_plus_poller_detect(NfcGenericEvent event, void* context) {
|
static bool mf_plus_poller_detect(NfcGenericEvent event, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
furi_assert(event.protocol = NfcProtocolIso14443_4a);
|
furi_assert(event.protocol == NfcProtocolIso14443_4a);
|
||||||
furi_assert(event.event_data);
|
furi_assert(event.event_data);
|
||||||
|
|
||||||
MfPlusPoller* instance = context;
|
MfPlusPoller* instance = context;
|
||||||
|
|||||||
@@ -314,8 +314,8 @@ SubGhzProtocolStatus
|
|||||||
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
||||||
|
|
||||||
if(!subghz_protocol_encoder_bin_raw_get_upload(instance)) {
|
if(!subghz_protocol_encoder_bin_raw_get_upload(instance)) {
|
||||||
break;
|
|
||||||
res = SubGhzProtocolStatusErrorEncoderGetUpload;
|
res = SubGhzProtocolStatusErrorEncoderGetUpload;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
instance->encoder.is_running = true;
|
instance->encoder.is_running = true;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,12 @@
|
|||||||
|
|
||||||
#define GATT_MIN_READ_KEY_SIZE (10)
|
#define GATT_MIN_READ_KEY_SIZE (10)
|
||||||
|
|
||||||
|
#ifdef BLE_GATT_STRICT
|
||||||
|
#define ble_gatt_strict_crash(message) furi_crash(message)
|
||||||
|
#else
|
||||||
|
#define ble_gatt_strict_crash(message)
|
||||||
|
#endif
|
||||||
|
|
||||||
void ble_gatt_characteristic_init(
|
void ble_gatt_characteristic_init(
|
||||||
uint16_t svc_handle,
|
uint16_t svc_handle,
|
||||||
const BleGattCharacteristicParams* char_descriptor,
|
const BleGattCharacteristicParams* char_descriptor,
|
||||||
@@ -42,6 +48,7 @@ void ble_gatt_characteristic_init(
|
|||||||
&char_instance->handle);
|
&char_instance->handle);
|
||||||
if(status) {
|
if(status) {
|
||||||
FURI_LOG_E(TAG, "Failed to add %s char: %d", char_descriptor->name, status);
|
FURI_LOG_E(TAG, "Failed to add %s char: %d", char_descriptor->name, status);
|
||||||
|
ble_gatt_strict_crash("Failed to add characteristic");
|
||||||
}
|
}
|
||||||
|
|
||||||
char_instance->descriptor_handle = 0;
|
char_instance->descriptor_handle = 0;
|
||||||
@@ -68,6 +75,7 @@ void ble_gatt_characteristic_init(
|
|||||||
&char_instance->descriptor_handle);
|
&char_instance->descriptor_handle);
|
||||||
if(status) {
|
if(status) {
|
||||||
FURI_LOG_E(TAG, "Failed to add %s char descriptor: %d", char_descriptor->name, status);
|
FURI_LOG_E(TAG, "Failed to add %s char descriptor: %d", char_descriptor->name, status);
|
||||||
|
ble_gatt_strict_crash("Failed to add characteristic descriptor");
|
||||||
}
|
}
|
||||||
if(release_data) {
|
if(release_data) {
|
||||||
free((void*)char_data);
|
free((void*)char_data);
|
||||||
@@ -82,6 +90,7 @@ void ble_gatt_characteristic_delete(
|
|||||||
if(status) {
|
if(status) {
|
||||||
FURI_LOG_E(
|
FURI_LOG_E(
|
||||||
TAG, "Failed to delete %s char: %d", char_instance->characteristic->name, status);
|
TAG, "Failed to delete %s char: %d", char_instance->characteristic->name, status);
|
||||||
|
ble_gatt_strict_crash("Failed to delete characteristic");
|
||||||
}
|
}
|
||||||
free((void*)char_instance->characteristic);
|
free((void*)char_instance->characteristic);
|
||||||
}
|
}
|
||||||
@@ -111,14 +120,27 @@ bool ble_gatt_characteristic_update(
|
|||||||
release_data = char_descriptor->data.callback.fn(context, &char_data, &char_data_size);
|
release_data = char_descriptor->data.callback.fn(context, &char_data, &char_data_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
tBleStatus result = aci_gatt_update_char_value(
|
tBleStatus result;
|
||||||
|
size_t retries_left = 1000;
|
||||||
|
do {
|
||||||
|
retries_left--;
|
||||||
|
result = aci_gatt_update_char_value(
|
||||||
svc_handle, char_instance->handle, 0, char_data_size, char_data);
|
svc_handle, char_instance->handle, 0, char_data_size, char_data);
|
||||||
if(result) {
|
if(result == BLE_STATUS_INSUFFICIENT_RESOURCES) {
|
||||||
FURI_LOG_E(TAG, "Failed updating %s characteristic: %d", char_descriptor->name, result);
|
FURI_LOG_W(TAG, "Insufficient resources for %s characteristic", char_descriptor->name);
|
||||||
|
furi_delay_ms(1);
|
||||||
}
|
}
|
||||||
|
} while(result == BLE_STATUS_INSUFFICIENT_RESOURCES && retries_left);
|
||||||
|
|
||||||
if(release_data) {
|
if(release_data) {
|
||||||
free((void*)char_data);
|
free((void*)char_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(result != BLE_STATUS_SUCCESS) {
|
||||||
|
FURI_LOG_E(TAG, "Failed updating %s characteristic: %d", char_descriptor->name, result);
|
||||||
|
ble_gatt_strict_crash("Failed to update characteristic");
|
||||||
|
}
|
||||||
|
|
||||||
return result != BLE_STATUS_SUCCESS;
|
return result != BLE_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +154,7 @@ bool ble_gatt_service_add(
|
|||||||
Service_UUID_Type, Service_UUID, Service_Type, Max_Attribute_Records, Service_Handle);
|
Service_UUID_Type, Service_UUID, Service_Type, Max_Attribute_Records, Service_Handle);
|
||||||
if(result) {
|
if(result) {
|
||||||
FURI_LOG_E(TAG, "Failed to add service: %x", result);
|
FURI_LOG_E(TAG, "Failed to add service: %x", result);
|
||||||
|
ble_gatt_strict_crash("Failed to add service");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result == BLE_STATUS_SUCCESS;
|
return result == BLE_STATUS_SUCCESS;
|
||||||
@@ -141,6 +164,7 @@ bool ble_gatt_service_delete(uint16_t svc_handle) {
|
|||||||
tBleStatus result = aci_gatt_del_service(svc_handle);
|
tBleStatus result = aci_gatt_del_service(svc_handle);
|
||||||
if(result) {
|
if(result) {
|
||||||
FURI_LOG_E(TAG, "Failed to delete service: %x", result);
|
FURI_LOG_E(TAG, "Failed to delete service: %x", result);
|
||||||
|
ble_gatt_strict_crash("Failed to delete service");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result == BLE_STATUS_SUCCESS;
|
return result == BLE_STATUS_SUCCESS;
|
||||||
|
|||||||
Reference in New Issue
Block a user