Blame winpr/libwinpr/comm/comm_sercx2_sys.c

Packit Service fa4841
/**
Packit Service fa4841
 * WinPR: Windows Portable Runtime
Packit Service fa4841
 * Serial Communication API
Packit Service fa4841
 *
Packit Service fa4841
 * Copyright 2011 O.S. Systems Software Ltda.
Packit Service fa4841
 * Copyright 2011 Eduardo Fiss Beloni <beloni@ossystems.com.br>
Packit Service fa4841
 * Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
Packit Service fa4841
 * Copyright 2014 Hewlett-Packard Development Company, L.P.
Packit Service fa4841
 *
Packit Service fa4841
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit Service fa4841
 * you may not use this file except in compliance with the License.
Packit Service fa4841
 * You may obtain a copy of the License at
Packit Service fa4841
 *
Packit Service fa4841
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit Service fa4841
 *
Packit Service fa4841
 * Unless required by applicable law or agreed to in writing, software
Packit Service fa4841
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit Service fa4841
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit Service fa4841
 * See the License for the specific language governing permissions and
Packit Service fa4841
 * limitations under the License.
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
#if defined __linux__ && !defined ANDROID
Packit Service fa4841
Packit Service fa4841
#include <winpr/wlog.h>
Packit Service fa4841
Packit Service fa4841
#include "comm_serial_sys.h"
Packit Service fa4841
#include "comm_sercx_sys.h"
Packit Service fa4841
Packit Service fa4841
#include "comm_sercx2_sys.h"
Packit Service fa4841
Packit Service fa4841
/* http://msdn.microsoft.com/en-us/library/dn265347%28v=vs.85%29.aspx
Packit Service fa4841
 *
Packit Service fa4841
 * SerCx2 does not support special characters. SerCx2 always completes
Packit Service fa4841
 * an IOCTL_SERIAL_SET_CHARS request with a STATUS_SUCCESS status
Packit Service fa4841
 * code, but does not set any special characters or perform any other
Packit Service fa4841
 * operation in response to this request. For an
Packit Service fa4841
 * IOCTL_SERIAL_GET_CHARS request, SerCx2 sets all the character
Packit Service fa4841
 * values in the SERIAL_CHARS structure to null, and completes the
Packit Service fa4841
 * request with a STATUS_SUCCESS status code.
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
static BOOL _set_serial_chars(WINPR_COMM* pComm, const SERIAL_CHARS* pSerialChars)
Packit Service fa4841
{
Packit Service fa4841
	return TRUE;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
static BOOL _get_serial_chars(WINPR_COMM* pComm, SERIAL_CHARS* pSerialChars)
Packit Service fa4841
{
Packit Service fa4841
	ZeroMemory(pSerialChars, sizeof(SERIAL_CHARS));
Packit Service fa4841
	return TRUE;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
/* http://msdn.microsoft.com/en-us/library/windows/hardware/hh439605%28v=vs.85%29.aspx */
Packit Service fa4841
/* FIXME: only using the Serial.sys' events, complete the support of the remaining events */
Packit Service fa4841
static const ULONG _SERCX2_SYS_SUPPORTED_EV_MASK =
Packit Service b1ea74
    SERIAL_EV_RXCHAR | SERIAL_EV_RXFLAG | SERIAL_EV_TXEMPTY | SERIAL_EV_CTS | SERIAL_EV_DSR |
Packit Service b1ea74
    SERIAL_EV_RLSD | SERIAL_EV_BREAK | SERIAL_EV_ERR | SERIAL_EV_RING |
Packit Service b1ea74
    /* SERIAL_EV_PERR     | */
Packit Service b1ea74
    SERIAL_EV_RX80FULL /*|
Packit Service b1ea74
    SERIAL_EV_EVENT1   |
Packit Service b1ea74
    SERIAL_EV_EVENT2*/
Packit Service b1ea74
    ;
