- Timestamp:
- Oct 6, 2015 1:34:45 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxUSB/win/dev/VBoxUsbRt.cpp
r58045 r58051 768 768 ULONG uTotalIfaceInfoLength = GET_USBD_INTERFACE_SIZE(pIfDr->bNumEndpoints); 769 769 NTSTATUS Status = STATUS_SUCCESS; 770 PURB pUrb = VBoxUsbToolUrbAllocZ(0, uUrbSize); 771 if (!pUrb) 772 { 773 AssertMsgFailed((__FUNCTION__": VBoxUsbToolUrbAlloc failed\n")); 774 return STATUS_NO_MEMORY; 775 } 776 777 /* 778 * Free old interface and pipe info, allocate new again 779 */ 770 PURB pUrb; 771 PUSBD_INTERFACE_INFORMATION pNewIFInfo; 772 VBOXUSB_PIPE_INFO *pNewPipeInfo; 773 780 774 if (pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo) 781 775 { 782 776 /* Clear pipes associated with the interface, else Windows may hang. */ 783 777 for(ULONG i = 0; i < pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo->NumberOfPipes; i++) 784 {785 778 VBoxUsbToolPipeClear(pDevExt->pLowerDO, pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo->Pipes[i].PipeHandle, FALSE); 786 } 787 vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo); 788 } 789 790 if (pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo) 791 { 792 vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo); 793 } 794 795 pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo = (PUSBD_INTERFACE_INFORMATION)vboxUsbMemAlloc(uTotalIfaceInfoLength); 796 if (pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo) 797 { 779 } 780 781 do { 782 /* First allocate all the structures we'll need. */ 783 pUrb = VBoxUsbToolUrbAllocZ(0, uUrbSize); 784 if (!pUrb) 785 { 786 AssertMsgFailed((__FUNCTION__": VBoxUsbToolUrbAllocZ failed\n")); 787 Status = STATUS_NO_MEMORY; 788 break; 789 } 790 791 pNewIFInfo = (PUSBD_INTERFACE_INFORMATION)vboxUsbMemAlloc(uTotalIfaceInfoLength); 792 if (!pNewIFInfo) 793 { 794 AssertMsgFailed((__FUNCTION__": Failed allocating interface storage\n")); 795 Status = STATUS_NO_MEMORY; 796 break; 797 } 798 798 799 if (pIfDr->bNumEndpoints > 0) 799 800 { 800 p DevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo = (VBOXUSB_PIPE_INFO*)vboxUsbMemAlloc(pIfDr->bNumEndpoints * sizeof(VBOXUSB_PIPE_INFO));801 if (!p DevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo)801 pNewPipeInfo = (VBOXUSB_PIPE_INFO *)vboxUsbMemAlloc(pIfDr->bNumEndpoints * sizeof(VBOXUSB_PIPE_INFO)); 802 if (!pNewPipeInfo) 802 803 { 803 AssertMsgFailed(( "VBoxUSBSetInterface: ExAllocatePool failed!\n"));804 AssertMsgFailed((__FUNCTION__": Failed allocating pipe info storage\n")); 804 805 Status = STATUS_NO_MEMORY; 806 break; 805 807 } 806 808 } 807 809 else 808 { 809 pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo = NULL; 810 } 811 812 if (NT_SUCCESS(Status)) 813 { 814 UsbBuildSelectInterfaceRequest(pUrb, uUrbSize, pDevExt->Rt.hConfiguration, InterfaceNumber, AlternateSetting); 815 pUrb->UrbSelectInterface.Interface.Length = GET_USBD_INTERFACE_SIZE(pIfDr->bNumEndpoints); 816 817 Status = VBoxUsbToolUrbPost(pDevExt->pLowerDO, pUrb, RT_INDEFINITE_WAIT); 818 if (NT_SUCCESS(Status) && USBD_SUCCESS(pUrb->UrbHeader.Status)) 810 pNewPipeInfo = NULL; 811 812 /* Now that we have all the bits, select the interface. */ 813 UsbBuildSelectInterfaceRequest(pUrb, uUrbSize, pDevExt->Rt.hConfiguration, InterfaceNumber, AlternateSetting); 814 pUrb->UrbSelectInterface.Interface.Length = GET_USBD_INTERFACE_SIZE(pIfDr->bNumEndpoints); 815 816 Status = VBoxUsbToolUrbPost(pDevExt->pLowerDO, pUrb, RT_INDEFINITE_WAIT); 817 if (NT_SUCCESS(Status) && USBD_SUCCESS(pUrb->UrbHeader.Status)) 818 { 819 /* Free the old memory and put new in. */ 820 if (pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo) 821 vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo); 822 pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo = pNewIFInfo; 823 if (pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo) 824 vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo); 825 pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo = pNewPipeInfo; 826 pNewPipeInfo = NULL; pNewIFInfo = NULL; /* Don't try to free it again. */ 827 828 USBD_INTERFACE_INFORMATION *pIfInfo = &pUrb->UrbSelectInterface.Interface; 829 memcpy(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo, pIfInfo, GET_USBD_INTERFACE_SIZE(pIfDr->bNumEndpoints)); 830 831 Assert(pIfInfo->NumberOfPipes == pIfDr->bNumEndpoints); 832 for(ULONG i = 0; i < pIfInfo->NumberOfPipes; i++) 819 833 { 820 USBD_INTERFACE_INFORMATION *pIfInfo = &pUrb->UrbSelectInterface.Interface; 821 memcpy(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo, pIfInfo, GET_USBD_INTERFACE_SIZE(pIfDr->bNumEndpoints)); 822 823 Assert(pIfInfo->NumberOfPipes == pIfDr->bNumEndpoints); 824 for(ULONG i = 0; i < pIfInfo->NumberOfPipes; i++) 825 { 826 pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo[i].EndpointAddress = pIfInfo->Pipes[i].EndpointAddress; 827 pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo[i].NextScheduledFrame = 0; 828 } 834 pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo[i].EndpointAddress = pIfInfo->Pipes[i].EndpointAddress; 835 pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo[i].NextScheduledFrame = 0; 829 836 } 830 else 831 { 832 AssertMsgFailed((__FUNCTION__": VBoxUsbToolUrbPost failed Status (0x%x) usb Status (0x%x)\n", Status, pUrb->UrbHeader.Status)); 833 /* Free up the allocated memory. */ 834 vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo); 835 pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo = NULL; 836 if (pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo) 837 { 838 vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo); 839 pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo = NULL; 840 } 841 } 842 } 843 844 } 845 else 846 { 847 AssertMsgFailed(("VBoxUSBSetInterface: ExAllocatePool failed!\n")); 848 Status = STATUS_NO_MEMORY; 849 } 850 851 VBoxUsbToolUrbFree(pUrb); 852 837 } 838 else 839 { 840 AssertMsgFailed((__FUNCTION__": VBoxUsbToolUrbPost failed Status (0x%x) usb Status (0x%x)\n", Status, pUrb->UrbHeader.Status)); 841 } 842 } while (0); 843 844 /* Clean up. */ 845 if (pUrb) 846 VBoxUsbToolUrbFree(pUrb); 847 if (pNewIFInfo) 848 vboxUsbMemFree(pNewIFInfo); 849 if (pNewPipeInfo) 850 vboxUsbMemFree(pNewPipeInfo); 851 853 852 return Status; 854 853 }
Note:
See TracChangeset
for help on using the changeset viewer.