[RFC] Network application API

Jukka Rissanen

Hi all,

There has been discussion and complaints that the current net_context
API that applications can use is too low level and requires lot of
effort from application developer to create a bug free application.
Many networking operations that various applications do, are very
similar and can be provided by a library. In order to address these
issues I created a higher level API that applications can use.

This API can be found in https://github.com/zephyrproject-rtos/zephyr/p
ull/540 and you can either give comments there, or here if you wish.

The API consists of two parts:

1. Application initialization support.
* The net_app_init() makes sure that we have IP address, routes etc.
configured and the IP stack is ready to serve before continuing. User
can supply a timeout to the function call, and also give a hint what
kind of support it needs from the IP stack. It is possible to use only
the net_app_init() without the connectivity support if needed.

2. Connectivity support
* Developer can create a simple TCP/UDP server or client application
with only few function calls.

Example for the TCP server:

net_app_init_server(&tcp, SOCK_STREAM, IPPROTO_TCP, NULL,
net_app_set_cb(&tcp, NULL, tcp_received, NULL, NULL);

Example for UDP server:

net_app_init_server(&udp, SOCK_DGRAM, IPPROTO_UDP, NULL,
net_app_set_cb(&udp, NULL, udp_received, pkt_sent, NULL);

Example TCP client:

net_app_init_client(ctx, SOCK_STREAM, IPPROTO_TCP, NULL,
  NULL, NULL, user_data);
net_app_set_cb(ctx, tcp_connected, tcp_received, NULL, NULL);
net_app_connect(ctx, CONNECT_TIME);

Example UDP client:

net_app_init_client(ctx, SOCK_DGRAM, IPPROTO_UDP, NULL,
NULL, NULL, user_data);
net_app_set_cb(ctx, udp_connected, udp_received, NULL, NULL);
net_app_connect(ctx, CONNECT_TIME);

So the developer needs to setup the proper callbacks that will be
called in various stages of the connection flow.

I created a TLS support for TCP server in this initial pull request.
The TLS support is transparent to the application, all the encryption
and decryption happens inside the net_app API. Only thing the
application needs to do is to setup the TLS, and prepare the
certificates for mbedtls library. With this transparent TLS support, it
is possible to create for example MQTT over TLS support quite easily.

In order to try the TLS support, the net-tools project have this
PR that provides stunnel configuration so that echo-client can be run
in Linux side and it can communicate with zephyr echo-server sample
over TLS.

This net_app API will replace the internal net_sample_app API that was
used by some of the network sample applications found under samples/net

The current patchset contains these patches:
* net_app core functions
* conversion of echo-client and echo-server samples to use this new API
* base TLS support
* setting up the echo-server to use the TLS if configured so

Future plans:
* create TLS TCP client support
* create DTLS UDP client and server support
* convert existing network samples to use this API

Any comments?


Join devel@lists.zephyrproject.org to automatically receive all group messages.