Commit Graph
2302 Commits
Author SHA1 Message Date
Jon Shallow f026f5701e client+server: Reduce code size by building libcoap for client or server only
Add in new ./configure options --enable-client-mode or
--enable-server-mode which by default are enabled.

If --disable-client-mode is set, then disable all the client specific code.
[ COAP_CLIENT_SUPPORT is not defined ]

If --disable-server-mode is set, then disable all the server specific code.
[ COAP_SERVER_SUPPORT is not defined ]

Functions and variables are only #ifdef'd out in the include/coap3/*_internal.h
files.  They cannot be #ifdef'd out in the other include files as
COAP_CLIENT_SUPPORT and COAP_SERVER_SUPPORT are not available for application
compilations. The result of this is if, say, client only API functons are used
in a server application and COAP_CLIENT_SUPPORT is not defined, there will be
linking issues (missing functions).  Providing stub functions unecessarily
increases the code size.

For coap-server, if it is able to provide proxy support, requires both
COAP_SERVER_SUPPORT and COAP_CLIENT_SUPPORT to set up the ongoing sessions.
So, the build environment deliberatly sets SERVER_CAN_PROXY=0 if
COAP_CLIENT_SUPPORT is not available to allow linking.

Some of the tests have to be disabled if COAP_SERVER_SUPPORT or
COAP_CLIENT_SUPPORT is not set.

Code size change indications

   text    data     bss     sum   filename
 155912    1728   12080  169720   libcoap-3-notls.a
 138300    1728   12080  152108   libcoap-3-notls.a --disable-client-mode
 106734    1632   10304  118670   libcoap-3-notls.a --disable-server-mode

 180485    1733   12080  194298   libcoap-3-openssl.a
 160306    1733   12080  174119   libcoap-3-openssl.a --disable-client-mode
 125543    1637   10304  137484   libcoap-3-openssl.a --disable-server-mode

 181755    1728   12080  195563   libcoap-3-gnutls.a
 160972    1728   12080  174780   libcoap-3-gnutls.a --disable-client-mode
 127178    1632   10304  139114   libcoap-3-gnutls.a --disable-server-mode

 165879    1855   12128  179862   libcoap-3-tinydtls.a
 147022    1855   12128  161005   libcoap-3-tinydtls.a --disable-client-mode
 115618    1759   10352  127729   libcoap-3-tinydtls.a --disable-server-mode

 171690    1728   13744  187162   libcoap-3-mbedtls.a
 152099    1728   13712  167539   libcoap-3-mbedtls.a --disable-client-mode
 118786    1632   11984  132402   libcoap-3-mbedtls.a --disable-server-mode
2021-09-30 16:10:52 +01:00
obgm 1091e59ff4 Merge pull request #747 from mrdeep1/session_release
net.c: Protect against session release in coap_io_do_io()
2021-09-30 16:28:52 +02:00
obgm 9291d40f14 Merge pull request #750 from mrdeep1/log_clashes
coap_debug.h: Allow <syslog.h> to be included before and after <coap3/coap.h>
2021-09-30 16:23:15 +02:00
Jon Shallow a7f53b4d6b coap_debug.h: Allow <syslog.h> to be included before and after <coap3/coap.h>
The syslog LOG_ definitions are defined in <syslog.h> and can be defined in
coap_debug.h (wrapped by a HAVE_SYSLOG_H wrapper to prevent duplicaton).

However, the coding order of
  include <coap3/coap.h>
  include <stdio.h
works, but
  include <stdio.h
  include <coap3/coap.h>
but fails if the application build environment does not define HAVE_SYSLOG_H
(as is the case of the examples in the examples/ directory).

The former "just" happens to work as the values of the variables are the same.

This fix is to remove the coap_log_t enum and replace it by simple #define
if LOG_ALERT etc. is not already defined.

Make coap_log_t int to remove Visual Studio compile warnings.
2021-09-28 12:10:04 +01:00
obgm 0061b3fe07 Merge pull request #739 from mrdeep1/coap_can_exit
doc: Document the coap_can_exit() function
2021-09-28 12:54:54 +02:00
obgm 38fa40857a Merge pull request #701 from mrdeep1/token_handling
coap-client: Add in support for generating multiple requests
2021-09-28 09:35:31 +02:00
obgm 8dbfca8c50 Merge pull request #754 from mrdeep1/tls_no_dtls
DTLS/TLS: Support TLS when DTLS is not enabled
2021-09-28 09:27:47 +02:00
obgm 7da4e5cd14 Merge pull request #704 from mrdeep1/mbedtls_tcp
coap_mbedtls.c: Add in TLS support
2021-09-28 09:27:16 +02:00
Jon Shallow 77f8cf5970 DTLS/TLS: Support TLS when DTLS is not enabled
Add in support for when TLS is enabled, but DTLS is not enabled, specific
to Mbed TLS configurations (ESP-IDF).
2021-09-27 21:33:07 +01:00
Jon Shallow 587de900c2 coap_mbedtls.c: Add in TLS support 2021-09-27 21:20:07 +01:00
obgm 3aa11612c1 Merge pull request #751 from hmalpani/develop
coap_mbedtls.c: Fix build fail with client only mbedtls
2021-09-27 17:50:33 +02:00
Harshit Malpani 94b297aae7 coap_mbedtls.c: Fix build fail for client only mbedtls 2021-09-21 17:20:37 +05:30
Jon Shallow cc2648aef6 net.c: Protect against session release in coap_io_do_io()
Wrap the whole iteration with  coap_session_reference() /
coap_session_release() instead of the individual if() statements within.

