Commit Graph

8409 Commits

Author SHA1 Message Date
Vinayak Kariappa Chettimada 0a23b1248f Bluetooth: controller: Remove is_enabled flag for BIS events
Remove is_enabled flag in LLL of BIS events context, as the
status returned from ticker_stop interface is sufficient to
determine if the Broadcast ISO Sync was established or not.
HCI Command Disallow as reason is to be returned if sync was
not established or sync was loss prior to call of HCI LE
BIG Terminate Command was called.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-04 16:27:58 +01:00
Vinayak Kariappa Chettimada 30740b4397 Bluetooth: controller: Move lll_sync_iso.h common to all vendors
Move lll_sync_iso.h as common to all vendors, as currently
there is nothing that is vendor specific.

Fixes #31044.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-04 16:27:58 +01:00
Flavio Ceolin 91715afa20 power: Reducing the scope of a private function
Setting pm_policy_mgr static.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-04 09:02:23 -05:00
Flavio Ceolin 8fe3866e19 power: rename _pm_power_state_ -> pm_power_state
Leftover from old renaming commits. This function is not private and
should not start with underscore.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-04 09:02:23 -05:00
Daniel Leung 6ab4886506 timing: fix timing_stop() ref counting
When there are more timing_stop() calls then timing_start(),
the reference counter will go negative, resulting in the next
timing_start() call not starting the timer. Without timer
running, getting cycles elasped would not work. So fix
the ref counting so it won't dip below zero.

Fixes #30397

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-01-04 12:15:30 +01:00
Peter Bigot d489765be4 net: dhcp: correct timeout scheduling with multiple interfaces
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>
2021-01-04 10:02:58 +02:00
Peter Bigot b4ed597afe net: dhcp: fix timeout on entry to bound state
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>
2021-01-04 10:02:58 +02:00
Peter Bigot 65183422c7 net: dhcp: correct timeout calculation with multiple interfaces
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>
2021-01-04 10:02:58 +02:00
Peter Bigot 2c813bc620 net: dhcp: fix invalid timeout on send failure
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>
2021-01-04 10:02:58 +02:00
Peter Bigot 508496f73b net: dhcp: rename variable for clarity
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>
2021-01-04 10:02:58 +02:00
Peter Bigot 07c5d2fe18 net: dhcp: avoid undefined behavior when assertions disabled
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>
2021-01-04 10:02:58 +02:00
Peter Bigot 5da984e890 net: dhcp: fix bounds check in timeout
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>
2021-01-04 10:02:58 +02:00
Peter Bigot d44b4252b7 net: dhcp: clear option state when selecting
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>
2021-01-04 10:02:58 +02:00
Peter Bigot 403c4974b0 net: dhcp: remove incorrect sign check
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>
2021-01-04 10:02:58 +02:00
Peter Bigot 7e77370acb net: dns: review use of k_work APIs
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>
2021-01-04 10:01:47 +02:00
Luiz Augusto von Dentz 64cc5a3746 Bluetooth: GATT: Fix BT_GATT_AUTO_DISCOVER_CCC
When using BT_GATT_AUTO_DISCOVER_CCC if the ccc_handle is not set
bt_gatt_subscribe would initiate a discovery to locate the CCC handle
but instead of awaiting it to complete the code does proceed to call
gatt_write_ccc even with ccc_handle being 0x0000 which is invalid.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-12-27 18:20:28 +01:00
Peter Bigot 5b544e115b fs: littlefs: define mount point structures for file systems
Use the devicetree filesystem bindings to populate an fs_mount_t
object that is preconfigured for a particular set of file system
properties on a specified partition.

At this time the mount point data is accessed by reference using the
partition's devicetree node identifier.

Note: While a file system can register itself before its devices
are available, it cannot do the automount.  In this commit the
initialization priority is increased to compensate, but that's not
a long-term solution.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-27 18:16:20 +01:00
Peter Bigot e571c88565 devicetree: flash-partitions: expose helper macros
Make generally available the macro that provides the flash device in
which a particular partition can be found.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-27 18:16:20 +01:00
Hubert Miś ade40136ea net: resolve literal IP addresses even when DNS is disabled
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>
2020-12-22 15:44:00 +02:00
Michael Rosen 1c89837e79 usb: dfu: add separate pid for dfu mode
Refactor the file structure for USB DFU class to facilitate
separate PID for USB DFU when in DFU mode. As required by USB DFU
1.1 Section 2, the PID in the USB device descriptor must be
different between the Run-time and DFU mode device descriptor to
avoid problems caused by the host OS caching the remaining
descriptors when switching to DFU mode, thus hiding the new
interface descriptors from applications on the host and reporting
the Run-time descriptors when the device is in DFU mode.

