From 0d54307251b8fc70bf6ee14a25264efdbe03e2b6 Mon Sep 17 00:00:00 2001 From: Emmanuel Ledoux Date: Wed, 2 Jul 2014 15:59:16 +0200 Subject: [PATCH] winpr-comm: introduced CommLog_Print(...). Don't use anymore DEBUG_WARN() and DEBUG_MSG() macros --- winpr/libwinpr/comm/comm.c | 359 +++++++++++++++++++------- winpr/libwinpr/comm/comm.h | 3 + winpr/libwinpr/comm/comm_io.c | 23 +- winpr/libwinpr/comm/comm_ioctl.c | 26 +- winpr/libwinpr/comm/comm_sercx2_sys.c | 8 +- winpr/libwinpr/comm/comm_sercx_sys.c | 30 +-- winpr/libwinpr/comm/comm_serial_sys.c | 99 ++++--- 7 files changed, 363 insertions(+), 185 deletions(-) diff --git a/winpr/libwinpr/comm/comm.c b/winpr/libwinpr/comm/comm.c index dea659353..4937a8af1 100644 --- a/winpr/libwinpr/comm/comm.c +++ b/winpr/libwinpr/comm/comm.c @@ -30,17 +30,17 @@ #include #include #include +#include #include #include #include #include #include -#include - #include #include #include +#include #include "comm_ioctl.h" @@ -52,33 +52,150 @@ #include "comm.h" + +static wLog *_Log = NULL; + +struct comm_device +{ + LPTSTR name; + LPTSTR path; +}; + +typedef struct comm_device COMM_DEVICE; + + +/* FIXME: get a clever data structure, see also io.h functions */ +/* _CommDevices is a NULL-terminated array with a maximun of COMM_DEVICE_MAX COMM_DEVICE */ +#define COMM_DEVICE_MAX 128 +static COMM_DEVICE **_CommDevices = NULL; + +static HANDLE_CREATOR *_CommHandleCreator = NULL; +static HANDLE_CLOSE_CB *_CommHandleCloseCb = NULL; + +static pthread_once_t _CommInitialized = PTHREAD_ONCE_INIT; +static void _CommInit() +{ + /* NB: error management to be done outside of this function */ + + assert(_Log == NULL); + assert(_CommDevices == NULL); + assert(_CommHandleCreator == NULL); + assert(_CommHandleCloseCb == NULL); + + _Log = WLog_Get("com.winpr.comm"); + + _CommDevices = (COMM_DEVICE**)calloc(COMM_DEVICE_MAX+1, sizeof(COMM_DEVICE*)); + + _CommHandleCreator = (HANDLE_CREATOR*)malloc(sizeof(HANDLE_CREATOR)); + if (_CommHandleCreator) + { + _CommHandleCreator->IsHandled = IsCommDevice; + _CommHandleCreator->CreateFileA = CommCreateFileA; + + RegisterHandleCreator(_CommHandleCreator); + } + + _CommHandleCloseCb = (HANDLE_CLOSE_CB*)malloc(sizeof(HANDLE_CLOSE_CB)); + if (_CommHandleCloseCb) + { + _CommHandleCloseCb->IsHandled = CommIsHandled; + _CommHandleCloseCb->CloseHandle = CommCloseHandle; + + RegisterHandleCloseCb(_CommHandleCloseCb); + } + + assert(_Log != NULL); + assert(_CommDevices != NULL); + assert(_CommHandleCreator != NULL); + assert(_CommHandleCloseCb != NULL); +} + + +/** + * Returns TRUE when the comm module is correctly intialized, FALSE otherwise + * with ERROR_DLL_INIT_FAILED set as the last error. + */ +static BOOL CommInitialized() +{ + if (pthread_once(&_CommInitialized, _CommInit) != 0) + { + SetLastError(ERROR_DLL_INIT_FAILED); + return FALSE; + } + + return TRUE; +} + + +void CommLog_Print(int level, char *fmt, ...) +{ + if (!CommInitialized()) + return; + + va_list ap; + va_start(ap, fmt); + WLog_PrintVA(_Log, level, fmt, ap); + va_end(ap); +} + + BOOL BuildCommDCBA(LPCSTR lpDef, LPDCB lpDCB) { + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + return TRUE; } BOOL BuildCommDCBW(LPCWSTR lpDef, LPDCB lpDCB) { + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + return TRUE; } BOOL BuildCommDCBAndTimeoutsA(LPCSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts) { + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + return TRUE; } BOOL BuildCommDCBAndTimeoutsW(LPCWSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts) { + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + return TRUE; } BOOL CommConfigDialogA(LPCSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC) { + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + return TRUE; } BOOL CommConfigDialogW(LPCWSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC) { + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + return TRUE; } @@ -86,6 +203,11 @@ BOOL GetCommConfig(HANDLE hCommDev, LPCOMMCONFIG lpCC, LPDWORD lpdwSize) { WINPR_COMM* pComm = (WINPR_COMM*) hCommDev; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -96,6 +218,11 @@ BOOL SetCommConfig(HANDLE hCommDev, LPCOMMCONFIG lpCC, DWORD dwSize) { WINPR_COMM* pComm = (WINPR_COMM*) hCommDev; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -106,6 +233,11 @@ BOOL GetCommMask(HANDLE hFile, PDWORD lpEvtMask) { WINPR_COMM* pComm = (WINPR_COMM*) hFile; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -116,6 +248,11 @@ BOOL SetCommMask(HANDLE hFile, DWORD dwEvtMask) { WINPR_COMM* pComm = (WINPR_COMM*) hFile; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -126,6 +263,11 @@ BOOL GetCommModemStatus(HANDLE hFile, PDWORD lpModemStat) { WINPR_COMM* pComm = (WINPR_COMM*) hFile; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -134,6 +276,7 @@ BOOL GetCommModemStatus(HANDLE hFile, PDWORD lpModemStat) /** * ERRORS: + * ERROR_DLL_INIT_FAILED * ERROR_INVALID_HANDLE */ BOOL GetCommProperties(HANDLE hFile, LPCOMMPROP lpCommProp) @@ -141,6 +284,9 @@ BOOL GetCommProperties(HANDLE hFile, LPCOMMPROP lpCommProp) WINPR_COMM* pComm = (WINPR_COMM*) hFile; DWORD bytesReturned; + if (!CommInitialized()) + return FALSE; + if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd ) { SetLastError(ERROR_INVALID_HANDLE); @@ -149,7 +295,7 @@ BOOL GetCommProperties(HANDLE hFile, LPCOMMPROP lpCommProp) if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_PROPERTIES, NULL, 0, lpCommProp, sizeof(COMMPROP), &bytesReturned, NULL)) { - DEBUG_WARN("GetCommProperties failure."); + CommLog_Print(WLOG_WARN, "GetCommProperties failure."); return FALSE; } @@ -174,6 +320,9 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB) WINPR_COMM* pComm = (WINPR_COMM*) hFile; DWORD bytesReturned; + if (!CommInitialized()) + return FALSE; + if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd ) { SetLastError(ERROR_INVALID_HANDLE); @@ -212,7 +361,7 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB) SERIAL_BAUD_RATE baudRate; if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_BAUD_RATE, NULL, 0, &baudRate, sizeof(SERIAL_BAUD_RATE), &bytesReturned, NULL)) { - DEBUG_WARN("GetCommState failure: could not get the baud rate."); + CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the baud rate."); goto error_handle; } lpLocalDcb->BaudRate = baudRate.BaudRate; @@ -220,7 +369,7 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB) lpLocalDcb->fBinary = (currentState.c_cflag & ICANON) == 0; if (!lpLocalDcb->fBinary) { - DEBUG_WARN("Unexpected nonbinary mode, consider to unset the ICANON flag."); + CommLog_Print(WLOG_WARN, "Unexpected nonbinary mode, consider to unset the ICANON flag."); } lpLocalDcb->fParity = (currentState.c_iflag & INPCK) != 0; @@ -228,7 +377,7 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB) SERIAL_HANDFLOW handflow; if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_HANDFLOW, NULL, 0, &handflow, sizeof(SERIAL_HANDFLOW), &bytesReturned, NULL)) { - DEBUG_WARN("GetCommState failure: could not get the handflow settings."); + CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the handflow settings."); goto error_handle; } @@ -290,7 +439,7 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB) SERIAL_LINE_CONTROL lineControl; if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_LINE_CONTROL, NULL, 0, &lineControl, sizeof(SERIAL_LINE_CONTROL), &bytesReturned, NULL)) { - DEBUG_WARN("GetCommState failure: could not get the control settings."); + CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the control settings."); goto error_handle; } @@ -304,7 +453,7 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB) SERIAL_CHARS serialChars; if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_CHARS, NULL, 0, &serialChars, sizeof(SERIAL_CHARS), &bytesReturned, NULL)) { - DEBUG_WARN("GetCommState failure: could not get the serial chars."); + CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the serial chars."); goto error_handle; } @@ -350,6 +499,9 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) /* FIXME: validate changes according GetCommProperties? */ + if (!CommInitialized()) + return FALSE; + if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd ) { SetLastError(ERROR_INVALID_HANDLE); @@ -371,14 +523,14 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) baudRate.BaudRate = lpDCB->BaudRate; if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_BAUD_RATE, &baudRate, sizeof(SERIAL_BAUD_RATE), NULL, 0, &bytesReturned, NULL)) { - DEBUG_WARN("SetCommState failure: could not set the baud rate."); + CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the baud rate."); return FALSE; } SERIAL_CHARS serialChars; if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_CHARS, NULL, 0, &serialChars, sizeof(SERIAL_CHARS), &bytesReturned, NULL)) /* as of today, required for BreakChar */ { - DEBUG_WARN("SetCommState failure: could not get the initial serial chars."); + CommLog_Print(WLOG_WARN, "SetCommState failure: could not get the initial serial chars."); return FALSE; } serialChars.XonChar = lpDCB->XonChar; @@ -388,7 +540,7 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) serialChars.EventChar = lpDCB->EvtChar; if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_CHARS, &serialChars, sizeof(SERIAL_CHARS), NULL, 0, &bytesReturned, NULL)) { - DEBUG_WARN("SetCommState failure: could not set the serial chars."); + CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the serial chars."); return FALSE; } @@ -398,7 +550,7 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) lineControl.WordLength = lpDCB->ByteSize; if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_LINE_CONTROL, &lineControl, sizeof(SERIAL_LINE_CONTROL), NULL, 0, &bytesReturned, NULL)) { - DEBUG_WARN("SetCommState failure: could not set the control settings."); + CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the control settings."); return FALSE; } @@ -432,7 +584,7 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) break; default: - DEBUG_WARN("Unexpected fDtrControl value: %d\n", lpDCB->fDtrControl); + CommLog_Print(WLOG_WARN, "Unexpected fDtrControl value: %d\n", lpDCB->fDtrControl); return FALSE; } @@ -469,7 +621,7 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) switch (lpDCB->fRtsControl) { case RTS_CONTROL_TOGGLE: - DEBUG_WARN("Unsupported RTS_CONTROL_TOGGLE feature"); + CommLog_Print(WLOG_WARN, "Unsupported RTS_CONTROL_TOGGLE feature"); // FIXME: see also GetCommState() return FALSE; @@ -486,7 +638,7 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) break; default: - DEBUG_WARN("Unexpected fRtsControl value: %d\n", lpDCB->fRtsControl); + CommLog_Print(WLOG_WARN, "Unexpected fRtsControl value: %d\n", lpDCB->fRtsControl); return FALSE; } @@ -505,7 +657,7 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_HANDFLOW, &handflow, sizeof(SERIAL_HANDFLOW), NULL, 0, &bytesReturned, NULL)) { - DEBUG_WARN("SetCommState failure: could not set the handflow settings."); + CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the handflow settings."); return FALSE; } @@ -527,7 +679,7 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) else { upcomingTermios.c_lflag |= ICANON; - DEBUG_WARN("Unexpected nonbinary mode, consider to unset the ICANON flag."); + CommLog_Print(WLOG_WARN, "Unexpected nonbinary mode, consider to unset the ICANON flag."); } if (lpDCB->fParity) @@ -570,6 +722,9 @@ BOOL GetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts) WINPR_COMM* pComm = (WINPR_COMM*) hFile; DWORD bytesReturned; + if (!CommInitialized()) + return FALSE; + if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd ) { SetLastError(ERROR_INVALID_HANDLE); @@ -580,7 +735,7 @@ BOOL GetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts) if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, lpCommTimeouts, sizeof(COMMTIMEOUTS), &bytesReturned, NULL)) { - DEBUG_WARN("GetCommTimeouts failure."); + CommLog_Print(WLOG_WARN, "GetCommTimeouts failure."); return FALSE; } @@ -597,6 +752,9 @@ BOOL SetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts) WINPR_COMM* pComm = (WINPR_COMM*) hFile; DWORD bytesReturned; + if (!CommInitialized()) + return FALSE; + if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd ) { SetLastError(ERROR_INVALID_HANDLE); @@ -607,7 +765,7 @@ BOOL SetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts) if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_TIMEOUTS, lpCommTimeouts, sizeof(COMMTIMEOUTS), NULL, 0, &bytesReturned, NULL)) { - DEBUG_WARN("SetCommTimeouts failure."); + CommLog_Print(WLOG_WARN, "SetCommTimeouts failure."); return FALSE; } @@ -616,21 +774,41 @@ BOOL SetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts) BOOL GetDefaultCommConfigA(LPCSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize) { + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + return TRUE; } BOOL GetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize) { + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + return TRUE; } BOOL SetDefaultCommConfigA(LPCSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize) { + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + return TRUE; } BOOL SetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize) { + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + return TRUE; } @@ -638,6 +816,11 @@ BOOL SetCommBreak(HANDLE hFile) { WINPR_COMM* pComm = (WINPR_COMM*) hFile; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -648,6 +831,11 @@ BOOL ClearCommBreak(HANDLE hFile) { WINPR_COMM* pComm = (WINPR_COMM*) hFile; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -658,6 +846,11 @@ BOOL ClearCommError(HANDLE hFile, PDWORD lpErrors, LPCOMSTAT lpStat) { WINPR_COMM* pComm = (WINPR_COMM*) hFile; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -670,6 +863,9 @@ BOOL PurgeComm(HANDLE hFile, DWORD dwFlags) WINPR_COMM* pComm = (WINPR_COMM*) hFile; DWORD bytesReturned = 0; + if (!CommInitialized()) + return FALSE; + if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd ) { SetLastError(ERROR_INVALID_HANDLE); @@ -678,7 +874,7 @@ BOOL PurgeComm(HANDLE hFile, DWORD dwFlags) if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_PURGE, &dwFlags, sizeof(DWORD), NULL, 0, &bytesReturned, NULL)) { - DEBUG_WARN("PurgeComm failure."); + CommLog_Print(WLOG_WARN, "PurgeComm failure."); return FALSE; } @@ -692,6 +888,9 @@ BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue) SERIAL_QUEUE_SIZE queueSize; DWORD bytesReturned = 0; + if (!CommInitialized()) + return FALSE; + if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd ) { SetLastError(ERROR_INVALID_HANDLE); @@ -703,7 +902,7 @@ BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue) if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_QUEUE_SIZE, &queueSize, sizeof(SERIAL_QUEUE_SIZE), NULL, 0, &bytesReturned, NULL)) { - DEBUG_WARN("SetCommTimeouts failure."); + CommLog_Print(WLOG_WARN, "SetCommTimeouts failure."); return FALSE; } @@ -714,6 +913,11 @@ BOOL EscapeCommFunction(HANDLE hFile, DWORD dwFunc) { WINPR_COMM* pComm = (WINPR_COMM*) hFile; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -724,6 +928,11 @@ BOOL TransmitCommChar(HANDLE hFile, char cChar) { WINPR_COMM* pComm = (WINPR_COMM*) hFile; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -734,6 +943,11 @@ BOOL WaitCommEvent(HANDLE hFile, PDWORD lpEvtMask, LPOVERLAPPED lpOverlapped) { WINPR_COMM* pComm = (WINPR_COMM*) hFile; + if (!CommInitialized()) + return FALSE; + + /* TODO: not implemented */ + if (!pComm) return FALSE; @@ -743,59 +957,13 @@ BOOL WaitCommEvent(HANDLE hFile, PDWORD lpEvtMask, LPOVERLAPPED lpOverlapped) /* Extended API */ -typedef struct _COMM_DEVICE -{ - LPTSTR name; - LPTSTR path; -} COMM_DEVICE; - -/* FIXME: get a clever data structure, see also io.h functions */ -/* _CommDevices is a NULL-terminated array with a maximun of COMM_DEVICE_MAX COMM_DEVICE */ -#define COMM_DEVICE_MAX 128 -static COMM_DEVICE **_CommDevices = NULL; - -static HANDLE_CREATOR *_CommHandleCreator = NULL; -static HANDLE_CLOSE_CB *_CommHandleCloseCb = NULL; - -static pthread_once_t _CommInitialized = PTHREAD_ONCE_INIT; -static void _CommInit() -{ - /* NB: error management to be done outside of this function */ - - assert(_CommDevices == NULL); - assert(_CommHandleCreator == NULL); - assert(_CommHandleCloseCb == NULL); - - _CommDevices = (COMM_DEVICE**)calloc(COMM_DEVICE_MAX+1, sizeof(COMM_DEVICE*)); - - _CommHandleCreator = (HANDLE_CREATOR*)malloc(sizeof(HANDLE_CREATOR)); - if (_CommHandleCreator) - { - _CommHandleCreator->IsHandled = IsCommDevice; - _CommHandleCreator->CreateFileA = CommCreateFileA; - - RegisterHandleCreator(_CommHandleCreator); - } - - _CommHandleCloseCb = (HANDLE_CLOSE_CB*)malloc(sizeof(HANDLE_CLOSE_CB)); - if (_CommHandleCloseCb) - { - _CommHandleCloseCb->IsHandled = CommIsHandled; - _CommHandleCloseCb->CloseHandle = CommCloseHandle; - - RegisterHandleCloseCb(_CommHandleCloseCb); - } - - assert(_CommDevices != NULL); - assert(_CommHandleCreator != NULL); - assert(_CommHandleCloseCb != NULL); -} - - static BOOL _IsReservedCommDeviceName(LPCTSTR lpName) { int i; + if (!CommInitialized()) + return FALSE; + /* Serial ports, COM1-9 */ for (i=1; i<10; i++) { @@ -843,11 +1011,8 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget LPTSTR storedDeviceName = NULL; LPTSTR storedTargetPath = NULL; - if (pthread_once(&_CommInitialized, _CommInit) != 0) - { - SetLastError(ERROR_DLL_INIT_FAILED); + if (!CommInitialized()) goto error_handle; - } if (_CommDevices == NULL) { @@ -952,11 +1117,8 @@ DWORD QueryCommDevice(LPCTSTR lpDeviceName, LPTSTR lpTargetPath, DWORD ucchMax) SetLastError(ERROR_SUCCESS); - if (pthread_once(&_CommInitialized, _CommInit) != 0) - { - SetLastError(ERROR_DLL_INIT_FAILED); + if (!CommInitialized()) return 0; - } if (_CommDevices == NULL) { @@ -1012,6 +1174,9 @@ BOOL IsCommDevice(LPCTSTR lpDeviceName) { TCHAR lpTargetPath[MAX_PATH]; + if (!CommInitialized()) + return FALSE; + if (QueryCommDevice(lpDeviceName, lpTargetPath, MAX_PATH) > 0) { return TRUE; @@ -1030,9 +1195,12 @@ void _comm_setServerSerialDriver(HANDLE hComm, SERIAL_DRIVER_ID driverId) PVOID Object; WINPR_COMM* pComm; + if (!CommInitialized()) + return; + if (!winpr_Handle_GetInfo(hComm, &Type, &Object)) { - DEBUG_WARN("_comm_setServerSerialDriver failure"); + CommLog_Print(WLOG_WARN, "_comm_setServerSerialDriver failure"); return; } @@ -1074,9 +1242,12 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare WINPR_COMM* pComm = NULL; struct termios upcomingTermios; + if (!CommInitialized()) + return INVALID_HANDLE_VALUE; + if (dwDesiredAccess != (GENERIC_READ | GENERIC_WRITE)) { - DEBUG_WARN("unexpected access to the device: 0x%lX", dwDesiredAccess); + CommLog_Print(WLOG_WARN, "unexpected access to the device: 0x%lX", dwDesiredAccess); } if (dwShareMode != 0) @@ -1090,7 +1261,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare if (lpSecurityAttributes != NULL) { - DEBUG_WARN("unexpected security attributes, nLength=%lu", lpSecurityAttributes->nLength); + CommLog_Print(WLOG_WARN, "unexpected security attributes, nLength=%lu", lpSecurityAttributes->nLength); } if (dwCreationDisposition != OPEN_EXISTING) @@ -1107,21 +1278,21 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare if (stat(devicePath, &deviceStat) < 0) { - DEBUG_WARN("device not found %s", devicePath); + CommLog_Print(WLOG_WARN, "device not found %s", devicePath); SetLastError(ERROR_FILE_NOT_FOUND); return INVALID_HANDLE_VALUE; } if (!S_ISCHR(deviceStat.st_mode)) { - DEBUG_WARN("bad device %s", devicePath); + CommLog_Print(WLOG_WARN, "bad device %s", devicePath); SetLastError(ERROR_BAD_DEVICE); return INVALID_HANDLE_VALUE; } if (dwFlagsAndAttributes != 0) { - DEBUG_WARN("unexpected flags and attributes: 0x%lX", dwFlagsAndAttributes); + CommLog_Print(WLOG_WARN, "unexpected flags and attributes: 0x%lX", dwFlagsAndAttributes); } if (hTemplateFile != NULL) @@ -1144,7 +1315,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare pComm->fd = open(devicePath, O_RDWR | O_NOCTTY | O_NONBLOCK); if (pComm->fd < 0) { - DEBUG_WARN("failed to open device %s", devicePath); + CommLog_Print(WLOG_WARN, "failed to open device %s", devicePath); SetLastError(ERROR_BAD_DEVICE); goto error_handle; } @@ -1152,7 +1323,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare pComm->fd_read = open(devicePath, O_RDONLY | O_NOCTTY | O_NONBLOCK); if (pComm->fd_read < 0) { - DEBUG_WARN("failed to open fd_read, device: %s", devicePath); + CommLog_Print(WLOG_WARN, "failed to open fd_read, device: %s", devicePath); SetLastError(ERROR_BAD_DEVICE); goto error_handle; } @@ -1160,7 +1331,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare pComm->fd_read_event = eventfd(0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */ if (pComm->fd_read_event < 0) { - DEBUG_WARN("failed to open fd_read_event, device: %s", devicePath); + CommLog_Print(WLOG_WARN, "failed to open fd_read_event, device: %s", devicePath); SetLastError(ERROR_BAD_DEVICE); goto error_handle; } @@ -1170,7 +1341,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare pComm->fd_write = open(devicePath, O_WRONLY | O_NOCTTY | O_NONBLOCK); if (pComm->fd_write < 0) { - DEBUG_WARN("failed to open fd_write, device: %s", devicePath); + CommLog_Print(WLOG_WARN, "failed to open fd_write, device: %s", devicePath); SetLastError(ERROR_BAD_DEVICE); goto error_handle; } @@ -1178,7 +1349,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare pComm->fd_write_event = eventfd(0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */ if (pComm->fd_write_event < 0) { - DEBUG_WARN("failed to open fd_write_event, device: %s", devicePath); + CommLog_Print(WLOG_WARN, "failed to open fd_write_event, device: %s", devicePath); SetLastError(ERROR_BAD_DEVICE); goto error_handle; } @@ -1192,7 +1363,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0) { - DEBUG_WARN("TIOCGICOUNT ioctl failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); goto error_handle; } @@ -1248,6 +1419,9 @@ BOOL CommIsHandled(HANDLE handle) { WINPR_COMM *pComm; + if (!CommInitialized()) + return FALSE; + pComm = (WINPR_COMM*)handle; if (!pComm || pComm->Type != HANDLE_TYPE_COMM) @@ -1264,6 +1438,9 @@ BOOL CommCloseHandle(HANDLE handle) { WINPR_COMM *pComm; + if (!CommInitialized()) + return FALSE; + pComm = (WINPR_COMM*)handle; if (!pComm || pComm->Type != HANDLE_TYPE_COMM) @@ -1280,7 +1457,7 @@ BOOL CommCloseHandle(HANDLE handle) /* ensures to gracefully stop the WAIT_ON_MASK's loop */ if (!CommDeviceIoControl(handle, IOCTL_SERIAL_SET_WAIT_MASK, &WaitMask, sizeof(ULONG), NULL, 0, &BytesReturned, NULL)) { - DEBUG_WARN("failure to WAIT_ON_MASK's loop!"); + CommLog_Print(WLOG_WARN, "failure to WAIT_ON_MASK's loop!"); } } diff --git a/winpr/libwinpr/comm/comm.h b/winpr/libwinpr/comm/comm.h index 800dcb5c7..92bca98a0 100644 --- a/winpr/libwinpr/comm/comm.h +++ b/winpr/libwinpr/comm/comm.h @@ -86,6 +86,9 @@ typedef struct winpr_comm WINPR_COMM; #define FREERDP_PURGE_TXABORT 0x00000001 /* abort pending transmission */ #define FREERDP_PURGE_RXABORT 0x00000002 /* abort pending reception */ + +void CommLog_Print(int wlog_level, char *fmt, ...); + BOOL CommIsHandled(HANDLE handle); BOOL CommCloseHandle(HANDLE handle); diff --git a/winpr/libwinpr/comm/comm_io.c b/winpr/libwinpr/comm/comm_io.c index 53fe67135..4f63a020d 100644 --- a/winpr/libwinpr/comm/comm_io.c +++ b/winpr/libwinpr/comm/comm_io.c @@ -28,9 +28,8 @@ #include #include -#include - #include +#include #include #include "comm.h" @@ -136,7 +135,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, if (currentTermios.c_lflag & ICANON) { - DEBUG_WARN("Canonical mode not supported"); /* the timeout could not be set */ + CommLog_Print(WLOG_WARN, "Canonical mode not supported"); /* the timeout could not be set */ SetLastError(ERROR_NOT_SUPPORTED); goto return_false; } @@ -162,7 +161,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, if ((pTimeouts->ReadIntervalTimeout == MAXULONG) && (pTimeouts->ReadTotalTimeoutConstant == MAXULONG)) { - DEBUG_WARN("ReadIntervalTimeout and ReadTotalTimeoutConstant cannot be both set to MAXULONG"); + CommLog_Print(WLOG_WARN, "ReadIntervalTimeout and ReadTotalTimeoutConstant cannot be both set to MAXULONG"); SetLastError(ERROR_INVALID_PARAMETER); goto return_false; } @@ -214,7 +213,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, if (tcsetattr(pComm->fd, TCSANOW, ¤tTermios) < 0) { - DEBUG_WARN("CommReadFile failure, could not apply new timeout values: VMIN=%u, VTIME=%u", vmin, vtime); + CommLog_Print(WLOG_WARN, "CommReadFile failure, could not apply new timeout values: VMIN=%u, VTIME=%u", vmin, vtime); SetLastError(ERROR_IO_DEVICE); goto return_false; } @@ -252,7 +251,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, nbFds = select(biggestFd+1, &read_set, NULL, NULL, pTmaxTimeout); if (nbFds < 0) { - DEBUG_WARN("select() failure, errno=[%d] %s\n", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); goto return_false; } @@ -281,7 +280,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, } else { - DEBUG_WARN("unexpected error on reading fd_read_event, errno=[%d] %s\n", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "unexpected error on reading fd_read_event, errno=[%d] %s\n", errno, strerror(errno)); /* FIXME: goto return_false ? */ } @@ -304,10 +303,10 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, nbRead = read(pComm->fd_read, lpBuffer, nNumberOfBytesToRead); if (nbRead < 0) { - DEBUG_WARN("CommReadFile failed, ReadIntervalTimeout=%lu, ReadTotalTimeoutMultiplier=%lu, ReadTotalTimeoutConstant=%lu VMIN=%u, VTIME=%u", + CommLog_Print(WLOG_WARN, "CommReadFile failed, ReadIntervalTimeout=%lu, ReadTotalTimeoutMultiplier=%lu, ReadTotalTimeoutConstant=%lu VMIN=%u, VTIME=%u", pTimeouts->ReadIntervalTimeout, pTimeouts->ReadTotalTimeoutMultiplier, pTimeouts->ReadTotalTimeoutConstant, currentTermios.c_cc[VMIN], currentTermios.c_cc[VTIME]); - DEBUG_WARN("CommReadFile failed, nNumberOfBytesToRead=%lu, errno=[%d] %s", nNumberOfBytesToRead, errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "CommReadFile failed, nNumberOfBytesToRead=%lu, errno=[%d] %s", nNumberOfBytesToRead, errno, strerror(errno)); if (errno == EAGAIN) { @@ -443,7 +442,7 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite nbFds = select(biggestFd+1, &event_set, &write_set, NULL, pTmaxTimeout); if (nbFds < 0) { - DEBUG_WARN("select() failure, errno=[%d] %s\n", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); goto return_false; } @@ -472,7 +471,7 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite } else { - DEBUG_WARN("unexpected error on reading fd_write_event, errno=[%d] %s\n", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "unexpected error on reading fd_write_event, errno=[%d] %s\n", errno, strerror(errno)); /* FIXME: goto return_false ? */ } @@ -501,7 +500,7 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite if (nbWritten < 0) { - DEBUG_WARN("CommWriteFile failed after %lu bytes written, errno=[%d] %s\n", *lpNumberOfBytesWritten, errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "CommWriteFile failed after %lu bytes written, errno=[%d] %s\n", *lpNumberOfBytesWritten, errno, strerror(errno)); if (errno == EAGAIN) { diff --git a/winpr/libwinpr/comm/comm_ioctl.c b/winpr/libwinpr/comm/comm_ioctl.c index 11f608552..551b677ce 100644 --- a/winpr/libwinpr/comm/comm_ioctl.c +++ b/winpr/libwinpr/comm/comm_ioctl.c @@ -30,7 +30,7 @@ #include #include -#include +#include #include "comm.h" #include "comm_ioctl.h" @@ -59,7 +59,7 @@ const char* _comm_serial_ioctl_name(ULONG number) { int i; - + for (i=0; _SERIAL_IOCTL_NAMES[i].number != 0; i++) { if (_SERIAL_IOCTL_NAMES[i].number == number) @@ -107,7 +107,7 @@ static BOOL _CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID l *lpBytesReturned = 0; /* will be ajusted if required ... */ - DEBUG_MSG("CommDeviceIoControl: IoControlCode: 0x%0.8x", dwIoControlCode); + CommLog_Print(WLOG_DEBUG, "CommDeviceIoControl: IoControlCode: 0x%0.8x", dwIoControlCode); /* remoteSerialDriver to be use ... * @@ -129,7 +129,7 @@ static BOOL _CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID l case SerialDriverUnknown: default: - DEBUG_MSG("Unknown remote serial driver (%d), using SerCx2.sys", pComm->serverSerialDriverId); + CommLog_Print(WLOG_DEBUG, "Unknown remote serial driver (%d), using SerCx2.sys", pComm->serverSerialDriverId); pServerSerialDriver = SerCx2Sys_s(); break; } @@ -629,7 +629,7 @@ static BOOL _CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID l } } - DEBUG_WARN(_T("unsupported IoControlCode=[0x%lX] %s (remote serial driver: %s)"), + CommLog_Print(WLOG_WARN, _T("unsupported IoControlCode=[0x%lX] %s (remote serial driver: %s)"), dwIoControlCode, _comm_serial_ioctl_name(dwIoControlCode), pServerSerialDriver->name); SetLastError(ERROR_CALL_NOT_IMPLEMENTED); /* => STATUS_NOT_IMPLEMENTED */ return FALSE; @@ -673,14 +673,14 @@ BOOL CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffe if (lpBytesReturned && *lpBytesReturned != nOutBufferSize) { /* This might be a hint for a bug, especially when result==TRUE */ - DEBUG_WARN("lpBytesReturned=%ld and nOutBufferSize=%ld are different!", *lpBytesReturned, nOutBufferSize); + CommLog_Print(WLOG_WARN, "lpBytesReturned=%ld and nOutBufferSize=%ld are different!", *lpBytesReturned, nOutBufferSize); } if (pComm->permissive) { if (!result) { - DEBUG_WARN("[permissive]: whereas it failed, made to succeed IoControlCode=[0x%lX] %s, last-error: 0x%lX", + CommLog_Print(WLOG_WARN, "[permissive]: whereas it failed, made to succeed IoControlCode=[0x%lX] %s, last-error: 0x%lX", dwIoControlCode, _comm_serial_ioctl_name(dwIoControlCode), GetLastError()); } @@ -697,7 +697,7 @@ int _comm_ioctl_tcsetattr(int fd, int optional_actions, const struct termios *te if ((result = tcsetattr(fd, optional_actions, termios_p)) < 0) { - DEBUG_WARN("tcsetattr failure, errno: %d", errno); + CommLog_Print(WLOG_WARN, "tcsetattr failure, errno: %d", errno); return result; } @@ -705,29 +705,29 @@ int _comm_ioctl_tcsetattr(int fd, int optional_actions, const struct termios *te ZeroMemory(¤tState, sizeof(struct termios)); if ((result = tcgetattr(fd, ¤tState)) < 0) { - DEBUG_WARN("tcgetattr failure, errno: %d", errno); + CommLog_Print(WLOG_WARN, "tcgetattr failure, errno: %d", errno); return result; } if (memcmp(¤tState, &termios_p, sizeof(struct termios)) != 0) { - DEBUG_MSG("all termios parameters are not set yet, doing a second attempt..."); + CommLog_Print(WLOG_DEBUG, "all termios parameters are not set yet, doing a second attempt..."); if ((result = tcsetattr(fd, optional_actions, termios_p)) < 0) { - DEBUG_WARN("2nd tcsetattr failure, errno: %d", errno); + CommLog_Print(WLOG_WARN, "2nd tcsetattr failure, errno: %d", errno); return result; } ZeroMemory(¤tState, sizeof(struct termios)); if ((result = tcgetattr(fd, ¤tState)) < 0) { - DEBUG_WARN("tcgetattr failure, errno: %d", errno); + CommLog_Print(WLOG_WARN, "tcgetattr failure, errno: %d", errno); return result; } if (memcmp(¤tState, termios_p, sizeof(struct termios)) != 0) { - DEBUG_WARN("Failure: all termios parameters are still not set on a second attempt"); + CommLog_Print(WLOG_WARN, "Failure: all termios parameters are still not set on a second attempt"); return -1; } } diff --git a/winpr/libwinpr/comm/comm_sercx2_sys.c b/winpr/libwinpr/comm/comm_sercx2_sys.c index 9d09e8c98..d391e69e7 100644 --- a/winpr/libwinpr/comm/comm_sercx2_sys.c +++ b/winpr/libwinpr/comm/comm_sercx2_sys.c @@ -22,7 +22,7 @@ #ifndef _WIN32 -#include +#include #include "comm_serial_sys.h" #include "comm_sercx_sys.h" @@ -81,7 +81,7 @@ static BOOL _set_wait_mask(WINPR_COMM *pComm, const ULONG *pWaitMask) if (possibleMask != *pWaitMask) { - DEBUG_WARN("Not all wait events supported (SerCx2.sys), requested events= 0X%lX, possible events= 0X%lX", *pWaitMask, possibleMask); + CommLog_Print(WLOG_WARN, "Not all wait events supported (SerCx2.sys), requested events= 0X%lX, possible events= 0X%lX", *pWaitMask, possibleMask); /* FIXME: shall we really set the possibleMask and return FALSE? */ pComm->WaitEventMask = possibleMask; @@ -101,7 +101,7 @@ static BOOL _purge(WINPR_COMM *pComm, const ULONG *pPurgeMask) if ((*pPurgeMask & SERIAL_PURGE_RXCLEAR) && !(*pPurgeMask & SERIAL_PURGE_RXABORT)) { - DEBUG_WARN("Expecting SERIAL_PURGE_RXABORT since SERIAL_PURGE_RXCLEAR is set"); + CommLog_Print(WLOG_WARN, "Expecting SERIAL_PURGE_RXABORT since SERIAL_PURGE_RXCLEAR is set"); SetLastError(ERROR_INVALID_DEVICE_OBJECT_PARAMETER); return FALSE; } @@ -109,7 +109,7 @@ static BOOL _purge(WINPR_COMM *pComm, const ULONG *pPurgeMask) if ((*pPurgeMask & SERIAL_PURGE_TXCLEAR) && !(*pPurgeMask & SERIAL_PURGE_TXABORT)) { - DEBUG_WARN("Expecting SERIAL_PURGE_TXABORT since SERIAL_PURGE_TXCLEAR is set"); + CommLog_Print(WLOG_WARN, "Expecting SERIAL_PURGE_TXABORT since SERIAL_PURGE_TXCLEAR is set"); SetLastError(ERROR_INVALID_DEVICE_OBJECT_PARAMETER); return FALSE; } diff --git a/winpr/libwinpr/comm/comm_sercx_sys.c b/winpr/libwinpr/comm/comm_sercx_sys.c index db5faeb60..dc53ac845 100644 --- a/winpr/libwinpr/comm/comm_sercx_sys.c +++ b/winpr/libwinpr/comm/comm_sercx_sys.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include "comm_serial_sys.h" @@ -180,7 +180,7 @@ static BOOL _set_baud_rate(WINPR_COMM *pComm, const SERIAL_BAUD_RATE *pBaudRate) newSpeed = _SERCX_SYS_BAUD_TABLE[i][0]; if (cfsetspeed(&futureState, newSpeed) < 0) { - DEBUG_WARN("failed to set speed 0x%x (%lu)", newSpeed, pBaudRate->BaudRate); + CommLog_Print(WLOG_WARN, "failed to set speed 0x%x (%lu)", newSpeed, pBaudRate->BaudRate); return FALSE; } @@ -188,7 +188,7 @@ static BOOL _set_baud_rate(WINPR_COMM *pComm, const SERIAL_BAUD_RATE *pBaudRate) if (_comm_ioctl_tcsetattr(pComm->fd, TCSANOW, &futureState) < 0) { - DEBUG_WARN("_comm_ioctl_tcsetattr failure: last-error: 0x%lX", GetLastError()); + CommLog_Print(WLOG_WARN, "_comm_ioctl_tcsetattr failure: last-error: 0x%lX", GetLastError()); return FALSE; } @@ -196,7 +196,7 @@ static BOOL _set_baud_rate(WINPR_COMM *pComm, const SERIAL_BAUD_RATE *pBaudRate) } } - DEBUG_WARN("could not find a matching speed for the baud rate %lu", pBaudRate->BaudRate); + CommLog_Print(WLOG_WARN, "could not find a matching speed for the baud rate %lu", pBaudRate->BaudRate); SetLastError(ERROR_INVALID_DATA); return FALSE; } @@ -226,7 +226,7 @@ static BOOL _get_baud_rate(WINPR_COMM *pComm, SERIAL_BAUD_RATE *pBaudRate) } } - DEBUG_WARN("could not find a matching baud rate for the speed 0x%x", currentSpeed); + CommLog_Print(WLOG_WARN, "could not find a matching baud rate for the speed 0x%x", currentSpeed); SetLastError(ERROR_INVALID_DATA); return FALSE; } @@ -251,17 +251,17 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) { if (pHandflow->ControlHandShake & SERIAL_DCD_HANDSHAKE) { - DEBUG_WARN("SERIAL_DCD_HANDSHAKE not supposed to be implemented by SerCx.sys"); + CommLog_Print(WLOG_WARN, "SERIAL_DCD_HANDSHAKE not supposed to be implemented by SerCx.sys"); } if (pHandflow->ControlHandShake & SERIAL_DSR_SENSITIVITY) { - DEBUG_WARN("SERIAL_DSR_SENSITIVITY not supposed to be implemented by SerCx.sys"); + CommLog_Print(WLOG_WARN, "SERIAL_DSR_SENSITIVITY not supposed to be implemented by SerCx.sys"); } if (pHandflow->ControlHandShake & SERIAL_ERROR_ABORT) { - DEBUG_WARN("SERIAL_ERROR_ABORT not supposed to be implemented by SerCx.sys"); + CommLog_Print(WLOG_WARN, "SERIAL_ERROR_ABORT not supposed to be implemented by SerCx.sys"); } SetLastError(ERROR_CALL_NOT_IMPLEMENTED); @@ -272,32 +272,32 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) { if (pHandflow->ControlHandShake & SERIAL_AUTO_TRANSMIT) { - DEBUG_WARN("SERIAL_AUTO_TRANSMIT not supposed to be implemented by SerCx.sys"); + CommLog_Print(WLOG_WARN, "SERIAL_AUTO_TRANSMIT not supposed to be implemented by SerCx.sys"); } if (pHandflow->ControlHandShake & SERIAL_AUTO_RECEIVE) { - DEBUG_WARN("SERIAL_AUTO_RECEIVE not supposed to be implemented by SerCx.sys"); + CommLog_Print(WLOG_WARN, "SERIAL_AUTO_RECEIVE not supposed to be implemented by SerCx.sys"); } if (pHandflow->ControlHandShake & SERIAL_ERROR_CHAR) { - DEBUG_WARN("SERIAL_ERROR_CHAR not supposed to be implemented by SerCx.sys"); + CommLog_Print(WLOG_WARN, "SERIAL_ERROR_CHAR not supposed to be implemented by SerCx.sys"); } if (pHandflow->ControlHandShake & SERIAL_NULL_STRIPPING) { - DEBUG_WARN("SERIAL_NULL_STRIPPING not supposed to be implemented by SerCx.sys"); + CommLog_Print(WLOG_WARN, "SERIAL_NULL_STRIPPING not supposed to be implemented by SerCx.sys"); } if (pHandflow->ControlHandShake & SERIAL_BREAK_CHAR) { - DEBUG_WARN("SERIAL_BREAK_CHAR not supposed to be implemented by SerCx.sys"); + CommLog_Print(WLOG_WARN, "SERIAL_BREAK_CHAR not supposed to be implemented by SerCx.sys"); } if (pHandflow->ControlHandShake & SERIAL_XOFF_CONTINUE) { - DEBUG_WARN("SERIAL_XOFF_CONTINUE not supposed to be implemented by SerCx.sys"); + CommLog_Print(WLOG_WARN, "SERIAL_XOFF_CONTINUE not supposed to be implemented by SerCx.sys"); } SetLastError(ERROR_CALL_NOT_IMPLEMENTED); @@ -356,7 +356,7 @@ static BOOL _set_wait_mask(WINPR_COMM *pComm, const ULONG *pWaitMask) if (possibleMask != *pWaitMask) { - DEBUG_WARN("Not all wait events supported (SerCx.sys), requested events= 0x%lX, possible events= 0x%lX", *pWaitMask, possibleMask); + CommLog_Print(WLOG_WARN, "Not all wait events supported (SerCx.sys), requested events= 0x%lX, possible events= 0x%lX", *pWaitMask, possibleMask); /* FIXME: shall we really set the possibleMask and return FALSE? */ pComm->WaitEventMask = possibleMask; diff --git a/winpr/libwinpr/comm/comm_serial_sys.c b/winpr/libwinpr/comm/comm_serial_sys.c index 813c419f7..2cffb31f6 100644 --- a/winpr/libwinpr/comm/comm_serial_sys.c +++ b/winpr/libwinpr/comm/comm_serial_sys.c @@ -29,11 +29,10 @@ #include #include -#include - #include "comm_serial_sys.h" #include +#include /* hard-coded in N_TTY */ #define TTY_THRESHOLD_THROTTLE 128 /* now based on remaining room */ @@ -194,13 +193,13 @@ static BOOL _set_baud_rate(WINPR_COMM *pComm, const SERIAL_BAUD_RATE *pBaudRate) newSpeed = _SERIAL_SYS_BAUD_TABLE[i][0]; if (cfsetspeed(&upcomingTermios, newSpeed) < 0) { - DEBUG_WARN("failed to set speed %u (%lu)", newSpeed, pBaudRate->BaudRate); + CommLog_Print(WLOG_WARN, "failed to set speed %u (%lu)", newSpeed, pBaudRate->BaudRate); return FALSE; } if (_comm_ioctl_tcsetattr(pComm->fd, TCSANOW, &upcomingTermios) < 0) { - DEBUG_WARN("_comm_ioctl_tcsetattr failure: last-error: 0x%lX", GetLastError()); + CommLog_Print(WLOG_WARN, "_comm_ioctl_tcsetattr failure: last-error: 0x%lX", GetLastError()); return FALSE; } @@ -208,7 +207,7 @@ static BOOL _set_baud_rate(WINPR_COMM *pComm, const SERIAL_BAUD_RATE *pBaudRate) } } - DEBUG_WARN("could not find a matching speed for the baud rate %lu", pBaudRate->BaudRate); + CommLog_Print(WLOG_WARN, "could not find a matching speed for the baud rate %lu", pBaudRate->BaudRate); SetLastError(ERROR_INVALID_DATA); return FALSE; } @@ -238,7 +237,7 @@ static BOOL _get_baud_rate(WINPR_COMM *pComm, SERIAL_BAUD_RATE *pBaudRate) } } - DEBUG_WARN("could not find a matching baud rate for the speed 0x%x", currentSpeed); + CommLog_Print(WLOG_WARN, "could not find a matching baud rate for the speed 0x%x", currentSpeed); SetLastError(ERROR_INVALID_DATA); return FALSE; } @@ -284,7 +283,7 @@ static BOOL _set_serial_chars(WINPR_COMM *pComm, const SERIAL_CHARS *pSerialChar */ if (pSerialChars->EofChar != '\0') { - DEBUG_WARN("EofChar='%c' cannot be set\n", pSerialChars->EofChar); + CommLog_Print(WLOG_WARN, "EofChar='%c' cannot be set\n", pSerialChars->EofChar); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -297,7 +296,7 @@ static BOOL _set_serial_chars(WINPR_COMM *pComm, const SERIAL_CHARS *pSerialChar /* FIXME: see also: _set_handflow() */ if (pSerialChars->ErrorChar != '\0') { - DEBUG_WARN("ErrorChar='%c' (0x%x) cannot be set (unsupported).\n", pSerialChars->ErrorChar, pSerialChars->ErrorChar); + CommLog_Print(WLOG_WARN, "ErrorChar='%c' (0x%x) cannot be set (unsupported).\n", pSerialChars->ErrorChar, pSerialChars->ErrorChar); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -305,7 +304,7 @@ static BOOL _set_serial_chars(WINPR_COMM *pComm, const SERIAL_CHARS *pSerialChar /* FIXME: see also: _set_handflow() */ if (pSerialChars->BreakChar != '\0') { - DEBUG_WARN("BreakChar='%c' (0x%x) cannot be set (unsupported).\n", pSerialChars->BreakChar, pSerialChars->BreakChar); + CommLog_Print(WLOG_WARN, "BreakChar='%c' (0x%x) cannot be set (unsupported).\n", pSerialChars->BreakChar, pSerialChars->BreakChar); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -313,7 +312,7 @@ static BOOL _set_serial_chars(WINPR_COMM *pComm, const SERIAL_CHARS *pSerialChar /* FIXME: could be implemented during read/write I/O. What about ISIG? */ if (pSerialChars->EventChar != '\0') { - DEBUG_WARN("EventChar='%c' (0x%x) cannot be set\n", pSerialChars->EventChar, pSerialChars->EventChar); + CommLog_Print(WLOG_WARN, "EventChar='%c' (0x%x) cannot be set\n", pSerialChars->EventChar, pSerialChars->EventChar); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -325,7 +324,7 @@ static BOOL _set_serial_chars(WINPR_COMM *pComm, const SERIAL_CHARS *pSerialChar if (_comm_ioctl_tcsetattr(pComm->fd, TCSANOW, &upcomingTermios) < 0) { - DEBUG_WARN("_comm_ioctl_tcsetattr failure: last-error: 0x%lX", GetLastError()); + CommLog_Print(WLOG_WARN, "_comm_ioctl_tcsetattr failure: last-error: 0x%lX", GetLastError()); return FALSE; } @@ -395,7 +394,7 @@ static BOOL _set_line_control(WINPR_COMM *pComm, const SERIAL_LINE_CONTROL *pLin break; case STOP_BITS_1_5: - DEBUG_WARN("Unsupported one and a half stop bits."); + CommLog_Print(WLOG_WARN, "Unsupported one and a half stop bits."); break; case STOP_BITS_2: @@ -403,7 +402,7 @@ static BOOL _set_line_control(WINPR_COMM *pComm, const SERIAL_LINE_CONTROL *pLin break; default: - DEBUG_WARN("unexpected number of stop bits: %d\n", pLineControl->StopBits); + CommLog_Print(WLOG_WARN, "unexpected number of stop bits: %d\n", pLineControl->StopBits); result = FALSE; /* but keep on */ break; } @@ -435,7 +434,7 @@ static BOOL _set_line_control(WINPR_COMM *pComm, const SERIAL_LINE_CONTROL *pLin break; default: - DEBUG_WARN("unexpected type of parity: %d\n", pLineControl->Parity); + CommLog_Print(WLOG_WARN, "unexpected type of parity: %d\n", pLineControl->Parity); result = FALSE; /* but keep on */ break; } @@ -463,14 +462,14 @@ static BOOL _set_line_control(WINPR_COMM *pComm, const SERIAL_LINE_CONTROL *pLin break; default: - DEBUG_WARN("unexpected number od data bits per character: %d\n", pLineControl->WordLength); + CommLog_Print(WLOG_WARN, "unexpected number od data bits per character: %d\n", pLineControl->WordLength); result = FALSE; /* but keep on */ break; } if (_comm_ioctl_tcsetattr(pComm->fd, TCSANOW, &upcomingTermios) < 0) { - DEBUG_WARN("_comm_ioctl_tcsetattr failure: last-error: 0x%lX", GetLastError()); + CommLog_Print(WLOG_WARN, "_comm_ioctl_tcsetattr failure: last-error: 0x%lX", GetLastError()); return FALSE; } @@ -543,7 +542,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) if ((!(pHandflow->ControlHandShake & SERIAL_DTR_CONTROL) && (pHandflow->FlowReplace & SERIAL_RTS_CONTROL)) || ((pHandflow->ControlHandShake & SERIAL_DTR_CONTROL) && !(pHandflow->FlowReplace & SERIAL_RTS_CONTROL))) { - DEBUG_WARN("SERIAL_DTR_CONTROL:%s and SERIAL_RTS_CONTROL:%s cannot be different, HUPCL will be set since it is claimed for one of the both lines.", + CommLog_Print(WLOG_WARN, "SERIAL_DTR_CONTROL:%s and SERIAL_RTS_CONTROL:%s cannot be different, HUPCL will be set since it is claimed for one of the both lines.", (pHandflow->ControlHandShake & SERIAL_DTR_CONTROL) ? "ON" : "OFF", (pHandflow->FlowReplace & SERIAL_RTS_CONTROL) ? "ON" : "OFF"); } @@ -567,7 +566,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) if ((!(pHandflow->ControlHandShake & SERIAL_CTS_HANDSHAKE) && (pHandflow->FlowReplace & SERIAL_RTS_HANDSHAKE)) || ((pHandflow->ControlHandShake & SERIAL_CTS_HANDSHAKE) && !(pHandflow->FlowReplace & SERIAL_RTS_HANDSHAKE))) { - DEBUG_WARN("SERIAL_CTS_HANDSHAKE:%s and SERIAL_RTS_HANDSHAKE:%s cannot be different, CRTSCTS will be set since it is claimed for one of the both lines.", + CommLog_Print(WLOG_WARN, "SERIAL_CTS_HANDSHAKE:%s and SERIAL_RTS_HANDSHAKE:%s cannot be different, CRTSCTS will be set since it is claimed for one of the both lines.", (pHandflow->ControlHandShake & SERIAL_CTS_HANDSHAKE) ? "ON" : "OFF", (pHandflow->FlowReplace & SERIAL_RTS_HANDSHAKE) ? "ON" : "OFF"); } @@ -587,7 +586,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) if (pHandflow->ControlHandShake & SERIAL_DTR_HANDSHAKE) { /* DTR/DSR flow control not supported on Linux */ - DEBUG_WARN("Attempt to use the unsupported SERIAL_DTR_HANDSHAKE feature."); + CommLog_Print(WLOG_WARN, "Attempt to use the unsupported SERIAL_DTR_HANDSHAKE feature."); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -596,7 +595,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) if (pHandflow->ControlHandShake & SERIAL_DSR_HANDSHAKE) { /* DTR/DSR flow control not supported on Linux */ - DEBUG_WARN("Attempt to use the unsupported SERIAL_DSR_HANDSHAKE feature."); + CommLog_Print(WLOG_WARN, "Attempt to use the unsupported SERIAL_DSR_HANDSHAKE feature."); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -604,7 +603,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) if (pHandflow->ControlHandShake & SERIAL_DCD_HANDSHAKE) { /* DCD flow control not supported on Linux */ - DEBUG_WARN("Attempt to use the unsupported SERIAL_DCD_HANDSHAKE feature."); + CommLog_Print(WLOG_WARN, "Attempt to use the unsupported SERIAL_DCD_HANDSHAKE feature."); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -613,7 +612,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) if (pHandflow->ControlHandShake & SERIAL_DSR_SENSITIVITY) { /* DSR line control not supported on Linux */ - DEBUG_WARN("Attempt to use the unsupported SERIAL_DSR_SENSITIVITY feature."); + CommLog_Print(WLOG_WARN, "Attempt to use the unsupported SERIAL_DSR_SENSITIVITY feature."); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -622,7 +621,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) if (pHandflow->ControlHandShake & SERIAL_ERROR_ABORT) { /* Aborting operations on error not supported on Linux */ - DEBUG_WARN("Attempt to use the unsupported SERIAL_ERROR_ABORT feature."); + CommLog_Print(WLOG_WARN, "Attempt to use the unsupported SERIAL_ERROR_ABORT feature."); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -670,7 +669,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) // FIXME: could be implemented during read/write I/O if (pHandflow->FlowReplace & SERIAL_BREAK_CHAR) { - DEBUG_WARN("Attempt to use the unsupported SERIAL_BREAK_CHAR feature."); + CommLog_Print(WLOG_WARN, "Attempt to use the unsupported SERIAL_BREAK_CHAR feature."); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -679,7 +678,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) if (pHandflow->FlowReplace & SERIAL_XOFF_CONTINUE) { /* not supported on Linux */ - DEBUG_WARN("Attempt to use the unsupported SERIAL_XOFF_CONTINUE feature."); + CommLog_Print(WLOG_WARN, "Attempt to use the unsupported SERIAL_XOFF_CONTINUE feature."); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -689,7 +688,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) // FIXME: could be implemented during read/write I/O if (pHandflow->XonLimit != TTY_THRESHOLD_UNTHROTTLE) { - DEBUG_WARN("Attempt to set XonLimit with an unsupported value: %lu", pHandflow->XonLimit); + CommLog_Print(WLOG_WARN, "Attempt to set XonLimit with an unsupported value: %lu", pHandflow->XonLimit); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -699,7 +698,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) // FIXME: could be implemented during read/write I/O if (pHandflow->XoffLimit != TTY_THRESHOLD_THROTTLE) { - DEBUG_WARN("Attempt to set XoffLimit with an unsupported value: %lu", pHandflow->XoffLimit); + CommLog_Print(WLOG_WARN, "Attempt to set XoffLimit with an unsupported value: %lu", pHandflow->XoffLimit); SetLastError(ERROR_NOT_SUPPORTED); result = FALSE; /* but keep on */ } @@ -707,7 +706,7 @@ static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow) if (_comm_ioctl_tcsetattr(pComm->fd, TCSANOW, &upcomingTermios) < 0) { - DEBUG_WARN("_comm_ioctl_tcsetattr failure: last-error: 0x%lX", GetLastError()); + CommLog_Print(WLOG_WARN, "_comm_ioctl_tcsetattr failure: last-error: 0x%lX", GetLastError()); return FALSE; } @@ -794,7 +793,7 @@ static BOOL _set_timeouts(WINPR_COMM *pComm, const SERIAL_TIMEOUTS *pTimeouts) /* http://msdn.microsoft.com/en-us/library/windows/hardware/hh439614%28v=vs.85%29.aspx */ if ((pTimeouts->ReadIntervalTimeout == MAXULONG) && (pTimeouts->ReadTotalTimeoutConstant == MAXULONG)) { - DEBUG_WARN("ReadIntervalTimeout and ReadTotalTimeoutConstant cannot be both set to MAXULONG"); + CommLog_Print(WLOG_WARN, "ReadIntervalTimeout and ReadTotalTimeoutConstant cannot be both set to MAXULONG"); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } @@ -824,7 +823,7 @@ static BOOL _set_lines(WINPR_COMM *pComm, UINT32 lines) { if (ioctl(pComm->fd, TIOCMBIS, &lines) < 0) { - DEBUG_WARN("TIOCMBIS ioctl failed, lines=0x%X, errno=[%d] %s", lines, errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCMBIS ioctl failed, lines=0x%X, errno=[%d] %s", lines, errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -837,7 +836,7 @@ static BOOL _clear_lines(WINPR_COMM *pComm, UINT32 lines) { if (ioctl(pComm->fd, TIOCMBIC, &lines) < 0) { - DEBUG_WARN("TIOCMBIC ioctl failed, lines=0x%X, errno=[%d] %s", lines, errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCMBIC ioctl failed, lines=0x%X, errno=[%d] %s", lines, errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -919,7 +918,7 @@ static BOOL _get_modemstatus(WINPR_COMM *pComm, ULONG *pRegister) UINT32 lines=0; if (ioctl(pComm->fd, TIOCMGET, &lines) < 0) { - DEBUG_WARN("TIOCMGET ioctl failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCMGET ioctl failed, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -998,7 +997,7 @@ static BOOL _set_wait_mask(WINPR_COMM *pComm, const ULONG *pWaitMask) if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0) { - DEBUG_WARN("TIOCGICOUNT ioctl failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); LeaveCriticalSection(&pComm->EventsLock); @@ -1012,7 +1011,7 @@ static BOOL _set_wait_mask(WINPR_COMM *pComm, const ULONG *pWaitMask) if (possibleMask != *pWaitMask) { - DEBUG_WARN("Not all wait events supported (Serial.sys), requested events= 0X%lX, possible events= 0X%lX", *pWaitMask, possibleMask); + CommLog_Print(WLOG_WARN, "Not all wait events supported (Serial.sys), requested events= 0X%lX, possible events= 0X%lX", *pWaitMask, possibleMask); /* FIXME: shall we really set the possibleMask and return FALSE? */ pComm->WaitEventMask = possibleMask; @@ -1044,10 +1043,10 @@ static BOOL _set_queue_size(WINPR_COMM *pComm, const SERIAL_QUEUE_SIZE *pQueueSi /* FIXME: could be implemented on top of N_TTY */ if (pQueueSize->InSize > N_TTY_BUF_SIZE) - DEBUG_WARN("Requested an incompatible input buffer size: %lu, keeping on with a %d bytes buffer.", pQueueSize->InSize, N_TTY_BUF_SIZE); + CommLog_Print(WLOG_WARN, "Requested an incompatible input buffer size: %lu, keeping on with a %d bytes buffer.", pQueueSize->InSize, N_TTY_BUF_SIZE); if (pQueueSize->OutSize > N_TTY_BUF_SIZE) - DEBUG_WARN("Requested an incompatible output buffer size: %lu, keeping on with a %d bytes buffer.", pQueueSize->OutSize, N_TTY_BUF_SIZE); + CommLog_Print(WLOG_WARN, "Requested an incompatible output buffer size: %lu, keeping on with a %d bytes buffer.", pQueueSize->OutSize, N_TTY_BUF_SIZE); SetLastError(ERROR_CANCELLED); return FALSE; @@ -1058,7 +1057,7 @@ static BOOL _purge(WINPR_COMM *pComm, const ULONG *pPurgeMask) { if ((*pPurgeMask & ~(SERIAL_PURGE_TXABORT | SERIAL_PURGE_RXABORT | SERIAL_PURGE_TXCLEAR | SERIAL_PURGE_RXCLEAR)) > 0) { - DEBUG_WARN("Invalid purge mask: 0x%lX\n", *pPurgeMask); + CommLog_Print(WLOG_WARN, "Invalid purge mask: 0x%lX\n", *pPurgeMask); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } @@ -1076,7 +1075,7 @@ static BOOL _purge(WINPR_COMM *pComm, const ULONG *pPurgeMask) { if (errno != EAGAIN) { - DEBUG_WARN("eventfd_write failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "eventfd_write failed, errno=[%d] %s", errno, strerror(errno)); } assert(errno == EAGAIN); /* no reader <=> no pending IRP_MJ_WRITE */ @@ -1091,7 +1090,7 @@ static BOOL _purge(WINPR_COMM *pComm, const ULONG *pPurgeMask) { if (errno != EAGAIN) { - DEBUG_WARN("eventfd_write failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "eventfd_write failed, errno=[%d] %s", errno, strerror(errno)); } assert(errno == EAGAIN); /* no reader <=> no pending IRP_MJ_READ */ @@ -1104,7 +1103,7 @@ static BOOL _purge(WINPR_COMM *pComm, const ULONG *pPurgeMask) if (tcflush(pComm->fd, TCOFLUSH) < 0) { - DEBUG_WARN("tcflush(TCOFLUSH) failure, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "tcflush(TCOFLUSH) failure, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_CANCELLED); return FALSE; } @@ -1117,7 +1116,7 @@ static BOOL _purge(WINPR_COMM *pComm, const ULONG *pPurgeMask) if (tcflush(pComm->fd, TCIFLUSH) < 0) { - DEBUG_WARN("tcflush(TCIFLUSH) failure, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "tcflush(TCIFLUSH) failure, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_CANCELLED); return FALSE; } @@ -1144,7 +1143,7 @@ static BOOL _get_commstatus(WINPR_COMM *pComm, SERIAL_STATUS *pCommstatus) ZeroMemory(¤tCounters, sizeof(struct serial_icounter_struct)); if (ioctl(pComm->fd, TIOCGICOUNT, ¤tCounters) < 0) { - DEBUG_WARN("TIOCGICOUNT ioctl failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); LeaveCriticalSection(&pComm->EventsLock); @@ -1206,7 +1205,7 @@ static BOOL _get_commstatus(WINPR_COMM *pComm, SERIAL_STATUS *pCommstatus) if (ioctl(pComm->fd, TIOCINQ, &(pCommstatus->AmountInInQueue)) < 0) { - DEBUG_WARN("TIOCINQ ioctl failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCINQ ioctl failed, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); LeaveCriticalSection(&pComm->EventsLock); @@ -1218,7 +1217,7 @@ static BOOL _get_commstatus(WINPR_COMM *pComm, SERIAL_STATUS *pCommstatus) if (ioctl(pComm->fd, TIOCOUTQ, &(pCommstatus->AmountInOutQueue)) < 0) { - DEBUG_WARN("TIOCOUTQ ioctl failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCOUTQ ioctl failed, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); LeaveCriticalSection(&pComm->EventsLock); @@ -1390,7 +1389,7 @@ static BOOL _wait_on_mask(WINPR_COMM *pComm, ULONG *pOutputMask) Sleep(100); /* 100 ms */ } - DEBUG_WARN("_wait_on_mask, unexpected return, WaitEventMask=0X%lX", pComm->WaitEventMask); + CommLog_Print(WLOG_WARN, "_wait_on_mask, unexpected return, WaitEventMask=0X%lX", pComm->WaitEventMask); EnterCriticalSection(&pComm->EventsLock); pComm->PendingEvents &= ~SERIAL_EV_FREERDP_WAITING; LeaveCriticalSection(&pComm->EventsLock); @@ -1402,7 +1401,7 @@ static BOOL _set_break_on(WINPR_COMM *pComm) { if (ioctl(pComm->fd, TIOCSBRK, NULL) < 0) { - DEBUG_WARN("TIOCSBRK ioctl failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCSBRK ioctl failed, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -1415,7 +1414,7 @@ static BOOL _set_break_off(WINPR_COMM *pComm) { if (ioctl(pComm->fd, TIOCCBRK, NULL) < 0) { - DEBUG_WARN("TIOCSBRK ioctl failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCSBRK ioctl failed, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -1428,7 +1427,7 @@ static BOOL _set_xoff(WINPR_COMM *pComm) { if (tcflow(pComm->fd, TCIOFF) < 0) { - DEBUG_WARN("TCIOFF failure, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TCIOFF failure, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -1441,7 +1440,7 @@ static BOOL _set_xon(WINPR_COMM *pComm) { if (tcflow(pComm->fd, TCION) < 0) { - DEBUG_WARN("TCION failure, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TCION failure, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); return FALSE; } @@ -1455,7 +1454,7 @@ BOOL _get_dtrrts(WINPR_COMM *pComm, ULONG *pMask) UINT32 lines=0; if (ioctl(pComm->fd, TIOCMGET, &lines) < 0) { - DEBUG_WARN("TIOCMGET ioctl failed, errno=[%d] %s", errno, strerror(errno)); + CommLog_Print(WLOG_WARN, "TIOCMGET ioctl failed, errno=[%d] %s", errno, strerror(errno)); SetLastError(ERROR_IO_DEVICE); return FALSE; }