Packit Service fa4841
Packit Service fa4841
/* use Serial.sys for basis (not SerCx.sys) */
Packit Service b1ea74
static BOOL _set_wait_mask(WINPR_COMM* pComm, const ULONG* pWaitMask)
Packit Service fa4841
{
Packit Service fa4841
	ULONG possibleMask;
Packit Service fa4841
	SERIAL_DRIVER* pSerialSys = SerialSys_s();
Packit Service fa4841
Packit Service fa4841
	possibleMask = *pWaitMask & _SERCX2_SYS_SUPPORTED_EV_MASK;
Packit Service fa4841
Packit Service fa4841
	if (possibleMask != *pWaitMask)
Packit Service fa4841
	{
Packit Service b1ea74
		CommLog_Print(WLOG_WARN,
Packit Service b1ea74
		              "Not all wait events supported (SerCx2.sys), requested events= 0x%08" PRIX32
Packit Service b1ea74
		              ", possible events= 0x%08" PRIX32 "",
Packit Service b1ea74
		              *pWaitMask, possibleMask);
Packit Service fa4841
Packit Service fa4841
		/* FIXME: shall we really set the possibleMask and return FALSE? */
Packit Service fa4841
		pComm->WaitEventMask = possibleMask;
Packit Service fa4841
		return FALSE;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	/* NB: All events that are supported by SerCx.sys are supported by Serial.sys*/
Packit Service fa4841
	return pSerialSys->set_wait_mask(pComm, pWaitMask);
Packit Service fa4841
}
Packit Service fa4841
Packit Service b1ea74
static BOOL _purge(WINPR_COMM* pComm, const ULONG* pPurgeMask)
Packit Service fa4841
{
Packit Service fa4841
	SERIAL_DRIVER* pSerialSys = SerialSys_s();
Packit Service fa4841
Packit Service fa4841
	/* http://msdn.microsoft.com/en-us/library/windows/hardware/ff546655%28v=vs.85%29.aspx */
Packit Service fa4841
Packit Service fa4841
	if ((*pPurgeMask & SERIAL_PURGE_RXCLEAR) && !(*pPurgeMask & SERIAL_PURGE_RXABORT))
Packit Service fa4841
	{
Packit Service b1ea74
		CommLog_Print(WLOG_WARN,
Packit Service b1ea74
		              "Expecting SERIAL_PURGE_RXABORT since SERIAL_PURGE_RXCLEAR is set");
Packit Service fa4841
		SetLastError(ERROR_INVALID_DEVICE_OBJECT_PARAMETER);
Packit Service fa4841
		return FALSE;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	if ((*pPurgeMask & SERIAL_PURGE_TXCLEAR) && !(*pPurgeMask & SERIAL_PURGE_TXABORT))
Packit Service fa4841
	{
Packit Service b1ea74
		CommLog_Print(WLOG_WARN,
Packit Service b1ea74
		              "Expecting SERIAL_PURGE_TXABORT since SERIAL_PURGE_TXCLEAR is set");
Packit Service fa4841
		SetLastError(ERROR_INVALID_DEVICE_OBJECT_PARAMETER);
Packit Service fa4841
		return FALSE;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return pSerialSys->purge(pComm, pPurgeMask);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
/* specific functions only */
Packit Service b1ea74
static SERIAL_DRIVER _SerCx2Sys = {
Packit Service b1ea74
	.id = SerialDriverSerCx2Sys,
Packit Service b1ea74
	.name = _T("SerCx2.sys"),
Packit Service b1ea74
	.set_baud_rate = NULL,
Packit Service b1ea74
	.get_baud_rate = NULL,
Packit Service b1ea74
	.get_properties = NULL,
Packit Service fa4841
	.set_serial_chars = _set_serial_chars,
Packit Service fa4841
	.get_serial_chars = _get_serial_chars,
Packit Service fa4841
	.set_line_control = NULL,
Packit Service fa4841
	.get_line_control = NULL,
Packit Service b1ea74
	.set_handflow = NULL,
Packit Service b1ea74
	.get_handflow = NULL,
Packit Service b1ea74
	.set_timeouts = NULL,
Packit Service b1ea74
	.get_timeouts = NULL,
Packit Service b1ea74
	.set_dtr = NULL,
Packit Service b1ea74
	.clear_dtr = NULL,
Packit Service b1ea74
	.set_rts = NULL,
Packit Service b1ea74
	.clear_rts = NULL,
Packit Service b1ea74
	.get_modemstatus = NULL,
Packit Service b1ea74
	.set_wait_mask = _set_wait_mask,
Packit Service b1ea74
	.get_wait_mask = NULL,
Packit Service b1ea74
	.wait_on_mask = NULL,
Packit Service b1ea74
	.set_queue_size = NULL,
Packit Service b1ea74
	.purge = _purge,
Packit Service b1ea74
	.get_commstatus = NULL,
Packit Service b1ea74
	.set_break_on = NULL,
Packit Service b1ea74
	.set_break_off = NULL,
Packit Service b1ea74
	.set_xoff = NULL, /* not supported by SerCx2.sys */
Packit Service b1ea74
	.set_xon = NULL,  /* not supported by SerCx2.sys */
Packit Service b1ea74
	.get_dtrrts = NULL,
Packit Service b1ea74
	.config_size = NULL,    /* not supported by SerCx2.sys */
Packit Service b1ea74
	.immediate_char = NULL, /* not supported by SerCx2.sys */
Packit Service b1ea74
	.reset_device = NULL,   /* not supported by SerCx2.sys */
Packit Service fa4841
};
Packit Service fa4841
Packit Service fa4841
SERIAL_DRIVER* SerCx2Sys_s()
Packit Service fa4841
{
Packit Service fa4841
	/* _SerCx2Sys completed with inherited functions from SerialSys or SerCxSys */
Packit Service fa4841
	SERIAL_DRIVER* pSerialSys = SerialSys_s();
Packit Service fa4841
	SERIAL_DRIVER* pSerCxSys = SerCxSys_s();
Packit Service fa4841
Packit Service b1ea74
	_SerCx2Sys.set_baud_rate = pSerialSys->set_baud_rate;
Packit Service b1ea74
	_SerCx2Sys.get_baud_rate = pSerialSys->get_baud_rate;
Packit Service fa4841
Packit Service b1ea74
	_SerCx2Sys.get_properties = pSerialSys->get_properties;
Packit Service fa4841
Packit Service fa4841
	_SerCx2Sys.set_line_control = pSerCxSys->set_line_control;
Packit Service fa4841
	_SerCx2Sys.get_line_control = pSerCxSys->get_line_control;
Packit Service fa4841
Packit Service b1ea74
	/* Only SERIAL_CTS_HANDSHAKE, SERIAL_RTS_CONTROL and SERIAL_RTS_HANDSHAKE flags are really
Packit Service b1ea74
	 * required by SerCx2.sys http://msdn.microsoft.com/en-us/library/jj680685%28v=vs.85%29.aspx
Packit Service fa4841
	 */
Packit Service fa4841
	_SerCx2Sys.set_handflow = pSerialSys->set_handflow;
Packit Service fa4841
	_SerCx2Sys.get_handflow = pSerialSys->get_handflow;
Packit Service fa4841
Packit Service fa4841
	_SerCx2Sys.set_timeouts = pSerialSys->set_timeouts;
Packit Service fa4841
	_SerCx2Sys.get_timeouts = pSerialSys->get_timeouts;
Packit Service fa4841
Packit Service b1ea74
	_SerCx2Sys.set_dtr = pSerialSys->set_dtr;
Packit Service fa4841
	_SerCx2Sys.clear_dtr = pSerialSys->clear_dtr;
Packit Service fa4841
Packit Service b1ea74
	_SerCx2Sys.set_rts = pSerialSys->set_rts;
Packit Service fa4841
	_SerCx2Sys.clear_rts = pSerialSys->clear_rts;
Packit Service fa4841
Packit Service fa4841
	_SerCx2Sys.get_modemstatus = pSerialSys->get_modemstatus;
Packit Service fa4841
Packit Service fa4841
	_SerCx2Sys.set_wait_mask = pSerialSys->set_wait_mask;
Packit Service fa4841
	_SerCx2Sys.get_wait_mask = pSerialSys->get_wait_mask;
Packit Service b1ea74
	_SerCx2Sys.wait_on_mask = pSerialSys->wait_on_mask;
Packit Service fa4841
Packit Service fa4841
	_SerCx2Sys.set_queue_size = pSerialSys->set_queue_size;
Packit Service fa4841
Packit Service fa4841
	_SerCx2Sys.get_commstatus = pSerialSys->get_commstatus;
Packit Service fa4841
Packit Service b1ea74
	_SerCx2Sys.set_break_on = pSerialSys->set_break_on;
Packit Service fa4841
	_SerCx2Sys.set_break_off = pSerialSys->set_break_off;
Packit Service fa4841
Packit Service fa4841
	_SerCx2Sys.get_dtrrts = pSerialSys->get_dtrrts;
Packit Service fa4841
Packit Service fa4841
	return &_SerCx2Sys;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
#endif /* __linux__ */