Commit graph

1155 commits

Author SHA1 Message Date
Carles Cufi bd31ad11de Bluetooth: controller: Add RL filter
In order for privacy to work correctly with and without peer IRKs, an
additional hardware filter is required to help match the peer device in
the case address resolution is not possible for a peer since the Host
has not provided a peer IRK for it.

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi 7df0ab780d Bluetooth: controller: Fix supported cmds and states
Properly use the role and feature Kconfig variables to populate both the
supported commands and the supported states in the controller.

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

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

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

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

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

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-06-22 13:47:28 -04:00
Kumar Gala 7572203f54 Bluetooth: Fix use of uint32_t in nRF5 radio timings abstractions
We have conflicting types between the decleration and implementation of
several radio functions.  We should be using u32_t everywhere.  This
shows up when we try and build with newlib enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-06-22 12:19:01 -05:00
Vinayak Kariappa Chettimada 46f9489704 Bluetooth: controller: Add radio fast ramp feature
Added implementation to use nRF radio's fast ramp up mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-22 18:48:15 +03:00
Vinayak Kariappa Chettimada cd1fd05778 Bluetooth: controller: nRF5 radio timings abstractions
Added HAL Radio abstractions to use SoC specific Radio Timings
as documented in SoC's electrical characteristics.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-22 18:48:15 +03:00
Carles Cufi 851b214af0 Bluetooth: controller: Fix OCF data size
An OCF is a 10-bit value as defined by HCI, and therefore requires a
16-bit integer to store it.

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

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

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

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

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

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

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

Follow-up commits will expand the functionality.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 15:20:09 +03:00
Carles Cufi 4307505e2d Bluetooth: controller: Rename mem function that checks all-zero mem
For consistency with the return value and to conform with other naming
schemes, rename mem_is_zero() to mem_nz().

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 15:20:09 +03:00
Vinayak Kariappa Chettimada f4242b0723 Bluetooth: controller: Use find_lsb_set instead of custom ffs
Use globally available find_lsb_set in Zephyr instead of a
custom find first set function.

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

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

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

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

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

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

Jira: ZEP-2238

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

Jira: ZEP-2238

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

Jira: ZEP-2073

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 18:40:40 +03:00
Carles Cufi 3b703288ae Bluetooth: controller: Handle reset atomic properly
In order to reuse code, the reset() function is used both to handle the
reset HCI command but also to initialize the internal HCI variables when
bringing up the system. In the latter case, avoid setting the reset bit
in the state atomic and signalling the polling API, since that is not
required during initialization.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-13 12:23:58 -04:00
Carles Cufi d0832f92fd Bluetooth: controller: Refactor whitelisting
As a preparation for advanced filtering (Controller-based privacy) this
commit refactors whitelisting so that it becomes its own module and
actually correctly performs state tracking to avoid modifying the
whitelist when it's in use.

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

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

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

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

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

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
David B. Kinder 9faa5f2033 doc: spelling fixes in Kconfig files
regular spelling check on Kconfig.* files

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-06-12 19:40:51 -04:00
Andrew Boie 567c6c7683 misc: use K_THREAD_STACK_DEFINE macros
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-06-09 18:53:28 -04:00
Vinayak Kariappa Chettimada d055252ea9 Bluetooth: controller: Restrict enc to 1M 27 bytes PDU on nRF51
Restrict encryption support on nRF51 series SoC to Bluetooth
LE 1M PHY and max. 27 bytes PDU. If 251 bytes PDU using Data
Length Update procedure is desired, then LE Encryption
procedure will not be supported (until a software CCM is
implemented in future).

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-09 10:33:06 +02:00
Vinayak Kariappa Chettimada 5d91b2ffe9 Bluetooth: controller: Explicitly compare radio event registers
While returning 32-bit values from radio status interfaces,
explicitly compare radio h/w event registers to be non-zero,
dont just return the direct 32-bit h/w register content.

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

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

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

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-29 17:08:52 +03:00
Carles Cufi 3e3a47dfef Bluetooth: controller: Conditionally include conn-related options
Only include connection-related options when CONFIG_BLUETOOTH_CONN is
selected, since otherwise this can lead to inconsistencies between
features and supported commands.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-29 17:08:52 +03:00
Carles Cufi d6513eeda3 Bluetooth: controller: Increase RX prio stack size
Due to several changes in the way stacks are calculated, 320 bytes is no
longer enough for the controller-only build. After measuring usages of
up to 320 bytes (locally) and 376 (reported by Ricardo Salveti), the
stack size is increased by 128 bytes, up to 448 bytes.

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-24 11:16:41 -07:00
Vinayak Kariappa Chettimada dac861be99 Bluetooth: controller: Add HCI Tx buffer overflow return code
Return error codes for HCI Tx buffer overflow conditions are
missing which would lead to silent dropping of Tx packets if
host implementations do not follow number of completed packets
or use correct buffer counts as returned by HCI Read Buffer
Size command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-24 11:15:47 -07:00
Vinayak Kariappa Chettimada e858f8db05 Bluetooth: controller: Increase Rx & Tx buf cnt range in Kconfig
With the support for 2M PHY added, the controller can now Rx/Tx
upto 18/19 minimum sized L2CAP packets per 7.5ms connection
intervals.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-16 15:30:51 +03:00
Carles Cufi ef2aecefda Bluetooth: Move hci_uart UART Kconfig to the top-level file
To allow for hci_uart builds that do not include the controller code,
move the UART Kconfig option used by the sample up one level so that it
is shared by all configurations using Bluetooth:

Jira: ZEP-2132

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-12 15:26:41 +03:00
Vinayak Kariappa Chettimada 3e0f72d7cc Bluetooth: controller: Fix missing PHY update cond. compilation
Added a missing conditional compilation #if-#endif that caused
compilation error when PHY update feature was deselected.

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-12 12:56:14 +03:00
Andrew Boie 899cf94dbd bluetooth: use k_thread_create()
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
Vinayak Kariappa Chettimada 0187280aa8 Bluetooth: controller: Revert cleanup redundant ticker busy loop
This reverts commit 698de88916 ("Bluetooth: controller:
Cleanup redundant ticker busy loop")

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

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

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

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

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

Change-Id: I57c0e3790d988f0de17993cebe5c5c2ab0fc07a6
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-05-10 23:03:11 +03:00
Carles Cufi ff2a85a587 Bluetooth: controller: Add flow control logging
When Controller to Host flow control is enabled, output informational
messages for certain operations to help tune and debug the feature.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-10 08:23:25 +03:00
Vinayak Chettimada c3adc7b0c7 Bluetooth: controller: PHY Update Procedure
Added support for Bluetooth v5.0 PHY Update Procedure in the
Controller.

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

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

Jira: ZEP-2086

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

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

Jira: ZEP-2073

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 15:56:04 +03:00
Vinayak Kariappa Chettimada a9a72f7bea Bluetooth: controller: Remove unreferenced hci_evt_is_discardable
Remove unreferenced function hci_evt_is_discardable after
introduction of hci_get_class function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 15:56:04 +03:00
Vinayak Chettimada b031d76655 Bluetooth: controller: Cond. compile connection state HCI cmds
Conditionally compile connection state related HCI commands.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Vinayak Chettimada c30ba00fbc Bluetooth: controller: Conditionally compile slave role HCI cmds
Conditionally compile slave role related HCI commands.

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Vinayak Chettimada d9d3f8e7c7 Bluetooth: controller: Add Kconfig options for states and roles
In preparation for refactoring the Controller implementation
into seperate state and role based source files, add Kconfig
options for states and roles in the Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Carles Cufi cff44ea3f6 Bluetooth: controller: Use sys_le16_to_cpu on all commands
To guarantee code that is endianness-independent, the sys_le* macros
must be used everywhere when accessing multi-byte values from the
command parameters.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-05 12:54:52 +03:00
Carles Cufi 47dedfc992 Bluetooth: controller: Fix overwriting of command parameters
In HCI, the response buffer to a command is the same as the one for the
command itself, requiring command parameters to be processed before the
response is formed on the same memory area.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-05 12:54:52 +03:00
Carles Cufi a1ff1a0933 Bluetooth: Consolidate flow control Kconfig
Since Controller to Host flow control is a feature that affects both
sides equally, move it to the top-level Kconfig file and consolidate its
use in both Controller and Host.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-04 18:09:31 +03:00
Johan Hedberg 70e09b11ea Bluetooth: Introduce buffer type parameter to bt_buf_get_rx
This is preparation for re-introducing host flow control.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-04 16:38:34 +03:00
Carles Cufi ccd4d4f401 Bluetooth: controller: Controller to Host Flow Control bits
Enable the bits corresponding to the new 3 commands supported when
enabling Controller to Host Flow Control, in order for the Host to be
able to enable the feature.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-04 15:23:46 +03:00
Carles Cufi 689bd232f8 Bluetooth: Reshuffle Kconfig options
In order to achieve proper sharing of configuration options, everything
that is common to both the Host and the Controller should now be placed
in the top-level Kconfig file, and Controller-only options are in the
controller/ Kconfig one.

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

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

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

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

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

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

Jira: ZEP-1735

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

Change-id: I22cb0135d2223f679c4d9321f4724f8b7de0aede
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 3666fb81f5 Bluetooth: hci: Consistently use bt_hci_evt_*
Rename occurences of bt_hci_ev_* to more widely used
bt_hci_evt_* namespace.

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

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

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

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

Change-Id: I1448b159ab1afe50ff88b7a6bd1b254c44858d4c
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-29 11:39:13 -04:00
David B. Kinder 61de8f892b spell: Kconfig help typos: /kernel /misc /subsys
Fix misspellings in Kconfig help text

Change-Id: I6eda081c7b6f38287ace8c0a741e65df92d6817b
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-22 01:04:56 +00:00
Kumar Gala d0eb235510 Bluetooth: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

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

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

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

Jira: ZEP-2051

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

Jira: ZEP-2033

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

Change-id: I9ae15d6d90fa7a3de186905d3c68088ee22d2911
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Carles Cufi 045f076e5e Bluetooth: Use event masks instead of bits in controller and host
To avoid having to define a BIT64() macro in a public namespace, use
instead masks directly instead of bits, and also refactor the host code
so that it uses those instead of the earlier byte array with hardcoded
indices and masks.

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

Change-id: I196ffea79e7e10b0253363949051fdf82be62cb4
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Carles Cufi 8f9776073f Bluetooth: HCI: Naming consistency tweaks
For consistency, "chan" and "param" are used wherever "channel" and
"parameters" are the words in the specification.

Change-Id: I778a8501ae6af991618c14cc6e395d765a9ae102
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-20 08:58:09 +03:00
David B. Kinder 0ffb648210 spell: fix doxygen comment typos: /subsys
Fix doxygen comment typos used to generate API docs

Change-Id: I3efff6f5fa26f87d1e658d6336fef01ce45f5bb0
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-19 18:44:06 +00:00
Vinayak Chettimada 7a10c35f6b Bluetooth: controller: Use defined keyword in #if cond compiles
Use #if defined(...) constructs while using conditional
compilations of advanced event preparation and advanced
scheduling implementations.

Change-id: I728c76d0e7dbbfa378e8978b726ec404d9e55a72
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-10 09:08:41 +00:00
Vinayak Chettimada 83b7d1b8b7 Bluetooth: controller: Group dup filter Kconfig with buf options
Move the scan duplicate filter length option and group it along
with rx/tx buffer size Kconfig options.

Change-id: I3df07e667029c7d2571270db442ecb7241a417c2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-10 09:08:34 +00:00
Carles Cufi 923c470f5d Bluetooth: controller: Fix warning with no dup filter
Conditionally declare the iterator variable to avoid a warning when
compiling the controller without any duplicate filter entries.

Change-Id: I69e23d4c594db18172dc57d45e7925243fe2da69
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-08 20:11:55 +03:00
Vinayak Chettimada 1a62acd00e Bluetooth: controller: Add BT 5.0 PDU structs
Add struct definitions for BT 5.0 PDUs, LL_PHY_REQ,
LL_PHY_RSP, LL_PHY_UPDATE_IND, and LL_MIN_USED_CHANNELS_IND.

Change-id: Ib54209cdf381ba53217eb425696c24d797fe0a30
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Carles Cufi 9a9699ebdb Bluetooth: controller: Implement event masks
HCI event masking allows the host to choose which events are reported to
it to avoid interruption and excessive traffic. This patch implements
masking to drop any non-enabled events as specified by the host.

Jira: ZEP-1769

Change-Id: If09d4aa22b0da8f743fc42a3b0db3f369daaff96
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Carles Cufi 27e83660ff Bluetooth: controller: Implement scan duplicate filter
Implement the controller's ability to drop duplicate advertising reports
when instructed by the Host.

Jira: ZEP-1246

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

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

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

Change-id: I85bb9ae3ab7ff9fcce18c886cfa3e33c91ebb670
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 2de3cc95be Bluetooth: controller: Move nRF5 specific debug pins to hal/nrf5
Move the nRF5 specific GPIO debug pin macro definitions to
hal/nrf5/debug.h.

The Controller's hal folder contains prototypes and
hal/<soc> shall contain SoC specific implementation to
realize a software-based Link Layer.

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

Change-id: I053ad75a4328c51cfe651b820a2fa961e42ae48f
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada ddba873aae Bluetooth: Kconfig: Move BLUETOOTH_CONTROLLER to Controller file
Move the Kconfig BLUETOOTH_CONTROLLER switch from top-level
Bluetooth Kconfig to Bluetooth Controller Kconfig.

Change-id: Iead760c22a0fbbda11e4558c4943b3366ecc8769
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Johan Hedberg dd1ba28726 Bluetooth: Controller: Introduce rate-limiting on stack analysis
In case the controller is receiving PDUs very rapidly, prevent it from
spamming the logs by limiting its stack analysis to at most once every
5 seconds.

Change-Id: I31c70d28e8af62b27172a4a77bf6e614ea3e20eb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada b593e44da6 Bluetooth: controller: Move comp id and subver to configuration
Move company id and subversion number Kconfig to the
Controller configuration section from the features section.

Change-id: Ic4deb8b24d84d9b1817ba542705eebd612f0e020
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 16bd3d48db Bluetooth: controller: Hide advance features in Kconfig
Added a explicit Kconfig option to show the Controller's
advanced feature configurations. These feature
configurations need specific in-depth Controller
implementation knowledge and should not overwhelm normal
users of the Controller.

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

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

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

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

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

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

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

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

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

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

Jira: ZEP-1941

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

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

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

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

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

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

Change-id: Idf9d7cdf7c60d74816ef2b093c4ae457df16e9a9
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:43 -07:00
Johan Hedberg 24c7397160 Bluetooth: Controller: Increase default TX buffer count
Only 1 TX buffer is sub-optimal for performance since the controller
would always have to wait for the host TX thread to give it another
buffer. Increase the value to 2 so the controller can keep
transmitting data without waiting for the host.

Change-Id: I4841a6c5010f294996d6fe0fe63260b848a6a437
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada f1aabd8ba2 Bluetooth: controller: Replace 0 for pointers with NULL keyword
Updated controller code to use NULL keyword instead of
using 0 for pointers.

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

Change-Id: Ia7b3e01bb0a07c4560b23f60c2f615ec614eb431
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Johan Hedberg 6cb853fc04 Bluetooth: Controller: Introduce big-endian variant for ECB
There are some use cases where all parameters are in big-endian. To
avoid excessive byte order reversals introduce a native big-endian
API.

Change-Id: I58fe9156c8819a3a43d715e70b6ba358bd2f844b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Johan Hedberg 579551ed06 Bluetooth: Controller: Factor out ECB core code from ecb_encrypt()
Do this in preparation of a purely big-endian API (all three
parameters as big-endian).

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

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

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

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

Change-Id: I1b54d655568a4ec02409da2f1a0addb4d64beed0
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Carles Cufi 8dd0374214 Bluetooth: controller: Remove public address config option
Since this presents a risk of public Bluetooth address duplication in
the wild by compiling once with a particular address and then flashing
the same image to multiple devices, a decision has been taken to remove
that config option and replace it later with another mechanism.

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

Change-Id: I2b0ab0d11b47b9c35a5759bcc30f347e6c616648
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Johan Hedberg 5517893543 Bluetooth: Make bt_hci_driver instances link-time constants
Declaring these as const lets the linker generate more optimal code.
Some extra care is needed with hci_ecc.c since it was overwriting the
send callback. Now the choice of send() call is done directly in the
bt_send() function

Change-Id: Iac74f5ee9bee097bbb34c11bd13d1d886700f5cc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Carles Cufi 841c5432cc Bluetooth: controller: Introduce BLUETOOTH_LL_SW
In preparation for future hardware implementations of the BLE
Link Layer, this patch introduces the BLUETOOTH_LL_SW
configuration option to specify that the default software
LL is to be built.

Change-Id: I8b9d5b5e0d2926d18f9e8c8f042a74326895bf95
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Carles Cufi be060208e9 Bluetooth: controller: Rename downstream API calls
Rename all LL downstream API calls from radio_ to ll_ so that they
reflect the layer they are actually targeting. Additionally they have
been moved to ll.h so as to expose a proper interface.

Change-Id: I4fb3946597920c9fafaacb6d87d34d83d75e8f27
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Carles Cufi 7e0a900e05 Bluetooth: controller: Remove unused H:4 tag macros
Remove the H:4 packet type macros that were unused in this file.

Change-Id: If161ddbf2d3adb2871cadd76de0e6c3bb50a16db
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada e3d00bf338 Bluetooth: Controller: Version 5.0 and PDU type rename
Report as Bluetooth 5.0 compliant controller as there are
no mandatory features.

Rename PDU types as per the changes in Bluetooth 5.0
Specification.

Change-id: I1363e054eafd37c2bdca0f69b2638c7edb785787
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada 00d8a902b7 Bluetooth: Controller: Add Kconfig range check for public address
Bluetooth device address is 48-bit, added Kconfig range
field to restrict input to 48-bit hexadecimal value.

Change-id: I650343eab5809535137e164e783c9dd4f3e2a6f2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Matthias Ringwald 34b6c53c46 Bluetooth: Controller: Kconfig company id and subversion number
Add Kconfig option to set the Controller's company id and
subversion number.

Change-id: I3508aba18bf0b79fd423c7b4142b6fc57eaf55d7
Signed-off-by: Matthias Ringwald <matthias@bluekitchen-gmbh.com>
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada 0d75faf02d Bluetooth: Controller: Add advertisement event indication feature
Add a Controller event that indicates everytime
advertisement event has been transmitted on air.

Change-id: I4722488bbfeca987e66983faf5b26467407a89c9
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada d8f28bc96a Bluetooth: Controller: Fix RSSI feature conditional compilation
Add ARG_UNUSED on rssi_ready local variable when the RSSI
feature is compiled out.

Change-id: I04f8f11cbc3530f7b85ffa72f27373e213b6e35e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada 16608e9a51 Bluetooth: Controller: mayfly enable to supercede over disable
If mayfly enable is called before mayfly could be disabled,
then enable shall supercede disabling, the mayfly will
remain enabled. Any new mayfly enqueued by the caller that
tried to disable mayfly will be chain for deferred
executon under this condition.

The BLE Controller's connection update procedure broke when
mayfly implementation was updated to defer disabling until
all queued mayfly where completed. Mayfly is disabled
between ticker_stop and ticker_start calls to chain them
so that ticker does not power off counter h/w if the ticker
being stopped is last one.

This commit fixes the connection update procedure which
used the mayfly enable before mayfly disable could
complete.

Jira: ZEP-1839

Change-id: I07d34c90d193b5eca9762acd8b7272e8d7a78474
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-08 15:14:32 +00:00
Vinayak Chettimada ecc0f83d92 Bluetooth: Controller: Fix assert on role stop/abort
Call to ticker_stop/update can fail under the condition
where in a role is being stopped but at the same time it is
preempted by the role event that also uses ticker_stop/
update.

Also if a role closes graceful while it is being stopped,
the radio ISR will process the stop state with no active
role at that instance in time. In this case just reset the
state to none, the role has already been gracefully closed
before this ISR execution. The above applies to aborting a
role event too.

This commit adds code to detect these conditions and
deterministically recover from it.

This commit fixes the assert observed while stopping
advertiser in the Bluetooth sample scan_adv.

Jira: ZEP-1852

Change-id: I51c8d6e212ef43e3526a199cf7b666a79729c732
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-08 15:14:22 +00:00
Vinayak Chettimada 8747090426 Bluetooth: Controller: Kconfig option to set public address
Added Kconfig option to be able set public address. Seems
conformance testers look for valid public address.

Change-Id: I2c4f702117f99a42c9eef0133b46556a1c6d1496
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 14:51:54 +01:00
Vinayak Chettimada 966fbbcd04 Bluetooth: Controller: Run all enqueued mayfly before disable
Controller asserted in preparation of a role event due to
the previous (same or another) role event preparation being
not complete.

Mayfly callee was disabled in the previous event due to the
preparation time being short and previous start running
(higher natural priority) before all previous preparation
mayfly completed. The previous start disabled mayfly to
avoid Radio ISR latencies.

The current role event that asserted, preempted the
previous role (observer role with continuous scanning
window) which runs until preemption to maximise the Radio
h/w use (observer scanning until next interval). The
previous preparation mayfly is still disabled when the
current role preparation tries to use same mayfly instance
which should be free for a new enqueue.

This commit updates mayfly implementation so that mayfly
callee is disabled only after all enqueued mayfly instances
are run to completion.

Jira: ZEP-1839

Change-id: I3e0d31422db8e47b819189110b11ebd07dd09a7c
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Carles Cufi ff3e6e333f Bluetooth: controller: Report 5.0 compliant controller
Since there are no mandatory features in 5.0 when compared to a 4.2
compliant controller, report 5.0 as the current specification
implemented by the controller, to allow for features such as short
advertising intervals (< 100ms) which are already supported.

Change-Id: I1b138a86290a0422760a5e265cdd7b72d68f0048
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Carles Cufi 3141dcf3b4 Bluetooth: controller: Introduce debug pins Kconfig option
A new Kconfig debug option now controls the usage of pin toggling to
debug the BLE controller.

Change-Id: I24c5c13ca71e3395e10f14e27ad4bca9f2e94687
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Carles Cufi 34e0c4b253 Bluetooth: controller: Set debug pins with macros
Use macros to identify the different debug pins used to monitor the
runtime behavior of the controller, for easier identification of the
lines.

Change-Id: Ia76d6298985b1d367b7ad193d8261f5403446371
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Vinayak Chettimada c78601481d Bluetooth: Controller: Fix LE Ping PDU dispatch
It was observed that due to possible CRC errors, one
connection interval was not sufficient by the peer to
respond to LE Ping PDU which caused the Controller to
generate the Authenticated Payload Timeout event to host.

This fix advanced the dispatch of LE Ping PDU by 6
connection intervals that the peer would listen to before
the 30s timeout.

Change-id: I6c292c623047a05b4e771e70093d87228db62cce
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Vinayak Chettimada 16ef73423e Bluetooth: Controller: Use direct ISR for Radio IRQ only
The new hard real-time (direct) interrupt support is used
only for Radio IRQ. Only Radio ISR has hard real-time
requirement of completing its execution inside the tIFS of
150us.

This commit reverts back RTC0 and SWI4 ISR to using the
normal IRQ_CONNECT.

Observed on nRF51, Radio ISR (open text, notifications):
Latencies: min. of 5us and max. of 10us.
CPU utilized: min. of 44us and max. of 77us.

Observed on nRF51, Radio ISR (LESC, fast encrypted,
notifications):
Latencies: min. of 5us and max. of 10us.
CPU utilized: min. of 39us and max. of 112us.

Jira: ZEP-1038

Change-id: Id3d09df7bdbdfea090f21f6f58aaded8c5f1e10d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Carles Cufi 727987276e Bluetooth: controller: Use direct ISRs
The new hard real-time (direct) interrupt support in the kernel allows
ISRs to be run directly with no significant latency overhead.

Use this new mechanism to improve the latency of the 3 critical
interrupts in the controller: radio, RTC0 and SWI4.

Jira: ZEP-1038

Change-Id: Ief9dacbea4c4c2e8a1c77893a0d6175a91819ffb
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Johan Hedberg 5b80603dbd Bluetooth: Controller: Use LL_ASSERT instead of BT_ASSERT
The controller code should not use BT_ASSERT directly.

Change-Id: If0b7d8e21d2ab4569a564bd03e36e4eb9204c595
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-07 12:29:58 +00:00
Johan Hedberg 50678b03cb Bluetooth: Reuse HCI command buffers for the command response
Reduce the pressure on the common RX buffer pool by reusing HCI
command buffers also for the Command Status or Command Complete
response to them. This also implies removing the existing Kconfig
variable for the command buffer sizes since the size is also dependent
on maximum Command Complete event sizes. Instead, reuse the RX buffer
size also for HCI Command buffers.

Change-Id: I006b287d64a0c9ca40de741aa9a424a49a927385
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 6c0e9720e2 Bluetooth: Controller: Redesign response buffer allocation for commands
With an upcoming patch the HCI command buffers will be reused for the
Command Complete/Status HCI events. The controller HCI code needs some
refactoring to postpone the event buffer allocation so that the
parsing state of the HCI command buffer isn't touched.

Change-Id: I1f614fb9f02ed1886ca84198fbc8c64abc29e44f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Kumar Gala 8d4c1787bf Bluetooth: Controller: Use CMSIS NVIC APIs directly
Convert driver to use the CMSIS NVIC APIs rather than the internal
ones so we can remove them in the future.

Change-Id: Ib9fe696e8d5e55f60865d3fd958a035135ce517a
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-23 15:15:55 -06:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Johan Hedberg 645f867444 Bluetooth: Take advantage of IS_ENABLED macro for BT_DBG
The new IS_ENABLED macro allows exposing conditionally enabled code
always to the compiler, even though it may not ultimately end up being
built. This is in particular useful for letting the compiler catch any
logging format string errors. Introduce a new BT_DBG_ENABLED macro
that c-files need to define before including <bluetooth/log.h> in
order to choose whether BT_DBG() logs are enabled or not.

When no Bluetooth logs are enabled the patch also modifies the log
macros to have the format strings checked with the help of the
__printf_like annotation and empty static inline functions.

Change-Id: Ie6bc8e10727b5b306f3ed0f94089a07a22583d9b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 08:28:06 +02:00
Johan Hedberg 815e15e3b2 Bluetooth: Controller: Rename hci_le_rand to bt_rand
Rename hci_le_rand to bt_rand and make its parameter types compatible.
This also includes updating rand_get() to use size_t instead of
uint32_t & uint8_t.

Change-Id: I4d434dfbbaf339b1bc7b451d358d07a291dd0375
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 4cd92c90c9 Bluetooth: Use the controller bt_rand() whenever possible
The controller bt_rand() ties into the hardware which uses less memory
and is more power-efficient than using the TinyCrypt PRNG.

Change-Id: I7570d18f3e84dae3d5c2d3322b5d37cd3e8f3b6b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Vinayak Chettimada 2d064eef89 Bluetooth: Controller: revert to event callback inside radio ISR
In order that host can continue a connection event by
enqueuing packets, the number of completed packets event
needs to be generated as soon it arrives on air. Hence, the
Controller now calls the radio_event_callback on every radio
Rx complete ISR.

The callback executes at the Radio ISR priority, take care
to only do as little as necessary in the callback, say, just
a semaphore give to wake up the hci_driver's thread.

Change-id: If48afd0f1390d450bc1e7ec66f1c9fd45208d9a4
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:17 +02:00
Carles Cufi e979d656cc bluetooth: controller: Split events into normal and priority
For the host to be able to block on the recv_thread while waiting for a
number of completed packets HCI event, those are pulled from the radio
in a new, higher priority thread that also schedules the execution of
the lower priority event/ACL data recv_thread.

Change-id: I9d356bd297d0504cb16a032fb5fe5530693546e2
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:17 +02:00
Johan Hedberg d64f47d956 Bluetooth: Create separate bt_recv_prio() API
Since callers of bt_recv() have so far anyway been required to know in
which context to call it (based on e.g. bt_hci_evt_is_prio) it's
cleaner to have two separate APIs: bt_recv and bt_recv_prio.

Change-Id: Icd0d9aed9c51ffd2def31432c4ffcc16a9f13ccd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 2f191012c2 Bluetooth: Controller: Deprioritize adv report buffer allocation
Advertising reports are the only HCI events which we can drop if we
are low on buffers. Allocate them therefore with K_NO_WAIT rather than
K_FOREVER.

Change-Id: I0b7c92647f9be54b8746da837037725f8161a452
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 88b620550c Bluetooth: Controller: Switch to controller-side RX thread
Since the controller already uses a thread for receiving data it makes
sense to enable the BLUETOOTH_RECV_IS_RX_THREAD option.

Change-Id: I927b20c1a0afaea8d000df28cc220a69ae817d59
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg d79bdd74e9 Bluetooth: Controller: Use bt_buf_get_rx for buffer allocation
The controller uses K_FOREVER for the allocations so there's no
benefit in trying to use specialized pools (which exist to try to
guarantee availability of buffers for critical data).

Change-Id: I130f2c44a2f28af1284290e6a0b17dcba438862f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Vinayak Chettimada a69cdca529 Bluetooth: Controller: Remove advertiser struct use in observer
Change-id: I2c332047d80167cb5823f5af605cb5edbcb5e9fe
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 0565945a5c Bluetooth: Controller: fix DLE conditional compilations
Fix missing conditional compilation of Data Length Update
feature.

Change-id: I93aa1da2145a33095c220c863ed1457bb27a7aec
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada d5d473b0f8 Bluetooth: Controller: replace work with mayfly
This commit introduces a very light-weight and lock-less
scheduling of the Controller's deferred function calls
called the Mayfly.

Earlier work implementation used in the Controller had an
O(n) to schedule a function in a linked list that used IRQ
lock during modification of the linked list in the
Controller's ISR executions.

Mayfly is a compile time configurable matrix of queues
where an execution context-safe queue exists between two
execution context, one being the caller and the second
being the callee. Callee(s) are run in a software interrupt
but can also be run in an OS thread.

There are minor clean ups too in this commit related to
folder structure.

Change-id: I5ff44dcee6679d2f5ce9e8437d98d6c868782f3d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 8bd73aeba7 Bluetooth: Controller: add memq_peek interface
Change-id: I276eddd5e347a5930cff3158ee9aaec0cc7a1585
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 85cfff0d92 Bluetooth: Controller: Kconfig fast encryption setup feature
Enable connection encryption setup in 3 connection
intervals. Peripheral will respond to Encryption Request
with Encryption Response in the same connection interval,
and also, will respond with Start Encryption Response PDU in
the 3rd connection interval, hence completing encryption
setup in 3 connection intervals. Encrypted data would be
transmitted as fast as in 3rd connection interval from the
connection establishment. Maximum CPU time in Radio ISR will
increase if this feature is selected.

Change-id: I16f2863fc2aaed624826505739519d4de1ac44c5
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 404e7662e0 Bluetooth: Controller: Kconfig Tx buffer size
Add Kconfig configuration to select Tx buffer size, this
value will be returned in the HCI LE Read Buffer Size
command response.
This configuration will allow lower Tx RAM usage when
larger PDU sizes are desired in Rx direction only.

Change-Id: I5106a448d78a0754c4b0f6fa61fd5dcacd87a67c
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 27353bb655 Bluetooth: Controller: Kconfig connection RSSI measurement
Add Kconfig configuration and conditional compilation of
RSSI measurement during a connection.

Change-id: I5a2f23f76a7cbbd9569d53d31899a472bf39d3ee
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 08fcc44b8a Bluetooth: Controller: Kconfig Data Length Update feature
Add Kconfig configuration to conditionally enable Data
Length Update procedure support in the Controller.
This will save CPU time, flash and RAM, if this feature is
not desired.

Change-id: I4515c0c7cf9aeb333a289397ae3c9bac04a08e4e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 4fb2947b61 Bluetooth: Controller: fix LE Ping conditional compilations
Add additional conditional compilation of code not needed
when LE Ping is disabled in Kconfig.

Change-id: Idab40b1371488e06a6f2009fb553f7655b7b86f3
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Carles Cufi 4b7cdd499f bluetooth: Tune stack sizes after measuring with hci_uart
The following readings were obtained after running the peripheral and
central_hr apps in qemu combined with the controller (hci_uart) on nRF51
and nRF52:

Main Stack 380
Idle Stack: 68
ISR stack: 532
Controller RX Stack: 388
HCI TX Stack: 516

The numbers set in this change provide a safety margin from the ones
measured empirically.

Change-id: Ice7ad7f081502e0ea1accf856a7937c0bf0783b2
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada b37e285c03 Bluetooth: Controller: Kconfig LE Ping feature
Add Kconfig configuration to conditionally enable LE Ping
feature in the Controller.
This will save CPU time, flash and RAM, if this feature is
not desired.

Change-id: I5fbbdbe8f45ac01c9b0d7b11e002a0d1db4d272e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 1921b53484 Bluetooth: Controller: refactor ISR to reduce critical path code
Move code that can be executed after radio tx/rx packet ptr
has been assigned in the radio h/w.

Change-id: I9c5a34ee6bb74c1265d7871bcdf93894e3e7b190
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada a591205045 Bluetooth: Controller: Kconfig radio ISR profiling
Add Kconfig configuration and conditional compilation of
radio ISR profiling.

Change-id: Ia80d6bc54810156be99b2e6a25327c30d0714697
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 73236dbaa5 Bluetooth: Controller: BT_INFO the ISR profiling event
Change-id: Ic2e01f698c13d76fc462349fe67f1694639888cb
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada ecb649c2a1 Bluetooth: Controller: add radio ISR profiling event
Added code to profile radio ISR execution time and generate
an event, which can be used to populate a vendor HCI event.

This event and associated code is disabled, subsequent
patch will add kconfig to enable it.

Change-id: Ic3fa3e0f4e36829a22a25ffee039949eaae561a7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 6996619399 Bluetooth: Controller: use BT_WARN to display unknown rsp
Use BT_WARN instead of BT_ASSERT to display unknown rsp in
HCI layer.

Change-id: I63c792468d9c4768f69df73395ee026a03521704
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada ced33653fa Bluetooth: Controller: internally handle unknown rsp for LE Ping
Peer controllers not supporting LE Ping feature will
respond with unknown response PDU, handle it internally in
the controller rather than exposing it to HCI layer.

Discovered that controller was passing the unknown rsp PDU
to HCI layer when LE Ping was send to Nexus 5.

Unknown response for slave feature request was forwarded to
HCI layer, during that implementation unknown rsp for LE
ping too was getting forwarded to HCI layer.

Change-id: I4396c482e5546d78239cf41d88728de996e48d7d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Johan Hedberg f3c632bf44 Bluetooth: Add timeout to event & ACL buffer allocation functions
Not all users are in an ISR context where we can't block, so give the
callers the freedom to choose if they want to block or not.

Jira: ZEP-1481

Change-Id: I19bd7e2df94c4eeb60886a17a78f872bd7bea887
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 08:42:15 +02:00
Carles Cufi 167eac7df3 Bluetooth: controller: Move call to k_sem_give() out of the ISR
The execution time of k_sem_give() increased slightly recently, and
since it was being called from the radio ISR this had an impact in the
deadlines not being met.
This change moves the actual call to k_sem_give() to a lower-priority
job and thus out of the ISR to avoid its execution time affecting the
ISR's timing.

Change-id: I76c82df895c6daaffef52786b0c900ee15acb0aa
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-24 08:42:15 +02:00
Carles Cufi fc479e03e0 Bluetooth: controller: Use SERIES config instead of NRF52
In preparation for the new Nordic MDK and nRF52840 IC support we switch
to using the SERIES config instead of the old "NRF52" macro that will be
deprecated in the new MDK.

JIRA: ZEP-1418

Change-Id: I563f025c9db9b7497116c5af23814d95c720f836
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-20 09:14:47 -06:00
Johan Hedberg 1c9da665c3 Bluetooth: Remove unnecessary runtime kernel object initialization
There are static initializer macros available for most kernel objects
which we should use whenever possible.

Change-Id: I496f4d05d26801eddd21fae53bdd4fcdc3246fe3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Vinayak Chettimada f0bd2805bc Bluetooth: Controller: tune the xtal and hard realtime radio start offsets
Reduce the time limit for active clock startup and increase
the CPU usage time limit before hard real-time radio
transmit/receive.

Due to isr_wrapper overhead in ARM architectures, more time
was used before hard real-time radio transmission or
reception which was detected by controller implementation
and the controller aborted the radio transactions.

This commit permits more CPU utilization by the controller
before hard real-time radio transactions start.

Change-Id: Id976add80c70cabc753c43dfac6f6603588458d9
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-12-16 10:27:48 +02:00
Vinayak Chettimada 6de7a808af Bluetooth: Controller: ctrl pdu processing based on available CPU time
On CPUs like nRF51 which run at 16MHz, certain BLE control
procedure PDU processing take more CPU time than permitted
inside tIFS (150us). Current implementation of Data Length
Update procedure does not span over multiple connection
interval (unlike Encryption Setup, which is another control
procedure processing that would consume more CPU time)
hence taking more CPU time inside tIFS on nRF51.

During the radio ISR, the active clock and packet timer are
active and it is used to profile the CPU time taken which
is used to decide on whether there is sufficient time in
the current radio event to process the control packet.

This commit also fixes a potential bug that would cause
disconnection due to MIC failure on encrypted connections
that performed Data Length Update. Controller used to NACK
the request/response PDU if it was not in a state to resize
the receive buffers but did not reset the CCM counter. This
is now fixed by the change done to NACK control PDU based
on available CPU time in radio ISR.

Change-id: Id58322ad76a0dbc284738cdd9a7c0437c9e8c423
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-12-16 10:27:48 +02:00
Johan Hedberg 299216b2f0 Bluetooth: Controller: Make use of min() convenience macro
Instead of having custom logic for determining the minimum of two
values, use the existing min() helper from misc/util.h.

Change-Id: I9809883d4a31126329373f293897dd49eb91e9ad
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-03 17:09:38 +00:00
Vinayak Chettimada f0186d716d Bluetooth: Controller: Fix DLE to check supported rx length
When the Controller is configured to support less than 251
as the supported maximum data length, missing check caused
the Controller to incorrectly re-initialize its rx buffers
causing assert during the DLE procedure. This commit fixes
the procedure to correctly use the supported maximum length
if the peer requests a transmit length that exceeds the
supported receive length.

Change-id: I6ad7196e3db44b303ddf2ec06e0ae579bf2eb774
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Carles Cufi d42987acf4 Bluetooth: Controller: Fix local LE supported features bitmap
Correct the local LE supported features bitmap to actually "or"
together all the bits that correspond to the set of features that
are implemented at this time.

Change-Id: I0c62ec566c775514250fcf062aeef6c9656719e3
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Carles Cufi 3b1baa88ef Bluetooth: Controller: Implement ECC commands
Implement the 2 HCI commands that provide ECC public key
and shared secret generation:

- LE Read Local P-256 Public Key
- LE Generate DHKey

Jira: ZEP-1246

Change-Id: I79388bfdb9f2e28b9377b4bb6ee2caca25f33f3e
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Carles Cufi c969e757bc Bluetooth: Controller: Implement missing DLE commands
Implement the 3 missing HCI commands required to support
Data Length Extensions:

- LE Read Suggested Default Data Length
- LE Write Suggested Default Data Length
- LE Read Maximum Data Length

Note: Only octets are actually used at this time, not time.

Jira: ZEP-1246

Change-Id: Id76d8fedb5ecaf0001c8429cf22f9a3e2c910a44
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada e9b818e763 Bluetooth: Controller: Fix suspicious use of sizeof
Fix Coverity, sizeof not portable, defect; by explicitly
using sizeof(void *).

suspicious_sizeof:
Passing argument mem_head of type void ** and argument 4U
/* sizeof (mem_head) */ to function memcpy is suspicious.
In this case, sizeof (void **) is equal to sizeof
(void *), but this is not a portable assumption.

Change-id: I4b4776466e16020876500feba0141985b8581017
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 26f6b71a8e Bluetooth: Controller: Fix incorrect irq priority check
External interrupts are indexed from value 16, wherein
0 to 15 are ARM cortex M exceptions. Fixed code in
_irq_is_priority_equal to fetch correct external
interrupt line ISR priority.

Change-id: I9cfd411480e78dfc9635e72d14df9d667a9d8400
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 27b1a24993 Bluetooth: Controller: Remove unused util functions
Change-id: I7b691d082d080239c35b63221e3c6c7aa93ed58e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 94a425429c Bluetooth: Controller: Fix incorrect auto variable init
Coverity analysis discovered NULL pointer being
dereferenced when passing a auto variable. The variable is
now correctly assigned with address of a valid default
value variable. As per design, the dereferencing will not
happen as the master role does not use the passed parameter
only slave role uses it to prepare the connection parameter
request PDU.

Change-id: I3f8519b23a83cb8c50c7fba81810eff7737ff74a
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 7b1c042b02 Bluetooth: Controller: Fix observer filter_policy field size
Coverity analysis discovered that observer filter policy
field was 1 bit, whereas valid range for extended scanner
filter policy feature implemented in controller is 0 to 3.
Increase the bit field size from 1 to 2.

Change-Id: Id4b2e354961dfb3b45f72fa4e0ab18de7425bbb5
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 11770b8bf4 Bluetooth: Controller: Fix HCI Reset Command implementation
Added implementation for HCI Reset Command. Implementation
gracefully disables any running advertiser, observer, and/
or connection roles, and it resets controller context members.
The HCI Reset Command is implemented in such a way that
driver instances shared with other sub-systems and
application is not disturbed and instance/references used
by Bluetooth Controller are gracefully returned back.

Jira: ZEP-1282

Change-id: Ifb9ae6807736b5ec2d9f346cf2a590322056bcee
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 4812b2d40e Bluetooth: Controller: Fix device whitelist feature
During the initial integration of controller to Zephyr OS,
radio hardware access was abstracted out into hal/radio.c
file. Bug introduced in hal/radio.c has been fixed so that
whitelist feature works again.

Change-id: Ie5faf80b1a008ef326613548a5a28a4ba52e7ef7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-11 16:40:59 +00:00
Johan Hedberg c245b96249 Bluetooth: Kconfig: Fix order of default entries
The conditional defaults must come last in order to be properly
processed.

Change-Id: Id7a152ca1a1584935029e212d0dd8f37494d1cf4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 12:09:46 +00:00
Vinayak Chettimada 5629197b17 Bluetooth: Controller: Add HCI_LE_Remove_Device_From_White_List
Add implementation in HCI and Controller to support
HCI_LE_Remove_Device_From_White_List, as it is listed as
mandatory under BT Spec. v4.2, Part E, Section 3.19 LE
Controller Requirements.

Change-id: Icef88dffc85746f3cc7adb7fb692ae5578274ed2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-11 11:56:47 +00:00
Johan Hedberg 916ed6cdd2 Bluetooth: Controller: Stop using deprecated APIs
Switch from fiber_start() to k_thread_spawn() and from NANOKERNEL to
POST_KERNEL init level.

Change-Id: I34fb11cbe20216c8646ebacb07be304a67e3cd0a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 10:04:02 +02:00
Johan Hedberg b0f0742b6e Bluetooth: Use k_yield() instead of deprecated fiber_yield()
Use the unified kernel API k_yield() instead of fiber_yield().

Change-Id: I8f52031f52f7ac8783033a51751dc22decdfa59a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg 3062516a1a Bluetooth: Controller: Improve default RX/TX buffer counts
Currently the ideal buffer counts for a controller-only build are 6 RX
buffers and 7 TX buffers: ATT_MTU of 158 bytes can be sent in one
connection interval of 6 tx/rx -es wherein connection interval is
7.5ms

Change-Id: I64b4620c5e8e7db8d7ed72fa1db82e266e121f27
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg c583a9f43b Bluetooth: Kconfig: Restructure for a more logical hierarchy
Restructure the Bluetooth options more logically.

- Both host and controller are now behind the same high level
  CONFIG_BLUETOOTH.

- Selecting controller support disables other HCI driver selection, so
  the controller isn't in the same list as HCI drivers any more.

- Under the top-level there's a "Custom stack" option, which when
  enabled opens up the option of choosing CONFIG_NBLE.

There are various other cleanups and simplifications in this patch as
well, since splitting these up would have been fairly tricky while
making sure all test cases still build.

Change-Id: I5bb715cb9d20201cb8b72fbd149c8a09a4b2d7d2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Carles Cufi f7d313b154 Bluetooth: Controller: Add ASSERT info dump on HCI builds
When building Zephyr in the controller-only configuration,
assertions that happen in the Link Layer code are not visible
to the Host which is running on another HCI and connected via
UART or USB to it. This patch allows the Controller code
to output the assertion line number when in such a configuration,
allowing the Host to view the event to help debugging.

The event format used is temporary and will be replaced by a
standardized Vendor Specific specification to come at a later
time.

Change-Id: I013ca6783a3fdedc47b171132919dd4798c66285
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-11 07:59:15 +02:00
Johan Hedberg 50f03a8de5 Bluetooth: Controller: Kconfig: Clean up style issues
The right convention for help text is tab + 2 spaces.

Change-Id: I2722a8b33f5f74be110dc43fbcecc12841f0db84
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Carles Cufi 6ccfa64b5c Bluetooth: Controller: Handle LL_UNKNOWN_RSP PDU for remote features
When a peer controller does not recognize one of the LL control
PDUs received, it will issue an LL_UNKNOWN_RSP PDU to let the
peer know that it does not recognize the request.
The controller now handles this incoming PDU and completes the
procedure by issuing the appropriate HCI event in the case of
an LL_FEATURE_REQ and _RSP pair.

Jira: ZEP-1220

Change-Id: I7c04a346441f04deee41198daa6309c11ae1b571
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-09 08:57:52 +02:00
Szymon Janc e18e3ed60a Bluetooth: Controller: Use unified k_sem API for semaphore
Change-Id: I02b4e5f4d0a2995cfae1b9a2edcbdf01d6ec631a
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 8944c25c90 Bluetooth: Controller: Include zephyr.h instead of nanokernel.h
zephyr.h includes required kernel header depending on selected
configuration.

Change-Id: Ib72c4038637c303ee32e433706355299ae1b9a13
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Vinayak Chettimada fb032efa90 Bluetooth: Controller: Use configured clock source
Remove hardcoded use of crystal as 32KHz clock source and
20 ppm accuracy; and use the values from config for sleep
clock source and sleep clock accuracy value in Bluetooth
Controller.

Change-id: I1c0d53ecf8ad158153d5186a6680b5eb03d1641b
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-07 12:04:03 +00:00
Vinayak Chettimada d62426030c Bluetooth: Controller: Fix re-encryption procedure
During implementation of alternate encryption procedure
usable in nRF51, commited in
c41d3edda8, re-encryption
procedure was broken. This commit fixes the issue, and
now re-encryption should work on both nRF51 and nRF52.

Change-id: Ia41200f42b1d46e1f3f35ff44b582d4ffcc5f4fa
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-04 22:06:31 +02:00
Johan Hedberg 26d39cd107 Bluetooth: Move controller code to subsys/bluetooth
Move controller code from drivers/controller to
subsys/bluetooth/controller.

Change-Id: I73f675188485aa3267507bad7647796e593a3da0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00