To avoid adding too much clutter to the root USB class Kconfig and
CMakeLists files, move the DFU class files into their own directory
with dedicated Kconfig and CMakeLists.txt.

Signed-off-by: Michael Rosen <michael.r.rosen@intel.com>
2020-12-20 13:04:45 -05:00
Michael Rosen d92ee92c95 usb: dfu: change device descriptors after reset
The USB device descriptors for DFU mode should only change after a
USB reset, not in appDETACH as the device is still in run-time mode
until reset; thus should still return the run-time descriptors when
requested.

Signed-off-by: Michael Rosen <michael.r.rosen@intel.com>
2020-12-20 13:04:45 -05:00
Michael Rosen c58d201086 usb: dfu: add timer for appDETACH
In accordance with USB DFU 1.1 Section 5.1, a device should only
stay in appDETACH for a given period of time, either from the
DFU_DETACH request (wValue ms) or from the wDetachTimeout property,
after which the device should return to appIDLE.

Signed-off-by: Michael Rosen <michael.r.rosen@intel.com>
2020-12-20 13:04:45 -05:00
Andrzej Kaczmarek f8c8cac714 Bluetooth: controller: Use PHY_xxx symbols consistently
We have convenient PHY_1M, PHY_2M and PHY_CODED symbols defined but
they are not used too much in the code. This replaces all usages of
magic numbers and other symbols as PHY constants with those symbols.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-20 13:04:13 -05:00
Emil Gydesen 9a3f863637 Bluetooth: host: Assert conn ref counter on unref
Adds an assert on the "old" ref counter when doing unref, that
checks if there indeed is a reference to unref. This prevents
any underflows of the ref counter.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-20 13:02:44 -05:00
Martin Jäger 6fd8cbb9b4 storage: stream: flash: update log output
LOG_DBG is more appropriate for this logging output than LOG_INF.

Signed-off-by: Martin Jäger <martin@libre.solar>
2020-12-20 12:40:19 -05:00
Emil Gydesen 47aa17bb5c Bluetooth: controller: Implements ULL Sync ISO ticker
Implements the ull_sync_iso_setup function which starts the
ticker for ISO sync. Furthermore, ll_big_sync_terminate
will not stop the ticker as well.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-20 13:36:50 +01:00
Emil Gydesen 9d4d6d06a0 Bluetooth: controller: Implements BIG sync commands in the ULL
Implements handling of the BIG sync commands in the ULL.
LLL support and handling of ACAD (biginfo) remaining.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-20 13:36:50 +01:00
Vinayak Kariappa Chettimada e603b9d59e Bluetooth: controller: Adjust PPI used for nRF51x and nRF52x
Adjust the PPI used by nRF51x and nRF52x so that PPI 0-5 is
available for application's use or for SW PWM driver use.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-20 13:36:09 +01:00
Morten Priess 467fd155a8 Bluetooth: controller: Make must-expire runtime configurable
Under CONFIG_BT_TICKER_EXT configuration, the ticker interface has been
extended to support enabling/disabling must-expire scheduling. This
means that conn and slave ticker start calls can now omit must-expire
default-on configuration, relying on LLL updating the mode as needed.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-12-20 13:35:58 +01:00
Dominik Ermel d83875f32a power: Idle depends on system clock when power management enabled
The idle, when power management is enabled, requires system clock to
be present.
This commit adds dependency, to PM option, on SYS_CLOCK_EXISTS.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-12-19 21:05:45 -05:00
Kumar Gala 82767ef3bb bluetooth: Convert DEVICE_AND_API_INIT to DEVICE_DEFINE
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>
2020-12-19 20:01:42 -05:00
Kumar Gala 4dd7aa6392 usb: Convert DEVICE_AND_API_INIT to DEVICE_DEFINE
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>
2020-12-19 16:58:00 -05:00
Rafał Kuźnia 3bf526beea net: openthread: add shell dependency to OPENTHREAD_SHELL
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>
2020-12-18 12:56:33 -05:00
Kumar Gala d47721d5cd usb: audio: Convert drivers to new DT device macros
Convert usb audio drivers from:

    DEVICE_AND_API_INIT -> DEVICE_DT_DEFINE

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-18 07:50:49 -06:00
Joakim Andersson cc470a2bd6 Bluetooth: host: Use smaller alignment for slab.
The slabs in ATT are using a slab alignment of 16, when only
4 is required on 32-bit.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-18 10:29:59 +01:00
Robert Lubos ae35d3000f net: openthread: Fix missed logging macro usage
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>
2020-12-17 20:58:00 +02:00
Joakim Andersson adeca565f8 Bluetooth: host: Use uintptr when checking for valid index
Align bt_le_per_adv_sync_get_index, bt_conn_index and
bt_le_ext_adv_get_index in use of uintptr_t.

This fixes an issue where the cast to uint8_t happened before the
assert for a valid index, which could lead to invalid pointers passing
this assert.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-17 17:16:34 +02:00
Joakim Andersson 9fee4d7ffd Bluetooth: SMP: Improve logging of unspecified pairing failure
Improve logging of pairing procedure when it fails with error code
unspecified. Since this is returned in many places debugging this
failure is not easy without adding additional debugging.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-17 12:42:22 +01:00
Joakim Andersson a01a619480 Bluetooth: SMP: Check return value of bt_rand
Add check of bt_rand return value and do not proceed in case of error.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-17 12:42:22 +01:00
Joakim Andersson d138790826 Bluetooth: SMP: Fix parallel pairing needing DHKey at the same time
Fix parallel pairing procedures using LE SC requiring the DHKey
calculation at the same time. This would otherwise end all other
pairing procedures with the SMP error code "unspecified" since
the call to bt_gen_dh_key would fail.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-17 12:42:22 +01:00
Joakim Andersson ad96ae0398 Bluetooth: SMP: Set allowed commands before sending the SMP packet
Set the allowed command bitmask before sending the SMP packet. This
avoids a race-condition in case the sending of the PDU made the
current thread not ready and would not be scheduled back in time
to set the bit before receiving the next SMP packet.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-17 12:42:22 +01:00
Joakim Andersson d04e19731e Bluetooth: host: Improve multiple DHKey handling
Improve multiple DHKey handling by allowing the next DHKey calculation
to be started in the dhkey ready callback.
Return error code EALREADY if the provided callback is the current
callback generating the DHKey.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-17 12:42:22 +01:00
Andrzej Kaczmarek 07bb612875 Bluetooth: controller: Call lll_adv_aux initialization funcs
lll_adv_aux_init and lll_adv_aux_reset were not called anywhere.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek 07ebf3d06d Bluetooth: controller: Release resources on failed AUX_CONNECT_RSP
We allocate nodes on receiving AUX_CONNECT_REQ, but we can only use
them if AUX_CONNECT_RSP is sent successfully. If that fails, we need
to release those nodes.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek 3fc74be7e7 Bluetooth: controller: Allow to simply release node allocated in LLL
If we allocate a node in LLL and it turns out that we don't need it
(e.g. allocated connection on AUX_CONNECT_REQ, but connection handshake
did not complete and we don't need it) we still need to send it to ULL
to be released. We can use existing NODE_RX_TYPE_DC_PDU_RELEASE node
type for this purpose, but we just need to make sure it's passed from
LLL to ULL properly.

Also, since this now does not only release DC PDUs, let's change its
name to a more generic one.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek 98d7adc30d Bluetooth: controller: Stop aux after connected
After slave connection is created only adv instance is stopped, we also
need to stop aux separately if enabled.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek 88a8fc1d5e Bluetooth: controller: Make global helper to get aux handle
Just make local function a global one, we need this in other files
as well.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek 01448bf378 Bluetooth: controller: Fix phy initialization when enabling adv
Make sure phy is properly initialized to 1M when ext adv is supported
and legacy advertising instance is being enabled.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek dd102e61c0 Bluetooth: controller: Add support for connectable ext adv
This adds handling for received AUX_CONNECT_REQ PDU which enables slave
connection with extended advertising.

Once AUX_CONNECT_REQ is received, standard checks are performed to
determine if we have resource to create connection, however unlike for
CONNECT_IND an rx node is temporarily kept in LLL until AUX_CONNECT_RSP
is successfully sent. This is to prevent creating a connection in case
response PDU was not sent for whatever reason.

A separate scratch buffer is created for AUX_CONNECT_RSP since default
radio scratch buffer is already used by received AUX_CONNECT_REQ.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek 2709c2c79a Bluetooth: controller: Initialize conn for connectable ext adv
Connection structs need to be initialized when advertising is enabled
on connectable extended advertising instance.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00