版权声明:本文全部是胡说八道,如果你喜欢,可随意转载 https://blog.csdn.net/robinsongsog/article/details/82114570
/**
Check whether USB keyboard driver supports this device.
@param This The USB keyboard driver binding protocol.
@param Controller The controller handle to check.
@param RemainingDevicePath The remaining device path.
@retval EFI_SUCCESS The driver supports this controller.
@retval other This device isn't supported.
**/
EFI_STATUS
EFIAPI
USBKeyboardDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_USB_IO_PROTOCOL *UsbIo;
//
// Check if USB I/O Protocol is attached on the controller handle.
//
Status = gBS->OpenProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Use the USB I/O Protocol interface to check whether Controller is
// a keyboard device that can be managed by this driver.
//
Status = EFI_SUCCESS;
if (!IsUSBKeyboard (UsbIo)) {
Status = EFI_UNSUPPORTED;
}
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
如何确认,找到的是不是我们想要的protocol , 可以事后,做一些判断:
比如:
//
// Use the USB I/O Protocol interface to check whether Controller is
// a keyboard device that can be managed by this driver.
//
Status = EFI_SUCCESS;
if (!IsUSBKeyboard (UsbIo)) {
Status = EFI_UNSUPPORTED;
}
UsbIo 是打开后得到的结果,用这个得到的结果拿出来测测
/**
Uses USB I/O to check whether the device is a USB keyboard device.
@param UsbIo Pointer to a USB I/O protocol instance.
@retval TRUE Device is a USB keyboard device.
@retval FALSE Device is a not USB keyboard device.
**/
BOOLEAN
IsUSBKeyboard (
IN EFI_USB_IO_PROTOCOL *UsbIo
)
{
EFI_STATUS Status;
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
//
// Get the default interface descriptor
//
Status = UsbIo->UsbGetInterfaceDescriptor (
UsbIo,
&InterfaceDescriptor
);
if (EFI_ERROR (Status)) {
return FALSE;
}
if (InterfaceDescriptor.InterfaceClass == CLASS_HID &&
InterfaceDescriptor.InterfaceSubClass == SUBCLASS_BOOT &&
InterfaceDescriptor.InterfaceProtocol == PROTOCOL_KEYBOARD
) {
return TRUE;
}
return FALSE;
}