Commit graph

134 commits

Author SHA1 Message Date
Jarno Lämsä 05e0b31fa8 net: lib: coap: Add an asynchronous coap client
The coap client takes requests and provides responses
asynchronously to callback given in a request.
Currently supports only 1 request at a time.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
2023-05-26 09:44:50 -04:00
Lukas Woodtli 12de4018ef net: coap: Add function for getting BLOCK1 option
The function gets the the BLOCK1 option from a received message
and extracts the block number, block size and has-more flag from
it.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-05-15 09:18:09 +02:00
Lukas Woodtli db480169a0 net: coap: Add function for inserting block option for sending
The function adds a block option to a CoAP message. If the message
is a request the BLOCK1 option is added. Otherwise (response) the
BLOCK2 option is added.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-05-15 09:18:09 +02:00
Lukas Woodtli 6a5260394b net: coap: Allow insertion of an option at arbitrary position
The insertion moves the data in the message buffer to make space for
the new option.

Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
2023-02-06 10:02:19 +01:00
Sagar Shah dfd897096d net: lib: coap: method_from_code() API change to return errors.
method_from_code() signature has changed to return error and
the method. In case of an invalid code it returns -EINVAL and
causes coap_handle_request() to return -ENOTSUP.

Fixes: #49498

Signed-off-by: Sagar Shah <sagar.shah@legrand.us>
2022-09-12 10:53:34 +00:00
Sagar Shah 7973483649 net: lib: coap: coap_packet_parse() returns different error values
coap_packet_parse() returns different values depending on error.
It now returns
-EINVAL for invalid input arguments,
-EBADMSG for malformed coap header,
-EILSEQ for malformed options error.

Fixes: #48960

Signed-off-by: Sagar Shah <sagar.shah@legrand.us>
2022-09-02 11:02:38 +00:00
Stephanos Ioannidis 532d2671be net: coap: Remove resource pointer NULL check
This commit removes the resource pointer NULL check inside the resource
enumeration loop of the `coap_well_known_core_get` function because the
expression `(resource + 1)` will never evaluate to NULL (aka. 0).

This fixes the "comparison will always evaluate as ‘true’ for the
pointer operand" warning generated by the GCC 12.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-01 10:47:23 +02:00
Andreas Chmielewski 363e2f3014 net: coap: make coap vars configurable
COAP_DEFAULT_MAX_RETRANSMIT and COAP_DEFAULT_ACK_RANDOM_FACTOR
should be configurable to determine the max transmission
timeout of a CoAP packet.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2022-07-05 21:56:34 +00:00
Andrei Emeltchenko 8dda6b8c37 net: coap: Remove unneeded statement
Assignment is not needed.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-30 10:34:40 +02:00
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Juha Heiskanen 5249e43e54 net: coap: Coap pending allocation fix
When sending 2 or more confirmable message before first one is
writed to socket all messages use same coap pending structure.
Now coap_pending_init() set data pointer which lock allocation
by each call.

Using data pointer for detecting free is more stable than timeout.
Timeout is initialized only before first socket send. Queued packet
may be triggered later than other and may cause that same block is
allocated multiple time.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-29 08:57:30 +02:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Efrain Calderon 6b936c0315 net: coap: Update coap context using payload length
When a file is download, `ctc->current` is increaed by the block
size, which is correct for all the blocks except the last one.

 Once the download is compelted, ctx->current must match
`ctx->total_size`.

Signed-off-by: Efrain Calderon <efrain.calderon@aquarobur.com>
2022-02-02 11:10:57 +01:00
Daniel Leung 8d8369204f net: remove @return doc for void functions
For functions returning nothing, there is no need to document
with @return, as Doxgen complains about "documented empty
return type of ...".

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-01-12 16:02:16 -05:00
Pieter De Gendt 421ecb77a3 net: coap: Add coap_next_block_for_option function
Add a function to update the coap block context from a
packet, according to the block option enum provided.

The existing coap_next_block does not handle block1 transfers
properly because we need to inspect the block1 option
returned by the server. This function is reworked to make use
of the newly introduced one.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-10-27 13:46:19 -04:00
Pieter De Gendt b966ba16a9 net: coap: Fix size1 for block1 transfers
According to RFC-7959:
When uploading with coap block1 requests the server may respond
with a size1 option (together with the response code 4.13).
This to indicate the maximum size the server is able and willing
to handle.

