Code Monkey home page Code Monkey logo

tty0tty's Introduction

tty0tty - linux null modem emulator v1.2

The tty0tty directory tree is divided in:

module - linux kernel module null-modem
pts - null-modem using ptys (without handshake lines)

Null modem pts (unix98):

When run connect two pseudo-ttys and show the connection names:

(/dev/pts/1) <=> (/dev/pts/2)

the connection is:

TX -> RX
RX <- TX

Module:

The module is tested in kernel 3.10.2 (debian)

When loaded, create 8 ttys interconnected:

/dev/tnt0 <=> /dev/tnt1
/dev/tnt2 <=> /dev/tnt3
/dev/tnt4 <=> /dev/tnt5
/dev/tnt6 <=> /dev/tnt7

the connection is:

TX -> RX
RX <- TX
RTS -> CTS
CTS <- RTS
DSR <- DTR
CD <- DTR
DTR -> DSR
DTR -> CD

Requirements:

For building the module kernel-headers or kernel source are necessary.

Installation:

Download the tty0tty package from one of these sources: Clone the repo https://github.com/freemed/tty0tty

git clone https://github.com/freemed/tty0tty

Build the kernel module from provided source

cd tty0tty-1.2/module
make

Install the new kernel module into the kernel modules directory

sudo make modules_install

NOTE: if module signing is enabled, in order for depmop to complete, you may need to create file certs/x509.genkey in the kernel modules include directory and generate file signing_key.pem using openssl, guides are available online.

Appropriate permissions are provided thanks to a udev rule located under:

/etc/udev/rules.d/50-tty0tty.rules

NOTE: you need to add yourself to the dialout group (and do a full relog), with:

sudo usermod -a -G dialout ${USER}

Load the module

sudo udevadm control --reload-rules
sudo depmod
sudo modprobe tty0tty

You should see new serial ports in /dev/ (ls /dev/tnt*) You can now access the serial ports as /dev/tnt0 (1,2,3,4 etc) Note that the consecutive ports are interconnected. For example, /dev/tnt0 and /dev/tnt1 are connected as if using a direct cable.

Persisting across boot:

edit the file /etc/modules (Debian) or /etc/modules.conf

nano /etc/modules

and add the following line:

tty0tty

Note that this method will not make the module persist over kernel updates so if you ever update your kernel, make sure you build tty0tty again repeat the process.

Debian package

In order to build the dkms Debian package

sudo apt-get update && sudo apt-get install -y dh-make dkms build-essential
debuild -uc -us

Contact

For e-mail suggestions : [email protected]

tty0tty's People

Contributors

altf02 avatar amateomi avatar avasygn avatar carpie avatar erickellerek1 avatar fairfieldt avatar jbuchbinder avatar jschwartzenberg avatar klogg avatar navidsav avatar reallyniceguy avatar stappersg avatar tian2992 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tty0tty's Issues

tty_port_destroy was added in 3.8.1.

The following in tty0tty.c is wrong. It should be 3.8.

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
tty_port_destroy(&tport[i]);
#endif

Also, why isn't this function being called if tty_register_driver fails? The tty_port_destroy comment in tty_port.c is:

  • When a port was initialized using tty_port_init, one has to destroy the
  • port by this function. Either indirectly by using tty_port refcounting
  • (tty_port_put) or directly if refcounting is not used.

CUSE build of tty0tty

Sorry if this is the wrong way to go about this, but is there any plans / chance for a CUSE module as opposed to a "standard" kernel module?

Udev rules

Hi,

i was success to create ebuild, install it and do some simple tests on my Funtoo with 4.9.18 kernel, then you can update the README about tested kernel versions.

For manage access rights i use simple udev rule in /lib/udev/rules.d/10-tty0tty.rules:

# set tty0tty devices permission
KERNEL=="tnt*" SUBSYSTEM=="tty", MODE="0660", GROUP="uucp"

IMO, you can describe to use udev rules, instead manually changing the the device files rights.

tiocmiwait ioctl is broken

The TIOCMIWAIT ioctl is dangerously broken. Presently, it will oops when issued, since the wait queue it uses isn't initialized, but even if that were fixed, it would never return (unless interrupted), since the places that are supposed to trigger the wait queue never actually wake it up!

