Commit graph

2736 commits

Author SHA1 Message Date
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
Luiz Augusto von Dentz b8911a8d35 Bluetooth: L2CAP: Fix data leaks when segment cannot be sent
Now that bt_l2cap_send_cb can fail the buffer state needs to be save
and restored otherwise the data stored on it would be lost.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Luiz Augusto von Dentz bdc1eff35b Bluetooth: L2CAP: Introduce BT_L2CAP_STATUS_SHUTDOWN flag
This introduces BT_L2CAP_STATUS_SHUTDOWN which is used to indicate when
a channel has been shutdown.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Luiz Augusto von Dentz cf84216b1a Bluetooth: L2CAP: Offload processing of tx_queue to a work
This offloads the processing of tx_queue to a work so the callbacks
calling resume don't start sending packets directly which can cause
stack overflow.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Luiz Augusto von Dentz 99066db21d Bluetooth: L2CAP: Ignore packets received while disconnecting
Drop packets received while disconnecting since they would most likely
be flushed once peer respond there is no gain in keeping them on a
queue.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Luiz Augusto von Dentz 5d26693d02 Bluetooth: L2CAP: Add dedicated pool for disconnect request
This prevents disconnect request packets to not being sent due to lack
of buffers normally caused by flooding or congestion.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Luiz Augusto von Dentz aa9a1f627c Bluetooth: Use NET_BUF_RX_COUNT if NET_L2_BT is enabled
If NET_L2_BT is enabled we need enough acl_in_pool needs to be big
enough to contain a full IP packet since that is no longer processed by
RX thread buffer would be queued to syswq to reassemble the SDU.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Luiz Augusto von Dentz dd4b340205 Bluetooth: L2CAP: Use NET_BUF_TX_COUNT as fragment count
When NET_L2_BT the memory pressure for fragments can be quite high
since that would be transfering IP packets which are considerable big
so this makes our frag_pool to be of the same size as NET_BUF_TX_COUNT.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Luiz Augusto von Dentz 4b8cd200ed Bluetooth: conn: Add debug variant to buffer allocation
This enable chaning the function and line number making it easier to
debug where a buffer allocation is blocking.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Luiz Augusto von Dentz bdb8b0af70 Bluetooth: L2CAP: Queue packets when a segment could not be allocated
When a segment could not be allocated it should be possible to resume
sending it later once previous segments complete, the only exception is
when there is no previous activity and we are unable to alocate even the
very first segment which should indicate to the caller that it would
block since that only happens on syswq the caller might need to defer to
another thread or resubmit the work.

Fixes #20640

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Joakim Andersson 41b6b21eeb Bluetooth: shell: Add command to print all connections available
Add command to print all existing connections. Useful for verifying that
connections are actually released when debugging.
More information can be retrieved with `bt info <addr>` using the
address printed by this command for each connection.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-13 14:39:54 +02:00
Joakim Andersson f6a6974186 Bluetooth: shell: Add command to print all bonds available
Add command to print all existing bonds. Useful for verifying that bonds
are actually cleared when debugging.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-13 14:39:54 +02:00
Joakim Andersson 8d88beca34 Bluetooth: shell: Fix whitelist clear shell command argument count
Fix whitelist clear (wl-clear) shell command argument count. This
command takes no arguments.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-13 14:39:54 +02:00
Vinayak Kariappa Chettimada bf623906f3 Bluetooth: controller: split: Fix missing version ind state reset
Fix implementation for the missing reset of version
information procedure request state value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-13 13:21:27 +01:00
Wolfgang Puffitsch b0207eb778 Bluetooth: host: Refactor checks in update_ccc for efficiency
Check peer address only if active.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-12-12 15:26:38 +02:00
Joakim Andersson f7f63c6306 Bluetooth: host: Check for device ready for whitelist API
The whitelist API uses the controller directly through HCI commands.
Bluetooth device must have been initialized before sending HCI commands.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-12 12:19:40 +02:00
Vinayak Kariappa Chettimada 7417e6e09e Bluetooth: controller: split: conn handle invalidation on release
Move invalidation of connection handle to connection context
release done on release of terminate rx node.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-12 08:48:24 +01:00
Wolfgang Puffitsch d3e3f8d2b4 Bluetooth: controller: split: Move invalidation of connection handle
Move invalidation of connection handle when flushing TX buffers into
LLL context. Otherwise, LLL may or may not see invalidated handle
depending on mayfly scheduling.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-12-12 08:48:24 +01:00
Aurelien Jarno a2ddf99f0c Bluetooth: Mesh: fix next_period computation
If the duration to publish is roughly the same as the period, we might
end up with elapsed == period, which returns 0 and cancel the periodic
publication. Instead 1 should be returned, just like when the elapsed
time is greater than the period.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-12-12 09:47:42 +02:00
Trond Einar Snekvik fc56b37116 Bluetooth: Mesh: Refactor CCM
Unifies the Mesh CCM implementation parts for encryption and decryption
into a crypt and an auth step, reducing stack usage and code size.

