xref: /btstack/src/ble/gatt-service/hids_device.c (revision b51b065ce0616a484629b52ad685953594ba1555)
1 /*
2  * Copyright (C) 2014 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 #define BTSTACK_FILE__ "hids_device.c"
39 
40 /**
41  * Implementation of the GATT HIDS Device
42  * To use with your application, add '#import <hids.gatt>' to your .gatt file
43  */
44 
45 #include "hids_device.h"
46 
47 #include "ble/att_db.h"
48 #include "ble/att_server.h"
49 #include "bluetooth_gatt.h"
50 #include "btstack_util.h"
51 #include "btstack_debug.h"
52 
53 #define HIDS_DEVICE_ERROR_CODE_INAPPROPRIATE_CONNECTION_PARAMETERS    0x80
54 
55 // storage for 'generic' HID Device with single Input, Output, and Feature Report
56 static hids_device_report_t hid_reports_generic_storage[3];
57 
58 typedef struct{
59     uint16_t        con_handle;
60 
61     uint8_t         hid_country_code;
62     const uint8_t * hid_descriptor;
63     uint16_t        hid_descriptor_size;
64 
65     uint16_t        hid_report_map_handle;
66     uint8_t         hid_protocol_mode;
67     uint16_t        hid_protocol_mode_value_handle;
68 
69     uint16_t        hid_boot_mouse_input_value_handle;
70     uint16_t        hid_boot_mouse_input_client_configuration_handle;
71     uint16_t        hid_boot_mouse_input_client_configuration_value;
72 
73     uint16_t        hid_boot_keyboard_input_value_handle;
74     uint16_t        hid_boot_keyboard_input_client_configuration_handle;
75     uint16_t        hid_boot_keyboard_input_client_configuration_value;
76 
77     hids_device_report_t * hid_reports;
78 
79     uint8_t         hid_input_reports_num;
80     uint8_t         hid_output_reports_num;
81     uint8_t         hid_feature_reports_num;
82 
83     uint16_t        hid_control_point_value_handle;
84     uint8_t         hid_control_point_suspend;
85 
86     btstack_context_callback_registration_t  battery_callback;
87 } hids_device_t;
88 
89 static hids_device_t hids_device;
90 
91 static btstack_packet_handler_t packet_handler;
92 static att_service_handler_t hid_service;
93 
94 // TODO: store hids device connection into list
95 static hids_device_t * hids_device_get_instance_for_con_handle(uint16_t con_handle){
96     UNUSED(con_handle);
97     return &hids_device;
98 }
99 
100 static hids_device_t * hids_device_create_instance(void){
101     memset(&hids_device, 0, sizeof(hids_device_t));
102     return &hids_device;
103 }
104 
105 static hids_device_report_t * hids_device_get_report_for_client_configuration_handle(hids_device_t * device, uint16_t client_configuration_handle){
106     uint8_t pos;
107     uint8_t total_reports =  device->hid_input_reports_num + device->hid_output_reports_num + device->hid_feature_reports_num;
108     for (pos = 0 ; pos < total_reports ; pos++){
109         if (device->hid_reports[pos].client_configuration_handle == client_configuration_handle){
110             return &device->hid_reports[pos];
111         }
112     }
113     return NULL;
114 }
115 
116 static hids_device_report_t *
117 hids_device_get_report_for_id_and_type(hids_device_t *device, uint16_t report_id, hid_report_type_t type) {
118     uint8_t pos;
119     uint8_t total_reports =  device->hid_input_reports_num + device->hid_output_reports_num + device->hid_feature_reports_num;
120     for (pos = 0 ; pos < total_reports ; pos++){
121         if ((device->hid_reports[pos].type == type) && (device->hid_reports[pos].id == report_id)){
122             return &device->hid_reports[pos];
123         }
124     }
125     return NULL;
126 }
127 
128 static void hids_device_emit_event_with_uint8(uint8_t event, hci_con_handle_t con_handle, uint8_t value){
129     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
130     if (!instance){
131         log_error("no instance for handle 0x%02x", con_handle);
132         return;
133     }
134 
135     if (!packet_handler) return;
136     uint8_t buffer[6];
137     buffer[0] = HCI_EVENT_HIDS_META;
138     buffer[1] = 4;
139     buffer[2] = event;
140     little_endian_store_16(buffer, 3, (uint16_t) con_handle);
141     buffer[5] = value;
142     (*packet_handler)(HCI_EVENT_PACKET, 0, buffer, sizeof(buffer));
143 }
144 
145 static void hids_device_emit_event_with_uint8_uint8_t(uint8_t event, hci_con_handle_t con_handle, uint8_t value_1, uint8_t value_2){
146     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
147     if (!instance){
148         log_error("no instance for handle 0x%02x", con_handle);
149         return;
150     }
151 
152     if (!packet_handler) return;
153     uint8_t buffer[7];
154     buffer[0] = HCI_EVENT_HIDS_META;
155     buffer[1] = 4;
156     buffer[2] = event;
157     little_endian_store_16(buffer, 3, (uint16_t) con_handle);
158     buffer[5] = value_1;
159     buffer[6] = value_2;
160     (*packet_handler)(HCI_EVENT_PACKET, 0, buffer, sizeof(buffer));
161 }
162 
163 static void hids_device_emit_event(uint8_t event, hci_con_handle_t con_handle){
164     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
165     if (!instance){
166         log_error("no instance for handle 0x%02x", con_handle);
167         return;
168     }
169 
170     if (!packet_handler) return;
171     uint8_t buffer[5];
172     buffer[0] = HCI_EVENT_HIDS_META;
173     buffer[1] = 4;
174     buffer[2] = event;
175     little_endian_store_16(buffer, 3, (uint16_t) con_handle);
176     (*packet_handler)(HCI_EVENT_PACKET, 0, buffer, sizeof(buffer));
177 }
178 
179 static void hids_device_can_send_now(void * context){
180     hci_con_handle_t con_handle = (hci_con_handle_t) (uintptr_t) context;
181     // notify client
182     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
183     if (!instance){
184         log_error("no instance for handle 0x%02x", con_handle);
185         return;
186     }
187 
188     if (!packet_handler) return;
189     uint8_t buffer[5];
190     buffer[0] = HCI_EVENT_HIDS_META;
191     buffer[1] = 3;
192     buffer[2] = HIDS_SUBEVENT_CAN_SEND_NOW;
193     little_endian_store_16(buffer, 3, (uint16_t) con_handle);
194     (*packet_handler)(HCI_EVENT_PACKET, 0, buffer, sizeof(buffer));
195 }
196 
197 // ATT Client Read Callback for Dynamic Data
198 // - if buffer == NULL, don't copy data, just return size of value
199 // - if buffer != NULL, copy data and return number bytes copied
200 static uint16_t att_read_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
201     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
202     if (!instance){
203         log_error("no instance for handle 0x%02x", con_handle);
204         return HIDS_DEVICE_ERROR_CODE_INAPPROPRIATE_CONNECTION_PARAMETERS;
205     }
206 
207     if (att_handle == instance->hid_protocol_mode_value_handle){
208         log_info("Read protocol mode");
209         return att_read_callback_handle_byte(instance->hid_protocol_mode, offset, buffer, buffer_size);
210     }
211 
212     if (att_handle == instance->hid_report_map_handle){
213         log_info("Read report map");
214         return att_read_callback_handle_blob(instance->hid_descriptor, instance->hid_descriptor_size, offset, buffer, buffer_size);
215     }
216 
217     if (att_handle == instance->hid_boot_mouse_input_client_configuration_handle){
218         return att_read_callback_handle_little_endian_16(instance->hid_boot_mouse_input_client_configuration_value, offset, buffer, buffer_size);
219     }
220 
221     if (att_handle == instance->hid_boot_keyboard_input_client_configuration_handle){
222         return att_read_callback_handle_little_endian_16(instance->hid_boot_keyboard_input_client_configuration_value, offset, buffer, buffer_size);
223     }
224 
225     if (att_handle == instance->hid_control_point_value_handle){
226         if (buffer && (buffer_size >= 1u)){
227             buffer[0] = instance->hid_control_point_suspend;
228         }
229         return 1;
230     }
231 
232     hids_device_report_t * report = hids_device_get_report_for_client_configuration_handle(instance, att_handle);
233     if (report != NULL){
234         return att_read_callback_handle_little_endian_16(report->client_configuration_value, offset, buffer, buffer_size);
235     }
236     return 0;
237 }
238 
239 static int att_write_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){
240     UNUSED(transaction_mode);
241     UNUSED(buffer_size);
242     UNUSED(offset);
243 
244     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
245     if (!instance){
246         log_error("no instance for handle 0x%02x", con_handle);
247         return HIDS_DEVICE_ERROR_CODE_INAPPROPRIATE_CONNECTION_PARAMETERS;
248     }
249 
250     if (att_handle == instance->hid_boot_mouse_input_client_configuration_handle){
251         uint16_t new_value = little_endian_read_16(buffer, 0);
252         instance->hid_boot_mouse_input_client_configuration_value = new_value;
253         hids_device_emit_event_with_uint8(HIDS_SUBEVENT_BOOT_MOUSE_INPUT_REPORT_ENABLE, con_handle, (uint8_t) new_value);
254     }
255     if (att_handle == instance->hid_boot_keyboard_input_client_configuration_handle){
256         uint16_t new_value = little_endian_read_16(buffer, 0);
257         instance->hid_boot_keyboard_input_client_configuration_value = new_value;
258         hids_device_emit_event_with_uint8(HIDS_SUBEVENT_BOOT_KEYBOARD_INPUT_REPORT_ENABLE, con_handle, (uint8_t) new_value);
259     }
260 
261     if (att_handle == instance->hid_protocol_mode_value_handle){
262         instance->hid_protocol_mode = buffer[0];
263         log_info("Set protocol mode: %u", instance->hid_protocol_mode);
264         hids_device_emit_event_with_uint8(HIDS_SUBEVENT_PROTOCOL_MODE, con_handle, instance->hid_protocol_mode);
265     }
266 
267     if (att_handle == instance->hid_control_point_value_handle){
268         if (buffer_size < 1u){
269             return ATT_ERROR_INVALID_OFFSET;
270         }
271         instance->hid_control_point_suspend = buffer[0];
272         instance->con_handle = con_handle;
273         log_info("Set suspend tp: %u", instance->hid_control_point_suspend );
274         if (instance->hid_control_point_suspend == 0u){
275             hids_device_emit_event(HIDS_SUBEVENT_SUSPEND, con_handle);
276         } else if (instance->hid_control_point_suspend == 1u){
277             hids_device_emit_event(HIDS_SUBEVENT_EXIT_SUSPEND, con_handle);
278         }
279     }
280 
281     hids_device_report_t * report = hids_device_get_report_for_client_configuration_handle(instance, att_handle);
282     if (report != NULL){
283         uint16_t new_value = little_endian_read_16(buffer, 0);
284         report->client_configuration_value = new_value;
285         log_info("Enable Report (type %u) notifications: %x", (uint8_t) report->type, new_value);
286 
287         switch (report->type){
288             case HID_REPORT_TYPE_INPUT:
289                 hids_device_emit_event_with_uint8_uint8_t(HIDS_SUBEVENT_INPUT_REPORT_ENABLE, con_handle, report->id, (uint8_t) new_value);
290                 break;
291             case HID_REPORT_TYPE_OUTPUT:
292                 hids_device_emit_event_with_uint8_uint8_t(HIDS_SUBEVENT_OUTPUT_REPORT_ENABLE, con_handle, report->id, (uint8_t) new_value);
293                 break;
294             case HID_REPORT_TYPE_FEATURE:
295                 hids_device_emit_event_with_uint8_uint8_t(HIDS_SUBEVENT_FEATURE_REPORT_ENABLE, con_handle, report->id, (uint8_t) new_value);
296                 break;
297             default:
298                 btstack_unreachable();
299                 break;
300         }
301     }
302     return 0;
303 }
304 
305 void hids_device_init_with_storage(uint8_t hid_country_code, const uint8_t * hid_descriptor, uint16_t hid_descriptor_size,
306     uint16_t num_reports, hids_device_report_t * report_storage){
307 
308     hids_device_t * instance = hids_device_create_instance();
309 
310     btstack_assert(num_reports > 0);
311     btstack_assert(report_storage != NULL);
312 
313     instance->hid_country_code    = hid_country_code;
314     instance->hid_descriptor      = hid_descriptor;
315     instance->hid_descriptor_size = hid_descriptor_size;
316 
317     // default
318     instance->hid_protocol_mode   = 1;
319 
320     // get service handle range
321     uint16_t start_handle = 0;
322     uint16_t end_handle   = 0xffff;
323     int service_found = gatt_server_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_HUMAN_INTERFACE_DEVICE, &start_handle, &end_handle);
324     btstack_assert(service_found != 0);
325     UNUSED(service_found);
326 
327     // get report map handle
328     instance->hid_report_map_handle                               = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT_MAP);
329 
330     // get report map handle
331     instance->hid_protocol_mode_value_handle                      = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_PROTOCOL_MODE);
332 
333     // get value and client configuration handles for boot mouse input, boot keyboard input and report input
334     instance->hid_boot_mouse_input_value_handle                   = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_BOOT_MOUSE_INPUT_REPORT);
335     instance->hid_boot_mouse_input_client_configuration_handle    = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_BOOT_MOUSE_INPUT_REPORT);
336 
337     instance->hid_boot_keyboard_input_value_handle                = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_BOOT_KEYBOARD_INPUT_REPORT);
338     instance->hid_boot_keyboard_input_client_configuration_handle = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_BOOT_KEYBOARD_INPUT_REPORT);
339 
340     instance->hid_control_point_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_HID_CONTROL_POINT);
341 
342     log_info("hid_report_map_handle                               0x%02x", instance->hid_report_map_handle);
343     log_info("hid_protocol_mode_value_handle                      0x%02x", instance->hid_protocol_mode_value_handle);
344     log_info("hid_boot_mouse_input_value_handle                   0x%02x", instance->hid_boot_mouse_input_value_handle);
345     log_info("hid_boot_mouse_input_client_configuration_handle    0x%02x", instance->hid_boot_mouse_input_client_configuration_handle);
346     log_info("hid_boot_keyboard_input_value_handle                0x%02x", instance->hid_boot_keyboard_input_value_handle);
347     log_info("hid_boot_keyboard_input_client_configuration_handle 0x%02x", instance->hid_boot_keyboard_input_client_configuration_handle);
348     log_info("hid_control_point_value_handle                      0x%02x", instance->hid_control_point_value_handle);
349 
350     instance->hid_reports = report_storage;
351 
352     uint16_t hid_reports_num = num_reports;
353     uint16_t assigned_reports_num = 0;
354     uint16_t start_chr_handle = start_handle;
355 
356     while ( (start_chr_handle < end_handle) && (assigned_reports_num < hid_reports_num)) {
357         // mandatory
358         uint16_t chr_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_chr_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT);
359         if (chr_value_handle == 0){
360             break;
361         }
362 
363         // optional
364         uint16_t chr_client_configuration_handle = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(start_chr_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT);
365 
366         // mandatory
367         uint16_t report_reference_handle = gatt_server_get_descriptor_handle_for_characteristic_with_uuid16(start_chr_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT, ORG_BLUETOOTH_DESCRIPTOR_REPORT_REFERENCE);
368         if (report_reference_handle == 0){
369             break;
370         }
371 
372         // get report id and type from report reference
373         uint16_t report_reference_value_len;
374         const uint8_t * report_reference_value = gatt_server_get_const_value_for_handle(report_reference_handle, &report_reference_value_len);
375         if (report_reference_value == NULL){
376             break;
377         }
378         if (report_reference_value_len != 2){
379             break;
380         }
381         uint8_t report_id = report_reference_value[0];
382         hid_report_type_t report_type = (hid_report_type_t) report_reference_value[1];
383 
384         // store report info
385         hids_device_report_t * report = &report_storage[assigned_reports_num];
386         report->value_handle = chr_value_handle;
387         report->client_configuration_handle = chr_client_configuration_handle;
388         report->client_configuration_value = 0;
389         report->id   = report_id;
390         report->type = report_type;
391 
392         switch (report->type){
393             case HID_REPORT_TYPE_INPUT:
394                 instance->hid_input_reports_num++;
395                 break;
396             case HID_REPORT_TYPE_OUTPUT:
397                 instance->hid_output_reports_num++;
398                 break;
399             case HID_REPORT_TYPE_FEATURE:
400                 instance->hid_feature_reports_num++;
401                 break;
402             default:
403                 btstack_unreachable();
404                 return;
405         }
406         log_info("hid_report_value_handle                       0x%02x, id %u, type %u", report->value_handle, report->id, (uint8_t)report->type);
407         if (report->client_configuration_handle != 0){
408             log_info("hid_report_client_configuration_handle        0x%02x", report->client_configuration_handle);
409         }
410 
411         assigned_reports_num++;
412         start_chr_handle = report_reference_handle + 1;
413     }
414 
415     // register service with ATT Server
416     hid_service.start_handle   = start_handle;
417     hid_service.end_handle     = end_handle;
418     hid_service.read_callback  = &att_read_callback;
419     hid_service.write_callback = &att_write_callback;
420     att_server_register_service_handler(&hid_service);
421 }
422 
423 /**
424  * @brief Set up HIDS Device
425  */
426 void hids_device_init(uint8_t country_code, const uint8_t * descriptor, uint16_t descriptor_size){
427     uint16_t hid_reports_num = sizeof(hid_reports_generic_storage) / sizeof(hids_device_report_t);
428     hids_device_init_with_storage(country_code, descriptor, descriptor_size, hid_reports_num, hid_reports_generic_storage);
429 }
430 
431 /**
432  * @brief Register callback for the HIDS Device client.
433  * @param callback
434  */
435 void hids_device_register_packet_handler(btstack_packet_handler_t callback){
436     packet_handler = callback;
437 }
438 
439 /**
440  * @brief Request can send now event to send HID Report
441  * Generates an HIDS_SUBEVENT_CAN_SEND_NOW subevent
442  * @param hid_cid
443  */
444 void hids_device_request_can_send_now_event(hci_con_handle_t con_handle){
445     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
446     if (!instance){
447         log_error("no instance for handle 0x%02x", con_handle);
448         return;
449     }
450 
451     instance->battery_callback.callback = &hids_device_can_send_now;
452     instance->battery_callback.context  = (void*) (uintptr_t) con_handle;
453     att_server_register_can_send_now_callback(&instance->battery_callback, con_handle);
454 }
455 
456 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){
457     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
458     if (!instance){
459         log_error("no instance for handle 0x%02x", con_handle);
460         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
461     }
462 
463     hids_device_report_t * report_storage = hids_device_get_report_for_id_and_type(instance, report_id,
464                                                                                    HID_REPORT_TYPE_INPUT);
465     if (report_storage == NULL){
466         return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
467     }
468 
469     return att_server_notify(con_handle, report_storage->value_handle, report, report_len);
470 }
471 
472 uint8_t hids_device_send_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){
473     hids_device_t * device = hids_device_get_instance_for_con_handle(con_handle);
474     if (!device){
475         log_error("no instance for handle 0x%02x", con_handle);
476         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
477     }
478 
479     uint8_t pos;
480     uint8_t total_reports =  device->hid_input_reports_num + device->hid_output_reports_num + device->hid_feature_reports_num;
481     for (pos = 0 ; pos < total_reports ; pos++){
482         hids_device_report_t * report_storage = &device->hid_reports[pos];
483         if (report_storage->type == HID_REPORT_TYPE_INPUT){
484             return att_server_notify(con_handle, report_storage->value_handle, report, report_len);
485         }
486     }
487     return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
488 }
489 
490 /**
491  * @brief Send HID Boot Mouse Input Report
492  */
493 uint8_t hids_device_send_boot_mouse_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){
494     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
495     if (!instance){
496         log_error("no instance for handle 0x%02x", con_handle);
497         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
498     }
499     return att_server_notify(con_handle, instance->hid_boot_mouse_input_value_handle, report, report_len);
500 }
501 
502 /**
503  * @brief Send HID Boot Mouse Input Report
504  */
505 uint8_t hids_device_send_boot_keyboard_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){
506     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
507     if (!instance){
508         log_error("no instance for handle 0x%02x", con_handle);
509         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
510     }
511     return att_server_notify(con_handle, instance->hid_boot_keyboard_input_value_handle, report, report_len);
512 }
513