comm_ioctl.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. * WinPR: Windows Portable Runtime
  3. * Serial Communication API
  4. *
  5. * Copyright 2011 O.S. Systems Software Ltda.
  6. * Copyright 2011 Eduardo Fiss Beloni <beloni@ossystems.com.br>
  7. * Copyright 2014 Hewlett-Packard Development Company, L.P.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21. #ifndef WINPR_COMM_IOCTL_H_
  22. #define WINPR_COMM_IOCTL_H_
  23. #if defined __linux__ && !defined ANDROID
  24. #include <termios.h>
  25. #include <winpr/io.h>
  26. #include <winpr/tchar.h>
  27. #include <winpr/wtypes.h>
  28. #include "comm.h"
  29. /* Serial I/O Request Interface: http://msdn.microsoft.com/en-us/library/dn265347%28v=vs.85%29.aspx
  30. * Ntddser.h http://msdn.microsoft.com/en-us/cc308432.aspx
  31. * Ntddpar.h http://msdn.microsoft.com/en-us/cc308431.aspx
  32. */
  33. #ifdef __cplusplus
  34. extern "C"
  35. {
  36. #endif
  37. /* TODO: defines and types below are very similar to those in comm.h, keep only
  38. * those that differ more than the names */
  39. #define STOP_BIT_1 0
  40. #define STOP_BITS_1_5 1
  41. #define STOP_BITS_2 2
  42. #define NO_PARITY 0
  43. #define ODD_PARITY 1
  44. #define EVEN_PARITY 2
  45. #define MARK_PARITY 3
  46. #define SPACE_PARITY 4
  47. typedef struct _SERIAL_BAUD_RATE
  48. {
  49. ULONG BaudRate;
  50. } SERIAL_BAUD_RATE, *PSERIAL_BAUD_RATE;
  51. typedef struct _SERIAL_CHARS
  52. {
  53. UCHAR EofChar;
  54. UCHAR ErrorChar;
  55. UCHAR BreakChar;
  56. UCHAR EventChar;
  57. UCHAR XonChar;
  58. UCHAR XoffChar;
  59. } SERIAL_CHARS, *PSERIAL_CHARS;
  60. typedef struct _SERIAL_LINE_CONTROL
  61. {
  62. UCHAR StopBits;
  63. UCHAR Parity;
  64. UCHAR WordLength;
  65. } SERIAL_LINE_CONTROL, *PSERIAL_LINE_CONTROL;
  66. typedef struct _SERIAL_HANDFLOW
  67. {
  68. ULONG ControlHandShake;
  69. ULONG FlowReplace;
  70. LONG XonLimit;
  71. LONG XoffLimit;
  72. } SERIAL_HANDFLOW, *PSERIAL_HANDFLOW;
  73. #define SERIAL_DTR_MASK ((ULONG)0x03)
  74. #define SERIAL_DTR_CONTROL ((ULONG)0x01)
  75. #define SERIAL_DTR_HANDSHAKE ((ULONG)0x02)
  76. #define SERIAL_CTS_HANDSHAKE ((ULONG)0x08)
  77. #define SERIAL_DSR_HANDSHAKE ((ULONG)0x10)
  78. #define SERIAL_DCD_HANDSHAKE ((ULONG)0x20)
  79. #define SERIAL_OUT_HANDSHAKEMASK ((ULONG)0x38)
  80. #define SERIAL_DSR_SENSITIVITY ((ULONG)0x40)
  81. #define SERIAL_ERROR_ABORT ((ULONG)0x80000000)
  82. #define SERIAL_CONTROL_INVALID ((ULONG)0x7fffff84)
  83. #define SERIAL_AUTO_TRANSMIT ((ULONG)0x01)
  84. #define SERIAL_AUTO_RECEIVE ((ULONG)0x02)
  85. #define SERIAL_ERROR_CHAR ((ULONG)0x04)
  86. #define SERIAL_NULL_STRIPPING ((ULONG)0x08)
  87. #define SERIAL_BREAK_CHAR ((ULONG)0x10)
  88. #define SERIAL_RTS_MASK ((ULONG)0xc0)
  89. #define SERIAL_RTS_CONTROL ((ULONG)0x40)
  90. #define SERIAL_RTS_HANDSHAKE ((ULONG)0x80)
  91. #define SERIAL_TRANSMIT_TOGGLE ((ULONG)0xc0)
  92. #define SERIAL_XOFF_CONTINUE ((ULONG)0x80000000)
  93. #define SERIAL_FLOW_INVALID ((ULONG)0x7fffff20)
  94. #define SERIAL_SP_SERIALCOMM ((ULONG)0x00000001)
  95. #define SERIAL_SP_UNSPECIFIED ((ULONG)0x00000000)
  96. #define SERIAL_SP_RS232 ((ULONG)0x00000001)
  97. #define SERIAL_SP_PARALLEL ((ULONG)0x00000002)
  98. #define SERIAL_SP_RS422 ((ULONG)0x00000003)
  99. #define SERIAL_SP_RS423 ((ULONG)0x00000004)
  100. #define SERIAL_SP_RS449 ((ULONG)0x00000005)
  101. #define SERIAL_SP_MODEM ((ULONG)0x00000006)
  102. #define SERIAL_SP_FAX ((ULONG)0x00000021)
  103. #define SERIAL_SP_SCANNER ((ULONG)0x00000022)
  104. #define SERIAL_SP_BRIDGE ((ULONG)0x00000100)
  105. #define SERIAL_SP_LAT ((ULONG)0x00000101)
  106. #define SERIAL_SP_TELNET ((ULONG)0x00000102)
  107. #define SERIAL_SP_X25 ((ULONG)0x00000103)
  108. typedef struct _SERIAL_TIMEOUTS
  109. {
  110. ULONG ReadIntervalTimeout;
  111. ULONG ReadTotalTimeoutMultiplier;
  112. ULONG ReadTotalTimeoutConstant;
  113. ULONG WriteTotalTimeoutMultiplier;
  114. ULONG WriteTotalTimeoutConstant;
  115. } SERIAL_TIMEOUTS, *PSERIAL_TIMEOUTS;
  116. #define SERIAL_MSR_DCTS 0x01
  117. #define SERIAL_MSR_DDSR 0x02
  118. #define SERIAL_MSR_TERI 0x04
  119. #define SERIAL_MSR_DDCD 0x08
  120. #define SERIAL_MSR_CTS 0x10
  121. #define SERIAL_MSR_DSR 0x20
  122. #define SERIAL_MSR_RI 0x40
  123. #define SERIAL_MSR_DCD 0x80
  124. typedef struct _SERIAL_QUEUE_SIZE
  125. {
  126. ULONG InSize;
  127. ULONG OutSize;
  128. } SERIAL_QUEUE_SIZE, *PSERIAL_QUEUE_SIZE;
  129. #define SERIAL_PURGE_TXABORT 0x00000001
  130. #define SERIAL_PURGE_RXABORT 0x00000002
  131. #define SERIAL_PURGE_TXCLEAR 0x00000004
  132. #define SERIAL_PURGE_RXCLEAR 0x00000008
  133. typedef struct _SERIAL_STATUS
  134. {
  135. ULONG Errors;
  136. ULONG HoldReasons;
  137. ULONG AmountInInQueue;
  138. ULONG AmountInOutQueue;
  139. BOOLEAN EofReceived;
  140. BOOLEAN WaitForImmediate;
  141. } SERIAL_STATUS, *PSERIAL_STATUS;
  142. #define SERIAL_TX_WAITING_FOR_CTS ((ULONG)0x00000001)
  143. #define SERIAL_TX_WAITING_FOR_DSR ((ULONG)0x00000002)
  144. #define SERIAL_TX_WAITING_FOR_DCD ((ULONG)0x00000004)
  145. #define SERIAL_TX_WAITING_FOR_XON ((ULONG)0x00000008)
  146. #define SERIAL_TX_WAITING_XOFF_SENT ((ULONG)0x00000010)
  147. #define SERIAL_TX_WAITING_ON_BREAK ((ULONG)0x00000020)
  148. #define SERIAL_RX_WAITING_FOR_DSR ((ULONG)0x00000040)
  149. #define SERIAL_ERROR_BREAK ((ULONG)0x00000001)
  150. #define SERIAL_ERROR_FRAMING ((ULONG)0x00000002)
  151. #define SERIAL_ERROR_OVERRUN ((ULONG)0x00000004)
  152. #define SERIAL_ERROR_QUEUEOVERRUN ((ULONG)0x00000008)
  153. #define SERIAL_ERROR_PARITY ((ULONG)0x00000010)
  154. #define SERIAL_DTR_STATE ((ULONG)0x00000001)
  155. #define SERIAL_RTS_STATE ((ULONG)0x00000002)
  156. #define SERIAL_CTS_STATE ((ULONG)0x00000010)
  157. #define SERIAL_DSR_STATE ((ULONG)0x00000020)
  158. #define SERIAL_RI_STATE ((ULONG)0x00000040)
  159. #define SERIAL_DCD_STATE ((ULONG)0x00000080)
  160. /**
  161. * A function might be NULL if not supported by the underlying driver.
  162. *
  163. * FIXME: better have to use input and output buffers for all functions?
  164. */
  165. typedef struct _SERIAL_DRIVER
  166. {
  167. SERIAL_DRIVER_ID id;
  168. TCHAR* name;
  169. BOOL (*set_baud_rate)(WINPR_COMM* pComm, const SERIAL_BAUD_RATE* pBaudRate);
  170. BOOL (*get_baud_rate)(WINPR_COMM* pComm, SERIAL_BAUD_RATE* pBaudRate);
  171. BOOL (*get_properties)(WINPR_COMM* pComm, COMMPROP* pProperties);
  172. BOOL (*set_serial_chars)(WINPR_COMM* pComm, const SERIAL_CHARS* pSerialChars);
  173. BOOL (*get_serial_chars)(WINPR_COMM* pComm, SERIAL_CHARS* pSerialChars);
  174. BOOL (*set_line_control)(WINPR_COMM* pComm, const SERIAL_LINE_CONTROL* pLineControl);
  175. BOOL (*get_line_control)(WINPR_COMM* pComm, SERIAL_LINE_CONTROL* pLineControl);
  176. BOOL (*set_handflow)(WINPR_COMM* pComm, const SERIAL_HANDFLOW* pHandflow);
  177. BOOL (*get_handflow)(WINPR_COMM* pComm, SERIAL_HANDFLOW* pHandflow);
  178. BOOL (*set_timeouts)(WINPR_COMM* pComm, const SERIAL_TIMEOUTS* pTimeouts);
  179. BOOL (*get_timeouts)(WINPR_COMM* pComm, SERIAL_TIMEOUTS* pTimeouts);
  180. BOOL (*set_dtr)(WINPR_COMM* pComm);
  181. BOOL (*clear_dtr)(WINPR_COMM* pComm);
  182. BOOL (*set_rts)(WINPR_COMM* pComm);
  183. BOOL (*clear_rts)(WINPR_COMM* pComm);
  184. BOOL (*get_modemstatus)(WINPR_COMM* pComm, ULONG* pRegister);
  185. BOOL (*set_wait_mask)(WINPR_COMM* pComm, const ULONG* pWaitMask);
  186. BOOL (*get_wait_mask)(WINPR_COMM* pComm, ULONG* pWaitMask);
  187. BOOL (*wait_on_mask)(WINPR_COMM* pComm, ULONG* pOutputMask);
  188. BOOL (*set_queue_size)(WINPR_COMM* pComm, const SERIAL_QUEUE_SIZE* pQueueSize);
  189. BOOL (*purge)(WINPR_COMM* pComm, const ULONG* pPurgeMask);
  190. BOOL (*get_commstatus)(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus);
  191. BOOL (*set_break_on)(WINPR_COMM* pComm);
  192. BOOL (*set_break_off)(WINPR_COMM* pComm);
  193. BOOL (*set_xoff)(WINPR_COMM* pComm);
  194. BOOL (*set_xon)(WINPR_COMM* pComm);
  195. BOOL (*get_dtrrts)(WINPR_COMM* pComm, ULONG* pMask);
  196. BOOL (*config_size)(WINPR_COMM* pComm, ULONG* pSize);
  197. BOOL (*immediate_char)(WINPR_COMM* pComm, const UCHAR* pChar);
  198. BOOL (*reset_device)(WINPR_COMM* pComm);
  199. } SERIAL_DRIVER;
  200. int _comm_ioctl_tcsetattr(int fd, int optional_actions, const struct termios* termios_p);
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif /* __linux__ */
  205. #endif /* WINPR_COMM_IOCTL_H_ */