From 1122b83a299be75fab8ca856a3903c8ce3ee1df0 Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Tue, 20 Aug 2024 11:29:32 -0400 Subject: [PATCH] uart: add modem IOCTLS --- hook/iohook.h | 1 - hooklib/serial.c | 7 +++---- hooklib/uart.c | 31 ++++++++++++++++++++++++++----- hooklib/uart.h | 7 +++++++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/hook/iohook.h b/hook/iohook.h index fdb5d48..0c1ec24 100644 --- a/hook/iohook.h +++ b/hook/iohook.h @@ -35,7 +35,6 @@ struct irp { uint32_t seek_origin; int64_t seek_offset; uint64_t seek_pos; - uint16_t modem_state; }; typedef HRESULT (*iohook_fn_t)(struct irp *irp); diff --git a/hooklib/serial.c b/hooklib/serial.c index 5586bfc..e12bfb6 100644 --- a/hooklib/serial.c +++ b/hooklib/serial.c @@ -745,7 +745,8 @@ static BOOL WINAPI my_GetCommModemStatus(HANDLE fd, DWORD modem_stat) irp.op = IRP_OP_IOCTL; irp.fd = fd; irp.ioctl = IOCTL_SERIAL_GET_MODEMSTATUS; - modem_stat = 0; + irp.read.bytes = (uint8_t *) &modem_stat; + irp.read.nbytes = sizeof(modem_stat); hr = iohook_invoke_next(&irp); @@ -755,7 +756,5 @@ static BOOL WINAPI my_GetCommModemStatus(HANDLE fd, DWORD modem_stat) SetLastError(ERROR_SUCCESS); - modem_stat = irp.modem_state; - return TRUE; -} \ No newline at end of file +} diff --git a/hooklib/uart.c b/hooklib/uart.c index 3ef21f6..fedc576 100644 --- a/hooklib/uart.c +++ b/hooklib/uart.c @@ -241,6 +241,13 @@ static HRESULT uart_handle_ioctl(struct uart *uart, struct irp *irp) case IOCTL_SERIAL_GET_WAIT_MASK: return iobuf_write(&irp->read, &uart->mask, sizeof(uart->mask)); + case IOCTL_SERIAL_GET_MODEM_CONTROL: + return iobuf_write(&irp->read, &uart->modem_control, sizeof(uart->modem_control)); + + case IOCTL_SERIAL_GET_MODEMSTATUS: + ULONG status = (uart->cts_on << 4) | (uart->dsr_on << 5) | (uart->ring_on << 6) | (uart->rlsd_on << 7); + return iobuf_write(&irp->read, &status, sizeof(status)); + case IOCTL_SERIAL_SET_BAUD_RATE: return iobuf_read(&irp->write, &uart->baud, sizeof(uart->baud)); @@ -259,16 +266,30 @@ static HRESULT uart_handle_ioctl(struct uart *uart, struct irp *irp) case IOCTL_SERIAL_SET_WAIT_MASK: return iobuf_read(&irp->write, &uart->mask, sizeof(uart->mask)); + case IOCTL_SERIAL_SET_MODEM_CONTROL: + return iobuf_read(&irp->write, &uart->modem_control, sizeof(uart->modem_control)); + + case IOCTL_SERIAL_CLR_DTR: + uart->dtr_on = false; + return S_OK; + + case IOCTL_SERIAL_CLR_RTS: + uart->rts_on = false; + return S_OK; + + case IOCTL_SERIAL_SET_DTR: + uart->dtr_on = true; + return S_OK; + + case IOCTL_SERIAL_SET_RTS: + uart->rts_on = true; + return S_OK; + /* These can be safely ignored */ case IOCTL_SERIAL_SET_BREAK_ON: case IOCTL_SERIAL_SET_BREAK_OFF: - case IOCTL_SERIAL_CLR_DTR: - case IOCTL_SERIAL_CLR_RTS: - case IOCTL_SERIAL_SET_DTR: - case IOCTL_SERIAL_SET_RTS: case IOCTL_SERIAL_SET_XOFF: case IOCTL_SERIAL_SET_XON: - case IOCTL_SERIAL_PURGE: case IOCTL_SERIAL_SET_QUEUE_SIZE: return S_OK; diff --git a/hooklib/uart.h b/hooklib/uart.h index f136086..9807d94 100644 --- a/hooklib/uart.h +++ b/hooklib/uart.h @@ -25,6 +25,13 @@ struct uart { SERIAL_LINE_CONTROL line; SERIAL_TIMEOUTS timeouts; DWORD mask; + bool cts_on; + bool dsr_on; + bool ring_on; + bool rlsd_on; + bool dtr_on; + bool rts_on; + ULONG modem_control; struct iobuf written; struct iobuf readable; };