Commit graph

8508 commits

Author SHA1 Message Date
Asbjørn Sæbø
c1f1b34c31 Bluetooth: Audio: Content Control ID module
This commit adds the content control ID (CCID) module from the
topic-le-audio branch.  This is required to the le-audio media control
files and call control files, which depend upon CCID.

The commit is a pure copy of the files and content in the
topic-le-audio branch, with the following exceptions:

- files are in bluetooth/audio instead of bluetooth/host/audio, with
  some include paths updated as a consequence
- as a consequence, CMake files and Kconfig files updates are done in
  other locations

The CCID module is written by
Emil Gydesen <emil.gydesen@nordicsemi.no>

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
2021-11-02 13:23:42 +01:00
Szymon Janc
47ac14282d bluetooth: host: Add support for SMP error code 0x0f
This error code informs that peer device rejected key during
keys distribution phase.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2021-11-01 21:48:52 -04:00
Jacob Siverskog
6d1e632e53 bluetooth: host: avoid freeing structure that's part of a linked list
see https://github.com/zephyrproject-rtos/zephyr/pull/39507 for
context.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2021-11-01 11:18:04 -04:00
Jacob Siverskog
7e74ec6c31 bluetooth: host: reset channel request on send failure
make sure channel request reference is cleared if send fails. without
this change this could happen when att_handle_rsp was called:

1. reqs before call:
head: 0x2000f8e8, tail: 0x2000f8c0, elements:
- addr 0x2000f8e8, function pointer NULL
- addr 0x2000f8c0, function pointer 0x35c1d

2. att_handle_rsp called, calling bt_att_req_free with address
0x2000f8e8

3. reqs after call:
head: 0x2000f8e8, tail:	0x2000f8c0, elements:
- addr 0x2000f8e8, function pointer NULL
- addr 0x2000f8d4, function pointer NULL
- addr 0x2000f8ac, function pointer NULL
- addr 0x2000f898, function pointer NULL
- addr 0x2000f884, function pointer NULL
- addr 0x2000f870, function pointer 0xd92b7e7c
- addr 0x2000f85c, function pointer 0x462a03a9
- addr 0x2000f848, function pointer 0xf77b2f4b
- addr 0x2000f834, function pointer 0x33714775
- addr 0x2000f820, function pointer 0x31ba37f8
- addr 0x2000f80c, function pointer 0x5fda8494
- addr 0x2000f7f8, function pointer 0xbcff174e
- addr 0x2000f7e4, function pointer 0x341393f
- addr 0x2000f7d0, function pointer 0xbcfee8b8
- addr 0x2000f7bc, function pointer 0x1e73d9e5

which obviously is broken.

closes #39506.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2021-11-01 11:18:04 -04:00
Piotr Pryga
06a8053901 Bluetooth: controller: ULL: fix dequeue of IQ samples reports
Dequeue and  scheduling IQ samples report towards host
was working by accident. IQ samples were casted to
pointer to struct pdu_adv. Then type of PDU was checked.
Fortunately the IQ samples hadn't got PDU_ADV_TYPE_EXT_IND
in memory pointed by struct pdu_adv->type.

NODE_RX_TYPE_IQ_SAMPLE_REPORT must have separate execution
path in rx_demux_rx.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-11-01 11:14:46 -04:00
Piotr Pryga
a9ab805983 BLuetooth: controller: hci: fix wrong sync handle in IQ samples report
There were no assignment to iq_report->hdr.handle in the code
hence all IQ samples reports had the same handle value which
was zero.

Since the handle is related with ll_sync_set pointer the handle
value may not be set in LLL.

The best place to set handle value is thread context where
bt_hci_evt_le_connectionless_iq_report is prepared.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-11-01 11:14:46 -04:00
Emil Gydesen
7958e86c66 Bluetooth: shell: Fix uninitalized values for iso big create
A few values were not initialized when creating a
big in the iso shell.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-11-01 09:02:24 -04:00
Emil Gydesen
4151f0ec90 Bluetooth: ISO: Fix typo in hci_le_cis_estabilished
The function should have been named
hci_le_cis_established.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-28 10:37:34 -04:00
Lingao Meng
9181ae44e6 Bluetooth: Mesh: Fix missing enable adv thread
When user only use pb-gatt provisioning, which unable to
send out connectable advertising, due to adv thread not started.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-10-28 10:36:55 -04:00
Morten Priess
cd470da214 Bluetooth: controller: Send disconnect complete when CIS is terminated
Previously the host would handle disconnecting associated CISes and
invoking callbacks when a host ACL conn was disconnected.

This responsibility has now been moved to the controller, which needs to
send a NODE_RX_TYPE_TERMINATE with the CIS handle for proper
disconnection in the host. This is in accordance with the spec.

As disconnect reason, the CIS uses the ACL reason, which is passed to
the host along with the handle.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-10-28 11:18:40 +02:00
Emil Gydesen
f6e829a68b Bluetooth: ISO: Make bt_iso_remove_data_path static
Make bt_iso_remove_data_path static as it is only used by iso.c

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-27 15:12:43 -04:00
Emil Gydesen
6f09a69679 Bluetooth: ISO: Make iso_new static
Make iso_new static as it is only used by iso.c

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-27 15:12:43 -04:00
Emil Gydesen
9d17138f92 Bluetooth: ISO: Make hci_le_remove_cig static
Make the function static as it is only used by iso.c

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-27 15:12:43 -04:00
Vinayak Kariappa Chettimada
7496e3f0cf Bluetooth: Controller: Select CSA#2 for Extended Advertising Support
Select CONFIG_BT_CTLR_CHAN_SEL_2 when CONFIG_BT_CTLR_ADV_EXT
is enabled.

Relates to commit 651137ee11 ("Bluetooth: Controller: Fix
Extended Advertising channel use").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-27 11:33:07 +02:00
Vinayak Kariappa Chettimada
c6ae4d52f7 Bluetooth: Controller: Fix LOW_LAT_ULL_DONE synchronization counting
Fix BT_CTLR_LOW_LAT_ULL_DONE synchronization counting so
that done events are processed before pipeline enqueue
decisions are taken in LLL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-27 11:32:48 +02:00
Emil Gydesen
254108bcf5 Bluetooth: Audio: Mark VOCS and VOCS_CLIENT as experimental
The implementation and its API is still considered experimental.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-27 10:53:24 +02:00
Emil Gydesen
6cf9138eac Bluetooth: Audio: Mark MICS and MICS_CLIENT as experimental
The implementation and its API is still considered experimental.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-27 10:53:24 +02:00
Emil Gydesen
46e299daa8 Bluetooth: Audio: Mark AICS and AICS_CLIENT as experimental
The implementation and its API is still considered experimental.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-27 10:53:24 +02:00
Emil Gydesen
864d1aa4ed Bluetooth: Audio: Mark VCS and VCS_CLIENT as experimental
The implementation and its API is still considered experimental.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-27 10:53:24 +02:00
Vinayak Kariappa Chettimada
39a667659f Bluetooth: Controller: Fix incorrect periodic advertising interval
Fix incorrect Periodic Advertising interval when Coded PHY
support is built, chain PDUs is used and Extended
Advertising is disable while the Periodic Advertising
continues to be active.

Related to commit a379196b48 ("Bluetooth: controller:
nRF5: Back-to-Back Radio Tx interface").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-27 10:51:55 +02:00
Szymon Janc
742ee977ca bluetooth: ATT: Ignore signed writes on EATT bearer
Core Specification 5.3 Vol 3. Part G. 4.2:
The Signed Write Without Response sub-procedure shall only be supported
on the LE Fixed Channel Unenhanced ATT bearer.

This was affecting GATT/SR/GAW/BI-38-C qualification test.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2021-10-25 19:24:17 -04:00
Emil Gydesen
4257f0b8a1 Bluetooth: Shell: Fix bad string formats in GATT shell
Some shell prints didn't use the correct format for some
values, causing warnings/build errors.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-25 19:22:05 -04:00
Vinayak Kariappa Chettimada
fefb0a00e4 Bluetooth: Controller: Fix extended advertising set remove
Fix extended advertising set remove and clear, to reset the
PDU double buffer to keep one initialized PDU. This is done
to prevent common extended payload format contents from
being overwritten and corrupted due to same primary PDU
buffer being used to remove AdvA if auxiliary PDU is
allocated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-25 16:29:49 +02:00
Vinayak Kariappa Chettimada
4bf88a43fd Bluetooth: Controller: Reset adv and scan resp to one allocated PDU
Reset allocated advertising and scan response PDUs to one
initial PDU in the double buffers when advertsing set is
removed or cleared.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-25 16:29:49 +02:00
Vinayak Kariappa Chettimada
55b130bc28 Bluetooth: Controller: Remove global lll_adv_pdu_release function
Remove lll_adv_pdu_release function which is not referenced
outside its current use.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-25 16:29:49 +02:00
Jacob Siverskog
046f29a8cb Bluetooth: ATT: Fix typo in defines
Fix typo in ATT first/last attribute defines.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2021-10-23 20:39:36 -04:00
Torsten Rasmussen
9a2be89557 kconfig: bluetooth: experimental settings now uses select EXPERIMENTAL
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all subsys/bluetooth and drivers/bluetooth/hci settings having
`[EXPERIMENTAL]` in their prompt has has been updated to include
`select EXPERIMENTAL` so that developers can enable warnings when
experimental features are enabled.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-10-22 13:59:21 +02:00
Abe Kohandel
190848177e bluetooth: ots: Enable testing with assert
Fix compilation and logic issues to allow testing OTS functionality with
assert enabled.

The compilation fixes are simple and do not require an explanation.

The assertion in bt_ots_dir_list_init was logically reversed. Its
purpose is to ensure the directory list is not already initialized
and as such should assert that the dir_list is not set (i.e. is NULL).

Signed-off-by: Abe Kohandel <abe.kohandel@gmail.com>
2021-10-21 11:21:13 -04:00
Emil Gydesen
1a11d1bd25 Bluetooth: ISO: Move some broadcast iso code to better group functionality
Better group code specific for e.g. ISO broadcaster and
ISO sync receiver.

No code has been changed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-18 12:43:38 +02:00
Emil Gydesen
a56cbed603 Bluetooth: ISO: Split ISO broadcast config
Splitt he ISO broadcast config into broadcaster and
sync receiver. This will allow a device that only
wants to one of the roles to have a much more optimized
configuration.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-18 12:43:38 +02:00
Krzysztof Chruscinski
eb3375f47c shell: Add __printf_like to shell_fprintf
Add __printf_like modifier to validate strings used by shell.
Fixing warnings triggered by this change.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-10-14 16:32:19 -04:00
Emil Gydesen
6e99941f6a Bluetooth: ISO: Remove bt_iso_data_path struct
The struct basically only had a pointer to
bt_iso_chan_path as well as duplicating the pid and
the direction.

The commit removes the struct as it was more confusing than helpful,
and instead use the PID for the bt_iso_chan_path and
supply the direction as a argument instead.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-11 21:05:05 -04:00
Emil Gydesen
f546ef4cde Bluetooth: ISO: Fix missing fallback to HCI for ISO data path
A recent change broke the fallback to using a simple
HCI data path configuration in case that the application
does not provide a data path.

This commit fixes that issue, while retaining the
intended update from the change that broke the fallback,
as well as making the code a bit easier to read
and more documented.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-11 21:05:05 -04:00
Thomas Ebert Hansen
e69b159c34 Bluetooth: host: Fix endianess bug in value_handle
The characteristic value handle is missing an endianess conversion.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2021-10-11 21:04:51 -04:00
Piotr Pryga
1c8af8cfe5 Bluetooth: controller: df: fix handling of max count of IQ reports
There was an error in handling of max number of IQ reports
generated by controller. Accordin to BT Core Spec 5.1 the host
may request a number of CTEs to be sampled and reported by
controller while enable IQ sampling. The max_cte_count value
set to zero means sample all CTEs in a periodic advertising chain.

The commit fixes wrong handling of the max_cte_count provided
value to generate expected number of IQ reports.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-10-11 21:01:36 -04:00
Piotr Pryga
39c535fef8 Bluetooth: controller: Make per adv filtering by CTE cond compilable
The filtering of periodic advertisements by scanner may be not needed
in certain situations e.g. while use of periodic advertising by BT ISO.
To make the code smaller and avoid execution of not needed code the
functionality will be conditionally compilable. It may be enabled
or disabled by use of CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING
Kconfig option.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-10-07 21:36:55 -04:00
Piotr Pryga
e03f9c3042 Bluetooth: controller: Add per sync filt by CTE type for SOC w/o DFE
First implementation of periodic advertising sync filtering
requires existence of Direction Finding Extension in Radio
peripheral.
To add the filtering support for other Nodric SOCs software
based PDU traversing for CTEInfo should be implemented.

In case there is no DFE in Radio peripheral, actual filtering
is done in ULL.

The commit provides necessary changes to previous solution.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-10-07 21:36:55 -04:00
Piotr Pryga
ecf761b4e9 Bluetooth: controller: ULL: add per sync filtering by CTE type
Follow up on changes in lower link layer to add filtering
of periodic advertisements synchronization by CTE type.

The NODE_RX_TYPE_SYNC is used to transport information that:
- Sync is established. In such situation the node_rx
  includes data related with received PDU
- Sync scanning is terminated.
In first case ULL will generate NODE_RX_TYPE_SYNC_REPORT
after sending NODE_RX_TYPE_SYNC.

Also EVENT_DONE_EXTRA_TYPE_SYNC handling has additional
execution path that terminates sync scanning if requested
by lower link layer. In other case it adjusts sync scan
window and maintains timeout as usual.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-10-07 21:36:55 -04:00
Piotr Pryga
9b66a8b47d Bluetooth: controller: rework per scan lll to allow filt by CTE type
Periodic advertisement synchronization may be filtered by CTE type.
If particular CTE type is not allowed then depening on filtering policy:
- if filtering policy is off synchronization if terminated
- if filtering policy is on synchronization is continued to
  synchonize with another device from allowed adverisements list.
If synchronization is established and peer device changes CTE type
to one that is not allowed, synchronization should be maintained.

There are two new execution paths. First one is executed when
synchronization is created. In this case CTEILINE is enabled
to parse PDU for CTEInfo field. In this execution path CTE
type is verified. Second execution path does not include
parsing PDU for CTEInfo and verification of CTE type.

Information about sync allowed is added to node_rx instance
that transports received PDU data. In case the sync has to be
terminated the node_rx will not hold PDU data.

Also done event is extended with information about sync
termination if CTE type is not allowed and filtering
policy is off.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-10-07 21:36:55 -04:00
Piotr Pryga
04e2e84cb7 Bluetooth: radio: move radio_df_cte_inline_set_enabled to radio.c
To enable runtime parsing of PDU to find CTEInfo field CTEINLINE mode
has to be enabled. Thanks to that it is possible to verify if the PDU
has allowed CTE type e.g. for periodic advertising synchornization.
To run CTEInfo parsing other parametrers of CTEINLINE are not relevant.
If Radio is set to disable after PDU END event the CTE sampling
will not be processed.

The commit moves the radio_df_cte_inline_set_enable function to make
it accessible even the direction finding features are disabled.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-10-07 21:36:55 -04:00
Piotr Pryga
ff3045db61 Bluetooth: hci: Add handling of allowed CTE types for per sync create
Add missing code responsible for handling of allowed CTE types
in HCI_LE_Periodic_Advertising_Create_Sync command.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-10-07 21:36:55 -04:00
Vinayak Kariappa Chettimada
2ab8b9061c Bluetooth: Controller: Fix cpu sleep for simulation targets
Use __WFE and __SEV for CPU sleep in simulation too to
avoid stalling and to let ISRs execute during CPU sleep.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-07 15:44:10 -04:00
Morten Priess
6344ea984b Bluetooth: controller: Framework for vendor ISO data path
Added weak function for data path dependent ISO-AL sink creation. This
is required for vendor specific ISO-AL data sink operation. Invoke sink
creation for vendor specific data path.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-10-07 15:43:17 -04:00
Morten Priess
06900485ec Bluetooth: host: Add bt_configure_data_path for vendor data path
Implemented host function for configuring vendor specific data path for
use with ISO, and fixed passing of path ID in setup.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-10-07 15:43:17 -04:00
Wolfgang Puffitsch
f3b97ccfb6 Bluetooth: controller: Introduce Kconfig for Read ISO Link Quality
Introduce Kconfig for Read ISO Link Quality command. Support for the
command is optional according to the specification.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-10-04 20:48:01 -04:00
Wolfgang Puffitsch
d58224566d Bluetooth: controller: Reorder variable declarations in ISO HCI commands
Reorder variable declarations in HCI command handlers of ISO-related
commands to conform to reverse Christmas tree style.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-10-04 20:48:01 -04:00
Wolfgang Puffitsch
7c0b74bc0d Bluetooth: controller: Fix use of handle field in HCI command handling
Fix use of handle field in HCI command handling for some ISO-related
commands. The response buffer may reuse the command buffer. Therefore,
the handle field must not be copied directly from the command to the
response.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-10-04 20:48:01 -04:00
Wolfgang Puffitsch
230f8db0d5 Bluetooth: controller: Update supported commands for ISO
Set bits for ISO-related supported commands depending on selected
features and adjust compilation guards for the respective handler
functions.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-10-04 20:48:01 -04:00
Trond Einar Snekvik
cd89f42393 Bluetooth: Mesh: Model extensions walk stops before last model
When reaching the last model in the circular extension linked list, the
walker would abandon the walk before checking the last model. This makes
us skip models when checking the subscription list, potentially causing
incoming messages to be wrongfully ignored.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-10-04 20:45:23 -04:00
Emil Gydesen
f9e2fc3fc4 Bluetooth: ISO: Move bt_iso_accept and make static
Move the function and make it static as it is only
used in iso.c and for unicast only.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-10-04 20:40:06 -04:00
Szymon Janc
088fac76ed Bluetooth: Mesh: Fix crash on disconnect
bt_mesh_proxy_role_setup() is called conditionally when peer is
connected and gatt_disconnected() is always called. This leads
to unbalance in role->conn reference count and crash.

Instead of hot-fixing this in gatt_disconnected(), this commit adds
proper bt_mesh_proxy_role_cleanup() API that is called by roles
implementations if cleanup is needed.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2021-10-04 18:52:08 +02:00
Vinayak Kariappa Chettimada
072c8f2c68 Bluetooth: Controller: Fix assertion failed [evdone]
When there are radio events with time reservations lower
than the preemption timeout of 1.5 ms, the pipeline has to
account for the maximum radio events that can be enqueued
during the preempt timeout duration. All these enqueued
events could be aborted in case of late scheduling needing
as many done event buffers.

During continuous scanning, there can be 1 active radio
event, 1 scan resume and 1 new scan prepare. If there are
peripheral prepares in addition, and due to late scheduling
all these will abort needing 4 done buffers.

If Extended Scanning is supported, then an additional
auxiliary scan event's prepare could be enqueued in the
pipeline during the preemption duration.

Fixes #36381.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-04 18:26:11 +02:00
Ingar Kulbrandstad
c1e053c9b3 Bluetooth: Mesh: Missed IV update cannot be captured
It seems that if the IV update is missed, a node cannot
recover it until the IV index has increased to a value
greater than Node's Last known IV + 1.

Signed-off-by: Ingar Kulbrandstad <ingar.kulbrandstad@nordicsemi.no>
2021-10-04 08:37:43 -04:00
Szymon Janc
c589994dc0 bluetooth: Add support for reconfiguring L2CAP channels
This allows application to increase channel's MTU and (in some cases)
MPS. When channel gets reconfigured dedicated callback is called to
inform application.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2021-10-04 11:05:03 +02:00
Vinayak Kariappa Chettimada
24596f5c08 Bluetooth: Controller: Refactor out sync setup addr and sid check
Refactor out the implementation of Periodic Sync Setup
address check including Periodic Advertiser List and SID.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-01 21:48:51 +02:00
Vinayak Kariappa Chettimada
bf01d55107 Bluetooth: Controller: Implement Periodic Advertiser List
Implement support for Periodic Advertiser List to be used
in LE Periodic Advertising Create Sync command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-01 21:48:51 +02:00
Vinayak Kariappa Chettimada
d76711f187 Bluetooth: Controller: Refactor ull_filter adva_get and tgta_get
Refactor `ull_filter_adva_get` and `ull_filter_adva_get` to
input resolving index compare to adv context reference.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-01 21:48:51 +02:00
Vinayak Kariappa Chettimada
4bfeee6d9e Bluetooth: Controller: Minor filter accept list related refactoring
Refactoring related to filter accept list, resolving list,
and removed the redundant anon variable.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-01 21:48:51 +02:00
Aleksander Wasaznik
a5cf50e61f Bluetooth: Host: Fix resource leak in bt_gatt_unsubscribe
There are two simmilar functions for unsubscribing from GATT handles.

 - `gatt_sub_remove`, which is called on disconnect for every
 subscription will free the `subscriptions` entry when the entry
 represents no subscriptions.

 - `bt_gatt_unsubscribe`, called by the application, which forgets to
 free the `subscriptions` entry.

If all subscriptions grouped in a `subscriptions` entry are removed
using `bt_gatt_unsubscribe` before disconnect, there are no
subscriptions left to call `gatt_sub_remove` on. The `subscriptions`
entry is then never freed.

The above results in a resource leak of a `subscriptions` entry.

This fix makes explicit and enforces the invariant that there should not
be entries in `subscriptions` with an empty subscription list.

Fixes #38688

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2021-10-01 14:38:06 -04:00
Piotr Pryga
982743b765 tests: Bluetooth: df: Add test to verify correctness of relase of PDUs
Add unit tests that will ensure the CTE disable operation does not
cause breaking of LLL operations by too early release of chained PDUs.
The tests verify if numbers of PDUs in free PDUs fifo and free PDUs
memory pool are correct.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-10-01 14:32:49 -04:00
Piotr Pryga
a3378d1c9f Bluetooth: controller: Fix ASSERT caused by ULL releasing chain PDUs
When CTE is enabled for periodic advertising and number of CTE is
greater than number of PDUs in a chain, that are needed to transport
advertising data, there are additional empty PDUs used for transport
CTE.

CTE transmission may be disabled when periodic advertising event is
pending in LLL. rem_cte_info_from_per_adv_chain removed CTEInfo field
from extended advertising header in chained PDUs. When there were found
empty PDUs (created to transport CTE only), they were released from
the chain that was currently used by LLL. That caused an assert in
isr_tx handler due to broken advertising chain.

The rem_cte_info_from_per_adv_chain may not relese PDUs that are in
use by LLL. The PDUs may be released by LLL in prepare step when
advertising pdu double buffer is swapped by lll_adv_sync_data_latest-
_get.

This PR fixes that issue.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-10-01 14:32:49 -04:00
Vinayak Kariappa Chettimada
bacfd0175f Bluetooth: Controller: Fix assert on aux LLL scheduled chain reception
Fix asserted in ULL due to incorrect resumption of scan
window when auxiliary channel chain PDU is LLL scheduled by
a ULL scheduled auxiliary channel PDU reception.

The issue is solved by having `is_chain_sched` flag in the
auxiliary channel scan context and using the already present
`is_aux_sched` in the primary channel scan context to
differentiate if the auxiliary PDU Rx ISR is to return back
to primary channel scan window or to close the auxiliary
chain PDU reception radio event.

Relates to #38146.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-01 14:32:24 -04:00
Vinayak Kariappa Chettimada
e123c4e381 Bluetooth: Controller: Fix to ignore aux ptr in scannable advertising
Fix to ignore aux pointer struct in scanning advertising, to
avoid ULL scheduling from setting up ticker to receive chain
PDUs while LLL is receiving scan response PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-10-01 14:32:24 -04:00
Vinayak Kariappa Chettimada
5cb3721313 Bluetooth: Controller: Fix HCI command parameter check failures
Fix assorted HCI command parameter check failures faced
during conformance testing.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-30 11:47:57 +02:00
Aleksandr Khromykh
797c17436b Bluetooth: Mesh: logging public key in big endian
Local public key has been logged in little endian but
remote public key in big endian. That has been changed.
Both are logged in big endian to be able to compare in logs.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2021-09-29 15:34:13 -04:00
Aleksandr Khromykh
ebf9a591d6 Bluetooth: Mesh: split debug for prov and prov_device
Debug configuration for prov and prov_device has been split
since prov general modul and it is used for provisioner as well.
It is not necessary to enable prov_device debugging
to debug provisioner.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2021-09-29 15:34:13 -04:00
Rubin Gerritsen
ca088aafbe Bluetooth: host: Warn on incomplete adv reports
When the controller forwards incomplete reports to the host,
the application currently has no way of reassembling them.
Therefore the application may fail to parse the data.

Issue a warning until
https://github.com/zephyrproject-rtos/zephyr/issues/37368
is resolved.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-09-29 14:47:47 -04:00
Vinayak Kariappa Chettimada
aa4b75b58c Bluetooth: Controller: Separate address get and read functions
Have separate Bluetooth Device address get and read
functions, remove use of function just to return Extended
Advertising Random address and replace with simple
assignment statement.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 14:44:47 -04:00
Vinayak Kariappa Chettimada
d7cfb5473b Bluetooth: Controller: Use defines for aux pointer offset unit value
Use defines for aux pointer offset unit value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 14:44:47 -04:00
Vinayak Kariappa Chettimada
651137ee11 Bluetooth: Controller: Fix Extended Advertising channel use
Add implementation defined channel index in the auxiliary
pointer of the common extended payload format in the primary
channel PDUs and the same be used in the transmission of
auxiliary PDUs.

Fixes #35668.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 14:44:47 -04:00
Vinayak Kariappa Chettimada
3075ba92d1 Bluetooth: Controller: Add FIXME for Per Adv chain channel use
Add FIXME comments for missing use of channel selection
algorithm for Periodic Advertising chained PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 14:44:47 -04:00
Vinayak Kariappa Chettimada
ec784fd420 Bluetooth: Controller: Add advertiser clock accuracy value
Add implementation to set correct Advertiser's clock
accuracy value in the auxiliary pointer field in the common
extended payload format.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 14:44:47 -04:00
Vinayak Kariappa Chettimada
6af9a433c2 Bluetooth: controller: Fix populate offset in latest advertising PDU
Fix implementation to populate the aux, and sync offset
in the latest PDU. If both the current and latest of the
double buffer has been filled and LLL did not pick the
latest PDU, then the offset should be filled into the latest
PDU (and not into the first/current PDU).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 14:44:47 -04:00
Vinayak Kariappa Chettimada
3ce9b2f2f5 Bluetooth: Controller: Minor indentation fixes
Minor indentation fixes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 14:44:47 -04:00
Vinayak Kariappa Chettimada
3a8bf279d9 Bluetooth: Controller: Explicitly typecast void return for memcpy calls
Explicitly typecast void return for memcpy calls.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 14:44:47 -04:00
Vinayak Kariappa Chettimada
ec10ef601d Bluetooth: Controller: Minor rename of ULL internal function
Rename ULL internal helper function to get the random
address.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 14:44:47 -04:00
Carles Cufi
301a7103a0 Bluetooth: common: Add build asserts for address struct sizes
In some HCI packed structures we place non-packed structs inside (in
particular the address structs).
Alignment is not an issue for those because all their members are just
byte-aligned, but size is. If the compiler ever packs those it would
become a real problem, and so detect this at build time.
See the link below for more info:
https://stackoverflow.com/a/66389167

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-29 19:07:52 +02:00
Joakim Andersson
da31a33905 Bluetooth: host: Access local IRKs consistently
Change the way the local IRKs are accessed to be consistent with the
all other uses.
Coverity thinks using the pointer to the array is suspicious in this
case.

Fixes: #38130

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-09-29 10:44:38 -04:00
Joakim Andersson
b7ad63362c Bluetooth: host: Verify valid local identity loaded from settings
Verify that the local identity loaded from the settings key is
valid for the current configuration.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-09-29 10:44:38 -04:00
Vinayak Kariappa Chettimada
ad36dcdf15 Bluetooth: Controller: Use defines for scanning state types
Use defines for scanning state types of passive, active,
initiator and synchronization state.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 15:05:57 +02:00
Vinayak Kariappa Chettimada
e0ac70ad91 Bluetooth: Controller: Allow resolving list update during passive scan
Allow resolving list update  when passive scanning,
otherwise deny if advertising, active scanning, initiating
or periodic sync create is active.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 15:05:57 +02:00
Vinayak Kariappa Chettimada
bbe8fe721b Bluetooth: Controller: Fix imprecise data bus error in periodic sync
Fix imprecise data bus error when receiving Periodic
Advertising Report caused due to uninitialized `extra` field
member in the node rx struct passed from ULL to LL thread
context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 15:02:37 +02:00
Vinayak Kariappa Chettimada
665a8d2c6e Bluetooth: Controller: Fix repeated per sync drift compensations
Fix repeated periodic sync drift compensation invoked when
receiving chain PDUs which caused memory corruptions and
bus faults.

Use `is_aux_sched` flag in Periodic Sync's LLL context to
differentiate between the first AUX_SYNC_IND PDU followed by
use of LLL scheduling to receive following AUX_CHAIN_IND PDU
versus ULL scheduling being used to receive AUX_CHAIN_IND
PDUs.

Drift compensation to be done only using the AUX_SYNC_IND
PDU and not on reception of AUX_CHAIN_IND PDU using ULL
scheduling.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-29 15:02:37 +02:00
Emil Gydesen
8d20e8d5bc Bluetooth: ISO: Add iso accept info struct
Add a new struct that provides information to the upper
layer when accepting an connected isochronous stream.

The CIG ID and CIS ID makes it possible for the upper layer
to determine which ISO channels are "together" in a group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-28 20:19:37 -04:00
Vinayak Kariappa Chettimada
fda7b46f92 Bluetooth: Controller: Update Bluetooth version to 5.3
Update the Bluetooth HCI Version to 5.3.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-28 20:18:00 -04:00
Emil Gydesen
c938c81575 Bluetooth: Audio: VCS client use auto CCC discovery
Update the VCS client to use the auto CCC discovery
feature instead of expecting it to be a specific place
in the remote server's GATT database.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-28 20:12:55 -04:00
Emil Gydesen
5a11a19713 Bluetooth: Iso: Add BT_ISO_SDU_BUF_SIZE macro
Add the BT_ISO_SDU_BUF_SIZE which can be used to declare
the TX buffers for ISO, similar to the BT_L2CAP_SDU_BUF_SIZE
macro for L2CAP.

This also updates the ISO samples to use this as well
updating the SDU check to use
CONFIG_BT_ISO_TX_MTU/CONFIG_BT_ISO_RX_MTU without
subtracting the BT_ISO_CHAN_SEND_RESERVE to make the
API more clear.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-28 20:07:32 -04:00
Emil Gydesen
49b36f4e79 Bluetooth: iso: Handle broadcast iso data path failure
Handle the case that setting up the iso data path for a
broadcast (sink or source) bis fails.

As part of this fix, implement the lookup_big_by_handle
function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-28 20:03:39 -04:00
Lingao Meng
5ddbdcedd0 Bluetooth: Mesh: Move proxy message size to kconfig
Add `BT_MESH_PROXY_MSG_LEN` to config proxy message length

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Lingao Meng
4fcf549607 Bluetooth: Mesh: Use common buf size for all conn
Use common buffer size for all bluetooth mesh connection.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Lingao Meng
355b18c43e Bluetooth: Mesh: Add seperate config for pb-gatt dev name
Add seperate config to control whether device name include in
pb-gatt advertising scan response data.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Lingao Meng
3f68692069 Bluetooth: Mesh: Reflact disconnect logic to separate roles
remove section ordering to use code more readable.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Lingao Meng
22b234cf03 Bluetooth: Mesh: Move bt_mesh_proxy_role to proxy_msg.c
Mesh bt_mesh_proxy_role structure to proxy_msg.c

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Lingao Meng
bc1d6580dc Bluetooth: Mesh: Move proxy complete message to seperate role
Move proxy complete message to seperate role.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Lingao Meng
d831d8a7d3 Bluetooth: Mesh: Move command buffer to proxy_msg.c
Move command buffer alloc to proxy_msg.c.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Lingao Meng
a88aac2a7f Bluetooth: Mesh: Remove unnecessary prov buf get function
Remove `bt_mesh_pb_gatt_get_buf`.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Lingao Meng
c057a69a2c Bluetooth: Mesh: Rename bt_mesh_pb_gatt<*> function
Rename bt_mesh_pb_gatt_<*> function, and split from proxy.h

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Lingao Meng
b2889903a3 Bluetooth: Mesh: Split gatt services to pb-gatt and proxy
Split gatt services to pb-gatt-srv and proxy-srv.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Lingao Meng
412e7da951 Bluetooth: Mesh: Delete bt_mesh_proxy_prov_disable parameter.
we will no longer need the additional `disconnect` parameter,
such as we only process gatt database from disconnect handler.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-28 19:57:15 -04:00
Aleksandr Khromykh
6f2516d9a7 Bluetooth: Mesh: Refactoring provisioning to make all OOB auth working
The current implementation has hidden dependencies that break
OOB authentication if provisioner does not have the configured
input or output fields used for device capabilities.
It didn't allow to pass several OOB authentication cases.
After refactoring provisioner behavior is independent to
provisionee settings.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2021-09-28 19:54:00 -04:00
Vinayak Kariappa Chettimada
1ea0fabe72 Bluetooth: Controller: Fix BT_CTLR_FAST_ENC Kconfig help text
Fix BT_CTLR_FAST_ENC Kconfig help text to reflect the
current Encryption Setup Procedure behavior.

With the split architecture, Encryption Setup Procedure
will take 4 connection events when BT_CTLR_FAST_ENC is
enabled, in comparison to 3 connection events in the
legacy Controller architecture. This is due to split
architecture processes control procedures in the lower
priority Upper Linker Layer execution context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-28 15:39:55 +02:00
Pavel Vasilyev
e40998a4e4 Bluetooth: Mesh: Return ETIMEDOUT if k_sem_take call times out
EAGAIN is used in some other places in the code, e.g. if node is not
provisioned when a model tries to send a message. This change helps to
differentiated if the acknowledged message timed out from other failers.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-09-28 11:49:27 +02:00
Vinayak Kariappa Chettimada
f07763640e Bluetooth: Controller: Fix multiple peripheral connection deadlock
Fix deadlock in multiple peripheral connection in a device
due to redundant double reservation of node rx buffer during
crossover scenario in Data Length Update procedure.

Data Length Update resize state was reset back to response
wait state when peripheral received an acknowledgment to
local initiated Data Length Request PDU after having already
transitioned to resize state.

Implementation is designed to transition to resize state
under both Data Length Response reception and crossover
scenario of Data Length Request reception when procedure is
local initiated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-28 11:38:16 +02:00
Joakim Andersson
284238339b Bluetooth: host: compile out check for multiple identities
Add check that can be removed by the compiler since the rest is only
needed when multiple identities have been enabled.

Fixes: #38134

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-09-27 22:27:18 -04:00
Emil Gydesen
623aaa136b Bluetooth: ISO: Remove bt_conn_unref for ISO deferred work
Removed the bt_conn_unref from the deferred_work function.
For ISO, the conn unref for the peripheral will happen in
the bt_iso_disconnected function. For the central, the
unref shall only happen when the CIG is terminated.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-27 22:24:23 -04:00
Joakim Andersson
dd0bf5c20b Bluetooth: shell: Log failure to register authentication handlers
Log failure to register authentication handlers since returning errors
from the shell is not visible to the user.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-09-27 19:47:50 +02:00
Joakim Andersson
0207e86e38 Bluetooth: shell: Handle return value of GATT service register functions
Handle return value of GATT service register and unregister functions.
Log action to shell.

Fixes: #38013

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-09-27 19:47:50 +02:00
Joakim Andersson
b08e5725ef Bluetooth: host: check return value of bt_rand when creating identities
Check the return value of bt_rand when creating identities.
Failure to generate a random IRK would result in the privacy feature
being compromised.

Fixes: #38120

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-09-27 17:14:20 +02:00
Joakim Andersson
884ebbbb9e Bluetooth: host: Fix unexpected control flow
Fix unexpected control flow in host keys module. A continue in a do
while false act the same as a break. This entire construct can be
replaced with a simple if else control flow.

Fixes: #38014

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-09-27 16:35:54 +02:00
Joakim Andersson
3a8190a194 Bluetooth: SDP: Check len is not zero before accessing data pointer
Check len is not zero before accessing data pointer, the len variable
is not checked before this point so cannot be trusted to not be zero.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-09-27 16:34:22 +02:00
Jamie McCrae
285a0737a3 Bluetooth: host: Fix non-extended adverts not being limited to 31 bytes
Fixes an issue whereby the application is configured for extended
advertising mode but advertises in legacy mode with a large device name
which should be limited to 31 bytes

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2021-09-27 10:10:00 -04:00
Joakim Andersson
05755df9c1 Bluetooth: host: Ignore return value of change-aware when reading DBhash
Ignore the return value of the bt_gatt_change_aware function when the
client is reading the database hash characteristic value. This is the
point where the client becomes change-aware, so nothing else should be
done if the client is change-unaware.

Fixes: #38012

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-09-27 08:23:17 -04:00
Szymon Janc
6440c9eb51 bluetooth: host: Fix legacy SMP pairing
This is a regression introduced in b8770acc28 when
aligning with BT Core Spec 5.3 naming convention.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2021-09-27 08:13:48 -04:00
Piotr Pryga
2637c0ed22 Bluetooth: controller: Fix compilation error due to missing includes
When CONFIG_ARM_MPU is explicitly unset in application prj.conf there
were build warnings related with implicit declarations of following
symbols: NRF_DT_GPIOS_TO_PSEL, __WFE, __SEV.
Lack of NRF_DT_GPIOS_TO_PSEL lead to build error due to undeclared
dfegpio0_gpios symbol.

The cause for the warnings and error were missing soc.h includes in
few source files. The missing includes were added in this commit.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-09-24 09:20:38 -04:00
Eric Johnson
83dd1d0a87 bluetooth: host: conn: Fix conn param during l2cap fallback
When falling back to L2CAP for connection parameter updates, the
interval min and maxes should also be saved.

Fixes #38613.

Signed-off-by: Eric Johnson <eric@liveathos.com>
2021-09-23 10:04:31 +02:00
Morten Priess
eb218a5405 Bluetooth: controller: Prevent multiple ticker_stop in cis_disabled_cb
When calling ull_conn_iso_cis_stop with no pending LLL events,
cis_disabled_cb may be called recursively if more than one CIS is
associated with a disconnecting ACL connection.

To prevent ticker_stop being called more than once, it shall be
registered at entry of cis_disabled_cb whether this is the last CIS.
Only then shall ticker_stop be called.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-09-21 12:52:15 -04:00
Vinayak Kariappa Chettimada
f3a0ae0cbc Bluetooth: Controller: Fix CIS LLL events pending check
CIS LLL events pending was checked incorrectly using a
mayfly incorrect set to be called from ULL LOW context,
but the actual call was from ULL HIGH context.

Beside this, the code was refactored to have file static
functions after global scope functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-21 12:52:15 -04:00
Carles Cufi
4801cbd921 Bluetooth: controller: Replace {m_,s_} with {c_,p_}
Replace the old master and slave prefixes with the new central and
peripehral ones from the Bluetooth spec v5.3.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-21 13:01:29 +02:00
Carles Cufi
947b38ac0a Bluetooth: controller: Replace slave with peripheral
Replace the old slave term with the new peripheral
one from the Bluetooth spec v5.3.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-21 13:01:29 +02:00
Carles Cufi
ba2d2ee936 Bluetooth: controller: Replace master with central
Replace the old master term with the new central one
from the Bluetooth spec v5.3.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-21 13:01:29 +02:00
Carles Cufi
40e7f5cd73 Bluetooth: controller: Fix coding guidelines violation
Avoid using "free" since it's a reserved identifier, switch to
"free_idx".

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-21 13:01:29 +02:00
Carles Cufi
76bf881e42 Bluetooth: controller: Replace whitelist with FAL
Replace the old whitelist-related terms with the new filter accept list
one from the Bluetooth spec v5.3.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-21 13:01:29 +02:00
Carles Cufi
b8770acc28 Bluetooth: host: Align with terms in v5.3 spec
Align with the new inclusive naming terms in the v5.3 spec in the
Bluetooth Host implementation.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-20 20:01:32 +02:00
Carles Cufi
1821d342c2 Bluetooth: shell: Align with terms in v5.3 spec
Align with the new inclusive naming terms in the v5.3 spec in the
Bluetooth shell implementation.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-20 20:01:32 +02:00
Carles Cufi
3b33ba2320 Bluetooth: shell: Avoid reusing the same label
To avoid hitting the following violation:
Violation to rule 5.7 (Tag name should be unique)

Replace the use of "shell" in the shell as an instance of a pointer to
const struct shell.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-20 20:01:32 +02:00
Carles Cufi
f1dff28854 Bluetooth: controller: hci: Align to terms in the v5.3 spec
Align with the new inclusive naming terms in the v5.3 spec in the
controller's HCI implementation.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-20 20:01:32 +02:00
Vinayak Kariappa Chettimada
a9a01d4cb7 Bluetooth: Controller: Fix missing reset of Periodic Sync Create
Fix missing reset of Periodic Sync Create when HCI Reset is
performed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-20 12:26:51 +02:00
Vinayak Kariappa Chettimada
29ae143a10 Bluetooth: Controller: Refactor out initiator reset
Refactor out the initiator reset implementation into a
function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-20 12:26:51 +02:00
Emil Gydesen
bcc819028f Bluetooth: ISO: Add ISO tx callback struct array
Add an array similar to the bt_conn (ACL/L2CAP)
tx sent callback, and initialize it.

This increases the number of bt_conn_tx available
such that ISO does not take any of "L2CAP's" buffers,
but also ensures that the sent callback is called
for a broadcast iso only build.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-18 06:30:07 -04:00
Carles Cufi
1325edff48 Bluetooth: hci: Align terms with the Bluetooth v5.3 spec
The new inclusive naming terminology changes in v5.3 of the Bluetooth
specification affect the HCI layer, so apply all relevant changes to
align with it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-17 16:05:01 +02:00
Vinayak Kariappa Chettimada
417647f057 Bluetooth: Controller: Fix extended header data be zero-length array
Fix the definiion of Common Extended Payload Format data
field in the PDU definitions to be zero-length array,
because PDU size are configurable and to avoid allocations
being made using these PDU structs.

Corrected the extended scan response length check code to
use the correct define instead.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-17 14:30:27 +02:00
Vinayak Kariappa Chettimada
14b369eda8 Bluetooth: Controller: Fix to use ticks_drift for duration calculation
Fix Extended Advertising stop on duration by using the
ticks_drift which now includes the random delay and any
ticker rescheduling of advertising radio events due to
collision with other radio events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-17 14:30:07 +02:00
Vinayak Kariappa Chettimada
19fe102862 Bluetooth: Controller: Propagate ticks_drift in the ticker callback
The ticker `ticks_drift` is propagated via the ticker
elapsed callback, in order to provide necessary information
to correctly calculate total elapsed durations by states and
roles that use ticker extensions to mitigate scheduling
collisions by drifting within a permitted window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-17 14:30:07 +02:00
Vinayak Kariappa Chettimada
b01b5f6786 Bluetooth: Controller: Fix indentation in ticker interface file
Fix indentations in the ticker interface file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-17 14:30:07 +02:00
Lingao Meng
c4fbc5bb20 Bluetooth: host: Fix hci command done
When received hci command rsp which not for expected
hci command, we should ignore this.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-16 21:29:09 +03:00
Lingao Meng
61370f171c Bluetooth: host: Fix host send cmd complete to dis-conn
Fixes: #38054

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-16 21:29:09 +03:00
Vinayak Kariappa Chettimada
9e2b9c7a91 Bluetooth: Host: Fix Periodic Advertising Sync using Advertiser List
Fix Periodic Advertising Sync Establishment to accept
synchronization establishment to device listed in the
Periodic Advertisers List when filter policy was used.

Fixes #38520.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-16 16:35:45 +02:00
Vinayak Kariappa Chettimada
380a800b88 Bluetooth: Controller: Fix incorrect common header length calc
Fix incorrect calculation of received common extended header
length. Due to this a zero length advertising data is
reported in Extended Advertising and Periodic Advertising
report as one byte AD data.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-16 15:20:12 +02:00
Asbjørn Sæbø
e8620a7416 Bluetooth: Object Transfer Service: Defines for allowed object ID values
Add #defines for the maximum and minimum allowed values for object
IDs.

Moves the #define for the directory listing object ID to the public
header file

Having these limits available is useful for applications wanting to
ensure they pass in (or handle) valid object ID values.

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
2021-09-16 10:32:19 +02:00
Carles Cufi
6de4747979 Bluetooth: Update terms in public API to spec v5.3
The Bluetooth Core Specification, version 5.3, has introduced multiple
changes to several widely-used terms in order to make them inclusive.
Update the public API to reflect this, excluding hci.h, which will be
done in a subsequent commit.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-09-15 14:02:50 +03:00
Trond Einar Snekvik
035d877967 Bluetooth: Mesh: Inclusive terminology
Implements the Bluetooth appropriate language mapping for the Bluetooth
mesh subsystem.

Changes the following terms:

- Master security credentials -> Flooding security credentials
- Whitelist filter -> Accept filter
- Blacklist filter -> Reject filter
- Removes CDB's NODE_BLACKLISTED, which was not in use.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-09-14 19:30:18 +02:00
Kamil Gawor
50ff77fa91 bluetooth: Split configuration into separated Kconfigs
Extracted new Kconfig file for the Extended Advertising
and for the Bluetooth Isochronous Channel from the
Bluetooth subsystem Kconfig.

Signed-off-by: Kamil Gawor <Kamil.Gawor@nordicsemi.no>
2021-09-14 09:57:03 +02:00
Kamil Gawor
3f09f94bd2 bluetooth: Add missing choice names in Kconfig
This commit adds missing choice names in Bluetooth
subsystem Kconfig files.

Signed-off-by: Kamil Gawor <Kamil.Gawor@nordicsemi.no>
2021-09-14 09:57:03 +02:00
Kamil Gawor
c95ee1744f bluetooth: services: Use log template for BAS
The BAS serivce Kconfig uses now a log template instead of
defining logger configuration itself.

Signed-off-by: Kamil Gawor <Kamil.Gawor@nordicsemi.no>
2021-09-14 09:57:03 +02:00
Andrzej Kaczmarek
defda27969 Bluetooth: Controller: Properly terminate per adv HCI on failed rx
If one of AUX_CHAIN_IND is not received properly we need to send an
extra report over HCI to indicate that data are incomplete.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-09-13 21:41:04 -04:00
Michał Narajowski
88b60f31c7 Bluetooth: Mesh: Verify if Remote confirmation is not identical
MESH/PVNR/PROV/BI-18-C verifies that the IUT rejects invalid
Confirmation Value.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-09-13 11:56:52 -04:00
Rubin Gerritsen
f79fbeabd5 Bluetooth: Host: Allow setting more than 251 bytes of adv data
When the application sets more than 251 bytes of advertising data,
the data is sent over multiple HCI commands.
This is only allowed if the advertiser is not running
as defined by the HCI specification.

The data is sent to the controller one AD-field at the time.
If an AD-field is larger than BT_HCI_LE_EXT_ADV_FRAG_MAX_LEN,
the data is split over two commands.
This introduces some additional complexity.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-09-09 14:22:53 -04:00
Krzysztof Kopyściński
fa2f83bf8b Bluetooth: host: add testing API (disconnect one EATT channel)
To test fallback to remaining bearers PTS might request IUT to
disconnect one of the connected EATT channels, while the others remain
intact. Test function must be added, because we cannot create L2CAP
server on EATT PSM and manage this server as normal and have EATT
enabled at same time.

This is affecting GATT/SR/GAW/BV-14-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-09-09 10:30:31 +02:00
Michał Narajowski
343c0bd2d3 Bluetooth: Mesh: Check if app key is bound in Model Publication Set
Th Configuration Server should respond with and Invalid AppKey Index
status code when the AppKey identified by AppKeyIndex is not known to
the node or is not bound to the model identified by the ModelIdentifier.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-09-07 11:32:16 -04:00
Emil Gydesen
5b602eab90 Bluetooth: ISO: Add missing negation for valid_chan_io_qos
A check for valid_chan_io_qos in big_init_bis was missing
a negation when checking for invalid parameters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-07 16:31:32 +02:00
Vinayak Kariappa Chettimada
99bdd27100 Bluetooth: Controller: Fix multiple advertising set assert
Fix assert at line 1085 in ull_adv_aux.c due to auxiliary
offset calculation scheduling on ticker timeout under must
expire which can happen for overlapping multiple advertising
sets without previous calculation not complete, a single
mayfly instance is used hence the assertion.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-06 17:25:37 +02:00
Lingao Meng
ecc7ca1b69 Bluetooth: Mesh: Fix friend buf send end not called.
As frnd->last will keep reference, so that net buffer
destructor function will not be call.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-06 08:42:05 -04:00
Piotr Pryga
aecdf4c242 Bluetooth: controller: df: fix error in remove CTE from per adv
cte_info_clear function is responsible for remove of CTE from
periodic advertising PDUs, including remove from optional chained
PDUs. The function uses subortinate function rem_cte_info_from_per_-
adv_chain to remove CTE from chained PDUs.

The rem_cte_info_from_per_adv_chain had pdu_prev and pdu as arguments.
After return from the function the pdu_prev should point to last
PDU from previously used periodic advertising data and pdu should
point to last new periodic advertising data.

The rem_cte_info_from_per_adv_chain function removes CTEInfo from
all but last one PDU. Last PDU must have removed AuxPtr field also.
Remove of CTEInfo and AuxPtr from last PDU is done explicitly in
the cte_info_clear function.

Unfortunately rem_cte_info_from_per_adv_chain had wrong type of
parameters for pdu_prev and pdu. These parameters were pointers
instead od double pointers.
That caused cte_info_clear function to remove CTEInfo and AuxPtr
from first PDU in a chain, which is AUX_SYNC_IND.

Changed parameters pdu_prev and pdu in the rem_cte_info_from_per_adv_-
chain to be double pointers.

Added small corrections in comments.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
Co-authored-by: Emil Gydesen <Thalley@users.noreply.github.com>
2021-09-04 10:54:36 -04:00
Lingao Meng
790ec89048 Bluetooth: Mesh: Fix missing destructor function
Zephyr Bluetooth Mesh move adv send cb to buf destructor
callback, There are two net_buf_pool define, one to adv.c
and ore to friend.c, we are missing destructor in friend.c.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-09-03 06:32:08 -04:00
Emil Gydesen
0ffb084bfb Bluetooth: iso: Fixes ISO paramter checking issues
Two checks reported wrong value if the value was invalid.
CIS parameter check would always fail on correct values
due to missing negation of valid_chan_qos.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-03 06:31:45 -04:00
Michał Narajowski
f51cf9ab86 Bluetooth: mesh: Fail provisioning when RFU values are used
When Public Key field is set to RFU value then we should send
Provisioning Fail with Invalid Format error.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-09-02 19:38:52 -04:00
Vinayak Kariappa Chettimada
b51021af3c Bluetooth: Host: Fix MPU fault due to incorrect EV_COUNT
Fix MPU fault due to incorrect EV_COUNT, `conn_change`
signal was not accounted for in the array used by k_poll.

Relates to commit 7854088116 ("Bluetooth: ISO: Fixes
missing handling of broadcast ISO TX").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-02 19:38:16 -04:00
Emil Gydesen
12a26649f5 Bluetooth: ISO: Wait for ISO disconnect event
Instead of disconnecting ISO channels on ACL,
we put them in a non-connected state, and wait for
the ISO disconnect events.

This ensure that the controller has free'd the
ISO channels when the iso disconnect callbacks
are received. It will thus be possible to e.g.
terminate the CIG on the ISO disconnect callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-02 19:37:28 -04:00
Emil Gydesen
5d14cddaa8 Bluetooth: ISO: Fixes ISO central disconnect and cleanup issues
When an ISO channel is disconnect on the central, it is
not deallocated, but merely disconnected. This is because,
as per the HCI spec, the CIS handle lives on in the CIG.

Instead of unref'ing the bt_conn to 0, we simply put the
channel and connection in the disconnected state.

This also fixes a few missing returns for
terminating a CIG.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-02 19:37:28 -04:00
Emil Gydesen
3a77308c97 Bluetooth: ISO: Add sent callback
Add a sent callback to bt_iso_chan_ops so that the application
can be notified when an SDU has been sent. This can help the
application decide whether to queue up multiple, or only
have a single ISO PDU enqueue for reduced latency.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-02 05:58:39 -04:00
Kumar Gala
13ba7c7825 Bluetooth: ISO: Fix build on native_posix_64 with debug
On native_posix_64 we get the following compile error in CI:

error: format %u expects argument of type unsigned int

Fix by using %zu instead of %u as type is of size_t.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-09-01 12:27:41 -04:00
Emil Gydesen
93bfe7a2c9 Bluetooth: ISO: Update BIS index to start from 0x01
The HCI spec defines the BIS index range as starting from
index 0x01. We had previously implemented it such that it
starts from 0x00, and then simply adding 1 to the index
when sending over HCI. However, this may cause issue with
other HCI, or other SIG defined specification, commands
and events, and thus it is probably simpler if we just
use the HCI defined range.

This commit disallows BIT(0) (representing the BIS
index 0x00) to be set, and removes the addition
of 1 when sending over HCI.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-01 10:57:07 -04:00
Vinayak Kariappa Chettimada
ced2116428 Bluetooth: Controller: Fix null pointer dereferencing in periodic sync
Fix null pointer deferencing in Periodic Synchronization
when ULL execution context could not assign an auxiliary
context when in LLL scheduling to receive chain PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-01 08:38:37 -04:00
Vinayak Kariappa Chettimada
a63158fdde Bluetooth: Controller: Fix null pointer dereferencing in Extended Scan
Fix null pointer dereferencing in Extended Scanning when
there are more peer devices than the allocated auxiliary
contexts.

When LLL scheduling does not get an auxiliary context
assigned in the ULL execution context, then further chain
reception is aborted, access to `lll->lll_aux` which is
NULL causes null pointer dereferencing in
`ull_scan_aux_release`.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-01 08:38:37 -04:00
Vinayak Kariappa Chettimada
b26c27f307 Bluetooth: Controller: Use lll_aux param for aux context release
When Extended Initiating a connection, release auxiliary
context memory referenced by the lll_aux pointer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-01 08:38:37 -04:00
Vinayak Kariappa Chettimada
a633c00096 Bluetooth: Controller: Update Periodic Sync drift compensation
Update Periodic Advertising Synchronization's drift
compensation to save radio ready and address capture on
AUX_SYNC_IND reception, restore and apply at the end of
reception of all AUX_CHAIN_IND PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-09-01 08:38:37 -04:00
Emil Gydesen
0c7eda9777 Bluetooth: ISO: Pointer check in bt_iso_connected was incorrect
Instead of checking `if (iso == NULL)` it simply checked
`if (iso)` which is the opposite of what it should have done.

This completely blocks iso from connecting channels.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-09-01 08:38:12 -04:00
Michał Narajowski
e93b41a21a Bluetooth: host: Fix Limited Advertising timeout cancel
Timeout cancel should only be done for connections established in
peripheral role.

Enhanced connection complete event could still be delivered without
extended advertising support (i.e no advertising set terminated event)
so this handling should be moved to the common conn complete function.

Fixes #37467

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-08-31 15:35:47 -04:00
Trond Einar Snekvik
c5757ca4a1 Bluetooth: Mesh: Initialize UUID in shell's mod_pub_set
PR #35774 introduced a uuid field in the bt_mesh_cfg_mod_pub structure.
The shell does not initialize this pointer before passing it to the
access layer. Add a line to initialize this pointer.

Fixes #38016.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-08-31 11:03:06 -04:00
Trond Einar Snekvik
4eb047d1af Bluetooth: Mesh: Remove lpn timeout param check
param can never be NULL here, so the check is redundant. Coverity is
complaining because param is accessed before the NULL check.

Fixes #37949.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-08-31 11:03:06 -04:00
Trond Einar Snekvik
fd6f51c410 Bluetooth: Mesh: Remove krp param check
param can never be NULL, so this check is redundant. Coverity complains
about this, as the param variable is accessed before the check, which
would be wrong if param could be NULL.

Fixes #37948.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-08-31 11:03:06 -04:00
Vinayak Kariappa Chettimada
5f55d8ef78 Bluetooth: Controller: Fix uninitialized pointer read of SR ADI
When Extended Scan Response data of length zero is set, the
Scan Response do not have the Common Extended Payload Format
and hence no ADI field. Fix uninitialized pointer to Scan
Response Data's ADI to avoid copy of ADI from primary
channel PDU.

Fixes #38015.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-31 14:04:28 +02:00
Lingao Meng
faf9efcb47 Bluetooth: host: Fix missing attr when indicate
When call bt_gatt_indicate with param->attr set to null.
and attr->uuid set to given uuid, the internal notify will
search uuid, but not assigned to param->attr, which cauce
null point reference when:
notify --> gatt_indicate --> bt_gatt_check_perm

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-30 13:41:03 -04:00
Lingao Meng
6ebdbe5974 Bluetooth: Fix missing rewrite attr
When call `bt_gatt_notify_cb` with param->attr set to null.
and attr->uuid set to given uuid, the internal notify will
search uuid, but not assigned to param->attr, which cauce
null point reference when:
   notify --> gatt_notify  --> bt_gatt_check_perm

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-30 13:41:03 -04:00
Michał Narajowski
a9db9a3aa8 Bluetooth: host: Cancel limited adv timeout when advertising stopped
Advertising might stop when:
- it was stopped by application
- device connected to a peer
- extended advertising reached stop condition
  defined in BT_LE_EXT_ADV_START_PARAM - this is handled in ll

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-08-30 14:41:20 +02:00
Michał Narajowski
cca76f157c Bluetooth: host: Fix advertise stop in adv_timeout()
Call bt_le_adv_stop() if adv == bt_dev.adv (Meaning it is the legacy
advertiser and was started with bt_le_adv_start()), otherwise use
bt_le_ext_adv_stop(), because it was started with bt_le_ext_adv_start().

Failing to stop advertising shouldn't result in assert.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-08-30 14:41:20 +02:00
Andrzej Kaczmarek
f2f99c0784 Bluetooth: Controller: Remove redundant local variable
'err' is already defined in parent scope, we can use. Just need to set
it back to 0 before returning from function.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
b308192bb1 Bluetooth: Controller: Add todos for per adv chain scan
Add todos for few useful improvements that can be done later.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
993838edbf Bluetooth: Controller: Make lll_create_iq_report static again
This was changes when sync chain handling was done in lll_scan_aux, we
can now revert to original code.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
1e6c69bc89 Bluetooth: Controller: Update BT_CTLR_ADV_EXT_RX_CNT for ea and df
We need more RX nodes when scanning either extended/periodic advertising
trains and CTE samples so pudate those values based on observer and DF
features enabled.

The number of nodes for non-DF allows to scan complete chain for each
aux scan set (assuming max data length and optimal fragmentation by
advertiser), for DF it allows to scan max possible PDUs and CTE samples.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
11da89cff1 Bluetooth: Controller: Remove unused flag
This seems not to be needed anymore, it's only written.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
88b4f45eae Bluetooth: Controller: Move aux sync scanning to lll_sync
Periodic advertising train scanner implemented in lll_scan_aux adds lots
of branches that cannot be compiled out with periodic advertising sync
disabled.

This commit moves sync parts of the code from lll_scan_aux to lll_sync.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
f353202eb7 Bluetooth: Controller: Fix DF for per adv chains scanning
This updates DF to properly receive CTE in per adv chains scanning.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
0723e7dc5e Bluetooth: Controller: Rework support for periodic adv reports
Periodic advertising PDUs are now dispatched immediately one by one
(i.e. without list of PDUs as when flushed from aux context) so we
do not need to iterate such a list.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
139711fd74 Bluetooth: Controller: Fix parsing sync report PDU
AdvA, TargetA, ADI and SyncInfo are RFU in periodic advertising PDUs so
we should ignore them when present in PDU.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
846f5e7b4a Bluetooth: Controller: Dispatch rx nodes for sync immediately
Periodic advertising reports can be reated directly from single PDU
as they do not require any information from superior PDU, so we can
dispatch them immediately instead of buffering in aux context and
flushing at the end of chain.

This also resolves proper order of Periodic advertising and IQ reports.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
e2cd879539 Bluetooth: Controller: Store parent lll struct in aux context
We use 1st node enqueued in aux context to retrieve lll scan/sync
struct, but that only works if we buffer PDUs in aux context. It's
better to store parent lll struct as explicit member in aux context
as this also works if we skip buffering.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
17a2e3a4ba Bluetooth: Controller: Add chain scanning for per adv
This adds complete support for scanning for periodic advertising trains.

AUX_SYNC_IND is always scheduled from ULL as usual, then code for aux
scanning is reused to allow for AUX_CHAIN_IND scanning scheduled from
both ULL and LLL, depending on AuxPtr.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
103bdb43ef Bluetooth: Controller: Simplify aux flush
aux->rx_last cannot be NULL since it's always set after acquire to a
valid node so the flow in flush() can be simplified.

rx parameter is only used to update PDU chain, then it's overwritten,
so we can instead update PDU chain in caller since there's only one
place when this should happen.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
ee0f93a9c3 Bluetooth: Controller: Fix aux scanning with mixed ULL/LLL sched
We should decide on flush immediately vs. from disabled_cb based on
ull_hdr reference count instead of last rxd node - if ull_hdr has
non-zero ref, then done event is still pending and we should flush
from there.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Andrzej Kaczmarek
a80f5b2081 Bluetooth: Controller: Set default HCI event size with per adv
Periodic advertising reports can have 255 bytes of payload so need to
use that value by default if periodic advertising is enabled.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-27 11:46:31 -04:00
Emil Gydesen
8490508b59 Bluetooth: ISO: Make ISO/ACL bt_conn pointers clear in ISO API
Update the name of the bt_conn pointers to make it clear
whether the connection pointers are ACL or ISO connections.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-27 11:46:07 -04:00
Emil Gydesen
ecb265be36 Bluetooth: ISO: Clear up ACL/ISO bt_conn pointer names
Make the name of the internal bt_conn pointers explicit as to
whether they point to an ACL or ISO bt_conn.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-27 11:46:07 -04:00
Emil Gydesen
d8d8d82f0e Bluetooth: ISO: Add ISO limits as #defines and use them
Add #define's for ISO HCI limits and use them to validate
input parameters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-27 09:34:43 -04:00
Vinayak Kariappa Chettimada
50280c67cf Bluetooth: Controller: Ignore PDU with RFU field set
Ignore received Extended Advertising PDU with RFU field set
in the Common Extended Advertising Payload Format of the
PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 09:34:16 -04:00
Vinayak Kariappa Chettimada
41ed5b2173 Bluetooth: Controller: Use defines to access hdr_data fields
Use defines to access hdr_data fields used by interfaces to
populate the Common Extended Advertising Payload Format in
the PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 09:34:16 -04:00
Vinayak Kariappa Chettimada
e976a146d2 Bluetooth: Controller: Use define for channel map size
Use a defined for channel map size of 5 octets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 09:34:16 -04:00
Vinayak Kariappa Chettimada
cf3b04534e Bluetooth: Controller: Periodic Adv Review Rework
Changes addressing Periodic Advertising and Synchronization
Channel Map Update Indication feature.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 09:34:16 -04:00
Vinayak Kariappa Chettimada
e5d93d5757 Bluetooth: Controller: Use helper function to check instant past
Use a helper function to check at instant or past to apply
the channelMapNew.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 09:34:16 -04:00
Vinayak Kariappa Chettimada
bb51848b93 Bluetooth: Controller: Use defined for event instant and latency max
Use defines for event instant and event instant latency
maximum values of 65536 and 32767 respectively.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 09:34:16 -04:00
Vinayak Kariappa Chettimada
b76070d57a Bluetooth: Controller: Periodic Sync with Chan Map Update Indication
Added implementation in Periodic Advertising Synchronization
to support Channel Map Update Indications present in the
ACAD fields of the AUX_SYNC_IND PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 09:34:16 -04:00
Vinayak Kariappa Chettimada
fbc7cafaf5 Bluetooth: Controller: Periodic Advertising Chan Map Update Indication
Added implementation to perform Periodic Advertising Channel
Map Update Indication as a Broadcaster.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 09:34:16 -04:00
Vinayak Kariappa Chettimada
c5e077c48f Bluetooth: Controller: Make node rx release code conditionally reusable
Make the block of code that is used to release node rx with
type NODE_RX_TYPE_RELEASE to be conditionally available for
other Kconfig selectable features like Extended Scanning.

Previously it was only available for CONFIG_BT_CONN, but now
Extended Scanning with LLL scheduling releases node rx when
radio event is closed due to failure to receive an auxiliary
PDU.

Relates to commit 2feffaf719 ("Bluetooth: Controller:
Release LLL scheduling aux on incomplete data").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 06:47:42 -04:00
Vinayak Kariappa Chettimada
fa02dc4d02 Bluetooth: Controller: Fix missing reset of connection handle
Fix missing reset of connection handle in the LLL context.
During a central connection, if LL reset is called, then
disabled connection context's handle has to be reset
otherwise new connection creation will fail by detecting
that there exists a connection to same peer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 06:47:21 -04:00
Vinayak Kariappa Chettimada
19099fc980 Bluetooth: Controller: Use define for invalid LLL context handle
Use a define for invalid LLL context handle instead of
0xFFFF magic value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 06:47:21 -04:00
Vinayak Kariappa Chettimada
631cc825da Bluetooth: Controller: Add same peer connection check to initiator
Add implementation to initiator to check and reject
connection requests to already connected peer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 06:47:21 -04:00
Vinayak Kariappa Chettimada
1c564e750b Bluetooth: Controller: Use id addr type to check same peer connection
Store and check device identity addr type of public or
random.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 06:47:21 -04:00
Vinayak Kariappa Chettimada
22a48e502e Bluetooth: Controller: Minor rename of disabled callback functions
Minor rename of Connection ISO disabled callback function
names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 06:46:55 -04:00
Vinayak Kariappa Chettimada
f06ac2be2c Bluetooth: Controller: Fix LLL events pending check from ULL Low
ULL reference count is checked in ULL_LOW context to decide
if LLL events are pending, but the reference count can be
decremented by the ULL HIGH execution context which can
prevent the set `disabled_cb` function not being called due
to no pending event to produce the done events.

Fixed by checking the reference count in the ULL HIGH
execution context using a mayfly to schedule the check.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 06:46:55 -04:00
Vinayak Kariappa Chettimada
d2be89d725 Bluetooth: Controller: Use consistent naming for ticker op callbacks
Use consistent naming for ticker operation callback
functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-27 06:46:55 -04:00
Pavel Vasilyev
cd294c12c3 tests: Bluetooth: Mesh: Verify that all stored mesh entries removed
This ensures that all mesh settings were removed from persistent storage
after node reset.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-08-26 14:04:38 -04:00
Joakim Andersson
334369ab44 Bluetooth: host: Fix dereference before null check
Fix dereference before null check in att.c

Fixes: #37947

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-26 13:57:16 -04:00
Vinayak Kariappa Chettimada
2e9f6d0201 Bluetooth: Controller: Remove unused PDU size defines
Remove unused legacy PDU size extra defines.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-26 13:42:41 -04:00
Vinayak Kariappa Chettimada
af41a508d6 Bluetooth: Controller: Fix radio packet size for Extended Scanning
Fix maximum radio packet size configuration to use 255 bytes
for Extended Scanning and Periodic Synchronization.

Add a Kconfig option so that application can reduce RAM
usage if a specific user scenario can live with smaller PDU
receptions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-26 13:42:41 -04:00
Vinayak Kariappa Chettimada
d3bda1dc06 Bluetooth: Controller: Minor rearrange rx packet set after radio config
Minor rearrange of rx packet set statements after radio
configuration function calls.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-26 13:42:41 -04:00
Piotr Pryga
2897870fa5 Bluetooth: controller: Fix aux ptr offset calculation for S2 Coded PHY
In the calculation of auxiliary PDU offset for periodic advertising
AUX_CHAIN_IND PDUs there were used old macro that was removed.
The code didn't compile.
Also there were no support for S2 Coded PHY in the offset calculation.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-26 13:14:38 -04:00
Emil Gydesen
4bd326d6c9 Bluetooth: ISO: Remove use of conn->channels for ISO
The channels list were originally meant to be used
for multiple bt_iso_chan per iso connect (bt_conn), but
that is not the case for the current API, and won't be
going forward, so the use of the list has been removed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-26 13:14:22 -04:00
Emil Gydesen
51f2022f7b Bluetooth: Audio: Add initial server values in bt_vcs_register_param
Add support for setting initial values in bt_vcs_register_param
when registering a VCS service

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-26 09:13:58 -04:00
Emil Gydesen
9341a3d50c Bluetooth: ISO: Add NULL check in bt_iso_big_sync
Verify that the ISO channels supplied by the caller
are non-NULL.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-26 09:12:47 -04:00
Emil Gydesen
581d07e494 Bluetooth: ISO: Add NULL check in bt_iso_big_create
Verify that the ISO channels supplied by the caller
are non-NULL.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-26 09:12:47 -04:00
Emil Gydesen
06ebe239c1 Bluetooth: ISO: Add NULL check in cleanup_big
In case that creating a BIG fails due to missing
ISO channel, cleanup_big would try to access a
NULL pointer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-26 09:12:47 -04:00
Vinayak Kariappa Chettimada
2f38c522fd Bluetooth: Controller: Remove ULL header include in LLL
Do not include ULL header in LLL, instead values and fields
required in LLL shall be declared in LLL contexts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-26 06:55:43 -04:00
Vinayak Kariappa Chettimada
43d8d34dc4 Bluetooth: Controller: Remove memcpy of SCAN_REQ and CONN_REQ PDUs
Removed implementation that used memcpy of received PDUs and
instead using the free Rx buffers; use the scratch PDU for
transmitting scan requests and connection requests.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:07:53 -04:00
Vinayak Kariappa Chettimada
c409b74f0d Bluetooth: Controller: Add lll_prof_reserve profiling function
Add the lll_prof_reserve and lll_prof_reserve_send profiling
functions to use when profiling active scanning and
initiator.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:07:53 -04:00
Vinayak Kariappa Chettimada
7426045a28 Bluetooth: Controller: Define invalid/unassigned node rx handle value
Add a define for invalid/unassigned node rx handle value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:07:53 -04:00
Erik Brockhoff
f41b3d7879 Bluetooth: Controller: Fix conn param req ack/req reset
llcp.conn_param.ack was reset on tx of conn param rsp, however this
should only be done once the expected conn update ind is received
and sets the cu.ack flag to indicate cu procedure 'takes over'.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:07:35 -04:00
Vinayak Kariappa Chettimada
5123b45761 Bluetooth: Controller: Initial support for advertising on S2/S8 coding
Added implementation to support advertising on S2/S8 coding
scheme.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:06:47 -04:00
Vinayak Kariappa Chettimada
193ce73109 Bluetooth: Controller: Fix missing resume of primary channel scanning
Fix missing implementation to release Auxiliary PDU chains
and then resume back to scanning on primary channel.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:06:47 -04:00
Vinayak Kariappa Chettimada
1ce46fd7a6 Bluetooth: Controller: Add PDU time calculation for S2 Coded PHY
Add PDU time calculation macro for S2 and S8 Coded PHY.
Rename PKT_AC_US to PDU_AC_MAX_US.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:06:47 -04:00
Vinayak Kariappa Chettimada
88b155de31 Bluetooth: Controller: Rename PKT_US to PDU_DC_MAX_US
Rename PKT_US to PDU_DC_MAX_US.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:06:47 -04:00
Vinayak Kariappa Chettimada
869d3c24d7 Bluetooth: Controller: Rename PKT_DC_US to PDU_MAX_US
Rename PKT_DC_US to PDU_MAX_US.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:06:47 -04:00
Vinayak Kariappa Chettimada
48f5990eea Bluetooth: Controller: Add missing range delay for extended active scan
Add missing range delay value when calculating the header
complete timeout value for the reception of extended scan
response PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:06:47 -04:00
Vinayak Kariappa Chettimada
6911e7e1d8 Bluetooth: Controller: Use the received coding scheme when scanning
Use the received coding scheme when scanning for correctly
calculating the receive chain delay and on-air PDU time.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:06:47 -04:00
Vinayak Kariappa Chettimada
cee9ce6b8e Bluetooth: Controller: Add Coded PHY Rx-ed coding get interface
Added a radio interface to fetch the received Coded PHY
coding scheme of the PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-25 18:06:47 -04:00
Emil Gydesen
7854088116 Bluetooth: ISO: Fixes missing handling of broadcast ISO TX
After 31045c7 was merged, it was possible to use broadcast
iso without CONFIG_BT_CONN, but it did not properly handle
TX as there were missing support to read the buffer
size from the controller, as well as missing support
for handling the number of completed packets event.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-25 18:06:09 -04:00
Emil Gydesen
96dfad0eef Bluetooth: host: Add ISO support for num_completed_packets event
Change so that num_completed_packets event handling is also
enabled for broadcast ISO only builds. This is because sending
data on a broadcast ISO still generates this event.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-25 18:06:09 -04:00
Emil Gydesen
24226b0135 Bluetooth: Host: Move bt_conn_create_pdu* out of ACL group
Move the function out of the ACL group as it may be used
for broadcast ISO only builds.

er 31045c7 was merged, it was possible to use broadcast
iso without CONFIG_BT_CONN, but it did not properly handle
TX and RX as there were missing support to read the buffer
size from the controller, as well as missing support
for handling the number of completed packets event.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-25 18:06:09 -04:00
Johann Fischer
9ad610d1a7 bluetooth: remove Kconfig options CONFIG_BT_*_ON_DEV_NAME
Follow up on commit bfd45e5b8c
("drivers: remove Kconfig option CONFIG_UART_CONSOLE_ON_DEV_NAME")
Remove Kconfig options
CONFIG_BT_UART_ON_DEV_NAME and CONFIG_BT_MONITOR_ON_DEV_NAME
since all UART drivers are converted to devicetree and we can just use
DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_uart)) and
DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_mon_uart)).

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-25 18:05:17 -04:00
Piotr Pryga
0395f46126 Bluetooth: controller: hci: Add missing DF conn-less cmds to supp list
There were missing commands in local supported commands list that
are related with connectionless direction finding.
The commands are implemented but they haven't been added
to HCI_Read_Local_Supported_Commands list.
The commit fixes that.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-25 18:02:39 -04:00
Vinayak Kariappa Chettimada
e4ed1d32be Bluetooth: Controller: Schedule LLL prepare before scan train code
Move the implementation of scan trains after call to LLL
prepare, so that LLL prepare executes without any latency.

To increase radio utilization, LLL prepare should be
scheduled as early in the `ticker_cb` of the radio event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-24 07:35:59 -04:00
Vinayak Kariappa Chettimada
7d1404a717 Bluetooth: Controller: Fix return value for unassigned aux context
Fix the return value use to indicate unassigned auxiliary
context when scanning is using LLL scheduling. This can
happen only under LLL scheduling where in LLL auxiliary
channel PDU reception has been spawn from LLL primary
channel scanning and on completion will join back to resume
primary channel PDU scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-24 07:35:24 -04:00
Vinayak Kariappa Chettimada
01393382d7 Bluetooth: Controller: Update AD Data PDU allocation configurability
Update the calculation for configurable amount of shared
PDUs across advertising sets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-24 07:33:48 -04:00
Vinayak Kariappa Chettimada
41bb453948 Bluetooth: Controller: Keep the default AD Data length to 31 octets
Keep the default AD Data length to Bluetooth Specification
defined minimum of 31 octets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-24 07:33:48 -04:00
Emil Gydesen
76091850c5 Bluetooth: sample: Update iso_connected_benchmark to use new ISO API
Update the sample to use the new ISO API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-24 07:29:11 -04:00
Emil Gydesen
7037b11e1a Bluetooth: shell: Update ISO shell to new API
Update the ISO shell commands to use the new
ISO API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-24 07:29:11 -04:00
Emil Gydesen
c47dae8c6d Bluetooth: ISO: Update connected ISO API
Update the connected ISO API to be more
similar to the broadcast ISO API as well
as the HCI spec.

This updated API allows for more flexibility
and will better support scenarios such as true
wireless setup, as ISO channels and connections
are more independent now.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-24 07:29:11 -04:00
Vinayak Kariappa Chettimada
c74fe1f009 Bluetooth: Controller: Fix scan window resume after extended scan
Fix implementation to not to put back the primary channel
scanning to resume state when Extended Scan has used ULL
scheduling which pre-empts the scan window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-24 07:27:35 -04:00
Johann Fischer
c3313c1dc1 bluetooth: monitor: remove CONFIG_UART_CONSOLE_ON_DEV_NAME
Replace with DT_LABEL(DT_CHOSEN(zephyr_console)).

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-23 18:53:47 -04:00
Vinayak Kariappa Chettimada
14fbcffbc7 Bluetooth: Controller: Simplify clearing of extended scan response data
Simplify implementation that clears extended scan response
data by moving the length check after the new PDU buffer
has been correctly initialized.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-23 08:23:36 -04:00
Vinayak Kariappa Chettimada
c0d569d233 Bluetooth: Controller: Check for invalid PHY in Aux Ptr
Add check to validate PHY value in the Auxiliary Pointer
structure in the common extended header format.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-23 08:22:32 -04:00
Vinayak Kariappa Chettimada
95e0f63bbd Bluetooth: Controller: Use one bit for Extended Scan Filter Directed
Use one bit to represent the Extended Scan Filter Directed
Advertising Report.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-23 08:22:10 -04:00
Mark Wang
c11ef74605 Bluetooth: SDP: add one API bt_sdp_get_add_proto_param
The bt_sdp_get_add_proto_param is used to get the protocol
parameter from Additional Protocol Descriptor List.
In order to implement it, one parameter
(proto_profile_index) is added to sdp_get_uuid_data_index
to get the indexed item.
Fix one bug in sdp_get_uuid_data because there may be more
than 2 consequent "seq len item".

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2021-08-23 15:11:24 +03:00
Joakim Andersson
d76bba4b5e Bluetooth: host: Device name handling of invalid length
Add a build assert if the device name has been misconfigured. The device
name has a max length of 248. When configured as dynamic make sure that
the initial device length can fit in the dynamic max length.
This prevents us from having to handle length overflow when setting
device name in advertising data which has an 8-bit length field.

Log a warning if failing to set the device name in bt_enable.
Remove unused defines in the shell.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-20 18:56:38 -04:00
Joakim Andersson
8672976120 Bluetooth: shell: Fix adv-data command hex data input
Fix adv-data command when given arbitrary advertising data in
hexadecimal format. The data_len field should contain the length of the
data which does not include the data type. Instead the AD len field in
the data was given. This caused the AD len field to be increased by 1
in the advertising dat.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-20 18:56:38 -04:00
Rubin Gerritsen
1aa3a77130 bluetooth: smp: Fix duplicate pairing_failed callback
In the case where keys are distributed on an unencrypted link,
we got the following call trace:
  - bt_smp_recv()
    - smp_error()
    - smp_pairing_complete()
      - bt_conn_security_changed()
      - smp_pairing_complete()
        - bt_auth->pairing_failed()
        - smp_reset()
      - bt_auth->pairing_failed()
      - smp_reset()

To avoid the second call to bt_auth->pairing_failed()
we validate the that smp flags before calling the callback.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-08-20 18:55:33 -04:00
Emil Gydesen
aa9a2aac0c Bluetooth: host: Remove reset of conn handle on disconnect
(Re)setting the connection handle in hci_disconn_complete
should not be done as the handle are used for
logging/debugging purposes after this, and makes it
impossible to lookup the handle of disconnected
connections.

The connection handle is set to 0 during bt_conn_new
in any case.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-20 12:54:39 +02:00
Krzysztof Kopyściński
852656d1ff Bluetooth: host: initialise mps_reduced to false in ecred reconf req
No initialisation will lead to undefined behaviour in check for
BT_L2CAP_RECONF_INVALID_MPS.

This is affecting L2CAP/ECFC/BV-23-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-08-20 12:54:29 +02:00
Vinayak Kariappa Chettimada
80f382e51e Bluetooth: Controller: Fix sync of primary and auxiliary adv terminate
Fix missing synchronization when stopping primary and
auxiliary PDU scheduling.

Added implementation to ensure primary and auxiliary event
count match when terminating extended advertising on maximum
number of events or on duration.

Fixes #37571.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-20 12:49:43 +02:00
Vinayak Kariappa Chettimada
462ac6dcd1 Bluetooth: Controller: Minor refactor of extra done type set function
Minor refactor of extra done memory get and type set
functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-20 12:49:43 +02:00
Vinayak Kariappa Chettimada
76d7f6364e Bluetooth: Controller: Correctly initialize max events and duration
Max events and duration parameter are not used in high duty
cycle directed, hence correctly initialized them and not
depend on the caller of advertising start API to set them
to zeroes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-20 12:49:43 +02:00
Trond Einar Snekvik
69fcaaa592 Bluetooth: Mesh: Use separate net_bufs for bt_mesh_app_decrypt in friend
unseg_app_sdu_decrypt decrypts messages in place using a single net_buf.
While this is safe in terms of data access, the buffer state is
manipulated with the assumption that they're two different buffers, and
the output buffer's length field is increased at the end. When
assertions are enabled and the pdu length is 11 or 12 bytes, this
triggers the net_buf length assert, as the decrypt function attempts to
add the pdu length to the out buffer, with the assumption that it was
reset before decryption was started.

Create a separate output buffer with len = 0 to avoid triggering the
assert. Improve readability of the unseg_app_sdu functions to highlight
the need for the additional buffer.

Fixes #37519.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-08-20 12:49:28 +02:00
Joakim Andersson
ce2fdd84ff Bluetooth: host: Allow app to set scannable when not providing scan data
Allow the application to configure the advertiser as scannable when it
does not provide scan data in the call to bt_le_adv_start. This makes it
possible for the application to later add scan response data in the
bt_le_adv_update_data call.
This aligns the legacy code path with the extended code path which
already had this behavior.

This also stops a directed connectable advertiser from being marked
internally in the host as scannable. This appears to not have been
causing any issues.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-20 12:49:06 +02:00
Joakim Andersson
750782ba46 Bluetooth: host: Fix non-connectable advertiser configured as scannable
Fix non-connectable advertiser configured as ADV_SCAN_IND when
configured by application to have the device name appear in the
advertising data instead of the scan response data.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-20 12:49:06 +02:00
Joakim Andersson
5ab34fab13 Bluetooth: host: Fail create ext scannable advertiser with name in AD
Disallow creating an extended scannable advertiser with the device name
configured to appear in the advertising data.
This would fail in either the call to bt_le_ext_adv_start or
bt_le_ext_adv_set_data when the host would try to set advertising data
in the controller.
Instead this now fails in the bt_le_ext_adv_create call.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-20 12:49:06 +02:00
Joakim Andersson
2ad039d9d0 Bluetooth: shell: Add option to set name in advertising data
Add advertising option to set the force advertising name in advertising
data option.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-20 12:49:06 +02:00
Lingao Meng
4a8a1577ef Bluetooth: Mesh: Redefine callback registration
There is a problem with the previous method, that is,
we use the same label(bt_mesh_subnet_cb_subnet_evt) and
put it in the same section, which is not friendly for debugging.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-20 06:28:12 -04:00
Asbjørn Sæbø
252a9bad9a Bluetooth: ots: Fix output formatting
Fix output formatting after changes in
https://github.com/zephyrproject-rtos/zephyr/pull/36653/
causes Twister build fails in pending le-audio code.

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
2021-08-19 10:20:37 -04:00
Omkar Kulkarni
f868ca3497 bluetooth: mesh: Fix IVU duration counter update
When device is first provisioned with IV Update
flag is set to 0, it should wait for minimum of
96 hours before going into IV Update In Progress
state. Such limit does not apply, if device is
provisioned with IV Update flag is set to 1.

Signed-off-by: Omkar Kulkarni <omkar.kulkarni@nordicsemi.no>
2021-08-19 10:19:43 -04:00
Pavel Vasilyev
0e9d668970 Bluetooth: Mesh: Add API to discard subscription in vendor model
This commit adds missing API that allows to discard the Subscription
List of a vendor model.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-08-19 10:19:02 -04:00
Pavel Vasilyev
538f97f737 Bluetooth: Mesh: Clarify name length in bt_mesh_model_data_store
Name length can't be longer than 8 bytes. This needs to be clarified
in the bt_mesh_model_data_store() documentation.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-08-19 10:19:02 -04:00
Emil Gydesen
03c3a31be9 Bluetooth: Iso: Change set CIG parameters fail to unref
Change the fail handling of setting the CIG parameters
(or when allocating the CIS) to unref the ISO conns
instead of calling cleanup on them directly.

This fixes an issue that if the CIG parameters failed,
then the iso conns would not be unref'ed and we could
not try again.

Unref'ing an iso conn will call cleanup once it hits 0
refs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-19 10:18:28 -04:00
Emil Gydesen
393436c773 Bluetooth: ISO: Add log if cleanup fails to remove the CIG
Add an warning log message if the CIG failed to be removed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-19 10:18:28 -04:00
Emil Gydesen
a0cec00807 Bluetooth: ISO: Add iso channel state check for unbind
A channel should only be allowed to unbind when in
the BT_ISO_BOUND state. If it is in a disconnected state,
then it the function would have meaning. If it is a connected
state, unbinding it would generate an error when removing
the CIG, which would fail silently.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-19 10:18:28 -04:00
Piotr Pryga
a947d5aa24 Bluetooth: controller: Extend HCI TX cmd buf size for CTE rx param cmd
LE Set Connection CTE Receive Parameters HCI command size may not fit
into HCI TX command buffer size, which default value is 65 bytes.
For platforms other than Nordic there may be up to 75 antenna IDs
put into the command.
Added new default value for SOCs not compatible with Nordic to
extend default TX buf size to 83 bytes (75 bytes for antena IDs,
5 bytes for other command parameters, 3 bytes for command header).

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-18 20:11:10 -04:00
Piotr Pryga
0b07a7812e Bluetooth: controller: add functions to enable CTE req LLCP
Add functions that handle enable CTE request control procedure
request from host.
Implementation of ll_df_set_conn_cte_req_enable in ULL is partial.
It will be integrated with refactored implementation of control
procedures.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-18 20:11:10 -04:00
Piotr Pryga
8382d6e5be Bluetooth: controller: Add CTE Rx params struct to lll_conn declaration
Add struct ll_df_conn_rx_params sturcutre to struct lll_conn.
This is storage for parametrers required to configure radio
for CTE reception in connected mode by lower link layer.

Add required includes to make the controller code compilable
after change struct ll_conn.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-18 20:11:10 -04:00
Piotr Pryga
52ec547894 Bluetooth: controller: Add handling for HCI set CTE Rx parameters
HCI_LE_Set_Connection_CTE_Receive_Parameters handling is required to
enable sampling of Constant Tone Extension in connected mode.

The commit adds handling for HCI_LE_Set_Connection_CTE_Receive_-
-Parameters command.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-18 20:11:10 -04:00
Piotr Pryga
ee71d95011 Bluetooth: controller: Add CTE Rx params struct to ll_conn declaration
Add struct ll_df_conn_rx_params sturcutre to struct ll_conn.
This is storage for parametrers required to configure radio
for CTE reception in connected mode.

Add required includes to make the controller code compilable
after change struct ll_conn.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-18 20:11:10 -04:00
Piotr Pryga
3a9d809d0d Bluetooth: controller: add struct for conf of CTE rx in conn mode
Add new strcture type for storage of CTE receive parameters.
The structure will be used in to store parameters for connected mode.

The parameters provided by HCI commands for receiving CTE
in connected mode and disconnected mode are a bit different.
There is common subset of parameters but extraction of those
into common structure would increase of size of other stuctures
that aggregate them.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-18 20:11:10 -04:00
Piotr Pryga
d159646e9b Bluetooth: controller: ull_df.c code re-arrange
Code related with connected mode was in middle between connectionless
RX and TX. Moved to the bottom of the file.

Added missing compilation guards for ll_df_set_conn_cte_tx_params.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-18 20:11:10 -04:00
Piotr Pryga
6a848ec91b Bluetooth: controller: Add LE features for CTE req and resp
Add features: connection CTE request, connection CTE response
and receiving constant tone extensions; to HCI and features
supported by controller.
The features are not enabled yet.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-18 20:11:10 -04:00
Piotr Pryga
2aa3fbb579 Bluetooth: controller: Add option to enable conn. CTE request feature
Add Kconfig option that enables BT v5.1 Connection CTE request feature.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-18 20:11:10 -04:00
Martí Bolívar
041099f67c Bluetooth: Controller: clean up nRF DFE
The way we currently handle direction finding extension (DFE) support
on Nordic nRF5 controllers relies on required devicetree properties
related to DFE in the "nordic,nrf-radio" node.

That doesn't make sense on radios without DFE support, though.
Any .dtsi for an SoC without DFE support which has such a node would
require extraneous DFE related properties like dfe-antenna-num.

Instead of making the properties required, mark them optional. We
indicate the presence of DFE support via a new 'dfe-supported' boolean
property which the SoC .dtsi files can set (or not) depending on
support.

This gives us the opportunity to do some cleanup in the Kconfig,
removing CONFIG_HAS_HW_NRF_RADIO_BLE_DF since we know from the
devicetree whether DFE support is available.

Handle that change appropriately in radio_df.c. This gives us an
opportunity to improve readability in the devicetree-related macro
magic in that file.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-08-17 17:52:43 -04:00
Vinayak Kariappa Chettimada
2cbc97d047 Bluetooth: Controller: Extended Active Scanning review rework
Miscellaneous review rework changes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
58b07c719a Bluetooth: Controller: Explicitly cast to void memq_dequeue calls
Explicitly cast to void memq_dequeue function calls.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
1cd8eb3a81 Bluetooth: Controller: Fix scan_data_status value
Fix scan_data_status value from being incorrected OR-ed with
the advertising data status.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
0fdac865e5 Bluetooth: Controller: Simplify LLL scheduling decision
Simplify the implementation deciding the use of LLL
scheduling for scanning PDUs with close auxiliary offsets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
2feffaf719 Bluetooth: Controller: Release LLL scheduling aux on incomplete data
Add implementation to release Auxiliary Context on failure
to receive auxiliary chain being in LLL scheduling.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Andrzej Kaczmarek
48ee84ffda Bluetooth: Controller: Fix aux scheduling from LLL
We need to alloc node prior to calling lll_scan_aux_setup, otherwise
the same node will be peeked inside that function and it will overwrite
some data in our node (e.g. "extra" field).

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
d879861d44 Bluetooth: Controller: LLL scheduling for active scanning and initiator
Implementation to use LLL scheduling for close auxiliary
offsets when active scanning and initiating connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
369dfd50ad Bluetooth: Controller: Fix tag name should be unique violation
Fix tag name should be unique violation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
451f0a25f1 Bluetooth: Controller: Resume primary PDU scanning after Auxiliary PDU
Add implementation to resume primary PDU scanning window
after use of LLL scheduling to receive auxiliary PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
25da55afce Bluetooth: Controller: Flush Aux PDUs being in LLL scheduling
When Auxiliary PDUs are scanning by the primary scan's LLL
scheduling, then flush the Auxiliary PDUs when processing
them in the ULL instead of using the disabled callback.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
cddf4cc4ed Bluetooth: controller: Extended scanning with LLL scheduling
Extended scanning with LLL scheduling.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-17 17:36:19 +02:00
Andrzej Kaczmarek
34edd41e76 Bluetooth: controller: Add ull_scan_aux_is_valid_get helper
This can be used to check if pointer is a valid lll_scan_aux pointer,
e.g. if we need to decide what kind of struct is attached to RX node
for further processing.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-17 17:36:19 +02:00
Andrzej Kaczmarek
1444c331a3 Bluetooth: controller: Fix isr_done_cleanup
We need to reset isr status before returning as otherwise irq will be
triggered over and over again.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
be8f1a2519 Bluetooth: Controller: Generate Extended Scan Response report
Added implementation to traverse the Extended Active Scanned
advertising PDUs, generate the Scannable Advertising and
Scan Response Advertising Report.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
bf957850ca Bluetooth: Controller: Hold back Extended Scannable PDUs
When Extended Active Scanning hold back the received PDUs in
a linked list and send it to HCI together so that fields
present across these PDUs can be aggregated for generating
the LE Extended Advertising Report.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
bbb53446ad Bluetooth: Controller: Flush scanned rx node before scan response PDU
Flush the scanned advertising PDUs to HCI while receiving
the scan response PDU when Extended Active scanning.
This reverts earlier implementation to remember the
advertising PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
9962faf3c6 Bluetooth: Controller: Add support for Extended Active Scanning
Add support for Extended Active Scanning and generation of
Extended Advertising Report with Scan Response event type.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
bf20b23f0f Bluetooth: Controller: Reverting Extended scanning with LLL scheduling
Reverting Extended scanning with LLL scheduling as this is
causing unresolvable merge conflict with the commits that
is implementing the Extended Active Scanning support.

Subsequent commit add the revert implementation back again.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Vinayak Kariappa Chettimada
854aaeb8ae Bluetooth: Controller: nRF53x: Fix missing sw_switch clear DPPI config
Fix missing sw_switch timer clear DPPI config when
re-enabling Tx or Rx after radio_disable() or
radio_switch_complete_and_disable() call in LLL state/role
contexts.

Relates to commit 1c3659519f ("Bluetooth: controller:
nRF53x: Fix missing sw_switch clear DPPI config").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 17:36:19 +02:00
Daniel Leung
378ad046c8 drivers: bluetooth: build as static library
Instead of putting object files inside libzephyr.a,
simply build a separate static library as most other
driver types are doing this already.

Note that the include to subsys/bluetooth has been
moved from under drivers/bluetooth to subsys/bluetooth,
as it is actually the subsystem's job to make sure
the include directories are correct.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-17 06:06:03 -04:00
Daniel Leung
23712842d1 bluetooth: audio: build as static library
Make subsys/bluetooth/audio build as a static library.
This is in preparation to enable building the bluetooth
drivers as a static library. That would change the line
"zephyr_include_directories(subsys/bluetooth)" where
this include path is applied to all code compiled.
Its removal will result in subsys/bluetooth/audio not
able to find subsys/bluetooth/common/log.h. So change
subsys/bluetooth/audio to be built as a static library
so it can link to the subsys/bluetooth library where
it can find "log.h" there.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-17 06:06:03 -04:00
Vinayak Kariappa Chettimada
d1e64cb9d7 Bluetooth: Controller: Fix hci_core assertion on advertising disable
Fix a race condition that caused the Controller to deadlock
waiting for a semaphore that be given when LLL events have
been disabled.

ULL reference count is checked in thread context to decide
if LLL events are pending, but the reference count can be
decremented by the ULL execution context which prevents the
set `disabled_cb` function not being called due to no
pending event to produce the done events.

Fixed by re-checking if reference count is zero and avoid
waiting to take the semaphore.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-17 10:22:14 +02:00
Saleh Mehdikhani
8618de9be4 Bluetooth: controller: radio: Fix wrong argument of radio_df_ctrl_set
While RADIO_DFECTRL1_TSAMPLESPACING and RADIO_DFECTRL1_TSAMPLESPACINGREF
has similar values, but they are logically different.
As expected by "radio_df_ctrl_set" function, TSAMPLESPACING should be
passed to this function not TSAMPLESPACINGREF.

Signed-off-by: Saleh Mehdikhani <saleh.mehdikhani@unikie.com>
2021-08-17 10:21:10 +02:00
Vinayak Kariappa Chettimada
190532bcc4 Bluetooth: Controller: Only remove duplicate resume events
When events are placed back into pipeline as resume events,
only remove duplicate resume events and not new prepare
events that may have been enqueue between the start of the
pre-empt ticker and its timeout.

Due to new prepare events that was removed, extra done
events generated cause the number of enqueued done events
to overflow and assert.

Fixes #36381.
Fixes #37597.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-16 15:13:11 -04:00
Vinayak Kariappa Chettimada
790a291e24 Bluetooth: Controller: Fix incorrect pipeline iterator index reset
Fix the incorrect iterator index being reset when flushing
duplicate resume events in the pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-16 15:13:11 -04:00
Vinayak Kariappa Chettimada
82eb2a4019 Bluetooth: Controller: Update AD data race implementation
Update the AD data race condition handling with explicit
revert of `pdu->last` value after detecting the race.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-16 15:12:55 -04:00
Vinayak Kariappa Chettimada
30b4c29aaf Bluetooth: Controller: Minor conditional compile refactor
Minor conditional compile refactor.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-16 12:46:43 +02:00
Vinayak Kariappa Chettimada
c399155bc4 Bluetooth: Controller: Reduce the Rx window switch for continous scan
Reduce the Rx window swithch overhead for continuous scan by
using radio interfae `radio_tmr_start_now` that accounts for
any minimum ticker offset requirement.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-16 12:46:43 +02:00
Vinayak Kariappa Chettimada
22a96ade74 Bluetooth: Controller: Remove radio complete and Tx after scan response
Remove the radio software switch from Rx to Tx after
reception of scan response.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-16 12:46:43 +02:00
Vinayak Kariappa Chettimada
eddd1b18eb Bluetooth: Controller: Remove radio complete and Tx for passive scan
Remove the radio software switch from Rx to Tx when in
passive scanning, as there is no transmission requirement
after reception of a PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-16 12:46:43 +02:00
Vinayak Kariappa Chettimada
dc633856d7 Bluetooth: Controller: Fix uninit update flag given to PDU _latest_get
Fix uninitialized update flag given to PDU _latest_get()
functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-13 10:14:50 -04:00
Morten Priess
fdc92ebb27 Bluetooth: controller: Implement ADV re-schedule for new scheduler
The new JIT scheduler does not have slot reservation, which means that
the ticker extension feature for automatically re-scheduling a colliding
non-anchored event, e.g. ADV, cannot be used.

This implementaion reacts to ADV envent done with result ABORTED or
TOO_LATE, and in those cases attempts to re-schedule the ADV event again
within the 10 ms pertubation window.

As the original scheduling, the re-scheduling is randomized, so there
is no absolute predictability as to how many attempts will be made. The
advertiser will attempt with randomly delayed re-schdules until the
window is exhausted.

If re-scheduling is unsuccessful, the weight of the ADV event is
increased, improving it's chances of success in the next event.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-08-13 07:30:56 -04:00
Fabio Baltieri
f88a420d69 toolchain: migrate iterable sections calls to the external API
This migrates all the current iterable section usages to the external
API, dropping the "Z_" prefix:

Z_ITERABLE_SECTION_ROM
Z_ITERABLE_SECTION_ROM_GC_ALLOWED
Z_ITERABLE_SECTION_RAM
Z_ITERABLE_SECTION_RAM_GC_ALLOWED
Z_STRUCT_SECTION_ITERABLE
Z_STRUCT_SECTION_ITERABLE_ALTERNATE
Z_STRUCT_SECTION_FOREACH

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2021-08-12 17:47:04 -04:00
Krzysztof Kopyściński
00bfac00ae Bluetooth: gatt: Add option to read multiple without variable length
Currently, with EATT enabled, when bt_gatt_read is called with multiple
handles first it'll try to use gatt_read_mult_vl, and if it fails
gatt_read_mult will be used to try again. Add option to skip
the gatt_read_mult_vl and use gatt_read_mult right away. This is needed
by tests that expect BT_ATT_OP_READ_MULT_REQ but support variable
lenght, thus don't return BT_ATT_ERR_NOT_SUPPORTED.

Removed fallback from read multiple vl to read multiple on
BT_ATT_ERR_NOT_SUPPORTED error.

This was affecting:
GATT/CL/GAR/BV-05-C, GATT/CL/GAR/BI-18-C, GATT/CL/GAR/BI-19-C,
GATT/CL/GAR/BI-20-C, GATT/CL/GAR/BI-21-C, GATT/CL/GAR/BI-22-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-08-12 11:07:08 -04:00
Vinayak Kariappa Chettimada
00d707e470 Bluetooth: Controller: Fix node rx memory corruption regression
Fix the node rx memory pool corruption regression introduced
due to same peer connection being rejected.

Regression introduced in commit 30f260dfaa ("Bluetooth:
controller: Fix adv/scan context access post release").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-12 11:57:12 +02:00
Vinayak Kariappa Chettimada
27b8beaa22 Bluetooth: Controller: Fix to handle relative short preempt timeout
When a new radio event is scheduled with a relatively short
preempt timeout while there is already a started preempt
ticker, then stop the ticker, abort the previous event that
requested the preemption, and request to start ticker with
the new relatively short preempt timeout.

Fixes #30245.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-12 11:56:56 +02:00
Vinayak Kariappa Chettimada
6cd9ec8c8d Bluetooth: Controller: Preempt ticker to use atmost one operation
When there are multiple events in prepare pipeline then fix
the implementation so that only one preempt ticker start
or stop operation is enqueued towards ticker_job for
processing.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-12 11:56:56 +02:00
Lingao Meng
8e1682d1ea samples: conn_cb replace to const zsector
It is more efficient and saves part of RAM
by replacing it with static one dynamically.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-11 13:42:28 +02:00
Lingao Meng
23a9594944 Bluetooth: Add connect event structure to zsector
Add an optional version for connection events
to save some memory.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-11 13:42:28 +02:00
Vinayak Kariappa Chettimada
eb22d5acf2 Bluetooth: Controller: Change random address on advertising re-enable
If HCI LE Set Extended Advertising Enable command is sent
again for an advertising set while that set is enabled, then
any change to the random address shall take effect.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-11 07:32:59 -04:00
Vinayak Kariappa Chettimada
e82fcb070a Bluetooth: Controller: Permit enabling already enabled advertising
Permit enabling already enabled advertising. Enabling
advertising when it is already enabled can cause the
random address to change, as specified in the Bluetooth
Specifications.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-11 07:32:59 -04:00
Vinayak Kariappa Chettimada
06f02b570e Bluetooth: Controller: Comment on enabling of already enabled scanning
Add comment about enabling of already enabled scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-11 07:32:59 -04:00
Lingao Meng
6bf35fa749 Bluetooth: Mesh: Fixes Same appkey add to multi netkey
The latest MESH.TS 1.0.1.2 4.15.10 Appkey List Procedures
MESH/NODE/CFG/AKL/BI-04-C

Verify that the IUT can respond to an Config AppKey Add
message with NetKeyIndex and AppKeyIndex already stored.

6. Repeat step 1 with the same AppKey, the same
AppKeyIndex, but NetKeyIndex field set to 0x001.

7. The Lower Tester expects the IUT to respond
with an Config AppKey Status message with the
Status field set to 0x04 (Invalid NetKey) and
the NetKeyIndex and AppKeyIndex values equal to
those sent in step 5.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-10 07:39:11 -04:00
Vinayak Kariappa Chettimada
4830571356 Bluetooth: Controller: Fix advertising after connections from same peer
Fix the missing resumption of connectable advertising and
release of received connection complete buffers from LLL
after detecting connection from same peer.

Relates to commit 010c5c2f20 ("Bluetooth: controller:
Ignore connections from same peer").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-10 07:36:47 -04:00
Joakim Andersson
79021187ac Bluetooth: host: Check for mandatory callback when accepting new channel
Add a check for the mandatory channel receive callback when the
application provides the L2CAP channel operations.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-09 13:03:55 -04:00
Joakim Andersson
921644c5a6 Bluetooth: OTS: Make L2CAP channel recv callback static
Make the OTS module L2CAP channel recv callback a static function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-09 13:03:55 -04:00
Joakim Andersson
9f989a0b00 Bluetooth: OTS: Add configuration for OTS channel TX mtu
Add configuration for Object Transfer Service channel MTU for outgoing
L2CAP SDUs.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-09 13:03:55 -04:00
Trond Einar Snekvik
8ab219cde5 bluetooth: Add defines for ECC key lengths
Adds defines for ECC public keys, private keys, DH keys and key
coordinates. Replaces raw numbers throughout.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-08-09 16:45:57 +02:00
Piotr Pryga
2675b8d8aa Bluetooth: controller: remove warning about defined bvt unused function
Remove compilation warning about adv_sync_pdu_ad_data_set function
that is defined but not used.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
120751118c Bluetooth: controller: ULL: Add handling of chains in disable CTE
Direction finding functionality allows to send a number of periodic
advertising PDUs in a chain that have CTE.
Disable sending CTE requiers additional steps while removing
cte_info from periodic advertising chains.
Removal of cte_info fields may be just delete of that filed
from extended advertising header. In case the PDUs are empty
PDUs created just to transport CTE. Those PDUs should be removed
from a periodic advertising chain.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
9c23fe0dcc Bluetooth: controller: Add release of chains when get latest adv pdu
Add release of chained PDUs by lll_adv_pdu_and_extra_data_-
latest_get function. It is requier to release unused
PDUs from a chain to avoid PDUs leakage.
It maight happen when chained PDUs were used by Direction
Finding, then lll_adv_pdu_and_extra_data_lates_get is used
instead of lll_adv_pdu_lates_get.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
467d132e6f Bluetooth: controller: Add macro with minimum allowed adv. PDU size
To check if advertising PDU is empty we can compare its length to 1.
To avoid use of magic number, the commit provides a macro for that
purpose.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
4a13b8b4c7 Bluetooth: controller: ULL: Add sending of number of CTEs in per adv chain
Direction finding functionality allows to send a number of periodic
advertising PDUs in a chain that have CTE.
ll_df_set_cl_cte_tx_enable function was changed to update periodic
advertising chain to include cte_info field. If the chain is too short,
there is less PDUs in the chain than requested number of CTEs,
the function will add new empty PDUs to the chain end.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
616ebcf8f7 Bluetooth: controller: ULL: ull_adv_sync_hdr_set_clear update PDU in place
Enabling or disabling transmission of Constant Tone Extension with
periodic advertising PDUs requires update of a PDU content.
CTE_INFO field of periodic advertising PDU must be filled with
appropriate data. That operation may be done for periodic
advertising PDU (or chain of PDUs) filled with other payload that
wasn't enqueued towards LLL. In that situation PDUs are updated
in place, to avoid increase of memory consumption.

The commit changes ull_adv_sync_pdu_set_clear function to
make possible update of the advertising PDU in place.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
151a32db7a Bluetooth: controller: ULL: Make API for per adv sync PDU change global
Some functions, provided to handle changing content of periodic
advertising PDUs, were defined as static.
Code responsible for handling direction finding updates periodic
advertising PDUs also. For that purposes, those functions were mede
globally accessible.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
2d71b2d82c Bluetooth: controller: LLL: Add CTE confing for per. adv. chain TX
Add configuration of CTE for periodic advertising chain transmission.
The commit provides configuration of radio in prepare stage and
in handle of Tx ISR. CTE is configured only for PDUs that
have cte_info field in extended advertising header.

During prepare of periodic advertising event there are updated
aux_ptr fields in extended advertising header in other PDUs from
a periodic advertising chain. aux_ptr offset value also depends
on CTE length. CTE configuration is always the same for every
PDU in periodic advertising chain.
CTE may be added to requested number of PDUs in periodic
advertising chain. Although it is possible that there are PDUs
that don't have CTE. PDUs that have CTE are alsways at the beginning
of a periodic advertising chain.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
8a5a88ce96 Bluetooth: controller: LLL: Add peek extra_data related with lll_adv_sync
Configuration of CTE for transmission is stored in extra_date member
of a lll_adv_sync object. PDUs in periodic advertising chain share the
same CTE configuration, so there is single instance of the extra_data.
To configure CTE transmission for every PDU in periodic advertising
chain a new function was introduced to peek extra_data instance without
peeking new PDU.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
6cc97e7a32 Bluetooth: controller: df: Add const to antenna patterns pointer
Add const qualifier in radio API related with setting antenna
switch pattern.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
2dad068545 Bluetooth: controller: radio: Add back2back TX switch after PHYEND event
Transmission of Constant Tone Extension is done after END event
triggered by radio. To correctly switch from TX to TX (back 2 back
TX) after transmission of CTE PHYEND event must be used instead of
END event.

The commit provides required function that allows LLL to correctly
setup radio to do back to back switch of TX when CTE transmission
is enabled.

The radio_switch_complete_and_phy_end_b2b_tx cannot be implemented
in radio.c source file. It will fail build of unit tests targeted
for NRFBSIM simulator board. There is no RADIO_SHORTS_PHYEND_DISABLE_Msk
macro defined in bsim_hw_models module.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
1e2ad5a590 Bluetooth: controller: Make per. adv. PDUs count related to max CTE num
Amount of memory allocated for advertising PDUs (including
periodic advertising) depends on two factors:
- maximum advertising data length
- maximum number of CTE in a periodic advertising chain.

Maximum advertising data length is divided by maximum size
of a single fragment (number of payload bytes that single
advertising PDU may hold) to get required number of fragments.

Actual number of PDUs allocated for advertising is maximum
of acutal number of advertising payload fragments and maximum
number of CTEs.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Piotr Pryga
f01b77f3c9 Bluetooth: controller: Add conf max num of PDUs with CTE in per adv chain
Add possiblity to configure maximum number of PDUs with Constant Tone
Extension in a single periodic advertising chain.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-07 20:50:03 -04:00
Emil Gydesen
57fc354f6c Bluetooth: ISO: Fix iso channels not disconnecting properly
We had added a break in a switch statement that stopped
ISO channels from setting the BT_CONN_CLEANUP flag
which in turn stopped them from disconnecting (in the
eyes of the upper layers) properly.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-05 15:08:06 -04:00
Emil Gydesen
b1f4764f4f Bluetooth: ISO: Add clearer error message on iso accept failure
Instead of just writing "err" we make it clear that it is
the ISO server that failed to accept.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-05 15:08:06 -04:00
Emil Gydesen
7f3a085a7a Bluetooth: shell: ISO change to use shell_print instead of printk
shell_print is preffered for the shell as printk may appear
in a different terminal.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-08-05 15:08:06 -04:00
Lingao Meng
524d2e2b27 Bluetooth: audio: Fix -Wunused-function
Fix -Wunused-function

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-05 16:07:44 +02:00
Lingao Meng
e0dfdd6723 Bluetooth: Fix -Wunused-but-set-variable
Fix -Wunused-but-set-variable

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-05 16:07:44 +02:00
Lingao Meng
4cbe77dbdb Bluetooth: Fix -Wunused-variable
Fix unused variable but defined, this will be
appear when dbg disabled.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-05 16:07:44 +02:00
Vinayak Kariappa Chettimada
239a663c40 Bluetooth: Controller: Fix tag name should be unique violation
Fix tag name should be unique violation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-05 11:45:41 +02:00
Vinayak Kariappa Chettimada
c091e267ff Bluetooth: Controller: Resume primary PDU scanning after Auxiliary PDU
Add implementation to resume primary PDU scanning window
after use of LLL scheduling to receive auxiliary PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-05 11:45:41 +02:00
Vinayak Kariappa Chettimada
9b4e1849f5 Bluetooth: Controller: Flush Aux PDUs being in LLL scheduling
When Auxiliary PDUs are scanning by the primary scan's LLL
scheduling, then flush the Auxiliary PDUs when processing
them in the ULL instead of using the disabled callback.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-05 11:45:41 +02:00
Vinayak Kariappa Chettimada
3ce651fe7b Bluetooth: controller: Extended scanning with LLL scheduling
Extended scanning with LLL scheduling.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-05 11:45:41 +02:00
Andrzej Kaczmarek
51173f9f40 Bluetooth: controller: Add ull_scan_aux_is_valid_get helper
This can be used to check if pointer is a valid lll_scan_aux pointer,
e.g. if we need to decide what kind of struct is attached to RX node
for further processing.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-08-05 11:45:41 +02:00
Andrzej Kaczmarek
c9fca499b2 Bluetooth: controller: Fix isr_done_cleanup
We need to reset isr status before returning as otherwise irq will be
triggered over and over again.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-05 11:45:41 +02:00
Lingao Meng
c85640edf3 Bluetooth: adv: Fix wrong assert
Fixes wrong ASSERT usage cause abnormal failed.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-05 11:25:39 +02:00
Joakim Andersson
2a2523ce74 Bluetooth: host: Fix bug in adv timeout for limited advertiser
Fix bug in adv timeout for limited advertiser when extended advertising
features has been enabled. The advertiser was only stopped when
configured as an extended advertiser. It should be stopped when
configured as a legacy advertiser also.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-05 11:25:11 +02:00
Vinayak Kariappa Chettimada
4661ae3c21 Bluetooth: Controller: Fix Extended Scanning Address Resolution
Fix the received Extended Advertising PDU's address
resolution latency due to missing reset of pending IRQ in
the NVIC which caused the wait loop from not exit correctly.

Fixes #30243.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-04 10:37:08 +02:00
Vinayak Kariappa Chettimada
fcc15f713a Bluetooth: Controller: Fix resolving index from being overwritten
When generating LE Extended Advertising Report the device
address can be either in primary or auxiliary channel PDU,
do not overwrite resolving list index if present in primary
channel PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-08-04 10:36:46 +02:00
Joakim Andersson
72bd8da095 Bluetooth: host: Fix key distribution not calling pairing complete
Fix key distribution not calling pairing complete callback when
distributing encryption information when not bonding.
Encryption information is only distributed in legacy pairing so issue
was only seen during legacy pairing.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-08-03 18:47:01 +02:00
Lingao Meng
3911ce8d40 Bluetooth: Mesh: Mark as internal function
Marks funcs:`show_faults` as internal, avoiding conflict.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-03 10:21:16 -04:00
Michał Narajowski
e167ca6539 Bluetooth: Mesh: Refactor Mesh Model Extensions
The existing extension tree does not support all the features that are
defined by the specification (e.g. multiple parents).

This patch approaches this problem by defining a circular single-linked
list of extension models. So for a given model, all models that are on
the same list as that model are in some extension relationship with that
model. All models on a list represent a single connected component of an
extension graph but without defining specific relationships between each
pair of models. This list is used to manage a shared subscription list
as per the Mesh Profile Specification:

```4.2.4 Subscription List

Within an element, each model has a separate instance of a Subscription
List, unless the model extends another model on that element. Instances
of models that extend other models (i.e., all models within an extension
relation tree) shall share a single instance of a Subscription List per
element.
```

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-08-03 10:20:52 -04:00
Piotr Pryga
ca26e7a3f7 Bluetooth: controller: Fix wrong CTE type in per adv report
The Bluetooth Core spec 5.2 requires to provide CTE type in
periodic advertising report.
The implementation of le_per_adv_sync_report assigned
value zero to be default CTE type. The assigned value
in Bluetooth Core spec 5.2 means "AoA Constant Tone
Extension". In case there is no CTE attached to periodic
advertising PDU, CTE type should contain value 0xFF.

This commit fixes the issue.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-03 13:58:51 +02:00
Piotr Pryga
fc7ead4b9f Bluetooth: host: df: Fix compilation warning in direction.c
Fix compilation warning in hci_df_set_cl_cte_rx_enable function.
The struct bt_hci_cp_le_set_cl_cte_sampling_enable *cp variable
was used just to evaluate size in bt_hci_cmd_create call.

The variable is moved to prepare_cte_rx_enable_cmd_params
function and size of the buf is evaluated directly from type.

Code is simpler and prepare_cte_rx_enable_cmd_params does not
require passing additional argument.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-03 13:58:02 +02:00
Abe Kohandel
dcaac1e7af bluetooth: ots: Make OTS Object Reads use POSIX parameter types
It is desirable to have the read and write like functions follow the
POSIX read and write parameter types.

Signed-off-by: Abe Kohandel <abe.kohandel@gmail.com>
2021-08-03 13:16:51 +02:00
Piotr Pryga
2863bbcdd7 Bluetooth: controller: Add init and reset of LLL per adv in lll_adv.c
There were missing calls to periodic advertising functions:
lll_adv_sync_init() and lll_adv_sync_reset() corresponding
functions in lll_adv.c.

Lack of those calls didn't introduce any harm.
I've added them to have complete init and reset patch,
similar to extended advertising implementation.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-03 13:16:10 +02:00
Piotr Pryga
162691c918 Bluetooth: controller: Add reset of per adv for HCI_Reset command
There is missing handling of periodic advertising reset for
HCI_Reset command. That makes impossible to execute e.g.
qualification tests without rebooting of the DUT
for periodic advertising and direction finding.

This commit adds missing implementation.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-08-03 13:16:10 +02:00
Abe Kohandel
997bbcb000 bluetooth: ots: Add object write procedure
Add the ability to perform an OTS Write Procedure with only Patch
support configuration.

Signed-off-by: Abe Kohandel <abe.kohandel@gmail.com>
2021-07-31 23:16:11 -04:00
Saleh Mehdikhani
36f934113f Bluetooth: Host: direction: Fixing the bug to support 1us slot
There was an issue with receiving CTE packets when the time
slot has changed from 2us to 1us. After receiving the packets
when it tries to enable receiving of CTE, the validator
returns EINVAL error.

Source of the problem is "validate_cte_rx_params" function,
it calls DF_AOA_RX_1US_SUPPORT(df_ant_info.switch_sample_rates)
which is expanded to:
((df_ant_info.switch_sample_rates) & BIT((BT_HCI_LE_1US_AOA_RX)))

And due to definition of BT_HCI_LE_1US_AOA_RX in hci.h it will be:
((df_ant_info.switch_sample_rates) & BIT(BIT(2)))

So the BIT operation has executed two times.

Signed-off-by: Saleh Mehdikhani <saleh.mehdikhani@unikie.com>
2021-07-30 19:54:42 -04:00
Lingao Meng
9042f76b8b Bluetooth: Mesh: Add pointer conversion for prov->uri
`prov_sd[0].data` and `prov->uri` have different point type.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-29 10:59:20 -04:00
Lingao Meng
baf0d58a67 Bluetooth: Mesh: Fix wrong use log_strdup
Should use `bt_hex` instead of `log_strdup`.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-29 10:59:20 -04:00
Lingao Meng
cce921dad5 Bluetooth: Fix Wrong format when debug
Fix wformat build warning

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-29 10:59:20 -04:00
Krzysztof Kopyściński
779e67c0fc Bluetooth: host: disallow MPS decrease for multiple CIDs in Reconf Req
When in le_ecred_reconf_req multiple CIDs are received host should
return  0x0002 error (Reconfiguration failed - reduction in size of
MPS not allowed for more than one channel at a time).

This affects test L2CAP/ECFC/BI-04-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-07-29 15:21:10 +02:00
Krzysztof Kopyściński
4f80fe814c Bluetooth: host: introduce timeout in limited advertising
In limited advertising advertising should end after certain timeout.
Previously, limited advertising was just general advertising with
BT_LE_AD_LIMITED flag set. Now, if this flag is set the work is
scheduled, that will disable advertising after timeout.

This affects tests GAP/DISC/LIMM/BV-03-C and GAP/DISC/LIMM/BV-04-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-07-29 15:20:54 +02:00
Lingao Meng
55145beee0 Bluetooth: Mesh: Add more explain for ADV_STACK_SIZE
Add explanatory statement for config `BT_MESH_ADV_STACK_SIZE`

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-28 15:44:34 +02:00
Lingao Meng
5fe698286e Bluetooth: Mesh: Add kconfig for thread priority
Add Kconfig `CONFIG_BT_MESH_ADV_PRIO`.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-28 15:44:34 +02:00
Vinayak Kariappa Chettimada
97adf875b8 Bluetooth: Controller: Flush pending Tx PDUs before PHY update
Flush any pending Tx PDUs in the lower link layer before
enqueueing PHY_UPDATE_IND PDU with instant to ensure the
PDU is transmitted before the instant occurs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-28 11:38:42 +02:00
Vinayak Kariappa Chettimada
ad1edf1cc4 Bluetooth: Controller: Advanced scheduling for Extended Initiator
Implement the advanced scheduling for Extended Initiator to
group central connections established to Extended
Advertisements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-28 11:38:29 +02:00
Vinayak Kariappa Chettimada
d8f4759c5f Bluetooth: Controller: Fail on multiple PHY use in PHY_UPDATE_IND
Disconnect connection if peer central uses multiple PHYs in
PHY_UPDATE_IND PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-28 11:38:15 +02:00
Vinayak Kariappa Chettimada
9a1b5c68f5 Bluetooth: Controller: Explicitly check previous auxiliary PDU for ADI
To be consistent in how order header flags are handled when
updating the common header format fields, explicit check
for ADI flag in previous auxiliary PDU buffer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-26 15:30:04 +02:00
Vinayak Kariappa Chettimada
ad8f4d368a Bluetooth: Controller: Remember last used DID for each SID
Remember last used DID for each SID, so that DID value used,
when updating the advertising PDU fields, change between
consecutive changes to PDU fields.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-26 15:30:04 +02:00
Vinayak Kariappa Chettimada
a919e1ba40 Bluetooth: Controller: Make Extended Advertising DID unique
Make the Extended Advertising DID value updated to be unique
for every new advertising set created.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-26 15:30:04 +02:00
Vinayak Kariappa Chettimada
d19476c3c2 Bluetooth: Controller: Fix corrupt AD data after directed advertising
Fix corrupt AD data used after directed advertising by
storing a backup of the AD data before switching to directed
advertising. Restore back the AD data with switching to non-
directed advertising.

The fix also addresses AD data backup when switching between
Legacy and Extended Advertising.

Fixes #18850.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-26 15:29:55 +02:00
Vinayak Kariappa Chettimada
4e6357e549 Bluetooth: Controller: Resolve AdvA in AUX_CONNECT_RSP PDU
Add implementation to resolve AdvA in the received
AUX_CONNECT_RSP PDU before generating the connection
complete.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-26 15:29:41 +02:00
Emil Gydesen
3a6952e3e6 Bluetooth: iso: Compile conn.c for BT_ISO even without BT_CONN
If BT_ISO is enabled we now compile conn.c which contains a
lot of functionality used by BT_ISO, even for broadcast-iso
builds, i.e. builds that do not require BT_CONN.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
a02abea0a2 Bluetooth: conn: Move ACL only data fields to ACL group
Move the data that is only relevant for ACL to
a guarded ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
72319abc7e Bluetooth: conn: Add BT_CONN guards in bt_conn_set_state
Add BT_CONN guards for ACL only functionality in
bt_conn_set_state.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
32da3287ac Bluetooth: conn: Add BT_CONN guard to bt_conn_get_pkts
Add a guard for BT_CONN and return NULL if no
packets can be returned.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
90a9ea92e2 Bluetooth: hci_core: Remove BT_CONN guard for ISO fields in bt_dev_le
Change the guard such that the iso_mtu and iso_pkts are
not guarded by BT_CONN as they should be available for
iso broadcast-only builds.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
4ac8a9e6c0 Bluetooth: conn: Add guard for ACL in conn_mtu
Add guard for accessing the bt_dev.le.acl_mtu if
CONFIG_BT_CONN is not enabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
5612f60185 Bluetooth: conn: Add bt_acl_recv for ACL only data
Add the bt_acl_recv function that works similar to
bt_iso_recv but for ACL data only, simplying the
generic bt_conn_recv function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
c877045133 Bluetooth: conn: Guard acl_send with CONFIG_BT_CONN
Guard the ACL send to only be called if CONFIG_BT_CONN
is enabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
c56fd68a13 Bluetooth: conn: Move bt_conn_connected to ACL group
Move the bt_conn_connected function to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
6952dcd7a8 Bluetooth: conn: Move acl_conns to ACL group
Move the acl_conns array to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
2249091176 Bluetooth: conn: Move bt_conn_disconnect to ACL group
Move the bt_conn_disconnect and conn_disconnect functions
to the ACL group.

Also adds a guard in the iso.c file for connected ISO.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
d203422082 Bluetooth: conn: Fix type of recieved to received
Fixed a typo that caused a CI issue.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
cbec9ffbc0 Bluetooth: conn: Move ACL callback handlers to ACL group
Move the notify_le_phy_updated, notify_le_data_len_updated,
notify_le_param_updated, notify_remote_info,
notify_disconnected and notify_connected functions
to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
866062d7ca Bluetooth: conn: Move ACL conn param functions to ACL group
Move the send_conn_le_param_update and le_param_req functions
to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
bee720e797 Bluetooth: conn: Move tx_complete_work to the ACL group
Move the tx_complete_work function to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
fc69f01136 Bluetooth: conn: Moved deferred_work to the ACL group
Move the deferred_work callback function to the ACL group.
This also moves the static function conn_lookup_iso
which is only called form deferred_work.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
fce489087f Bluetooth: conn: Move acl_conn_new to the ACL group
Move the acl_conn_new function to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
c6472f3b56 Bluetooth: conn: Move the BREDR functions to the ACL group
Move the BREDR functions to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
1aefa8baac Bluetooth: conn: Move SMP functions to the ACL group
Move the SMP functions to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
d0d2df4cd8 Bluetooth: conn: Move bt_conn_cb_register to ACL group
Move the bt_conn_cb_register function to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
83e25a7d4b Bluetooth: conn: Move the bt_conn add and exist functions to ACL group
Move the bt_conn_add_le and bt_conn_exists_le functions to the
ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
f1e438c63b Bluetooth: conn: Move bt_conn ACL lookup functions to ACL group
Move the bt_conn_lookup_state_le, bt_conn_lookup_addr_le and
bt_conn_is_peer_addr_le functions to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
9ec9943bab Bluetooth: conn: Move bt_conn_get_dst to ACL group
Move the bt_conn_get_dst function to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
8b64e3c8fd Bluetooth: conn: Move bt_conn get info functions to ACL group
Move the bt_conn_get_info and bt_conn_get_remote_info functions
to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
bcf2515f3b Bluetooth: conn: Move TX power level functions to ACL group
Move the bt_conn_get_tx_power_level and
bt_conn_le_get_tx_power_level functions to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
422beb41bd Bluetooth: conn: Move bt_conn_le_param_update to ACL group
Move the bt_conn_le_param_update function to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
c9250fea7c Bluetooth: conn: Move bt_conn_le_data_len_update to ACL group
Move the bt_conn_le_data_len_update function to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
661377192a Bluetooth: conn: Move bt_conn_le_phy_update to ACL group
Move the bt_conn_le_phy_update function to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
05c67528e9 Bluetooth: conn: Move the ACL create functions to ACL group
Move the central role functions to create BT connections to
the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
a7b1ab4d3e Bluetooth: conn: Move bt_conn_le_conn_update to ACL group
Move the bt_conn_le_conn_update function to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
11d7fd3afd Bluetooth: conn: Move bt_conn_create netbuf functions to ACL group
Moves the bt_conn_create_frag_timeout and
bt_conn_create_pdu_timeout to the ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
12ce4b8ba9 Bluetooth: conn: Move bt_conn_auth_* functions to ACL group
Move the bt_conn_auth_* functions to the newly create
ACL group.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Emil Gydesen
2cb6f3cf3e Bluetooth: conn: Start connected-only grouping
Start a group of functions guarded by CONFIG_BT_CONN
that are for connected-only functions. This is a
preparation step for allowing compilation and usage of
conn.c for ISO broadcast-only builds.

Moving all connected-only functionality into a single
group will also allow a possible move of all those
functions into an connected (ACL) only file.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-23 16:11:52 -04:00
Agata Ponitka
a279ff3958 Bluetooth: Mesh: Fix Health Client Model
Assigning a value to the msg_timeout parameter.

Signed-off-by: Agata Ponitka <agata.ponitka@codecoup.pl>
2021-07-22 22:41:32 +03:00
Agata Ponitka
22aafd422c Bluetooth: Mesh: Add missing Configuration Client API
Add missing API:
- Delete all group addresses in a SIG model's subscription list
- Update a network key
- Update an application key
- Get/Set Node Identity parameters
- Set virtual addtess for a SIG model
- Get/Set Key Refresh Procedures

Signed-off-by: Agata Ponitka <agata.ponitka@codecoup.pl>
2021-07-22 22:41:32 +03:00
Agata Ponitka
e962cbb9fd Bluetooth: Mesh: Fix Configuration Client API
Hardcoded invalid Company ID was used instead of the parameter passed to
the API.

Signed-off-by: Agata Ponitka <agata.ponitka@codecoup.pl>
2021-07-22 22:41:32 +03:00
Vinayak Kariappa Chettimada
2c606239e2 Bluetooth: Controller: Make adva and tgta check function file static
The functions to check advertising and target address in a
PDU are used only inside the same file, hence make them file
static functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-22 17:35:22 +02:00
Vinayak Kariappa Chettimada
33c06e6992 Bluetooth: Controller: Move assignments close to locality of reference
Minor refactor to move assignment statements close to their
locality of reference.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-22 17:35:22 +02:00
Vinayak Kariappa Chettimada
dee5b53b73 Bluetooth: Controller: Add target address check to extended scanning
Add target address check to extended scanning implementation
to detect invalid target address present in primary and
auxiliary channel PDU. Implementation is reuse of the check
used in the initiator after refactoring to pass parameter to
differentiate, its use for primary or auxiliary channel, and
for scanning or initiating.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-22 17:35:22 +02:00
Bud Wandinger
7a2b248b98 Bluetooth: Mesh: Added support for application access to mesh messages
Added bt_mesh_msg_send() which can be used by the application to
directly send model layer messages without local instantiation of
related models. Also added bt_mesh_msg_cb_set() which allows the
application to recieve mesh model layer messages without local
instantiation of related models.

Added bt_mesh_has_addr() which returns a bool. For unicast addresses,
this returns whether or not bt_mesh_elem_find() was successfull. If the
above mentioned bt_mesh_msg_cb_set() has been used by the application to
set a message callback, this returns true so that the stack attempts to
push every model message up to the application via the callback. If no
callback has been set, group addresses are searched to see if the stack
should pass the message up the stack to an instantiated model.

These changes allow applications that do not or can not instantiate
models to interface with models in a mesh network. This is applicable to
applications which act as a Bluetooth mesh gateway, sniffer, debugger,
network monitoring, non-mesh relay/extender, etc.

In app_keys.c friend.c net.c bt_mesh_elem_find() is used only to
determine the existance of an address. The full return value of
bt_mesh_elem_find() is unecessary and so was replaced by the above
mentioned bt_mesh_has_addr() function in these instances.

Simplified bt_mesh_elem_find() by removing the search through group
address. Since the above mentioned bt_mesh_has_addr() function handles
instances where group addresses must be searched, it was no longer
necessary to preform this search in this function.

Signed-off-by: Bud Wandinger <bud@budkoembedded.ca>
2021-07-22 06:23:56 -04:00
William Fish
6b67a568c9 Bluetooth: Mesh: Provisioning Start Fix
Resolves provisioning start process

Signed-off-by: William Fish <william.fish@manulytica.com>
2021-07-22 11:20:23 +03:00
Vinayak Kariappa Chettimada
636fbcd081 Bluetooth: Increase maximum allowed identity range to 64
Increase the maximum allowed identity range to 64.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-21 08:37:07 -04:00
Johan Hedberg
9aedfa676b Bluetooth: L2CAP: Fix CIDs in disconnect request
The destination and source CIDs were mixed up in the L2CAP
Disconnect request.

Fixes #36665

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-07-21 10:23:10 +03:00
Lingao Meng
40365babaa Bluetooth: Modify kconfig to use related path
Because we use the extended kconfig, we have already
supported relative paths, and it is clearer to use
relative paths in the bluetooth submodules.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-20 20:02:34 -04:00
Vinayak Kariappa Chettimada
52db419e7a Bluetooth: Mesh: Update advertising duration calculation
Zephyr Bluetooth Low Energy Controller for mesh stack
uses pre-emptible continuous scanning, allowing advertising
events to be transmitted without delay when advertising is
enabled. No need to compensate with scan window duration.

Zephyr Bluetooth Low Energy Controller built for nRF51x
SoCs use CONFIG_BT_CTLR_LOW_LAT=y, and continuous scanning
cannot be pre-empted, hence, scanning will block advertising
events from being transmitted. Increase the advertising
duration by the amount of scan window duration to compensate
for the blocked advertising events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-20 13:35:49 +02:00
Vinayak Kariappa Chettimada
d84397f66d Bluetooth: Controller: Disable scan unreserved for LOW_LAT option
Disable use of BT_CTLR_SCAN_UNRESERVED with BT_CTLR_LOW_LAT.
nRF51x SoC needs to block any CPU use inside radio events,
hence use of radio without time reservation is required for
proper functioning of Controller in nRF51x.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-20 13:35:49 +02:00
Trond Einar Snekvik
abcbfed6c3 Bluetooth: Mesh: Provisioning PDU length defines
Adds length defines for all provisioning PDUs and uses them to split
prov_link.conf_inputs into separate fields.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-07-20 13:32:57 +02:00
Emil Gydesen
6ee70bd220 Bluetooth: Audio: Fix compile error if AICS is not enabled
Fix compile error if AICS is disable but AICS_CLIENT is
enabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-19 20:08:30 -04:00
Emil Gydesen
e6d49645de Bluetooth: Audio: Guard MICS cli/srv structs
Add guards to the structs. This has two purposes:
1) Reduce size of only one of them are enabled
2) Fix a compile issue if only one of them were enabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-19 20:08:30 -04:00
Emil Gydesen
dfc1fa39b6 Bluetooth: Audio: Guard VCS cli/srv structs
Add guards to the structs. This has two purposes:
1) Reduce size of only one of them are enabled
2) Fix a compile issue if only one of them were enabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-19 20:08:30 -04:00
Emil Gydesen
d9213051bd Bluetooth: Audio: Fix MICS client without AICS compile error
Fix an error if MICS client was enabled without MICS AICS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-19 20:08:30 -04:00
Emil Gydesen
a9557531d3 Bluetooth: Audio: Fix compile error for VCS cli if no AICS/VOCS
If either AICS or VOCS clients were not enable, then the VCS
client could not be enabled as there was a compile error
in the function that registered callbacks.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-19 20:08:30 -04:00
Emil Gydesen
61a3b1eb38 Bluetooth: uuid: Use BT_UUID_SIZE_ macros for bt_uuid_create
Use the UUID size macros instead of literal values in
bt_uuid_create.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-19 18:52:41 +02:00
Vinayak Kariappa Chettimada
c1792c002d Bluetooth: Controller: Fix HCI reset assert initiating on coded PHY
Fix HCI Reset Command from asserting when there is pending
connection creation requested on coded PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 14:19:25 +02:00
Vinayak Kariappa Chettimada
a5ac9c65f1 Bluetooth: Controller: Fix SID for legacy advertising reported
SID value for legacy advertising reported shall be 255.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 14:19:15 +02:00
Vinayak Kariappa Chettimada
8818c51cec Bluetooth: Controller: Use sizeof(uint8_t) for Tx Power field size
Use sizeof(uint8_t) for Tx Power field size instead of
auto-increment ++.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 14:19:00 +02:00
Vinayak Kariappa Chettimada
1922a0e982 Bluetooth: Controller: Add target address into common extended header
Add and retain in subsequent updates the target address
in the auxiliary PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 14:19:00 +02:00
Vinayak Kariappa Chettimada
6e0692fc4c Bluetooth: Controller: Fix legacy advertising PDU length initialization
Fix missing initialization of legacy advertising PDU length
when advertising sets are reused between extended and legacy
advertising modes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 14:18:40 +02:00
Vinayak Kariappa Chettimada
e34ec9fc25 Bluetooth: Controller: Use BT_CTLR_BROADCAST_ISO Kconfig option
Use CONFIG_BT_CTLR_BROADCAST_ISO when CONFIG_BT_CTLR_ADV_ISO
or CONFIG_BT_CTLR_SYNC_ISO Kconfig option is supported.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 14:18:31 +02:00
Vinayak Kariappa Chettimada
ba6be70129 Bluetooth: Controller: Added comments for CSA #2 implementation
Added Bluetooth Specification references to the
implementation of Channel Selection algorithm #2 in the
Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 14:18:31 +02:00
Vinayak Kariappa Chettimada
7b12723aad Bluetooth: Controller: Replace test vector inputs with auto variable
Replace hard coded channel map count and channel identifier
with an auto variables.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 14:18:31 +02:00
Vinayak Kariappa Chettimada
b329d198a7 Bluetooth: controller: Implement CSA #2 for SubEvents
Implement the functions required to calculate the SubEvent 1
and SubEvent n mapped channel indices.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 14:18:31 +02:00
Vinayak Kariappa Chettimada
3501148922 Bluetooth: Controller: Legacy vs Extended check for Periodic Adv HCI
Add the check for mixed use of Legacy vs Extended HCI
commands for Periodic Advertising related HCI commands.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 12:28:55 +02:00
Vinayak Kariappa Chettimada
591007206d Bluetooth: Controller: Fix directed advertising report
Fix extended advertising report to set the directed bit in
the event type when receiving directed non-connectable
advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 12:05:10 +02:00
Vinayak Kariappa Chettimada
449d0b29b7 Bluetooth: Controller: Fix extended advertising timeout
Fix extended advertising PDUs seen after the advertising
duration has elapsed, by considering the events skipped
due to overlap with other events which is provided by
the ticker lazy parameter.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 12:04:56 +02:00
Vinayak Kariappa Chettimada
5659b005f1 Bluetooth: Controller: Add checks for invalid PHYs
Add checks for invalid PHYs supplied to HCI LE Extended Scan
Parameters and LE Extended Create Connection commands.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 12:04:36 +02:00
Vinayak Kariappa Chettimada
027835fea6 Bluetooth: Controller: Disallow anonymous legacy advertising
Check and disallow legacy advertising from being anonymous.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-19 12:03:35 +02:00
Piotr Pryga
378a1e082a Bluetooth: controller: remove unnecessary ull_adv_ext_hdr_data struct
After extracting from ull_adv_sync_pdu_set_clear functions:
ull_adv_sync_pdu_alloc, ull_adv_sync_extra_data_set_clear
Use of ull_adv_ext_hrd_data structure became unnecessary.
The extra_data member of the structure was never used
due to separate function responsible for setting extra_data
content.
In all cases content for extended advertising header fields
may be passed to the ull_adv_sync_pdu_set_clear directly
as void * pointer, instead of pointer to ull_adv_ext_hdr_data.

This simplifies use of ull_adv_sync_pdu_set_clear as well
as removes unneccesary code to handle special structure type.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-07-17 16:43:08 -04:00
Piotr Pryga
4c3d76bf8b Bluetooth: controller: remove extra_data use in BIG create and terminate
extra_data is not used by ll_big_create and ll_big_terminate.
extra_data_prev and extra_data_new are optional arguments for
ull_adv_sync_pdu_alloc.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-07-17 16:43:08 -04:00
Piotr Pryga
bef9d14f7f Bluetooth: controller: simplify arg list of ull_adv_sync_pdu_alloc
ull_adv_sync_pdu_alloc function was extracted from ull_adv_sync_pdu_-
-set_clear function. The arguments list of ull_adv_sync_pdu_alloc
was derived from source function but the acutal functionality is
only part of what it was before.

The ull_adv_sync_pdu_alloc does not change extended advertising
PDU header fileds. The hdr_add_fields and hdr_rem_fields arguments
were used to allocate or not allocate memory for extra_data related
with new periodic advertising PDU. Also hrd_data pointer was
not used by the function.

The function arguments list was simplified.
New enum ull_adv_pdu_extra_data_flag was introduced to provide
named flags for extra_data memory management.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-07-17 16:43:08 -04:00
Vinayak Kariappa Chettimada
78e3fe3d75 Bluetooth: Controller: Refactor Periodic Advertising time update
Refactor Periodic Advertising time update function to use
caller supplied Periodic Advertising PDU to calculate the
time reservations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
ab6d4693da Bluetooth: Controller: Use BT_HCI_ERR_SUCCESS return and other changes
Apply suggestions from code review, and change to using
BT_HCI_ERR_SUCCESS instead of returning 0.

Co-authored-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
ead034d514 Bluetooth: Controller: Fix Extended and Periodic Coded PHY time
Fix Extended and Periodic Coded PHY time reservation. The
define earlier used does not have calculations for Coded
PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
177ebac790 Bluetooth: Controller: Periodic advertising time reservation
Implementation to update Periodic Advertising time
reservations when advertising data and/or CTE length is
updated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
91956dadcd Bluetooth: Controller: Disallow Periodic Adv Enable if already enabled
Add check for already enabled and started Periodic
Advertising when HCI LE Set Periodic Advertising Parameters
command is called.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
baca5c2c55 Bluetooth: Controller: Refactor out Periodic Advertising time calc
Refactor out Periodic Advertising time calculations so that
it can be reused when PDU length is updated as part of
advertising data updates.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
f93e41202d Bluetooth: Controller: Extended advertising time reservation
Implementation to update Extended Advertising time
reservations when advertising and scan response data are
updated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
9928c81fbf Bluetooth: Controller: Export primary adv channel event time calc
Export the function calculating the primary channel
advertising event time reservation, so that Extended
Advertising implementation can reuse it.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
dd1b296d46 Bluetooth: Controller: Update DID when scan response data removed
Update DID value when scan response data is remove, length
set to 0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
739b8ad903 Bluetooth: Controller: Refactor out Extended Advertising time calc
Refactor out Extended Advertising time calculations so that
it can be reused when PDU length is updated as part of
advertising data and scan response data updates.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
ee04896ca9 Bluetooth: Controller: Legacy advertising time reservation
Implementation to update legacy advertising time
reservations when advertising and scan response data are
updated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
e50e4f97e0 Bluetooth: Controller: Refactor out advertising time calculations
Refactor out advertising time calculations so that it can be
reused when PDU length is updated as part of advertising
data and scan response data updates.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
85c4095b76 Bluetooth: controller: Extended/Periodic Advertising time reservations
Add Extended and Periodic Advertising radio event time
reservations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
8822b24b17 Bluetooth: Controller: nRF5: Use conservative Tx-Rx turnaround timing
Use a conservative turnaround time of 150us covering slower
nRF51 and faster nRF52 CPU that influence the turnaround
timing.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-16 10:48:39 +02:00
Vinayak Kariappa Chettimada
7cd77c2cec Bluetooth: Add identifiers for Bluetooth 5.3
The Bluetooth 5.3 specification was recently released, and
has a new version identifier (12) assigned to it in the
Bluetooth Assigned Numbers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-15 13:56:03 +02:00
Piotr Pryga
a95457a984 Bluetooth: controller: df: Fixes truncated transmission of CTE
There was an issue with wrong length of CTE send in connectionless
mode, with periodic advertising PDUs. Radio peripheral was not
configured to send CTE with correct length while PDU had CTEInfo
field informing receiver that CTE is attached to the PDU.

Source of the problem was in ll_df_set_cl_cte_tx_enable function.

Order of parameters in ull_adv_sync_pdu_alloc was wrong.
ULL_ADV_PDU_HDR_FIELD_CTE_INFO was speficed as hdr_rem_fields.
Because of that extra_data, memory used to provide CTE configuration
to LLL, was not allocated. PDU content is prepared in ULL, so CTEInfo
field included correct information, while Radio was never configured
by LLL to send CTE.

ull_adv_sync_extra_data_set_clear received a pointer to hdr_data,
instead of a direct pointer to df_cfg structure. When extra_data
was allocated correclty, wrong CTE configuration was provided
copied there and LLL received invalid CTE length. It was different
than the length in PDUs CTEInfo field.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-07-15 11:39:13 +02:00
Michał Narajowski
ca53e86f67 Bluetooth: Mesh: Add msg length check for Cfg and Health models
According to spec we should ignore messages with incorrect msg size.
This patch adds a check to every opcode handler.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-07-15 11:34:52 +02:00
Michał Narajowski
b9422ea9f3 Bluetooth: Mesh: Add return value for opcode callback
```
3.7.3.4 Message error procedure
When receiving a message that is not understood by an element, it shall
ignore the message.
Note: A message can be falsely identified as a valid message, passing
the NetMIC and TransMIC authentication using a known network key and
application key even though that message was sent using different keys.
The decryption of that message using the wrong keys would result in a
message that is not understood by the element. The probability of such a
situation occurring is small but not insignificant.
A message that is not understood includes messages that have one or more
of the following conditions:
• The application opcode is unknown by the receiving element.
• The access message size for the application opcode is incorrect.
• The application parameters contain values that are currently
Prohibited.
Note: An element that sends an acknowledged message that is not
understood by a peer node will not receive any response message.
```

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-07-15 11:34:52 +02:00
Ingar Kulbrandstad
3ec6411c7f Bluetooth: Mesh: Align capitalization for BT mesh
Align the capitalization of the term "Bluetooth Mesh" to Bluetooth mesh"
in the documentation. This is done to to match the new updated naming
convention done in Bluetooth SIG. In the upcoming spec versions, it its
used "Bluetooth mesh" with the lower case convention.

Signed-off-by: Ingar Kulbrandstad <ingar.kulbrandstad@nordicsemi.no>
2021-07-13 11:23:54 -04:00
Mark Wang
149d490b3f Bluetooth: SDP: judge the buf->len before sys_get_be16
There may be less than 2 bytes in buf before calling sys_get_be16.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2021-07-13 14:18:28 +03:00
Vinayak Kariappa Chettimada
9bc9e15852 Bluetooth: Controller: Fix Periodic Sync setup with invalid channels
Fix Periodic Synchronization setup when handling invalid
number of channel count in Periodic Advertising's Sync Info
structure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-12 17:23:51 +02:00
Vinayak Kariappa Chettimada
40374df24f Bluetooth: Controller: Use macros for SCA and Channel Map access
Use macros to access SCA and Channel Map fields in the Sync
Info structure in advertising PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-12 13:19:46 +02:00
Vinayak Kariappa Chettimada
71c6d11b08 Bluetooth: Controller: Minor fix debug message with channel map mask
Minor fix to channel map mask used in debug message to print
sync info fields.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-12 13:19:46 +02:00
Vinayak Kariappa Chettimada
53cd7f7152 Bluetooth: controller: Refactor sync_info population
Based on review comments, refactor out sync_info population
to be performed by the caller of the function that prepares
the extended advertising PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-12 13:19:46 +02:00
Vinayak Kariappa Chettimada
300f1bb6a0 Bluetooth: controller: Use set/clear to add/remove ACAD
Use the set/clear function to modify the common extended
header format in the PDU to add/remove ACAD.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-12 13:19:46 +02:00
Vinayak Kariappa Chettimada
693ae63145 Bluetooth: controller: Add/Remove ACAD on create/terminate BIG
Added implementation to add/remove ACAD field in the common
extended header format of the periodic advertising PDU on
create/terminate BIG.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-12 13:19:46 +02:00
Vinayak Kariappa Chettimada
f3d9808012 Bluetooth: Controller: Warn when building experimental features
Add CMake warning message when building experimental
features like Advertising Extensions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-10 14:53:26 -04:00
Andrzej Kaczmarek
9db0a18158 Bluetooth: controller: Remove adv_sync_hdr_set_clear
adv_sync_hdr_set_clear was just wrapped by ull_adv_sync_pdu_set_clear
so we can merge both into single function.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
678ec60f36 Bluetooth: controller: Add helper to update CTEInfo
This adds simple helper to update CTEInfo. It assumes proper periodic
adv PDU as input to simplify code.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
1ebecdf606 Bluetooth: controller: Add initial support to update AD in chain
This adds some initial support to update AD in chain. We still only
support placing AD in 1st PDU, but this will properly copy any linked
PDUs that may be added due to e.g. CTEInfo present.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
45ebbbf04b Bluetooth: controller: Add helper to initialize adv PDU from scratch
This adds adv_sync_pdu_init helper which initializes pdu_adv buffer
with contents of AUX_SYNC_IND/AUX_CHAIN_IND PDU. Extended header flags
can be specified to reserve required space for corresponding fields if
necessary.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
7c81ed71d0 Bluetooth: controller: Enable back-to-back chaining for periodic adv
This enables chaining ota for periodic advertising. AUX_CHAIN_IND PDUs
will be sent automatically if AuxPtr is detected in preceding PDU.
AuxPtr offset is always set to achieve minimal required frame spacing,
i.e. 300us (T_mafs). AuxPtr in all PDUs in advertising train are
updated on enqueue since PDU spacing is already known at that time so
we do not need to waste time in LLL.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
21892eecf1 Bluetooth: controller: Add support for linked adv PDUs
This adds support to allow advertising PDUs to be linked which is
required to send advertising trains, i.e. AUX_CHAIN_IND.

PDUs are linked with a simple single-linked list, the pointer to next
PDU is stored at the very end of PDU buffer. This prevents it from
being overwritten if PDU is modified and allows for build time offset
calculation.

There are few helpers added to make handling easier, e.g.:
- get next linked PDU
- get last linked PDU
- link one PDU to another
- link PDU at the end
- release all linked PDUs (except for 1st)

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
1e02d400e2 Bluetooth: controller: Optimize lll_adv_pdu_and_extra_data_alloc
This function is the same as lll_adv_pdu_alloc except it also allocates
extra data at the end - it can just use lll_adv_pdu_alloc call to avoid
extensive c&p.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
5af3e39574 Bluetooth: controller: Add helper to allocate new pdu_adv
This adds helper to always allocate advertising PDU either from memory
pool or pdu_free queue and does not reuse existing PDU in adv_pdu.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
67bfb2fb56 Bluetooth: controller: Fix PKT_AC_US macro
Advertising channel packets do not have MIC, there's no need to have
extra parameter which always has to be set to 0 anyway.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Emil Gydesen
f18bebd9de Bluetooth: Iso: Do not remove iso data path on disconnect
We previously removed the iso data path when the iso channel
disconnected. Since the iso data path is unique for a given
iso channel (by handle), it does not make sense to remove
it for a disconnected channel, as the channel is, in
a sense, not existing anymore.

This update is to better comply with the bluetooth
core spec, and to avoid getting errors from the
controller on disconnect.

Rather than removing the implementation of being able
to remove the data path, the function was made non-static
and moved to the internal header file, in case we ever
want to use it. This should not affect compile size.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-10 12:41:48 -04:00
Emil Gydesen
f50574a6a0 Bluetooth: host: Move bt_data_parse to hci_core.c
Move the function from scan.c to hci_core.c.
When in scan.c, the function is only available if
CONFIG_BT_OBSERVER was enabled. Since the function
can be used in other scenarioes where we need to parse
LTV data, it has been moved to a more generic place.

hci_core.c might not be the ideal place, but it is
where most other common bluetooth functions
are located.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-10 12:41:18 -04:00
Lingao Meng
3d2ad8e653 Bluetooth: Mesh: Split proxy.h to proxy.h and proxy_msg.h
The Bluetooth proxy feature includes proxy client and proxy server.
In addition to the proxy pdu message used above, pb-gatt also uses
the same proxy pdu message.

Currently zephyr bluetooth mesh couples them in one file.

A file at the separation is called gatt_services.c,
which is used to contain Mesh Provisioning Service and
Mesh Proxy Service.

Another file in the separation is called proxy_msg.c,
which is used to process Proxy pdu messages.

Also according to Trond's suggestion:

Rename CONFIG_BT_MESH_PROXY to CONFIG_BT_MESH_GATT.
Create an additional promptless entry CONFIG_BT_MESH_GATT_SERVER
that selects CONFIG_BT_MESH_GATT and is selected by
CONFIG_BT_MESH_GATT_PROXY or CONFIG_BT_MESH_PB_GATT.

Create additional CONFIG_BT_MESH_PROXY used to represent
proxy feature (also include proxy client).

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-09 17:56:16 +03:00
Lingao Meng
7b2e51881c Bluetooth: Mesh: Rename proxy.c to proxy_msg.c
The Bluetooth proxy feature includes proxy client
and proxy server. In addition to the proxy pdu
message used above, pb-gatt also uses the same
proxy pdu message.

Currently zephyr bluetooth mesh couples them in one file.

A file at the separation is called gatt_services.c,
which is used to contain Mesh Provisioning Service and
Mesh Proxy Service.

Another file in the separation is called proxy_msg.c,
which is used to process Proxy pdu messages.

Also according to Trond's suggestion:

Rename CONFIG_BT_MESH_PROXY to CONFIG_BT_MESH_GATT.
Create an additional promptless entry CONFIG_BT_MESH_GATT_SERVER
that selects CONFIG_BT_MESH_GATT and is selected by
CONFIG_BT_MESH_GATT_PROXY or CONFIG_BT_MESH_PB_GATT.

Create additional CONFIG_BT_MESH_PROXY used to represent
proxy feature (also include proxy client).

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-09 17:56:16 +03:00
Lingao Meng
3a559e972a Bluetooth: Mesh: Modularizing the proxy
The Bluetooth proxy feature includes proxy client
and proxy server. In addition to the proxy pdu
message used above, pb-gatt also uses the same
proxy pdu message.

Currently zephyr bluetooth mesh couples them in one file.

A file at the separation is called gatt_services.c,
which is used to contain Mesh Provisioning Service
and Mesh Proxy Service.
Another file in the separation is called proxy_msg.c,
which is used to process Proxy pdu messages.

Also according to Trond's suggestion:

Rename `CONFIG_BT_MESH_PROXY` to `CONFIG_BT_MESH_GATT`.
Create an additional promptless entry
`CONFIG_BT_MESH_GATT_SERVER` that selects
`CONFIG_BT_MESH_GATT` and is selected by
`CONFIG_BT_MESH_GATT_PROXY` or `CONFIG_BT_MESH_PB_GATT`.

Create additional `CONFIG_BT_MESH_PROXY` used to represent
proxy feature (also include proxy client).

see #36343

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-09 17:56:16 +03:00
Vinayak Kariappa Chettimada
b81cecf8df Bluetooth: Controller: Use define for offset unit and SCA calculation
Use defines for offset unit and for calculation of Periodic
Advertising window widening using clock accuracy value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-06 18:51:51 -04:00
Vinayak Kariappa Chettimada
6684af11b9 Bluetooth: Controller: Fix clock accuracy calculation scanning Aux PDU
Fix clock accuracy value used in the calculation of window
widening applied when scanning for auxiliary PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-06 18:51:51 -04:00
Kamil Piszczek
bd7d28ef7d bluetooth: services: hrs: use template for logging configuration
Use template for logging configuration in Bluetooth HR service.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2021-07-05 14:34:25 +03:00
Kamil Piszczek
dd5a0d1997 bluetooth: services: hrs: add characteristic permission config
Added a configuration of characteristic access permissions for
Bluetooth Heart Rate service.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2021-07-05 14:34:25 +03:00
Abe Kohandel
d6314fa456 bluetooth: ots: Add object name write capability
Add the ability to perform a write on the object name GATT
Characteristic with a notification callback to the application
that the name has been written.

In order for this operation to work the memory backing the
object name must be modifiable. To prevent forcing the user
to always allocate 120 bytes for the name, the maximum name
length is changed from a define to a configuration parameter.

Signed-off-by: Abe Kohandel <abe.kohandel@gmail.com>
2021-07-02 22:22:24 -04:00
Patrick Rathje
cb6ef1328b Bluetooth: L2CAP: Fix missing net_buf_unref()
In case of non-recoverable errors (e.g. the connection breaks while
transmitting), the l2cap_chan_tx_process deques the net_buf but does
not unreference it. As this is inside a work queue thread, the sending
thread gets no information on this error, relying on the tx_process to
ultimately free the buffer.

Signed-off-by: Patrick Rathje <git@patrickrathje.de>
2021-07-02 22:22:02 -04:00
Vinayak Kariappa Chettimada
3cc8f31744 Bluetooth: Controller: Fix auxiliary scan context leak
Fix an auxiliary scan context leak when initiator
establishes a connection while there is another pending
auxliary PDU scheduled to be received. In this case, the
pending auxliary scan LLL context does an early abort
without generating a scan aux done event. Missing scan aux
done event caused the auxiliary scan context leak.

Fixes #36131.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-02 13:05:36 -04:00
Pavel Vasilyev
6c9411656c Bluetooth: Mesh: Restore default device configuration on reset
This commit fixes an issue where bt_mesh_reset() call just erases all
mesh flags set at the initialization instead of restoring them and
thus disabling some features until the board reboot.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-07-02 16:58:21 +03:00
Vinayak Kariappa Chettimada
aab30dad6f Bluetooth: controller: Use S8 encoding Tx chain delay
Minor update to calls to get Tx chain delay in extended
advertising and scanning to use S8 encoding delays.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:31:16 -04:00
Vinayak Kariappa Chettimada
c7dd004148 Bluetooth: controller: PA/LNA radio timing tuned
PA/LNA related timing calculations tuned for extended
advertising and scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:31:16 -04:00
Vinayak Kariappa Chettimada
3f519fea17 Bluetooth: controller: Fix 1st connection event offset for peripheral
We need to take RX chain delay and PHY used to receive
CONNECT_IND into account when calculating 1st connection
event offset.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:31:16 -04:00
Vinayak Kariappa Chettimada
abc573e0f5 Bluetooth: Controller: Define a macro for active clock jitter value
Define a macro for active clock jitter value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:31:16 -04:00
Vinayak Kariappa Chettimada
d510351b4f Bluetooth: controller: Fix Tx-Rx switch delay calculation
In the Tx to Rx switch, fix the delay which should be the
Rx ready delay plus the Tx chain delay and plus 4 us active
clock jitter compensation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:31:16 -04:00
Vinayak Kariappa Chettimada
0bd05c0ed9 Bluetooth: Controller: Rename CPR mutual exclusion functions
Rename CPR mutual exclusion function to not sound similar to
OS mutex interfaces.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:30:50 -04:00
Vinayak Kariappa Chettimada
a8d4c062fa Bluetooth: Controller: Use inline functions for CPR mutex operations
Use inline functions for CPR mutex operations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:30:50 -04:00
Vinayak Kariappa Chettimada
d518337835 Bluetooth: Controller: Cleanup mutual exclusion in CPR implementation
Minor cleanup of the implementation of mutual exclusion
of LE Connection Parameter Request amongst active
connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:30:50 -04:00
Lingao Meng
cc0abee3db Bluetooth: Mesh: Check the CID field before opcode compare
Bluetooth Mesh Vendor model hava company id field.

Accordin MeshPRFV1.0.1 3.7.3.1 Operation codes.

The 3-octet opcodes are used for manufacturer-specific opcodes.
The company identifiers are 16-bit values defined by the
Bluetooth SIG and are coded into the second and third octets of
the 3-octet opcodes.

Therefore, we can speed up the search process by checking whether
CID fields match, rather than comparing opcodes one by one.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-06-29 17:08:02 -04:00
Vinayak Kariappa Chettimada
d3c27aeb8f Bluetooth: Controller: Fix Data Length Update node Rx reservations
Reserve a minimum node rx of 2 that can happen when local
central initiated PHY Update reserves 2 node rx, one for PHY
Update complete and another for Data Length Update complete
notification. Otherwise, a peripheral only needs 1
additional node rx to generate Data Length Update complete
when PHY Update completes.

Relates to #36381.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-29 17:05:20 -04:00
Vinayak Kariappa Chettimada
6810facffa Bluetooth: Controller: Fix free rx buffer MFIFO enqueue
Replace the post decrement in loop's conditional into
explicit decrement inside the loop so as to avoid
decrementing the maximum count without enqueueing free rx
buffers into the free rx buffer MFIFO.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-29 17:05:20 -04:00
Vinayak Kariappa Chettimada
ecf7106177 Bluetooth: Controller: Minor change to use IS_ENABLED
Minor changes to use IS_ENABLED and updates to comments in
code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-29 17:05:20 -04:00
Emil Gydesen
50cea984b8 Bluetooth: ISO: Only remove CIG as central
The hci_le_remove_cig command shall only be sent as the
master/central. Implemented this by early termination in
bt_iso_cleanup as the slave/peripheral.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-29 10:38:14 -04:00
Vinayak Kariappa Chettimada
5627ce32c7 Bluetooth: Controller: Fix peripheral tx, rx and time reservations
Fix peripheral maximum transmit time, maximum receive time
and radio event length time reservations when connection
established using Extended Advertisements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-28 11:58:45 -04:00
Vinayak Kariappa Chettimada
bb50284676 Bluetooth: Controller: Fix central tx, rx and time reservations
Fix central maximum transmit time, maximum receive time
and radio event length time reservations when connection
established using Extended Advertisements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-28 11:58:45 -04:00
Trond Einar Snekvik
534177b2ca Bluetooth: Mesh: Fix regression in PB-ADV
After #35702, the provisioner is unable to mark a link as closed, as
it depends on the send_end callback to be called, so it can start its
timer. PB-Adv keeps a reference to the buffers of reliable messages,
which prevents this callback to be invoked, as the buffer destructor is
never called.

Move scheduling of the retransmit timer to the initial transmission, and
replace the timer based LINK_CLOSE message tx duration with a message
counting solution.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-06-27 19:51:47 +03:00
Emil Gydesen
141620519b Bluetooth: Audio: AICS client add function to get conn pointer
Add a function that returns the bluetooth connection
pointer of a given AICS client instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 11:31:04 -04:00
Emil Gydesen
7e6d927467 Bluetooth: Audio: AICS remove need for bt_conn pointer
Remove the bt_conn pointer from the AICS API, as the
instance pointer is enough to determine if it is a client
and perform client operations on the cached connection pointer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 11:31:04 -04:00
Trond Einar Snekvik
c6945fbb1d Bluetooth: Mesh: Ensure proxy_send's attribute is always set
Initializes proxy_send's attr pointer, which in theory could be
uninitialized if neither gatt proxy or PB GATT is enabled while proxy.c
is enabled.

This scenario is not really possible with the current kconfig structure,
but is reported as a potential error by Coverity, and should be fixed
for future proofing purposes.

Fixes #36314.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-06-24 11:30:26 -04:00
Emil Gydesen
cefaba47f8 Bluetooth: Audio: Fix MICS client deref of null pointer
The mute_val pointer could be NULL when dereferenced in the
callback. Change to be a simple value which is just assigned
instead.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 11:29:34 -04:00
Emil Gydesen
c42a511d39 Bluetooth: Audio: VCS update client check in API functions
Update the check if the instance is a client to be
a more simple check.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
5d4992ae25 Bluetooth: Audio: VCS client add function to get conn pointer
Add a function for the VCS client that gets the bluetooth
connection pointer if a given VCS client instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
946013e25f Bluetooth: Audio: VCS register return if already registered
Change how bt_vcs_register works if VCS has already been
registered.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
0043c741a5 Bluetooth: Audio: Update VCS API to use bt_vcs
Update the VCS API to use the bt_vcs struct instead
of the bt_conn. This is create a more simple API
that uses a, remote or loca, instance pointer, rather
than a specified connection (for remote) or NULL (for
local) operations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
a1c7a48ee3 Bluetooth: Audio: VCS client change to use bt_vcs instead of bt_vcs_client
Change to use the generic bt_vcs struct instead of the bt_vcs_client
struct, to align better with the future API change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
65f59e73dd Bluetooth: Audio: VCS use bt_vcs struct instead of bt_vcs_server
Change the type of the vcs_inst in vcs.c to bt_vcs instead
of bt_vcs_server to align better with the future API change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
c7375079cc Bluetooth: Audio: VCS client return pointer to instance on discover
Add return of instance pointer in bt_vcs_discover so that a client
will get a bt_vcs pointer when doing discover, which will be
used going forward in the API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
db025e26a6 Bluetooth: Audio: VCS introduce opaque bt_vcs struct
Add a bt_vcs struct that represents a VCS instance,
either a local (server) or remote (client) instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
973e88104f Bluetooth: Audio: MICS client add function to get conn pointer
Add a function that returns the bluetooth connection
pointer of a given MICS client instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:34:37 +02:00
Emil Gydesen
12103771af Bluetooth: Audio: MICS register return if already registered
Change how bt_mics_register works if MICS has already been
registered.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:34:37 +02:00
Emil Gydesen
3c9f943fa7 Bluetooth: Audio: Update MICS API to use bt_mics
Update the MICS API to use the bt_mics struct instead
of the bt_conn. This is create a more simple API
that uses a, remote or loca, instance pointer, rather
than a specified connection (for remote) or NULL (for
local) operations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:34:37 +02:00
Emil Gydesen
f7ca9b4afa Bluetooth: Audio: MICS client change to use bt_mics
Change to use the generic bt_mics struct instead of the
bt_mics_client struct, to align better with the future
API change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:34:37 +02:00
Emil Gydesen
8ca8dabc19 Bluetooth: Audio: MICS use bt_mics struct instead of bt_mics_server
Change the type of the mics_inst in mics.c to bt_mics instead
of bt_mics_server to align better with the future API change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:34:37 +02:00
Emil Gydesen
f42d6c475c Bluetooth: Audio: MICS client return pointer to instance on discover
Add return of instance pointer in bt_mics_discover so that a client
will get a bt_mics pointer when doing discover, which will be
used going forward in the API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:34:37 +02:00
Emil Gydesen
d6fd79f65d Bluetooth: Audio: MICS introduce opaque bt_mics struct
Add a bt_mics struct that represents a MICS instance,
either a local (server) or remote (client) instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:34:37 +02:00
Mark Wang
5daf0b2fad bluetooth: rfcomm: fix the coverity 203443 memory corruptions
- Coverity think it is out-of-bound writing
because the codes write two bytes to address (&hdr->length)
that hdr->length is uint8_t. Coverity doesn't think about
the one more byte after the hdr->length.
- Use net_buf_push to resolve this issue.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2021-06-24 11:57:33 +03:00
Pavel Vasilyev
5513b86864 Bluetooth: Mesh: Update SNB beacon before sending it
Authentication value must be recalculated before sending it.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-06-23 08:02:38 -04:00
Joakim Andersson
b4ce2ba481 Bluetooth: host: Add helper function to find an attribute from its uuid
Expose a helper function to the application that searches the local
database for the given attribute from its UUID.
Provide arguments to limit the search that matches the service
declaration to make it easy to limit the search to a specific service.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-22 09:06:00 -04:00
Joakim Andersson
3ad3a72caf Bluetooth: host: Allow attribute as NULL with notify / indicate by UUID
Allow to pass attribute as NULL pointer when using notify or indicate by
UUID. This will use the entire handle value range to search for an
attribute with a matching UUID.
Document optional parameters, and clarify attr and uuid usage in the
variable declaration in the struct for clarification.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-22 09:06:00 -04:00
Vinayak Kariappa Chettimada
d76baf9bbb Bluetooth: Controller: Fix ticker ops count for extended initiator
Increase the ticker operations count in ULL high context
when Extended Advertising Connection Establishment on Coded
PHY is supported.

This fixes assertion in Controller when initiating a
connection on Coded PHY, wherein two scan instance ticker,
one window stop ticker, and a new connection instance
ticker operations needs to be enqueued.

Relates to commit a6b8eba7c5 ("Bluetooth: controller:
Implement disabling the other PHY initiator").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-22 08:24:00 -04:00
Emil Gydesen
a1cf45b26e Bluetooth: ISO: Split connected and broadcast ISO Kconfig
Add a new Kconfig option, BT_ISO_UNICAST, to make it possible
either configure unicast only, broadcast only or both.

This results in some code being moved, but not modified, and
should not effect anything.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-22 08:21:00 -04:00
Krzysztof Kopyściński
e62c3c533a Bluetooth: gatt: allow writing long device name
BT_DEVICE_NAME_MAX can be up to 248 bytes. This may exceed ATT MTU size,
which will cause the offset in write_name() to be non zere, resulting in
BT_ATT_ERR_INVALID_OFFSET. However, device name should be writable up to
it's defined size, using subsequent prepare write requests. Error should
be returned if offset exceeds size of device name, and if total size of
new value exceeds BT_DEVICE_NAME_MAX, BT_ATT_ERR_INVALID_ATTRIBUTE_LEN
shall be returned.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-06-19 16:55:56 -05:00
Emil Gydesen
22cfbd3dbd Bluetooth: Host: Modify check for read buffer size v2
Modify the check from checking the feature bit to
checking the command bit. This ensures that we
don't send the read buffer size V2 to a controller
that does not support it.

This also moves the entire ISO init procedure into
a separate function to avoid having a large
ISO-only block in `le_init`.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-18 11:21:14 +02:00
Krzysztof Kopyściński
9bf65e557b Bluetooth: gatt: add checks for db out of sync on read mult requests
This check is present in att_read_rsp(), but att_read_mult_req and
att_read_mult_vl_req do not use it. Add this check to these functions.

This was affecting GATT/SR/GAS/BV-08-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-06-18 00:41:23 +03:00
Lingao Meng
3e492665c0 Bluetooth: Controller: Add net_buf_ref ret value to variables
Return value should assigns to variables instead of ignoring them.

Related to PR(#36259).

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-06-17 12:46:05 +03:00
Lingao Meng
4820989195 Bluetooth: Add missing store net_buf_ref ret value
... related to(#36259)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-06-17 12:46:05 +03:00
YanBiao Hao
d466a807ee Bluetooth: Mesh: comp pointer check
comp data pointer check before using

Signed-off-by: YanBiao Hao <haoyanbiao@xiaomi.com>
2021-06-16 22:58:44 -05:00
Krzysztof Kopyściński
5f9d760755 bluetooth: l2cap: fix ecred conn response for all connections refused
If all connections were refused, we haven't reached part of
le_ecred_conn_req with connecting channels - thus i was never
incremented. PDU shall be created always with the length containing
full size of scid array - we always respond with all of the CIDs filled,
they just will be all zeros when all connections were refused.

This was affecting L2CAP/ECFC/BV-26-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-06-16 10:41:51 +02:00
Morten Priess
d1f71e93a0 Bluetooth: controller: CIS/CIG teardown at ACL disconnect
When an ACL connection with active CISes terminates, inject CIS/CIG
teardown to ensure CIS is stopped before ACL disconnection completes.
This includes stopping CIG ticker when last CIS has stopped.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-06-16 10:38:38 +02:00
Morten Priess
01e7dd853f Bluetooth: controller: Remove cis_handles array from ISO groups
Maintaining the cis_handles array in ULL/LLL ISO group data amounts to
double book-keeping. This commit eliminates the array and introduces a
'getter' for obtaining CISes owned by a specific CIG, and iterate
through them.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-06-16 10:38:38 +02:00
Morten Priess
ab40e57894 Bluetooth: host: Disconnect all ISO channels on BT_CONN_DISCONNECTED
When an ACL changes state to disconnected, all associated ISO channels
must be disconnected and cleaned up. This commit ensures that.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-06-16 10:38:38 +02:00
Lingao Meng
c45ec6fc0d Bluetooth: Mesh: Fix missing proxy send status
Add an error judgment during `proxy_send` to avoid
missing `net_buf_unref`.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-06-16 11:01:41 +03:00
YanBiao Hao
f6d7f8f36f bluetooth: mesh: sequence number limit config
set sequence number limit by Kconfig

Signed-off-by: YanBiao Hao <haoyanbiao@xiaomi.com>
2021-06-15 12:51:50 +03:00
Vinayak Kariappa Chettimada
97598c4d61 Bluetooth: controller: Yield scan window when scanning Aux PDUs
Use ticker_yield_abs interface to make scan window on
primary channel to yield when trying to scan auxiliary PDUs.

Fixes #30244.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-14 15:19:33 +02:00
Vinayak Kariappa Chettimada
bce82ad49b Bluetooth: controller: Add ticker_yield_abs interface
Add ticker_yield_abs interface to reduce ticks_slot_previous
value when radio events yield/stop earlier than their time
reservations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-14 15:19:33 +02:00
Trond Einar Snekvik
f2579cb3f2 Bluetooth: Mesh: Increase default CDB node count
The old default of 1 makes provisioner devices useless, as they can only
provision themselves before they run out of space.

Increase the default value for CONFIG_BT_MESH_CDB_NODE_COUNT to 8.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-06-14 15:19:07 +02:00
Emil Gydesen
b450e63f28 Bluetooth: Audio: AICS use bt_aics instead of bt_aics_server
Modify aics.c to use the bt_aics struct instead of the
bt_aics_server struct. This is done so that there is less
difference between the internal struct usage and the struct
type used in the API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-14 14:54:59 +02:00
Emil Gydesen
6b2cc7e57e Bluetooth: Audio: Rename bt_vcs to bt_vcs_included
Rename the struct from bt_vcs to bt_vcs_included, and
rename bt_vcs_get to bt_vcs_included_get as that is more
descriptive of the value returned.

Furthermore, this will also allow us to use bt_vcs as
an opaque pointer to a VCS service instance (local
or remote) to match the service instance pointers of
AICS and VOCS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-14 14:25:55 +02:00
Emil Gydesen
d52b4ac4bf Bluetooth: Audio: Rename bt_mics to bt_mics_included
Rename the struct from bt_mics to bt_mics_included, and
rename bt_mics_get to bt_mics_included_get as that is more
descriptive of the value returned.

Furthermore, this will also allow us to use bt_mics as
an opaque pointer to a MICS service instance (local
or remote) to match the service instance pointers of
AICS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-14 14:25:49 +02:00
Emil Gydesen
b683bea5d7 Bluetooth: Audio: VOCS client add function to get conn pointer
Add a function that returns the bluetooth connection
pointer of a given VOCS client instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-14 14:25:42 +02:00
Lingao Meng
7531d2e3c8 Bluetooth: Mesh: Add proxy send callback
Zephyr Bluetooth Mesh did not check whether the proxy message
was actually sent out, so that the response message could
not be received during reset. It did not solve the status
callback of the proxy sending message, so a new problem was
introduced after PR(#28457) merged.

bt_mesh_prov_send(&buf, public_key_sent))

This PR will try to solve the above problem, and will fix
the problem due to thread competition, and PR(#26668) will
not be necessary.

Compared with PR(#30138), it no longer consumes extra RAM
space and supports synchronization of group addresses

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-06-14 11:52:21 +03:00
Lingao Meng
a63f2d8d60 Bluetooth: Mesh: Reconstructing adv callback logic
The adv callback logic is reconstructed to coexist
with proxy send callback.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-06-14 11:52:21 +03:00
Kumar Gala
3f149f0828 bluetooth: Removed deprecated bt_set_id_addr function
The function have been deprecated for 2 releases so remove the code
associated with it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-06-11 16:35:19 -05:00
Piotr Pryga
15375d4478 Bluetooth: controller: Fix wrong channel index in IQ samples report
Fix wrong channel index send by controller in connectionless
IQ samples report. Former implementation reported value from
lll->data_chan_id which is not valid channel index.
Updated implementation reports value stored in IQ samples receive
node during periodic scanning event preparation.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-06-11 17:14:29 +02:00
Morten Priess
fa20fa95d0 Bluetooth: controller: Improve ticker_by_next_slot_get
Fixes ticker_by_next_slot_get for JIT scheduler by allowing iterating
through ticker nodes without ticks_slot information, and improves
performance for legacy ticker scheduling use.

To reduce the processing and context switching overhead, a new feature
is introduced via BT_TICKER_NEXT_SLOT_GET_MATCH, by which an operation
callback may be added via the ticker_next_slot_get_ext interface, and
the match function is then called when the ticker_job is processing the
request.
By returning true in this callback, iteration stops and normal operation
callback is invoked. If the match function returns false, node iteration
continues. This reduces the number of ticker_job executions for node
iteration.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-06-11 16:18:55 +02:00
Joakim Andersson
946cf25f78 Bluetooth: shell: Use UUID encode macro for 128-bit UUIDs
Use UUID encode macro fro 128-bit UUIDs for readability. This makes
it easier to see which service you are working with as the
bt_uuid_to_str prints the 128-bit UUIDs in this format.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-11 16:13:35 +02:00
Emil Gydesen
18f1745d29 Bluetooth: ISO: Add packet status flag to iso recv info
Add the packet status flag value to the iso receive info
struct. This will allow an application to handle potential
lost or erroneous messages.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-11 16:12:34 +02:00
Pavel Vasilyev
65f798a00a Bluetooth: Mesh: Add API to manually store pending RPL entries
The current approach with storing RPL by timeout doesn't solve all
issues as the node may loss power before the timer is fired.
In addition to that this may wear out flash quickly if short timeout is
used.

This change adds an API to store the pending RPL entry upon user
request. Additional Kconfig option allows to completely disable timer
so that the whole storing relies on the user.

The mesh stack still stays responsible for outdating RPL entries in case
of IV Index update as this happens implicitly for the user.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-06-11 15:47:09 +02:00
Pavel Vasilyev
f5ba999257 Bluetooth: Mesh: Fix setting remote public key in provisioner
This aligns provisioner and provisionee APIs in terms of endianess
of public key provided by an application.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-06-10 17:14:03 -04:00
Pavel Vasilyev
0335d5fb01 Bluetooth: Mesh: Add OOB Public Key support for provisionee role
This commit allows an unprovisioned device to exchange its public key
using out-of-band techology (see MeshPRFv1.0.1, table 5.19 and section
5.4.2.3).

For in-band public key exchange, the mesh stack uses HCI commands to
generate public and private keys, and DH key. This, however, doesn't
work for OOB public key exchange since there is no command to generate
DH key with a private key provided by an application. Therefore, this
commit adds direct usage of TinyCrypto into the mesh stack for DH key
generation for OOB public key support.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-06-10 17:14:03 -04:00
Jonathan Rico
ecae33740d Bluetooth: host: Prevent race condition in pairing procedure
Moving the key check after checking that no pairing or encryption
procedure is started fixes a race condition that is seen in some PTS
tests:

GATT/CL/GAR/BI-04-C
GATT/CL/GAR/BI-16-C
GATT/CL/GAR/BI-21-C
GATT/CL/GAW/BI-05-C
GATT/CL/GAW/BI-12-C

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2021-06-10 17:13:41 -04:00
Carles Cufi
d9848b155d Bluetooth: host: Optionally disable GATT sec re-establishment
Some centrals deal poorly with receiving a security request immediately
after reconnection whenever reconnecting with characteristics that are
notifiable or indicatable and requiring security. In particular,
Android 9 and earlier devices may lose bond information when this
happens, some Microsoft Surface devices will enter an invalid state
and, on top of that, Apple's Bluetooth Low Energy guidelines explicitly
discourage this behavior.

In order to allow interoperability with those devices, make the GATT
automatic security request sending as a peripheral optional by
introducing a new Kconfig option, BT_GATT_AUTO_SEC_REQ.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-06-09 21:10:14 +03:00
Faisal Saleem
c9fd7a6099 Bluetooth: Keys: Fix BT_KEYS_OVERWRITE_OLDEST logic for BT_MAX_CONN > 1
When the Bluetooth stack is configured for CONFIG_BT_MAX_CONN > 1
the oldest key might currently be in use.  Fix the logic to ensure the
oldest key overwritten is from the set of keys currently not in use.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/35999

Signed-off-by: Faisal Saleem <faisal.saleem@setec.com.au>
Signed-off-by: Nick Ward <nick.ward@setec.com.au>
2021-06-08 20:18:49 +02:00
Pavel Vasilyev
33fafe1e2f Bluetooth: Mesh: Reject identical public keys
This commit address Erratum E10395 and Errata Correction E16350
to ensure that public keys exchanged between Provisioner and
a device aren't identical.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-06-07 18:56:26 +03:00
Piotr Pryga
7afc31a834 Bluetooth: host: Unmask CTE report related events for DF connected mode
Unmask events related with CTE report for Direction Finding
working in connected mode.
The feature is enabled conditionally, depending on KConfig
configuration provided.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-06-07 17:09:01 +02:00
Piotr Pryga
a717e8c2a6 Bluetooth: host: Add option to enable connection CTE RX
Add Kconfig option that will enable support for CTE reception
in connected mode. Thanks to that it will be possible to
conditionally enable or disable support of the feature and
decrease code size if the feature is not required.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-06-07 17:09:01 +02:00
Emil Gydesen
f500e0fb9c Bluetooth: Audio: VOCS remove need for bt_conn pointer
Remove the bt_conn pointer from the VOCS API, as the
instance pointer is enough to determine if it is a client
and perform client operations on the cached connection pointer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-07 12:08:10 +02:00
Emil Gydesen
301cedbad5 Bluetooth: Audio: VOCS use bt_vocs instead of bt_vocs_server
Modify vocs.c to use the bt_vocs struct instead of the
bt_vocs_server struct. This is done so that there is less
difference between the internal struct usage and the struct
type used in the API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-07 12:08:10 +02:00
Kamil Piszczek
eff957b764 Bluetooth: HCI: add api for getting advertising handle
Added an API to the HCI header that can be used to retrieve
advertising handle information from a given advertising set.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2021-06-07 12:08:02 +02:00
Joakim Andersson
3aaf50ae6e Bluetooth: host: Remove unneccesary limit of host to controller packets
Remove unneccesary limit of host to controller packets by the host ISO
buffers and host pending buffers with TX callback.
The host always allocates the buffer before taking the semaphore so this
is already handled by the size of the host buffer pool and the
functionality of the buffer pools to wait for buffers.

In addition the ACL max limit is using the wrong define, as
CONFIG_BT_CONN_TX_MAX is the maximum amount of callback contexts for
transmitting. So the host can have more pending packets than this value.
This is also inconsistent with how the host would handle the V1 reply.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-07 12:06:48 +02:00
Emil Gydesen
20f0bff05f Bluetooth: Audio: MICS shell commands
Add the shell commands for both MICS server and client.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-07 12:04:28 +02:00
Emil Gydesen
2c67bafb7b Bluetooth: Audio: Microphone Input Control Service and Client
This commit implements the microphone input  control service
(MICS) and client, The implementation supports and uses the
Audio Input Control Service (AICS) secondary service.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-07 12:04:28 +02:00
Jordan Yates
43b2400688 Bluetooth: gatt: callbacks on ATT MTU update
Adds a new callback structure to `<gatt.h>` for receiving notifications
of ATT MTU updates. This callback is called regardless of whether the
MTU update was initiated locally or remotely.

Fixes #32035.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-06-07 12:03:09 +02:00
Vinayak Kariappa Chettimada
adae515d8d Bluetooth: controller: Fix conn setup regression
Fix incorrect and redundant use of ticker user id ULL_LOW
instead of ULL_HIGH when setting up a connection using a
mayfly to disable LLL context. Also, the LLL context pointer
is invalid, where node rx is passed instead of LLL context.

Use the ULL disabled callback when done event has not yet
been processed, or a direct connection setup in ULL_HIGH
context when ULL is already disabled (reference count is
zero) is sufficient.

Regression introduced in commit 30f260dfaa ("Bluetooth:
controller: Fix adv/scan context access post release").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-04 12:13:34 -05:00
Joakim Andersson
95e359d658 Bluetooth: controller: Check length field of scan response data
Check the length field of the scan response data.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-04 12:51:27 +02:00
Joakim Andersson
4dd49ac746 Bluetooth: host: Fix CCC store on write for multiple connections
Fix CCC store on write feature for multiple connections. CCCs are only
enqueued for storing when going from no connections subscribed to any
connection subscribed.
The CCC should be stored when its value is changed for the specific
connection.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-03 11:36:22 +02:00
Vinayak Kariappa Chettimada
12ba459c92 Bluetooth: controller: Minor improvements to ext header population
Minor refactor and improvement to common extended header
population.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-01 16:50:41 +02:00
Vinayak Kariappa Chettimada
0de4c30b0f Bluetooth: controller: Fix incorrect prev aux header flag access
Fix Extended Advertising PDU population from incorrectly
populating new PDU when there is no common extended header
flags being set in the previous PDU and or the new PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-01 16:50:41 +02:00
Vinayak Kariappa Chettimada
cabcae2413 Bluetooth: controller: Fix incorrect prev periodic header flag access
Fix Periodic Advertising PDU population from incorrectly
populating new PDU when there is no common extended header
flags being set in the previous PDU and or the new PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-01 16:50:41 +02:00
Vinayak Kariappa Chettimada
c877385adb Bluetooth: controller: Fix incorrect ext header flag access
Fix Periodic Advertising data population from corrupting
the PDU by populating fields when there is no flags in the
common extended advertising header.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-01 16:50:41 +02:00
Emil Gydesen
fe1de126fe Bluetooth: Host: Add status check BIG sync/create events
Add a status check for the BIG sync established and
BIG sync created events such that we don't log a warning
of invalid BIS count when it is an error event.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-01 07:31:51 -05:00
Emil Gydesen
4bc5a02d51 Bluetooth: ISO: Fix BIG cleanup
Fix a regression for cleaning up BIGs added by
80c824f18ee80caa5bd162b9d2957dde1639add6 where the way
ISO connections were unref'ed was changed.

bt_iso_cleanup has been changed to only effect CIS
(as the unref from that has been removed), so instead
of calling bt_iso_cleanup we just call
bt_conn_unref directly.

This also removes some unref's from the BIG complete
and BIG Sync complete event handlers as the BIS bt_conns as
they don't increase the ref counter before anymore.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-01 14:03:48 +02:00
Krzysztof Kopyściński
9c4dba12aa Bluetooth: Host: change error returned when ecred_conn_req
BT_L2CAP_LE_ERR_INVALID_PARAMS shall be returned instead of
BT_L2CAP_LE_ERR_UNACCEPT_PARAMS.

This was affecting test case L2CAP/ECFC/BV-26-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-06-01 14:03:28 +02:00
Krzysztof Kopyściński
975ed76d78 Bluetooth: Host: do not overwrite result in le_ecred_conn_req
For more than one requested channels in le_ecred_conn_req only result is
overwritten in every iteration. This causes an issues if after failed
l2cap_chan_accept occures successful one: returned result will be
BT_L2CAP_LE_SUCCESS, where in reality should be returned error
and non-zero Destination CIDs will signal "Some connections refused".
Now, overwrite error only if the last one failed. If no errors occur,
result will remain BT_L2CAP_LE_SUCCESS.

This was affecting test cases L2CAP/ECFC/BV-20-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-06-01 14:03:28 +02:00
Krzysztof Kopyściński
3e66dd2054 Bluetooth: Host: add missing zero CIDs in ecred_conn_req
Fix missing 0x0000 CIDs in response for ecred_conn_req. Previously,
when one of "All connections refused" error i variable was set to 0,
thus no CIDs were copied to response.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-06-01 14:03:28 +02:00
Piotr Pryga
1d0de7afc1 Bluetooth: host: Check sync_handle return value when CTE sampl enable
Check correctness of returned sync_handle value while requesting
HCI_LE_Set_Connectionless_IQ_Sampling_Enable in controller.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-31 17:44:29 +02:00
Piotr Pryga
725ceb69b3 Bluetooth: controller: hci: Set correct return params for CTE sampl enable
Fix bug of missing sync_handle parameter in return data in
HCI_LE_Set_Connectionless_IQ_Sampling_Enable commnad
handling function.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-31 17:44:29 +02:00
Joakim Andersson
b9a586821e Bluetooth: host: Log failure to initiatie security for bonded peer
Log failure to initiatet security for bonded peer when GATT wants to
initiate security for CCCs for the remote.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-31 17:40:36 +02:00
Joakim Andersson
8d53def576 Bluetooth: host: Reject remote public key on same X coordinate.
Reject remote public key when this has the same X coordinate.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-31 17:40:27 +02:00
Joakim Andersson
f5f8eb7263 Bluetooth: host: Notify application about prepare write error
Notify application about prepare write error when continueing the write
procedure fails when RX thread is processing responses. It is possible
that this operation fails, either because of disconnection or ATT
timeout on the ATT bearer. Notify the application in case it needs to
clear up resources, e.g. the write parameters.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-31 17:39:27 +02:00
Krzysztof Kopyściński
a527409011 Bluetooth: host:l2cap: fix sending error in le_ecred_reconf_req
Result to send was overwritten by BT_L2CAP_RECONF_SUCCESS just after
exiting while loop. This caused to send success response even if
reconfiguration failed. Now, result is initialized to success value,
and if reconfiguration fails, this value will be overwritten with
appropriate one. Added BT_L2CAP_RECONF_INVALID_CID (0x0003) for invalid
cid in request. Added BT_L2CAP_RECONF_OTHER_UNACCEPT (0x0004) to return
if MPS is to small. Reordered checks for mps/mtu as
BT_L2CAP_RECONF_OTHER_UNACCEPT is expected to be returned if both mps
and mtu are to small.

This was affecting L2CAP/ECFC/BI-05-C and L2CAP/ECFC/BI-05-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-05-28 10:50:42 -05:00
Luiz Augusto von Dentz
066a7c2de5 Bluetooth: conn: Align cleanup for ISO connections
This makes connections of type BT_CONN_TYPE_ISO use BT_CONN_CLEANUP to
cleanup so the TX and RX queues are properly cleanup.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Luiz Augusto von Dentz
2a99d80403 Bluetooth: shell: Add connection type information to connections command
This prints information about the role and id along with connection
parameters in case the connection is of LE type.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Luiz Augusto von Dentz
fc9b7e62f0 Bluetooth: conn: Add support for ISO connections to bt_conn_get_info
This enables bt_conn_get_info to be used with connection of type
BT_CONN_TYPE_ISO.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Luiz Augusto von Dentz
8b6d3c6c4d Bluetooth: ISO: Fix call order of connected callback
The state shall be set before calling the callback as it could be check
code behind would expect the channel to be in connected state.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Luiz Augusto von Dentz
76ad664d4e Bluetooth: ISO: Fix not assigning CIG and CIS IDs
When handling CIS Requested event CIG and CIS IDs must be set in order
for the channel to be properly accepted.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Luiz Augusto von Dentz
21404c4bd0 Bluetooth: ISO: Simplify reference handling
This makes bt_conn_cleanup to be automatically called when the last
reference to a connection of BT_CONN_TYPE_ISO is dropped.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Casper Bonde
3af1f4bac5 Bluetooth: ISO: Make it possible to setup unidirectional CIS
The current iso commands in the shell only supports setting up
a bidirectional stream or unidirectional for central role.
Adding rx/tx/rxtx option to iso listen command to allow for
peripheral side configuration of an iso connection.

Signed-off-by: Casper Bonde <casper_bonde@bose.com>
2021-05-27 13:16:40 +02:00
Casper Bonde
04dfcba792 Bluetooth: ISO: Add sequence number to ISO data packets
The sequence number is needed in the appliaction layer to detect lost
packets in the ISO stream in cases where the timestamp is not included.
(Sequence number is mandatory to include where timestamp is optional).
The API for the public metadata have been moved to a public header file.

As the size of the ISO meta data exceeds the default 4 octets net_buf
user_data the public ISO metadata have been moved into a seperate array.
The internal metadata is still stored in net_buf user_data.

This also fixed the user_data overflow on 32 bit systems, caused by
writing the ts into user_data on index 4 to 7, which is outside the 4
allocated bytes.

Signed-off-by: Casper Bonde <casper_bonde@bose.com>
2021-05-27 13:16:40 +02:00
Joakim Andersson
b6c95edc63 Bluetooth: host: Fix extended advertising feature bit check
Fix CONFIG_BT_EXT_ADV_LEGACY_SUPPORT option which optimizes the host
to skip checking the feature bit of the controller to check for
extended advertising commands.
This was broken because of how this was implented using an undef of the
feature bit, which was not replicated in scan.c, adv.c and id.c once
this was split out from hci_core.

Instead of doing this wierd way of redefining the feature check macro
do it in a proper way by defining a new macro.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-26 16:35:15 +02:00
Joakim Andersson
8a32c2d967 Bluetooth: host: Fix disconnect priority event handling
Fix issue is host handling of connected and disconnected event.
Since the host wants the disconnected event to be processed as a
priority event as well as in reguler event context while the connected
event is always in reguler event context we can end up in a situation
where the disconnected priority event is processed before the connected
event.

Since the disconnected priority event is there to release unack'ed TX
pending on the connection in case the RX thread is blocked waiting
for TX resources, we need to keep this behavior. Otherwise this would
be a potential deadlock of the RX thread waiting for resources that can
only be released by the RX thread.
When this situation happens we know that there cannot be any pending TX
on this connection so we can safely skip releasing of unack'ed TX.

The second thing the disconnected priority event does is marking the TX
path on the connection as disconnected. We need to do the same in this
situation, so we make sure that the TX path is already marked
disconnected when providing the connected callback to the application.

This fixes a regression from 4be66bd33d.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-25 20:30:48 +03:00
Joakim Andersson
c99b7ba71c Bluetooth: host: Fix L2CAP sent callback on disconnected channel
When receiving the L2CAP sent callbacks the dynamic L2CAP channel may
have been disconnected already. The user of the dynamic channel should
have received the disconnected and released callbacks for this channel
to release any resources for the data being sent, so simply ignoring
this sent callback is enough.

Fix sent callbacks by providing the CID to the callback instead of a
pointer to potentially released memory, and lookup the CID to check that
it is still valid.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-25 19:26:32 +02:00
Joakim Andersson
c429ffb0ed Bluetooth: host: Add check for already enabled in advertising set start
Add check for the advertising already being enabled when attempting to
start the advertising set.
Document that the advertising set cannot be started from the connection
connected callback, and instead has to be started from the advertising
set connected callback.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-25 19:26:23 +02:00
Joakim Andersson
3318bd3491 Bluetooth: host: Fix multiple advertisers with different ID support
Fix multiple advertisers with different ID support, this was added
in 98321c61fb but the guard was never
removed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-25 19:25:05 +02:00
Vinayak Kariappa Chettimada
79f6a63840 Bluetooth: controller: Fix initial empty flag for peripheral
Fix to avoid an assertion when processing an acknowledgment
in the first connection event in peripheral role.

Ensure that empty flag reflects the state of the Tx queue,
as a peripheral the first connection event has no prior PDU
transmitted, an incorrect acknowledgment by peer should
not dequeue a PDU that has not been transmitted on air.

Relates to assert added in commit 2bfaadffb8 ("Bluetooth:
controller: Add Tx fragmentation assertion").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-25 19:24:55 +02:00
Joakim Andersson
7986cae05c Bluetooth: host: Remove cancel sync from database hash commit
Fix deadlock when db_hash_commit has to wait for the delayed work to
finish. This creates a deadlock if the delayed work for database hash
calculation needs to store the hash since the settings API is locked
when calling the commit callback.
Remove call to k_work_cancel_delayable_sync from db_hash_commit in order
to avoid the deadlock. Instead move comparing of the stored hash to the
delayed work and reschedule the work with no wait.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-24 23:29:52 -04:00
Carles Cufi
0e26836c8a Bluetooth: controller: Add conn creation param checks
Coverity detected that a zero divisor can be passed to
ll_create_connection() without parameter sanitization. Conditionally
check the connection creation parameters according to spec.

Fixes #35343.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-05-21 18:50:22 +02:00
Krzysztof Kopyściński
58460f9273 Bluetooth: gatt: cancel all prepared writes on invalid write response
On sending write request we should check write response.
If data prepaired to be written by peer or offset are not equal
to the data and offset we sent, we shall send Execute Write
Request with Request Flag set to 0x00 (Cancel All Prepared Writes).

This was affecting GATT/CL/GAW/BI-32-C and GATT/CL/GAW/BI-37-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-05-21 18:50:26 +03:00
Erik Brockhoff
6ce0f2ee66 Bluetooth: controller: add apto/appto reset for peripheral
For peripheral the apto/appto_expire are now reset on adv start

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2021-05-21 15:17:20 +02:00
Vinayak Kariappa Chettimada
d999d5eb64 Bluetooth: controller: Fix missing HCI event data len limit check
Fix the missing HCI event data len limit check when encoding
incomplete advertising data report.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-21 13:39:22 +02:00
Andrzej Kaczmarek
9835888a91 Bluetooth: controller: Fix data length calculation in adv report
Max data length has to be adjusted for subevent code, otherwise we'll
hit an assert when trying to add data to event due to insufficient
free space.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-05-21 13:39:22 +02:00
Asger Munk Nielsen
38850b4820 Bluetooth: Controller: fix uninitialized variable
Fixes issue #35157
[Coverity CID: 221380]

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2021-05-20 21:27:40 -04:00
Vinayak Kariappa Chettimada
858dc7fab4 Bluetooth: controller: Fix EVENT_OVERHEAD_START_US jitter
As EVENT_OVERHEAD_START_US offset is used in ticks unit in
LLL, ULL scheduling using ticker should also use ticks unit
for EVENT_OVERHEAD_START_US when reducing the first
connection event preparation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-20 15:33:55 +02:00
Vinayak Kariappa Chettimada
8cfbaf5d55 Bluetooth: controller: Revert strict preempt ticker start failure check
Revert the strict preempt ticker start failure check.
Preempt ticker start can fail when enqueuing prepares into
already filled pipeline which has preempt ticker already
started for the first prepare that was added in the
pipeline.

Regression introduced in commit 5b75bdf589 ("Bluetooth:
controller: nRF5: Check preempt event on timeout").

Fixes #35476.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-20 15:33:32 +02:00
Emil Gydesen
01c4d597b3 Bluetooth: Host: Avoid memcpy'ing bt_addr_t to same pointer
From le_ext_adv_param_set we will occasionally attempt
to call bt_addr_copy where the `addr` and &adv->random_addr.a
are the same pointer. Doing a memcpy where source and destination
is the same pointer is undefined behavior and should not be
done.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-20 13:22:21 +02:00
Emil Gydesen
7d3def3275 Bluetooth: Audio: Fix VCS client shell missing compile
The VCS client shell was never compiled before, and thus
the implementation had a few undetected errors.

This commit adds the VCS client to the shell CMakelists
as well as fixing the issues.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-20 13:19:17 +02:00
Emil Gydesen
71c7566b96 Bluetooth: Audio: Move NULL check for conn in bt_vcs_discover
Move the check for the connection pointer before we get the
index.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-20 13:02:56 +02:00
Emil Gydesen
03a2c291c0 Bluetooth: Audio: Fix dead code issue in VCS
The common API functions in VCS had dead code in specific
configurations, causing coverity issues. Fixed by this
commit.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-20 12:00:57 +02:00
Vinayak Kariappa Chettimada
c0a8f38ec6 Bluetooth: controller: Avoid deferencing null return value
Add assert check to avoid deferencing null return value by
ull_adv_set_get() function.

Fixes #35347.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-19 17:10:08 -04:00
Vinayak Kariappa Chettimada
7d1a959d01 Bluetooth: controller: Explicitly ignore return value
Explicitly ignore return value from call to mayfly_enqueue.

Fixes #32917, #32961.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-19 17:10:08 -04:00
Vinayak Kariappa Chettimada
a92f7c6138 Bluetooth: controller: Fix side effect in assertion
Fix side effect in assertion when checking a volatile
variable inside assert check.

Fixes #32904, #32923.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-19 17:10:08 -04:00
Trond Einar Snekvik
85ad497c39 Bluetooth: Mesh: Don't reset PB ADV reliable timer on retransmit
The send_reliable function was reused in multiple places as part of the
k_delayed_work changes for Bluetooth Mesh in #33782. This function
contains a line that resets the start timer, causing prov_retransmit to
continously move the goal post for when to give up sending.

Extract this line out of the send_reliable function, and put it along
with the other link.tx initialization in bearer_ctl_send and
prov_send_adv.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-05-19 15:54:20 +03:00
Emil Gydesen
10011fd1de Bluetooth: Audio: Update VOCS conn check return value
Change the return value from -ENOTCONN to -EINVAL as that
is a more appropriate return value for checking a NULL
pointer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-19 07:53:10 -05:00
Emil Gydesen
a9efa14a95 Bluetooth: Audio: Update AICS client conn check return value
Change from -ENOTCONN to -EINVAL as that is a more appropriate
return value for checking a NULL pointer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-19 07:53:10 -05:00
Emil Gydesen
8470fe8cb3 Bluetooth: Audio: Update VCS Client conn check return value
Instead of return -ENOTCONN they will now return -EINVAL as
that is a more appropriate return value for checking if
the pointer is NULL.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-19 07:53:10 -05:00
Pavel Vasilyev
1b129c50c2 Bluetooth: Mesh: Remove outated RPL entry from persistent storage
This commit fixes a bug where outdated RPL entries might not be removed
properly from the persistent storage making those entries dead.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-05-18 12:29:53 -05:00
Freddie Yang
013008a3ef Bluetooth: Host: Disable BLE scan before setting random address
According to Bluetooth core specification v5.2, if Host set
random address when any of scanning (passive or active), the
Controller shall return the error code Command Disallowed (0x0C).

Signed-off-by: Freddie Yang <freddie.yang325@outlook.com>
2021-05-18 12:29:04 -05:00
Pavel Vasilyev
8717a0f678 Bluetooth: Mesh: Pass correct pointer to publish_sent
This commit fixes a bug where incorrect pointer passed to publish_sent
in access.c caused bus fault.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-05-18 11:05:46 +02:00
Trond Einar Snekvik
878043aff1 Bluetooth: Mesh: Change friend_cred decision point to friend selection
The network layer previously decided to use the friend credentials if
there was an established friendship. During the friendship setup phase,
the friendship is not considered established until the LPN receives the
first friend poll. Before this happens, the LPN should send a friend
poll message, encrypted with the friendship credentials. This wrongly
gets encrypted with the master credentials.

Change the decision point to whether the LPN has selected a friend,
which happens after the friend offer, and before the friend poll. This
will remain set for the duration of the friendship.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-05-17 13:36:24 +03:00
Pavel Vasilyev
22fabefdf2 Bluetooth: Mesh: Add VA flag to generic pending flags
This adds BT_MESH_SETTINGS_VA_PENDING to GENERIC_PENDING_BITS
as it should be stored by CONFIG_BT_MESH_STORE_TIMEOUT.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-05-17 13:23:30 +03:00
Pavel Vasilyev
3ae0f96acb Bluetooth: Mesh: Fix incorrect flag check in mesh settings
This bug was introduced in PR #31176, where setting's flags were
moved out from bt_mesh.flags to pending_flags.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-05-17 13:23:30 +03:00
Vinayak Kariappa Chettimada
7897eae2b4 Bluetooth: controller: Fix PPIs use for nRF52805 SoC
Fix regression in PPIs use for nRF52805 SoC, which has
fewer of them. And the regression was introduced in
commit e603b9d59e ("Bluetooth: controller: Adjust PPI
used for nRF51x and nRF52x").

Fixes #35204.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-13 22:05:41 -04:00
René Beckmann
41afd838aa Bluetooth: Crypto: Fix naming of params
The naming and documentation of the parameters was inconsistent with
their actual meaning and the implementation - enc_data and plaintext
were swapped.
Also, the parameter names in the file aes_ccm.c were completely
different from the ones in the header. Since all functions in the
header file are consistent in their parameter naming, I chose to make
the implementation follow the header and not the other way around.

Signed-off-by: René Beckmann <rene.beckmann@grandcentrix.net>
2021-05-12 12:37:27 +03:00
Vinayak Kariappa Chettimada
30f260dfaa Bluetooth: controller: Fix adv/scan context access post release
Fix advertiser and scanning context being accessed on done
event when connection complete node rx that is processed
earlier has release them.

Relates to #30735.
Fixes #35013.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-10 18:19:00 +02:00
Vinayak Kariappa Chettimada
32d9b68944 Bluetooth: controller: Implement LE Set Host Feature Command
Added implementation of HCI LE Set Host Feature command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-07 15:25:18 +02:00
Vinayak Kariappa Chettimada
ed59ceba62 Bluetooth: controller: Replace use if LL_FEAT with ll_feat_get()
Replace the use of LL_FEAT define with ll_feat_get() so that
feature set value can be updated at runtime with host
feature bit values.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-07 15:25:18 +02:00
Emil Gydesen
82a32f5ca5 Bluetooth: Audio: Volume Control Service and client
This commit implements the volume control service (VCS) and
client, The implementation supports and uses the
Audio Input Control Service (AICS) and
Volume Offset Control Service (VOCS) secondary services.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-07 15:02:41 +02:00
Vinayak Kariappa Chettimada
a9e900dbfd Bluetooth: controller: Fix scheduling stall in BT_CTLR_LOW_LAT feature
Fix radio event scheduling stall when using BT_CTLR_LOW_LAT
feature.

Performing a Connection Update Procedure on an ACL
connection while simultaneously having continuous scanning
causes the ACL connection to drop in nRF51 series which uses
BT_CTLR_LOW_LAT by default.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-07 15:02:13 +02:00
Asger Munk Nielsen
29006bd6fb Bluetooth: Controller: ISO adaptation layer
Improves error handling and makes ISO adaptation layer
independent of CIS.

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2021-05-07 13:14:31 +02:00
Vinayak Kariappa Chettimada
7eba8c403d Bluetooth: controller: Add Kconfig for maximum Broadcast ISO PDU length
Added Kconfig option to configure the maximum Broadcast and
Synchronized Receiver ISO PDU length.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-07 13:10:11 +02:00
Thomas Ebert Hansen
5f43fb3463 Bluetooth: controller: Make number of done events vendor configurable
The amount of needed done events changes when using the "must expire"
logic.

Make the amount vendor configurable (via ull_vendor.h)

Defaults to the original amount of 3.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2021-05-07 13:08:27 +02:00
Rubin Gerritsen
98321c61fb bluetooth: host: Allow concurrent advertising with multiple ids
The HCI specification creates additional complexity to allow this
configuration:
 - When a connection gets established, we need to know which
   identity the HCI_LE_Connection_Complete event corresponds to.
 - The identity is a property of the advertising set.
   Therefore we need the advertising handle.
 - The advertising handle is part of the
   HCI_LE_Advertising_Set_Terminated event and is not part of
   the HCI_LE_Connection_Complete event. Therefore
   the information of both events needs to be combined.

By spec the LE_Connection_Complete comes first. Therefore we cache
this event until the identity is available.
The event is only cached when a connection gets established as
that is the only case where we need to resolve the identity.

As the caching requires more resources, it is only enabled if the
application requires multiple advertising sets and multiple
identities.

The host maps the HCI_LE_Advertising_Set_Terminated event with
the HCI_LE_Connection_Complete event by comparing the connection
handles.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-05-07 12:15:20 +03:00
Morten Priess
b8aae321a1 Bluetooth: controller: ISO resume ticker in ULL
Added function ull_conn_iso_resume_ticker_start to enable LLL ISO
peripheral/central to start the one-shot resume ticker.
At timeout the common lll_resume handler is called, and based on the
LLL state, the peripheral/central is able to resume the CIG event.

The resume acts exactly like a normal event resume from the prepare
pipeline, with the exception that the LLL must provide specific
lll_event instances.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-05-06 13:23:00 -04:00
Vinayak Kariappa Chettimada
03a285b9d5 Bluetooth: controller: Add LE Read Buffer Size v2 support
Add LE Read Buffer Size v2 support in the controller
implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 13:22:02 -04:00
Vinayak Kariappa Chettimada
44e9163484 Bluetooth: controller: Add ISO Buffer size Kconfig dependency
Add BT_CTLR_ISO_TX_BUFFER_SIZE depends on Broadcast ISO
and/or Connected ISO feature being enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 13:22:02 -04:00
Vinayak Kariappa Chettimada
63a68e6ff4 Bluetooth: HCI: Rename LE Read Buffer Size v2 struct members
Rename LE Read Buffer Size v2 struct members to related to
Bluetooth Specification use Length and Number terminology.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 13:22:02 -04:00
Vinayak Kariappa Chettimada
8db6941b1a Bluetooth: controller: Minor conditional compile comment correction
Corrected a conditional compile comment and added some
newlines.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 13:22:02 -04:00
Vinayak Kariappa Chettimada
ffb3242e4b Bluetooth: controller: Accumulate latency on aborting event in pipeline
Only accumulate latency when event has not been prepared but
has been aborted while being enqueued in pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 19:13:31 +02:00
Pavel Vasilyev
a335c755a7 Bluetooth: Mesh: Add option to include bt name in scan rsp
Sometimes it may be needed to know device name when proxy feature is
enabled.

This commit adds an option to include device name in scan response.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-05-06 19:20:00 +03:00
Piotr Pryga
ce56f046e5 bluetooth: Fix cte_type value in periodic adv sync report
Periodic advertising sync report returned wrong cte_type value.
This commit fixes the problem.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
7cdbeb541a Bluetooth: controller: Use common mem_link_rx for node_rx_iq_report
Change use of dedicated memory pool for linked list nodes for
node_rx_iq_report to common mem_link_rx. Former solution had
a drawback. Released link nodes may be enqueued to wrong memory
pool. E.g. link related with nopde_rx_iq_report went to common
link memory pool, whereas link nodes from common pool were enqueued
to dedicated list.
The solution was working because links have the same memory layout,
just different memory pools they originated from.
The problem may occur if one of those link memory pools is reset.
Then the same link may be used by node_rx and node_rx_iq_report
at the same time, causing controller failure.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
938f04ffaa Bluetooth: controller: Fix build error for non Nordic plaforms
Direction finding is implemented only for Nordic link layer.
Build was failing due to missing header files for Openisa (RiskV).
Added dummy lll_df_types.h header file to OpenISA lower link layer.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
7c834bf19d Bluetooth: host: Add handl HCI_LE_Connectionless_IQ_Report
Add handling for HCI_LE_Connectionless_IQ_Report received
from controller.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
64c359bcef Bluetoot: host: Make get_per_adv_sync to be global function
The function get_per_adv_sync is used by HCI events to get
reference to periodic advertising sync object related with
handle available in handled events. Due to implementation
of Direction Finding event handlers in separate source file,
direction.c instead of putting in hci_core.c the function
get_per_adv_sync has to be globally accessible.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
6518621805 Bluetooth: host: Add CTE receive and sample enable API
Add functions that give possibility to enable or disable
CTE receive and sample in connectionless mode.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
b48fe0a7db Bluetooth: host: Add option to enable connectionless CTE RX
Add Kconfig option that will enable supprot for connectionless
CTE reception. Thanks to that it will be possible to conditionally
enable or disable support of the feature and decrease code size
if the feature is not required.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
ca87766bd7 Bluetooth: controller: df: Set BT_CTLR_DF_ANT_SWITCH_RX enable
Set BT_CTLR_DF_ANT_SWITCH_RX enabled by default.
There is already added implementation that supports
this feature in controller, so it may be enabled by
default.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
4009692fcf Bluetooth: controller: Add connectionless CTE RX feat. in supp. feat. list
Add connectionless CTE RX feature to list of features supported
by controller. Add direction finding initialization in hci_core
if the feature is enabled.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
f74a0b294c Bluetooth: controller: Dropp IQ sampl report if CTE disabled after evt end
Disable of CTE sampling for periodic advertising sync PDUs may be
interrupted by radio event. In such situation, TX thread will be
handled before RX thread delivers IQ samples report to host. In
this case RX thread would deliver IQ samples report after CTE
sampling was disabled.

To avoid such situation RX thread has to check if:
- CTE sampling is not disabled,
- CTE sampling was not requested to be disabled after start of radio
  event.

CTE sampling configuration is double buffered. Updated configuration is
swapped at the beginning of radio event.

If CTE sampling is diabled or requested to disable (next radio event
didn't start), the IQ samples report should be dropped by RX thread
and should not be delivered to host.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
6652b18d19 Bluetooth: controller: LLL: Add CTE report for per. adv. PDU with bad CRC
Add reporing of IQ samples collected for CTE attached to periodic
advertising PDUs with bad CRC.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
e884c02d92 Bluetooth: controller: Add opt. to enable CTE samplig for PDUs with bad CRC
Add Kconfig option that will enable possiblity to sample CTE attached to
PDUs that have bard CRC. Sampling is based on CTEInfo field available
in received PDU. If radio is able to parse the field correclty then
it will start sampling even the CRC is wrong.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
17d9df1c7a Bluetooth: controller: hci: Add connectionless IQ report event handler
Add handler for HCI_LE_Connection_IQ_Report event.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
582ca85e29 Bluetooth: controller: hci: Add connectionelss IQ samplig enable handler
Add handler for HCI_LE_Set_Connectionless_IQ_Sampling_Enable HCI
command.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
ff24092bdd Bluetooth: controller: ULL: Add function to enable or disable CTE sampling
Add function that enables or disables CTE sampling attached to received
periodic advertising PDUs.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
b7c1c4575d Bluetooth: controller: LLL: Add CTE sampling and reporting
ULL may request LLL to start receiving and sampling CTE attached to
end of periodic advertising PDUs. When the CTE is successfully sampled,
LLL should report collected samples to ULL.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
edfb85736e Bluetooth: controller: radio: Add function to get CTEInfo from Radio reg
Nordic Radio perihperal provides possiblity to get value of CTEInfo
field parsed from received PDU. It is faster to get the information
from Radio register than parse a PDU content.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
646303834c Bluetooth: controller: LLL: DF: Add function to enable CTE receive
Add function to enable CTE receive and sampling. The function
is aimed to be used by code in lll_sync.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
d182b7169a Bluetooth: controller: Add function to update per sync event slot duration
To enable or disable CTE sampling during periodic advertising sync evnet
it is requireq to change the event duration. To make it possible new
function was added that handles the operation.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
871359d934 Bluetooth: controller: ULL: Add init of DF sync configuration
lll_sync object is used to store information for LLL to enable
or disable CTE sampling. The commit adds initialization of
lll_df_sync member of lll_sync.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
37dd38c988 Bluetooth: controller: LLL: Add DF configuration to lll_sync structure.
To enable or disable CTE sampling in periodic advertising scanner LLL
implementation lll_sync is extended by lll_df_sync member.
The lll_df_sync is a double buffer for lll_df_sync_cfg.
It will be used by LL thread to enable or disable CTE sampling and
provide configuration for sampling CTE in AoA mode.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
2f4e014f14 Bluetooth: controller: ULL: Add node_rx_iq_report handling in ULL RX path
Add handling of Direction Finding node_rx_iq_report type in ULL.
This is required to correctly deliver IQ samples collected by
LLL during receive of PDU including CTE.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
ff94b9f676 Bluetooth: controller: Add double buffer for DF sync configuration
CTE sampling enable or disable requests should be provided to LLL.
Double buffer of lll_df_sync_cfg is added to lll_sync for that purpose
Thanks to that:
- there is no need to synchronize LLL with LL thread
- LLL has always access to valid configuration (new or former)

The configuration is stored in double buffer as instances
of lll_df_sync_cfg, not as pointers. This is the only
difference between double buffer pattern used to store adverising PDU.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
aa51f0a0dc Bluetooth: controller: Add DF per. adv. sync. configuration stucture
Add new structure lll_df_sync_cfg to store DF configuration
for periodic advertising synchronization.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
4d706bb6fb Bluetooth: controller: Add IQ report mem pool management
Add functions that will allow to mangage IQ reports memory pool
e.g. allocate or relase new IQ report nodes.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
bdaf4eed9a Bluetooth: controller: New node_rx type for IQ sample report
Add new kind of node_rx type that will store IQ samples report.
The structure includes node_rx_hdr and may be used by the same
queues that are used to forward regular node_rx_pdu objects
between LLL and ULL.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
68704c8cb1 Bluetooth: controller: Add Kconfig option to enable conn-less CTE sampling
Direction Finding support requires possibility to receive and sample CTE
attached to periodic advertising PDUs. New option will be used to enable
or disable the functionality. New option is introduced to avoid using
double statements checking if BT_CTLR_DF_CTE_RX and BT_CTLR_SYNC_-
-PERIODIC are enabled.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
2e1e8aff8d Bluetooth: controller: Add Kconfig option to enable debugging code in DF
To avid enabling HCI drived debugging, like in other controller source
files, Direction Finding has its own option BT_CTLR_DF_DEBUG_ENABLE.
This gives fine grained control deubgging output.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
2f7b0b7392 Bluetooth: controller: Disable not implemented DF features
Set to disabled not yet implemented Direction Finding features.
The features will be enabled by default when they are implemented.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Piotr Pryga
5779a2d7f2 Bluetooth: controller: radio: Add function to get PDU ant. switch pattern
IQ samples report requires information about antenna switch pattern
that was used to measure RSSI. RSSI is measured during PDU receive.
For Nordic Radio peripheral the PDU antenna is selected by first antenna
switch pattern set in SWITCHPATTERN register. That pattern is providded
by device tree. This information is already available in radio_df.c.
The information is required by LLL, that has access to functions
provided in radio_df.c. New function was provided to return PDU antenna
switch pattern.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-06 16:27:16 +02:00
Vinayak Kariappa Chettimada
737cab2614 Bluetooth: controller: openisa: Check preempt event on timeout
Check whether the preempt event matches with the head of the
pipeline before aborting the currently active event.

This is required to avoid preemption of events that became
active due to done event and there has been a race in
stopping the preempt ticker.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 15:39:16 +02:00
Vinayak Kariappa Chettimada
5b75bdf589 Bluetooth: controller: nRF5: Check preempt event on timeout
Check whether the preempt event matches with the head of the
pipeline before aborting the currently active event.

This is required to avoid preemption of events that became
active due to done event and there has been a race in
stopping the preempt ticker.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 15:39:16 +02:00
Vinayak Kariappa Chettimada
6916eb97ac Bluetooth: controller: openisa: Preempt timeout for next in pipeline
Start new preempt timeout for the next in pipeline when a
new event gets active.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 15:39:16 +02:00
Vinayak Kariappa Chettimada
8edc998332 Bluetooth: controller: nRF5: Preempt timeout for next in pipeline
Start new preempt timeout for the next in pipeline when a
new event gets active.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 15:39:16 +02:00
Vinayak Kariappa Chettimada
aeafc9ede5 Bluetooth: controller: openisa: Sync up LLL changes
Sync up with missing LLL changes done related to moving the
handling of pipeline handling into LLL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 15:39:16 +02:00
Joakim Andersson
396450b72b Bluetooth: shell: Update L2CAP chan send to reserve for an L2CAP SDU
Update the L2CAP channel send command to correctly reserve the number
of bytes needed for an L2CAP SDU.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-06 14:56:18 +02:00
Joakim Andersson
f0e6b400e4 Bluetooth: OTS: Update OTS to use correct reserve define
Update the L2CAP OTS implementation to use the correct reserve
defitition. By not using the correct definition the stack always
allocates a new segment for the packet, which puts more stress on the
stack buffers.
Update TX data size to be more intuitive by adding the overhead, instead
of subtracting it. This increases the default MTU of the implementation.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-06 14:56:18 +02:00
Joakim Andersson
11bfbf83ee Bluetooth: shell: Add argument to L2CAP send command for packet length
Add argument to the L2CAP channel send command so that the user can
determine the length of the packet to send, this is useful for testing
various segmentation scenarios.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-06 14:56:18 +02:00
Joakim Andersson
69613626ed Bluetooth: host: Document L2CAP channel send buffer sizes
Update the documentation for L2CAp Connection oriented channel send
function to include better description of the L2CAP PDUs (Basic frames)
and L2CAP SDUs (Credit-based frames) so that the application can better
understand how to size the buffer pools and setting the RX mtu.
Document stack behavior on RX path and how the application has to
set up the channel in order to receive segmented packets.
Document stack behavior on TX path for reserving either mandatory or
optional header bytes.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-06 14:56:18 +02:00
Joakim Andersson
6483e12a8a Bluetooth: Refactor bluetooth buffer configuration for simplification
Refactor and simplify the bluetooth buffer configurations to improve the
easy of configurations and eliminate invalid ones.
By moving configurations out of host and controller specific
configurations and into a common one it becomes easier to configure
the host and controller separately as the same configurations can be
used as would be for a combined build.

All HCI configurations are now given exluding the matching HCI header,
which eases the configuration as the application don't have to know the
different header sizes.
The BT_RX_BUF_LEN is split into ACL and Event, as well as the suprising
use of Command size.
BT_L2CAP_RX_MTU is removed as the stack does not support reassembling of
HCI ACL data to larger L2CAP PDUs. The application will have to set
ACL RX size and account for the L2CAP PDU header itself.
BT_EATT_RX_MTU was removed as it is only used for setting a different
default value for another option which leads to the stuck kconfig symbol
problem.

The configurations can be updated according to the table below:

** New configuration         | ** Old configuration
All configurations
BT_BUF_ACL_RX_SIZE           | BT_L2CAP_RX_MTU + 4
BT_BUF_ACL_RX_SIZE           | BT_RX_BUF_LEN - 4
BT_BUF_EVT_RX_SIZE           | BT_RX_BUF_LEN - 2
BT_BUF_CMD_TX_SIZE           | BT_RX_BUF_LEN - 3
BT_BUF_CMD_TX_COUNT          | BT_HCI_CMD_COUNT
BT_BUF_EVT_RX_COUNT          | BT_RX_BUF_COUNT
BT_BUF_ACL_RX_COUNT          | BT_RX_BUF_COUNT
BT_BUF_ACL_RX_COUNT          | BT_ACL_RX_COUNT
BT_BUF_EVT_DISCARDABLE_SIZE  | BT_DISCARDABLE_BUF_SIZE - 2
BT_BUF_EVT_DISCARDABLE_COUNT | BT_DISCARDABLE_BUF_COUNT
Controller-build
BT_BUF_ACL_TX_SIZE           | BT_CTLR_TX_BUFFERS_SIZE
BT_BUF_ACL_TX_COUNT          | BT_CTLR_TX_BUFFER
HCI-bridge
BT_BUF_ACL_TX_SIZE           | BT_HCI_ACL_DATA_SIZE
BT_BUF_ACL_TX_COUNT          | 6

Fixed invalid configurations setting either BT_L2CAP_RX_MTU or
BT_CTLR_DATA_LENGTH_MAX larger than BT_RX_BUF_LEN could lead to buffer
overruns.

Fix advertising report max data length calculation.
This always used the BT_DISCARDABLE_BUF_SIZE macro but this feature
can be turned off and advertising reports will be allocated from the RX
buffer in that case. Also controller-build does not have this buffer
(in hci_raw.c). Also the wrong HCI header was used in the calculation,
HCI event header should have been used instead of HCI ACL header.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-06 14:56:18 +02:00
Joakim Andersson
7b7b17a495 Bluetooth: Mesh: Set L2CAP TX MTU default to fit public key packet
Set the L2CAP TX MTU default to fit the public key packet in a single
L2CAP fragment. This matches the configuration for RX buffer lengths
being set with this configuration.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-06 14:56:18 +02:00
Joakim Andersson
a8d9373b94 Bluetooth: Kconfig: Remove discardable dependency on implementations
Remove discardable buffer dependency on the specific implementations
except for HCI raw.
All of the in-tree Host-side HCI drivers have implemented discardable
buffer behavior.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-06 14:56:18 +02:00
Joakim Andersson
eba6350a12 Bluetooth: host: Add macros for calculating buffer sizes
Add macros for calculating buffer sizes, accounting for the various
L2CAP and HCI headers needed as well as the reserved bytes needed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-06 14:56:18 +02:00
Vinayak Kariappa Chettimada
d54d75b6fd Bluetooth: controller: nRF5: Add radio ready time save and restore
Added radio interface to save and restore radio ready
timestamp. This will be saved between ISO Subevents and
used in done event for anchor point synchronization and
drift compensation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-06 12:18:10 +02:00
Joakim Andersson
cc401820f3 Bluetooth: shell: Update L2CAP to use new delayable work API
Update shell L2CAP to use the new delayable work API for the delayed
received confirmation response.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Joakim Andersson
92d80d50b9 Bluetooth: host: Update GATT to use new delayable work API
Update GATT to use the new delayable work API for the delayed
calculation of the database hash and the service changed indication.

When the database hash characteristic is read the hash work needs to be
canceled if in progress and if currently executing wait for it to
complete so that the threads don't both write to the stored value.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Joakim Andersson
8fcb4318f7 Bluetooth: host: Update connections to use new delayable work API
Update the connections to use the new delayable work API for the
deferred work host timer.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Joakim Andersson
a14b9145e4 Bluetooth: host: Update AVDTP to use new delayable work API
Update AVDTP to use the new delayable work API for the send host timer.
The AVDTP protocol is incomplete, there is no cancelation of the timer
but it is also never started, as there is no users of the internal
functions, and no public functions exists.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Joakim Andersson
9c62841b58 Bluetooth: controller: Update privacy to use new delayable work API
Update the implementation of controller based privacy to use the new
delayable work API for the RPA timer. Always use schedule for the
timer since RPAs should not be used more than the configured RPA
timeout.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Joakim Andersson
b9ea5d9910 Bluetooth: host: Update RFCOMM to new delayable work API
Update RFCOMM to use the new delayable work API for the RTX host timer
used for disconnecting and idling.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Joakim Andersson
83dc781702 Bluetooth: host: Update ATT to use the new delayable work API
Update ATT to use the new delayable work API for the transaction
host timer.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Joakim Andersson
8e85259e7b Bluetooth: host: Update SMP to use new delayable work API
Update SMP to use the new delayable work API for the pairing procedure
host timer.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Joakim Andersson
afc29f3a1c Bluetooth: host: Update L2CAP to use the new delayable work API
Update L2CAP to use the new delayable work API for the signaling
RTX host timer.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Joakim Andersson
7a7afa570b Bluetooth: host: refactor SMP channel context layout
Refactor the SMP channel context to in order to simplify the memset of
the struct in smp_init. This makes the code easier to read, and easier
to add more structs that should not be reset by memset.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Joakim Andersson
52a21a9478 Bluetooth: host: Update RPA timer to new delayable work API
Update the RPA timer to the new delayable work API.
Checking for submitted RPA timer no longer needed with the schedule
function, which does not change the deadline.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Vinayak Kariappa Chettimada
167e83df49 Bluetooth: controller: Move le_adv_ext_terminate under broadcaster
Move le_adv_ext_terminate under broadcaster conditional
compilation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 17:05:52 +02:00
Marek Metelski
1a927b5fbf Bluetooth: shell: Fix implicit gatt client requirement for bt shell
`write_stats` functionality implementation is guarded by
`BT_GATT_CLIENT`, but is also called from commands defined when
`BT_GATT_DYNAMIC_DB` is set. This means that now application will not
build with `BT_SHELL` used, when we set `BT_GATT_DYNAMIC_CB` solely.

Move this functionality to top of the file without guarding
ifdefs, so it can be used in all gatt shell commands.

Signed-off-by: Marek Metelski <marek.metelski01@gmail.com>
2021-05-05 16:03:51 +02:00
Magdalena Kasenberg
d0e0af74da Bluetooth: Add option to log btsnoops over RTT
There is a choice to log btmon logs over UART or RTT.
You can choose number of RTT buffer, set its name and size.

Replaced CONFIG_BT_DEBUG_MONITOR with CONFIG_BT_DEBUG_MONITOR_UART
for UART usage and CONFIG_BT_DEBUG_MONITOR_RTT for RTT.

Signed-off-by: Magdalena Kasenberg <magdalena.kasenberg@codecoup.pl>
2021-05-05 16:03:38 +02:00
Vinayak Kariappa Chettimada
08a679dc4c Bluetooth: controller: Add Broadcast ISO related timing macros
Added Broadcast ISO related timing macros, like T_MSS
Minimum Subevent Space.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:41:40 -04:00
Vinayak Kariappa Chettimada
03c191c281 Bluetooth: controller: Add function to calculate BIS access address
Added a function to calculate the BIS SubEvent access
addresses.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:41:09 -04:00
Vinayak Kariappa Chettimada
3469171041 Bluetooth: controller: Add function to calculate seed access address
Added utility function to calculate seed access address.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:41:09 -04:00
Vinayak Kariappa Chettimada
544acb9804 Bluetooth: controller: Fix missing EVENT_TICKER_RES_MARGIN_US
Fix missing use of EVENT_TICKER_RES_MARGIN_US in Periodic
Synchronization.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:40:44 -04:00
Vinayak Kariappa Chettimada
0da63124d2 Bluetooth: controller: Add ticker allocation for BIG events
Add ticker node allocations for BIG radio event scheduling.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:40:28 -04:00
Vinayak Kariappa Chettimada
12f04da828 Bluetooth: controller: Minor rename in BIS PDU data members
Renamed offset and offset_units to offs and offs_unit to be
consistent with rest of the other structures.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:40:06 -04:00
Vinayak Kariappa Chettimada
eb5874ca7b Bluetooth: controller: Fix ULL reference decrement on done event
Fix ULL reference count decrement to be performed before the
done events are handled, so that correct reference count is
used to determine if events are pending in the pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:39:41 -04:00
Vinayak Kariappa Chettimada
b0bba245ea Bluetooth: controller: HCI: Allow processing a list of events
Update HCI driver implementation in the controller to
process a list of controller events by traversing net buf
frags.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:39:25 -04:00
Vinayak Kariappa Chettimada
323b8efe75 Bluetooth: controller: Reorder feature bits
Reorder Channel Selection Algorithm #2 and Minimum Number of
Used Channels Procedure bits.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:38:56 -04:00
Vinayak Kariappa Chettimada
4eca1a821c Bluetooth: controller: Add ticker allocation for BIG Sync events
Add ticker node allocations for BIG Sync radio event
scheduling.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:36:43 -04:00
Vinayak Kariappa Chettimada
415e068e16 Bluetooth: controller: Conditional compile ISO Tx functions
Conditional compile ISO Tx related declarations and
implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 08:36:27 -04:00
Vinayak Kariappa Chettimada
a4d2e062cb Bluetooth: controller: Fix regression in central initiated terminate
Fix regression in central initiated terminate introduced in
commit 3a80785947 ("Bluetooth: controller: Fix connection
terminate to happen on event done").

The regression caused an additional central connection event
transmitting PDU  after the previous connection event had
received acknowledgment for the terminate_ind PDU from the
peripheral.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 14:21:05 +02:00
Andrzej Kaczmarek
b8dfecfdc5 Bluetooth: conn: Fix invalid ref on conn object
We should unref conn object if skipped during lookup.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-05-05 14:20:05 +02:00
Emil Gydesen
3e6ea470a1 Bluetooth: ISO: Additional text for setting unidir values for the CIG
Add additional text to explain why we use the TX values if RX is
disabled and vice versa.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-05 14:19:38 +02:00
Vinayak Kariappa Chettimada
e5ffc18507 Bluetooth: controller: Do not report Aux PDUs while initiating
Do not report auxiliary PDUs as advertising reports when in
initiator state on auxiliary channels.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 14:15:05 +02:00
Vinayak Kariappa Chettimada
472169befa Bluetooth: controller: Ensure both 1M and Coded PHY can initiate
Ensure that the advertiser address type and address is setup
in both 1M and Coded PHY scanning instance when extended
create connection is enabled on both the PHYs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 14:15:05 +02:00
Vinayak Kariappa Chettimada
a6b8eba7c5 Bluetooth: controller: Implement disabling the other PHY initiator
When connection is initiated in one of either 1M or Coded
PHY initiating scan instance then the other scanning
instance's scheduling and memory allocation needs to be
cleaned up.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 14:15:05 +02:00
Vinayak Kariappa Chettimada
9eb5f85870 Bluetooth: controller: Reserve an additional node rx for Ext. Initiator
Reserve an additional node rx buffer when Extended Initiator
is supported as the received ADV_EXT_IND PDU is being
buffered in the auxiliary channel scanning instance and is
only released/flushed in the done event of the initiating
auxiliary channel radio event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 14:15:05 +02:00
Vinayak Kariappa Chettimada
236755198b Bluetooth: controller: Rename use of params to param
Rename the use of params word with param.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 14:15:05 +02:00
Vinayak Kariappa Chettimada
6f2d4a4458 Bluetooth: controller: Fixes and use of defines related to initiator
Fixed incorrect LLL context used to generate done event for
auxiliary channel scanning. Other minor comments and fixes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 14:15:05 +02:00
Vinayak Kariappa Chettimada
031aa8c340 Bluetooth: controller: Ensure only initiating on selected PHY
Reset the scanning context for the PHY not selected in the
Extended Create Connection command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-05 14:15:05 +02:00
Andrzej Kaczmarek
0b04dd7221 Bluetooth: controller: Add support for initiator on secondary adv ch
This allows to initiate a connection on secondary advertising channels,
i.e. when advertises uses advertising extensions.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-05-05 14:15:05 +02:00
Andrzej Kaczmarek
c47396abd9 Bluetooth: controller: Fix aux scanning for connectable ADV_EXT_IND
When in initiating state we need to handle ADV_EXT_IND as in regular
scan sice we always want to scan AUX_ADV_IND in order to be able to
connect.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-05-05 14:15:05 +02:00
Andrzej Kaczmarek
37b79ff229 Bluetooth: controller: Fix 1st connection event offset
We need to take RX chain delay and PHY used to send CONNECT_IND into
account when calculating 1st connection event offset.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-05-05 14:15:05 +02:00
Andrzej Kaczmarek
2ab25f67fe Bluetooth: controller: Use proper transmitWindowDelay for central
On secondary advertising channel transmitWindowDelay depends on PHY
used to create connection so we need to adjust it.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-05-05 14:15:05 +02:00
Andrzej Kaczmarek
e58800267f Bluetooth: controller: Add public helpers for scan checks
We will need the same checks for AdvA and TargetA/InitA in lll_scan_aux
so let's make them public and use address explicitly instead of passed
via pdu.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-05-05 14:15:05 +02:00
Andrzej Kaczmarek
95b693965e Bluetooth: controller: Refactor CONNECT_IND prepare to separate func
We can use the same code to create both CONNECT_IND and AUX_CONNECT_REQ
since they are basically that same PDUs.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-05-05 14:15:05 +02:00
Emil Gydesen
556baa2fd2 Bluetooth: Shell: ISO: Broadcast use correct bis_tx_pool
When broadcasting with ISO it would wrongly use the tx_pool
defined for CIS, instead of the broadcast TX pool.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-04 10:20:12 -05:00
Joakim Andersson
80e5295dca Bluetooth: host: Fix buffer leak trying to send when disconnected
Fix buffer leak in L2CAP and SMP when attempting to send over a
a connection that has been disconnected.
Both L2CAP and SMP now have ownership of the buffer in case of failure
to send it and need to unref it in case of send failure.

Change the return type of bt_l2cap_send since the user of this function
has to handle releasing of the buffer when this fails.

Regression from: a77f809faa47ff9922692d2b4eab33062b8a2b4d

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-03 16:45:53 +02:00
Joakim Andersson
ae4662f037 Bluetooth: host: Remove comment providing false information
Remove the comment about bt_l2cap_send_cb not being able to fail when
called from RX thread. It will fail in the case where the connection
has been disconnected.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-03 16:45:53 +02:00
Emil Gydesen
87df76c7f7 Bluetooth: ISO: Improved text for setting ISO data paths
Improved the documentation for the ISO data paths, as well
as making the bt_iso_setup_data_path function a bit more
clear.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-03 11:59:25 +02:00
Emil Gydesen
735009e9f8 Bluetooth: ISO: Only remove a single data path for broadcasters
Since we are only setting up a single data path for
broadcasters (either receive or transmit), we should
only remove that same path.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-03 11:59:25 +02:00
Emil Gydesen
b2281cce78 Bluetooth: shell: Mark BIGinfo reports more clearly in the shell
The BIGinfo reports were almost identical to the
periodic advertising reports when printet. Updated to
mark the start of the line with BIGinfo.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-03 11:59:25 +02:00
Emil Gydesen
1c466d4d92 Bluetooth: ISO: Fix issue with setting iso data path for BISs
When setting the iso data path for a BIS, it shall only be set for
one direction (depending on whether we are a broadcaster or
a receiver).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-03 11:59:25 +02:00
Sylvio Alves
a3c35c93ff driver: esp32: add bluetooth support
Add support to BLE and BR/EDR feature.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2021-04-30 16:51:30 -04:00
Piotr Pryga
c5f8d0adb7 Bluetooth: controller: radio: Add API to configure CTE Rx
Add Radio configuration API that gives possiblity configure
reception and sampling of CTE.
Part of alrady implemented API was re-factored to comply
with new API and do complete initialization of registers:
DFECTRL1 and CTEINLINECONF.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-04-30 11:07:55 +02:00
Michał Narajowski
b9c8d270ab Bluetooth: Mesh: Allow to be NODE when PROVISIONER is enabled
When PROVISIONER and CDB is enabled then IUT couldn't be a NODE.
This patch fixes this by not returning an error when CDB is not
configured. This is useful especially in testing environment, when all
the features are compiled in and we can choose role in runtime.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-04-29 09:52:35 -04:00
Emil Gydesen
cc35750603 Bluetooth: ISO: Add missing handling of interval and latency of unidir
Adds missing handling of the m_interval and m_latency if tx QOS is
not set, and handling of the s_interval and s_latency if rx QOS is
not set.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-28 14:34:48 -04:00
Peter Bigot
4e6cb116f8 Bluetooth: Mesh: transport: update delayable work
Switch to the new API. Adds early exits for the ack and retransmit
timers, and replaces a remaining_time() + submit() call with schedule().

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-28 11:48:59 +03:00
Peter Bigot
1577fec851 Bluetooth: Mesh: proxy: update delayable work
Switch to the new API. Adds check for a pending buffer in the SAR
timeout handler.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-28 11:48:59 +03:00
Peter Bigot
3cba9613a4 Bluetooth: Mesh: pb_gatt: update delayable work
Switch to the new API. Adds a link check to the protocol timeout to
ensure the link is still active.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-28 11:48:59 +03:00
Peter Bigot
45e5914ce9 Bluetooth: Mesh: pb_adv: update delayable work
Switch to the new API. Consolidates reliable sending logic for the first
transmission and the retransmit into one. Adds check for link active in
protocol timeout.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-28 11:48:59 +03:00
Peter Bigot
f415ae7859 Bluetooth: Mesh: adv_ext: update delayable work
Switch to the new API in Mesh's extended advertising handler.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-28 11:48:59 +03:00
Peter Bigot
38609d34e0 Bluetooth: Mesh: Core delayable work updates
Switch to the new API in friend, net and main.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-28 11:48:59 +03:00
Trond Einar Snekvik
0f5b5f74ac Bluetooth: Mesh: Add friend_is_allocated utility
Friend structure allocaction logic is implemented over and over
throughout the friend module. Move it into a static utility function for
readability.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-28 11:48:59 +03:00
Emil Gydesen
676a91636b Bluetooth: Audio: VOCS add error checks on read
The error check was removed earlier as it was assumed that
we would either get an error, or the data would be valid.
However, without an error check, we are not guarded
against bad reads.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-27 13:31:06 -04:00
Emil Gydesen
449ceca2fe Bluetooth: Audio: Remove VOCS desc data check as it can be empty
If the output description of the server is empty (legal by the
spec), then we should not return an error to the application
when read. Also added some debug statements when the value is
truncated.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-27 13:31:06 -04:00
Emil Gydesen
d005a62451 Bluetooth: Audio: Fix issues with setting VOCS offset state
Fixes 2 issues:
1) The write callback always returned an error
2) The auto-read of the offset state did not, unlike what the
comment suggested, retry only once and fail on the second attempt,
but rather keep retrying.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-27 13:31:06 -04:00
Emil Gydesen
abb97f57dd Bluetooth: GATT: Extend GATT notify/indicate security check with auth
Add authentication check to the security checks for
GATT notify and indicate.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-27 13:30:44 -04:00
Emil Gydesen
2f4ee7dcb6 Bluetooth: GATT: Verify security when notifiying or indicating
Adds a security checks when notifying or indicating, such
that we don't send notifications for characteristics that
require encryption on an unencrypted link.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-27 13:30:44 -04:00
Emil Gydesen
910e0c63f4 Bluetooth: Audio: VOCS: Move callback structure to register function
Moves the callback structure for VOCS to the register function
which is renamed from init, as there's no reason to register
the callbacks separately.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-26 13:42:50 +02:00
Wolfgang Puffitsch
feb9943e84 Bluetooth: controller: Fix overflow with preferred periodicity
Avoid possibly overflowing maximum interval when calculating interval
with preferred periodicity.

Changed calculation to round down from maximum interval and reset to
maximum in case of underflowing minimum interval.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-04-26 13:38:34 +02:00
Kai Ren
92c5afe2be Bluetooth: shell: Fix null check in conn and data length update
Perform null check of default_conn in call cmd_conn_update()
and cmd_conn_data_len_update() in ./subsys/bluetooth/shell/bt.c

Signed-off-by: Kai Ren <renkaikaiser@163.com>
2021-04-26 13:05:55 +03:00
Emil Gydesen
2bada95482 Bluetooth: Host: Adds periodic advertising min/max interval macros
Add the BT_GAP_PER_ADV_MIN_INTERVAL and BT_GAP_PER_ADV_MAX_INTERVAL
macros in gap.h that are also reference in bluetooth.h and
used for parameter validation in adv.c.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-23 15:01:32 +02:00
Asger Munk Nielsen
19650299fb Bluetooth: controller: Moved sdu_interval field members
Moved sdu_interval struct members from llcp_cis to cis group,
to match spec and enable access by ULL

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2021-04-23 15:00:45 +02:00
Trond Einar Snekvik
3656f7f609 Bluetooth: Mesh: Provisioning output count number should be at least 1
When selecting a random count for blink, beep or vibrate, the Bluetooth
Mesh Profile Specification v1.0.1, section 5.4.2.4 states: "the device
shall select a random integer between 0 and 10 to the power of the
Authentication Size exclusive".

This means that if size is 1, the integer should be in the range 1-9,
while the implementation chose an integer in the range 0-9. Reduce the
range and add 1 to the num to correct this for these actions.

Fixes #34209.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-23 14:58:56 +02:00
Joakim Andersson
d1469ecf26 Bluetooth: host: Fix undefined reference to bt_le_adv_lookup_legacy
Fix undefined referenc to bt_le_adv_lookup_legacy in bt_le_oob_get_local
when bt_le_oob_get_local is used in a central only application.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-04-23 15:30:40 +03:00
Vinayak Kariappa Chettimada
a379196b48 Bluetooth: controller: nRF5: Back-to-Back Radio Tx interface
Add Radio interface to perform back-to-back transmit of PDU
with a configurable inter frame spacing.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-22 16:00:10 +02:00
Vinayak Kariappa Chettimada
377d168c51 Bluetooth: controller: nRF53 sw_switch always required Radio End
nRF53 implementation of sw_switch always requires Radio End
event, hence optimize out redundant code due to explicit use
of radio_tmr_end_capture.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-22 16:00:10 +02:00
Vinayak Kariappa Chettimada
0426b1dd68 Bluetooth: controller: Minor indentation and HAL code change
Minor indentation change and replaced if-then-else-if clause
with toggle implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-22 16:00:10 +02:00
Vinayak Kariappa Chettimada
72504c8a58 Bluetooth: controller: Enclose macro parameters in paranthesis
Enclose macro parameters in paranthesis to avoid ambiguous
macro expansions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-22 16:00:10 +02:00
Emil Gydesen
cfe0849072 Bluetooth: services: Adds OTS name length checks
Adds name length checks. The OTS spec does not
explicitely specifiy a maximum name length, but the
maximum name length in the directory listing object
shall be less or equal to 120 octets.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-22 11:32:25 +02:00
Emil Gydesen
5a90fcee3a Bluetooth: services: Adds additonal len checks for ots_dir_list
Adds additional length checks for the OTS directory listing
implementation. This will check the object name length and
the total length of the object when encoding,
as well as the length of the objects when removing objects
from the directory listing.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-22 11:32:25 +02:00
Emil Gydesen
59f3e2c502 Bluetooth: host: Fix typo in PA defines and missing min check
Fixes a typo where the BT_GAP_PER_ADV macros had MAX twice,
as well as adding a MIN timeout macro and check.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-21 20:41:17 -04:00
Joakim Andersson
15dfec4df6 Bluetooth: host: Fix ECC thread stack size too small
Fix ECC thread stack size which is to small to account for the worst
case scenario. When an interrupt happens at the point where the ECC
thread is at the highest stack size usage pushing the thread context
to service the ISR causes a stack overflow.

Increase the ECC thread stack size by atleast the size of the basic
stack frame of 32 bytes aligned on 8 byte for ARM architectures.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-04-21 16:57:14 +03:00
Bjørn Spockeli
9c871fb0b6 Bluetooth: controller: nRF21540 FEM support for nRF52x Series
Added nRF21540 FEM support for nRF52x Series.

Signed-off-by: Bjørn Spockeli <bjorn.spockeli@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-21 15:04:12 +02:00
Bjørn Spockeli
9930e22322 Bluetooth: controller: Add GPIO control for nRF21540 CSN and PDN lines
Added GPIO control for nRF21540 CSN and PDN lines.

Signed-off-by: Bjørn Spockeli <bjorn.spockeli@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-21 15:04:12 +02:00
Bjørn Spockeli
568113c0a9 Bluetooth: controller: Add Kconfig options for nRF21540 PDN and CSN pins
Added Kconfig options for nRF21540 PDN and CSN pins.

Signed-off-by: Bjørn Spockeli <bjorn.spockeli@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-21 15:04:12 +02:00
Bjørn Spockeli
207b393fff Bluetooth: controller: Add PA/LNA pin range for nRF5340 SoC
Added correct SOC_NRF5340_CPUNET pin range for
BT_CTLR_GPIO_PA_PIN and BT_CTLR_GPIO_LNA_PIN.

Signed-off-by: Bjørn Spockeli <bjorn.spockeli@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-21 15:04:12 +02:00
Vinayak Kariappa Chettimada
35122d4be5 Bluetooth: controller: GPIO PA/LNA support for nRF53x
Ported the GPIO PA/LNA support for nRF53x by using a DPPI
channel.

Fixes #24142.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-21 15:04:12 +02:00
Vinayak Kariappa Chettimada
0772890992 Bluetooth: controller: Adjust DPPI used for nRF53x
Adjust the PPI used by nRF53x so that DPPI 0-4 available
for application's use.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-21 15:04:12 +02:00
Kai Ren
de16299c62 Bluetooth: shell: Fix null check in cmd_conn_phy_update
Null check in case of system failure.

Signed-off-by: Kai Ren <renkaikaiser@163.com>
2021-04-21 01:21:05 +03:00
Luiz Augusto von Dentz
33d95894e1 Bluetooth: Align error handling of send functions
This aligns the error handling of send function to never unref the
buffer in place so the caller retain the ownership of the buffer
whenever there is an error.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-04-20 18:20:04 -04:00
Jamie McCrae
840d1d9381 bluetooth: Add flag to force device name to appear in AD data
This adds a new flag, BT_LE_ADV_OPT_FORCE_NAME_IN_AD, which can be used
to force the Bluetooth GAP device name to appear in the advertising
data rather than the scan response data of an advert with scan response
data.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2021-04-20 18:19:30 -04:00
Krzysztof Chruscinski
b3c5496159 bluetooth: Add cast to forward declared struct
Logging v2 is using _Generic keyword for detecting type of
log message arguments. Apparently, it does not support handling
of pointers to forward declared structures. Added casting to void *.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-19 10:59:23 -04:00
Vinayak Kariappa Chettimada
41e9493ae1 Bluetooth: controller: Fix missing encryption procedure state check
Fix a missing encryption procedure state check which allowed
out of order receive of START_ENC_RSP PDU, which made the
controller to believe its already in an encryption procedure
in progress state.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-19 10:59:01 -04:00
Asbjørn Sæbø
22068d4967 Bluetooth: services: Do not set current object until selected
Do not make the first object added to the object transfer server the
current (=selected object).  This leads to the server having no
current object until one is selected by the client.

This solves a startup issue where the selected callback is not called
by the server if the first object selected by the client happens to be
the same object as the object that was first added to the server.  In
that case, the user of the OTS does not know which object is selected,
and therefore may not be able to supply the correct data later.

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
2021-04-19 16:18:16 +02:00
Vinayak Kariappa Chettimada
82925a8c99 Bluetooth: controller: Avoid sizeof to access ULL/LLL struct member
Avoid using sizeof to access ULL and LLL struct members.
Based on the alignment requirements of structures, due to
padding between structure members, use of sizeof of previous
struct member to access next struct member is incorrect.

Continue to use explicitly stored parent pointer to access
ULL context. Combine event header and ULL header so that
the parent pointer point directly to the combined ULL
struct.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-19 10:26:38 +02:00
Vinayak Kariappa Chettimada
e395c6ce2c Bluetooth: controller: Fix uninitialized ULL reference count
Fix missing initialization of reference count in
ull_hdr_init function.

This has not caused issues so far, but when the ref member
of the struct ull_hdr if placed in the beginning of a
context that is allocated using mem_acquire function then
first few bytes used would make the ref member to have
uninitialized value when such context is allocated by
mem_acquire. First few bytes are the next pointer and free
count stored by the mem module.

The issue was discovered in subsequent commits that
restructure the ULL context structures.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-19 10:26:38 +02:00
Vinayak Kariappa Chettimada
624e003064 Bluetooth: controller: Fix auxiliary scan context release
Fix the auxiliary scan context release to be performed in
the disabled_cb callback after the ULL reference count is
decremented.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-19 10:26:38 +02:00
Vinayak Kariappa Chettimada
3a80785947 Bluetooth: controller: Fix connection terminate to happen on event done
Fix conn_cleanup to be performed in the event done. The
regression was introduced in
commit 5412f61ac6 ("Bluetooth: controller: Introduce
separate done memq").

Now that done event is handled asynchronously outside the
handling of the terminate node rx type, it is necessary that
terminate node rx type is generated after the done event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-19 10:26:38 +02:00
Wolfgang Puffitsch
13b4d441b3 Bluetooth: controller: Fix dependency of ISO TX buffer Kconfig
Synchronized Receiver does not require TX buffers.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-04-19 10:22:59 +02:00
Wolfgang Puffitsch
88db0d4b45 Bluetooth: controller: Consolidate ISO role Kconfigs
Consolidate Kconfigs for ISO roles to make compilation guards more
concise. Just introduces aliases, does not change functionality.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-04-19 10:22:59 +02:00
Trond Einar Snekvik
286d9c22cd Bluetooth: Mesh: Convert beacon timer to delayable work
Moves the beacon_enabled check in the beacon work handler to check the
beacon flag before sending anything, in case a cancel call fails.

Split out from #33782.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-16 15:34:30 -04:00
Jonathan Rico
545938ea55 Bluetooth: host: Accept keypress notifications as responder
Ignore peer keypress notifications as a responder, allowing the pairing
procedure to continue instead of being aborted.

The Bluetooth LE specification does not specify a behavior, the
implementation has the choice of ignoring or aborting.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2021-04-16 15:34:06 -04:00
Trond Einar Snekvik
777718ea6e Bluetooth: Mesh: move lpn logic for msg_received inside lpn.c
The Transport layer implements some checks surrounding the
lpn_msg_received call, with an accompanying comment that explains the
logic. Move this inside the msg_received call instead.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-16 15:33:09 -04:00
Trond Einar Snekvik
f54ca2fefd Bluetooth: Mesh: LPN: Rework poll timeout scheduling
Switch to the new delayed work API. Puts the scheduling for the next
poll in the response_received function instead of cancelling it, then
optionally scheduling it again later.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-16 15:33:09 -04:00
Trond Einar Snekvik
bf942bdf9a Bluetooth: Mesh: Report configured LPNTimeout in cfg_srv
Changes lpn_timeout_get behavior in the config server to report the
configured LPN timeout, instead of the currently remaining timeout time.
According to the Bluetooth Mesh Profile specification, section 4.2.21,
the PollTimeout list is a list of the PollTimeout timer values, and
according to table 4.32 in this section, values 1-9 are prohibited.
Although this is not explicitly stated, this indicates that the
PollTimeout value is the configured poll timeout time - not the time
remaining until the timeout value expires. This patch changes the
implementation to reflect this.

Split out from #33782.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-16 15:31:38 -04:00
Trond Einar Snekvik
5c6df442ff Bluetooth: Mesh: Transport length checks should account for MIC
The Transport layer would previously rely on the access layer to check
whether there's room for the full message and a MIC in the available
buffer space, and its own checks would ignore the MIC. This should be
handled by the Transport layer checks, so the access layer doesn't have
to.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-15 20:31:44 +02:00
Trond Einar Snekvik
820cfc52ad Bluetooth: Mesh: Rework publication timer
Periodic publication would previously build and send the first
publication inside the bt_mesh_model_pub() function, before cancelling
and rescheduling the next publication. The timer handler would only
handle retransmissions, and would abandon the rest of the publication
event if one of the packets failed to send.

This design has three issues:
- If the initial timer cancel fails, the publication would interfer with
  the periodic publication management, which might skip an event or
  send too many packets.
- If any of the messages fail to publish, the full publication event
  would be abandoned. This is not predictable or expected from the API.
- bt_mesh_model_pub() required 384 bytes of stack to build the message,
  which has to be factored into all calling threads.

This patch moves all transmission into the publication timer by
replacing k_work_cancel with a single k_work_reschedule(K_NO_WAIT). It
also changes the error recovery behavior to attempt to finish the full
publication event even if some of the transmissions fail.

Split out from #33782.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-15 20:31:44 +02:00
Marek Pieta
cc21ff5a8c Bluetooth: GATT: Fix undefined symbols
Change fixes build issues for configurations without Bluetooth.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2021-04-14 18:19:42 +02:00
Asger Munk Nielsen
b9b1c7e19b Bluetooth: controller: ISO adaptation layer, Rx unframed
First design towards ISO adaptation layer, this PR introduces
data-structures and framework for Rx unframed PDUs (BT RX ingress).
Two callbacks are defined for the SDU production (BT RX egress), one for
SDU allocation as well as a callback for emitting a reassembled SDU.

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2021-04-14 18:17:09 +02:00
Luiz Augusto von Dentz
6017506bcc Bluetooth: ATT: Add documentation for chan_send
chan_send does restore buffer state in case of an error which is
different than how bt_l2cap_send_cb works as it does always unref in
case of an error.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-04-13 16:21:25 -04:00
Luiz Augusto von Dentz
9d2d1a208a Bluetooth: ATT: Fix crash if bt_l2cap_send_cb fails
This fixes a regression introduced by
10841b9a14 as it did remove a call to
net_buf_ref which was used not only to keep a reference for resending
but also to prevent bt_l2cap_send_cb to unref the buffer in case it
fails.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-04-13 16:21:25 -04:00
Vinayak Kariappa Chettimada
94cd9dd207 Bluetooth: controller: Remove unused code in auxiliary advertising
Remove unused early prototyping code experimenting with
piggyback of auxiliary PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-13 13:02:35 -04:00
Morten Priess
07278fc98f Bluetooth: controller: Guard against race in conn. establishment
In the time between a NODE_RX_TYPE_CONNECTION node is sent from LLL and
demuxed in ULL, an ADV role disable may be executed.
This makes the LLL data referenced in the node NULL/invald, and
ull_conn_setup would operate on invalid data.

This commit introduces a check in ADV disable to disallow the operation
(including conn invalidation), if a connection has been initiated.

To prevent pipeline-queued prepares from advertising after disable has
been initiated, set 'cancelled' flag for immediate signalling to LLL.

Signed-off-by: Morten Priess <mtpr@oticon.com>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-13 13:02:35 -04:00
Morten Priess
cc46dee7d0 Bluetooth: controller: LLL refactoring of openisa for API changes
Update openisa LLL to match common LLL changes and make CI pass.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-04-13 12:15:12 +02:00
Morten Priess
772a77718e Bluetooth: controller: Framework for new feature BT_CTLR_JIT_SCHEDULING
This option enables BT_TICKER_SLOT_AGNOSTIC which eliminates
priorities and collision resolving in the ticker.

Event scheduling states are stored in the lll_hdr, and event priority
is passed from LLL implementation, and runtime priority calculated.

LLL implementation decides whether to program radio, start preemption
timer, and/or queue prepare in the prepare pipeline.

Event arbitration is made possible via the common LLL, but not yet
implemented in Nordic LLL.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-04-13 12:15:12 +02:00
Morten Priess
9aaa120abd Bluetooth: controller: Clean up LLL priority
Priority in the legacy stack has been unused and "work in progress" for
some time. With this commit, the priority passing/handling is cleaned
up, preparing for the new JIT scheduling priority handling.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-04-13 12:15:12 +02:00
Morten Priess
7dd5820920 Bluetooth: controller: Move common LLL from vendor file
Split lll_prepare and lll_resume from Nordic LLL to common file for
reuse by all vendors. The split also supports new JIT Scheduling by
defining a common place to calculate event prepare priority.

The module may also house other common parts of the LLL currently
re-implemented identically by vendors.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-04-13 12:15:12 +02:00
Morten Priess
385f232ae2 Bluetooth: controller: Propagate ticker force to ULL
The ticker 'force' flag is propagated via the ticker elapsed callback,
in order to provide necessary information for collision resolving in the
link layer.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-04-13 12:15:12 +02:00
Morten Priess
9f82034245 Bluetooth: controller: Introducing slot agnostic ticker
Added config BT_TICKER_SLOT_AGNOSTIC which configures the ticker in
a "slot agnostic" mode, in which no collision resolving or slot
reservation is possible or used. In this mode, the ticker acts as a
simple timer.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-04-13 12:15:12 +02:00
Morten Priess
4277af8f55 Bluetooth: controller: Rename BT_TICKER_COMPATIBILITY_MODE
Renamed to BT_TICKER_LOW_LAT in ticker, and changed selected
conditionally compiled code to use IS_DEFINED macro.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-04-13 12:15:12 +02:00
Emil Gydesen
2016509756 Bluetooth: Audio: Audio Input Control Service and client
This commit implements the secondary service
Audio Input Control Service (AICS) server and client.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-12 11:47:00 -04:00
Vinayak Kariappa Chettimada
661991405b Bluetooth: controller: Move LLL done handling from ULL to LLL
Move the LLL done event handling from ULL to LLL, this
reduces CPU utilization and reduces overhead between radio
events.

Fixes #21993.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-09 11:55:29 -04:00
Vinayak Kariappa Chettimada
5be2149c48 Bluetooth: controller: Defer event early abort
Defer the event early abort so that lll_done does not get
recursively invoked when called inside prepare callback.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-09 11:55:29 -04:00
Vinayak Kariappa Chettimada
27c26eb1e7 Bluetooth: controller: Fix LLL done and pipeline enqueue race
There is a race between the pipeline enqueue by the ULL
context when processing the LLL done event, and the
pipeline queue by the ticker timeout for a new radio
event. This caused an already enqueued event prepare to be
placed after the newly arrived request to enqueue a prepare
by ticker timeout.

Fix this race by placing the new prepare in the pipeline
instead of starting the event, when ULL is still processing
the LLL done event.

As ticker timeout and ULL processing of LLL done event are
in the same ULL_HIGH context, the pipeline handling is safe
with the order of prepares maintained correctly.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-09 11:55:29 -04:00
Michał Narajowski
f62a40beb6 Bluetooth: Fix callback handling in ECC Public Key generation
Commit d6c34c4644 changed the behavior
slightly but didn't update the documentation. The callback will now be
reset to NULL once the key is generated. Calling bt_pub_key_gen()
multiple times before the key is finished would result in creation of an
infinite loop. This could happen when an application calls mesh_init()
and mesh_reset() in quick succession. Clarify the behavior of the API in
the documentation.

Also passing a NULL argument would result in an undefined behavior, so
add a check to match the behavior described in documentation.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-04-09 13:27:24 +02:00
Emil Gydesen
42da370df5 Bluetooth: Use ATT FIRST/LAST attribute handle defines where applicable
Change to use the BT_ATT_FIRST_ATTTRIBUTE_HANDLE and
BT_ATT_LAST_ATTTRIBUTE_HANDLE instead of the literal values where
applicable.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-08 16:35:57 +02:00
Emil Gydesen
83396d91e2 Bluetooth: ISO: Fix segmentation fault for disconnecting BIS
The bt_iso_chan_disconnected assumes a CIS, but was
also used for BIS, so whenever it was called it attempted
to get a non-existing ACL connection.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-08 16:35:27 +02:00
Pavel Vasilyev
a94c7e3a23 Bluetooth: Mesh: Introduce acknowledged message API
The implementation of blocking calls is common for all the client
models.

This change reduces the code duplication by introducing new API that
helps to manage acknowledged messages.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-04-08 13:44:24 +02:00
Emil Gydesen
477dab13b3 Bluetooth: ISO: Update check for invalid num_bis for BIS events
Updates the check to only log the error if the issue was with
the num_bis and not the status.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-07 23:23:34 +02:00
Emil Gydesen
c479aa8211 Bluetooth: ISO: Add missinng disconnect reason to big_disconnect
A few calls to big_disconnect was missing the disconnect reason
due to a bad rebase.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-07 23:23:34 +02:00
Emil Gydesen
55771d36a7 Bluetooth: shell: Add index check for per_adv_sync commands
Adds a check for valid index before accessing the per_adv_syncs
array.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-07 14:17:34 +02:00
Emil Gydesen
49bf124bf6 Bluetooth: shell: Fix null check in cmd_per_adv_sync_delete
The check for NULL was on the pointer to the pointer,
rather than the pointer. The pointer of the pointer would
always be non-null, but the pointer might not be.

Moved from using a pointer of a pointer to just a
pointer to make it easier to read and understand.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-07 14:17:34 +02:00
Emil Gydesen
026da2df03 Bluetooth: host: Add ISO disconnect reason
Adds a disconnect reason in the ISO disconnect callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-07 14:16:54 +02:00
Emil Gydesen
62ba4f325c Bluetooth: host: Fixed bt_le_per_adv_sync interval unit decription
Changed from 1.25MS to 1.25 ms to be consistent with other
unit decriptions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-07 14:16:46 +02:00
Emil Gydesen
5a1afaa47a Bluetooth: host: Add functions for periodic adv sync objects
Adds two functions:
1) Lookup periodic adv sync object by address
2) Get information about a periodic adv sync object.

These can be useful for the application verify if there is already an
existing sync to an periodic advertiser.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-07 14:16:46 +02:00
Joakim Andersson
9f7061a83d Bluetooth: host: Add discovery of standard descriptor values
Add discovery of standard descriptor values. This provides a shorthand
instead of doing a read by UUID, allowing the application discovery
procedure to re-use the discover parameters for simple descriptors.

Fixes: #21489

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-04-06 10:50:18 -04:00
Trond Einar Snekvik
b84fee5190 Bluetooth: Mesh: Composition data page 0 traversal
Adds a parsing mechanism for Composition data page 0 in the Config
Client API, and uses it in the shell module to parse the incoming
composition data.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-06 16:19:13 +03:00
Trond Einar Snekvik
9259b199bb Bluetooth: Mesh: Rename bt_mesh_cfg_comp_data_get's status param to rsp
The first byte of the composition data status message is the returned
page index, not the status of the request. This is now reflected in the
API.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-04-06 16:19:13 +03:00
Vinayak Kariappa Chettimada
470e9fdd5c Bluetooth: controller: Fix minor typo in Periodic Sync PHY
Fix minor typo in Periodic Advertising Sync implementation
when PA/LNA is enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-06 13:52:14 +02:00
Vinayak Kariappa Chettimada
6ae93e62f0 Bluetooth: controller: Trivial peripheral ISO code cleanup
Trivial peripheral ISO code cleanup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-06 13:51:56 +02:00
Morten Priess
07d4ba5917 Bluetooth: controller: Fix ISO CI tests
Make bluetooth.init tests for nRF platform pass again by adding ULL/LLL
stub functions, and fixing minor compile issues.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-04-06 13:51:56 +02:00
Vinayak Kariappa Chettimada
a0c255f23e Bluetooth: controller: openisa: Fix missing conditional compile
Fix missing conditional compile regression introduced by
the commit 34451a9970 ("Bluetooth: controller: Conditional
compile adv addr used by initiator").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-04-06 13:51:45 +02:00
Emil Gydesen
b86f7addae Bluetooth: SMP: Adds Kconfig for minimum encryption key size
Adds a Kconfig option to set the minimum key size accepted
by this device. This can be used to e.g. enforce 128-bit keys.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-04-02 16:46:18 +03:00
Joakim Andersson
d9a89fb40b Bluetooth: host: Fix packet reording in ATT under high load
Fix packet reordering in ATT when putting the host under high load.
In certain conditions a packet can be transmitted while there is
elements in the TX queue in bt_att_send. This means that the packet will
skip ahead in the TX queue leading to packet re-ordering.

Fix by always appending to the queue, and then initiate sending of the
HEAD of the queue.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-04-01 13:07:47 +03:00
Vinayak Kariappa Chettimada
6d78016858 Bluetooth: controller: Fix event abort on delayed start
Fix the calculation of event delay when starting a radio
event. The calculation and check was incorrect causing
event abort when radio event was setup before the preempt
timeout by the lll_done when the next prepare was already
in the pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-31 11:18:42 +02:00
Morten Priess
7a79f1a73c Bluetooth: controller: Support for multiple CISes in a CIG
When a CIS indication is received and CIG ticker is already started,
calculate the absolute time of the first subevent of the new CIS,
and validate the handle. This will allow the LLL prepare to see a new
valid CIS, and calculate the offset within the CIG event, where the new
CIS should start. This offset is then valid for all following events for
the duration of the CIS.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-03-31 11:18:27 +02:00
Piotr Pryga
060d34d4a7 Bluetooth: controller: ULL: Fix DF build error if CTE Tx is disabled
Add missing #if defined(CONFIG_BT_CTLR_DF_ADV_CTE_TX) statements
to fix build errors of Direction Finding code when
the CONFIG_BT_CTLR_DF_ADV_CTE_TX Kconfig entry is not set.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-03-31 11:18:13 +02:00
Piotr Pryga
b4e188653e Bluetooth: controller: Enable GPIO debug pins for nrf52833 DK
Enable possiblity to use debug pins for controller debugging
purposes with nrf52833dk_nrf52833 board.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-03-31 11:17:58 +02:00
Rubin Gerritsen
1cd97a8a74 bluetooth: controller: radio: Fail if PPI/DPPI header not present
The hal requires one of these to be present.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-03-31 11:15:14 +02:00
Aurora Sletnes Bjørlo
4600fadf2b bluetooth: controller: radio: Split radio_nrf5_ppi.h
Splits the file into radio_nrf5_ppi.h and radio_nrf5_dppi.h
and moves the nRF53 DPPI to radio_nrf5_dppi.h.

Signed-off-by: Aurora Sletnes Bjørlo <aurora.sletnes@nordicsemi.no>
2021-03-31 11:15:14 +02:00
Aurora Sletnes Bjørlo
dfe8d32aec bluetooth: controller: radio: Use HAL API in radio_nrf5_ppi
Rewrite to use subscribe and publish functions for the
different peripherals. This will make it possible to test
the controller in a simulator.

Signed-off-by: Aurora Sletnes Bjørlo <aurora.sletnes@nordicsemi.no>
2021-03-31 11:15:14 +02:00
Vinayak Kariappa Chettimada
ab5d8432d3 Bluetooth: controller: Fix PHY Update procedure checks
Fix PHY update procedure to check transaction violations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 19:42:46 +02:00
Vinayak Kariappa Chettimada
03fa38aa7e Bluetooth: controller: Fix ping procedure checks
Fix ping procedure to check transaction violations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 19:42:46 +02:00
Vinayak Kariappa Chettimada
f8cec621d2 Bluetooth: controller: Fix data length update procedure checks
Fix data legnth update procedure to check transaction
violations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 19:42:46 +02:00
Vinayak Kariappa Chettimada
fa95660b63 Bluetooth: controller: Fix reject extended indication checks
Fix reject extended indication PDU dispatch to check
transaction violations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 19:42:46 +02:00
Vinayak Kariappa Chettimada
ef9e429228 Bluetooth: controller: Fix unknown control PDU checks
Fix unknown control procedure handling to check transaction
violations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 19:42:46 +02:00
Vinayak Kariappa Chettimada
9cb8b0af89 Bluetooth: controller: Fix Feature Exchange checks
Fix Feature Exchange procedure to check transaction
violations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 19:42:46 +02:00
Vinayak Kariappa Chettimada
fb5b5b7069 Bluetooth: controller: Add control procedure lock
Add control procedure lock flag to detection procedure
transaction violations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 19:42:46 +02:00
Emil Gydesen
929aec19ed Bluetooth: services: Fix ID check for bt_gatt_ots_obj_manager_obj_get
The ID validation check would always fail with IDs less than
OTS_OBJ_ID_START_RANGE, where the intention was that it should
allow the OTS_OBJ_ID_DIR_LIST (0) value as well if
CONFIG_BT_OTS_DIR_LIST_OBJ was enabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-30 11:01:06 -04:00
Joakim Andersson
b6323abaad Bluetooth: host: Fix missing big_disconnect when invalid number of BIS
Fix missing big_disconnect in hci_le_big_complete when the number of
BIS in the event is invalid.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-30 08:17:22 -04:00
Joakim Andersson
f4477df803 Bluetooth: host: Validate big_handle before using it as an array index
Validate the big_handle before received from the controller before
using it as an array into the bigs array.

Discover by coverity: Insecure data handling  (TAINTED_SCALAR)
  Using tainted variable "big_handle" as an index into an array "bigs".

Cleanup state of BIG in pending or syncing state if it exists.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-30 08:17:22 -04:00
Joakim Andersson
c9aa26efe2 Bluetooth: host: Fix parsing BIG handle as a two byte field
Fix parsing BIG handle which is just one octet as a two octet field,
which could have caused problems on big-endian systems.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-30 08:17:22 -04:00
Joakim Andersson
1f1c6c097e Bluetooth: host: Refactor BIG initialized handling to use bit flags
Refactor the BIG initialized atomic handling to use bits instead of a
single atomic.
This allows for more bit flags to be added.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-30 08:17:22 -04:00
Vinayak Kariappa Chettimada
77cfd3cf52 Bluetooth: controller: Fix race in create connection cancel
Fix race conditional when create connection cancel is called
and actually a connection did get setup while initiator is
being stopped.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 14:04:23 +02:00
Vinayak Kariappa Chettimada
34451a9970 Bluetooth: controller: Conditional compile adv addr used by initiator
Conditional compile adv_addr which is only used by
controller when supporting initiator/central role.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 14:04:23 +02:00
Vinayak Kariappa Chettimada
b2e802b018 Bluetooth: controller: Move initiated flag into role specific union
Move the initiated bit flag into role specific union, so that
other role specific bit flags can share bit space in the LLL
context structure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 14:04:23 +02:00
Vinayak Kariappa Chettimada
cd798202cb Bluetooth: controller: Fix flash driver sync regression
Fix flash driver sync regression introduced due to changed
default ULL_HIGH in the commit 30634334a8 ("Bluetooth:
controller: Fix ULL_HIGH priority to be lower than LLL").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 10:55:36 +02:00
Vinayak Kariappa Chettimada
433fad53bf Bluetooth: controller: Remove duplicate radio_isr_set call
Remove the redundant radio_isr_set function call.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 10:54:51 +02:00
Vinayak Kariappa Chettimada
0df70608a7 Bluetooth: controller: Fix SyncInfo with correct event counter
Fix Periodic Advertising SyncInfo structure to be filled
with correct event counter value considering accumulated
latency and ticker lazy value.

Fixes #32860.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 10:54:23 +02:00
Vinayak Kariappa Chettimada
f708f861bc Bluetooth: controller: Ticker next slot get to return lazy value
Updated ticker implementation to return lazy value for a
ticker when enumerating active tickers with time
reservations.

This is required to find offsets and to use the lazy value
to correctly calculate event and payload counter values that
needs to be filled into SyncInfo and BigInfo structures.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-30 10:54:23 +02:00
Martí Bolívar
c3d3b3dbc8 Bluetooth: remove CONFIG_BT_CTLR_TO_HOST_UART_DEV_NAME
This is now unused.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-03-29 16:33:51 +02:00
Morten Priess
96a13712ad Bluetooth: controller: Initial CIS peripheral establishment
LL_CIS_IND starts a ticker for the created CIG, using the event_counter
and offset provided. Ticker generates callbacks to
lll_peripheral_iso_prepare. Event done with ISO (extra) type is demuxed
and done handled for CIG including ticker update with drift
compensation.

TODO: Handle multiple CISes as well as pause/resume and scheduling
latency.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-03-27 08:57:03 -04:00
Morten Priess
a95ca4f3b7 Bluetooth: host: Reject CIS request if hci_le_accept_cis fails
Act on returned error code from hci_le_accept_cis, and reject CIS
request if failed.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-03-27 08:57:03 -04:00
Morten Priess
e0b8881622 Bluetooth: controller: Temporary LLCP CIS_REQ/CIS_IND handling
Implemented LL_CIS_REQ/RSP and LL_CIS_IND handling to allow a central
to establish a CIS connection. Implementation is temporary, for
test/development purpose and should be re-implemented in the new LLCP
framework when ready.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-03-27 08:57:03 -04:00
Emil Gydesen
8750b7c6f7 Bluetooth: audio: Changed VOCS to use ENOTSUP instead of EOPNOTSUPP
Changed to use ENOTSUP to be more consistent with the rest of the
bluetooth subsystem.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-26 15:32:43 -04:00
Jun Huang
03eb3778e0 Bluetooth: Host: Add a configuration for writable name
In the file gatt.c, GAP service contains the Device Name
characteristic. If writable, authentication and authorization may
be defined by a higher layer specification.It means that GATT
clients can write to device name GAP characteristic without
bonding. So we add a configuration for writable name without
bonding.

Signed-off-by: Jun Huang <huangjun6@xiaomi.com>
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-26 15:31:29 -04:00
Krzysztof Kopyściński
4c8605b003 bluetooth/smp: reject pairing in SC Only mode if insufficient keysize
This is required for GAP/SEC/SEM/BI-09-C and GAP/SEC/SEM/BI-10-C to pass
signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-03-26 15:30:25 -04:00
Emil Gydesen
83599467ce Bluetooth: host: Add feature check for periodic adv functions
Adds a check for the BT_LE_FEAT_BIT_PER_ADV bit for each
function related to periodic advertising, including sync and
PAST transfer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-26 15:28:09 -04:00
Emil Gydesen
f3e9c3eff1 Bluetooth: shell: Adds Periodic adv sync transfer shell command
Adds a command for tranferring a periodic adv sync to a PAST
receiver.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-26 07:10:15 -04:00
Flavio Ceolin
9fd4ea91b7 coccinelle: Remove extra semicolon
coccicheck --mode=patch --cocci=semicolon.cocci

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-25 11:35:30 -05:00
Joakim Andersson
eafc6c067f Bluetooth: host: Fix BT_LOG_SNIFFER_INFO option without BT_SMP enabled
Fix undefined reference to bt_key_foreach when BT_LOG_SNIFFER_INFO has
been enabled but BT_SMP is not enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-25 07:23:52 -04:00
Pavel Vasilyev
8bcc85b38c Bluetooth: Mesh: Check response address in Configuration Client
The Configuration Client doesn't check the address in a received
response. This means that a response from any device will be accepted.

This change ensures that the correct response will be accepted.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-03-25 07:09:47 -04:00
Joakim Andersson
a9b4cae019 Bluetooth: audio: Fix compilation issue with BT_AUDIO
Fix bluetooth audio compilation issue when BT_AUDIO is enabled but
no Bluetooth host services has been enabled.
This leads to an empty library file.
Instead of creating a new library for audio add the sources to the
parent library, similar to how bluetooth services are added.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-23 20:58:35 -05:00
Emil Gydesen
e1b840c4ab Bluetooth: Audio: VOCS add explicit ignore of notify return
Add casting to (void) to explicitely ignore the return value
of the notifi function calls.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-23 17:50:06 -04:00
Emil Gydesen
30edb5e52e Bluetooth: Audio: VOCS add missing check for offset in writes
VOCS does not support the write long procedure, and thus
should not accept any offset in write requests.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-23 17:50:06 -04:00
Emil Gydesen
04232fe1ef Bluetooth: Audio: Append bt_ for everything defined in vocs_internal
Was requested in the review for
ed2162c700 but was merged before it
could be fixed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-23 17:50:06 -04:00
Luiz Augusto von Dentz
2a42ebc743 Bluetooth: ISO: Add function to access bt_conn_iso
This adds bt_conn_iso function to safely access the struct bt_conn_iso
within a bt_conn.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-23 17:49:08 -04:00
Luiz Augusto von Dentz
9d0fb5ec47 Bluetooth: ISO: Remove channel direction
Channel direction was actually a source of confusion since the spec does
actually define the data path direction from controller point of view
meaning input actually means transmit and output receive, also direction
can be configured with different QoS settings.

To make these APIs less confusing and allow QoS to be configured
independently they are now split into RX (receiving) and TX
(transmission) settings including its data path.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-23 17:49:08 -04:00
Luiz Augusto von Dentz
0eb4bfee3f Bluetooth: ISO: Fix not unbind if ACL has been disconnected
If ACL has been disconnected any ISO handle shall be considered invalid
as well.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-23 17:49:08 -04:00
Luiz Augusto von Dentz
b5a46db6c6 Bluetooth: ISO: Use CHECKIF instead of __ASSERT_NO_MSG
CHECKIF is preferred as it handles full runtime error handling in
addition to just asserts.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-23 17:49:08 -04:00
Luiz Augusto von Dentz
af0fc963d8 Bluetooth: ISO: Fix cleanup connection
This fixes bt_iso_cleanup when there are still channels bound to the
ACL connection.

On top of it introduce bt_iso_chan_unbind which can be used to unbind
channels and thus release the reference to the ACL connection if that
has not been disconnected in which case the channels are unbind
automatically.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-23 17:49:08 -04:00
Luiz Augusto von Dentz
7ffbd55ecf Bluetooth: ISO: Fix revert direction when setting SDU
s_sdu refers to rx/input and m_sdu refers to tx/output.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-23 17:49:08 -04:00
Luiz Augusto von Dentz
151e93b78d Bluetooth: ISO: Fix not calling channel disconnected
When the channel has just been bound but is not connected yet there is
no need to send any command over the air but the disconnected callback
shall still be called in order to notify the channel owner that it has
reached disconnected state.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-23 17:49:08 -04:00
Luiz Augusto von Dentz
84811d5726 Bluetooth: conn: Fix invalid state transition
When initiating a disconnection conn_disconnect would be called to send
HCI_Disconnect but the controller may be quick enough to send Disconnect
Complete event before setting BT_CONN_DISCONNECT which will then cause
the invalid transition from BT_CONN_DISCONNECTED to BT_CONN_DISCONNECT
and the connection won't be freed properly.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-23 17:49:08 -04:00
Luiz Augusto von Dentz
a0d6f30895 Bluetooth: conn: Fix unbalance reference when an ISO has been connected
This fixes a regression introduced by 4350021f09 which prevents
references to be properly release when there is an ISO connection.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-23 17:49:08 -04:00
Emil Gydesen
ed2162c700 Bluetooth: Audio: Volume Offset Control Service and Client
This commit implements the secondary service
Volume Offset Control Service (VOCS) server and client.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-22 13:05:56 -04:00
Vinayak Kariappa Chettimada
7f727ac322 Bluetooth: controller: Fix regression in ctrl tx queue handling
Fix control Tx buffer leak into data Tx pool that happens
after a cross-over control procedure response was paused due
to currently active encryption setup procedure, and a new
control Tx PDU in addition to the paused one is enqueued
thereafter.

When the control tx PDUs is resumed but not yet enqueued
towards the radio, if there is a new control Tx PDU enqueued
then the paused control Tx PDU is not set as the head of the
control PDUs in the Tx queue. This caused the paused control
Tx PDU to be associated with data Tx pool, hence causing the
incorrect release into data Tx pool.

Relates to the commit bff76b4cce ("Bluetooth: controller:
split: Fix control tx queue handling") and to the
commit 6991d09977 ("Bluetooth: controller: Fix control tx
queue handling").

Fixes #32898.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-18 11:52:23 -04:00
Vinayak Kariappa Chettimada
bc782cf11b Bluetooth: controller: Remove redundant connection initiated check
Remove the redundant connection initiated check as the event
is closed on connection initiated and it is sufficient to
check in the prepare_cb function to abort any events in the
pipeline after the connection has been initiated.

Relates to commit 5ce5dc055e ("Bluetooth: controller:
Avoid race between ULL and LLL when initiating conn") and
commit 18f5fb99c1 ("Bluetooth: controller: Remove use of
lll_stop").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-18 13:52:42 +01:00
Vinayak Kariappa Chettimada
62e5db70ef Bluetooth: controller: Fix channel identifier for Periodic Adv/Sync
Fix the channel identifier value used in Periodic
Advertising and Synchronization.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-18 13:11:47 +01:00
Vinayak Kariappa Chettimada
545332db98 Bluetooth: controller: Use channel identifier function
Use the channel identifier calculation function in the
central and peripheral implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-18 13:11:47 +01:00
Vinayak Kariappa Chettimada
c5e75509ac Bluetooth: controller: Add function to calculate channel identifier
Added function to calculate channel identifier value
required for Channel Selection Algorithm #2.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-18 13:11:47 +01:00
Rubin Gerritsen
2affd52339 bluetooth: host: EAGAIN when initiating a connection when scanning
Also improve the documentation.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-03-17 15:33:43 -04:00
Carles Cufi
66c298dbb7 bluetooth: controller: Set missing bits in supported list
A bunch of commands were missing from the bitmap in the Read Local
Supported Commands response. Add them accordingly.

Fixes #33324.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-03-17 15:33:19 -04:00
Wolfgang Puffitsch
010c5c2f20 Bluetooth: controller: Ignore connections from same peer
Ignore connection indications from peers that are already
connected. This is to bring the behavior of the controller in
accordance with [5.2, Vol 6, Part B, 4.5 Connection state]:
"If an advertiser receives a connection request from an initiator it
is already connected to, it shall ignore that request."

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-03-17 15:32:47 -04:00
Wolfgang Puffitsch
1161c1dca9 Bluetooth: controller: Rename peer's address in advertising set struct
Rename the peer's address in the advertising set struct from `id_addr`
to `peer_addr` to clarify what the address refers to.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-03-17 15:32:47 -04:00
Joakim Andersson
2013ce41e6 Bluetooth: host: Fix undefined references to adv in central only builds
Fix regression is central only builds when CONFIG_BT_PRIVACY and/or
CONFIG_BT_EXT_ADV is enabled, or the functions bt_id_reset or
bt_id_delete is called from application.

This resulted in build error for undefined functions
bt_le_ext_adv_foreach and bt_le_adv_lookup_legacy since the definition
for these functions are now only compiled in when CONFIG_BT_BROADCASTER
has been enabled.

Regression from:
53cea4719d

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-17 18:58:49 +02:00
Joakim Andersson
101b96a0b9 Bluetooth: HCI: Fix option CONFIG_BT_HCI_ACL_DATA_SIZE default to 0
Fix CONFIG_BT_HCI_ACL_DATA_SIZE default value set to 0 when data length
feature in the controller is not enabled. In this case the default value
will be set to 0 which is outside of the range specified for the option.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-17 17:09:19 +02:00
Wolfgang Puffitsch
3773d6d3d0 Bluetooth: controller: Remove unused assignments to ticker_id_prev
Remove assignments to ticker_id_prev that were overwritten before
being used.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-03-17 16:03:12 +01:00
Wolfgang Puffitsch
07130ec24c Bluetooth: controller: Move access to volatile out of assertion
Move access to volatile variable out of assertion to avoid warnings
about side effect in assertion.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-03-17 16:02:09 +01:00
Wolfgang Puffitsch
ede34fb0e2 Bluetooth: host: Add missing include in id.c
Add hci_driver.h to include files in id.c to ensure that prototype for
bt_read_static_addr is visible. This fixes builds that define
CONFIG_BT_CTLR but not CONFIG_BT_HCI_VS_EXT.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-03-17 08:43:26 -05:00
Emil Gydesen
a3b6bc212f Bluetooth: services: Refacter OTS dir list to avoid circular dependency
Refactors the OTS directory listing object implementation to avoid
circular dependency.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-17 11:30:07 +01:00
Emil Gydesen
0cc408a9ac Bluetooth: Services: Ensure correct ID before getting object index
Moved the call to obj_id_to_index such that we can check for valid
ID before getting the index.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-17 11:30:07 +01:00
Emil Gydesen
806344c8e0 Bluetooth: Services: Adds bt_gatt_ots_obj_manager_obj_contains
Adds a ots_obj_manager function that returns true if the object is
in the object manager, or false otherwise.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-17 11:30:07 +01:00
Emil Gydesen
e90ec2df44 Bluetooth: services: Adds directory listing object to OTS
The directory listing object is an internal object which
content is the aggregation of all the metadata of all objects
(including the directory listing object itself). The client
can read this value to get a list of all objects with names,
lengths, and other metadata.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-17 11:30:07 +01:00
Luiz Augusto von Dentz
06e18c6df5 Bluetooth: L2CAP: Fix not including all DCIDs
The order of Destination CIDs shall correspond the order of Source CIDs
including its amount so errors that don't result in all connection being
refused shall not break the order of CIDs.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-17 11:29:27 +01:00
Luiz Augusto von Dentz
168389cccd Bluetooth: L2CAP: Fix invalid BT_L2CAP_ECRED_CONN_RSP
For errors that means all connections have been refused there is no need
to add dcids since none will be valid.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-17 11:29:27 +01:00
Luiz Augusto von Dentz
39a3dee29d Bluetooth: L2CAP: Fix not checking for L2CAP_ECRED_CHAN_MAX
When receiving L2CAP_CREDIT_BASED_CONNECTION_REQ the remote may request
more channels than allowed so this checks if amount of channel surpasses
the maximum channels (5) and return an error.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-03-17 11:29:27 +01:00
Trond Einar Snekvik
318d0928c1 Bluetooth: Mesh: Add Proxy callback structure
Adds a Proxy callback structure with a callback for Node ID enable and
disable. This API follows the Friend and LPN API pattern in mesh/main.h,
and can be expanded with more callbacks later.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-17 11:28:46 +01:00
Vinayak Kariappa Chettimada
7f62c7d531 Bluetooth: controller: Fix assertion on Ext. Advertising disable
Fix an assertion when disabling Extended Advertising with
auxiliary PDUs. Stop the auxiliary PDU scheduling after the
primary PDU scheduling is stopped first. This will avoid the
assertion caused due to a search for a stopped auxiliary PDU
offset by the primary PDU scheduling that is being stopped.

Fixes #32866.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-17 11:28:36 +01:00
Vinayak Kariappa Chettimada
dec6140685 Bluetooth: controller: Fix dev assert in CPR implementation
Replace a development assertion in the implementation of
Connection Parameter Request Procedure with an internal
comment and handle transaction violation be ignoring the
PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-16 10:02:05 +01:00
Vinayak Kariappa Chettimada
813b24157b Bluetooth: controller: Fix interval check in CONNECT_IND PDU
Check for interval value in received CONNECT_IND PDU and
ignore connection setup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-16 10:01:39 +01:00
Vinayak Kariappa Chettimada
4e7985e9d8 Bluetooth: controller: Fix channel map check in CONNECT_IND PDU
Fix the leak of node rx buffer used to generate the
connection complete and CSA#2 event introduced in the
commit 4a5f263e5a ("Bluetooth: controller: split: Validate
chan map and hop value") and the
commit 94d5f0854e ("Bluetooth: controller: fixing error
re. all zero chmap in conn-ind").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-16 10:01:39 +01:00
Michał Narajowski
497d9df96a Bluetooth: Mesh: Send Link Close message when closing link
Instead of silently closing the link we should send a Link Close message
three times before resetting provisioning state.

From Mesh Profile Specification v1.0.1.:
```
5.3.1.4.3 Link Close message

The Link Close message is used to close a link.
```

```
5.3.2 Link Establishment procedure

The device shall start the link timer, set to 60 seconds, when the link
is open. When the link timer expires, then the device shall close the
link.
```

```
5.3.3 Generic Provisioning behavior

If the sender does not receive a Transaction Acknowledgment message
within 30 seconds after sending the first message in a transaction,
the sender shall cancel the transaction, cancel the provisioning
process and close the link.
```

From Mesh Profile Test Specification p6:
```
MESH/PVNR/PBADV/BV-01-C

Test Procedure:
[...]
6. The IUT is induced to send a Link Close message with the Reason field
set to 0x02 to terminate the link. The message is sent at least three
times to ensure the message is received by the Lower Tester.
```

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-03-15 16:54:44 +02:00
Joakim Andersson
32afda01d1 Bluetooth: host: Fix style warnings in existing code
Fix style warnings in existing code.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-15 16:51:51 +02:00
Joakim Andersson
a7e3e32ea5 Bluetooth: host: Refactor out BR/EDR from hci_core to br
Refactor out the BR/EDR handling from hci_core.c to its own source file
in br.c.
BR/EDR consists of inquiry and discovery roles in addition to
initialization. SSP is still kept separate.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-15 16:51:51 +02:00
Joakim Andersson
c387d280fe Bluetooth: host: Align SSP HCI event handler function names
Align the SSP HCI event handlers with the rest of the functions in using
the bt_ prefix. In order to avoid name conflict with the HCI struct
definitions the infix _evt_ has been dropped.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-15 16:51:51 +02:00
Joakim Andersson
e61d1d0883 Bluetooth: host: Fix compilation error with BR/EDR enabled
Fix compilation error with BR/EDR is enabled but the feature
CONFIG_BT_KEYS_OVERWRITE_OLDEST is disabled.
This caused compilation error because the field aging_counter is not
defined in the keys struct.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-15 16:51:51 +02:00
Joakim Andersson
53cea4719d Bluetooth: host: Refactor out advertiser roles from hci_core to adv
Refactor out the advertiser roles handling from hci_core.c to its own
source file in adv.c.
Advertising roles consists of legacy and extended advertiser, and
periodic advertiser.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-15 16:51:51 +02:00
Joakim Andersson
be6797ed64 Bluetooth: host: Refactor out scan roles from hci_core to scan
Refactor out the scan roles handling from hci_core.c to its own source
file in scan.c.
Scan roles consists of regular scanning and synchronization to
periodic advertiser.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-15 16:51:51 +02:00
Joakim Andersson
c4a9bfbd57 Bluetooth: host: Don't include adv checks when adv is disabled
Don't include checks for advertiser is enabled when the broadcaster role
is not enabled. This makes it possible to have bt_le_ext_adv_foreach
be excluded from the compilation.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-15 16:51:51 +02:00
Joakim Andersson
54fe1cd1b3 Bluetooth: host: Refactor out identity handling from hci_core to id
Refactor out the identity handling from hci_core to its own source file
in id.c
Identity consistes of managing the identities of the device, the privacy
feature which hides the identities. And handling of the identity
resolving list in the controller, needed to support privacy-enabled
remote devices.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-15 16:51:51 +02:00
Joakim Andersson
517ba3756a Bluetooth: host: Dont include bt_adv_lookup_legacy when adv is disabled
Refactor the code so that bt_adv_lookup_legacy is always called after
the IS_ENABLED(CONFIG_BT_BROADCASTER) configuration has been checked and
the code path will be excluded.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-15 16:51:51 +02:00
Joakim Andersson
9ca13ca664 Bluetooth: host: Refactor command state set handling to one function
Refactor command state state handling to one function.
When setting state outside of hci_core the cmd macro is not available,
so in order to assign the buf pointer to state the function is needed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-15 16:51:51 +02:00
Vinayak Kariappa Chettimada
1e79d5b9c6 Bluetooth: host: iso: Fix typo in hci_le_big_terminate
Fix typo in hci_le_big_terminate function name.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-15 10:23:44 +01:00
Johan Stridkvist
a81765bbe4 Bluetooth: HCI: Add option CONFIG_BT_HCI_ACL_DATA_SIZE
Add the option CONFIG_BT_HCI_ACL_DATA_SIZE which allows the user
to configure the max HCI ACL data payload. This is needed for platorms
where the BLE LL, HCI uart and host run on three different cores.

Fixes: #30441

Signed-off-by: Johan Stridkvist <johan.stridkvist@nordicsemi.no>
2021-03-12 20:40:21 +02:00
Joakim Andersson
e06bac0e4f Bluetooth: host: Overwrite existing bond when IRK has been updated
Overwrite the existing bond when the IRK of the existing bond could not
resolve the RPA of the peer. This would happen if the peer has deleted
the bond and replaced the IRK that was used.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-12 11:27:43 -05:00
Joakim Andersson
7fee6b8ae8 Bluetooth: host: Refactor update_keys_check to operate on keys as input
Refactor update_keys_check helper function to operate on input keys
input. This allows the function to be re-used on a keys structure that
is not the current connection keys.

This also avoids the helper function changing the connection state.
The conn->le.keys pointer should at this point always have been
assigned, as central when sending the pairing request, and as peripheral
when receiving the pairing request at the very latest.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-12 11:27:43 -05:00
Aleksandr Khromykh
73e1c6a77d Bluetooth: Mesh: Fix restoring fast period divisor from settings
The Health Fast Period Divisor is stored within
the model publish parameters on the access layer.
The opposite part for divisor restoring has been missed.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2021-03-12 16:58:09 +02:00
Krzysztof Chruscinski
7e125fe7e4 logging: Add backend parameter to the init function
Added backend parameter to the backend init interface function.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-03-12 09:24:54 -05:00
Trond Einar Snekvik
20ce680d79 Bluetooth: Mesh: Make internal virtual addr pointers const
Adds the const qualifier to the internal api for adding and removing
virtual addresses, to allow them to accept const hardcoded values in
tests.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-12 16:17:27 +02:00
Trond Einar Snekvik
9b4266b591 Bluetooth: Mesh: Resolve keys before logging subnet
Moves the debug log printing the transport packet metadata to after the
keys are resolved, so that the subnet pointer is valid.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-12 16:17:27 +02:00
Trond Einar Snekvik
66699b8170 Bluetooth: Mesh: Add net transmit status rx in config client
Adds an opcode handler for the network transmit status opcode.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-12 16:17:27 +02:00
Trond Einar Snekvik
243e29cc29 Bluetooth: Mesh: Add poll callback for friend role
Adds a "polled" function to the friend callback structure, that gets
called every time the friend receives a poll message. The polled
callback is called before the establish callback, to match the LPN
behavior.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-12 16:14:58 +02:00
Emil Gydesen
d48b040a78 Bluetooth: Host: Updated ISO SCA description
The SCA (sca) field of bt_iso_chan_qos did not give much
information about the expected values or what they meant,
nor any information about what the value perhaps should be.

Updated the description and the ISO shell.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-11 06:38:08 -05:00
Trond Einar Snekvik
4fbd0cb0ca Bluetooth: Mesh: Perform replay check on SeqAuth
To prevent the transport layer from accepting duplicate or out of order
segmented messages, add an RPL-like check for the SeqAuth of the
segmented messages when their context is allocated. This prevents
duplicate receives of the same segmented messages in the case where a
single source address sends two segmented messages in parallel (to two
different addresses):

Previously, when receiving two segmented messages, the first message
would go through to the access layer, then the second. Then, if the
transport layer received any repeated segments for the first message, it
would fail to identify the SeqAuth as old, as all its segments were of
new sequence numbers, and the "already complete SDU" check would only
look at the second message. Thus, the segmented message got processed
again and passed to the access layer, even though it was a duplicate.

To solve this, we need a mechanism like RPL, but only for the segmented
messages' SeqAuth. We cannot re-use the actual RPL mechanism, as it
can't support the scenario provoked by the "blocking tx" mechanism in
transport. This mechanism allocates the SeqAuth when the message is
first passed to the transport layer. The ongoing message that caused the
block would keep sending segments with higher sequence numbers than
the blocked message got, which will cause the blocked message to fail
the RPL check.

This patch adds a parallel SeqAuth mechanism to the RPL module, which
only deals with the SeqAuth of the segmented messages. This list gets
checked when the segmented message is first allocated, in the same
manner as the general RPL mechanism. The storage gets hooked into the
RPL mechanism, by adding a separate seg field to each RPL entry.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-11 12:36:04 +02:00
Vinayak Kariappa Chettimada
0fbf31a147 Bluetooth: controller: Fix auxiliary PDU disable
When Extended Advertising terminated due to duration or
maximum number of events, the auxiliary PDU scheduling
is now correctly stopped.

Fixes #31254.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-10 15:08:47 -05:00
Vinayak Kariappa Chettimada
5b7f4d19bb Bluetooth: controller: nRF5: Move HAL_RADIO_PDU_LEN_MAX into radio_nrf5
Move the define HAL_RADIO_PDU_LEN_MAX into radio_nrf5.h in
the HAL folders.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-10 15:08:31 -05:00
Vinayak Kariappa Chettimada
1643b9453b Bluetooth: controller: nRF: Ensure HAL_RADIO_PDU_LEN_MAX is defined
Add compiler error if HAL_RADIO_PDU_LEN_MAX is not defined.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-10 15:08:31 -05:00
Peter Bigot
5506727bde bluetooth: mesh: update heartbeat subscription work API
Replace the legacy delayed work API with the new delayable work API.
Avoid cancelling work and manually notifying when the subscription is
disabled; instead allow the work item to do this.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-10 20:47:02 +02:00
Peter Bigot
6a097caa22 bluetooth: mesh: update heartbeat publish work API
Replace the legacy delayed work API with the new delayable work API.
Use a zero period as a flag value to ensure that the work handler is a
no-op of the publish operation is disabled.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-10 20:47:02 +02:00
Peter Bigot
17831b045f bluetooth: mesh: settings: update k_work API
Switch to new work API, taking advantage of the difference between
schedule and reschedule to force an update if the new deadline is
sooner, and retain any previous deadline (or use the new deadline) if
it isn't.  Do not leave a path out that could, due to races, fail to
schedule necessary work.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-10 20:45:13 +02:00
Peter Bigot
81b9ba3a9b bluetooth: mesh: health_srv: update k_work API
Switch to new work API.  Avoid a racy cancel by allowing the work
handler to deal with an immediate off when the time remaining changes
to zero.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-10 15:18:10 +02:00
Emil Gydesen
a264efbcbc Bluetooth: host: Initial support for BIS
Added initial support for BIS (broadcast ISO stream), which
adds support for creating BISes as both broadcaster and receiver,
as well as managing and creating BIGs.

Extends PA sync to handle BIGInfo adveritising reports.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-09 08:06:02 -05:00
Emil Gydesen
3fbff9ab77 Bluetooth: shell: Adds BT_INTERVAL_TO_MS macro
Added a simple macro for the BT shell that transforms the
interval unit (N * 1.25ms) to ms.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-03-09 08:06:02 -05:00
Peter Bigot
6a81a99724 Bluetooth: controller: update k_work_pending to new API
k_work_pending is now called k_work_is_pending.

These two uses are correct assuming the functions that invoke them are
not involved in race conditions: that the work is not pending is an
allowed condition for modifying state that will be used by the work
handler.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-09 04:52:23 -05:00
Trond Einar Snekvik
dc6e880eab Bluetooth: Mesh: Remove unsigned typing to returns in heartbeat
Removes U-suffix from signed return codes in heartbeat.c.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Trond Einar Snekvik
f9d41595a3 Bluetooth: Mesh: Explicitly ignore gatt_service_register return code
The error code from gatt_service_register is being ignored to ensure
that repeated actions still complete. Do this explicitly by adding
(void) casts, resolving coverity warnings on accidental error code
ignores.

Fixes #33051.
Fixes #33074.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Trond Einar Snekvik
aef354c6bc Bluetooth: Mesh: Resolve dead code in store_seg
If CONFIG_BT_MESH_SEQ_STORE_RATE is 1, the check in store_seq can be
reduced to a simple if (false), and the modulo code does not need to be
included in the build.

Fixes #33036.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Trond Einar Snekvik
bba2d7b84b Bluetooth: Mesh: Check model publish pointer before dereferencing
Moves the if !(pub) check to happen before it gets used in the
initialization of the message context in bt_mesh_model_publish.

Fixes #5116.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Trond Einar Snekvik
7039675df1 Bluetooth: Mesh: Only do label lookup when there are labels
Include virtual label's pending_store function in the LABEL_COUNT > 0
compile guard to avoid including dead iteration code in the compilation.

Fixes #32928.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Trond Einar Snekvik
8309353b7f Bluetooth: Mesh: Check subnet existence in heartbeat_send
Check that the assigned subnet hasn't been removed in heartbeat_send to
avoid potential NULL defererence in transport's ctl_send.

Fixes #32907.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-03-08 16:18:10 -05:00
Vinayak Kariappa Chettimada
05c69098e0 Bluetooth: controller: Comment on conn context reuse for coded PHY
Added comments to explain the re-use of allocated same
connection context to both 1M and coded PHY scanning context
when both PHY is enabled for initiating connection.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-08 12:52:09 +01:00
Vinayak Kariappa Chettimada
cffaf26f23 Bluetooth: controller: Extended create connection cancel
Initial work in progress implementation of Create Connection
Cancel for Extended connection initiation.

Adds implementation to teardown connection initiated at ULL
layer and gracefully release allocated resources.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-08 12:52:09 +01:00
Wolfgang Puffitsch
18f5fb99c1 Bluetooth: controller: Remove use of lll_stop
Remove use of lll_stop and lll_is_stop and rely on "initiated" flag in
lll_conn struct instead.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-03-06 09:32:42 -05:00
Wolfgang Puffitsch
5ce5dc055e Bluetooth: controller: Avoid race between ULL and LLL when initiating conn
Use an "initiated" flag in the lll_conn struct to guard the processing
of PDUs related to connection initiation (CONNECT_IND,
AUX_CONNECT_RSP). This avoids races between ULL and LLL when creating
a connection.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-03-06 09:32:42 -05:00
James Harris
b10428163a kernel: sem: add K_SEM_MAX_LIMIT
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".

Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.

In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.

These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.

Signed-off-by: James Harris <james.harris@intel.com>
2021-03-05 08:13:53 -06:00
Joakim Andersson
200f4687e0 Bluetooth: host: Log security keys needed by sniffer
Log the security keys that the sniffer needs in order to sucessfully
decrypt the connection.
This option allows the sniffer to work in the cases where enabling
using the SMP debug keys is not wanted, either because it changes the
way the peer behaves or is denied by the peer.
It also enables the sniffer to decrypt a connection where the bond
already exists.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-04 14:20:25 +02:00
Joakim Andersson
acd0555f50 Bluetooth: host: Convert allowed_cmds to an array of atomic_t of size 1
Convert allowed_cmds to an array of atomic_t of size 1.
This makes it future proof in case more commands are added.
Possibly silences coverity false positives on array vs singleton usage.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-03-04 13:11:47 +01:00
Lingao Meng
e5bee34b39 Bluetooth: Mesh: Fix cfg_cli Format and CID use problem
Fix some format warning in cfg_cli.c.
Fix use CID_VNAL as param when use vendor models.

This is a resubmission of PR (#30086)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-03-04 14:10:56 +02:00
Lingao Meng
e0d2309589 Bluetooth: Mesh: Fix config message result print format
Add line breaks to make the results more intuitive

This is a resubmission of PR (#30086)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-03-04 14:10:56 +02:00
Lingao Meng
71fd8e1d01 Bluetooth: Mesh: Add CDB handle key refresh phase
Fixed some undesired or incorrect macros, which
can cause build error.

This is a resubmission of PR (#30086)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-03-04 14:10:56 +02:00
Lingao Meng
0841ee69f2 Bluetooth: Mesh: Fix provisioner provisioning
Correct format errors, such as oob action 2-octers
should use 0x%04x, and action in prov capalilities pdu
big-ending. When every call `bt_mesh_auth_method_set<*>`
should also clear auth value, otherwise will case confirm
failed.

Provisioner role expect peer public key should be sent
immediately, instead of requiring ACK. After all, ACK may
be lost, and the other device’s public key will be sent
over, and provisioning procedure will be failed..

This is a resubmission of PR (#30086)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-03-04 14:10:56 +02:00
Vinayak Kariappa Chettimada
21e83e40ad Bluetooth: controller: Fix ticker job_guard
Move the ticker job_guard reset to after
ticker_job_compare_update, so that the ticks_current and
ticks_slot_previous are updated before ticker_worker gets
to execute. Without this fix, there is a possibility that
ticker_worker will use incorrect ticks_slot_previous and
ticks_current value under race conditions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-02 15:51:48 +01:00
Vinayak Kariappa Chettimada
ebecca7c47 Bluetooth: controller: Fix ticker to avoid recursive ticker_job
Fix ticker job to defer itself to avoid recursive
invocation to itself due to ticker interface calls from
inside the ticker operation callbacks.

The recursive use was exposed when using ticker stop
operation callback of stopping an auxiliary PDU to stop
the primary PDU scheduling as part of generation of
Advertising Terminate event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-02 15:51:48 +01:00
Vinayak Kariappa Chettimada
f9511079b2 Bluetooth: controller: Remove vendor specific internal LLL include
Remove inclusion of vendor specific internal LLL include
files in ULL source code.

Prefix `lll/` include file path to correctly include vendor
defined types and function implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-01 11:24:40 +01:00
Vinayak Kariappa Chettimada
92f5b68f2c Bluetooth: Use bt_id_get function to get count
Allow NULL pointer to be passed to bt_id_get function so
that only count can be fetched.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-26 08:12:43 -05:00
Peter Bigot
84334badfb bluetooth: host: improve documentation on stack override
There's a prompt to set the TX stack size, that's documented as an
advanced setting, but attempts to override it it are rejected unless
you add another setting that allows it to be change.  Tell the user
how to make changes work.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-25 16:53:35 +02:00
Piotr Pryga
deeecaaa8f Bluetooth: host: direction: Remove compilation warning
Remove compilation warning caused by currently not used
hci_df_set_conn_cte_tx_param function.
Code is sorrounded by #ifdef CONFIG_BT_CTLR_DF_CONN_CTE_RSP.
The CONFIG_BT_CTLR_DF_CONN_CTE_RSP is changed to be disabled
by default (until complete implementation of the feature is
provided).

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-25 14:53:27 +01:00
Piotr Pryga
8dcf8c111f dts: bindings: net: wireless: Change dfe-ant-num property name
Change dfe-ant-num propert name to dfe-antenna-num.
The change is conde to keep the same naming style
for all properies, like dfe-pdu-antenna property.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-25 14:53:27 +01:00
Piotr Pryga
64cb4bbc37 Bluetooth: controller: LLL: DF add initialization of ant switching GPIOs
Add initialization of GPIOs that are used for antenna switching.
GPIOs provided to DFE extension in Radio peripheral, to drive
antenna switching, should be initialized in GPIO peripheral beforehand.
The initialization is optional and may be disabled by Kconfig.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-25 14:53:27 +01:00
Piotr Pryga
e91a54799e Bluetooth: controller: LLL: Fix not switching antennas in AoD mode
Antenna switching done by Radio with use of GPIOs provided in
PSEL.DFEGPIO registers. Registers were initialized once during
controller initialization.
At preparation of new radio event, Radio peripheral is powered
down and up to resset its registers. It is related with multi
protocol handling and possible leftovers in Radio registers.

Due to that, PSEL.DFEGPIO registers should be initialized
at the preparation of every event that will transmit
or receive CTE and run antenna switching.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-25 14:53:27 +01:00
Piotr Pryga
9b3c941d4d Bluetooth: controller: Kconfig: Disable ant switching when CTE Rx not supp
Anternna switching should be disabled when CTE Rx is not supported
or disabled. Added missing dependency on BT_CTLR_DF_CTE_RX.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-25 14:53:27 +01:00
Piotr Pryga
dee17b0bca Bluetooth: controller: Fix compilation errors related with DF code
Add missing declarations of functions that are compiled in when
CONFIG_BT_CTLR_ADV_EXT_PDU_EXTRA_DATA_MEMORY is selected
Add missing include of header file.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-25 14:53:27 +01:00
Vinayak Kariappa Chettimada
8806225cb2 Bluetooth: controller: openisa: Fix unsupported ISR profiling
Fix duplicate include of lll_test.c file under the
unsupported ISR profiling feature in OpenISA port.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-25 12:54:35 +01:00
Vinayak Kariappa Chettimada
a0e34a1477 Bluetooth: controller: Fix missing cond. compile of adv extra data
Fix missing conditional compilation of Advertising PDU's
exta data member.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-25 12:54:20 +01:00
Vinayak Kariappa Chettimada
298b3ca467 Bluetooth: controller: #if defined(...) vs #if IS_ENABLED(..)
Use `#if defined(...)` instead of `#if IS_ENABLED(..)` when
conditional compilation of definitions in source code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-25 12:54:13 +01:00
Johan Hedberg
0ba9437938 Bluetooth: L2CAP: Fix missing buffer length check for sdu_len
We should verify that the buffer has sufficient data before attempting
to parse the SDU length field. If we get a too short packet just
disconnect the channel.

Fixes #32497

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-02-24 23:52:43 +02:00
Vinayak Kariappa Chettimada
8ded9c2487 Bluetooth: controller: Fix undeclared BT_CTLR_SCAN_SET
Fix undeclared BT_CTLR_SCAN_SET when BT_OBSERVER is
disabled.

Regression in commit bee6aa325b ("Bluetooth: controller:
Increased thread context operation queue count").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-24 13:46:31 -06:00
Joakim Andersson
f8005c7ba9 Bluetooth: host: Fix array overrun of client features bitset
Fix array overrun of client features bitset, where CF_BYTE_LAST was
incorrectly defined as 2 using module instead of divide.
Also fix additional bit-logic when number of bits would exceed a byte:
 - Inner for loop iterates from 0 to number of bits on a single byte.
 - Same bitmask used for all bytes.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-24 10:37:45 -05:00
Vinayak Kariappa Chettimada
9cb07ab413 Bluetooth: controller: Use define for common ext. header minimum size
Use define for the common extended header format's minimum
length value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-24 15:53:56 +01:00
Vinayak Kariappa Chettimada
c3befdc771 Bluetooth: controller: Handle ACAD in Periodic Advertising
Handle ACAD field in when updating the Advertising Data in
Periodic Advertising PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-24 15:53:56 +01:00
Martí Bolívar
31c1dc58ad Bluetooth: controller: fix typo
A macro is misspelled.

Fixes: #32599
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-02-24 07:21:48 -05:00
Joakim Andersson
61584fb35f Bluetooth: host: Don't auto-update device name and document behavior
Don't auto-update the device name in the advertising data as that
would clear any other scan-response data set by the application.
Document the behavior of the advertise with device name option
and the need to update data by the application to make sure
advertising data does not get cleared.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-23 20:08:51 +01:00
Joakim Andersson
84dffe5b3c Bluetooth: host: Fix endianness issue in reading CPF descriptor
Fix endianness issue in reading CPF descriptor not converting from
native endianess to little-endian on the 'unit' and 'description'
fields.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-23 20:07:53 +01:00
Joakim Andersson
22218129a6 Bluetooth: host: Use definitions of UUID values instead of constants
Use the definitions of UUID values instead of magic constants with
explanation in comment.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-23 20:07:53 +01:00
Vinayak Kariappa Chettimada
27b7c27dca Bluetooth: controller: Use Ext. Advertising association for BIG created
Check for associated Extended Advertising set to determine
whether Broadcast ISO Group instance has been already
created.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-23 19:36:41 +01:00
Vinayak Kariappa Chettimada
fc2e71dfec Bluetooth: controller: Add association between adv, sync and iso
Add association between extended advertising, periodic
advertising and broadcast ISO instance, so that attempts to
create and terminate BIG can detect error conditions.

Error conditions being, trying to create BIG without a valid
periodic advertising train, or terminating BIG without prior
creation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-23 19:36:41 +01:00
Vinayak Kariappa Chettimada
bee6aa325b Bluetooth: controller: Increased thread context operation queue count
When ticker job is disabled inside radio events then all
advertising, scanning, and slave latency cancel ticker
operations will be deferred, requiring increased ticker
thread context operation queue count.

Relates to #32430.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-23 13:01:20 +01:00
Vinayak Kariappa Chettimada
03ea3463c9 Bluetooth: controller: Facilitate reuse of BT_CTLR_MAX_CONNECTABLE
Minor rearrange order of definition BT_CTLR_MAX_CONNECTABLE
to better reuse it.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-23 13:01:20 +01:00
Vinayak Kariappa Chettimada
73308a3333 Bluetooth: controller: Consistent use of internal BT_CTLR_ADV_SET
Consistently use the internal BT_CTLR_ADV_SET value in the
controller's implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-23 13:01:20 +01:00
Piotr Pryga
1785129a3d Bluetooth: controller: pdu: Add offset_adjust filed to pdu_adv_sync_info
Add missing offset_adjust filed to pdu_adv_sync_info.
Add handling of the field when sync_info is added to advertising PDU.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-23 12:37:06 +01:00
Vinayak Kariappa Chettimada
ca220e4a9d Bluetooth: controller: Fix tertiary PDU and extended header length
Fix the tertiary PDU and extended header length value after
the refactoring in the commit c8475b9a3e ("Bluetooth:
controller: ULL: enable TX of CTE with per. adv. PDU").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-23 10:22:21 +01:00
Wolfgang Puffitsch
1a7157d316 Bluetooth: controller: Add missing compilation guard
Add missing compilation guard for initialization of "force" flag in
ull_slave.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-19 07:32:01 -05:00
Vinayak Kariappa Chettimada
8e75fff580 Bluetooth: controller: Move auto variables closer to local reference
Move auto variables closer to their locality of reference.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-19 10:29:10 +01:00
Vinayak Kariappa Chettimada
69869d1834 Bluetooth: controller: Move ull_adv_sync_pdu_set_clear
Move ull_adv_sync_pdu_set_clear function after LL interface
functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-19 10:28:55 +01:00
Vinayak Kariappa Chettimada
b230d23938 Bluetooth: controller: Rename pdu_biginfo to pdu_big_info
Rename struct pdu_biginfo to struct pdu_big_info.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-19 10:28:41 +01:00
Vinayak Kariappa Chettimada
4b4267fa09 Bluetooth: controller: Rearrange LL interface functions
Rearrange the LL interface functions in the ll.h file to
group functions use by HCI separate from other buffer and
control flow related functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-19 10:28:11 +01:00
Vinayak Kariappa Chettimada
cba60c56bd Bluetooth: controller: Minor rearrange LLL Adv structures
Minor refactoring/rearranging of LLL adv structures.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-19 10:27:48 +01:00
Vinayak Kariappa Chettimada
9527c04c60 Bluetooth: controller: Move version define to ll_feat.h file
Move the controller version define into ll_feat.h file to
keep the version number and featureset bitmaps together.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-19 10:26:48 +01:00
Wolfgang Puffitsch
9b3c0572cb Bluetooth: controller: Align include paths in hci.c
Align include paths for LLL include files in hci.c.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-18 12:03:13 -05:00
Wolfgang Puffitsch
cfa668fd51 Bluetooth: controller: Restructure LLL include files
Move LLL header files for all roles to common folder. Move
vendor-specific content to internal header files, in particular ADV
buffer handling. Define the vendor-specific type lll_adv_pdu in a
separate header file lll_adv_pdu.h to avoid cyclic dependency when
moving ADV buffer handling to internal header file. Make sure all
internal header files are in vendor-specific folders.

The goal is to have a more consistent structure for LLL header files
and allow unconditional inclusion of non-internal LLL header files.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-18 12:03:13 -05:00
Joakim Andersson
a4f0ca8649 Bluetooth: host: Refactor host ECC handling to own source file
Move the host ECC handling under BT_ECC to its own source file.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-18 13:50:22 +01:00
Joakim Andersson
4a25fb7136 Bluetooth: host: Remove dependency on host emulation for debug ECC keys
Remove the depency on host emulation of ECC for the Use debug keys
option.
This allows the application to use debug keys without shifting the
ECC from the controller to the host, which could potentially alter
the behavior of the application and make debugging this way less useful.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-18 13:50:22 +01:00
Joakim Andersson
9235b1b8b3 Bluetooth: Refactor ECC emulation supported commands bits
Refactor the ECC emulation setting the supported command bits in order
to group the supported commands together with the implementation of
these commands.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-18 13:50:22 +01:00
Morten Priess
5412f61ac6 Bluetooth: controller: Introduce separate done memq
In order to avoid stalling LLCP procedures blocking done event
processing, done events are now put in a separate memory queue,
and processed by own mayfly function.
This ensures prepare/done refcount balancing and prevents assertion
due to lack of done events.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-02-18 13:42:43 +01:00
Andrzej Kaczmarek
def2d7cf4e Bluetooth: controller: Fix reset with ext adv enabled
We need to make sure aux is cleared on reset, otherwise we may end up
with legacy advertising with aux.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-02-18 13:29:37 +01:00
Andrzej Kaczmarek
74d6b9fae9 Bluetooth: controller: Improve readability
Create shortcuts to set and lll to make code easier to read.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-02-18 13:29:37 +01:00
Andrzej Kaczmarek
9d8503c3b1 Bluetooth: controller: Initialize PDUs in set #0 on reset
Set #0 is used for legacy advertising when legacy HCI commands are used
and in such case it's possible to enable advertising without any prior
configuration. This means we should better always have PDUs in set #0
initialized with default empty data.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-02-18 13:29:37 +01:00
Andrzej Kaczmarek
55698d26b6 Bluetooth: controller: Remove all advertising sets on reset
We should remove all advertising sets when resetting controller. It's
enough to just clear is_created flag for each set.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-02-18 13:29:37 +01:00
Andrzej Kaczmarek
d5fc34491c Bluetooth: controller: Disable advertising before cleanup on reset
It seems more reasonable to first disable all advertising sets before
final cleanup.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-02-18 13:29:37 +01:00
Trond Einar Snekvik
135af76666 Bluetooth: Mesh: Reduce proxy rx buffer to an exact fit
Removes the 3 byte padding at the end of each proxy connection's rx
buffer.

Fixes #18509.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-02-17 23:16:29 +03:00
Wolfgang Puffitsch
fcadabadb5 Bluetooth: controller: openisa: Add missing include file
Add obviously missing include file in openisa Bluetooth controller.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-16 12:02:00 -05:00
Wolfgang Puffitsch
70f3e5a726 Bluetooth: controller: Add guards for feature_rsp_send
Add compilation guards for the feature_rsp_send function to avoid
compilation errors for some configurations.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-16 12:02:00 -05:00
Emil Gydesen
86f22aa526 Bluetooth: Audio: Move BT audio to new directory
It was decided that the Bluetooth audio subsystem should
be in subsys/bluetooth/audio instead of subsys/bluetooth/host/audio.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-02-16 08:55:17 -05:00
Wolfgang Puffitsch
ef1f8c34f1 Bluetooth: controller: Add support for ISO feature bits
Add support for ISO feature bits. This includes extending fields that
hold features to 64 bits to be able to handle the host-controlled
"Isochronous Channels" feature.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-15 17:33:46 -05:00
Wolfgang Puffitsch
45bdff1509 Bluetooth: controller: Add CIS-related LL control PDU types
Add definitions for LL_CIS_REQ, LL_CIS_RSP, and LL_CIS_IND PDUs.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-15 17:33:46 -05:00
Wolfgang Puffitsch
119d22a7b9 Bluetooth: controller: Refactor LLCP PDU length checks
Refactor LLCP PDU length checks to avoid constructing a look-up-table.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-15 17:33:46 -05:00
Wolfgang Puffitsch
b452321c51 Bluetooth: controller: Add init/reset stubs for CIS central/peripheral ULL
Add stub functions to initialize and reset CIS central and CIS
peripheral roles in ULL.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-15 17:33:46 -05:00
Wolfgang Puffitsch
4c9f89352b Bluetooth: controller: CIS HCI event generation
Implement generation of CIS Request and CIS Established events in HCI
layer.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-15 17:33:46 -05:00
Wolfgang Puffitsch
adaf45cf4b Bluetooth: controller: Define ULL/LLL interface for CIS central and periph
Define interface between ULL and LLL for CIS central and peripheral.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-15 17:33:46 -05:00
Vinayak Kariappa Chettimada
2bfaadffb8 Bluetooth: controller: Add Tx fragmentation assertion
Added Tx fragmentation implementation assertion to check
invalid offset use due to any memory corruptions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-15 12:07:59 -05:00
Vinayak Kariappa Chettimada
938fca2e08 Bluetooth: controller: Use ticker resolution margin in central
Use the vendor specific ticker resolution margin in the
central connection initiation offset calculation.

Related to commit 89ab68f242 ("bluetooth: controller:
Vendor specific ticker resolution margin").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-15 12:07:43 -05:00
Vinayak Kariappa Chettimada
ce27b2627f Bluetooth: controller: Remove redundant event margin use
Remove the redundant advanced scheduling event margin used
while finding a free space between existing active central
connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-15 12:07:43 -05:00
Vinayak Kariappa Chettimada
60730eb702 Bluetooth: controller: Move connection event length calculation
Move the initial connection event length calculation to
when initiating connection so that initiator with advanced
scheduling to place central connections in a non-overlapping
timeline has the correct ticks slot value available.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-15 12:07:43 -05:00
Vinayak Kariappa Chettimada
0d255cc270 Bluetooth: controller: Add invalid ACL data length check
Add checks to detect ACL data lengths greater than the
configured maximum Tx buffer size in the controller.
The Host should conform to the LE_ACL_Data_Packet_Length
returned by the LE Read Buffer Size command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-15 08:02:59 -05:00
Vinayak Kariappa Chettimada
08d3e49ee0 Bluetooth: controller: Optimize LOW_LAT_ULL scheduling
Optimize LOW_LAT_ULL scheduling by avoiding redundant
rx_demux mayfly enqueue. Only schedule after checking for
node rx or tx ack presence in the memq.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-15 08:02:17 -05:00
Vinayak Kariappa Chettimada
db3f7e7a7b Bluetooth: controller: Use Subsystem defined Periodic Advertising Kconfig
Use the Subsystem defined BT_PER_ADV_SYNC_MAX Kconfig in the
controller implementation of Periodic Advertising Sync Sets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-15 08:01:56 -05:00
Emil Gydesen
92c97a8eec Bluetooth: Audio: Fixed bad L2CAP Kconfig for ISO fragmentation
A line of code was guarded by CONFIG_BT_L2CAP_TX_FRAG_COUNT instead
of CONFIG_BT_ISO_TX_FRAG_COUNT.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-02-15 08:01:34 -05:00
Emil Gydesen
c6132c8fdb Bluetooth: Seperate BT_ISO and BT_AUDIO
ISO is a building block for BT_AUDIO but it is not only
useful for AUDIO, and as such should be possible to
enable without enabling BT_AUDIO.

This commit moves iso.c and iso_internal.h to the
host directory (from host/audio) and removes
the CMakeLists.txt.

The /audio directory is left intact for the Kconfig options
it provides, and as a directory for future BLE Audio
content.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-02-15 08:01:34 -05:00
Emil Gydesen
25be47e7a4 Bluetooth: hci_raw: Move BT_ISO to common Kconfig and fix ISO buffers
This commit moves the BT_ISO to a common (host and controller)
Kconfig and fixes the ISO buffers in hci_raw.c

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-02-15 08:01:34 -05:00
Piotr Pryga
62819022bd Bluetooth: controller: Add release of periodic advertising sync set
Add release of memory acquired for periodic advetising sync. set
when:
- advertising set is removed
- advertising parameters are changed and past PDU type was
  extended advertising PDU

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-15 08:00:58 -05:00
Piotr Pryga
c8475b9a3e Bluetooth: controller: ULL: enable TX of CTE with per. adv. PDU
Enable transmission of CTE with periodic advertising PDU.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-15 08:00:58 -05:00
Piotr Pryga
f1ef3087d9 Bluetooth: controller: ULL: Add CTE to per. adv. PDU
Add CTE to extended header of periodic advertising PDU.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-15 08:00:58 -05:00
Piotr Pryga
4b600fcf9a Bluetooth: controller: Remove assert in functions that get latest adv. PDU
Remove LL_ASSERT from functions that return latest advertising PDU.
The LL_ASSERT was raised in situation that there is no memory to
store unused PDUs memory in a pdu_free queue or extra_data_free queue
Those functions return NULL in such sitation. The returned value is
verified by callers by LL_ASSERT. That gives better context if lack
of memory issue issue occurs.

Besides that there was removed a LL_ASSERT from lll_adv_pdu_and_extra_-
data_alloc. The reasons is the same as above, to give better context
when the lack of memory issue occurs.
This function is used in ULL context (ll_adv_sync_ad_data_set).
If it returns NULL the caller will return BT_HCI_ERR_MEM_CAPACITY_-
EXCEEDED to Host.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-15 08:00:58 -05:00
Piotr Pryga
cf47d53c77 Bluetooth: controller: LLL: enable TX of CTE with per. adv. PDU
Enable transmission of CTE with periodic advertising PDU.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-15 08:00:58 -05:00
Piotr Pryga
515f95382e Bluetooth: controller: radio: Add DF configuration to enable CTE TX
Add set of functions that will make possible to configure
radio Direction Finding Extension to transmit CTE for periodic
advertising.

Some of the new Radio API functions are provided as separate
functions changing the same Radio peripheral registers, e.g.
radio_df_mode_set_aoa, radio_df_mode_set_aod. This is done on
purpose and is related with lack of DFE in nrf52_bsim.
To avoid use of conditionally compiled constants to represent
e.g. CTE mode; separate functions were introduced.
Thanks to that DF unit tests are able to compile successfully
without changes in nrf52_bsim platform. Also if DFE is added
to nrf52_bsim there is no need to change the code until it is
desired.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-15 08:00:58 -05:00
Piotr Pryga
b56a2d1384 Bluetooth: controller: Add extra data storage for ext. adv. configuration
The storage for extra data is required for implementation of
CTE transmission with periodic advertising.

Data required to transmit CTE correctly are compound of two parts:
- PDU field CTEInfo
- radio configuration to transmit actual constant tone at the end
  of PDU.

Extra data is a storage required for radio configuration data.
Nevertheless it must be in compliance with content of CTEInfo field.
Because of that extra data is stored as part of lll_adv_pdu and
is double buffered like PDU memory.

Bluetooth 5.1 spec. allows to enable or disable CTE TX
and change CTE TX parameters when periodic advertising is
enabled. Besides that CTE TX settings may be set before periodic
advertising parameters are set. In such situation ll_adv_sync_set
may be not yet created.
To overcome these constraints ULL should store CTE TX
settings and forward them to LLL only when CTE TX is enabled.
Because of above reasons ULL stores CTE TX settings in ll_adv_set.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-15 08:00:58 -05:00
Piotr Pryga
175e9d9c4d Bluetooth: controller: hci: Enable reporting of CTE reception
Enable reporting CTE in periodic advertising reports send to host.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-15 08:00:58 -05:00
Piotr Pryga
3c59b6a25f Bluetooth: controller: ll_feat: Add CTE connectionless TX feat.
Add Directin Finding related features:
- transmission of connectionless CTE,
- antenna switching during CTE transmission (AoD),
to list of features supported by controller.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-02-15 08:00:58 -05:00
Ioannis Glaropoulos
2d32ca5e99 bluetooth: controller: remove support for nRF5340 PDK
Remove support for nRF5340 PDK in the BLE controller.
The controller will now support only the nRF5340 DK.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-02-15 07:59:43 -05:00
Vinayak Kariappa Chettimada
706551cfe5 Bluetooth: controller: Fix periodic sync cancel for Coded PHY
Fix cancel of Periodic Synchronization on Coded PHY. Reset
the association of periodic sync instance after validation
of command disallowed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-15 07:54:18 -05:00
Vinayak Kariappa Chettimada
fde9ba5c43 Bluetooth: controller: Fix network privacy with resolution disabled
When address resolution is disabled, an identity address has
been added into the resolving list with peer IRK, and device
privacy has not been selected for the peer device then
connection indication shall not be sent to the peer that is
advertising using its identity address.

Fixes #24731.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-14 18:17:05 -05:00
Matias Karhumaa
dd63b0baf8 Bluetooth: hci_raw: Fix switch fallthrough
Fix apparently accidental switch fallthrough in bt_buf_get_tx().

Signed-off-by: Matias Karhumaa <matias.karhumaa@gmail.com>
2021-02-14 15:58:05 -05:00
Joakim Andersson
2b3a2c8573 Bluetooth: host: Fail pairing if remote cannot meet required security
Fail after pairing request and response have been exchanged if the
selected pairing method would not result in the required security level.
This avoids the case where we would discover this after having encrypted
the connection and disconnect instead.

This was partially attempted but lacked checking for authentication
requirement when L3 was required, as well as skipping the check if L4
was required but remote did not support Secure Connections since the
check was after we had taken the legacy branch.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 14:58:03 -05:00
Joakim Andersson
6b8fbfa68a Bluetooth: host: Set error in security changed when not required level
Set the error in the security changed callback when the encryption has
not reached the required security level.
Terminate the pairing procedure in SMP on failure to avoid the security
changed callback being called twice in this case.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 14:58:03 -05:00
Joakim Andersson
09eb7e066b Bluetooth: host: Terminate the pairing procedure when disconnected
Terminate the pairing procedure when disconnected while this was in
progress. This notifies the application that security has failed and
removes the key entry.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 14:58:03 -05:00
Joakim Andersson
6b72e6584c Bluetooth: host: Set encryption pending when LE SC bond exists
Set the SMP flag encryption pending in the case where a bond exists
with ediv and rand equal to zero, i.e LE Secure Connections bond.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 14:58:03 -05:00
Joakim Andersson
0cc5dc1839 Bluetooth: host: Don't call callbacks on unexpected SMP PDUs
When receiving unexpected SMP PDUs with no pairing procedures in
progress don't treat it as a pairing procedure that has failed.
This causes unexpected SMP PDUs to trigger the pairing failed and
security changed callback at unexpected times.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 14:58:03 -05:00
Joakim Andersson
500ac369ed Bluetooth: shell: Improve security error readability
Improve the readability of security errors by converting the error code
to a string.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 14:58:03 -05:00
Joakim Andersson
1bf90c6f2f Bluetooth: shell: Add only pairing failed and pairing complete callbacks
Add status only pairing failed callbacks (complete and failed) so that
these handlers can be added without providing the ability for MITM
pairing procedures.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 14:58:03 -05:00
Joakim Andersson
00d8068b45 Bluetooth: host: Fix wrong error code type passed to security changed
Fix wrong error code type passed to security changed, passed SMP error
code instead of HCI error code.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 14:58:03 -05:00
Joakim Andersson
bdf1452b4e Bluetooth: host: Rename auth_err_get to security_err_get
Rename auth_err_get to security_err_get which better reflect the
error namespace it converts to. Also update to using the enum definition
instead of uint8_t for local variable holding returned value.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 14:58:03 -05:00
Faisal Saleem
b8c33efb78 Bluetooth: SMP: fix for bt fixed passkey BT_PASSKEY_INVALID
when BT_PASSKEY_INVALID was set, it never updated the fixed
passkey which made its use ineffective

Signed-off-by: Faisal Saleem <faisal.saleem@setec.com.au>
2021-02-11 14:46:24 -05:00
Joakim Andersson
10841b9a14 Bluetooth: host: Release ATT request buffers once sent
The ATT request buffers are held until the ATT response has been
received. This means that the ATT request buffers are released by the
RX thread, instead of the from the RX priority context of
num_complete.
This can cause a deadlock in the RX thread when we allocate buffers
and all the available buffers are ATT requests, since the RX thread is
the only thread that can release buffers.

Release the ATT request buffers once they have been sent and instead
handle ATT request resending by reconstructing the buffer from the
GATT parameters.

Also re-order the order of resource allocation by allocating the
request context before the buffer. This ensures that we cannot
allocate more buffers for ATT requests than there are ATT requests.

Fixed a buf reference leak that could occur when the ATT request buffer
has been allocated, but GATT returns an error before handing the
responsebility of the buffer to ATT, for example when bt_att_req_alloc
fails.
This is fixed by moving the functionality of att_req_destroy to
bt_att_req_free.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Joakim Andersson
5cbfdf6311 Bluetooth: host: Remove unused ATT request destroy callback
Remove the ATT request destroy callback which is never assigned
by any of the ATT requests.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Joakim Andersson
75deefb1b2 Bluetooth: host: Fix indicate without user callback
Fix indicate without func not working properly, when sent as a
non-req by GATT this has two propblems:
 - The indicate would not be treated as a transaction, and back
   to back indicate would be sent without waiting for the confirm
 - The destroy callback would not be called on the indicate parameters
   since the indicate_rsp callback would not be called.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Luiz Augusto von Dentz
8df6124deb Bluetooth: ATT: Remove BT_ATT_TX_MAX
ATT channels do support queueing buffer so it no longer need to block
waiting the tx_sem besides the buffer allocation already serves the
same purpose as the application will not be able to have more requests
than there are buffers available.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-02-11 12:59:01 -05:00
Joakim Andersson
9752cee3d7 Bluetooth: host: Refactor smp handling of conn pointer
Refactor SMP to have a conn pointer where this pointer is used
multiple times.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Joakim Andersson
fcdb2eef25 Bluetooth: host: Allow requesting new security when security changed
Allow to request a higher security level during the key distribution
phase.

This is required by ATT and L2CAP since they only react to the encrypt
change event where they resend the current request.
The current request might require a higher security level still and
might have to request a higher security level before the pairing
procedure has been finished.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Joakim Andersson
301317e8fd Bluetooth: host: Handle multiple step security elevation
When ATT resends an ATT request it is sent as a "response" instead of
as a request. This causes the ATT request buffer to be released and
the ATT request cannot be resent one more time.

This causes a problem when the ATT request requires authentication
but the elevation of security is not enforcing MITM protection.
In this case the ATT will first require security level 2 and then resend
the request once this has been reached.
This will lead to a new ATT error response and ATT will require security
level L3.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Joakim Andersson
2f588f946f Bluetooth: host: Fix update keys when using debug public key check
Fix the update keys check allowing to overwrite the keys when using
debug keys. Instead the check disallowed overwriting keys made using
debug keys.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Joakim Andersson
abd470cbe6 Bluetooth: shell: Fix gatt write command not cleanup up on error
Fix gatt write command returned "write in progress" when either
hex2bin or bt_gatt_write returned an error.
The write_params.func should not be set if the write command was not
successful.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-11 12:59:01 -05:00
Trond Einar Snekvik
512444d863 Bluetooth: Mesh: Update seqnum when re-encrypting for friend
Sets the sequence number when re-encrypting messages from the friend to
the lpn.

This is a regression from #28511.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-02-10 08:55:40 -05:00
Trond Einar Snekvik
48526b6925 Bluetooth: Mesh: Initialize msg_ctx when re-encrypting friend msg
Set app_idx and net_idx in the msg_ctx before calling
bt_mesh_keys_resolve when re-encrypting friend messages, as they'll be
referenced inside the function.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-02-10 08:55:40 -05:00
Vinayak Kariappa Chettimada
b365ab06a7 Bluetooth: controller: Fix missing advertising PDU len initialization
Fix missing advertising PDU length initialization which
prevented advertising PDU to be transmitted by Radio. This
issue was reproduced when connectable undirected advertising
was enabled without setting an advertising data.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-10 07:17:48 -05:00
Trond Einar Snekvik
a281d10cff Bluetooth: Mesh: Store network at the end of provisioning
After #31176, the network would get stored immediately in
bt_mesh_net_create, causing the address and devicekey to get stored as
their zero-initialized version, as they're only being set in the
bt_mesh_comp_provision call, which fires after.

Fixes #32067.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-02-08 10:37:08 -05:00
Joel Westerberg
8b14b83940 Bluetooth: ISO: fix error value set but not returned
err was set to -EIO, but function still returned 0.

Fixes: #31847

Signed-off-by: Joel Westerberg <joel@teenage.engineering>
2021-02-05 08:13:14 -05:00
Vinayak Kariappa Chettimada
a980012aa9 Bluetooth: controller: Fix build error with ISO support
Fix build error due to missing include file with ISO support
enabled.

Fixes #31996.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-05 06:36:52 -05:00
Emil Hammarstrom
3cf64b17c3 bluetooth: host: expand l2cap CID abbreviation
Reduces some user confusion regarding whether it is related
to "Connection ID", "Channel ID", or "Company ID" for the
uninitiated.

Signed-off-by: Emil Hammarstrom <emil.hammarstrom@assaabloy.com>
2021-02-04 08:31:20 -05:00
Vinayak Kariappa Chettimada
b7acb6bf55 Bluetooth: controller: openisa: Fix to use compiler memory barrier
Fix OpenISA port to include compiler memory barrier as in
commit 1a14f8b3a6 ("Bluetooth: controller: Use DMB instead
of DSB").

Relates to commit 1af2b91c23 ("Bluetooth: controller: Fix
Tx Buffer Overflow") and to commit ef2ece82c0 ("Bluetooth:
controller: openisa: Fix sanitycheck failures") and to
commit c2fc629dd2 ("Bluetooth: controller: 255 byte AD
payload support").

Fixes #31937.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-03 14:16:12 -05:00
Vinayak Kariappa Chettimada
59616c0b03 Bluetooth: controller: openisa: Fix unsupported ULL LLL Prio config
Fix for OpenISA rv32m1_vega_ri5cy board not supporting
different IRQ Priority levels for LLL, ULL_HIGH and ULL_LOW
execution contexts.

Fixes #31937.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-03 14:16:12 -05:00
Vinayak Kariappa Chettimada
3664cb9f62 Bluetooth: controller: Fix BT_CTLR_ULL_HIGH_PRIO default value
Fix BT_CTLR_ULL_HIGH_PRIO default value to equal
BT_CTLR_LLL_PRIO value if BT_CTLR_LOW_LAT is enabled, else
default ULL_HIGH to lower IRQ priority level in comparison
to LLL IRQ priority level. If BT_CTLR_ZLI is enabled,
BT_CTLR_ULL_HIGH_PRIO can default to a priority level value
of 0 and still be lower priority level than the LLL which
is placed at Zero Latency IRQ priority level (highest
priority in the CPU).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-03 14:16:12 -05:00
Trond Einar Snekvik
2bd5b63dfd Bluetooth: Mesh: Verify network buffer max len
As network_decode needs a target buffer for decoding, the max PDU length
must be checked to prevent overflow on the target buffer. When receiving
a proxy configuration message with excessive length, there's no previous
check for this.

Also pulls the NET PDU length defines out into net.h, so they can be
used when defining the target buffers.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-02-03 13:12:09 -05:00
Vinayak Kariappa Chettimada
1af2b91c23 Bluetooth: controller: Fix Tx Buffer Overflow
Fix Tx Buffer Overflow caused by uninitialized node_tx
memory being used by ULL ISR context due to Compiler
Instructions Reordering in the use of MFIFO_ENQUEUE.

The MFIFO last index was committed before the data element
was stored in the MFIFO due to Compiler Instructions
Reordering.

This is fixed now by adding a Data Memory Barrier
instruction alongwith a compiler memory clobber.

Fixes #30378.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-02 14:00:57 -05:00
Vinayak Kariappa Chettimada
1a14f8b3a6 Bluetooth: controller: Use DMB instead of DSB
Use of Data Memory Barrier instruction with memory clobber
in ARM Cortex M architectures is sufficient in the
controller implementation to keep compiler data access
instructions in order so that an ISR vectoring has memory
accesses in the correct order as intented by design.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-02 14:00:57 -05:00
Joakim Andersson
97d59a7c6d Bluetooth: host: Mark the option BT_FIXED_PASSKEY as insecure
Mark the option BT_FIXED_PASSKEY as an insecure option.
During Legacy pairing the passkey is used as encryption key, and
brute-forcing this is easy.
During LE Secure Connections the passkey is checked one bit at a time,
so when it is fixed the passkey can be deduced with series of pairing
attempts.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 11:09:05 -05:00
Joakim Andersson
b9695c07cd Bluetooth: kconfig: Fix SMP dependency on BT_ECC
The Bluetooth SMP protocol depends on the BT_ECC for the LE Secure
Connections pairing. Since this feature cannot be disabled we must
select this dependency.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 11:09:05 -05:00
Joakim Andersson
971404eee9 Bluetooth: host: Fix fixed passkey for legacy pairing
Fix fixed passkey for legacy pairing. The pairing procedure fails
because the temporary key (TK) has not been set for this pairing
procedure.

Fix this by always requesting the legacy TK.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 11:09:05 -05:00
Joakim Andersson
2d50761c3e Bluetooth: shell: Fix misleading shell message id-create failed
Fix misleading message in the bluetooth shell when the id-create
command returns en error code. In this case both failure and success
messages are printed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 08:46:17 -05:00
Joakim Andersson
e800ec1cf3 Bluetooth: host: Add options to control behavior of the init command
Add options to control the behavior of the init command.
Option no-settings-load allows the user to create identities
with the id-create command after bt_enable() but before settings_load().
Option no-ready-cb allows the user to test using synchronous enable,
since this sometimes leads to different behavior of the stack.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 08:46:17 -05:00
Joakim Andersson
8a55e04e23 Bluetooth: host: Prevent bt_rand calls before bt_enable
Prevent the bt_rand function from being called before bt_enable.
Depending on the implementation of bt_rand this function cannot
be called before bluetooth has been initialized. With host supplied
crypto functions the HCI LE rand command is used for example.

The use case for calling bt_id_create before bt_enable is meant for
when the application has storage for the identity instead of the stack.
So we add the requirement that the application has to have storage
for the identity resolving key (IRK) in addition when the local
device is privacy-enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-02-02 08:46:17 -05:00
Vinayak Kariappa Chettimada
30634334a8 Bluetooth: controller: Fix ULL_HIGH priority to be lower than LLL
Fix the default ULL_HIGH execution priority to be lower than
LLL execution priority to reduce Radio ISR service latency.

Also, default to Zero Latency IRQ for Radio ISR if enabled
in the kernel.

Fixes #29994.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-02 08:09:29 -05:00
Vinayak Kariappa Chettimada
929dae8cad Bluetooth: controller: Add ISR cputime measurement
Adding ISR cputime measurement for Radio, LLL, ULL_HIGH and
ULL_LOW execution contexts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-02 08:09:29 -05:00
Andrzej Kaczmarek
ebb5b9a558 Bluetooth: shell: Fix 'bt per-adv-data'
ad_len parameter is not length of complete advertising data, but number
of bt_data structs passed to bt_le_per_adv_set_data - we pass only one.

Also memset target buffer before converting hex string so data shorter
than specified will be right-padded with zeroes instead of some
leftovers.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-02-02 07:15:40 -05:00
Nicolas LANTZ
942979b252 Bluetooth: Mesh: Fix fix mod_sub_get_vnd
pass cid instead of CID_NVAL in parameters of mod_member_list_get

Signed-off-by: Nicolas LANTZ <nicolas.lantz@ubicore.net>
2021-02-01 08:38:24 -05:00
Vinayak Kariappa Chettimada
b8b946f37f Bluetooth: controller: Fix rx_demux scheduling for LOW_LAT_ULL
Fix the mayfly callee id for the rx_demux scheduling under
the LOW_LAT_ULL implementation. This could be causing
undefined mayfly execution behavior in nRF51x SoC.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-01 08:36:19 -05:00
Joakim Andersson
c14da53772 Bluetooth: host: Remove the deprecated bt_conn_create_slave_le function
Remove the deprecated bt_conn_create_slave_le function.
This was deprecated in the 2.3.0 release.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-01-29 12:53:10 -05:00
Vinayak Kariappa Chettimada
1afbe0770c Bluetooth: controller: Fix accept scan en/disable if already en/disabled
Conform to Bluetooth Specification, if the LE_Scan_Enable
parameter is set to 0x01 and scanning is already enabled,
any change to the Filter_Duplicates setting shall take
effect. Disabling scanning when it is disabled has no
effect.

Fixes #31019.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-29 08:02:46 -05:00
Nicolas LANTZ
3ff1eb618f Bluetooth: Mesh: Fix mod app key get vnd
pass cid instead of CID_NVAL in parameters of mod_member_list_get

Signed-off-by: Nicolas LANTZ <nicolas.lantz@ubicore.net>
2021-01-28 07:52:06 -05:00
Vinayak Kariappa Chettimada
7712caa1a7 Bluetooth: controller: Fix peripheral conditional compilation
Fix regression in peripheral only build conditional
compilation introduced in commit 8a9bda307cc1 ("Bluetooth:
controller: Fix CPR conditional compilation").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
7295204af9 Bluetooth: controller: Fix CPR conditional compilation
Move the newly added Connection Parameter Request reject
state implementation under conditional compilation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
804419592f Bluetooth: controller: Fix incorrect reset of CPR reject state
Fix regression in adding the state for Connection Parameter
Request being rejected where in Connection Parameter Request
Procedure state machine was prematurely reset before the
reject PDU was enqueued.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
7bf202791f Bluetooth: controller: Fix missing initialization
Fix missing initialization of ticks_to_offset value on
instantiation of new peripheral context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
b5cba3c955 Bluetooth: controller: Minor identation changes
Minor changes to indentations in advanced scheduling
implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
b150d3a90f Bluetooth: controller: Fix repeated offsets in CPR PDU
Fix repeated offsets in LE Connection Parameter Request PDU
due to rounding errors. Use tick units of connection
interval to calculate the offset units.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
a8e25d9402 Bluetooth: controller: Fix deferred Conn Param Req offset population
Fix deferred Connection Parameter Request offset population
by introduction of explicit states waiting for the offset
calculations to complete in the ULL_LOW context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
383e688e3f Bluetooth: controller: Fix deferred Conn Update offset population
Fix deferred Connection Update offset population by
introduction of explicit states waiting for the offset
calculation to complete in the ULL_LOW context.

Fixes #29636.

The problem was, in an encrypted connection the enqueued PDU
to be transmitted is encrypt in the prepare callback by the
hardware and swapped to a different buffer for transmission;
the deferred offset population did not reflect in the
transmitted PDU as it was filled in the cleartext buffer
while encryption completed into the encrypted buffer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
2919989ee9 Bluetooth: controller: Fix compilation error with encryption disabled
Fix compilation error with encryption support disabled in the
controller.

Fixes #31693.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 07:57:28 -05:00
Piotr Pryga
53b4da93e9 Bluetooth: controller: ll_sw: Fix wrong cmake code that adds radio_df.c
Fix error introduced by pull request:
https://github.com/zephyrproject-rtos/zephyr/pull/31591

Zephyrs CMake extension function zephyr_library_sources_ifdef()
does not allow to use complex conditions to toggle if
sources should be included in build or not.
It allows to use only single variable as an input for
feature_toggle argument because it is double-expanded
in contition statement in the function.

In case there is a requirement that source file is included
when more complicated condition is true we have to fall-back
to reqular if() statement and zephyr_library_sources().

The fix is required because without it radio_df.c source
is never compiled. If DF functionality is enabled build
will fail because of missing functions implementation.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-27 07:57:03 -05:00
Joakim Andersson
3102f3b081 Bluetooth: host: Fail pairing with identical public key
Fail the pairing procedure when both devices have the same non-debug
public key.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-01-26 13:41:56 -05:00
Vinayak Kariappa Chettimada
8f537de8c4 Bluetooth: controller: Fix encryption and procedure with instant
Fix implementation to run local peripheral initiated control
procedure with instant in parallel with remote initiated
encryption procedure.

Relates to #28887.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-26 06:18:39 -05:00
Thomas Ebert Hansen
d4347339f5 Bluetooth: controller: Fix enc. setup during PHY update
If a PHY update is waiting for the instant to be reached and the master
starts the encryption procedure, store the pending PHY update procedure
and handle it simultaneously with the encryption setup.

This fix prevents the encryption setup from stalling and thereby timing
out after 40s, after which the master drops the link.

The ll_conn::llcp::encryption can not longer be unioned with the
ll_conn::llcp:phy_upd_ind as one would overwrite the other.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2021-01-26 06:18:39 -05:00
Vinayak Kariappa Chettimada
d2415fcfd0 Bluetooth: controller: Add peripheral/central conditional compilations
Add conditional compilation on peripheral and central
specific control procedure implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-26 06:18:39 -05:00
Vinayak Kariappa Chettimada
abcee4dc2b Bluetooth: controller: Fix BIG Sync Terminate command
Fix BIG Sync Terminate Command to generate Sync Established
event if Sync initiation is in progress.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-26 06:18:23 -05:00
Vinayak Kariappa Chettimada
eaa0215c74 Bluetooth: controller: Fix missing node rx allocation for ISO establish
Added missing allocation of node rx buffer required for
generation of Broadcast ISO Sync Established.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-26 06:18:23 -05:00
Emil Gydesen
085d2eda8d Bluetooth: Audio: Add missing unref for ISO recv
The net_buf was never unref'ed when the host received an
ISO package that was a SINGLE.

Also adds a few additional debug messages.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-01-25 21:47:06 -05:00
Emil Gydesen
aed1db5782 Bluetooth: shell: Fix number of optional args for iso send
`iso send` may take an optional "count" parameter but the
number of optional arguments was incorrect.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-01-25 21:47:06 -05:00
Piotr Pryga
a8c18ff5f4 tests: Bluetooth: df: Fix build error, missing antenna config in DTS
The DF tests are implemented to be executed with nrf52_bsim platform.
The nrf52_bsim platform does not include Direction Finding Extenstion.
Due to that, radio_df.c compilation failed with error about missing
antenna configuration in DTS.

To solve the problem, I've changed nrf.cmake to include radio_df.c
file when CONFIG_BT_CTLR_DF is defined and CONFIG_SOC_SERIES_BSIM_NRFXX
is not definded.

Thanks to that any other platform is not affected. The file will not
build if there is no appropriate configuration or there are missing
features in a hardwared.

Unit tests have provided stub imlpementation or radio functionality.
If nrf52_bsim has implemented Direction Finding Extension, the
DF unit tests code will stil work and will not require additional
changes. Also content of the file is not affected by contional
compilation entries.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-25 21:46:34 -05:00
Joakim Andersson
dbe4a5f0d2 Bluetooth: host: Remove ATT modification of L2CAP conn pointer
Remove ATT modifying the L2CAP channel state by unassigning the
the connection pointer on timeout.
Unassigning this pointer does not prevent the ATT channel from receiving
since bt_l2cap_recv does not inspect this pointer before calling the
channel receive function.
This prevented the disconnected callback from being called on the
channel after the channel had timed out, but since the disconnected
callback now handles this case this workaroun is no longer needed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-01-25 18:49:30 -05:00
Joakim Andersson
28bddf9380 Bluetooth: host: Handle ATT timeout on disconnected ATT channel
Handle ATT timeout on disconnected ATT channel.
When the ATT channel is disconnected with a pending request the ATT
timeout is canceled and the response processed with an error code.
However canceling of delayed work is not guaranted to succeed, e.g:
"Work queue thread has removed the work item from the queue but has not
 called its handler"
This could lead to timeout handler being invoked after the disconnected
handler.

Fixes: #29098

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-01-25 18:49:30 -05:00
Vinayak Kariappa Chettimada
c2513eb993 Bluetooth: controller: Fix PHY update procedure cachability
Fix missing PHY update procedure cachability omitted in
commit 16dbb9a4fe ("Bluetooth: controller: split: Fix cmd
disallowed and collision disconnects").

Relates to #31473.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-25 11:49:28 +01:00
Piotr Pryga
609701fa21 Bluetooth: controller: radio: Fix compilation error
Fix compilation error caused by use of wrong header file:
nrfx/hal/nrf_radio.h instead of hal/nrf_radio.h.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-22 09:49:03 -05:00
Rubin Gerritsen
76c5707639 bluetooth: controller: Disable Coded PHY by default.
Coded PHY is only enabled by default if the application is using
BT_HCI_RAW.

Coded PHY is not needed in most applications.
By disabling Coded PHY, most applications will:

* Get smaller in terms of flash and ram usage
* Not get vurnerable to devices trying to switch to Coded and
  thereby increasing power consumption.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2021-01-21 15:57:48 -05:00
Piotr Pryga
ff1d8efd38 Bluetooth: controller: Fix error when max ant. pattern len not defined
Fix compilation error if CONFIG_BT_CTLR_DF is not defined.
If DF was not enabled, there was missing CONFIG_BT_CTLR_DF_MAX_-
ANT_SW_PATTERN_LEN and undeclared symbol was found.

Split ll_df.h into two parts:
- ll_df.h that is generally includeable and allows to successfully
  compile sources when DF is not enabled.
- ll_df_internal.h to be used in soucres that are compiled when
  DF is enabled.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-20 14:55:24 +01:00
Piotr Pryga
0b230ae639 Bluetooth: controller: Add DF initialization to controller init sequence
Direction Finding requires initalization of a set of registers
in Radio peripheral. Also it requires information about antenna
matrix unit that are provided by end user in DTS overlay.
Implemented initialization step is responsible for validation of
hardware information delivered by DTS and setting up DF related
registers in Radio.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-20 14:55:24 +01:00
Piotr Pryga
f3e04898eb Bluetooth: controller: ll_sw: nordic: Add DF antenna configuration handling
Add support for Direction Finding antenna configuration in
Nordic hal of Bluetooth controller.
Add handling of response for HCI_LE_Read_Antenna_Information
HCI command in controller (upper and lower link layer).
Handling of response to the command requires antenna matrix
configuration.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-20 14:55:24 +01:00
Andrzej Głąbek
dbf9d99e54 bluetooth/controller: Update paths in inclusions of nrfx HAL files
After nrfx glue code was decoupled from nrfx sources, it is no longer
feasible to use those inclusions in the <nrfx/hal/nrf_*.h> form (there
is no point in adding the main directory of the hal_nordic module as
an include path solely for this reason). Remove then the nrfx/ part.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2021-01-19 17:35:04 +01:00
Joakim Andersson
66427d370b Bluetooth: host: Fix size of L2CAP disconnect request pool
Fix size of L2CAP disconnect request buffer pool which did not include
the size of the L2CAP signal header.

Regression from: 3346aa4d39

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-01-18 19:12:20 +01:00
Nirosharn Amarasinghe
b2fcda8efb Bluetooth: Controller: re-factor magic constants
Defined 625 and 1250 as context specific interval common to ULL and LLL.
Checked with bluetooth sanity checks.

Fixes #23314.

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2021-01-18 19:12:12 +01:00
Thomas Ebert Hansen
65b453d44e Bluetooth: controller: Fix header inclusion
Use correct headers to make the inclusion of lll.h work when
CONFIG_BT_CTLR_USER_EXT is enabled.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2021-01-18 19:07:06 +01:00
Thomas Ebert Hansen
c3f557c12b Bluetooth: controller: User defined CPR intervals
Some proprietary protocols that reuse the Bluetooth LLCP logic requires
that the CPR interval has a valid range that differs from the Bluetooth
specification defined.

Vendor must implement the function (ull_vendor.h)
uint16_t ull_conn_interval_min_get(struct ll_conn *conn)
that returns the valid limit for the given connection.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2021-01-18 19:07:06 +01:00
Morten Priess
3617128cf4 Bluetooth: controller: Add vendor operations to TICKER_USER_LLL_OPS
Allow vendor specific increase of user operation capacity for LLL, to
support queuing additional ticker operations from lower link layer
context. These would typically take place in lll_xxx_prepare.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-01-15 11:37:23 -05:00
Lingao Meng
c262239680 Bluetooth: Mesh: Fix friendship counter increasing order
For Bluetooth Mesh, counter shall be increasing by one when
every try to establishing friendship.

Counter to be used when create friendship security material.
So this value shall be consist between friend and lpn.

Due to zephyr bluetooth mesh send previous counter, after that
it will automatically increase one, which will result in the
incorrect generation of friend key when key rephase.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-01-15 11:36:48 -05:00
Vinayak Kariappa Chettimada
21d9bb6e51 Bluetooth: controller: Remove BIT64 redundant definition
Remove the redundant definition of BIT64 macro.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-15 11:21:25 -05:00
Pavel Vasilyev
561a8e4f0e Bluetooth: Mesh: Break up mesh settings
The mesh settings.c module is a giant piece of code responsible for
storing the mesh stack configuration. Such approach makes it difficult
to control the data to be stored, breaks the stack modules'
encapsulation by forcing them to reveal the internal kitchen, which
leads to unpleasant issues such as #19799.

This commit moves the responsibility of storing the configuration
to corresponding modules while keeping control of the moment of storing
the configuration and of starting the stack after the settingss loading
is completed.

This doesn't introduce any abstraction between the mesh settings.c and
other modules as it will add more complexity and overhead than necessary
for the actual task.

Fixes #19850

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-01-14 16:38:50 +02:00
Piotr Pryga
472febfe69 Bluetooth: host: direction: Add public API to set CTE TX enable for adv
Add public function to set Constant Tone Extension transmission
enabled or disabled for periodic advertising.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-14 15:26:32 +01:00
Piotr Pryga
0a09441e47 Bluetooth: host: Rename and make non-static HCI cmd state update
Enable CTE HCI command requires update of a state of its
execution after receive command completion response from
controller. Host has already implemented such functionality
but it was used only internally by hci_core.

This commit changes it to be accessible from other sourece files
in host.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-14 15:26:32 +01:00
Piotr Pryga
f36b7a8732 Bluetooth: controller: hci: Add HCI_Set_Connectionless_CTE_TX_Enable cmd
Add implementation of HCI_Set_Connecitonless_CTE_TX_Enable
command to HCI. Add scratch implementation of command handling
functions to controller.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-14 15:26:32 +01:00
Piotr Pryga
9d711d6e09 Bluetooth: host: direction: Fix compilation error
Fix compilation error caused by missing header files.
Reorganized order of header files include.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-14 15:26:32 +01:00
Piotr Pryga
43a1304e9a Bluetooth: controller: df: Config help corrction correction
Correct names of kconfig entries to mach to style of other entries.
Style correction in hci.c. Use the same approach of checking if
Kconfig entry is enabled.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-14 15:26:32 +01:00
Michał Narajowski
419d2aa85b Bluetooth: Mesh: Fix heartbeat subscription tests
MESH/NODE/CFG/HBS/BV-01-C expects the MinHops to be 0x7f after
disabling subscription, but 0x00 for subsequent Get requests.

MESH/NODE/CFG/HBS/BV-02-C expects us to return previous
count value and then reset it to 0.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2021-01-12 06:49:38 -05:00
chao an
1027b0e4f0 Bluetooth: host: add support for unregister scanner callback
This is a pairing function with bt_le_scan_cb_register()
to used for remove the scanner callback from callback list.

Signed-off-by: chao an <anchao@xiaomi.com>
2021-01-12 12:31:00 +02:00
chao.an
bc7e86b9ec Bluetooth: host: Unified namespace of hci event
BT_HCI_EV_LE_REMOTE_FEAT_COMPLETE ->
BT_HCI_EVT_LE_REMOTE_FEAT_COMPLETE

Signed-off-by: chao an <anchao@xiaomi.com>
2021-01-12 12:30:11 +02:00
Morten Priess
907a8377b3 Bluetooth: controller: Fixed conn_meta bitflag misalignment
Fixed misalignment of bitflag in ll_conn type causing unintentional
overwrite between unions. Common flag must be present in master/slave
uinons as well. Problem is only present when enabling feature
CONFIG_BT_CTLR_CONN_META, which is default disabled.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2021-01-10 15:40:05 -05:00
Vinayak Kariappa Chettimada
e0ff2d0957 Bluetooth: controller: Reserve link Rx buffer to ISO sync
Reserve two link rx buffer for each supported Broadcast ISO
sync instance, for establishment and for sync lost node rx
generation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-10 15:39:42 -05:00
Aurora Sletnes Bjørlo
717687806c bluetooth: controller: radio: Add guards on TXPOWER
For tx_power_max_get and tx_power_floor, only allow for
positive values of txpower if they are defined.

Signed-off-by: Aurora Sletnes Bjørlo <aurora.sletnes@nordicsemi.no>
2021-01-10 15:39:22 -05:00
Vasilyev, Pavel
d593af30db Bluetooth: Mesh: Fix typo when deleting app key in CDB
This commit sets `net_idx` to `BT_MESH_KEY_UNUSED` when deleting app key in
cdb.

Signed-off-by: Vasilyev, Pavel <pavel.vasilyev@nordicsemi.no>
2021-01-08 13:16:46 +02:00
Vinayak Kariappa Chettimada
8a5154d71c Bluetooth: controller: Add missing initialization of ISO sync
Add missing initialization of ISO sync context to be
established.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 18:02:34 +01:00
Vinayak Kariappa Chettimada
c709d4f85f Bluetooth: controller: Rename periodic adv rx enable flag
Rename the Periodic Advertising Rx Enable flag from
is_enabled to is_rx_enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 18:01:44 +01:00
Vinayak Kariappa Chettimada
44492c8324 Bluetooth: controller: Rename supported ISO Sets Kconfig
Rename Kconfig BT_CTLR_SCAN_SYNC_ISO_MAX to
BT_CTLR_SCAN_SYNC_ISO_SET, to be consistent with other
Kconfig naming.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 18:01:10 +01:00
Vinayak Kariappa Chettimada
32a79dd7e3 Bluetooth: controller: Fix AUX_CONNECT_RSP PDU buffer size
AUX_CONNECT_RSP PDU static buffer definition was missing one
byte required for the Extended Header Flags.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 18:00:35 +01:00
Vinayak Kariappa Chettimada
5d3d9b7522 Bluetooth: controller: Internal documentation of node rx count
Document with comments, the explanation of node rx count and
the design of the free rx PDU management.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 17:59:59 +01:00
Vinayak Kariappa Chettimada
bc71d39d81 Bluetooth: controller: Fix free Rx PDU queue starvation
Fix for scenarios where in active PHY Update Procedure or
Connection Update Procedure could cause temporary depletion
of the free Rx PDUs in the queue between LL/HCI thread
context to LLL context. Symptoms being on-air NACKing during
the above said procedures, causing supervision timeouts due
to procedures not completing at instants.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 17:59:59 +01:00
Vinayak Kariappa Chettimada
2a99857cad Bluetooth: controller: Refactor PA/LNA PPI configuration
Refactor the implementation of PA/LNA PPI configuration
which was done on every Tx or Rx as common code to be
executed once per radio reset. And only setup the timeout
and enabling of PPI at every Tx or Rx.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 17:59:20 +01:00
Vinayak Kariappa Chettimada
5470444e6a Bluetooth: controller: PA/LNA use NRF_P0/P1 define
For PA/LNA implementation use NRF_P0/P1 defines instead of
the deprecated NRF_GPIO to reference GPIO Port 0 registers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 17:58:24 +01:00
Vinayak Kariappa Chettimada
e51295a309 Bluetooth: controller: Fix missing GPIOTE channel disable
Fix the missing GPIOTE channel disable when GPIOTE channel
is alternately used between PA and LNA use.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 17:58:01 +01:00
Vinayak Kariappa Chettimada
f265b178c3 Bluetooth: controller: Fix regression in PA/LNA support
Fix regression in PA/LNA support wherein the GPIO pins where
left in undefined state after each radio event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 17:57:29 +01:00
Vinayak Kariappa Chettimada
e14be4477a Bluetooth: controller: Fix missing call to radio_setup interface
Fix regression, add back missing call to radio_setup HAL
interface. This is needed to setup the initial PA/LNA GPIO
states.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 17:56:57 +01:00
Vinayak Kariappa Chettimada
108d431902 Bluetooth: controller: nRF52811: Errata Id 164 not applicable
nRF52840 Engineering A Errata Id 164 is not applicable to
nRF52811 SoC.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-07 17:56:03 +01:00
Joakim Andersson
577cd82b0d Bluetooth: host: Fix crash when receiving response after ATT timeout
Fix crash in ATT when the response for a request is received after
the ATT timeout has fired and the ATT channel has been detached.
Add similar handling for all ATT channel operations.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-01-07 13:51:18 +01:00
Vinayak Kariappa Chettimada
db5270bd93 Bluetooth: controller: nRF53x: SWI mapping should use SOC define
SWI IRQ line mapping for nRF5340 shall use
CONFIG_SOC_NRF5340_CPUNET for conditional compilation
instead of the board define, so as to allow new boards to
use the BLE controller implementation.

Fixes #30488.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-06 16:25:52 +01:00
Piotr Pryga
1c493b4a77 Bluetooth: host: direction: Add public API to set CTE TX params for adv.
Add publicly accessible function to set Constant Tone Extension
parameters for CTE transmission with periodic advertising.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-05 09:38:53 +01:00
Piotr Pryga
098f767298 Bluetooth: host: Add set connectionless CTE TX params wrapper function
Add implementation of a wrapper for HCI_LE_Set_-
Connectionless_CTE_Transmit_Parameters send command.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-05 09:38:53 +01:00
Piotr Pryga
9bfc095d4a Bluetooth: host: Add DF to initalization sequence
Add Direction Finding to host initialization sequence.
It allows to get information about Direction finding
optional CTE settings supported by controller.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-01-05 09:38:53 +01:00
Vinayak Kariappa Chettimada
0a23b1248f Bluetooth: controller: Remove is_enabled flag for BIS events
Remove is_enabled flag in LLL of BIS events context, as the
status returned from ticker_stop interface is sufficient to
determine if the Broadcast ISO Sync was established or not.
HCI Command Disallow as reason is to be returned if sync was
not established or sync was loss prior to call of HCI LE
BIG Terminate Command was called.

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

Fixes #31044.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-04 16:27:58 +01:00
Luiz Augusto von Dentz
64cc5a3746 Bluetooth: GATT: Fix BT_GATT_AUTO_DISCOVER_CCC
When using BT_GATT_AUTO_DISCOVER_CCC if the ccc_handle is not set
bt_gatt_subscribe would initiate a discovery to locate the CCC handle
but instead of awaiting it to complete the code does proceed to call
gatt_write_ccc even with ccc_handle being 0x0000 which is invalid.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-12-27 18:20:28 +01:00
Andrzej Kaczmarek
f8c8cac714 Bluetooth: controller: Use PHY_xxx symbols consistently
We have convenient PHY_1M, PHY_2M and PHY_CODED symbols defined but
they are not used too much in the code. This replaces all usages of
magic numbers and other symbols as PHY constants with those symbols.

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

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-20 13:02:44 -05:00
Emil Gydesen
47aa17bb5c Bluetooth: controller: Implements ULL Sync ISO ticker
Implements the ull_sync_iso_setup function which starts the
ticker for ISO sync. Furthermore, ll_big_sync_terminate
will not stop the ticker as well.

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

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

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

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-12-20 13:35:58 +01:00
Joakim Andersson
cc470a2bd6 Bluetooth: host: Use smaller alignment for slab.
The slabs in ATT are using a slab alignment of 16, when only
4 is required on 32-bit.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-18 10:29:59 +01:00
Joakim Andersson
adeca565f8 Bluetooth: host: Use uintptr when checking for valid index
Align bt_le_per_adv_sync_get_index, bt_conn_index and
bt_le_ext_adv_get_index in use of uintptr_t.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek
f5d3a637a4 Bluetooth: controller: Use proper phy when initializing slave conn
Connection created from extended advertising instance uses the same phy
as on secondary channels.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek
384b64508c Bluetooth: controller: Use proper channel sel algorithm
Connections created from extended advertising instance always use CSA2.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek
6c8c97a26e Bluetooth: controller: Use proper transmitWindowDelay for slave
transmitWindowDelay is either 2.5ms or 3.75ms when AUX_CONNECT_REQ is
used (for 1M/2M and Coded respectively). It also uses the same unit
as transmitWindowOffset (1.25ms) so we can just simply add both.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek
68723274da Bluetooth: controller: Use decoded AdvA/TargetA for conn ind helper
The same helper will be used for legacy and extended advertising so we
better pass AdvA and TargetA directly instead of complete advertising
PDU. This is because those fields are at different locations in legacy
and extended advertising PDUs so caller can figure them out.

Also, we can now check for directed advertising using TargetA since it
will be only supplied for such advertising (NULL otherwise).

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Andrzej Kaczmarek
ffb320504c Bluetooth: controller: Add public helper to process connection ind
We will use the same code for auxes so let's make it public.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Vinayak Kariappa Chettimada
a46d090328 Bluetooth: controller: Release blocking LF clock request
Release the LF clock requested in blocking mode used to wait
to settle, which has already been asynchronously requested.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-17 11:24:19 +01:00
Vinayak Kariappa Chettimada
da18345b08 Bluetooth: controller: nRF5x: Fix lll LF clock wait
Fix lll_clock_wait function to wait for LF clock to settle
only once after power up.

Regression introduced in commit 2b4763076e ("bluetooth:
controller: Adapt to onoff clock control").

Fixes #30480.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-17 11:24:19 +01:00
Vinayak Kariappa Chettimada
35c397fc46 Bluetooth: controller: Remove unused lll scan struct member
Remove the unused LLL scan context struct member,
conn_ticks_slot.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-17 11:23:36 +01:00
Vinayak Kariappa Chettimada
6f22ac2851 Bluetooth: controller: Cleanup included header files
Clean up included header files, remove including
zephyr/types.h and other deprecated or redundant
header files.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-17 11:23:18 +01:00
Vinayak Kariappa Chettimada
17c006ce4a Bluetooth: controller: Add extended scan filter duplicates
Added implementation to filter out duplicates in generated
extended advertising reports.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-17 11:23:03 +01:00
Lingao Meng
5b11c053ef Bluetooth: Mesh: Fixes Friend Queue store message
If the SRC field of the received message is a unicast
address of an element of the Low Power node, then the
message shall not be stored in the Friend Queue.

Otherwise, lpn will discard this message, eventually
it breaks friendship.

Fixes: #30657

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-12-16 14:27:12 +01:00
Joakim Andersson
39e14580e9 Bluetooth: controller: Validate disconnect reason in disconnect command
Validate the disconnect reason in the disconnect command, according
to the the core specification.

7.1.6 Disconnect command:
Authentication Failure error code (0x05), Other End Terminated Connec-
tion error codes (0x13 to 0x15), Unsupported Remote Feature error code
(0x1A), Pairing with Unit Key Not Supported error code (0x29) and Unac-
ceptable Connection Parameters error code (0x3B).

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-15 11:20:34 +01:00
Joakim Andersson
9205fe0a3a Bluetooth: host: Return error code if disconnect has invalid parameters
Return the error code from the disconnect command to the application
when an invalid disconnect reason has been provided.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-15 11:20:34 +01:00
Vinayak Kariappa Chettimada
62cb9aedc4 Bluetooth: controller: Clean up direction finding Kconfig
Simplify selection of direction finding related Kconfig.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-14 11:23:26 +01:00
Piotr Pryga
1283b136e7 Bluetooth: controller: ull_df: Fix compilation warnings
Remove unused functions to fix compilation warninigs.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2020-12-14 11:23:26 +01:00
Piotr Pryga
307ac64374 Bluetooth: controller: Add set connectionless CTE TX parameters
Add implementation of HCI_LE_Set_Connectionless_CTE_-
Transmit_Parameters command in HCI.
Add implementation of command handling in controller.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2020-12-14 11:23:26 +01:00
Trond Einar Snekvik
2e3de6c5f8 Bluetooth: Mesh: LPN non-low power establishment set state
Sets the LPN state to WAIT_UPDATE when waiting for the initial poll
response when disabling LPN_ESTABLISHMENT. Previously, the LPN node
would stay in the wait offer state even after the offer was processed,
which led to it aborting the friend establishment completely if it
failed to receive the first poll.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-12-14 11:21:41 +01:00
Trond Einar Snekvik
040b027e00 Bluetooth: Mesh: Check LPN credentials before establishment
While the friend node considers the friendship established as soon as it
sends the friendship offer, the LPN only considers the friendship
established once it receives the first update after its poll. This
update is encrypted with the friendship credentials, which aren't
available, as they're protected by an if (lpn_established()) check.

Changes the check to lpn_waiting_update(), which makes the LPN check its
friendship credentials only when it's expecting a response to a poll
message. This is the only time the friend will send messages encrypted
with the friendship credentials.

This is a regression from #28511.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-12-14 11:21:41 +01:00
Trond Einar Snekvik
a0bb080f8a Bluetooth: Mesh: Set LPN credentials on friend_req
Explicitly sets the LPN credentials when sending a friend request.

This fixes a regression from #28511.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-12-14 11:21:41 +01:00
Jonathan Rico
21311c8bc5 Bluetooth: host: Ignore reserved SMP PDUs
Do not abort pairing when peer sends a SMP command with an opcode
reserved for future use, as per spec.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2020-12-14 11:21:24 +01:00
Jonathan Rico
98584a4bbc Bluetooth: host: Add keypress notification SMP handler
Add a dummy SMP command handler for keypress notification, that does
nothing (yet). This allows the next commit to work properly.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2020-12-14 11:21:24 +01:00
Joakim Andersson
a7fd4eab5c drivers: counters: Fix TIMER0 and RTC0 with Bluetooth controller
Fix TIMER0 and RTC0 being selectable when using out-of-tree Bluetooth
controller.
Generalize the Kconfig to have the features that use the HW peripheral
select them as reserved to make the dependencies more manageable.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-13 19:25:49 -05:00
Pavel Vasilyev
347a1ab19f Bluetooth: Mesh: Make access packet sizes defines public
This commit makes BT_MESH_*_SDU_MAX macros public so that applications
can use them.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2020-12-12 14:15:47 +02:00
Pavel Vasilyev
12bcf652e6 Bluetooth: Mesh: Make address defines public
This commit makes BT_MESH_ADDR_IS_* macros public so that applications
can use them.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2020-12-12 14:15:47 +02:00
Lingao Meng
f105455ebe Bluetooth: Mesh: Fix overflow of ivu_duration value
Bluetooth Mesh require minimum limit time to enter iv update
state or return to iv nornal state.

For Zephyr bluetooth mesh implementation, use`ivu_duration`
type `uint8_t` to represent current time, but if the time is
more than 255 hours, there will be problems due to the
overflow of 8-bit unassigned variables.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-12-11 09:03:05 -05:00
Trond Einar Snekvik
040b14366e Bluetooth: Mesh: Pull all function calls out of the K_MSEC macro
The K_MSEC macro evaluates its argument twice, which causes double
evaluation of some function calls in the mesh stack.

This removes all instances of function calls inside K_MSEC macros in the
mesh stack.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-12-10 12:15:04 -05:00
Kamil Piszczek
ac88b86179 bluetooth: services: add tps service
Added Transmit Power Service implementation.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2020-12-10 13:33:12 +01:00
Kamil Piszczek
fd8d03bd8b bluetooth: conn: add api for getting tx power level
Added a new Bluetooth API that can be used to read the current and
maximum transmit power level of the radio. The reading operation is
performed over HCI.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2020-12-10 13:33:12 +01:00
Rubin Gerritsen
a8bbe4d1db bluetooth: host: Disallow directed adv options on undirected adv
Previously, if the peer address was not set, the host would
do undirected advertising even if the application applied
options only applicable to directed advertising.

Adding this additional parameter validation reduces the confusion
of application developers when they have configured something wrong.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-12-10 14:32:51 +02:00
Lingao Meng
aea9adfc89 Bluetooth: Mesh: Fixes LPN poll timeout gradually grow
`POLL_TIMEOUT_MAX` should use `CONFIG_BT_MESH_LPN_POLL_TIMEOUT`
instead of `CONFIG_BT_MESH_LPN_INIT_POLL_TIMEOUT`. The described
algorithm to grow the poll timeout implemented in function
poll_timeout does not work with this implementation.

It's a regression in 3b4d58a
Bluetooth: Mesh: optimize performance for lpn node

Fixes: #30338

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-12-10 14:04:19 +02:00
Thomas Ebert Hansen
f0f25cfc32 Bluetooth: controller: Fix CUI/CPR lock during TO
Release the CUI/CPR lock if the connection owning the lock is
terminated.

This can happen if a device performing a CUI/CPR procedure gets a LSTO
before the procedeure completes or the procedure itself TO.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2020-12-10 12:58:35 +01:00
Lingao Meng
779fd135f3 Bluetooth: Mesh: Fixes wrong app_key_idx parameters
`app_key_del` first param should be key_app_idx,
not key_net_idx.

The effect is that app_key_del is broken.

It's a regression in eca014115
Bluetooth: Mesh: Isolate cryptographic material

Fixes: 30468

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-12-10 12:58:20 +01:00
Trond Einar Snekvik
81bf99145a Bluetooth: Mesh: Extended advertising support
Adds support for extended advertiser commands in the mesh. This doubles
throughput for common packet sending, and significantly improves timing
accuracy for the Friend and Low Power features.

The proxy module's advertisement control has been moved inside the adv
module to abstract away the different advertiser modes.

The extended advertiser mode does not need an advertising thread to
operate, and ends up with a net reduction in RAM usage.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-12-09 12:57:59 +02:00
Andy Ross
ea7ffbde7d subsys/bluetooth: Add missing stdint.h include
This tiny header uses non-builtin types but includes no headers that
would define them.  Recent header motion seems to have exposed a case
where this file can get built before its dependencies are included.
Add the header directly.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
0c15627cc1 lib: Remove sys_mem_pool implementation
This has been replaced by sys_heap now and all dependencies are gone.
Remove.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Vinayak Kariappa Chettimada
3f7b4d2877 Bluetooth: controller: Fix cond. compile of conn window offset calc
Fix missing conditional compilation of connection window
offset calculations.

Regression introduced in commit 467173a56646 ("Bluetooth:
controller: Fix incorrect initiator window offset").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-07 15:25:39 -05:00
Andrzej Kaczmarek
f0352500b3 Bluetoth: controller: Fix memory corruption in RPA refresh
memcpy() could overwrite memory adjacent to "pdu" due to invalid
copy size.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-07 13:59:55 +01:00
Morten Priess
392e044548 Bluetooth: controller: Fix ull_conn LSTO for must_expire
When CONFIG_BT_CTLR_CONN_META is enabled and the ticker "must_expire"
feature is used, collisions may cause incorrect decrement of the
supervision_expire counter, resulting in a too early link supervision
timeout.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-12-07 13:36:17 +01:00
Vinayak Kariappa Chettimada
b19747ee11 Bluetooth: controller: Fix incorrect initiator window offset
Fix incorrect initiator window offset used when in continous
initiator scanning. Calculated window offset to free time
space after existing central connections is not decremented
correctly when there is change in window at every initiator
scan interval.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-07 11:41:37 +01:00
Vinayak Kariappa Chettimada
0db7e5afb8 Bluetooth: controller: Fix corruption of footer auto-variable
Fix corruption of ftr auto-variable due to reuse to insert
new node rx into the received auxiliary PDU chain, which can
cause corrupt reference used later in the implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-07 11:41:29 +01:00
Vinayak Kariappa Chettimada
e6911bc06c Bluetooth: controller: Fix Coded PHY S2 S8 coding use
Fix PHY Update control procedure to accept the preferred Tx
coding options (S2 or S8) requested even if there is no
actual PHY change happening on procedure completion.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-04 23:08:51 -05:00
Andrzej Kaczmarek
e9cece87bb Bluetooth: controller: Add definitions for AdvA and TargetA offsets
Both AdvA and TargetA have constant offset in extended header so it
makes sense to have dedicated definitions for those numbers.
AdvA is always placed at the beginning on extended header while TargetA
follows AdvA directly. There are no PDUs without AdvA and with only
TargetA.

Offsets of other fields depends on extended header contents and thus
are non constant.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-04 23:08:15 -05:00
Andrzej Kaczmarek
99226e1e95 Bluetooth: controller: Add ext_hdr member to pdu_adv_com_ext_adv
'ext_hdr' member only covers extended header part of 'ext_hdr_adv_data'
and with addition of 'data' member to 'pdu_adv_ext_hdr' those can be
used to quickly access both extended header flags and data directly
from 'pdu_adv' without need for extra local variables and casts.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-04 23:08:15 -05:00
Andrzej Kaczmarek
def072ea65 Bluetooth: controller: Rename pdu_adv_hdr to pdu_adv_ext_hdr
pdu_adv_hdr name is quite confusing since it suggests some generic
header for advertising PDUs while this in fact is extended header
which is a part of common extended advertising payload and only applies
to extended advertising PDUs.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-04 23:08:15 -05:00
Andrzej Kaczmarek
014eb0ddf8 Bluetooth: controller: Rename ext_hdr_adi_adv_data
The 'adi' part of that member name does not make sense since ADI is
already part of extended header, so we only have 'extended header' and
'advertising data'.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-04 23:08:15 -05:00
Andrzej Kaczmarek
85adca4be3 Bluetooth: controller: Use proper handle in advertising events
If handle mapping is enabled, we need to use proper advertising set
handle in HCI event.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-04 16:31:44 -05:00
Andrzej Kaczmarek
77fd7fdbd7 Bluetooth: controller: Initialize scan rsp only for legacy adv
When legacy set is configured we need to make sure scan response is
properly initialized with empty data. For extended sets we should not
touch scan response on configure since data for those sets have to be
set explicitly, e.g. we cannot enable scannable advertising set if no
data was set.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-04 17:44:13 +01:00
Andrzej Kaczmarek
e4c39d6e19 Bluetooth: controller: Fix AdvA/TgtA for extended adv PDUs
AdvA in extended advertising PDUs was only set if random address was
used. This patch enables proper support for AdvA/TgtA in those PDUs
also with LL Privacy enabled.

On enable, we always update advertising PDU (i.e. ADV_IND, ADV_EXT_IND
or ADV_AUX_IND, depending on advertising set parameters) as well as
scan response PDU.

On RPA timeout, we simply copy old PDU as-is and update AdvA in new
PDU, since both PDUs are exactly the same (except AdvA) so no need to
recreate it step-by-step.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-04 17:09:46 +01:00
Emil Gydesen
b527f80f0f Bluetooth: controller: Guard ll_adv_iso_by_hci_handle_* functions
Guards the functions with CONFIG_BT_CTLR_HCI_ADV_HANDLE_MAPPING
and added a non-HCI inline function for them.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-04 17:09:33 +01:00
Emil Gydesen
2c67c29fd4 Bluetooth: controller: Remove empty BIS packet tx from ULL
The empty BIS packet should be enqueue and handled in the LLL.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-04 17:09:33 +01:00
Emil Gydesen
47e716ba83 Bluetooth: controller: removed node_rx for big create/terminate
Removed the node_rx argument for the BIG create/terminate
functions. The event should not be sent right after the
command, but needs to wait for transmissions of
empty BIS packets or BIG terminate indications.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-04 17:09:33 +01:00
Emil Gydesen
b32af6a643 Bluetooth: controller: ll_big_create add check if handle already created
Adds a check to verify that the BIG handle isn't already allocated.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-04 17:09:33 +01:00
Emil Gydesen
146fd961ef Bluetooth: controller: ull_adv_iso merge unknown adv id check
Merges the 3 checks for checking valid adv when creating a big.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-04 17:09:33 +01:00
Emil Gydesen
9c9253db5f Bluetooth: controller: Move ISO tx functionality to ull_iso.c
Moves the ISO tx pool and functions from ull_adv_iso.c to
ull_iso.c as the pool and functions will be shared between
BIS and CIS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-04 17:09:33 +01:00
Emil Gydesen
e1aa633e67 Bluetooth: controller: Rearrange functions in ull_adv_iso.c
Rearranged the functions so the order of functions match
the common pattern in other ULL files.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-04 17:09:33 +01:00
Emil Gydesen
41fe6d72a1 Bluetooth: controller: Implements BIG terminate command
Implements the BIG terminate command that terminates a
BIG and returns the appropriate events.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-04 17:09:33 +01:00
Emil Gydesen
339b9b8df5 Bluetooth: controller: BIG create sends empty BIS PDUs (ULL)
When a BIG is create, it will now start sending empty BIS PDUs;
at least from an ULL perspective, as the LLL support is still
missing.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-04 17:09:33 +01:00
Emil Gydesen
5a512fbe2f Bluetooth: controller: Implements ULL handling for BIG create command
Implements handling of the BIG create command in the upper link layer.
Does not yet handle sending any BIS events.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-12-04 17:09:33 +01:00
Vinayak Kariappa Chettimada
1d63c81033 Bluetooth: controller: Fix Extended Scanning on Coded PHY
Fix Extended Scanning on Coded PHY, auxiliary PDUs on Coded
PHY where not received due to redundant conditional code
only applicable in connection role being copy-pasted during
the development of Extended Scanning feature.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-03 13:54:25 -05:00
Vinayak Kariappa Chettimada
d6a3a0a05e Bluetooth: controller: Use memmove to copy overlapping memory
Use memmove to copy overlapping memory when populating the
Common Extended Advertising Header Format in the advertising
PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-03 13:54:25 -05:00
Vinayak Kariappa Chettimada
6cc7278b8b Bluetooth: controller: Fix maximum PDU len configuration
Fix maximum PDU len configuration when advertising and/or
scanning on primary channels.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-03 13:54:25 -05:00
Piotr Pryga
98b11ee95c Bluetooth: host: Fix data type of advertising set handle
Change type of advertising set handle to 8 bit to comply with
Bluetooth Core spec. type.
Fixes wrong usage of adv. set handle variable in function
bt_le_per_adv_set_param.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2020-12-03 14:53:37 +02:00
Joakim Andersson
180099f9ff Bluetooth: host: Remove irq_lock around connection lookup
Remove irq_lock around connection lookup, this is no longer needed
now that the lookup functions always have a valid reference.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-03 13:52:02 +01:00
Joakim Andersson
4350021f09 Bluetooth: host: Make connection lookup functions thread-safe
Make the connection lookup functions thread-safe by re-using the
bt_conn_ref returning NULL mechanism and keeping a valid reference.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-03 13:52:02 +01:00
Joakim Andersson
fae964c008 Bluetooth: host: Make bt_conn_ref return NULL if the ref count is zero
Make bt_conn_ref return NULL if the reference count has reached zero.
This makes it possible to re-use bt_conn_ref internally to re-use the
reference count mechanism to check if the reference is in use.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-03 13:52:02 +01:00
Andrzej Głąbek
7ee994af0f bluetooth: controller: nrf: Provide info about used DPPI resources
Use common definitions of HAL_USED_PPI_CHANNELS and HAL_USED_PPI_GROUPS
macros that will provide (through z_bt_ctlr_used_nrf_ppi_* variables)
information about either PPI or DPPI (depending on the SoC) resources
used by the Bluetooth controller.
Update also the hal_nordic module revision, to make the related nrfx
allocator aware of those reserved DPPI resources.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-12-02 16:44:40 +01:00
Andrzej Głąbek
1f6f383481 bluetooth: controller: nrf: Clean up a bit radio_nrf5_ppi.h
Remove no longer needed definition of NRFX_PPI_CHANNELS_USED_BY_PWM_SW
(after recent changes in the nrf_hw_models models, also for simulated
nRF boards the nrfx_glue.h file is processed, so this symbol is always
defined).
Remove also a couple of *_PPI_x_INCLUDE macros, to make the code a bit
clearer and to avoid things like a build assertion (also removed here)
that checks if HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_0_INCLUDE is indeed
defined as BIT(HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(0)).

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-12-02 16:44:40 +01:00
Asger Munk Nielsen
fbee6cc933 Bluetooth: controller: Create HCI stubs for CIG/CIS and ISO
Put infrastructure for the following HCI commands/events in place:
* LE Read ISO Link Quality command
* LE Read ISO TX Sync command
* LE Set Host Feature Command

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2020-11-30 15:49:30 +01:00
Lingao Meng
1b65fd066f Bluetooth: Mesh: Fix Friend node estalished
Since first poll request send by lpn use friend security
credentials, so, friend nodes should be able to decrypt with
friend security, even if they have not yet established a friendship.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-11-30 12:32:37 +02:00
Lingao Meng
084574b470 Bluetooth: Mesh: Fix Friend node handle Key update
When friend node key refresh phase to stage_1, there
are need to add friend update message to friend queue,
but, when friend KR phase to stage_2, must add friend
update to queue.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-11-30 12:32:37 +02:00
Lingao Meng
325288d531 Bluetooth: Mesh: Fix friend node cache message
Friend node cache segment message for lpn, message with
sequence number can't change, since could cause lpn replay
attack.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-11-30 12:32:37 +02:00
Wolfgang Puffitsch
6aa16e01dd Bluetooth: controller: hci: Fix naming for ISO path setup parameters
Fix field names of bt_hci_cp_le_setup_iso_path in le_setup_iso_path to
make CIS central/periphal compile and adjust parameter names for
ll_setup_iso_path accordingly.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-11-28 07:36:16 -05:00
Vinayak Kariappa Chettimada
8bf3ee9f98 Bluetooth: controller: Fix skipped single-shot ticker failure callback
A single-shot ticker in requested state beyond the elapsed
duration or skipped due to collision shall generate an
operation callback with failure status.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-26 15:47:02 +01:00
Morten Priess
2d0107ab27 Bluetooth: controller: Fix ticker collision update race
In the case where a BLE connection ticker node collides and does not
trigger a callback to ULL, and at the same time the same node receives a
ticker update request, the update causes the node to be scheduled for
execution a second time. This has the consequence of event_counter going
out of sync, and BLE connection is ultimately lost.

The solution is to mark collsions and re-scheduled nodes as expired, and
use the increased lazy count to identify its state instead of req/ack.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-11-26 15:47:02 +01:00
Wolfgang Puffitsch
1547108b19 Bluetooth: controller: HCI commands to read codecs and controller delay
Implement HCI commands to read information about supported codecs and
controller delay.
* Read Local Supported Codecs command (v1 and v2)
* Read Local Supported Codec Capabilities command
* Read Local Supported Controller Delay command

The following functions are implemented as "weak" symbols and should
be overridden to fill in vendor-specific information into the above
commands.
* hci_vendor_read_std_codecs
* hci_vendor_read_vs_codecs
* hci_vendor_read_codec_capabilities
* hci_vendor_read_ctlr_delay

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-11-26 15:46:17 +01:00
Wolfgang Puffitsch
9437a6a08d Bluetooth: hci: Add definitions for codec and controller delay info
Add defines and structs for reading information about supported codes,
codec capabilities and controller delays. Return parameter structs for
commands that return multiple variable-length fields only model the
fixed-length fields to minimize inconsistencies.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-11-26 15:46:17 +01:00
Morten Priess
18c01ecae8 Bluetooth: controller: Make random force on lost anchor configurable
Legacy functionality in ull_conn will force scheduling of a connection
which has missed an anchor point due to lost RX. This kicks in either
for previously skipped events (latenzy_event != 0) or at random
depending on the randomness of the AA bit pattern.

This behavior is good at ensuring that a connection with errors or
aborted RX gets prioitized, and helps break locked round-robin
patterns with lost sync, but it also breaks the predictability of
the round-robin ticker scheduling.

With "must_expire" enabled, this feature also kicks in for scheduling
collisions, which may not be desirable.

This commit adds a configuration flag, BT_CTLR_CONN_RANDOM_FORCE, which
is default enabled (legacy behavior).

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-11-26 13:51:15 +01:00
Vinayak Kariappa Chettimada
b7976e5633 Bluetooth: host: Fix uninitialized periodic interval parameter
Fix missing initialization of periodic interval value in
advertising report info structure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-26 13:50:03 +01:00
Joakim Andersson
8d3b9bae3b Bluetooth: host: Make acl_data extension of bt_buf user data explicit
Clarify that the acl_data struct includes the bt_buf type as the
first variable in the user data struct.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-11-26 13:15:03 +01:00
Joakim Andersson
431dd9f25b Bluetooth: host: Refactor out buffer handling to new file
Refactor out implementation of functions defined in buf.h to its own
source file buf.c

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-11-26 13:15:03 +01:00
Joakim Andersson
4978c19c05 Bluetooth: host: Refactor out address handling to new file
Refactor implementation of functions defined in addr.h to its own
source file addr.c.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-11-26 13:15:03 +01:00
Piotr Pryga
e54d2a7740 Bluetooth: host: Add HCI set conn CTE TX params wrapper function
Add implementation of a wrapper for HCI_LE_Set_Connection_-
CTE_Transmit_Parameters command.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2020-11-26 13:14:17 +01:00
Piotr Pryga
2589b7ace2 Bluetooth: controller: hci: Add set connection CTE transmit params
Add implementation of HCI_LE_Set_Connection_CTE_Transmit_Parameters
for Bluetooth 5.1 Direction Finding.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2020-11-26 13:14:17 +01:00
Piotr Pryga
0285903aee Bluetooth: controller: Add Direction Finding specific KConfig
Add separated Kconfig file for Bluetooth 5.1 Direction Finding.
Enable controller support for:
 - transmission of CTE
 - 2us antenna switching
 - 1us antenna switching
if build for nRF52833 SOC.
Add HAS_HW_NRF_RADIO_BLE_DF to nrf52833 SOC configuration.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2020-11-26 13:14:17 +01:00
Piotr Pryga
57b55d0fad Bluetooth: controller: Add read antenna information HCI command
Add partial implementation for handling Bluetooth 5.1 Direction
Finding HCI command HCI_LE_Read_Antenna_Information to controller
Upper Link layer.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2020-11-26 13:14:17 +01:00
Piotr Pryga
14890c8eb6 Bluetooth: host: Add read antenna information HCI command
Add Bluetooth 5.1 Direction Finding HCI command:
HCI_LE_Read_Antenna_Information handling to Host.
Add wrapper function to handle send the command
and receive response from Controller.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2020-11-26 13:14:17 +01:00
Trond Einar Snekvik
b0f83d387a Bluetooth: Mesh: Only block mod_sub if status was requested
Adds a cli_reset to mod_sub if no status response was requested. This
adds a non-blocking mode to the mod_sub calls, matching the behavior of
other cfg_cli functions.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-26 13:04:04 +01:00
Lingao Meng
fe7eda6ac8 Bluetooth: Mesh: Permit kr phase 0x00 to 0x03
MESH/NODE/KR/BI-01-C
Permit kr phase 0x00-->0x03

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-11-26 12:21:09 +02:00
Lingao Meng
3d55080bf3 Bluetooth: Mesh: Fixes missing recv net_idx copy to context
Missing copy net_idx to ctx, this cause tx subnet not found
or different with rx subnet, when rx subnet net_idx not zero.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-11-26 12:21:09 +02:00
Peter Bigot
cd2a5dd612 bluetooth: mesh: avoid improper access to internal structures
Nothing in the API description the delayed work structure sanctions
direct reference to internal fields.  Do not assume that a delayed
work item can be submitted without delay by invoking k_work_submit()
with a reference to the contained work item.  Instead submit with the
delayed API and no wait.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-24 13:04:48 +02:00
Vinayak Kariappa Chettimada
27529e0c0d Bluetooth: controller: Fix periodic sync conditional compilation
Fix Periodic Advertising Synchronization conditional
compilation to allow Extended Scanning feature without
Periodic Advertising Synchronization feature enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-23 17:01:50 +01:00
Vinayak Kariappa Chettimada
64874168cb Bluetooth: controller: Fix extended adv/sync report buffer leak
Fix node rx buffer leak if extended advertising and/or
periodic sync reports are masked out by the host.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-23 17:01:50 +01:00
Vinayak Kariappa Chettimada
ab82d8e158 Bluetooth: controller: Minor readability different variable use
Use an explicitly named variable to convey auxiliary pointer
present in the PDU chain.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-23 17:01:50 +01:00
Vinayak Kariappa Chettimada
283a30875b Bluetooth: controller: Add code comments for ext adv report
Added code comments to explain the reasons to drop
incomplete advertising and sync report.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-23 17:01:50 +01:00
Vinayak Kariappa Chettimada
d80d79e7f9 Bluetooth: controller: Use HCI defines for constants
Use HCI defines for PHY, and RSSI constants.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-23 17:01:50 +01:00
Vinayak Kariappa Chettimada
20939b7b11 Bluetooth: controller: Periodic Advertising Report generation
Added implementation for LE Periodic Advertising Report
event generation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-23 17:01:50 +01:00
Vinayak Kariappa Chettimada
5b62fae902 Bluetooth: controller: Fix Extended Advertising Report generation
Fix Extended Advertising Report generation that skipped
population of AD data when there was no extended header.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-23 17:01:50 +01:00
Asger Munk Nielsen
3df64a306b Bluetooth: controller: Create HCI stubs for CIG/CIS and ISO tests
Put infrastructure for the following HCI commands/events in place:
* LE Setup ISO Data Path command
* LE Remove ISO Data Path command
* Configure Data Path command
* LE Set CIG Parameters Test command
* LE ISO Read Test Counters command
* LE ISO Receive Test command
* LE ISO Test End command
* LE ISO Transmit Test command

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2020-11-20 10:56:51 +01:00
Vinayak Kariappa Chettimada
e9892c0000 tests: Bluetooth: shell: Fix PAST commands conditional compilation
Enclose PAST subscribe/unsubscribe test commands inside
CONFIG_BT_PER_ADV_SYNC and CONFIG_BT_CONN conditional
compilation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-20 11:39:13 +02:00
Vinayak Kariappa Chettimada
6578a366d5 Bluetooth: host: Fix Periodic Adv Set Info Transfer dependency
Periodic Advertising Set Info Transfer depends on Extended
Advertising and connections hence enclose the LE Periodic
Advertising Set Info Sync Transfer implementation inside
CONFIG_BT_PER_ADV and CONFIG_BT_CONN conditional
compilation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-20 11:39:13 +02:00
Vinayak Kariappa Chettimada
77d4ad65c5 Bluetooth: host: Fix PAST dependency on connections
Periodic Advertising Sync Transfer depends on connections
hence enclose the LE Periodic Advertising Sync Transfer
Received Event code inside CONFIG_BT_CONN conditional
compilation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-20 11:39:13 +02:00
Joakim Andersson
34e66db776 Bluetooth: host: Fix different endian in comparison
Fix the debug key-set comparison for debug keys comparing the
generated key in big-endian format against the debug private
key in little-endian format.

Fix this by converting the private key to big-endian format for
convenience.

Use the _be suffix for all variables to make the mixing of the
endian formats easier to read.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-11-19 12:40:13 +01:00
Emil Gydesen
deac6d73c5 Bluetooth: controller: Removes guards ull_adv_sync_*
Two ull_adv_sync function declarations, ull_adv_sync_reset and
ull_adv_sync_init was guarded by a #if causing CI issues.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-19 12:36:23 +01:00
Emil Gydesen
6b72bed967 Bluetooth: Controller: Add common ULL ticker stop with mark function
The same code block for marking an object with
ull_disable_mark, stopping the ticker and then unmarking
the object appeared multiple places; often with a regression
bug where instead of unmarking it in case of error, it would
be "remarked".

This commit fixes the bug, and moves the functionality to
a common function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-19 12:36:14 +01:00
Emil Gydesen
071db25f66 Bluetooth: Controller: Adds missing ull_disable in ll_sync_terminate
A call to `ull_disable` was missing in the function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-19 12:36:14 +01:00
Lingao Meng
65395f30ec Bluetooth: Mesh: Fixes pb-adv segment recv
Wrong use of function `find_msb_set(~link.rx.seg)`,
uint8_t type is implicitly converted to uint32_t.
As a result, it always returns 32 instead of the
expected value, resulting in abnormal processing
of prov segment.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-11-19 13:28:28 +02:00
Lingao Meng
9cd34f8675 Bluetooth: Mesh: Fixes prov string log dump
Missing log_strdup around the string.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-11-19 13:28:28 +02:00
Lingao Meng
109d6d4d8c Bluetooth: Mesh: Fixes wrong prov pointer clear
The structure pointer was wrongly cleared before,
`bearer` and `role` in `bt_mesh_prov_link` structure
resulting in illegal pointer access.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-11-19 13:28:28 +02:00
Ilya Averyanov
d262b064a2 Bluetooth: shell: fix compilation
phy2str also used when CONFIG_BT_USER_PHY_UPDATE not only
when CONFIG_BT_OBSERVER

Signed-off-by: Ilya Averyanov <a1ien.n3t@gmail.com>
2020-11-19 13:28:06 +02:00
Lingao Meng
88f8c735a7 Bluetooth: Mesh: Fixes missing set virtual addr
Fixes missing virtual address set

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-11-19 13:23:48 +02:00
Lingao Meng
4fbce04372 Bluetooth: Mesh: Correction of missing beacon auth generation
When kr phase to `BT_MESH_KEY_REVOKED`, should also call beacon
authentication, since beacon flag has change(0x01-->0x00).

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2020-11-19 13:21:28 +02:00
Marcin Niestroj
8669709d1e Bluetooth: DIS: settings: select SETTINGS
DIS module builts fine when BT_DIS_SETTINGS is selected, but SETTINGS is
not. However no settings handlers are executed, just like with
BT_DIS_SETTINGS disabled, which might confuse user.

Select SETTINGS, so settings handlers are properly selected and executed
in runtime.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-11-19 13:18:16 +02:00
Marcin Niestroj
faabbb6809 Bluetooth: DIS: settings: drop dependency on BT_SETTINGS
Currently BT_DIS_SETTINGS and BT_SETTINGS are independent in
Kconfig. This seems fine, because BT_SETTINGS pulls a lot of
functionality, which is not really needed to implement DIS with values
configured in runtime (from settings subsystem).

Drop BT_SETTINGS conditional compilation and leave check on
BT_DIS_SETTINGS only.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-11-19 13:18:16 +02:00
Morten Priess
5a10f27f13 Bluetooth: controller: Make WL size configurable
In architectures supporting more than 8 WL entries, e.g. pure
software implementations, it is desirable to be able to increase the
WL size. This change increases the range to 1..16 for SOCs other than
nRF5x and OpenISA.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-11-17 20:03:00 +01:00
Vinayak Kariappa Chettimada
ef2ece82c0 Bluetooth: controller: openisa: Fix sanitycheck failures
Fix sanitycheck failures when building
samples/bluetooth/peripheral_hr for rv32m1_vega_ri5cy
platform.

Updates from nRF platform related to 255 byte AD data
support have been directly copied into openisa port to
fix build failures.

Relates to commit c2fc629dd2 ("Bluetooth: controller:
255 byte AD payload support").

Fixes #29967.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-17 19:47:27 +01:00
Vinayak Kariappa Chettimada
05ca10001e Bluetooth: controller: nrf: Fix sanitycheck failures
Fix sanitycheck failures covered by following tests:

`./scripts/sanitycheck -p nrf51dk_nrf51422 -T tests/bluetooth/init`

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-17 19:47:27 +01:00
Vinayak Kariappa Chettimada
b2b93871a3 Bluetooth: controller: Fix minor typo in comment
Fix minor typo in comment that was not caught by check
compliance stage in PR CI.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-17 19:47:27 +01:00
Thomas Ebert Hansen
002b579416 bluetooth: controller: Add vendor operations to TICKER_USER_THREAD_OPS
Allow vendor specific increase of user operation capacity for
THREAD, to support queuing additional ticker operations.

Relocate TICKER_USER_<XXX>_VENDOR_OPS to before TICKER_USER_<XXX>_OPS.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2020-11-17 19:37:39 +01:00
Vinayak Kariappa Chettimada
27dcc39494 Bluetooth: controller: Fix regression in central event close
Fix regression in connection radio event close in central
role introduced in commit 222dca5598

Fixes #29957.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-17 12:16:36 +01:00
Marek Pieta
3b4ead139f Bluetooth: controller: Fix TX power dependencies
Change adds missing TX power dependencies. nRF52833 and nRF52820 SoCs
also support higher TX power values.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2020-11-17 11:52:06 +02:00
Emil Gydesen
919ba04988 Bluetooth: host: Periodic advertiser list support
Adds support for using the periodic advertiser list.
This list allows the application to rely on specific
devices when creating periodic advertising syncs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-16 16:35:44 +01:00
Emil Gydesen
1dada244c1 Bluetooth: host: Periodic Advertising Sync Transfer
Adds support for the periodic advertising sync transfer
(PAST) feature, which allows a synced device, or an
advertiser, to transfer synchronization of a periodic
advertising train to a connected device.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-16 13:40:09 +01:00
Joakim Andersson
2cc4d8d95c Bluetooth: mesh: Fix use of deprecated scan parameter filter_dup
Fix use of deprecated scan parameter filter_dup.
Should have been changed to options as part of:
be57dfbe2a

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-11-13 16:49:28 -05:00
Vinayak Kariappa Chettimada
59888103d2 Bluetooth: controller: Fix AD data size overflow check
pdu->len is only 8 bits and CONFIG_BT_CTLR_ADV_DATA_LEN_MAX
can be upto 1650 bytes. Fix the implementation to use 16
bit auto variable to check AD data length overflow.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-13 09:56:53 +01:00
Vinayak Kariappa Chettimada
afff307645 Bluetooth: controller: Initial support for set periodic adv data
Add initial support for LE Set Periodic Advertising Data
command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-13 09:56:53 +01:00
Vinayak Kariappa Chettimada
92a942257d Bluetooth: controller: Fix Extended Advertising data population
Fix Extended Advertising Data population when there is no
Extended Header to be filled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-13 09:56:53 +01:00
Andrzej Kaczmarek
a17952237f Bluetooth: controller: Fix build error
.../ll_sw/nordic/lll/lll_scan.c: In function 'isr_tx':
.../ll_sw/nordic/lll/lll_scan.c:483:19: error: unused variable 'lll'
                                              [-Werror=unused-variable]
  483 |  struct lll_scan *lll = param;
      |                   ^~~
cc1: all warnings being treated as errors

This fixes https://github.com/zephyrproject-rtos/zephyr/issues/29968.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-13 00:02:12 +02:00
Andrzej Kaczmarek
273cb94c0d Bluetooth: controller: Resolve AdvA in ADV_EXT_IND properly
Since ADV_EXT_IND is received on primary channel, the AR is configured
to resolve AdvA in legacy PDU (assuming on 1M) and it will not resolve
AdvA properly. In such case, we should resolve AdvA manually in LLL.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-11 13:27:25 +01:00
Andrzej Kaczmarek
0316329db1 Bluetooth: controller: Add radio API to resolve addr via AAR
This allows to synchronously resolve any address using AAR. The AAR
has to be configured prior to calling this function.

The intended use for this function is to resolve AdvA in a PDU on
primary channel when AR was configured for different PDU type. That
means AR was configured to resolve in legacy PDU, but extended PDU
was received and we need to resolve AdvA manually. In such case, AAR
is already configured so just need to trigger it again with proper
ADDRPTR.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-11 13:27:25 +01:00
Andrzej Kaczmarek
de027edfb8 Bluetooth: controller: Configure AR for resolving in ext adv
This patch allows to configure AR for resolving AdvA in extended adv
PDUs. The extra 'flags' field provides a hint from caller on how to
setup AR:
- if legacy PDU is expected, AdvA is set after PDU header,
- if extended PDU is expected, AdvA is set with +2B offset due to
  common extended advertising header,
- if Coded PHY is used, AdvA is set with extra +5b offset due to CI and
  TERM1 fields.

Note that AUX_SCAN_REQ and AUX_CONNECT_REQ are also considered legacy
PDUs here since they are exactly the same as SCAN_REQ and CONNECT_IND.

If neither legacy nor extended PDU is specified, it's derived from PHY,
i.e. 1M means legacy, non-1M means extended. Since it is still possible
to receive different type PDU in such case, it's up to LLL to detect
this and resolve AdvA when RX is done.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-11 13:27:25 +01:00
Andrzej Kaczmarek
fb0c3dbaa4 Bluetooth: controller: Disable AAR PPI on AR reset
This was never disabled so would be triggered even if not explicitly
enabled.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-11 13:27:25 +01:00
Emil Gydesen
d911f99bfc Bluetooth: controller: guard NODE_RX_TYPE_USER with range value
Instead of guarding the NODE_RX_TYPE_USER cases with
CONFIG_BT_CTLR_USER_EXT we guard them with
CONFIG_BT_CTLR_USER_EVT_RANGE > 0 as that is the actual value that
enables/disables the NODE_RX_TYPE_USER values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-11 13:25:20 +01:00
Emil Gydesen
58eb76e06d Bluetooth: Controller: Change node_rx_type to auto incrementing enum
Instead of having explicit values for each entry in the enum that
has to be updated for each new entry (thus requiring manual work
which can also be error-prone), the enum will now be
self-incrementing, to make it easier and safer to add new
entries.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-11 13:25:20 +01:00
Emil Gydesen
8af767e28c Bluetooth: controller: Remove #ifdef for node_rx_type enum
Removed the #ifdef's for the node_rx_type enum. Since the
savings, they just make the enum harder to read.

Furthermore it will also ensure that all the enum values
will have the same value once the enum entries are no
longer manually defined.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-11 13:25:20 +01:00
Erik Brockhoff
b67233c6a4 bluetooth: controller: don't assert on rl disabled
Simply return 0 to indicate the deferred resolve was not accepted when
address resolve is not enabled

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2020-11-11 13:24:14 +01:00
Thomas Ebert Hansen
28a8582a49 Bluetooth: host: Fix endianness in conn. handle
Fix the endianness of the connection handle in the handler for
BT_HCI_EVT_REMOTE_VERSION_INFO.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2020-11-11 13:23:49 +01:00
Andrzej Kaczmarek
04a48d9ec2 Bluetooth: controller: Fix build without BT_CENTRAL
lll->conn is only defined valid when BT_CENTRAL is enabled.
Also ull_sched_mfy_after_mstr_offset_get is only used when BT_CENTRAL
is enabled.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-11 13:23:33 +01:00
Lingao Meng
7e302979f3 Bluetooth: Mesh: Fix DST field check when send
Add check for dst field in transport layer tx function.

Fixes: #29868

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-11-11 13:23:14 +01:00
Trond Einar Snekvik
a2aad2b3f8 Bluetooth: Mesh: Check TTL max value on transport TX
Adds check for TTL max in the transport send functions, and moves
setting of default TTL to transport.

Fixes #29855.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-11 13:22:34 +01:00
Joakim Andersson
d81197ff77 Bluetooth: shell: Fix shell scan option duplicate filtering options
Fix the shell always setting the filter duplicates option for active
scan.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-11-11 13:22:02 +01:00
Joakim Andersson
bd7a2fc395 Bluetooth: host: Change directed advertising to privacy-enabled peer
Change the advertising option that controls if the directed advertiser
will use an RPA or the identity address of the peer for the initiator
address.
This option currently has two issues:
 - It behaves differently if the privacy feature has been enabled,
   which can be confusing for application to use.
 - It cannot start a directed advertiser towards a peer that is not
   privacy-enabled and has distributed an IRK.

This commit includes the following changes:
 - When privacy has been enabled in order to advertise towards a
   privacy-enabled peer the BT_LE_ADV_OPT_DIR_ADDR_RPA option must now
   be set (same as when privacy has been disabled).
 - It is now possible to start a directed advertiser using the identity
   address of the peer when privacy-enabled.
 - When privacy has been enabled the advertising option combination
   of using the local identity address and an RPA as the initiator
   address is now disallowed and will return an error code.
   This is done because this combination did not actually work and would
   have used the identity address of the peer instead.
 - If the controller does not support controller-based privacy then
   using the option BT_LE_ADV_OPT_DIR_ADDR_RPA will return ENOTSUP
   because this behavior cannot be done with host-based privacy.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-11-11 13:22:02 +01:00
Andrzej Kaczmarek
904a421915 Bluetooth: controller: Disallow starting scannable adv w/o scan rsp
Scannable advertising set cannot be started without scan response data.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-11 13:20:40 +01:00
Andrzej Kaczmarek
7195ce6970 Bluetooth: controller: Allow to discard scan response data
Host can discard scan response data by setting empty data. We simply
set PDU length to 0 to indicate this, it will make future check easier.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-11 13:20:40 +01:00
Andrzej Kaczmarek
b08a0bd8a7 Bluetooth: controller: Fix LE Set Ext Scan Rsp Data restrictions
This fixes restrictions for setting/discarding scan response data to
mach spec.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-11 13:20:40 +01:00
Vinayak Kariappa Chettimada
701d524143 Bluetooth: controller: Fix memory alignment of PDU buffer reference
Align the PDU buffer reference in struct node_rx_pdu so that
node rx type specific parameters, like, terminate and sync
lost reason can be accessed without any memory alignment
issues.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 13:20:33 +01:00
Vinayak Kariappa Chettimada
d7d8ae7894 Bluetooth: controller: Use connection complete variable naming
Use the connection complete varaible naming to access
connection complete parameters.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 13:20:33 +01:00
Vinayak Kariappa Chettimada
a5b489e2fa Bluetooth: controller: Make conn cancel and sync cancel impl. consistent
Make the connection cancel and periodic advertising sync
create cancel implementation consistent.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 13:20:33 +01:00
Vinayak Kariappa Chettimada
92b2591558 Bluetooth: controller: Fix missing storage for sync cancel reason
Fix missing storage allocation in ll_sync_set structure for
storing the sync cancel reason.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 13:20:33 +01:00
Vinayak Kariappa Chettimada
be090f7b33 Bluetooth: controller: Fix maximum AC PDU payload size calcuation
Fix maximum Advertising Channel PDU payload size calculation
by including the Common Extended Advertising Payload Format
overload alongwith the AD data maximum size supported.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 12:28:05 +01:00
Vinayak Kariappa Chettimada
f677144f30 Bluetooth: controller: Remove unused defined in pdu.h file
Remove used constant macro defined in pdu.h file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 12:28:05 +01:00
Vinayak Kariappa Chettimada
09c5035359 Bluetooth: controller: Added comments related to AD data double buffering
Added inline comments explaining the implementation of AD
data PDU double buffering.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 12:28:05 +01:00
Vinayak Kariappa Chettimada
22ec1acacc Bluetooth: controller: Minor move code closer to locality of reference
Minor change to move code closer to locality of reference.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 12:28:05 +01:00
Vinayak Kariappa Chettimada
c842eef3ae Bluetooth: controller: Add semaphore to indicate free AD data buffers
Add semaphore implementation to indicate and wait for free
AD data buffers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 12:28:05 +01:00
Vinayak Kariappa Chettimada
dc02ebf5ed Bluetooth: controller: Release AD data on advertising set remove
Add implementation to release AD data PDU buffers on
advertising set remove.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 12:28:05 +01:00
Vinayak Kariappa Chettimada
5b396aaafb Bluetooth: controller: Use mfifo to return stale AD data PDU
Added implementation using mfifo to return stale AD data PDU
from LLL to Thread context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 12:28:05 +01:00
Vinayak Kariappa Chettimada
2be0d07543 Bluetooth: controller: Add Max. AD data buffers Kconfig option
Add Kconfig option to configure maximum number of buffered
AD data PDUs across enabled advertising sets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 12:28:05 +01:00
Vinayak Kariappa Chettimada
c2fc629dd2 Bluetooth: controller: 255 byte AD payload support
Add 255 byte AD payload support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-11 12:28:05 +01:00
Wolfgang Puffitsch
f68d7863e5 Bluetooth: controller: Create HCI stubs for CIG/CIS creation and removal
Put infrastructure for the following HCI commands/events in place:
* LE Set CIG Parameters command
* LE Remove CIG command
* LE Create CIS command
* LE Accept CIS Request command
* LE Reject CIS Request command
* LE CIS Established event
* LE CIS Request event

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-11-10 13:19:08 +01:00
Wolfgang Puffitsch
e5356595ca Bluetooth: controller: Introduce Kconfig options for CIS central/peripheral
Add Kconfig options to enable Connected Isochronous Stream central and
peripheral roles.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-11-10 13:19:08 +01:00
Jordan Yates
ffab099eb9 Bluetooth: add destroy callback to indication
Adds a `destroy` callback to the `struct bt_gatt_indicate_params` which
is used to signify to the application that the indication operation has
completed and the struct instance can be freed/destroyed.

This is required as the number of indication value callbacks that will
be triggered is not known by the caller when the `conn` parameter is
`NULL`.

Tracking when this callback should be run is mananged by a private
reference counter inside the struct.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-11-10 11:21:46 +01:00
Jordan Yates
170f17e0e7 Bluetooth: indication callback signature update
Update the signature of the `bt_gatt_indicate_func_t` callback type by
replacing the attr pointer with a pointer to the
`bt_gatt_indicate_params` struct that was used to start the indication.

This allows the callback to free the `bt_gatt_indicate_params` instance
if it was allocated from storage, while still allowing the
`bt_gatt_attr` value to be accessed through `params->attr`.

Allocating the `bt_gatt_indicate_params` instance from storage is
desirable as multiple indications can be queued, however each instance
must be valid until the callback is run.

Implements API update from #29357

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-11-10 11:21:46 +01:00
Joakim Andersson
f8956cfbc7 Bluetooth: L2CAP: Enable L2CAP dynamic channels without Enhanced CBFC
Allow application to enable L2CAP dynamic channels without support
for Enhanced Credit Based Flow Control (CBFC).

Since these are separate features in the qualification it should
be possible to qualify L2CAP connection oriented channels without
also having to qualify L2CAP enhanced credit based flow control.

The L2CAP/LE/REJ/BI-02-C conformance test will fail when enhanced CBFC
has not been selected in the ICS.

The lower tester expects that since the Enhanced CBFC is not supported,
the command L2CAP_CREDIT_BASED_CONNECTION_REQ should be met with an
L2CAP_COMMAND_REJECT_RSP and not an L2CAP_CREDIT_BASED_CONNECTION_RSP.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-11-09 11:25:10 +01:00
Trond Einar Snekvik
ad2fd44d7a Bluetooth: Mesh: Encapsulate feature config
Moves mesh feature configuration to a separate module, deprecating the
bt_mesh_cfg_srv structure. The initial values for the features should
now be enabled through KConfig, where new config entries have been added
for each feature.

This removes the upward dependency on the config server from the core
stack, and makes the config server a pure frontend for the configuration
states, as all spec mandated behavior around the feature states is now
encapsulated.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-09 11:23:34 +02:00
Trond Einar Snekvik
0dc9e5cd96 Bluetooth: Mesh: Move heartbeat to separate module
Encapsulates the Heartbeat state and functionality in a separate
heartbeat module, removing all manipulation of the heartbeat state from
the transport and config server modules.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-09 11:23:34 +02:00
Trond Einar Snekvik
b20a44ded8 Bluetooth: controller: Silence unused variable warning with non-AE
Places definition of lll under the ADV_EXT #ifdef in lll_adv.c:isr_tx,
to silence build warnings for non-AE builds.

Follow-up from #29753.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-05 11:10:22 -06:00
Andrzej Kaczmarek
dd5e9c4da1 Bluetooth: controller: Add common def for max AD size on legacy
This def can be used instead of hardcoding "31" everywhere.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-05 12:17:16 +01:00
Andrzej Kaczmarek
5166426940 Bluetooth: controller: Fix timings for non-1M PHY on advertising
We need to use actual phy wherever required to make sure radio delays
are calculated properly. This is especially important for LE Coded
since delays for that phy are significantly higher than on 1M and 2M.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-05 12:17:16 +01:00
Andrzej Kaczmarek
1df5897679 Bluetooth: controller: Verify AD length for legacy adv
We should not allow setting more than 31 bytes of AD on legacy
instances.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-05 12:17:16 +01:00
Andrzej Kaczmarek
5aab391f4b Bluetooth: controller: Update HCI supported cmds with ext adv
Return proper bitmask of supported commands when extended advertising
enabled.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-05 12:17:16 +01:00
Andrzej Kaczmarek
f2de6931de Bluetooth: controller: Remove redundant check
ull_adv_data_set() is only used for legacy advertising data (either via
legacy HCI command or as fallback for extended advertising set which
uses legacy PDUs) so there is no need to check for extended advertising.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-05 12:17:16 +01:00
Andrzej Kaczmarek
aec809e75e Bluetooth: controller: Remove redundant check
We handle secondary channel only for extended advertising sets, that
means we always have ADV_EXT_IND on primary channel so there is no need
to support non-ext PDUs here.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-11-05 12:17:16 +01:00
Trond Einar Snekvik
86c793af3f sys: util: Replace MIN(MAX(a, b), c) with CLAMP
Replaces all existing variants of value clamping with the MIN and MAX
macros with the CLAMP macro.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-05 12:12:17 +01:00
Trond Einar Snekvik
2fb56ba74d Bluetooth: Mesh: Account for ASZMIC in encrypt
The decision to set aszmic = 1 in the net_tx structure was made after
the variable was passed to the crypto context, creating a discrepancy
between the two when aszmic is 1.

Extracts transport encryption to a separate function.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-03 16:04:30 +02:00
Emil Gydesen
b0a99051f5 Bluetooth: shell: Avoid registering PA sync callbacks more than once
The PA sync callbacks would have been registered for each new
PA sync, which would cause the callbacks to be called multiple times
if multiple PA syncs were created.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-03 11:04:07 +01:00
Emil Gydesen
12ceb6c195 Bluetooth: host: Handle PA sync cancel event
The sync established event caused by a cancel by the host
was not properly handled. When cancelling the sync established
event is created, and the sync object should not be deleted
before that event is received.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-03 11:04:07 +01:00
Lingao Meng
5efe6ff887 Bluetooth: Mesh: Fix set friend_cred flag incorrectly
Only set friend_cred to true when friendship established and
use friend cred security material decryption successfully.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-11-02 12:47:36 +02:00
Trond Einar Snekvik
a878b36af0 Bluetooth: Mesh: Permit model walk from any model
Fixes bug where applications that disable model extensions end up in an
infinite loop, and adds support for walking model subtrees, as opposed
to forcing root to be unextended.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-02 12:46:45 +02:00
Vinayak Kariappa Chettimada
84096455ad Bluetooth: controller: Adv set terminated event on Directed Adv timeout
Add generation of Advertising Set Terminated event on High
Duty Cycle Directed Advertising Timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-30 15:55:57 +01:00
Vinayak Kariappa Chettimada
ad348337a5 Bluetooth: controller: Reduce use of ARG_UNUSED on auto variables
Reduce the use of ARG_UNUSED on auto variables and try to
use conditional compilation where appropriate.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-30 15:54:56 +01:00
Michał Narajowski
3908638bab Bluetooth: Mesh: Fix model tree walk procedure
`bt_mesh_model_tree_walk()` was too simplistic and did not track visited
nodes which caused it to fall into infinite loop. Moreover the double
next jump could skip a level causing depth value to be invalid.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-10-30 16:27:20 +02:00
Lingao Meng
0bcd66ac36 Bluetooth: Mesh: Fix build warning with Warray-bounds
../zephyrNew/subsys/bluetooth/mesh/prov.c: In function
'bt_mesh_prov_reset_state': ../zephyrNew/subsys/bluetooth/mesh
/prov.c:61:2⚠️ '__builtin_memset' offset [52, 292] from
the object at 'bt_mesh_prov_link' is out of the bounds of referenced
subobject 'dhkey' with type 'uint8_t[32]' {aka 'unsigned char[32]'}
at offset 19 [-Warray-bounds] 61 | memset(&bt_mesh_prov_link.dhkey, 0,

Fixes: #29634

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-10-30 10:59:55 +02:00
Luiz Augusto von Dentz
09e95a26a4 Bluetooth: ISO: Fix crash when channel has already been disconnected
If chan->conn is already NULL do not call bt_conn_unref as that will
likely cause a crash, also this make sure that if channel has been
disconnected using bt_iso_chan_disconnect it removes the channel from
connection list before setting the chan->conn to NULL.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-10-29 20:34:55 +02:00
Joakim Andersson
92deb9ddba Bluetooth: host: Document and check for disallowed directed advertising
Document and validate advertising parameters for the disallowed
advertising mode high duty cycle directed connectable advertising
using extended advertising PDUs.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-29 16:02:57 +02:00
Vinayak Kariappa Chettimada
f8889c1d87 Bluetooth: controller: Fix unused variable compiler warning
Fix unused variable compiler warning with asserts disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-29 14:31:38 +02:00
Joakim Andersson
5e999a3081 Bluetooth: ATT: Handle encrypt change event unrelated to current req
Fix issue where the encrypt change has an error code, but the
encrypt change request was unrelated to the current ATT request.

This lead to the current ATT transaction being interpreted as finished
an the ATT client would proceed with the next ATT request, which would
fail since the ATT client is now violating the ATT single transaction
rule.

Updated similar if statement checking for the opposite to improve
readability.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-29 14:28:40 +02:00
Lingao Meng
627ee1125b Bluetooth: Mesh: Remove bt_mesh_net_start
Move `bt_mesh_net_start` functionality to `bt_mesh_start`.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-10-29 14:17:09 +02:00
Trond Einar Snekvik
af5bd00d1c Bluetooth: Mesh: Move labels to transport
Moves the virtual address labels to the transport layer, disconnecting
them from the configuration server.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-10-29 14:14:43 +02:00
YanBiao Hao
c9be68532c Bluetooth: Mesh: Add Config Client API
The api is used to reset a node (other than a Provisioner) and
remove it from the network

Signed-off-by: YanBiao Hao <haoyanbiao@xiaomi.com>
2020-10-29 14:13:36 +02:00
Lingao Meng
1e9bd13c99 Bluetooth: Mesh: Fixes Relay to frnd_cred message
If low power node publish with unicast address other
than friend address, the friend node should relayed
this message to all network interface.

When Proxy feature enabled, message from gatt bearer should
relay to adv bearer even relay feature disabled.

Fixes: #29544

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-10-29 14:07:58 +02:00
Lingao Meng
5374245dd6 Bluetooth: Mesh: split prov.c into two separate modules
Currently all provisioning procedure into common source
files call `prov.c`, that will not compile separately.

Add `BT_MESH_NODE` to control whether nodes are supported
and device provisioning is supported, this will be used in
provisioner role.

Add more provisioner OOB authentication method.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-10-28 12:53:09 +02:00
Vinayak Kariappa Chettimada
b3c9565891 Bluetooth: controller: Remove redundant condition compile
Remove a redundant condition compile.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-26 17:40:08 +01:00
Vinayak Kariappa Chettimada
c74438cdfa Bluetooth: controller: Fix arguments unused without Extended Scanning
Fix arguments unused when not enabling Extended Scanning
which was introduced in
commit 0cef1e43c9 ("Bluetooth: controller: Extended
Scanning Coded PHY duration and period").

Fixes #29442.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-26 17:40:08 +01:00
Joakim Andersson
999a91e30d Bluetooth: host: Fix application conn param update not started
Fix application conn param update submitted before the timeout of
CONFIG_BT_CONN_PARAM_UPDATE has expired being ignored when
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-26 16:16:35 +02:00
Joakim Andersson
21b8e08caa Bluetooth: host: Rename update_work to deferred_work
Rename the update_work handler to deferred_work since this handler
is being multiplexed for different kinds of deferred work, not just
updating the connection parameters.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-26 16:16:35 +02:00
Joakim Andersson
77b11d6b0c Bluetooth: host: Move auto-initiation of peripheral conn param update
Move auto-initiation of the peripheral connection parameter update,
this handling would only submit the delayed work with the timeout once
all other auto initiated procedures had completed. This behavior means
that the delay would not be set on when the connection was established
but instead relative to the previous procedures.
Based on the connection interval used, the instant(s) used, and the
number of auto procedures this delay becomes indeterminate.

Submit the work once connected, the constraint that existed in the
zephyr link layer earlier about requesting only one control procedure
at a time has been removed.

This also brings all the handling of the timeout work to the connection
state handling, which makes it easier to track this behavior in code.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-26 16:16:35 +02:00
Joakim Andersson
f4888b1ff6 Bluetooth: host: Allow conn param update delay of 0 milliseconds
Allow the application to set a conn param update delay of
0 milliseconds.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-26 16:16:35 +02:00
Joakim Andersson
f2a23ee166 Bluetooth: host: Document peripheral bt_conn_le_conn_update behavior
Document the behavior of the bt_conn_le_conn_update API when the
local device is the peripheral role.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-26 16:16:35 +02:00
Lingao Meng
27739fcc43 Bluetooth: Mesh: Add queue_size and recv_win to lpn_cb
Add Queue Size and Receive Window information to lpn
callback function to notify upper layer to determine
currently friend node information, which may be used
in future.

Add Callback structure to notification application which friendship
has been changed.

Add function `bt_mesh_friend_terminate` let's app layer determine
terminate friendship manually.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-10-24 10:57:45 +03:00
Joakim Andersson
948615d247 Bluetooth: shell: Fix ifdef order in command inclusion
Fix ifdef in command inclusion, in practice this meant that
CONFIG_BT_LL_SW_SPLIT and CONFIG_BT_CTLR_ADV_EXT switched meaning.
Added blank lines so that the commands in shell/ll.c are more
easily visible as group.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-23 12:56:39 +02:00
Vinayak Kariappa Chettimada
28d6028127 Bluetooth: controller: Periodic Adv Sync on Coded PHY
Added implementation to be able to establish Periodic
Advertising Sync on Coded PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-23 12:56:13 +02:00
Joakim Andersson
d62aefe608 Bluetooth: Kconfig: Default BT_TINYCRYPT_ECC only when not supported
Introduce a support kconfig for controller ECDH command support.
Default to host ECDH emulation in combined host controller build
where the controller does not support these commands.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-22 16:12:26 +03:00
Trond Einar Snekvik
eca0141152 Bluetooth: Mesh: Isolate cryptographic material
This is a major refactoring of the handling of the cryptographic
material of both the network and transport layers. The aim is to
encapsulate the key object manipulation, and improve overall modularity.

Pulls Applications and Subnets out of the bt_mesh and into separate
modules, with static storage types on the data. This has several
side-effects:
- The Config Server no longer operates directly on the bt_mesh.subs and
  bt_mesh.apps lists, but goes through a public configuration interface,
  following the pattern set in #27908.
- All iteration through the keys is done through iteration APIs
- Key resolution on RX and TX is centralized.
- Changes to the keys triggers events the other modules can register
  handlers for.
- Friendship credentials are stored in the lpn and friend structures.

Part of #27842.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-10-22 14:36:02 +03:00
Luiz Augusto von Dentz
2811f0abf7 Bluetooth: shell: Allow passing more than one byte to gatt write
This makes it possible to pass different byte arrays to gatt write
making it usable to test attributes that take more than a single byte.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-10-22 13:33:57 +02:00
Luiz Augusto von Dentz
b4dceec686 Bluetooth: GATT: Don't start any work until the stack is initilized
This prevents any work to be submitted until the stack is initialized
thus avoiding pointless hash generation, etc, while initializing the
system.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-10-22 14:33:30 +03:00
Emil Gydesen
44f00358a6 Bluetooth: host: PA sync receive enable/disable
Adds support for enabling/disabling PA sync receive,
which allows applications to control when to receive data
while a sync is established.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-10-22 13:28:41 +02:00
Luiz Augusto von Dentz
6c67d3cb4b Bluetooth: conn: Fix not cleanup properly if ACL is disconnected
If an ACL connection is disconnected while there is an ISO connection
associated with it the ACL connection will not be cleanup properly as
the code attempt to cleanup the ISO connection and breaks without
proceeding to cleanup the ACL as well.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-10-22 14:26:55 +03:00
Emil Gydesen
c29f62e2b8 Bluetooth: host: Removed cb pointer from bt_le_per_adv_sync
The callbacks has been moved from being local to each
bt_le_per_adv_sync object, to being global. The
removal of the pointer in bt_le_per_adv_sync was
missing from that update.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-10-22 13:23:01 +02:00
Joakim Andersson
b2e56412a7 Bluetooth: shell: Fix shell build with out-of-tree controller
Fix shell build errors when building with combined host and controller
but the selected controller is not the in-tree zephyr controller, i.e
CONFIG_BT_CTLR=y, CONFIG_BT_LL_SW_SPLIT=n and cmd_scanx and others
are not defined.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-22 13:18:35 +02:00
Lingao Meng
4acfd5f6af Bluetooth: Mesh: Change the default value to Kconfig
Move default value of segment retransmit and timeout value
to Kconfig.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-10-22 14:13:49 +03:00
Vinayak Kariappa Chettimada
1bb4e6caa5 Bluetooth: controller: Use conversion macros for duration and period
Use conversion macros to convert Extended Scan duration and
period to radio event counts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Vinayak Kariappa Chettimada
0cef1e43c9 Bluetooth: controller: Extended Scanning Coded PHY duration and period
Added implementation to support simultaneous 1M and Coded
PHY Extended Scanning duration and period. Also, added
implementation to support update to duration and period of
an active scanning instance.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Vinayak Kariappa Chettimada
a5be61dede Bluetooth: controller: Fix the ll_scan_enable signature
Fix the ll_scan_enable interface signature, place duration
before period parameter to reflect the order as in the HCI
LE Set Extended Scan Enable command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Vinayak Kariappa Chettimada
bc34d06c82 Bluetooth: controller: Use defines in place of magic numbers
Use defines for Extended Scan duration, period and scan
interval units.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Vinayak Kariappa Chettimada
b3ac86f37f Bluetooth: controller: Extended Scan with duration and period
Added implementation for Extended Scanning with duration
and period parameters.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Vinayak Kariappa Chettimada
d91b441685 Bluetooth: controller: Revert ticker status check
Revert the added ticker status busy check.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Vinayak Kariappa Chettimada
896c20188a Bluetooth: controller: Fix scan done generation
Fix scan done to be generated when the window is closed
both under abort and graceful window close.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Vinayak Kariappa Chettimada
1bc2861dee Bluetooth: controller: Move scanning channel set implementation
Move the implementation to set scanning channel to
isr_window function where the next window is started,
instead of being at the abort of the previous continuous
window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Vinayak Kariappa Chettimada
9610467f5c Bluetooth: controller: Fix scanning flags reset
Fix scanning state and is_adv_ind flags to be common to both
isr_done and isr_window code path.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Vinayak Kariappa Chettimada
e1c2a14a98 Bluetooth: controller: Cond. compile related to extended scanning
Refactoring of conditional compilation related to extended
scanning with duration and period.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Dag Bjarvin
d22c2ec0ed Bluetooth: controller: Add periodic scanning
Start/stop scan according to period and duration
parameters.

Signed-off-by: Dag Bjarvin <Dag.Bjarvin@nordicsemi.no>
2020-10-21 12:44:38 +02:00
Vinayak Kariappa Chettimada
60caea58ee Bluetooth: controller: Rework handling of failure to start sync
Rework implementation handling the disable and the error
handling when failure to start Periodic Advertising
instance.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:28 +02:00
Vinayak Kariappa Chettimada
a3cdc01cd2 Bluetooth: controller: Fix missing auxiliary advertising start
Fix missing auxiliary channel advertising start when
starting Periodic Advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:28 +02:00
Vinayak Kariappa Chettimada
eccfe4916a Bluetooth: controller: Move ticker status wait
Move ticker status wait into adv_aux_start and
adv_sync_start functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:28 +02:00
Vinayak Kariappa Chettimada
acc371c86f Bluetooth: controller: Change indentation
Minor change to indentation of how adv and adv_aux interval
is calculated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:28 +02:00
Vinayak Kariappa Chettimada
0d6b17f7a1 Bluetooth: controller: Minor refactor to move ull_hdr_init
Minor refactor to move ull_hdr_init into adv_aux_start and
adv_sync_start functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:28 +02:00
Vinayak Kariappa Chettimada
a2ea8c4a93 Bluetooth: controller: Fix incorrect return value data type
Fix incorrect use of unint32_t instead of a sufficient
uint8_t for the returned HCI error code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:28 +02:00
Vinayak Kariappa Chettimada
f84dc5fe2a Bluetooth: controller: Decouple primary and secondary PDU update
Decouple updates to primary and secondary AD Data PDU such
that primary PDU changes can be committed on successful
scheduling of secondary PDU radio events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:28 +02:00
Vinayak Kariappa Chettimada
4b929aa34e Bluetooth: controller: Use sys_get_le32 to fetch unaligned value
Use sys_get_le32() to fetch unaligned 32-bit value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-21 12:44:28 +02:00
François Delawarde
c13603ef87 bluetooth: host: Fix endianness issue in bt_uuid_to_str
This commit makes sure the string generated by bt_uuid_to_str is correct
if the architecture is big-endian.

Signed-off-by: François Delawarde <fnde@demant.com>
2020-10-21 12:16:17 +03:00
Joakim Andersson
d1e5802167 Bluetooth: kconfig: Remove the range on BT_RX_STACK_SIZE
Remove the range on the setting the bluetooth BT_RX_STACK_SIZE.
This range prevents setting the RX stack size lower than 1024,
which depending on the application is too high.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-20 12:22:38 +03:00
Emil Gydesen
1f23e30b48 Bluetooth: controller: Adds kconfig for BIG commands
Guards the BIG command functions with advertiser and sync
Kconfigs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-10-19 18:59:49 +02:00
Emil Gydesen
68153f048d Bluetooth: controller: HCI stubs for BIG commands
Adds initial HCI stubs for the BIG commands to be used for
broadcast isochronous channels.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-10-19 18:59:49 +02:00
Vinayak Kariappa Chettimada
07009701c4 Bluetooth: controller: Minor re-arrange in order of assigning handle
Minor re-arrange in the order of assigning handle after
Node Rx Type.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-19 18:54:59 +02:00
Vinayak Kariappa Chettimada
9c91344bbd Bluetooth: controller: Fix missing handle in ext adv terminate
Fix missing advertising handle value in the extended
advertising terminate event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-19 18:54:59 +02:00
Emil Gydesen
54fe453b7a Bluetooth: controller: Adds definitions for ISO PDUs
Adds the CIS, BIS and BIG Control PDU definitions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-10-19 18:49:07 +02:00
Rubin Gerritsen
71ee632e94 bluetooth: controller: Allow CTLR_PRIVACY and EXT_SCAN_FP when CONN=n
These options are not dependent on the connection state.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-10-19 17:54:32 +02:00
Rubin Gerritsen
63733d840d bluetooth: controller: All controllers can use BT_CTLR_FILTER
This option is generic enough to be used for all controllers.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-10-19 17:54:32 +02:00
Lingao Meng
0e3b04e393 Bluetooth: Mesh: Disable network_id beacon when proxy disabled
According Mesh Spec 1.0.1 Section 7.2.2.2.1 Advertising

A node that does not support the Proxy feature or has the Proxy
feature disabled shall not advertise with Network ID.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-10-16 10:06:50 +02:00
Anas Nashif
b3ff5cbd70 Bluetooth: remove unused extern z_prf
z_prf is not being used in the monitor code, so remove it.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-10-15 11:50:14 -05:00
Joakim Andersson
2837ac4409 Bluetooth: shell: Add disable advertising channel arguments
Add options to disable advertising channels for the different
advertising commands.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-15 13:21:26 +03:00
Joakim Andersson
ea273100ef Bluetooth: host: Add advertising options to disable channel
Add advertising options to disable the individual advertising
channel 37, 38 and 39 per advertising instance.

Fixes: #26732

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-15 13:21:26 +03:00
Joakim Andersson
426cef4477 Bluetooth: host: fix size of advertising option argument
Fix size of advertising option argument to get_filter_policy
function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-15 13:21:26 +03:00
Vinayak Kariappa Chettimada
99dfa277bf Bluetooth: host: Fix missing BT_DEV_EXPLICIT_SCAN flag clear
Fix missing BT_DEV_EXPLICIT_SCAN flag clear on error
return.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-15 13:10:16 +03:00
Joakim Andersson
ee81c0865d Bluetooth: GATT: Consistent permission handling of discovered attribute
Be consistent in the permission handling of the discovered attribute
in the temporary object given in the discovery callback.
For characteristics the permission field was set to READ, while for
all other attributes it was set to 0.

Fixes: #29083

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-15 11:08:48 +02:00
Joakim Andersson
24f62eeea1 Bluetooth: GATT: Use UUID of attribute to check for a characteristic
Update check in the bt_gatt_attr_value_handle API function to use the
UUID of the function, in case the attribute has been declared with a
different read handler, or the attribute is a temporary object
where the read attribute has not been set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-15 11:08:48 +02:00
Joakim Andersson
34cf1c74c2 Bluetooth: GATT: Fix regression in lazy loading of CCCs
Fix regression in lazy loading handling of GATT CCCs.
Bug introduced by: 00d370b09aa5dd1dc56986989989df6d4dd53bcf
The commit failed to account for ccc_set_direct calling ccc_set.

Fixes: #29150

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-14 17:35:22 +02:00
Joakim Andersson
c13588a508 Bluetooth: GATT: Improve service changed static RAM usage when disabled
Improve GATT service changed static RAM usage when the feature has
been disabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-14 17:18:35 +02:00
Joakim Andersson
374cbdd124 Bluetooth: GATT: Refactor use of 16-bit UUID core types
Refactor use of 16-bit common GATT UUID types where a complete UUID
object is declared on the stack only to use the 16-bit value.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-13 19:51:49 +03:00
Joakim Andersson
3346aa4d39 Bluetooth: l2cap: Reduce size of disconnect pool
Reduce the size of the disconnect pool required the full MTU
for a disconnect request.
Also completely remove the pool when not needed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-13 13:13:50 +02:00
Vinayak Kariappa Chettimada
605ecf25a1 Bluetooth: controller: Fix debug pin for radio close
Fix the debug pin state when prematurely closing radio
events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-13 10:13:54 +02:00
Vinayak Kariappa Chettimada
43d8e3c90c Bluetooth: controller: Fix missing return on Auxiliary PDU abort
Fix the missing return statement when Auxiliary PDU
transmission is aborted because Primary PDU does not have
the aux pointer setup. Also, directly stop clocks and
post LLL done, like being done in other state/role LLL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-13 10:13:54 +02:00
Vinayak Kariappa Chettimada
77f12700e7 Bluetooth: controller: Minor conditional compile refactor
Minor Extended Advertising conditional compilation reorder
to better reflect the order Observer->Extended Scanning
dependency.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-13 10:13:40 +02:00
Vinayak Kariappa Chettimada
4b965c6174 Bluetooth: controller: Fix rx quota mismatch due to ext adv terminate
NODE_RX_TYPE_EXT_ADV_TERMINATE is generated in ULL context
and shall not increment received PDU quota value.

Fixes #29101.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-13 10:13:40 +02:00
Vinayak Kariappa Chettimada
babd7289eb Bluetooth: controller: Move bsim radio hal header
Move the bsim radio hal header for nrfxx into the
controller's hal folder.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-12 19:34:13 +02:00
Vinayak Kariappa Chettimada
9072f78abf Bluetooth: controller: openisa: Port drift implementation changes
Port minor anchor point synchronization drift implementation
changes.

Relates to changes in commit 732de50f67 ("Bluetooth:
controller: Refactor out drift compensation code").

Fixes #29062.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-09 13:46:46 +02:00
Vinayak Kariappa Chettimada
c1c627ce5a Bluetooth: controller: Fix Periodic Advertising cond. compilations
Fix Periodic Advertising conditional compilation to not
fail on undefined declarations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-09 11:41:34 +02:00
Vinayak Kariappa Chettimada
c440c0d92f Bluetooth: controller: Initialize close to locality of reference
Initialize auto variables close to locality of reference.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-08 17:29:08 +02:00
Vinayak Kariappa Chettimada
e50319e055 Bluetooth: controller: Check for ticker operation failure
Add assert check to detect failure to enqueue ticker
operations. This will avoid HCI thread from stalling
forever on k_sem_take.

This assert will trigger on design fault, not defining
enough queued ticker operations count.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-08 11:54:42 +02:00
Vinayak Kariappa Chettimada
75bb449d2d Bluetooth: controller: Fix missing NULL check
Added a missing NULL pointer dereference check and made the
structure member scan->per_scan.sync and timeout_reload as
volatile, as they are modified in ISR context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
f71664a970 Bluetooth: controller: Added link struct allocation explanation
Added link structure allocation explanation related to HCI
event generation by the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
44243f8e0c Bluetooth: controller: Use BT_INFO to log unsupported code path
Use BT_INFO to log missing support for Periodic Advertising
report generation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
2a1f134c32 Bluetooth: controller: Add Experimental keyword
Add Experimental keyword to LE Periodic Advertising in
Advertising and Synchronization state Kconfig title.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
cb67f36029 Bluetooth: controller: Rename to BT_CTLR_SYNC_PERIODIC
Rename Kconfig option BT_CTLR_SCAN_PERIODIC to
BT_CTLR_SYNC_PERIODIC.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
01006be29f Bluetooth: controller: Fix offset and offset units population
Fix the auxiliary pointer and sync information offset and
offset unit population. Offsets are 13-bit value, use 300 us
offset unit when offset value using 30 us offset unit does
not fit in 13-bits.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
56a7a46bc9 Bluetooth: controller: Fix SCA and Channel Map in Sync Info
Fix the population of SCA and Channel Map in Sync Info
structure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
bf505fdf98 tests: Bluetooth: shell: Minor print format update
Minor print format update, updated format for Periodic
Advertising Interval, and added SID to be printed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
66b95aa1d4 Bluetooth: controller: Fix set per adv recv enable HCI integration
Uncomment the code integrating the LE Set Periodic
Advertising Receive Enable command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
f9a8507b4d Bluetooth: controller: Move identical ll_scan_params_set out
Move the identical ll_scan_params_set definitions out of
extended advertising conditional compilation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
2234515f96 Bluetooth: controller: Add missing Periodic Adv Sync resources
Add the missing resources like ticker instances, Rx PDU
buffers and memory queue link buffers, that are required
for Periodic Advertising Sync creation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
3a5eed8bac Bluetooth: controller: Fix Periodic Advertising Context leak
Fix Periodic Advertising Context leak on Sync Lost.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
f402435535 Bluetooth: controller: Remove redundant use of update check
Remove the redundant ticker update check, ticker is not
stopped and started in Periodic Advertising unlike in a
Connection Update Procedure in connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
0a56d57107 Bluetooth: controller: Fix own address type check
Fix the own address type check for whether local static
random address has been set.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
874c1452f1 Bluetooth: controller: Replace use of printk with BT_WARN
Replace printk in ISR with BT_WARN to avoid problems with
co-existing with logging subsystem.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
a5983e1237 Bluetooth: controller: Fix memory alignment violation
Fix memory word access alignment violation that causes
hardfault in nRF51x SoC.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
abebdb2f52 Bluetooth: controller: Fix cond. compilation for broadcaster
Fix compilation error when building only broadcaster support
in an application.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
0de3943bb6 Bluetooth: controller: Do not generate sync lost on terminate sync
Remove generation of Periodic Sync Lost HCI event generation
that is not needed as per BT Spec. v5.2 Vol.4 Part E.
Section 7.8.69.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
c23b1a27a7 Bluetooth: controller: Fix uninitialized rl_idx value
Fix uninitialized rl_idx value for the Extended Advertising
PDU received in the auxiliary channels. This caused
uninitialized rl_idx to be used by HCI layer and fail an
assert check in ull_filter.c file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
62e8572df7 Bluetooth: controller: Fix missing periodic advertising start
Fix missing periodic advertising start due to missing
allocation of auxiliary context when no Extended
Advertising PDU on auxiliary channels.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
aec99da741 Bluetooth: controller: Remove cond compile on struct definition
Remove conditional compilation on structure definition in
pdu.h so as to allow inclusion of header files with
function prototypes that use those structures. I.e. to
avoid conditionally including the header file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
baef416d5d Bluetooth: controller: Added Periodic Sync Terminate and Sync Lost
Added implementation to perform Periodic Sync Terminate,
generation of Sync Lost on terminate and on remote device
termination of Periodic Advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
d1f4611ad8 Bluetooth: controller: Add Periodic Sync drift compensation
Added implementation to handle Periodic Advertising clock
drift in the created Periodic Advertising Sync instance.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
31f2196abd Bluetooth: controller: Fix auxiliary channel scanning
Fix auxiliary channel scanning to capture the PDU end
timing that is need to correctly setup Periodic Sync.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
422d8b1466 Bluetooth: controller: Fix correct CA in Periodic Advertising
Fill the correct local clock accurracy in the Sync Info
structure in the Periodic Advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
b2dcfa7ace Bluetooth: controller: Refactor the order of file static function
Refactor the order of file static function to be consistent.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
90cfe1dc66 Bluetooth: controller: Fix minor conditional compilation
Fix minor conditional compilation around extended advertising
and scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
732de50f67 Bluetooth: controller: Refactor out drift compensation code
Refactor out drift compensation implementation so as to
reuse it for Periodic Sync feature.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
057653c220 Bluetooth: controller: Initial implementation of Periodic Sync setup
Added initial implementation of setting up of Periodic Sync
and scheduling the Radio Events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
ff4546dced Bluetooth: controller: Refactor out common lll_abort_cb function
Refactor out common lll_abort_cb function so that it can be
used across Periodic Advertising and Periodic Advertising
Sync creation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
2627524162 Bluetooth: controller: Refactor out clock ppm interface
Refactor out clock ppm interface so that it can be reused
for Periodic Advertising Sync feature.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
a0612dabe1 Bluetooth: controller: Implementation of Periodic Sync Create Cancel
Implementation of Periodic Sync Create Cancel.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
f9380dbf48 Bluetooth: controller: Implementation of Periodic Sync Create
Implementation of Periodic Sync creation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
e533f99f04 Bluetooth: controller: Initial implementation of Periodic Sync LLL
Added initial implementation of LLL layer of Periodic Sync
creation feature.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
96dd0ef9d8 Bluetooth: controller: Minor internal comments updated
Minor updates to internal comments.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
99916bead0 Bluetooth: controller: Refactor to use ull_sync naming
Refactored to use ull_sync naming instead of ull_scan_sync.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
7a5413dcca Bluetooth: controller: Add Kconfig to config Periodic Sync Sets
Added Kconfig option to configure supported simultaneous
Periodic Sync Sets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
5c525f0350 Bluetooth: controller: Add HCI integration of Periodic Sync
Added implementation to integrate the Periodic Sync LL
interface with HCI layer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
b0cc96ec61 Bluetooth: controller: Add initial ULL Periodic Sync code
Add initial files and code for Periodic Sync feature support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
5acdb7d9d2 Bluetooth: controller: Add depends on BT_PER_ADV
Enable controller periodic advertising if host supports it.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Joakim Andersson
b5bf46fe3c Bluetooth: host: Don't use struct with zero size
Don't use the ATT structs that has contains only a flexible array
member. This is not supported by C99 standard, only through GNU C
extension with zero length array.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-10-07 14:51:30 +02:00
Vinayak Kariappa Chettimada
c87c1a8890 Bluetooth: controller: Fix implicit declaration warning
Fix implicit declaration warning for peripheral_latency_cancel
by moving it to ull_slave file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-06 13:47:18 +02:00
Andrew Boie
ed7263bf6b bluetooth: add dep on !SMP
The BT code uses co-op thread priorities to implement some
critical sections. This won't work with SMP turned on.
Express this in our configuration ontology, so that it's
not possible for the end user to set up the system in this
way and get crashes or odd behavior.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-05 19:33:02 -07:00
Jordan Montgomery
ec9080a036 Bluetooth: controller: Fix Null deref during adv data update
Added a check for adv->lll.aux before starting extended advertising to
fix observed NULL pointer dereference when updating AD data of legacy
advertising.

Fixes #28544.

Signed-off-by: Jordan Montgomery <montytyper@msn.com>
2020-10-05 11:47:30 +02:00
Emil Gydesen
8cc051ccac Bluetooth: host: Change PA sync callbacks to global callbacks
Changes the callbacks for periodic sync callbacks such that multiple
applications can register callbacks, similar to the connection and
scan callbacks.

This change will make it easier to support the PAST feature, as
PA syncs make be created by the controller which then notifies
the host, and thus the application (if callback registered).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-10-02 11:49:13 +02:00
Xavier Chapron
824f423e54 misc: Replace assert include and calls by sys/__assert.h equivalent
Replace all calls to the assert macro that comes from libc by calls to
__ASSERT_NO_MSG(). This is usefull as the former might be different
depending on the libc used and the later can be customized to reduce
flash footprint.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-10-02 11:42:40 +02:00
YanBiao Hao
dc89bfcc7f Bluetooth: Mesh: Config Client network transmit set/get API
Get/Set network transmit parameter of a node.

Signed-off-by: YanBiao Hao <haoyanbiao@xiaomi.com>
2020-10-02 11:30:12 +02:00
Emil Gydesen
0be8a91a73 Bluetooth: host: Add NULL checks for scan callbacks
The scan callbacks may be NULL, which would cause an error if
e.g. the timeout callback wasn't set and the scan terminates after
a timeout.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-10-01 13:57:53 -04:00
Lingao Meng
f16c653be9 Bluetooth: Mesh: Move Replay Protect to seperate module
Move RPL to seperate module, and remove it in `bt_mesh`
structure.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-10-01 16:20:24 +03:00
Vinayak Kariappa Chettimada
8f203e46ca Bluetooth: shell: Fix PER SYNC conditional compilation
Fix conditional compilation to allow building test shell
with Periodic Advertising Sync alone.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-01 12:54:06 +02:00
Vinayak Kariappa Chettimada
416d7ee32a Bluetooth: controller: Fix latency cancel on LLCP initiation
Fix controller implementation to cancel peripheral latency
when initiating new control procedures.

Fixes #28699.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-01 12:53:53 +02:00
Vinayak Kariappa Chettimada
b6fb074d6e Bluetooth: controller: Connection termination race condition
Add checks to abort connection radio event preparation and
start, if the connection terminates with a race condition
with new radio event being prepared or being in prepare
pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-01 11:47:35 +02:00
Vinayak Kariappa Chettimada
3e2dc0d706 Bluetooth: controller: Add branch prediction hints
Add branch prediction hints in critical control paths in the
code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-01 11:47:35 +02:00
Vinayak Kariappa Chettimada
d64bbd5a06 Bluetooth: controller: Add missing debug pin toggle
Add missing debug pin toggle on abort of connection event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-01 11:47:35 +02:00
Vinayak Kariappa Chettimada
48a0c0c3a8 Bluetooth: controller: Fix undeclared identifier
Fix undeclared CONFIG_BT_CTLR_DATA_LENGTH_MAX when Force
MD bit automatic feature is enabled in nRF51 Series.

Fixes #28774.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-30 06:38:19 -05:00
Vinayak Kariappa Chettimada
e4fe7435d7 Bluetooth: controller: Added Force MD bit automatic feature
Added automatic runtime calculation of Forced MD bit count
based on incoming Tx buffer throughput.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
3bbe2c0a07 Bluetooth: controller: Add in-system Tx throughput measurement
Added feature to in-system measure incoming Tx throughput.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
cf05f49ee2 Bluetooth: controller: Refactor Force MD bit implementation
Add Force MD bit feature wherein connection events can be
extended to match the rate at which applications provide
new Tx data. MD bit in Tx PDUs is forced on if there has
been CONFIG_BT_CTLR_TX_BUFFERS count number times Tx/Rx
happened in a connection event. The assumption here is,
if controller's tx buffers are full, it is probable that
the application would send more Tx data during the
connection event, and keeping the connection event alive
will help improve overall throughput.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
1fcb0d0b5e Bluetooth: controller: Add force MD bit feature
Add force Md bit feature wherein connection events can be
extended to match the rate at which applications provide
new Tx data.

Fixes #27981.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
62f1ad79bb Bluetooth: controller: Fix connection event close check
Fix the check that decides to close a connection event,
which was missing a check on MD bit being set for empty PDU
to be Tx-ed out.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
45593ff508 Bluetooth: controller: Optimise Tx PDU preparation
Optimize the Tx PDU preparation, empty PDU only needs MD bit
to be modified, other fields be initialised only at power up.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
6b1cfdda33 Bluetooth: controller: Fix premature connection event close
Fix premature connection event close due to the new Tx
buffers not being de-multiplexed and routed to connection's
Lower Link Layer context when they arrive while being
inside the connection's radio event.

Also, fix master prepare to demux and enqueue two Tx buffers
so that MD bit can be set correctly.

Relates to #27981.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
0096fca39d Bluetooth: controller: Refactor ull_conn_tx_ack function
Refactor ull_conn_tx_ack function as it no longer needs to
return the connection context back to caller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
35c0b77304 Bluetooth: controller: Add interface to get ULL ref count
Add a static inline interface to get ULL context reference
count.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
41017478b1 Bluetooth: controller: Move tx_ull_dequeue to static functions
Move tx_ull_dequeue function to be placed alongwith other
static function definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
2dc174fb10 Bluetooth: controller: Minor relocation of lll_conn_flush function
Minor relocation of lll_conn_flush function to place alongwith
non-static functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
accd35fe62 Bluetooth: controller: Remove commented code
Remove commented out code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Trond Einar Snekvik
fc4fe09966 Bluetooth: Mesh: Provisioning: Reject identical random
Adds check for provisioning random values that are identical to our own,
and terminates the provisioning procedure.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-09-24 13:45:15 -05:00
Ilya Averyanov
e363decf1c Bluetooth: fix strncpy call in bt_set_name
In bt_set_name we already get name length so let's use it in strncpy
Also fix warning with enable -Wstringop-truncation

Signed-off-by: Ilya Averyanov <a1ien.n3t@gmail.com>
2020-09-24 13:41:57 -05:00
Emil Gydesen
8825ce0ce6 Bluetooth: Shell: Fix PA shell command parameter cnt
The sync create and sync delete dit not have the correct
amount of mandatory and optional parameters set in the
SHELL_CMD_ARG declarations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-09-24 21:29:47 +03:00
Emil Gydesen
68a357e66d Bluetooth: Shell: PA sync terminate callback clears entry
The sync terminate callback did not set any entries in the
PA sync array to NULL, thus not allowing the shell to
reuse them in case that the sync was lost unexpectectly.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-09-24 21:29:47 +03:00
Emil Gydesen
27f6bf19e8 Bluetooth: Host: Change PA sync scan to fast scan
Instead of doing slow (non-fast) scan when syncing to
a PA, it will now do a fast scan, which drastically reduces the
time it takes to create the sync. The application may
still do explicit slow scan if wanted.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-09-24 21:29:47 +03:00
Emil Gydesen
b78245db60 Bluetooth: Host: Fix PA sync cancel scan update
When the application cancels the PA sync, it would update
the scan before clearing the BT_PER_ADV_SYNC_SYNCING flag
which cause the scan to always start again.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-09-24 21:29:47 +03:00
Vinayak Kariappa Chettimada
222dca5598 Bluetooth: controller: Fix redundant PDU transmission
Fix the redundant PDU transmission when the new Tx PDU
buffer is enqueued after MD bit value of zero was
transmitted previously in a connection event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-24 17:27:00 +02:00
Vinayak Kariappa Chettimada
1c3659519f Bluetooth: controller: nRF53x: Fix missing sw_switch clear DPPI config
Fix missing sw_switch timer clear DPPI config when
re-enabling Tx or Rx after radio_disable() or
radio_switch_complete_and_disable() call in LLL state/role
contexts.

Fixes #28471.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-24 17:05:14 +02:00
Joakim Andersson
407411f1af Bluetooth: host: Fix stuck OOB get local functions SC is not supported
Fix bt_le_oob_get_local and bt_le_ext_adv_oob_get_local stuck forever
waiting for the sc_local_pkey_ready semaphore when SC HCI commands
are not supported in the controller.

By using the le_sc_supported helper function the runtime check of HCI
commands and the feature check of CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY
is combined to be handled int the same way.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-22 19:37:31 +02:00
Joakim Andersson
214175483b Bluetooth: SMP: Move le_sc_supported helper function up
Move the le_sc_supported helper function up in the source file so that
it can be re-used in other places without a forward declaration.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-22 19:37:31 +02:00
Luiz Augusto von Dentz
d8fd5bab04 Bluetooth: L2CAP: Truncate RX MTU if segmentation is not supported
If hannel don't have alloc_buf and the RX MTU is configured to require
segmentation this warn the user and truncate the RX MTU.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-22 10:56:27 +03:00
Erik Brockhoff
9bbbf17cf2 bluetooth: controller: fix mark/unmark error in ull_adv::disable
In case where ull_adv::disable() is disallowed, disable_mark is
erroneously re-mark instead of un-marked

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2020-09-21 17:05:19 -05:00
Luiz Augusto von Dentz
25fda14702 Bluetooth: GATT: Fix assuming CCC position
Accourding to the spec the CCC descriptor may occur in any position
within the characteristic definition after the Characteristic Value.

Fixes #28324

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-21 17:15:19 +03:00
Vinayak Kariappa Chettimada
a8ffc03f6e Bluetooth: controller: Fix REJECT_IND PDU handling
Fix for handling REJECT_IND PDU received for PHY Update,
Connection Parameter Request and Data Length Update control
procedures.

If a link layer control procedure collision occurs, example
with local initiated PHY Update Procedure, and peer sends a
REJECT_IND PDU, then the PHY Update Procedure is stalled.

Fixes #28282.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-21 14:52:41 +02:00
Ievgenii Meshcheriakov
d27c32efc3 drivers/flash/soc_flash_nrf: Rename config option SOC_FLASH_NRF_RADIO_SYNC
Call it SOC_FLASH_NRF_RADIO_SYNC_TICKER so it is not too generic.

Signed-off-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@nordicsemi.no>
2020-09-21 13:06:16 +02:00
Lingao Meng
4cc8cb1c15 Bluetooth: Mesh: Fix send input_complete before public key
According Mesh Profile Spec 5.4.2.4 Authentication, if device
use Input OOB Authentication method, should send input complete
pub after local public key has been acked.

`bt_mesh_input_string` or `bt_mesh_input_number` directly send
`input_complete`, however does not check whether the pub key has
been sent.

Mesh Provisioning timeout set to `60` seconds, so even this
probability is extremely low, it does not mean that there is no
such probability.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-09-21 13:07:18 +03:00
Joakim Andersson
0fe62c6392 Bluetooth: host: Fix bug in device name shortening handling
Fix bug in device name shortening handling leading to memory
corruption.
This is triggered by an underflow in the length field of the shortened
name when set_data_len + 2 > set_data_len_max.

Fixes: #27693

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-19 10:25:49 +02:00
Joakim Andersson
f332d51d60 Bluetooth: host: Ignore failure to set passive scanner address
Ignore error when failing to set the passive scanner private address.
This can happen because in between the time we checked if the
advertiser was enabled and the time we execute the set random address
command the state of the advertiser could have changed in the
controller, and we only set the state once the command has completed
in the controller.

Fixes: #25672

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-19 10:19:03 +02:00
Joakim Andersson
2cb4548a42 Bluetooth: host: Fix not setting NRPA before starting scanner
Fix not setting NRPA before starting scanner.
Occurs with BT_PRIVACY=n and BT_EXT_ADV=y

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-19 10:19:03 +02:00
Thomas Stenersen
b7336616b2 Bluetooh: Host: Fix wrong buffer in acl_total_len calc
To be squashed.

Co-authored-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-09-18 20:24:46 +03:00
Thomas Stenersen
3d57cdb7c3 Bluetooth: host: Use C89-style
To be squashed after review.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-09-18 20:24:46 +03:00
Thomas Stenersen
e28fdbb9df Bluetooth: host: Fetch L2CAP length directly
This commit will be squashed after review.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-09-18 20:24:46 +03:00
Thomas Stenersen
8bc00f5ead Bluetooth: host: Refactor bt_conn_recv
Re-structures the `bt_conn_recv()` to support more generic appending of
new ACL data. This also handles the possibility of receiving 0-length
ACL_START and ACL_CONT fragments, whilst maintaining existing
error-checking functionality.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-09-18 20:24:46 +03:00
Thomas Stenersen
a8f47a1110 Bluetooth: host: Support fragmented L2CAP header
Fixes issue #26900.

A controller may fragment an L2CAP SDUs in any way it sees fit,
including fragmenting the L2CAP header. Likewise, the receiving
controller may send the fragmented header as ACL data to the host.

The Zephyr host assumed that a `BT_ACL_START` was at least 2 bytes long,
and consequently read the two-byte length field from the buffer without
length checks.

This commit allows the `BT_ACL_START` to be less than two bytes,
updating the `conn->rx_len` onces the `BT_ACL_CONT` with the remaining
part of the length field has been received.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-09-18 20:24:46 +03:00
Joakim Andersson
cccfea24c1 Bluetooth: controller: Fix Kconfig dependencies for PHY options
Fix Kconfig dependencies for enabling the controller PHY options
for LE 2M Phy  and LE Coded Phy. These options should be selectable
without connections enabled when extended advertising has been enabled.

The issue affects out-of-tree controllers that wish to use the
BT_CTLR_PHY_CODED and BT_CTLR_PHY_2M options.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-18 18:11:35 +02:00
Joakim Andersson
4cc6098af8 Bluetooth: controller: Select controller features from SoC capabilities
Select the controller feature support for data length and LE 2M PHY
based on the SoC hardware capabilities instead of relying on SoC
family.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-18 18:11:35 +02:00
Luiz Augusto von Dentz
6f20e072f1 Bluetooth: ISO: Fix unbalanced reference count
When disconnecting chan->conn is set to NULL without unrefing.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-18 15:24:17 +02:00
Luiz Augusto von Dentz
a76c804d07 Bluetooth: ISO: Fix crash when bt_iso_chan_bind fails
When attempting to bind a channel if it fails the code will attempt to
cleanup calling bt_iso_cleanup which expects connections of
BT_CONN_TYPE_ISO.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-18 15:24:17 +02:00
Luiz Augusto von Dentz
a177dfdd93 Bluetooth: ISO: Fix missing break after bt_iso_cleanup
ISO connection does not initialize its tx_complete_work nor it uses for
anything so calling into tx_notify will likely cause a crash.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-18 15:24:17 +02:00
Lingao Meng
b667ba997f Bluetooth: Mesh: Fix RPL not check by proxy configuration
Fixes proxy configuration not check by replay.
Fixes secure beacon iv update not store new RPL.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-09-18 15:18:18 +02:00
Vinayak Kariappa Chettimada
17c4396ed4 Bluetooth: controller: Fix cond. compilation for broadcaster
Fix conditional compilation for extended advertising
without peripheral support.

This fixes missing initialization of buffer for generating
advertising terminate event.

Fixes #28325.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-18 10:28:57 +02:00
Carles Cufi
121937e071 Bluetooth: controller: Make RX prio thread stack configurable
Now that CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE defines a stack size, allow
for it to be configurable from a .conf file just like the rest of the
threads in Bluetooth.

Fixes #27768.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-09-17 18:08:21 +02:00
Trond Einar Snekvik
d7e0d8135f Bluetooth: Mesh: Use #ifdef for provisioner build
Replaces the current zero length array for provisioner data with
ifdefs, to silence new gcc 10 warnings about array element access.

Fixes #28371.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-09-17 11:51:13 +03:00
chao an
e611b10fde Bluetooth: host: free the adv instance if start legacy advertise fail
the adv instance should be delete correctly if advertise fail,
Otherwise the instance will unable to allocate if start the legacy again

Signed-off-by: chao an <anchao@xiaomi.com>
2020-09-16 11:29:09 +03:00
Trond Einar Snekvik
61819f23f9 Bluetooth: Mesh: Virtual address memory leak
Fixes a memory leak when a virtual address subscription is added for a
model that either has this VA already, or the model has no more space
for subscription addresses.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-09-12 22:48:20 +03:00
Vinayak Kariappa Chettimada
c8e23139c1 Bluetooth: controller: Fix addr type in auxiliary PDU
Fix uninitialized transmitter address type being set in the
auxiliary PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-10 12:07:57 -05:00
Lingao Meng
0023d3f364 Bluetooth: Mesh: Store Krp phase after krp value changed
Store krp phase persistently when this value has been changed.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-09-10 14:12:49 +03:00
Vinayak Kariappa Chettimada
48e791a625 Bluetooth: host: Fix Suggested Default Data Len for QUIRK_NO_AUTO_DLE
Add back call to LE Write Suggested Default Data Length
command so that new connections, receiving Data Length
Update procedure before local device can auto initiate, can
respond with the suggested default data length Tx octets
and Tx time.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-10 12:51:27 +02:00
Andrzej Kaczmarek
7a113ea657 Bluetooth: controller: Fix TxAdd setting in auxiliary PDU
When controller is built with extended advertising support but without
LL Privacy build fails due to issue with code that sets TxAdd in aux
PDU:

.../ll_sw/ull_adv_aux.c: In function 'ull_adv_aux_hdr_set_clear':
.../ll_sw/ull_adv_aux.c:502:25: error: 'struct ll_adv_set' has no
                                member named 'own_addr_type'
  502 |   sec_pdu->tx_addr = adv->own_addr_type & 0x1;
      |

We need own_addr_type value if an advertising set with aux but without
AD is created since we cannot get TxAdd value from other PDU.

ull_adv_aux_hdr_set_clear() can now be called with a flag to explicitly
set AdvA field and pass own_addr_type in 'value' parameter. This allows
to set proper TxAdd when creating new advertising set.

On aux updates, we use TxAdd from other PDU:
- if primary PDU has AdvA, we use TxAdd from that PDU
- if previous secundary PDU has AdvA, we use TxAdd from that PDU
In other case we just return an unpsecified error since this should not
happen in any valid scenario.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-10 12:40:29 +02:00
Vinayak Kariappa Chettimada
61b6534727 Bluetooth: controller: Scanning with unreserved window
Added a Kconfig option to enable scanner with unreserved
scan window when in continuous scan mode. This will permit
scanner to be always pre-empted by other roles, making it
the lowest in priority when it comes to using the radio.

Fixes #27414.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-07 15:11:33 +02:00
Luiz Augusto von Dentz
95cec8354c Bluetooth: GATT: Introduce bt_gatt_attr_get_handle
This introduces bt_gatt_attr_get_handle which can be used to resolve
handles of static attributes.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-05 11:06:21 +02:00
Luiz Augusto von Dentz
5c4bde55d0 Bluetooth: GATT: Rework bt_gatt_attr_func_t
Make it actually give the original pointer to the attribute and its
resolved handle so static attributes don't need an extra lookup.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-05 11:06:21 +02:00
Luiz Augusto von Dentz
dde25a3d44 Bluetooth: GATT: Optimize static service handle resolution
This optimizes the lookups to skip ahead when attribute pointer is not
located within service array.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-05 11:06:21 +02:00
Luiz Augusto von Dentz
b8e9b6f88a Bluetooth: shell: Add iso module
This adds iso shell module which we can be used to exercise ISO related
APIs:

iso - Bluetooth ISO shell commands
Subcommands:
  bind        :[dir] [interval] [packing] [framing] [latency] [sdu]
  [phy] [rtn]
  connect     :Connect ISO Channel
  listen      :[security level]
  send        :Send to ISO Channel
  disconnect  :Disconnect ISO Channel

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Luiz Augusto von Dentz
d85d40c58e Bluetooth: hci_raw: Add support for ISO packets
This adds supports for ISO packets so then can be transmitted and
received with hci_raw driver.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Luiz Augusto von Dentz
c29e6ffa73 Bluetooth: monitor: Add support for ISO packets
This adds types for TX/RX ISO packets so the likes of btmon can decode
them properly.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Luiz Augusto von Dentz
81d34ecd19 Bluetooth: Audio: Initial ISO channel support
This adds initial code for handling ISO channels.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Guillaume Lager
f5cb887a79 bluetooth: Allow immediate logging with software-based LL
Some logging configuration are compatible with software-base Link
Layer. Currently only one configuration is supported:
RTT back-end in drop mode and no clean output

Signed-off-by: Guillaume Lager <guillaume.lager@gmail.com>
2020-09-04 18:48:32 +02:00
Kamil Piszczek
be7e2fc5ab bluetooth: services: ots: use multi-instance macro from gatt.h
Used multi-instance macro defined in gatt.h for OTS instance
definitions.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2020-09-04 18:37:27 +02:00
Joakim Andersson
48606a2dcd Bluetooth: shell: Add "add-subscription" command
Add the command add-subscription to the shell to test the
bt_gatt_add_subscription API.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-04 18:34:18 +02:00
Joakim Andersson
76119c526e Bluetooth: GATT: Allow application to add subscription.
Allow the application to add subscription without resubscribing.
This is needed for persistent bonds that can go to deep sleep and
turn of the RAM or power-cycle.
In this case the application as a GATT client must have a way to add
the subscription callbacks back to the stack before the GATT server
sends notifications.
This should preferable be able to be done before even connecting
since the notifications can arrive immediately after connecting to
the peer.
The stack cannot persist this on it's own since it must remember the
function pointers for the callback functions. Storing these in
persistent storage would not be compatible with a Device Firmware
Upgrade (DFU) solution.

Fixes: #21798

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-04 18:34:18 +02:00
Joakim Andersson
ae5489085f Bluetooth: GATT: Refactor gatt_sub_add to add withouth conn object
Refactor the gatt_sub_add function to be similar in structure to how
find_cf_cfg is implemented. This is so that a subscription can be added
without an active connection.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-04 18:34:18 +02:00
Vinayak Kariappa Chettimada
94d7469172 Bluetooth: controller: Add DEBUG_PINS support in nRF5340DK
Add support for BT_CTLR_DEBUG_PINS for nRF5340DK board.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-04 17:17:07 +02:00
Vinayak Kariappa Chettimada
03852a5f02 Bluetooth: controller: Fix DEBUG_PINS_CPUAPP dependency
Remove the BT_LL_SW_SPLIT dependency for
BT_CTLR_DEBUG_PINS_CPUAPP when building CPUAPP application
that is using Zephyr BLE HCI controller on the CPUNET core.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-04 17:17:07 +02:00
Kamil Piszczek
0a7a8fd137 bluetooth: services: add Object Transfer service
Added GATT Object Transfer Service implementation.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2020-09-04 17:06:17 +02:00
Emil Gydesen
9c5db74a6e Bluetooth: Remove _gatt_ infix for Device Information Service (DIS)
The _gatt_ infix was determined to be unnecessary as
GATT is implied by it being a Bluetooth service.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-09-04 15:38:44 +02:00
Emil Gydesen
8d7b5ebd7a Bluetooth: Remove _gatt_ infix for Heart Rate Service (HRS)
The _gatt_ infix was determined to be unnecessary as
GATT is implied by it being a Bluetooth service.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-09-04 15:38:44 +02:00
Emil Gydesen
b4a8229db6 Bluetooth: Remove _gatt_ infix for Battery Service (BAS)
The _gatt_ infix was determined to be unnecessary as
GATT is implied by it being a Bluetooth service.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-09-04 15:38:44 +02:00
Joakim Andersson
7ab35145fb Bluetooth: host: Add hardware error event handling
Add handling of the HCI_Hardware_Error event to log the hardware code.
This event was unmasked in set_event_mask.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-04 14:46:54 +02:00
Jordan Yates
4f54b4176d bluetooth: controller: add name to TX power choice
Add a name to the Kconfig choice that selects the controller TX power.
This allows board `*.defconfig` files to change the default TX power
as their certifications warrant. For example:

```
choice BT_CTLR_TX_PWR
	default BT_CTLR_TX_PWR_PLUS_4
endchoice
```

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-09-04 14:46:05 +02:00
Jordan Yates
1723e479ab Bluetooth: controller: preserve TX power
Preserve the TX power set with the `BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL`
command for advertising and scanning procedures. As the TX power is no
longer overwritten on procedure start, the TX powers can now be set
before starting the procedure. This eliminates the chance for the first
transmissions to use the default TX power instead of the request TX
power.

Similar changes are not made to the connection advertising powers as
changing the TX power for a connection to device A should not change
the TX power for a future connection to device B using the same
`struct lll_adv` instance.

Fixes #27921.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-09-04 14:37:57 +02:00
Andrzej Kaczmarek
d8864d44f4 Bluetooth: controller: Add ADI support in AUX_SCAN_RSP
ADI field is optional in AUX_SCAN_RSP so by default it's disabled, but
now we'll have an option to include it.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
1b1ab16a64 Bluetooth: controller: Return current ADI when updating aux
When aux is upated, DID is changed and unlike SID it's only stored in
aux PDU. To allow quick access to new DID value, let's just optionally
return current ADI value after aux was updated. It will be useful e.g.
when updating scan response data if we want to put ADI there.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
09115429a1 Bluetooth: controller: Add non-connectable scannable
This enables processing of AUX_SCAN_REQ and sending back AUX_SCAN_RSP
on non-connectabe scannable advertising instances. Similar path will
be used for AUX_CONNECT_REQ so there are few references for connectable
as well, but this is not supported as for now.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
b47df3cc21 Bluetooth: controller: Add scan response data setting restrictions
This adds restrictions for setting scan response data as specified by
Core spec:
* on legacy, only complete data can be set
* on legacy, data cannot be longer than 31 octets
* on ext, if non-scannable, data can only be discarded
* if ext enabled, only complete data can be set
* if ext enabled, data cannot be discarded

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
60b8df94e1 Bluetooth: controller: Add support to set scan response data on ext
This allows to set scan response data using ext adv commands.

New AUX_SCAN_RSP can be created without analyzing previous PDU since
the only value that need to be copied from previous PDU is AdvA which
is placed at fixed location. TxPower is omitted since, if enabled, it
is already present in AUX_ADV_IND and does not need to be presed in
other PDUs. ADI support is to be added later.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
e49ef46677 Bluetooth: controller: Add AdvA to connectable and scannable aux
AdvA in aux is mandatory for any connectable and scannable set so make
sure it's always added.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
c34bd1c2c4 Bluetooth: controller: Add aux for connectable and scannable
Connectable and scannable instances always have aux so we need to force
AuxPtr to be included in primary PDU and have aux allocated even if no
data are set.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
bef663d5c0 Bluetooth: controller: Require aux for connectable or scannable
Connectable and scannable instances always have AuxPtr so we can return
error immediately if controller is configured with no aux.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Andrzej Kaczmarek
0274a6b26b Bluetooth: controller: Disallow setting AD on scannable instance
Scannable instance can only have scan response data set.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-09-04 14:30:21 +02:00
Morten Priess
8682e47eb0 Bluetooth: controller: Prevent incorrect lazy_current increment
Prevent redundant collision resolves and potential incorrect and harmful
increment of lazy_current.

During collision scenarios with high CPU load, the ticker_worker may be
called a second time before the ticker_job gets to run. This will cause
ticker operations on the previosly expired node (expected), and in some
cases increment lazy_current, even though the node was not sceduled to
execute via the req/ack mechanism.

By moving the request check before collision resolve, CPU time is saved,
and lazy_current will not incorrectly be incremented if node is in
collision.

The problem may be seen as a connection suddenly not receiving packets,
or MIC error on master, because the event counter goes out of sync.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-09-04 14:14:23 +02:00
Rubin Gerritsen
69867a48db bluetooth: controller: BT_CTLR_CONN_RSSI as a shared controller opt
Use a helper config BT_CTLR_CONN_RSSI_SUPPORT so that it is only
enabled when supported by the controller.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-09-04 14:03:20 +02:00
Vinayak Kariappa Chettimada
42d59c95f2 Bluetooth: controller: Fix periodic advertising cond. compile
Fix missing conditional compilation around the periodic
advertising feature implementation.

Fixes #28017.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-04 11:59:23 +02:00
YanBiao Hao
e877ee6088 Bluetooth: Mesh: Adds three Config Client API.
Those APIs are used for deleting appkey, unbinding an application
from SIG model, unbinding an application from vendor model on the
target node, with matching shell command.

Signed-off-by: YanBiao Hao <haoyanbiao@126.com>
2020-09-04 11:47:52 +02:00
Joakim Andersson
e997c46e6d Bluetooth: GATT: Handle bt/ccc setting with CCC lazy loading
When lazy loading of CCCs are enabled there is no settings set handler
register for the 'bt/ccc' key, this means that the settings set handler
for 'bt' key is called instead. This handler does not know what to do
for the 'ccc' subkey, and returns -ENOENT for the entry.
This results in an error message logged by the settings subsystem.
  "E: set-value failure. key: bt/ccc/f8c39e2f98210 error(-2)"

Fix this by providing an empty handler for the 'bt/ccc' key when
Lazy Loading feature is enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-03 13:56:10 +02:00
Vinayak Kariappa Chettimada
eafb6aece1 Bluetooth: host: Fix periodic advertising delete
Fix periodic advertising delete implementation, to not
NULL the callback pointer when deleting the instance so
that the application's terminate callback can be called
thereafter.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-03 10:40:35 +02:00
Vinayak Kariappa Chettimada
c895e3650f Bluetooth: host: minor code style cleanup
Minor cleanup to use reverse christmas tree declarations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-03 10:40:35 +02:00
Tomasz Bursztyka
4dcfb5531c isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs

This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.

Note that only the ISR passed to IRQ_CONNECT are of interest here.

In order to do so, the script fix_isr.py below is necessary:

from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os

cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
(
 const struct device *D = (const struct device *)P;
|
 const struct device *D = P;
)
 ...
}

@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
 const struct device *D;
 ...
(
 D = (const struct device *)P;
|
 D = P;
)
 ...
}

@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
 ...
}

@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);

@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
 ...
}

@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
 ...
}
"""

def find_isr(fn):
    db = []
    data = None
    start = 0

    try:
        with open(fn, 'r+') as f:
            data = str(mmap.mmap(f.fileno(), 0).read())
    except Exception as e:
        return db

    while True:
        isr = ""
        irq = data.find('IRQ_CONNECT', start)
        while irq > -1:
            p = 1
            arg = 1
            p_o = data.find('(', irq)
            if p_o < 0:
                irq = -1
                break;

            pos = p_o + 1

            while p > 0:
                if data[pos] == ')':
                    p -= 1
                elif data[pos] == '(':
                    p += 1
                elif data[pos] == ',' and p == 1:
                    arg += 1

                if arg == 3:
                    isr += data[pos]

                pos += 1

            isr = isr.strip(',\\n\\t ')
            if isr not in db and len(isr) > 0:
                db.append(isr)

            start = pos
            break

        if irq < 0:
            break

    return db

def patch_isr(fn, isr_list):
    if len(isr_list) <= 0:
        return

    for isr in isr_list:
        tmplt = cocci_template.replace('<!fn!>', isr)
        with open('/tmp/isr_fix.cocci', 'w') as f:
            f.write(tmplt)

        cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]

        subprocess.run(cmd)

def process_files(path):
    if path.is_file() and path.suffix in ['.h', '.c']:
        p = str(path.parent) + '/' + path.name
        isr_list = find_isr(p)
        patch_isr(p, isr_list)
    elif path.is_dir():
        for p in path.iterdir():
            process_files(p)

if len(sys.argv) < 2:
    print("You need to provide a dir/file path")
    sys.exit(1)

process_files(Path(sys.argv[1]))

And is run: ./fix_isr.py <zephyr root directory>

Finally, some files needed manual fixes such.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka
e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Johan Hedberg
0aa5341ea5 Bluetooth: Mesh: Remove unnecessary #ifdefs from beacon code
Many #ifdefs can be removed, but the UNPROV_BEACON_INT Kconfig
variable needs to be also made available also. This is done by making
its prompt (user selectability) optional rather than the option
itself. This approach is fine for "parameter style" options, but
should probably not be used for feature enabling options.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-09-01 22:00:02 +03:00
Lingao Meng
23ddc90394 Bluetooth: Mesh:Move LPN_SUB_ALL to lpn subgroup
Move BT_MESH_LPN_SUB_ALL_NODES_ADDR to lpn subgroup

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-09-01 22:00:02 +03:00
Lingao Meng
f869e51c25 Bluetooth: Mesh: Add Option config unprov beacon interval
Add Option to specifies the second interval when device
send Unprovisioned Beacon.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-09-01 22:00:02 +03:00
Joakim Andersson
9ac8dcf5a7 Bluetooth: Call bt_recv from priority higher that TX thread.
A build assert in dummy.c lists the following requirement:
[...] receive thread priority shall be higher than the Bluetooth
Host's Tx and the Controller's receive thread priority.
This is required in order to dispatch Number of Completed Packets
event before any new data arrives on a connection to the Host threads.

The drivers uses a priority that is equal to the Host TX thread,
and since they don't use the CONFIG define that is only available
to the controller then this BUILD_ASSERT will not catch the
requirement.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-01 15:15:36 +03:00
Trond Einar Snekvik
18ace841d8 Bluetooth: Mesh: Config client net_key_del
Adds a Config Client API for deleting netkeys on the target node, with
matching shell command.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-09-01 14:49:20 +03:00
Emil Gydesen
9bf50ddb20 Bluetooth: Gatt: Added write callback for gatt (un)subscribe
Added a callback that lets an application get write error
(if any) when subscribing to a gatt characteristic.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-09-01 13:34:25 +02:00
Joakim Andersson
becd9cadfe Bluetooth: host: Fix option USE_IDENTITY for bt_le_ext_adv_* API
Fix option USE_IDENTITY for bt_le_ext_adv_* API.
The random static identity address that was set in bt_le_ext_adv_create
was overwritten in bt_le_ext_adv_start in the call to
le_adv_set_private_addr.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-01 13:28:56 +02:00
Andrzej Głąbek
8e5afef6da bluetooth: controller: nrf5: Add support for nRF52805
Add the nRF52805-specific file with radio related defintions.
Use also specific configurations for certain PPI channels used by
the controller, as this SoC has limited number of programmable PPI
channels.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-08-31 15:40:19 +02:00
Andrzej Głąbek
89c7588917 bluetooth: controller: nrf5: Refactor a bit radio_nrf5_ppi.h
Change hard-coded (D)PPI channel bitfield values to the BIT() macro
calls with the corresponding channel base value supplied as parameter,
to make it possible to actually change this base value if needed.
Remove unused *_EXCLUDE macros.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-08-31 15:40:19 +02:00
Vinayak Kariappa Chettimada
293aa54ef3 Bluetooth: controller: Revert back to using EGU in nRF5340PDK
Refer to nRF5340 Engineering A Errata 29.
[29] SWI: SWIRQ is not functional.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:35 +02:00
Vinayak Kariappa Chettimada
5a40aa073d Bluetooth: controller: nRF53: Use SWI instead of EGU
nRF5340 does have SWI peripheral, hence use it instead of
the single available EGU peripheral. Use of SWI will allow
controller's LLL, ULL_HIGH and ULL_LOW execution context to
be independently configured to different interrupt priority
levels.

When ULL_HIGH priority equals ULL_LOW priority, only SWI2
is used by controller. Otherwise, SWI3 is used for ULL_LOW.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:35 +02:00
Vinayak Kariappa Chettimada
13bbfc8172 Bluetooth: controller: Handle AD data set race condition
Detect and handle AD data set race condition between thread
and ISR context.

Fixes #27637.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:13 +02:00
Vinayak Kariappa Chettimada
530c090cba Bluetooth: controller: Add cpu_dsb hal interface
Add cpu_dsb() hal interface so that data synchronization
barrier be used in ARM Cortex M4 and M33 architecture
implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:13 +02:00
Vinayak Kariappa Chettimada
c0950dc35d Bluetooth: controller: Add volatile to AD data double buffer index
Set the AD data double buffer first index as volatile
because it is modified in LLL ISR context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:13 +02:00
Vinayak Kariappa Chettimada
8b2024e26c Bluetooth: controller: Add code to detect AD data set race
Added code to detect AD data set race condition.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:49:13 +02:00
Vinayak Kariappa Chettimada
58620ec5a7 Bluetooth: controller: Review rework use HCI defines
Use HCI error and command parameter defines.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
139fbb0f4d Bluetooth: controller: Add sync info structure fill function
Refactor out into function the filling of sync info
structure in the common extended advertising payload format
header.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
c85786ff6f Bluetooth: controller: Add aux ptr fill function
Refactor out into function the filling of aux ptr structure
in the common extended advertising payload format header.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
4a2300d2da Bluetooth: controller: Add common header len get/fill function
Refactor out into functions the calculation of common
extended advertising payload format header length.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
3abe58e7f1 Bluetooth: controller: Refactor to allow code reuse
Moved the assignment of PDU length out side of a conditional
so that code to calculate PDU length can be reused.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
3120cddb47 Bluetooth: controller: Refactor out AD data population
Refactor out AD data population to use the common function
ull_adv_aux_hdr_set_clear.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Vinayak Kariappa Chettimada
f69d9ed515 Bluetooth: controller: Refactor sync info population
Refactor out sync info field population into a utility
function with set and clear interface to add or remove
the common extended advertising header format fields.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-31 13:47:36 +02:00
Trond Einar Snekvik
3c8e5b0e1c Bluetooth: Mesh: Network loopback
Changes the local network interface to exclusively handle packets for
the local interface, duplicating the buffers in the process.

The loopback mechanism now operates its own packet pool for the local
interface queue. The loopback is moved ahead of encryption, allowing the
local interface packets to go back up the stack without network crypto,
saving a full round of encrypt/decrypt for self-send.

Packets for group addresses the local node subscribes to are now
duplicated, with one unencrypted variant going into the network
queue, and the network bound packets following the regular path to the
advertiser.

Introduces one new configuration for setting the number of loopback
buffers.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-08-30 17:09:59 +03:00
chao an
00d1408a14 Bluetooth: host: fix build break if enable oob legacy pair only
enable CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY:

In function `bt_le_oob_get_local':
subsys/bluetooth/host/hci_core.c:8878:
		undefined reference to `bt_smp_le_oob_generate_sc_data'

Signed-off-by: chao an <anchao@xiaomi.com>
2020-08-28 12:23:56 +03:00
Flavio Ceolin
9337b782d1 bluetooth: Fix a fallthrough warning
It fixes:

../../../../include/toolchain/gcc.h:169:30: warning: statement will
never be executed [-Wswitch-unreachable]

  169 | #define __fallthrough        __attribute__((fallthrough))

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-27 07:02:40 -04:00
Emil Gydesen
c5636508d4 Bluetooth: host: Deleting PA sync before term callback
The PA sync is now "deleted" (i.e. flags reset) before
the terminated callback is called, so that is
possible to create PA sync in the callback. One flag
was already cleared before for this reason, but one
other flag is also required, so we just clear
everything now.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-26 12:31:59 +02:00
Emil Gydesen
4ee327461f Bluetooth: host: PA sync while explicitely scanning
Removed the check for explicit scanning, such that
an application may create a PA sync while explicitely
scanning.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-26 12:31:59 +02:00
Vinayak Kariappa Chettimada
b5dba35727 tests: Bluetooth: shell: Fix conditional compilations
Fix conditional compilations that fail when combinations
of Broadcaster, Observer, Peripheral and/or Central are
selected to build an application.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-25 16:38:12 +03:00
Vinayak Kariappa Chettimada
2a3e86a2fd Bluetooth: controller: Fix conditional compilations
Fix conditional compilations that fail when combinations
of Broadcaster, Observer, Peripheral and/or Central are
selected to build an application.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-25 16:38:12 +03:00
Vinayak Kariappa Chettimada
be1b634193 Bluetooth: controller: Fix BT_CTLR_SCAN_REQ_NOTIFY dependency
Fix BT_CTLR_SCAN_REQ_NOTIFY as depends on BT_BROADCASTER.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-25 16:38:12 +03:00
Vinayak Kariappa Chettimada
e8e7ccb448 Bluetooth: controller: Fix Adv Set Terminated event cond. compile
Fix the conditional compilation of Advertising Set Terminated
event implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-25 16:38:12 +03:00
Joakim Andersson
5880f3d74f Bluetooth: UUID: Use BT_UUID_16_ENCODE to set UUIDs in adv data
Use BT_UUID_16_ENCODE to set UUIDs in advertising data.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-25 16:09:22 +03:00
Emil Gydesen
689f3b2bc8 Bluetooth: host: per_adv_sync auto scan fixed for central role
If `CONFIG_BT_CENTRAL` was enabled and the device was not scanning
or connected, then `bt_le_per_adv_sync_create` would not start
scanning for periodic advertisers.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-25 15:50:32 +03:00
Lingao Meng
a574d4c840 Bluetooth: Mesh: Enhancement prov segment received
Optimize provisioning segment package received, and
not ignore non-begin segment.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-08-25 15:48:56 +03:00
Kim Sekkelund
41842dd174 Bluetooth: host: GATT Lazyloading cleanup at disconnect
Mark the ram version of the ccc_cfg as free after ccc has been
stored when a bonded device disconnects.
If the device use lazy loading of settings then ccc_cfg was not
cleaned up properly when a bonded device disconnects. This
resulted in the ccc system ran out of ccc_cfg resources after
having disconnected CONFIG_BT_MAX_CONN times.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2020-08-25 15:40:31 +03:00
Kim Sekkelund
29b42c5a2f Bluetooth: host: GATT Relocate bt_gatt_disconnected
Step1: Move bt_gatt_disconnected() to avoid forward declarations which
otherwise would be needed by a fix to lazy loading cleanup on
disconnect in step 2.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2020-08-25 15:40:31 +03:00
Luiz Augusto von Dentz
426fb82bd8 Bluetooth: ATT: Fix not restoring buffer state when send fails
Since bt_l2cap_send_cb can fail returning its error is not enough as
the buffer has been modified to add the headers, so this save the state
before calling bt_conn_send_cb and takes a reference so it can be
restored its original state in case of error.

Fixes #27434

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-08-25 15:22:07 +03:00
Flavio Ceolin
0aaae4a039 guideline: Make explicit fallthrough cases
-Wimplicit-fallthrough=2 requires a fallthrough comment or a compiler
to tells gcc that this happens intentionally.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-24 20:28:47 -04:00
Andrzej Kaczmarek
3006dac9ae Bluetooth: controller: Add privacy handling for LE Scan Request Recv
Scanner address returned in event should be resolved, if possible.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-24 13:28:31 +02:00
Andrzej Kaczmarek
bca3560100 Bluetooth: controller: Use set handle for LE Scan Request Received
Set handle is passed in node_rx header.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-24 13:28:31 +02:00
Andrzej Kaczmarek
37badf0afa Bluetooth: controller: Enable LE Scan Request Received Event
Just need to pass HCI command parameter to LLL.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-24 13:28:31 +02:00
Andrzej Kaczmarek
28238fef71 Bluetooth: controller: Add public scan_req_report function
This will be also used by lll_adv_aux code.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-24 13:28:31 +02:00
Joakim Andersson
c7ad66157d Bluetooth: host: Elevate security to L4 when SC only is enabled
Elevate connections always to security mode 1 level 4 when
Secure Connections Only Mode has been enabled in the Security Manager.

Elevate connections always to security mode 1 level 3 when
Legacy pairing with OOB only has been enabled in the Security Manager.

Fixes: #27338

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-24 10:16:51 +02:00
Andries Kruithof
7ecc55ac84 Bluetooth: controller: consistent HCI error messages
Return BT_HCI_ERR_INVALID_CONN_ID if an invalid handle is
given by the HCI; currently sometimes BT_HCI_ERR_CMD_DISALLOWED
is returned

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-08-19 12:10:33 -04:00
Emil Gydesen
66bd06a7d1 Bluetooth: shell: per_adv_sync cb removed pointer to selected inst
Removed the check for selected_per_adv_sync as it was unused by the
create/delete functions (which take the index as parameters), and
caused the shell not to print any values.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-17 13:44:35 -04:00
Emil Gydesen
6cc0487c46 Bluetooth: shell: Fixed pointer in cmd_per_adv_sync_create
The `free_per_adv_sync` pointer in `cmd_per_adv_sync_create`
did not work as intended, as it didn't actually update the
pointer in the array, which caused the
`cmd_per_adv_sync_delete` to not function as intended.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-17 13:44:35 -04:00
Emil Gydesen
2f527092ca Bluetooth: host: Fixed warning when legacy adv support disabled
If CONFIG_BT_EXT_ADV was enabled but
CONFIG_BT_EXT_ADV_LEGACY_SUPPORT was disabled and
CONFIG_NO_OPTIMIZATIONS was enabled, then there was a
maybe-initialized warning. Fixed by adding additional
checks.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-08-14 17:16:25 +02:00
Andrzej Kaczmarek
236759b18a Bluetooth: controller: Add advertising set handle mapping
Core 5.2, Vol 4, Part E, section 5.3.1 clarifies that advertising set
handle is assigned by host when advertising set is created and this
happens only on LE Set Extended Advertising Parameters.

An advertising set handle is an arbitrary number within allowed range,
i.e. 0x00-0xEF and not 0..max_supported-1.

This patch adds option to enable advertising set handle mapping from
HCI range as defined by Core specification to zero-based handles used
by LL. If enabled, HCI handle will be remapped to LL handle for each
command, otherwise HCI handle will be used as an LL handle. The latter
effectively skips mapping logic and should be used with Zephyr host
which uses zero based indexes.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-13 16:14:29 +02:00
Andrzej Kaczmarek
c6db3c275a Bluetooth: controller: Remove redundant flags for advertising set
There's not need to mark advertising set as created by either legacy
or advertising command since this is determined by current so-called
HCI advertising mode which determines whether host uses legacy or
extended advertising commands.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-13 16:14:29 +02:00
Andrzej Kaczmarek
ae987f3f3a Bluetooth: controller: Disallow mixing legacy/ext adv HCI commands
As per Core 5.2, Part B, section 3.1.1 controller should not allow
mixing of legacy and extended advertising commands. Once 1st command
is received from host, we should only allow commands of the same type
and return an error on other commands.

If legacy advertising interface is selected by 1st command received,
we need to make sure that set with handle=0 is created since it's
used by all legacy commands.

When not using external host, we assume that only extended advertising
interface will be used thus all checks can be skipped (optimized and
compiled-out).

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-13 16:14:29 +02:00
Andrzej Kaczmarek
dd1ac8d0a6 Bluetooth: controller: Add helper for CC event with status only
A lot of commands return CC event with status parameter only, especially
when error is returned. This patch adds a helper to create such event,
similar to cmd_status.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-13 16:14:29 +02:00
Andrzej Kaczmarek
c088b02872 Bluetooth: controller: Fix error code on invalid adv set handle
Proper error code should be returned if advertising set with given
handle does not exist instead of generic "invalid parameters" one.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-13 16:14:29 +02:00
Andrzej Kaczmarek
5f8dd00a6a Bluetooth: controller: Fix return value type
This should match prototype in ll.h.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-13 16:14:29 +02:00
Andrzej Kaczmarek
11cf7ad3ff Bluetooth: controller: Fix set_ext_adv_param returned status
Should not always return success.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-13 16:14:29 +02:00
Andrzej Kaczmarek
ca99404832 Bluetooth: controller: Update scan request handling for ext adv
AdvA in extended advertising PDUs is put at different offset than in
legacy PDUs thus it's better to let caller calculate and pass AdvA and
TxAdd explicitly. This way we won't need to check whether scan request
was on legacy or extended PDU every time.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-08-13 12:26:31 +02:00
Erik Brockhoff
94d5f0854e Bluetooth: controller: fixing error re. all zero chmap in conn-ind
When a connect indication contains a channel map of all zeros, the
adv->conn is left NULL'ed after return and next connect attempt leads
to a crash.

This was identified via the Sweyntooth test suite executing the script
re. issue 6.14 towards an Oticon target.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2020-08-13 12:24:28 +02:00
Joakim Andersson
b0d8758fb6 Bluetooth: host: Split SSP to it's own module
Refactor the BR/EDR SSP feature out into it's own source file.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-11 19:32:35 +02:00
Joakim Andersson
487d2be749 Bluetooth: host: Move reset_pairing call to bt_conn_security_changed
Move call to reset_pairing to bt_conn_security_changed, since this
should always be done at the same time, and should be done in the same
order for all calls. For auth_complete this was reset after the
callbacks, which is inconsistent with the other events.

Also call it even if not connected anymore, the disconnection complete
event will be delivered after this event. Callback should alway be
called if security was initiated.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-11 19:32:35 +02:00
Emil Gydesen
5580cb4391 Bluetooth: host: Periodic adv sync shell support
Added shell support to create and delete a periodic adv sync
object.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-11 14:17:19 +02:00
Emil Gydesen
aea6afe3fa Bluetooth: host: Perodic advertisement synchronization
Added support for syncing to periodic advetisements.
The API and usage is heavily inspired by the extended advertisement
and connection APIs.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-11 14:17:19 +02:00
Emil Gydesen
262a0501de Bluetooth: host: Added scan support for periodic advertisement
Added the ext adv report interval to bt_le_scan_recv_info which
denotes whether or not there is periodic advertisement data
associated with the advertisement report.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-11 14:17:19 +02:00
Emil Gydesen
d5801316d7 Bluetooth: host: periodic adv shell support
Added shell support for periodic advertisement params,
data and enable.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-11 14:17:19 +02:00
Emil Gydesen
8cf01ab590 Bluetooth: host: Add periodic advertising API
Added API to set periodic adv parameters, periodic adv data
and to enable/disable periodic advertisement.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-08-11 14:17:19 +02:00
Rubin Gerritsen
38295e0b73 bluetooth: controller: Add BT_QUIRK_NO_AUTO_DLE for BT_LL_SW_SPLIT
It does not auto-initiate the DLE procedure if the default data length
parameters are not equal to the initial parameters.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-08-10 12:14:49 +02:00
Rubin Gerritsen
5b034e103f bluetooth: hci_driver: Add BT_QUIRK_NO_AUTO_DLE
Some controllers do not follow the recommendation of auto-initiating
a data length update if the host writes default data length parameters.

If the controller follows this recommendation, calling
LE Write Suggested Default Data Length command is sufficient
to ensure that the LL will auto-initiate the DLE procedure. Performing
a second procedure is unecessary.

In Core v5.2, Vol 4, Part E, Section 7.8.35:
The HCI_LE_Write_Suggested_Default_Data_Length command allows the
Host to specify its suggested values for the Controller's maximum
transmission number of payload octets and maximum packet
transmission time for packets containing LL Data PDUs to be used
for new connections. The Controller may use smaller or larger values
for connInitialMaxTxOctets and connInitialMaxTxTime based on local
information.

In short, this command sets connInitialMaxTxOctets
and connInitialMaxTxTime.

In Core v5.2, Vol 6, Part B, Section 4.5.10:

For a new connection: connMaxTxOctets shall be set to
connInitialMaxTxOctets and connMaxRxOctets shall be chosen by the
Controller. If either value is not 27 then the Controller should
initiate the Data Length Update Procedure at the earliest practical
opportunity.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-08-10 12:14:49 +02:00
Joakim Andersson
35201d86ba Bluetooth: GATT: Unregister CCC when unregistering services
Fix issue with bt_gatt_service_unregister not clearing CCC information.

If the service is unregistered while an unbonded peer is connected and
subscribed then this CCC would be restored again when registering the
service even if the peer is now disconnected.

If the service is unregistered with bonded peers CCCs stored in settings
then this value would never be cleared. If the service is registered
again then the peer would receive a service changed for this service,
but it's CCC value would still be enabled.

Fixes: #26924

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-10 12:11:57 +02:00
Joakim Andersson
b2d852be95 Bluetooth: GATT: Extract en queuing of GATT CCC write to a function
Extract enqueue of GATT CCC when CONFIG_BT_SETTINGS_CCC_STORE_ON_WRITE
is enabled to a helper function gatt_ccc_conn_enqueue so that it can be
reused.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-10 12:11:57 +02:00
Joakim Andersson
2919eac891 Bluetooth: GATT: Move clear_ccc_cfg for reuse
Move the clear_ccc_cfg function further up to be re-used without a
forward declaration in bt_gatt_service_unregister.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-10 12:11:57 +02:00
Trond Einar Snekvik
af944ff665 Bluetooth: Mesh: Heartbeat period starts at tx
Starts the periodic heartbeat publish period at the end of the
publication, instead of at the ordering time. This ensures that the
heartbeat period doesn't get shortened by other enqueued messages.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-08-09 09:33:00 -04:00
Trond Einar Snekvik
0221853386 Bluetooth: Mesh: Silence proxy not connected log
When performing node reset over a proxy connection, the disconnection is
asynchronous, and will finish after the reset callback goes to the
application. If the application restarts provisioning in this callback,
the disconnected-event is triggered after PB GATT is reactivated, and
this error is printed without any faults actually occurring.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-08-06 12:56:54 +03:00
Joakim Andersson
97ec4a775e Bluetooth: Host: Notify L2CAP that security change failed
Notify L2CAP when pairing procedure fails during SMP pairing
process. L2CAP needs to be notified so that it can cancel
ongoing connection-oriented channel requests.

Rename bt_l2cap_encrypt_change to bt_l2cap_security_changed and
call it from bt_conn_security_changed always, so that L2CAP
is informed when changing security fails.

This also fixes security_changed conn callback not called when
auth_complete returns an error.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-06 11:47:03 +02:00
Joakim Andersson
42b4719947 Bluetooth: ATT: Avoid warning when no ATT request is pending
Avoid warning in att_handle_rsp, only call this when there is a
pending ATT request. This avoids a warning happens when elevating
security fails but higher security had not been requested by an
ATT request.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>

squash! Bluetooth: ATT: Remove warning when no ATT process pending
2020-08-06 11:47:03 +02:00
Joakim Andersson
53435fdd8f Bluetooth: shell: Add sec_level argument to l2cap connect command
Add argument to set required security level when connection
an L2CAP channel.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-06 11:47:03 +02:00
Joakim Andersson
521034c63d Bluetooth: L2CAP: Release channel when connect request fails
Release the l2cap channel when sending the l2cap connect request
fails.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-06 11:47:03 +02:00
Joakim Andersson
5f00ee1e88 Bluetooth: L2CAP: Elevate security level if requested by application
Elevate the security level before sending the connection request if
the application has set a required security level on the channel.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-06 11:47:03 +02:00
Joakim Andersson
9c3d006471 Bluetooth: L2CAP: Elevate security level when connect request denied
Elevate the security level of the connection when the l2cap channel
connect request is denied with encryption or authentication error
code.
The l2cap channel required_sec_level was used, but this is not
correct as this is set by the user of the API. This resulted in
the call to bt_conn_set_security seeing that the current security
level was already set, decide there is nothing to be done and return
success.

Fixes: #27220

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-06 11:47:03 +02:00
Joakim Andersson
81e297aa88 Bluetooth: L2CAP: Use safe for-each loop where channel can be removed
Use safe for-each loop in bt_l2cap_encrypt_change since dynamic
channels with pending connection-oriented channel requests will
be canceled and removed from the list if the encryption change
failed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-06 11:47:03 +02:00
Joakim Andersson
1d66c1e491 Bluetooth: host: Use CONFIG_BT_L2CAP_RX_MTU always to set L2CAP RX MTU
Remove dependency on CONFIG_BT_ACL_FLOW_CONTROL and use
CONFIG_BT_L2CAP_RX_MTU always to set L2CAP RX MTU.
The ATT MTU is set from two different KConfig options depending
on if CONFIG_BT_ACL_FLOW_CONTROL is enabled, which makes it
a confusing option and hard to provide a conf file that
supports multiple board configurations.

This changes the behavior when CONFIG_BT_ACL_FLOW_CONTROL and
CONFIG_BT_BUF_RX_LEN was used to set the L2CAP RX MTU, and by
extension the ATT MTU.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-06 11:46:48 +02:00
Andrew Boie
d0e4b24453 bluetooth: use kernel stacks
These threads don't run in user mode, save some memory if
userspace is enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-05 21:30:32 -04:00
Dag Bjarvin
e93963b719 Bluetooth: controller: Add ll_adv_aux_set_clear function
Add ll_adv_aux_set_clear, add to bsim test

Signed-off-by: Dag Bjarvin <Dag.Bjarvin@nordicsemi.no>
2020-08-05 12:52:42 +02:00
Vinayak Kariappa Chettimada
77b820a9ea Bluetooth: controller: Fix incorrect use of ticker user id
Fix incorrect use of LLL ticker user id in ULL_LOW execution
context.

Regression introduced in commit 23ef75f6d9 ("Bluetooth:
controller: split: Fix Low Latency Prepare Done").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-08-05 12:02:05 +02:00
chao an
5328adcff5 Bluetooth: Mesh: Fix tx seg buffer with NULL pointer reference
Fix tx seg buffer with NULL pointer reference if enable mesh friendly

Signed-off-by: chao an <anchao@xiaomi.com>
2020-08-04 12:47:05 +03:00
Luiz Augusto von Dentz
6c7a387e9f Bluetooth: ATT: Fix handling to EATT channels
EATT channels use bt_l2cap_chan_send which does return the number of
bytes sent on success not 0 as bt_l2cap_send.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-08-04 10:38:27 +03:00
chao an
9e64d379f0 Bluetooth: Mesh: configurable advertiser stack size
Add a configurable Kconfig option for advertiser thread stack size

Change-Id: Ia59a03311706de929d1833fa46cff66652620e7a
Signed-off-by: chao an <anchao@xiaomi.com>
2020-08-03 13:50:21 +02:00
Vinayak Kariappa Chettimada
dc48999ee1 Bluetooth: controller: Fill event counter in sync info
Fill the referenced event counter of the Periodic
Advertising SYNC_IND PDU into the sync info struct in the
Common Extended Advertising Header Format.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-31 19:04:23 +02:00
Vinayak Kariappa Chettimada
807ee0c849 Bluetooth: controller: Fill Periodic Adv interval in Ext Adv Report
Fill the missing Periodic Advertising interval in the
Extended Advertising Report when Auxiliary PDUs contain
Sync Info fields.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-29 16:39:59 +02:00
Dag Bjarvin
bc0b8cfae1 tests: Bluetooth: shell: Add ll_adv_aux_set_remove function
Add call to ll_adv_aux_set_remove in shell app

Signed-off-by: Dag Bjarvin <Dag.Bjarvin@nordicsemi.no>
2020-07-29 16:37:15 +02:00
Dag Bjarvin
cb3b7863dc Bluetooth: controller: Add ll_adv_aux_set_remove function
Add ll_adv_aux_set_remove function

Signed-off-by: Dag Bjarvin <Dag.Bjarvin@nordicsemi.no>
2020-07-29 16:37:15 +02:00
Joakim Andersson
e82b688c72 Bluetooth: SMP: Reject legacy pairing early in SC only mode
Reject the security request immediately when receiving a security
request that does not support LE Secury Connections pairing.
This would have been rejected during the pairing procedure, but
PTS testing expects the security request to be rejected.

Ref: GAP/SEC/SEM/BV-29-C

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-29 16:07:29 +02:00
Luiz Augusto von Dentz
e536b46a01 Bluetooth: GATT: Fix crash when using CONFIG_BT_CONN_DISABLE_SECURITY
When using CONFIG_BT_CONN_DISABLE_SECURITY bt_gatt_check_perm would
ignore not only the security sensitive permissions but also access
related ones causing crashes since the callback would be NULL.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-07-29 11:17:39 +03:00
Joakim Andersson
73c50dc0bd Bluetooth: Move implementation of hci_driver.h exposed functions
Move implementation of hci_driver.h exposed functions to a common file.
The functions exposed by hci_driver.h header file is implemented in
either hci_core.c, or hci_raw.c. But since these functions would be
identical for both implementations have them in a new file that is
included for both.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-27 13:27:05 +02:00
Vinayak Kariappa Chettimada
10142ab398 Bluetooth: controller: Added some comments for fields in node rx struct
Added internal comments about the use of some of the fields
in the node rx structure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-23 11:39:47 +02:00
Vinayak Kariappa Chettimada
61e7eb907c Bluetooth: controller: Define struct in node rx for adv term event
Defined struct in node rx for passing event parameters of
Advertising Set Terminated Event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-23 11:39:47 +02:00
Vinayak Kariappa Chettimada
cd0e72a91e Bluetooth: controller: Reworked adv set terminate event
Reworked the implementation of Advertising Set Terminate
event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-23 11:39:47 +02:00
Dag Bjarvin
46a622837d Bluetooth: controller: Release term event memory on timeout
Release memory allocated to ext adv terminate event, after timeout

Signed-off-by: Dag Bjarvin <Dag.Bjarvin@nordicsemi.no>
2020-07-23 11:39:47 +02:00
Dag Bjarvin
0df34da5d7 Bluetooth: controller: Terminate event for ext adv
Update to free term event node

Signed-off-by: Dag Bjarvin <Dag.Bjarvin@nordicsemi.no>
2020-07-23 11:39:47 +02:00
Vinayak Kariappa Chettimada
a4eead690d Bluetooth: controller: Adv Set Terminated Evt on duration
Implementation of Advertising Set Terminated Event on
duration sans use of additional variable in advertising
set context structure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-23 11:39:47 +02:00
Dag Bjarvin
12fdddb80d Bluetooth: controller: Add terminate event for external advertising
Add terminate event for duration timeout, max number of events and
connection.

Signed-off-by: Dag Bjarvin <Dag.Bjarvin@nordicsemi.no>
2020-07-23 11:39:47 +02:00
Luiz Augusto von Dentz
75f47a56b5 Bluetooth: Add config option to disable security checks
This adds CONFIG_BT_CONN_DISABLE_SECURITY which can be used to disable
security checks for incoming requests enabling to test accessing GATT
attributes and L2CAP channels that would otherwise require
encryption/authentication in order to be accessed.

It depends on BT_TESTING to indicate to the users that this is a
testing feature which shall not be used in production.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-07-23 11:00:04 +02:00
Andrzej Kaczmarek
38997a5719 Bluetooth: host: Do not set AD on scannable ext adv
Advertising data is not supported on scannable extended advertising
instances.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-07-23 10:58:33 +02:00
Andrzej Kaczmarek
d93489035c Bluetooth: host: Add flag to indicate ext adv set
It should be possible to identify whether advertising set uses legacy
or extended advertising to avoid performing operations that are not
supported on either of them.

For example, scannable advertising can have advertising data set only
if legacy PDUs are used.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-07-23 10:58:33 +02:00
Krzysztof Chruscinski
2b4763076e bluetooth: controller: Adapt to onoff clock control
Adapt link layer to use onoff service when controlling clock.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-07-20 16:22:21 +02:00
Joakim Andersson
c4c0e64331 Bluetooth: host: Fix infinite recursion in persistent advertising
Fix a crash in the persistent advertising handling.
This occurs because the callstack of the RX thread overflowed
due to an infinite recursion between bt_conn_unref and
bt_le_adv_resume.
This happens when starting a new advertiser is denied by the
controller, then the conn object reserved will be released again
and the host will attempt to resume advertising in the bt_conn_unerf
at the end of bt_le_adv_resume.
This situation can happen if the host supports more connections
than the controller.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-20 15:58:36 +02:00
Joakim Andersson
970e921cd7 Bluetooth: hci_ecc: Follow BT spec when public key is invalid
Follow Bluetooth specification recommendation of setting the output
of the DH_Key field in the LE Generate DHKey Complete event when the
public key is invalid.

 If the Remote_P-256_Public_Key parameter of the HCI_LE_Generate_DHKey
 command (see Section 7.8.37) was invalid (see [Vol 3] Part H, Section
 2.3.5.6.1), then all octets of the DH_Key event parameter should be
 set to 0xFF.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-20 12:48:23 +02:00
Trond Einar Snekvik
f8663774de Bluetooth: Mesh: Document shell commands
Adds a high-level documentation page for the Bluetooth Mesh Shell
subsystem, documenting all available commands and their parameters.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-07-20 12:47:31 +02:00
Vinayak Kariappa Chettimada
4bf2a0d520 Bluetooth: controller: Make coding style around ret_cb consistent
Updated implementation to have consistent initialization of
ret_cb use when passing it to ticker function calls.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-20 12:46:54 +02:00
Vinayak Kariappa Chettimada
13f079f212 Bluetooth: controller: Fix missing ticker status initialization
Fix missing ticker status callback return value
initialization.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-20 12:46:54 +02:00
Vinayak Kariappa Chettimada
c9332e76b3 tests: Bluetooth: shell: Remove cmd_ull_reset
Remove cmd_ull_reset command, as this would put the host out
of sync. Also, this command is seldom used/required.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-20 12:46:26 +02:00
Vinayak Kariappa Chettimada
293a2f69d0 Bluetooth: controller: Remove redundant BT_LL_SW_SPLIT conditional
Remove redundant use of BT_LL_SW_SPLIT conditional.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-20 12:46:26 +02:00
Emil Gydesen
5b59c002f6 Bluetooth: Gatt: Automatic discover of CCC when subscribing
Added a feature that allows an application to request
automatic discovery of the CCCD handle when subscriping
to a characteristic. In order to preserver RAM, the application
is expected to provide the discovery parameters, and it's up
to the application whether or not it wants to reuse the
discovery parameters or use one for each characteristic.

Signed-off-by: Emil Gydesen <emil_gydesen@bose.com>
2020-07-20 12:46:18 +02:00
Rubin Gerritsen
742358c6a6 bluetooth: controller: Kconfig: debug pins depends on BT_LL_SPLIT
When BT_LL_SPLIT is not selected, it should not be visible.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-07-17 12:57:49 +02:00
Rubin Gerritsen
f9b19186f5 bluetooth: controller: Kconfig: Move LL version config to split ll
These configs are not generic.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-07-17 12:57:49 +02:00
Rubin Gerritsen
cd63479f2e bluetooth: controller: Kconfig: Move RX_PRIO configs to split ll
These configs are not generic

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-07-17 12:57:49 +02:00
Rubin Gerritsen
6c7ed9627e bluetooth: controller: Kconfig: Move LLL selection to split config
The dependency to LL_SPLIT is removed.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-07-17 12:57:49 +02:00
Rubin Gerritsen
1ec8b0ff0a bluetooth: controller: Kconfig: Move split LL helper configs to file
These configs are not generic.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-07-17 12:57:49 +02:00
Rubin Gerritsen
eea9d258a3 bluetooth: controller: Kconfig: Split out split config to new file
By splitting it out to a separate file, it will become easier to
separate generic and non-generic controller features.
This commit only contains the simple extraction.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-07-17 12:57:49 +02:00
Vinayak Kariappa Chettimada
8666236bc6 Bluetooth: controller: Fix overflow due to use uninitialised PDU
Fixed memory corruption when using uninitialised previous
PDU to populate current PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-16 14:43:46 +02:00
Trond Einar Snekvik
6b5c2e02d3 Bluetooth: Mesh: Transport seg send timeout
Resolves a corner case where the segmented sending would be rescheduled
before the segments were done sending. This would happen if the
processing of each segment took longer than the retry delay. The
consequence of this was that some segments were resent multiple times at
the cost of other segments, occasionally causing a loss of transfers.

Rearranges, realigns and documents seg_tx structure bitfields in
transport.c. Removes bitwidth of counter fields, and collecting all flag
fields into one byte.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-07-16 13:10:42 +02:00
Wolfgang Puffitsch
da5eff8087 Bluetooth: controller: Enforce support for Read RSSI command in Kconfig
Enforce support for Read RSSI command if BT_CONN and BT_HCI_RAW are
selected. According to the Bluetooth specification, support for the
Read RSSI command is mandatory if the Connection State is
supported. BT_HCI_RAW indicates that the controller is an
independently qualifiable module and not part of a combined
host/controller build. This change avoids a configuration that cannot
be possibly qualified.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-07-16 12:13:37 +02:00
Marek Pieta
a6e8cf4374 bluetooth: gatt: Fix storing subscriptions
Change fixes storing subscriptions in settings. CCC write can interrupt
the ccc_delayed_store. Without the change, new CCC was not stored in
non-volatile memory and the work that stored CCC was not resubmitted.
That resulted in lost subscription after reboot.

Fixes: #26862

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2020-07-16 12:13:22 +02:00
Vinayak Kariappa Chettimada
6ecd5e56ed Bluetooth: controller: Minor refactor of sync implementation
Minor refactoring of code in periodic advertising
implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-16 12:12:41 +02:00
Vinayak Kariappa Chettimada
be72282be5 Bluetooth: controller: Refactor sync enabled and started states
Refactor implementation to perform enable and started state
updates at consistent places in code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-16 12:12:00 +02:00
Vinayak Kariappa Chettimada
d3457d1f12 Bluetooth: controller: Refactor sync PDU variable names
Refactor and use variable name ter_pdu for periodic
advertising PDU pointers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-16 12:11:19 +02:00
Vinayak Kariappa Chettimada
6a862b9862 Bluetooth: controller: Non-overlapping sync PDUs
Updated implementation to schedule non-overlapping
ADV_EXT_IND, AUX_ADV_IND, and AUX_SYNC_IND PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-16 12:11:04 +02:00
Joakim Andersson
d6b526a038 Bluetooth: shell: Add bond_deleted callback
Add the bond_deleted callback to the bluetooth shell.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-16 12:09:57 +02:00
Joakim Andersson
4876923085 Bluetooth: shell: Use selected ID when selecting default connection
Use the selected local ID when switching the default connection.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-16 12:09:57 +02:00
Joakim Andersson
71ab1ec5a7 Bluetooth: host: Add bond_deleted callback
Add bond_deleted callback so that the application can keep track
of when bond information is deleted in the stack.
Bond information can be deleted by the application through bt_unpair
or automatically by the stack in some cases, e.g when
CONFIG_BT_KEYS_OVERWRITE_OLDEST is enabled and the oldest bond
is overwritten.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-16 12:09:57 +02:00
Joakim Andersson
ae4ac87a91 Bluetooth: shell: Add advertising options one-time and directed privacy
Add advertising option for undirected one-time advertising, and
directed advertising using identity, and peer direct is RPA option.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-15 17:49:20 +02:00
Joakim Andersson
411bd99982 Bluetooth: shell: Print PHY and data len info in info command
Print the PHY and data len information from the conn info struct.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-15 15:12:45 +02:00
Joakim Andersson
8482ab64e0 Bluetooth: host: Start persistent advertiser with max conn reached
Allow calling bt_le_adv_start with no connection object available
when not the option BT_LE_ADV_OPT_ONE_TIME has been set. In this
case the advertiser will be restarted once there is a connectable
advertiser object available.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-15 15:12:28 +02:00
Vinayak Kariappa Chettimada
2ca56a2ab7 Bluetooth: controller: Add missing aux acquire on periodic adv
Added implementation to acquire and initialize auxiliary
channel instance on use of periodic advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-14 12:52:41 +02:00
Luiz Augusto von Dentz
ede13428e7 Bluetooth: GATT: Fix not being able to notify
When CONFIG_BT_GATT_NOTIFY_MULTIPLE is selected and the remote has
enabled support for using its procedure data can sometimes not fit
into the buffer since the multiple variant has a bigger header, so
instead of failing immediatelly this attempts to send the data using
the legacy PDU instead so those using bt_gatt_get_mtu - 3 can still be
sent.

Fixes #26106

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-07-13 12:23:48 +02:00
Rubin Gerritsen
8561fc9563 bluetooth: controller: Kconfig: Add dependency when ADV_EXT is y
BT_CTLR_SCAN_REQ_NOTIFY is only available for BT_LL_SW_SPLIT

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-07-13 11:54:17 +02:00
Rubin Gerritsen
82b3276777 bluetooth: controller: ADV_EXT enabled by default
Enable Advertising Extensions by default if supported by the controller.
That is, do not enable it by default for BT_LL_SW_SPLIT.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-07-13 11:54:17 +02:00
Asbjørn Sæbø
1886cb4b4e Bluetooth: Shell: Add shell command to output the ATT MTU size
It is sometimes useful to know what the ATT MTU size is.

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
2020-07-10 13:14:30 +02:00
Marek Pieta
4e43e00c4c Bluetooth: controller: Safe default value of BT_CTLR_LLCP_CONN
Change sets default value of Kconfig option BT_CTLR_LLCP_CONN to
BT_MAX_CONN. The default value should properly handle the worst case.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2020-07-09 19:08:50 +02:00
Vinayak Kariappa Chettimada
dc55538645 Bluetooth: controller: Fix missing skip value calculation
Fix missing recalculation of skip value of the ticker being
inserted into ordered list, when it collides and is being
attempted to be inserted at next periodic interval.
This fix is for ticker compatibility mode which is used as
default for nRF51 series.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-09 19:08:35 +02:00
Trond Einar Snekvik
cb7835d18f Bluetooth: Mesh: Wait for proxy on node reset
Adds idle wait callback to proxy by counting the number of pending
notifications.

Ensures that all connected nodes have received messages before resetting
the mesh stack.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-07-09 13:49:26 +02:00
Vinayak Kariappa Chettimada
eb2a64989b drivers: flash: nrf: Fix flash operation timeout
Fix flash operation timeout due to incorrect use of
secondary ticker to abort any radio in use. Ticker id 0
is reserved for split controller's pipeline preempt timeout.
Using the same ticker id caused the secondary ticker to
not be started if controller is using the same ticker id
for pipeline preempt timeout.

Fixes #26333.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-09 07:17:41 -04:00
Michał Narajowski
67ab8a3173 Bluetooth: Mesh: Fix response to Provisioning PDU with invalid type
Reverse the order of these checks because invalid PDU type will
never be expected. If PDU type is invalid we should respond with
error 0x0002 - Invalid format.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-08 10:19:02 +02:00
Vinayak Kariappa Chettimada
2b45736f28 Bluetooth: controller: Add Periodic Advertising HCI integration
Add implementation to integrate the HCI Periodic Advertising
interface.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-07 15:04:51 +02:00
Joakim Andersson
c3308275f6 Bluetooth: GATT: Turn GATT notify multiple feature default off
Turn the GATT notify multiple feature off as default value.
This feature changes the behavior of the bt_gatt_notify API in a way
that might not be backwards-compatible.
This is because the notify multiple header is larger, and therefore
limits the amount of bytes that could otherwise have been sent in a
normal notify PDU for a given ATT MTU.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 16:50:36 +02:00
Joakim Andersson
1d27450954 Bluetooth: host: Fix conn_handle in LE Advertising Set Terminated evt
Fix use of conn_handle in LE Advertising Set Terminated event not
converting from serial Little Endian to native CPU endianness.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 16:49:28 +02:00
Vinayak Kariappa Chettimada
6adfc9bfba Bluetooth: controller: Fix Periodic Adv Data Set parameter list
Fix the parameter list of Periodic Advertising Data Set
interface.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-06 16:49:19 +02:00
Joakim Andersson
4f7505cb10 Bluetooth: host: Unspecified disconnect reason for no pending conn
Use an unspecified reason when disconnecting a connection that did not
have a pending connection in the host.
We don't allocate connection objects in the connection complete anymore
so using memory-capacity-exceeded is misleading.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 14:39:30 +02:00
Joakim Andersson
52f9c0dd46 Bluetooth: host: Fix resume advertiser race condition
This patch fixes an issue with the advertiser not resuming connectable
advertiser if the last bt_conn_unref happens from something other
than the disconnected callback.
In this case this last bt_conn_unref was from gatt.c notify_cb called
from application main thread.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 11:15:39 +02:00
Joakim Andersson
4be66bd33d Bluetooth: Fix host RX thread deadlock
Fix host RX thread being deadlocked. The deadlock occurs because the
RX thread is stuck waiting in conn_tx_alloc with K_FOREVER but if the
connection is disconnected only the RX thread can unblock it in the
handling of the disconnect event.

This commit fixes this deadlock by splitting the processing of the
disconnected event into two parts.
The part needed to unblock the RX is to release resources held by
unack'ed TX packets and mark the connection state as not connected
anymore.
The RX thread waiting for free_tx fifo and the TX thread waiting for
the bt_dev.le.pkts semaphore will both check the connected state after
having acquired them and will abort if disconnected.
The rest of the processing will be handled at normal RX thread
priority like normal.

Move the bt_recv_prio handling to the Bluetooth host when the host
has defined its own RX thread (CONFIG_BT_RECV_IS_RX_THREAD=n).
If the HCI driver has the RX thread (CONFIG_BT_RECV_IS_RX_THREAD=y),
then the responsibility to call bt_recv and bt_recv_prio correctly
falls to the HCI driver.
The helper function bt_hci_evt_is_prio() is replaced with
bt_hci_evt_get_flags() so that the HCI driver can do this correctly.
This decision to replace was made so that existing HCI drivers
maintained out-of-tree will fail at compile time with the new system.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>

Bluetooth: host: Move bt_recv_prio to host when RX thread is defined

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 11:15:39 +02:00
ZhongYao Luo
ddf5152bb8 Bluetooth: br/edr: store link key
Save link key to settings_subsys, no need to re-pair after restart.
Overwrite old pairing records with aging counts.

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2020-07-02 16:32:41 +03:00
Andries Kruithof
2bfb128463 Bluetooth: shell: allow multiple parameters for bt hci-cmd
The hci-cmd currently accepts only a 1 byte parameter. This
disables use of commands that requires more than 1 byte,
for ex. the feature exchange that requires a 16 bit parameter.

This commit allows a datafield parameter up to 65 bytes long.
65 bytes comes from the nr. of parameters for the
HCI_LE_Generate_DHKey command

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-07-02 16:32:04 +03:00
Michał Narajowski
91761767dd mesh: Ignore Friend Request from local interface
Friend Request is also transmitted over local queue and
if both Friend and LPN features are enabled then we would
try to establish friendship with ourselves.

Fixes MESH/NODE/FRND/LPN testcases.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski
1e29b2dceb mesh: Replace hardcoded duplicate cache size
The hardcoded value was arbitrary and interfered with message cache
mechanism causing invalid behavior and PTS test to fail.

Fixes MESH/NODE/RLY/BV-02-C.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski
cc6d9f1072 mesh: Do not ignore message with DST as RFU group address
According to Mesh Profile Test Specification we should still
relay messages with DST address that is RFU.

Fixes MESH/NODE/RLY/BV-01-C.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski
3e7c64dda9 mesh: Fix net_buf leak in advertising provisioning bearer
Unsegmented buffer in bearer_ctl_send was not unrefed causing
a memory leak.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski
73e1cccdbb mesh: Fix Vendor Model Subscription Get procedure
Invalid argument was passed to bt_mesh_model_tree_walk.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski
addbdb0d00 mesh: Fix key refresh procedure
Key refresh procedure was ignored on non-primary subnet.

Mesh Profile Specification v1.0.1:
3.10.4 Key Refresh procedure
"This procedure is used when the security of one or more network
keys and/or one or more of the application keys has been compromised
or could be compromised."

"It is possible to update each NetKey independently of all other
NetKeys. A Key Refresh procedure for one NetKey can be in a different
phase to another Key Refresh procedure for other NetKeys."

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski
9a0602417a mesh: Add reset link functionality to provisioning bearers
Reset provisioning bearers when bt_mesh_reset() is called. Accept
another provisioning attempt after link close.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski
5e543a2366 mesh: Add a define representing max transaction id
This value was used quite often in the file so adding a
descriptive name should improve readability.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski
ebabba3684 mesh: Start protocol timer on send message in advertising bearer
Protocol timer was not started when sending a control message
in advertising bearer.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Michał Narajowski
df426abe53 mesh: Fix resending provisioning link ack
The comparison of a current tx link transaction id caused
us to not send ack and in effect fail provisioning.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2020-07-02 16:30:01 +03:00
Joakim Andersson
16763ff9b6 Bluetooth: host: Fix adv object not released on directed adv timeout
Fix the advertise object not release when a high-duty cycle directed
advertiser timeout happens. If the extended advertising feature has been
enabled in the host, but not supported by the controller then the
advertising object must be released in the connection complete event
since there will not be a advertising set terminated event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-25 19:34:16 +02:00
Joakim Andersson
0b1af81daa Bluetooth: controller: Fix non-privacy directed advertiser
Fix issue with directed advertiser not accepting connection request
from non-privacy enabled peer that has given us a non-zero IRK.
When device privacy is enabled then ull_filter_lll_rl_addr_allowed will
return true, and update the rl_idx to entry in the resolving list.
When the directed advertiser is not privacy enabled then lll->rl_idx is
set to FILTER_IDX_NONE and will not use RPA for the target address.
The check rl_idx != lll->rl_idx will then fail (0 != 0xff) and the
connect request is denied, even though all addresses matches on-air.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-25 12:11:02 +02:00
Trond Einar Snekvik
5ea787c794 Bluetooth: Mesh: Keep PB-GATT callback through disconnect
Removes the memset of the prov_bearer_cb in PB-GATT during resets. This
allows the provisioning link to disconnect and reconnect again without
having to call pb_gatt_open.

Fixes #26343.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-06-23 19:22:58 +02:00
Vinayak Kariappa Chettimada
1af8c136a7 Bluetooth: controller: Add explicit opcode check in unknown rsp PDU
Add explicit opcode check when handling received unknown
response PDU.

Without this, for example, an in progress Data Length Update
procedure state was reset when receiving an unknown response
to slave initiated feature request.

Fixes #26252.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-22 12:33:22 +02:00
Joakim Andersson
0f67f6cb72 Bluetooth: shell: Add phy procedure options to the shell
Add command line options to set the PHY options coding schemed and
no preference.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-19 13:42:29 +02:00
Joakim Andersson
1d0b03bb37 Bluetooth: host: Add phy update procedure options
Add options for phy update procedure. User can now set no preference
option for a particular PHY as well as preference for LE Coded PHY
coding scheme.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-19 13:42:29 +02:00
Luiz Augusto von Dentz
0742a45ac9 Bluetooth: shell: Add support for printing the write rate
This makes the gatt metrics also available for
gatt write-without-rsp-cb so it now prints the rate of each write:

uart:~$ gatt write-without-response-cb 1e ff 10 10
Write #1: 16 bytes (0 bps)
Write #2: 32 bytes (3445948416 bps)
Write #3: 48 bytes (2596929536 bps)
Write #4: 64 bytes (6400 bps)
Write #5: 80 bytes (8533 bps)
Write #6: 96 bytes (10666 bps)
Write #7: 112 bytes (8533 bps)
Write #8: 128 bytes (9955 bps)
Write #9: 144 bytes (11377 bps)
Write #10: 160 bytes (7680 bps)
Write #11: 176 bytes (8533 bps)
Write #12: 192 bytes (9386 bps)
Write Complete (err 0)
Write #13: 208 bytes (8533 bps)
Write #14: 224 bytes (9244 bps)
Write #15: 240 bytes (9955 bps)
Write #16: 256 bytes (8000 bps)

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz
0028559860 Bluetooth: ATT: Fix using of k_fifo_{put,get}
These functions don't work with buffers that do have fragments, instead
this replaces their usage with net_buf_{put,get}.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz
5aac983419 Bluetooth: ATT: Fix low throughput
ATT_PENDING_SENT does severely impact the throughput since multiple
packets no longer can be scheduled at same time, so instead of always
setting it regardless of the bearer/channel it is now only used for
EATT since that cannot set its own callbacks.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz
3ae926c0f1 Bluetooth: ATT: Fix not returning error
bt_l2cap_send_cb may fail if there are no context available which means
that the request would not be sent, also due to the use of custom
callback it cannot be queued either so the only option is to return the
error and let the application handle it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz
bc7ce86ac5 Bluetooth: ATT: Fix not processing pending requests
Since the TX semaphore is used for all types of PDUs a request may have
to be put on the request list while there is no pending request pending
which means no response will be generated to trigger att_process,
previously this condition was handled by setting the request as
currently pending and append its buffer to tx_queue but this is no
longer efficient since there could be more than one channel active the
code should try all of them before queueing back to request list.

To fix this the request list will now be processed each time a PDU has
been sent.

Fixes #26070

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz
4418ba76a5 Bluetooth: ATT: Fix overwritting sent callback
ATT channel sent callback shall not be overwritting until the
operation completes as it can result in breaking flow control when
CONFIG_BT_ATT_ENFORCE_FLOW is enabled.

Fixes #25964
Fixes #26071

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
chao an
95e4eb8867 Bluetooth: Mesh: fix different signedness
CC:  subsys/bluetooth/mesh/prov.c
subsys/bluetooth/mesh/prov.c: In function 'bt_mesh_input_string':
subsys/bluetooth/mesh/prov.c:616:14:
        warning: pointer targets in passing argument 1 of
        'strncpy' differ in signedness [-Wpointer-sign]
  616 |  strncpy(link.auth, str, prov->input_size);
      |          ~~~~^~~~~
      |              |
      |              uint8_t * {aka unsigned char *}

Signed-off-by: chao an <anchao@xiaomi.com>
2020-06-18 13:17:24 +02:00
Joakim Andersson
e4af41acc2 Bluetooth: kconfig: Disable advertising extension until feature complete
Disable the controller advertising extension feature default setting
until the feature is complete. The zephyr host requires the
LE Advertising Set Terminated event to function.
Without this event a peripheral connection cannot pair because the
local on-air address is not set, and the advertising state will not be
cleaned up, so advertising cannot be started again.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-17 17:09:59 +02:00
Trond Einar Snekvik
ca901c2149 Bluetooth: Mesh: Null check buf before unref
The frnd->last buffer can potentially be NULL if friend_clear is called
after the adv.c buf->busy check, but before the adv_start callback.
The current design is based on the adv.c thread being cooperative, and
therefore not yielding between the busy check and the adv_start
callback, but as the bt_le_adv_start call has to acquire a semaphore,
there's a possibility for friend_clear being called inbetween.

Fixes #26177.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-06-17 17:09:36 +02:00
Carles Cufi
88f25df9ac Bluetooth: smp: Warn on enabling several Bluetooth options
Add warning about enabling the options below so that users are
aware that this is a security risk.

- CONFIG_BT_DEBUG_SMP
- CONFIG_BT_DEBUG_KEYS
- CONFIG_BT_OOB_DATA_FIXED
- CONFIG_BT_USE_DEBUG_KEYS
- CONFIG_BT_STORE_DEBUG_KEYS

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-06-17 17:14:33 +03:00
Joakim Andersson
f756b79124 Bluetooth: controller: Use NRF RNG entropy device
Use the NRF RNG entropy device as the entropy device for bt_rand and
controller internal functions when LLL is Nordic.
Using an entropy source with a significant increase in stack usage
will invalidate all stack size configurations in the system and lead
to stack overflow issues.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-16 19:09:55 +02:00
Vinayak Kariappa Chettimada
69ef82f22f Bluetooth: controller: Fix missing RADIO_TXP_DEFAULT define
Fix compile error due to missing include file that defined
RADIO_TXP_DEFAULT.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-16 17:48:59 +02:00
Vinayak Kariappa Chettimada
a20ecb6722 Bluetooth: controller: Fix compilation regression
Fix compilation regression due to addition of const
qualifier to tx_pwr_lvl parameter of ll_tx_pwr_lvl_set
function. Support for BT_CTLR_TX_PWR_DYNAMIC_CONTROL
needs the tx_pwr_lvl to be updated and returned.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-16 17:48:59 +02:00
Carles Cufi
8617e93b84 Bluetooth: controller: Work around compiler silliness
For some reason GCC 9.x doesn't seem to be able to realize that set_num
will always be > 0 and so the local variable status will always be
initialized. Use a do {} while instead to keep it happy.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-06-12 22:58:05 +02:00
Vinayak Kariappa Chettimada
d048570ec5 Bluetooth: controller: Re-arrange Kconfig options
Re-arrange and have conditional prompt for BT_CTLR_ADV_EXT.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
3d78a16d81 Bluetooth: controller: split: Fix initialization of new aux header
Fix missing implementation of initialization of common
advertising header bit fields when new auxiliary channel PDU
is instantiated. This caused corrupt invalid Bluetooth
Device address being copied from uninitialised previous
auxiliary PDU instead of copying from primary channel PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
205fe1825e Bluetooth: controller: split: Refactor auto variable names
Review rework updates, refactor auto variable names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
130d63a1c2 Bluetooth: controller: split: Review rework use defines
Review rework updates, use defines in place of magic values.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
5d13bf4e98 Bluetooth: controller: split: Fix endianness in filling DID
Handle endianness when filling the DID value in advertising
PDU extended header.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
06cba0d4e3 Bluetooth: controller: split: Move aux_offset_fill into ULL files
Move the aux pointer fill function to ULL files, so as it is
re-usable by all vendors.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
15d3711a75 Bluetooth: controller: split: Remove +1 magic ticks and microseconds
Remove use of magic numbers to adjust ticks offset, replace with
vendor defines.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
2037ebd58a Bluetooth: controller: Set Extended Advertising feature bit
Update supported features bitmap with Extended Advertising
bit.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
e20455b9cc Bluetooth: controller: split: Fix ext create conn when coded PHY unsupp
Fix implementation from performing a redundant loop checking
for coded PHY create connection parameters in HCI command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
28f4c1b703 Bluetooth: controller: split: Rework with defines for adv set states
Review rework, added comments, TODOs, FIXMEs and converted
magic number use in advertising set state flags to defines.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
322561c6bb Bluetooth: controller: split: Disable all adv sets unsupported
Added comments and code to make note that disabling all
advertising sets is not yet implemented.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
95d3d5be2a Bluetooth: controller: Refactor pdu.h defines
Refactor pdu.h defined in anticipation of reused in
Advertising Extensions implementation. To reuse in
calculating ticks_slots etc.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
a682fe63eb Bluetooth: controller: added Kconfig for max adv data length
Added a Kconfig for maximum advertising data length.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
dc55e08ce6 Bluetooth: controller: split: Fix crash due to incorrect no. of tickers
Fix segmentation fault detected by BabbleSim test due to
incorrect number of tickers being allocated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
688ddc4db6 Bluetooth: controller: split: Fix directed adv addr type returned
Fix HCI LE Directed Advertising Report event to return
correct directed advertiser's address type.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
0d6476248a Bluetooth: controller: split: Fix auxiliary channel scan window width
Fix the calculation of auxiliary channel scan window width.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
c2b7f15556 Bluetooth: controller: split: Avoid ticker null pointer dereferencing
Avoid ticker from null pointer dereferencing when storing
operation callback functions to be called during collision
resolution.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
af90f17758 Bluetooth: controller: split: Fix conditional compile of ticker ids
Fix conditional compile of ticker ids for auxiliary sets and
periodic sets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
516bae9536 Bluetooth: controller: split: Fix scan set allocation
Fix scan set allocation using BT_CTLR_SCAN_SET instead of
an incorrect duplicate BT_CTLR_SCAN_MAX.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
18995306f1 Bluetooth: controller: split: Fix Ext Scanning when coded PHY unsupported
Fix implementation from starting coded PHY scan window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
1aa9ca244f Bluetooth: controller: split: Fix compile error in periodic adv code
Fix copy-paste compile error in the implementation of the
periodic advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
8eebc2e926 Bluetooth: controller: Integrate extended adv report into HCI
Integrate the generated extended adv report PDU list into
HCI layer to generate the HCI LE Extended Advertising Report
event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
0c058badf2 Bluetooth: controller: split: Change the extended scan PDU rx list
Change the implementation of extended scan PDU rx list to use
the extra pointer as the next field in the linked list node.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
fbf91da922 Bluetooth: controller: split: Extended scanning Rx list
Added implementation to enqueue received auxiliary PDUs in
the ULL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
97355e4799 Bluetooth: controller: split: Fix for missing Aux PDU
Fix missing Auxiliary PDU when primary PDU is calculating
the offset. Schedule the auxiliary PDU ticker before primary
PDU ticker is scheduled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
23ef75f6d9 Bluetooth: controller: split: Fix Low Latency Prepare Done
Fix the Low Latency Prepare Done that disables ULL_LOW
context executions inside a radio event, so that
ticker_job_idle_get is invoked from ULL_LOW instead of LLL
context so that its enqueued alongwith others scheduled
in ULL_LOW. This is avoid premature disable of ULL_LOW
context executions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
e9bee3b070 Bluetooth: controller: split: Updated HCI BT_INFO of scanned PDU
Updated HCI BT_INFO of printing the parsed extended PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
45231fd071 Bluetooth: controller: split: Fix missing enh conn complete HCI event
When Privacy is not supported in the build and Advertising
Extensions is enabled, HCI LE Enhanced Connection Complete
event was missing. This is fixed now.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
fa91a80f28 Bluetooth: controller: split: Port openisa files
Port OpenISA LLL files to reflect some of the changes done
in Nordic LLL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
e51167b787 Bluetooth: controller: split: Fix to stop preempt ticker
Fixed premature abort of events due to stale preempt ticker
expiry.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
4702d9cead Bluetooth: controller: split: Minor refactor return variable
Minor refactor return variable name and fix return value
type.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
ef97208eeb Bluetooth: controller: split: Fix DID increment
Fix missing DID increment when AD data changed to zero len.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
cc2cb6a347 Bluetooth: controller: split: Fix incorrect adv_addr type
Fix incorrect adv_addr type in auxiliary PDU when address
is removed from primary and added to auxiliary PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
e099cfd6d7 Bluetooth: controller: split: Add correct aux scan ticks slot
Implemented the missing ticks_slot calculation for the
auxiliary channel PDU scanning window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
cb3024fe86 Bluetooth: controller: split: Fix slave HCTO calculation
Fix missing sleep clock accuracy related jitter in the
header complete timeout calculation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
746ffdc194 Bluetooth: controller: split: Add Extended Scanning window widening
Added implementation to calculate the window widening for
the reception of auxiliary PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
e9c80f8534 Bluetooth: controller: split: Initial extended scanning code
Initial extended scanning code added.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
6a86307ad4 Bluetooth: controller: split: Abort auxiliary LLL if aux_ptr missing
Abort Auxiliary LLL prepare if current primary PDU is
missing the aux_ptr.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
29f26bac24 Bluetooth: controller: split: Schedule auxiliary after primary PDU
Fix to avoid a crash due to missing aux_ptr in current
primary PDU constructed by LE Set Extended Advertising
Parameter Set, while aux_ptr was populated by LE Set
Extended Advertising Data Set in the latest double buffered
PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
9a82f38435 Bluetooth: controller: split: Fix extended event properties changes
Added implementation to handle updates to adv mode and event
properties of an already created advertising set.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
6c2bccfb09 Bluetooth: controller: split: Refactor PKT_US for Adv. Ext. use
Refactor the PKT_US for reuse with Extended Scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
e0bd57901f Bluetooth: controller: split: Use uint8_t for advertising handles
Refactor to use uint8_t for advertising handles.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
d6cc180168 Bluetooth: controller: Fix collision resolution for single-shot ticker
Fix collision resolution to consider single-shot ticker,
current single-shot with ticks_slot as older that a next
periodic or single-shot ticker with ticks_slot.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
35d9933597 Bluetooth: controller: Fix single-short ticker operation failure
Fix ticker to correctly generate the operation callback if
single-shot ticker fails to be scheduled and does not
expire.

As the collision resolution is deferred to the worker, if
a single-shot ticker is cancelled, then appropriately call
the operation callback with failure status. This is allow
the user to take necessary actions, like release resources
allocated that need to be release on the failure to schedule
the single-shot ticker expiry.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
ba9b065c13 Bluetooth: controller: split: Move PKT_US into pdu.h
Move the definition of PKT_US into pdu.h so that it can be used
by Advertising Extensions implementations too.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
5d6c4a6cb5 Bluetooth: controller: split: Refactor node_rx_ftr
Remove us_radio_rdy field in the footer structure as its always
a constant value which can be obtained using a functional
interface to HAL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
0681c80573 Bluetooth: controller: Fix to use advertiser random address
Fix legacy advertising started using Extended Advertising
sets to use the set advertising random address.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
c89c94f940 Bluetooth: controller: split: Workaround succeed on zero len scan rsp set
Added a workaround to succeed setting a zero length Extended
Scan Response Data.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
3527778c41 Bluetooth: controller: split: Fix extended scan param set
Fix missing reset of phy struct member for scan set that is
not being enabled by use of LE Extended Scan Parameter Set
command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
281fa4c4a9 Bluetooth: controller: split: Allow set rand addr when using ext cmds
Allow use of HCI LE Set Random Address cmd when advertising
is enabled using Extended Advertising commands.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
eb102d7822 Bluetooth: controller: split: Fix missing coded PHY scanning
Fix, use phy variable instead of type to determine if
scanning on Coded PHY is to be enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
a40b1e9212 Bluetooth: controller: hci: Integrate LE Ext. Create Connection
Integrate the support for HCI LE Extended Create Connection.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
a74276e1bd Bluetooth: controller: split: Added LE Ext. Create Connection
Added implementation of LE Extended Create Connection.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
b87cae97bb Bluetooth: controller: split: Add generate of ext adv legacy report
Added implementation to generate LE Extended Advertising
Report for received legacy PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
d9523c5005 Bluetooth: controller: split: SCAN_RSP for ADV_IND or SCAN_IND
Added implementation to differentiate SCAN_RSP received for
ADV_IND or SCAN_IND PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
60a117c6ca Bluetooth: controller: split: Add the missing enable of dup filtering
Add implementation to enable duplicate filtering for extended
scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
24e3fd521e Bluetooth: controller: split: Fix missing reset of scanner state
Fix missing reset of scanner state which could cause a
spurious SCAN_RSP packet without a prior SCAN_REQ being sent
to be reported.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
608063b3ec Bluetooth: controller: hci: Indent BT_INFO of extended header
Indent when logging out the field value of common extended
advertising header format.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
561354dde2 Bluetooth: controller: hci: Integrate Adv Extensions commands
Integrate Advertising Extensions related Extended Advertising
and Extended Scan HCI commands.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
e941e72092 Bluetooth: controller: split: Added Extended Scan Support
Updated implementation to support Extended Scan Parameters
and Extended Scan Enable.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
6b17eb2291 Bluetooth: controller: split: Added Adv Random Address set
Added implementation to set advertising random address.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
b0dd599db1 Bluetooth: controller: split: Support legacy AD/SR data
Added implementation to support setting of legacy
Advertising Data and Scan Response Data using Extended
Advertising Data set functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
f84ebf4869 Bluetooth: controller: split: Differentiate extended ll_adv_params_set
Differentiate call to ll_adv_params_set, whether used by
legacy LE Set Advertising Parameters or LE Set Extended
Advertising Parameters.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
179b213fce Bluetooth: controller: split: use CONFIG_BT_CTLR_ADV_SET
Use CONFIG_BT_CTLR_ADV_SET instead of derived BT_CTLR_ADV_SET.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
594e12139b Bluetooth: controller: split: Use uint8_t for scan handles
Use uint8_t for scan set handles.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
5db91100bc Bluetooth: controller: split: Enable Adv Extensions
Enable Advertising Extensions features in the controller
when enabled in the Host in combined host+controller based
applications.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
c8b050ee77 Bluetooth: controller: split: cond compile Ext Adv without Aux chan
Conditional compile Extended Advertising without Auxiliary
channel PDU use.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
46299e71cc Bluetooth: controller: split: Fix uninitialized variable use error
Fix for compiler complaining of uninitialized variable use.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
55cebf0eaa Bluetooth: controller: split: handle latency for cancelled sync events
Update implementation of periodic advertiser's LLL to
correctly handle event counter values when latencies
introduced due to sync events cancelled by active events
operating in unreserved time space.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
b3190cf24c Bluetooth: controller: split: handle latency for cancelled conn events
Update implementation of master and slave LLL's to correctly
handle event counter values when latencies introduced due to
connection events cancelled by active events operating in
unreserved time space.

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
b348b7fa28 Bluetooth: controller: split: Fix cond. complile of periodic adv
Fix conditional compilation of advertising extensions and
periodic advertising do that platforms with not support in
their LLL can be built without advertising extensions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
de3d4a3a64 Bluetooth: controller: split: Fix piggy back implementation
Fix conditional compilation of piggy back implementation.
This code should be deleted once periodic advertising
implementation is complete.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
4d79d43db1 Bluetooth: controller: split: Implement Aux Sets
Implement use of configurable Auxiliary advertising sets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
59f2bb1337 Bluetooth: controller: split: Fix to use correct secondary PHY
Fix using correct secondary PHY for auxiliary PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
18e916b22e Bluetooth: controller: split: Handle SyncInfo in Aux Data set
Handle using existing SyncInfo when updating Aux PDU AD Data.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
a43c3be2b9 Bluetooth: controller: split: Added SyncInfo into Aux Packet
Added SyncInfo population in Aux packet.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
a126850c15 Bluetooth: controller: split: Use correct secondary PHY, AA and CRC
Implement use of correct secondary PHY for transmission,
access address and CRC setup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
1773274118 Bluetooth: controller: split: Moved chan map helper functions
Moved Channel Map helper functions into separate file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
5c512d6e9a Bluetooth: controller: Move access address helper to util.c
Move the access address helper function to util.c file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
bb720d68ce Bluetooth: controller: split: Refactor to reuse common ISR code
Refactor to reuse common repeated code in ISR that reset
status, and performed abort, done and cleanup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
5949205315 Bluetooth: controller: split: Add periodic adv LLL implementation
Add LLL implementation to perform periodic advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
3eac6c3a52 Bluetooth: controller: split: Add periodic adv ULL implementation
Add ULL implementation to perform periodic advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
5ebbac32d9 Bluetooth: controller: split: Fill bdaddr in aux packet
Fill the bdaddr on advertising enable in the aux packet.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
0b99773037 Bluetooth: controller: Minor refactor of SyncInfo structure
Minor refactor of SyncInfo structure field names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
be3dd3687b Bluetooth: controller: split: non-conn non-scan with aux packets
Added implementation to advertise non-connectable
non-scannable advertising with auxiliary packets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
365774da7c Bluetooth: controller: Move Adv Ext interface to ll interface
Move Advertising Extensions interface to LL interface header
file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
fdd91bb116 Bluetooth: controller: split: Add AuxPtr to ADV_EXT_IND PDU
Add implementation to support ADV_EXT_IND PDU with AuxPtr.
Changes in this commit only prepares the ADV_EXT_IND PDU
in the primary channel.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
eec42ca522 Bluetooth: controller: split: Added le_set_ext_adv_param interface
Added le_set_ext_adv_param functional interface to integrate
HCI with controller's functional interface.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
5f1301245c Bluetooth: shell: Updated advx command to use Adv Data Set
Updated the shell commands related to Advertising Extensions
to call the LE Set Extended Advertising Data command
functional interface for testing purposes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
505fdadef2 Bluetooth: controller: split: Add Adv. Ext. HCI debug informations
Added debug information print outs in HCI code related to
Advertising Extensions events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 15:50:34 +02:00
Vinayak Kariappa Chettimada
c4b6fd0248 Bluetooth: controller: nRF5x: Introduce sw_switch_cleanup function
Refactor and introduce hal_radio_sw_switch_cleanup interface.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 12:22:29 +02:00
Vinayak Kariappa Chettimada
428799295d Bluetooth: controller: Add support for nRF5340 debug pins
Add support for Bluetooth Controller GPIO Debug Pins for
nRF5340 PDK board. GPIO Pin toggling can be captured on the
P3 pinhead of the PDK.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-12 11:13:39 +02:00
Lingao Meng
7239dc1cbd Bluetooth: Mesh: Add key-value concept to store model data
Previous mode store function only can store single data,
change this to store as KV model, let's app-layer to manager
model data, other than by stack when node reset.

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-06-12 11:09:11 +02:00
Vinayak Kariappa Chettimada
d96a1a5fef Bluetooth: controller: split: Fix endianness in ull_sched
Use sys_put_le16 and sys_get_le16 in populating PDU with
offset values.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-09 10:43:58 +02:00
Vinayak Kariappa Chettimada
6dce205b95 Bluetooth: controller: split: Port advanced scheduling
Port advanced scheduling implementation from legacy
controller.

This implementation schedules
- non-overlapping scan window when there are simulataneous
central connections active
- central connection establishment with similar connection
intervals be placed in a non-overlapping  group, temporally
- connection parameter request with calculated window offset
hints to have non-overlapping BLE radio events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-09 10:43:58 +02:00
Vinayak Kariappa Chettimada
0b6664fc3d Bluetooth: controller: split: Add function to reset conn upd mutex
Add a function to reset the variable holding the connection
context of the currently active Connection Parameter Request
Procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-09 10:43:58 +02:00
Vinayak Kariappa Chettimada
3cabacce9a Bluetooth: controller: Address nRF5340 Engineering A Errata 16
Address the nRF5340 Engineering A Errata 16, RADIO: POWER
register is not functional.

This affects the dependency of controller's HAL
implementation that expected correct reset values being
set in the Radio peripheral.

As the SUBSCRIBE_TXEN and SUBSCRIBE_RXEN where not in their
reset value, Radio transmission and reception start using
DPPI was broken.

Fixes #25942.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-08 22:04:25 +02:00
Kumar Gala
a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Jim Luther
ffd15131d2 bluetooth: host: fix unpacked l2cap struct
The bt_l2cap_le_conn_rsp struct in l2cap_internal.h has not been
declared __packed. This can cause alignment problems on some
platforms if the struct is placed on an unaligned address.

A __packed declaration solves this issue by forcing the compiler to
use store instructions that do not required alignment.

Signed-off-by: Jim Luther <jilu@oticon.com>
2020-05-29 17:43:32 +02:00
Vinayak Kariappa Chettimada
ba487feb0f Bluetooth: controller: split: Workaround nRF52832 CCM overrun
Implemented an intermediate decrypt buffer to cover the CCM
overrun under CRC error conditions. The workaround is
applicable to nRF52832 SoC only, which is missing the
MAXPACKETSIZE register in the NRF_CCM peripheral.

Fixes #21107 for nRF52832 SoC.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-05-29 13:12:28 +02:00
Trond Einar Snekvik
a385873336 Bluetooth: Mesh: Fail init on model init error
Adds propagation of error returns from the model init callbacks in
Access, and removing any other checks for successful init in the
foundation models.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-27 18:45:18 +02:00
Vinayak Kariappa Chettimada
cd7a73c20a Bluetooth: controller: split: Fix NRF_CCM overrun
Fix missing assignment of NRF_CCM->MAXPACKETSIZE register
for PDU sizes smaller than 251 bytes. If there is CRC errors
causing PDU length fields to be higher than configured PDU
buffer sizes in the controller, without the MAXPACKETSIZE
register set to correct PDU size, CCM module could overrun
the PDU buffer and cause memory corruption. This fix is
applicable for all nRF52 Series SoCs except nRF52832 SoC.

Fixes #21107.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-05-27 18:06:17 +02:00
Andries Kruithof
3a91f35893 Bluetooth: controller: split: include proper header file
After removal of legacy controller ll_adv_aux.h does not exist anymore.
This is fixed in this PR by including ull_adv_aux.h instead.
The error only shows up when Advertisement Extensions are enabled
in the LL (CONFIG_BT_CTLR_ADV_EXT=y)

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-05-26 15:28:12 +02:00
chao an
2f15e3901a Bluetooth: Mesh: correct the return type
CC:  mesh/access.c
mesh/access.c: In function 'model_has_dst':
mesh/access.c:483:10:
	warning: returning 'u16_t *' {aka 'short unsigned int *'} from
	a function with return type '_Bool8' {aka 'unsigned char'} makes
	integer from pointer without a cast [-Wint-conversion]
  483 |   return bt_mesh_model_find_group(&mod, dst);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: chao an <anchao@xiaomi.com>
2020-05-26 14:36:40 +02:00
chao an
bb5ce8ae30 Bluetooth: Mesh: fix shadow declare
CC:  mesh/adv.c
mesh/adv.c: In function 'bt_mesh_scan_cb':
mesh/adv.c:247:13: warning: declaration of 'adv_type'
                   shadows a global declaration [-Wshadow]
  247 |        u8_t adv_type, struct net_buf_simple *buf)
      |        ~~~~~^~~~~~~~
mesh/adv.c:58:19: note: shadowed declaration is here
   58 | static const u8_t adv_type[] = {
      |                   ^~~~~~~~

CC:  mesh/prov.c
mesh/prov.c: In function 'bt_mesh_prov_enable':
mesh/prov.c:1203:30: warning: declaration of 'prov'
                     shadows a global declaration [-Wshadow]
 1203 |   const struct bt_mesh_prov *prov = bt_mesh_prov_get();
      |                              ^~~~
mesh/prov.c:129:35: note: shadowed declaration is here
  129 | static const struct bt_mesh_prov *prov;
      |                                   ^~~~

Signed-off-by: chao an <anchao@xiaomi.com>
2020-05-26 14:36:40 +02:00
Andries Kruithof
6a2f50aba2 Bluetooth: controller: split: Update feature exchange to BTCore V5.0
The existing feature exchange procedure does not give the proper
response as specified in the BT core spec 5.0.
The old behaviour is that the feature-response returns the logical and
of the features for both peers.
The behaviour implemented here is that the feature-response returns the
featureset of the peer, except for octet 0 which is the logical and of
the supported features.
Tested by using the bt shell, and having different featuresets
on the 2 peers.

This fixes #25483

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-05-26 14:34:39 +02:00
Erwan Gouriou
2716cbcaa6 drivers: susbsys: Check errors on devices selected using dt macro
Some Kconfig defined devices may be defined using dt_chosen_label
function. Since there is no way to ensure a device enabled in dts
is also defined in Kconfig, it may happen that instance is not
actually defined.
In this case device_get_binding might return 0, leading to undefined
behavior in the function that calls it.
When not already done, systematically check return of function
device_get_binding on devices defined through dt_chosen_label macro.
Trigger ASSERT when required and return error when possible.

Fixes #20068

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-05-25 11:43:14 +02:00
François Delawarde
24729bb7c6 bluetooth: host: fix wrong bt/cf settings loading
This commits fixes the loading of bt/cf settings into memory. Only data
was loaded and not the address.

Signed-off-by: François Delawarde <fnde@demant.com>
2020-05-23 22:42:25 +02:00
chao an
32e6347f42 Bluetooth: host: foreach bond only SMP is enabled
build breakage if SMP is disabled

In function `bt_unpair':
bluetooth/host/hci_core.c:2640: undefined reference to `bt_foreach_bond'

Signed-off-by: chao an <anchao@xiaomi.com>
2020-05-20 15:36:10 +02:00
Trond Einar Snekvik
4a2e56d42a Bluetooth: Mesh: Transport tx fields overflow
The transport segmented TX nack and seg_pending fields must be at least
6 bits to avoid overflow for 32 segment messages. This change rearranges
the seg_tx fields to gather all state flag fields in one byte, while
making the counter fields whole bytes.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-19 14:44:51 +02:00
Vinayak Kariappa Chettimada
122c43562e Bluetooth: controller: split: Fix slave latency cancel race
Fix missing transmit buffer demutiplexing before checking if
slave latency needs to be maintained or cancelled.

This bug was detected when new transmit buffer was enqueued
overlapping with on-air radio transmission of empty PDU
preceding the handling of radio event done.

Symptoms of this bug being data transmission latency of upto
slave latency plus one times connection interval.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-05-15 17:07:33 +02:00
Trond Einar Snekvik
e1c6ea9241 Bluetooth: Mesh: Transport tx seg_o overflow
Increases the transport segmentented tx seg_o counter to 6 bits to avoid
overflow when sending 32 segments. The check in the send loop would
previously never be false, which causes segments to repeat
unnecessarily.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-15 17:04:45 +02:00
Trond Einar Snekvik
0aeba0eb12 Bluetooth: Mesh: Transport seg with few adv bufs
Fixes bug where the transport segmented tx would decrement the attempt
counter every time it ran out of buffers. If transport ran out of
buffers 4 times before the sending could complete, the transfer would
end prematurely.

Moves the attempt decrement to only execute when all segments have been
sent.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-15 17:04:24 +02:00
Trond Einar Snekvik
266e3f27da Bluetooth: Mesh: Friend with unknown appkey
Ensures that friend messages are enqueued, even if the packet is
received with an appkey is unknown to the friend. Previously, sdu_recv
would return EINVAL if the appkey was unknown, which would prevent the
lower transport layer from adding the packet to the friend queue. This
is irrelevant for the logic in lower transport, and should not be
returned as an error.

Fixes #24014.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-05-15 17:04:07 +02:00
Luiz Augusto von Dentz
ef25b864e2 Bluetooth: hci_core: Fix invalid if LE Read PHY
If LE Read PHY fails the code was still trying to parse the buffer as a
valid response.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-15 11:29:41 +03:00
Joakim Andersson
a1b8cc2671 Bluetooth: host: Fix extended advertiser address with privacy disabled
Fix extended advertiser not using correct set random address command
to set private (NRPA) address when privacy feature has been disabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-13 21:23:20 +02:00
Joakim Andersson
831ffcd4c2 Bluetooth: host: Fix Service Changed not cleared from flash
Fix Service Changed configuration stored in flash not deleted in flash
when calling bt_gatt_clear from bt_unpair.
When clearing the check for "is bonded" should not be made. If the
bond information is already removed this check will fail.
When clearing the check for "modified" should not be made, clearing
is in itself a modification, and should always be made.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-12 21:00:58 +03:00
Joakim Andersson
6de4294aed Bluetooth: host: Fix CCC cfg not cleared when overwriting oldest bond
Fix CCC cfg not cleared when overwriting oldest bond. Calling
bt_unpair with a pointer to the key will result in the key addr being
memset to zero and bt_gatt_clear is called with an zero-set address.
This happens because unpair (hci_core.c) calls bt_keys_clear before
calling bt_gatt_clear.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-12 21:00:58 +03:00
Peter A. Bigot
cca0b79c27 Bluetooth: host: fix warning on unused function
get_phy is referenced by BT_EXT_ADV only when BT_OBSERVER is also
selected.  Avoid defined-but-not-used warnings in that situation.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2020-05-10 11:07:35 +03:00
Carles Cufi
b67a31e411 Bluetooth: controller: Remove legacy LL
Remove the legacy Link Layer implementation.

Closes #24187.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-05-08 15:07:00 +02:00
Mieszko Mierunski
f93924c689 bluetooth: Add bluetooth support for nRF52820
This commit adds support for bluetooth in nRF52820 SoC.
Bluetooth radio related files created and added to Zephyr.

Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
2020-05-08 15:00:41 +02:00
Joakim Andersson
21a42f3b67 Bluetooth: shell: Add phy handling to the shell
Add phy update callback and command to the shell.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson
322f70243e Bluetooth: shell: Add data length handling in the shell
Add data length callback and command to the shell.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson
0ccee9ba60 Bluetooth: host: Read current PHY when using extended advertising
When using extended advertising the connection can be established on
different PHY. In order to have an updated value of the current PHY
we need to read the PHY of the connection in the connection complete
event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson
6f0b8c1421 Bluetooth: host: Add application control of PHY change procedure
Add application control of initiating phy change procedure and it's
parameters.
The reasons for allowing the application control over the PHY:
 - Allow changing to Coded PHY.
 - Application may change PHY to react to changes in environment
   to balance throughput and range.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson
d9e228a4b0 Bluetooth: host: Add application control of data length procedure
Add application control of initiating data length procedure and it's
parameters.
The reasons for allowing the application control over the data length:
 - Bandwidth control adjusted based on number of active connections.
 - Changing data length before switching to coded phy.
 - Applying workarounds for interoperability problems.
 - Controlling order of ATT MTU and data length procedures.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson
69dfcc6fca Bluetooth: host: Add Kconfig option for auto data length procedure
Add Kconfig option so that the application can disable automatic
initiation of the data length procedure. This is symmetric with the
PHY auto initiation kconfig option.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson
f85433c4a9 Bluetooth: host: Refactor setting maximum data length
Refactor setting the maximum data length parameters supported on in
auto data length procedure. This makes setting the data length of the
connection a re-usable function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Vinayak Kariappa Chettimada
aa60a51a66 Bluetooth: controller: Update Bluetooth version to 5.2
Update the Bluetooth HCI Version to 5.2.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-05-07 19:26:13 +03:00
Morten Priess
3ed658e9ed Bluetooth: controller: Added support for vendor ticker nodes
With BT_CTLR_USER_TICKER_ID_RANGE it is possible for vendors to add a
number of ticker nodes for proprietary purposes. The feature depends on
BT_CTLR_USER_EXT.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-05-07 17:34:21 +02:00
Luiz Augusto von Dentz
1c35cc18fe Bluetooth: hci_raw: Split TX into ACL and CMD pools
This might reduce the footprint if the supported sizes are different.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-07 10:31:36 +03:00
Luiz Augusto von Dentz
f9d1b7ed63 Bluetooth: hci_raw: Fix number of TX buffers
The numbers should have been the sum of HCI commands count and ACL TX
buffers but instead the buffer size was used which makes the pool holds
substatially more buffer than necessary.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-07 10:31:36 +03:00
Joakim Andersson
c6edfa0971 Bluetooth: shell: Add name option control to advertise parameters.
Add control over the use name option to advertise shell parameters as
an optional argument.
The argument count for extended advertise parameters had not been
updated for the maximum directed advertise parameter count.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson
4592cb64ea Bluetooth: host: Add BT_LE_ADV_OPT_USE_NAME for new advertising API
Implement the BT_LE_ADV_OPT_USE_NAME when using bt_le_ext_adv_* APIs
to start the advertiser.
When starting an extended connectable advertiser the name must be
included in the advertising data, since scan response data is
not allowed in this configuration.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson
e9002a4fb4 Bluetooth: host: remove duplicate flags set.
Remove setting state flags in bt_le_adv_start_ext since they are set
by le_ext_adv_param_set, except for BT_ADV_PERSIST flag.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson
a2a7cc9fe6 Bluetooth: host: Only persist advertising with bt_le_adv_start API
Only persist advertising when the bt_le_adv_start API is used to start
the advertiser. For multiple advertising set a connectable advertiser
can only be started if there is a connection object available for the
advertiser. Leave the decision on which advertising set should be
advertising up to the application instead of suspending advertising
when no connection object is available.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson
fdb3da8aff Bluetooth: host: Rename BT_LE_CONN_OPT to BT_CONN_LE_OPT
Rename connection options to be consistent with the rest of the API
names in conn.h

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-04 17:48:22 +03:00
Joakim Andersson
8b70079ebe Bluetooth: host: Remove BT_LE_CONN_OPT_2M option
Remove the BT_LE_CONN_OPT_2M option and update documentation.
This was a misunderstand about the init PHY HCI parameter.
The init PHY in the extended connection create command does not
determine which PHYs are accepted as the initial PHY of the
connection. This is instead determined by the secondary PHY of the
extended advertiser.
The init PHY parameter only specifies which conn parameters are
provided, and since we only provide one conn parameter this option
has no effect.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-04 17:48:22 +03:00
Johan Hedberg
e1dddf7bef Bluetooth: Fix NULL pointer dereference when bt_send() fails
The last parameter to hci_cmd_done() is expected to be a valid net_buf
since the function immediately tries to dereference it. Fix this by
passing the appropriate buffer reference to the function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-05-04 10:59:39 +03:00
Luiz Augusto von Dentz
ec5603da8d Bluetooth: L2CAP: Add status flag to track encrypt pending
This adds a new flag to track if the L2CAP channel is pending waiting
for encryption to be changed to resume connecting.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz
e0cbdf3b87 Bluetooth: GATT: Add support for new PDUs
This adds support for ATT_MULTIPLE_HANDLE_VALUE_NTF,
ATT_READ_MULTIPLE_VARIABLE_REQ and ATT_READ_MULTIPLE_VARIABLE_RSP.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz
f4192bda26 Bluetooth: ATT: Add support EATT bearer
This adds support for EATT bearer which was introduced in 5.2, they work
as extra channels to have GATT traffic, at the moment it is completely
transparent to application when they are in use since the allocation
happens automatically.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz
d148f8648b Bluetooth: ATT: Add definitions from 5.2
This adds the definitions for Enhanced ATT along with new PDUs and UUIDs
introduced in 5.2.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz
14d6c00b9b Bluetooth: L2CAP: Add released callback
This adds a callback to indicate when the stack has released all
references to a given channel so the owner free up any resources
associated with that.

This is requires since EATT channels cannot rely on the destroy callback
as it does not use a fixed channel like ATT.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz
0473b436b5 Bluetooth: L2CAP: Process channel with fixed PSM on RX thread
This leaves only channels on the dynamic range to be offloaded to the
system queue so ATT and EATT handling are handling in the same context.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz
f7586b0b04 Bluetooth: L2CAP: Add initial implementation of ECRED mode
This adds the initial implementation of ECRED mode which can connect up
to 5 channels simultaneously and is required by EATT.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz
72d4f06bf0 Bluetooth: L2CAP: Use spaces to align defines
This replaces the use of tabs with spaces to align defines.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz
95e109bc8e Bluetooth: L2CAP: Add definitions introduced in 5.2
This introduces new Enhanced Credit Based Flow Control PDUs and related
definitions which were introduced in 5.2.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Kumar Gala
8316818739 bluetooth: controller: openisa/RV32M1: Convert irqs to new dts macros
Convert old style defines for IRQ numbers to using DT_IRQN and
DT_NODELABEL to extract IRQ numbers.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-30 11:26:59 -05:00
Joakim Andersson
eba6265ac3 Bluetooth: controller: Add BT_CTLR_CONN_RSSI_EVENT option
Split BT_CTLR_CONN_RSSI option into two, the base option enables the
Read RSSI command, while the new BT_CTLR_CONN_RSSI_EVENT enables the
connection RSSI events. There is no handling of RSSI events, only a
BT_INFO log.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-30 13:33:16 +02:00
Joakim Andersson
91c20e313d Bluetooth: Remove LEGACY_TIMEOUT_API selection from bluetooth
The bluetooth subsystem is now fully compatible with the new timeout
API, so remove the selection of the legacy API.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-30 13:46:48 +03:00
Joakim Andersson
ac2ce863ef Bluetooth: shell: Convert bluetooth shell to using k_timeout struct
Convert bluetooth shell to using k_timeout struct.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-30 13:46:48 +03:00
Joakim Andersson
87d9eadf50 Bluetooth: mesh: Convert bluetooth mesh to using k_timeout struct
Convert bluetooth mesh to using k_timeout struct. Many of the mesh
modules uses timeout calculations, so it is most practical to keep
the s32_t type and only initialize a k_timeout_t struct when
calling the kernel.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-30 13:46:48 +03:00
Joakim Andersson
d858264d9e Bluetooth: host: Convert bluetooth host to using k_timeout_t struct
Convert bluetooth host to using k_timeout_struct for the timeout values.
This is mostly replacing s32_t with k_timeout_t.
In l2cap the handling of no timeout in send channel request was removed
since the timeout is both documented as minimum of 1 second and never
given any no timeout value.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-30 13:46:48 +03:00
Joakim Andersson
05e5db74cf Bluetooth: controller: Convert bluetooth controller to using k_timeout_t
Convert bluetooth controller to using the new k_timeout_t API so that
CONFIG_LEGACY_TIMEOUT_API can be turned off.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-30 13:46:48 +03:00
Joakim Andersson
e9375a2814 Bluetooth: Remove bluetooth thread stack size analysis
Remove logging of individual threads spread out throughout the
bluetooth subsystem. The stacks can be analysed by enabling the
following options.

CONFIG_THREAD_ANALYZER=y
CONFIG_THREAD_ANALYZER_AUTO=y
CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y
Optional:
CONFIG_THREAD_NAME=y

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-28 09:11:13 -04:00
Joakim Andersson
3230a85590 Bluetooth: host: Include RPAs in enhanced conn complete logging
Include the RPA addresses in the enhanced connection complete debug
log. This makes it easier to debug privacy failures.
Use a new debug statement so that the debug print will work correctly
when log_strdup does not copy the string.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-27 19:02:48 +02:00
Joakim Andersson
578f2a582f Bluetooth: controller: Set local RPA field only when generated legacy
Fix local RPA field for the legacy controller. This failed without
compilation errors because of blind pointer cast between two
structs of similar definition.
Set the local RPA field of the enhanced connection complete event only
when the address was generated by the controller. If the host has
set an RPA and this one was used the controller should return all
zeroes.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-27 19:02:48 +02:00
Joakim Andersson
e9b39cd304 Bluetooth: controller: Set local RPA field only when generated
Set the local RPA field of the enhanced connection complete event only
when the address was generated by the controller. If the host has
set an RPA and this one was used the controller should return all
zeroes.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-27 19:02:48 +02:00
Joakim Andersson
0d9db89dde Bluetooth: host: Fix compilation issue for extended advertising beacon
Fix compilation issue for extended advertising beacon. Adv pool was
mistakenly put under BT_OBSERVER define.
Both observer and broadcaster use the bt_lookup_id_addr. SMP cannot
be enabled without connections, so for broadcaster and observer there
will not be a lookup.
Fix compilation warning for extended scanner-only build.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-27 19:02:48 +02:00
Joakim Andersson
203d13c1a4 Bluetooth: host: Handle zero-set local RPA in enhanced conn complete
According to the BT Core spec. The local RPA field in the enhanced
connection complete event should be set if the own-address type was
set to 0x02/0x03 and the controller generated an RPA using a non-zero
IRK, otherwise the controller should return all zeroes.
In the case where we generate the RPA in the host instead we need to
handle set the on-air RPA address based on the random address set by
the host.
If this is not handled then pairing will fail because the on-air
addresses are used as input to the pairing procedure.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-27 19:02:48 +02:00
Joakim Andersson
a3161ef58e Bluetooth: host: Remove extended advertising from connection complete
Remove handling of extended advertising from connection complete
event. If extended advertising has been enabled and is supported by
the controller then enhanced connection complete must be supported.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-27 19:02:48 +02:00
Alex Porosanu
4c4f07e0dc bluetooth: controller: openisa: Fix densely scheduled event preemption
This is a rework for OpenISA SW LL of
"b7220cef86 Bluetooth: controller: split: Fix densely scheduled event
preemption"

Fix LLL implementation handling preemption of currently
active radio event with densely scheduled events in the
pipeline.

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2020-04-27 11:31:31 +02:00
Alex Porosanu
678f0296c8 bluetooth: controller: openisa: Reduce time to setup tIFS switch
This is a rework for OpenISA SW LL of
"b0826a7f65 Bluetooth: controller: split: Reduce time to setup tIFS
switch"

Refactor to reduce the setup next tIFS switch within tIFS
period of the Radio ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2020-04-27 11:31:31 +02:00
Alex Porosanu
d6710257bd bluetooth: controller: openisa: handle latency for cancelled conn events
This is a rework for OpenISA SW LL of
"4547bfb452 Bluetooth: controller: split: handle latency for cancelled
conn events" as well as subsequent fixes

Update implementation of master and slave LLL's to correctly
handle event counter values when latencies introduced due to
connection events cancelled by active events operating in
unreserved time space.

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2020-04-27 11:31:31 +02:00
Alex Porosanu
e08ceec584 bluetooth: controller: openisa: fix assert on invalid packet sequence
This is a rework for OpenISA SW LL of
"62c1e1a52b Bluetooth: controller: split: Fix assert on invalid packet
sequence"

Fix to remove assertion failure check on detecting invalid
packet sequence used by peer central and that no non-empty
packet was transmitted.

Fixes #22967.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2020-04-27 11:31:31 +02:00
Luiz Augusto von Dentz
440f647013 Bluetooth: hci_raw: Fix pushing H4 headers in bt_buf_get_rx
User of bt_buf_get_rx may attempt to push their own headers, e.g. ACL
headers, so move the H4 header logic to bt_recv after logging into the
monitor since otherwise the buffer would contain H4 headers which is
not expected by the monitor.

Fixes #24646

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-04-24 10:00:02 +03:00
Trond Einar Snekvik
86137c3a62 Bluetooth: Mesh: Add cfg cli list getters
Adds config client getters for all list commands:
- mod_app_get
- mod_sub_get
- net_key_get
- app_key_get

Closes #24505.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-04-23 14:03:17 +03:00
Lingao Meng
be33f913ac Bluetooth: Mesh: Remove net_idx params when with app key
According Mesh Profile 1.0.1. A application key shall
binding single network key. And Device key shall bind all
network key, and dev key only known by cfg_cli and node self,
only used by cfg_cli & cfg_srv.

Fixes: #21088

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-04-23 11:30:41 +03:00
Trond Einar Snekvik
00ba872769 Bluetooth: Mesh: net_key_status only pull one key idx
Fixes bug where the config client's net_key_status handler would attempt
to pull two key indexes from a message which only holds one.

Fixes #24601.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-04-23 11:26:29 +03:00
Trond Einar Snekvik
e5d9291d1a Bluetooth: Zero-initialize adv params
After #22013, bt_le_adv_param got additional fields which were passed to
the bluetooth API uninitialized in the BT Mesh module. This
zero-initializes the entire structure in all usages to avoid passing
uninitialized data now and in the future.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-04-21 18:26:37 +02:00
Joakim Andersson
d4f22a8216 Bluetooth: host: Add support for multiple advertising set
Add support for multiple advertising set. Move the advertising state
flags to be per advertising set and loop over advertising sets instead
of looking up legacy advertiser set or handle 0.

Since it is not certain that the advertising set terminated event can
arrive directly after the connection complete event there is currently
a limitation that there can only be one local identity used by
connectable advertisers at a time. This guarantees that we know
the local identity being used in the connection complete event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-21 12:46:05 +03:00
Joakim Andersson
bfd2f6e928 Bluetooth: host: Only attempt to restart scanner when role is master
Only attempt to restart the background scanner in connection complete
event when the new connection is a master role connection or the
initiator was successfully canceled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-21 12:46:05 +03:00
Joakim Andersson
36de18304b Bluetooth: host: Enable enhanced connection complete for extended adv
Enable enhanced connection complete when extended advertising has been
enabled. This event is mandatory if extended advertising is supported.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-21 12:46:05 +03:00
Kumar Gala
e241de8a31 bluetooth: controller: openisa/RV32M1: Convert DT_ALIAS to NODELABEL
Use the new DT_NODELABEL macro instead of aliases to get the specific
gpios ports.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-20 15:52:30 -05:00
Luiz Augusto von Dentz
4b622afbb3 Bluetooth: hci_raw: Move buffer management to common place
This makes hci_raw to manage RX and TX buffers so its logic don't have
to be replicated on each an every driver/application, it also makes it
simpler to deal with extra headers for H:4 mode since that then can be
done at earlier at buffer allocation.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-04-20 21:59:47 +03:00
Luiz Augusto von Dentz
05f0816f93 Bluetooth: hci_raw: Add support for command extention
This adds support for registering a command extention table which is
used to match incoming commands and then pass the buffer to its
function handler.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-04-20 21:59:47 +03:00
Luiz Augusto von Dentz
b3ee8be80d Bluetooth: hci_raw: Add support for using H:4 transport
This adds 2 config options which enables hci_raw to work in
H:4 mode and enable it by default automatically.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-04-20 21:59:47 +03:00
Luiz Augusto von Dentz
b4e71014f2 Bluetooth: hci_usb: Add implementation of Read/Set USB Transport Mode
This implements Read/Set USB Transport Mode in the Bluetooth class.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-04-20 21:59:47 +03:00
Luiz Augusto von Dentz
f710b9be50 Bluetooth: HCI: Add helpers to create events
This adds bt_hci_evt_create and bt_hci_cmd_complete functions.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-04-20 21:59:47 +03:00
Luiz Augusto von Dentz
2534ab11c0 USB: Add driver and PID for Bluetooth H4
This adds USB_PID_BLE_HCI_H4_SAMPLE along with it driver which uses H4
over bulk endpoints.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-04-20 21:59:47 +03:00
Ahmed Shokry
c2444b4e30 Bluetooth: host: Allow only one legacy advertising instance
When legacy advertising enable command is issues,
the BT_ADV_ADVERTISING has to be set, because this
flag is checked in many scenarios to see if the
advertising is ongoing or not.

Signed-off-by: Ahmed Shokry <ahmed.shokry@synopsys.com>
2020-04-20 15:49:58 +02:00
Joakim Andersson
fda3bfcf1b Bluetooth: controller: Send command status for unknown commands
When receiving an unknown command send the unknown command response
as a command status event instead of a command complete event.
A command complete event has no status field, although by convention
all command parameters has a status field as the first parameter the
command status event seems like the more fitting option.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-20 15:45:18 +02:00
Lingao Meng
49e4f754b4 Bluetooth: Mesh: Fix add model group address to sub list
When low power node reset, should add group address to
friend subscription list.

Fixes: #24311

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-04-19 18:36:12 +03:00
Lingao Meng
2e4eab5ebc Bluetooth: Mesh: Add option for lpn auto sub all-nodes
Add option for low power node automatically subscribe
all-nodes-address to friend sub list.

Fixes: #24009

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-04-19 18:36:12 +03:00
Joakim Andersson
69d91f0a9d Bluetooth: shell: Give NULL pointer when ad_len or sd_len is zero
Give NULL pointer when ad_len or sd_len is zero, this stops the host
from setting a zero length advertise data or scan response.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-17 15:28:03 +02:00
Joakim Andersson
8b5d91e659 Bluetooth: shell: Fix advertise command parameters
Fix the advertise command not setting the peer address parameter to
NULL, this could turn it into a directed advertiser.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-17 15:28:03 +02:00
Jeanina Dragusin
40ee38a945 bluetooth: controller: enable privacy for RV32M1
This patch adds the selection of the necessary CONFIG_*
options for allowing the use of privacy on VEGA platform

Signed-off-by: Jeanina Dragusin <ancajeanina.dragusin@nxp.com>
2020-04-15 13:43:00 -05:00
Jeanina Dragusin
6099e0f928 bluetooth: controller: openisa/RV32M1: add RPA support
The radio on the VEGA platform will now be able to resolve Resolvable
Private Addresses through the use of the CAUv3 hardware. With this
patch the RPA feature is now fully supported on the Controller:
RPA addresses are generated with local IRK and resolved with
previously exchanged peer IRK.

Signed-off-by: Jeanina Dragusin <ancajeanina.dragusin@nxp.com>
2020-04-15 13:43:00 -05:00
Luiz Augusto von Dentz
8863b72b05 Bluetooth: ATT: Fix passing wrong pointer when disconnecting
When disconnecting att_reset is called and all requests are notified
but instead of passing req->user_data like it should it pass the req
itself which nowdays comes from a k_mem_slab, rather than being a
contiguous memory that would contain the request and its user data,
which would likely cause invalid access.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-04-15 11:38:41 +03:00
Joakim Andersson
962b86564e Bluetooth: shell: Add advertising directed and scan response options
Add shell options to configure an extended advertiser for directed
advertising.
Add shell options to provide arbitrary advertising data as well as
giving scan response data.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-15 10:57:38 +03:00
Joakim Andersson
18bee9178f Bluetooth: host: Add non-connectable directed advertising support
This patch introduces two major changes to the directed advertising
feature of the bluetooth host.

Deprecating the bt_conn_create_slave_le, and removing
bt_conn_le_create_slave which has never been released. This behaviour
has now been moved by to providing the peer direct address into the
advertising parameters.

Introducing directed advertising support for nonconnectable
directed extended advertising, both scannable and non-scannable.

A bug was also fixed in the the directed-adv command in the shell
when the argument "low" was given. The advertiseng parameter pointer
declared with BT_LE_ADV_CONN_DIR_LOW_DUTY was declared in a scope that
was no longer valid when it was used to start the advertiser.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-15 10:57:38 +03:00
Trond Einar Snekvik
7c5c4da63a Bluetooth: Mesh: PB-GATT common link closed
Makes a common link_closed function for PB-GATT, getting rid of a bug
where cb_data is reset before the link closed callback. Also ensures
that the link close and reset order is the same in both scenarios.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-04-14 11:27:23 +03:00
Kumar Gala
43a7d26603 drivers: entropy: replace CONFIG_ENTROPY_NAME with DT macro
Replace CONFIG_ENTROPY_NAME with DT_CHOSEN_ZEPHYR_ENTROPY_LABEL.  We now
set zephyr,entropy in the chosen node of the device tree to the entropy
device.

This allows us to remove CONFIG_ENTROPY_NAME from dts_fixup.h.  Also
remove any other stale ENTROPY related defines in dts_fixup.h files.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-13 09:14:21 -05:00
Carles Cufi
76c3a8d964 Bluetooth: controller: Fix Peer Address Type in Conn Complete
The LE Connection Complete HCI event, unlike its Enhanced counterpart,
only uses 0x0 and 0x1 for Peer Address Type. Fix it so that it reflects
the specification correctly.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-04-09 17:18:58 +02:00
Andries Kruithof
aafd563195 Bluetooth: controller: legacy: Correct DLE time calculations
This PR fixes #23482. The preamble size for a 2M phy was incorrect.

There is a bug in calculation of time for the DLE procedure:
the preamble size is incorrect for the 2M phy

Fixes #23482

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-04-09 14:55:20 +02:00
Lingao Meng
ada840a308 Bluetooth: Mesh: Fix duplicated close callback
When PB-GATT Procedure timeout, func `bt_mesh_pb_gatt_close`
will also dumplicated with `link_closed()`

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-04-09 14:19:18 +03:00
Joakim Andersson
b1611d0ace Bluetooth: host: Check return value of le_ext_adv_param_set
Check the return value of LE Set Extended Advertising Parameters
command when starting an advertiser from bt_le_adv_start with
CONFIG_BT_EXT_ADV enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-08 17:59:13 +03:00
Joakim Andersson
19434a1056 Bluetooth: host: Do not set adv random address before adv parameters
The LE Set Extended Advertising Set Random Address command may be
issued at any time after an advertising set identified by
the Advertising Handle parameter has been created using the
LE Set Extended Advertising Parameters command.

This commit fixes the advertising set issueing the set random address
command before the advertising set is created in the controller.
Since the le_adv_set_random_addr function has is used to get the the
own address parameter for the it could not simply be moved, and
moving the own address parameter handling out of this function
would create a potentioal maintaince problem.
Also this function is used for both with and without advertising
extension feature so changing it is not trivial without breaking all
the previous random address handling already put in place.
The simplest solution was therefore to postpone the command until the
parameters has been set using 2 flags.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-08 17:59:13 +03:00
Joakim Andersson
d10d0f0b39 Bluetooth: host: Use bluetooth assert on HCI command send error
Use bluetooth assert on HCI command send error since this assertion is
always enabled and we should not continue after this has failed.
Log command status failure with information in order to make it more
visible as the HCI status code is more interesting than the -EIO error
code returned by the function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-08 17:58:32 +03:00
Joakim Andersson
9e8a30203f Bluetooth: log: Add BT_ASSERT_MSG that matches __ASSERT
Add BT_ASSERT_MSG assert mechanism that can print assertion messages
when verbose bluetooth asserts are enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-08 17:58:32 +03:00
Lingao Meng
5b991aa09a Bluetooth: Mesh: Fix transport tx and rx
Fix seg_tx occupy when no segment not send
and allocate rx_seg when receive such message.

Fixes: #24101

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-04-08 11:36:11 +03:00
Kumar Gala
60541af791 Bluetooth: controller: specify entropy device explicitly
For the ll code we know the exact entropy device as its the one for the
SoC that we are on.  So use the new DT macro's to get the entropy device
via DT_INST rather than using CONFIG_ENTROPY_NAME.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-07 13:07:45 -05:00
Joakim Andersson
fe8334c130 Bluetooth: host: Fix wrong latency and timeout values in conn update
Fix the pending slave set connection latency and timeout values not used
in the connection update procedure when
CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS has not been enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-07 18:12:15 +03:00
Carles Cufi
205cf1595e boards: nrf52810_pca10040: Rename to nrf52dk_nrf52810
The board target for emulation of nRF52810 on nRF5DK, so far
known as nrf52810_pca10040, is renamed to nrf52dk_nrf52810.
Its documentation and all references to its name in the tree are
updated accordingly. Overlay and configuration files specific to
this board are also renamed, to match the new board name.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-04-06 13:09:07 +02:00
Carles Cufi
6656214af2 boards: nrf52_pca10040: Rename to nrf52dk_nrf52832
The board name for the nRF52 DK, so far known as nrf52_pca10040, is
renamed to nrf52dk_nrf52832.  Its documentation and all references
to its name in the tree are updated accordingly. Overlay and
configuration files specific to this board are also renamed, to
match the new board name.

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

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

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

Fixes #23468

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

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

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

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

This is a regression from: a3e89e84a8

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

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-03 18:06:59 -04:00
Johan Hedberg
71eb56a34c net: buf: Move LEGACY_TIMEOUT_API selection to specific subsystems
The net_buf subsystem is now fully compatible with the new timeout
API, so move the selection of the legacy API to those specific
subsystems that use net_buf and still need converting.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-04-03 23:17:53 +03:00
Vinayak Kariappa Chettimada
4547bfb452 Bluetooth: controller: split: handle latency for cancelled conn events
Update implementation of master and slave LLL's to correctly
handle event counter values when latencies introduced due to
connection events cancelled by active events operating in
unreserved time space.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-03-31 12:25:12 +03:00
Oleg Zhurakivskyy
b1e1f64d14 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-31 07:18:06 +02:00
Joakim Andersson
a20066ed4f Bluetooth: shell: Add shell advertise set info get command
Add shell advertise set info get command to print advertiser set local
identity and TX power selected by the controller.

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

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

This gives the following size reduction for hci_core.c:

Without legacy support
hci_core.c  19980     7.75%
total      257679

With legacy support
hci_core.c  21816     8.41%
total      259519

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson
f2d7b77e96 Bluetooth: host: Deprecate BT_LE_ADV defines in hci.h in favour of gap.h
Deprecate BT_LE_ADV defines in hci.h that are expected to be used by the
application in the scan received callback to identify the advertising
PDU type. These defines are mixing HCI input parameters and advertising
PDU types. Internally it is acceptable to mix these, but at the API we
should to mix in them.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson
be57dfbe2a Bluetooth: host: Rename and deprecate scan filter for more scan options
Rename filter_dup parameters used for scanning filter options to the
more generic name options, and make scan filter options follow same
naming patters as advertising and initiator scan options.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson
405ce842ab Bluetooth: host: Add new argument and return code to bt_create_conn_le
Deprecate bt_create_conn_le and rename it to in order to add return
code, new arguments and to follow the established naming convention.

Add API for the application to control the scan parameters of the
initiator role. This allows the application more scheduling control
of the initiator in multi-role scenarios. Also provides options to
configure the initiator for LE Coded PHY for long range support.
We deprecate the old way of creating connection to make the name more
consistent with the rest of the API.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Kumar Gala
3a59f87ba9 bluetooth: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

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

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

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

Fixes #23805.

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

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

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

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

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

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

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

Additional trivial fixes from testing:

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

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-19 18:45:13 +01:00
Oleg Zhurakivskyy
8739517107 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-19 15:47:53 +01:00
Trond Einar Snekvik
824c2ebc58 Bluetooth: Mesh: Slab based segmentation handling
Allocates segmented message buffers as slabs in a common pool for RX and
TX. This reduces memory requirements for both TX and RX, as TX messages
can be stored without the network and advertising buffer overhead, and
RX can use only the slabs it needs, instead of allocating a full size
segmented message. This approach also removes the need for decrypting
the segments for each retransmission, reducing overall processing load.

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

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

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

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

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

Fixes #23482

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Also fixes #23109.

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

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

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

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

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

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

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

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

Regressions from:
fbe3285bfa
and
4876a8f39a

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

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

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

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

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

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

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

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

Fixes #21601.

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

Fixes #23069.

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

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

Fixes #22968.

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

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

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

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

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

Fixes #23110

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

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

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

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

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

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

Bluetooth: controller: split: fixed for endianness

Added conversion to correct endianness

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

Fixes #23069.

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

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

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

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

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

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

Fixes #22945.

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

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

Fixes #22926.

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

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

Fixes #22967.

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

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

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

Continuous scanning and connections are working fine now.

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

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

Fixes #22822

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

Fixes #22801.

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

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

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

---

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

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

Mesh Profile Spec 1.0, Section 4.2.11:

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

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

Mesh Profile Spec 1.0, Section 4.2.11.1:

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

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

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

Fixes #22539

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

Fixes #22514

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

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

Fixes #22786

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

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

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

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

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

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

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-10 10:22:42 +01:00
Ulf Magnusson
eddd98f811 kconfig: Replace some single-symbol 'if's with 'depends on'
I think people might be reading differences into 'if' and 'depends on'
that aren't there, like maybe 'if' being needed to "hide" a symbol,
while 'depends on' just adds a dependency.

There are no differences between 'if' and 'depends on'. 'if' is just a
shorthand for 'depends on'. They work the same when it comes to creating
implicit menus too.

The way symbols get "hidden" is through their dependencies not being
satisfied ('if'/'depends on' get copied up as a dependency on the
prompt).

Since 'if' and 'depends on' are the same, an 'if' with just a single
symbol in it can be replaced with a 'depends on'. IMO, it's best to
avoid 'if' there as a style choice too, because it confuses people into
thinking there's deep Kconfig magic going on that requires 'if'.

Going for 'depends on' can also remove some nested 'if's, which
generates nicer symbol information and docs, because nested 'if's really
are so simple/dumb that they just add the dependencies from both 'if's
to all symbols within.

Replace a bunch of single-symbol 'if's with 'depends on' to despam the
Kconfig files a bit and make it clearer how things work. Also do some
other minor related dependency refactoring.

The replacement isn't complete. Will fix up the rest later. Splitting it
a bit to make it more manageable.

(Everything above is true for choices, menus, and comments as well.)

Detected by tweaking the Kconfiglib parsing code. It's impossible to
detect after parsing, because 'if' turns into 'depends on'.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-02-08 08:32:42 -05:00
Andrew Boie
efc5fe07a2 kernel: overhaul unused stack measurement
The existing stack_analyze APIs had some problems:

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

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

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

Fixes: #17852

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

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

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

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

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

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

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

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

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

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

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

Fixes: #22086

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

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

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

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

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

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

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

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

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

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

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

Fixes #22088.

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

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

Fixes: #21036

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

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

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

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

Fixes #22202

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

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

Introduced by:
6c1f52dff7 for bt_conn_create_le
e9eebf0c40 for bt_conn_create_auto_le.

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

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

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

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

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

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

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

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

Fixes #22207

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Just remove the select.

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-20 18:58:02 +02:00
Ulf Magnusson
4e85006ba4 dts: Rename generated_dts_board*.{h,conf} to devicetree*.{h,conf}
generated_dts_board.h is pretty redundant and confusing as a name. Call
it devicetree.h instead.

dts.h would be another option, but DTS stands for "devicetree source"
and is the source code format, so it's a bit confusing too.

The replacement was done by grepping for 'generated_dts_board' and
'GENERATED_DTS_BOARD'.

Two build diagram and input-output SVG files were updated as well, along
with misc. documentation.

hal_ti, mcuboot, and ci-tools updates are included too, in the west.yml
update.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-17 17:57:59 +01:00
Erik Brockhoff
48b6dae329 Bluetooth: controller: split: ULL filter API modifications
Moving struct definitions into header file and adding API to
allow accessing data-structures from lll context

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

Fixes: #21996

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

Fixes #21974.

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

This commit moves the selection to BT_CTLR_CRYPTO.

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

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

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

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

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

Fixes #21586.

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

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

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

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

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

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

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

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

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

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

This is a regression from 89981b07c8.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-01-13 14:27:01 +01:00
Joakim Andersson
08168f60f7 Bluetooth: assert: Change printed expression to printing line and file
Change assertion messaged printed from printing expression to printing
the line and file name. This provides more context as the same
expression could be asserted upon multiple times and would then not
provide enough clarity in the message.

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

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

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

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

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

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

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

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

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

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

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

Fixes #21103

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

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

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

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

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

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

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

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

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

The controller validations are included in controller only
builds.

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

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

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

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

Relates to assert in #21006.

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

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

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

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

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

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

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

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

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

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

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

Fixes #19922

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

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

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

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

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

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

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

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

    if FOO

    menu "blah"

    ...

    endmenu

    endif

can be replaced with

    menu "blah"
            depends on FOO

    ...

    endmenu

Fix up all existing instances.

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

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

Piggyback removing a redundant 'default n' for BME280.

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-12-19 11:28:24 +02:00
Johan Hedberg
0e91493ab4 Bluetooth: L2CAP: Make channel ops const
Make the channel ops struct const since there really isn't anything
there that needs to change at runtime. The only exception is the L2CAP
shell which was playing with the recv callback, however that can be
fixed by introducing a simple bool variable.

With tests/bluetooth/shell this reduces RAM consumption by 112 bytes
while adding only 16 bytes to flash consumption.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-12-19 11:28:24 +02:00
Vinayak Kariappa Chettimada
b0826a7f65 Bluetooth: controller: split: Reduce time to setup tIFS switch
Refactor to reduce the setup next tIFS switch within tIFS
period of the Radio ISR.

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

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

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

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

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

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

Relates to #21299.

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

- BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL
- BT_HCI_OP_VS_READ_TX_POWER_LEVEL

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

The functionality is enabled upon the Kconfig advanced configuration
triggered by

- BT_CTLR_TX_PWR_DYNAMIC_CONTROL

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

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

- BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL
- BT_HCI_OP_VS_READ_TX_POWER_LEVEL

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

The functionality is enabled upon the Kconfig advanced configuration
triggered by

- BT_CTLR_TX_PWR_DYNAMIC_CONTROL

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

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

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

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

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

Fixes #21299.

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

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

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

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

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

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

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

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

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
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
Vinayak Kariappa Chettimada
3aa57808ac Bluetooth: controller: split: Add interface to get adv/scan handle
Added interface to get Advertiser and Scanner instance
handle for use in Lower Link Layer module.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-04 09:46:49 +02:00
Luiz Augusto von Dentz
dbe80fd987 Bluetooth: GATT: Fix registering on static service area
When registering a new service it has to account the area used by static
services.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-07-02 15:49:58 -04:00
Arthur Crepin-Leblond
ba894d8b0a Bluetooth: gatt: Fix DB corruption when adding/removing service
Fix an issue in the gatt_register routine where removing a service and
adding it again would cause the database to have non-ascending
orderdered handles numbers and lead to an incomplete service discovery.

Fix: Go through the database and look for a place where to insert
the new service.

Signed-off-by: Arthur Crepin-Leblond <arthur.crepin@proglove.de>
2019-07-02 17:34:57 +03:00
Thomas Stenersen
d596262821 Bluetooth: controller: Rename assert handler Kconfig title
Renames the "Blueooth Controller Assertion Handler" to "Application
Defined Assertion Handler" to better fit the purpose of the Kconfig
option.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2019-07-02 09:19:16 +03:00
Thomas Stenersen
3379b641b7 Bluetooth: controller: Remove BT_HCI_RAW dependency
Removes the dependency on BT_HCI_RAW from BT_CTLR_ASSERT_HANDLER.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2019-07-02 09:19:16 +03:00
Johan Hedberg
0d9dab300e Bluetooth: Introduce separate pool for discardable events
Introduce a separate buffer pool for events which the HCI driver
considers discardable. Examples of such events could be e.g.
Advertising Reports. The benefit of having such a pool means that the
if there is a heavy inflow of such events it will not cause the
allocation for other critical events to block and may even eliminate
deadlocks in some cases.

Also update all mesh samples not to specify explicit RX buffer counts
anymore. Instead, create appropriate defaults in Kconfig so that we
only need to override this in the app for cases like the bbc:microbit
with limited memory.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-01 16:36:15 +03:00
Johan Hedberg
fc2fcd10cf Bluetooth: Add dedicated pool for HCI_Num_Completed_Packets HCI event
This event is a priority one, so it's not safe to have it use the RX
buffer pool which may be depleted due to non-priority events (e.g.
advertising events). Since the event is consumed synchronously it's
safe to have a single-buffer pool for it. Also introduce a new
bt_buf_get_evt() API for HCI drivers to simplify the driver-side code,
this effectively also deprecates bt_buf_get_cmd_complete() which now
has no in-tree HCI driver users anymore.

Fixes #16864

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-01 16:36:15 +03:00
Radu Alexe
f1c5586523 Bluetooth: controller: better field names
Fields nodes, users are arrays; therefore their names should be plural
to suggest that.

Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
2019-06-28 11:09:25 +02:00
Anas Nashif
efb8df5366 cleanup: include/: move misc/stack.h to debug/stack.h
move misc/stack.h to debug/stack.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
536dd5a71f cleanup: include/: move misc/slist.h to sys/slist.h
move misc/slist.h to sys/slist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
1ed300b318 cleanup: include/: move misc/mempool_base.h to sys/mempool_base.h
move misc/mempool_base.h to sys/mempool_base.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
ee9dd1a54a cleanup: include/: move misc/dlist.h to sys/dlist.h
move misc/dlist.h to sys/dlist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
d1b2718687 cleanup: include/: move uart.h to drivers/uart.h
move uart.h to drivers/uart.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
969f8f1c68 cleanup: include/: move entropy.h to drivers/entropy.h
move entropy.h to drivers/entropy.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
17ddd1714c cleanup: include/: move clock_control.h to drivers/clock_control.h
move clock_control.h to drivers/clock_control.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
e1e05a2eac cleanup: include/: move atomic.h to sys/atomic.h
move atomic.h to sys/atomic.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Vinayak Kariappa Chettimada
a438e71460 Bluetooth: controller: Add PA/LNA support on NRF_P1 GPIO pins
Added support for using NRF_P1 GPIO pins on nRF52840 SoC.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-27 15:17:20 +02:00
Johan Hedberg
d57a7b5138 Bluetooth: Mesh: Fix provisioning send error handling
Log all send errors, but don't try to call e.g. prov_send_fail_msg()
since that'll almost certainly fail as well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg
c4e225109e Bluetooth: Mesh: Fix rejecting invalid remote public key
Mesh Profile Spec v1.0.1 | Section 5.4.2.3:
"The Provisioner and the device shall check whether the public key
provided by the peer device or obtained OOB is valid (see Section
5.4.3.1).

When the Provisioner receives an invalid public key, then provisioning
fails, and the Provisioner shall act as described in Section 5.4.4.
When the device receives an invalid public key, then provisioning
fails, and the device shall act as described in Section 5.4.4."

This is also in Erratum 10395 which is Mandatory for Mesh v1.0.

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

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

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg
10274718bb Bluetooth: Mesh: Generate new public key for each provisioning session
Mesh Profile Spec v1.0.1 Section 5.4.2.3: "If the public key was not
available using an OOB technology, then the public keys are exchanged
between the Provisioner and the unprovisioned device. For each
exchange, a new key pair shall be generated by the Provisioner and the
unprovisioned device."

This allows passing MESH/NODE/PROV/BV-12-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg
d6c34c4644 Bluetooth: Fix public key callback management
Clear the callback list once generation is complete and we've done
calling all callbacks. This lets us use bt_pub_key_gen() multiple
times, which before this patch could have resulted in a corrupt linked
list.

Also remove redundant callback dispatching from bt_pub_key_gen() since
the function checks for the PUB_KEY_BUSY flag in the beginning, i.e.
there cannot be other pending generation actions at this point in the
code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg
60f47c2d7e Bluetooth: SMP: Make public key handling more robust
Update code to handle other users of the public key generation APIs
by fetching the current public key at the beginning of each SMP
session. This is particularly important if someone creates the (rather
odd) combination of Mesh and SMP where Mesh will regenerate a new
key pair after provisioning.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg
8d9a65c2c8 Bluetooth: Mesh: Rename reset_link() to reset_adv_link()
This is a PB-ADV specific internal helper, so rename it appropriately
to avoid any confusion.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg
d39fbf5e9c Bluetooth: Mesh: Fix Public Key mismatch error handling
Mismatch in Public Key type will cause device to send Invalid Format
error, and treat any further PDU's as unexpected.

This affects MESH/NODE/PROV/BI-03-C test case.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Johan Hedberg
8de784a09d Bluetooth: Mesh: Fix missing protocol error timeout
Provisioning errors shouldn't cause device to close link. Upon error,
device will send Provisioning Failed PDU, and any further PDU's will
be considered as unexpected as per Mesh Profile section 5.4.4.

Also a timer is started every time device sends or receives a PDU.
This affects MESH/NODE/PROV/BV-10-C test case.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-27 12:18:33 +02:00
Vinayak Kariappa Chettimada
4fe004ad87 Bluetooth: controller: Fix handling zero length L2CAP start frame
Added a fix handling L2CAP start frame with payload length
of zero which otherwise sent zero length data start PDU on
air.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-26 16:32:14 +02:00
Laczen JMS
5f19c8160a subsys/settings: Update bluetooth module
Updated the bluetooth module to use static handlers. Removed the
old bt specific static registration.

The routine bt_settings_init() is still calling settings_init() which
IMO is not needed anymore.

Updates:

changed SETTINGS_REGISTER_STATIC() to SETTINGS_STATIC_HANDLER_DEFINE()
changed settings_handler_stat type to settings_handler_static type
removed NULL declarations
renamed bt_handler to bt_settingshandler, as bt_handler already exists.
renamed all bt_XXX_handler to bt_xxx_settingshandler to avoid any
overlap.
changed SETTINGS_STATIC_HANDLER_DEFINE() to create variable names from
_hname by just prepending them with settings_handler_.
updated all bt_xxx_settings_handler to just bt_xxx.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-26 16:31:01 +02:00
Johan Hedberg
46ea1df2ec Bluetooth: Fix not using log_strdup() for bt_uuid_str()
The string returned by bt_uuid_str() is not in ROM so log_strdup()
must be used on it. This also eliminates the following kind of warning
messages: "<err> log: argument 3 in log message "%s: start_handle
0x%04x end_handle 0x%04x type %s" missing log_strdup()."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-26 13:37:44 +02:00
Carles Cufi
3b3bbc1ee0 Bluetooth: hci_uart: Use DT for the hci_uart UART
Use Device Tree,and in particular a new 'bt-c2h-uart' to select which
UART is being used to communicate with an external BLE Host when acting
as a Controller.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-06-26 12:37:04 +02:00
Peter A. Bigot
587c35fa64 Bluetooth: gatt: avoid assumptions about characteristic handles
Although the Characteristic Value descriptor is required to be
immediately after the characteristic descriptor, the specification
allows for gaps in the corresponding Attribute handles.  Use the value
handle from the characteristic descriptor for value reads.

See BLUETOOTH CORE SPECIFICATION Version 5.1 Vol 3, Part G section 2.5.1
(p. 2345), first paragraph.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-06-25 18:24:32 +02:00
Johan Hedberg
4857cb852c Bluetooth: Mesh: Fix segmented message RPL behavior
Update the Replay Protection List handling for segmented messages to
be more in line with Figure 3.43 in Mesh Profile Specification 1.0.
This means that the RPL check and update need to be split into two
independent steps rather than always doing these together.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-25 11:35:08 +02:00
Luiz Augusto von Dentz
3408bfe211 Bluetooth: shell: gatt: Add discover command
This adds discover command which can be used to discover all attributes
using BT_GATT_DISCOVER_ATTRIBUTE:

uart:~$ gatt discover
Discover pending
Descriptor 2800 found: handle 1
Descriptor 2803 found: handle 2
Descriptor 2a00 found: handle 3
Descriptor 2803 found: handle 4
Descriptor 2a01 found: handle 5
Descriptor 2800 found: handle 6
Descriptor 2803 found: handle 7
Descriptor 2a05 found: handle 8
Descriptor 2902 found: handle 9
Descriptor 2803 found: handle a
Descriptor 2b29 found: handle b
Descriptor 2803 found: handle c
Descriptor 2b2a found: handle d
Descriptor 2803 found: handle e
Descriptor 2b2b found: handle f

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-24 12:16:49 +02:00
Luiz Augusto von Dentz
eb8abda6b0 Bluetooth: GATT: Fix bt_gatt_discovery with BT_GATT_DISCOVER_DESCRIPTOR
Fix iterating past the response which causes an invalid memory to be
accessed and passed over to the callback as if there were more
attributes found.

Fixes #16602

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-24 12:16:49 +02:00
Morten Priess
14537fee9d bluetooth: controller: Moved ull_entropy_get to LLL
Moved and renamed ull_entropy_get to lll_entropy_get, placed under
vendor specific ll_sw. This is needed for SW implemented entropy,
to allow vendor implementation of faster, less secure random number
generator for randomizing ADV timing.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-06-20 10:30:28 +02:00
Anas Nashif
f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Johan Hedberg
4e89d29416 Bluetooth: Fix expiring RPA when different local identities are used
When advertising with different identities we need to flag any
programmed RPA as invalid if it was generated using a different
identity.

Fixes #16893

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-19 11:07:52 +03:00
Johan Hedberg
72e80104c1 Bluetooth: Remove unused bt_hci_get_cmd_opcode() function
This function has no users in the tree.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-19 11:07:27 +03:00
Johan Hedberg
a16d513162 Bluetooth: Remove unnecessary HCI command data array
This array was created because more than 4 bytes were needed, however
now the minimum is 8 bytes, so we can use the net_buf user data
directly.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-19 11:07:27 +03:00
David B. Kinder
2aebc980e2 doc: fix Kconfig misspellings
Fix misspellings in Kconfig files missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-06-18 15:07:52 -04:00
Laczen JMS
8ca8708224 subsys/settings: Update client modules
This updates all client modules to const char processing of
setting names.

Update of peripheral_dis sample

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-18 17:57:08 +02:00
Morten Priess
b34db7fb71 bluetooth: controller: Reverted revised ticker pending redesign
Reversed revised ticker implementation pending new design which resolves
the issues described in GH issues #16830.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-06-18 14:20:52 +02:00
Vinayak Kariappa Chettimada
3e56c2cf16 Bluetooth: controller: split: Fix buffer leak on disconnect
Fix pending Tx control buffer leak on supervision timeout.
Queued tx buffers in LLL consists of both data and control
PDUs but only data buffers got correctly released.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-17 15:32:35 +02:00
Luiz Augusto von Dentz
db7b9a988b Bluetooth: Make it safe to allocate buffers from TX callback
This makes it safe to allocate buffer from the TX callback by freeing
the context before calling the callback which should wake up the TX
thread had it be pending on add_pending_tx.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-17 15:53:06 +03:00
Johan Hedberg
4396dc9c71 Bluetooth: Simplify bt_gatt_notify_cb() API
This API had several issues:

 - The parameter types and order were inconsistent with e.g.
   bt_le_adv_start()
 - There were no real users of num_params, which just caused increased
   code size and memory consumption for no good reason.
 - The error handling policy was arbitrary: if one of the
   notifications would fail it would be impossible for the caller to
   know if some notifications succeeded, i.e. at what point the
   failure happened. Some callers might also want to make note of the
   failure but continue trying to notify for the remaining parameters.

The first issue is easily fixable, but because of the other two I
think it's best we don't have this code as part of the stack, rather
require whoever needs it to do the for loop themselves. It's just a
few lines of code, so the benefit of having this in the stack was
anyway quite minimal.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-15 10:37:19 +03:00
Kumar Gala
a2693975d7 dts: Convert from DT_<COMPAT>_<INSTANCE>_<PROP> to DT_INST...
Change code from using now deprecated DT_<COMPAT>_<INSTANCE>_<PROP>
defines to using DT_INST_<INSTANCE>_<COMPAT>_<PROP>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-14 08:02:15 -05:00
Luiz Augusto von Dentz
a788ce23da Bluetooth: ATT: Fix unbalanced use of k_sem_give
k_sem_give shall only be used if no callback has been set otherwise
k_sem_take was not called which can break the flow control.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-14 15:55:07 +03:00
Luiz Augusto von Dentz
ec89ae6ff4 Bluetooth: ATT: Queue buffers on bt_att_send
This prevents threads to block which may deadlock when system wq is
used.

Fixes #16803

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-14 15:55:07 +03:00
Vinayak Kariappa Chettimada
802718a773 Bluetooth: controller: BT_CTLR_USER_EXT depends on BT_LL_SW_SPLIT
Make the Kconfig option BT_CTLR_USER_EXT depend on
BT_LL_SW_SPLIT.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-13 15:11:31 +02:00
Vinayak Kariappa Chettimada
dd3e8241e9 Bluetooth: controller: split: Port random slave event backoff
Port the implementation that performed random backoff of
forced slave event scheduling.

When peer master implementation skips events, multiple
local overlapping slaves will randomize their forced
scheduling to break out of a round robin pattern increasing
the chance of synchronizing with their masters again.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-13 14:13:36 +02:00
Luiz Augusto von Dentz
e61c5b3630 Bluetooth: L2CAP: Fix inverting of SCID and DCID on disconnect
For the request:

DCID shall map to rx.cid:
  'This field specifies the endpoint of the channel to be disconnected
  on the device receiving this request.'

SCID shall map to tx.cid:
  'This field specifies the endpoint of the channel to be disconnected
  on the device sending this request.'

For the response when receiving the roles are inverted.

Fixes #16799

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-13 14:33:27 +03:00
Morten Priess
8a92818c0a 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.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-06-13 13:12:26 +02:00
Joakim Andersson
f5d2d99762 Bluetooth: controller: Fix scan request when advertising directed
Fix scan requests being processed during directed advertisiments.
Directed advertise packets are not scannable

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-06-13 10:51:51 +02:00
Luiz Augusto von Dentz
ada05eaaf4 Bluetooth: shell: Add number of matches to gatt show-db
This adds number of matches as optional parameter to gatt show-db:

> gatt show-db 2803 1
attr 0x005065f0 handle 0x0002 uuid 2803 perm 0x01

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-12 20:09:29 +03:00
Luiz Augusto von Dentz
e8d9609c36 Bluetooth: GATT: Fix bt_gatt_foreach_attr_type
Number of matches was not being properly handled causing the callback to
be called more than specified by the caller.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-12 20:09:29 +03:00
Tobias Svehagen
1c84d7c5eb Bluetooth: Change from bitfields to normal types
Since the bt_mesh_msg_ctx struct no longer has a size that is a
multiple of 2, the bitfields might as well be made to normal types
as this will minimize the code generated to access them.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-06-12 15:51:04 +03:00
Tobias Svehagen
4866fa9e58 Bluetooth: Make RSSI value available to mesh applications
By moving the rssi value from the bt_mesh_net_rx struct to the
bt_mesh_msg_ctx struct, it will be available to applications via
the mesh op callbacks.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-06-12 15:51:04 +03:00
Mariusz Skamra
f6665c812e Bluetooth: gatt: Fix infinite read_by_uuid procedure
The attribute handle used to read next attribute has to be incremented
to not loop reading the same attribute.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-06-12 12:57:43 +03:00
Rich Barlow
5c6e09b10a Bluetooth: Mesh: LPN: Clear sent_req on failure
When trying to establish friendship the Friend must respond to the
initial Friend Poll with a Friend Update. If this initial Friend Update
response is not received the Friendship establishment process must start
again.

When starting a second Friendship establishment processes the `sent_req`
field of the `lpn` struct was left set to `TRANS_CTL_OP_FRIEND_POLL`.
This prevented the initial Friend Poll being sent out on the second
attempt. Since the Friend Poll was not sent, no timeout is set and
nothing happens ever again. No more Friendship Requests are sent.

This commit clears `sent_req` back to zero when no Friend Update
response has been received after the initial Friend Poll.

Fixes #16678

Signed-off-by: Rich Barlow <rich@bennellick.com>
2019-06-12 11:44:41 +03:00
Vinayak Kariappa Chettimada
3cf304fd95 Bluetooth: controller: split: Add ULL/LLL architecture assert checks
Add some missing fatal asserts that need to be caught to
avoid unexpected failures in the implementation of the
architecture.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-12 10:25:09 +02:00
Luiz Augusto von Dentz
8ba5b73e8e Bluetooth: GATT: Fix assuming writes to CCC will always contain 2 bytes
Although unlikely it is possible that a remote may attempt to send just
1 byte as the write request allows to do that:

BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part F
page 2320:

  'If the attribute value has a fixed length and the Attribute Value
  parameter length is less than or equal to the length of the attribute
  value, the octets of the attribute value parameter length shall be
  written; all other octets in this attribute value shall be
  unchanged.'

Fixes #16734

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-11 15:47:06 +03:00
Vinayak Kariappa Chettimada
3169556592 Bluetooth: controller: split: Fix tx_ack mfifo count
Fix the tx_ack mfifo count to accomodate both data and
control PDUs being acknowledged.

With out this fix, pending maximum number of data plus
control PDUs in LLL on supervision timeout asserted due to
tx_ack mfifo overflow.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-11 13:14:46 +02:00
Vinayak Kariappa Chettimada
23a6de5dd0 Bluetooth: controller: split: Port slave conn update assert fix
Explicitly track the connection update related ticker stop
and start to avoid asserting due to ticker update being done
at the same time for compensating the master clock drift.

Relates to #11764.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-11 11:09:38 +02:00
Vinayak Kariappa Chettimada
b11a0d35ee Bluetooth: controller: split: Add internal ull_update_mark func
Added an internal ull_update_mark function to detect race
conditions while stopping ticker instances during slave
drift, disconnection and connection update.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-11 11:09:38 +02:00
Nicolas Pitre
b1d3742ce2 linker generated list: introduce Z_STRUCT_SECTION_ITERABLE()
This convenience macro wraps Z_DECL_ALIGN() and __in_section() to
simplify static definitions of structure instances gathered in dedicated
sections. Most of the time those go together, and the section name is
already closely related to the struct type, so abstracting things behind
a simpler interface reduces probability of mistakes and makes the code
clearer. A few input section names have been adjusted accordingly.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-06 14:21:32 -07:00
Nicolas Pitre
8bb1f2a947 linker generated list: explicit alignment on data definitions
The alignment fix on struct device definitions should be done to all
such linker list tricks. Let's abstract the declaration plus alignment
with a macro and apply it to all concerned cases.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-06 14:21:32 -07:00
Anas Nashif
4c32258606 style: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Luiz Augusto von Dentz
aec04a02ed Bluetooth: GATT: Fix using invalid handle
When reading attributes from static services their handles will not be
set and must be resolved at runtime.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-06 13:32:17 +03:00
Vinayak Kariappa Chettimada
79cb615770 Bluetooth: controller: split: Port Enc setup to be queueable
Port the fix for the controller implementation to make start
encryption queueable if there is any control procedure in
progress.

Refer to #15335.
Relates to #15335, #15186, #15958 and #14636.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-06 10:34:13 +02:00
Vinayak Kariappa Chettimada
d244ee878f Bluetooth: shell: Fix disconnect command argument count
Fix disconnect command optional argument count to permit the
supply of Bluetooth Address so as to be able to cancel a
pending central initiated connection creation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-05 16:29:06 +02:00
Joakim Andersson
e182d75ef7 Bluetooth: host: Fix gatt indicate when conn is NULL
Fix gatt indicate when conn is NULL and called with characteristic
declaration as the attribute argument. In this case the handle was not
advanced to the characteristic value. This is inconsistent with the rest
of the notify and indicate API

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-06-05 17:24:36 +03:00
Johan Hedberg
82497eca2b Bluetooth: Mesh: Fix missing implementation of Proxy SAR timeout
Mesh Profile 1.0 Section 6.6:
"The timeout for the SAR transfer is 20 seconds. When the timeout
expires, the Proxy Server shall disconnect."

This will let qualification test case MESH/SR/PROX/BV-05-C pass
without requiring an explicit disconnect.

Fixes #16600

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-06-05 17:13:56 +03:00
Luiz Augusto von Dentz
2699d05e45 Bluetooth: Fix BT_ATT_ENFORCE_FLOW
This moves the processing packets of upper layers from RX thread to the
system workqueue so they have the same priority as the TX callbacks
which has the added benefit of making any protocol on top of L2CAP to
be executed using system wq stack.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-05 16:45:57 +03:00
Vinayak Kariappa Chettimada
a2c84ecf9e Bluetooth: Fix building of broadcaster or observer only
Fix conditional compilations to allow building broadcaster
and/or observer only applications.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-04 14:08:59 +02:00
Luiz Augusto von Dentz
2692f2e616 Bluetooth: Shell: Add gatt notify command
This adds gatt notify command which can be used to exercise the
bt_gatt_notify* APIs.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz
93dfa640dd Bluetooth: Shell: Fix having gatt unregister twice
Only one command handle shall be needed.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz
362497235d Bluetooth: GATT: Disable flow control if running with POSIX_ARCH
Disable flow control with POSIX_ARCH since these boards tend to run
faster than normal defering the TX callback to system wq may not be
able to run before another packet is received.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz
8a7615f4a3 Bluetooth: conn: Defer bt_conn_tx callback to system wq
This makes the transmission complete callbacks to run on system wq
context so they are not executed in TX thread which usually has a much
smaller, and non-configurable, stack size.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz
648a53d50f Bluetooth: GATT: Add support to notify by UUID
This reworks bt_gatt_notify_cb to allow passing an UUID, in addition to
that it can now accept multiple notification at once as there could be
multiple instance of the same UUID the user can set multiple set of
parameters.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz
9bf61dac75 Bluetooth: shell: Make use of bt_gatt_foreach_attr_type
This make use of bt_gatt_foreach_attr_type in gatt show-db to match
attributes by UUID.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz
e6ef539667 Bluetooth: GATT: Make use of bt_gatt_foreach_attr_type on bt_gatt_notify
This make use of bt_gatt_foreach_attr_type to match the CCC UUID which
previously was not possible with bt_gatt_foreach_attr.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Luiz Augusto von Dentz
a5c07aa7fb Bluetooth: GATT: Add bt_gatt_foreach_attr_type
This adds bt_gatt_foreach_attr_type which can match attribute by UUID
and/or attribute user_data, in addition of that the user can also limit
the number of matches.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-04 09:52:47 +03:00
Erwan Gouriou
3d9416bfed drivers/bluetooth/hci: Implement HCI driver for stm32wb
Implement HCI driver for STM32WB. It allows host to controller.
It is based on ST library allowing communication over RAM shared
bewteen chip's C-M4 and C-M0 cores.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-06-03 09:38:19 -04:00
Arthur Crepin-Leblond
1d36734799 Bluetooth: gatt: Reuse existing handles from a previously added service
When removing a service using bt_gatt_service_unregister, its attributes
handles will keep their value which can cause a problem when adding the
service again to the GATT database.
When re-adding, the gatt_register routine is taking the last handle of
the GATT database to compare it with the handles of the service to be
added.
If a service has handles with a lower value than the last handle of
the database an error will occur.
If we add/remove/add the last service, no error will occur as its
handles are always greater than the last one of the database.

Instead of resetting the handles when unregistering a service and
reassign new ones we make sure that the handles of the services are
not in use in the GATT database in order to place the service back
where it used to be.

Signed-off-by: Arthur Crepin-Leblond <arthur.crepin@proglove.de>
2019-05-30 17:17:30 -04:00
Asger Munk Nielsen
eb73a32bc1 Bluetooth: controller: Moved advanced settings in Kconfig
Moved some user defined Kconfig constants to advanced
settings menu.

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2019-05-30 17:14:54 -04:00
Asger Munk Nielsen
8844b7f5a5 Bluetooth: controller: Enable use of user defined protocols
Implements hooks to implement user protocols in ull.c
A user defined init function can now be called, this code is gated by
the CONFIG_BT_CTLR_USER_EXT define.
A user defined PDU length can now also be defined using the Kconfig
CONFIG_BT_RX_USER_PDU_LEN

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2019-05-30 17:14:54 -04:00
Marek Pieta
c8be3e81d3 Bluetooth: host: Fix bt_keys_get_addr()
Change fixes issue causing multiple keys creation for given address
and identity.

Fixes: #16478

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2019-05-30 13:21:16 +02:00
Radoslaw Koppel
974231ee6e subsys/settings: Add const modifier to the value pointer
This commit adds const modifier for value pointer in
settings_save_one function.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-05-29 10:11:12 -04:00
Luiz Augusto von Dentz
f8f6e7e117 Bluetooth: shell: Print L2CAP channel status
This uses the new status callback to print the channel status
whenever it changes.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz
c904a45d8f Bluetooth: L2CAP: Add callback to notify status
This adds a new callback for L2CAP channels which notities whenever
status has changed so the channel user can can for example resume or
suspend sending depending on the status.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz
270e8342f5 Bluetooth: L2CAP: Move Kconfig option to its own it own file
The Bluetooth menu has way too many option so this move the L2CAP
specific option to its own menu.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz
74135b3392 Bluetooth: shell: Add sent callback to L2CAP ops
This prints to the output when a packet finishes transmitting:

uart:~$ l2cap send 2
Outgoing data channel 0x005166a0 transmitted
Outgoing data channel 0x005166a0 transmitted

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz
d8f20fe1e0 Bluetooth: L2CAP: Add sent callback
This adds a new callback to bt_l2cap_chan_ops which is called whenever a
SDU is completely sent.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz
b65fe62719 Bluetooth: Add possibility to pass a user_data to conn_tx_cb_t
This allows setting a custom pointer to be passed back to the complete
callback at expense of increasing the buffers in 4 bytes.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz
a3bea8872b Bluetooth: L2CAP: Move fixed channels to its own section in ROM
This changes the declaration of fixed channels to be statically defined
with use of BT_L2CAP_CHANNEL_DEFINE since fixed channels are never
unregistered.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Vinayak Kariappa Chettimada
8de64fcb81 Bluetooth: controller: split: Fix shell app regression
Fix shell app regression due to stale tmp role implementation
not fully being removed in commit 4c77bf6194 ("Bluetooth:
controller: Remove redundant tmp role implementation").

The regression caused ticker indexes outside of allocations to
be accessed causing application faults and memory corruptions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-28 21:31:55 -04:00
Alexander Svensen
67de7ec86d Bluetooth: controller: split: Refactor if defines in lll_scan.c
This commit refactors if defines to use IS_ENABLED macro
for readability.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-27 09:24:44 -04:00
Alexander Svensen
1c33d90fdb Bluetooth: controller: split: Refactor if defines in lll_adv.c
This commit refactors if defines to use IS_ENABLED macro
for readability.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-27 09:19:06 -04:00
Kamil Piszczek
e4409d5d7d Bluetooth: smp: adding LE SC OOB support for peripheral side
Added support for the LE SC pairing with the OOB data. The peripheral
side is only supported for now.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-05-27 13:50:46 +02:00
Joakim Andersson
34758e8349 Bluetooth: controller: Fix rx_ftr and extra overlapping memory
The the footer structure and extra bytes (rssi, resolving index etc.)
were overlapping in memory, rx_ftr was moved into the header, but the
extra and footer are still being read from the same place, extra was
written to the end. So this avoided memory corruption, but reading extra
reads wrong information.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-27 12:59:05 +02:00
Joakim Andersson
9e96df39f2 Bluetooth: controller: Fix compilation without broadcaster or observer
Fix compilation issues in central_hr or peripheral_hr sample when using
split LL and privacy is enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Joakim Andersson
cecd7f8d70 Bluetooth: controller: Copy the connect_ind into node_rx
The node_rx buffer does not contain the data from the connect ind, so
copy it over.
Also back up the adv pdu chan_sel bit so that it can be used to properly
select the correct channel selection algorithm

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Joakim Andersson
6db4776980 Bluetooth: controller: Fix pdu being overwritten while in use
The node_rx buffer for the connect ind buffer is being reused to send
connection complete event, make sure all data is backed up before
reusing the buffer.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Joakim Andersson
65b3f17aa9 Bluetooth: controller: Fix initialization of rl_idx and rpa_gen
The privacy state variables rl_idx and rpa_gen was not initialized
properly, which results in connection failing to be established.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Vinayak Kariappa Chettimada
b928cef69c Bluetooth: controller: split: Port h/w privacy feature
Ported h/w based LL privacy to ULL/LLL split architecture.

Fixes #14675.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Vinayak Kariappa Chettimada
c5c87c38eb Revert "Bluetooth: controller: Disable controller privacy feature"
This reverts commit c629ea8a64.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Tedd Ho-Jeong An
fccb2e1ffc Bluetooth: GATT: Fix using a wrong handle
This patch fixes to use the right handle value.

Fixes #16341

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2019-05-23 12:31:35 +03:00
Asger Munk Nielsen
69790e5c73 Bluetooth: controller: Enable use of proprietary rx demuxing functions
Code refactored to allow calling of a proprietary rx demux function.
This will enable implementation of proprietary protocols and
functionality that is not yet public, while keeping a common zephyr
code base.

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2019-05-22 14:59:30 +02:00
Peter A. Bigot
ea6cad9b89 Bluetooth: controller: remove duplicated code
A conditional block to save a directed advertising report flag was
present three times.  Remove two of the blocks.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-05-21 21:42:01 -04:00
Alexander Svensen
63a93e8b5a Bluetooth: controller: split: Refactor if_defines to is_enabled in lll.c
This commit refactors if defines to use the macro is_enabled,
for readability

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-21 14:40:21 +02:00
Thomas Ebert Hansen
5e1de1a983 Bluetooth: Add support for vendor-specific events
Add an event handler for HCI vendor-specific events with the
event code BT_HCI_EVT_VENDOR.

A vendor defined callback can be registered to be called when
vendor-Specific events are received in the stack. The callback can then
decode and handle the event; if not the stack will decode and handle
the event.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2019-05-20 13:33:36 +02:00
Luiz Augusto von Dentz
852b1dca55 Bluetooth: GATT: Fix not parsing result of Read by Type
When using the procedure Read By Type the response may contain multiple
instances so it needs to be parsed properly. When dealing with long
values only the beggining will be read, for the remaining bytes the
application should issue another bt_gatt_read with offset so Read Blob
procedure is used as recommended by the spec:

BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part F page 2312:

The Read Blob Request would be used to read the remaining octets of a
long attribute value.

Fixes #16107

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-17 15:29:37 +03:00
Joakim Andersson
172dcec236 Bluetooth: controller: Fix unknown rsp received during enc procedure
Port fix for #14044 from legacy LL to split LL.

The master is using unknown rsp to terminate slave side initiated
procedures that has collided with the encryption procedure initiated by
the master.
We need to handle an unknown response that is sent in unencrypted during
the encryption procedure, even though we have already set up to receive
encrypted packets.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-05-15 10:10:42 +02:00
Joakim Andersson
289eab6ad5 Bluetooth: controller: Remove incorrect comment
Remove comment stating that UNKNOWN_RSP during encryption procedure
is a workaround.
The core spec mandates that connections should not be dropped if
receiving this control packet during encryption procedure.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-05-15 10:10:42 +02:00
Alexander Svensen
d9d85fd1d3 Bluetooth: controller: split: Refactor the lll_clock_wait() function
This is a pure refactoring of the k32src_wait function. It used the
following rules when refactoring:

Don't use the preprocessor when unprocessed C language suffices.

Don't undefine macro's.

Avoid global variables when possible.

Use consistent names for similiar things (hf_clock, lf_clock).

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-14 14:18:02 +02:00
Alexander Svensen
3d94df7e8e Bluetooth: controller: split: Fix master role RSSI measurement
Fix broken master role RSSI measurement. Since the original
contribution clean up into Zephyr, the radio shorts that was
set for measuring the RSSI for master role has been broken,
as it was cleared by the radio switching code further in the
Tx ISR.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-14 14:08:11 +02:00
Asger Munk Nielsen
58e9ac6811 bluetooth: Controller: Refactor node_rx footer to avoid ptr arithmetic
The old footer was appended after PDU using pointer arithmetic. Now
the footer fields have been moved to the header struct, the
footer fields are now statically located in the data structure,
this is type safe and fields can be referred to by their actual
names rather than indirectly through reference to other members,
thus avoiding pointer arithmetic. Secondly, this change will pave
the way for adding other meta data in the future.

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2019-05-14 10:56:16 +02:00
Ulf Magnusson
e7be378a47 Bluetooth: kconfig: Put 'menuconfig BT' in top-level menu
The 'Bluetooth' menu contains just 'config BT' and its indented
children.

Remove one menu level by removing the 'Bluetooth' menu and turning BT
into a 'menuconfig' symbol. Also change the prompt from "Bluetooth
support" to just "Bluetooth", to make it consistent with e.g. "Logging".

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-05-14 10:27:11 +02:00
Jakub Rzeszutko
d9c18ff05e boards: arm: Add Nordic nRF52811 board
This commit adds support for board: nrf52811_PCA10056.

The nRF52840 DK: PCA10056 is the recommend development kit, it emulates
the nRF52811, and can be used as a starting point for development
before moving over to a custom board.

Please note that this development kit does not support Bluetooth
Direction Finding. What is more it cannot be used with most of Arduino
shields because of PCA10056 PIN layout.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-05-14 09:52:57 +02:00
Peter Herager
95e1eb960b Bluetooth: Add additional attributes to DIS
Add SW, HW, FW & serial attributes to DIS
Add support for reading attributes from settings during boot

Signed-off-by: Peter Herager <pehe@oticon.com>
2019-05-08 20:17:07 +03:00
Peter Herager
4678447d45 Bluetooth: Add debug kconfig for bluetooth services
Add kconfig to enable debug output for bluetoth services

Signed-off-by: Peter Herager <pehe@oticon.com>
2019-05-08 20:17:07 +03:00
Alexander Svensen
774d5e871c Bluetooth: controller: split: Fix Conn Param Req procedure stall issue
Fix an issue wherein local or remote initiated Connection
Parameter Request procedure would stall without generation
of LE Connection Update Complete HCI event because a local
or remote initiated PHY Update procedure has overwritten the
currently active Link Layer Control Procedure type.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-08 11:21:52 +02:00
Mariusz Skamra
44739f4427 Bluetooth: controller: Workaround CPR procedure collision at CPU instant
This is a workaround for IOP issue, where peer rejects LLCP Slave
Connection Parameter Request with LMP Error Transaction Collision
error code even if previous request is complete at the instant.

Relates to #15366.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-07 23:17:34 -04:00
Luiz Augusto von Dentz
f9e89e5532 Bluetooth: shell: GATT: Make get command take a handle range
This enables get command to operate on a handle range so multiple
attributes values can be printed out:

uart:~$ gatt get 0x0001 0xffff
attr 0x00506600 uuid 2800 perm 0x01
00000000: 01 18
attr 0x00506600 uuid 2803 perm 0x01
00000000: 20 03 00 05 2A
attr 0x00506600 uuid 2a05 perm 0x00
attr 0x00506600 uuid 2902 perm 0x03
00000000: 00 00
attr 0x00506600 uuid 2803 perm 0x01
00000000: 0A 06 00 29 2B
attr 0x00506600 uuid 2b29 perm 0x03
00000000: 00
attr 0x00506600 uuid 2803 perm 0x01
00000000: 02 08 00 2A 2B
attr 0x00506600 uuid 2b2a perm 0x01
00000000: AA 2D 05 EB E8 1D D0 E5 F7 B9 C1 B6 3F 66 93 15
attr 0x00506600 uuid 2800 perm 0x01
00000000: 00 18
attr 0x00506600 uuid 2803 perm 0x01
00000000: 0A 0B 00 00 2A
attr 0x00506600 uuid 2a00 perm 0x09
00000000: 74 65 73 74 20 73 68 65 6C 6C
attr 0x00506600 uuid 2803 perm 0x01
00000000: 02 0D 00 01 2A
attr 0x00506600 uuid 2a01 perm 0x01
00000000: 00 00
attr 0x00506600 uuid 2803 perm 0x01
00000000: 02 0F 00 A6 2A
attr 0x00506600 uuid 2aa6 perm 0x01
00000000: 01
attr 0x00506600 uuid 2803 perm 0x01
00000000: 02 11 00 04 2A
attr 0x00506600 uuid 2a04 perm 0x01
00000000: 18 00 28 00 00 00 2A 00
attr 0x00506600 uuid 2800 perm 0x01
00000000: 0D 18
attr 0x00506600 uuid 2803 perm 0x01
00000000: 10 14 00 37 2A
attr 0x00506600 uuid 2a37 perm 0x00
attr 0x00506600 uuid 2902 perm 0x03
00000000: 00 00
attr 0x00506600 uuid 2803 perm 0x01
00000000: 02 17 00 38 2A
attr 0x00506600 uuid 2a38 perm 0x01
00000000: 00
attr 0x00506600 uuid 2803 perm 0x01
00000000: 08 19 00 39 2A
attr 0x00506600 uuid 2a39 perm 0x00

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-07 23:17:13 -04:00
Vinayak Kariappa Chettimada
019d282ab2 Bluetooth: controller: Fix Enc Setup overlap with Length Update
Fix the encryption setup queueing implementation to avoid
overlapping with local initiated Length Update Procedure.

Fixes #15733.
Relates to #15335, and #15186.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-07 23:16:23 -04:00
Johan Hedberg
e9ed634654 Bluetooth: Mesh: Fix postponing storage deadline indefinitely
If the local node keeps getting bombarded with messages, it's possible
that the storage timer gets rescheduled over and over again and never
expires. Add the necessary code to only reschedule the timer if the
new deadline is earlier than an existing one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-05-07 19:15:22 +03:00
Johan Hedberg
c0a7e4d778 Bluetooth: Mesh: Fix RPL storage timeout handling
The default values for the timeouts, as well as non-defaults in most
Mesh samples, use a higher value for the RPL than then generic mesh
storage timeout. This hasn't had any effect in practice since the code
only uses the RPL timeout if it is *smaller* than the generic one.

The original intention of the code was to use the RPL timeout,
regardless of what the generic one is, whenever the RPL is the only
thing that needs updating. Add some helper macros to track the various
groups of pending flags, and perform the appropriate checks to apply
the RPL timeout whenever it's smaller than the generic timeout, or if
there are no other items to store besides the RPL.

Fixes #15904

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-05-07 19:15:22 +03:00
Andrzej Głąbek
9a5cb2280e bluetooth: controller: hal: Correct the bit mask of used PPI channels
This is a follow up to commit 0eaa5e53a36af498115b4e56b1ea68cc89fc29ee.

`HAL_SW_SWITCH_RADIO_ENABLE_S2_PPI_BASE` is a base number for two PPI
channels, so two bits need to be marked in the used channel bit mask.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-05-07 11:12:01 +02:00
Mariusz Skamra
909f5a8a67 Bluetooth: gatt: Fix foreach iteration of static attributes
Fix calling bt_gatt_foreach_attr with start handle parameter set
to last static attribute handle.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-05-07 08:06:09 +03:00
Carles Cufi
2a0a48f6bb Bluetooth: controller: hal: Fix PPI macro naming
Due to a protracted merge of:
5e38ed9320
the naming for the HAL_SW_SWITCH_RADIO_ENABLE_S2_PPI changed
semnatics, now requiring use of
HAL_SW_SWITCH_RADIO_ENABLE_S2_PPI_BASE.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-05-06 17:46:56 +02:00
Andrzej Głąbek
5e38ed9320 ext: nrfx: Reserve PPI channels and groups used by Bluetooth controller
Mark the PPI channels and groups used by the Bluetooth controller
as occupied and thus unavailable for allocation through nrfx_ppi.

Add also a build time assertion that checks if these PPI channels
do not overlap with those assigned to the pwm_nrf5_sw driver
(to replace the comments in this driver that were supposed to warn
about this threat but had in fact little chance to be read by users).

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-05-06 15:25:44 +02:00
Alexander Svensen
e5cf9ce1f2 Bluetooth: controller: ull/lll: Do not feature exc more than once
Updated the controller implementation to not feature
exchange if already done once either by local or remote peer
device in an active connection session.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-06 14:47:48 +02:00
Vinayak Kariappa Chettimada
c629ea8a64 Bluetooth: controller: Disable controller privacy feature
Disable the unsupported controller privacy feature in the
ULL/LLL split architecture implementation.

This feature will be enabled in the future when it has been
ported to support multiple vendor SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada
90c205f6a0 Bluetooth: controller: Enable Zephyr VS HCI in ULL/LLL impl.
Enable the support for Zephyr HCI Vendor-Specific Commands
and Event in the ULL/LLL split architecture implementation
of the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada
06ddc2bbec Bluetooth: controller: Fix Rx and Tx buffer sizes
Fix incorrectly defined Rx and Tx buffer sizes. Wrong
calculation allocated more memory than necessary.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada
a4370b73f5 Bluetooth: controller: Fix ULL LLL execution priority selection
Fix Kconfig default values for ULL and LLL execution
priorities that caused build warnings when ranges changes
based on other priority values being selected.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada
9602a690bd Bluetooth: controller: Fix incorrect data type use in slot calc
Fix incorrect data type used in calculation of slot_us
detected by compiler, and reported as possible integer
overflow.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada
e2dbe4f6f3 Bluetooth: controller: Fix incorrect conditional compilation
Fix incorrect conditional compilation that caused compile
error when lll_scan structure did not contain connection
context included which is needed only for central role.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada
343937c542 Bluetooth: controller: ull/lll: Fix pin or key missing response
Fix the missing reset of Encryption Procedure state when the
peripheral responded with error reason as pin or key missing
which otherwise caused connection disconnection on next
reception of data or control packet.

Relates to #15570, and #15727.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-03 14:26:46 -04:00
Alexander Svensen
8a4c13146e Bluetooth: controller: ull/lll: Workaround CPR procedure collision
This is a workaround for IOP issue, where peer rejects LLCP Slave
Connection Parameter Request with LMP Error Transaction Collision
error code even if previous request is complete at the instant.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-03 14:24:47 -04:00
Vinayak Kariappa Chettimada
b8c2c7e71a Bluetooth: controller: ull/lll: Increase adv random delay resolution
Increase the resolution of advertising random delay from
1 ms unit to 1 ticker unit.

Relates to #10289, #10391, and #10398.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-03 08:33:13 -04:00
Vinayak Kariappa Chettimada
4cebd73824 Bluetooth: controller: Use void pointer to return rand value
Use void pointer to return random value from ull_entropy_get
interface.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-03 08:33:13 -04:00
Morten Priess
ffcbf121e8 bluetooth: controller: Made BT_CTLR_RX_PRIO_STACK_SIZE non-hidden
Added prompt to BT_CTLR_RX_PRIO_STACK_SIZE, allowing vendor specific
configuration of high priority Rx thread stack size for
!SOC_COMPATIBLE_NRF.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-05-03 12:40:00 +02:00
Vinayak Kariappa Chettimada
211a81f9f4 Bluetooth: controller: Fix XTAL advanced feature
Fix XTAL advanced feature by adding the missing
implementation to calculate and, retain or release the XTAL
clock source after a Bluetooth state or role is stopped.

Fixes #15817.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-03 12:20:22 +02:00
Vinayak Kariappa Chettimada
4b9dee8a74 Bluetooth: controller: Add GPIO Debug Pins for HFCLK state
Add implementation to toggle GPIO Debug pins on HFCLK
request and release by the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-03 12:20:22 +02:00
Vinayak Kariappa Chettimada
54e78b9041 Bluetooth: controller: Move LLL-to-ULL Tx Ack API to ULL
Move the LLL-to-ULL Tx Ack queue API to ULL files.

Fixes #49.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-02 22:53:45 -04:00
Vinayak Kariappa Chettimada
23269d9891 Bluetooth: controller: Implement low latency ULL processing
Implement a lower ISR latency ULL processing design. Instead
of looping use ISR/mayfly tail-chaining to process
successive ULL messages.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-02 22:53:45 -04:00
Vinayak Kariappa Chettimada
34f6d08ff0 Bluetooth: controller: Yield ULL processing when Ctrl PDU deferred
Implemented ULL to yield from processing in an infinite loop
if current PDU being handled is deferred.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-02 22:53:45 -04:00
Vinayak Kariappa Chettimada
a872911cbb Bluetooth: controller: Fix missing BT_CTLR_FILTER conditional
Fix missing BT_CTLR_FILTER conditional compilations that
cause compile errors when device whitelisting feature is
disabled in builds.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-02 07:48:38 -04:00
Morten Priess
646f617a39 bluetooth: controller: Allow out-of-tree vendor specific HCI commands
Renamed function vendor_cmd_handle to vendor_cmd_handle_common for
shared vendor commands. This allows vendor to implement
vendor_cmd_handle, containing both common and specific handling.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-05-02 12:28:38 +02:00
Mark Ruvald Pedersen
99fae68010 Bluetooth: controller: commentary and readability improvements
* Rename the stack local 'done' to 'evdone' so as to disambiguate from
  MFIFO_DEQUEUE_PEEK(done) which is actually 'mfifo_done'.

* add comment on ull_slave_done

* add comments to addr_us_get

* add comments to HCI_CLASS

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 11:12:21 +02:00
Vinayak Kariappa Chettimada
23636cbae0 Bluetooth: controller: Fix pin or key missing response
Fix the missing reset of Encryption Procedure state when the
peripheral responded with error reason as pin or key missing
which otherwise caused connection disconnection on next
reception of data or control packet.

Relates to #15570.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-02 11:04:16 +02:00
Johan Hedberg
e69b4be2af Bluetooth: Fix return type for settings read callback
settings_read_cb is defined to return ssize_t and not size_t. This
also eliminates several Coverity warnings.

Fixes #15765
Fixes #15768
Fixes #15771
Fixes #15774
Fixes #15778

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-05-02 11:18:30 +03:00
Luiz Augusto von Dentz
bd007141fd Bluetooth: GATT: Rename BT_GATT_DB to BT_GATT_DYNAMIC_DB
This should be clearer about the intent of the option.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz
45e1ce8b52 Bluetooth: GATT: Move GATT/ATT option to Kconfig.gatt
This makes the host Kconfig a little less cluttered.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz
d7d64032f6 Bluetooth: GATT: Fix typo in commments
COFNIG_BT_GATT_CACHING when it should be CONFIG_BT_GATT_CACHING

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz
2c4e5d5f16 Bluetooth: GATT: Disable dynamic database by default
This makes BT_GATT_DB default to n which reduces the ram required for
many samples.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz
c42707c2d3 Bluetooth: Use BT_GATT_SERVICE_DEFINE whenever possible
This makes use of BT_GATT_SERVICE_DEFINE to statically define services
for services that are not required to be dynamically registered.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz
b3a6da671f Bluetooth: GATT: Add option to enable/disable database
This adds BT_GATT_DB option which can be used to enable/disable
registering/unregistering services dynamically:

with BT_GATT_DB=y (make ram_report):
      gatt.c                                    206     1.14%
        cf_cfg                                   32     0.18%
        db                                        8     0.04%
        db_hash                                  16     0.09%
        db_hash_work                             32     0.18%
        gatt_sc                                  80     0.44%
        init                                      4     0.02%
        last_static_handle                        2     0.01%
        sc_ccc_cfg                               32     0.18%

with BT_GATT_DB=n (make ram_report):
      gatt.c                                      6     0.03%
        init                                      4     0.02%
        last_static_handle                        2     0.01%

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz
e0f3ab6bf2 Bluetooth: GATT: Add support for static services
This reintroduces support for static service in the form of a new API,
BT_GATT_SERVICE_DEFINE, and changes the internal services (GAP/GATT)
to be defined as const as they are never register/unregistered.

Internal service needed to be renamed in order to keep the same order
as before since the section elements are sorted by name.

The result is the following (make ram_report):

before:
      gatt.c                                    572     0.66%
        cf_cfg                                   32     0.04%
        db                                        8     0.01%
        db_hash                                  16     0.02%
        db_hash_work                             32     0.04%
        gap_attrs				180     0.21%
        gap_svc                                  12     0.01%
        gatt_attrs                              160     0.18%
        gatt_sc                                  80     0.09%
        gatt_svc                                 12     0.01%
        sc_ccc_cfg                               32     0.04%
        subscriptions                             8     0.01%

after:
      gatt.c                                    210     0.24%
        cf_cfg                                   32     0.04%
        db                                        8     0.01%
        db_hash                                  16     0.02%
        db_hash_work                             32     0.04%
        gatt_sc                                  80     0.09%
        last_static_handle                        2     0.00%
        sc_ccc_cfg                               32     0.04%
        subscriptions                             8     0.01%

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Luiz Augusto von Dentz
0392ad0dc8 Bluetooth: GATT: Fix usage of uint16_t instead of u16_t
This fixes checkpatch complaning about usage of uint16_t.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Thomas Ebert Hansen
3ac8fa5c00 bluetooth: controller: Move Nordic specific code
Move lll_chan_set into Nordic LLL.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2019-05-01 10:40:41 -04:00
Thomas Ebert Hansen
a202c14ff5 bluetooth: controller: Move Nordic specific code
Move the call to radio_is_idle into Nordic LLL.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2019-05-01 10:40:41 -04:00
Vinayak Kariappa Chettimada
a1cbbbe9bd Bluetooth: controller: Fix nRF52840 Coded PHY timings
Fix the nRF52840 Coded PHY radio timings based on testing
with conformance tester.

Fixes the following conformance tests:
LL/CON/MAS/BV-52-C [Master Receiving Data, LE Coded, CI Change]
LL/CON/MAS/BV-54-C [Slave Receiving Data, LE Coded, CI Change]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-01 10:28:26 -04:00
Vinayak Kariappa Chettimada
f35dd8ece8 Bluetooth: controller: Fix regression in Coded PHY CI Change
Fix the regression in Coded PHY CI change implementation
introduced by reverting the commit 9d1ca9c390 ("Bluetooth:
controller: remove redundant PPI channel and TIMER CC").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-05-01 10:28:26 -04:00
Morten Priess
c741ef6efd bluetooth: controller: Mayfly yield after call under Kconfig
Added Kconfig BT_MAYFLY_YIELD_AFTER_CALL to support vendor requirement
of invoking all outstanding mayflies for a given callee in
mayfly_run().

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-04-30 15:42:20 +02:00
Morten Priess
d533dde0ad bluetooth: controller: Moved library source for lll_test.c
Moved library source for nordic/lll/lll_test.c under
CONFIG_BT_LLL_VENDOR_NORDIC condition.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-04-30 15:41:56 +02:00
Morten Priess
23e1f4d2bc bluetooth: controller: Added missing variable initializations
In ull.c ll_rx_get, a configuration without CONFIG_BT_CONN would
sometimes return an uninitialized node_rx.
In ull_scan.c, the scanning channel was not initialized to 0 (37). This
would cause new scanning to start at random index (0,1,2).

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-04-30 15:41:23 +02:00
Morten Priess
4596e155a3 bluetooth: controller: Minor refactoring in ticker.c
Moved duplicate code to function. Removed superfluous include.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-04-30 15:11:55 +02:00
Morten Priess
21ae70504d bluetooth: controller: Source code documentation of ticker
Added source code documentation to ticker.c.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-04-30 15:11:55 +02:00
Erik Brockhoff
5c3709c13f bluetooth: controller: Add def's re. update to slot reservation calc
Add defines to support updated slot reservation calculation in advertise
Note: Numbers used in added defines are subject to HW specific tuning

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2019-04-30 15:10:13 +02:00
Erik Brockhoff
1618c1b885 bluetooth: controller: Update to use new EVENT_IFS_US define
Added a new define (EVENT_IFS_US) to pdu.h - this is now used instead of
previous TIFS_US from vendor specific header

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2019-04-30 15:10:13 +02:00
Erik Brockhoff
1090b45225 bluetooth: controller: Update slot reservation time calculation for ADV
Correct slot reservation time calc for legacy advertise
Add dependency on data lengths for advertise and scan response

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2019-04-30 15:10:13 +02:00
Vinayak Kariappa Chettimada
5257fede63 Bluetooth: controller: Fix advanced XTAL feature regression
Fix regression by the addition of CONFIG_BT_CONN conditional
compilation that disabled the advanced clock (crystal)
oscillator management when only observer and/or advertiser
states supported in the controller build.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-29 13:08:12 +02:00
Marek Pieta
0654c33229 bluetooth: Fix bt_conn->id handling
Fixed bt_conn->id handling in bt_conn_create_slave_le function.

Fixes: #15698

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2019-04-29 11:34:08 +03:00
François Delawarde
94451b22fc subsys/settings: Allow to register custom backends in settings subsystem
Major changes are:
- Expose settings backend API to enable custom backend support.
- Add a new CONFIG_SETTINGS_CUSTOM backend to allow registering a custom
backend.
- Change api of the handlers h_set() routines to allow for
backend-specific read callbacks.
- Provide a customizable settings_backend_init() routine for custom
backends.
- Move runtime settings support to be its own backend.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-04-26 11:24:31 +03:00
Kamil Piszczek
c5f6e8bed4 bluetooth: host: format specifier alignment
Aligned format specifiers for the Bluetooth Host. Now, the format
specifier matches the variable type.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-04-24 13:05:11 -07:00
Tedd Ho-Jeong An
6576efe038 Bluetooth: shell: Add command for Read Using Characteristic UUID
This patch adds a command for Read Using Characteristic UUID.

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2019-04-24 09:39:53 -07:00
Tedd Ho-Jeong An
100f671bca Bluetooth: GATT: Add support for Read Using Characteristic UUID
This patch adds support for Read Using Characteristic UUID which is one
of the procedure to read the characteristic value especially when the
client only knows the characteristic UUID and does not know the handle
of the characteristic.

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2019-04-24 09:39:53 -07:00
Vinayak Kariappa Chettimada
e90ba89812 Bluetooth: controller: Fixes to pass DLE/PHY conformance tests
Added implementation to pause data PDU transmission during
PHY update procedure in order to comply to BT Spec. v5.1
Vol.6, Part B, Section 5.1.10.1 Packet transmit time
restrictions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-23 12:09:23 -07:00
Vinayak Kariappa Chettimada
7b68ec888c Bluetooth: controller: Move PKT_US to ULL internal header
Minor refactoring to move PKT_US into ULL internal header,
and rename ull_conn_allowed_check to ull_conn_llcp_req.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-23 12:09:23 -07:00
Vinayak Kariappa Chettimada
705515c092 Bluetooth: controller: Data Length Update port to ULL/LLL arch
Ported implementation of Data Length Update Procedure to
ULL/LLL architecture of the Link Layer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-23 12:09:23 -07:00
Luiz Augusto von Dentz
2ba6146f66 Bluetooth: Shell: Add GATT command set
This introduces set command to GATT which can be used to write local
attributes:

uart:~$ gatt set 0x000b 62 6c 61 68
attr 0x004235a8 uuid 2a00 perm 0x09
00000000: 62 6C 61 68

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-18 17:50:16 -04:00
Luiz Augusto von Dentz
4c80bb57aa Bluetooth: Shell: Add GATT command get
This introduces get command to GATT which can be used to read the
local attributes:

uart:~$ gatt get 0x000b
attr 0x004235a8 uuid 2a00 perm 0x09
00000000: 74 65 73 74 20 73 68 65 6C 6C

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-18 17:50:16 -04:00
Luiz Augusto von Dentz
090f95d2ba Bluetooth: Shell: Add option UUID parameter to GATT show-db
This enables locating specific attribute in the database:

uart:~$ gatt show-db 0x2a00
attr 0x004235a8 handle 0x000b uuid 2a00 perm 0x09

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-18 17:50:16 -04:00
Luiz Augusto von Dentz
26fea23435 Bluetooth: shell: Make show-db print the total number of attributes
In addition to just print each attribute this also include the total
number of attribute and how much the database consumes:

uart:~$ gatt show-db
attr 0x00423460 handle 0x0001 uuid 2800 perm 0x01
attr 0x00423474 handle 0x0002 uuid 2803 perm 0x01
attr 0x00423488 handle 0x0003 uuid 2a05 perm 0x00
attr 0x0042349c handle 0x0004 uuid 2902 perm 0x03
attr 0x004234b0 handle 0x0005 uuid 2803 perm 0x01
attr 0x004234c4 handle 0x0006 uuid 2b29 perm 0x03
attr 0x004234d8 handle 0x0007 uuid 2803 perm 0x01
attr 0x004234ec handle 0x0008 uuid 2b2a perm 0x01
attr 0x00423580 handle 0x0009 uuid 2800 perm 0x01
attr 0x00423594 handle 0x000a uuid 2803 perm 0x01
attr 0x004235a8 handle 0x000b uuid 2a00 perm 0x09
attr 0x004235bc handle 0x000c uuid 2803 perm 0x01
attr 0x004235d0 handle 0x000d uuid 2a01 perm 0x01
attr 0x004235e4 handle 0x000e uuid 2803 perm 0x01
attr 0x004235f8 handle 0x000f uuid 2aa6 perm 0x01
attr 0x0042360c handle 0x0010 uuid 2803 perm 0x01
attr 0x00423620 handle 0x0011 uuid 2a04 perm 0x01
=================================================
Total: 2 services 17 attributes (476 bytes)

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-18 17:50:16 -04:00
Luiz Augusto von Dentz
09c06a1232 Bluetooth: Shell: Convert users of hexdump to shell_hexdump
This replaces the use of hexdump with shell_hexdump and removes the
former.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-18 17:50:16 -04:00
Pawel Dunaj
56a2691e1c bluetooth: host: Unref conn on direct adv start error
Unref conn when direct adv start exits with an error.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-04-18 11:59:12 +02:00
Pawel Dunaj
d4dbab9f83 bluetooth: host: Use correct identity when direct advertising
When starting direct advertising use correct identity during
connection lookup.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-04-18 11:59:12 +02:00
Pawel Dunaj
26cfbf81db bluetooth: host: Save id when allocating CCC cfg slot
Make sure that along with address identity is saved too.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-04-18 11:58:27 +02:00
Reham Tarek
a1d69fb725 Bluetooth: Mesh: AES-CCM: Fix output MIC with additional data
General MIC fix for AAD lengths up to 14 bytes.
This case doesn't concern the mesh stack because it uses 16 bytes.

Signed-off-by: Reham Tarek <reham.tarek@si-vision.com>
2019-04-17 10:08:03 +03:00
Marek Pieta
321fec4a38 bluetooth: hci_core: Remove misleading log
Changed misleading log of all stack sizes.
Only leaving stacks from hci_core.c file.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2019-04-17 10:06:04 +03:00
Luiz Augusto von Dentz
951822391d Bluetooth: GATT: Store database hash
This stores the database hash and check if it has changed on commit
skipping service changed if hash matches.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-17 10:05:19 +03:00
Luiz Augusto von Dentz
f7b4069ac2 Bluetooth: Settings: Fix not allowing custom handlers without arguments
Custom handlers without any arguments don't since there is a check for
argc > 1, to fix this behavior removing the check.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-17 10:05:19 +03:00
Luiz Augusto von Dentz
755a6e503e Bluetooth: GATT: Fix iterating over requested handle range
If handle is over the range end return since handles are always placed
in ascending order.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-17 10:05:19 +03:00
Luiz Augusto von Dentz
4154f27ab5 Bluetooth: GATT: Skip ahead if handle is not within service handles
This reduces bt_gatt_foreach_attr complexity (O(n)) so it can skip
ahead when the start handle is not within its service handles.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-17 10:05:19 +03:00
Johan Hedberg
1a3d9fa0ba Bluetooth: Mesh: Add error checks for scan start/stop
It may be very important information for the developer if scanning
fails to start or stop, so add proper logs. There's no need to log
EALREADY errors, since the mesh stack doesn't track the current scan
state and simply relies on the under lying GAP layer to return this
error if the desired state is already set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-04-17 09:59:04 +03:00
Marek Pieta
51b45f0df6 bluetooth: conn: Fix bt_gatt_connected call
bt_gatt_connected should be only called, when there is no
connection error. Change fixes problem with receiving notifications
before connection.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2019-04-16 17:43:55 +02:00
Johan Hedberg
42d330406e Bluetooth: Mesh: Fix qualification test MESH/SR/HM/CFS/BV-02-C
The commit 8d0ef1eb85 attempted to fix
test case MESH/SR/HM/CFS/BV-02-C, however inadvertently ended up
introducing a hidden bug. This bug was unearthed thanks to commit
686f5c79cf. We have to keep always track
of the FastPeriodDivisor state whether we're using it (faults > 0) or
not (faults == 0). Introduce a boolean field to the model publication
that's used to indicate whether the FastPeriodDivisor should be
applied or not, instead of zeroing the divisor when there are no
faults (this would cause wrong behavior when faults appear again).

Additionally, the PTS seems to require that we wait until the end of
the existing period before sending the next Health Current Status,
rather than sending it immediately when the fault count changes.

Fixes #15365

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-04-11 21:24:55 +03:00
Vinayak Kariappa Chettimada
fff35bd682 Bluetooth: controller: Fix encryption setup to be queueable
Fix the controller implementation to make start encryption
queueable if there is any control procedure in progress.

The context related to encryption procedure is now shared so
that it will be used after the ongoing procedure completes.

The fix here maintains the old functionality of serializing
the queued data and LL Encryption Request PDU, so that data
queued before start encryption is acknowledged.

Fixes #15012.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-11 13:22:02 -04:00
Vinayak Kariappa Chettimada
e81acd8c3f Bluetooth: controller: Revert set encryption procedure pending
This reverts commit 0cf82cdd31.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-11 13:22:02 -04:00
Carles Cufi
bae9f1967b samples: Bluetooth: hci_uart: Implement NOP Command Complete
Implement the Controller counterpart to CONFIG_BT_WAIT_NOP so that it
issues a NOP Command Complete event after booting up, to signal to the
Host that it is ready to receive HCI traffic.

Fixes #15333

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-04-11 14:54:37 +02:00
Luiz Augusto von Dentz
f2a34a6106 Bluetooth: GATT: Fix not clearing Client Features
When a device is considered unpaired any configuration set in Client
Features shall also be removed.

Fixes #15329

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-11 12:04:53 +03:00
Joakim Andersson
0e7bf9b657 Bluetooth: controller: Send unknown rsp to unexpected ENC ctrl PDU
Send unknown rsp instead of asserting when encryption related control
PDUs are received in the wrong state.
This would allow an attacker to intentionally crash the device.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-04-10 14:01:21 +02:00
Joakim Andersson
9fb3abef1e Bluetooth: controller: Fix length request during encryption procedure
Stop the Length request procedure from initiating during the encryption
procedue. This would cause the peer to disconnect the link with error
code LMP_TRANSACTION_COLLISION

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-04-10 14:01:21 +02:00
Joakim Andersson
0cf82cdd31 Bluetooth: controller: Set encryption procedure pending
Set the encryption procedure pending and start it as soon as
there are no other procedures running.
This allows the Host to enqueue the encryption procedure, and not
get disallowed command because a different LL procedure is active.

Fixes #15012

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-04-10 14:01:21 +02:00
Johan Hedberg
63955e5f70 Bluetooth: Fix clearing conn->le.keys when unpairing
When calling bt_unpair() the keys were removed from flash, however a
pointer was left to the invalidated keys in case there was an existing
connection. This would then lead to a bogus entry being stored in
flash for a zero-address peer device. Fix this issue by clearing the
conn->le.keys pointer in the bt_unpair() function.

Fixes #15325

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-04-10 14:47:29 +03:00
Johan Hedberg
686f5c79cf Bluetooth: Mesh: Fix not updating health publication message
The bt_mesh_fault_update() API is meant for updating the publication
message and sending it out to the network, however it was missing the
necessary call to health_pub_update() which is responsible for
updating the publication message.

Fixes #15300

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-04-10 10:56:27 +03:00
Jim Paris
7cdfe7f26f Bluetooth: shell: fix build warning if !BT_CENTRAL
Fixes:
  .../zephyr/subsys/bluetooth/shell/bt.c:906:12:
     warning: 'cmd_chan_map' defined but not used [-Wunused-function]

Signed-off-by: Jim Paris <jim@jtan.com>
2019-04-08 12:36:15 +03:00
Johan Hedberg
309b7ff3b4 Bluetooth: Mesh: Update TODO to match current situation
Persistent storage is done. So are the configuration and health
clients. We're also not actively looking to optimize the provisioning
protocol & mesh networking memory usage anymore.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-04-07 09:39:30 -04:00
Anas Nashif
3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Joakim Andersson
fa20ac3693 Bluetooth: controller: Fix assert in raising event during proc collision
The fix done in #14938 introduced a later assert when raising an HCI
event for the procedure that was terminated during the procedure
collision handling. This assert happens because the unknown rsp
has information that is needed when raising the event.
Solve this by copying the scratch packet into the node buffer so that
we keep the data.

Fixes #15183

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-04-05 09:31:22 -04:00
Patrik Flykt
4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Patrik Flykt
97b3bd11a7 drivers: Rename reserved function names
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Luiz Augusto von Dentz
593d8561c9 Bluetooth: PPCP: Fix not being able to disable configurations
The spec allows to set to no specific value with use of 0xffff.

As this still enables entering values in the invalid range, 3200-65535
for min/max interval, this adds the necessary build checks to prevent
values within this range to be used and at same time check if min
interval is not bigger that max interval.

Fixes #15017

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-02 12:13:22 -04:00
Joakim Andersson
710adac50d Bluetooth: host: Add RPA in directed advertisement support
In order to advertise directed to a privacy enabled central the
initiator field of the directed adv packet needs to set to an RPA.
To instruct the controller to use an RPA in the initiator field own
address type should be set to either 0x02 or 0x03.
Since it is not certain that a remote device supports address resolution
of the initiator address we add an option to turn this on and give the
application the responsibility to check if peer supports this.

Fixes #14743

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-04-02 13:19:00 +02:00
Luiz Augusto von Dentz
c581163dcf Bluetooth: Fix not accepting string equal to CONFIG_BT_DEVICE_NAME_MAX
In order to accept string of the same size entered in
CONFIG_BT_DEVICE_NAME_MAX an extra byte must be allocated to guarantee
it will always be NULL terminated.

Fixes #15067

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-04-01 17:51:41 +03:00
Patrik Flykt
21358baa72 all: Update unsigend 'U' suffix due to multiplication
As the multiplication rule is updated, new unsigned suffixes
are added in the code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt
24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Johan Hedberg
49a34244be Bluetooth: Mesh: Remove redundant LOCAL_PUB_KEY flag
There's no need to track this info in prov.c since hci_core.c is
already doing it. Just query hci_core.c always using the
bt_pub_key_get() API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:39:59 +01:00
Johan Hedberg
c6fa295e6a Bluetooth: Mesh: Fix disconnecting existing provisioning bearers
If PB-GATT is disabled while there are connected clients, those
clients must be disconnected. Add a 'disconnect` parameter to
bt_mesh_proxy_prov_disable() to handle scenarios when we don't want to
disconnect (e.g. right after successfully finishing provisioning) and
tose where we do want to disconnect (e.g. user requesting to disable
the provisioning bearer).

Also make sure that we always update advertising, so that a stale
advertising set isn't left in the controller.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:39:59 +01:00
Johan Hedberg
7d3b627e19 Bluetooth: Mesh: Fix re-initializing provisioning state upon reset
If both PB-ADV and PB-GATT are supported, we need to properly
re-initialize variables such as link.rx.prev_id and (particularly
importantly) link.rx.buf. If we don't do this it may lead to the
following fault when trying to reprovision again:

***** USAGE FAULT *****
  Illegal use of the EPSR
***** Hardware exception *****
Current thread ID = 0x20001f10
Faulting instruction address = 0x0
Fatal fault in thread 0x20001f10! Aborting.

Fixes #14928

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:39:59 +01:00
Johan Hedberg
87fe134e65 Bluetooth: Mesh: Fix gen_prov struct definition
Remove unnecessary const keywords (the entire struct is const) and use
bool instead of u8_t for the require_link member.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:39:59 +01:00
Johan Hedberg
b40235b3e0 Bluetooth: Mesh: Take advantage of settings_delete() when possible
Using settings_delete() makes it much easier to understand what the
code is doing, and actually also reduces the amount of code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:23:46 +01:00
Johan Hedberg
35ebacbe06 Bluetooth: Clean up settings related code
Add error checking, remove redundant code, and improve the logging for
settings related functionality.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:23:46 +01:00
Johan Hedberg
f9450f072f Bluetooth: Remove unused ID_SIZE_MAX macro
There are no more user for this macro - just remove it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:23:46 +01:00
Johan Hedberg
bcc2d8f0a9 Bluetooth: GATT: Fix attribute read return parameter type
The read() callback of attributes returns ssize_t and not size_t. Fix
this, which also fixes a Coverity warning.

Fixes Coverity CID 197457
Fixes #14958

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 15:22:22 +01:00
Johan Hedberg
12bf7e6ead Bluetooth: Use bt_addr_le_copy() instead of direct assignment
The convention in the code is to use the appropriate address copying
functions instead of direct assignments. Even when a specific copying
function doesn't exist the convention is to use memcpy.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-28 09:02:00 -05:00
Joakim Andersson
273796e1bb Bluetooth: controller: Fix unknown rsp received during enc procedure
The master is using unknown rsp to terminate slave side initiated
procedures that has collided with the encryption procedure initiated by
the master.
We need to handle an unknown response that is sent in unencrypted during
the encryption procedure, even though we have already set up to receive
encrypted packets.

Fixes #14044

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-03-28 14:41:10 +01:00
Vinayak Kariappa Chettimada
3353c9f3c8 Bluetooth: Fix scan failed to start due to RPA timeout
Updating the Resolvable Private Address when advertising and
active scanning in progress fails and clears the RPA_VALID
flag; making the next bt_le_scan_start while continuing to
advertise to fail.

This is fixed by keeping the RPA_VALID flag remain set.
Stopping and starting active scanning to update RPA can be
implemented in a separate commit.

Fixes #9463.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-28 14:37:58 +01:00
Carles Cufi
42fcaf2df4 Bluetooth: shell: Add missing include path
When building ticker.c from the shell, it requires include access to the
Nordic HAL, so add the relevant folder to the include path.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-03-26 10:18:59 -05:00
Erwan Gouriou
7d81a099e6 Bluetooth: Mesh: Increase advertising thread stack size
With BT_HOST_CRYPTO, advertising stack size could be overflowed,
increase size to 1024 when BT_HOST_CRYPTO is enabled.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-03-25 22:51:18 -04:00
Jakub Rzeszutko
41ad9b716c shell: fix command bt scan
Command scan fixed in the way that it can take one mandatory parameter
and one optional. Previously it accepted only 2 mandatory parameters.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-03-25 20:38:35 +02:00
Jakub Rzeszutko
4557b6b2d1 shell: removed dead code in bt command
Removed automatic argument count checking in bt command. Now
it is possible to print a message that extra argument is not
recognized.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-03-25 20:38:35 +02:00
Jakub Rzeszutko
b6fc1af6ba shell: unify bt commands return value
Repleaced magic number 1 with define SHELL_CMD_HELP_PRINTED

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-03-25 20:38:35 +02:00
Johan Hedberg
f811e5446a Bluetooth: Fix missing checks for the BT_DEV_READY flag
Several public APIs were not checking the BT_DEV_READY flag, which
could lead to hard-to-debug behavior, particularly when the stack
lacks an identity address. Add the appropriate checks to these APIs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-25 10:04:45 +02:00
Johan Hedberg
12a413779d Bluetooth: Fix init procedure handling with BT_SETTINGS
The treatment of the BT_DEV_READY flag was broken when used together
with BT_SETTINGS. The flag would get set even though the stack was
still in a partially initialized state. Even worse, for central role
the stack would potentially try to initiate passive scanning without
having an identity address.

Refactor the code that sets the BT_DEV_READY flag (among other
initialization) into a separate bt_finalize_init() helper function and
call it when the settings have been loaded. Also clarify the warning
message given to the user in case settings_load() needs to be called.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-25 10:04:45 +02:00
Joakim Andersson
66d339a7c9 Bluetooth: controller: Fix scanner memory corruption
Fix a bug where the controller would use the length
field of the advertisement packet before checking
if the length field was valid.
It is possible that the controller has received a packet
that passes CRC check but has a length field that is invalid.
This would cause the scanner to overwrite the scan report
buffer

Fixes: #14741
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-03-22 13:58:24 +01:00
Johan Hedberg
3ebd9b4a09 Bluetooth: Mesh: Fix clearing model binding and subscriptions
The code for clearing model bindings and subscriptions was flawed in
that proper "cleared" entries were never stored in settings. The code
must pass 0 and NULL to settings_save_one() in case the entry is
desired to be cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-21 10:10:52 +02:00
Johan Hedberg
dac335c238 Bluetooth: Mesh: Fix clearing model subscription list
The code was storing a "cleared" entry in storage for every model,
regardless of them having any subscriptions or not. Update hte
mod_sub_list_clear() function to return a "cleared entries" count so
that the calling code can decide whether any action is needed or not.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-21 10:10:52 +02:00
Johan Hedberg
a0d762999d Bluetooth: Mesh: Clean up logging related to settings storage
Remove redundant "val (null)" logs and add a few missing BT_DBG()
calls to make the tracing of storage handling easier.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-21 10:10:52 +02:00
Johan Hedberg
4cac39e14a Bluetooth: Fix missing return statement in le_conn_param_req()
The le_conn_param_req() function was missing a return statement in
case of a failed connection lookup. This could lead to replying to the
connection parameter request twice as well as passing NULL to
bt_conn_unref(). The latter issue also triggered a Coverity warning.

Fixes CID 196638

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-21 10:05:47 +02:00
Johan Hedberg
4882849f18 Bluetooth: controller: Convert benign BT_WARN() messages to BT_DBG()
BT_WARN() should only be used for log messages that may indicate a
problem. However, the controller HCI code was using it for messages
that were of a pure debugging/informational nature. Convert these to
BT_DBG() instead - this should hopefully also help avoid unnecessary
user questions of seemingly alarming log messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-19 18:17:41 +02:00
Joakim Andersson
319a1239aa Bluetooth: controller: Fix PHY bits sets with PHY disabled
The 2M and Coded PHY bit should not be set when the
PHY update procedure is not supported.

Fixes #14658

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-03-19 16:34:55 +02:00
Joakim Andersson
f4c8e3ff31 Bluetooth: controller: Fix transaction collision
Peer side will disconnect if controller initiates
Encryption procedure before PHY update procedure
has finished.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-03-19 09:55:41 +01:00
Mariusz Skamra
3ab275f3e1 Bluetooth: mesh: Fix net_id net_buf_pull in secure_beacon_recv
This fixes usage of net_buf_simple_pull_mem to pull the net_id
from network buffer.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-03-19 06:54:26 +02:00
Joakim Andersson
100287d77b Bluetooth: controller: Fix bug in LL encryption.
Fix bug in LL encryption procedure, controller was
using the wrong pointer to connection state.
Function event_enc_prep is called from
slave_event_prepare, where _radio.curr_conn has not
been assigned yet.
The connection ended up sending LL_START_ENC_RSP
unencrypted, resulting in disconnect on the peer
side with reason MIC failure.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-03-15 20:56:16 +01:00
Vinayak Kariappa Chettimada
d570e139dc Bluetooth: controller: Fix tx power level set and get
Fix implementation to correctly return the configured
default Tx Power Level.

Also, fix the missing use of RADIO_TXP_DEFAULT in the new
ULL/LLL implementation of Advertiser and Observer states.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-15 11:07:32 +01:00
Vinayak Kariappa Chettimada
5d78a5f07a Bluetooth: controller: Read Tx Power Level depends on Connections
Conditionally compile HCI Read Tx Power Level command for
connections support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-03-15 11:07:32 +01:00
Vinayak Kariappa Chettimada
f4281c38f8 Bluetooth: controller: Add range delay calculations
Add implementation in controller to use range delay
alongwith the active clock accuracy jitter.

Range has been hard coded to 1000 meters, suffices
modules out in the market.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-15 11:07:00 +01:00
Vinayak Kariappa Chettimada
fd334a2aa5 Bluetooth: controller: Fix disabled Prop. PHY Update for nRF51 series
Due to regression the option to enable PHY Update Procedure
on proprietary 2M PHY for nRF51 series was disable.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-15 11:06:23 +01:00
Vinayak Kariappa Chettimada
0437fd7aff Bluetooth: controller: Workaround multi-link DLE assert
Workaround from asserting when Rx PDU buffers from pool
needing resize is acquired by another connection. By
skipping the connection events to give some headroom for
the host to process the Rx packets and eventually make the
pool available for resize.

Fixes #11841.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-15 11:05:12 +01:00
Kumar Gala
fdc59d7c2b Bluetooth: Mesh: Fix clang uninitialized var warning
There's a BT_DBG that will output the value of pub_addr before its ever
set to anything.  Remove output of pub_addr from BT_DBG().

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-14 14:31:57 -05:00
Luiz Augusto von Dentz
bcf3d8e16b Bluetooth: GATT: Add BT_GATT_DISCOVER_ATTRIBUTE type
This adds BT_GATT_DISCOVER_ATTRIBUTE which can be used to discover any
type of attribute in a given range.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-03-13 17:48:37 +02:00
Luiz Augusto von Dentz
af61102ae1 Bluetooth: GATT: Skip Characteristic Value when discovering Descriptors
Those are not considered Descriptors and shall be discovered with
use of BT_GATT_DISCOVER_CHARACTERISTIC.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-03-13 17:48:37 +02:00
Luiz Augusto von Dentz
76deb657d7 Bluetooth: GATT: Skip certain attributes when discovering descriptors
When discovering descriptor Find Information procedure is used which
does not allow any filtering by the server so it will return all
attributes in the given range including services and characteristics.

Fixes #14265

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-03-13 17:48:37 +02:00
Ulf Magnusson
53376394b7 kconfig: Remove blank lines at the beginning/end of files
Maybe this is some "just in case" thing that got copied around. There's
no need to have a blank line at the beginning or end of Kconfig files.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-13 07:29:42 -05:00
Johan Hedberg
0299db7303 Bluetooth: Mesh: Fix checking for bt_mesh_provision() error
There isn't much we can do if this fails, but at least log an error
about it.

Fixes #13855

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-13 05:35:58 -05:00
Wolfgang Puffitsch
d7fac9bf8c Bluetooth: controller: Support big-endian archs in split controller.
Use reverse order for bitfields on big-endian architectures. Treat
all PDU data as little-endian and add conversions as needed. Treat
access address as 4-byte value instead of u32_t to avoid flipping
endianness.

Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
2019-03-13 10:37:40 +01:00
Thomas Stenersen
c1a18fb514 bluetooth: host: Specify controller in BT_HCI_TX_STACK_SIZE defaults
By specifying the controller directly when selecting the default
BT_HCI_TX_STACK_SIZE, an external controller may rely on the final
default value when none of the in-tree controllers are used.

The value is increased to 1024 to accomodate the current worst-case
stack size.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2019-03-12 19:42:40 +01:00
Thomas Stenersen
caa4f7baae kconfig: bluetooth: Let BT_HCI_VS be configurable from controller
This moves the vendor-specific HCI command/event configuration
definitions out of bluetooth/common into bluetooth. This allows
the controller itself to indicate its support for vendor-specific
commands/events.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2019-03-12 19:42:40 +01:00
Patrik Flykt
4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Ulf Magnusson
b34b2c5a94 Bluetooth: kconfig: Remove redundant dependencies
subsys/bluetooth/common/Kconfig and subsys/bluetooth/host/Kconfig are
'source'd within 'if BT' and 'if BT_HCI', in subsys/bluetooth/Kconfig,
so there's no need to add those dependencies within them.

'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.

Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-09 10:03:06 -05:00
Carles Cufi
1cdf2460f4 Bluetooth: controller: Fix unchecked return value
Check the return value of mayfly_enqueue() and assert if not successful.

Coverity ID: CID 190991
Fixes #13833.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-03-05 13:08:12 +01:00
Pawel Dunaj
4858a868e6 bluetooth: host: Expand TX thread stack for BT_CENTRAL
Expand TX stack size as more RAM is needed when keys are
stored.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-03-05 11:22:39 +01:00
Maksim Masalski
eead071b18 bluetooth: fix unchecked return from lll_clk_off in ll_test_end
Inside ll_test_end(), result of lll_clk_off() is not checked
which might result in releasing resources acquired for radio.

Coverity-CID: 190954
Fixes: #13861
Signed-off-by: Maksim Masalski <maxxliferobot@gmail.com>
2019-03-05 11:21:55 +01:00
Vinayak Kariappa Chettimada
4fb64d11c8 Bluetooth: controller: Fix disabled clear text DLE for nRF51 series
Due to regression the option to enable Data Length Update
Procedure for nRF51 series was disable.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-03 23:56:16 -05:00
Vinayak Kariappa Chettimada
5f2099fb63 Bluetooth: controller: Workaround for Unknown Rsp during Enc Setup
Some old peer central controllers respond with Unknown
Response PDU to our local Slave Initiated Feature Request
after the peer initiated the Encryption Setup Procedure.

The peer has voilated the Bluetooth Specification by sending
the Unknown Response during the Encryption Setup Procedure,
but as a workaround to IOP with such controller our local
implementation is updated to not disconnect the connection
but accept the voilating Unknown Response PDU.

Relates to #12362.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-01 14:23:50 +01:00
Nick Ward
b17d9eefc5 Bluetooth: GATT: Remove ccc cfg value
CCC cfg value was not being cleared on disconnection of a non bonded
peer if another peer was connected, had non zero value and occurred
earlier in the ccc cfg array.

Signed-off-by: Nick Ward <nick.ward@setec.com.au>
2019-03-01 12:50:43 +01:00
Filip Kubicz
5415f67475 bluetooth: settings: Clean up storing Bluetooth host values
Add missing log_strdup and remove usage of goto where not needed.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2019-03-01 12:49:28 +01:00
Flavio Ceolin
23e75c1492 bluetooth: shell: Fix uninitialized variable
Variable evt_prop could be used without being initialized. This problem
was spotted by coverity.

CID 190970

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-01 09:19:31 +01:00
David B. Kinder
e731bdc81a doc: fix docs, include, and Kconfig misspellings
Fix misspellings missed during regular reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-02-28 09:32:12 +01:00
Pawel Dunaj
aab77ea10f bluetooth: Fix broken directed advertising
This code probably got broken during some merge.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-02-27 11:49:48 +02:00
Luiz Augusto von Dentz
46298da104 Bluetooth: Mesh: Use BT_GATT_CCC_MANAGED
This makes use of BT_GATT_CCC_MANAGED so instead of having a custom
attribute which is not managed by stack.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-27 10:30:50 +01:00
Luiz Augusto von Dentz
efb064ab9b Bluetooth; GATT: Consolidate code for finding a CCC config
This consolidates code for finding a CCC config in a helper function
thus reducing the amount of duplicated code.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-27 10:30:50 +01:00
Luiz Augusto von Dentz
da163794d0 Bluetooth: GATT: Add BT_GATT_CCC_MANAGED
This adds another helper macro called BT_GATT_CCC_MANAGED which can be
used to set 2 new callbacks:

 - cfg_write: Which application can set if it wants to manage writes to
 CCC configuration.
 - cfg_match: Which application can set if it wants to manage matching
 CCC configuration when notifying/indicating.

BT_GATT_CCC_MANAGED retains the ability of saving peer configuration
on storage making it useful for clients which are only interrested in
managing the CCC configuration but not the storage itself.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-27 10:30:50 +01:00
Ulf Magnusson
9aab5cef96 kconfig: Remove redundant 'default n' properties
Some more were added since the cleanup pass in June 2018. See e.g.
commit 2d50da70a1 ("drivers: ipm: Kconfig: Remove redundant 'default n'
properties") for a motivation. It also avoids people wondering whether
or not they need to put in 'default n'.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 09:25:22 +01:00
Ulf Magnusson
40436f730b kconfig: Use a short consistent prompt style
Same change as in commit 8cf8db3a73 ("Kconfig: Use a short, consistent
style for prompts"), fixing stuff that got introduced since then.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 09:23:30 +01:00
Piotr Zięcik
d30c9aeafd drivers: nrf_power_clock: Migrate to DTS.
This commit migrates the nrf_power_clock driver to DTS.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-02-25 17:51:24 +01:00
Filip Kubicz
e44011b6e3 Bluetooth: host: Use log_strdup() for stack strings
Prevent temporary strings from being printed incorrectly if they go out
of scope before being processed by logger.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2019-02-21 09:25:50 -05:00
Filip Kubicz
f1a2295088 Bluetooth: settings: Always initialize key when storing Client Features
Fixes #13572.

Initialize key used to store Client Features even when config was not
found.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2019-02-21 09:25:50 -05:00
Johan Hedberg
16311e2285 Bluetooth: settings: Fix missing log_strdup() call
The bt_settings_encode_key() cannot know if the given path pointer is
on the stack or not, so the only safe way to pass it to the logger is
by using a log_strdup() call. Not doing this will likely cause
corrupted strings to show up in the log output.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-02-21 13:25:06 +02:00
Krzysztof Chruscinski
3605e48c44 shell: Modify subcommands to use SHELL_STATIC_SUBCMD_SET_CREATE
It is planned to deprecate SHELL_CREATE_STATIC_SUBCMD_SET macro
which is replaced by SHELL_STATIC_SUBCMD_SET_CREATE.

Additionally, removed irrelevant comments about alphabetical
ordering which is no longer needed.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Mark Ruvald Pedersen
406dc2cb0e bluetooth: controller: Static mem_pdu_rx, remove PDU_RX_SIZE_MIN
mem_pdu_rx is not runtime resized meaning PDU_RX_SIZE_MIN is no longer
relevant.

Dynamic resizing was a left-over from the old bt controller.
Its size field was only ever set to PDU_RX_SIZE_MIN.
PDU_RX_SIZE_MIN only accounted for advertise PDUs.
So we remove size field from mem_pdu_rx.

However, the rest of the BT controller expects to be able to pull
RX_CNT-number of valid nodes from the pool at init/reset (rx_alloc)
time. This will fail unless we inflate the capacity by one.

To avoid inflation-by-one, mem_* would have to be rewritten to avoid
always-one-extra pattern.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-19 10:34:48 +01:00
Mark Ruvald Pedersen
e24d1efe7c bluetooth: controller: Refactor PDU_RX_POOL_SIZE
Refactor PDU_RX_POOL_SIZE into its constituents and name each term.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-19 10:34:48 +01:00
Vinayak Kariappa Chettimada
0d82116655 Bluetooth: controller: Fix bug in Encryption feature cond. compile
Fix a bug in Encryption Procedure feature conditional
compile which prevent any data transfer when the feature was
disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-19 09:27:24 +01:00
Mark Ruvald Pedersen
10d3f070e6 bluetooth: controller: Document RX path flow from mayfly to HCI
No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-18 15:13:45 -05:00
Kamil Piszczek
6bb75a53d1 Bluetooth: gatt: ccc changed cb after connection cb
Changed the order of Bluetooth callbacks. Now the connected callback is
received before CCC changed callbacks.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-02-18 15:13:25 -05:00
Johan Hedberg
1cfa12276c Bluetooth: Mesh: Increase advertising thread size
In certain configurations, such as with MPU support enabled, the
consumption of the advertising thread has gone slightly up. In some
case it was seen to overflow by some 48 bytes. Let it always be 786,
like it was so far with CONFIG_BT_HOST_CRYPTO.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-02-15 18:49:14 -05:00
Mark Ruvald Pedersen
479df56858 bluetooth: controller: Add a few ticker comments
No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-15 09:52:14 -05:00
Mark Ruvald Pedersen
d315dbd67b bluetooth: controller: Commentary in LLL header
No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-15 09:51:54 -05:00
Mark Ruvald Pedersen
e4892abe31 bluetooth: controller: Document more of memq, mfifo
* Slight tweaks to memq comments,
 * Document most of mfifo through commentary.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-15 09:49:45 -05:00
Mark Ruvald Pedersen
a61938130b bluetooth: controller: Add comments across ull
* Clarify certain functions and data structures in upper link layer.
 * Disambiguate node rx event done, add commentary.

MFIFO_DEQUEUE macro does string concatenation.
Thus MFIFO_DEQUEUE(done) does not refer to done (the stack local), but
mfifo_done.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-15 09:49:34 -05:00
Mark Ruvald Pedersen
9d8a614ed7 bluetooth: controller: Introduce ull_ref_dec for consistency
ull_ref_inc already existed, but not ull_ref_dec.
No functional change expected.
Consistency is preferred due to code navigation.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-15 09:49:21 -05:00
Carlos Stuart
75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Vinayak Kariappa Chettimada
85d92923e2 Bluetooth: controller: Rename non-Kconfig option macros
Remove CONFIG_ prefix from non-Kconfig macro definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 09:20:26 -05:00
Vinayak Kariappa Chettimada
72bef65087 Bluetooth: controller: Fix non-HCI error code return value data type
Fix the return value of non-HCI errror code data type to
int.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada
e6a256a785 Bluetooth: controller: Fix Rx buffer size variable data type
Fix the Rx buffer size variable data type to fit memory
block sizes greater than 255.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada
5aa9d2ce1e Bluetooth: controller: Remove unused commented code
Remove unused redundant commented code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada
e85c4d00b6 Bluetooth: controller: Rename ull_tx_ack_put to ll_tx_ack_put
Rename ull_tx_ack_put to ll_tx_ack_put as ack is enqueued
into LL thread context from ULL ISR context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada
5bacbf612d Bluetooth: controller: Move PKT_US from LLL to ULL header file
Move PKT_US definition from LLL header file to ULL header so
as to share it across vendors.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada
d33641f39a Bluetooth: controller: Remove underscore prefixes from functions
Cleanup and rename functions from having underscore prefixes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada
dd25e59762 Bluetooth: controller: Fix compile error in observer only support
Fix compile error due to missing conditional compile of
connection related code when selecting only observer state
support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-12 08:37:31 -05:00
Vinayak Kariappa Chettimada
7a99035515 Bluetooth: controller: 32-bit word align allocations
nRF51 series requires the 32-bit word aligned accesses to
avoid hardfaults.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-12 08:37:05 -05:00
Alexander Svensen
8d86773d6b Bluetooth: controller: refactored llcp_req/ack test to helper function
Moved test of llcp_req/ack to separate helper function in ull_conn.c

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-02-12 09:38:25 +01:00
Wolfgang Puffitsch
012d404125 bluetooth: controller: Remove trailing semicolons in HCI defines.
Remove trailing semicolons from defines.

Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
2019-02-10 16:16:58 -05:00
Kumar Gala
ff70b3444f dts: Convert CONFIG_ to DT_ symbols for chosen props
Replace generating CONFIG_ symbols with DT_ symbols for chosen
properties like 'zephyr,console' or 'zephyr,bt-mon-uart'.  We now use a
kconfigfunctions (dt_str_val) to extract the info from dts into Kconfig.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 11:41:26 -06:00
Luiz Augusto von Dentz
e919054155 Bluetooth: GATT: Add option to enforce client change-unware state
This adds BT_GATT_ENFORCE_CHANGE_UNAWARE option which when enable
returns -EAGAIN when notifying or indicating if the client is
change-unware to conform with following statement on the spec:

  'BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part G page 2350:
   Except for the Handle Value indication, the  server shall not send
   notifications and indications to such a client until it becomes
   change-aware.'

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz
aecf7c7076 Bluetooth: GATT: Store Client features
Client features shall be persisted across connections.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz
3cccf27b2d Bluetooth: GATT: Persist Client Features config only when paired
BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part G page 2405:

  'For clients with a trusted relationship, the characteristic value
  shall be persistent across connections. For clients without a
  trusted relationship the characteristic value shall be set to the
  default value at each connection.'

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz
daac1fa77a Bluetooth: GATT: Implement Robust Caching
This implement Robust Caching which is mandatory when Database Hash and
Service changed Characteristics are supported.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz
a3bca71a5e Bluetooth: GATT: Implement Database Hash
This implements the Database Hash characteristic which generates a hash
with the contents of certain attributes. The generation of hash is
usually offloaded to the systemwq using a delayed work so that when
application register multiple services only one hash needs to be
calculated.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz
ad9846b928 Bluetooth: GATT: Implement Client Supported Features
The Client Supported Features characteristic is used by the client to
inform the server which features are supported by the client.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz
408edcfcdb Bluetooth: Kconfig: Add menu for ATT and GATT options
This move Kconfig options for ATT and GATT to a dedicated menu.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Luiz Augusto von Dentz
753a6d4f20 Bluetooth: Kconfig: Add BT_GATT_CACHING
This adds BT_GATT_CACHING option which can be used to enable support
for Client Supported Features and Database Hash characteristics.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Wolfgang Puffitsch
aed74024b5 bluetooth: host: Fix endianness issue for group end_handle.
Convert end_handle to native endianness before comparison.

Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
2019-02-07 21:00:42 +02:00
Sebastian Bøe
7644d02598 Bluetooth: Increase hci_tx stack size when CONFIG_NO_OPTIMIZATIONS
When optimizations are disabled more RAM is used and we get a stack
overflow on BT_HCI_TX_STACK_SIZE. To rectify this, increase the stack
size when CONFIG_NO_OPTIMIZATIONS.

This does not scale well, and will have to be replaced by a a more
general solution eventually, but in the mean time it follows the
existing best practice established by the GCOV infrastructure in
commit e908ea9aa5

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-07 11:16:59 -06:00
Filip Kubicz
1d199181ac Bluetooth: host: Meaningful error codes on advertising start
Translate HCI error codes to POSIX error codes in order to be able to
distinguish reason of connectable advertising start failure.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2019-02-07 12:56:26 +02:00
Filip Kubicz
5e4f6e9c73 Bluetooth: ctlr: Return different error codes on advertising start
Return meaninful HCI error when it's not possible to start advertising
because of maximum number of connections already in use.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2019-02-07 12:56:26 +02:00
Vinayak Kariappa Chettimada
c086c9e8fe Bluetooth: controller: Fix dereferencing type punned pointer
Fix compiler warning about dereferencing type-punned pointer
that will break strict-aliasing rules.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-05 15:00:08 +01:00
Vinayak Kariappa Chettimada
4c77bf6194 Bluetooth: controller: Remove redundant tmp role implementation
Remove the redundant proof of concept template temporary
role implementation from the repository.

Relates to #12860.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-05 15:00:08 +01:00
Vinayak Kariappa Chettimada
ff88b7f255 Bluetooth: controller: ULL/LLL: Fix compile error with PA/LNA
During regression testing of PA/LNA feature it was noticed
that compilation failed due to missing port of the code
conditionally compiled for PA/LNA feature.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-02 10:35:40 -05:00
Andrzej Głąbek
1dbcd0affa samples: bluetooth: hci_spi: Use DT instead of Kconfig to get HW params
Convert the hci_spi sample to get the SPI and GPIO settings from Device
Tree instead of Kconfig.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-02-01 19:12:57 -05:00
Johan Hedberg
1c171ec283 Bluetooth: Add identifiers for Bluetooth 5.1
The Bluetooth 5.1 specification was recently released, and has a new
version identifier (10) assigned to it in the Bluetooth Assigned
Numbers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-29 16:00:57 +02:00
Johan Hedberg
fe7f1e17de Bluetooth: Take advantage of net_buf_pull_mem()
Convert the remaining places of the host stack where
net_buf_pull_mem() makes more sense than net_buf_pull().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg
c10b9ac228 Bluetooth: Redesign HCI event handling
Take advantage of the new net_buf_pull_mem() API, and refactor the
events from long switch statements into (const) handler tables. This
helps reduce code size and makes it cheap to add proper checks/asserts
for having sufficient data in the buffers coming from the controller.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg
e399399a99 Bluetooth: Mesh: Take advantage of net_buf_simple_pull_mem()
Use net_buf_simple_pull_mem() instead of net_buf_simple_pull() where
it makes sense.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg
006946b8f4 Bluetooth: controller: Use net_buf_pull_mem() for command parsing
It's more natural to use net_buf_pull_mem() for the HCI command
parsing. Note that this also fixes a bug in hci_cmd_handle() where it
would previously check for sufficient parameter length with the
command header still included in the buffer (which it shouldn't have
been).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg
9abce3ec58 Bluetooth: Mesh: Fix publish timer handling when sending fails
Sending a model publication message could fail e.g. if there are no
buffers available, however this doesn't mean that we should stop doing
periodic publishing indefinitely. When an error occurs, make sure to
call the publish_sent() function so that the periodic publishing timer
gets resubmitted if necessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg
e5b8f60bb6 Bluetooth: Mesh: Add support for suspend/resume
In some cases the Friendship & Low Power Node features aren't
available or feasible, however power saving is nevertheless required.
This patch introduces two new APIs to suspend and resume the Mesh
network. Currently, what this impacts is the LE scanning, the
ability to allocate new outgoing buffers, as well as the model
publishing, beacon and heartbeat timers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg
3e11177a06 Bluetooth: Mesh: Clean up net validity & provisioning state handling
Tracking of the BT_MESH_VALID flag and the PB-GATT state was rather
fragile. Add proper error returns to the various GATT service enable &
disable handlers, and toggle the BT_MESH_VALID flag in a single file
(main.c). Use the newly added error returns to ensure that we don't
re-enable PB-GATT if it wasn't already enabled from before.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg
fbe661fd3b Bluetooth: Mesh: Convert bit-fields into flags
There's already a flags member in the bt_mesh context, so take
advantage of that for any boolean members that have so far been
bit-fields. This should produce more efficient code, also for the
sequence number that's now its own u32_t.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg
f18e978837 Bluetooth: Take advantage of atomic_set_bit_to() API
Use the atomic_set_bit_to() API to simplify code where possible.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-25 17:35:44 -05:00
Johann Fischer
5c23843e65 bluetooth: smp: fix build if BT_SMP_SELFTEST is enabled
Build fails in smp.c:3942 if BT_SMP_SELFTEST is enabled,
sign_test uses smp_sign_buf which only available for BT_SIGNING.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-01-25 13:47:24 +02:00
Vinayak Kariappa Chettimada
5478e82993 Bluetooth: shell: Updates related to new ULL LLL architecture
Updates related to new ULL LLL controller architecture.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada
749652080c Bluetooth: controller: Fix control procedure context safety
Fix the control procedure context safety by adding checks in
thread mode control path to detect pre-emption by interrupt.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada
1475402d41 Bluetooth: controller: Introduce ULL LLL architecture
This is a squash merge of commits introducing the new split
Upper Link Layer and Lower Link Layer architecture of the
Bluetooth Low Energy controller.

This introduces a new, improved Link Layer based on the
concept of split responsibilities; The Upper Link Layer
(ULL) is in charge of control procedures, inter-event
scheduling and overall role management. The code for the
ULL is shared among all hardware implementations. The
Lower Link Layer (LLL) is responsible for the intra-event
scheduling and vendor specific radio hardware access.

The communication between ULL and LLL is achieved through
a set of FIFOs that contain both control and data packets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada
254a97af93 Bluetooth: controller: Preliminary work in progress mesh ext.
Preliminary work done towards Mesh extensions on the old LL
architecture implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada
44d046ff8d Bluetooth: controller: Updates to prep to introduce new arch
Missing updates to old architecture implementation towards
introduction of new ULL LLL architecture.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada
0989c0f8c2 Bluetooth: controller: Refactor the internal LL interfaces
Refactored the internal LL interfaces to have return value
to match the HCI error code u8_t data type.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Luiz Augusto von Dentz
478b6b5381 Bluetooth: Shell: Add write-without-response-cb command
This adds write-without-response-cb command which can be used to
confirm the transmission of the PDU using bt_gatt_write_without_rsp_cb.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-01-16 21:43:53 -05:00
Luiz Augusto von Dentz
a779705f16 Bluetooth: GATT: Add bt_gatt_write_response_cb
This adds bt_gatt_write_response_cb works similarly to
bt_gatt_notify_cb which can take a callback to be called when the PDU
is considered transmitted over the air.

Note: This can also be used to disable the ATT flow control which would
blocks sending multiple commands without wainting their transmissions.

Fixes #11558

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-01-16 21:43:53 -05:00
Ioannis Glaropoulos
2e687653fa drivers: clock control: rename nrf5_power_clock source and header
This commit renames the nrf5_clock_control.h and
nrf5_clock_control.c files to nrf_clock_control.h and
nrf_clock_control.c, respectively, as they are used
in nRF9160 builds, as well.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-01-15 18:03:24 +01:00
Ioannis Glaropoulos
302a746bd6 drivers: clock control: nrf: rename CLOCK_CONTROL_NRF5 Kconfig symbol
This commit renames the CLOCK_CONTROL_NRF5 Kconfig symbol to
CLOCK_CONTROL_NRF. The change is required to aleviates confusion
when selecting the symbol in nRF9160 SOC definition.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-01-15 18:03:24 +01:00
Johan Hedberg
a7a0d27ae2 Bluetooth: Give proper names to Bluetooth threads
Provide names for all Bluetooth threads so that they don't show up as
"NA" when issuing the "kernel stacks" command in the shell.

To get this info the following Kconfig options need to be enabled:

CONFIG_THREAD_STACK_INFO=y
CONFIG_THREAD_MONITOR=y
CONFIG_KERNEL_SHELL=y
CONFIG_INIT_STACKS=y
CONFIG_THREAD_NAME=y

After issuing the "kernel stacks" command the output should look
something like this:

uart:~$ kernel stacks
0x200011D0 BT RX      (real size 1024): unused 760      usage 264 / 1024 (25 %)
0x20001148 BT RX pri  (real size 448):  unused 280      usage 168 / 448 (37 %)
0x20000654 BT ECC     (real size 1100): unused 168      usage 932 / 1100 (84 %)
0x20000764 BT TX      (real size 640):  unused 280      usage 360 / 640 (56 %)
0x20001ED8 sysworkq   (real size 1024): unused 592      usage 432 / 1024 (42 %)
0x200004C4 shell_uart (real size 2048): unused 904      usage 1144 / 2048 (55 %)
0x20000058 logging    (real size 768):  unused 584      usage 184 / 768 (23 %)
0x20001D84 idle       (real size 256):  unused 184      usage 72 / 256 (28 %)
0x20001E08 main       (real size 1024): unused 768      usage 256 / 1024 (25 %)

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-15 17:39:54 +01:00
Johan Hedberg
eba16555ce Bluetooth: Increase default TX stack size
The current stack consumption with the H4 driver on qemu_x86 is as
follows with a change from 256 to 512:

	usage 396 / 512 (77 %)

Increase the default for this configuration, as well as other similar
configurations. Set the fallback default to a higher value as well.

Fixes #12429

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-15 10:31:55 +02:00
Johan Hedberg
61ff1bda2f Bluetooth: Mesh: Remove redundant stack variable
The msg->prev_addr is already stored in frnd->clear.frnd, so there's
no need to have an extra stack variable for this (in the form of
prev_addr).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-14 11:38:51 +02:00
Wolfgang Puffitsch
3159049c39 bluetooth: controller: Update ticker_user_op for predictable layout.
Use fixed-width type instead of enum for field op in struct
ticker_user_op to avoid struct layout differences between
compilers. Also make check whether struct sizes match size definitions
build-time asserts.

Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
2019-01-14 10:12:15 +01:00
Jiahao Li
5b9d5a217c Bluetooth: Fixes length limit in bt_hex_real
Since `str` is the output buffer, `bt_hex_real` should limit its output
length according to the `str` size, not the `hex` size.

Signed-off-by: Jiahao Li <reg@ljh.me>
2019-01-13 23:19:30 +02:00
Jiahao Li
6a5623566e Bluetooth: Mesh: Fixes existing friend lookup in Friend Request handling
Currently, when handling a Friend Request message with `prev_addr` set,
we look up existing friend entry using `prev_addr` as the address.
However, `prev_addr` is the address of the requesting node's previous
friend, NOT the address of the requesting node itself. Therefore, we
should always look up existing friend entry using `rx->ctx.addr` as the
address.

Signed-off-by: Jiahao Li <reg@ljh.me>
2019-01-12 22:07:41 +02:00
Johan Hedberg
a886229c2b Bluetooth: shell: Fix incorrect indentation
This line was indented using four spaces instead of a tab.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-11 15:27:38 +02:00
Mark Ruvald Pedersen
076fd6a32a bluetooth: controller: Document mem, memq, util
Adds documentation-commentary to some infrastructure used by the LL.
It is a long-term effort to better document the LL.

Notably ticker and mayfly require more documentation; this will be
done later.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-01-10 18:00:41 +01:00
Wenjie Xu
ce43d428c0 Bluetooth: shell: Fix NULL shell context
On bt_ready, ctx_shell would be NULL if not initialized before
bt_enable.

Signed-off-by: Wenjie Xu <xuwenjie@huantengsmart.com>
2019-01-10 11:56:07 +01:00
Vinayak Kariappa Chettimada
dfe415a912 Bluetooth: shell: Changes related to controller split preparation
Changes to Bluetooth shell application related to the
controller split architecture preparation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-07 13:42:01 +01:00
Vinayak Kariappa Chettimada
87fe440f01 Bluetooth: controller: Prepare to introduce LL split architecture
Preparation to introduce the Upper Link Layer (ULL) and
Lower Link Layer (LLL) split architecture.

- Move SoC dependent HAL to vendor specific folder.
- Preparation to split data structures into ULL and LLL
  types.
- Added more role and state conditional compilations.
- Added some work-in-progress implementation of advertising
  extensions, will be used as inspiration in the new split
  architecture work.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-07 13:42:01 +01:00
Johan Hedberg
d57a9a648b Bluetooth: Mesh: Fix heartbeat publication storing
This fixes usage of an uninitialized variable (to_store) as introduced
by commit bfad2a0.

Fixes #12314

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-07 12:49:36 +02:00
Johan Hedberg
3d0950e59a Bluetooth: Mesh: Fix typo leading to incorrect settings storage
This was intended to be an equality comparison and not an assignment.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-07 12:49:36 +02:00
Luiz Augusto von Dentz
80bc21e03c Bluetooth: GATT: Fix warning when attempting to use read callback
When using bt_gatt_discover with BT_GATT_DISCOVER_CHARACTERISTIC the
read callback would be set to bt_gatt_attr_read_chrc which would attempt
to access the next attribute which in this case would not be set since
the value attribute is no fetched by the discovery, the spec actually
omit the value handle saying it should always be the first attribute to
appear after the characteristic thus we can assume it to be handle + 1.

Fixes #12159

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-01-03 12:12:10 +01:00
Vinayak Kariappa Chettimada
99ae80b632 Bluetooth: controller: Fix Conn Param Req procedure stall issue
Fix an issue wherein local or remote initiated Connection
Parameter Request procedure would stall without generation
of LE Connection Update Complete HCI event because a local
or remote initiated PHY Update procedure has overwritten the
currently active Link Layer Control Procedure type.

Signed-off-by: Vinayak Kariappa Chettimada <vinayak.kariappa@gmail.com>
2018-12-19 14:47:38 +01:00
Jakub Rzeszutko
f0b19181e0 bt_shell: fix command bt advertise valid argument count
Changed number of valid arguments from two required to
one required and one optional.

Command can be called with required <type: off, on, scan, nconn>
and optional <mode: discov, non_discov>".

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-18 18:52:00 +02:00
Krzysztof Chruscinski
dc2ab4d74f bluetooth: Simplifying log macros
Function name prefix is now configurable (by default only debug
messages are prefixed) and log macros can be simplified.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-13 14:21:25 +01:00
Alberto Escolar Piedras
fc0f80391c Bluetooth: nordic ECB hal: Bugfix for simulation
Fix in the do_ecb() function
In real HW this function busy waits for the ECB to be done.
In simulation with the POSIX arch a WFE was added to avoid that
infinite loop.
But this function is called with the ECB interrupts disabled.
In normal builds other interrupts will awake the CPU very soon
after entering into that WFE, and the problem was not discovered.

But, in controller only builds, during some conformance tests,
the loop will hang as no other interrupts are coming.

=> Replace the WFE() with a k_busy_wait (only for simulation)

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-12-12 12:12:04 +01:00
Vinayak Kariappa Chettimada
afbbb97ab1 Bluetooth: controller: Fix chan map update's diff trans collision
Fix channel map update procedure implementation's handling
of different transaction collision by not asserting but
disconnecting the connection due to invalid behavior by
peer implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-12-12 12:05:05 +01:00
Johan Hedberg
fc29dd8c8f Bluetooth: Mesh: Fix confusing language in log messages
Both "store" and "clear" are verbs, so putting them after each other
is just confusing. Use "clean" consistently when clearing settings
entries.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-12-11 16:58:36 +02:00
Johan Hedberg
ed3c2cd38a Bluetooth: Mesh: Fix missing log_strdup() for logging
Several non-persistent strings were being logged without log_strdup().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-12-11 16:58:36 +02:00
Andrzej Puzdrowski
bfad2a0cbf bluetooth: host: mesh: align code to reworked settings
The code need to be align after introduction of stream codec to
setting serialization subsystem.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski
bfb60743d5 bluetooth: host: align code to reworked settings
The Code need to be align after introduction of stream codec to
setting serialization subsystem.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski
c2e7847daa bluetooth: common: Add BT hexdump
Added BT alisa for dumping binary data to the logg.
The macro will be useful for BT as reworked settings supports r/w of
raw data - which will be widely leveraged in bluetooth storage alignment
to reworked settings.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Vinayak Kariappa Chettimada
5e7c916e77 Bluetooth: controller: Fix CPR procedure regression
This fixes regression introduced in commit a11868fea9.

Fixes the following conformance tests:
LL/CON/MAS/BV-32-C [Accepting Connection Parameter Request -
Preferred Periodicity]
LL/CON/MAS/BV-33-C [Accepting Connection Parameter Request -
Preferred Periodicity and preferred anchor points]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-12-10 11:13:48 +01:00
Jakub Rzeszutko
b928b71756 shell: rename shell_help_print function
Function printing help has been renamed to shell_help.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko
3064ca4f2f shell: creating new module for help functionality
1. Created new shell module: shell_help.
2. Simplified command handlers with new shell print macros.
3. Removed help functions from command handlers.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko
5451ff2848 shell: remove "options" concept
Removing help "options" from shell API.

Currently SHELL_OPT macro is not used by users. What is more
commit: a89690d10f ignores possible options created in
command handler by the user. As a result they are not printed
in help message.

Second, currntly implemented "options" in command handlers options are
implemented without SHELL_OPT macro.

And last but not least this change will allow to implement
help handler in a way that user will not need to think about calling
functions printing help in a command handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Patrik Flykt
b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Vinayak Kariappa Chettimada
a2f2d23c9f Bluetooth: controller: Fix conn update assert in slave role
Explicitly track the connection update related ticker stop
and start to avoid asserting due to ticker update being done
at the same time for compensating the clock drift.

The compensation related ticker update failure in this case
can be safely ignored as new anchor point is used anyway
at the instant of the connection update.

Fixes #8796

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-12-03 10:38:57 +01:00
Johan Hedberg
bec74121f6 Bluetooth: Mesh: Fix matching for all elements of an LPN
When we're acting as a Friend for an LPN, we need to consider all
elements of the LPN. The information of how many elements the LPN has
is provided in the Friend Request message, however until now the code
did not do anything with this information.

Fix the issue by tracking the number of elements for each LPN and
update the unicast address matching code to take this into account.

Fixes #11731

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-11-29 17:55:23 +02:00
Olivier Martin
58245cd02f Bluetooth: Define log level at bluetooth subsystem level
This commit defines a default log level at bluetooth subsystem
level when module log level is not defined.

Prior to this change, the bluetooth subsystem would use
the firmware default log level.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-28 13:52:35 -06:00
Kim Sekkelund
bf11698ed9 bluetooth: host: Rename bt_conn_get_id and make it public.
There is not an easy way to relate an application's user_data to a
connection. One way is to save a pointer to bt_conn in the
application's user_data array upon connection establishment.
Each connection related callback function will have to loop for all
user_data and compare the saved pointer to the passed bt_conn
pointer. This is inefficient if there are many callback activations
during the connection.

This change makes the internal bt_conn mapping function accessible to
applications in conn.h. The function name is changed to
bt_conn_index() to clearly indicate that the function returns an
index of an array.
Add an ASSERT to catch illegal parameter.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2018-11-28 18:20:38 +02:00
Olivier Martin
ff66b4b09a Bluetooth: host: Remove peer from CCC cfg
When removing a peer from a CCC, it also needs to be removed from
the attribute `cfg`.

Not removing it would create a shortage of `cfg` that could
prevent new host to pair to the BLE device.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-27 13:58:21 +02:00
Olivier Martin
6c3aefa0b6 Bluetooth: host: Clear CCC when clearing all keys
CCC settings was not removed when unpairing all keys.
It means CCC settings were still present in flash and were
loading at bluetooth initialization time.

Loading these orphan CCC settings would fill `bt_gatt_ccc_cfg`
configurations and would prevent to add new CCC when pairing
with a new device.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-26 18:34:41 +02:00
Luiz Augusto von Dentz
6798a421e1 Bluetooth: GATT: Ensure GATT service is registered first
Accourding to Bluetooth specification the Service Changed
Characteristic shall not have its handle changed once it has been
bonded, so this moves the GATT service to be the very first service
registered that way it is guaranteed that it won't change even if
device is flashed with a different configuration which end up changing
the handles after it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-22 17:27:48 +02:00
Mariusz Skamra
474b2b3e94 Bluetooth: Don't mask ECDH related events if CONFIG_BT_ECC disabled
It is related to b904ad387f.
This fixes checking ECDH related events in event mask.
If ECDH support is disabled in host, there is no need to check
if those are supported in the controller.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-22 12:54:57 +02:00
Luiz Augusto von Dentz
a618ea2a5a Bluetooth: GATT: Fix not handling duplicated CCC storage
Some backends may actually contain the same key multiple times so the
code needs to check if there is already a ccc_cfg for an address before
attempting to use one that is unallocated.

Fixes #11409

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-21 19:48:16 +02:00
Luiz Augusto von Dentz
046e1ab94a Bluetooth: GATT: Fix not resetting CCC storage
If there are no CCC to be stored the value should be set to NULL so it
is properly cleared otherwise calling settings_str_from_bytes will leave
str uninitialized which may cause a crash when attempting to load the
value.

Fixes #11564

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-21 19:32:16 +02:00
Mariusz Skamra
b904ad387f Bluetooth: Add Kconfig option to disable HCI ECDH support
This adds Kconfig option to disable HCI ECDH support.
It will compile out ECDH related code, especially HCI event handlers.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Mariusz Skamra
8f5ba0be88 Bluetooth: Add common Kconfig option to disable LE Data Length Update
This adds common option to disable support for LE Data Length Update
procedure in controller and host.
This will reduce flash usage by compiling out le_data_len_change
event handler that will never be called if controller has been
compiled with BT_CTLR_DATA_LENGTH option disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Mariusz Skamra
be314d3af5 Bluetooth: Add common Kconfig option to disable PHY Update
This adds common option to disable support for PHY Update
procedure in controller and host.
This will reduce flash usage by compiling out le_phy_update_complete
event handler that will never be called if controller has been
compiled with BT_CTLR_PHY option disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Olivier Martin
1d9fb2b2b3 Bluetooth: host: Increase ECC thread stack
Logging subsystem could take few extra bytes when enabled.
ECC thread stack has been unconditionally increased to
support it.

During my test, I noticed a usage of 1052 bytes when logging
subsystem is enabled.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-21 14:39:36 +02:00
Luiz Augusto von Dentz
57a6858278 Bluetooth: ATT: Rename op parameter of att_write_rsp
This makes it clear that only request need to set an opcode since they
require a error response in case it fails.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 13:14:58 +02:00
Luiz Augusto von Dentz
8f812f30a1 Bluetooth: GATT: Fix comment related to write attribute
The comment was suggesting that write callback was reading and storing
buffer when in fact it should write to the attribute value.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 13:14:58 +02:00
Luiz Augusto von Dentz
ae05089946 Bluetooth: GATT: Add flag to indicate write command
Application may need to handle the write differently depending on the
write operation so this adds a flag called BT_GATT_WRITE_FLAG_CMD which
can then be checked by the callback, for instance one can respond with
BT_ATT_ERR_WRITE_REQ_REJECTED when that flag is not set which should
indicate to the client to use write command instead.

Fixes #11206

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 13:14:58 +02:00
Vinayak Kariappa Chettimada
aa5bbd5dfe Bluetooth: controller: Fix enable and disable of scan state
Updated controller implementation to disallow disabling
initiator state using scan disable. But allow disabling an
already disabled scan state. Also, disallow enabling scan
state while in initiator state.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-20 11:19:07 +01:00
Luiz Augusto von Dentz
3fdedde967 Bluetooth: ATT: Assert if request is invalid
Consider invalid if the request pointer is NULL or the callback is NULL
or there is a request ongoing. This conditions would likely lead to a
crash and most likely there is some other bug involved like for example
the application queueing the same request multiple times.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 11:15:33 +01:00
Vinayak Kariappa Chettimada
c326ae729f Bluetooth: controller: Do not feature exchange more than once
Updated the controller implementation to not feature
exchange if already done once either by local or remote peer
device in an active connection session.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-20 11:14:58 +01:00
Szymon Janc
e693997c29 Bluetooth: host: Fix not starting slave conn param update timer
When issuing LE Set Data Length Command host should not assume that
LE Data Length Change Event will be generated. From Core Spec 5.0:
"If the command causes the maximum transmission packet size or maximum
packet transmission time to change, an LE Data Length Change Event
shall be generated."

Change-Id: I17723b58ed4f390aa465db3f69126ee229871123
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-19 13:40:13 +02:00
Szymon Janc
bf71fa1aeb Bluetooth: host: Don't send slave conn param request if not needed
If master or application decided to switch connection parameters to
ones that meet pending parameters don't bother sending request
after 5 seconds timeout.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-19 13:22:43 +02:00
Johan Hedberg
296dab3fe2 Bluetooth: Mesh: Increase scan window from 10ms to 30ms
Experiments have shown that the probability of missing advertising
packets is significantly lower with 30ms scan window compared to 10ms
scan window. This is especially the case with advertisers using a 20ms
advertising interval, which in turn is perhaps the most common one
since it's the smallest allowed by the Bluetooth 5.0 specification.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-11-16 09:36:20 +02:00
Luiz Augusto von Dentz
67e4710598 Bluetooth: shell: Make use of SHELL_CMD_ARG
Use SHELL_CMD_ARG to register commands.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-13 20:42:01 +02:00
Luiz Augusto von Dentz
b7c6ea4971 Bluetooth: shell: Remove macros to print messages
Make use of shell_print and shell_error now that they are available.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-13 20:42:01 +02:00
Luiz Augusto von Dentz
4add794570 Bluetooth: shell: Remove auto selecting of SERIAL
This is no longer needed and the shell itself will take care of
selecting SERIAL.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-13 20:42:01 +02:00
Filip Kubicz
7c290b053d Bluetooth: settings: store CCC on write
By default, CCC value is only stored to persistent memory during
BT disconnection. This commit adds an optional storing of CCC right
after it has been updated. This results in better robustness of
peripheral but increases system workqueue stack usage.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2018-11-13 16:36:49 +02:00
Andrzej Głąbek
4750cf3b7b bluetooth: controller: nrf5: Reorder used PPI channels
The channels assigned to the controller are reordered so that the ones
previously used and now available for other purposes have continuous
numbers. When the controller can take advantage of the pre-programmed
PPI channels (when TIMER0 is used as the event timer), the now free
channels are 0-4, when it cannot, it is the channel 0.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-10 12:39:40 -05:00
Andrzej Głąbek
589b65e72d bluetooth: controller: nrf5: Use pre-programmed PPI channels
Several PPI channels in nRF5 family SoCs are pre-programmed with fixed
settings. A few of them can be used in the bluetooth controller instead
of the freely programmable ones that are used currently. This commit
makes such replacements where possible so that the universal channels
can be left available for other purposes.

This commit also removes macros used previously in calls to functions
enabling and disabling particular PPI channels (as it is sufficient
to use the BIT macro to set bits corresponding to the channel numbers)
to prevent such problems like the one introduces by commit
9d1ca9c390 (channel 18 changed to 17
but the related macro definition not updated).

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-10 12:39:40 -05:00
Krzysztof Chruscinski
97345dbb1b logging: Fix errors in log usage
Couple of findings which were revealed after changing
LOG_MODULE_REGISTER macro:
- missing semicolons after LOG_MODULE_REGISTER()
- missing LOG_LEVEL defines
- other

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Kumar Gala
701a574c03 Bluetooth: host: Fix trivial comment mismatch
The endif comment block is for CONFIG_BT_FIXED_PASSKEY not
CONFIG_SMP_FIXED_PASSKEY.  Fix the comment to match.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-09 16:20:19 +02:00
Luiz Augusto von Dentz
75979397b2 Bluetooth: shell: Fix illegal access
BT_LE_ADV_CONN_DIR_LOW_DUTY declares a local variable so it cannot go
out of scope, so instead of assigning in the scope of the if statement
this rework the code to mantain the declaration in the same scope it is
used.

Fixes #10570

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-09 16:18:44 +02:00
Luiz Augusto von Dentz
7aa58ff91d mesh: Port shell module to the new shell
This makes mesh shell to register commands with the new shell subsystem
and stop using the legacy shell.

Fixes #11056

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-09 11:19:49 +01:00
Szymon Janc
602e08c69a Bluetooth: host: Don't restart scan if connection is pending
With multiple devices on auto-connect list it is possible that while
having pending connection to device A, device B disconnects. In that
case host should not try to start scan (currently controller doesn't
support concurrent scanning and initiating).

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-08 14:21:21 +02:00
Emanuele Di Santo
7e8b44f774 subsys: bluetooth: services: dev. information service enhancements
This commit moves the BLE GATT Device Information 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: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2018-11-07 18:08:05 +01:00
Szymon Janc
16fe6c5473 Bluetooth: host: Add comment clarifying L2CAP fallback for CPUP
Makes it easier to understand reason for else branch.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-07 13:01:01 +02:00
Vinayak Kariappa Chettimada
f403bfa343 Bluetooth: controller: Add min & max interval support in CPR
Add support for exchanging both minimum and maximum
connection interval values in Connection Parameter Request
Procedure implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-06 20:56:13 -05:00
Szymon Janc
b6979010c6 Bluetooth: host: Fallback to L2CAP for CPUP if rejected by master on LL
Fallback to L2CAP Connection Parameters Update Request if LL Connection
Update Request was rejected by remote device that has this marked as
supported in features. This can happen if procedure is supported only
by remote controller, but not enabled by host. This is connection
parameters update with iOS devices.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-06 16:30:15 -05:00
Johan Hedberg
97141734f1 Bluetooth: shell/gatt: Fix unreachable code
The code had somehow gotten corrupt (yet in a way that it compiles) so
that an intended if-branch was missing.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-11-06 22:29:51 +02:00
Mariusz Skamra
50768a6bba Bluetooth: Do not compile GATT response handlers if Client is disabled
This will exclude GATT Client response handlers from compilation
if GATT Client support is disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-06 09:33:19 +02:00
Sebastian Bøe
637c41a382 Bluetooth: controller: Refactor the k32src_wait() function
This is a pure refactoring of the k32src_wait function. It used the
following rules when refactoring:

Don't use the preprocessor when unprocessed C language suffices.

Don't undefine macro's.

Avoid global variables when possible.

Use consistent names for similiar things (hf_clock, lf_clock).

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-11-05 21:46:00 +01:00
Flavio Ceolin
aecd4ecb8d kernel: Change k_poll_signal api
k_poll_signal was being used by both, struct and function. Besides
this being extremely error prone it is also a MISRA-C violation.
Changing the function to contain a verb, since it performs an action
and the struct will be a noun. This pattern must be formalized and
followed and across the project.

MISRA-C rules 5.7 and 5.9

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-04 11:37:24 -05:00
David B. Kinder
ee47f7fb7a doc: fix kconfig misspellings
Fix misspellings in Kconfig files that show up in the configuration
documentation (and make menuconfig screens).

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-11-02 17:58:16 -04:00
Vinayak Kariappa Chettimada
133d3870b3 Bluetooth: controller: Fix integer overflow in scheduling code
Fix an integer overflow in the scheduling implementation
that calculates whether resources required for next radio
event be retained.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-02 12:26:32 -04:00
Piotr Zięcik
708468bdce Bluetooth: controller: Optimize RNG access
This commit optimizes access to RNG driver by taking advantage
of the data structures layout. As result, number of calls to RNG
driver is reduced.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-10-30 11:16:34 +01:00
Piotr Zięcik
615efcce69 drivers: entropy: nrf5: Remove entropy_nrf_get_entropy_isr() function
The entropy_nrf_get_entropy_isr(), which is specific to this driver,
is in fact equivalent of generic entropy_get_entropy_isr(..., 0).

This commit removes the entropy_nrf_get_entropy_isr() function
and replaces its usage by call to generic entropy API.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-10-30 11:16:34 +01:00
Joakim Andersson
2487d55403 Bluetooth: host: Fix identation of struct members
Fix identation of struct members so that all are aligned.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-29 14:10:26 +02:00
Joakim Andersson
c2d62a29f0 Bluetooth: host: Require 128-bit encryption key for security level 4.
In Bluetooth 5 the definition of LE security mode 1, has changed.
LE Security Mode 1 level 4 requires authenticated LE Secure Connections
pairing with encryption using a 128-bit strength encryption key.
This also changes the behaviour when a security request and response
would end up with a security level that is lower than the one requested.
Before pairing would complete, and the link would disconnect with error
authentication failure. Instead a SMP will abort pairing with error code
authentication requirement, or encryption key size.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-29 14:10:26 +02:00
Mariusz Skamra
45411bc08d Bluetooth: Update advertising data without advertising restart
This adds new API fuction to update running advertising data.
It will remove the need of advertising restarting.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-29 12:30:34 +02:00
Mariusz Skamra
74318e61ca Bluetooth: Change l2cap accept callback return error
This changes EKEYREJECTED to EPERM due to newlib dependencies
errors.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-26 16:56:01 +01:00
Sebastian Bøe
5e23278bab Bluetooth: Controller: Use a different flag for speed optimization
The bluetooth controller has been using the flag '-Ofast' to keep
within a real-time limit. There are two problems with this; firstly,
when a project should be optimized for size it is standard to use -O2,
not -Ofast.

Secondly, optimization flags have been deemed to be non-portable, so
instead of directly using "-Ofast" we should use the intent-macro
OPTIMIZE_FOR_SPEED_FLAG to ensure toolchain portability.

Testing has shown that we are still within the real-time limit when
changing from -Ofast to -O2. -Ofast is about 1us and 1% faster, but
increases the code size by 13kB (5% of the available flash on a
nRF51).

Since the slowdown is comparatively small compared to the code size
increase we have decided to use -O2 in place of -Ofast.

Other optimization combinations were also measured and their results
can be seen below:

-Ofast in BLE Controller and in #pragma in entropy driver.

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      138920 B       256 KB     52.99%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 75, 45, 132.

-O2 in BLE Controller and in #pragma in entropy driver.

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      125840 B       256 KB     48.00%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 75, 51, 133

-O3 in BLE Controller and in #pragma in entropy driver.

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      138920 B       256 KB     52.99%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 75, 50, 132.

No extra CFLAGS for BLE and entropy driver (pragmas removed), using
CONFIG_SIZE_OPTIMIZATIONS=y

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      120124 B       256 KB     45.82%

        [bt] [ERR] isr_rx_conn: assert: '!radio_is_ready()' failed

No extra CFLAGS for BLE and entropy driver (pragmas removed), using
CONFIG_SPEED_OPTIMIZATIONS=y

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      138004 B       256 KB     52.64%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 61, 51, 130.

NB: RAM usage differences were insignificant.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-26 15:55:49 +01:00
Szymon Janc
2abd05e9fc Bluetooth: controller: Compile conn complete due to cancel conditionally
BT_HCI_ERR_UNKNOWN_CONN_ID can only be sent when master role is enabled.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-25 17:03:59 +01:00
Szymon Janc
b732a9a69b Bluetooth: host: Compile master role conn complete conditionally
Connection complete event with error code can be received only for
central role and can be compiled conditionally.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-25 17:03:59 +01:00
Mariusz Skamra
c04b70469b Bluetooth: shell: Add possibility to reject L2CAP CoC conn request
This adds a possibility to reject incomming LE Connection request
due to insufficient authorization or encryption key size.
This is needed for qualification purposes

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-25 08:02:54 +01:00
Mariusz Skamra
e82ebb2c84 Bluetooth: L2CAP: Extend available return codes from accept cb
This adds support for returning various return codes from
the channel accept callback.
This is needed for implementation of incoming connection
authorization for certification purposes.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-25 08:02:54 +01:00
Mariusz Skamra
2c6065c2d1 Bluetooth: L2CAP: Rename LE Connection Response Results
Rename connection response results to map those that are defined
for BR.
BR: BT_L2CAP_BR_*
LE: BT_L2CAP_LE_*

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-25 08:02:54 +01:00
Satya Bhattacharya
6063707662 bluetooth: shell: Uninitialized scalar variables
Initialize variables chan_map in bt.c
Pass NULL and 0 directly to bt_le_adv_start()
Coverity-CID: 188735
Coverity-CID: 188729

Fixes #10588 #10594

Signed-off-by: Satya Bhattacharya <satyacube@gmail.com>
2018-10-21 15:09:54 +03:00
Johan Hedberg
9f18ff9baf Bluetooth: Convert monitor protocol to a logger backend
Convert the monitor protocol to a proper logger backend. This also
means that our log.h headerfile gets greatly simplified.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg
cd4cf4e580 Bluetooth: Convert string helpers to use log_strdup
This reduces the multiple buffer requirement to a single buffer.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg
251d99132d Bluetooth: Remove custom stack macros
Now that log processing happens in a separate thread, the
BT_STACK_EXTRA macro is not needed (since there's no significant
overhead), and therefore the BT_STACK macros become unnecessary as
well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg
343c53e841 Bluetooth: Switch from SYS_LOG to logger-based logging
Initial conversion to use syslog instead of logger.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg
5bd6bc4bed Bluetooth: log: Make address helpers more robust
Use irq_lock (same way as bt_hex does it) and increase the number of
static buffers to reduce the risk of reuse before a buffer gets
processed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg
6a68b29f41 Bluetooth: Only build bt_hex() if BT_DEBUG is enabled
bt_hex() should be included in the same block as the address helpers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Jakub Rzeszutko
147122e77f shell: examples unification
Updating examples according to new return value of function
shell_cmd_precheck.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-19 13:35:56 +02:00
Anas Nashif
3aa2a1c6db flash: make flash shell generic
This shell command was tied to bluetooth and the bluetooth shell and
also had messages all related to nordic ICs.
Make it generic and put it under drivers/flash/ so it can be included by
anyone and independently of bluetooth.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-19 11:49:18 +02:00
Szymon Janc
30ce313482 Bluetooth: host: Avoid using out-of-scope pointer
Mkae sure that variable pointed by params is valid when passing it
as function argument.

Fixes #10587

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-18 21:22:33 +03:00
Sebastian Bøe
2aea475846 Bluetooth: host: Improve error feedback on invalid input
Improve the error feedback when calling bt_le_adv_start and inputting
too much data in the advertisement.

Error feedback before:

Bluetooth initialized
Advertising failed to start (err -22)

Error feedback after:

Bluetooth initialized
[bt] [ERR] set_ad: Advertising data does not fit in buffer
Advertising failed to start (err -22)

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-17 13:37:24 +03:00
Joakim Andersson
912cdc0b8e Bluetooth: host: Allow to disable legacy pairing.
Add option to disable legacy pairing and only use secure connection.
If legacy pairing was requested pairing will be denied with status
insufficient authenticated

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-16 14:25:56 +03:00
Vinayak Kariappa Chettimada
51574c177f Bluetooth: controller: Avoid retransmission of NACK-ed Tx PDU
Added implementation to avoid retransmitting NACK-ed Tx PDU,
to save on current consumption in retrying to transmit in
case peer device has no free buffer to receive the PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-16 10:32:41 +02:00
Alberto Escolar Piedras
5f39dbb1b0 Bluetooth: Use new nrf COMPATIBLE options
To allow the BLE stack to be used both in the real nRF platforms
and simulated ones, change the used macros in the code to the
COMPATIBLE ones.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-10-15 09:36:37 -04:00
Vinayak Kariappa Chettimada
d80fee1ecb Bluetooth: controller: Fix master role RSSI measurement
Fix broken master role RSSI measurement. Since the original
contribution clean up into Zephyr, the radio shorts that was
set for measuring the RSSI for master role has been broken,
as it was cleared by the radio switching code further in the
Tx ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-15 11:08:00 +02:00
Vinayak Kariappa Chettimada
ae8649c5ec Bluetooth: controller: Fix connection failed to be established
Fix connection failed to be established regression
introduced by the commit 350c569aba ("Bluetooth:
controller: Avoid offseting to lldata").

As the Rx-ed PDU buffer is re-used to construct the
connection complete message towards HCI, the fields in the
Rx-ed PDU need to be backup for future use in the control
path. Here the channel selection bit is backup now.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-11 20:50:44 +02:00
Vinayak Kariappa Chettimada
a11868fea9 Bluetooth: controller: Fix conn param req procedure response
Fix Connection Parameter Request Procedure implementation
to respond with sent interval_min and interval_max so that
certain peer devices dont reject the response as Invalid LL
Parameters.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-11 20:30:02 +02:00
Radoslaw Koppel
4db9731451 bluetooth: host: conn: Add const to addr in bt_le_set_auto_conn
This commit adds missed const modifier for addr pointer for
bt_le_set_auto_conn function

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2018-10-08 20:31:39 -04:00
Vinayak Kariappa Chettimada
71fff7648d Bluetooth: controller: Refactor adv random delay resolution fix
Refactored the fix in the commit 685da02354 ("Bluetooth:
controller: Fix advertising random delay resolution calc")
to apply modulo in tick units before adding a tick.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-08 12:53:50 -04:00
Joakim Andersson
773b21ac38 bluetooth: config: Fix bluetooth config dependencies
Fix bluetooth config dependencies where the definitions depend on other
definitions.
BT_RX_PRIO is not always defined in a controller only build.
BT_CTLR_TX_BUFFER_SIZE does not depend on BT_CTLR, but BT_LL_SW.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-05 11:15:27 -04:00
Vinayak Kariappa Chettimada
049267a5ca Bluetooth: controller: Fix connection cancel deadlock
Calling bt_recv in the Bluetooth host Tx thread by the
controller implementation caused deadlock in combined host
controller builds when HCI LE Create Connection Cancel
generated the HCI LE Connection Complete or HCI LE Enhanced
Connection Complete events.

Controller's HCI implementation has been updated to place
the generated event into Rx FIFO to avoid the deadlock.

Relates to commit a59f544fb4 ("bluetooth: controller:
Handle non-priority events correctly")

Relates to #10314.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-05 13:44:10 +02:00
Vinayak Kariappa Chettimada
350c569aba Bluetooth: controller: Avoid offseting to lldata
Avoid offseting to lldata when populating event structure
members.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-05 13:44:10 +02:00
Szymon Janc
861bae22b8 Bluetooth: Fix autoconnect if cancelled pending connection
bt_conn_disconnect removes device from autoconnect list and thus
should not be called from le_conn_update when timeouting pending
connection. Also auto connect flag needs to be check on connection
failure to make sure scan is restarted.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-05 13:43:49 +02:00
Michael Scott
685da02354 Bluetooth: controller: Fix advertising random delay resolution calc
In commit d5836195d7 ("Bluetooth: controller: Increase advertising
random delay resolution"), the resolution of random_delay was
increased from 8-bit to 16-bit.  Due to this switch the result
of HAL_TICKER_US_TO_TICKS() can now be a 0, which causes the following
crash:
***** Kernel OOPS! *****
Current thread ID = 0x200043f0
Faulting instruction address = 0x17914
Fatal fault in ISR! Spinning...

Let's make sure we don't pass a 0 to ticker_update() by increasing
the result of HAL_TICKER_US_TO_TICKS() by 1.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-10-05 10:18:27 +02:00
Vinayak Kariappa Chettimada
3d1a659019 Bluetooth: controller: Fix default Tx buffers
Fix the default Tx buffers to 3. While the first Tx-ed
buffer generates the HCI Number of Completed Packets Event,
the controller needs to have 2 additional Tx buffers queued
so that the second Tx PDU has the More Data (MD) bit set so
as to have the connection event to continue to transmit any
additional Tx buffers that the Host will enqueue in the same
connection event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-04 11:45:54 +02:00
Radoslaw Koppel
152b15ab3b subsys: bluetooth: shell: bt: Add command to show LL address
This commit implements command in the shell to show current
link layer address.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2018-10-04 10:35:06 +02:00
Luiz Augusto von Dentz
76714c1480 Bluetooth: Shell: Make error message for unknown parameter consistent
Also simplify it by having the 'unknown parameter:' as part of the
message format.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-03 09:49:58 +02:00
Luiz Augusto von Dentz
ba545e0d3c Bluetooth: shell: Fix using \n with print/error
Those macros already contain line termination.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-03 09:49:58 +02:00
Carles Cufi
990ab2de70 Bluetooth: shell: Transition flash.c to the new shell
Convert the flash.c functions to the new shell format.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-02 18:41:11 +02:00
Carles Cufi
63f4d9f509 Bluetooth: shell: Transition ticker.c to the new shell
Convert the ticker.c functions to the new shell format.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-02 18:41:11 +02:00
Carles Cufi
5372950336 Bluetooth: shell: Transition ll.c to the new shell
Convert the ll.c functions to the new shell format.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-02 18:41:11 +02:00
Jakub Rzeszutko
0eea1ef212 subsys: shell: add int ret_val to command handlers
1. Command handler can return command exectution status as int.
2. Existing command handlers rework.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-02 14:44:25 +02:00
Luiz Augusto von Dentz
17558c9382 Bluetooth: shell: Use \r\n to terminate line
Shell expects each printed lined to be terminated with \r\n.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Luiz Augusto von Dentz
fb4785d274 Bluetooth: shell: Split L2CAP commands
This splits L2CAP commands under 'bt' to 'l2cap' removing 'l2cap-'
prefix from the commands:

l2cap - Bluetooth L2CAP shell commands
Options:
  -h, --help  :Show command help.
Subcommands:
  connect     :<psm>
  disconnect  :[none]
  metrics     :<value on, off>
  recv        :[delay (in miliseconds)
  register    :<psm> [sec_level]
  send        :<number of packets>

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Luiz Augusto von Dentz
043a8b0202 Bluetooth: shell: Split GATT commands
This splits GATT command under 'bt' to 'gatt' removing 'gatt-' prefix
from commands:

gatt - Bluetooth GATT shell commands
Options:
  -h, --help  :Show command help.
Subcommands:
  discover-characteristic  :[UUID] [start handle] [end handle]
  discover-descriptor      :[UUID] [start handle] [end handle]
  discover-include         :[UUID] [start handle] [end handle]
  discover-primary         :[UUID] [start handle] [end handle]
  discover-secondary       :[UUID] [start handle] [end handle]
  exchange-mtu             :[none]
  read                     :<handle> [offset]
  read-multiple            :<handle 1> <handle 2> ...
  subscribe                :<CCC handle> <value handle> [ind]
  write                    :<handle> <offset> <data> [length]
  write-without-response   :<handle> <data> [length] [repeat]
  write-signed             :<handle> <data> [length] [repeat]
  unsubscribe              :[none]
  metrics                  :register vendr char and measure rx
			    [value on, off]
  register                 :register pre-predefined test service
  show-db                  :[none]
  unregister               :unregister pre-predefined test service

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Luiz Augusto von Dentz
bcfc9939e4 Bluetooth: shell: Split RFCOMM commands
This splits RFCOMM command under 'br' to 'rfcomm' removing 'rfcomm-'
prefix from commands:

rfcomm - Bluetooth RFCOMM shell commands
Options:
  -h, --help  :Show command help.
Subcommands:
  register    :<channel>
  connect     :<channel>
  disconnect  :[none]
  send        :<number of packets>

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Luiz Augusto von Dentz
310ffc4c4c Bluetooth: shell: Split BR/EDR commands
This splits BR/EDR command under 'bt' to 'br' to reduce the command
list and at same time cleaning the mix between different bearers.

In addition to that also remove "br-" prefix for the commands:

br - Bluetooth BR/EDR shell commands
Options:
  -h, --help  :Show command help.
Subcommands:
  auth-pincode       :<pincode>
  connect            :<address>
  discovery          :<value: on, off> [length: 1-48] [mode: limited]
  iscan              :<value: on, off>
  l2cap-register     :<psm>
  oob                :
  pscan              :value: on, off
  sdp-find           :<HFPAG>
  rfcomm-register    :<channel>
  rfcomm-connect     :<channel>
  rfcomm-send        :<number of packets>
  rfcomm-disconnect  :[none]

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Luiz Augusto von Dentz
592dd2e964 Bluetooth: shell: Port commands to the news shell
Fixes #8873

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Vinayak Kariappa Chettimada
d5836195d7 Bluetooth: controller: Increase advertising random delay resolution
Increase the resolution of advertising random delay from
1 ms unit to 1 us units. The controller scheduling will
floor it to nearest 32KHz clock unit on nRF5 series.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-09-28 18:03:51 +02:00
Szymon Janc
a7bf9de0ee Bluetooth: Use BT_CMD_TEST macro for testing supported commands
Make code easier to read and more consistent.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-28 13:43:39 +03:00
Szymon Janc
9c5c2f8baf Bluetooth: Fix incorrectly reporting connection as failure
Auto connect code reuses bt_conn object and connection code was assuming
object was cleared which resulted in invalid code being provided to
application. Fix that by explicitly setting error code to 0 on
successful connection.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-28 13:43:00 +03:00
Szymon Janc
f0f4147a57 Bluetooth: Allow to configure LE Create Connection timeout
Depending on perhiperal advertising interval 3 seconds might not be
enough and would result in cancelling pending connection. Make this
Kconfig configurable and let application to decide.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-28 13:42:26 +03:00
Mark Ruvald Pedersen
d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Szymon Janc
063123f35a Bluetooth: Allow to configure background scan window and interval
Applications may require different scan windows and interval depending
on expected re-connection time or peer devices advertising parameters.
Default to GAP recommended slow values.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-26 22:45:37 +02:00
Carles Cufi
d813b13109 Bluetooth: controller: Remove timestamp from HCI
In order to avoid the build system complications that come from
including a timestamp, remove it by default from the version string in
HCI Vendor Extensions. Users can still include a unique identifier, be
it timestamp or not, using the CONFIG_BT_CTLR_HCI_VS_BUILD_INFO Kconfig
option.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-09-26 14:50:26 +02:00
Vinayak Kariappa Chettimada
684f753fd4 Bluetooth: controller: Fix Data Length Update implementation
The Data Length Update implementation reused the flags used
by Encryption Procedure which caused invalid Encryption
Procedure sequence under conditions where Data Length Update
Procedure collide with Encryption Setup initiated by the
peer central device.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-09-26 11:55:02 +02:00
Kamil Piszczek
868a3bff0d Bluetooth: host: always set address via HCI before scanning
The address of the device is also set via HCI interface when passive
scanning is used. As a result, LL does not filter out directed
advertising packets that are targeted at this device.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-25 14:25:17 +03:00
Szymon Janc
bb271a6d98 Bluetooth: Add option to configure peripheral connection parameters
This allows to configure desired parameters for peripheral. When set
PPCP characteristic is also added to GAP service. If disabled it is
up to application to controll connection parameters and stack will
only enforce 5 seconds delay before update.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-25 13:31:10 +03:00
Szymon Janc
75405f5613 Bluetooth: Fix connection parameters update
This fixes a few issues with the handling of Connection Parameter
update in the Host:
 - starting conn param update timer as master
 - ignoring 5 seconds slave timer when calling bt_conn_le_param_update
 - starting conn param update timer on every PHY update

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-25 13:31:10 +03:00
Sebastian Bøe
f8616291e4 Kconfig: BT: Give the LL selection option a name
There is an unnamed choice for the BT link layer selection.

Giving the choice a name would allow multiple declarations of the
option and the ability to select out-of-tree LL's.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-09-25 09:42:23 +02:00
Johan Hedberg
559578c09a Bluetooth: Add API to iterate through existing bonds
So far the stack hasn't provided any way for the application to access
the existing bonds. This patch adds such an API.

Fixes #10122

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-24 13:27:26 +03:00
Luiz Augusto von Dentz
8c02af73be Bluetooth: shell: Add l2cap-recv command
This adds l2cap-recv which can be used to set a delay when confirming
the receptions of packets:

> l2cap-recv 1000
Incoming conn 0x00401c20
Channel 0x004220c8 connected
Channel 0x004220c8 requires buffer
Incoming data channel 0x004220c8 len 230
00000000 00 00 00 00 e6 00 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000010 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000020 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000030 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000040 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000050 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000060 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000070 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000080 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000090 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
000000a0 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
000000b0 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
000000c0 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
000000d0 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
000000e0 7f 7f 7f 7f 7f 7f
Delaying response...
Confirming reception

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz
16fdd74908 Bluetooth: L2CAP: Make use of net_buf_append_bytes
This uses net_buf_append_bytes to reassemble the SDU segments instead of
doing it manually.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz
62f41df283 Bluetooth: L2CAP: Prevent the channel to stall
If the remote stack is not able to fully utilize each segment it is
possible it would run out of credits before completing the SDU, these
changes detects if that would happen and attempt to restore enough
credits for the SDU to be received.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz
8af4786e9f Bluetooth: L2CAP: Restore credits after receiving an SDU
This simplify the logic of restoring the credits after each SDU instead
of using an arbitrary threshold which was not configurable per channel.

Because the credits are restored only when the full SDU has been
reassembled it means the channels needs to be set up with enough for
the configured MTU otherwise there is a risk of the channel to run out
of RX credits before the packet is fully reassembled, because of such
corner case the code will now warn if a channel is setup with not enough
init_credits.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz
3151d26572 Bluetooth: L2CAP: Add return to recv
This adds a int return to recv callback which can be used to notify the
stack about errors when receiving a packet. In addition to that the user
can return -EINPROGRESS to inform the stack the data will be processed
asynchronously which can be complete by calling
bt_l2cap_chan_recv_complete.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Joakim Andersson
0287a04340 Bluetooth: host: Fix name conflict with kernel smp_init in smp.c
When activating SystemView internal kernel header files will be
included. This causes a name conflict with smp_init in smp.c
and smp_init in kernel_internal.h

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-09-24 10:53:20 +03:00
Kamil Piszczek
e48434bc71 Bluetooth: gatt: gatt_discover_next with inclusive handle range
This fix ensures that the handle range used for next GATT discovery is
always inclusive. Previously, the discovery procedure could not be
started with equal value of start and end handle.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-21 18:52:52 -04:00
Szymon Janc
6c89c4b5f7 Bluetooth: Controller: Add support for setting public address
This allows to provide public address for controller without using
VS HCI command from host. Useful for controller only builds or
combined builds that are not using VS HCI commands.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-21 12:40:10 +02:00
Luiz Augusto von Dentz
0a23067540 Bluetooth: GATT: Remove BT_GATT_WRITE_FLAG_PREPARE check in GAP
This check is only required when BT_GATT_WRITE_FLAG_PREPARE is set.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-21 12:27:50 +03:00
Adithya Baglody
9fe378b7e7 Bluetooth: Mesh: Enforce proper compilation.
The current method relies heavily on the linker/compiler to
do the correct operation. Which is to eliminate the code that will
never get called. This posses a problem if the build even changes
by a smallest fraction.
The current patch will enforce proper inclusion of the code at the
pre-processing stage. Thereby not relying on the compiler/linker to
do the right thing.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 11:14:03 +03:00
Krzysztof Chruscinski
527256501f shell: Rename shell to legacy_shell
New shell implementation is on the way. For now old one and all
references are kept to be gradually replaced by new shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Joakim Andersson
9c2214e2a3 Bluetooth: shell: Add shell command set channel map
Add a new command in the shell which can be used to set the channel
map by specifying a 37 bit bitmask written as a five byte hex array.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-09-19 15:51:57 +03:00
Joakim Andersson
139beac5cf Bluetooth: host: Add set channel map command
Add functionality for setting the host channel classification in
the controller using the HCI command.
This closes issue #9851

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-09-19 15:51:57 +03:00
Szymon Janc
732b45cff3 Bluetooth: Read static address from FICR on nRF5 if no VS enabled
When running combined build on nRF5 with disabled VS command it is
possible to simply read static random address from FICR in host.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-19 13:03:56 +02:00
Szymon Janc
e76224d038 Bluetooth: Controller: Add CONFIG_BT_HCI_VS option
This allows to fully disable HCI VS commands support.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-19 13:03:56 +02:00
Szymon Janc
f93eef17a5 Bluetooth: Fix security level checking with LE SC and no-bonding
This was affecting SM/MAS/SCPK/BV-01-C qualification test case.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-19 13:34:29 +03:00
Mariusz Skamra
323243d376 Bluetooth: Add a shell command to disable bondable mode
This adds a shell command for qualification purposes to enable/disable
Bonding flag in Authentication Requirements.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Mariusz Skamra
4f74f69814 Bluetooth: Add run-time option to disable SMP bondable mode
This adds a function that will disable Bonding flag in
Authentication Requirements flag in SMP Pairing Request/Response.
This is needed for qualification purposes.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Mariusz Skamra
7ff9eeea0e Bluetooth: Add Kconfig option to disable bondable mode
This adds Kconfig option to allow disable bondable mode in compile
time.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Mariusz Skamra
64e608be8b Bluetooth: testing: Exclude Mesh related code if BT_MESH not set
This will exclude testing Mesh related code from build if BT_MESH
option in Kconfig is not set.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Luiz Augusto von Dentz
f67d45609e Bluetooth: shell: Fix requiring UUID for gatt-discover
This enables using these commands to perform discover all procedure:

> gatt-discover-primary
 Discover pending
 Service 1800 found: start handle 1, end_handle 5
 Service 1801 found: start handle 6, end_handle 9

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-19 09:23:08 +03:00
Luiz Augusto von Dentz
e2362e1d00 Bluetooth: GATT: Make bt_gatt_discover perform discover all procedure
This makes bt_gatt_discover perform discover all proceduce if no UUID
is given in the parameters.

Fixes #9713

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-19 09:23:08 +03:00
Luiz Augusto von Dentz
0d1724b069 Bluetooth: GATT: Fix long write procedure
Long write procedure currently requires BT_GATT_PERM_PREPARE_WRITE to
be set otherwise the prepares would fail. This changes the behavior so
that BT_GATT_PERM_PREPARE_WRITE enables checking each prepare chunk
skipping it otherwise.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-19 09:22:31 +03:00
Matias Karhumaa
22a27fa0e2 Bluetooth: hci_ecc: Fix byte order of dbg keys
Pass Bluetooth SMP debug keys to crypto API in correct byte order.

Fixes #9867

Signed-off-by: Matias Karhumaa <matias.karhumaa@gmail.com>
2018-09-18 14:23:15 +03:00
Johan Hedberg
366378f8ac Bluetooth: GATT: Fix const'ness of characteristic descriptor data
None of the data for the CEP, CUD and CPF descriptors needs to be
modified by the stack at runtime. Make it possible to pass constant
data to the descriptor macros, and make sure the descriptor handlers
cast the data back to be a constant.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-18 10:19:08 +03:00
Johan Hedberg
3c1dab005f Bluetooth: SMP: Remove bogus ARG_UNUSED() macro
The req variable in smp_pairing_failed() does get used, so
ARG_UNUSED() is inappropriate for it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 14:46:10 -04:00
Johan Hedberg
b4d7c2906b Bluetooth: Remove bogus condition for setting IRK for an identity
Just like we set the address for an identity without depending on the
BT_DEV_READY flag, we should do the same for the IRK. Otherwise we
risk getting an all-zeroes IRK. Remove the condition and always set
the IRK value whenever CONFIG_BT_PRIVACY is enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 19:50:49 +03:00
Johan Hedberg
cb08963fac Bluetooth: Fix identity creation through vendor HCI
The code creating identities from the Read_Static_Addresses vendor
command was failing to create matching IRKs, resulting in an
all-zeroes IRK to be used. Fix this by using the existing id_create()
function which takes care of generaing an IRK when necessary.

Fixes #10003

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 19:50:49 +03:00
Johan Hedberg
a8f4370966 Bluetooth: Move bt_setup_id_addr() to avoid forward declaration
A subsequent patch will make bt_setup_id_addr() depend on id_create()
which was so far lower down in the hci_core.c c-file. Move
bt_setup_id_addr() further down to avoid a forward declaration.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 19:50:49 +03:00
Flavio Ceolin
abffd83d26 kernel: atomic: Ignore atomic_and/or return when not used
There are some cases where atomic_and/or don't need to be
checked. Actively acknowledge these cases.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Flavio Ceolin
da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Kamil Gawor
8853cb3d06 subsys: bluetooth: Add notification TX complete callback
This changed added notification complete callback which
gives information if a given notification has been sent.

Signed-off-by: Kamil Gawor <Kamil.Gawor@nordicsemi.no>
2018-09-14 14:39:01 +02:00
Kamil Piszczek
3e8f118d8f Bluetooth: shell: adding command for directed advertising
Added a new command, which can be used to test the directed advertising
API. This command allows user to turn on directed advertising in two
modes: low and high duty. High duty mode is the default one.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-13 14:21:21 +02:00
Kamil Piszczek
9af28ddc09 Bluetooth: host: directed advertising support
Added implementation to the directed advertising API in the Connection
Management module. Introduced a new connection state for this type of
advertising. The new state is symmetric to the connection state used for
scanning.

Added a new advertising option that can be used to trigger low and high
duty directed advertising. Added macros for default values of
Advertising Parameters, which are used to trigger directed advertising.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-13 14:21:21 +02:00
Alberto Escolar Piedras
877c4d0ca7 Bluetooth: controller: Use nRFx functions for PPI reg access
In the BLE controller, NRF radio HAL, for the PPI registers used
for the SW TIFS.
To allow easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-12 13:13:48 +02:00
Mariusz Skamra
02d980add3 bluetooth: gatt: Add GAP Central Address Resolution characteristic
This adds Central Address Resolution characteristic that is required
to check by peer if it's about to send directed advertisements where
initiator address is set to RPA.
Zephyr supports the Address Resolution, so the characteristic value
is hard-coded.
Please check Core 5.0 Vol 3 Part C 12.4 CENTRAL ADDRESS RESOLUTION
Related PTS test case: GAP/CONN/ACEP/BV-03-C

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-10 17:47:15 -04:00
Luiz Augusto von Dentz
148c7dd8a3 Bluetooth: GATT: Auto init if bt_gatt_service_register is called
This ensures the core services are always registered first and the
gatt_sc work is initialized.

Fixes #9785

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-10 12:07:08 -04:00
David Leach
c2d980798a Bluetooth: Mesh: Fix incorrect reference to BT_SETTINGS
The test for IS_ENABLED(BT_SETTINGS) in mod_reset()
should be IS_ENABLED(CONFIG_BT_SETTINGS).

Signed-off-by: David Leach <david.leach@nxp.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-10 10:46:23 -04:00
Carles Cufi
022f9157e8 Bluetooth: mesh: Fix missing semicolon
Fix a missing semicolon at the end of a statement.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-09-05 10:45:19 -04:00
Johan Hedberg
697919c5ba Bluetooth: Mesh: Fix checking for subnet when recovering App Key
The ordering of items in flash is not guaranteed, so it's possible we
get an App Key before the corresponding Net Key. Remove the check for
a Net Key, since the storing code should never store an App Key if
there is no corresponding Net Key.

Fixes #9670

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-02 21:44:54 -04:00
Johan Hedberg
643c8abea3 Bluetooth: Fix using correct IRK when generating RPA
The code in le_set_private_addr() was hardcoding identity 0, even
though it is given a specific identity as an input parameter.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-30 13:49:59 +03:00
David B. Kinder
1c29bff055 doc: fix kconfig misspellings
Fix misspellings in kconfig files missed during regular reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-08-28 13:58:46 -04:00
Olivier Martin
c3118e66ee subsys: bluetooth: host: Ensure PDUs are not allocated in ISR
`bt_conn_create_pdu()` must not be called in ISR has the call
might be blocking.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-08-27 12:52:11 -04:00
Vinayak Kariappa Chettimada
f3be631625 Bluetooth: controller: Fix compile error when PHY update disabled
Fixed compile error when PHY update feature is disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-27 12:48:12 -04:00
Vinayak Kariappa Chettimada
021b12328a Bluetooth: Kconfig the Auto PHY Update Procedure initiation
Added Kconfig option to select Auto-initiation of PHY update
procedure on connection establishment.

Relates to #9608.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-27 12:47:34 -04:00
Vinayak Kariappa Chettimada
f232643f7c Bluetooth: controller: Use HCI Error Code definitions
Replase magic numbers with HCI Error Code definitions in the
LE controller implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-24 16:10:01 +03:00
Vinayak Kariappa Chettimada
94d7669cf3 Bluetooth: controller: Fix assert on different transaction collision
Updated the implementation of Connection Update Procedure to
not assert when peer master violates the Bluetooth
Specification v5.0 Vol.6 Part B Section 5.3 Procedure
Collisions. Instead disconnect the link with reason
Different Transaction Collision (0x2A).

Certain phones in the market perform Connection Update
Procedure and do not correctly handle remote initiated
colliding PHY update procedures. They try to perform both
the transactions involving an instant simultaneously
violating the Bluetooth Specifications.

Implementation in Zephyr is updated to gracefully handle
the violating remote master device, and not fatally assert
in the local device.

Relates to commit 8b3fd6963c ("Bluetooth: controller: Fix
assert on different transaction collision")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-24 16:10:01 +03:00
Luiz Augusto von Dentz
871859a07e Bluetooth: GATT: Make CCC cfg_changed optional
If cfg_changed has not been set consider that the application don't
care and just skip it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-08-21 21:57:00 +03:00
Vinayak Kariappa Chettimada
8b3fd6963c Bluetooth: controller: Fix assert on different transaction collision
Updated the implementation of PHY update procedure to not
assert when peer master violates the Bluetooth Specification
v5.0 Vol.6 Part B Section 5.3 Procedure Collisions. Instead
disconnect the link with reason Different Transaction
Collision (0x2A).

Certain phones in the market perform Connection Update
Procedure and do not correctly handle remote initiated
colliding PHY update procedures. They try to perform both
the transactions involving an instant simultaneously
violating the Bluetooth Specifications.

Implementation in Zephyr is updated to gracefully handle
the violating remote master device, and not fatally assert
in the local device.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-18 23:22:10 +02:00
Johan Hedberg
bf023d6210 Bluetooth: Mesh: Fix heartbeat subscription state handling
PTS version 7.3.0 incorporates some errata which change the expected
behavior of the heartbeat subscription state. Update the code so that
the following tests pass successfully:

MESH/NODE/CFG/HBS/BV-01
MESH/NODE/CFG/HBS/BV-02
MESH/NODE/CFG/HBS/BV-03
MESH/NODE/CFG/HBS/BV-04

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 22:40:02 +03:00
Johan Hedberg
c037127754 Bluetooth: Mesh: Initialize PB-GATT advertising data at the right time
Some things, such as UUID, URI or even the local name may be different
when bt_mesh_prov_enable() is called compared to when bt_mesh_init()
was called. Create the advertising data on-demand each time when
enabling PB-GATT.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 22:39:36 +03:00
Johan Hedberg
bb576f61b6 Bluetooth: Mesh: Move Device UUID log to bt_mesh_prov_enable()
In some cases the application might only initialize its UUID after
calling bt_mesh_init(), e.g. in the case of deriving the UUID from the
identity address. To avoid confusing logs, only print the UUID when
actually enabling one of the provisioing bearers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 22:39:36 +03:00
Johan Hedberg
e4908119f1 Bluetooth: Mesh: Transport: Fix calculating SeqAuth
This patch fixes case where Mesh is receiving segmented data with
SEQ and SeqZero as in logs below:

bt_mesh_trans_recv: src 0x07FF dst 0x0001 seq 0x00031FFF friend_match 0
bt_mesh_trans_recv: Payload dd7ffc016e5c7f861272e5f7577a6644
trans_seg: ASZMIC 0 AKF 1 AID 0x1D
trans_seg: SeqZero 0x1FFF SegO 0 SegN 1
trans_seg: ######## seq_auth=204799

bt_mesh_trans_recv: src 0x07FF dst 0x0001 seq 0x00032000 friend_match 0
bt_mesh_trans_recv: Payload dd7ffc21abb5a7
trans_seg: ASZMIC 0 AKF 1 AID 0x1D
trans_seg: SeqZero 0x1FFF SegO 1 SegN 1
trans_seg: ######## seq_auth=212991

Original-patch-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 17:36:27 +03:00
Johan Hedberg
61ec51251e Bluetooth: shell: Add id-delete command
Add a command to test the new bt_id_delete() API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
346f815d9e Bluetooth: Introduce bt_id_delete() API
This API makes it possible to delete an existing identity and to flag
its storage slot as unused.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
47291330b2 Bluetooth: Add safe-guards for creating duplicate identities
Make sure the application doesn't pass existing identity addresses to
bt_id_create() and bt_id_reset(). Also make sure we don't accidentally
create a duplicate when generating random identity addresses.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
7ec40e81d0 Bluetooth: shell: Add multiple identity support
Add shell support for creating and showing identities.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
7dba2512e3 Bluetooth: Introduce bt_id_reset() API
Add a new API which can be used to reclaim an identity slot for a new
identity. When called, any previous pairings, connections, or other
data will be cleared, and then a new identity will be generated in the
place of the old one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
3d3888c094 Bluetooth: Remove return parameter from bt_id_add/del
None of the callers of these APIs do anything with the return value,
so just remove it to produce more efficient code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
9336049725 Bluetooth: Remove bogus bt_keys_func_t typedef
This wasn't used anywhere and was typed incorrectly (the foreach
callback takes two parameters). There was also one user of this which
was triggering compiler warnings of mismatched callback type.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
cbb1b84f91 Bluetooth: Pass identity to connection and pairing clearing functions
When doing bt_unpair() we need to pass the given identity when
disconnecting and clearing keys, in case all associated pairings were
requested to be cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
e70c556dcc Bluetooth: Add full storage support for multiple identities
Update the storage handling to take into account multiple identities.
We can save a bit of code by using the new bt_id_create() API from
within settings.c.

Also make the treatment of addr & irk parameters to bt_id_create()
consistent, in that NULL is acceptable for both of them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
3ed01b48b9 Bluetooth: Remove redundant BT_DEV_ID_STATIC_RANDOM flag
This flag was both redundant and creates confusion with potentially
multiple identity addresses (it was only referring to the first
identity address). We can simply just look at the type of the identity
address wanting to be used.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
1d8dab811e Bluetooth: Add initial APIs for identity manipulation
Add APIs for getting current identities as well as for creating new
ones.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
5708f1e8b1 Bluetooth: Add infrastructure to handle multiple identities
Make it possible to have multiple identity addresses as an LE
peripheral. For central role only the default identity is supported
for now. This also extends the flash storage in a backward compatible
way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg
6b8af4f0b2 Bluetooth: Minor whitespace fixes
Remove redundant whitespace.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Ulf Magnusson
ec3eff57e0 Kconfig: Use the first default with a satisfied condition
Up until now, Zephyr has patched Kconfig to use the last 'default' with
a satisfied condition, instead of the first one. I'm not sure why the
patch was added (it predates Kconfiglib), but I suspect it's related to
Kconfig.defconfig files.

There are at least three problems with the patch:

  1. It's inconsistent with how Kconfig works in other projects, which
     might confuse newcomers.

  2. Due to oversights, earlier 'range' properties are still preferred,
     as well as earlier 'default' properties on choices.

     In addition to being inconsistent, this makes it impossible to
     override 'range' properties and choice 'default' properties if the
     base definition of the symbol/choice already has 'range'/'default'
     properties.

     I've seen errors caused by the inconsistency, and I suspect there
     are more.

  3. A fork of Kconfiglib that adds the patch needs to be maintained.

Get rid of the patch and go back to standard Kconfig behavior, as
follows:

  1. Include the Kconfig.defconfig files first instead of last in
     Kconfig.zephyr.

  2. Include boards/Kconfig and arch/<arch>/Kconfig first instead of
     last in arch/Kconfig.

  3. Include arch/<arch>/soc/*/Kconfig first instead of last in
     arch/<arch>/Kconfig.

  4. Swap a few other 'source's to preserve behavior for some scattered
     symbols with multiple definitions.

     Swap 'source's in some no-op cases too, where it might match the
     intent.

  5. Reverse the defaults on symbol definitions that have more than one
     default.

     Skip defaults that are mutually exclusive, e.g. where each default
     has an 'if <some board>' condition. They are already safe.

  6. Remove the prefer-later-defaults patch from Kconfiglib.

Testing was done with a Python script that lists all Kconfig
symbols/choices with multiple defaults, along with a whitelist of fixed
symbols. The script also verifies that there are no "unreachable"
defaults hidden by defaults without conditions

As an additional test, zephyr/.config was generated before and after the
change for several samples and checked to be identical (after sorting).

This commit includes some default-related cleanups as well:

  - Simplify some symbol definitions, e.g. where a default has 'if FOO'
    when the symbol already has 'depends on FOO'.

  - Remove some redundant 'default ""' for string symbols. This is the
    implicit default.

Piggyback fixes for swapped ranges on BT_L2CAP_RX_MTU and
BT_L2CAP_TX_MTU (caused by confusing inconsistency).

Piggyback some fixes for style nits too, e.g. unindented help texts.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-10 12:38:28 -07:00
Alberto Escolar Piedras
3712fd3415 Bluetooth: controller: remove unnecessary guards in hal headers
After a dedicated header is allocated to the simulated SOC versions
there is no need anymore to have guards in these other files

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-09 12:15:45 +02:00
Alberto Escolar Piedras
e0864a9338 Bluetooth: controller: HAL: Separate simulated SOC in own header
To avoid issues with differences between the simulated and the real
SOC let's separate the simulated one into its own header

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-09 12:15:45 +02:00
David B. Kinder
7c89b63b7c doc: fix kconfig misspellings
Fix misspellings in Kconfig files missed during normal reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-08-08 01:48:24 -05:00
Szymon Janc
504584a998 Bluetooth: att: Add option to disable GATT writable name
This allow to set name at runtime while leaving GAP name characteristic
read only.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-08-03 10:41:01 +02:00
Luiz Augusto von Dentz
1329763a14 Bluetooth: Fix storing name in plain text
Settings consider the character space the end of the value, so instead
encode the name using settings_str_from_bytes and restore it with
settings_bytes_from_str.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-08-02 19:16:58 +02:00
Johan Hedberg
6ee8e41915 Bluetooth: Mesh: Clarify confusing log message
Normally App Keys are identified using the AppKey Index value (a 12
bit value in practice), whereas the stack-internal array index has
very little relevance.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-02 01:06:29 +02:00
Johan Hedberg
28d5a65a94 Bluetooth: SMP: Don't try to encrypt with a non-existing LTK
When we receive a security request we need to make sure that any
existing keys contain an LTK to encrypt with. Otherwise there's a risk
of trying to encrypt with an all-zeroes LTK.

Fixes #3221

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-02 01:05:49 +02:00
Vinayak Kariappa Chettimada
3ebb81ba73 Bluetooth: controller: Wait for stable k32src for connected roles
Added implementation to check and wait for stable 32KHz
clock source before starting connectable/directed
advertising state and initiating state.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-02 01:04:46 +02:00
Vinayak Kariappa Chettimada
76320d2142 Bluetooth: controller: Fix HCI LE Set PHY command status response
Fixed the implementation to generate command status as per
Bluetooth v5.0 specification instead of the incorrect
command complete that was generated before.

Also, the unsupported features status will be generated
before the invalid parameters status.

Relates to commit 258c7ccff1 ("Bluetooth: controller: Fix
HCI LE Set PHY invalid behavior check")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-02 01:03:17 +02:00
Vinayak Kariappa Chettimada
97da52bb95 Bluetooth: controller: Update AA generation for Coded PHY support
Update the access address generation function with Coded PHY
support requirements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-02 01:02:29 +02:00
Johan Hedberg
0ab27e6803 Bluetooth: shell: Add support for pairing confirm-only callbacks
Add a callback struct with only the pairing_confirm authentication
method. This is useful both for just-works testing as well as the
recently added fixed passkey support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg
e504aad28f Bluetooth: shell: Add pairing failed/complete callbacks
Add support for the recently added pairing failed/complete callbacks.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg
b049ac1216 Bluetooth: shell: Add command for setting fixed passkey
Add a shell command to utilize the newly added bt_passkey_set() API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg
c446c8267b Bluetooth: Add support for fixed passkeys
Add a new bt_passkey_set() API that can be used to set a fixed passkey
to be used for pairing. The new API also requires a new Kconfig option
to be enabled first (CONFIG_BT_FIXED_PASSKEY).

Fixes #8350

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg
ef70fc85a9 Bluetooth: SMP: Fix SMP context init when sending security request
The code was not doing the right thing when we as peripheral would
send a security request to the central. First of all, the SEQ_REQ flag
was getting cleared by the pairing request handler, resulting in
pairing_confirm() callbacks for no reason. Secondly, the behavior in
encrypt_change() was not utilizing the smp_reset() helper as it should
have done.

Fix the situation by calling smp_init() when sending a security
request, and detect that this has been done when receiving a pairing
request. Also do the appropriate cleanup if the result is an encrypt
change instead of a pairing request (in case we were already paired
with the peer).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg
da8f62de3a Bluetooth: SMP: Remove redundant check for smp pointer
The smp pointer is the return value of CONTAINER_OF() which is
guaranteed to always be non-NULL.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg
4752788c81 Bluetooth: Fix documentation and other issues with auth callbacks
Provide proper documentation for all of the authentication callbacks,
and clarify the usage of the cancel callback. Previously the cancel
callback was always required, even though that doesn't necessarily
make sense now that the pairing_complete/failed callbacks exist.

Fixes #8385

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Ulf Magnusson
642db77591 bluetooth: kconfig: Fix swapped 'range's on BT_RFCOMM_L2CAP_MTU
Whoever added Zephyr's prefer-later-defaults Kconfig patch originally
didn't do the same for 'range's. Earlier ranges are still preferred.
Swap the ranges on BT_RFCOMM_L2CAP_MTU to give the intended behavior.

Fixes the following warning for tests/bluetooth/shell/prj_br.conf:

  warning: default value 200 on BT_RFCOMM_L2CAP_MTU (defined at
  subsys/bluetooth/host/Kconfig:508) clamped to 264 due to being outside
  the active range ([264, 32767])

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-31 08:26:28 -04:00
Johan Hedberg
db0e4d5267 Bluetooth: Kconfig: Enable TINYCRYPT_ECC for combined builds
Essentially all products that support pairing or Mesh need to be able
to support ECC. This is particularly important for traditional
peripheral/central use cases where legacy pairing is considered
insecure. With split builds we don't know if the controller supports
ECC HCI commands or not, however with a combined build we know that
the current controller lacks any special ECC support, so enable
TINYCRYPT_ECC by default for such a configuration.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-31 13:55:40 +03:00
Johan Hedberg
4fe8eddd27 Bluetooth: SMP: Don't return STK if it hasn't been generated yet
The SMP_FLAG_ENC_PENDING flag indicates that we've generated an STK
and are waiting for encryption to happen. In case the remote enables
encryption prematurely we should not try to encrypt with whatever is
stored in smp->tk, rather reject the pairing attempt.

Fixes #3222

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-30 13:02:34 +03:00
Johan Hedberg
4d10b04aa1 Bluetooth: SMP: Fix missing NULL-checks for bt_auth
The recently added pairing_complete & pairing_failed callbacks
were missing a NULL-check for bt_auth, since it is possible that
there's no authentication callback structure registered at all.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-30 12:42:45 +03:00
Luiz Augusto von Dentz
8780636ff8 Bluetooth: shell: Add hci-cmd command
hci-cmd can be used to inject an arbritrary HCI command which can be
useful when testing vendor/new commands.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-27 19:36:11 +03:00
Johan Hedberg
e2e0202995 Bluetooth: SMP: Fix minor coding style issues
commit 9b6ad4067b introduced some minor
coding style issues related to line splitting. Fix these.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-27 19:34:34 +03:00
Jun Li
9b6ad4067b bluetooth: add callback to notify pairing is complete
Added two new callbacks for Bluetooth stack to notify
the application that pairing has been completed or failed.

fixes: #8390

Signed-off-by: Jun Li <jun.r.li@intel.com>
2018-07-27 16:16:52 +03:00
Johan Hedberg
c384631dac Bluetooth: Mesh: Kconfig: Tweak RX SDU value
Update the RX SDU Kconfig value to something that reflects better
current use cases and doesn't waste memory needlessly. Also lower the
minimum to two segments, since while many samples need three for their
composition data (typically the biggest transferred payload), it's
possible to have a very simple node whose composition fits in two
segments.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-25 18:16:45 +03:00
Johan Hedberg
8c1c1641fe Bluetooth: Mesh: Improve outgoing segment count configuration
The Mesh specification doesn't support more than 32 transport layer
segments, the way the number was so far derived from the advertising
buffer count could result in a highre numbe than 32, thereby wasting
memory. Make the number of supported segments build-time configurable
through a new BT_MESH_TX_SEG_MAX configuration option.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-25 18:16:45 +03:00
Szymon Janc
e3bf53566e Bluetooth: controller: Fix disabling LE Encryption support
Symbols without prompt cannot be configured from application
configuration file.

warning: BT_CTLR_LE_ENC (defined at subsys/bluetooth/controller/
Kconfig:198) was assigned the value 'n' but got the value 'y'.
This symbol has no prompt, meaning assignments in configuration files
have no effect on it. It can only be set indirectly, via Kconfig
defaults (e.g. in a Kconfig.defconfig file) or through being 'select'ed
or 'imply'd (note: try to avoid Kconfig 'select's except for trivial
promptless "helper" symbols without dependencies, as it ignores
dependencies and forces symbols on).

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-07-25 13:52:03 +03:00
Johan Hedberg
99a91c9459 Bluetooth: Kconfig: Lower minimum required ACL buffer count
The controller already has a minimum of 1, and the host should mirror
that (in particular to avoid Kconfig warnings). A single buffer is
unsafe in some scenarios (such as with LE SC enabled) however there
are valid scenarios where a single buffer makes sense, so leave it up
to the developer to choose this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-24 14:14:49 +03:00
Luiz Augusto von Dentz
e9e5115116 Bluetooth: shell: Add name command
name command can be used to read or write the GAP Device Name which is
used by the advertise command.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz
d1c4ce8741 Bluetooth: shell: Make use of BT_LE_ADV_OPT_USE_NAME
Use BT_LE_ADV_OPT_USE_NAME whenver possible since it does properly
track updates.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz
4052ca6d17 Bluetooth: Use shortened name if complete doesn't fit
If the complete name doesn't fit try shortening the name.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz
18df11646f Bluetooth: Allow use of ScanData with BT_LE_ADV_OPT_USE_NAME
This enables the user to provide a ScanData, as long as it contain
names, and set BT_LE_ADV_OPT_USE_NAME.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz
acc3e5129e Bluetooth: Add BT_LE_ADV_OPT_USE_NAME
This introduces a new advertising flag BT_LE_ADV_OPT_USE_NAME which can
be used by applications to make the stack automatically include the
Bluetooth Device Name in the Scan Response.

The name is also updated in case there is already an advertising
instance using it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz
aa339ed0f2 Bluetooth: GATT: Make GAP name writable
This makes GAP name writable if CONFIG_BT_DEVICE_NAME_STORAGE is > 0
which means the name can be persisted.

Fixes #8357

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz
2637c978fe Bluetooth: Store device name
This uses bt_dev to store the name and allow changing it at runtime, in
addtion to that if CONFIG_BT_SETTINGS is defined make the name
persistent.

Fixes #8357

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Johan Hedberg
be9966f3ae Bluetooth: Mesh: Fix missing semicolon for debug log
Without this it's not possible to build cfg_srv.c with debug logs
enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-20 14:15:49 +03:00
Anas Nashif
e29acf0015 Bluetooth: shell: fix type usage
We have been mixing u32_t and uint32_t. Using u32_t when the API expects
something else.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-07-18 12:32:23 -04:00
Kumar Gala
f035395ed0 bluetooth: at: Fix warning when building with newlib
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Explicity cast to unsigned char so we deal with both this warning and
possible warning when -Wpointer-sign is enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-16 11:06:20 -04:00
Kumar Gala
c2862eda4d bluetooth: mesh: shell: Fix warning when building with newlib
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Explicity cast to unsigned char so we deal with both this warning and
possible warning when -Wpointer-sign is enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-16 11:06:20 -04:00
Ulf Magnusson
1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
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.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Vinayak Kariappa Chettimada
505a83414e drivers: gpio: nrf5: Fix GPIOTE channel use overlap
Fixes issues caused in GPIO driver due to overlapping GPIOTE
channel use in nRF5 software PWM driver and in Bluetooth
controller for implementing PA/LNA feature.

The issue is solved by assigning the base and available
channel count for GPIOTE considering whether PWM and/or
PA/LNA feature is selected in the Kconfig.

Fixes #8815.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-07-10 11:25:32 +02:00
Joakim Andersson
dbc00ba374 Bluetooth: controller: Fix empty_pkt_us_get for 2M phy.
An empty packet on 2M phy is one more byte compared to 1M phy because
of the preamble.
The empty packet is then 11 bytes, which takes 44 us to transmit.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-07-03 22:47:45 -04:00
Ioannis Glaropoulos
0677812910 arch: arm: nrf: remove kernel_includes.h from nRF5x soc.h inclusions
This commit removes the inclusion of kernel_includes.h from
the nRF51 and nRF52 soc.h headers. This prevents from an
inclusion cycle formation on soc.h. In the wake of
kernel_includes.h removal, necessary header files have been
added in several source files to be able to compile Zephyr for
nRF5x SOCs.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-07-02 16:50:10 +02:00
Joakim Andersson
c6dea9e068 Bluetooth: Reorganize Kconfig options for BLE controller
Split meaning of BT_CTLR and BT_LL_SW, since they always are the same.
This way BT_CTLR means that there an controller implemented,
and BT_LL_SW refers to the specific implementation.
This allows alternative controller implementations.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-07-02 11:59:43 +02:00
Mariusz Skamra
8f6ebc5322 Bluetooth: controller: Fix LE Extended Scanner Filter Policy dependency
This adds dependency upon Observer role.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-28 22:16:31 +02:00
Johan Hedberg
387e91a76b Bluetooth: Mesh: cfg_srv: Ignore Prohibited element addresses
The Configuration Model specification states that all non-unicast
addresses given as the address of an element are Prohibited. The
correct action for Prohibited parameter values is to ignore the
message. As of writing this patch the PTS does not enforce this, but
it might in the future (as it does for many other Prohibited values).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-28 10:48:18 +03:00
Johan Hedberg
e69b735a5a Bluetooth: Mesh: Fix checking for model subscription address
Previously the code only checked if any of the models within an
element had the destination address in their subscription list. After
that check the specific model that the message was addressed to was
not verified to have that address in it's subscription list. This
patch fixes the problem.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-28 10:48:18 +03:00
Vinayak Kariappa Chettimada
cea4b31866 Bluetooth: controller: Add support for the nRF52810
The nRF52810 is a low-cost variant of the nRF52832, with a reduced set
of peripherals and memory. This commit adds Bluetooth controller support
for it.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-06-27 16:09:58 +02:00
Johan Hedberg
59bbab99a8 Bluetooth: Mesh: Fix cyclic rewriting to flash when restoring state
When we're reading the initial state from flash, calling the various
internal functions was leading to scheduling a rewrite to flash. Add
an extra parameter to the appropriate functions so they know when
they're called due to active configuration by a configuration client,
and when they're called due to restoring the state from flash.

This was not only wasting flash space, but also causing erroneous
behavior with the FCB settings backend if there was an intermediate
node reset operation stored, followed by a reprovisioning. The node
reset entries would cause them to be re-appened after the second valid
provisioning, leading to an incomplete node state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-27 15:54:40 +03:00
Johan Hedberg
f23e808ed0 Bluetooth: Mesh: Fix redundant model publication clearing
If the model publication is not enabled, we should return success,
however no other steps need to be done. This also helps avoid writing
redundant entries to flash when resetting a node that never had model
publication enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-27 15:54:40 +03:00
Johan Hedberg
310320c4d1 Bluetooth: Mesh: Fix initialization order during node reset
There were several things broken with the initialization order during
node reset:

 - The model->flags should not be touched since the writing to
   persistent storage happends through delayed work, and the flags
   need to be kept until that.

 - The unprovision() function should only be called at the very end of
   the reset procedure, since it calls model-specific init functions
   which may clear things which the earlier reset routines depend on.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-27 15:54:40 +03:00
Joakim Andersson
5e3c48f43c bluetooth: Make controller crypto functions optional
Provide flexibility in choosing to use the host defined crypto
functions or the ones provided by the controller

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-06-27 12:12:45 +02:00
Mariusz Skamra
698311d220 Bluetooth: att: Add Kconfig option to disable Multiple Read operation
This adds an Kconfig option to disable GATT Multiple Read support.
This GATT sub-procedure is optional and does not have to be supported.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra
becbfa2243 Bluetooth: att: Do not build Signed Write cmd handler if SMP disabled
This function does nothing actually if SMP is disabled.
This excludes att_signed_write_cmd handler from build if BT_SMP
is disabled or BT_SIGNING is disabled.

Note:
BT_SIGNING depends on BT_SMP

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra
76d0dd41f9 Bluetooth: hci_core: Exclude scan related code if non-observer
This chunks should be excluded from build if the target application
does not support neither observer not central role.
This helps to reduce the application image size that implement
Peripheral or Broadcaster role.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra
8a50160198 Bluetooth: Mesh: Depend Mesh upon Observer and Broadcaster roles
This adds dependency upon BT_BROADCASTER and BT_OBSERVER roles.
Those are necessary to implement Mesh device.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra
f3ba6e3806 Bluetooth: hci_core: Exclude conn creation related code for non-central
Don't build the code that is related to central role if the target
does not support connection creation.
This helps to reduce the application image size that implement
either Observer, Peripheral or Broadcaster role.

Note:
BT_CENTRAL implies BT_CONN and BT_OBSERVER

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Johan Hedberg
d41d9bd112 Bluetooth: Convert sample code to use the new bt_data_parse() API
Convert the shell and central_hr sample apps to use the newly
introduced bt_data_parse() API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-26 19:34:57 +03:00
Johan Hedberg
8818244959 Bluetooth: Add helper for parsing advertising data
It is quite easy to implement a buggy or security vulnerable
advertising data parser. Provide a helper for this purpose, which uses
the existing bt_data struct which is used for programming the local
advertising data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-26 19:34:57 +03:00
Vinayak Kariappa Chettimada
b35ed7e79c Bluetooth: Fix central from failing to start encryption
This fixes a regression introduced in commit 6af5d1cd1f
("Bluetooth: Compress bt_keys struct").

Instead of passing a value zero as the random number, the
value at the RAM address zero was being used by the start
encryption function call. It is now fixed by consistently
using byte-array to store EDiv and Rand values.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-22 18:03:43 +02:00
Alberto Escolar Piedras
15ae4fa314 Bluetooth: controller: Use nRFx functions for PPI reg with sideef
In the BLE controller, radio HAL, for the PPI registers:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras
c97645c884 Bluetooth: controller: Use nRFx functions for TIMER reg w sideeffects
In the BLE controller, radio HAL (TIMER registers):
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras
1c5bb49415 Bluetooth: controller: Use nRFx functions for CCM reg w sideeffects
In the BLE controller radio HAL, for the CCM registers:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.
(CCM part)

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras
88f0fbdc00 Bluetooth: controller: Use nRFx functions for RTC reg w sideeffects
In the Radio HAL, for the RADIO and RTC registers:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras
5f146e491e Bluetooth: controller: Use SOC series macro instead of the board macro
In the BLE controller radio HAL:
To avoid confusion, use SOC series macro instead of board macro.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras
1742972585 Bluetooth: controller: Use SOC series macro instead of board macro
In the BLE controller ECB HAL:
To avoid confusion, use SOC series macro instead of board macro.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras
347f32621a Bluetooth: controller: Use nRFx functions for ECB reg with sideeffect
In the BLE HAL for the ECB:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras
bc606d2220 Bluetooth: controller: Use nRFx functions for RTC reg with sideeffects
In the ble hal for the RTC:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Mariusz Skamra
48b7f236fa Bluetooth: Fix assertion condition in bt_gatt_discover
This fixes invalid assert condition.

As stated in Bluetooth Core v5.0 Vol 3 Part F
3.4.4.1 Read By Type Request &&
3.4.4.9 Read by Group Type Request
"The starting handle shall be less than or equal to the
ending handle."

3.4.3.1 Find Information Request &&
3.4.3.3 Find By Type Value Request
"Only attributes with attribute handles between and
including the Starting Handle parameter and the Ending
Handle parameter that match the requested attribute type
and the attribute value that have sufficient permissions
to allow reading will be returned."

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-15 15:47:04 +02:00
Sebastian Bøe
d62117e5b8 kconfig: Change how BT affects SYSTEM_WORKQUEUE_PRIORITY
Invalid configurations should be detected during configuration instead
of during compilation whenever possible.

This patch replaces a BUILD_ASSERT on CONFIG_SYSTEM_WORKQUEUE_PRIORITY
with what is intended to be an equivalent Kconfig restriction.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-06-14 16:49:50 -04:00
Vinayak Kariappa Chettimada
660c5c92c0 Bluetooth: controller: Remove include guards in internal files
Remove include guards in internal files; it is an agreed
convention to not have include guards in internal header
files in Bluetooth subsystem.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-14 17:11:42 +02:00
Johan Hedberg
b20aff2f80 Bluetooth: Introduce HCI driver quirks
Introduce a quirks field to the HCI driver struct, which can be used
to create exceptions in host behavior for non-standard or unusual
controller behavior. An initial quirk is added to prevent the host
from sending the HCI_Reset command (in which case the controller is
responsible for performing the reset).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-13 21:04:27 +02:00
Johan Hedberg
b1b1017178 Bluetooth: Export HCI command APIs through public hci.h header file
This is the simplest & cleanest way to make these APIs available for
drivers. We already have a public hci.h header file, so using it seems
most natural.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-13 21:04:27 +02:00
Sebastian Bøe
f8dc4b6b50 net: bluetooth: Enforce the minimum user_data size at Kconfig
Invalid configurations should be detected during configuration instead
of during compilation whenever possible.

This patch replaces a BUILD_ASSERT on CONFIG_NET_BUF_USER_DATA_SIZE
with what is intended to be an equivalent Kconfig restriction.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-06-13 15:13:18 +02:00
Johan Hedberg
e1b772479b Bluetooth: GATT: Fix notifications
Recent commits which made the choice of attribute to pass to
bt_gatt_notify() more flexible contained some unfortunate bugs in
handling the attributes and their values. In particular, both calls to
gatt_notify() would in certain circumstances pass the wrong handle
value. This should now be fixed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-12 17:54:59 +02:00
Vinayak Kariappa Chettimada
362a6b34c7 Bluetooth: controller: Fix to use max. tx power in DTM test mode
According to the Bluetooth Specification v5.0, Direct Test
Mode shall use maximum Tx power.

Fixed by adding nRF5x Radio HAL interfaces to get supported
maximum Tx power for SoC selected, and DTM testing sets the
Radio peripheral to use maximum Tx power.

Fixes #7243

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-12 13:22:10 +02:00
Vinayak Kariappa Chettimada
dc95e1ba05 Bluetooth: controller: Add Tx Power Kconfig option
Add support for changing the default Tx Power value using
Kconfig option.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-11 17:40:00 -04:00
Vinayak Kariappa Chettimada
edb2ad11f0 Bluetooth: controller: Remove redundant include of cmsis.h
Remove the redundant include of cmsis.h as soc.h already
includes it as necessary.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-11 17:30:29 -04:00
Johan Hedberg
7d9896575b Bluetooth: Add HCI User Channel driver for native POSIX port
Introduce a custom HCI driver for the native POSIX port, which opens a
HCI User Channel socket to the Linux kernel to gain access to a local
Bluetooth controller.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-11 17:14:43 -04:00
Luiz Augusto von Dentz
68de9d5d66 Bluetooth: Use Characteristic attribute whenever possible
With updates to bt_gatt_notify and bt_gatt_indicate it is now possible
to pass the Characteristic attribute instead of its value which makes
the code able to verify if attribute properties are set correctly.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-11 14:41:19 -04:00
Luiz Augusto von Dentz
679a0b395f Bluetooth: GATT: Allow Characterist to be used with bt_gatt_indicate
Since BT_GATT_CHARACTERISTIC now expands to 2 attributes it may be
confusing to use bt_gatt_indicate as that expects the Value attribute to
be given which is no longer visible, so this enables the user to use
the Characteristic attribute in addition to its value.

Fixes #8231

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-11 14:41:19 -04:00
Luiz Augusto von Dentz
c3edc82fe7 Bluetooth: GATT: Allow Characterist to be used with bt_gatt_notify
Since BT_GATT_CHARACTERISTIC now expands to 2 attributes it may be
confusing to use bt_gatt_notify as that expects the Value attribute to
be given which is no longer visible, so this enables the user to use
the Characteristic attribute in addition to its value.

Fixes #8231

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-11 14:41:19 -04:00
Luiz Augusto von Dentz
1218648ed1 Bluetooth: ATT: Fix clearing context at disconnect
When att_disconnected is called a thread may be waiting for the tx_sem
but that is memset to 0, furthermore there exists a flag
ATT_DISCONNECTED to indicate the context is no longer valid so instead
move memset to bt_att_accept so it is cleared when it is about to be
reused.

Fixes #8083

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-06 09:38:37 -04:00
Johan Hedberg
ed5fb3ff37 Bluetooth: Mesh: Fix (re)transmit interval handling
The adv_send() function was incorrectly decoding the 5-bit value (it
was using it directly as milliseconds), which effectively lead to the
code always picking the controller's minimum supported interval.

Fix this issue, but do it by simplifying the (re)transmission state
tracking so that the state is always stored in the original "packed"
8-bit value, where 5 bits are reserved for the interval, and 3 for the
count.

Fixes #7972

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-05 19:15:14 +02:00
Johan Hedberg
ae829b269d Bluetooth: Fix unchecked settings value lengths
We should check for valid lengths, not just because flash may have
become corrupted, but also because this fixes coverity errors, such as
CID 186030.

Fixes #7739

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-04 17:05:07 -04:00
Carles Cufi
a59f544fb4 bluetooth: controller: Handle non-priority events correctly
In certain cases the response to a command can come in the form of a
non-priority event. This is the case of LE Create Connection Cancel,
which generates a Command Complete and then an LE (Enh) Connection
Complete. Take this case (and other future ones) into account by calling
the correct Host recv function.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-05-25 17:25:41 +02:00
Johan Hedberg
c4b0f1c5b4 Bluetooth: Mesh: Fix build error when LPN is not enabled
Some versions of gcc do not seem to compile out the inaccessible code
in this case and instead give the following error:

subsys/bluetooth/host/mesh/transport.c:419: undefined reference to
`bt_mesh_lpn_poll'

This happens at least when building samples/bluetooth/mesh for
native_posix on Fedora 28.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-25 10:53:46 +03:00
Carles Cufi
6f534e4551 drivers: entropy: nrf5: Implement standard ISR-specific call
Implement the new entropy_get_entropy_isr() function to allow the kernel
to collect entropy before the scheduler and kernel data structures are
ready. Switch to an nrf-specific version for high-performance
requirements in the BLE Link Layer.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-05-24 15:13:13 -07:00
Johan Hedberg
8d1f67c605 Bluetooth: Remove references to non-existing Kconfig symbols
Remove non-existent Kconfig symbol references. An additional (but
related) change is the removal of all persistent storage symbols from
the Arduino 101 Bluetooth shell app, since BT_STORAGE no longer
exists.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-23 16:57:59 -04:00
Johan Hedberg
20a2b7a79d Bluetooth: Mesh: Fix reference to CONFIG_BT_MESH_FRIEND
The Kconfig symbols use BT_* and not BLUETOOTH_*.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-23 16:57:59 -04:00
David B. Kinder
44383a394b doc: fix misspellings in Kconfig files
Found some misspellings missed during normal reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-05-23 16:57:20 -04:00
Joakim Andersson
81b964b619 doc: Update description of BT_RECV_IS_RX_THREAD.
Clarify why this option is needed and which restrictions it has if
disabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-05-22 13:30:45 -04:00
Johan Hedberg
df4220b213 Bluetooth: L2CAP: Add support for dynamically allocated PSM values
The Bluetooth core specification splits the valid LE L2CAP PSM range
into two subranges:

 - Standard, SIG-assigned fixed PSM values in the range 0x0001-0x007f
 - Dynamic, allocated at runtime in the range 0x0080-0x00ff

Previously the bt_l2cap_server_register() API was assuming that the
app would always decide the PSM, which effectively made it impossible
to have collision-free dynamic PSMs. This patch extends the
implementation so that if server->psm is 0, then the stack will look
for a free PSM from the dynamic range and take it into use.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-18 12:39:58 +03:00
Johan Hedberg
20ea1b86b9 Bluetooth: Mesh: Remove redundant ivu_unknown variable
Instead of having an ivu_unknown variable to track when we can ignore
the 96-hour minimum duration requirement, simply set the duration to
the minimum (96 hours) in the places where ivu_unknown would have been
1.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-18 12:39:41 +03:00
Johan Hedberg
2b73c97d68 Bluetooth: Mesh: Fix IV Update duration tracking
When the IV Update state enters Normal operation or IV Update in
Progress, we need to keep track of how many hours has passed in the
state, since the specification requires us to remain in the state at
least for 96 hours (Update in Progress has an additional upper limit
of 144 hours).

In order to fulfil the above requirement, even if the node might be
powered off once in a while, we need to store persistently how many
hours the node has been in the state. This doesn't necessarily need to
happen every hour (thanks to the flexible duration range). The exact
cadence will depend a lot on the ways that the node will be used and
what kind of power source it has.

Since there is no single optimal answer, this patch adds a new
configuration option, which allows specifying a divider, i.e. how many
intervals the 96 hour minimum gets split into. After each interval the
duration that the node has been in the current state gets stored to
flash. E.g. the default value of 4 means that the state is saved every
24 hours (96 / 4).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-17 17:30:03 +03:00
Johan Hedberg
cfb34d2b80 Bluetooth: Mesh: shell: Add persistent storage support
Add persistent storage support to the mesh shell module and app.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-16 18:41:23 +03:00
Johan Hedberg
a3c1b3dbcc Bluetooth: Mesh: Expose bt_mesh_is_provisioned() publicly
After introducing persistent storage, it's useful for an app to check
if the node has been provisioned or not.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-16 18:00:19 +03:00
Ramakrishna Pallala
0fb9ea0304 subsys: bluetooth: Remove deprcated k_call_stacks_analyze API
Replace deprecated k_call_stacks_analyze() API with
k_thread_foreach() API.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-15 13:43:00 +03:00
Luiz Augusto von Dentz
1b038f2941 Bluetooth: GATT: Make BT_GATT_CHARACTERISTIC declare its value
This ensures the every characteristic has a value attribute declared
with the same UUID since the old macro did not declare the value the
application would normally have to declare one itself using a different
UUID which is not allowed.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-05-14 18:51:22 +03:00
Johan Hedberg
4f4afce5b0 Bluetooth: Remove unused rx_prio_queue
The rx_prio_queue k_fifo object has not been used for anything for a
really long time. The use for it was originally removed by the following
commit:

commit ad475d863a
Author: Szymon Janc <ext.szymon.janc@tieto.com>
Date:   Fri Apr 22 11:36:04 2016 +0200

    Bluetooth: Remove RX priority fiber

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-12 21:28:09 +03:00
Johan Hedberg
88dfd399f4 Bluetooth: Mesh: Remove sequence number from bt_mesh_provision()
The sequence number was acting as a stop-gap for missing persistent
storage. Now that we have the settings support in place it's no longer
needed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
e240421496 Bluetooth: Mesh: Fix sequence number restoring
The logic for restoring the sequence number was flawed in that it
would not always cause an incremented sequence write upon the
transmission of the first packet. The reason the code didn't work is
that it assumed the stored value was a multiple of SEQ_STORE_RATE,
however since the sequence number is stored in a deferred fashion
that's not always true.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
53c85cf8bf Bluetooth: Mesh: Fix updating RPL for locally originated messages
We can implicitly trust locally originated messages, so there's no
need to burden the RPL with them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
59239032f6 Bluetooth: Mesh: Support for storing common configuration states
Add support for storing the remaining configuration server model
states (all of which are one byte values). The states are stored under
a single settings key bt/mesh/Cfg.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
44bd56877b Bluetooth: Mesh: Support for storing heartbeat publication persistently
Add support for storing the heartbeat publication persistently. The
information is only stored as "publish indefinitely" or as "periodic
publishing disabled" since we can't know for how long the node is
powered off. The information is stored under the settings key
bt/mesh/HBPub.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
efb68ca2da Bluetooth: Mesh: Support for storing model publication persistently
Add support for storing the model publication information
persistently. The addresses are stored under the settings key
bt/mesh/s/<mod id>/pub for SIG models and bt/mesh/v/<mod id>/pub for
vendor models.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
dde2db5626 Bluetooth: Mesh: Support for storing model subscriptions persistently
Add support for storing the subscribed group addresses for each model
persistently. The addresses are stored under the settings key
bt/mesh/s/<mod id>/sub for SIG models and bt/mesh/v/<mod id>/sub for
vendor models.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
c3d5a0da62 Bluetooth: Mesh: Support for storing model bindings persistently
Add support for storing the bound App Keys for each model
persistently. The bindings are stored under the settings key
bt/mesh/s/<mod id>/bind for SIG models and bt/mesh/v/<mod id>/bind for
vendor models.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
8703ffad23 Bluetooth: Mesh: Redesign element and storage info for models
Keeping the model struct same sized, change the element pointer to two
indexes, and add a flags member that will be used to track pending
storage actions.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
b7078e1487 Bluetooth: Mesh: Perform storage clearing also through delayed work
In order not to have a Node Reset consume more stack than other
operations, also perform the related storage writes through the same
delayed work as all other storage updates.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
9e2189c4c1 Bluetooth: Mesh: Introduce generic storage timer
Instead of having an RPL-specific storage timer, introduce a generic
one that'll eventually be used for all persistent storage.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg
ace198142e Bluetooth: Mesh: Convert RPL storage timer into a generic one
To reduce stack consumption, and to avoid blocking the CPU during
network activity, prepare for a generic timer that can be used for
most (possibly all) mesh storage values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Luiz Augusto von Dentz
f6a687c0ce Bluetooth: GATT: Add support to persistent CCC config
This makes use of bt_settings to store CCC configs for bonded devices.

Fixes #7073

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-05-11 14:55:42 +03:00
Johan Hedberg
c1c5f3d9a3 Bluetooth: Mesh: Expose destination address in bt_mesh_msg_ctx
There are valid use cases where the model layer must know the true
destination address. So far only the fact that it was one of the
addresses that the model subscribes to (its element's unicast
included) has been knowable.

Solve the issue by moving the destination address from the internal
net_rx context to the public bt_mesh_msg_ctx struct.

Fixes #7453

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 13:57:43 +03:00
Johan Hedberg
5b01cb1a46 Bluetooth: Introduce new bt_set_id_addr() API
There are certain use cases where the application needs to be able to
explicitly set a specific identity address. This was previously
possible using the bt_storage API, however now that it's gone another
solution is needed.

This patch adds a ne bt_set_id_addr() API which the application can
use to set a specific identity address before calling bt_enable().

Fixes #7434

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-10 22:39:04 +02:00
Johan Hedberg
31afd18977 Bluetooth: Mesh: Add support for clearing persistent network storage
Add support for clearing all data that's currently supported to be
persistently stored.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
cc3830f8ed Bluetooth: Mesh: Fix resetting configuration model state
Instead of manually iterating all app keys and net keys, use the
bt_mesh_subnet_del() helper on all subnets. This will also clear any
app keys, and ensures that persistent storage is cleared as well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
be7fe55b82 Bluetooth: Mesh: Introduce measures to avoid too frequent flash writes
Both the local sequence number as well as the Replay Protection List
(RPL) are states that may potentially change very often. In order not
to wear out the flash with these updates it makes sense to try to
avoid too frequent writes.

For the local sequence number a simple solution is not to write the
number on every increment. This patch introduces a new Kconfig option
to define after how many increments the sequence number gets written.
When the stack gets initialized it automatically adds the configured
number to the last stored one, thereby guaranteeing that the node
starts off with a number that's larger than the last used one.

The RPL is more problematic, since in principle it needs to be updated
every single time that we receive and process a message. Especially
security sentitive nodes will want this stored immediately to flash.
To give some use-case dependent flexibility, this patch introduces a
new Kconfig option to specify a timeout after which the RPL gets
written to flash.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
43c7ef3959 Bluetooth: Mesh: Move network startup operations to common function
These are needed both for bt_mesh_provision() as well as persistent
storage-based network creation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
3f30d12ce5 Bluetooth: Mesh: Remove redundant 'provisioned' variable
This variable is both redundant as well as problematic when it comes
to adding persistent-storage-based provisioning information, which
will not come through main.c or the bt_mesh_provision() API. Just
remove it and use bt_mesh.valid which serves the same purpose in
practice.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
1c846651db Bluetooth: Mesh: Add storage APIs for core network values
Add APIs for storing core network values, such as Net and App Keys, IV
Index, Sequence number, RPL, etc.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
9540f7d52d Bluetooth: Mesh: Add skeleton for persistent storage
Add initial skeleton for doing settings-based persistent storage for
the mesh network state. This patch only includes restoring some core
network state such as IV Index, Sequence number, Net Keys, App Keys
and the Replay Protection list. The remaining state, and actually
storing the state, is left for follow-up patches.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
2be496a03b Bluetooth: Mesh: Create dedicated helper for incrementing seq
The sequence number is incremented from several different places in
the stack. The way it was done was potentially race condition prone,
and was also problematic from the perspective of updating the
sequence number in persistent storage. Create a dedicated helper for
incrementing the sequence number (solves the race) which can in later
patches be used to add the persistent storage support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
ca10b6bc94 Bluetooth: Mesh: Remove redundant initialization
This for loop runs inside an "if (!sub)" branch, so explicitly setting
sub to NULL in the loop is redundant.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
f7e780a719 Bluetooth: Mesh: Increase visibility of net & app key helpers
These app key and net key (subnet) helpers will soon be needed to be
called from the persistent storage code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
10fabcd04f Bluetooth: Mesh: Move IV Update defines to net.h
These will soon be needed from other places, e.g. the persistent
storage support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg
a29554360a Bluetooth: shell: Add settings support
Enable settings and increase the system workqueue size to deal with
the stack usage. This also makes it possible to test unpairing support
with the shell's 'clear' command.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg
6af5d1cd1f Bluetooth: Compress bt_keys struct
There's a bit of unnecessary space in the bt_keys struct. Re-design
some fields for a more compact format, which is particularly helpful
now that the struct gets stored as-is to flash through the settings
API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg
f36ea83628 Bluetooth: Add support for persistent pairing keys storage
Integrate the bt_keys submodule with bt_settings. Add a new
bt_keys_store() API to write keys to flash, and extend the existing
bt_keys_clear() to remove the keys from flash.

Along with this, add some helpers for genrating settings key values
containing a bluetooth address, as well as for decoding them to get
the binary bt_addr_le_t.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg
470349c25a Bluetooth: settings: Add support for per-submodule handlers
Add a new linker section for a list of submodule settings handlers,
and iterate the list from the various settings callbacks.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg
d22b7c9f2d Bluetooth: Remove bt_storage API
The same functionality is now supported by the settings-based
solution, so remove bt_storage out of the way. There were stubs in
bt_storage to handle per-peer information (e.g. pairing keys) but this
was never actually implemented in full. The next step is to add this
support to the settings-based solution.

Leave the code for generating temporary IRK and identity address in
case BT_SETTINGS is not enabled. Also leave the code for using vendor
HCI to read the identity address, in which case the settings
implementation will not touch it.

Introduce a new bt_unpair() API to replace the removed
bt_storage_clear(), since the latter was actually doing more than just
storage management: it was also handling runtime storage of pairing
information. Later, the bt_unpair() implementation will be extended to
clear settings-based pairing storage.

There is one feature that the bt shell module looses: the ability to
give a specific identity address to the "init" command as a parameter.
We might look later in the future if this is really needed, and add a
separate API for this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg
b997a283f7 Bluetooth: Introduce skeleton for settings-based storage
Introduce a basic skeleton for peristent storage based on the settings
subsystem. Also enable support for this to the peripheral sample
application, so the new code gets exersized by CI. For now, the
implementation provides the same level support as the bt_storage API
ever did, i.e. for the identity address and the IRK.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg
8dd37fa79a Bluetooth: Mesh: Fix sequence number in Friend queue
The code was updating net_rx->seq to make sure sdu_recv() gets the
right sequence number (seq_auth for segmented messages), however later
net_rx->seq was also used for enqueuing to the Friend Queue, causing
the queued messages to have the wrong value.

To fix this, don't update net_rx->seq, rather pass an explicit
sequence number value to sdu_recv(), which is just net_rx->seq for
unsegmented messages, and seq_auth for segmented messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-03 10:01:00 +01:00
Johan Hedberg
6a71a69f8d Bluetooth: GATT: Fix CCC handling
The 'valid' member of struct bt_gatt_ccc_cfg was redundant, since
setting 'peer' to BT_ADDR_LE_ANY does the same job. What's worse, the
handling of 'valid' was also buggy in that some places looking for
valid CCC structs only matched the address, meaning it might yield a
positive match for invalid entries.

Fix these issues by removing the 'valid' struct member, and solely
using the 'peer' member to identify valid entries. Also simplify the
code by acknowledging that no CCC entry is essentially the same as the
value '0' written to CCC.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-03 09:53:16 +01:00
Johan Hedberg
6b11106440 Bluetooth: Mesh: Fix enabling Node Identity advertising
The bt_mesh_provision() call results in the provisioning link state
being cleared, so link.conn will become NULL. Add code to store the
information of whether PB-GATT was used and use this information after
the call instead of relying on link.conn anymore at this point.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-02 15:45:16 +01:00
Johan Hedberg
aa67a4c55a Bluetooth: Mesh: Remove redundant branch for IV Update
The condition 'iv_index != bt_mesh.iv_index + 1' is already caught by
the earlier conditions in this branch.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 12:18:31 +03:00
Johan Hedberg
c7c5829ba6 Bluetooth: Mesh: Fix missing IVU normal mode timer when provisioning
If the network is in IV Update In Progress state when we get
provisioned we should set a timer so we eventually transition back to
Normal mode (otherwise we may end up in IVU In Progress indefinitely).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 12:18:31 +03:00
Johan Hedberg
2a896cc6c4 Bluetooth: Mesh: Fix IV Update tests when duration is unknown
When we get provisioned we can't know how long the network has been in
the current IV Update state. Introduce a special value for
bt_mesh.last_update to indicate that we don't know the duration.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 12:18:31 +03:00
Vinayak Kariappa Chettimada
6c6d98bc4e Bluetooth: controller: Use hal/ticker.h to abstract SoC specifics
Introduce hal/ticker.h to abstract out SoC specific
implementations and move any conditional compilations to
include header files here.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-04-09 10:34:04 +02:00
Johan Hedberg
d6a549ceba Bluetooth: Mesh: Fix Node Identity advertising with PB-ADV
The Node Identity advertising should only be automatically enabled
when provisioning happened over PB-GATT, but not when it happened over
PB-ADV. Move the enabling of Node Identity to the provisioning code,
where we know the bearer that was used (this information does not get
passed to the bt_mesh_provision function).

Fixes #6338

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-09 11:13:10 +03:00
Johan Hedberg
b8042ea9ce Bluetooth: Mesh: Fix possible NULL dereferences in client models
There's a small but real chance of a race-condition when sending
messages to the local node (through the local network interface) that
expected parameters will be NULL in the message handles. Add
appropriate NULL checks for them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-05 10:08:18 +03:00
Mariusz Skamra
276d17df04 Bluetooth: L2CAP: Update LE specific connection result values
This updates result values for LE Credit Based Connection
Response according to Table 4.20 from Core 5.0 Vol 3 Part A.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-04-03 14:30:10 +03:00
Mariusz Skamra
d458f1e7a2 Bluetooth: L2CAP: Use BR definition on connection success
This fixes BR L2CAP to use BT_L2CAP_BR_SUCCESS.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-04-03 14:30:10 +03:00
Ulf Magnusson
93689bdc80 kconfig: Remove no-op selects of choice symbols
Selecting a choice symbol is always a no-op, and the latest version of
Kconfiglib prints a warning. This commit removes all selects of choice
symbols, which might make the Kconfig files a bit clearer and gets rid
of the warnings.

This is just a dumb removal. I did not try to guess the intent of each
select.

Fixes #6849

Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
2018-03-29 08:57:39 -04:00
Vinayak Kariappa Chettimada
4c49df98e5 Bluetooth: controller: Fix missing device filter clear
Fix missing device filter clearing for cases where whitelist
was used and then in subsequent adv/scan enable it was
unused.

This fixes an assert in ll_filter.c at line 248.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-26 16:44:35 +02:00
David Maitland
f77469a3bb Bluetooth: controller: Refactor to use max macro
Cleaned up the use of conditional statements to use the max macro.

Fixes #6230.

Signed-off-by: David Maitland <hello@davidmaitland.me>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-25 11:33:51 +02:00
Johan Hedberg
bf8050b016 Bluetooth: Mesh: Introduce debug option to use identity address
Add a Kconfig debug option to enable using the local identity address
for advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-21 18:11:49 +02:00
Johan Hedberg
ac133268a5 Bluetooth: Remove 'own_addr' from advertising parameters
This was originally added as a work-around to avoid the heavy stack
consumption of the TinyCrypt PRNG when generating NRPAs. This is
no-longer an issue, and there are in fact no (in-tree) users of this.
Remove it before it gains any wider users, since it was in many ways a
hack/work-around to begin with.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-21 18:11:49 +02:00
Johan Hedberg
7d4514a8b0 Bluetooth: Add option to force using identity address for advertising
In some cases the app may want to force using the identity address
regardless of privacy support or what type of advertising is done.
Provide such an option in bt_le_adv_param.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-21 18:11:49 +02:00
Carles Cufi
8aa9a37902 drivers: flash: nrf: Rename nrf5 to nrf
With upcoming ICs that are not in the nRF5x family, rename the flash
driver and all its dependencies from nrf5 to nrf.

Should also fix the issue introduced by f49150cab6 which broke the
assignment of the flash device due to a partial rename.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-20 20:07:09 +01:00
Carles Cufi
f49150cab6 arch: arm: nrf: Rename nrf5 SoC Family to nrf
Upcoming Nordic ICs that share many of the peripherals and architecture
with the currently supported nRF5x ones are no longer part of the nRF5
family. In order to accomodate that, rename the SoC family from nrf5 to
nrf, so that it can contain all of the members of the wider Nordic
family.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-20 11:57:14 +01:00
Johan Hedberg
0cee4ed747 Bluetooth: Mesh: cfg_cli: Fix possible race condition
If the thread that sends the configuration messages has low priority
and is sending to the local node (a common use case currently) it's
possible that the response arrives before the cli->op_* state
variables are set, resulting in the message never getting properly
processed and the client API call timing out.

Split the initialization into a separete cli_prepare() call and add a
cli_reset() to clean up the variables in case of premature completion
of the client operation (e.g. due to message sending failure).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-20 09:22:42 +02:00
Johan Hedberg
7fd4184d2e Bluetooth: Mesh: cfg_cli: Fix trying to write a NULL pointer
It's not always guaranteed that param->status will be non-NULL,
especially not after a subsequent patch to fix a race condition with
the response waiting.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-20 09:22:42 +02:00
Carles Cufi
fb3387a490 Bluetooth: Remove rand driver and use entropy instead
After porting the rand driver to drivers/entropy, replace the usage of
the old, Buetooth-specific driver with the generic entropy one.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-14 16:47:50 +01:00
Kumar Gala
d68b6a901a subsys: fs: Fix fs_file_t and fs_dir_t usage
With the introduce of VFS the typedef for fs_file_t & fs_dir_t don't
exist anymore so we need to use 'struct fs_dir_t' or 'struct fs_file_t'.
Fix up some places that got missed in the VFS conversion.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-03-13 09:47:58 -05:00
Carles Cufi
50693c0fcd Bluetooth: controller: Generate LE Conn Complete on cancellation
When using the LE Create Connection Cancel command, the controller is
supposed to return a Command Complete first and then an LE Connection
Complete Event after. Since the Link Layer does not generate an event in
this case emulate the behavior in the HCI layer instead.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-07 12:49:47 +01:00
Mariusz Skamra
cfc79d1669 Bluetooth: Fix available LPN groups count
This fixes the LPN_GROUPS define.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-03-06 18:41:17 +01:00
Luiz Augusto von Dentz
9c92609a66 Bluetooth: GATT: Fix possible crash while resubscribing
When reconnecting the code will attempt to recover the subscriptions
but it was not setting any callback causing the bt_att_req.func to be
NULL.

Fixes #5982

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-03-06 17:06:22 +01:00
Mariusz Skamra
b7ac9770c9 Bluetooth: Add missing check prior sending LE Set Privacy Mode cmd
This check is needed to not send command that is not supported
by controller. LE Set Privacy Mode command was introduced in
Bluetooth 5.0 so that it will fail on older controllers.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-03-06 08:54:58 +01:00
Johan Hedberg
b9588d8eb6 Bluetooth: Mesh: Switch to using Linux Foundation Company ID
The Linux Foundation now has an assigned Company Identifier, so switch
to using that.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-05 19:54:21 -05:00
Mariusz Skamra
777f9c8cd0 Bluetooth: Workaround privacy feature issue
This fixes intercompatibility issues with controllers supporting
privacy feature.
Core Spec requires to use network privacy mode as a default when
peer device provides its IRK during bonding when LL Privacy is used,
which is the case for Zephyr. We've seen devices including PTS
which exchanges it's IRK but is not aware about network privacy
mode. This results in Zephyr not able do be reconnect to such bonded
devices.
This workaround sets device privacy mode to be able to reconnect
to such devices.

Fixes #4989
Fixes #5486

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-03-02 17:56:37 +01:00
Carles Cufi
d4d2581b76 Bluetooth: controller: Default to the LF Company ID
The Linux Foundation has been assigned a Company Identifier, and with it
a means of identifying Zephyr over the air. Default to the LF Company
Identifier, which can be overridden by silicon vendors.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-02 17:27:35 +01:00
Vinayak Kariappa Chettimada
ac34131f42 Bluetooth: controller: Fix missing advDelay in Low Duty Cycle Directed
Fixed the controller implementation for the missing advDelay
for connectable directed advertising events used in a low
duty cycle mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-02 16:34:39 +01:00
Alberto Escolar Piedras
4484e9efbd bluetooth: controller: nrf5: fix to IC-specific reset function
Fix of 80210198ad so it does
not cause a segfault in simulated boards

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-03-02 16:33:52 +01:00
Alberto Escolar Piedras
cf07caa3c9 bluetooth: controller: last radio hal changes for simulation
All sideeffects for simulation are there now, including CCM part

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-28 19:56:16 +01:00
Carles Cufi
80210198ad bluetooth: controller: nrf5: Add IC-specific reset function
In order to address anomalies 102, 106 and 107 in nRF52, add a generic
hal_radio_reset() that does additional processing when required by a
particular IC or IC family. Implement the fix for the nRF52.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-02-24 12:33:51 +01:00
Johan Hedberg
1e159de848 Bluetooth: Mesh: Use a single transmission from Friend to LPN
As per TSE 10009 the TS will enforce that a Friend ever only uses a
single transmission when sending packets to an LPN. Make sure that our
implementation follows this.

https://www.bluetooth.org/tse/errata_view.cfm?errata_id=10009

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-20 17:22:23 +02:00
Vinayak Kariappa Chettimada
b55e7b784c Bluetooth: controller: Use RADIO_TIES_US to define inter event space
Use RADIO_TIES_US to define minimum inter event space
between concurrent master and slave roles below which it
will be detected as a probable drift towards each other
leading to them overlapping on each other.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-20 15:34:55 +01:00
Vinayak Kariappa Chettimada
7fa2c4dfac Bluetooth: controller: Add missing HCI supp. cmd bits for PHY Update
Added missing HCI Supported Commands bit fields for PHY
Update feature. Also, refactored with missing conditional
compilation for other bit fields.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 11:46:21 +01:00
Vinayak Kariappa Chettimada
ae03e35d6c Bluetooth: controller: Fix incorrect master role scheduling
Revert incorrect calculation introduced in
commit ec5a787da2 ("Bluetooth: controller: Fix multiple
master role event scheduling") and revert a related
incorrect fix in commit a02606cbf9 ("Bluetooth:
controller: Fix missing ticks to us conversion").

Fixes the controller assert in ctrl.c line number 1477. A
64-bit arithmetic took ~35 us in Radio ISR for nRF51 causing
the ISR to take too much time before packet buffer could be
set.

Also, fixed master scheduling by correctly accounting for
the jitter between each master event.

Relates to: #5486

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada
067ac68f0b Bluetooth: controller: Fix XTAL_ADVANCED threshold detection
Fix incorrect calculation of unreserved timespace which
should take into account the ticks_slot of current event,
and compensation for any reduced prepare in the current
event as well as in the next event.

This regression relates to the commit ad7c9d3d76
("Bluetooth: controller: Improved continuous scanning")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada
1433475b29 Bluetooth: controller: Define HAL_TIMER_SIGN_BIT
Define a macro HAL_TIMER_SIGN_BIT to correspond to the most
significant bit support by counter hardware used by ticker.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada
8f5e96a1b7 Bluetooth: controller: Use XON_BITMASK instead of BIT(31)
Use XON_BITMASK define instead of raw BIT(31) or bit shift
operations in code to represent use of reduced prepared by
an event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada
1bda83af1c Bluetooth: controller: Fix to use random CRC init value
Fixed controller implementation to use random CRC init value.

Fixes #6204.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-15 21:15:21 +01:00
Vinayak Kariappa Chettimada
499baff333 Bluetooth: controller: Reuse safer bt_rand in thread call path
Reuse the thread safe bt_rand() interface in the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-15 21:15:21 +01:00
Johan Hedberg
294c68d087 Bluetooth: SMP: Send Pairing failed if there's no key space
If there's no more room to store new pairings, send a proper error
instead of letting the SMP timeout expire.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-15 20:54:50 +02:00
Johan Hedberg
c9097a9346 Bluetooth: Mesh: Declare seg_rx_buf_data as __noinit
This is a fairly large buffer, and there's no need to initialize it to
zeroes at boottime.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-15 10:58:24 +02:00
Johan Hedberg
05884c7f18 Bluetooth: Mesh: Split proxy client buffer payload into separate array
This makes things slightly cleaner, and we don't need to rely on the
deprecated net_buf_simple_init() API (which was a bit hackish for
these custom-constructed net_buf_simple objects anyway).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-15 10:58:24 +02:00
Mariusz Skamra
daa8040e2f Bluetooth: Mesh: Ignore segments of cancelled message
This fixes the issue when after incomplete timer expiration
host sent ACK.
The host failed in two cases:
1. Sending ACK right after the incomplete timer expiration;
2. Sending ACK from new RX context. Now, seq_auth of cancelled
message is not cleaned on RX reset, so segments of cancelled message
will be discarded when resend.

According to the Mesh Profile v1.0
"When the incomplete timer expires, the lower transport layer
shall consider that the message being received has failed and
cancel the acknowledgment timer. Any segment of a canceled
message shall be ignored."

Fixes #6023

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-02-14 17:53:37 +02:00
Johan Hedberg
6b3d2935f4 Bluetooth: Mesh: Fix sending Provisioning Failed for PB-GATT
In the case of an unexpected PDU we need to send the right response.
This was already taken care of for PB-ADV, but not for PB-GATT.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-14 11:43:34 +02:00
Johan Hedberg
4f47bc3611 Bluetooth: Mesh: Resend Link Acknowledgment when necessary
The Provisioner might have missed our earlier Link Acknowledgement, so
if we receive another one with matching Link ID and link.expect state,
simply send another acknowledgement.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-14 11:43:34 +02:00
Johan Hedberg
27e1c4fbb2 Bluetooth: Mesh: Fix handling of failed transmissions
When sending a segmented message, the state could get stuck if the
advertising bearer fails in transmitting and we don't detect that it
happened. Add a send_start callback for all packets so we can always
know if sending fails.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-14 11:43:34 +02:00
Johan Hedberg
6379da2a09 Bluetooth: Mesh: Fix NULL pointer access with PB-ADV
When both PB-ADV and PB-GATT are enabled, the PB-ADV code (prov.c)
uses the bt_mesh_proxy_get_buf() API to get a net_buf_simple buffer.
Unfortunately this function also suffers from the same issue that was
fixed by commit 2b273444c1.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-14 11:43:34 +02:00
Johan Hedberg
2b273444c1 Bluetooth: Mesh: Fix NULL pointer access with GATT Proxy
The conversion to the new net_buf_simple API was done incorrectly
here. The buffer initialization should use net_buf_simple_init()
instead of net_buf_simple_reset(), so that buf->__buf gets properly
initialized (and not left pointing at NULL).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-13 15:03:34 +02:00
Johan Hedberg
abc20e7eae Bluetooth: Introduce dedicated TX fragment pool
There's a risk of a deadlock if we use the same pool for ACL fragments
as we use for general ACL TX buffers: all TX buffers are queued up,
and we try to segment one of them, a segment buffer will never become
available. To work around this risk, introduce a dedicated fragment
pool.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-13 14:49:52 +02:00
Vinayak Kariappa Chettimada
4c123a5162 Bluetooth: controller: Refactor ticker integration into hal
Refactor ticker execution context dependency out into HAL
folder. This decouples ticker from mayfly, enabling porting
towards a more tasklet (if and when kernel gets the support)
style execution contexts type implementation support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-13 13:26:37 +01:00
Johan Hedberg
ac1360f0a7 Bluetooth: Mesh: Convert to new net_buf_simple APIs
Convert the mesh code to use the new net_buf_siple APIs. This has the
benefit of saving 4 bytes off the stack due to the not needed pointer.
Also update the publication context helpers to map to the new
net_buf_simple API in an intuitive way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-13 14:00:08 +02:00
Luiz Augusto von Dentz
800bfaf9a7 Bluetooth: UUID: Remove macros defining 16 bit values
Application should normally declare a bt_uuid with proper type and then
use bt_uuid_cmp.

Fixes #5162

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-02-13 13:33:48 +02:00
Vinayak Kariappa Chettimada
4eedb5067f Bluetooth: mesh: Account for scan window delaying adv events
New advertising started while scanning is already enabled
would delay the first advertisement event until the end of
the current overlapping scan window in the Zephyr native BLE
controller implementation. Hence, consider this scan window
duration when calculating the advertising stop.

Relates to: #6083

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada
af13d6d581 Bluetooth: controller: Fix soft latencies in periodic ticker
Fix, add the missing code for the removal of any accumulated
soft latencies or negative drift ticks when scheduling next
interval expiry with added laziness.

Typically a first interval would accumulate soft latencies
and this has to be removed if the interval is rescheduled
with any added laziness (scheduled to the next soft real
time interval).

Example, scan windows block any new scheduling until the end
of the window, adding latencies to any soft real time ticker
expiry which should try to execute as early as possible after
the scan window.

Fixes: #6083

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada
57e49b1f03 Bluetooth: controller: Refactor BT_CTLR_ADV_INDICATION feature
Refactor BT_CTLR_ADV_INDICATION feature by moving the
implementation closer to the implementation that is closing
the advertisement event so that in the future new members
can be added as necessary (example, advertised channels).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada
baf05409f8 Bluetooth: controller: Fix BT_CTLR_XTAL_ADVANCED cond. compilation
Fix compile warnings when BT_CTLR_XTAL_ADVANCED Kconfig
option is disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Johan Hedberg
5ded8d8d49 Bluetooth: Remove useless BT_L2CAP_TX_USER_DATA_SIZE Kconfig variable
No one was setting this to any other value than its default, which
happens to be the same as BT_BUF_USER_DATA_MIN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-12 09:48:32 +02:00
Johan Hedberg
0ad6dbd80d Bluetooth: Move HCI command buffer user data into separate array
The HCI command buffers are the only ones with more than 4 bytes of
required user data. Move the user data into a separate array and do
the mapping with the help of net_buf_id(). After this, it will be
possible to reduce the default net_buf user data size from 8 to 4.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-12 09:48:32 +02:00
Johan Hedberg
a7518ba30f Bluetooth: Mesh: Fix coverity warning with unchecked error return
This fixes Coverity CID 182769.

Fixes #6102

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-11 21:38:02 +02:00
Vinayak Kariappa Chettimada
a152109eb1 Bluetooth: controller: Fix nRF52840 radio timings for Coded PHY
Fix incorrect radio timing for Tx chain delay for S2 and S8
coding. Regression introduced  in commit 55d3ce111c
("Bluetooth: controller: Refactoring nRF5 radio driver").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-11 20:33:02 +01:00
Johan Hedberg
d5f27b70cc Bluetooth: Remove bogus return statements for BR/EDR connections
Having these in the beginning of a switch statement without any case
statement makes no sense.

Fixes #6135

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-11 18:29:57 +02:00
Johan Hedberg
dd09cbc1c4 net: buf: Redesigned API with split data and meta-data
Redesign of the net_buf_simple and net_buf structs, where the data
payload portion is split to a separately allocated chunk of memory. In
practice this means that buf->__buf becomes a pointer from having just
been a marker (empty array) for where the payload begins right after
the meta-data.

Fixes #3283

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Vinayak Kariappa Chettimada
18f366ca07 Bluetooth: controller: Fix disabling of Coded PHY feature
Fix conditional compilation in nRF5 radio interface so that
when Coded PHY feature is not selected then it does not use
the PPIs required for supporting the feature.

This will allow pwm_nrf5_sw driver to use PPI channels 14 to
19 and support 3 PWM channels. Without the Coded PHY feature
disabled, only PPI 14, 15, 18 and 19 are available for PWM.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-09 14:41:44 +01:00
Vinayak Kariappa Chettimada
f54f2ceb95 Bluetooth: controller: Rename a microsecond variable
Rename incorrectly named variable storing microseconds, from
ticks_slot to slot_us.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 12:26:34 +01:00
Vinayak Kariappa Chettimada
a02606cbf9 Bluetooth: controller: Fix missing ticks to us conversion
Fixed a missing ticks unit to microsecond unit conversion
potentially caused incorrect window offsets being used while
establishing connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:57:26 +01:00
Vinayak Kariappa Chettimada
978652e7b5 Bluetooth: controller: Remove redundant whitespace
Removed redundant whitespace when dereferencing struct
members.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:57:26 +01:00
Vinayak Kariappa Chettimada
bb84be2c5c Bluetooth: controller: Fix ticker to use u32_t ticks_slot
ticker timespace reservation can range up to 10.24 seconds,
needing 19-bits to represent in 32KHz clock units. Hence,
fix controller implementation to use u32_t to store ticks
slot values.

Without this fix, the controller is asserting in scan_adv
sample when using continuous scanning with 2 second interval
and window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:48:27 +01:00
Vinayak Kariappa Chettimada
ad7c9d3d76 Bluetooth: controller: Improved continuous scanning
Refactored the high frequency clock preparation advanced
feature to improve radio utilization during continuous
scanning.

The inter-event timespace value now considers the reserved
timespace while determining if the high frequency clock
will be retained. This reduces the preparation time, hence
increased radio use inside scan window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:23:10 +01:00
Vinayak Kariappa Chettimada
fa724b2bba Bluetooth: controller: Refactor invalid ctrl PDU handling
Refactor the invalid control PDU handling so as to reuse the
switch-case and hence, reduce code size and CPU time used.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:20:48 +01:00
Vinayak Kariappa Chettimada
8f239cd363 Bluetooth: controller: Rename radio_*_is_enabled to ll_*_is_enabled
In preparation towards a refactored controller, rename the
old radio_*_is_enabled() function to ll_*_is_enabled().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-06 10:49:25 +01:00
Vinayak Kariappa Chettimada
122a644d03 Bluetooth: controller: Fix handling of invalid Ctrl PDU lengths
Fix the controller implementation to handle Control PDUs
with invalid lengths by responding with Unknown Response
PDU.

Fixes LL.TS.5.0.2 conformance tests:
LL/PAC/SLA/BI-01-C [Control PDUs with Invalid Length from
	Master]
LL/PAC/MAS/BI-01-C [Control PDUs with Invalid Length from
	Slave]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
2800a9cb27 Bluetooth: controller: Minor cleanup of macros
Removed redundant macro definitions and rearranged code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
947bcba3d3 Bluetooth: controller: Use shorter (void *) for typecasts
Refactor and clean up code to use (void *) typecasts
consistently.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
4cd9ba7813 Bluetooth: controller: Use anonymous structs and unions in PDUs
Take advantage to cleanup code by using anonymous struct and
union definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
b7819ccab6 Bluetooth: controller: Add missing PDU struct definitions
Add missing PDU struct definitions in pdu.h file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
b521d50adc Bluetooth: controller: Refactor pdu_adv_payload_* to pdu_adv_*
Refactor PDU type names pdu_adv_payload_* to a shorter
pdu_adv_* struct names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
c4ba30cb1a Bluetooth: controller: Cleanup radio_pdu_node_rx/tx variables
Cleanup the use of long radio_pdu_node_rx and
radio_pdu_node_tx variable to shorter node_rx and node_tx
names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
fe0cebedcf Bluetooth: controller: Refactor phy req/rsp PDU struct
Refactor the pdu_data_llctrl_phy_req_rsp struct into
pdu_data_llctrl_phy_req and pdu_data_llctrl_phy_req structs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada
9abf8ce0a0 Bluetooth: controller: Refactor length req/rsp PDU struct
Refactor the pdu_data_llctrl_length_req_rsp struct into
pdu_data_llctrl_length_req and pdu_data_llctrl_length_req
structs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Ioannis Glaropoulos
d09baafe64 Bluetooth: controller: inline implementation of radio-enable-on-tIFS
This commit implements a minor refactoring of the implementation
for enabling the Radio on TIFS expiration. It inlines a function
that is defined in the local radio_nrf5_ppi header file.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos
2764084561 Bluetooth: controller: implement sw-switch with the event timer
This commit contributes the implementation of the sw-switch for
tIFS in nRF5 Radio using the EVENT_TIMER instead of a dedicated
TIMER instance. A Kconfig configuration is added so the user can
select whether to use the EVENT_TIMER for the tIFS switch or use
a dedicated TIMER instance.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos
0ec1095dd6 Bluetooth: controller: sw-switch with the event timer (prepare commit)
This commit implements minor refactoring of radio.c and ctrl.c,
to prepare for adding the implementation of sw-switch based on
the event timer.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos
9c4dc04ba5 Bluetooth: controller: conditionally reuse CC for ISR profiling
This commit adds the option of conditionally reuse an existing
CC register of the event timer for timer sampling used in ISR
profiling, in case SW tIFS switching is implemented based on the
event timer.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos
2a85dda206 Bluetooth: controller: symbolic name for CC used in ISR profiling
This commit adds a symbolic name for the event timer
CC offset that is used to sample the event timer during
ISR profiling.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Vinayak Kariappa Chettimada
d4cc46c453 Bluetooth: controller: refactor radio_nrf5* headers
Refactor radio_nrf5* header files to group together
definitions and have less #if-#else-#endif.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Johan Hedberg
2ff98636a5 Bluetooth: Mesh: Add support for OOB info and URI in provisioning data
Until now the OOB info and URI fields in unprovisioned beacons were
generally ignored by the implementation. Add fields for these to
bt_mesh_prov and make sure to take them into account when encoding
advertising data, both for PB-ADV and PB-GATT. For PB-ADV the URI goes
out in a separate beacon, whereas for PB-GATT it is placed in the scan
response data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-05 12:46:05 +02:00
Vinayak Kariappa Chettimada
258c7ccff1 Bluetooth: controller: Fix HCI LE Set PHY invalid behavior check
Fix HCI LE Set PHY command for invalid behavior testing for
invalid parameters and unsupported features.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-02 10:41:46 +01:00
Vinayak Kariappa Chettimada
a1f12eb238 Bluetooth: controller: Fix redundant length update event
Fix generation of redundant length update event when no
change in effective octets or time.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-73-C [Master Data Length Update - Responding
	to Data Length Update Procedure; LE 1M PHY]
LL/CON/MAS/BV-74-C [Master Data Length Update - Initiating
	Data Length Update Procedure; LE 1M PHY]
LL/CON/MAS/BV-76-C [Master Data Length Update - Responding
	to Data Length Update Procedure; LE 2M PHY]
LL/CON/MAS/BV-77-C [Master Data Length Update - Initiating
	Data Length Update Procedure; LE 2M PHY]
LL/CON/SLA/BV-77-C [Slave Data Length Update - Responding
	to Data Length Update Procedure; LE 1M PHY]
LL/CON/SLA/BV-78-C [Slave Data Length Update - Initiating
	Data Length Update Procedure; LE 1M PHY]
LL/CON/SLA/BV-80-C [Slave Data Length Update - Responding
	to Data Length Update Procedure; LE 2M PHY]
LL/CON/SLA/BV-81-C [Slave Data Length Update - Initiating
	Data Length Update Procedure; LE 2M PHY]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-02 10:40:52 +01:00
Johan Hedberg
0b7ac73eb6 Bluetooth: Mesh: fix BT_MESH_LPN_POLL_TIMEOUT description
The calculation was off by a factor of 10.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-01 12:37:09 -08:00
Vinayak Kariappa Chettimada
5c57027f53 Bluetooth: controller: Fix to use CPR preferred periodicity value
Fixed implementation to use Connection Parameter Request
Procedure Preferred Periodicity value in calculating the new
connection interval used by the master role in Connection
Update Indication.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-32-C [Accepting Connection Parameter Request –
	Preferred_Periodicity]
LL/CON/MAS/BV-33-C [Accepting Connection Parameter Request –
	Preferred_Periodicity and preferred anchor points]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-01 16:51:54 +01:00
Johan Hedberg
d6b905910b Bluetooth: Mesh: Fix passing CID to model publication messages
The vendor variants of the model publication client messages were not
passing onward the CID, rather passing CID_NVAL which is clearly not
right.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 13:35:36 -08:00
Vinayak Kariappa Chettimada
9acfc7fb5c Bluetooth: controller: Fix to restrict addr set in initiator
Fix controller implementation to restrict HCI LE Set Random
Address command when advertising and/or active scanning
and/or initiator state is enable.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/INI/BV-01-C [Connection Initiation]
LL/SEC/ADV/BV-01-C [Advertising With Static Address]
LL/SEC/SCN/BV-01-C [Random Address Scanning]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 10:54:26 -08:00
Vinayak Kariappa Chettimada
7af9c7108f Bluetooth: controller: Fix for CPR with/without Feature Exchange
Fix implementation to support Connection Parameter Request
Procedure initiation with and without use of Feature
Exchange Procedure being performed in a connection.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-81-C [Initiating Connection Parameter Request
	- Unsupported Without Feature Exchange]
LL/CON/MAS/BV-82-C [Initiating Connection Parameter Request
	- Unsupported With Feature Exchange]
LL/CON/SLA/BV-85-C [Initiating Connection Parameter Request
	- Unsupported Without Feature Exchange]
LL/CON/SLA/BV-86-C [Initiating Connection Parameter Request
	- Unsupported With Feature Exchange]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 16:02:14 +01:00
Johan Hedberg
8fc4c99496 Bluetooth: Remove redundant AD parsing check
A few lines earlier the code bails out in case len is 0. Checking for
buf->len < 1 is the same as checking for buf->len == 0. Since len is
guaranteed to be > 0 here the check len > buf->len implicitly checks
for buf->len == 0, i.e. the second test can be removed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 07:01:10 -08:00
Johan Hedberg
7ae78c9928 Bluetooth: Mesh: Fix segment transmission timeout
The timeout was hard-coded to 400ms, but the spec actually states:

"This timer shall be set to a minimum of 200 + 50 * TTL milliseconds."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg
1150858d8f Bluetooth: Mesh: Fix ack timeout calculation
The caculation was wrong since the value may be BT_MESH_TTL_DEFAULT,
i.e. 0xff, leading to much too large values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg
fee8734874 Bluetooth: Mesh: Clear segment rx context when incomplete timer expires
https://www.bluetooth.org/errata/errata_view.cfm?errata_id=10321

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg
fde013b254 Bluetooth: Mesh: Take advantage of K_SECONDS macro
This makes the code slightly more readable.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg
a0ab6086e3 Bluetooth: Mesh: Fix ignoring old SeqAuth values
Replay protection is not enforced at the Lower Transport Layer, so it
is possible to get an old replayed segment here. In such a case
cleanly discard it instead of causing a valid existing transaction
from being discarded.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Vinayak Kariappa Chettimada
d03ad43dbb Bluetooth: controller: Fix to restrict addr set in active scan
Fix controller implementation to only restrict HCI LE Set
Random Address command when advertising and/or active
scanning is enable.

Continues to pass the following LL.TS.5.0.2 conformance
test:
LL/SEC/SCN/BV-01-C [Random Address Scanning]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 10:16:47 +01:00
Vinayak Kariappa Chettimada
f117505773 Bluetooth: controller: Fix to restrict addr set in active states
Fixed implementation to disallow setting Bluetooth device
address under active advertising or scanning states.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/INI/BV-01-C [Connection Initiation]
LL/SEC/ADV/BV-01-C [Advertising With Static Address]
LL/SEC/SCN/BV-01-C [Random Address Scanning]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-29 18:03:15 +01:00
Alberto Escolar Piedras
ec7727077b native: nrf52 changes to HAL to support running on simulated HW
Conditionally compiled changes to the NRF52 HAL so it can
run on simulated HW on the native port.
(HW models are not included in this commit)

All changes are under ifdefs and therefore will not have any
effect on normal builds

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-01-29 16:02:29 +01:00
Vinayak Kariappa Chettimada
619bcf56c4 Bluetooth: controller: Refactor mayfly integration into hal
Refactor mayfly based execution context solution out into
the HAL folder. This opens up the possibility to use
tasklets (if and when kernel gets the support) style
execution contexts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-29 13:04:15 +01:00
Vinayak Kariappa Chettimada
f5d64aafaa Bluetooth: controller: Fix CPR initiation while in Enc. setup
Fixes a bug where in Connection Parameter Request was
initiated by slave role while Encryption Setup had been
started by the peer master.

Fixes: #5823

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-26 11:35:17 +01:00
Kumar Gala
26e4da52cf arm: nordic: flash: Use FLASH_DEV_NAME define
We want to move to use a common FLASH_DEV_NAME across the various flash
drivers. So samples, tests, or other code can be a bit more generic.  So
replace CONFIG_SOC_FLASH_NRF5_DEV_NAME with FLASH_DEV_NAME.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-01-25 15:23:00 -06:00
Vinayak Kariappa Chettimada
4d7d9de342 Bluetooth: controller: Refactor LL up and downstream interface
Rename some legacy upstream and downstream interfaces in
radio_* namespace to ll_* namespace for consistency.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 22:09:17 +01:00
Vinayak Kariappa Chettimada
5b0cd2c69b Bluetooth: controller: Conditional compile BT_LL_SW variant
Refactor Kconfig and CMakelists.txt to be able to
conditionally compile in BT_LL_SW variant in the controller
subsystem. This is done to support future controller with
vendor specific variant implementations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 11:51:10 +01:00
Vinayak Kariappa Chettimada
ae9f5b38d0 Bluetooth: controller: Add missing CPR and DLE cond. compilation
Add missing conditional compilation in controller's HCI
implementation, removing redundant code being compiled in.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 11:16:45 +01:00
Vinayak Kariappa Chettimada
5f4a7ea119 Bluetooth: shell: Support a non-connectable build
Add conditional compilation and move code to support
building a non-connectable Bluetooth shell application.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 10:51:54 +02:00
Vinayak Kariappa Chettimada
be0aa2ac2c Bluetooth: controller: Remove redundant clear of NRF_RADIO events
Remove redundant code that clears NRF_RADIO->EVENT_*
registers that are only used in PPI context. Only EVENT_*
registers that are read back need to be cleared.

Relates to: #5753

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-24 11:07:06 +01:00
Ioannis Glaropoulos
9d1ca9c390 Bluetooth: controller: remove redundant PPI channel and TIMER CC
This commit implements the SW-based radio switch for TIFS for LE
Coded PHY S2 in nRF52840 with a single PPI channel and a single
TIMER CC register.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-24 11:06:33 +01:00
Ioannis Glaropoulos
adaef465e4 Bluetooth: controller: minor refactoring in nrf5 radio driver
This commit moves the radio enable on-tick functionality in
function hal_radio_enable_on_tick_ppi_config_and_enable() in
radio_nrf5_ppi.h.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-24 11:06:33 +01:00
Ioannis Glaropoulos
36ded0b516 Bluetooth: controller: adjust nRF52840 HW radio timings for Coded PHY
This commit adjust the nRF52840 HW Radio timings for LE Coded PHY.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-24 11:06:33 +01:00
Vinayak Kariappa Chettimada
13130dbe73 Bluetooth: controller: Fix BT_CTLR_DEBUG_PINS Kconfig help text
Help text for BT_CTLR_DEBUG_PINS incorrectly mentioned
specific GPIO pins being reserved for this feature, but in
reality the pins reserved vary on the SoC selected, hence
any specific mention of pin details is removed from help
text.

Fixes: #5499

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-24 11:05:51 +01:00
Vinayak Kariappa Chettimada
5d4a32b70a Bluetooth: controller: Fix missing TIFS_HW cond. compilation
Fix a missing !CONFIG_BT_CTLR_TIFS_HW conditional
compilation when nRF52840 is configured to use hardware
Trx switching, that caused compile error.

Fixes: #5779
Fixes: #5761

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-22 15:33:15 -06:00
Mariusz Skamra
0572fe99ec Bluetooth: mesh: Check Heartbeat Pub count prior scheduling delayed work
This check is needed to not schedule the delayed work if current
message to be sent is the last heartbeat message.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-19 14:07:48 +02:00
Mariusz Skamra
37122d7205 Bluetooth: mesh: Reset Heartbeat Pub timer before sending message
The timer should be reset before sending to ensure correct
publication period.

This patch allows to pass MESH/NODE/CFG/HBP/BV-02-C.

This patch is ported from mynewt:
Commit: d4b84638df47e7ea21629e6919f547f5dcd47285

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-19 14:07:48 +02:00
Ioannis Glaropoulos
55d3ce111c Bluetooth: controller: Refactoring nRF5 radio driver
This commit refactors the nRF5 radio driver of Bluetooth controller
to use symbolic names for PPIs. It also revisits the Radio hardware
timing constants to align with experimental measurements.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-18 10:58:04 +01:00
Mariusz Skamra
385240ad0c Bluetooth: Fix BT_TESTING option dependency
This removes BT_DEBUG dependency on BT_TESTING flag.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-16 14:40:54 +02:00
Mariusz Skamra
2f81942754 Bluetooth: mesh: Fix model subscription groups cleanup
Virtual address labels array entries were not updated on va deletion,
so that STATUS_INSUFF_RESOURCES error was returned after few
subsequent Config Model Subscription Virtual Address Add, Delete,
Overwrite commands, even if there shall be free space available.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-10 16:38:53 +02:00
Mariusz Skamra
4ba9543bdd Bluetooth: mesh: Fix LPN subsciption groups update on VA deletion
This fixes missing bt_mesh_lpn_group_del call in mod_sub_va_del.
If Config Model Subscription Virtual Address Delete was received
and successfully proceeded, subscription address shall be also
deleted from LPN Subscribe Groups.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-10 16:38:53 +02:00
Anas Nashif
4d2ad0a8a5 Bluetooth: remove unused BT_DEBUG_COLOR
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-09 10:59:41 -05:00
Mariusz Skamra
253e40ad0e Bluetooth: mesh: Do not set RFU bits in Heartbeat Publication Features
Features received in Config Heartbeat Publication Set message can have
Feature bits set to RFU values.
This patch fixes setting this RFU bits in Heartbeat Publication
Features, so that those are not indicated in Config Heartbeat
Publication Status message.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-05 09:31:50 +02:00
Mariusz Skamra
fdca8d8f54 Revert "Bluetooth: Mesh: Fix ignoring invalid Transport OpCode as LPN"
This reverts commit ada5771d7c.

MESH/NODE/FRND/LPN/BI-02-C in Mesh Test Specification 1.0.1
has been fixed according to TSE #9774.

IUT shall ignore the message with an RFU Transport Control Opcode
but another Friend Poll message shall be sent with an alternating
FSN value.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-04 15:33:19 +01:00
Mariusz Skamra
cc1a960730 Bluetooth: mesh: Fix status returned from mod_unbind
According to Mesh Specification v1.0 4.3.2.48 Config Model App Status:
"The Status Code shall be Success if the received request was redundant
(bind request of existing binding, or unbind of a non-existing binding),
with no further action taken."

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-04 15:08:43 +01:00
Mariusz Skamra
813ec50838 Bluetooth: btp: Add event indicating expiration of incomp timer
This event indicates that segmented message incomplete timer
expired.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Mariusz Skamra
9977caefa1 Bluetooth: testing: Move bt_test_mesh_net_recv to internal API
This function is called only within mesh stack.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Mariusz Skamra
8274cbabf6 Bluetooth: btp: Add Mesh Clear Replay Protection List Cache command
This command is needed for Bluetooth Mesh testing against PTS.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Mariusz Skamra
a909aa3a0b Bluetooth: btp: Add LPN Subscribe/Unsubscribe commands
This adds commands to manage Friend node Subscription List.
Those will be used to add or remove and group/virtual address
from subscription list.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Mariusz Skamra
0bd3790d5b Bluetooth: btp: Add event indicating invalid provisioning BearerOpcode
This adds BTP event indicating reception of provisioning message
with invalid (RFU) BearerOpcode.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Mariusz Skamra
0d71cef1f2 Bluetooth: tester: Add BTP Mesh Model Send command implementation
This command will be used to test if model can properly send
segmented and unsegmented messages to a given destination address.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Manivannan Sadhasivam
045d146d9f subsys: bluetooth: host: mesh: shell: Fix IVIndex parsing
Fix the parsing of IVIndex value from shell command line for
cmd_provision

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
2017-12-30 08:28:00 +01:00
Vinayak Kariappa Chettimada
891ba80087 Bluetooth: controller: Fix S2 coding Rx chain delay timing const
Fix the S2 coding Rx chain delay timing constant based on
manual observations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-29 10:31:44 +01:00
Vinayak Kariappa Chettimada
d3585cd1d9 Bluetooth: controller: Add tIFS SW switching for Coded PHY
Add implementation to consider differing Rx chain delays for
S2 and S8 Coded PHY PDU reception. These changes are
required to meet tIFS timings for transmission after a
reception on S8 coding.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-29 10:31:44 +01:00
Vinayak Kariappa Chettimada
e00282af6e Bluetooth: Fix build failure with -Wshadow CFLAGS
Fixes many instances of errors similar to below:
zephyr/subsys/bluetooth/controller/ll_sw/ctrl.c:5927:22:
    error: declaration of ‘s_link’ shadows a previous
        local [-Werror=shadow]
  static memq_link_t s_link;
                     ^~~~~~
zephyr/subsys/bluetooth/controller/ll_sw/ctrl.c:5905:21:
    note: shadowed declaration is here
  static memq_link_t s_link;
                     ^~~~~~

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-20 12:29:52 -05:00
Mariusz Skamra
a87840e8e2 Bluetooth: Expose Bluetooth Testing API
This moves Bluetooth testing header file to the include/bluetooth.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2017-12-18 12:43:23 +01:00
Anas Nashif
429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Mariusz Skamra
700328ac55 Bluetooth: Introduce Bluetooth Testing API
This introduces Bluetooth internal API intended to be used for
qualification purposes. Application may register callbacks to get
data that is not exposed by public API.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2017-12-13 11:26:32 +02:00
Vinayak Kariappa Chettimada
ec5a787da2 Bluetooth: controller: Fix multiple master role event scheduling
When the controller is connecting to multiple connectable
advertisers, the events are scheduled consecutively avoiding
overlapping events. Calculation of the window offset did not
consider the preparation time before the event, causing the
new master role connection event to overlap with previous
event. This is now fixed by including the preparation time
in the used window offset from the end of connect_ind PDU
transmitted.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-09 09:24:37 +02:00
Michał Narajowski
06facdcad7 Bluetooth: Mesh: Fix typo in Kconfig help message
300 * 100 ms = 30000 ms = 30 s

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2017-12-07 17:15:47 +02:00
Vinayak Kariappa Chettimada
ba13c99141 Bluetooth: controller: Fix conn param req initiation check
Fixed the check related to initiating connection parameter
request procedure. This will avoid sending invalid repeated
dispatch of connection parameter request PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-06 11:30:42 -06:00
Vinayak Kariappa Chettimada
73a493eae6 Bluetooth: controller: Fix missing CPR procedure reset
When connection parameter request procedure was responded
by master role with Unsupported Link Layer Parameter Value,
a missing reset of the connection parameter request
procedure state caused next connection parameter request to
be incorrectly responded with same procedure collision
extended reject ind PDU. This caused an eventual connection
disconnection with reason LMP response timeout. This is now
fixed by reseting the state correctly.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-06 10:24:26 -06:00
Johan Hedberg
8b51b60634 Bluetooth: Mesh: Proxy: Don't try to advertise when it's not possible
If we have the maximum number of supported connections, then it
doesn't make sense to try to do connectable advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg
e4cac812df Bluetooth: Mesh: Proxy: Fine-tune subnet advertising rotation
Create a slightly smarter algorithm for choosing how long to advertise
each subnet. This is particularly important for the mesh_shell app,
since it uses a 10 second NODE_ID_TIMEOUT, meaning starting Node ID
advertising through user interaction would only succeed in advertising
one subnet (due to this being configured to 10 seconds).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg
6e89138823 Bluetooth: Mesh: Suppport multiple subnets for app-triggered Node ID
Mesh Profile Specification 1.0 section 7.2.2.2.3:

"When the server starts advertising as a result of user interaction,
the server shall interleave the advertising of each subnet it is a
member of"

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg
174facc02a Bluetooth: Mesh: Prioritize subnets with Node ID
Node ID advertising is short lived, so it's important to make sure
that subnets that get it enabled are first in queue to start
advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg
86ac86c6ca Bluetooth: Mesh: Add helpers for starting/stopping Node ID
We'll soon extend the start functionality with a bit more stuff
(prioritizing the started subnet), so in order to avoid excessive code
duplication, create helpers for these actions.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg
62777755f9 Bluetooth: Mesh: Add Proxy advertising support for multiple subnets
Until now the proxy server code would only advertise with the first
subnet. Introduce tracking of what the last advertised subnet was, and
give each subnet 10 seconds of advertising at a time.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg
364ce8801f Bluetooth: Mesh: Add support for sending NetKey Add message
Add configuration client model support for NetKey Add message, as well
as a mesh shell command for calling the new API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg
74e1f51350 Bluetooth: Mesh: Coding-style: Remove redundant whitespace
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg
22f3d36ba7 Bluetooth: Mesh: Fix relaying from GATT to Advertising
The logic for choosing to relay from the GATT bearer to the
advertising bearer was still buggy. This patch refactors the logic to
a separate helper function to make it clearer.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 13:52:10 +02:00
Johan Hedberg
7d7121b1ee Bluetooth: Mesh: Fix copy-paste mistake in log message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 13:36:31 +02:00
Johan Hedberg
dd839d90ac Bluetooth: Mesh: shell: Fix AppKey Add command handler
The command handler already has support for decoding from hex, however
it was not using the decoded value when calling the client API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 13:36:31 +02:00
Johan Hedberg
39298cf3c5 Bluetooth: Mesh: Fix format specifier for s32_t
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 13:36:31 +02:00
Johan Hedberg
c0b5a91588 Bluetooth: Mesh: Fix using the correct transmit state
If relaying is not supported, or disabled, the Relay Transmit state
will normally be 0, which is not what we want to use when proxying out
packets from GATT clients. The bt_mesh_net_relay() function is also
used for sending out locally originated packets, in which case the
Relay Retransmit state is also the wrong one to use (the Network
Transmit state should be used instead).

This patch makes sure we only use the Relay Retransmit state for
packets originating from the advertising bearer, and for all other
packets use the Network Transmit state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 11:13:31 +02:00
Johan Hedberg
4871d8567b Bluetooth: Mesh: Fix relaying conditions for Adv & GATT bearers
The bt_mesh_net_relay() function was missing several important checks
for whether a PDU should be relayed or not. In particular, it would
relay a packet from adv to adv even if the Relay state was set to
disabled, as long as GATT Proxy was set to enabled. The code would
also relay packets to the GATT Proxy bearer if the Relay state was set
to enabled but GATT Proxy was set to disabled. This patch addresses
both of these issues.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 11:13:31 +02:00
Johan Hedberg
ad6f9b15e6 Bluetooth: Mesh: Fix changing Relay state from Not Supported (0x02)
If the Relay state is set to Not Supported (0x02) the Config Relay Set
message should not change the state, rather just return its current
value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 11:13:31 +02:00
Johan Hedberg
967d8b5b59 Bluetooth: Mesh: Fix beacon cache handling
The beacon cache handling was severely broken in the way that the
cache_add() function was incorrectly mapping net_idx to array index,
which could have lead to array overflows.

To fix this, while also cleaning things up, move the cache to the
actual bt_mesh_subnet struct. This e.g. lets us avoid having to track
the net_idx twice.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-01 12:28:56 +02:00
Johan Hedberg
a3448aba9f Bluetooth: Mesh: Fix setting an upper limit on beacon interval
https://www.bluetooth.org/errata/errata_view.cfm?errata_id=9807

"If the computed Beacon Interval is less than 10 seconds, it should be
set to 10 seconds. If the computed Beacon Interval is greater than 600
seconds, it should be set to 600 seconds."

The lower limit is already covered by how frequently the delayed work
callback gets called, so we just need enforce the 600 second maximum.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-01 12:28:56 +02:00
Johan Hedberg
77ca943fd5 Bluetooth: Mesh: Fix sending beacons to Friend Queue & GATT clients
Whenever there's a security change (Key Refresh or IV Update) we
should immediately send beacons to any Friend Queues or connected GATT
clients. Introduce a helper function to do this, and make sure it's
called from all places that change the Key Refresh or IV Update
states.

This fixes test case MESH/SR/PROX/PB-12-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-30 19:29:15 +02:00
Johan Hedberg
8f2a7f2d46 Bluetooth: Mesh: Fix logging mesh addresses
Addresses are 16-bit and not 8-bit.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-30 19:29:15 +02:00
Johan Hedberg
1210258603 Bluetooth: Mesh: Clearly document the magic 18 byte minimum length
This makes it clear why 18 is a valid minimum network PDU length to
enforce. This is particularly important since as of writing this patch
there's at least one PTS test case which sends too small PDUs, which
could potentially lead to people thinking the implementation is at
fault (it's not).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-30 14:58:09 +02:00
Johan Hedberg
6078f8acc2 Bluetooth: Mesh: Introduce API for clearing the RPL
Some Transport Layer tests (MESH/NODE/TNPT/BV-13-C in particular)
require manual clearing of the RPL. Introduce an API for it as well as
a command to the mesh shell to call the API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:49:45 +02:00
Johan Hedberg
3222662553 Bluetooth: Mesh: Fix Replay Protection List checking
If we the stored RPL entry was for an old IV Index, and the received
PDU is for a new IV Index we should not be comparing the sequence
number (as it's by definition always greater than the old one).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:49:45 +02:00
Johan Hedberg
859afbf39b Bluetooth: Mesh: Fix disconnecting clients when disabling GATT Proxy
Section 4.2.11 of the Mesh Profile Specification 1.0 states:

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

This also makes test case MESH/SR/MPXS/BV-08-C pass.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg
90ea44cc4b Bluetooth: Mesh: Fix initializing Node ID start time
The bt_mesh_proxy_identity_enable() function was missing a line to
properly initialize the start time for Node Identity advertising.
Without it this public function wouldn't work as intended.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg
012e763311 Bluetooth: Mesh: Fix GATT Proxy Service CCC read permissions
Test case MESH/SR/MPXS/BV-04-C requires the Proxy Service CCC to have
read permissions in order to pass.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg
ff7d5ca910 Bluetooth: Mesh: Fix GATT Proxy & Node Identity state binding
Section 4.2.11.1 of the Mesh Profile specification 1.0 states:

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

When the proxy state has been changed we also need to wake up the
advertising module to make sure we do the right kind of advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg
84409d0161 Bluetooth: Mesh: Deliver TTL=1 PDUs only to the local net interface
Section 3.4.5.2 in the Mesh Profile Specification (1.0) states:

"The output filter of the interface connected to advertising or GATT
bearers shall drop all messages with TTL value set to 1."

Also: https://www.bluetooth.org/errata/errata_view.cfm?errata_id=9811

Note that this is specifically 1 and not 0, since e.g. Friend PDUs
always go out with TTL 0.

Another noteworthy thing is that the way this has to be implemented is
slightly contrary to how it's presented in the specification (both in
the text as well as the Message processing flow diagram in section
3.11. If this was implemented following the spec to its word, then any
PDU received over GATT or Advertising with TTL 2 would never be
relayed (since the TTL would be 1 when the PDU gets rerouted back to
the bearer). This would be both counterintuitive to the intended
purpose of the TTL, and would also be contrary to the test
specification (see Test Procedure step 1 in MESH/NODE/RLY/BV-01-C).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg
bed5472cab Bluetooth: Mesh: Remove unnecessary variable
Most places in bt_mesh_friend_req() used rx->sub (which is already
quite short in itself), so just remove the only remaining user and the
helper variable itself.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg
c393bfd8e3 Bluetooth: Mesh: Fix Friend messaging state tracking
There were several issues with the code:

 - queue_size wasn't properly kept up to date, leading to erroneous
   buffer discarding logic.

 - Poll timeout when there were buffers in the Friend Queue didn't
   work because we didn't track if there'd been a preceding request
   for messages or not (hence the added pending_req variable).

 - We would overwrite the recv_delay timer if there was another
   request while the previous one was still sending (a likely scenario
   if we send out multiple advertising events per packet).

 - We weren't canceling the sending of a buffer if the Friendship was
   suddenly cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
49c5e5546a Bluetooth: Mesh: Log information about the on-behalf-of flag
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
b123799ebe Bluetooth: Mesh: Reduce logging clutter for LPN lookups
The logs for looking up LPNs were spamming the console a bit too much.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
c65d04655d Bluetooth: Mesh: Fix looking up existing friendship contexts
When receiving Friend Offers we should also consider unestablished
contexts, and simply start from the beginning if that happens.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
a9a18cec7b Bluetooth: Mesh: Fix clearing Friend state upon reset
Not clearing the Friend state could risk invalid timers staying
active, etc.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
2d63f5e480 Bluetooth: Mesh: Fix & clean up Friendship Credential handling
Pass the subnet to some friend_cred_* APIs since it contains all
necessary information for choosing the right keys to generate them
from. Also shorten the API names to avoid awkward line splitting -
these are internal APIs so it's an acceptable compromise. One bug that
this fixes as part of the cleanup is using the right NetKey Index when
clearing Friendship: previously the code was always using the index of
the first subnet, regardless of which subnet the Friendship was based
on.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
e7199060c6 Bluetooth: Mesh: Remove unnecessary logic for key selection
Key Refresh Phase 2 is analogous to the Key Refresh flag being set.
This means that the flag can directly be used as the index to the
new/old key two-element array.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
46f8c7fb44 Bluetooth: Mesh: Fix clearing network message cache
Since the stack supports runtime reset and reprovisioning, we need to
clear the network message cache whenever creating a new mesh network.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
48e6bfaaa7 Bluetooth: Mesh: Fix proxy advertising handling
Remove inconsistent and sometimes unreliable tracking of what
advertising parameters should be used and when the Node Identity
advertising started. The main change that facilitates this is to have
the Node ID start timestamp as part of the mesh subnet context.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
bdcf8c3692 Bluetooth: Mesh: Use 32-bit math for Node ID duration
The Node Identity duration is at most 60 seconds, so it's safe to use
32-bit timestamps.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
7909c3d3fa Bluetooth: Mesh: Introduce option for Node ID timeout
Some PTS test cases only work when we're advertising using Network
Identity. Using the default timeout of 60 seconds for Node Identity
will cause this test cases to fail (i.e. the PTS gives up before
Zephyr transitions to advertising from Node Identity to Network
Identity).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
699a7c9e85 Bluetooth: Mesh: shell: Fix parsing "boolean" parameters
The shell was being inconsistent in its parsing of boolean parameters.
Some commands were documented as accepting "on" but were actually
parsing the parameter with strtoul() which would result in 0.
Introduce a new helper to convert a string to a u8_t which still
accepts "on" or "enable". This gives us full flexibility of having a
simple interface to the user, but still allowing non-boolean values to
be tested (since on-air the value is a full octet).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
f81b23a624 Bluetooth: Mesh: shell: Add command for setting the UUID
Instead of having a hard-coded UUID, introduce a command to change it.
This is particularly useful if there are many unprovisioned nodes
around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg
4c180d6fbf Bluetooth: Mesh: shell: Make Static OOB optional
Having the Static OOB value set up-front can be confusing to the user
since they will not know what the value is. Start off by having it
unset, but introduce a new command using which the user can either set
or clear it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Vinayak Kariappa Chettimada
b022f72cf4 Bluetooth: shell: Fix compile error due to missing memq.h include
Fixes the following compile error when building
tests/bluetooth/shell application:

In file included from subsys/bluetooth/shell/ticker.c:16:0:
subsys/bluetooth/shell/../controller/util/mayfly.h:21:2:
error: unknown type name 'memq_link_t'
  memq_link_t *_link;
  ^~~~~~~~~~~

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-27 13:48:24 -08:00
Johan Hedberg
f20afb7473 Bluetooth: Mesh: Restrict scope of variables in health_get_registered()
Don't declare the variables in a wider scope than what they're needed
for.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 12:10:49 +02:00
Johan Hedberg
c2fd67699d Bluetooth: Mesh: shell: Fix sending health publication
We need to send out a Health Fault Current Status (the Health Model's
publication message) when all faults are cleared. The logic for
calculating number of faults was also wrong after the updated model
publication API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 12:10:49 +02:00
Johan Hedberg
8a13066a4e Bluetooth: Mesh: shell: Fix health publication message size
The Health Current Fault message size was being set too small to fit
any faults. Use a macro to make sure the size gets applied in both
places where appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 12:10:49 +02:00
Vakul Garg
d5134d9bf3 Bluetooth: Added missing checks for whether CONFIG_BT_PRIVACY is enabled
Fixes error encountered during connecting BLE endpoint.
[bt] [ERR] le_remote_feat_complete: Unable to lookup conn for handle 32

This is to work around a buggy controller that states support for
enhanced privacy, but misbehaves when it's enabled. This change
makes it possible to ensure the host doesn't try to enable the enhanced
event by simply disabling the privacy feature in Kconfig.

Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
2017-11-27 11:30:00 +02:00
Johan Hedberg
d0826f3392 Bluetooth: Mesh: Fix NetKey Update behavior in Phase 1
If we get a different key value in Phase 1 we should return the same
"Cannot Update" error as in phases 2 and 3. This fixes test case
MESH/NODE/KR/BI-02-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:54 +02:00
Johan Hedberg
48aecd1513 Bluetooth: Mesh: Add IV Update test mode API
This makes it possible to pass all IV Update tests without having to
build a custom configuration for some of the tests. We also disable
the feature in all sample configurations, but leave it on in the
tests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:54 +02:00
Johan Hedberg
a41449ef2a Bluetooth: Mesh: shell: Add iv-update command
This command is needed to pass some IV Update-related PTS tests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:54 +02:00
Johan Hedberg
6e2a3863ac Bluetooth: Mesh: Fix creating initial beacon data
There was a chance that initial beacons for subnets would be sent with
uninitialized data. Make sure we initialize the beacon data each time
when we create a new subnet.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:42 +02:00
Johan Hedberg
a48724fd0f Bluetooth: Mesh: shell: Fix & clean up command help
Use NULL instead of "", fix typos, and indicate app-key-add last
parameter as optional (to match the command implementation).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg
35fd523b03 Bluetooth: Mesh: Add support for manipulating Label UUIDs
Add support for sending messages that add, delete or overwrite Label
UUIDs, and add commands for these to the shell. With the help of these
commands it's possible to pass Transport Layer PTS tests (in
particular TNPT/BV-05-C) by manually adding a Label UUID through
module subscription, since the test case itself does not do this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg
23ffed0511 Bluetooth: Mesh: Improve logging related to Label UUID lookups
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg
e80881d0b9 Bluetooth: Mesh: shell: Add raw network PDU sending support
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg
b0393caeb5 Bluetooth: Mesh: shell: Add support for decoding hex strings
Add helper to decode arbitrary-length hex strings. The first user is
the AppKeyAdd handler.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg
561b458011 Bluetooth: Mesh: shell: Fix decoding vendor model IDs
The code was accessing the wrong parameter.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg
9097a66460 Bluetooth: Mesh: LPN: Fix clearing group status
When the Friendship is lost the group status tracking needs to be
cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg
9859146722 Bluetooth: Mesh: LPN: Fix clearing pending request
The code would unconditionally clear sent_req in update_timeout(),
which would e.g. cause us to switch to Friend Polls if the Friend
didn't respond to a Subscription List Add/Remove on the first attempt.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg
4cc6a4fcbb Bluetooth: Mesh: Increase initial poll timeout
The purpose of using something less than the configured poll timeout
was to cover the case where the LPN establishes Friendship before the
provisioner has completely configured it. However, there's the "more
data" flag in the initial Friend Response, and we now also have a
public API to request for more messages. Both of these features
diminish the value of having a reduced initial timeout. Also, some LPN
test cases do not expect us to send frequent polls initially, causing
failures with the PTS.

Therefore, introduce a Kconfig option to set the initial timeout, and
make it default to the actual poll timeout.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg
89030f0906 Bluetooth: Mesh: Introduce public LPN APIs for better control
Many apps, the mesh shell included (due to PTS test requirements)
benefit from exposing LPN state and polling outside of the stack.
Introduce new APIs for these, and add code to the mesh shell module to
take advantage of them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg
46e0afdf82 Bluetooth: Mesh: Health: Fix requiring specific Company ID
The Health Fault Test & Test Unacknowledged messages are supposed to
be sent for more than the Node Composition Data Company ID. It's true
that some PTS tests require the message to be ignored for
non-composition data ID, however that's something that should be
covered by the application that's used for testing, and not the
generic Health Server Code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
d588850c0c Bluetooth: Mesh: Add support for Health Attention messages
Add support for sending Health Attention messages, as well as commands
to use these new APIs from the shell.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
30d6761396 Bluetooth: Mesh: Introduce helpers to wait for a status message
There was a lot of code duplicated in the Foundation Client Models for
waiting on a specific status message. Refactor this into helper
functions (one per client model).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
7e8f9afee5 Bluetooth: Mesh: Add support for Health Period messages
Add support for sending Health Period messages, as well as commands to
use these new APIs from the shell.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
ce10be3a2a Bluetooth: Mesh: Add support for Health Fault Test messages
Add support for sending Test and Test Unacknowledged messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
987c68b7aa Bluetooth: Mesh: Add support for Health Fault Clear messages
Add support for sending Clear and Clear Unacknowledged messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
9e3ebf19d9 Bluetooth: Mesh: shell: Add Health Fault support to the server
Add commands and callbacks to manage the Registered Fault state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
1699d045f8 Bluetooth: Mesh: shell: Use a valid Company ID
The Company ID 0xffff is treated as invalid in some contexts, so use a
valid one. Also, the Health tests require the Health Fault Company ID
to match that found in the Composition Data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
2eda34cf3f Bluetooth: Mesh: Add support for receiving Health Current Status
Add a callback to the Health Client Model context, so that the
application is able to receive Health Current Status messages that
some Health Server Model publishes.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
b26231d770 Bluetooth: Mesh: Add support for sending Health Fault Get message
Add the needed Health Client API for sending Health Fault Get, and add
a command to the shell to utilize it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
7ef5e53e28 Bluetooth: Mesh: Add skeleton for Health Client model
Add a skeleton for the Health Client model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg
2a6010f1b3 Bluetooth: Mesh: shell: Add appidx command for setting the AppIndex
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Vinayak Kariappa Chettimada
f9cd9d4a7b Bluetooth: controller: Fix compile error when LE_ENC is disabled
Fixes the following compile error when CONFIG_BT_CTLR_LE_ENC
is disabled:
subsys/bluetooth/controller/ll_sw/ctrl.c: In function
'isr_rx_conn_pkt_ctrl':
subsys/bluetooth/controller/ll_sw/ctrl.c:2613:29: error:
'LLCP_ENCRYPTION' undeclared (first use in this function)
         (conn->llcp_type != LLCP_ENCRYPTION)) ||
                             ^~~~~~~~~~~~~~~
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 18:48:05 -05:00
Johan Hedberg
ea68c3aa22 Bluetooth: Fix compiler warning when VS HCI is unset
Fixes:

subsys/bluetooth/host/hci_core.c: In function ‘set_static_addr’:
subsys/bluetooth/host/hci_core.c:4043:1: error: label ‘generate’ defined
but not used [-Werror=unused-label]
 generate:
 ^~~~~~~~

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 18:48:05 -05:00
Vinayak Kariappa Chettimada
9fd502f956 Bluetooth: controller: Use PPI indices 14/15 for PA/LNA
PA/LNA feature being not default enabled, keeping the PPI
indices used for this feature at the higher indices would
allow use of these PPI indices by other drivers, for
instance the nRF5 software PWM driver.

Software PWM driver provides 3 PWM pins/channels using upto
6 PPI channels. If BLE controler where to use 0-13, then
14-19 PPI indices can be used by the PWM driver.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 18:46:20 -05:00
Vinayak Kariappa Chettimada
f44efd12fa Bluetooth: controller: Replace void * with memq_link_t
Replace use if void * declaration related to memq links with
more readable memq_link_t.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 15:28:49 +01:00
Johan Hedberg
6fda8b2b4d Bluetooth: Mesh: Friend: Fix poll timeout type
The Poll Timeout needs to be at least 24 bits, so u16_t doesn't
suffice and will potentially result in truncation. Use u32_t, thereby
also fixing a coverity warning.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg
9b87e0f2cc Bluetooth: Mesh: Fix coverity warning of unchecked return
Most places check the return value of bt_mesh_model_send(), so check
for it in all places.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg
2849662aa8 Bluetooth: Mesh: Fix dereferencing mod->pub too early
The bt_mesh_model_publish() is supposed to return a "not supported"
error if the publish context doesn't exist. Fixing the premature
dereferencing also fixes coverity warnings.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg
7c53d31ed2 Bluetooth: Mesh: remove redundant 32-bit wrap-around code
The separate checking for "now < reftime" is unnecessary, since the
integer over/under-flow for unsigned 32-bit values resulting from
subtraction will give the right delta even if 'now' is less than the
reference.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg
15fe221f13 Bluetooth: Mesh: Fix accuracy of Publish Period
After the Publish Retransmit state was introduced the Publish Period
measurement would begin once the previous Publish message has finished
transmitting. This will however cause inaccurate periods, which is
particularly an issue with the PTS that expects accuracy of less than
0.5 seconds (apparently).

Since the publication timer is also used for the retransmissions we
can't simultaneously use if for the period as well. Therefore, we
introduce a new variable called period_start which makes a note of
when the period was supposed to start, and then once all
retransmissoins are done initializes the timer with the send duration
taken into account.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg
8f1541184f Bluetooth: Mesh: Fix non-periodic Model Publication
The only generally available model supporting publication that's
convenient to be used for testing is the Health Server Model.
Unfortunately since this model supports period publication, the
non-periodic side got less attention and had some bugs.

The first thing that needs to be done is to verify that the period
returned by bt_mesh_model_pub_period_get() is positive. If it's zero
then no periodic publication should take place.

Another thing that this patch cleans up is the naming of the callback
used for periodic publishing. There's no need do require the callback
to call bt_mesh_model_publish() since this must happen no matter what,
so instead rename the callback from 'func' to 'update' and have the
access layer call bt_mesh_model_publish() if the callback was
successful.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg
03151fc8d7 Bluetooth: Mesh: Proxy: Downgrade advertising errors to warnings
When a small amount of supported connections is configured (especially
the default number of 1), connectable advertising may fail. This is
perfectly fine since as soon as a disconnection event happens the
advertising will be successfully restarted. To avoid causing
unnecessary user worries, downgrade the resulting errors to warnings.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 15:02:25 +02:00
Johan Hedberg
95bef3694e Bluetooth: Mesh: Fix node reset
There were some things that were working only when receiving a Node
Reset message from someone else, but not when the app called
bt_mesh_reset() directly. There was also some state cleanup missing
for the transport layer. This patch addresses all of these issues.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 15:02:25 +02:00
Johan Hedberg
3a072f07a1 Bluetooth: Mesh: shell: Declare mandatory dependency on BT_MESH_CFG_CLI
The Configuration Client is such a generally useful feature for the
shell that it makes sense to have it as a mandatory dependency (the
shell wasn't anyway compiling at the moment without it).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 13:32:53 +02:00
Johan Hedberg
5a3a9aed49 Bluetooth: Mesh: Update TODO file
Update the TODO file with the latest status.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 12:19:41 +02:00
Vinayak Kariappa Chettimada
25737d9963 Bluetooth: controller: Optimise memq interface
Optimised the parameter passing order of memq interface such
that the compiled code uses less space and execution time.

Having a parameter that gets returned as the first parameter
passed to a function avoids instructions required to have
the result in the return register.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-21 09:11:34 +02:00
Johan Hedberg
47756c8364 Bluetooth: Mesh: shell: Add mod-sub-del command
Add command to delete model subscriptions.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg
324336167e Bluetooth: Mesh: Add Model Subscription Del & Overwrite support
The Del and Overwrite operations have the exact same parameters and
expected status response as the Add operation, so we can reuse most of
the code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg
a5340e72a3 Bluetooth: Mesh: Fix ignoring all messages in LPN mode
Even though we have LPN enabled, we might still receive messages
through other network interfaces than the advertising one (e.g. the
local network interface).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg
ec9aaaed23 Bluetooth: Mesh: Fix calling send start for multi-segmented messages
Using the start callback, especially with multi-segment messages, may
not be super useful for applications, but we should support if if they
do provide it. One application could e.g. be to calculate the duration
it takes for a multi-segment message to be completely received by the
remote end.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg
e7bb76e2b6 Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:

 - The Publish Retransmit State was not taken into account at all
 - Health Server used a single publish state for all elements

To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.

Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.

To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.

The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.

The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg
f9fad553ac Bluetooth: Mesh: Fix encoding/decoding Publish Retransmit value
The Model Publish Retransmit Interval is in units of 50ms and not 10ms
like the other transmit/retransmit states. Create dedicated macros for
the Publish Retransmit State and use them where appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg
4bf045e282 Bluetooth: Mesh: Use a unified send callback also for public API
There's no need for callback exposed in the public API to be something
different than what's used internally. In fact this would just
complicate things. This patch exposes the internal callback under a
bt_mesh_adv_cb name and uses it throughout the mesh stack.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg
224506c78c Bluetooth: Mesh: Fix notifying message send completion for GATT proxy
In case an outgoing message gets only delivered to the proxy interface
we should not forget to notify the send callbacks of this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg
c3ad883872 Bluetooth: Mesh: Introduce a second advertising callback
Some places of the code are interested in when the first advertising
event goes out. Others, on the other hand, are interested when the
last advertising event goes out. Some are even interested in both of
these. Instead of providing a single callback, provide a struct with
two possible callbacks for sending advertising PDUs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg
8beb6784d3 Bluetooth: Mesh: Introduce user data for the advertising callback
This simplifies the callback implementations since they no-longer need
to do their own look-ups of the needed context.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg
ad7afa0c7c Bluetooth: Mesh: Move per-buffer mesh meta-data to external struct
We've so far been trying to keep the per-buffer mesh meta-data to
a maximum of 8 bytes in anticipation of upcoming net_buf refactoring
that'll have all net_bufs in the system with the same sized user data.

It's however slowly becoming unfeasible to do this - e.g. simply
adding user data to the sending callback would already fill up the
full 8 bytes.

To solve this issue, treat the net_buf user data as just a pointer to
the actual user data, and keep the actual user data in a separate
array. We still keep taking advantage of net_buf_id() however, so
buffers can cheaply be mapped to their meta-data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Vinayak Kariappa Chettimada
9746b2a75d Bluetooth: controller: Fix memq_dequeue function
When testing memq implementation used by controller, a
missing check on NULL pointer return could lead to NULL
pointer deferencing.

Current implementation of controller and mayfly do not
by design lead to NULL pointer dereferencing, this fix
is only for correct-ness and complete-ness.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-20 10:42:53 +02:00
Johan Hedberg
6d7f171549 Bluetooth: Mesh: Fix clearing incomplete Friendship upon reset
When resetting there is no point trying to start clearing the
Friendship since there will not be any security material left to send
out PDUs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 14:44:19 +02:00
Johan Hedberg
62f2475e3e Bluetooth: Mesh: Fix compiler warning for access.c
This fixes a warning for duplicate const declaration specifier.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 14:44:19 +02:00
Johan Hedberg
1edb69e4b6 Bluetooth: Mesh: Make AppKey binding implicit for Model Publication
The common interpretation (among other implementations) seems to be
that Model Publication for a given AppKey Index implies a binding for
that AppKey. This isn't currently explicitly stated in the spec, but
in order to improve interoperability go with this interpretation as
well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 13:24:30 +02:00
Johan Hedberg
1c825c825f Bluetooth: Mesh: Friend: Fix setting pending_buf variable
The variable for tracking that a buffer from the Friend Queue hasn't
been sent yet was not being properly set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 13:09:45 +02:00
Johan Hedberg
bd69b2127e Bluetooth: Mesh: Use dedicated struct for heartbeat subscription
This simplifies the API since there is no-longer a need to pass a huge
number of function arguments around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg
d4365e16f9 Bluetooth: Mesh: Use dedicated struct for heartbeat publication
This simplifies the API since there is no-longer a need to pass a huge
number of function arguments around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg
a18a22524f Bluetooth: Mesh: shell: Add mod-pub command
Add a command for getting and setting the model publication. We also
have to adjust the app's configuration, since both the Model
Publication Set and Status messages are segmented messages, meaning we
need two TX and RX segment contexts.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg
05be6b8033 Bluetooth: Mesh: Add support for sending Model Publication messages
Add support for Model Publication Set/Get and their vendor model
variants.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg
2e50ba9847 Bluetooth: Mesh: Use invalid CID instead of bool for non-vendor models
The value 0xffff is reserved, so we can use that to indicate whether
there's a vendor model in question or not. Simplifies things over the
previously used separate boolean value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg
bde9dcd3bc Bluetooth: Mesh: Fix enabling scanning after provisioning
There were some needed changes missing after the update to have manual
control of PB-ADV & PB-GATT provisioning bearers. E.g. the test for
CONFIG_BT_MESH_LOW_POWER in net.c was no-longer indicative of scanning
being on or not.

Do the scan enabling selection within the LPN module if LPN is
supported, or otherwise enable scanning unconditionally in
bt_mesh_provision().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 08:39:00 +02:00
Johan Hedberg
c8b51ded29 Bluetooth: Mesh: shell: Fix newline in incorrect place
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:38:54 +01:00
Johan Hedberg
d4be608036 Bluetooth: Mesh: Allow changing cfg client message timeout
10 seconds is quite long for configuration messages, and way too much
currently since we only talk through the local networking interface.
Set the default timeout to 2 seconds, and provide APIs through which
the timeout may be changed at run-time (mainly useful for the shell).

Note: The timeout_set() API is normally assumed to be called just once
for an application, based on the expected size of the network (hops &
latency). Trying to change it e.g. in a multi-threaded environment for
every message may not yield the expected results.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
882ce59e97 Bluetooth: Mesh: shell: Convert hb-sub-set command to hb-sub
Convert the hb-ub-set command to a more generic hb-sub that can be
used both for getting and setting the Heartrate Subscription State.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
7b27d96f96 Bluetooth: Mesh: Add support for sending Heartbeat Subscription Get
Add support for sending the Heartrate Subscription Get message.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
135fd92492 Bluetooth: Mesh: shell: Convert hb-pub-set command to hb-pub
Convert the hb-pub-set command to a more generic hb-pub that can be
used both for getting and setting the Heartrate Publication State.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
9bf8af8507 Bluetooth: Mesh: Add support for sending Heartbeat Publication Get
Add support for sending the Heartrate Publication Get message.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
8e9e039700 Bluetooth: Mesh: shell: Implicitly initialize Bluetooth support
Avoid having to go do "init" for the bt module before issuing "init"
for the mesh module. Instead perform Bluetooth init implicitly. The
bt_enable() API will cleanly fail with -EALREADY if it was previously
called.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
d35061357a Bluetooth: Mesh: shell: Add provision command for self-provisioning
This is for testing purposes, in case an external provisioner is not
available or not wanted.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
e631d6d6cc Bluetooth: Mesh: shell: Add hb-pub-set command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
5e3804b11d Bluetooth: Mesh: Add support for sending Heartbeat Publication Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
2d40c1673c Bluetooth: Mesh: Fix calling complete callback for bt_mesh_provision()
If the app does direct provisioning, it may still want to do common
handling through its provisioning complete callback (if it has one
registered). This also means that we always require a non-NULL
provisioning context provided to bt_enable(), and that it needs to
fail if NULL was given.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
255edcfde2 Bluetooth: Mesh: Provisioning: Add NetKeyIndex to complete callback
It may be useful for the app to know what the initial NetKeyIndex that
it was given during provisioning is.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
0b53341d92 Bluetooth: Mesh: shell: Group global variables in a dedicated struct
This avoids conflicts with function-local variables being called the
same way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
70cbcef576 Bluetooth: Mesh: Rename health server code from health to health_srv
This is in anticipation of soon adding health client support, which
could then cause confusion due to the ambiguous API names.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
3b252ca2be Bluetooth: Mesh: Rename configuration server code from cfg to cfg_srv
Now that there's support for configuration client as well, rename cfg
to cfg_srv to avoid any confusion.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
0ef7c6e09a Bluetooth: Mesh: Add more flexible APIs for provisioning bearers
Add the ability to track the provisioning bearer through an extra
parameter to link_open/close. Also introduce new public functions to
enable/disable specific provisioning bearers. This also means that one
now needs to explicitly enable provisioning bearers after calling
bt_mesh_init().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
a81fa43a59 Bluetooth: Mesh: Use proper _t suffix for typedefs
To be consistent with the coding style, use a _t suffix for typedefs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg
d235f9cc6f Bluetooth: Mesh: shell: Add hb-sub-set command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
63329b79d6 Bluetooth: Mesh: shell: Add mod-sub-add command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
c233ce4fdb Bluetooth: Mesh: shell: Add app-key-bind command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
5429f14a69 Bluetooth: Mesh: shell: Add app-key-add command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
6585347f78 Bluetooth: Mesh: shell: Add for relay and 1-byte state commands
Add commands for 1-byte states such as Default TTL, Friend and GATT
Proxy, as well as the 2-byte Relay state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
cc54f8c84c Bluetooth: Mesh: shell: Add support for Beacon Get/Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
96934bd3d4 Bluetooth: Mesh: shell: Add "dst" & "netidx" commands
Add commands to modify the used destination address and NetIdx.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
7a1c0b979e Bluetooth: Mesh: shell: Add support for getting composition data
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
f50b99572f Bluetooth: Mesh: Add support for sending Heartbeat Subscription Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
b4688bdc84 Bluetooth: Mesh: Add support for sending Model Subscription Add
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
e4db09e919 Bluetooth: Mesh: Add support for sending Model App Bind message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
e1bc6a6141 Bluetooth: Mesh: Add support for sending AppKeyAdd message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
cbfea942f6 Bluetooth: Mesh: Add support for Relay and 1-byte state Get/Set
Add support to the Configuration Client Model for getting and setting
1-byte states (which can be nicely generalized in code) as well as the
2-byte Relay state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
07305fd71d Bluetooth: Mesh: Add support for sending Beacon Get & Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
3d1ce43eb0 Bluetooth: Mesh: Add support for sending Get Composition Data
Add Get Composition Data support to the Configuration Client Model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
588887c9b7 Bluetooth: Mesh: Add primary address to provisioning complete callback
It may be useful for the app to know that the local node's primary
address is.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
2a1e16c2a3 Bluetooth: Mesh: Add skeleton for Configuration Client Model
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg
17c9b3a105 Bluetooth: Mesh: Make TRANSMIT_COUNT & TRANSMIT_INT macros public
These are useful for apps who want to implement/use the Configuration
Client Model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Grzegorz Kolodziejczyk
1ff3ab5f82 Bluetooth: Mesh: Add read callback for ccc in provisioning service
This patch adds read permission for client characteristic configuration
descriptor. This is required by MESH/NODE/MPS/BV-06-C,
MESH/NODE/MPS/BV-07-C PTS tests.

Signed-off-by: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@codecoup.pl>
2017-11-14 14:27:37 +02:00
Johan Hedberg
1c0ff01ac7 Bluetooth: Mesh: shell: Add command for Node Identity
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Johan Hedberg
a6af281f04 Bluetooth: Mesh: shell: Take advantage of link open/close callbacks
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Johan Hedberg
75253195a4 Bluetooth: Mesh: shell: Add LPN toggling command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Johan Hedberg
e2e74f705b Bluetooth: Mesh: shell: Add basic skeleton
Add a basic shell skeleton for Mesh, containing basic command for
initialization, provisioning and reset.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Sebastian Bøe
578c91ae18 Bluetooth: storage: Fix linking with subsys__fs
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-13 15:10:20 +02:00
Johan Hedberg
cc55e86cc8 Bluetooth: Mesh: Fix relaying packets
The restoring of the buffer parsing state was only correct for the
friend queue (which needs the app-layer data). Relaying on the other
hand requires the network layer data, i.e. it needs a different state
to be restored.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg
02d98d0da0 Bluetooth: Mesh: Fix missing tracking of segment callback
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg
e70f6dfc88 Bluetooth: Mesh: Take advantage of BT_MESH_TTL_MAX macro
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg
a2a46e66e1 Bluetooth: Mesh: Export key packing helpers internally
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg
9cbb979db7 Bluetooth: Mesh: Fix sending messages when not provisioned
The message sending APIs should fail cleanly if we are not yet
provisioned.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg
514cebcfe8 Bluetooth: Mesh: Change local_queue from k_fifo to sys_slist_t
We never access the local network interface queue in a blocking
fashing, so it's unnecessary to have all the infrastructure that
k_fifo provides. Use the simpler sys_slist_t instead.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg
092a28541a Bluetooth: Mesh: Provisioning: Introduce link open/close callbacks
It may be useful for the app to know when the provisioning link is
active and when it has been closed. This can be used e.g. to signal
the user the state of the device. Some PTS tests also require
verifying the link state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg
25604f979d Bluetooth: Mesh: Provisioning: Fix encoding of OOB values into link.auth
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg
32399a4cd2 Bluetooth: Mesh: Provisioning: Fix input OOB support
The code was missing the sending of the Input Complete PDU, and was
also setting the link.auth value too late.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg
497fef85c3 Bluetooth: Mesh: Provisioning: Fix coding style (too long line)
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg
ec6fd3575b Bluetooth: Mesh: Provisioning: Fix OOB string output
The OOB string was being generated in an incorrect way, resulting
essentially in garbage.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg
d43a92b1c8 Bluetooth: Fix clearing advertising & scanning parameters
The parameter structs for advertising and scanning contain many
members that may not get explicitly set when enabling these states. Do
a memset to zero on them to make sure we don't operate on
uninitialized memory.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-12 21:48:03 +02:00
Johan Hedberg
cb8470f3a0 Bluetooth: Mesh: Kconfig: Use a saner default ReceiveDelay
A value of 20ms means it's possible the LPN will end up doing
simultaneous advertising & scanning, which increases the risk of lost
packets. Use a default of 100ms to keep these separate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
50a656ff16 Bluetooth: Mesh: Implement handling of Friend Clear messages
Handling Friend Clear messages and sending the Friend Clear
Confirmation responses wasn't so far properly implemented. One of the
requirements is to keep sending the reponses even though we no-longer
have a friendship. This means that we need to keep the net_idx, frnd
and lpn_counter values valid, which in turn requires the introduction
of a separate "valid" boolean value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
cb89cc7fdc Bluetooth: Mesh: Kconfig: Set PTS-friendly Friendship values
The PTS tests for the Friend node expect a minimum of 16 queued
messages and the ability to have two LPNs. Set these as defaults.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
b644bad5c0 Bluetooth: Mesh: Use network transmit count and interval for Friend
When sending PDUs from Friend to LPN we should adhere to the
configured network transmit count & interval to get better
reliability for the PDUs to be received by the LPN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
ed8ed9ea7d Bluetooth: Mesh: Implement the Friend Clear procedure
When a Friend Node receives a Friend Request with a unicast
PreviousAddress that's not an element on the Friend Node, it needs to
start the Friend Clear procedure. This procedure involves sending
periodic Friend Clear messages to the old Friend of the LPN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
eb23d688f2 Bluetooth: Mesh: Fix network credential selection
The only messages that should be encrypted using the friendship
credentials are those coming through the Friend Queue on the Friend
node, most request-response pairs between LPN & Friend (exceptions are
Friend Request - Friend Offer, and Friend Clear - Friend Clear
Confirm), as well as Model Publication messages when the Friendship
Credentials Flag has been enabled in the model publication.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
d43a23652c Bluetooth: Mesh: Introduce LPN-specific adv transmit properties
When the node is in LPN node, the LPN-Friend messages has its own
retries, so doing this on the advertising level (i.e. following the
network transmit state) is sub-optimal.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
01d3940cdb Bluetooth: Mesh: Allow passing adv transmit info in net_tx
This makes it possible (in a subsequent patch) to fine-tune some
special cases, like the LPN poll messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
1d86ef0955 Bluetooth: Mesh: Use more accurate timing for LPN functions
Update the advertising callback to include the exact duration that we
will be sending out the packet. This is useful since sometimes we want
to use the end point of the advertising as the reference time to count
when some other action should take place.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
e74f4a6c39 Bluetooth: Mesh: Fix clearing friendship
Lower the attempts and make sure we track the old Friend address for
subsequent Friend Requests, in case we never receive a Clear
Confirmation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
4d7757fab1 Bluetooth: Mesh: Fix sending Friend Clear messages indefinitely
We should give up after a small number of attempts.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
b95d70c3f0 Bluetooth: Mesh: Improve Low Power establishment procedure
Add some automated policies for starting LPN establishment and make it
possible to perform the establishment in a "low power" way, i.e.
switching to low duty-cycle already when starting to send Friend
Requests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg
1f76023ad4 Bluetooth: Mesh: Fix ignoring prohibited ReceiveWindow value
According to the Mesh Spec value 0x00 of ReceiveWindow parameter is
prohibited. This is needed to pass MESH/NODE/FRND/LPN/BI-03-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 15:35:15 +02:00
Johan Hedberg
85e7a3d47e Bluetooth: Mesh: Fix typo when iterating GATT clients
The intention of the code was to access client->conn and not
clients->conn (which would always access the first client struct).

Fixes #4738

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 15:13:01 +02:00
Johan Hedberg
9c8ce3d7c4 Bluetooth: Mesh: Fix Mesh feature description in Kconfig
Use the correct term for the feature, and reformulate the help text
for BT_MESH.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 08:11:52 -05:00
Johan Hedberg
e980d45c13 Bluetooth: Mesh: Fix net_find_and_decrypt() function
The function return type was declared incorrectly. Also, the magic
checking for i after exiting the loop could cause some false positive
compiler warnings. Instead, return directly from the loop (with the
downside of duplicating a few lines of code).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 14:52:23 +02:00
Johan Hedberg
25c5d36b91 Bluetooth: Mesh: Avoid using 64-bit storage & math for beacons
It's in practice impossible for the time between two beacons to be
more than 50 hours (the approximate wrap-around time for a 32-bit
millisecond timer), so we can use a 32-bit timestamp instead of a
64-bit one for the beacon tracking.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 14:33:03 +02:00
Johan Hedberg
68f6b59e2d Bluetooth: Fix deadlock-risky HCI command buffer allocation
The LE scanning and advertising implementations were allocating and
holding buffers (the scan & advertising parameters respectively) while
at the same time potentially sending other commands (such as setting
the local private address). If these APIs would end up being called
simultaneously from different contexts, this could lead to a deadlock
in trying to allocate HCI command buffers, especially considering that
the default HCI command buffer count is 2.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 10:42:38 +02:00
Sebastian Bøe
0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe
12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
David B. Kinder
7e3ed1465f doc: fix Kconfig misspellings
Kconfig files are processed to create configuration
option documentation.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-11-08 13:50:35 -05:00
Johan Hedberg
2a74be43ea Bluetooth: Mesh: Fix network decryption in case of multiple LPNs
If we are a Friend node with multiple LPNs, we need to iterate through
all available Friendship credentials to find the right keys.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
1ecb486f17 Bluetooth: Mesh: Simplify & fix net credentials selection
The Mesh spec expects us to fall back to master credentials if
friendship ones are not available. Also remove an unnecessary branch
with the help of a new 'idx' variable.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
d118fff232 Bluetooth: Mesh: Remove unnecessary per-buffer segment context
The friend_cred and new_key information is common for all segments of
a segmented transaction, so it makes sense to store them as part of
struct seg_tx instead of each buffer's user data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
9b2a6d4866 Bluetooth: Mesh: Fix friendship credential usage for segmented messages
The friend_cred hint needs to be set already at the point of
segmenting, i.e. doing it in bt_mesh_net_send() is too late. Move the
setting to bt_mesh_trans_send() and bt_mesh_ctl_send().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
ada5771d7c Bluetooth: Mesh: Fix ignoring invalid Transport OpCode as LPN
MESH/NODE/FRND/LPN/BI-02-C requires us to ignore unknown Transport
OpCodes instead of treating them as valid responses to a Friend Poll.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
f51797335d Bluetooth: Mesh: Fix retries when establishing Friendship as LPN
The Mesh Specification recommends retrying up to 6 times the Friend
Poll when establishing Friendship as LPN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
b18f023e31 Bluetooth: Mesh: Improve debug logs for provisioning
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
f7e74dd5cb Bluetooth: Mesh: Fix provisioning with Key Refresh flag set
We should not have any valid key material in key slot 0 if the KR flag
is set, since then the new key/old key information will be incorrect
when network PDUs get decrypted.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
4492c5d072 Bluetooth: Mesh: Improve acknowledgement timer calculation
According to the Mesh Profile Specification: "The acknowledgment timer
shall be set to a minimum of 150 + 50 * TTL milliseconds".

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
8fe33607c6 Bluetooth: Mesh: Fix message replay protection
The Mesh Profile Specification states that replay protection must be
done for all control and access messages. Furthermore, the replay
protection list must be updated with the sequence from the last
segment of a segmented message (the code was only updating based on
SeqZero).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
cad1f4ce7b Bluetooth: Mesh: Fix transport layer heartbeat subscription matching
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
95d34e0583 Bluetooth: Mesh: Cfg: Implement Low Power Node PollTimeout Get fully
Now that Friend support is complete we can create a full
implementation of the LPN PollTimeout Get message.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
6abfab08d4 Bluetooth: Mesh: Fix not including RSSI into network RX context
The RSSI was supposed to be stored in the net_rx struct.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
7248e4b7c3 Bluetooth: Mesh: Add complete Friend support
Add all the missing pieces of Friend node support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg
86c32aac1c Bluetooth: Kconfig: Introduce new BT_SCAN_WITH_IDENTITY option
Even with the privacy feature disabled, the stack has so far defaulted
to using an NRPA for active scanning, in order to protect privacy.
This is mainly because it is not always clear that scanning for other
devices may risk revealing the local identity.

There may however be use cases where such revealing is actively
desired, so introduce a new option for this (which defaults to
disabled).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 14:14:17 +03:00
Johan Hedberg
e25d925242 Bluetooth: Defer RL update if there's an ongoing connection
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg
56f79f817e Bluetooth: Add support for Link Layer Privacy
Add support for loading IRKs into the controller as well as the LE
Enhanced Connection Complete HCI event. To simplify things, the old LE
Connection Complete handler translates its event into the new enhanced
one which is then the single place of processing new connection
events.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg
a74feaaf55 Bluetooth: Add missing HCI defines for LL privacy
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg
7762578de4 Bluetooth: Simplify and clean up LE scan handling
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg
9a8316061d Bluetooth: Mesh: Fix HB Sub Status when disabling subscription
MESH/NODE/CFG/HBS/BV-02-C expects it to be possible to do a Set with
the existing src & dst addresses but with a zero period in order to
"cancel" the current subscription. In such a case the addresses should
remain set but the period be set to zero, similar to what would happen
if the period would expire.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg
33826b91bd Bluetooth: Mesh: Fix clearing HB state when disabling HB sub
The heartbeat subscription Count, MinHops & MaxHops should only be
reset when enabling heartbeat subscription. Any other actions should
keep it unchanged.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg
bcc140dbe6 Bluetooth: Mesh: Fix sending heartbeat only when relay state changes
The heartbeat should only be sent in case the relay state actually
changes. This fixes MESH/NODE/CFG/HBP/BV-03-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg
c44daebe97 Bluetooth: Mesh: Fix HB Pub Count Log calculation routine
"4.1.2 Log field transformation

In order to compress two-octet values into one-octet fields, the
following logarithmic transformation is used: any two-octet value is
mapped onto a one-octet field value representing the largest integer
n, where 2^(n-1) is less than or equal to the two-octet value."

Log field transformation table:

Log Field Value         2-octet Value
0x01                    0x0001
0x02                    0x0002 through 0x0003
0x03                    0x0004 through 0x0007
0x04                    0x0008 through 0x000F
0x05                    0x0010 through 0x001F
0x06                    0x0020 through 0x003F
0x07                    0x0040 through 0x007F
0x08                    0x0080 through 0x00FF
0x09                    0x0100 through 0x01FF
0x0A                    0x0200 through 0x03FF
0x0B                    0x0400 through 0x07FF
0x0C                    0x0800 through 0x0FFF
0x0D                    0x1000 through 0x1FFF
0x0E                    0x2000 through 0x3FFF
0x0F                    0x4000 through 0x7FFF
0x10                    0x8000 through 0xFFFF

"4.2.17.2 Heartbeat Publication Count Log

The Heartbeat Publication Count Log value between 0x01 and 0x11 shall
represent that smallest integer n where 2^(n-1) is greater than or
equal to the Heartbeat Publication Count value. For example, if the
Heartbeat Publication Count value is 0x0579, then the Heartbeat
Publication Count Log value would be 0x0C."

According to this definition 2^(n-1) is an upper bound for n log
value.

Proposed Publication Count Log transformation table:

Pub Count Log Value     2-octet Value
0x01                    0x0001
0x02                    0x0002
0x03                    0x0003 through 0x0004
0x04                    0x0005 through 0x0008
0x05                    0x0009 through 0x0010
0x06                    0x0011 through 0x0020
0x07                    0x0021 through 0x0040
0x08                    0x0041 through 0x0080
0x09                    0x0081 through 0x0100
0x0A                    0x0101 through 0x0200
0x0B                    0x0201 through 0x0400
0x0C                    0x0401 through 0x0800
0x0D                    0x0801 through 0x1000
0x0E                    0x1001 through 0x2000
0x0F                    0x2001 through 0x4000
0x10                    0x4001 through 0x8000
0x11                    0x8001 through 0x10000

According to Log field transformation table 0x0579 would be
transformed to 0x0B and should be to transformed to 0x0C.

This is required to pass MESH/NODE/CFG/HBP/BV-01-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg
ebf1a3c661 Bluetooth: Mesh: Fix ignoring all prohibited sub_dst in HB Sub Set
Section 4.2.18.2 in the Mesh Profile Specification states:

"The Heartbeat Subscription Destination shall be the unassigned address,
the primary unicast address of the node, or a group address, all other
values are Prohibited."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg
6047ccd2a1 Bluetooth: Mesh: Extend advertising API with helpers for Friend support
These extensions prepare the way of implementing full Friend support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg
91e75985bd Bluetooth: Mesh: Fix and clean up IV Update procedure
This patch fixes issue when receiving iv index greater than current
index + 42 in update mode. According to Specification when node is in
update state it should only accept iv index equal to the current iv
index. When node is in normal mode it should ignore index that is
greater than current index + 42.

This allows to pass MESH/NODE/IVU/BI-02-C.

Also this patch cleans up the iv update procedure, to make it easier
to read.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg
b0a43b9d3c Bluetooth: Mesh: Return change information from bt_mesh_iv_update()
This will soon be useful to the callers of bt_mesh_iv_update(), in
particular Friend support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg
e1b381c58f Bluetooth: Mesh: Export bt_mesh_friend_cred_get() for Friend usage
This function will soon be needed by the Friend support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg
020425f61a Bluetooth: Mesh: Remove redundant assignment
This value is assigned again a few lines later.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg
a6ce33d7ea Bluetooth: Mesh: Cfg: Only update friend state if supported
If Friend support is not available we should not modify the value of
cfg->frnd.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg
ab84517b45 Bluetooth: Mesh: Export some transport layer helpers
These will soon be needed by the Friend code to compose messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg
ae714e4028 Bluetooth: Mesh: Add bt_mesh_net_flags() helper function
This reduces code in various places needed to construct a flags value
for a given subnet.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg
b8e2c9a40f Bluetooth: Mesh: Fix TX segment context lookups
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg
2f9171c3ac Bluetooth: Mesh: Take advantage of BT_MESH_NET_HDR_LEN define
Avoid using hard-coded magic numbers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg
799ee46b5c Bluetooth: Mesh: Keep received buffer intact until transport layer
The lower transport layer is responsible e.g. for the Friend Queue, so
we need to have the buffer in its original parsing state there.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Szymon Janc
3b1cb4a309 Bluetooth: Mesh: Fail init on keys generation error
Fail on Mesh initialization if provisioning is enabled and keys were
not generated. This make it simpler to debug misconfigured devices.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-11-02 15:52:07 +02:00
Johan Hedberg
7166920a1d Bluetooth: Add option to use heuristics for VS HCI detection
On targets where non-Zephyr controllers are likely, such as qemu, it
may be harmful to try to issue any of the vendor HCI commands, since
non-Zephyr controllers may interpret them in completely different
ways.

Introduce a Kconfig option that, when enabled, uses some simple
heuristics (HCI version & lack of public address) to try to guess in
advance whether the Zephyr HCI vendor extensions are supported or not.
The new option is available for any host-only configuration and is
enabled by default for the qemu targets.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-02 14:51:42 +02:00
Vinayak Kariappa Chettimada
6016ccffe8 Bluetooth: controller: Fix diff proc collision with enc proc
Fixes the following conformance test regression failure
introduced in commit 7dd5fbee26 ("Bluetooth: controller:
Fix MIC error due to parallel Enc Proc")

TP/CON/MAS/BV-28-C [Initiating Connection Parameter Request
different procedure collision encryption]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-02 10:26:09 +01:00
Vinayak Kariappa Chettimada
7dd5fbee26 Bluetooth: controller: Fix MIC error due to parallel Enc Proc
Fix to disallow initiating LE Start Encryption while another
procedure is in progress. Similarly, disallow initiating
another procedure while Encryption procedure is in progress.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-01 16:35:29 +01:00
Vinayak Kariappa Chettimada
8edcbade9a Bluetooth: controller: Fix to enable Asym PHY on nRF52 Series
Fix the controller Kconfig to enable use of fast radio ramp
up by default, hence enabling support for Asym PHY updates
by default on nRF52 Series SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-30 14:51:18 +01:00
Vinayak Kariappa Chettimada
0328ecf6fc Bluetooth: controller: Fix Ctrl PDU Tx starvation assert
Replace all controller asserts in control procedure responses
that checked for buffer availability with an implementation
that nacks request PDUs if there are no buffer to prepare
response PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-25 16:16:47 +02:00
Vinayak Kariappa Chettimada
482771c497 Bluetooth: controller: Remove assert on invalid LL id
Remove an assert on receiving invalid LL id, drop these
invalid PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-25 14:54:17 +02:00
Johan Hedberg
c2f0dad29d Bluetooth: Mesh: Improve Network Message Cache behavior
The implementation of the Network Message Cache has so far been
suboptimal, since it has treated the same packet with different TTL
values as different packets. Since one of the purposes of this cache
is to prevent unnecessary relaying, it's important that we don't let
the TTL value influence the "hash" that's used for matching messages.

This patch changes the hash to consist of most of the IV Index (three
least significant bytes of it), the sequence number and the source
address, which should give fairly optimal matching behavior.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-24 18:23:36 +03:00
Johan Hedberg
afc9b5098b Bluetooth: Mesh: Update TODO with current status
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-20 17:53:31 +03:00
Carles Cufi
493852bac3 Bluetooth: controller: Fix flow control packet drop
The main purpose of recv_thread is to process incoming events from the
radio and also any buffered items waiting to be dispatched to the Host
and that are pending because of lack of Host buffers.
When an iteration of the recv_thread obtains a element from the radio it
needs to process it immediately, either sending it straight away to the
Host or appending it to the queue. This was not the case before this
patch, where the concurrency of a buffered packet with one coming from
the radio would cause the latter to be "dropped", causing missing
packets.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-18 14:43:39 +02:00
Johan Hedberg
328f80fa07 Bluetooth: Fix memory leak of command response buffer
There was a missing net_buf_unref() for the response to reading the
controller static addresses.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-17 17:40:00 -04:00
Johan Hedberg
aaeff3c165 Bluetooth: Add basic host-side support for HCI vendor extensions
Add skeleton for HCI vendor extenstions and convert the nRF5x-specific
static address setting to use the HCI VS commands instead.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-17 15:01:54 +03:00
Carles Cufi
5c49afc9ec Bluetooth: controller: Fix Controller to Host flow control leak
When a connection is disconnected with outstanding unacked packets, the
Host has no way to signal or acknowledge their processing to the
Controller, since it is illegal to send a Host Number of Completed
Packets command when the connection is not up. Instead, consider the
outstanding packets as acked in order not to affect the correct flow
control.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-17 13:10:08 +02:00
Johan Hedberg
092ec23024 Bluetooth: Mesh: Fix missing feature bits
The feature bits for Proxy and Friend were missing in the composition
data and heart beat messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-17 13:18:39 +03:00
Steve Brown
db0ee4ea62 Bluetooth: Mesh: heartbeat fixes for message count
Both count and period must be non-zero for message publication
Stop publication when count becomes zero
Add count to debug message in hb_publish

Signed-off-by: Steve Brown <sbrown@cortland.com>
2017-10-17 08:35:18 +03:00
Luiz Augusto von Dentz
49c895815a Bluetooth: L2CAP: Increase disconnect timeout to 2 seconds
There have been situations where the remote stacks cannot responds
within a second, so increases it to 2 seconds. The timeout has to be
relatively short as the channel cannot be reused while disconnecting.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-10-15 15:50:38 +03:00
Luiz Augusto von Dentz
5115cb16cf Bluetooth: L2CAP: Fix sending MPS that cannot be fully used
MPS shall never be bigger than MTU + 2 as the remaining bytes cannot
be used since the SDU is limited to length + MTU.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-10-15 15:50:38 +03:00
Vinayak Kariappa Chettimada
52bc2b6cd1 Bluetooth: controller: Add Coded PHY packet tx time restrictions
Add implementation to support Coded PHY update procedure
with packet transmit time restrictions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:47:47 +02:00
Vinayak Kariappa Chettimada
77eb73b505 Bluetooth: controller: Add encrypted Coded PHY support
Add support for encrypted Coded PHY connections on nRF52840
SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:45:02 +02:00
Vinayak Kariappa Chettimada
559c0248d5 Bluetooth: controller: Fix PA/LNA for Coded PHY
Use S8 coding Rx chain delay timings to calculate the PA
pin assertions when in Coded PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:43:45 +02:00
Vinayak Kariappa Chettimada
f5d744b998 Bluetooth: controller: Fix tIFS calc for Coded PHY
Always use S8 Rx Chain Delay instead of the actual Rx-ed
packet coding. I believe, as the packet always start with
S8, hence S8 timings when used the tIFS is near correct
value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:43:45 +02:00
Vinayak Kariappa Chettimada
3ab134de9e Bluetooth: controller: Fix Coded PHY supervision timeout
When calculating and setting up the header compelte timeout
use S8 coding Rx chain delay.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:43:45 +02:00
Vinayak Kariappa Chettimada
6a8f22eeab Bluetooth: controller: Fix connection update supervision timeout
In the commit dd52b8ea02 ("Bluetooth: controller: Fix
first connection interval timing"), instead of using just a
tick unit as workaround, microseconds corresponding to a
tick unit was used while calculating the window offset to be
used at the connection update instant. This introduced an
error in scheduling the first event with new connection
parameters, causing supervision timeout of connection update
procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-14 12:20:45 +02:00
Johan Hedberg
fccdb28154 Bluetooth: Mesh: Fix mod sub status parameters upon failure
Mesh Profile Specification v1.0, 4.4.1.2.8:

"When an element receives a Config Model Subscription Add message
or a Config Model Subscription Virtual Address Add message that
is not successfully processed (i.e., it results in an error condition
listed in Table 4.113), it shall respond with the Config Model
Subscription Status message, setting its fields to the values
of the corresponding fields (i.e., the identically named fields)
of the incoming message and setting the Status field to a status code
(defined in Table 4.113), and setting all other fields to 0."

The same applies to other Model Subscription messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-13 17:24:31 -07:00
Johan Hedberg
02b2b8cf65 Bluetooth: Mesh: Fix potential access to uninitialized variable
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-13 17:24:31 -07:00
Johan Hedberg
ee217d4051 Bluetooth: Fix freeing up conn->tx_notify upon disconnect
It's possible that tx_notify still contains items when a Disconnect
Complete happens. Since the normal path for processing tx_notify is
not taken when the connection is not in CONNECTED state, we must make
sure to process the list latest in conn_cleanup() that's called as one
last thing before the connection object is freed up.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-13 17:23:46 -07:00
Vinayak Kariappa Chettimada
bebffd3dc6 Bluetooth: controller: Fix missing reset of FC feature
Fixed a missing reset of FC feature on HCI reset. This
feature provided a simple connection handle based event
exclusions, but this is no longer needed with the
support for controller to host flow control. This feature
should be removed in the future.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-13 09:23:54 +02:00
Johan Hedberg
c136a2eb83 Bluetooth: Fix reporting packets for disconnected connections
A connection might have gotten disconnected by the time that an ACL
buffer is free up, in which case there is no need to send a HCI
command for it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-12 22:02:14 -05:00
Vinayak Kariappa Chettimada
278df482a9 Bluetooth: controller: Fix missing PHY update procedure reset
When a peer master performed a PHY update procedure with no
change, the state machine was not released. This blocked
any future local initiation of the procedure and also
leading to termination of connection with reason LMP
response timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-12 11:03:51 +02:00
Vinayak Kariappa Chettimada
7cc796771b Bluetooth: controller: Fix NRF_AAR use
Fixed the usage of NRF_AAR peripheral for controller privacy
to clear events on configure and on every radio ISR entry.

Without this fix, there was spurious AAR matches leading to
controller asserts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-11 22:21:10 +02:00
Vinayak Kariappa Chettimada
e454862600 Bluetooth: controller: Fix PHY Update response state transition
PHY Update procedure timeout was started without transition
to the state that waits for the procedure to complete. This
prevented the timeout from being reset on successful
completion of the procedure and eventually leading to a
connection termination with reason LMP Response Timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-11 14:07:33 +02:00
Vinayak Kariappa Chettimada
f64cccfea9 Bluetooth: controller: Fix CPR procedure's Conn Upd initiation
Fix Connection Parameter Request Procedure's Connection
Update Procedure initiation to calculate the offset rather
than selecting offsets from an out-of-bound memory area.

The symptoms of the bug was noticed as a supervision timeout
due to use of incorrect offset communicated to peer and a
wrong offset used in scheduling the connection events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-11 09:57:36 +02:00
Vinayak Kariappa Chettimada
8ab1a1112b Bluetooth: controller: Fix Conn Param Req response timeout
When the peer slave rejects a Connection Parameter Request
Procedure, the controller proceeds to perform a Connection
Update Procedure without clearing the procedure timer that
causes the connection to terminate eventually. This is
fixed by clearing the procedure timeout when the Connection
Update Procedure completes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-10 10:10:23 -04:00
Vinayak Kariappa Chettimada
c707c82fc8 Bluetooth: controller: Fix slave from initiating conn upd ind
If a peer master role has support for Connection Parameter
Request Procedure set in its supported features but would
send an Extended Reject Ind as response to the procedure
then the controller incorrectly initiated a Connection
Update Procedure which is not permitted in a slave role.

This would lead to connection timeout after the used instant
in the invalid Connection Update Procedure.

This is fixed by initiating a Connection Update Procedure
only if in a master role.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-10 10:09:49 -04:00
Johan Hedberg
44d4c06b70 Bluetooth: Mesh: Fix missing initialization of bt_mesh.local_queue
The local_queue was never being initialized.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-09 20:40:36 +03:00
Johan Hedberg
d1dd19880d Bluetooth: Mesh: Fix revoking app keys
The needed code for taking updated app keys into use and revoking the
old ones was missing.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-09 19:46:10 +03:00
Johan Hedberg
3993814e94 Bluetooth: Add helper to iterate all key objects
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-05 13:14:08 +03:00
Johan Hedberg
a2db217e15 Bluetooth: Clean up address-to-string usage & implementation
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-05 13:14:08 +03:00
Johan Hedberg
8d02ab52ad Bluetooth: Add command opcode to warning about unusual pool id
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-05 13:14:08 +03:00
Carles Cufi
e0c1c0aa64 Bluetooth: controller: Common config for VS extensions
Since the Zephyr HCI VS extensions apply to both the Host (using them
for additional functionality) and the Controller (implement the commands
and events), it make sense to make this a common setting in order for it
to be configurable in a way that applies to both.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-03 17:57:49 +03:00
Carles Cufi
09330fa7b0 Bluetooth: controller: Disable PA/LNA for nRF51x
The PA/LNA feature is not functional on nRF51x series due to added
interrupt latency. Disable this feature unconditionally for those ICs to
avoid unexpected behavior.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-02 12:04:43 +02:00
Vinayak Kariappa Chettimada
6831351799 Bluetooth: shell: Add controller DTM commands
Add controller Direct Test Mode commands to bt shell module.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 20:56:11 +02:00
Vinayak Kariappa Chettimada
e95fd2860d Bluetooth: controller: Fix HCI Reset hang
Issuing HCI reset command while having connections sometimes
hung the controller.

ll_reset supplied invalid stop ticker id to role_disable
when trying to stop all connections. Connection role does
not utilize stop ticker. The invalid ticker id supplied
referenced memory outside the pool of tickers and based on
what the content is in RAM there, the controller would hang
trying to stop connections.

Fixed by not calling the ticker_stop interface with invalid
ticker ids.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 15:47:36 +02:00
Vinayak Kariappa Chettimada
b97b9c4fef Bluetooth: controller: GPIO PA/LNA feature
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 15:38:31 +02:00
Carles Cufi
6cfac15c68 Bluetooth: controller: Add PA/LNA GPIO Kconfig option
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 15:38:31 +02:00
Johan Hedberg
029780a196 Bluetooth: Mesh: Fix dropping valid proxy configration messages
Proxy configuration messages are allowed (in fact required) to use
unassigned addresses, so they should be exempt from this check.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg
a576c4a73b Bluetooth: Mesh: Don't send health status messages if a test fails
The test failure may be e.g. because of an unknown company id, and in
that case the spec expects us to ignore the message.

With this patch it should be possible to pass MESH/SR/HM/RFS/BI-01-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg
8d0ef1eb85 Bluetooth: Mesh: Fix setting health period divider
A previous patch which moved dispatching the health publish callback
to a later moment introduced a regression where the period divider
does not get updated when it should. In fact, having the divider as
part of the Health Server context is redundant, since the same
information is already stored generically in the model publication
context. Switching to using the model publication context makes things
simpler and ensures that the value is always up-to-date.

With this patch it is possible to pass MESH/SR/HM/CFS/BV-02-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg
4d3a2c66d1 Bluetooth: Mesh: Fix Set LPNTimeout message handling
We should ignore invalid addresses (helps pass
MESH/NODE/CFG/LPNPT/BI-01-C). Also fix a copy-paste issue in an error
log.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg
19c304086f Bluetooth: Mesh: Fix resetting heartbeat subscription expiry properly
Set the value clearly to 0 instead of letting the old expiry time stay
around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg
f1638e0a2b Bluetooth: Mesh: Fix zeroing heartbeat state
The values all need to be zeroed when heartbeat subscription is
disabled. This makes it possible to pass MESH/NODE/CFG/HBS/BV-01-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg
ea397170d3 Bluetooth: Mesh: Fix spelling of "heartbeat"
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg
53d06a1653 Bluetooth: Mesh: Fix encoding fault count to Health Current Status
There was a missing adjustment to buf->len after fetching the faults
from the app.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg
a3a481deb1 Bluetooth: Mesh: Fix Health Period Set OpCode
This was a copy-paste mistake.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Carles Cufi
3b2120f500 Bluetooth: controller: Implement Read Build Info cmd
Implement the Read Build Information VS command. This returns a UTF-8
encoded string, which is extendable by the user via a new Kconfig
option.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-28 15:41:49 +02:00
Carles Cufi
573c1c9071 Bluetooth: controller: Implement Write BD_ADDR VS cmd
Implement the Zephyr VS command that allows a Host to write a public
Bluetooth Address to the Controller in order to allow Hosts to provide
their own public Bluetooth addresses.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-28 15:41:49 +02:00
Johan Hedberg
d712a4e1a3 Bluetooth: Mesh: Remove local network interface Kconfig option
From section 3.4.5.3 in the Mesh Profile Specification 1.0:

    "A node shall implement a Local Network Interface."

Removing the Kconfig option also helps clean up quite a lot of code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 16:33:06 +03:00
Johan Hedberg
76fd02ee0c Bluetooth: Mesh: Allow TTL <= 1 for the local net interface
The bt_mesh_net_relay() function needs to allow TTL <= 1 for the local
network interface since that's the code path that locally originated
outgoing packets take.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 16:33:06 +03:00
Johan Hedberg
418cdadeab Bluetooth: Mesh: Send ack for every message with matching FCS
Mesh Profile Specification v1.0, 5.3.3:

"On the PB-ADV bearer, when the receiver has received all segments of
a transaction, the receiver shall calculate the FCS for the received
Provisioning PDU, and if it matches the FCS field in the Transaction
Start PDU, it shall send a Transaction Acknowledgment PDU after
a random delay between 20 and 50 milliseconds."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg
7e779ba69b Bluetooth: Mesh: Always set company ID in health status message
The Mesh specification recommends defaulting to the company ID in the
composition data when no other ID is relevant (e.g. in error cases or
if the app has not provided a callback).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg
ac5140891b Bluetooth: Mesh: Set timer for periodic publish before publishing
Encrypting and sending a message takes a considerable amount of time
which makes the publication period longer than expected.

With this patch it is possible to pass MESH/SR/HM/CFS/BV-02-C test.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg
fc679c50f9 Bluetooth: Mesh: Fix encoding health status when app has no callback
The branch for handling the case when the app has not provided a
callback for health faults was encoding the payload in a wrong way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg
6b966e4b96 Bluetooth: Mesh: Fix copy-paste mistake when assigning to cfg->frnd
The right value is BT_MESH_FRIEND_NOT_SUPPORTED.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg
5363f6e765 Bluetooth: Mesh: Drop invalid destination addresses
This is required to pass certain PTS tests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg
68b459ec41 tests: bluetooth/at: Fix string signedness issues
To avoid signedness issues with some compilers, like icx, use 'char *'
instead of 'unsigned char *' for the at_client buffer.

Fixes #3600

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-26 12:56:50 +03:00
Johan Hedberg
c40dc580b0 Bluetooth: Mesh: Fix SDU length check
The code was passing the wrong first parameter to the sdu_len_is_ok()
function.

Fixes #3985
Fixes #3984

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-26 12:56:23 +03:00
Johan Hedberg
3341439f98 Bluetooth: Mesh: Fix string signedness issue
Some compilers (like icx) may complain about unsigned vs signed
strings.

Fixes #3985

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-26 12:56:23 +03:00
Johan Hedberg
bac7367b0a Bluetooth: SMP: Fix responding to Pairing Failed PDUs
It makes no sense to respond with Pairing Failed PDU to another
Pairing Failed PDU.

Jira: ZEP-2620

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-25 14:38:34 +03:00
Vinayak Kariappa Chettimada
f0274c9e52 Bluetooth: controller: Move tIFS s/w switch PPI index up by one
Move the use of tIFS software switching PPI index set up by
one position to make place for use of PA/LNA implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 16:14:43 +02:00
Vinayak Kariappa Chettimada
74cd8d852e Bluetooth: controller: Use single PPI channel for AA capture
Earlier design captured AA twice in the first Rx in a slave
connection event and retained one of the capture until end
of event to calculate drift.

Design updated to use single capture of AA and save the
first AA capture in a slave connection event in RAM instead.

This frees up a PPI channel in the controller design.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 16:14:27 +02:00
Vinayak Kariappa Chettimada
3cd37866cc Bluetooth: controller: Internal document purpose of end capture
Document internal the purposes of various Tx/Rx PDU end
capture setup.

Also, removed any redundant capture of packet end.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 15:18:37 +02:00
Vinayak Kariappa Chettimada
4cb7b949dc Bluetooth: controller: Minor refactor radio_tmr_start
Minor refactor of radio_tmr_start to reduced duplicate
assignments common in if-then-else control path.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 15:18:07 +02:00
Vinayak Kariappa Chettimada
492d9d9a06 Bluetooth: controller: Map debug pins to P3 pin head on nRF5x DK
Updated debug pin mapping so that the outputs are on P3 pin
head on all nRF5x Development Kits.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:25:55 +02:00
Vinayak Kariappa Chettimada
4d3a07b8be Bluetooth: controller: Add radio setup HAL interface
Added a new interface to perform setup of radio hardware.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada
a952d47a31 Bluetooth: controller: Fix NRF_CCM config for 2M PHY
Fixed the configuration of NRF_CCM for 2M PHY connections.
Now faster 2M data rate mode will be used when a connection
is in 2M PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada
ea431f5fce Bluetooth: controller: Use correct NRF_AAR enable define
Use correct NRF_AAR enable macro defines from Nordic MDK.
Old code funtionally worked fine even though not setting
the correct enable value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada
247488c038 Bluetooth: controller: Remove unreachable workaround code
A workaround code for nRF52840 under nRF51 conditional
compilation is removed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada
20c4db8197 Bluetooth: controller: Fix conn param req procedure timeout
Fixed a bug in the implementation of Connection Parameter
Request Procedure when initiated in master role caused the
connection to terminate with reason LL response timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:15 +02:00
Carles Cufi
d627ae4802 Bluetooth: controller: Fix handling of Read Static Addrs cmd
The status in the Command Complete event was uninitialized, leading to
incorrect contents of the event parsed by the Host. Correctly initialize
the status to success.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-14 17:15:23 +02:00
Vinayak Kariappa Chettimada
e17e495af8 Bluetooth: controller: Fix hang on directed adv timeout
During testing it was discovered that directed advertising
timeout is missing implementation to handle the timeout
happening while next event is already in preparation.
The consequence was that after the event ticker expired,
the counter is shutdown, stalling the setup PPI from
starting the erroneous advertising, leaving the controller
in an invalid hung state.

This has been fixed by correctly handling the cases, stop
between prepare and event, and stop inside radio advertising
event. The fix takes care of putting the radio active
callback and HF clock in the correct states.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-13 18:03:14 +03:00
Carles Cufi
b77b8e615b Bluetooth: controller: Issue Data Buffer Overflow event
Whenever the HCI ACL flow control is violated by the Host, a Data Buffer
Overflow event is now issued by the Controller (if enabled) to notify
the Host of the buffer overrun.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-13 14:17:32 +02:00
Vinayak Kariappa Chettimada
29e9d14420 Bluetooth: controller: Add checks to detect radio ISR latency
Added missing asserts to catch high CPU use in radio ISR and
latencies, without which if radio packet pointer is not set
correctly, would cause spurious transmissions and invalid
behavior.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada
934d512223 Bluetooth: controller: Optimize the loop in nRF5 hal rand get()
Optimised the get() function in nRF5 hal rand implementation
to reduce number of probable branching operations.

This is needed to reduce nRF51 platform's CPU use in radio
ISR when using the fast encryption setup implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada
5164d4b189 Bluetooth: controller: Move RSSI sampling after pkt processing
Move the code to acquire the RSSI sample after critical
control path that processes PDUs.

This is needed to reduce the time taken to assign the next
packet ptr inside radio ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada
2cc2be707a Bluetooth: controller: Inline the packet_rx_reserve_get() func
Simplify and inline the packet_rx_reserve_get() functions
used inside radio ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada
ed3aa170f3 Bluetooth: controller: Remove redundant use of auto variable
Removed use of a redundant auto variable that was assigned
and referenced only once.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada
09368217d4 Bluetooth: controller: Fast enc setup with ccflags -Ofast
To meet CPU time usage restricts inside radio ISR on nRF51
SoCs, use ccflags -Ofast when using fast encryption setup
implementation in the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada
9182de5f0b Bluetooth: controller: Disable DLE and PHY upd proc for nRF51
Default to n the support for Data Length Update and
PHY update procedures on nRF51 SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Steve Brown
dfebd40ce1 Bluetooth: Mesh: Avoid spurious "No matching AppKey" warning
Signed-off-by: Steve Brown <sbrown@cortland.com>
2017-09-07 14:26:45 -05:00
Vinayak Kariappa Chettimada
f43e4e0637 Bluetooth: controller: Fix assert on peer unknown rsp
Fixed an assert when peer responded with unknown rsp to
slave feature request when an existing another control
procedure was in progress.

This assert happened with a BT v4.0 peer implementation that
was performing a channel map update and local controller
initiated a slave feature request, receiving an unknown
response.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 05:51:46 -05:00
Łukasz Rymanowski
d3862d7b39 Bluetooth: mesh: Clear link TX when ACK arrived on it
Without this fix there is an issue when doing PB-ADV provisioning
with PTS. We keep retransmitting Public Key which is ACKed by PTS and
this leads to transaction timeout as PTS does not send confirm probably
because it keep receiving PK from us.

This patch also makes sure that transaction id is between 0x80 - 0xFF

Signed-off-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
2017-09-05 09:25:49 -05:00
Łukasz Rymanowski
dbb90a1a99 Bluetooth: mesh: Fix failed provisioning response
Needed for following PTS test cases:

MESH/NODE/PROV/UPD/BV-10-C
MESH/NODE/PROV/BI-02-C

Signed-off-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
2017-09-05 09:25:49 -05:00
Vinayak Kariappa Chettimada
4f87ad2ec1 Bluetooth: controller: Fix a bug in ctrl and data management
Fix the control and data packet management implementation
discovered during conformance testing.

This fixes:
TP/SEC/MAS/BV-12 [Master Start Encryption: Overlapping
Procedure]
TP/SEC/MAS/BV-13 [Master Start Encryption: Overlapping
Procedure with LL_SLAVE_FEATURES_REQ]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-05 09:16:19 -05:00
Carles Cufi
93ca60b733 Bluetooth: controller: Require nRF52 for privacy
Privacy on nRF51 is not passing the conformance and qualification tests
due to the time it takes to execute the privacy code while in ISR. Until
we come up with a way of optimizing and/or deferring the work, do not
allow privacy on nRF51 targets.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-05 07:55:05 -04:00
Carles Cufi
3df18ff277 Bluetooth: controller: Fix Read Version Info VS cmd
Use the macros generated during the build and located in version.h to
fill in the version information in the Read Version Information VS
command. Additionally reply with the correct hardware identifiers when
running on Nordic hardware.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-04 14:46:13 -04:00
Carles Cufi
80e0f7939e Bluetooth: controller: Add DTM HCI commands
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-04 06:08:09 -04:00
Vinayak Kariappa Chettimada
37c7551120 Bluetooth: controller: Add Direct Test Mode support
Added controller implementation to support Direct Test Mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-04 06:08:09 -04:00
Carles Cufi
b276eeabc7 Bluetooth: controller: Fix Coverity unreachable code
CID: 175182

Use #else to avoid Coverity warning about unreachable code.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-04 06:06:29 -04:00
Vinayak Kariappa Chettimada
4225b7985e Bluetooth: controller: Fix pointless expression
Seems due to incorrect rebase in commit 07270e52ba
("Bluetooth: controller: Coding style and refactoring"),
commit 95d55a2bfc ("Bluetooth: controller: Do not skip
one-shot tickers with slot"), and
commit 4ba2bb0d1c ("Bluetooth: controller: Be fair when
pre-empting a ticker"), a pointless expression was
introduced, fixed it.

Coverity-CID: 171563

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-02 04:53:30 -04:00
Łukasz Rymanowski
c90e09aa88 Bluetooth: mesh: Fix for key size
For input method we should use input_size instead of output_size

Signed-off-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
2017-09-01 09:31:41 -04:00
Johan Hedberg
f7654a787e Bluetooth: Mesh: Fix setting the right value for Static OOB type
The code was setting the wrong bit of the Static OOB Type when a
static value has been provided.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-01 09:30:54 -04:00
Vinayak Kariappa Chettimada
38b148023e Bluetooth: controller: Fix assert on connection establishment
Fixes an assert during connection establishment when the
initiator overflows the initiator window in time while
sending the CONNECT_IND PDU. The actual window is one low
frequency tick less, hence corrected the check that permits
the transmission of CONNECT_IND PDU inside the initiator
window.

Symptom was, stopping of the scanner's ticker succeeds on
connection establishment, but next interval prepare was
already run when continuous scanning was used, breaking the
design, hence there was an assert.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-31 14:31:55 -04:00
Carles Cufi
2874841576 Bluetooth: Controller: Add Read Key Hier. Roots VS cmd
Implement the Zephyr Read Key Hierarchy Roots command, returning the IR
and ER present in nRF5x ICs when compiling for those.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-30 08:18:42 -04:00
Carles Cufi
b7a5fab4cf Bluetooth: controller: Add Read Static Addresses VS command
Implement the first Vendor-Specific Command of the Zephyr specification
other than the 3 mandatory ones already present in the codebase, along
with a Kconfig option to enable and disable the presence of the VS
commands.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-30 08:18:42 -04:00
Carles Cufi
7924d16aef Bluetooth: controller: Fix broken switch statement
Add a missing break that was forgotten when we introduced the Read TX
Power command.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 16:25:11 +02:00
Luiz Augusto von Dentz
7d01c5ecb7 poll: Enable multiple threads to use k_poll in the same object
This is necessary in order for k_queue_get to work properly since that
is used with buffer pools which might be used by multiple threads asking
for buffers.

Jira: ZEP-2553

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-08-25 09:00:46 -04:00
Vinayak Chettimada
2b2eb9bb07 Bluetooth: controller: Refactor Conn Param Req implementation
Refactor the Connection Parameter Request Procedure to be
separate from and not overlap the variables of the
Connection Update Procedure.

Also, added missing implementations to pass all Connection
Parameter Request Procedure related Conformance Tests.

Jira: ZEP-1918

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-25 12:51:01 +02:00
Carles Cufi
f597c8120e Bluetooth: controller: Add LE Read Chan Map command
Implement the LE Read Channel Map HCI command, along with making the
reading of the multi-byte channel map value from the connection pointer
thread-safe in case the ISR triggers while we are reading the value.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 11:27:22 +02:00
Carles Cufi
a5fcafa155 Bluetooth: controller: Add Read TX Power commands
Although the current BLE controller only supports a single TX power (0
dBm), the qualification tests require the 2 Read TX Power to be
present and supported in the controller, so implement them while
returning always 0 dBm.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 11:27:22 +02:00
Carles Cufi
7bfa0ef47b Bluetooth: controller: Implement Read RSSI command
When the CONFIG_BT_CTLR_CONN_RSSI option is set, the connection RSSI is
available in the controller, and can be reported to the Host via the
Read RSSI command. Implement the command, which is required for
qualification.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 11:27:22 +02:00
Carles Cufi
94bab6ca8c Bluetooth: controller: Fix Read Peer RPA Command
There are 2 possible interpretations regarding the address to return in
response to the Read Peer RPA HCI Command:

1) The RPA that the local controller generates to be used in certain
packets it sends
2) The RPA generated and used by the peer device in its packets

We used to return 1) but our interpretation turned out to be incorrect
when reading the HCI test specification, so this commit switches to
returning 2).

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-22 15:22:25 +02:00
Carles Cufi
523a9dfe8a Bluetooth: controller: Fix RL index check
In the ll_rl_pdu_adv_update() function, the check to verify if we are
dealing with an item from the resolving list or else with a simple
standard non-privacy enabled device was left over from the previous
iteration, which used negative values. Replace that check with the
proper current one, using the size of the rl array as an indicator of
whether the index is valid.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-21 18:49:59 +02:00
Vinayak Kariappa Chettimada
dd52b8ea02 Bluetooth: controller: Fix first connection interval timing
Due to varying remainder value, first interval will need to
consider the remainder value used in microsecond timing from
the start of the initiator window.

Also the tx chain delay and ready delay must be substract
after the window offset is calculated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-21 17:37:43 +02:00
Carles Cufi
558be2e02c Bluetooth: controller: Enable Read Remote Ver Info bit
The Read Remote Version Information command is supported on the BLE
controller, enable the bit in Read Local Supported Commands to reflect
this.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-21 08:42:24 -04:00
Vinayak Kariappa Chettimada
6a39ed084f Bluetooth: controller: Add Minimum Number of Used Channels Proc
Add implementation to support Bluetooth 5.0 Minimum Number
of Used Channels Procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-21 08:41:56 -04:00
Vinayak Kariappa Chettimada
cb90fbe56a Bluetooth: controller: Fix controller assert at clock rollover
Fix controller assert due to a bug introduced in commit
07270e52ba ("Bluetooth: controller: Coding style and
refactoring").

This reverts implementation to original way it was and the
calculation of the ticker expiry will now not overflow the
range of the RTC peripheral, which is a 24 bit counter.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-18 15:34:19 +02:00
Ricardo Salveti
60a908c9c9 Bluetooth: Kconfig: fix default value and range for BT_RX_STACK_SIZE
Fix checks for BT_HCI_RAW and move default range after the other range
options, required by Kconfig to avoid overwriting other options.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-17 21:11:50 +03:00
Andrzej Kaczmarek
dedb70d864 Bluetooth: Fix formatting string for storage directory name
Precision specifier is not supported by printk(), let's use
zero padding instead.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2017-08-17 11:16:03 +03:00
Carles Cufi
e0194750cf Bluetooth: controller: Fix RSSI sign
The RSSI value is an 8-bit signed integer. Since the Link Layer works
only with positive unsigned integers, translate into a negative number
at the HCI layer.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-17 10:02:07 +02:00
Paul Sokolovsky
cf43be1a2e Bluetooth: Increase CONFIG_BT_HCI_TX_STACK_SIZE for BT_SPI
Older value of 256 was introduced in 1.7 times. Testing on
BOARD=96b_carbon with 2 weeks old codebase however showed that TX
thread stack however can grow to 324 bytes. Finally, with the
latest master, following stacks are reported on BLE disconnect
(with CONFIG_INIT_STACKS enabled):

rx stack (real size 1024): unused 452 usage 572 / 1024 (55 %)
tx stack (real size 384):  unused 16  usage 368 / 384 (95 %)

Two outcomes:

1. TX stack needs increase.
2. Over time, the stack usage grows, plus variations in SPI
drivers should also be taken into account.

So, increase the stack size to 416 bytes, to leave some headroom
beyond the immediate values seen on 96b_carbon.

Jira: ZEP-2510

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-16 14:54:20 +03:00
Ricardo Salveti
8dbb388000 samples: Bluetooth: add HCI SPI raw handler sample
Add a sample application that allows a Zephyr-based Bluetooth
controller to interface with an HCI driver via SPI. This sample
implements the same BT SPI protocol already as Zephyr's HCI SPI
driver.

Currently, the sample only supports the legacy SPI API.

Provide a single configuration file, avoiding board-specific
files. Some board-specific configuration information must be provided
via other means:

- CONFIG_BT_CONTROLLER_TO_HOST_SPI_DEV_NAME
- CONFIG_BT_CONTROLLER_TO_HOST_SPI_IRQ_DEV_NAME
- CONFIG_BT_CONTROLLER_TO_HOST_SPI_IRQ_PIN

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-15 22:58:02 +03:00
Marti Bolivar
4e53f4e830 Bluetooth: Kconfig: delete stray double quote
Trivial fix.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-15 22:58:02 +03:00
Carles Cufi
fc965e5554 Bluetooth: controller: Split Ext Scan Filter Policies out
Since Extended Scanner Filter Policies is an independent feature from
Controller-based Privacy, split it out so it can be built independently
and included without it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-15 22:55:15 +03:00
Paul Sokolovsky
0592c0ce59 Bluetooth: shell: gatt_read: Reset offset to 0
Unless offset was specified, it should default to 0, whereas
previously, value from the last command was used.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-15 21:16:40 +03:00
Carles Cufi
03a75e17dd Bluetooth: controller: Enable Extended Scan Filter Policies bit
Whenever privacy is enabled, we support the Extended Scan Filter
Policies functionality, and therefore we must show it in the bitfield of
LE supported features for the controller.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-14 21:06:51 +02:00
Carles Cufi
d5c13a7530 Bluetooth: controller: Rename Kconfig prefix
Rename the BT_CONTROLLER prefix used in all of the Kconfig variables
related to the Bluetooth controller to BT_CTLR.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-14 15:44:56 +03:00
Johan Hedberg
01df52c2b7 Bluetooth: Use higher RX_BUF_LEN when Mesh Proxy protocol is used
Avoiding segmentation in the GATT-based Mesh Proxy protocol requires
having an RX buffer length of at least 77. We could round it up to 80
since there's otherwise wasted space, however there's also
BT_HCI_RESERVE to consider, so to avoid pushing over the 4-byte
boundary for certain HCI drivers just leave the size at 77.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-14 13:01:39 +03:00
Carles Cufi
868aeeb126 Bluetooth: controller: LE Directed Advertising Report
Implement the 4.2 event LE Directed Advertising Report, used for
scanners in a privacy-enabled controller to report directed advertising
events whose TargetA cannot be resolved by the local controller.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-10 12:33:36 +03:00
Vinayak Kariappa Chettimada
882bdd57b4 Bluetooth: controller: Add packet transmit time restrictions
Add implementation to support PHY update procedure with
packet transmit time restrictions.

This fixes:
TP/CON/SLA/BV-49-C [Initiating PHY Update Procedure Packet
Time Restrictions]
TP/CON/SLA/BV-50-C [Responding to PHY Update Procedure
Packet Time Restrictions]
TP/CON/SLA/BV-52-C [Initiating PHY Update Procedure Packet
Time Restrictions, No Change]
TP/CON/SLA/BV-53-C [Responding to PHY Update Procedure
Packet Time Restrictions, No Change]
TP/CON/MAS/BV-49-C [Initiating PHY Update Procedure Packet
Time Restrictions]
TP/CON/MAS/BV-50-C [Responding to PHY Update Procedure
Packet Time Restrictions]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-10 10:54:28 +03:00
Sebastian Bøe
2120beebf4 Kconfig: Move BT_WAIT_NOP into subsys/bluetooth/host
The CONFIG_BT_WAIT_NOP define is used only by
zephyr/subsys/bluetooth/host/hci_core.c.

It is also the only config in drivers/bluetooth that is in use when
BT_CONTROLLER is enabled. Moving it into the bluetooth subsystem
allows us to restructure the drivers/kconfig code such that the entire
Bluetooth driver menu option is omitted when the BT_CONTROLLER is
enabled.

Moving it will also mean that all configs in drivers/bluetooth will
now be related to configuring the source code in drivers/bluetooth.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-09 19:06:14 +03:00
Johan Hedberg
2975ca0754 Bluetooth: Kconfig: Rename CONFIG_BLUETOOTH_* to CONFIG_BT_*
The API name space for Bluetooth is bt_* and BT_* so it makes sense to
align the Kconfig name space with this. The additional benefit is that
this also makes the names shorter. It is also in line with what Linux
uses for Bluetooth Kconfig entries.

Some Bluetooth-related Networking Kconfig defines are renamed as well
in order to be consistent, such as NET_L2_BLUETOOTH.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-09 11:14:19 +03:00
Sebastian Bøe
197e6e2ba3 Kconfig: Move BLUETOOTH_HCI_RESERVE into subsys/bluetooth/host
There are two kinds of HCI implementations. Bluetooth drivers in
 drivers/bluetooth that implement HCI by using a wired serial
 transport layer to talk to an external controller chip. And a
 bluetooth controller in subsys/bluetooth/controller that directly
 talks to an internal on-chip controller node.

Currently, when the the subsys/bluetooth/controller is used there
still exists exposed to the user a bluetooth driver configuration
menu, even though no external bluetooth driver is in use. This is due
to a dependency on certain configs in driver/bluetooth that are needed
even though no external controller is used.

This patch moves one of these configs, BLUETOOTH_HCI_RESERVE, from
drivers/bluetooth/hci/Kconfig to subsys/bluetooth/host/Kconfig such
that eventually we can omit the entire Bluetooth driver menu option.

This re-organization does not change when the config can be enabled.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-08 23:01:05 +03:00
Vinayak Kariappa Chettimada
dc1dad34f3 Bluetooth: controller: Fix return type in hal/rand.c
Fix incorrect return data type, which causes controller to
hang generating random numbers.

Fixes bug introduced in commit d90095b556 ("Bluetooth:
controller: Use random numbers in adv and enc setup")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-08 18:11:07 +03:00
Carles Cufi
2fab706216 Bluetooth: controller: Check AdvA in Scan Response
The specification requires the scanner to verify that the AdvA present
in a scan response matches the AdvA that was sent in the original scan
request.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-08 14:48:34 +02:00
Vinayak Kariappa Chettimada
d90095b556 Bluetooth: controller: Use random numbers in adv and enc setup
Added implementation to get random numbers in ISR. And fixed
implementation to use random numbers in advertisement random
delay and encryption setup procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-08 15:29:55 +03:00
Carles Cufi
505ebfbe36 Bluetooth: controller: Fix TargetA check as initiator
The existing check for the TargetA address in directed advertising
events was incorrect. In fact the specification states:

"An initiator that has been instructed by the Host to use
Resolvable Private Addresses shall not respond to directed connectable
advertising events that contain Public or Static addresses for the
target’s address (TargetA field)."

Hence, reject TargetA values that have not been successfully resolved
when the controller is generating its own RPAs.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-07 21:54:16 -04:00
Johan Hedberg
bf8e504588 Bluetooth: Mesh: Fix duplicate const declarations
Remvoe duplicate const declarations which may cause compiler warnings.

Jira: ZEP-2442

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-07 19:18:02 +03:00
Johan Hedberg
01b684f82b Bluetooth: Mesh: Fix pointer signedness compiler warnings
Fix compiler warnings resulting from passing C string literals to
functions expecting an unsigned char pointer.

Jira: 2443

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-07 19:17:40 +03:00
Carles Cufi
264481116c Bluetooth: controller: Enable AAR for Scan Responses
To be able to get a hit on the AAR whenever a Scan Response is received,
enable it in the state transition.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-07 14:37:56 +03:00
Carles Cufi
ba9d3ae6b5 Bluetooth: controller: Fix whitelist filter logic
Add missing checks for the logic that discriminates between whitelisting
and non-whitelisting filtering, so that we do not fall into an
unsuspected false positive.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-07 12:05:49 +02:00
Carles Cufi
f6405dfd93 Bluetooth: controller: Avoid assignments in if statement
Rework the ctrl_lrpa_get() function so that it doesn't require an
assignment to be present inside the if statement, yielding smaller and
safer code.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi
f23aaeb7f4 Bluetooth: controller: Fix warning due to unused variable
With privacy disabled the lrpa pointers are not used, so exclude them
from the build.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi
3a35859410 Bluetooth: controller: Translate addresses in adv reports
Advertising reports generated by a scanner require the controller to
look up the resolving list to supply the host with an ID address instead
of the RPA that has been sent over the air.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi
66c619eb83 Bluetooth: controller: Fix typo in scan request address population
Use the actual scanner address to copy the generated RPA into, instead
of mistakenly copying it into the advertiser's address.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi
6e42c2af3b Bluetooth: controller: Use RPA in scanner only if available
Whenever trying to generate a local RPA to send a scan request or a conn
ind, verify that it can be generated (i.e. no NULL IRK provided by the
Host) and fall back to using the public/random address if required.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi
2c60df0786 Bluetooth: controller: Fix Set Privacy Mode command
Trivial fix for the return value in the processing of the Set Privacy
Mode HCI command.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 12:01:11 +03:00
Carles Cufi
a87e8a08ee Bluetooth: controller: Use little-endian peer IRKs for generation
Since the hardware expects big-endian IRKs but the common generation
function expects it in little-endian, copy and reverse the peer IRK
before generating RPAs.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 12:01:11 +03:00
Carles Cufi
b2a76be25b Bluetooth: controller: LE Enhanced Connection Complete
Implement the LE Enhanced Connection Complete HCI event, but include it
only when controller-based privacy is enabled, since it is only relevant
with it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-03 16:13:09 +03:00
Carles Cufi
dce2f95e95 Bluetooth: controller: Increase conn count only on success
Since a connection attempt can fail and will still generate an LE
Connection Complete event, check the status from the LL control module
before incrementing the HCI connection count used for flow control.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-03 16:13:09 +03:00
Johan Hedberg
f8c338fde8 Bluetooth: Mesh: Health: Fix Current Status encoding
The Test ID was incorrectly being added as 4 bytes (size of a pointer)
instead of the intended 1 byte.

This fixes Coverity CID 173643.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-03 14:09:40 +03:00
Johan Hedberg
d97be9e7a6 Bluetooth: Mesh: Provisioning: Always allow Failed PDU
In addition to the next expected PDU we should also process Failed in
all states.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-03 13:10:40 +03:00
Johan Hedberg
019b805275 Bluetooth: hci_ecc: Fine-tune thread stack size
The current 960 is at least too small under qemu_x86:

ecc stack (real size 1024): unused 36 usage 988 / 1024 (96 %)

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-03 10:47:18 +03:00
Carles Cufi
4694fe6e8a Bluetooth: controller: nrf5: Fix AAR packet pointer
The nRF5 AAR requires the packet pointer to be placed exactly 3 bytes
before the beginning of the address. Since we don't use the S1 extra
length byte, substract one from the address of the radio packet pointer.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-02 16:48:03 +02:00
Carles Cufi
fc0c3a6c32 Bluetooth: controller: Fix IRK endianness
The currently supported hardware in the LL requires big-endian IRK
values to properly function. Reverse the order of the IRK bytes coming
from HCI to address this issue.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-02 16:48:03 +02:00
Carles Cufi
ba2f0a1f1e Bluetooth: controller: nrf5: Fix AAR scratch pointer
The nRF5's AAR was being improperly configured, leading to a NULL
scratch pointer which made it not function at all.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-02 16:48:03 +02:00
Johan Hedberg
2d57272f65 Bluetooth: hci_ecc: Convert to new uECC API
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-01 10:35:06 -04:00
Carles Cufi
296b469c40 Bluetooth: controller: Thread-safe local RPA access
In order to make sure that the ISR never gets an incomplete or partial
local RPA, use pointers to share the local RPA between thread mode and
ISRs. Pointer updates are guaranteed to be atomic at least on ARM
Cortex-M.
Additionally add support for using local RPAs when initiating a
connection or sending a scan request.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-01 09:39:59 +02:00
Carles Cufi
a260d6face Bluetooth: controller: Resolve TargetA in software
Since the hardware is only able to resolve the first address in the
packet, use the existing functionality to resolve a potential TargetA
RPA in software to verify if it matches the local device.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-01 09:39:59 +02:00
Carles Cufi
af93255aa5 Bluetooth: controller: Privacy filtering in scanner and initiator
This commit introduces controller-based privacy for both the scanner and
the initiator roles. All the features in the specification are
implemented except:

* RPA resolution for directed advertising (TargetA address)
* RPA generation for scan requests and conn ind packets

Follow-up patches will cover the 2 items of functionality still missing
from the basic implementation. Hosts not using controller-based privacy
should not be affected by this change.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-01 09:39:59 +02:00
Luiz Augusto von Dentz
cf913738c5 Bluetooth: GATT: Indicate service changes when reconnecting
If peer has previously configure to received service changes indications
any changes to the database during the time it has been disconnected
shall be indicated once it reconnects:

[bt] [DBG] sc_process: (0x004065b4) start 0x000a end 0x0014
[bt] [DBG] sc_save: (0x004065b4) peer b8:8a:60:d8:17:d7 (public)
 start 0x000a end 0x0014
[bt] [DBG] bt_gatt_connected: (0x00405240) conn 0x00405aa0
[bt] [DBG] gatt_ccc_changed: (0x00405240) ccc 0x00400b30 value 0x0002
[bt] [DBG] sc_ccc_cfg_changed: (0x00405240) value 0x0002
[bt] [DBG] sc_restore: (0x00405240) peer b8:8a:60:d8:17:d7 (public)
 start 0x000a end 0x0014
[bt] [DBG] sc_process: (0x004065b4) start 0x000a end 0x0014
[bt] [DBG] gatt_indicate: (0x004065b4) conn 0x00405aa0 handle 0x0008
[bt] [DBG] sc_indicate_rsp: (0x00405240) err 0x00

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-31 13:52:08 +03:00
Luiz Augusto von Dentz
c6cb97f7c4 Bluetooth: GATT: Fix not setting SC_INDICATE_PENDING
bt_gatt_indicate return 0 in case of success, not true, so
SC_INDICATE_PENDING was flag was not set when it should.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-31 13:52:08 +03:00
Luiz Augusto von Dentz
737c50b50f Bluetooth: GATT: Improve notification code
Only checks if consolidated CCC value matches with data->type once.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-31 13:52:08 +03:00
Vinayak Kariappa Chettimada
bc64c46e35 Bluetooth: controller: Fix control and data Tx queue management
Control and Data packet Tx queue management updated to be
optimal and defer control packet responses when Tx is paused
during encryption setup.

This fixes:
TP/SEC/MAS/BV-12 [Master Start Encryption: Overlapping
Procedure]
TP/SEC/MAS/BV-13 [Master Start Encryption: Overlapping
Procedure with LL_SLAVE_FEATURES_REQ]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
6b02fb6e93 Bluetooth: controller: Fix handling PHY upd diff proc collision
Fix handling of different procedure collision when receiving
a PHY update request and handling of reject extended
indication.

This fixes:
TP/CON/MAS/BV-47-C [Handling Protocol Collision – Different
Procedure – Channel Map],

TP/CON/SLA/BV-46-C [Handling Protocol Collision – Different
Procedure – Channel Map] and

TP/CON/SLA/BV-48-C [Handling Protocol Collision – Different
Procedure – Connection Update]

conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
08466d5021 Bluetooth: controller: Fix missing procedure timeout on PHY_RSP
Fix missing procedure timeout start on PHY_RSP response
enqueue.

This fixes TP/CON/SLA/BV-51-C [Protocol Timeout for PHY
Update Procedure – No Update Request] conformance test in
LL.TS.5.0.0,

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
4ceca0864d Bluetooth: controller: Fix a missing PHY Update event
Fix missing PHY update event generation on same procedure
collision,

This fixes TP/CON/SLA/BV-44-C [Handling Protocol Collision –
Same Procedure] conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
c9a9d0f708 Bluetooth: controller: Fix PHY update with no change in PHY
Fix PHY update procedure intiation to use correct No Change
value in MtoS and StoM when there is no change to respective
PHYs. Also, added missing HCI event generation under this
case.

This fixes TP/CON/MAS/BV-41-C [Initiating PHY Update
Procedure] conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
21935f7dd6 Bluetooth: controller: Fix asymmetric PHY by using correct tIFS
Fix asymmetric PHY connection by using correct tIFS,
considering previous PHY and next PHY chain delays while
calculating the Tx and Rx tIFS.

This fixes:
TP/CON/SLA/BV-40-C [Initiating PHY Update Procedure]
TP/CON/SLA/BV-42-C [Responding to PHY Update Procedure]
TP/CON/MAS/BV-41-C [Initiating PHY Update Procedure]
TP/CON/MAS/BV-43-C [Responding to PHY Update Procedure]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
df5deea218 Bluetooth: controller: Fix header complete timeout calculation
Fix header complete timeout calculation by using Rx PHY
chain delay instead of incorrectly used Tx PHY chain delay.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
a682554231 Bluetooth: controller: Fix slave drift compensation
As ticker can only drift in 32kHz units, the slave Rx
window should consider a +/- one 32kHz unit in addition to
+/- 16us jitter of the master. Hence, for the current
implementation the slave Rx window jitter is +/- 48us.
Future improvement can be done by using remainder of 32kHz
unit drift to reduce this jitter to +/- 16us.

With this fix 20ppm clock accuracy passes conformance TIM
tests (else 251-500ppm had to be used).

Problem was not seen in real life as master do not have a
+/- 16us jitter.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
1ff96f2588 Bluetooth: controller: Fix terminate procedure timeout
Fix terminate procedure timeout when supervision timeout
equals connection interval. In this case, avoid timing out
in the first event of procedure initiation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
b0f3944e90 Bluetooth: controller: Fix slave sending reject_ext_ind
Fix slave implementation to initiate reject_ext_ind if peer
supports reject_ext_ind.

This fixes:
TP/SEC/SLA/BV-11-C [Slave Sending Reject_Ind_Ext]
conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
0883915a1e Bluetooth: controller: Fix master rx-ing reject_ext_ind enc_req
Fix master receiving REJECT_EXT_IND for ENC_REQ PDU.

This fixes:
TP/SEC/MAS/BV-11-C [Master Receiving Reject_Ind_Ext]
conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
8bf3d5d98f Bluetooth: controller: Fix for unexpected PDU during Enc setup
Fix for handling unexpected PDU during Encryption start.

This fixes:
TP/SEC/MAS/BV-14-C [Master Receiving unexpected PDU during
encryption start], and
TP/SEC/SLA/BI-05-C [Slave Receiving unexpected PDU during
encryption start]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
b187b1b949 Bluetooth: controller: Fix handling invalid control PDUs
Fix handling invalid control PDUs by generating
LL_UNKNOWN_RSP PDU.

This fixes:
TP/PAC/SLA/BV-01-C [Unknown Packet from Master]
TP/PAC/MAS/BV-01-C [Unknown Packet from Slave]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
f80344f0fe Bluetooth: controller: Fix access address generation
Fix access address generation to correctly have two
transitions in the six MS bits and add other missing checks.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada
d6506c1f54 Bluetooth: controller: Minor cleanup of enc pause impl.
Minor cleanup of Encryption Restart Procedure; No need to
pause rx for slave role on reception of PAUSE_ENC_RSP PDU as
its already paused.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Luiz Augusto von Dentz
59e9d7ad1c Bluetooth: L2CAP: Store sent data in the correct buffer
The buf variable may have been unrefed by net_buf_frag_del thus it shall
not be used to store the sent data nor it should be in the
chan->tx_queue.

Jira: ZEP-2395

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-30 18:00:17 +03:00
Vinayak Kariappa Chettimada
ca143612bf Bluetooth: controller: Fix assert on create connection
Fix assert in the controller on master connection creation
due to the CONNECT_IND PDU being transmitted beyond the
calculated scan window.

This is related to commit 80a796b493 ("Bluetooth:
controller: Fix scanner to use correct slot ticks")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-29 09:51:20 +03:00
Vinayak Kariappa Chettimada
b380ab0251 Bluetooth: controller: Fix assert, reset ticker_id_prepare
Fix an assert in next role event preparation when a
connection terminated during the connection event being
aborted/pre-empted out by the next role event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-28 13:41:16 -07:00
Johan Hedberg
c878bbdf08 Bluetooth: Mesh: Fix advertising thread initialization
Recent thread API update patches failed to update the mesh advertising
thread initialization.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-27 11:38:01 +03:00