Commit graph

21541 commits

Author SHA1 Message Date
Jan Van Winkel
4a9a49a185 ztest: Added support to return data via mock
Added support to mock framework to return data via function parameters

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2021-03-09 07:09:13 -05:00
Pete Skeggs
cb5ca42a0e debug: coredump: improve delayed logging
If CONFIG_LOG_IMMEDIATE=n, go to panic mode with LOG_PANIC() so full
coredump is logged.

Add missing log_strdup() call.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2021-03-09 07:04:56 -05:00
Jukka Rissanen
2ce87533aa net: tcp: Implement ISN calculation according to RFC6528
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>
2021-03-09 04:54:14 -05:00
Peter Bigot
6a81a99724 Bluetooth: controller: update k_work_pending to new API
k_work_pending is now called k_work_is_pending.

These two uses are correct assuming the functions that invoke them are
not involved in race conditions: that the work is not pending is an
allowed condition for modifying state that will be used by the work
handler.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-09 04:52:23 -05:00
Trond Einar Snekvik
dc6e880eab Bluetooth: Mesh: Remove unsigned typing to returns in heartbeat
Removes U-suffix from signed return codes in heartbeat.c.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Trond Einar Snekvik
f9d41595a3 Bluetooth: Mesh: Explicitly ignore gatt_service_register return code
The error code from gatt_service_register is being ignored to ensure
that repeated actions still complete. Do this explicitly by adding
(void) casts, resolving coverity warnings on accidental error code
ignores.

Fixes #33051.
Fixes #33074.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Trond Einar Snekvik
aef354c6bc Bluetooth: Mesh: Resolve dead code in store_seg
If CONFIG_BT_MESH_SEQ_STORE_RATE is 1, the check in store_seq can be
reduced to a simple if (false), and the modulo code does not need to be
included in the build.

Fixes #33036.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Trond Einar Snekvik
bba2d7b84b Bluetooth: Mesh: Check model publish pointer before dereferencing
Moves the if !(pub) check to happen before it gets used in the
initialization of the message context in bt_mesh_model_publish.

Fixes #5116.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Trond Einar Snekvik
7039675df1 Bluetooth: Mesh: Only do label lookup when there are labels
Include virtual label's pending_store function in the LABEL_COUNT > 0
compile guard to avoid including dead iteration code in the compilation.

Fixes #32928.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Trond Einar Snekvik
8309353b7f Bluetooth: Mesh: Check subnet existence in heartbeat_send
Check that the assigned subnet hasn't been removed in heartbeat_send to
avoid potential NULL defererence in transport's ctl_send.

Fixes #32907.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Pete Skeggs
5f2e3998d1 shell: kernel: also print the thread entry pointer
Sometimes it is hard to tell which instance of a thread is which
in the printed list, based solely on the name (if present) and
the k_thread pointer, so also print the thread entry fn pointer.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2021-03-08 12:52:47 +01:00
Vinayak Kariappa Chettimada
05c69098e0 Bluetooth: controller: Comment on conn context reuse for coded PHY
Added comments to explain the re-use of allocated same
connection context to both 1M and coded PHY scanning context
when both PHY is enabled for initiating connection.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-08 12:52:09 +01:00
Vinayak Kariappa Chettimada
cffaf26f23 Bluetooth: controller: Extended create connection cancel
Initial work in progress implementation of Create Connection
Cancel for Extended connection initiation.

Adds implementation to teardown connection initiated at ULL
layer and gracefully release allocated resources.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-08 12:52:09 +01:00
Jukka Rissanen
7e1ae869e4 net: context: Remove unnecessary null check
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>
2021-03-08 13:26:00 +02:00
Flavio Ceolin
98dbea0979 power: Get rid of deep sleep and sleep concepts
New power states have more granularity than deep sleep and sleep
states. Just get rid of this and keep the same behavior for now.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-07 07:59:53 -05:00
Flavio Ceolin
741141e464 power: Send state changes notification after device PM
Currently the power subsys is sending notifications about power state
changes before doing device pm. If one device fails to low power or
suspend the system never goes to an idle state. Change to send
notifications just before call SoC to suspend and avoid misleading
information.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-07 07:59:53 -05:00
Flavio Ceolin
e2771340af power: Remove unnecessary pm_idle_exit_notification_disable api
This function is useless and the state variable that it was
controlling is also not necessary because the same logic is being
handled by the variable post_ops_done.\

This reasonably simplifies idle thread logic.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-07 07:59:53 -05:00
Flavio Ceolin
af99c90cac power: Remove unnecessary pm_system_mgr function
There is no need for this function. This function is called only in
one place and the code can be moved to the function that was calling
it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-07 07:59:53 -05:00
Flavio Ceolin
5c5172ddae power: Effectively allow forcing a state
pm_power_state_force had two different behavior, if
CONFIG_PM_DIRECT_FORCE_MODE was enabled this function immediately
calls pm_system_suspend() without wait the idle thread. Without this
option enabled, this function will wait for the idle thread run but
will use the given power state instead of asking the policy manager.

The problem in both cases is that the process involves handling
devices and the way that was implemented if at least one device failed
to go to low power or suspended the system power state would not
change / be forced.

This commit simplifies this API removing the conditional behavior
since it is not clear the need for that and effectively, and
immediately, forces the system to go to the given state without
bother with devices.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-07 07:59:53 -05:00
Marek Porwisz
19727d3c34 ipc: Make log level configurable for RPMsg service and backend
The PRMsg service and backend had hardcoded and incorrectly named log
level. Created the Kconfig options for configuring log level of this
module.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2021-03-06 09:09:50 -06:00
Wolfgang Puffitsch
18f5fb99c1 Bluetooth: controller: Remove use of lll_stop
Remove use of lll_stop and lll_is_stop and rely on "initiated" flag in
lll_conn struct instead.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-03-06 09:32:42 -05:00
Wolfgang Puffitsch
5ce5dc055e Bluetooth: controller: Avoid race between ULL and LLL when initiating conn
Use an "initiated" flag in the lll_conn struct to guard the processing
of PDUs related to connection initiation (CONNECT_IND,
AUX_CONNECT_RSP). This avoids races between ULL and LLL when creating
a connection.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-03-06 09:32:42 -05:00
James Harris
6fd147b612 net: config: ensure counter k_sem init'd before reset
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>
2021-03-06 07:39:43 -05:00
Julien Massot
80402f7f8b tracing: add RAM backend
If Zephyr is running on a coprocessor we might lack I/O
such as uart or usb to output tracing datas but we might
have gigabytes of RAM available.

This patch allows to output trace datas to a ram buffer, which then
may be retrieved using gdb.

e.g:
(gdb) dump binary memory channel0_0 <ram_tracing_start> \
<ram_tracing_end>

Signed-off-by: Julien Massot <julien.massot@iot.bzh>
2021-03-06 07:33:59 -05:00
James Harris
b10428163a kernel: sem: add K_SEM_MAX_LIMIT
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>
2021-03-05 08:13:53 -06:00
Pete Skeggs
61e0e14df1 shell: improve help for conditional commands
If a shell command is compiled out using SHELL_COND_CMD(),
a line for this command will still be printed but will
be blank. Change it so compiled out commands are not
listed as blank lines.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2021-03-05 15:35:16 +03:00
Pete Skeggs
e0de4ff227 net: mqtt: log struct mqtt_utf8 with hexdump
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>
2021-03-05 12:49:22 +02:00
Spoorthy Priya Yerabolu
6d10db3ed6 Coding guideline: Fixing code violations for 21.13 Rule
Any value passed to a function in <ctype.h> shall be
representable as an unsigned char or be the value EOF.

So changed type of variable to unsigned char.

Signed-off-by: Spoorthy Priya Yerabolu <spoorthy.priya.yerabolu@intel.com>
2021-03-05 10:53:13 +03:00
Peter Bigot
7b8bce898f net: openthread: radio: switch to new API for k_work_pending
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>
2021-03-04 18:00:56 -05:00
Peter Bigot
e373004135 net: tcp: switch to new API for k_work_pending
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>
2021-03-04 18:00:56 -05:00
Peter Bigot
4817a41484 net: ip: remove incorrect check of work item status
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>
2021-03-04 18:00:56 -05:00
Robert Lubos
7f3537f0d3 net: lwm2m: Initialize the variable to silence compiler warning
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>
2021-03-04 14:53:05 -05:00
Jukka Rissanen
d07c1c500b net: conn_mgr: Ignore network interfaces that are not used
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>
2021-03-04 14:52:35 -05:00
Jukka Rissanen
1ccc67f759 net: conn_mgr: Print network interface index in debug
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>
2021-03-04 14:52:35 -05:00
Jukka Rissanen
924e433ffb net: context: Set target network interface in send if needed
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>
2021-03-04 16:05:52 +02:00
Joakim Andersson
45da9d3962 Kconfig: logging: Improve defaults for Bluetooth
Improve default logging strdup buffer count and size.
The maximum string logged with Bluetooth is a 32-byte key in hex.
The strdup buffer is empty too often.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-04 14:20:25 +02:00
Joakim Andersson
200f4687e0 Bluetooth: host: Log security keys needed by sniffer
Log the security keys that the sniffer needs in order to sucessfully
decrypt the connection.
This option allows the sniffer to work in the cases where enabling
using the SMP debug keys is not wanted, either because it changes the
way the peer behaves or is denied by the peer.
It also enables the sniffer to decrypt a connection where the bond
already exists.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-04 14:20:25 +02:00
Joakim Andersson
acd0555f50 Bluetooth: host: Convert allowed_cmds to an array of atomic_t of size 1
Convert allowed_cmds to an array of atomic_t of size 1.
This makes it future proof in case more commands are added.
Possibly silences coverity false positives on array vs singleton usage.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-04 13:11:47 +01:00
Lingao Meng
e5bee34b39 Bluetooth: Mesh: Fix cfg_cli Format and CID use problem
Fix some format warning in cfg_cli.c.
Fix use CID_VNAL as param when use vendor models.

This is a resubmission of PR (#30086)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-03-04 14:10:56 +02:00
Lingao Meng
e0d2309589 Bluetooth: Mesh: Fix config message result print format
Add line breaks to make the results more intuitive

This is a resubmission of PR (#30086)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-03-04 14:10:56 +02:00
Lingao Meng
71fd8e1d01 Bluetooth: Mesh: Add CDB handle key refresh phase
Fixed some undesired or incorrect macros, which
can cause build error.

This is a resubmission of PR (#30086)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-03-04 14:10:56 +02:00
Lingao Meng
0841ee69f2 Bluetooth: Mesh: Fix provisioner provisioning
Correct format errors, such as oob action 2-octers
should use 0x%04x, and action in prov capalilities pdu
big-ending. When every call `bt_mesh_auth_method_set<*>`
should also clear auth value, otherwise will case confirm
failed.

Provisioner role expect peer public key should be sent
immediately, instead of requiring ACK. After all, ACK may
be lost, and the other device’s public key will be sent
over, and provisioning procedure will be failed..

This is a resubmission of PR (#30086)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-03-04 14:10:56 +02:00
Dominik Ermel
d0017e9e5e fs: shell: Remove unneeded flags from fs_open calls
The cmd_write and cmd_ctunc have been opening/creating file for
read/write operation.
The commit changes cmd_write to open/create file for write only,
and cmd_trunc to only open file for write.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-04 06:10:58 -05:00
Peter Bigot
b706a5e999 kernel: remove old work queue implementation
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>
2021-03-03 20:06:00 -05:00
Peter Bigot
753d56dd7b net: tcp2: work around limitations of legacy API
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>
2021-03-03 20:06:00 -05:00
Jim Paris
ffec5aa7f7 ppp: add net events for PPP dead and running
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>
2021-03-03 15:56:13 +02:00
Dominik Ermel
32451230e2 storage/stream/flash: Failed write of reminder rewinds buffer offset
The stream_flash_buffered_write, when invoked to do flush write, will
attempt to write the tail bytes from the buffer, filling the required
minimal write block size with erase value bytes; after write it rewinds
the buffer offset, bytes_written, by number of the "filler bytes".
Doe to lack of return code processing from flash_sync call, two things
would happen to context in case of failure:
 1) the ctx->bytes_written would be rewind pass the value it had before
    function call as it gets decremented by "filler bytes" even if write
    failed;
 2) the ctx->buf_bytes offset would be accounting for added "filler
    bytes" which should not be counted as data in buffer.

Proper processing of return code has been added to remove effects
described above.

Unit tests have been expended to cover the scenarios.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-03 11:40:11 +03:00
Dominik Ermel
07107f92c7 storage/stream/flash: Use flash_get_parameters to get flash erase_value
The stream_flash_buffered_write used to read byte from flash, in front
of the current buffer pointer, to obtain value of errased flash;
the code has been replaced with obtaining the value from flash
parameters.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-03 11:40:11 +03:00
Dominik Ermel
5a1750b053 storage/stream/flash: flash_sync: Check if there is anything to write
The commit moves block that checks if flash_stream_ctx.buf_bytes
is non-zero out of CONFIG_STREAM_FLASH_ERASE specific code,  as that is
universal check and is valid also for not CONFIG_STREAM_FLASH_ERASE
code.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-03 11:40:11 +03:00
Dominik Ermel
cfb056901c storage/stream/flash: Fix flash_sync updating bytes_written on failure
The flash_sync function is able to call, if specified, write
verification callback to check whether data flash has been correctly
written to a flash.  Part of that procedure is to read date back of
the flash and call the verification callback on the buffer;
in case if the read would fail, the flash_sync would return,
with an error code, without updating stream_flash_ctx.

The same logic should be applied to failed verification, but, due to
missing return, the stream_flash_ctx gets updated with probably
incorrectly written bytes added to total bytes_written and buf_bytes,
representing number of bytes awaiting in buffer, being zeroed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-03 11:40:11 +03:00