4.1.1 Driver Host Mode Client Functions
The DRV_USB_HOST_INTERFACE structure contains pointers to the USB Driver’s Host mode Client functions. These functions are only applicable when the USB module is operating as a USB Host. Along with the function pointers to the driver’s Host mode specific functions, the DRV_USB_HOST_INTERFACE structure also contains another structure of function pointers of the type DRV_USB_ROOT_HUB_INTERFACE. This structure contains function pointers to the USB Driver’s Root Hub functions. A USB Driver must implement these functions and ensure that the Host Stack can access these functions through the driver’s DRV_USB_HOST_INTERFACE structure. The Driver Host mode Client functions in the DRV_USB_HOST_INTERFACE structure are:
- Driver Host Pipe Setup Function
 - Driver Host Pipe Close Function
 - Driver Host Events Disable Function
 - Driver Host Events Enable Function
 - Driver Host IRP Submit Function
 - Driver Host IRP Cancel Function
 
Driver Host Pipe Setup Function
The hostPipeSetup member of the DRV_USB_HOST_INTERFACE structure
                should point to the USB Driver Host Pipe Setup function. The signature of the Host
                Pipe Setup function is as follows:
DRV_USB_HOST_PIPE_HANDLE (*hostPipeSetup)  ( DRV_HANDLE client,  uint8_t deviceAddress,
                           USB_ENDPOINT endpointAndDirection, uint8_t hubAddress,
                           uint8_t hubPort, USB_TRANSFER_TYPE pipeType, uint8_t bInterval,
                           uint16_t wMaxPacketSize, USB_SPEED speed);
            The USB Driver Host mode Pipe Setup function must match this signature. The USB Host
                Stack calls this function to create a communication pipe to the attached device. The
                function parameters define the property of this communication pipe. The
                    driverHandle parameter is the handle to the driver obtained
                through the driver Open function. The deviceAddress and the
                    endpointAddress parameters specify the address of the USB
                device and the endpoint on this device to which this pipe must connect. 
If the device is connected to the Host though a hub, hubAddress and
                    hubPort must specify the address of the hub and port to which
                the device is connected. The USB Driver will use these parameters to schedule split
                transactions if the target device is a Low-Speed or Full-Speed device and is
                connected to the Host through a high-speed hub. If the device is connected directly
                to the Host, these parameters should be set to zero ('0'). 
The pipeType parameter specifies the type of USB transfers that this
                pipe would support. The bInterval parameter is interpreted as per
                the USB 2.0 Specification based on the transfer type and the speed of the pipe. The
                    wMaxPacketSize parameter defines the maximum size of a
                transaction that the driver should use while transporting a transfer on the pipe.
                The Host layer will use the information obtained from the USB device descriptors of
                the attached device to decide the wMaxPacketSize parameter. 
The Driver Host Pipe Setup function should be thread-safe, but does not have to be event safe. The Host layer (or the Host Client Drivers) will not, and should not attempt to create a pipe in an interrupt, and therefore, an event context. The function should return DRV_USB_PIPE_HANDLE_INVALID if the driver could not open the pipe. The driver may not be able to open a pipe due to incorrect function parameters or due to lack of resources.
Driver Host Pipe Close Function
The hostPipeClose member of the DRV_USB_HOST_INTERFACE structure
                should point to the USB Driver Host Pipe Close function. The signature of the Host
                Pipe Close function is as follows:
void (*hostPipeClose)(DRV_USB_HOST_PIPE_HANDLE pipeHandle);
The USB Driver Host mode Pipe Close function must match this signature. The USB Host
                Stack calls this function to close communication pipes. The
                    pipeHandle parameter is the pipe handle obtained from the Pipe
                Setup function. The Host Client Driver typically closes pipes when a device detach
                was detected. The Client Driver may also close pipes when a device configuration
                needs to change or when the Client Driver is being unloaded by the Host. The Pipe
                Close function has no side effect if the pipe handle is invalid. Closing the pipe
                will abort all I/O Request Packets (IRP) that are scheduled on the pipe. Any
                transaction in progress will complete. The IRP callback functions for each IRP
                scheduled in the pipe will be called with a USB_HOST_IRP_STATUS_ABORTED status. 