I'll be around with a patch set to fix.

Ubuntu /module/make error

Hello,

I followed the steps exactly for installation.
/pts/make works perfectly fine.

But /module/make throws the following error.
error: initialization of ‘int (*)(struct tty_struct )’ from incompatible pointer type ‘unsigned int ()(struct tty_struct *)’ [-Werror=incompatible-pointer-types]
603 | .write_room = tty0tty_write_room,
| ^~~~~~~~~~~~~~~~~~

I have ugraded the Kernal and build and also tried re installing them but the error remains the same
Screenshot from 2021-11-17 15-23-16

modprobe: ERROR: could not insert 'tty0tty': Device or resource busy

I am also getting same issues, below is the traceback, could you please check and tell where is the issue ?

===================================================================
waageesh@waageesh-Aspire-A715-75G:~/Downloads/Softwares/tty0tty$ hostnamectl
Static hostname: waageesh-Aspire-A715-75G
Icon name: computer-laptop
Chassis: laptop
Machine ID: 7a93dcb479364111a24c53faca24ad60
Boot ID: f50dc5d4059f49ca9bcabbf3e677ea32
Operating System: Ubuntu 20.04.2 LTS
Kernel: Linux 5.8.0-48-generic
Architecture: x86-64

===================================================================

image

image

Installation steps on fedora 27

Thank you for this works. Please find below the steps I followed to install that on Fedora 27:

su -c 'dnf install kernel-devel'
sudo dnf install elfutils-libelf-devel
git clone https://github.com/freemed/tty0tty
cd tty0tty/module
make
(root) cp tty0tty.ko /lib/modules/$(uname -r)/kernel/drivers/misc/
(root) depmod
(root) modprobe tty0tty
(root) chmod 666 /dev/tnt*
ls -la /dev/tnt*

Fedora documentation to know more about requirements to build kernel modules: https://fedoraproject.org/wiki/Building_a_custom_kernel#Building_Only_Kernel_Modules_.28Out_Of_Tree_Modules.29

won't compile

scottbeebiwan@lmsbw ~/tty0tty-1.2/module $ make
make -C /lib/modules/4.13.0-43-generic/build M=/home/scottbeebiwan/tty0tty-1.2/module modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-43-generic'
  CC [M]  /home/scottbeebiwan/tty0tty-1.2/module/tty0tty.o
/home/scottbeebiwan/tty0tty-1.2/module/tty0tty.c: In function ‘tty0tty_ioctl_tiocmiwait’:
/home/scottbeebiwan/tty0tty-1.2/module/tty0tty.c:524:8: error: implicit declaration of function ‘signal_pending’ [-Werror=implicit-function-declaration]
    if (signal_pending(current))
        ^
cc1: some warnings being treated as errors
scripts/Makefile.build:323: recipe for target '/home/scottbeebiwan/tty0tty-1.2/module/tty0tty.o' failed
make[2]: *** [/home/scottbeebiwan/tty0tty-1.2/module/tty0tty.o] Error 1
Makefile:1550: recipe for target '_module_/home/scottbeebiwan/tty0tty-1.2/module' failed
make[1]: *** [_module_/home/scottbeebiwan/tty0tty-1.2/module] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-43-generic'
Makefile:26: recipe for target 'default' failed
make: *** [default] Error 2

Not working on Linux kernel 5.12.4-arch1-2

ENOTTY received on Linux kernel 5.12.4-arch1-2

openat(AT_FDCWD, "/dev/tnt1", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_CLOEXEC) = 10
flock(10, LOCK_EX|LOCK_NB) = 0
ioctl(10, TIOCEXCL) = 0
ioctl(10, TCGETS, {B38400 -opost -isig -icanon -echo ...}) = 0
ioctl(10, TIOCMGET, [0]) = 0
ioctl(10, TCGETX, 0x55a071c56090) = -1 ENOTTY (Inappropriate ioctl for device)
close(10) = 0

error: initialization of ‘void (*)(struct tty_struct *, const struct ktermios *)’

Kernel: 6.2.0-25-generic x86_64
gcc: (Ubuntu 12.3.0-1ubuntu1~23.04) 12.3.0

After cloning, building module fails:

git clone https://github.com/freemed/tty0tty.git
cd tty0tty/module/
make
. . . 
tty0tty.c:608:24: error: initialization of ‘void (*)(struct tty_struct *, const struct ktermios *)’ from incompatible pointer type ‘void (*)(struct tty_struct *, struct ktermios *)’ [-Werror=incompatible-pointer-types]
  608 |         .set_termios = tty0tty_set_termios,

Changing line 291 from:

struct ktermios *old_termios)

to

const struct ktermios *old_termios)

resolved the error.

error
errorfixed

modprobe: ERROR: could not insert 'tty0tty': Device or resource busy

I can't run the emulator under 4.15.0-32-generic in Ubuntu 18.04. Here's what I tried:

cd modules
make
sudo cp tty0tty.ko /lib/modules/$(uname -r)/kernel/drivers/misc/
sudo depmod
sudo modprobe tty0tty # this fails with "modprobe: ERROR: could not insert 'tty0tty': Device or resource busy"

and there are no tnt* devices under /dev/.

This used to work under 4.15.0-29-generic, but not under 4.15.0-30-generic or 4.15.0-32-generic.

Could you please help me with this?

How to throttle writes according to input queue size of other paired port

I have a scenario where the application connected to the other paired port can only read data at a certain rate (because it is passing it on to another slow hardware device). So I want to limit the number of bytes that can be written in one port, to ensure the other paired port's input data queue gets no bigger than, say, 64 bytes. So I want to modify tty0tty_write_room() function in the tty0tty module, so that it returns eg [64 – the number of bytes in the other paired port's input queue].

I'm trying to figure out how to get the number of bytes in the other paired port's input queue. It looks as though tty_insert_flip_string() is the way to write bytes into the other paired port's input queue. But I can't see a function that will give me a count of bytes in the other paired port's input queue. Do you have any advice on this?

Back/forward compatibility issues

Latest commit tested for newer and older (w.r.t. KERNEL_VERSION(5, 14, 0)) versions and found back/forward compatibility issues for 4 lines below:

After patching lines as below, working older and newer kernel versions.

  1. This is a back compatibility issue

=> Now:

tty0tty_tty_driver = tty_alloc_driver(2 * pairs, 0);

=> Patch for back compatiblity;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0)
	tty0tty_tty_driver = tty_alloc_driver(2 * pairs, 0);
#else
	tty0tty_tty_driver = alloc_tty_driver(2*pairs);
#endif
  1. This is a back compatibility issue

=> Now:

tty_driver_kref_put(tty0tty_tty_driver);

=> Patch for back compatiblity;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0)
	tty_driver_kref_put(tty0tty_tty_driver);
#else
	put_tty_driver(tty0tty_tty_driver);
#endif	

3.This is a back compatibility issue, but this is also not working for newer versions ('tty0tty_write' could return negative value, but assumed that it should return non-negative value)

=> Now:

int retval = 0;

=> Patch for back compatiblity & for newer ( > KERNEL_VERSION(5, 14, 0)) kernel versions,

int retval = -EINVAL;
  1. This is a back compatibility issue, ('tty0tty_write_room' function now returns (for this line) non-negative for older versions, but should return non-negative for newer kernels, and negative for older versions.)

=> Now:

	int room = 0;

	if (!tty0tty)
		return -ENODEV;

=> Patch for older & newer ( > KERNEL_VERSION(5, 14, 0)) kernel versions,

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 14, 0)
	int room = -EINVAL;
#else
	int room = 0;
#endif	

	if (!tty0tty) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 14, 0)
            room = -ENODEV
#endif
            return room;
        }

Resource temporarily unavailable

Hi,

I am using module with QSerialPort at Qt 5.12 on Manjaro.

After open, there is no error. But after write(), QSerialPort returns Resource temporarily unavailable error, and closes.

I am opening /dev/tnt0 and there is no opened on the other side. I need to write without connection. Trying to implement a virtual electronics device. There is a gui which tries to connect with timer on the other side.

After some search, Resource temporarily unavailable is related with EAGAIN, I think. But I couldn't find at module c file. Specially write function.

I tried with kernels; 5.10, 5.15, 5.19.

At some trials my virtual device and gui connected. But not all the times.

How can I fix this error ?

Edit1;

  • Complete the question.
  • Added tried kernel versions.

