Skip to main content

dyspxkrypt_libuefi/protocols/usb/
function.rs

1/*
2 * Dyspxkrypt LibUEFI: Raw bindings of UEFI that conforms to the definitions of the UEFI Specification.
3 * Copyright (C) 2023-2024 HTGAzureX1212.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18
19use crate::protocols::usb::io::{
20    EFI_USB_CONFIG_DESCRIPTOR, EFI_USB_DEVICE_DESCRIPTOR, EFI_USB_DEVICE_REQUEST,
21    EFI_USB_ENDPOINT_DESCRIPTOR, EFI_USB_INTERFACE_DESCRIPTOR,
22};
23
24pub const EFI_USBFN_IO_PROTOCOL_GUID: EFI_GUID = unsafe {
25    EFI_GUID::from_raw_parts(
26        0x32D2963A,
27        0xFE5D,
28        0x4F30,
29        [0xB6, 0x33, 0x6E, 0x5D, 0xC5, 0x58, 0x03, 0xCC],
30    )
31};
32
33pub const EFI_USBFN_IO_PROTOCOL_REVISION: UINT32 = 0x00010001;
34
35#[derive(Clone, Copy)]
36#[repr(C)]
37pub enum EFI_USB_BUS_SPEED {
38    UsbBusSpeedUnknown,
39    UsbBusSpeedLow,
40    UsbBusSpeedFull,
41    UsbBusSpeedHigh,
42    UsbBusSpeedSuper,
43    UsbBusSpeedMaximum,
44}
45
46#[repr(C)]
47pub enum EFI_USB_ENDPOINT_TYPE {
48    UsbEndpointControl,
49    UsbEndpointIsochronous,
50    UsbEndpointBulk,
51    UsbEndpointInterrupt,
52}
53
54#[repr(C)]
55pub enum EFI_USBFN_DEVICE_INFO_ID {
56    EfiUsbDeviceInfoUnknown,
57    EfiUsbDeviceInfoSerialNumber,
58    EfiUsbDeviceInfoManufacturerName,
59    EfiUsbDeviceInfoProductName,
60}
61
62#[derive(Clone, Copy)]
63#[repr(C)]
64pub enum EFI_USBFN_ENDPOINT_DIRECTION {
65    EfiUsbEndpointDirectionHostOut = 0,
66    EfiUsbEndpointDirectionHostIn,
67    EfiUsbEndpointDirectionDeviceTx,
68    EfiUsbEndpointDirectionDeviceRx,
69}
70
71#[repr(C)]
72pub enum EFI_USBFN_MESSAGE {
73    EfiUsbMsgSetupPacket,
74    EfiUsbMsgEndpointStatusChangedRx,
75    EfiUsbMsgEndpointStatusChangedTx,
76    EfiUsbMsgBusEventDetach,
77    EfiUsbMsgBusEventAttach,
78    EfiUsbMsgBusEventReset,
79    EfiUsbMsgBusEventSuspend,
80    EfiUsbMsgBusEventResume,
81    EfiUsbMsgBusEventSpeed,
82}
83
84#[repr(C)]
85pub enum EFI_USBFN_POLICY_TYPE {
86    EfiUsbPolicyUndefined,
87    EfiUsbPolicyMaxTransactionSize,
88    EfiUsbPolicyZeroLengthTerminationSupport,
89    EfiUsbPolicyZeroLengthTermination,
90}
91
92#[repr(C)]
93pub enum EFI_USBFN_PORT_TYPE {
94    EfiUsbUnknownPort,
95    EfiUsbStandardDownstreamPort,
96    EfiUsbChargingDownstreamPort,
97    EfiUsbDedicatedChargingPort,
98    EfiUsbInvalidDedicatedChargingPort,
99}
100
101#[derive(Clone, Copy)]
102#[repr(C)]
103pub enum EFI_USBFN_TRANSFER_STATUS {
104    UsbTransferStatusUnknown,
105    UsbTransferStatusComplete,
106    UsbTransferStatusAborted,
107    UsbTransferStatusActive,
108    UsbTransferStatusNone,
109}
110
111#[repr(C)]
112pub struct EFI_USB_CONFIG_INFO {
113    pub ConfigDescriptor: *mut EFI_USB_CONFIG_DESCRIPTOR,
114    pub InterfaceInfoTable: *mut *mut EFI_USB_INTERFACE_INFO,
115}
116
117#[repr(C)]
118pub struct EFI_USB_DEVICE_INFO {
119    pub DeviceDescriptor: *mut EFI_USB_DEVICE_DESCRIPTOR,
120    pub ConfigInfoTable: *mut *mut EFI_USB_CONFIG_INFO,
121}
122
123#[repr(C)]
124pub struct EFI_USB_INTERFACE_INFO {
125    pub InterfaceDescriptor: *mut EFI_USB_INTERFACE_DESCRIPTOR,
126    pub EndpointDescriptorTable: *mut *mut EFI_USB_ENDPOINT_DESCRIPTOR,
127}
128
129#[repr(C)]
130pub struct EFI_USBFN_IO_PROTOCOL {
131    pub Revision: UINT32,
132    pub DetectPort: unsafe extern "efiapi" fn(
133        This: *mut EFI_USBFN_IO_PROTOCOL,
134        PortType: *mut EFI_USBFN_PORT_TYPE,
135    ) -> EFI_STATUS,
136    pub ConfigureEnableEndpoints: unsafe extern "efiapi" fn(
137        This: *mut EFI_USBFN_IO_PROTOCOL,
138        DeviceInfo: *mut EFI_USB_DEVICE_INFO,
139    ) -> EFI_STATUS,
140    pub GetEndpointMaxPacketSize: unsafe extern "efiapi" fn(
141        This: *mut EFI_USBFN_IO_PROTOCOL,
142        EndpointType: EFI_USB_ENDPOINT_TYPE,
143        BusSpeed: EFI_USB_BUS_SPEED,
144        MaxPacketSize: *mut UINT16,
145    ) -> EFI_STATUS,
146    pub GetDeviceInfo: unsafe extern "efiapi" fn(
147        This: *mut EFI_USBFN_IO_PROTOCOL,
148        Id: EFI_USBFN_DEVICE_INFO_ID,
149        BufferSize: *mut UINTN,
150        Buffer: *mut VOID,
151    ) -> EFI_STATUS,
152    pub GetVendorIdProductId: unsafe extern "efiapi" fn(
153        This: *mut EFI_USBFN_IO_PROTOCOL,
154        Vid: *mut UINT64,
155        Pid: *mut UINT64,
156    ) -> EFI_STATUS,
157    pub AbortTransfer: unsafe extern "efiapi" fn(
158        This: *mut EFI_USBFN_IO_PROTOCOL,
159        EndpointIndex: UINT8,
160        Direction: EFI_USBFN_ENDPOINT_DIRECTION,
161    ) -> EFI_STATUS,
162    pub GetEndpointStallState: unsafe extern "efiapi" fn(
163        This: *mut EFI_USBFN_IO_PROTOCOL,
164        EndpointIndex: UINT8,
165        Direction: EFI_USBFN_ENDPOINT_DIRECTION,
166        State: *mut BOOLEAN,
167    ) -> EFI_STATUS,
168    pub SetEndpointStallState: unsafe extern "efiapi" fn(
169        This: *mut EFI_USBFN_IO_PROTOCOL,
170        EndpointIndex: UINT8,
171        Direction: EFI_USBFN_ENDPOINT_DIRECTION,
172        State: BOOLEAN,
173    ) -> EFI_STATUS,
174    pub EventHandler: unsafe extern "efiapi" fn(
175        This: *mut EFI_USBFN_IO_PROTOCOL,
176        Message: *mut EFI_USBFN_MESSAGE,
177        PayloadSize: *mut UINTN,
178        Payload: *mut EFI_USBFN_MESSAGE_PAYLOAD,
179    ) -> EFI_STATUS,
180    pub Transfer: unsafe extern "efiapi" fn(
181        This: *mut EFI_USBFN_IO_PROTOCOL,
182        EndpointIndex: UINT8,
183        Direction: EFI_USBFN_ENDPOINT_DIRECTION,
184        BufferSize: *mut UINTN,
185        Buffer: *mut VOID,
186    ) -> EFI_STATUS,
187    pub GetMaxTransferSize: unsafe extern "efiapi" fn(
188        This: *mut EFI_USBFN_IO_PROTOCOL,
189        MaxTransferSize: *mut UINTN,
190    ) -> EFI_STATUS,
191    pub AllocateTransferBuffer: unsafe extern "efiapi" fn(
192        This: *mut EFI_USBFN_IO_PROTOCOL,
193        Size: UINTN,
194        Buffer: *mut *mut VOID,
195    ) -> EFI_STATUS,
196    pub FreeTransferBuffer: unsafe extern "efiapi" fn(
197        This: *mut EFI_USBFN_IO_PROTOCOL,
198        Buffer: *mut VOID,
199    ) -> EFI_STATUS,
200    pub StartController: unsafe extern "efiapi" fn(This: *mut EFI_USBFN_IO_PROTOCOL) -> EFI_STATUS,
201    pub StopController: unsafe extern "efiapi" fn(This: *mut EFI_USBFN_IO_PROTOCOL) -> EFI_STATUS,
202    pub SetEndpointPolicy: unsafe extern "efiapi" fn(
203        This: *mut EFI_USBFN_IO_PROTOCOL,
204        EndpointIndex: UINT8,
205        Direction: EFI_USBFN_ENDPOINT_DIRECTION,
206        PolicyType: EFI_USBFN_POLICY_TYPE,
207        BufferSize: UINTN,
208        Buffer: *mut VOID,
209    ) -> EFI_STATUS,
210    pub GetEndpointPolicy: unsafe extern "efiapi" fn(
211        This: *mut EFI_USBFN_IO_PROTOCOL,
212        EndpointIndex: UINT8,
213        Direction: EFI_USBFN_ENDPOINT_DIRECTION,
214        PolicyType: EFI_USBFN_POLICY_TYPE,
215        BufferSize: *mut UINTN,
216        Buffer: *mut VOID,
217    ) -> EFI_STATUS,
218}
219
220#[derive(Clone, Copy)]
221#[repr(C)]
222pub struct EFI_USBFN_TRANSFER_RESULT {
223    pub BytesTransferred: UINTN,
224    pub TransferStatus: EFI_USBFN_TRANSFER_STATUS,
225    pub EndpointIndex: UINT8,
226    pub Direction: EFI_USBFN_ENDPOINT_DIRECTION,
227    pub Buffer: *mut VOID,
228}
229
230#[repr(C)]
231pub union EFI_USBFN_MESSAGE_PAYLOAD {
232    pub udr: EFI_USB_DEVICE_REQUEST,
233    pub utr: EFI_USBFN_TRANSFER_RESULT,
234    pub ubs: EFI_USB_BUS_SPEED,
235}