Commit Graph
1422 Commits
Author SHA1 Message Date
obgm ee5cee6e6b Merge pull request #248 from mrdeep1/block2
BLOCK option support in coap-server
2018-09-28 18:24:24 +02:00
Anthony Rabine d0dfa0b7c0 missing cast for coap_encodevar_safe() conversion 2018-09-28 18:08:57 +02:00
obgm 6ea51c8a03 Merge pull request #242 from mrdeep1/tls13
Add in support for OpenSSL 1.1.1 to support TLS1.3 (RFC8446)
2018-09-28 17:47:33 +02:00
Jon Shallow 469357b824 BLOCK option support in coap-server
hashkey.[ch] files restored (now prefixed with coap_)
LWIP and Contiki builds now include these files

block.[ch]:
New function coap_add_data_blocked_response() to simplify GET
responses and handle adding in BLOCK2 options as appropriate.
Needs coap_hash() to generate ETag option.

net.c:
Determine if Block2 is in use, and add to coap_add_observer().

resource.[ch]:
Include Block2 request in coap_add_observer().

subscribe.h:
Include Block2 definition in coap_subscriber_t for using during
observe responses.

pdu.h:
Update comment.

coap-client.c:
No longer causes duplicate calls to coap_show_pdu()
(one in library, one in coap-client for the same PDU).

