Merge pull request #10548 from akallabeth/serial-port

[BSD] build-serial-port
This commit is contained in:
akallabeth 2024-09-09 09:41:12 +02:00 committed by GitHub
commit 9738fc40f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 159 additions and 145 deletions

View File

@ -830,7 +830,7 @@ static BOOL tls_prepare(rdpTls* tls, BIO* underlying, SSL_METHOD* method, int op
return TRUE; return TRUE;
} }
static void adjustSslOptions(int* options) static void adjustSslOptions(int* options) // NOLINT(readability-non-const-parameter)
{ {
WINPR_ASSERT(options); WINPR_ASSERT(options);
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)

View File

@ -28,8 +28,6 @@
#include <winpr/winpr.h> #include <winpr/winpr.h>
#include <winpr/wtypes.h> #include <winpr/wtypes.h>
#if defined __linux__ && !defined ANDROID
#define NOPARITY 0 #define NOPARITY 0
#define ODDPARITY 1 #define ODDPARITY 1
#define EVENPARITY 2 #define EVENPARITY 2
@ -463,63 +461,6 @@ extern "C"
const char* name; const char* name;
} _SERIAL_IOCTL_NAME; } _SERIAL_IOCTL_NAME;
static const _SERIAL_IOCTL_NAME _SERIAL_IOCTL_NAMES[] = {
{ IOCTL_SERIAL_SET_BAUD_RATE, "IOCTL_SERIAL_SET_BAUD_RATE" },
{ IOCTL_SERIAL_GET_BAUD_RATE, "IOCTL_SERIAL_GET_BAUD_RATE" },
{ IOCTL_SERIAL_SET_LINE_CONTROL, "IOCTL_SERIAL_SET_LINE_CONTROL" },
{ IOCTL_SERIAL_GET_LINE_CONTROL, "IOCTL_SERIAL_GET_LINE_CONTROL" },
{ IOCTL_SERIAL_SET_TIMEOUTS, "IOCTL_SERIAL_SET_TIMEOUTS" },
{ IOCTL_SERIAL_GET_TIMEOUTS, "IOCTL_SERIAL_GET_TIMEOUTS" },
{ IOCTL_SERIAL_GET_CHARS, "IOCTL_SERIAL_GET_CHARS" },
{ IOCTL_SERIAL_SET_CHARS, "IOCTL_SERIAL_SET_CHARS" },
{ IOCTL_SERIAL_SET_DTR, "IOCTL_SERIAL_SET_DTR" },
{ IOCTL_SERIAL_CLR_DTR, "IOCTL_SERIAL_CLR_DTR" },
{ IOCTL_SERIAL_RESET_DEVICE, "IOCTL_SERIAL_RESET_DEVICE" },
{ IOCTL_SERIAL_SET_RTS, "IOCTL_SERIAL_SET_RTS" },
{ IOCTL_SERIAL_CLR_RTS, "IOCTL_SERIAL_CLR_RTS" },
{ IOCTL_SERIAL_SET_XOFF, "IOCTL_SERIAL_SET_XOFF" },
{ IOCTL_SERIAL_SET_XON, "IOCTL_SERIAL_SET_XON" },
{ IOCTL_SERIAL_SET_BREAK_ON, "IOCTL_SERIAL_SET_BREAK_ON" },
{ IOCTL_SERIAL_SET_BREAK_OFF, "IOCTL_SERIAL_SET_BREAK_OFF" },
{ IOCTL_SERIAL_SET_QUEUE_SIZE, "IOCTL_SERIAL_SET_QUEUE_SIZE" },
{ IOCTL_SERIAL_GET_WAIT_MASK, "IOCTL_SERIAL_GET_WAIT_MASK" },
{ IOCTL_SERIAL_SET_WAIT_MASK, "IOCTL_SERIAL_SET_WAIT_MASK" },
{ IOCTL_SERIAL_WAIT_ON_MASK, "IOCTL_SERIAL_WAIT_ON_MASK" },
{ IOCTL_SERIAL_IMMEDIATE_CHAR, "IOCTL_SERIAL_IMMEDIATE_CHAR" },
{ IOCTL_SERIAL_PURGE, "IOCTL_SERIAL_PURGE" },
{ IOCTL_SERIAL_GET_HANDFLOW, "IOCTL_SERIAL_GET_HANDFLOW" },
{ IOCTL_SERIAL_SET_HANDFLOW, "IOCTL_SERIAL_SET_HANDFLOW" },
{ IOCTL_SERIAL_GET_MODEMSTATUS, "IOCTL_SERIAL_GET_MODEMSTATUS" },
{ IOCTL_SERIAL_GET_DTRRTS, "IOCTL_SERIAL_GET_DTRRTS" },
{ IOCTL_SERIAL_GET_COMMSTATUS, "IOCTL_SERIAL_GET_COMMSTATUS" },
{ IOCTL_SERIAL_GET_PROPERTIES, "IOCTL_SERIAL_GET_PROPERTIES" },
// {IOCTL_SERIAL_XOFF_COUNTER, "IOCTL_SERIAL_XOFF_COUNTER"},
// {IOCTL_SERIAL_LSRMST_INSERT, "IOCTL_SERIAL_LSRMST_INSERT"},
{ IOCTL_SERIAL_CONFIG_SIZE, "IOCTL_SERIAL_CONFIG_SIZE" },
// {IOCTL_SERIAL_GET_STATS, "IOCTL_SERIAL_GET_STATS"},
// {IOCTL_SERIAL_CLEAR_STATS, "IOCTL_SERIAL_CLEAR_STATS"},
// {IOCTL_SERIAL_GET_MODEM_CONTROL,"IOCTL_SERIAL_GET_MODEM_CONTROL"},
// {IOCTL_SERIAL_SET_MODEM_CONTROL,"IOCTL_SERIAL_SET_MODEM_CONTROL"},
// {IOCTL_SERIAL_SET_FIFO_CONTROL, "IOCTL_SERIAL_SET_FIFO_CONTROL"},
// {IOCTL_PAR_QUERY_INFORMATION, "IOCTL_PAR_QUERY_INFORMATION"},
// {IOCTL_PAR_SET_INFORMATION, "IOCTL_PAR_SET_INFORMATION"},
// {IOCTL_PAR_QUERY_DEVICE_ID, "IOCTL_PAR_QUERY_DEVICE_ID"},
// {IOCTL_PAR_QUERY_DEVICE_ID_SIZE,"IOCTL_PAR_QUERY_DEVICE_ID_SIZE"},
// {IOCTL_IEEE1284_GET_MODE, "IOCTL_IEEE1284_GET_MODE"},
// {IOCTL_IEEE1284_NEGOTIATE, "IOCTL_IEEE1284_NEGOTIATE"},
// {IOCTL_PAR_SET_WRITE_ADDRESS, "IOCTL_PAR_SET_WRITE_ADDRESS"},
// {IOCTL_PAR_SET_READ_ADDRESS, "IOCTL_PAR_SET_READ_ADDRESS"},
// {IOCTL_PAR_GET_DEVICE_CAPS, "IOCTL_PAR_GET_DEVICE_CAPS"},
// {IOCTL_PAR_GET_DEFAULT_MODES, "IOCTL_PAR_GET_DEFAULT_MODES"},
// {IOCTL_PAR_QUERY_RAW_DEVICE_ID, "IOCTL_PAR_QUERY_RAW_DEVICE_ID"},
// {IOCTL_PAR_IS_PORT_FREE, "IOCTL_PAR_IS_PORT_FREE"},
{ IOCTL_USBPRINT_GET_1284_ID, "IOCTL_USBPRINT_GET_1284_ID" },
{ 0, NULL }
};
/** /**
* FIXME: got a proper function name and place * FIXME: got a proper function name and place
*/ */
@ -561,6 +502,4 @@ extern "C"
} }
#endif #endif
#endif /* __linux__ */
#endif /* WINPR_COMM_H */ #endif /* WINPR_COMM_H */

