Use tty to pass serial data - communication between host & guest - serial-port

I'm using QEMU and here is my problem : I want to send basic data from host to guest.
I first tried using virtio-serial, but I can't modify my guest kernel (2.6.32) => virtio-console wasn't made to support the virtio-serial communication.
I can't use USB nor TCP:IP... Yes it's painful.
I thought about using the TTY on my guest, then connected to my host using chardevs :
qemu-system-i386 image.raw -chardev socket,path=mysock,server,nowait,id=sok -serial pty -serial chardev:sok -nographic
That works almost as intended... Problem, the data isn't sent to the guest through my socket until I enter a '\r' (new line), which corresponds to a 0xA in hexa. And some of my data can take this value !
Is there a way to configure a tty so it doesn't recognize some characters as options ? Or better : a simple way to send data host <=> guest

Related

Qemu connecting to specific guest UART device

I emulate the firmware of a embedded device with qemu-system-arm. The output of the console is working fine by appending "console=ttyAMA0" to the kernel. On the guest there is a binary which opens another serial port for communication (bi-directional) on /dev/ttyGS0 and listens on that port. Now I need to connect to this port from the host, to send commands to the binary and receive the output.
I already tried different things like creating character devices and pseudo ttys, but I don't know how to define the serial device for the guest.
Is there a way to do this?
Thanks in advance.
If you pass multiple -serial options to QEMU they will be interpreted as defining what you want to do for UARTs 0, 1, 2, etc. So for example "-serial stdio -serial tcp::4444,server" will send UART 0 to your terminal and connect UART 1 to a TCP server on port 4444 which you can then connect to with netcat or similar utility. (You can connect serial output to a lot of different backends, not just stdio or TCP: check the QEMU documentation.)
(NB: this relies on your board model actually creating multiple UARTs and wiring them up to the command line options correctly, of course.)

socat to log serial port data

I want to log and display a stream of data arriving at a serial port in hex with timestamps and all non printable characters (particularly any XON XOFF characters). don't need to transmit anything on the Tx port, it is not connected.
Been trying to use stty to set port parameters and socat to log but having trouble.
using /dev/null socat just exits without any doing any thing, using -u and /dev/null as second address doesn't show or log anything, using a PTY as second address works for a while but then hangs - I guess the PTY fills up and block with nothing reading it.
Thanks for any help.

How to check if a device is using RS232 or RS422?

Suppose we have a device which can operate on both RS232 and RS422 protocols. we know which serial port is connected to the device, lets say /dev/ttyS4.
In Linux environment using setserial, dmesg and proc file-system (following commands) helps to identify the serial ports and some hardware/software configurations of them but not much about the device connected to them. (am I missing something here?)
dmesg | grep tty
cat /proc/tty/driver/serial
setserial -a /dev/ttyS[0-4]
My question being, Is there a good way in which we can point out exactly which protocol the device is using?

convert TCP/IP to Address name on LAN network

I wonder if I can use TCP connection protocol or something similar to it to convert IP to Address name
ex:
192.168.1.10:8080 //convert this ip to for example >>
my.localpc.com // or thomething looks like this
so Where I can start from
I like if suggestions related to these lang.s (C# , Python , C++ , MATLAB)
here is the story
"..
I was building an ROV for a competition and I used TCP IP to transfer date from PC to Raspberry PI but the IP always changes whatever I use fixed IP sometimes I have to change the TCP port then I'll change the port on the client program as well , so I asked myself if there is a way to call the ROV like http\myROV.com .. instead of 192.168.1.5:8080 .. which may change on several situations "
Thank you
Anything that can access normal sockets functions directly should be able to use gethostbyaddr or gethostinfo.

how to write a program to report the local IP address such as 192.168.1.102?

since my Linksys router doesn't assign a fixed local IP to the computers (PC and Mac and Linux), i'd like to write a script so that every minute, the computers will update to each other so that
http://localhost/list.html
on each machine will contain a list of names of all PC and Mac and a link to their apache server (pointing to http://192.168.1.102, etc)
it looks like a way to find out the local IP address is by ipconfig on PC, and ifconfig on the Mac and Linux, and to do it programmatically, it will be gethostbyname().
But I tried on Ruby, that
irb(main):001:0> require 'socket'
=> true
irb(main):002:0> p Socket::gethostbyname("localhost")
["Core2Duo", [], 2, "\177\000\000\001"]
irb(main):005:0> p Socket::gethostbyname("core2duo")
["Core2Duo", [], 2, "\300\250\001g"]
=> nil
and ipconfig actually shows
IPv4 Address. . . . . . . . . . . : 192.168.1.103
so is this the right way to do it? I can hack it by executing "ipconfig" in Ruby and use regular expression to get the result, but would be nice to do it using a more standard way.
Socket::getaddrinfo might be more of what you're looking for:
Socket::getaddrinfo('localhost', 'http')
[["AF_INET", 80, "localhost", "127.0.0.1", ...]]
Socket::getaddrinfo('core2duo', 'http')
[["AF_INET", 80, "Core2Duo", "192.168.1.103", ...]]
Or, you might just try:
Socket::getaddrinfo('core2duo', 'http')[0][3]
"192.168.1.103"
You can do this in Java using:
Socket s = new Socket();
s.getLocalSocketAddress();
If you run Bonjour on your Windows systems and avahi on your Linux systems, you can do away with the need to determine each system's IP address. You can then simply address each system using "hostname.local". More info here.
Why not just turn off DHCP for those machines and assign them fixed IP addresses?
Edit in response to comments: At least as-of three years or so ago (last time I bought a router), Linksys routers allowed you to set the bottom IP address for the built-in DHCP server. Then, you go into the individual machines' network setup, disable DHCP, and assign physical addresses. For example, on my home network the router is 192.168.1.1, the Terastation is 1.2, the printer is 1.3, my Linux box is 1.99, and the router is configured to give out 1.100 and above.
The problem in the Ruby script might be that there is no DNS name resolution on your network, this is often hidden if you usually share stuff between computers with SMB/CIFS because that has it's own name discovery protocol.
If you are going to be broadcasting datagrams with the name/ip info in, then you don't really need a PC to know its own IP address. Just send the datagram containing its name, then use recvfrom() - or equivalents - to catch it at the other PCs. That way the receivers can extract the sender's IP address directly via the recvfrom() function.
As a bonus, that should work where the sending PC has more than one network adapter.

Resources