Commit Graph
382 Commits
Author SHA1 Message Date
Olaf Bergmann 2cae4ff662 coap_resource_internal.h: include uthash.h 2021-04-29 12:41:33 +02:00
Olaf Bergmann 07ac47ae73 resource.h: remove uthash from public API
As the uthash macros have been moved to coap_resource_internal.h by
PR #582 [1], see commit da18643, the convenience macros and uthash.h
inclusion can be removed from resource.h

[1] https://github.com/obgm/libcoap/pull/582
2021-04-29 12:41:33 +02:00
Jon Shallow 14cf0fe9e5 struct: Remove struct prefix for structures that are typedef'd 2021-04-26 16:52:14 +01:00
obgm 8c4a566313 Merge pull request #661 from mrdeep1/const_pdu
net.h: Make request PDUs const in functions
2021-04-26 17:32:48 +02:00
Jon Shallow 17b7c13435 net.h: Make request PDUs const in functions
Now that coap_method_handler_t passes in the request PDU as const, make
functions that have request PDUs as a parameter const for that parameter.
2021-04-26 08:00:26 +01:00
Jon Shallow f436961084 coap_session.c: Correct coap_session_get_max_retransmit() name
Make things consistent.
2021-04-23 09:11:19 +01:00
Jon Shallow 23f8a531b1 Nits: Fix documentation
Remove a duplicate definition.
2021-04-22 16:47:35 +01:00
Jon Shallow 5bcd89da01 handlers: Make parameters const where appropriate
Also remove the unneeded parameters which can easily be derived - e.g context
and token.
2021-04-22 07:18:47 +01:00
Olaf Bergmann 2e54ca5252 pdu.[hc]: make token argument const in coap_pdu_duplicate() 2021-04-21 14:38:54 +02:00
Olaf Bergmann 3f7ba0afc8 Bump API version to 3, release candidate 2 2021-04-21 14:38:54 +02:00
Jon Shallow 84a69c7436 tls: Update coap_session_get_tls() to return actual TLS information 2021-04-21 09:25:57 +01:00
obgm 75a41b7aed Merge pull request #650 from mrdeep1/lwip_warnings
lwip: Fix compiler warnings
2021-04-21 09:52:11 +02:00
Jon Shallow ac7ad8cd46 lwip: Fix compiler warnings
There still is a #warning for inet_ntop().
2021-04-20 20:08:03 +01:00
Jon Shallow ab78bc8254 coap_dtls.h: Move internal structures and functions int coap_dtls_internal.h
This removes the functions etc. being available in the standard header files,
but not available in the dynamic library.
2021-04-20 17:05:38 +01:00
obgm 04c641f7f0 Merge pull request #639 from mrdeep1/obf_pdu_t
coap_pdu_t: Obfuscate coap_pdu_t for applications
2021-04-20 15:22:08 +02:00
Olaf Bergmann 9e3ba503ec coap_dtls.h: Fix doxygen warning
This change removes a doxygen comment starter because doxygen is
getting confused otherwise because of the immediately preceding
documentation group start.
2021-04-20 14:15:51 +02:00
Jon Shallow e4e067e5fb coap_pdu_t: Obfuscate coap_pdu_t for applications
Move coap_pdu_t to coap_pdu_internal.h.

Move internal PDU based function definitions to coap_pdu_internal.h.

Replace most references to "struct coap_pdu_t" with "coap_pdu_t".

Create new enum coap_pdu_type_t, enum coap_pdu_code_t and coap_option_num_t,
using them where appropriate for clarity of documentation.

Provide new functions to allow applications to access/update parts of
coap_pdu_t as appropriate and document as appropriate.

Update examples to use these new access functions where appropriate.
2021-04-20 10:31:14 +01:00
Olaf Bergmann fd5ecf5697 Add in configuration option for async (separate responses)
The new configuration option --disable-async now allows to switch
of support for asynchronous operations.

The new function coap_async_is_supported() can be used to check
if the library was built with async support.
2021-04-20 10:36:48 +02:00
obgm b9989ef485 Merge pull request #645 from mrdeep1/mcast_delay
Multicast: Add in response delay
2021-04-20 10:31:57 +02:00
Jon Shallow e008d905fd Multicast: Add in response delay
See https://tools.ietf.org/html/rfc7252#section-8.2

Also updated coap_find_async() to search on token instead of mid as
mid is not used in reliable transports.
2021-04-19 11:09:19 +01:00
Jon Shallow 028b3062f6 internal structs: Obfuscate coap_packet_t and coap_socket_t for applications
Move coap_socket_t and coap_packet_t to coap_io_internal.h.

Move internal io based function definitions to coap_io_internal.h.

