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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>