USBProxyDevice-solaris.cpp revision 9de2fa82343af2df7df171b18afbe32b6f37ed84
/* $Id$ */
/** @file
* USB device proxy - the Solaris backend.
*/
/*
* Copyright (C) 2008 Oracle Corporation
*
* Oracle Corporation confidential
* All rights reserved
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DRV_USBPROXY
#include <limits.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <iprt/critsect.h>
#include "../USBProxyDevice.h"
/* WORK-IN-PROGRESS */
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Log Prefix. */
#define USBR3PROXY "USBProxyDev"
/** Maximum endpoints supported. */
#define USBSOL_MAXENDPOINTS 32
/** Maximum interfaces supported. */
#define USBSOL_MAXINTERFACES 256
/** EndPoint address mask (bEndPointAddress) */
#define USBSOL_EPADDR_NUM_MASK 0x0F
#define USBSOL_EPADDR_DIR_MASK 0x80
#define USBSOL_EPADDR_IN 0x80
#define USBSOL_EPADDR_OUT 0x00
#define USBSOL_CTRLREQ_SIZE 0x08
/** This really needs to be defined in vusb.h! */
#ifndef VUSB_DIR_TO_DEV
# define VUSB_DIR_TO_DEV 0x00
#endif
/** Ugen isoc support toggle, disable this for S10. */
//#define VBOX_WITH_SOLARIS_USB_ISOC
/** -XXX- Remove this hackery eventually */
#if 0
#ifdef DEBUG_ramshankar
#endif
#endif
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct USBPROXYURBSOL;
/**
* Asynchronous URB status.
*/
typedef struct URBSTATUSSOL
{
/** The result of the transfer. */
/** The URB associated with this transfer. */
/**
* Wrapper around the solaris urb request structure.
* This is required to track in-flight and landed URBs.
*/
typedef struct USBPROXYURBSOL
{
/** Pointer to the VUSB URB (set to NULL if canceled). */
/** The millisecond timestamp when this URB was submitted. */
/** Pointer to the Solaris device. */
struct USBPROXYDEVSOL *pDevSol;
/** Status of this URB. */
#ifdef VBOX_WITH_SOLARIS_USB_ISOC
/** Isoc. OUT buffer. */
/** Size of the isoc. OUT buffer */
/** Isoc. IN buffer. */
/** Size of the isoc. IN buffer. */
#endif
/** Pointer to the next solaris URB. */
struct USBPROXYURBSOL *pNext;
/** Pointer to the previous solaris URB. */
struct USBPROXYURBSOL *pPrev;
/**
* Data for the solaris usb proxy backend.
*/
typedef struct USBPROXYDEVSOL
{
/** Path of the USB device in the dev tree (driver bound). */
char *pszDevPath;
/** Path of the USB device in the devices tree (persistent). */
char *pszDevicePath;
/** Status endpoint. */
/** Pointer to the proxy device instance. */
/** Array of all endpoints. */
/** Array of all status endpoints.*/
/** Critical section protecting the two lists. */
/** The list of free solaris URBs. Singly linked. */
/** The list of active solaris URBs. Doubly linked.
* We must maintain this so we can properly reap URBs of a detached device.
* Only the split head will appear in this list. */
/** The list of landed solaris URBs. Doubly linked.
* Only the split head will appear in this list. */
/** The tail of the landed solaris URBs. */
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static void usbProxySolarisAsyncNotify(bool fActive);
static int usbProxySolarisSendReq(RTFILE File, RTFILE StatFile, PVUSBSETUP pReq, caddr_t pData, uint16_t cbData, int *pStatus);
static int usbProxySolarisSendReqAsync(RTFILE File, PVUSBSETUP pReq, caddr_t pData, uint16_t cbData, PURBSTATUSSOL pUrbStatus);
static int usbProxySolarisCtrlReq(RTFILE File, RTFILE StatFile, PVUSBSETUP pReq, caddr_t pData, uint16_t cbData, int *pStatus);
static int usbProxySolarisCtrlReqAsync(RTFILE File, PVUSBSETUP pReq, caddr_t pData, uint16_t cbData, PURBSTATUSSOL pStatus);
static int usbProxySolarisIO(RTFILE File, RTFILE StatFile, caddr_t pData, size_t cbData, int fOpenMode, int *pStatus);
static int usbProxySolarisIOAsync(RTFILE File, caddr_t pData, size_t cbData, int fOpenMode, PURBSTATUSSOL pUrbStatus);
static int usbProxySolarisOpenEndPoint(PUSBPROXYDEVSOL pDevSol, int EndPoint, VUSBXFERTYPE XferType);
static int usbProxySolarisOpenNode(PUSBPROXYDEVSOL pDevSol, uint8_t bCfgValue, int iInterface, int iAlternate, int EndPoint,
static void usbProxySolarisAsyncComplete(int Sig);
/**
* Toggle asynchronous notification signals for asynchronous USB IO.
*
* @param fNotify Whether notification is active.
*/
static void usbProxySolarisAsyncNotify(bool fNotify)
{
if (fNotify)
else
}
/**
* Translate the USB ugen status code to a VUSB status.
*
* @returns VUSB URB status code.
* @param irc ugen status code.
*/
{
switch (irc)
{
case USB_LC_STAT_NOERROR: return VUSBSTATUS_OK;
case USB_LC_STAT_CRC: return VUSBSTATUS_CRC;
case USB_LC_STAT_STALL: return VUSBSTATUS_STALL;
case USB_LC_STAT_DEV_NOT_RESP: return VUSBSTATUS_DNR;
case USB_LC_STAT_DATA_OVERRUN: return VUSBSTATUS_DATA_OVERRUN;
case USB_LC_STAT_DATA_UNDERRUN: return VUSBSTATUS_DATA_UNDERRUN;
case USB_LC_STAT_TIMEOUT: return VUSBSTATUS_DNR;
case USB_LC_STAT_NOT_ACCESSED: return VUSBSTATUS_NOT_ACCESSED;
//case USB_LC_STAT_BITSTUFFING:
//case USB_LC_STAT_DATA_TOGGLE_MM:
//case USB_LC_STAT_PID_CHECKFAILURE:
//case USB_LC_STAT_UNEXP_PID:
//case USB_LC_STAT_BUFFER_OVERRUN:
//case USB_LC_STAT_BUFFER_UNDERRUN:
//case USB_LC_STAT_UNSPECIFIED_ERR:
//case USB_LC_STAT_NO_BANDWIDTH:
//case USB_LC_STAT_HW_ERR:
//case USB_LC_STAT_SUSPENDED:
//case USB_LC_STAT_DISCONNECTED:
//case USB_LC_STAT_INTR_BUF_FULL:
//case USB_LC_STAT_INVALID_REQ:
//case USB_LC_STAT_INTERRUPTED:
//case USB_LC_STAT_NO_RESOURCES:
//case USB_LC_STAT_INTR_POLLING_FAILED:
default:
return VUSBSTATUS_STALL;
}
}
/**
* Setup a USB request packet.
*/
{
LogFlow((USBR3PROXY ":usbProxySolarisSetupReq pSetupData=%p bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n",
/* Handle endianess here. Currently no swapping is needed. */
}
/**
* Helper for sending messages through an endpoint, Synchronous version.
* Note: pData is assumed to be (pReq + 1) i.e. following the request! Caller's responsibility.
*
* @returns Number of bytes transferred.
* @param pStatus Where to store the VUSB status (Optional).
*/
static int usbProxySolarisSendReq(RTFILE File, RTFILE StatFile, PVUSBSETUP pReq, caddr_t pData, uint16_t cbData, int *pStatus)
{
/* Handle read request */
return usbProxySolarisIO(File, StatFile, (caddr_t)pReq, sizeof(VUSBSETUP), RTFILE_O_WRITE, pStatus);
/* Handle write request */
return usbProxySolarisIO(File, StatFile, (caddr_t)pReq, sizeof(VUSBSETUP) + cbData, RTFILE_O_WRITE, pStatus);
}
/**
* Helper for sending messages through an endpoint, Asynchronous version.
* Note: pData is assumed to (pReq + 1) i.e. following the request! Caller's responsibility.
*
* @returns VBox status code
* @param pUrbStatus Where to store the status.
*/
static int usbProxySolarisSendReqAsync(RTFILE File, PVUSBSETUP pReq, caddr_t pData, uint16_t cbData, PURBSTATUSSOL pUrbStatus)
{
/* Handle read request */
/* Handle write request */
return usbProxySolarisIOAsync(File, (caddr_t)pReq, sizeof(VUSBSETUP) + cbData, RTFILE_O_WRITE, pUrbStatus);
}
/**
* Helper for sending control messages, Synchronous version.
*
* @returns Number of bytes transferred or -1 for errors.
* @param pStatus Where to store the VUSB status (Optional).
*/
static int usbProxySolarisCtrlReq(RTFILE File, RTFILE StatFile, PVUSBSETUP pReq, caddr_t pData, uint16_t cbData, int *pStatus)
{
if (cbIO < USBSOL_CTRLREQ_SIZE)
return cbIO;
/* Handle read requests, synchronous. */
&& cbData > 0)
{
}
return cbIO;
}
/**
* Helper for sending control messages, Asynchronous version.
*
* @returns VBox status code.
* @param pStatus Where to store the VUSB status (Optional).
*/
static int usbProxySolarisCtrlReqAsync(RTFILE File, PVUSBSETUP pReq, caddr_t pData, uint16_t cbData, PURBSTATUSSOL pStatus)
{
if (cbIO < USBSOL_CTRLREQ_SIZE)
return VERR_BUFFER_OVERFLOW;
/* Handle read requests, asynchronous. */
int rc = VINF_SUCCESS;
&& cbData > 0)
{
}
return rc;
}
#ifdef VBOX_WITH_SOLARIS_USB_ISOC
/**
* Helper for sending isochronous requests, Asynchronous version.
*
* @returns VBox status code.
* @param pStatus Where to store the VUSB status (Optional).
*/
{
return usbProxySolarisIOAsync(File, pUrbSol->pIsocBufOut, pUrbSol->cbIsocBufOut, RTFILE_O_WRITE, pStatus);
/* Handle read request, write request info synchronous, read asynchronous */
int cbIO = usbProxySolarisIO(File, NIL_RTFILE, pUrbSol->pIsocBufOut, pUrbSol->cbIsocBufOut, RTFILE_O_WRITE, NULL);
/* Free OUT buffer for the read request. */
pUrbSol->cbIsocBufOut = 0;
if (cbIO < 0)
return VERR_GENERAL_FAILURE; /* @todo find proper error code here */
return usbProxySolarisIOAsync(File, pUrbSol->pIsocBufIn, pUrbSol->cbIsocBufIn, RTFILE_O_READ, pStatus);
}
#endif /* VBOX_WITH_SOLARIS_USB_ISOC */
/**
*
* @returns Number of bytes transferred or -1 on errors.
* @param File The endpoint node
* @param StatFile The associated status endpoint node (Optional, can be NIL_RTFILE).
* @param cbData Number of bytes to transfer (should be size of buffer).
* @param pError Where to store VUSB result of operation (Optional, can be NULL).
*/
static int usbProxySolarisIO(RTFILE File, RTFILE StatFile, caddr_t pData, size_t cbData, int fOpenMode, int *pStatus)
{
int rc;
if (fOpenMode == RTFILE_O_READ)
else
if ( pStatus
&& StatFile != NIL_RTFILE)
{
int Status;
}
return cbIO;
}
/**
*
* @returns VBox status code.
* @param File The endpoint node
* @param cbData Number of bytes to transfer (should be size of buffer).
* @param fMode RT IO mode for the endpoint (RTFILE_O_READ/RTFILE_O_WRITE).
* @param pUrbStatus Where to store the result (allocated by caller).
*/
static int usbProxySolarisIOAsync(RTFILE File, caddr_t pData, size_t cbData, int fMode, PURBSTATUSSOL pUrbStatus)
{
int rc;
/* Turn on asynchronous notifications. */
usbProxySolarisAsyncNotify(true);
if (fMode == RTFILE_O_READ)
else
if (!rc)
return VINF_SUCCESS;
return RTErrConvertFromErrno(rc);
}
/**
* Initializes all pipes (including the default pipe) to their default state.
*
* @param pDevSol The Solaris USB device.
*/
{
for (int i = 0; i < USBSOL_MAXENDPOINTS; i++)
{
}
}
/**
* Opens the default device pipe and it's corresponding status node.
* Also opens the device status node in non-blocking mode.
*
* @returns VBox status code.
* @param pDevSol The Solaris USB device.
*/
{
/*
* Open status endpoint as read-only.
*/
int rc = RTFileOpen(&pDevSol->StatFile, achBuf, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_NON_BLOCK);
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Open default control endpoint as read-write.
*/
rc = RTFileOpen(&pDevSol->aEpFile[0], achBuf, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
if (RT_FAILURE(rc))
/*
* Open default control status endpoint as read-only.
*/
rc = RTFileOpen(&pDevSol->aEpStatFile[0], achBuf, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
if (RT_FAILURE(rc))
return rc;
}
/**
* Closes the default pipe, status node and device status node.
*
* @param pDevSol The Solaris USB device.
*/
{
int rc;
#define CLOSEFILE_AND_RESET(servicefile) \
do { \
if (servicefile != NIL_RTFILE) \
{ \
servicefile = NIL_RTFILE; \
} \
} while(0)
}
/**
* Close all endpoints and reset endpoint descriptor arrays.
*
* @param pDevSol The Solaris USB device.
*/
{
/* Close endpoint and endpoint status descriptors. */
for (int i = 1; i < USBSOL_MAXENDPOINTS; i++)
{
{
}
{
}
}
}
/**
*
* @param pDevSol The Solaris USB device.
*/
{
}
/**
* Get status information from a status node.
*
* @param StatFile The opened status node,
* @param pStatus Where to store the status (optional).
* @param fDevStat Whether the passed StatFile is the device status node.
*/
{
int Status;
{
}
else
{
/*
* Ugen supplied error codes.
*/
rc = VINF_SUCCESS;
if (!fDevStat)
{
switch (Status)
{
case USB_LC_STAT_CRC: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: CRC Timeout Detected\n")); break;
case USB_LC_STAT_BITSTUFFING: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Bit Stuffing Violation\n")); break;
case USB_LC_STAT_DATA_TOGGLE_MM: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Data Toggle Mismatch\n")); break;
case USB_LC_STAT_STALL: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: End Point Stalled\n")); break;
case USB_LC_STAT_DEV_NOT_RESP: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Device Not Responding\n")); break;
case USB_LC_STAT_PID_CHECKFAILURE: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: PID Check Failure\n")); break;
case USB_LC_STAT_UNEXP_PID: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Unexpected PID\n")); break;
case USB_LC_STAT_DATA_OVERRUN: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Data Exceeded Size\n")); break;
case USB_LC_STAT_DATA_UNDERRUN: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Less Data Received\n")); break;
case USB_LC_STAT_BUFFER_OVERRUN: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Buffer Size Exceeded\n")); break;
case USB_LC_STAT_BUFFER_UNDERRUN: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Buffer Underrun\n")); break;
case USB_LC_STAT_TIMEOUT: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Command has timed out\n")); break;
case USB_LC_STAT_NOT_ACCESSED: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Not Accessed by Hardware\n")); break;
case USB_LC_STAT_UNSPECIFIED_ERR: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Unspecified Error\n")); break;
case USB_LC_STAT_NO_BANDWIDTH: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: No Bandwidth\n")); break;
case USB_LC_STAT_HW_ERR: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Host Controller Hardware Error\n")); break;
case USB_LC_STAT_SUSPENDED: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Device Suspended\n")); break;
case USB_LC_STAT_DISCONNECTED: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Device Disconnected\n")); break;
case USB_LC_STAT_INTR_BUF_FULL: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Interrupt Buffer full\n")); break;
case USB_LC_STAT_INVALID_REQ: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Request Invalid\n")); break;
case USB_LC_STAT_INTERRUPTED: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Request Interrupted\n")); break;
case USB_LC_STAT_NO_RESOURCES: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: No Resources Available for Request\n")); break;
case USB_LC_STAT_INTR_POLLING_FAILED: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Failed to Restart Poll")); break;
default: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Error Not Determined %d\n", Status)); break;
}
}
else
{
switch (Status)
{
case USB_DEV_STAT_DISCONNECTED: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Device Disconnected\n")); break;
case USB_DEV_STAT_RESUMED: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Device Resumed\n")); break;
case USB_DEV_STAT_UNAVAILABLE: LogRel((USBR3PROXY ":usbProxySolarisGetStatus: Device Status Unavailable\n")); break;
}
}
}
if (pStatus)
return rc;
}
/**
* Get currently active configuration.
*
* @param pDevSol The Solaris USB Device.
* @param pConfigValue Where to store the configuration value.
* @returns VBox status code.
*/
{
LogFlow((USBR3PROXY ":usbProxySolarisGetActiveCfg pDevSol=%p pConfigValue=%p\n", pDevSol, pConfigValue));
/* USB 2.0(Sec. 9.4.2): bRequest=GET_CONFIGURATION(0x08) wValue=0 wIndex=0 wLength=1 */
int iConfig = -1;
if (RT_SUCCESS(rc))
{
&& RT_SUCCESS(rc))
{
*pConfigValue = iConfig;
return rc;
}
LogRel((USBR3PROXY ":usbProxySolarisGetActiveCfg failed to read configuration. cbRead=%d rc=%Rrc iConfig=%d\n", cbRead, rc, iConfig));
}
else
return rc;
}
/**
* Finds the interface and alternate setting for a given Endpoint address.
*
* @returns VBox status code.
* @param pDevSol The Solaris USB device.
* @param EndPoint The endpoint address as seen in the descriptor.
* @param piInterface Where to store the interface number.
* @param piAlternate Where to store the alternate number.
*/
static int usbProxySolarisGetInterfaceForEndpoint(PUSBPROXYDEVSOL pDevSol, int EndPoint, int *piInterface, int *piAlternate)
{
LogFlow((USBR3PROXY ":usbProxySolarisGetInterfaceForEndpoint pDevSol=%p Endpoint=%#x\n", pDevSol, EndPoint));
/* Find the interface for this endpoint. */
/* Find the configuration index for this configuration value. */
int iCfg = usbProxySolarisConfigIndex(pDevSol, pProxyDev->iActiveCfg >= 1 ? pProxyDev->iActiveCfg : 1);
if (iCfg < 0)
{
LogRel((USBR3PROXY ":usbProxySolarisGetInterfaceForEndpoint failed to obtain configuration index\n"));
return VERR_GENERAL_FAILURE;
}
/*
* Loop through all interfaces for this configuration.
*/
{
/*
* Loop through all alternate settings of this interface.
*/
{
/*
* Loop through all the endpoints of this interface.
*/
{
{
if (piInterface)
if (piAlternate)
return VINF_SUCCESS;
}
}
}
}
return VERR_GENERAL_FAILURE;
}
/**
* Finds configuration index for the configuration value.
*
* @returns Index of configuration with value 'bCfgValue' or -1 if not found.
*/
{
/* Find the configuration index corresponding to this configuration value. */
for (int i = 0; i < cCfg; i++)
{
{
return i;
}
}
return -1;
}
/**
* Claims all interfaces for a given configuration.
*
* @returns VBox status code.
* @param pDevSol The Solaris USB device.
* @param bCfgValue The configuration value.
*/
{
LogFlow((USBR3PROXY ":usbProxySolarisSeizeAllInterfaces pDevSol=%p bCfgValue=%d\n", pDevSol, bCfgValue));
/*
* ugen doesn't have a seize all interface scheme, but we can just open all the end-points of the interface
* in exclusive mode to have a similar effect. This should mostly be called from Init.
*/
int rc = VERR_GENERAL_FAILURE;
/* Find the configuration index for this configuration value. */
if (iCfg < 0)
{
LogRel((USBR3PROXY ":usbProxySolarisSeizeAllInterfaces failed to find configuration index for configuration value %d\n", bCfgValue));
return VERR_GENERAL_FAILURE; /* @todo find a better code? */
}
{
/*
* Loop through all interfaces for this configuration.
*/
{
/*
* Loop through all alternate settings of this interface.
*/
{
/*
* Loop through all endpoints for this interface.
*/
{
bCfgValue, /* Configuration value */
iInterface, /* Interface number */
iAlternate, /* Alternate setting */
if (RT_FAILURE(rc))
{
LogRel((USBR3PROXY ":usbProxySolarisSeizeAllInterfaces failed to open Cfg%d If%d Alt%d Ep%d(Addr %#x)\n", bCfgValue,
break;
}
}
}
if (RT_FAILURE(rc))
break;
}
}
else
return rc;
}
/**
* Determine the XferType from the endpoint attribute.
*
* @returns XferType for the given endpoint 'bmAttribute'
*/
{
/*
* USB 2.0(Sec. 9.6.6): bmAttribute transfer type.
*/
}
/**
* Determines the ugen node's open mode based on the XferType and direction.
*
* @returns The file open mode, or UINT32_MAX upon errors.
* @param bmEndpointAddress Address of endpoint as seen in the descriptor.
* @param XferType The VUSB XferType.
*/
{
LogFlow((USBR3PROXY ":usbProxySolarisOpenMode bmEndpointAddress=%#x XferType=%d\n", bmEndpointAddress, XferType));
switch (XferType)
{
case VUSBXFERTYPE_INTR: fMode |= (fIn ? RTFILE_O_READ : RTFILE_O_WRITE | RTFILE_O_NON_BLOCK); break;
case VUSBXFERTYPE_INVALID: fMode = UINT32_MAX; LogRel((USBR3PROXY ":invalid XferType %d\n", XferType)); break;
}
return fMode;
}
/**
* Open and endpoint given the XferType and optional OpenMode.
*
* @returns VBox status code.
* @param pDevSol The Solaris USB device.
* @param EndPoint The endpoint address as in the descriptor.
* @param XferType Endpoint xfer type.
*/
static int usbProxySolarisOpenEndPoint(PUSBPROXYDEVSOL pDevSol, int EndPoint, VUSBXFERTYPE XferType)
{
LogFlow((USBR3PROXY ":usbProxySolarisOpenEndPoint pDevSol=%p EndPoint=%#x XferType=%d\n", EndPoint, XferType));
/* Endpoint zero (the default control pipe) would already be open. */
if (EndPoint == 0)
return VINF_SUCCESS;
/* @todo Fix This! I'm not yet sure what's the right thing to do here regarding configuration... */
/* Get current configuration index. */
if (bCfgValue == -1)
{
/* @todo Fix or remove this. GET_CONFIGURATION requests don't work... */
if (RT_FAILURE(rc))
bCfgValue = 1;
}
/* Get interface for endpoint. */
int iInterface;
int iAlternate;
if (RT_SUCCESS(rc))
else
LogRel((USBR3PROXY ":usbProxySolarisOpenEndPoint usbProxySolarisGetInterfaceForEndpoint failed. rc=%Rrc\n", rc));
return VERR_GENERAL_FAILURE;
}
/**
* Open an endpoint node and stores it among the list of open endpoints.
*
* @returns VBox status code.
* @param pDevSol The Solaris USB device.
* @param bCfgValue The configuration value.
* @param iInterface The interface number.
* @param iAlternate The alternate setting.
* @param EndPoint The endpoint address as stored in the descriptor.
* @param XferType Endpoint xfer type.
* @param fOpenMode Open mode for the endpoint (< 0 auto-detects mode based on xfer type and direction).
*/
static int usbProxySolarisOpenNode(PUSBPROXYDEVSOL pDevSol, uint8_t bCfgValue, int iInterface, int iAlternate, int EndPoint,
{
LogFlow((USBR3PROXY ":usbProxySolarisOpenNode pDevSol=%p bCfgValue=%d iInterface=%d iAlternate=%d EndPoint=%#x XferType=%d\n",
int EndPtIndex = (EndPoint & USBSOL_EPADDR_NUM_MASK) + ((EndPoint & USBSOL_EPADDR_DIR_MASK) ? USBSOL_MAXENDPOINTS / 2 : 0);
return VERR_INVALID_HANDLE;
/* Check if already open; ep0 should already be open as well. */
if ( EndPtIndex == 0
{
return VINF_SUCCESS;
}
/*
* Construct the node name and open the endpoint.
*/
char szConfig[12];
char szAlternate[12];
if (iCfg > 0)
if (iAlternate > 0)
RTStrPrintf(szEndPoint, sizeof(szEndPoint), "%s/%sif%d%s%s%d", pDevSol->pszDevPath, szConfig, iInterface,
szAlternate, (EndPoint & USBSOL_EPADDR_DIR_MASK) ? "in" : "out", (EndPoint & USBSOL_EPADDR_NUM_MASK));
/*
* Ugen requires Interrupt IN endpoints to be polled before opening.
*/
/*
* Open the endpoint status node.
*/
if ( XferType == VUSBXFERTYPE_INTR
&& (EndPoint & USBSOL_EPADDR_IN))
{
int rc = RTFileOpen(&pDevSol->aEpStatFile[EndPtIndex], szEndPointStat, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
if (RT_FAILURE(rc))
{
LogRel((USBR3PROXY ":usbProxySolarisOpenNode failed to poll Intr IN endpoint stat %s\n", szEndPointStat));
return rc;
}
/*
* Unbuffered Interrupt IN transfers requires us to open the status endpoint and transfer
* USB_EP_INTR_ONE_XFER once. This will put it in unbuffered transfer mode until it's closed.
*/
char cMsg = USB_EP_INTR_ONE_XFER;
if (RT_FAILURE(rc))
{
LogRel((USBR3PROXY ":usbProxySolarisOpenNode failed to poll Intr IN endpoint %s\n", szEndPointStat));
return rc;
}
}
else
{
int rc = RTFileOpen(&pDevSol->aEpStatFile[EndPtIndex], szEndPointStat, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
if (RT_FAILURE(rc))
{
LogRel((USBR3PROXY ":usbProxySolarisOpenNode failed to open endpoint stat %s in read only.\n", szEndPointStat));
return rc;
}
}
if (fOpenMode == UINT32_MAX)
{
return VERR_INVALID_FMODE;
}
/*
* Open the Endpoint.
*/
if (RT_FAILURE(rc))
{
LogRel((USBR3PROXY ":usbProxySolarisOpenNode failed to open endpoint %s in mode %d\n", szEndPoint, fOpenMode));
}
else
Log((USBR3PROXY ":usbProxySolarisOpenNode Success! szEndPoint=%s Endpoint=%#x EndPtIndex=%#x\n", szEndPoint, EndPoint, EndPtIndex));
return rc;
}
/**
* Completion callback worker.
*
* @param pTimeout Pointer to a timeval struct specifying the timeout.
*/
{
/*
* Deque the completed URB.
*/
if (!pResult) /* Timeout */
{
Log(("usbProxySolarisUrbComplete: timed out\n"));
return;
}
{
Log(("usbProxySolarisUrbComplete: No pending requests.\n"));
else
return;
}
/*
* Update the URB status.
*/
#ifdef VBOX_WITH_SOLARIS_USB_ISOC
{
{
pUrbSol->cbIsocBufIn = 0;
}
else
{
pUrbSol->cbIsocBufOut = 0;
}
}
else
#endif /* !VBOX_WITH_SOLARIS_USB_ISOC */
{
pUrb->enmStatus = pResult->aio_errno ? VUSBSTATUS_STALL : VUSBSTATUS_OK; /* @todo find a better way */
}
/*
* Remove from the active list.
*/
else
{
}
/*
* Link it into the taxing list.
*/
if (pDevSol->pTaxingTail)
else
Log(("%s: usbProxySolarisUrbComplete: cb=%d EndPt=%#x enmStatus=%s\n",
pUrb->pszDesc, pUrb->cbData, pUrb->EndPt, pUrb->enmStatus == VUSBSTATUS_OK ? "VUSBSTATUS_OK" : "NotSuccessful"));
}
/**
* Completion callback for asynchronous URBs.
*
*/
static void usbProxySolarisAsyncComplete(int Sig)
{
LogFlow((USBR3PROXY ":usbProxySolarisAsyncComplete Sig=%s %d\n", Sig == SIGIO ? "SIGIO" : "Irrelevant Sig", Sig));
return usbProxySolarisUrbComplete(NULL);
}
/**
* Opens the USB device.
*
* @returns VBox status code.
* @param pProxyDev The device instance.
* @param pszAddress The path to the device in the dev and devices tree,
* @param pvBackend Backend specific pointer, unused for the solaris backend.
*/
{
LogFlow((USBR3PROXY ":usbProxySolarisOpen pProxyDev=%p pszAddress=%s pvBackend=%p\n", pProxyDev, pszAddress, pvBackend));
/*
* Initialize our USB R3 lib.
*/
int rc = USBLibInit();
if (RT_SUCCESS(rc))
{
/*
* Allocate and initialize the solaris backend data.
*/
if (pDevSol)
{
/*
* Parse out 2 paths (dev and devices tree).
*/
char szDevicesBuf[PATH_MAX];
if (cFields == 2)
{
if (RT_SUCCESS(rc))
{
/*
* Initialize all pipes.
*/
/*
* Open the default control and control status endpoint.
*/
if (RT_SUCCESS(rc))
{
/*
* @todo Fix this: Try to get the active configuration.
*/
//int iActiveCfg = -1;
//rc = usbProxySolarisGetActiveCfg(pDevSol, &iActiveCfg);
if (RT_SUCCESS(rc))
{
//pProxyDev->iActiveCfg = usbProxySolarisConfigIndex(pDevSol, iActiveCfg) > 0 ? iActiveCfg : -1;
}
else
return VINF_SUCCESS;
}
else
}
else
}
else
{
}
}
else
rc = VERR_NO_MEMORY;
}
else
USBLibTerm();
return rc;
}
/**
* Post-open initialization of the USB device.
*
* @returns VBox status code.
* @param pProxyDev The device instance.
*/
{
/* Use the first configuration as the active configure. */
if (pCfg)
{
/* Now seize all the interfaces. */
}
return VERR_INVALID_HANDLE;
}
/**
* Close the USB device.
*
* @param pProxyDev The device instance.
*/
{
/* Close the device. */
/* Reset the device without reattaching a new driver. */
/*
* Now we can close it and free all the resources.
*/
{
}
{
}
usbProxySolarisAsyncNotify(false);
USBLibTerm();
}
/**
* Reset the device.
*
* @returns VBox status code.
* @param pProxyDev The device to reset.
*/
{
/* Close all endpoints and endpoint status nodes. */
/* Stop notifications */
usbProxySolarisAsyncNotify(false);
/*
* Root hub resets that affects all devices are executed.
*/
if (fResetOnSolaris)
{
/* Reset the device without reattaching a new driver */
if (RT_SUCCESS(rc))
{
pProxyDev->cIgnoreSetConfigs = 0;
}
else
return rc;
}
else
return VINF_SUCCESS;
}
/**
* Set the active configuration.
*
* The caller makes sure that it's not called first time after open or reset
* with the active interface.
*
* @returns success indicator.
* @param pProxyDev The device instance data.
* @param iCfg The configuration value to set.
*/
{
/*
* Solaris ugen ignores any SET_CONFIGURATION requests. It does an implicitly config change while
* opening the appropriate nodes of the configuration. So what we need to do is make sure all the
* nodes of previous configuration is closed before re-opening/claiming the new configuration.
*/
return true;
if (RT_SUCCESS(rc))
{
if (iCfg > 0)
else
return true;
}
LogRel((USBR3PROXY ":usbProxySolarisSetConfig failed to seize all interfaces for iCfg %d\n", iCfg));
return false;
}
/**
* Claims an interface.
*
*
* @returns success indicator (always true).
*/
{
return true;
}
/**
* Releases an interface.
*
*
* @returns success indicator.
*/
{
return true;
}
/**
* Specify an alternate setting for the specified interface of the current configuration.
*
* @returns success indicator.
*/
{
/*
* We already open all alternate settings for all interfaces. Don't think we need to do
* anything special here. As talking with the specified alternate setting would already be
* possible as it's already open.
*/
return true;
}
/**
* Clears the halted endpoint 'EndPt'.
*/
{
/*
* Clearing the zero control pipe doesn't make sense and isn't
* supported by the USBA. Just ignore it.
*/
if (EndPt == 0)
return true;
int Status;
usbProxySolarisSetupReq(&Req, VUSB_DIR_TO_DEV | VUSB_TO_ENDPOINT, VUSB_REQ_CLEAR_FEATURE, 0, EndPt, 0);
if (Status == VUSBSTATUS_OK)
return true;
return false;
}
/**
* Allocates a Solaris URB request structure.
*
* @returns Pointer to an active URB request.
* @returns NULL on failure.
*
* @param pDevSol The solaris USB device.
*/
{
/*
* Try remove a Solaris URB from the free list, if none there allocate a new one.
*/
if (pUrbSol)
else
{
if (!pUrbSol)
return NULL;
}
/*
* Link it into the active list
*/
return pUrbSol;
}
#ifdef VBOX_WITH_SOLARIS_USB_ISOC
/**
* Allocates an isochronous buffer.
*
* @returns VBox status code.
* @param pUrbSol Pointer to the solaris URB associated with the transfer.
*/
{
if (pBuf)
{
{
pIsocPkt[i].dsc_isoc_pkt_actual_len = 0;
pIsocPkt[i].dsc_isoc_pkt_status = 0;
}
/*
* Copy the isoc. Out buffers.
*/
if (fOut)
{
}
/*
* Associate the buffer with the solaris URB to free it later as
* we perform async. transfers.
*/
if (fOut)
{
pUrbSol->cbIsocBufIn = 0;
}
else
{
/*
* Allocate space for read buffer. While perform isoc. IN request we will make
* use of both the pvIsocIn and pvIsocOut buffers (see usbProxySolarisIsocReqAsync).
*/
if (pBufIn)
{
}
else
{
return VERR_NO_MEMORY;
}
}
LogFlow((USBR3PROXY ":usbProxySolarisUrbAllocIsocBuf success! cbBufIn=%ld cbBufOut=%ld\n", cbBufIn, cbBufOut));
return VINF_SUCCESS;
}
return VERR_NO_MEMORY;
}
#endif
/**
* Frees a Solaris URB request structure.
*
* @param pDevSol The Solaris USB device.
* @param pUrbSol The Solaris URB to free.
*/
{
/*
* Remove from the active or taxing list.
*/
else
AssertFailed();
/*
* Link it into the free list.
*/
}
/**
* @copydoc USBPROXYBACK::pfnUrbQueue
*/
{
LogFlow((USBR3PROXY ":usbProxySolarisUrbQueue pUrb=%p pProxyDev=%p pDevSol=%p EndPt=%#x cbData=%d\n", pUrb, pProxyDev, pDevSol,
/*
* Allocate a solaris urb.
*/
if (!pUrbSol)
return false;
int EndPtIndex = (EndPt & USBSOL_EPADDR_NUM_MASK) + ((EndPt & USBSOL_EPADDR_DIR_MASK) ? USBSOL_MAXENDPOINTS / 2 : 0);
{
return VERR_INVALID_HANDLE;
}
Log((USBR3PROXY ":usbProxySolarisUrbQueue EndPoint=%#x EndPtIndex=%d XferType=%d Direction=%s\n", pUrb->EndPt, EndPtIndex, pUrb->enmType,
/*
* Open the endpoint.
*/
int irc = VERR_GENERAL_FAILURE;
if (RT_SUCCESS(rc))
{
/*
* Perform the transfer.
*/
{
case VUSBXFERTYPE_MSG:
{
if (EndPtIndex == 0)
{
irc = usbProxySolarisCtrlReqAsync(pDevSol->aEpFile[EndPtIndex], pSetup, (caddr_t)(pSetup + 1), pSetup->wLength,
}
else
{
irc = usbProxySolarisSendReqAsync(pDevSol->aEpFile[EndPtIndex], pSetup, (caddr_t)(pSetup + 1), pSetup->wLength,
}
break;
}
case VUSBXFERTYPE_INTR:
case VUSBXFERTYPE_BULK:
{
AssertMsgBreak(pUrb->enmDir == VUSBDIRECTION_IN || pUrb->enmDir == VUSBDIRECTION_OUT, ("invalid enmDir=%d\n", pUrb->enmDir));
break;
}
#ifdef VBOX_WITH_SOLARIS_USB_ISOC
case VUSBXFERTYPE_ISOC:
{
/*
* Allocate the isoc buffer and submit the request.
*/
if (RT_SUCCESS(irc))
break;
}
#endif
default:
{
break;
}
}
}
if ( RT_SUCCESS(rc)
&& RT_SUCCESS(irc))
{
LogFlow((USBR3PROXY ":successfully queued USB %p Endpoint=%d EndPtIndex=%d enmType=%d cbData=%d\n", pUrb, pUrb->EndPt, EndPtIndex,
return true;
}
LogRel((USBR3PROXY ":failed to transfer URB %p Endpoint=%d enmType=%d cbData=%d\n", pUrb, pUrb->EndPt, pUrb->enmType, pUrb->cbData));
return false;
}
/**
* Cancels the URB.
* The URB requires reaping, so we don't change its state.
*/
{
LogFlow((USBR3PROXY ":usbProxySolarisUrbCancel pUrb=%p pUrbSol=%p pDevSol=%p", pUrb, pUrbSol, pUrbSol->pDevSol));
}
/**
* Reap URBs in-flight on a device.
*
* @returns Pointer to a completed URB.
* @returns NULL if no URB was completed.
* @param pProxyDev The device.
* @param cMillies Number of milliseconds to wait. Use 0 to not wait at all.
*/
{
/*
* Deque URBs inflight or those landed.
*/
if ( pDevSol->pInFlightHead
|| pDevSol->pTaxingHead)
{
if (cMillies > 0)
{
}
}
/*
* Any URBs pending delivery?
*/
while ( pDevSol->pTaxingHead
&& !pUrb)
{
if (pUrbSol)
{
if (pUrb)
{
}
}
}
if (pUrb)
Log(("%s: usbProxySolarisUrbReap: pProxyDev=%s returns %p enmStatus=%d\n", pUrb->pszDesc, pProxyDev->pUsbIns->pszName, pUrb, pUrb->enmStatus));
return pUrb;
}
/**
* The Solaris USB Proxy Backend.
*/
extern const USBPROXYBACK g_USBProxyDeviceHost =
{
"host",
};