Changeset 38488 in vbox for trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbFlt.cpp
- Timestamp:
- Aug 18, 2011 10:26:06 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbFlt.cpp
r38436 r38488 403 403 if (pDevDr == NULL) 404 404 { 405 WARN(("Failed to alloc mem for urb \n"));405 WARN(("Failed to alloc mem for urb")); 406 406 return STATUS_INSUFFICIENT_RESOURCES; 407 407 } … … 412 412 if (!NT_SUCCESS(Status)) 413 413 { 414 WARN(("getting device descriptor failed, Status (0x%x) \n", Status));414 WARN(("getting device descriptor failed, Status (0x%x)", Status)); 415 415 break; 416 416 } … … 418 418 if (vboxUsbFltBlDevMatchLocked(pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice)) 419 419 { 420 WARN(("found a known black list device, vid(0x%x), pid(0x%x), rev(0x%x) \n", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));420 WARN(("found a known black list device, vid(0x%x), pid(0x%x), rev(0x%x)", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice)); 421 421 Status = STATUS_UNSUCCESSFUL; 422 422 break; 423 423 } 424 424 425 LOG(("Device pid=%x vid=%x rev=%x \n", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));425 LOG(("Device pid=%x vid=%x rev=%x", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice)); 426 426 pDevice->idVendor = pDevDr->idVendor; 427 427 pDevice->idProduct = pDevDr->idProduct; … … 442 442 if (!NT_SUCCESS(Status)) 443 443 { 444 WARN(("reading language ID failed \n"));444 WARN(("reading language ID failed")); 445 445 if (Status == STATUS_CANCELLED) 446 446 { 447 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x) \n", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));447 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x)", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice)); 448 448 vboxUsbFltBlDevAddLocked(pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice); 449 449 Status = STATUS_UNSUCCESSFUL; … … 457 457 if (!NT_SUCCESS(Status)) 458 458 { 459 WARN(("reading serial number failed \n"));459 WARN(("reading serial number failed")); 460 460 ASSERT_WARN(pDevice->szSerial[0] == '\0', ("serial is not zero!!")); 461 461 if (Status == STATUS_CANCELLED) 462 462 { 463 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x) \n", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));463 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x)", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice)); 464 464 vboxUsbFltBlDevAddLocked(pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice); 465 465 Status = STATUS_UNSUCCESSFUL; … … 476 476 if (!NT_SUCCESS(Status)) 477 477 { 478 WARN(("reading manufacturer name failed \n"));478 WARN(("reading manufacturer name failed")); 479 479 ASSERT_WARN(pDevice->szMfgName[0] == '\0', ("szMfgName is not zero!!")); 480 480 if (Status == STATUS_CANCELLED) 481 481 { 482 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x) \n", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));482 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x)", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice)); 483 483 vboxUsbFltBlDevAddLocked(pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice); 484 484 Status = STATUS_UNSUCCESSFUL; … … 495 495 if (!NT_SUCCESS(Status)) 496 496 { 497 WARN(("reading product name failed \n"));497 WARN(("reading product name failed")); 498 498 ASSERT_WARN(pDevice->szProduct[0] == '\0', ("szProduct is not zero!!")); 499 499 if (Status == STATUS_CANCELLED) 500 500 { 501 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x) \n", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));501 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x)", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice)); 502 502 vboxUsbFltBlDevAddLocked(pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice); 503 503 Status = STATUS_UNSUCCESSFUL; … … 521 521 if (!NT_SUCCESS(Status)) 522 522 { 523 AssertMsgFailed((__FUNCTION__": IoGetDeviceProperty failed Status (0x%x) \n", Status));523 AssertMsgFailed((__FUNCTION__": IoGetDeviceProperty failed Status (0x%x)", Status)); 524 524 break; 525 525 } … … 535 535 if (!NT_SUCCESS(Status)) 536 536 { 537 AssertMsgFailed((__FUNCTION__": RtlUnicodeStringToAnsiString failed Status (0x%x) \n", Status));537 AssertMsgFailed((__FUNCTION__": RtlUnicodeStringToAnsiString failed Status (0x%x)", Status)); 538 538 break; 539 539 } … … 543 543 if (!NT_SUCCESS(Status)) 544 544 { 545 AssertMsgFailed((__FUNCTION__": VBoxUsbToolGetDeviceSpeed failed Status (0x%x) \n", Status));545 AssertMsgFailed((__FUNCTION__": VBoxUsbToolGetDeviceSpeed failed Status (0x%x)", Status)); 546 546 break; 547 547 } 548 548 } 549 549 #endif 550 LOG((": strings: '%s':'%s':'%s' (lang ID %x) \n",550 LOG((": strings: '%s':'%s':'%s' (lang ID %x)", 551 551 pDevice->szMfgName, pDevice->szProduct, pDevice->szSerial, langId)); 552 552 } … … 754 754 } 755 755 756 typedef struct VBOXUSBFLTCHECKWALKER 757 { 758 PVBOXUSBFLTCTX pContext; 759 } VBOXUSBFLTCHECKWALKER, *PVBOXUSBFLTCHECKWALKER; 760 761 static DECLCALLBACK(BOOLEAN) vboxUsbFltFilterCheckWalker(PFILE_OBJECT pFile, PDEVICE_OBJECT pTopDo, PDEVICE_OBJECT pHubDo, PVOID pvContext) 762 { 763 PVBOXUSBFLTCHECKWALKER pData = (PVBOXUSBFLTCHECKWALKER)pvContext; 764 PVBOXUSBFLTCTX pContext = pData->pContext; 765 766 LOG(("Visiting pFile(0x%p), pTopDo(0x%p), pHubDo(0x%p), oContext(0x%p)", pFile, pTopDo, pHubDo, pContext)); 767 KIRQL Irql = KeGetCurrentIrql(); 768 ASSERT_WARN(Irql == PASSIVE_LEVEL, ("unexpected IRQL (%d)", Irql)); 769 770 771 772 PDEVICE_RELATIONS pDevRelations = NULL; 773 774 NTSTATUS Status = VBoxUsbMonQueryBusRelations(pTopDo, pFile, &pDevRelations); 775 if (Status == STATUS_SUCCESS && pDevRelations) 776 { 777 ULONG cReplugPdos = pDevRelations->Count; 778 LIST_ENTRY ReplugDevList; 779 InitializeListHead(&ReplugDevList); 780 for (ULONG k = 0; k < pDevRelations->Count; ++k) 781 { 782 PDEVICE_OBJECT pDevObj = pDevRelations->Objects[k]; 783 784 LOG(("Found existing USB PDO 0x%p", pDevObj)); 785 VBOXUSBFLT_LOCK_ACQUIRE(); 786 PVBOXUSBFLT_DEVICE pDevice = vboxUsbFltDevGetLocked(pDevObj); 787 if (pDevice) 788 { 789 LOG(("Found existing device info (0x%p) for PDO 0x%p", pDevice, pDevObj)); 790 bool bReplug = vboxUsbFltDevCheckReplugLocked(pDevice, pContext); 791 if (bReplug) 792 { 793 LOG(("Replug needed for device (0x%p)", pDevice)); 794 InsertHeadList(&ReplugDevList, &pDevice->RepluggingLe); 795 vboxUsbFltDevRetain(pDevice); 796 /* do not dereference object since we will use it later */ 797 } 798 else 799 { 800 LOG(("Replug NOT needed for device (0x%p)", pDevice)); 801 ObDereferenceObject(pDevObj); 802 } 803 804 VBOXUSBFLT_LOCK_RELEASE(); 805 806 pDevRelations->Objects[k] = NULL; 807 --cReplugPdos; 808 ASSERT_WARN((uint32_t)cReplugPdos < UINT32_MAX/2, ("cReplugPdos(%d) state broken", cReplugPdos)); 809 continue; 810 } 811 VBOXUSBFLT_LOCK_RELEASE(); 812 813 LOG(("NO device info found for PDO 0x%p", pDevObj)); 814 VBOXUSBFLT_DEVICE Device; 815 Status = vboxUsbFltDevPopulate(&Device, pDevObj /*, FALSE /* only need filter properties */); 816 if (NT_SUCCESS(Status)) 817 { 818 uintptr_t uId = 0; 819 bool fFilter = false; 820 bool fIsOneShot = false; 821 VBOXUSBFLT_LOCK_ACQUIRE(); 822 PVBOXUSBFLTCTX pCtx = vboxUsbFltDevMatchLocked(&Device, &uId, 823 false, /* do not remove a one-shot filter */ 824 &fFilter, &fIsOneShot); 825 VBOXUSBFLT_LOCK_RELEASE(); 826 LOG(("Matching Info: Filter (0x%p), pCtx(0x%p), fFilter(%d), fIsOneShot(%d)", uId, pCtx, (int)fFilter, (int)fIsOneShot)); 827 if (fFilter) 828 { 829 LOG(("Matching: This device SHOULD be filtered")); 830 /* this device needs to be filtered, but it's not, 831 * leave the PDO in array to issue a replug request for it 832 * later on */ 833 continue; 834 } 835 } 836 else 837 { 838 WARN(("vboxUsbFltDevPopulate for PDO 0x%p failed with Status 0x%x", pDevObj, Status)); 839 } 840 841 LOG(("Matching: This device should NOT be filtered")); 842 /* this device should not be filtered, and it's not */ 843 ObDereferenceObject(pDevObj); 844 pDevRelations->Objects[k] = NULL; 845 --cReplugPdos; 846 ASSERT_WARN((uint32_t)cReplugPdos < UINT32_MAX/2, ("cReplugPdos is %d", cReplugPdos)); 847 } 848 849 LOG(("(%d) non-matched PDOs to be replugged", cReplugPdos)); 850 851 if (cReplugPdos) 852 { 853 for (ULONG k = 0; k < pDevRelations->Count; ++k) 854 { 855 if (!pDevRelations->Objects[k]) 856 continue; 857 858 Status = vboxUsbFltPdoReplug(pDevRelations->Objects[k]); 859 ASSERT_WARN(Status == STATUS_SUCCESS, ("vboxUsbFltPdoReplug ailed Status(0x%x)", Status)); 860 ObDereferenceObject(pDevRelations->Objects[k]); 861 if (!--cReplugPdos) 862 break; 863 } 864 865 ASSERT_WARN(!cReplugPdos, ("cReplugPdosreached zero!")); 866 } 867 868 vboxUsbFltReplugList(&ReplugDevList); 869 870 ExFreePool(pDevRelations); 871 } 872 else 873 { 874 WARN(("VBoxUsbMonQueryBusRelations failed for DO(0x%p), Status(0x%x), pDevRelations(0x%p)", 875 pTopDo, Status, pDevRelations)); 876 } 877 878 LOG(("Done Visiting pFile(0x%p), pTopDo(0x%p), pHubDo(0x%p), oContext(0x%p)", pFile, pTopDo, pHubDo, pContext)); 879 880 return TRUE; 881 } 882 756 883 NTSTATUS VBoxUsbFltFilterCheck(PVBOXUSBFLTCTX pContext) 757 884 { 758 NTSTATUS Status;759 UNICODE_STRING szStandardControllerName[RT_ELEMENTS(lpszStandardControllerName)];760 885 KIRQL Irql = KeGetCurrentIrql(); 761 A ssert(Irql == PASSIVE_LEVEL);886 ASSERT_WARN(Irql == PASSIVE_LEVEL, ("unexpected IRQL (%d)", Irql)); 762 887 763 888 LOG(("Running filters, Context (0x%p)..", pContext)); 764 889 765 for (int i=0;i<RT_ELEMENTS(lpszStandardControllerName);i++) 766 { 767 szStandardControllerName[i].Length = 0; 768 szStandardControllerName[i].MaximumLength = 0; 769 szStandardControllerName[i].Buffer = 0; 770 771 RtlInitUnicodeString(&szStandardControllerName[i], lpszStandardControllerName[i]); 772 } 773 774 for (int i = 0; i < 16; i++) 775 { 776 char szHubName[32]; 777 WCHAR szwHubName[32]; 778 UNICODE_STRING UnicodeName; 779 ANSI_STRING AnsiName; 780 PDEVICE_OBJECT pHubDevObj; 781 PFILE_OBJECT pHubFileObj; 782 783 sprintf(szHubName, "\\Device\\USBPDO-%d", i); 784 785 UnicodeName.Length = 0; 786 UnicodeName.MaximumLength = sizeof (szwHubName); 787 UnicodeName.Buffer = szwHubName; 788 789 RtlInitAnsiString(&AnsiName, szHubName); 790 RtlAnsiStringToUnicodeString(&UnicodeName, &AnsiName, FALSE); 791 792 Status = IoGetDeviceObjectPointer(&UnicodeName, FILE_READ_DATA, &pHubFileObj, &pHubDevObj); 793 if (Status == STATUS_SUCCESS) 794 { 795 LOG(("IoGetDeviceObjectPointer for %s returned %p %p\n", szHubName, pHubDevObj, pHubFileObj)); 796 797 if (pHubDevObj->DriverObject 798 && pHubDevObj->DriverObject->DriverName.Buffer 799 && pHubDevObj->DriverObject->DriverName.Length 800 ) 801 { 802 for (int j = 0; j < RT_ELEMENTS(lpszStandardControllerName); ++j) 803 { 804 if (!RtlCompareUnicodeString(&szStandardControllerName[j], &pHubDevObj->DriverObject->DriverName, TRUE /* case insensitive */)) 805 { 806 PDEVICE_RELATIONS pDevRelations = NULL; 807 808 LOG(("Flt Associated driver ")); 809 LOG_USTR(&pHubDevObj->DriverObject->DriverName); 810 LOG((" -> related dev obj=0x%p", pHubDevObj)); 811 812 Status = VBoxUsbMonQueryBusRelations(pHubDevObj, pHubFileObj, &pDevRelations); 813 if (Status == STATUS_SUCCESS && pDevRelations) 814 { 815 ULONG cReplugPdos = pDevRelations->Count; 816 LIST_ENTRY ReplugDevList; 817 InitializeListHead(&ReplugDevList); 818 for (ULONG k = 0; k < pDevRelations->Count; ++k) 819 { 820 PDEVICE_OBJECT pDevObj = pDevRelations->Objects[k]; 821 822 LOG(("Found existing USB PDO 0x%p", pDevObj)); 823 VBOXUSBFLT_LOCK_ACQUIRE(); 824 PVBOXUSBFLT_DEVICE pDevice = vboxUsbFltDevGetLocked(pDevObj); 825 if (pDevice) 826 { 827 LOG(("Found existing device info (0x%p) for PDO 0x%p", pDevice, pDevObj)); 828 bool bReplug = vboxUsbFltDevCheckReplugLocked(pDevice, pContext); 829 if (bReplug) 830 { 831 LOG(("Replug needed for device (0x%p)", pDevice)); 832 InsertHeadList(&ReplugDevList, &pDevice->RepluggingLe); 833 vboxUsbFltDevRetain(pDevice); 834 /* do not dereference object since we will use it later */ 835 } 836 else 837 { 838 LOG(("Replug NOT needed for device (0x%p)", pDevice)); 839 ObDereferenceObject(pDevObj); 840 } 841 842 VBOXUSBFLT_LOCK_RELEASE(); 843 844 pDevRelations->Objects[k] = NULL; 845 --cReplugPdos; 846 ASSERT_WARN((uint32_t)cReplugPdos < UINT32_MAX/2, ("cReplugPdos(%d) state broken", cReplugPdos)); 847 continue; 848 } 849 VBOXUSBFLT_LOCK_RELEASE(); 850 851 LOG(("NO device info found for PDO 0x%p", pDevObj)); 852 VBOXUSBFLT_DEVICE Device; 853 Status = vboxUsbFltDevPopulate(&Device, pDevObj /*, FALSE /* only need filter properties */); 854 if (NT_SUCCESS(Status)) 855 { 856 uintptr_t uId = 0; 857 bool fFilter = false; 858 bool fIsOneShot = false; 859 VBOXUSBFLT_LOCK_ACQUIRE(); 860 PVBOXUSBFLTCTX pCtx = vboxUsbFltDevMatchLocked(&Device, &uId, 861 false, /* do not remove a one-shot filter */ 862 &fFilter, &fIsOneShot); 863 VBOXUSBFLT_LOCK_RELEASE(); 864 LOG(("Matching Info: Filter (0x%p), pCtx(0x%p), fFilter(%d), fIsOneShot(%d)", uId, pCtx, (int)fFilter, (int)fIsOneShot)); 865 if (fFilter) 866 { 867 LOG(("Matching: This device SHOULD be filtered")); 868 /* this device needs to be filtered, but it's not, 869 * leave the PDO in array to issue a replug request for it 870 * later on */ 871 continue; 872 } 873 } 874 else 875 { 876 WARN(("vboxUsbFltDevPopulate for PDO 0x%p failed with Status 0x%x", pDevObj, Status)); 877 } 878 879 LOG(("Matching: This device should NOT be filtered")); 880 /* this device should not be filtered, and it's not */ 881 ObDereferenceObject(pDevObj); 882 pDevRelations->Objects[k] = NULL; 883 --cReplugPdos; 884 ASSERT_WARN((uint32_t)cReplugPdos < UINT32_MAX/2, ("cReplugPdos is %d", cReplugPdos)); 885 } 886 887 LOG(("(%d) non-matched PDOs to be replugged", cReplugPdos)); 888 889 if (cReplugPdos) 890 { 891 for (ULONG k = 0; k < pDevRelations->Count; ++k) 892 { 893 if (!pDevRelations->Objects[k]) 894 continue; 895 896 Status = vboxUsbFltPdoReplug(pDevRelations->Objects[k]); 897 ASSERT_WARN(Status == STATUS_SUCCESS, ("vboxUsbFltPdoReplug ailed Status(0x%x)", Status)); 898 ObDereferenceObject(pDevRelations->Objects[k]); 899 if (!--cReplugPdos) 900 break; 901 } 902 903 ASSERT_WARN(!cReplugPdos, ("cReplugPdosreached zero!")); 904 } 905 906 vboxUsbFltReplugList(&ReplugDevList); 907 908 ExFreePool(pDevRelations); 909 } 910 else 911 { 912 WARN(("VBoxUsbMonQueryBusRelations failed for DO(0x%p), Status(0x%x), pDevRelations(0x%p)", 913 pHubDevObj, Status, pDevRelations)); 914 } 915 } 916 else 917 { 918 LOG(("driver name not match, was:")); 919 LOG_USTR(&pHubDevObj->DriverObject->DriverName); 920 LOG(("but expected:")); 921 LOG_USTR(&szStandardControllerName[j]); 922 } 923 } 924 } 925 else 926 { 927 LOG(("null driver object (0x%p) or name buffer (0x%p), length(%d)", pHubDevObj->DriverObject, 928 pHubDevObj->DriverObject ? pHubDevObj->DriverObject->DriverName.Buffer : NULL, 929 pHubDevObj->DriverObject ? pHubDevObj->DriverObject->DriverName.Length : 0)); 930 } 931 ObDereferenceObject(pHubFileObj); 932 } 933 } 890 VBOXUSBFLTCHECKWALKER Data; 891 Data.pContext = pContext; 892 vboxUsbMonHubDevWalk(vboxUsbFltFilterCheckWalker, &Data, VBOXUSBMONHUBWALK_F_FDO); 934 893 935 894 LOG(("DONE Running filters, Context (0x%p)", pContext)); … … 1029 988 *pId = 0; 1030 989 /* LOG the filter details. */ 1031 LOG((__FUNCTION__": %s %s %s \n",990 LOG((__FUNCTION__": %s %s %s", 1032 991 USBFilterGetString(pFilter, USBFILTERIDX_MANUFACTURER_STR) ? USBFilterGetString(pFilter, USBFILTERIDX_MANUFACTURER_STR) : "<null>", 1033 992 USBFilterGetString(pFilter, USBFILTERIDX_PRODUCT_STR) ? USBFilterGetString(pFilter, USBFILTERIDX_PRODUCT_STR) : "<null>", 1034 993 USBFilterGetString(pFilter, USBFILTERIDX_SERIAL_NUMBER_STR) ? USBFilterGetString(pFilter, USBFILTERIDX_SERIAL_NUMBER_STR) : "<null>")); 1035 994 #ifdef VBOX_USB_WITH_VERBOSE_LOGGING 1036 LOG(("VBoxUSBClient::addFilter: idVendor=%#x idProduct=%#x bcdDevice=%#x bDeviceClass=%#x bDeviceSubClass=%#x bDeviceProtocol=%#x bBus=%#x bPort=%#x Type%#x \n",995 LOG(("VBoxUSBClient::addFilter: idVendor=%#x idProduct=%#x bcdDevice=%#x bDeviceClass=%#x bDeviceSubClass=%#x bDeviceProtocol=%#x bBus=%#x bPort=%#x Type%#x", 1037 996 USBFilterGetNum(pFilter, USBFILTERIDX_VENDOR_ID), 1038 997 USBFilterGetNum(pFilter, USBFILTERIDX_PRODUCT_ID), … … 1394 1353 { 1395 1354 pDevice->enmState = VBOXUSBFLT_DEVSTATE_CAPTURED; 1396 LOG(("The proxy notified proxy start for the captured device 0x%x \n", pDevice));1355 LOG(("The proxy notified proxy start for the captured device 0x%x", pDevice)); 1397 1356 vboxUsbFltDevRetain(pDevice); 1398 1357 vboxUsbFltSignalChangeLocked(); … … 1415 1374 { 1416 1375 /* this is due to devie was physically removed */ 1417 LOG(("The proxy notified proxy stop for the captured device 0x%x, current state %d \n", pDevice, pDevice->enmState));1376 LOG(("The proxy notified proxy stop for the captured device 0x%x, current state %d", pDevice, pDevice->enmState)); 1418 1377 pDevice->enmState = VBOXUSBFLT_DEVSTATE_CAPTURING; 1419 1378 vboxUsbFltSignalChangeLocked();
Note:
See TracChangeset
for help on using the changeset viewer.