Commit graph

2736 commits

Author SHA1 Message Date
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
Luiz Augusto von Dentz 3f43413887 Bluetooth: L2CAP: Fix not unrefing tx_buf
If the channel has a tx_buf it must be unrefed when destroying the
channel.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-11-29 15:19:08 +02:00
Johan Hedberg 1e831befea Bluetooth: host: Fix ordering of TX sent callbacks
Now that the TX callbacks happen from the system workqueue but fixed
channels get processed from the RX thread there's a risk that the
ordering of these gets messed up. This is particularly bad for ATT
when it's trying to enforce flow control.

To fix the issue store the completed TX packet information in a
per-connection list and process this list before processing any new
packets for the same connection. We still also schedule a workqueue
callback, which will simply do nothing for this list if bt_recv()
already took care of it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-28 19:55:59 +02:00
Johan Hedberg 39291fbbbe Bluetooth: Remove usage of BT_BUF_USER_DATA_MIN
This define is not of use anymore since there's a global net_buf user
data Kconfig variable and its definition already guarantees a
sufficient minimum for Bluetooth.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-28 13:35:11 +02:00
Johan Hedberg be71e68fcb Bluetooth: L2CAP: Use fixed size for net_buf user data
The "sent" tracking doesn't have to be a signed integer. Use a fixed
size so that the consumed size doesn't change between different
architectures. Use a u16_t since bigger sizes are needed and because
this is mapped to an int function return higher up in the stack.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-28 13:35:11 +02:00
Kamil Piszczek 362f2299cd drivers: bluetooth: hci: rpmsg: fix handling of hci events
Fixed handling of HCI events in the HCI driver over RPMsg. Now,
the driver makes use of discardable buffer pool when allocating
memory for certain HCI event types (e.g. Advertising Report Event).
Applications that are flooded with Advertising Reports will run
much better after this change (e.g. Mesh applications).

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-11-28 10:55:32 +02:00
Vinayak Kariappa Chettimada 44bbdd0a94 Bluetooth: controller: Fix llcp_rx check assert
If LL Connection Parameter Request or LL Connection Update
or LL PHY Update procedure is started by the local device
while a LL Length Update Request PDU has been sent by peer
then a Rx node has been stored in the llcp_rx place holder
for generation of Length Update procedure complete.

The failing assert check is incorrect in the above scenario
hence remove. Instead a missing append of the allocated Rx
node to the llcp_rx list has been added to the controller
implementation.