View File

@ -18,10 +18,14 @@
set(MODULE_NAME "winpr-comm") set(MODULE_NAME "winpr-comm")
set(MODULE_PREFIX "WINPR_COMM") set(MODULE_PREFIX "WINPR_COMM")
if(UNIX AND NOT ANDROID AND NOT APPLE AND NOT EMSCRIPTEN) if (NOT WIN32)
set(${MODULE_PREFIX}_SRCS set(${MODULE_PREFIX}_SRCS
comm.c comm.c
comm.h comm.h
)
if(UNIX AND NOT IOS AND NOT EMSCRIPTEN)
add_definitions(-DWINPR_HAVE_SERIAL_SUPPORT)
list(APPEND ${MODULE_PREFIX}_SRCS
comm_io.c comm_io.c
comm_ioctl.c comm_ioctl.c
comm_ioctl.h comm_ioctl.h
@ -30,11 +34,15 @@ if(UNIX AND NOT ANDROID AND NOT APPLE AND NOT EMSCRIPTEN)
comm_sercx_sys.c comm_sercx_sys.c
comm_sercx_sys.h comm_sercx_sys.h
comm_sercx2_sys.c comm_sercx2_sys.c
comm_sercx2_sys.h) comm_sercx2_sys.h
)
endif()
winpr_module_add(${${MODULE_PREFIX}_SRCS}) winpr_module_add(${${MODULE_PREFIX}_SRCS})
if(UNIX AND NOT IOS AND NOT EMSCRIPTEN)
if(BUILD_TESTING AND BUILD_COMM_TESTS) if(BUILD_TESTING AND BUILD_COMM_TESTS)
add_subdirectory(test) add_subdirectory(test)
endif() endif()
endif()
endif() endif()

View File