coap_io_do_epoll() is already suitably protected.
2021-09-08 14:42:56 +01:00
Olaf Bergmann ca44071b8a net.h: do not include sys/select.h in Windows builds
Windows apparently has no select.h header, therefore it is not
included for Windows builds.
2021-09-01 09:50:45 +02:00
Olaf Bergmann e984f38b8f [DTLS] make buffer sizes for psk and psk_identity configurable
The pre-processor values COAP_DTLS_MAX_PSK and
COAP_DTLS_MAX_PSK_IDENTITY now can be set at build time. Both values
default to 64. Static buffer sizes in the TLS library wrappers are
adjusted accordingly.
2021-09-01 09:35:38 +02:00
Olaf Bergmann 54dbc3eeb8 [RIOT] coap_time.h: fix COAP_TICKS_PER_SECOND for undefined XTIMER_HZ
With ztimer usage, XTIMER_HZ is not defined anymore in xtimer.h. As a
workaround, XTIMER_HZ_BASE is used.
2021-09-01 09:34:47 +02:00
Olaf Bergmann 05e7f12d7c net.h: Include sys/select.h for fd_set 2021-09-01 09:34:47 +02:00
Jon Shallow a5c0d12354 doc: Document the coap_can_exit() function 2021-08-04 14:14:37 +01:00
obgm 0585fb4398 Merge pull request #731 from mrdeep1/cmake_mac
CMakeLists.txt: Fix macOS builds by checking for if_nametoindex support
2021-08-02 12:22:32 +02:00
obgm 65e380ab83 Merge pull request #733 from mrdeep1/event_enum
coap_event.h: Make coap_event_t an enum
2021-08-02 12:07:55 +02:00
obgm 12eb676fff Merge pull request #736 from mrdeep1/tiny_fix
tiny.c: Fix message id generation
2021-08-02 12:04:20 +02:00
Jon Shallow a1d78d505d tiny.c: Fix message id generation 2021-08-02 10:09:21 +01:00
Jon Shallow 67f189f134 CMakeLists.txt: Fix macOS builds by checking for if_nametoindex support
Set -D__APPLE_USE_RFC_3542=1 if APPLE

Do not install uthash.h.
2021-08-02 09:21:03 +01:00
Jon Shallow 8ce139d349 coap_event.h: Make coap_event_t an enum
examples/coap-client.c:
examples/coap-server.c:

Explicitly define each enum case to remove complier warnings.
2021-07-31 17:08:10 +01:00
obgm a0754473f9 Merge pull request #729 from mrdeep1/observe_fix
resource.c: Delete previous subscription correctly
2021-07-30 17:56:23 +02:00
obgm 320a1e6e0c Merge pull request #727 from mrdeep1/async_mid
async: Correct MID usage in response
2021-07-30 17:27:49 +02:00
Jon Shallow b0ca3ae643 resource.c: Delete previous subscription correctly
Fix the coap_find_observer_cache_key() function comparison to correctly match
previously set up subscription.

Handle NULL return from coap_cache_derive_key_w_ignore().

Update diagnostic logging.

Start the reported Observe value from 2, to remove confusion with the
usage of values of 1 and 0.
2021-07-29 19:36:47 +01:00
Jon Shallow 98b9179d56 async: Correct MID usage in response
There currently are 2 requirements for async (delayed response)

1. Application support to delay separate response while doing other processing
2. Delay any response for random time if receiving multicast request

The MID is used by the client to match initial response (empty ack or
piggy-backed response).  Any subsequent response (usually the separate
response or unsolicited Observe) should have a different MID as generated by
the server (and are matched using the token).

Fix is to move the tracking of the client MID from coap_register_async()
(so 1. is supported correctly) into handle_request() for multicast requests
(so that 2. continues to be supported correctly).

coap_check_async() will then call the appropriate request handler with the
appropriate MID (application different, multicast same).
2021-07-21 15:15:13 +01:00
obgm a80d462ff5 Merge pull request #722 from mrdeep1/lg_xmit_release
RFC7959: session->lg_xmit not being released for a server
2021-07-07 17:22:08 +02:00
Jon Shallow c61748f4dd RFC7959: session->lg_xmit not being released for a server
Following transmission of a large body by a server using BLOCK2,
session->lg_xmit is not getting released. It does get released when the session
is freed off.