The USB Driver Pipe Close function must be thread-safe and event-safe. The latter requirement allows the Pipe Close function to be called in the context of the device detach Interrupt Service Routine.
Driver Host Event Disable Function
The hostEventsDisable member of the DRV_USB_HOST_INTERFACE structure
                should point to the USB Driver Host mode Driver Events Disable function. The
                signature of the Events Disable function is as follows:
bool (*hostEventsDisable)(DRV_HANDLE handle);
The USB Driver Host mode Driver Events Disable function must match this signature.
                The Host Stack will call this function when it wants to execute a section of code
                that should not be interrupted by the USB Driver. Calling this function should
                disable USB Driver event generation. The handle parameter is set to
                the driver handle obtained via the driver Open function. The function will return
                the present state of the event generation, whether it is enabled or disabled. The
                Host Stack will pass this value to the USB Driver Host mode Driver Events Enable
                function when it needs to enable the driver events.
Driver Host Events Enable Function
The hostEventsEnable member of the DRV_USB_HOST_INTERFACE structure
                should point to the USB Driver Host mode Driver Events Enable function. The
                signature of the events enable function is as follows:
void (*hostEventsEnable)(DRV_HANDLE handle, bool eventContext);
The USB Driver Host mode Driver Events Enable function must match this signature. The
                USB Host Stack calls this function to re-enable the USB Driver Host mode Events (if
                they were enabled) after it called the USB Driver Host mode Events Disable function
                to disable driver events. The handle parameter is set to the driver
                handle obtained via the driver Open function. The eventContext
                parameter is set to the value returned by the Host mode Driver Events Disable
                function. The USB Driver will use the eventContext parameter to
                restore the event generation status (enabled or disabled) to what it was when the
                USB Driver Host mode Driver Events Disable function was called.
Driver Host IRP Submit Function
The hostIRPSubmit member of the DRV_USB_HOST_INTERFACE structure
                should point to the USB Driver Host IRP Submit function. The signature of the IRP
                Submit function is as follows:
USB_ERROR (*hostIRPSubmit)(DRV_USB_HOST_PIPE_HANDLE pipeHandle, USB_HOST_IRP * irp);
The USB Driver Host IRP Submit function must match this signature. The Host Stack
                calls this function to submit an IRP to the USB Driver. The USB Driver provides this
                mechanism to transfer data between the Host Stack and the attached device. The
                    pipeHandle parameter should be set to the pipe handle obtained
                by the Pipe Setup function. The pipe handle specifies the pipe, and therefore, the
                target device, endpoint, speed and transfer type, on which the I/O must be
                processed. The irp parameter should point to the IRP data
                structure. The IRP data structure will transport an entire transfer over the pipe.
                The USB Driver will split up the transfer into transactions based on the parameters
                specified at the time of pipe creation. This process does not require Host Stack
                intervention. 
The function will return USB_ERROR_HOST_PIPE_INVALID if the pipe handle is not valid. It will return USB_ERROR_OSAL_FUNCTION if an error occurred while performing a RTOS-related operation. It will return USB_ERROR_NONE if the IRP was submitted successfully.
The USB Driver will queue the IRP if there is already an IRP being processed on the
                pipe. The completion of the IRP processing is indicated by the USB Driver calling
                the IRP Callback function specified within the IRP. The Host IRP Submit function
                must be thread-safe and IRP callback-safe. The Host Stack may resubmit the IRP
                within the IRP Callback function. The IRP Callback function itself executes within
                an interrupt context. The completion status of the IRP will be available in the
                    status member of the IRP when the IRP callback function is
                invoked.
Driver Host IRP Cancel Function
The hostIRPCancel member of the DRV_USB_HOST_INTERFACE
                        structure should point to the USB Driver Host IRP Cancel function. The
                        signature of the IRP Cancel function is as follows:
void (*hostIRPCancel)(USB_HOST_IRP * irp);
The USB Driver Host IRP Cancel function must match this signature. The Host Stack and Host Client Drivers will call this function to cancel an IRP that was submitted. The IRP will be aborted successfully if it is not in progress. If the IRP processing has begun, the on-going transaction will complete and pending transactions in the transfer will be aborted. In either case, the IRP Callback function will be called with the IRP status as USB_HOST_IRP_STATUS_ABORTED.
Topics
| Name | Description | 
| Driver Host Root Hub Interface | Provides information on the Root Hub interface for the USB Host Driver. | 
| Driver Host USB Root Hub Port Interface | Provides information on the Root Hub Port interface of the USB Host Driver. | 
