ndinstall: update installer to support both IBAL and WV ND providers
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Fri, 10 Jul 2009 17:57:19 +0000 (17:57 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Fri, 10 Jul 2009 17:57:19 +0000 (17:57 +0000)
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2284 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

tools/ndinstall/user/installsp.c

index 3d55d0d..d8b37c8 100644 (file)
@@ -1,6 +1,7 @@
 /*\r
  * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.\r
  * Portions Copyright (c) 2008 Microsoft Corporation.  All rights reserved.\r
+ * Copyright (c) 2009 Intel Corp, Inc.  All rights reserved.\r
  *\r
  * This software is available to you under the OpenIB.org BSD license\r
  * below:\r
  */\r
 \r
 #include <winsock2.h>\r
+#include <ws2tcpip.h>\r
 #include <ws2spi.h>\r
 #include <stdio.h>\r
+#include <string.h>\r
+#include "..\..\..\..\etc\user\getopt.c"\r
 \r
 #ifndef PFL_NETWORKDIRECT_PROVIDER\r
 #define PFL_NETWORKDIRECT_PROVIDER          0x00000010\r
 #endif\r
 \r
 /* Initialize the LSP's provider path for Infiband Service Provider dll */\r
-static const WCHAR provider_path[] = L"%SYSTEMROOT%\\system32\\ibndprov.dll";\r
-static const WCHAR provider_name[] = L"OpenFabrics Network Direct Provider";\r
-static const char openib_key_name[] = "OpenFabrics Alliance";\r
-\r
-/* Unique provider GUID generated with "uuidgen -s" */\r
-static GUID provider_guid = {\r
-       /* {52CDAA00-29D0-46be-8FC6-E51D7075C338} */\r
-       0x52CDAA00, 0x29D0, 0x46be,\r
-       { 0x8f, 0xc6, 0xe5, 0x1d, 0x70, 0x75, 0xc3, 0x38 }\r
+#define IBAL_INDEX                     0\r
+#define IBAL_DEBUG_INDEX       1\r
+#define WV_INDEX                       2\r
+#define WV_DEBUG_INDEX         3\r
+#define MAX_INDEX                      4\r
+\r
+int index;\r
+\r
+static const char * const provider_name[MAX_INDEX] = {\r
+       "IBAL", "IBAL (debug)", "WinVerbs", "WinVerbs (debug)"\r
+};\r
+\r
+static const WCHAR * const provider_path[MAX_INDEX] = {\r
+       L"%SYSTEMROOT%\\system32\\ibndprov.dll",\r
+       L"%SYSTEMROOT%\\system32\\ibndprov.dll",\r
+       L"%SYSTEMROOT%\\system32\\wvndprov.dll",\r
+       L"%SYSTEMROOT%\\system32\\wvndprovd.dll"\r
+};\r
+\r
+static const WCHAR * const provider_desc[MAX_INDEX] = {\r
+       L"OpenFabrics Network Direct Provider",\r
+       L"OpenFabrics Network Direct Provider (Debug)",\r
+       L"OpenFabrics Winverbs Network Direct Provider",\r
+       L"OpenFabrics Winverbs Network Direct Provider (Debug)"\r
+};\r
+\r
+static GUID provider_guid[MAX_INDEX] = {\r
+       // {52CDAA00-29D0-46be-8FC6-E51D7075C338}\r
+       { 0x52CDAA00, 0x29D0, 0x46be, { 0x8f, 0xc6, 0xe5, 0x1d, 0x70, 0x75, 0xc3, 0x38 } },\r
+       // {52CDAA00-29D0-46be-8FC6-E51D7075C338}\r
+       { 0x52CDAA00, 0x29D0, 0x46be, { 0x8f, 0xc6, 0xe5, 0x1d, 0x70, 0x75, 0xc3, 0x38 } },\r
+       // {854DCE83-C872-4462-A3EB-C961C40E59D0}\r
+       { 0x854dce83, 0xc872, 0x4462, { 0xa3, 0xeb, 0xc9, 0x61, 0xc4, 0x0e, 0x59, 0xd0 } },\r
+       // {1B8F1692-EDD9-4153-A159-605A73BCFFCF}\r
+       { 0x1b8f1692, 0xedd9, 0x4153, { 0xa1, 0x59, 0x60, 0x5a, 0x73, 0xbc, 0xff, 0xcf } }\r
 };\r
 \r
 #ifdef _WIN64\r
 #define WSCInstallProvider     WSCInstallProvider64_32\r
 #endif /* _WIN64 */\r
 \r
-/*\r
- * Function: usage\r
- *   Description: Prints usage information.\r
- */\r
 static void\r
-usage (char *progname)\r
+show_usage (char *progname)\r
 {\r
-       printf ("usage: %s [-i/-r [-p]]\n", progname);\r
-       printf ("    -i   Install the OpenFabrics NetworkDirect service provider\n"\r
-                       "    -r   Remove the OpenFabrics NetworkDirect service provider\n"\r
-                       "    -r <name>   Remove the specified service provider\n"\r
-                       "    -l   List service providers\n");\r
+       printf("usage: %s\n", progname);\r
+       printf("\tRemove, install, and list OFA Network Direct providers\n\n");\r
+       printf("\t[-[i|r] provider_name]  Install/remove the specified provider\n");\r
+       printf("\t[-d]                    Install/remove debug version of provider\n");\r
+       printf("\tprovider_name must be one of the following:\n");\r
+       printf("\t\tibal\n");\r
+       printf("\t\twinverbs\n");\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
@@ -100,7 +124,6 @@ static void print_providers(void)
                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
@@ -118,8 +141,9 @@ static void print_providers(void)
 \r
        protocol_count = rc;\r
 \r
+       printf("\nCurrent providers:\n");\r
        for (i = 0; i < protocol_count; i++) {\r
-               printf ("%010d - %S\n", protocol_info[i].dwCatalogEntryId,\r
+               printf ("\t%010d - %S\n", protocol_info[i].dwCatalogEntryId,\r
                                protocol_info[i].szProtocol);\r
        }\r
 \r
@@ -157,12 +181,17 @@ static void install_provider(void)
        provider.dwServiceFlags3 = 0;   /* Reserved */\r
        provider.dwServiceFlags4 = 0;   /* Reserved */\r
        provider.dwProviderFlags = PFL_HIDDEN | PFL_NETWORKDIRECT_PROVIDER;\r
-       provider.ProviderId = provider_guid;    /* Service Provider ID provided by vendor. Need to be changed later */\r
+       provider.ProviderId = provider_guid[index];\r
        provider.dwCatalogEntryId = 0;\r
        provider.ProtocolChain.ChainLen = 1;    /* Base Protocol Service Provider */\r
        provider.iVersion = 1;\r
-       provider.iAddressFamily = AF_INET;\r
-       provider.iMaxSockAddr = 16;\r
+       if (index == IBAL_INDEX || index == IBAL_DEBUG_INDEX) {\r
+               provider.iAddressFamily = AF_INET;\r
+               provider.iMaxSockAddr = sizeof(SOCKADDR_IN);\r
+       } else {\r
+               provider.iAddressFamily = AF_INET6;\r
+               provider.iMaxSockAddr = sizeof(SOCKADDR_IN6);\r
+       }\r
        provider.iMinSockAddr = 16;\r
        provider.iSocketType = -1;\r
        provider.iProtocol = 0;\r
@@ -171,16 +200,19 @@ static void install_provider(void)
        provider.iSecurityScheme = SECURITY_PROTOCOL_NONE;\r
        provider.dwMessageSize = 0xFFFFFFFF; /* IB supports 32-bit lengths for data transfers on RC */\r
        provider.dwProviderReserved = 0;\r
-       wcscpy( provider.szProtocol, provider_name );\r
+       wcscpy( provider.szProtocol, provider_desc[index] );\r
 \r
+       printf("\nInstalling %s provider: ", provider_name[index]);\r
        rc = WSCInstallProvider(\r
-               &provider_guid, provider_path, &provider, 1, &err_no );\r
+               &provider_guid[index], provider_path[index], &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
+                       printf("already installed\n");\r
                else\r
-                       printf("install_provider: WSCInstallProvider failed: %d\n", err_no);\r
+                       printf("WSCInstallProvider failed: %d\n", err_no);\r
+       } else {\r
+               printf("successful\n");\r
        }\r
 }\r
 \r
@@ -188,7 +220,7 @@ static void install_provider(void)
  * Function: remove_provider\r
  *   Description: removes our provider.\r
  */\r
-static void remove_provider( const char* const provider_name )\r
+static void remove_provider(void)\r
 {\r
        int rc;\r
        int err_no;\r
@@ -196,93 +228,105 @@ static void remove_provider( const char* const provider_name )
        HKEY hkey;\r
 \r
        /* Remove from the catalog */\r
-       rc = WSCDeinstallProvider(&provider_guid, &err_no);\r
+       printf("\nRemoving %s provider: ", provider_name[index]);\r
+       rc = WSCDeinstallProvider(&provider_guid[index], &err_no);\r
        if (rc == SOCKET_ERROR) {\r
                printf ("WSCDeinstallProvider failed: %d\n", err_no);\r
+       } else {\r
+               printf ("successful\n");\r
        }\r
 \r
 #ifdef _WIN64\r
        /* Remove from the 32-bit catalog too! */\r
-       rc = WSCDeinstallProvider32(&provider_guid, &err_no);\r
+       printf("Removing 32-bit %s provider: ", provider_name[index]);\r
+       rc = WSCDeinstallProvider32(&provider_guid[index], &err_no);\r
        if (rc == SOCKET_ERROR) {\r
                printf ("WSCDeinstallProvider32 failed: %d\n", err_no);\r
+       } else {\r
+               printf ("successful\n");\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
+static int get_prov_index(char *name)\r
+{\r
+       int i;\r
+\r
+       for (i = 0; i < MAX_INDEX; i++) {\r
+               if (!_stricmp(provider_name[i], name)) {\r
+                       index = i;\r
+                       return 0;\r
+               }\r
+       }\r
+       return -1;\r
+}\r
+\r
 int __cdecl main (int argc, char *argv[])\r
 {\r
+       int ret, op;\r
+       int install = 0, remove = 0, debug = 0;\r
        WSADATA wsd;\r
+       char *prov;\r
+\r
+       while ((op = getopt(argc, argv, "i:r:d")) != -1) {\r
+               switch (op) {\r
+               case 'i':\r
+                       if (install || remove || get_prov_index(optarg)) {\r
+                               goto usage;\r
+                       }\r
+                       install = 1;\r
+                       break;\r
+               case 'r':\r
+                       if (install || remove || get_prov_index(optarg)) {\r
+                               goto usage;\r
+                       }\r
+                       remove = 1;\r
+                       break;\r
+               case 'd':\r
+                       debug = 1;\r
+                       break;\r
+               default:\r
+                       goto usage;\r
+               }\r
+       }\r
+\r
+       index += debug;\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
+               printf("InstallSP: Unable to find a usable version of Winsock DLL\n");\r
+               ret = -1;\r
+               goto exit;\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
+       if (install) {\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
+       } else if (remove) {\r
+               remove_provider();\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
+       print_providers();\r
+\r
+exit:\r
+       WSACleanup();\r
+       return ret;\r
 \r
-       return 0;\r
+usage:\r
+       show_usage(argv[0]);\r
+       return -1;\r
 }\r