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.

212 lines
6.2 KiB

  1. /*********************************************************************/
  2. /** Copyright(c) 1995 Microsoft Corporation. **/
  3. /*********************************************************************/
  4. //***
  5. //
  6. // Filename: rasapihd.c
  7. //
  8. // Description: Handler for RASAPI32 disconnect events
  9. //
  10. // History: May 11,1996 NarenG Created original version.
  11. //
  12. #include "ddm.h"
  13. #include "objects.h"
  14. #include "handlers.h"
  15. //**
  16. //
  17. // Call: RasApiCleanUpPort
  18. //
  19. // Returns: NO_ERROR - Success
  20. // Non-zero returns - Failure
  21. //
  22. // Description: Will cleanup a locally initiated disconnected port.
  23. //
  24. VOID
  25. RasApiCleanUpPort(
  26. IN PDEVICE_OBJECT pDeviceObj
  27. )
  28. {
  29. PCONNECTION_OBJECT pConnObj = NULL;
  30. //
  31. // If already cleaned up, then simply return
  32. //
  33. if ( pDeviceObj->hRasConn == NULL )
  34. {
  35. return;
  36. }
  37. pConnObj = ConnObjGetPointer(pDeviceObj->hConnection);
  38. if( (NULL != pConnObj) &&
  39. (0 == (pConnObj->fFlags & CONN_OBJ_DISCONNECT_INITIATED)))
  40. {
  41. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  42. "RasApiCleanUpPort: hanging up 0x%x",
  43. pDeviceObj->hRasConn);
  44. RasHangUp( pDeviceObj->hRasConn );
  45. }
  46. ConnObjRemoveLink( pDeviceObj->hConnection, pDeviceObj );
  47. DDM_PRINT(gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  48. "RasApiDisconnectHandler:Cleaning up locally initiated connection hPort=%d",
  49. pDeviceObj->hPort );
  50. //
  51. // Was this the last link in the connection
  52. //
  53. if ( ( pConnObj != NULL ) && ( pConnObj->cActiveDevices == 0 ) )
  54. {
  55. if ( pConnObj->hDIMInterface != INVALID_HANDLE_VALUE )
  56. {
  57. ROUTER_INTERFACE_OBJECT * pIfObject;
  58. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection));
  59. pIfObject = IfObjectGetPointer( pConnObj->hDIMInterface );
  60. if ( pIfObject != NULL )
  61. {
  62. IfObjectDisconnected( pIfObject );
  63. }
  64. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection));
  65. }
  66. //
  67. // Remove the Connection Object
  68. //
  69. ConnObjRemoveAndDeAllocate( pDeviceObj->hConnection );
  70. }
  71. //
  72. // Increase media for this port if we were previously connected.
  73. //
  74. if ( pDeviceObj->fFlags & DEV_OBJ_MARKED_AS_INUSE )
  75. {
  76. pDeviceObj->fFlags &= ~DEV_OBJ_MARKED_AS_INUSE;
  77. gblDeviceTable.NumDevicesInUse--;
  78. //
  79. // Increase media count for this device
  80. //
  81. if ( pDeviceObj->fFlags & DEV_OBJ_ALLOW_ROUTERS )
  82. {
  83. MediaObjAddToTable( pDeviceObj->wchDeviceType );
  84. }
  85. //
  86. // Possibly need to notify router managers of reachability
  87. // change
  88. //
  89. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  90. IfObjectNotifyAllOfReachabilityChange(TRUE,INTERFACE_OUT_OF_RESOURCES);
  91. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  92. }
  93. pDeviceObj->fFlags &= ~DEV_OBJ_OPENED_FOR_DIALOUT;
  94. pDeviceObj->hConnection = (HCONN)INVALID_HANDLE_VALUE;
  95. pDeviceObj->wchUserName[0] = (WCHAR)NULL;
  96. pDeviceObj->wchDomainName[0] = (WCHAR)NULL;
  97. pDeviceObj->wchCallbackNumber[0] = (WCHAR)NULL;
  98. pDeviceObj->hRasConn = NULL;
  99. //
  100. // If the service was paused while we were dialed out
  101. //
  102. if ( gblDDMConfigInfo.pServiceStatus->dwCurrentState == SERVICE_PAUSED )
  103. {
  104. DeviceObjCloseListening( pDeviceObj, NULL, 0, 0 );
  105. }
  106. RasSetRouterUsage( pDeviceObj->hPort, FALSE );
  107. //
  108. // If we have gotten a PnP remove message, then discard this port
  109. //
  110. if ( pDeviceObj->fFlags & DEV_OBJ_PNP_DELETE )
  111. {
  112. //
  113. // We do this in a worker thread since this thread may be
  114. // walking the device list, hence we cannot modify it here.
  115. //
  116. RtlQueueWorkItem( DeviceObjRemoveFromTable,
  117. pDeviceObj->hPort,
  118. WT_EXECUTEDEFAULT );
  119. }
  120. }
  121. //**
  122. //
  123. // Call: RasApiDisconnectHandler
  124. //
  125. // Returns: NO_ERROR - Success
  126. // Non-zero returns - Failure
  127. //
  128. // Description: Handles a disconnect notification for a port on which a
  129. // dialout was initiated by the router. We made this a separate
  130. // handler with a separate event because otherwise we would have
  131. // problems with race conditions between rasman setting this event
  132. // and rasapi32 setting this event.
  133. //
  134. VOID
  135. RasApiDisconnectHandler(
  136. IN DWORD dwEventIndex
  137. )
  138. {
  139. PDEVICE_OBJECT pDeviceObj;
  140. DWORD dwRetCode = NO_ERROR;
  141. RASCONNSTATUS RasConnectionStatus;
  142. DWORD dwBucketIndex = dwEventIndex
  143. - NUM_DDM_EVENTS
  144. - (gblDeviceTable.NumDeviceBuckets*2);
  145. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  146. DDM_PRINT(gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  147. "RasApiDisconnectHandler: Entered");
  148. for ( pDeviceObj = gblDeviceTable.DeviceBucket[dwBucketIndex];
  149. pDeviceObj != (DEVICE_OBJECT *)NULL;
  150. pDeviceObj = pDeviceObj->pNext )
  151. {
  152. //
  153. // If locally initiated, then this event means that the port is now
  154. // disconnected
  155. //
  156. if ( pDeviceObj->fFlags & DEV_OBJ_OPENED_FOR_DIALOUT )
  157. {
  158. ZeroMemory( &RasConnectionStatus, sizeof( RasConnectionStatus ) );
  159. RasConnectionStatus.dwSize = sizeof( RasConnectionStatus );
  160. dwRetCode = RasGetConnectStatus( pDeviceObj->hRasConn, &RasConnectionStatus );
  161. if ( ( dwRetCode != NO_ERROR ) ||
  162. ( ( dwRetCode == NO_ERROR ) &&
  163. ( RasConnectionStatus.rasconnstate == RASCS_Disconnected ) ) )
  164. {
  165. RasApiCleanUpPort( pDeviceObj );
  166. }
  167. }
  168. }
  169. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  170. }