A client doing transmission of a large body idoes release session->lg_xmit.

Timeout lg_xmit after 4 * ACK_TIMEOUT seconds after final block is transmitted.
2021-07-07 15:27:06 +01:00
obgm 545fbc6b31 Merge pull request #721 from Delsian/develop
gnutls:  GNUTLS_CRT_RAW not defined
2021-07-07 15:08:10 +02:00
Eug Krashtan 482be755fe gnutls: GNUTLS_CRT_RAW not defined
Old version of GnuTLS, used in Raspbian,  contains no definition
for GNUTLS_CRT_RAW. This patch fixes build error:
`error: ‘GNUTLS_CRT_RAW’ undeclared`

Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
2021-07-07 15:59:54 +03:00
obgm 208a2e8b9a Merge pull request #719 from mrdeep1/man_1
man: Update man page documentation
2021-07-06 12:30:28 +02:00
Jon Shallow e0d6477b5e man: Update man page documentation
man/coap.txt.in:

Include all the current man pages

man/coap_block.txt.in:

Clarification updates to handle questions being raised

man/coap_resource.txt.in:

Incoming PDU is now no longer NULL if triggered by Observe.
2021-07-06 11:13:47 +01:00
obgm f7c9b13dd6 Merge pull request #715 from mrdeep1/remove_slash
coap_resource_init: Leading '/' is not required for uri_path
2021-07-01 09:49:56 +02:00
Jon Shallow d52986f004 coap_resource_init: Leading '/' is not required for uri_path
Remind users in the documentation that the full path defining the resource in
the uri_path parameter does not normally need a leading '/'.

E.g. It should be "full/path/for/resource", not "/full/path/for/resource".
2021-06-30 14:05:22 +01:00
obgm 97a2c0f186 Merge pull request #716 from mrdeep1/remove_bad_code
pdu.h: Remove unassigned response code COAP_RESPONSE_CODE_OK
2021-06-30 14:21:11 +02:00
Jon Shallow 60c69557f3 pdu.h: Remove unassigned response code COAP_RESPONSE_CODE_OK 2021-06-30 12:11:54 +01:00
obgm 9b6451c365 Merge pull request #713 from mrdeep1/esp_idf_psk
coap_mbedtls.c: Allow ESP-IDF systems to be compiled without PSK support
2021-06-28 15:30:18 +02:00
Jon Shallow 87fab6d573 coap_mbedtls.c: Allow ESP-IDF systems to be compiled without PSK support
Also fix a warning when DTLS is not enabled in ESP-IDF.
2021-06-28 09:52:37 +01:00
obgm 51f5d45333 Merge pull request #711 from technodromega/develop
Fix condition for MBEDTLS_INCLUDE_DIRS
2021-06-23 09:21:37 +02:00
Danijel Hodzic 77d1aae06b Fix condition for MBEDTLS_INCLUDE_DIRS 2021-06-22 19:57:23 +02:00
Olaf Bergmann 1da37b9abb Bump version to 4.3.0 v4.3.0 2021-06-21 10:39:42 +02:00
Olaf Bergmann 64505862d1 update release version to rc4 in configuration v4.3.0-rc4 2021-06-15 10:27:25 +02:00
Olaf Bergmann 80e304271d [tinydtls] update to latest version
libcoap now includes tinydtls commit 59055b8
2021-06-15 10:22:40 +02:00
obgm 7274ffecd0 Merge pull request #702 from mrdeep1/without_async
async: Fix building with './configure --disable-async'
2021-06-14 14:15:36 +02:00
Jon Shallow 9447930cde async: Fix building with './configure --disable-async'
Correct some parameters for the dummy coap_async_*() functions.

Update some documentation for clarity.
2021-06-14 13:04:35 +01:00
Jon Shallow 4bbf25ba33 coap-client: Add in support for generating multiple requests
Demonstrate Token usage for tracking the multiple requests so
that it is easy to see how to extend this for bespoke applications.
2021-06-10 10:35:13 +01:00
Olaf Bergmann 60421db0a5 Add SPDX-License-Identifier to source files
This change adds 'SPDX-License-Identifier: BSD-2-Clause' [1] to
the source code files that originate in the libcoap project.

Note that not all files are tagged because they are pulled in
from other sources and thus may fall under a different license.
More information about these is contained in the LICENSE file.

[1] https://spdx.org/licenses/BSD-2-Clause.html
2021-06-08 18:14:03 +02:00
Olaf Bergmann 677b0c8330 coap.h.windows{,.in}: Remove bits.h 2021-06-08 15:53:23 +02:00