Commit graph

2878 commits

Author SHA1 Message Date
Carles Cufi 6656214af2 boards: nrf52_pca10040: Rename to nrf52dk_nrf52832
The board name for the nRF52 DK, so far known as nrf52_pca10040, is
renamed to nrf52dk_nrf52832.  Its documentation and all references
to its name in the tree are updated accordingly. Overlay and
configuration files specific to this board are also renamed, to
match the new board name.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-04-06 13:09:07 +02:00
Jordan Yates a038dc76f1 bluetooth: host: Dynamic bt_conn_le_create timeout
Extends the bt_conn_le_create_param struct to provide the option
to set a custom timeout for the initiation of the connection.

The logic for the default values of window_coded and interval_coded
were moved to conn.c in order to resolve all defaults for the
create_param struct at a single location.

Timeout is not added as a parameter to the BT_CONN_LE_CREATE_PARAM
macro due to the expectation that CONFIG_BT_CREATE_CONN_TIMEOUT
will be the typical value that users will expect.

Fixes #23468

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-04-06 13:29:49 +03:00
Lingao Meng 3b4d58aa4b Bluetooth: Mesh: optimize performance for lpn node
Fixed overflow risk when `poll_timeout` is 1s,
although it is not recommended to use it like this,
when it is used like this, `POLL_TIMEOUT_MAX`
will overflow.

When the poll timeout set like above, the default `6`
req_attemps for first pull request lost,
may cause this procedure bigger than poll_timeout,

Well, stop scanning when lpn terminated friendship,
this will save lots of energy, when lpn mode enable,
the scanning will be start after `FRIEND_REQ_RETRY_TIMEOUT`

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-04-06 11:33:51 +03:00
Joakim Andersson 7ab754d997 Bluetooth: SMP: Fix bond lost on pairing failure.
Fix an an issue where established bonding information in the peripheral
are deleted when the central does not have the bond information.
This could be because the central has removed the bond information, or
this is in fact not the central but someone spoofing it's identity, or
an accidental RPA match.

This is a regression from: a3e89e84a8

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-05 14:32:56 +03:00
Joakim Andersson 7b2f9d929f bluetooth: fix signed and unsigend comparison warnings
Fix instances of:
warning: comparison between signed and unsigned integer expressions
[-Wsign-compare]

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-03 18:06:59 -04:00
Johan Hedberg 71eb56a34c net: buf: Move LEGACY_TIMEOUT_API selection to specific subsystems
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>
2020-04-03 23:17:53 +03:00
Vinayak Kariappa Chettimada 4547bfb452 Bluetooth: controller: split: handle latency for cancelled conn events
Update implementation of master and slave LLL's to correctly
handle event counter values when latencies introduced due to
connection events cancelled by active events operating in
unreserved time space.

When an active radio event extends into unreserved time
space, and a connection event prepare is scheduled but at
the time of pre-emption timeout if the connection event is
cancelled then the event count and latencies needs to be
continiued to get acummulated.

In the current controller usecases the above scenarios does
not get exercised, the changes in this commit is needed for
future roles that can extend into unreserved time space and
would cancel a scheduled connection event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-03 22:10:40 +02:00
Joakim Andersson 93f644e1c0 Bluetooth: Use zd print conversion modifier for ssize_t
Use the zd print conversion modifier for ssizet_t variables.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-03 21:13:14 +03:00
Joakim Andersson 3baccee472 Bluetooth: tests: Add additional build configurations
Add additional build configurations to the shell to catch build errors
when enabling extended advertising.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-03 21:13:14 +03:00
Joakim Andersson a167e08910 Bluetooth: host: Fix compilation issue when privacy is disabled
Fix compilation issue when extended advertising is enabled but privacy
is disabled. In this case the rpa_update work is compiled out.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-03 21:13:14 +03:00
Peter Bigot ecf3bdb5b3 coccinelle: re-run timeout conversion semantic patch
Run the int_literal_to_timeout Coccinelle script to fix places where
it is clear that an integer duration is being passed where a timeout
value is required.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-02 19:47:51 +03:00
Joakim Andersson d751e09652 Bluetooth: host: Add parentesis around bitmask expression
Add parentesis around bitmask expression.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-02 19:39:28 +03:00
Joakim Andersson f8017adf5c Bluetooth: Use ssize_t for the return value of read_cb
Most places used an int so that should have handled most cases but
keys_set was using an unsigned int, which meant that checking len > 0
is an expression that is always false, and the error handling is not
working.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-02 19:39:28 +03:00
Joakim Andersson 21c37a6c6a Bluetooth: mesh: Remove redundant expression
Remove checking of the same argument twice.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-02 19:39:28 +03:00
Johan Hedberg 329d5908a2 Bluetooth: Mesh: Fix dereferencing pointer before checking for NULL
The publication context is checked for NULL in bt_mesh_model_publish()
however it was dereferenced before that. Move the assignment to
ctx.send_rel to the same place where other ctx members are set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-04-02 17:44:50 +03:00
Vinayak Kariappa Chettimada b7e35ae4a3 Bluetooth: controller: legacy: Fix slave latency during conn update
Fix regression in cancelling slave latency during Connection
Update Procedure.

Slave latency should not be applied between the ack of a
Connection Update Indication PDU and until the instant.
When caching was introduced, implementation missed this
consideration.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:41:00 +02:00
Vinayak Kariappa Chettimada fd343ee3c8 Bluetooth: controller: nRF: Revert use of ticker compat mode as default
Ticker is now fixed to avoid catch up of periodic timeout under
large ISR latencies.

