Commit Graph
206 Commits
Author SHA1 Message Date
Carsten Schoenert 1d1eb455d6 spelling: fix seperate -> separate 2018-11-24 13:59:47 +01:00
Carsten Schoenert 32eea645b1 spelling: fix compatability -> compatibility 2018-11-24 13:59:34 +01:00
Jon Shallow 04ced3e5e5 Replace debug(), info() & warn() macros with appropriate coap_log()
This then removes the need for name polution/confict of debug(), info() and
warn() when building other projects that use libcoap and need to #include the
libcoap header files

Updated:
 examples/client.c
 examples/contiki/coap-observer.c
 examples/etsi_iot_01.c
 include/coap2/debug.h
 src/async.c
 src/block.c
 src/coap_io.c
 src/coap_openssl.c
 src/coap_session.c
 src/coap_tinydtls.c
 src/debug.c
 src/mem.c
 src/net.c
 src/option.c
 src/pdu.c
 src/resource.c
 src/uri.c

If the debug() etc. macros are still required, then the change to
include/coap2/debug.h just needs to be reverted.

There are also a couple of space changes - to cause log output to be columnar
e.g "ERR" was padded to "ERR ", so that "EMRG" or "ERR " log output output was
aligned in the same way.

This is a replacement for PR#51, and partially deals with name polution issues
raised in Issue #50.

Parameter re-aligned some long strings, splitting strings across multiple lines
2018-11-10 20:27:50 +00:00
Jon Shallow 4c95c50528 Clarify coap_resource_unknown_init() usage documentation
include/coap2/resource.h
man/coap_resource.txt.in
modified:   src/net.c (comment only)
2018-10-29 09:27:04 +00:00
Olaf Bergmann a8306bbb15 doxygen: fix warnings 2018-10-17 15:10:38 +02:00
Olaf Bergmann e782b4291f coap_hashkey.h: moved to include/coap2 2018-10-04 12:53:10 +02:00
Carsten Schoenert f584abc19e include: move header files to include/coap2
Automake is using the variable 'libcoap_include_HEADERS' as the list to
install the header files and is this list installing to $(prefix)
basically.
This commit is changing the primary installation folder for the header
files in addition to the previous commit.
2018-10-04 12:21:12 +02:00
Jon Shallow f5367ef3de Delete trailing spaces from files, replace TAB with 8*SPACE
"git diff -w" shows no differences

TAB left alone in files that are not C based files or documentation
2018-09-28 17:34:07 +01:00
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
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 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
jcmichelou 949d32da86 net.h: Fix documentation of coap_context_set_keepalive() 2018-09-24 15:53:45 +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 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
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
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
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
Jon Shallow c695dea7cd New coap_logging(3) and updated Doxygen comments for logging
Documentation changes/updates only - no code changes.

configure.ac
include/coap/coap_dtls.h
include/coap/coap_session.h
include/coap/debug.h
man/Makefile.am
man/coap.txt.in
man/coap_context.txt.in
man/coap_logging.txt.in (new)
2018-07-25 09:48:02 +01:00
Jon Shallow 0355821afe {coap_dtls|net}.h: New coap_context_set_pki_root_cas(), updated coap_dtls_pki_t
coap_context_set_pki_root_cas(): New
coap_dtls_context_set_psk(): remove unused parameters, add in server parameter
coap_dtls_context_set_pki(): add in server parameter

coap_dtls_pki_t: Additional configuration parameters
coap_dtls_security_setup_t: Updated
coap_dtls_cn_callback_t: New
coap_dtls_sni_callback_t: New
coap_pki_key_t: New
coap_pki_key_pem_t: New
coap_pki_key_asn1_t: New
coap_dtls_sni_t: New

Comments tidy up.

Better Doxygen comments for coap_dtls.h and net.h

