Commit graph

1085 commits

Author SHA1 Message Date
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
Kumar Gala a45dac0bd1 dts: fix Kconfig enablment of BLUETOOTH_MONITOR_ON_DEV_NAME
Since we generate BLUETOOTH_MONITOR_ON_DEV_NAME based on dts we need a
!HAS_DTS check around it.  Otherwise we can get into odd build errors.
Its also possibly that we don't specify "zephyr,bt-mon-uart" and in that
case we default to CONFIG_UART_CONSOLE_ON_DEV_NAME (ie 'zephyr,console'
on DTS platforms).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-07-25 12:23:20 -05:00
Vinayak Kariappa Chettimada 255e5cc344 Bluetooth: controller: Implement Read/Write Auth Payload timeout
Added implementation to support HCI Read Authenticated
Payload Timeout Command and HCI Write Authenticated Payload
Timeout Command.

This fixes:
TP/SEC/SLA/BV-08-C [No response to LL_PING_REQ]
TP/SEC/SLA/BV-09-C [Modified Authentication Payload Timeout]
TP/SEC/MAS/BV-08-C [No response to LL_PING_REQ]
TP/SEC/MAS/BV-09-C [Modified Authentication Payload Timeout]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-22 11:55:35 +03:00
Johan Hedberg 0ec2630882 Bluetooth: Mesh: Add initial implementation
Add an initial implementation for the Bluetooth Mesh Profile
Specification. The main code resides in subsys/bluetooth/host/mesh and
the public API can be found in include/bluetooth/mesh.h. There are a
couple of samples provided as well under samples/bluetooth and
tests/bluetooth.

The implementation covers all layers of the Bluetooth Mesh stack and
most optional features as well. The following is a list of some of
these features and the c-files where the implementation can be found:

 - GATT & Advertising bearers (proxy.c & adv.c)
 - Network Layer (net.c)
 - Lower and Upper Transport Layers (transport.c)
 - Access Layer (access.c)
 - Foundation Models, Server role (health.c & cfg.c)
 - Both PB-ADV and PB-GATT based provisioning (prov.c)
 - Low Power Node support (lpn.c)
 - Relay support (net.c)
 - GATT Proxy (proxy.c)

Notable features that are *not* part of the implementation:

 - Friend support (initial bits are in place in friend.c)
 - Provisioner support (low-value for typical Zephyr devices)
 - GATT Client (low-value for typical Zephyr devices)

Jira: ZEP-2360

Change-Id: Ic773113dbfd84878ff8cee7fe2bb948f0ace19ed
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-20 09:30:44 +03:00
Carles Cufi 35b34c2e65 Bluetooth: controller: Only add active slots to hw filter
When populating the hardware filter, add only slots that are marked as
taken to avoid the hardware being confused by all-0 addresses. This
solves an EBQ issue with whitelist filtering.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-14 22:11:40 +03:00
Carles Cufi 77b0108afd Bluetooth: controller: Avoid warning with privacy disabled
To avoid warnings (seen on some machines) that a function reaches its
end without returning a value, conditionally compile the function in a
way that this cannot happen.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-14 22:11:40 +03:00
Vinayak Kariappa Chettimada 52ee6622c0 Bluetooth: controller: Fix master terminate procedure
Fix master terminate procedure so that if slave responded to
the ack from master for the LL_TERMINATE_IND then the master
correctly disconnected.

This fixes TP/CON/MAS/BV-09-C [Master Accepting Termination]
in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Tested-by: Ulrich Myhre <ulmy@nordicsemi.no>
2017-07-14 22:11:25 +03:00
Vinayak Kariappa Chettimada 9fc4fefc47 Bluetooth: controller: Fix slave latency enable at conn setup
Fix implementation to maintain a connection in the slave
role not taking slave latency into use before receiving an
acknowledgement from the master.

This fixes TP/CON/ADV/BV-03-C [Master Missing Slave Packets]
in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Tested-by: Ulrich Myhre <ulmy@nordicsemi.no>
2017-07-14 22:11:25 +03:00
Marcel Holtmann aefcf547ad Bluetooth: controller: Add skeleton for vendor HCI commands
Signed-off-by: Marcel Holtmann <marcel.holtmann@intel.com>
2017-07-14 14:54:52 +03:00
Carles Cufi a8173b9033 Bluetooth: controller: Fix privacy whitelist allocation
Fix copy-paste issues when allocating devices in the privacy-enabled
whitelist.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-14 13:07:41 +02:00
Vinayak Kariappa Chettimada 88dba0dd35 Bluetooth: controller: Fix cond. mayfly priority check
When the controller is configured to have its worker and job
be run at different interrupt priority, check for mayfly
priority being equal was incorrect.

