Commit Graph
2057 Commits
Author SHA1 Message Date
Jon Shallow a31dcba587 coap-client: Rename client.c to coap-client.c
Keep the examples source names and executables in the same form
for consistency.
2021-02-26 14:21:12 +00:00
obgm 8770152571 Merge pull request #552 from mrdeep1/ack_response
net.c: Delay sending ACK until after response_handler() is called
2021-02-26 15:15:20 +01:00
obgm 25eda91e2f Merge pull request #596 from mrdeep1/no_respond
net.c: Stop reliable sessions returning ACK 0.00
2021-02-26 13:31:20 +01:00
Jon Shallow d89c0140df net.c: Stop reliable sessions returning ACK 0.00
The ACK 0.00 is being returned by the server for reliable conections and the
client is then reporting that CON 0.00 is invalid (CON, NON, ACK and RST are
all resported as CON in a received reliable PDU).

coap-client coap+tcp://127.0.0.1/async?1 -v9

demonstrates the issue.

src/net.c:

Update no_response() to return RESPONSE_DROP for both reliable and
non-confirmable if the application handler returns with the response code set
to 0.00 in the PDU. This then generally simplifies the code around when
calling no_response().

Check for valid multicast responses.

If the response is confirmable and piggybacked and being dropped, convert the
response to an empty ACK so the client does not continue to retry sending the
request.
2021-02-26 11:36:26 +00:00
obgm 1652108d78 Merge pull request #604 from mrdeep1/write_char_inlining
pdu.c: Remove inline expansion warnings for write_char()
2021-02-26 11:40:01 +01:00
Jon Shallow 9b9f6c85c6 pdu.c: Remove inline expansion warnings for write_char()
Just make write_char() and write_prefix() static functions.
2021-02-26 10:22:48 +00:00
obgm 4bbdcc87b2 Merge pull request #584 from mrdeep1/option_strict_aliasing
coap_opt_filter_t: Make it a proper structure
2021-02-26 11:12:26 +01:00
Jon Shallow e2e783033c coap_opt_filter_t: Make it a proper structure
Update coap_opt_filter_t to be a structure rather than a 16bit array that is
aliased with the real structure format.

Update code to use pointers where appropriate.
2021-02-26 09:24:34 +00:00
obgm 486f97f8d4 Merge pull request #599 from mrdeep1/option_encoding
pdu.c: Output debug information for broken CoAP Options
2021-02-26 09:37:15 +01:00
obgm 85c6e0038c Merge pull request #602 from mrdeep1/fix_rebase
resource.h: Remove function definitions that are duplicated
2021-02-26 09:16:43 +01:00
Jon Shallow 757ca19cd0 pdu.c: Output debug information for broken CoAP Options
Refactor coap_pdu_parse_opt() to additionally output the block options in
hex for debugging if there is an error.

Fix the two tests that are now reported with the updated code.
[Other PDU test are reporting information, but only at LOG_DEBUG which is
not output]
2021-02-26 08:13:43 +00:00
obgm 9f1d96a829 Merge pull request #600 from mrdeep1/github_workflows
workflow: Add in distribution and CMake checks
2021-02-26 08:46:53 +01:00
Jon Shallow 669400665d resource.h: Remove function definitions that are duplicated
Result of a rebase confusion.

include/coap2/resource.h:

Remove duplicates that are also in coap_subscriber_internal.h.

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

Remove the now internal only functions.
2021-02-25 16:35:59 +00:00
Jon Shallow dc6c5e6b00 workflow: Add in distribution and CMake checks
.github/workflows/main.yml:

Do a 'make check' for matrix builds.
Move documentation into separate job to reduce matrix build times
Add in CMake job.
Add in distribution job.
Add in tinydtls job.
Add in contiki/lwip job.

scripts/github_dist.sh:

Do the distribution checks using a script.

examples/etsi_iot_01.c:
examples/tiny.c:

Fix include coap.h directory in old examples.

README.md:

Update status badges to get only the branch actions and remove CMake
status badge.
2021-02-24 18:15:25 +00:00
obgm cea89718e9 Merge pull request #582 from mrdeep1/obfuscate_resource
coap_resource_t: Obfuscate coap_resource_t from applications.
2021-02-24 17:53:29 +01:00
Jon Shallow da18643702 coap_resource_t: Obfuscate coap_resource_t from applications.
Create a new include/coap2/coap_resource_internal.h to hold all the information
not available to applications.

Makefile.am:

Include coap_resource_internal.h in EXTRA_DIST.
Remove functions no longer visible from CTAGS_IGNORE.

examples/coap-rd.c:
examples/contiki/server.c:
examples/etsi_iot_01.c:
tests/test_wellknown.c

Replace direct access to coap_resource_t variables with functions as
appropriate.

include/coap2/resource.h:
include/coap2/subscribe.h:
include/coap2/coap_resource_internal.h: (New)
include/coap2/coap_subscribe_internal.h:

Move coap_resource_t, coap_addr_t, non API #defines and non API functions from
resource.h into coap_resource_internal.h, coap_subscribe_internal.h and
subscribe.h.

Replace inline functions accessing coap_resource_t with actual function
definitions.

Add new functions coap_resource_release_userdata_handler() and
coap_attr_get_value().

include/coap2/block.h:

Use coap_resource_t typedef.

include/coap2/coap_forward_decls.h:

Include coap_resource_t and coap_addr_t typedefs.  Also typedef coap_context_t
to get rid of #include circular requirements.

include/coap2/coap_internal.h:
win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:

Include coap_resource_internal.h.

include/coap2/net.h:

Remove "typedef struct coap_context_t" and do this in coap_forward_decls.h.

src/resource.c:

Update with the replaced inline functions. Add in the new functions
coap_resource_release_userdata_handler() and coap_attr_get_value().

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

Update with new function visibility.

man/Makefile.am:
man/coap_attribute.txt.in:
man/coap_observe.txt.in:
man/coap_resource.txt.in:

Update with the new coap_resource_t and coap_attr_t usage.
2021-02-24 16:34:27 +00:00
Jon Shallow 14e75a54b8 net.c: Delay sending ACK until after response_handler() is called
In handle_response() the ACK is sent before calling ctx->response_handler() so
if the response_handler() wants to send RST the server ignores it as the ACK
has already been received.

By updating coap_response_handler_t to return a value, this can be used to
send the ACK (return of COAP_RESPONSE_OK) or a RST (return of COAP_RESPONSE_FAIL)
after ctx->response_handler() is called.

include/coap2/net.h:
man/coap_handler.txt.in:

Create a new enum coap_response_t for use as the return value for
coap_response_handler_t.
Update coap_response_handler_t and associated documentation.

src/net.c:

Send CoAP ACK or RST depending on return value of ctx->response_handler().

examples/client.c:

Update message_handler() to use the new coap_response_handler_t return values
(coap_response_t).
2021-02-24 09:37:32 +00:00
obgm b0e47d71d0 Merge pull request #580 from mrdeep1/with_observe
Observe: Remove WITHOUT_OBSERVE conditional statements in the library.
2021-02-24 09:52:33 +01:00
obgm 8724c0c372 Merge pull request #578 from mrdeep1/icmp_issue_nack_handler
ICMP reporting: Call nack handler when ICMP unreachable is received
2021-02-24 09:22:57 +01:00
obgm 35dbc32708 Merge pull request #577 from mrdeep1/observer_fix
Observe: Fix coap_free_context() assert when active observe
2021-02-24 09:14:42 +01:00
obgm 7c54bd748f Merge pull request #554 from mrdeep1/add_data_large
RFC7641: Move block handling logic down into libcoap
2021-02-24 09:09:01 +01:00
Jon Shallow 4cd633e763 RFC7641: Add in example support using updated libcoap handling of blocks
Remove block handling logic from coap-client and coap-server and make use of the
new libcoap functionality.

