[ofw] [PATCH 1/2] tools/ndinstall: update to support multiple ND providers

Sean Hefty sean.hefty at intel.com
Thu Jul 2 15:32:49 PDT 2009


Update the ndinstall utility to support multiple ND providers.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
diff -up -r -X \mshefty\scm\winof\trunk\docs\dontdiff.txt -I '\$Id:' trunk\tools\ndinstall/user/installsp.c
branches\winverbs\tools\ndinstall/user/installsp.c
--- trunk\tools\ndinstall/user/installsp.c	2009-06-11 10:30:28.736750000 -0700
+++ branches\winverbs\tools\ndinstall/user/installsp.c	2009-06-24 11:07:48.535625000 -0700
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.
  * Portions Copyright (c) 2008 Microsoft Corporation.  All rights reserved.
+ * Copyright (c) 2009 Intel Corp, Inc.  All rights reserved.
  *
  * This software is available to you under the OpenIB.org BSD license
  * below:
@@ -41,48 +42,71 @@
  */
 
 #include <winsock2.h>
+#include <ws2tcpip.h>
 #include <ws2spi.h>
 #include <stdio.h>
+#include <string.h>
+#include "..\..\..\..\etc\user\getopt.c"
 
 #ifndef PFL_NETWORKDIRECT_PROVIDER
 #define PFL_NETWORKDIRECT_PROVIDER          0x00000010
 #endif
 
 /* Initialize the LSP's provider path for Infiband Service Provider dll */
