third_party/virtualbox/src/VBox/Devices/USB/VUSBUrb.cpp
/**
 * Allocates the extra state data required for a control pipe.
 *
 * @returns Pointer to the allocated and initialized state data.
 * @returns NULL on out of memory condition.
 * @param   pUrb    A URB we can copy default data from.
 */
Allocates the extra state data required for a control pipe.
@returns Pointer to the allocated and initialized state data.
@returns NULL on out of memory condition.
@param   pUrb    A URB we can copy default data from.
Allocates the extra state data required for a control pipe . @returns Pointer to the allocated and initialized state data . @returns NULL on out of memory condition . @param pUrb A URB we can copy default data from .
static PVUSBCTRLEXTRA vusbMsgAllocExtraData(PVUSBURB pUrb)
{
    PVUSBCTRLEXTRA pExtra;
    const size_t cbMax = sizeof(VUSBURBVUSBINT) + sizeof(pExtra->Urb.abData) + sizeof(VUSBSETUP);
    pExtra = (PVUSBCTRLEXTRA)RTMemAllocZ(RT_UOFFSETOF_DYN(VUSBCTRLEXTRA, Urb.abData[cbMax]));
    if (pExtra)
    {
        pExtra->enmStage = CTLSTAGE_SETUP;
        pExtra->pMsg = (PVUSBSETUP)pExtra->Urb.abData;
        pExtra->pbCur = (uint8_t *)(pExtra->pMsg + 1);
        pExtra->cbMax = cbMax;
        pExtra->Urb.u32Magic = VUSBURB_MAGIC;
        pExtra->Urb.enmState = VUSBURBSTATE_ALLOCATED;
        pExtra->Urb.fCompleting = false;
#ifdef LOG_ENABLED
        RTStrAPrintf(&pExtra->Urb.pszDesc, "URB %p msg->%p", &pExtra->Urb, pUrb);
#endif
        pExtra->Urb.pVUsb = (PVUSBURBVUSB)&pExtra->Urb.abData[sizeof(pExtra->Urb.abData) + sizeof(VUSBSETUP)];
        pExtra->Urb.pVUsb->pUrb = &pExtra->Urb;
        pExtra->Urb.pVUsb->pDev = pUrb->pVUsb->pDev;
        pExtra->Urb.pVUsb->pfnFree = vusbMsgFreeUrb;
        pExtra->Urb.pVUsb->pvFreeCtx = &pExtra->Urb;
        pExtra->Urb.DstAddress = pUrb->DstAddress;
        pExtra->Urb.EndPt = pUrb->EndPt;
        pExtra->Urb.enmType = VUSBXFERTYPE_MSG;
        pExtra->Urb.enmDir = VUSBDIRECTION_INVALID;
        pExtra->Urb.enmStatus = VUSBSTATUS_INVALID;
        vusbUrbAssert(&pExtra->Urb);
    }
    return pExtra;
}
static PVUSBCTRLEXTRA vusbMsgAllocExtraData ( PVUSBURB pUrb ) { PVUSBCTRLEXTRA pExtra ; const size_t cbMax = sizeof ( VUSBURBVUSBINT ) + sizeof ( pExtra -> Urb . abData ) + sizeof ( VUSBSETUP ) ; pExtra = ( PVUSBCTRLEXTRA ) RTMemAllocZ ( RT_UOFFSETOF_DYN ( VUSBCTRLEXTRA , Urb . abData [ cbMax ] ) ) ; if ( pExtra ) { pExtra -> enmStage = CTLSTAGE_SETUP ; pExtra -> pMsg = ( PVUSBSETUP ) pExtra -> Urb . abData ; pExtra -> pbCur = ( uint8_t * ) ( pExtra -> pMsg + 1 ) ; pExtra -> cbMax = cbMax ; pExtra -> Urb . u32Magic = VUSBURB_MAGIC ; pExtra -> Urb . enmState = VUSBURBSTATE_ALLOCATED ; pExtra -> Urb . fCompleting = false ; #ifdef LOG_ENABLED RTStrAPrintf ( & pExtra -> Urb . pszDesc , " " , & pExtra -> Urb , pUrb ) ; #endif pExtra -> Urb . pVUsb = ( PVUSBURBVUSB ) & pExtra -> Urb . abData [ sizeof ( pExtra -> Urb . abData ) + sizeof ( VUSBSETUP ) ] ; pExtra -> Urb . pVUsb -> pUrb = & pExtra -> Urb ; pExtra -> Urb . pVUsb -> pDev = pUrb -> pVUsb -> pDev ; pExtra -> Urb . pVUsb -> pfnFree = vusbMsgFreeUrb ; pExtra -> Urb . pVUsb -> pvFreeCtx = & pExtra -> Urb ; pExtra -> Urb . DstAddress = pUrb -> DstAddress ; pExtra -> Urb . EndPt = pUrb -> EndPt ; pExtra -> Urb . enmType = VUSBXFERTYPE_MSG ; pExtra -> Urb . enmDir = VUSBDIRECTION_INVALID ; pExtra -> Urb . enmStatus = VUSBSTATUS_INVALID ; vusbUrbAssert ( & pExtra -> Urb ) ; } return pExtra ; }
Allocates the extra state data required for a control pipe.
Allocates the extra state data required for a control pipe .
/** @todo reuse these? */ //pExtra->fOk = false; //pExtra->cbLeft = 0; //pExtra->Urb.Dev.pvProxyUrb = NULL; //pExtra->Urb.pVUsb->pCtrlUrb = NULL; //pExtra->Urb.pVUsb->pNext = NULL; //pExtra->Urb.pVUsb->ppPrev = NULL; //pExtra->Urb.Hci = {0}; //pExtra->Urb.Dev.pvProxyUrb = NULL; //pExtra->Urb.fShortNotOk = false; //pExtra->Urb.cbData = 0;