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.

389 lines
10 KiB

  1. #ifndef __pxsvc_q931_h
  2. #define __pxsvc_q931_h
  3. #include "q931msg.h"
  4. #include "ovioctx.h"
  5. #include "crv.h"
  6. /*---------------------------------------------------
  7. Copyright (c) 1998, Microsoft Corporation
  8. File: q931.h
  9. Purpose:
  10. Contains declarations specific to q931 processing that need
  11. not be present in cbridge.h.
  12. History:
  13. 1. created
  14. Byrisetty Rajeev (rajeevb) 26-Aug-1998
  15. ---------------------------------------------------*/
  16. // The H.225 spec calls for a 2 byte call reference value
  17. typedef WORD CALL_REF_TYPE;
  18. // Q931 source side states
  19. enum Q931_SOURCE_STATE
  20. {
  21. Q931_SOURCE_STATE_NOT_INIT = 0,
  22. Q931_SOURCE_STATE_INIT,
  23. Q931_SOURCE_STATE_CON_ESTD,
  24. Q931_SOURCE_STATE_SETUP_RCVD,
  25. Q931_SOURCE_STATE_REL_COMP_RCVD
  26. };
  27. // Q931 destination side states
  28. enum Q931_DEST_STATE
  29. {
  30. Q931_DEST_STATE_NOT_INIT = 0,
  31. Q931_DEST_STATE_INIT,
  32. Q931_DEST_STATE_CON_ESTD,
  33. Q931_DEST_STATE_CALL_PROC_RCVD,
  34. Q931_DEST_STATE_ALERTING_RCVD,
  35. Q931_DEST_STATE_CONNECT_RCVD,
  36. Q931_DEST_STATE_REL_COMP_RCVD
  37. };
  38. #ifdef DBG
  39. // CODEWORK: Define a static array of strings to use in dbg printfs
  40. // where the array can be indexed by the state.
  41. #endif DBG
  42. // Q931_INFO
  43. class Q931_INFO :
  44. public OVERLAPPED_PROCESSOR,
  45. public TIMER_PROCESSOR
  46. {
  47. public:
  48. inline Q931_INFO();
  49. inline void Init(
  50. IN H323_STATE &H323State
  51. );
  52. inline CALL_REF_TYPE GetCallRefVal();
  53. virtual HRESULT SendCallback(
  54. IN HRESULT CallbackHResult
  55. );
  56. virtual HRESULT ReceiveCallback(
  57. IN HRESULT CallbackHResult,
  58. IN BYTE *pBuf,
  59. IN DWORD BufLen
  60. );
  61. // Implementation is provided by SOURCE_Q931_INFO and DEST_Q931_INFO
  62. virtual HRESULT ReceiveCallback(
  63. IN Q931_MESSAGE *pQ931Message,
  64. IN H323_UserInformation *pH323UserInfo
  65. ) = 0;
  66. HRESULT CreateTimer(DWORD TimeoutValue);
  67. virtual void TimerCallback();
  68. HRESULT SendReleaseCompletePdu();
  69. HRESULT QueueSend(
  70. IN Q931_MESSAGE *pQ931Message,
  71. IN H323_UserInformation *pH323UserInfo
  72. );
  73. // queue an asynchronous receive call back
  74. HRESULT QueueReceive();
  75. void IncrementLifetimeCounter (void);
  76. void DecrementLifetimeCounter (void);
  77. protected:
  78. // call reference value for this call (Q931 portion)
  79. // A Call Reference Value is generated for each outbound call.
  80. // The CRV in PDUs corresponding to outbound calls needs to be
  81. // replaced because the external H.323 endpoint sees the call
  82. // as coming from the proxy. No CRV replacement is required for inbound
  83. // calls. But we need to store the CRV so that we can send the
  84. // CallProceeding/ReleaseComplete PDUs.
  85. // This variable is initialized when we process the Setup PDU.
  86. // Note that the Call Reference Value also includes the Call Reference Flag
  87. // which indicates whether the PDU is sent by the originator (0) or
  88. // destination (1) of the call.
  89. // m_CallRefVal always stores the Call Reference Value that we send in
  90. // the PDUs. So, SOURCE_Q931_INFO CRV will have the CRV flag set (since
  91. // it sends to the source) and the DEST_Q931_INFO CRV will have this flag
  92. // zeroed (since it is the source from the destination's point of view.
  93. CALL_REF_TYPE m_CallRefVal;
  94. };
  95. inline
  96. Q931_INFO::Q931_INFO(
  97. )
  98. : m_CallRefVal(0)
  99. {
  100. }
  101. inline void
  102. Q931_INFO::Init(
  103. IN H323_STATE &H323State
  104. )
  105. {
  106. // initialize the overlaped processor
  107. OVERLAPPED_PROCESSOR::Init(OPT_Q931, H323State);
  108. }
  109. class SOURCE_Q931_INFO :
  110. public Q931_INFO
  111. {
  112. public:
  113. inline SOURCE_Q931_INFO();
  114. inline void Init(
  115. IN SOURCE_H323_STATE &SourceH323State
  116. );
  117. inline HRESULT SetIncomingSocket(
  118. IN SOCKET IncomingSocket,
  119. IN SOCKADDR_IN * LocalAddress,
  120. IN SOCKADDR_IN * RemoteAddress);
  121. inline DEST_Q931_INFO &GetDestQ931Info();
  122. inline SOURCE_H245_INFO &GetSourceH245Info();
  123. // TimerValue contains the timer value in seconds, for a timer event
  124. // to be created when a queued send completes
  125. HRESULT ProcessDestPDU(
  126. IN Q931_MESSAGE *pQ931Message,
  127. IN H323_UserInformation *pH323UserInfo
  128. );
  129. virtual ~SOURCE_Q931_INFO();
  130. protected:
  131. Q931_SOURCE_STATE m_Q931SourceState;
  132. // this should never be called
  133. virtual HRESULT AcceptCallback(
  134. IN DWORD Status,
  135. IN SOCKET Socket,
  136. IN SOCKADDR_IN * LocalAddress,
  137. IN SOCKADDR_IN * RemoteAddress);
  138. virtual HRESULT ReceiveCallback(
  139. IN Q931_MESSAGE *pQ931Message,
  140. IN H323_UserInformation *pH323UserInfo
  141. );
  142. private:
  143. // processes PDUs when in Q931_SRC_CON_EST state
  144. HRESULT HandleStateSrcConEstd(
  145. IN Q931_MESSAGE *pQ931Message,
  146. IN H323_UserInformation *pH323UserInfo
  147. );
  148. // handles the release complete PDU - sends it to the
  149. // destination q931 instance, performs state transition and
  150. // initiates cleanup
  151. HRESULT HandleReleaseCompletePDU(
  152. IN Q931_MESSAGE *pQ931Message,
  153. IN H323_UserInformation *pH323UserInfo
  154. );
  155. // processes CONNECT PDU forwarded by the dest instance
  156. HRESULT ProcessConnectPDU(
  157. IN Q931_MESSAGE *pQ931Message,
  158. IN H323_UserInformation *pH323UserInfo
  159. );
  160. };
  161. inline
  162. SOURCE_Q931_INFO::SOURCE_Q931_INFO(
  163. )
  164. : m_Q931SourceState(Q931_SOURCE_STATE_NOT_INIT)
  165. {
  166. }
  167. inline void
  168. SOURCE_Q931_INFO::Init(
  169. IN SOURCE_H323_STATE &SourceH323State
  170. )
  171. {
  172. m_Q931SourceState = Q931_SOURCE_STATE_INIT;
  173. Q931_INFO::Init((H323_STATE &)SourceH323State);
  174. }
  175. class DEST_Q931_INFO :
  176. public Q931_INFO
  177. {
  178. public:
  179. inline DEST_Q931_INFO();
  180. inline HRESULT Init(
  181. IN DEST_H323_STATE &DestH323State
  182. );
  183. inline SOURCE_Q931_INFO &GetSourceQ931Info();
  184. inline DEST_H245_INFO &GetDestH245Info();
  185. // processes PDUs received from the source Q931 instance
  186. // and directs them to the method for processing the
  187. // specific PDU
  188. HRESULT ProcessSourcePDU(
  189. IN Q931_MESSAGE *pQ931Message,
  190. IN H323_UserInformation *pH323UserInfo
  191. );
  192. virtual ~DEST_Q931_INFO();
  193. protected:
  194. // state for the dest instance
  195. Q931_DEST_STATE m_Q931DestState;
  196. // this method should never be called
  197. virtual HRESULT AcceptCallback(
  198. IN DWORD Status,
  199. IN SOCKET Socket,
  200. IN SOCKADDR_IN * LocalAddress,
  201. IN SOCKADDR_IN * RemoteAddress);
  202. virtual HRESULT ReceiveCallback (
  203. IN Q931_MESSAGE *pQ931Message,
  204. IN H323_UserInformation *pH323UserInfo
  205. );
  206. private:
  207. // the following methods handle PDUs when the instance
  208. // is in a certain Q931 state
  209. HRESULT HandleStateDestConEstd(
  210. IN Q931_MESSAGE *pQ931Message,
  211. IN H323_UserInformation *pH323UserInfo
  212. );
  213. HRESULT HandleStateDestCallProcRcvd(
  214. IN Q931_MESSAGE *pQ931Message,
  215. IN H323_UserInformation *pH323UserInfo
  216. );
  217. HRESULT HandleStateDestAlertingRcvd(
  218. IN Q931_MESSAGE *pQ931Message,
  219. IN H323_UserInformation *pH323UserInfo
  220. );
  221. HRESULT HandleStateDestConnectRcvd(
  222. IN Q931_MESSAGE *pQ931Message,
  223. IN H323_UserInformation *pH323UserInfo
  224. );
  225. // the following methods handle a specific PDU for
  226. // any state of the Q931 instance. These are typically
  227. // called after the PDU has gone through one of the
  228. // HandleState* methods
  229. HRESULT HandleCallProceedingPDU(
  230. IN Q931_MESSAGE *pQ931Message,
  231. IN H323_UserInformation *pH323UserInfo
  232. );
  233. HRESULT HandleAlertingPDU(
  234. IN Q931_MESSAGE *pQ931Message,
  235. IN H323_UserInformation *pH323UserInfo
  236. );
  237. HRESULT HandleConnectPDU(
  238. IN Q931_MESSAGE *pQ931Message,
  239. IN H323_UserInformation *pH323UserInfo
  240. );
  241. // handles the release complete PDU - sends it to the
  242. // source q931 instance, performs state transition and
  243. // initiates cleanup
  244. HRESULT HandleReleaseCompletePDU(
  245. IN Q931_MESSAGE *pQ931Message,
  246. IN H323_UserInformation *pH323UserInfo
  247. );
  248. // the following methods process PDUs received from
  249. // the source Q931 instance
  250. // processes source Q.931 instance setup PDU
  251. HRESULT ProcessSourceSetupPDU(
  252. IN Q931_MESSAGE *pQ931Message,
  253. IN H323_UserInformation *pH323UserInfo
  254. );
  255. // other helper methods
  256. HRESULT ConnectToH323Endpoint(
  257. IN SOCKADDR_IN * DestinationAddress);
  258. HRESULT LookupDefaultDestination (
  259. OUT DWORD * ReturnAddress); // host order
  260. // if necessary, bring up the demand-dial interface
  261. HRESULT ConnectDemandDialInterface (void);
  262. };
  263. inline
  264. DEST_Q931_INFO::DEST_Q931_INFO(
  265. )
  266. : m_Q931DestState(Q931_DEST_STATE_NOT_INIT)
  267. {
  268. }
  269. inline HRESULT
  270. DEST_Q931_INFO::Init(
  271. IN DEST_H323_STATE &DestH323State
  272. )
  273. {
  274. m_Q931DestState = Q931_DEST_STATE_INIT;
  275. Q931_INFO::Init((H323_STATE &)DestH323State);
  276. return S_OK;
  277. }
  278. void
  279. Q931AsyncAcceptFunction (
  280. IN PVOID Context,
  281. IN SOCKET Socket,
  282. IN SOCKADDR_IN * LocalAddress,
  283. IN SOCKADDR_IN * RemoteAddress);
  284. HRESULT
  285. Q931CreateBindSocket (
  286. void);
  287. void Q931CloseSocket (
  288. void);
  289. HRESULT Q931StartLoopbackRedirect (
  290. void);
  291. void Q931StopLoopbackRedirect (
  292. void);
  293. extern SYNC_COUNTER Q931SyncCounter;
  294. extern ASYNC_ACCEPT Q931AsyncAccept;
  295. extern SOCKADDR_IN Q931ListenSocketAddress;
  296. extern HANDLE Q931LoopbackRedirectHandle;
  297. #endif // __pxsvc_q931_h