rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.
Rename it to random.h and get consistently with other
subsystems.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
The websocket_connect api expects connected tcp socket, do not close
the user supplied socket so that the caller can re-use it if needed.
Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
Coverity reported potential issues with implicit signed/unsigned type
conversions and potential problems with this. Fix this, by casing the
byte-shifted data variable to uint64_t type explicitly.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Although websocket_recv_msg function accepts timeout parameter, the
functionality was rather limited, allowing only to either work in
non-blocking manner, or to block indefinitely. Any timeout value
other than -1 (forever) ended up in non-blocking operation.
This PR fixes this by implementing a basic timeout mechanism, built on
top of poll(). For now on, only timeout of 0 will result in non-blocking
operation, any other timeout will make the function block for the
specified amount of time.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Instead of passing the test parameters to the websocket function, by
casting the pointer to integer (which may not work on 64-bit platform
due to int/pointer size mismatch), let the test allocate a file
descriptor, and initialize it with test context. The tested functions
expect a file descriptor as an argument anyway, so it's a more intuitive
approach.
The conditional test code within WS implementation can retrieve the test
context by using FD APIs to obtain the object represented by the FD.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In the header the websocket protocol needs a SHA1 hash. This is
implemented using the mbedtls_sha1 function. Select the option
MBEDTLS_MAC_SHA1_ENABLED from the Kconfig of websocket to ensure this
function is build in.
Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
The websocket implementation did not comply with the RFC 6455 when it
comes to connection close. The websocket should send in such case Close
control frame. This commit fixes this behaviour.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The websocket "socket" layer did not handle ZFD_IOCTL_SET_LOCK command,
and just forwarded it to the underlying socket. This overwritten the
mutex pointer used by the underlying socket, resulting in erroneous
behaviour in certain cases.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
websocket_recv_msg() is reworked with using fsm. Now the function
return 0 when payload is empty, -ENOTCONN if socket close. Receiving
empty ping and sending empty pong were added in tests.
Fixes#52327
Signed-off-by: Grixa Yrev <grixayrev@yandex.ru>
Some minor housekeeping prior to adding an http server
implementation. There are already a number of http headers
and that number will likely increase with subsequent work.
Moving them into a common directory cleans up the
`include/net` directory a bit.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
When the websocket_prepare_and_send is called from websocket_send_msg,
the header length is subtracted to retrieve the transmitted payload length.
Make an exclutsion to prevent the return code of
websocket_prepare_and_send being modified in case of 0 or a negative
return code.
This avoid confusion with modificated error codes
Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Remove network specific default and max log level setting
and start to use the zephyr logging values for those.
Remove LOG_MODULE_REGISTER() from net_core.h and place the
calls into .c files. This is done in order to avoid weird
compiler errors in some cases and to make the code look similar
as other subsystems.
Fixes#11343Fixes#11659
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Adding spaces around "=" when definining Kconfig template so
that is more consistent with overall style of these template
variables.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.
The only directory excluded directory was ext/* since it contains
only imported code.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Bool symbols implicitly default to 'n'.
A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.
Remove some 'default ""' properties on string symbols too.
Also make definitions more consistent by converting some
config FOO
<type>
prompt "foo"
definitions to a shorter form:
config FOO
<type> "foo"
This shorthand works for int/hex/string symbols too, not just for bool
symbols.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This removes some tricky math to calculate lengths and offsets,
ensuring that, when appending the WebSocket UUID to the handshake
key, the key_accept buffer won't overflow.
Coverity-ID: 183057
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
Rewrite prepare_reply() to reduce unnecessary string copies and calls
to net_pkt_append_all(). Also reduces some of the tricky string length
calculations.
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
There was not enough space for \0 at the end of the string.
Coverity-CID: 183057
Coverity-CID: 183050
Fixes#6675Fixes#6682
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit creates a websocket library that can be used by
applications. The websocket library implements currently only
server role and it uses services provided by net-app API.
The library supports TLS if enabled in configuration file.
This also adds websocket calls to HTTP app server if websocket
connection is established.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>