2 * Copyright (c) 2018 Yubico AB. All rights reserved.
3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file.
5 * SPDX-License-Identifier: BSD-2-Clause
11 get_key_len(uint8_t tag, uint8_t *key, size_t *key_len)
14 if ((*key & 0xf0) == 0xf0) {
15 fido_log_debug("%s: *key=0x%02x", __func__, *key);
28 get_key_val(const void *body, size_t key_len, uint32_t *val)
30 const uint8_t *ptr = body;
40 *val = (uint32_t)((ptr[1] << 8) | ptr[0]);
43 fido_log_debug("%s: key_len=%zu", __func__, key_len);
51 fido_hid_get_usage(const uint8_t *report_ptr, size_t report_len,
54 const uint8_t *ptr = report_ptr;
55 size_t len = report_len;
58 const uint8_t tag = ptr[0];
66 if (get_key_len(tag, &key, &key_len) < 0 || key_len > len ||
67 get_key_val(ptr, key_len, &key_val) < 0) {
72 *usage_page = key_val;
83 fido_hid_get_report_len(const uint8_t *report_ptr, size_t report_len,
84 size_t *report_in_len, size_t *report_out_len)
86 const uint8_t *ptr = report_ptr;
87 size_t len = report_len;
88 uint32_t report_size = 0;
91 const uint8_t tag = ptr[0];
99 if (get_key_len(tag, &key, &key_len) < 0 || key_len > len ||
100 get_key_val(ptr, key_len, &key_val) < 0) {
105 report_size = key_val;
106 } else if (key == 0x80) {
107 *report_in_len = (size_t)report_size;
108 } else if (key == 0x90) {
109 *report_out_len = (size_t)report_size;
120 fido_dev_info_new(size_t n)
122 return (calloc(n, sizeof(fido_dev_info_t)));
126 fido_dev_info_reset(fido_dev_info_t *di)
129 free(di->manufacturer);
131 memset(di, 0, sizeof(*di));
135 fido_dev_info_free(fido_dev_info_t **devlist_p, size_t n)
137 fido_dev_info_t *devlist;
139 if (devlist_p == NULL || (devlist = *devlist_p) == NULL)
142 for (size_t i = 0; i < n; i++)
143 fido_dev_info_reset(&devlist[i]);
150 const fido_dev_info_t *
151 fido_dev_info_ptr(const fido_dev_info_t *devlist, size_t i)
153 return (&devlist[i]);
157 fido_dev_info_set(fido_dev_info_t *devlist, size_t i,
158 const char *path, const char *manufacturer, const char *product,
159 const fido_dev_io_t *io, const fido_dev_transport_t *transport)
161 char *path_copy = NULL, *manu_copy = NULL, *prod_copy = NULL;
164 if (path == NULL || manufacturer == NULL || product == NULL ||
166 r = FIDO_ERR_INVALID_ARGUMENT;
170 if ((path_copy = strdup(path)) == NULL ||
171 (manu_copy = strdup(manufacturer)) == NULL ||
172 (prod_copy = strdup(product)) == NULL) {
173 r = FIDO_ERR_INTERNAL;
177 fido_dev_info_reset(&devlist[i]);
178 devlist[i].path = path_copy;
179 devlist[i].manufacturer = manu_copy;
180 devlist[i].product = prod_copy;
183 devlist[i].transport = *transport;
195 fido_dev_info_path(const fido_dev_info_t *di)
201 fido_dev_info_vendor(const fido_dev_info_t *di)
203 return (di->vendor_id);
207 fido_dev_info_product(const fido_dev_info_t *di)
209 return (di->product_id);
213 fido_dev_info_manufacturer_string(const fido_dev_info_t *di)
215 return (di->manufacturer);
219 fido_dev_info_product_string(const fido_dev_info_t *di)
221 return (di->product);