Update on POSIX socket library for W5100: client and server for TCP or UDP

Posted on 2015/11/22

3


Nucleo board wired with Ethernet shield.

Nucleo board wired with Ethernet shield.

I am writing a library that implements POSIX sockets, also called Berkeley sockets, for my ST Nucleo+Ethernet shield setup. The functionality that is currently in place, as for the source code on GitHub, allows for TCP client/server connections and UDP client/server communication using Wiznet W5100 chip resources. The interface is not complete, but what’s in place is taken as literally as I could from POSIX.1-2008 standard. One benefit of this approach is that I wrote a few tests for this library, and they compile and run both for my Nucleo board and for my Linux PC without changing a line of code, despite the fact that the first one works on top of my library and the second one works on Linux system calls (see the tests here). In order to do so I had to write also some code for generic file descriptors and standard I/O.

What works is the following:

  • Generic socket management: socket() and close() for socket creation and destruction
  • Generic socket communication: send()/sendto()/write() to transmit and recv()/recvfrom()/read() to receive using TCP and UDP sockets.
  • TCP client functions: connect() to initiate a connection with a server.
  • TCP server functions: bind()/listen()/accept() to manage server-side connections on a chosen port.
  • UDP client functions: connect() and recvfrom()/sendto() for connectionless communication.
  • UDP server: bind() and recvfrom()/sendto() for connectionless communication.
  • Miscellaneous: stdin, stdout and stderr are directed to the serial port seamlessly.

4 connections at the same time can be made with W5100 because of its internal resources. I am not familiar with the other components of the Wiznet family, but I suppose they are similar to the W5100 so I hope that what I am doing may be ported easily to other chips.

The next POSIX functionalities that I want to implement are non-blocking option and select()/poll() functions. Then I could move on to the following:

Another functionality that I would like to add to my platform is to use the SD-card slot of the Ethernet shield to access a file system. I could use ChaN FatFs, encapsulating its interface so that I can access the file system with the standard C I/O functions such as fopen() and fprintf().

Posted in: Embedded