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