Null modem emulator linux

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

virtual nullmodem driver for linux (kernel module)

pitti98/nullmodem

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This implements a virtual nullmodem driver for linux as a kernel module.

I wrote this when I needed a real virtual nullmodem emulator that could emulate the control lines and handle ioctl() calls for TIOCMIWAIT like a real hardware device.

I found the tty0tty project on sourceforge but it did not do what I needed, so I took it as a basis and started hacking.

I also posted a response on stackoverflow where someone asked for a nullmodem emulator: http://stackoverflow.com/questions/52187/virtual-serial-port-for-linux

When the module is loaded, pairs of virtual COM ports are created that are connected to each other. The name of the devices are /dev/nmpX, where X is the number of the COM port. «nmp» stands for «null modem port».

Two consecutive devices are linked with each other:

/dev/nmp0 /dev/nmp1
/dev/nmp2 /dev/nmp3
etc.

  • line speed emulation Unlike pseudo terminals, this driver emulates serial line speed by using a timer. So if you set the line speed to 9600 baud, the througput will be about 960 cps. The driver takes mismatching configuration of the two ends of the virtual line into account. So if one end is configured for a different baud rate than the other end, each end will not receive any data from the other end. Likewise, if startbits/stopbits/databits don’t match, no data will be received. Charsizes less than 8 are handled by clearing the appropriate upper bits.
  • emulation of control lines
    • Supports TIOCMGET/TIOCMSET. This allows setting and reading the control lines (RTS/DTR etc.) via ioctl(). When changed on one end of the virtual line, it affects the other end.
    • Supports TIOCMIWAIT. With this ioctl a user mode program can perform a blocking wait for control line changes.

    Known problems / limitations:

    • Flow control via XON/XOFF is not implemented.
    • a 4k buffer is allocated for each virtual COM port (when opened). This may be a bit large.
    • The timer that is used to emulate the line speed fires 20 times per second, even when no port is open (although it does not do much apart from checking every port whether it is open). This may put an unnecessary load on the system. However, I have found this not to be a problem.

    Just unpack the tarball somewhere and run make in the nullmodem directory. You will need to have the «kernel-headers» package installed to compile the module. I included a small shell script, called «reload», that (re-)loads the module and sets permissions of the /dev/nmp* devices.

    There are a few defines that can be tweaked:

    • NULLMODEM_PAIRS: This defines how many virtual com port pairs will be created when the module is loaded. Currently, there will be 4 pairs created (8 devices).
    • TIMER_INTERVAL: This determines the interval at which the timer fires. If you slow the timer down, more data will need to be transfered at each timer tick. Make sure the buffers are large enough. The timer rate and the highest baud rate determine the needed buffer size. Currently, the timer is set to 20Hz, i.e. every 50 milliseconds.
    • TX_BUF_SIZE: This determines the size of the send buffers for the serial ports. These get filled by writes to the port and are drained by the timer. The timer also uses a buffer of this size to transfer data from one end of the virtual line to the other.
    • NULLMODEM_MAJOR: this is the major device number. This is from the experimental range. Maybe someday it will be an officially assigned number 🙂

    In the makefile, you can turn on debug mode by un-commenting the «DEBUG = y» line. The driver then prints diagnostic messages to the kernel log. You can watch this with a «tail -f /var/log/kern.log». Some messages that produce a high volume of logging output are commented out in the code. You can uncomment them if you want.

    This was my first attempt at kernel hacking. Likewise I did not do any extensive stability testing. If it fails for you — bad luck 🙂 Well, you can contact me, and I might try and find a fix. But, I wrote this quite some time ago, and I don’t remember everything about writing kernel drivers, or which features this driver may be lacking. I apologize if the code style does not conform to any linux kernel coding rules.

    If anyone of the kernel staff wants to include this in the kernel distribution as an experimental driver, please go ahead. Maybe this thing will come to life and/or find a new maintainer.

    That said, may it be useful to you!

    Источник

    Saved searches

    Use saved searches to filter your results more quickly

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    License

    lcgamboa/tty0tty

    This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

    Name already in use

    A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

    Sign In Required

    Please sign in to use Codespaces.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    linux null modem emulator v1.4

    This is the tty0tty directory tree:

    • module : linux kernel module null-modem
    • pts : null-modem using ptys (without handshake lines)
    • debian : debian package build tree
    • ssniffer : simple serial sniffer using tty0tty driver ports

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

    The module is tested in kernels from 3.10.2 to 5.3.15 (debian)

    When loaded, create 8 ttys interconnected:

    /dev/tnt0 /dev/tnt1 /dev/tnt2 /dev/tnt3 /dev/tnt4 /dev/tnt5 /dev/tnt6 /dev/tnt7 
    TX -> RX RX CTS CTS DSR DTR -> CD 

    This is a simple serial sniffer program supporting handshake lines (using tty0tty module) with two working modes. In normal mode the data is displayed on the console as in the figure below. In ysplitter mode a third virtual port is connected and has access to the data sent by the device port and by the control application.

    PICsimLab

    You can get precompiled tty0tty dkms module or ssniffer packages from the piduino.org repository for Debian or Ubuntu :

    wget -O- http://www.piduino.org/piduino-key.asc | sudo apt-key add - sudo add-apt-repository 'deb http://apt.piduino.org buster piduino' sudo apt update 

    The repository added in the add-apt-repository command is for the Debian Buster distribution, but you can also choose bullseye, bionic, focal or jammy.
    These repositories provide packages for the amd64, armhf and arm64 architectures.

    If the add-apt-repository command fails, install the software-properties-common package like this:

    sudo apt install software-properties-common 
    sudo apt install tty0tty-dkms 

    Источник

    Setup Virtual Serial Ports Using tty0tty in Linux

    Before starting off with this tutorial, let’s get on with a little bit of background on serial communication, null modems, and virtual ports.

    A serial port (COM port) is an asynchronous port on the computer used to connect a serial device and capable of transmitting data one bit at a time or serially. Most serial ports on computers conform to the RS-232C or RS-422 standards. A serial port is a physical interface for communicating digital data between a DTE (Data Terminal Equipment) -usually your computer and a DCE (Data Communication Equipment) – your modem or another serial device. A standard RS-232 cable is used to connect a DCE device to a DTC device via their serial ports.

    You can’t always expect to pair up DTE and DCE equipment. The devices can be configured as either DTE or DCE. The DTE interface can be used by both your PC and the attached serial device. However, the DTE interface is designed to work with a DCE device. If you want to connect two DTE devices together, a special type of serial cable is required called a “null modem” cable. A null modem cable makes the other end of the PC or device’s DTE interface look like a DCE interface.

    Null modems cables are commonly used for data transfer between computers or two software packages running on the same computer. For example, if you are using a single computer with two serial ports, you can assign the first serial port to one software and the second serial port to the other software. Connecting a physical null modem cable between the serial ports would then allow the two programs to communicate with each other. Although this works just fine, the null modem cable makes the computer more susceptible to RFI because of the physical cable looped between two serial ports.

    A virtual serial port allows you to emulate a physical serial port and thus removes the necessity of bulky cable and physical communication interfaces. Such virtual ports allow your software packages to communicate using the computer’s internal memory. A special type of software that combines two virtual serial ports together and allows data to pass between them is known as a null modem emulator.

    Let’s move on to our topic now. The Linux null modem emulator (tty0tty) is a kernel-module virtual serial port driver for Linux. This creates virtual tty ports pairs and you can use any pair to establish communication between two legacy serial applications.

    1. Download the tty0tty package from one of these sources:
      1.1 http://sourceforge.net/projects/tty0tty/files/
      1.2 clone the repo https://github.com/freemed/tty0tty
    2. Extract it
      2.1 tar xf tty0tty-1.2.tgz
    3. Build the kernel module from provided source
      3.1 cd tty0tty-1.2/module
      3.2 make
    4. Copy the new kernel module into the kernel modules directory
      4.1 sudo cp tty0tty.ko /lib/modules/$( uname -r)/kernel/drivers/misc/
    5. Load the module
      5.1 sudo depmod
      5.2 sudo modprobe tty0tty
      5.3 You should see new serial port/libs in /dev/ ( ls /dev/tnt* )
    6. Give appropriate permissions to the new serial ports
      6.1 sudo chmod 666 /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.

    Edit the file /etc/modules (Debian) or /etc/modules.conf 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 and repeat the process.

    Источник

    Читайте также:  Transferring windows files to linux
Оцените статью
Adblock
detector