Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FL-3920] Fix lost BadBLE keystrokes #3993

Merged
merged 15 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/ble_profile/extra_services/hid_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#define TAG "BleHid"

#define BLE_SVC_HID_REPORT_MAP_MAX_LEN (255)
#define BLE_SVC_HID_REPORT_MAX_LEN (255)
#define BLE_SVC_HID_REPORT_REF_LEN (2)
#define BLE_SVC_HID_INFO_LEN (4)
#define BLE_SVC_HID_CONTROL_POINT_LEN (1)
#define BLE_SVC_HID_REPORT_MAX_LEN (255)
#define BLE_SVC_HID_REPORT_REF_LEN (2)
#define BLE_SVC_HID_INFO_LEN (4)
#define BLE_SVC_HID_CONTROL_POINT_LEN (1)

#define BLE_SVC_HID_INPUT_REPORT_COUNT (3)
#define BLE_SVC_HID_OUTPUT_REPORT_COUNT (0)
#define BLE_SVC_HID_INPUT_REPORT_COUNT (3)
#define BLE_SVC_HID_OUTPUT_REPORT_COUNT (0)
#define BLE_SVC_HID_FEATURE_REPORT_COUNT (0)
#define BLE_SVC_HID_REPORT_COUNT \
(BLE_SVC_HID_INPUT_REPORT_COUNT + BLE_SVC_HID_OUTPUT_REPORT_COUNT + \
Expand Down Expand Up @@ -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);
evt_blecore_aci* blecore_evt = (evt_blecore_aci*)event_pckt->data;
// aci_gatt_attribute_modified_event_rp0* attribute_modified;

if(event_pckt->evt == HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE) {
if(blecore_evt->ecode == ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE) {
// Process modification events
Expand Down Expand Up @@ -274,6 +275,7 @@ bool ble_svc_hid_update_input_report(
.data_ptr = data,
.data_len = len,
};

return ble_gatt_characteristic_update(
hid_svc->svc_handle, &hid_svc->input_report_chars[input_report_num], &report_data);
}
Expand Down
28 changes: 23 additions & 5 deletions targets/f7/ble_glue/furi_ble/gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void ble_gatt_characteristic_init(
&char_instance->handle);
if(status) {
FURI_LOG_E(TAG, "Failed to add %s char: %d", char_descriptor->name, status);
furi_assert(false, "Failed to add characteristic");
}

char_instance->descriptor_handle = 0;
Expand All @@ -68,6 +69,7 @@ void ble_gatt_characteristic_init(
&char_instance->descriptor_handle);
if(status) {
FURI_LOG_E(TAG, "Failed to add %s char descriptor: %d", char_descriptor->name, status);
furi_assert(false, "Failed to add characteristic descriptor");
}
if(release_data) {
free((void*)char_data);
Expand All @@ -82,6 +84,7 @@ void ble_gatt_characteristic_delete(
if(status) {
FURI_LOG_E(
TAG, "Failed to delete %s char: %d", char_instance->characteristic->name, status);
furi_assert(false, "Failed to delete characteristic");
}
free((void*)char_instance->characteristic);
}
Expand Down Expand Up @@ -111,14 +114,27 @@ bool ble_gatt_characteristic_update(
release_data = char_descriptor->data.callback.fn(context, &char_data, &char_data_size);
}

tBleStatus result = aci_gatt_update_char_value(
svc_handle, char_instance->handle, 0, char_data_size, char_data);
if(result) {
FURI_LOG_E(TAG, "Failed updating %s characteristic: %d", char_descriptor->name, result);
}
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);
if(result == BLE_STATUS_INSUFFICIENT_RESOURCES) {
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) {
free((void*)char_data);
}

if(result != BLE_STATUS_SUCCESS) {
FURI_LOG_E(TAG, "Failed updating %s characteristic: %d", char_descriptor->name, result);
furi_assert(false, "Failed to update characteristic");
}

return result != BLE_STATUS_SUCCESS;
}

Expand All @@ -132,6 +148,7 @@ bool ble_gatt_service_add(
Service_UUID_Type, Service_UUID, Service_Type, Max_Attribute_Records, Service_Handle);
if(result) {
FURI_LOG_E(TAG, "Failed to add service: %x", result);
furi_assert(false, "Failed to add service");
}

return result == BLE_STATUS_SUCCESS;
Expand All @@ -141,6 +158,7 @@ bool ble_gatt_service_delete(uint16_t svc_handle) {
tBleStatus result = aci_gatt_del_service(svc_handle);
if(result) {
FURI_LOG_E(TAG, "Failed to delete service: %x", result);
furi_assert(false, "Failed to delete service");
}

return result == BLE_STATUS_SUCCESS;
Expand Down
Loading