Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the worst case of 1-byte requests at 115200 baud. #1

Merged
merged 2 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/driver/EnlyzePortSniffer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// PortSniffer - Monitor the traffic of arbitrary serial or parallel ports
// Copyright 2020 Colin Finck, ENLYZE GmbH <c.finck@enlyze.com>
// Copyright 2020-2021 Colin Finck, ENLYZE GmbH <c.finck@enlyze.com>
//
// SPDX-License-Identifier: MIT
//
Expand All @@ -16,9 +16,15 @@

#define CONTROL_DEVICE_NAME_STRING L"\\Device\\EnlyzePortSniffer"
#define CONTROL_SYMBOLIC_LINK_NAME_STRING L"\\DosDevices\\EnlyzePortSniffer"
#define MAX_LOG_ENTRIES_PER_PORT 32
#define POOL_TAG (ULONG)'nSoP'

// The worst case is a serial port at 115200 baud, which is read via 1-byte requests.
// 115200 baud makes 14400 bytes/second. Considering that the PortSniffer-Tool polls the
// driver in 10 millisecond intervals (100 times/second), we need to buffer up to
// 144 1-byte log entries.
// Choose 160 (divisible by 32) as the upper limit here to be on the safe side.
#define MAX_LOG_ENTRIES_PER_PORT 160


typedef struct _PORTLOG_ENTRY
{
Expand Down
19 changes: 14 additions & 5 deletions src/tool/monitoring.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// PortSniffer - Monitor the traffic of arbitrary serial or parallel ports
// Copyright 2020 Colin Finck, ENLYZE GmbH <c.finck@enlyze.com>
// Copyright 2020-2021 Colin Finck, ENLYZE GmbH <c.finck@enlyze.com>
//
// SPDX-License-Identifier: MIT
//
Expand Down Expand Up @@ -138,7 +138,16 @@ HandleMonitorParameter(
&cbReturned,
NULL))
{
fprintf(stderr, "DeviceIoControl failed for PORTSNIFFER_IOCTL_CONTROL_RESET_PORT_MONITORING, last error is %lu.\n", GetLastError());
if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
fprintf(stderr, "The PortSniffer Driver is not attached to %S!\n", pwszPort);
fprintf(stderr, "Please run this tool using the /attach option.\n");
}
else
{
fprintf(stderr, "DeviceIoControl failed for PORTSNIFFER_IOCTL_CONTROL_RESET_PORT_MONITORING, last error is %lu.\n", GetLastError());
}

goto Cleanup;
}

Expand All @@ -154,8 +163,6 @@ HandleMonitorParameter(
// Fetch new port log entries from our driver until we are terminated.
while (!_bTerminationRequested)
{
Sleep(250);

if (!DeviceIoControl(hPortSniffer,
(DWORD)PORTSNIFFER_IOCTL_CONTROL_POP_PORTLOG_ENTRY,
&PopRequest,
Expand All @@ -167,12 +174,14 @@ HandleMonitorParameter(
{
if (GetLastError() == ERROR_NO_MORE_ITEMS)
{
Sleep(10);
continue;
}
else if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
fprintf(stderr, "The PortSniffer Driver is not attached to %S!\n", pwszPort);
fprintf(stderr, "The PortSniffer Driver is no longer attached to %S!\n", pwszPort);
fprintf(stderr, "Please run this tool using the /attach option.\n");
goto Cleanup;
}
else
{
Expand Down