Commit Graph
25 Commits
Author SHA1 Message Date
Jon Shallow 084c866c69 coap_startup: Make coap_startup() first function call in examples
This then makes sure that all things libcoap are properly initialized
before use, and coders realize they need to do this.

Note: coap_new_context() continues to make sure that coap_startup()
is invoked if not done previously, but this may be too late.
2023-07-25 13:50:18 +01:00
Jon Shallow 3755358b7d pre-commit: Include re-styled LwIP and Contiki example files to checks 2023-07-06 11:45:47 +01:00
Jon Shallow 5c1e7cae34 Async: Invert WITHOUT_ASYNC define to COAP_ASYNC_SUPPORTED for clarity
Prevents possibility of name clashes when integrating with other code / OS.
2023-06-15 11:01:22 +01:00
kkrentz 79c66705a1 Updates Contiki-specific code to Contiki-NG 2023-02-08 16:05:09 +00:00
Jon Shallow 68f1a6eff3 log_levels: Replace usage of syslog LOG_ with COAP_LOG_
This removes the reliance of syslog definitions in libcoap by using libcoap's
version.
2022-12-17 12:38:31 +00:00
Jon Shallow 4b54c0d9ef logging: Use new logging macros for examples and man pages
Drop the use of syslog LOG_DEBUG etc. for coap_log() and use the
coap_log_debug() etc. macros which make use of COAP_LOG_DEBUG etc.

Application examples updated, as well as the man page examples.
2022-12-09 14:55:39 +00: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 3f7ba0afc8 Bump API version to 3, release candidate 2 2021-04-21 14:38:54 +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
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 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 afefd95ceb coap_io_process: Fix 1ms busy loop and indefinite sleep
Replace COAP_RUN_BLOCK with COAP_IO_WAIT and COAP_RUN_NOBLOCK with
COAP_IO_NO_WAIT for naming clarity.

Instead of COAP_IO_NO_WAIT being 1, make it -1 to fix 1ms busy loop.
Handle the case when coap_io_prepare_io returns 0 to prevent indefinite
select() wait.

include/coap2/net.h:

Make the timeout_ms parameter uint32_t in coap_io_process*() functions to
make sure special case of COAP_IO_NO_BLOCK is correctly handled on different
architectures.
Update COAP_IO_NO_BLOCK to -1.

src/coap_io.c:

Fix the 1ms busy loop and potential infinite wait in the non epoll case.

man/coap_io.txt.in:

Update documentation to reflect the changes.

examples/coap-server.c:
examples/contiki/server.c:

Update to use COAP_IO WAIT and COAP_IO_NO_WAIT as appropriate.
2020-02-25 22:03:46 +00:00
Jon Shallow 9cf4f10b35 Rename coap_run_once() to coap_io_process()
coap_read(), coap_write() and coap_run_once() are confusing in their names
and do not really describe what they do.

For example, coap_read() does both reading and writing, coap_write() may
do some writing, but primarily is used to determine what should be monitored
and for how long to wait in the following select() or epoll_wait() calls.

coap_run_once() implies that the code is only to be run once - again confusing.

By renaming coap_read() to coap_io_do_io(), this better describes what this
function does.

By renaming coap_write() to coap_io_prepare_io() this better describes what this
function does.

By renaming coap_run_once() to coap_io_process(), this better describes what
this function does.

By renaming coap_io_do_events() to coap_io_do_epoll(), this better describes what
this function does and is associated with.

A wrapper function coap_io_prepare_epoll() has been created, using
coap_io_prepare_io() with some preset values to simplify function usage.

include/coap2/net.h:

Update with the new function names, and deprecate the old functions.  Also
document the fact that coap_io_prepare_io(), coap_io_do_io(),
coap_io_prepare_epoll(), and coap_io_do_epoll() are really internal functions.

Create app_io module for Doxygen.

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

Expose the new functions to applications.

examples/client.c:
examples/coap-rd.c:
examples/coap-server.c:
examples/contiki/coap-observer.c:
examples/contiki/server.c:
examples/etsi_iot_01.c:
man/coap_io.txt.in:
man/coap_observe.txt.in:
src/coap_io.c:
src/coap_io_lwip.c:
src/net.c:
src/pdu.c:

Update using the new function names.

Setting the etimer has been moved out of coap_io_process() into
coap_io_do_epoll(), making the logic easier for applications to use
coap_io_do_epoll() should they need to.  This also gets rid of a
potential timing window where a pending etimer event gets missed.

coap_io_do_epoll() now calls coap_io_prepare_epoll() if the etimer has
triggered removing the need for applications using coap_io_do_epoll() to
set up their own loops if etimer is triggered.
2020-02-13 19:54:48 +00:00
Jon Shallow 2900f72a64 Make coap_subscription_t and coap_endpoint_t opaque to applications
include/coap2/coap_subscribe_internal.h and
include/coap2/coap_session_internal.h contain the information not exposed
to applications.

This internal information was moved out of the respective
include/coap2/subscribe.h and include/coap2/coap_session.h files comprising of
the coap_subscription_t and coap_endpoint_t definitions.

To ease inter .h file dependencies, a new file
include/coap2/coap_forward_decls.h is added to include forward declarations
for both libcoap and applications.

Makefile.am:

Include include/coap2/coap_*internal.h as files for distribution, but not
installed for applications to use.
Include include/coap2/coap_forward_decls.h, so it is installed for
applications.

include/coap2/coap.h.in:

Include "coap_forward_decls.h"

include/coap2/coap_forward_decls.h: (New)

Forward declare structures and typedef the structures defined in
coap_internal.h.

include/coap2/coap_internal.h: (New)

Includes all the required #include files that libcoap internally needs.

include/coap2/coap_session_internal.h: (New)

Include the coap_endpoint_t information taken from
include/coap2/coap_session.h.

include/coap2/coap_session.h:

Remove coap_endpoint_t definition.

include/coap2/lwippools.h:

Add in coap_forward_decls.h and coap_internal.h to handle the LwIP memory
allocations.

include/coap2/resource.h:

Add in "block.h" to allow things to build.

include/coap2/coap_subscribe_internal.h: (New)

Include the coap_subscription_t information taken from
include/coap2/subscribe.h.

include/coap2/subscribe.h:

Remove coap_subscription_t definition.

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

Updated, removing coap_subscription_init().

src/address.c:
src/asyn.c:
src/block.c:
src/coap_debug.c:
src/coap_event.c:
src/coap_gnutls.c:
src/coap_hashkey.c:
src/coap_io.c:
src/coap_io_lwip.c:
src/coap_notls.c:
src/coap_openssl.c:
src/coap_session.c:
src/coap_time.c:
src/coap_tinydtls.c:
src/encode.c:
src/mem.c:
src/net.c:
src/option.c:
src/pdu.c:
src/resource.c:
src/str.c:
src/subscribe.c:
src/uri.c:

Add in '#include "coap_internal.h"' to the source files.
Remove other libcoap #include files.

win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:

Update for Windows build (not tested).

examples/contiki/server.c:
src/coap_io.c:

Remove knowledge of endpoint from the server and update Contiki's
version of coap_run_once() to do the work instead.

