mirror of https://github.com/FreeRDP/FreeRDP
[winpr,comm] build generic serial-port support
* Disable linux specific code if build on *BSD * Build stub to just return NULL for unsupported platforms
This commit is contained in:
parent
e37dffaca4
commit
9c6126c470
|
@ -28,8 +28,6 @@
|
|||
#include <winpr/winpr.h>
|
||||
#include <winpr/wtypes.h>
|
||||
|
||||
#if defined __linux__ && !defined ANDROID
|
||||
|
||||
#define NOPARITY 0
|
||||
#define ODDPARITY 1
|
||||
#define EVENPARITY 2
|
||||
|
@ -463,63 +461,6 @@ extern "C"
|
|||
const char* 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
|
||||
*/
|
||||
|
@ -561,6 +502,4 @@ extern "C"
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
#endif /* WINPR_COMM_H */
|
||||
|
|
|
@ -18,23 +18,31 @@
|
|||
set(MODULE_NAME "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
|
||||
comm.c
|
||||
comm.h
|
||||
comm_io.c
|
||||
comm_ioctl.c
|
||||
comm_ioctl.h
|
||||
comm_serial_sys.c
|
||||
comm_serial_sys.h
|
||||
comm_sercx_sys.c
|
||||
comm_sercx_sys.h
|
||||
comm_sercx2_sys.c
|
||||
comm_sercx2_sys.h)
|
||||
)
|
||||
if(UNIX AND NOT IOS AND NOT EMSCRIPTEN)
|
||||
add_definitions(-DWINPR_HAVE_SERIAL_SUPPORT)
|
||||
list(APPEND ${MODULE_PREFIX}_SRCS
|
||||
comm_io.c
|
||||
comm_ioctl.c
|
||||
comm_ioctl.h
|
||||
comm_serial_sys.c
|
||||
comm_serial_sys.h
|
||||
comm_sercx_sys.c
|
||||
comm_sercx_sys.h
|
||||
comm_sercx2_sys.c
|
||||
comm_sercx2_sys.h
|
||||
)
|
||||
endif()
|
||||
|
||||
winpr_module_add(${${MODULE_PREFIX}_SRCS})
|
||||
|
||||
if(BUILD_TESTING AND BUILD_COMM_TESTS)
|
||||
add_subdirectory(test)
|
||||
if(UNIX AND NOT IOS AND NOT EMSCRIPTEN)
|
||||
if(BUILD_TESTING AND BUILD_COMM_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
|
||||
#include <sys/eventfd.h>
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -83,9 +86,13 @@ static int CommGetFd(HANDLE handle)
|
|||
|
||||
HANDLE_CREATOR* GetCommHandleCreator(void)
|
||||
{
|
||||
#if defined(WINPR_HAVE_SERIAL_SUPPORT)
|
||||
sCommHandleCreator.IsHandled = IsCommDevice;
|
||||
sCommHandleCreator.CreateFileA = CommCreateFileA;
|
||||
return &sCommHandleCreator;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void CommInit(void)
|
||||
|
@ -1261,8 +1268,10 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
|||
goto error_handle;
|
||||
}
|
||||
|
||||
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
|
||||
pComm->fd_read_event = eventfd(
|
||||
0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
|
||||
#endif
|
||||
|
||||
if (pComm->fd_read_event < 0)
|
||||
{
|
||||
|
@ -1281,8 +1290,10 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
|||
goto error_handle;
|
||||
}
|
||||
|
||||
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
|
||||
pComm->fd_write_event = eventfd(
|
||||
0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
|
||||
#endif
|
||||
|
||||
if (pComm->fd_write_event < 0)
|
||||
{
|
||||
|
@ -1296,6 +1307,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
|||
pComm->serverSerialDriverId = SerialDriverUnknown;
|
||||
InitializeCriticalSection(&pComm->EventsLock);
|
||||
|
||||
#if defined(WINPR_HAVE_COMM_COUNTERS)
|
||||
if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 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));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The binary/raw mode is required for the redirection but
|
||||
* only flags that are not handle somewhere-else, except
|
||||
|
@ -1402,6 +1415,7 @@ BOOL CommCloseHandle(HANDLE handle)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
|
||||
#ifndef WITH_EVENTFD_READ_WRITE
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -21,16 +21,20 @@
|
|||
#ifndef 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 <sys/eventfd.h>
|
||||
#endif
|
||||
|
||||
#include <winpr/comm.h>
|
||||
|
||||
#include "../handle/handle.h"
|
||||
#include <winpr/config.h>
|
||||
|
||||
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
|
||||
#include <sys/eventfd.h>
|
||||
#endif
|
||||
|
||||
struct winpr_comm
|
||||
{
|
||||
WINPR_HANDLE common;
|
||||
|
@ -65,7 +69,9 @@ struct winpr_comm
|
|||
|
||||
CRITICAL_SECTION
|
||||
EventsLock; /* protects counters, WaitEventMask and PendingEvents */
|
||||
#if defined(WINPR_HAVE_COMM_COUNTERS)
|
||||
struct serial_icounter_struct counters;
|
||||
#endif
|
||||
ULONG WaitEventMask;
|
||||
ULONG PendingEvents;
|
||||
|
||||
|
@ -101,11 +107,11 @@ BOOL CommIsHandleValid(HANDLE handle);
|
|||
BOOL CommCloseHandle(HANDLE handle);
|
||||
HANDLE_CREATOR* GetCommHandleCreator(void);
|
||||
|
||||
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
|
||||
#ifndef WITH_EVENTFD_READ_WRITE
|
||||
int eventfd_read(int fd, eventfd_t* value);
|
||||
int eventfd_write(int fd, eventfd_t value);
|
||||
#endif
|
||||
|
||||
#endif /* __linux__ */
|
||||
#endif
|
||||
|
||||
#endif /* WINPR_COMM_PRIVATE_H */
|
||||
|
|
|
@ -225,7 +225,9 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
|||
/* FIXME: had expected eventfd_write() to return EAGAIN when
|
||||
* there is no eventfd_read() but this not the case. */
|
||||
/* discard a possible and no more relevant event */
|
||||
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
|
||||
eventfd_read(pComm->fd_read_event, NULL);
|
||||
#endif
|
||||
biggestFd = pComm->fd_read;
|
||||
|
||||
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 defined(WINPR_HAVE_SYS_EVENTFD_H)
|
||||
eventfd_t 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 */
|
||||
#endif
|
||||
}
|
||||
|
||||
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
|
||||
* there is no eventfd_read() but this not the case. */
|
||||
/* discard a possible and no more relevant event */
|
||||
|
||||
#if defined(WINPR_HAVE_SYS_EVENTFD_H)
|
||||
eventfd_read(pComm->fd_write_event, NULL);
|
||||
#endif
|
||||
|
||||
/* ms */
|
||||
ULONGLONG Tmax = 1ull * nNumberOfBytesToWrite * pComm->timeouts.WriteTotalTimeoutMultiplier +
|
||||
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 defined(WINPR_HAVE_SYS_EVENTFD_H)
|
||||
eventfd_t 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 */
|
||||
#endif
|
||||
}
|
||||
|
||||
/* write_set */
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
|
||||
#include <winpr/config.h>
|
||||
|
||||
#if defined __linux__ && !defined ANDROID
|
||||
|
||||
#include <winpr/assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -50,15 +48,67 @@
|
|||
* found in [MSFT-W2KDDK] Volume 2, Part 2—Serial and Parallel
|
||||
* 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return _SERIAL_IOCTL_NAMES[i].name;
|
||||
}
|
||||
const _SERIAL_IOCTL_NAME* const cur = &S_SERIAL_IOCTL_NAMES[x];
|
||||
if (cur->number == number)
|
||||
return cur->name;
|
||||
}
|
||||
|
||||
return "(unknown ioctl name)";
|
||||
|
@ -69,7 +119,7 @@ static BOOL s_CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID
|
|||
LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
|
||||
{
|
||||
WINPR_COMM* pComm = (WINPR_COMM*)hDevice;
|
||||
SERIAL_DRIVER* pServerSerialDriver = NULL;
|
||||
const SERIAL_DRIVER* pServerSerialDriver = NULL;
|
||||
|
||||
if (!CommIsHandleValid(hDevice))
|
||||
return FALSE;
|
||||
|
@ -727,5 +777,3 @@ int _comm_ioctl_tcsetattr(int fd, int optional_actions, const struct termios* te
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
#ifndef WINPR_COMM_IOCTL_H_
|
||||
#define WINPR_COMM_IOCTL_H_
|
||||
|
||||
#if defined __linux__ && !defined ANDROID
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
#include <winpr/io.h>
|
||||
|
@ -231,6 +229,4 @@ extern "C"
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
#endif /* WINPR_COMM_IOCTL_H_ */
|
||||
|
|
|
@ -160,11 +160,11 @@ static SERIAL_DRIVER SerCx2Sys = {
|
|||
.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 */
|
||||
SERIAL_DRIVER* pSerialSys = SerialSys_s();
|
||||
SERIAL_DRIVER* pSerCxSys = SerCxSys_s();
|
||||
const SERIAL_DRIVER* pSerialSys = SerialSys_s();
|
||||
const SERIAL_DRIVER* pSerCxSys = SerCxSys_s();
|
||||
if (!pSerialSys || !pSerCxSys)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
#ifndef COMM_SERCX2_SYS_H
|
||||
#define COMM_SERCX2_SYS_H
|
||||
|
||||
#if defined __linux__ && !defined ANDROID
|
||||
|
||||
#include "comm_ioctl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -29,12 +27,10 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
SERIAL_DRIVER* SerCx2Sys_s(void);
|
||||
const SERIAL_DRIVER* SerCx2Sys_s(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
#endif /* COMM_SERCX2_SYS_H */
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if defined __linux__ && !defined ANDROID
|
||||
|
||||
#include <winpr/assert.h>
|
||||
#include <termios.h>
|
||||
|
||||
|
@ -212,10 +210,10 @@ static SERIAL_DRIVER SerCxSys = {
|
|||
.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 */
|
||||
SERIAL_DRIVER* pSerialSys = SerialSys_s();
|
||||
const SERIAL_DRIVER* pSerialSys = SerialSys_s();
|
||||
if (!pSerialSys)
|
||||
return NULL;
|
||||
|
||||
|
@ -262,5 +260,3 @@ SERIAL_DRIVER* SerCxSys_s(void)
|
|||
|
||||
return &SerCxSys;
|
||||
}
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
#ifndef COMM_SERCX_SYS_H
|
||||
#define COMM_SERCX_SYS_H
|
||||
|
||||
#if defined __linux__ && !defined ANDROID
|
||||
|
||||
#include "comm_ioctl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -29,12 +27,10 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
SERIAL_DRIVER* SerCxSys_s(void);
|
||||
const SERIAL_DRIVER* SerCxSys_s(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
#endif /* COMM_SERCX_SYS_H */
|
||||
|
|
|
@ -28,9 +28,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "comm_serial_sys.h"
|
||||
#ifdef __UCLIBC__
|
||||
#include "comm.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/wlog.h>
|
||||
|
@ -1085,7 +1083,7 @@ static BOOL set_wait_mask(WINPR_COMM* pComm, const ULONG* pWaitMask)
|
|||
if (*pWaitMask == 0)
|
||||
{
|
||||
/* clearing pending events */
|
||||
|
||||
#if defined(WINPR_HAVE_COMM_COUNTERS)
|
||||
if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
#endif
|
||||
pComm->PendingEvents = 0;
|
||||
}
|
||||
|
||||
|
@ -1177,7 +1175,7 @@ static BOOL purge(WINPR_COMM* pComm, const ULONG* pPurgeMask)
|
|||
if (*pPurgeMask & SERIAL_PURGE_TXABORT)
|
||||
{
|
||||
/* 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 (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 */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (*pPurgeMask & SERIAL_PURGE_RXABORT)
|
||||
{
|
||||
/* 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 (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 */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (*pPurgeMask & SERIAL_PURGE_TXCLEAR)
|
||||
|
@ -1261,9 +1261,9 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
|
|||
{
|
||||
BOOL rc = FALSE;
|
||||
/* 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 };
|
||||
|
||||
#endif
|
||||
WINPR_ASSERT(pComm);
|
||||
WINPR_ASSERT(pCommstatus);
|
||||
|
||||
|
@ -1284,6 +1284,7 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
|
|||
status = 0;
|
||||
}
|
||||
|
||||
#if defined(WINPR_HAVE_COMM_COUNTERS)
|
||||
if (ioctl(pComm->fd, TIOCGICOUNT, ¤tCounters) < 0)
|
||||
{
|
||||
if (!commstatus_error(pComm, "TIOCGICOUNT"))
|
||||
|
@ -1324,6 +1325,7 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
|
|||
pCommstatus->Errors |= SERIAL_ERROR_FRAMING;
|
||||
pComm->PendingEvents |= SERIAL_EV_ERR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* HoldReasons */
|
||||
|
||||
|
@ -1341,11 +1343,13 @@ static BOOL get_commstatus(WINPR_COMM* pComm, SERIAL_STATUS* pCommstatus)
|
|||
|
||||
/* AmountInInQueue */
|
||||
|
||||
#if defined(__linux__)
|
||||
if (ioctl(pComm->fd, TIOCINQ, &(pCommstatus->AmountInInQueue)) < 0)
|
||||
{
|
||||
if (!commstatus_error(pComm, "TIOCINQ"))
|
||||
goto fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 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 */
|
||||
|
||||
/* other events based on counters */
|
||||
|
||||
#if defined(WINPR_HAVE_COMM_COUNTERS)
|
||||
if (currentCounters.rx != pComm->counters.rx)
|
||||
{
|
||||
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->counters = currentCounters;
|
||||
#endif
|
||||
|
||||
if (pCommstatus->AmountInInQueue > (0.8 * N_TTY_BUF_SIZE))
|
||||
{
|
||||
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->counters = currentCounters;
|
||||
|
||||
rc = TRUE;
|
||||
fail:
|
||||
LeaveCriticalSection(&pComm->EventsLock);
|
||||
|
@ -1639,7 +1644,7 @@ static BOOL reset_device(WINPR_COMM* pComm)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static SERIAL_DRIVER SerialSys = {
|
||||
static const SERIAL_DRIVER SerialSys = {
|
||||
.id = SerialDriverSerialSys,
|
||||
.name = _T("Serial.sys"),
|
||||
.set_baud_rate = set_baud_rate,
|
||||
|
@ -1674,7 +1679,7 @@ static SERIAL_DRIVER SerialSys = {
|
|||
.reset_device = reset_device,
|
||||
};
|
||||
|
||||
SERIAL_DRIVER* SerialSys_s(void)
|
||||
const SERIAL_DRIVER* SerialSys_s(void)
|
||||
{
|
||||
return &SerialSys;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
#ifndef COMM_SERIAL_SYS_H
|
||||
#define COMM_SERIAL_SYS_H
|
||||
|
||||
#if defined __linux__ && !defined ANDROID
|
||||
|
||||
#include "comm_ioctl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -29,12 +27,10 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
SERIAL_DRIVER* SerialSys_s(void);
|
||||
const SERIAL_DRIVER* SerialSys_s(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
#endif /* COMM_SERIAL_SYS_H */
|
||||
|
|
|
@ -180,9 +180,7 @@ static pthread_once_t HandleCreatorsInitialized = PTHREAD_ONCE_INIT;
|
|||
|
||||
extern HANDLE_CREATOR* GetNamedPipeClientHandleCreator(void);
|
||||
|
||||
#if defined __linux__ && !defined ANDROID
|
||||
#include "../comm/comm.h"
|
||||
#endif /* __linux__ && !defined ANDROID */
|
||||
|
||||
static void HandleCreatorsInit(void)
|
||||
{
|
||||
|
@ -196,9 +194,9 @@ static void HandleCreatorsInit(void)
|
|||
* Register all file handle creators.
|
||||
*/
|
||||
ArrayList_Append(HandleCreators, GetNamedPipeClientHandleCreator());
|
||||
#if defined __linux__ && !defined ANDROID
|
||||
ArrayList_Append(HandleCreators, GetCommHandleCreator());
|
||||
#endif /* __linux__ && !defined ANDROID */
|
||||
HANDLE_CREATOR* serial = GetCommHandleCreator();
|
||||
if (serial)
|
||||
ArrayList_Append(HandleCreators, serial);
|
||||
ArrayList_Append(HandleCreators, GetFileHandleCreator());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue