Source code of Windows XP (NT5)
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.

184 lines
7.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Header defining Null Modem structures and prototypes
  4. //
  5. // Copyright(c) Microsoft 1999
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef _NULL_MODEM_H_
  9. #define _NULL_MODEM_H_
  10. /****************************************************************************/
  11. /* These are valid return codes from TPhys API functions */
  12. /* */
  13. /* TPHYS_SUCCESS */
  14. /* The function executed properly, without error. */
  15. /* TPHYS_RESULT_INUSE */
  16. /* The TPhysInitialize() function failed because the transport */
  17. /* is already initialized */
  18. /* TPHYS_RESULT_FAIL */
  19. /* A general failure, such as a memory allocation error has */
  20. /* caused the function to fail */
  21. /* TPHYS_RESULT_NOT_INITIALIZED */
  22. /* The user is attempting to use a function even though the */
  23. /* TPhysInitialize() function failed. */
  24. /* TPHYS_RESULT_CONNECT_FAILED */
  25. /* The TPhysConnectRequest() function failed. */
  26. /* TPHYS_CONNECT_RESPONSE_FAILED */
  27. /* The TPhysConnectResponse() function failed. */
  28. /* TPHYS_RESULT_NOT_LISTENING */
  29. /* The transport is not currently in a listening state */
  30. /* TPHYS_RESULT_INVALID_CONNECTION */
  31. /* The disconnect references an invalid connection handle */
  32. /* TPHYS_RESULT_INVALID_ADDRESS */
  33. /* The supplied address is invalid */
  34. /* TPHYS_RESULT_CONNECT_REJECTED */
  35. /* The node controller has successfully rejected ain incoming */
  36. /* connection request. */
  37. /* TPHYS_RESULT_SUCCESS_ALTERNATE */
  38. /* The TPHYSICAL driver has connected, but with an alternate */
  39. /* ADDRESS_TYPE as indicated in the connect_info in the response */
  40. /****************************************************************************/
  41. typedef enum tagTPhysicalError
  42. {
  43. TPHYS_SUCCESS = 0,
  44. TPHYS_RESULT_INUSE = 100,
  45. TPHYS_RESULT_FAIL = 101,
  46. TPHYS_RESULT_NOT_INITIALIZED = 102,
  47. TPHYS_RESULT_CONNECT_FAILED = 103,
  48. TPHYS_CONNECT_RESPONSE_FAILED = 104,
  49. TPHYS_RESULT_NOT_LISTENING = 105,
  50. TPHYS_RESULT_INVALID_CONNECTION = 106,
  51. TPHYS_RESULT_INVALID_ADDRESS = 107,
  52. TPHYS_RESULT_CONNECT_REJECTED = 108,
  53. TPHYS_RESULT_SUCCESS_ALTERNATE = 109,
  54. TPHYS_RESULT_COMM_PORT_BUSY = 110,
  55. TPHYS_RESULT_WAITING_FOR_CONNECTION = 111,
  56. }
  57. TPhysicalError;
  58. /****************************************************************************/
  59. /* Structure TPHYS_CALLBACK_INFO */
  60. /* */
  61. /* This structure is passed back as the second parameter to */
  62. /* TPhysCallback for CONNECT notifications. It contains all the */
  63. /* information necessary for the node controller to establish a logical */
  64. /* connection over the physical connection */
  65. /* */
  66. /* It is the responsibility of the node controller to format and present */
  67. /* this information to the transport driver during the in-band portion of */
  68. /* the physical connection establishment. */
  69. /* */
  70. /****************************************************************************/
  71. #define TPHYS_MAX_ADDRESS_INFO 64
  72. typedef struct tphys_connect_info
  73. {
  74. UINT connectionID;
  75. UINT resultCode;
  76. }
  77. TPHYS_CONNECT_INFO, * PTPHYS_CONNECT_INFO;
  78. typedef UINT PHYSICAL_HANDLE;
  79. typedef void (CALLBACK *TPhysCallback) (WORD, PTPHYS_CONNECT_INFO, UINT);
  80. // OOB compatible
  81. #define WM_TPHYS_CONNECT_CONFIRM (WM_APP + 1)
  82. #define WM_TPHYS_CONNECT_INDICATION (WM_APP + 2)
  83. #define WM_TPHYS_DISCONNECT_CONFIRM (WM_APP + 3)
  84. #define WM_TPHYS_DISCONNECT_INDICATION (WM_APP + 4)
  85. #define WM_TPHYS_STATUS_INDICATION (WM_APP + 5)
  86. ///////////////////////////////////////////////////////////////////////////////
  87. // Structure containing state information for each NULLMODEM line
  88. ///////////////////////////////////////////////////////////////////////////////
  89. typedef enum tagCALL_STATE
  90. {
  91. CALL_STATE_IDLE = 0, // Call is idle
  92. CALL_STATE_MAKE = 1, // Establishing phone connection
  93. CALL_STATE_ANSWER = 2, // Answering a new call
  94. CALL_STATE_DROP = 3, // Dropping the phone connection
  95. CALL_STATE_CONNECTED = 4, // Phone connection established and passed onto TDD.
  96. }
  97. CALL_STATE;
  98. typedef struct tagLINE_INFO
  99. {
  100. HANDLE hevtCall; // handle to the call
  101. HANDLE hCommLink; // handle to COM device - call
  102. BOOL fCaller; // FALSE = incoming call
  103. CALL_STATE eCallState; // one of the following states
  104. PHYSICAL_HANDLE pstnHandle;
  105. TPHYS_CONNECT_INFO connInfo;
  106. }
  107. LINE_INFO;
  108. #define MAX_NULLMODEM_LINES 4
  109. class CNullModem
  110. {
  111. public:
  112. CNullModem(HINSTANCE);
  113. ~CNullModem(void);
  114. TPhysicalError TPhysInitialize(TPhysCallback callback, UINT transport_id);
  115. TPhysicalError TPhysTerminate(void);
  116. TPhysicalError TPhysListen(void);
  117. TPhysicalError TPhysUnlisten(void);
  118. TPhysicalError TPhysConnectRequest(LPSTR pszComPort);
  119. TPhysicalError TPhysDisconnect(void);
  120. DWORD WorkerThreadProc(void);
  121. HWND GetHwnd(void) { return m_hwnd; }
  122. LRESULT TPhysProcessMessage(UINT uMsg, LPARAM lParam);
  123. HANDLE GetCommLink(void) { return m_Line.hCommLink; }
  124. void SetBuffers(void);
  125. void SetTimeouts(void);
  126. private:
  127. void DropCall(void);
  128. BOOL WaitForConnection(void);
  129. void SetConnectedPort(void);
  130. private:
  131. BOOL m_fInitialized;
  132. HINSTANCE m_hDllInst;
  133. TPhysCallback m_pfnCallback;
  134. BOOL m_fListening;
  135. HWND m_hwnd;
  136. UINT m_nTransportID; // ID required by RNC
  137. UINT m_nConnectionID; // next conn ID to allocate
  138. LINE_INFO m_Line;
  139. HANDLE m_hThread;
  140. DWORD m_dwThreadID;
  141. HANDLE m_hevtOverlapped;
  142. DWORD m_dwEventMask;
  143. BOOL m_fCommPortInUse;
  144. OVERLAPPED m_Overlapped;
  145. COMMTIMEOUTS m_DefaultTimeouts;
  146. };
  147. LRESULT CALLBACK TPhysWndProc(HWND, UINT, WPARAM, LPARAM);
  148. TPhysicalError CALLBACK TPhysDriverCallback(USHORT msg, ULONG parm, void *userData);
  149. #define COMM_PORT_TIMEOUT 60000 // 60 seconds
  150. #endif // _NULL_MODEM_H_