From nobody Thu Sep 19 01:08:37 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1719337053; cv=none; d=zohomail.com; s=zohoarc; b=EMlJplBm/FNzHyOAQkGnQC2nh1E7EO2inTTArk+yRkv3jKzaO6XWBUTocCHJSzgGovRCfRfDvXSYtqvNmubLv7UkTSsOR9YoymP9lRb/EMCCVhYzV993Filx0fxH4wwtXo6609db1ZJUSEZt/0ChZ6nLCGBxPfz3isXbv3elhwc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719337053; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gd1bnX5yMsLjKAf/zlmApEfZTYiMqAMKaFxN5Ze85Yc=; b=jm472h7bbxrcHjJxy6DSI3MP2Tx9KJYIwfeFvoYm4fmwpBo9EjHAn3V8UzwTj0jie1Qu9gIeJtfocmlKaroKi1DKbyzL26fdII7OtbZBv70Lle2/LkgTNcuBA2Fl/1pbULNBuqtF9nEvAck9zmHk14c/xO2j9K/61O+G51nvg2o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171933705398279.54793857771938; Tue, 25 Jun 2024 10:37:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM9xC-0001JQ-P8; Tue, 25 Jun 2024 13:27:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sM7Yp-0003cB-Iq for qemu-devel@nongnu.org; Tue, 25 Jun 2024 10:54:19 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM7Yo-0003GF-0U for qemu-devel@nongnu.org; Tue, 25 Jun 2024 10:54:19 -0400 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-57cc1c00b97so5574308a12.0 for ; Tue, 25 Jun 2024 07:54:17 -0700 (PDT) Received: from 41414141.home (84-82-177-210.fixed.kpn.net. [84.82.177.210]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57d3042d421sm6092740a12.42.2024.06.25.07.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 07:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719327255; x=1719932055; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gd1bnX5yMsLjKAf/zlmApEfZTYiMqAMKaFxN5Ze85Yc=; b=i3gBoxlrtqBamK0ytEM0RYFDW1E67Q08WQxMa9FsiHACz4RoB7x60IHfMTOGTHBw97 4iLaAfynHRCzdKjXlIetMfFs8/M0Xv/ur8YACVuCItyGEwxuLFy1gfy3qPhI35w4WDXY Z0N9coGVi5iikR5A2wiNu4Ybq0kFqcZ90Ega4bTsqd47wfwY+KqgfTszhCYi5AAbj/Rn lpiWvVreDolD3YUYmpkEwKCdlFyJAo4qSppCz6Nl13AwMSZW276eCFwOfTj7Nnd4TtLD 8smgBvMmcbiYic9YDppc6y8KTcUwoiekIEz5cBEDUl4sL2SSTxVO4vCJE6ga7HNVq3Fz MBSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719327255; x=1719932055; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gd1bnX5yMsLjKAf/zlmApEfZTYiMqAMKaFxN5Ze85Yc=; b=TienmJYXb+BFYhpTseUSPTnKilWXUySjOict4xfWiDiN8hB5oHmT4qVeQSu5Nx0i1u 8a+HlXOKYPQeoHzZN1mBQHgBzA/C8dvNP2yQpF28S5RLe15pE0OEIy/Rtg5htq8JszyL cc30JZ7ujzepsxB1vuVPcOhTdbqleFnNLE4ps2OqH+LBdFHtpP9Pe47Nq6jj3FUo0+kE CI+lEbi3XzdDH7bxkl+RxHDswJ4zLYAMid/66exmmpl6wx9FdBnM2C+tmqETVemMWyhh QUvcsZq7D23TicdN+Laozu8AC5SRldzFXswxszCxUNP8jEHDptS2FNNjTJMvNmOdrV40 ixBg== X-Gm-Message-State: AOJu0Yz/pQlGDmLq10s7RRmjGX0oV9hfYjze4BrpYdHkL0NySG4a6nTU 3aERC0xlARZIsPfRyTXYKWLjddHEyFUbIrEfah9FvecUox5cusdn4OSbbQ== X-Google-Smtp-Source: AGHT+IGqX5yA+0k3VJ5/KXQ+ampjX9TzFY8KWbpglDZmONHaMBeigDL/BjTd77zUURHG4QynOlWREA== X-Received: by 2002:a50:aa96:0:b0:57d:788:aaae with SMTP id 4fb4d7f45d1cf-57d4bddfabamr6098598a12.35.1719327255483; Tue, 25 Jun 2024 07:54:15 -0700 (PDT) From: David Bouman To: qemu-devel@nongnu.org Cc: David Bouman 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 Message-Id: <20240625145350.65978-2-dbouman03@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240625145350.65978-1-dbouman03@gmail.com> References: <20240625145350.65978-1-dbouman03@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=dbouman03@gmail.com; helo=mail-ed1-x534.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 25 Jun 2024 13:25:46 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1719337055404100001 Content-Type: text/plain; charset="utf-8" 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 --- 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, USBPac= ket *p) case USB_TOKEN_IN: packet_in =3D u2f_pending_in_get(key); if (packet_in =3D=3D NULL) { + U2FKeyClass *kc =3D U2F_KEY_GET_CLASS(key); + + /* An early INTR IN is sent to kick the device. */ + if (!key->started) { + key->started =3D (kc->start ? kc->start(key) : true); + } p->status =3D USB_RET_NAK; return; } @@ -317,6 +323,21 @@ const VMStateDescription vmstate_u2f_key =3D { } }; =20 +static void u2f_ep_stopped(USBDevice *dev, USBEndpoint *ep) +{ + U2FKeyState *key =3D U2F_KEY(dev); + U2FKeyClass *kc =3D U2F_KEY_GET_CLASS(key); + + if (!key->started) { + return; + } + if (kc->stop) { + kc->stop(key); + } + key->started =3D false; +} + + static void u2f_key_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -332,6 +353,8 @@ static void u2f_key_class_init(ObjectClass *klass, void= *data) uc->unrealize =3D u2f_key_unrealize; dc->desc =3D "QEMU U2F key"; dc->vmsd =3D &vmstate_u2f_key; + + uc->ep_stopped =3D u2f_ep_stopped; } =20 static const TypeInfo u2f_key_info =3D { 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); }; =20 /* @@ -64,6 +67,8 @@ struct U2FKeyState { uint8_t pending_in_start; uint8_t pending_in_end; uint8_t pending_in_num; + + bool started; }; =20 /* --=20 2.34.1