#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
+#include <stdarg.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
-#include <freerdp/utils/debug.h>
-
#include <winpr/crt.h>
#include <winpr/comm.h>
#include <winpr/tchar.h>
+#include <winpr/wlog.h>
#include "comm_ioctl.h"
#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;
}
{
WINPR_COMM* pComm = (WINPR_COMM*) hCommDev;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
{
WINPR_COMM* pComm = (WINPR_COMM*) hCommDev;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
{
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
{
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
{
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
/**
* ERRORS:
+ * ERROR_DLL_INIT_FAILED
* ERROR_INVALID_HANDLE
*/
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);
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;
}
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);
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;
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;
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;
}
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;
}
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;
}
/* FIXME: validate changes according GetCommProperties? */
+ if (!CommInitialized())
+ return FALSE;
+
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
{
SetLastError(ERROR_INVALID_HANDLE);
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;
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;
}
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;
}
break;
default:
- DEBUG_WARN("Unexpected fDtrControl value: %d\n", lpDCB->fDtrControl);
+ CommLog_Print(WLOG_WARN, "Unexpected fDtrControl value: %d\n", lpDCB->fDtrControl);
return FALSE;
}
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;
break;
default:
- DEBUG_WARN("Unexpected fRtsControl value: %d\n", lpDCB->fRtsControl);
+ CommLog_Print(WLOG_WARN, "Unexpected fRtsControl value: %d\n", lpDCB->fRtsControl);
return FALSE;
}
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;
}
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)
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);
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;
}
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);
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;
}
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;
}
{
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
{
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
{
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
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);
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;
}
SERIAL_QUEUE_SIZE queueSize;
DWORD bytesReturned = 0;
+ if (!CommInitialized())
+ return FALSE;
+
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
{
SetLastError(ERROR_INVALID_HANDLE);
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;
}
{
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
{
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
{
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
+ if (!CommInitialized())
+ return FALSE;
+
+ /* TODO: not implemented */
+
if (!pComm)
return FALSE;
/* 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++)
{
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)
{
SetLastError(ERROR_SUCCESS);
- if (pthread_once(&_CommInitialized, _CommInit) != 0)
- {
- SetLastError(ERROR_DLL_INIT_FAILED);
+ if (!CommInitialized())
return 0;
- }
if (_CommDevices == NULL)
{
{
TCHAR lpTargetPath[MAX_PATH];
+ if (!CommInitialized())
+ return FALSE;
+
if (QueryCommDevice(lpDeviceName, lpTargetPath, MAX_PATH) > 0)
{
return TRUE;
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;
}
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)
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)
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)
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
{
WINPR_COMM *pComm;
+ if (!CommInitialized())
+ return FALSE;
+
pComm = (WINPR_COMM*)handle;
if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
{
WINPR_COMM *pComm;
+ if (!CommInitialized())
+ return FALSE;
+
pComm = (WINPR_COMM*)handle;
if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
/* 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!");
}
}
#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);
#include <termios.h>
#include <unistd.h>
-#include <freerdp/utils/debug.h>
-
#include <winpr/io.h>
+#include <winpr/wlog.h>
#include <winpr/wtypes.h>
#include "comm.h"
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;
}
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;
}
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;
}
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;
}
}
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 ? */
}
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)
{
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;
}
}
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 ? */
}
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)
{
#include <assert.h>
#include <errno.h>
-#include <freerdp/utils/debug.h>
+#include <winpr/wlog.h>
#include "comm.h"
#include "comm_ioctl.h"
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)
*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 ...
*
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;
}
}
}
- 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;
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());
}
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;
}
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;
}
}
#ifndef _WIN32
-#include <freerdp/utils/debug.h>
+#include <winpr/wlog.h>
#include "comm_serial_sys.h"
#include "comm_sercx_sys.h"
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;
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;
}
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;
}
#include <assert.h>
#include <termios.h>
-#include <freerdp/utils/debug.h>
+#include <winpr/wlog.h>
#include "comm_serial_sys.h"
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;
}
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;
}
}
}
- 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;
}
}
}
- 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;
}
{
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);
{
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);
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;
#include <termios.h>
#include <unistd.h>
-#include <freerdp/utils/debug.h>
-
#include "comm_serial_sys.h"
#include <winpr/crt.h>
+#include <winpr/wlog.h>
/* hard-coded in N_TTY */
#define TTY_THRESHOLD_THROTTLE 128 /* now based on remaining room */
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;
}
}
}
- 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;
}
}
}
- 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;
}
*/
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 */
}
/* 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 */
}
/* 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 */
}
/* 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 */
}
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;
}
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:
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;
}
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;
}
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;
}
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");
}
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");
}
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 */
}
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 */
}
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 */
}
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 */
}
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 */
}
// 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 */
}
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 */
}
// 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 */
}
// 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 */
}
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;
}
/* 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;
}
{
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;
}
{
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;
}
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;
}
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);
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;
/* 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;
{
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;
}
{
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 */
{
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 */
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;
}
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;
}
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);
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);
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);
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);
{
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;
}
{
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;
}
{
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;
}
{
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;
}
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;
}