@ -27,6 +27,9 @@
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
#include <stdarg.h> #include <stdarg.h>
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
#include <sys/eventfd.h>
#endif
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@ -83,9 +86,13 @@ static int CommGetFd(HANDLE handle)
HANDLE_CREATOR* GetCommHandleCreator(void) HANDLE_CREATOR* GetCommHandleCreator(void)
{ {
#if defined(WINPR_HAVE_SERIAL_SUPPORT)
sCommHandleCreator.IsHandled = IsCommDevice; sCommHandleCreator.IsHandled = IsCommDevice;
sCommHandleCreator.CreateFileA = CommCreateFileA; sCommHandleCreator.CreateFileA = CommCreateFileA;
return &sCommHandleCreator; return &sCommHandleCreator;
#else
return NULL;
#endif
} }
static void CommInit(void) static void CommInit(void)
@ -1261,8 +1268,10 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
goto error_handle; goto error_handle;
} }
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
pComm->fd_read_event = eventfd( pComm->fd_read_event = eventfd(
0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */ 0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
#endif
if (pComm->fd_read_event < 0) if (pComm->fd_read_event < 0)
{ {
@ -1281,8 +1290,10 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
goto error_handle; goto error_handle;
} }
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
pComm->fd_write_event = eventfd( pComm->fd_write_event = eventfd(
0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */ 0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
#endif
if (pComm->fd_write_event < 0) if (pComm->fd_write_event < 0)
{ {
@ -1296,6 +1307,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
pComm->serverSerialDriverId = SerialDriverUnknown; pComm->serverSerialDriverId = SerialDriverUnknown;
InitializeCriticalSection(&pComm->EventsLock); InitializeCriticalSection(&pComm->EventsLock);
#if defined(WINPR_HAVE_COMM_COUNTERS)
if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0) if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0)
{ {
char ebuffer[256] = { 0 }; char ebuffer[256] = { 0 };
@ -1310,6 +1322,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
*/ */
ZeroMemory(&(pComm->counters), sizeof(struct serial_icounter_struct)); ZeroMemory(&(pComm->counters), sizeof(struct serial_icounter_struct));
} }
#endif
/* The binary/raw mode is required for the redirection but /* The binary/raw mode is required for the redirection but
* only flags that are not handle somewhere-else, except * only flags that are not handle somewhere-else, except
@ -1402,6 +1415,7 @@ BOOL CommCloseHandle(HANDLE handle)
return TRUE; return TRUE;
} }
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
#ifndef WITH_EVENTFD_READ_WRITE #ifndef WITH_EVENTFD_READ_WRITE
int eventfd_read(int fd, eventfd_t* value) int eventfd_read(int fd, eventfd_t* value)
{ {
@ -1413,3 +1427,4 @@ int eventfd_write(int fd, eventfd_t value)
return (write(fd, &value, sizeof(value)) == sizeof(value)) ? 0 : -1; return (write(fd, &value, sizeof(value)) == sizeof(value)) ? 0 : -1;
} }
#endif #endif
#endif

View File

@ -21,16 +21,20 @@
#ifndef WINPR_COMM_PRIVATE_H #ifndef WINPR_COMM_PRIVATE_H
#define WINPR_COMM_PRIVATE_H #define WINPR_COMM_PRIVATE_H
#if defined __linux__ && !defined ANDROID #if defined(__linux__)
#define WINPR_HAVE_COMM_COUNTERS
#include <linux/serial.h> #include <linux/serial.h>
#include <sys/eventfd.h> #endif
#include <winpr/comm.h> #include <winpr/comm.h>
#include "../handle/handle.h" #include "../handle/handle.h"
#include <winpr/config.h> #include <winpr/config.h>
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
#include <sys/eventfd.h>
#endif
struct winpr_comm struct winpr_comm
{ {
WINPR_HANDLE common; WINPR_HANDLE common;
@ -65,7 +69,9 @@ struct winpr_comm
CRITICAL_SECTION CRITICAL_SECTION
EventsLock; /* protects counters, WaitEventMask and PendingEvents */ EventsLock; /* protects counters, WaitEventMask and PendingEvents */
#if defined(WINPR_HAVE_COMM_COUNTERS)
struct serial_icounter_struct counters; struct serial_icounter_struct counters;
#endif
ULONG WaitEventMask; ULONG WaitEventMask;
ULONG PendingEvents; ULONG PendingEvents;
@ -101,11 +107,11 @@ BOOL CommIsHandleValid(HANDLE handle);
BOOL CommCloseHandle(HANDLE handle); BOOL CommCloseHandle(HANDLE handle);
HANDLE_CREATOR* GetCommHandleCreator(void); HANDLE_CREATOR* GetCommHandleCreator(void);
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
#ifndef WITH_EVENTFD_READ_WRITE #ifndef WITH_EVENTFD_READ_WRITE
int eventfd_read(int fd, eventfd_t* value); int eventfd_read(int fd, eventfd_t* value);
int eventfd_write(int fd, eventfd_t value); int eventfd_write(int fd, eventfd_t value);
#endif #endif
#endif
#endif /* __linux__ */
#endif /* WINPR_COMM_PRIVATE_H */ #endif /* WINPR_COMM_PRIVATE_H */

View File

@ -225,7 +225,9 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
/* FIXME: had expected eventfd_write() to return EAGAIN when /* FIXME: had expected eventfd_write() to return EAGAIN when
* there is no eventfd_read() but this not the case. */ * there is no eventfd_read() but this not the case. */
/* discard a possible and no more relevant event */ /* discard a possible and no more relevant event */
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
eventfd_read(pComm->fd_read_event, NULL); eventfd_read(pComm->fd_read_event, NULL);
#endif
biggestFd = pComm->fd_read; biggestFd = pComm->fd_read;
if (pComm->fd_read_event > biggestFd) if (pComm->fd_read_event > biggestFd)
@ -258,6 +260,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
if (FD_ISSET(pComm->fd_read_event, &read_set)) if (FD_ISSET(pComm->fd_read_event, &read_set))
{ {
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
eventfd_t event = 0; eventfd_t event = 0;
if (eventfd_read(pComm->fd_read_event, &event) < 0) if (eventfd_read(pComm->fd_read_event, &event) < 0)
@ -286,6 +289,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
} }
WINPR_ASSERT(event == WINPR_PURGE_RXABORT); /* no other expected event so far */ WINPR_ASSERT(event == WINPR_PURGE_RXABORT); /* no other expected event so far */
#endif
} }
if (FD_ISSET(pComm->fd_read, &read_set)) if (FD_ISSET(pComm->fd_read, &read_set))
@ -394,7 +398,11 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
/* FIXME: had expected eventfd_write() to return EAGAIN when /* FIXME: had expected eventfd_write() to return EAGAIN when
* there is no eventfd_read() but this not the case. */ * there is no eventfd_read() but this not the case. */
/* discard a possible and no more relevant event */ /* discard a possible and no more relevant event */
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
eventfd_read(pComm->fd_write_event, NULL); eventfd_read(pComm->fd_write_event, NULL);
#endif
/* ms */ /* ms */
ULONGLONG Tmax = 1ull * nNumberOfBytesToWrite * pComm->timeouts.WriteTotalTimeoutMultiplier + ULONGLONG Tmax = 1ull * nNumberOfBytesToWrite * pComm->timeouts.WriteTotalTimeoutMultiplier +
1ull * pComm->timeouts.WriteTotalTimeoutConstant; 1ull * pComm->timeouts.WriteTotalTimeoutConstant;
@ -456,6 +464,7 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
if (FD_ISSET(pComm->fd_write_event, &event_set)) if (FD_ISSET(pComm->fd_write_event, &event_set))
{ {
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
eventfd_t event = 0; eventfd_t event = 0;
if (eventfd_read(pComm->fd_write_event, &event) < 0) if (eventfd_read(pComm->fd_write_event, &event) < 0)
@ -484,6 +493,7 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
} }
WINPR_ASSERT(event == WINPR_PURGE_TXABORT); /* no other expected event so far */ WINPR_ASSERT(event == WINPR_PURGE_TXABORT); /* no other expected event so far */
#endif
} }
/* write_set */ /* write_set */

