Commit graph

789 commits

Author SHA1 Message Date
Vinayak Kariappa Chettimada 067ac68f0b Bluetooth: controller: Fix XTAL_ADVANCED threshold detection
Fix incorrect calculation of unreserved timespace which
should take into account the ticks_slot of current event,
and compensation for any reduced prepare in the current
event as well as in the next event.

This regression relates to the commit ad7c9d3d76
("Bluetooth: controller: Improved continuous scanning")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada 8f5e96a1b7 Bluetooth: controller: Use XON_BITMASK instead of BIT(31)
Use XON_BITMASK define instead of raw BIT(31) or bit shift
operations in code to represent use of reduced prepared by
an event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada 1bda83af1c Bluetooth: controller: Fix to use random CRC init value
Fixed controller implementation to use random CRC init value.

Fixes #6204.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-15 21:15:21 +01:00
Vinayak Kariappa Chettimada 499baff333 Bluetooth: controller: Reuse safer bt_rand in thread call path
Reuse the thread safe bt_rand() interface in the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-15 21:15:21 +01:00
Vinayak Kariappa Chettimada 4c123a5162 Bluetooth: controller: Refactor ticker integration into hal
Refactor ticker execution context dependency out into HAL
folder. This decouples ticker from mayfly, enabling porting
towards a more tasklet (if and when kernel gets the support)
style execution contexts type implementation support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-13 13:26:37 +01:00
Vinayak Kariappa Chettimada 57e49b1f03 Bluetooth: controller: Refactor BT_CTLR_ADV_INDICATION feature
Refactor BT_CTLR_ADV_INDICATION feature by moving the
implementation closer to the implementation that is closing
the advertisement event so that in the future new members
can be added as necessary (example, advertised channels).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada baf05409f8 Bluetooth: controller: Fix BT_CTLR_XTAL_ADVANCED cond. compilation
Fix compile warnings when BT_CTLR_XTAL_ADVANCED Kconfig
option is disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada f54f2ceb95 Bluetooth: controller: Rename a microsecond variable
Rename incorrectly named variable storing microseconds, from
ticks_slot to slot_us.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 12:26:34 +01:00
Vinayak Kariappa Chettimada a02606cbf9 Bluetooth: controller: Fix missing ticks to us conversion
Fixed a missing ticks unit to microsecond unit conversion
potentially caused incorrect window offsets being used while
establishing connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:57:26 +01:00
Vinayak Kariappa Chettimada 978652e7b5 Bluetooth: controller: Remove redundant whitespace
Removed redundant whitespace when dereferencing struct
members.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:57:26 +01:00
Vinayak Kariappa Chettimada bb84be2c5c Bluetooth: controller: Fix ticker to use u32_t ticks_slot
ticker timespace reservation can range up to 10.24 seconds,
needing 19-bits to represent in 32KHz clock units. Hence,
fix controller implementation to use u32_t to store ticks
slot values.

Without this fix, the controller is asserting in scan_adv
sample when using continuous scanning with 2 second interval
and window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:48:27 +01:00
Vinayak Kariappa Chettimada ad7c9d3d76 Bluetooth: controller: Improved continuous scanning
Refactored the high frequency clock preparation advanced
feature to improve radio utilization during continuous
scanning.

The inter-event timespace value now considers the reserved
timespace while determining if the high frequency clock
will be retained. This reduces the preparation time, hence
increased radio use inside scan window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:23:10 +01:00
Vinayak Kariappa Chettimada fa724b2bba Bluetooth: controller: Refactor invalid ctrl PDU handling
Refactor the invalid control PDU handling so as to reuse the
switch-case and hence, reduce code size and CPU time used.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:20:48 +01:00
Vinayak Kariappa Chettimada 8f239cd363 Bluetooth: controller: Rename radio_*_is_enabled to ll_*_is_enabled
In preparation towards a refactored controller, rename the
old radio_*_is_enabled() function to ll_*_is_enabled().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-06 10:49:25 +01:00
Vinayak Kariappa Chettimada 122a644d03 Bluetooth: controller: Fix handling of invalid Ctrl PDU lengths
Fix the controller implementation to handle Control PDUs
with invalid lengths by responding with Unknown Response
PDU.

Fixes LL.TS.5.0.2 conformance tests:
LL/PAC/SLA/BI-01-C [Control PDUs with Invalid Length from
	Master]
LL/PAC/MAS/BI-01-C [Control PDUs with Invalid Length from
	Slave]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada 2800a9cb27 Bluetooth: controller: Minor cleanup of macros
Removed redundant macro definitions and rearranged code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada 947bcba3d3 Bluetooth: controller: Use shorter (void *) for typecasts
Refactor and clean up code to use (void *) typecasts
consistently.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada 4cd9ba7813 Bluetooth: controller: Use anonymous structs and unions in PDUs
Take advantage to cleanup code by using anonymous struct and
union definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada b7819ccab6 Bluetooth: controller: Add missing PDU struct definitions
Add missing PDU struct definitions in pdu.h file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada b521d50adc Bluetooth: controller: Refactor pdu_adv_payload_* to pdu_adv_*
Refactor PDU type names pdu_adv_payload_* to a shorter
pdu_adv_* struct names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada c4ba30cb1a Bluetooth: controller: Cleanup radio_pdu_node_rx/tx variables
Cleanup the use of long radio_pdu_node_rx and
radio_pdu_node_tx variable to shorter node_rx and node_tx
names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada fe0cebedcf Bluetooth: controller: Refactor phy req/rsp PDU struct
Refactor the pdu_data_llctrl_phy_req_rsp struct into
pdu_data_llctrl_phy_req and pdu_data_llctrl_phy_req structs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada 9abf8ce0a0 Bluetooth: controller: Refactor length req/rsp PDU struct
Refactor the pdu_data_llctrl_length_req_rsp struct into
pdu_data_llctrl_length_req and pdu_data_llctrl_length_req
structs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Ioannis Glaropoulos 0ec1095dd6 Bluetooth: controller: sw-switch with the event timer (prepare commit)
This commit implements minor refactoring of radio.c and ctrl.c,
to prepare for adding the implementation of sw-switch based on
the event timer.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Vinayak Kariappa Chettimada a1f12eb238 Bluetooth: controller: Fix redundant length update event
Fix generation of redundant length update event when no
change in effective octets or time.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-73-C [Master Data Length Update - Responding
	to Data Length Update Procedure; LE 1M PHY]