Add in new -L option to be able to define how libcoap is to work with block
handling.  Update documentation accordingly.
2021-02-23 18:01:14 +00:00
Jon Shallow 9cb2f62a3e RFC7641: Move block handling logic down into libcoap
This change removes the need for applications having to know about handling
requests for the next block etc.  It also gives the application the ability
to pass a large body of data to be transmitted and be told when this body is
no longer required.

This logic is enabled in libcoap by setting COAP_BLOCK_USE_LIBCOAP using
coap_context_set_block_mode()

This change breaks down into 4 specific areas

1) Client doing a PUT/POST etc. of a large amount of data (BLOCK1).

coap_add_data_large_request() is used which provides a 'finished with data'
callback function as well as adding required options to the PDUs.  This
function calls coap_add_data_large_internal().

Internal coap_handle_response_send_block() sends off the subsequent blocks
(using session->lg_xmit).

2) Server receiving PUT/POST etc. of a large amount of data (BLOCK1).

Internal coap_handle_request_get_block() acknowledges the appropriate blocks
(using session->lg_srcv) and either passes in the individual blocks or the body
depending on whether COAP_BLOCK_SINGLE_BODY is set or not using
coap_context_set_block_mode().

3) Server sending a large data response to GET / observe (BLOCK2)

coap_add_data_large_response() is used which provides a 'finished with data'
callback function.  This function calls coap_add_data_large_internal() as well
as filling in the necessary options for each PDU.

Interal coap_handle_request_send_block() will then send the next requested block
(using session->lg_xmit).

4) Client receiving a large data response (BLOCK2)

coap_send_large() for the initial request sets this up.

Internal coap_handle_response_get_block() will then request the next block when
previous block received (using session->lg_crcv) and either passes the
individual blocks or the body depending on COAP_BLOCK_SINGLE_BODY being set in
coap_context_set_block_mode().

----

The following new internal functions have been added

coap_handle_request_get_block()
coap_handle_request_send_block()
coap_handle_response_get_block()
coap_handle_response_send_block()
coap_add_data_large_internal()

The following new functions have been added.

coap_add_data_large_request()
coap_add_data_large_response()
coap_context_set_block_mode()
coap_get_data_large()
coap_pdu_duplicate()
coap_send_large()
coap_session_init_token()
coap_session_new_token()

The coap_session_init_token() and coap_session_new_token() were added to make
the handling of unique tokens for each request/response easier.
https://datatracker.ietf.org/doc/html/draft-ietf-core-echo-request-tag-10#section-4

New files

include/coap2/coap_block_internal.h:
man/coap_block.txt.in:

New memory types

COAP_LG_XMIT
COAP_LG_SRCV
COAP_LG_CRCV
2021-02-23 18:01:04 +00:00
obgm b7fed2a706 Merge pull request #571 from Delsian/develop
refactor: replace magic numbers with defines
2021-02-23 17:50:06 +01:00
Olaf Bergmann 528c0293b7 README.md: Update build status badges
As travis-ci gets not triggered anymore, continuous integration has
been changed in commit 57a5a7e0 to use GitHub Actions. This change
updates the build status badges to report the GitHub Actions result
for the branches master and develop.
2021-02-23 10:56:28 +01:00
Eug Krashtan 6b58bfa96c examples: replace magic numbers with defines
CoAP response codes in examples represented by non-human-readable magic
numbers. It makes code harder to read, understand, and maintain.
Magic numbers there where replaced by human-readable enums.

Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
2021-02-22 21:20:31 +02:00
obgm f249117691 Merge pull request #579 from mrdeep1/keepalive_doc
DOC: Clarify coap_keepalive(3) documentation
2021-02-22 17:54:59 +01:00
obgm e42d7b7725 Merge pull request #598 from mrdeep1/mbedtls_version
configure.ac: Determine Mbed TLS library version for validity
2021-02-22 14:11:46 +01:00
Jon Shallow febed37ebf configure.ac: Determine Mbed TLS library version for validity
configure.ac:

Add in explicit library version checking as .pc file is not available.

m4/ac_check_cryptolibs.m4:

Add in AX_CHECK_MBEDTLS_VERSION for checking version compatibility.

configure.ac:
src/coap_mbedtls.c:

Correct brand name to Mbed TLS.
2021-02-20 11:08:29 +00:00
obgm 9f778cabca Merge pull request #583 from mrdeep1/doxygen_update
doxygen: Tidy up comments and add in missing modules
2021-02-19 16:04:13 +01:00
obgm 6a087687e8 Merge pull request #574 from mrdeep1/mbedTLS_naming
Mbed TLS: Update MbedTLS and mbedTLS to Mbed TLS to reflect brand name
2021-02-19 10:00:16 +01:00
obgm a15b3006d4 Merge pull request #561 from mrdeep1/tls_options
PKI: Make (D)TLS operation consistent across all TLS libraries
2021-02-19 09:48:55 +01:00
Jon Shallow 05d30e5ef1 PKI: Make (D)TLS operation consistent across all TLS libraries
The use of the verify_peer_cert and require_peer_cert variables in the
coap_dtls_pki_t structure was giving inconsistent results across all the
TLS libraries.  This primarily was down to the large numbers of options
available to control the TLS handshakes in OpenSSL compared to the limited
control available to mbedTLS port which followed later. require_peer_cert is
not easy to control in mbedTLS as it is an implicit configuration based on how
other, not always related, items were configured.

require_peer_cert was used by the server to control whether the client could
use anonymous certificates or not.  This is now controlled by verify_peer_cert.

require_peer_cert variable has been replaced with check_common_ca, so that
the OpenSSL functionality can continue, but enable GnuTLS / mbedTLS to
produce the same results.  This allows peers to mutually authenticate (because
the peer certs are signed by the same common CA) or not which was in effect
controlled by verify_peer_cert previously.

If check_common_ca is set, then allow_self_signed is ignored.

If is_rpk_not_cert is set, then all certificate validation is ignored.

In the examples, use of the -R option unsets check_common_ca, so disables
mutual authentication support by having a common CA.  This was needed as
mbedTLS and GnuTLS only have a single trust store for CAs.

configure.ac:

Increase the number of mbed libraries to use when checking for mbedTLS.

examples/client.c:
examples/coap-rd.c:
examples/coap-server.c:

Add in -n (unset verify_peer_cert) option. In the case of coap-server and
coap-rd, make -n refer to verify_peer_cert.
Add in TLS library capabilites in usage().

Update usage() documentation as appropriate, with some changes to fit
everything into a 80 column output.

include/coap2/coap_dtls.h:
include/coap2/net.h:

Update with variable changes, and make the coap_dtls_pki_t parameter const for
the *_context_set_pki() functions.

man/coap-client.txt.in:
man/coap-rd.txt.in:
man/coap-server.txt.in:

Update documentation to reflect the examples option usage.

man/coap_context.txt.in:
man/coap_encryption.txt.in:
man/coap_session.txt.in:

Update with the new variable name and document as appropriate.

src/coap_gnutls.c
src/coap_mbedtls.c
src/coap_notls.c
src/coap_openssl.c
coap_tinydtls.c

Update to make variable usage consistent. Update logging from LOG_WARNING to
LOG_INFO where there is an override of a PKI check failure by one of the
coap_dtls_pki_t variables.

Timing window closed for TLS where the peer does not like a certificate, sends
fatal alert and closes connection.  local then fails on writing the next
handshake - but now also reads in alert and reports on it.

src/coap_io.c:

Update logging from LOG_WARNING to LOG_INFO for EPIPE or ECONNRESET errors in
coap_socket_write().

src/net.c:

