+++ /dev/null
-/*\r
- * Copyright (c) 2005 SilverStorm Technologies. All rights reserved.\r
- *\r
- * This software is available to you under the OpenIB.org BSD license\r
- * below:\r
- *\r
- * Redistribution and use in source and binary forms, with or\r
- * without modification, are permitted provided that the following\r
- * conditions are met:\r
- *\r
- * - Redistributions of source code must retain the above\r
- * copyright notice, this list of conditions and the following\r
- * disclaimer.\r
- *\r
- * - Redistributions in binary form must reproduce the above\r
- * copyright notice, this list of conditions and the following\r
- * disclaimer in the documentation and/or other materials\r
- * provided with the distribution.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
- * SOFTWARE.\r
- *\r
- * $Id$\r
- */\r
-\r
-\r
-// IBInstaller.cpp : Defines the entry point for the DLL application.\r
-//\r
-\r
-#include "stdafx.h"\r
-\r
-wchar_t debug_buf[256];\r
-\r
-// IB Fabric device HW ID\r
-#define GUID_IB_BUS_HW_ID TEXT("{94f41ced-78eb-407c-b5df-958040af0fd8}")\r
-#ifdef WINIB \r
-#define DEVICE_DESC TEXT("Mellanox InfiniBand Fabric")\r
-#else\r
-#define DEVICE_DESC TEXT("InfiniBand Fabric")\r
-#endif\r
-\r
-// System Class GUID (from wdmguid.h)\r
-//{4D36E97D-E325-11CE-BFC1-08002BE10318}\r
-static const GUID GUID_CLASS_SYSTEM = \r
-{ 0x4D36E97D, 0xE325, 0x11CE, {0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18 } };\r
-\r
-\r
-BOOL APIENTRY DllMain(\r
- HANDLE hModule, \r
- DWORD ul_reason_for_call, \r
- LPVOID lpReserved )\r
-{\r
- UNREFERENCED_PARAMETER( hModule );\r
- UNREFERENCED_PARAMETER( ul_reason_for_call );\r
- UNREFERENCED_PARAMETER( lpReserved );\r
- return TRUE;\r
-}\r
-\r
-\r
-//\r
-// Checks the installed devices, looking for an instance of the bus root.\r
-//\r
-DWORD NeedInstall()\r
-{\r
- HDEVINFO hDevList;\r
- BOOL bSuccess;\r
- SP_DEVINFO_DATA devInfo;\r
- DWORD i;\r
- TCHAR buf[128];\r
-\r
- memset( &devInfo, 0, sizeof(SP_DEVINFO_DATA) );\r
- devInfo.cbSize = sizeof(SP_DEVINFO_DATA);\r
-\r
- OutputDebugString(\r
- TEXT("[IbInstaller]Checking for existance of IB Fabric Root device.\n") );\r
-\r
- // Get all devices of the system class.\r
- hDevList = SetupDiGetClassDevs( &GUID_CLASS_SYSTEM, 0, NULL, 0 );\r
- if( hDevList == INVALID_HANDLE_VALUE )\r
- {\r
- swprintf( debug_buf,L"[IbInstaller] Failed to get system class dev info list Error %d\n",GetLastError());\r
- OutputDebugString( debug_buf );\r
- return GetLastError();\r
- }\r
-\r
- // Enumerate until we find our device. If the device exists, we\r
- // exit.\r
- i = 0;\r
- do\r
- {\r
- // Get the next device.\r
- bSuccess = SetupDiEnumDeviceInfo( hDevList, i++, &devInfo );\r
- if( !bSuccess )\r
- {\r
- OutputDebugString( TEXT("[IbInstaller]SetupDiEnumDeviceInfo failed.\n") );\r
- break;\r
- }\r
-\r
- // Get the device's description.\r
- bSuccess = SetupDiGetDeviceRegistryProperty( hDevList, &devInfo,\r
- SPDRP_HARDWAREID, NULL, (BYTE*)buf, sizeof(buf), NULL );\r
- if( !bSuccess )\r
- {\r
- // Device has no HW ID.\r
- OutputDebugString(\r
- TEXT("[IbInstaller]SetupDiGetDeviceRegistryProperty failed.\n") );\r
- // Skip to the next.\r
- bSuccess = TRUE;\r
- continue;\r
- }\r
-\r
- // Compare to our device description.\r
- if( _tcscmp( buf, GUID_IB_BUS_HW_ID ) )\r
- continue;\r
-\r
- // The device is already installed.\r
- SetupDiDestroyDeviceInfoList( hDevList );\r
- OutputDebugString( TEXT("[IbInstaller]IB Fabric Root device already exists.\n") );\r
- return ERROR_ALREADY_EXISTS;\r
-\r
- } while( bSuccess );\r
-\r
- return ERROR_SUCCESS;\r
-}\r
-\r
-\r
-DWORD SelectDriver(\r
- IN HDEVINFO hDevList,\r
- IN SP_DEVINFO_DATA *pDevInfo,\r
- OUT SP_DRVINFO_DATA *pDrvInfo )\r
-{\r
- DWORD i;\r
- BOOL bSuccess;\r
- \r
- OutputDebugString( L"SelectDriver" );\r
-\r
- // Get a list of drivers.\r
- bSuccess =\r
- SetupDiBuildDriverInfoList( hDevList, pDevInfo, SPDIT_CLASSDRIVER );\r
- if( !bSuccess )\r
- {\r
- swprintf( debug_buf,L"[IbInstaller] SetupDiBuildDriverInfoList failed Error %d\n",GetLastError());\r
- OutputDebugString( debug_buf );\r
- return GetLastError();\r
- }\r
-\r
- // Set the size of the structure properly.\r
- pDrvInfo->cbSize = sizeof(SP_DRVINFO_DATA);\r
-\r
- // Enumerate all drivers, looking for the correct description.\r
- i = 0;\r
- do\r
- {\r
-\r
- bSuccess = SetupDiEnumDriverInfo( hDevList, pDevInfo,\r
- SPDIT_CLASSDRIVER, i++, pDrvInfo );\r
- if( !bSuccess )\r
- {\r
- swprintf( debug_buf,L"[IbInstaller] SetupDiEnumDriverInfo failed Error %d\n",GetLastError());\r
- OutputDebugString( debug_buf );\r
- break;\r
- }\r
- // make the string\r
-\r
- swprintf( debug_buf,TEXT("[IbInstaller] pDrvInfo->Description %s\n"),pDrvInfo->Description);\r
- OutputDebugString( debug_buf );\r
- \r
- if( _tcscmp( pDrvInfo->Description, DEVICE_DESC ) )\r
- continue;\r
-\r
- // Found it!\r
- OutputDebugString( TEXT("[IbInstaller]Found our driver!\n") );\r
- return ERROR_SUCCESS;\r
-\r
- } while( bSuccess );\r
-\r
- return ERROR_NOT_FOUND;\r
-}\r
-\r
-\r
-DWORD\r
-CreateIbBusRoot(\r
- IN PTSTR driverPath )\r
-{\r
- HDEVINFO hDevList;\r
- BOOL bSuccess;\r
- SP_DEVINFO_DATA devInfo;\r
- SP_DRVINFO_DATA drvInfo;\r
- LONG status;\r
- SP_DEVINSTALL_PARAMS installParams;\r
- size_t nEnd;\r
- DWORD gle = 0;\r
-\r
- memset( &devInfo, 0, sizeof(SP_DEVINFO_DATA) );\r
- devInfo.cbSize = sizeof(SP_DEVINFO_DATA);\r
-\r
- OutputDebugString( TEXT("[IbInstaller]Creating IB Fabric Root device.\n") );\r
-\r
- // Create a list for devices of the system class.\r
- hDevList = SetupDiCreateDeviceInfoList( &GUID_CLASS_SYSTEM, NULL );\r
- if( hDevList == INVALID_HANDLE_VALUE )\r
- {\r
- gle = GetLastError();\r
- OutputDebugString( TEXT("[IbInstaller]Failed to create dev info list.\n") );\r
- return gle;\r
- }\r
-\r
- // Create the device.\r
- bSuccess = SetupDiCreateDeviceInfo( hDevList, TEXT("SYSTEM"), \r
- &GUID_CLASS_SYSTEM, DEVICE_DESC,\r
- NULL, DICD_GENERATE_ID, &devInfo );\r
- if( !bSuccess )\r
- {\r
- gle = GetLastError();\r
- OutputDebugString( TEXT("[IbInstaller]SetupDiCreateDeviceInfo failed.\n") );\r
- SetupDiDestroyDeviceInfoList( hDevList );\r
- return gle;\r
- }\r
-\r
- // Setup the HW ID for the device.\r
- bSuccess = SetupDiSetDeviceRegistryProperty( hDevList, &devInfo,\r
- SPDRP_HARDWAREID, (BYTE*)GUID_IB_BUS_HW_ID, sizeof(GUID_IB_BUS_HW_ID) );\r
- if( !bSuccess )\r
- {\r
- gle = GetLastError();\r
- OutputDebugString(\r
- TEXT("[IbInstaller]SetupDiSetDeviceRegistryProperty failed.\n") );\r
- SetupDiDestroyDeviceInfoList( hDevList );\r
- return gle;\r
- }\r
-\r
- // Setup the install path.\r
- ZeroMemory( &installParams, sizeof(installParams) );\r
- installParams.cbSize = sizeof(installParams);\r
-\r
-\r
- OSVERSIONINFO osvi;\r
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);\r
- bSuccess = GetVersionEx (&osvi);\r
- if( !bSuccess )\r
- {\r
- gle = GetLastError();\r
- OutputDebugString(\r
- TEXT("[IbInstaller]GetVersionEx failed.\n") );\r
- SetupDiDestroyDeviceInfoList( hDevList );\r
- return gle;\r
- }\r
-\r
- // for LH we want to find the correct path\r
- if (osvi.dwMajorVersion > 5) \r
- {\r
- WIN32_FIND_DATA FindFileData;\r
- HANDLE hFind;\r
-\r
- // Strip the file name from the path.\r
- nEnd = _tcslen( driverPath );\r
- while( driverPath[nEnd] != '\\' ) {\r
- nEnd--;\r
- }\r
- driverPath[nEnd] = _T('\0');\r
- _tcsncat(driverPath,TEXT("\\ib_bus.inf_*"), MAX_PATH);\r
-\r
- hFind = FindFirstFile(driverPath, &FindFileData);\r
- if (hFind == INVALID_HANDLE_VALUE) \r
- {\r
- printf ("Invalid File Handle. GetLastError reports %d\n", GetLastError ());\r
- return ERROR_FILE_NOT_FOUND;\r
- } \r
- else \r
- {\r
- printf ("The first file found is %s\n", FindFileData.cFileName);\r
-\r
- // Strip the file name from the path.\r
- nEnd = _tcslen( driverPath );\r
- while( driverPath[nEnd] != '\\' ) {\r
- nEnd--;\r
- }\r
- driverPath[nEnd+1] = _T('\0'); \r
-\r
- _tcsncpy( installParams.DriverPath, driverPath, MAX_PATH );\r
- _tcsncat(installParams.DriverPath, FindFileData.cFileName, MAX_PATH);\r
- FindClose(hFind);\r
- }\r
-\r
- } else {\r
- _tcsncpy( installParams.DriverPath, driverPath, MAX_PATH );\r
- }\r
-\r
-\r
- bSuccess =\r
- SetupDiSetDeviceInstallParams( hDevList, &devInfo, &installParams );\r
- if( !bSuccess )\r
- {\r
- gle = GetLastError();\r
- OutputDebugString( TEXT("[IbInstaller]SetupDiSetDeviceInstallParams failed.\n") );\r
- SetupDiDestroyDeviceInfoList( hDevList );\r
- return gle;\r
- }\r
-\r
- status = SelectDriver( hDevList, &devInfo, &drvInfo );\r
- if( status != ERROR_SUCCESS )\r
- {\r
- OutputDebugString( TEXT("[IbInstaller]Could not find driver.\n") );\r
- SetupDiDestroyDriverInfoList( hDevList, &devInfo, SPDIT_CLASSDRIVER );\r
- SetupDiDestroyDeviceInfoList( hDevList );\r
- return status;\r
- }\r
-\r
- // Select the device.\r
- bSuccess = SetupDiSetSelectedDevice( hDevList, &devInfo );\r
- if( !bSuccess )\r
- {\r
- gle = GetLastError();\r
- OutputDebugString( TEXT("[IbInstaller]SetupDiSetSelectedDevice failed.\n") );\r
- SetupDiDestroyDriverInfoList( hDevList, &devInfo, SPDIT_CLASSDRIVER );\r
- SetupDiDestroyDeviceInfoList( hDevList );\r
- return gle;\r
- }\r
-\r
- // Select the driver.\r
- bSuccess = SetupDiSetSelectedDriver( hDevList, &devInfo, &drvInfo );\r
- if( !bSuccess )\r
- {\r
- gle = GetLastError();\r
- OutputDebugString( TEXT("[IbInstaller]SetupDiSetSelectedDriver failed.\n") );\r
- SetupDiDestroyDriverInfoList( hDevList, &devInfo, SPDIT_CLASSDRIVER );\r
- SetupDiDestroyDeviceInfoList( hDevList );\r
- return gle;\r
- }\r
-\r
- // Register the device (since it is non-PnP).\r
- bSuccess = SetupDiRegisterDeviceInfo( hDevList, &devInfo, SPRDI_FIND_DUPS,\r
- NULL, NULL, NULL );\r
- if( !bSuccess )\r
- {\r
- gle = GetLastError();\r
- OutputDebugString( TEXT("[IbInstaller]SetupDiRegisterDeviceInfo failed.\n") );\r
- SetupDiDestroyDriverInfoList( hDevList, &devInfo, SPDIT_CLASSDRIVER );\r
- SetupDiDestroyDeviceInfoList( hDevList );\r
- return gle;\r
- }\r
-\r
- // Install the device (copies the files and starts it).\r
- bSuccess = SetupDiInstallDevice( hDevList, &devInfo );\r
- if( !bSuccess )\r
- {\r
- gle = GetLastError();\r
- OutputDebugString( TEXT("[IbInstaller]SetupDiInstallDevice failed.\n") );\r
- SetupDiDestroyDriverInfoList( hDevList, &devInfo, SPDIT_CLASSDRIVER );\r
- SetupDiDestroyDeviceInfoList( hDevList );\r
- return gle;\r
- }\r
-\r
- return ERROR_SUCCESS;\r
-}\r
-\r
-\r
-UINT CALLBACK\r
-IbFileCallback(\r
- IN PVOID Context,\r
- IN UINT Notification,\r
- IN UINT_PTR Param1,\r
- IN UINT_PTR Param2 )\r
-{\r
- TCHAR *pPath;\r
- FILEPATHS *pFileInfo;\r
-\r
- OutputDebugString( L"IbFileCallback" );\r
-\r
- UNREFERENCED_PARAMETER( Param2 );\r
-\r
- if( Notification != SPFILENOTIFY_QUEUESCAN_EX )\r
- return 0;\r
-\r
- pPath = (TCHAR*)Context;\r
- pFileInfo = (FILEPATHS*)Param1;\r
-\r
- // Copy the source path of the file to the path.\r
- if( pFileInfo->Source )\r
- _tcsncpy( pPath, pFileInfo->Source, MAX_PATH );\r
-\r
- return 0;\r
-}\r
-\r
-extern "C"\r
-{\r
-\r
-\r
-HRESULT\r
-IbCoInstaller(\r
- IN DI_FUNCTION InstallFunction,\r
- IN HDEVINFO DeviceInfoSet,\r
- IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,\r
- IN OUT PCOINSTALLER_CONTEXT_DATA Context )\r
-{\r
- SP_DEVINSTALL_PARAMS InstallParams;\r
- DWORD result;\r
- BOOL b;\r
- TCHAR path[MAX_PATH];\r
- size_t nEnd;\r
-\r
- UNREFERENCED_PARAMETER( Context );\r
-\r
- swprintf( debug_buf ,L"IbCoInstaller called DI_FUNCTION =%d\n", InstallFunction);\r
- OutputDebugString( debug_buf );\r
-\r
- // The file queue is valid on the DIF_INSTALLDEVICE, so trap that\r
- // code and extract the install path.\r
- if( InstallFunction != DIF_INSTALLDEVICE )\r
- return NO_ERROR;\r
-\r
- // First find out if we need to install the transport.\r
- result = NeedInstall();\r
- if( result != ERROR_SUCCESS )\r
- {\r
- if( result == ERROR_ALREADY_EXISTS )\r
- return NO_ERROR;\r
- else\r
- return result;\r
- }\r
-\r
- // Extract the file path from the file queue.\r
- // First get the file queue (it's in the install parameters).\r
- memset( &InstallParams, 0, sizeof(InstallParams) );\r
- InstallParams.cbSize = sizeof(InstallParams);\r
-\r
- // Get the installation parameters.\r
- b = SetupDiGetDeviceInstallParams( DeviceInfoSet, DeviceInfoData,\r
- &InstallParams );\r
- if( !b )\r
- return GetLastError();\r
-\r
- // If there isn't a file queue, abort the installation.\r
- if( !InstallParams.FileQueue )\r
- return ERROR_DI_DONT_INSTALL;\r
-\r
- // Scan the file queue. The callback will copy the file name to our path.\r
- SetupScanFileQueue( InstallParams.FileQueue, SPQ_SCAN_USE_CALLBACKEX, NULL,\r
- IbFileCallback, &path, &result );\r
- if( result )\r
- return result;\r
-\r
- // Strip the file name from the path.\r
- nEnd = _tcslen( path );\r
- while( path[nEnd] != '\\' )\r
- nEnd--;\r
-/*\r
- NOTE: no need to strip the platform directoty it was removed for WHQL\r
- // Skip the slash.\r
- nEnd--;\r
- // Strip the platform subdir name from the path.\r
- while( path[nEnd] != '\\' )\r
- nEnd--;\r
-*/\r
- path[nEnd] = _T('\0');\r
-\r
- swprintf( debug_buf ,L"[IbInstaller] path %s\n",path);\r
- OutputDebugString( debug_buf );\r
-\r
-\r
- // Create the bus root.\r
- result = CreateIbBusRoot( path );\r
- if( result != ERROR_SUCCESS )\r
- return result;\r
-\r
- return NO_ERROR;\r
-}\r
-\r
-} // extern "C"\r
-\r