How to implement a tty serial driver for RFC2217 networked serial port access devices?
I'm investigating how to design and write a module for RFC2217 [1] networked serial port access devices. The aim is to present /dev/ttyXXYY devices so that all user-space applications that connect to local serial ports can connect to the remote RFC2217 ports in the same way. The kernel module would act as a RFC2217 client, presenting the local system with serial TTY devices whose endpoints are on a remote network access device, e.g. the Moxa NPort 6650 [2][*]. The driver would need a configuration interface for setting the endpoint(s) for one or more access servers, possibly via sysfs. Because of the underlying TCP network link I'm not at all clear on how to implement it so I am hoping that others may have some insight on how to tackle this, in particular how to handle the network connections since they seem more appropriate for user-space rather than the kernel. For an access device with 16 ports I'd imagine presenting something like /dev/ttyNET${DEV}p${PORT}, e.g: /dev/ttyNET0p0 /dev/ttyNET0p1 /dev/ttyNET0p2 ... /dev/ttyNET0p13 /dev/ttyNET0p14 /dev/ttyNET0p15 and a sysfs control interface something like: /sys/bus/net-serial/drivers/rfc2217/ with nodes: endpoint_add # echo "${IPv4} ${BASE_PORT} 16" > endpoint_add # creates /dev/ttyNET0p0 - p15 endpoint_add # echo "${IPv6} ${BASE_PORT} 8" > endpoint_add # creates /dev/ttyNET1p0 - p8 endpoints # cat endpoints; "0 ${IPv4} ${BASE_PORT} 16", "1 ${IPv6} ${BASE_PORT} 8" endpoint_del # echo 0 > endpoint_del Because RFC2217 is only one flavour of network-attached serial ports my thoughts are to create two modules, the first being a generic "ttynet" module that manages tty creation, configuration, tear-down and network connection when a port is opened, and a specialised rfc2217 module that depends on "ttynet" and knows how to talk to RFC2217 devices. That would provide ready support for other types of networked serial device such as raw (which the generic module should probably do by default). Because some access devices support more than one serial protocol (RS232, RS422, RS485, etc.) I'm wondering how that should be represented in the driver - possibly another parameter passed to "endpoint_add", or an additional per-port setting (since access devices allow per-port setting) ? Thanks in advance. [*] Moxa do provide an out-of-tree driver for the NPort series but it only works in the NPort-specific 'Real COM' mode, not RFC2217 [1] http://tools.ietf.org/html/rfc2217 [2] http://www.moxa.com/product/NPort_6650.htm
On Sat, 02 Aug 2014 12:38:50 +0100, TJ said:
The kernel module would act as a RFC2217 client, presenting the local system with serial TTY devices whose endpoints are on a remote network access device, e.g. the Moxa NPort 6650 [2][*].
Wouldn't a 2217-capable telnet at the other end of a /dev/pts be easier?
For an access device with 16 ports I'd imagine presenting something like /dev/ttyNET${DEV}p${PORT}, e.g:
You might want to look at how bash deals with /dev/{tcp,udp} pseudo-names in redirections... Bash handles several filenames specially when they are used in redirec- tions, as described in the following table: /dev/fd/fd If fd is a valid integer, file descriptor fd is dupli- cated. /dev/stdin File descriptor 0 is duplicated. /dev/stdout File descriptor 1 is duplicated. /dev/stderr File descriptor 2 is duplicated. /dev/tcp/host/port If host is a valid hostname or Internet address, and port is an integer port number or service name, bash attempts to open the corresponding TCP socket. /dev/udp/host/port If host is a valid hostname or Internet address, and port is an integer port number or service name, bash attempts to open the corresponding UDP socket. (at which point you cay use 'stty < /dev/tcp/10.0.0.15/818' or whatever....) (This may require a hacked-up stty command and/or a smarter bash. But that's still easier than doing it in kernelspace)
participants (2)
-
TJ -
Valdis.Kletnieks@vt.edu