View File

@ -22,8 +22,6 @@
#include <winpr/config.h> #include <winpr/config.h>
#if defined __linux__ && !defined ANDROID
#include <winpr/assert.h> #include <winpr/assert.h>
#include <errno.h> #include <errno.h>
@ -50,15 +48,67 @@
* found in [MSFT-W2KDDK] Volume 2, Part 2Serial and Parallel * found in [MSFT-W2KDDK] Volume 2, Part 2Serial and Parallel
* Drivers, and in [MSDN-PORTS]. * Drivers, and in [MSDN-PORTS].
*/ */
static const _SERIAL_IOCTL_NAME S_SERIAL_IOCTL_NAMES[] = {
{ IOCTL_SERIAL_SET_BAUD_RATE, "IOCTL_SERIAL_SET_BAUD_RATE" },
{ IOCTL_SERIAL_GET_BAUD_RATE, "IOCTL_SERIAL_GET_BAUD_RATE" },
{ IOCTL_SERIAL_SET_LINE_CONTROL, "IOCTL_SERIAL_SET_LINE_CONTROL" },
{ IOCTL_SERIAL_GET_LINE_CONTROL, "IOCTL_SERIAL_GET_LINE_CONTROL" },
{ IOCTL_SERIAL_SET_TIMEOUTS, "IOCTL_SERIAL_SET_TIMEOUTS" },
{ IOCTL_SERIAL_GET_TIMEOUTS, "IOCTL_SERIAL_GET_TIMEOUTS" },
{ IOCTL_SERIAL_GET_CHARS, "IOCTL_SERIAL_GET_CHARS" },
{ IOCTL_SERIAL_SET_CHARS, "IOCTL_SERIAL_SET_CHARS" },
{ IOCTL_SERIAL_SET_DTR, "IOCTL_SERIAL_SET_DTR" },
{ IOCTL_SERIAL_CLR_DTR, "IOCTL_SERIAL_CLR_DTR" },
{ IOCTL_SERIAL_RESET_DEVICE, "IOCTL_SERIAL_RESET_DEVICE" },
{ IOCTL_SERIAL_SET_RTS, "IOCTL_SERIAL_SET_RTS" },
{ IOCTL_SERIAL_CLR_RTS, "IOCTL_SERIAL_CLR_RTS" },
{ IOCTL_SERIAL_SET_XOFF, "IOCTL_SERIAL_SET_XOFF" },
{ IOCTL_SERIAL_SET_XON, "IOCTL_SERIAL_SET_XON" },
{ IOCTL_SERIAL_SET_BREAK_ON, "IOCTL_SERIAL_SET_BREAK_ON" },
{ IOCTL_SERIAL_SET_BREAK_OFF, "IOCTL_SERIAL_SET_BREAK_OFF" },
{ IOCTL_SERIAL_SET_QUEUE_SIZE, "IOCTL_SERIAL_SET_QUEUE_SIZE" },
{ IOCTL_SERIAL_GET_WAIT_MASK, "IOCTL_SERIAL_GET_WAIT_MASK" },
{ IOCTL_SERIAL_SET_WAIT_MASK, "IOCTL_SERIAL_SET_WAIT_MASK" },
{ IOCTL_SERIAL_WAIT_ON_MASK, "IOCTL_SERIAL_WAIT_ON_MASK" },
{ IOCTL_SERIAL_IMMEDIATE_CHAR, "IOCTL_SERIAL_IMMEDIATE_CHAR" },
{ IOCTL_SERIAL_PURGE, "IOCTL_SERIAL_PURGE" },
{ IOCTL_SERIAL_GET_HANDFLOW, "IOCTL_SERIAL_GET_HANDFLOW" },
{ IOCTL_SERIAL_SET_HANDFLOW, "IOCTL_SERIAL_SET_HANDFLOW" },
{ IOCTL_SERIAL_GET_MODEMSTATUS, "IOCTL_SERIAL_GET_MODEMSTATUS" },
{ IOCTL_SERIAL_GET_DTRRTS, "IOCTL_SERIAL_GET_DTRRTS" },
{ IOCTL_SERIAL_GET_COMMSTATUS, "IOCTL_SERIAL_GET_COMMSTATUS" },
{ IOCTL_SERIAL_GET_PROPERTIES, "IOCTL_SERIAL_GET_PROPERTIES" },
// {IOCTL_SERIAL_XOFF_COUNTER, "IOCTL_SERIAL_XOFF_COUNTER"},
// {IOCTL_SERIAL_LSRMST_INSERT, "IOCTL_SERIAL_LSRMST_INSERT"},
{ IOCTL_SERIAL_CONFIG_SIZE, "IOCTL_SERIAL_CONFIG_SIZE" },
// {IOCTL_SERIAL_GET_STATS, "IOCTL_SERIAL_GET_STATS"},
// {IOCTL_SERIAL_CLEAR_STATS, "IOCTL_SERIAL_CLEAR_STATS"},
// {IOCTL_SERIAL_GET_MODEM_CONTROL,"IOCTL_SERIAL_GET_MODEM_CONTROL"},
// {IOCTL_SERIAL_SET_MODEM_CONTROL,"IOCTL_SERIAL_SET_MODEM_CONTROL"},
// {IOCTL_SERIAL_SET_FIFO_CONTROL, "IOCTL_SERIAL_SET_FIFO_CONTROL"},
// {IOCTL_PAR_QUERY_INFORMATION, "IOCTL_PAR_QUERY_INFORMATION"},
// {IOCTL_PAR_SET_INFORMATION, "IOCTL_PAR_SET_INFORMATION"},
// {IOCTL_PAR_QUERY_DEVICE_ID, "IOCTL_PAR_QUERY_DEVICE_ID"},
// {IOCTL_PAR_QUERY_DEVICE_ID_SIZE,"IOCTL_PAR_QUERY_DEVICE_ID_SIZE"},
// {IOCTL_IEEE1284_GET_MODE, "IOCTL_IEEE1284_GET_MODE"},
// {IOCTL_IEEE1284_NEGOTIATE, "IOCTL_IEEE1284_NEGOTIATE"},
// {IOCTL_PAR_SET_WRITE_ADDRESS, "IOCTL_PAR_SET_WRITE_ADDRESS"},
// {IOCTL_PAR_SET_READ_ADDRESS, "IOCTL_PAR_SET_READ_ADDRESS"},
// {IOCTL_PAR_GET_DEVICE_CAPS, "IOCTL_PAR_GET_DEVICE_CAPS"},
// {IOCTL_PAR_GET_DEFAULT_MODES, "IOCTL_PAR_GET_DEFAULT_MODES"},
// {IOCTL_PAR_QUERY_RAW_DEVICE_ID, "IOCTL_PAR_QUERY_RAW_DEVICE_ID"},
// {IOCTL_PAR_IS_PORT_FREE, "IOCTL_PAR_IS_PORT_FREE"},
{ IOCTL_USBPRINT_GET_1284_ID, "IOCTL_USBPRINT_GET_1284_ID" }
};
const char* _comm_serial_ioctl_name(ULONG number) const char* _comm_serial_ioctl_name(ULONG number)
{ {
for (int i = 0; _SERIAL_IOCTL_NAMES[i].number != 0; i++) for (size_t x = 0; x < ARRAYSIZE(S_SERIAL_IOCTL_NAMES); x++)
{ {
if (_SERIAL_IOCTL_NAMES[i].number == number) const _SERIAL_IOCTL_NAME* const cur = &S_SERIAL_IOCTL_NAMES[x];
{ if (cur->number == number)
return _SERIAL_IOCTL_NAMES[i].name; return cur->name;
}
} }
return "(unknown ioctl name)"; return "(unknown ioctl name)";
@ -69,7 +119,7 @@ static BOOL s_CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID
LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped) LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
{ {
WINPR_COMM* pComm = (WINPR_COMM*)hDevice; WINPR_COMM* pComm = (WINPR_COMM*)hDevice;
SERIAL_DRIVER* pServerSerialDriver = NULL; const SERIAL_DRIVER* pServerSerialDriver = NULL;
if (!CommIsHandleValid(hDevice)) if (!CommIsHandleValid(hDevice))
return FALSE; return FALSE;
@ -727,5 +777,3 @@ int _comm_ioctl_tcsetattr(int fd, int optional_actions, const struct termios* te
return 0; return 0;
} }
#endif /* __linux__ */

View File

@ -22,8 +22,6 @@
#ifndef WINPR_COMM_IOCTL_H_ #ifndef WINPR_COMM_IOCTL_H_
#define WINPR_COMM_IOCTL_H_ #define WINPR_COMM_IOCTL_H_
#if defined __linux__ && !defined ANDROID
#include <termios.h> #include <termios.h>
#include <winpr/io.h> #include <winpr/io.h>
@ -231,6 +229,4 @@ extern "C"
} }
#endif #endif
#endif /* __linux__ */
#endif /* WINPR_COMM_IOCTL_H_ */ #endif /* WINPR_COMM_IOCTL_H_ */

