Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/willglynn/tcpserial_hook
https://github.com/willglynn/tcpserial_hook
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/willglynn/tcpserial_hook
- Owner: willglynn
- Created: 2024-07-30T03:19:44.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-01T22:48:25.000Z (6 months ago)
- Last Synced: 2024-11-30T02:51:36.510Z (about 2 months ago)
- Language: C
- Size: 3.91 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `tcpserial_hook`
This is a library which can be inserted into a closed-source application for the purpose of monitoring its serial port
activity over TCP/IP. It causes the application to listen for incoming connections (TCP port 7160), to which it
transmits a copy of every byte exchanged over the serial port.Theory of operation
tcpserial_hook.so
intercepts theread()
,write()
, andtcsetattr()
system calls. When inserted into a target process usingLD_PRELOAD
, the target process will calltcpserial_hook.so
instead of the operating system. These three functions all pass through to the operating
system, but with side effects.The preloaded library contains a static initializer which listens on port 7160 and spawns a thread to accept
incoming connections prior to the application'smain()
function. When the application configures a serial
port usingtcsetattr()
, the library remembers its file descriptor, at which point any data exchanged by
futureread()
orwrite()
calls on that file descriptor are broadcast to all connected
clients.If a client's TCP send buffer is filled, the library must choose between a) allocating an unbounded amount of memory,
b) blocking the application, c) discarding data for that client, or d) terminating that connection. The library chooses
to terminate the connection. This alerts the consumer that it fell behind, and the consumer is of course free to
reconnect and try again.This library supports a fixed maximum number of simultaneous clients (8). Additional connections are terminated
immediately. This is intended to provide another bound on resource consumption and prevent an accidental
denial-of-service condition.It is intended for the [Tigo Cloud Connect Advanced (CCA)](https://www.tigoenergy.com/product/cloud-connect-advanced) or
similar, targeting the `meshdcd` process which communicates with a [Tigo Access Point
(TAP)](https://www.tigoenergy.com/product/tigo-access-point) using a serial port.## Installation
Installation requires `root` access. Obtaining `root` access on a Tigo CCA is outside the scope of this document.
Start by downloading the shared library and ensure that the `wrap_mesh.sh` script does not exist:
```console
~ # curl -L --insecure -o /mnt/ffs/lib/tcpserial_hook.so https://github.com/willglynn/tcpserial_hook/releases/download/v1.0.0/tcpserial_hook.so
~ # ls -l /mnt/ffs/mgmtu/bin/wrap_mesh.sh
~ #
```Assuming `ls` did not show an existing `wrap_mesh.sh` script, create one and make it executable:
```console
~ # echo -e '#!/bin/sh\nLD_PRELOAD=/mnt/ffs/lib/tcpserial_hook.so exec /mnt/ffs/mgmtu/bin/meshdcd' > /mnt/ffs/mgmtu/bin/wrap_mesh.sh
~ # chmod +x /mnt/ffs/mgmtu/bin/wrap_mesh.sh
```Finally, restart `meshdcd`:
```console
~ # /mnt/ffs/etc/rc.d/S040_MeshDCD
Shutting down meshdcd from meshdcd launcher
Killing program PID 3088
Shutting down wrap_mesh.sh from meshdcd launcher
Killing watcher PID 2815
Starting Tigo Mesh Data Collection service.
~ #
```You can now connect to the CCA on TCP port 7160 to monitor the serial data.
## Uninstallation
Remove the files and restart `meshdcd`.
```console
~ # rm /mnt/ffs/mgmtu/bin/wrap_mesh.sh /mnt/ffs/lib/tcpserial_hook.so
~ # /mnt/ffs/etc/rc.d/S040_MeshDCD
Shutting down meshdcd from meshdcd launcher
Killing program PID 8158
Shutting down wrap_mesh.sh from meshdcd launcher
Killing watcher PID 7120
Starting Tigo Mesh Data Collection service.
~ #
```