Handle the const coap_dtls_pki_t parameter in coap_context_set_pki() function.
2021-02-18 16:51:32 +00:00
obgm df6615bef5 Merge pull request #597 from mrdeep1/easier_troubleshoot
message id: Report everywhere the hex value for consistency
2021-02-16 10:08:23 +01:00
Jon Shallow 2e6cb55a50 message id: Report everywhere the hex value for consistency
coap_show_pdu() reports the Message ID (mid) as a hex value prefixes by i:.
Elsewhere it is reported as an integer or unsigned making those entries
difficult to match up with the reported PDU.

examples/coap-rd.c:
examples/etsi_iot_01.c:
src/async.c:
src/coap_session.c:
src/net.c:

Replace tid=%d, message %d and transaction %d with mid=0x%x for clarity.
2021-02-15 09:47:02 +00:00
obgm 475654021e Merge pull request #595 from mrdeep1/coap_prng_impl
coap_prng.c: Fix missing coap_prng_impl function.
2021-02-15 10:05:33 +01:00
Jon Shallow b0d46deef6 coap_prng.c: Fix missing coap_prng_impl function.
PR #590 unfortunately broke the standard builds.
2021-02-13 10:57:34 +00:00
obgm 9b45575cdf Merge pull request #586 from timgates42/bugfix_typo_updated
docs: fix simple typo, udated -> updated
2021-02-12 15:28:24 +01:00
obgm 85b45e0249 Merge pull request #590 from wenwu-glagle/pull_request
Fix some compile error in windows visual studio
2021-02-12 15:25:28 +01:00
Olaf Bergmann 4185e6215f [CI] main.yml: Enable building on all relevant events and branches 2021-02-12 13:01:39 +01:00
Olaf Bergmann 961afc742e [CI] main.yml: Set -Werror in compile matrix 2021-02-12 12:44:50 +01:00
Olaf Bergmann 16ea2dca63 [CI] main.yml: Enable more checks 2021-02-12 12:44:47 +01:00
Olaf Bergmann 391be3176e [CI] main.yml: Run unit tests with valgrind 2021-02-12 12:40:44 +01:00
Olaf Bergmann 57a5a7e089 [CI] main.yml: basic build steps 2021-02-12 12:09:01 +01:00
Olaf Bergmann 5bcb0a1578 Revert ".github: removed consistently failing github workflow"
This reverts commit 610c3f6bf2.
2021-02-12 12:09:01 +01:00
Olaf Bergmann 2df4850180 net.c: Suppress warning for -Wunused-result
On systems where read() is declared with the attribute
warn_unused_result, a cast to void is not sufficient to suppress the
resulting warning. This change therefore checks the result explicitly.
2021-02-12 12:06:51 +01:00
Olaf Bergmann f681525272 coap-server.c: fix typecast warning for verify_cn_callback
This change fixes a warning output by clang for the cast from void* to
the potentially smaller enum coap_dtls_role_t (-Wvoid-pointer-to-enum-cast).
2021-01-13 15:56:28 +01:00
Olaf Bergmann 238fded2d8 pdu.c: fix heap overflow in coap_pdu_parse_opt()
coap_opt_length() must be called next_option_safe() to avoid
out-of-bound reads for malformed options.

Thanks to Marten Geuking for providing a detailed bug report.
2021-01-13 15:34:09 +01:00
obgm 7e6b2a9ec3 Merge pull request #589 from mrdeep1/now_2021
Update general copyrights to 2021
2021-01-07 12:05:37 +01:00
沈文武 ad01c1d5eb Fix some compile error in windows visual studio
1. since coap_add_option_later() has been removed, so remove
coap_add_option_later in lib-coap-2.(map,sym) and pdu.h
2. [PRNG] need include coap_prng.c into visual studio project too, since new
functions for generating pseudo numbers replace the old macro-based
approach.
3. [PRNG] need define coap_prng() coap_prng_init() coap_set_prng() for
windows too since these function are exported in lib-coap-2.(map,sym)
2021-01-06 10:47:24 +08:00