lwm2m_engine_pause() caused deadlock if it was called within
engine thread.
Remove while loop from lwm2m_engine_resume().
Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
Add short delay before triggering registration update. This allows
postponing the update from application side if needed.
Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
DTLS socket is not really connection-less as UDP, as it required the
DTLS handshake to take place before the socket is usable. Therefore,
align the DTLS connect() behavior with regular TLS.
The change is backward compatible. connect() call is still optional for
DTLS socket (the handshake can still take place from send()/recv()) and
a socket option was provided to disable DTLS handshake on connect().
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When using DTLS socket, the application may choose to monitor socket
with poll() before handshake has been complete. This could lead to
potential crash (as the TLS context may have been left uninitialized)
and unexpected POLLIN reports (while handshake was still not complete).
This commit fixes the above - POLLIN will only be reported once
handshake is complete and data is available
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case a socket error was caused by TLS layer, it was not reported with
POLLERR. This commit fixes this.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case TLS session is closed at the TLS level (and thus recv() reports
0 to the application) a certain race occurs between consecutive recv()
call, and TCP session teardown. As mbedtls_ssl_read() only reports
session close upon receiving CLOSE alert, consecutive non-blocking
recv() calls would report EAGAIN instead of connection closed, if called
before underlying TCP connection was closed.
Fix this, by storing the information that TLS session has ended at TLS
socket level. The new flag will be checked before attempting further
mbed TLS actions, so that connection status is reported correctly.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If we receive a IPv4 packet to v4 mapped address, the relevant
net_context is bound to IPv6. This causes issues if we try
to get the family from the context struct in sendto.
Fix this by checking if the destination address is IPv4 but
the socket is bound to IPv6 and v4 mapping is enabled.
If all these criterias are set, then set the family of the
packet separately and do not get it from net_context.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Make sure iovec is initialized to a value so that there
is no possibility that it is accessed uninitialized.
Fixes: #66838
Coverity-CID: 334911
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The original idea was to check that we have enough network
interfaces in the system. The check needs to verify max IPv4
and IPv6 supported interfaces instead of always checking
IPv6 one.
Fixes: #66843
Coverity-CID: 334899
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Refactored the socket state indication into its own function
that checks the state of TX queues as well as number of
pending CoAP responses.
Check the state after receiving a packet, as it might
have been a last Ack packet we have been waiting.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Deprecate lwm2m_set_u64() and lwm2m_get_u64 as only
LWM2M_RES_TYPE_S64 exist. Unsigned variant is not defined.
Technically these might have worked OK, but it is undefined
what happens to large unsigned values when those are
converted to various payload formats (like CBOR) that might
decode numbers differently depending of their signedness.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Any received address is no longer valid once the interface goes down.
Leaving the address assigned results in the L4 interface transitioning
through the following on reconnection:
UP: Interface is connected
DOWN: Old address is removed by DHCP
UP: New address is re-added by DHCP
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Networking events are masks of bits, which are almost impossible to read
as decimal, and trivial to read as hex. Also unifies the format string
across multiple outputs for some flash savings.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
If we receive a packet where the source address is our own
address, then we should drop it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
If we receive a packet from non localhost interface, then
drop it if either source or destination address is a localhost
address.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Allow engine to give hints about ongoing CoAP transmissions.
This information can be used to control various power saving
modes for network interfaces. For example cellular networks might
support release assist indicator.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
In slow networks, like Nb-IOT, when using queue mode,
there might be significant delay between the time we
put the packet into a transmission queue and the time
we actually start transmitting.
This might cause QUEUE_RX_OFF state to be triggered earlier
than expected. Remedy the issue by updating the timestamp on the
moment where packet is accepted by zsock_send().
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
In case a waiting TLS socket reports an error in the underlying poll
call, try to read the actual error from the socket, instead of blindly
returning -EIO in all cases.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
There are several subsystems and boards which require a relatively large
system heap (used by k_malloc()) to function properly. This became even
more notable with the recent introduction of the ACPICA library, which
causes ACPI-using boards to require a system heap of up to several
megabytes in size.
Until now, subsystems and boards have tried to solve this by having
Kconfig overlays which modify the default value of HEAP_MEM_POOL_SIZE.
This works ok, except when applications start explicitly setting values
in their prj.conf files:
$ git grep CONFIG_HEAP_MEM_POOL_SIZE= tests samples|wc -l
157
The vast majority of values set by current sample or test applications
is much too small for subsystems like ACPI, which results in the
application not being able to run on such boards.
To solve this situation, we introduce support for subsystems to specify
their own custom system heap size requirement. Subsystems do
this by defining Kconfig options with the prefix HEAP_MEM_POOL_ADD_SIZE_.
The final value of the system heap is the sum of the custom
minimum requirements, or the value existing HEAP_MEM_POOL_SIZE option,
whichever is greater.
We also introduce a new HEAP_MEM_POOL_IGNORE_MIN Kconfig option which
applications can use to force a lower value than what subsystems have
specficied, however this behavior is disabled by default.
Whenever the minimum is greater than the requested value a CMake warning
will be issued in the build output.
This patch ends up modifying several places outside of kernel code,
since the presence of the system heap is no longer detected using a
non-zero CONFIG_HEAP_MEM_POOL_SIZE value, rather it's now detected using
a new K_HEAP_MEM_POOL_SIZE value that's evaluated at build.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This reverts commit 6b644dff67.
Reason: breaks Peer-to-Peer gPTP connection. A better solution should be
found to handle the optional TLV on the announce message (chapter 10.5.1
IEEE 802.1AS-2011)
Signed-off-by: Mario Paja <mario.paja@zal.aero>
Zephyr does not support MLDv1 (which has a shorter header than MLDv2),
and this resulted in log errors being printed on header access if MLDv1
queries were received. Since receiving such packet is not really an
error, just drop it silently.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Update coap_service_send and coap_resource_send to take an optional
pointer argument to the newly introduced coap_transmission_parameters.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
AP enable takes the same parameters as connect, so, update the help and
also fix the optional parameter count when security is involved.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
In case one of the networking shell backends is enabled, net arp command
could potentially trigger a deadlock, as it locks the ARP mutex before
TCP connection mutex, while TCP stack could do this in reverse order
(for instance when sending ACK or retransmission).
Mitigate this, by forcing a separate TX thread in such case, so that ARP
mutex is no longer accessed with TCP mutex locked.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Replace function parameter 'retries' with pointer to structure
holding coap transmission parameters. This allows setting the
retransmission parameters individually for each pending request.
Add coap transmission parameters to coap_pending structure.
Update migration guide and release notes.
Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
The dummy L2 layer does not implement any L2 functionality
but it does not mean that it should not implement start/stop
functions that are called when the related network interface
is brought up or taken down.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
It is pointless to take net interface up if the underlaying
device is not ready. Set also the interface status properly
in this case.
Fixes#65423
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Use correct format specifier for LOG_ERR in lwm2m_obj_device.c. The
previously used format specifier of %u was correct for 32 bit systems
but would produce a build warning for 64 bit systems.
Fixes#66441
Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
As the common.h is only meant to be used by the network
shell files, rename it to be more descriptive in order to
avoid possible conflicts with any other common.h file.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Calling the registered receive callback when releasing TCP context
doesn't make sense, as at that point the application should've already
closed the associated socket (that's one of the conditions for the
context to be released). Therefore, remove the pointless receive
callback call, while keeping the loop to unref any leftover data packets
(although again, I don' think there should be any packets left at that
point, as they're all consumed in tcp_in()).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
While improving thread safety of the TCP stack I've introduced a
possible deadlock scenario, when calling tcp_conn_close() in tcp_in().
This function shall not be called with connection mutex locked, as it
calls registered recv callback internally, which could lead to deadlock
between TCP/socket mutexes.
This commit moves the tcp_conn_close() back where it was originally
called. I've verified that the thread safety is still solid with the
test apps used originally.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add empty macro for net_if_mon functions if they are not otherwise
defined, like the other functions in the net_if.c file have.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Add new functions to the public CoAP API to configure CoAP packet
retransmission settings. Application may need to re-configure the
settings for example when cellular modem changes connection from
LTE-M to NB-IoT or vice versa.
Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
The number of Kconfig options for the TCP stack grew considerably,
therefore it makes sense to move them to a separate file not to bloat
the Kconfig file with generic networking options.
Take this opportunity to reorder TCP options, so that protocol
parameters (timings/buffer sizes) are not mixed up with optional
protocol features (fast retransmit/congestion avoidance etc.).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When a TCP connection is established, if there is no data exchange
between the two parties within the set time, the side that enables
TCP Keep-alive will send a TCP probe packet with the same sequence
number as the previous TCP packet. This TCP probe packet is an empty
ACK packet (the specification recommends that it should not contain
any data, but can also contain 1 nonsense byte, such as 0x00.). If
there is no response from the other side after several consecutive
probe packets are sent, it is determined that the tcp connection has
failed, and the connection is closed.
The keep-alive default parameters are aligned with Linux defaults.
Signed-off-by: Horse Ma <mawei@coltsmart.com>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If observed resource was written during the pMin period, it did
not schedule any wake-up event into the future. Notify message would
then only be generated as a result of any other (like Update) event.
Refactor check_notifications() to follow same pattern as retransmit_req().
Return the next event timestamp, which could be now.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
SNTP response is not analyzed for uncertainty, and no uncertainty is given
to the `struct sntp_time` returned. Fix it with a Kconfig option that adds
optional SNTP uncertainty and timestamp fields in SNTP time struct, and
calculates these when parsing the response.
Adds two helper functions to convert Q16.16/Q32.32 in seconds to `int64_t`
in microseconds to facilitate this.
Also changes combined `lvm` field in `struct sntp_pkt` to bit-fields
`li`, `vn`, and `mode`.
Signed-off-by: Jasper Smit <git@jrhrsmit.nl>
Add const prefix for service uuid and char uuid.
Since Service UUID and Char UUID should not change in the service
definition, they are most reasonably defined as rodata, also for
save some ram footprint.
The field `attr->user_data` type is `void *`, as this PR change
all Service UUID to rodata, so there must add (void *) to avoid warning.
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
Add Kconfig choice for the user to select how Network Events are
handled. It's own thread, the system work queue or synchronous when
events are emitted.
By default a separate thread is created to be backwards compatible.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>