This commit changes the total_size in the current block context
being handled to the optional size1 option value from the server.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-10-27 13:46:19 -04:00
Veijo Pesonen d3f4ae20cf net: coap: adds PATCH and iPATCH methods
Based on on RFC 8132 -
PATCH and FETCH Methods for the Constrained Application Protocol (CoAP)

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2021-10-25 13:26:19 +03:00
Veijo Pesonen 3071e97a3a net: coap: adds FETCH method
Based on on RFC 8132 -
PATCH and FETCH Methods for the Constrained Application Protocol (CoAP)

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2021-10-25 13:26:19 +03:00
Pieter De Gendt 4192c8b83e net: coap: coap_next_token single sys_rand_get call
Improve coap_next_token by using a single sys_rand_get call.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-07-29 11:47:51 -04:00
Robert Lubos b369156e28 net: lwm2m: Fix how payload offset is calculated
Instead of manually computing payload offset, let the CoAP library do
the work, and use the payload pointer returned by the
`coap_packet_get_payload()` function instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-07 07:40:55 -05:00
Robert Lubos 0bc4e7619b net: coap: Fix coap_packet_get_payload function
The function did not work correct for packets generated with Zephyr
APIs, as `max_len` holds the entire buffer size, not the actual packet
size.

Additionally, unify how Payload Marker is handled in the calculation -
currently the coap parsing function adds it to the `opt_len` field,
which is counter-intuitive.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-07 07:40:55 -05:00
Robert Lubos 78e84eb3e7 net: coap: Adjust offset value after packet parsing
It is important that offset is set in the same manner, regardless of the
origin packet - it should indicate the final packet length in both
cases, when the packet is generated on the Zephyr side with CoAP APIs,
and when it's parsed from the UDP datagram. This allows for functions
like `coap_packet_get_payload()` to work correcty in both cases.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-07 07:40:55 -05:00
Pieter De Gendt cdf7d314fe net: coap: Fix coap client observe out-of-order messages
coap_response_received returned NULL if the observe option was out of
order, however it makes more sense to return the coap_reply handler
without actually calling it.

Additionally the reorder check has been modified to partially match
the RFC.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-06-29 10:27:22 -04:00
Eug Krashtan 86fc962a48 net: coap: Keep user data inside message
Keeping user data in the CoAP packet

Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
2021-06-09 18:41:42 +03:00
Maik Vermeulen ae4c5193a3 net: coap: coap_find_options() now returns 0 when options empty
coap_find_options() now first checks if there is actual payload
to parse.

Fixes #34463.

Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
2021-04-22 19:34:11 +03:00
Hubert Miś 5e43418cf9 net: coap: acknowledgement initialization helper
When handling CoAP Confirmable requests, there is a common
Acknowledgement initialization procedure that repeats for each
response packet initialization. This patch adds a function that
simplifies Acknowledgement initialization procedure encapsulating
repeating code.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-15 10:17:11 +02:00
Hubert Miś 77c68aa070 net: coap: clean up token usage in samples and tests
This patch replaces magic numbers with COAP_TOKEN_MAX_LEN value and
removes unnecessary castings of token buffer type.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-02 14:03:01 -05:00
Hubert Miś 22687c34e3 net: coap: define default CoAP version
RFC 7252 (CoAP) specifies value of the Version (Ver) field in the
protocol header to value 1. This patch defines value of the Version
field to make packet initialization easier. All samples and tests
are updated to use the new COAP_VERSION_1 field when initializing
a CoAP packet.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-02 14:03:01 -05:00
Kasun Hewage 7dad85695e net: coap: Fixed discovery response formatting according to RFC6690
CoAP RFC (RFC7252) states that end points should support
the CoRE Link Format of discoverable resources as described in RFC6690
(refer section 7.2 of the RFC7252).

Fixes #31609

Signed-off-by: Kasun Hewage <kasun.ch@gmail.com>
2021-01-27 18:26:13 -05:00
Hubert Miś 0475cd0eae net: coap: Allow encoding packets using data from constant buffers
Token and payload are appended from data buffers to a CoAP packet
being encoded. Keyword const was missing for parameters in functions
appending these parts to a packet.

