Commit Graph
60 Commits
Author SHA1 Message Date
Olaf Bergmann c217ff6352 plaform/posix/{coap_io,run}.c: fixed LWS in source
Removed trailing whitespace and reformatted indentation as suggested by
Carsten in [1].

[1] https://sourceforge.net/p/libcoap/mailman/message/34988221/
2016-04-08 15:14:20 +02:00
Olaf Bergmann 5ebd003a80 coap_dtls.c: Discard DTLS session on fatal error
When a fatal error is detected for an ongoing DTLS session, any
retransmission is stopped and the session object is released.
2016-04-08 15:14:20 +02:00
Olaf Bergmann 999a46d710 net.c: moved DTLS-specific code to coap_send_impl()
coap_send_impl() now decides if outbound data is passed to coap_dtls_send()
or to the registered network_send callback function.

For coap_send_confirmed() this implies that retransmitted PDUs are
passed to coap_dtls_send() as well, causing retransmissions on the
DTLS layer when the session is established. As long as the DTLS handshake
is not complete, coap_dtls_send() caches the outbound application data
for this particular PDU hence avoiding duplicate messages.
2016-04-08 15:14:20 +02:00
Olaf Bergmann 205efaed92 coap_dtls.c: bugfix: set correct error code for wrong credentials
get_psk_info() now returns appropriate error codes.
2016-04-08 15:14:20 +02:00
Olaf Bergmann a3059ab781 net.c: bugfix: call coap_read_endpoint() only when data available
coap_read_endpoint() should not be called when no data is available
on the attached endpoint.
2016-04-08 15:14:20 +02:00
Olaf Bergmann b734208ed2 coap_event.[hc]: pass library events to application
An application can register a callback function of type
coap_event_handler_t that will be called by the library on certain
events. Currently, the DTLS implementation invokes coap_handle_event()
with session-specific events such as session close or
renegotiation.
2016-04-08 15:14:20 +02:00
Olaf Bergmann 578b38dbfa coap_dtls.[hc]: improved session handling
The handling of DTLS sessions has been improved so that calling
coap_dtls_send() buffers data for later delivery in case of a
successful handshake.
2016-04-08 15:14:20 +02:00
Olaf Bergmann 655e84c040 net.[hc]: Changed interface for coap_handle_message()
The local endpoint object, peer address and data buffer address and
length now are passed as arguments to coap_handle_message(). This
change reverts a previous attempt to provide a more concise interface
for this function that hides the actual implementation-specific data.

As the DTLS implementation needs to deal with this implementation-
specific parts, it has to be made explicit, either by making the
packet abstraction public or passing the relevant parameters
explicitely to coap_handle_message(). As this has worked smoothly
before, this approach has been taken.

