xref: /btstack/src/ble/gatt-service/hids_device.c (revision d38dfb7f7d933e1fd827c77cee90f709ed1ff351)
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 * hids_device_get_report_for_type_and_id(hids_device_t * device, hid_report_type_t type, uint16_t report_id){
117     uint8_t pos;
118     uint8_t total_reports =  device->hid_input_reports_num + device->hid_output_reports_num + device->hid_feature_reports_num;
119     for (pos = 0 ; pos < total_reports ; pos++){
120         if ((device->hid_reports[pos].type == type) && (device->hid_reports[pos].id == report_id)){
121             return &device->hid_reports[pos];
122         }
123     }
124     return NULL;
125 }
126 
127 static hids_device_report_t * hids_device_get_report_for_id(hids_device_t * device, uint16_t report_id){
128     uint8_t pos;
129     uint8_t total_reports =  device->hid_input_reports_num + device->hid_output_reports_num + device->hid_feature_reports_num;
130     for (pos = 0 ; pos < total_reports ; pos++){
131         if (device->hid_reports[pos].id == report_id){
132             return &device->hid_reports[pos];
133         }
134     }
135     return NULL;
136 }
137 
138 static void hids_device_emit_event_with_uint8(uint8_t event, hci_con_handle_t con_handle, uint8_t value){
139     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
140     if (!instance){
141         log_error("no instance for handle 0x%02x", con_handle);
142         return;
143     }
144 
145     if (!packet_handler) return;
146     uint8_t buffer[6];
147     buffer[0] = HCI_EVENT_HIDS_META;
148     buffer[1] = 4;
149     buffer[2] = event;
150     little_endian_store_16(buffer, 3, (uint16_t) con_handle);
151     buffer[5] = value;
152     (*packet_handler)(HCI_EVENT_PACKET, 0, buffer, sizeof(buffer));
153 }
154 
155 static void hids_device_emit_event(uint8_t event, hci_con_handle_t con_handle){
156     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
157     if (!instance){
158         log_error("no instance for handle 0x%02x", con_handle);
159         return;
160     }
161 
162     if (!packet_handler) return;
163     uint8_t buffer[5];
164     buffer[0] = HCI_EVENT_HIDS_META;
165     buffer[1] = 4;
166     buffer[2] = event;
167     little_endian_store_16(buffer, 3, (uint16_t) con_handle);
168     (*packet_handler)(HCI_EVENT_PACKET, 0, buffer, sizeof(buffer));
169 }
170 
171 static void hids_device_can_send_now(void * context){
172     hci_con_handle_t con_handle = (hci_con_handle_t) (uintptr_t) context;
173     // notify client
174     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
175     if (!instance){
176         log_error("no instance for handle 0x%02x", con_handle);
177         return;
178     }
179 
180     if (!packet_handler) return;
181     uint8_t buffer[5];
182     buffer[0] = HCI_EVENT_HIDS_META;
183     buffer[1] = 3;
184     buffer[2] = HIDS_SUBEVENT_CAN_SEND_NOW;
185     little_endian_store_16(buffer, 3, (uint16_t) con_handle);
186     (*packet_handler)(HCI_EVENT_PACKET, 0, buffer, sizeof(buffer));
187 }
188 
189 // ATT Client Read Callback for Dynamic Data
190 // - if buffer == NULL, don't copy data, just return size of value
191 // - if buffer != NULL, copy data and return number bytes copied
192 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){
193     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
194     if (!instance){
195         log_error("no instance for handle 0x%02x", con_handle);
196         return HIDS_DEVICE_ERROR_CODE_INAPPROPRIATE_CONNECTION_PARAMETERS;
197     }
198 
199     if (att_handle == instance->hid_protocol_mode_value_handle){
200         log_info("Read protocol mode");
201         return att_read_callback_handle_byte(instance->hid_protocol_mode, offset, buffer, buffer_size);
202     }
203 
204     if (att_handle == instance->hid_report_map_handle){
205         log_info("Read report map");
206         return att_read_callback_handle_blob(instance->hid_descriptor, instance->hid_descriptor_size, offset, buffer, buffer_size);
207     }
208 
209     if (att_handle == instance->hid_boot_mouse_input_client_configuration_handle){
210         return att_read_callback_handle_little_endian_16(instance->hid_boot_mouse_input_client_configuration_value, offset, buffer, buffer_size);
211     }
212 
213     if (att_handle == instance->hid_boot_keyboard_input_client_configuration_handle){
214         return att_read_callback_handle_little_endian_16(instance->hid_boot_keyboard_input_client_configuration_value, offset, buffer, buffer_size);
215     }
216 
217     if (att_handle == instance->hid_control_point_value_handle){
218         if (buffer && (buffer_size >= 1u)){
219             buffer[0] = instance->hid_control_point_suspend;
220         }
221         return 1;
222     }
223 
224     hids_device_report_t * report = hids_device_get_report_for_client_configuration_handle(instance, att_handle);
225     if (report != NULL){
226         return att_read_callback_handle_little_endian_16(report->client_configuration_value, offset, buffer, buffer_size);
227     }
228     return 0;
229 }
230 
231 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){
232     UNUSED(transaction_mode);
233     UNUSED(buffer_size);
234     UNUSED(offset);
235 
236     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
237     if (!instance){
238         log_error("no instance for handle 0x%02x", con_handle);
239         return HIDS_DEVICE_ERROR_CODE_INAPPROPRIATE_CONNECTION_PARAMETERS;
240     }
241 
242     if (att_handle == instance->hid_boot_mouse_input_client_configuration_handle){
243         uint16_t new_value = little_endian_read_16(buffer, 0);
244         instance->hid_boot_mouse_input_client_configuration_value = new_value;
245         hids_device_emit_event_with_uint8(HIDS_SUBEVENT_BOOT_MOUSE_INPUT_REPORT_ENABLE, con_handle, (uint8_t) new_value);
246     }
247     if (att_handle == instance->hid_boot_keyboard_input_client_configuration_handle){
248         uint16_t new_value = little_endian_read_16(buffer, 0);
249         instance->hid_boot_keyboard_input_client_configuration_value = new_value;
250         hids_device_emit_event_with_uint8(HIDS_SUBEVENT_BOOT_KEYBOARD_INPUT_REPORT_ENABLE, con_handle, (uint8_t) new_value);
251     }
252 
253     if (att_handle == instance->hid_protocol_mode_value_handle){
254         instance->hid_protocol_mode = buffer[0];
255         log_info("Set protocol mode: %u", instance->hid_protocol_mode);
256         hids_device_emit_event_with_uint8(HIDS_SUBEVENT_PROTOCOL_MODE, con_handle, instance->hid_protocol_mode);
257     }
258 
259     if (att_handle == instance->hid_control_point_value_handle){
260         if (buffer_size < 1u){
261             return ATT_ERROR_INVALID_OFFSET;
262         }
263         instance->hid_control_point_suspend = buffer[0];
264         instance->con_handle = con_handle;
265         log_info("Set suspend tp: %u", instance->hid_control_point_suspend );
266         if (instance->hid_control_point_suspend == 0u){
267             hids_device_emit_event(HIDS_SUBEVENT_SUSPEND, con_handle);
268         } else if (instance->hid_control_point_suspend == 1u){
269             hids_device_emit_event(HIDS_SUBEVENT_EXIT_SUSPEND, con_handle);
270         }
271     }
272 
273     hids_device_report_t * report = hids_device_get_report_for_client_configuration_handle(instance, att_handle);
274     if (report != NULL){
275         uint16_t new_value = little_endian_read_16(buffer, 0);
276         report->client_configuration_value = new_value;
277         log_info("Enable Report (type %u) notifications: %x", (uint8_t) report->type, new_value);
278 
279         switch (report->type){
280             case HID_REPORT_TYPE_INPUT:
281                 hids_device_emit_event_with_uint8(HIDS_SUBEVENT_INPUT_REPORT_ENABLE, con_handle, (uint8_t) new_value);
282                 break;
283             case HID_REPORT_TYPE_OUTPUT:
284                 hids_device_emit_event_with_uint8(HIDS_SUBEVENT_OUTPUT_REPORT_ENABLE, con_handle, (uint8_t) new_value);
285                 break;
286             case HID_REPORT_TYPE_FEATURE:
287                 hids_device_emit_event_with_uint8(HIDS_SUBEVENT_FEATURE_REPORT_ENABLE, con_handle, (uint8_t) new_value);
288                 break;
289             default:
290                 btstack_unreachable();
291                 break;
292         }
293     }
294     return 0;
295 }
296 
297 void hids_device_init_with_storage(uint8_t hid_country_code, const uint8_t * hid_descriptor, uint16_t hid_descriptor_size,
298     uint16_t num_reports, hids_device_report_t * report_storage){
299 
300     hids_device_t * instance = hids_device_create_instance();
301 
302     btstack_assert(num_reports > 0);
303     btstack_assert(report_storage != NULL);
304 
305     instance->hid_country_code    = hid_country_code;
306     instance->hid_descriptor      = hid_descriptor;
307     instance->hid_descriptor_size = hid_descriptor_size;
308 
309     // default
310     instance->hid_protocol_mode   = 1;
311 
312     // get service handle range
313     uint16_t start_handle = 0;
314     uint16_t end_handle   = 0xffff;
315     int service_found = gatt_server_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_HUMAN_INTERFACE_DEVICE, &start_handle, &end_handle);
316     btstack_assert(service_found != 0);
317     UNUSED(service_found);
318 
319     // get report map handle
320     instance->hid_report_map_handle                               = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT_MAP);
321 
322     // get report map handle
323     instance->hid_protocol_mode_value_handle                      = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_PROTOCOL_MODE);
324 
325     // get value and client configuration handles for boot mouse input, boot keyboard input and report input
326     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);
327     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);
328 
329     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);
330     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);
331 
332     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);
333 
334     log_info("hid_report_map_handle                               0x%02x", instance->hid_report_map_handle);
335     log_info("hid_protocol_mode_value_handle                      0x%02x", instance->hid_protocol_mode_value_handle);
336     log_info("hid_boot_mouse_input_value_handle                   0x%02x", instance->hid_boot_mouse_input_value_handle);
337     log_info("hid_boot_mouse_input_client_configuration_handle    0x%02x", instance->hid_boot_mouse_input_client_configuration_handle);
338     log_info("hid_boot_keyboard_input_value_handle                0x%02x", instance->hid_boot_keyboard_input_value_handle);
339     log_info("hid_boot_keyboard_input_client_configuration_handle 0x%02x", instance->hid_boot_keyboard_input_client_configuration_handle);
340     log_info("hid_control_point_value_handle                      0x%02x", instance->hid_control_point_value_handle);
341 
342     instance->hid_reports = report_storage;
343 
344     uint16_t hid_reports_num = num_reports;
345     uint16_t assigned_reports_num = 0;
346     uint16_t start_chr_handle = start_handle;
347 
348     while ( (start_chr_handle < end_handle) && (assigned_reports_num < hid_reports_num)) {
349         uint16_t chr_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_chr_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT);
350         if (chr_value_handle == 0){
351             break;
352         }
353 
354         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);
355         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);
356         uint16_t report_reference_value_len;
357         const uint8_t * report_reference_value = gatt_server_get_const_value_for_handle(report_reference_handle, &report_reference_value_len);
358 
359         if (report_reference_value == NULL){
360             break;
361         }
362         if (report_reference_value_len != 2){
363             break;
364         }
365 
366         hids_device_report_t * report = &report_storage[assigned_reports_num];
367         report->value_handle = chr_value_handle;
368         report->client_configuration_handle = chr_client_configuration_handle;
369         report->client_configuration_value = 0;
370 
371         report->id = report_reference_value[0];
372         report->type = (hid_report_type_t)report_reference_value[1];
373 
374         switch (report->type){
375             case HID_REPORT_TYPE_INPUT:
376                 instance->hid_input_reports_num++;
377                 break;
378             case HID_REPORT_TYPE_OUTPUT:
379                 instance->hid_output_reports_num++;
380                 break;
381             case HID_REPORT_TYPE_FEATURE:
382                 instance->hid_feature_reports_num++;
383                 break;
384             default:
385                 btstack_unreachable();
386                 return;
387         }
388         log_info("hid_report_value_handle                       0x%02x, id %u, type %u", report->value_handle, report->id, (uint8_t)report->type);
389         log_info("hid_report_client_configuration_handle        0x%02x", report->client_configuration_handle);
390 
391         assigned_reports_num++;
392         start_chr_handle = chr_client_configuration_handle + 1;
393     }
394 
395     // register service with ATT Server
396     hid_service.start_handle   = start_handle;
397     hid_service.end_handle     = end_handle;
398     hid_service.read_callback  = &att_read_callback;
399     hid_service.write_callback = &att_write_callback;
400     att_server_register_service_handler(&hid_service);
401 }
402 
403 /**
404  * @brief Set up HIDS Device
405  */
406 void hids_device_init(uint8_t country_code, const uint8_t * descriptor, uint16_t descriptor_size){
407     uint16_t hid_reports_num = sizeof(hid_reports_generic_storage) / sizeof(hids_device_report_t);
408     hids_device_init_with_storage(country_code, descriptor, descriptor_size, hid_reports_num, hid_reports_generic_storage);
409 }
410 
411 /**
412  * @brief Register callback for the HIDS Device client.
413  * @param callback
414  */
415 void hids_device_register_packet_handler(btstack_packet_handler_t callback){
416     packet_handler = callback;
417 }
418 
419 /**
420  * @brief Request can send now event to send HID Report
421  * Generates an HIDS_SUBEVENT_CAN_SEND_NOW subevent
422  * @param hid_cid
423  */
424 void hids_device_request_can_send_now_event(hci_con_handle_t con_handle){
425     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
426     if (!instance){
427         log_error("no instance for handle 0x%02x", con_handle);
428         return;
429     }
430 
431     instance->battery_callback.callback = &hids_device_can_send_now;
432     instance->battery_callback.context  = (void*) (uintptr_t) con_handle;
433     att_server_register_can_send_now_callback(&instance->battery_callback, con_handle);
434 }
435 
436 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){
437     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
438     if (!instance){
439         log_error("no instance for handle 0x%02x", con_handle);
440         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
441     }
442 
443     hids_device_report_t * report_storage = hids_device_get_report_for_type_and_id(instance, HID_REPORT_TYPE_INPUT, report_id);
444     if (report_storage == NULL){
445         return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
446     }
447 
448     return att_server_notify(con_handle, report_storage->value_handle, report, report_len);
449 }
450 
451 uint8_t hids_device_send_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){
452     hids_device_t * device = hids_device_get_instance_for_con_handle(con_handle);
453     if (!device){
454         log_error("no instance for handle 0x%02x", con_handle);
455         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
456     }
457 
458     uint8_t pos;
459     uint8_t total_reports =  device->hid_input_reports_num + device->hid_output_reports_num + device->hid_feature_reports_num;
460     for (pos = 0 ; pos < total_reports ; pos++){
461         hids_device_report_t * report_storage = &device->hid_reports[pos];
462         if (report_storage->type == HID_REPORT_TYPE_INPUT){
463             return att_server_notify(con_handle, report_storage->value_handle, report, report_len);
464         }
465     }
466     return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
467 }
468 
469 /**
470  * @brief Send HID Boot Mouse Input Report
471  */
472 uint8_t hids_device_send_boot_mouse_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){
473     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
474     if (!instance){
475         log_error("no instance for handle 0x%02x", con_handle);
476         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
477     }
478     return att_server_notify(con_handle, instance->hid_boot_mouse_input_value_handle, report, report_len);
479 }
480 
481 /**
482  * @brief Send HID Boot Mouse Input Report
483  */
484 uint8_t hids_device_send_boot_keyboard_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len){
485     hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle);
486     if (!instance){
487         log_error("no instance for handle 0x%02x", con_handle);
488         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
489     }
490     return att_server_notify(con_handle, instance->hid_boot_keyboard_input_value_handle, report, report_len);
491 }
492