From nobody Fri May 17 03:54:29 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599847785; cv=none; d=zohomail.com; s=zohoarc; b=UqTi4vtNIItpysJ8EfwkTCscqAIj9unF3Qj4kn55ZKueLBDja8WWZgbE7NncsOt3qvRZSI5w1EWDmZ9izyD9EATQz6OoZL1InMDh4+WvTk7Defko8sBKVH6v9e0uJrQOduLT+bUhN+/wrqOOw4TNgwKMZwC+yjpJeWvTb2ZTcWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599847785; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Subject:To; bh=54qs5SzNA4IK8apF26BHLQSOgoj+kDk7kWhGzxcha1A=; b=aPTNePDL94fSuYIhQV1jIw62uUMrxuGlsFDCjBnaM53wzMTg3ujXuft+UYCHvNTJfL+6IG/de1Ww+CHFGf3HRfgS1GqHrQZNRBSmlqsT4r7D3pZPYSJUNzN0vpWcdt3TEUSc/GM9M36pEU+tFGXoieMq7pKl6jn1y5E5CuA5DnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1599847785921564.2334773397208; Fri, 11 Sep 2020 11:09:45 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 6194510C006B; Fri, 11 Sep 2020 18:09:41 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id C59BB10C0050 for ; Fri, 11 Sep 2020 18:09:23 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Fri, 11 Sep 2020 11:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=U560HRbmA0PxVb7MHrYRckP+VzNafA78O3ORv+4oGMA=; b=bqKMjw8/1AtxS9eMvOPdXiLDH8GZ/dYBCReL+j+g/gM5g6Tk5KGtJS3CD2YktwUbkw 6LP1godfroyT0n1MBDcwM9PybQleyka1k393tB0RBfO7iO5NdNOqcPXdz7/ADG5Z2yP3 +IYlDBYl4iBM9RUl2TV8xG0hSUDmcsaO4twbZ0Vh5477n89kXFgXoJH/r/xp/UODEzuG kzX2LG3Na/REapjLN5uRj2+/th8JvuzwAdqJG8JK59+D1C7UI+cPAwKcM+isepcVW6rw iatWpDmqmGDXQmJvF9lIKawGvW8joGPcrG8ZOCb/8eDJf0nwWmqMbNnq28ZF6R+h6jxv cFPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=U560HRbmA0PxVb7MHrYRckP+VzNafA78O3ORv+4oGMA=; b=Llg61vVdlttgBB4+RrskswJyMZINjvSKezzQW1GKt848PYZ1v81vkd6P095d0zvIKx ojApS4DkXJJRrVVsLLYzHiN5foJIsb/yd6uCEYplUm9EhE1eZgu9vwHxlhfgCrGaJUGV J8bnJ5wTqt5F3eyJhbaIC/NHxa5NhO1plRBNjr6cGHEpFNsETMf93YEZLf9whUFHC6vN FLEJno6+53redqIQOzNPpA6wcOz0OOzTzvONPFcWRaP4eRoSpDqHrBVFnRAuPwuryYYI cevPvNQAVLmWhrscwv7f6w0aqO74NXLTNCZdwvqscmsjAKLr6W6XrvYScSZmr8Udxiru 2f0g== X-Gm-Message-State: AOAM532rDB5+2P0ImcFgaDObyTOPR2l/8h92HjJJjqKuyq8LPlK4PlZl wMX1JPefo+x0DEIzc/4I8FCBS/0m+XmwVI75kVpeHZyDCYD+qA== X-Google-Smtp-Source: ABdhPJyWUSw5Nk+aLvYlZJ6Iq10YeYQmeg1yAhSah6Ja2mPcqeLJlMasJTOd2nm7H8J2OiM1r7AgwL0hGS/uTLM2NO0= X-Received: by 2002:adf:a1d6:: with SMTP id v22mr3320924wrv.185.1599847762751; Fri, 11 Sep 2020 11:09:22 -0700 (PDT) MIME-Version: 1.0 From: Matt DeVillier Date: Fri, 11 Sep 2020 13:09:11 -0500 Message-ID: To: seabios Message-ID-Hash: RMZJDMQL3QAZH5I7NX5AA5QCXCF3AGSP X-Message-ID-Hash: RMZJDMQL3QAZH5I7NX5AA5QCXCF3AGSP X-MailFrom: matt.devillier@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.3.2b1 Precedence: list Subject: [SeaBIOS] [SEABIOS] [PATCH] usb.c: Fix devices using non-primary interface descriptor List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: --- X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From 38f63fcd9b646d6a4eac30f0476bbaee611211ce Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Fri, 11 Sep 2020 12:54:21 -0500 Subject: [PATCH] usb.c: Fix devices using non-primary interface descriptor A fair number of USB devices (keyboards in particular) use an interface descriptor other than the first available, making them non-functional currently. To correct this, iterate through all available interface descriptors until one with the correct class/subclass is found, then proceed to set the configuration and setup the driver. Tested on an ultimate hacking keyboard (UHK 60) Signed-off-by: Matt DeVillier --- src/hw/usb.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/hw/usb.c b/src/hw/usb.c index 4f9a852..38a866a 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -248,14 +248,14 @@ get_device_config(struct usb_pipe *pipe) if (ret) return NULL; - void *config =3D malloc_tmphigh(cfg.wTotalLength); + struct usb_config_descriptor *config =3D malloc_tmphigh(cfg.wTotalLeng= th); if (!config) { warn_noalloc(); return NULL; } req.wLength =3D cfg.wTotalLength; ret =3D usb_send_default_control(pipe, &req, config); - if (ret) { + if (ret || config->wTotalLength !=3D cfg.wTotalLength) { free(config); return NULL; } @@ -367,13 +367,24 @@ configure_usb_device(struct usbdevice_s *usbdev) return 0; // Determine if a driver exists for this device - only look at the - // first interface of the first configuration. + // interfaces of the first configuration. + int num_iface =3D config->bNumInterfaces; + void *config_end =3D (void*)config + config->wTotalLength; struct usb_interface_descriptor *iface =3D (void*)(&config[1]); - if (iface->bInterfaceClass !=3D USB_CLASS_HID - && iface->bInterfaceClass !=3D USB_CLASS_MASS_STORAGE - && iface->bInterfaceClass !=3D USB_CLASS_HUB) - // Not a supported device. - goto fail; + for (;;) { + if (!num_iface-- || (void*)iface + iface->bLength > config_end) + // Not a supported device. + goto fail; + if (iface->bDescriptorType =3D=3D USB_DT_INTERFACE + && (iface->bInterfaceClass =3D=3D USB_CLASS_HUB + || (iface->bInterfaceClass =3D=3D USB_CLASS_MASS_STORAGE + && (iface->bInterfaceProtocol =3D=3D US_PR_BULK + || iface->bInterfaceProtocol =3D=3D US_PR_UAS)) + || (iface->bInterfaceClass =3D=3D USB_CLASS_HID + && iface->bInterfaceSubClass =3D=3D USB_INTERFACE_SUBCLASS_BOOT))) + break; + iface =3D (void*)iface + iface->bLength; + } // Set the configuration. ret =3D set_configuration(usbdev->defpipe, config->bConfigurationValue= ); --=20 2.20.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org