Commit Graph
230 Commits
Author SHA1 Message Date
jcmichelou f81cb43fd3 session, pdu: Enforce maximum message size. 2017-10-21 16:11:12 +02:00
jcmichelou dfff930805 io, net: Add TCP accept/connect/read/write 2017-10-21 16:11:12 +02:00
jcmichelou bcfd7a0753 pdu: add support for TCP-style headers
Make coap_pdu-t independent of the header style.
Use C99 sized types when applicable.
Use transaction ids in host byte order in the library.
Make coap_pdu_t payload storage grow on demand.
Add parsing and encoding of PDUs with UDP or TCP style headers.
Adapt examples and unit tests to the new PDU format.
2017-10-21 16:11:11 +02:00
obgm c1254c1be8 Merge pull request #111 from spinetix/build-fixes
Assorted build fixes
2017-09-21 12:48:10 +02:00
Diego Santa Cruz 9b12571804 Makefile.am: fix building outside of source tree
When building outside the source tree compilation fails on
examples, because the libcoap headers expect to be all in the
same directory but coap.h is generated under the build
directory, so it is necessary to add an extra include path
for it.

Also, build directories should always appear before source
directories in the include path, so that any leftover
generated files in the source tree are ignored.
2017-09-20 10:48:54 +02:00
cladmi 57a3b59060 coap-server: fix unused 'request' parameter 2017-09-12 15:48:58 +02:00
jcmichelou 30619691e2 resource.[ch], uri.c[ch]: Query string dependent observe.
Remember the query string used during the observe request and pass it to the resource handler.
Support partial notification of observers based on the query string.
2017-09-08 19:50:34 +02:00
Olaf Bergmann 5c079b72d9 coap_session.[hc]: make message id session-local
The message id in the CoAP header is used for reliability when
transferring a CoAP PDU over a non-reliable transport protocol
such as UDP. For message de-duplication, it is useful to have
a monotonously increasing number space within a session. Therefore,
the context-global value has been moved to coap_session_t.
The function coap_new_message_id() now takes a coap_session_t
object as its argument.
2017-08-18 14:15:20 +02:00
John Carter d7ebf14395 coap-server.c: fixed wait time for coap_run_once() invocation
In the main of examples/coap-server.c wait_ms was set to
COAP_RESOURCE_CHECK_TIME * 1000, then coap_run_once() was invoked
with parameter timeout_ms as COAP_RESOURCE_CHECK_TIME * wait_ms,
i.e., squaring the resource check time.

This bug has been fixed by removing COAP_RESOURCE_CHECK_TIME from
the call to coap_run_once().

Signed-off-by: Olaf Bergmann <bergmann@tzi.org>
2017-08-08 12:23:41 +02:00
Olaf Bergmann e77c3565cb client.c: show outgoing and received PDUs in log level INFO
coap-client now prints PDUs that are sent and received in log level
INFO so that these are output with '-v6' or higher. These messages
are now visible without turning on the full debug.
2017-08-03 15:24:36 +02:00
Olaf Bergmann f2ebb4f926 coap-rd.c: removed unused signal handler 2017-08-02 21:30:46 +02:00
Olaf Bergmann 8f37e20f85 coap-server.c: removed parameter local_if from check_async()
coap_async_state_t now contains a reference to the session that is
associated with the respective async state. As the response must
be sent over this session, the local_if parameter of check_async()
is not used anymore and can be removed.
2017-08-02 21:26:55 +02:00
Olaf Bergmann 5f7f043ad6 client.c: fix compiler warning for unused transaction id
coap_send() now takes ownership of the coap_pdu_t object passed
as second argument. Therefore, it is no longer necessary to release
the PDU structure in case of an error.
2017-08-02 21:20:25 +02:00
Olaf Bergmann 8423ebbe8b client.c: allow empty user names
Zero-length strings passed to -u are valid user names for DTLS.
The function cmdline_read_user() therefore returns 0 when the
argument passed with option '-u' is an empty string.
2017-08-02 21:17:07 +02:00
Olaf Bergmann 44f392d29a client.c: added new method names from RFC 8132
Updated the method names for coap-client option '-m' to include
FETCH, PATCH, IPATCH (see [1]).

