winpr-comm: got IOCTL_SERIAL_GET_DTRRTS

This commit is contained in:
Emmanuel Ledoux 2014-05-28 11:39:10 +02:00 committed by Emmanuel Ledoux
parent f959590bd2
commit 1e9e8b68bf
6 changed files with 62 additions and 7 deletions

View File

@ -433,7 +433,7 @@ WINPR_API HANDLE CommCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD
#define IOCTL_SERIAL_GET_HANDFLOW 0x001B0060
#define IOCTL_SERIAL_SET_HANDFLOW 0x001B0064
#define IOCTL_SERIAL_GET_MODEMSTATUS 0x001B0068
/* IOCTL_SERIAL_GET_DTRRTS 0x001B0078 */
#define IOCTL_SERIAL_GET_DTRRTS 0x001B0078
/* according to [MS-RDPESP] it should be 0x001B0084, but servers send 0x001B006C */
#define IOCTL_SERIAL_GET_COMMSTATUS 0x001B006C
@ -499,7 +499,7 @@ static const _SERIAL_IOCTL_NAME _SERIAL_IOCTL_NAMES[] =
{IOCTL_SERIAL_GET_HANDFLOW, "IOCTL_SERIAL_GET_HANDFLOW"},
{IOCTL_SERIAL_SET_HANDFLOW, "IOCTL_SERIAL_SET_HANDFLOW"},
{IOCTL_SERIAL_GET_MODEMSTATUS, "IOCTL_SERIAL_GET_MODEMSTATUS"},
// {IOCTL_SERIAL_GET_DTRRTS, "IOCTL_SERIAL_GET_DTRRTS"},
{IOCTL_SERIAL_GET_DTRRTS, "IOCTL_SERIAL_GET_DTRRTS"},
{IOCTL_SERIAL_GET_COMMSTATUS, "IOCTL_SERIAL_GET_COMMSTATUS"},
{IOCTL_SERIAL_GET_PROPERTIES, "IOCTL_SERIAL_GET_PROPERTIES"},
// {IOCTL_SERIAL_XOFF_COUNTER, "IOCTL_SERIAL_XOFF_COUNTER"},

View File

@ -558,6 +558,28 @@ static BOOL _CommDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID l
}
break;
}
case IOCTL_SERIAL_GET_DTRRTS:
{
if (pRemoteSerialDriver->get_dtrrts)
{
ULONG *pMask = (ULONG*)lpOutBuffer;
assert(nOutBufferSize >= sizeof(ULONG));
if (nOutBufferSize < sizeof(ULONG))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
if (!pRemoteSerialDriver->get_dtrrts(pComm, pMask))
return FALSE;
*lpBytesReturned = sizeof(ULONG);
return TRUE;
}
break;
}
}
DEBUG_WARN(_T("unsupported IoControlCode=[0x%lX] %s (remote serial driver: %s)"),

View File

@ -198,6 +198,13 @@ typedef struct _SERIAL_STATUS
#define SERIAL_ERROR_QUEUEOVERRUN ((ULONG)0x00000008)
#define SERIAL_ERROR_PARITY ((ULONG)0x00000010)
#define SERIAL_DTR_STATE ((ULONG)0x00000001)
#define SERIAL_RTS_STATE ((ULONG)0x00000002)
#define SERIAL_CTS_STATE ((ULONG)0x00000010)
#define SERIAL_DSR_STATE ((ULONG)0x00000020)
#define SERIAL_RI_STATE ((ULONG)0x00000040)
#define SERIAL_DCD_STATE ((ULONG)0x00000080)
/**
* A function might be NULL if not supported by the underlying remote driver.
*
@ -233,6 +240,7 @@ typedef struct _REMOTE_SERIAL_DRIVER
BOOL (*set_break_off)(WINPR_COMM *pComm);
BOOL (*set_xoff)(WINPR_COMM *pComm);
BOOL (*set_xon)(WINPR_COMM *pComm);
BOOL (*get_dtrrts)(WINPR_COMM *pComm, ULONG *pMask);
} REMOTE_SERIAL_DRIVER;

View File

@ -150,6 +150,7 @@ static REMOTE_SERIAL_DRIVER _SerCx2Sys =
.set_break_off = NULL,
.set_xoff = NULL, /* not supported by SerCx2.sys */
.set_xon = NULL, /* not supported by SerCx2.sys */
.get_dtrrts = NULL,
};
@ -195,6 +196,8 @@ REMOTE_SERIAL_DRIVER* SerCx2Sys_s()
_SerCx2Sys.set_break_on = pSerialSys->set_break_on;
_SerCx2Sys.set_break_off = pSerialSys->set_break_off;
_SerCx2Sys.get_dtrrts = pSerialSys->get_dtrrts;
return &_SerCx2Sys;
}

View File

@ -399,6 +399,7 @@ static REMOTE_SERIAL_DRIVER _SerCxSys =
.set_break_off = NULL,
.set_xoff = NULL,
.set_xon = NULL,
.get_dtrrts = NULL,
};
@ -441,6 +442,8 @@ REMOTE_SERIAL_DRIVER* SerCxSys_s()
_SerCxSys.set_xoff = pSerialSys->set_xoff;
_SerCxSys.set_xon = pSerialSys->set_xon;
_SerCxSys.get_dtrrts = pSerialSys->get_dtrrts;
return &_SerCxSys;
}

View File

@ -163,9 +163,6 @@ static BOOL _get_properties(WINPR_COMM *pComm, COMMPROP *pProperties)
* implementation just relies on the Linux' implementation.
*/
// TMP: TODO:
if (pProperties->dwProvSpec1 != COMMPROP_INITIALIZED)
{
ZeroMemory(pProperties, sizeof(COMMPROP));
@ -184,7 +181,7 @@ static BOOL _get_properties(WINPR_COMM *pComm, COMMPROP *pProperties)
pProperties->dwMaxBaud = SERIAL_BAUD_115200; /* _SERIAL_MAX_BAUD */
/* FIXME: what about PST_RS232? */
/* FIXME: what about PST_RS232? see also: serial_struct */
pProperties->dwProvSubType = PST_UNSPECIFIED;
/* TMP: TODO: to be finalized */
@ -205,7 +202,7 @@ static BOOL _get_properties(WINPR_COMM *pComm, COMMPROP *pProperties)
pProperties->wSettableStopParity = STOPBITS_10 | /*STOPBITS_15 |*/ STOPBITS_20 | PARITY_NONE | PARITY_ODD | PARITY_EVEN | PARITY_MARK | PARITY_SPACE;
/* FIXME: could be implemented on top of N_TTY */
/* FIXME: additional input and output buffers could be implemented on top of N_TTY */
pProperties->dwCurrentTxQueue = N_TTY_BUF_SIZE;
pProperties->dwCurrentRxQueue = N_TTY_BUF_SIZE;
@ -1489,6 +1486,27 @@ static BOOL _set_xon(WINPR_COMM *pComm)
}
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));
SetLastError(ERROR_IO_DEVICE);
return FALSE;
}
*pMask = 0;
if (!(lines & TIOCM_DTR))
*pMask |= SERIAL_DTR_STATE;
if (!(lines & TIOCM_RTS))
*pMask |= SERIAL_RTS_STATE;
return TRUE;
}
static REMOTE_SERIAL_DRIVER _SerialSys =
{
.id = RemoteSerialDriverSerialSys,
@ -1519,6 +1537,7 @@ static REMOTE_SERIAL_DRIVER _SerialSys =
.set_break_off = _set_break_off,
.set_xoff = _set_xoff,
.set_xon = _set_xon,
.get_dtrrts = _get_dtrrts,
};