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.

269 lines
7.3 KiB

  1. #ifndef _RAS_H_
  2. #define _RAS_H_
  3. #define REG_RETRY_MAX 3
  4. #define URQ_RETRY_MAX 2
  5. #define ARQ_RETRY_MAX 3
  6. #define DRQ_RETRY_MAX 3
  7. #define RASIO_SEND_BUFFER_LIST_MAX 10
  8. #define REG_EXPIRE_TIME 4000
  9. #define ARQ_EXPIRE_TIME 4000
  10. #define NOT_RESEND_SEQ_NUM -1
  11. //(127.0.0.1 in network byte order)
  12. #define NET_LOCAL_IP_ADDR_INTERFACE 0x0100007F
  13. //(127.0.0.1 in host byte order)
  14. #define HOST_LOCAL_IP_ADDR_INTERFACE 0x7F000001
  15. extern const ASN1objectidentifier_s _OID_H225ProtocolIdentifierV1 [];
  16. extern const ASN1objectidentifier_s _OID_H225ProtocolIdentifierV2 [];
  17. #define OID_H225ProtocolIdentifierV1 const_cast<ASN1objectidentifier_s *> (_OID_H225ProtocolIdentifierV1);
  18. #define OID_H225ProtocolIdentifierV2 const_cast<ASN1objectidentifier_s *> (_OID_H225ProtocolIdentifierV2);
  19. #undef OID_ELEMENT
  20. #define OID_RasProtocolIdentifierV2 (ASN1objectidentifier_s *)_OID_RasProtocolIdentifierV2
  21. class RAS_CLIENT;
  22. struct EXPIRE_CONTEXT
  23. {
  24. WORD seqNumber;
  25. union
  26. {
  27. HDRVCALL DriverCallHandle;
  28. RAS_CLIENT * RasClient;
  29. };
  30. };
  31. typedef struct _ALIASCHANGE_REQUEST
  32. {
  33. LIST_ENTRY listEntry;
  34. ENDPOINT_ID rasEndpointID;
  35. WORD wRequestSeqNum;
  36. PH323_ALIASNAMES pAliasList;
  37. } ALIASCHANGE_REQUEST, *PALIASCHANGE_REQUEST;
  38. #define REG_TTL_MARGIN 2
  39. enum RAS_CLIENT_STATE
  40. {
  41. RAS_CLIENT_STATE_NONE = 0,
  42. RAS_CLIENT_STATE_INITIALIZED
  43. };
  44. //If the app wants to send an URQ but the TSP ihasn't received RCF yet then we
  45. //the information in this struct and send URQ when we get RCF.
  46. typedef struct _PENDINGURQ
  47. {
  48. WORD RRQSeqNumber;
  49. } PENDINGURQ;
  50. enum RAS_REGISTER_STATE
  51. {
  52. RAS_REGISTER_STATE_IDLE = 0,
  53. RAS_REGISTER_STATE_RRQSENT,
  54. RAS_REGISTER_STATE_RRQEXPIRED,
  55. RAS_REGISTER_STATE_REGISTERED,
  56. RAS_REGISTER_STATE_URQSENT,
  57. RAS_REGISTER_STATE_URQEXPIRED,
  58. RAS_REGISTER_STATE_UNREGISTERED,
  59. RAS_REGISTER_STATE_RRJ,
  60. RAS_REGISTER_STATE_URQRECVD,
  61. };
  62. class RAS_CLIENT
  63. {
  64. private:
  65. HANDLE m_hRegTimer;
  66. HANDLE m_hUnRegTimer;
  67. HANDLE m_hRegTTLTimer;
  68. PH323_ALIASNAMES m_pAliasList;//list of all the aliases registered with this list
  69. SOCKET m_Socket;
  70. CRITICAL_SECTION m_CriticalSection;
  71. RAS_REGISTER_STATE m_RegisterState;
  72. DWORD m_IoRefCount;
  73. RAS_CLIENT_STATE m_dwState;
  74. LIST_ENTRY m_sendFreeList;
  75. LIST_ENTRY m_sendPendingList;
  76. DWORD m_dwSendFreeLen;
  77. SOCKADDR_IN m_GKAddress;
  78. SOCKADDR_IN m_sockAddr;
  79. TransportAddress m_transportAddress;
  80. RAS_RECV_CONTEXT m_recvOverlapped;
  81. WORD m_lastRegisterSeqNum;
  82. WORD m_wTTLSeqNumber;
  83. WORD m_UnRegisterSeqNum;
  84. WORD m_wRASSeqNum;
  85. DWORD m_dwRegRetryCount;
  86. DWORD m_dwUnRegRetryCount;
  87. DWORD m_dwCallsInProgress;
  88. ENDPOINT_ID m_RASEndpointID;
  89. ASN1_CODER_INFO m_ASNCoderInfo;
  90. PENDINGURQ m_PendingURQ;
  91. DWORD m_dwRegTimeToLive;
  92. EXPIRE_CONTEXT* m_pRRQExpireContext;
  93. EXPIRE_CONTEXT* m_pURQExpireContext;
  94. LIST_ENTRY m_aliasChangeRequestList;
  95. RAS_SEND_CONTEXT *AllocSendBuffer();
  96. void FreeSendBuffer( RAS_SEND_CONTEXT * pBuffer );
  97. void OnInfoRequest( InfoRequest * IRQ );
  98. void ProcessRasMessage(IN RasMessage *rasMessage );
  99. void OnUnregistrationConfirm( IN UnregistrationConfirm *UCF );
  100. void OnUnregistrationReject( IN UnregistrationReject *URJ );
  101. void OnRegistrationReject( IN RegistrationReject * RRJ );
  102. void OnRegistrationConfirm( IN RegistrationConfirm * RCF );
  103. BOOL InitializeIo();
  104. BOOL IssueRecv();
  105. int TermASNCoder(void);
  106. int InitASNCoder(void);
  107. BOOL SendUCF( WORD seqNumber );
  108. BOOL SendURJ( WORD seqNumber, DWORD dwReason );
  109. void OnUnregistrationRequest( IN UnregistrationRequest *URQ );
  110. BOOL FreeSendList( PLIST_ENTRY pListHead );
  111. BOOL InitializeTTLTimer( IN RegistrationConfirm * RCF );
  112. HRESULT SendInfoRequestResponse(
  113. IN SOCKADDR_IN * RasAddress,
  114. IN USHORT SequenceNumber,
  115. IN InfoRequestResponse_perCallInfo * CallInfoList);
  116. HRESULT EncodeSendMessage(
  117. IN RasMessage * rasMessage );
  118. public:
  119. RAS_CLIENT();
  120. ~RAS_CLIENT();
  121. void Lock()
  122. {
  123. H323DBG((DEBUG_LEVEL_TRACE, "wait on RAS client lock:%p.", this ));
  124. EnterCriticalSection( &m_CriticalSection );
  125. H323DBG((DEBUG_LEVEL_TRACE, "RAS client locked: %p.", this ));
  126. }
  127. void Unlock()
  128. {
  129. LeaveCriticalSection( &m_CriticalSection );
  130. H323DBG((DEBUG_LEVEL_TRACE, "RAS client unlocked: %p.", this ));
  131. }
  132. WORD GetNextSeqNum()
  133. {
  134. WORD wSeqNum;
  135. Lock();
  136. wSeqNum = ++m_wRASSeqNum;
  137. if( wSeqNum == 0 )
  138. wSeqNum = ++m_wRASSeqNum;
  139. Unlock();
  140. return wSeqNum;
  141. }
  142. RAS_REGISTER_STATE GetRegState()
  143. {
  144. return m_RegisterState;
  145. }
  146. HRESULT GetEndpointID (
  147. OUT ASN1char16string_t * ReturnEndpointID);
  148. HRESULT GetLocalAddress (
  149. OUT SOCKADDR_IN * ReturnSocketAddress)
  150. {
  151. HRESULT hr;
  152. Lock();
  153. if (m_RegisterState == RAS_REGISTER_STATE_REGISTERED)
  154. {
  155. *ReturnSocketAddress = m_sockAddr;
  156. hr = S_OK;
  157. }
  158. else
  159. {
  160. hr = E_FAIL;
  161. }
  162. Unlock();
  163. return hr;
  164. }
  165. PH323_ALIASNAMES
  166. GetRegisteredAliasList()
  167. {
  168. return m_pAliasList;
  169. }
  170. BOOL Initialize( SOCKADDR_IN* psaGKAddr );
  171. void Shutdown();
  172. static void NTAPI RegExpiredCallback( PVOID dwParam1, BOOLEAN bTimer );
  173. static void NTAPI UnregExpiredCallback( PVOID dwParam1, BOOLEAN bTimer );
  174. static void NTAPI TTLExpiredCallback( IN PVOID dwParam1, IN BOOLEAN bTimer );
  175. BOOL SendRRQ( IN long seqNumber, IN PALIASCHANGE_REQUEST pAliasList );
  176. BOOL SendURQ( long seqNumber, EndpointIdentifier * pEndpointID );
  177. void RegExpired( WORD seqNumber );
  178. void UnregExpired( WORD seqNumber );
  179. void TTLExpired();
  180. static void NTAPI IoCompletionCallback(IN DWORD dwStatus, IN DWORD cbTransferred,
  181. IN LPOVERLAPPED pOverlapped );
  182. void OnSendComplete( IN DWORD dwStatus, RAS_SEND_CONTEXT *pOverlappedSend );
  183. void OnRecvComplete( IN DWORD dwStatus, RAS_RECV_CONTEXT * pOverlappedRecv );
  184. void HandleRegistryChange();
  185. BOOL IssueSend( RasMessage * pRasMessage )
  186. {
  187. return EncodeSendMessage (pRasMessage) == S_OK;
  188. }
  189. };
  190. void
  191. HandleRASCallMessage(
  192. IN RasMessage *pRasMessage
  193. );
  194. HRESULT RasStart (void);
  195. void RasStop (void);
  196. HRESULT RasSetAliasList (
  197. IN AliasAddress * AliasArray,
  198. IN DWORD Count);
  199. BOOL RasIsRegistered (void);
  200. HRESULT RasGetLocalAddress (
  201. OUT SOCKADDR_IN * ReturnLocalAddress);
  202. USHORT RasAllocSequenceNumber (void);
  203. HRESULT RasGetEndpointID (
  204. OUT EndpointIdentifier * ReturnEndpointID);
  205. HRESULT RasEncodeSendMessage (
  206. IN RasMessage * RasMessage);
  207. PH323_ALIASNAMES RASGetRegisteredAliasList();
  208. void RasHandleRegistryChange();
  209. #endif //_RAS_H_