-static const WCHAR provider_path[] = L"%SYSTEMROOT%\\system32\\ibndprov.dll";
-static const WCHAR provider_name[] = L"OpenFabrics Network Direct Provider";
-static const char openib_key_name[] = "OpenFabrics Alliance";
-
-/* Unique provider GUID generated with "uuidgen -s" */
-static GUID provider_guid = {
-	/* {52CDAA00-29D0-46be-8FC6-E51D7075C338} */
-	0x52CDAA00, 0x29D0, 0x46be,
-	{ 0x8f, 0xc6, 0xe5, 0x1d, 0x70, 0x75, 0xc3, 0x38 }
+#define IBAL_INDEX			0
+#define IBAL_DEBUG_INDEX	1
+#define WV_INDEX			2
+#define WV_DEBUG_INDEX		3
+#define MAX_INDEX			4
+
+int index;
+
+static const char * const provider_name[MAX_INDEX] = {
+	"IBAL", "IBAL (debug)", "WinVerbs", "WinVerbs (debug)"
+};
+
+static const WCHAR * const provider_path[MAX_INDEX] = {
+	L"%SYSTEMROOT%\\system32\\ibndprov.dll",
+	L"%SYSTEMROOT%\\system32\\ibndprov.dll",
+	L"%SYSTEMROOT%\\system32\\wvndprov.dll",
+	L"%SYSTEMROOT%\\system32\\wvndprovd.dll"
+};
+
+static const WCHAR * const provider_desc[MAX_INDEX] = {
+	L"OpenFabrics Network Direct Provider",
+	L"OpenFabrics Network Direct Provider (Debug)",
+	L"OpenFabrics Winverbs Network Direct Provider",
+	L"OpenFabrics Winverbs Network Direct Provider (Debug)"
+};
+
+static GUID provider_guid[MAX_INDEX] = {
+	// {52CDAA00-29D0-46be-8FC6-E51D7075C338}
+	{ 0x52CDAA00, 0x29D0, 0x46be, { 0x8f, 0xc6, 0xe5, 0x1d, 0x70, 0x75, 0xc3, 0x38 } },
+	// {52CDAA00-29D0-46be-8FC6-E51D7075C338}
+	{ 0x52CDAA00, 0x29D0, 0x46be, { 0x8f, 0xc6, 0xe5, 0x1d, 0x70, 0x75, 0xc3, 0x38 } },
+	// {854DCE83-C872-4462-A3EB-C961C40E59D0}
+	{ 0x854dce83, 0xc872, 0x4462, { 0xa3, 0xeb, 0xc9, 0x61, 0xc4, 0x0e, 0x59, 0xd0 } },
+	// {1B8F1692-EDD9-4153-A159-605A73BCFFCF}
+	{ 0x1b8f1692, 0xedd9, 0x4153, { 0xa1, 0x59, 0x60, 0x5a, 0x73, 0xbc, 0xff, 0xcf } }
 };
 
 #ifdef _WIN64
 #define WSCInstallProvider	WSCInstallProvider64_32
 #endif	/* _WIN64 */
 
-/*
- * Function: usage
- *   Description: Prints usage information.
- */
 static void
-usage (char *progname)
+show_usage (char *progname)
 {
-	printf ("usage: %s [-i/-r [-p]]\n", progname);
-	printf ("    -i   Install the OpenFabrics NetworkDirect service provider\n"
-			"    -r   Remove the OpenFabrics NetworkDirect service provider\n"
-			"    -r <name>   Remove the specified service provider\n"
-			"    -l   List service providers\n");
+	printf("usage: %s\n", progname);
+	printf("\tRemove, install, and list OFA Network Direct providers\n\n");
+	printf("\t[-[i|r] provider_name]  Install/remove the specified provider\n");
+	printf("\t[-d]                    Install/remove debug version of provider\n");
+	printf("\tprovider_name must be one of the following:\n");
+	printf("\t\tibal\n");
+	printf("\t\twinverbs\n");
 }
 
 
-/* Function: print_providers
- *   Description: 
- *     This function prints out each entry in the Winsock catalog.
-*/
 static void print_providers(void)
 {
 	WSAPROTOCOL_INFOW *protocol_info;
@@ -100,7 +124,6 @@ static void print_providers(void)
 		return;
 	}
 
-	/* Allocate the buffer */
 	protocol_info = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, protocol_size);
 	if (protocol_info == NULL) {
 		printf("HeapAlloc() failed\n");
@@ -118,8 +141,9 @@ static void print_providers(void)
 
 	protocol_count = rc;
 
+	printf("\nCurrent providers:\n");
 	for (i = 0; i < protocol_count; i++) {
-		printf ("%010d - %S\n", protocol_info[i].dwCatalogEntryId,
+		printf ("\t%010d - %S\n", protocol_info[i].dwCatalogEntryId,
 				protocol_info[i].szProtocol);
 	}
 
@@ -157,12 +181,17 @@ static void install_provider(void)
 	provider.dwServiceFlags3 = 0;	/* Reserved */
 	provider.dwServiceFlags4 = 0;	/* Reserved */
 	provider.dwProviderFlags = PFL_HIDDEN | PFL_NETWORKDIRECT_PROVIDER;
-	provider.ProviderId = provider_guid;	/* Service Provider ID provided by vendor. Need to be changed later */
+	provider.ProviderId = provider_guid[index];
 	provider.dwCatalogEntryId = 0;
 	provider.ProtocolChain.ChainLen = 1;	/* Base Protocol Service Provider */
 	provider.iVersion = 1;
-	provider.iAddressFamily = AF_INET;
-	provider.iMaxSockAddr = 16;
+	if (index == IBAL_INDEX || index == IBAL_DEBUG_INDEX) {
+		provider.iAddressFamily = AF_INET;
+		provider.iMaxSockAddr = sizeof(SOCKADDR_IN);
+	} else {
+		provider.iAddressFamily = AF_INET6;
+		provider.iMaxSockAddr = sizeof(SOCKADDR_IN6);
+	}
 	provider.iMinSockAddr = 16;
 	provider.iSocketType = -1;
 	provider.iProtocol = 0;
@@ -171,16 +200,19 @@ static void install_provider(void)
 	provider.iSecurityScheme = SECURITY_PROTOCOL_NONE;
 	provider.dwMessageSize = 0xFFFFFFFF; /* IB supports 32-bit lengths for data transfers on RC */
 	provider.dwProviderReserved = 0;
-	wcscpy( provider.szProtocol, provider_name );
+	wcscpy( provider.szProtocol, provider_desc[index] );
 
+	printf("\nInstalling %s provider: ", provider_name[index]);
 	rc = WSCInstallProvider(
-		&provider_guid, provider_path, &provider, 1, &err_no );
+		&provider_guid[index], provider_path[index], &provider, 1, &err_no );
 	if( rc == SOCKET_ERROR )
 	{
 		if( err_no == WSANO_RECOVERY )
-			printf("The provider is already installed\n");
+			printf("already installed\n");
 		else
-			printf("install_provider: WSCInstallProvider failed: %d\n", err_no);
+			printf("WSCInstallProvider failed: %d\n", err_no);
+	} else {
+		printf("successful\n");
 	}
 }
 
@@ -188,7 +220,7 @@ static void install_provider(void)
  * Function: remove_provider
  *   Description: removes our provider.
  */
