mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-01 01:13:23 +00:00
btstack_hid_parser: return if btstack_hid_parse_descriptor_item was sucessful
This commit is contained in:
parent
d7bfc7cd40
commit
76fa2448e1
@ -147,12 +147,12 @@ static void hid_pretty_print_item(btstack_hid_parser_t * parser, hid_descriptor_
|
||||
}
|
||||
|
||||
// parse descriptor item and read up to 32-bit bit value
|
||||
void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8_t * hid_descriptor, uint16_t hid_descriptor_len){
|
||||
bool btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8_t * hid_descriptor, uint16_t hid_descriptor_len){
|
||||
|
||||
const int hid_item_sizes[] = { 0, 1, 2, 4 };
|
||||
|
||||
// parse item header
|
||||
if (hid_descriptor_len < 1u) return;
|
||||
if (hid_descriptor_len < 1u) return false;
|
||||
uint16_t pos = 0;
|
||||
uint8_t item_header = hid_descriptor[pos++];
|
||||
item->data_size = hid_item_sizes[item_header & 0x03u];
|
||||
@ -160,7 +160,7 @@ void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8
|
||||
item->item_tag = (item_header & 0xf0u) >> 4u;
|
||||
// long item
|
||||
if ((item->data_size == 2u) && (item->item_tag == 0x0fu) && (item->item_type == 3u)){
|
||||
if (hid_descriptor_len < 3u) return;
|
||||
if (hid_descriptor_len < 3u) return false;
|
||||
item->data_size = hid_descriptor[pos++];
|
||||
item->item_tag = hid_descriptor[pos++];
|
||||
}
|
||||
@ -168,8 +168,8 @@ void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8
|
||||
item->item_value = 0;
|
||||
|
||||
// read item value
|
||||
if (hid_descriptor_len < item->item_size) return;
|
||||
if (item->data_size > 4u) return;
|
||||
if (hid_descriptor_len < item->item_size) return false;
|
||||
if (item->data_size > 4u) return false;
|
||||
int i;
|
||||
int sgnd = (item->item_type == Global) && (item->item_tag > 0u) && (item->item_tag < 5u);
|
||||
int32_t value = 0;
|
||||
@ -184,6 +184,7 @@ void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8
|
||||
}
|
||||
}
|
||||
item->item_value = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void btstack_hid_handle_global_item(btstack_hid_parser_t * parser, hid_descriptor_item_t * item){
|
||||
|
@ -184,8 +184,9 @@ void btstack_hid_parser_get_field(btstack_hid_parser_t * parser, uint16_t * usag
|
||||
* @param item
|
||||
* @param hid_descriptor
|
||||
* @param hid_descriptor_len
|
||||
* @return true if item has been parsed successfully
|
||||
*/
|
||||
void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8_t * hid_descriptor, uint16_t hid_descriptor_len);
|
||||
bool btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8_t * hid_descriptor, uint16_t hid_descriptor_len);
|
||||
|
||||
/**
|
||||
* @brief Parses descriptor and returns report size for given report ID and report type
|
||||
|
Loading…
x
Reference in New Issue
Block a user