[libnfc] pn532_net driver

124 views
Skip to first unread message

Jiapeng Li

unread,
Dec 26, 2013, 6:23:40 AM12/26/13
to nfc-too...@googlegroups.com
I wrote a pn532_net driver for libnfc. https://github.com/JiapengLi/libnfc/commits/net

This driver is aimed to use the libnfc with devices like RPi or OpenWrt without porting or cross compile it.
As we know that device like RPi and OpenWrt has uart, LAN even wifi. 
When playing with RPi or OpenWrt devices, install libnfc library into them maybe not a good choice for sometimes.
When developing, coross compile is needed, and once you need a PC client to communicate with these devices, 
then the work is more boring, you need to make a protocol to control/communicate.

Based on this reasons, i wrote a net driver for libnfc, with this pn532_net, when use libnfc with RPi or OpenWrt, 
we only need a ser2net http://ser2net.sourceforge.net/ program, through it, we can connect to a serial port from a network connection. 
Then we get a pn532_net device, users can develop applications depends on libnfc with a pn532_net driver.
This way is more convenient for the devices which have both uart and net interface.

uart communication is much like to net than i2c and spi, so development is easy. 
This way may also be applicable to i2c/spi driver devices, but a i2c_to_net or spi_to_net program(with fame analyse function) is needed.

How about adding this pn532_net driver to libnfc? 

I hope i have described the function of pn532_net clearly. 

I've tested this driver under both windows and linux simply, all are workable.

BR.
Jiapeng


Philippe Teuwen

unread,
Dec 28, 2013, 7:36:11 PM12/28/13
to nfc-too...@googlegroups.com
Hi Jiapeng

> How about adding this pn532_net driver to libnfc?

This is a good idea but I find the current driver too specific to UART,
and too specific to one model over UART (this won't work e.g. with an
Arygon ADRA as the serial protocol frame is a bit different)

For this kind of exercise, I believe you can do it with socat.
In the man page, this one is pretty close to what you want to do:

socat PTY,link=$HOME/dev/vmodem0,raw,echo=0,waitslave EXEC:�"ssh
modemserver.us.org socat - /dev/ttyS0,nonblock,raw,echo=0"�

generates a pseudo terminal device (PTY) on the client that can be
reached under the symbolic link $HOME/dev/vmodem0. An application that
expects a serial
line or modem can be configured to use $HOME/dev/vmodem0; its traffic
will be directed to a modemserver via ssh where another socat instance
links it with
/dev/ttyS0.

So by using /dev/vmodem0 as the "serial port" of your board in libnfc
config, libnfc will talk to the board connected to the RPi over /dev/ttyS0
Alternatively you can try something like
socat PTY,link=$HOME/dev/vmodem0,raw,echo=0,waitslave TCP4:myRPi:1234
and on the RPi:
socat TCP4-LISTEN:1234,reuseaddr /dev/ttyS0,nonblock,raw,echo=0"

See the socat manpage, there is a lot of possible tuning in all termios
parameters, baudrate etc/

Phil

Jiapeng Li

unread,
Dec 29, 2013, 11:41:35 PM12/29/13
to nfc-too...@googlegroups.com
Hi Phil,
Thanks for your advice. I have checked the manpage and some papers of
'socat', it is a very good tool to make a virtual terminal,
build a bridge between network and uart. Amazing!

>The net driver is too specific.
Yes, have to admit ,it is.
A general net to uart driver need contain termios parameter, baudrate
configure functions.
So a communication protocol may be needed to divide data frame and
configuration frame. But for the embedded devices
it need use the same protocol, too. As you said in the email, `socat`
must be supported on both pc and embedded device.
I haven't found a clean way to do this.

Thanks again for the 'socat', the amazing tool.
BR.
Jiapeng

Philippe Teuwen

unread,
Dec 30, 2013, 4:35:34 AM12/30/13
to Jiapeng Li, nfc-too...@googlegroups.com

Le 30 déc. 2013 05:41, Jiapeng Li
>. As you said in the email, `socat`
> must be supported on both pc and embedded device.
> I haven't found a clean way to do this.

If ser2net doesn't add extra framing you may just use it on RPI side.
Socat is amazing but socat2 is even more;-) think of serial over TCP through proxy hidden behind SSL or even more complex setups, made possible in v2.
Cheers
Phil

Reply all
Reply to author
Forward
0 new messages