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.

227 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. net\routing\ipx\sap\adaptdb.c
  5. Abstract:
  6. This module implements interface to net adapter driver
  7. notification mechanism for standalone (not part of a router) SAP
  8. agent
  9. Author:
  10. Vadim Eydelman 05-15-1995
  11. Revision History:
  12. --*/
  13. #include "sapp.h"
  14. HANDLE ConfigEvent;
  15. HANDLE ConfigPort;
  16. // Interval for periodic update broadcasts (for standalone service only)
  17. ULONG UpdateInterval = SAP_UPDATE_INTERVAL_DEF;
  18. // Server aging timeout (for standalone service only)
  19. ULONG WanUpdateMode = SAP_WAN_UPDATE_MODE_DEF;
  20. // Update mode on WAN lines (for standalone service only)
  21. ULONG WanUpdateInterval = SAP_WAN_UPDATE_INTERVAL_DEF;
  22. // Interval for periodic update broadcasts on WAN lines (for standalone service only)
  23. ULONG ServerAgingTimeout = SAP_AGING_TIMEOUT_DEF;
  24. // Makes pnp changes to an interface
  25. DWORD SapReconfigureInterface (ULONG idx,
  26. PIPX_ADAPTER_BINDING_INFO pAdapter);
  27. /*++
  28. *******************************************************************
  29. C r e a t e A d a p t e r P o r t
  30. Routine Description:
  31. Allocates resources and establishes connection to net adapter
  32. notification mechanism
  33. Arguments:
  34. cfgEvent - event to be signalled when adapter configuration changes
  35. Return Value:
  36. NO_ERROR - resources were allocated successfully
  37. other - reason of failure (windows error code)
  38. *******************************************************************
  39. --*/
  40. DWORD
  41. CreateAdapterPort (
  42. IN HANDLE *cfgEvent
  43. ) {
  44. DWORD status;
  45. ADAPTERS_GLOBAL_PARAMETERS params;
  46. ConfigEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  47. if (ConfigEvent!=NULL) {
  48. *cfgEvent = ConfigEvent;
  49. ConfigPort = IpxCreateAdapterConfigurationPort(
  50. ConfigEvent,
  51. &params);
  52. if (ConfigPort!=INVALID_HANDLE_VALUE)
  53. return NO_ERROR;
  54. else {
  55. status = GetLastError ();
  56. Trace (DEBUG_FAILURES, "File: %s, line %ld."
  57. " Failed to create adapter cfg port(gle:%ld).",
  58. __FILE__, __LINE__, status);
  59. }
  60. CloseHandle (ConfigEvent);
  61. }
  62. else {
  63. status = GetLastError ();
  64. Trace (DEBUG_FAILURES, "File: %s, line %ld."
  65. " Failed to create cfg event(gle:%ld).",
  66. __FILE__, __LINE__, status);
  67. }
  68. return status;
  69. }
  70. /*++
  71. *******************************************************************
  72. D e l e t e A d a p t e r P o r t
  73. Routine Description:
  74. Dispose of resources and break connection to net adapter
  75. notification mechanism
  76. Arguments:
  77. None
  78. Return Value:
  79. None
  80. *******************************************************************
  81. --*/
  82. VOID
  83. DeleteAdapterPort (
  84. void
  85. ) {
  86. IpxDeleteAdapterConfigurationPort (ConfigPort);
  87. ConfigPort = NULL;
  88. CloseHandle (ConfigEvent);
  89. ConfigEvent = NULL;
  90. }
  91. /*++
  92. *******************************************************************
  93. P r o c e s s A d a p t e r E v e n t s
  94. Routine Description:
  95. Dequeues and process adapter configuration change events and maps them
  96. to interface configuration calls
  97. This routine should be called when configuration event is signalled
  98. Arguments:
  99. None
  100. Return Value:
  101. None
  102. *******************************************************************
  103. --*/
  104. VOID
  105. ProcessAdapterEvents (
  106. VOID
  107. ) {
  108. ULONG cfgStatus;
  109. ADAPTER_INFO params;
  110. ULONG idx;
  111. SAP_IF_INFO info;
  112. IPX_ADAPTER_BINDING_INFO adapter;
  113. NET_INTERFACE_TYPE InterfaceType;
  114. DWORD dwErr;
  115. while (IpxGetQueuedAdapterConfigurationStatus (
  116. ConfigPort,
  117. &idx,
  118. &cfgStatus,
  119. &params)==NO_ERROR) {
  120. switch (cfgStatus) {
  121. case ADAPTER_CREATED:
  122. case ADAPTER_UP:
  123. Trace (DEBUG_ADAPTERS, "New adapter %d"
  124. " (addr: %02X%02X%02X%02X:"
  125. "%02X%02X%02X%02X%02X%02X).",
  126. idx,
  127. params.Network[0],
  128. params.Network[1],
  129. params.Network[2],
  130. params.Network[3],
  131. params.LocalNode[0],
  132. params.LocalNode[1],
  133. params.LocalNode[2],
  134. params.LocalNode[3],
  135. params.LocalNode[4],
  136. params.LocalNode[5]);
  137. info.AdminState = ADMIN_STATE_ENABLED;
  138. info.PacketType = IPX_STANDARD_PACKET_TYPE;
  139. info.Supply = ADMIN_STATE_ENABLED;
  140. info.Listen = ADMIN_STATE_ENABLED;
  141. info.GetNearestServerReply = ADMIN_STATE_ENABLED;
  142. IpxNetCpy (adapter.Network, params.Network);
  143. IpxNodeCpy (adapter.LocalNode, params.LocalNode);
  144. if (params.NdisMedium==NdisMediumWan) {
  145. InterfaceType = DEMAND_DIAL;
  146. switch (WanUpdateMode) {
  147. case SAP_WAN_NO_UPDATE:
  148. info.UpdateMode = IPX_NO_UPDATE;
  149. break;
  150. case SAP_WAN_CHANGES_ONLY:
  151. info.UpdateMode = IPX_STANDARD_UPDATE;
  152. info.PeriodicUpdateInterval = MAXULONG;
  153. break;
  154. case SAP_WAN_STANDART_UPDATE:
  155. info.UpdateMode = IPX_STANDARD_UPDATE;
  156. info.PeriodicUpdateInterval = WanUpdateInterval*60;
  157. info.AgeIntervalMultiplier = ServerAgingTimeout/UpdateInterval;
  158. break;
  159. }
  160. IpxNodeCpy (adapter.RemoteNode, params.RemoteNode);
  161. }
  162. else {
  163. InterfaceType = PERMANENT;
  164. info.UpdateMode = IPX_STANDARD_UPDATE;
  165. info.PeriodicUpdateInterval = UpdateInterval*60;
  166. info.AgeIntervalMultiplier = ServerAgingTimeout/UpdateInterval;
  167. memset (adapter.RemoteNode, 0xFF, sizeof (adapter.RemoteNode));
  168. }
  169. adapter.MaxPacketSize = params.MaxPacketSize;
  170. adapter.AdapterIndex = idx;
  171. if (((dwErr = SapCreateSapInterface (L"",idx, InterfaceType, &info)) == NO_ERROR)
  172. && (SapSetInterfaceEnable (idx, TRUE)==NO_ERROR)) {
  173. SapBindSapInterfaceToAdapter (idx, &adapter);
  174. }
  175. else if (dwErr == ERROR_ALREADY_EXISTS) {
  176. SapReconfigureInterface (idx, &adapter);
  177. Trace (DEBUG_ADAPTERS, "Adapter %d has been reconfigured", idx);
  178. }
  179. break;
  180. case ADAPTER_DOWN:
  181. case ADAPTER_DELETED:
  182. Trace (DEBUG_ADAPTERS, "Adapter %d is gone.", idx);
  183. SapDeleteSapInterface (idx);
  184. break;
  185. default:
  186. Trace (DEBUG_ADAPTERS, "Unknown adapter event %d.", cfgStatus);
  187. }
  188. }
  189. }