mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-30 07:21:20 +00:00
hids_client: move protocol mode to service, set protocol on boot mode, add report type as input param to get and write report functions
This commit is contained in:
parent
bd0562f189
commit
fd39e93aa9
@ -250,31 +250,26 @@ static bool external_report_index_for_uuid_exists(hids_client_t * client, uint16
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint8_t find_report_index_for_report_id(hids_client_t * client, uint8_t report_id){
|
||||
static uint8_t find_report_index_for_report_id_and_report_type(hids_client_t * client, uint8_t report_id, hid_report_type_t report_type){
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < client->num_reports; i++){
|
||||
hids_client_report_t report = client->reports[i];
|
||||
hid_protocol_mode_t protocol_mode = client->services[report.service_index].protocol_mode;
|
||||
|
||||
switch (client->protocol_mode){
|
||||
case HID_PROTOCOL_MODE_BOOT:
|
||||
for (i = 0; i < client->num_reports; i++){
|
||||
if (!client->reports[i].boot_report){
|
||||
continue;
|
||||
}
|
||||
if (client->reports[i].report_id == report_id){
|
||||
return i;
|
||||
}
|
||||
if (protocol_mode == HID_PROTOCOL_MODE_BOOT){
|
||||
if (!client->reports[i].boot_report){
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} else if (protocol_mode == HID_PROTOCOL_MODE_REPORT){
|
||||
if (client->reports[i].boot_report){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
for (i = 0; i < client->num_reports; i++){
|
||||
if (client->reports[i].boot_report){
|
||||
continue;
|
||||
}
|
||||
if (client->reports[i].report_id == report_id){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
break;
|
||||
if (report.report_id == report_id && report.report_type == report_type){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return HIDS_CLIENT_INVALID_REPORT_INDEX;
|
||||
}
|
||||
@ -322,27 +317,6 @@ static uint8_t hids_client_add_external_report(hids_client_t * client, gatt_clie
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool hid_clients_has_reports_in_report_mode(hids_client_t * client){
|
||||
uint8_t i;
|
||||
for (i = 0; i < client->num_reports; i++){
|
||||
if (!client->reports[i].boot_report){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool hid_clients_has_reports_in_boot_mode(hids_client_t * client){
|
||||
uint8_t i;
|
||||
for (i = 0; i < client->num_reports; i++){
|
||||
if (client->reports[i].boot_report){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint8_t hids_client_get_next_active_report_map_index(hids_client_t * client){
|
||||
uint8_t i;
|
||||
for (i = client->service_index; i < client->num_instances; i++){
|
||||
@ -394,29 +368,17 @@ static bool hids_client_report_map_uuid_query_init(hids_client_t * client){
|
||||
static uint8_t hids_client_get_next_report_index(hids_client_t * client){
|
||||
uint8_t i;
|
||||
uint8_t index = HIDS_CLIENT_INVALID_REPORT_INDEX;
|
||||
switch (client->protocol_mode){
|
||||
case HID_PROTOCOL_MODE_REPORT:
|
||||
for (i = client->report_index; i < client->num_reports && (index == HIDS_CLIENT_INVALID_REPORT_INDEX); i++){
|
||||
hids_client_report_t report = client->reports[i];
|
||||
if (report.report_type == HID_REPORT_TYPE_RESERVED && report.report_id == HID_REPORT_MODE_REPORT_ID){
|
||||
index = i;
|
||||
client->service_index = report.service_index;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HID_PROTOCOL_MODE_BOOT:
|
||||
for (i = client->report_index; i < client->num_reports && (index == HIDS_CLIENT_INVALID_REPORT_INDEX); i++){
|
||||
hids_client_report_t report = client->reports[i];
|
||||
if (report.boot_report){
|
||||
index = i;
|
||||
client->service_index = report.service_index;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = client->report_index; i < client->num_reports && (index == HIDS_CLIENT_INVALID_REPORT_INDEX); i++){
|
||||
hids_client_report_t report = client->reports[i];
|
||||
if (!report.boot_report){
|
||||
if (report.report_type == HID_REPORT_TYPE_RESERVED && report.report_id == HID_REPORT_MODE_REPORT_ID){
|
||||
index = i;
|
||||
client->service_index = report.service_index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
client->report_index = index;
|
||||
return index;
|
||||
}
|
||||
@ -444,35 +406,23 @@ static uint8_t hids_client_get_next_notification_report_index(hids_client_t * cl
|
||||
uint8_t i;
|
||||
uint8_t index = HIDS_CLIENT_INVALID_REPORT_INDEX;
|
||||
|
||||
switch (client->protocol_mode){
|
||||
case HID_PROTOCOL_MODE_REPORT:
|
||||
for (i = client->report_index; i < client->num_reports && (index == HIDS_CLIENT_INVALID_REPORT_INDEX); i++){
|
||||
hids_client_report_t report = client->reports[i];
|
||||
if (report.report_type != HID_REPORT_TYPE_INPUT){
|
||||
continue;
|
||||
}
|
||||
if (!report.boot_report){
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case HID_PROTOCOL_MODE_BOOT:
|
||||
for (i = client->report_index; i < client->num_reports && (index == HIDS_CLIENT_INVALID_REPORT_INDEX); i++){
|
||||
hids_client_report_t report = client->reports[i];
|
||||
if (report.report_type != HID_REPORT_TYPE_INPUT){
|
||||
continue;
|
||||
}
|
||||
if (report.boot_report){
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
break;
|
||||
for (i = client->report_index; i < client->num_reports && (index == HIDS_CLIENT_INVALID_REPORT_INDEX); i++){
|
||||
hids_client_report_t report = client->reports[i];
|
||||
hid_protocol_mode_t protocol_mode = client->services[report.service_index].protocol_mode;
|
||||
|
||||
default:
|
||||
break;
|
||||
if (protocol_mode == HID_PROTOCOL_MODE_BOOT){
|
||||
if (!client->reports[i].boot_report){
|
||||
continue;
|
||||
}
|
||||
} else if (protocol_mode == HID_PROTOCOL_MODE_REPORT){
|
||||
if (client->reports[i].boot_report){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (report.report_type == HID_REPORT_TYPE_INPUT){
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
client->report_index = index;
|
||||
return index;
|
||||
}
|
||||
@ -557,7 +507,7 @@ static void hids_emit_connection_established(hids_client_t * client, uint8_t sta
|
||||
little_endian_store_16(event, pos, client->cid);
|
||||
pos += 2;
|
||||
event[pos++] = status;
|
||||
event[pos++] = client->protocol_mode;
|
||||
event[pos++] = client->services[0].protocol_mode;
|
||||
event[pos++] = client->num_instances;
|
||||
(*client->client_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
}
|
||||
@ -700,20 +650,6 @@ static void hids_run_for_client(hids_client_t * client){
|
||||
UNUSED(att_status);
|
||||
break;
|
||||
|
||||
case HIDS_CLIENT_STATE_W2_SET_BOOT_PROTOCOL_MODE:
|
||||
att_status = gatt_client_write_value_of_characteristic_without_response(client->con_handle, client->protocol_mode_value_handle, 1, (uint8_t *)&client->required_protocol_mode);
|
||||
UNUSED(att_status);
|
||||
|
||||
client->protocol_mode = client->required_protocol_mode;
|
||||
if (hids_client_report_query_init(client)){
|
||||
hids_run_for_client(client);
|
||||
break;
|
||||
}
|
||||
|
||||
hids_emit_connection_established(client, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
|
||||
hids_finalize_client(client);
|
||||
break;
|
||||
|
||||
case HIDS_CLIENT_STATE_W2_READ_REPORT_MAP_HID_DESCRIPTOR:
|
||||
#ifdef ENABLE_TESTING_SUPPORT
|
||||
printf("\n\nRead REPORT_MAP (Handle 0x%04X) HID Descriptor of service %d:\n", client->services[client->service_index].report_map_value_handle, client->service_index);
|
||||
@ -920,14 +856,9 @@ static void hids_run_for_client(hids_client_t * client){
|
||||
client->handle);
|
||||
break;
|
||||
|
||||
case HIDS_CLIENT_STATE_W2_SET_PROTOCOL_MODE_WITHOUT_RESPONSE:
|
||||
case HIDS_CLIENT_W2_WRITE_VALUE_OF_CHARACTERISTIC_WITHOUT_RESPONSE:
|
||||
#ifdef ENABLE_TESTING_SUPPORT
|
||||
printf(" Write characteristic [service %d, handle 0x%04X]:\n", client->service_index, client->handle);
|
||||
#endif
|
||||
client->state = HIDS_CLIENT_STATE_CONNECTED;
|
||||
|
||||
att_status = gatt_client_write_value_of_characteristic_without_response(client->con_handle, client->handle, 1, (uint8_t *) &client->value);
|
||||
UNUSED(att_status);
|
||||
(void) gatt_client_request_can_write_without_response_event(&handle_gatt_client_event, client->con_handle);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -996,7 +927,6 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
|
||||
switch (characteristic.uuid16){
|
||||
case ORG_BLUETOOTH_CHARACTERISTIC_PROTOCOL_MODE:
|
||||
client->protocol_mode_value_handle = characteristic.value_handle;
|
||||
client->services[client->service_index].protocol_mode_value_handle = characteristic.value_handle;
|
||||
break;
|
||||
|
||||
@ -1193,6 +1123,60 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
}
|
||||
break;
|
||||
|
||||
case GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE:
|
||||
client = hids_get_client_for_con_handle(gatt_event_can_write_without_response_get_handle(packet));
|
||||
btstack_assert(client != NULL);
|
||||
|
||||
switch (client->state){
|
||||
case HIDS_CLIENT_STATE_W2_SET_PROTOCOL_MODE_WITHOUT_RESPONSE:
|
||||
att_status = gatt_client_write_value_of_characteristic_without_response(
|
||||
client->con_handle,
|
||||
client->services[client->service_index].protocol_mode_value_handle, 1, (uint8_t *)&client->required_protocol_mode);
|
||||
|
||||
#ifdef ENABLE_TESTING_SUPPORT
|
||||
printf("\n\nSet report mode %d of service %d, status 0x%02x", client->required_protocol_mode, client->service_index, att_status);
|
||||
#endif
|
||||
|
||||
if (att_status == ATT_ERROR_SUCCESS){
|
||||
client->services[client->service_index].protocol_mode = client->required_protocol_mode;
|
||||
if ((client->service_index + 1) < client->num_instances){
|
||||
client->service_index++;
|
||||
hids_run_for_client(client);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// read UUIDS for external characteristics
|
||||
if (hids_client_report_map_uuid_query_init(client)){
|
||||
hids_run_for_client(client);
|
||||
break;
|
||||
}
|
||||
|
||||
// discover characteristic descriptor for all Report characteristics,
|
||||
// then read value of characteristic descriptor to get Report ID
|
||||
if (hids_client_report_query_init(client)){
|
||||
hids_run_for_client(client);
|
||||
break;
|
||||
}
|
||||
|
||||
client->state = HIDS_CLIENT_STATE_CONNECTED;
|
||||
hids_emit_connection_established(client, ERROR_CODE_SUCCESS);
|
||||
break;
|
||||
|
||||
case HIDS_CLIENT_W2_WRITE_VALUE_OF_CHARACTERISTIC_WITHOUT_RESPONSE:
|
||||
#ifdef ENABLE_TESTING_SUPPORT
|
||||
printf(" Write characteristic [service %d, handle 0x%04X]:\n", client->service_index, client->handle);
|
||||
#endif
|
||||
client->state = HIDS_CLIENT_STATE_CONNECTED;
|
||||
(void) gatt_client_write_value_of_characteristic_without_response(client->con_handle, client->handle, 1, (uint8_t *) &client->value);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
client = hids_get_client_for_con_handle(gatt_event_query_complete_get_handle(packet));
|
||||
btstack_assert(client != NULL);
|
||||
@ -1231,56 +1215,28 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
break;
|
||||
}
|
||||
|
||||
btstack_assert(client->required_protocol_mode != HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT);
|
||||
|
||||
switch (client->required_protocol_mode){
|
||||
case HID_PROTOCOL_MODE_REPORT:
|
||||
client->protocol_mode = HID_PROTOCOL_MODE_REPORT;
|
||||
if (hid_clients_has_reports_in_report_mode(client)){
|
||||
client->protocol_mode = HID_PROTOCOL_MODE_REPORT;
|
||||
for (i = 0; i < client->num_instances; i++){
|
||||
client->services[i].protocol_mode = HID_PROTOCOL_MODE_REPORT;
|
||||
}
|
||||
// 1. we need to get HID Descriptor and
|
||||
// 2. get external Report characteristics if referenced from Report Map
|
||||
if (hids_client_report_map_query_init(client)){
|
||||
break;
|
||||
}
|
||||
hids_emit_connection_established(client, att_status);
|
||||
hids_emit_connection_established(client, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
|
||||
hids_finalize_client(client);
|
||||
return;
|
||||
|
||||
case HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT:
|
||||
if (hid_clients_has_reports_in_report_mode(client)){
|
||||
client->protocol_mode = HID_PROTOCOL_MODE_REPORT;
|
||||
break;
|
||||
}
|
||||
if (hid_clients_has_reports_in_boot_mode(client)){
|
||||
if (client->protocol_mode_value_handle != 0){
|
||||
client->state = HIDS_CLIENT_STATE_W2_SET_BOOT_PROTOCOL_MODE;
|
||||
break;
|
||||
}
|
||||
hids_emit_connection_established(client, att_status);
|
||||
hids_finalize_client(client);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (hid_clients_has_reports_in_boot_mode(client)){
|
||||
if (client->protocol_mode_value_handle != 0){
|
||||
client->state = HIDS_CLIENT_STATE_W2_SET_BOOT_PROTOCOL_MODE;
|
||||
break;
|
||||
}
|
||||
hids_emit_connection_established(client, att_status);
|
||||
hids_finalize_client(client);
|
||||
return;
|
||||
}
|
||||
// set boot mode
|
||||
client->service_index = 0;
|
||||
client->state = HIDS_CLIENT_STATE_W2_SET_PROTOCOL_MODE_WITHOUT_RESPONSE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (client->state == HIDS_CLIENT_STATE_W2_SET_BOOT_PROTOCOL_MODE){
|
||||
break;
|
||||
}
|
||||
|
||||
// 1. we need to get HID Descriptor and
|
||||
// 2. get external Report characteristics if referenced from Report Map
|
||||
if (hids_client_report_map_query_init(client)){
|
||||
break;
|
||||
}
|
||||
hids_emit_connection_established(client, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
|
||||
hids_finalize_client(client);
|
||||
break;
|
||||
|
||||
|
||||
@ -1342,7 +1298,6 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
client->state = HIDS_CLIENT_STATE_W2_READ_REPORT_ID_AND_TYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
// go for next report
|
||||
if (hids_client_report_query_next_report(client)){
|
||||
break;
|
||||
@ -1441,7 +1396,7 @@ uint8_t hids_client_disconnect(uint16_t hids_cid){
|
||||
return ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t hids_client_send_write_report(uint16_t hids_cid, uint8_t report_id, const uint8_t * report, uint8_t report_len){
|
||||
uint8_t hids_client_send_write_report(uint16_t hids_cid, uint8_t report_id, hid_report_type_t report_type, const uint8_t * report, uint8_t report_len){
|
||||
hids_client_t * client = hids_get_client_for_cid(hids_cid);
|
||||
if (client == NULL){
|
||||
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
|
||||
@ -1451,7 +1406,7 @@ uint8_t hids_client_send_write_report(uint16_t hids_cid, uint8_t report_id, cons
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
uint8_t report_index = find_report_index_for_report_id(client, report_id);
|
||||
uint8_t report_index = find_report_index_for_report_id_and_report_type(client, report_id, report_type);
|
||||
|
||||
if (report_index == HIDS_CLIENT_INVALID_REPORT_INDEX){
|
||||
return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
|
||||
@ -1477,7 +1432,7 @@ uint8_t hids_client_send_write_report(uint16_t hids_cid, uint8_t report_id, cons
|
||||
return ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t hids_client_send_get_report(uint16_t hids_cid, uint8_t report_id){
|
||||
uint8_t hids_client_send_get_report(uint16_t hids_cid, uint8_t report_id, hid_report_type_t report_type){
|
||||
hids_client_t * client = hids_get_client_for_cid(hids_cid);
|
||||
if (client == NULL){
|
||||
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
|
||||
@ -1487,7 +1442,7 @@ uint8_t hids_client_send_get_report(uint16_t hids_cid, uint8_t report_id){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
uint8_t report_index = find_report_index_for_report_id(client, report_id);
|
||||
uint8_t report_index = find_report_index_for_report_id_and_report_type(client, report_id, report_type);
|
||||
if (report_index == HIDS_CLIENT_INVALID_REPORT_INDEX){
|
||||
return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
|
||||
}
|
||||
|
@ -67,7 +67,8 @@ typedef enum {
|
||||
HIDS_CLIENT_STATE_W2_QUERY_CHARACTERISTIC,
|
||||
HIDS_CLIENT_STATE_W4_CHARACTERISTIC_RESULT,
|
||||
|
||||
HIDS_CLIENT_STATE_W2_SET_BOOT_PROTOCOL_MODE,
|
||||
// called if BOOT mode
|
||||
HIDS_CLIENT_STATE_W2_SET_PROTOCOL_MODE_WITHOUT_RESPONSE,
|
||||
|
||||
// for each REPORT_MAP characteristic, read HID Descriptor (Report Map Characteristic Value)
|
||||
HIDS_CLIENT_STATE_W2_READ_REPORT_MAP_HID_DESCRIPTOR,
|
||||
@ -144,6 +145,8 @@ typedef struct {
|
||||
} hids_client_report_t;
|
||||
|
||||
typedef struct {
|
||||
hid_protocol_mode_t protocol_mode;
|
||||
|
||||
uint16_t start_handle;
|
||||
uint16_t end_handle;
|
||||
|
||||
@ -168,7 +171,7 @@ typedef struct {
|
||||
|
||||
hci_con_handle_t con_handle;
|
||||
uint16_t cid;
|
||||
hid_protocol_mode_t protocol_mode;
|
||||
|
||||
hid_service_client_state_t state;
|
||||
btstack_packet_handler_t client_handler;
|
||||
|
||||
@ -179,8 +182,6 @@ typedef struct {
|
||||
uint8_t service_index;
|
||||
hid_protocol_mode_t required_protocol_mode;
|
||||
|
||||
uint16_t protocol_mode_value_handle;
|
||||
|
||||
// send report
|
||||
hids_client_report_t reports[HIDS_CLIENT_NUM_REPORTS];
|
||||
uint8_t num_reports;
|
||||
@ -224,9 +225,9 @@ uint8_t hids_client_connect(hci_con_handle_t con_handle, btstack_packet_handler_
|
||||
* @param report_len
|
||||
* @result status ERROR_CODE_SUCCESS on success, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
|
||||
*/
|
||||
uint8_t hids_client_send_write_report(uint16_t hids_cid, uint8_t report_id, const uint8_t * report, uint8_t report_len);
|
||||
uint8_t hids_client_send_write_report(uint16_t hids_cid, uint8_t report_id, hid_report_type_t report_type, const uint8_t * report, uint8_t report_len);
|
||||
|
||||
uint8_t hids_client_send_get_report(uint16_t hids_cid, uint8_t report_id);
|
||||
uint8_t hids_client_send_get_report(uint16_t hids_cid, uint8_t report_id, hid_report_type_t report_type);
|
||||
|
||||
uint8_t hids_client_get_hid_information(uint16_t hids_cid, uint8_t service_index);
|
||||
|
||||
|
@ -61,5 +61,28 @@ HOGP/BH/HGDC/BV-14-I: b
|
||||
HOGP/BH/HGDC/BV-15-I: b
|
||||
HOGP/BH/HGDC/BV-16-I: d
|
||||
|
||||
HOGP/BH/HGRF/BV-10-I: b, r, k
|
||||
HOGP/BH/HGRF/BV-11-I: b
|
||||
HOGP/BH/HGRF/BV-12-I: d
|
||||
HOGP/BH/HGRF/BV-13-I: h, r, 7
|
||||
HOGP/BH/HGRF/BV-14-I: h, r, 7
|
||||
HOGP/BH/HGRF/BV-15-I: h, r, 8
|
||||
HOGP/BH/HGRF/BV-16-I: h, r, 9
|
||||
HOGP/BH/HGRF/BV-17-I: h, r, 9
|
||||
HOGP/BH/HGRF/BV-18-I: h, r, p, P
|
||||
|
||||
HOGP/BH/HGWF/BV-08-I: h, w, p, P
|
||||
HOGP/BH/HGWF/BV-09-I: h, w, 7
|
||||
HOGP/BH/HGWF/BV-10-I: h, w, 8
|
||||
HOGP/BH/HGWF/BV-11-I: h, w, 9
|
||||
|
||||
HOGP/BH/HGCF/BV-03-I: h
|
||||
HOGP/BH/HGCF/BV-04-I: h, w, N
|
||||
HOGP/BH/HGCF/BV-05-I: h
|
||||
HOGP/BH/HGCF/BV-06-I: h, w, N
|
||||
|
||||
HOGP/BH/HGNF/BV-02-I: h
|
||||
HOGP/BH/HGNF/BV-03-I: h
|
||||
HOGP/BH/HGNF/BI-01-I: h
|
||||
|
||||
|
||||
|
@ -263,9 +263,18 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
if (app_state != READY) break;
|
||||
hids_client_disconnect(hids_cid);
|
||||
battery_service_client_disconnect(battery_service_cid);
|
||||
|
||||
connection_handle = HCI_CON_HANDLE_INVALID;
|
||||
printf("\nDisconnected\n");
|
||||
hids_cid = 0;
|
||||
battery_service_cid = 0;
|
||||
|
||||
connect_hids_client = false;
|
||||
connect_battery_client = false;
|
||||
connect_device_information_client = false;
|
||||
app_state = IDLE;
|
||||
printf("\nDisconnected\n");
|
||||
break;
|
||||
|
||||
case HCI_EVENT_LE_META:
|
||||
@ -586,24 +595,60 @@ static void show_usage(void){
|
||||
}
|
||||
|
||||
static void hog_host_connect_hids_client(void){
|
||||
app_state = W4_CONNECTED;
|
||||
printf("Connect to remote device\n");
|
||||
connect_hids_client = true;
|
||||
gap_connect(remote_device.addr, remote_device.addr_type);
|
||||
switch (app_state){
|
||||
case READY:
|
||||
if (hids_cid){
|
||||
hids_client_disconnect(hids_cid);
|
||||
hids_cid = 0;
|
||||
}
|
||||
app_state = W4_CLIENT_CONNECTED;
|
||||
(void) hids_client_connect(connection_handle, hid_service_gatt_client_event_handler, protocol_mode, &hids_cid);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Connect to remote device\n");
|
||||
connect_hids_client = true;
|
||||
app_state = W4_CONNECTED;
|
||||
gap_connect(remote_device.addr, remote_device.addr_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void hog_host_connect_battery_client(void){
|
||||
app_state = W4_CONNECTED;
|
||||
printf("Connect to remote device\n");
|
||||
connect_battery_client = true;
|
||||
gap_connect(remote_device.addr, remote_device.addr_type);
|
||||
printf("state %d\n", app_state);
|
||||
switch (app_state){
|
||||
case READY:
|
||||
if (battery_service_cid){
|
||||
hids_client_disconnect(battery_service_cid);
|
||||
battery_service_cid = 0;
|
||||
}
|
||||
app_state = W4_CLIENT_CONNECTED;
|
||||
(void) battery_service_client_connect(connection_handle, battery_service_gatt_client_event_handler, 2000, &battery_service_cid);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Connect to remote device\n");
|
||||
connect_battery_client = true;
|
||||
app_state = W4_CONNECTED;
|
||||
gap_connect(remote_device.addr, remote_device.addr_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void hog_host_connect_device_information_client(void){
|
||||
app_state = W4_CONNECTED;
|
||||
printf("Connect to remote device\n");
|
||||
connect_device_information_client = true;
|
||||
gap_connect(remote_device.addr, remote_device.addr_type);
|
||||
switch (app_state){
|
||||
case READY:
|
||||
app_state = W4_CLIENT_CONNECTED;
|
||||
(void) device_information_service_client_query(connection_handle, device_information_service_gatt_client_event_handler);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Connect to remote device\n");
|
||||
connect_device_information_client = true;
|
||||
app_state = W4_CONNECTED;
|
||||
gap_connect(remote_device.addr, remote_device.addr_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void stdin_process(char character){
|
||||
@ -680,32 +725,50 @@ static void stdin_process(char character){
|
||||
|
||||
case '1':
|
||||
printf("Get report with ID 1\n");
|
||||
hids_client_send_get_report(hids_cid, 1);
|
||||
hids_client_send_get_report(hids_cid, 1, HID_REPORT_TYPE_INPUT);
|
||||
break;
|
||||
case '2':
|
||||
printf("Get report with ID 2\n");
|
||||
hids_client_send_get_report(hids_cid, 2);
|
||||
hids_client_send_get_report(hids_cid, 2, HID_REPORT_TYPE_OUTPUT);
|
||||
break;
|
||||
|
||||
case '3':
|
||||
printf("Get report with ID 3\n");
|
||||
hids_client_send_get_report(hids_cid, 3);
|
||||
hids_client_send_get_report(hids_cid, 3, HID_REPORT_TYPE_FEATURE);
|
||||
break;
|
||||
|
||||
case '4':
|
||||
printf("Get report with ID 4\n");
|
||||
hids_client_send_get_report(hids_cid, 4);
|
||||
hids_client_send_get_report(hids_cid, 4, HID_REPORT_TYPE_INPUT);
|
||||
break;
|
||||
|
||||
case '5':
|
||||
printf("Get report with ID 5\n");
|
||||
hids_client_send_get_report(hids_cid, 5);
|
||||
hids_client_send_get_report(hids_cid, 5, HID_REPORT_TYPE_OUTPUT);
|
||||
break;
|
||||
|
||||
case '6':
|
||||
printf("Get report with ID 6\n");
|
||||
hids_client_send_get_report(hids_cid, 6);
|
||||
hids_client_send_get_report(hids_cid, 6, HID_REPORT_TYPE_FEATURE);
|
||||
break;
|
||||
|
||||
|
||||
case '7':
|
||||
printf("Get Input report from Boot Keyboard\n");
|
||||
hids_client_send_get_report(hids_cid, HID_BOOT_MODE_KEYBOARD_ID, HID_REPORT_TYPE_INPUT);
|
||||
break;
|
||||
|
||||
case '8':
|
||||
printf("Get Output report from Boot Keyboard\n");
|
||||
hids_client_send_get_report(hids_cid, HID_BOOT_MODE_KEYBOARD_ID, HID_REPORT_TYPE_OUTPUT);
|
||||
break;
|
||||
|
||||
case '9':
|
||||
printf("Get Input report from Boot Mouse\n");
|
||||
hids_client_send_get_report(hids_cid, HID_BOOT_MODE_MOUSE_ID, HID_REPORT_TYPE_INPUT);
|
||||
break;
|
||||
|
||||
|
||||
case '\n':
|
||||
case '\r':
|
||||
break;
|
||||
@ -719,37 +782,55 @@ static void stdin_process(char character){
|
||||
case '1':{
|
||||
uint8_t report[] = {0xAA, 0xB3, 0xF8, 0xA6, 0xCD};
|
||||
printf("Write report with id 0x01\n");
|
||||
hids_client_send_write_report(hids_cid, 0x01, report, sizeof(report));
|
||||
hids_client_send_write_report(hids_cid, 0x01, HID_REPORT_TYPE_INPUT, report, sizeof(report));
|
||||
break;
|
||||
}
|
||||
case '2':{
|
||||
uint8_t report[] = {0xEF, 0x90, 0x78, 0x56, 0x34, 0x12, 0x00};
|
||||
printf("Write report with id 0x02\n");
|
||||
hids_client_send_write_report(hids_cid, 0x02, report, sizeof(report));
|
||||
hids_client_send_write_report(hids_cid, 0x02, HID_REPORT_TYPE_OUTPUT, report, sizeof(report));
|
||||
break;
|
||||
}
|
||||
case '3':{
|
||||
uint8_t report[] = {0xEA, 0x45, 0x3F, 0x2D, 0x87};
|
||||
printf("Write report with id 0x03\n");
|
||||
hids_client_send_write_report(hids_cid, 0x03, report, sizeof(report));
|
||||
hids_client_send_write_report(hids_cid, 0x03, HID_REPORT_TYPE_FEATURE, report, sizeof(report));
|
||||
break;
|
||||
}
|
||||
case '4':{
|
||||
uint8_t report[] = {0xAA, 0xB3, 0xF8, 0xA6, 0xCD};
|
||||
printf("Write report with id 0x04\n");
|
||||
hids_client_send_write_report(hids_cid, 0x04, report, sizeof(report));
|
||||
hids_client_send_write_report(hids_cid, 0x04, HID_REPORT_TYPE_INPUT, report, sizeof(report));
|
||||
break;
|
||||
}
|
||||
case '5':{
|
||||
uint8_t report[] = {0xEF, 0x90, 0x78, 0x56, 0x34, 0x12, 0x00};
|
||||
printf("Write report with id 0x05\n");
|
||||
hids_client_send_write_report(hids_cid, 0x05, report, sizeof(report));
|
||||
hids_client_send_write_report(hids_cid, 0x05, HID_REPORT_TYPE_OUTPUT, report, sizeof(report));
|
||||
break;
|
||||
}
|
||||
case '6':{
|
||||
uint8_t report[] = {0xEA, 0x45, 0x3F, 0x2D, 0x87};
|
||||
printf("Write report with id 0x06\n");
|
||||
hids_client_send_write_report(hids_cid, 0x06, report, sizeof(report));
|
||||
hids_client_send_write_report(hids_cid, 0x06, HID_REPORT_TYPE_FEATURE, report, sizeof(report));
|
||||
break;
|
||||
}
|
||||
case '7':{
|
||||
uint8_t report[] = {};
|
||||
printf("Write Input report for Boot Keyboard\n");
|
||||
hids_client_send_write_report(hids_cid, HID_BOOT_MODE_KEYBOARD_ID, HID_REPORT_TYPE_INPUT, report, sizeof(report));
|
||||
break;
|
||||
}
|
||||
case '8':{
|
||||
uint8_t report[] = {0xEF, 0x90, 0x78, 0x56, 0x34, 0x12, 0x00};
|
||||
printf("Write Output report for Boot Keyboard\n");
|
||||
hids_client_send_write_report(hids_cid, HID_BOOT_MODE_KEYBOARD_ID, HID_REPORT_TYPE_OUTPUT, report, sizeof(report));
|
||||
break;
|
||||
}
|
||||
case '9':{
|
||||
uint8_t report[] = {0xEA, 0x45, 0x3F, 0x2D, 0x87};
|
||||
printf("Write Input report for Boot Mouse\n");
|
||||
hids_client_send_write_report(hids_cid, HID_BOOT_MODE_MOUSE_ID, HID_REPORT_TYPE_INPUT, report, sizeof(report));
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user