[1] https://tools.ietf.org/html/rfc8132
2017-07-18 11:43:23 +02:00
Olaf Bergmann 5687681d71 {tests/examples}/Makefile.am: add DTLS variables for static linkage
Statically linked executables require DTLS_CFLAGS and DTLS_LIBS.
2017-07-10 15:33:39 +02:00
jcmichelou 7fb4ace2b7 Fix for the signedness warning with gcc.
Compact coap_address_t.
Use coap_queue_t for all queues.
OpenSSL warning for close alert should be info level.
Fix OpenSSL log level not working.
Use the application defined MTU in OpenSSL.
coap_log() optimization to avoid generating the log message text before testing the log level.
coap_can_exit() should check the new retransmit queues.
Fix retransmit time sometimes not correctly computed relative to sendqueue_basetime.
Add coap_write() API call for applications with their own main loop.
2017-06-29 18:12:46 +02:00
jcmichelou b2fe4a64de Make MTU configurable.
Use static or stack storage for coap_packet_t.
2017-06-26 17:34:01 +02:00
jcmichelou 9490a0c8ab Fix bug in setting the OpenSSL log level make its use consistent with tinydtls
Rename session.c and session.h to coap_session.c and coap_session.h
Use length to PSK hint and identity
Improve packet loss testing
2017-06-22 16:02:03 +02:00
jcmichelou adf1238eae Add DTLS retransmit and recovery.
Add lossy networks debug option in examples.
2017-06-21 20:40:15 +02:00
jcmichelou 8353417afb Added session management with simpler DTLS lib API.
Added DTLS support with OpenSSL.
2017-06-18 20:09:47 +02:00
jcmichelou 5b1a8f67bf Implement coap_session_t concept for POSIX. 2017-06-15 18:42:42 +02:00
jcmichelou b2ab881ad4 Fix the result of dtls branch merge so that all the examples work (DTLS support not enabled yet) 2017-06-13 14:38:30 +02:00
jcmichelou 1c79a4b977 Merge remote-tracking branch 'remotes/obgm/dtls' into dtls-dev with tinydtls support
# Conflicts:
#	Makefile.am
#	configure.ac
#	examples/client.c
#	examples/coap-rd.c
#	examples/coap-server.c
#	include/coap/address.h
#	include/coap/coap_io.h
#	include/coap/net.h
#	include/coap/prng.h
#	libcoap-1.map
#	libcoap-1.sym
#	src/net.c
#	src/platform/posix/coap_io.c
2017-06-12 17:26:25 +02:00
jcmichelou 78148d0c20 Merge develop into win32 2017-06-10 16:19:12 +02:00
Olaf Bergmann 6d7ba61ae0 libcoap-1.pc: fix pkg-config include path
This change excludes the coap subdirectory from the include path
reported by pkg-config --cflags to avoid name conflicts with other
installed packages. Applications now must add the prefix 'coap/'
to include directives for libcoap header files, e.g.

  #include <coap/coap.h>

Jean-Claude Michelou has reported this problem in Bug #82 [1].

[1] https://github.com/obgm/libcoap/issues/82

A minimal Makefile now could look be written as:

  PKG_LIBCOAP=libcoap-1
  CPPFLAGS=$(shell pkg-config --cflags-only-I $(PKG_LIBCOAP)) -DWITH_POSIX
  LDFLAGS=$(shell pkg-config --libs-only-L $(PKG_LIBCOAP))
  LDLIBS=$(shell pkg-config --libs-only-l $(PKG_LIBCOAP))
2017-06-01 12:33:04 +02:00
jcmichelou 9e8a693ffd Fix typo on ipv6 notation for the multicast group address for coap. 2017-05-05 20:48:18 +02:00
jcmichelou 9b647d5d05 Add visual studio 2015 solution and project files for building libcoap on windows.
Merge changes from PR #47 related to windows platform support.
Add full windows platform support including correct error checking and working regression tests and examples.
Remove need to build applications using libcoap with -DWITH_POSIX and to include coap_config.h. This applies to the examples as well.
2017-05-05 20:29:10 +02:00
Olaf Bergmann 771f013b6e coap-server.c: fixed resource check time calculation
This change is a fix for issue #72 [1].

[1] https://github.com/obgm/libcoap/issues/72
2017-04-12 22:40:34 +02:00
Olaf Bergmann dc91eb9a1a client.c: allow user name and key to be empty
RFC 4279 allows psk_identity and psk to have a length of zero, so
-u and -k now are optional for coaps: resources.
2017-04-12 21:32:30 +02:00
Pawel Winogrodzki 9adc4eb6a7 Fixing /W4 warnings for Windows builds.
Removing all of the /W4 level warnings from the code.
No functional changes.

Signed-off-by: Pawel Winogrodzki <pawelwi@microsoft.com>
2017-03-20 15:48:33 -07:00
Olaf Bergmann 6d882f6ed5 client.c: fix TOCTOU for file input
The function cmdline_input_from_file() allocates a chunk of memory
to hold the contents of the given file. As libcoap does not offer
an interface to realloc(), we have to determine the required buffer
size before starting to read from the file, leading to a classical
TOCTOU condition.

This change mitigates the defect by first opening the file and then
calling fstat(). Note that the subsequent fread() call takes the
size of the pre-allocated buffer into account.
2016-12-02 13:43:45 +01:00
Olaf Bergmann 53183e63b2 coap-server.c: discard result of coap_get_data()
coap_get_data() sets the given result parameter size to 0 if no
data is available. The function's result therefore can be neglected
in hnd_put_time().
2016-12-02 13:35:32 +01:00
Olaf Bergmann d9cb9c826c client.c: abort on invalid URI at command line
cmdline_uri() now aborts operation if an invalid URI was passed
as argument.
2016-12-02 13:22:07 +01:00
Joakim Nohlgård f7a17c975e examples/client: Fix Block1 handling for growing block sizes
Only increment block size if it can be done without causing gaps or
overlaps in the byte sequence.

