Commit Graph
1835 Commits
Author SHA1 Message Date
Olaf Bergmann 5d930d8683 Makefile.am: Added new file coap_riot.h
The new header file is required by RIOT applications to execute
thread-specific startup code.
2020-04-24 20:16:10 +01:00
Olaf Bergmann 648d8b9a33 coap_io.c, coap_io_riot.c: RIOT-specific coap_network_send()
The RIOT-specific version of coap_network_send() has been moved
to coap_io_riot.c for clarity.
2020-04-24 20:16:10 +01:00
Olaf Bergmann ad1c985fcf Makefile.am: added new file coap_io_riot.c to EXTRA_DIST 2020-04-24 20:16:10 +01:00
Olaf Bergmann 7949440ee0 [RIOT] coap_io.c: replace coap_network_read()
A RIOT-specific version of the function coap_network_read() is
now included in the new file coap_io_riot.c. This function requires
the received gnrc_pktsnip_t structure to be passed with the
coap_socket_t structure.
2020-04-24 20:16:10 +01:00
Olaf Bergmann cf5f1a09e9 coap_session.c: minimize buffer space for coap_session_str()
The buffer szSession for storing a textual representation of the
session structure has been trimmed down to 2 * (INET6_ADDRSTRLEN + 8)
+ 24, allowing two IPv6 address references, port numbers, some
structuring text and about eight characters for the interface index.

Background: coap_print_addr() calls inet_ntop() for address output
which on RIOT is mapped to ipv6_addr_to_str(). As the length parameter
of ipv6_addr_to_str() is a uint8_t, only the lower eight bits of
szSession's size are effectively used. The previous value of 256 then
always lead no ENOSPC because 256 & 0xff == 0.
2020-04-24 20:16:10 +01:00
Olaf Bergmann f510b86573 coap_time.h: RIOT support based on xtimer 2020-04-24 20:16:10 +01:00
Olaf Bergmann 054fbf08ce coap_io.c: basic support for RIOT
RIOT lacks support of the ancillary interface and various ioctls
therefore basic sendto() and recvfrom() are used instead.

coap_io.c: Fix mismatching #elif

This change fixes a mismatching #elif introduced during git rebase
conflict resolution.
2020-04-24 20:16:10 +01:00
obgm 17957e1e68 Merge pull request #430 from gocarlos/develop
add cmake support to libcoap
2020-04-24 20:42:04 +02:00
Carlos Gomes Martinho b35fe5408d style: add new line in gitignore 2020-04-24 15:20:44 +02:00
Carlos Gomes Martinho 7e9a7fb3e6 ci: run github ci on PR 2020-04-24 15:20:28 +02:00
obgm c4f7851462 Merge pull request #463 from mrdeep1/coap_io_process
coap_io_process: Fix 1ms busy loop and indefinite sleep
2020-04-24 12:17:28 +02:00
Carlos Gomes Martinho e191e2d726 build: add cmake support 2020-04-22 17:07:24 +02:00
Olaf Bergmann 357a0f6b7a README.md: Updated CI status badge 2020-04-01 15:11:54 +02:00
Olaf Bergmann bbc6b24abd unit tests: Make global variables static
As of gcc 10, -fno-common is default to check for multiple
definitions of global variables at link time. This change makes
the global variables in the unit test files static to avoid
error messages caused by this.

Fixes #464
2020-02-26 12:49:38 +01:00
Jon Shallow afefd95ceb coap_io_process: Fix 1ms busy loop and indefinite sleep
Replace COAP_RUN_BLOCK with COAP_IO_WAIT and COAP_RUN_NOBLOCK with
COAP_IO_NO_WAIT for naming clarity.

Instead of COAP_IO_NO_WAIT being 1, make it -1 to fix 1ms busy loop.
Handle the case when coap_io_prepare_io returns 0 to prevent indefinite
select() wait.

include/coap2/net.h:

Make the timeout_ms parameter uint32_t in coap_io_process*() functions to
make sure special case of COAP_IO_NO_BLOCK is correctly handled on different
architectures.
Update COAP_IO_NO_BLOCK to -1.

src/coap_io.c:

Fix the 1ms busy loop and potential infinite wait in the non epoll case.

man/coap_io.txt.in:

Update documentation to reflect the changes.

examples/coap-server.c:
examples/contiki/server.c:

Update to use COAP_IO WAIT and COAP_IO_NO_WAIT as appropriate.
2020-02-25 22:03:46 +00:00
obgm 66e6fca48e Merge pull request #460 from mrdeep1/without_tcp_split_uri_fix
DISABLE_TCP: Make TCP enabled code checking more rigorous
2020-02-24 13:49:34 +01:00
obgm af6b76590a Merge pull request #457 from mrdeep1/remove_defines
pdu.h: Remove unneeded backward compatible #defines from 2011
2020-02-24 11:23:54 +01:00
obgm 78ad0c2dd7 Merge pull request #458 from mrdeep1/esp-idf_mbedtls_fix
coap_mbedtls.c: Fix esp-idf build warning if client only
2020-02-24 11:20:53 +01:00
Olaf Bergmann 620e6fe2d4 coap_debug.c: Use length returned by print_timestamp()
In theory, print_timestamp() could omit the terminating null byte when
the buffer passed as argument is too small or if snprintf() returns -1.
To make coap_log_impl() more robust against unforeseen out-of-bounds
access, the length returned by print_timestamp() now is passed to
fprintf() explicitly.
2020-02-24 11:17:35 +01:00
obgm a9d5f07661 Merge pull request #437 from mrdeep1/debug_timing
coap_debug.c: Extend date+time to include millisecs reporting
2020-02-24 11:07:35 +01:00
Jon Shallow 4b072cd706 DISABLE_TCP: Make TCP enabled code checking more rigorous
In the same way that coap_split_uri() allows coaps:// scheme even if DTLS is
not available, it should allow coap+tcp:// and coaps+tcp:// scheme and let
other functions check whether TCP/TLS is available or not.

examples/client.c:

Verify if TCP is supported for scheme coap+tcp://.

src/coap_session.c:

Verify that the underlying CoAP transport protocol is supported in
coap_session_create_client().
Add verify for TCP protocol in coap_new_endpoint(), as well as always check
if TLS is supported.

src/uri.c:

Always allow coap+tcp:// and coaps+tcp:// in coap_split_uri() as a parsed
scheme in same way that coaps:// is always allowed.

Makefile.libcoap:

Include coap_tcp.c to include coap_tcp_is_supported() function.

examples/lwip/Makefile:

Include coap_tcp.o to include coap_tcp_is_supported() function.
2020-02-24 09:58:14 +00:00
obgm 249fb860e5 Merge pull request #455 from biodranik/openssl-self-signed-certificate-depth-0
OpenSSL: Support self-signed certificates at depth 0
2020-02-24 10:46:26 +01:00
Jon Shallow c3be323749 pdu.h: Remove unneeded backward compatible #defines from 2011
The # COAP_RESPONSE_nnn entries were introduced to handle a response change
introduced by draft-ietf-core-coap-04 in 2011.  These are no longer used
and can cause confusion - e.g.
 define COAP_RESPONSE_304      COAP_RESPONSE_CODE(203)  /* 2.03 Valid */
as raised in #456.  Entries now removed.
2020-02-21 17:27:48 +00:00
Jon Shallow bf18aad751 coap_mbedtls.c: Fix esp-idf build warning if client only
Only include psk_sni_callback() if appropriate.
2020-02-21 17:26:46 +00:00
Olaf Bergmann 636a4df2b5 .travis.yml: Cleanup
* Remove deprecated option `sudo`
* Explicitly set `os` to `linux`
2020-02-21 17:57:44 +01:00
Olaf Bergmann fb92c07ae4 .travis.yml: eliminate concurring build options
Eliminate the matrix description which overides the jobs.
If both keywords are present, matrix takes precedence. This made
subsequent stages specified in the jobs section to be ignored.

Fixes #452
2020-02-21 17:44:16 +01:00
Alexander Borsuk 52a9d2ad07 OpenSSL: Support self-signed certificates at depth 0
When libcoap config allows self-signed certificates (*) the library should
also accept self-signed certificates at depth 0. This is achieved by allowing
X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT [1].

(*) coap_dtls_pki_t.allow_self_signed == 1
[1] https://www.openssl.org/docs/man1.1.0/man3/X509_STORE_CTX_get_error_depth.html
2020-02-18 04:42:59 +01:00
Jon Shallow f342f8a4c6 coap_debug.c: Extend date+time to include millisecs reporting
This helps to debug timing issues such as DTLS retransmits.
2020-02-14 11:31:48 +00:00
obgm ef4c01df04 Merge pull request #419 from mrdeep1/coap_run_once
Rename coap_run_once() to coap_io_process()
2020-02-14 10:26:35 +01:00
Jon Shallow 9cf4f10b35 Rename coap_run_once() to coap_io_process()
coap_read(), coap_write() and coap_run_once() are confusing in their names
and do not really describe what they do.

