2014-04-25 02:20:48 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* Serial Communication API
|
|
|
|
*
|
|
|
|
* Copyright 2011 O.S. Systems Software Ltda.
|
|
|
|
* Copyright 2011 Eduardo Fiss Beloni <beloni@ossystems.com.br>
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.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.
|
|
|
|
*/
|
|
|
|
|
2014-07-04 19:40:06 +04:00
|
|
|
#if defined __linux__ && !defined ANDROID
|
2014-04-28 21:57:17 +04:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <termios.h>
|
|
|
|
|
2014-07-02 17:59:16 +04:00
|
|
|
#include <winpr/wlog.h>
|
2014-04-25 02:20:48 +04:00
|
|
|
|
|
|
|
#include "comm_serial_sys.h"
|
|
|
|
|
2014-04-28 21:57:17 +04:00
|
|
|
|
2014-05-06 18:08:58 +04:00
|
|
|
static BOOL _set_handflow(WINPR_COMM *pComm, const SERIAL_HANDFLOW *pHandflow)
|
|
|
|
{
|
2014-05-19 18:53:57 +04:00
|
|
|
SERIAL_HANDFLOW SerCxHandflow;
|
2014-05-06 18:08:58 +04:00
|
|
|
BOOL result = TRUE;
|
2014-06-18 17:58:08 +04:00
|
|
|
SERIAL_DRIVER* pSerialSys = SerialSys_s();
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
memcpy(&SerCxHandflow, pHandflow, sizeof(SERIAL_HANDFLOW));
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-06-16 21:18:45 +04:00
|
|
|
/* filter out unsupported bits by SerCx.sys
|
2014-05-19 18:53:57 +04:00
|
|
|
*
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/hardware/jj680685%28v=vs.85%29.aspx
|
|
|
|
*/
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
SerCxHandflow.ControlHandShake = pHandflow->ControlHandShake & (SERIAL_DTR_CONTROL | SERIAL_DTR_HANDSHAKE | SERIAL_CTS_HANDSHAKE | SERIAL_DSR_HANDSHAKE);
|
|
|
|
SerCxHandflow.FlowReplace = pHandflow->FlowReplace & (SERIAL_RTS_CONTROL | SERIAL_RTS_HANDSHAKE);
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
if (SerCxHandflow.ControlHandShake != pHandflow->ControlHandShake)
|
2014-05-06 18:08:58 +04:00
|
|
|
{
|
2014-05-19 18:53:57 +04:00
|
|
|
if (pHandflow->ControlHandShake & SERIAL_DCD_HANDSHAKE)
|
|
|
|
{
|
2014-07-02 17:59:16 +04:00
|
|
|
CommLog_Print(WLOG_WARN, "SERIAL_DCD_HANDSHAKE not supposed to be implemented by SerCx.sys");
|
2014-05-19 18:53:57 +04:00
|
|
|
}
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
if (pHandflow->ControlHandShake & SERIAL_DSR_SENSITIVITY)
|
|
|
|
{
|
2014-07-02 17:59:16 +04:00
|
|
|
CommLog_Print(WLOG_WARN, "SERIAL_DSR_SENSITIVITY not supposed to be implemented by SerCx.sys");
|
2014-05-19 18:53:57 +04:00
|
|
|
}
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
if (pHandflow->ControlHandShake & SERIAL_ERROR_ABORT)
|
|
|
|
{
|
2014-07-02 17:59:16 +04:00
|
|
|
CommLog_Print(WLOG_WARN, "SERIAL_ERROR_ABORT not supposed to be implemented by SerCx.sys");
|
2014-05-19 18:53:57 +04:00
|
|
|
}
|
2014-05-06 18:08:58 +04:00
|
|
|
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
2014-05-19 18:53:57 +04:00
|
|
|
result = FALSE;
|
2014-05-06 18:08:58 +04:00
|
|
|
}
|
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
if (SerCxHandflow.FlowReplace != pHandflow->FlowReplace)
|
2014-05-06 18:08:58 +04:00
|
|
|
{
|
2014-05-19 18:53:57 +04:00
|
|
|
if (pHandflow->ControlHandShake & SERIAL_AUTO_TRANSMIT)
|
|
|
|
{
|
2014-07-02 17:59:16 +04:00
|
|
|
CommLog_Print(WLOG_WARN, "SERIAL_AUTO_TRANSMIT not supposed to be implemented by SerCx.sys");
|
2014-05-19 18:53:57 +04:00
|
|
|
}
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
if (pHandflow->ControlHandShake & SERIAL_AUTO_RECEIVE)
|
|
|
|
{
|
2014-07-02 17:59:16 +04:00
|
|
|
CommLog_Print(WLOG_WARN, "SERIAL_AUTO_RECEIVE not supposed to be implemented by SerCx.sys");
|
2014-05-19 18:53:57 +04:00
|
|
|
}
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
if (pHandflow->ControlHandShake & SERIAL_ERROR_CHAR)
|
|
|
|
{
|
2014-07-02 17:59:16 +04:00
|
|
|
CommLog_Print(WLOG_WARN, "SERIAL_ERROR_CHAR not supposed to be implemented by SerCx.sys");
|
2014-05-19 18:53:57 +04:00
|
|
|
}
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
if (pHandflow->ControlHandShake & SERIAL_NULL_STRIPPING)
|
|
|
|
{
|
2014-07-02 17:59:16 +04:00
|
|
|
CommLog_Print(WLOG_WARN, "SERIAL_NULL_STRIPPING not supposed to be implemented by SerCx.sys");
|
2014-05-19 18:53:57 +04:00
|
|
|
}
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
if (pHandflow->ControlHandShake & SERIAL_BREAK_CHAR)
|
|
|
|
{
|
2014-07-02 17:59:16 +04:00
|
|
|
CommLog_Print(WLOG_WARN, "SERIAL_BREAK_CHAR not supposed to be implemented by SerCx.sys");
|
2014-05-19 18:53:57 +04:00
|
|
|
}
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
if (pHandflow->ControlHandShake & SERIAL_XOFF_CONTINUE)
|
|
|
|
{
|
2014-07-02 17:59:16 +04:00
|
|
|
CommLog_Print(WLOG_WARN, "SERIAL_XOFF_CONTINUE not supposed to be implemented by SerCx.sys");
|
2014-05-19 18:53:57 +04:00
|
|
|
}
|
2014-05-06 18:08:58 +04:00
|
|
|
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
2014-05-19 18:53:57 +04:00
|
|
|
result = FALSE;
|
2014-05-06 18:08:58 +04:00
|
|
|
}
|
2014-06-16 21:18:45 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
if (!pSerialSys->set_handflow(pComm, &SerCxHandflow))
|
2014-05-06 18:08:58 +04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL _get_handflow(WINPR_COMM *pComm, SERIAL_HANDFLOW *pHandflow)
|
|
|
|
{
|
2014-05-19 18:53:57 +04:00
|
|
|
BOOL result;
|
2014-06-18 17:58:08 +04:00
|
|
|
SERIAL_DRIVER* pSerialSys = SerialSys_s();
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
result = pSerialSys->get_handflow(pComm, pHandflow);
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-06-16 21:18:45 +04:00
|
|
|
/* filter out unsupported bits by SerCx.sys
|
2014-05-19 18:53:57 +04:00
|
|
|
*
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/hardware/jj680685%28v=vs.85%29.aspx
|
|
|
|
*/
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
pHandflow->ControlHandShake = pHandflow->ControlHandShake & (SERIAL_DTR_CONTROL | SERIAL_DTR_HANDSHAKE | SERIAL_CTS_HANDSHAKE | SERIAL_DSR_HANDSHAKE);
|
|
|
|
pHandflow->FlowReplace = pHandflow->FlowReplace & (SERIAL_RTS_CONTROL | SERIAL_RTS_HANDSHAKE);
|
2014-05-06 18:08:58 +04:00
|
|
|
|
2014-05-19 18:53:57 +04:00
|
|
|
return result;
|
2014-05-06 18:08:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-14 18:29:10 +04:00
|
|
|
/* http://msdn.microsoft.com/en-us/library/windows/hardware/hh439605%28v=vs.85%29.aspx */
|
2014-06-16 21:18:45 +04:00
|
|
|
static const ULONG _SERCX_SYS_SUPPORTED_EV_MASK =
|
2014-05-14 18:29:10 +04:00
|
|
|
SERIAL_EV_RXCHAR |
|
|
|
|
/* SERIAL_EV_RXFLAG | */
|
|
|
|
SERIAL_EV_TXEMPTY |
|
|
|
|
SERIAL_EV_CTS |
|
2014-06-16 21:18:45 +04:00
|
|
|
SERIAL_EV_DSR |
|
2014-05-14 18:29:10 +04:00
|
|
|
SERIAL_EV_RLSD |
|
|
|
|
SERIAL_EV_BREAK |
|
|
|
|
SERIAL_EV_ERR |
|
|
|
|
SERIAL_EV_RING /* |
|
|
|
|
SERIAL_EV_PERR |
|
|
|
|
SERIAL_EV_RX80FULL |
|
|
|
|
SERIAL_EV_EVENT1 |
|
|
|
|
SERIAL_EV_EVENT2*/;
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL _set_wait_mask(WINPR_COMM *pComm, const ULONG *pWaitMask)
|
|
|
|
{
|
|
|
|
ULONG possibleMask;
|
2014-06-18 17:58:08 +04:00
|
|
|
SERIAL_DRIVER* pSerialSys = SerialSys_s();
|
2014-05-14 18:29:10 +04:00
|
|
|
|
|
|
|
possibleMask = *pWaitMask & _SERCX_SYS_SUPPORTED_EV_MASK;
|
|
|
|
|
|
|
|
if (possibleMask != *pWaitMask)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
CommLog_Print(WLOG_WARN, "Not all wait events supported (SerCx.sys), requested events= 0x%08"PRIX32", possible events= 0x%08"PRIX32"", *pWaitMask, possibleMask);
|
2014-05-14 18:29:10 +04:00
|
|
|
|
|
|
|
/* FIXME: shall we really set the possibleMask and return FALSE? */
|
2014-05-23 17:55:44 +04:00
|
|
|
pComm->WaitEventMask = possibleMask;
|
2014-05-14 18:29:10 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NB: All events that are supported by SerCx.sys are supported by Serial.sys*/
|
|
|
|
return pSerialSys->set_wait_mask(pComm, pWaitMask);
|
|
|
|
}
|
|
|
|
|
2014-04-28 21:57:17 +04:00
|
|
|
|
2014-04-25 02:20:48 +04:00
|
|
|
/* specific functions only */
|
2014-06-18 17:58:08 +04:00
|
|
|
static SERIAL_DRIVER _SerCxSys =
|
2014-04-25 02:20:48 +04:00
|
|
|
{
|
2014-06-18 17:58:08 +04:00
|
|
|
.id = SerialDriverSerCxSys,
|
2014-04-29 06:04:09 +04:00
|
|
|
.name = _T("SerCx.sys"),
|
2014-09-16 13:21:01 +04:00
|
|
|
.set_baud_rate = NULL,
|
|
|
|
.get_baud_rate = NULL,
|
|
|
|
.get_properties = NULL,
|
2014-04-29 06:04:09 +04:00
|
|
|
.set_serial_chars = NULL,
|
|
|
|
.get_serial_chars = NULL,
|
2014-04-30 00:25:07 +04:00
|
|
|
.set_line_control = NULL,
|
|
|
|
.get_line_control = NULL,
|
2014-05-06 18:08:58 +04:00
|
|
|
.set_handflow = _set_handflow,
|
|
|
|
.get_handflow = _get_handflow,
|
2014-05-12 19:33:56 +04:00
|
|
|
.set_timeouts = NULL,
|
|
|
|
.get_timeouts = NULL,
|
2014-05-12 22:16:13 +04:00
|
|
|
.set_dtr = NULL,
|
|
|
|
.clear_dtr = NULL,
|
2014-05-12 22:33:33 +04:00
|
|
|
.set_rts = NULL,
|
|
|
|
.clear_rts = NULL,
|
2014-05-13 19:27:51 +04:00
|
|
|
.get_modemstatus = NULL,
|
2014-05-14 18:29:10 +04:00
|
|
|
.set_wait_mask = _set_wait_mask,
|
|
|
|
.get_wait_mask = NULL,
|
|
|
|
.wait_on_mask = NULL,
|
2014-05-14 19:30:29 +04:00
|
|
|
.set_queue_size = NULL,
|
2014-05-14 23:21:31 +04:00
|
|
|
.purge = NULL,
|
2014-05-23 14:27:09 +04:00
|
|
|
.get_commstatus = NULL,
|
|
|
|
.set_break_on = NULL,
|
|
|
|
.set_break_off = NULL,
|
2014-05-23 15:04:43 +04:00
|
|
|
.set_xoff = NULL,
|
|
|
|
.set_xon = NULL,
|
2014-05-28 13:39:10 +04:00
|
|
|
.get_dtrrts = NULL,
|
2014-06-17 17:19:16 +04:00
|
|
|
.config_size = NULL, /* not supported by SerCx.sys */
|
2014-06-17 18:34:20 +04:00
|
|
|
.immediate_char = NULL,
|
2014-06-17 19:49:06 +04:00
|
|
|
.reset_device = NULL, /* not supported by SerCx.sys */
|
2014-04-25 02:20:48 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-18 17:58:08 +04:00
|
|
|
SERIAL_DRIVER* SerCxSys_s()
|
2014-04-25 02:20:48 +04:00
|
|
|
{
|
2014-04-30 00:25:07 +04:00
|
|
|
/* _SerCxSys completed with inherited functions from SerialSys */
|
2014-06-18 17:58:08 +04:00
|
|
|
SERIAL_DRIVER* pSerialSys = SerialSys_s();
|
2014-04-29 06:04:09 +04:00
|
|
|
|
2014-09-16 13:21:01 +04:00
|
|
|
_SerCxSys.set_baud_rate = pSerialSys->set_baud_rate;
|
|
|
|
_SerCxSys.get_baud_rate = pSerialSys->get_baud_rate;
|
|
|
|
|
|
|
|
_SerCxSys.get_properties = pSerialSys->get_properties;
|
|
|
|
|
2014-04-29 06:04:09 +04:00
|
|
|
_SerCxSys.set_serial_chars = pSerialSys->set_serial_chars;
|
|
|
|
_SerCxSys.get_serial_chars = pSerialSys->get_serial_chars;
|
2014-04-30 00:25:07 +04:00
|
|
|
_SerCxSys.set_line_control = pSerialSys->set_line_control;
|
|
|
|
_SerCxSys.get_line_control = pSerialSys->get_line_control;
|
2014-04-25 02:20:48 +04:00
|
|
|
|
2014-05-12 19:33:56 +04:00
|
|
|
_SerCxSys.set_timeouts = pSerialSys->set_timeouts;
|
|
|
|
_SerCxSys.get_timeouts = pSerialSys->get_timeouts;
|
|
|
|
|
2014-05-12 22:16:13 +04:00
|
|
|
_SerCxSys.set_dtr = pSerialSys->set_dtr;
|
|
|
|
_SerCxSys.clear_dtr = pSerialSys->clear_dtr;
|
|
|
|
|
2014-05-12 22:33:33 +04:00
|
|
|
_SerCxSys.set_rts = pSerialSys->set_rts;
|
|
|
|
_SerCxSys.clear_rts = pSerialSys->clear_rts;
|
|
|
|
|
2014-05-13 19:27:51 +04:00
|
|
|
_SerCxSys.get_modemstatus = pSerialSys->get_modemstatus;
|
|
|
|
|
2014-05-14 18:29:10 +04:00
|
|
|
_SerCxSys.set_wait_mask = pSerialSys->set_wait_mask;
|
|
|
|
_SerCxSys.get_wait_mask = pSerialSys->get_wait_mask;
|
|
|
|
_SerCxSys.wait_on_mask = pSerialSys->wait_on_mask;
|
|
|
|
|
2014-05-14 19:30:29 +04:00
|
|
|
_SerCxSys.set_queue_size = pSerialSys->set_queue_size;
|
|
|
|
|
2014-05-14 23:21:31 +04:00
|
|
|
_SerCxSys.purge = pSerialSys->purge;
|
|
|
|
|
2014-05-23 14:27:09 +04:00
|
|
|
_SerCxSys.get_commstatus = pSerialSys->get_commstatus;
|
|
|
|
|
|
|
|
_SerCxSys.set_break_on = pSerialSys->set_break_on;
|
|
|
|
_SerCxSys.set_break_off = pSerialSys->set_break_off;
|
|
|
|
|
2014-05-23 15:04:43 +04:00
|
|
|
|
|
|
|
_SerCxSys.set_xoff = pSerialSys->set_xoff;
|
|
|
|
_SerCxSys.set_xon = pSerialSys->set_xon;
|
|
|
|
|
2014-05-28 13:39:10 +04:00
|
|
|
_SerCxSys.get_dtrrts = pSerialSys->get_dtrrts;
|
|
|
|
|
2014-06-17 18:34:20 +04:00
|
|
|
_SerCxSys.immediate_char = pSerialSys->immediate_char;
|
|
|
|
|
2014-04-25 02:20:48 +04:00
|
|
|
return &_SerCxSys;
|
|
|
|
}
|
2014-04-28 21:57:17 +04:00
|
|
|
|
2014-07-04 18:16:26 +04:00
|
|
|
#endif /* __linux__ */
|