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.

209 lines
7.3 KiB

  1. /* com.h -- Exported definitions for main communications routines
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 5 $
  7. * $Date: 3/22/02 3:21p $
  8. */
  9. #if !defined(H_COM)
  10. #define H_COM
  11. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= CONSTANTS =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  12. #define COM_VERSION 20
  13. // Function return codes
  14. #define COM_OK 0
  15. #define COM_INVALID_HANDLE 1
  16. #define COM_NOT_ENOUGH_MEMORY 2
  17. #define COM_PORT_NOT_OPEN 3
  18. #define COM_PORT_OPEN 4
  19. #define COM_PORT_UNINITIALIZED 5
  20. #define COM_PORT_IN_USE 6
  21. #define COM_PORT_INVALID_NAME 7
  22. #define COM_CANCELLED 8
  23. #define COM_SEND_QUEUE_STUCK 12
  24. #define COM_DEVICE_INVALID 13
  25. #define COM_DEVICE_VERSION_ERROR 15
  26. #define COM_DEVICE_ERROR 16
  27. #define COM_DEVICE_LIBERROR 14
  28. #define COM_DEVICE_INVALID_SETTING 17
  29. #define COM_BUSY 18
  30. #define COM_NOT_SUPPORTED 19
  31. #define COM_FAILED 21
  32. #define COM_NOT_FOUND 22
  33. #define COM_CANT_OVERRIDE 25
  34. // bits in fsStatus value
  35. #define COMSB_WAIT_XON 0x01
  36. #define COMSB_WAIT_CTS 0x02
  37. #define COMSB_WAIT_DSR 0x04
  38. #define COMSB_WAIT_DCD 0x08
  39. #define COMSB_WAIT_BUSY 0x40 /* flow controlled off for some other reason */
  40. #define COMSB_RESERVED 0x80 /* reserved for use by textsend */
  41. // Bit definition of common fields
  42. #define COM_BAUD 0x01
  43. #define COM_DATABITS 0x02
  44. #define COM_STOPBITS 0x04
  45. #define COM_PARITY 0x08
  46. #define COM_AUTO 0x10
  47. // Common field constants
  48. #define COM_PARITY_MIN 0
  49. #define COM_PARITY_NONE 0
  50. #define COM_PARITY_ODD 1
  51. #define COM_PARITY_EVEN 2
  52. #define COM_PARITY_MARK 3
  53. #define COM_PARITY_SPACE 4
  54. #define COM_PARITY_MAX 4
  55. #define COM_STOPBITS_1 0
  56. #define COM_STOPBITS_1_5 1
  57. #define COM_STOPBITS_2 2
  58. /* Values for usReason arg. to caller supplied status functions */
  59. #define COMSEND_LOCAL 0 /* so callers can call their own
  60. handler function without confusion */
  61. #define COMSEND_FIRSTCALL 1 /* Handler is being registered */
  62. #define COMSEND_LASTCALL 2 /* Handler is being replaced */
  63. #define COMSEND_DATA_WAITING 3 /* Unbuffered data is pending */
  64. #define COMSEND_NORMAL 4 /* Routine call, all data is buffered */
  65. /* Return values from caller supplied status functions */
  66. #define COMSEND_OK 0
  67. #define COMSEND_GIVEUP 1
  68. #define COMSEND_CLEAR_DATA 2
  69. #define COMSEND_FORCE_CONTINUATION 3
  70. // Options for ComOverride()
  71. #define COM_OVERRIDE_8BIT 0x0001 // forces 8-bit (no parity) mode
  72. #define COM_OVERRIDE_RCVALL 0x0002 // suspends any features that would
  73. // prevent any character from
  74. // being received (XON/XOFF etc.)
  75. #define COM_OVERRIDE_SNDALL 0x0004 // ditto for sending
  76. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= TYPES =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  77. // Enumeration type for ComNotify
  78. enum COM_EVENTS
  79. {
  80. CONNECT,
  81. DATA_RECEIVED,
  82. NODATA,
  83. SEND_STARTED,
  84. SEND_DONE
  85. };
  86. // Type for use with ComSend routines
  87. typedef int (*STATUSFUNCT)(int, unsigned, long);
  88. typedef struct s_com_control
  89. {
  90. // Pointers to allow quick macros to access received chars.
  91. UCHAR FAR *puchRBData; // points to next valid received char.
  92. UCHAR FAR *puchRBDataLimit; // limit of valid received chars.
  93. } ST_COM_CONTROL;
  94. // Structure for transferring common data into & out of driver
  95. typedef struct s_common
  96. {
  97. unsigned afItem;
  98. long lBaud;
  99. int nDataBits;
  100. int nStopBits;
  101. int nParity;
  102. int fAutoDetect;
  103. int nPrivateSize;
  104. } ST_COMMON;
  105. // -=-=-=-=-=-=-=-=-=-=-=-=-=- PROTOTYPES -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  106. extern int ComCreateHandle(const HSESSION hSession, HCOM *phcom);
  107. extern int ComDestroyHandle(HCOM *phCom);
  108. extern int ComInitHdl(const HCOM pstCom);
  109. extern int ComLoadHdl(const HCOM pstCom);
  110. extern int ComSaveHdl(const HCOM pstCom);
  111. extern int ComSetDeviceFromName(const HCOM pstCom,
  112. const TCHAR * const pszDeviceName);
  113. extern int ComSetDeviceFromFile(const HCOM pstCom,
  114. const TCHAR * const pszFileName);
  115. extern int ComGetDeviceName(const HCOM pstCom,
  116. TCHAR * const pszName,
  117. int * const pnLen);
  118. extern HANDLE ComGetRcvEvent(HCOM pstCom);
  119. extern int ComGetSession(const HCOM pstCom, HSESSION * const phSession);
  120. extern void ComNotify(const HCOM pstCom, enum COM_EVENTS event);
  121. extern int ComIsActive(const HCOM pstCom);
  122. extern int ComSetPortName(const HCOM pstCom,
  123. const TCHAR * const pszPortName);
  124. extern int ComGetPortName(const HCOM pstCom, TCHAR * const pszName, int nLen);
  125. extern int ComGetBaud(const HCOM pstCom, long * const plBaud);
  126. extern int ComSetBaud(const HCOM pstCom, const long lBaud);
  127. extern int ComGetDataBits(const HCOM pstCom, int * const pnDataBits);
  128. extern int ComSetDataBits(const HCOM pstCom, const int nDataBits);
  129. extern int ComGetStopBits(const HCOM pstCom, int * const pnStopBits);
  130. extern int ComSetStopBits(const HCOM pstCom, const int nStopBits);
  131. extern int ComGetParity(const HCOM pstCom, int * const pnParity);
  132. extern int ComSetParity(const HCOM pstCom, const int nParity);
  133. extern int ComGetAutoDetect(HCOM pstCom, int *pfAutoDetect);
  134. extern int ComSetAutoDetect(HCOM pstCom, int fAutoDetect);
  135. extern int ComPreconnect(const HCOM pstCom);
  136. extern int ComActivatePort(const HCOM pstCom, DWORD_PTR dwMediaHdl);
  137. extern int ComDeactivatePort(const HCOM pstCom);
  138. extern int ComOverride(const HCOM pstCom,
  139. const unsigned afOptions,
  140. unsigned * const pafOldOptions);
  141. extern int ComQueryOverride(HCOM pstCom, unsigned *pafOptions);
  142. extern int ComConfigurePort(const HCOM pstCom);
  143. extern int ComRcvBufrRefill(const HCOM pstCom, TCHAR * const tc, const int fRemoveChar);
  144. extern int ComRcvBufrClear(const HCOM pstCom);
  145. extern int ComSndBufrSend(
  146. const HCOM pstCom,
  147. void * const pvBufr,
  148. const int nCount,
  149. const int nWait);
  150. extern int ComSndBufrBusy(const HCOM pstCom);
  151. extern int ComSndBufrWait(const HCOM pstCom, const int nWait);
  152. extern int ComSndBufrClear(const HCOM pstCom);
  153. extern int ComSndBufrQuery(const HCOM pstCom, unsigned * const pafStatus,
  154. long * const plHandshakeDelay);
  155. extern int ComDeviceDialog(const HCOM pstCom, const HWND hwndParent);
  156. extern int ComDriverSpecial(const HCOM pstCom, const TCHAR * const pszInstructions,
  157. TCHAR * const pszResults, const int nBufrSize);
  158. extern int ComSendChar(const HCOM pstCom, const TCHAR chCode);
  159. extern int ComSendCharNow(const HCOM pstCom, const TCHAR chCode);
  160. extern int ComSendPush(const HCOM pstCom);
  161. extern int ComSendWait(const HCOM pstCom);
  162. extern int ComSendClear(const HCOM pstCom);
  163. extern int ComSendSetStatusFunction(const HCOM pstCom, STATUSFUNCT pfNewStatusFunct,
  164. STATUSFUNCT *ppfOldStatusFunct);
  165. extern int ComLoadWinsockDriver(HCOM pstCom);
  166. extern int ComLoadStdcomDriver(HCOM pstCom);
  167. extern int ComValidHandle(HCOM pstCom);
  168. // Function replacement macros
  169. #define PCOM ST_COM_CONTROL *
  170. #define mComRcvChar(h,p) ((((PCOM)h)->puchRBData < ((PCOM)h)->puchRBDataLimit) ? \
  171. (*(p) = *((PCOM)h)->puchRBData++, TRUE) : \
  172. ComRcvBufrRefill((h), (p), TRUE))
  173. #define mComRcvBufrPeek(h,p) ((((PCOM)h)->puchRBData < ((PCOM)h)->puchRBDataLimit) ? \
  174. (*(p) = *((PCOM)h)->puchRBData, TRUE) : \
  175. ComRcvBufrRefill((h), (p), FALSE))
  176. #define mComRcvBufrPutback(h,c) ((VOID)(*--((PCOM)h)->puchRBData = (TCHAR)(c)))
  177. #endif // !defined(H_COM)