Fixed by conditionally compiling the correct check of mayfly
priority level.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 10:01:15 +02:00
Vinayak Kariappa Chettimada 9dc7975b76 Bluetooth: controller: Fix to use correct anchor for scanner
Fixed a defect wherein anchor for first scanner event was in
the past (when looking for a free timeslice to avoid
overlapping with master role events) when actually there
were no master roles active. This defect caused the scanner
role to assert, when started with other roles active (eg.
advertiser), when trying to catch-up to current tick.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 09:23:28 +02:00
Vinayak Kariappa Chettimada 449295eee3 Bluetooth: controller: Revert fix for assert due to stale tick
This reverts commit 3c23c6f53d ("Bluetooth: controller:
Fix assert due to stale tick count") as this leads to
connection events to be skipped, failing conformance tests.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 09:23:28 +02:00
Vinayak Kariappa Chettimada de6ed122a8 Bluetooth: controller: Revert fix for scanner Rx window hang
This reverts commit b5235207d3 ("Bluetooth: controller:
Fix for scanner Rx window hang") as this leads to
connection events to be skipped, failing conformance tests.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 09:23:28 +02:00
Vinayak Kariappa Chettimada b07e7f2b5a Bluetooth: controller: Fix T_Terminate and other timeout calc.
Fix calculation of T_Terminate and other procedure timers by
using ceil on calculated connection interval units.

This fixes TP/CON/MAS/BI-02-C [Master T_Terminate Timer] and
TP/CON/SLA/BI-02-C [Slave T_Terminate Timer] in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Ulrich Solli Myhre <ulmy@nordicsemi.no>
2017-07-13 15:39:42 +03:00
Vinayak Kariappa Chettimada 2800961fe1 Bluetooth: controller: Fix supervision timeout countdown
Add missing supervision timeout countdown initiation on CRC
error.

This fixes TP/CON/ADV/BI-01-C [Connection Supervision
Timeout during Fail Connection Setup] and TP/CON/INI/BI-02-C
[Slave Packets Invalid CRC] in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Ulrich Solli Myhre <ulmy@nordicsemi.no>
2017-07-13 15:39:42 +03:00
Vinayak Kariappa Chettimada 97bfb1d9f4 Bluetooth: controller: Fix slave conn. failed to be established
Fix implementation so that both slave and master behave same
during connection setup and generate disconnection complete
with reason 0x3e (connection failed to be established).

This fixes TP/CON/ADV/BV-02-C [Accepting Connections
Timeout] in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Ulrich Solli Myhre <ulmy@nordicsemi.no>
2017-07-13 15:39:42 +03:00
Carles Cufi 6886f979cf Bluetooth: controller: Allow devices not in resolving list
Whenever not using the whitelist the resolving list is traversed to
verify that the device is allowed depending on its current privacy mode.
In the case where the device is not found by address in the resolving
list, allow the request to go through, since we are then dealing with an
unknown devices and the resolving list restrictions do not apply.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-13 14:07:27 +03:00
Carles Cufi 4666015323 Bluetooth: controller: Fix regression in WL filter population
Erroneous check conversion triggered a regression when populating the
whitelist filter.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-13 09:29:16 +02:00
Luiz Augusto von Dentz 16e6abbcfb Bluetooth: L2CAP: Don't reuse RX buffers to respond
This causes num of packets command handling to dead lock since it
is done on RX buffer destroy if used on TX it may not be destroyed
on time causing.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-12 17:37:45 +03:00
Carles Cufi c9bd30aa90 Bluetooth: controller: Check AdvA in scan requests
The specification states that the AdvA in a Scan Request packet should
be identical to the one sent in the original advertising packet, so
check this when processing a Scan Request.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00
Carles Cufi 486dad9e4c Bluetooth: controller: Fix RL permission check
When the initiator is using an RPA and we match it using the filtering,
we should return early and allow the device packet through instead of
going through the whole resolving list.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00
Carles Cufi 7b02b06b41 Bluetooth: controller: Fix directed adv filtering
The specification states that filter policies shall be ignored for
directed advertising, so reflect this behaviour in the code.
Additionally when the local device is using RPAs but the peer uses an
identity address, the resolving list index needs to be updated when
traversing the RL to reflect that there has indeed been a  device match
even though the IRK match did not happen.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00
Carles Cufi 968e4089d1 Bluetooth: controller: Fix AdvA checks in advertiser
The AdvA in the CONN_IND packet must match the AdvA in the advertising
packet that triggered it regardless of the advertising type.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00