From: David Bouman <dbouman03@gmail.com>
To: qemu-devel@nongnu.org
Cc: David Bouman <dbouman03@gmail.com>
Subject: [PATCH 1/4] hw/usb/u2f: Add `start` and `stop` callbacks to U2F key class
Date: Tue, 25 Jun 2024 16:53:47 +0200 [thread overview]
Message-ID: <20240625145350.65978-2-dbouman03@gmail.com> (raw)
In-Reply-To: <20240625145350.65978-1-dbouman03@gmail.com>
Preparation for improved u2f-passthru hidraw handle lifetimes:
These callbacks can be implemented by the backing implementation,
i.e. u2f-passthru or u2f-emulated.
The start callback is invoked when the device receives an INTR IN, and
the stop callback is invoked when the endpoint has been unlinked/stopped.
For a Linux guest, the start callback corresponds to the `hid_hw_open` and
`hid_hw_close` routines, invoked whenever the first user opens, respectively
the last user closes the emulated hidraw device.
Signed-off-by: David Bouman <dbouman03@gmail.com>
---
hw/usb/u2f.c | 23 +++++++++++++++++++++++
hw/usb/u2f.h | 5 +++++
2 files changed, 28 insertions(+)
diff --git a/hw/usb/u2f.c b/hw/usb/u2f.c
index 1fb59cf404..cc1abd6c7d 100644
--- a/hw/usb/u2f.c
+++ b/hw/usb/u2f.c
@@ -253,6 +253,12 @@ static void u2f_key_handle_data(USBDevice *dev, USBPacket *p)
case USB_TOKEN_IN:
packet_in = u2f_pending_in_get(key);
if (packet_in == NULL) {
+ U2FKeyClass *kc = U2F_KEY_GET_CLASS(key);
+
+ /* An early INTR IN is sent to kick the device. */
+ if (!key->started) {
+ key->started = (kc->start ? kc->start(key) : true);
+ }
p->status = USB_RET_NAK;
return;
}
@@ -317,6 +323,21 @@ const VMStateDescription vmstate_u2f_key = {
}
};
+static void u2f_ep_stopped(USBDevice *dev, USBEndpoint *ep)
+{
+ U2FKeyState *key = U2F_KEY(dev);
+ U2FKeyClass *kc = U2F_KEY_GET_CLASS(key);
+
+ if (!key->started) {
+ return;
+ }
+ if (kc->stop) {
+ kc->stop(key);
+ }
+ key->started = false;
+}
+
+
static void u2f_key_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
@@ -332,6 +353,8 @@ static void u2f_key_class_init(ObjectClass *klass, void *data)
uc->unrealize = u2f_key_unrealize;
dc->desc = "QEMU U2F key";
dc->vmsd = &vmstate_u2f_key;
+
+ uc->ep_stopped = u2f_ep_stopped;
}
static const TypeInfo u2f_key_info = {
diff --git a/hw/usb/u2f.h b/hw/usb/u2f.h
index 8bff13141a..56d989c783 100644
--- a/hw/usb/u2f.h
+++ b/hw/usb/u2f.h
@@ -49,6 +49,9 @@ struct U2FKeyClass {
const uint8_t packet[U2FHID_PACKET_SIZE]);
void (*realize)(U2FKeyState *key, Error **errp);
void (*unrealize)(U2FKeyState *key);
+
+ bool (*start)(U2FKeyState *key);
+ void (*stop)(U2FKeyState *key);
};
/*
@@ -64,6 +67,8 @@ struct U2FKeyState {
uint8_t pending_in_start;
uint8_t pending_in_end;
uint8_t pending_in_num;
+
+ bool started;
};
/*
--
2.34.1
next prev parent reply other threads:[~2024-06-25 17:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-25 14:53 [PATCH 0/4] hw/usb/u2f-passthru: U2F keepalive fixes David Bouman
2024-06-25 14:53 ` David Bouman [this message]
2024-06-25 14:53 ` [PATCH 2/4] hw/usb/u2f-passthru: Do not needlessly retain handle to hidraw chardev David Bouman
2024-06-25 14:53 ` [PATCH 3/4] hw/usb/u2f-passthru: Clean up code David Bouman
2024-06-25 14:53 ` [PATCH 4/4] hw/usb/u2f-passthru: Implement FIDO U2FHID keep-alive David Bouman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240625145350.65978-2-dbouman03@gmail.com \
--to=dbouman03@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).