Doxygen fix for debug.h (introduced by #219 merge)
Doxygen update coap_endpoint_new_dtls_session() for in coap_session.h
2018-07-23 11:14:22 +01:00
Jon Shallow fd421dd119 debug.c: Make coap_show_pdu() use coap_log() or fprintf()
coap_show_pdu()'s API is now coap_show_pdu(coap_log_t, coap_pdu_t*)
New function void coap_set_show_pdu_output(int use_fprintf)
Default is use fprintf() instead of coap_log()

The output buffer size can be configuring -DCOAP_DEBUG_BUF_SIZE

Output COAP_OPTION_SIZE2 option as well

For binary data, output ascii readable equivalent immediately under the
hex output for ease of debugging.

include/coap/debug.h
src/debug.c

Update coap_show_pdu() API
New function coap_set_show_pdu_output()
Update coap_show_pdu() code

include/coap/pdu.h

Define the coap debug output debug buffer size
COAP_DEBUG_BUF_SIZE

examples/client.c
examples/contiki/coap-observer.c
src/net.c
tests/test_wellknown.c
tests/test_pdu.c

Update coap_show_pdu() calls

libcoap-2.map
libcoap-2.sym

New function coap_set_show_pdu_output()
2018-07-20 18:58:55 +01:00
obgm bf4323ed55 Merge pull request #201 from mrdeep1/issue-198
Limit outstanding CON requests to 1 per session for congestion control
2018-07-20 17:33:23 +02:00
Jon Shallow c37dc485bc Remove doxygen warnings re text in header files by correcting parameter names
include/coap/coap_dtls.h
include/coap/coap_session.h
include/coap/encode.h
include/coap/net.h
include/coap/str.h
include/coap/subscribe.h
src/resource.c

Several functions have been better commented as well.
2018-07-20 14:02:02 +01:00
Jon Shallow ea72c3d770 Limit outstanding CON requests to NSTART per session for congestion control
https://tools.ietf.org/html/rfc7641#section-4.5

In order not to cause congestion, servers MUST strictly limit the number of
simultaneous outstanding notifications/responses that they transmit to a given
client to NSTART (1 by default; see Section 4.7 of RFC 7252 [RFC7252]).
An outstanding notification/response is either a confirmable message for which
an acknowledgement has not yet been received and whose last retransmission
attempt has not yet timed out or a non-confirmable message for which the
waiting time that results from the following rate-limiting rules has not yet
elapsed.

Delay sending of PDUs if active CON request waiting for ACK.

Do not start of another Observer unsolicited response if active CON waiting
waiting for ACK.

Display outgoing PDU if log level DEBUG or higher to help troubleshooting.

This does not fix the ratelimiting of non-confirmable messages, which
should be handled by the application.
2018-07-10 14:11:32 +01:00
Olaf Bergmann 118bbebbbc pdu.h: add COAP_OPTION_SIZE2
This change closes issue #210 [1].

[1] https://github.com/obgm/libcoap/issues/210
2018-06-26 10:04:33 +02:00
Jon Shallow c7e9359f02 Make coap_encode_var_bytes() by replacing with coap_encode_var_safe()
Update code / examples / man pages with the updated function.

include/coap/libcoap.h:
Add in new define COAP_DEPRECATED to generate compiler warnings when used

include/coap/encode.h
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.

Make coap_encode_var_bytes() a wrapper for coap_encode_var_safe() and
mark it as COAP_DEPRECATED for backwards compatability

src/encode.c:
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.

examples/coap-server.c:
examples/contiki/server.c:
Make the ticks resource consistent in case
2018-06-05 09:41:58 +01:00
obgm 60f699d535 Merge pull request #189 from mrdeep1/optlist-mem-leak
options: Fix subtle memory leak in coap_add_optlist_pdu()
2018-06-04 14:05:01 +02:00
Robrecht Dewaele 9677376902 fix typographical error in forward declaration 2018-06-02 03:42:45 +02:00
Jon Shallow 9fa448e439 options: Fix subtle memory leak in coap_add_optlist_pdu()
coap_add_optlist_pdu() sorted the options for insertion, but did not update
the coap_optlist_t head (whch may then no longer point to the first entry in the
sorted chain) and so when coap_delete_optlist() was called, the first few
entries of the sorted chain may not get deleted.
Fixed by making it
 coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t** optlist_chain)
instead of
 coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t* optlist_chain)

Additionally deleted options_start() and options_next() as they are not
required - Issue #184.

examples/client.c:
Fix coap_add_optlist_pdu() call

include/coap/options.h:
Fix coap_add_optlist_pdu() call

libcoap-2.{map|sym}:
Delete options_start()

man/coap_observe.txt.in:
man/coap_pdu_setup.txt.in:

Update docmentation

src/option.c:
Update coap_add_optlist_pdu()

