How to implement a tty serial driver for RFC2217 networked serial port access devices?

TJ linux at iam.tj
Sat Aug 2 07:38:50 EDT 2014


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



More information about the Kernelnewbies mailing list