For example, coap_read() does both reading and writing, coap_write() may
do some writing, but primarily is used to determine what should be monitored
and for how long to wait in the following select() or epoll_wait() calls.

coap_run_once() implies that the code is only to be run once - again confusing.

By renaming coap_read() to coap_io_do_io(), this better describes what this
function does.

By renaming coap_write() to coap_io_prepare_io() this better describes what this
function does.

By renaming coap_run_once() to coap_io_process(), this better describes what
this function does.

By renaming coap_io_do_events() to coap_io_do_epoll(), this better describes what
this function does and is associated with.

A wrapper function coap_io_prepare_epoll() has been created, using
coap_io_prepare_io() with some preset values to simplify function usage.

include/coap2/net.h:

Update with the new function names, and deprecate the old functions.  Also
document the fact that coap_io_prepare_io(), coap_io_do_io(),
coap_io_prepare_epoll(), and coap_io_do_epoll() are really internal functions.

Create app_io module for Doxygen.

libcoap-2.map:
libcoap-2.sym:

Expose the new functions to applications.

examples/client.c:
examples/coap-rd.c:
examples/coap-server.c:
examples/contiki/coap-observer.c:
examples/contiki/server.c:
examples/etsi_iot_01.c:
man/coap_io.txt.in:
man/coap_observe.txt.in:
src/coap_io.c:
src/coap_io_lwip.c:
src/net.c:
src/pdu.c:

Update using the new function names.

Setting the etimer has been moved out of coap_io_process() into
coap_io_do_epoll(), making the logic easier for applications to use
coap_io_do_epoll() should they need to.  This also gets rid of a
potential timing window where a pending etimer event gets missed.

coap_io_do_epoll() now calls coap_io_prepare_epoll() if the etimer has
triggered removing the need for applications using coap_io_do_epoll() to
set up their own loops if etimer is triggered.
2020-02-13 19:54:48 +00:00
Olaf Bergmann fca966385e coap-server.c: Immediate exit when no endpoints defined
get_context() creates a new context object and adds coap_endpoint_t
objects for all listen addresses. The function now clears the
context object and returns NULL when no endpoint was created,
causing the server to exit immediately.
2020-02-12 13:28:39 +01:00
obgm af841d3a91 Merge pull request #451 from nmeum/coap-server-segfault
coap_free_endpoint: fix segfault with incorrect -A argument
2020-02-12 13:24:26 +01:00
Sören Tempel 605d56eb8d coap_free_endpoint: fix segfault with incorrect -A argument
`coap-server(1)` segfaults when invoked as:

	$ coap-server -A '2001:db8::1'
	Feb 09 18:28:49 WARN coap_socket_bind_udp: bind: Address not available
	Segmentation fault

In this case, the `ep->context->endpoint` is NULL but
`coap_free_endpoint` still attempts to access it. To prevent this
invocation from causing a segmentation fault, check if
`ep->context->endpoint` is NULL before accessing it.
2020-02-09 18:39:07 +01:00
obgm 978b228f5f Merge pull request #447 from mrdeep1/missing_no_tcp_openssl
coap_openssl.c: OpenSSL < 1.1.1 fails to build with --disable-tcp
2020-02-06 14:42:28 +01:00
obgm a52cce58af Merge pull request #450 from mrdeep1/con_active_fix
net.c: Correct setting of con_active if error
2020-02-06 14:40:11 +01:00
Jon Shallow 591c130276 net.c: Correct setting of con_active if error
Only update con_active if PDU has been successfully sent
2020-02-06 12:01:09 +00:00
Jon Shallow 15f9cf568a coap_openssl.c: OpenSSL < 1.1.1 fails to build with --disable-tcp
Missing COAP_DISABLE_TCP wrapper in OpenSSL 1.1.0 - 1.1.1 specific code

doc/main.md:

Update Copyright year.

include/coap2/coap_tcp_internal.h:

Update documentation for the internal TCP functions

src/coap_session.c
src/coap_tinydtls.c