LL/CON/MAS/BV-74-C [Master Data Length Update - Initiating
	Data Length Update Procedure; LE 1M PHY]
LL/CON/MAS/BV-76-C [Master Data Length Update - Responding
	to Data Length Update Procedure; LE 2M PHY]
LL/CON/MAS/BV-77-C [Master Data Length Update - Initiating
	Data Length Update Procedure; LE 2M PHY]
LL/CON/SLA/BV-77-C [Slave Data Length Update - Responding
	to Data Length Update Procedure; LE 1M PHY]
LL/CON/SLA/BV-78-C [Slave Data Length Update - Initiating
	Data Length Update Procedure; LE 1M PHY]
LL/CON/SLA/BV-80-C [Slave Data Length Update - Responding
	to Data Length Update Procedure; LE 2M PHY]
LL/CON/SLA/BV-81-C [Slave Data Length Update - Initiating
	Data Length Update Procedure; LE 2M PHY]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-02 10:40:52 +01:00
Vinayak Kariappa Chettimada 5c57027f53 Bluetooth: controller: Fix to use CPR preferred periodicity value
Fixed implementation to use Connection Parameter Request
Procedure Preferred Periodicity value in calculating the new
connection interval used by the master role in Connection
Update Indication.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-32-C [Accepting Connection Parameter Request –
	Preferred_Periodicity]
LL/CON/MAS/BV-33-C [Accepting Connection Parameter Request –
	Preferred_Periodicity and preferred anchor points]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-01 16:51:54 +01:00
Vinayak Kariappa Chettimada 9acfc7fb5c Bluetooth: controller: Fix to restrict addr set in initiator
Fix controller implementation to restrict HCI LE Set Random
Address command when advertising and/or active scanning
and/or initiator state is enable.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/INI/BV-01-C [Connection Initiation]
LL/SEC/ADV/BV-01-C [Advertising With Static Address]
LL/SEC/SCN/BV-01-C [Random Address Scanning]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 10:54:26 -08:00
Vinayak Kariappa Chettimada 7af9c7108f Bluetooth: controller: Fix for CPR with/without Feature Exchange
Fix implementation to support Connection Parameter Request
Procedure initiation with and without use of Feature
Exchange Procedure being performed in a connection.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-81-C [Initiating Connection Parameter Request
	- Unsupported Without Feature Exchange]
LL/CON/MAS/BV-82-C [Initiating Connection Parameter Request
	- Unsupported With Feature Exchange]
LL/CON/SLA/BV-85-C [Initiating Connection Parameter Request
	- Unsupported Without Feature Exchange]
LL/CON/SLA/BV-86-C [Initiating Connection Parameter Request
	- Unsupported With Feature Exchange]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 16:02:14 +01:00
Vinayak Kariappa Chettimada d03ad43dbb Bluetooth: controller: Fix to restrict addr set in active scan
Fix controller implementation to only restrict HCI LE Set
Random Address command when advertising and/or active
scanning is enable.

Continues to pass the following LL.TS.5.0.2 conformance
test:
LL/SEC/SCN/BV-01-C [Random Address Scanning]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 10:16:47 +01:00
Vinayak Kariappa Chettimada f117505773 Bluetooth: controller: Fix to restrict addr set in active states
Fixed implementation to disallow setting Bluetooth device
address under active advertising or scanning states.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/INI/BV-01-C [Connection Initiation]
LL/SEC/ADV/BV-01-C [Advertising With Static Address]
LL/SEC/SCN/BV-01-C [Random Address Scanning]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-29 18:03:15 +01:00
Vinayak Kariappa Chettimada 619bcf56c4 Bluetooth: controller: Refactor mayfly integration into hal
Refactor mayfly based execution context solution out into
the HAL folder. This opens up the possibility to use
tasklets (if and when kernel gets the support) style
execution contexts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-29 13:04:15 +01:00
Vinayak Kariappa Chettimada f5d64aafaa Bluetooth: controller: Fix CPR initiation while in Enc. setup
Fixes a bug where in Connection Parameter Request was
initiated by slave role while Encryption Setup had been
started by the peer master.

Fixes: #5823

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-26 11:35:17 +01:00
Vinayak Kariappa Chettimada 4d7d9de342 Bluetooth: controller: Refactor LL up and downstream interface
Rename some legacy upstream and downstream interfaces in
radio_* namespace to ll_* namespace for consistency.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 22:09:17 +01:00
Vinayak Kariappa Chettimada 5b0cd2c69b Bluetooth: controller: Conditional compile BT_LL_SW variant
Refactor Kconfig and CMakelists.txt to be able to
conditionally compile in BT_LL_SW variant in the controller
subsystem. This is done to support future controller with
vendor specific variant implementations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 11:51:10 +01:00
Ioannis Glaropoulos 55d3ce111c Bluetooth: controller: Refactoring nRF5 radio driver
This commit refactors the nRF5 radio driver of Bluetooth controller
to use symbolic names for PPIs. It also revisits the Radio hardware
timing constants to align with experimental measurements.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-18 10:58:04 +01:00
Vinayak Kariappa Chettimada e00282af6e Bluetooth: Fix build failure with -Wshadow CFLAGS
Fixes many instances of errors similar to below:
zephyr/subsys/bluetooth/controller/ll_sw/ctrl.c:5927:22:
    error: declaration of ‘s_link’ shadows a previous
        local [-Werror=shadow]
  static memq_link_t s_link;
                     ^~~~~~