The patch adds a check for alignment to ensure that no gaps appear when
a server responds with a larger block size than the original request
was using.

Ignore the block number sent by the server since that may or may not be
valid. Always recompute based on how many bytes have been sent so far.

Rationale:

Erbium (Contiki CoAP) responds to Block1 request with a Block1 option
containing the server's maximum supported Block1 size (Contiki
configuration option REST_MAX_CHUNK_SIZE). However, the block number
in the Block1 option is the same number as the block number of the
original request.
2016-12-02 09:52:17 +01:00
Olaf Bergmann 85733a6acb client.c: Added missing option -U in usage info
The new option '-U' was missing in the usage information of
coap-client and the corresponding part of the manual page.
2016-11-19 17:39:48 +01:00
Ken Bannister 572e7110e0 Allow client example to not generate Uri-Host and Uri-Port options.
* Via new command line option, -U.
2016-11-19 17:34:44 +01:00
Carsten Schoenert 18f2309759 make: enable out of tree build
The build environment was lacking the possibility to get libcoap
buildable out of tree, simply checkable by the running 'make distcheck'.
Without this fix the users are impossible to build libcoap in a own
folder that's independed from the source containing folder. Typical use
case would be:

  $ mkdir libcoap-build && cd libcoap-build
  $ /path/to/libcoap-source/configure \
      --srcdir=/path/to/libcoap-source \
      --prefix=/somethere/to-install

This commit enables the out of tree build by adding and changing some
needed variables.
2016-10-26 10:46:50 +02:00
Olaf Bergmann d737344b52 client.c: use function parameter in cmdline_subscribe()
cmdline_subscribe() has used the global variable optarg instead of
the local argument that was passed to this function. Changing this
as intended also makes __attribute__((unused)) unneeded.
2016-09-22 12:43:27 +02:00
Olaf Bergmann 2c36cf4ade client.c: fixed malformed mode-line 2016-09-22 12:41:19 +02:00
chrysn d43d92e40b examples/lwip: depend on coap.h
The handcrafted Makefile will not attempt to build the coap.h, but will
indicate to the user how to generate it.
2016-06-22 12:51:46 +02:00
chrysn 6b6840599a lwip: cleanups of leftover variables and similar compiler warnings
note on coap_read removal: as the lwip implementation currently launches
the package handling right from the recv callback, a coap_read function
is not meaningful (as it is in posix or contiki where it actively
fetches the messages from the network buffer).
2016-06-22 12:38:01 +02:00
chrysn 909d863a4e lwip: Use latest version
This drops the cumbersome mintapif mechanisms from server.c, fixes
header troubles that have popped up probably during the header cleanups,
drops old workarounds and enables IPv6.
2016-06-22 12:37:27 +02:00
Olaf Bergmann 392deff2d7 Makefile.contiki: Added -Os to remove undefined symbol
handle_periodic_timer() in rpl-timers.c relies on the optimizer to
remove the if(0)-guarded call to rpl_ns_periodic() when storing
mode is selected. This does not happen with clang's default options
and thus leads to an error for the undefined reference at link time.

This modification adds -Os to fix this.
2016-06-10 16:41:53 +02:00
Olaf Bergmann 68d910f4fe examples/contiki/Makefile: use --depth 1 for cloning Contiki
This change avoids cloning the entire Contiki history when building
the Contiki server example.
2016-06-10 15:10:02 +02:00
Olaf Bergmann a267d3a2b0 server.c: fixed Contiki-related debug functions
The debug function for printing lladdress have been renamed and moved
to net-debug.h. This change now includes this header and uses the
appropriate macros instead.
2016-06-10 15:07:25 +02:00
Olaf Bergmann 5f9579b01f client.c: Pass coap log level to DTLS library
The log level now is set by the new function coap_dtls_set_log_level().
2016-04-15 13:18:31 +02:00
Olaf Bergmann 022238df4d coap-server.c: DTLS server with default credentials for PSK
The example server creates a new endpoint for DTLS-secured traffic.
The secure endpoint is bound to the port number of the unsecure
port plus one (i.e. if the default port number 5683 is used for
cleartext CoAP traffic, the secure port is bound to 5684).

This server uses the credentials "Client_identity" as user name and
"secretPSK" as password for testing. DO NOT USE THIS FOR PRODUCTION.
2016-04-08 15:14:20 +02:00
Olaf Bergmann 094f733440 client.c: added command line options for DTLS credentials
The new option -u allows setting the user name (aka PSK identity) and
-k is used to specify the corresponding secret (the PSK).
2016-04-08 15:14:20 +02:00
Olaf Bergmann e3b82756c0 dtls: create DTLS session for outgoing NON messages 2016-04-08 15:14:20 +02:00