Delete trailing space
2020-02-04 10:30:16 +00:00
obgm 69dd4426c5 Merge pull request #449 from mrdeep1/coap_request_enum
Make COAP_REQUEST_* enum for clarity
2020-02-03 12:38:29 +01:00
Jon Shallow e9cffe9b91 Make COAP_REQUEST_* enum for clarity
Make the COAP_REQUEST_* #defines enum coap_request_t for clarity.

This should help prevent mistakes such as in #448.
2020-02-03 09:33:15 +00:00
obgm b136504d22 Merge pull request #446 from mrdeep1/coap-rd-windows
coap-rd: Fix windows build
2020-01-17 10:58:25 +01:00
obgm ea838843ac Merge pull request #431 from mrdeep1/dtls_spin
coap_gnutls.c: Fix potential spin in DTLS retransmit timeout loop
2020-01-17 10:57:29 +01:00
obgm 8a31e24a85 Merge pull request #414 from mrdeep1/disable-tcp
Rebase disable-tcp branch and reduce code further
2020-01-16 16:46:10 +01:00
Jon Shallow 2a48f44fe4 coap-rd: Fix windows build
Define S_ISDIR if needed for Windows.
2020-01-16 15:36:28 +00:00
Jon Shallow c237b15b16 Correct Disable TCP for TLS and Windows
Makefile.am:

include coap_tcp_internal.h in EXTRA_DIST

libcoap-2.map
libcoap-2.sym:

Don't expose previously static coap_socket_format_errno().

src/coap_gnutls.c:
src/coap_openssl.c:
src/coap_tinydtls.c:

Correct ENABLE_TCP (never defined) to !COAP_DISABLE_TCP.
Conditionally compile in TLS code as appropriate.

src/coap_io.c:

Correct #endif description.

src/coap_session.c:

Conditionally compile in TLS code as appropriate.

src/coap_tcp.c

Merge in appropriate parts of https://github.com/obgm/libcoap/pull/396 and
https://github.com/obgm/libcoap/pull/345 fixes.

include/coap2/coap_tcp.h:
include/coap2/coap_tcp_internal.h:

Rename include/coap2/coap_tcp.h to include/coap2/coap_tcp_internal.h and
remove reference to coap_tcp_is_supported().

include/coap2/coap.h.in:

Remove reference to coap_tcp.h.

coap_config.h.windows:

Include #define COAP_DISABLE_TCP 0.

include/coap2/coap.h.windows:

Reorder #includes

include/coap2/coap_internal.h:

Add #include coap_tcp_internal.h

include/coap2/coap_io.h:

Add in definition of coap_tcp_is_supported().

win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:

Include src/coap_tcp.c and include/coap2/coap_tcp_internal.h.
2020-01-16 15:17:10 +00:00
Olaf Bergmann b43907ef2b Conditionally disable TCP
The pre-processor flag COAP_DISABLE_TCP controls if TCP support is
compiled into the library. If set to 1, some bytes can be saved
by omitting TCP-specific code. By default, this flag is set to 0.

The new configure option '--disable-tcp' will set this flag to 1.
2020-01-16 13:37:24 +00:00
obgm bbe620f997 Merge pull request #427 from mrdeep1/handle_timeouts
coap_io.c: Stop calls to coap_dtls_handle_timeout() dereferencing the session
2020-01-16 13:10:25 +01:00
obgm e4e6676dcb Merge pull request #353 from mrdeep1/mbedtls
Add in MbedTLS support
2020-01-16 11:14:52 +01:00
Jon Shallow 2d6c50e041 coap-server: Add in support for using/testing COAP_PKI_KEY_PEM_BUF
Add in -m option to enable using COAP_PKI_KEY_PEM_BUF instead of
COAP_PKI_KEY_PEM when defining certificates.  This is done by reading in
the contents of the file into a temporary buffer and the buffer is
passed in instead of the filename to the PKI logic.
2020-01-16 09:40:44 +00:00
Jon Shallow d7055d16d8 Update win32 builds
win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:

Include coap_mbedtls.c in the files
2020-01-16 09:38:43 +00:00
Jon Shallow 8abd8fa677 Add mbedtls build into Travis builds
.travis.yml
build-env/Dockerfile.build-env
build-env/Dockerfile.develop
scripts/build.sh
scripts/dist.sh

Update with mbedtls information
2020-01-16 09:38:43 +00:00