View File

@ -160,11 +160,11 @@ static SERIAL_DRIVER SerCx2Sys = {
.reset_device = NULL, /* not supported by SerCx2.sys */ .reset_device = NULL, /* not supported by SerCx2.sys */
}; };
SERIAL_DRIVER* SerCx2Sys_s(void) const SERIAL_DRIVER* SerCx2Sys_s(void)
{ {
/* SerCx2Sys completed with inherited functions from SerialSys or SerCxSys */ /* SerCx2Sys completed with inherited functions from SerialSys or SerCxSys */
SERIAL_DRIVER* pSerialSys = SerialSys_s(); const SERIAL_DRIVER* pSerialSys = SerialSys_s();
SERIAL_DRIVER* pSerCxSys = SerCxSys_s(); const SERIAL_DRIVER* pSerCxSys = SerCxSys_s();
if (!pSerialSys || !pSerCxSys) if (!pSerialSys || !pSerCxSys)
return NULL; return NULL;

View File

@ -20,8 +20,6 @@
#ifndef COMM_SERCX2_SYS_H #ifndef COMM_SERCX2_SYS_H
#define COMM_SERCX2_SYS_H #define COMM_SERCX2_SYS_H
#if defined __linux__ && !defined ANDROID
#include "comm_ioctl.h" #include "comm_ioctl.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -29,12 +27,10 @@ extern "C"
{ {
#endif #endif
SERIAL_DRIVER* SerCx2Sys_s(void); const SERIAL_DRIVER* SerCx2Sys_s(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* __linux__ */
#endif /* COMM_SERCX2_SYS_H */ #endif /* COMM_SERCX2_SYS_H */

View File

@ -20,8 +20,6 @@
* limitations under the License. * limitations under the License.
*/ */
#if defined __linux__ && !defined ANDROID
#include <winpr/assert.h> #include <winpr/assert.h>
#include <termios.h> #include <termios.h>
@ -212,10 +210,10 @@ static SERIAL_DRIVER SerCxSys = {
.reset_device = NULL, /* not supported by SerCx.sys */ .reset_device = NULL, /* not supported by SerCx.sys */
}; };
SERIAL_DRIVER* SerCxSys_s(void) const SERIAL_DRIVER* SerCxSys_s(void)
{ {
/* _SerCxSys completed with inherited functions from SerialSys */ /* _SerCxSys completed with inherited functions from SerialSys */
SERIAL_DRIVER* pSerialSys = SerialSys_s(); const SERIAL_DRIVER* pSerialSys = SerialSys_s();
if (!pSerialSys) if (!pSerialSys)
return NULL; return NULL;
@ -262,5 +260,3 @@ SERIAL_DRIVER* SerCxSys_s(void)
return &SerCxSys; return &SerCxSys;
} }
#endif /* __linux__ */

View File

@ -20,8 +20,6 @@
#ifndef COMM_SERCX_SYS_H #ifndef COMM_SERCX_SYS_H
#define COMM_SERCX_SYS_H #define COMM_SERCX_SYS_H
#if defined __linux__ && !defined ANDROID
#include "comm_ioctl.h" #include "comm_ioctl.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -29,12 +27,10 @@ extern "C"
{ {
#endif #endif
SERIAL_DRIVER* SerCxSys_s(void); const SERIAL_DRIVER* SerCxSys_s(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* __linux__ */
#endif /* COMM_SERCX_SYS_H */ #endif /* COMM_SERCX_SYS_H */

View File

@ -28,9 +28,7 @@
#include <unistd.h> #include <unistd.h>
#include "comm_serial_sys.h" #include "comm_serial_sys.h"
#ifdef __UCLIBC__
#include "comm.h" #include "comm.h"
#endif
#include <winpr/crt.h> #include <winpr/crt.h>
#include <winpr/wlog.h> #include <winpr/wlog.h>
@ -1085,7 +1083,7 @@ static BOOL set_wait_mask(WINPR_COMM* pComm, const ULONG* pWaitMask)
if (*pWaitMask == 0) if (*pWaitMask == 0)
{ {
/* clearing pending events */ /* clearing pending events */
#if defined(WINPR_HAVE_COMM_COUNTERS)
if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0) if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0)
{ {
if (!commstatus_error(pComm, "TIOCGICOUNT")) if (!commstatus_error(pComm, "TIOCGICOUNT"))
@ -1095,7 +1093,7 @@ static BOOL set_wait_mask(WINPR_COMM* pComm, const ULONG* pWaitMask)
} }
ZeroMemory(&(pComm->counters), sizeof(struct serial_icounter_struct)); ZeroMemory(&(pComm->counters), sizeof(struct serial_icounter_struct));
} }
#endif
pComm->PendingEvents = 0; pComm->PendingEvents = 0;
} }
@ -1177,7 +1175,7 @@ static BOOL purge(WINPR_COMM* pComm, const ULONG* pPurgeMask)
if (*pPurgeMask & SERIAL_PURGE_TXABORT) if (*pPurgeMask & SERIAL_PURGE_TXABORT)
{ {
/* Purges all write (IRP_MJ_WRITE) requests. */ /* Purges all write (IRP_MJ_WRITE) requests. */
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
if (eventfd_write(pComm->fd_write_event, WINPR_PURGE_TXABORT) < 0) if (eventfd_write(pComm->fd_write_event, WINPR_PURGE_TXABORT) < 0)
{ {
if (errno != EAGAIN) if (errno != EAGAIN)
@ -1189,12 +1187,13 @@ static BOOL purge(WINPR_COMM* pComm, const ULONG* pPurgeMask)
WINPR_ASSERT(errno == EAGAIN); /* no reader <=> no pending IRP_MJ_WRITE */ WINPR_ASSERT(errno == EAGAIN); /* no reader <=> no pending IRP_MJ_WRITE */
} }
#endif
} }
if (*pPurgeMask & SERIAL_PURGE_RXABORT) if (*pPurgeMask & SERIAL_PURGE_RXABORT)
{ {
/* Purges all read (IRP_MJ_READ) requests. */ /* Purges all read (IRP_MJ_READ) requests. */
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
if (eventfd_write(pComm->fd_read_event, WINPR_PURGE_RXABORT) < 0) if (eventfd_write(pComm->fd_read_event, WINPR_PURGE_RXABORT) < 0)
{ {
if (errno != EAGAIN) if (errno != EAGAIN)
@ -1206,6 +1205,7 @@ static BOOL purge(WINPR_COMM* pComm, const ULONG* pPurgeMask)
WINPR_ASSERT(errno == EAGAIN); /* no reader <=> no pending IRP_MJ_READ */ WINPR_ASSERT(errno == EAGAIN); /* no reader <=> no pending IRP_MJ_READ */
} }
#endif
} }
if (*pPurgeMask & SERIAL_PURGE_TXCLEAR) if (*pPurgeMask & SERIAL_PURGE_TXCLEAR)
@ -1261,9 +1261,9 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
{ {
BOOL rc = FALSE; BOOL rc = FALSE;
/* http://msdn.microsoft.com/en-us/library/jj673022%28v=vs.85%29.aspx */ /* http://msdn.microsoft.com/en-us/library/jj673022%28v=vs.85%29.aspx */
#if defined(WINPR_HAVE_COMM_COUNTERS)
struct serial_icounter_struct currentCounters = { 0 }; struct serial_icounter_struct currentCounters = { 0 };
#endif
WINPR_ASSERT(pComm); WINPR_ASSERT(pComm);
WINPR_ASSERT(pCommstatus); WINPR_ASSERT(pCommstatus);
@ -1284,6 +1284,7 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
status = 0; status = 0;
} }
#if defined(WINPR_HAVE_COMM_COUNTERS)
if (ioctl(pComm->fd, TIOCGICOUNT, &currentCounters) < 0) if (ioctl(pComm->fd, TIOCGICOUNT, &currentCounters) < 0)
{ {
if (!commstatus_error(pComm, "TIOCGICOUNT")) if (!commstatus_error(pComm, "TIOCGICOUNT"))
@ -1324,6 +1325,7 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
pCommstatus->Errors |= SERIAL_ERROR_FRAMING; pCommstatus->Errors |= SERIAL_ERROR_FRAMING;
pComm->PendingEvents |= SERIAL_EV_ERR; pComm->PendingEvents |= SERIAL_EV_ERR;
} }
#endif
/* HoldReasons */ /* HoldReasons */
@ -1341,11 +1343,13 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
/* AmountInInQueue */ /* AmountInInQueue */
#if defined(__linux__)
if (ioctl(pComm->fd, TIOCINQ, &(pCommstatus->AmountInInQueue)) < 0) if (ioctl(pComm->fd, TIOCINQ, &(pCommstatus->AmountInInQueue)) < 0)
{ {
if (!commstatus_error(pComm, "TIOCINQ")) if (!commstatus_error(pComm, "TIOCINQ"))
goto fail; goto fail;
} }
#endif
/* AmountInOutQueue */ /* AmountInOutQueue */
@ -1360,7 +1364,7 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
/* BOOLEAN WaitForImmediate; TODO: once IOCTL_SERIAL_IMMEDIATE_CHAR fully supported */ /* BOOLEAN WaitForImmediate; TODO: once IOCTL_SERIAL_IMMEDIATE_CHAR fully supported */
/* other events based on counters */ /* other events based on counters */
#if defined(WINPR_HAVE_COMM_COUNTERS)
if (currentCounters.rx != pComm->counters.rx) if (currentCounters.rx != pComm->counters.rx)
{ {
pComm->PendingEvents |= SERIAL_EV_RXFLAG | SERIAL_EV_RXCHAR; pComm->PendingEvents |= SERIAL_EV_RXFLAG | SERIAL_EV_RXCHAR;
@ -1398,6 +1402,9 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
pComm->PendingEvents |= SERIAL_EV_RING; pComm->PendingEvents |= SERIAL_EV_RING;
} }
pComm->counters = currentCounters;
#endif
if (pCommstatus->AmountInInQueue > (0.8 * N_TTY_BUF_SIZE)) if (pCommstatus->AmountInInQueue > (0.8 * N_TTY_BUF_SIZE))
{ {
pComm->PendingEvents |= SERIAL_EV_RX80FULL; pComm->PendingEvents |= SERIAL_EV_RX80FULL;
@ -1409,8 +1416,6 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
pComm->PendingEvents &= ~SERIAL_EV_RX80FULL; pComm->PendingEvents &= ~SERIAL_EV_RX80FULL;
} }
pComm->counters = currentCounters;
rc = TRUE; rc = TRUE;
fail: fail:
LeaveCriticalSection(&pComm->EventsLock); LeaveCriticalSection(&pComm->EventsLock);
@ -1639,7 +1644,7 @@ static BOOL reset_device(WINPR_COMM* pComm)
return TRUE; return TRUE;
} }
static SERIAL_DRIVER SerialSys = { static const SERIAL_DRIVER SerialSys = {
.id = SerialDriverSerialSys, .id = SerialDriverSerialSys,
.name = _T("Serial.sys"), .name = _T("Serial.sys"),
.set_baud_rate = set_baud_rate, .set_baud_rate = set_baud_rate,
@ -1674,7 +1679,7 @@ static SERIAL_DRIVER SerialSys = {
.reset_device = reset_device, .reset_device = reset_device,
}; };
SERIAL_DRIVER* SerialSys_s(void) const SERIAL_DRIVER* SerialSys_s(void)
{ {
return &SerialSys; return &SerialSys;
} }

View File

@ -20,8 +20,6 @@
#ifndef COMM_SERIAL_SYS_H #ifndef COMM_SERIAL_SYS_H
#define COMM_SERIAL_SYS_H #define COMM_SERIAL_SYS_H
#if defined __linux__ && !defined ANDROID
#include "comm_ioctl.h" #include "comm_ioctl.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -29,12 +27,10 @@ extern "C"
{ {
#endif #endif
SERIAL_DRIVER* SerialSys_s(void); const SERIAL_DRIVER* SerialSys_s(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* __linux__ */
#endif /* COMM_SERIAL_SYS_H */ #endif /* COMM_SERIAL_SYS_H */

View File

@ -180,9 +180,7 @@ static pthread_once_t HandleCreatorsInitialized = PTHREAD_ONCE_INIT;
extern HANDLE_CREATOR* GetNamedPipeClientHandleCreator(void); extern HANDLE_CREATOR* GetNamedPipeClientHandleCreator(void);
#if defined __linux__ && !defined ANDROID
#include "../comm/comm.h" #include "../comm/comm.h"
#endif /* __linux__ && !defined ANDROID */
static void HandleCreatorsInit(void) static void HandleCreatorsInit(void)
{ {
@ -196,9 +194,9 @@ static void HandleCreatorsInit(void)
* Register all file handle creators. * Register all file handle creators.
*/ */
ArrayList_Append(HandleCreators, GetNamedPipeClientHandleCreator()); ArrayList_Append(HandleCreators, GetNamedPipeClientHandleCreator());
#if defined __linux__ && !defined ANDROID HANDLE_CREATOR* serial = GetCommHandleCreator();
ArrayList_Append(HandleCreators, GetCommHandleCreator()); if (serial)
#endif /* __linux__ && !defined ANDROID */ ArrayList_Append(HandleCreators, serial);
ArrayList_Append(HandleCreators, GetFileHandleCreator()); ArrayList_Append(HandleCreators, GetFileHandleCreator());
} }

View File

@ -430,22 +430,24 @@ BOOL ArrayList_RemoveAt(wArrayList* arrayList, size_t index)
SSIZE_T ArrayList_IndexOf(wArrayList* arrayList, const void* obj, SSIZE_T startIndex, SSIZE_T count) SSIZE_T ArrayList_IndexOf(wArrayList* arrayList, const void* obj, SSIZE_T startIndex, SSIZE_T count)
{ {
SSIZE_T sindex = 0;
SSIZE_T cindex = 0;
BOOL found = FALSE; BOOL found = FALSE;
WINPR_ASSERT(arrayList); WINPR_ASSERT(arrayList);
ArrayList_Lock_Conditional(arrayList); ArrayList_Lock_Conditional(arrayList);
sindex = (size_t)startIndex; SSIZE_T sindex = startIndex;
if (startIndex < 0) if (startIndex < 0)
sindex = 0; sindex = 0;
cindex = (size_t)count;
if (count < 0)
cindex = arrayList->size;
SSIZE_T index = sindex; SSIZE_T index = sindex;
SSIZE_T cindex = count;
if (count < 0)
{
if (arrayList->size > SSIZE_MAX)
goto fail;
cindex = (SSIZE_T)arrayList->size;
}
for (; index < sindex + cindex; index++) for (; index < sindex + cindex; index++)
{ {
if (arrayList->object.fnObjectEquals(arrayList->array[index], obj)) if (arrayList->object.fnObjectEquals(arrayList->array[index], obj))
@ -455,6 +457,7 @@ SSIZE_T ArrayList_IndexOf(wArrayList* arrayList, const void* obj, SSIZE_T startI
} }
} }
fail:
if (!found) if (!found)
index = -1; index = -1;
@ -486,7 +489,7 @@ SSIZE_T ArrayList_LastIndexOf(wArrayList* arrayList, const void* obj, SSIZE_T st
WINPR_ASSERT(arrayList); WINPR_ASSERT(arrayList);
ArrayList_Lock_Conditional(arrayList); ArrayList_Lock_Conditional(arrayList);
sindex = (size_t)startIndex; sindex = startIndex;
if (startIndex < 0) if (startIndex < 0)
sindex = 0; sindex = 0;

View File

@ -314,13 +314,15 @@ void* BufferPool_Take(wBufferPool* pool, SSIZE_T size)
if (pool->uSize + 1 > pool->uCapacity) if (pool->uSize + 1 > pool->uCapacity)
{ {
size_t newUCapacity = pool->uCapacity * 2; size_t newUCapacity = pool->uCapacity * 2ULL;
if (newUCapacity > SSIZE_MAX)
goto out_error;
wBufferPoolItem* newUArray = wBufferPoolItem* newUArray =
(wBufferPoolItem*)realloc(pool->uArray, sizeof(wBufferPoolItem) * newUCapacity); (wBufferPoolItem*)realloc(pool->uArray, sizeof(wBufferPoolItem) * newUCapacity);
if (!newUArray) if (!newUArray)
goto out_error; goto out_error;
pool->uCapacity = newUCapacity; pool->uCapacity = (SSIZE_T)newUCapacity;
pool->uArray = newUArray; pool->uArray = newUArray;
} }