]> git.openfabrics.org - ~shefty/rdma-win.git/commitdiff
Initial copy of WSD installer, used as base for ND installer.
authorftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 20 Apr 2009 20:04:06 +0000 (20:04 +0000)
committerftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 20 Apr 2009 20:04:06 +0000 (20:04 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1@2111 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

trunk/tools/ndinstall/dirs [new file with mode: 0644]
trunk/tools/ndinstall/user/InstallSP.sln [new file with mode: 0644]
trunk/tools/ndinstall/user/SOURCES [new file with mode: 0644]
trunk/tools/ndinstall/user/installsp.c [new file with mode: 0644]
trunk/tools/ndinstall/user/installsp.exe.manifest [new file with mode: 0644]
trunk/tools/ndinstall/user/installsp.rc [new file with mode: 0644]
trunk/tools/ndinstall/user/makefile [new file with mode: 0644]

diff --git a/trunk/tools/ndinstall/dirs b/trunk/tools/ndinstall/dirs
new file mode 100644 (file)
index 0000000..389156f
--- /dev/null
@@ -0,0 +1,2 @@
+DIRS=\\r
+       user\r
diff --git a/trunk/tools/ndinstall/user/InstallSP.sln b/trunk/tools/ndinstall/user/InstallSP.sln
new file mode 100644 (file)
index 0000000..9c8f2cb
--- /dev/null
@@ -0,0 +1,21 @@
+Microsoft Visual Studio Solution File, Format Version 8.00\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InstallSP", "InstallSP.vcproj", "{B3A2B7A0-1906-413E-A457-8AD2FC5E88BB}"\r
+       ProjectSection(ProjectDependencies) = postProject\r
+       EndProjectSection\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfiguration) = preSolution\r
+               Debug = Debug\r
+               Release = Release\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfiguration) = postSolution\r
+               {B3A2B7A0-1906-413E-A457-8AD2FC5E88BB}.Debug.ActiveCfg = Debug|Win32\r
+               {B3A2B7A0-1906-413E-A457-8AD2FC5E88BB}.Debug.Build.0 = Debug|Win32\r
+               {B3A2B7A0-1906-413E-A457-8AD2FC5E88BB}.Release.ActiveCfg = Release|Win32\r
+               {B3A2B7A0-1906-413E-A457-8AD2FC5E88BB}.Release.Build.0 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(ExtensibilityGlobals) = postSolution\r
+       EndGlobalSection\r
+       GlobalSection(ExtensibilityAddIns) = postSolution\r
+       EndGlobalSection\r
+EndGlobal\r
diff --git a/trunk/tools/ndinstall/user/SOURCES b/trunk/tools/ndinstall/user/SOURCES
new file mode 100644 (file)
index 0000000..5914a25
--- /dev/null
@@ -0,0 +1,23 @@
+TARGETNAME=installsp\r
+TARGETPATH=..\..\..\bin\user\obj$(BUILD_ALT_DIR)\r
+TARGETTYPE=PROGRAM\r
+UMTYPE=console\r
+USE_MSVCRT=1\r
+\r
+INCLUDES=..\..\..\inc;\\r
+       ..\..\..\inc\user;\\r
+       $(PLATFORM_SDK_PATH)\include;\r
+\r
+SOURCES= \\r
+       installsp.rc \\r
+       installsp.c\r
+\r
+USER_C_FLAGS=$(USER_C_FLAGS) -DPERFMON_ENABLED\r
+\r
+TARGETLIBS=\\r
+       $(SDK_LIB_PATH)\ws2_32.lib \\r
+       $(SDK_LIB_PATH)\LoadPerf.lib \r
+\r
+MSC_WARNING_LEVEL= /W3\r
+\r
+LINKER_FLAGS=$(LINKER_FLAGS)\r
diff --git a/trunk/tools/ndinstall/user/installsp.c b/trunk/tools/ndinstall/user/installsp.c
new file mode 100644 (file)
index 0000000..e0cba2e
--- /dev/null
@@ -0,0 +1,759 @@
+/*\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
+ *     Module Name: installsp.c\r
+ *     Description: This module installs/removes a winsock service provider for infiniband. \r
+ *     execute:\r
+ *     To install the service provider\r
+ *             installsp -i        \r
+ *     To remove the service provider\r
+ *             installsp -r\r
+ */\r
+\r
+#include <winsock2.h>\r
+#include <ws2spi.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+\r
+/* Initialize the LSP's provider path for Infiband Service Provider dll */\r
+static const WCHAR provider_path[] = L"%SYSTEMROOT%\\system32\\ibwsd.dll";\r
+static const WCHAR provider_prefix[] =L" Winsock Direct for InfiniBand"; //includes one whitespace\r
+static const char provider_name[] = VER_PROVIDER ;//L"%VER_PROVIDER% Winsock Direct for InfiniBand"; //(VER_PROVIDER ## WINDIR);\r
+static const char winsock_key_path[] =\r
+       "System\\CurrentControlSet\\Services\\Winsock\\Parameters\\TCP on SAN";\r
+static const char openib_key_name[] = IB_COMPANYNAME;\r
+\r
+/* Unique provider GUID generated with "uuidgen -s" */\r
+static GUID provider_guid = {\r
+       /* c943654d-2c84-4db7-af3e-fdf1c5322458 */\r
+       0xc943654d, 0x2c84, 0x4db7,\r
+       { 0xaf, 0x3e, 0xfd, 0xf1, 0xc5, 0x32, 0x24,     0x58 }\r
+};\r
+\r
+#ifdef _WIN64\r
+#define WSCInstallProvider     WSCInstallProvider64_32\r
+#endif /* _WIN64 */\r
+\r
+#ifdef PERFMON_ENABLED\r
+#include <Loadperf.h>\r
+#include "wsd/ibsp_regpath.h"\r
+\r
+\r
+typedef struct _pm_symbol_def\r
+{\r
+       DWORD   name_def;\r
+       CHAR    name_str[40];\r
+       CHAR    name_desc[40];\r
+       CHAR    help_desc[256];\r
+\r
+} pm_symbol_def_t;\r
+\r
+static pm_symbol_def_t  _pm_symbols[]=\r
+{\r
+       { IBSP_PM_OBJ,\r
+       "IBSP_PM_OBJ",\r
+       "IB Winsock Direct",\r
+       "InfiniBand Windows Sockets Direct Provider."\r
+       },\r
+       { IBSP_PM_COUNTER(BYTES_SEND),\r
+       "IBSP_PM_BYTES_TX_SEC",\r
+       "Send bytes/sec",\r
+       "Send bytes/second, excluding RDMA Write."\r
+       },\r
+       { IBSP_PM_COUNTER(BYTES_RECV),\r
+       "IBSP_PM_BYTES_RX_SEC",\r
+       "Recv bytes/sec",\r
+       "Receive bytes/second, excluding RDMA Read."\r
+       },\r
+       { IBSP_PM_COUNTER(BYTES_WRITE),\r
+       "IBSP_PM_RDMA_WR_SEC",\r
+       "RDMA Write bytes/sec",\r
+       "RDMA Write bytes/second."\r
+       },\r
+       { IBSP_PM_COUNTER(BYTES_READ),\r
+       "IBSP_PM_RDMA_RD_SEC",\r
+       "RDMA Read bytes/sec",\r
+       "RDMA Read bytes/second."\r
+       },\r
+       { IBSP_PM_COUNTER(BYTES_TOTAL),\r
+       "IBSP_PM_BYTES_SEC",\r
+       "Total bytes/sec",\r
+       "Total bytes transmitted per second, including send, "\r
+       "receive, RDMA Write, and RDMA Read."\r
+       },\r
+       { IBSP_PM_COUNTER(COMP_SEND),\r
+       "IBSP_PM_SEND_COMPLETIONS_SEC",\r
+       "Send Completions/sec",\r
+       "Send and RDMA Write Completions/sec."\r
+       },\r
+       { IBSP_PM_COUNTER(COMP_RECV),\r
+       "IBSP_PM_RECV_COMPLETIONS_SEC",\r
+       "Recv Completions/sec",\r
+       "Recv and RDMA Read Completions/sec."\r
+       },\r
+       { IBSP_PM_COUNTER(COMP_TOTAL),\r
+       "IBSP_PM_COMPLETIONS_SEC",\r
+       "Total Completions/sec",\r
+       "Total Completions processed per second."\r
+       },\r
+       { IBSP_PM_COUNTER(INTR_TOTAL),\r
+       "IBSP_PM_COMPLETIONS_INTR",\r
+       "Total Interrupts/sec",\r
+       "Completion Queue events per second."\r
+       }\r
+};\r
+\r
+#define IBSP_PM_NUM_SYMBOLS  (sizeof(_pm_symbols)/sizeof(pm_symbol_def_t))\r
+#define IBSP_PM_LANGUAGE "009" /* good for English */\r
+\r
+static CHAR *\r
+_IBSPGenerateFileName(char *header,    char *file )\r
+{\r
+       DWORD size1, size;\r
+       CHAR *full_file_name;\r
+       int header_len = header == NULL ? 0 : strlen(header);\r
+\r
+       size = GetTempPath(0, NULL);\r
+       if (size == 0)\r
+       {\r
+               fprintf( stderr, "GetTempPath  failed\n" );\r
+               return NULL;\r
+       }\r
+       size1 = size + strlen(file) + header_len;\r
+       full_file_name = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, size1);\r
+       if ( full_file_name == NULL )\r
+       {\r
+               fprintf( stderr, "GetTempPath  failed\n" );\r
+               return NULL;\r
+       }\r
+       size1 = GetTempPath(size, full_file_name + header_len);\r
+       if (size != size1 + 1) \r
+       {\r
+               fprintf( stderr, "Very strange, GetTempPath  returned something different\n" );\r
+               HeapFree (GetProcessHeap (), 0, full_file_name);\r
+               return NULL;\r
+       }\r
+       if (header_len != 0)\r
+       {\r
+               memcpy(full_file_name, header, header_len);\r
+       }\r
+       strcat(full_file_name, file);\r
+       return full_file_name;\r
+}\r
+\r
+\r
+static DWORD\r
+_IBSPPerfmonIniFilesGenerate( void )\r
+{\r
+       FILE    *f_handle;\r
+       DWORD   num;\r
+       DWORD ret = ERROR_SUCCESS;\r
+       char *ibsp_pm_sym_file = NULL;\r
+       char *ibsp_pm_ini_file = NULL;\r
+\r
+       /* create ".h" file first */\r
+       ibsp_pm_sym_file = _IBSPGenerateFileName(NULL, IBSP_PM_SYM_H_FILE);\r
+       if( !ibsp_pm_sym_file )\r
+       {\r
+               fprintf( stderr, "_IBSPGenerateFileName  failed\n" );\r
+               ret = ERROR_NOT_ENOUGH_MEMORY;\r
+               goto Cleanup;\r
+       }\r
+\r
+       f_handle = fopen( ibsp_pm_sym_file, "w+" );\r
+\r
+       if( !f_handle )\r
+       {\r
+               fprintf( stderr, "Create Header file %s failed\n", ibsp_pm_sym_file );\r
+               ret = ERROR_FILE_INVALID;\r
+               goto Cleanup;\r
+       }\r
+\r
+       fprintf(\r
+               f_handle, "/* %s Generated by program */ \r\n", ibsp_pm_sym_file );\r
+               \r
+       \r
+       for( num = 0; num < IBSP_PM_NUM_SYMBOLS; num++ )\r
+       {\r
+               fprintf( f_handle, "#define\t%s\t%d\r\n",\r
+                       _pm_symbols[num].name_str, _pm_symbols[num].name_def );\r
+       }\r
+\r
+       fflush( f_handle );\r
+       fclose( f_handle );\r
+\r
+       /* create 'ini' file next */\r
+       ibsp_pm_ini_file = _IBSPGenerateFileName(NULL, IBSP_PM_INI_FILE);\r
+       if( !ibsp_pm_sym_file )\r
+       {\r
+               fprintf( stderr, "_IBSPGenerateFileName  failed\n" );\r
+               ret = ERROR_NOT_ENOUGH_MEMORY;\r
+               goto Cleanup;\r
+       }\r
+       f_handle = fopen( ibsp_pm_ini_file, "w+" );\r
+\r
+       if( !f_handle )\r
+       {\r
+               fprintf( stderr, "Create INI file %s  failed\n", ibsp_pm_ini_file );\r
+               ret = ERROR_FILE_INVALID;\r
+               goto Cleanup;\r
+       }\r
+       \r
+       fprintf( f_handle, "[info]\r\ndrivername=" IBSP_PM_SUBKEY_NAME\r
+               "\r\nsymbolfile=%s\r\n\r\n", ibsp_pm_sym_file );\r
+       fprintf( f_handle,"[languages]\r\n" IBSP_PM_LANGUAGE\r
+               "=language" IBSP_PM_LANGUAGE "\r\n\r\n" );\r
+\r
+       fprintf( f_handle, \r
+               "[objects]\r\n%s_" IBSP_PM_LANGUAGE "_NAME=%s\r\n\r\n[text]\r\n",\r
+               _pm_symbols[0].name_str, _pm_symbols[0].name_desc );\r
+       \r
+       for( num = 0; num < IBSP_PM_NUM_SYMBOLS; num++ )\r
+       {\r
+               fprintf( f_handle,"%s_" IBSP_PM_LANGUAGE "_NAME=%s\r\n",\r
+                       _pm_symbols[num].name_str, _pm_symbols[num].name_desc );\r
+               fprintf( f_handle,"%s_" IBSP_PM_LANGUAGE "_HELP=%s\r\n",\r
+                       _pm_symbols[num].name_str, _pm_symbols[num].help_desc );\r
+       }\r
+\r
+       fflush( f_handle );\r
+       fclose( f_handle );\r
+\r
+Cleanup:\r
+       if ( ibsp_pm_sym_file )\r
+       {\r
+               HeapFree (GetProcessHeap (), 0, ibsp_pm_sym_file);\r
+       }\r
+       if ( ibsp_pm_ini_file )\r
+       {\r
+               HeapFree (GetProcessHeap (), 0, ibsp_pm_ini_file);\r
+       }\r
+       return ret;\r
+}\r
+\r
+\r
+static void\r
+_IBSPPerfmonIniFilesRemove( void )\r
+{\r
+       char *ibsp_pm_sym_file = NULL;\r
+       char *ibsp_pm_ini_file = NULL;\r
+\r
+       ibsp_pm_sym_file = _IBSPGenerateFileName(NULL, IBSP_PM_SYM_H_FILE);\r
+       if( !ibsp_pm_sym_file )\r
+       {\r
+               fprintf( stderr, "_IBSPGenerateFileName  failed\n" );\r
+               goto Cleanup;\r
+       }\r
+\r
+       ibsp_pm_ini_file = _IBSPGenerateFileName(NULL, IBSP_PM_INI_FILE);\r
+       if( !ibsp_pm_sym_file )\r
+       {\r
+               fprintf( stderr, "_IBSPGenerateFileName  failed\n" );\r
+               goto Cleanup;\r
+       }\r
+\r
+       if( !DeleteFile( ibsp_pm_ini_file ) )\r
+       {\r
+               fprintf( stderr, "Delete file %s failed status %d\n",\r
+                       ibsp_pm_ini_file, GetLastError() );\r
+       }\r
+       if( !DeleteFile( ibsp_pm_sym_file ) )\r
+       {\r
+               fprintf( stderr,"Delete file %s failed status %d\n",\r
+                       ibsp_pm_sym_file, GetLastError() );\r
+       }\r
+\r
+Cleanup:       \r
+       if ( ibsp_pm_sym_file )\r
+       {\r
+               HeapFree (GetProcessHeap (), 0, ibsp_pm_sym_file);\r
+       }\r
+       if ( ibsp_pm_ini_file )\r
+       {\r
+               HeapFree (GetProcessHeap (), 0, ibsp_pm_ini_file);\r
+       }\r
+       \r
+}\r
+\r
+\r
+/* Try to create IB WSD Performance Register Keys */\r
+static LONG\r
+_IBSPPerfmonRegisterKeys( void )\r
+{\r
+       LONG    reg_status;\r
+       HKEY    pm_hkey;\r
+       DWORD   typesSupp = 7;\r
+\r
+       reg_status = RegCreateKeyEx( HKEY_LOCAL_MACHINE,\r
+               IBSP_PM_REGISTRY_PATH IBSP_PM_SUBKEY_PERF, 0, NULL,\r
+               REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &pm_hkey, NULL );\r
+\r
+       if( reg_status != ERROR_SUCCESS )\r
+       {\r
+               fprintf( stderr,\r
+                       "_IBSPPerfmonRegisterKeys Create Key %s failed with %d\n",\r
+                       IBSP_PM_REGISTRY_PATH IBSP_PM_SUBKEY_PERF, reg_status );\r
+               return reg_status;\r
+       }\r
+\r
+       /* create/assign values to the key */\r
+       RegSetValueExW( pm_hkey, L"Library", 0, REG_EXPAND_SZ,\r
+               (LPBYTE)provider_path, sizeof(provider_path) );\r
+\r
+       RegSetValueEx( pm_hkey, TEXT("Open"), 0, REG_SZ,\r
+               (LPBYTE)TEXT("IBSPPmOpen"), sizeof(TEXT("IBSPPmOpen")) );\r
+\r
+       RegSetValueEx( pm_hkey, TEXT("Collect"), 0, REG_SZ,\r
+               (LPBYTE)TEXT("IBSPPmCollectData"), sizeof(TEXT("IBSPPmCollectData")) );\r
+\r
+       RegSetValueEx( pm_hkey, TEXT("Close"), 0, REG_SZ,\r
+               (LPBYTE)TEXT("IBSPPmClose"), sizeof(TEXT("IBSPPmClose")) );\r
+\r
+       RegFlushKey( pm_hkey );\r
+       RegCloseKey( pm_hkey );\r
+\r
+       reg_status = RegCreateKeyEx( HKEY_LOCAL_MACHINE,\r
+               IBSP_PM_EVENTLOG_PATH, 0, NULL,\r
+               REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &pm_hkey, NULL );\r
+\r
+       if( reg_status != ERROR_SUCCESS )\r
+       {\r
+               fprintf(stderr, "Create EventLog Key failed with %d\n", reg_status );\r
+               return reg_status;\r
+       }\r
+\r
+       /* create/assign values to the key */\r
+       RegSetValueExW( pm_hkey, L"EventMessageFile", 0, REG_EXPAND_SZ,\\r
+               (LPBYTE)provider_path, sizeof(provider_path) );\r
+\r
+       RegSetValueEx( pm_hkey, TEXT("TypesSupported"), 0, REG_DWORD,\r
+               (LPBYTE)&typesSupp, sizeof(typesSupp) );\r
+\r
+       RegFlushKey( pm_hkey );\r
+       RegCloseKey( pm_hkey );\r
+\r
+       return reg_status;\r
+}\r
+\r
+\r
+/* Try to destroy IB WSD Performance Register Keys */\r
+static LONG\r
+_IBSPPerfmonDeregisterKeys( void )\r
+{\r
+       LONG    reg_status;\r
+\r
+       reg_status = RegDeleteKeyEx( HKEY_LOCAL_MACHINE,\r
+               IBSP_PM_REGISTRY_PATH IBSP_PM_SUBKEY_PERF,\r
+               (KEY_WOW64_32KEY | KEY_WOW64_64KEY), 0 );\r
+\r
+       if( reg_status != ERROR_SUCCESS )\r
+       {\r
+               fprintf( stderr,\r
+                       "_IBSPPerfmonRegisterKeys Remove SubKey failed with %d\n",\r
+                       GetLastError() );\r
+       }\r
+\r
+       reg_status = RegDeleteKeyEx( HKEY_LOCAL_MACHINE,\r
+               IBSP_PM_REGISTRY_PATH, (KEY_WOW64_32KEY | KEY_WOW64_64KEY), 0 );\r
+\r
+       if( reg_status != ERROR_SUCCESS )\r
+       {\r
+               fprintf( stderr,\r
+                       "_IBSPPerfmonRegisterKeys Remove SubKey failed with %d\n",\r
+                       GetLastError() );\r
+       }\r
+\r
+       reg_status = RegDeleteKeyEx( HKEY_LOCAL_MACHINE,\r
+               IBSP_PM_EVENTLOG_PATH, (KEY_WOW64_32KEY | KEY_WOW64_64KEY), 0 );\r
+\r
+       if( reg_status != ERROR_SUCCESS )\r
+       {\r
+               fprintf( stderr,\r
+                       "_IBSPPerfmonRegisterKeys Remove SubKey failed with %d\n",\r
+                       GetLastError() );\r
+       }\r
+\r
+       return reg_status;\r
+}\r
+\r
+\r
+/*\r
+ * functions will try to register performance counters\r
+ * definitions with PerfMon application.\r
+ * API externally called by lodctr.exe/unlodctr.exe utilities.\r
+ */\r
+static DWORD\r
+_IBSPPerfmonRegisterCounters( void )\r
+{\r
+       DWORD status;\r
+       char *ibsp_pm_ini_file = NULL;\r
+\r
+       ibsp_pm_ini_file = _IBSPGenerateFileName("unused ", IBSP_PM_INI_FILE);\r
+       if( !ibsp_pm_ini_file )\r
+       {\r
+               fprintf( stderr, "_IBSPGenerateFileName  failed\n" );\r
+               status = ERROR_NOT_ENOUGH_MEMORY;\r
+               goto Cleanup;\r
+       }\r
+\r
+       /*\r
+        * format commandline string, as per SDK :\r
+        *      Pointer to a null-terminated string that consists of one or more \r
+        *      arbitrary letters, a space, and then the name of the initialization\r
+        *      file.\r
+        */\r
+       status = LoadPerfCounterTextStrings( ibsp_pm_ini_file, TRUE );\r
+       if( status != ERROR_SUCCESS )\r
+       {\r
+               status = GetLastError();\r
+               fprintf( stderr,\r
+                       "IBSPPerfmonRegisterCounters install failed status %d\n", status );\r
+       }\r
+Cleanup:       \r
+       if ( ibsp_pm_ini_file )\r
+       {\r
+               HeapFree (GetProcessHeap (), 0, ibsp_pm_ini_file);\r
+       }\r
+\r
+       return status;\r
+}\r
+\r
+\r
+/*\r
+ * functions will try to unregister performance counters\r
+ * definitions with PerfMon application.\r
+ * API externally called by lodctr.exe/unlodctr.exe utilities.\r
+ */\r
+static DWORD\r
+_IBSPPerfmonDeregisterCounters( void )\r
+{\r
+       DWORD status;\r
+\r
+       /*\r
+        * format commandline string, as per SDK :\r
+        *      Pointer to a null-terminated string that consists of one or more \r
+        *      arbitrary letters, a space, and then the name of the initialization\r
+        *      file.\r
+        */\r
+       status = UnloadPerfCounterTextStrings(\r
+               TEXT("unused ") TEXT(IBSP_PM_SUBKEY_NAME), TRUE );\r
+       if( status != ERROR_SUCCESS )\r
+       {\r
+               fprintf( stderr,\r
+                       "IBSPPerfmonDeregisterCounters remove failed status %d\n",\r
+                       status );\r
+       }\r
+       return status;\r
+}\r
+\r
+#endif /* PERFMON_ENABLED */\r
+\r
+\r
+/*\r
+ * Function: usage\r
+ *   Description: Prints usage information.\r
+ */\r
+static void\r
+usage (char *progname)\r
+{\r
+       printf ("usage: %s [-i/-r [-p]]\n", progname);\r
+       printf ("    -i   Install the service provider\n"\r
+                       "    -r   Remove the %s service provider\n"\r
+                       "    -r <name>   Remove the specified service provider\n"\r
+                       "    -l   List service providers\n",VER_PROVIDER);\r
+}\r
+\r
+\r
+/* Function: print_providers\r
+ *   Description: \r
+ *     This function prints out each entry in the Winsock catalog.\r
+*/\r
+static void print_providers(void)\r
+{\r
+       WSAPROTOCOL_INFOW *protocol_info;\r
+       unsigned int protocol_count;\r
+       unsigned int i;\r
+       DWORD protocol_size;\r
+       INT err_no;\r
+       int rc;\r
+\r
+       /* Find the size of the buffer */\r
+       protocol_size = 0;\r
+       rc = WSCEnumProtocols (NULL, NULL, &protocol_size, &err_no);\r
+       if (rc == SOCKET_ERROR && err_no != WSAENOBUFS) {\r
+               printf("WSCEnumProtocols() returned error (%d)\n", err_no);\r
+               return;\r
+       }\r
+\r
+       /* Allocate the buffer */\r
+       protocol_info = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, protocol_size);\r
+       if (protocol_info == NULL) {\r
+               printf("HeapAlloc() failed\n");\r
+               return;\r
+       }\r
+\r
+       /* Enumerate the catalog for real */\r
+       rc = WSCEnumProtocols (NULL, protocol_info, &protocol_size, &err_no);\r
+       if (rc == SOCKET_ERROR) {\r
+               printf("WSCEnumProtocols returned error for real enumeration (%d)\n",\r
+                        err_no);\r
+               HeapFree (GetProcessHeap (), 0, protocol_info);\r
+               return;\r
+       }\r
+\r
+       protocol_count = rc;\r
+\r
+       for (i = 0; i < protocol_count; i++) {\r
+               printf ("%010d - %S\n", protocol_info[i].dwCatalogEntryId,\r
+                               protocol_info[i].szProtocol);\r
+       }\r
+\r
+       HeapFree (GetProcessHeap (), 0, protocol_info);\r
+\r
+       return;\r
+}\r
+\r
+/*\r
+ * Function: install_provider\r
+ *   Description: installs the service provider\r
+ *\r
+ * Note: most of the information setup here comes from "MSDN Home >\r
+ * MSDN Library > Windows Development > Network Devices and\r
+ * Protocols > Design Guide > System Area Networks > Windows Sockets\r
+ * Direct > Windows Sockets Direct Component Operation > Installing\r
+ * Windows Sockets Direct Components".\r
+ * The direct link is http://msdn.microsoft.com/library/default.asp?url=/library/en-us/network/hh/network/wsdp_2xrb.asp\r
+ */\r
+static void install_provider(void)\r
+{\r
+       int rc;\r
+       INT err_no;\r
+       LONG reg_error;\r
+       WSAPROTOCOL_INFOW provider;\r
+       HKEY hkey;\r
+    size_t res;\r
+    size_t st_len;\r
+\r
+       /* Now setup the key. */\r
+       reg_error = RegCreateKeyExA( HKEY_LOCAL_MACHINE, winsock_key_path,\r
+               0, NULL, REG_OPTION_NON_VOLATILE, (KEY_WRITE | KEY_READ), NULL,\r
+               &hkey, NULL );\r
+       if( reg_error == ERROR_SUCCESS )\r
+       {\r
+               reg_error = RegSetValueExA( hkey, openib_key_name, 0, REG_BINARY,\r
+                       (PBYTE)&provider_guid, sizeof(GUID) );\r
+               if( reg_error == ERROR_SUCCESS )\r
+               {\r
+                       /* Force the system to write the new key now. */\r
+                       RegFlushKey(hkey);\r
+               }\r
+               else\r
+               {\r
+                       fprintf(stderr, "RegSetValueEx failed with %d\n", GetLastError());\r
+               }\r
+\r
+               RegCloseKey(hkey);\r
+       }\r
+       else\r
+       {\r
+               fprintf(stderr, "Could not get a handle on Winsock registry (%d)\n", GetLastError());\r
+       }\r
+\r
+       /* Setup the values in PROTOCOL_INFO */\r
+       provider.dwServiceFlags1 = \r
+               XP1_GUARANTEED_DELIVERY | \r
+               XP1_GUARANTEED_ORDER | \r
+               XP1_MESSAGE_ORIENTED |\r
+               XP1_GRACEFUL_CLOSE;\r
+       provider.dwServiceFlags2 = 0;   /* Reserved */\r
+       provider.dwServiceFlags3 = 0;   /* Reserved */\r
+       provider.dwServiceFlags4 = 0;   /* Reserved */\r
+       provider.dwProviderFlags = PFL_HIDDEN;\r
+       provider.ProviderId = provider_guid;    /* Service Provider ID provided by vendor. Need to be changed later */\r
+       provider.dwCatalogEntryId = 0;\r
+       provider.ProtocolChain.ChainLen = 1;    /* Base Protocol Service Provider */\r
+       provider.iVersion = 2;  /* don't know what it is */\r
+       provider.iAddressFamily = AF_INET;\r
+       provider.iMaxSockAddr = 16;\r
+       provider.iMinSockAddr = 16;\r
+       provider.iSocketType = SOCK_STREAM;\r
+       provider.iProtocol = IPPROTO_TCP;\r
+       provider.iProtocolMaxOffset = 0;\r
+       provider.iNetworkByteOrder = BIGENDIAN;\r
+       provider.iSecurityScheme = SECURITY_PROTOCOL_NONE;\r
+       provider.dwMessageSize = 0xFFFFFFFF; /* IB supports 32-bit lengths for data transfers on RC */\r
+       provider.dwProviderReserved = 0;\r
+\r
+       st_len = strlen(provider_name);\r
+       rc = mbstowcs(provider.szProtocol, provider_name,st_len); //do not count \0\r
+       // We can't use there mbstowcs_s \r
+       //rc = mbstowcs_s(&convertedChars, provider.szProtocol, sizeof(provider_name), provider_name, );\r
+    if (rc  != st_len) {\r
+        printf("<install_provider> Can't convert string %s to WCHAR\n",provider_name);\r
+        printf("Converted %d from %d\n", rc, st_len);\r
+    }\r
+    wcscpy( provider.szProtocol + st_len, provider_prefix);\r
+    //wprintf(L"provider.szProtocol = %s\n",provider.szProtocol);\r
+\r
+       rc = WSCInstallProvider(\r
+               &provider_guid, provider_path, &provider, 1, &err_no );\r
+       if( rc == SOCKET_ERROR )\r
+       {\r
+               if( err_no == WSANO_RECOVERY )\r
+                       printf("The provider is already installed\n");\r
+               else\r
+                       printf("install_provider: WSCInstallProvider failed: %d\n", err_no);\r
+       }\r
+}\r
+\r
+/*\r
+ * Function: remove_provider\r
+ *   Description: removes our provider.\r
+ */\r
+static void remove_provider( const char* const provider_name )\r
+{\r
+       int rc;\r
+       int err_no;\r
+       LONG reg_error;\r
+       HKEY hkey;\r
+\r
+       /* Remove our key */\r
+       reg_error = RegOpenKeyExA(HKEY_LOCAL_MACHINE,\r
+                                                        winsock_key_path,\r
+                                                        0,\r
+                                                        (KEY_WRITE | KEY_READ),\r
+                                                        &hkey);\r
+       if (reg_error == ERROR_SUCCESS) {\r
+\r
+               reg_error = RegDeleteValueA(hkey, provider_name);\r
+               if (reg_error == ERROR_SUCCESS) {\r
+                       /* Force the system to remove the key now. */\r
+                       RegFlushKey(hkey);\r
+               } else {\r
+                       fprintf(stderr, "RegDeleteValue failed with %d\n", GetLastError());\r
+               }\r
+\r
+               RegCloseKey(hkey);\r
+       }\r
+\r
+       /* Remove from the catalog */\r
+       rc = WSCDeinstallProvider(&provider_guid, &err_no);\r
+       if (rc == SOCKET_ERROR) {\r
+               printf ("WSCDeinstallProvider failed: %d\n", err_no);\r
+       }\r
+\r
+#ifdef _WIN64\r
+       /* Remove from the 32-bit catalog too! */\r
+       rc = WSCDeinstallProvider32(&provider_guid, &err_no);\r
+       if (rc == SOCKET_ERROR) {\r
+               printf ("WSCDeinstallProvider32 failed: %d\n", err_no);\r
+       }\r
+#endif /* _WIN64 */\r
+}\r
+\r
+/* Function: main\r
+ *\r
+ *  Description:\r
+ *    Parse the command line arguments and call either the install or remove\r
+ *    routine.\r
+ */\r
+int __cdecl main (int argc, char *argv[])\r
+{\r
+       WSADATA wsd;\r
+\r
+       /* Load Winsock */\r
+       if (WSAStartup (MAKEWORD (2, 2), &wsd) != 0) {\r
+               printf ("InstallSP: Unable to load Winsock: %d\n", GetLastError ());\r
+               return -1;\r
+       }\r
+\r
+       /* Confirm that the WinSock DLL supports 2.2. Note that if the\r
+        * DLL supports versions greater than 2.2 in addition to 2.2, it\r
+        * will still return 2.2 in wVersion since that is the version we\r
+        * requested. */\r
+       if (LOBYTE (wsd.wVersion) != 2 || HIBYTE (wsd.wVersion) != 2) {\r
+\r
+               /* Tell the user that we could not find a usable WinSock DLL. */\r
+               WSACleanup ();\r
+               printf\r
+                       ("InstallSP: Unable to find a usable version of Winsock DLL\n");\r
+               return -1;\r
+       }\r
+       if (argc < 2) {\r
+               usage (argv[0]);\r
+               return -1;\r
+       }\r
+       if ((strlen (argv[1]) != 2) && (argv[1][0] != '-')\r
+               && (argv[1][0] != '/')) {\r
+               usage (argv[0]);\r
+               return -1;\r
+       }\r
+       switch (tolower (argv[1][1])) {\r
+\r
+       case 'i':\r
+               /* Install the Infiniband Service Provider */\r
+               install_provider ();\r
+#ifdef PERFMON_ENABLED\r
+               _IBSPPerfmonIniFilesGenerate();\r
+               if ( _IBSPPerfmonRegisterKeys() == ERROR_SUCCESS )\r
+                               _IBSPPerfmonRegisterCounters();\r
+#endif\r
+               break;\r
+\r
+       case 'r':\r
+               /* Remove the service provider */\r
+               if( argc == 2 )\r
+                       remove_provider( openib_key_name );\r
+               else\r
+                       remove_provider( argv[2] );\r
+#ifdef PERFMON_ENABLED\r
+               _IBSPPerfmonIniFilesRemove();\r
+               if ( _IBSPPerfmonDeregisterCounters() == ERROR_SUCCESS )\r
+                       _IBSPPerfmonDeregisterKeys();\r
+#endif\r
+               break;\r
+\r
+       case 'l':\r
+               /* List existing providers */\r
+               print_providers();\r
+               break;\r
+       \r
+       default:\r
+               usage (argv[0]);\r
+               break;\r
+       }\r
+\r
+       WSACleanup ();\r
+\r
+       return 0;\r
+}\r
diff --git a/trunk/tools/ndinstall/user/installsp.exe.manifest b/trunk/tools/ndinstall/user/installsp.exe.manifest
new file mode 100644 (file)
index 0000000..d5e574e
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r
+    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">\r
+    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">\r
+        <security>\r
+            <requestedPrivileges>\r
+                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>\r
+            </requestedPrivileges>\r
+        </security>\r
+    </trustInfo>\r
+</assembly>   
\ No newline at end of file
diff --git a/trunk/tools/ndinstall/user/installsp.rc b/trunk/tools/ndinstall/user/installsp.rc
new file mode 100644 (file)
index 0000000..51a73c8
--- /dev/null
@@ -0,0 +1,47 @@
+/*\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
+#include <oib_ver.h>\r
+\r
+#define VER_FILETYPE                           VFT_APP\r
+#define VER_FILESUBTYPE                                VFT2_UNKNOWN\r
+\r
+#ifdef _DEBUG_\r
+#define VER_FILEDESCRIPTION_STR                "Winsock Direct for InfiniBand installer (Debug)"\r
+#else\r
+#define VER_FILEDESCRIPTION_STR                "Winsock Direct for InfiniBand installer"\r
+#endif\r
+\r
+#define VER_INTERNALNAME_STR           "installsp.exe"\r
+#define VER_ORIGINALFILENAME_STR       "installsp.exe"\r
+\r
+#include <common.ver>\r
diff --git a/trunk/tools/ndinstall/user/makefile b/trunk/tools/ndinstall/user/makefile
new file mode 100644 (file)
index 0000000..a28a561
--- /dev/null
@@ -0,0 +1,8 @@
+#\r
+# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
+# file to this component.  This file merely indirects to the real make file\r
+# that is shared by all the driver components of the OpenIB Windows project.\r
+#\r
+MINIMUM_NT_TARGET_VERSION=0x502\r
+\r
+!INCLUDE ..\..\..\inc\openib.def\r