[Solved] tty0tty error on Linux Mint 19.3

Hi,
On the last Linux Mint 19.3 with Kernel 5.0.0-37, it is impossible to install tty0tty.
I get this error : modprobe: ERROR: could not insert 'tty0tty': Device or resource busy

Please help me because without tty0tty, I can't make my educational project with students. I'm a radioamateur and I really need it for Doppler correction with my radio YAESU FT-847.

tty0tty is a part of a very complex software bundle since many years to enable the lack of my radio to be controlled in TX and RX on same frequencies range for ISS communications. I really really need it.

Have a look at my website : https://f4bpp.com/articles.php?lng=en&pg=55&tconfig=0

Thanks for your help.

David.

Error Compiling

Good day to you

I am trying to compile tty0tty on a BeagleBone Black

I am experiencing the following problem when trying to compile
Could you please assist?
Thank you in advance
Anton
root@arm:/tty0tty/tty0tty-1.2/module# make
make -C /lib/modules/4.4.84-ti-r120/build M=/root/tty0tty/tty0tty-1.2/module modules
make[1]: *** /lib/modules/4.4.84-ti-r120/build: No such file or directory. Stop.
Makefile:26: recipe for target 'default' failed
make: *** [default] Error 2
root@arm:
/tty0tty/tty0tty-1.2/module# cd tty0tty-1.2/module

Second attempt

root@arm:/tty0tty-1.2/module# make
make -C /lib/modules/4.4.84-ti-r120/build M=/root/tty0tty-1.2/module modules
make[1]: *** /lib/modules/4.4.84-ti-r120/build: No such file or directory. Stop.
Makefile:26: recipe for target 'default' failed
make: *** [default] Error 2
root@arm:
/tty0tty-1.2/module#

Device or resource busy

Hi,
I have follow all installation step without problems, but at the moment of load the module on kernel I receive this error:

modprobe: ERROR: could not insert 'tty0tty': Device or resource busy

I have found another user that have test the same issue nvidia forum but the same solution doesn't work for me! I have try many other minor number but the problem remains.
Some suggestions?

Thanks

[patch] fix for Linux kernels >= 6.6.

The code needs to be updated for Linux >= 6.6:

Here is a patch that adds support for Linux >= 6.6 (needs to have the patch for Linux >= 6.1 also be added separately):

linux-6.6-fixup.patch.txt:

diff -rU1 tty0tty.linux-6.1-fixed/module/tty0tty.c tty0tty/module/tty0tty.c
--- tty0tty.linux-6.1-fixed/module/tty0tty.c	2024-01-11 20:13:27.739146823 +0100
+++ tty0tty/module/tty0tty.c	2024-01-11 20:14:35.892478188 +0100
@@ -212,4 +212,9 @@
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,6,0)
+static ssize_t tty0tty_write(struct tty_struct *tty, const unsigned char *buffer,
+			 size_t count)
+#else
 static int tty0tty_write(struct tty_struct *tty, const unsigned char *buffer,
 			 int count)
