Commit graph

1155 commits

Author SHA1 Message Date
Ioannis Glaropoulos dc3e9b1755 bluetooth: controller: abstract PPI handling functions
This commit refactors radio.c, so it calls abstract functions
for PPI handling (e.g. enable, disable channels, or configure
endpoints), which, then, call the platform-specific functions
for PPI handling. The abstract functions are simple wrappers,
implemented in radio_nrf5_ppi.h.

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

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-16 19:06:51 +02:00
Kristoffer Rist Skøien c58af2b686 Bluetooth: Controller: Typo in Kconfig
Changed documentation in Bluetooth Controller
Kconfig for BT_CTLR_ASSERT_HANDLER

Signed-off-by: Kristoffer Rist Skøien <kristoffer.skoien@nordicsemi.no>
2019-09-10 08:32:02 -05:00
Stephanos Ioannidis 9b0e738e37 bluetooth: controller: Explicitly include toolchain.h.
This commit adds an explicit inclusion of toolchain.h from pdu.h.

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

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

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-09-09 21:40:54 +02:00
Morten Priess d62ad4117c bluetooth: controller: Added function to support RX link quota update
Added ll_rx_link_inc_quota to allow vendor to manipulate
mem_link_rx.quota_pdu when cleaning up nodes via ull_vendor.h.

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

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

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

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

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

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

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

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

Relates to #15256.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-09-07 17:10:22 +02:00
Ioannis Glaropoulos 1d45a2fe77 bluetooth: controller: minor fixes in inline comments
Several minor fixes to inline comments of #ifdef .. #endif
blocks.

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

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-31 17:04:29 +02:00
Wolfgang Puffitsch e8e668ae9c Bluetooth: controller: Fix endianness for length update.
Fix endianness when accessing length update parameters in PDU.

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

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

Relates to #18578.

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

Fixes #18645.

Signed-off-by: Vinayak Kariappa Chettimada <vinayak.chettimada@gmail.com>
2019-08-27 15:13:38 +02:00
Erik Brockhoff a4bd5b6835 bluetooth: controller: Fixing race re. adv disable in HDC
Re. issue "BT LL assert on LL/CON/ADV/BV-04-C #18584"

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-22 16:40:46 +02:00
Vinayak Kariappa Chettimada 73f0fa3727 Bluetooth: controller: split: Tx cleanup and comments
Post Tx pool corruption fix, clean up code and add comments
explaining the use of Tx node next field used to indicate
the Tx node's allocation from Control or Data pool.

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

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

Fixes #18546.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-22 14:34:04 +02:00
Vinayak Kariappa Chettimada 07460176ed Bluetooth: controller: split: Fix control flow issues
This fixes reported Coverity CID 203393 control flow issues.

Fixes #18381.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-20 14:17:26 +02:00
Morten Priess 69ff0f310e bluetooth: controller: Fix for uninitialized data compile error
Due to conditional compile path ending in LL_ASSERT(0), the compiler
sees code following the assert as using uninitialized variables.

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

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-08-19 11:26:20 +02:00
Carles Cufi cb700d0e12 Bluetooth: controller: Disable AE by default
Disable Advertising Extensions by default, since they are not really
operational and they take RAM.

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-08-15 15:07:12 +02:00
Vinayak Kariappa Chettimada 5d30d49f88 Bluetooth: controller: Fix ifdef block comment
Fix a minor incorrectly commented ifdef block.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-08-15 11:53:59 +02:00
Vinayak Kariappa Chettimada 3e0e378dca Bluetooth: controller: split: Fix pipeline for continuous events
Fix the pipeline prepare-resume implementation to correctly
handle multiple continuous events that request resume on
being pre-empted.

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

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

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

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

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

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

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

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-08-07 13:52:48 +02:00
Joakim Andersson bd89cc3f4d Bluetooth: Controller: Fix privacy advertiser connect peer address type
Fix an issue with enhanced connection complete event raised by the
advertiser role. The advertiser reported that it has resolved the
the identity address of the peer, even when the peer is connecting
using it's identity address.
The host will not have the correct on-air address type i.e public.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-06 14:53:33 +02:00
Vinayak Kariappa Chettimada 09c1c9e800 Bluetooth: controller: Decorrelate address generation from resolution
Changes related to Bluetooth TSE 11068.

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-30 12:57:02 +02:00
Wolfgang Puffitsch c5c3a46824 Bluetooth: controller: Settings for company_id and subversion_number.
Enable use of settings system in controller and introduce settings for
company_id and subversion_number.

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

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

The missing features will subsequently be submitted
upstream.

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

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-18 14:20:32 +02:00
Vinayak Kariappa Chettimada da431f2a7d Bluetooth: controller: split: Handle zero length L2CAP start frame
Added a fix to handle L2CAP start frame with payload length
of zero which otherwise sent zero length data start PDU on
air.

Relates to #17046.

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

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

Relates to #17097.

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

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

Related to #17097.

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

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

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

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

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

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

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

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

Relates to #15171.

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

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

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

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

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

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-15 15:22:23 +02:00
Vinayak Kariappa Chettimada ab69044310 Bluetooth: controller: Fix logging assert
Fix logging assertion by using bt_addr_le_str which uses
log_strdup().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-12 13:37:47 +02:00
Vinayak Kariappa Chettimada 17b05526ba Bluetooth: controller: Fix assert during DLE
Fix assert in controller checking ticker_id_prepare = 0 when
a scanner and connection are active, and the connection is
skipping events in order to resize Rx buffers.

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-10 14:10:37 +02:00
Vinayak Kariappa Chettimada a02151ebd4 Bluetooth: controller: split: Port radio event abort
Port the implementation that does radio event abort due to
ISR latencies. The implementation measures if the ISR could
not meet the hard real time deadline and closes the event
early.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-04 09:46:49 +02:00
Vinayak Kariappa Chettimada 3aa57808ac Bluetooth: controller: split: Add interface to get adv/scan handle
Added interface to get Advertiser and Scanner instance
handle for use in Lower Link Layer module.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-07-04 09:46:49 +02:00
Thomas Stenersen d596262821 Bluetooth: controller: Rename assert handler Kconfig title
Renames the "Blueooth Controller Assertion Handler" to "Application
Defined Assertion Handler" to better fit the purpose of the Kconfig
option.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2019-07-02 09:19:16 +03:00
Thomas Stenersen 3379b641b7 Bluetooth: controller: Remove BT_HCI_RAW dependency
Removes the dependency on BT_HCI_RAW from BT_CTLR_ASSERT_HANDLER.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2019-07-02 09:19:16 +03:00
Johan Hedberg 0d9dab300e Bluetooth: Introduce separate pool for discardable events
Introduce a separate buffer pool for events which the HCI driver
considers discardable. Examples of such events could be e.g.
Advertising Reports. The benefit of having such a pool means that the
if there is a heavy inflow of such events it will not cause the
allocation for other critical events to block and may even eliminate
deadlocks in some cases.

Also update all mesh samples not to specify explicit RX buffer counts
anymore. Instead, create appropriate defaults in Kconfig so that we
only need to override this in the app for cases like the bbc:microbit
with limited memory.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-01 16:36:15 +03:00
Johan Hedberg fc2fcd10cf Bluetooth: Add dedicated pool for HCI_Num_Completed_Packets HCI event
This event is a priority one, so it's not safe to have it use the RX
buffer pool which may be depleted due to non-priority events (e.g.
advertising events). Since the event is consumed synchronously it's
safe to have a single-buffer pool for it. Also introduce a new
bt_buf_get_evt() API for HCI drivers to simplify the driver-side code,
this effectively also deprecates bt_buf_get_cmd_complete() which now
has no in-tree HCI driver users anymore.

Fixes #16864

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-01 16:36:15 +03:00
Radu Alexe f1c5586523 Bluetooth: controller: better field names
Fields nodes, users are arrays; therefore their names should be plural
to suggest that.

Signed-off-by: Radu Alexe <radu.alexe@nxp.com>
2019-06-28 11:09:25 +02:00
Anas Nashif efb8df5366 cleanup: include/: move misc/stack.h to debug/stack.h
move misc/stack.h to debug/stack.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 536dd5a71f cleanup: include/: move misc/slist.h to sys/slist.h
move misc/slist.h to sys/slist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 1ed300b318 cleanup: include/: move misc/mempool_base.h to sys/mempool_base.h
move misc/mempool_base.h to sys/mempool_base.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif ee9dd1a54a cleanup: include/: move misc/dlist.h to sys/dlist.h
move misc/dlist.h to sys/dlist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 969f8f1c68 cleanup: include/: move entropy.h to drivers/entropy.h
move entropy.h to drivers/entropy.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 17ddd1714c cleanup: include/: move clock_control.h to drivers/clock_control.h
move clock_control.h to drivers/clock_control.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif e1e05a2eac cleanup: include/: move atomic.h to sys/atomic.h
move atomic.h to sys/atomic.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Vinayak Kariappa Chettimada a438e71460 Bluetooth: controller: Add PA/LNA support on NRF_P1 GPIO pins
Added support for using NRF_P1 GPIO pins on nRF52840 SoC.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-27 15:17:20 +02:00
Vinayak Kariappa Chettimada 4fe004ad87 Bluetooth: controller: Fix handling zero length L2CAP start frame
Added a fix handling L2CAP start frame with payload length
of zero which otherwise sent zero length data start PDU on
air.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-26 16:32:14 +02:00
Morten Priess 14537fee9d bluetooth: controller: Moved ull_entropy_get to LLL
Moved and renamed ull_entropy_get to lll_entropy_get, placed under
vendor specific ll_sw. This is needed for SW implemented entropy,
to allow vendor implementation of faster, less secure random number
generator for randomizing ADV timing.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-06-20 10:30:28 +02:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
David B. Kinder 2aebc980e2 doc: fix Kconfig misspellings
Fix misspellings in Kconfig files missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-06-18 15:07:52 -04:00
Morten Priess b34db7fb71 bluetooth: controller: Reverted revised ticker pending redesign
Reversed revised ticker implementation pending new design which resolves
the issues described in GH issues #16830.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-06-18 14:20:52 +02:00
Vinayak Kariappa Chettimada 3e56c2cf16 Bluetooth: controller: split: Fix buffer leak on disconnect
Fix pending Tx control buffer leak on supervision timeout.
Queued tx buffers in LLL consists of both data and control
PDUs but only data buffers got correctly released.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-17 15:32:35 +02:00
Kumar Gala a2693975d7 dts: Convert from DT_<COMPAT>_<INSTANCE>_<PROP> to DT_INST...
Change code from using now deprecated DT_<COMPAT>_<INSTANCE>_<PROP>
defines to using DT_INST_<INSTANCE>_<COMPAT>_<PROP>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-14 08:02:15 -05:00
Vinayak Kariappa Chettimada 802718a773 Bluetooth: controller: BT_CTLR_USER_EXT depends on BT_LL_SW_SPLIT
Make the Kconfig option BT_CTLR_USER_EXT depend on
BT_LL_SW_SPLIT.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-13 15:11:31 +02:00
Vinayak Kariappa Chettimada dd3e8241e9 Bluetooth: controller: split: Port random slave event backoff
Port the implementation that performed random backoff of
forced slave event scheduling.

When peer master implementation skips events, multiple
local overlapping slaves will randomize their forced
scheduling to break out of a round robin pattern increasing
the chance of synchronizing with their masters again.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-13 14:13:36 +02:00
Morten Priess 8a92818c0a bluetooth: controller: Revised ticker for improved conflict resolution
Changed ticker behavior to resolve conflicts in ticker_worker instead of
in ticker_job. This allows better real-time slot allocation, as well as
allowing callbacks even if ticker node doesn't get air-time (for audio
stream housekeeping). A priority property now also allows prioritizing
one ticker node over others.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-06-13 13:12:26 +02:00
Joakim Andersson f5d2d99762 Bluetooth: controller: Fix scan request when advertising directed
Fix scan requests being processed during directed advertisiments.
Directed advertise packets are not scannable

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-06-13 10:51:51 +02:00
Vinayak Kariappa Chettimada 3cf304fd95 Bluetooth: controller: split: Add ULL/LLL architecture assert checks
Add some missing fatal asserts that need to be caught to
avoid unexpected failures in the implementation of the
architecture.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-12 10:25:09 +02:00
Vinayak Kariappa Chettimada 3169556592 Bluetooth: controller: split: Fix tx_ack mfifo count
Fix the tx_ack mfifo count to accomodate both data and
control PDUs being acknowledged.

With out this fix, pending maximum number of data plus
control PDUs in LLL on supervision timeout asserted due to
tx_ack mfifo overflow.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-11 13:14:46 +02:00
Vinayak Kariappa Chettimada 23a6de5dd0 Bluetooth: controller: split: Port slave conn update assert fix
Explicitly track the connection update related ticker stop
and start to avoid asserting due to ticker update being done
at the same time for compensating the master clock drift.

Relates to #11764.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-11 11:09:38 +02:00
Vinayak Kariappa Chettimada b11a0d35ee Bluetooth: controller: split: Add internal ull_update_mark func
Added an internal ull_update_mark function to detect race
conditions while stopping ticker instances during slave
drift, disconnection and connection update.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-11 11:09:38 +02:00
Vinayak Kariappa Chettimada 79cb615770 Bluetooth: controller: split: Port Enc setup to be queueable
Port the fix for the controller implementation to make start
encryption queueable if there is any control procedure in
progress.

