Changeset 51871 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Jul 4, 2014 2:21:03 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
r51849 r51871 418 418 */ 419 419 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGenHostonlyConnectionName(PCWSTR DevName, WCHAR *pBuf, PULONG pcbBuf); 420 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection 420 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection(LPWSTR pGuid, PCWSTR NewName); 421 421 422 422 static BOOL vboxNetCfgWinRemoveAllNetDevicesOfIdCallback(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext) 423 423 { 424 HRESULT hr = S_OK;425 424 SP_REMOVEDEVICE_PARAMS rmdParams; 426 WCHAR pWCfgGuidString[50] = {L''}; 427 425 memset(&rmdParams, 0, sizeof(SP_REMOVEDEVICE_PARAMS)); 428 426 rmdParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER); 429 427 rmdParams.ClassInstallHeader.InstallFunction = DIF_REMOVE; 430 428 rmdParams.Scope = DI_REMOVEDEVICE_GLOBAL; 431 rmdParams.HwProfile = 0; 432 433 if (SetupDiSetClassInstallParams(hDevInfo,pDev,&rmdParams.ClassInstallHeader,sizeof(rmdParams)))434 { 435 if (SetupDiSetSelectedDevice 436 { 437 /* Figure out NetCfgInstanceId */438 HKEY h key = SetupDiOpenDevRegKey(hDevInfo,429 430 if (SetupDiSetClassInstallParams(hDevInfo,pDev, 431 &rmdParams.ClassInstallHeader, sizeof(rmdParams))) 432 { 433 if (SetupDiSetSelectedDevice(hDevInfo, pDev)) 434 { 435 /* Figure out NetCfgInstanceId. */ 436 HKEY hKey = SetupDiOpenDevRegKey(hDevInfo, 439 437 pDev, 440 438 DICS_FLAG_GLOBAL, … … 442 440 DIREG_DRV, 443 441 KEY_READ); 444 if (hkey == INVALID_HANDLE_VALUE) 445 NonStandardLogFlow(("SetupDiOpenDevRegKey failed (0x%08X)", GetLastError())); 442 if (hKey == INVALID_HANDLE_VALUE) 443 { 444 NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: SetupDiOpenDevRegKey failed with error %ld\n", 445 GetLastError())); 446 } 446 447 else 447 448 { 448 DWORD cbSize = sizeof(pWCfgGuidString); 449 WCHAR wszCfgGuidString[50] = { L'' }; 450 DWORD cbSize = sizeof(wszCfgGuidString); 449 451 DWORD dwValueType; 450 DWORD ret = RegQueryValueExW (hkey, L"NetCfgInstanceId", NULL,451 &dwValueType, (LPBYTE) pWCfgGuidString, &cbSize);452 DWORD ret = RegQueryValueExW(hKey, L"NetCfgInstanceId", NULL, 453 &dwValueType, (LPBYTE)wszCfgGuidString, &cbSize); 452 454 if (ret == ERROR_SUCCESS) 453 455 { 454 /* Figure out device name */ 455 WCHAR DevName[256], TempName[256]; 456 ULONG cbName = sizeof(TempName); 456 NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: Processing device ID \"%S\"\n", 457 wszCfgGuidString)); 458 459 /* Figure out device name. */ 460 WCHAR wszDevName[256], wszTempName[256]; 461 ULONG cbName = sizeof(wszTempName); 462 457 463 if (SetupDiGetDeviceRegistryPropertyW(hDevInfo, pDev, 458 SPDRP_FRIENDLYNAME , /* INDWORD Property,*/459 NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/460 (PBYTE)DevName, /*OUT PBYTE PropertyBuffer,*/461 sizeof(DevName), /* INDWORD PropertyBufferSize,*/462 NULL /*OUT PDWORD RequiredSize OPTIONAL*/))464 SPDRP_FRIENDLYNAME, /* IN DWORD Property,*/ 465 NULL, /* OUT PDWORD PropertyRegDataType, OPTIONAL*/ 466 (PBYTE)wszDevName, /* OUT PBYTE PropertyBuffer,*/ 467 sizeof(wszDevName), /* IN DWORD PropertyBufferSize,*/ 468 NULL /* OUT PDWORD RequiredSize OPTIONAL*/)) 463 469 { 464 470 /* … … 467 473 * to rename a newly created connection (see @bugref{6740}). 468 474 */ 469 HRESULT hr _tmp = VBoxNetCfgWinGenHostonlyConnectionName(DevName,TempName, &cbName);470 wcscat_s( TempName, sizeof(TempName), L" removed");475 HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName(wszDevName, wszTempName, &cbName); 476 wcscat_s(wszTempName, sizeof(wszTempName), L" removed"); 471 477 if (SUCCEEDED(hr)) 472 hr _tmp = VBoxNetCfgWinRenameConnection(pWCfgGuidString,TempName);478 hr = VBoxNetCfgWinRenameConnection(wszCfgGuidString, wszTempName); 473 479 //NonStandardLogFlow(("VBoxNetCfgWinRenameConnection(%S,%S) => 0x%x\n", pWCfgGuidString, TempName, hr_tmp)); 474 480 } 475 481 else 476 482 { 477 NonStandardLogFlow(("Failed to get 'friendly name' property for %S\n", pWCfgGuidString)); 483 NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: Failed to get friendly name for device \"%S\"\n", 484 wszCfgGuidString)); 478 485 } 479 486 } 480 487 else 481 488 { 482 NonStandardLogFlow(("RegQueryValueExW(L\"NetCfgInstanceId\") failed with %d\n", ret)); 483 } 484 485 RegCloseKey (hkey); 486 } 487 488 if (SetupDiCallClassInstaller(DIF_REMOVE,hDevInfo,pDev)) 489 NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: Querying instance ID failed with %d\n", 490 ret)); 491 } 492 493 RegCloseKey(hKey); 494 } 495 496 if (SetupDiCallClassInstaller(DIF_REMOVE, hDevInfo, pDev)) 489 497 { 490 498 SP_DEVINSTALL_PARAMS devParams; 499 memset(&devParams, 0, sizeof(SP_DEVINSTALL_PARAMS)); 491 500 devParams.cbSize = sizeof(devParams); 492 if (SetupDiGetDeviceInstallParams(hDevInfo,pDev,&devParams)) 493 { 494 if (devParams.Flags & (DI_NEEDRESTART|DI_NEEDREBOOT)) 501 502 if (SetupDiGetDeviceInstallParams(hDevInfo, pDev, &devParams)) 503 { 504 if ( (devParams.Flags & DI_NEEDRESTART) 505 || (devParams.Flags & DI_NEEDREBOOT)) 495 506 { 496 hr = S_FALSE; 497 NonStandardLog(("!!!REBOOT REQUIRED!!!\n")); 507 NonStandardLog(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: A reboot is required\n")); 498 508 } 499 509 } 510 else 511 NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: SetupDiGetDeviceInstallParams failed with %ld\n", 512 GetLastError())); 500 513 } 501 514 else 502 { 503 DWORD dwErr = GetLastError(); 504 NonStandardLogFlow(("SetupDiCallClassInstaller failed with %ld\n", dwErr)); 505 hr = HRESULT_FROM_WIN32(dwErr); 506 } 515 NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: SetupDiCallClassInstaller failed with %ld\n", 516 GetLastError())); 507 517 } 508 518 else 509 { 510 DWORD dwErr = GetLastError(); 511 NonStandardLogFlow(("SetupDiSetSelectedDevice failed with %ld\n", dwErr)); 512 hr = HRESULT_FROM_WIN32(dwErr); 513 } 519 NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: SetupDiSetSelectedDevice failed with %ld\n", 520 GetLastError())); 514 521 } 515 522 else 516 { 517 DWORD dwErr = GetLastError(); 518 NonStandardLogFlow(("SetupDiSetClassInstallParams failed with %ld\n", dwErr)); 519 hr = HRESULT_FROM_WIN32(dwErr); 520 } 521 523 NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: SetupDiSetClassInstallParams failed with %ld\n", 524 GetLastError())); 525 526 /* Continue enumeration. */ 522 527 return TRUE; 523 528 } … … 532 537 { 533 538 PVBOXNECTFGWINPROPCHANGE pPc = (PVBOXNECTFGWINPROPCHANGE)pContext; 534 HRESULT hr = S_OK; 539 535 540 SP_PROPCHANGE_PARAMS PcParams; 536 541 memset (&PcParams, 0, sizeof (PcParams)); 537 538 PcParams.ClassInstallHeader.cbSize = sizeof (SP_CLASSINSTALL_HEADER); 542 PcParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER); 539 543 PcParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; 540 544 PcParams.Scope = DICS_FLAG_GLOBAL; 541 PcParams.HwProfile = 0; 545 542 546 switch(pPc->enmPcType) 543 547 { … … 549 553 break; 550 554 default: 551 NonStandardLogFlow((" unexpected prop change type: %d\n", pPc->enmPcType));555 NonStandardLogFlow(("vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback: Unexpected prop change type: %d\n", pPc->enmPcType)); 552 556 pPc->hr = E_INVALIDARG; 553 557 return FALSE; 554 558 } 555 559 556 557 if (SetupDiSetClassInstallParams(hDevInfo, pDev, &PcParams.ClassInstallHeader, sizeof (PcParams))) 560 if (SetupDiSetClassInstallParams(hDevInfo, pDev, &PcParams.ClassInstallHeader, sizeof(PcParams))) 558 561 { 559 562 if (SetupDiSetSelectedDevice(hDevInfo, pDev)) … … 565 568 if (SetupDiGetDeviceInstallParams(hDevInfo,pDev,&devParams)) 566 569 { 567 if (devParams.Flags & (DI_NEEDRESTART|DI_NEEDREBOOT)) 570 if ( (devParams.Flags & DI_NEEDRESTART) 571 || (devParams.Flags & DI_NEEDREBOOT)) 568 572 { 569 hr = S_FALSE; 570 NonStandardLogFlow(("PropChange: !!!REBOOT REQUIRED!!!\n")); 573 NonStandardLog(("vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback: A reboot is required\n")); 571 574 } 572 575 } 576 else 577 NonStandardLogFlow(("vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback: SetupDiGetDeviceInstallParams failed with %ld\n", 578 GetLastError())); 573 579 } 574 580 else 575 { 576 DWORD dwErr = GetLastError(); 577 NonStandardLogFlow(("SetupDiCallClassInstaller failed with %ld\n", dwErr)); 578 hr = HRESULT_FROM_WIN32(dwErr); 579 } 581 NonStandardLogFlow(("vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback: SetupDiCallClassInstaller failed with %ld\n", 582 GetLastError())); 580 583 } 581 584 else 582 { 583 DWORD dwErr = GetLastError(); 584 NonStandardLogFlow(("SetupDiSetSelectedDevice failed with %ld\n", dwErr)); 585 hr = HRESULT_FROM_WIN32(dwErr); 586 } 585 NonStandardLogFlow(("SetupDiSetSelectedDevice failed with %ld\n", GetLastError())); 587 586 } 588 587 else 589 { 590 DWORD dwErr = GetLastError(); 591 NonStandardLogFlow(("SetupDiSetClassInstallParams failed with %ld\n", dwErr)); 592 hr = HRESULT_FROM_WIN32(dwErr); 593 } 594 588 NonStandardLogFlow(("SetupDiSetClassInstallParams failed with %ld\n", GetLastError())); 589 590 /* Continue enumeration. */ 595 591 return TRUE; 596 592 } 597 593 598 594 typedef BOOL (*VBOXNETCFGWIN_NETENUM_CALLBACK) (HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext); 599 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnumNetDevices(LPCWSTR pPnPId, VBOXNETCFGWIN_NETENUM_CALLBACK callback, PVOID pContext) 600 { 601 DWORD winEr; 602 HRESULT hr = S_OK; 603 604 HDEVINFO hDevInfo = SetupDiGetClassDevsExW( 605 &GUID_DEVCLASS_NET, 606 NULL, /* IN PCTSTR Enumerator, OPTIONAL*/ 607 NULL, /*IN HWND hwndParent, OPTIONAL*/ 608 DIGCF_PRESENT, /*IN DWORD Flags,*/ 609 NULL, /*IN HDEVINFO DeviceInfoSet, OPTIONAL*/ 610 NULL, /*IN PCTSTR MachineName, OPTIONAL*/ 611 NULL /*IN PVOID Reserved*/ 612 ); 595 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnumNetDevices(LPCWSTR pwszPnPID, 596 VBOXNETCFGWIN_NETENUM_CALLBACK callback, PVOID pContext) 597 { 598 NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Searching for: %S\n", pwszPnPID)); 599 600 HRESULT hr; 601 HDEVINFO hDevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, 602 NULL, /* IN PCTSTR Enumerator, OPTIONAL */ 603 NULL, /* IN HWND hwndParent, OPTIONAL */ 604 DIGCF_PRESENT, /* IN DWORD Flags,*/ 605 NULL, /* IN HDEVINFO DeviceInfoSet, OPTIONAL */ 606 NULL, /* IN PCTSTR MachineName, OPTIONAL */ 607 NULL /* IN PVOID Reserved */); 613 608 if (hDevInfo != INVALID_HANDLE_VALUE) 614 609 { 615 DWORD iDev = 0; 616 SP_DEVINFO_DATA Dev; 610 DWORD winEr; 611 612 DWORD dwDevID = 0; 613 size_t cPnPId = wcslen(pwszPnPID); 614 617 615 PBYTE pBuffer = NULL; 618 DWORD cbBuffer = 0; 619 DWORD cbRequired = 0; 620 BOOL bEnumCompleted; 621 size_t cPnPId = wcslen(pPnPId); 622 623 Dev.cbSize = sizeof(Dev); 624 625 for (; bEnumCompleted = SetupDiEnumDeviceInfo(hDevInfo, iDev, &Dev); iDev++) 626 { 627 if (!SetupDiGetDeviceRegistryPropertyW(hDevInfo,&Dev, 628 SPDRP_HARDWAREID, /* IN DWORD Property,*/ 629 NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/ 630 pBuffer, /*OUT PBYTE PropertyBuffer,*/ 631 cbBuffer, /* IN DWORD PropertyBufferSize,*/ 632 &cbRequired /*OUT PDWORD RequiredSize OPTIONAL*/ 633 )) 616 617 for (;;) 618 { 619 SP_DEVINFO_DATA Dev; 620 memset(&Dev, 0, sizeof(SP_DEVINFO_DATA)); 621 Dev.cbSize = sizeof(SP_DEVINFO_DATA); 622 623 if (!SetupDiEnumDeviceInfo(hDevInfo, dwDevID, &Dev)) 624 { 625 winEr = GetLastError(); 626 if (winEr == ERROR_NO_MORE_ITEMS) 627 winEr = ERROR_SUCCESS; 628 break; 629 } 630 631 NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Enumerating device %ld ... \n", dwDevID)); 632 dwDevID++; 633 634 if (pBuffer) 635 free(pBuffer); 636 pBuffer = NULL; 637 DWORD cbBuffer = 0; 638 DWORD cbRequired = 0; 639 640 if (!SetupDiGetDeviceRegistryPropertyW(hDevInfo, &Dev, 641 SPDRP_HARDWAREID, /* IN DWORD Property */ 642 NULL, /* OUT PDWORD PropertyRegDataType OPTIONAL */ 643 pBuffer, /* OUT PBYTE PropertyBuffer */ 644 cbBuffer, /* IN DWORD PropertyBufferSize */ 645 &cbRequired /* OUT PDWORD RequiredSize OPTIONAL */)) 634 646 { 635 647 winEr = GetLastError(); 636 648 if (winEr != ERROR_INSUFFICIENT_BUFFER) 637 649 { 638 NonStandardLogFlow(("SetupDiGetDeviceRegistryPropertyW (1) failed winErr(%d)\n", winEr)); 639 hr = HRESULT_FROM_WIN32(winEr); 650 NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: SetupDiGetDeviceRegistryPropertyW (1) failed with %ld\n", winEr)); 640 651 break; 641 652 } 642 653 643 if (pBuffer)644 free(pBuffer);645 646 654 pBuffer = (PBYTE)malloc(cbRequired); 655 if (!pBuffer) 656 { 657 NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Out of memory allocating %ld bytes\n", 658 cbRequired)); 659 winEr = ERROR_OUTOFMEMORY; 660 break; 661 } 662 647 663 cbBuffer = cbRequired; 648 664 649 665 if (!SetupDiGetDeviceRegistryPropertyW(hDevInfo,&Dev, 650 SPDRP_HARDWAREID, /* IN DWORD Property,*/ 651 NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/ 652 pBuffer, /*OUT PBYTE PropertyBuffer,*/ 653 cbBuffer, /* IN DWORD PropertyBufferSize,*/ 654 &cbRequired /*OUT PDWORD RequiredSize OPTIONAL*/ 655 )) 666 SPDRP_HARDWAREID, /* IN DWORD Property */ 667 NULL, /* OUT PDWORD PropertyRegDataType, OPTIONAL */ 668 pBuffer, /* OUT PBYTE PropertyBuffer */ 669 cbBuffer, /* IN DWORD PropertyBufferSize */ 670 &cbRequired /* OUT PDWORD RequiredSize OPTIONAL */)) 656 671 { 657 672 winEr = GetLastError(); 658 NonStandardLogFlow((" SetupDiGetDeviceRegistryPropertyW (2) failed winErr(%d)\n", winEr));659 hr = HRESULT_FROM_WIN32(winEr);673 NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: SetupDiGetDeviceRegistryPropertyW (2) failed with %ld\n", 674 winEr)); 660 675 break; 661 676 } 662 677 } 663 678 664 PWCHAR pCurId = (PWCHAR)pBuffer; 665 size_t cCurId = wcslen(pCurId); 679 PWSTR pCurID = (PWSTR)pBuffer; 680 size_t cCurId = wcslen(pCurID); 681 682 NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Device %ld: %S\n", dwDevID, pCurID)); 683 666 684 if (cCurId >= cPnPId) 667 685 { 668 pCurId += cCurId - cPnPId; 669 if (!wcsnicmp(pCurId, pPnPId, cPnPId)) 670 { 671 672 if (!callback(hDevInfo,&Dev,pContext)) 686 pCurID += cCurId - cPnPId; 687 if (!wcsnicmp(pCurID, pwszPnPID, cPnPId)) 688 { 689 if (!callback(hDevInfo, &Dev, pContext)) 673 690 break; 674 691 } 675 692 } 676 677 } 693 } 694 695 NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Found %ld devices total\n", dwDevID)); 678 696 679 697 if (pBuffer) 680 698 free(pBuffer); 681 699 682 if (bEnumCompleted) 683 { 684 winEr = GetLastError(); 685 hr = winEr == ERROR_NO_MORE_ITEMS ? S_OK : HRESULT_FROM_WIN32(winEr); 686 } 700 hr = HRESULT_FROM_WIN32(winEr); 687 701 688 702 SetupDiDestroyDeviceInfoList(hDevInfo); … … 691 705 { 692 706 DWORD winEr = GetLastError(); 693 NonStandardLogFlow((" SetupDiGetClassDevsExW failed winErr(%d)\n", winEr));707 NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: SetupDiGetClassDevsExW failed with %ld\n", winEr)); 694 708 hr = HRESULT_FROM_WIN32(winEr); 695 709 } 696 710 711 NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Ended with hr (0x%x)\n", hr)); 697 712 return hr; 698 713 }
Note:
See TracChangeset
for help on using the changeset viewer.