+#endif
 {

(Authorship goes to @ozz from Arch User Repository.)

linux-6.1-fixup.patch.txt:

diff -rU1 tty0tty.org/module/tty0tty.c tty0tty/module/tty0tty.c
--- tty0tty.org/module/tty0tty.c	2024-01-11 20:08:54.922488036 +0100
+++ tty0tty/module/tty0tty.c	2024-01-11 20:10:36.829151760 +0100
@@ -290,2 +290,5 @@
 static void tty0tty_set_termios(struct tty_struct *tty,
+				#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,1,0)
+					const
+				#endif
 				struct ktermios *old_termios)

(Note that tabulars are used!, copy & paste might transform them to whitespace which will break applying the patches.)

Regards!

Compile error [-Werror=incompatible-pointer-types]

module/tty0tty.c:610:18: erreur: initialisation de « ssize_t (*)(struct tty_struct *, const u8 *, size_t) » {alias « long int (*)(struct 
tty_struct *, const unsigned char *, long unsigned int) »} depuis le type pointeur « int (*)(struct tty_struct *, const unsigned 
char *, int) » qui est incompatible [-Werror=incompatible-pointer-types]
  610 |         .write = tty0tty_write,
      |                  ^~~~~~~~~~~~~

I got this error when doing make in /module/

write error: Invalid argument

Hi,
I installed the tool and it seemed to work.
I don't know what happened, but suddenly I have following problem:

$ sudo depmod
$ sudo modprobe tty0tty
$ ls /dev/tnt*
/dev/tnt0  /dev/tnt2  /dev/tnt4  /dev/tnt6
/dev/tnt1  /dev/tnt3  /dev/tnt5  /dev/tnt7
$ sudo chmod 666 /dev/tnt*
$ echo test > /dev/tnt0
bash: echo: write error: Invalid argument

This error appears when I try to write in the terminal, or open normally. After the error, the port closes. Writing to a physical com port works without problems.
What is wrong?
Best,
Jan

Error when compling.

Thank you for this code, I've been using it for about a year, however, when building the module for my current kernel, I met with fail.
system: 4.11.7-1-ARCH #1 SMP PREEMPT Sat Jun 24 22:22:46 CDT 2017 x86_64 GNU/Linux
Error:
tty0tty-1.2/module/tty0tty.c:524:8: error: implicit declaration of function ‘signal_pending’; did you mean ‘timer_pending’? [-Werror=implicit-function-declaration]
if (signal_pending(current))
^~~~~~~~~~~~~~
timer_pending
cc1: some warnings being treated as errors

After a solid two minutes of effort, the fix:
Add to includes in tty0tty.c:
#include <linux/sched/signal.h>

Thank you.

make Error

LSB Version: 1.4
Distributor ID: Arch
Description: Arch Linux
Release: rolling
Codename: n/a

make -C /lib/modules/5.13.9-arch1-1/build M=/home/andy/Documents/makedeb/tty0tty-1.3/module modules
make[1]: Entering directory '/usr/lib/modules/5.13.9-arch1-1/build'
CC [M] /home/andy/Documents/makedeb/tty0tty-1.3/module/tty0tty.o
/home/andy/Documents/makedeb/tty0tty-1.3/module/tty0tty.c: In function ‘tty0tty_ioctl_tcsets’:
/home/andy/Documents/makedeb/tty0tty-1.3/module/tty0tty.c:646:22: error: implicit declaration of function ‘tty_check_change’ [-Werror=implicit-function-declaration]
646 | int retval = tty_check_change(tty);
| ^~~~~~~~~~~~~~~~
/home/andy/Documents/makedeb/tty0tty-1.3/module/tty0tty.c:671:32: error: implicit declaration of function ‘tty_termios_input_baud_rate’; did you mean ‘tty_termios_encode_baud_rate’? [-Werror=implicit-function-declaration]
671 | tmp_termios.c_ispeed = tty_termios_input_baud_rate(&tmp_termios);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
| tty_termios_encode_baud_rate
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:273: /home/andy/Documents/makedeb/tty0tty-1.3/module/tty0tty.o] Error 1
make[1]: *** [Makefile:1853: /home/andy/Documents/makedeb/tty0tty-1.3/module] Error 2
make[1]: Leaving directory '/usr/lib/modules/5.13.9-arch1-1/build'
make: *** [Makefile:29: default] Error 2

tty0tty failed after update to Linux 6.1

After Arch Linux got an update to Linux 6.1.1, tty0tty does not compile anymore.

make[1]: Entering directory '/home/user/work/src/tty0tty-/module'
make -C /lib/modules/6.1.1-arch1-1/build M=/home/user/work/src/tty0tty-/module modules
make[2]: Entering directory '/usr/lib/modules/6.1.1-arch1-1/build'
  CC [M]  /home/user/work/src/tty0tty-/module/tty0tty.o
/home/user/work/src/tty0tty-/module/tty0tty.c:608:24: error: initialization of ‘void (*)(struct tty_struct *, const struct ktermios *)’ from incompatible pointer type ‘void (*)(struct tty_struct *, struct ktermios *)’ [-Werror=incompatible-pointer-types]
  608 |         .set_termios = tty0tty_set_termios,
      |                        ^~~~~~~~~~~~~~~~~~~
/home/user/work/src/tty0tty-/module/tty0tty.c:608:24: note: (near initialization for ‘serial_ops.set_termios’)
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:250: /home/user/work/src/tty0tty-/module/tty0tty.o] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.