Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
5.3 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. ndisutil.cpp
  7. FILE HISTORY:
  8. */
  9. #include "stdafx.h"
  10. #include "ndisutil.h"
  11. #include "rtrstr.h"
  12. #include "raserror.h"
  13. #include "ustringp.h"
  14. #include <ndispnp.h>
  15. //-------------------------------------------------------------------
  16. // Function: HrSendNdisHandlePnpEvent
  17. //
  18. // Purpose: Send to Ndis a HandlePnpEvent notification
  19. //
  20. // Parameters:
  21. // uiLayer - either NDIS or TDI
  22. // uiOperation - either BIND, RECONFIGURE, or UNBIND
  23. // pszUpper - a WIDE string containing the upper component name
  24. // pszLower - a WIDE string containing the lower component name
  25. // This is one of the Export names from that component
  26. // The values NULL and c_szEmpty are both supported
  27. // pmszBindList - a WIDE string containing the NULL terminiated list of strings
  28. // representing the bindlist, vaid only for reconfigure
  29. // The values NULL and c_szEmpty are both supported
  30. // pvData - Pointer to ndis component notification data. Content
  31. // determined by each component.
  32. // dwSizeData - Count of bytes in pvData
  33. //
  34. // Returns: HRESULT S_OK on success, HrFromLastWin32Error otherwise
  35. //
  36. // Notes: Do not use this routine directly, see...
  37. // HrSendNdisPnpBindOrderChange,
  38. // HrSendNdisPnpBindStateChange, or
  39. // HrSendNdisPnpReconfig
  40. //
  41. //-------------------------------------------------------------------
  42. HRESULT
  43. HrSendNdisHandlePnpEvent (
  44. UINT uiLayer,
  45. UINT uiOperation,
  46. LPCWSTR pszUpper,
  47. LPCWSTR pszLower,
  48. LPCWSTR pmszBindList,
  49. PVOID pvData,
  50. DWORD dwSizeData)
  51. {
  52. UNICODE_STRING umstrBindList;
  53. UNICODE_STRING ustrLower;
  54. UNICODE_STRING ustrUpper;
  55. UINT nRet;
  56. HRESULT hr = S_OK;
  57. Assert(NULL != pszUpper);
  58. Assert((NDIS == uiLayer)||(TDI == uiLayer));
  59. Assert( (BIND == uiOperation) || (RECONFIGURE == uiOperation) || (UNBIND == uiOperation) );
  60. // AssertSz( FImplies( ((NULL != pmszBindList) && (0 != lstrlenW( pmszBindList ))),
  61. // (RECONFIGURE == uiOperation) &&
  62. // (TDI == uiLayer) &&
  63. // (0 == lstrlenW( pszLower ))),
  64. // "bind order change requires a bind list, no lower, only for TDI, and with Reconfig for the operation" );
  65. // optional strings must be sent as empty strings
  66. //
  67. if (NULL == pszLower)
  68. {
  69. pszLower = c_szEmpty;
  70. }
  71. if (NULL == pmszBindList)
  72. {
  73. pmszBindList = c_szEmpty;
  74. }
  75. // build UNICDOE_STRINGs
  76. SetUnicodeMultiString( &umstrBindList, pmszBindList );
  77. SetUnicodeString( &ustrUpper, pszUpper );
  78. SetUnicodeString( &ustrLower, pszLower );
  79. // Now submit the notification
  80. nRet = NdisHandlePnPEvent( uiLayer,
  81. uiOperation,
  82. &ustrLower,
  83. &ustrUpper,
  84. &umstrBindList,
  85. (PVOID)pvData,
  86. dwSizeData );
  87. if (!nRet)
  88. {
  89. hr = HRESULT_FROM_WIN32(GetLastError());
  90. }
  91. // TraceError( "HrSendNdisHandlePnpEvent", hr );
  92. return( hr );
  93. }
  94. //-------------------------------------------------------------------
  95. // Function: HrSendNdisPnpReconfig
  96. //
  97. // Purpose: Send to Ndis a HandlePnpEvent reconfig notification
  98. //
  99. // Parameters: uiLayer - either NDIS or TDI
  100. // wszUpper - a WIDE string containing the upper component name
  101. // (typically a protocol)
  102. // wszLower - a WIDE string containing the lower component name
  103. // (typically an adapter bindname) The values NULL and
  104. // c_szEmpty are both supported
  105. // pvData - Pointer to ndis component notification data. Content
  106. // determined by each component.
  107. // dwSizeData - Count of bytes in pvData
  108. //
  109. // Returns: HRESULT S_OK on success, HrFromLastWin32Error otherwise
  110. //
  111. //-------------------------------------------------------------------
  112. HRESULT
  113. HrSendNdisPnpReconfig (
  114. UINT uiLayer,
  115. LPCWSTR wszUpper,
  116. LPCWSTR wszLower,
  117. PVOID pvData,
  118. DWORD dwSizeData)
  119. {
  120. Assert(NULL != wszUpper);
  121. Assert((NDIS == uiLayer)||(TDI == uiLayer));
  122. if (NULL == wszLower)
  123. {
  124. wszLower = c_szEmpty;
  125. }
  126. CString strLower;
  127. // tstring strLower;
  128. // If a lower component is specified, prefix with "\Device\" else
  129. // strLower's default of an empty string will be used.
  130. if ( wszLower && lstrlenW(wszLower))
  131. {
  132. strLower = c_szDevice;
  133. strLower += wszLower;
  134. }
  135. HRESULT hr = HrSendNdisHandlePnpEvent( uiLayer,
  136. RECONFIGURE,
  137. wszUpper,
  138. strLower,
  139. c_szEmpty,
  140. pvData,
  141. dwSizeData);
  142. // TraceError( "HrSendNdisPnpReconfig", hr);
  143. return hr;
  144. }