Start adding basic files for generating all the needed files to create a
working build environment by the autotools. By this currently only the
shared library of libcoap is build.
There is no API version implemented! This has to be done later.
The autotools will generate the *.in files automatically. We have to
move the current files out of the way to not look later probably into
the old files while re creating the build maintaining config.
In preparation for changing the make buildsystem to a fully autotools
controlled system moving the core libcoap source files to a better logical
place.
All the library related header files moving to include/coap/ to get
all the public and local header files in a separate place. Also moving
the C source files of the libcoap library to the folder src/.
It was noted on the mailing list that the changed retransmission
timeout calculation in commit 1a28b3 may yield to inefficient code
on embedded systems which have no fpu. This change now uses
fixed point arithmetic instead. By default, it represents ACK_TIMEOUT
and ACK_RANDOM_FACTOR as Q2.6 numbers and uses Q0.8 for the
randomness parameter. The resulting timeout value is represented in
system ticks (i.e. a multiple of COAP_TICKS_PER_SECOND) as an
unsigned integer.
coap_insert() now appends every item at the list's end, sorting must
be done explicitly using LL_SORT. As a side-effect, the new
implementation makes valgrind happy :-)
The retransmission timeout is more accurate now by using floating point
arithmetic.
For better readability, the parameter names from RFC 7252 are used.
strnlen() is used for formatting messages in debug.c. As strnlen() is
unknown in C99, the compiler emits a warning even if configure has
detected the presence of strnlen() in glibc and has set HAVE_STRNLEN
accordingly. To overcome this, the symbol _GNU_SOURCE now is set when
HAVE_STRNLEN and __GNUC__ are defined but not _GNU_SOURCE. This works
not only for glibc prior 2.10 but also for newer versions that conform
to POSIX.1-2008 (see strnlen(1)).
The switch {} construct in the function coap_dispatch{} doesn't had a
'default:' directive so the compiler is complaining about that with a
warning.
src/net.c: In function 'coap_dispatch':
src/net.c:1545:5: warning: switch missing default case [-Wswitch-default]
switch (rcvd->pdu->hdr->type) {
^
Directory examples/contiki now contains a small example server for
Contiki and a Makefile for platform minimal-net.
Build:
make contiki # clones Contiki
make server # creates the minimal-net coap server
Run:
Unfortunately, you have to run the server with sudo unless you
set CAP_NET_ADMIN for both, the server executable, and ifconfig
(sudo setcap cap_net_admin+pei ...).
sudo ./server
Then, add the server's interface address to the tap0 device and
optionally set a default route:
sudo ip -6 a a aaaa::1000 dev tap0
sudo ip -6 r a aaaa::/64 dev tap0
Although everything should work now, it does not. I had to send
router advertisements on tap0:
sudo radvd -C ./radvd.conf
Note that on Debian (and Ubuntu, and ...), radvd will not start
when IPv6 forwarding is disabled (which is usually the case on
end systems). Trying to enable like this did not work for me:
sudo sysctl -w net.ipv6.conf.tap0.forwarding=1
sudo sysctl -w net.ipv6.conf.tap0.mc_forwarding=1
Workaround (ugly): get the radvd sources, compile them and use that.
To get rid of the awful (and buggy!) ALIGNPTR stuff that used to
be in coap_pdu_clear(), a new memory type COAP_PDU_BUF has been
introduced for Contiki. This allows storing the message payload
in its own memory chunk similar to the way it is stored for lwIP.
On POSIX systems we always have a file device as integer. So picking up
the 'socketfd' within the struct. Otherwise the compiler doesn't really
now what member to pick and gives up.
src/net.c: In function 'coap_new_context':
src/net.c:369:13: error: incompatible types when assigning to type 'int' from type 'union <anonymous>'
c->sockfd = c->endpoint->handle;
^
this sidesteps the copying parts of coap_parse_pdu, using the directo
allocation of the pdu payload data from the package's pbuf, whose
reference is consumed.
the old implementation stuffed the pdu struct in front of the
transport-level pbuf, and preserved it on the stack while the packages
were sent.
this had two advantages:
* saving ram
* preserving the other implementation's structure of pdu->hdr == pdu+1
(ie. starting right after the pdu struct)
but two disadvantages:
* bad readability and pointer juggling in the send routine
* relying on the send function to block until the package is out (which
works for simple implementations of lwip drivers but not dma etc)
if something really assumes the contiguous memory structure, it will
show (unfortunately by corrupting other pdu structs), and chances are
people use ->hdr anyway.