Replace most references to "struct coap_socket_t" with "coap_socket_t" and
references to "struct coap_packet_t" with "coap_packet_t".
2021-04-16 22:08:10 +01:00
obgm d9ff2f0ff7 Merge pull request #630 from mrdeep1/obf_async_t
coap_async_state_t: Obfuscate coap_async_state_t for applications
2021-04-16 20:13:23 +02:00
Olaf Bergmann 1b15bf244f coap_net_internal.h: add missing doxygen group end marker 2021-04-16 18:27:55 +02:00
Jon Shallow dc1ca3c001 coap_async_state_t: Obfuscate coap_async_state_t for applications
Move coap_async_state_t to coap_async_internal.h and rename to coap_async_t
as it no longer has any state.

Refactor the async logic to simplify usage and provide libcoap based delay
functionality support for request/response traffic such as multicast.  Let
libcoap decide when the delayed response is to be sent.

Move internal async based function definitions to coap_async_internal.h.

Replace most references to "struct coap_async_state_t" with
"coap_async_t".

Provide new functions to allow applications to access parts of
coap_async_t as appropriate.

Update examples to use these new access functions where appropriate.

Add in new man page.
2021-04-16 14:29:52 +01:00
Jon Shallow f8d9af4b93 coap_context_t: Obfuscate coap_context_t for applications
Move coap_context_t and coap_queue_t to coap_net_internal.h.

Move internal context and queue based function definitions to
coap_net_internal.h.

Replace most references to "struct coap_context_t" with "coap_context_t".

Provide new functions to allow applications to access parts of coap_context_t
as appropriate and document these functions.

Update examples to use these new access functions where appropriate.

For the man documentation, move the server session setup functions to (new)
coap_endpoint_server(3) and update coap_context(3) with all the context access
functions as these are common to both the client and server.
2021-04-15 17:27:02 +01:00
Jon Shallow 0c3928f536 coap_session_t: Obfuscate coap_session_t for applications
Move coap_session_t and coap_addr_hash_t to coap_session_internal.h.

Move internal session based function definitions to coap_session_internal.h.

Replace most references to "struct coap_session_t" with "coap_session_t".

Provide new functions to allow applications to access parts of coap_session_t
as appropriate and document these functions.

Update examples to use these new access functions where appropriate.

For the man documentation, move the client session setup functions to (new)
coap_endpoint_client(3) and update coap_session(3) with all the session access
functions as these are common to both the client and server.
[coap_endpoint_server(3) will be created when coap_context_t is obfuscated.]
2021-04-09 13:13:46 +01:00
obgm 4426fa2a69 Merge pull request #624 from mrdeep1/versioning
versioning: Include api version in non-posix coap_config.h/coap.h .in…
2021-04-08 14:29:14 +02:00
Jon Shallow 91737ccb46 versioning: Include api version in non-posix coap_config.h/coap.h .in files
Add in some new .in files, but still keep original files in distribution
files.

Essentially, use coap@LIBCOAP_API_VERSION@ (or equivalent) instead of
coap2. so resultant files have the correct value.

coap_config.h.lwip.in: (new)
coap_config.h.riot.in: (new)
include/coap2/coap.h.windows.in: (new)

As per https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html, many of the
coap2/ prefixes are not required for #include, so these have been removed.

Make sure that the test suite accesses the latest source version of
coap@LIBCOAP_API_VERSION@/coap.h by creating a tests/test_common.h.in that
makes the correct tests/test_common.h which is included in all of the test
suite files.
2021-04-07 13:01:42 +01:00
Jon Shallow 640ede340e COAP_INVALID_TID: Inform this is deprecated and to use COAP_INVALID_MID
Doxygen comment only, but allow COAP_INVALID_TID to still be used.
2021-04-07 11:48:03 +01:00
obgm 7906bcf2a3 Merge pull request #613 from mrdeep1/message_id
message id: clean up documentation usage of transaction which is message id
2021-03-18 13:52:10 +01:00
obgm 9410aa5070 Merge pull request #619 from mrdeep1/large_mcast
mcast block2: Support mcast request with block2 responses
2021-03-18 13:51:53 +01:00
Jon Shallow a34228c80f multicast: Add in IPv4 and update IPv6 multicast support
include/coap2/net.h:
src/net.c:

Update code using #587 as a base to fix potential issues.

Fixes CID 1502429

CMakeLists.txt:
cmake_coap_config.h.in:

Test for <net/if.h>

examples/coap-rd.c:
examples/coap-server.c:
man/coap-rd.txt.in:
man/coap-server.txt.in:

Add in -G option to support specifying interface to use for multicasting.
Otherwise, the interface allocated by the O/S is used depending on the
address (if any) bound to.

