USBProxyDevice-darwin.cpp revision 0aefc1b31a411a6cdfa560b5d95d96b47f6fd9e4
/* $Id$ */
/** @file
* USB device proxy - the Darwin backend.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DRV_USBPROXY
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include <IOKit/IOKitLib.h>
#include <mach/mach_error.h>
#include <IOKit/IOCFPlugIn.h>
#include <iprt/critsect.h>
#include "../USBProxyDevice.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** An experiment... */
//#define USE_LOW_LATENCY_API 1
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** Forward declaration of the Darwin interface structure. */
typedef struct USBPROXYIFOSX *PUSBPROXYIFOSX;
/**
* A low latency isochronous buffer.
*
* These are allocated in chunks on an interface level, see USBPROXYISOCBUFCOL.
*/
typedef struct USBPROXYISOCBUF
{
/** Whether this buffer is in use or not. */
bool volatile fUsed;
/** Pointer to the buffer. */
void *pvBuf;
/** Pointer to an array of 8 frames. */
/**
* Isochronous buffer collection (associated with an interface).
*
* These are allocated in decent sized chunks and there isn't supposed
* to be too many of these per interface.
*/
typedef struct USBPROXYISOCBUFCOL
{
/** Write or Read buffers? */
/** The next buffer collection on this interface. */
struct USBPROXYISOCBUFCOL *pNext;
/** The buffer. */
void *pvBuffer;
/** The frame. */
void *pvFrames;
/** The buffers.
* The number of buffers here is decided by pvFrame begin allocated in
* PAGE_SIZE chunks. The size of IOUSBLowLatencyIsocFrame is 16 bytes
* and we require 8 of those per buffer. PAGE_SIZE / (16 * 8) = 32.
* @remarks Don't allocate too many as it may temporarily halt the system if
* some pool is low / exhausted. (Contiguous memory woes on mach.)
*/
/**
* Per-urb data for the Darwin usb proxy backend.
*
* This is required to track in-flight and landed URBs
* since we take down the URBs in a different thread (perhaps).
*/
typedef struct USBPROXYURBOSX
{
/** Pointer to the next Darwin URB. */
struct USBPROXYURBOSX *pNext;
/** Pointer to the previous Darwin URB. */
struct USBPROXYURBOSX *pPrev;
/** The millisecond timestamp when this URB was submitted. */
/** Pointer to the VUSB URB.
* This is set to NULL if canceled. */
/** Pointer to the Darwin device. */
struct USBPROXYDEVOSX *pDevOsX;
/** The transfer type. */
/** Union with data depending on transfer type. */
union
{
/** The control message. */
/** The Isochronous Data. */
struct
{
#ifdef USE_LOW_LATENCY_API
/** The low latency isochronous buffer. */
/** Array of frames parallel to the one in VUSBURB. (Same as pBuf->paFrames.) */
#else
/** Array of frames parallel to the one in VUSBURB. */
#endif
} Isoc;
} u;
/**
* Per-pipe data for the Darwin usb proxy backend.
*/
typedef struct USBPROXYPIPEOSX
{
/** The endpoint number. */
/** The IOKit pipe reference. */
/** The pipe Transfer type type. */
/** The pipe direction. */
/** The endpoint interval. (interrupt) */
/** The max packet size. */
/** The next frame number (isochronous pipes only). */
typedef struct RUNLOOPREFLIST
{
typedef RUNLOOPREFLIST **PPRUNLOOPREFLIST;
/**
* Per-interface data for the Darwin usb proxy backend.
*/
typedef struct USBPROXYIFOSX
{
/** Pointer to the next interface. */
struct USBPROXYIFOSX *pNext;
/** The interface number. */
/** The current alternative interface setting.
* This is used to skip unnecessary SetAltInterface calls. */
/** The interface class. (not really used) */
/** The interface protocol. (not really used) */
/** The number of pipes. */
/** Array containing all the pipes. (Currently unsorted.) */
/** The IOUSBDeviceInterface. */
/** The run loop source for the async operations on the interface level. */
/** List of isochronous buffer collections.
* These are allocated on demand by the URB queuing routine and then recycled until the interface is destroyed. */
/** Pointer to a pointer to an darwin interface. */
typedef USBPROXYIFOSX **PPUSBPROXYIFOSX;
/**
* Per-device Data for the Darwin usb proxy backend.
*/
typedef struct USBPROXYDEVOSX
{
/** The USB Device IOService object. */
/** The IOUSBDeviceInterface. */
/** The run loop source for the async operations on the device level
* (i.e. the default control pipe stuff). */
/** we want to add and remove RunLoopSourceRefs to run loop's of
* every EMT thread participated in USB processing. */
/** Pointer to the proxy device instance. */
/** Pointer to the first interface. */
/** Pointer to the last interface. */
/** Critical section protecting the lists. */
/** The list of free Darwin URBs. Singly linked. */
/** The list of active Darwin URBs. Doubly linked.
* Only the split head will appear in this list. */
/** The list of landed Darwin URBs. Doubly linked.
* Only the split head will appear in this list. */
/** The tail of the landed Darwin URBs. */
/* Runloop source for waking up the reaper thread. */
/** List of threads used for reaping which can be woken up. */
/** Runloop reference of the thread reaping. */
volatile CFRunLoopRef hRunLoopReaping;
/** Flag whether the reaping thread is about the be waked. */
volatile bool fReapingThreadWake;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The runloop mode we use.
* Since it's difficult to remove this, we leak it to prevent crashes.
* @bugref{4407} */
/** The IO Master Port.
* Not worth cleaning up. */
/**
* Init once callback that sets up g_MasterPort and g_pRunLoopMode.
*
* @returns IPRT status code.
*
* @param pvUser1 NULL, ignored.
* @param pvUser2 NULL, ignored.
*/
{
int rc;
if (krc == KERN_SUCCESS)
{
g_pRunLoopMode = CFStringCreateWithCString(kCFAllocatorDefault, "VBoxUsbProxyMode", kCFStringEncodingUTF8);
if (g_pRunLoopMode)
return VINF_SUCCESS;
}
else
return rc;
}
/**
* Adds Source ref to current run loop and adds it the list of runloops.
*/
{
return VINF_SUCCESS;
/* Add to the list */
if (!pListNode)
return VERR_NO_MEMORY;
return VINF_SUCCESS;
}
/*
* Removes all source reference from mode of run loop's we've registered them.
*
*/
{
while (!RTListIsEmpty(pHead))
{
/* XXX: Should Release Reference? */
}
return VINF_SUCCESS;
}
/**
* Allocates a Darwin URB request structure.
*
* @returns Pointer to an active URB request.
* @returns NULL on failure.
*
* @param pDevOsX The darwin proxy device.
*/
{
/*
* Try remove a Darwin URB from the free list, if none there allocate a new one.
*/
if (pUrbOsX)
else
{
if (!pUrbOsX)
return NULL;
}
/*
* Link it into the active list
*/
return pUrbOsX;
}
#ifdef USE_LOW_LATENCY_API
/**
* Allocates an low latency isochronous buffer.
*
* @returns VBox status code.
* @param pUrbOsX The OsX URB to allocate it for.
* @param pIf The interface to allocated it from.
*/
{
/*
* Walk the buffer collection list and look for an unused one.
*/
{
return VINF_SUCCESS;
}
/*
* Didn't find an empty one, create a new buffer collection and take the first buffer.
*/
IOReturn irc = (*pIf->ppIfI)->LowLatencyCreateBuffer(pIf->ppIfI, &pNew->pvBuffer, 8192 * RT_ELEMENTS(pNew->aBuffers), enmLLType);
{
}
if (irc == kIOReturnSuccess)
{
irc = (*pIf->ppIfI)->LowLatencyCreateBuffer(pIf->ppIfI, &pNew->pvFrames, PAGE_SIZE, kUSBLowLatencyFrameListBuffer);
{
}
if (irc == kIOReturnSuccess)
{
{
//pNew->aBuffers[i].fUsed = false;
}
#if 0 /* doesn't help :-/ */
/*
* If this is the first time we're here, try mess with the policy?
*/
{
}
#endif
return VINF_SUCCESS;
}
/* bail out */
}
return RTErrConvertFromDarwin(irc);
}
#endif /* USE_LOW_LATENCY_API */
/**
* Frees a Darwin URB request structure.
*
* @param pDevOsX The darwin proxy device.
* @param pUrbOsX The Darwin URB to free.
*/
{
/*
* Remove from the active or taxing list.
*/
else
AssertFailed();
#ifdef USE_LOW_LATENCY_API
/*
* Free low latency stuff.
*/
{
}
#endif
/*
* Link it into the free list.
*/
}
/**
* Translate the IOKit status code to a VUSB status.
*
* @returns VUSB URB status code.
* @param irc IOKit status code.
*/
{
switch (irc)
{
/* IOKit OHCI VUSB */
//case kIOUSBBitstufErr: /* 2 */ return VUSBSTATUS_;
//case kIOUSBDataToggleErr: /* 3 */ return VUSBSTATUS_;
//case kIOUSBPIDCheckErr: /* 6 */ return VUSBSTATUS_;
//case kIOUSBWrongPIDErr: /* 7 */ return VUSBSTATUS_;
//case kIOUSBReserved1Err: /* 10 */ return VUSBSTATUS_;
//case kIOUSBReserved2Err: /* 11 */ return VUSBSTATUS_;
//case kIOUSBBufferOverrunErr: /* 12 */ return VUSBSTATUS_;
//case kIOUSBBufferUnderrunErr: /* 13 */ return VUSBSTATUS_;
/* Other errors */
case kIOUSBTransactionTimeout: return VUSBSTATUS_DNR;
//case kIOReturnAborted: return VUSBSTATUS_CRC; - see on SET_INTERFACE...
default:
return VUSBSTATUS_STALL;
}
}
/**
* Completion callback for an async URB transfer.
*
* @param pvUrbOsX The Darwin URB.
* @param irc The status of the operation.
* @param Size Possible the transfer size.
*/
{
/*
* Do status updates.
*/
if (pUrb)
{
{
#ifdef USE_LOW_LATENCY_API
/* copy the data. */
//if (pUrb->enmDir == VUSBDIRECTION_IN)
#endif
Log3(("AsyncComplete isoc - raw data (%d bytes):\n"
{
#ifdef USE_LOW_LATENCY_API
Log2((" %d{%d/%d-%x-%RX64}", i, pUrbOsX->u.Isoc.aFrames[i].frActCount, pUrb->aIsocPkts[i].cb, pUrbOsX->u.Isoc.aFrames[i].frStatus,
RT_MAKE_U64(pUrbOsX->u.Isoc.aFrames[i].frTimeStamp.lo, pUrbOsX->u.Isoc.aFrames[i].frTimeStamp.hi) ));
#else
Log2((" %d{%d/%d-%x}", i, pUrbOsX->u.Isoc.aFrames[i].frActCount, pUrb->aIsocPkts[i].cb, pUrbOsX->u.Isoc.aFrames[i].frStatus));
#endif
pUrb->aIsocPkts[i].enmStatus = vusbProxyDarwinStatusToVUsbStatus(pUrbOsX->u.Isoc.aFrames[i].frStatus);
}
Log2(("\n"));
#if 0 /** @todo revisit this, wasn't working previously. */
#endif
pUrb->enmStatus = VUSBSTATUS_OK; /* Don't use 'irc'. OHCI expects OK unless it's a really bad error. */
}
else
{
}
}
/*
* Remove from the active list.
*/
else
{
}
/*
* Link it into the taxing list.
*/
if (pDevOsX->pTaxingTail)
else
LogFlow(("%s: usbProxyDarwinUrbAsyncComplete: cb=%d EndPt=%#x irc=%#x (%d)\n",
}
/**
* Release all interfaces (current config).
*
* @param pDevOsX The darwin proxy device.
*/
{
while (pIf)
{
if (pIf->RunLoopSrcRef)
{
int rc = usbProxyDarwinRemoveSourceRefFromAllRunLoops((PRTLISTANCHOR)&pIf->HeadOfRunLoopLst, pIf->RunLoopSrcRef);
}
while (pIf->pIsocBufCols)
{
}
}
}
/**
* Get the properties all the pipes associated with an interface.
*
* This is used when we seize all the interface and after SET_INTERFACE.
*
* @returns VBox status code.
* @param pDevOsX The darwin proxy device.
* @param pIf The interface to get pipe props for.
*/
{
/*
* Get the pipe (endpoint) count (it might have changed - even on open).
*/
int rc = VINF_SUCCESS;
if (irc != kIOReturnSuccess)
{
if (irc == kIOReturnNoDevice)
else
return rc;
}
/*
* Get the properties of each pipe.
*/
{
if (irc != kIOReturnSuccess)
{
LogRel(("USB: Failed to query properties for pipe %#d / interface %#x on device '%s'. (prot=%#x class=%#x)\n",
if (irc == kIOReturnNoDevice)
else
break;
}
/* reconstruct bEndpoint */
Log2(("usbProxyDarwinGetPipeProperties: #If=%d EndPt=%#x Dir=%d Type=%d PipeRef=%#x MaxPktSize=%#x Interval=%#x\n",
pIf->u8Interface, pIf->aPipes[i].u8Endpoint, pIf->aPipes[i].u8Direction, pIf->aPipes[i].u8TransferType,
}
/** @todo sort or hash these for speedy lookup... */
return VINF_SUCCESS;
}
/**
* Seize all interfaces (current config).
*
* @returns VBox status code.
* @param pDevOsX The darwin proxy device.
* @param fMakeTheBestOfIt If set we will not give up on error. This is for
* use during SET_CONFIGURATION and similar.
*/
{
/*
* Create a interface enumerator for all the interface (current config).
*/
int rc;
if (irc == kIOReturnSuccess)
{
/*
* Iterate the interfaces.
*/
rc = VINF_SUCCESS;
{
/*
* Create a plug-in and query the IOUSBInterfaceInterface (cute name).
*/
if (krc == KERN_SUCCESS)
{
{
/*
* Query some basic properties first.
* (This means we can print more informative messages on failure
* to seize the interface.)
*/
if (irc == kIOReturnSuccess)
if (irc == kIOReturnSuccess)
if (irc == kIOReturnSuccess)
UInt8 cEndpoints = 0;
if (irc == kIOReturnSuccess)
if (irc == kIOReturnSuccess)
{
/*
* Try seize the interface.
*/
if (irc == kIOReturnSuccess)
{
if (pIf)
{
/*
* Create the per-interface entry and query the
* endpoint data.
*/
/* initialize the entry */
if (RT_SUCCESS(rc))
{
/*
* Create the async event source and add it to the
* default current run loop.
* (Later: Add to the worker thread run loop instead.)
*/
if (irc == kIOReturnSuccess)
{
pIf->RunLoopSrcRef);
/*
* Just link the interface into the list and we're good.
*/
Log(("USB: Seized interface %#x (alt=%d prot=%#x class=%#x)\n",
else
continue;
}
}
/* failure cleanup. */
}
}
else if (irc == kIOReturnExclusiveAccess)
{
LogRel(("USB: Interface %#x on device '%s' is being used by another process. (prot=%#x class=%#x)\n",
}
else
{
LogRel(("USB: Failed to open interface %#x on device '%s'. (prot=%#x class=%#x) krc=%#x\n",
}
}
else
{
LogRel(("USB: Failed to query interface properties on device '%s', irc=%#x.\n",
}
}
else if (RT_SUCCESS(rc))
}
else if (RT_SUCCESS(rc))
if (!fMakeTheBestOfIt)
{
break;
}
} /* iterate */
}
else if (irc == kIOReturnNoDevice)
else
{
}
return rc;
}
/**
* Find a particular interface.
*
* @returns The requested interface or NULL if not found.
* @param pDevOsX The darwin proxy device.
* @param u8Interface The interface number.
*/
{
return pIf;
/* AssertMsgFailed(("Cannot find If#=%d\n", u8Interface)); - the 3rd quickcam interface is capture by the ****ing audio crap. */
return NULL;
}
/**
* Find a particular endpoint.
*
* @returns The requested interface or NULL if not found.
* @param pDevOsX The darwin proxy device.
* @param u8Endpoint The endpoint.
* @param pu8PipeRef Where to store the darwin pipe ref.
* @param ppPipe Where to store the darwin pipe pointer. (optional)
*/
static PUSBPROXYIFOSX usbProxyDarwinGetInterfaceForEndpoint(PUSBPROXYDEVOSX pDevOsX, uint8_t u8Endpoint,
{
{
while (i-- > 0)
{
if (ppPipe)
return pIf;
}
}
return NULL;
}
/**
* Gets an unsigned 32-bit integer value.
*
* @param DictRef The dictionary.
* @param KeyStrRef The key name.
* @param pu32 Where to store the key value.
*/
static bool usbProxyDarwinDictGetU32(CFMutableDictionaryRef DictRef, CFStringRef KeyStrRef, uint32_t *pu32)
{
if (ValRef)
{
return true;
}
*pu32 = 0;
return false;
}
/**
* Gets an unsigned 64-bit integer value.
*
* @param DictRef The dictionary.
* @param KeyStrRef The key name.
* @param pu64 Where to store the key value.
*/
static bool usbProxyDarwinDictGetU64(CFMutableDictionaryRef DictRef, CFStringRef KeyStrRef, uint64_t *pu64)
{
if (ValRef)
{
return true;
}
*pu64 = 0;
return false;
}
{
return;
}
/* -=-=-=-=-=- The exported methods -=-=-=-=-=- */
/**
* Opens the USB Device.
*
* @returns VBox status code.
* @param pProxyDev The device instance.
* The format of this string is something iokit.c in Main defines, currently
* it's sequences of "[l|s]=<value>" separated by ";".
* @param pvBackend Backend specific pointer, unused for the Darwin backend.
*/
static DECLCALLBACK(int) usbProxyDarwinOpen(PUSBPROXYDEV pProxyDev, const char *pszAddress, void *pvBackend)
{
int vrc;
/*
* Init globals once.
*/
/*
* The idea here was to create a matching directory with the sessionID
* and locationID included, however this doesn't seem to work. So, we'll
* use the product id and vendor id to limit the set of matching device
* and manually match these two properties. sigh.
* (Btw. vendor and product id must be used *together* apparently.)
*
* Wonder if we could use the entry path? Docs indicates says we must
* use IOServiceGetMatchingServices and I'm not in a mood to explore
* this subject further right now. Maybe check this later.
*/
uint64_t u64SessionId = 0;
uint32_t u32LocationId = 0;
const char *psz = pszAddress;
do
{
switch (chValue)
{
case 'l':
break;
case 's':
break;
case 'p':
case 'v':
{
#if 0 /* Guess what, this doesn't 'ing work either! */
CFDictionarySetValue(RefMatchingDict, chValue == 'p' ? CFSTR(kUSBProductID) : CFSTR(kUSBVendorID), Num);
#endif
break;
}
default:
}
if (*psz == ';')
psz++;
} while (*psz);
unsigned cMatches = 0;
{
cMatches++;
kern_return_t krc = IORegistryEntryCreateCFProperties(USBDevice, &PropsRef, kCFAllocatorDefault, kNilOptions);
if (krc == KERN_SUCCESS)
{
if ( ( !u64SessionId
&& u64CurSessionId == u64SessionId))
&& ( !u32LocationId
&& u32CurLocationId == u32LocationId))
)
{
break;
}
}
}
USBDevices = NULL;
if (!USBDevice)
{
return VERR_VUSB_DEVICE_NAME_NOT_FOUND;
}
/*
* Call the USBLib init to make sure we're a valid VBoxUSB client.
* For now we'll ignore failures here and just plunge on, it might still work...
*/
vrc = USBLibInit();
if (RT_FAILURE(vrc))
#endif
/*
* Create a plugin interface for the device and query its IOUSBDeviceInterface.
*/
if (irc == kIOReturnSuccess)
{
{
/*
* Try open the device for exclusive access.
* If we fail, we'll try figure out who is using the device and
* convince them to let go of it...
*/
if (irc == kIOReturnExclusiveAccess)
{
RTThreadSleep(20);
}
if (irc == kIOReturnSuccess)
{
/*
* Init a proxy device instance.
*/
if (RT_SUCCESS(vrc))
{
/*
* Try seize all the interface.
*/
if (RT_SUCCESS(vrc))
{
/*
* Create the async event source and add it to the run loop.
*/
if (irc == kIOReturnSuccess)
{
/*
* Determine the active configuration.
* Can cause hangs, so drop it for now.
*/
/** @todo test Palm. */
//uint8_t u8Cfg;
//irc = (*ppDevI)->GetConfiguration(ppDevI, &u8Cfg);
if (irc != kIOReturnNoDevice)
{
CtxRunLoopSource.version = 0;
{
//pProxyDev->iActiveCfg = irc == kIOReturnSuccess ? u8Cfg : -1;
return VINF_SUCCESS; /* return */
}
else
{
}
}
}
else
}
/* else: already bitched */
}
}
else if (irc == kIOReturnExclusiveAccess)
{
}
else
{
}
}
else
{
}
}
else
{
LogRel(("USB: Failed to open device '%s', plug-in creation failed with irc=%#x.\n", pszAddress, irc));
}
USBLibTerm();
#endif
return vrc;
}
/**
* Closes the proxy device.
*/
{
/*
* Release interfaces we've laid claim to, then reset the device
* and finally close it.
*/
/* ?? */
if (pDevOsX->RunLoopSrcRef)
{
int rc = usbProxyDarwinRemoveSourceRefFromAllRunLoops(&pDevOsX->HeadOfRunLoopLst, pDevOsX->RunLoopSrcRef);
}
if (pDevOsX->hRunLoopSrcWakeRef)
{
int rc = usbProxyDarwinRemoveSourceRefFromAllRunLoops(&pDevOsX->HeadOfRunLoopWakeLst, pDevOsX->hRunLoopSrcWakeRef);
}
#ifndef VBOX_WITH_NEW_USB_CODE_ON_DARWIN
if (irc == kIOReturnSuccess)
#endif
{
}
/*
* Free all the resources.
*/
{
//RTMemFree(pUrbOsX); - leak these for now, fix later.
}
{
}
USBLibTerm();
#endif
LogFlow(("usbProxyDarwinClose: returns\n"));
}
/**
* Reset a device.
*
* @returns VBox status code.
* @param pDev The device to reset.
*/
{
int rc;
if (irc == kIOReturnSuccess)
{
/** @todo Some docs say that some drivers will do a default config, check this out ... */
pProxyDev->cIgnoreSetConfigs = 0;
rc = VINF_SUCCESS;
}
else if (irc == kIOReturnNoDevice)
else
{
}
return rc;
}
/**
* SET_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 to set.
*/
{
LogFlow(("usbProxyDarwinSetConfig: pProxyDev=%s cfg=%#x\n",
if (irc != kIOReturnSuccess)
{
return RTErrConvertFromDarwin(irc);
}
return VINF_SUCCESS;
}
/**
* Claims an interface.
*
*
* @returns success indicator (always VINF_SUCCESS).
*/
{
return VINF_SUCCESS;
}
/**
* Releases an interface.
*
*
* @returns success indicator.
*/
{
return VINF_SUCCESS;
}
/**
* SET_INTERFACE.
*
* @returns success indicator.
*/
{
LogFlow(("usbProxyDarwinSetInterface: pProxyDev=%s iIf=%#x iAlt=%#x iCurAlt=%#x\n",
if (pIf)
{
/* Avoid SetAlternateInterface when possible as it will recreate the pipes. */
{
if (irc == kIOReturnSuccess)
{
return VINF_SUCCESS;
}
}
else
{
/*
* Just send the request anyway?
*/
return VINF_SUCCESS;
}
}
LogFlow(("usbProxyDarwinSetInterface: pProxyDev=%s eiIf=%#x iAlt=%#x - failure - pIf=%p irc=%#x\n",
return RTErrConvertFromDarwin(irc);
}
/**
* Clears the halted endpoint 'EndPt'.
*/
{
LogFlow(("usbProxyDarwinClearHaltedEp: pProxyDev=%s EndPt=%#x\n", pProxyDev->pUsbIns->pszName, EndPt));
/*
* Clearing the zero control pipe doesn't make sense and isn't
* supported by the API. Just ignore it.
*/
if (EndPt == 0)
return VINF_SUCCESS;
/*
* method. (The ResetPipe and ClearPipeStall methods will not send the
* CLEAR_FEATURE(ENDPOINT_HALT) request that this method implements.)
*/
if (pIf)
{
if (irc == kIOReturnSuccess)
return VINF_SUCCESS;
AssertMsg(irc == kIOReturnNoDevice || irc == kIOReturnNotResponding, ("irc=#x (control pipe?)\n", irc));
}
LogFlow(("usbProxyDarwinClearHaltedEp: pProxyDev=%s EndPt=%#x - failure - pIf=%p irc=%#x\n",
return RTErrConvertFromDarwin(irc);
}
/**
* @copydoc USBPROXYBACK::pfnUrbQueue
*/
{
LogFlow(("%s: usbProxyDarwinUrbQueue: pProxyDev=%s pUrb=%p EndPt=%d cbData=%d\n",
/*
* Find the target interface / pipe.
*/
{
if (!pIf)
{
LogFlow(("%s: usbProxyDarwinUrbQueue: pProxyDev=%s EndPt=%d cbData=%d - can't find interface / pipe!!!\n",
return VERR_NOT_FOUND;
}
}
/* else: pIf == NULL -> default control pipe.*/
/*
* Allocate a Darwin urb.
*/
if (!pUrbOsX)
return VERR_NO_MEMORY;
/*
* Submit the request.
*/
{
case VUSBXFERTYPE_MSG:
{
if (pIf)
else
break;
}
case VUSBXFERTYPE_BULK:
case VUSBXFERTYPE_INTR:
{
else
break;
}
case VUSBXFERTYPE_ISOC:
{
#ifdef USE_LOW_LATENCY_API
/* Allocate an isochronous buffer and copy over the data. */
else
#endif
/* Get the current frame number (+2) and make sure it doesn't
overlap with the previous request. See WARNING in
ApplUSBUHCI::CreateIsochTransfer for details on the +2. */
FrameNo += 2;
for (unsigned j = 0; ; j++)
{
unsigned i;
{
#ifdef USE_LOW_LATENCY_API
#endif
}
{
#ifdef USE_LOW_LATENCY_API
#endif
}
#ifdef USE_LOW_LATENCY_API
else
#else
else
#endif
if ( irc != kIOReturnIsoTooOld
|| j >= 5)
{
Log(("%s: usbProxyDarwinUrbQueue: isoc: u64NextFrameNo=%RX64 FrameNo=%RX64 #Frames=%d j=%d (pipe=%d)\n",
if (irc == kIOReturnSuccess)
break;
}
/* try again... */
FrameNo += j;
}
break;
}
default:
break;
}
/*
* Success?
*/
{
return VINF_SUCCESS;
}
switch (irc)
{
case kIOUSBPipeStalled:
{
Log(("%s: usbProxyDarwinUrbQueue: pProxyDev=%s EndPt=%d cbData=%d - failed irc=%#x! (stall)\n",
return VINF_SUCCESS;
}
}
Log(("%s: usbProxyDarwinUrbQueue: pProxyDev=%s EndPt=%d cbData=%d - failed irc=%#x!\n",
return RTErrConvertFromDarwin(irc);
}
/**
* 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.
*/
{
{
/* Return immediately. */
return NULL;
}
/*
* If we've got any in-flight URBs, excercise the runloop.
*/
if (pDevOsX->pInFlightHead)
if ( !pDevOsX->pTaxingHead
&& cMillies)
/*
* Any URBs pending delivery?
*/
while ( pDevOsX->pTaxingHead
&& !pUrb)
{
if (pUrbOsX)
{
if (pUrb)
{
}
}
}
if (pUrb)
LogFlowFunc(("LEAVE: %s: pProxyDev=%s returns %p\n", pUrb->pszDesc, pProxyDev->pUsbIns->pszName, pUrb));
else
return pUrb;
}
/**
* Cancels a URB.
*
* The URB requires reaping, so we don't change its state.
*
* @remark There isn't any way to cancel a specific async request
* on darwin. The interface only supports the aborting of
* all URBs pending on an interface / pipe pair. Provided
* the card does the URB cancelling before submitting new
* requests, we should probably be fine...
*/
{
LogFlow(("%s: usbProxyDarwinUrbCancel: pProxyDev=%s EndPt=%d\n",
/*
* Determine the interface / endpoint ref and invoke AbortPipe.
*/
else
{
if (pIf)
else /* this may happen if a device reset, set configuration or set interface has been performed. */
Log(("usbProxyDarwinUrbCancel: pProxyDev=%s pUrb=%p EndPt=%d - cannot find the interface / pipe!\n",
}
int rc = VINF_SUCCESS;
if (irc != kIOReturnSuccess)
{
Log(("usbProxyDarwinUrbCancel: pProxyDev=%s pUrb=%p EndPt=%d -> %#x!\n",
}
return rc;
}
{
CFRunLoopRef hRunLoopWake = (CFRunLoopRef)ASMAtomicReadPtr((void * volatile *)&pDevOsX->hRunLoopReaping);
if (hRunLoopWake)
{
}
return VINF_SUCCESS;
}
/**
* The Darwin USB Proxy Backend.
*/
extern const USBPROXYBACK g_USBProxyDeviceHost =
{
/* pszName */
"host",
/* cbBackend */
sizeof(USBPROXYDEVOSX),
NULL,
0
};