-static void remove_provider( const char* const provider_name )
+static void remove_provider(void)
 {
 	int rc;
 	int err_no;
@@ -196,93 +228,105 @@ static void remove_provider( const char*
 	HKEY hkey;
 
 	/* Remove from the catalog */
-	rc = WSCDeinstallProvider(&provider_guid, &err_no);
+	printf("\nRemoving %s provider: ", provider_name[index]);
+	rc = WSCDeinstallProvider(&provider_guid[index], &err_no);
 	if (rc == SOCKET_ERROR) {
 		printf ("WSCDeinstallProvider failed: %d\n", err_no);
+	} else {
+		printf ("successful\n");
 	}
 
 #ifdef _WIN64
 	/* Remove from the 32-bit catalog too! */
-	rc = WSCDeinstallProvider32(&provider_guid, &err_no);
+	printf("Removing 32-bit %s provider: ", provider_name[index]);
+	rc = WSCDeinstallProvider32(&provider_guid[index], &err_no);
 	if (rc == SOCKET_ERROR) {
 		printf ("WSCDeinstallProvider32 failed: %d\n", err_no);
+	} else {
+		printf ("successful\n");
 	}
 #endif	/* _WIN64 */
 }
 
-/* Function: main
- *
- *  Description:
- *    Parse the command line arguments and call either the install or remove
- *    routine.
- */
+static int get_prov_index(char *name)
+{
+	int i;
+
+	for (i = 0; i < MAX_INDEX; i++) {
+		if (!_stricmp(provider_name[i], name)) {
+			index = i;
+			return 0;
+		}
+	}
+	return -1;
+}
+
 int __cdecl main (int argc, char *argv[])
 {
+	int ret, op;
+	int install = 0, remove = 0, debug = 0;
 	WSADATA wsd;
+	char *prov;
+
+	while ((op = getopt(argc, argv, "i:r:d")) != -1) {
+		switch (op) {
+		case 'i':
+			if (install || remove || get_prov_index(optarg)) {
+				goto usage;
+			}
+			install = 1;
+			break;
+		case 'r':
+			if (install || remove || get_prov_index(optarg)) {
+				goto usage;
+			}
+			remove = 1;
+			break;
+		case 'd':
+			debug = 1;
+			break;
+		default:
+			goto usage;
+		}
+	}
+
+	index += debug;
 
-	/* Load Winsock */
 	if (WSAStartup (MAKEWORD (2, 2), &wsd) != 0) {
 		printf ("InstallSP: Unable to load Winsock: %d\n", GetLastError ());
 		return -1;
 	}
 
-	/* Confirm that the WinSock DLL supports 2.2. Note that if the
-	 * DLL supports versions greater than 2.2 in addition to 2.2, it
-	 * will still return 2.2 in wVersion since that is the version we
-	 * requested. */
 	if (LOBYTE (wsd.wVersion) != 2 || HIBYTE (wsd.wVersion) != 2) {
-
-		/* Tell the user that we could not find a usable WinSock DLL. */
 		WSACleanup ();
-		printf
-			("InstallSP: Unable to find a usable version of Winsock DLL\n");
-		return -1;
+		printf("InstallSP: Unable to find a usable version of Winsock DLL\n");
+		ret = -1;
+		goto exit;
 	}
-	if (argc < 2) {
-		usage (argv[0]);
-		return -1;
-	}
-	if ((strlen (argv[1]) != 2) && (argv[1][0] != '-')
-		&& (argv[1][0] != '/')) {
-		usage (argv[0]);
-		return -1;
-	}
-	switch (tolower (argv[1][1])) {
 
-	case 'i':
-		/* Install the Infiniband Service Provider */
-		install_provider ();
+	if (install) {
+		install_provider();
 #ifdef PERFMON_ENABLED
 		_IBSPPerfmonIniFilesGenerate();
 		if ( _IBSPPerfmonRegisterKeys() == ERROR_SUCCESS )
 				_IBSPPerfmonRegisterCounters();
 #endif
-		break;
-
-	case 'r':
-		/* Remove the service provider */
-		if( argc == 2 )
-			remove_provider( openib_key_name );
-		else
-			remove_provider( argv[2] );
+	} else if (remove) {
+		remove_provider();
 #ifdef PERFMON_ENABLED
 		_IBSPPerfmonIniFilesRemove();
 		if ( _IBSPPerfmonDeregisterCounters() == ERROR_SUCCESS )
 			_IBSPPerfmonDeregisterKeys();
 #endif
-		break;
-
-	case 'l':
-		/* List existing providers */
-		print_providers();
-		break;
-	
-	default:
-		usage (argv[0]);
-		break;
 	}
 
-	WSACleanup ();
+	print_providers();
 
-	return 0;
+exit:
+	WSACleanup();
+	return ret;
+
+usage:
+	show_usage(argv[0]);
+	return -1;
 }





More information about the ofw mailing list