FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
libwinpr/comm/comm.h
1
21#ifndef WINPR_COMM_PRIVATE_H
22#define WINPR_COMM_PRIVATE_H
23
24#if defined(__linux__)
25#define WINPR_HAVE_COMM_COUNTERS
26#include <linux/serial.h>
27#endif
28
29#include <winpr/comm.h>
30
31#include "../handle/handle.h"
32#include <winpr/config.h>
33
34#if defined(WINPR_HAVE_SYS_EVENTFD_H)
35#include <sys/eventfd.h>
36#endif
37
39{
40 WINPR_HANDLE common;
41
42 int fd;
43
44 int fd_read;
45 int fd_read_event; /* as of today, only used by _purge() */
46 CRITICAL_SECTION ReadLock;
47
48 int fd_write;
49 int fd_write_event; /* as of today, only used by _purge() */
50 CRITICAL_SECTION WriteLock;
51
52 /* permissive mode on errors. If TRUE (default is FALSE)
53 * CommDeviceIoControl always return TRUE.
54 *
55 * Not all features are supported yet and an error is then returned when
56 * an application turns them on (e.g: i/o buffers > 4096). It appeared
57 * though that devices and applications can be still functional on such
58 * errors.
59 *
60 * see also: comm_ioctl.c
61 *
62 * FIXME: getting rid of this flag once all features supported.
63 */
64 BOOL permissive;
65
66 SERIAL_DRIVER_ID serverSerialDriverId;
67
68 COMMTIMEOUTS timeouts;
69
71 EventsLock; /* protects counters, WaitEventMask and PendingEvents */
72#if defined(WINPR_HAVE_COMM_COUNTERS)
73 struct serial_icounter_struct counters;
74#endif
75 ULONG WaitEventMask;
76 ULONG PendingEvents;
77
78 BYTE eventChar;
79 /* NB: CloseHandle() has to free resources */
80 ULONG XOnLimit;
81 ULONG XOffLimit;
82
83#if defined(WINPR_HAVE_COMM_COUNTERS)
84 BOOL TIOCGICOUNTSupported;
85#endif
86};
87
88typedef struct winpr_comm WINPR_COMM;
89
90#define SERIAL_EV_RXCHAR 0x0001
91#define SERIAL_EV_RXFLAG 0x0002
92#define SERIAL_EV_TXEMPTY 0x0004
93#define SERIAL_EV_CTS 0x0008
94#define SERIAL_EV_DSR 0x0010
95#define SERIAL_EV_RLSD 0x0020
96#define SERIAL_EV_BREAK 0x0040
97#define SERIAL_EV_ERR 0x0080
98#define SERIAL_EV_RING 0x0100
99#define SERIAL_EV_PERR 0x0200
100#define SERIAL_EV_RX80FULL 0x0400
101#define SERIAL_EV_EVENT1 0x0800
102#define SERIAL_EV_EVENT2 0x1000
103#define SERIAL_EV_WINPR_WAITING 0x4000 /* bit today unused by other SERIAL_EV_* */
104#define SERIAL_EV_WINPR_STOP 0x8000 /* bit today unused by other SERIAL_EV_* */
105
106#define WINPR_PURGE_TXABORT 0x00000001 /* abort pending transmission */
107#define WINPR_PURGE_RXABORT 0x00000002 /* abort pending reception */
108
109#define CommLog_Print(level, ...) CommLog_PrintEx(level, __FILE__, __LINE__, __func__, __VA_ARGS__)
110void CommLog_PrintEx(DWORD wlog_level, const char* file, size_t line, const char* fkt, ...);
111
112BOOL CommIsHandled(HANDLE handle);
113BOOL CommIsHandleValid(HANDLE handle);
114BOOL CommCloseHandle(HANDLE handle);
115const HANDLE_CREATOR* GetCommHandleCreator(void);
116
117#define CommIoCtl(pComm, ctl, data) \
118 CommIoCtl_int((pComm), (ctl), (data), __FILE__, __func__, __LINE__)
119BOOL CommIoCtl_int(WINPR_COMM* pComm, unsigned long int ctl, void* data, const char* file,
120 const char* fkt, size_t line);
121BOOL CommUpdateIOCount(HANDLE handle, BOOL checkSupportStatus);
122
123const char* CommSerialEvString(ULONG status, char* buffer, size_t size);
124
125#if defined(WINPR_HAVE_SYS_EVENTFD_H)
126#ifndef WITH_EVENTFD_READ_WRITE
127int eventfd_read(int fd, eventfd_t* value);
128int eventfd_write(int fd, eventfd_t value);
129#endif
130#endif
131
132#endif /* WINPR_COMM_PRIVATE_H */