If a block'ed response received and observing, now observing continues.
(Fixes #166).

Send Observe Cancel with Block2 option if -b defined

coap-server.c:
Replaced all option setting, data addition etc. with new
coap_add_data_blocked_response() function in the GET handlers.
(Fixes #246 Issue 2).

Support PUT with BLOCK1.
(Fixes #246 Issue 1).

Add in -N option to send observe responses as non-confirmable.

Handle small wait_ms values correctly (after being decremented) for testing
whether observe should be triggered or not.

Refresh time every second by making COAP_RESOURCE_CHECK_TIME 1

Manuals:
Add in new function coap_add_data_blocked_response()
Update coap_observe with coap_delete_observer(s) functions

Correct example typo and use new function in hnd_get_time().

Add in -N option to coap-server(5)

Be more specific about COAP_RESOURCE_FLAGS_NOTIFY_NON and
COAP_RESOURCE_FLAGS_NOTIFY_CON usage for observe.

Files:
Makefile.am
Makefile.libcoap
examples/client.c
examples/coap-server.c
examples/lwip/Makefile
include/coap/block.h
include/coap/coap_hashkey.h
include/coap/pdu.h
include/coap/resource.h
include/coap/subscribe.h
libcoap-2.map
libcoap-2.sym
man/Makefile.am
man/coap-server.txt.in
man/coap_handler.txt.in
man/coap_observe.txt.in
man/coap_pdu_setup.txt.in
man/coap_resource.txt.in
src/block.c
src/coap_hashkey.c
src/net.c
src/resource.c
2018-09-24 20:49:57 +01:00
obgm a2986f1bdb Merge pull request #239 from mrdeep1/delayqueue-flush
net.c: Flush out delayqueue if a CON times out
2018-09-24 17:54:22 +02:00
obgm 354c7b4e9c Merge pull request #237 from mrdeep1/doxygen-man
Include man pages into Doxygen.  Add landing page for Doxygen
2018-09-24 17:52:31 +02:00
Jon Shallow 8238f628b9 Include man pages into Doxygen. Add landing page for Doxygen
Added in a new landing page for Main Page
 doc/main.md (new)

Enabled Tree View of whats available
Disable Related Pages TAB as it fills up with the man pages
 - updated doc/Doxyfile.in

Get a2x to also generate html man pages which are then included.  These
html files are updated to correct the lowercasing of NAME and SYNOPSIS.
The SEE ALSO references to other man pages are made hyper links.
 - done by doc/build_man_files.sh (new)

Created a new TAB Manual Pages
Created a new TAB Depricated Items
 - done by modifing DoxygenLayout.xml file using doc/build_man_files.sh

Updated .gitignore to ignore additional files and autogen.sh to clean them up

man/coap*txt.in updated to display as expected in Doxygen.

This only updates documentation

.gitignore
Makefile.am
autogen.sh
doc/Doxyfile.in
doc/Makefile.am
doc/build_man_files.sh (New)
doc/main.md            (New)
include/coap/debug.h
include/coap/encode.h
include/coap/option.h
include/coap/pdu.h
include/coap/prng.h
man/Makefile.am
man/coap.txt.in
man/coap_attribute.txt.in
man/coap_context.txt.in
man/coap_encryption.txt.in
man/coap_handler.txt.in
man/coap_logging.txt.in
man/coap_observe.txt.in
man/coap_pdu_setup.txt.in
man/coap_recovery.txt.in
man/coap_resource.txt.in
man/coap_session.txt.in
man/coap_tls_library.txt.in
2018-09-24 16:46:42 +01:00
obgm 395815e26d Merge pull request #236 from mrdeep1/dtls_event
openssl.c: Global dtls_event variable causing confusion when events happen
2018-09-24 16:28:19 +02:00
obgm e758f338c5 Merge pull request #235 from mrdeep1/observe-con
src/resource.c: Non Confirmable observe requests not getting out if CON pending
2018-09-24 16:25:03 +02:00
obgm 2501ff92c9 Merge pull request #208 from mrdeep1/build-lwip
Update code to build LwIP and Contiki from the examples directory
2018-09-24 16:19:15 +02:00
Jean-Claude Michelou ecfcd37f0c client: Sort options alphabetically, ping is TCP only. 2018-09-24 15:55:57 +02:00
Jean-Claude Michelou 8701fb33c7 pdu.c: Remove downcast warning. 2018-09-24 15:55:54 +02:00
Jean-Claude Michelou 01b2ec78fd examples: Add missing stat macro for win32. 2018-09-24 15:54:11 +02:00
jcmichelou 949d32da86 net.h: Fix documentation of coap_context_set_keepalive() 2018-09-24 15:53:45 +02:00
jcmichelou f0a85e2278 build: Rebuild symbols list 2018-09-24 15:53:07 +02:00
jcmichelou 48d304e7ac io, net: Pong response may have same timestamp as ping.
Because of time accuracy of COAP_TICKS_PER_SECOND (usually 1000
ticks per second on platform POSIX), the pong response may have
the same timestamp as the ping request. To be reliable, the pong
timestamp must be tracked separately from the general last RX/TX
timestamp.
2018-09-24 15:51:13 +02:00
jcmichelou 460c7248bb resource.c: Return 0 if there is no observer to notify.
According to documentation, coap_resource_notify_observers() must return 0 if
no observer will be notified. This can help an application release resources
associated to that resource for observation.
2018-09-24 15:42:40 +02:00
jcmichelou 4e73052872 session: Improve event reporting, add auto-ping and csm timeout.
Add new event types to report the TCP connection status and CSM exchange
status to the application. Add optional auto send of ping messages for
reliable client sessions. Add default timeout of 30s for receiving a CSM
message from the remote host after connect.
2018-09-24 15:42:40 +02:00
Olaf Bergmann c090fa96dc pdu.h: Added Content-Formats from RFC 8428 (SenML) 2018-09-06 12:20:06 +02:00
Jon Shallow 2466853075 openssl.c: Global dtls_event variable causing confusion when events happen
dtls_event is a static variable, declared outside of all the functions which
tracks (D)TLS errors for generating events etc.

If there are multiple SSL sessions being set up to the same server (as per
Happy Eyeballs for the DOTS protocol) it is possible to asynchronously get
dtls_event updated and the wrong SSL session then acts on it.

Make dtls_event a part of coap_session_t to maintain seperation.

Preset dtls_event to -1 in coap_make_session().

Update coap_event_handler() to have the 3rd parameter as
coap_session_t *session instead of void *arg as the parameter is always session.
Updated coap_event_handler_t to have session as the 3rd parameter.

Add in new registration handler coap_register_event_handler() to be consistent
with all the other coap_register_XXX_handler()s.
Consequently, coap_set_event_handler() and coap_clear_enent_handler() are
deprecated.

Update coap_handler(3) to include new coap_register_event_handler().
(PR #183 event definitions are included presumptive on #183 getting merged)
2018-08-28 13:32:05 +01:00
Jon Shallow 45731f1c0e Add in support for OpenSSL 1.1.1 to support TLS1.3 (RFC8446)
OpenSSL 1.1.0 has support for making decisions during receipt of
the Client Hello - the call back function is set up using
SSL_CTX_set_tlsext_servername_callback() which is called later in the
Client Hello processing - but called every Client Hello.
Certificates and Preshared Keys have to be set up in the SSL CTX before
SSL_Accept() is called, making the code messy to decide whether this is a
PKI or PSK incoming request to handle things accordingly if both are
defined.  SNI has to create a new SSL CTX to handle different server names
with different crtificates.

OpenSSL 1.1.1 introduces a new function SSL_CTX_set_client_hello_cb().
The call back is invoked early on in the Client Hello processing giving
the ability to easily use different Preshared Keys, Certificates etc.
Certificates do not have to be set up in the SSL CTX before SSL_Accept is
called.
Later in the Client Hello code, the callback for
SSL_CTX_set_tlsext_servername_callback() is still called, but only if SNI
is being used by the client, so cannot be used for doing things the
OpenSSL 1.1.0 way.

OpenSSL 1.1.1 supports TLS1.3.

Consequently, this code has to have compile time options to include /
exclude code based on whether compiled against 1.1.0 or 1.1.1, as well as
have additional run time checks.

Updated:
examples/client.c
examples/coap-server.c
include/coap/coap_dtls.h
man/coap_context.txt.in
man/coap_encryption.txt.in
man/coap_session.txt.in
src/coap_openssl.c

In addition, the callback app_override_tls_setup_call_back has been removed
from coap_dtls_pki_t and replaced with additional_tls_setup_call_back
as app_override_tls_setup_call_back became very messy with 2 versions
of OpenSSL.  If the application now wants to make additional checks/
changes etc., app_override_tls_setup_call_back will get invoked after
the defined configuration checks are done.

SNI has been added into coap-client for testing / demonstration
2018-08-21 11:09:59 +01:00
Jon Shallow 9db731d218 net.c: Flush out delayqueue if a CON times out
This allows a Coap Ping sent after a CON request to then go through the
cycle of retries and then timeout after the original CON fails.

In addtion, in coap_session_connected() the entry is now removed from the
delayqueue queue only if it can be transmitted.
2018-08-17 16:33:38 +01:00
Olaf Bergmann b7772e8dd5 .gitignore: updated to include gcov files
All files ending in .gcda, .gcno, and .gcov are now ignored.
2018-08-01 20:33:34 +02:00
Olaf Bergmann ed2d9acd1a Makefile.am: added target for cleaning gcov files
Calling 'make clean' now deleted all files ending on .gcda, .gcno,
and .gcov. This requires the find utility to be present.
2018-08-01 20:31:42 +02:00
Olaf Bergmann 7dc5c9d822 configure.ac: add option for gcov flags
Gcov[1] is a tool to investigate test code coverage. To collect
runtime statistics, certain compiler options must be set, i.e.
-fprofile-arcs, -ftest-coverage, and --coverage. Currently, only
the Gnu C Compiler is known to support the gcov instrumentation.

This change adds the configure option --enable-gcov that checks if
the compiler supports the aforementioned compiler flags and enables
these.

[1] https://gcc.gnu.org/onlinedocs/gcc/Gcov.html
2018-08-01 20:31:08 +02:00
Olaf Bergmann 4980971dce oss-fuzz: pass libFuzzingEngine in LDLIBS 2018-08-01 15:47:25 +02:00
Jon Shallow f3d3aca527 src/resource.c: Non Confirmable observe requests not gettng out if CON pending
If an non-confirmable observe response was triggered, and there was already a
CON message outstanding, then the observe response would not get sent in error.

[Example being a observe response following a Ping 0.00 that has not yet had
a reply]

The fix is to check whether the observe request is non-confirmable and there
are less than COAP_OBS_MAX_NON already sent to allow it to get sent.
2018-08-01 12:33:22 +01:00
Olaf Bergmann 1cef78ebda coap-server.c: check if data is present in PUT request
This change change fixes coverity CID 1472105.
2018-07-31 11:26:33 +02:00
Olaf Bergmann 57ee5eb55c coap-server.c: fix NULL-pointer dereference in example server
When realloc() returns NULL, hnd_put() must be left immediately
after setting the response code.

This change fixes coverity CID 1472106.
2018-07-31 11:23:04 +02:00
Olaf Bergmann 87761373e4 coap_session.c: fix possible NULL-pointer dereference
Re-arrange checks in coap_new_client_session_pki() to prevent possible
dereference of setup_data before checking for NULL.

This fixes coverity CID 1472107.
2018-07-31 11:16:51 +02:00
obgm 2213e021b4 Merge pull request #232 from mrdeep1/delayqueue
Rename coap_session_t sendqueue variable to delayqueue
2018-07-31 10:55:16 +02:00
obgm 95d1aa6951 Merge pull request #221 from mrdeep1/issue-197
coap_io.c,net.c: Fix head of node queue re-transmit timeouts
2018-07-31 10:52:31 +02:00
Olaf Bergmann 57c78e40dd Makefile.oss-fuzz: Wrapper Makefile for OSS Fuzzer
This Makefile will be invoked from the OSS Fuzzer to create the
fuzzing executables. Invocation:

  make -C tests/oss-fuzz -f Makefile.oss-fuzz

This change closes issue #231 [1].

[1] https://github.com/obgm/libcoap/issues/231
2018-07-30 14:53:19 +02:00
Olaf Bergmann 248a27518d Makefile.ci.in: Add make targets for OSS fuzzer
This change extends the continuous integration Makefile.ci with
new rules for creating the executables for OSS-Fuzz [1].

Object files and linked executables are now created in the directory
$OUT which is set to '.' by default.

[1] https://github.com/google/oss-fuzz
2018-07-30 14:47:44 +02:00
Jon Shallow d766f9d8ee Update code to build LwIP and Contiki from the examples directory
Update code to use new APIs
[Some code changes modelled on PR #202, some code being moved between files]
Remove #ifdef WITH_LWIP from coap_io.c as file is not used
Add in resource time to lwip
Update for Travis build
Report on Contiki memory allocate failures to ease debugging
Make the different memory type counts configurable by using the -D option
included in a CFLAGS definition to the ./configure command line

.travis.yml
BUILDING
Makefile.libcoap
examples/contiki/Makefile
examples/contiki/README     new
examples/contiki/server.c
examples/contiki/.gitignore (new)
examples/lwip/Makefile
examples/lwip/README
examples/lwip/lwipopts.h
examples/lwip/server-coap.c
examples/lwip/server.c
include/coap/address.h
include/coap/coap_io.h
include/coap/lwippools.h
include/coap/pdu.h
scripts/build.sh
src/address.c
src/coap_io.c
src/coap_io_lwip.c
src/coap_session.c
src/mem.c
src/net.c
src/pdu.c
2018-07-27 15:30:37 +01:00
Olaf Bergmann 15a45f6f24 str.h: fix coap_make_str_const macro for C++
As C++ forbides returning a pointer to a temporary object, the
creation of a coap_str_const_t to wrap the character-array and
size done in coap_make_str_const() does not work.

This change therefore creates a C++ class CoAPStrConst in namespace
libcoap in a way that allows the default constructor to be used with
aggregate initialization.

This commit closes issue #233 [2].

[1] https://en.cppreference.com/w/cpp/language/aggregate_initialization
[2] https://github.com/obgm/libcoap/issues/233
2018-07-27 16:23:57 +02:00
obgm ccb01d0257 Merge pull request #204 from mrdeep1/coap_string_t
Replace str with coap_string_t.  Make tokens coap_binary_t
2018-07-27 16:20:21 +02:00
Jon Shallow 06f57978de Replace str with coap_string_t. Make tokens coap_binary_t
New struct coap_binary_t - same as coap_string_t, used for tokens

Deprecate struct str with the intent of removing it downstream as it
polutes namespace.

Make end of coap_string_t data a NUL.

Updated coap_make_str_const(), removing .length= and .s= to keep upstream
compilers happy.

Update Doxygen for str.h

Files:
examples/client.c
examples/coap-rd.c
examples/coap-server.c
examples/contiki/server.c
examples/etsi_iot_01.c
include/coap/resource.h
include/coap/str.h
include/coap/subscribe.h
man/coap_observe.txt.in
src/net.c
src/resource.c
src/str.c
src/uri.c
tests/test_options.c

Update
2018-07-26 15:45:38 +01:00
Jon Shallow a0f94fe2de Rename coap_session_t sendqueue variable to delayqueue
This better describes what is going on here (as they are created by
coap_session_delay_pdu() and are only released off this queue when
either the session becomes established, or the outstanding CON requests
falls below COAP_DEFAULT_NSTART (a value of 1).

This is to remove confusion with the use of coap_context_t sendqueue
which is used for retransmitting data after no response detected for a
CON request.

include/coap/coap_session.h
src/coap_io.c
src/coap_session.c
src/net.c
2018-07-26 14:06:37 +01:00
obgm e1491dee77 Merge pull request #226 from mrdeep1/logging-doc
New coap_logging(3) and updated Doxygen comments for logging
2018-07-26 14:08:25 +02:00
obgm 38246dd41d Merge pull request #230 from mrdeep1/sendqueue-cleanup
net.c: Flush out session->sendqueue when PDU is delayed
2018-07-26 14:02:36 +02:00
Olaf Bergmann e83d0ede27 pdu_parse_target.c: fix include path for coap.h 2018-07-26 13:02:33 +02:00
Olaf Bergmann 93f9ee61b3 build.sh: integrate OSS-Fuzz syntax checks in CI build 2018-07-26 12:35:27 +02:00
Olaf Bergmann 315067add0 configure.ac: add creation of tests/oss-fuzz/Makefile.ci 2018-07-26 12:29:13 +02:00
Olaf Bergmann f0f614897e Makefile.ci.in: Continuous integration checks for OSS-Fuzz
The sub-directory tests/oss-fuzz contains single files that are
used from the Open Source Software Fuzzer [1]. This change provides
a template Makefile with the proper flags for compiling libcoap
applications in a continuous integration environment such as travis.

Intended usage from top_srcdir is:

  make -C test/oss-fuzz -f Makefile.ci check clean

[1] https://github.com/google/oss-fuzz/
2018-07-26 12:22:35 +02:00
Jon Shallow a5cd7dcbd9 net.c,coap_session.c: Flush out session->sendqueue when PDU is delayed
Delayed PDUs (found by the limiting of 1 CON request outstanding) are
added to session->sendqueue by coap_session_delay_pdu().
The session->sendqueue is only flushed out when a session becomes established
by calling coap_session_connected().

This fix now calls coap_session_connected() whenever the current CON count
is decremented.

Additionally, CON tracking now only tracks UDP & DTLS sessions.

coap_session_connected() is updated to not sent out more than one CON
request.
2018-07-26 08:20:34 +01:00
obgm 733628c3d2 Merge pull request #229 from mrdeep1/con-active
Missing case for #201 to close down con_active
2018-07-25 18:01:06 +02:00
obgm ea97fbb835 Merge pull request #228 from mrdeep1/loss-level-restore
src/debug.c: Allow loss level of 0% to restore full flow
2018-07-25 17:53:00 +02:00
Jon Shallow 0a36832bd3 Missing case for #201 to close down con_active
The RST to a CoAP Ping was not decrementing the con_active count, so
all new CON requests were waiting for the Ping to expire.
2018-07-25 14:49:25 +01:00
Jon Shallow 4eeda95ac7 src/debug.c: Allow loss level of 0% to restore full flow
If a loss level is configured using coap_debug_set_packet_loss(), it
is not possible to restore full flow using 0% - as 0 is rejected as
being invalid.  This fix allows 0% to restore full traffic flows again.
2018-07-25 11:47:00 +01:00