This change also brings several performance improvements, most notably
reducing copying of the nonce and unrolling the 16 byte XOR operations.

Performance for the Mesh worst case of a 382 byte payload with 16 bytes
of additional data (full transport encrypt with virtual address) goes
from an average of 889us to 780us on nRF52840 with default optimization
flags.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-12-11 23:53:02 +02:00
Ulf Magnusson 984bfae831 global: Remove leading/trailing blank lines in files
Remove leading/trailing blank lines in .c, .h, .py, .rst, .yml, and
.yaml files.

Will avoid failures with the new CI test in
https://github.com/zephyrproject-rtos/ci-tools/pull/112, though it only
checks changed files.

Move the 'target-notes' target in boards/xtensa/odroid_go/doc/index.rst
to get rid of the trailing blank line there. It was probably misplaced.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-11 19:17:27 +01:00
Joakim Andersson a1d73acfcd Bluetooth: HCI: Handle invalid ACL flags.
Handle invalid ACL flags in HCI transport.
Only Point to Point is supported over HCI in both directions.
Fix flushable start HCI ACL packets not allowed on LE-U connections
from Host to controller.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-11 12:34:34 +02:00
ZhongYao Luo d1aa80c049 bluetooth: l2cap_br: l2cap channel used wrong cid when removing
In bt_l2cap_br_chan, rx.cid is the local cid and tx.cid is the
remote cid. According to Core-5.0 Vol3.Part A 4.6-4.7,
l2cap_br_remove_tx_cid should be searched using tx.cid

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2019-12-11 11:34:43 +02:00
Vinayak Kariappa Chettimada 5f10154724 Bluetooth: controller: split: Fix HCI LE Add Device to Whitelist
According to BT Spec v5.1 Vol 2 Part E Section 7.8.16, if the
device is already in the White List, the controller should not
add the device to the White List and should return success.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-10 22:29:15 +02:00
Vinayak Kariappa Chettimada 09f7364cf8 Bluetooth: controller: legacy: Fix HCI LE Add Device to Whitelist
According to BT Spec v5.1 Vol 2 Part E Section 7.8.16, if the
device is already in the White List, the controller should not
add the device to the White List and should return success.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-10 22:29:15 +02:00
Joakim Andersson e4136178ed Bluetooth: Host: Fix duplicate whitelist entries issue
If the whitelist already exists in the controller then the controller
should not add the device tot the whitelist and should return success.
In that case the counting of entries in the whitelist in the host will
be wrong.

Remove all whitelist counting in the host, and instead rely on the error
reported by the controller for this.
The controller should return error if the whitelist is full.
The controller should return error if use of whitelist was requested but
the whitelist was empty.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-10 17:54:10 +02:00
Kumar Gala 24ae1b1aa7 include: Fix use of <misc/FOO.h> -> <sys/FOO.h>
Fix #include <misc/FOO.h> as misc/FOO.h has been deprecated and
should be #include <sys/FOO.h>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-10 08:39:37 -05:00
Maximus Liu 2f691d2597 Bluetooth: Mesh: Fixes wrong subnet used for Friend Clear
When Friend node tries to send Friend Clear message to other
Friend nodes, it should use the subnet information based on
the net_idx from friendship.

Fixes #21165

Signed-off-by: Maximus Liu <maximus.liu@gmail.com>
2019-12-09 16:35:29 -05:00
Joakim Andersson b30b480c7c Bluetooth: UUID: Expose bt_uuid_to_str to application
Expose the bt_uuid_to_str function as an API to the application.
This aligns this function with the bt_addr_to_str function call. This
allows the application to use this function without having to enable
the BT_DEBUG option.

Move the in-place bt_uuid_str to internal logging, this is mainly done
due to the limitation in the log_strdup that shouldn't be exposed to the
application.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-09 17:15:05 +02:00
Ulf Magnusson 87e917a925 kconfig: Remove redundant 'default n' and 'prompt' properties
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Also replace some

    config
    	prompt "foo"
    	bool/int

