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.

439 lines
13 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. line.h
  5. Abstract:
  6. Definitions for H.323 TAPI Service Provider line device.
  7. Author:
  8. Nikhil Bobde (NikhilB)
  9. Revision History:
  10. --*/
  11. #ifndef _LINE_H_
  12. #define _LINE_H_
  13. //
  14. // Header files
  15. //
  16. #include "call.h"
  17. extern H323_OCTETSTRING g_ProductID;
  18. extern H323_OCTETSTRING g_ProductVersion;
  19. enum LINEOBJECT_STATE
  20. {
  21. LINEOBJECT_INITIALIZED = 0x00000001,
  22. LINEOBJECT_SHUTDOWN = 0x00000002,
  23. };
  24. //
  25. // Line device GUID
  26. //
  27. DEFINE_GUID(LINE_H323,
  28. 0xe41e1898, 0x7292, 0x11d2, 0xba, 0xd6, 0x00, 0xc0, 0x4f, 0x8e, 0xf6, 0xe3);
  29. //
  30. // Line capabilities
  31. //
  32. #define H323_MAXADDRSPERLINE 1
  33. #define H323_MAXCALLSPERADDR 32768
  34. #define H323_LINE_ADDRESSMODES LINEADDRESSMODE_ADDRESSID
  35. #define H323_LINE_ADDRESSTYPES (LINEADDRESSTYPE_DOMAINNAME | \
  36. LINEADDRESSTYPE_IPADDRESS | \
  37. LINEADDRESSTYPE_PHONENUMBER | \
  38. LINEADDRESSTYPE_EMAILNAME)
  39. #define H323_LINE_BEARERMODES (LINEBEARERMODE_DATA | \
  40. LINEBEARERMODE_VOICE)
  41. #define H323_LINE_DEFMEDIAMODES LINEMEDIAMODE_AUTOMATEDVOICE
  42. #define H323_LINE_DEVCAPFLAGS (LINEDEVCAPFLAGS_CLOSEDROP | \
  43. LINEDEVCAPFLAGS_MSP | \
  44. LINEDEVCAPFLAGS_LOCAL )
  45. #define H323_LINE_DEVSTATUSFLAGS (LINEDEVSTATUSFLAGS_CONNECTED | \
  46. LINEDEVSTATUSFLAGS_INSERVICE)
  47. #define H323_LINE_MAXRATE 1048576 //1 mbps
  48. #define H323_LINE_MEDIAMODES (H323_LINE_DEFMEDIAMODES | \
  49. LINEMEDIAMODE_INTERACTIVEVOICE | \
  50. LINEMEDIAMODE_VIDEO)
  51. #define H323_LINE_LINEFEATURES (LINEFEATURE_MAKECALL | \
  52. LINEFEATURE_FORWARD | \
  53. LINEFEATURE_FORWARDFWD )
  54. //
  55. // Type definitions
  56. //
  57. typedef enum _H323_LINESTATE
  58. {
  59. H323_LINESTATE_NONE = 0, //before call to LineOPen
  60. H323_LINESTATE_OPENED, //after call to lineOpen
  61. H323_LINESTATE_OPENING,
  62. H323_LINESTATE_CLOSING,
  63. H323_LINESTATE_LISTENING
  64. } H323_LINESTATE, *PH323_LINESTATE;
  65. typedef struct _TAPI_LINEREQUEST_DATA
  66. {
  67. DWORD EventID;
  68. HDRVCALL hdCall1;
  69. union {
  70. HDRVCALL hdCall2;
  71. DWORD dwDisconnectMode;
  72. };
  73. WORD wCallReference;
  74. } TAPI_LINEREQUEST_DATA;
  75. typedef struct _CTCALLID_CONTEXT
  76. {
  77. int iCTCallIdentity;
  78. HDRVCALL hdCall;
  79. }CTCALLID_CONTEXT, *PCTCALLID_CONTEXT;
  80. typedef struct _MSPHANDLEENTRY
  81. {
  82. struct _MSPHANDLEENTRY* next;
  83. HTAPIMSPLINE htMSPLine;
  84. HDRVMSPLINE hdMSPLine;
  85. } MSPHANDLEENTRY;
  86. typedef TSPTable<PCTCALLID_CONTEXT> CTCALLID_TABLE;
  87. class CH323Line
  88. {
  89. CRITICAL_SECTION m_CriticalSection; // synchronization object
  90. H323_LINESTATE m_nState; // state of line object
  91. DWORD m_dwTSPIVersion; // tapi selected version
  92. DWORD m_dwMediaModes; // tapi selected media modes
  93. H323_CALL_TABLE m_H323CallTable; // table of allocated calls
  94. H323_VENDORINFO m_VendorInfo;
  95. DWORD m_dwDeviceID; // tapi line device id
  96. WCHAR m_wszAddr[H323_MAXADDRNAMELEN+1]; // line address
  97. HDRVLINE m_hdLine; // tspi line handle
  98. DWORD m_dwInitState;
  99. HDRVMSPLINE m_hdNextMSPHandle; // bogus msp handle count
  100. H323_CONF_TABLE m_H323ConfTable; // table of allocated calls
  101. CALLFORWARDPARAMS* m_pCallForwardParams;
  102. DWORD m_dwInvokeID;
  103. CTCALLID_TABLE m_CTCallIDTable;
  104. MSPHANDLEENTRY* m_MSPHandleList;
  105. void ShutdownAllCalls(void);
  106. void ShutdownCTCallIDTable();
  107. PH323_CALL CreateNewTransferedCall( IN PH323_ALIASNAMES pwszCalleeAddr );
  108. public:
  109. //public data members
  110. BOOLEAN m_fForwardConsultInProgress;
  111. DWORD m_dwNumRingsNoAnswer;
  112. HTAPILINE m_htLine; // tapi line handle
  113. //public functions
  114. CH323Line();
  115. BOOL Initialize( DWORD dwLineDeviceIDBase );
  116. ~CH323Line();
  117. void Shutdown(void);
  118. void RemoveFromCTCallIdentityTable( HDRVCALL hdCall );
  119. HDRVCALL GetCallFromCTCallIdentity( int iCTCallID );
  120. int GetCTCallIdentity( IN HDRVCALL hdCall );
  121. void SetCallForwardParams( IN CALLFORWARDPARAMS* pCallForwardParams );
  122. BOOL SetCallForwardParams( IN LPFORWARDADDRESS pForwardAddress );
  123. PH323_CALL FindH323CallAndLock( IN HDRVCALL hdCall );
  124. PH323_CALL FindCallByARQSeqNumAndLock( WORD seqNumber );
  125. PH323_CALL FindCallByDRQSeqNumAndLock( WORD seqNumber );
  126. PH323_CALL FindCallByCallRefAndLock( WORD wCallRef );
  127. PH323_CALL Find2H323CallsAndLock( IN HDRVCALL hdCall1,
  128. IN HDRVCALL hdCall2, OUT PH323_CALL * ppCall2 );
  129. BOOL AddMSPInstance( HTAPIMSPLINE htMSPLine, HDRVMSPLINE hdMSPLine );
  130. BOOL IsValidMSPHandle( HDRVMSPLINE hdMSPLine, HTAPIMSPLINE* phtMSPLine );
  131. BOOL DeleteMSPInstance( HTAPIMSPLINE* phtMSPLine,
  132. HDRVMSPLINE hdMSPLine );
  133. LONG Close();
  134. LONG CopyLineInfo(DWORD dwDeviceID, LPLINEADDRESSCAPS pAddressCaps );
  135. void H323ReleaseCall( HDRVCALL hdCall, IN DWORD dwDisconnectMode,
  136. IN WORD wCallReference );
  137. BOOL CallReferenceDuped(WORD wCallReference);
  138. //supplementary services functionality
  139. LONG CopyAddressForwardInfo( IN LPLINEADDRESSSTATUS lpAddressStatus );
  140. PH323_ALIASITEM CallToBeDiverted( IN WCHAR* pwszCallerName,
  141. IN DWORD dwCallerNameSize, IN DWORD dwForwardMode );
  142. void PlaceDivertedCall( IN HDRVCALL hdCall,
  143. IN PH323_ALIASNAMES pDivertedToAlias );
  144. void PlaceTransferedCall(IN HDRVCALL hdCall,
  145. IN PH323_ALIASNAMES pTransferedToAlias);
  146. void SwapReplacementCall(
  147. HDRVCALL hdReplacementCall,
  148. HDRVCALL hdPrimaryCall,
  149. BOOL fChangeCallState );
  150. H323_CONF_TABLE* GetH323ConfTable()
  151. {
  152. return &m_H323ConfTable;
  153. }
  154. HDRVMSPLINE GetNextMSPHandle()
  155. {
  156. return ++m_hdNextMSPHandle;
  157. }
  158. HDRVLINE GetHDLine()
  159. {
  160. return m_hdLine;
  161. }
  162. DWORD GetDeviceID()
  163. {
  164. return m_dwDeviceID;
  165. }
  166. PH323_CALL
  167. GetCallAtIndex( int iIndex )
  168. {
  169. return m_H323CallTable[iIndex];
  170. }
  171. CALLFORWARDPARAMS* GetCallForwardParams()
  172. {
  173. return m_pCallForwardParams;
  174. }
  175. BOOL ForwardEnabledForAllOrigins(void)
  176. {
  177. return
  178. (
  179. m_pCallForwardParams &&
  180. (m_pCallForwardParams ->fForwardForAllOrigins == TRUE) &&
  181. (m_pCallForwardParams ->fForwardingEnabled = TRUE)
  182. );
  183. }
  184. H323_VENDORINFO *GetVendorInfo()
  185. {
  186. return &m_VendorInfo;
  187. }
  188. WCHAR * GetMachineName()
  189. {
  190. return m_wszAddr;
  191. }
  192. //!!must be always called in a lock
  193. WORD GetNextInvokeID()
  194. {
  195. return (WORD)InterlockedIncrement( (LONG*)&m_dwInvokeID );
  196. }
  197. BOOL IsValidAddressID( DWORD dwID )
  198. {
  199. return (dwID == 0);
  200. }
  201. void Lock()
  202. {
  203. H323DBG(( DEBUG_LEVEL_VERBOSE, "H323 line waiting on lock." ));
  204. EnterCriticalSection( &m_CriticalSection );
  205. H323DBG(( DEBUG_LEVEL_VERBOSE, "H323 line locked." ));
  206. }
  207. void Unlock()
  208. {
  209. LeaveCriticalSection( &m_CriticalSection );
  210. H323DBG(( DEBUG_LEVEL_VERBOSE, "H323 line unlocked." ));
  211. }
  212. int GetNoOfCalls()
  213. {
  214. DWORD dwNumCalls;
  215. LockCallTable();
  216. dwNumCalls = m_H323CallTable.GetSize();
  217. UnlockCallTable();
  218. return dwNumCalls;
  219. }
  220. //!!must be always called after locking the call table.
  221. int GetCallTableSize()
  222. {
  223. return m_H323CallTable.GetAllocSize();
  224. }
  225. //!This function should not be called while holding a lock on a call object
  226. //!When called from shutdown the calltable object is locked before the call object, so its OK.
  227. void RemoveCallFromTable(
  228. HDRVCALL hdCall
  229. )
  230. {
  231. m_H323CallTable.RemoveAt( LOWORD(hdCall) );
  232. }
  233. //!This function should not be called while holding a lock on a call object
  234. int AddCallToTable(
  235. PH323_CALL pCall
  236. )
  237. {
  238. return m_H323CallTable.Add( pCall );
  239. }
  240. void DisableCallForwarding()
  241. {
  242. H323DBG(( DEBUG_LEVEL_TRACE, "DisableCallForwarding -Entered" ));
  243. if( m_pCallForwardParams != NULL )
  244. {
  245. FreeCallForwardParams( m_pCallForwardParams );
  246. m_pCallForwardParams = NULL;
  247. }
  248. H323DBG(( DEBUG_LEVEL_TRACE, "DisableCallForwarding -Exited" ));
  249. }
  250. //!This function should not be called while holding a lock on a call object
  251. void LockCallTable()
  252. {
  253. H323DBG(( DEBUG_LEVEL_TRACE, "Waiting on call table lock - %p.",
  254. m_H323CallTable ));
  255. m_H323CallTable.Lock();
  256. H323DBG(( DEBUG_LEVEL_TRACE, "Call table locked - %p.",
  257. m_H323CallTable ));
  258. }
  259. void UnlockCallTable()
  260. {
  261. m_H323CallTable.Unlock();
  262. H323DBG(( DEBUG_LEVEL_TRACE, "Call table lock released - %p.",
  263. m_H323CallTable ));
  264. }
  265. H323_LINESTATE GetState()
  266. {
  267. return m_nState;
  268. }
  269. void SetState( H323_LINESTATE nState )
  270. {
  271. m_nState = nState;
  272. }
  273. DWORD GetMediaModes()
  274. {
  275. return m_dwMediaModes;
  276. }
  277. void SetMediaModes(
  278. DWORD dwMediaModes
  279. )
  280. {
  281. m_dwMediaModes = dwMediaModes;
  282. }
  283. BOOL IsMediaDetectionEnabled()
  284. {
  285. return (m_dwMediaModes != 0) &&
  286. (m_dwMediaModes != LINEMEDIAMODE_UNKNOWN);
  287. }
  288. LONG Open (
  289. IN DWORD DeviceID,
  290. IN HTAPILINE TapiLine,
  291. IN DWORD TspiVersion,
  292. OUT HDRVLINE * ReturnDriverLine);
  293. };
  294. //
  295. // Address capabilities
  296. //
  297. #define H323_NUMRINGS_LO 4
  298. #define H323_NUMRINGS_NOANSWER 8
  299. #define H323_NUMRINGS_HI 12
  300. #define H323_ADDR_ADDRESSSHARING LINEADDRESSSHARING_PRIVATE
  301. #define H323_ADDR_ADDRFEATURES (LINEADDRFEATURE_MAKECALL | LINEADDRFEATURE_FORWARD)
  302. #define H323_ADDR_CALLFEATURES (LINECALLFEATURE_ACCEPT | \
  303. LINECALLFEATURE_ANSWER | \
  304. LINECALLFEATURE_DROP | \
  305. LINECALLFEATURE_RELEASEUSERUSERINFO | \
  306. LINECALLFEATURE_SENDUSERUSER | \
  307. LINECALLFEATURE_MONITORDIGITS | \
  308. LINECALLFEATURE_GENERATEDIGITS)
  309. #define H323_ADDR_CALLINFOSTATES LINECALLINFOSTATE_MEDIAMODE
  310. #define H323_ADDR_CALLPARTYIDFLAGS LINECALLPARTYID_NAME
  311. #define H323_ADDR_CALLSTATES (H323_CALL_INBOUNDSTATES | \
  312. H323_CALL_OUTBOUNDSTATES)
  313. #define H323_ADDR_CAPFLAGS (LINEADDRCAPFLAGS_DIALED | \
  314. LINEADDRCAPFLAGS_ORIGOFFHOOK)
  315. /*LINEADDRCAPFLAGS_FWDCONSULT )*/
  316. #define H323_ADDR_DISCONNECTMODES (LINEDISCONNECTMODE_BADADDRESS | \
  317. LINEDISCONNECTMODE_BUSY | \
  318. LINEDISCONNECTMODE_NOANSWER | \
  319. LINEDISCONNECTMODE_NORMAL | \
  320. LINEDISCONNECTMODE_REJECT | \
  321. LINEDISCONNECTMODE_UNAVAIL)
  322. extern CH323Line g_H323Line;
  323. #define g_pH323Line (&g_H323Line)
  324. BOOL
  325. QueueTAPILineRequest(
  326. IN DWORD EventID,
  327. IN HDRVCALL hdCall1,
  328. IN HDRVCALL hdCall2,
  329. IN DWORD dwDisconnectMode,
  330. IN WORD wCallReference);
  331. static DWORD
  332. ProcessTAPILineRequestFre(
  333. IN PVOID ContextParam
  334. );
  335. #endif // _LINE_H_