Now token and paylod can be copied to CoAP packet from constant
buffers, that can be stored in ROM.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-01-26 06:17:41 -05:00
Hubert Miś 759f7454d8 net: coap: define max token length
This patch introduces COAP_TOKEN_MAX_LEN definition in coap.h file.
This definition replaces magic number across CoAP protocol
implementation and CoAP samples.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-01-26 06:17:41 -05:00
Hubert Miś 13aa4b2f9e net: coap: define Content-Format option values
CoAP protocol defines registry of Content-Format option values.
This patch adds this enumeration to coap header file to make it
available to all applications using CoAP protocol. It modifies
code using CoAP service to use new enumeration.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-01-19 16:07:20 -05:00
Robert Lubos c563736bd3 net: coap: Randomize initial ACK timeout
Add Kconfig option to randomize the initial ACK timeout, as specified in
RFC 7252. The option is enabled by default.

Additionally, finetune the default value of COAP_INIT_ACK_TIMEOUT_MS
option, to match the default ACK_TIMEOUT value specified by the RFC
7252. The RFC does not specify the minimum/maximum value of the
ACK_TIMEOUT parameter, but only suggests it should be no lower than 1
second, so adjust the option range to reflect this.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-01-18 23:22:37 -05:00
Robert Lubos 538e19ee2e net: coap: Rework pending retransmission logic
Introduce retransmission counter to the coap_pending structure. This
allows to simplify the retransmission logic and allows to keep track of
the number of remaining retranmissions.

Additionally, extend the `coap_pending_init()` function with `retries`
parameter, which allows to set the retransmission count individually for
each confirmable transaction.

Fixes #28117

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-01-18 23:22:37 -05:00
Robert Lubos 4851611d55 net: coap: Fix long options encoding
`delta_size` was incorrectly used to assess whether extended option
length field shall be used. In result, options larger than 268 bytes
were not encoded properly.

Fixes #31206

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-01-13 08:02:03 -05:00
Eug Krashtan bb378c7201 net: coap: Use MQTT style wildcard in path description:
In 'struct coap_resource' path description:
- the plus symbol represents a single-level wild card in the path;
- the hash symbol represents the multi-level wild card in the path.

This change keeps compatibility with RFC 7252 but allows handling
multiple requests in single function.

Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
2020-08-26 12:31:00 +02:00
Robert Lubos 5bb35892dd net: coap: Parse zero-length option correctly
In case CoAP packet does not carry payload, and the last option is
zero-length, the option structure was not filled with data (opt number
and length). Fix the length check to prevent this from happening.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-06-15 22:13:34 +03:00
Gerson Fernando Budke 1ca95e7bc4 net: coap: Rem macros that uses coap_get_option_int
Clean up and remove macros that uses coap_get_option_int.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2020-06-09 21:25:11 +03:00
Gerson Fernando Budke 76e32ba32b net: coap: Add coap_get_option_int public method
Any CoAP implementation when use at least block transfer or is a server
side need access some CoAP options as integer values. This add a method
at public interface and defines for block wise operations to avoid code
useless code duplication.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2020-06-09 21:25:11 +03:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Kiril Petrov 7305e7b4a2 net: coap: add coap_pendings_clear and coap_replies_clear
Clears whole stack of pendins and replies.

Signed-off-by: Kiril Petrov <retfie@gmail.com>
2020-04-28 20:46:35 +03:00
Robert Lubos df152ab59f net: coap: Add initial tx time to coap_pending structure
So far, coap_pending structure kept track only of the timeout interval
between two consecutive retransmissions. Calculations inside
`coap_pending_next_to_expire` relied only on this value. This approach
gives incorrect results though, in case multiple messages are pending
for retransmission.

For instance, assuming initial retransmission timeout is set to 2
seconds. If some message had been retransmitted already, its timeout
would be increased to 4 seconds. Any new message added to the pending
list would have a retransmission timeout set to 2 seconds, and will be
returned as a first message to expire, no matter how long the initial
message was already on the list.