zephyr/subsys/bluetooth/controller/ll_sw/ctrl.c:5905:21:
    note: shadowed declaration is here
  static memq_link_t s_link;
                     ^~~~~~

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-20 12:29:52 -05:00
Vinayak Kariappa Chettimada ec5a787da2 Bluetooth: controller: Fix multiple master role event scheduling
When the controller is connecting to multiple connectable
advertisers, the events are scheduled consecutively avoiding
overlapping events. Calculation of the window offset did not
consider the preparation time before the event, causing the
new master role connection event to overlap with previous
event. This is now fixed by including the preparation time
in the used window offset from the end of connect_ind PDU
transmitted.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-09 09:24:37 +02:00
Vinayak Kariappa Chettimada ba13c99141 Bluetooth: controller: Fix conn param req initiation check
Fixed the check related to initiating connection parameter
request procedure. This will avoid sending invalid repeated
dispatch of connection parameter request PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-06 11:30:42 -06:00
Vinayak Kariappa Chettimada 73a493eae6 Bluetooth: controller: Fix missing CPR procedure reset
When connection parameter request procedure was responded
by master role with Unsupported Link Layer Parameter Value,
a missing reset of the connection parameter request
procedure state caused next connection parameter request to
be incorrectly responded with same procedure collision
extended reject ind PDU. This caused an eventual connection
disconnection with reason LMP response timeout. This is now
fixed by reseting the state correctly.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-06 10:24:26 -06:00
Vinayak Kariappa Chettimada f9cd9d4a7b Bluetooth: controller: Fix compile error when LE_ENC is disabled
Fixes the following compile error when CONFIG_BT_CTLR_LE_ENC
is disabled:
subsys/bluetooth/controller/ll_sw/ctrl.c: In function
'isr_rx_conn_pkt_ctrl':
subsys/bluetooth/controller/ll_sw/ctrl.c:2613:29: error:
'LLCP_ENCRYPTION' undeclared (first use in this function)
         (conn->llcp_type != LLCP_ENCRYPTION)) ||
                             ^~~~~~~~~~~~~~~
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 18:48:05 -05:00
Vinayak Kariappa Chettimada f44efd12fa Bluetooth: controller: Replace void * with memq_link_t
Replace use if void * declaration related to memq links with
more readable memq_link_t.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 15:28:49 +01:00
Vinayak Kariappa Chettimada 25737d9963 Bluetooth: controller: Optimise memq interface
Optimised the parameter passing order of memq interface such
that the compiled code uses less space and execution time.

Having a parameter that gets returned as the first parameter
passed to a function avoids instructions required to have
the result in the return register.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-21 09:11:34 +02:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05: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 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
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 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
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
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 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
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
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 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 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
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
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 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 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
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
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
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
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
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
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
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
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
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
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
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 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 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
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
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
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
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
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
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
Carles Cufi f6260d6adb Bluetooth: controller: Rename whitelist arrays
For consistency with the Resolving List, rename the whitelist filter to
match its type and the privacy-enabled version to align it with the
short name used in the RL.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-10 20:47:51 +02:00
Carles Cufi a99d1f8fe6 Bluetooth: controller: Fix resolving list error handling
To correctly handle the allocation and deallocation of resolving list
items, the ll_rl_find and wl_pees_find functions have been modified to
return an invalid index instead of a negative value in case of error.
This is to avoid the ambiguity when mixing indices and negative numbers,
which does not play well with the first index 0.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-10 20:47:51 +02:00
Vinayak Kariappa Chettimada b56768b626 Bluetooth: controller: Fix first interval to be within +/-16us
Due to the missing remainder support in the ticker_start
function for first interval, fix implementation so as to
round the first interval/offset during master connection
setup and connection update to within +/-16us.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-06 14:48:32 +03:00
Carles Cufi 269a828cb1 Bluetooth: controller: Use RL indices in adv ISR
To avoid manipulation of the irkmatch_ok and irkmatch_id, rely instead
on Resolving List indices for all checks in the advertising ISR.
Although we do incur in a small overhead to look it up initially, the
overall gains are worth the change.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-04 09:30:46 +03:00
Vinayak Kariappa Chettimada 2dd375ef45 Bluetooth: controller: Fix advertisement event lengths
The Controller reserved more than required time for
advertisement event length. Due to this, directed
advertisements did not meet the required <= 3.75ms
interval. It is now fixed by having event lengths based
on the advertisement PDU types.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-04 08:16:29 +03:00
Vinayak Kariappa Chettimada 879c49ce91 Bluetooth: controller: Rename chl_* to chan_*
Rename use of chl_* namespace to more commonly used chan_*.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-04 08:16:29 +03:00
Carles Cufi b97a4670a6 Bluetooth: controller: Reset filters correctly
Reset and initialize filters correctly based on whether privacy is
enabled in the controller. Particularly relevant in the case of the
whitelist, which is handled in a completely different way if privacy is
enabled. Additionally reset the peer IRK list in the resolving list
whenever the list itself is cleared.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-03 15:43:00 +02:00
Vinayak Kariappa Chettimada 3779fb626a Bluetooth: controller: Increase ticker operations in thread mode
When flashing in synchronous mode with BLE roles active,
ticker function calls will be deferred to avoid radio ISR
latencies. Increase the total operations supported by 1, to
accommodate flash driver's use of ticker operations.

It has been observed, without this increase, either the
flash driver returned -ECANCEL or the BLE Controller
asserted on data transmit as a slave (trying to force data
transmit on earliest connection event interval).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-01 13:21:38 +02:00
Carles Cufi 803eab08ec Bluetooth: controller: Privacy filtering in advertiser
Implement privacy-enabled filtering in the advertiser role. This
includes all required checks when running address generation and
resolution so that the advertiser complies with the relevant
specification sections.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-30 17:19:30 +03:00
Vinayak Kariappa Chettimada 4362eda4aa Bluetooth: controller: Fix missing re-initialization of ret_cb
Fix missing re-initialization of ret_cb to
TICKER_STATUS_BUSY before every new call to ticker interface
functions' with operation's callback.

