* Gets the size of the HID item at the given position * Returns 1 if successful, 0 if an invalid key * Sets data_len and key_size when successful */
| 193 | * Sets data_len and key_size when successful |
| 194 | */ |
| 195 | static int get_hid_item_size(__u8 *report_descriptor, unsigned int pos, __u32 size, int *data_len, int *key_size) |
| 196 | { |
| 197 | int key = report_descriptor[pos]; |
| 198 | int size_code; |
| 199 | |
| 200 | /* |
| 201 | * This is a Long Item. The next byte contains the |
| 202 | * length of the data section (value) for this key. |
| 203 | * See the HID specification, version 1.11, section |
| 204 | * 6.2.2.3, titled "Long Items." |
| 205 | */ |
| 206 | if ((key & 0xf0) == 0xf0) { |
| 207 | if (pos + 1 < size) |
| 208 | { |
| 209 | *data_len = report_descriptor[pos + 1]; |
| 210 | *key_size = 3; |
| 211 | return 1; |
| 212 | } |
| 213 | *data_len = 0; /* malformed report */ |
| 214 | *key_size = 0; |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | * This is a Short Item. The bottom two bits of the |
| 219 | * key contain the size code for the data section |
| 220 | * (value) for this key. Refer to the HID |
| 221 | * specification, version 1.11, section 6.2.2.2, |
| 222 | * titled "Short Items." |
| 223 | */ |
| 224 | size_code = key & 0x3; |
| 225 | switch (size_code) { |
| 226 | case 0: |
| 227 | case 1: |
| 228 | case 2: |
| 229 | *data_len = size_code; |
| 230 | *key_size = 1; |
| 231 | return 1; |
| 232 | case 3: |
| 233 | *data_len = 4; |
| 234 | *key_size = 1; |
| 235 | return 1; |
| 236 | default: |
| 237 | /* Can't ever happen since size_code is & 0x3 */ |
| 238 | *data_len = 0; |
| 239 | *key_size = 0; |
| 240 | break; |
| 241 | }; |
| 242 | |
| 243 | /* malformed report */ |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * Get bytes from a HID Report Descriptor. |
no outgoing calls
no test coverage detected