This change breaks the LWIP implementation (for now). It will be fixed
when integrating the DTLS code with LWIP in this branch.
2016-04-08 15:14:20 +02:00
Olaf Bergmann 90fb5fdffc dtls: Added basic keystore implementation
coap_keystore.[hc] provides a simple data structure for managing
credentials to be used during DTLS handshake. Each coap_context_t
has its own keystore object that is independent of the actual
DTLS context. Applications can access the keystore during the
entire lifetime of the coap context. The existing implementation
is not thread-safe.
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
Olaf Bergmann 39698f7ba7 dtls: added initial boilerplate for dtls support
coap_dtls.h defines a generic API for DTLS communication. The
initial version will use tinydtls as implementation.
2016-04-08 15:14:20 +02:00
Olaf Bergmann 009934e298 coap_io.c: make socket non-blocking for platform posix
Making the posix sockets non-blocking was missing from coap_new_endpoint().
This wasn't much of a problem because recvmsg() was called only after
select() had indicated that data is available. Setting this flag explicitly
would also allow for peeking into the socket.
2016-04-08 15:14:20 +02:00
Olaf Bergmann 3a127a3816 uri.[hc]: improved support for 'coaps' URI scheme 2016-04-08 15:14:20 +02:00
Olaf Bergmann 63f51418c5 run.[hc]: Add new functions for main loop
This modification provides two new functions, coap_run_once() and
coap_run(), that can be used by applications to drive the library's
I/O logic.
2016-04-08 15:14:20 +02:00
Olaf Bergmann 3d3eb02ad8 net.[hc]: allow multiple endpoints in single context
Endpoints will be attached to the context object using a new function
coap_attach_endpoint(). The sockfd component has been removed from
coap_context_t as it is accessible by the endpoint.
coap_endpoint_t has a new field 'context' that refers to the context
object the respective endpoint has been associated with, or NULL
if it is not attached to any context. An endpoint can be attached
to at least one context at a time.
2016-04-08 15:14:20 +02:00
Olaf Bergmann cfdfd030f9 coap_io.c: Moved to platform/posix/ 2016-04-08 15:14:20 +02:00
Olaf Bergmann 96d572d309 prng.c: move platform-specific PRNG invocation into separate files
This change introduces a new subtree in the library's directory structure.
Platform-specific code now should be placed into the corresponding directory
in src/platform/. To illustrate this, prng.h has been split into three
distinct files, one for each platform (contiki, lwip, posix) and moved into
the respective subdirectory.
2016-04-08 15:14:20 +02:00
Olaf Bergmann 7dea55099f resource.c: bugfix: Memory leak from hash table
The function coap_delete_all_resources() did not free the hash buckets
created by HASH_ADD. Thus, the iterator must call HASH_DELETE to free
the allocated storage.

This bug has been discovered  by
Jean-Michel Julien <Jean-Michel.Julien@trilliantinc.com>
who also provided this fix. See [1] for more information.

[1] https://sourceforge.net/p/libcoap/mailman/message/34994226/
2016-04-06 12:43:27 +02:00
Olaf Bergmann 4a5f381978 src/net.c: bugfix: remove observer on cancel before invoking resource handler
When a client sends a GET request with Observe: 1, it must be removed from
the list of observers before the resource handler is called. Otherwise, it
will add an Observe option to its response.
2016-04-05 14:51:48 +02:00
Vlad Lungu 81865503a1 Use LWIP_PLATFORM_DIAG for LWIP
fprintf() is not guaranteed to be available. Or even printf().

Signed-off-by: Vlad Lungu <vlad.lungu@windriver.com>
2016-02-16 15:44:59 +01:00
Olaf Bergmann 4c299f9da6 Makefile.contiki: Fixed build flags for Contiki-3.0
Some configuration flags have been changed since Contiki version 3.
The Makefile.contiki for building a server example that uses libcoap
as a Contiki app has been fixed. The following builds now succeed:

make -f Makefile.contiki TARGET=minimal-net
make -f Makefile.contiki TARGET=econotag
make -f Makefile.contiki TARGET=mbxxx
2016-02-16 13:12:26 +01:00
Carsten Schoenert 8a8790cfc3 fixup small typos, no functional changes
There are few miss spelled words 'reponse', fixed up into the meaned word
'response'.
2016-01-29 16:31:53 +01:00
onovo1 4c5c0e6c61 Update net.c 2016-01-28 13:57:00 +02:00
Carsten Schoenert f4166a536f coap.h: adding main header file into various source files
After splitting of the platform header part within libcoap some source
files that use functions of the network stack need to include coap.h
(which is including the libcoap.h) to get the platform specific header file
for the network stack.
Sort list of included headers in alphabetical order.
2016-01-10 17:49:07 +01:00
Olaf Bergmann a5b61409a5 coap_io.c: set local address after bind for new endpoint
This fixes a bug reported by Daniel Petrie:

"When the coap-client is used and a local address to bind to is
specified, but the local port is not specified, I get errors for the
response coming in from an unexpected interface and the response is
dropped/ignored."

The solution here is to call getsockname() after successful bind()
in coap_new_endpoint() to set ep->addr to the actual transport
address being used.
2015-10-27 13:05:03 +01:00
Olaf Bergmann 3f5a797776 net.c: fixed critical option check
The limitation of COAP_OPT_FILTER_SHORT to six entries made the
critical option check fail e.g. for Block2. This change hard-codes
the built-in critical options in coap_option_check_critical() so
that up to COAP_OPT_FILTER_SHORT short options and COAP_OPT_FILTER_LONG
long options can be registered dynamically.

