Modify the signature of the k_mem_slab_free() function with a new one,
replacing the old void **mem with void *mem as a parameter.
The following function:
void k_mem_slab_free(struct k_mem_slab *slab, void **mem);
has the wrong signature. mem is only used as a regular pointer, so there
is no need to use a double-pointer. The correct signature should be:
void k_mem_slab_free(struct k_mem_slab *slab, void *mem);
The issue with the current signature, although functional, is that it is
extremely confusing. I myself, a veteran Zephyr developer, was confused
by this parameter when looking at it recently.
All in-tree uses of the function have been adapted.
Fixes#61888.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Make sure we use the network interface name (if configured)
instead of device name when binding to certain network
interface.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Add TLS_DTLS_CID socket option, which enables to use the Connection ID
extension for the DTLS session.
The option provides control of the use of CID with the `setsockopt()`
function. The value provided can disable, enable, and control whether to
provide a CID to the peer. It uses a random self CID (if told to provide
one to the peer) unless TLS_DTLS_CID_VALUE set previously.
Add TLS_DTLS_CID_VALUE to get or set the CID sent to the peer, if any.
Add TLS_DTLS_PEER_CID_VALUE to get the CID value provided by the peer,
if any.
Add TLS_DTLS_CID_STATUS to determine if CID used, and whether
bidirectional or one way.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
getsockname() did not work properly on bound sockets, as it verified
whether the socket has an active connection before retuning result. This
is not correct, as socket after bound may not have a connection yet.
Fix this, by verifying that local_addr on an underlying net_context is
set, to determine whether socket has a local address assigned, before
returning result.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
* Renamed 'coap_client_init_path_options' to
'coap_packet_set_path'
* Moved into 'coap.c'
* The function is public now
Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
Fix options initialization for path and query
when a final segment is one character long.
For example, "a/b" inits path as ["a"] instead
of expected ["a", "b"]. The same applies to
query option. The "a/abc?a&b" options won't
contain "b".
Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
The previous patch to address race condition on STREAM sockets had a
side effect on DGRAM socket, where net_context_recv() is not only
installing recv callback, but also registering a connection at net_conn
level. Doing so before setting remote address first (which is done in
net_context_connect()) had an impact on the connected DGRAM socket
operation, which now accepted packets from any remote peer, and not only
the one socket was connected to.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When resource data length is set to zero, we still need to
ensure that string reading will return an empty string.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
There are a few structs, unions, and enums where -Wshadow would
complain. Since names being the same are intentional, we need
to tell compiler to ignore -Wshadow for those names.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
The `ioctl()` interface is already supported by the network
subsystem but there was no `zsock_` interface available for it.
Add the `zsock_ioctl()` syscall.
Implement two somewhat commont ioctl requests for socket
file descriptors; namely
- `FIONBIO` set non-blocking I/O mode
- `FIONREAD` get the number of available bytes
In the process, added `net_pkt_ip_proto_hdr_len()`
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
In order to get a semi-accurate assessment of how many
bytes are available on a socket prior to performing a read,
BSD and POSIX systems have typically used
`ioctl(fd, FIONREAD, &avail)`
We can support this in Zephyr as well with little effort, so
add support for `socketpair()` sockets as an example.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Previously, if a net_context had multiple packets already in
the receive queue, and a call to zsock_recvfrom() was made with
a buffer large enough to receive content from multiple packets,
only the content from a single receive buffer would be received.
Since zsock_recvfrom() is a system call, which has a
non-negligible overhead, it makes sense to receive as many bytes
as possible per system call.
Add zsock_recv_stream_immediate() as a shorthand for
"fill this receive buffer with as many bytes as possible without
blocking". Allow nullable buffer parameters so that we can also
have a shorthand for "count how many bytes are immediately
available".
With minor refactoring, zsock_recv_stream_timed() is a simple
wrapper around zsock_recv_stream_immediate() that handles timing
and error conditions.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The added function allows to check if a descriptive block
option was already added to a message.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
In some cases the options of a CoAP message are reused for
block transfer. Then the block header needs to be updated.
The current approach is to remove the old block option and
add an updated one.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
The provided function allows to remove a CoAP option in a
message. This is useful for reusing parts of a message.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
The reply callback doesn't need to handle the case when the
code of the reply is 'continue' (2.31). In that case the callback
is not executed until the last block is transmitted.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
When using block-wise transfer, call the reply callback only when
the last block arrived.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
Fix possible race conditions when state and results are written
by locking the registry, so a first write does not cause Notify
message to be send too early.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
When the protocol layer like TCP is blocking transmission, the socket
layer will attempt and wait for a maximum amount of time before returning
with an ENOBUFS error.
This change allows to set the maximum waiting time from the configuration
file instead of using a fixed 10 second value.
Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
Bootstrap executable cause socket to be closed, so
it requires some delay for Ack to be send out as well.
Similarly, add small delay for Update trigger, so the
possible Ack goes out before the actual update message.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
When BOOTSTRAP FINNISH message was received, it caused
engine to immediately switch to BOOTSTRAP_TRANS_DONE state
which then closed the connection.
Ack packet was still on the send-queue so it never got send before close().
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Some state changes were do by directly writing into
client.engine_state variable, followed by call next_event_at(0);
This causes hard-to-find side effects.
Refactor all state transitions to use set_sm_state() to have better
control for it.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Updates NET_SOCKETS_TLS_MAX_APP_PROTOCOLS Kconfig option description to use
DTLS instead of DTL.
Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
* Create submenu for protocol versions.
Like LwM2M 1.0 vs 1.1. Object versions.
* Create submenu for engine features.
Containing all engine tweaks that are not directly from
protocol specification.
* Create submenu for all memory tuning options.
For example maximum number of certain objects, buffer
sizes, etc.
* Order all objects by object ID and show the ID in
title.
* When multiple options depend on same feature, group
them under if <option> ... endif. Preferably directly
after the selection itself.
* Move IPSO and uCIFI menuentries one sublevel up.
* Drop deprecated entries to bottom.
No functional changes, just clean up of Kconfig menu.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Use 64bit timestamps from k_uptime_get() so they don't
roll over during the expected device lifetime.
Fixes#60826
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Engine now allows registering service callbacks that are
called only once on a given timestamp.
This allows tickless services to be developed.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Allow socket-loop to wake up immediately, if there are changes,
instead of waiting for zsock_poll() to timeout.
This change makes engine more reactive and removes
hard coded timeout from zsock_poll().
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
When the target board does not have heap by default, allows
statically reserving the space for required socketpairs.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
The initial goal was to remove sys_clock_timeout_end_calc(). However,
several related issues have been fixed as well.
First this:
int64_t print_interval = sys_clock_timeout_end_calc(K_SECONDS(1));
/* Print log every seconds */
int64_t print_info = print_interval - k_uptime_ticks();
if (print_info <= 0) {
[...]
}
The above condition will simply never be true.
Then there is lots of back-and-forth time conversions using expensive
base-10 divisions for each loop iterations which is likely to impact
performance.
Let's do the time conversion only once outside the loop and track
everything in terms of ticks within the loop. Also the various timeouts
are open-coded based on the absolute uptime tick so to sample it only
once per round. Using sys_timepoint_calc() and sys_timepoint_timeout()
would have introduced additional uptime tick sampling which implies the
overhead of a downstream lock each time for no gain. For those reasons,
open coding those timeouts bears more benefits in this particular case
compared to using the timepoint API.
Then this:
secs = k_ticks_to_ms_ceil32(loop_time) / 1000U;
usecs = k_ticks_to_us_ceil32(loop_time) - secs * USEC_PER_SEC;
The above should round down not up to work accurately. And the usecs
value will become garbage past 1.2 hour of runtime due to overflows.
And no need to clamp the wait period which is on the microsec scale
using the total duration argument being on the millisec scale. That's
yet more loop overhead that can be omitted. The actual duration is
recorded at the end anyway.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The TLS credentials libraries are purely software constructs with no
external dependencies, run them immediately after the kernel setup to
allow other initialisation functions to add credentials without the
requirement to run in the back half of the `APPLICATION` priority.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
When PMAX value is changed, it should update all events.
I believe there is a bug that caused the code only to update
events that are ongoing (to be send).
Now if PMAX changes, next event timestamp is recalculated.
Fixes#59397
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
The signal strength for the connectivity monitor was
defined as int8_t, however this was too small for
LTE RSRP values, which has range [-140,-44].
Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
Use only single thread for handling polling of the sockets.
Each client will have only 1 active socket which to poll.
Each client can have multiple simultaneous requests ongoing.
The client only has one buffer for receiving and one buffer for sending.
Therefore the messages are reformed when resending.
Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
Lwm2m firmware object have defined a write of zero length
string as a cancel operation.
So allow lwm2m_set_opaque(path, NULL, 0);
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Pause and resume functionality was written into assumption
that sockets are closed before resuming.
With use new options CONFIG_LWM2M_RD_CLIENT_STOP_POLLING_AT_IDLE
or CONFIG_LWM2M_RD_CLIENT_LISTEN_AT_IDLE this is not always true.
Fix the state machine, so that on those cases, sockets are not
closed and resume is always similar like from the QUEUE mode.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Add support for using X509 certificates.
Default settings use ECDSA certificates with SHA256 hash.
When different settings are required clients should overwrite
struct lwm2m_ctx->load_credentials() and
struct lwm2m_ctx->set_socketoptions()
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
When writing string data to resources which are string types,
we should count in the terminating character into the data length.
Corner cases exist where LwM2M resource type is opaque but
lwm2m_get_string() or lwm2m_set_string() are used to read/write
the data. We must ensure string termination on those case, but
terminating character must not be stored in the engine buffer
or counted in the data length as this might be considered
as part of the binary data.
Fixes#59196
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Add a new Kconfig parameter NET_CONFIG_MY_VLAN_ID as initial network
configuration to enable users to set VLAN identifier at startup.
Add a new setup_vlan(...) function to setup the VLAN identifier in
the device, the call have an effect only when NET_CONFIG_MY_VLAN_ID
is above zero.
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
websocket_disconnect api does not closes mqtt's tcp socket, so
tcp socket must be closed after done.
Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>