tests/test_pdu.c:
New tests for checkout out coap_insert_optlist() and coap_add_optlist_pdu()
functions
2018-05-30 11:38:50 +01:00
Jon Shallow b4fc68c554 include/coap/*.h: Remove cast-qual compiler warnings
Commented out coap_opt_block_set_m() as it is not used anywhere, and needs
to get rewritten if needed.

Removed / changed references to coap_opt_const_value()

Created a new struct coap_str_const_t to handle const parameters
Add in 2 new functions to create / delete the new string type
coap_new_str_const()
coap_delete_str_const()
Added in coap_make_str_const() to help create the necessary string equivalents
of the ascii test string.  Note that the byte array must be in the
local scope.

Make coap_string_equal() a macro to handle differing string types

Made uri_path a pointer in coap_resource_t
Made name and value a pointer in coap_attribute_t

Reasoning behind this was triggerred by test t_wellknown3() creating a
number of resources, all using the same string buffer, so they all ended up
with the same uri-path (last update to uri-path).  In the days of hashing
uri-path for the lookup would have worked, but the wrong uri-path
presented from the resource.  Now we always allocate uri-path if
application does not want it freed off - and always free it off at time
or resource removal.  The same is also true for coap_add_attr().

Updated coap_resource_init(), coap_add_attr() and coap_find_attr() to
pass in string parameters, rather than use a pointer to data and a length.

Where appropriate

Replace 'unsigned char' with 'const uint8_t'
Replace 'str' with 'coap_str_const_t'
Replace 'str' with 'coap_string_t'
Prefix with 'const' some type casts
Remove 'const' prefix from some type casts
2018-05-25 16:37:05 +01:00
Jon Shallow a17757ec6e async.[ch]: Fix flexible array member 'token' warning
Make token[] token[8] as the maximum size of a token is 8 bytes

Check that we do not overflow coap_async_state_t when copying in
the token.
2018-05-22 11:32:58 +01:00
Jon Shallow 856236dc6c option.[ch]: Fix "warning: ISO C++ forbids flexible array member 'data' " 2018-05-22 10:42:13 +01:00
Olaf Bergmann a2d263356e configure.ac: enable -Wwrite-strings
As discussed in bug #185 [1], const strings should be protected
from being overwritten. This change adds -Wwrite-strings to the
compiler warning flags and fixes resulting warnings by making
static strings const.

[1] https://github.com/obgm/libcoap/issues/185
2018-05-19 09:27:50 +02:00
Olaf Bergmann c2301257d0 option.h: Fixed bug in doxygen comment.
s/@pdu/@p pdu/
2018-05-18 14:41:47 +02:00
Olaf Bergmann 99fbe78a47 resource.h: get rid of -Winline warning
As gcc 7 complains that coap_register_handler() is too large to
be inlined automatically, the function definition now has been
moved to resource.c.

This change also updates the symbol mappings accordingly.
2018-05-18 13:40:05 +02:00
Jon Shallow 25aa689f99 include/coap/mem.h: Include COAP_OPTLIST in coap_memory_tag_t 2018-05-17 18:58:16 +01:00
Jon Shallow 250f6d46ef include/coap/pdu.h: Document struct coap_option is deprecated 2018-05-17 18:58:16 +01:00
Jon Shallow 3122428445 include/coap/option.h: Add in optlist structures / functions
Add in new coap_optlist_t structure
Add in the new functions
 coap_new_optlist()
 coap_add_optlist_pdu()
 coap_insert_optlist()
 coap_delete_optlist()
2018-05-17 18:45:26 +01:00
Jon Shallow ece443f107 include/coap/debug.h: Fix compiler optimizer warning 2018-05-17 18:45:26 +01:00
Jon Shallow b35a66ea3d include/coap/coap.h.in: Remove utlist.h uthash.h includes as not needed 2018-05-17 18:45:26 +01:00
Olaf Bergmann 837917f272 Merge branch 'develop' of https://github.com/nikosft/libcoap-fork into nikosft-develop
Resolved conflicts in file resource.h.
2018-04-20 10:10:08 +02:00
Olaf Bergmann 8c35e7625b net.h: fixed data type option number in coap_register_option()
As option numbers can be up to 16 bit, the function
coap_register_option() for making new options known to libcoap
must also take at least 16 bit numbers. The data type for
argument type therefore has been changed to uint16_t.
2018-04-18 09:21:02 +02:00