Changeset 60550 in vbox for trunk/src/VBox/Devices/USB/usbip
- Timestamp:
- Apr 18, 2016 5:35:51 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 106679
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/USB/usbip/USBProxyDevice-usbip.cpp
r58170 r60550 231 231 typedef UsbIpReqSubmit *PUsbIpReqSubmit; 232 232 #pragma pack() 233 AssertCompileSize(UsbIpReqSubmit, 48); 233 234 234 235 /** … … 256 257 typedef UsbIpRetSubmit *PUsbIpRetSubmit; 257 258 #pragma pack() 259 AssertCompileSize(UsbIpRetSubmit, 48); 258 260 259 261 /** … … 267 269 /** The sequence number to unlink. */ 268 270 uint32_t u32SeqNum; 271 /** Padding - unused. */ 272 uint8_t abPadding[24]; 269 273 } UsbIpReqUnlink; 270 274 /** Pointer to a URB unlink request. */ 271 275 typedef UsbIpReqUnlink *PUsbIpReqUnlink; 272 276 #pragma pack() 277 AssertCompileSize(UsbIpReqUnlink, 48); 273 278 274 279 /** … … 282 287 /** Status of the request. */ 283 288 int32_t u32Status; 289 /** Padding - unused. */ 290 uint8_t abPadding[24]; 284 291 } UsbIpRetUnlink; 285 292 /** Pointer to a URB unlink request. */ 286 293 typedef UsbIpRetUnlink *PUsbIpRetUnlink; 287 294 #pragma pack() 295 AssertCompileSize(UsbIpRetUnlink, 48); 288 296 289 297 /** … … 335 343 /** Sequence number the assigned URB is identified by. */ 336 344 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; 337 349 /** Pointer to the VUSB URB. */ 338 350 PVUSBURB pVUsbUrb; … … 845 857 846 858 UsbIpReqSubmit ReqSubmit; 859 860 RT_ZERO(ReqSubmit); 861 847 862 uint32_t u32SeqNum = usbProxyUsbIpSeqNumGet(pProxyDevUsbIp); 848 863 ReqSubmit.Hdr.u32ReqRet = USBIP_CMD_SUBMIT; … … 883 898 * @param u32SeqNum The sequence number to search for. 884 899 */ 885 static PUSBPROXYURBUSBIP usbProxyUsbIpGet UrbFromSeqNum(PUSBPROXYDEVUSBIP pProxyDevUsbIp, uint32_t u32SeqNum)900 static PUSBPROXYURBUSBIP usbProxyUsbIpGetInFlightUrbFromSeqNum(PUSBPROXYDEVUSBIP pProxyDevUsbIp, uint32_t u32SeqNum) 886 901 { 887 902 bool fFound = false; … … 891 906 { 892 907 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 */ 924 static 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) 893 933 { 894 934 fFound = true; … … 981 1021 case USBPROXYUSBIPRECVSTATE_HDR_RESIDUAL: 982 1022 { 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)) 986 1026 { 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 { 992 1032 usbProxyUsbIpRetSubmitN2H(&pProxyDevUsbIp->BufRet.RetSubmit); 993 1033 … … 1020 1060 usbProxyUsbIpResetRecvState(pProxyDevUsbIp); 1021 1061 } 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 { 1024 1073 usbProxyUsbIpRetUnlinkN2H(&pProxyDevUsbIp->BufRet.RetUnlink); 1025 1074 pUrbUsbIp = pProxyDevUsbIp->pUrbUsbIp; 1026 1075 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; 1035 1081 } 1036 1082 … … 1119 1165 aSegReq[0].cbSeg = sizeof(ReqSubmit); 1120 1166 1121 1122 1167 switch (pUrb->enmType) 1123 1168 { 1124 1169 case VUSBXFERTYPE_MSG: 1125 1170 memcpy(&ReqSubmit.Setup, &pUrb->abData, sizeof(ReqSubmit.Setup)); 1171 ReqSubmit.u32TransferBufferLength -= sizeof(VUSBSETUP); 1126 1172 if (pUrb->enmDir == VUSBDIRECTION_OUT) 1127 1173 { 1128 1174 aSegReq[cSegsUsed].cbSeg = pUrb->cbData - sizeof(VUSBSETUP); 1129 1175 aSegReq[cSegsUsed].pvSeg = pUrb->abData + sizeof(VUSBSETUP); 1130 cSegsUsed++; 1176 if (aSegReq[cSegsUsed].cbSeg) 1177 cSegsUsed++; 1131 1178 } 1132 1179 LogFlowFunc(("Message (Control) URB\n")); 1133 1180 break; 1134 1181 case VUSBXFERTYPE_ISOC: 1182 LogFlowFunc(("Isochronous URB\n")); 1135 1183 ReqSubmit.u32XferFlags |= USBIP_XFER_FLAGS_ISO_ASAP; 1136 1184 ReqSubmit.u32NumIsocPkts = pUrb->cIsocPkts; … … 1161 1209 case VUSBXFERTYPE_BULK: 1162 1210 case VUSBXFERTYPE_INTR: 1211 LogFlowFunc(("Bulk URB\n")); 1163 1212 if (pUrb->enmDir == VUSBDIRECTION_OUT) 1164 1213 { … … 1467 1516 return VERR_NO_MEMORY; 1468 1517 1518 pUrbUsbIp->fCancelled = false; 1469 1519 pUrbUsbIp->pVUsbUrb = pUrb; 1470 1520 pUrb->Dev.pvPrivate = pUrbUsbIp; … … 1547 1597 UsbIpReqUnlink ReqUnlink; 1548 1598 1599 RT_ZERO(ReqUnlink); 1600 1549 1601 uint32_t u32SeqNum = usbProxyUsbIpSeqNumGet(pProxyDevUsbIp); 1550 1602 ReqUnlink.Hdr.u32ReqRet = USBIP_CMD_UNLINK; … … 1556 1608 1557 1609 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; 1559 1618 } 1560 1619
Note:
See TracChangeset
for help on using the changeset viewer.