linux-user: Use do_munmap for target_mmap failure
[qemu/kevin.git] / hw / usb / u2f.h
blob8bff13141af1a0ea9b7904074eada18fae8c1753
1 /*
2 * U2F USB device.
4 * Copyright (c) 2020 César Belley <cesar.belley@lse.epita.fr>
5 * Written by César Belley <cesar.belley@lse.epita.fr>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
26 #ifndef U2F_H
27 #define U2F_H
29 #include "hw/qdev-core.h"
31 #define U2FHID_PACKET_SIZE 64
32 #define U2FHID_PENDING_IN_NUM 32
34 typedef struct U2FKeyInfo U2FKeyInfo;
36 #define TYPE_U2F_KEY "u2f-key"
37 OBJECT_DECLARE_TYPE(U2FKeyState, U2FKeyClass, U2F_KEY)
40 * Callbacks to be used by the U2F key base device (i.e. hw/u2f.c)
41 * to interact with its variants (i.e. hw/u2f-*.c)
43 struct U2FKeyClass {
44 /*< private >*/
45 USBDeviceClass parent_class;
47 /*< public >*/
48 void (*recv_from_guest)(U2FKeyState *key,
49 const uint8_t packet[U2FHID_PACKET_SIZE]);
50 void (*realize)(U2FKeyState *key, Error **errp);
51 void (*unrealize)(U2FKeyState *key);
55 * State of the U2F key base device (i.e. hw/u2f.c)
57 struct U2FKeyState {
58 USBDevice dev;
59 USBEndpoint *ep;
60 uint8_t idle;
62 /* Pending packets to be send to the guest */
63 uint8_t pending_in[U2FHID_PENDING_IN_NUM][U2FHID_PACKET_SIZE];
64 uint8_t pending_in_start;
65 uint8_t pending_in_end;
66 uint8_t pending_in_num;
70 * API to be used by the U2F key device variants (i.e. hw/u2f-*.c)
71 * to interact with the U2F key base device (i.e. hw/u2f.c)
73 void u2f_send_to_guest(U2FKeyState *key,
74 const uint8_t packet[U2FHID_PACKET_SIZE]);
76 extern const VMStateDescription vmstate_u2f_key;
78 #define VMSTATE_U2F_KEY(_field, _state) { \
79 .name = (stringify(_field)), \
80 .size = sizeof(U2FKeyState), \
81 .vmsd = &vmstate_u2f_key, \
82 .flags = VMS_STRUCT, \
83 .offset = vmstate_offset_value(_state, _field, U2FKeyState), \
86 #endif /* U2F_H */