From d38dfb7f7d933e1fd827c77cee90f709ed1ff351 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 22 Jun 2023 11:46:16 +0200 Subject: [PATCH] gatt-service/hids_device: return status for all send input functions --- src/ble/gatt-service/hids_device.c | 35 +++++++++++++----------------- src/ble/gatt-service/hids_device.h | 16 +++++++++++--- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/ble/gatt-service/hids_device.c b/src/ble/gatt-service/hids_device.c index 178b4281d..8cc4e8b97 100644 --- a/src/ble/gatt-service/hids_device.c +++ b/src/ble/gatt-service/hids_device.c @@ -448,7 +448,7 @@ uint8_t hids_device_send_input_report_for_id(hci_con_handle_t con_handle, uint16 return att_server_notify(con_handle, report_storage->value_handle, report, report_len); } -static uint8_t hids_device_send_report_with_type(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len, hid_report_type_t report_type){ +uint8_t hids_device_send_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){ hids_device_t * device = hids_device_get_instance_for_con_handle(con_handle); if (!device){ log_error("no instance for handle 0x%02x", con_handle); @@ -459,38 +459,33 @@ static uint8_t hids_device_send_report_with_type(hci_con_handle_t con_handle, co uint8_t total_reports = device->hid_input_reports_num + device->hid_output_reports_num + device->hid_feature_reports_num; for (pos = 0 ; pos < total_reports ; pos++){ hids_device_report_t * report_storage = &device->hid_reports[pos]; - - if (report_storage->type == report_type){ + if (report_storage->type == HID_REPORT_TYPE_INPUT){ return att_server_notify(con_handle, report_storage->value_handle, report, report_len); } } return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE; } -void hids_device_send_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){ - (void)hids_device_send_report_with_type(con_handle, report, report_len, HID_REPORT_TYPE_INPUT); +/** + * @brief Send HID Boot Mouse Input Report + */ +uint8_t hids_device_send_boot_mouse_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){ + hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle); + if (!instance){ + log_error("no instance for handle 0x%02x", con_handle); + return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; + } + return att_server_notify(con_handle, instance->hid_boot_mouse_input_value_handle, report, report_len); } /** * @brief Send HID Boot Mouse Input Report */ -void hids_device_send_boot_mouse_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){ +uint8_t hids_device_send_boot_keyboard_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){ hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle); if (!instance){ log_error("no instance for handle 0x%02x", con_handle); - return; + return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; } - att_server_notify(con_handle, instance->hid_boot_mouse_input_value_handle, report, report_len); -} - -/** - * @brief Send HID Boot Mouse Input Report - */ -void hids_device_send_boot_keyboard_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){ - hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle); - if (!instance){ - log_error("no instance for handle 0x%02x", con_handle); - return; - } - att_server_notify(con_handle, instance->hid_boot_keyboard_input_value_handle, report, report_len); + return att_server_notify(con_handle, instance->hid_boot_keyboard_input_value_handle, report, report_len); } diff --git a/src/ble/gatt-service/hids_device.h b/src/ble/gatt-service/hids_device.h index d6e1f5e95..6e757c65d 100644 --- a/src/ble/gatt-service/hids_device.h +++ b/src/ble/gatt-service/hids_device.h @@ -98,6 +98,7 @@ void hids_device_request_can_send_now_event(hci_con_handle_t con_handle); * @param report_id * @param report * @param report_len + * @returns status */ uint8_t hids_device_send_input_report_for_id(hci_con_handle_t con_handle, uint16_t report_id, const uint8_t * report, uint16_t report_len); @@ -106,18 +107,27 @@ uint8_t hids_device_send_input_report_for_id(hci_con_handle_t con_handle, uint16 * @param con_handle * @param report * @param report_len + * @returns status */ -void hids_device_send_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len); +uint8_t hids_device_send_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len); /** * @brief Send HID Boot Mouse Input Report + * @param con_handle + * @param report + * @param report_len + * @returns status */ -void hids_device_send_boot_mouse_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len); +uint8_t hids_device_send_boot_mouse_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len); /** * @brief Send HID Boot Mouse Input Report + * @param con_handle + * @param report + * @param report_len + * @returns status */ -void hids_device_send_boot_keyboard_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len); +uint8_t hids_device_send_boot_keyboard_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len); /* API_END */