This issue relates to commit d12c53f89f ("Bluetooth:
controller: split: Fix missing data len update event").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-27 18:43:02 +01:00
Johan Hedberg 0a925bdf9c Bluetooth: L2CAP: Process fixed channels in the RX thread
Now that the TX path and TX context (bt_conn_tx) has been redesigned
to free the contexts always in the system workqueue, it means the
system workqueue is the only context where their allocation may also
fail. This is particularly problematic with us having all L2CAP
channels (fixed & CoC alike) deferred to the system workqueue. It is
especially bad for fixed channels where being able to send responses
for SM, L2CAP signaling and ATT is critical to avoid timeouts for the
connection.

This patch moves the processing of all fixed L2CAP channels back to
the RX thread, thereby making it possible (and safe) to block while
waiting for a TX context to become available.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-27 17:44:59 +02:00
Johan Hedberg a065e5782a Bluetooth: host: Move system workqueue special case to the right place
Now that we've removed the TX allocation dependency from the TX thread
we no longer have the need to do special-casing for the system
workqueue when allocating buffers. Instead, we do have to special-case
the system workqueue when allocating TX contexts since the system
workqueue is the only place where they get freed up.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-27 17:44:59 +02:00
Johan Hedberg d8689cdc72 Bluetooth: host: Fix deadlocks with pending TX packet handling
This is a moderate redesign of the pending TX packet handling that
aims to eliminate potential deadlocks between the TX thread and the
system workqueue thread. The main changes are:

 - TX context (bt_conn_tx) is allocated during buffer allocation, i.e.
   not in the TX thread.

 - We don't allocate a TX context unless there's an associated
   callback. When there's no callback simple integer counters are used
   for tracking.

 - The TX thread is no longer responsible for TX callbacks or
   scheduling of TX callbacks. Instead, the callbacks get directly
   scheduled (k_work_submit) from the RX priority thread.

 - CONFIG_BT_CONN_TX_MAX defaults to CONFIG_BT_L2CAP_TX_BUF_COUNT,
   and in most cases wont need changing. The value now only indicates
   how many pending packets with a callback are possible.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-27 17:44:59 +02:00
Johan Hedberg 28f89478f6 Bluetooth: host: Shrink size of struct bt_conn_tx
The `node` and `work` members are never used simultaneously.
Additionally k_work already has built-in support for being in a linked
list, however a union makes this change a bit cleaner.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-27 17:44:59 +02:00
Lingao Meng a071957746 Bluetooth: Mesh: Fixes wrong return value
Fixes missing return value on `va_del`
Fixes wrong return value on `va_add`

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2019-11-27 11:22:20 +02:00
Maximus Liu 1050ef7932 Bluetooth: Mesh: Fixes seg_tx_reset adv buf unref
In seg_tx_reset() in transport.c, set the busy flag to 0U
before doing adv buf unref, which will avoid sending
unnecessary adv packets in case the adv buf is already put
in the mesh adv_queue.

Fixes #20970

Signed-off-by: Maximus Liu <maximus.liu@gmail.com>
2019-11-27 11:21:46 +02:00
Lingao Meng c0cdd46adf Bluetooth: Mesh: Fixes Delete On Node
Fixes a issure where nodes could not be deleted.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2019-11-27 10:16:53 +02:00
Johan Hedberg 5a8b143028 Bluetooth: host: Fix command buffer corruption
A recent patch increased struct cmd_data from 8 to 12 bytes, which is
more than the default user data for Bluetooth. We generally don't want
the core stack to require more than 8, so instead of increasing the
requirement, move the data out from the buffer into its own array with
the help of the net_buf_id() API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-26 16:08:00 +02:00
Alex Li 198013ad9f Bluetooth: Fix BT log level config won't take effect
BT log module should be registered as user configured level,
instead of using default log level

Signed-off-by: Alex Li <lizhiqin46783937@live.com>
2019-11-26 09:11:06 +02:00
Joakim Andersson 0bf9931c2c Bluetooth: Host: Fix create connection fails to stop scanner
Fix race condition in bt_conn_create_le for the state of the scanner in
the Host. This leads to the host issuing a create connection command
without stopping the scanner first. This leads to command disallowed and
failing to establish connection. As well as inconsistent state in the
host which does not allow to stop the running scanner.

The race condition exists because the processing of le_adv_report
handler is done before the thread that called bt_conn_create_le was
woken up to continue after the command_complete event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-11-25 17:21:17 +01:00
Vinayak Kariappa Chettimada 430df927b0 Bluetooth: controller: split: Fix aborting of connection req PDU
Fix the initiator so that connection request PDU is not abort
mid-air by preemption by the overalapping first connection
event.

If the connection establishment is in progress, then the
first connection event trying to abort the initiator will
wait the connection request to be transmited completely.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-22 08:40:41 +01:00
Vinayak Kariappa Chettimada d5314b8387 Bluetooth: controller: split: Add missing BT_DEBUG_ENABLED define
Add missing BT_DEBUG_ENABLED definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-21 17:08:37 +01:00
Vinayak Kariappa Chettimada 2993b1ec0a Bluetooth: controller: legacy: Add missing BT_DEBUG_ENABLED define
Add missing BT_DEBUG_ENABLED definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-21 17:08:37 +01:00
Vinayak Kariappa Chettimada 83d6e5d3d4 Bluetooth: controller: Add missing BT_DEBUG_ENABLED define
Add missing BT_DEBUG_ENABLED definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-21 17:08:37 +01:00
Vinayak Kariappa Chettimada e27abee331 Bluetooth: controller: split: Schedule first conn event ASAP
Enable ticker job mayfly as soon as possible when
establishing connection. This is required so as to not miss
the first connection event in slow CPU like in nRF51 series.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-21 17:08:03 +01:00
Joakim Andersson 113b80ff0d Bluetooth: Host: Fix silent LE conn param update command failure
Fix command status for LE Command Param Update HCI command silently
dropped by the host without notifying the application that this command
has failed. This happens because the host does not wait for the command
status event to check the status code returned.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-11-21 17:21:01 +02:00
Joakim Andersson a961679171 Bluetooth: Host: Fix deadlock calling API functions from SMP callbacks
Fix deadlock in Bluetooth Host. Deadlock could happen from the SMP
callbacks when calling Bluetooth API functions. This is because the
callbacks was given directly from the HCI TX thread. If the calling
API function resulted in trying to send a new HCI command it would post
this HCI command to the HCI TX thread and then wait for command complete
event. This would result in the HCI TX thread blocked waiting for the
itself to process the command.

Example:
Calling bt_conn_le_conn_param_update from pairing_complete callback.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-11-21 14:51:50 +02:00
Alex Porosanu fec5bbb1c1 Bluetooth: controller: openisa: sync with Nordic SW LL
There are some changes that were introduced to the Nordic SW LL,
and as such, in order to maintain compatibility, propragate them
to the OpenISA SW LL as well.

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2019-11-21 10:35:16 +01:00
Vinayak Kariappa Chettimada 91fe1d9aa1 Bluetooth: controller: split: Dont use continuous directed adv in nRF51
In nRF51 which uses CONFIG_BT_CTLR_LOW_LAT, the advertising
PDU tend to get aborted in directed advertising at event slot
durations.

Dont not use continuous directed advertising event in nRF51
where CONFIG_BT_CTLR_LOW_LAT scheduling design alternative
is used. Instead close the event after each triplet of PDU
has been tx-ed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-21 08:43:41 +01:00
Vinayak Kariappa Chettimada 528944708c Bluetooth: controller: split: Fix non-connectable event slot time
Fix the calculation of non connectable advertising event
slot reservation duration.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-21 08:43:05 +01:00
Vinayak Kariappa Chettimada b33ccbf275 Bluetooth: controller: split: Fix directed adv event interval
Fix the directed advertising event interval calculation.
When CONFIG_BT_CTLR_LOW_LAT is used then prepare duration
has to be included in the event slot reservation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-21 08:42:27 +01:00
George Stefan d2212581be Bluetooth: controller: split: Fix check for control procedures request
Remove wrong #ifdef that guarded the control procedures request check

Signed-off-by: George Stefan <george.stefan@nxp.com>
2019-11-20 19:37:42 +01:00
Johan Hedberg d67416321e Bluetooth: hci_raw: Add support for specifying buffer headroom
The HCI transport implemented by an application using the HCI raw
interface may have its own buffer headroom requirements. Currently the
available headroom gets completely determined by the selected HCI
driver. E.g. most of the time this is the native controller driver
which doesn't reserve any headroom at all.

To cover for the needs of HCI raw users, add a new Kconfig variable
for the apps to set to whatever they need. Correspondingly, use the
maximum of the HCI driver and HCI raw headroom requirements for the
buffer pool definitions and the headroom initializations.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-20 19:29:06 +01:00
Vinayak Kariappa Chettimada 3805290055 Bluetooth: controller: legacy: Fix the slow Enc Setup alternative
Fix the implementation of slow encryption setup design
alternative to send ENC_RSP PDU before sending REJECT_IND
or REJECT_EXT_IND PDU.

Fixes #19917.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-19 13:53:50 -05:00
Joakim Andersson 667886d63d Bluetooth: Kconfig: Fix host phy and data length update dependency
Fix dependency on the Host to include the PHY update procedure and the
data length update procedure. In a host-only build this feature should
be possible to select without relying on the supported features of the
controller. The host will check support using HCI command to read
attached controller features and commands supported.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-11-19 16:57:18 +01:00
Vinayak Kariappa Chettimada 62f939adb8 Bluetooth: controller: split: Fix typo EVENT_RX_TX_TURNARROUND
Fix typo in EVENT_RX_TX_TURNARROUND.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-19 15:37:56 +01:00
Joakim Andersson ea7a1859af Bluetooth: GATT: Fix taking address of packed member of struct sc_data.
Fix GCC9 warning "warning: taking address of packed member of
'struct sc_data' may result in an unaligned pointer value"
Issue is that the on-air structure of sc_data was re-used for the gatt
service changed data.

Added build assert because data is stored in settings, so the structure
should be the same size to be compatible.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-11-18 13:54:15 +01:00
Stephane D'Alu 6ba1fcec3f Bluetooth: shell: Fix missing return statement for name command
Return once bt name has been displayed

Signed-off-by: Stephane D'Alu <sdalu@sdalu.com>
2019-11-17 21:03:24 +02:00
Vinayak Kariappa Chettimada 4a42e636e8 Bluetooth: controller: Fix Code PHY update support dependency
Fix the regression introduced as part of
commit 57d9411837 ("bluetooth: kconfig: disable some
options for openisa/RV32M1").

Also, prior to PR that introduced this regression, the Coded
PHY support selection was incorrectly depending on PHY update
support Kconfig BT_PHY_UPDATE. This was already fixed as part
the previous PR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-15 16:01:31 +01:00
Sebastian Bøe 59abaf461b cmake: make the BT_HCI_TX_STACK_SIZE's prompt conditional
The BT_HCI_TX_STACK_SIZE is carefully calculated from other
options. When those options change, e.g. from a menuconfig update, it
is important that the stack size is re-calculated, but it is not when
there is a prompt.

Therefore, make the prompt conditional such that the previously set
value is only used when it has been explicitly configured to be so.

Now users can still change the value through menuconfig and prj.conf,
by also enabling <option>_WITH_PROMPT, but when the value is
calculated by the defaults, it will continue to be calculated by
defaults instead of inheriting the intial value.

This is AFAIK a novel approach, but testing has shown that it gives
the users the behaviour they want, at the cost of some boilerplate of
course. This pattern can be applied to other options if it proves to
work as intended.

Alternatively one could remove the prompt, but then it would no longer
be possible to override the value through menuconfig.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-11-15 13:28:56 +01:00
Lingao Meng ff9f208492 Bluetooth: Mesh: Fixes Config client send publish message
When Config client model send publish message, app_idx will
be need, however, currently code clear this value use `&`,
this will be generate error when app_idx not zero.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2019-11-14 14:26:21 +02:00
Emil Obalski 446d98b09e bluetooth: Add bluetooth support for nRF52833
This commit adds support for bluetooth in nRF52833 SoC.
Bluetooth radio related files created and added to Zephyr.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2019-11-13 10:33:38 -06:00
Johan Hedberg 1df9a2e1d3 Bluetooth: hci_raw: Fix buffer init after allocation
The code was not properly taking into account CONFIG_BT_HCI_RESERVE,
which would cause buffer underruns for any HCI driver where this value
defaults to non-zero. Also, all the allocation functions use the same
pool, so we can map them simply to bt_buf_get_rx() instead of
repeating the same code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-12 16:59:43 +02:00
Morten Priess 087706498e bluetooth: controller: Perform synchronized LLL reset via mayfly
Use semaphore to synchronize lll_reset completion with HCI thread for
returning (command complete) only when all is done.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-11-12 11:34:28 +01:00
Erik Brockhoff ed61065f2c Bluetooth: controller: ull_filter: RPA ADV refresh fix
local variable (idx) was used in conflicting contexts

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2019-11-12 11:30:05 +01:00
Vinayak Kariappa Chettimada d1d603afc3 Bluetooth: controller: split: Fix conn update to be cacheable
Fix connection update procedure to be cacheable if any other
local or remote control procedure is in progress.

Relates to commit 9c14567ce2 ("Bluetooth: controller: Fix
conn update to be cacheable").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-11 14:17:35 +01:00
Carles Cufi 4657d8515a Bluetooth: controller: openisa: Fix radio ISR signature
Non-direct ISRs are supposed to take a void pointer as an argument,
unliike direct ones, which take no arguments. Since the radio ISR is not
declared as direct, the void pointer argument was missing, likely due to
a copy-paste mistake from the nordic LLL, which indeed uses a direct ISR
for the radio ISR.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-11-11 13:53:03 +01:00
Johann Fischer fd82d2b47c Bluetooth: l2cap: fix null pointer dereference
bt_conn_create_pdu_timeout() may return NULL if no buffer
is available, l2cap_chan_create_seg() does not check the
subsequent return value.
Fix possible null pointer dereference in l2cap_chan_create_seg()
and l2cap_chan_le_send().

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-11-10 19:18:53 +02:00
Anas Nashif 53f30bc3ac Bluetooth: controller: openisa: do not use instances for openisa IRQs
An issue with DT generation where instance defines are not determinstic
generating values that collide with existing IRQs.

Fixes #20558

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-10 11:17:35 -05:00
François Delawarde 4ca408ed6a bluetooth: host: refactor ccc settings handling
Move functions in order to avoid function prototype and use IS_ENABLED
instead of #if defined where possible.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-11-08 21:29:23 +02:00
François Delawarde a51986616e bluetooth: host: add ability to load CCC settings on demand
This commits adds a BT_SETTINGS_CCC_LAZY_LOADING option to allow for
CCC settings to be loaded on demand when a peer device connects in
order to reduce memory usage.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-11-08 21:29:23 +02:00
François Delawarde 42eb629188 bluetooth: host: refactor sc settings handling
Move functions in order to avoid function prototypes.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-11-08 21:29:23 +02:00
François Delawarde fd10c4c962 bluetooth: host: do not remove SC entry when peer subscribed and paired
Maintain Service Changed entry as long as the peer device is subscribed
to SC indications and bonded. This allows to save indication data for
disconnected peers peers when CCC settings are not available (loaded
on-demand).

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-11-08 21:29:23 +02:00
Ioannis Glaropoulos 9d52f798c5 bluetooth: controller: define SW IRQ structure for nRF53 SoCs
Extend the nRF5-specific SW IRQ framework to support nRF53.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-08 19:26:35 +01:00
Ioannis Glaropoulos fb56d56dc9 bluetooth: controller: setup nRF53 DDPI configuration for Coded PHY
This commit provides the DPPI configuration for the Radio
driver for nRF5340 SoC, supporting LE Coded PHY.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-08 19:26:35 +01:00
Ioannis Glaropoulos 17859e1eee bluetooth: controller: setup DDPI configuration for nRF5340
This commit provides the DPPI configuration for the Radio
driver for nRF5340 SoC.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-08 19:26:35 +01:00
Ioannis Glaropoulos 0186c66ac3 bluetooth: controller: enable support for nRF53 when building radio.c
Add the require #ifdef blocks in radio.c, in order to support
building for nRF53 SoC series (and, in particular, for nRF5340
CPU1 SoC).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-08 19:26:35 +01:00
Ioannis Glaropoulos 1b3039ef1a bluetooth: controller: include nRF5340-specific radio header
Conditionally include nrf5340_radio.h when building the
BLE controller for nRF5340 SoC. Introduce the header for
nrf5340.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-08 19:26:35 +01:00
Ioannis Glaropoulos 04e66dab53 bluetooth: host: add nRF53 in HW variants
This commit adds a string representation of the
nRF53 variant in bluetooth host.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-08 19:26:35 +01:00
Ioannis Glaropoulos 613e716e11 bluetooth: controller: enable support for nRF53 in Kconfig
This commit enables support in bluetooth/controller/Kconfig
for nRF53 series of SoCs.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-08 19:26:35 +01:00
Ioannis Glaropoulos a7a4c89579 bluetooth: controller: conditionally define NRF_RADIO_TXPOWER_POS4DBM
nRF5340 does not support a Radio TX power of 4dBm, so we
introduce a dependency for the respective Kconfig option
for TX power, so the option is never defined for nRF5340.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-08 19:26:35 +01:00
Ioannis Glaropoulos 53e4c215ee include: bluetooth: define hci macro for nRF53
Define the nRF53 HW variant in include/bluetooth/hci_vs.h
and pass the define in hci_vendor.h

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-08 19:26:35 +01:00
Trond Einar Snekvik c704495807 Bluetooth: Move Company ID config out of ctlr
The Company ID concept is not restricted to the controller, and should
be part of the wider Bluetooth scope, so it can be used on a
controller-less device. It's used in multiple host level modules, most
notably the Bluetooth Mesh and Device Information Service.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-11-08 16:16:37 +01:00
Alex Porosanu 57d9411837 bluetooth: kconfig: disable some options for openisa/RV32M1
Some Bluetooth options are currently not supported by the experimental
BLE SW LL implementation done on VEGABoard. As such, hide them from
the user altogether.

The full list of disabled config options is as follows:

- CONFIG_BT_PHY_UPDATE
- CONFIG_BT_DATA_LEN_UPDATE
- CONFIG_BT_HCI_VS
- CONFIG_BT_CTLR_LE_ENC
- CONFIG_BT_CTLR_CONN_PARAM_REQ
- CONFIG_BT_CTLR_EXT_REJ_IND
- CONFIG_BT_CTLR_SLAVE_FEAT_REQ
- CONFIG_BT_CTLR_LE_PING
- CONFIG_BT_CTLR_PRIVACY
- CONFIG_BT_CTLR_EXT_SCAN_FP
- CONFIG_BT_CTLR_CHAN_SEL_2
- CONFIG_BT_CTLR_ADV_EXT
- CONFIG_BT_CTLR_XTAL_ADVANCED
- CONFIG_BT_CTLR_SCHED_ADVANCED
- CONFIG_BT_CTLR_TIFS_HW

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2019-11-08 15:38:57 +01:00
David Leach 5edcb7dc2a bluetooth: controller: openisa/RV32M1: add debug pins support
Add SW defined BLE LL debug support on Vega platform by using
the debug GPIO pins infrastructure.

Signed-off-by: David Leach <david.leach@nxp.com>
2019-11-08 15:38:57 +01:00
George Stefan d87aaa6107 bluetooth: controller: openisa/RV32M1: enable the BLE SW controller
This patch updates the config files required to enable the
BLE SW defined controller to be built on RV32M1 SoCs. Only the split
version is supported.

Signed-off-by: George Stefan <george.stefan@nxp.com>
Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
Signed-off-by: Ionut Ursescu <ionut.ursescu@nxp.com>
2019-11-08 15:38:57 +01:00
George Stefan b063456015 bluetooth: controller: openisa/RV32M1: BLE Link Layer ULL/LLL split
This commit takes the Nordic LLL and adapts it for RV32M1 SoCs, using
the blocks that are specific to this SoC: the GenFSK & LPTMR IP
blocks.

Signed-off-by: George Stefan <george.stefan@nxp.com>
Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
Signed-off-by: Ionut Ursescu <ionut.ursescu@nxp.com>
2019-11-08 15:38:57 +01:00
George Stefan 24d9ad2494 bluetooth: controller: openisa/RV32M1: add HAL for LPTMR & GenFSK
This commit adds the HAL layer needed for the BLE controller
LL on RV32M1 SoCs on OpenISA boards. Specifically, the controller
makes use of the the GenFSK and LPTMR IP blocks.

Signed-off-by: George Stefan <george.stefan@nxp.com>
Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
Signed-off-by: Ionut Ursescu <ionut.ursescu@nxp.com>
2019-11-08 15:38:57 +01:00
David Leach 94106a8ff3 boards: riscv: rv32m1: add support for GPIO debugging
Having a pin toggle when the code reaches a certain point
is really useful for debugging; the infrastructure is already
in place for Nordic boards, so just build upon and enable the
mechanism on the Vega board as well.

Signed-off-by: David Leach <david.leach@nxp.com>
2019-11-08 15:38:57 +01:00
Andrzej Głąbek d84447e943 bluetooth: nordic: Update nrfx HAL calls with pointers to HW instances
Update calls to nrfx HAL functions to reflect API changes introduced in
nrfx 2.0.0. All these functions are now called with the first parameter
pointing to the structure of registers of the relevant peripheral.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-11-08 14:54:12 +01:00
Vinayak Kariappa Chettimada 2f965a1fb0 Bluetooth: controller: split: Fix DLE for remote unsupported Coded PHY
Fix Data Length Procedure to use Feature Exchange values to
send correct parameters based on whether Coded PHY is
supported by remote peer.

Relates to BT TS.5.1.1 tests:
LL/CON/MAS/BV-129-C
LL/CON/MAS/BV-130-C
LL/CON/SLA/BV-132-C
LL/CON/SLA/BV-133-C

Relates to commit fca32e41e6 ("Bluetooth: controller: Fix
DLE for remote unsupported Coded PHY").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-08 14:30:25 +01:00
Vinayak Kariappa Chettimada 48e5d9482a Bluetooth: controller: split: Fix the slow Enc Setup alternative
Fix the implementation of slow encryption setup design
alternative to send ENC_RSP PDU before sending REJECT_IND
or REJECT_EXT_IND PDU.

Fixes #19917.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-08 14:29:36 +01:00
Vinayak Kariappa Chettimada 0a892310d3 Bluetooth: controller: split: Fix feature exchange state reset
Fix feature exchange event generation to be correctly
deferred to wait for Rx node availability for cases when
the procedure has already been performed on air.

Without this fix, remote feature request from host may not
get back a HCI event back.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-08 14:29:21 +01:00
Vinayak Kariappa Chettimada ebb2c0d208 Bluetooth: controller: split: Port missing break latency
Port missing implementation of the slave latency break
when there is data to be sent to peer master. Without this
initial data send from slave is delay by upto the slave
latency number of connection events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-08 14:29:07 +01:00
Vinayak Kariappa Chettimada f344516a0b Bluetooth: controller: split: Fix enc procedure reject handling
This is a port of the commit 4135fb55f1 ("Bluetooth:
controller: Fix rejected enc procedure not terminated") and
commit 4d59ef306b ("Bluetooth: controller: Check if enc
procedure is in progress").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-08 14:28:10 +01:00
Joakim Andersson 64d6d1079c Bluetooth: SMP: Add option to disallow unauthenticated re-pairing
Disallows all unauthenticated pairing attempts made by the
peer where an unauthenticated bond already exists.
This would enable cases where an attacker could copy the peer device
address to connect and start an unauthenticated pairing procedure
to replace the existing bond. Now in order to create a new bond the old
bond has to be explicitly deleted with bt_unpair.

Added option to disable this rule in order to maintain backwards
compatibility in case this behavior is accepted.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-11-08 13:42:56 +02:00
Andy Ross 8892406c1d kernel/sys_clock.h: Deprecate and convert uses of old conversions
Mark the old time conversion APIs deprecated, leave compatibility
macros in place, and replace all usage with the new API.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-11-08 11:08:58 +01:00
Trond Einar Snekvik 0151d6dc33 Bluetooth: Mesh: Model extension concept
Adds the model extension concept to the access layer, as described in
the Mesh Profile Specification, Section 2.3.6. Extensions are
implemented as a tree, using two pointers in each model:

The extends pointer points to the first extended model, and the next
pointer points to the next sibling or (if the NEXT_IS_PARENT flag is
set) the parent model in the tree, forming a cyclical "Left-child
right-sibling" (LCRS) tree. The tree root can be obtained by calling
bt_mesh_model_root_get(), and the extended models can be walked by
calling bt_mesh_model_tree_walk().

According to the Mesh Profile Specification Section 4.2.3, all models in
the same extension tree share one subscription list per element. This is
implemented by walking the model's extension tree, and pooling the
subscription lists of all models in the same element into one. If the
config server adds a subscription to a model, it may be stored in any of
the model tree's models' subscription lists. No two models in the same
extension tree and element will have duplicate groups listed. This
allows us to increase extended models' capacity for subscriptions
significantly.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-11-07 18:57:32 +02:00
François Delawarde 129e05c03f bluetooth: host: fix missing log_strdup
Fix missing log_strdup when loading bt/name setting. It should be done
on every string which is not in read only memory.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-11-07 12:49:34 +02:00
Trond Einar Snekvik 2cc0263a53 Bluetooth: Reduce severity of unavoidable warnings
Reduces the severity of warnings that happen from normal behavior, or
can't be prevented by the user:
- "No ID address" in hci_core.c: Reduced to an informational warning, as
  this will always output with the expected usage. This isn't useful
  information for 99.9% of users, and pollutes the output of all samples
  using the module.
- "Composition page %u not available" in cfg_srv.c: According to the
  Mesh Profile Specification section 4.4.2.2.2, the client is expected
  to send page=0xff. Reduced to a debug message.
- "Connectable advertising deferred" in proxy.c: Gets logged every 10
  seconds when in a Mesh Proxy connection. This is not useful
  information unless the user is debugging the proxy module. Reduced to
  a debug message.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-11-06 19:24:32 +02:00
Wolfgang Puffitsch e108898270 Bluetooth: controller: split: Make number of TX ctrl buffers configurable
A single connections may take up to 4 buffers at the same time. Make
number of connections that support this worst-case number
configurable.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-11-06 17:58:54 +01:00
Vinayak Kariappa Chettimada 3420f0863c Bluetooth: controller: split: Add data length procedure queueing
Added implementation to cache Data Length Procedure when
another control procedure is in progress.

Relates to commit 26317491e04b ("Bluetooth: controller: Add
data length procedure queueing").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-06 12:46:52 +01:00
Vinayak Kariappa Chettimada b9a8682d78 Bluetooth: controller: split: Fix Re-encryption procedure
Fix MIC failure on re-encryption procedure when responding
at the same time to peer initiated feature request.

Relates to commit 560d6ddb964c ("Bluetooth: controller: Fix
Re-encryption procedure").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-06 12:46:52 +01:00
Vinayak Kariappa Chettimada 11c3d2cd4e Bluetooth: controller: split: Fix ENC_REQ PDU retransmission
Fix dropped ENC_REQ PDU when retransmitting, if slave was
not listening or nack-ed it.

Relates to commit 31256568a283 ("Bluetooth: controller: Fix
ENC_REQ PDU retransmission").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-06 12:46:52 +01:00
Vinayak Kariappa Chettimada bff76b4cce Bluetooth: controller: split: Fix control tx queue handling
Fix control tx queue handling to correctly pause control PDU
responses during encryption setup.

Relates to commit 4b4b650174bf ("Bluetooth: controller: Fix
control tx queue handling").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-06 12:46:52 +01:00
Vinayak Kariappa Chettimada 16dbb9a4fe Bluetooth: controller: split: Fix cmd disallowed and collision disconnects
Fix implementation to correctly cache the control procedures
initiatable by local and peer. And, fix feature exchange and
version information procedures from being disallowed by
having then as cached requests to the controller.

Relates to #15256 and commit 0dcfa3853782 ("Bluetooth:
controller: Fix cmd disallowed and collision disconnects").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-06 12:46:52 +01:00
Vinayak Kariappa Chettimada b0c495791a Bluetooth: controller: split: Fix start encryption in progress check
Fix check in start encryption to disallow new encryption
setup while there is one already in progress.

Relates to commit 120eba45f81b ("Bluetooth: controller: Fix
start encryption in progress check").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-06 12:46:52 +01:00
Vinayak Kariappa Chettimada 7f0a95468a Bluetooth: controller: split: Fix data PDU leak during ctrl PDU defer
Fix a bug where in tx data PDU enqueued, while a ctrl PDU is
deferred due to Encryption setup being in progress, is
leaked causing HCI Tx Buffer Overflow crash.

Relates to commit 671ccc4b0ee6 ("Bluetooth: controller: Fix
data PDU leak during ctrl PDU defer").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-06 12:46:52 +01:00
Vinayak Kariappa Chettimada d8928d7952 Bluetooth: controller: split: Fix DLE during data transmission
Fix bug in Data Length Update procedure that caused the
connection to drop due to the implementation sending bigger
PDU before the peer has acknowledged the receipt of Length
Response PDU.

Relates to commit ffbbec7a89ca ("Bluetooth: controller: Fix
DLE during data transmission").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-06 12:46:52 +01:00
Ioannis Glaropoulos 46b728204e bluetooth: controller: nrf5: use nrfx function to get CCM IRQ line
We use the nRFx API nrf_get_irq_number(.) to retrieve the IRQ
line of the CCM peripheral, instead of the hard coded enum
value from MDK. We do this for portability, since these
enums may be different for different nRF SoC series.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-05 16:42:15 +01:00
Vinayak Kariappa Chettimada 709dee5ed0 Bluetooth: controller: split: Fix conditional compile error
Fix conditional compilation error in building the central
only samples as all peripheral structure member accesses in
the controller where not correctly compiled out.

Regression introduced in commit 6d8b12468e ("Bluetooth:
controller: split: Refactor LLL conn structure").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-05 11:22:38 +01:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
Ioannis Glaropoulos 73483094da bluetooth: controller: nrf5: simplify preprocessor conditionals
We make a minor simplification in the way we define
RADIO_PDU_LEN_MAX in Nordic nRF LE radio driver; as
nRF51 SoC series is the only series where the LL PDU
max length representation is limited to a 5-bit field,
we simplify the conditional preprocessor expression,
to avoid having to list all nRF5x SoCs with PDU LEN
MAX is represented by an 8-bit integer field.

In addition, we modify the preprocessor conditional,
that compiles in the CCM support for 8-bit length field,
PDUs to be an #ifndef CONFIG_SOC_SERIES_NRF51X, instead
of #ifdef CONFIG_SOC_COMPATIBLE_NRF52X; this will
simplify the expression when adding nRF53X series
support.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-04 17:14:06 +01:00
Joakim Andersson 23e8e6891b Bluetooth: Shell: Disallow GATT commands when params are in use
GATT parameters need to remain valid while the procedure is active.
Disallow GATT commands while the procedure is active to avoid asserting.

Fixes: #20232

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-11-04 14:41:15 +01:00
Vinayak Kariappa Chettimada eed51cc018 Bluetooth: controller: split: Fix missing terminate_ack initialization
Add the missing initialization of master role terminate_ack
flag. This caused slave initiated remote termination as
procedure timeout.

Fixes #20135.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-04 10:44:59 +01:00
Vinayak Kariappa Chettimada 6d8b12468e Bluetooth: controller: split: Refactor LLL conn structure
Refactor the LLL connection context to move out the member
fields not accessed in LLL execution context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-11-04 10:44:59 +01:00
François Delawarde 5317008ad3 bluetooth: host: fix missing bt_conn_unref
Fix missing bt_conn_unref when using the ccc match callback.

Fixes: #20299

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-11-04 09:43:13 +01:00
Peter A. Bigot bf5817d273 Bluetooth: rework to support C++20 designated initializers
C++ does not allow chaining of data members when identifying the
designator.  Since the generic structure has only one member remove
the designator from its internal initializer.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-11-03 13:24:57 +01:00
Morten Priess ca5c829a84 bluetooth: controller: Move calculation of max_tx_octets to ULL
Move calculation of max_tx_octets from Nordic lll_conn.c to ULL, to
allow usage by other vendors and prevent duplicate code.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-11-02 11:15:44 +01:00
Morten Priess 89ab68f242 bluetooth: controller: Vendor specific ticker resolution margin
With sub-microsecond resolution in ticker, it is not necessary to add a
precision margin to the conn_offset. A macro is created to allow setting
the margin to something other than the hard coded 2 * EVENT_JITTER_US.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-11-02 11:14:38 +01:00
Morten Priess b631cc09ab bluetooth: controller: Add vendor specific overhead to TX buffer size
TX pdu buffers may need to be augmented for fragmentation or other
purpose, depending on vendor LLL implementation. Introduced define to
add extra bytes to TX buffer size, defaulting to 0 if unused.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-11-01 17:54:29 +01:00
Ulf Magnusson 975de21858 kconfig: Global whitespace/consistency cleanup
Clean up space errors and use a consistent style throughout the Kconfig
files. This makes reading the Kconfig files more distraction-free, helps
with grepping, and encourages the same style getting copied around
everywhere (meaning another pass hopefully won't be needed).

Go for the most common style:

 - Indent properties with a single tab, including for choices.

   Properties on choices work exactly the same syntactically as
   properties on symbols, so not sure how the no-indentation thing
   happened.

 - Indent help texts with a tab followed by two spaces

 - Put a space between 'config' and the symbol name, not a tab. This
   also helps when grepping for definitions.

 - Do '# A comment' instead of '#A comment'

I tweaked Kconfiglib a bit to find most of the stuff.

Some help texts were reflowed to 79 columns with 'gq' in Vim as well,
though not all, because I was afraid I'd accidentally mess up
formatting.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-01 15:53:23 +01:00
Tobias Svehagen 3282ff22c4 Bluetooth: Mesh: Add support for provisioner over PB-ADV to shell
Adds the command provision-adv to the mesh shell.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-10-30 13:08:09 +01:00
Tobias Svehagen 7e3f0c125a Bluetooth: Mesh: Add bt_mesh_provision_adv API
Add API for supporting provisioning of devices over PB-ADV.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-10-30 13:08:09 +01:00
Tobias Svehagen 80669decce Bluetooth: Mesh: Add support for provisioner role over PB-ADV
Make it possible to provision devices over advertising bearer (PB-ADV).
Many messages in the provisioning protocol are the same for provisioner
and device so much of the code could be reused by only changing when
they are expected to arrive.

This introduces to concept of local and remote device keys. The models
for cfg_cli and cfg_srv have been updated to reflect this concept. Both
the send and receive path in the transport layer have been updated to
support encrypting/decrypting with local and remote device keys.

When a node has been provisioned it is stored in bt_mesh_net.nodes. If
CONFIG_BT_SETTINGS is enabled, they are also saved to settings. If the
callback node_added in bt_mesh_prov has been set, it will be called for
every node that gets provisioned. This includes when they are retrieved
from settings.

The configuration CONFIG_BT_MESH_NODE_COUNT controls how many nodes that
can be provisioned.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-10-30 13:08:09 +01:00
Tobias Svehagen de92d1a83b Bluetooth: Mesh: Add callback for unprovisioned device beacon
Adds the unprovisioned_beacon callback to the bt_mesh_prov structure.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-10-30 13:08:09 +01:00
David B. Kinder 241044f178 doc: fix misspellings in Kconfig files
Fix misspellings in Kconfig files missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-10-30 10:24:30 +01:00
Solveig Fure aefe941396 bluetooth: controller: Remove condition for header inclusion
Remove ifdef guard around inclusion of nrf_clock_control.h in bluetooth
controller as the defines in this header are needed anyway.

Signed-off-by: Solveig Fure <solveig.fure@nordicsemi.no>
2019-10-28 16:24:51 +01:00
Carles Cufi 8c2b849ae7 Bluetooth: hci: Fix Create Connection Cancel assert
Since the LE (Enhanced) Connection Complete that comes as part of
cancelling a connection does not come through the priority rx thread in
hci_driver.c, the event class was not being calculated and cached.
Hence, calculate and cache the class whenever an event is received as
part of invoking a command.

Fixes #20110.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-10-24 20:33:59 +02:00
Radoslaw Koppel ecf06debe6 Bluetooth: UUID: Implement UUID 128 encoder
This commit adds an macro to allow UUID 128
to be written in more user-friendly form.
UUID in 128 bit form requires an array creation.
To complicate the whole thing - it requires the array to start from LSB,
so using the readable form, we have to write it down backwards.

Old way to declare example UUID 6E400001-B5A3-F393-E0A9-E50E24DCCA9E:
 0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0,
 0x93, 0xF3, 0xA3, 0xB5, 0x01, 0x00, 0x40, 0x6E

A form provided by this commit:
 BT_UUID_128_ENCODE(0x6E400001, 0xB5A3, 0xF393, 0xE0A9, 0xE50E24DCCA9E)

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-10-23 18:49:13 +03:00
Vinayak Kariappa Chettimada 09088d856f Bluetooth: controller: split: Fix conn RSSI initial value
On connection callback generated by host, application
reading the RSSI value by using HCI LE Read RSSI Command
received -127 dB as the first connection event has not
occured yet in order to measure the RSSI value.

Fix this by using the RSSI value of received advertising
PDU by the initiator, and using the RSSI value of the
received CONNECT_REQ PDU by the connectable advertiser as
the initial value at connection setup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-22 13:19:26 +02:00
Vinayak Kariappa Chettimada 4cc3cab9c7 Bluetooth: controller: legacy: Fix conn RSSI initial value
On connection callback generated by host, application
reading the RSSI value by using HCI LE Read RSSI Command
received -127 dB as the first connection event has not
occured yet in order to measure the RSSI value.

Fix this by using the RSSI value of received advertising
PDU by the initiator, and using the RSSI value of the
received CONNECT_REQ PDU by the connectable advertiser as
the initial value at connection setup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-22 13:19:26 +02:00
Vinayak Kariappa Chettimada 9c14567ce2 Bluetooth: controller: Fix conn update to be cacheable
Fix connection update procedure to be cacheable if any other
local or remote control procedure is in progress.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-22 13:18:56 +02:00
Vinayak Kariappa Chettimada fcd9612016 Bluetooth: controller: split: Fix incorrect MD bit value
MD bit was set based on whether a memq link's next pointer
being NULL, instead the check should be that the  memq has
more elements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-21 13:01:26 +02:00
Vinayak Kariappa Chettimada 8ada121b68 Bluetooth: controller: split: Fix slave latency enable
Fix regression in porting slave latency, slave latency
enabled was not used, cause slave latency to be applied
before first packet being acknowledged by the master.

Regression in commit 5dff214d57 ("Bluetooth: controller:
split: Fix missing slave latency impl.").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-21 10:21:30 +02:00
Ulf Magnusson 91dc62949e Bluetooth: Settings: Fix broken CONFIG_BT_SETTINGS_USE_PRINTK check
The CONFIG_* prefix was missing, making the #ifdef always false.

Found with a script (CONFIG_BT_SETTINGS_USE_PRINTK was unused).

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-10-18 21:52:03 +03:00
Joakim Andersson d0481f6d7f Bluetooth: GATT: Fix gatt buffer leak for write commands and notify
Fix GATT buffer leak when bt_att_send returns error the allocated
buffer is never freed. Discovered case where the link was disconnected
during the function call, so when GATT checkd the link was still
connected, but ATT checkd the link was disconnected.

Fixes: #19889

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-10-18 21:22:18 +03:00
Ulf Magnusson 72fb847a25 bluetooth: kconfig: Remove unused BT_CTLR_LOWEST_PRIO symbol
Added in commit 1475402d41 ("Bluetooth: controller: Introduce ULL LLL
architecture"), then never used.

Found with a script.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-10-18 19:43:47 +02:00
Sergiy Nikolayenko 25164654dd Bluetooth: Keys: add key overwrite feature for key storage.
Key overwrite feature allows to overwrite old pairing key
records when key storage is full and a new pairing request occurs,
or new keys are distributed. If enabled when key storage is full and
a keys storage slot is requested, the oldest keys added will be
removed. So new devices can be paired with no limitations and no need
to determine, which devices should be unpaired to free key storage
space explicitly in application. To enable the feature set
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y.

Oldest keys are determined by minimum value of up-counting aging
counter. If you set CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING=y
aging counter values will be updated each time the secure connection
is established. This might increase flash wear out if at least two
secure connections are established and shut down periodically. When
the option disabled aging counter is still updated on each new secure
connection, but not stored to flash.

Signed-off-by: Sergiy Nikolayenko <sergiy_nikolayenko@jabil.com>
2019-10-17 22:20:55 +03:00
Ulf Magnusson ac9fe11f2f Kconfig: Remove copy-pasted comments on some promptless symbols
Remove the

    # Omit prompt to signify a "hidden" option

comments that appear on some symbols. They seem to have been copy-pasted
at random, as there are lots of promptless symbols that don't have them
(that's confusing in itself, because it might give the idea that the
ones with comments are special in some way).

I suspect those comments wouldn't have helped me much if I didn't know
Kconfig either. There's a lot more Kconfig documentation now too, e.g.
https://docs.zephyrproject.org/latest/guides/kconfig/index.html.

Keep some comments that give more information than the symbol having no
prompt.

Also do some minor drive-by cleanup.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-10-17 13:05:24 -05:00
Lingao Meng 101ad56d43 Bluetooth: Mesh: Persistent storage of Virtual Addresses
The 16-bit format group addresses will be stored,
but we don't store (or restore) the virtual label UUIDs,
i.e. after a power cycle the 16-bit group addresses
would be meaningless.

Fixes #19342

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2019-10-17 12:24:13 +03:00
Joakim Andersson 0f06c7d8e4 Bluetooth: HCI: Add function to get connection handle of connection
Add public API function to get the connection handle of the connection.
The connection handle is needed by applications that intend to send
vendor specific commands for a given connection.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-10-17 10:04:06 +02:00
Vinayak Kariappa Chettimada 3d4aef8f99 Bluetooth: controller: split: Stop pre-empt timer
Add pre-empt timer stop when a prepare is executed so that
when the pipeline has another event queued, the firing of
the pre-empt timer does not pre-empt the just executed
prepare.

Relates to #19685.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-16 16:00:36 +02:00
Luiz Augusto von Dentz c736de05fa Bluetooth: GATT: Replace check for CONFIG_BT_SMP
Make use of bt_conn_get_security instead of accessing conn->sec_level
directly.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-10-16 12:08:25 +03:00
Lingao Meng 345b64f106 Bluetooth: Mesh: Fixed Provision Random buffer size
Fixed some minor issues, missing a byte for opcode.

Fixes: #19767

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2019-10-15 23:22:04 +03:00
Vinayak Kariappa Chettimada 4d4fb8e301 Bluetooth: controller: split: Fix ticks slot used on conn update
Fix incorrectly calculated ticks slots for a connection on
connection update. The reservation incorrectly included the
prepare offset.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-15 16:04:05 +02:00
Joakim Andersson 8ff183eb6c Bluetooth: GATT: Fix bug in bt_gatt_attr_next unable for static handles
Fix bug in bt_gatt_attr_next when given an attribute that has static
allocation. The handle is then 0 and the function would always return
the attribute with handle 1.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-10-15 14:53:03 +02:00
Joakim Andersson 23554b00b8 Bluetooth: host: Fix whitelist for non-central bluetooth applications
Fix compilation issue when wanting to use whitelist in bluetooth
applications that does not have CONFIG_BT_CENTRAL defined.
These functions are useful even for broadcaster and observer roles.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-10-15 15:26:43 +03:00
Joakim Andersson 5229276817 Bluetooth: GATT: Add function to check if attribute has been subscribed
Add public API function in GATT to check if a specific connection has
subscribed to the given attribute.
Without this function the application has to keep track of which
connections has subscribed using the callbacks from BT_GATT_CCC_MANAGED
since the cfg_changed callback of the CCC doesn't carry connection
context.
The other alternative is for the application to parse the information
in the struct _bt_gatt_ccc object. Although this object has structure
information available to the application the structure is marked as
internal, so the application shouldn't rely on this definition.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-10-15 15:08:56 +03:00
Vinayak Kariappa Chettimada fca32e41e6 Bluetooth: controller: Fix DLE for remote unsupported Coded PHY
Fix Data Length Procedure to use Feature Exchange values to
send correct parameters based on whether Coded PHY is
supported by remote peer.

Relates to BT TS.5.1.1 tests:
LL/CON/MAS/BV-129-C
LL/CON/MAS/BV-130-C
LL/CON/SLA/BV-132-C
LL/CON/SLA/BV-133-C

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-15 13:26:29 +02:00
François Delawarde 1ce95de6ae bluetooth: host: Persist Service Changed data
Add support for persisted Service Changed data, to fix the case of a
paired device not reconnecting before a reboot and thus not receiving
SC indication. It also enables support for GATT database being changed
during a firmware update.

Move Service Changed data outside of the CCC struct and make it
persistent by adding support for a bt/sc/... setting.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-10-15 10:57:08 +02:00
François Delawarde 3a2d269bb4 bluetooth: host: Introduce a config option for Service Changed
The Service Changed characteristic support should also work when the
GATT database has been modified after reboot (firmware update scenario)

This commit introduces a BT_GATT_SERVICE_CHANGED config option that is
independent from BT_GATT_CACHING and BT_GATT_DYNAMIC_DB.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-10-15 10:57:08 +02:00
Vinayak Kariappa Chettimada af696bdd4c Bluetooth: controller: split: Fix ctrl proc rx node starvation
Rx nodes are reserved during control procedures for
generation of HCI event on completion. Fix the allocation
and reservation in the form of a linked list per connection
context. Worst case, this list will hold one rx node for
overlapping non-instant control procedure (Data Length
Update) plus two rx node for control procedure with instant
(PHY update with Data Length Update support).

Fixes #19198.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-14 11:25:10 +02:00
Carles Cufi 6c34983ed2 Bluetooth: controller: Handle remote version as a prio event
The remote version information event needs to be processed by the
prio_recv_thread() thread in order to unblock the Host RX thread
(effectively hci_driver's recv_thread()) when it blocks waiting for a
response to a remote version information.

Add the same time gate the inclusion of the feature behind a new Kconfig
option: CONFIG_BT_REMOTE_INFO.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-10-11 13:31:52 +02:00
Carles Cufi b37be1c0c5 Bluetooth: controller: Introduce a new LLCP class
In order to be able to distinguish between connection-related events
that are generated by the controller and others genrated by LL control
procedures, introduce a new class for LLCP.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-10-11 13:31:52 +02:00
Carles Cufi 058724f329 Bluetooth: controller: Optimize calls to hci_get_class()
Cache the result of calling hci_get_class() to avoid repeatedly invoking
it on the same data. In order to cache it we take advantage of the fact
that both radio_pdu_node_rx_hdr and node_rx_hdr are not packed
structures and they currently have a spare padding byte (between type
and handle).

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-10-11 13:31:52 +02:00
Carles Cufi 9c32a6d287 Bluetooth: controller: hci: Obtain pdu_data using a macro
Hide the details of obtaining a pointer to the PDU data from a node_rx
structure to simplify the code.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-10-11 13:31:52 +02:00
Carles Cufi db5e6f861d Bluetooth: controller: Further trim connection-related code
Conditionally compile additional code that is only relevant when
enabling connections.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-10-11 13:31:52 +02:00
Wolfgang Puffitsch 34b95feb54 Bluetooth: controller: split: Call LLL reset functions from ll_reset
Call LLL reset functions when calling ll_reset to avoid carrying LLL
state across HCI resets. Respective functions already exist in LLL but
had not been called from anywhere.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-10-11 08:58:33 +02:00
Trond Einar Snekvik f7d9af8cb2 Bluetooth: Mesh: Proxy forwards ALL_NODES addr
Unless explicitly blacklisted, the Proxy node will forward all messages
for the ALL_NODES address to the GATT proxy client.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-10-10 13:09:42 +02:00
Vinayak Kariappa Chettimada d12c53f89f Bluetooth: controller: split: Fix missing data len update event
Fix missing generation of data length update HCI event when
effective tx and rx timings change due to PHY update
procedure.

Fixes BT LL TS 5.1.0 test:
LL/CON/MAS/BV-52-C [Master Receiving Data, LE Coded, CI
Change]

Relates to #17097.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-10 12:13:54 +02:00
Vinayak Kariappa Chettimada 186a584d0a Bluetooth: controller: split: cond. compile job disable
When ULL High and ULL Low are not at same execution priority
level, it is not necessary to disable ULL Low execution when
updating ticker using stop and start. Also, ULL Low need not
be disable inside Radio Events. This commit corrects some of
the conditional compiles.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-10 12:12:47 +02:00
Vinayak Kariappa Chettimada b71eb71de7 Bluetooth: controller: Fix Kconfig conditional optionals
Fix Kconfig conditional include of Minimum Channels Used
and Channel Selection Algorithm #2.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-09 15:53:14 +02:00
Wolfgang Puffitsch 537f06a532 Bluetooth: controller: split: Add hook for flushing in LLL
Add hook for flushing in LLL to allow clean-up of LLL-specific
resources.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-10-09 13:17:58 +02:00
Vinayak Kariappa Chettimada d534492bf9 Bluetooth: controller: Fix ticker previous slot value
Fix ticker previous slot value with elapsed ticks value from
the time stopped ticker has expired. When a ticker is
stopped, if it was in its reserved time space, then the
currently occupied slot (was set to 0) should be the amount
of time that has elapsed in the expired and stopped ticker's
reserved time space and beyond until the stop.
This is required to ensure that any other new ticker does
not get scheduled over the stopped ticker's reserved time
space.

Fixes #19515.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-09 09:19:32 +02:00
Vinayak Kariappa Chettimada a1945db08a Bluetooth: controller: 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-10-09 09:19:18 +02:00
Vinayak Kariappa Chettimada 3096c0e741 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-10-09 09:19:18 +02:00
Vinayak Kariappa Chettimada 1e20009212 Bluetooth: controller: Add Zero Latency IRQ Kconfig
Add a Kconfig option to enable use of Zero Latency IRQs in
the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-09 09:19:18 +02:00
Trond Einar Snekvik 5aee3ee995 Bluetooth: Mesh: Model message macros
Creates macros for determining model message lengths based on opcode,
payload length and MIC size. Also adds macro wrapping
NET_BUF_SIMPLE_DEFINE to serve the most common use case.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-10-08 18:38:43 +03:00
Thomas Ebert Hansen 392d3a864a Bluetooth: controller: Fix endianness for length update.
Fix endianness when accessing length update parameters over HCI

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2019-10-08 11:38:55 +02:00
Morten Priess 90fabfd96b bluetooth: controller: Prevent unnecesary ticker "must expire"
When running a ticker node as "must expire", the node would invoke the
ticker callback even when programmed with latency. As "must expire" is
intended for scheduled events which are skipped due to collision, and as
such expected by LLL, purposefully skipped events should not generate
"must expire" callbacks.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-10-08 11:37:58 +02:00
Morten Priess 51e4acb8e0 bluetooth: host: Added handler for data buffer overflow
Added event handler to prio_events in hci_core.c.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-10-07 12:43:46 +03:00
Vinayak Kariappa Chettimada 786bed70ac Bluetooth: controller: split: Fix central_hr sample compilation
Fix ULL implementation that uses conditional compilation by
replacing back to use of #if defined(...) in code accessing
compiled out struct members.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 21:46:13 +02:00
Vinayak Kariappa Chettimada 1d00072bdc Bluetooth: controller: split: Fix flushing Tx buffers in ULL
Fix for possible Tx Buffer leak during disconnection when
the buffers are in ULL context and not yet enqueued towards
LLL context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 20:29:29 +02:00
Vinayak Kariappa Chettimada aa38b2298c Bluetooth: controller: split: Fix for Tx Buffer Overflow error
When more than one simultaneous connections are active,
transmitting data packets to peer, a termination causes
host to use the flushed pending number of completed packets
count for other active connections. This is on reception
of HCI disconnection complete event. But the controller has
not yet released any of the pending enqueued Tx buffers
which was happening after the disconnection event was
dispatched to HCI layer.

The fix here is to dispatch the disconnection complete event
from the LLL context after pending Tx buffers have been
flushed and the buffers get returned to Tx pool in the ULL
context. This way buffers are in the Tx pool before host
get to process the disconnection complete event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 20:29:29 +02:00
Vinayak Kariappa Chettimada 203b5859a1 Bluetooth: controller: split: Fix flushing Tx buffers in HCI
Fix for possible Tx Buffer leak during disconnection when
the buffers are in HCI thread context  and not yet demux-ed
and enqueued towards LLL context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 20:29:29 +02:00
Vinayak Kariappa Chettimada 7d49726498 Bluetooth: controller: split: Fix LLL Tx flush to be immediate
Fix the mayfly scheduling of the Tx buffer flushing on
connection termination to be immediate (not to tailchain).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 20:29:29 +02:00
Luiz Augusto von Dentz 1ef9b20f61 Bluetooth: ATT: Replace checks for CONFIG_BT_ATT_ENFORCE_FLOW
Make use of IS_ENABLED so the compiler do its job to remove any dead
code.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-10-04 20:57:13 +03:00
Luiz Augusto von Dentz 8d2cb14b17 Bluetooth: L2CAP: Replace checks for CONFIG_BT_CENTRAL
Make use of IS_ENABLED so the compiler do its job to remove any dead
code.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-10-04 20:57:13 +03:00
Trond Einar Snekvik 6911287899 Bluetooth: Mesh: Use net_buf_simple_clone
Uses net_buf_simple_clone to access the sdu of an unsegmented app packet
for re-encryption.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-10-04 20:56:25 +03:00
Trond Einar Snekvik 9fdefc7d73 Bluetooth: Mesh: Skip local messages in rx
Local messages are already enqueued for the LPN in the tx path, and
don't have to be added again in the rx path.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-10-04 20:56:25 +03:00
Trond Einar Snekvik a7cf776d52 Bluetooth: Mesh: Ensure seqnum match in app/net
Re-encrypts single-segment application messages when the network seqnum
has changed, to avoid encrypting messages with different seqnums in
network and transport. This operation is only required for unsegmented
messages, as segmented messages don't need to use the same seqnum in
network.

Reinstates the special adv data for friend messages to store the app key
index.

Fixes #19265.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-10-04 20:56:25 +03:00
Trond Einar Snekvik 70b5556b09 Bluetooth: Mesh: Expose app key get
Provides a utility function for getting an application key given a
subnet and an app ID. Primary use-case in friendship re-encryption.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-10-04 20:56:25 +03:00
Trond Einar Snekvik ec5e43ba5f Bluetooth: Mesh: Expose header parsing outside net
Provides utility function for parsing network headers outside of the
network layer. The primary intended use-case is friendship.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-10-04 20:56:25 +03:00
Krzysztof Chruscinski ec6b7e780b bluetooth: controller: Align nrf link layer to new clock control API
Align to use clock_control_get_status for blocking clock start.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-10-04 17:15:39 +02:00
Joakim Andersson 4d59ef306b Bluetooth: controller: Check if enc procedure is in progress
Check if the encryption procedure is in progress when receiving
rejection for the procedure.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-10-04 15:10:45 +02:00
Joakim Andersson 4135fb55f1 Bluetooth: controller: Fix rejected enc procedure not terminated
Fix issue in the handling of LL_REJECT_EXT_IND packets, this would look
at the procedures that are enqueued, and not the procedure that was
being rejected. This meant that although a reject was received for the
encryption procedure, the handling for a different control procedure was
run.
This would result in the link being terminated as control procedure
timer would time out for the encryption procedure.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-10-04 15:10:45 +02:00
Johan Hedberg bca12197fd Bluetooth: Mesh: crypto: Remove unnecessary #ifdefs
Static variables and functions don't need #ifdefs if the code calling
them is using IS_ENABLED(). If IS_ENABLED() evaluates to false the
compiler will strip out all the static entities.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-10-04 16:03:57 +03:00
Johan Hedberg 84847f5c6d Bluetooth: Mesh: beacon: Remove unnecessary #ifdefs
Static variables and functions don't need #ifdefs if the code calling
them is using IS_ENABLED(). If IS_ENABLED() evaluates to false the
compiler will strip out all the static entities.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-10-04 16:03:57 +03:00
Johan Hedberg 71283c6c9b Bluetooth: Mesh: net: Remove unnecessary #ifdefs
Static variables and functions don't need #ifdefs if the code calling
them is using IS_ENABLED(). If IS_ENABLED() evaluates to false the
compiler will strip out all the static entities.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-10-04 16:03:57 +03:00
Vinayak Kariappa Chettimada 6f7f5153db Bluetooth: controller: split: Fix radio abort race condition
When aborting radio event, there is a possibility that the
packet timer would start the radio while the packet timer
is being reset. Hence, perform a second radio state disable
with packet timers uninitialised.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 12:44:46 +02:00
Vinayak Kariappa Chettimada 20e385e675 Bluetooth: controller: split: Fix missing radio status reset
Fix missing radio status and configurations reset on radio
event abort. This caused under race conditions the radio
being put into active state after being aborted.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 12:44:46 +02:00
Vinayak Kariappa Chettimada 8d8d6a7608 Bluetooth: controller: split: Fix incorrect mayfly caller id
Fix incorrect ticker/mayfly user id used in scheduling the
abort of a radio event. Incorrect use of thread context as
the caller caused the abort function to be scheduled from
thread context while being called from ULL high context
level in reality. This could cause corruption of mayfly
scheduling.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 12:44:46 +02:00
Vinayak Kariappa Chettimada 848015854a Bluetooth: controller: split: Fix flash driver co-operation
When flash driver requests abort of radio event in unreserved
time space, resume radio events in the pipeline were not
flushed. These resumed events caused flash driver to assert
on the check whether radio was in use.

Fixed by flushing the pipeline of all radio events, resume
and also those events in pipeline with pre-empt timeout
being setup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 12:44:46 +02:00
Vinayak Kariappa Chettimada 9d6c170e22 Bluetooth: controller: split: Fix advertising for multiple peripherals
When multiple simultaneous peripheral connections are
supported, restarting connectable advertising by host on
peripheral connection establishment failed in controller.
This prevented establishing new connections while first
connection was active.

The failure was caused by a bug in the way controller was
using quota for Rx PDU buffers. As the quota count was
release before the connection complete event rx PDU buffer
being released, the Rx PDUs needed to reserve for
connection complete event for new connectable advertising
was not available. This caused the connectable advertising
enable to fail.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 12:44:00 +02:00
Vinayak Kariappa Chettimada 5dff214d57 Bluetooth: controller: split: Fix missing slave latency impl.
Port the missing slave latency implementation from legacy
controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-10-04 12:43:24 +02:00
Joakim Andersson 4bca0f3d33 Bluetooth: ATT: Fix disconnected ATT not releasing buffers
Fix bug in ATT reset handling, not releasing queued notification
buffers when the connection is terminated.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-10-04 10:33:55 +03:00
Johan Hedberg 4f3b0cb28c Bluetooth: Mesh: Remove unused macro
The FRIEND_BUF_SIZE macro has no users.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-10-02 10:36:12 -07:00
Wolfgang Puffitsch 799b46e35e Bluetooth: controller: Use entropy driver directly in bt_rand
Use entropy driver directly in bt_rand instead of stitching together
calls to sys_rand32_get to improve efficiency. The use of
sys_rand32_get could also leak timestamps into keys.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-10-02 13:21:24 +02:00
Morten Priess 70cbf342ff bluetooth: controller: RX PDU meta data support in LLL
Added support for vendor specific meta data in LLL node_rx_hdr. This
enables vendors to add "footer" data to the RX PDU, for supporting
specialized BLE features.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-10-02 13:20:50 +02:00
Carles Cufi cd9b940756 Bluetooth: common: Statically check for immediate logging
Immediate logging is not compatible with the software-based controller
due to the additional ISR latency that it introduces. Ensure that
deferred logging is in use whenever using the software-based LL.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-10-01 19:11:16 +02:00
Andrew Boie 1b900bf546 bluetooth: monitor: don't build backend if minimal
Log backends don't exist with minimal logging enabled,
don't compile this code.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-01 09:24:02 -04:00
Joakim Andersson 2ac5841928 Bluetooth: SMP: Handle both devices initiating security
Handle case where:
 - Peripheral sends security request after master has sent pairing
   request or started encryption procedure.
   This packet can be ignored, as long as the slave has not already
   responded with pairing response.
 - Central wants to start security after peripheral initiated security
   request, return error code busy in this case

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-30 10:29:56 -07:00
Joakim Andersson eb6ae10745 Bluetooth: SMP: Move re-encryption handling into the SMP module
Move initiating security functionality and LTK requesting into the SMP
module so that SMP can track when the connection is in the encryption
process

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-30 10:29:56 -07:00
Joakim Andersson d50b1ac301 Bluetooth: SMP: Move bt_smp_keys_check function up
Move the bt_smp_keys_check function above all usage of the function
in order to avoid prototype declaration when making the function static.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-30 10:29:56 -07:00
Joakim Andersson 3920844842 Bluetooth: Host: Fix usage of re-using Bluetooth log buffers
Fix calling bt_hex and bt_addr_le_str multiple times in the same logging
call could result in string overwritten since log_strdup is not
guaranteed to duplicate the string buffer in all logging configurations.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-30 17:47:43 +02:00
Morten Priess c1038de6e8 bluetooth: controller: Add vendor operations to TICKER_USER_ULL_HIGH_OPS
Added to allow vendor specific increase of user operation capacity for
ULL_HIGH, to support queuing additional ticker operations.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-09-30 13:04:17 +02:00
Morten Priess cd07fe94d6 bluetooth: controller: Use ticker must_expire to ensure ADV timing rand
Enabled use of ticker must_expire feature for ensuring ADV timing
randomization, even when ADV doesn't get air-time. This reduces ADV
collisions. Not active for nRF51 platform for now.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-09-30 12:52:52 +02:00
Morten Priess 5ce4df2a67 bluetooth: controller: Connection meta property support in LLL
Added support for vendor specific meta data in LLL conn object. This
enables vendors to add state data to connection, for supporting
specialized BLE slave features.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-09-30 12:52:33 +02:00
Vinayak Kariappa Chettimada c38e2ee61a Bluetooth: controller: Fix refactored SWI regression
Fix regression introduced in refactoring of use of SWI.
Reduced use of SWI cannot be used in combination with
CONFIG_BT_CTLR_LOW_LAT as additional SWI is required
to split ticker WORKER and JOB contexts in order to
disable JOB but keep WORKER enabled.

Regression introduced in commit 78b461ae3e ("Bluetooth:
controller: Refactor use of SWI").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-30 12:25:10 +02:00
Joakim Andersson 8b976b12a8 Bluetooth: GATT: Provide correct error code when disconnected
Calling indicate or notify on a disconnected connection object would
result in the error code ENOMEM when failing to acquire buffers instead
of the expected return code ENOTCONN.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-27 20:53:23 +03:00
Sebastian Bøe 8610b84d55 cmake: don't link interface libraries with zephyr_interface
Stop linking interface libraries against zephyr_interface. This is
cargo cult code that in practice does nothing.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-09-26 05:50:46 -07:00
Johan Hedberg 6d798c8cce Bluetooth: Mesh: Fix Clear Procedure start timestamp initialization
The start timestamp was supposed to signify the starting point of the
clear procedure. The code was incorrectly initializing it to the *end*
point of the procedure.

Fixes #19263

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-09-26 15:30:51 +03:00
Kim Sekkelund 0450263393 Bluetooth: Host: Remove printk dependency from settings
Some modules use snprintk to format the settings keys. Unfortunately
snprintk is tied with printk which is very large for some embedded
systems.
To be able to have settings enabled without also enabling printk
support, change creation of settings key strings to use bin2hex, strlen
and strcpy instead.
A utility function to make decimal presentation of a byte value is
added as u8_to_dec in lib/os/dec.c
Add new Kconfig setting BT_SETTINGS_USE_PRINTK

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2019-09-25 17:36:39 +02:00
Vinayak Kariappa Chettimada 571809009e Bluetooth: controller: Fix legacy for TICKER_COMPATABILITY_MODE
When not using ticker compatibility mode in legacy
controller, ticker job should not be disabled inside radio
events.

Ticker compatibility mode was introduced in
commit 3a9173afe1 ("bluetooth: controller: Revised ticker
for improved conflict resolution").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-25 11:53:38 +02:00
Andrzej Głąbek 35754375bc soc: nordic: Get rid of nrf_common.h
This file contains redundant definitions of a bunch of nRF IRQ numbers
(not all, however) that only generates confusion, as enumeration values
provided by MDK can be used instead.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-09-24 16:20:16 +02:00
Andrzej Głąbek 57c6cfc9cd nordic: Use hal/ in all inclusions of nrfx HAL header files
Header files of nrfx HALs are not supposed to be included directly
but only with their names prepended with the hal/ directory (so that
an inclusion of an nrfx HAL header clearly differs from an inclusion
of an nrfx driver header).

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-09-24 16:20:16 +02:00
Vinayak Kariappa Chettimada f965b9c685 Bluetooth: controller: Fix DLE event on PHY update
Fix HCI Data Length Update event generation on PHY update
procedure, i.e. preserve Data Length Parameters on PHY
update.

Fixes BT LL.TS.5.1.1 tests:
LL/CON/MAS/BV-126-C
LL/CON/MAS/BV-127-C
LL/CON/SLA/BV-129-C
LL/CON/SLA/BV-130-C

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-24 10:37:44 +02:00
Vinayak Kariappa Chettimada 5ef52da005 Bluetooth: controller: Fix mayfly optimization
Fix incorrect reset of mayfly pended flag. This fix reduces
CPU use by mayfly.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-24 10:37:23 +02:00
Ioannis Glaropoulos 3bf872110d bluetooth: controller: nRF52811: fix LE Coded S2 Radio Timings
The nRF52811 Radio is similar to nRF52840 and exhibits
similar Radio Timings constants. We align the LE Coded
PHY (S2) RX chain delay with that of nRF52840, which,
eventually fixes the TIFS for nRF52811. In nRF52840 we
correct the inline comment only.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-24 09:02:15 +02:00
Vinayak Kariappa Chettimada 3202f91748 Bluetooth: controller: Fix to reject invalid enable command
Fix to reject invalid advertise and scan enable commands.

Fixes BT HCI.TS.5.1.1 tests:
HCI/DDI/BI-06-C
HCI/DDI/BI-07-C

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-24 08:15:56 +02:00
Vinayak Kariappa Chettimada 0ef062407c Bluetooth: controller: split: Fix to reject invalid enable command
Fix to reject invalid advertise and scan enable commands.

Fixes BT HCI.TS.5.1.1 tests:
HCI/DDI/BI-06-C
HCI/DDI/BI-07-C

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-24 08:15:32 +02:00
Ioannis Glaropoulos 5692ee17ed bluetooth: controller: replace SOC_NRF52840 in ifdef blocks for Coded
We have introduced option HAS_HW_NRF_RADIO_BLE_CODED, which
reflects that an nRF SoC has a Radio with LE Coded PHY
capabilities. We now modify all #ifdef expressions for
Coded PHY in the nRF controller port, removing SOC_NRF52840
and adding this new option instead. This allows to build
an nRF controller with Coded PHY support for SOCs other
than nRF52840.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-23 10:50:01 +02:00
Ioannis Glaropoulos b2809ff769 bluetooth: controller: enable Coded PHY support for nRF52811
Nordic nRF52811 SoC has a 2.4GHx Radio which supports
LE Coded PHY, so we add the option to build a BLE
Controller for nRF52811 platforms with LE Coded PHY
support.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-23 10:50:01 +02:00
Piotr Pryga a2eb10a76d Bluetooth: host: Configurable time to run slave conn param update
Enable possibility to configure time a slave will wait until
start of connection parameters update procedure after BT connection
is established.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2019-09-23 10:10:49 +02:00
Wolfgang Puffitsch bc2abd5cf3 Bluetooth: host: Fold consecutive calls to bt_rand into one
Calls to bt_rand can be expensive, folding consecutive calls into one
reduces the overhead.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-09-20 08:22:18 +03:00
Luiz Augusto von Dentz 4f3892c0eb Bluetooth: GATT: Use check_perm to check CCC permission
This moves check_perm code under GAT and make use of it to check if CCC
write permission can be attended by the connection security level or if
it needs to be increased.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-09-19 21:12:39 +03:00
Luiz Augusto von Dentz 03b9ce487c Bluetooth: GATT: Add support to setting permission on CCCD
This adds support to set different permissions to CCCD so security can
be checked when enabling notification which conforms to:

BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part G page 2360:

  '3.3.3.3 Client Characteristic Configuration

   Authentication and authorization may be required by the server to
   write the configuration descriptor.'

In addition to that also ensure that notification are not re-enabled
until the proper security level is reached to conform to the following
statement:

  '10.3.1.1 Handling of GATT indications and notifications

   A client “requests” a server to send indications and notifications
   by appropriately configuring the server via a Client Characteristic
   Configuration Descriptor. Since the configuration is persistent
   across a disconnection and reconnection, security requirements must
   be checked against the configuration upon a reconnection before
   sending indications or notifications. When a server reconnects to a
   client to send an indication or notification for which security is
   required, the server shall initiate or request encryption with the
   client prior to sending an indication or notification. If the client
   does not have an LTK indicating that the client has lost the bond,
   enabling encryption will fail.'

Fixes #17983

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-09-19 21:12:39 +03:00
Joakim Andersson ff2bd93eea Bluetooth: GATT: Add initializer for GATT CCC
Add GATT initializer macro for GATT CCC and allow the
BT_GATT_CCC_MANAGED to accept an already initialized CCC user data.
This allows the application to specify the storage location of the CCC
user data.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-19 14:08:12 +02:00
Luiz Augusto von Dentz 296f92276f Bluetooth: GATT: Fix not storing SC changes
CCC storaged is no longer declared separetly so check if ccc->cfg
matches with sc_ccc_cfg no longer works so instead use the cfg_changed
callback and match against sc_ccc_cfg_changed.

Fixes #19267

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-09-19 12:58:18 +02:00
Vinayak Kariappa Chettimada bfd393ac62 Bluetooth: controller: legacy: Ensure that a case statement is present
When compiling a sample like a beacon, none of the `if defined()`
statements in the switch case are actually compiled in, so the compiler
complains of an orphan mem_release();break; sequence.
Add a type that we know will always be compiled in in order to avoid
this issue.

Relates to commit 76bfea7cf9 ("Bluetooth: controller: Ensure that a
`case` statement is present").

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-18 20:56:43 +02:00
Johan Hedberg 73baaaa3dc Bluetooth: Pass local identity to bt_conn_add_le()
This makes the identity initialization consistent and actually catches
a few branches where it may not have properly happened.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-09-17 11:36:38 +03:00
Johan Hedberg 0ce7dad5b2 Bluetooth: Allow disconnected state connections to be reconnected
Make it possible to initiate new connections from within the
disconnect callback. This wasn't completely trivial since there was
connection cleanup done through deferred action using the CONN_CLEANUP
flag.

This patch moves the disconnected callbacks to be run after all
cleanup is done. We can't directly do this in the TX thread, since
that's internal, so we instead take advantage of the deferred work
support and do it using the update_work callback. Since the same
cleanup is needed also for BR/EDR connections the work definition is
moved from the LE-specific struct to the generic struct bt_conn.

A valid bt_conn object in disconnected state is a likely indication of
a connection reference leak, so there's a new BT_WARN() for this case
in bt_conn_create_le().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-09-17 11:36:38 +03:00
Trond Einar Snekvik b7d05fbf13 Bluetooth: Mesh: Add model reset callback
Adds additional model callback that gets called on node_reset. Will also
erase any user data when this happens.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-09-16 22:56:22 +03:00
Trond Einar Snekvik 91ca7ca763 Bluetooth: Mesh: Add persistent model user data
Adds user data file in the model settings, allowing each model instance
to store some application specific data without having to reinvent the
settings path encoding for model element/ID combinations. Exposes the
settings_handler interface in the model callback structure and adds a
data store function.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-09-16 22:56:22 +03:00
Trond Einar Snekvik c2c05c916a Bluetooth: Mesh: Add model callback structure
Adds a structure of callbacks for each model instance. This allows for
more flexible model implementations, that can interact with the Mesh
stack without going through the application.

For now, only an init callback is added, replacing the init mechanism in
the foundation models. The init callback does not provide the primary
flag that used to be in the foundation model callbacks, but replaces
this with an inline function in access.h.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-09-16 22:56:22 +03:00
Vinayak Kariappa Chettimada 28f46131b3 Bluetooth: controller: split: Fix Rx reserved for conn cmplt
When both central and peripheral are supported, one each Rx
node will be needed by connectable advertising and the
initiator to generate connection complete, hence
conditionally set the count.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-16 21:46:35 +02:00
Vinayak Kariappa Chettimada 78b461ae3e Bluetooth: controller: Refactor use of SWI
Refactor to abstract the use of software interrupts in nRF5
Series.

Also, reduce the number of SWI used when interrupt priority
level configured is same for ULL High and ULL Low contexts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-16 19:06:51 +02:00
Ioannis Glaropoulos ee85f248fc bluetooth: controller: abstract PPI handling for LE Coded
This commit completes the refactoring of radio.c, so it
calls abstract functions for PPI handling for LE Coded
PHY (e.g. enable, disable channels, or configure endpoints),
which, then, call the platform-specific functions for PPI
handling. The abstract functions are simple wrappers,
implemented in radio_nrf5_ppi.h, conditionally, if we
build the controller with support for LE Coded PHY.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-16 19:06:51 +02:00
Ioannis Glaropoulos f754ee4aa8 bluetooth: controller: conditionally define macros for LE Coded PHY
Make the definitions of LE Coded PHY-specific macros
and inline functions conditional, i.e. only if we
actually build the controller with support for LE
Coded PHY.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-16 19:06:51 +02:00
Ioannis Glaropoulos dc3e9b1755 bluetooth: controller: abstract PPI handling functions
This commit refactors radio.c, so it calls abstract functions
for PPI handling (e.g. enable, disable channels, or configure
endpoints), which, then, call the platform-specific functions
for PPI handling. The abstract functions are simple wrappers,
implemented in radio_nrf5_ppi.h.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-16 19:06:51 +02:00
Ioannis Glaropoulos d72d4f356d bluetooth: controller: define generic macros for LLL, ULL LOW IRQs
This commit defines generic macros for the software interrupt
(SWI) IRQ lines that are used for LLL and ULL LOW interrupts.
This is done for both the cases of the legacy and new (split)
controller architectures. In addition, it abstracts some of
the functionality around software-IRQ signals, to generic
functions, which have platform-specific implementations.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-16 19:06:51 +02:00
Trond Einar Snekvik 532241d5ad Bluetooth: Mesh: Encrypt friend packets on send
Stores friend queue packets unencrypted, removing any out-of-order
issues caused by seqnum allocation. Also moves as much of the metadata
storage as possible into the packet, allowing us to free up some bytes
of net_buf user data for friend packets.

Fixes #18488

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-09-16 14:00:57 +03:00
Trond Einar Snekvik 9e85c33239 Bluetooth: Mesh: Expose SeqZero mask
Makes a define for the seqzero 13-bit mask in transport, and exposes it
in the header for use in the friend module.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-09-16 14:00:57 +03:00
Kumar Gala 8ce0cf0126 kconfig: Convert device tree chosen properties to new kconfigfunctions
Convert how we get the various chosen properties like "zephyr,console"
to use the new kconfig functions like dt_chosen_to_label.

Because of how kconfig parses things we define a set of variables of the
form DT_CHOSEN_Z_<PROP> since comma's are parsed as field seperators in
macros.

This conversion allows us to remove code in gen_defines.py for the
following chosen properties:

zephyr,console
zephyr,shell-uart
zephyr,bt-uart
zephyr,uart-pipe
zephyr,bt-mon-uart
zephyr,uart-mcumgr
zephyr,bt-c2h-uart

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-09-13 11:42:34 -05:00
Kristoffer Rist Skøien c58af2b686 Bluetooth: Controller: Typo in Kconfig
Changed documentation in Bluetooth Controller
Kconfig for BT_CTLR_ASSERT_HANDLER

Signed-off-by: Kristoffer Rist Skøien <kristoffer.skoien@nordicsemi.no>
2019-09-10 08:32:02 -05:00
Mariusz Skamra ac7f81314e Bluetooth: ATT: Fix responding to unknown ATT command
Host shall ignore the unknown ATT PDU that has Command Flag set.
Fixes regression introduced in 3b271b8455.

Fixes: GATT/SR/UNS/BI-02-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-09-10 12:26:11 +03:00
Stephanos Ioannidis 9b0e738e37 bluetooth: controller: Explicitly include toolchain.h.
This commit adds an explicit inclusion of toolchain.h from pdu.h.

The endianness preprocessor definitions (__BYTE_ORDER__,
__ORDER_LITTLE_ENDIAN__, __ORDER_BIG_ENDIAN__) are used by pdu.h;
these being not defined can easily go unnoticed and cause unexpected
behaviours, as detailed in PR #18922.

toolchain.h ensures that these preprocessor definitions are defined and
*must* be included in a file that uses these definitions.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-09-09 21:40:54 +02:00
Johan Hedberg c333e8e8a4 Bluetooth: Mesh: Fix matching for "All Proxies" group address
The bt_mesh_fixed_group_match() function is intended to match the
various well-known group addresses, however it was never updated when
Proxy support was added.

Fixes #19015

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-09-09 13:03:47 +03:00
Trond Einar Snekvik 110332cad9 Bluetooth: Mesh: Make unicast elem lookup O(1)
As element addresses are sequential, there's no need for iterating
through the elements to find the one matching a unicast address.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-09-09 11:14:30 +03:00
Morten Priess d62ad4117c bluetooth: controller: Added function to support RX link quota update
Added ll_rx_link_inc_quota to allow vendor to manipulate
mem_link_rx.quota_pdu when cleaning up nodes via ull_vendor.h.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-09-08 12:39:09 +02:00
Vinayak Kariappa Chettimada a28eba9897 Bluetooth: controller: Fix data PDU leak during ctrl PDU defer
Fix a bug where in tx data PDU enqueued, while a ctrl PDU is
deferred due to Encryption setup being in progress, is
leaked causing HCI Tx Buffer Overflow crash.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-07 17:10:22 +02:00
Vinayak Kariappa Chettimada af5bcf354a Bluetooth: controller: Fix start encryption in progress check
Fix check in start encryption to disallow new encryption
setup while there is one already in progress.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-07 17:10:22 +02:00
Vinayak Kariappa Chettimada 7872b733d1 Bluetooth: controller: Fix Re-encryption procedure
Fix MIC failure on re-encryption procedure when responding
at the same time to peer initiated feature request.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-07 17:10:22 +02:00
Vinayak Kariappa Chettimada 46d5554664 Bluetooth: controller: Fix ENC_REQ PDU retransmission
Fix dropped ENC_REQ PDU when retransmitting, if slave was
not listening or nack-ed it.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-07 17:10:22 +02:00
Vinayak Kariappa Chettimada 6991d09977 Bluetooth: controller: Fix control tx queue handling
Fix control tx queue handling to correctly pause control PDU
responses during encryption setup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-07 17:10:22 +02:00
Vinayak Kariappa Chettimada 1d978e8856 Bluetooth: controller: Add data length procedure queueing
Added implementation to cache Data Length Procedure when
another control procedure is in progress.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-07 17:10:22 +02:00
Vinayak Kariappa Chettimada 2e365424f0 Bluetooth: controller: Defer encryption setup if in conn update
Workaround, defer peer initiated encryption while local
initiated procedure with instant is not complete. Peer
master has sent CONN_UPDATE_IND in response to
CONN_PARAM_REQ, and also has initiated a Encryption Setup
thereafter. In this case, avoid corruption of the connection
update context by deferring the Encryption Setup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-07 17:10:22 +02:00
Vinayak Kariappa Chettimada 3f695f7823 Bluetooth: controller: Fix cmd disallowed and collision disconnects
Fix implementation to correctly cache the control procedures
initiatable by local and peer. And, fix feature exchange and
version information procedures from being disallowed by
having then as cached requests to the controller.

Relates to #15256.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-07 17:10:22 +02:00
Joakim Andersson 0790fdf0d7 Bluetooth: host: Add bt_conn_foreach API to iterate all connections
Add iterator function to iterate over all connection objects.
Make type a bitmap so that it can be used as a bitmask to select which
conns to receive foreach callback.
Use foreach function internally where possible.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-07 15:53:26 +03:00
Trond Einar Snekvik b2463a7126 Bluetooth: Mesh: Move model_find to public header
Allows models to find each other without direct access to the
composition data.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-09-07 15:51:25 +03:00
Trond Einar Snekvik 9a3ff5cdff Bluetooth: Mesh: Add prov input_complete to shell
Notifies the user that the callback fired.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-09-07 15:51:09 +03:00
Trond Einar Snekvik c91d0646a6 Bluetooth: Mesh: Add prov input_complete cb
Allows the user to pass a provisioning input complete callback to the
provisioning module, letting the application stop displaying its output
OOB value when the other party finishes their OOB input.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-09-07 15:51:09 +03:00
Morten Priess fddd786dfe bluetooth: host: Configurable HCI stack sizes
Made BT_HCI_TX_STACK_SIZE configurable and added BT_HCI_ECC_STACK_SIZE.
These changes are necessary to allow vendors to adjust for other
achitectures.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-09-07 15:50:43 +03:00
Carles Cufi aa960c9d6e Bluetooth: log: Rework BT_ASSERT
Rework the BT_ASSERT infrastructure with the following changes:

- Transition from LOG() macros to printk()
- Allow the BT_ASSERT() macro to map directly to stancard __ASSERT()
- Allow printing of the assert reason to be disabled
- Switch from k_oops() to k_panic() configurable

There are 2 reasons for using printk() instead of LOG():

- BT_ERR uses deferred logging by default, which is problematic with
ASSERTs
- The __ASSERT() macro in Zephyr uses printk()

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-09-07 15:50:23 +03:00
Joakim Andersson 6d08a30838 Bluetooth: SMP: Add missing static to internal function
Add missing static to internal SMP function

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-07 15:49:34 +03:00
Joakim Andersson 361cbea9cd Bluetooth: SMP: Fix pairing using debug keys
Fix issue when checking if SMP pairing procedure is allowed to use the
SMP debug keys. This check did not consider the case where the keys
pointer was assigned, but did not contain a valid LTK key.
This resulted in being unable to pair with debug keys without an
existing bond.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-07 15:49:34 +03:00
Joakim Andersson 8f75cf732d Bluetooth: Shell: Fix shell build dependencies
Fix shell build dependencies, subsys/bluetooth/controller is only added
for CONFIG_BT_LL_SW_SPLIT or CONFIG_BT_LL_SW_LEGACY.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-07 15:48:35 +03:00
Joakim Andersson dcde30e5e4 Bluetooth: host: Handle return code of set_random_address
The return code of set_random_address is not always handled. This could
lead to connection using the wrong Identity address.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-07 15:48:17 +03:00
Ioannis Glaropoulos 1d45a2fe77 bluetooth: controller: minor fixes in inline comments
Several minor fixes to inline comments of #ifdef .. #endif
blocks.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-07 14:18:36 +02:00
Ioannis Glaropoulos 98356a14b7 bluetooth: controller: remove redundant header inclusions
nrf_timer.h and nrf_ppi.h are included by including
radio_nrf5.h, so we do not need to include them in
radio.c.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-07 14:18:36 +02:00
Vinayak Kariappa Chettimada 73bf27f243 Bluetooth: controller: split: Fix crash on terminate
Remove incorrect LL_ASSERT check in Lower Link Layer that
checked for invalid connection handle on reception of PDU.
The assert is not needed as PDUs can be received until the
Upper Link Layer is aware of the acknowledgement of the
terminate ind PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-03 13:56:12 +02:00
Joakim Andersson 6c2b7937c5 Bluetooth: Host: Workaround for controller advertising data bug
Add workaround for advertising data issue in the internal bluetooth
controller. The advertising data must be set after advertising
parameters in order to successfully update the advertising data after
an directed advertiser has been active.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-09-03 13:08:39 +02:00
Vinayak Kariappa Chettimada 0d766c668d Bluetooth: controller: split: Fix PDU handling on terminate
Fix handling of Rx-ed PDU on termination, do not process
Rx-ed control PDUs and release the PDU buffer back to the
free pool.

Without this fix, Rx-ed control PDU was responded with a
Tx PDU, which did not get acknowledged or released.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-31 17:04:29 +02:00
Akshatha Harishchandra 613655e91b bluetooth: host: Replaced bt_uuid_create_le with bt_uuid_create
Endianness bug fix in bt_uuid_create function.
Replaced bt_uuid_create_le with bt_uuid_create which
handles both UUID from air and internal varaiable.
Fixed bug with endianess in case of big endian targets.

Signed-off-by: Akshatha Harishchandra <akhr@oticon.com>
2019-08-30 12:42:24 +02:00
Luiz Augusto von Dentz 5ac014aac6 Bluetooth: ATT: Fix misleading warning
When an opcode doesn't have a handle that doesn't mean it is unknown
just that it will not be handle as it could have been disabled.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-30 09:52:01 +02:00
Luiz Augusto von Dentz ac02b30923 Bluetooth: Don't run SMP callbacks on syswq
SMP shall be considered internal TX notify callbacks so they are
allowed to be run from TX thread context like the others.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-30 09:52:01 +02:00
Luiz Augusto von Dentz 5d0c6fe562 Bluetooth: ATT: Use timeout when allocating a buffer
Whenever responding or confirming use the ATT timeout to allocate a
buffer.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-30 09:52:01 +02:00
Luiz Augusto von Dentz 3b271b8455 Bluetooth: ATT: Fix att_op_get_type when client is disabled
When CONFIG_BT_GATT_CLIENT is not set att_op_get_type would return
unkown operation instead of properly return the opcode.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-30 09:52:01 +02:00
Luiz Augusto von Dentz 68bfd1422e Bluetooth: L2CAP: Fix invalid access if a buffer cannot be allocated
Since bt_l2cap_create_pdu can return NULL when used under syswq context
the code should always check its result, this also changes the timeout
to have a specific value (RTX maximum timeout) so signalling PDUs still
wait for a buffer to become available.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-30 09:52:01 +02:00
Luiz Augusto von Dentz 6a71ebf6c5 Bluetooth: SMP: Fix invalid access if a buffer cannot be allocated
In certain cases there could be no buffer available which may lead to
NULL being returned by bt_l2cap_create_pdu so instead use
bt_l2cap_create_pdu_timeout to wait with a specific timeout.

Note that this should also ensure the SMP will not be waiting for a
buffer when the remote might have timed out already.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-30 09:52:01 +02:00
Luiz Augusto von Dentz 1af31671e3 Bluetooth: conn: Add bt_conn_create_pdu_timeout
This adds bt_conn_create_pdu_timeout function which can be used
to provide a timeout when allocating a buffer.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-30 09:52:01 +02:00
Wolfgang Puffitsch e8e668ae9c Bluetooth: controller: Fix endianness for length update.
Fix endianness when accessing length update parameters in PDU.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-08-28 13:03:39 +02:00
Vinayak Kariappa Chettimada 3f894250ef Bluetooth: controller: Fix Enc setup reset on rejection
Fix reset of Encryption Procedure state on reception of
REJECT_IND and REJECT_EXT_IND.

This is a regression in commit 79cb615770 ("Bluetooth:
controller: split: Port Enc setup to be queueable")

Relates to #18578.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-28 12:07:40 +02:00
Vinayak Kariappa Chettimada 385b82dcef Bluetooth: controller: split: Fix data pause on Enc Req enqueue
Fix the controller implementation to handle data packet
enqueue being pause on Encryption Request be done early in
the ULL when enqueueing packets towards LLL.

Fixes #18645.

Signed-off-by: Vinayak Kariappa Chettimada <vinayak.chettimada@gmail.com>
2019-08-27 15:13:38 +02:00
Joakim Andersson 3320b51644 Bluetooth: Host: Rename long error codes
Rename AUTHENTICATION, to AUTH, since this is a well established short
form of the word.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-27 15:13:25 +02:00
Joakim Andersson 3e9888105e Bluetooth: Host: Rename API function to initiate bluetooth security.
Rename bt_conn_security to bt_conn_set_security, this makes the API
naming more consistent.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-27 15:13:25 +02:00
Joakim Andersson 1c48757d94 Bluetooth: Host: Rename security level enum
Rename security level enum, using level and number instead of low,
medium, high and fips.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-27 15:13:25 +02:00
Johan Hedberg b763a9be3a Bluetooth: Host: Fix checking for sufficient encryption key size
A security vulnerability in the Bluetooth BR/EDR Bluetooth Core
specification versions 1.0 through 5.1 has been identified as
CVE-2019-9506. The Bluetooth BR/EDR encryption key negotiation
protocol is vulnerable to packet injection that could allow an
unauthenticated user to decrease the size of the entropy of the
encryption key, potentially causing information disclosure and/or
escalation of privileges via adjacent access. There is not currently
any knowledge of this being exploited.

From Core spec erratum 11838:

A device shall enforce an encryption key with at least 128-bit
equivalent strength for all services that require Security Mode 4,
Level 4. For all other services that require encryption, a device
should enforce an encryption key with at least 56-bit equivalent
strength, irrespective of whether the remote device supports Secure
Simple Pairing.

After encryption has been enabled, the Host should check the
encryption key size using either the HCI_Read_Encryption_Key_Size
command (see [Vol 2] Part E, Section 7.5.7) or a vendor-specific
method.

Fixes #18658

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-27 14:53:18 +03:00
Johan Hedberg 7d29296047 Bluetooth: Host: Fix failure handling with security level change
In case sufficient security level wasn't reached the error propagation
was missing, which could lead to incorrect state transitions when
update_sec_level_br() returns. Return true/false and make sure to
abort any further operations in case the update fails.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-27 14:53:18 +03:00
Asbjørn Sæbø 56e6b99a69 Bluetooth: Add log_strdup() to BT_ERR string arguments
Wrap string arguments to BT_ERR in log_strdup().

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
2019-08-27 14:02:01 +03:00
Joakim Andersson d2c1da1335 Bluetooth: Host: Fix invalid pointer in bt_smp_pkey_ready
The storage for the public key is pub_key in hci_core.c.
When the public key event is generated the public key is copied into
this buffer, but the pointer to the event storage of the key is given
in the public key ready callback (bt_smp_pkey_ready).
SMP expects that it is safe to assign a global pointer to this variable.
In smp_init bt_pub_key_get is used to get the pointer to the public key.
In both cases SMP assigns the le_sc_pub_key to the pointer given.

This creates an issue when bt_smp_pkey_ready callback occurs after
smp_init during pairing procedure, SMP will then have a pointer to an
event buffer that has been released and contains invalid data.

Fixes: #18580

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-27 13:05:08 +03:00
Joakim Andersson 05354129e7 Bluetooth: SMP: Give security changed when rejecting LTK
Give the security changed callback when the peripheral initiated
security request and peer attempted to encrypt the connection but no LTK
match was found.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-26 13:12:49 +02:00
Joakim Andersson 545f090d8b Bluetooth: Shell: Add pairing failed and complete to OOB handling
Add pairing failed and complete callback to OOB authentication handlers.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-26 13:12:49 +02:00
Joakim Andersson b35075d595 Bluetooth: SMP: Re-pairing cannot lower the security level of the bond
Make sure that a new pairing procedure with an existing bond does not
result in a security with weaker security properties.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-26 13:12:49 +02:00
Joakim Andersson bc19e241f9 Bluetooth: Shell: Add force-pair option to bt security command
Add shell argument to use bt_conn_security force pairing functionality.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-26 13:12:49 +02:00
Joakim Andersson 128cf42d8a Bluetooth: Host: Add option to force pairing in bt_conn_security
Add option to force the host to initiate pairing procedure even if the
host has encryption keys for the peer.
This option can be used to pair with a bonded peer that has deleted its
bonding information without deleting the keys. If new pairing results
in weaker keys the pairing will be aborted.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-26 13:12:49 +02:00
Joakim Andersson 6d4b842a10 Bluetooth: Host: Add error to security changed callback
Add security error to security_changed callback. Call this callback when
security has failed and provide current security level and error.
Reason for failure can be.
 - Pairing procedure failed, pairing aborted before link encryption.
 - Link encrypt procedure failed
 - Link key refresh procedure failed.

Fix missing bt_conn_unref on encryption key refresh with error status.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-26 13:12:49 +02:00
Joakim Andersson f1c7371494 Bluetooth: SMP: Stop new pairing early if MAX_PAIR has been reached
Stop the pairing procedure in the request phase if no storage is
available for the keys. This avoids the pairing procedure from failing
during the key distribution phase.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-26 13:12:49 +02:00
Joakim Andersson 3263f93747 Bluetooth: host: Pairing callback fail and complete for SSP
Proved the Authentication callback for pairing failed and pairing
complete when BR/EDR SSP is complete.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-26 13:12:49 +02:00
Joakim Andersson 1fb68828ef Bluetooth: SMP: Add pairing failed reason
Forward the pairing failed SMP status code to the application

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-26 13:12:49 +02:00
Joakim Andersson a378498fdc Bluetooth: SMP: Add option to treat debug keys normally during debugging
Allow SMP debug keys to behave in the same way as normal keys, in order
to debug with encryption and Bluetooth sniffer the exact way it behaves
when not using debug keys.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-26 13:12:49 +02:00
Erik Brockhoff a4bd5b6835 bluetooth: controller: Fixing race re. adv disable in HDC
Re. issue "BT LL assert on LL/CON/ADV/BV-04-C #18584"

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2019-08-23 18:26:13 +02:00
Vinayak Kariappa Chettimada 1751648db0 Bluetooth: controller: split: Fix Enc setup reset on rejection
Fix reset of Encryption Procedure state on reception of
REJECT_IND and REJECT_EXT_IND.

This is a regression in commit 79cb615770 ("Bluetooth:
controller: split: Port Enc setup to be queueable")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-22 16:40:46 +02:00
Johan Hedberg 71d00c1bf8 Bluetooth: Mesh: Fix publication period timestamp initialization
The period_start timestamp wasn't getting properly initialized in the
case that retransmission was not being used. In the case of
retransmission the timestamp was getting updated in the mod_publish()
delayed work callback. Add a send_start callback and do the
initialization there, since this covers both the retransmission as
well as the no-retransmission cases.

Fixes #17820

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-22 17:28:19 +03:00
Vinayak Kariappa Chettimada 73f0fa3727 Bluetooth: controller: split: Tx cleanup and comments
Post Tx pool corruption fix, clean up code and add comments
explaining the use of Tx node next field used to indicate
the Tx node's allocation from Control or Data pool.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-22 14:34:04 +02:00
Vinayak Kariappa Chettimada bdcec8418f Bluetooth: controller: split: Fix Tx FIFO, queue, and pool corruption
Fix the Tx FIFO, queue and pool corruption due to missing
release of link object to Tx link pool and hence missing
reset of the per connection initially allocated Tx link
free pointer.

The bug caused Tx PDUs and associated memory to be lost
leading to missing L2CAP segment transmissions. With lost
control PDU buffers, ULL would stall processing Done events
also leading to controller asserts.

Fixes #18546.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-22 14:34:04 +02:00
Luiz Augusto von Dentz 5f3595e47c Bluetooth: GATT: Fix using variable size storage for CCC
This removes the necessity of registering the storage for CCC and make
it part of the declaration itself.

Fixes #18547

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-22 15:14:39 +03:00
Luiz Augusto von Dentz cee271968e Bluetooth: GATT: Add support for indicating by UUID
This adds support to provide an UUID to bt_gatt_indicate so API user
don't need to hardcode the attribute offset by hand.

Fixes #18572

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-22 15:14:39 +03:00
Tobias Svehagen 9f2d364414 Bluetooth: Mesh: Remove dependency on BT_MESH_IV_UPDATE_TEST in shell
Only enable the IV update commands when CONFIG_BT_MESH_IV_UPDATE_TEST
is defined.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-08-22 13:13:29 +02:00
Johan Hedberg 6de5b79f9c Bluetooth: Mesh: Fix discarding messages with many segments
The code for checking space in the Friend queue was faulty in the case
that we receive a message with more segments than the configured Friend
Queue size. This is not an issue for the default configuration but
still a possible one. Move the check for exceeding Friend Queue Size
to the per-LPN function, so that bt_mesh_friend_queue_has_space()
iterates all LPNs before delivering its verdict. This allows us to
return success in case no LPN matched (which is how the code was
intended to work).

Fixes #18522

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-20 21:24:09 +03:00
Vinayak Kariappa Chettimada 07460176ed Bluetooth: controller: split: Fix control flow issues
This fixes reported Coverity CID 203393 control flow issues.

Fixes #18381.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-20 14:17:26 +02:00
Trond Einar Snekvik 7d472c3c38 Bluetooth: Mesh: Use define for no prov pdu
Adds a prov PDU type define for cases when no PDU is expected.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-08-19 18:47:41 +03:00
Trond Einar Snekvik d408f4afe5 Bluetooth: Mesh: Prov confirm tx after confirm rx
According to Mesh Profile Specification 1.0.1 Figure 5.17, the
unprovisioned device should send its confirmation value after the
provisioner sends theirs. Previously, the confirmation value would be
sent immediately after OOB input complete. Now it first waits for the
input data, then from confirmation from the provisioner before sending
the confirmation.

Fixes: #18178.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-08-19 18:47:41 +03:00
Johan Hedberg 8aba96b772 Bluetooth: Mesh: Fix adhering to the configured Friend Queue size
Qualification test case MESH/NODE/FRND/FN/BV-08-C requires that we do
not store more messages than the reported Friend Queue size. The
implementation was so far opportunistic and stored more if it could
(it would later discard if necessary to make sure all queues can store
the required amount). The spec also requires the queues to have new
messages overwrite old ones (in the style of a circular buffer), so we
have to keep track of which buffers are part of the same segmented
message (so we discard all buffers belonging to the same message).

To pass the test case, add APIs to check for space in the Friend
queue, and track the number of buffers for each incoming segmented
message.

Fixes #18090

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-19 16:30:31 +03:00
Johan Hedberg e613b6e61b Bluetooth: Mesh: Remove unused code
The bt_mesh_trans_resend() function had no users, and had in fact not
even a prototype in a header file. Just remove it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-19 16:30:31 +03:00
Johan Hedberg 81effc053b Bluetooth: Mesh: Fix missing call to send_cb_finalize
When sent solely to the Friend Queue the send callbacks were not
getting called for unsegmented messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-19 16:30:31 +03:00
Luiz Augusto von Dentz 2f91f1323d Bluetooth: GATT: Remove dead code
This fixes the dead code when parsing Find Information response since
the index counter can never be zero, instead it checks there are any
attributes found and if there nothing don't proceed with discovering
which was the original intent of the now dead code.

Fixes #18384

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-19 13:09:26 +02:00
Morten Priess 69ff0f310e bluetooth: controller: Fix for uninitialized data compile error
Due to conditional compile path ending in LL_ASSERT(0), the compiler
sees code following the assert as using uninitialized variables.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-08-19 13:05:19 +02:00
Morten Priess c635f4cb6d bluetooth: controller: Fix for coverity CID 203524
Fixes coverity issue: [Coverity CID :203524] Incorrect expression in
/subsys/bluetooth/controller/ticker/ticker.c #18382

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-08-19 11:26:20 +02:00
Luiz Augusto von Dentz 692d7d523e Bluetooth: GATT: Fix not clearing out of sync flag
When the database changes and a client becomes change unware it should
also clear the out of sync flag as the following request should return
an error:

Core Spec 5.1 | Vol 3, Part G, 2.5.2.1 Robust Caching:

  'The error response 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 error
  response shall be sent again.'

Fixes: #18183

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-16 20:47:40 +03:00
Luiz Augusto von Dentz 67a2ae53ae Bluetooth: GATT: Fix assert when storying CCCs
This fixes the following crash:

ASSERTION FAIL [0] @ ZEPHYR_BASE/subsys/logging/log_core.c:180
	argument 2 in log message "%s: Stored CCCs for %s (%s)"
	missing log_strdup().

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-16 20:47:40 +03:00
Joakim Andersson c19dac1a66 Bluetooth: Host: Fix unable to connect using host resolution
Fix issue unable to connect to bonded peer when host resolution is used
either because the controller does not support privacy, or the
controller resolving list was exceeded.
In this case we need to use the RPA from the advertising report
directly, there is a small chance of the peer cycling the RPA here, in
which case the connection might be unsuccessful.

Bug introduced here: 45da629b24

Fixes: #18306

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-16 15:46:46 +03:00
Carles Cufi cb700d0e12 Bluetooth: controller: Disable AE by default
Disable Advertising Extensions by default, since they are not really
operational and they take RAM.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-08-15 15:07:12 +02:00
Carles Cufi 76bfea7cf9 Bluetooth: controller: Ensure that a case statement is present
When compiling a sample like a beacon, none of the `if defined()`
statements in the switch case are actually compiled in, so the compiler
complains of an orphan mem_release();break; sequence.
Add a type that we know will always be compiled in in order to avoid
this issue.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-08-15 15:07:12 +02:00
Rich Barlow 5d5706e785 Bluetooth: Mesh: LPN: Remove msg from cache on rejection
When in Low Power mode an LPN may receive messages sent by nodes other
than its friend during its brief receive window. These messages get
rejected by the transport layer. At some point in the future the LPN
will receive these messages from its friend, however they will have
already been added to the network message cache earlier.

When the transport layer rejects a message due to it being received from
a non-friend node while in Low Power mode it must be removed from the
network message cache so that it can be correctly received from its
friend in the future.

Fixes #17809

Signed-off-by: Rich Barlow <rich@bennellick.com>
2019-08-15 13:24:17 +02:00
Vinayak Kariappa Chettimada 5d30d49f88 Bluetooth: controller: Fix ifdef block comment
Fix a minor incorrectly commented ifdef block.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-15 11:53:59 +02:00
Johan Hedberg 286a59c8b5 Bluetooth: Mesh: Fix reference count imbalance in bt_mesh_net_resend()
The commit 1c7b668804 tried to fix
resending segments to the GATT bearer, however it got the buffer
refernce counting wrong. The bt_mesh_net_resend() function doesn't
own a reference to the buffer, i.e. it's not responsible for unrefing
it. E.g. bt_mesh_adv_send() takes its own reference.

What was missing however was the handling of the callbacks. Use the
recently introduced send_cb_finalize() helper to make sure they're
called.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-15 11:53:10 +02:00
Johan Hedberg 104d30c989 Bluetooth: Mesh: Introduce a helper for send callback finalization
There are several places that require the send callbacks to be called
immediately. Reduce the code a bit by introducing a helper for this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-15 11:53:10 +02:00
Joakim Andersson a62f609cd9 Bluetooth: Host: Set Kconfig RPA timeout in controller
Use the RPA timeout provided by Kconfig in the controller

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-15 11:50:25 +02:00
Joakim Andersson d94da73a19 Bluetooth: Host: Fix RPA timer not running
The RPA timer should always be running, even with privacy supported by
the controller. In order to select an IRK to generate the private
the controller is instructed by provided an identity address.
If we want to advertise privately without providing an identity address
the host has to set the private address.

Fixes: #18150

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-15 11:50:25 +02:00
Johan Hedberg 59ba9a1156 Bluetooth: Mesh: Fix starting IV Update when not on primary subnet
The Mesh Profile Specification states in section 3.10.5 IV Update
procedure: "The IV Update procedure is initiated by any node that is a
member of a primary subnet", meaning if we're not on the primary
subnet we should not try to initiate the procedure.

Additionally this fixes initiating IV Update in all cases where the
sequence is updated, by putting the code into bt_mesh_next_seq().

Fixes #17977

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-14 16:27:22 +02:00
Johan Hedberg a43ef332ec Bluetooth: Mesh: Fix canceling publication retransmission timer
This branch is inherited from old code that used to start the timer as
soon as a message was queued for transmission rather than when it was
actually transmitted (the case today). It'll also cause a race in case
the publication goes over the GATT layer since the "sent" callback
happens synchronously in that case.

Fixes #17821

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-14 14:56:26 +02:00
Johan Hedberg 1c7b668804 Bluetooth: Mesh: Fix resending segments on correct bearer
The GATT bearer is a reliable one so there should theoretically never
be a need to resend segments. If however for some strange reason the
proxy client doesn't immediately ack all segments we should do the
resending on the GATT bearer, rather than sending them over
advertising.

Fixes #17907

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-14 14:50:36 +02:00
Johan Hedberg 680d778f57 Bluetooth: Mesh: Fix not sending all segments through the Friend Queue
The code was incorrectly bailing out with "return 0" rather than
continue. Also, it was incorrectly making a reference to
tx->seg[seg_o] since when a PDU goes through the friend queue we don't
use the usual retransmission mechanism.

Fixes: #17932

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-14 14:49:43 +02:00
Johan Hedberg 5f6043bc35 Bluetooth: Mesh: Fix canceled buffer memory leak
In case a queued buffer is canceled before sending we have to unref
it, since that's what adv_send() would do as well.

Fixes #17936
Fixes #18013

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-14 14:49:43 +02:00
Johan Hedberg 94fcb211de Bluetooth: Mesh: Fix heartbeat sending on Friendship established/lost
Mesh Profile 3.6.7.2 Publishing Heartbeat messages:

"
Triggered publishing of Heartbeat messages is enabled by
the Heartbeat Publication Features state (see Section 4.2.17.5):
...
- If the Low Power bit is set to 1, a Heartbeat message shall be
 published when the node establishes or loses Friendship (see Section
 3.6.6.1).
"

Fixes #18194

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-14 14:48:37 +02:00
Johan Hedberg 39edab1013 Bluetooth: Mesh: Fix checking for active heartbeat publication
When sending heartbeat messages triggered by feature changes the code
was trying to look up the configured publication subnet, in an
apparent attempt to figure out if publication is enabled or not. A
more appropriate way is to check for the heartbeat publication
destination address, and since we have a helper function this can be
done in a single place.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-14 14:48:37 +02:00
Johan Hedberg ed71fc9a9e Bluetooth: Mesh: Move heartbeat sending to transport layer
The heartbeat is a transport layer feature, so move it to transport.c.
This also opens the way to properly fix Friendship-established/lost
triggering for LPN role.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-08-14 14:48:37 +02:00
Joakim Andersson 1691e0a699 Bluetooth: Host: fix missing interval_min copy
Fix missing interval min copy in bt_conn_set_param_le. Application is
unable to override BT_GAP_INIT_CONN_INT_MIN for interval_min.

Fixes: #17789

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-14 12:04:26 +02:00
Peter Bigot 5412409781 include/bluetooth: rearrange for standard use of extern "C"
Consistently place C++ use of extern "C" after all include directives,
within the negative branch of _ASMLANGUAGE if used.

Background from issue #17997:

Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.

Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.

See: https://en.cppreference.com/w/cpp/language/language_linkage
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-08-13 18:00:31 +02:00
Vinayak Kariappa Chettimada 3e0e378dca Bluetooth: controller: split: Fix pipeline for continuous events
Fix the pipeline prepare-resume implementation to correctly
handle multiple continuous events that request resume on
being pre-empted.

Symptoms of the bug being, when having continuous scanning,
and an active peripheral if a directed advertising is
started the peripheral event are not scheduled causing link
supervision timeout.

This is fixed by not having an enqueued resume event
prepared if there is an enqueued new non-resume event in the
pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-11 16:42:52 +02:00
Vinayak Kariappa Chettimada d90f3db3bc Bluetooth: controller: split: Increase pipeline size
Increase pipeline size to accommodate probable multiple
prepare for directed advertising events, with reserved time
which are shorter than prepare duration, being enqueued.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-11 16:42:52 +02:00
Vinayak Kariappa Chettimada e4ae7b8818 Bluetooth: controller: split: Increase event start overhead time
Increase the event start overhead time to accommodate for
processing time for dequeueing pipeline in Upper Link Layer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-11 16:42:52 +02:00
Vinayak Kariappa Chettimada f6799ff57e Bluetooth: controller: split: Reduce event done queue size
Reduce the maximum number of pending event done elements by
decoupling it from the maximum pipeline elements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-11 16:42:52 +02:00
Luiz Augusto von Dentz b563f4440a Bluetooth: Dispatch internal callbacks using RX thread
This is safer now that bt_conn_create_pdu can return NULL when using
syswq which can prevent things like signalling of L2CAP and ATT layers.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-09 21:01:59 +02:00
Luiz Augusto von Dentz 6b0242cfeb Bluetooth: Fix deadlock caused by blocking on syswq
Since TX complete notification are dispatched with syswq blocking on it
can completely deadlock Bluetooth so this attempt to make it safe by
return -ENOMEM if that the current thread happens to be the syswq
thread.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-09 21:01:59 +02:00
Luiz Augusto von Dentz 4244b320e7 Bluetooth: conn: Warn when blocking with K_FOREVER
If debug is enabled print warnings when a call with K_FOREVER would have
blocked.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-09 21:01:59 +02:00
Joakim Andersson 513244afe2 Bluetooth: Shell: Add whitelist commands to shell
Add shell commands to add and remove devices from the shell.
Add commands and options to use whitelist for advertising, scanning,
and creating connections.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-09 16:26:10 +02:00
Joakim Andersson a463d117f6 Bluetooth: Host: Add whitelist support in Bluetooth Host API
Add whitelist support in the bluetooth host.
Supported features:
 - Advertising with whitelist on scan requests, connect request ,or both
 - Scanning with whitelist
 - Creating connections using a whitelist (Auto connection procedure).

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-09 16:26:10 +02:00
Joakim Andersson 0307f6cd83 Bluetooth: Host: Improve shell OOB handling
Add authentication method using only OOB authentication data.
Add command to clear OOB data.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-09 11:20:31 +02:00
Joakim Andersson a2531e1622 Bluetooth: SMP: MITM security possible without IO when OOB data present
Allow Security level HIGH and FIPS to be initiated when we have received
OOB data for the remote device. The security property of MITM is allowed
if out of band authentication data is available.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-09 11:20:31 +02:00
Joakim Andersson 835b1c1425 Bluetooth: Shell: Update sec level help text and validate input
Update bluetooth help text to include FIPS level in help text.
Also validate input range for the different connection types
Bluetooth security level for LE is from 1-4, while BR/EDR is 0-3

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-09 11:20:31 +02:00
Joakim Andersson e242c250c4 Bluetooth: Shell: Use on-air addresses when checking for OOB data
Authentication using OOB data uses the on-air device addresses used
during connection setup. So we need to check against the on-air
addresses in the info object to see if we have correct OOB data.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-08 15:49:19 +02:00
Joakim Andersson 90706a8217 Bluetooth: shell: Handle error code of bt_conn_auth_cb_register
Fix issue with registering authentication callback handlers failing
without notifying the user of the shell.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-08 15:49:19 +02:00
Joakim Andersson 7f1e67ba75 Bluetooth: shell: Add info command to print connection information
Add command to print connection info object.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-08 15:49:19 +02:00
Joakim Andersson 54d9ae45a5 Bluetooth: Host: Add identity addresses to conn info object
Use the src and dst naming to refer to the identity addresses of the
connection. Keep the device addresses used during connections but rename
them to local and remote instead.
Update documentation to be more descriptive.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-08 15:49:19 +02:00
Ulf Magnusson 5ef7eea6e2 Bluetooth: GATT: Kconfig: Remove redundant BT_CONN dependencies
subsys/bluetooth/host/Kconfig.gatt is already sourced within an
'if BT_CONN' in subsys/bluetooth/host/Kconfig.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-08 11:54:46 +02:00
Vinayak Kariappa Chettimada 857bcd96bd Bluetooth: shell: Fix directed adv parameter check
Fix the mandatory and optional parameter counts for the
directed adv shell command definition. Also, refactor the
command for consistency.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-08 11:33:51 +02:00
Joakim Andersson 50b28c010d Bluetooth: controller: Fix assert in RPA timeout for advertiser
Fix assert in the RPA timeout when no resolving entry exists in the
resolving list, and the advertiser was requested to use a local IRK
to generate it's own address.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-07 20:49:49 +02:00
Joakim Andersson 16c24ea8d2 Bluetooth: SMP: Use error code for OOB data not available
If no callback for oob data request is registered, or the user decided
to abort authentication during OOB data request, we should return the
error code for no OOB data available to indicate that the user does not
have the correct OOB, or no OOB interface at all.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-07 18:32:32 +02:00
Joakim Andersson a80ab8bcf6 Bluetooth: SMP: Fix kernel crash if auth handler is NULL
Fix kernel crash if bluetooth authentication handlers has not been
registered. The bt_auth object is then NULL, this dereference caused a
call to an invalid function pointer.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-07 18:32:32 +02:00
Mariusz Skamra 83b50f6bee Bluetooth: Mesh: Fix rejecting invalid remote public key
The code was already rejecting the key, however that rejection
happened only after we had already sent our public key as response,
which got interpreted as acceptance by the tester (PTS).

This fixes issue that d4fd267086a56c270a793114e7575afae9a9befa
supposed to fix. The problem is bt_dh_key_gen is async.
Local public key cannot be sent from the same context
the bt_dh_key_gen is called because we don't know yet
if remote key is valid.

Fixes MESH/NODE/PROV/BI-13-C.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-08-07 17:13:32 +02:00
Krzysztof Chruscinski b785ded9fa bluetooth: host: Fix Kconfig error
Fixed error 'The int symbol BT_DISCARDABLE_BUF_COUNT is being evaluated
in a logical context somewhere'.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-08-07 16:12:29 +02:00
Ulf Magnusson b5b7853ad9 Bluetooth: L2CAP: Kconfig: Remove redundant BT_CONN dependency
subsys/bluetooth/host/Kconfig.l2cap is already sourced within an
'if BT_CONN' in subsys/bluetooth/host/Kconfig, so BT_DEBUG_L2CAP does
not need a 'depends on BT_CONN'.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-08-07 16:51:02 +03:00
Kim Sekkelund 87c3db9e0b Bluetooth: Host: Find by type should accept 128bit UUIDs
Find by type does only accept a UUID with the same length as the UUID
which is stored in the internal list. If a UUID is stored in the short
16 bit format then a request with 128 bit UUID will fail.
Add support for the missing formats.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2019-08-07 15:39:11 +02:00
Morten Priess 3a9173afe1 bluetooth: controller: Revised ticker for improved conflict resolution
Changed ticker behavior to resolve conflicts in ticker_worker instead of
in ticker_job. This allows better real-time slot allocation, as well as
allowing callbacks even if ticker node doesn't get air-time (for audio
stream housekeeping). A priority property now also allows prioritizing
one ticker node over others.
Compatibility mode enables lagacy ticker behavior if needed.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-08-07 13:52:48 +02:00
Joakim Andersson ccbb18c9ac Bluetooth: SMP: Fix SMP identity distributing IRK for ID 0 always
Fix an issue in the SMP identity distribution where the IRK for the
default identity was always distributed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-06 19:47:27 +02:00
Joakim Andersson bd89cc3f4d Bluetooth: Controller: Fix privacy advertiser connect peer address type
Fix an issue with enhanced connection complete event raised by the
advertiser role. The advertiser reported that it has resolved the
the identity address of the peer, even when the peer is connecting
using it's identity address.
The host will not have the correct on-air address type i.e public.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-06 14:53:33 +02:00
Joakim Andersson 699436a3b6 Bluetooth: Host: Fix bug in creating connection with wrong own address.
Fix bug introduced by: 45da629b24
Mistakenly set the own address type to the destination address type.
Also this uses the RPA_OR_RANDOM in case local IRKs exists in the
controller.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-06 14:28:17 +02:00
Mariusz Skamra 7c60300753 Bluetooth: Shell: Fix unregister GATT Metrics vendor service
The 'registered' flag was not cleared when 'gatt metrics off'
was called so that one was unable to register the service again.
Remove 'registered' variable that is actually not needed as there
is no tracking if service is already registered in similar
cmd_register_test_svc command. If the service is already registered,
the host will log an error.

Fixes: #17882
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-08-05 21:50:41 +02:00
Joakim Andersson 45da629b24 Bluetooth: Host: Fix wrong init address when controller resolved address
The init addr should contain the on-air address used to establish the
connection. The dst address contains either the current RPA of the
unknown peer, or the identity address after identity information has
been exchanged.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-05 12:18:46 +02:00
Joakim Andersson c1a754f665 Bluetooth: Host: Print error codes in hex
Error codes are listed in header files and in the core spec as hex
values. Always print them in hex in debug for easier error code
checking.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-05 12:18:17 +02:00
Joakim Andersson 2b84c726c8 Bluetooth: Settings: Fix generated identity not persistently stored.
Fix an issue where the generated identity was not permanently stored.
This resulted in being unable to reconnect after bonding when using
privacy, since a new local IRK was generated on reboot.

When settings is enabled the application is responsible for loading
identities and possible creating its own identities.
When settings_load is called and no identities has been created or found
in persistent storage a new identity will be created.
Since bt init has not been finalized bt_id_create will not make a call
to bt_settings_save_id. So we need to make sure that this identity will
be stored.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-05 11:00:57 +02:00
Joakim Andersson 7f757e64d3 Bluetooth: Host: Move BT_DBG out of irq_lock
Don't have BT_DBG inside of irq_lock, this will create unnecessary IRQ
delays.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-31 17:07:50 +02:00
Joakim Andersson 1555ae8f38 Bluetooth: Keys: Fix logging assertions when enabling BT_DEBUG_KEYS.
Logging module requires strings to be duplicated using log_strdup.
Enabling CONFIG_BT_DEBUG_KEYS caused runtime assertions in the logging
module.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-31 16:48:54 +02:00
Mariusz Skamra a56695db9a Bluetooth: GATT: Fix byte order for database hash
Core 5.1, Vol 3, Part F, 3.3.1
"Multi-octet fields within the GATT profile shall be sent least
significant octet first (little-endian) with the exception of the
Characteristic Value field. The Characteristic Value and any fields
within it shall be little-endian unless otherwise defined in the
specification which defines the characteristic."

Fixes: GATT/SR/GAS/BV-02-C
Fixes: #17857
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-07-31 15:25:06 +02:00
Vinayak Kariappa Chettimada 09c1c9e800 Bluetooth: controller: Decorrelate address generation from resolution
Changes related to Bluetooth TSE 11068.

This is done because the current test suite does not issue
an LE Enable Address Resolution command anymore in RPA
generation tests. Makes sense now that the Bluetooth SIG has
agreed to completely decouple address resolution from
generation.

Fixes BT LL TS 5.1.0 test:
LL/SEC/ADV/BV-03-C [Privacy - Non-connectable Undirected
Advertising, Resolvable Private Address]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-31 15:22:49 +02:00
Joakim Andersson c2ee00f737 Bluetooth: SMP: Fix peripheral security request with authenticated keys
The call to bt_conn_security will send a SMP security request for
peripheral, and for central it will initiate LL encryption.
A call to bt_conn_security with no IO capabilities but authenticated
keys has been distributed, would succeed on central side, but fail on
peripheral side with error code -22.

The keys could have been either:
 - Preprogrammed
 - IO capabilities may have changed.
 - OOB bonding may been used.

Fix so that Peripheral can send a security request if the bond
information is already established.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-31 14:24:10 +02:00
Findlay Feng 0ea07d3072 bluetooth: Fix an undefined behavior
The original creates a pointer to a compiler-generated temporary that is
destroyed when the scope is exited. The pointer is stored in a structure
defined in an enclosing scope and is invalid by the point it's used.

The fix holds the structure in a variable with the same lifetime as
the pointer.

Signed-off-by: Findlay Feng <i@fengch.me>
2019-07-31 12:15:36 +03:00
Vinayak Kariappa Chettimada 20ccdab445 Bluetooth: controller: split: Fix pipeline prepare/resume loop
Fix the pipeline prepare or resume dequeue loop from
overflow. Fixes premature exit of dequeue of done FIFO
which caused the pipeline to overflow due to previously
placed done is not dequeued correctly and next event not
being put back into the pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-30 12:57:02 +02:00
Luiz Augusto von Dentz 29782a006b Bluetooth: GATT: Use atomic_t for subscribe flags
This makes use of atomic_t helpers to set, test and clear flags.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-07-29 12:26:18 +02:00
Luiz Augusto von Dentz 219bb6fe1f Bluetooth: GATT: Fix not canceling on unsubscribe
This introduces a new flag (BT_GATT_SUBSCRIBE_WRITE_PENDING) which is
set when a write operation requires canceling before the parameters can
be reused.

Fixes #17534

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-07-29 12:26:18 +02:00
Luiz Augusto von Dentz 662a519a17 Bluetooth: ATT: Fix bt_att_req_cancel clearing outstanding request
This adds a dummy cancel request which is used instead of NULL when
clearing and outstanding request thus prevent new request to take
place before a response is received while allowing the original request
to be reused.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-07-29 12:26:18 +02:00
Joakim Andersson 4fa0825925 Bluetooth: Host: Fix advertiser state flags
Set advertisers state flags so that previous advertise params does not
affect the current advertiser state.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-23 13:25:15 +02:00
Wolfgang Puffitsch c5c3a46824 Bluetooth: controller: Settings for company_id and subversion_number.
Enable use of settings system in controller and introduce settings for
company_id and subversion_number.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-07-23 10:58:03 +02:00
Vinayak Kariappa Chettimada 6cf26b8fe6 Bluetooth: controller: Make ULL/LLL split the default
Make the Upper and Lower Link Layer split architecture
implementation of the controller as the default when
building Zephyr Bluetooth Low Energy controller support
in applications.

Noticeable missing feature (porting) in comparison to old
architecture implementation is, Advanced scheduling of
connection events.

The missing features will subsequently be submitted
upstream.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-22 14:23:42 +02:00
Vinayak Kariappa Chettimada f4eb03c538 Bluetooth: controller: Rename BT_LL_SW to BT_LL_SW_LEGACY
Rename the controller Kconfig option BT_LL_SW to
BT_LL_SW_LEGACY in preparation towards switch to new Link
Layer implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-22 14:23:42 +02:00
Vinayak Kariappa Chettimada 60bf4da4aa Bluetooth: controller: split: Conditional compile LL Rx pool use
Conditional compile the use of Rx Pool used to dispatch ULL
context generated messages towards LL thread context, which
is presently only used in connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-22 12:34:49 +02:00
Vinayak Kariappa Chettimada 04f351ac0a Bluetooth: controller: Fix cond compile of DLU event generation
Fix the conditional compile of Data Length Update event
generation on PHY Update Procedure when Data Length
Extensions are not supported.

The regression was introduced in
commit 70a89876d0 ("Bluetooth: controller: Fix missing
data length update event")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-18 14:20:32 +02:00
Mariusz Skamra 2809bdf8c6 Bluetooth: shell: Fix L2CAP connect parameters count
This fixes mandatory parameters count.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-07-17 16:46:32 +02:00
Vinayak Kariappa Chettimada da431f2a7d Bluetooth: controller: split: Handle zero length L2CAP start frame
Added a fix to handle L2CAP start frame with payload length
of zero which otherwise sent zero length data start PDU on
air.

Relates to #17046.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-17 15:07:52 +02:00
Vinayak Kariappa Chettimada a081e001b0 Bluetooth: controller: split: Fix PHY update proc symmetric rsp
Fix PHY update procedure to correctly handle master
requesting asymmetrical and slave symmetrical.

Fixes BT LL TS 5.1.0 conformance test:
LL/CON/MAS/BV-117-C [PHY Update Procedure - Master
Requests Asymmetrical, Slave Symmetrical]

Relates to #17097.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-17 14:46:49 +02:00
Vinayak Kariappa Chettimada ae8628d089 Bluetooth: controller: split: Fix packet timing restrict reset
Fixed a bug related to missing reset of packet timing
restriction variable.

Fixes BT LL TS 5.1.0 test:
LL/CON/SLA/BV-55-C [Initiating PHY Update Procedure - Packet
Time Restrictions, LE Coded]

Related to #17097.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-17 14:45:49 +02:00
Wolfgang Puffitsch 845064bb31 Bluetooth: controller: hci: Add user hooks.
Add hooks for processing of HCI user events on the controller side.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-07-17 13:53:13 +02:00
Wolfgang Puffitsch e54a7ba324 Bluetooth: controller: hci: Add some documentation for encode_control().
No functional change.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-07-17 13:53:13 +02:00
Vinayak Kariappa Chettimada e0965fa53c Bluetooth: controller: Update Bluetooth version to 5.1
Update the Bluetooth HCI Version to 5.1.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-16 12:53:10 +02:00
Vinayak Kariappa Chettimada 6f2476caa1 Bluetooth: controller: Fix DLE during data transmission
Fix bug in Data Length Update procedure that caused the
connection to drop due to the implementation sending bigger
PDU before the peer has acknowledged the receipt of Length
Response PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-16 12:53:10 +02:00
Vinayak Kariappa Chettimada 35bbf148f2 Bluetooth: controller: Add deferred procedure complete event
Added implementation to defer procedure complete event until
actual on-air connection event instant.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-16 12:53:10 +02:00
Vinayak Kariappa Chettimada b60fa21f93 Bluetooth: controller: Enable Fast Enc and RSSI features
Enable the Fast Encryption design and connection RSSI
measurement when CONFIG_BT_HCI_RAW is selected.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-16 12:53:10 +02:00
Vinayak Kariappa Chettimada fa4b4932b9 Bluetooth: controller: Fix post DLE/PHY update event length
Fix the controller implementation to perform connection
event length reservation based on the completed Data Length
Update and/or PHY Update Procedure.

This fix with avoid states/roles from stepping on each
others event length. Connection would have supervision timed
out or have stalled data transmissions due to insufficient
reserved air time.

Relates to #15171.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-16 12:53:10 +02:00
Vinayak Kariappa Chettimada 70a89876d0 Bluetooth: controller: Fix missing data length update event
Fix missing generation of data length update HCI event when
effective tx and rx timings change due to PHY update
procedure.

Fixes BT LL TS 5.1.0 test:
LL/CON/MAS/BV-52-C [Master Receiving Data, LE Coded, CI
Change]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-16 12:53:10 +02:00
Vinayak Kariappa Chettimada dbb3c7f702 Bluetooth: controller: Fix packet timing restriction reset
Fixed a bug related to missing reset of packet timing
restriction variable.

Fixes BT LL TS 5.1.0 test:
LL/CON/SLA/BV-55-C [Initiating PHY Update Procedure - Packet
Time Restrictions, LE Coded]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-16 12:53:10 +02:00
Vinayak Kariappa Chettimada 3f576360ae Bluetooth: controller: Fix PHY update proc symmetric rsp
Fix PHY update procedure to correctly handle master
requesting asymmetrical and slave symmetrical.

Fixes BT LL TS 5.1.0 conformance test:
LL/CON/MAS/BV-117-C [PHY Update Procedure - Master
Requests Asymmetrical, Slave Symmetrical]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-16 12:53:10 +02:00
Joakim Andersson e03bdba8a7 Bluetooth: shell: Add support for LE SC OOB authentication in shell
Add support for for LE secure connection using OOB authentication in the
shell.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-16 12:44:18 +02:00
Joakim Andersson f8b7f2ab6a Bluetooth: smp: Add LE SC OOB support for central side
Add support for LE secure connections using OOB authentication for the
central role.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-16 12:44:18 +02:00
Joakim Andersson 0ac83180fd Bluetooth: host: Move address string parsing to bluetooth API
Bluetooth address parsing has been duplicated across the different
sub-shell files. Also missing parsing of identity/resolved addresses.
Move parsing of string close to parsing to string for a symmetrical API

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-16 12:44:18 +02:00
Joakim Andersson 7a93e948a9 kernel: lib: Add convert functions for hex strings and binary arrays
Move duplicate hex2bin and add bin2hex function so that application can
use the functions and avoid code duplication.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-16 12:44:18 +02:00
Vinayak Kariappa Chettimada 8401fda961 Bluetooth: controller: split: Fix continuous initiator
Fix the implementation of initiator to use correct anchor
tick and remainder microseconds when sending out CONNECT_REQ
PDU and then to scheduling the first connection event. This
is a fix when initiator is in continuous scan.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-15 16:11:06 +02:00
Joakim Andersson 479edc9b51 Bluetooth: shell: Fix argument count of bt clear shell command
The bt clear command accepts either 'all' or a bluetooth address.
If it is an LE address then type is also needed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-15 15:42:36 +02:00
Vinayak Kariappa Chettimada 803739cd80 Bluetooth: controller: split: Fix incorrect CU under latency
Fix bug in the ported code of the connection update, when
the slave events are skipped due to other overlapping state
or role the connection update at the instant used wrong
latency calculations. This lead to connection disconnection.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-15 15:22:23 +02:00
François Delawarde 88a2fb87ac bluetooth: fix GATT database hash done too many times
Submit GATT database hash as a delayed work to prevent it being run
twice if we register dynamic services.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-07-15 15:11:27 +02:00
Vinayak Kariappa Chettimada ab69044310 Bluetooth: controller: Fix logging assert
Fix logging assertion by using bt_addr_le_str which uses
log_strdup().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-12 13:37:47 +02:00
Mariusz Skamra 74dbd835c3 Bluetooth: Add BT_SMP_ENFORCE_MITM option
Having this option disabled, MITM flag state can be controlled by
bt_conn_security state. This option is enabled by default to not
change the current implementation behavior.
Related to SM/MAS/SCPK/BV-01-C.

Fixes #17463

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-07-11 15:54:17 +03:00
Joakim Andersson 029a66a195 Bluetooth: services: Move Heart rate service
This commit moves the BLE GATT heart rate service from
samples/bluetooth/gatt to subsys/bluetooth/services and adds a Kconfig
entry to enable and configure the service.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-11 13:21:14 +03:00
Emanuele Di Santo 30d65809fc Bluetooth: services: battery service enhancements
This commit moves the BLE GATT Battery service
from /samples/bluetooth/gatt to /subsys/bluetooth/services and
adds a Kconfig entry to enable and configure the service;
when enabled, it will register itself automatically.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-11 13:21:14 +03:00
Joakim Andersson 3bddc20f87 Bluetooth: GATT: Fix segfault discover descriptors all UUIDs
Handle optional argument UUID in bt_gatt_discover with type
DISCOVER_DESCRIPTOR, bt_uuid_cmp doesn't check for NULL pointer.
On system with MMU (nrf52_bsim) this can result in segfault.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-10 18:57:37 +03:00
Vinayak Kariappa Chettimada 17b05526ba Bluetooth: controller: Fix assert during DLE
Fix assert in controller checking ticker_id_prepare = 0 when
a scanner and connection are active, and the connection is
skipping events in order to resize Rx buffers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-10 14:10:37 +02:00
Vinayak Kariappa Chettimada 6d272a17f4 Bluetooth: controller: Move ticker_id_prepare reset to early return
Move the reset of ticker_id_prepare variable to the early
return in event_connection_prepare function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-10 14:10:37 +02:00
Johan Hedberg 408703e8dd Bluetooth: Mesh: Move under subsys/bluetooth/mesh
We've already got GATT services in subsys/bluetooth/services so
subsys/bluetooth/mesh is a more natural place. Aditionally this aims
to fix the Kconfig dependencies to be able to use mesh together with
BT_CUSTOM (i.e. a custom, potentially non-HCI, host stack).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-10 09:41:57 +03:00
Nicolas Pitre 6ce89204e6 Bluetooth: L2CAP: fix use of Z_STRUCT_SECTION_ITERABLE
Two sections are needed: bt_l2cap_fixed_chan and bt_l2cap_br_fixed_chan.
However the second one cannot be created using #define as the
preprocessor will expand it to the first before compilation happens,
sending bt_l2cap_br_fixed_chan instances in the wrong section.

This fixes commit 4e8ddfd640 ("Bluetooth: L2CAP: Make use of
Z_STRUCT_SECTION_ITERABLE").

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-04 20:42:02 +03:00
Luiz Augusto von Dentz 4e8ddfd640 Bluetooth: L2CAP: Make use of Z_STRUCT_SECTION_ITERABLE
This makes use of Z_STRUCT_SECTION_ITERABLE to define fixed channel
sections.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-07-04 17:00:09 +03:00
Luiz Augusto von Dentz 8b9920fd77 Bluetooth: GATT: Make use of Z_STRUCT_SECTION_ITERABLE
This makes use of Z_STRUCT_SECTION_ITERABLE to define static service
sections.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-07-04 17:00:09 +03:00
Vinayak Kariappa Chettimada a02151ebd4 Bluetooth: controller: split: Port radio event abort
Port the implementation that does radio event abort due to
ISR latencies. The implementation measures if the ISR could
not meet the hard real time deadline and closes the event
early.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-04 09:46:49 +02:00