diff --git a/winpr/libwinpr/comm/CMakeLists.txt b/winpr/libwinpr/comm/CMakeLists.txt index f3385430a..5e0008e7e 100644 --- a/winpr/libwinpr/comm/CMakeLists.txt +++ b/winpr/libwinpr/comm/CMakeLists.txt @@ -36,6 +36,11 @@ if (NOT WIN32) comm_sercx2_sys.c comm_sercx2_sys.h ) + else() + list(APPEND ${MODULE_PREFIX}_SRCS + comm_ioctl_dummy.c + comm_ioctl.h + ) endif() winpr_module_add(${${MODULE_PREFIX}_SRCS}) diff --git a/winpr/libwinpr/comm/comm.c b/winpr/libwinpr/comm/comm.c index d7ce4e976..27d9babfa 100644 --- a/winpr/libwinpr/comm/comm.c +++ b/winpr/libwinpr/comm/comm.c @@ -72,6 +72,72 @@ static CRITICAL_SECTION sCommDevicesLock = { 0 }; static pthread_once_t sCommInitialized = PTHREAD_ONCE_INIT; +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 (size_t x = 0; x < ARRAYSIZE(S_SERIAL_IOCTL_NAMES); x++) + { + const _SERIAL_IOCTL_NAME* cur = &S_SERIAL_IOCTL_NAMES[x]; + if (cur->number == number) + return cur->name; + } + + return "(unknown ioctl name)"; +} + static int CommGetFd(HANDLE handle) { WINPR_COMM* comm = (WINPR_COMM*)handle; diff --git a/winpr/libwinpr/comm/comm_ioctl.c b/winpr/libwinpr/comm/comm_ioctl.c index 360d85b4b..5155be6cc 100644 --- a/winpr/libwinpr/comm/comm_ioctl.c +++ b/winpr/libwinpr/comm/comm_ioctl.c @@ -48,72 +48,6 @@ * 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 (size_t x = 0; x < ARRAYSIZE(S_SERIAL_IOCTL_NAMES); x++) - { - const _SERIAL_IOCTL_NAME* cur = &S_SERIAL_IOCTL_NAMES[x]; - if (cur->number == number) - return cur->name; - } - - return "(unknown ioctl name)"; -} - static BOOL s_CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped) diff --git a/winpr/libwinpr/comm/comm_ioctl_dummy.c b/winpr/libwinpr/comm/comm_ioctl_dummy.c new file mode 100644 index 000000000..3c9910c96 --- /dev/null +++ b/winpr/libwinpr/comm/comm_ioctl_dummy.c @@ -0,0 +1,87 @@ +/** + * WinPR: Windows Portable Runtime + * Serial Communication API - Dummy implementation + * + * Copyright 2024 Armin Novak + * Copyright 2024 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include "comm_ioctl.h" +#include <../log.h> + +#define TAG WINPR_TAG("comm") + +BOOL CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer, + DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize, + LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped) +{ + WINPR_UNUSED(hDevice); + WINPR_UNUSED(dwIoControlCode); + WINPR_UNUSED(lpInBuffer); + WINPR_UNUSED(nInBufferSize); + WINPR_UNUSED(lpOutBuffer); + WINPR_UNUSED(nOutBufferSize); + WINPR_UNUSED(lpBytesReturned); + WINPR_UNUSED(lpOverlapped); + + WLog_ERR(TAG, "TODO: Function not implemented for this platform"); + return FALSE; +} + +int _comm_ioctl_tcsetattr(int fd, int optional_actions, const struct termios* termios_p) +{ + WINPR_UNUSED(fd); + WINPR_UNUSED(optional_actions); + WINPR_UNUSED(termios_p); + + WLog_ERR(TAG, "TODO: Function not implemented for this platform"); + return -1; +} + +BOOL _comm_set_permissive(HANDLE hDevice, BOOL permissive) +{ + WINPR_UNUSED(hDevice); + WINPR_UNUSED(permissive); + + WLog_ERR(TAG, "TODO: Function not implemented for this platform"); + return FALSE; +} + +BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, + LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped) +{ + WINPR_UNUSED(hDevice); + WINPR_UNUSED(lpBuffer); + WINPR_UNUSED(nNumberOfBytesToRead); + WINPR_UNUSED(lpNumberOfBytesRead); + WINPR_UNUSED(lpOverlapped); + + WLog_ERR(TAG, "TODO: Function not implemented for this platform"); + return FALSE; +} + +BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, + LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped) +{ + WINPR_UNUSED(hDevice); + WINPR_UNUSED(lpBuffer); + WINPR_UNUSED(nNumberOfBytesToWrite); + WINPR_UNUSED(lpNumberOfBytesWritten); + WINPR_UNUSED(lpOverlapped); + + WLog_ERR(TAG, "TODO: Function not implemented for this platform"); + return FALSE; +}