Refer to #15335.
Relates to #15335, #15186, #15958 and #14636.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-06-06 10:34:13 +02:00
Asger Munk Nielsen eb73a32bc1 Bluetooth: controller: Moved advanced settings in Kconfig
Moved some user defined Kconfig constants to advanced
settings menu.

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2019-05-30 17:14:54 -04:00
Asger Munk Nielsen 8844b7f5a5 Bluetooth: controller: Enable use of user defined protocols
Implements hooks to implement user protocols in ull.c
A user defined init function can now be called, this code is gated by
the CONFIG_BT_CTLR_USER_EXT define.
A user defined PDU length can now also be defined using the Kconfig
CONFIG_BT_RX_USER_PDU_LEN

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2019-05-30 17:14:54 -04:00
Vinayak Kariappa Chettimada 8de64fcb81 Bluetooth: controller: split: Fix shell app regression
Fix shell app regression due to stale tmp role implementation
not fully being removed in commit 4c77bf6194 ("Bluetooth:
controller: Remove redundant tmp role implementation").

The regression caused ticker indexes outside of allocations to
be accessed causing application faults and memory corruptions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-28 21:31:55 -04:00
Alexander Svensen 67de7ec86d Bluetooth: controller: split: Refactor if defines in lll_scan.c
This commit refactors if defines to use IS_ENABLED macro
for readability.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-27 09:24:44 -04:00
Alexander Svensen 1c33d90fdb Bluetooth: controller: split: Refactor if defines in lll_adv.c
This commit refactors if defines to use IS_ENABLED macro
for readability.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-27 09:19:06 -04:00
Joakim Andersson 34758e8349 Bluetooth: controller: Fix rx_ftr and extra overlapping memory
The the footer structure and extra bytes (rssi, resolving index etc.)
were overlapping in memory, rx_ftr was moved into the header, but the
extra and footer are still being read from the same place, extra was
written to the end. So this avoided memory corruption, but reading extra
reads wrong information.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-27 12:59:05 +02:00
Joakim Andersson 9e96df39f2 Bluetooth: controller: Fix compilation without broadcaster or observer
Fix compilation issues in central_hr or peripheral_hr sample when using
split LL and privacy is enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Joakim Andersson cecd7f8d70 Bluetooth: controller: Copy the connect_ind into node_rx
The node_rx buffer does not contain the data from the connect ind, so
copy it over.
Also back up the adv pdu chan_sel bit so that it can be used to properly
select the correct channel selection algorithm

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Joakim Andersson 6db4776980 Bluetooth: controller: Fix pdu being overwritten while in use
The node_rx buffer for the connect ind buffer is being reused to send
connection complete event, make sure all data is backed up before
reusing the buffer.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Joakim Andersson 65b3f17aa9 Bluetooth: controller: Fix initialization of rl_idx and rpa_gen
The privacy state variables rl_idx and rpa_gen was not initialized
properly, which results in connection failing to be established.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Vinayak Kariappa Chettimada b928cef69c Bluetooth: controller: split: Port h/w privacy feature
Ported h/w based LL privacy to ULL/LLL split architecture.

Fixes #14675.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Vinayak Kariappa Chettimada c5c87c38eb Revert "Bluetooth: controller: Disable controller privacy feature"
This reverts commit c629ea8a64.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-24 12:00:12 -04:00
Asger Munk Nielsen 69790e5c73 Bluetooth: controller: Enable use of proprietary rx demuxing functions
Code refactored to allow calling of a proprietary rx demux function.
This will enable implementation of proprietary protocols and
functionality that is not yet public, while keeping a common zephyr
code base.

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2019-05-22 14:59:30 +02:00
Peter A. Bigot ea6cad9b89 Bluetooth: controller: remove duplicated code
A conditional block to save a directed advertising report flag was
present three times.  Remove two of the blocks.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-05-21 21:42:01 -04:00
Alexander Svensen 63a93e8b5a Bluetooth: controller: split: Refactor if_defines to is_enabled in lll.c
This commit refactors if defines to use the macro is_enabled,
for readability

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-21 14:40:21 +02:00
Joakim Andersson 172dcec236 Bluetooth: controller: Fix unknown rsp received during enc procedure
Port fix for #14044 from legacy LL to split LL.

The master is using unknown rsp to terminate slave side initiated
procedures that has collided with the encryption procedure initiated by
the master.
We need to handle an unknown response that is sent in unencrypted during
the encryption procedure, even though we have already set up to receive
encrypted packets.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-05-15 10:10:42 +02:00
Joakim Andersson 289eab6ad5 Bluetooth: controller: Remove incorrect comment
Remove comment stating that UNKNOWN_RSP during encryption procedure
is a workaround.
The core spec mandates that connections should not be dropped if
receiving this control packet during encryption procedure.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-05-15 10:10:42 +02:00
Alexander Svensen d9d85fd1d3 Bluetooth: controller: split: Refactor the lll_clock_wait() function
This is a pure refactoring of the k32src_wait function. It used the
following rules when refactoring:

Don't use the preprocessor when unprocessed C language suffices.

Don't undefine macro's.

Avoid global variables when possible.

Use consistent names for similiar things (hf_clock, lf_clock).

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-14 14:18:02 +02:00
Alexander Svensen 3d94df7e8e Bluetooth: controller: split: Fix master role RSSI measurement
Fix broken master role RSSI measurement. Since the original
contribution clean up into Zephyr, the radio shorts that was
set for measuring the RSSI for master role has been broken,
as it was cleared by the radio switching code further in the
Tx ISR.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-14 14:08:11 +02:00
Asger Munk Nielsen 58e9ac6811 bluetooth: Controller: Refactor node_rx footer to avoid ptr arithmetic
The old footer was appended after PDU using pointer arithmetic. Now
the footer fields have been moved to the header struct, the
footer fields are now statically located in the data structure,
this is type safe and fields can be referred to by their actual
names rather than indirectly through reference to other members,
thus avoiding pointer arithmetic. Secondly, this change will pave
the way for adding other meta data in the future.

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2019-05-14 10:56:16 +02:00
Jakub Rzeszutko d9c18ff05e boards: arm: Add Nordic nRF52811 board
This commit adds support for board: nrf52811_PCA10056.

The nRF52840 DK: PCA10056 is the recommend development kit, it emulates
the nRF52811, and can be used as a starting point for development
before moving over to a custom board.

Please note that this development kit does not support Bluetooth
Direction Finding. What is more it cannot be used with most of Arduino
shields because of PCA10056 PIN layout.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-05-14 09:52:57 +02:00
Alexander Svensen 774d5e871c Bluetooth: controller: split: Fix Conn Param Req procedure stall issue
Fix an issue wherein local or remote initiated Connection
Parameter Request procedure would stall without generation
of LE Connection Update Complete HCI event because a local
or remote initiated PHY Update procedure has overwritten the
currently active Link Layer Control Procedure type.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-08 11:21:52 +02:00
Mariusz Skamra 44739f4427 Bluetooth: controller: Workaround CPR procedure collision at CPU instant
This is a workaround for IOP issue, where peer rejects LLCP Slave
Connection Parameter Request with LMP Error Transaction Collision
error code even if previous request is complete at the instant.

Relates to #15366.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-07 23:17:34 -04:00
Vinayak Kariappa Chettimada 019d282ab2 Bluetooth: controller: Fix Enc Setup overlap with Length Update
Fix the encryption setup queueing implementation to avoid
overlapping with local initiated Length Update Procedure.

Fixes #15733.
Relates to #15335, and #15186.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-07 23:16:23 -04:00
Andrzej Głąbek 9a5cb2280e bluetooth: controller: hal: Correct the bit mask of used PPI channels
This is a follow up to commit 0eaa5e53a36af498115b4e56b1ea68cc89fc29ee.

`HAL_SW_SWITCH_RADIO_ENABLE_S2_PPI_BASE` is a base number for two PPI
channels, so two bits need to be marked in the used channel bit mask.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-05-07 11:12:01 +02:00
Carles Cufi 2a0a48f6bb Bluetooth: controller: hal: Fix PPI macro naming
Due to a protracted merge of:
5e38ed9320
the naming for the HAL_SW_SWITCH_RADIO_ENABLE_S2_PPI changed
semnatics, now requiring use of
HAL_SW_SWITCH_RADIO_ENABLE_S2_PPI_BASE.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-05-06 17:46:56 +02:00
Andrzej Głąbek 5e38ed9320 ext: nrfx: Reserve PPI channels and groups used by Bluetooth controller
Mark the PPI channels and groups used by the Bluetooth controller
as occupied and thus unavailable for allocation through nrfx_ppi.

Add also a build time assertion that checks if these PPI channels
do not overlap with those assigned to the pwm_nrf5_sw driver
(to replace the comments in this driver that were supposed to warn
about this threat but had in fact little chance to be read by users).

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-05-06 15:25:44 +02:00
Alexander Svensen e5cf9ce1f2 Bluetooth: controller: ull/lll: Do not feature exc more than once
Updated the controller implementation to not feature
exchange if already done once either by local or remote peer
device in an active connection session.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-06 14:47:48 +02:00
Vinayak Kariappa Chettimada c629ea8a64 Bluetooth: controller: Disable controller privacy feature
Disable the unsupported controller privacy feature in the
ULL/LLL split architecture implementation.

This feature will be enabled in the future when it has been
ported to support multiple vendor SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada 90c205f6a0 Bluetooth: controller: Enable Zephyr VS HCI in ULL/LLL impl.
Enable the support for Zephyr HCI Vendor-Specific Commands
and Event in the ULL/LLL split architecture implementation
of the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada 06ddc2bbec Bluetooth: controller: Fix Rx and Tx buffer sizes
Fix incorrectly defined Rx and Tx buffer sizes. Wrong
calculation allocated more memory than necessary.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada a4370b73f5 Bluetooth: controller: Fix ULL LLL execution priority selection
Fix Kconfig default values for ULL and LLL execution
priorities that caused build warnings when ranges changes
based on other priority values being selected.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada 9602a690bd Bluetooth: controller: Fix incorrect data type use in slot calc
Fix incorrect data type used in calculation of slot_us
detected by compiler, and reported as possible integer
overflow.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada e2dbe4f6f3 Bluetooth: controller: Fix incorrect conditional compilation
Fix incorrect conditional compilation that caused compile
error when lll_scan structure did not contain connection
context included which is needed only for central role.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-06 14:41:58 +02:00
Vinayak Kariappa Chettimada 343937c542 Bluetooth: controller: ull/lll: Fix pin or key missing response
Fix the missing reset of Encryption Procedure state when the
peripheral responded with error reason as pin or key missing
which otherwise caused connection disconnection on next
reception of data or control packet.

Relates to #15570, and #15727.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-03 14:26:46 -04:00
Alexander Svensen 8a4c13146e Bluetooth: controller: ull/lll: Workaround CPR procedure collision
This is a workaround for IOP issue, where peer rejects LLCP Slave
Connection Parameter Request with LMP Error Transaction Collision
error code even if previous request is complete at the instant.

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-05-03 14:24:47 -04:00
Vinayak Kariappa Chettimada b8c2c7e71a Bluetooth: controller: ull/lll: Increase adv random delay resolution
Increase the resolution of advertising random delay from
1 ms unit to 1 ticker unit.

Relates to #10289, #10391, and #10398.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-03 08:33:13 -04:00
Vinayak Kariappa Chettimada 4cebd73824 Bluetooth: controller: Use void pointer to return rand value
Use void pointer to return random value from ull_entropy_get
interface.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-03 08:33:13 -04:00
Morten Priess ffcbf121e8 bluetooth: controller: Made BT_CTLR_RX_PRIO_STACK_SIZE non-hidden
Added prompt to BT_CTLR_RX_PRIO_STACK_SIZE, allowing vendor specific
configuration of high priority Rx thread stack size for
!SOC_COMPATIBLE_NRF.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-05-03 12:40:00 +02:00
Vinayak Kariappa Chettimada 211a81f9f4 Bluetooth: controller: Fix XTAL advanced feature
Fix XTAL advanced feature by adding the missing
implementation to calculate and, retain or release the XTAL
clock source after a Bluetooth state or role is stopped.

Fixes #15817.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-03 12:20:22 +02:00
Vinayak Kariappa Chettimada 4b9dee8a74 Bluetooth: controller: Add GPIO Debug Pins for HFCLK state
Add implementation to toggle GPIO Debug pins on HFCLK
request and release by the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-03 12:20:22 +02:00
Vinayak Kariappa Chettimada 54e78b9041 Bluetooth: controller: Move LLL-to-ULL Tx Ack API to ULL
Move the LLL-to-ULL Tx Ack queue API to ULL files.

Fixes #49.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-02 22:53:45 -04:00
Vinayak Kariappa Chettimada 23269d9891 Bluetooth: controller: Implement low latency ULL processing
Implement a lower ISR latency ULL processing design. Instead
of looping use ISR/mayfly tail-chaining to process
successive ULL messages.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-02 22:53:45 -04:00
Vinayak Kariappa Chettimada 34f6d08ff0 Bluetooth: controller: Yield ULL processing when Ctrl PDU deferred
Implemented ULL to yield from processing in an infinite loop
if current PDU being handled is deferred.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-02 22:53:45 -04:00
Vinayak Kariappa Chettimada a872911cbb Bluetooth: controller: Fix missing BT_CTLR_FILTER conditional
Fix missing BT_CTLR_FILTER conditional compilations that
cause compile errors when device whitelisting feature is
disabled in builds.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-02 07:48:38 -04:00
Morten Priess 646f617a39 bluetooth: controller: Allow out-of-tree vendor specific HCI commands
Renamed function vendor_cmd_handle to vendor_cmd_handle_common for
shared vendor commands. This allows vendor to implement
vendor_cmd_handle, containing both common and specific handling.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-05-02 12:28:38 +02:00
Mark Ruvald Pedersen 99fae68010 Bluetooth: controller: commentary and readability improvements
* Rename the stack local 'done' to 'evdone' so as to disambiguate from
  MFIFO_DEQUEUE_PEEK(done) which is actually 'mfifo_done'.

* add comment on ull_slave_done

* add comments to addr_us_get

* add comments to HCI_CLASS

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 11:12:21 +02:00
Vinayak Kariappa Chettimada 23636cbae0 Bluetooth: controller: Fix pin or key missing response
Fix the missing reset of Encryption Procedure state when the
peripheral responded with error reason as pin or key missing
which otherwise caused connection disconnection on next
reception of data or control packet.

Relates to #15570.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-02 11:04:16 +02:00
Thomas Ebert Hansen 3ac8fa5c00 bluetooth: controller: Move Nordic specific code
Move lll_chan_set into Nordic LLL.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2019-05-01 10:40:41 -04:00
Thomas Ebert Hansen a202c14ff5 bluetooth: controller: Move Nordic specific code
Move the call to radio_is_idle into Nordic LLL.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2019-05-01 10:40:41 -04:00
Vinayak Kariappa Chettimada a1cbbbe9bd Bluetooth: controller: Fix nRF52840 Coded PHY timings
Fix the nRF52840 Coded PHY radio timings based on testing
with conformance tester.

Fixes the following conformance tests:
LL/CON/MAS/BV-52-C [Master Receiving Data, LE Coded, CI Change]
LL/CON/MAS/BV-54-C [Slave Receiving Data, LE Coded, CI Change]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-05-01 10:28:26 -04:00
Vinayak Kariappa Chettimada f35dd8ece8 Bluetooth: controller: Fix regression in Coded PHY CI Change
Fix the regression in Coded PHY CI change implementation
introduced by reverting the commit 9d1ca9c390 ("Bluetooth:
controller: remove redundant PPI channel and TIMER CC").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-05-01 10:28:26 -04:00
Morten Priess c741ef6efd bluetooth: controller: Mayfly yield after call under Kconfig
Added Kconfig BT_MAYFLY_YIELD_AFTER_CALL to support vendor requirement
of invoking all outstanding mayflies for a given callee in
mayfly_run().

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-04-30 15:42:20 +02:00
Morten Priess d533dde0ad bluetooth: controller: Moved library source for lll_test.c
Moved library source for nordic/lll/lll_test.c under
CONFIG_BT_LLL_VENDOR_NORDIC condition.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-04-30 15:41:56 +02:00
Morten Priess 23e1f4d2bc bluetooth: controller: Added missing variable initializations
In ull.c ll_rx_get, a configuration without CONFIG_BT_CONN would
sometimes return an uninitialized node_rx.
In ull_scan.c, the scanning channel was not initialized to 0 (37). This
would cause new scanning to start at random index (0,1,2).

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-04-30 15:41:23 +02:00
Morten Priess 4596e155a3 bluetooth: controller: Minor refactoring in ticker.c
Moved duplicate code to function. Removed superfluous include.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-04-30 15:11:55 +02:00
Morten Priess 21ae70504d bluetooth: controller: Source code documentation of ticker
Added source code documentation to ticker.c.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-04-30 15:11:55 +02:00
Erik Brockhoff 5c3709c13f bluetooth: controller: Add def's re. update to slot reservation calc
Add defines to support updated slot reservation calculation in advertise
Note: Numbers used in added defines are subject to HW specific tuning

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2019-04-30 15:10:13 +02:00
Erik Brockhoff 1618c1b885 bluetooth: controller: Update to use new EVENT_IFS_US define
Added a new define (EVENT_IFS_US) to pdu.h - this is now used instead of
previous TIFS_US from vendor specific header

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2019-04-30 15:10:13 +02:00
Erik Brockhoff 1090b45225 bluetooth: controller: Update slot reservation time calculation for ADV
Correct slot reservation time calc for legacy advertise
Add dependency on data lengths for advertise and scan response

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2019-04-30 15:10:13 +02:00
Vinayak Kariappa Chettimada 5257fede63 Bluetooth: controller: Fix advanced XTAL feature regression
Fix regression by the addition of CONFIG_BT_CONN conditional
compilation that disabled the advanced clock (crystal)
oscillator management when only observer and/or advertiser
states supported in the controller build.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-29 13:08:12 +02:00
Vinayak Kariappa Chettimada e90ba89812 Bluetooth: controller: Fixes to pass DLE/PHY conformance tests
Added implementation to pause data PDU transmission during
PHY update procedure in order to comply to BT Spec. v5.1
Vol.6, Part B, Section 5.1.10.1 Packet transmit time
restrictions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-23 12:09:23 -07:00
Vinayak Kariappa Chettimada 7b68ec888c Bluetooth: controller: Move PKT_US to ULL internal header
Minor refactoring to move PKT_US into ULL internal header,
and rename ull_conn_allowed_check to ull_conn_llcp_req.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-23 12:09:23 -07:00
Vinayak Kariappa Chettimada 705515c092 Bluetooth: controller: Data Length Update port to ULL/LLL arch
Ported implementation of Data Length Update Procedure to
ULL/LLL architecture of the Link Layer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-23 12:09:23 -07:00
Vinayak Kariappa Chettimada fff35bd682 Bluetooth: controller: Fix encryption setup to be queueable
Fix the controller implementation to make start encryption
queueable if there is any control procedure in progress.

The context related to encryption procedure is now shared so
that it will be used after the ongoing procedure completes.

The fix here maintains the old functionality of serializing
the queued data and LL Encryption Request PDU, so that data
queued before start encryption is acknowledged.

Fixes #15012.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-11 13:22:02 -04:00
Vinayak Kariappa Chettimada e81acd8c3f Bluetooth: controller: Revert set encryption procedure pending
This reverts commit 0cf82cdd31.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-04-11 13:22:02 -04:00
Joakim Andersson 0e7bf9b657 Bluetooth: controller: Send unknown rsp to unexpected ENC ctrl PDU
Send unknown rsp instead of asserting when encryption related control
PDUs are received in the wrong state.
This would allow an attacker to intentionally crash the device.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-04-10 14:01:21 +02:00
Joakim Andersson 9fb3abef1e Bluetooth: controller: Fix length request during encryption procedure
Stop the Length request procedure from initiating during the encryption
procedue. This would cause the peer to disconnect the link with error
code LMP_TRANSACTION_COLLISION

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-04-10 14:01:21 +02:00
Joakim Andersson 0cf82cdd31 Bluetooth: controller: Set encryption procedure pending
Set the encryption procedure pending and start it as soon as
there are no other procedures running.
This allows the Host to enqueue the encryption procedure, and not
get disallowed command because a different LL procedure is active.

Fixes #15012

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-04-10 14:01:21 +02:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Joakim Andersson fa20ac3693 Bluetooth: controller: Fix assert in raising event during proc collision
The fix done in #14938 introduced a later assert when raising an HCI
event for the procedure that was terminated during the procedure
collision handling. This assert happens because the unknown rsp
has information that is needed when raising the event.
Solve this by copying the scratch packet into the node buffer so that
we keep the data.

Fixes #15183

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-04-05 09:31:22 -04:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Patrik Flykt 21358baa72 all: Update unsigend 'U' suffix due to multiplication
As the multiplication rule is updated, new unsigned suffixes
are added in the code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Joakim Andersson 273796e1bb Bluetooth: controller: Fix unknown rsp received during enc procedure
The master is using unknown rsp to terminate slave side initiated
procedures that has collided with the encryption procedure initiated by
the master.
We need to handle an unknown response that is sent in unencrypted during
the encryption procedure, even though we have already set up to receive
encrypted packets.

Fixes #14044

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-03-28 14:41:10 +01:00
Joakim Andersson 66d339a7c9 Bluetooth: controller: Fix scanner memory corruption
Fix a bug where the controller would use the length
field of the advertisement packet before checking
if the length field was valid.
It is possible that the controller has received a packet
that passes CRC check but has a length field that is invalid.
This would cause the scanner to overwrite the scan report
buffer

Fixes: #14741
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-03-22 13:58:24 +01:00
Johan Hedberg 4882849f18 Bluetooth: controller: Convert benign BT_WARN() messages to BT_DBG()
BT_WARN() should only be used for log messages that may indicate a
problem. However, the controller HCI code was using it for messages
that were of a pure debugging/informational nature. Convert these to
BT_DBG() instead - this should hopefully also help avoid unnecessary
user questions of seemingly alarming log messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-03-19 18:17:41 +02:00
Joakim Andersson 319a1239aa Bluetooth: controller: Fix PHY bits sets with PHY disabled
The 2M and Coded PHY bit should not be set when the
PHY update procedure is not supported.

Fixes #14658

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-03-19 16:34:55 +02:00
Joakim Andersson f4c8e3ff31 Bluetooth: controller: Fix transaction collision
Peer side will disconnect if controller initiates
Encryption procedure before PHY update procedure
has finished.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-03-19 09:55:41 +01:00
Joakim Andersson 100287d77b Bluetooth: controller: Fix bug in LL encryption.
Fix bug in LL encryption procedure, controller was
using the wrong pointer to connection state.
Function event_enc_prep is called from
slave_event_prepare, where _radio.curr_conn has not
been assigned yet.
The connection ended up sending LL_START_ENC_RSP
unencrypted, resulting in disconnect on the peer
side with reason MIC failure.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-03-15 20:56:16 +01:00
Vinayak Kariappa Chettimada d570e139dc Bluetooth: controller: Fix tx power level set and get
Fix implementation to correctly return the configured
default Tx Power Level.

Also, fix the missing use of RADIO_TXP_DEFAULT in the new
ULL/LLL implementation of Advertiser and Observer states.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-15 11:07:32 +01:00
Vinayak Kariappa Chettimada 5d78a5f07a Bluetooth: controller: Read Tx Power Level depends on Connections
Conditionally compile HCI Read Tx Power Level command for
connections support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-03-15 11:07:32 +01:00
Vinayak Kariappa Chettimada f4281c38f8 Bluetooth: controller: Add range delay calculations
Add implementation in controller to use range delay
alongwith the active clock accuracy jitter.

Range has been hard coded to 1000 meters, suffices
modules out in the market.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-15 11:07:00 +01:00
Vinayak Kariappa Chettimada fd334a2aa5 Bluetooth: controller: Fix disabled Prop. PHY Update for nRF51 series
Due to regression the option to enable PHY Update Procedure
on proprietary 2M PHY for nRF51 series was disable.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-15 11:06:23 +01:00
Vinayak Kariappa Chettimada 0437fd7aff Bluetooth: controller: Workaround multi-link DLE assert
Workaround from asserting when Rx PDU buffers from pool
needing resize is acquired by another connection. By
skipping the connection events to give some headroom for
the host to process the Rx packets and eventually make the
pool available for resize.

Fixes #11841.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-15 11:05:12 +01:00
Wolfgang Puffitsch d7fac9bf8c Bluetooth: controller: Support big-endian archs in split controller.
Use reverse order for bitfields on big-endian architectures. Treat
all PDU data as little-endian and add conversions as needed. Treat
access address as 4-byte value instead of u32_t to avoid flipping
endianness.

Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
2019-03-13 10:37:40 +01:00
Thomas Stenersen caa4f7baae kconfig: bluetooth: Let BT_HCI_VS be configurable from controller
This moves the vendor-specific HCI command/event configuration
definitions out of bluetooth/common into bluetooth. This allows
the controller itself to indicate its support for vendor-specific
commands/events.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2019-03-12 19:42:40 +01:00
Carles Cufi 1cdf2460f4 Bluetooth: controller: Fix unchecked return value
Check the return value of mayfly_enqueue() and assert if not successful.

Coverity ID: CID 190991
Fixes #13833.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-03-05 13:08:12 +01:00
Maksim Masalski eead071b18 bluetooth: fix unchecked return from lll_clk_off in ll_test_end
Inside ll_test_end(), result of lll_clk_off() is not checked
which might result in releasing resources acquired for radio.

Coverity-CID: 190954
Fixes: #13861
Signed-off-by: Maksim Masalski <maxxliferobot@gmail.com>
2019-03-05 11:21:55 +01:00
Vinayak Kariappa Chettimada 4fb64d11c8 Bluetooth: controller: Fix disabled clear text DLE for nRF51 series
Due to regression the option to enable Data Length Update
Procedure for nRF51 series was disable.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-03 23:56:16 -05:00
Vinayak Kariappa Chettimada 5f2099fb63 Bluetooth: controller: Workaround for Unknown Rsp during Enc Setup
Some old peer central controllers respond with Unknown
Response PDU to our local Slave Initiated Feature Request
after the peer initiated the Encryption Setup Procedure.

The peer has voilated the Bluetooth Specification by sending
the Unknown Response during the Encryption Setup Procedure,
but as a workaround to IOP with such controller our local
implementation is updated to not disconnect the connection
but accept the voilating Unknown Response PDU.

Relates to #12362.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-03-01 14:23:50 +01:00
David B. Kinder e731bdc81a doc: fix docs, include, and Kconfig misspellings
Fix misspellings missed during regular reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-02-28 09:32:12 +01:00
Ulf Magnusson 40436f730b kconfig: Use a short consistent prompt style
Same change as in commit 8cf8db3a73 ("Kconfig: Use a short, consistent
style for prompts"), fixing stuff that got introduced since then.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 09:23:30 +01:00
Piotr Zięcik d30c9aeafd drivers: nrf_power_clock: Migrate to DTS.
This commit migrates the nrf_power_clock driver to DTS.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-02-25 17:51:24 +01:00
Mark Ruvald Pedersen 406dc2cb0e bluetooth: controller: Static mem_pdu_rx, remove PDU_RX_SIZE_MIN
mem_pdu_rx is not runtime resized meaning PDU_RX_SIZE_MIN is no longer
relevant.

Dynamic resizing was a left-over from the old bt controller.
Its size field was only ever set to PDU_RX_SIZE_MIN.
PDU_RX_SIZE_MIN only accounted for advertise PDUs.
So we remove size field from mem_pdu_rx.

However, the rest of the BT controller expects to be able to pull
RX_CNT-number of valid nodes from the pool at init/reset (rx_alloc)
time. This will fail unless we inflate the capacity by one.

To avoid inflation-by-one, mem_* would have to be rewritten to avoid
always-one-extra pattern.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-19 10:34:48 +01:00
Mark Ruvald Pedersen e24d1efe7c bluetooth: controller: Refactor PDU_RX_POOL_SIZE
Refactor PDU_RX_POOL_SIZE into its constituents and name each term.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-19 10:34:48 +01:00
Vinayak Kariappa Chettimada 0d82116655 Bluetooth: controller: Fix bug in Encryption feature cond. compile
Fix a bug in Encryption Procedure feature conditional
compile which prevent any data transfer when the feature was
disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-19 09:27:24 +01:00
Mark Ruvald Pedersen 10d3f070e6 bluetooth: controller: Document RX path flow from mayfly to HCI
No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-18 15:13:45 -05:00
Mark Ruvald Pedersen 479df56858 bluetooth: controller: Add a few ticker comments
No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-15 09:52:14 -05:00
Mark Ruvald Pedersen d315dbd67b bluetooth: controller: Commentary in LLL header
No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-15 09:51:54 -05:00
Mark Ruvald Pedersen e4892abe31 bluetooth: controller: Document more of memq, mfifo
* Slight tweaks to memq comments,
 * Document most of mfifo through commentary.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-15 09:49:45 -05:00
Mark Ruvald Pedersen a61938130b bluetooth: controller: Add comments across ull
* Clarify certain functions and data structures in upper link layer.
 * Disambiguate node rx event done, add commentary.

MFIFO_DEQUEUE macro does string concatenation.
Thus MFIFO_DEQUEUE(done) does not refer to done (the stack local), but
mfifo_done.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-15 09:49:34 -05:00
Mark Ruvald Pedersen 9d8a614ed7 bluetooth: controller: Introduce ull_ref_dec for consistency
ull_ref_inc already existed, but not ull_ref_dec.
No functional change expected.
Consistency is preferred due to code navigation.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-15 09:49:21 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Vinayak Kariappa Chettimada 85d92923e2 Bluetooth: controller: Rename non-Kconfig option macros
Remove CONFIG_ prefix from non-Kconfig macro definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 09:20:26 -05:00
Vinayak Kariappa Chettimada 72bef65087 Bluetooth: controller: Fix non-HCI error code return value data type
Fix the return value of non-HCI errror code data type to
int.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada e6a256a785 Bluetooth: controller: Fix Rx buffer size variable data type
Fix the Rx buffer size variable data type to fit memory
block sizes greater than 255.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada 5aa9d2ce1e Bluetooth: controller: Remove unused commented code
Remove unused redundant commented code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada e85c4d00b6 Bluetooth: controller: Rename ull_tx_ack_put to ll_tx_ack_put
Rename ull_tx_ack_put to ll_tx_ack_put as ack is enqueued
into LL thread context from ULL ISR context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada 5bacbf612d Bluetooth: controller: Move PKT_US from LLL to ULL header file
Move PKT_US definition from LLL header file to ULL header so
as to share it across vendors.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada d33641f39a Bluetooth: controller: Remove underscore prefixes from functions
Cleanup and rename functions from having underscore prefixes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-13 12:21:51 +01:00
Vinayak Kariappa Chettimada dd25e59762 Bluetooth: controller: Fix compile error in observer only support
Fix compile error due to missing conditional compile of
connection related code when selecting only observer state
support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-12 08:37:31 -05:00
Vinayak Kariappa Chettimada 7a99035515 Bluetooth: controller: 32-bit word align allocations
nRF51 series requires the 32-bit word aligned accesses to
avoid hardfaults.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-12 08:37:05 -05:00
Alexander Svensen 8d86773d6b Bluetooth: controller: refactored llcp_req/ack test to helper function
Moved test of llcp_req/ack to separate helper function in ull_conn.c

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
2019-02-12 09:38:25 +01:00
Wolfgang Puffitsch 012d404125 bluetooth: controller: Remove trailing semicolons in HCI defines.
Remove trailing semicolons from defines.

Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
2019-02-10 16:16:58 -05:00
Filip Kubicz 5e4f6e9c73 Bluetooth: ctlr: Return different error codes on advertising start
Return meaninful HCI error when it's not possible to start advertising
because of maximum number of connections already in use.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2019-02-07 12:56:26 +02:00
Vinayak Kariappa Chettimada c086c9e8fe Bluetooth: controller: Fix dereferencing type punned pointer
Fix compiler warning about dereferencing type-punned pointer
that will break strict-aliasing rules.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-05 15:00:08 +01:00
Vinayak Kariappa Chettimada 4c77bf6194 Bluetooth: controller: Remove redundant tmp role implementation
Remove the redundant proof of concept template temporary
role implementation from the repository.

Relates to #12860.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-05 15:00:08 +01:00
Vinayak Kariappa Chettimada ff88b7f255 Bluetooth: controller: ULL/LLL: Fix compile error with PA/LNA
During regression testing of PA/LNA feature it was noticed
that compilation failed due to missing port of the code
conditionally compiled for PA/LNA feature.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-02-02 10:35:40 -05:00
Johan Hedberg 006946b8f4 Bluetooth: controller: Use net_buf_pull_mem() for command parsing
It's more natural to use net_buf_pull_mem() for the HCI command
parsing. Note that this also fixes a bug in hci_cmd_handle() where it
would previously check for sufficient parameter length with the
command header still included in the buffer (which it shouldn't have
been).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Vinayak Kariappa Chettimada 749652080c Bluetooth: controller: Fix control procedure context safety
Fix the control procedure context safety by adding checks in
thread mode control path to detect pre-emption by interrupt.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada 1475402d41 Bluetooth: controller: Introduce ULL LLL architecture
This is a squash merge of commits introducing the new split
Upper Link Layer and Lower Link Layer architecture of the
Bluetooth Low Energy controller.

This introduces a new, improved Link Layer based on the
concept of split responsibilities; The Upper Link Layer
(ULL) is in charge of control procedures, inter-event
scheduling and overall role management. The code for the
ULL is shared among all hardware implementations. The
Lower Link Layer (LLL) is responsible for the intra-event
scheduling and vendor specific radio hardware access.

The communication between ULL and LLL is achieved through
a set of FIFOs that contain both control and data packets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada 254a97af93 Bluetooth: controller: Preliminary work in progress mesh ext.
Preliminary work done towards Mesh extensions on the old LL
architecture implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada 44d046ff8d Bluetooth: controller: Updates to prep to introduce new arch
Missing updates to old architecture implementation towards
introduction of new ULL LLL architecture.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada 0989c0f8c2 Bluetooth: controller: Refactor the internal LL interfaces
Refactored the internal LL interfaces to have return value
to match the HCI error code u8_t data type.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Ioannis Glaropoulos 2e687653fa drivers: clock control: rename nrf5_power_clock source and header
This commit renames the nrf5_clock_control.h and
nrf5_clock_control.c files to nrf_clock_control.h and
nrf_clock_control.c, respectively, as they are used
in nRF9160 builds, as well.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-01-15 18:03:24 +01:00
Ioannis Glaropoulos 302a746bd6 drivers: clock control: nrf: rename CLOCK_CONTROL_NRF5 Kconfig symbol
This commit renames the CLOCK_CONTROL_NRF5 Kconfig symbol to
CLOCK_CONTROL_NRF. The change is required to aleviates confusion
when selecting the symbol in nRF9160 SOC definition.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-01-15 18:03:24 +01:00
Johan Hedberg a7a0d27ae2 Bluetooth: Give proper names to Bluetooth threads
Provide names for all Bluetooth threads so that they don't show up as
"NA" when issuing the "kernel stacks" command in the shell.

To get this info the following Kconfig options need to be enabled:

CONFIG_THREAD_STACK_INFO=y
CONFIG_THREAD_MONITOR=y
CONFIG_KERNEL_SHELL=y
CONFIG_INIT_STACKS=y
CONFIG_THREAD_NAME=y

After issuing the "kernel stacks" command the output should look
something like this:

uart:~$ kernel stacks
0x200011D0 BT RX      (real size 1024): unused 760      usage 264 / 1024 (25 %)
0x20001148 BT RX pri  (real size 448):  unused 280      usage 168 / 448 (37 %)
0x20000654 BT ECC     (real size 1100): unused 168      usage 932 / 1100 (84 %)
0x20000764 BT TX      (real size 640):  unused 280      usage 360 / 640 (56 %)
0x20001ED8 sysworkq   (real size 1024): unused 592      usage 432 / 1024 (42 %)
0x200004C4 shell_uart (real size 2048): unused 904      usage 1144 / 2048 (55 %)
0x20000058 logging    (real size 768):  unused 584      usage 184 / 768 (23 %)
0x20001D84 idle       (real size 256):  unused 184      usage 72 / 256 (28 %)
0x20001E08 main       (real size 1024): unused 768      usage 256 / 1024 (25 %)

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-15 17:39:54 +01:00
Wolfgang Puffitsch 3159049c39 bluetooth: controller: Update ticker_user_op for predictable layout.
Use fixed-width type instead of enum for field op in struct
ticker_user_op to avoid struct layout differences between
compilers. Also make check whether struct sizes match size definitions
build-time asserts.

Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
2019-01-14 10:12:15 +01:00
Mark Ruvald Pedersen 076fd6a32a bluetooth: controller: Document mem, memq, util
Adds documentation-commentary to some infrastructure used by the LL.
It is a long-term effort to better document the LL.

Notably ticker and mayfly require more documentation; this will be
done later.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-01-10 18:00:41 +01:00
Vinayak Kariappa Chettimada 87fe440f01 Bluetooth: controller: Prepare to introduce LL split architecture
Preparation to introduce the Upper Link Layer (ULL) and
Lower Link Layer (LLL) split architecture.

- Move SoC dependent HAL to vendor specific folder.
- Preparation to split data structures into ULL and LLL
  types.
- Added more role and state conditional compilations.
- Added some work-in-progress implementation of advertising
  extensions, will be used as inspiration in the new split
  architecture work.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-07 13:42:01 +01:00
Vinayak Kariappa Chettimada 99ae80b632 Bluetooth: controller: Fix Conn Param Req procedure stall issue
Fix an issue wherein local or remote initiated Connection
Parameter Request procedure would stall without generation
of LE Connection Update Complete HCI event because a local
or remote initiated PHY Update procedure has overwritten the
currently active Link Layer Control Procedure type.

Signed-off-by: Vinayak Kariappa Chettimada <vinayak.kariappa@gmail.com>
2018-12-19 14:47:38 +01:00
Alberto Escolar Piedras fc0f80391c Bluetooth: nordic ECB hal: Bugfix for simulation
Fix in the do_ecb() function
In real HW this function busy waits for the ECB to be done.
In simulation with the POSIX arch a WFE was added to avoid that
infinite loop.
But this function is called with the ECB interrupts disabled.
In normal builds other interrupts will awake the CPU very soon
after entering into that WFE, and the problem was not discovered.

But, in controller only builds, during some conformance tests,
the loop will hang as no other interrupts are coming.

=> Replace the WFE() with a k_busy_wait (only for simulation)

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-12-12 12:12:04 +01:00
Vinayak Kariappa Chettimada afbbb97ab1 Bluetooth: controller: Fix chan map update's diff trans collision
Fix channel map update procedure implementation's handling
of different transaction collision by not asserting but
disconnecting the connection due to invalid behavior by
peer implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-12-12 12:05:05 +01:00
Vinayak Kariappa Chettimada 5e7c916e77 Bluetooth: controller: Fix CPR procedure regression
This fixes regression introduced in commit a11868fea9.

Fixes the following conformance tests:
LL/CON/MAS/BV-32-C [Accepting Connection Parameter Request -
Preferred Periodicity]
LL/CON/MAS/BV-33-C [Accepting Connection Parameter Request -
Preferred Periodicity and preferred anchor points]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-12-10 11:13:48 +01:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Vinayak Kariappa Chettimada a2f2d23c9f Bluetooth: controller: Fix conn update assert in slave role
Explicitly track the connection update related ticker stop
and start to avoid asserting due to ticker update being done
at the same time for compensating the clock drift.

The compensation related ticker update failure in this case
can be safely ignored as new anchor point is used anyway
at the instant of the connection update.

Fixes #8796

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-12-03 10:38:57 +01:00
Mariusz Skamra 8f5ba0be88 Bluetooth: Add common Kconfig option to disable LE Data Length Update
This adds common option to disable support for LE Data Length Update
procedure in controller and host.
This will reduce flash usage by compiling out le_data_len_change
event handler that will never be called if controller has been
compiled with BT_CTLR_DATA_LENGTH option disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Mariusz Skamra be314d3af5 Bluetooth: Add common Kconfig option to disable PHY Update
This adds common option to disable support for PHY Update
procedure in controller and host.
This will reduce flash usage by compiling out le_phy_update_complete
event handler that will never be called if controller has been
compiled with BT_CTLR_PHY option disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Vinayak Kariappa Chettimada aa5bbd5dfe Bluetooth: controller: Fix enable and disable of scan state
Updated controller implementation to disallow disabling
initiator state using scan disable. But allow disabling an
already disabled scan state. Also, disallow enabling scan
state while in initiator state.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-20 11:19:07 +01:00
Vinayak Kariappa Chettimada c326ae729f Bluetooth: controller: Do not feature exchange more than once
Updated the controller implementation to not feature
exchange if already done once either by local or remote peer
device in an active connection session.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-20 11:14:58 +01:00
Andrzej Głąbek 4750cf3b7b bluetooth: controller: nrf5: Reorder used PPI channels
The channels assigned to the controller are reordered so that the ones
previously used and now available for other purposes have continuous
numbers. When the controller can take advantage of the pre-programmed
PPI channels (when TIMER0 is used as the event timer), the now free
channels are 0-4, when it cannot, it is the channel 0.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-10 12:39:40 -05:00
Andrzej Głąbek 589b65e72d bluetooth: controller: nrf5: Use pre-programmed PPI channels
Several PPI channels in nRF5 family SoCs are pre-programmed with fixed
settings. A few of them can be used in the bluetooth controller instead
of the freely programmable ones that are used currently. This commit
makes such replacements where possible so that the universal channels
can be left available for other purposes.

This commit also removes macros used previously in calls to functions
enabling and disabling particular PPI channels (as it is sufficient
to use the BIT macro to set bits corresponding to the channel numbers)
to prevent such problems like the one introduces by commit
9d1ca9c390 (channel 18 changed to 17
but the related macro definition not updated).

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-10 12:39:40 -05:00
Vinayak Kariappa Chettimada f403bfa343 Bluetooth: controller: Add min & max interval support in CPR
Add support for exchanging both minimum and maximum
connection interval values in Connection Parameter Request
Procedure implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-06 20:56:13 -05:00
Sebastian Bøe 637c41a382 Bluetooth: controller: Refactor the k32src_wait() function
This is a pure refactoring of the k32src_wait function. It used the
following rules when refactoring:

Don't use the preprocessor when unprocessed C language suffices.

Don't undefine macro's.

Avoid global variables when possible.

Use consistent names for similiar things (hf_clock, lf_clock).

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-11-05 21:46:00 +01:00
Flavio Ceolin aecd4ecb8d kernel: Change k_poll_signal api
k_poll_signal was being used by both, struct and function. Besides
this being extremely error prone it is also a MISRA-C violation.
Changing the function to contain a verb, since it performs an action
and the struct will be a noun. This pattern must be formalized and
followed and across the project.

MISRA-C rules 5.7 and 5.9

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-04 11:37:24 -05:00
Vinayak Kariappa Chettimada 133d3870b3 Bluetooth: controller: Fix integer overflow in scheduling code
Fix an integer overflow in the scheduling implementation
that calculates whether resources required for next radio
event be retained.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-02 12:26:32 -04:00
Piotr Zięcik 708468bdce Bluetooth: controller: Optimize RNG access
This commit optimizes access to RNG driver by taking advantage
of the data structures layout. As result, number of calls to RNG
driver is reduced.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-10-30 11:16:34 +01:00
Piotr Zięcik 615efcce69 drivers: entropy: nrf5: Remove entropy_nrf_get_entropy_isr() function
The entropy_nrf_get_entropy_isr(), which is specific to this driver,
is in fact equivalent of generic entropy_get_entropy_isr(..., 0).

This commit removes the entropy_nrf_get_entropy_isr() function
and replaces its usage by call to generic entropy API.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-10-30 11:16:34 +01:00
Sebastian Bøe 5e23278bab Bluetooth: Controller: Use a different flag for speed optimization
The bluetooth controller has been using the flag '-Ofast' to keep
within a real-time limit. There are two problems with this; firstly,
when a project should be optimized for size it is standard to use -O2,
not -Ofast.

Secondly, optimization flags have been deemed to be non-portable, so
instead of directly using "-Ofast" we should use the intent-macro
OPTIMIZE_FOR_SPEED_FLAG to ensure toolchain portability.

Testing has shown that we are still within the real-time limit when
changing from -Ofast to -O2. -Ofast is about 1us and 1% faster, but
increases the code size by 13kB (5% of the available flash on a
nRF51).

Since the slowdown is comparatively small compared to the code size
increase we have decided to use -O2 in place of -Ofast.

Other optimization combinations were also measured and their results
can be seen below:

-Ofast in BLE Controller and in #pragma in entropy driver.

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      138920 B       256 KB     52.99%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 75, 45, 132.

-O2 in BLE Controller and in #pragma in entropy driver.

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      125840 B       256 KB     48.00%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 75, 51, 133

-O3 in BLE Controller and in #pragma in entropy driver.

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      138920 B       256 KB     52.99%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 75, 50, 132.

No extra CFLAGS for BLE and entropy driver (pragmas removed), using
CONFIG_SIZE_OPTIMIZATIONS=y

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      120124 B       256 KB     45.82%

        [bt] [ERR] isr_rx_conn: assert: '!radio_is_ready()' failed

No extra CFLAGS for BLE and entropy driver (pragmas removed), using
CONFIG_SPEED_OPTIMIZATIONS=y

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      138004 B       256 KB     52.64%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 61, 51, 130.

NB: RAM usage differences were insignificant.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-26 15:55:49 +01:00
Szymon Janc 2abd05e9fc Bluetooth: controller: Compile conn complete due to cancel conditionally
BT_HCI_ERR_UNKNOWN_CONN_ID can only be sent when master role is enabled.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-25 17:03:59 +01:00
Johan Hedberg 251d99132d Bluetooth: Remove custom stack macros
Now that log processing happens in a separate thread, the
BT_STACK_EXTRA macro is not needed (since there's no significant
overhead), and therefore the BT_STACK macros become unnecessary as
well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg 343c53e841 Bluetooth: Switch from SYS_LOG to logger-based logging
Initial conversion to use syslog instead of logger.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Vinayak Kariappa Chettimada 51574c177f Bluetooth: controller: Avoid retransmission of NACK-ed Tx PDU
Added implementation to avoid retransmitting NACK-ed Tx PDU,
to save on current consumption in retrying to transmit in
case peer device has no free buffer to receive the PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-16 10:32:41 +02:00
Alberto Escolar Piedras 5f39dbb1b0 Bluetooth: Use new nrf COMPATIBLE options
To allow the BLE stack to be used both in the real nRF platforms
and simulated ones, change the used macros in the code to the
COMPATIBLE ones.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-10-15 09:36:37 -04:00
Vinayak Kariappa Chettimada d80fee1ecb Bluetooth: controller: Fix master role RSSI measurement
Fix broken master role RSSI measurement. Since the original
contribution clean up into Zephyr, the radio shorts that was
set for measuring the RSSI for master role has been broken,
as it was cleared by the radio switching code further in the
Tx ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-15 11:08:00 +02:00
Vinayak Kariappa Chettimada ae8649c5ec Bluetooth: controller: Fix connection failed to be established
Fix connection failed to be established regression
introduced by the commit 350c569aba ("Bluetooth:
controller: Avoid offseting to lldata").

As the Rx-ed PDU buffer is re-used to construct the
connection complete message towards HCI, the fields in the
Rx-ed PDU need to be backup for future use in the control
path. Here the channel selection bit is backup now.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-11 20:50:44 +02:00
Vinayak Kariappa Chettimada a11868fea9 Bluetooth: controller: Fix conn param req procedure response
Fix Connection Parameter Request Procedure implementation
to respond with sent interval_min and interval_max so that
certain peer devices dont reject the response as Invalid LL
Parameters.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-11 20:30:02 +02:00
Vinayak Kariappa Chettimada 71fff7648d Bluetooth: controller: Refactor adv random delay resolution fix
Refactored the fix in the commit 685da02354 ("Bluetooth:
controller: Fix advertising random delay resolution calc")
to apply modulo in tick units before adding a tick.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-08 12:53:50 -04:00
Vinayak Kariappa Chettimada 049267a5ca Bluetooth: controller: Fix connection cancel deadlock
Calling bt_recv in the Bluetooth host Tx thread by the
controller implementation caused deadlock in combined host
controller builds when HCI LE Create Connection Cancel
generated the HCI LE Connection Complete or HCI LE Enhanced
Connection Complete events.

Controller's HCI implementation has been updated to place
the generated event into Rx FIFO to avoid the deadlock.

Relates to commit a59f544fb4 ("bluetooth: controller:
Handle non-priority events correctly")

Relates to #10314.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-05 13:44:10 +02:00
Vinayak Kariappa Chettimada 350c569aba Bluetooth: controller: Avoid offseting to lldata
Avoid offseting to lldata when populating event structure
members.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-05 13:44:10 +02:00
Michael Scott 685da02354 Bluetooth: controller: Fix advertising random delay resolution calc
In commit d5836195d7 ("Bluetooth: controller: Increase advertising
random delay resolution"), the resolution of random_delay was
increased from 8-bit to 16-bit.  Due to this switch the result
of HAL_TICKER_US_TO_TICKS() can now be a 0, which causes the following
crash:
***** Kernel OOPS! *****
Current thread ID = 0x200043f0
Faulting instruction address = 0x17914
Fatal fault in ISR! Spinning...

Let's make sure we don't pass a 0 to ticker_update() by increasing
the result of HAL_TICKER_US_TO_TICKS() by 1.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-10-05 10:18:27 +02:00
Vinayak Kariappa Chettimada 3d1a659019 Bluetooth: controller: Fix default Tx buffers
Fix the default Tx buffers to 3. While the first Tx-ed
buffer generates the HCI Number of Completed Packets Event,
the controller needs to have 2 additional Tx buffers queued
so that the second Tx PDU has the More Data (MD) bit set so
as to have the connection event to continue to transmit any
additional Tx buffers that the Host will enqueue in the same
connection event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-04 11:45:54 +02:00
Vinayak Kariappa Chettimada d5836195d7 Bluetooth: controller: Increase advertising random delay resolution
Increase the resolution of advertising random delay from
1 ms unit to 1 us units. The controller scheduling will
floor it to nearest 32KHz clock unit on nRF5 series.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-09-28 18:03:51 +02:00
Mark Ruvald Pedersen d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Carles Cufi d813b13109 Bluetooth: controller: Remove timestamp from HCI
In order to avoid the build system complications that come from
including a timestamp, remove it by default from the version string in
HCI Vendor Extensions. Users can still include a unique identifier, be
it timestamp or not, using the CONFIG_BT_CTLR_HCI_VS_BUILD_INFO Kconfig
option.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-09-26 14:50:26 +02:00
Vinayak Kariappa Chettimada 684f753fd4 Bluetooth: controller: Fix Data Length Update implementation
The Data Length Update implementation reused the flags used
by Encryption Procedure which caused invalid Encryption
Procedure sequence under conditions where Data Length Update
Procedure collide with Encryption Setup initiated by the
peer central device.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-09-26 11:55:02 +02:00
Sebastian Bøe f8616291e4 Kconfig: BT: Give the LL selection option a name
There is an unnamed choice for the BT link layer selection.

Giving the choice a name would allow multiple declarations of the
option and the ability to select out-of-tree LL's.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-09-25 09:42:23 +02:00
Szymon Janc 6c89c4b5f7 Bluetooth: Controller: Add support for setting public address
This allows to provide public address for controller without using
VS HCI command from host. Useful for controller only builds or
combined builds that are not using VS HCI commands.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-21 12:40:10 +02:00
Szymon Janc 732b45cff3 Bluetooth: Read static address from FICR on nRF5 if no VS enabled
When running combined build on nRF5 with disabled VS command it is
possible to simply read static random address from FICR in host.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-19 13:03:56 +02:00
Szymon Janc e76224d038 Bluetooth: Controller: Add CONFIG_BT_HCI_VS option
This allows to fully disable HCI VS commands support.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-19 13:03:56 +02:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Alberto Escolar Piedras 877c4d0ca7 Bluetooth: controller: Use nRFx functions for PPI reg access
In the BLE controller, NRF radio HAL, for the PPI registers used
for the SW TIFS.
To allow easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-12 13:13:48 +02:00
Vinayak Kariappa Chettimada f3be631625 Bluetooth: controller: Fix compile error when PHY update disabled
Fixed compile error when PHY update feature is disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-27 12:48:12 -04:00
Vinayak Kariappa Chettimada f232643f7c Bluetooth: controller: Use HCI Error Code definitions
Replase magic numbers with HCI Error Code definitions in the
LE controller implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-24 16:10:01 +03:00
Vinayak Kariappa Chettimada 94d7669cf3 Bluetooth: controller: Fix assert on different transaction collision
Updated the implementation of Connection Update Procedure to
not assert when peer master violates the Bluetooth
Specification v5.0 Vol.6 Part B Section 5.3 Procedure
Collisions. Instead disconnect the link with reason
Different Transaction Collision (0x2A).

Certain phones in the market perform Connection Update
Procedure and do not correctly handle remote initiated
colliding PHY update procedures. They try to perform both
the transactions involving an instant simultaneously
violating the Bluetooth Specifications.

Implementation in Zephyr is updated to gracefully handle
the violating remote master device, and not fatally assert
in the local device.

Relates to commit 8b3fd6963c ("Bluetooth: controller: Fix
assert on different transaction collision")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-24 16:10:01 +03:00
Vinayak Kariappa Chettimada 8b3fd6963c Bluetooth: controller: Fix assert on different transaction collision
Updated the implementation of PHY update procedure to not
assert when peer master violates the Bluetooth Specification
v5.0 Vol.6 Part B Section 5.3 Procedure Collisions. Instead
disconnect the link with reason Different Transaction
Collision (0x2A).

Certain phones in the market perform Connection Update
Procedure and do not correctly handle remote initiated
colliding PHY update procedures. They try to perform both
the transactions involving an instant simultaneously
violating the Bluetooth Specifications.

Implementation in Zephyr is updated to gracefully handle
the violating remote master device, and not fatally assert
in the local device.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-18 23:22:10 +02:00
Ulf Magnusson ec3eff57e0 Kconfig: Use the first default with a satisfied condition
Up until now, Zephyr has patched Kconfig to use the last 'default' with
a satisfied condition, instead of the first one. I'm not sure why the
patch was added (it predates Kconfiglib), but I suspect it's related to
Kconfig.defconfig files.

There are at least three problems with the patch:

  1. It's inconsistent with how Kconfig works in other projects, which
     might confuse newcomers.

  2. Due to oversights, earlier 'range' properties are still preferred,
     as well as earlier 'default' properties on choices.

     In addition to being inconsistent, this makes it impossible to
     override 'range' properties and choice 'default' properties if the
     base definition of the symbol/choice already has 'range'/'default'
     properties.

     I've seen errors caused by the inconsistency, and I suspect there
     are more.

  3. A fork of Kconfiglib that adds the patch needs to be maintained.

Get rid of the patch and go back to standard Kconfig behavior, as
follows:

  1. Include the Kconfig.defconfig files first instead of last in
     Kconfig.zephyr.

  2. Include boards/Kconfig and arch/<arch>/Kconfig first instead of
     last in arch/Kconfig.

  3. Include arch/<arch>/soc/*/Kconfig first instead of last in
     arch/<arch>/Kconfig.

  4. Swap a few other 'source's to preserve behavior for some scattered
     symbols with multiple definitions.

     Swap 'source's in some no-op cases too, where it might match the
     intent.

  5. Reverse the defaults on symbol definitions that have more than one
     default.

     Skip defaults that are mutually exclusive, e.g. where each default
     has an 'if <some board>' condition. They are already safe.

  6. Remove the prefer-later-defaults patch from Kconfiglib.

Testing was done with a Python script that lists all Kconfig
symbols/choices with multiple defaults, along with a whitelist of fixed
symbols. The script also verifies that there are no "unreachable"
defaults hidden by defaults without conditions

As an additional test, zephyr/.config was generated before and after the
change for several samples and checked to be identical (after sorting).

This commit includes some default-related cleanups as well:

  - Simplify some symbol definitions, e.g. where a default has 'if FOO'
    when the symbol already has 'depends on FOO'.

  - Remove some redundant 'default ""' for string symbols. This is the
    implicit default.

Piggyback fixes for swapped ranges on BT_L2CAP_RX_MTU and
BT_L2CAP_TX_MTU (caused by confusing inconsistency).

Piggyback some fixes for style nits too, e.g. unindented help texts.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-10 12:38:28 -07:00
Alberto Escolar Piedras 3712fd3415 Bluetooth: controller: remove unnecessary guards in hal headers
After a dedicated header is allocated to the simulated SOC versions
there is no need anymore to have guards in these other files

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-09 12:15:45 +02:00
Alberto Escolar Piedras e0864a9338 Bluetooth: controller: HAL: Separate simulated SOC in own header
To avoid issues with differences between the simulated and the real
SOC let's separate the simulated one into its own header

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-09 12:15:45 +02:00
Vinayak Kariappa Chettimada 3ebb81ba73 Bluetooth: controller: Wait for stable k32src for connected roles
Added implementation to check and wait for stable 32KHz
clock source before starting connectable/directed
advertising state and initiating state.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-02 01:04:46 +02:00
Vinayak Kariappa Chettimada 76320d2142 Bluetooth: controller: Fix HCI LE Set PHY command status response
Fixed the implementation to generate command status as per
Bluetooth v5.0 specification instead of the incorrect
command complete that was generated before.

Also, the unsupported features status will be generated
before the invalid parameters status.

Relates to commit 258c7ccff1 ("Bluetooth: controller: Fix
HCI LE Set PHY invalid behavior check")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-02 01:03:17 +02:00
Vinayak Kariappa Chettimada 97da52bb95 Bluetooth: controller: Update AA generation for Coded PHY support
Update the access address generation function with Coded PHY
support requirements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-02 01:02:29 +02:00
Szymon Janc e3bf53566e Bluetooth: controller: Fix disabling LE Encryption support
Symbols without prompt cannot be configured from application
configuration file.

warning: BT_CTLR_LE_ENC (defined at subsys/bluetooth/controller/
Kconfig:198) was assigned the value 'n' but got the value 'y'.
This symbol has no prompt, meaning assignments in configuration files
have no effect on it. It can only be set indirectly, via Kconfig
defaults (e.g. in a Kconfig.defconfig file) or through being 'select'ed
or 'imply'd (note: try to avoid Kconfig 'select's except for trivial
promptless "helper" symbols without dependencies, as it ignores
dependencies and forces symbols on).

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-07-25 13:52:03 +03:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

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

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Vinayak Kariappa Chettimada 505a83414e drivers: gpio: nrf5: Fix GPIOTE channel use overlap
Fixes issues caused in GPIO driver due to overlapping GPIOTE
channel use in nRF5 software PWM driver and in Bluetooth
controller for implementing PA/LNA feature.

The issue is solved by assigning the base and available
channel count for GPIOTE considering whether PWM and/or
PA/LNA feature is selected in the Kconfig.

Fixes #8815.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-07-10 11:25:32 +02:00
Joakim Andersson dbc00ba374 Bluetooth: controller: Fix empty_pkt_us_get for 2M phy.
An empty packet on 2M phy is one more byte compared to 1M phy because
of the preamble.
The empty packet is then 11 bytes, which takes 44 us to transmit.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-07-03 22:47:45 -04:00
Ioannis Glaropoulos 0677812910 arch: arm: nrf: remove kernel_includes.h from nRF5x soc.h inclusions
This commit removes the inclusion of kernel_includes.h from
the nRF51 and nRF52 soc.h headers. This prevents from an
inclusion cycle formation on soc.h. In the wake of
kernel_includes.h removal, necessary header files have been
added in several source files to be able to compile Zephyr for
nRF5x SOCs.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-07-02 16:50:10 +02:00
Joakim Andersson c6dea9e068 Bluetooth: Reorganize Kconfig options for BLE controller
Split meaning of BT_CTLR and BT_LL_SW, since they always are the same.
This way BT_CTLR means that there an controller implemented,
and BT_LL_SW refers to the specific implementation.
This allows alternative controller implementations.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-07-02 11:59:43 +02:00
Mariusz Skamra 8f6ebc5322 Bluetooth: controller: Fix LE Extended Scanner Filter Policy dependency
This adds dependency upon Observer role.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-28 22:16:31 +02:00
Vinayak Kariappa Chettimada cea4b31866 Bluetooth: controller: Add support for the nRF52810
The nRF52810 is a low-cost variant of the nRF52832, with a reduced set
of peripherals and memory. This commit adds Bluetooth controller support
for it.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-06-27 16:09:58 +02:00
Joakim Andersson 5e3c48f43c bluetooth: Make controller crypto functions optional
Provide flexibility in choosing to use the host defined crypto
functions or the ones provided by the controller

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-06-27 12:12:45 +02:00
Alberto Escolar Piedras 15ae4fa314 Bluetooth: controller: Use nRFx functions for PPI reg with sideef
In the BLE controller, radio HAL, for the PPI registers:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras c97645c884 Bluetooth: controller: Use nRFx functions for TIMER reg w sideeffects
In the BLE controller, radio HAL (TIMER registers):
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras 1c5bb49415 Bluetooth: controller: Use nRFx functions for CCM reg w sideeffects
In the BLE controller radio HAL, for the CCM registers:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.
(CCM part)

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras 88f0fbdc00 Bluetooth: controller: Use nRFx functions for RTC reg w sideeffects
In the Radio HAL, for the RADIO and RTC registers:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras 5f146e491e Bluetooth: controller: Use SOC series macro instead of the board macro
In the BLE controller radio HAL:
To avoid confusion, use SOC series macro instead of board macro.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras 1742972585 Bluetooth: controller: Use SOC series macro instead of board macro
In the BLE controller ECB HAL:
To avoid confusion, use SOC series macro instead of board macro.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras 347f32621a Bluetooth: controller: Use nRFx functions for ECB reg with sideeffect
In the BLE HAL for the ECB:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras bc606d2220 Bluetooth: controller: Use nRFx functions for RTC reg with sideeffects
In the ble hal for the RTC:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Vinayak Kariappa Chettimada 660c5c92c0 Bluetooth: controller: Remove include guards in internal files
Remove include guards in internal files; it is an agreed
convention to not have include guards in internal header
files in Bluetooth subsystem.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-14 17:11:42 +02:00
Vinayak Kariappa Chettimada 362a6b34c7 Bluetooth: controller: Fix to use max. tx power in DTM test mode
According to the Bluetooth Specification v5.0, Direct Test
Mode shall use maximum Tx power.

Fixed by adding nRF5x Radio HAL interfaces to get supported
maximum Tx power for SoC selected, and DTM testing sets the
Radio peripheral to use maximum Tx power.

Fixes #7243

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-12 13:22:10 +02:00
Vinayak Kariappa Chettimada dc95e1ba05 Bluetooth: controller: Add Tx Power Kconfig option
Add support for changing the default Tx Power value using
Kconfig option.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-11 17:40:00 -04:00
Vinayak Kariappa Chettimada edb2ad11f0 Bluetooth: controller: Remove redundant include of cmsis.h
Remove the redundant include of cmsis.h as soc.h already
includes it as necessary.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-11 17:30:29 -04:00
Carles Cufi a59f544fb4 bluetooth: controller: Handle non-priority events correctly
In certain cases the response to a command can come in the form of a
non-priority event. This is the case of LE Create Connection Cancel,
which generates a Command Complete and then an LE (Enh) Connection
Complete. Take this case (and other future ones) into account by calling
the correct Host recv function.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-05-25 17:25:41 +02:00
Carles Cufi 6f534e4551 drivers: entropy: nrf5: Implement standard ISR-specific call
Implement the new entropy_get_entropy_isr() function to allow the kernel
to collect entropy before the scheduler and kernel data structures are
ready. Switch to an nrf-specific version for high-performance
requirements in the BLE Link Layer.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-05-24 15:13:13 -07:00
Johan Hedberg 8d1f67c605 Bluetooth: Remove references to non-existing Kconfig symbols
Remove non-existent Kconfig symbol references. An additional (but
related) change is the removal of all persistent storage symbols from
the Arduino 101 Bluetooth shell app, since BT_STORAGE no longer
exists.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-23 16:57:59 -04:00
Vinayak Kariappa Chettimada 6c6d98bc4e Bluetooth: controller: Use hal/ticker.h to abstract SoC specifics
Introduce hal/ticker.h to abstract out SoC specific
implementations and move any conditional compilations to
include header files here.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-04-09 10:34:04 +02:00
Ulf Magnusson 93689bdc80 kconfig: Remove no-op selects of choice symbols
Selecting a choice symbol is always a no-op, and the latest version of
Kconfiglib prints a warning. This commit removes all selects of choice
symbols, which might make the Kconfig files a bit clearer and gets rid
of the warnings.

This is just a dumb removal. I did not try to guess the intent of each
select.

Fixes #6849

Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
2018-03-29 08:57:39 -04:00
Vinayak Kariappa Chettimada 4c49df98e5 Bluetooth: controller: Fix missing device filter clear
Fix missing device filter clearing for cases where whitelist
was used and then in subsequent adv/scan enable it was
unused.

This fixes an assert in ll_filter.c at line 248.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-26 16:44:35 +02:00
David Maitland f77469a3bb Bluetooth: controller: Refactor to use max macro
Cleaned up the use of conditional statements to use the max macro.

Fixes #6230.

Signed-off-by: David Maitland <hello@davidmaitland.me>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-25 11:33:51 +02:00
Carles Cufi 8aa9a37902 drivers: flash: nrf: Rename nrf5 to nrf
With upcoming ICs that are not in the nRF5x family, rename the flash
driver and all its dependencies from nrf5 to nrf.

Should also fix the issue introduced by f49150cab6 which broke the
assignment of the flash device due to a partial rename.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-20 20:07:09 +01:00
Carles Cufi f49150cab6 arch: arm: nrf: Rename nrf5 SoC Family to nrf
Upcoming Nordic ICs that share many of the peripherals and architecture
with the currently supported nRF5x ones are no longer part of the nRF5
family. In order to accomodate that, rename the SoC family from nrf5 to
nrf, so that it can contain all of the members of the wider Nordic
family.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-20 11:57:14 +01:00
Carles Cufi fb3387a490 Bluetooth: Remove rand driver and use entropy instead
After porting the rand driver to drivers/entropy, replace the usage of
the old, Buetooth-specific driver with the generic entropy one.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-14 16:47:50 +01:00
Carles Cufi 50693c0fcd Bluetooth: controller: Generate LE Conn Complete on cancellation
When using the LE Create Connection Cancel command, the controller is
supposed to return a Command Complete first and then an LE Connection
Complete Event after. Since the Link Layer does not generate an event in
this case emulate the behavior in the HCI layer instead.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-07 12:49:47 +01:00
Carles Cufi d4d2581b76 Bluetooth: controller: Default to the LF Company ID
The Linux Foundation has been assigned a Company Identifier, and with it
a means of identifying Zephyr over the air. Default to the LF Company
Identifier, which can be overridden by silicon vendors.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-02 17:27:35 +01:00
Vinayak Kariappa Chettimada ac34131f42 Bluetooth: controller: Fix missing advDelay in Low Duty Cycle Directed
Fixed the controller implementation for the missing advDelay
for connectable directed advertising events used in a low
duty cycle mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-02 16:34:39 +01:00
Alberto Escolar Piedras 4484e9efbd bluetooth: controller: nrf5: fix to IC-specific reset function
Fix of 80210198ad so it does
not cause a segfault in simulated boards

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-03-02 16:33:52 +01:00
Alberto Escolar Piedras cf07caa3c9 bluetooth: controller: last radio hal changes for simulation
All sideeffects for simulation are there now, including CCM part

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-28 19:56:16 +01:00
Carles Cufi 80210198ad bluetooth: controller: nrf5: Add IC-specific reset function
In order to address anomalies 102, 106 and 107 in nRF52, add a generic
hal_radio_reset() that does additional processing when required by a
particular IC or IC family. Implement the fix for the nRF52.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-02-24 12:33:51 +01:00
Vinayak Kariappa Chettimada b55e7b784c Bluetooth: controller: Use RADIO_TIES_US to define inter event space
Use RADIO_TIES_US to define minimum inter event space
between concurrent master and slave roles below which it
will be detected as a probable drift towards each other
leading to them overlapping on each other.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-20 15:34:55 +01:00
Vinayak Kariappa Chettimada 7fa2c4dfac Bluetooth: controller: Add missing HCI supp. cmd bits for PHY Update
Added missing HCI Supported Commands bit fields for PHY
Update feature. Also, refactored with missing conditional
compilation for other bit fields.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 11:46:21 +01:00
Vinayak Kariappa Chettimada ae03e35d6c Bluetooth: controller: Fix incorrect master role scheduling
Revert incorrect calculation introduced in
commit ec5a787da2 ("Bluetooth: controller: Fix multiple
master role event scheduling") and revert a related
incorrect fix in commit a02606cbf9 ("Bluetooth:
controller: Fix missing ticks to us conversion").

Fixes the controller assert in ctrl.c line number 1477. A
64-bit arithmetic took ~35 us in Radio ISR for nRF51 causing
the ISR to take too much time before packet buffer could be
set.

Also, fixed master scheduling by correctly accounting for
the jitter between each master event.

Relates to: #5486

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada 067ac68f0b Bluetooth: controller: Fix XTAL_ADVANCED threshold detection
Fix incorrect calculation of unreserved timespace which
should take into account the ticks_slot of current event,
and compensation for any reduced prepare in the current
event as well as in the next event.

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada 1433475b29 Bluetooth: controller: Define HAL_TIMER_SIGN_BIT
Define a macro HAL_TIMER_SIGN_BIT to correspond to the most
significant bit support by counter hardware used by ticker.

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

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

Fixes #6204.

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-15 21:15:21 +01:00
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 af13d6d581 Bluetooth: controller: Fix soft latencies in periodic ticker
Fix, add the missing code for the removal of any accumulated
soft latencies or negative drift ticks when scheduling next
interval expiry with added laziness.

Typically a first interval would accumulate soft latencies
and this has to be removed if the interval is rescheduled
with any added laziness (scheduled to the next soft real
time interval).

Example, scan windows block any new scheduling until the end
of the window, adding latencies to any soft real time ticker
expiry which should try to execute as early as possible after
the scan window.

Fixes: #6083

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada a152109eb1 Bluetooth: controller: Fix nRF52840 radio timings for Coded PHY
Fix incorrect radio timing for Tx chain delay for S2 and S8
coding. Regression introduced  in commit 55d3ce111c
("Bluetooth: controller: Refactoring nRF5 radio driver").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-11 20:33:02 +01:00
Vinayak Kariappa Chettimada 18f366ca07 Bluetooth: controller: Fix disabling of Coded PHY feature
Fix conditional compilation in nRF5 radio interface so that
when Coded PHY feature is not selected then it does not use
the PPIs required for supporting the feature.

This will allow pwm_nrf5_sw driver to use PPI channels 14 to
19 and support 3 PWM channels. Without the Coded PHY feature
disabled, only PPI 14, 15, 18 and 19 are available for PWM.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Ioannis Glaropoulos d09baafe64 Bluetooth: controller: inline implementation of radio-enable-on-tIFS
This commit implements a minor refactoring of the implementation
for enabling the Radio on TIFS expiration. It inlines a function
that is defined in the local radio_nrf5_ppi header file.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos 2764084561 Bluetooth: controller: implement sw-switch with the event timer
This commit contributes the implementation of the sw-switch for
tIFS in nRF5 Radio using the EVENT_TIMER instead of a dedicated
TIMER instance. A Kconfig configuration is added so the user can
select whether to use the EVENT_TIMER for the tIFS switch or use
a dedicated TIMER instance.

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

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos 9c4dc04ba5 Bluetooth: controller: conditionally reuse CC for ISR profiling
This commit adds the option of conditionally reuse an existing
CC register of the event timer for timer sampling used in ISR
profiling, in case SW tIFS switching is implemented based on the
event timer.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos 2a85dda206 Bluetooth: controller: symbolic name for CC used in ISR profiling
This commit adds a symbolic name for the event timer
CC offset that is used to sample the event timer during
ISR profiling.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Vinayak Kariappa Chettimada d4cc46c453 Bluetooth: controller: refactor radio_nrf5* headers
Refactor radio_nrf5* header files to group together
definitions and have less #if-#else-#endif.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Vinayak Kariappa Chettimada 258c7ccff1 Bluetooth: controller: Fix HCI LE Set PHY invalid behavior check
Fix HCI LE Set PHY command for invalid behavior testing for
invalid parameters and unsupported features.

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-02 10:40:52 +01:00
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
Alberto Escolar Piedras ec7727077b native: nrf52 changes to HAL to support running on simulated HW
Conditionally compiled changes to the NRF52 HAL so it can
run on simulated HW on the native port.
(HW models are not included in this commit)

All changes are under ifdefs and therefore will not have any
effect on normal builds

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-01-29 16:02:29 +01:00
Vinayak Kariappa Chettimada 619bcf56c4 Bluetooth: controller: Refactor mayfly integration into hal
Refactor mayfly based execution context solution out into
the HAL folder. This opens up the possibility to use
tasklets (if and when kernel gets the support) style
execution contexts.

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

Fixes: #5823

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 11:51:10 +01:00
Vinayak Kariappa Chettimada ae9f5b38d0 Bluetooth: controller: Add missing CPR and DLE cond. compilation
Add missing conditional compilation in controller's HCI
implementation, removing redundant code being compiled in.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 11:16:45 +01:00
Vinayak Kariappa Chettimada be0aa2ac2c Bluetooth: controller: Remove redundant clear of NRF_RADIO events
Remove redundant code that clears NRF_RADIO->EVENT_*
registers that are only used in PPI context. Only EVENT_*
registers that are read back need to be cleared.

Relates to: #5753

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-24 11:07:06 +01:00
Ioannis Glaropoulos 9d1ca9c390 Bluetooth: controller: remove redundant PPI channel and TIMER CC
This commit implements the SW-based radio switch for TIFS for LE
Coded PHY S2 in nRF52840 with a single PPI channel and a single
TIMER CC register.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-24 11:06:33 +01:00
Ioannis Glaropoulos adaef465e4 Bluetooth: controller: minor refactoring in nrf5 radio driver
This commit moves the radio enable on-tick functionality in
function hal_radio_enable_on_tick_ppi_config_and_enable() in
radio_nrf5_ppi.h.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-24 11:06:33 +01:00
Ioannis Glaropoulos 36ded0b516 Bluetooth: controller: adjust nRF52840 HW radio timings for Coded PHY
This commit adjust the nRF52840 HW Radio timings for LE Coded PHY.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-24 11:06:33 +01:00
Vinayak Kariappa Chettimada 13130dbe73 Bluetooth: controller: Fix BT_CTLR_DEBUG_PINS Kconfig help text
Help text for BT_CTLR_DEBUG_PINS incorrectly mentioned
specific GPIO pins being reserved for this feature, but in
reality the pins reserved vary on the SoC selected, hence
any specific mention of pin details is removed from help
text.

Fixes: #5499

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-24 11:05:51 +01:00
Vinayak Kariappa Chettimada 5d4a32b70a Bluetooth: controller: Fix missing TIFS_HW cond. compilation
Fix a missing !CONFIG_BT_CTLR_TIFS_HW conditional
compilation when nRF52840 is configured to use hardware
Trx switching, that caused compile error.

Fixes: #5779
Fixes: #5761

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-22 15:33:15 -06:00
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 891ba80087 Bluetooth: controller: Fix S2 coding Rx chain delay timing const
Fix the S2 coding Rx chain delay timing constant based on
manual observations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-29 10:31:44 +01:00
Vinayak Kariappa Chettimada d3585cd1d9 Bluetooth: controller: Add tIFS SW switching for Coded PHY
Add implementation to consider differing Rx chain delays for
S2 and S8 Coded PHY PDU reception. These changes are
required to meet tIFS timings for transmission after a
reception on S8 coding.

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-20 12:29:52 -05:00
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 9fd502f956 Bluetooth: controller: Use PPI indices 14/15 for PA/LNA
PA/LNA feature being not default enabled, keeping the PPI
indices used for this feature at the higher indices would
allow use of these PPI indices by other drivers, for
instance the nRF5 software PWM driver.

Software PWM driver provides 3 PWM pins/channels using upto
6 PPI channels. If BLE controler where to use 0-13, then
14-19 PPI indices can be used by the PWM driver.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 18:46:20 -05:00
Vinayak Kariappa Chettimada f44efd12fa Bluetooth: controller: Replace void * with memq_link_t
Replace use if void * declaration related to memq links with
more readable memq_link_t.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 15:28:49 +01:00
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
Vinayak Kariappa Chettimada 9746b2a75d Bluetooth: controller: Fix memq_dequeue function
When testing memq implementation used by controller, a
missing check on NULL pointer return could lead to NULL
pointer deferencing.

Current implementation of controller and mayfly do not
by design lead to NULL pointer dereferencing, this fix
is only for correct-ness and complete-ness.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-20 10:42:53 +02:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Vinayak Kariappa Chettimada 6016ccffe8 Bluetooth: controller: Fix diff proc collision with enc proc
Fixes the following conformance test regression failure
introduced in commit 7dd5fbee26 ("Bluetooth: controller:
Fix MIC error due to parallel Enc Proc")

TP/CON/MAS/BV-28-C [Initiating Connection Parameter Request
different procedure collision encryption]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-02 10:26:09 +01:00
Vinayak Kariappa Chettimada 7dd5fbee26 Bluetooth: controller: Fix MIC error due to parallel Enc Proc
Fix to disallow initiating LE Start Encryption while another
procedure is in progress. Similarly, disallow initiating
another procedure while Encryption procedure is in progress.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-01 16:35:29 +01:00
Vinayak Kariappa Chettimada 8edcbade9a Bluetooth: controller: Fix to enable Asym PHY on nRF52 Series
Fix the controller Kconfig to enable use of fast radio ramp
up by default, hence enabling support for Asym PHY updates
by default on nRF52 Series SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-30 14:51:18 +01:00
Vinayak Kariappa Chettimada 0328ecf6fc Bluetooth: controller: Fix Ctrl PDU Tx starvation assert
Replace all controller asserts in control procedure responses
that checked for buffer availability with an implementation
that nacks request PDUs if there are no buffer to prepare
response PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-25 16:16:47 +02:00
Vinayak Kariappa Chettimada 482771c497 Bluetooth: controller: Remove assert on invalid LL id
Remove an assert on receiving invalid LL id, drop these
invalid PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-25 14:54:17 +02:00
Carles Cufi 493852bac3 Bluetooth: controller: Fix flow control packet drop
The main purpose of recv_thread is to process incoming events from the
radio and also any buffered items waiting to be dispatched to the Host
and that are pending because of lack of Host buffers.
When an iteration of the recv_thread obtains a element from the radio it
needs to process it immediately, either sending it straight away to the
Host or appending it to the queue. This was not the case before this
patch, where the concurrency of a buffered packet with one coming from
the radio would cause the latter to be "dropped", causing missing
packets.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-18 14:43:39 +02:00
Carles Cufi 5c49afc9ec Bluetooth: controller: Fix Controller to Host flow control leak
When a connection is disconnected with outstanding unacked packets, the
Host has no way to signal or acknowledge their processing to the
Controller, since it is illegal to send a Host Number of Completed
Packets command when the connection is not up. Instead, consider the
outstanding packets as acked in order not to affect the correct flow
control.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-17 13:10:08 +02:00
Vinayak Kariappa Chettimada 52bc2b6cd1 Bluetooth: controller: Add Coded PHY packet tx time restrictions
Add implementation to support Coded PHY update procedure
with packet transmit time restrictions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:47:47 +02:00
Vinayak Kariappa Chettimada 77eb73b505 Bluetooth: controller: Add encrypted Coded PHY support
Add support for encrypted Coded PHY connections on nRF52840
SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:45:02 +02:00
Vinayak Kariappa Chettimada 559c0248d5 Bluetooth: controller: Fix PA/LNA for Coded PHY
Use S8 coding Rx chain delay timings to calculate the PA
pin assertions when in Coded PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:43:45 +02:00
Vinayak Kariappa Chettimada f5d744b998 Bluetooth: controller: Fix tIFS calc for Coded PHY
Always use S8 Rx Chain Delay instead of the actual Rx-ed
packet coding. I believe, as the packet always start with
S8, hence S8 timings when used the tIFS is near correct
value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:43:45 +02:00
Vinayak Kariappa Chettimada 3ab134de9e Bluetooth: controller: Fix Coded PHY supervision timeout
When calculating and setting up the header compelte timeout
use S8 coding Rx chain delay.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:43:45 +02:00
Vinayak Kariappa Chettimada 6a8f22eeab Bluetooth: controller: Fix connection update supervision timeout
In the commit dd52b8ea02 ("Bluetooth: controller: Fix
first connection interval timing"), instead of using just a
tick unit as workaround, microseconds corresponding to a
tick unit was used while calculating the window offset to be
used at the connection update instant. This introduced an
error in scheduling the first event with new connection
parameters, causing supervision timeout of connection update
procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-14 12:20:45 +02:00
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 7cc796771b Bluetooth: controller: Fix NRF_AAR use
Fixed the usage of NRF_AAR peripheral for controller privacy
to clear events on configure and on every radio ISR entry.

Without this fix, there was spurious AAR matches leading to
controller asserts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-11 22:21:10 +02:00
Vinayak Kariappa Chettimada e454862600 Bluetooth: controller: Fix PHY Update response state transition
PHY Update procedure timeout was started without transition
to the state that waits for the procedure to complete. This
prevented the timeout from being reset on successful
completion of the procedure and eventually leading to a
connection termination with reason LMP Response Timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-11 14:07:33 +02:00
Vinayak Kariappa Chettimada f64cccfea9 Bluetooth: controller: Fix CPR procedure's Conn Upd initiation
Fix Connection Parameter Request Procedure's Connection
Update Procedure initiation to calculate the offset rather
than selecting offsets from an out-of-bound memory area.

The symptoms of the bug was noticed as a supervision timeout
due to use of incorrect offset communicated to peer and a
wrong offset used in scheduling the connection events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-11 09:57:36 +02:00
Vinayak Kariappa Chettimada 8ab1a1112b Bluetooth: controller: Fix Conn Param Req response timeout
When the peer slave rejects a Connection Parameter Request
Procedure, the controller proceeds to perform a Connection
Update Procedure without clearing the procedure timer that
causes the connection to terminate eventually. This is
fixed by clearing the procedure timeout when the Connection
Update Procedure completes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-10 10:10:23 -04:00
Vinayak Kariappa Chettimada c707c82fc8 Bluetooth: controller: Fix slave from initiating conn upd ind
If a peer master role has support for Connection Parameter
Request Procedure set in its supported features but would
send an Extended Reject Ind as response to the procedure
then the controller incorrectly initiated a Connection
Update Procedure which is not permitted in a slave role.

This would lead to connection timeout after the used instant
in the invalid Connection Update Procedure.

This is fixed by initiating a Connection Update Procedure
only if in a master role.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-10 10:09:49 -04:00
Carles Cufi e0c1c0aa64 Bluetooth: controller: Common config for VS extensions
Since the Zephyr HCI VS extensions apply to both the Host (using them
for additional functionality) and the Controller (implement the commands
and events), it make sense to make this a common setting in order for it
to be configurable in a way that applies to both.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-03 17:57:49 +03:00
Carles Cufi 09330fa7b0 Bluetooth: controller: Disable PA/LNA for nRF51x
The PA/LNA feature is not functional on nRF51x series due to added
interrupt latency. Disable this feature unconditionally for those ICs to
avoid unexpected behavior.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-02 12:04:43 +02:00
Vinayak Kariappa Chettimada e95fd2860d Bluetooth: controller: Fix HCI Reset hang
Issuing HCI reset command while having connections sometimes
hung the controller.

ll_reset supplied invalid stop ticker id to role_disable
when trying to stop all connections. Connection role does
not utilize stop ticker. The invalid ticker id supplied
referenced memory outside the pool of tickers and based on
what the content is in RAM there, the controller would hang
trying to stop connections.

Fixed by not calling the ticker_stop interface with invalid
ticker ids.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 15:47:36 +02:00
Vinayak Kariappa Chettimada b97b9c4fef Bluetooth: controller: GPIO PA/LNA feature
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 15:38:31 +02:00
Carles Cufi 6cfac15c68 Bluetooth: controller: Add PA/LNA GPIO Kconfig option
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 15:38:31 +02:00
Carles Cufi 3b2120f500 Bluetooth: controller: Implement Read Build Info cmd
Implement the Read Build Information VS command. This returns a UTF-8
encoded string, which is extendable by the user via a new Kconfig
option.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-28 15:41:49 +02:00
Carles Cufi 573c1c9071 Bluetooth: controller: Implement Write BD_ADDR VS cmd
Implement the Zephyr VS command that allows a Host to write a public
Bluetooth Address to the Controller in order to allow Hosts to provide
their own public Bluetooth addresses.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-28 15:41:49 +02:00
Vinayak Kariappa Chettimada f0274c9e52 Bluetooth: controller: Move tIFS s/w switch PPI index up by one
Move the use of tIFS software switching PPI index set up by
one position to make place for use of PA/LNA implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 16:14:43 +02:00
Vinayak Kariappa Chettimada 74cd8d852e Bluetooth: controller: Use single PPI channel for AA capture
Earlier design captured AA twice in the first Rx in a slave
connection event and retained one of the capture until end
of event to calculate drift.

Design updated to use single capture of AA and save the
first AA capture in a slave connection event in RAM instead.

This frees up a PPI channel in the controller design.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 16:14:27 +02:00
Vinayak Kariappa Chettimada 3cd37866cc Bluetooth: controller: Internal document purpose of end capture
Document internal the purposes of various Tx/Rx PDU end
capture setup.

Also, removed any redundant capture of packet end.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 15:18:37 +02:00
Vinayak Kariappa Chettimada 4cb7b949dc Bluetooth: controller: Minor refactor radio_tmr_start
Minor refactor of radio_tmr_start to reduced duplicate
assignments common in if-then-else control path.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 15:18:07 +02:00
Vinayak Kariappa Chettimada 492d9d9a06 Bluetooth: controller: Map debug pins to P3 pin head on nRF5x DK
Updated debug pin mapping so that the outputs are on P3 pin
head on all nRF5x Development Kits.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:25:55 +02:00
Vinayak Kariappa Chettimada 4d3a07b8be Bluetooth: controller: Add radio setup HAL interface
Added a new interface to perform setup of radio hardware.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada a952d47a31 Bluetooth: controller: Fix NRF_CCM config for 2M PHY
Fixed the configuration of NRF_CCM for 2M PHY connections.
Now faster 2M data rate mode will be used when a connection
is in 2M PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada ea431f5fce Bluetooth: controller: Use correct NRF_AAR enable define
Use correct NRF_AAR enable macro defines from Nordic MDK.
Old code funtionally worked fine even though not setting
the correct enable value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada 247488c038 Bluetooth: controller: Remove unreachable workaround code
A workaround code for nRF52840 under nRF51 conditional
compilation is removed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada 20c4db8197 Bluetooth: controller: Fix conn param req procedure timeout
Fixed a bug in the implementation of Connection Parameter
Request Procedure when initiated in master role caused the
connection to terminate with reason LL response timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:15 +02:00
Carles Cufi d627ae4802 Bluetooth: controller: Fix handling of Read Static Addrs cmd
The status in the Command Complete event was uninitialized, leading to
incorrect contents of the event parsed by the Host. Correctly initialize
the status to success.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-14 17:15:23 +02:00
Vinayak Kariappa Chettimada e17e495af8 Bluetooth: controller: Fix hang on directed adv timeout
During testing it was discovered that directed advertising
timeout is missing implementation to handle the timeout
happening while next event is already in preparation.
The consequence was that after the event ticker expired,
the counter is shutdown, stalling the setup PPI from
starting the erroneous advertising, leaving the controller
in an invalid hung state.

This has been fixed by correctly handling the cases, stop
between prepare and event, and stop inside radio advertising
event. The fix takes care of putting the radio active
callback and HF clock in the correct states.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-13 18:03:14 +03:00
Carles Cufi b77b8e615b Bluetooth: controller: Issue Data Buffer Overflow event
Whenever the HCI ACL flow control is violated by the Host, a Data Buffer
Overflow event is now issued by the Controller (if enabled) to notify
the Host of the buffer overrun.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-13 14:17:32 +02:00
Vinayak Kariappa Chettimada 29e9d14420 Bluetooth: controller: Add checks to detect radio ISR latency
Added missing asserts to catch high CPU use in radio ISR and
latencies, without which if radio packet pointer is not set
correctly, would cause spurious transmissions and invalid
behavior.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada 934d512223 Bluetooth: controller: Optimize the loop in nRF5 hal rand get()
Optimised the get() function in nRF5 hal rand implementation
to reduce number of probable branching operations.

This is needed to reduce nRF51 platform's CPU use in radio
ISR when using the fast encryption setup implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada 5164d4b189 Bluetooth: controller: Move RSSI sampling after pkt processing
Move the code to acquire the RSSI sample after critical
control path that processes PDUs.

This is needed to reduce the time taken to assign the next
packet ptr inside radio ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada 2cc2be707a Bluetooth: controller: Inline the packet_rx_reserve_get() func
Simplify and inline the packet_rx_reserve_get() functions
used inside radio ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada ed3aa170f3 Bluetooth: controller: Remove redundant use of auto variable
Removed use of a redundant auto variable that was assigned
and referenced only once.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada 09368217d4 Bluetooth: controller: Fast enc setup with ccflags -Ofast
To meet CPU time usage restricts inside radio ISR on nRF51
SoCs, use ccflags -Ofast when using fast encryption setup
implementation in the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada 9182de5f0b Bluetooth: controller: Disable DLE and PHY upd proc for nRF51
Default to n the support for Data Length Update and
PHY update procedures on nRF51 SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
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
Carles Cufi 93ca60b733 Bluetooth: controller: Require nRF52 for privacy
Privacy on nRF51 is not passing the conformance and qualification tests
due to the time it takes to execute the privacy code while in ISR. Until
we come up with a way of optimizing and/or deferring the work, do not
allow privacy on nRF51 targets.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-05 07:55:05 -04:00
Carles Cufi 3df18ff277 Bluetooth: controller: Fix Read Version Info VS cmd
Use the macros generated during the build and located in version.h to
fill in the version information in the Read Version Information VS
command. Additionally reply with the correct hardware identifiers when
running on Nordic hardware.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-04 14:46:13 -04:00
Carles Cufi 80e0f7939e Bluetooth: controller: Add DTM HCI commands
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-04 06:08:09 -04:00
Vinayak Kariappa Chettimada 37c7551120 Bluetooth: controller: Add Direct Test Mode support
Added controller implementation to support Direct Test Mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-04 06:08:09 -04:00
Carles Cufi b276eeabc7 Bluetooth: controller: Fix Coverity unreachable code
CID: 175182

Use #else to avoid Coverity warning about unreachable code.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-04 06:06:29 -04:00
Vinayak Kariappa Chettimada 4225b7985e Bluetooth: controller: Fix pointless expression
Seems due to incorrect rebase in commit 07270e52ba
("Bluetooth: controller: Coding style and refactoring"),
commit 95d55a2bfc ("Bluetooth: controller: Do not skip
one-shot tickers with slot"), and
commit 4ba2bb0d1c ("Bluetooth: controller: Be fair when
pre-empting a ticker"), a pointless expression was
introduced, fixed it.

Coverity-CID: 171563

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-02 04:53:30 -04:00
Vinayak Kariappa Chettimada 38b148023e Bluetooth: controller: Fix assert on connection establishment
Fixes an assert during connection establishment when the
initiator overflows the initiator window in time while
sending the CONNECT_IND PDU. The actual window is one low
frequency tick less, hence corrected the check that permits
the transmission of CONNECT_IND PDU inside the initiator
window.

Symptom was, stopping of the scanner's ticker succeeds on
connection establishment, but next interval prepare was
already run when continuous scanning was used, breaking the
design, hence there was an assert.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-31 14:31:55 -04:00
Carles Cufi 2874841576 Bluetooth: Controller: Add Read Key Hier. Roots VS cmd
Implement the Zephyr Read Key Hierarchy Roots command, returning the IR
and ER present in nRF5x ICs when compiling for those.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-30 08:18:42 -04:00
Carles Cufi b7a5fab4cf Bluetooth: controller: Add Read Static Addresses VS command
Implement the first Vendor-Specific Command of the Zephyr specification
other than the 3 mandatory ones already present in the codebase, along
with a Kconfig option to enable and disable the presence of the VS
commands.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-30 08:18:42 -04:00
Carles Cufi 7924d16aef Bluetooth: controller: Fix broken switch statement
Add a missing break that was forgotten when we introduced the Read TX
Power command.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 16:25:11 +02:00
Luiz Augusto von Dentz 7d01c5ecb7 poll: Enable multiple threads to use k_poll in the same object
This is necessary in order for k_queue_get to work properly since that
is used with buffer pools which might be used by multiple threads asking
for buffers.

Jira: ZEP-2553

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-08-25 09:00:46 -04:00
Vinayak Chettimada 2b2eb9bb07 Bluetooth: controller: Refactor Conn Param Req implementation
Refactor the Connection Parameter Request Procedure to be
separate from and not overlap the variables of the
Connection Update Procedure.

Also, added missing implementations to pass all Connection
Parameter Request Procedure related Conformance Tests.

Jira: ZEP-1918

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-25 12:51:01 +02:00
Carles Cufi f597c8120e Bluetooth: controller: Add LE Read Chan Map command
Implement the LE Read Channel Map HCI command, along with making the
reading of the multi-byte channel map value from the connection pointer
thread-safe in case the ISR triggers while we are reading the value.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 11:27:22 +02:00
Carles Cufi a5fcafa155 Bluetooth: controller: Add Read TX Power commands
Although the current BLE controller only supports a single TX power (0
dBm), the qualification tests require the 2 Read TX Power to be
present and supported in the controller, so implement them while
returning always 0 dBm.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 11:27:22 +02:00
Carles Cufi 7bfa0ef47b Bluetooth: controller: Implement Read RSSI command
When the CONFIG_BT_CTLR_CONN_RSSI option is set, the connection RSSI is
available in the controller, and can be reported to the Host via the
Read RSSI command. Implement the command, which is required for
qualification.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 11:27:22 +02:00
Carles Cufi 94bab6ca8c Bluetooth: controller: Fix Read Peer RPA Command
There are 2 possible interpretations regarding the address to return in
response to the Read Peer RPA HCI Command:

1) The RPA that the local controller generates to be used in certain
packets it sends
2) The RPA generated and used by the peer device in its packets

We used to return 1) but our interpretation turned out to be incorrect
when reading the HCI test specification, so this commit switches to
returning 2).

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-22 15:22:25 +02:00