Please note that registering critical options that are already known
(i.e. listed in pdu.h and checked in coap_option_check_critical())
is a waste of storage space.
2015-10-01 19:27:50 +02:00
Olaf Bergmann 683337890e bugfix: add flag for CON/NON notification messages
Two new flags COAP_RESOURCE_FLAGS_NOTIFY_NON and
COAP_RESOURCE_FLAGS_NOTIFY_CON have been added to control the
message type for notifications to send. The default type is
COAP_RESOURCE_FLAGS_NOTIFY_NON which can be changed with the
function coap_resource_set_mode().

The observer-specific flag has been removed.
2015-09-29 09:03:18 +02:00
franc0is 11daf0545a Fix coap_ticks platforms with no _POSIX_TIMERS
(cherry picked from commit bde305210e)
2015-09-09 14:04:44 +02:00
Olaf Bergmann 1baa8163b5 coap_time.[hc]: make ticks relative to global offset for POSIX
For POSIX platforms, ticks have been absolute which caused an
overflow on 32-bit architectures. This modification makes values
returned by coap_ticks() relative to a global offset stored
internally in coap_clock_offset.
2015-06-28 15:04:52 +02:00
Olaf Bergmann 155adae29a coap_io.c: Include multicast addresses in is_local_if()
is_local_if() checks if a message's destination address matches
a local interface. As multicast requests are allowed on either
interface, this function now returns true when the destination
address is a multicast address.
2015-06-10 18:25:32 +02:00
Olaf Bergmann ababd3f7f2 net.c: Removed misleading comment
The behavior of coap_send_impl() has been changed long time ago
but this comment was still there.
2015-06-10 18:06:30 +02:00
Olaf Bergmann 91f37ae1a7 coap_io.c: select outbound interface when responding to multicast requests
coap_network_send() uses the address given by local_interface as
source address of outgoing IP packets. For responses to requests
that have been received via IP multicast, this address is a
multicast group and thus must not be set as source in the IP header.

As a workaround, this change clears the address and ifindex so that
the kernel selects a suitable outbound interface.
2015-06-10 17:59:52 +02:00
Olaf Bergmann d989bb174c net.c: Suppress RST and error responses for multicast requests
When a request has been received via IP multicast, negative
responses including RST should not be sent. This modification
uses the new result code COAP_DROPPED_RESPONSE to indicate that
the response was intentionally suppressed. As the error handling
code only checks for COAP_INVALID_TID, no error messages will
be emitted due to this new behavior.
2015-06-10 17:55:36 +02:00
Olaf Bergmann 3c84f5c012 net.c, pdu.h: ensure that valid transaction ids are positive
The calculation of transaction ids did not ensure that the result
is always greater or equal zero. To avoid conflicts with the error
codes returned by coap_send(), the calculation now masks out the
lower half.
2015-06-10 17:46:53 +02:00
Olaf Bergmann 83a06c7969 net.c: removed debug output from function no_response() 2015-06-10 13:07:06 +02:00
Olaf Bergmann 3e10a49c43 debug.c: added option No-Response to list of known option types
With this change, the new No-Response option is recognized by the
helper function msg_option_string() called from coap_show_pdu() for
pretty-printing CoAP messages.
2015-06-07 12:21:58 +02:00
Olaf Bergmann e4e2e57218 option.[hc]: new option filter implementation
The implementation of option filters based on coap_opt_filter_t
has changed to improve support for long option numbers. An option
filter is now a sparse field of a fixed size that can hold up to
COAP_OPT_FILTER_LONG options with a number larger than 255, and
up to COAP_OPT_FILTER_SHORT options with a number of 255 or less.

The space taken by coap_opt_filter_t is
2 * ((((COAP_OPT_FILTER_SHORT + 1) >> 1) + COAP_OPT_FILTER_LONG) + 1),
or 12 bytes with the default settings for COAP_OPT_FILTER_SHORT == 6
and COAP_OPT_FILTER_LONG == 2.