To resolve this, add a `t0` field to the coap_pending structure. This
field is initialized to the initial transmission time, and is increased
on each retransmission by the retransmission timeout.
`coap_pending_next_to_expire` uses this value to calculate absolute
time, when the next retransmission should take place, and based on this
information returns correctly first pending message to expire.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-28 09:50:45 +03:00
Flavio Ceolin e6204a982e net: coap: Fix possible overflow
Fix possible integer overflow when parsing a CoAP packet.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-04-20 09:12:33 +03:00
Kumar Gala ebbd3cc078 include: Fix use of <atomic.h> -> <sys/atomic.h>
Fix #include <atomic.h> as it has been deprecated and
should be #include <sys/atomic.h>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-10 08:39:37 -05:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
Benjamin Lindqvist 81ccbd96c9 net: coap: Add internal init function to seed message_id
Randomly generating ID the first time coap_next_id() is called is more
in accordance with CoAP recommendations (see
https://tools.ietf.org/html/draft-ietf-core-coap-18, section 4.4)

"It is strongly recommended that the initial value of the
variable (e.g., on startup) be randomized, in order to make successful
off-path attacks on the protocol less likely."

Doing this in a dedicated init function is the cleanest and most
idiomatic approach. This init function is not exposed publically which
means it will be called only once, by the network stack init procedure.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2019-10-04 21:22:55 +03:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Ravi kumar Veeramally f940cec0d0 net: coap: Fix coverity issue
To get u8_t value, just right shift the operands are enough.

Fixes #12298
Coverity-CID: 190635

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-27 10:36:39 +01:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Ravi kumar Veeramally 1e47f26d1c net: coap: Remove legacy CoAP implementation
As we are removing net_app and net_pkt based libraries and
applications, CoAP legacy based libraries and apps are moved
to socket based implementations. So removing legacy CoAP.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-04 16:49:59 -05:00
Aurelien Jarno d3b6c5a755 net: coap: return -EPERM for a resource without requested method
When walking through the coap resources in coap_handle_request, return
-EPERM if a resource exists but does not have the request method. This
allows the caller to catch the error and return a 4.05 message.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-02 13:04:46 +01:00
David B. Kinder 06d78354ae doc: regular misspelling scan
Fix misspellings in documentation (.rst, Kconfig help text, and .h
doxygen API comments), missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-12-26 13:27:14 -05:00
Jukka Rissanen 86689030e8 net: Clarify logging in networking code
Remove network specific default and max log level setting
and start to use the zephyr logging values for those.

Remove LOG_MODULE_REGISTER() from net_core.h and place the
calls into .c files. This is done in order to avoid weird
compiler errors in some cases and to make the code look similar
as other subsystems.

Fixes #11343
Fixes #11659

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Ravi kumar Veeramally 19c598f081 net: coap: Deprecate net_pkt based CoAP library
Deprecating net_pkt based CoAP library due to Socket based
CoAP library.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-22 09:08:46 -05:00
Anas Nashif 3d906dc4c1 net: coap: Move both CoAP implementations into one Kconfig
Two separate folders and Kconfig options causing confusion on
CoAP and CoAP_SOCK implementations. This patch simplifies it.
Current CoAP Kconfig option moved to COAP_NET_PKT.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-22 09:08:46 -05:00
Jukka Rissanen cf063fe85b net: Rename net_is_xxx...() functions to net_xxx_is...()
Unify the function naming for various network checking functions.

For example:
     net_is_ipv6_addr_loopback() -> net_ipv6_is_addr_loopback()
     net_is_my_ipv6_maddr() -> net_ipv6_is_my_maddr()
etc.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 14:52:33 -04:00
Jukka Rissanen 009e4dafa7 net: Make Kconfig template variables prettier
Adding spaces around "=" when definining Kconfig template so
that is more consistent with overall style of these template
variables.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-05 09:01:37 -04:00
Jukka Rissanen dc018376f2 net: lib: Convert coap API to use log level
Use network log level in CoAP library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Taehwa Kang 2bdc5923ad net: coap: Fix Coap coap_option_value_to_int and coap_append_option_int
In coap_option_value_to_int function, when coap option length is 4,
option->value[3] should be shifted by 0 rather than option->value[2].
This doesn't affect the behavior of function but needs to be fixed.

In coap_append_option_int function, when the value is between 0xffff
and 0xffffff(when option length is 3), bit shift operation is wrong.
For example, if the value is 0xABCDEF, by sys_put_be16(val, data)
data[0]=0xCD, data[1]=0xEF, by val >> 16, data[2]=0xAB. So the result
becomes 0xCDEFAB not 0xABCDEF. So, to sys_put_be16 function hand
&data[1] over instead of handing data over and val >> 16 needs to be
set to data[0], not data[2].

Signed-off-by: Taehwa Kang <hegrecomm@gmail.com>
2018-09-28 11:11:17 +03:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Jukka Rissanen 4078e46e7d net: l2/lib: Always have a timeout when allocating a net_buf
Instead of waiting forever for a network buffer, have a timeout
when allocating net_buf. This way we cannot left hanging for a
long time waiting for a buffer and possibly deadlock the system.
This commit adds checks to L2 and network support libraries.

Fixes #7571

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-14 12:17:00 +03:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Ravi kumar Veeramally 6586dba334 net: coap: Fix CoAP observer helper function
sin6_scope_id is not set anywhere and not used. Probably left over
from old ZOAP library. Just address, port and family type are enough
to find registered CoAP observer.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-05-22 08:54:54 -04:00
Michael Scott d07391d386 net: coap: clear more fields in coap_reply_clear()
We only clear 3 of the 6 member variables of the coap_reply structure
in coap_reply_clear().

Let's make sure to reset all of them.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:57:55 +03:00
Michael Scott bb98d8766a net: coap: add COAP_INIT_ACK_TIMEOUT_MS setting
The base CoAP retry setting is quite fast for network technologies
such as LTE-M and LoRa.  Let's add an option to delay retries
a bit longer depending on the need.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:57:55 +03:00
Paul Sokolovsky e82578919a mbedtls: Replace COAP-specific max len setting with generic
Instead of CONFIG_COAP_MBEDTLS_SSL_MAX_CONTENT_LEN, use recently
introduced CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-03-18 09:38:22 -07:00
Robert Chou 6f466cd7e5 net: coap: retransmission for four times
RFC 7252, sec 4.8 [https://tools.ietf.org/html/rfc7252#section-4.8]
The default MAX_RETRANSMIT is 4, current implementation only
retry 3 times. Update next_timeout() to return one more retry.

Also, add a TODO for random generated initial ACK timeout

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-02-13 13:06:15 +02:00
Michael Scott 2fc554b8fc crypto: config: config-coap: add CONFIG for setting max content length
The CoAP samples use an MBEDTLS config "config-coap.h" which could be
re-used by the LwM2M sample, except that most servers use a larger
maximum content length setting of 1500 bytes.

Let's add a CONFIG to set this for users of the CoAP lib and set the
CONFIG value for the samples to the 256 size currently used.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-15 17:52:13 -05:00
Anas Nashif 429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Robert Chou 1d70a39d1b net: samples: replace tag zoap with coap
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-14 06:42:57 -05:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Michael Scott 2567b9fb6a net: coap: Fix error handling for coap option length
Currently, we check the length of an option value in the
coap_packet_append_option() function.  This isn't required as
we're appending to a net_pkt and not using struct coap_option
where the limitation is imposed.

Instead, we should check the option value length in
parse_option() where we assign the value to a struct
coap_option.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-27 11:33:06 -04:00
Robert Chou e2024128e1 net: coap: check null pointer before assign value
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-26 12:43:34 +02:00
Robert Chou 7aa223174a net: coap: empty payload with payload marker is malformed
From RFC 7252, section 3
"The absence of the Payload Marker denotes a zero-length payload.
The presence of a marker followed by a zero-length payload MUST
be processed as a message format error."

Check empty payload when COAP_MARKER is found and add a test case to
cover it

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-25 13:21:53 +03:00
Ravi kumar Veeramally 630fad3bbf net: coap: Improve options parsing helper functions
Options parsing helpers functions unable to handle the malformed
packets and dropping it. Improved parsing functionality to handle
malformed packets. Also payload marker is not mandatory in CoAP
packets when there is no payload. Exit gracefully when CoAP
packet contains only options.

Fixes #4396.

Coverity-ID: 178060

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-25 10:54:25 +03:00
Michael Scott 9a8597399d net: coap: fix coap packet length calculation
This calculation reads the length portion of the COAP header to determine
the length of the coap packet.  However, when encrypted via DTLS this
value seems to be getting corrupted.  Let's change this calculation so
that it will work for when DTLS is both enabled and disabled.  Use the
total length of the fragment data and substract back out the headers
to get a correct value.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:37:55 +03:00
Ravi kumar Veeramally f4772519d6 net: coap: Add multi fragment support to CoAP library
Current coap library fails to parse or prepare if packet is more
than one fragment. Added support to handle multi fragment packet.
Also well-known/core api used to prepare coap packet and send it
through net context api immediately. This is goind to be problematic
if user doesn't enable net context. Also user can not encrypt coap
packets. Now api will return prepared coap packet to application.
Application will send it to peer.

Jira: ZEP-2210

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-06 22:07:37 -04:00
Ravi kumar Veeramally 42a91f4c07 net: coap: Rename ZOAP library
ZOAP library has certain limitations in parsing and preparation of
coap messages. It can handle only on single network fragment. If
network packet is split between multiple fragments it fails. This
patch is just copy and rename of 'zoap' to 'coap'.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-06 22:07:37 -04:00