From 74b3823b0cc1a4f7c403e19da61b9cd5c01fce14 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 6 Aug 2020 12:54:06 -0600 Subject: [PATCH] Add webcam disconnect test --- MdeModulePkg/Application/UiApp/FrontPage.c | 74 ++++++++++++++++++- .../Application/UiApp/FrontPageStrings.uni | 1 + .../Application/UiApp/FrontPageVfr.Vfr | 1 + 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Application/UiApp/FrontPage.c b/MdeModulePkg/Application/UiApp/FrontPage.c index 534a7bdcc2..d85b484f2d 100644 --- a/MdeModulePkg/Application/UiApp/FrontPage.c +++ b/MdeModulePkg/Application/UiApp/FrontPage.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include #include #include #include @@ -780,6 +781,75 @@ STATIC VOID FirmwareConfigurationInformation(VOID) { } } +VOID WebcamStatus(VOID) { + EFI_STATUS Status; + UINTN UsbIoHandleCount; + EFI_HANDLE *UsbIoBuffer; + UINTN Index; + EFI_USB_IO_PROTOCOL *UsbIo; + EFI_USB_DEVICE_DESCRIPTOR DevDesc; + UINTN Webcams; + EFI_STRING_ID Token; + + // + // Get all Usb IO handles in system + // + UsbIoHandleCount = 0; + Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiUsbIoProtocolGuid, NULL, &UsbIoHandleCount, &UsbIoBuffer); + if (EFI_ERROR(Status)) { + DEBUG ((EFI_D_INFO, "Failed to read UsbIo handles: 0x%x\n", Status)); + return; + } + + Webcams = 0; + for (Index = 0; Index < UsbIoHandleCount; Index++) { + DEBUG ((EFI_D_INFO, "UsbIo Handle %d\n", Index)); + + // + // Get the child Usb IO interface + // + Status = gBS->HandleProtocol( + UsbIoBuffer[Index], + &gEfiUsbIoProtocolGuid, + (VOID **) &UsbIo + ); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_INFO, " Failed to find UsbIo protocol\n")); + continue; + } + + Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_INFO, " Failed to get device descriptor\n")); + continue; + } + + DEBUG ((EFI_D_INFO, " ID: 0x%04X:0x%04X\n", DevDesc.IdVendor, DevDesc.IdProduct)); + DEBUG ((EFI_D_INFO, " Class: %d\n", DevDesc.DeviceClass)); + DEBUG ((EFI_D_INFO, " SubClass: %d\n", DevDesc.DeviceSubClass)); + DEBUG ((EFI_D_INFO, " Protocol: %d\n", DevDesc.DeviceProtocol)); + + //TODO: make sure this picks up all of our laptop webcams and nothing else + UINT32 Id = (((UINT32)DevDesc.IdVendor) << 16) | ((UINT32)DevDesc.IdProduct); + switch (Id) { + case 0x04f2b5a7: // Chicony Camera (bonw13, oryp4) + case 0x04f2b649: // Chicony Camera (galp4) + case 0x04f2b685: // Chicony Camera (darp6, gaze15, lemp9) + case 0x59869102: // Acer BisonCam (addw2, oryp6) + Webcams++; + break; + } + } + + FreePool (UsbIoBuffer); + + //TODO: logic for not showing the warning on desktops + Token = STRING_TOKEN (STR_WEBCAM_STATUS); + if (Webcams == 0) { + HiiSetString (gFrontPagePrivate.HiiHandle, Token, L"Info: Webcam Module Disconnected", NULL); + } +} + /** Update the information for the Front Page based on Smbios information. @@ -801,9 +871,9 @@ UpdateFrontPageStrings ( SMBIOS_TABLE_ENTRY_POINT *EntryPoint; SMBIOS_STRUCTURE_POINTER SmbiosTable; - WarnNoBootableMedia (); - FirmwareConfigurationInformation(); + WarnNoBootableMedia (); + WebcamStatus(); Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &Table); if (EFI_ERROR (Status) || Table == NULL) { diff --git a/MdeModulePkg/Application/UiApp/FrontPageStrings.uni b/MdeModulePkg/Application/UiApp/FrontPageStrings.uni index 934a2cb94d..8370ecb1d4 100644 --- a/MdeModulePkg/Application/UiApp/FrontPageStrings.uni +++ b/MdeModulePkg/Application/UiApp/FrontPageStrings.uni @@ -19,6 +19,7 @@ #string STR_BOOT_DEFAULT_HELP #language en-US "Boot the default entry" #string STR_MISSING_STRING #language en-US "Missing String" #string STR_NO_BOOTABLE_MEDIA #language en-US "" +#string STR_WEBCAM_STATUS #language en-US "" #string STR_EMPTY_STRING #language en-US "" #string STR_VIRTUALIZATION #language en-US "" #string STR_VIRTUALIZATION_STATUS #language en-US "" diff --git a/MdeModulePkg/Application/UiApp/FrontPageVfr.Vfr b/MdeModulePkg/Application/UiApp/FrontPageVfr.Vfr index 6d036c7cfe..39fd87f135 100644 --- a/MdeModulePkg/Application/UiApp/FrontPageVfr.Vfr +++ b/MdeModulePkg/Application/UiApp/FrontPageVfr.Vfr @@ -42,6 +42,7 @@ formset subtitle text = STRING_TOKEN(STR_EMPTY_STRING); subtitle text = STRING_TOKEN(STR_NO_BOOTABLE_MEDIA); + subtitle text = STRING_TOKEN(STR_WEBCAM_STATUS); endform;