hid_device: provide SDP record params by struct

This commit is contained in:
Milanka Ringwald 2021-04-07 18:38:58 +02:00
parent 37bb4f7b91
commit 80d9d5d49a
6 changed files with 94 additions and 62 deletions

View File

@ -405,11 +405,21 @@ int btstack_main(int argc, const char * argv[]){
uint8_t hid_remote_wake = 1;
uint8_t hid_reconnect_initiate = 1;
uint8_t hid_normally_connectable = 1;
hid_sdp_record_t hid_params = {
// hid sevice subclass 2540 Keyboard, hid counntry code 33 US
0x2540, 33,
hid_virtual_cable, hid_remote_wake,
hid_reconnect_initiate, hid_normally_connectable,
hid_boot_device,
0xFFFF, 0xFFFF, 3200,
hid_descriptor_keyboard_boot_mode,
sizeof(hid_descriptor_keyboard_boot_mode),
hid_device_name
};
// hid sevice subclass 2540 Keyboard, hid counntry code 33 US, hid virtual cable off, hid reconnect initiate off, hid boot device off
hid_create_sdp_record(hid_service_buffer, 0x10001, 0x2540, 33,
hid_virtual_cable, hid_remote_wake, hid_reconnect_initiate, hid_normally_connectable,
hid_boot_device, hid_descriptor_keyboard_boot_mode, sizeof(hid_descriptor_keyboard_boot_mode), hid_device_name);
hid_create_sdp_record(hid_service_buffer, 0x10001, &hid_params);
printf("HID service record size: %u\n", de_get_len( hid_service_buffer));
sdp_register_service(hid_service_buffer);

View File

@ -306,10 +306,20 @@ int btstack_main(int argc, const char * argv[]){
uint8_t hid_reconnect_initiate = 1;
uint8_t hid_normally_connectable = 1;
// hid sevice subclass 2540 Keyboard, hid counntry code 33 US, hid virtual cable off, hid reconnect initiate off, hid boot device off
hid_create_sdp_record(hid_service_buffer, 0x10001, 0x2540, 33,
hid_virtual_cable, hid_remote_wake, hid_reconnect_initiate, hid_normally_connectable,
hid_boot_device, hid_descriptor_mouse_boot_mode, sizeof(hid_descriptor_mouse_boot_mode), hid_device_name);
hid_sdp_record_t hid_params = {
// hid sevice subclass 2580 Mouse, hid counntry code 33 US
0x2580, 33,
hid_virtual_cable, hid_remote_wake,
hid_reconnect_initiate, hid_normally_connectable,
hid_boot_device,
0xFFFF, 0xFFFF, 3200,
hid_descriptor_mouse_boot_mode,
sizeof(hid_descriptor_mouse_boot_mode),
hid_device_name
};
hid_create_sdp_record(hid_service_buffer, 0x10001, &hid_params);
printf("SDP service record size: %u\n", de_get_len( hid_service_buffer));
sdp_register_service(hid_service_buffer);

View File

@ -155,19 +155,7 @@ static hid_device_t * hid_device_create_instance(void){
return &_hid_device;
}
void hid_create_sdp_record(
uint8_t *service,
uint32_t service_record_handle,
uint16_t hid_device_subclass,
uint8_t hid_country_code,
uint8_t hid_virtual_cable,
uint8_t hid_remote_wake,
uint8_t hid_reconnect_initiate,
bool hid_normally_connectable,
bool hid_boot_device,
const uint8_t * descriptor, uint16_t descriptor_size,
const char *device_name){
void hid_create_sdp_record(uint8_t *service, uint32_t service_record_handle, const hid_sdp_record_t * params){
uint8_t * attribute;
de_create_sequence(service);
@ -233,7 +221,7 @@ void hid_create_sdp_record(
// 0x0100 "ServiceName"
de_add_number(service, DE_UINT, DE_SIZE_16, 0x0100);
de_add_data(service, DE_STRING, strlen(device_name), (uint8_t *) device_name);
de_add_data(service, DE_STRING, strlen(params->device_name), (uint8_t *) params->device_name);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST);
attribute = de_push_sequence(service);
@ -255,19 +243,16 @@ void hid_create_sdp_record(
de_add_number(service, DE_UINT, DE_SIZE_16, 0x0111); // v1.1.1
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_DEVICE_SUBCLASS);
de_add_number(service, DE_UINT, DE_SIZE_8, hid_device_subclass);
de_add_number(service, DE_UINT, DE_SIZE_8, params->hid_device_subclass);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_COUNTRY_CODE);
de_add_number(service, DE_UINT, DE_SIZE_8, hid_country_code);
de_add_number(service, DE_UINT, DE_SIZE_8, params->hid_country_code);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_VIRTUAL_CABLE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_virtual_cable);
de_add_number(service, DE_BOOL, DE_SIZE_8, params->hid_virtual_cable);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_RECONNECT_INITIATE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_reconnect_initiate);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_NORMALLY_CONNECTABLE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_normally_connectable);
de_add_number(service, DE_BOOL, DE_SIZE_8, params->hid_reconnect_initiate);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_DESCRIPTOR_LIST);
attribute = de_push_sequence(service);
@ -275,7 +260,7 @@ void hid_create_sdp_record(
uint8_t* hidDescriptor = de_push_sequence(attribute);
{
de_add_number(hidDescriptor, DE_UINT, DE_SIZE_8, 0x22); // Report Descriptor
de_add_data(hidDescriptor, DE_STRING, descriptor_size, (uint8_t *) descriptor);
de_add_data(hidDescriptor, DE_STRING, params->hid_descriptor_size, (uint8_t *) params->hid_descriptor);
}
de_pop_sequence(attribute, hidDescriptor);
}
@ -294,11 +279,26 @@ void hid_create_sdp_record(
}
de_pop_sequence(service, attribute);
// battery power
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_REMOTE_WAKE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_remote_wake ? 1 : 0);
de_add_number(service, DE_BOOL, DE_SIZE_8, params->hid_remote_wake ? 1 : 0);
// supervision timeout
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_SUPERVISION_TIMEOUT);
de_add_number(service, DE_UINT, DE_SIZE_16, params->hid_supervision_timeout);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_NORMALLY_CONNECTABLE);
de_add_number(service, DE_BOOL, DE_SIZE_8, params->hid_normally_connectable);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_BOOT_DEVICE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_boot_device ? 1 : 0);
de_add_number(service, DE_BOOL, DE_SIZE_8, params->hid_boot_device ? 1 : 0);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HIDSSR_HOST_MAX_LATENCY);
de_add_number(service, DE_UINT, DE_SIZE_16, params->hid_ssr_host_max_latency);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HIDSSR_HOST_MIN_TIMEOUT);
de_add_number(service, DE_UINT, DE_SIZE_16, params->hid_ssr_host_min_timeout);
}
static inline void hid_device_emit_connected_event(hid_device_t * context, uint8_t status){

View File

@ -48,39 +48,34 @@
extern "C" {
#endif
/* API_START */
typedef struct {
uint16_t hid_device_subclass;
uint8_t hid_country_code;
uint8_t hid_virtual_cable;
uint8_t hid_remote_wake;
uint8_t hid_reconnect_initiate;
bool hid_normally_connectable;
bool hid_boot_device;
uint16_t hid_ssr_host_max_latency;
uint16_t hid_ssr_host_min_timeout;
uint16_t hid_supervision_timeout;
const uint8_t * hid_descriptor;
uint16_t hid_descriptor_size;
const char * device_name;
} hid_sdp_record_t;
/**
* @brief Create HID Device SDP service record.
* @param service Empty buffer in which a new service record will be stored.
* @param have_remote_audio_control
* @param service
* @param service_record_handle
* @param hid_device_subclass
* @param hid_country_code
* @param hid_virtual_cable
* @param hid_remote_wake
* @param hid_reconnect_initiate
* @param hid_normally_connectable
* @param hid_boot_device
* @param hid_descriptor
* @param hid_descriptor_size size of hid_descriptor
* @param device_name
* @param params
*/
void hid_create_sdp_record(
uint8_t * service,
uint32_t service_record_handle,
uint16_t hid_device_subclass,
uint8_t hid_country_code,
uint8_t hid_virtual_cable,
uint8_t hid_remote_wake,
uint8_t hid_reconnect_initiate,
bool hid_normally_connectable,
bool hid_boot_device,
const uint8_t * hid_descriptor,
uint16_t hid_descriptor_size,
const char * device_name);
void hid_create_sdp_record(uint8_t * service, uint32_t service_record_handle, const hid_sdp_record_t * params);
/**
* @brief Set up HID Device

View File

@ -133,6 +133,9 @@ static bool hid_boot_device = true;
static bool send_mouse_on_interrupt_channel = false;
static bool send_keyboard_on_interrupt_channel = false;
static uint16_t host_max_latency = 1600;
static uint16_t host_min_timeout = 3200;
#ifdef HAVE_BTSTACK_STDIN
static const char * device_addr_string = "00:1B:DC:08:E2:5C";
#endif
@ -525,10 +528,21 @@ int btstack_main(int argc, const char * argv[]){
virtual_cable_enabled = true;
virtual_cable_unplugged = false;
}
// hid sevice subclass 2540 Keyboard, hid counntry code 33 US, hid virtual cable on, hid reconnect initiate on, hid boot device off
hid_create_sdp_record(hid_service_buffer, 0x10001, 0x2540, 33,
hid_virtual_cable, hid_remote_wake, hid_reconnect_initiate, hid_normally_connectable,
hid_boot_device, hid_descriptor_keyboard_boot_mode, sizeof(hid_descriptor_keyboard_boot_mode), hid_device_name);
hid_sdp_record_t hid_params = {
// hid sevice subclass 2540 Keyboard, hid counntry code 33 US
0x2540, 33,
hid_virtual_cable, hid_remote_wake,
hid_reconnect_initiate, hid_normally_connectable,
hid_boot_device,
host_max_latency, host_min_timeout,
3200,
hid_descriptor_keyboard_boot_mode,
sizeof(hid_descriptor_keyboard_boot_mode),
hid_device_name
};
hid_create_sdp_record(hid_service_buffer, 0x10001, &hid_params);
printf("HID service record size: %u\n", de_get_len( hid_service_buffer));
sdp_register_service(hid_service_buffer);

View File

@ -203,7 +203,7 @@ TEST(SDPRecordBuilder, AVRCP_CONTROLLER){
// hid_device.h
//
#define HID_DEVICE_RECORD_SIZE_MIN 169
#define HID_DEVICE_RECORD_SIZE_MIN 187
static uint16_t hid_device_record_size(uint16_t descriptor_size, const char * name){
return HID_DEVICE_RECORD_SIZE_MIN + descriptor_size + strlen(name);
@ -217,7 +217,10 @@ TEST(SDPRecordBuilder, HID_DEVICE){
name = "";
descriptor_size = 0;
expected_len = hid_device_record_size(descriptor_size, name);
hid_create_sdp_record(service_buffer, 0x0001, 0, 0, 0, 0, 0, 0, 0, NULL, descriptor_size, name);
hid_sdp_record_t hid_params = {0, 0, 0, 0, 0, false, false, 0xFFFF, 0xFFFF, 3200, NULL, descriptor_size, name};
hid_create_sdp_record(service_buffer, 0x0001, &hid_params);
CHECK_EQUAL(de_get_len(service_buffer), expected_len);
}