target/i386: Constify VMState in machine.c
[qemu/kevin.git] / hw / usb / canokey.h
blobe528889d332572104910bfb3cd36cefb76d89872
1 /*
2 * CanoKey QEMU device header.
4 * Copyright (c) 2021-2022 Canokeys.org <contact@canokeys.org>
5 * Written by Hongren (Zenithal) Zheng <i@zenithal.me>
7 * This code is licensed under the GPL v2 or later.
8 */
10 #ifndef CANOKEY_H
11 #define CANOKEY_H
13 #include "hw/qdev-core.h"
15 #define TYPE_CANOKEY "canokey"
16 #define CANOKEY(obj) \
17 OBJECT_CHECK(CanoKeyState, (obj), TYPE_CANOKEY)
20 * State of Canokey (i.e. hw/canokey.c)
23 /* CTRL INTR BULK */
24 #define CANOKEY_EP_NUM 3
25 /* BULK/INTR IN can be up to 1352 bytes, e.g. get key info */
26 #define CANOKEY_EP_IN_BUFFER_SIZE 2048
27 /* BULK OUT can be up to 270 bytes, e.g. PIV import cert */
28 #define CANOKEY_EP_OUT_BUFFER_SIZE 512
30 typedef enum {
31 CANOKEY_EP_IN_WAIT,
32 CANOKEY_EP_IN_READY,
33 CANOKEY_EP_IN_STALL
34 } CanoKeyEPState;
36 typedef struct CanoKeyState {
37 USBDevice dev;
39 /* IN packets from canokey device loop */
40 uint8_t ep_in[CANOKEY_EP_NUM][CANOKEY_EP_IN_BUFFER_SIZE];
42 * See canokey_emu_transmit
44 * For large INTR IN, receive multiple data from canokey device loop
45 * in this case ep_in_size would increase with every call
47 uint32_t ep_in_size[CANOKEY_EP_NUM];
49 * Used in canokey_handle_data
50 * for IN larger than p->iov.size, we would do multiple handle_data()
52 * The difference between ep_in_pos and ep_in_size:
53 * We first increase ep_in_size to fill ep_in buffer in device_loop,
54 * then use ep_in_pos to submit data from ep_in buffer in handle_data
56 uint32_t ep_in_pos[CANOKEY_EP_NUM];
57 CanoKeyEPState ep_in_state[CANOKEY_EP_NUM];
59 /* OUT pointer to canokey recv buffer */
60 uint8_t *ep_out[CANOKEY_EP_NUM];
61 uint32_t ep_out_size[CANOKEY_EP_NUM];
62 /* For large BULK OUT, multiple write to ep_out is needed */
63 uint8_t ep_out_buffer[CANOKEY_EP_NUM][CANOKEY_EP_OUT_BUFFER_SIZE];
65 /* Properties */
66 char *file; /* canokey-file */
67 } CanoKeyState;
69 #endif /* CANOKEY_H */