with the more common shorthand

    config
    	bool/int "foo"

See the 'Style recommendations and shorthands' section in
https://docs.zephyrproject.org/latest/guides/kconfig/index.html.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-09 16:14:50 +01:00
Joakim Andersson cbf666ecc3 Bluetooth: Host: Check that bluetooth device is ready
Check that the bluetooth device has in fact been initialized before
continuing with public API calls. This could lead to crashes when using
state that has not yet been initialized.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-09 16:11:19 +01:00
François Delawarde db106a2b5b bluetooth: host: Add flag to prevent client resubscription on reconnect
When set, the BT_GATT_SUBSCRIBE_FLAG_NO_RESUB flag indicates that the
subscription should not be renewed when reconnecting with the server.

This is useful if the application layer knows that the GATT server
persists subscription information.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-12-09 17:07:39 +02:00
Martin Rieva bf361aa66c Bluetooth: Host: Add CONFIG_BT_BONDING_REQUIRED flag
Added configuration for accepting pairing requests only if both devices
has bonding flag set in order to reject other devices at an early stage,
thus leaving more chance for devices expected to bond.

With the CONFIG_BT_BONDING_REQUIRED flag the device only accept pairing
requests if it has CONFIG_BT_BONMDABLE set and the device requesting
pairing has Bonding_Flags field set to Bonding (0x01) in its AuthReq.
Note: When using bt_set_bondable(false) pairing requests will be
rejected when CONFIG_BT_BONDING_REQUIRED is set.

Signed-off-by: Martin Rieva <mrrv@demant.com>
2019-12-09 17:05:32 +02:00
Kiran Paramaswaran f30bed350c Bluetooth: Host: Enable/Disable Automatic Sending of Conn Parameter update
Added a new Kconfig flag to enable/disable this feature.

Signed-off-by: Kiran Paramaswaran <kipm@oticon.com>
2019-12-09 17:04:50 +02:00
Joakim Andersson b5f70ef1c0 Bluetooth: GATT: Fix discover callback invalid pointer
Fix issues that surfaced when trying out GCC 9.2, official release name
gcc-arm-none-eabi-9-2019-q4-major, both related to invalid pointers in
GATT when declaring UUIDs in if-scope.

1. Fix the discovery callback giving an invalid pointer in the discovery
callback in two instances.
2. Fix gatt_find_type sending invalid data during discovery procedure.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-09 16:58:01 +02:00
Kiran Paramaswaran d86d37a075 Bluetooth: Host: Adding valid param check in send_conn_le_param_update()
Send connection parameter update request only if it contains the valid
range of values for connection intervals, latency and timeout.

Signed-off-by: Kiran Paramaswaran <kipm@oticon.com>
2019-12-09 16:57:38 +02:00
Jacob Siverskog 7096fa512f Bluetooth: GATT: Remove all subscriptions for connection when unpairing
Make sure all subscriptions are removed when a connection is unpaired.

Fixes #21131

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2019-12-04 19:14:28 +01:00
Joakim Andersson afe088247d Bluetooth: ATT: Fix ATT MTU support for larger MTUs
Fix ATT MTU size of length variables resulting in wrong length values
reported to the user. Communicating with an Android device using an MTU
of 517 resulted in write commands reported as length 2 instead.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-04 19:08:10 +01:00
Luiz Augusto von Dentz 5beb5b5992 Bluetooth: ATT: Fix not handling errors properly
Since bt_conn_send_cb can fail to send buffer causing it to unref this
may cause buffer leaks as the caller is not aware of the error assuming
the buffer could be sent.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-03 19:44:51 +01:00
Vinayak Kariappa Chettimada 92e017fd70 Bluetooth: controller: split: Support Zero Latency IRQs
Add support for Zero Latency IRQs, which avoids any Zephyr
OS or application influenced ISR latencies on the
controller's ISRs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-03 10:43:09 +01:00
Vinayak Kariappa Chettimada dab182896e Bluetooth: controller: split: Revert broken ZLI support
This reverts commit 3096c0e741.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-03 10:43:09 +01:00
Vinayak Kariappa Chettimada c53ca07246 Bluetooth: controller: legacy: Revert broken ZLI support
This reverts commit a1945db08a.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-12-03 10:43:09 +01:00
Luiz Augusto von Dentz 42c5b0a7fa Bluetooth: L2CAP: Fix unrefing buffers that are queued
Processing of data received on dynamic channels is still done via syswq
so the buffer shall not be unrefed when they are queued.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-11-29 15:19:08 +02:00