Three new functions have been added to the option filter API:
* coap_option_filter_set() to store an option number in a filter,
* coap_option_filter_get() to check if a filter contains a given
  option number, and
* coap_option_filter_unset() to remove an option number from a
  filter.

The previously existing functions coap_option_setb(), coap_option_getb(),
and coap_option_clrb() continue to work on the new option filter
unchanged but now are deprecated.
2015-06-07 12:21:58 +02:00
Olaf Bergmann 6db8e5172d net.c: fixed calculation of mask bit for no-response option
* The shift in function no_response was off by one bit.
* The response code must be checked, not the request method.
2015-06-07 12:21:58 +02:00
Olaf Bergmann bf9a3c7a1b net.c: Implementation of No-Response option
Response suppression according to draft-tcs-coap-no-response-option-11.
2015-06-07 12:21:58 +02:00
Olaf Bergmann 81d4297b50 option.[hc]: Fix type of option parameter
Since CoAP options can have a numeric type between 0 and 65535, the
type parameter of coap_check_option() must be at least 16 bits.
2015-06-07 12:21:57 +02:00
Olaf Bergmann 519da113a3 debug.c: improved output of zero-length option values
The function print_readable() did not add a terminating zero in case
len == 0. Now, the output buffer will always have a terminating '\0'
when buf has at least one byte free (i. e. buflen > 0). Note that the
function result does not include the trailing zero-byte.
2015-06-07 12:15:30 +02:00
Olaf Bergmann 312fc9251b debug.c: made output of coap_show_pdu() more readable
The new format[0] was inspired by the discussion[1] on the IETF CoRE
mailing list. Changes include:

* Print human-readable message type and method/response code
* Output token included in {...} even if token is empty
* Print human-readable option types
* Print human-readable option values where possible
* Print human-readable Content-Format and Block options
* Print hex string included in <<...>> for binary content,
  human-readable string included in '...' for text content
* Use '::' as payload delimiter if message contains a payload

[0] http://www.ietf.org/mail-archive/web/core/current/msg06069.html
[1] http://www.ietf.org/mail-archive/web/core/current/msg06062.html
2015-06-07 12:15:30 +02:00
Bergmann ab8f4a9e45 coap_time.c: Apple does not support clock_gettime()
Although _POSIX_TIMERS is defined on MacOSX no clock_gettime() is
provided, so we have to fall back to gettimeofday().
2015-03-13 14:03:12 +01:00
Olaf Bergmann 83b19e6f16 resource.c: always include utlist.h and mem.h for all platforms 2015-03-11 16:12:55 +01:00
Olaf Bergmann 2250db4c95 address.[hc]: make coap_address_equals() not inline on POSIX
gcc-4.8 -Winline keeps complaining about the function's size, so
it is now placed into address.c.
2015-03-11 16:08:58 +01:00
Olaf Bergmann 3a78280982 mem.c: Added missing include for coap_resource_t and coap_attr_t 2015-03-11 15:28:10 +01:00
Olaf Bergmann ecda1426ac resource.c: Increase use of coap_malloc_type() and coap_free_type()
coap_malloc_type() and coap_free_type() provide an abstract API for
dynamic memory management on different platforms. resource.c still
is in transition and needs more cleanup.
2015-03-11 14:59:40 +01:00
Olaf Bergmann 65620fde3e resource.[hc]: Replaced custom list structures by utlist macros.
The CoAP resource management is based on uthash and utlist for
platform POSIX but used a custom list implementation for Contiki.
This modification replaces the list handling by utlist macros
entirely. A set of convenience macros has been defined to access
the resources stored in a CoAP context with respect to the
preprocessor symbol COAP_RESOURCES_NOHASH.
2015-03-11 14:28:24 +01:00
Olaf Bergmann 55c6efeca8 coap_split_uri: Check if port number is in valid range
This change is made to resolve the failed URI parser test
t_parse_uri5()
2015-03-09 18:01:34 +01:00
Olaf Bergmann 3e99d6634e Fixed documentation of coap_split_path_impl() 2015-03-09 17:56:08 +01:00