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.

341 lines
12 KiB

  1. /* comstd.hh -- Private header file for stdcom communications driver module
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 6 $
  7. * $Date: 1/18/02 4:59p $
  8. */
  9. // -=-=-=-=-=-=-=-=-=-=-=-=-=- DEBUG CONTROL -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  10. // These constants are used to turn on various types of debug display
  11. //#define DEBUG_THREAD // Thread startup and shutdown
  12. //#define DEBUG_READ // Read operations, main & thread
  13. //#define DEBUG_WRITE // Write operations, main & thread
  14. //#define DEBUG_EVENTS // Com Events handled in thread
  15. //#define DEBUG_AD // Auto Detect
  16. #if defined(DEBUG_THREAD)
  17. #define DEBUGSTR
  18. #define DBG_THREAD(s,a1,a2,a3,a4,a5) DbgOutStr(s,a1,a2,a3,a4,a5)
  19. #else
  20. #define DBG_THREAD(s,a1,a2,a3,a4,a5)
  21. #endif
  22. #if defined(DEBUG_READ)
  23. #define DEBUGSTR
  24. #define DBG_READ(s,a1,a2,a3,a4,a5) DbgOutStr(s,a1,a2,a3,a4,a5)
  25. #else
  26. #define DBG_READ(s,a1,a2,a3,a4,a5)
  27. #endif
  28. #if defined(DEBUG_WRITE)
  29. #define DEBUGSTR
  30. #define DBG_WRITE(s,a1,a2,a3,a4,a5) DbgOutStr(s,a1,a2,a3,a4,a5)
  31. #else
  32. #define DBG_WRITE(s,a1,a2,a3,a4,a5)
  33. #endif
  34. #if defined(DEBUG_EVENTS)
  35. #define DEBUGSTR
  36. #define DBG_EVENTS(s,a1,a2,a3,a4,a5) DbgOutStr(s,a1,a2,a3,a4,a5)
  37. #else
  38. #define DBG_EVENTS(s,a1,a2,a3,a4,a5)
  39. #endif
  40. #if defined(DEBUG_AD)
  41. #define DEBUGSTR
  42. #define DBG_AD(s,a1,a2,a3,a4,a5) DbgOutStr(s,a1,a2,a3,a4,a5)
  43. #else
  44. #define DBG_AD(s,a1,a2,a3,a4,a5)
  45. #endif
  46. // -=-=-=-=-=-=-=-=-=-=-=-=-=- DEFINITIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  47. #define SIZE_INQ 1152
  48. #define SIZE_OUTQ 2048
  49. #define MAX_READSIZE 80L
  50. // Set these values to make auto detection work
  51. #define MIN_AD_TOTAL 15
  52. #define MIN_AD_MIX 6
  53. // Values for nBestGuess
  54. #define AD_DONT_KNOW 0
  55. #define AD_8N1 1
  56. #define AD_7O1 2
  57. #define AD_7E1 3
  58. // Flag values in afHandshake
  59. #define HANDSHAKE_RCV_X 0x0001
  60. #define HANDSHAKE_RCV_DTR 0x0002
  61. #define HANDSHAKE_RCV_RTS 0x0004
  62. #define HANDSHAKE_SND_X 0x0008
  63. #define HANDSHAKE_SND_CTS 0x0010
  64. #define HANDSHAKE_SND_DSR 0x0020
  65. #define HANDSHAKE_SND_DCD 0x0040
  66. #define MDMSTAT_CTS 0x10
  67. #define MDMSTAT_DSR 0x20
  68. #define MDMSTAT_DCD 0x80
  69. #define STDCOM struct s_stdcom *
  70. // System value item IDs
  71. #define SFID_COMSTD_BAUD 0x1011
  72. #define SFID_COMSTD_DATABITS 0x1012
  73. #define SFID_COMSTD_STOPBITS 0x1013
  74. #define SFID_COMSTD_PARITY 0x1014
  75. #define SFID_COMSTD_HANDSHAKING 0x1015
  76. #define SFID_COMSTD_XON 0x1016
  77. #define SFID_COMSTD_XOFF 0x1017
  78. #define SFID_COMSTD_BREAK 0x1018
  79. #define SFID_COMSTD_AUTODETECT 0x1019
  80. // Identifiers for events in ahEvents
  81. #define EVENT_COMEVENT 0
  82. #define EVENT_READ 1
  83. #define EVENT_WRITE 2
  84. #define EVENT_COUNT 3
  85. #if defined(INCL_WINSOCK)
  86. // Size of receive circular buffer
  87. #define WSOCK_SIZE_INQ 1500
  88. // Size of send circular bufffer. Don't make too big or status displays
  89. // during file transfers will act oddly.
  90. #define WSOCK_SIZE_OUTQ 3000
  91. #define WSOCK_MAX_READSIZE 1500L
  92. #define IP_ADDR_LEN 128
  93. // Note: This was once "HA/WinSock" however this would cause HyperTerminal
  94. // to crash if HAWin16 was running and using WinSock. Since this was an
  95. // obvious cut-and-paste job, I have changed this to be unique for
  96. // HyperTerminal. - cab:12/06/96
  97. //
  98. #define WINSOCK_EVENT_WINDOW_CLASS "HyperTrm/WinSock"
  99. #define WM_WINSOCK_NOTIFY (WM_USER+133)
  100. #define WM_WINSOCK_RESOLVE (WM_USER+134)
  101. #define WM_WINSOCK_STARTUP (WM_USER+135)
  102. #define MODE_MAX 5
  103. #endif // defined(INCL_WINSOCK)
  104. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= TYPES =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  105. typedef struct s_stdcom_settings
  106. {
  107. long lBaud;
  108. int nDataBits;
  109. int nStopBits;
  110. int nParity;
  111. unsigned afHandshake;
  112. TCHAR chXON;
  113. TCHAR chXOFF;
  114. int nBreakDuration;
  115. int fAutoDetect;
  116. } ST_STDCOM_SETTINGS;
  117. #if defined(INCL_WINSOCK)
  118. struct stOptionStateData
  119. {
  120. int option;
  121. int us;
  122. int usq;
  123. int him;
  124. int himq;
  125. };
  126. typedef struct stOptionStateData STOPT;
  127. typedef STOPT FAR * PSTOPT;
  128. #endif // defined(INCL_WINSOCK)
  129. typedef struct s_stdcom
  130. {
  131. // Configuration details
  132. ST_STDCOM_SETTINGS stFileSettings;
  133. ST_STDCOM_SETTINGS stWorkSettings;
  134. // These are control variables private to the stdcom driver
  135. HCOM hCom; // access to com routines
  136. HANDLE hWinComm; // handle to windows comm device
  137. HTIMER hTmrBreak; // Timer to control break duration
  138. int fBreakSignalOn; // TRUE while sending break signal
  139. int fNotifyRcv; // TRUE if driver should send notification
  140. DWORD dwEventMask; // Mask used in Set/GetCommEventmask
  141. int fSending; // TRUE if we've sent a buffer of data
  142. long lSndTimer; // started when we issue a WriteComm
  143. long lSndLimit; // amt. of time to wait for send
  144. long lSndStuck; // amt. of time we've been waiting for
  145. // handshaking
  146. HWND hwndEvents; // window to process event messages
  147. // generate messages for us
  148. BYTE bLastMdmStat;
  149. OVERLAPPED stWriteOv;
  150. // Control fields for receiving
  151. int nRBufrSize; // Size of receive buffer
  152. BYTE *pbBufrStart; // Address of receive buffer
  153. BYTE *pbBufrEnd;
  154. BYTE *pbReadEnd; // Where read thread left off
  155. BYTE *pbComStart; // Marks area being unloaded by main Com
  156. BYTE *pbComEnd;
  157. int fBufrFull; // True when driver buffers are full
  158. int fBufrEmpty; // True when driver buffers are empty
  159. // Control fields for sending
  160. DWORD dwBytesToSend; // Number of bytes pending for write
  161. DWORD dwSndOffset; // Offset into send buffer for write
  162. BYTE *pbSndBufr; // Buffer used by pending write calls
  163. // Error counts
  164. int nParityErrors;
  165. int nFramingErrors;
  166. int nOverrunErrors;
  167. int nOverflowErrors;
  168. // Auto detection fields
  169. int fADRunning;
  170. int nADTotal;
  171. int nADMix;
  172. int nAD7o1;
  173. int nADHighBits;
  174. int nADBestGuess;
  175. char chADLastChar;
  176. int fADToggleParity;
  177. int fADReconfigure;
  178. HANDLE hComstdThread; // Thread to handle ongoing activity
  179. int fHaltThread; // To control when thread shuts down
  180. // Data access control
  181. CRITICAL_SECTION csect; // To synchronize access to driver vars.
  182. HANDLE ahEvent[EVENT_COUNT]; // To control scheduling
  183. #if defined(INCL_WINSOCK)
  184. // Configuration details
  185. // These are control variables private to the tcpip comm driver
  186. SOCKET hSocket; // connected socket
  187. int fConnected; // COM_PORT_UNINITIALIZED initially,
  188. // COM_PORT_NOT_OPEN if init'd,
  189. // COM_PORT_OPEN connected
  190. TCHAR szRemoteAddr[IP_ADDR_LEN];// IP address
  191. short nPort; // Port number
  192. unsigned long ulCompatibility; // to pass flags into dialogs
  193. ULONG ulAddr;
  194. // These are control variables private to the stdcom driver
  195. int fSndBreak; // emulate a break sequence
  196. // Control fields for receiving
  197. BYTE *pbSendBufr; // Pointer to data passed to SndBufrSend
  198. int nSendBufrLen; // Amount of data to send
  199. BYTE abSndBufr[WSOCK_SIZE_OUTQ*2]; // Buffer to send when Winsock is ready
  200. BYTE *pbSndPtrEnd; // Current offset in auchSndBufr
  201. HANDLE hComReadThread; // Thread to handle reading from network
  202. HANDLE hComWriteThread; // Thread to handle writing to network
  203. HANDLE hComConnectThread; // Thread to handle connecting to host
  204. int fClearSendBufr; // flag to signal send buffer to be cleared
  205. int fEscapeFF; // We are escaping FF characters (by doubling)
  206. int fSeenFF; // We have just encountered and FF character
  207. union { // JYF: 29-Sep-2000, fix alignment fault
  208. HOSTENT stHostBuf; // used by WSAGetHostByName
  209. BYTE pcharHostBuf[MAXGETHOSTSTRUCT]; // for allocating MAXGETHOSTSTRUCT bytes
  210. };
  211. struct sockaddr_in stHost;
  212. // Pointers to socket library functions (porting note: these are just pasted in from winsock.h
  213. // with the function pointer declaration fixed up)
  214. int (PASCAL * FAR accept)( int, struct sockaddr *, int * );
  215. int (PASCAL * FAR bind)( int, struct sockaddr *, int );
  216. int (PASCAL * FAR connect)( int, struct sockaddr *, int );
  217. int (PASCAL * FAR gethostid)(void);
  218. int (PASCAL * FAR listen)( int, int);
  219. int (PASCAL * FAR recv)( int, char *, int, int );
  220. int (PASCAL * FAR send)( int, char *, int, int );
  221. int (PASCAL * FAR sock_init)( void );
  222. int (PASCAL * FAR sock_errno)( void );
  223. int (PASCAL * FAR socket)( int, int, int );
  224. int (PASCAL * FAR soclose)( int );
  225. int (PASCAL * FAR shutdown)(int, int);
  226. int (PASCAL * FAR setsockopt)( int, int, int, char *, int );
  227. // from netdb.h
  228. struct hostent * (PASCAL * FAR gethostbyname)( char * );
  229. // from netinet/in.h
  230. unsigned long (PASCAL * FAR inet_addr)(char *);
  231. // from utils.h
  232. unsigned short (PASCAL * FAR bswap)(unsigned short);
  233. // Telnet emulation data
  234. int NVTstate; // Current state of Network Virtual Terminal
  235. STOPT stMode[MODE_MAX];
  236. #ifdef INCL_CALL_ANSWERING
  237. // Answer mode variables - cab:11/19/96
  238. //
  239. int fAnswer; // Are we waiting for a call?
  240. #endif
  241. #endif // defined(INCL_WINSOCK)
  242. } ST_STDCOM;
  243. // -=-=-=-=-=-=-=-=-=-=-=- Globals -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  244. extern HINSTANCE hinstDLL;
  245. // -=-=-=-=-=-=-=-=-=-=-=- EXPORTED PROTOTYPES -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  246. int WINAPI DeviceInitialize(HCOM hCom, unsigned usInterfaceVersion,
  247. void **ppvDriverData);
  248. int WINAPI DeviceClose(ST_STDCOM *pstPrivate);
  249. int WINAPI DeviceDialog(ST_STDCOM *pstPrivate, HWND hwndParent);
  250. int WINAPI DeviceGetCommon(ST_STDCOM *pstPrivate, ST_COMMON *pstCommon);
  251. int WINAPI DeviceSetCommon(ST_STDCOM *pstPrivate, ST_COMMON *pstCommon);
  252. int WINAPI DeviceSpecial(ST_STDCOM *pstPrivate,
  253. const TCHAR *pszInstructions,
  254. TCHAR *pszResult,
  255. int nBufrSize);
  256. int WINAPI DeviceLoadHdl(ST_STDCOM *pstPrivate, SF_HANDLE sfHdl);
  257. int WINAPI DeviceSaveHdl(ST_STDCOM *pstPrivate, SF_HANDLE sfHdl);
  258. int WINAPI PortConfigure(ST_STDCOM *pstPrivate);
  259. int WINAPI PortActivate(ST_STDCOM *pstPrivate,
  260. TCHAR *pszPortName,
  261. DWORD_PTR dwMediaHdl);
  262. int WINAPI PortDeactivate(ST_STDCOM *pstPrivate);
  263. int WINAPI PortConnected(ST_STDCOM *pstPrivate);
  264. int PortExtractSettings(ST_STDCOM *pstPrivate);
  265. int PortDefaultSettings(ST_STDCOM *pstPrivate);
  266. int WINAPI RcvRefill(ST_STDCOM *pstPrivate);
  267. int WINAPI RcvClear(ST_STDCOM *pstPrivate);
  268. int WINAPI SndBufrSend(ST_STDCOM *pstPrivate, void *pvBufr,
  269. int nSize);
  270. int WINAPI SndBufrIsBusy(ST_STDCOM *pstPrivate);
  271. int WINAPI SndBufrQuery(ST_STDCOM *pstPrivate, unsigned *pafStatus,
  272. long *plHandshakeDelay);
  273. int WINAPI SndBufrClear(ST_STDCOM *pstPrivate);
  274. DWORD WINAPI ComstdThread(void *pvData);
  275. void AutoDetectAnalyze(ST_STDCOM *pstPrivate, int nBytes, char *pchBufr);
  276. void AutoDetectOutput(ST_STDCOM *pstPrivate, void *pvBufr, int nSize);
  277. void AutoDetectStart(ST_STDCOM *pstPrivate);
  278. void AutoDetectStop(ST_STDCOM *pstPrivate);
  279. void ComstdSettingsToDCB(ST_STDCOM_SETTINGS *pstSettings, DCB *pstDcb);
  280. void ComstdDCBToSettings(DCB *pstDcb, ST_STDCOM_SETTINGS *pstSettings);
  281. // Temporary til TAPI lets us change media handle settings correctly
  282. int ComstdGetAutoDetectResults(void *pvData, BYTE *bByteSize,
  283. BYTE *bParity, BYTE *bStopBits);