Revert commit a749e28d98 ("Bluetooth: controller: split:
nRF: Use ticker compat mode as default").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada 7b89438f4b Bluetooth: controller: Consider must_expire while avoiding catchup
If must_expire is set for a ticker instance, then ticker
expiry shall still perform catchup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada 6cb43749a4 Bluetooth: controller: Fix ticks_slot_previous calculation
Fix ticks_slot_previous calculation in the ticker_job when
tickers are skipped.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada b263c2860e Bluetooth: controller: Fix ticker state on skipped
Reset ticker state in ticker_job for ticker instances that
have been skipped in the ticker_worker.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada 32352a1041 Bluetooth: controller: Remove lazy handling in ticker_worker
Removed lazy handling from ticker_worker as it is now taken
care in ticker_job.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada 7182c7062e Bluetooth: controller: Fix ticker catch up on ISR latency
Fix ticker to avoid catch up of periodic timeouts in case of
large ISR latencies like in case of flash erase scenarios.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada bc357718a7 Bluetooth: controller: split: Fix slave latency during conn update
Fix regression in cancelling slave latency during Connection
Update Procedure.

Slave latency should not be applied between the ack of a
Connection Update Indication PDU and until the instant.
When caching was introduced, implementation missed this
consideration.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:16 +02:00
Vinayak Kariappa Chettimada 79942b47cc Bluetooth: controller: legacy: Fix DLE duplicate requests
Fix implementation to handle back-to-back and duplicate
LENGTH_REQ PDU reception.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:00 +02:00
Vinayak Kariappa Chettimada 9bd4a786cd Bluetooth: controller: legacy: Simplify DLE state checks
Simplify the Data Length Update Procedure state check when
processing incoming LENGTH_REQ/RSP PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:00 +02:00
Vinayak Kariappa Chettimada 45500f3dc9 Bluetooth: controller: split: Fix DLE duplicate requests
Fix implementation to handle back-to-back and duplicate
LENGTH_REQ PDU reception.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:39:31 +02:00
Vinayak Kariappa Chettimada d13c6b2b29 Bluetooth: controller: split: Simplify DLE state checks
Simplify the Data Length Update Procedure state check when
processing incoming LENGTH_REQ/RSP PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:39:31 +02:00
Vinayak Kariappa Chettimada e217ade79e Bluetooth: controller: legacy: Validate chan map and hop value
Add validation of channel map and hop increment value
received in CONNECT_IND PDU.

Zero bit count leads to controller assert or divide-by-zero
fault.

Hop increment shall be between 5 and 16 by BT Specification.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:39:17 +02:00
Vinayak Kariappa Chettimada 4a5f263e5a Bluetooth: controller: split: Validate chan map and hop value
Add validation of channel map and hop increment value
received in CONNECT_IND PDU.

Zero bit count leads to controller assert or divide-by-zero
fault.

Hop increment shall be between 5 and 16 by BT Specification.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:38:27 +02:00
Joakim Andersson 29749af88a Bluetooth: host: Fix high-duty cycle directed extended advertising
Fix high-duty cycle directed advertising when extended advertising
feature has been enabled. The duration parameter when starting extended
high duty cycle directed advertising has to be set to a non-zero value
less than or equal to 1.28 seconds.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-31 12:48:19 +03:00
Joakim Andersson 17276d558e Bluetooth: host: Replace alignment with tabs with spaces
Replace alignment with tabs with spaces.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-31 12:26:15 +03:00
Joakim Andersson 6d9e45a2ee Bluetooth: host: Avoid removing keys from controller that are not added
Avoid removing identity keys from the controller during the pairing
procedure. During the pairing procedure the keys will be cleared before
they are updated. This causes an unnecessary warning from HCI core where
it tries to remove an IRK key-set from the controller that has has not
been added yet.

While this is not an issue, the warning from HCI core is misleading and
might lead to unnecessary questions and investigations.
Warning appeared after: 6c6bd8c49e

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-31 12:26:15 +03:00
Joakim Andersson c8b3d2772a Bluetooth: host: Move pending keys pending flags out of key storage
Move the pending ID keys add and delete flag out of keys storage area.
These flags are runtime flags and should not be stored in persistent
storage.
Due to struct alignment storage start has to be aligned so that
variables added before storage start does not affect the storage bytes
by introducing padding in the storage area

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-31 12:26:15 +03:00
Lingao Meng 96c733c4d7 Bluetooth: Mesh: Fix restore when revoke keys
Store keys again after revokes keys

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-03-31 12:25:12 +03:00
Oleg Zhurakivskyy b1e1f64d14 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
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>
2020-03-31 07:18:06 +02:00
Joakim Andersson a20066ed4f Bluetooth: shell: Add shell advertise set info get command
Add shell advertise set info get command to print advertiser set local
identity and TX power selected by the controller.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 506bb7f005 Bluetooth: host: Add get advertising set info
Implement function to get advertising set information.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 0e3586c375 Bluetooth: host: Skip feature testing when legacy adv is disabled
Skip feature testing of controller features when legacy advertising
commands are not supported. For combined builds or builds where the
capability of the controller is known it is not required to have runtime
check of controller extended advertising support.

This gives the following size reduction for hci_core.c:

Without legacy support
hci_core.c  19980     7.75%
total      257679

With legacy support
hci_core.c  21816     8.41%
total      259519

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 06ce4de658 Bluetooth: host: Handle identity keys update for limited adv or scan
Handle updating the identity keys in the controller while a scanner
limited by timeout or advertiser limited by number of events or timeout
is active in the controller. For this case we mark they keys as pending
and handle the update of the resolving list ones the roles are stopped.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson fc04cb0553 Bluetooth: shell: Add shell option to set scan timeout parameter
Add shell option to set scan timeout parameter.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 8f8b163a93 Bluetooth: host: Refactor HCI remove from resolving list command
Move HCI remove device from resolving list command out to it's own
function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 84fefc776e Bluetooth: host: Add RPA handling for scan limited by timeout
Add RPA handling for scan limited by timeout. The scan limited by
timeout has no information about elapsed time when stopped. So pausing
the scan at RPA timeout has no new scan timeout value to set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson d4c17e5648 Bluetooth: host: Handle anonymous advertiser
Add handling of anonymous advertise address type.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson b9acef930b Bluetooth: shell: Add shell command for advertising OOB information
Add shell command to retrieve advertising set OOB information for the
selected advertising set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson ed11ca1744 Bluetooth: host: Add error code to directed advertiser
Add error code to API for starting directed advertiser. Also rename the
API in order to follow the established naming pattern.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson fe597c07bf Bluetooth: shell: Use the new advertising callbacks
Add advertising sent connected and scanned callback and print the
information available.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 7c92ffdcb3 Bluetooth: shell: Add shell commands for advertising sets
Add shell commands to create advertising sets, add advertising data,
start advertising, stop advertising, and delete advertising set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 9ee31a4106 Bluetooth: shell: Add shell arguments to control scanning phys
Add shell arguments to control scanning phys for scanner and initiator.
This allows to scan on coded or create connections on coded.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 8859ddab92 Bluetooth: shell: Use the new scan callbacks to print extended info
Add scan recv callback and print extended scan information available.
Add scan timeout callback to print when scanner has stopped.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 11970b89f9 Bluetooth: shell: Print error code in hex
Print the error codes in hex so that it is easier to lookup, error
codes are usually given as hex.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson bcad8cf1c6 Bluetooth: host: Add support for single advertising set
Add support for creating and advertising with an advertising set.
This has support to advertise with extended data and with long range
feature on Coded PHY.
Limited to only supported one advertising set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 06ee3d8e62 Bluetooth: host: Add support for extended conn create options
Add support to use the extended conn create options to establish
connections on LE Coded PHY or 2M. This uses the connection options
set by bt_conn_set_scan_params.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson f24cc91a6b Bluetooth: host: Add API to set initiator scan parameters
Add API to set the scan parameters used in the LE Create Connection
HCI command used by bt_conn_create_le and bt_conn_create_aute_le.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 38b1d58b62 Bluetooth: host: Add scanner options for extendend scanning
Add support for the new scan options and use the LE Extended Scan
HCI commands if they are available in the controller.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson d29ab4a7df Bluetooth: host: Refactor scan and initiator random address handling
Refactor scan and initiator random address handling to a helper function
so that it can be re-used.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 869bea659a Bluetooth: host: Add reference count old and new value in debug print
Add reference count old to new value transition in the debug print, this
makes it easier to interpret the printed line when debuggin reference
count bugs.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 3c603b225b Bluetooth: host: Refactor get advertiser filter policy
Extract setting advertising filter policy parameter from the adv params
options field to a helper function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 88a6234ff2 Bluetooth: host: Use bluetooth defines instead of hci defines
Use the scan types defined in bluetooth.h instead of the hci defined
ones. Although they have the same value it is best to avoid using the
hci.h header in applications.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson d9d0964fcc Bluetooth: Kconfig: Update buffer sizes for advertising extension
Update buffer sizes needed when advertising extensions is enabled. Since
BT_RX_BUF_LEN is used for the HCI command as well we need to fit the
full 255 bytes of the Set Extended Advertising Data or Scan Response
Data plus the 3 byte header of an HCI command.

For the discardable buffer size we need to fit the LE Extended
Advertising Report event, which can be a maximum of 255 bytes plus the
2 byte header of an HCI event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 886badc69e Bluetooth: Kconfig: Add kconfig options for extended advertising
Add Kconfig options to enable extendend advertising and scanning
support.
Include option to support both types of advertising
commands in case the controller capabilities is not know or the
controller is pluggable.
Include option to only support legacy advertising API, this is to
support the use-case of advertising using different identity than the
scanner or initiator.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson f2d7b77e96 Bluetooth: host: Deprecate BT_LE_ADV defines in hci.h in favour of gap.h
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>
2020-03-30 00:38:23 +03:00
Joakim Andersson be57dfbe2a Bluetooth: host: Rename and deprecate scan filter for more scan options
Rename filter_dup parameters used for scanning filter options to the
more generic name options, and make scan filter options follow same
naming patters as advertising and initiator scan options.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 405ce842ab Bluetooth: host: Add new argument and return code to bt_create_conn_le
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>
2020-03-30 00:38:23 +03:00
Kumar Gala 3a59f87ba9 bluetooth: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-27 16:53:21 -05:00
Vinayak Kariappa Chettimada d7cc4bd2c5 Bluetooth: controller: ticker minor code optimization
Minor optimization to use a local variable instead of a
deferencing of a struct member.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-27 11:37:36 +01:00
Andrzej Głąbek 4253eae005 boards: nrf52840_pca10056: Rename board to nrf52840dk_nrf52840
The nRF52840 DK board target, so far known as nrf52840_pca10056,
is renamed to nrf52840dk_nrf52840.
Its documentation and all references to its name in the tree are
updated accordingly. Overlay and configuration files specific to
this board are also renamed, to match the new board name.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-03-27 09:14:08 +01:00
Vinayak Kariappa Chettimada b77b099bf9 Bluetooth: controller: Fix ticker ticks_current value
Update the ticks_current value on last stopped ticker
instance, so that when a new ticker instance is started
the anchor ticks calculation uses the correct current tick
with respect to supplied anchor ticks.

Fixes #23805.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-26 12:46:04 +01:00
Vinayak Kariappa Chettimada 915c510a0a Bluetooth: controller: split: Remove use of k_cpu_idle
Remove use of k_cpu_idle in controller, and refactor the
implementation used to start, wait and stop clocks needed
by the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-24 13:38:59 +01:00
Ioannis Glaropoulos f3807f19dc boards: arm: nrf51_pca10028: rename board to nrf51dk_nrf51422
We rename the nRF51 Dev Kit board target (nrf51_pca10028)
to nrf51dk_nrf51422. We update all associated references
in the supportive documentation and all nRF51-related
cofigurations and overlay files in the samples and tests
in the tree.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-03-24 11:45:27 +01:00
Joakim Andersson 6c6bd8c49e Bluetooth: host: Fix directed advertising from privacy-disabled peer
Fix directed advertising from privacy disabled peer. In this case we
need to have the local IRK in the controllers resolving list in order to
have the controller resolve the initiator address of the directed
advertising pdu (ADV_DIR_IND).

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-23 12:44:44 +02:00
Joakim Andersson 9ec6fb87c9 Bluetooth: host: Fix directed advertiser for multiple local identities
Fix directed advertiser using the wrong local IRK when doing directed
advertising when the identity of the advertiser is not the default
identity.
This is only an issue for the directed advertiser because it is only
for the directed advertiser that we use the controllers local IRK
to generate the Advertisers RPA.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-23 12:44:44 +02:00
Joakim Andersson e4538c6807 Bluetooth: HCI: Re-organize vendor read static address handling
Add header definition for bt_read_static_addr function. Declaring it
without a header definition will not give any compilation error when
function definition changes.
Refactor nRF SoC specific code into nRF specific source files and
provide weak definitions when these are not implemented. This will make
it easier to add handlers per vendor.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-22 11:58:17 +02:00
Joakim Andersson ffa10eba83 Bluetooth: host: Include scan response with name when non-connectable
When using BT_LE_ADV_NCONN_NAME then the advertising name will not be
included in the advertising data. This is because the host always puts
the device name in the scan response. But since the scan data was
otherwise empty the advertising type was set to ADV_NONCONN_IND.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-20 14:06:42 +02:00
Trond Einar Snekvik 09333caf52 Bluetooth: Mesh: Split out provisioning bearers
Splits PB-ADV and PB-GATT into separate modules with a common interface
to modularize prov.c.

Additional trivial fixes from testing:

- Reduces warnings for normal occurances like repeated packets.
- Makes link ack a non-reliable packet to prevent it from being repeated
  until prov invite.
- Provisioner does not send link fail, but closes the link (as per spec
  section 5.4.4). This prevents lingering zombie links on both sides.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-20 12:45:53 +02:00
Carles Cufi 4b37a8f3a4 Revert "global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()"
This reverts commit 8739517107.

Pull Request #23437 was merged by mistake with an invalid manifest.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-19 18:45:13 +01:00
Oleg Zhurakivskyy 8739517107 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
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>
2020-03-19 15:47:53 +01:00
Trond Einar Snekvik 824c2ebc58 Bluetooth: Mesh: Slab based segmentation handling
Allocates segmented message buffers as slabs in a common pool for RX and
TX. This reduces memory requirements for both TX and RX, as TX messages
can be stored without the network and advertising buffer overhead, and
RX can use only the slabs it needs, instead of allocating a full size
segmented message. This approach also removes the need for decrypting
the segments for each retransmission, reducing overall processing load.

Slab based segmentation for tx also introduces queuing of segmented
messages, which allows the application layer to send multiple messages
to the same destination without violating Bluetooth Mesh specification
v1.0.1, section 3.6.4.1. This mechanism is provided through a flag that
blocks segmented messages to a destination which a message is already
being sent to until the previous message finishes.

This changes the SDU size configuration to a symmetrical
RX_SEG_MAX/TX_SEG_MAX pair of configurations, plus a new segment pool
side configuration. It also removes the binding between the TX_SEG_MAX
config and the advertising buffers, reducing the minimum advertising
buffer count from 6 to 3.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-19 15:54:26 +02:00
Trond Einar Snekvik ca2f5c3f91 Bluetooth: Mesh: Friend SeqAuth cleanup
The Friend queue uses the message SeqAuth to determine whether the
message is already in the queue. To facilitate this, the SeqAuth is
passed around as a pointer throughout the transport modules. In the
bt_mesh_ctl_send functions, this parameter is also exposed in the API,
but the internal usage is inconsistent and buggy. Also, no one actually
uses this parameter.

- Removes seq_auth param from bt_mesh_ctl_send, instead passing NULL
  directly to the friend module, to enforce its addition to the queue.
- Makes the seq_auth pointer const throughout the friend module.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-19 15:54:26 +02:00
Andries Kruithof 30e3205e32 Bluetooth: controller: split: correct timing calculation in PKT_US
A bug in the PKT_US resulted in wrong calculations for the 2M phy.
Fixes the bug, verified on EBQ.
Also adds some defines for improved readability.

Fixes #23482

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-03-18 16:09:33 +01:00
Vinayak Kariappa Chettimada b7220cef86 Bluetooth: controller: split: Fix densely scheduled event preemption
Fix LLL implementation handling preemption of currently
active radio event with densely scheduled events in the
pipeline.

Preempt timeout was stopped without consideration to there
being more queued events in the pipeline. Also, added
chaining of preemption timeouts one after the other expiry
so as to preempt currently active events by the densely
scheduled events in the pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-18 10:45:43 +01:00
Vinayak Kariappa Chettimada 5474dbb544 Bluetooth: controller: split: Fix regression in handling invalid pkt seq
Fix regression in handling invalid packet sequence in the
first packet in a connection.

This relates to commit 62c1e1a52b ("Bluetooth: controller:
split: Fix assert on invalid packet sequence")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-18 10:44:47 +01:00
Vinayak Kariappa Chettimada 6a37dc5a68 Bluetooth: controller: legacy: Fix regression handling tx pool corruption
Fix regression in handling tx pool corruption in relation to
commit 7a3e29af06 ("Bluetooth: controller: legacy: Fix Tx
pool corruption").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-18 10:44:21 +01:00
Wolfgang Puffitsch f3de1f5b38 Bluetooth: controller: split: Fix response to unexpected LL_FEATURE_RSP
Fix response to unexpected LL_FEATURE_RSP for the case that
BT_CTLR_SLAVE_FEAT_REQ is disabled. Fixes LL/PAC/SLA/BV-01 for such a
configuration.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-03-17 12:37:03 +01:00
Dan Erichsen 6a12a2dbe1 bluetooth: host: Do not send unwanted SC indicate
Fixes #23485

When we create a GATT table dynamically, we also create a hash
identifying this table. This hash can be stored in persistent memory and
we can thus determine after recreating the GATT table whether the
services have changed or not from before the reboot.

When these hashes are identical, it implies that the table has not
changed, wherefore a service changed indication should not be sent to
any bonded clients. The method for achieving this was to remove the
gatt_sc.work entry from the work queue. This work queue entry was to
send an indication to the clients when the table had been allocated.
If the final entry then caused the hashes to match, the indication
would be cancelled.

On unit testing this behaviour in simulation and in practice, we found
that the indication was sent nonetheless, and the issue was located to
be tied to the SERVICE_RANGE_CHANGED flag which is set when the services
are changed and is cleared when the indications are being sent out.

It was the job of the work queue entry to clear this flag, and as the
entry was never serviced, the flag was never cleared, and when
sc_commit() is called at the end of the process, it believes that there
is a new service change pending and therefore starts the job over, thus
creating a redundant indication to the clients.

This commit fixes the issue by clearing the flag when the work entry
is removed due to a hash match. This has been unittested in a live
environment, in a simulation environment, and sanitycheck has been run
on it.

Signed-off-by: Dan Erichsen <daee@demant.com>
2020-03-16 21:09:24 +02:00
Johan Hedberg 80cb358fe2 Bluetooth: Kconfig: Fix BT_ECC defaults
The commit e85dd8af5d changed the way the BT_ECC Kconfig option
is enabled, however it got the dependency wrong. The dependency should
only look at BT_SMP_OOB_LEGACY_PAIR_ONLY if BT_SMP was also enable.

This broke e.g. the build of the mesh_demo app for the BBC
micro:bit since the memory consumption jumped up by roughly 2k.

This patch fixes the issue, and in the same go makes the Mesh handling
consistent by also using a conditional default rather than select.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-03-16 14:26:08 +02:00
Joakim Andersson 628b3bc416 Bluetooth: host: Allow get local OOB data while advertiser is enabled
Allow to get local OOB data while advertiser, scanner or whitelist
initiator is active. If direct initiator is active or the advertiser
is using the random address as a random static identity address then
the function will return error.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-13 17:16:51 +02:00
Joakim Andersson 7ff4a632b7 Bluetooth: host: Allow to initiate pairing without OOB present
When OOB callbacks are present it is possible to achieve authenticated
pairing without having the remote OOB data present. Using OOB with
LE Secure Connection only one side of the pairing procedure is required
to have the OOB data present. If we have given the remote our OOB data
then pairing can proceed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-13 14:18:48 +02:00
Joakim Andersson 8514794ed3 Bluetooth: controller: Do not use LL procedures not supported by remote
Update LLCP handling during PHY update and Data Length update to not
start the LL control procedure if the remote has already indicated that
the procedure is not supported.

This fulfills the following requirement from the BT Core Specification
(Core_v5.2, Vol 6, Part B, Section 4.6):

Except where explicitly stated elsewhere in this specification, if the
peer Link Layer has indicated either during a feature exchange procedure
or by responding with an LL_UNKNOWN_RSP PDU that it does not support a
procedure, then the Link Layer shall not use that procedure.

Re-use the connection parameter request handling for PHY and
data length update procedures.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-13 13:02:13 +01:00
Vinayak Kariappa Chettimada 8a294a62d4 Bluetooth: controller: legacy: Fix missing first conn event
Fix missing first connection event due to first connection
event ticks_slot overlapping with the initiator window
ticks_slot.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-13 10:39:39 +01:00
Vinayak Kariappa Chettimada 489bebfb04 Bluetooth: controller: Add ticker_stop_abs interface
Add ticker_stop_abs interface, similar functionality as to
ticker_stop interface to stop a running ticker but with a
supplied absolute tick reference value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-13 10:39:39 +01:00
George Stefan 76b1f03345 bluetooth: controller: openisa/RV32M1: use DSM from LLL
Added the functions to turn on/off the radio from LLL.
Added WAKE_IRQ to start radio after it's out of DSM.

Signed-off-by: George Stefan <george.stefan@nxp.com>
2020-03-12 17:05:02 +02:00
Ionut Ursescu 27878377b2 bluetooth: controller: openisa/RV32M1: introducing radio Deep Sleep Mode
Added the functions to turn on/off the radio.
Deep Sleep Mode (DSM)

Signed-off-by: Ionut Ursescu <ionut.ursescu@nxp.com>
Signed-off-by: George Stefan <george.stefan@nxp.com>
2020-03-12 17:05:02 +02:00
Alex Porosanu cf96a0bdaa bluetooth: controller: enable 2Mbps PHY for RV32M1
This patch adds the selection of  the necessary CONFIG_*
options for allowing the use of the 2Mbps BLE PHY on
VEGA platform.

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2020-03-12 13:10:04 +02:00
Alex Porosanu cb0a6c2eff bluetooth: controller: openisa/RV32M1: add 2 Mbps PHY support
The radio on the VEGA platform supports both 1Mbps, as well
as 2Mbps BLE PHYs. It does not support coded BLE PHY. This patch
adds the necessary callback, as well as timings to enable the 2 Mbps
PHY support in the SW LL HAL for VEGA.

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2020-03-12 13:10:04 +02:00
Joakim Andersson a421fc882b Bluetooth: shell: Add support for Legacy OOB pairing in the shell
Add command to input the legacy pairing OOB TK during the pairing
procedure.
Fixed shell build with CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY defined.
Print error code when passkey input failed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-12 12:30:15 +02:00
Iván Morales e85dd8af5d Bluetooth: smp: Adding Legacy OOB only mode and no JW/Passkey mode
Added CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY option that completely disables
all legacy and SC pairing modes(except for Out of Band) and frees the
memory previously used by these.

Added CONFIG_BT_SMP_DISABLE_LEGACY_JW_PASSKEY option that force rejects
pair requests that lead to legacy Just Works or Passkey pairing.

Signed-off-by: Iván Morales <ivan98ams@gmail.com>
2020-03-12 12:30:15 +02:00
Iván Morales cc0d2447f1 Bluetooth: smp: Adding Legacy OOB pairing support
Added support for Legacy pairing using OOB Temporary Key

Signed-off-by: Iván Morales <ivan98ams@gmail.com>
2020-03-12 12:30:15 +02:00
Trond Einar Snekvik 56a918f8ca Bluetooth: Mesh: Rework msg_cache
Changes the behavior of the message cache to optimize for cache
capacity. Previously, the message cache's primary function was to avoid
decrypting messages multiple times, although the cache's main function
in the spec is to avoid message rebroadcasting. Optimizing for minimal
decryption causes us to fill the network cache faster, which in turn
causes more cache misses, potentially outweighing the advantage.

Now stores src + seq in message cache instead of field hash value. This
cuts cache size in two, while including more of the sequence number than
before.

Adds messages to the cache only after the packet is successfully
decrypted. This reduces noise in the cache, and ensures that no
invalid deobfuscations are added.

Additionally, this fixes a bug where multiple calls to net_decrypt with
the same packet failed, as the message cache found its own entry from
the previous call.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-10 17:13:32 +02:00
Joakim Andersson 564ba1a07b Bluetooth: host: Use switch statement in bt_conn_set_state
Refactor old state handling in bt_conn_set_state to use switch statement
instead of if statements.
This will give us warning about enum values not covered.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-10 15:09:43 +02:00
Joakim Andersson f19b7a6e69 Bluetooth: host: Fix local RPA not valid in connection complete
Fix connection complete event handling when the local RPA is not valid.
This can happen when the controller was not instructed to use an RPA
address, or the local IRK was set to an all zero IRK.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-10 15:09:31 +02:00
Rubin Gerritsen 9c28569901 bluetooth: controller: Fix incorrect dependency of Coded PHY
In Core v5.2, Vol 6, Part B, Section 4.6.9 it is stated that it is
mandatory to support the PHY procedure if any PHY other than 1M is
supported.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-03-10 15:05:51 +02:00
Rubin Gerritsen 213c8e9d53 bluetooth: controller: Allow any controller to config PHY support
For the time being this 2M is only selectable for !nRF51 platforms.
Coded PHY is only selectable for nRF platforms supporting Coded PHY.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-03-10 15:05:51 +02:00
Joakim Andersson 681dfdc12b Bluetooth: HCI_VS: Check for supported command
According to the Zephyr VS HCI specification:
Only Read_Version_Information and Read_Supported_Commands commands are
mandatory.

Check for supported Read Supported Features command before issuing this
command to the controller.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-10 15:02:48 +02:00
Vinayak Kariappa Chettimada 66d1be6728 Bluetooth: controller: nRF51x: Force optimize for speed
Make BT_CTLR_OPTIMIZE_FOR_SPEED option so that it is not
user selectable for nRF51x series SoC with encrypted
connections support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-10 15:01:43 +02:00
Vinayak Kariappa Chettimada b466d5399c Bluetooth: controller: legacy: Fix mandatory min PDU len Code PHY
Fix to return the max tx/rx time back to set default time
after using mandatory minimum PDU length and time while
switching back from Coded PHY to 1M PHY.

Also fixes #23109.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-10 14:55:31 +02:00
Vinayak Kariappa Chettimada baeed73684 Bluetooth: controller: legacy: Fix DLE tx rx time on PHY update
Fix Data Length Update transmit and receive time calculation
on PHY update procedure completion.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-10 14:55:31 +02:00
Vinayak Kariappa Chettimada 5386095ba4 Bluetooth: controller: legacy: Fix Data Length Tx Rx time
Fix Data Length Update procedure calculation of transmit
and receive time.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-10 14:55:31 +02:00
Joakim Andersson 94e1620c03 Bluetooth: host: Fix host resolving peer identity in connection complete
Fix host resolving the peer identity address in enhanced connection
complete event when the resolving list in the controller is full and
resolution is done in the host.
Move the handling from legacy connection complete into enhanced
connection complete event so that it is done for both connection
complete events.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-10 12:18:09 +02:00
Trond Einar Snekvik db330cb06a Bluetooth: Mesh: Segmented TX to groups
Implements several changes to the transport layer segmented tx to
improve group message performance:
- Moves retransmit counter to tx context instead of per packet. As every
  unacked packet is sent every retransmit, the retransmit counters would
  be the same in each segment. This makes it easier to control progress.
- Delays the scheduling of the retransmit until the completion of the
  last segment by adding a seg_pending counter. This is essentially the
  same as the old behavior, except that the old behavior might retrigger
  the sending before all segments are finished if the advertising is
  slow.
- Allows the group transmits to stop as soon as all retransmits have
  been exhausted, instead of timing out waiting for acks that won't
  come. This allows group tx to finish without error.
- Fixes a bug where a failed TX would block IV update.
- Cancels any pending transmissions of acked segments.
- Reduces log level for several common group tx scenarios that aren't
  erronous.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-10 12:17:13 +02:00
Trond Einar Snekvik 2f27e0ce84 Bluetooth: Mesh: CDB for config client in shell
When available, the shell will use the CDB when configuring. This
replaces the default key for configuration and self-provisioning,
ensuring that there aren't multiple key values for the same indexes.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-10 12:16:31 +02:00
Joakim Andersson bb42abdd7c Bluetooth: host: Fix LE SC OOB authentication and id for central role
If the application has used bt_le_oob_get_local to retrieve the OOB
RPA address and OOB authentication information the central role should
use this RPA address for the next RPA timeout period.

The central role always refreshes the RPA address for the initiator,
this will make the OOB information not usable as the peer cannot
recognize the central role since the RPA address is changed.
Check if the initiator can use the address for the duration of the of
remaining RPA period.

Fix central role using the advertiser identity when setting the private
address. The central role should only use the default identity.

Regressions from:
fbe3285bfa
and
4876a8f39a

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-06 18:25:48 +02:00
Joakim Andersson c97e1aafb1 Bluetooth: Mesh: Fix possible NULL dereference in BT_DBG statement.
Fix possible NULL dereference in BT_DBG statement when
bt_mesh_friend_get is called before a successful cfg_srv init

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-06 10:04:46 +02:00
Trond Einar Snekvik 2835da8194 Bluetooth: Mesh: Fix cdb key update iteration
Fixes copy/paste error taking the size of the the wrong array.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-05 20:33:07 +02:00
Vinayak Kariappa Chettimada 4bacb0e098 Bluetooth: controller: legacy: Fix cond. compile error
Fix conditional compilation error when enabling
BT_CTLR_FAST_ENC for central only application builds.

Also added additional compilation to code exclusive to
central or peripheral role.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-29 19:39:41 +02:00
Vinayak Kariappa Chettimada ca66f5b2e5 tests: Bluetooth: shell: Fix conditional compile error
When building the tests/bluetooth/shell application without
the BT_CENTRAL feature, compilation fails:

subsys/bluetooth/shell/bt.c:1642: undefined reference to
`bt_conn_create_auto_le'

Signed-off-by: Vinayak Kariappa Chettimada <vinayak.kariappa@gmail.com>
2020-02-29 10:47:18 +02:00
Tobias Svehagen 60563977df Bluetooth: Mesh: Fix handling of app index and local device key
Fix problem of not checking if the remote device key is actually our
own. This bug was intruduced in
46a95f12ad and causes failure of models
that use app_idx BT_MESH_KEY_DEV_REMOTE. Since this is used by cfg_cli,
it was not possible to do self-configuration.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-02-28 20:18:54 +02:00
Vinayak Kariappa Chettimada f972fb057d Bluetooth: controller: Add Kconfig for Optimize for Speed
Add Kconfig option to support building the controller
optimized for speed.

Fixes #21601.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-28 10:55:33 +02:00
Vinayak Kariappa Chettimada e1d9620187 Bluetooth: controller: legacy: Fix assert on DLE procedure stall
Fix local initiated Data Length Update procedure from being
stalled when a remote initiates a procedure with instant.

Fixes #23069.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-28 10:02:15 +02:00
Andries Kruithof 2c70df32b7 Bluetooth: controller: split: Fix regression errors
This commit fixes problems with LL tests CON/SLA/129, CON/SLA/130,
CON/SLA/132, CON/MAS/126, CON/MAS/127, CON/MAS/129, CON/MAS/55,
CON/SLA/57

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-02-27 19:14:32 +02:00
Vinayak Kariappa Chettimada 7a3e29af06 Bluetooth: controller: legacy: Fix Tx pool corruption
Fix Tx pool from being corrupted when rough central device
uses invalid packet sequence numbers, causing NULL pointer
to be released into free data Tx pool.

Fixes #22968.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-27 12:54:35 +02:00
Tobias Svehagen 7a737a0084 Bluetooth: Mesh: Fix bug with storing node in CDB
The free_slot->clear must be set to false since it could still be true
from previous use.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-02-27 12:40:19 +02:00
Rubin Gerritsen 3a30eed083 bluetooth: Fix wrong warning text for unsupported Zephyr HCI commands
They were interchanged.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-02-27 12:31:01 +02:00
Dag Bjarvin 1a43a798e7 Bluetooth: controller: Merge 2 lines
Merge 2 lines that fit on one line

Signed-off-by: Dag Bjarvin <Dag.Bjarvin@nordicsemi.no>
2020-02-27 12:30:44 +02:00
Luiz Augusto von Dentz 9e8b78b8e1 Bluetooth: GATT: Fix not clearing CF_OUT_OF_SYNC
If the client is change-unware and disconnects the spec requires that
the stack still sends the error out of sync for the next request:

'The ATT_ERROR_RSP PDU is sent only once after the client becomes
change-unaware, unless the client _disconnects_ or the database changes
again before the client becomes change-aware in which case the
ATT_ERROR_RSP PDU shall be sent again'

Fixes #23110

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-27 11:26:30 +02:00
Trond Einar Snekvik 7b48611143 Bluetooth: Mesh: Group resends in proxy nodes
Resend transport segments for groups on the advertiser interface, even
if a connected proxy node holds the group.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-02-27 10:02:40 +02:00
Joakim Andersson 1ef16e6d96 Bluetooth: shell: Update help text of bt init command
Update help text of `bt init` command which says address could be
provided. This feature was removed by:
d22b7c9f2d

As a replacement the `bt id-create` command can be used instead.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-26 17:51:18 +02:00
Morten Priess 41481f92f7 Bluetooth: controller: Prevent LLCP handling of must-expire events
When a must-expire ticker callback is executed, it is important not to
call the LLCP state machine, as the lazy state is unavailable. The code
must rely on the next proper event to call ull_conn_llcp with an updated
non-zero lazy count.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-02-26 09:20:58 +01:00
Andries Kruithof 0ac4433a12 Bluetooth: controller: split: fix LL/CON/MAS/BV-74-C tx timing
Fix EBQ tests for the Max Tx Time and Max Rx Time parameter.

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>

Bluetooth: controller: split: fixed for endianness

Added conversion to correct endianness

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-02-25 16:13:17 +01:00
Vinayak Kariappa Chettimada e0f51b29ef Bluetooth: controller: split: Fix assert on DLE procedure stall
Fix local initiated Data Length Update procedure from being
stalled when a remote initiates a procedure with instant.

Fixes #23069.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-25 15:14:31 +01:00
Joakim Andersson 58908aa5d0 Bluetooth: host: Fix missing connection id checks
Fix issue where a new connection with the same peer would use the CCC
from from first connection, despite different local identity.
Since there is no CCC for the new connection yet this caused the
application to think that CCC was enabled but the remote device had not
yet subscribed.

Fix this issue by making the id as an input to the peer address check
function. This will force us to make the check every time. This commit
might also fix similar issues not yes discovered as the ID check was
missing in a few other places as well.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-21 21:28:30 +02:00
Joakim Andersson 4e829eb544 Bluetooth: host: Rename acl context id to index
Rename the acl buf context id to index since to avoid confusing it with
the conn object ID parameter. Especially the bt_conn_lookup_id function
was creating confusion.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-21 21:28:30 +02:00
Rubin Gerritsen fa241f0249 bluetooth: Add decoding for BLE 5.2 version string
The BLE 5.2 specification has been assigned the version number 0x0b.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-02-21 16:53:16 +02:00
Vinayak Kariappa Chettimada cc468e89d0 Bluetooth: controller: Fix ticker resolve collision implementation
Fix ticker resolve collision implementation for incorrect
ticks accumulation and the calculation of next period.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-21 11:38:37 +01:00
Vinayak Kariappa Chettimada ae9bf5e440 Bluetooth: controller: split: Fix radio in use during flash op
Fix a race condition in radio abort requested by flash
driver. It is possible that during abort function execution,
PPI setup to start radio fires. Hence, check explicitly in
cleanup function for radio being in use and disable it.

Fixes #22945.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-21 11:38:37 +01:00
Vinayak Kariappa Chettimada 459ff3f83e Bluetooth: controller: Fix BT_TICKER_EXT dependency
BT_TICKER_EXT depends on BT_TICKER_COMPATIBILITY_MODE not
being selected.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-21 10:55:51 +01:00
Vinayak Kariappa Chettimada a749e28d98 Bluetooth: controller: split: nRF: Use ticker compat mode as default
Use the old ticker compatibility mode implementation as
default for nRF5x Series SoCs.

Fixes #22926.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-21 11:38:20 +02:00
Joakim Andersson 9ab17a3eb4 Bluetooth: test: Delay SMP pairing distribution phase when testing
Avoid the HCI-USB race condition where HCI data and HCI events can be
re-ordered, and pairing information appears to be sent unencrypted.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-20 21:32:59 +02:00
Vinayak Kariappa Chettimada 62c1e1a52b Bluetooth: controller: split: Fix assert on invalid packet sequence
Fix to remove assertion failure check on detecting invalid
packet sequence used by peer central and that no non-empty
packet was transmitted.

Fixes #22967.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-20 19:34:17 +02:00
Joakim Andersson 2e6983c0f5 Bluetooth: GATT: Fix invalid DB hast written to settings storage
Fix issue where an invalid (all zeroes) hash was written to settings
storage on reset. This caused the old value to written to zeroes, before
being written back to it's original value again immediately after.
This causes excessive flash wear.

This happens because the check if (k_delayed_work_remaining) returns the
amount of time until the work will execute. When that time has run out
the time is zero, but the work has not yet been executed.
We then write the invalid hash to flash, and then once the work-item
executes it will write the correct value.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-18 13:55:33 +02:00
George Stefan f8293807da bluetooth: controller: openisa/RV32M1: fix LL scheduling
- avoid spourious radio interrupts by fixing ISR set,
    waiting for idle, command configuration
- adjust counter to account for missing increment
- change preemption instant to avoid missing the deadline in LLL
- decrese EVENT_JITTER_US and
    EVENT_TICKER_RES_MARGIN_US (same as Nordic)

Continuous scanning and connections are working fine now.

Signed-off-by: George Stefan <george.stefan@nxp.com>
2020-02-18 13:48:12 +02:00
Cristi Caciuloiu 2a2f84256c bluetooth: controller: openisa: encryption and decryption using CAUv3
Created unit tests for the encryption and decryption functions.
Tested with the peripheral and with central_hr samples.
Due to latency of CAUv3 when used as CCM inline accelerator
only one of the PDU can be encrypted/decrypted within an
bilateral exchange M->S + S->M in a connection event.
If the RXed PDU is encrypted, the TXed PDU must be empty
with More Data if there is data in the LLL queue.
The TXed PDU will be encrypted when an empty PDU is RXed.

Signed-off-by: Cristi Caciuloiu <cristian.caciuloiu@nxp.com>
2020-02-18 12:34:27 +02:00
Stephen Pliaskin 84e381e0a7 Bluetooth: Mesh: typo in condition in comp_add_elem of cfg_srv
Vendor model IDs take up four (not two) bytes in the composition

Fixes #22822

Signed-off-by: Stephen Pliaskin <strelok@e-kirov.ru>
2020-02-16 23:28:51 +03:00
Vinayak Kariappa Chettimada 23c5003d12 Bluetooth: controller: split: Fix regression in privacy port
Fix regression due to addition of conditional compilations
while porting the privacy feature from legacy to split
controller.

Fixes #22801.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-14 18:21:16 +01:00
Trond Einar Snekvik d55c8ead03 Bluetooth: Mesh: GATT Proxy Spec 1.0.1 changes
Backport of https://github.com/apache/mynewt-nimble/pull/724

Mesh spec 1.0.1 changes proxy disabling behavior to only affect the
relaying from proxy nodes. Previously, disabling proxy would shut down
all proxy and node activity.

Tweaks from the original commit:
- Removed redundant call to bt_mesh_adv_update() in gatt_proxy_set()
- Removed invalid ref to 4.2.11.1 in node_identity_set()

---

According to Mesh Profile Spec 1.0.1, Section 4.2.11:
"If the Proxy feature is disabled, a GATT client device can connect
over GATT to that node for configuration and control. Messages from
the GATT bearer are not relayed to the advertising bearer."

Moreover some notes have been removed from the spec compared to
version 1.0:

Mesh Profile Spec 1.0, Section 4.2.11:

"Upon transition from GATT Proxy state 0x01 to GATT Proxy state 0x00
the GATT Bearer Server shall disconnect all GATT Bearer Clients."

"The Configuration Client should turn off the Proxy state as the last
step in the configuration process."

Mesh Profile Spec 1.0, Section 4.2.11.1:

"When the GATT Proxy state is set to 0x00, the Node Identity state
for all subnets shall be set to 0x00 and shall not be changed."

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-02-14 14:43:06 +02:00
Luiz Augusto von Dentz bd5048c251 Bluetooth: Setting: Make bt_settings_encode_key take a const address
This removes the need to cast in case the address is already const.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-14 14:15:11 +02:00
Luiz Augusto von Dentz 4edfd45c6d Bluetooth: GATT: Fix not clearing SC when disconnecting
SC config data is no longer stored within the CCC config itself
therefore it must be cleared separately.

Fixes #22539

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-14 14:15:11 +02:00
Luiz Augusto von Dentz b6825ffc31 Bluetooth: GATT: Fix not clearing stored data when unpairing
GATT data shall not be considered conditional to BT_SETTINGS since
the data is stored in RAM it must also be cleared when unpairing.

Fixes #22514

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-14 14:15:11 +02:00
Luiz Augusto von Dentz 730989078c Bluetooth: GATT: Move functions related to bt_gatt_clear
These functions shall not be conditional to BT_SETTINGS.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-14 14:15:11 +02:00
Luiz Augusto von Dentz 1156412904 Bluetooth: SMP: Fix failing to pass SM/MAS/PROT/BV-01-C
smp_pairing_complete does actually clears flags so setting
SMP_FLAG_TIMEOUT must come after that.

Fixes #22786

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-14 11:55:14 +02:00
Joakim Andersson 1f0f3ca9ba Bluetooth: GATT: Fix gatt indicate using wrong pointer for attribute
Fix bt_gatt_indicate using the wrong attribute pointer when a uuid was
provided as input.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-12 20:28:32 +02:00
Andries Kruithof 82a6208b40 Bluetooth: controller: split: fix HCI read_max_data_len
In the function le_read_max_data_len the rx-component is not set.
This PR fixes this

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-02-12 14:37:09 +02:00
Joakim Andersson 08a39851dc Bluetooth: host: Rename scan recv callback info struct
Rename the scan recv callback info struct so that it reflects that it
is part of the scan recv callback. This will make it consistent with
future plans for advertising callbacks.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-11 23:57:27 +02:00
Joakim Andersson 794cbd641b Bluetooth: host: Fix handling of scan start failed
Handle scan start failed and release the connection object in this case.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-11 23:56:47 +02:00
Joakim Andersson abd03aa3ad Bluetooth: host: Fix scanner using wrong identity to resolve peer
Fix the scanner using the advertiser identity instead of the scanners
identity, scanner always use BT_ID_DEFAULT.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-11 23:56:47 +02:00
Kamil Piszczek 8f7fe8357e bluetooth: host: fix RPMsg driver headroom configuration
Corrected configuration of BT_HCI_RESERVE for the RPMsg HCI driver.
This change fixes the following assert:
[net_buf_simple_headroom(buf) >= len] @ ZEPHYR_BASE/subsys/net/buf.c:881

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2020-02-11 13:23:50 +02:00
Luiz Augusto von Dentz 6ea0ea38a7 Bluetooth: L2CAP: Fix not queueing in case there are no credits
This can happens if for example the remote peer have the initial credits
set to 0 which would cause bt_l2cap_chan_send to fail instead of just
queue the packets until more credits are given.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-10 22:08:14 +02:00
Vinayak Kariappa Chettimada 8a3a4bb589 Bluetooth: controller: split: Fix PHY update tx pause
Data transmission was paused when PHY update request control
PDU was enqueued in ULL. If there was pending data PDU in
ULL that was not enqueued towards LLL, this caused
transmission to stall.

Move the tx pause due to PHY update request/response being
enqueued to pre_tx_ack callback, this way all pending PDUs
in ULL is enqueued to LLL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-10 10:22:42 +01:00
Ulf Magnusson eddd98f811 kconfig: Replace some single-symbol 'if's with 'depends on'
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>
2020-02-08 08:32:42 -05:00
Andrew Boie efc5fe07a2 kernel: overhaul unused stack measurement
The existing stack_analyze APIs had some problems:

1. Not properly namespaced
2. Accepted the stack object as a parameter, yet the stack object
   does not contain the necessary information to get the associated
   buffer region, the thread object is needed for this
3. Caused a crash on certain platforms that do not allow inspection
   of unused stack space for the currently running thread
4. No user mode access
5. Separately passed in thread name

We deprecate these functions and add a new API
k_thread_stack_space_get() which addresses all of these issues.

A helper API log_stack_usage() also added which resembles
STACK_ANALYZE() in functionality.

Fixes: #17852

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-02-08 10:02:35 +02:00
Alex Porosanu 03892c1571 Bluetooth: controller: split: openisa: fix missing include
If CONFIG_BT_CTLR_CONN_RSSI is enabled, then lll_conn.h should
be included as well. Otherwise, struct lll_conn is unknown
at the compile unit level. This has been reproduced by
compiling the hci_uart sample, where the following error occurs:

lll_adv.c: In function 'isr_rx_pdu':
lll_adv.c:722:13: error: dereferencing pointer to incomplete
                         type 'struct lll_conn'
    lll->conn->rssi_latest =  radio_rssi_get();
             ^~

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2020-02-07 15:52:26 -06:00
Johan Hedberg 578dbe1c0a Bluetooth: Mesh: Support reliable sending when publishing
Until now the choice of reliable sending (segmented messages with
acks) was implicitly dependent on the size of the payload. Add a new
member to the bt_mesh_model_pub to force using segment acks even when
the payload would fit a single unsegmented message.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-02-07 20:42:15 +02:00
Vinayak Kariappa Chettimada a81fc17bb2 Bluetooth: controller: split: Fix uninitialized advertiser rl_idx
Fix uninitialized advertiser rl_idx used to check own identity
in CONNECT_IND received for directed advertisements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-07 14:09:05 +01:00
Tobias Svehagen 46a95f12ad Bluetooth: Mesh: Add database for managing nodes and keys
Refactor the handling of network nodes and their keys into a separate
Mesh Configuration Database (CDB). This, not only creates a separation
of the local node and the other nodes, but also makes it possible to
implement functions to manage the whole, or at least parts of the mesh
network.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-02-05 18:47:41 +02:00
Peter Bigot ddc3f0699f gpio: replace gpio pin write/read with set/get
This API will be deprecated in favor of the new API that clearly
specifies whether it works on logical or physical levels.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-02-05 12:00:36 +01:00
Morten Priess c1cb5ea540 Bluetooth: controller: Remove compiler specific warning
Some compilers can't resolve the conditional if/else/else construction
in ull_conn event_len_prep function, and fail with an 'uninitialized
variables' error. The change has no functional impact.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-02-04 18:11:18 +01:00
Thomas Ebert Hansen 4efbbce692 Bluetooth: controller: Fix settings dependency
BT_CTLR_SETTINGS should not depend on BT_SETTINGS as this will prevent
using settings system in the controller in a controller only build.
(BT_SETTINGS depends on BT_HCI_HOST)

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2020-02-04 12:50:27 +01:00
François Delawarde 9d2e34e9c8 bluetooth: host: Add workaround for USB HCI controllers
This commit adds a new option CONFIG_BT_SMP_USB_HCI_CTLR_WORKAROUND
to support USB HCI controllers that sometimes send out-of-order HCI
events and ACL Data due to using different USB endpoints.

Enabling this option will make the master role not require the
encryption-change event to be received before accepting
key-distribution data.

It opens up for a potential vulnerability as the master cannot detect
if the keys are distributed over an encrypted link.

Fixes: #22086

Signed-off-by: François Delawarde <fnde@oticon.com>
2020-02-03 18:39:55 +02:00
Vinayak Kariappa Chettimada 814654af80 Bluetooth: host: Invalid role used in finding connections
Directed advertising timeout was dropped in the host due to
not being able to find a pending connection. Host used the
role parameter from the error event parameters which has
been earlier zero-ed out.

Regression introduced in commit a0349689ff ("Bluetooth:
host: Fix conn object assigned to wrong connection")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-03 12:51:59 +02:00
Joakim Andersson a570be6e93 Bluetooth: host: Refresh advertiser NRPA when active scan is using NRPA
When starting a non-connectable advertiser and an active scanner is also
using NRPA address then this use-case should be supported. A new
advertiser that is non-connectable should have a fresh NRPA address
every time it is started, so we must refresh the NRPA used by the active
scanner.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-03 12:44:39 +02:00
Joakim Andersson d977282514 Bluetooth: host: Scanner must be disabled to update to NRPA address
When advertiser is disabled we should update the random address for both
passive and active scanner back to an NRPA. But this command will fail
because the if the scanner is an active scanner, we must disable and
re-enabled the active scanner after setting the random address.
This behavior should not be there when scanner is configured to scan
with identity address.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-03 12:44:39 +02:00
Joakim Andersson 499b4e0ce0 Bluetooth: host: Document privacy-disabled directed advertising reports
Document why a privacy-disabled scanner will not notify about directed
advertising reports. This is the default behaviour of the
privacy-disabled scanner. In order to receive the reports the option
BT_SCAN_WITH_IDENTITY must be enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-03 12:44:39 +02:00
Joakim Andersson 56bbc4e6d3 Bluetooth: host: Prevent adv overwriting passive scan identity address
Prevent the advertiser from overwriting the passive scanners identity
address when the scanner has been configured to scan using the identity.
In this case the LE Set Random Address command would not prevent the
address from being overwritten. So instead we explicitly stop it in the
host.

Also fix original code function not working at all since the first
if statement was should had a bad check. Resulting in it always
returning success.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-03 12:44:39 +02:00
Joakim Andersson a6b978b1f2 Bluetooth: host: Drop directed adv reports for NRPA passive scanner
Drop directed advertiser reports when the passive scanner should have
been using the NRPA address. The advertiser has overwritten the NRPA
with it's identity address instead and a peer is sending directed
advertiser packets to it.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-02-03 12:44:39 +02:00
Trond Einar Snekvik a112f1568d Bluetooth: host: Skip set passive scan when not scanning with identity
When privacy is disabled by default the scanner still protects it's
identity with the use of NRPA addresses. We should not set the identity
address for the passive scanner unless the Kconfig option to scan with
the identity has been enabled.

This makes passive scanner behave the same way as an active scanner
since none of them will report directed advertising reports towards
the scanners identity.

This also enables the advertiser to switch out the random address which
is needed for the Bluetooth Mesh LPN case.

Fixes #22088.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-02-03 12:44:39 +02:00
Joakim Andersson 9dc4eed622 Bluetooth: shell: Add support for pairing accept callback
Add pairing support callback to print remote pairing features when this
option is enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-31 20:39:25 +02:00
Martin Rieva 2685a94c02 Bluetooth: Host: Add generic pairing query callback
Similar to pairing_confirm this callback is called each
time a peer requests pairing, but for all types of
pairings, except SSP. The pairing req/rsp information is
passed as a parameter so the application can decide
wheter to accept or reject the pairing.

Fixes: #21036

Signed-off-by: Martin Rieva <mrrv@demant.com>
2020-01-31 20:39:25 +02:00
Joakim Andersson ac05ae3d25 Bluetooth: Fix controller RPA calling into host with host-based crypto
In a combined build where bt_rand functions is implemented in the host
the RPA module should not use the bluetooth rand function since the RPA
module is common for host and controller.
Having the controller call the the host only to go through HCI back into
the controller would not be a good idea.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-31 18:33:06 +01:00
Joakim Andersson 291ebdd4e4 Bluetooth: Fix infinite recursion in host-based bt_rand
Fix infinite recursion in host-based bt_rand function. This would call
HCI LE Random Number command, which would in turn call bt_rand, causing
an infinite recursion.

bt_rand -> prng_reseed -> BT_HCI_OP_LE_RAND -> le_rand -> bt_rand

To solve this issue the controller should avoid doing calls into the
host, so all calls to bt_rand in the controller should be replaced with
a call to a controller function.

Fixes #22202

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-31 18:33:06 +01:00
Joakim Andersson bdc535dba3 Bluetooth: host: Fix out of range parameters provided to the controller
Fix LE Create Connection command giving out of range parameters to the
controller, this came back as 0x30 (Out of Range Parameters) status code
on the command from the controller.
This appears to be the min and max CE parameters in the command.
Revert back memset from 137f704064

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-31 17:45:11 +02:00
Joakim Andersson 8629f0a450 Bluetooth: host: Fix app notified connected but no connection exists
Fix problem where application was notified about a new connection being
established, but no connection has actually been made.
This occurred because the LE Create Connection command failed directly
from the API, in which case the state transition thinks the err is valid
and always notifies the application.

Introduced by:
6c1f52dff7 for bt_conn_create_le
e9eebf0c40 for bt_conn_create_auto_le.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-31 17:45:11 +02:00
François Delawarde a3e89e84a8 bluetooth: host: Fix simultaneous pairings getting the same keys slot
Fix an issue where a slot in the key pool was considered free when
either the address was cleared or no keys were written in the entry
(enc_size == 0). This caused a problem with simultaneous pairing
attempts that would be assigned the same entry.

This patch makes it so a a slot is considered free even when keys are
not yet present in the entry, and makes sure the address is cleared in
case of pairing failure or timeout so to mark the slot as free.

Signed-off-by: François Delawarde <fnde@oticon.com>
2020-01-31 12:50:03 +02:00
Rubin Gerritsen 171a9fa167 bluetooth: controller: Guard SW based privacy config by Zephyr LL
SW based privacy is an implementation detail in the zephyr link layers.
Therefore it should not be visible when selecting an out-of-tree
controller.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-01-31 10:59:35 +01:00
Morten Priess 2945143edd Bluetooth: controller: split: Force central cleanup on MIC error
Since a peer MIC failure closes the event, it does not allow a terminate
acknowledge. For that reason a peer MIC fail for central role must force
a conn_cleanup.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-01-31 10:15:19 +01:00
Andries Kruithof 3db3ae5aed Bluetooth: controller: split: Fix DLE preparation routine
This fixes the EBQ tests 129 and 130. These tests check behaviour for
the DLE procedure when Encoded PHY or 2M PHY are not supported.
See also BT core spec. Version 5.1, Vol6, Part B, Section 5.1.9

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-01-30 15:25:40 +01:00
Erik Brockhoff 88f8880e16 bluetooth: controller: fixing issue with white list clear
When clearing the whitelist, possible white listings in resolve list
were left. These are now also cleared.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2020-01-30 15:11:45 +01:00
Trond Einar Snekvik 4ea59711d2 Bluetooth: Move Mesh CCM into a separate module
Moves the Mesh AES-CCM module out into a separate module, to make it
accessible from other subsystems. Adds the new CCM API in
include/bluetooth/crypto.h along with the bt_encrypt functions.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-01-30 12:41:45 +02:00
Johan Hedberg 637582dfae Bluetooth: Mesh: Fix provisioning buffer initialization
When PB-GATT support has been enabled the provisioning code "borrows"
the buffer from the proxy code. However, the way that initialization
was happening the proxy buffers were initialized only after
provisioning initialization, resulting in a corrupted buffer with
buf->data pointing to NULL. Reorder the initialization calls so that
proxy is done first and provisioning only after it.

Fixes #22207

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-01-29 18:59:40 +02:00
Vinayak Kariappa Chettimada 0ee81aab9a Bluetooth: controller: Clean up nrf cmake include
Clean up the nRF cmake include file to remove redundant
check for BT_LLL_VENDOR_NORDIC inside the file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-29 15:27:24 +01:00
Wolfgang Puffitsch 2071c2fb7a Bluetooth: controller: Support SMI TX flag as setting
SMI TX is different than other controller features in that it does not
necessarily imply any software changes; whether SMI TX is supported
may be simply a matter of hardware calibration. This change supports
using the same software on chips that do or do not support SMI TX
depending on calibration.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-01-28 20:28:50 +01:00
Wolfgang Puffitsch e477c5a525 Bluetooth: controller: Add feature bits for SMI support
Enable setting features bits for Stable Modulation Index in controller
features.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-01-28 20:28:50 +01:00
Joakim Andersson 576c68317a Bluetooth: L2CAP: Reset channel status before destroy callback
Move reset of channel status from after the destroy callback since the
after the destroy callback the memory should be assumed to be released.
Instead clear the channel status when the channel is created in
l2cap_chan_add. This way we don't rely on the memory given being set to
the correct value.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-28 17:55:38 +02:00
Joakim Andersson d84528edb1 Bluetooth: ATT: Fix ATT corrupting mem_slab structure after free
Fix ATT releasing the att structure back to the memory slab allocator
before the structure is actually ready to be released. The memory slab
allocator will write context data inside the freed slab which is
currently being overwritten by l2cap during channel teardown.

This manifests as an "Unable to allocate ATT context for conn" when
reconnecting with multiple connections.

Since the l2cap channel is embedded inside of the ATT context and l2cap
still has a valid referenc to the l2cap channel we need to release the
ATT context at a later time.
This should be fixed by implementing the channel destroy function and
releasing the channel there.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-28 17:55:38 +02:00
Joakim Andersson 83f108afd1 Bluetooth: L2CAP: Add destroy callback to fixed L2CAP channels
Add the option to provide the destroy callback to the fixed channels.
This can be used to free the memory for the L2CAP channel context which
is provided by the fixed channel in the accept callback.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-28 17:55:38 +02:00
Morten Priess c20a870b6b bluetooth: controller: Added use of slot_window for ADV
Request ticker re-scheduling of ADV (within the 10ms randomized window).

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-01-28 08:07:54 +01:00
Morten Priess 64c89d682f bluetooth: controller: Implemented dynamic re-scheduling in ticker
As a part of a ticker extension interface, it is now possible to specify
a slot_window when starting a ticker. When setting the
ticks_slot_window to a non-zero value, it is requested that the node
timeout is re-located to a position within the window, where the node
does not collide with other nodes - aligning to the end of the window.
The solution takes into consideration if a node has already been
updated with drift correction (e.g. ADV randomization), subtracting this
from the window.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-01-28 08:07:54 +01:00
Vinayak Kariappa Chettimada c793c0edda Bluetooth: controller: split: Update lll_conn_flush interface
Updated the lll_conn_flush interface to pass the connection
handle while the LLL connection context stored handle has
been invalidated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-27 13:51:08 +01:00
Vinayak Kariappa Chettimada d9c67ebd77 Bluetooth: controller: split: Revert Move invalidation of connection handle
This reverts commit d3e3f8d2b4.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-27 13:51:08 +01:00
Vinayak Kariappa Chettimada 43d8166045 Bluetooth: controller: split: Revert conn handle invalidation
This reverts commit 7417e6e09e.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-27 13:51:08 +01:00
Marek Pieta bce335458b Bluetooth: ATT: Fix handling ATT response
The callback function may modify the att->req and it has to be
called after the att_process. The att_process does not re-check
if att->req is still NULL.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2020-01-25 22:39:45 +01:00
Ulf Magnusson 0618cf00e8 Bluetooth: host: kconfig: Fix broken ref. to BT_CTLR_TX_BUFFER_SIZE
The CONFIG_ prefix was missing.

Found with a work-in-progress scripts/kconfig/lint.py check.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-25 08:15:34 -05:00
Joakim Andersson bf33338652 Bluetooth: host: Fix net buf assert on att encrypt change event
Fix assert in net_buf triggered on att encrypt change event.

	ASSERTION FAIL [net_buf_simple_headroom(buf) >= len] @
	  ZEPHYR_BASE/subsys/net/buf.c:881

This happens because when the att request was allocated, it was not
properly initialized and req->retrying was left as true.
This caused the att encrypt change handling to assume an att request
needed to be resent, starting resending with an invalid request and
request buffer.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-23 18:08:24 +02:00
Ulf Magnusson f84abe9011 Bluetooth: shell: kconfig: Do not select FLASH_SHELL from BT_SHELL
Fixes some selects with unsatisfied dependencies. FLASH_SHELL depends on
FLASH_PAGE_LAYOUT, but only FLASH_SHELL is selected. The select was
introduced in commit 3aa2a1c6db ("flash: make flash shell generic").

Spoke to Johan Hedberg. The BT_SHELL code does not depend on
FLASH_SHELL. He didn't think people would assume that BT_SHELL by itself
enables the FLASH_SHELL commands either.

Just remove the select.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-23 17:54:08 +02:00
Alex Porosanu 3412612085 bluetooth: controller: refactor CMake related files
Zephyr aims to enable supporting of multiple SW defined
BLE LL. There is a complex hierarchy of defines in the
CMake files controlling the compilation units that part of
the final library. Adding another SW LL implementation
from a different SoC provider will make the main controller
CMake file unmaintable.
As such, split the into vendor-specific CMake files for
easier additions.

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2020-01-23 16:08:00 +01:00
Marek Pieta e2905c09cb Bluetooth: controller: Fix Kconfig dependency
Change adds missing Kconfig dependency.
The CONFIG_BT_CTLR_FILTER is used only for SW Link Layers.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2020-01-23 11:00:17 +01:00
Joakim Andersson 813e5bdd7a Bluetooth: host: Refactor use of #ifdef to IS_ENABLED()
Refactor use of #ifdef to IS_ENABLED() pattern for handling cancellation
of outgoing connection attempt. Reduce the amount of indentation by
combining outer if-statements.
Move handling of canceled create connection into a helper function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Joakim Andersson 64b890463d Bluetooth: host: Fix advertiser with identity switches to RPA
Fix advertiser requested to use the identity address while privacy
feature is enabled will change to using RPA address when advertise is
resumed or when RPA timeout occurred.
RPA timeout does not need to run when advertiser is using identity.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Joakim Andersson 93d25321b6 Bluetooth: shell: Add shell command for advertise with identity option
Add shell command for advertise with identity option to have the
possibility to temporarily disable privacy feature in the advertise from
the shell.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Joakim Andersson fbe3285bfa Bluetooth: host: Handle initiator at RPA timeout
Handle initiator role when RPA timeout expires. For direct connect
establishment procedure we make sure the RPA is refreshed when starting
initiator and limit the timeout to the RPA timeout.
For auto establishment procedure we cancel the initiator and restart it
again in the connection complete event that is generated when canceling
an initiator.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Joakim Andersson 99662c63bc Bluetooth: host: Handle starting roles with different random address
Handle starting of advertiser and scanner or initiator when advertiser
is using a different identity than the default identity to generate the
random resolvable address in the controller.
We need to handle this only for the privacy case because the random
address is set in the RPA timeout handler and not from the API.
When privacy is disabled we can return error code from the LE Set Random
Address HCI command instead.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Joakim Andersson 4876a8f39a Bluetooth: host: Handle scanner active at RPA timeout
Fix RPA timeout handling when the scanner is active. An active scanner
must be restarted at RPA timeout otherwise the Set Random Address
command will fail.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Joakim Andersson 137f704064 Bluetooth: host: Refactor initiator to common code and initiator state
Refactor the handling of sending the LE Create Connection command and
for whitelist and direct initiator to use the same host state flag
and common handling of the privacy address.
Also simplify the way we check if the procedure has already been started
when application tries to start it again.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Joakim Andersson 6c1f52dff7 Bluetooth: host: Set conn state before sending HCI command
Handle a possible race condition in the host connection state.
Set the conn state of the connection object before command is sent. This
is in case the calling function is not scheduled again before the
connection complete event arrives. In this case find_pending_conn will
not find the connection object.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Joakim Andersson cc6b8c3a6f Bluetooth: host: Ifdef starting of background scanner in init
Starting a background scanner for auto-connection is an API that is only
available when whitelist API is not enabled.
There is currently no way to set this bit when the whitelist API is
enabled so there is not any issues with the current code, but it is
still not correct.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Joakim Andersson 0861c8c834 Bluetooth: host: Disconnect connection if no conn object is available
When receiving a connection complete event but no connection object are
available in the host something strange has happened. In this case
the controller might have a connection that cannot be controlled by the
application. It would then be sensible to disconnect this connection in
the controller.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Ulf Magnusson 4e85006ba4 dts: Rename generated_dts_board*.{h,conf} to devicetree*.{h,conf}
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>
2020-01-17 17:57:59 +01:00
Erik Brockhoff 48b6dae329 Bluetooth: controller: split: ULL filter API modifications
Moving struct definitions into header file and adding API to
allow accessing data-structures from lll context

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2020-01-17 17:11:54 +01:00
Joakim Andersson 8b98231e4f Bluetooth: HCI: Fix allow Zephyr VS HCI commands in host-only build
Fix unable to select the Zephyr Vendor-Specific HCI commands support in
host-only build. Set VS HCI support as default on if it is known that
the controller supports it. Otherwise set it to off, this means that
VS HCI support will be default off in host-only builds.

Fixes: #21996

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-17 13:55:56 +02:00
Carles Cufi 6cf7ac77bf Bluetooth: Always use full path to hci_driver.h
The path to include/drivers should not be in the compiler include path
list, only include/. In order to make this possible, always explictly
refer to hci_driver.h via the drivers/bluetooth/ path and not only
bluetooth/.

Fixes #21974.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-01-16 19:20:39 -05:00
Dominik Ermel 50f7555789 Bluetooth: Selecting ENTROPY_GENERATOR for crypto
Bluetooth sample with controller crypto, requires sys_rand32_get that
used to be linked with Tinycrypt. The selection, within Kconfig of
Tinycrypt, that has been enabling compilation of the symbol has
been removed and thus preventing controller crypto to link.

This commit moves the selection to BT_CTLR_CRYPTO.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-16 13:25:31 +01:00
Trond Einar Snekvik 19718fd6da Bluetooth: Mesh: Skip publish if update fails
Allow models to skip a periodic publish interval by returning an error
from the publish update callback.

Previously, an error return from publish update would cancel periodic
publishing. This can't be recovered from, and as such, no valid model
implementation could return an error from this callback, and there was
no way to skip a periodic publish.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-01-16 14:13:37 +02:00
Vinayak Kariappa Chettimada b5c63c69ca Bluetooth: controller: split: Fix ull_disable hang
Under race conditions it is possible that there is no call
to k_sem_give to the waiting k_sem_take in the ull_disable
function.

ull_disable function checks for reference count before
using a mayfly to schedule lll_disable, which in turn
would close requested currently active role event leading
to done event being propogated to ULL. Done event would
then call the set disabled_cb callback when the reference
count is zero, giving the semaphore to the waiting
k_sem_give in the ull_disable.

Under race conditions if the reference count reached zero
after the reference count check and before the disabled_cb
was assigned in the ull_disable function, then there are
chances that a k_sem_give is not called while ull_disable
proceeds to waiting using k_sem_take.

Fixes #21586.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-16 10:54:40 +01:00
Wolfgang Puffitsch dbdfd2995b Bluetooth: host: Guard calls to bt_conn functions
Guard calls to bt_conn functions in bt_le_adv_start_internal with
IS_ENABLED(CONFIG_BT_PERIPHERAL) to avoid undefined symbols in builds
that do not support that role.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-01-16 08:53:21 +01:00
Vinayak Kariappa Chettimada 9a6d200cb9 Bluetooth: controller: legacy: Fix redundant priv variable check
Fix the redundant check of priv flag variable introduced as
regression in commit f8877e39ce ("Bluetooth: controller:
legacy: Fix controller address check").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-16 08:49:35 +01:00
Vinayak Kariappa Chettimada 51c46d94ed Bluetooth: controller: Fix CONFIG_BT_CTLR_TX_BUFFER_SIZE range
Fix CONFIG_BT_CTLR_TX_BUFFER_SIZE value range to 251 Bytes
due to implementation limitation in use of u8_t for PDU
length fields in controller Tx buffers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-15 15:26:19 +01:00
Vinayak Kariappa Chettimada 8cd9a94b2f Bluetooth: controller: split: Fix controller privacy address check
Fix controllers address check in cases of controller-based
privacy is supported but not used to start advertising.

This fixes regression introduced in
commit 896619ad40 ("Bluetooth: controller: Fix
controller address check").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-15 15:24:55 +01:00
Andries Kruithof 98430a61cf Bluetooth: controller: split: Refactor DLE prepare
Refactor the event_len_prep routine to increase readability without
affecting code size

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-01-15 14:01:23 +01:00
Andries Kruithof 26a97aed4f Bluetooth: controller: split: Fix LENGTH_REQ PDU prepare
There is an obscure bug in the case that CFG_BT_CTLR_PHY is not defined;
when a feature-exchange already has happened the lr->max_tx_time and
lr->max_rx_time are not calculated.
This bug is fixed by this commit.

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-01-15 14:01:23 +01:00
Joakim Andersson ca2d3f0a89 Bluetooth: Kconfig: Fix error in buffer pool sizes
Fix error in calculation of the minimum discardable buffer size. For
the LE Advertising Report the maximum payload is 31 bytes plus
additional data in the event gives an event size of 41 bytes (given that
num_reports is 1). Since this is a meta event we need to include the
sub-event code, plus the event header of 2 bytes. Total of 44 bytes.

This is a regression from afa9c42d75 where we forgot th 1 byte for the
RSSI that is appended after the data. Easy to miss since it is not part
of the struct.

Fix error in calculation of the num complete buffer size. Here we forgot
to include the 2 byte event header.

This is a regression from 89981b07c8.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-14 21:19:17 +01:00
Rubin Gerritsen 4ce9c9d59c bluetooth: controller: Guard zephyr LL specific configurations
This change prevents zephyr LL specific configurations to show up when
using an out of tree BLE controller.

BT_CTLR_ASSERT_HANDLER is used outside the controller as well,
so this is kept as is.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-01-14 11:07:40 -05:00
Joakim Andersson 4401b6a2f3 Bluetooth: host: Stop using existing conn object when creating new conn
Remove re-using connection objects in disconnected state when creating
directed advertiser or establishing a connection as a central using
direct connection procedure.
This makes the API mores consistent it terms of which connection roles
can be started from the disconnected callback.
This also avoids a central connection object being re-used for a
connection as a peripheral instead and vice versa.

When attempting to create a new connection the API would returning
a valid connection object if there is already an existing connection
object.
This existing connection object could be either in the process of
establishing the connection or already connected.
Returning the connection object in this would give the false impression
that the stack has initiated connection procedure, when in fact it just
returned an existing connection object.

The application has the ability to check for existing connection objects
using the bt_conn_lookup_addr_le API.

Add warning plus comment possible scenarios why the a valid connection
object might exists. Most important is to explain why a valid connection
object exists during the disconnected callback.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-14 14:27:31 +01:00
Joakim Andersson 46bf20036a Bluetooth: host: Reserve conn object for connectable advertiser
Reserve conn object for undirected connectable advertiser. This means we
won't have a situation where we start a connectable advertise but will
fail to allocate a connection object for it in the connection complete
event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-14 14:27:31 +01:00
Joakim Andersson e9eebf0c40 Bluetooth: host: Reserve conn object for connecting with whitelist
Reserve a connection object when starting the auto-initiator using the
controller whitelist.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-14 14:27:31 +01:00
Joakim Andersson e91f9804e6 Bluetooth: host: Fix error code when calling API before init
Fix bt_conn_create_aute_le returning the wrong error code when bt_init
has not been called yet. This is inconsistent with the rest of the API
functions.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-14 14:27:31 +01:00
Joakim Andersson c635425487 Bluetooth: host: Refactor stopping directed advertiser
Refactor stopping directed advertiser to disconnect the state object
when calling advertise stop. This follows the same pattern as
bt_conn_disconnect.

Remove returning conn objects in BT_CONN_CONNECT state, this state could
only  be an initiator starting a connection in the central role.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-14 14:27:31 +01:00
Joakim Andersson a45226a238 Bluetooth: host: Clear auto-conn state when failed to get conn object
Make sure that the auto-conn state is cleared correctly when we might
fail to allocate a new connection object.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-14 14:27:31 +01:00
Joakim Andersson a0349689ff Bluetooth: host: Fix conn object assigned to wrong connection
Fix conn object assigned to the wrong controller connection in the
connection complete handler. This could happen when running a
directed advertiser and establishing a connection at the same time to
the same peer.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-14 14:27:31 +01:00
Joakim Andersson 89981b07c8 Bluetooth: host: Lower the size of the num_complete buffer
Set the size of the num complete buffer to the maximum possible size it
can be.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-13 17:59:00 +01:00
Joakim Andersson afa9c42d75 Bluetooth: host: Add config option for discardable buffer size.
Add option to set the size of the discardable buffer pool. This saves
memory for the MESH use case where we expect a large number of advertise
reports.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-13 17:59:00 +01:00
Trond Einar Snekvik 5b14ab4481 Bluetooth: Add dynamic le scan listener interface
Adds a way to register listeners for incoming scanner packets, in
addition to the callback passed in bt_le_scan_enable.

This allows application modules to add multiple scan packet listeners
without owning the scanner life cycle API, enabling use cases like
beacon scanning alongside Bluetooth Mesh.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-01-13 14:27:01 +01:00
Joakim Andersson 08168f60f7 Bluetooth: assert: Change printed expression to printing line and file
Change 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.

Also using a formatted string would save code space as we can use the
same string for all messages instead of creating a unique one for each
condition.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-13 13:59:55 +01:00
Ahmed Hussein d24e5e520c Bluetooth: Mesh: Enable Segmented Control Messages
The function bt_mesh_ctl_send() used to support maximum length of
11 bytes. The segmentation complies with the BLE Mesh Standard.
The ack is disabled in case of non unicast address.

Signed-off-by: Ahmed Hussein <ahmed_hussein_@hotmail.com>
2020-01-11 18:20:52 +01:00
Trond Einar Snekvik 723e14a432 Bluetooth: Mesh: Model start callback
Replaces the Mesh model settings_commit callback with a start callback,
indicating that the mesh model behavior is ready to start. Everything
that was previously done in the settings_commit callback may be moved to
this callback, which gets called just after mesh settings are committed,
instead of in the middle of the process.

This resolves an issue where models had no context in which to start
their behavior, as the previous settings_commit call fired before the
mesh was declared valid, making access APIs inaccessible.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-01-11 18:20:00 +01:00
Kim Sekkelund 9ea6e72bae Bluetooth: host: cfg_write callback to return error code
Current implementation of application's cfg_write callback only has the
possibility of returning boolean status, which in case of failure only
allows for one error code; BT_ATT_ERR_WRITE_NOT_PERMITTED.
This change makes the application able to add own security check on
characteristic subscription in the cfg_write callback and report a more
relevant error code (e.g. BT_ATT_ERR_AUTHORIZATION).

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2020-01-10 17:41:15 +01:00
Joakim Andersson c336539249 Bluetooth: host: Remove toggling advertiser on advertise data update
Remove toggling the advertise enable state when the advertiser name has
been updated. Advertise and scan response data should be used by the
controller on subsequent advertising events.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-10 17:10:46 +01:00
Andries Kruithof 44daa9f15c Bluetooth: controller: Refactor time calculation for LL DLE procedure
Refactor the PKT_US macro to show more clearly where the different
fields come from

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-01-10 14:10:23 +01:00
Luiz Augusto von Dentz 708c8bae54 Bluetooth: ATT: Use k_mem_slab for connection context
This uses k_mem_slab APIs to allocate/free ATT context instead of custom
array.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-01-09 19:20:21 +01:00
Luiz Augusto von Dentz aa7013b9bd Bluetooth: shell: Fix not reseting value_handle if subscription fails
If bt_gatt_subscirbe fails value_handle must be reset since otherwise it
will not possible to subscribe again as the parameters will be consider
in use.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-01-09 19:20:21 +01:00
Luiz Augusto von Dentz 3be9980bd6 Bluetooth: GATT: Remove _peer member from bt_gatt_subscribe_params
This further reduce the overhead on each subscription at expense of
having a dedicated array to store subscriptions, the code now maintain
a separate list for each peer which should also scale better with large
number of subscriptions to different peers.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-01-09 19:20:21 +01:00
Luiz Augusto von Dentz d278cdc3d7 Bluetooth: GATT: Allocate request from a memory slab
This should reduce the footprint on applications that do a lot of
requests i.e have a lot of subscriptions.

Fixes #21103

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-01-09 19:20:21 +01:00
Vinayak Kariappa Chettimada f8877e39ce Bluetooth: controller: legacy: Fix controller address check
Fix controllers address check in cases of controller-based privacy.
When controller has been instructed by the host to use privacy
the controller should look up the peer identity address and generate
an address based on the local IRK. In the case where no match
is found or the local IRK is all zeroes the controller shall use
the fallback address. If the fallback address is not valid the
controller shall return invalid params.

This commit fixes these issues:
 - Starting a private advertiser without valid random address set
   but a valid local IRK exists. In this case the advertiser should
   be able to advertise using the RPA regardless of a valid random
   or public address.
 - Starting a private advertiser with a fallback to the public
   address type or an adveriser using public address  does not
   check if a valid public address exists. The host cannot
   advertise with an all-zero public address.

Signed-off-by: Joakim Andersson <joerchan@gmail.com>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-09 15:34:23 +01:00
Joakim Andersson f5d2b3271a Bluetooth: controller: Fix bug in LE create conn with filter policy
Fix bug when connecting using whitelist and split controller.
The peer address was set to an all zeroes address.

Bug using shell:
bt init
bt wl-add <addr>
bt wl-connect on
Connected: 00:00:00:00:00:00 (public)

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-08 10:48:47 +01:00
Marco Sterbik 9217c6634e bluetooth: fix removal of needed subscriptions
Providing 'tmp', which was never updated, resulted in removeal of
subscriptions from the beginning.
Using the updated 'prev' resolves this.

Signed-off-by: Marco Sterbik <madbadmax00@gmail.com>
2020-01-07 17:01:25 +01:00
Joakim Andersson 57addad856 Bluetooth: host: Use direct connection if not host resolving list
Start initiator immediately instead of scanning for device first.
If the host resolving list is used we need to go via scanner to resolve
the address.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-07 16:04:03 +01:00
Vinayak Kariappa Chettimada 19ac87c4f0 Bluetooth: controller: Add set adv param cmd param validation
Added implementation to validate HCI LE Set Advertising
Parameters Command parameters.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-06 17:42:34 +01:00
Vinayak Kariappa Chettimada ec1e66ebd8 Bluetooth: controller: Add Kconfig option for parameter checking
Added Kconfig option to conditionally compile in HCI command
parameter validation code.

When building a combined host plus controller application,
only validations in the host at the top level close to the
API caller is sufficient.

The controller validations are included in controller only
builds.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-06 17:42:34 +01:00
Christopher Friedt 5308a941a9 Bluetooth: controller: define adv channel access address as macro in pdu.h
The new macro is PDU_AC_ACCESS_ADDR

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-01-06 09:58:18 +01:00
Jacob Siverskog 6eef6cd946 Bluetooth: host: Rethink how unpair all works
Instead of having all (=addr NULL or BT_ADDR_LE_ANY to bt_unpair) as a
special case, iterate over all connected peers and unpair them the
regular way. This means bt_gatt_clear is called too. Doing this way
allows us to remove a lot of (now) unused code as well.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2020-01-04 14:10:46 +01:00
Vinayak Kariappa Chettimada c9c65a9b9b Bluetooth: controller: split: Pass scanner LLL context in event
Pass the scanner LLL context in the generated connection
complete event with unknown connecion id for HCI Create
Connection Cancel Command Response.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-03 14:16:16 +01:00
Vinayak Kariappa Chettimada 13a3270096 Bluetooth: controller: split: Fix assert in PDU Rx quota increment
Directed advertising timeout released PDU Rx quota which it
should not be.

Relates to assert in #21006.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-03 14:16:16 +01:00
Vinayak Kariappa Chettimada ca8b6028c6 Bluetooth: controller: split: Move statements close to related context
Minor refactor, move statements close to related context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-03 14:16:16 +01:00
Vinayak Kariappa Chettimada 4f42baa43d Bluetooth: controller: split: Use define instead of magic number
Use HCI Error Code define instead of magic number.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-03 14:16:16 +01:00
ZhongYao Luo a94e81ba3e Bluetooth: RFCOMM: Fix length errors when payload exceeds 127
hdr->length is the length of the payload, it should be
buf->len - sizeof(*hdr) - 1 or buf->len - (sizeof(*hdr) + 1)

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2020-01-03 10:14:59 +01:00
Aurelien Jarno b35d414916 Bluetooth: Mesh: Fix PreviousAddress endianess in Friend Request
The upper transport layer is using big endian ordering. The
PreviousAddress field of a Friend Request message should therefore
be converted to native endianess using sys_cpu_to_be16().

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2020-01-03 10:14:10 +01:00
Joakim Andersson 63567c90ea Bluetooth: mesh: Add comment explaining use of byte order
Add comment that explains why a different byte order is used for the
3-byte opcode on the CID part of the opcode.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-02 19:05:27 +01:00
Joakim Andersson f675e14718 Bluetooth: controller: Use 24-bit functions for LL Features
Use 24-bit functions for LL Features copying to make byteorder more
readable.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-02 19:05:27 +01:00
Joakim Andersson 6426cd58fc Bluetooth: mesh: Use 24-bit functions
Use 24-bit functions for byteorder and net_buf in order to make the
byteorder used more readable.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-02 19:05:27 +01:00
Vinayak Kariappa Chettimada f5bbb4d3fd Bluetooth: controller: legacy: Fix tx_time calculation for length update
Fix tx_time calculation for the case that BT_CTRL_PHY is defined and
there has not been a feature exchange.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-02 16:53:54 +01:00
Wolfgang Puffitsch 41e6016885 Bluetooth: controller: split: Fix tx_time calculation for length update
Fix tx_time calculation for the case that BT_CTRL_PHY is defined and
there has not been a feature exchange.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-01-02 16:53:45 +01:00
Luiz Augusto von Dentz 2cfef8cd77 Bluetooth: L2CAP: Fix using s16_t to represent credits
Credits are 2 octects long so an s16_t positive portion can only half to
the theorical maximum number of credits, so instead this uses u16_t and
do a bound check instead of checking for negative values.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-01-02 16:53:27 +01:00
Luiz Augusto von Dentz 4ff711d8a5 Bluetooth: L2CAP: Remove use of k_sem for credits
With the changes that introduced a queue k_sem is only used with
K_NO_WAIT which means it is no longer possible to wait/block for credits
so the usage of k_sem is no longer needed and can be safely replaced
with atomic_t just to count the available credits at a given instant.

Fixes #19922

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-01-02 16:53:27 +01:00
Johan Hedberg 4e135d76a3 Bluetooth: shell: Add printing of remote version information
Add printing of the remote version information whenever the new
CONFIG_BT_REMOTE_VERSION option is enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-12-23 14:47:31 +02:00
Sverre Storvold 649a813bf6 Bluetooth: host: Add calling of read_remote_version
Make remote features and remote version accesible to the application
through the bt_conn_get_remote_info object. The host will auto initiate
the procedures. If the procedures have not finished with the application
calls bt_conn_get_remote_info then EBUSY will be returned.
The procedures should finish during the first 10 connection intervals.

Signed-off-by: Sverre Storvold <Sverre.Storvold@nordicsemi.no>
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-23 14:47:31 +02:00
Joakim Andersson 32bde4fe78 Bluetooth: host: Refactor host auto initiated LL procedures
Refactor the handling of the host auto initiated LL procedures.
This makes it easier to add new auto initiated procedures as well as
reduced the maintenance by reducing code duplication.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-23 14:47:31 +02:00
Joakim Andersson 40c20b1f18 Bluetooth: Change remote version event from prio to normal event type
This commit reverts the change that moved the remote version event from
a priority event to a normal event. This is done because the strategy
for using this event has been changed and will be used with a callback
instead of a semaphore that could be locked from the RX thread.

This commit retains the infrastructure that was added in the controller
so that moving events to priority processing is still possible.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-23 14:47:31 +02:00
Johan Hedberg cbb7ef5560 Bluetooth: shell: Fix floating point usage
Avoid floating point usage when possible. E.g. on qemu_x86 this would
otherwise result in something like the following:

<err> os: Floating point unit not enabled
<err> os: eax: 0x00000024, ebx: 0x00000000, ecx: 0x00248fc8,
          edx: 0x00146120
<err> os: esi: 0x0012b30c, edi: 0x0024c628, ebp: 0x0024c638,
          esp: 0x0024c5b8
<err> os: eflags: 0x00000216 cs: 0x0008 cr3: 0x001465a0
<err> os: call trace:
<err> os: eip: 0x00121c8d
<err> os:      0x0010679c (0x127750)
<err> os:      0x0010693b (0x100f33)
<err> os:      0x001061bc (0x12b800)
<err> os:      0x001074fb (0x0)
<err> os:      0x00101151 (0x12b800)
<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception
<err> os: Current thread: 0x00146120 (shell_uart)
<err> os: Halting system

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-12-23 14:47:31 +02:00
Ulf Magnusson 6ef29c0250 kconfig: Remove some redundant single-item menus and ifs
A single menu within an if like

    if FOO

    menu "blah"

    ...

    endmenu

    endif

can be replaced with

    menu "blah"
            depends on FOO

    ...

    endmenu

Fix up all existing instances.

Also remove redundant extra menus underneath 'menuconfig' symbols.
'menuconfig' already creates a menu.

Also remove the menu in arch/arm/core/aarch32/Kconfig around the
"Floating point ABI" choice. The choice depends on FLOAT, which depends
on CPU_HAS_CPU, so remove the 'depends on CPU_HAS_FPU' too.

Piggyback removing a redundant 'default n' for BME280.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-21 10:26:54 -05:00
Joakim Andersson b69edc3844 Bluetooth: HCI: Check length of VS command complete
Always check that the length of the returned command complete
event for a vendor specific command matches the expected length
when the support for Zephyr VS HCI commands are uncertain.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-20 15:45:34 +01:00
Joakim Andersson a34d4afe7d Bluetooth: Host: Fix issues with host IRK handling
Fix multiple issues related to the way the host handles
Identity Information related to privacy

1. If the controller provided a public address the IRK
   for this identity would be randomly generated but not
   stored persistenly.

2. Fix the handling of the above issue which was fixed
   for the random address but would initiate settings save
   ID on every boot.

3. Fix the host not using the Vendor Specific HCI commands
   related to retrieving the Identity Root (IR) from the
   controller and using the key diversified function d1
   to generate an IRK as specified in the BT Core spec.

Make sure that a Host generated ID is only saved when it is first
generated.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-20 15:45:34 +01:00
Joakim Andersson 091ebf905d Bluetooth: controller: Return FICR as a static address IR
Return the IR defined in FICR as the Identity Root for the static
address through the read static addresses command instead of providing
it through the Read Key Hierarchy Root command.
This is following the recommendations in the Zephyr HCI extension
document in doc/reference/bluetooth/hci.txt

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-20 15:45:34 +01:00
Joakim Andersson 896619ad40 Bluetooth: controller: Fix controller address check
Fix controllers address check in cases of controller-based privacy.
When controller has been instructed by the host to use privacy
the controller should look up the peer identity address and generate
an address based on the local IRK. In the case where no match
is found or the local IRK is all zeroes the controller shall use
the fallback address. If the fallback address is not valid the
controller shall return invalid params.

This commit fixes these issues:
 - Starting a private advertiser without valid random address set
   but a valid local IRK exists. In this case the advertiser should
   be able to advertise using the RPA regardless of a valid random
   or public address.
 - Starting a private advertiser with a fallback to the public
   address type or an adveriser using public address  does not
   check if a valid public address exists. The host cannot
   advertise with an all-zero public address.

Signed-off-by: Joakim Andersson <joerchan@gmail.com>
2019-12-20 15:26:41 +01:00
Johan Hedberg 847f4e6ae6 Bluetooth: L2CAP: Fix checking for STATUS_OUT
The test_and_set_bit() should be checking if the flag was *not*
already set, since that's the scenario where we want to call the
status callback.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-12-19 11:28:24 +02:00
Johan Hedberg 525889c6b5 Bluetooth: L2CAP: Remove bogus NULL checks
The ch pointer is the result of a CONTAINER_OF() operation, so
checking it for NULL is pointless. Additionally, there's no place that
calls this function with chan set to NULL.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-12-19 11:28:24 +02:00
Johan Hedberg 0e91493ab4 Bluetooth: L2CAP: Make channel ops const
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>
2019-12-19 11:28:24 +02:00
Vinayak Kariappa Chettimada b0826a7f65 Bluetooth: controller: split: Reduce time to setup tIFS switch
Refactor to reduce the setup next tIFS switch within tIFS
period of the Radio ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-18 22:02:02 +01:00
Vinayak Kariappa Chettimada 7ba5e012f7 Bluetooth: controller: nordic: Tune tIFS switching
Remove the 4us advanced radio reception, the implementation
passes all timing conformance tests without this.
This change should reduce some radio power consumption by
avoiding redundant reception duration.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-18 22:02:02 +01:00
Krzysztof Chruscinski 00156ad80a drivers: clock_control: nrf: Switch to single clock device
Low frequency and high frequency clocks had separate devices
while they are actually handled by single peripheral with single
interrupt. The split was done probably because opaque subsys
argument in the API was used for other purposes and there was
no way to pass the information which clock should be controlled.
Implementation changes some time ago and subsys parameter was
no longer used. It now can be used to indicate which clock should
be controlled.

Change become necessary when nrf5340 is taken into account where
there are more clocks and current approach would lead to create
multiple devices - mess.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-12-17 14:38:19 +01:00
Vinayak Kariappa Chettimada 9128200e6c Bluetooth: controller: legacy: Fix compiler warnings
Fix compiler warnings when central only support is used.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-17 13:14:37 +01:00
Vinayak Kariappa Chettimada e23c7fbba6 Bluetooth: controller: legacy: Fix length and ping rsp
Fix LENGTH_RSP and PING_RSP to be send after Encryption
Setup under the cases where LENGTH_REQ or PING_REQ cross-
over with ENC_REQ in the same connection event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-17 13:14:37 +01:00
Vinayak Kariappa Chettimada 1ede7db159 Bluetooth: controller: legacy: Fix Tx Ctrl PDU leak
Overlapping Feature Exchange requested by host with
Encryption Setup requested by the application caused the
controller to corrupt its Tx queue leading to Tx Ctrl PDU
buffers from leaking from the system.

Relates to #21299.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-17 13:14:37 +01:00
Andrei Stoica 930d178c69 Bluetooth: controller: enable dynamic TXP over LEGACY arch (#17731)
This commit targets solving issue #17731 over the Nordic LL LEGACY
arch of the BLE stack in Zephyr. This functionality is exposed
to the user as HCI Zephyr Command extensions

- BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL
- BT_HCI_OP_VS_READ_TX_POWER_LEVEL

which enable Tx power read/write operations within BLE radio events
on a per role/connection basis.

The functionality is enabled upon the Kconfig advanced configuration
triggered by

- BT_CTLR_TX_PWR_DYNAMIC_CONTROL

depending on the enablement of Zephyr HCI vendor-specific command
extensions.

Signed-off-by: Andrei Stoica <stoica.razvan.andrei@gmail.com>
2019-12-17 12:29:57 +01:00
Andrei Stoica abd1d047dd Bluetooth: controller: enable dynamic TXP over LL_SPLIT arch (#17731)
This commit targets solving issue #17731 over the LL_SW_SPLIT
arch of the BLE stack in Zephyr. This functionality is exposed
to the user as HCI Zephyr Command extensions

- BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL
- BT_HCI_OP_VS_READ_TX_POWER_LEVEL

which enable Tx power read/write operations within BLE radio events
on a per role/connection basis.

The functionality is enabled upon the Kconfig advanced configuration
triggered by

- BT_CTLR_TX_PWR_DYNAMIC_CONTROL

depending on the enablement of Zephyr HCI vendor-specific command
extensions.

Necessary low-level radio HAL functionality and power definitions
are also supplied to address the high-level functionality of
controlling the Tx power.

Signed-off-by: Andrei Stoica <stoica.razvan.andrei@gmail.com>
2019-12-17 12:29:57 +01:00
Vinayak Kariappa Chettimada f95a7faa58 Bluetooth: controller: split: Fix compiler warnings
Fix compiler warnings when PHY update feature is not selected.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-16 16:16:08 +01:00
Vinayak Kariappa Chettimada 9bd8518baf Bluetooth: controller: split: Fix length and ping rsp
Fix LENGTH_RSP and PING_RSP to be send after Encryption
Setup under the cases where LENGTH_REQ or PING_REQ cross-
over with ENC_REQ in the same connection event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-16 16:16:08 +01:00
Vinayak Kariappa Chettimada f7c890e08c Bluetooth: controller: split: Fix Tx Ctrl PDU leak
Overlapping Feature Exchange requested by host with
Encryption Setup requested by the application caused the
controller to corrupt its Tx queue leading to Tx Ctrl PDU
buffers from leaking from the system.

Fixes #21299.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-16 16:16:08 +01:00
Lingao Meng 6e260af889 Bluetooth: Mesh: Fixes Friend Add Another Update
Fixes: #20746

According MESH/NODE/FRND/FN/BV-20-C should add another
Friend Update.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2019-12-14 16:59:59 +02:00
Asger Munk Nielsen 612984e09c Bluetooth: controller: SW deferred privacy IRK size define
Replaced symbolic constants with a define for the size of IRKs.

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2019-12-13 15:35:25 +01:00
Asger Munk Nielsen 1d412c4acd Bluetooth: controller: SW deferred privacy
Enable deferred resolve of RPA

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2019-12-13 15:35:25 +01:00
Joakim Andersson e978d8620f Bluetooth: controller: Fix rx buffer leak for LL Version priority event
Fix leak of the node_rx buffer when processing the LL version ind as a
priority event. This leak meant being able to establish new connections
was no longer possible, because there weren't enough events to process
the all the events during connection establishment. And instead the LL
ignored the connection request sent by the peer.

Removed the inline extern declaration of a function which had a proper
header included.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-13 15:15:53 +01:00
Luiz Augusto von Dentz 9a111df676 Bluetooth: L2CAP: Add define for signalling timeout
This adds a define for the so called RTX timeout.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Luiz Augusto von Dentz 1a7f85cb53 Bluetooth: L2CAP: Document cases where -EAGAIN is returned
This documents the special cases where -EAGAIN is returned which leads
the buffer to be queued.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00