One issue was undirected advertisement disable to return
failure status in the scan_adv sample.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-30 13:42:33 +03:00
Vinayak Kariappa Chettimada b5235207d3 Bluetooth: controller: Fix for scanner Rx window hang
With the fix in commit 3c23c6f53d ("Bluetooth: controller:
Fix assert due to stale tick count") it is required that a
skipping event shall abort the previous role in order to
enable the ticker_job to resume and reschedule next ticker
expiry.

In the scan_adv sample, with continuous scanning, an
advertiser would pre-empt it, but if the advertiser skipped
its event without aborting the scanner, the scanner is hung
with its rx window without a timeout, and HCI command to
stop the advertiser will wait forever to complete.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-30 13:42:33 +03:00
Vinayak Kariappa Chettimada 80a796b493 Bluetooth: controller: Fix scanner to use correct slot ticks
The scanner was reserving a little less slot ticks which
caused other roles to overlap before scan window could
close.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-30 13:42:33 +03:00
Vinayak Kariappa Chettimada 2f29d7904f Bluetooth: controller: Fix hardfault, out-of-range ticker access
With the ticker for flash driver added, the Controller was
corrupting memory outside its allocations by incorrectly
using the flash ticker instance to be a BLE role and
corrupting memory. This is now fixed by checking for the
ticker ids to be within the Controller's use before using
them.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-29 16:54:34 +03:00
Vinayak Kariappa Chettimada 040b85bfbc Bluetooth: controller: Temporarily disable scan req notification
Temporarily, disable scan request notification reports when
LE Advertising Extensions feature is enabled; as support for
enabling scan request notification is not yet added to the
Controller's Link Layer interface functions, yet.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-28 15:00:47 +02:00
Andrzej Puzdrowski 7e6b9fa841 Bluetooth: controller: support for code exe. in co-operation with radio
Extend radio ticker nodes for support in-timeslice execution
Added interface for abort the radio
Added interface for check whether the radio is idle

Added interface for get ticker IDs for timeslice ticker node
Added interface for check whether radio ticker is running
Added interface for check whether radio ticker is initialized

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-06-28 12:29:50 +02:00
Carles Cufi 386c524f93 Bluetooth: controller: Keep track of IRK to RL indices
In order to associate a hit on the hardware IRK filtering with an entry
of the resolving list, add an array of correspondance between the IRKs
and the resolving list entries.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Carles Cufi 59ff81ca28 Bluetooth: controller: Add wl bit in resolving list
In order for some of the required checks in the ISR to be performed, we
need to keep track of which of the items in the resolving list are in
the whitelist as well. Track them using a single bit in the resolving
list entries.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Carles Cufi 1a07179a3c Bluetooth: controller: Generate RPAs for scanning and initating
Start RPA generation when enabling the scanner either for observing or
for initiating.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Carles Cufi 0f0c45ce7c Bluetooth: controller: Optimize RL addition
To avoid iterating twice through the list, have ll_rl_find() return the
first free empty slot on the list.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi 2c1dbd21f4 Bluetooth: controller: Handle Privacy Modes
Add handling of the LE Set Privacy Mode HCI Command along with the logic
required to take it into account when populating the hardware filters.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi bd31ad11de Bluetooth: controller: Add RL filter
In order for privacy to work correctly with and without peer IRKs, an
additional hardware filter is required to help match the peer device in
the case address resolution is not possible for a peer since the Host
has not provided a peer IRK for it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi 343a916d48 Bluetooth: controller: Properly remove peer IRKs from RL
When removing a device from the resolving list, if it contained a peer
IRK then it is necessary to update the indices that point to the peer
IRK list, since the list itself is contiguous in memory.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi 540a209085 Bluetooth: controller: Add whitelist population with privacy
When using privacy, an additional cache of the actual privacy peers is
required to avoid additional processing in the ISR (since some of the
peers in the whitelist will be disabled by the corresponding privacy
settings). Add the cache and populate the actual whitelist just before
advertising, scanning or initiating a connection.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Vinayak Kariappa Chettimada 3c23c6f53d Bluetooth: controller: Fix assert due to stale tick count
Fixed assert due to stale tick count in role event
preparation. This happens when ticker timeout expiry is
delayed from the requested realtime anchor, due to thread
mode processing overheads and occurring interrupts therein,
if any, that added a delay between requested anchor tick
and actual scheduling for the requested ticker timeout.

The assert is reproduced in bt shell by starting advertising
and following it with continuous scanning (interval 2.5ms,
window 2.5ms), on nRF51x. If the overheads and/or a
advertiser event delayed the scheduling of scanner by over
2.5ms, then the preparation of scanner asserted.

The assert has been fixed by checking for stale tick count
at expiry in role event preparation and skip the event
gracefully.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-23 16:02:54 +03:00
Carles Cufi 3707096d86 Bluetooth: controller: Correct adv, scan and init state checks
For whitelist and resolving list handling, avoid trying to start the
advertiser and scanner roles when they are already running.
Additionally, and since simultaneous scanning and initiating is not
supported, correctly report this to the host both in the supported
states and in the HCI command via an error code, instead of silently
disabling scanning.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-23 11:53:40 +03:00
Kumar Gala b0cbf1d455 Bluetooth: Cleanup use of C99 types
We introduced some see C99 types, so convert them over to the Zephyr
types.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-06-22 13:47:28 -04:00
Vinayak Kariappa Chettimada cd1fd05778 Bluetooth: controller: nRF5 radio timings abstractions
Added HAL Radio abstractions to use SoC specific Radio Timings
as documented in SoC's electrical characteristics.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-22 18:48:15 +03:00
Vinayak Kariappa Chettimada 997b72d8dc Bluetooth: controller: Fix directed adv timeout and disable
Fixed assert due to incorrect implementation of stopping of
advertiser role under directed advertisement timeout, and
also, fixed assert due to adv stop ticker not being stopped
on advertisement disable from thread mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-21 11:27:40 +03:00
Vinayak Kariappa Chettimada 6616065e95 Bluetooth: controller: Add connect ind PDU address fields check
Added checks for advertiser and initiator/target addresses
received in CONNECT_IND when performing directed
advertising.

This is required to pass TP/CON/ADV/BV-04-C [Directed
Advertising Connection].

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-21 11:27:23 +03:00
Vinayak Kariappa Chettimada 8b74c98ed5 Bluetooth: controller: Fix conn context leak under directed adv
When directed advertisements timed out, connection context
associated was not being released. Subsequent connectable
advertising or connection creation failed.
This is now fixed by releasing the connection context on
directed advertisement timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-21 11:27:10 +03:00
Carles Cufi 89af682e88 Bluetooth: controller: Refactor whitelist handling (v2)
Refactor whitelist handling into generic filter management in
preparation for future resolving list ID address filters.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 21:37:22 +03:00
Carles Cufi 4053470f62 Bluetooth: controller: Add inital support for Controller-based privacy
This initial commit adds the following:

* Handling of privacy HCI commands
* New Link Layer filter module for both whitelist and resolving list
* Advertising RPA generation with timeouts

Follow-up commits will expand the functionality.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 15:20:09 +03:00
Vinayak Kariappa Chettimada 1dd5462320 Bluetooth: controller: Move scan response data swap outside tIFS
In preparation towards Privacy 1.2, move implementation that
swapped scan response PDU double buffer to same place as
where adv data PDU double buffer is swapped. So that, change
in AdvA in adv data PDU can be reflected in scan response
PDU buffer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-15 16:23:28 +02:00
Vinayak Kariappa Chettimada 799757a81f Bluetooth: controller: Avoid adv data set on ADV_EXT_IND PDU
Added fix to avoid adv data set function call from
corrupting a ADV_EXT_IND PDU under LE Extended Advertising.
Also, avoid redundant code execution under directed
advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-15 15:54:24 +02:00
Vinayak Kariappa Chettimada 0a1efac161 Bluetooth: controller: Fix ChSel bit be not used in ADV_EXT_IND
Only ADV_IND, ADV_DIRECT_IND, and CONNECT_IND PDUs can have
ChSel bit set in Advertising channel.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-15 15:54:24 +02:00
Vinayak Kariappa Chettimada 66d9e11f93 Bluetooth: controller: Add ll_adv_scan_state_cb callback
Added a callback function ll_adv_scan_state_cb from the
Controller that gets called on either an advertiser or a
scanner getting started as the Controller's first enabled
state. The callback is also called on the Controller's
last disabled advertising or scanning state.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 17:42:27 +02:00
Vinayak Kariappa Chettimada ffc74034fb Bluetooth: controller: Fix missing reset of direct adv state
Fix missing implementation to reset the advertiser state
when directed advertisements stop without a connection being
established.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 17:42:27 +02:00
Vinayak Kariappa Chettimada bedbd7fdee Bluetooth: controller: Extended scan for nconn nscan w/o aux
Update scanner implementation to receive ADV_EXT_IND PDUs.

Jira: ZEP-2238

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 18:40:40 +03:00
Vinayak Kariappa Chettimada 03942483ec Bluetooth: controller: LE Adv. Ext. non-conn non-scan w/o aux
Add implementation to set extended advertising parameters,
start advertising Non-Connectable and Non-Scannable
Undirected without auxiliary packet.

Jira: ZEP-2238

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 18:40:40 +03:00
Vinayak Kariappa Chettimada 51d6bdb2ff Bluetooth: controller: LE Advertising Extensions PDU structs
Add Bluetooth v5.0 LE Advertising Extensions air interface
packet structures.

Jira: ZEP-2073

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 18:40:40 +03:00
Carles Cufi d0832f92fd Bluetooth: controller: Refactor whitelisting
As a preparation for advanced filtering (Controller-based privacy) this
commit refactors whitelisting so that it becomes its own module and
actually correctly performs state tracking to avoid modifying the
whitelist when it's in use.

Additionally it also removes the duplicate separate entries for
advertising and scanning, since the specification only allows one single
global whitelist singleton.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-13 12:22:43 -04:00
Vinayak Kariappa Chettimada d4fe898fe2 Bluetooth: controller: Add functions to get active filter policy
Add internal functions to read advertiser and scanner filter
policy if the roles are enabled. This is required to
restrict updates to whitelist and resolving lists when
filter policy are being used by the roles.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 12:34:51 +02:00
Vinayak Kariappa Chettimada 08f3c62916 Bluetooth: controller: Reduce ll_adv struct size
Remove ll_adv struct members whose contents are stored in
PDU buffers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada faaa82fa5d Bluetooth: controller: Remove scan_ prefixes in scanner struct
Remove scan_ prefixes in scanner struct member names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada 8eb9c8cea0 Bluetooth: controller: Fix advertiser context corruption
Under invalid host behavior, trying to start advertising
while already active would corrupt the advertiser context.
This is fixed by having an explicit flag to check whether
advertiser is already running.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada d577d3c450 Bluetooth: controller: Fix scanner context corruption
Under invalid host behavior, trying to start scanning while
already active would corrupt the scanner context. This is
fixed by having an explicit flag to check whether scanner is
already running.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada 19bccdd434 Bluetooth: controller: Use the term scanner in place of observer
Rename the use of the term observer in the controller to
the term scanner.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada e28323aed1 Bluetooth: controller: Fix non-scannable advertising mode
Under non-scannable advertising do not start a Rx window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada d055252ea9 Bluetooth: controller: Restrict enc to 1M 27 bytes PDU on nRF51
Restrict encryption support on nRF51 series SoC to Bluetooth
LE 1M PHY and max. 27 bytes PDU. If 251 bytes PDU using Data
Length Update procedure is desired, then LE Encryption
procedure will not be supported (until a software CCM is
implemented in future).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-09 10:33:06 +02:00
Vinayak Kariappa Chettimada ebd94f06b5 Bluetooth: controller: Cond. compile LE Encryption
Add Kconfig option to be able to conditional compile the
Bluetooth v4.0 LE Encryption procedure.

This is needed in order to be able to not support encryption
on nRF51 series when using Data Length Update procedure with
upto 251 byte payloads until a software-based CCM support is
implemented.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-09 10:33:06 +02:00
Vinayak Kariappa Chettimada 05ad68b353 Bluetooth: controller: Add extra assert checks
Added extra assert checks to detect controller failure if
a role event preparation function was not followed by the
role event start function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-30 11:03:05 +03:00
Vinayak Kariappa Chettimada c3e674071d Bluetooth: controller: Fix failing fast encryption setup feature
In commit c41d3edda when implementing the alternative
encryption setup implementation, the original fast
encryption setup implementation was broken. When host is
slow in responding to LTK request, the controller asserted
when fast encryption implementation is selected. This is
now fixed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-29 17:31:04 +03:00
Vinayak Kariappa Chettimada 3a2ff7b08c Bluetooth: controller: Fix CSA#2 assert
Fix the assert in the controller during connection setup
when peer does not support CSA#2 feature and free Rx buffer
queue does not have enough buffers to generate CSA event.

The assert was reproduced by turning on advertisement
indication and scan request notification features in the
controllers advanced features, and a peer that does not
support CSA#2 initiated a connection.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-29 17:30:44 +03:00
Carles Cufi 5d38c99761 Bluetooth: Consolidate all role configuration
Since role support is fundamental to both the Host and the Controller,
move the role configuration options to the top-level file and rename
them to fit the GAP specification, avoiding confusion between GAP and LL
names.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-29 17:08:52 +03:00
Vinayak Kariappa Chettimada c6dd9d5ef6 Bluetooth: controller: Handle Rej Ext Ind for Length Req PDU
Added implementation to handle an incoming Reject Ext Ind PDU in
response to a sent Length Req PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-24 11:16:41 -07:00
Vinayak Kariappa Chettimada a2a364bac4 Bluetooth: controller: Fix DLE crossover assert
When initiating Data Length Change at the same instant the
crossover condition was not handled correctly causing the
controller to assert.

This fix will allow crossover of Data Length Update
procedure, and this collison is harmless as per Bluetooth
specification, and gracefully handled by the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-24 11:16:41 -07:00
Vinayak Kariappa Chettimada 3e0f72d7cc Bluetooth: controller: Fix missing PHY update cond. compilation
Added a missing conditional compilation #if-#endif that caused
compilation error when PHY update feature was deselected.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-12 13:55:39 +03:00
Carles Cufi 6c9e563c92 Bluetooth: Move common code to common/
Since more and more code is going to be reused by both the Host and the
Controller, this commit introduces a common/ folder that will contain
everything that is not tied to one of the two components but shared by
them.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-12 12:56:14 +03:00
Vinayak Kariappa Chettimada 0187280aa8 Bluetooth: controller: Revert cleanup redundant ticker busy loop
This reverts commit 698de88916 ("Bluetooth: controller:
Cleanup redundant ticker busy loop")

Scan enable asserted in ctrl.c line 3756 due to the fact that a
role event was active and ticker job has hence been disabled.
Add back the busy loop so that scan enable can wait until the
active role event completes gracefully.

The ticker busy loop is mandatory in all ticker interface calls
if a blocking behavior is desired.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-11 11:53:53 +03:00
Michael Scott 774567ea14 Bluetooth: controller: remove dup code in packet_rx_reserve_get()
The calculation in packet_rx_reserve_get() was already handled by
packet_rx_acquired_count_get().  So, let's use that code instead
and remove the duplication.

Change-Id: Ic76f70f1e78bebc74f5bef36cd92a3c332e489e9
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-05-10 23:03:11 +03:00
Michael Scott 667a40a181 Bluetooth: controller: nix #ifdefs from packet_rx_acquired_count_get()
This calculation can be used in packet_rx_reserve_get() where currently
the code is duplicated from packet_rx_acquired_count_get().
Let's allow use of packet_rx_acquired_count_get() regardless of whether
CONFIG_BLUETOOTH_CONTROLLER_DATA_LENGTH is enabled.

Change-Id: I613bde0a407f3caccabb22f369098575965e98ad
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-05-10 23:03:11 +03:00
Michael Scott 5699af2af0 Bluetooth: controller: verify DLE req_rsp has valid values
During testing, lr->max_rx_octets and lr->max_tx_octets were
at times set to 0.  If we use these 0 values, we end up with
very erratic behavior.  Best, to check for a sane value and
if invalid, default to the value in _radio.conn_curr->max_*x_octets.

Change-Id: I57c0e3790d988f0de17993cebe5c5c2ab0fc07a6
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-05-10 23:03:11 +03:00
Vinayak Chettimada c3adc7b0c7 Bluetooth: controller: PHY Update Procedure
Added support for Bluetooth v5.0 PHY Update Procedure in the
Controller.

Asymmetric PHY connections do not work for now due to the
Radio mode not being setup in time in the ISR during tIFS
period and the Radio already ramping up in the cached
previous Radio mode to meet tIFS deadline.

Subsequent commits will add this feature, by either double
buffering the mode in software or using fast radio ramp up
which gives enough time in the ISR to change the mode.

Jira: ZEP-2086

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-10 07:30:16 +03:00
Vinayak Chettimada f19a1a348e Bluetooth: controller: Allow multiple ctrl pkt enqueue
Scale the ctrl pkt enqueue implementation to allow multiple
ctrl packets to be enqueued. This will aid in the graceful
implementation of parallel control procedure collisions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-10 07:30:16 +03:00
Vinayak Chettimada fc6d8d1bc4 Bluetooth: controller: Scan Request Notifications
Implement the framework for LE Scan Request Received Event.
The feature is available under the Controller's advanced
features and will be selected implcitly when Bluetooth v5.0
LE Advertising Extensions feature is implemented.

Jira: ZEP-2073

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 15:56:04 +03:00
Vinayak Chettimada d39d8224be Bluetooth: controller: Refactor LL Master role to ll_master.c
Move master role related implementation out into a separate
ll_master.c file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Vinayak Chettimada 446923e4d5 Bluetooth: controller: Refactor LL Scan state to ll_scan.c file
Move scanning state related implementation out into a
separate ll_scan.c file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Vinayak Chettimada 6117d1dda7 Bluetooth: controller: Refactor LL Adv state to ll_adv.c file
Move advertising state related implementation out into a
separate ll_adv.c file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Vinayak Chettimada 75bff19541 Bluetooth: controller: Introduce s/w based TRX switching
Introduce alternative TRX switching using dedicated timers
and peripheral interconnect. This will enable the
possibility to independently configure the Tx and Rx
settings between the tIFS.

Note, this will also provide the opportunity to design a
soft realtime Radio ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-04 09:36:31 +03:00
Carles Cufi 7ebe7da736 Bluetooth: controller: Controller to Host flow control
The Bluetooth Specification allows for optional Controller to Host flow
control based on the same credit-based mechanism as the Host to
Controller one. This is particularly useful in 2-chip solutions where
the Host and the Controller are connected via a physical link (UART, SPI
or similar) where the Host is sometimes required to ask the Controller
to throttle its data traffic while still making sure that relevant
events get through the line.

This implementation is based on a simple queue of pending events and
data that is populated whenever the Controller detects that the Host is
out of buffers and then emptied whenever the Host notifies the
Controller that is ready to receive data again. Events relevant to the
connections are also queued to preserve the order of arrival.

At this point the Controller ignores the connection handle sent by the
Host and treats all connections equally, and it also queues events even
for connections that have no data pending in the queue. Both this items
can be improved if necessity arises.

Note that Number of Completed Packets will still flow freely from the
Controller to the Host regardless of the pending ACL data packets, which
might lead to inconsistencies in the sequential order of certain
operations that include bi-directional data transfer.

Jira: ZEP-1735

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-03 22:23:42 +03:00
Vinayak Chettimada b29b3e2fdb Bluetooth: controller: Rename ll_address_* to ll_addr_*
Rename ll_address_* to ll_addr_*. Also, update ll_addr_get
to return reference to stored public or random address.

Change-id: I22cb0135d2223f679c4d9321f4724f8b7de0aede
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 9fcd0827fd Bluetooth: controller: Explicit AC and DC packet configure
In the Controller's radio hal, explicitly differentiate
between Advertisement and Data channel packet
configuration.

Also, remove nRF5x specific extra overhead in Advertisement
PDU structure.

Change-id: I942b88a160af78f8900d7e49fb5f36c8aa493b97
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 56f8af92cf Bluetooth: controller: Low Duty Cycle Directed Advertising
Added Bluetooth v4.1 Low Duty Cycle Directed Advertising
feature.

Change-id: I6ca665e298b343200c65405739f3998bc78b84e7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Carles Cufi a6e157b61a Bluetooth: Controller: Fix alignment issues from new integer types
The switch from C99 integer types to u16_t, etc. caused misalignment
in structs and function definitions with multi-line parameter lists.

Change-Id: I1448b159ab1afe50ff88b7a6bd1b254c44858d4c
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Kumar Gala d0eb235510 Bluetooth: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I8f57a17f78e674aca5400f005db8975c9f9e150e
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 13:25:23 -05:00
Kumar Gala 3c454017b4 Merge "Merge bluetooth branch into master" 2017-04-20 16:55:36 +00:00
Kumar Gala 789081673f Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t.  This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.

We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.

We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.

Jira: ZEP-2051

Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 16:07:08 +00:00
Vinayak Chettimada 392b5deacb Bluetooth: controller: Channel Selection Algorithm #2
Add Bluetooth 5.0 LE Channel Selection Algorithm #2 feature

Jira: ZEP-2033

Change-id: Ic1155b4399882b89cab33cac78b08b7b39ff6f9d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Vinayak Chettimada 11a32bf46d Bluetooth: controller: Support BT 5.0 feature set bit fields
Added support in the Controller for increased feature set
bit fields in Bluetooth 5.0. Cached feature set in the
connection context is increased to a uint32_t value to
accommodate 17 feature bits.

Change-id: I9ae15d6d90fa7a3de186905d3c68088ee22d2911
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Vinayak Chettimada 2f70a6bcca Bluetooth: controller: Rename channel/chnl to chan
Rename symbol names with channel/chnl to chan.

Change-id: I196ffea79e7e10b0253363949051fdf82be62cb4
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Vinayak Chettimada 7a10c35f6b Bluetooth: controller: Use defined keyword in #if cond compiles
Use #if defined(...) constructs while using conditional
compilations of advanced event preparation and advanced
scheduling implementations.

Change-id: I728c76d0e7dbbfa378e8978b726ec404d9e55a72
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-10 09:08:41 +00:00
Vinayak Chettimada 1a62acd00e Bluetooth: controller: Add BT 5.0 PDU structs
Add struct definitions for BT 5.0 PDUs, LL_PHY_REQ,
LL_PHY_RSP, LL_PHY_UPDATE_IND, and LL_MIN_USED_CHANNELS_IND.

Change-id: Ib54209cdf381ba53217eb425696c24d797fe0a30
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 7c22073195 Bluetooth: controller: Make worker and job priority configurable
Add Controller advanced Kconfig options to select IRQ
priorities of the Radio, Ticker's Worker and JOB IRQs.

This will provide an opportunity to have peripheral IRQ's
of higher level than Bluetooth Controller.

Change-id: Iaa128c1cd64a309a77d42d485fdefe68f31e4895
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 1277eea15e Bluetooth: controller: Remove util/config.h
Remove util/config.h and unnecessary redefinitions of
caller ids.

Change-id: I85bb9ae3ab7ff9fcce18c886cfa3e33c91ebb670
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 698de88916 Bluetooth: controller: Cleanup redundant ticker busy loop
Cleanup redundant ticker busy loop that could hang if the
worker and job IRQ priority levels are misconfigured, and
job gets disabled before all users/mayfly functions using
job complete.

Change-id: I053ad75a4328c51cfe651b820a2fa961e42ae48f
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada f38d57cba3 Bluetooth: controller: Kconfig option for advanced scheduling
Add Kconfig option to enable advanced scheduling in the
controller.

Enable non-overlapping placement of observer, initiator and
master roles in timespace. Uses window offset in connection
updates and uses connection parameter request in slave role
to negotiate non-overlapping placement with active master
roles to avoid slave roles drifting into active master
roles in the local controller.

This feature maximizes the average data transmission amongst
active concurrent master and slave connections while other
observer, initiator, master or slave roles are active in the
local controller.

Disabling this feature will lead to overlapping role in
timespace leading to skipped events amongst active roles.

Change-id: I16e4e6c3ca99f93987ab86924af0cb9d76bdbc7e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 646726518f Bluetooth: controller: Kconfig for advanced event preparation
Added Kconfig option to enable advanced event preparation
feature.

Enables advanced event preparation offset ahead of radio
tx/rx, taking into account predictive processing time
requirements in preparation to the event, like control
procedure handling and CPU execution speeds. Crystal
oscillator is retained between closely spaced consecutive
radio events to reduce the overall number of crystal
settling current consumptions.

This feature maximizes radio utilization in an average role
event timeslice when they are closely spaced by using a
reduced offset between preparation and radio event.

By disabling this feature, the controller will use a
constant offset between the preparation and radio event. The
controller will toggle crystal oscillator between two
closely spaced radio events leading to higher average
current due to increased number of crystal settling current
consumptions.

Change-id: I19e640f7395ac7938873ef4bfac38acf8d6f7e0e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 611460b913 Bluetooth: controller: Fix race waiting for ticker job to complt
Same volatile status variable as return and being updated
in ISR would modify the variable in two context which
caused the variable to be set to a stale value.

This commit uses two different variables, one for return
value and the other to be updated by ISR.

Jira: ZEP-1941

Change-id: I19e3bdc85e15bda7891395f3f1f64c2ddbeee0c6
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-24 17:06:59 +00:00
Vinayak Chettimada 2d644f2f42 Bluetooth: controller: Fix mayfly caller id for thread call path
role_disable initiated through HCI commands are initiated
in thread context and controller code was using the job
mayfly caller id instead of using the correct app caller
id.

Also the XTAL retain calls being called from two different
call context used the same worker caller id and same mayfly
instead of using the correct caller ids and independent
mayfly for each caller.

This potentially could cause mayfly enqueued list to be
corrupted and enqueued mayfly could be lost.

Change-id: Ia356419462d1fb4e38f4a20c720974143f12fdb6
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-24 17:06:43 +00:00
Vinayak Chettimada 0efd38885a Bluetooth: controller: Cleanup makefiles
Cleanup controller's root makefile and add folder level
makefile to have better control over dependencies.

Also explicitly include folder paths in c files to clearly
depict the dependencies.

Change-id: Iac7b3a86eff11082111049ba48559c74f6c4d3fb
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:43 -07:00
Vinayak Chettimada 9522b9a37f Bluetooth: controller: Move PDU macros from radio.h to pdu.h
Move the PDU related size definitions out of radio.h and
place it in pdu.h. This will remove hci's dependency on
radio.h.

Change-id: Idf9d7cdf7c60d74816ef2b093c4ae457df16e9a9
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:43 -07:00
Vinayak Chettimada f1aabd8ba2 Bluetooth: controller: Replace 0 for pointers with NULL keyword
Updated controller code to use NULL keyword instead of
using 0 for pointers.

Change-id: I5ebff53dfeeba670fb7afe4740596b2662eb0334
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Johan Hedberg 94831a7589 Bluetooth: Introduce public big-endian AES API
There may be use cases where input and output is in big-endian rather
than little-endian. Introduce a native big-endian API to avoid
excessive byte order reversals in these cases.

Change-Id: Ia7b3e01bb0a07c4560b23f60c2f615ec614eb431
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada a91dd34830 Bluetooth: Make LE Encrypt helpers public
Expose LE Encrypt helpers to applications. If software-
based controller is compiled-in, then controller's AES
hardware will be used by the exposed helper interface.

Change-id: I2bac9dfa5ccb3dd50447079affb52d920ae5bd81
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>.
2017-03-21 17:05:42 -07:00
Vinayak Chettimada 32f03a42c7 Bluetooth: controller: Move bt_rand into separate file
Move crypto related interface provided by the
software-based Controller bt_rand into separate file,
crypto.c.

Change-id: I9998a43fe45799b479969ca195f324199418b8c2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada 5bf86ea209 Bluetooth: controller: Use explicit paths to internal headers
Use explicit path while including internal header files.

Change-id: Ide80eb23007574a7362850173ac227943bda21d5
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Carles Cufi 4b10d75fbe Bluetooth: controller: Move LL code from driver to ll_sw
The current hci_driver.c contained all the software Link Layer
initialization code. To decouple HCI from the actual LL, most of the
functionality that is actually part of the LL has been moved to the
ll_sw folder, opening the possibility for future hardware-based LL
implementations.

Change-Id: I1b54d655568a4ec02409da2f1a0addb4d64beed0
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Carles Cufi a7f6656998 Bluetooth: controller: Move ll.h to an include folder
To present a common interface to both software and hardware Link Layers
the API in ll.h now lives in its own separate include/ folder.

Change-Id: I2b0ab0d11b47b9c35a5759bcc30f347e6c616648
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00