VirtualBox

Changeset 60550 in vbox for trunk/src/VBox/Devices/USB/usbip


Ignore:
Timestamp:
Apr 18, 2016 5:35:51 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106679
Message:

Devices/USB/USBProxyDevice-usbip.cpp: Fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/usbip/USBProxyDevice-usbip.cpp

    r58170 r60550  
    231231typedef UsbIpReqSubmit *PUsbIpReqSubmit;
    232232#pragma pack()
     233AssertCompileSize(UsbIpReqSubmit, 48);
    233234
    234235/**
     
    256257typedef UsbIpRetSubmit *PUsbIpRetSubmit;
    257258#pragma pack()
     259AssertCompileSize(UsbIpRetSubmit, 48);
    258260
    259261/**
     
    267269    /** The sequence number to unlink. */
    268270    uint32_t       u32SeqNum;
     271    /** Padding - unused. */
     272    uint8_t        abPadding[24];
    269273} UsbIpReqUnlink;
    270274/** Pointer to a URB unlink request. */
    271275typedef UsbIpReqUnlink *PUsbIpReqUnlink;
    272276#pragma pack()
     277AssertCompileSize(UsbIpReqUnlink, 48);
    273278
    274279/**
     
    282287    /** Status of the request. */
    283288    int32_t        u32Status;
     289    /** Padding - unused. */
     290    uint8_t        abPadding[24];
    284291} UsbIpRetUnlink;
    285292/** Pointer to a URB unlink request. */
    286293typedef UsbIpRetUnlink *PUsbIpRetUnlink;
    287294#pragma pack()
     295AssertCompileSize(UsbIpRetUnlink, 48);
    288296
    289297/**
     
    335343    /** Sequence number the assigned URB is identified by. */
    336344    uint32_t           u32SeqNumUrb;
     345    /** Sequence number of the unlink command if the URB was cancelled. */
     346    uint32_t           u32SeqNumUrbUnlink;
     347    /** Flag whether the URB was cancelled. */
     348    bool               fCancelled;
    337349    /** Pointer to the VUSB URB. */
    338350    PVUSBURB           pVUsbUrb;
     
    845857
    846858    UsbIpReqSubmit ReqSubmit;
     859
     860    RT_ZERO(ReqSubmit);
     861
    847862    uint32_t u32SeqNum = usbProxyUsbIpSeqNumGet(pProxyDevUsbIp);
    848863    ReqSubmit.Hdr.u32ReqRet           = USBIP_CMD_SUBMIT;
     
    883898 * @param  u32SeqNum         The sequence number to search for.
    884899 */
    885 static PUSBPROXYURBUSBIP usbProxyUsbIpGetUrbFromSeqNum(PUSBPROXYDEVUSBIP pProxyDevUsbIp, uint32_t u32SeqNum)
     900static PUSBPROXYURBUSBIP usbProxyUsbIpGetInFlightUrbFromSeqNum(PUSBPROXYDEVUSBIP pProxyDevUsbIp, uint32_t u32SeqNum)
    886901{
    887902    bool fFound = false;
     
    891906    {
    892907        if (pIt->u32SeqNumUrb == u32SeqNum)
     908        {
     909            fFound = true;
     910            break;
     911        }
     912    }
     913
     914    return fFound ? pIt : NULL;
     915}
     916
     917/**
     918 * Returns the URB matching the given sequence number from the cancel list.
     919 *
     920 * @returns pointer to the URB matching the given sequence number or NULL
     921 * @param  pProxyDevUsbIp    The USB/IP proxy device data.
     922 * @param  u32SeqNum         The sequence number to search for.
     923 */
     924static PUSBPROXYURBUSBIP usbProxyUsbIpGetCancelledUrbFromSeqNum(PUSBPROXYDEVUSBIP pProxyDevUsbIp, uint32_t u32SeqNum)
     925{
     926    bool fFound = false;
     927    PUSBPROXYURBUSBIP pIt;
     928
     929    RTListForEach(&pProxyDevUsbIp->ListUrbsInFlight, pIt, USBPROXYURBUSBIP, NodeList)
     930    {
     931        if (   pIt->u32SeqNumUrbUnlink == u32SeqNum
     932            && pIt->fCancelled == true)
    893933        {
    894934            fFound = true;
     
    9811021                case USBPROXYUSBIPRECVSTATE_HDR_RESIDUAL:
    9821022                {
    983                     /* Get the URB from the in flight list. */
    984                     pProxyDevUsbIp->pUrbUsbIp = usbProxyUsbIpGetUrbFromSeqNum(pProxyDevUsbIp, RT_N2H_U32(pProxyDevUsbIp->BufRet.Hdr.u32SeqNum));
    985                     if (pProxyDevUsbIp->pUrbUsbIp)
     1023                    /** @todo: Verify that the directions match, verify that the length doesn't exceed the buffer. */
     1024
     1025                    switch (RT_N2H_U32(pProxyDevUsbIp->BufRet.Hdr.u32ReqRet))
    9861026                    {
    987                         /** @todo: Verify that the directions match, verify that the length doesn't exceed the buffer. */
    988 
    989                         switch (RT_N2H_U32(pProxyDevUsbIp->BufRet.Hdr.u32ReqRet))
    990                         {
    991                             case USBIP_RET_SUBMIT:
     1027                        case USBIP_RET_SUBMIT:
     1028                            /* Get the URB from the in flight list. */
     1029                            pProxyDevUsbIp->pUrbUsbIp = usbProxyUsbIpGetInFlightUrbFromSeqNum(pProxyDevUsbIp, RT_N2H_U32(pProxyDevUsbIp->BufRet.Hdr.u32SeqNum));
     1030                            if (pProxyDevUsbIp->pUrbUsbIp)
     1031                            {
    9921032                                usbProxyUsbIpRetSubmitN2H(&pProxyDevUsbIp->BufRet.RetSubmit);
    9931033
     
    10201060                                    usbProxyUsbIpResetRecvState(pProxyDevUsbIp);
    10211061                                }
    1022                                 break;
    1023                             case USBIP_RET_UNLINK:
     1062                            }
     1063                            else
     1064                            {
     1065                                LogRel(("USB/IP: Received reply with sequence number %u doesn't match any local URB\n", pProxyDevUsbIp->BufRet.Hdr.u32SeqNum));
     1066                                usbProxyUsbIpResetRecvState(pProxyDevUsbIp);
     1067                            }
     1068                            break;
     1069                        case USBIP_RET_UNLINK:
     1070                            pProxyDevUsbIp->pUrbUsbIp = usbProxyUsbIpGetCancelledUrbFromSeqNum(pProxyDevUsbIp, RT_N2H_U32(pProxyDevUsbIp->BufRet.Hdr.u32SeqNum));
     1071                            if (pProxyDevUsbIp->pUrbUsbIp)
     1072                            {
    10241073                                usbProxyUsbIpRetUnlinkN2H(&pProxyDevUsbIp->BufRet.RetUnlink);
    10251074                                pUrbUsbIp = pProxyDevUsbIp->pUrbUsbIp;
    10261075                                pUrbUsbIp->pVUsbUrb->enmStatus = usbProxyUsbIpVUsbStatusConvertFromStatus(pProxyDevUsbIp->BufRet.RetUnlink.u32Status);
    1027                                 usbProxyUsbIpResetRecvState(pProxyDevUsbIp);
    1028                                 break;
    1029                         }
    1030                     }
    1031                     else
    1032                     {
    1033                         LogRel(("USB/IP: Received reply with sequence number doesn't match any local URB\n", pProxyDevUsbIp->BufRet.Hdr.u32SeqNum));
    1034                         usbProxyUsbIpResetRecvState(pProxyDevUsbIp);
     1076                            }
     1077                            /* else: Probably received the data for the URB and is complete already. */
     1078
     1079                            usbProxyUsbIpResetRecvState(pProxyDevUsbIp);
     1080                            break;
    10351081                    }
    10361082
     
    11191165    aSegReq[0].cbSeg = sizeof(ReqSubmit);
    11201166
    1121 
    11221167    switch (pUrb->enmType)
    11231168    {
    11241169        case VUSBXFERTYPE_MSG:
    11251170            memcpy(&ReqSubmit.Setup, &pUrb->abData, sizeof(ReqSubmit.Setup));
     1171            ReqSubmit.u32TransferBufferLength -= sizeof(VUSBSETUP);
    11261172            if (pUrb->enmDir == VUSBDIRECTION_OUT)
    11271173            {
    11281174                aSegReq[cSegsUsed].cbSeg = pUrb->cbData - sizeof(VUSBSETUP);
    11291175                aSegReq[cSegsUsed].pvSeg = pUrb->abData + sizeof(VUSBSETUP);
    1130                 cSegsUsed++;
     1176                if (aSegReq[cSegsUsed].cbSeg)
     1177                    cSegsUsed++;
    11311178            }
    11321179            LogFlowFunc(("Message (Control) URB\n"));
    11331180            break;
    11341181        case VUSBXFERTYPE_ISOC:
     1182            LogFlowFunc(("Isochronous URB\n"));
    11351183            ReqSubmit.u32XferFlags |= USBIP_XFER_FLAGS_ISO_ASAP;
    11361184            ReqSubmit.u32NumIsocPkts = pUrb->cIsocPkts;
     
    11611209        case VUSBXFERTYPE_BULK:
    11621210        case VUSBXFERTYPE_INTR:
     1211            LogFlowFunc(("Bulk URB\n"));
    11631212            if (pUrb->enmDir == VUSBDIRECTION_OUT)
    11641213            {
     
    14671516        return VERR_NO_MEMORY;
    14681517
     1518    pUrbUsbIp->fCancelled = false;
    14691519    pUrbUsbIp->pVUsbUrb = pUrb;
    14701520    pUrb->Dev.pvPrivate = pUrbUsbIp;
     
    15471597    UsbIpReqUnlink ReqUnlink;
    15481598
     1599    RT_ZERO(ReqUnlink);
     1600
    15491601    uint32_t u32SeqNum = usbProxyUsbIpSeqNumGet(pProxyDevUsbIp);
    15501602    ReqUnlink.Hdr.u32ReqRet           = USBIP_CMD_UNLINK;
     
    15561608
    15571609    usbProxyUsbIpReqUnlinkH2N(&ReqUnlink);
    1558     return RTTcpWrite(pProxyDevUsbIp->hSocket, &ReqUnlink, sizeof(ReqUnlink));
     1610    int rc = RTTcpWrite(pProxyDevUsbIp->hSocket, &ReqUnlink, sizeof(ReqUnlink));
     1611    if (RT_SUCCESS(rc))
     1612    {
     1613        pUrbUsbIp->u32SeqNumUrbUnlink = u32SeqNum;
     1614        pUrbUsbIp->fCancelled         = true;
     1615    }
     1616
     1617    return rc;
    15591618}
    15601619
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette