FreeRDP
comm.c File Reference
#include <winpr/config.h>
#include <winpr/assert.h>
#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 <winpr/crt.h>
#include <winpr/comm.h>
#include <winpr/tchar.h>
#include <winpr/wlog.h>
#include <winpr/handle.h>
#include "comm_ioctl.h"
#include "../log.h"
#include "comm.h"

Macros

#define TAG   WINPR_TAG("comm")
 
#define COMM_DEVICE_MAX   128
 

Functions

static int CommGetFd (HANDLE handle)
 
HANDLE_CREATORGetCommHandleCreator (void)
 
static void CommInit (void)
 
static BOOL CommInitialized (void)
 
void CommLog_Print (DWORD level,...)
 
BOOL BuildCommDCBA (LPCSTR lpDef, LPDCB lpDCB)
 
BOOL BuildCommDCBW (LPCWSTR lpDef, LPDCB lpDCB)
 
BOOL BuildCommDCBAndTimeoutsA (LPCSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts)
 
BOOL BuildCommDCBAndTimeoutsW (LPCWSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts)
 
BOOL CommConfigDialogA (LPCSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC)
 
BOOL CommConfigDialogW (LPCWSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC)
 
BOOL GetCommConfig (HANDLE hCommDev, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
 
BOOL SetCommConfig (HANDLE hCommDev, LPCOMMCONFIG lpCC, DWORD dwSize)
 
BOOL GetCommMask (HANDLE hFile, PDWORD lpEvtMask)
 
BOOL SetCommMask (HANDLE hFile, DWORD dwEvtMask)
 
BOOL GetCommModemStatus (HANDLE hFile, PDWORD lpModemStat)
 
BOOL GetCommProperties (HANDLE hFile, LPCOMMPROP lpCommProp)
 
BOOL GetCommState (HANDLE hFile, LPDCB lpDCB)
 
BOOL SetCommState (HANDLE hFile, LPDCB lpDCB)
 
BOOL GetCommTimeouts (HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
 
BOOL SetCommTimeouts (HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
 
BOOL GetDefaultCommConfigA (LPCSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
 
BOOL GetDefaultCommConfigW (LPCWSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
 
BOOL SetDefaultCommConfigA (LPCSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize)
 
BOOL SetDefaultCommConfigW (LPCWSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize)
 
BOOL SetCommBreak (HANDLE hFile)
 
BOOL ClearCommBreak (HANDLE hFile)
 
BOOL ClearCommError (HANDLE hFile, PDWORD lpErrors, LPCOMSTAT lpStat)
 
BOOL PurgeComm (HANDLE hFile, DWORD dwFlags)
 
BOOL SetupComm (HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
 
BOOL EscapeCommFunction (HANDLE hFile, DWORD dwFunc)
 
BOOL TransmitCommChar (HANDLE hFile, char cChar)
 
BOOL WaitCommEvent (HANDLE hFile, PDWORD lpEvtMask, LPOVERLAPPED lpOverlapped)
 
BOOL DefineCommDevice (LPCTSTR lpDeviceName, LPCTSTR lpTargetPath)
 
DWORD QueryCommDevice (LPCTSTR lpDeviceName, LPTSTR lpTargetPath, DWORD ucchMax)
 
BOOL IsCommDevice (LPCTSTR lpDeviceName)
 
void _comm_setServerSerialDriver (HANDLE hComm, SERIAL_DRIVER_ID driverId)
 
HANDLE CommCreateFileA (LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
 
BOOL CommIsHandled (HANDLE handle)
 
BOOL CommIsHandleValid (HANDLE handle)
 
BOOL CommCloseHandle (HANDLE handle)
 

Variables

static wLog * sLog = NULL
 
static COMM_DEVICE ** sCommDevices = NULL
 
static CRITICAL_SECTION sCommDevicesLock
 
static HANDLE_CREATOR sCommHandleCreator = { 0 }
 
static pthread_once_t sCommInitialized = PTHREAD_ONCE_INIT
 
static HANDLE_OPS ops
 

Macro Definition Documentation

◆ COMM_DEVICE_MAX

#define COMM_DEVICE_MAX   128

◆ TAG

#define TAG   WINPR_TAG("comm")

WinPR: Windows Portable Runtime Serial Communication API

Copyright 2011 O.S. Systems Software Ltda. Copyright 2011 Eduardo Fiss Beloni belon.nosp@m.i@os.nosp@m.syste.nosp@m.ms.c.nosp@m.om.br Copyright 2014 Marc-Andre Moreau marca.nosp@m.ndre.nosp@m..more.nosp@m.au@g.nosp@m.mail..nosp@m.com Copyright 2014 Hewlett-Packard Development Company, L.P.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ _comm_setServerSerialDriver()

void _comm_setServerSerialDriver ( HANDLE  hComm,
SERIAL_DRIVER_ID  driverId 
)

Sets

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildCommDCBA()

BOOL BuildCommDCBA ( LPCSTR  lpDef,
LPDCB  lpDCB 
)
Here is the call graph for this function:

◆ BuildCommDCBAndTimeoutsA()

BOOL BuildCommDCBAndTimeoutsA ( LPCSTR  lpDef,
LPDCB  lpDCB,
LPCOMMTIMEOUTS  lpCommTimeouts 
)
Here is the call graph for this function:

◆ BuildCommDCBAndTimeoutsW()

BOOL BuildCommDCBAndTimeoutsW ( LPCWSTR  lpDef,
LPDCB  lpDCB,
LPCOMMTIMEOUTS  lpCommTimeouts 
)
Here is the call graph for this function:

◆ BuildCommDCBW()

BOOL BuildCommDCBW ( LPCWSTR  lpDef,
LPDCB  lpDCB 
)
Here is the call graph for this function:

◆ ClearCommBreak()

BOOL ClearCommBreak ( HANDLE  hFile)
Here is the call graph for this function:

◆ ClearCommError()

BOOL ClearCommError ( HANDLE  hFile,
PDWORD  lpErrors,
LPCOMSTAT  lpStat 
)
Here is the call graph for this function:

◆ CommCloseHandle()

BOOL CommCloseHandle ( HANDLE  handle)
Here is the call graph for this function:

◆ CommConfigDialogA()

BOOL CommConfigDialogA ( LPCSTR  lpszName,
HWND  hWnd,
LPCOMMCONFIG  lpCC 
)
Here is the call graph for this function:

◆ CommConfigDialogW()

BOOL CommConfigDialogW ( LPCWSTR  lpszName,
HWND  hWnd,
LPCOMMCONFIG  lpCC 
)
Here is the call graph for this function:

◆ CommCreateFileA()

HANDLE CommCreateFileA ( LPCSTR  lpDeviceName,
DWORD  dwDesiredAccess,
DWORD  dwShareMode,
LPSECURITY_ATTRIBUTES  lpSecurityAttributes,
DWORD  dwCreationDisposition,
DWORD  dwFlagsAndAttributes,
HANDLE  hTemplateFile 
)

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363198%28v=vs.85%29.aspx

Parameters
lpDeviceNamee.g. COM1, ...
dwDesiredAccessexpects GENERIC_READ | GENERIC_WRITE, a warning message is printed otherwise. TODO: better support.
dwShareModemust be zero, INVALID_HANDLE_VALUE is returned otherwise and GetLastError() should return ERROR_SHARING_VIOLATION.
lpSecurityAttributesNULL expected, a warning message is printed otherwise. TODO: better support.
dwCreationDispositionmust be OPEN_EXISTING. If the communication device doesn't exist INVALID_HANDLE_VALUE is returned and GetLastError() returns ERROR_FILE_NOT_FOUND.
dwFlagsAndAttributeszero expected, a warning message is printed otherwise.
hTemplateFilemust be NULL.
Returns
INVALID_HANDLE_VALUE on error.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CommGetFd()

static int CommGetFd ( HANDLE  handle)
static
Here is the call graph for this function:

◆ CommInit()

static void CommInit ( void  )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CommInitialized()

static BOOL CommInitialized ( void  )
static

Returns TRUE when the comm module is correctly intialized, FALSE otherwise with ERROR_DLL_INIT_FAILED set as the last error.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CommIsHandled()

BOOL CommIsHandled ( HANDLE  handle)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CommIsHandleValid()

BOOL CommIsHandleValid ( HANDLE  handle)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CommLog_Print()

void CommLog_Print ( DWORD  level,
  ... 
)
Here is the call graph for this function:

◆ DefineCommDevice()

BOOL DefineCommDevice ( LPCTSTR  lpDeviceName,
LPCTSTR  lpTargetPath 
)

Returns TRUE on success, FALSE otherwise. To get extended error information, call GetLastError.

ERRORS: ERROR_DLL_INIT_FAILED ERROR_OUTOFMEMORY was not possible to get mappings. ERROR_INVALID_DATA was not possible to add the device.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EscapeCommFunction()

BOOL EscapeCommFunction ( HANDLE  hFile,
DWORD  dwFunc 
)
Here is the call graph for this function:

◆ GetCommConfig()

BOOL GetCommConfig ( HANDLE  hCommDev,
LPCOMMCONFIG  lpCC,
LPDWORD  lpdwSize 
)
Here is the call graph for this function:

◆ GetCommHandleCreator()

HANDLE_CREATOR* GetCommHandleCreator ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCommMask()

BOOL GetCommMask ( HANDLE  hFile,
PDWORD  lpEvtMask 
)
Here is the call graph for this function:

◆ GetCommModemStatus()

BOOL GetCommModemStatus ( HANDLE  hFile,
PDWORD  lpModemStat 
)
Here is the call graph for this function:

◆ GetCommProperties()

BOOL GetCommProperties ( HANDLE  hFile,
LPCOMMPROP  lpCommProp 
)

ERRORS: ERROR_DLL_INIT_FAILED ERROR_INVALID_HANDLE

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCommState()

BOOL GetCommState ( HANDLE  hFile,
LPDCB  lpDCB 
)

ERRORS: ERROR_INVALID_HANDLE ERROR_INVALID_DATA ERROR_IO_DEVICE ERROR_OUTOFMEMORY

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCommTimeouts()

BOOL GetCommTimeouts ( HANDLE  hFile,
LPCOMMTIMEOUTS  lpCommTimeouts 
)

ERRORS: ERROR_INVALID_HANDLE

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDefaultCommConfigA()

BOOL GetDefaultCommConfigA ( LPCSTR  lpszName,
LPCOMMCONFIG  lpCC,
LPDWORD  lpdwSize 
)
Here is the call graph for this function:

◆ GetDefaultCommConfigW()

BOOL GetDefaultCommConfigW ( LPCWSTR  lpszName,
LPCOMMCONFIG  lpCC,
LPDWORD  lpdwSize 
)
Here is the call graph for this function:

◆ IsCommDevice()

BOOL IsCommDevice ( LPCTSTR  lpDeviceName)

Checks whether lpDeviceName is a valid and registered Communication device.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PurgeComm()

BOOL PurgeComm ( HANDLE  hFile,
DWORD  dwFlags 
)
Here is the call graph for this function:

◆ QueryCommDevice()

DWORD QueryCommDevice ( LPCTSTR  lpDeviceName,
LPTSTR  lpTargetPath,
DWORD  ucchMax 
)

Returns the number of target paths in the buffer pointed to by lpTargetPath.

The current implementation returns in any case 0 and 1 target path. A NULL lpDeviceName is not supported yet to get all the paths.

ERRORS: ERROR_SUCCESS ERROR_DLL_INIT_FAILED ERROR_OUTOFMEMORY was not possible to get mappings. ERROR_NOT_SUPPORTED equivalent QueryDosDevice feature not supported. ERROR_INVALID_DATA was not possible to retrieve any device information. ERROR_INSUFFICIENT_BUFFER too small lpTargetPath

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCommBreak()

BOOL SetCommBreak ( HANDLE  hFile)
Here is the call graph for this function:

◆ SetCommConfig()

BOOL SetCommConfig ( HANDLE  hCommDev,
LPCOMMCONFIG  lpCC,
DWORD  dwSize 
)
Here is the call graph for this function:

◆ SetCommMask()

BOOL SetCommMask ( HANDLE  hFile,
DWORD  dwEvtMask 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCommState()

BOOL SetCommState ( HANDLE  hFile,
LPDCB  lpDCB 
)
Returns
TRUE on success, FALSE otherwise.

As of today, SetCommState() can fail half-way with some settings applied and some others not. SetCommState() returns on the first failure met. FIXME: or is it correct?

ERRORS: ERROR_INVALID_HANDLE ERROR_IO_DEVICE

ioctl calls stage

upcomingTermios stage

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCommTimeouts()

BOOL SetCommTimeouts ( HANDLE  hFile,
LPCOMMTIMEOUTS  lpCommTimeouts 
)

ERRORS: ERROR_INVALID_HANDLE

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetDefaultCommConfigA()

BOOL SetDefaultCommConfigA ( LPCSTR  lpszName,
LPCOMMCONFIG  lpCC,
DWORD  dwSize 
)
Here is the call graph for this function:

◆ SetDefaultCommConfigW()

BOOL SetDefaultCommConfigW ( LPCWSTR  lpszName,
LPCOMMCONFIG  lpCC,
DWORD  dwSize 
)
Here is the call graph for this function:

◆ SetupComm()

BOOL SetupComm ( HANDLE  hFile,
DWORD  dwInQueue,
DWORD  dwOutQueue 
)
Here is the call graph for this function:

◆ TransmitCommChar()

BOOL TransmitCommChar ( HANDLE  hFile,
char  cChar 
)
Here is the call graph for this function:

◆ WaitCommEvent()

BOOL WaitCommEvent ( HANDLE  hFile,
PDWORD  lpEvtMask,
LPOVERLAPPED  lpOverlapped 
)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ops

HANDLE_OPS ops
static
Initial value:
NULL }
if availableBytes return NULL
Definition: TPCircularBuffer.h:109
BOOL CommCloseHandle(HANDLE handle)
Definition: comm.c:1388
BOOL CommIsHandled(HANDLE handle)
Definition: comm.c:1367
static int CommGetFd(HANDLE handle)
Definition: comm.c:77

◆ sCommDevices

COMM_DEVICE** sCommDevices = NULL
static

◆ sCommDevicesLock

CRITICAL_SECTION sCommDevicesLock
static

◆ sCommHandleCreator

HANDLE_CREATOR sCommHandleCreator = { 0 }
static

◆ sCommInitialized

pthread_once_t sCommInitialized = PTHREAD_ONCE_INIT
static

◆ sLog

wLog* sLog = NULL
static