mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-22 06:41:17 +00:00
hid_host: set hid_descriptor_status for incoming connection; emit descriptor_available_event in boot modus
This commit is contained in:
parent
f1aa1cdc5d
commit
e615b0ec8b
@ -124,6 +124,8 @@ static enum {
|
||||
|
||||
static uint16_t hid_host_cid = 0;
|
||||
static bool hid_host_descriptor_available = false;
|
||||
static hid_protocol_mode_t hid_host_report_mode = HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT;
|
||||
|
||||
/* @section Main application configuration
|
||||
*
|
||||
* @text In the application configuration, L2CAP is initialized
|
||||
@ -261,7 +263,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
*/
|
||||
case BTSTACK_EVENT_STATE:
|
||||
if (btstack_event_state_get_state(packet) == HCI_STATE_WORKING){
|
||||
status = hid_host_connect(remote_addr, HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT, &hid_host_cid);
|
||||
status = hid_host_connect(remote_addr, hid_host_report_mode, &hid_host_cid);
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("HID host connect failed, status 0x%02x\n", status);
|
||||
}
|
||||
@ -286,7 +288,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
case HCI_EVENT_HID_META:
|
||||
switch (hci_event_hid_meta_get_subevent_code(packet)){
|
||||
case HID_SUBEVENT_INCOMING_CONNECTION:
|
||||
hid_host_accept_connection(hid_subevent_incoming_connection_get_hid_cid(packet), HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT);
|
||||
hid_host_accept_connection(hid_subevent_incoming_connection_get_hid_cid(packet), hid_host_report_mode);
|
||||
break;
|
||||
|
||||
case HID_SUBEVENT_CONNECTION_OPENED:
|
||||
@ -309,6 +311,8 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
if (status == ERROR_CODE_SUCCESS){
|
||||
hid_host_descriptor_available = true;
|
||||
printf("HID Descriptor available\n");
|
||||
} else {
|
||||
printf("Cannot handle input report, HID Descriptor is not available.\n");
|
||||
}
|
||||
break;
|
||||
case HID_SUBEVENT_CONNECTION_CLOSED:
|
||||
@ -363,10 +367,10 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
}
|
||||
switch ((hid_protocol_mode_t)hid_subevent_set_protocol_response_get_protocol_mode(packet)){
|
||||
case HID_PROTOCOL_MODE_BOOT:
|
||||
printf("Boot protocol mode set.\n");
|
||||
printf("Protocol mode set: BOOT.\n");
|
||||
break;
|
||||
case HID_PROTOCOL_MODE_REPORT:
|
||||
printf("Report protocol mode set.\n");
|
||||
printf("Protocol mode set: REPORT.\n");
|
||||
break;
|
||||
default:
|
||||
printf("Unknown protocol mode.\n");
|
||||
@ -377,10 +381,8 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
|
||||
case HID_SUBEVENT_REPORT:
|
||||
if (hid_host_descriptor_available){
|
||||
// printf("Received input report[%d]: ", hid_subevent_report_get_report_len(packet));
|
||||
hid_host_handle_interrupt_report(hid_subevent_report_get_report(packet), hid_subevent_report_get_report_len(packet));
|
||||
} else {
|
||||
printf("Cannot handle input report, HID Descriptor is not available: \n");
|
||||
printf_hexdump(hid_subevent_report_get_report(packet), hid_subevent_report_get_report_len(packet));
|
||||
}
|
||||
break;
|
||||
@ -406,7 +408,7 @@ static void show_usage(void){
|
||||
printf("\n--- Bluetooth HID Host Test Console %s ---\n", bd_addr_to_str(iut_address));
|
||||
printf("c - Connect to %s in report mode, with fallback to BOOT mode.\n", remote_addr_string);
|
||||
printf("C - Disconnect from %s\n", remote_addr_string);
|
||||
|
||||
|
||||
printf("\n");
|
||||
printf("Ctrl-c - exit\n");
|
||||
printf("---\n");
|
||||
@ -417,7 +419,7 @@ static void stdin_process(char cmd){
|
||||
switch (cmd){
|
||||
case 'c':
|
||||
printf("Connect to %s in report mode, with fallback to BOOT mode.\n", remote_addr_string);
|
||||
status = hid_host_connect(remote_addr, HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT, &hid_host_cid);
|
||||
status = hid_host_connect(remote_addr, hid_host_report_mode, &hid_host_cid);
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
|
@ -702,6 +702,7 @@ static void hid_host_packet_handler(uint8_t packet_type, uint16_t channel, uint8
|
||||
}
|
||||
|
||||
connection->state = HID_HOST_W4_CONTROL_CONNECTION_ESTABLISHED;
|
||||
connection->hid_descriptor_status = ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
|
||||
connection->con_handle = l2cap_event_incoming_connection_get_handle(packet);
|
||||
connection->control_cid = l2cap_event_incoming_connection_get_local_cid(packet);
|
||||
connection->incoming = true;
|
||||
@ -764,6 +765,7 @@ static void hid_host_packet_handler(uint8_t packet_type, uint16_t channel, uint8
|
||||
|
||||
switch (connection->requested_protocol_mode){
|
||||
case HID_PROTOCOL_MODE_BOOT:
|
||||
hid_emit_descriptor_available_event(connection);
|
||||
connection->set_protocol = true;
|
||||
l2cap_request_can_send_now_event(connection->control_cid);
|
||||
log_info("Incoming interrupt connection opened: set boot mode");
|
||||
|
@ -110,6 +110,8 @@ static enum {
|
||||
|
||||
static bool unplugged = false;
|
||||
static uint16_t hid_host_cid = 0;
|
||||
static bool hid_host_descriptor_available = false;
|
||||
|
||||
static hid_protocol_mode_t hid_host_protocol_mode = HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT;
|
||||
|
||||
// SDP
|
||||
@ -147,7 +149,7 @@ static void hid_host_setup(void){
|
||||
setbuf(stdout, NULL);
|
||||
}
|
||||
|
||||
static void handle_input_report(const uint8_t * report, uint16_t report_len){
|
||||
static void hid_host_handle_interrupt_report(const uint8_t * report, uint16_t report_len){
|
||||
// check if HID Input Report
|
||||
if (report_len < 1){
|
||||
printf("ignore report: len 0");
|
||||
@ -283,6 +285,16 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
hid_host_cid = hid_subevent_connection_opened_get_hid_cid(packet);
|
||||
printf("HID Host connected...\n");
|
||||
break;
|
||||
|
||||
case HID_SUBEVENT_DESCRIPTOR_AVAILABLE:
|
||||
status = hid_subevent_descriptor_available_get_status(packet);
|
||||
if (status == ERROR_CODE_SUCCESS){
|
||||
hid_host_descriptor_available = true;
|
||||
printf("HID Descriptor available\n");
|
||||
} else {
|
||||
printf("Cannot handle input report, HID Descriptor is not available.\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case HID_SUBEVENT_CONNECTION_CLOSED:
|
||||
hid_host_cid = 0;
|
||||
@ -337,9 +349,11 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
break;
|
||||
|
||||
case HID_SUBEVENT_REPORT:
|
||||
printf("Received input report[%d]: ", hid_subevent_report_get_report_len(packet));
|
||||
handle_input_report(hid_subevent_report_get_report(packet), hid_subevent_report_get_report_len(packet));
|
||||
printf("\n");
|
||||
if (hid_host_descriptor_available){
|
||||
hid_host_handle_interrupt_report(hid_subevent_report_get_report(packet), hid_subevent_report_get_report_len(packet));
|
||||
} else {
|
||||
printf_hexdump(hid_subevent_report_get_report(packet), hid_subevent_report_get_report_len(packet));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user