1 /* 2 * CanoKey QEMU device header. 3 * 4 * Copyright (c) 2021-2022 Canokeys.org <contact@canokeys.org> 5 * Written by Hongren (Zenithal) Zheng <i@zenithal.me> 6 * 7 * This code is licensed under the GPL v2 or later. 8 */ 9 10 #ifndef CANOKEY_H 11 #define CANOKEY_H 12 13 #include "hw/qdev-core.h" 14 15 #define TYPE_CANOKEY "canokey" 16 #define CANOKEY(obj) \ 17 OBJECT_CHECK(CanoKeyState, (obj), TYPE_CANOKEY) 18 19 /* 20 * State of Canokey (i.e. hw/canokey.c) 21 */ 22 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 28 typedef enum { 29 CANOKEY_EP_IN_WAIT, 30 CANOKEY_EP_IN_READY, 31 CANOKEY_EP_IN_STALL 32 } CanoKeyEPState; 33 34 typedef struct CanoKeyState { 35 USBDevice dev; 36 37 /* IN packets from canokey device loop */ 38 uint8_t ep_in[CANOKEY_EP_NUM][CANOKEY_EP_IN_BUFFER_SIZE]; 39 /* 40 * See canokey_emu_transmit 41 * 42 * For large INTR IN, receive multiple data from canokey device loop 43 * in this case ep_in_size would increase with every call 44 */ 45 uint32_t ep_in_size[CANOKEY_EP_NUM]; 46 /* 47 * Used in canokey_handle_data 48 * for IN larger than p->iov.size, we would do multiple handle_data() 49 * 50 * The difference between ep_in_pos and ep_in_size: 51 * We first increase ep_in_size to fill ep_in buffer in device_loop, 52 * then use ep_in_pos to submit data from ep_in buffer in handle_data 53 */ 54 uint32_t ep_in_pos[CANOKEY_EP_NUM]; 55 CanoKeyEPState ep_in_state[CANOKEY_EP_NUM]; 56 57 /* OUT pointer to canokey recv buffer */ 58 uint8_t *ep_out[CANOKEY_EP_NUM]; 59 uint32_t ep_out_size[CANOKEY_EP_NUM]; 60 61 /* Properties */ 62 char *file; /* canokey-file */ 63 } CanoKeyState; 64 65 #endif /* CANOKEY_H */ 66