mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 03:35:20 +00:00
hids_client: get protocol mode, update pts test
This commit is contained in:
parent
f4d3b82a97
commit
af2241c2c0
@ -601,7 +601,21 @@ static void hids_client_emit_hid_information_event(hids_client_t * client, const
|
||||
|
||||
(*client->client_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
}
|
||||
|
||||
|
||||
static void hids_client_emit_protocol_mode_event(hids_client_t * client, const uint8_t *value, uint16_t value_len){
|
||||
if (value_len != 1) return;
|
||||
|
||||
uint8_t event[11];
|
||||
int pos = 0;
|
||||
event[pos++] = HCI_EVENT_GATTSERVICE_META;
|
||||
event[pos++] = sizeof(event) - 2;
|
||||
event[pos++] = GATTSERVICE_SUBEVENT_HID_PROTOCOL_MODE;
|
||||
little_endian_store_16(event, pos, client->cid);
|
||||
pos += 2;
|
||||
event[pos++] = client->service_index;
|
||||
event[pos++] = value[0];
|
||||
(*client->client_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
}
|
||||
|
||||
static void handle_notification_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) {
|
||||
UNUSED(packet_type);
|
||||
@ -749,7 +763,7 @@ static void hids_run_for_client(hids_client_t * client){
|
||||
client->reports[client->report_index].value_handle);
|
||||
#endif
|
||||
client->state = HIDS_CLIENT_STATE_W4_REPORT_FOUND;
|
||||
client->descriptor_handle = 0;
|
||||
client->handle = 0;
|
||||
|
||||
characteristic.value_handle = client->reports[client->report_index].value_handle;
|
||||
characteristic.end_handle = client->reports[client->report_index].end_handle;
|
||||
@ -764,8 +778,8 @@ static void hids_run_for_client(hids_client_t * client){
|
||||
client->state = HIDS_CLIENT_STATE_W4_REPORT_ID_AND_TYPE;
|
||||
|
||||
// result in GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT
|
||||
att_status = gatt_client_read_characteristic_descriptor_using_descriptor_handle(&handle_gatt_client_event, client->con_handle, client->descriptor_handle);
|
||||
client->descriptor_handle = 0;
|
||||
att_status = gatt_client_read_characteristic_descriptor_using_descriptor_handle(&handle_gatt_client_event, client->con_handle, client->handle);
|
||||
client->handle = 0;
|
||||
UNUSED(att_status);
|
||||
break;
|
||||
|
||||
@ -843,14 +857,14 @@ static void hids_run_for_client(hids_client_t * client){
|
||||
|
||||
break;
|
||||
#endif
|
||||
case HIDS_CLIENT_W2_SEND_GET_HID_INFORMATION:
|
||||
client->state = HIDS_CLIENT_W4_GET_HID_INFORMATION_RESULT;
|
||||
case HIDS_CLIENT_W2_READ_VALUE_OF_CHARACTERISTIC:
|
||||
client->state = HIDS_CLIENT_W4_VALUE_OF_CHARACTERISTIC_RESULT;
|
||||
|
||||
// result in GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT
|
||||
att_status = gatt_client_read_value_of_characteristic_using_value_handle(
|
||||
&handle_gatt_client_event,
|
||||
client->con_handle,
|
||||
client->services[client->service_index].hid_information_value_handle);
|
||||
client->handle);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -919,6 +933,7 @@ 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;
|
||||
|
||||
case ORG_BLUETOOTH_CHARACTERISTIC_BOOT_KEYBOARD_INPUT_REPORT:
|
||||
@ -944,12 +959,10 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
|
||||
case ORG_BLUETOOTH_CHARACTERISTIC_HID_INFORMATION:
|
||||
client->services[client->service_index].hid_information_value_handle = characteristic.value_handle;
|
||||
client->services[client->service_index].hid_information_end_handle = characteristic.end_handle;
|
||||
break;
|
||||
|
||||
case ORG_BLUETOOTH_CHARACTERISTIC_HID_CONTROL_POINT:
|
||||
client->services[client->service_index].control_point_value_handle = characteristic.value_handle;
|
||||
client->services[client->service_index].control_point_end_handle = characteristic.end_handle;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -1019,7 +1032,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
case HIDS_CLIENT_STATE_W4_REPORT_FOUND:
|
||||
// setup for descriptor value query
|
||||
if (characteristic_descriptor.uuid16 == ORG_BLUETOOTH_DESCRIPTOR_REPORT_REFERENCE){
|
||||
client->descriptor_handle = characteristic_descriptor.handle;
|
||||
client->handle = characteristic_descriptor.handle;
|
||||
#ifdef ENABLE_TESTING_SUPPORT
|
||||
printf(" Report Characteristic Report Reference Characteristic Descriptor: Handle 0x%04X, UUID 0x%04X\n",
|
||||
characteristic_descriptor.handle,
|
||||
@ -1048,6 +1061,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
|
||||
value = gatt_event_characteristic_value_query_result_get_value(packet);
|
||||
value_len = gatt_event_characteristic_value_query_result_get_value_length(packet);
|
||||
|
||||
|
||||
switch (client->state){
|
||||
#ifdef ENABLE_TESTING_SUPPORT
|
||||
@ -1056,10 +1070,18 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
printf_hexdump(value, value_len);
|
||||
break;
|
||||
#endif
|
||||
case HIDS_CLIENT_W4_GET_HID_INFORMATION_RESULT:
|
||||
hids_client_emit_hid_information_event(client, value, value_len);
|
||||
case HIDS_CLIENT_W4_VALUE_OF_CHARACTERISTIC_RESULT:{
|
||||
uint16_t value_handle = gatt_event_characteristic_value_query_result_get_value_handle(packet);
|
||||
if (value_handle == client->services[client->service_index].hid_information_value_handle){
|
||||
hids_client_emit_hid_information_event(client, value, value_len);
|
||||
break;
|
||||
}
|
||||
if (value_handle == client->services[client->service_index].protocol_mode_value_handle){
|
||||
hids_client_emit_protocol_mode_event(client, value, value_len);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1252,7 +1274,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
break;
|
||||
|
||||
case HIDS_CLIENT_STATE_W4_REPORT_FOUND:
|
||||
if (client->descriptor_handle != 0){
|
||||
if (client->handle != 0){
|
||||
client->state = HIDS_CLIENT_STATE_W2_READ_REPORT_ID_AND_TYPE;
|
||||
break;
|
||||
}
|
||||
@ -1291,7 +1313,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
break;
|
||||
#endif
|
||||
|
||||
case HIDS_CLIENT_W4_GET_HID_INFORMATION_RESULT:
|
||||
case HIDS_CLIENT_W4_VALUE_OF_CHARACTERISTIC_RESULT:
|
||||
client->state = HIDS_CLIENT_STATE_CONNECTED;
|
||||
break;
|
||||
|
||||
@ -1423,7 +1445,31 @@ uint8_t hids_client_get_hid_information(uint16_t hids_cid, uint8_t service_index
|
||||
}
|
||||
|
||||
client->service_index = service_index;
|
||||
client->state = HIDS_CLIENT_W2_SEND_GET_HID_INFORMATION;
|
||||
client->handle = client->services[client->service_index].hid_information_value_handle;
|
||||
|
||||
client->state = HIDS_CLIENT_W2_READ_VALUE_OF_CHARACTERISTIC;
|
||||
hids_run_for_client(client);
|
||||
return ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t hids_client_get_protocol_mode(uint16_t hids_cid, uint8_t service_index){
|
||||
hids_client_t * client = hids_get_client_for_cid(hids_cid);
|
||||
if (client == NULL){
|
||||
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
|
||||
}
|
||||
|
||||
if (client->state != HIDS_CLIENT_STATE_CONNECTED) {
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
if (service_index >= client->num_instances){
|
||||
return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
|
||||
}
|
||||
|
||||
client->service_index = service_index;
|
||||
client->handle = client->services[client->service_index].protocol_mode_value_handle;
|
||||
|
||||
client->state = HIDS_CLIENT_W2_READ_VALUE_OF_CHARACTERISTIC;
|
||||
hids_run_for_client(client);
|
||||
return ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ typedef enum {
|
||||
HIDS_CLIENT_W2_SEND_GET_REPORT,
|
||||
HIDS_CLIENT_W4_GET_REPORT_RESULT,
|
||||
|
||||
HIDS_CLIENT_W2_SEND_GET_HID_INFORMATION,
|
||||
HIDS_CLIENT_W4_GET_HID_INFORMATION_RESULT,
|
||||
HIDS_CLIENT_W2_READ_VALUE_OF_CHARACTERISTIC,
|
||||
HIDS_CLIENT_W4_VALUE_OF_CHARACTERISTIC_RESULT,
|
||||
|
||||
#ifdef ENABLE_TESTING_SUPPORT
|
||||
HIDS_CLIENT_W2_READ_CHARACTERISTIC_CONFIGURATION,
|
||||
@ -144,10 +144,8 @@ typedef struct {
|
||||
uint16_t report_map_end_handle;
|
||||
|
||||
uint16_t hid_information_value_handle;
|
||||
uint16_t hid_information_end_handle;
|
||||
|
||||
uint16_t control_point_value_handle;
|
||||
uint16_t control_point_end_handle;
|
||||
uint16_t protocol_mode_value_handle;
|
||||
|
||||
// descriptor storage
|
||||
uint16_t hid_descriptor_offset;
|
||||
@ -185,7 +183,7 @@ typedef struct {
|
||||
|
||||
// index used for report and report map search
|
||||
uint8_t report_index;
|
||||
uint16_t descriptor_handle;
|
||||
uint16_t handle;
|
||||
uint16_t report_len;
|
||||
const uint8_t * report;
|
||||
|
||||
@ -224,6 +222,7 @@ uint8_t hids_client_send_get_report(uint16_t hids_cid, uint8_t report_id);
|
||||
|
||||
uint8_t hids_client_get_hid_information(uint16_t hids_cid, uint8_t service_index);
|
||||
|
||||
uint8_t hids_client_get_protocol_mode(uint16_t hids_cid, uint8_t service_index);
|
||||
|
||||
/**
|
||||
* @brief Disconnect from Battery Service.
|
||||
|
@ -3244,6 +3244,14 @@ typedef uint8_t sm_key_t[16];
|
||||
*/
|
||||
#define GATTSERVICE_SUBEVENT_HID_INFORMATION 0x15
|
||||
|
||||
/**
|
||||
* @format 1211
|
||||
* @param subevent_code
|
||||
* @param hids_cid
|
||||
* @param service_index
|
||||
* @param protocol_mode see hid_protocol_mode_t in hid.h
|
||||
*/
|
||||
#define GATTSERVICE_SUBEVENT_HID_PROTOCOL_MODE 0x16
|
||||
|
||||
// MAP Meta Event Group
|
||||
|
||||
|
@ -9652,6 +9652,34 @@ static inline uint8_t gattservice_subevent_hid_information_get_normally_connecta
|
||||
return event[10];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get field hids_cid from event GATTSERVICE_SUBEVENT_HID_PROTOCOL_MODE
|
||||
* @param event packet
|
||||
* @return hids_cid
|
||||
* @note: btstack_type 2
|
||||
*/
|
||||
static inline uint16_t gattservice_subevent_hid_protocol_mode_get_hids_cid(const uint8_t * event){
|
||||
return little_endian_read_16(event, 3);
|
||||
}
|
||||
/**
|
||||
* @brief Get field service_index from event GATTSERVICE_SUBEVENT_HID_PROTOCOL_MODE
|
||||
* @param event packet
|
||||
* @return service_index
|
||||
* @note: btstack_type 1
|
||||
*/
|
||||
static inline uint8_t gattservice_subevent_hid_protocol_mode_get_service_index(const uint8_t * event){
|
||||
return event[5];
|
||||
}
|
||||
/**
|
||||
* @brief Get field protocol_mode from event GATTSERVICE_SUBEVENT_HID_PROTOCOL_MODE
|
||||
* @param event packet
|
||||
* @return protocol_mode
|
||||
* @note: btstack_type 1
|
||||
*/
|
||||
static inline uint8_t gattservice_subevent_hid_protocol_mode_get_protocol_mode(const uint8_t * event){
|
||||
return event[6];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get field map_cid from event MAP_SUBEVENT_CONNECTION_OPENED
|
||||
* @param event packet
|
||||
|
@ -19,3 +19,16 @@ HOGP/RH/HGDC/BV-15-I: b, saerch for 'Battery Level Client Characteristic Configu
|
||||
HOGP/RH/HGDC/BV-16-I: d
|
||||
|
||||
HOGP/RH/HGRF/BV-01-I: h
|
||||
HOGP/RH/HGRF/BV-02-I: h
|
||||
HOGP/RH/HGRF/BV-03-I: h, 1, 4, (confirmation)
|
||||
HOGP/RH/HGRF/BV-04-I: h, 1, 4, (confirmation)
|
||||
HOGP/RH/HGRF/BV-05-I: h, (confirmation)
|
||||
HOGP/RH/HGRF/BV-19-I: h, 2, 5, (confirmation)
|
||||
HOGP/RH/HGRF/BV-06-I: h, (confirmation)
|
||||
HOGP/RH/HGRF/BV-07-I: h, 3, 6
|
||||
HOGP/RH/HGRF/BV-08-I: h, (confirmation)
|
||||
HOGP/RH/HGRF/BV-09-I: h, i, j, (confirmation)
|
||||
HOGP/RH/HGRF/BV-10-I: b, k
|
||||
HOGP/RH/HGRF/BV-11-I: b
|
||||
HOGP/RH/HGRF/BV-12-I: d
|
||||
HOGP/RH/HGRF/BV-18-I: h
|
@ -413,6 +413,14 @@ static void hid_service_gatt_client_event_handler(uint8_t packet_type, uint16_t
|
||||
gattservice_subevent_hid_information_get_remote_wake(packet),
|
||||
gattservice_subevent_hid_information_get_normally_connectable(packet));
|
||||
break;
|
||||
|
||||
case GATTSERVICE_SUBEVENT_HID_PROTOCOL_MODE:
|
||||
printf("Protocol Mode: service index %d, mode 0x%02X (Boot mode: 0x%02X, Report mode 0x%02X)\n",
|
||||
gattservice_subevent_hid_protocol_mode_get_service_index(packet),
|
||||
gattservice_subevent_hid_protocol_mode_get_protocol_mode(packet),
|
||||
HID_PROTOCOL_MODE_BOOT,HID_PROTOCOL_MODE_REPORT);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -429,6 +437,16 @@ static void device_information_service_gatt_client_event_handler(uint8_t packet_
|
||||
}
|
||||
uint8_t status;
|
||||
switch (hci_event_gattservice_meta_get_subevent_code(packet)){
|
||||
|
||||
case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_PNP_ID:
|
||||
printf("PnP ID: vendor source ID 0x%02X, vendor ID 0x%02X, product ID 0x%02X, product version 0x%02X\n",
|
||||
gattservice_subevent_device_information_pnp_id_get_vendor_source_id(packet),
|
||||
gattservice_subevent_device_information_pnp_id_get_vendor_id(packet),
|
||||
gattservice_subevent_device_information_pnp_id_get_product_id(packet),
|
||||
gattservice_subevent_device_information_pnp_id_get_product_version(packet)
|
||||
);
|
||||
break;
|
||||
|
||||
case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_DONE:
|
||||
status = gattservice_subevent_device_information_done_get_att_status(packet);
|
||||
switch (status){
|
||||
@ -503,14 +521,24 @@ static void show_usage(void){
|
||||
bd_addr_t iut_address;
|
||||
gap_local_bd_addr(iut_address);
|
||||
printf("\n--- Bluetooth HOG Host Test Console %s ---\n", bd_addr_to_str(iut_address));
|
||||
printf("c - connect to remote device\n");
|
||||
printf("C - disconnect from remote device\n");
|
||||
|
||||
printf("h - connect to HID Service client\n");
|
||||
printf("b - connect to Battery Service Client\n");
|
||||
printf("d - connect to Device Information Service Client\n");
|
||||
|
||||
|
||||
printf("c - Connect to remote device\n");
|
||||
printf("C - Disconnect from remote device\n");
|
||||
printf("h - Connect to HID Service Client\n");
|
||||
printf("b - Connect to Battery Service\n");
|
||||
printf("d - Connect to Device Information Service\n");
|
||||
printf("\n");
|
||||
printf("p - Get protocol mode for service 0\n");
|
||||
printf("q - Get protocol mode for service 1\n");
|
||||
printf("i - Get HID information for service index 0\n");
|
||||
printf("j - Get HID information for service index 1\n");
|
||||
printf("k - Get Battery Level for service index 0\n");
|
||||
printf("1 - Get report with ID 1\n");
|
||||
printf("2 - Get report with ID 2\n");
|
||||
printf("3 - Get report with ID 3\n");
|
||||
printf("4 - Get report with ID 4\n");
|
||||
printf("5 - Get report with ID 5\n");
|
||||
printf("6 - Get report with ID 6\n");
|
||||
printf("\n");
|
||||
printf("Ctrl-c - exit\n");
|
||||
printf("---\n");
|
||||
}
|
||||
@ -565,6 +593,15 @@ static void stdin_process(char character){
|
||||
hog_host_connect_device_information_client();
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
printf("Get protocol mode for service 0\n");
|
||||
hids_client_get_protocol_mode(hids_cid, 0);
|
||||
break;
|
||||
case 'q':
|
||||
printf("Get protocol mode for service 1\n");
|
||||
hids_client_get_protocol_mode(hids_cid, 1);
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
query_service_index = 0;
|
||||
printf("Get HID information for service index %d\n", query_service_index);
|
||||
@ -581,7 +618,7 @@ static void stdin_process(char character){
|
||||
printf("Read Battery Level for service index 0\n");
|
||||
battery_service_client_read_battery_level(battery_service_cid, 0);
|
||||
break;
|
||||
|
||||
|
||||
case '1':
|
||||
printf("Get report with ID 1\n");
|
||||
hids_client_send_get_report(hids_cid, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user