man/Makefile.am:
man/coap_context.txt.in:

Document the coap_join_mcast_group_intf() function.

src/coap_debug.c:

Make sure that coap_print_addr() returns a NULL terminated buffer.
2021-03-17 17:43:14 +00:00
Szabolcs Szekelyi 42b2f03470 Allow network interface name to be specified when joining multicast group
This change renames `coap_join_mcast_group` to `coap_join_mcast_group_intf`
and adds an extra `const char *ifname` parameter to specify the interface
name.

A `coap_join_mcast_group` macro is defined to maintain backwards API
compatibility.

`coap_is_mcast` has been modified to recognize IPv6-mapped IPv4 multicast
addresses. Without this `coap_network_send` treats these addresses as
unicast which makes `semdmsg` fail with EINVAL.

Examples have been updated to use the new call.
2021-03-17 17:25:31 +00:00
Jon Shallow 50095d343a mcast block2: Support mcast request with block2 responses
The first block response is unicast, and the client requests the further blocks
using unicast.  https://tools.ietf.org/html/rfc7959#section-2.8

However, the hash for the server lookup of incoming data is based on
coap_addr_tuple_t which includes the local address - which changes between
receipt of mcast and unicast requests.  This causes 2 sessions to be set up,
and the subsequent request/responses are treated as individual block random
access causing mismatch of information by the client.

Fix is to hash only on the remote address (IP + port) and local port for
servers.
2021-03-16 11:32:59 +00:00
Jon Shallow 48a680359d Block2: Fix ordering issue when calling coap_add_data_large_response()
If the response code was set after calling coap_add_data_large_response(),
the continuing blocks were sent with code 0.00.

Now check following call to response handler that the correct code is held
within the lg_xmit information.
2021-03-10 13:12:45 +00:00
Jon Shallow 48ae6b0fdc message id: clean up documentation usage of transaction which is message id
CoAP transaction id was formerly defined as a hash of the remote address and
message id of the CoAP PDU.  It now only refers to, and is used as, the
message id.

Replace occurences of 'transaction id' with 'message id' to reflect naming in
RFC7252.

Correct the definition of coap_tid_t to what it actually represents.

Replace occurrences of coap_tid_t with coap_mid_t.

Replace uses of tid with mid

Remove unused function coap_find_transaction().
2021-03-08 18:49:30 +00:00
obgm ae752e9e7a Merge pull request #612 from mrdeep1/coap_unused
COAP_UNUSED: Remove UNUSED and UNUSED_PARAM and use COAP_UNUSED instead
2021-03-08 18:43:45 +01:00
Jon Shallow 0c031d7904 include: Move header files into libcoap namespace
I.E. '#include "mem.h"' becomes '#include "coap2/mem.h"'

This prevents header name clashes.

Replacement for #487
2021-03-08 16:45:02 +00:00
Jon Shallow 4a264b2b4c COAP_UNUSED: Remove UNUSED and UNUSED_PARAM and use COAP_UNUSED instead
Remove the UNUSED and UNUSED_PARAM definitions and use a single definition
of COAP_UNUSED as defined in libcoap.h

Replace all UNUSED / UNUSED_PARAM usages with COAP_UNUSED.
2021-03-05 11:49:34 +00:00
Jon Shallow 640bb4e667 variables: Remove size changing warnings when using Visual Studio
Change some of the types of variables, and cast change sizes where known to
be safe.

There still are some C4116 warning and a couple of C4090 warning which are OK,
so disabled by a #pragma.
2021-03-03 12:23:25 +00:00
obgm b1ababec35 Merge pull request #607 from mrdeep1/ubuntu_20_4
Ubuntu 20.4: Fix builds as Ubuntu 20.4 will be used by github workflows
2021-03-01 18:26:16 +01:00
Olaf Bergmann dc888cb6c2 ut{hash,list}.h: Updated to uthash version 2.3.0 2021-03-01 18:07:37 +01:00
Jon Shallow c8ab318e48 Ubuntu 20.4: Fix builds as Ubuntu 20.4 will be used by github workflows
.github/workflows/main.yml:

Build all the cmake TLS variants.

CMakeLists.txt:

Add in missing file.

examples/tiny.c:
include/coap2/encode.h:

Move COAP_PSEUDOFP_ENCODE_8_4 functions from encode.h to tiny.c.
Fix COAP_PSEUDOFP_ENCODE_8_4_DOWN 'ls' ordering complaint.

man/examples-code-check.c:

Fix compile warning, allow 'Unused but set variables' in examples and set
-Werror when compling the examples.

examples/lwip/Makefile:

Remove  compilation option -fpack-struct
2021-03-01 15:47:55 +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
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
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 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
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