====
Other structures (plus some internal required #defines) will follow as
separate PRs.
2019-09-03 11:59:07 +01:00
Jon Shallow f5367ef3de Delete trailing spaces from files, replace TAB with 8*SPACE
"git diff -w" shows no differences

TAB left alone in files that are not C based files or documentation
2018-09-28 17:34:07 +01:00
Jon Shallow d766f9d8ee Update code to build LwIP and Contiki from the examples directory
Update code to use new APIs
[Some code changes modelled on PR #202, some code being moved between files]
Remove #ifdef WITH_LWIP from coap_io.c as file is not used
Add in resource time to lwip
Update for Travis build
Report on Contiki memory allocate failures to ease debugging
Make the different memory type counts configurable by using the -D option
included in a CFLAGS definition to the ./configure command line

.travis.yml
BUILDING
Makefile.libcoap
examples/contiki/Makefile
examples/contiki/README     new
examples/contiki/server.c
examples/contiki/.gitignore (new)
examples/lwip/Makefile
examples/lwip/README
examples/lwip/lwipopts.h
examples/lwip/server-coap.c
examples/lwip/server.c
include/coap/address.h
include/coap/coap_io.h
include/coap/lwippools.h
include/coap/pdu.h
scripts/build.sh
src/address.c
src/coap_io.c
src/coap_io_lwip.c
src/coap_session.c
src/mem.c
src/net.c
src/pdu.c
2018-07-27 15:30:37 +01:00
Jon Shallow 06f57978de Replace str with coap_string_t. Make tokens coap_binary_t
New struct coap_binary_t - same as coap_string_t, used for tokens

Deprecate struct str with the intent of removing it downstream as it
polutes namespace.

Make end of coap_string_t data a NUL.

Updated coap_make_str_const(), removing .length= and .s= to keep upstream
compilers happy.

Update Doxygen for str.h

Files:
examples/client.c
examples/coap-rd.c
examples/coap-server.c
examples/contiki/server.c
examples/etsi_iot_01.c
include/coap/resource.h
include/coap/str.h
include/coap/subscribe.h
man/coap_observe.txt.in
src/net.c
src/resource.c
src/str.c
src/uri.c
tests/test_options.c

Update
2018-07-26 15:45:38 +01:00
Jon Shallow c7e9359f02 Make coap_encode_var_bytes() by replacing with coap_encode_var_safe()
Update code / examples / man pages with the updated function.

include/coap/libcoap.h:
Add in new define COAP_DEPRECATED to generate compiler warnings when used

include/coap/encode.h
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.

Make coap_encode_var_bytes() a wrapper for coap_encode_var_safe() and
mark it as COAP_DEPRECATED for backwards compatability

src/encode.c:
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.

examples/coap-server.c:
examples/contiki/server.c:
Make the ticks resource consistent in case
2018-06-05 09:41:58 +01:00
jcmichelou 3f77c117ea resource: Fix issues #90, #91 and #92
The value of the observe option is kept for each resource rather than being global to the context.
The value of the observe option must wrap to be stay below 2^24.
The value of the observe option must be different from the initial value when a notification is sent.
2017-10-25 20:22:01 +02:00
jcmichelou dfff930805 io, net: Add TCP accept/connect/read/write 2017-10-21 16:11:12 +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
Carsten Schoenert b4973f1d73 fixup argument list for uip_ds6_prefix_add
uip_ds6_prefix_add is using 6 arguments, better use explicit argument
list than let the compiler decide. Some compiler will complain if some
optionally arguments are missed.
2016-01-10 17:49:07 +01:00
Olaf Bergmann d55bd85e14 examples/contiki/server.c: Define clock_offset locally
The global variable clock_offset has been removed from libcoap, so
we have to define our own.
2015-03-11 14:37:18 +01:00
Olaf Bergmann b87f45eeb2 remove unused code from Contiki server example 2015-02-16 17:04:57 +01:00
Olaf Bergmann 4635435771 Created a self-contained Contiki server example
Directory examples/contiki now contains a small example server for
Contiki and a Makefile for platform minimal-net.

Build:

  make contiki     # clones Contiki
  make server      # creates the minimal-net coap server

Run:

Unfortunately, you have to run the server with sudo unless you
set CAP_NET_ADMIN for both, the server executable, and ifconfig
(sudo setcap cap_net_admin+pei ...).

  sudo ./server

Then, add the server's interface address to the tap0 device and
optionally set a default route:

  sudo ip -6 a a aaaa::1000 dev tap0
  sudo ip -6 r a aaaa::/64 dev tap0

Although everything should work now, it does not. I had to send
router advertisements on tap0:

  sudo radvd -C ./radvd.conf

Note that on Debian (and Ubuntu, and ...), radvd will not start
when IPv6 forwarding is disabled (which is usually the case on
end systems). Trying to enable like this did not work for me:

  sudo sysctl -w net.ipv6.conf.tap0.forwarding=1
  sudo sysctl -w net.ipv6.conf.tap0.mc_forwarding=1

Workaround (ugly): get the radvd sources, compile them and use that.
2015-02-16 16:30:28 +01:00