LWM2M Client Sample with DTLS enabled fails because TLS_HOSTNAME is set
but MBEDTLS_X509_CRT_PARSE_C is disabled which leads to error
'net_lwm2m_engine: Failed to set TLS_HOSTNAME option: 109'
Add new field hostname_verify to let the application decide if hostname
should be checked.
Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
When connect() is called on a TCP socket, tcp_in() is called with a NULL
packet to start establishing a connection. That in turn leads to a SYN
packet being produced which, depending on the Ethernet driver, may
result in a synchronous transmit of that packet. After that, the
connect() implementation, which at this point is executing
net_tcp_connect() starts waiting to take a semaphore until the
connection timeout is reached. However, if the transmit of the SYN
packet results in a RST packet being returned from the connection
destination (due to there being no listening socket) very quickly on a
local network, the device driver may deliver an interrupt which can
cause the receive path of the network stack to run, resulting in the
tcp_in() of the RST packet via the network RX thread. That can cause
tcp_conn_unref() to be called before the connecting thread has gotten
to the point of acquiring (or failing to) the semaphore, which results
in a deinitialized semaphore being accessed.
This commit fixes the possible race condition by ensuring that the
connection lock mutex is held until after the connection state moves
to "in connect."
Fixes#44186
Signed-off-by: Berend Ozceri <berend@recogni.com>
If NET_IPV4 and NET_SOCKETS_PACKET is enabled, NET_SOCKADDR_MAX_SIZE will
be bigger than the ipv4 address length.
This is a problem when DTLS is used as the address comparison will fail
because of the different length of the received and the stored address.
This is also a problem if NET_IPV6 and NET_IPV4 is enabled and the remote
address is a ipv4 address
Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
Use defines instead of hardcoded strings to avoid future errors if the
values would change.
Signed-off-by: Andreas Pettersson <andreaspettersson95@gmail.com>
When TCP stack enters retransmission mode, the variable tracking the
amount of unacknowledged data is cleared. This prevents the stack from
detecting when TX window is full, which could lead to queueing unlimited
amount of data, effectively consuming all of the avaiable network
buffers.
Prevent this, by returning early from net_tcp_queue_data() in case TCP
stack is in retransmission mode. The socket layer will take care of
retrying just as in case the window is full.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case a loopback or own address is used in TCP connection, the TCP
stack delegates the acatual data send to a workqueue. This is fine,
however it could lead to some aritificial delays in case a lot of data
is being sent before the workqueue has a chance to execute queued work
items. In such case, we only sent a single packet, when many could've
already been queued.
Fix this, by resubmitting the queue in case a local address is used, and
there's still more packets pending for send.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When peer reports a zero length receive window, the TCP stack block any
outgoing data from being queued. In case no further ACK comes from the
peer, the whole communication could stall. Fix this by sending a simple
Zero Window Probe, when we detect a Zero Length Window.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
NSEC_PER_SEC is an unsigned integer macro. Thus, -NSEC_PER_SEC will be
treated as unsigned integer as well which lead to calculation error on
64bits integer variables. Added the correct type casting into the formula
to fix the calculation error.
Signed-off-by: Kweh Hock Leong <hock.leong.kweh@intel.com>
The ARRAY_SIZE macro uses sizeof and thus the return
type should be an unsigned value. size_t is typically
the type used for sizeof and fits well for the
ARRAY_SIZE macro as well.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Sometimes message is being reset from multiple locations in code.
If message has already been reset, pointer to context is invalid.
Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
Read operation must return empty payload when read /object_id
if there is no created object instances.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
http_client_req() was supposed to return the number of bytes sent as a
HTTP request. The return value was not riht however due to some bugs in
helper functions:
* http_send_data() returned the current buffer position istead of the
number of bytes actually sent. This could result in counting the same
data into the total request size several times. A helper variable was
added to track how many bytes were actually sent to the network.
* http_flush_data() forwarded the return value of sendall() helper
function. That function however did not return number of bytes sent,
but 0 or a negative error code.
Additionally, change the return type of sendall() function - according
to standard the ssize_t type is only capable of holding -1 negative
value, but the function could return the full range of negative errno
values. Use int instead.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Closing a listening socket will set the accept callback to NULL.
This could lead to a crash, in case an already received packet,
finalizing the connection handshake, was processed after the socket was
closed. Thereby, it's needed to verify if the callback is actually set
before processing it.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The verification function for accept() did not take into account that
addr and addrlen pointers provided could be NULL.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
TCP processed IPv4/IPv6 packets w/o verifying first if IPv4/IPv6 is
enabled in the system. This could lead to problems especially for IPv6,
where in case it's disabled the sockaddr structure is not large enough
to accomodate IPv6 address, leading to possible out-of-bound access on
the sockaddr structure.
Fix this by adding appropriate checks where applicable.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Added support for Composite observation for LwM2M v1.1.
Updated current Observation node to support linked path list.
Rename typos lwm_ to lwm2m_.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
Removed to store pmin and pmax at oberservation node structure and
use attribute list store for calculate time for next Notification.
Observation class use timestamp for triggering notification based on
resource update which use pmin and default pmax behaviour.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
TCP module can report EAGAIN in case TX window is full. This should not
be forwarded to the application, as blocking socket is not supposed to
return EAGAIN.
Fix this for sendmsg by implementing the same mechanism for handling TX
errors as for regular send/sendto operations.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When queue mode is enabled, state machine will enter state
ENGINE_REGISTRATION_DONE_RX_OFF. This state needs to be
taken into account during registration update to send
correct event.
Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
Following #42026, the body_start pointer now points to the
start of the body fragment in the recv_buffer as long as there
is body in it, either entirely or partially.
Rename the body_start to body_frag_start to better reflect
what it represents.
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
SenML Json support dynamical basename for composite operation.
Changes simplify base name generation and compres message better.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
The device can be obtained at compile time. Note that now the readiness
is checked on every call, but it's a fast operation anyway.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
ot_setting_delete_subtree returns the information if the subtree
had been found in the persistent storage or not before removing.
This has matter for otPlatSettingsGet. In other uses cases
the return value shoud be ignored.
The right place for the check if deletion succeded is in
settings_load_subtree_direct and its callback.
Currently "ot factoryreset" causes an assert if there is no
OpenThread dataset stored in the persistent memory.
This PR fixes it.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
As the receive window is now decreased at the TCP module level, other
direct net_context users are also responsible for acknowledging the
received data with net_context_update_recv_wnd() - otherwise, the
communication will stall.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
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>
This commit adds implementation of otPlatRadioSetChannelMaxTransmitPower
This function is responsible for setting maximum allowed power on
IEEE 802.15.4 channels.
Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
Adds an official behavior in response to null response from HTTP
endpoint.
Fixes#42988
Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
Fix#42800
Both pss->rate_ratio and port_ds->neighbor_rate_ratio are double type
but sync_receipt_time is uint64_t. If pss->rate_ratio is less than 1
or sync_receipt_time * port_ds->neighbor_rate_ratio is less than 1,
sync_receipt_time becomes 0 due to double to uint64_t cast.
Assign port_ds->neighbor_prop_delay to sync_receipt_time first to fix
this issue.
Signed-off-by: Lu Ding <lucasdinglu@gmail.com>
It depends from a content formatter is there need to put constructs
with a path level deeper than object instance. In other words with
resource- or resource-instance-level.
Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
This commit moves openthread CMakeLists.txt from openthread submodule
to zephyr/modules/openthread.
Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
So far close() was called on underlying socket when timeout has expired.
This is wrong in several ways. First of all POSIX specification of
close() does not specify what should happen on blocking recv() call and
different systems have different behaviors (e.g. Linux does not wake up
recv() caller if there was no new incoming data, while other systems
might wakeup recv() caller immediately). Another (and much more severe)
problem is that HTTP client user does not know whether underlying socket
was already closed or not after HTTP request has finished. As a result
it was not clear whether close() should be called by HTTP client user.
Use shutdown(..., SHUT_RD) in internal HTTP client implementation, so
that recv() is woken up immediately with 0 as result (which means EOF).
This will allow to gracefully handle timeouts and make it clear that it
is application responsibility to always call close() after HTTP
request (successful or not).
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Add basic shutdown() implementation of TLS sockets, which basically
calls shutdown() on underlying wrapped sockets.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Add basic shutdown() implementation for net_context sockets, which
handles only SHUT_RD as 'how' parameter and returns -ENOTSUP for SHUT_WR
and SHUT_RDWR. The main use case to cover is to allow race-free wakeup
of threads calling recv() on the same socket.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
So far shutdown() implementation was a noop and just resulted in warning
logs. Add shutdown() method into socket vtable. Call it if provided and
fallback into returning -ENOTSUP if not.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
correction field in sync follow up message must be converted from host
endianness to network endianness.
Signed-off-by: Lu Ding <lucasdinglu@gmail.com>
This file defines the crypto driver API, cipher is supposed to be just
one type of capability (other can be hash) of these drivers, just
change the file name to be consistent with it.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
A previous commit fixed OpenThread logging when `LOG=n`, but
introduced regression when `LOG_MODE_MINIMAL=y`. This commit
fixes the latest.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
This commit utilizes psa_crypto_get function to fetch cryptographically
secure pseudorandom numbers.
Signed-off-by: Lukasz Duda <lukasz.duda@nordicsemi.no>
Makes possible to read a single resource instance at a time with
plaint text, JSON and TLV content formats.
Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
If settings wipe fails we are not informed about this what can lead to
bugs which are hard to investigate.
This commit adds log and/or assert which is triggered by this failure.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
LwM2M version 1.1 will select SenML Json for default content format.
Version 1.0 will use TLV format.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
LwM2M engine Send operation support /dp.
Send operation based on Composite Read functionality
which is not enabled at engine side like composite write.
Added Kconfig configurable for composite read path list size.
Created generic Read object instance which is shared between
general read and Composite Read operation.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
LwM2M SenML JSON contain format support for Read / Write operation.
Added Kconfig configurable for enable SenML JSON format.
LwM2m read validate read operation and report out of memory.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
In case an individual resource is being discovered, the LwM2M client
should not only fill the attributes assinged at the resource level, but
also the ones inherited from the object and object instance levels.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
LwM2M 1.1 allows to write attributes for resource instances as well.
Resource instance level attributes need also to be taken into
consideration when adding/updating observers.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
LwM2M adds Resource Instance reporting in Discovery response, along with
attributes assinged at the Resource Instance level.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Peer may send a zero-length keepalive message, probing the recv window
size - TCP stack should still reply for such packets, otherwise
connection will stall.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add implementation of net_tcp_update_recv_wnd() function.
Move the window deacreasing code to the tcp module - receive window
has to be decreased before sending ACK, which was not possible when
window was decreased in the receive callback function.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If OPENTHREAD_IP6_FRAGM is enabled the IPv6 fragments are handled in
OpenThread stack but also forwarder unconditionally to the Zephyr
uplayers. It causes additional packets processing and leads to errors
like unrecognized next header type or duplicate ping reply. What more
these errors generate additional traffic which jam channel and decrease
latency for packets required fragmentation.
This commit add filtering IPv6 fragments when data fragmentation and
reassembling is enabled in OpenThread.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
Uninitialized memory would report wrong value for
`mAckedWithSecEnhAck` flag in the received frame, making the
OpenThread stack to update the frame counter for the neighbor
wrongly.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
This is a bare minimal changes to tell the server that we are using
LwM2M 1.1 version. Queue-mode parameter has changed between 1.0 and
1.1 so it must be changed in the same time.
Other 1.1 features may follow on separate commits. This is still
an experimental feature that allows developing and testing of
1.1 features.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
This far time values have been synonymous to integer values. Content
formats like CBOR do use different representation.
Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
Added support for Portfolio object support because LwM2M v1.1 conformance
test requirement that. This object is only for conformance test purposing.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
Do not retransmit a message that just has been send successfully.
This case can in particular happen quite frequently if the modem
connection/throughput is quite bad and so there is a high latency.
A message that has to be acknowledged is scheduled for retransmission.
Before retransmission a ack for this message is received that will
cause a reset of the original message. In this case you see a
"LwM2M message is invalid" error message.
Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
Read operation must return empty payload when read /object_id
if there is no created object instances.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
There is no releavnce between CAN sockets and offloading that would
prevent one from working with another, therefore it's not right to
allow CAN sockets to be build only if offloading is disabled. Fix the
wrong dependency in socket CMakeLists.txt file.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Fix bug in radio implementation that reported any transmit error
as `OT_ERROR_NO_ACK` to OpenThread.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
This reverts commit e7489d8de7.
And fixes the deadlock by allowing only 1 thread to actualy clean up
the connection when the ref_count is 0.
Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
Takes the modem state machine by calling lcp_close instead of lcp_down
Using this method the LCP layer sends a TERMINATE_REQ to the modem and the
network interface is only taken down when the LCP layer has properly
finished.
Moved the ppp_mgmt_raise_carrier_off_event and net_if_carrier_down
to lcp.c to avoid breaking the interface.
Tested on a real modem.
Fixes: zephyrproject-rtos#41627
Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
many functions in the lwm2m librarys api take a pathstr argument
that is never written to, so make it const
Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
The path was erroneously pointing to update state
resource instead of update result causing a wrong
resource value to be updated.
Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
Unlock tcp_lock when calling the recv_cb. In case when
a connection is being closed from both the tcp stack
and the application, a race condition can happen resulting
in locking each other out on tcp_lock and socket lock.
Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
Firmware Update Protocol Support resource initialization
has been left out in #41402.
Initialise the resource in object creation function.
Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
Increments send retry every time
after the tcp_send_data when resending.
That way unhandled return values can time
out after set amount of tcp_retries.
Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
A common pattern here was to take the work item as the subfield of a
containing object. But the contained field is not a k_work, it's a
k_work_delayable.
Things were working only because the work field was first, so the
pointers had the same value. Do things right and fix things to
produce correct code if/when that field ever moves within delayable.
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Calling lwm2m_rd_client_stop causes the client context to be closed.
Doing this from arbitrary thread other than internal lwm2m engine thread
causes racing condition on lwm2m engine context pointers.
Fixes#42358
Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
Server Object SSID should only have Read access.
LightweightM2M-1.1-int-256 confirmance test validate
that write operation to SSID should return error.
Overwrite SSID affect dead block for lwm2m engine and
only reset will heal.
Fix by adding bootstrap overwrite access for Security and
Server object when bootstrap is active.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
Use explicit casting to long long within `snprintk()` and logger
functions to prevent compiler warnings with different
platforms/toolchins (as 64-bit integer can be either represented
as ld or lld depending on platform).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
At some point OMA TLV integer encoding was optimised to use the smallest
size possible. This broke the objlnk encoding, which internally used
`put_s32()`, but should always be 4 bytes long. In case the result
32-bit integer would fit into 16 or 8 bytes, it'd get optimized.
Fix this, by creating and writing TLV manually for objlnk instead of
relying on int32 encoder.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case a string with an integer was provided to the function (no
decimal point), the function did not update the output pointer value.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Verify the restult of the content writer functions and return an error
if content writer fails to read/write field in the message.
This solves an issue when for example malformed packet was sent to the
server if the payload did not fit in the message.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
It's now possible to return an error code instead of 0 where
appropriate.
Make `buf_read()` return -ENODATA instead of -ENOMEM if there's not
enough data in the packet to serve the request, which is more meaningful
for this scenario.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Rework the content encoder/decoder API to allow to return negative
values as well. This allows a proper error reporting and error handling,
as it's now possible to differentiate when there is no content to write
(retuned 0) or and error occured, and further processing should be
aborted.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
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>
Fix net_pkt leak by increasing net_context the reference count earlier
in the zsock_accepted_cb() with instalment of the
zsock_received_cb() callback.
And consequently flushing recv_q and decrement net_context
reference count if zsock_accept_ctx() fails.
Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
In case system workqueue processing is delayed for any reason, and
resolver callback is executed after getaddrinfo() call already timed
out, the system would crash as the callback makes use of the user data
allocated on the stack within getaddrinfo() function.
Prevent that, by cancelling the DNS request explicitly from the
getaddrinfo() context, therefore preventing the resolver callback
from being executed after the getaddrinfo() call ends.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The previous approach to detect if the underlying transport was closed
(by checking the return value of `mbedtls_ssl_read()` was not right,
since the function call does not request any data - therefore 0 as a
return value is perfectly fine.
Instead, rely on the underlying transport ZSOCK_POLLHUP event - if it
reports that the connection ended, forward the event to the application.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Report ZSOCK_POLLHUP event if peer closed the connection, and thus the
socket is in EOF state.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In a similar way as its done for IPv6. This allows to rejoin the group
once the interface is up again.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Conceptually the net_mgmt_lock should be a mutex instead of a
semaphore. It is easier to identify the owner of a mutex and
debug when deadlock happens, so convert it.
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Set `body_start` pointer regardless of the body position in the recv
buffer. In result, the pointer shall indicate correctly position of the
body for each fragment, it's also explicit now that if the pointer is
not set for a fragment, there's no body in that particular fragment.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Validate the respective attribute parameters only if both are provided
at given level. This prevents from comparing for instance unset pmax
value (equal to 0) with some new pmin value sent by the server.
Additionally, fix the sanity check for the `pmax` value set on observer,
after fetching the attribute value at all levels (including the default
value at from the server object). Instead of using wrong max(pmin, pmax)
formula, set the pmax value only if it's a valid one (>= pmin),
otherwise ignore the value and set it to 0. This makes the notification
engine ignore the pmax value set for observation.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Implement an empty `otPlatLog` function when `CONFIG_LOG` is not
enabled. This also fixes the issue with `log_count_args` not being
available when logging is disabled.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and
dev->config instead.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Add support for the gateway object [EXPERIMENTAL] used by the
MG100, BT510, and BT610 LwM2M demo.
Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
This commit adds OPENTHREAD_PLATFORM_CSL_UNCERToption to Kconfig.
This option will allow user to configure openthreads CSL clock
uncertianity during build time.
Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
Provide possibility to have instance specific callbacks
for writing the FW image and executing the update
Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
Previously the object 5 was only single instance object. Provide
backwards compatibility, so it can be continued to use with single
instance.
Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
This is a proof-of-concept implementation.
A device might have multiple firmware images which needs to be updated
separately. For example a single device might have
* A bootloader image
* An application image
* External firmware image
Instead of pushing all these updates through the object instance 0 -
/5/0 - here a split to multiple has been made possible.
Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
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>
The intention behind this patch is to know the current state/result
of a firmware update process in the application code. It makes it
possible to use pre/post_write_callbacks to get the proper value
of state (5/0/3) and result (5/0/5) resource.
Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
Rename a few CAN API functions for clarity and consistency with other
Zephyr RTOS APIs.
CAN_DEFINE_MSGQ() becomes CAN_MSGQ_DEFINE() to match K_MSGQ_DEFINE().
can_attach_isr() becomes can_add_rx_filter() since a filter callback
function is not an interrupt service routine (although it is called in
isr context). The word "attach" is replaced with "add" since filters are
added, not attached. This matches the terminology used is other Zephyr
APIs better.
can_detach() becomes can_remove_rx_filter() to pair with
can_add_rx_filter().
can_attach_msgq() becomes can_add_rx_filter_msgq() and documentation is
updated to mention its relationship with can_add_rx_filter().
can_register_state_change_isr() becomes can_set_state_change_callback()
since a state change callback function is not an interrupt service
routine (although it is called in isr context). The word "register" is
replaced with "set" since only one state change callback can be in
place.
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
The strtol() function use errno to return error code.
However, it is not being initialized in the parser_arg()
function before calling the strtol(). Thus, hitting error
when performing net ping command with -c / -i parameters.
Signed-off-by: Kweh Hock Leong <hock.leong.kweh@intel.com>
Changed resource IDs 11 and 12 of the security object to use
signed integer as they are defined in the OMA specification.
Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
Update the connectivity monitor object to version 1.2.
OMA core specification for the object adds 2 optional
resources.
Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
According to MbedTLS API documentation, its session must be reset if
mbedtls_ssl_handshake returns something other than:
- 0
- MBEDTLS_ERR_SSL_WANT_READ
- MBEDTLS_ERR_SSL_WANT_WRITE
- MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS
- MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS
In MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS and
MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS cases the function must be called
again when operation is ready. These cases now return -EAGIN or
continue to retry if it's a blocking call.
Signed-off-by: Ramiro Merello <rmerello@itba.edu.ar>
Change the can_tx_callback_t function signature to use an "int" (not an
uint32_t) for representing transmission errors.
The "error" callback function parameter is functionally equivalent to
the return value from can_send() and thus needs to use the same data
type and needs to be able to hold negative errno values.
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Log_strdup was used in NET_ASSERT macro which is not logging.
As a result linking fails when logging is disabled but asserts
are enabled.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
For instance, DHCP (UDP protocol) can send broadcasted packet and if we
no not serve the requested destination port, let's not send an error
back.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Invert src/dst strings, the icmpv4 error is sent from the dst (us) to
src (sender of the ipv4 packet that generated the error).
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
When support for custom MRU/MTU was added with
CONFIG_NET_L2_PPP_OPTION_MRU=y, code flow with
CONFIG_NET_L2_PPP_OPTION_MRU=n has been broken due to lack of valid
'ctx->lcp.my_options.mru' initialization and its use (with value 0) in
the implementation.
Initialize 'ctx->lcp.my_options.mru' unconditionally in lcp_init(), so
that PPP works fine with CONFIG_NET_L2_PPP_OPTION_MRU=n.
Fixes: 8a51a79d89 ("net: l2: ppp: possibility to have a custom
MRU/MTU")
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This provides the infrastructure to create network packet filter rules
and to apply them to the RX and TX packet paths. Rules are made of
simple condition tests that can be linked together, creating a facility
similarly to the Linux iptables functionality.
A couple of generic and Ethernet-specific condition tests are also
provided.
Additional tests can be easily created on top of this.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Adds support for LWM2M object 9 Software management.
This is implemented according to this release:
http://openmobilealliance.org/release/LWM2M_SWMGMT/V1_0_1-20200616-A/
Note that the XML is lacking some resources and for that reason those
resources are not included. This is a known problem by OMA and will be
fixed in a later releases.
This uses the lwm2m_pull_context to pull binaries in case
FIRMWARE_PULL_SUPPORT is enabled
Signed-off-by: Michal Ciesielski <michal.m.ciesielski@voiapp.io>
Add a semaphore to control that no collisions occur when multiple
sources want to use the pull_context
Add struct firmware_pull_context *ctx as an argument to the result_cb of
the context. This allows the receiver to do some kind of differentiation
on the source.
Signed-off-by: Michal Ciesielski <michal.m.ciesielski@voiapp.io>
Make it possible to reuse the pull logic from firmware_pull.c by
separating it to a separate file.
The firmware_pull_context is still owned and statically allocated in
firmware_pull.c and is being passed into lwm2m_pull_context.c as a
pointer.
In other words, pull_context, does not keep any state except for a
pointer to the context currently in use.
Signed-off-by: Michal Ciesielski <michal.m.ciesielski@voiapp.io>
Add EtherCAT protocol support, now applications can
transmit/receive EtherCAT packets via RAW socket.
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
Since most of the functions will access non thread-safe resources like
SLIST, and can be invoked from different threads (like the expiry timer
delayed work), add mutex protection to the function calls.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Implement a concept of Route Preference, as specified in RFC 4191. The
Zephyr host will prefer routes with higher preference, if they lead to
the same prefix through different neighbours.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add support for route lifetime, as defined in RFC 4191. The existing
route adding logic remains the same, if not specified, lifetime is set
to infinite. For routes added with Route Info option from ICMPv6 RA
message, set the expiration timer, according to the route lifetime value
received.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commits adds handling of the Route Information option from
the Router Advertisement message. This option allows to add/delete
routes in the host based on the information sent by the router.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When new route is allocated, a corresponding NBR entry (containing
`struct net_route_nexthop` data) is allocated from
`net_route_nexthop_pool`. When the route was deleted however, the entry
was not freed - only the "core" neighbor entry from the neighbor
management module (nbr.c) was dereferenced. This lead to a resource
leak, effecitevly leaking one `net_route_nexthop_pool` entry for each
deleted route.
Fix this, by defreferencing the NBR entry corresponding to the `struct
net_route_nexthop` data of the deleted route when route is removed.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Verify the `ref` value of the neighbor entry in `net_route_foreach()`,
so that it only executes the callback on routes in use. Otherwise, the
function could call the callback for the route that has already been
deleted.
This could be encountered when executing `net route` shell command,
which printed the already deleted routes along the existing ones.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Added Kconfig configurable choise option for enable Server
object version 1.0 or 1.1.
Server Object v1.1 enable by default server initiated bootstrap
trigger when CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP is enabled.
Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
Deprecate the use of CAN-specific error return values and replace them
with standard errno values.
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit adds an option to store OpenThread settings in RAM for the
case where the flash driver is not available. This can be useful
for testing openthread on new platforms which are still under
development.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
The comment before this change was misleading, as those functions
(and other ones used from the level of user space application) require
DSA interface (like lan{012}), not the master one (like eth0).
Signed-off-by: Lukasz Majewski <lukma@denx.de>
The address of DSA API functions' structure available for usage from
the level of user's application (like for example in
samples/net/dsa/src) is stored in dsa context, not per DSA interface
device.
The struct dsa_context is defined once for all DSA (i.e. not master)
interfaces.
Signed-off-by: Lukasz Majewski <lukma@denx.de>
Transports should close the socket in case of `setsockopt()` failure,
otherwise we end up with a leaked socket, as it won't be closed
elsewhere.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Simplify common `getsockname()` implementation by using VTABLE_CALL()
macro, in the same way as other socket calls do. This additionally
allows to cover the case, when `getsockname()` is not implemnented by
particular socket implementation, preventing the crash.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The device PM subsystem _depends_ on device, not vice-versa. Devices
only hold a reference to struct pm_device now, and initialize this
reference with the value provided in Z_DEVICE_DEFINE. This requirement
can be solved with a forward struct declaration, meaning there is no
need to include device PM headers.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The supported protocol must be delivered to the firmware update object
as optional, then configured in the application.
This information is device/server dependent so does not can be fixed
in library.
Signed-off-by: Jair Jack <jack@icatorze.com.br>
`struct ieee802154_mpdu` access generates warnings related to unaligned
access to packed structure member. The structure itself however does not
need to be packed, since it is not mapped directly into the frame
buffer, but rather contains pointers to the structures representing
corresponding header regions in the frame. Those structures are
correctly defined as packed.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Replace unpacked in6_addr structures with raw buffers in packed icmpv6
structs, to prevent compiler warnings about unaligned access.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Replace unpacked in6_addr structures with raw buffers in net_ipv6_hdr
struct, to prevent compiler warnings about unaligned access.
Remove __packed parameter from `struct net_6lo_context` since the
structure isn't really serialized.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Replace unpacked in_addr structures with raw buffers in net_ipv4_hdr
struct, to prevent compiler warnings about unaligned access.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Replace unpacked in_addr/in6_addr structures with raw buffers in
net_arp_hdr struct, to prevent compiler warnings about unaligned
access.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Make sure that in_addr/in6_addr structure size match the respective
binary IP address size with BUILD_ASSERT.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Added an observe callback so that the application can register to
receive events like observer added/deleted, and notification acked/
timed out. The notifications can be traced back to the exact data
contained within them by use of the user_data pointer.
Fixes#38531.
Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
Add an option in MQTT client context to take advantage of the
"TLS_CERT_NOCOPY" option when using TLS socket transport.
Signed-off-by: Lucas Dietrich <ld.adecy@gmail.com>
Add TLS socket option "TLS_CERT_NOCOPY" to prevent the copy of
certificates to mbedTLS heap if possible.
Add support to provide a chain of DER certificates by registering
them with multiple tags.
Signed-off-by: Lucas Dietrich <ld.adecy@gmail.com>
Since drivers implement a callback based on action and not the state,
we should be using the API based on the action instead of the one based
on the state.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Transition the `user_data` field in `struct net_buf` to be a flexible
array member instead of a hardcoded array. Compile-time asserts are
introduced at the location of the intermediate struct usage to ensure
that the assumptions utilised in runtime code hold true.
The primary assumptions are that the two `user_data` fields exist at the
same memory offset, and that the instantiated struct size can be
determined from the generic struct size and the length of the user data.
`net_buf_id` and `pool_get_uninit` must now use manual address
calculations as the `__bufs` type is no longer the actual size of the
instantiated variable.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Store the `user_data` array size on both the pool and net_buf structs.
This will enable length validation once `user_data` fields are not
globally the same size. The new variables fit inside existing padding,
and therefore do not increase the size of either structure.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Replace the statically defined net_buf with the standard mechanism of
allocating the buffer from a pool. This introduces a minor memory
overhead, but has the benefit of ensuring that standard net_buf calls
will work correctly.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Define a custom IEEE802154 based L2. The user can then use those symbols
to implement their own 802.15.4 based L2, based on those symbols, w/o a
need to modify the Zephyr tree.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Introduce a common config for all 802.15.4 based L2 implementations.
This way, any custom 15.4 L2 implementation will be able to
automatically enable use 15.4 driver, w/o a need to modify the actual
Kconfig.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case the payload and header size exceeded the network MTU size,
`websocket_send_msg()` would only send a part of the payload,
effectively leading to erronous results if called again to send the
rest. Fix the issue, by calling `sendmsg()` in a loop internally in case
it did not manage to send the entire websocket message in a single call.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
`net_eth_vlan_enable()` allowed to use illegal vlan tag values, fix this
by disallowing any tag value higher or equal to 0xfff (which is a limit
for the tag and a reserved value).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Reading a set MTU from the used net_if when starting LCP.
This enables also other custom MTU/MRU to be set for the link than
the default CONFIG_NET_PPP_MTU_MRU (set by a ppp driver during
initialization).
Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
The print specifier for `atomic_t` should be updated
to `%ld`, `%lu`, or `%lx` to account for the type
change of `atomic_t` to `long`.
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
There was a problem with source address selection for ARP
retransmissions, when an ARP entry was already pending. In such case,
the `entry` value passed to `arp_prepare()` is NULL, which in result
caused the `current_ip` variable being used as the source value. The
problem with this approach is, that the `current_ip` is only set in
IPv4 autoconf, the Ethernet L2 does not set this variable. In result,
every retransmission of an ARP packet was sent with unspecified source
address, preventing the response from being handled.
Fix this by partially restoring the behaviour of the ARP source address
assignment from before IPv4 autoconf was introduced. If the ARP is sent
by the IPv4 autoconf, use the `current_ip` value provided. If entry is
not set, use the source IPv4 address set in the actual data packet.
Otherwise, search for a source address on the interface corresponding to
the `entry`.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
TCP2 is no longer needed as it is the unique implementation since the
legacy one has been removed.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Move the structure definition into the relevant header. Rename the
access relevantly as well. It's easier to read without mss_option being
used in various places (struct and access).
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Too long lines and indentations mostly. Let's just keep it concistent
over the file.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
OpenThread has changed it's behaviour in terms of prompt printing in the
CLI module. Previously it was only printed on the UART CLI backend, now
it's printed on every CLI backend. This results in a double prompt being
printed when combined with Zephyr shell (one from OT and other form
Zephyr).
This commit adds a temporary fix to prevent OT prompt from being printed
in Zehpyr shell. As a long term solution we should add an option to
OpenThread to allow to disable prompt on the output.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
During stack reset in RCP, the mac keys are resseting my calling
otPlatRadioSetMacKey with aKeyId == 0. aKeyId == 0 was not handling
properly since it is not valid for mac keys. This commit fixes it.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
Change the wording of the warning printed when there is no entropy to
hopefully remove any doubt that there might be security in TLS without
an entropy source. TLS connections with insufficient entropy are
trivially decodable, and should not be relied on for any type of
security.
Signed-off-by: David Brown <david.brown@linaro.org>
As the already existing macro K_MEM_SLAB_DEFINE results in
two variable definitions, the preceding static modifier leads to
a seemingly working solution, though linkage conflicts will occur
when the same memory slab name is used across multiple modules.
The new K_MEM_SLAB_DEFINE_STATIC macro duplicates the functionality of
K_MEM_SLAB_DEFINE with the difference that the static keywords are
internally prepended before both variable definitions.
The implementation has been tested on my Zephyr project (the build
issue faded out). The documentation has been updated altogether
with all incorrect occurences of static K_MEM_SLAB_DEFINE.
Signed-off-by: Pavel Hübner <pavel.hubner@hardwario.com>
net: lwm2m: When mbedtls CONFIG_MBEDTLS_SERVER_NAME_INDICATION is
enabled, a destination hostname must be passed to socket to properly
connect do lwm2m server.
Passing lwm2m context to lwm2m_parse_peerinfo
Signed-off-by: Jair Jack <jack@icatorze.com.br>
Reason why the prority was at its lowest is unknown, but now that it may
be used to send local packets (which used to be sent right away),
it seems to affect TCP scheduling in loopback mode. Raising the prority
so it matches how it was previously (i.e. sent right away) should fix
things. (Note however that this issue was not broadly present, only
sockets.tls test seemed to be affected.)
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Closing a connection, thus calling net_context_put() will not close a
TCP connection properly, and will leak tcp connection memory.
This is because: net_context_put calls net_context_unref which calls
net_tcp_unref which leads to unref tcp connection and thus sets
ctx->tcp to NULL. Back to net_context_put, that one finally calls
net_tcp_put: but that bails out directly since ctx->tcp is NULL.
Fixing it by inverting net_tcp_put() and net_context_unref() calls
within net_context_put().
Fixes#38598
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
On any target, running a TCP server and a net shell can show the issue:
net tcp connect local_ip port
will fail. Usally it ends up by consumming all tcp connection memory.
This is because in tcp_in(), state changes will most of the time lead to
sending SYN/ACK/etc... packets under the same thread, which will run all
through net_send_data(), back to tcp_in(). Thus a forever loop on SYN ->
SYN|ACK -> SYN -> SYN|ACK until tcp connection cannot be allocated
anymore.
Fixing it by scheduling any local packet to be sent on the queue.
Fixes#38576
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
The device service creates a notification of the current time resource
every 10s. This commit adds the possibility to change this timer to a
different value thus giving more control over the way the device object
is notified.
Signed-off-by: Sebastian Salveter <sebastian.salveter@grandcentrix.net>
Firmware Update object did not initialise resources PkgName,
PkgVersion and Firmware Update Protocol Support. Initialise
Firmware Update Protocol Support on creation and report CoAP
as default transfer protocol.
Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
`engine_remove_observer_by_path()` was not updated during some recent
LwM2M observer changes, still using the `engine_observer_list` which got
moved into the `lwm2m_context` structure. Update the function to align
with these changes.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
`ztls_socket_data_check()` function ignored a fact when
`mbedtls_ssl_read()` indicated that the underlying TCP connection was
closed. Fix this by returning `-ENOTCONN` in such case, allowing
`poll()` to detect such event.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Loop by LOOP_DIVIDER counts instead of the number of seconds
specified in the timeout.
Fixes#39672
Signed-off-by: Paul Gautreaux <paulgautreaux@fb.com>
- Add a `log_strdup` to the role text output for logging V1
compatibility
- Fix style issues
- Change where the documentation refers to an OpenThread device as
"himself" to "itself"
Signed-off-by: Chris Pearson <ctpearson@gmail.com>
If CONFIG_NET_LOG=y is set, OpenThread will output the current OT
role whenever the state changes.
To simplify understanding of the log output, this change replaces
the numerical role ID with the text name of the role. This also
required a change to a documentation file to replace an instance
of a numerical ID.
NOTE: This is potentially a breaking change should anyone be using
test scripts that monitor the OpenThread state changes and look
for the numerical ID. This does not seem to be the case for the
Zephyr tests, however.
Signed-off-by: Chris Pearson <ctpearson@gmail.com>
There is no need to veirfy the result value of the strtol() operation,
as we copy the result to a 64 bit buffer anyway.
CID: 240696
Fixes#39810
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
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>
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>
The OpenThread stack uses uint32_t to calculate expiry time for
alarms, while comparing to zephyr's uint64_t uptime.
This commit fixes broken milliseconds alarms after ~49.7 days of
uptime.
Fixes#39704
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Based on on RFC 8132 -
PATCH and FETCH Methods for the Constrained Application Protocol (CoAP)
Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
Based on on RFC 8132 -
PATCH and FETCH Methods for the Constrained Application Protocol (CoAP)
Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
ipv6_prefix_find() wrongly tests if the unicast address is in use
instead of the prefix. This has two implications:
- The function can return an expired prefix to net_if_ipv6_prefix_add(),
which will do nothing more to enable it (since it assumes that it is
already enabled). As a result, the prefix will not be used by the
rest of the stack due to prefix->is_used being false.
- ipv6_prefix_find() loops using a bound of NET_IF_MAX_IPV6_PREFIX, but
the size of the unicast[] array is defined by NET_IF_MAX_IPV6_ADDR.
This could lead to an out-of-bound access if NET_IF_MAX_IPV6_ADDR is
smaller than NET_IF_MAX_IPV6_PREFIX.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all subsys/net and drivers/ethernet/Kconfig.e1000 settings
having `[EXPERIMENTAL]` in their prompt has has been updated to include
`select EXPERIMENTAL` so that developers can enable warnings when
experimental features are enabled.
The following settings has EXPERIMENTAL removed as they are considered
mature:
- NET_OFFLOAD
- NET_PROMISCUOUS_MODE
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all subsys/canbus, subsys/net/l2/canbus, and drivers/can settings
having `[EXPERIMENTAL]` in their prompt has has been updated to include
`select EXPERIMENTAL` so that developers can enable warnings when
experimental features are enabled.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The condition checks whether the connection was established or not. The
return value should reflect that.
Signed-off-by: Caspar Friedrich <c.s.w.friedrich@gmail.com>
OpenThread has lately got an option to provide a custom
crypto backend that replaces the default, based on mbedTLS
API. Implement a backend based on ARM PSA crypto API that
is better suited for applications willing to take advantage
of the ARM trust zone technology.
Add Kconfig option: OPENTHREAD_CRYPTO_PSA_ENABLE which
enables that backend.
Also, another Kconfig option:
OPENTHREAD_PLATFORM_KEY_REFERENCES_ENABLE, implied by the
former, which enables usage of key references instead of
literal keys in OpenThread. It will eventually allow
OpenThread applications to keep sensitive data such as
encryption keys in the secure storage, accessible from the
secure world only.
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
If a firmware update is fetched from a server, and no port number is set
in the URI (e.g. coap://example.com/fw_update), the client will try
to connect on the port specified by CONFIG_LWM2M_PEER_PORT.
If a port different from the peer port is to be used for firmware
update, this has to be set explicitly in the URI:
coap://example.com:5683/fw_update.
This fix adds CONFIG_LWM2M_FIRMWARE_PORT, which will be used when
fetching a firmware update without specifying the port number in the
URI.
Signed-off-by: Tjerand Bjornsen <tjerand.bjornsen@nordicsemi.no>
Add __printf_like modifier to validate strings used by shell.
Fixing warnings triggered by this change.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Replace the custom float32_value_t LwM2M type with native double, to
facilitate LwM2M API and improve floating point precission.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The irq_lock() usage here is incompatible with SMP systems, and one's
first reaction might be to convert it to a spinlock.
But are those irq_lock() instances really necessary?
Commit 6161ea2542 ("net: socket: socketpair: mitigate possible race
condition") doesn't say much:
> There was a possible race condition between sock_is_nonblock()
> and k_sem_take() in spair_read() and spair_write() that was
> mitigated.
A possible race without the irq_lock would be:
thread A thread B
| |
+ spair_write(): |
+ is_nonblock = sock_is_nonblock(spair); [false]
* [preemption here] |
| + spair_ioctl():
| + res = k_sem_take(&spair->sem, K_FOREVER);
| + [...]
| + spair->flags |= SPAIR_FLAG_NONBLOCK;
| * [preemption here]
+ res = k_sem_take(&spair->sem, K_NO_WAIT); [-1]
+ if (res < 0) { |
+ if (is_nonblock) { [skipped] }
* res = k_sem_take(&spair->sem, K_FOREVER); [blocks here]
| + [...]
But the version with irq_lock() isn't much better:
thread A thread B
| |
| + spair_ioctl():
| + res = k_sem_take(&spair->sem, K_FOREVER);
| + [...]
| * [preemption here]
+ spair_write(): |
+ irq_lock(); |
+ is_nonblock = sock_is_nonblock(spair); [false]
+ res = k_sem_take(&spair->sem, K_NO_WAIT); [-1]
+ irq_unlock(); |
* [preemption here] |
| + spair->flags |= SPAIR_FLAG_NONBLOCK;
| + [...]
| + k_sem_give(&spair->sem);
| + spair_read():
| + res = k_sem_take(&spair->sem, K_NO_WAIT);
| * [preemption here]
+ if (res < 0) { |
+ if (is_nonblock) { [skipped] }
* res = k_sem_take(&spair->sem, K_FOREVER); [blocks here]
In both cases the last k_sem_take(K_FOREVER) will block despite
SPAIR_FLAG_NONBLOCK being set at that moment. Other race scenarios
exist too, and on SMP they are even more likely.
The only guarantee provided by the irq_lock() is to make sure that
whenever the semaphore is acquired then the is_nonblock value is always
current. A better way to achieve that and be SMP compatible is to simply
move the initial sock_is_nonblock() *after* the k_sem_take() and remove
those irq_locks().
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
While adding support for service type enumeration, a regression was
introduced which prevented mDNS ptr query responses.
1. There was an off-by-one error with label size checking
2. Valid queries were failing to match in `dns_rec_match()` due to
not checking for either NULL or 0 "wildcard" port
Fixes#39284
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
From the OMA LwM2M Object and Resource Registry: "When the single Device
Object Instance is initiated, there is only one error code Resource
Instance whose value is equal to 0 that means no error."
This fix creates that initial error code resource instance, and makes
sure that it doesn't get deleted by the Reset Error Code resource.
Signed-off-by: Tjerand Bjornsen <tjerand.bjornsen@nordicsemi.no>
Mbed TLS 3.0 removes the definition for MBED_ERR_SSL_PEER_VERIFY_FAILED,
since non of its code ever returns that value. Since there isn't really
a perfect response, instead return a somewhat generic response
indicating this was unexpected.
Signed-off-by: David Brown <david.brown@linaro.org>
Several fields of structures in mbedTLS 3.0 are now private. To access
them directly is necessary to define MBEDTLS_ALLOW_PRIVATE_ACCESS.
That is a temporary fix, the proper solution is not access directly
but using proper API.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Fixes#38994, ARP messages were being sent to IPvXmcast MAC addresses
rather than the expected source MAC address or the broadcast address.
Signed-off-by: Robert Melchers <rmelch@hotmail.com>
Implements mechanism similar to the one available in net/lib/sockets.c
(since the merge of #27054) in sockets_can to enable parallel rx/tx.
Fixes#38698
Signed-off-by: Mateusz Karlic <mkarlic@internships.antmicro.com>
Add an option to force close the LwM2M connection
instead of always trying to deregister.
If on a cellular connection and the connection is dropped,
deregistering will never complete and take a long time
before retries fail. This option allows the app to close the
socket and quickly re-establish the connection when the
network connection is available again.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
If blockwise transfer is not in use it must be possible to send bigger
CoAP messages than what is the block size used with blockwise transfers.
To compensate for the increased memory usage number of in-flight packets
allowed could be decreased.
Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
...range for LWM2M_COAP_BLOCK_SIZE.
The range has been set to start from 64 bytes and now the help text has
been brought up to date.
Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
Support DNS-SD Service Type Enumeration in the dns_sd library
and mdns_responder sample application.
For more information, please see Section 9, "Service Type
Enumeration" in RFC 6763.
https://datatracker.ietf.org/doc/html/rfc6763Fixes#38673
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
According to `sendmsg()` man pages, the `struct msghdr` can contain
empty records (iov_len equal to 0). Ignore them in TLS `sendmsg()`
implementation to avoid unnecessary calls to mbed TLS.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case zsock_sendmsg did not send all of the data requested, update the
`struct msghdr` content and retry.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If data for `context_sendto()` was provided in a form of
`struct msghdr` (for instance via `sendmsg()`), it was not verified that
the provided data would actually fit into allocated net_pkt. In result,
and error could be returned in case the provided data was larger than
net_pkt allows.
Fix this, by verifying the remaining buffer length when iterating over
`struct msghdr`. Once the buffer is filled up, break the loop. In
result, functions like `sendmsg()` will return the actual length of data
sent instead of an error.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When creating a socket, all of the registered socket implementation are
processed in a sequence, allowing to find appropriate socket
implementation for specified family/type/protocol. So far however,
the order of processing was not clearly defined, leaving ambiguity if
multiple implmentations supported the same set of parameters.
Fix this, by registering socket priority along with implementation. This
makes the processing order of particular socket implementations
explicit, giving more flexibility to the user, for example when it's
neeed to prioritze one implementation over another if they support the
same set of parameters.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As with IPv6, the mdns and llmnr responders should join their multicast
groups for IPv4 instead of just adding the multicast address to the
interface.
Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
As per #38352, we would like to start building out PTP (IEEE 1588)
support for superset of gPTP functionality in Zephyr. This is the first
step to abstract away some key interfaces from NET_GPTP umbrella to
NET_L2_PTP.
Signed-off-by: Alex Sergeev <asergeev@carbonrobotics.com>
RFC 2460 Sec. 5 requires that a ICMPv6 Time Exceeded message is sent
upon reassembly timeout, if we received the first fragment (i.e. the one
with a Fragment Offset of zero).
Implement this requirement.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
The purpose of shift_packets() is to make room to insert one fragment in
the list. This is not what it does currently, potentially leading to
-ENOMEM even if there is enough free room.
To see the current behaviour, let's assume that we receive 3 fragments
in reverse order:
- Frag3(offset = 0x40, M=0)
- Frag2(offset = 0x20, M=1)
- Frag1(offset = 0x00, M=1)
After receiving Frag3 and Frag2, pkt[] will look like:
.-------.-------.-------.
| Frag2 | Frag3 | NULL |
| 0x20 | 0x40 | |
'-------'-------'-------'
pkt[0] pkt[1] pkt[2]
When receiving Frag1, shift_packets(pos = 0) is called to make some room
at position 0. It will iterate up to i = 2 where there is a free
element. The current algorithm will try to shift pkt[0] to pkt[2], which
is indeed impossible but also unnecessary. It is only required to shift
pkt[0] and pkt[1] by one element in order to free pkt[0] to insert
Frag1.
Update the algorithm in order to shift the memory only by one element.
As a result, the ENOMEM test is only simpler: as long as we encounter
one free element, we are guaranteed that we can shift by one element.
Also assign a NULL value to the newly freed element since memmove() only
copy bytes.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
Currently net_ipv6_handle_fragment_hdr() performs 2 distinct tests: it
checks the M-bit of the most recent fragment to decide if we can proceed
with the reassembly. Then it performs some sanity checks which can lead
to dropping the whole packet if not successful.
The test on the M-bit assumes that fragments arrive in order. But this
will fail if packets arrive out-of-order, since the last fragment can
arrive before some other fragments. In that case, we proceed with the
reassembly but it will fail because not all the fragments have been
received.
We need a more complete check before proceeding with the reassembly:
- We received the first fragment (offset = 0)
- All intermediate fragments are contiguous
- The More bit of the last fragment is 0
Since these conditions can also detect a malformed fragmented packet, we
can replace the existing sanity check that is performed before
reassembly. As a bonus, we can now detect and rejected overlapping
fragments, since this can have some security issues (see RFC 5722).
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
Currently we only store the fragment offset. But in some cases it might
be necessary to also inspect the M-bit (More Fragment) of all received
fragments.
Modify the semantics of the field to store all the flags, rename the
setter to account for this change, and add a getter for the M-bit.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
The special handling of the 1st fragment in unnecessary, since it will
be correctly handled even without it. Moreover it causes some corner
cases, like a single packet with a fragment header (M=0), to be
incorrectly handled since the reassembly code is skipped.
Remove the special handling of the 1st fragment to fix these problems.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
Currently the requirement of the length being a multiple of 8 is not
tested for the first fragment, since the first fragment takes a
different path due to the goto.
Move the test earlier in the process, so that it is performed on all
fragments, including the first one.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
If we have less fragments than what can be stored in the reassembly
array, some loops will blindly dereference NULL pointers.
Add checks for NULL pointers when necessary and exit the loop.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
Currently the stack is limited to a maximum of 2 incoming fragments per
packet. While this can be enough in most cases, it might not be enough
in other cases.
Make this value configurable at build time.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
Currently prev_hdr_offset always equals 6, which is the offset of
the nexthdr field in the IPv6 header. This value is used to overwrite it
when removing an IPv6 Fragment header, so it will work as long as there
is no other Extension header between the IPv6 header and the Fragment
header.
However this does not work in the other cases: the nexthdr field of the
IPv6 header will be overwritten instead of the nexthdr field of the last
Extension header before the Fragment, leading to unwanted results.
Update prev_hdr_offset so that it always point to the nexthdr field of
the previous header, either the IPv6 header or an Extension header.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
The current validation code waits to process the header before rejecting
it, while some checks can be already enforced when reading the nexthdr
field of the previous header.
The main problem is a wrong pointer field in the resulting ICMPv6 error
message: the pointer should have the offset of the invalid nexthdr
field, while currently it will the offset the invalid header.
To solve that problem, reorganize the loop in two parts: the first
switch validates nexthdr, while the second switch processes the current
header. This allows to reject invalid nexthdr earlier.
The check for duplicated headers is also generalized, so that we can
catch other kind of headers (like the Fragment header).
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
By definition, NET_IPV6_NEXTHDR_NONE is void. So we must stop processing
before trying to read any data, since we will start reading values that
are outside the Extension Header (likely the payload, if any).
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
When an unknown option is encountered, an ICMPv6 error message must be
sent in some cases. The message contains a pointer field, which must be
the offset to the unknown option. Currently the offset is computed from
the beginning of the option list, while it should be computed with
respect to the beginning of the IPv6 header.
Record the offset when reading the option type and pass it later to
ipv6_drop_on_unknown_option() to correctly set the pointer field. Also
rename the argument in ipv6_drop_on_unknown_option() to make the
purpose more clear.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
Currently PADN data are not skipped, which results in the stack to think
that the next header starts in the middle of the padding. We have to
skip the bytes before going on.
Also clarify the PAD1 does not have any length field.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
The current names are confusing. Indeed "nexthdr" if the type of the
header currently processed, while "next_nexthdr" is the nexthdr field of
the current header.
Rename them to improve readability and make it less error-prone.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
ICMPv6 error messages are not sent (on native_posix) because the first
net_pkt_write() returns an error.
pkt has just been allocated using net_pkt_alloc_with_buffer(). Trying to
write an empty packet in overwrite mode will result in an error. There
is no need to be in overwrite mode, since we want to write the LL
src/dst addresses at the beginning.
Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
Refactor IPv4 multicast address to MAC multicast address conversion
into its own function, so it can be reused by drivers as it is already
possible for IPv6 multicast addresses.
Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
In case LwM2M server or bootstrap server rejected
Registration/Registration Update/Deregsitration attempt, there were no
reasonable notification to the application. Fix this by reporting
LWM2M_RD_CLIENT_EVENT_*_FAILURE in such case.
Addtitionaly, remove pointless ENGINE_DEREGISTER_FAILED event, which
have no use in the state machine.
Finally, simplify the response code logging to prevent code duplication.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The Counter resource in the IPSO Push Button object was incremented
silently by the post write handler of the State resource. This prevented
the resource from being marked as updated, effectively preventing
the engine from sending notifications to observers.
Fix this, by setting the new counter value with `lwm2m_engine_set_u64()`
instead. This will update the resource value, and trigger the engine to
send notifications if needed.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
HTTP_DATA_FINAL was incorrectly notified in case Content Length field
was present in the HTTP respone - in such case it was set for every
response fragment, not only the last one.
Fix this by relying on `message_complete` flag instead of
`http_should_keep_alive()` function to determine whether to notify
HTTP_DATA_FINAL or not. As the HTTP parser calls the
`on_message_complete()` callback in either case (response is chunked or
not), this seems to be a more reasonable apporach to determine whether
the fragment is final or not.
Additinally, instead of calling response callback for
`on_body`/`on_message_complete` separately, call it directly from
`http_wait_data()` function, after the parsing round. This fixes the
case when headers were not reported correctly when the provided buffer
was smaller than the total headers length, resulting in corrupted data
being reported to the user.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The helper function to conver 32-bit binary float value to
float32_value_t incorrectly identified the "hidden" bit, resulting in
invalid conversion when TLV encoding was used to write a resource
(the output value was divided by 2).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
There were several issues preventing JSON format writes to work
correctly:
1. The formatter wrongly assumed that Base Name and Relative Name values
read from the message are NULL terminated, which in result could give
invalid results when combining them.
2. The formatter wrongly assumed that Relative Name is always present,
which is not always the case. In result, it failed to parse messages,
which contained full path in their Base Name Field
3. There were no boundaries check when reading JSON variable name/value,
which could lead to buffer overflow in case malformed data was
received.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Just like plain text, JSON parser ignored leading zeros after decimal
point, giving invalid results. Fix this in a similar way as for the
plain text.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Floating point parser for plain text format was parsing floats wrongly,
ignoring leading zeros after decimal points.
Fix this, by reusing atof32() function, already avaialbe in a different
part of the engine, which did the parsing correctly.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
According to the specificaion, resources are not predefined to use 32 or
64 bit floating point numbers, but should rather accept any of them (as
indicated by the size of the TLV in the message). This lead to issues
for instance with Eclipse Leshan LWM2M server, where Leshan sent 64-bit
value, while Zephyr expected 32-bit, making it impossible to write
the resource.
Therefore, unify the float usage to 32-bit float representation and fix
the TLV parsing functions, to accept values sent as either 32 or 64 bit
float.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The `poll()` function did not report POLLHUP if the peer ended the DTLS
session, making it impossible to detect such event on the application
side.
On the other hand, TLS erroneusely reported POLLHUP along with each
POLLIN event, as the 0 returned by the `recv()` socket call was
wrongly interpreted (it was expected to get 0 in return as 0 bytes were
requested).
Fix this by introducing a helper function to process the mbedtls context
and verify if new application data is pendingi or session has ended.
Use this new function in the poll handler, instead of a socket `recv()`
call, to remove any ambiguity in the usage, for both TLS and DTLS.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Notify the application when DTLS client session ends by returning
ENOTCONN on such event. Additionally, reset the mbed TLS session
structures, allowing to reinstante the session on the next send() call.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
ECONNABORTED was returned in case tls_mbedtls_reset() function for
resetting session failed, which can be caused by memory shortage. Return
ENOMEM instead.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
net_packet_socket_input() was changed to hardcode the return of
NET_CONTINUE and that caused a segmentation fault/crash in
net_core/process_data(), in cases when pkt was unreferred and
NET_OK was returned from net_conn_input()
This happened with socket combo of: AF_PACKET+SOCK_RAW+IPPROTO_RAW.
Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
The nbr_lock var actually depends on CONFIG_NET_IPV6_NBR_CACHE
(not CONFIG_NET_IPV6_ND), so move its initialization call.
Signed-off-by: Stancu Florin <niflostancu@gmail.com>
BT_SECURITY_LOW and etc. were previously renamed and are no longer
valid.
The original rename is in the following commits:
1c48757d94 (New names, deprecate old)
5f2a9ba8e4 (Remove deprecated names)
Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemiconductor.no>
Since it's not possible to encode full range of 64-bit unsigned integer,
remove this type from the LwM2M implementation, and replace its uses
with 64-bit signed integer.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As the resource values represented by the unsigned integers were casted
to integers of a corresponding size in the read handler, they were not
ecoded properly if the unsigned value was larger than the maximum
integer value of the corresponding size (i.e. they were encoded as
negative values).
Fix this by casting the unsinged value to a wider integer type, to
prevent incorrect interpratetion of the data provided. The TLV encoding
functions take care of the optimization (i. e. encoding integers on the
minimum number of bytes needed), so it should prevent bandwith waste if
the unsigned value would actually fit into the integer of the
corresponding size.
Similar case is for the write hander, where unsigned integers encoded at
8 bytes were not processed correctly. Fix this by using wider decoder as
well.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Listing a neighbour table with "net nbr" command, when a neighbour w/o
assigned link address was present, resulted in an assert condition. Add
additional check to prevent this.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
TCP state machine gets stuck in TCP_FIN_WAIT_2 state
when server responds with [ FIN, PSH, ACK ]
Fixes#37842
Signed-off-by: Nicolas Marty <nicolas.marty@zuehlke.com>
Using zsock_ in http_client instead of the POSIX API versions of the
functions allows the usage of http_client in combination with
CONFIG_POSIX_API.
Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
Function parameters can be checked without MQTT instance lock being
held. Additionally if NULL parameter would be passed (which this check
tries to handle), then function would return without releasing lock.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
Sending of > 2k buffers leads to split socket writes.
Current implementation is not checking for full buffer size.
ztls_sendmsg_ctx proceeds to next iov on sucessful write.
Solution: Add loop into ztls_sendmsg_ctx to process whole buffer
before proceeding to next iov.
Signed-off-by: Pavlo Hamov <pasha.gamov@gmail.com>
Rework NCP interface configuration and NCP sample. Remove
CONFIG_OPENTHREAD_COPROCESSOR_SPINEL_ON_UART_DEV_NAME and
CONFIG_OPENTHREAD_COPROCESSOR_SPINEL_ON_UART_ACM Kconfig
options in favor of chosen node zephyr,ot-uart usage.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Checks PAN ID for matching self address / broadcast, then the short /
extended address based on the used address mode.
Only when IEEE802154_HW_FILTER is not advertised by driver.
Signed-off-by: Stancu Florin <niflostancu@gmail.com>
Instead of putting object files inside libzephyr.a,
simply build a separate static library as most other
driver types are doing this already.
Note that the include to subsys has been moved from
under the drivers into subsys, as it is actually
the subsystem's job to make sure the include
directories are correct.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This migrates all the current iterable section usages to the external
API, dropping the "Z_" prefix:
Z_ITERABLE_SECTION_ROM
Z_ITERABLE_SECTION_ROM_GC_ALLOWED
Z_ITERABLE_SECTION_RAM
Z_ITERABLE_SECTION_RAM_GC_ALLOWED
Z_STRUCT_SECTION_ITERABLE
Z_STRUCT_SECTION_ITERABLE_ALTERNATE
Z_STRUCT_SECTION_FOREACH
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
When transmitting a frame, inform the radio driver whether
security processing and/or header updates are needed or not.
When a frame was transmitted, inform back to OpenThread whether
the security procedure and/or header updates were completed for
the frame or not.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
By default ICMP desination unreachable error packets are generated when
input packets target ports that are not in a listening state. This not
only reveals the presence of the host on the network which may be
considered a security vulnerability depending on the application, it
also ends up triggering ARP lookups to respond to the sending host. With
a small ARP table and a network where there may be broadcast (or
multicast) service discovery traffic such as mDNS or uPnP, ARP table
thrashing can occur impacting network stack performance.
Signed-off-by: Berend Ozceri <berend@recogni.com>
Socket CAN does not require interface link address to be
assigned, check is not applicable for socket CAN
interfaces. As this address is NULL for socket CAN interface
it results in assertion.
Signed-off-by: Ramesh Babu B <ramesh.babu.b@intel.com>
k_timeout_t was converted to ticks using a nonsense function
causing poll timeout corruption for offloaded sockets; this
commit uses ticks directly from the struct instead.
Fixes#37472
Signed-off-by: Emil Lindqvist <emil@lindq.gr>
According to MbedTLS API documentation, its session must be
reset if mbedtls_ssl_handshake returns timeout error. This
commit resets the session for said return value, and that
allows us to call send() multiple times even if handshake
times out for previous calls.
Fixes#35711
Signed-off-by: Emil Lindqvist <emil@lindq.gr>
Add missing otPlatTimeGet implementation which is needed for proper
calculation the time offset in host-RCP communication.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
Fix potential bug when returning error codes not handled by
OpenThread in `otPlatRadioTxDone`.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
ZFD_IOCTL_POLL_OFFLOAD operation needed special handling, as it needed
to modify the fds table for the offloaded implementation, overwriting
websocket file descriptors with the underlying offloaded ones. This is
only needed for the offloaded sockets, as the native implmentation use
POLL_PREPARE/UPDATE operations instead.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The websocket implementation of ioctl wrongly passed websocket context
to the undrelying `ioctl` implementation instead of the context of the
underlying socket.
Additionally, currentl implementation used the vtable of the native
socket implementation unconditionally, making it unusable with an
offloaded underlying socket.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The verb tense for the suspended state was not consistent with other
states. The likely reason: state was being used as a command/action.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
A mutex is used to syncrhonize the start, stop and service() functions
of the RD client. Previously it could happen that while service() was
working on e.g. bootstrapping, a stop() call by another thread would
close the socket. Then the bootstrapping process would detect it as a
network error, and restart the process.
Fixes#37170.
Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
Change DSA API to use `net_if` directly to make API calls instead of
indirectly via `dsa_context` and `switch_id`.
Remove unused `switch_id`, `switch_enable_port`, and `dsa_get_context`.
Signed-off-by: Arvin Farahmand <arvinf@ip-logix.com>
Check for the address family of the packet when setting the multicast
destination address used in the response. Current code checks either the
query type or the stack configuration, which can result in setting the
wrong type of address for the frame.
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
This provides a command line interface to query and modify
bridge instances, similar to Linux's brctl utility.
It can be used to inspect an application's bridge usage,
or manage a bridge of its own in a generic way.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This adds the ability to create Ethernet bridges for connecting
separate Ethernet segments together to appear as a single
Ethernet network.
This mimics the Linux functionality of the same name.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
In case a non-readable resource gets updated (either by the server or
with an API), it makes no sense to send a notification in such case, as
no such resources are not included in notifications anyway.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Flag that indicates if a given packet is being retransmitted has become
obsolete since more detailed flags were added. This commit removes the
flag and references to it altogether.
Signed-off-by: Jedrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
Fix `poll()` handling for DTLS clients when the underlying socket is an
offloaded socket. As in this case no `k_poll()` is used underneath, it's
not possible to monitor the handhshake status with `tls_established`
semaphore. Instead, do the following:
1. If no handhshake is in progress yet, just drop the incoming data -
it's the client who should initiate the handshake, any data incoming
before that should not be processed.
2. If handshake is currently in progress, lift the `POLLIN` flag and add
small delay to allow the other thread to proceed with the handshake.
3. Otherwise, just proceed as usual.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The TLS/DTLS handshake in most cases is a blocking process, therefore
the underlying socket should be in a blocking mode to prevent busy
looping in the handshake thread. Fix this by clearing the O_NONBLOCK
flag on the underlying socket before the handshake, and restoring it
afterards.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The openthread has enhanced features for periodic parent search,
this commit adds kconfig options to enable and configure these.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Introduce a helper function for being able to remove any arbitrary
length from tail of packet. This is handy in cases when removing
unneeded data, like CRC once it was verified.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
`OT_LOG_LEVEL_NONE` has some uses within OpenThread but it is not
hanled in the Zephyr's platform implementation. This commit makes
use of those logs as `LOG_LEVEL_ERR` level.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
The callback is not used anymore, so just delete it from the pm_control
callback signature.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
When zsock_close() is called, socket is freed before the mutex for the
socket is unlocked. If the freed socket is given to another thread
immediately, the mutex for the socket will be initialized by the new
socket owner, while the mutex is still locked by the thread calling
zosck_close().
Fixes#36568
Signed-off-by: Chih Hung Yu <chyu313@gmail.com>
When tcp_send_data() is called to resend data, but there is no data
to resend, zero length packet is allocated and NULL net_buf is passed
to net_buf_frag_insert() in which assertion fails.
Fixes#36578
Signed-off-by: Chih Hung Yu <chyu313@gmail.com>
6lowpan module can swap the original buffer with a newly allocated one
during decompression in case the decompressed header would not fit into
the original buffer. Therefore, storing the LL address offset and
restoring the pointer after decompression as it is done today is not
correct, as the new packet with decompressed IPv6 header will not
contain the LL header.
As the 6lowpan module doesn't deallocate the original buffer and
doesn't overwrite the LL header, its fine to use the original
pointers as they are.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Regular OpenThread upmerge to bring in a fix for a possible
infinite loop and support for DNS service subtypes.
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
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>
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>
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>
Rename `write_signal` to `readable` and `read_signal` to `writeable`
which are more meaningful to the actual states they represent, and make
the code analysis easier.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case read or write were called before the actual poll() call, the
poll() function was not signalled correctly about such events, which in
order could lead to a deadlock if the poll() was called with infinite
timeout.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This will fix a bug caused by creating a multi instance resource with
only a single resource. Previously this was treated as a single instance
resource. This is now properly treated as a multi instance resource with
one instance
Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
Add new custom transport type.
This allows user defined transport for MQTT communication.
The user must implement the transport procedure.
Fixes **#27015**
Signed-off-by: Vlad Tuhut <vlad.tuhut@raptor-technologies.ro>
Direct openthread API usage requires explicit locking,
which is also used internally.
Exposing a work queue through the openthread context allows
work to be submitted without the need to block other threads.
In particular with CONFIG_OPENTHREAD_MANUAL_START, application
logic can offload work which otherwise would need to wait for
the lock to become available.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
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>
- bugfix: Accept initial tftp server reply from a port different than
the one used to establish the connection (typically 69) as mandated
by RFC 1350. Previous implementation was not standard compliant.
- bugfix: close socket in case of error or timeout.
- bugfix: Reset retransmit counter after receipt of a good packet.
- bugfix: Use CONFIG_TFTP_LOG_LEVEL to set log level.
- api: upon successful receipt of the file set `client.user_buf_size`
to the size of the file received.
- Restructure the code, comments.
- Limit usage of global variables.
- Limit usage of `goto`.
Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
The openthread initialization in turn calls platform specific
functions, lock the API during this step.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Added notify_timeout_cb to struct lwm2m_ctx to allow application to
handle notify timeout
Added lwm2m_rd_client_update to lwm2m.h to allow application to
trigger registration update
Added notify_message_timeout_cb which calls notify_timeout_cb from
struct lwm2m_ctx and logs an error message
Fixes#31499
Signed-off-by: John Power <john.power@xylem.com>
This commit fixes diag repeat command port by fixing issue with
incorrectly handled repeat timer.
Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
There is a small window between when socket is created and
before it is bound to a local address, where the local address
pointer might be NULL.
Fixes#36276
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
TCP unacked_len can be set to zero in tcp_resend_data(),
and then be minus by len_acked when ACK is received,
resulting in a negative unacked_len value.
Fixes#36390
Signed-off-by: Chih Hung Yu <chyu313@gmail.com>
Allow caller to specify microsecond accuracy and not convert
to milliseconds.
Fixes#36072
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Make zsock_select() a syscall so that the following commit
can call the internal poll implementation directly. This is
needed as zsock_select() will not call zsock_poll() directly
in order to allow select to use microsecond timeout accuracy.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
In case both, static IP address configuration and DHCP were used, and no
DHCP server was avaliable in the network, clearing the gateway address
rendered the network interface unusable as it's gateway configuration
was cleared.
Prevent this by removing the gateway clearing during the DHCP
inititalization. If the DHCP server is available in the network, the
gateway address will be overwriten after receiving the DHCP OFFER
message or cleared if there's no Router option is avaiable in the
DHCP OFFER message.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
After lwm2m async io was introduced with 32989a38f0,
one instance of function lwm2m_send_message() was left unchanged,
and makes build to fail when boostrap support is enabled.
Signed-off-by: Kiril Petrov <retfie@gmail.com>
Allow caller to either set or receive various Ethernet Qbu
configuration options defined in IEEE Std 802.1Qbu-2016
specification.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Allow caller to either set or receive various Ethernet Qbv
configuration options defined in IEEE Std 802.1Qbv-2015
specification.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Fixed issue that caused message to be not correctly reset even after
it is consumed after send sets errno to EAGAIN or EWOULDBLOCK
Signed-off-by: Dominik Dess <dominik.dess@grandcentrix.net>
The ieee802154_frame_retry will be set by the OpenThread integration
layer in the event of frame retransmission.
Signed-off-by: Rafał Kuźnia <rafal.kuznia@nordicsemi.no>
Fill the ACK timestamp field in nRF5 driver. This is required by
OpenThread for the proper CSL transmitter functioning.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Fixed mutli-IP DNS resolution as previously the same IP address was
used to populate all AI entries and added DNS_RESOLVER_AI_MAX_ENTRIES
config entry to define max number of IP addresses per DNS name to be
handled.
Signed-off-by: Ievgen Glinchuk <john.iceblink@gmail.com>
Use IE variable of ieee802154 MAC frame instead of Thread specific
configuration call for configuring injection of vendor specific
data into enh ack.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
this has a number of advantages:
- allows to only create notifications for each client if there are no
messages already waiting to be send, in practice prioritizing the
memory for messages for answers, thus staying more "responsive".
- saves a fair bit of memory by eliminationg now redundant client_ctx
pointer per observer.
- fixes a potential subtle bug: previously, an observer reset would've
stopped the first observation found with a matching token, which
might've belonged to a differen client.
Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
This restructures the lwm2m_engine to use a non-blocking socket access
instead of the previously used blocking style, and eliminates any
socket-access from outside of the main work loop.
The main motivation behind this is an issue within nordics
nrf_modem_lib/modem-fw on nrf9160, that leads to socket send() calls to
block indefinitely when the shared memory used for
rpc-communication with the modem is already exhausted because of
incoming data.
This lead to the lwm2m_engine locking up on send calls when there is
also a large amount of incoming data.
This works around this issue, by only issuing send calls when poll
reports the socket to be ready for sending, and (more importantly) by
always receiving all buffered incoming data before sending anything.
There might still be a (perhaps academic) possibility where this
situation might be triggered, when the scheduler interrupts the lwm2m
thread in-between receiving and sending, but for now we have not yet
observed this.
Besides working around the aforementioned issue, this also simplifies
the way resends are handled as they are no longer send from the main
system-workqueue, and limits all interaction with the sockets to a
single thread.
Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
Keys management API for IEEE 802.15.4 drivers was specific for Thread
protocol. With this change API is more generic and aligned with Thread
needs.
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
Zephyr has introduced secure random generator API after the TLS sockets
were implemented. Use this new API in TLS sockets implementation,
instead of implementing secure RNG with mbedTLS in the module itself.
This facilitates integration of the HW RNG accelerators with the TLS
sockets module.
Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If radio driver supports transmission security we need an option
to disable transmission security which by default is done by OT stack
for Thread v1.2
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
This commit allows to add callbacks to NET_EVENT_IF_UP events before
the network initialization.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
OpenThread expects the FCS field at the end of the ACK frame to be
passed with `otPlatRadioTxDone`.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Not checking return code in fcntl can result in interpreting -1 as
flags, and cause unexpected behaviour.
Fixes#35541
Signed-off-by: Emil Lindqvist <emil@lindq.gr>
If we receive any data in FIN_WAIT_1, then ack it even if we
are discarding it.
Fixes#33986
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Jim Paris <jim@jim.sh>
The k_fifo_ prefix is meant for kernel API functions, and
not to our socket helper. So remove the k_ prefix in order
to avoid confusion.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If we are waiting all the data i.e., the MSG_WAITALL flag is set,
then if we have not yet received all the data at the end of the
receive loop. We must use the condition variable to get the signal
when the data is ready to be received. Otherwise the receive loop
will not release the socket lock and receive_cb will not be able
to indicate that data is received.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Fix a regression when application is waiting data but does
not notice that because socket layer is not woken up.
This could happen because application was waiting condition
variable but the signal to wake the condvar came before the
wait started. Normally if there is constant flow of incoming
data to the socket, the signal would be given later. But if
the peer is waiting that Zephyr replies, there might be a
timeout at peer.
The solution is to add locking in socket receive callback so
that we only signal the condition variable after we have made
sure that the condition variable is actually waiting the data.
Fixes#34964
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If there are no sockets in the system, then do not drop the
packet immediately as there can be other L2 network handlers
like gPTP in the system. This will also allow ICMP messages
to pass to local handler.
Fixes#34865
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The resource description on the OMA LwM2M registry states that only the
first instance of a particular error should trigger creation of a new
error code instance.
Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
When application calls TCP connect(), the call is blocked
by a semaphore which is then released when the connection
is established. Unfortunately the semaphore release was done
before the connection was marked as established. Depending
on the configuration options set, it is possible that after
the semaphore release, the thread that is waiting on connect()
is run immediately. Because of this, the connection bookeeping
still thought that the connection was not established even if
it was. A simple solution is to release the semaphore after
the connection is marked as established.
Fixes#35390
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Call on_status if the Reason-Phrase is not provided.
This allows for the numeric status code to be set.
Also, ensure the numeric status code is always set
in on_status, not just if the specific callback is set.
Signed-off-by: Justin Morton <justin.morton@nordicsemi.no>
Without TX thread support in network stack USB device stack
blocks it self by usb_transfer_sync() which is
called in the same context as usb_set_interface() in sequence
of netusb_enable(), net_if_up(), net_l2_send().
Fixes: #35338
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This was already implemented for firmware update packages.
For other opaque resources it failed to determine the target resource
id, which is now stored in the block_context.
Signed-off-by: Jan Buenker <jan.buenker@grandcentrix.net>
OpenThread shell tries to execute commands without checking
if the shell has already been initialized. As a result, we
may hit an assertion in the OpenThread CLI code. It's
particularly painful in automated tests which spawn commands
very early in the firmware boot process.
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
The return value might be uninitialized if there was no
suitable IPv4 address found for the network interface.
Coverity-CID: 224630
Fixes#35158
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
After the recent OpenThread upmerge, OpenThread changed its behaviour in
terms of CLI handling during commissioning procedure. OpenThread will
now call the registered CLI callback when it recieves the Discovery
message.
This resulted in a crash if no CLI command was executed by the user
before, because the `shell_p` pointer was only set in the command
handler. As it was not set to the actual shell backend instance, it
caused a crash (or assert if enabled) in the `shell_vfprintf()`
function.
Fix this by verifying the `shell_p` pointer in the
`otConsoleOutputCallback()` function before use. Additionally, set the
pointer to the most common UART shell backed (if enabled) in the
initialization function so that the initial messages from OpenThread are
not dropped.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When destination address is a multicast address, select the source
address from non link local address first.
This means that for example if we are responding to mDNS query,
and we have both normal IPv4 and LL (169.254.x.y) address set for
the interface, we are now able to select the normal address instead
of the LL one.
Fixes#34409
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The ISN algorithm from RFC 6528 doesn't need Mbed TLS, but rather the
MD5 algorithm from Mbed TLS. Therefore select MBEDTLS_MD and
MBEDTLS_MAC_MD5_ENABLED in addition to MBEDTLS.
This fixes the following build failure when using TLS version 1.2 is
selected:
zephyr/subsys/net/ip/tcp2.c:1329: undefined reference to
`mbedtls_md5_ret'
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
SRP client and server require ECDSA to be enabled otherwise the build
fails. Select OPENTHREAD_ECDSA for both OPENTHREAD_SRP_CLIENT and
OPENTHREAD_SRP_SERVER options.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
OPENTHREAD_SRP_CLIENT and OPENTHREAD_SRP_SERVER are Thread features and
not Thread configuration, so move them to Kconfig.features.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
The OPENTHREAD_MAX_CHILDREN and OPENTHREAD_MAX_IP_ADDR_PER_CHILD options
make not sense for a MTD device. Make them depend on OPENTHREAD_FTD.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
With the updates to mbedTLS Kconfig it is now possible to update the
OpenThread security configurations by disabling the mbedTLS prompt and
avoid stuck symbol selection.
As part of this, the OpenThread security selection has been reworked
into a choice which ensures only a single security selection can be
chosen.
And the OPENTHREAD_MBEDTLS itself has been made promptless to ensure
other parts of the build system can select a specific OpenThread
security implementation and disable user selection, if the module or
sample require such behavior.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
In Mbed TLS:
commit eccd88871767e2fba5f3a079cfdfcb77c376cf20
Author: Gilles Peskine <Gilles.Peskine@arm.com>
Date: Tue Mar 10 12:19:08 2020 +0100
Rename identifiers containing double-underscore
changes the name of a symbol we use. As part of upgrading to newer
versions of Mbed TLS, change the name of the symbol we use.
A better fix would be to not use this symbol at all, and perhaps define
our own symbol the same way this internal symbol is defined within the
library.
Signed-off-by: David Brown <david.brown@linaro.org>
With the updates to mbedTLS Kconfig it is now possible to update the
OpenThread security configurations by disabling the mbedTLS prompt and
avoid stuck symbol selection.
As part of this, the OpenThread security selection has been reworked
into a choice which ensures only a single security selection can be
chosen.
And the OPENTHREAD_MBEDTLS itself has been made promptless to ensure
other parts of the build system can select a specific OpenThread
security implementation and disable user selection, if the module or
sample require such behavior.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The k_work handler cannot manipulate the used k_work. This means
that it is not easy to cleanup the net_pkt because it contains
k_work in it. Because of this, use k_fifo instead between
RX thread and network driver, and between application and TX
thread.
A echo-server/client run with IPv4 and UDP gave following
results:
Using k_work
------------
TX traffic class statistics:
TC Priority Sent pkts bytes time
[0] BK (1) 21922 5543071 103 us [0->41->26->34=101 us]
[1] BE (0) 0 0 -
RX traffic class statistics:
TC Priority Recv pkts bytes time
[0] BK (0) 0 0 -
[1] BE (0) 21925 6039151 97 us [0->21->16->37->20=94 us]
Using k_fifo
------------
TX traffic class statistics:
TC Priority Sent pkts bytes time
[0] BK (1) 15079 3811118 94 us [0->36->23->32=91 us]
[1] BE (0) 0 0 -
RX traffic class statistics:
TC Priority Recv pkts bytes time
[0] BK (1) 0 0 -
[1] BE (0) 15073 4150947 79 us [0->17->12->32->14=75 us]
So using k_fifo gives about 10% better performance with same workload.
Fixes#34690
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Following commits will remove k_work from net_pkt, so convert
PPP L2 to use k_fifo when sending PPP data.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Following commits will remove k_work from net_pkt, so convert
6locan L2 to use k_fifo between application and TX thread, and
driver and RX error handler.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit implements the OpenThread APIs to configure Enhanced-ACK
Based Probing in radio for a specific Initiator. This is needed for
Link Metrics functionality.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
This commit implements the missing OpenThread APIs related to CSL
receiver configuration.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Add extra check for the LwM2M client state, to allow triggering of the
Registration Update message only when registered.
This fixes an issue, when the `trigger_update` flag could be set during
the bootstrap procedure (when the value of the Lifetime resource was
set), which resulted in an uneccessary Registration Update message just
after the successful registration.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit implements the OpenThread APIs to configure a radio
reception slot at a specific time. This is needed for the correct
functioning of a CSL receiver.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
This commit implements the OpenThread APIs to pass MAC keys and
frame counter to the radio layer in order to process the
transmission security. This is needed for the correct functioning
of a CSL transmitter.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
The device has sent RESET_POWER_UP message before the communication
with the host hadn't been established. It could be observed with
pyspinel which displayed `Framing error`.
This commit fixes the bug by initializing NCP after the host stated
is ready to communicate.
This commit reverts initialization the USB stack into function
otPlatUartEnable to be consistent with others OpenThread platforms.
OpenThread co-processor samples are not affected by #27071 as they use
USB for SPINEL communication with host and not for UART console.
Note:
When co-processor communicates by USB CDC ACM and it is hard reset
(what is happening in current Zephyr OpenThread platform)
the connection needs to be properly handled by the host.
For posix platform used together with RCP it was implemented in:
https://github.com/openthread/openthread/pull/6454
and for NCP:
https://github.com/openthread/wpantund/pull/492 .
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
OpenThread modified its NCP API, so we need to align with these changes
in Zephyr.
One of the major changes was removal of UART from the platform APIs.
`openthread/platform/uart.h` header file was moved to
`examples/platforms/util/uart.h` so we need to use the new location in
Zephyr. This means that OpenThread no longer impose the UART API but for
the simplicity of the upmerge I've kept the UART APIs as they are for
now.
The NCP initialization function have now to register a send handler,
and the appropriate transport driver have to call NCP callbacks when
transmission/reception is done. For now, re-use the existing code of
the UART driver, just as the upstream NCP application does.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Use OpenThread mutex in order to protect OT CLI API call instead of
halting the OpenThread thread.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The OpenThread CLI API has changed therefore it's needed to align
OpenThread Shell implementation in Zephyr with these changes.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Since the API already has a function to create an LwM2M object instance,
it makes sense to add a corresponding delete funtion, allowing the
application to delete created objects.
Additionally, for the remote delete set the Registration Update trigger
only when not in bootstrap mode.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The Registration Update message should be sent whenever an object
instance is created or deleted. Currently this was only the case when an
object instance was created by the server and not by the application.
Fix this by triggerng the Registration Update from the API function
as well.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This PR increases the OpenThread stacks to compensate
for the runtime increase of the MPU stack guard
when the usage of the FP context is detected.
Signed-off-by: Piotr Szkotak <piotr.szkotak@nordicsemi.no>
Use recently introduced API, which takes care of gracefully closing any
pending DNS requests and replacing existing DNS server list with new
one.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Use recently introduced API, which takes care of gracefully closing any
pending DNS requests and replacing existing DNS server list with new
one.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
So far there was no dedicated mechanism for replacing DNS servers with
new list. Add dns_resolve_reconfigure() API that allows to achieve that
in a thread-safe manner.
Introduce 3rd state in DNS context lifetime by converting from 'bool
is_used' to 'enum dns_resolve_context_state state'. This new
DEACTIVATING state allows to mark a DNS context as busy and safely close
context without holding lock. Closing DNS context with released lock
prevents deadlock in case net_context_close() has to synchronize with a
separate thread executing handler passed to net_context_recv() (which is
the case for example with ESP-AT WiFi driver).
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
ctx->is_used member seemed to be used sometimes within a mutex acquired
block, sometimes not. Make it consistent by always using it with
acquired mutex.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Reboot functionality has nothing to do with PM, so move it out to the
subsys/os folder.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Currently the lwm2m_path_log_strdup allocates a temporary buffer on a
stack, and then passes it to the log_strdup function to create a copy
of the string for the logger. log_strdup however will not copy the
string if for instance immediate logging is used, therefore the logging
function will still use the memory address of the already invalid buffer
allocated within lwm2m_path_log_strdup.
Fix this by passing an addittional `buf` parameter to the
lwm2m_path_log_strdup function, therefore allowing the user to provide
the buffer within a valid scope.
CID: 220536
Fixes#34005
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
zsock_select() cannot poll file descriptors with number >= 32.
When a whole word in FD_SET was skipped due to being empty,
corresponding fd number was not updated, leading to wrong
fd's being passed to poll().
Fixes#34563
Signed-off-by: Chih Hung Yu <chyu313@gmail.com>
Initializing a work item from its handler will destroy the content of
the kernel structures used to process the work item. This can lead to a
system crash for example when the delayed work is being rescheduled when
the previous run is already queued for processing but not yet executed.
Fix this by initializing the work item once during trickle timer
creation and moving the logic, previously achieved by switching the work
handler, into the new work handler.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This value is used to measure the RX/TX statistics. The previous
use of the timestamp field did not work in RX path as the timestamp
value could be overwritten by the driver if gPTP timestamping
is enabled. So to fix the RX statistics, use a separate field
for the create time.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If user enables CONFIG_USERSPACE, then at least one TX or RX thread
is needed to isolate the application from the kernel space components.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Set the default behaviour of the networking subsystem so that
no TX or RX threads are created. This will save RAM as there
is no need to allocate stack space for the RX/TX threads.
Also this will give small improvement to network packet latency
shown here:
* with 1 traffic class (1 TX and RX thread)
Avg TX net_pkt (42707) time 60 us [0->22->15->22=59 us]
Avg RX net_pkt (42697) time 36 us [0->10->3->12->7=32 us]
* with 0 traffic classes (no TX and RX threads)
Avg TX net_pkt (41608) time 42 us [0->21->20=41 us]
Avg RX net_pkt (41593) time 31 us [0->9->12->8=29 us]
In this qemu_x86 test run, 40k UDP packets was transferred between
echo-server and echo-client. In TX the speed increase was 30% and
in RX it was 14%.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Set the net_pkt creation time just before the actual net_pkt
is allocated in order to get more accurate information for
statistics.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If user has set the priority of the sent net_pkt to highest
priority (NET_PRIORITY_CA) and enabled CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO
option, then push that packet directly to driver instead of TX queue.
This will make the TX sending latency smaller for the high priority
packet. This is not enabled by default.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add support for delayed transmission of frames for the CSL
Transmitter OpenThread function.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
The net_shell only uses iface_flags2str when CONFIG_NET_NATIVE is
enabled. Disabling this produces an "unused function" warning for this
function. Wrap the function in an #ifdef to silence the warning for this
configuration.
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
This option was only able to collect statistics of transmitted
data. The same functionality is available if one sets the
CONFIG_NET_PKT_RXTIME_STATS and/or CONFIG_NET_PKT_TXTIME_STATS
options.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The RX statistics might not get updated properly because the used
ifdef was referring the TX options.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Query timeout handler is rescheduled if DNS context mutex is locked. So
far there was no timeout used, which means that work is simply put at
the end of system workqueue. This solves cases when mutex is locked by
any higher priority cooperative threads.
If however mutex was locked in application code within lower priority
thread (which is very likely) and query timeout has expired in the
meantime, then system workqueue is busy looping by calling query timeout
handler and trying to acquire DNS context lock.
Reschedule query timeout handler with 10ms delay, so that all
threads, including those with lower priorities, have a chance to move
forward and release DNS context lock.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This library is coded with standard POSIX names for socket functions,
so make that requirement explicit.
Also, switch it from select'ing NET_SOCKETS, to depend'ing on it. This
follows the general approach of avoiding unneeded select's in Zephyr,
which lead to conflicting dependencies and make debugging dependencies
complex overall. In this particular case, it's fair (for a user) to
expect that "simple network time protocol" requires networking API,
namely sockets, and have that explicitly on in their app configuration,
giving better overview of their app config overall.
Fixes: #34165
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This aligns the error handling of send function to never unref the
buffer in place so the caller retain the ownership of the buffer
whenever there is an error.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
The virtual_iface is already NULL checked by net_if_get_by_iface()
at the beginning of the function so no need to do it here too.
Coverity-CID: 220535
Fixes#34006
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Simplifying the loop in order to remove dead code (ctx_up is
always NULL after the slist loop.
Coverity-CID: 220538
Fixes#34003
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Logging v2 is using _Generic keyword for detecting type of
log message arguments. Apparently, it does not support handling
of pointers to forward declared structures. Added casting to void *.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Made the LwM2M engine checks for pmin and pmax optional to adhere to
the LwM2M specificattion. We now first check that pmin and pmax are
actually set. Also changed the default CONFIG values for the attributes
pmin and pmax to 0 to indicate that they are not active by default.
Fixes#34329.
Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
If `CONFIG_NET_ICMPV4_ACCEPT_BROADCAST` is enabled ICMPv4 should reply
to request packets sent to the broadcast address of an interface with
the unicast address of that interface from the same subnet.
Previously the code blindly copied the ICMP source address which meant
it would reply to broadcast packets with a broadcast source address.
Signed-off-by: Arvin Farahmand <arvinf@ip-logix.com>
The `init_string` array could have been used uninitialized, fix this
by initializing it as an empty string, which is a desired content in
case it's not overwritten.
CID: 220302
Fixes#33839
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
First design towards ISO adaptation layer, this PR introduces
data-structures and framework for Rx unframed PDUs (BT RX ingress).
Two callbacks are defined for the SDU production (BT RX egress), one for
SDU allocation as well as a callback for emitting a reassembled SDU.
Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
Add numeric http status code to the response struct to allow for
easier processing by the caller. Textual status already exists.
Signed-off-by: Justin Morton <justin.morton@nordicsemi.no>
This commit puts the radio in sleep mode when the diagnostics are
stopped.
This fixes an assert on MAC code when `ot diag stop` command is
issued while `ot diag send` is still ongoing.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Replace all existing deprecated API with the recommended alternative.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Zephyr socket subsystem has come a long way since initial experimental
alternative to internal Zephyr networking API. Its configuration also
mirrors the usual conservative approach, where a user needs to
explicitly enable options to get "more" features. And as an
experimental API, socket subsystem was initially developed as
namespaced API, where all functions/structures are prefixed with
"zsock_", and to get standard names, CONFIG_NET_SOCKETS_POSIX_NAMES
needs to be set (or alternatively, CONFIG_POSIX_API needs to be, which
enabled full POSIX subsys overall).
However, a few years later, sockets are the standard networking API,
and in majority of cases its used under the standard POSIX names.
Necessity to explicitly set an option to achieve this effects, and
confusion which results from it - are just unneeded chores for users.
So, switch CONFIG_NET_SOCKETS_POSIX_NAMES to be on by default (unless
CONFIG_POSIX_API is already defined). It still can be explicitly
disabled if needed (but usecases for that would be peculiar and rare).
Addresses #34165
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Create net_l2_send() function which will be called by each L2
sending function so that we can catch all the network packets
that are being sent. Some L2 layers send things a bit differently,
so in those cases call the net_capture_send() directly by the L2
layer.
Add network packet capture call in receive side after the pkt has
been received by the RX queue handler. This avoids calling the
net_capture_send() from ISR context.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The "net mem" command did not print external net_pkt slabs
properly (the number of free net_pkt's was not printed).
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Show detailed information about network interface that is down,
only when user asks such information about one specific network
interface. This means that for "net iface" command only
"Interface is down." is printed but the command "net iface 1"
will print detailed information even if interface is down.
This helps to view the information and user does not need
to bring interface up to see the details.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add infrastructure to allow user to configure the system so that
all the network packets, that are sent to or received from a specific
network interface, are sent to remote system for analysis.
The captured network packets are placed as a payload in UDP packet,
which is then sent inside a tunnel to a remote host. The host can
then receive the packets and for example show them in wireshark.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add get/set helpers to store information whether the net_pkt
is captured already or not. This bit is used to detect capture
loop and avoid recursion.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Instead of forcing net_pkt_clone() use the tx_pkts slab, use
the same slab that was used when allocating the original net_pkt.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The IPIP tunnel capability bit helps to detect which network
interface supports IPIP tunneling.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Implement SO_BINDTODEVICE socket option which allows to bind an open
socket to a particular network interface. Once bound, the socket will
only send and receive packets through that interface.
For the TX path, simply avoid overwriting the interface pointer by
net_context_bind() in case it's already bound to an interface with an
option. For the RX path, drop the packet in case the connection handler
detects that the net_context associated with that connection is bound to
a different interface that the packet origin interface.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
An option has been added which can be passed to setsockopt
which allows the user to set & get the dtls handshake timeout,
either before first handshake or online.
Signed-off-by: Emil Lindqvist <emil@lindq.gr>
With these changes, dial up Zephyr application/driver can use
socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW) for creating
a socket for sending/receiving data to/from ppp net link, i.e.
packet is going to/from PPP L2.
Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
Introducing PPP dialup features to enable e.g. usage of nrf9160
based board as a dialup modem for transferring ip data over PPP
(e.g. windows dial up), i.e. usage of Zephyr PPP as a server for
providing MTU/MRU, IP address and DNS addresses for a PC:
- PPP LCP MRU option (configurable)
- PPP server: IPCP ip and dns address peer options to enable
providing IP and DNS addresses for PPP peer.
Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
The specification states that the server can cancel observations "at any
moment, by sendinga GET request with Observe option=1, the LwM2M Server
cancancel an “Observe”operation on a specified Resource, or specified
Object Instance(s)."
It does not mention any token matching requirement, but RFC 7641 does.
The correct interpretation is not obvious. The EMQx LwM2M implementation
uses a new token for instance, which does not work with Zephyrs token
matching cancel-observe.
This commit introduces cancel-observe via path matching as a Kconfig
option. This could hypothetically introduce problems when we are
connected to multiple peers simultaneously, but since that is not likely
to be supported for a long time (if ever), this change should be fairly
uncontroversial since path matching is only used as a fallback.
Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
Current implementation of poll prepare/update could end up busy looping
if `poll()` function was called before/during DTLS client handshake
(i. e. `poll()` called before an initial `send()`).
Fix this, by monitoring the handshake semaphore, already available in
the tls_context structure for DTLS client instead of underlying socket.
After the handshake is complete, switch to monitoring the underlying
socket instead.
For DTLS server this is not needed, since the handshake is initiated in
the `recv()` function, therefore any incoming data should trigger the
handshake.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
IPv6 source address selection procedure selected link-local address
for any muticast destination with other scope than mesh-local. It
was a cause of problems for broader multicast scopes like admin-, or
site-local. For such broader scopes source address must be at least
as broad as the scope of multicast destination.
This patch updates IPv6 source address selection procedure. Now
link-local address is selected only for link-local destinations,
including multicast destinations. For broader destination scope,
source address with broader scope is selected.
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
Previously, a non null-terminated "string" could
be passed to z_impl_net_addr_pton if the string was
exactly `INET6_ADDRSTRLEN` long.
Signed-off-by: James Harris <james.harris@intel.com>
All IPSO objects that utilized the non-standard timestamp extension now
implement their model in version 1.1, which contains the Timestamp
resource. As it's no longer needed to add timestamp in a non-standard
way, simply remove LWM2M_IPSO_TIMESTAMP_EXTENSIONS option.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Update IPSO Pressure Sensor object implementation to support object
model version 1.1.
Add missing optional resources for the object model version 1.0.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Some of the objects redefined reusable resources IDs, while others used
a common header which defines resource IDs. Unify the approach and use
the header in every object.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Each object now have to specify the object version it implements.
Based on this information the LwM2M engine can decide whether it's
needed to report the object version during Registration/Discovery
operations or not.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If the first network interface is down when the net config init
is run, then the IP addresses etc would be set to wrong network
interface. So when initializing the network, try to first find
a network interface that is auto started and use that to configure
IP addresses etc.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
When printing network interface information print index or
index + pointer, so that the output is more user friendly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
As DAD is not done for point-to-point links, we can mark them
valid immediately. If this is not done, then the address will
never be picked as a source address to a sent packet.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Useful to know what flags are set for the network interface
so print them in the shell by the "net iface" command.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This can be used to implement tunneling, VPN etc. The virtual
interfaces can be chained together to support multilayer
network interfaces.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add a function that allow caller to create IPv4 header with
possibility to set various fields in the header.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Application can disable IPv4 or IPv6 later if those are not
needed nor used for a given network interface.
Fixes#14581
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Move ptp_clock.h out of the top level include/ dir into
include/drivers/ptp_clock.h and deprecated the old location.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
net_eth_carrier_on() and net_eth_carrier_off() call k_work_init() on
work item that can be pending or still be processed in another thread.
This results in undefined behavior.
Initialize work item once and use an atomic flag to switch between
up/down carrier state. Submit work to workqueue whenever up/down carrier
state changes, so that last state is always properly propagated to
network interface layer.
While at it, save network interface pointer during ethernet context
initialization, so that is becomes static (and thread-safe) during whole
ethernet context lifetime.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
net_ppp_carrier_on() and net_ppp_carrier_off() call k_work_init() on
work item that can be pending or still be processed in another thread.
This results in undefined behavior.
Initialize work item once and use an atomic flag to switch between
up/down carrier state. Submit work to workqueue whenever up/down carrier
state changes, so that last state is always properly propagated to
network interface layer.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Remove legacy TCP stack as it is replaced by the new TCP2 stack.
The TCP2 stack has been the default stack since 2.4 release.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The payload of the Register/Register Update message is also formatted as
application/link-format. Therefore it's reasonable to reuse the new
content writer instead of filling the payload manually.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit adds a new content writer, application/link-format, which
can be used during the Discovery procedure, to fill the content of the
response payload.
Introducing this new content writer, which encapsulates some of the
details like attribute handling which is different for bootstrap/regular
discovery, allows to unify the discovery handler in the lwm2m_engine,
thus it's no longer needed to have spearate handler functions for
bootstrap/regular discovery.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
`.well-known/core` resource is described by the CoAP RFC as an optional
method of resource discovery. The LwM2M specification though makes no
mentionon about this mechanism and provides an alternative method of
resource discovery instead (Device Management Discover, sec 5.4.2, and
Bootstrap Discovery, sec 5.2.7.3).
Since LwM2M does not require to implement `.well-known/core` resource
and it complicates the existing Discovery mechanism (and likely cause a
security concern) remove its handling from the LwM2M implementation.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Introduce LwM2M engine helper functions that allows to work with LwM2M
attributes outside of lwm2m_engine.c.
This is a groundwork for application/lwm2m-format content writer.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When recvfrom() was called with src_addr != NULL, then source address
was fetched from beginning of net_pkt. This works with native IP stack
obviously. However with offloaded IP stack there is no IP header, so
trying to parse missing IP header results in undefined behavior.
Check if network interface has offloaded IP stack. If positive, then
figure out if there is assigned remote address to network context on
which packet was received. Return this remote address, which SHOULD be
the source address of received packet. Otherwise, return an error.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
When using `OPENTHREAD_ECDSA` deterministic variant has to be
enabled after some OpenThread changes. Also generic public key
functions are required.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Add locking when accessing interface list and the DHCPv4 config
struct that is found in net_if.
Fixes#33348
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Switch to the new API for delayed work related to DNS queries.
In the previous solution it was assumed that the work item could be
immediately cancelled at the point the query slot was released. This
is not true. We need a secondary condition to record the fact that
the query was completed while the work item was still pending, and an
additional check to detect when the work item completed and the slot
reclaimed.
Also annotate functions to indicate when they require the lock on
query content to be held, add some helpers that abstract core
operations like invoking a callback or releasing a query slot, and fix
some more cases where query slot content was accessed outside of the
new lock infrastructure.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
There was no close method implemented for AF_PACKET type
sockets. This meant that calling close() on packet socket
caused NULL pointer access.
This will allow #32949 issue to work properly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
OpenThread UART tx callback has been processed even if it was not
triggered by OpenThread otPlatUartSend function.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
Implement MSG_WAITALL flag for stream sockets. Setting this flag on
`recv()` call will make it wait until the requested amount of data is
received.
In case both, MSG_WAITALL all is set and SO_RCVTIMEO option configured
on a socket, follow the Linux behavior, i. e. when the requested amount
of data is not received until the timeout expires, return the data
received so far w/o an error.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If there is no timeout, the connect will timeout immediately
and the connection is not established.
Fixes#33185
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
DHCPv4 client code needs to know information when network
interfaces are going down and up. So make sure that network
management config options are enabled in that case.
Fixes#33137
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add option to disable validation callback support by setting the
validation buffer size to 0, which allows to save some memory in case
it's not needed.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add a data validation callback to the resource structure, which can be
registered by an application. It allows to verify the data before
actually modifying the resource data.
If the callback is registered for a resource, the data is decoded into a
temporary buffer first, and only copied into the actual resource buffer
if the validation is successfull. If no validation is required (and thus
no callback registered) the resource value is decoded directly into the
resource buffer, as it used to be.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Mention that it's "data offset" in 32-bit words. Helpful when doing
code review and using search for "th_off".
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
If CONFIG_NET_TCP_ISN_RFC6528 is disabled, then mbedtls include
files are not available so check this.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Verify the result of option encoding while forming Deregister message
instead of silently ignoring it.
Coverity ID: 215373
Fixes#33096
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Calculate Initial Sequence Number (ISN) as described in RFC 6528
https://tools.ietf.org/html/rfc6528
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The address pointer cannot be null at this point so remove
the checks.
Coverity-CID: 219595
Fixes#33071
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
check_interface resets the counter semaphore, but
net_config_init_by_iface first calls check_interface, then inits
the semaphore.
Initialize the semaphore up front to allow the k_sem_reset call
to work properly.
Signed-off-by: James Harris <james.harris@intel.com>
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".
Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.
In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.
These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.
Signed-off-by: James Harris <james.harris@intel.com>
Add NET_HEXDUMP_DBG/ERR/WARN/INFO macros, then use them for new
MQTT_HEXDUMP_TRC/ERR/WARN/INFO macros.
Log struct mqtt_utf8 using MQTT_HEXDUMP_TRC. One cannot safely log
mqtt_utf8 strings due to no guarantee of a NULL terminator being
present. Also, logging without log_strdup() as if it were a NULL
terminated string asserts when CONFIG_LOG_IMMEDIATE=n. This solves
both issues.
Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
Uses of k_work_pending are to be replaced by k_work_is_pending which
conforms to current proposed naming guidelines.
Switch to the new function.
Also initialize the private work structure at build time, rather than
on each iteration (it is not permitted to invoke work API on an
uninitialized work item).
The implementation here is racy: that a work item is pending does not
mean changes since it was first submitted are guaranteed to be seen
when the work item begins (began) executing.
A better solution would be to have transmit_message be able to
determine whether there is unprocessed work. Then the work item can
be submitted unconditionally.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Uses of k_work_pending are to be replaced by k_work_is_pending which
conforms to current proposed naming guidelines.
Both uses in this file are fragile: that a work item is pending does
not mean changes since it was first submitted are guaranteed to be
seen when the work item begins (began) executing.
As long as this module is expected to be replaced by tcp2 it doesn't
seem worth trying to fix the logic, so just switch to the new function
name.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Checking whether a work item is pending before submitting it is racy:
the item may be finishing up in its handler, and essentially
completed, in which case chosing not to resubmit would leave work
unhandled.
In this case it appears very wrong, since the sole call site in
net_if.c has just initialized the work item, which is not permitted if
the work item is pending.
Remove the check.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The compiler generates a warning regarding a variable being used
w/o being initialized in certian configuration. According to the logic
that's not the case, so just add some initial value to the variable to
silence the compiler.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As network interface array size might be larger than the actual
network interface count, check this condition and ignore those
interfaces that are not in use.
We cannot know for certain how many network interfaces there
are at built time, as the total count is only available at runtime.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The network interface index is very useful info to see in
debug prints so add those to debug output.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If we are sending a network packet and if the remote address
is not set in the context (which means that connect() has not
been called), then we must set the target network interface
to a proper value.
This is done so that when we select the local source address,
we might select the wrong interface if we have multiple network
interfaces in the system. In this case the packet would be always
assigned to first network interface regardless of the destination
address.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Now that the old API has been reimplemented with the new API remove
the old implementation and its tests.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The tcp2 infrastructure is using the legacy delayed work API, and
relies heavily on the transient state indicated by an estimate of
delayed time remaining to determine whether a delayed work item is
still active. While the wrappers for this work in most cases, one use
is unsanctioned: directly accessing the fields of k_delayed_work
structure to satisfy the calling parameters of the handler when
invoked directly.
The chosen solution for this specific need in the new API is to use a
schedule (rather than reschedule) operation, which leaves any previous
timer unchanged but allows immediate submission if the work is idle.
This changes behavior in that the resend is delegated to the work
queue, rather than done immediately. The former behavior can be
supported by further refactoring that turns the work handler into a
wrapper around a function that takes a connection reference, and
invoking that here, while the handler invokes it after reconstructing
the connection from the contained work item.
For now put in a hack that also uses the non-public fields of the
delayed work structure to implement the required behavior. The
complete fix if this solution is used requires replacing all use of
k_delayed_work in this module with k_work_delayable, leveraging the
new functionality of the API to avoid having to guess about the true
state of a work item based on its transient timer or flag states.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This lets an application detect when a PPP connection fails to establish
or terminates, so that the connection can be reattempted (for example,
by setting carrier off and on).
Signed-off-by: Jim Paris <jim@jim.sh>
In case the endpoint string provided by the application is longer or
equal to CLIENT_EP_LEN - 1, the strncpy() function will not add the NULL
terminator. As the endpoint buffer is treated as a C-string in other
places in the code, make sure it's NULL terminated by adding NULL
explicitly at the end of the buffer.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Make sure query string used by the lwm2m_rd_client is large enough to
encode any query string that can be sent during bootstrap/registration.
As the maximum query string length is related to the endpoint name,
which is limited by `CONFIG_LWM2M_RD_CLIENT_ENDPOINT_NAME_MAX_LENGTH`,
make the query string corellated to the value of this config.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit adds to network shell set of basic commands for UDP
protocol to receive and send datagrams.
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Check NULL value when we are trying to print link address
because the link address can be null.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
As the input string can be allocated from stack, we need to use
log_strdup() in net_pkt_hexdump() to print the extra string.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This returns the available contingous space in the packet starting from
the current cursor position.
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
Avoid splitting lines when possible while keeping length below 100
chars. Some other minor style corrections.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
The use of a single error variable for RX and TX operations has
shown the OpenThread code to be asserting in some conditions.
This commit splits tx_rx_result into rx_result and tx_result
to avoid such cases.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
If the network interface is down when trying to send a message,
return -ENETDOWN as we cannot send a message in this case.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit fixes some edge cases when using net_bufs with reserved
bytes (headroom) as fragments of a net_pkt.
Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
net_buf_max_len() provides the maximum number of bytes which can be put
behind the data pointer. This provides a save alternative to using the
size field of the net_buf structure directly, which does not take the
reserved bytes (headroom) into account.
This commit also replaces the usage of the size field in places where
size got used directly. Code has not been adjusted when it is easy to
recognise that the buffer does not have any reserved bytes, which is the
case after allocation or reset. Same goes for the faulty usage by
net_pkt as exposed by the last commit and begin fixed by a separate
commit.
Even though it would be cleaner, I decided to not rename the size field
to e.g. __buf_size in order to keep the amount of code changes low.
Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
Added 3 utility functions :
- lwm2m_engine_update_period_service() which updates the period of a
given service.
- lwm2m_engine_update_period_min_observer() which updates the
min_period_sec for a given observe node.
- lwm2m_engine_update_period_max_observer() which updates the
max_period_sec for a given observe node.
Signed-off-by: Thomas LE ROUX <thomas.leroux@smile.fr>
* Added implementations of otPlatCAlloc and otPlatFree methods
necessary for the OpenThread in case of using EXTERNAL_HEAP.
* Added CONFIG_OPENTHREAD_DNSSD_SERVER option to allow enabling
OT_DNSS_SERVER feature.
Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
If user sets CONFIG_NUM_PREEMPT_PRIORITIES=0, then the priority
of the net_mgmt thread will be -1 which is the same as idle thread.
This will trigger assert in kernel as then the minimum coop priority
is -2 in this case. Remove the net_mgmt thread priority setting from
Kconfig file as it is low value and set the coop thread priority
the same way as other network threads are doing it.
Fixes#32375
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This patch adds implementation of socket option used to get
protocol used for given socket (e.g. IPPROTO_TCP). This option
is not defined in POSIX, but it is Linux extension.
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
This patch adds implementation of socket option used to get
type of given socket (e.g. SOCK_STREAM).
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
Remove `OPENTHREAD_CONFIG_NCP_BUFFER_SIZE` define since it does not
exist in OpenThread.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
If userspace is enabled, then the TLS context needs to be
made a NET_SOCKET kernel object. Without this the userspace
cannot access TLS sockets.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
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>
Current 6lo implementation is unable to deal with scattered headers
(which should not happen usually, though it's a valid use case), so
let's just fail uncompressing such packet then.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Bogus fragmented packet could be sent without a FRAG1 fragment and hit
reassembly. Let's make sure this does not happen.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
In case the current packet is the same as the cached one, let's not
unreference it while clearing the cache.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Though ACK frames are not meant to reach L2 (drivers must ensure this
never happens), let's "re-enforce" the L2 by dropping them.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
All addressing mode but IEEE802154_ADDR_MODE_NONE should have a valid
address. If not, the frame is invalid.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
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>
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>
When pushing received data to the application, check that app
was able to receive the data. If the application already closed
the socket, then we must free the received net_pkt in order to
avoid memory leak.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If we cannot allocate net_pkt or net_buf, then check this condition
properly and release other resources that were already allocated.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We need to make sure that when listening a connection establishment,
the connection gets cleared if we do not receive final ACK.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
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>
After the latest upmerge, OpenThread requires explicit configuration
of the Master Key. This commit adds a Kconfig symbol that can be
used to setup its value. By default no Master Key is configured and
OpenThread generates a random one.
The Sockets Echo samples are configured with a fixed key with this
commit.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Only start the network logging backend if the autostarting
option CONFIG_LOG_BACKEND_NET_AUTOSTART is enabled.
Also, call init to make sure that the backend is initialized
properly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
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>
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>
This enables to use net_buf_append_bytes without passing an allocator in
which case the code would attempt to use the net_buf_pool of the
original buffer.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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>
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>
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>
Multi-instance resources shall report its dimension (number of
resource instances) on discovery. Since it was not possible to tell
simply on the instance count whether the resource is multi-instance or
not (there could be a multi-instance resource with only one instance
avaialble) add a new parameter to the structure representing resource,
indicating whether it's multi-instance or not.
Add dimension information to the discovery result.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Remove any references of Bootstrap Discovery from Device Management
Discovery procedure and fix some of it's logic following the
specification.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Bootstrap discovery was not implemented properly in the LwM2M engine.
Although, there were some indications in the source code that it is
implemented, it was not done according to spec (and actually broken).
Given that Bootstrap Discovery procedure differs a lot from the regular
Device Management Discovery (different permissions, different
information returned), it's easier to implement it as a separate
function (`bootstrap_discovery()`) instead of making the existing
`do_discovery_op()` function even more complicated.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit improves portability somewhat on machines where sizeof
(int) is less than sizeof (void *). Note that the implementation is
still not portable and will fail when you start using addresses which
can not be represented by "int cast to unsigned int".
On RISC-V 64-bit with RAM on 0x80000000 we previously got hit by
E: Exception cause Load access fault (5)
ld s0,16(a0)
a0: 0xffffffff80025610
(The int should probably be changed to intptr_t if possible.)
Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
This patch brings support for AF_PACKET and SOCK_RAW type of sockets.
In net_conn_input() function the new flag has been introduced -
'raw_pkt_continue' to indicate if there are other than AF_PACKET
connections registered.
If we do not have other connections than AF_PACKET, the packet is
solely handled in net_conn_input() (or to be more specific in its
helper function - conn_raw_socket()).
Otherwise, it is passed back to net_conn_input in IPv4/6 processing.
Signed-off-by: Lukasz Majewski <lukma@denx.de>
The new function - namely conn_raw_socket(); has been introduced to
handle raw sockets processing. Its code, up till now, only was
executed when IS_ENABLED(CONFIG_NET_SOCKETS_PACKET) was defined.
After this change it can be reused when one would like to handle
raw sockets also when CONFIG_NET_{UDP|TCP} are enabled.
Signed-off-by: Lukasz Majewski <lukma@denx.de>
Add a check to stop a multicast address to be registered multiple times.
This can happen if the application is using net_if_ipv6_maddr_add()
directly.
Tested on the existing bluetooth/ipsp sample:
<wrn> net_if: Multicast address ff02::1 is is already registered.
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
6lowpan over BLE should work without solicit node multicast messages
according to RFC7668[1], but that requires Neighbor Solicitation with
Address Registration Option, which is currently not implemented in
either Zephyr or Linux. This is causing the router to fallback to normal
neighbor solicitation based discovery, but the NS frames are being
discarded in the host stack because the solicit node multicast groups
are not registered.
This drops the NET_L2_MULTICAST_SKIP_JOIN_SOLICIT_NODE as a workaround
and adds a TODO about it.
[1] https://tools.ietf.org/html/rfc7668#section-3.2.3
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
Add Kconfig option NET_HOSTNAME_UNIQUE_UPDATE to allow the unique
hostname - which is derived from the network interface's link
address - to be updated on both initial assignment and updates of
the link address.
Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
`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>
The #if statement used IS_ENABLED to check if it was defined.
IS_ENABLED will only return true if the value is 1, and false otherwise.
If the NET_TCP_MAX_SEND_WINDOW_SIZE value would be e.g. 8, then the
check would fail.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
If we receive data that is out-of-order, queue sequential
TCP segments until we have received earlier segment or a timeout
happens.
Note that we only queue data sequentially in current version i.e.,
there should be no holes in the queue. For example, if we receive
SEQs 5,4,3,6 and are waiting SEQ 2, the data in segments 3,4,5,6 is
queued (in this order), and then given to application when we receive
SEQ 2. But if we receive SEQs 5,4,3,7 then the SEQ 7 is discarded
because the list would not be sequential as number 6 is be missing.
Fixes#30364
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Modifies openthread shim layer to automatically join multicast
addresses as they are added to zephyr from openthread, unless the
address is interface-local or link-local. This allows incoming
openthread multicast group messages to avoid being filtered by
zephyr ipv6 recv.
Fixes#31085
Signed-off-by: Joel Frazier <frazieje@gmail.com>
The LwM2M firmware pull object no longer uses the system workqueue
to execute firmware_transfer(), but directly executes it itself.
Previously, the workqueue would be blocked because firmware_transfer()
indirectly calls a blocking connect(). This would lead to problems
with e.g. modem drivers that use UART to interface with the modem
hardware, as some UART drivers use the workqueue.
Fixes#31053.
Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
As the tcp header struct can be cast to unaligned memory, mark
it as packed and access fields using UNALIGNED_GET/PUT when
needed.
Fixes#31145
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Both RS and DAD timeouts are simplified because the delay is a
constant, and by construction the list of timeouts is in increasing
time remaining.
Refactor to avoid repeating the expression that represents the time
until DAD state expires. Uniformly use unsigned operands in deadline
calculation.
Note a case where the racy idiom for retaining an existing timeout is
required in the current work API, but can be replaced with a robust
solution in the proposed new API (the reschedule API replaces any
existing pending update, but the schedule API will leave an existing
scheduled submission in place).
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The existing implementation is inconsistent in that checking for
expired routers when a timeout is processed detects end-of-life
correctly (when the remaining duration exceeds the signed maximum),
but the calculation of time remaining before expiration uses only
unsigned calculation. So when the set of routers is changed the newly
calculated timeout will not recognize routers that have expired, and
so those routers expired late. In the worst case if the only
remaining router had expired the timer may be set for almost two
months in the future.
Refactor to calculate remaining time in one place and as a signed
value. Change a function name to more clearly reflect what it does.
Avoid unnecessary race conditions in k_work API.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The net_timeout structure is documented to exist because of behavior
that is no longer true, i.e. that `k_delayed_work_submit()` supports
only delays up to INT32_MAX milliseconds. Nonetheless, use of 32-bit
timestamps within the work handlers mean the restriction is still
present.
This infrastructure is currently used for two timers with long
durations:
* address for IPv6 addresses
* prefix for IPv6 prefixes
The handling of rollover was subtly different between these: address
wraps reset the start time while prefix wraps did not.
The calculation of remaining time in ipv6_nbr was incorrect when the
original requested time in seconds was a multiple of
NET_TIMEOUT_MAX_VALUE: the remainder value would be zero while the
wrap counter was positive, causing the calculation to indicate no time
remained.
The maximum value was set to allow a 100 ms latency between elapse of
the deadline and assessment of a given timer, but detection of
rollover assumed that the captured time in the work handler was
precisely the expected deadline, which is unlikely to be true. Use of
the shared system work queue also risks observed latency exceeding 100
ms. These calculations could produce delays to next event that
exceeded the maximum delay, which introduced special cases.
Refactor so all operations that use this structure are encapsulated
into API that is documented and has a full-coverage unit test. Switch
to the standard mechanism of detecting completed deadlines by
calculating the signed difference between the deadline and the current
time, which eliminates some special cases.
Uniformly rely on the scanning the set of timers to determine the next
deadline, rather than assuming that the most recent update is always
next.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Adds a new family of `struct net_buf` operations that remove data from
the end of the buffer.
The semantics of `net_buf_remove_mem` have been chosen to match those of
`net_buf_pull_mem`, i.e. the return value is a pointer to the memory
that was removed.
The opposite of this function, `net_buf_remove`, would need to return
the old end of the data buffer to be useful. However this value is
always an invalid target for reading or writing data to (It points to
the middle of unused data).The existance of the function would be
misleading, therefore it is not implemented.
Fixes#31069.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
If there are multiple interfaces a change to the timeout for one
cannot determine the correct delay until the next timeout event. That
can be determined only by checking for the next event over all
interfaces, which is exactly what's done by the timeout worker.
Refactor interface timeout configuration to just set the start time
and request time, and trigger the worker to calculate the next
scheduled event.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
When a renewal occurs the client enters RENEWING, sends a request,
then sets a short timeout (about 4 s) for the response. In the common
case the response will arrive immediately, which will trigger an
attempt to reset the timer with T1 which is generally large.
However the check for updating the timer performs the update only if
the new deadline is closer than the currently set one. Thus the timer
fires at the time the RENEWING request would have been retransmitted,
and only then updates to the correct deadline (T1) for the current
machine state.
Remove the extra timeout by unconditionally setting the timeout to the
new value.
This works when there is one interface; it could be wrong if there
were multiple interfaces one of which had a closer deadline, but
multiple interfaces are mishandled anyway and will be fixed next.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
When there is only a single interface the timeout infrastructure can
correctly calculate time to next event, because timeouts only occur
when an event for that interface is due. This is not the case when
multiple interfaces are present: the timeout is scheduled for the next
event calculated over all interfaces.
When calculating the next event for an interface where the timeout is
not due the current code returns the original absolute delay
associated with its current state, without accounting for the time
that has passed since the start time.
For example if interface A's T1 is 3600 s and is due at 3610, but at
3605 a timeout for interface B occurs, the contribution of A to the
delay to the next scheduled event would be 3600 rather than 5,
preventing the renewal from occurring at the scheduled time.
Fix this by replacing the boolean timed-out state with the number of
seconds remaining until the interface event will occur, and
propagating that through the system so the correct delay over all
interfaces can be maintained.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
If send_request() fails it would return UINT32_MAX as the next
timeout. Callers pass the returned value to update_timeout_work
without validating it. This has worked only because
update_timeout_work will not set a timeout if an existing timeout
would fire earlier, and the way the state is currently structured it
is likely there will be an existing timeout. However, if work thread
retransmission from REQUESTING failed the timer would not be
rescheduled, causing the state machine to stop.
A more clean solution, which matches the behavior of send_discover(),
is to return the timeout for the next transmission even in the case
when the send fails. The observed behavior is the same as if the
network, rather than the sender, failed to transport the request.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
A variable named "timeout" is used to represent the current time in
comparisons against timeouts calculated from a start time and an
interval. Since this current time is not the timeout change its name
to "now" to reduce maintainer confusion.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
If assertions are disabled the send operation would continue on to
transmit a message. Stop it from doing so.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The flag value UINT32_MAX is returned from manage_timers() when a send
operation did not succeed. This indicates that the timeout should not
be rescheduled, but because it will never replace the starting update
value UINT32_MAX-1 the check will never pass, and in cases where it
should work will be submitted to run at UINT32_MAX-1 seconds.
Fix the upper bound.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
When a connection is lost the client will first attempt to renew, and
then to rebind, and finally to select. Options like gateway may have
been provided by the original connection, but not the new connection,
resulting in an inconsistent configuration for the new network.
Remove the partial state clearing when entering INIT, and expand the
state cleared when entering SELECTING to be more comprehensive.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The start time is negative only if the interface came up in the the
first milliscond since startup; even then changing the sign of the
start is not appropriate. Presumably a left-over from signed 32-bit
timestamps.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
It is documented that using transient information like whether a work
item is pending or a delayed work item has time left to determine the
state of the work item before subsequent reconfiguration is prone to
race conditions, and known to produce unexpected behavior in the
presence of preemptive threads, SMP, or use of the work item from
interrupts. As a best practice such pre-validation steps should be
avoided unless algorithmically necessary.
All comparisons of remaining delayed time before canceling a delayed
work item in this module appear to be optimizations subject to the
above race conditions. Remove the checks so that only the inherent
race conditions in the implementation of canceling a work item remain.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
With this patch the resolver module can resolve literal IPv6
and IPv4 addresses even when DNS client is not presnet in
the system.
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
Convert drivers to DEVICE_DEFINE instead of DEVICE_AND_API_INIT
so we can deprecate DEVICE_AND_API_INIT in the future.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit replaces the 'select SHELL' statement with
'depends on SHELL' in OPENTHREAD_SHELL config option.
This ensures, that shell will not be implicitly enabled
when OpenThread stack is built.
Signed-off-by: Rafał Kuźnia <rafal.kuznia@nordicsemi.no>
During recent upmerge OPENTHREAD_CONFIG_PLAT_LOG_FUNCTION__COUNT_ARGS
macro was renamed to OPENTHREAD_CONFIG_PLAT_LOG_MACRO_NAME__COUNT_ARGS
but the code wasn't updated where the macro is actually used.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Reordering of the struct elements to match the Linux format.
The __packed() is not necessary anymore.
std_id and ext_id is merged to id in the frame and filter.
Additionally, the frames are ready for CAN-FD.
Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
If getaddrinfo() was called with AI_PASSIVE flag in hints,
returned address defaulted to SOCK_STREAM and IPPROTO_TCP.
Fixed so that SOCK_DGRAM leads to correct address type
that can be fed to bind() directly.
Same hard coding was visible when numerical IPv4 address string
was converted to binary. That is also fixed to respect hints now.
Also, added functionality to get IPv6 address, when hints contained
AF_INET6.
Fixes#30686
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
When needing to lock non-connection related access, use k_mutex
instead of locking irq. There is really no reason to prevent the
system from generating interrupts.
Fixes#30636
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
A dedicated LwM2M execute callback type has been implemented which
supports execute arguments. The lwm2m engine, lwm2m_client sample and
lwm2m objects have been updated accordingly. Also the API change has
been documented, and the lwm2m engine reference has been updated.
Fixes#30551.
Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
Add option to enable software CSMA backoff in the OpenThread MAC layer.
This allows to run CSMA procedure correctly in radios that do not
support hardware CSMA backoff, and use them as RCP, where this feature
is required.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit adds a missing otPlatSettingsDeinit function
to the Zephyr OpenThread platform implementation.
Signed-off-by: Rafał Kuźnia <rafal.kuznia@nordicsemi.no>
- Remove SYS_ prefix
- shorten POWER_MANAGEMENT to just PM
- DEVICE_POWER_MANAGEMENT -> PM_DEVICE
and use PM_ as the prefix for all PM related Kconfigs
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Previously, lwm2m_engine set would check against the max_data_len
parameter of the ressource, but didn't take into consideration the
(possibly changed) max_data_len returned by the pre_write callback.
Fixes#30541
Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
In mqtt_keepalive_time_left(), return -1 if keep alive messages are
disabled by setting CONFIG_MQTT_KEEPALIVE=0.
This allows to use mqtt_keepalive_time_left() directly as an input
for poll(). If no keep-alive is expected, -1 would indicate
that poll() can block until new data is available on the socket.
Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
Use the core k_heap API pervasively within our tree instead of the
z_mem_pool wrapper that provided compatibility with the older mempool
implementation.
Almost all of this is straightforward swapping of one alloc/free call
for another. In a few cases where code was holding onto an old-style
"mem_block" a local compatibility struct with a single field has been
swapped in to keep the invasiveness of the changes down.
Note that not all the relevant changes in this patch have in-tree test
coverage, though I validated that it all builds.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Mark all k_mem_pool APIs deprecated for future code. Remaining
internal usage now uses equivalent "z_mem_pool" symbols instead.
Fixes#24358
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
The message should only be returned if the requested pending/reply
pointer is not NULL. Otherwise it could get an incorrect match (for
instance if specific pending pointer is searched for and reply is NULL
the function could return any message that doesn't expect a reply (and
thus has its reply pointer set to NULL).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
LwM2M engine by default sends piggybacked responses for requests after
all callbacks are executed. This approach however isn't good enough if
the application callback executes some lenghty operations (for instance
during FW update). Delaying the ACK may result in unnecessary
retransmissions.
This commits adds an API function which allows to send an early empty
ACK from the application callback. This prevents further retransmissions
from the server side. After all callbacks are executed, the LwM2M engine
will send the response as a separate CON message.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Verify if block tranfer is used and not an initial block when skipping
directly to data processing during FW update in PUSH mode.
This fixes a bug, which caused TLV not to be processed when the FW
object was updated as a whole, and actual resource number was encoded in
a TLV (for instance when writing FW Update URI).
Fixes#30135
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Rework the bootstrap DELETE operation, to support deletion of multiple
resources.
Current implementation had several oversimplifications, making it not
spec-compliant:
* DELETE `/` removed only Security object instances (!= 0)
* DELETE `/x` was handled as DELETE `/x/0`, therefore not removing all
of the object instances.
Since the above is only supported during bootstrap and not regular
Device management, this functionality was implemented in the
`bootstrap_delete` function, which now will be called for all DELETE
operations initiated during bootstrap. The regular LwM2M DELETE handler
will only be called during regular Device management, as it has more
strict limitations on what can be deleted.
Additionally, handle empty URI Path option as `/`, therefore indicating
deletion of all resources.
Fixes#29964
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
We did not check that user has supplied network interface index
in "net stats iface <idx>" command.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Debug messages used the address of a member of the work_q structure as
an identifier; that field is not public API, so replace it with the
address of the work queue itself.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Set the RX/TX thread priorities so that if cooperative priorities
are used, then lowest priority thread will have priority -1 which
is the lowest cooperative priority. The higest net thread priority
will depend on number of traffic classes but with max value 8,
the highest priority will be -8.
If preemptive priorities are used, then highest priority thread
will have priority 0, which is the highest preemptive priority.
In this case, the lowest thread priority will be 7 if there are
8 traffic classes.
The motivation for this change is that for cooperative priorities
we want to let other cooperative priority threads to run before
networking. But if preemptive priorities are used, we want
networking threads to run reasonably often compared to other
preemptive priority threads.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If networking pre-emptive thread priorities are enabled,
then use the proper macro to enable them.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Let user to decide whether the RX/TX threads are run in either
co-operative or pre-emptive thread priority.
Default is co-operative threading.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Because unoconnected stream socket doesn't have any chance to receive
any data, so a blocking recv() would hang forever on it (and does
without this change).
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
* Add RCP library.
* Conditionally remove non required libraries not required for RCP.
* Drop :option: marker for CONFIG_OPENTHREAD_NCP_SPINEL_ON_UART_ACM
Signed-off-by: Markus Becker <markus.becker@tridonic.com>
subpress warnings from llvm:
warning: absolute value function 'abs' given an argument of type
'int64_t' (aka 'long long') but has parameter of type 'int' which may
cause truncation of value [-Wabsolute-value]
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Add a macro in public header that represents maximum hostname string
length without terminating NULL character. This will allow other
modules, such as offloaded network drivers, to know how much space is
needed to allocate in order to fit whole hostname.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
A cast made assumption on how data is stored.
This commit makes the following test pass on qemu_leon3:
- net.udp
Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
A cast made assumption on how data is stored.
This commit makes the following test pass on qemu_leon3:
- net.ipv6.fragment
Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
Following errors occuring after enabling debug logs:
log: argument 2 in source net_hostname log message "%s: (%s): \
Hostname set to %s" missinglog_strdup().
log: argument 2 in source net_hostname log message "%s: (%s): \
New hostname %s" missinglog_strdup().
Fix that by printing CONFIG_NET_HOSTNAME directly in the first case and
using log_strdup() in the second.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
If user has enabled TCP debugging, print detailed internal TCP2
information too when user gives "net conn" command. This is useful
to have when debugging.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Comment out TCP1 specific stuff when TCP2 is enabled. This means
shuffling the code around a bit so that common code is placed at
the end. Introduce also net_tcp_foreach() function to TCP2 so that
it can be used from net-shell.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The data length is already calculated in tcp_in() so no need
to do it again in tcp_data_get(). Just pass the length to the
tcp_data_get() function.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This change enables support for DNS service discovery
(RFC 6763) in the mdns_responder service and sample app.
Fixes#29429
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This change adds support for DNS Service Discovery (DNS-SD)
as described in RFC 6763.
Fixes#29099
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This change adds net_context_port_in_use(), which is a simple
wrapper around net_context_check_port() and is used to check
if a particular socket is bound to a given IP address.
Fixes#29649
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
Do not send the original pkt in 6lo based networks as in those
the IPv6 header is mangled and we would not be able to do any
resends of the original pkt. So for 6lo networks, clone the
pkt and send it to peer. The original pkt is kept in sent list
in case we need to resend to peer.
Fixes#29771
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Track the number of dropped TCP data segments and number of dropped
TCP packets in network statistics. It is useful to see these
numbers separately.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add a simple backoff mechanism between consecutive registration attempts
in case of registration failures. Finally, notify the application in
case the registration failed several times.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Refactor the boostrap regstration procedure, by splitting the message
creation and sending into a separate function, in similar manner as
it's done with regular registration.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Currently, when socket errors occur during receive, the LwM2M engine
restarts the state machine and registers again to the server. While this
works in simple use case (only RD client socket open), it's not a valid
approach when more sockets are open (FW update socket).
Fix this by introducing socket fault callback, which is registered by
the LwM2M engine users. This way, a proper socket owner is notified on
error and can pertake appropriate action.
For RD socket errors the behaviour remains the same - the state machine
is reset and the client registers again to the server. For FW update
socket, handle the error by reopening the socket and retransmitting the
last request. This allows to resume the download from the point the
error occured, w/o a need to start from scratch.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Call mbedtls_ssl_conf_max_frag_len() on created TLS context
configuration, so that Maximum Fragment Length (MFL) will be sent to
peer using RFC 6066 max_fragment_length extension. MFL value is
automatically chosen based on MBEDTLS_SSL_OUT_CONTENT_LEN and
MBEDTLS_SSL_IN_CONTENT_LEN mbed TLS macros.
This extension is mostly useful for TLS client side to tell TLS server
what is the maximum supported receive record length.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit corrects the maximum allowed amount of children to
match Thread specification.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
If the peer ACKs data when it closes the connection, update
our sequence number accordinly. The connection would eventually
be terminated but this will avoid extra resends by the peer.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
When a connection is being closed, it is possible that the application
will have a lock to net_context and TCP2 connection lock. If we then
receive a final TCP2 ACK and close the connection, the locking order
get switched and TCP2 will first try to get its own lock and then the
net_context lock. This will lead to deadlock as the locking ordering
is now mixed.
The solution is to unref the TCP connection after releasing the
connection lock. The TCP connection unref function will anyway get the
lock so no need to do double locking.
Fixes#29444
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If there are enough tls_context objects in the system (configured by
CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS), but there are not enough file
descriptors (configured by CONFIG_POSIX_MAX_FDS) to create underneath
TCP/UDP socket, then TLS socket creation fails with leaked tls_context.
Call tls_release() in ztls_socket() error path whenever underneath
TCP/UDP socket creation fails.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
According to LwM2M specfication v1.0.2, par. 5.3.2, the LwM2M client
MUST send an “Update” operation to the LwM2M Server whenever the
lifetime parameter of the Server object changes the server). The same
applies for the object instances created/deleted. The changes in objects
seem to already be handled, but the lifetime was not.
Additionally, the "Update" message shall only contain these parameters
which changed since the last update (including objects). As it's
straightforward to determine if the liftime changed but it's not easy
to tell if there were updates in the object instances, add an
additional parameter to the engine_trigger_update() function, indicating
that new object information shall be sent in the "Update" message.
Eventually add a proper error checking in `sm_send_registration` as the
function is reworked anyway.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The memset on firmware_ctx during PULL FW update initialization will
set the socket descriptor to a valid value of 0. This leads to an error
if parsing of the URI provided by the server fails, and the firware_ctx
is closed - the socket with a descriptor 0 will be accidently closed.
Fix this by invalidating the socket FD after the memset on
initialization.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
It shouldn't be optional to handle separate response, as it's a
mandatory requirement according to the RFC7252:
"The protocol leaves the decision whether to
piggyback a response or not (i.e., send a separate response) to
the server. The client MUST be prepared to receive either."
Therefore, remove the flag as separate responses are handled now
properly.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Separate response handling implemented in the engine was faulty. The
separate response was not acknowledged by the client, resulting in
spurious retransmissions from the server side.
Also, the pending CON message was retransmitted by the client even after
it was acknowledged by an empty ACK, but the respnse haven't arrived
yet. Fix this by adding a new `acknowledged` flag to the `lwm2m_message`
structure. Once acknowledged, the flag is set and the confirmable
message is no longer retransmitted. We keep the message on the pending
list in order to timeout properly in case separate response does not
arrive in time.
Finally, prevent the reply callback from being called twice in case
the response is transmitted separately from ACk. The callback should
only be called on the actual reply, not the empty ACK.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
So far this function existed as a static function in LwM2M PULL FOTA
module. Since such functionality will be needed in other places, make it
an internal API function.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
using CONFIG_NET_BUF_POOL_USAGE monitor avail_count,
this variable should be protect.
Protecting it by using atomic variable
Signed-off-by: Ehud Naim <ehudn@marvell.com>
Some LWM2M backends/servers, such as emxq, expect the sequence numbers
to begin on 0.
This change is in line with how other lwm2m clients, such as Anjay and
Wakama, starts the notification sequence.
Signed-off-by: Viktor Sjölind <viktor.sjolind@endian.se>
The commit 93e5181f ("net: context: Add locking for concurrent
access") added net_context locking to only IPv4 sockets.
That is not enough and we need locking also to other supported
socket address families like IPv6, SocketCAN and packet socket.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Prior to this commit, the LwM2M stack would TLV-encode integers
depending on their internal storage size. An integer with value 5 stored
in an int8_t would be encoded with length 1, but an integer stored in an
int32_t would be encoded as "00 00 00 05" with length 4.
This commit checks if the value is castable to a smaller int and encodes
it as such if so. This is cascading, so even a 64 bit integer with value
5 will be encoded with length 1.
Note that this does not seem to be required by the specification, but
this is how Anjay and the other LwM2M stack seem to do it.
Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
When we are sending ICMPv6 error message, we need to store the
link local addresses of the received packet somewhere in order
to know where to send the new error message.
Easiest is to store the ll addresses is to the error message
itself, just before where the sent packet will start in memory.
We cannot use the original pkt to store the ll addresses
as that packet might get overwritten if we receive lot of packets.
Fixes#29398
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Currently, there is a case for net_config_init function that for
timeout==0 and when iface is already up, the ip setup is not proceed
and the error message "Timeout while waiting network..." is logged.
This commit fixes it.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
Adds the socket option TLS_ALPN_LIST for SOL_TLS sockets
Passes the configured alpn list to the mbedtls config
on mbedtls init
Signed-off-by: Emil Hammarstrom <emil.hammarstrom@assaabloy.com>
If we are sending data directly, we already have TCP lock so
there is no need to do any locking. But when data is re-sent,
the work queue handler is doing the sending so we need to lock
the TCP connection.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
When receiving data that needs to be passed the data to application,
queue it for short time so that we do not have TCP connection lock
held. This way if the application wants to send data, there is no
possibility that the connection lock would prevent sending data.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Release the context lock before passing data to the application
socket as that might cause deadlock if the application is run
before the RX thread and it starts to send data and if the RX
thread is never able to run (because of priorities etc).
Fixes#29347
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
These defines are leftover of old platform settings implementation
and are not used any more.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
net_icmp4_input() may net_pkt_unref() a packet. The header mustn't be
accessed after this or the system may crash.
Signed-off-by: Oliver Hitz <oliver@net-track.ch>
Existing openthread_api_mutex_lock()/unlock() functions are
crucial to assure thread safety of an application which
needs to use OT API directly, but some applications may also
require a non-blocking version of the former for less critical
OT-related tasks.
Add openthread_api_mutex_try_lock() which never waits and
exits immediately if the mutex is held by another thread.
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
If there are more than one RX or TX threads, then make the name
of each of them unique so that it is easier to figure them out
in "kernel stacks" command.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The name of the connection manager thread (conn_mgr_thread) was
unnecessarily long in "kernel stacks" command. So make the name
to "conn_mgr" which fits nicely to the output of that command.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If an address was obtained by IPCP, it should always be removed in
ipcp_down(). This commit replaces the predicate with something slightly
more robust.
Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
Windows 10 sends ECN-Echo and Congestion Window Reduced (CWR) flags
together with SYN flag in the connection establishment but the code
did not ignore these flags and send just SYN back (instead of SYN|ACK).
This caused the connection establishement in application level to
fail as the application was never notified about it.
Fixes#29258
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit moves IPv6 initialization from OT init to OT start to
avoid unwantedly bringing 802.15.4 radio up.
Previously, even when OT manual start was enabled, the radio would
be receiving frames resulting in unnecessary power consumption and
causing issues for instance when the device just wants to use
Bluetooth for provisioning befor moving to Thread.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Another team reported that current default values for number of allowed
IP addresses per child (4) and and max number of children (10) are too
small for some customers.
Increased the values allowed configuring child count.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
OpenThread mac counters require rx failed notification to work properly.
Made use of previously implemented notification.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
Clip the timeout to 64 seconds, this avoids the timeout value to
increase to high values (e.g. several years).
Signed-off-by: Armand Ciejak <armand@riedonetworks.com>
This avoids code duplication. The same logic was present
in dhcpv4_send_request() and dhcpv4_send_discover().
Signed-off-by: Armand Ciejak <armand@riedonetworks.com>
The TCP2 was calling accept callback before actually finalizing
the connection attempt.
Fixes#29164
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
A normal websocket close sequence:
close(websock) ->
websocket_close_vmeth() ->
websocket_disconnect()
close(ctx->sock) called in the function websocket_disconnect()
and cause websocket_close_vmeth() called again.
Finally stack overflow by loop close call.
It's maybe a side-effect by PR #27485
Signed-off-by: Jackie Ja <qazq.jackie@gmail.com>
Improve token handling by removing special meaning of tokenlen == 0,
which allows to handle server requests w/o a token (so far such
requests would cause the lwm2m engine to autogenerate token in the
response).
In order to autogenerate token during message initialization, use
special symbol `LWM2M_MSG_TOKEN_GENERATE_NEW`. If no token is wished to
be used, simply set the tokenlen to 0.
Additionally, fix an issue with token autogeneration, where invalid
token len was used (0 instead of 8).
Fixes#28299
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
LwM2M engine did not set response code for the Bootstrap-finish message,
hence it replied with the code copied from the request which is not
correct. Fix this by setting correct code for the Bootstrap-finish
reply.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
So far, `LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE` event was
reported before the final ACK for the Bootstrap Finish was sent from the
client side. This could cause delays in the ACK sending, in case the
application wanted for instance to store the received data in flash.
Fix this, by reporting the
`LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE` event on the next
state tansition (before the actual registration starts).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
"Public Key or Identity" resource is of opaque data type, therefore it's
not correct to assume it will be a NULL terminated string (the existing
servers, for instance Leshan, does not include NULL terminator). Use the
actual size associated with the resource instead.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
So far, the resource instance structure kept only the information about
the buffer length provided to the resource (in the `data_len` field).
While this approach might be enough for integer resources, where the
actual data size is fixed, it did not work for opaque resources. It is
impossible to determine the actual opaque resource length after it's
been written into.
Fix this, by replacing the current `data_len` field of the
`lwm2m_engine_res_inst` with `max_data_len`, indicating the buffer
size, and making the `data_len` field to hold the actual data size of
the resource.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Currently, after `CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP` is enabled,
the LwM2M engine will initiate bootstrap procedure on each run. This
approach limits the flexibility of the application, as it's not always
necessary to go over the bootstrap procedure (for instance, the
application may decide to store the security object obtained during the
bootstrap in flash, and restore it on boot).
Fix this by introducing an additional `flags` parameter to the
`lwm2m_rd_client_start()` function, which provides information whether
to run bootstrap in the current session or not.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
So far, the LwM2M state machine started in the `ENGINE_INIT` state,
which made it exectue the registration/bootstrap registration even when
`lwm2m_rd_client_start()` was not called. With a new `ENGINE_IDLE`
state, the state machine can wait for the application to actually start
the client before proceeding. It also makes sense to stay in the
ENGINE_IDLE state after successfull deregistration, until the
application restarts the client.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Without removing the stale address obtained during IPCP, it will still
be present the next time we do IPCP, marked as "in use" by the network
stack even if it is stale. This turned out to be a showstopper for
restarting the PPP stack on devices without static IP.
Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
This commit fixes PUSH FOTA when opaque content-format is used.
This consists of the following fixes:
* Moved `struct block_context` to a private header, so that it can be a
part of `struct lwm2m_input_context`. This allows content decoders to
make use of the block context data.
* Removed faulty `get_length_left` function from the plain text
decoder, and replace it with coap_packet_get_payload() to obtain the
actual payload size.
* Introduce `struct lwm2m_opaque_context` as a part of block context,
which allows to keep track of opaque data download progress.
* Simplify `lwm2m_write_handler_opaque()` function. It will now only
make calls to `engine_get_opaque` - it's the decoder responsibility
to update the opaque context according to it's content format (for
instance TLV decoder should only update it with the actual opaque
data size, not the whole TLV).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The L4 connected/disconnected events are usually used to detect
when the application is connected to the network. Unfortunately
if the device has also a static address, then the connected event
might be created (for the static address) even if DHCPv4 is not
ready yet and application would not be able to connect (yet) to the
network. In order to allow the application to fine tune the network
connection creation, generate start, bound and stop events for DHCPv4.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The "tc" field which was holding the traffic class thread
priority is not used nor needed so remove it from the struct
to save some space.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Replace all calls to the assert macro that comes from libc by calls to
__ASSERT_NO_MSG(). This is usefull as the former might be different
depending on the libc used and the later can be customized to reduce
flash footprint.
Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
Using zephyr's internals zsock_ calls make mqtt library more compatible,
now it does not depend on NET_SOCKETS_POSIX_NAMES.
Signed-off-by: Jan Pohanka <xhpohanka@gmail.com>
No real need to assert when the send timer is cancelled. Just
check if there is re-transmission going on and do nothing if
there is not.
Fixes#28758
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The local and accepted socket was not bound which caused the
local address to be set as NULL. This then caused issues when
zsock_getsockname() was called by the application.
Fixes#28735
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Since the info parameter is only read from and never written the const
in the function parameter should be present.
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
This commit adds additional Kconfigs that allow for changing
configuration values for the Zephyr port in OpenThread.
Those values are:
- number of the internal OT message buffers
- number of the state change callbacks
- number of the EID-to-RLOC cache entries
- size of the NCP buffer
Signed-off-by: Rafał Kuźnia <rafal.kuznia@nordicsemi.no>
Instead of directly checking the multicast IPv4 address, use
the net_ipv4_is_addr_mcast() utility function.
Fixes#26584
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
MQTT client state is protected using mutex. That mutex however is
temporarily unlocked when calling event callbacks. This means that in
client_disconnect() transport can already be disconnected, but without
marking it as such in client->internal.state.
When mutex is unlocked in event_notify() function, then there are two
possible paths of failure:
1) First possibility is when RX and TX are called from two separate
threads, so that the other thread gets resumed and functions like
verify_tx_state() (e.g. in mqtt_publish()) allow to continue
communication over disconnected medium.
2) Another possibility is that user calls mqtt_abort() or
mqtt_disconnect() in event handler.
In both cases MQTT library tries to send or receive data, possibly
followed by second close() of underlying file descriptor.
Prevent using disconnected transport by clearing MQTT client state right
after calling mqtt_transport_disconnect(), without releasing mutex, even
for a while.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
When compiling with CONFIG_NET_NATIVE=n and CONFIG_NET_OFFLOAD=n
then the following error is printed.
```
In file included from zephyr/subsys/net/ip/ net_if.c:23:0:
zephyr/subsys/net/ip/net_private.h: In function 'net_context_state':
zephyr/subsys/net/ip/net_private.h:58:27:
error: type of 'context' defaults to 'int' [-Werror=implicit-int]
static inline const char *net_context_state(context)
```
This add `struct net_context *` as type for context.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Remove obsolete include of the shell_uart.h file.
It is sufficient to include the shell.h file.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
Since commit b3a1ede830 OpenThread uses the Zepyhr settings submodule
instead of writing to the flash directly. The flash.c file is not
compiled anymore, so let's just remove it. Also remove the
OT_PLAT_FLASH_PAGES_COUNT Kconfig option which was solely used by that
file.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Check that Ethernet header is in the first net_buf fragment.
This is very unlikely to happen as device driver is expected
to only deliver proper Ethernet frames to upper stack.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We run various TCP function from work queue. Make sure the
connection lock is taken before accessing the connection.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
support longer name like urn:dev:ops:{OUI}-{ProductClass}-{SerialNumber}
or urn:imei-msisdn:###############-###############
Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
Fixed stack being to small for joiner operations.
Enabled auto joining even in case of manual start.
Fixed attachement of SED on norfic radios.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Instead of casting k_delayed_work directly to k_work, use the
k_work field name. This avoids warnings from Coverity and
allows the code to work even if the k_delayed_work fields are
re-ordered in the future.
Coverity-CID: 214346
Fixes#28659
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add dependency to UDP in DHCPv4 Kconfig option as UDP is needed
in DHPCv4 to work properly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Bug description:
When in tcp_conn_unref(), in case one of the delayed works is already
submitted to sysworkq (after delay period), e.g. send_timer, the check
of k_delayed_work_remaining_get() prevents calling
k_delayed_work_cancel().
This leads to corrupting sysworkq when zeroing struct tcp* conn.
Note that the "next" pointer for the work queue is part of the struct
work (in _reserved field). Which is, in this case, a member of struct
tcp.
Scenario leading to the bug:
(1) net_tcp_connect() is called from a work in sysworkq
(2) net_tcp_connect() submits conn->send_timer to sysworkq
(3) while net_tcp_connect() is waiting on connect_sem, delay period
passes (z_timeout) and send_timer enters sysworkq work slist
(4) also, some other code (app) submits more works to queue, now pointed
by conn->send_timer in sysworkq work list
(5) connection fails (no answer to SYN), causing a call to
tcp_conn_unref()
(6) tcp_conn_unref() is calling tcp_send_queue_flush()
(7) checking k_delayed_work_remaining_get(&conn->send_timer) returns 0
due to delay period end, but send_timer is still in sysworkq work
slist (sysworkq thread still hasn't handled the work)
(8) BUG!: no call to k_delayed_work_cancel(&conn->send_timer)
(9) back in tcp_conn_unref(), a call to memset(conn, 0, sizeof(*conn))
zeroes conn->send_timer
(10) conn->send_timer is pointed to in sysworkq work slist, but is
zeroed, clearing pointer to following works submitted in stage (4)
(11) EFFECT! the works in stage (4) are never executed!!
NOTES:
* k_delayed_work_cancel(), handles both states:
(1) delayed work pends on timeout and
(2) work already in queue.
So there is no need to check k_delayed_work_remaining_get()
* This is also relevant for conn->send_data_timer
Solution:
removing checks of k_delayed_work_remaining_get(), always calling
k_delayed_work_cancel() for work in struct tcp, in unref, before memset
Signed-off-by: David Komel <a8961713@gmail.com>
Instead of hardcoding the priority1 and priority2 values used
in BMCA, let the user tweak the values via Kconfig.
Fixes#28151
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Since conn->send_data_total is of time size_t we need to use %zu or
we'll get build errors in sanitycheck on 64-bit platforms
Fixes#28605
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
If the network driver for some reason did not set the data in
the network packet properly, then just drop it as we cannot do
anything with just plain net_pkt.
Fixes#28131
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If there is no handler for IPv4 broadcast packet, then ignore it
instead of trying to send an ARP message to resolve the senders
address.
Fixes#21016
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We need to have timer that closes the connection for good if
we do not get the FIN and ACK reponse from the peer.
If there is any pending data when application does close(),
send them before sending FIN.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If there is some error during connection creation, just bail
out in order to avoid null pointer access.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If we try to send data but the sending window is full, then
try to kick the resend of the pending data.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If there is no space in the sending window, then return -EAGAIN
so that the caller may try later.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We should have a max value for sending window so that application
is not able to use all our net_bufs for queueing packets.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The socket layer expects to receive -ENOBUFS if we do not have
any network buffers so cannot build a network message to be sent.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If there is an error, the net_context.c:context_sendto() will
free the net_pkt, so we must not do it here.
This commit fixes this error message:
<err> net_pkt: *** ERROR *** pkt 0x20421908 is freed already
(context_sendto():1672)
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Usually the out-of-memory situation will clear itself eventually,
so if that happens in TCP, then keep the connection running and
let the user to decide what to do next.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If we run out of network buffers and cannot send data, and if
we have a blocking socket, then wait until new buffers are
available before returning. As this might lead to deadlock,
wait only max 10 seconds and return ENOMEM if we cannot get
buffers in a reasonable amount of time.
Fixes#28216
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Instead of hardcoded value of 3, use the value from Kconfig file
so that user can tweak the TCP retry count.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use SYS_SLIST_FOR_EACH_CONTAINER_SAFE() macro when searching
the connection list so that we notice if new entries are added
or removed in the list.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Instead of forcing the slist node to be first in the tcp struct,
use the pointer to node when accessing the slist. This way we
can change the ordering of fields in tcp struct.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Change so that the caller of lwm2m_init_message is
responsible for generating a message id and remove message id generation
from lwm2m_init_message. Prevents generating a new id when the caller's
intent is to init a message with id 0.
Fixes#28283
Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
message id 0 and token 0 have special semantics in the lwm2m engine,
they are used to request generation of new id, mark them as such.
Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
Fix the OpenThread initialization to prevent the IPv6 interface to
be enabled when `CONFIG_OPENTHREAD_RAW` is set.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Because the previous commit fixed the destination address check,
we need to handle msghdr (used by sendmsg()) in CAN socket.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
No need to specifically check CAN sockets here. This also means
that SocketCAN will need to support sendmsg() call too. This will
come in following commit.
Fixes#28229
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The timeout variable in `dtls_rx()` was initialized improperly.
Coverity ID: 214219
Fixes#28161
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The default string representing Sensor Type resource in Generic IPSO
object would not fit into the predefined buffer. Increase the buffer
size and add extra BUILD_ASSERT to detect this situation.
Coverity ID: 214225
Fixes#28164
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The timeout log error message condition in wrong. When the timout
happens the "count == -1" and the condition is invalid.
This commit fixes it.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
When the connection is terminated, make sure that any pending
data is feed to the application.
Fixes#28057
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Fix for a problem in current lwm2m firmware object implementation.
Transfer should not begin when an empty string is received.
Signed-off-by: Marin Jurjevic <marin.jurjevic@hotmail.com>
Some implementation consist of multiple libraries to be linked instead
of one. Added possibility to pass multiple libraries. Additionally
renamed the config name as it was stateing something different than it
does.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
If we receive a TCP segment with FIN | ACK | PSH flags, then
update the ack values properly.
Fixes#27982
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This new option allows to include `sockets_tls.c` into the build when
socket offloading is enabled.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Given that the offloaded poll handling differs from the poll handling of
native sockets (entire poll function call is offloaded), some
adjustements were needed to make TLS socket work with offloaded poll
calls.
To achieve this, in case socket offloading is used, instead of jumping
directly to the offloaded poll call, a TLS wrapper for the offloaded
poll will be called. This wrapper will do additional checks at the
mbedtls level, to verify that the event is only notified to the caller
when the application data is available (i. e. not to report events
during handshake or when partial data is received, not ready to
decrypt).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Separate TLS sockets implementation from net_context layer. Instead of
calling net_context functions directly, create an underlying TCP/UDP
socket, and call socket functions on it instead. This results in a
simpler design, where we don't need to duplicate specific parts of code
from the native socket implementation. Additionally, this allows to use
a different TCP/UDP stack underneath (i. e. when sockets offloading is
used).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit adds helper function to verify protocol, which was done in
two different places in the code. The function returns the underlying
protocol information on success.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When connection is closed and we send ACK flag, use proper seq
values so that any data that is still in flight will get acked too.
Currently this assumes that window is still open.
Fixes#27876
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Entropy device, as being unique here, does not need to be passed through
mbedtls and can instead set static locally.
Fixes#27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.
A coccinelle rule is used for this:
@r_const_dev_1
disable optional_qualifier
@
@@
-struct device *
+const struct device *
@r_const_dev_2
disable optional_qualifier
@
@@
-struct device * const
+const struct device *
Fixes#27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Following are the changes to variable names that are matching
with tag names (Rule 5.7 violations)
In kernel.h, event_type is matching with a tag name in
lib/os/onoff.c. Added a _ prefix to event_type and
also to the macro argument names.
In userspace.c, *dyn_obj is matching with the tag name
dyn_obj in the file itslef. Changed it to dyn
In device.h, device_mmio.h, init.h and init.c,
changed the *device to dev. Except for one change in
init.h
Signed-off-by: Spoorthy Priya Yerabolu <spoorthy.priya.yerabolu@intel.com>
Add more tests to verify that we discard malformed packets.
In order to simplify the testing, separate message validation to
dns_validate_msg() function in resolve.c. Allow that function to
be called from unit test. This way we can construct invalid DNS
messages in unit test and verify that they are discarded when
needed.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The ANCOUNT has nothing to do with label count so remove the
original while loop and just go through all the labels until
we have read all of them.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This is not possible with valid DNS messages but is possible if
we receive malformed DNS packet.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Allow user to create SOCK_DGRAM type AF_PACKET socket. This
allows user to send raw IP packets without specifying
L2 (like Ethernet) headers.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The steps_removed field must be placed right after root_system_id
so that priority vector comparision can be done in one memcmp()
call. This fixes the best master clock selection algorithm (BMCA).
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
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>
-Wimplicit-fallthrough=2 requires a fallthrough comment or a compiler
to tells gcc that this happens intentionally.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Added additonal checks in net_ipv6_input to ensure that multicasts
are only passed to the upper layer if the originating interface
actually joined the destination multicast group.
Signed-off-by: Philip Serbin <philip.serbin@lemonbeat.com>
Now that TCP2 is the default stack, make the shell compatible
with both stacks.
Note: net_tcp_foreach is not implemented in TCP2, so related
code depends on TCP1.
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
PPP Phase Diagram [1] allows only one way phase change. In current
implementation there is an additional RUNNING phase, which is entered
just after NETWORK phase.
Prevent going back from RUNNING to NETWORK phase when Term-Req was
received, as this is meaningless for overall PPP operation and violates
PPP Phase Diagram property of having one way direction change.
This change also improves Adminitrative Close handling (calling
lcp_close()). This request results in moving into TERMINATE phase. Then
LCP is put down (by calling lcp_down()) and then ppp_link_down() is
called, which so far (before this patch) resulted in moving back to
NETWORK and then to DEAD. Right now (after this patch) we move directly
from TERMINATE to DEAD phase, which is exactly how [1] specifies it.
[1] https://tools.ietf.org/html/rfc1661#section-3.2
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
State Transition Table [1] specifies that Administrative Close should
result in CLOSING state. This is not respected in case of LCP, as
STOPPED state was forced in lcp_close().
Don't force going into STOPPED state in lcp_close() and rely on
ppp_fsm_close() to move to CLOSING state instead.
This patch fixes overall Adminitrative Close procedure and allows to
move back into fully operating PPP connection once again after
Adminitrative Open.
[1] https://tools.ietf.org/html/rfc1661#section-4.1
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Print role information next to port information. Also make
sure that port number is set correctly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Save some memory and separate common string snippets from larger
strings. In this case "does not match" sub-string is printed by
several warning prints so separate the sub-string from the bigger
string.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
net: route: Add prefix-based ipv6 multicast forwarding
This adds/reenables the feature of multicast routing/forwarding.
The forwarding decision is based on the added multicast routes
and the new network interface flag:
NET_IF_FORWARD_MULTICASTS.
Signed-off-by: Jan Georgi <jan.georgi@lemonbeat.com>
This patch implements optional authentication phase, which is done
between link establishment and network phases. It is part of LCP option
negotiation to decide whether authentication is needed and which
protocol will be used. For now we add only PAP support and try to
negotiate it when some other protocol (e.g. CHAP or EAP) is proposed
earlier. For simplicity reason we only add one way authentication
support, which means that we try to authenticate to the other peer, but
do not require authentication from it.
This is an important step to make PPP work with cellular network modems,
because most of them require to provide username and password within PPP
authentication phase. Those credentials are used by modem to login to
cellular network. In most cases however it is enough to provide dummy
values, because they are not verified. For this reason and simplicity of
this patch we hardcode PAP Peer-ID and Password now.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This module had only some header includes, without actual code. Remove
it, as it is better to create one module per authentication protocol
anyway.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Add enums of PAP, CHAP and EAP authentication protocols. Also add their
string representations, so they will nicely show up in logs during
debugging.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Interpret -EINVAL return value from options' parse() callback as "option
value is not supported". After receiving such value nack() callback will
be executed in order to put supported value in the response.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Given the comment in `ipv6_event_handler`, the init function shall wait
for the last added IPv6 address to be confirmed with DAD. This is
contrary with current logic, which will only wait for the first address
to be confirmed.
This commit adds a break statement in the loop, not to overwrite the
recent address to verify with an older one.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When verifying the parameters check NULL value separately.
This will avoid nasty warning message to be printed.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add function pointer to vtable and use that directly instead of
routing via ioctl() call. This is done as we are trying to get
rid of ioctl() calls in the system.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Do not route close() calls via ioctl() as that is error prone
and quite pointless. Instead create a callback for close() in
fdtable and use it directly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Instead of casting struct in6_addr, sin6_addr member is now used
directly, like in every other instance of calling net_ipv6_is_prefix().
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
This macro has no use in code and was most probably replaced by
FSM_TIMEOUT (which resolves to CONFIG_NET_L2_PPP_TIMEOUT) with the same
default value.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Those macros are not used anymore after commit 35a2519091 ("net: l2:
ppp: add generic function for handling Conf-Req"), because we no longer
need preallocated table on stack for parsing option information.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This option is not used after commit 50b2cafc42 ("net: l2: ppp: use
net_pkt API for replying to Configure-Req") has been applied. We don't
need to preallocate table on stack for parsing option information, so
information about maximum number of supported options is useless.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit allows let build zperf sample with overlay-netusb.conf.
USB subsystem must be enabled by the application.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
For platforms using non-native stacks, net_tcp_init() should be
compiled out, similar to how it is done in tcp_internal.h.
Fixes#27463
Signed-off-by: Vincent Wan <vwan@ti.com>
Instead of just showing network interface pointer, print also
network interface index. This helps debugging.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
OT_RADIO_CAPS_SLEEP_TO_TX was added as a radio capability
for ieee802154 radio. Waiting on RX state before transmission
is alternative condition to OT_RADIO_CAPS_SLEEP_TO_TX support
as it was a result of OpenThread architecture and is actually
not needed in the Zephyr. Such change lets to start transmission
faster and lower SED device power consumption in active state
about 30%.
Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
Enable the new TCP stack as a default one in order to get people
to use it before Zephyr 2.4 is released.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Zephyr platform does not support MAC retransmissions on its own,
so OT_RADIO_CAPS_TRANSMIT_RETRIES capability was removed.
It should not be enabled basing on IEEE802154_HW_CSMA support,
as these are quite seperate features. Current implementation
assumes that platform performs retransmissions on its own,
what is not provided and leads to lack of MAC retransmissions.
Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
Allow user to enable CONFIG_NET_PKT_TXTIME and
CONFIG_NET_PKT_TXTIME_STATS at the same time. This will increase
memory consumption but as the CONFIG_NET_PKT_TXTIME_STATS is
only meant to be enabled for debugging purposes this overhead
can be accepted.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
In TCP, we increase the net_pkt refcount in order to resend
it later if we do not receive ACK in time. Because we are not
getting a new net_pkt, the TXTIME statistics would be calculated
incorrectly. So if we re-send, reset the net_pkt creation time.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add extra net_pkt RX timing information to "net stats" command.
You neeed to enable CONFIG_NET_PKT_RXTIME_STATS and
CONFIG_NET_PKT_RXTIME_STATS_DETAIL config options.
The "net stats" command will print something like this:
Avg RX net_pkt (7) time 459 us [0->23->16->257->160=456 us]
The extra stats is the end of line inside brackets.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add extra net_pkt TX timing information to "net stats" command.
You neeed to enable CONFIG_NET_PKT_TXTIME_STATS and
CONFIG_NET_PKT_TXTIME_STATS_DETAIL config options.
The "net stats" command will print something like this:
Avg TX net_pkt (5867) time 82 us [0->33->20->27=80 us]
The extra stats information is the end of line inside brackets.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Collect information how long net_pkt has travelled in IP stack
in certain points. See network documentation what these points
are and how to get information about the timings. This initial
commit adds support to TX timing collection.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
CONFIG_NET_CONFIG_INIT_TIMEOUT should not only be available if
CONFIG_NET_CONFIG_AUTO_INIT=y. If *_AUTO_INIT=n then application
may wish to initialize net manually and still use configured
timeout.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
If the CONFIG_NET_CONFIG_AUTO_INIT is not set, then let application
to do the initialization manually. In that case the app should call
net_config_init_app() when it is ready to setup the network.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Include directories for ${ARCH} is not specified correctly.
Several places in Zephyr, the include directories are specified as:
${ZEPHYR_BASE}/arch/${ARCH}/include
the correct line is:
${ARCH_DIR}/${ARCH}/include
to correctly support out of tree archs.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The original return type of tcp_data_get() was unsigned and the
return value <0 was not checked properly.
Fixes#25723
Coverity-CID: 210559
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The LwM2M server might modify the lifetime value while the device is
registered, hence it's needed to obtain the value directly from the
Server object instance, before each Register Update.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
A proper way to match a Security object instance with a Server object
instance is via Short Server ID resource. Both coupled object instances
should carry the same value of this resource in order to me considered
matched.
This was not implemented in the LwM2M library and it was incorrectly
assumed that the Security object instance index corresponds to the
Server object instance index. While such apporach works is simple
scenario, it might yield incorrect results when bootstrap is used.
Fix this, by verifyng the Short Server ID resource in the Secuirty
instance used, and finding a matching Server instance. The server object
instance is stored for future use in the engine.
Additionally, remove an extra Server object instance that was created
when the bootstrap procedure was used. Since the boostrap Security
object instance does not have the corresponding Server object, it's
enough to have a single Server instance.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Remove the static buffer for TCP options. Make sure that the
options were read properly to temp buffer.
Fixes: #25729
Coverity-CID: 210056
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This set of functions seem to be there just because of historical
reasons, stemming from Kbuild. They are non-obvious and prone to errors,
so remove them in favor of the `_ifdef()` ones with an explicit
`CONFIG_` condition.
Script used:
git grep -l _if_kconfig | xargs sed -E -i
"s/_if_kconfig\(\s*(\w*)/_ifdef(CONFIG_\U\1\E \1/g"
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Currently, OpenThread builds produce warning from the OT logger module,
because we don't use one of the parameters provided by logger macro.
Explicitly mark the parameter as unused to prevent warnings being
thrown.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Drop unused ppp_parse_options_array() function and 'struct
ppp_option_pkt' data type. Both were used in initial PPP implementation,
but are not longer needed after recent PPP refactoring.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Introduce new ppp_config_info_req() function that can be used in order
to handle options received within Conf-Req packet. As an input it takes
array of supported options. If received Conf-Req packet contains unknown
options, then a Conf-Rej packet is automatically generated with all of
those options. If all of received options are supported, then function
continues to parse each provided option individually by calling option
specific callbacks.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Use a generic handler for received options in Conf-Rej packet. This will
mark all those options as rejected, to they will no longer be included
in subsequence Conf-Req packets.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Use a generic handler for received options in Conf-Rej packet. This will
mark all those options as rejected, to they will no longer be included
in subsequence Conf-Req packets.
This allows to communicate with PPP peers, which do not support DNS1 and
DNS2 options.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
So far there was no generalized way how to handle negotiation of "my
options" (those sent with Conf-Req packet to peer). Peer response for
proposed options and their values were not tracked in any way, so
rejected (by peer) options were sent over and over again in subsequent
Conf-Req packets. In case of IPCP it means that all sent options such as
IP_ADDRESS, DNS1, DNS2 were mandatory for being supported by peer in
order to successfully finish negotiation. For example if 'pppd' was the
configured peer (e.g. when using with QEMU and net-tools scripts),
without ms-dns being configured (which is the default), then "my
options" negotiation failed.
Introduce generalized mechanism for negotiating "my options", so it is
easier to maintain current set of supported options and easily add new
options to the implementation in future. FSM instance inititialization
function can provide information about supported "my options".
Information is is passed as a table of 'struct ppp_my_option_info'
containing:
* option code (type),
* callback for adding option to Conf-Req packet,
* callback for received Conf-Ack with that option,
* callback for received Conf-Nak with that option.
Store also runtime information about each negotiated option. First of
all remember which options have been rejected, so they are not sent to
peer once again in the next Conf-Req packet. This will solve issue with
IPCP negotiation when peer doesn't support DNS1 or DNS2 options. Keep
also track about which options have been acked, so such information can
be verified before bringing FSM instance up.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Rework implementation of ppp_parse_options() to be more generic and
flexible to use. Pass callback and user data for parsing each option
separately.
Keep old functionality of ppp_parse_options() accessible via
ppp_parse_options_array() function. This will make sure that old code
using this function doesn't need to be changed now. There are plans
however to remove ppp_parse_options_array() once there are no more users
of it in future.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Use net_pkt API to assemble Configure-Req messages. Compared to net_buf
API it allows us to simplify code.
Remove append_to_buf() helper functions, as their functionality is now
totally replaced by net_pkt API. Additionally net_pkt API handles data
that wraps several net_buf packets, which was not the case with
append_to_buf().
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Use net_pkt instead of net_buf API for replying to Configure-Req. We use
the fact that for now we reply with either Configure-Ack or
Configure-Rej only. In both cases we can allocate net_pkt ahead, because
we know its maximum length (which is equal to length of received
Configure-Req packet).
Make also an improvement in generic FSM code and reply with
Configure-Rej to all Configure-Req for which there is no config_info_req
callback set. Use that to drop LCP specific Conf-Req handling code,
because there is no option properly supported there yet.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
So far ppp_parse_options() has returned enum net_verdict. This type was
never used directly by network stack. Instead, caller was always
checking for NET_OK and returning error code in case of failure.
Change implementation of ppp_parse_options(), so it returns error code
in case of error and 0 when succeeded. This better fits its generic
purpose.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
There is no allocation in ppp_l2.c file, which mean that
BUF_ALLOC_TIMEOUT macros is not used anywhere. Drop it.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Make sure that only those threads that have been granted access
to net_if objects, can call the functions that modify net_if data.
The CONFIG_NET_IF_USERSPACE_ACCESS config option is also removed
as it is no longer needed after this change.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Make net_if a kernel object with type K_OBJ_NET_IF so that we
can restrict access to it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
There was a race condition when ppp_fsm_open() was called in CLOSED
state. Conf-Req was sent first, then state was changed to
REQUEST_SENT. In the meantime however we have already received Conf-Req
to which we responded with Term-Ack.
Change state before sending Conf-Req, so we handle Conf-Req from peer
properly instead of dropping it.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
OpenThread API is not thread safe, therefore it shall be protected
from being preempted by OT thread, or other thread issuing API calls.
The problem showed up after a recent OpenThread upmerge, where changes
in the Joiner class made this problem visible. W/o extra protection,
`otJoinerStart` call can be preempted by the OT thread, leading to an
unexpected behavior.
Introduce new function to allow to lock any API operations for others.
Anyone willing to call OT APIs, shall lock the mutex first to get
exclusive access to the stack.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
`otLinkRawSetEnable` was removed and Link Raw mode is now enabled with
`otLinkRawSetReceiveDone` which requires to register a callback
function. Since it makes little sense for OT L2 to register a Link Raw
callback in current setup, leave it up to the application to register
the callback.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Bugfix: in tcp_conn_unref(), the conn was zeroed before removing it
from the connection list (tcp_conns).
Zeroing conn, results in zeroing its 'next' member,
which in effect removes all its following connections referred to
in tcp_conns linked list.
The solution is to move the memset() after sys_slist_find_and_remove().
Signed-off-by: David D <a8961713@gmail.com>
The network interface check was invalid when IPv6 Router
Solicitation message was timeout and interface was not found.
This is highly unlikely but needs to be checked properly.
Fixes#27145
Coverity-CID: 211511
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Currently, the application could receive a duplicate CONNACK event, in
case the server rejected the connection at MQTT level (with an error
code provided with CONNACK message). A subsequent connection close (with
`mqtt_abort` for instance) would produce the duplicate event.
Fix this by reporting back to the MQTT engine, that the connection was
refused, so it can close the connection rightaway. Rework the event
notification logic, so that DISCONNECT event instead of a duplicate
CONNACK event is notified in that case.
Also, prevent the MQTT engine from notyfing DISCONNECT event in case of
socket errors during initial connection phase (i. e. before
`mqtt_connect` function finished).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
is_init field is useless, because there is only single code path that
always sets it to true before using it.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Make sure IPv6 address is removed from network interface in IPV6CP
protocol down handler. This makes sure that application can receive
high-level notification about missing network connection.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Make sure IPv4 address is removed from network interface in IPCP
protocol down handler. This makes sure that application can receive
high-level notification about missing network connection.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Added the 'fall through' comment to switch to quiet compiler
and coverity warnings.
Fixes#25724Fixes#25726
Signed-off-by: David Leach <david.leach@nxp.com>
To allow hardware crypto acceleration custom mbedtls library needs to be
prepared. However current implementation forces the default library to
be used.
This patch allows not using the default library and passing custom
mbedtls target to use with openthread.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
The TCP2 stack does operations directly on the packet data which may
or may not be aligned. The unaligned access causes a fault on the
Cortex-M0+ so use the UNALIGNED_* macros instead.
Signed-off-by: Michael Hope <mlhx@google.com>
Putting data to local buffer before transmission was removed
to optimize operation. Local buffering was not needed, as passed
buffer cannot be modified until sending is finished.
Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
Currently, functions for poll sock_fds array management are buggy, in
case there is another socket open (for instance the socket for firmware
update download), it could get overwritten, if the LwM2M socket was
closed and re-opened in a meantime (e. g. on registration timeout).
Fix this, by appending new entries to the sock_fds in continuous manner.
In case of removal, the deleted entry is overwritten by the last one,
and the last one is cleared.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
During FW update, the application expects a consecutive data stream.
Therefore retransmitted blocks shall not be forwarded to the
application, but ignored. In case blocks are received out of order,
return an error and do not handle this block.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When FW update in PUSH mode is used, the firmware is encapsulated in the
TLV as an opaque data, according to the LMWM2M satandard, and then
sliced into blocks and transferred block by block in several
transactions. Therefore, the TLV header is only present in the initial
message.
Current implementation did not handle this case well, reporting errors
on consecutive blocks, therefore making the FW update in PUSH mode
broken.
This commit fixes this issue with following changes:
* The TLV is only assumed to be present in the initial block, while
consecutive blocks will be processed directly into the appropriate
handler,
* 32-bit variables shall be used whenever dealing with the opaque data
length, since the firmware size can easily exceed the 16-bit range,
* Additional information, required for the FW block transfer to work
properly were added to the block context structure,
* The application shall only be notified of the actual data length, and
not the total block size (the total TLV size including header).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When the dupplicate address detection mechanism is not used, we should
not wait for IPv6 address configuration. Because of the bug we are
waiting for it, when CONFIG_NET_CONFIG_MY_IVP6_ADDR is not set.
This commit fixes it.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
Remove the `sm_bootstrap_reg_done` function, which produced duplicated
logs. The bootstrap registration done event is already logged on state
transition. Additionally, in case bootstrap procedure took longer time,
the duplicated log message was printed on each `lwm2m_rd_client_service`
call (500 miliseconds by default).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The security object instance used should be cleared on engine reset,
otherwise we might end up using invalid object instance for the
registration (i. e. if the engine was restarted during the bootstrap
procedure due to socket errors, the registration attempt will use
bootstrap security object instead of finding a proper one).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
During the bootstrap procedure, when Boostrap Finish was received, the
response message was not initialized properly, resulting in a socket
error (NULL pointer porovided) and the response not being sent.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The Z_STRUCT_SECTION_ITERABLE() provides an alignment so remove
the 32 byte alignment for net_if and ppp_protocol_handler structs.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use system provided Z_STRUCT_SECTION_FOREACH() and
Z_STRUCT_SECTION_ITERABLE() macros instead of manually coding
everything for network sections.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Different switch was used for build to allow including all shim body
in zephyr without the need for building openthread from this repo. This
allows developer to include custom OpenThread sources as part of the
application.
This change is needed as Thread is a subject of certification and
sources provided by zephyr may not necesairly pass certification or be
precertified. User is allowed to use certified OpenThread version
this way.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
Fix compilation error when the DIAG module is enabled.
All core functionalities are provided.
Signed-off-by: Piotr Szkotak <piotr.szkotak@nordicsemi.no>
When this happens, ip6_addr_cb and ipv6_addr_event_handler() both look
unused, since they are passed to macros which discard them.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
In order to implement a blocking connect, add a semaphore
and block on it in net_tcp_connect().
The semaphore is released when ESTABLISHED state is reached.
In case tcp_conn_unref() is called while waiting on the semaphore,
defer the unreference, tcp_conn_unref() will be called from
net_tcp_connect().
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to improve readability, refactor and simplify
the control flow in net_tcp_connect().
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order for events to be correctly interpreted in SYN_SENT,
check for SYN and ACK simultaneosly.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
net_tcp_put() can be called before ESTABLISHED state
is reached, send FIN only in ESTABLISHED state.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Single work object for whole fsm was not being able to handle more than
single packet at a time. Because of that we have overwritten already
scheduled packets, resulting in fsm timeout and net_pkt leak.
Use net_pkt work object instead, so we can safely schedule more than a
single packet.
This commit also drops workaround for qemu_x86 unit testing.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Current implementation of net_ipv6_send_rs() uses
net_ipv6_addr_create_ll_allnodes_mcast() for creating RS packet.
As result we send RS packet to all-nodes destination [FF02::1],
but RFC4291 requires all-routers destination [FF02::2] for RS packets.
Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
`addrlen` parameter is updated on each `recvfrom` call, indicating the
actual address length returned. In case both, IPv4 and IPv6 are used on
different sockets (i. e. on regular LWM2M socket and FOTA socket), the
returned address length will differ.
In case `from_addr_len` is not reinitialized on each iteration, the
value stored in the `from_addr_len` variable will eventually indicate
the smaller IPv4 address size, therefore resulting in a failure in a
consecutive call on an IPv6 socket.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Although LwM2M engine uses cooperative threads, the internal `send()`
implementation might trigger context switch when it calls a kernel
function, therefore resulting in `send()` call being entered from both
the LwM2M thread and the retransmit work.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Currently there is a single function that handles both Configure-Ack and
Configure-Rej messages. This is obviously wrong for Configure-Rej,
because implementation applies options received in the message.
Remove Configure-Rej callback, so those frames are simply ignored for
the time no valid handling code exists.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Clear negotiated options in protocol down handler. That way all
addresses are properly requested (by sending 0.0.0.0 in Configure-Req)
in the subsequent option negotiation phases.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Unit tests were failing to build because random header was included by
kernel_includes.h. The problem is that rand32.h includes a generated
file that is either not generated or not included when building unit
tests. Also, it is better to limit the scope of this file to where it is
used.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
The context should only clear messages it owns, not all of them. Since
both context (LwM2M and FOTA) share common message pool, they might
interrupt their operation otherwise (i. e. cancel retransmissions).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The FOTA socket was not closed when download finished or an error
occured.
Additionally, fix the socket fd verification (it was assumed 0 is not a
valid fd which is not correct).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In function z_vrfy_net_addr_pton(),
the final copy should be to 'dst' variable not to 'src'
Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
In case unsopported TLV type or malformed packet is received, the
`do_write_op_tlv` function will end up in an infinite loop. Prevent that
by returning an error code in case it does not recognize TLV type.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
There is already a variable 'network_protos_up', which stores number of
network protocols being up. Additionally each network protocol has its
own state represented by is_ip{,v6}cp_up. Use the latter in FSM up() and
down() callbacks.
This fixes a case when both IPCP and IPv6CP protocols are going
down. When using ctx->is_network_up only one of them (the first) was
deinitialized correctly, second stayed always up (at least partially,
e.g. not calling ppp_network_down()).
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Each PPP packet sent on wire needs to have at least 4 bytes length. Set
that length for outgoing Term-Req and Term-Ack packets. Also update
length validation to check for at least 4 bytes instead of at least 1
byte.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
It fixes #issues/26220.
openthread_start function is called when L2 enable(iface, true) is
called. openthread_stop is called when L2 enable(iface, false) is
called. openthread_stop makes the device to leave the OpenThread
network.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
OpenThread BR can assign addresses via DHCPv6 or when acting as an
NCP, addresses can be added manually. Currently, those addresses are
handled in the same way as auto-configured addresses.
This patch maps the newly introduced mAddressOrigin of otNetifAddress to
Zephyr's net_addr_type.
This way an application can register a handler and differentiate by type
of assignment:
```
static void handler(struct net_mgmt_event_callback *cb,
u32_t mgmt_event,
struct net_if *iface)
{
if (iface->config.ip.ipv6->unicast[i].addr_type == NET_ADDR_DHCP) {
}
}
```
Signed-off-by: Markus Becker <markus.becker@tridonic.com>
Some options were available in the options.cmake but were not reflected
in Kconfig.
Added possibility to enable additional configuration options for OT.
Some of the options were left commented out as those options are not
yet supported e.g. require Thread 1.2 or require shim changes.
As openthread has gazillion configuration options that are passed as
define value, created generic option for passing any number of those
values separated with space.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
Currently user needs to specify quite much additional options to enable
OpenThread support. He also needs to set ip address count,
heap size, etc depending on features enabled.
Nade changes to automatically select/set some of the options on
enabling OpenThread
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
Both ASYNC_CTRL_CHAR_MAP and MAGIC_NUMBER are not supported right
now. Send Configure-Reject for them instead of Configure-Nak, as we
don't even propose new values in reply (which should be part of
Configure-Nak).
Send also Configure-Reject for MRU option, as we don't respect it
either.
Drop both count_rej and count_nack, as we can rely solely on nack_idx to
send Configure-Reject or not.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
If we have multiple network interfaces and we are waiting incoming
network packets, make sure to honor the bind of the socket so that
correct socket will receive data in certain network interface.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The sync receive timeout was using invalid value (nanoseconds
instead of milliseconds). This caused unnecessary state switches
from SLAVE to MASTER and back.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add debug prints when the port announce information state
machine state changes. This is useful in debugging.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The port number is stored starting from 0 in Ethernet context.
But in gPTP, it is an index which starts from 1. So increase
the value by 1 for a value returned from Ethernet context.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
It may be useful for the application to register its own callback for
ot state changed event which does not override the current one.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
It may be useful to start openthread manually but with default
network settings. For instance when the application wants to register
ot state changed callback which should be done before openthread
starts.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
Allow to configure, how long before registration timeout should the
Registration Update be sent. The fixed 6 seconds used so far, might
not be enough in slower networks (like NB-IoT), resulting in frequent
re-registrations at LWM2M level.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
OpenThread API is not thread-safe.
Moved creation of otMessage to the Thread task and created api
for passing it properly.
This way it should be less possible for an issue to occure eg.
during message buffer allocation.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
ppp does not populate the lladdr fields in the received packet.
To enable routing for packets received on the ppp interface, the check
of the link layer addresses in the packet must be skipped.
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
Added automatic strdup for RAM %s parameters. Postponed format
processing to idle time. Automatic parameters counting during
compilation. Very fast execution for up to three parameters.
Signed-off-by: Tomasz Konieczny <tomasz.konieczny@nordicsemi.no>
This is no longer required since drivers implementing the sockets
offload interface were migrated to use pure zsock_ instead of
raw POSIX types and functions.
Signed-off-by: Adam Porter <porter.adam@gmail.com>
A net context in LISTENING mode waits for incoming connections, once
a new connection is established a new net context is spawned which
is responsible for handling the new connection.
Therefore when closing a LISTENING context it is not useful to send FIN
as it is never connected. Actually closing the connection would be done
by calling close on the spawned net context which is returned by the
accept call.
Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
Currently there is chosen the link local address as a source address
for each multicast destination address. It is a bug for OpenThread
network where the mesh-local EID addres should be picked in this case.
This commit fixes it by distinquish the mesh local multicast among any
others.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
With timeout==0 count is set to 0 as well and then it is decremented to
-1. It is later checked == 0 and continues to decrement and loop.
Signed-off-by: Markus Becker <markus.becker@tridonic.com>
Under Linux when you shutdown a socket which is blocked on
an accept call the error code returned by accept is EINVAL.
Modify the socket code to be inline with this behaviour.
Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
When closing a listening socket the functions waiting on the
FIFO will be unblocked this will result in receiving a NULL child
context. If that is the case return an error instead of carrying on.
Return the same error code (EINVAL) that is returned on Linux when
calling shutdown on a blocked accept call.
Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
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>
This should be boolean according to specification. It makes difference
when JSON encoding is used.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Avoid null pointer access by checking that Ethernet device has
PTP clock before trying to get the actual PTP clock device.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
So far net config initialization code relied on number of services
needed by application. This was fine as long as all enabled
services (e.g. CONFIG_NET_IPV4=y, CONFIG_NET_IPV6=y) were selected by
project configuration as "needed" (e.g. CONFIG_NET_CONFIG_NEED_IPV4=y,
CONFIG_NET_CONFIG_NEED_IPV6=y). Problem appeared for example when both
IPv4 and IPv6 were enabled (CONFIG_NET_IPV4=y, CONFIG_NET_IPV6=y), but
only IPv6 was marked as "needed" (CONFIG_NET_CONFIG_NEED_IPV6=y). In
such situation number of required services was equal to 1. When IPv4
setup was completed, this resulted in returning from net_config_init()
function. Application code failed, because IPv6 was still not
functional.
Do not rely on number of services anymore, as it is error prone. Use
flags instead to mark which services are ready. Compare those flags with
the flags passed to net_config_init() (selected in project configuration
in most cases) to decide whether network configuration has completed
already or not.
Also introduce services_notify_ready() and services_are_ready() helper
functions to isolate implementation details from the logic.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
With current design there is single semaphore (called 'waiter') for
wakeing up initialization thread. This thread should then check for
number of protocols that still need to be initialized. This happens now
only when waiting on 'waiter' semaphore times out.
Do not check for k_sem_take(&waiter) return value, as all needed
information about protocols being initialized already is in 'counter'
semaphore.
Fixes: #25358
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Add command to register a receive callback to the net_context used for
the TCP connection that is opened with 'net tcp connect'. The receive
callback will simply print the number of bytes received and inform if
the connection is closed. This makes it possible to test both the tx
and rx paths with the net shell.
Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
It might happen that while we are waiting for the response
to one of our query, we receive a query to resolve another name.
Previously this would make the current name resolution to fail because
only responses were expected to be received.
Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
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>
It add an option to configure openthread thread priority class
by the application if there is a such need.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
The SET_ERRNO() macro does nothing if a positive value is provided
to it, and the functions were not returning -1 or setting errno
as expected.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
APIs were returning -1 without setting errno if the file
descriptor looked up a null object or there was no function
installed in the vtable. Set to EBADF for this case.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Net pkt is added into the ot net list after queued net pkt into
the net_rx which bases on it. It affects in losting net pkt when for
instance ot thread is preemptive.
Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
The eth_stats_update_errors_rx() implicitly assumes that passed pointer
to struct net_if is not NULL.
This is not true for MCUX's eth_rx() (in eth_mcux.c), where we can
execute eth_stats_update_errors_rx() after net_recv_data() returning
-EINVAL because of passed NULL iface pointer.
This change fixes this problem with adding extra check on iface not
being NULL before it is dereferenced.
Signed-off-by: Lukasz Majewski <lukma@denx.de>
This change fixes routing for routes when the nexthop is a link-local
address of a connected peer.
The issue was that nexthop was correctly set from the routes, but the
code did not detect that the nexthop address (link local of the pc on
ppp interface) was on the ppp interface, because
net_if_ipv6_addr_onlink() only evaluated the network prefix and not
any other information (like the nbr list).
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
This change adds new, optional switch to 'net ping' command - to
be more specific the '-I <iface index>', where the <iface index>
is the number of supported network interface.
One can discover this number from the Zephyr shell after running
'net iface'.
The default interface stays the same - just the switch is added to
override the used interface for 'net ping' invocation.
Signed-off-by: Lukasz Majewski <lukma@denx.de>
Cleansession is hardcoded to 1 but some use case might require 0
to make the sessions persistent (ie get messages sent while the
client was offline)
Signed-off-by: Xavier Naveira <xnaveira@gmail.com>
This PR enables the user to configure the maximum command length for
OpenThread's CLI using Zephyr's shell, which is currently fixed to
256 characteres. This limitation was not enough for certain allowed
OpenThread commands, like some variants of 'ot dataset mgmtsetcommand'.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Right now shell pointer is not assigned before doing a scan, so scan
results are printed using printk(). Save shell instance in context, so
results are printed using shell_fprintf(), thus better aligned in the
console output.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
The network statistics is stored for each traffic class, but the
collecting function was given net_pkt priority. The priority
must be first converted to traffic class and then the statistics
stored to correct place in the stats array.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Some radio drivers need configuration before start-up. Up to now only
the RF2XX drivers allowed this, but other radio drivers need this as
well. In particular for setting EUI64 addresses.
Signed-off-by: Markus Becker <markus.becker@tridonic.com>
When `z_get_fd_obj_and_vtable()` function returns NULL (no valid entry
in the FD table for the socket), there is no need for further usermode
checks on the `ctx` pointer, as there is nothing to invalidate in that
case.
Fixes#25990Fixes#25991
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The original sockets system calls used file descriptors which
were actually net_context pointers. For all socket system calls,
any calls from user mode would check if the caller had permission
to use the net context.
This was later changed to not stuff net_context pointers into file
descriptors, but all the permission checking was unintentionally
lost, allowing all threads on the system to
read/write all socket file descriptors in the system at will, with
no way to isolate applications running on the same microcontroller
from each other's network activity.
This patch restores the permission checks on network context objects
for socket system calls that originated from user mode.
The call to z_object_recycle() was never removed from
zsock_socket_internal(); this is again leveraged to grant the
caller who opened the socket permission on the net_context
associated with the returned file descriptor.
To ensure that all socket calls do this checking, all uses of
z_get_fd_obj_and_vtable() have been routed through get_sock_vtable().
Objects have initialization state set and thread permissions
reset to just the caller in common zsock_socket() code.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
The socketpair file descriptor context objects are heap allocated
and not drawn from a static pool. Register these as kernel objects
when we create them if user mode is enabled.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Zephyr running on MPU devices have a different memory model than
process-oriented OSes like Linux and require a method to set
kernel object permissions on a file descriptor's underlying
context object. Add this, and a test to show that it is working.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Used for permission validation when accessing the associated file
descriptors from user mode.
There often get defined in implementation code, expand the search
to look in drivers/ and subsys/net/.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Need to use %zd in formatter string for net_pkt_get_len since it returns
a size_t otherwise we get something like:
error: format ‘%d’ expects argument of type ‘int’, but argument
3 has type ‘size_t’ {aka ‘long unsigned int’} [-Werror=format=]
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
If we are calling sendmsg() without any aux data, then msg_controllen
is 0 and msg_control is NULL. Check these allowed values properly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If we are calling sendmsg() for a connected socket, then msg_namelen
is 0 and msg_name is NULL. Check these allowed values properly.
Also modify unit tests so that we test this scenario.
Fixes#25925
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
In this, case is_nonblock is false and will_block is true.
Therefore, we *may* block, and furthermore we *expect* to
block. Checking is_nonblock is, in fact, redundant, and
passing K_FOREVER to k_sem_take() is justified.
Fixes#25727
Coverity-CID: 210611
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
Due to new checks in mbedTLS config sanitizer, TLS option can no longer
be left enabled, when TLS is not used. OpenThread needs MBEDTLS_MD_C
and MBEDTLS_CIPHER_C even without TLS being used, so we need an option
to enable them manually.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The Router Advertisement can have prefix option. It's length
is 4 but the code did not check that which meant that we could
accept malformed packet. See RFC 4861 chapter 4.6.2 for details.
Fixes#25694
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Make sure that we do not add same IPv6 prefix, received from RA,
multiple times to prefix timer list. This avoids possible
denial-of-service issue if we receive suitably crafted RA packet.
Fixes#25698
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
OpenThread moved from 4 to 5 debug levels and it was not possible
to configure all of them with Kconfig.
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
In order to support the retransmission for the outgoing data:
1. The outgoing data packet is appended to the send_data queue
in net_tcp_queue_data().
2. tcp_send_queued_data() is called and will use tcp_send_data()
to sends queued but unsent data packet by packet
until there's an unsent data and the receiver's window isn't full.
tcp_send_queued_data() subscribes send_data_timer
that will handle retrasmissions with tcp_resend_data().
3. tcp_send_data() peeks a single chunk of data from the send_data
queue that will not exceed the maximum segment size
until the the receiver's window is full.
tcp_send_data() uses conn->seq and conn->unack_len as the sequence
number for the TCP packet.
conn->unacked_len is advanced on each send.
4. On data acknowledgment:
- acknowledged amount of data is removed from the beginning
of the send_data queue
- conn->seq is advanced by the acknowledged amount
- conn->unacked_len is decremented by the acknowledged amount
- send_data_timer is cancelled
- tcp_send_queued_data() is called to send queued but
prevoiusly unsent data
5. On timeout, tcp_resend_data() will reset conn->unack_len,
peek one packet from the beginning of the send_queue and resend,
terminating the connection on retries exceeded.
Meanwhile the outgoing data tcp_send_queued_data() is just
appended to the send_data but not sent.
In case of the acknowledgement, tcp_send_queued_data() will
start sending multiple packets until the receiver's window
is full.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to support the retransmission for the outgoind data,
add the following into the TCP connection:
- struct net_pkt *send_data (used as a queue)
- send_data_total
- unack_len
- send_data_timer
- send_data_retries
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to support the send window, add send_win into
the TCP connection.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to support the data retransmission, refactor tcp_out()
into tcp_out_ext() which supports passing the sequence number.
In addition drop modifications of the connection sequence number
from tcp_out_ext(), this is the responsibility of data retransmission.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to use struct net_pkt for the outgoing data queue,
update tcp_pkt_alloc() macros, so they support allocation
without buffer.
Additionally, merge tcp_pkt_alloc() macros macros into one.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Unsuccessfull packet clone in tcp_data_get() isn't handled,
add an error handling and don't ACK the incoming data in this case.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to handle sequence overflow cases, use
net_tcp_seq_greater() to check if the sequence is greater/lower.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
The initial sequence number for a connection should be randomized
to prevent easy guesses.
Do not randomize the sequence number if network test or
test protocol is enabled.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
There was a possible race condition between sock_is_nonblock()
and k_sem_take() in spair_read() and spair_write() that was
mitigated.
Also clarified some of the conditional branching in those
functions.
Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
The link address was not printed correctly as log_strdup() was
missing from the debug print.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Print detailed information about a given net_pkt. This is
useful if there is a memory leak and you want to see more
detailed information about the data inside the buffer.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Added support for Qemu User Networking and tested with
qemu_x86 model. The support is kept simple assuming that
the TAP interface will always be preferred for more
sophisticated / practical use cases.
QEMU User Networking is implemented using "slirp", which
provides a full TCP/IP stack within QEMU and uses that
stack to implement a virtual NAT'd network. As this
support is built into QEMU, it can be used with any model
and requires no admin privileges on the host machine,
unlike TAP.
Added documentation to facilitate the user.
Signed-off-by: Bilal Wasim <bilalwasim676@gmail.com>
The LLDP packet was created but its type was not set to LLDP
and was sent as ARP message.
Fixes#25084
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add OpenThread configuration option, which allows to configure and start
OpenThread stack operation manually. This mode should be used in NCP
devices, as well as is needed for certification purposes, where
OpenTread stack have to be configured by the test framework and not
initialize and join the network on its own.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Frame format was validated, but its length should be also validated
relevantly against the format.
Fixes#24970
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Convert all canbus related API/samples/tests/subsys
to the new timeout API with k_timeout_t.
Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
If we have removed first net_buf, then we must not restore the
original cursor as that will point to wrong head net_buf.
Add also unit test to check that the packets are removed
properly.
Clarify the documentation that we are removing data from
beginning of the function, also document that the cursor
is reset after this call.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Replace:
DT_FLASH_ERASE_BLOCK_SIZE ->
DT_PROP(DT_CHOSEN(zephyr_flash), erase_block_size)
DT_FLASH_WRITE_BLOCK_SIZE ->
DT_PROP(DT_CHOSEN(zephyr_flash), write_block_size)
As this allows us to phase out the old generator.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Adding RFC1350 compliant support for TFTP Client in Zephyr. The
current implementation is minimal and only supports the ability
to get a file from the server.
Things for the future include support for putting files to
server and adding support for RFC2347.
Signed-off-by: Bilal Wasim <bilalwasim676@gmail.com>
In order to avoid retransmissions from the peer's side
on full-close, handle states properly.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
If net_pkt_pull() would cause an empty net_buf, then unref
those empty buffers from the list.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
So far socket errors reported by poll/recvfrom were ignored, which could
lead to an unexpected behavior when socket was left in an undefined
state.
Fix this, by requesting a re-registration in the LWM2M state machine,
which will close the faulty socket and open a new one. Note, that simply
closing and re-opening a socket in the lwm2m engine would not work,
since this would silently invalidate any open observations on the
lwm2m server side (due to port number change). Triggering a fresh
registration will notify the server to update its observations.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
SNTP implementation defined symbols like "MODE_MASK", which can easily
conflict with similary laxly defined symbols in other modules, and
indeed, we hit a case like that (below). So, prefix these symbols
consistently with "SNTP_", until more clear private namespacing
convention are made pervasive in Zephyr.
subsys/net/lib/sntp/sntp_pkt.h:14: error: "MODE_MASK" redefined
include/arch/arm/aarch32/cortex_a_r/cpu.h:17: note: this is the
location of the previous definition
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
On OT network with poor coverage, very often request/observe packets
doesn't get it's ACK and consumes from pendings/replies/message stacks.
In such cases when LWM2M engine tries to recover by resetting its state,
it fails because of lack of free messages.
Signed-off-by: Kiril Petrov <retfie@gmail.com>
In networks with high latencies (like NB-IoT), it's quite common to
recieve duplicated response. It's not an error condition, a correct way
to handle it is to simply ignore the duplicate. Lower the log level for
this event, not to disturb users.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The retaransmission logic was not correct in the lwm2m_engine, and could
lead to faulty behavior in case multiple messages were pending for
retransmission in the queue.
1. Since there is a singe delayed work item for entire retransmission
queue, `coap_pending_next_to_expire` should be called before
scheduling next timeout, to identify which message is going to expire
next (and when). Currently, the engine always set next timeout, based
on timeout from the message being currently re-transmitted.
2. In case the message was re-transmitted several times, and is removed
from the retansmission queue due to a timeout, next retransmission
should be scheduled, in case there are other messages on the queue.
3. Verify the timeout of the earliest message to expire in the
retransmission handler. In case messages from the beginning of the
queue were removed, we might need to schedule the retransmission
again, instead of sending message rightaway.
4. `lwm2m_send_message` is not handling retransmissions anyway, so
there's no need to check send attempts. Instead, verify
retransmission work item is already pending, and update its timeout
if needed.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
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>
Replace DT_FLASH_DEV_NAME with DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL.
We now set zephyr,flash-controller in the chosen node of the device
tree to the flash controller device.
NOTE: For a SoCs with on die flash, this points to the controller and
not the 'soc-nv-flash' node. Typically the controller is the
parent of the 'soc-nv-flash' node).
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit renames the Kconfig `FLOAT` symbol to `FPU`, since this
symbol only indicates that the hardware Floating Point Unit (FPU) is
used and does not imply and/or indicate the general availability of
toolchain-level floating point support (i.e. this symbol is not
selected when building for an FPU-less platform that supports floating
point operations through the toolchain-provided software floating point
library).
Moreover, given that the symbol that indicates the availability of FPU
is named `CPU_HAS_FPU`, it only makes sense to use "FPU" in the name of
the symbol that enables the FPU.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
In order to fix the line tracking of the TCP packet allocation
with the test protocol enabled, refactor tcp_pkt_alloc(),
so the line of the allocation can be tracked properly.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
The LwM2M stack would previously ignore all OPAQUE resources when
reading them. This meant that it was impossible to read them, even if
there was a custom read callback.
Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
Some services like DHCHPv4 directly send raw packets to the iface.
This causes issue when the iface does not implement l2, e.g.
because it is a socket offload interface. fix that.
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Make sure we only parse the received TCP options only once. Store
the options to tcp conn struct for later use.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This patch fixes an issue with TCP options reading. Previous approach
was accessing the options with pointers (th + 1). This does not work if
TCP options span multiple net_pkt buffer fragments. Instead net_pkt
functions must be used.
Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
During registration, first thing LWM2M does is trying to close a socket
indicated by sock_fd stored in its context. In case it is not
initialized to some invalid value (-1 in this case), LWM2M may close an
ambigous socket.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In order to avoid retransmissions from the peer's side
on active connection close, acknowledge the incoming FIN+ACK
in FIN_WAIT_1 state.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
We cannot directly use the local address in net_context when
registering the connection as it is not proper type. So create
temp address variable for that purposes.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Avoid dynamic allocations and all the issues if we run out of
memory, by placing the connection endpoint directly to TCP
connection struct.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Bug fix and improved `payload` handling in `http_client_req`.
Changes to `http_client_req` behaviour:
If the user provides `payload_len` it is used to generate the
`Content-Length` header. This is done even if `payload_cb` is used to
provide the actual data. If no `payload_len` is specified then no
`Content-Length` is generated.
If `payload_cb` is provided it is called to send the payload data.
Otherwise `payload` is used as the payload buffer and sent. If
`payload_len` is not zero, it is used as the size of `payload`.
Otherwise `payload` is assumed to be a string and `strlen` is used to
determine its size. This is to maintain current behaviour and not break
existing samples.
Fixes#24431
Signed-off-by: Arvin Farahmand <arvinf@ip-logix.com>
In tcp_endpoint_cmd() we allocate and then almost immediately
destroy the allocated endpoint. This is quite inefficient so
use a endpoint from stack in the compare.
Separate endpoint allocation from value setting so the caller
can decide how the endpoint union values are set.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Cell ID resource was not initialized properly in the Connectivity
Monitoring object, making it unusable from the application.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Some other part of Zephyr has similar defines (SRC)
causing build failures.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Assigning the allocated IPv4 endpoint as struct sockaddr
leads to the memory overwrite, assign the correct structure,
i.e. struct sockaddr_in.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
There was no way to use Openthread CoAP api in zephyr application so
far. These changes enable the feature. Now you can fully use CoAP
communication in an application working in Thread network.
Signed-off-by: Lukasz Maciejonczyk <Lukasz.Maciejonczyk@nordicsemi.no>
Set information about Frame Pending Bit from the ACK response in the
frame passed to OpenThread.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In order to implement active connection close with the
TIME_WAIT state, send FIN and enter FIN_WAIT_1 state.
We actually send FIN+ACK as most of the implementations do.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to support TIME_WAIT state during the TCP connection
termination, add a TIME_WAIT timer and the corresponding state.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to improve readability, rename TCP_FIN_WAIT
states into TCP_FIN_WAIT_1, TCP_FIN_WAIT_2.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Replace CONFIG_ENTROPY_NAME with DT_CHOSEN_ZEPHYR_ENTROPY_LABEL. We now
set zephyr,entropy in the chosen node of the device tree to the entropy
device.
This allows us to remove CONFIG_ENTROPY_NAME from dts_fixup.h. Also
remove any other stale ENTROPY related defines in dts_fixup.h files.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Fill the mTimestamp filed in OpenThread frame based on the net_pkt
timestamp value (only if NET_PKT_TIMESTAMP is enabled).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This change is to allow access to the firmware block context in order to
give the firmware update callback implementation an indication of when
to reset the flash context. Additionally, it allows for a validity check
between the total expected size downloaded and the actual size
downloaded. A simple implementation can check if the block context's
current downloaded blocks is equal to the expected block size in order
to determine if the flash context needs to be reset. This approach
seemed the simplest, and knowing the firmware block context can have
other purposes. This has been tested by accessing the block context
during the update in the block received callback and confirming that the
callback had information regarding the current downloaded bytes.
Fixes#16122
Signed-off-by: Kyle Sun <yaomon18@yahoo.com>
Received frames shall be handled in the OpenThread thread, not in
the receiver thread.
Passed received frame to the function that will handle it in a proper
thread instead of calling otPlatRadioReceiveDone directly.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
OpenThread received frame handling shall be done in the OpenThread
thread.
Created API to pass net packets to the proper thread and handle them
there.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
The time parameter cannot be K_NO_DELAY because the time delay
parameter is ms so using value 0 instead.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The net_context API will change, the s32_t timeout parameter
will be changed to k_timeout_t. All the Zephyr users of this API will
be changed in subsequent commits. This is internal Zephyr API only,
so the API is not deprecated etc.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Mention in websocket API documentation that the timeout value
is in milliseconds. Check timeout values properly using K_TIMEOUT_EQ()
macro.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use k_timeout_t internally, no change to user API.
Clarify the documentation of the timeout parameter that it is
in milliseconds.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use 64-bit time in order to avoid overlaps, and do not use K_MSEC()
as that will convert to k_timeout_t which we do not want in this
case.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
OpenThread uses "tx started" notification to start ACK
timeout if the driver does not support it.
In order for this to be achieved tx task needs to run in parallel
to the OpenThread task, otherwise it may delay the gap between
cca and tx or run after transmission has already finished.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
The function calculates the number of octets put, but does not return
it. Call sites check for non-zero values suggesting this is a bug.
See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 12.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Use the size of the target buffer as the maximum length when
formatting with snprintf.
See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 3.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This patch enables handling of a single octet of option-kind at the end
of the option list (EOL). Also, add functionality to drop a segment with
an invalid single octet option-kind at the EOL.
Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
The net_buf subsystem is now fully compatible with the new timeout
API, so move the selection of the legacy API to those specific
subsystems that use net_buf and still need converting.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This patch updates the net_buf API to use k_timeout_t in essentially
all places where "s32_t timeout" was previously used. For the most
part the conversion is trivial, except for the places where
intermediate decrements of remaining timeout is needed. For this the
z_timeout_end_calc() API is used.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Use existing network stack calls to create net pkt,
ip header and udp header creation. Also simplify
finalize api calls.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Use existing network stack calls to create net pkt,
ip header and tcp header creation. Also simplify
finalize api calls.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
net_context local sin/sin6 addresses are used only
when input src is not available. So ASSERT should
be inside if block.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
In case hardware CSMA CA is used, ieee802154 L2 does not initialize ACK
processing structures, as it does not need to process ACK messages. As
it is not possible to conditionally disable ACK reporting to the upper
layer, ieee802154 could end up using uninitialized kernel primitive
(semaphore) in the ACK handler, which lead to a crash.
Avoid this, by explicitly checking in the ACK handler, if HW CSMA CA is
used.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Even though radio driver can report in its capabilities that it does
support CSMA CA, there's no way in the driver to select how the frame
should be transmitted (with CSMA or without). As layers above radio
driver (Thread, Zigbee) can expect that both TX modes are available, we
need to extend the API to allow either of these modes.
This commits extends the API `tx` function with an extra parameter,
`ieee802154_tx_mode`, which informs the driver how the packet should be
transmitted. Currently, the following modes are specified:
* direct (regular tx, no cca, just how it worked so far),
* CCA before transmission,
* CSMA CA before transmission,
* delayed TX,
* delayed TX with CCA
Assume that radios that reported CSMA CA capability transmit in CSMA CA
mode by default, all others will support direct mode.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Implemented blocking OpenThread otPlatRadioGetRssi api function using
no-blocking energy scan function from radio driver api interface.
Signed-off-by: Tomasz Konieczny <tomasz.konieczny@nordicsemi.no>
Counting how many times it went suspended, for how long on the last one
and on overage.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
End option indicates the end of the option list. Hence, correct way to
handle it is to break out of the option parsing routine.
Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
k_sleep() now takes a k_timeout_t so an integer value needs to be
wrapped through the appropriate macro, in this case K_SECONDS().
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Verify that `ed_scan` is implemented by the radio driver before use. In
case it's not, return appropriate error code to OpenThread.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
According to RFC 793 and IANA "TCP Option Kind Numbers" an option with
kind 0 is an End of Option List option and not a PAD.
Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument. Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created. This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.
The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.
The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.
Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.
For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided. When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.
Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions. These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig. These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.
k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.
Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate. Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure. But k_poll() does not fail
spuriously, so the loop was removed.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Deprecate BT_LE_ADV defines in hci.h that are expected to be used by the
application in the scan received callback to identify the advertising
PDU type. These defines are mixing HCI input parameters and advertising
PDU types. Internally it is acceptable to mix these, but at the API we
should to mix in them.
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Deprecate bt_create_conn_le and rename it to in order to add return
code, new arguments and to follow the established naming convention.
Add API for the application to control the scan parameters of the
initiator role. This allows the application more scheduling control
of the initiator in multi-role scenarios. Also provides options to
configure the initiator for LE Coded PHY for long range support.
We deprecate the old way of creating connection to make the name more
consistent with the rest of the API.
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Identify when received PUBLISH message is malformed and overall packet
length received is smaller than parsed variable header lenght.
Add unit test to cover this case.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Verify more strictly that data read from the transport fits into RX
buffer. Switch to unsigned integers, where possible, to prevent
unnecessary signed/unsigned operations.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The standard allows up to 4 bytes of packet length data, while current
implementation parsed up to 5 bytes.
Add additional unit test, which verifies that error is reported in case
of invalid packet length.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Such state needs to be set _from_ the PM API functions and not the other
way round. So if a network device driver does not support such API, it
will not be able to set the core net_if on PM state, obviously.
Currently, these functions only set/unset NET_IF_SUSPENDED flag.
More logic will be added later, to decide whether the net_if can be
actually set to suspend mode or not and also to take care of all timers
related to the interface.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This function can be used for example by network power management
to check if the network interface can be suspended or not.
If there are network packets in transmit queue, then the network
interface cannot be suspended yet.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We need to know whether the net_pkt was successfully placed
to transmit queue. It is possible in TX side, that the net_pkt
is already in TX queue when for example TCP packet is
re-transmitted, in which case the queue submit will fail.
This cannot happen in RX side as there are no timers involved.
It is required to check about such pending flag before trying to submit
it into the queue. Indeed, the work queue could be scheduled right after
such queuing, thus checking for the pending flag afterwards would
provide a false information.
It is unfortunate k_work_submit_to_queue() does not return anything as
it would simplify the code then.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
In case OPENTHREAD_NCP option is disabled, uart.c platform driver should
not be compiled as it misses dependencies.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When NCP starts-up some of the initialisation functions of a regular
OpenThread device do not need to be called, because they get triggered
by wpantund via UART. Instead NCP initialisation needs to be called.
A small typo has been fixed as well.
Also initialisation for raw link packet interface has been added. Can be
used for picking up 802.15.4 frames and interpreting them in the
application.
Signed-off-by: Markus Becker <markus.becker@tridonic.com>
The functions ppp_mgmt_raise_carrier_on/off_event() were not
implemented, but already documeted in the header net/ppp.h
Fixes#23420
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
This reverts commit 8739517107.
Pull Request #23437 was merged by mistake with an invalid manifest.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
ieee802154_scan() checks if ctx->scan_ctx (scan) is NULL what implies
that this can be true, but de-reference this variable before this
check what may cause a problem.
Fixes#23299 [3]
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
If the network interface is down, we should timeout properly
and let the application to handle the situation.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
It is possible that net_pkt will disappear while we are sending
it, so save link address if we need that information.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If we are receiving UDP packet and if there is some error happening
inside zsock_recv_dgram(), then make sure that the net_pkt received
from recv_q is freed.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The code was leaking memory in TX side when there was lot of
incoming packets. The reason was that the net_pkt_sent() flag
was manipulated in two threads which caused races. The solution
is to move the sent flag check only to tcp.c.
Fixes#23246
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The current design of the network-specific stack dumping APIs
is fundamentally unsafe. You cannot properly dump stack data
without information which is only available in the thread object.
In addition, this infrastructure is unnecessary. There is already
a core shell command which dumps stack information for all
active threads.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Contents of mqtt_3_1_0_proto_desc and mqtt_3_1_1_proto_desc were logged
with following code:
MQTT_TRC("Encoding Protocol Description. Str:%s Size:%08x.",
mqtt_proto_desc->utf8, mqtt_proto_desc->size);
This resulted in invalid log, since they were not NULL-terminated
strings. Use MQTT_UTF8_LITERAL() to initialize both utf8 strings to make
sure they are NULL-terminated now and valid to print and
log. Additionally this makes the code a bit shorter.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
There are scenarios where there is a NAT firewall in between MQTT
client and server. In such case, the NAT TCP timeout may be shorter
than MQTT keepalive timeout and TCP timeout. The the MQTT ping
request message is dropped by the NAT firewall, so that it cannot be
received by the server, resulting in void MQTT ping response message.
There is no TCP FIN or RST at all. The application looks hang-up
until TCP timeout happens on the client side, which may take too
long.
Therefore, the event MQTT_EVT_PINGRESP is added to inform the
application that the route between client and server is still valid.
Signed-off-by: PK Chan <pak.kee.chan@nordicsemi.no>
This commit updates the the IPv4 ping command to handle the ENETUNREACH
error number returned by `net_icmpv4_send_echo_request` function when
IPv4 is unavailable.
The `net_icmpv4_send_echo_request` function previously returned EINVAL
when IPv4 is unavailable and this caused the shell command to report
"Invalid IP address" even when the provided IP address is correct; this
problem was corrected by returning ENETUNREACH instead of EINVAL in the
aforementioned function.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
net_icmpv4_send_echo_request currently returns EINVAL (invalid
argument) when IPv4 is unavailable.
Since the availability of IPv4 has nothing to do with the arguments
provided to this function and the meaning of EINVAL in this case is
ambiguous, return the ENETUNREACH (network is unreachable) error
number instead.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
The TCP connection might be concurrently modified from the
TR/TX threads, so add a mutex to protect from the concurrent
modification.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
After removing the test windows, update test protocol
functions for the TTCN-3 sanity check.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
These test receive windows were used by TTCN-3 sanity check,
but it's possible to do without them.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to drop dependency on a heap, drop the
test send window.
Use net_tcp_queue_data() to receive the outgoing data
from the socket layer.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to drop dependency on a heap, drop the test
receive window.
The receive window was needed for TTCN-3 sanity check,
but it's possible to do without it.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
On incoming SYN+ACK, use the existing TCP connection.
This problem was overlooked earlier and was found while
testing TCP2 client side.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In SYN_SENT check the ack number of the incoming TCP message
against our sequence number.
This problem was overlooked earlier and was found while
testing TCP2 client side.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Don't erroneously instantiate an extra TCP connection
on TCP connect.
This problem was overlooked earlier and found while testing
TCP2 client side.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
k_timer callback is executed from ISR context, which isn't
currenty compatible with Zephyr's shell implementation.
This problem was found while testing TCP2 client side.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to support TTCN-3 based TCP2 sanity check,
register test inputs with net_conn_register() and adjust
test functions to account for this.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to support IPv4/IPv6, work with packet through
net_pkt_ip_hdr_len(), net_pkt_ip_opts_len() which account
for IPv4/IPv6, IPv4 options and IPv6 extension headers.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Remove temporary interception of TCP, UDP for TTCN-3 based
TCP2 sanity check.
As a part of adding IPv6 support, TCP2 will register test
callbacks/inputs with net_conn_register().
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Allocate tcp2.c endpoints before storing port numbers or addresses.
Select the IPv4 source address since net_context_create_ipv4_new()
is not currently called on packet output.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
NET_OFFLOAD interfaces do not handle ICMP request. Request to send ICMP
packet resulted in NULL pointer dereference in net_if_tx() later
on. Prevent that by detecting NET_OFFLOAD interfaces early in icmpv4
module.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
OpenThread has api to make use of radios energy scan feature.
Implemented this api in zephyr. This allows thread to perform energy
scan when needed.
Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
If the system has more than one network interface, then it should
be possible to bind a AF_PACKET socket to each interface if the
network interface index is set when bind() is called. This was
not possible earlier as the code was always using default network
interface with AF_PACKET socket bind().
Fixes#23153
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
According to LWM2M specification, when Queue Mode is used, the LWM2M
client should keep the reciever on for specified time after sending A
CoAP message. This commit adds a new LWM2M event,
`LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF`, to facilitate the process by
notifying the application when it's safe to turn the receiver off.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add Kconfig option to enable Queue Mode binding. With this option
enabled, the LWM2M client will register with `UQ` binding, instead of
`U`.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Calculate length based on provided SSID string, so user does not have to
provide length explicitly over shell.
This patch also removes requirement of minimum 3 characters SSID, as
the shortest SSID can be even 1 character.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Older OT code used preprocessor #if conditionals, while newer code
used IS_ENABLED macro. Unify the approach by switching to the latter
option.
Additinally, fix inclusion issue that came out after switching to
IS_ENABLED.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add new transport handler for MQTT, with sendmsg-like functionality.
This allows TCP transport to send PUBLISH packets w/o fragmentation at
the TCP layer. Implement this new functionality for all existing
transports.
Fixes#22679
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
`mqtt_transport_write` failue was logged with `errno` value which is not
correct as the return value from the function is valid in this case.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This option specifies the name of the client.
See https://tools.ietf.org/html/rfc2132#section-3.14
This is useful for identification when looking in DHCP lease table.
Signed-off-by: Luuk Bosma <l.bosma@interay.com>
We now negotiate DNS servers in the IPCP configuration. This has been
observed to speed up the connection setup. The received DNS servers
are used by the DNS resolver library, but we leave it optional since
the static server list might be preferable.
Increase MAX_IPCP_OPTIONS to 4 so that we can nack all RFC 1877
options.
Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
It is not unusual that the peer does not provide an IP address in the
ipcp negotiation. But because ppp is a peer-to-peer protocol, we do
not actually need to know the peer's address to use the network.
Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
TLS sockets did not increase refcount of a net_context running TCP,
which could lead to a crash upon TCP disconnection.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
opts_len renamed to total_opts_len in previous changes.
But it's not replaced at one place.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
If IPv4 header options has wrong options length
(e.g. options length is more that actual data),
then parser decrements opts_len without checking
actual data length. Which crashes the network stack.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Store the time difference value in u32_t variable than
abs() value in signed variable.
Fixes#22912
Coverity CID: 208406
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
net_pkt_clone() initializes the original packet cursor
and clone the packet. But it doesn't restore the cursor
back to original position.
Issue noticed when mDNS resolving fails when mdns responder
is also enabled.
net_conn_input(), in case of multicast packet, connection
handler clone the packet and deliver to matching handler.
Example case: dns_resolver and mdns_responder both register
handlers for 5353 port. After first clone original packet
cursor moved back to starting position. But first cloned
packet cursor is set properly. Second time cloning makes
cursor position to set to zero. Which makes second packet
handler header unpacking goes wrong.
Fixes#21970.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Same deal as in commit eddd98f811 ("kconfig: Replace some single-symbol
'if's with 'depends on'"), for the remaining cases outside defconfig
files. See that commit for an explanation.
Will do the defconfigs separately in case there are any complaints
there.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
If nack_idx > 0, then the count_rej must be > 0. This means that
the "code" variable will never be set to PPP_CONFIGURE_NACK.
Fixes#22436
Coverity-CID: 207975
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If CONFIG_NET_PKT_RXTIME_STATS is set, then update the received
packet RX time for packet sockets (SOCK_RAW). This was already
working for normal sockets but the statistics update was missing
from SOCK_RAW.
Fixes#22489
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
commit e3dc05f14d ("net: config: Wait network interface to come up")
introduced check_interface() function, which accidentally has 2
different signatures depending on CONFIG_NET_NATIVE selection.
Let's fix the second signature to be correct.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/22693
Signed-off-by: Michael Scott <mike@foundries.io>
The zsock_accept_ctx() calls z_reserve_fd() on entry but fails
to call z_free_fd() on failure. This will leak the allocated
socket descriptor.
Fixes#22366
Signed-off-by: Inbar Anson Bratspiess <inbar.anson.bratspiess@330plus.net>
I think people might be reading differences into 'if' and 'depends on'
that aren't there, like maybe 'if' being needed to "hide" a symbol,
while 'depends on' just adds a dependency.
There are no differences between 'if' and 'depends on'. 'if' is just a
shorthand for 'depends on'. They work the same when it comes to creating
implicit menus too.
The way symbols get "hidden" is through their dependencies not being
satisfied ('if'/'depends on' get copied up as a dependency on the
prompt).
Since 'if' and 'depends on' are the same, an 'if' with just a single
symbol in it can be replaced with a 'depends on'. IMO, it's best to
avoid 'if' there as a style choice too, because it confuses people into
thinking there's deep Kconfig magic going on that requires 'if'.
Going for 'depends on' can also remove some nested 'if's, which
generates nicer symbol information and docs, because nested 'if's really
are so simple/dumb that they just add the dependencies from both 'if's
to all symbols within.
Replace a bunch of single-symbol 'if's with 'depends on' to despam the
Kconfig files a bit and make it clearer how things work. Also do some
other minor related dependency refactoring.
The replacement isn't complete. Will fix up the rest later. Splitting it
a bit to make it more manageable.
(Everything above is true for choices, menus, and comments as well.)
Detected by tweaking the Kconfiglib parsing code. It's impossible to
detect after parsing, because 'if' turns into 'depends on'.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
When is NET_SOCKETS_SOCKOPT_TLS set, it should set TLS_CREDENTIALS
even when NET_NATIVE=n, so that platforms that use socket offloading
can continue to set TLS credentials.
We are now setting this via 'imply' instead of 'select', so that
prj.conf can opt out if necessary.
Fixes#22390
Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
Instead of using a custom offloading interface, users can use
`NET_SOCKET_REGISTER` macro to register custom socket API provider. This
solution removes a limitation, that only one offloaded interface can be
registered and that it cannot be used together with native IP stack.
The only exception remainig are DNS releated operations -
`getaddrinfo`/`freeaddrinfo`, which, when offloaded, have to be
registered specifically.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Sort out mbedTLS dependencies in sockets Kconfig. mbedTLS will now
be enabled when TLS sockets and native network stack are enabled.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Each network interface needs to have IPv6 link local address.
The ll address was not set to VLAN interfaces which then caused
some of the IPv6 neighbors to be in wrong state (INCOMPLETE) in
neighbor cache.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
When we are about to send a NS, we should not use the destination
address as that is typically the multicast address. We should use
the target address instead.
This fixes the case where a neighbor is in incomplete state, and
we send a neighbor solicitation to find out whether the neighbor
is reachable. In this case the destination address is the solicited
node multicast address which is no use when trying to figure out
the source address.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit fixes a problem where our own IP address
is added to the cache instead of the senders.
This bug was due to a swap of the address in the original packet.
The swapping of the address is now removed.
Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
Users of mqtt_live() have no idea when it actually sends a ping.
As a result it's very hard to know when to use mqtt_input() to
process the incoming PINGACK.
Instead of returning a 0 result when a ping isn't generated in
mqtt_live(), let's return -EAGAIN.
Signed-off-by: Michael Scott <mike@foundries.io>
Make sure that if we receive websocket data in small chunks,
the parsing and returning of data to caller is done properly.
Fixes#21989
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Store the IPv4 address into the local LCP options and set it
as the interface IP address once IPCP negotiation is complete.
Fix calling the correct function when an IPCP Configure Reject
is received carrying our local IP address.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
The MQTT connection is closed in case an mqtt_ping fails anyway, so
it's better to let the application know early that something went
wrong.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As mDNS requests set DNS id to 0, we cannot use it to match
the DNS response packet. In order to allow this functionality,
create a hash from query name and type, and use that together
with DNS id to match request and response.
Fixes#21914
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
A neighbor solicitation packet for an address that is not ours should
not cause the sender to be added to the neighbor cache. See RFC 4861
section 7.2.3.
Add the neighbor to the cache when we have decided to respond to the
NS packet.
Fixes#21869.
Signed-off-by: Jonas Norling <jonas.norling@greeneggs.se>
Use the same code when parsing source link-layer address option for
both RA and NS packets. It looked like handle_ns_neighbor() could
actually read too much data into lladdr.addr when handling 8-byte
addresses (802.15.4).
Signed-off-by: Jonas Norling <jonas.norling@greeneggs.se>
Make ioctl handlers of `ZFD_IOCTL_POLL_PREPARE` and
`ZFD_IOCTL_POLL_UPDATE` return an error code instead of setting errno
variable.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
A memory corruption could happen in `uncompress_IPHC_header` function,
when data was moved to make place in the net buffer for the uncompressed
IPv6/UDP header.
The size of data being moved should only contain the original data size,
not incremented by the amount of space needed to expand the header,
which was already added to the net buffer size. In result, the `memmove`
operation could exceed the allocated net buffer and cause memory
corruption.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If no other route is found, the network interface prefixes are
evaluated. If a matching interface is found, the packet is sent out on
this interface.
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
The address family of the received packet must be set, before routing
it. E.g. the ethernet driver would drop the packet if this is not
done.
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
Add function that returns remaining time until next keep alive message
shall be sent. Such function could be used for instance as a source
for `poll` timeout.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
generated_dts_board.h is pretty redundant and confusing as a name. Call
it devicetree.h instead.
dts.h would be another option, but DTS stands for "devicetree source"
and is the source code format, so it's a bit confusing too.
The replacement was done by grepping for 'generated_dts_board' and
'GENERATED_DTS_BOARD'.
Two build diagram and input-output SVG files were updated as well, along
with misc. documentation.
hal_ti, mcuboot, and ci-tools updates are included too, in the west.yml
update.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The transition from LISTEN to SYN_SENT nullifies the th,
guard on th being NULL in SYN_SENT.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In case the final ACK for the connection establishment arrives
out of order, evaluate the sequence number in SYN_RECEIVED,
so the data packet isn't false identified as a final ACK.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to simplify the evaluation of the incoming data,
add len and evaluate the data for the incoming packet once.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Create a new connection only for the SYN packet,
otherwise pass a packet into existing connection.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
The initial logic with this check is too restrictive,
do not bail-out on unconsumed flags.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Add a diagnostic information on network buffer sizes
and the total length of the packet.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Set the net_context to NET_CONTEXT_CONNECTED state only once
in transitions to TCP_ESTABLISHED.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
1. Reduce the internal buffer
2. Eliminate extra string pointer
3. Add a comment on deleting the last comma
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
In order to avoid naming collision with tcp_recv(),
rename tcp_recv() into tp_tcp_recv().
This function is used by the test protocol.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
After sending the MQTT disconnect message, no response is expected,
therefore it makes little sense to delay the socket closure.
So far it was expected to call `mqtt_input` function after calling
`mqtt_disconnect` in order to close the socket, which is
counter-intuitive. Simplify this, by closing the socket rightaway
in the `mqtt_disconnect` function.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
OpenThread settings implementation built on top of Zepyhr settings
submodule.
With this solution, OpenThread settings are identified with keys of
the following format: `ot/id/instance`, where `id` is assigned by
OpenThread stack, and `instance` is a 32-bit random number, both in
hex. The implementation makes use of `settings_load_subtree_direct`
function to iterate over settings instances. This allows the
OpenThread settings layer to be a fully transparent shim layer between
OpenThread/Zephyr APIs.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Remove net bufs own assertion mechanism and use the system assert
instead. This changes the assertion messaged printed from printing
expression to printing the line and file name. This provides more
context as the same expression could be asserted upon multiple times and
would then not provide enough clarity in the message.
This removes the option to enable only net buf assertions.
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Drop snprintf() and use snprintk() as snprintk()
is more suitable for the networking code.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
NET_BUF_ASSERT() tranlates into nothing in presence
of CONFIG_ASSERT=y, which is misleading.
Use __ASSERT() in NET_BUF_ASSERT().
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
No packet was previously sent, because net_pkt_set_ppp(pkt, true) was
not called on the outgoing packet. Also the received protocol instead of
LCP was used, which was incorrectly interpreted by remote peer.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Received net_pkt is always discarded in ppp_recv() if we return
NET_OK. Don't do this in ppp_fsm_recv_discard_req().
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
When iterating though configuration options it is possible that we will
fail to add data to nack_buf and hence unref it in error handling
path. Just after that we will unref buf, which has nack_buf in its
buffer chain.
Drop code unrefing nack_buf and just go directly to unrefing buf.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
There is no possibility right now that 'nack == NULL' and 'nack_buf !=
NULL', so drop code path for that case.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
If we can write to the socket in POLLOUT, then there is no need to
wait.
Note that this is not a full POLLOUT implementation but prevents
the code from waiting even if we could send data out.
Fixes#18867
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Same deal as in commit 41713244b3 ("kconfig: Remove '# Hidden' comments
on promptless symbols"). I forgot to do a case-insensitive search.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Make the channel ops struct const since there really isn't anything
there that needs to change at runtime. The only exception is the L2CAP
shell which was playing with the recv callback, however that can be
fixed by introducing a simple bool variable.
With tests/bluetooth/shell this reduces RAM consumption by 112 bytes
while adding only 16 bytes to flash consumption.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Maintain a simple count of how many PINGREQ have been sent for the
current connection that have not had a corresponding PINGRESP. Nothing
is done with this information internal to the MQTT driver, but it is
exposed to the application layer to monitor as desired.
Signed-off-by: Justin Brzozoski <justin.brzozoski@signal-fire.com>
The commit 8892406c1d ("kernel/sys_clock.h: Deprecate and convert
uses of old conversions") changed code to not use deprecated macro.
Unfortunately there was some changes done to RX TC stats update that
were missing from that commit. This commit fixes the issue and removes
the last user of the deprecated SYS_CLOCK_HW_CYCLES_TO_NS64() macro.
This is follow up to commit 5bbdf56769 ("net: stats: Fix RX time
statistics update") which failed to remove all users of the deprecated
macro.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Based on work by Michael Scott.
Add a new Kconfig knob, CONFIG_LWM2M_IPSO_TIMESTAMP_EXTENSIONS. This
defaults to n. When enabled, various IPSO objects will by default have
the timestamp resource (5518) added to their representations. This can
be turned off on a per-object basis.
The idea of adding timestamp resources was originally suggested by
Hannes Tschofenig on this OMA page:
https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues/429
Signed-off-by: Michael Scott <mike@foundries.io>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The commit 8892406c1d ("kernel/sys_clock.h: Deprecate and convert
uses of old conversions") changed code to not use deprecated macro.
Unfortunately there was some changes done to RX stats update that were
missing from that commit. This commit fixes the issue and removes use
of the deprecated SYS_CLOCK_HW_CYCLES_TO_NS64() macro.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Follwing the convention in Zephyr, all CMake configuration related to
a module, should be placed within the module repostiory.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Timestamp and RecordRoute options are supported
in only ICMPv4 EchoRequest call as per
RFC 1122 3.2.2.6.
Fixes#14668
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
IPv4 header options length will be stored in ipv4_opts_len
in net_pkt structure. Now IPv4 header length will be in
net_pkt ip_hdr_len + ipv4_opts_len. So modified relevant
places of ip header length calculation for IPv4.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
OpenThread recently introduced CMake build system into its repostiory
so we no longer need autotools to build OpenThread libraries and can
integrate them natively.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The TCP code expects that we know when the socket has called accept()
in order to continue connection attempt.
Fixes#21335
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Packets shall never fail to be sent now that they are queued, so if an
error occured there is no point in keep the channel connected.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Functions like `setup_ipv4` or `setup_ipv6` might already use the
`counter` semaphore, therefore it should be initialized before these
functions are called.
As a result of this issue, the network stack could stall until timeout
under certain circumstances (e.g. when OpenThread was used).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
An expired IPv6 router would cause an infinite loop where
iface_router_run_timer() repeatedly scheduled a work item. In some
conditions it would schedule with negative delay, in other conditions
the infinite loop wouldn't happen until a router was added again.
Get rid of the router from active_router_timers when it is removed.
Fixes#21339
Signed-off-by: Jonas Norling <jonas.norling@greeneggs.se>
Without this fix is it not possible to terminate pppd and restart
pppd afterwards without restarting the firmware, too.
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
Without this fix is it not possible to terminate pppd and restart
pppd afterwards without restarting the firmware, too.
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
Remove leading/trailing blank lines in .c, .h, .py, .rst, .yml, and
.yaml files.
Will avoid failures with the new CI test in
https://github.com/zephyrproject-rtos/ci-tools/pull/112, though it only
checks changed files.
Move the 'target-notes' target in boards/xtensa/odroid_go/doc/index.rst
to get rid of the trailing blank line there. It was probably misplaced.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This adds net_bug_simple_init_with_data which can be used to initialize
a net_buf_simple pointer with an external data pointer.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Before we try to set IP addresses to the network interface,
make sure that the interface is up.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Allow to select Sleepy End Device, and configure it during OpenThread
initialization.
According to Thread Specification, Sleepy End Devices should always
attach to the network as SED, to indicate increased buffer requirement
to a parent. Therefore, we reconfigure the Link Mode on each boot.
Note, that Poll Period value is not stored in the persistent storage,
hence we also need to initialize it on each boot.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
OpenThread radio layer did not implement `ieee802154_radio_handle_ack`
API and provided fake ACK frame to the OpenThread.
This prevented proper Sleepy End Device operation, as it expects to
receive information in the ACK whether it should wait for more data to
come or should it put the radio to sleep.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
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.
Also replace some
config
prompt "foo"
bool/int
with the more common shorthand
config
bool/int "foo"
See the 'Style recommendations and shorthands' section in
https://docs.zephyrproject.org/latest/guides/kconfig/index.html.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The time difference calculation did not check if the result
value would be < 0 which means really large value when converted
to unsigned.
Fixes#20100
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
For 32-bit architecture Bluetooth only requires 4 bytes for the user
data. There are places that store a pointer in it, so we need to make
an exception for 64-bit architecture. The code contains relevant build
asserts, so it's sufficient to set a conditional default in Kconfig
but let the range definition be simpler (unconditional).
Also simplify & fix the conditional defaults & ranges. E.g. separately
mentioning X86_64 is redundant since that option explicitly selects
the 64BIT option.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Add an implementation for `sendmsg`, so secure sockets can be used
together with the WebSocket module to implement secure WebSockets
("wss").
Fixes#20431
Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
This commit adds a NULL pointer check for the destination
context pointer. The pointer is NULL in case the context
does not exist.
Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
Setting it to UINT32_MAX, as it is subsequently overwritten with
MIN(oldest, something_else).
Signed-off-by: Piotr Zierhoffer <pzierhoffer@antmicro.com>
Mark the old time conversion APIs deprecated, leave compatibility
macros in place, and replace all usage with the new API.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit refactors kernel and arch headers to establish a boundary
between private and public interface headers.
The refactoring strategy used in this commit is detailed in the issue
This commit introduces the following major changes:
1. Establish a clear boundary between private and public headers by
removing "kernel/include" and "arch/*/include" from the global
include paths. Ideally, only kernel/ and arch/*/ source files should
reference the headers in these directories. If these headers must be
used by a component, these include paths shall be manually added to
the CMakeLists.txt file of the component. This is intended to
discourage applications from including private kernel and arch
headers either knowingly and unknowingly.
- kernel/include/ (PRIVATE)
This directory contains the private headers that provide private
kernel definitions which should not be visible outside the kernel
and arch source code. All public kernel definitions must be added
to an appropriate header located under include/.
- arch/*/include/ (PRIVATE)
This directory contains the private headers that provide private
architecture-specific definitions which should not be visible
outside the arch and kernel source code. All public architecture-
specific definitions must be added to an appropriate header located
under include/arch/*/.
- include/ AND include/sys/ (PUBLIC)
This directory contains the public headers that provide public
kernel definitions which can be referenced by both kernel and
application code.
- include/arch/*/ (PUBLIC)
This directory contains the public headers that provide public
architecture-specific definitions which can be referenced by both
kernel and application code.
2. Split arch_interface.h into "kernel-to-arch interface" and "public
arch interface" divisions.
- kernel/include/kernel_arch_interface.h
* provides private "kernel-to-arch interface" definition.
* includes arch/*/include/kernel_arch_func.h to ensure that the
interface function implementations are always available.
* includes sys/arch_interface.h so that public arch interface
definitions are automatically included when including this file.
- arch/*/include/kernel_arch_func.h
* provides architecture-specific "kernel-to-arch interface"
implementation.
* only the functions that will be used in kernel and arch source
files are defined here.
- include/sys/arch_interface.h
* provides "public arch interface" definition.
* includes include/arch/arch_inlines.h to ensure that the
architecture-specific public inline interface function
implementations are always available.
- include/arch/arch_inlines.h
* includes architecture-specific arch_inlines.h in
include/arch/*/arch_inline.h.
- include/arch/*/arch_inline.h
* provides architecture-specific "public arch interface" inline
function implementation.
* supersedes include/sys/arch_inline.h.
3. Refactor kernel and the existing architecture implementations.
- Remove circular dependency of kernel and arch headers. The
following general rules should be observed:
* Never include any private headers from public headers
* Never include kernel_internal.h in kernel_arch_data.h
* Always include kernel_arch_data.h from kernel_arch_func.h
* Never include kernel.h from kernel_struct.h either directly or
indirectly. Only add the kernel structures that must be referenced
from public arch headers in this file.
- Relocate syscall_handler.h to include/ so it can be used in the
public code. This is necessary because many user-mode public codes
reference the functions defined in this header.
- Relocate kernel_arch_thread.h to include/arch/*/thread.h. This is
necessary to provide architecture-specific thread definition for
'struct k_thread' in kernel.h.
- Remove any private header dependencies from public headers using
the following methods:
* If dependency is not required, simply omit
* If dependency is required,
- Relocate a portion of the required dependencies from the
private header to an appropriate public header OR
- Relocate the required private header to make it public.
This commit supersedes #20047, addresses #19666, and fixes#3056.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
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>
Clean up space errors and use a consistent style throughout the Kconfig
files. This makes reading the Kconfig files more distraction-free, helps
with grepping, and encourages the same style getting copied around
everywhere (meaning another pass hopefully won't be needed).
Go for the most common style:
- Indent properties with a single tab, including for choices.
Properties on choices work exactly the same syntactically as
properties on symbols, so not sure how the no-indentation thing
happened.
- Indent help texts with a tab followed by two spaces
- Put a space between 'config' and the symbol name, not a tab. This
also helps when grepping for definitions.
- Do '# A comment' instead of '#A comment'
I tweaked Kconfiglib a bit to find most of the stuff.
Some help texts were reflowed to 79 columns with 'gq' in Vim as well,
though not all, because I was afraid I'd accidentally mess up
formatting.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Added in commit 106a0f7306 ("net: lib: config: Add SYS_INIT handler to
set clock from SNTP"), never used.
Found with a script.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
In order to avoid net_pkt ref count going to <0, do not unref
the packet if it was not sent in the first place. This can happen
if the connection was closed while we are waiting packets to be sent.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Do not print warning if transitioning from LISTEN -> CLOSED which
happens when the socket is closed.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The initial state from CLOSED -> ESTABLISHED caused error
to be printed by state validator. This is unnecessary, so add
this as a valid state to validator.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Handle this corner case with TCP connection closing:
1) Client A connects, it is accepted and can send data to us
2) Client B connects, the application needs to call accept()
before we will receive any data from client A to the application.
The app has not yet called accept() at this point (for
whatever reason).
3) Client B then disconnects and we receive FIN. The connection
cleanup is a bit tricky as the client is in half-connected state
meaning that the connection is in established state but the
accept_q in socket queue contains still data which needs to be
cleared.
4) Client A then disconnects, all data is sent etc
The above was not working correctly as the system did not handle the
step 3) properly. The client B was accepted in the application even
if the connection was closing.
After this commit, the commit called "net: tcp: Accept connections
only in LISTENING state" and related other commits are no longer
needed and are reverted.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add CONFIG_NET_TCP_AUTO_ACCEPT option which can be used to
automatically accept incoming data connection even if the
application has not yet called accept(). This can speed up
data transfer from peer to the application.
Problem with this is that if the peer sends lot of data and
we have limited amount of net_buf's available, then we can
run out of them which is very bad situation and can lead to
deadlocks. Because of this, the setting is turned off by default.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This reverts commit d70a854904.
The next commit fixes the original issue so this commit is no
longer needed.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
With this feature enabled (via CONFIG_NET_CONFIG_CLOCK_SNTP_INIT), an
application will automagically get correct absolute time via POSIX
functions like time(), gettimeofday(), etc.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Use the newest version of the OpenThread project, as updated in
https://github.com/zephyrproject-rtos/openthread/pull/2.
Introduce the following fixes along with the update (they're squashed to
retain bisectability of OT samples):
* Update configs and flags used
Some OT configs were renamed, some new were introduced that Zephyr port
needs to set.
* Add entropy platform driver
OpenThreads `random` platform subsystem was replaced with `entropy`
subsystem which is supposed to serve as an entropy source for the
generic OpenThread's random generator.
* Halt OT thread when OT command is processed
OpenThread can currently be processed from two threads - a
genuine OpenThread thread and shell thread, which processes CLI
commands. This could cause trouble, when context was switched
during OT command processing (i.e. switched to process an incomming OT
message, while still in unfinished command handler).
In result, it was not possible to turn the commissioner role on via
CLI, as the commissioner petition response was handled before the
Commissioner::Start function finished its execution (if the
petitioner is also the network leader, all messages are passed
internally within the stack).
Fix this by suspending the OT thread for the time of an OT command
processing.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In order to properly remove struct tcp and its data, net_context
needs to be supplied as k_timer user data. Modify net_tcp_unref()
to take a net_context argument when removing, and add ifdefs
around code that after this will only be used by TCP testing
functionality.
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Add a net_context backpointer and receiver user data to the tcp
structure. Once the desired callback and user data is set in
net_tcp_recv(), net_context_packet_received() can be called at
TCP reception in tcp_data_get(), moving the TCP data to the
recipient. IP and TCP protocol headers are sent as NULL, they
are not used by e.g. the socket code.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Since TCP needs to be able to decide how much data is to be sent
in a TCP segment and when the segment needs to be sent, the TCP
data buffer needs to be passed down to the TCP stack. For tcp2
this causes a new function handling the data as a buffer or as an
iov to be implemented and only that function is called when
sending data out via the new TCP stack. net_tcp_send_data() is
invoked as the caller expects to be informed when the data has
been sent.
For the current stack keep the sending functions as is.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Register the TCP connection when accept() and connect() is called.
With the connection registration net_context will have the necessary
callback pointer set up, whereby net_context can call the proper
function when receiving packets for the TCP connecton.
With the new TCP stack this callback is always the same function.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Currently the TCP commands work only for legacy TCP.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
Applications should use setsockopt() to setup the SOCKS5 proxy,
so the old API file, which is using net_context directly, is
moved SOCKS5 directory.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Fix GCC "warning: 'ipv4' defined but not used [-Wunused-variable]" and
"warning: 'ipv6' defined but not used [-Wunused-variable]" when either
IPv4 or IPv6 support is not enabled.
Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
Use sys_put_xyz() helpers instead of memcpy() whenever possible. This
brings in straight-line inline code for pushes and adds of known,
small sizes.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
On processing a DNS server option, which re-initializes the DNS resolve
context, also cancel all pending DNS queries before closing the old DNS
resolve context. Otherwise, `z_clock_announce()` will later work on the
re-initialized context once the queries expire and crash because the
reference to the timeout function `query_timeout()` has been cleared.
Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
Unused after commit a76814bfb6 ("net: Convert core IP stack to use log
levels").
Found with a script.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Use same format string when printing information that certain
config option is not enabled. This saves some flash as the
same string can be shared in the shell.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
LWM2M_FIRMWARE_UPDATE_PULL_LOCAL_PORT is unused since commit 54c10c04e5
("net: lwm2m: use security data for connections").
Found with a script.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Unused since commit d1cb39e7ce ("net: lwm2m: migrate LwM2M library to
BSD-sockets API").
Found with a script.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The earlier code was always queuing the FIN that is sent when
connection is closed. This caused long delay (200 ms) before the peer at
the other end noticed that the connection was actually closed.
Now check if there is nothing in the queue, then send the FIN
immediately. If there is some data in the queue, flush it when a valid
ack has been received.
Fixes#19678
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
With `CONFIG_NET_NATIVE`, offloaded drivers can specify capabilites with
`NET_IPV4/6` configs, so there is no longer need to handle socket
offloading separately.
Also, initialize hints structure with zeros, as according to man pages
unused fields should be set to 0:
`All the other fields in the structure pointed to by hints must contain
either 0 or a NULL pointer, as appropriate.`
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add new config option `LWM2M_DNS_SUPPORT` to the LWM2M library, instead
of relying on `DNS_RESOLVER` which is only compatible with native
network stack. This allows to use DNS with offloaded interfaces
seamlessly.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This is related to commit 1a6f4a6368 ("net: tcp: Accept
connections only in LISTENING state") which made the system
to only accept new connections if the application had called
accept(). Unfortunately the TLS accept was not fixed by that
commit so we were in wrong state when accepting TLS sockets.
This commit fixes that issue.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
A socket-offloaded interface should bypass interface initialization in
the same way as net-offloaded interface does.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This function will be useful in shell when we want to monitor
the amount of bytes transferred and want to clear earlier
statistics.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Print information about how long network packets took from
application to the network device driver.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Calculate how long on average net_pkt has spent on its way from
application to the network device driver. The data is calculated
for all network packets and not just for UDP or TCP ones like in
RX statistics.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Print information about how long network packets took from
network device driver to the application.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Calculate how long on average net_pkt has spent on its way from
network device driver to the application. The data is only
calculated for UDP and TCP network packets.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Send a Echo-Reply to every Echo-Request. This code does not verify
if the ppp stm is in LCP Opened state. See rfc1661 section 5.8.
Signed-off-by: Christian Taedcke <hacking@taedcke.com>
Re-run with updated script to convert integer literal delay arguments
to k_thread_create and K_THREAD_DEFINE to use the standard timeout
macros.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Try to figure out where the ping reply should be sent if there
are multiple network interfaces in the system.
Fixes#19612
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The MQTT transport API functions are already documented in
mqtt_transport.h so need to duplicate them in individual
transport .c file.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
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>
Provides a way to clone a net_buf_simple without altering the state of
the original buffer. The primary usage scenario is for manipulating a
previously allocated PDU inside a buffer without altering the length and
offset of the buffer.
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
create_ipv6_answer() function is behind #define's but get used behind
IS_ENABLED(CONFIG_NET_IPV6), which is not allowed.
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Use the int_literal_to_timeout Coccinelle script to convert literal
integer arguments for kernel API timeout parameters to the standard
timeout value representations.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The main and idle threads, and their associated stacks,
were being referenced in various parts of the kernel
with no central definition. Expose these in kernel_internal.h
and namespace with z_ appropriately.
The main and idle threads were being defined statically,
with another variable exposed to contain their pointer
value. This wastes a bit of memory and isn't accessible
to user threads anyway, just expose the actual thread
objects.
Redundance MAIN_STACK_SIZE and IDLE_STACK_SIZE defines
in init.c removed, just use the Kconfigs they derive
from.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
The callback function has been ignored in z_timeout_init() since the
timer rework in fall 2018. Passing real handlers to it in code is
distracting when they will be overridden by whatever callback is
provided in z_add_timeout().
As this function is an internal API deprecation is not necessary.
Remove the parameter and change all call sites to drop the argument.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Cast a %lld argument to long long int. This is causing warnings on
recent GNU Arm Embedded toolchains, which fail the build with
-Werror=format=.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
* The issue is found in supporting offload module esp8266
* For device like esp8266, it's responsible for tcp/udp handling,
no need of net_tcp related functions
* This commit is only tested for esp8266, no gurantee for other
modules
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
Currently the CONFIG_NET_ROUTING option has limited use as there
would be some entity that populates routing table. Previously it
was RPL that did it but RPL support was removed some time ago.
Fixes#16320
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If we are getting an old net_context, clear the content of it
in order to make sure we do not have old data in it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Do not try to re-use net_context.user_data field as in many places
(like in accept) it is expected to contain pointer to net_context.
Storing the socket flags will corrupt the value. To simplify and
make things less error prone, use socket specific field in net_context
to store the socket flags.
Fixes#19191
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
So far OpenThread compiled it's own, internal copy of mbedTLS library.
This commit changes this behavior by using Zephyr's mbedTLS instance
appropriately configured for OpenThread needs.
Generic mbedTLS config file was used in this case, so that application
can still configure remaining parts of mbedTLS for it's own needs.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The socket flags are stored in void* so we need to use uintptr_t
instead of u32_t when manipulating the flag variable.
Fixes#19181
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We need to make sure that net_pkt_clone() sets cursor correctly.
This cursor position is needed so that we can skip IP header
for incoming packet properly. Not all applications need to know
the cursor position of the cloned packet. Unfortunately we cannot
know that in advance so just set the cursor to correct position in
the cloned packet.
Fixes#19135
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If socket is marked non-blocking, then accept() will return immediately
if there is no one connecting.
Fixes#19103
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
SNTP is UDP-based protocol, and thus not reliable. Previously,
high-level aka "simple" SNTP just issues a single request via
the low-level SNTP API. Instead, send multiple requests, starting
with a small timeout, and exponential backoff, repeated within
timeout specified by user in call to sntp_simple().
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
If we receive a multicast IPv4 or IPv6 packet, then we need to
deliver it to all sockets that have installed a handler for it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Previously, they were tested only with CONFIG_NET_SOCKETS_POSIX_NAMES,
but should also work with POSIX subsys. Achieve this by including POSIX
headers in this case.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
If proto field in socket() call is set to 0, then we should have
a sane default for it that depends on the type of the socket.
Fixes#18873
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The semi-automated API changes weren't checkpatch aware. Fix up
whitespace warnings that snuck into the previous patches. Really this
should be squashed, but that's somewhat difficult given the structure
of the series.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
These calls are buildable on common sanitycheck platforms, but are not
invoked at runtime in any tests accessible to CI. The changes are
mostly mechanical, so the risk is low, but this commit is separated
from the main API change to allow for more careful review.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
If we are returned IPv4 address but the hints says IPv6, then
return error as currently we do not support AI_V4MAPPED addresses.
Same check for IPv6 if we want only IPv4 address.
Fixes#18870
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Issue noticed with following scenario.
1) TCP server is listening for connections but will handle
only one connection at a time (e.g. echo-server sample)
2) Client A connects, and the connection is accepted.
3) Client B connects, instead of denying a connection,
it is "auto" accepted (this is the actual bug) even
if the application has not called accept().
4) After the connection A is closed, the connection B
gets accepted by application but now the closed
connection A will cause confusion in the net-stack
5) This confusion can cause memory leak or double free
in the TCP core.
It is not easy to trigger this issue because it depends
on timing of the connections A & B.
Fixes: #18308
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
If we are closing connection before the connection was established,
then unref the context so that the cleanup is done properly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Allow user to disable native IP stack and use offloaded IP
stack instead. It is also possible to enable both at the same
time if needed.
Fixes#18105
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit adds an explicit inclusion of toolchain.h from
ieee802154_frame.h.
The endianness preprocessor definitions (__BYTE_ORDER__,
__ORDER_LITTLE_ENDIAN__, __ORDER_BIG_ENDIAN__) are used by
ieee802154_frame.h; these being not defined can easily go unnoticed and
cause unexpected behaviours, as detailed in PR #18922.
toolchain.h ensures that these preprocessor definitions are defined and
*must* be included in a file that uses these definitions.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
When using offloaded network, an L2 is never assigned to the net_if.
Only certain portions of the net_if code are referenced such as:
net_if_up()
net_if_down()
And these functions make use of several L2 references:
get_flags()
enable()
Let's add checks to make sure we don't deref a NULL when using these
functions.
Fixes the following exception on K64F and other HW which can make
use of offloaded network HW:
FATAL: ***** Reserved Exception ( -16) *****
FATAL: r0/a1: 0x00000010 r1/a2: 0x0000644f r2/a3: 0x00000000
FATAL: r3/a4: 0x00000000 r12/ip: 0x2000474c r14/lr: 0x0001475b
FATAL: xpsr: 0x00000000
FATAL: Faulting instruction address (r15/pc): 0x0001b1cd
FATAL: >>> ZEPHYR FATAL ERROR 0: CPU exception
FATAL: Current thread: 0x20004c4c (unknown)
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18957
Signed-off-by: Michael Scott <mike@foundries.io>
Corrected the amount of bytes copied for port handling in parse_ipv6
to prevent reading past the boundaries of the input string.
Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
Add new RD Client API of lwm2m_rd_client_stop() for this
Fix issues of de-register and event reporting in RD Client
Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
The LwM2M implementation for DNS resolving has checks which
configure hints based on whether IPv4 or IPv6 are enabled.
Neither of them need enabled if using NET_SOCKETS_OFFLOAD,
which then causes an error to be returned to due to
"hints.ai_family" not being set.
Also the offload API need to know when to free the allocated
"struct addrinfo" instead of calling free() generically,
thus let's use the freeaddrinfo() API for sockets which will
call into the offload API if needed.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18765
Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
When the firmware_pull mechansim sends the callback to notify the
sample of a new firmware block, the user supplied buffer can be
smaller than the CoAP BLOCK_SIZE setting. To handle this case,
we loop through the payload and fill the user supplied buffer with
smaller chunks.
Unfortunately, the last_block calculation is done outside this loop
which causes several callbacks (while in this loop) to have
last_block true. Let's fix this by adding a small check to make
sure we're at the end of the current payload block before notifying
the user of a last_block.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16158
Signed-off-by: Michael Scott <mike@foundries.io>
The mDNS packet receive had issues:
* The DNS id needs to be 0 for both sending and receiving, we did
not accepted 0 incoming id.
* The mDNS response does not have any questions in it so we just
need to skip the question count checks in response.
* Skip the Cache-Flush bit in Class field so that we can properly
parse CLASS_IN value.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
In DNS server init, print information whether the DNS server
is mDNS or LLMNR one. This way we do not need to remember what
IP addresses are used either of them.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The source UDP port in all Multicast DNS responses MUST be 5353
as described in RFC 6762 chapter 6.
Fixes#18732
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Make sure we use the IPv4 event command when checking IPv4 address
add or delete instead of event mask.
Coverity-CID: 203483
Fixes#18400
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
When val1 is 0, we need to handle a negative val2 value so that we
generate correct TLV value.
Example: val1 = 0, val2 = -500000 is equivalent to -0.5 decimal.
Currently we generate: 0.5 (losing the sign).
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16154
Signed-off-by: Michael Scott <mike@foundries.io>
Current JSON formatting for float32/64 is broken in a similar way as
plain text. Let's use the newly fixed logic for plain text to
generate the float32/64 values in the JSON string.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16154
Signed-off-by: Michael Scott <mike@foundries.io>
We can use the plain text float32/64 formatter for JSON as well, so
let's expose the put_float32/64 functions.
Signed-off-by: Michael Scott <mike@foundries.io>
Formatting a float32/64 value for plain text is broken.
Example for 32bit: val1=0 and val2=500000 is equivalent to 0.5
Current formatter was using %d.%d (%lld.%lld for 64bit) so
exported value was 0.500000 (or 0.5)
To fix this, for val2 use a zero-padded formatter for the maximum
length of each bit length (6 for 32bit and 9 for 64bit), and then
remove the zero characters at the end of the string.
Notes re: handling of val1/val2 signs:
- eliminate potential negative sign when converting val2 to avoid:
a value like: 0.-5
- use negative val2 when val1 is 0 to fix small negative handling
such as -0.5
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16154
Signed-off-by: Michael Scott <mike@foundries.io>
Do not try to memcpy() the same buffer to itself.
This one also reverts commit 112ecb7290
("net: gptp: Fix for coverity CIDs 203471 and 203464") as that
did not fully fix the issue.
Coverity-CID: 203464
Coverity-CID: 203471
Fixes#18394
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Make sure that the extension, like HBHO, sub-option length is
not too large.
Fixes#16323
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
When the bootstrap support was added, it looks like I somehow missed
the handling block in the engine.
Let's add it now to fix boostrap support.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18080
Signed-off-by: Michael Scott <mike@foundries.io>
- LWM2M_SECURITY_INSTANCE_COUNT wasn't following the standard of
having the unconditional default in the last position
- LWM2M_SERVER_INSTANCE_COUNT needs another instance when
bootstrap is enabled.
Signed-off-by: Michael Scott <mike@foundries.io>
LwM2M boostrap support is enabled via the config option:
LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP. If enabled, this config sets
the default # of server and security instances. However, this is
not working correctly because LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
is defined below it's uses in the Kconfig file.
Let's move the RD_CLIENT configs higher in the Kconfig to fix this
behavior.
Signed-off-by: Michael Scott <mike@foundries.io>
If no challenger went to replace the best port/vector, then the best
port is still the global_ds and thus point to the same memory: no need
to update the global_ds then.
Coverity-CID: 203471
Coverity-CID: 203464
Fixes#18395
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Looks like the logic to count rejection is missing. Removing count_rej
variable, and set a comment about initializing the code to the right
value once this logic will be in.
Coverity-CID: 203514
Fixes#18398
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Simplify algorithm to skip (aka calculate length) of encoded domain
name in a DNS answer. Now it's fully compliant to RFC 1035 regarding
handling of compressed FQDNs. Additionally, bounds checking is now
performed by the parsing code.
Fixes: #18334
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Let's use IS_ENABLED() instead of the #ifdef to get clearer code. ret
variable is used only at one place, no need for the ARG_UNUSED()
Coverity-CID: 203397
Fixes#18419
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Let's use IS_ENABLED() instead of the #ifdef to get clearer code. ret
variable is used only at one place, no need for the ARG_UNUSED()
Coverity-CID: 203468
Fixes#18420
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
IPv4 connection management status is stored in wrong
variable. ip_state should hold the status and then
it should be stored in state variable.
Fixes#18253
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
When checking for total IP address counts, don't check
CONFIG_NET_IF_MAX_IPV6_COUNT twice. This was a typo for
CONFIG_NET_IF_MAX_IPV4_COUNT.
This was reported by IRC user: retfie
Signed-off-by: Michael Scott <mike@foundries.io>
This commit changes the Link-Layer Address Option length calculation
from hardcoded values to a numerical rounding up to full 8.
The length is calculated according to rfc4861 section 4.6.1.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
If the UDP socket is connected, then allow the user to leave
out the remote address in msghdr struct.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
- Commands were not gathered with the right macro
- bus fault access due to wrong declaration of iface_states external
variable.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
The network to host byte order conversion is actually in place
on the network buffer. This prevents the reuse and forwarding of
RA packets. This commit uses temporary variables instead.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
This commit adds support for a 6LoCAN Ethernet border translator.
CAN frames with the translator CAN address are translated and forwarded
to Ethernet. Ethernet frames with the first 34 bits matching the MAC
address of the translator are translated and forwarded to 6LoCAN.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
Take the targer link layer address option link laxer addres lenght
from net packets source addres instead if the interface.
This is usefull for 6LoCAN border translator (6LoCAN to Ethernet).
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
This commit implements net_pkt_shallow_clone. A shallow clone clones
the net_pkt but not the buffers. The buffers are only referenced and
therefor only freed when both copies of the net_pkt are freed.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
This commits adds support for reception of packets thats comes from
a Ethernet to 6LoCAN translator. This packets carry the Ethernet
MAC address (6 bytes) inline in the FF (First Frame).
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
This commit is an implementation of 6LoCAN, a 6Lo adaption layer for
Controller Area Networks. 6LoCAN is not yet standardised.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
Rename the socket_can implementation from CANBUS to CANBUS_RAW.
This is a preperation for 6LoCAN which is a CANBUS L2 for IPv6.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
If sendmsg() is used for TCP sockets, the msghdr->msg_name is not
really used as the socket must already have been connected.
In that case just get the destination address directly from
net_context remote address field.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Before calling socket callback function, make sure the callback
function exists so that we do not get NULL pointer reference.
Fixes#18021
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This is related to findings in #17997 and changes network related
header files to have include files outside of extern "C" { } block.
Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.
Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.
See: https://en.cppreference.com/w/cpp/language/language_linkage
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Current SOCKS5 based connections in mqtt are only
TCP (nonsecure) based. To support TLS based SOCKS5
connections, new methods needs to be introduced.
Instead, removed CONFIG_MQTT_LIB_SOCKS based implementation.
And now mqtt provides an api to set proxy
(mqtt_client_set_proxy()) details. That's enough,
socket layer will take care of making connections through
proxy server.
Fixes: #17037
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Current SOCKS5 implementation is above socket level and every
higher layer protocol or application level needs to have
SOCKS5 related changes. This solution is based on socket
setsockopt(). Application caller has to set proxy details
through setsockopt() and socket:connect() will take care
creating connection.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
The SO_SOCKS5 socket option can be used by the application to
set the SOCKS5 proxy details. These details will be used when
connecting to peer.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Error codes are listed in header files and in the core spec as hex
values. Always print them in hex in debug for easier error code
checking.
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Several problems with memset usage in the LwM2M subsystem were
identified:
- Every single object that can have multiple instances is using
memset to initialize static resource data during init. This data
will already be set to 0 because it is static, so the memset
statements are unneeded.
- Instead of using memset during object init which is only called
one time during kernel startup, let's add a memset to the
object create function to ensure the resource data is cleared out.
It could have been used prior and then released via a DELETE op.
- the IPSO Timer object was setting a lot of data structure members
to 0 in the create function. Let's do 1 memset on the entire
structure and then only the non-zero values afterward.
Signed-off-by: Michael Scott <mike@foundries.io>
When presenting errors in lwm2m_engine_set() let's include the related
LwM2M path for easier debugging.
Signed-off-by: Michael Scott <mike@foundries.io>
This core LwM2M Object enables monitoring of parameters related to
network connectivity.
This is only the basic object structure. More work will be needed
to set the various resources based on connectivity.
Signed-off-by: Michael Scott <mike@foundries.io>
This Object is used to report the state of a momentary action push
button control and to count the number of times the control has
been operated since the last observation.
Signed-off-by: Michael Scott <mike@foundries.io>
LwM2M allows for multiple instance resources such the power source
resources in the device object. These types of resources have
always been very hard to work with, and frankly were poorly
implemented.
This led to other issues where it was very hard to have
non-sequential resource instances, and each resource of this type
needed special getter / setter methods such as:
lwm2m_device_add_pwrsrc()
lwm2m_device_set_pwrsrc_voltage_mv()
Going forward, as more LwM2M objects are implemented this just
doesn't scale well.
To fix this:
- split the resource instance data out from the resource data.
This includes the data pointer information and resource
instance id.
- add resource id and resource instance id to the event callback
functions so user's can see in more detail what resources and
resource instances are being handled.
- allow generic functions like lwm2m_engine_get_*() and
lwm2m_engine_set_*() to access resource instance data.
- adjust object resource initialization macros to map resource
instances to resources at the time of object instance
creation.
- fix up the lwm2m_client as a reflection of all of these changes.
Signed-off-by: Michael Scott <mike@foundries.io>
Due to work combining data into the lwm2m_message structure, we no
longer need to pass the lwm2m_engine_obj parameter between
formatters and most of the operation handlers.
So, let's remove it.
Signed-off-by: Michael Scott <mike@foundries.io>
The multi_max_count is no longer used and can be removed from the
obj_field structure if we change all of the OBJ_FIELD() macros to
use OBJ_FIELD_DATA() instead.
Technically, OBJ_FIELD() and OBJ_FIELD_DATA() are now the same, but
we're keeping them both for the time being. In the future, more
fields may be added to the obj_field structure and we can use the
OBJ_FIELD() macro again if that's the case.
Signed-off-by: Michael Scott <mike@foundries.io>
- Several of the functions use "path" as the parameter name for the
string-based LwM2M path. Let's clarify by using "pathstr".
- Recent updates to the LwM2M engine now support resource instances
when parsing the LwM2M path. Let's update descriptions accordingly.
Signed-off-by: Michael Scott <mike@foundries.io>
Per IPSO Light Control definition from the OMA LwM2M registry:
http://www.openmobilealliance.org/tech/profiles/lwm2m/3311.xml
There is an optional "Application Type" string resource (5750) in the
Light Control object. This was missed in the initial implementation.
NOTE: sample will assign reference if needed.
Signed-off-by: Michael Scott <mike@foundries.io>
We are pre-allocating a storage variable for the application type
resource in the IPSO Timer object. This is an optional resource
which won't always be set by samples.
Let's leave out the pre-allocated variable and let the sample set
this reference if needed (it's optional).
Signed-off-by: Michael Scott <mike@foundries.io>
Server records contain the default PMIN and PMAX settings for how
often we can send observe notifications. We are currently using
arbitrary defaults which cannot be changed when compiled or
during runtime.
Let's add Kconfig settings for the default settings to use and
also lookup the current values in the active server record when
an observe is added.
The actual PMIN/PMAX values can still be set via WRITE_ATTRIBUTE
operation.
Signed-off-by: Michael Scott <mike@foundries.io>
Currently the retransmit_work is not cancelled when closing a context,
making it operate on an invalid context.
LwM2M RD client also closes the context and initializes it again when
registration with the server fails, overwriting the active timeout and
breaking the timeout dlist.
Signed-off-by: Pieterjan Camerlynck <pieterjan.camerlynck@gmail.com>
We must discard the received Discard-Request silently.
See RFC 1661 chapter 5.9 for details.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Currently only net-shell calls net_ppp_ping() command, so make
it return the amount of time that it took to receive Echo-Reply
so the net-shell can print the round trip time value.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If the network interface is point-to-point one which does
not need IP address etc, then no need to start DAD etc for
those interfaces.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If we receive a protocol that we do not currently handle, then
return Protocol-Reject to peer.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
By default PPP is started immediately when the network interface
goes up. This can be problematic especially when debugging the beast
so allow user to delay the startup.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This patch tries to avoid memmoves and buffer allocations when there
is enough space in the original buffer. Headers are still contiguous
but not in the same buffer.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
This is a rework of the 6lo IPHC uncompression.
The uncompression now tries to work in place on the original buffer
instead of allocation a new one. If there is not enough tail-room,
a new buffer is allocated and filled with the IP and maybe UDP header.
The compressed header is pulled from the original buffer and the
buffer is preserved.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
When net_pkt_skip skips the entire data in a net buffer, the cursor
still points to this buffer on data that is off by one.
Calling pkt_cursor_advance in net_pkt_is_contiguous fixes this and
moves the cursor to the next buffer.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
This is a rework of the 6lo IPHC. The compression now works inline
on the original buffer instead of allocation a new one.
Additionally DAM_11 (Destination address fully elided) has precedence
over DAM_10 (16 bit compressible) now.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
Move CMake ExternalProject integration of OpenThread to the
CMakeLists.txt file within the OpenThread fork.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The SO_TXTIME socket option can be used by the application to
tell the network device driver the exact moment when the
network packet should be sent.
This feature is also implemented in Linux.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add BSD socket sendmsg() API that can be used to send data to peer
and also pass ancillary data to lower level of the network stack.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
User could have set something to optval in getsockopt() and we
need to copy the data to kernel optval so that the socket family
code can use the value for something.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If the allocated net_pkt is larger than the network interface MTU,
then check if the IPv6 fragmentation is enabled and allow larger
net_pkt length as the IPv6 fragmentation will split the packet into
suitable parts.
Fixes#16354
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The net_pkt_pull() needs to move all the remaining data in the
net_buf instead of just the pull amount.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Certain Thread implementations (notably ARMs) require a DHCPv6
implementation.
Allow the usage of the relevant OpenThread configuration parameters in
Zephyr.
Signed-off-by: Markus Becker <markus.becker@tridonic.com>
Bluetooth address parsing has been duplicated across the different
sub-shell files. Also missing parsing of identity/resolved addresses.
Move parsing of string close to parsing to string for a symmetrical API
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Move duplicate hex2bin and add bin2hex function so that application can
use the functions and avoid code duplication.
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
It currently only listens to relevant events about network interface to
decide whether raising connected or disconnected event.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Current implementation of LwM2M engine doesn't allow users a way
of overriding TLS credential load with custom function. This
would be needed by an offloaded TLS stack where we don't want
to use standard Zephyr functions.
Let's add a load_credential function pointer to the LwM2M client
context which will be called when it's available.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17408
Signed-off-by: Michael Scott <mike@foundries.io>
Let's remove depends on NET_LLDP from all the options. It avoids this:
# CONFIG_NET_LLDP is not set
# CONFIG_NET_LLDP_LOG_LEVEL_OFF is not set
# CONFIG_NET_LLDP_LOG_LEVEL_ERR is not set
# CONFIG_NET_LLDP_LOG_LEVEL_WRN is not set
# CONFIG_NET_LLDP_LOG_LEVEL_INF is not set
# CONFIG_NET_LLDP_LOG_LEVEL_DBG is not set
CONFIG_NET_LLDP_LOG_LEVEL_DEFAULT=y
CONFIG_NET_LLDP_LOG_LEVEL=3
CONFIG_NET_LLDP_CHASSIS_ID="CHASSIS_ID_PLACEHOLDER"
CONFIG_NET_LLDP_PORT_ID="PORT_ID_PLACEHOLDER"
And instead it will generate this:
# CONFIG_NET_LLDP is not set
Make the menu as an enablement config option as well.
Adapting lldp header file relevantly.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
ARP, LLDP and GPTP functions have dummies in case of being disabled so
let's use IS_ENABLED() accordingly.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
If we receive IPv6 packet where source address is unspecified
(all zeros), then we need to drop it.
Fixes#17450
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
When performing OTA using the LwM2M subsys, several logging errors
regarding log_strdup were noted. Let's fix these.
Signed-off-by: Michael Scott <mike@foundries.io>
If a sample wants to use the Zephyr implementation of mbedtls, it
enables CONFIG_MBEDTLS and sets any needed Zephyr-specific mbedtls
options.
Currently, the LwM2M subsystem selects MBEDTLS automatically when
LWM2M_DTLS_SUPPORT is enabled. Let's remove this and let the
LwM2M client sample enable mbedtls and it's options.
This mimics the behavior of several other network-related samples
and removes conflicts when selecting alternate implementations of
MBEDTLS.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17399
Signed-off-by: Michael Scott <mike@foundries.io>
CONFIG_NET_IPV* checks are not needed in lwm2m_parse_peerinfo().
The functions used are always available. Worse, having these checks
forces the need to enable CONFIG_NET_IPV4 or IPV6 when it's not really
needed (LwM2M could be using an offloaded IP stack).
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17401
Signed-off-by: Michael Scott <mike@foundries.io>
CONFIG_NET_IPV* checks are not needed in lwm2m_sprint_ip_addr(). The
functions used are always available. Worse, having these checks
forces the need to enable CONFIG_NET_IPV4 or IPV6 when it's not really
needed (LwM2M could be using an offloaded IP stack).
NOTE: Also fixes an issue where a NULL is returned when the IP address
is unknown. This usually ends up with a crash/abort in the logging
code.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17401
Signed-off-by: Michael Scott <mike@foundries.io>
If we receive IPv4 packet where source address is unspecified
(all zeros), then we need to drop it.
Fixes#17427
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If DNS server(s) are added or removed e.g., as part of DHCP
processing, send newly defined net-mgmt events so that
a user application may get this information.
Fixes#16924
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Removing an IPv4 router was missing, as well as finding the default
router for an IPv4 address.
Note howevere that IPv4 router features are not used anywhere yet. But
at least the API is there and is a 1:1 to IPv6, if that matters.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
- router lifetime is always a u16_t so fixing
net_if_ipv6_router_update_lifetime() signature.
- Coalescing router timers into one: this reduces the net_if_router
structure by 22 bytes
- refactor IPv6 and IPv4 router code so it's handled in generic
functions, to avoid duplicating 90% of the code for each family. This
also fixes the lifetime support for IPv4 which was missing.
Note however that IPv4 routing support seems to be missing as none of
the relevant functions are used anywhere yet.
Fixes#8728
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This reduces the size of struct net_if_ipv6 by 24 bytes by moving
the k_delayed_work attribute into net_if core code.
Then each net_if_ipv6 can be added to the timer handler via a slist.
This does not make much gain if the system has only 1 network interface
It starts to be interesting if it has 2+ network interfaces then.
Fixes#8728
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This reduces the size of struct net_if_addr by 24 bytes by moving
the k_delayed_work attribute into net_if core code.
Then each net_if_addr can be added to the timer handler via a slist.
This does not make much gain if the system has only 1 unicast IPv6
address. It's a nice memory improvment once it has 2+ unicast IPv6
address. Note that having IPv4 enabled along with IPv6 will also see
memory improvements since both IPv6 and IPv4 use the same struct
net_if_addr.
Fixes#8728
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Let's regroup all the IPv4 related function into one ifdef. There is no
need to implement a dummy function for each: if IPv4 is not enabled,
these functions are unused in the core.
Fixes#8728
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Let's regroup all the IPv6 related function into one ifdef. There is no
need to implement a dummy function for each: if IPv6 is not enabled,
these functions are unused in the core.
Fixes#8728
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
The hostname needs to have log_strdup() when printing it.
Also it is useful to print information if the sending fails.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
- answer offset was 1 byte off.
- request offset, when copied into the answer, was off as well.
Fixes#16142
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Skip the TCP options before giving the data to application.
Without this, the TCP options would be passed to the application.
Fixes#17055
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The handcrafted allocation falls victim of misaligned structures due to
toolchain padding which crashes the socket test code on 64-bit targets.
Let's move it to the iterable section utility where those issues are
already taken care of.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
OpenThread did not verify if the interface provided in the net_mgmt
handler is actually an OpenThread interface. In result, when multiple
network interfaces were used, different interfaces were processed by the
OpenThread handler, ending up in a crash.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Make sure the IPv4 and IPv6 socket addresses are initialized before
copying them. This avoids uninitialized memory access.
Coverity-CID: 199436
Fixes#17202
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This can be used to activate the network packet statistics
collection. Note that we do not have resources to calculate
each network packet transit times but we collect average times
instead.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Finalize the CONFIG_NET_CONTEXT_TIMESTAMP support that was started
earlier but never properly finished. We collect network statistics for
TX packet network stack throughput time from when the net_context_send
is called and when the net_pkt was sent out successfully by the network
device driver.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Currently only setting and getting of Ethernet Qav options are
supported via this interface.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If the net_mgmt event has some info, like IP address, that
could be sent, then send it the same time. This is very useful
for the receiver of the event in order to know that is happening
in the system.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Allow application to listen network management events using
BSD socket API. Application needs to create the socket using
AF_NET_MGMT address family. At this point we only support
receiving network management events that the network subsystem
is sending.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The info parameter is difficult to use if the caller does not
get information how long the info struct is. So add info_length
parameter to net_mgmt_event_wait_on_iface() and
net_mgmt_event_wait() APIs.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Allow application to call net_if_ipv4_set_gw_by_index()
and set the gateway if enabled by configuration.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Allow application to call net_if_ipv4_set_netmask_by_index()
and set the netmask if enabled by configuration.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Make IPv4 and IPv6 address addition and removal possible from
userspace app. But allow this only if CONFIG_NET_IF_USERSPACE_ACCESS
By default these operations are not allowed from userspace app.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This fixes the issue where observations are automatically reported using
the minimum period instead of the maximum. This causes notifications to
be sent more frequently than configured when the resource does not
change.
Signed-off-by: Pieterjan Camerlynck <pieterjan.camerlynck@gmail.com>
Current socket connect call implementation always takes
K_FOREVER timeout value, which blocks TCP connections
in case failure. TCP connections waits until it receives
SYN ACK. If there is no SYC ACK means, connect call is
blocked forever.
Added a Kconfig option to define timeout value. Default
value is 3000 milliseconds. User can modify it.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Modify dns_unpack_answer() function to check if the answer is
compressed or not, and return correct values regardless.
Fixes#16594
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This change will allow an MQTT client to override the compile-time
keepalive if desired. The change is structured such that the
compile-time default will still be setup by calling mqtt_client_init,
but can be changed by the application before calling mqtt_connect if
desired.
Signed-off-by: Justin Brzozoski <justin.brzozoski@signal-fire.com>
move misc/reboot.h to power/reboot.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>
move misc/util.h to sys/util.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>
move misc/slist.h to sys/slist.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>
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>
move misc/mutex.h to sys/mutex.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>
move misc/math_extras.h to sys/math_extras.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>
move misc/fdtable.h to sys/fdtable.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>
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>
move misc/__assert.h to sys/__assert.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>
move flash.h to drivers/flash.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>
move entropy.h to drivers/entropy.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>
Return value from close() can be ignored in sntp_close()
as it is not returning value to caller anyway.
Coverity-CID: 198863
Fixes#16584
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Make net_eth_get_ptp_clock_by_index() clock API to work with user space.
Create also unit test for testing this user mode support.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If immediate logging is disabled, then we must use log_strdup()
when printing log string allocated from stack.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We must query both IPv4 and IPv6 addresses if the hints parameter
is NULL i.e., user does not supply hints or if family is set to
AF_UNSPEC.
Fixes#16453
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This function uses mqtt_read_publish_payload_blocking to perform a
blocking read of the specified number of bytes.
When reading out a payload, the normal use case is to read the
entire payload. This function facilitates that use case.
Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
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>
If the socket is closed, then do CAN detach if that is needed.
This way the CAN interrupts are not received if there are no
CAN sockets listening the data.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
At the moment there is no real address for local CANBUS socket,
but we can still set protocol family of local socket to AF_CAN
so that for example net-shell "net conn" command can show
information about it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We need to dispatch the received CAN frame if there are multiple
sockets interested in the same CAN-IDs.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The neighbor cache did not contain link address type. This is not
causing problems atm but good to fix anyway.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
It is possible that iface is NULL when selecting IPv4 destination
address for a sent packet.
Coverity-CID: 198877
Fixes#16570
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The query->len does not take 'Terminator' into account, shift over
one byte to prevent overwriting it with next field (Type).
This fixes mdns_resolver sample.
Fixes: 87eb552dd2 (net/dns: Switch mdns responder to new net_pkt API)
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Allow user to set the socket priority using setsockopt() call.
The priority value is used to order the networking queues so
that packets with a higher priority may be processed first.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
It is possible that UDP header cannot be accessed so we need
to check that we do not do null pointer dereference.
Coverity-CID: 198866
Fixes#16581
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
These options are mutually exclusive, or more specifically,
CONFIG_POSIX_API has wider scope and supersedes
CONFIG_NET_SOCKETS_POSIX_NAMES. Implementation-wise, the two
options should not be defined at the same time, as that may
lead to declaration conflicts.
Fixes: #16141
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Offloaded `fcntl` implementation should be available for all offloaded
implementations, not specific for TI. `socket_offload.c` is already
conditionally compiled based on `CONFIG_NET_SOCKETS_OFFLOAD` option, so
there should not be conflicts for non-offloaded interfaces.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Length should be at least of UDP header size but not bigger than actual
payload size.
Reported-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Due to commit a211afb0 ("logging: Add option to detect missed
transient string duplication"), the logs for LwM2M subsystem
is now spamming missing log_strdup() calls.
Let's add log_strdup() where needed.
Signed-off-by: Michael Scott <mike@foundries.io>
This allows setting a custom pointer to be passed back to the complete
callback at expense of increasing the buffers in 4 bytes.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If a valid numeric IP address is provided as argument, it should
be resolved without contacting DNS server.
Also, implement handling of AI_NUMERICHOST.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Having a checksum of zeros in UDP means "missing checksum" and is a
valid case as per RFC 768:
"An all zero transmitted checksum value means that the transmitter
generated no checksum (for debugging or for higher level protocols
that don't care)."
Such support is made possible by adding a new Kconfig option named
CONFIG_NET_UDP_MISSING_CHECKSUM.
However, that is valid only for IPv4. For IPv6, see the RFC 2460
section 8.1:
"Unlike IPv4, when UDP packets are originated by an IPv6 node, the UDP
checksum is not optional."
So the UDP checksum will always be verified in IPv6.
Fixes#16375
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
From RFC 768, in "Fields":
"If the computed checksum is zero, it is transmitted as all ones"
Fixes#16379
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
The 32bits one can hold up to about 50 days, this is more than enough
knowing that ARP request timeout is 2 seconds.
So reducing the request start time to 32bits.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Do not always print general help for ping cmd. Only if user supplies
'-h' or '--help' command, print information about the parameters.
After this the generated HTML documentation looks better for the
ping command.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
OpenThread uses CONFIG_OT_PLAT_FLASH_PAGES_COUNT to calculate the # of
pages at the end of flash to use for storing OpenThread settings.
This calculation has an off-by-one error which sets the offset for
the storage area as 1 page of flash too low.
For example, on nRF52840:
- default setting for CONFIG_OT_PLAT_FLASH_PAGES_COUNT is 4
- flash size is 1MB (0x100000)
- flash page size is 4096 (0x1000)
- expected offset is 0xfc000
Using the current logic we get an offset of: 0xfb000
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16339
Signed-off-by: Michael Scott <mike@foundries.io>
Drop packet if it has broadcast destination MAC address but the IPv4
destination address is not multicast or broadcast address.
See RFC 1122 ch 3.3.6 for details.
Fixes#16276
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The net_if_ipv4_select_src_addr() should return global address
in the interface if nothing else is being found.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Let's filter out on a state parameter.
There is no impact as this function is not used anywhere yet.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
If we receive a multicast ICMPv4 packet, then send the reply back
with correct source address and not with multicast address.
Fixes#16257
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Make sure we are able to receive UDP packets with broadcast
destination address. If CONFIG_NET_IPV4_ACCEPT_ZERO_BROADCAST
is set, then check here also non-standard broadcast address
that is described in RFC 1122 chapter 3.3.6.
Fixes#11617
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
From POSIX.1-2017:
The getsockname() function shall retrieve the locally-bound name of the
specified socket, store this address in the sockaddr structure pointed
to by the address argument, and store the length of this address in the
object pointed to by the address_len argument.
The address_len argument points to a socklen_t object which on input
specifies the length of the supplied sockaddr structure, and on output
specifies the length of the stored address. If the actual length of the
address is greater than the length of the supplied sockaddr structure,
the stored address shall be truncated.
If the socket has not been bound to a local name, the value stored in
the object pointed to by address is unspecified.
Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
If host is NULL and ai_flags are AI_PASSIVE in a call to
getaddrinfo(), need to return "any" address.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Use the new math_extras functions instead of calling builtins directly.
Change a few local variables to size_t after checking that all uses of
the variable actually expects a size_t.
Signed-off-by: Jakob Olesen <jolesen@fb.com>
We replied to an ARP request that has the same Sender Hardware Address
than that of ours. Such an ARP request must be discarded, no reply
should be sent and translation table should not be updated.
Fixes#16110
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
If a packet is received with Ethernet source address different
from ARP's sender hardware address field, then DUT must use the
latter address in response packets.
Fixes#16098
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Libraries that use mbedTLS have been invoking
zephyr_link_interface(mbedTLS). It is not clear what the intent of
this code has been, but it is redundant with the mbedTLS build
scripts, so it can be safely removed.
In addition to being redundant, it causes problems as it introduces an
ordering dependency, with this code mbedTLS must be declared before
users of mbedTLS are declared. Since this code is redundant, this
ordering dependency is also unnecessary.
This code is believed to have been added early on by accident and
copied through cargo-cult programming since.
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
sntp_simple() function queries the server (passed as "addr[:port]"
string). It wraps calls to a number of other functions, and may be
useful to write simple, concise apps needing the absolute time.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Two utils to manipulate addresses in format "addr[:port]". I.e.,
network address (domain name or numeric), optionally followed by
port number:
* net_addr_str_find_port(), to return pointer to port number
substring (or NULL if not present).
* net_getaddrinfo_addr_str(), which is effectively getaddrinfo()
wrapper taking a "addr[:port]" string as a parameter.
The header file is named socketutils.h to emphasize that these
utility functions are implemented on top of BSD Sockets API
(and other POSIX/ANSI C functions), and thus portable to other
POSIX systems (e.g., Linux), so can be used in apps testing
POSIX compatibility. More utility functions (beyond address
manipulation) can be added later.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Calling functions like `net_if_start_dad`, `join_mcast_nodes` or
`net_if_start_rs` lead to L2 API function calls, which is not correct
for offloaded interfaces and leads to a crash. This is especially
problematic, as they are called in the default configuration.
Avoid calling these functions while an offloaded interface is brought up
by adding extra jump label.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case socket offloading is used, one might want to disable native IP
stack, both IPv4 and IPv6, to save memory. Currently it is not possible
due to preprocessor check. Prevent that by adding additional exception
for socket offloading.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
It is convenient to have a blocking version of
`mqtt_read_publish_payload` function, for cases when it is called from
the event handler. Therefore, extend the 'mqtt_read_publish_payload'
argument list with information whether the call should block or not.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
It is possible that the device driver API pointer is null.
For example if the device driver returns an error, the device
code will make the API pointer NULL so that the API would not
be used. This can cause errors in networking code where we
typically do not check the NULL value.
Fixes#15003
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
- renaming functions to better names
- reordering functions place (register, then unregister for instance)
- centralizing logs to relevant place
Fixes#8722
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Also, there is no need for unspecified address bit. If specified address
bit is not set, then it will be obvious address is unspecified. Reducing
the amount of bits from 6 to 4.
This permits to reduce net_conn structure of 4 bytes. Its size is as
before indroducing node attribute.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This will optimize path when unused an connection is required or when
looking up a used one.
That said, at this stage, it bloats up the net_conn structure with 4
added bytes. More optimization will overcome this drawback.
Fixes#8722
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Most of present #ifdef can be removed via using IS_ENABLED() macro.
Only small part of cache related logic still require #ifdef.
Fixes#8722
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
There were various flaws in it that motivated its removal:
- No hash collision handling mechanism. In case that would happen, the
behavior of the network connection would be unknown. This is the main
drawback
- The lookup is not that much more efficient than the default one. The
only difference of gain is in connection comparison (a u32t comparison
vs a full connection compare). But the list handling is the same. It's
made worse by the presence of a negatives match array which can be
easily filled in and becomes then fully usless, appart from consuming
CPU. As well as adding a new connection: it requires the whole cache
to be cleared which is unefficient.
- Not memory efficient, even compared to a proper hash table.
Two arrays instead of one etc...
All of this could be fixed by using a proper hash table, though it
remains to be seen if such object could fit in Zephyr core.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
During net_pkt/net_context API changes, some ip handling blocks were
ordered ipv4 first, ipv6 second. While it is the contrary everywhere
else. So reordering to get things consistent.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
- Not all #ifdef can be removed: those which have a dedicated attribute
in struct net_context.
- For CONFIG_NET_CONTEXT_CHECK: switching the NET_ASSERT_INFO to
NET_DBG (simpler to read and anyway an error code is returned)
Fixes#8725
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Zephyr implementation of OpenThreads utilsFlashErasePage platform
function did not disable flash protection before calling `flash_erase`
function. This resulted in an error instead of actual flash erase on
platforms that properly implement flash write protection.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This make use of NET_IF_NO_AUTO_START flag so Bluetooth interfaces are
not automatically enabled after initialized.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
The approved trademark name is Wi-Fi so update references to WiFi and
other spellings to Wi-Fi in documentation and Kconfig help strings.
(Note that use of spelling variatios of "wifi" in module names, CONFIG
names, link names and such are untouched.)
https://www.wi-fi.org/
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Implement OpenThreads frame pending bit management on top of the Zephyrs
radio driver API. This allows for proper Sleepy End Devices handling
from the parent side.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The pkt variable cannot be NULL at this point so the check for
nullness is not needed.
Coverity-CID: 198002
Fixes#15777
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This makes use of BT_GATT_SERVICE_DEFINE to statically define services
for services that are not required to be dynamically registered.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If the loopback driver is enabled, then the packet might come
from localhost in which case mark it properly. Without this marking
the packet from/to 127.0.0.1 or ::1 would be dropped in later checks.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
When importing a pre compiled imported library it is currently
required to perform three steps.
This commit introduces a helper function which allows the
user to import a library with a single function call.
Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
If ethernet controller has VLAN tag strip flag enabled
(ETHERNET_HW_VLAN_TAG_STRIP), L2 etherent will not read tag from
the Rx etherent header. Instead it will fetch VLAN tag from
net packet metadata.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Allow for including arbitrary data in net_icmpv6_send_echo_request()
that will be echoed verbatim by the receiver.
This allows to use ICMP echo for diagnostic use cases, e.g. by testing
packet framentation (large payload) or measuring round-trip-time.
Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
Allow for including arbitrary data in net_icmpv4_send_echo_request()
that will be echoed verbatim by the receiver.
This allows to use ICMP echo for diagnostic use cases, e.g. by testing
packet framentation (large payload) or measuring round-trip-time.
Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
Allow accessing already parsed information from the ICMP header
that callbacks might be interested in.
This makes the callback signature and behaviour match that of
the ICMPv6 implementation.
Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
We need to re-initialize the trickle->timer delayed work to use
trickle_timeout() if there are multiple triggerings.
Fixes#15606
Signed-off-by: ling wei <lingwei@cisco.com>
Existing sntp_request() function has a coarse integer seconds
precision, discarding fractional part as returned by SNTP.
Deprecate it, and instead introduce sntp_query() function which
returns both integer and fractional seconds as a newly introduced
structure sntp_tstamp.
Fixes: #15596
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Previously, a case when poll() call timed out wasn't handled, and
recv() was called unconditionally. In the case of timeout, recv()
itself would hang indefinitely.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This commit prevents a situation when stored and possibly modified
commissioner dataset is overwritten with default configuration during
OpenThread initialization.
It introduces a new function, openthread_start, which verifies if the
dataset is already stored, and if not, depending on configuration,
preloads the default configuration or initiates the join procedure.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If the NET_IF_NO_AUTO_START network interface flag is set, then
do not take network interface up during the initialization of the
network interface. The network device driver can set the flag in its
network interface initialization function if needed.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Provide access functions for manipulating network interface flags.
There is no need for the caller of this API to know about the inner
details of the flags.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
In addition to checking that the ARP entry does not exist as the
implementation is done currently, also check if the ARP packet
is due to IPv4 link local address configuration. In both cases
use the provided IPv4 address instead of the one set for the
interface.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
IPv4 link local uses ARP to detect conflicting addresses. Properly
set the ethernet packet type to NET_ETH_PTYPE_ARP when probing
for address duplicates.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
The source address in unicast DHCPv4 Request packets was found out
to be all zeros address 0.0.0.0. This address is only acceptable if
the destination is a multicast one, where the host in question is
acquiring a DHCP address lease. This is true for the DHCP Discover
and the initial DHCP Request message from the client towards the
server. As subsequent DHCP Request renewal messages are sent as
unicast to the server, the server will drop such packets.
Fix this issue by explicitely specifying what source IP address is
to be used, if none is specified, the all zeros address 0.0.0.0 is
used in multicast addresses. The source address in the other
unicast cases is identical to the 'ciaddr' in the DHCP message.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
If for some reason the DNS resolver callback is not called properly
then make sure that semaphore will not block forever.
Fixes#15197
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
When VLAN is enabled, ethernet l2 layer fills ethernet header
but not added to the network buffer.
Fixes#15346
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
This fixes an issue where if timestamp == service_due_timestamp,
we don't call the periodic service. Then the following call to
engine_next_service_timeout_ms() returns 0 because the service
is still due and lwm2m_engine_service() is called again.
This process repeats several times until the value of
k_uptime_get() changes and then the work is finally handled.
Previously, the resolution of k_uptime_get() was in ms. A recent
change to this API defaults Zephyr so that the resolution is
set via CONFIG_SYS_CLOCK_TICKS_PER_SEC (default 100).
This means the value of k_uptime_get() only changes every 10ms.
Reported-by: Github User pieterjanc
Signed-off-by: Michael Scott <mike@foundries.io>
"It's a Trap!" -- Admiral Ackbar
When moving to the BSD-socket APIs, the original thread running LwM2M
periodic services such as observes and lifetime updates, was replaced
with a re-occuring workqueue job. To save the overhead of creating a
new thread, I used the system workqueue for these jobs.
This was a mistake. If these jobs hit a semaphore or wait for some
reason, it cannot be prempted due to the priority of the system work
queue.
Let's instead add this service handling to the thread that we already
use for polling sockets. This also removes a configuration issue where
the system workqueue stack size needed to be increased. This can now
be adjusted via the LWM2M_ENGINE_STACK_SIZE knob.
Directly fixes semaphore usage in the socket-based DNS code.
This was introduced as a bugfix for non-responsive DNS server hanging
the Zephyr device forever. However, this probably fixes randomly
seeming hangs on the device.
Signed-off-by: Michael Scott <mike@foundries.io>
Increase the default mgmt event stack size from 512 to 768 because of
stack overflows.
Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
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>
We need all the socket APIs to work from user mode.
tests/net/socket/misc now runs in userspace.
Fixes: #15227
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This macro is slated for complete removal, as it's not possible
on arches with an MPU stack guard to know the true buffer bounds
without also knowing the runtime state of its associated thread.
As removing this completely would be invasive to where we are
in the 1.14 release, demote to a private kernel Z_ API instead.
The current way that the macro is being used internally will
not cause any undue harm, we just don't want any external code
depending on it.
The final work to remove this (and overhaul stack specification in
general) will take place in 1.15 in the context of #14269Fixes: #14766
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
DNS is not part of L3, but as dhcpv4 or the net shell, it is a services
on top of the network stack. So let's gather all in a dedicated
function.
This also rework the order when starting the DNS service. There was an
issue for offload device: these would be fully initialized in
init_rx_queues() which was called after l3_init. l3_init had already
started dns: which would not be able to bind correctly, proving to be
fully dead afterwards. Instead, starting the dns at the very end
ensures that all is initialized properly from devices to stack.
Fixes#15124
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
With or without options headers it has to work. Currently it was
setting always hop-by-hop next header which is obviously wrong but
worked on ipv6_fragment test since that one has only packets with
optional headers (hop-by-hop in that case has to be the first optional
header).
Fixes#14622
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
If the TCP segment is not sent properly by L2, then do not mark
it "not sent" in net_if.c:net_if_tx(). That "not sent" marking
confused TCP ref counting in tcp.c:tcp_retry_expired() and caused
the packet to be freed too early which then caused free net_buf
access issue during packet resend. This free memory access was
seen with zperf sample application.
From TCP point of view, the packet can be considered sent when
it is given to L2. The TCP timer will resend the packet if needed.
Fixes#15050
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This reverts commit 9cd547f53b.
The commit we are reverting, fixed originally the issue that was
seen with zperf. There we freed the net_pkt too early while it was
still waiting for a TCP ACK. The commit 9cd547f5 seemd to fix that
issue but it was causing issues in dump_http_server sample app which
then started to leak memory. No issues were seen with echo-server
with or without the commit 9cd547f5.
So the lessons learned here is that one needs to test with multiple
network sample apps like dump_http_server, echo_server and zperf
before considering TCP fixes valid, especially fixes that touch
ref counting issues.
Fixes#15031
The next commit will fix the zperf free memory access patch.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The network packet ref count was not properly increased when
the TCP was retried. This meant that the second time the packet
was sent, the device driver managed to release the TCP frame even
if we had not got ACK to it.
Somewhat long debug log follows:
The net_pkt 0x08072d5c is created, we write 1K data into it, initial ref
count is 1.
net_pkt_write: pkt 0x08072d5c data 0x08075d40 length 1024
net_tcp_queue_data: Queue 0x08072d5c len 1024
net_tcp_trace: pkt 0x08072d5c src 5001 dst 5001
net_tcp_trace: seq 0x15d2aa09 (366127625) ack 0x7f67d918
net_tcp_trace: flags uAPrsf
net_tcp_trace: win 1280 chk 0x0bea
net_tcp_queue_pkt: pkt 0x08072d5c new ref 2 (net_tcp_queue_pkt:850)
At this point, the ref is 2. Then the packet is sent as you see below.
net_pkt_ref_debug: TX [13] pkt 0x08072d5c ref 2 net_tcp_queue_pkt():850
net_tcp_send_data: Sending pkt 0x08072d5c (1084 bytes)
net_pkt_unref_debug: TX [13] pkt 0x08072d5c ref 1 (ethernet_send():597)
Ref is still correct, packet is still alive. We have not received ACK,
so the packet is resent.
tcp_retry_expired: ref pkt 0x08072d5c new ref 2 (tcp_retry_expired:233)
net_pkt_ref_debug: TX [10] pkt 0x08072d5c ref 2 tcp_retry_expired():233
net_pkt_unref_debug: TX [10] pkt 0x08072d5c ref 1 ... (net_if_tx():173)
net_pkt_unref_debug: TX [10] pkt 0x08072d5c ref 0 ... (net_if_tx():173)
Reference count is now wrong, it should have been 1. This is because we
did not increase the ref count when packet was placed first time into
sent list in tcp.c:tcp_retry_expired().
The fix is quite simple as you can see from this commit.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This patch fixes following issues.
* If IPv6 neighbor table is full, stack can not add any new
neighbors. So stale counter is introduced. Whenever neighbor
enters into STALE state, stale counter will be incremented
by one. When table is full and if stack wants to add new
neighbor, oldest neighbor in STALE state will be removed
and new neighbor will be added.
* When neighbor is in PROBE state and when it exceeds max
number of PROBEs, only neighbor with router is removed.
As per RFC 4861 Appendix C, entry can be discarded. Now
neighbor will be removed from the table.
* Reachability timer has an issue. e.g. if a first entry timer
is 10 seconds, after 3 seconds, a new entry added with
only 3 seconds. But current implementation does not check
whether remaining time of current left over timeout is more
than new entry timeout or not. In this example, when new entry
timeout is 3 seconds, left over timeout from first etnry is
still 7 seconds. If k_delayed_work_remaining_get() returns
some value then new entry time out was not considered.
Which is bad. It fixed now.
* nbr_free is used sometimes to remove the neighbor. Which does
not remove route if that particulat neighbor is route to some
other neighbor. net_ipv6_nbr_rm() should be used in such places.
* Trivial changes which does not affect functionality.
Fixes#14063
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Fix regression and allow incoming packet when source and
destination port numbers are the same.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
In case of Ethernet for instance, the MTU is larger than the minimal
IPv6 MTU, so it is not required to fragment a packet that fits in
Ethernet MTU.
Fixes#14659
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
It is invalid to try to bit shift the same amount of bits as
what is the number of bits in the left expression’s type.
Coverity-CID: 187079
Fixes#8988
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The "is this packet for us?" filter in net_ipv4_input() has a minor
logic error which fails to discard many packets which are.. not for us.
Fixes: #14647
Signed-off-by: Charles E. Youse <charles.youse@intel.com>
The context_alloc_pkt() might run out of memory, and if that
happens we must not try to set the context pointer in it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We are reverting the changes in commit
55b3f05932 given build errors are seen
when fcntl.h is included, as it declares fcntl() as a non-static
function. The same function cannot be declared as both static and
non-static.
Instead, we avoid redefining fcntl() in lib/os/fdtable.c specifically
for case of the SimpleLink family, til we have support for the new
socket_op_vtable.
Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
Since the new packet flow came in, payload comes at the end so udp
length for instance is known only when we "finalize" the packet.
However such finalization was still under the condition of chksum
offload, like it used to be in the former flow (udp headers were
inserted). This is obviously wrong but that was not caught with
existing driver in master as none of these drivers offloading
chksum calculation.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Commit fc27a81ed2 ("net: context: Select proper network interface
when binding") moved the bind_default() call to after the remote
address was set for the net_context.
This and a later net_pkt API refactor broke net_offload() handling
so that context->iface wasn't set and context->flags didn't have
NET_CONTEXT_REMOTE_ADDR_SET correctly.
Let's fix this by relocating the net_offload handling to after
these have happened.
Signed-off-by: Michael Scott <mike@foundries.io>
Some places were still using the old allocator. Using the new one does
not change any behavior. This will help to remove the useless data_len
attribute in net_pkt which legacy allocator was still setting.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
net_offload API is left untouched, so it still takes a net_pkt as input
for the buffer. This is under-optimized since offload drivers will copy
the data from that net_pkt back into contiguous buffer again.
Let's tackle this issue another time.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This attribute, in case CONFIG_NET_STATISTICS is enabled, made sense
when L2's send() function did not return the length of the sent packet.
But now, it's a superflous optimization as is it used only to set the
stats on recv or send, where net_pkt_get_len() can be used directly.
This helps to save 2 bytes from struct net_pkt.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
And also to the relevant callbacks.
That parameter is not used anywhere so it is useless.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Seems like a useless attribute. Since net_context is not being used by
the user directly (socket is the unique interface now) and since no core
parts uses the token parameter of net_context API: let's remove the
attribute.
This helps to save 4 bytes from struct net_pkt.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Now that legacy - and unrelated - function named net_pkt_get_data has
been removed, we can rename net_pkt_get_data_new relevantly.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
That function was responsible for allocating new buffer element, but it
is now unused and can be removed safely. Buffer allocation is now done
via net_pkt_alloc_buffer().
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Now that legacy functions are removew, let's rename the new functions by
removing the _new suffix.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
There is no need for these anymore: all is dictated by the position of
the net_pkt's cursor now
- actual cursor position is like the former appdata attribute
- net_pkt_remaining_data() is like the former appdatalen attribute
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Former net_context_send/sendto and net_context_create_ipv4/ipv6 are now
unused and can be removed.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
IPv6 next header might be something else (here NET_IPV6_NEXTHDR_HBHO)
but when finalizing it is mandatory to give the actual last header
protocol type. In this case IPPROTO_ICMPV6, so the checksum can be
computed properly then by net_icmpv6_finalize() called from
net_ipv6_finalize().
Fixes#14663
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
As the L2 layer might have modified the cursor, reset it here
before giving the packet to promiscuous mode API. This way
the application will get a fresh copy of the buffer.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
TCP context is now created with refcount of 2, signifying that it's
jointly owned by an app and stack. Thus, net_context_put()
unconditionally calls net_context_unref() to decrement refcount on
app's behalf, and leaves stack's refcount to internal routines
which handle sending/receiving/timing out FINs, etc.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
TCP context is effectively owned by both application and the stack:
stack may detect that peer closed/aborted connection, but it must
not dispose of the context behind the application back. Likewise,
when application "closes" context, it's not disposed of immediately,
there's yet closing handshake for stack to perform.
This effectively means that TCP contexts have refcount of 2 when
they're created. Without this change, following situation is
possible: peer opens connection, an app get a context (or socket)
via accept, peer sends data, closes connection. An app still holds
a reference to connection, but stack may dispose of context, and
even reuse it for a new connection. Then application holds a reference
to either free, or completely different context.
This situation was very clearly and 100% reproducible when making
Zephyr port of open62541 library, which works in async manner using
select().
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
To save binary size, currently just returns textual name of error
code, e.g. EAI_FAIL -> "EAI_FAIL". Based on real usecases, can be
replaced with user-friendly message later. (Current usecase is to
allow/help to elaborate sockets API by proof-of-concept porting
existing socket apps).
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Normally, this bug wasn't apparent as the value is type-casted
to a float32/64 type. However, once we start persisting these
values they need the correct length.
Signed-off-by: Michael Scott <mike@foundries.io>
Let's avoid future compile issues with this macro when passing
in a type-casted value that isn't surrounded by parenthesis.
Signed-off-by: Michael Scott <mike@foundries.io>
Occasionally we see a stack crash in LwM2M. This may have been
due to the swap from net_app APIs to socket-based APIs.
Let's raise the default stack by 1k.
Signed-off-by: Michael Scott <mike@foundries.io>
When a context is closed to a server, we should clean up any
existing observes along with it. Otherwise these will try to fire
afterward.
Signed-off-by: Michael Scott <mike@foundries.io>
We are already in sm_do_registration(), there's no need to check
!sm_is_registered(). Either we are performing a full registration
or a registration update. In both cases, sm_send_registration()
is called.
Signed-off-by: Michael Scott <mike@foundries.io>
If an error is received during registration update, we need to reset
the status so that a full registration is performed. This was
incorrectly being set to ENGINE_REGISTRATION_SENT.
The correct status should be: ENGINE_DO_REGISTRATION
Signed-off-by: Michael Scott <mike@foundries.io>
send() returns -1 upon error and sets errno appropriately. Let's
not bother saving the return code and instead share errno back
to the user.
Signed-off-by: Michael Scott <mike@foundries.io>
The socket-can code expects to have "struct can_frame" from
application when it calls send(). We then have to convert to
"struct zcan_frame" as that is what the driver expects.
Same thing when receiving data. We just convert to
"struct can_frame" and pass that to application.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Remove use of select to "force" enabling other configs in subsys/fs
and subsys/net/l2. The forcing will cause infinite kconfig recursion.
Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
Now that IPv4 options are handled, ICMPv4 echo reply must be created
taking into account that IPv4 header length can be variable. So instead
of cloning and rewriting (that would copy the useless options), let's
allocate and copy only the payload.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
IPv4 header length might be bigger than struct net_ipv4_hdr if there are
options appended to it.
Fixes#11618
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
IPv4 header might come with options, unlike IPv6, these are not
encapsulated in option header but are fully part of the IPv4 header.
Zephyr must handles these. Now silently ignoring their content and
setting the cursor to the payload properly.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This is probably the only place where net_pkt_alloc_from_slab() is going
to be used.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This is meant for very particular use case as only logging uses that.
Where it makes entirely sense for it to send the logs through its own
slab/pool in order to not drain the core slabs/pools.
So enabling the new API to manage that. That has to be used with
net_context for the buffer pool. So one has to first allocate the
net_pkt from external slab, set the context and then (and only then)
allocate buffer. Basically, only net_context will uses that scheme
anyway.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Update reserved function names starting with one underscore, replacing
them as follows:
'_k_' with 'z_'
'_K_' with 'Z_'
'_handler_' with 'z_handl_'
'_Cstart' with 'z_cstart'
'_Swap' with 'z_swap'
This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.
Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.
Various generator scripts have also been updated as well as perf,
linker and usb files. These are
drivers/serial/uart_handlers.c
include/linker/kobject-text.ld
kernel/include/syscall_handler.h
scripts/gen_kobject_list.py
scripts/gen_syscall_header.py
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Though core system is able to manage packet timestamping internaly (gptp
requires it for instance), it might be necessary to enable/disable
packet timestamping from net context directly.
Currently this will be only used by the tx timestamp test. So this
support is disabled by default. (And gptp does not require it anyway).
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This is required if traffic class is enabled, so allocated packets from
net_context do get the right priority set.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
That can be useful on some tests which will not have any interface but
still allocate net_pkt. Also, one may allocate a packet with buffer not
knowing yet the interface it will be send through.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
subsys/net/lib/lwm2m/Kconfig.ipso is 'source'd within an 'if LWM2M', in
subsys/net/lib/lwm2m/Kconfig, so the 'depends on LWM2M' is redundant.
The 'depends on NET_IPV4' and 'depends on NET_L2_OPENTHREAD' are within
corresponding 'if's in the same file.
'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.
Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Some of these are from 'source'ing a file within a menu that has a
'depends on NET_L2_ETHERNET' (in drivers/ethernet/Kconfig) and then
adding another 'depends on NET_L2_ETHERNET' within it.
Similarly, subsys/net/l2/ethernet/Kconfig sources files within an
'if NET_L2_ETHERNET'.
'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.
Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This reverts commit 8cb5d083cb53627964ed72fb9fa3fb7a5219739f.
This was breaking tests on master due to missing dependency that is
still being reviewed.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This is done to conform with how the rest of the socket APIs are
implemented during socket offload. Otherwise link error would
result due to the symbol being redefined in lib/os/fdtable.c.
Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
As per RFC2131 4.1.1 requires we wait a random period
between 1 and 10 seconds before sending the initial
discover. But tests can not wait that longer. So this
option helps test to configure the value to minimum.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
No Kconfig symbol called NET_GPTP_STACK_SIZE has ever been defined in
the Zephyr repo. Drop the CONFIG_* prefix from the #define.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
We sometimes want to join a device to OpenThread mesh automatically.
This commit adds supports to do by Kconfig.
The default of CONFIG_OPENTHREAD_JOINER_PSKD is based on this page:
https://codelabs.developers.google.com/codelabs/openthread-hardware/
Signed-off-by: Takumi Ando <takumi.ando@atmark-techno.com>
If we receive the ARP request, then check if the ARP cache
contains an entry for this IP address already. If it does,
then update the MAC address in the cache.
Fixes#10188
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
These options are oftentimes used when implementing servers, and
thus required to port existing socket apps. These options are also
safe to just ignore, e.g. SO_REUSEADDR has effect only for repeated
recreation of server socket (not an expected usecase for a Zephyr
app), while TCP_NODELAY is effectively the default for Zephyr, as we
don't implement TCP buffering (aka Nagle algorithm).
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Multiple flag bits were set so the ACK flag set was not checked
properly which meant that connection establishment was not
successfull.
Fixes#13943
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
No need to hide the symbols in the header file if CONFIG_NET_LLDP
is not enabled. This also allows the documentation to be generated
properly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The ipv6_handle_ext_hdr_options() can return negative value
but we stored it into unsigned variable and then checked < 0.
Coverity-CID: 190995
Fixes#13830
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The LI bits checks is useless as the bitshifted value cannot be
larger than SNTP_LI_MAX (3).
Coverity-CID: 190924
Fixes#13888
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Found via Coverity CID 191001: Control flow issues (NO_EFFECT)
This less-than-zero comparison of an unsigned value is never true:
"put_char(out, '}') < 0U".
Let's fix this check to be less than 1 instead as it should have
been originally.
Signed-off-by: Michael Scott <mike@foundries.io>
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>
Some more were added since the cleanup pass in June 2018. See e.g.
commit 2d50da70a1 ("drivers: ipm: Kconfig: Remove redundant 'default n'
properties") for a motivation. It also avoids people wondering whether
or not they need to put in 'default n'.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The net-shell was using wrong config options for statistics
support. Also net_stats.h had wrong config used for IPv6 MLD
statistics.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Poll descriptor was not incremented in poll update function in case it
was reported as not ready. In result, poll could end up processing the
same poll descriptor for every fd requested to monitor.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Rework detection of EOF on a socket, so that it can be detected in a
poll prepare that socket is in in a EOF state and poll can return
immediately.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Unfortunately, most of the dns pack/unpack code is not factorized, and
mdns responder rewrites its own functions to write dns hdr, query,
answer.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Unfortunately, most of the dns pack/unpack code is not factorized, and
llmnr responder rewrites its own functions to write dns hdr, query,
answer.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
So instead of building the net_pkt by itself, dns will pass its message
buffer to net_context_sendto_new(), which in turn will build the net_pkt
relevantly.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Since net_context_sendto_new() does not take a net_pkt anymore, the only
way to set net_pkt's ttl/hop_limit is to pass it through net_context.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
dns_write was in the middle of this, let's just move it to a more
relevant place so we logically have macros, then local variables then
functions.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Some of dns_pack.c macros are also used in resolve.c, so let's just put
the macros in dns_pack.h
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Once the fraction value has been assigned a value, we can't move
the exponent any more.
Fixes erroneous values the binary32/64 formats.
Signed-off-by: Michael Scott <mike@foundries.io>
- differentiating actual "fragment" to buffer element from a net_pkt
- instead of copying data (and thus allocating buffer) let's just take
the fragment buffer and put it into result packet.
- fixing compilation issue in relevant test
It's more efficient that way, as we use already allocated fragment
buffer instead of reallocating/deallocating after each fragment
reception.
A possible optimization would be to calculate the actual size + header
difference if only the actual size is close to the target size.
It would avoid to get a dry run of the header decompression for each
fragment received. The difficulty being in finding the sweet spot when
it is relevant to calculate the header difference.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Since we don't want to redo the complex calculation, let's reuse the
uncompress functions, adding a dry_run possibility to those.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
When DTLS client was added to `poll` before/during the handshake, it
could throw errors and in some circumstances (when polling thread was
cooperative and had higher or equal priority to the handshake thread)
could lead to a deadlock in the application.
Prevent that, by blocking on handshake semaphore instead of fifo. Poll
will start using fifo for data poll only after handshake is complete.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Instead of simple bool value, use a semaphore to notify that TLS
handshake is complete. This way, we can monitor this value with k_poll.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Errno value is only significant when `recvfrom` function indicated an
error (by returning -1). We should not depend on it's value if no error
is notified.
As the return value of `recvfrom` is already checked, misused errno
verification can simply be removed.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
It simplifies things again, as it does not need to create the net_pkt by
itself anymore.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
When closing the socket, zsock_close_ctx() would call
net_context_accept() when the socket was in "LISTEN" state.
This would result in an error log message for "Identical
connection handler already found" because the connection
context was already created because the initial
zsock_listen_ctx() called net_context_accept() to set up
the socket at the beginning. This change adds a test to
check if the callback is NULL which indicates this
close state and avoids the error message.
Signed-off-by: david leach <david.leach@nxp.com>
The sending of the final FIN message was being put on the sent_list
to be handled by the retry logic and being sent directly. But in
the case of a socket that never had a connection, the logic after
the direct send would decrement the reference on the packet which
would cause the retry logic to eventually have a situation where
the pkt is on the sent_list queue but the buffer associated with
the packet is freed back to slab. The code would then get a null
pointer to the tcp header and would fault when setting the crc to
zero on frdm-k64f platform.
Fixes#13489, #13301
Signed-off-by: david leach <david.leach@nxp.com>
The TODO file contained some random nice to have features.
The file does not mention use cases for these and also currently
the new features are managed and discussed in github.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Maybe there is an easier way to fill in the buffer in one call from an
otMessage.
Switch "frag" keyword to "buf", as "frag" is now reserved for actual
packet fragmentation and not buffer.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Possible null pointer dereference when looking up the nexthop
neighbor.
Coverity-CID: 190639
Fixes#12294
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
ICMPv6 network packets are processed and consumed (if not dropped)
within `net_icmpv6_input` function. Therefore they shoud not be
passed to the `net_conn_input` function.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Macros are replaced by C++ friendly versions:
- SHELL_CREATE_STATIC_SUBCMD_SET by SHELL_STATIC_SUBCMD_SET_CREATE
- SHELL_CREATE_DYNAMIC_CMD by SHELL_DYNAMIC_CMD_CREATE
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
It is planned to deprecate SHELL_CREATE_STATIC_SUBCMD_SET macro
which is replaced by SHELL_STATIC_SUBCMD_SET_CREATE.
Additionally, removed irrelevant comments about alphabetical
ordering which is no longer needed.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This function is the opposite of getaddrinfo(), i.e. converts
struct sockaddr into a textual address. Normally (or more
specifically, based on the flags) it would perform reverse DNS
lookup, but current implementation implements only subset of
functionality, by converting to numeric textual address.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
`net_ipv6_finalize` expects packet cursor to be reinitialized in order
to finalize packet correctly. This commits adds missing cursor
initialization.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
A debug message told "Set EOF flag on pkt %p", but actually printed
net_context instead of net_pkt.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
In order to follow the BSD socket numbering of the network
interfaces, start numbering from 1. The index 0 is reserved
to mean any interface in BSD socket code.
Fixes#13084
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Make sure that network related functions are always documented.
This means keeping the prototype and possible stub together.
Fixes#12615
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
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>
Commit 44964c735e ("net/gptp: Switch GPTP to new net_pkt API") changed
the callback used for allocation (from net_pkt_get_reserve_tx to
net_pkt_alloc_with_buffer), but for compilation with
CONFIG_NET_DEBUG_NET_PKT_ALLOC enabled, both callbacks are used
(the first pointer was just overwritten, causing MPU FAULT).
This commit removes the extra callback and fixes the fault.
Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
Per Coverity report, oma_tlv_put() does pointer arithmetic accessing
the data as an array of u8_t. In put_bool() we get a singleton
pointer from the evaluation of: "value != 0 ? 1 : 0" which is
passed to put_s8() which in turn passes it to oma_tlv_put().
To avoid misinterpretation, let's create a temporary s8_t variable
to pass into oma_tlv_put instead.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12312
Signed-off-by: Michael Scott <mike@foundries.io>
The option CONFIG_NET_SOCKETS_RAW name was changed to
CONFIG_NET_SOCKETS_PACKET but two checks using the old name
was left to net_context.c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
shutdown() itself is described as just marking RX or TX path of a
socket as not available. For the first approximation, we implement
it just as a dummy function, to allow build existing POSIX
applications which use it.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Zero is a special value in the binary32/64 format. It has all zero
bits (sign=0, exponent=0 and fraction=0).
Handle this special case explicitly instead of trying to encode
in binary format which results in an incorrect value of 0.5.
Signed-off-by: Michael Scott <mike@foundries.io>
net_context uses net_pkt_alloc_with_buffer(), which sets the family and
protocol (according to parameters) so no need to set the family again.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Initial implementation of IPSO Timer object #3340
Based on: http://www.openmobilealliance.org/tech/profiles/lwm2m/3340.xml
"This IPSO object is used to time events and actions, using patterns
common to industrial timers. A POST to the trigger resource or On/Off
input state change starts the timing operation, and the timer
remaining time shows zero when the operation is complete. The
patterns supported are One-Shot (mode 1), On-Time or Interval
(mode 2), Time delay on pick-up or TDPU (tmode 3), and Time Delay
on Drop-Out or TDDO (mode 4). Mode 0 disables the timer, so the output
follows the input with no delay. A counter is provided to count
occurrences of the timer output changing from 0 to 1. Writing a value
of zero resets the counter. The Digital Input State resource reports
the state of the timer output."
NOTE: Only One-Shot Mode (mode 1) is implemented in this patch.
Signed-off-by: Michael Scott <mike@foundries.io>
During the initial work on LwM2M, the float32/64 code was
basically stubbed out. Float32 sent only whole values and
float64 was completely broken.
Let's clean up the OMA TLV formatting code by moving the float
processing code into a separate file: lwm2m_util.c.
Then using public definitions for binary32 and binary64, let's
fix the processing code to correctly fill the float32_value_t
and float64_value_t types.
Signed-off-by: Michael Scott <mike@foundries.io>
Now that legacy net_pkt_pull function has been removed, the new
function can be renamed accordingly.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Now that the stack uses the new API from net_pkt for pulling, no need
to keep the legacy one around.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Now that legacy net_pkt_clone function has been removed, the new
function can be renamed accordingly.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>