Commit graph

472 commits

Author SHA1 Message Date
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
Carles Cufi 8a7eeeb7f1 Bluetooth: Move HCI driver debug to top-level Kconfig
Since the HCI driver debug option applies to both files in
drivers/bluetooth and subsys/bluetooth, the configuration option itself
now lives in the top-level Kconfig file for consistency.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-10 08:23:25 +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
Johan Hedberg 97f0241c07 Bluetooth: Fix alignment issues resulting 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: Ic0e33dc199f834ad7772417bca4c0b2d2f779d15
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-29 11:39:13 -04:00
David B. Kinder 93e4d7258d spell: fix Kconfig help typos: /boards /drivers
Fix misspellings in Kconfig help text

Change-Id: I3ae28a5d23d8e266612114bc0eb8a6e158129dc7
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-21 21:31:30 +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 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
David B. Kinder 896cf7a00a spell: fix doxygen comment typos: /drivers
Fix doxygen comment typos used to generate API docs

Change-Id: I6fd5051c99bdcc731740c92001e525349c254d85
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-19 10:45:34 -07:00
Anas Nashif 306e15e0a1 kernel: remove legacy kernel support
Change-Id: Iac1e21677d74f81a93cd29d64cce261676ae78a6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-04-19 15:48:37 +00: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
Prasanna Karthik 6545aa3f52 Bluetooth: nble: Catch and handle non-zero fn_index
Avoid multiple breaks and gracefully catch non-zero values of fn_index

Change-Id: I1cf7b271b8478e63af2da1f40b4caceb63d7ce90
Signed-off-by: Prasanna Karthik <pkarthik@intrinsyc.com>
2017-02-10 12:03:09 +00:00
Jonathan Gelie 048a15bcc8 Bluetooth: GATT: fixing unsubscription
If subcription was found within the subscription list,
we have check if remains identical subscription
from the next node.
Otherwise none unsubscription is realized.

Change-Id: I38132d7c80575801885b8057902f3d4666b08aea
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-08 11:00:06 +00:00
Jonathan Gelie a42e4f694f Bluetooth: GATT: set subscribe value to zero for unsubscription
Subscribe value is set to zero before calling notify callback,
to distinguish a subscription failure from an unsubscription
on disconnection (when flag BT_GATT_SUBSCRIBE_FLAG_VOLATILE is set).

Change-Id: Ia91220492d82041b2c385bf88a15180387e7a483
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:44:01 +00:00
Jonathan Gelie b3ac77becd Bluetooth: GATT: introduce volatile subscription flag
Some application protocol required non-persistente subscription
across connection even in bonded case.
Flag BT_GATT_SUBSCRIBE_FLAG_VOLATILE specify if subscription
must be remove during disonnection.

Change-Id: I1bc2bbbb4bc86f58905e44a7eb267ca0871f2fdb
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:43:18 +00:00
Luiz Augusto von Dentz 31016448b4 Bluetooth: GATT: Fix not removing subscriptions safely
The subscriptions callback may free or reuse the subscription so all
instances that where this could happen need to safely fetch the next
element which is why this changes switch to use sys_list_t as it has
SYS_SLIST_FOR_EACH_NODE_SAFE.

Change-Id: I37d51f27116ea0c057b560924a9416676477597b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-06 11:18:57 +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 743379c21f Bluetooth: Kconfig: Merge headroom reserve variables into a single one
A subsequent patch will start reusing HCI command buffers for
receiving the response, so the distinction of received vs sent data
headroom would just make the code unnecessarily complex. Instead, just
merge these two variable into a single one.

Change-Id: I31d846331939f1a2270df7ed0c75112825e16493
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg bbf389aae6 Bluetooth: drivers/h4: Add support for discarding certain events
If we are low on RX buffers and receive an LE Advertising Report or a
BR/EDR Inquiry response we should just discard this. If we don't
discard the event we increase the risk of deadlock where the RX
interrupt is enabled but bt_recv() is doing a synchronous HCI command
sending, i.e. waiting for a cmd_status/cmd_complete (which will never
come since the RX interrupt is disabled).

Change-Id: I6266625c9790d68bcf8e8718c8c36f127946c4c6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Ricardo Salveti a3474a731e Bluetooth: SPI: Disable IRQ pin callback to avoid spurious IRQs
Avoid spurious IRQ when already handling the SPI Slave IRQ.

Change-Id: If8452a668bc9768d462a5fa56b851e99a076e67c
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Ricardo Salveti 2569e2e8d1 Bluetooth: SPI: retry spi_transceive calls if invalid
spi_transceive can return successfuly even if the data provided by the
slave is invalid, so check if the content is correct and retry until a
valid data is available.

Change-Id: Ia951de391e0b24c5b41eeabfb5c10b056d32b62e
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Ricardo Salveti f27d8eef39 Bluetooth: SPI: switch to a single SPI transfer when receiving
Change-Id: I27b504032080bddf7ebc88ef4812a0e7eab691c6
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Ricardo Salveti 8227c72c47 Bluetooth: SPI: fix max SPI buffer length
Drop the BLUETOOTH_SPI_RX_BUFFER_SIZE and BLUETOOTH_SPI_TX_BUFFER_SIZE
config options by fixing the max SPI buffer length to 255, as used by
the X-NUCLEO-IDB04A1 BSP. This simplifies the rx/tx buffer handling, and
avoids a potential spi rx stack overflow depending on the config values
set by the user.

Change-Id: Ifa7fd086016abda4bdcf9638f28b38d001a288c5
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Ricardo Salveti 4afe063aad Bluetooth: SPI: introduce CONFIG_BLUETOOTH_SPI_BLUENRG
This new option is used to encapsulate the logic specific to devices
implementing the BlueNRG Bluetooth stack (e.g. X-NUCLEO-IDB05A1).

The current BlueNRG specific logic covers the HCI Reset handling and
the manual control of the SPI Chip Select line (normally not needed since
spi_transceive is also responsible for controlling the SPI CS line).

Change-Id: I5db4addf873eee0af2d957e2181c50aac53ab656
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Ricardo Salveti ef7f2bd54e Bluetooth: SPI: fix Kconfig SPI IRQ PIN description
Change-Id: I4c25062e922cd05ca738222182909c261b55abca
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Johan Hedberg 4153b6ca1f Bluetooth: Kconfig: Make device name variable generic
Change BREDR_NAME to DEVICE_NAME so it can also be used as the LE
device name.

Change-Id: I9ef55d9dff098372d47d9d5754ad7a7163a65bc0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-28 08:43:41 +02:00
Ricardo Salveti e2b759bc69 Bluetooth: SPI: fix buf handling for HCI ACL packets
Code was assuming that all the HCI messages were events, causing invalid
data length when receiving HCL ACL packets.

Change-Id: I8c1a07f46b6b62a04e242cf29ee1119f59d4bda6
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Johan Hedberg 916837c22c Bluetooth: SPI: Replace Apache boilerplate with SPDX tag
There was a recent change to the license boilerplate of the entire
source tree, however as this spi.c was just recently added it missed
the change.

Change-Id: Icc95084a4b051266beaf1796c31d9aec9da538d0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-19 08:04:16 +02: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
Lee Jones 7890290e81 Bluetooth: Add HCI SPI driver
This driver acts as a pass-through, taking raw HCI data, converting
it to SPI comms and vice versa.  It works in the same way as the
existing H:4 and H:5 drivers, only it uses SPI instead of UART.

In this first release, the only BLE board which has been tested is
the X-NUCLEO-IDB05A1:

  http://www.st.com/en/ecosystems/x-nucleo-idb05a1.html

Although the current supported SPI format works like the one below,
it should be trivial to adapt it to support other chips with a
different format.

SANITY CHECK = 0x02
SPI WRITE    = 0x0A
SPI READ     = 0x0B

Tx Format:

   [HOST] {SPI WRITE}     0x00          0x00  0x00  0x00  {HCI MESSAGE ...}
   [CHIP] {SANITY CHECK}  {FLASH SIZE}  0x00  0x00  0x00  {0xFF * MESSAGE LEN}

Rx Format:

   {IRQ LINE GOES HIGH}

   [HOST] {SPI READ}  0x00          0x00  0x00             0x00  {0xFF * BYTES TO READ}
   [CHIP] 0x02        {FLASH SIZE}  0x00  {BYTES TO READ}  0x00  {HCI MESSAGE ...}

Change-Id: I4a00711c922d9ea02c5e2afb0d16715e413b1ed5
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2017-01-18 12:24:17 +00:00
Johan Hedberg 4ce96e1bc3 Bluetooth: drivers/nble: Remove bogus BT_DBG manipulation
This file doesn't even include <bluetooth/log.h> so any tricks on
BT_DBG are completely pointless (and wrong after the recent update to
the debug logging API).

Change-Id: I1b2b7942a11a4f7229dc35aa2701b3180dc35a28
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 11:04:58 +02: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 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 3341d7d2b5 Bluetooth: h4: Convert TX path to be interrupt based
Use interrupt based transmission instead of polling.

Change-Id: Iebfd67372044d3e6de9bdbdd6f0c9c6d01d46cb9
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 37aa1a1f8b Bluetooth: h4: Use k_fifo instead of k_sem
So far the use of k_sem meant that there was no major benefit of
having more than 2 or 3 RX buffers since there was no queuing
mechanism. Instead of using k_sem, introduce a k_fifo and use that to
queue up incoming buffers. This way the RX buffer count can be
increased with measurable effects on throughput.

Change-Id: I8122b233aeee7c8e145de3fff5f10bcfe348efaa
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 3fb654ecd1 Bluetooth: drivers: Use bt_buf_get_rx() in h5.c
The H:5 HCI driver doesn't need the type-specific bt_buf allocation
helpers.

Change-Id: Iccb9803f32f3143f1cdf972d9229124816a99aa6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 95049fb99b Bluetooth: Convert H:4 HCI driver to RECV_IS_RX_THREAD
Completely redesign the H:4 driver to utilize its own thread and
select the new RECV_IS_RX_THREAD Kconfig option.

Jira: ZEP-1483

Change-Id: I0ca0661b66d564e5edc1b8505706d6bb76632e79
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 6f429a38d8 Bluetooth: Kconfig Remove HOST_BUFFERS option
This option has not been used so far and will only contribute
unnecessary complexity in subsequent patches that introduce a concept
of combined RX buffers.

Change-Id: I53e0ce5155eebc352b84ba41b30ecb9d9958699f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 63f71adc5f Bluetooth: Take advantage of new net_buf_add_mem() API
This helps simplify code that was previously combining net_buf_add()
with memcpy().

Change-Id: If44cf9cd651aba5e544e36567869f147468663eb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
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
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
Johan Hedberg 71c7c01819 net: buf: Remove the need for net_buf_pool_init()
In order to keep the initialization process light-weight, remove
net_buf_pool_init() and instead perform the initialization of the pool
and buffers in a "lazy" manner. This means storing more information
in the pool, and removing any 'const' members from net_buf. Since
there are no more const members in net_buf the buffer array can be
declared with __noinit, which further reduces initialization overhead.

Change-Id: Ia126af101c2727c130651b697dcba99d159a1c76
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 09:58:02 +02:00
Johan Hedberg c3e08c8fea net: buf: Redesigned pool & buffer allocation API
Until now it has been necessary to separately define a k_fifo and
an array of buffers when creating net_buf pools. This has been a bit
of an inconvenience as well as blurred the line of what exactly
constitutes the "pool".

This patch removes the NET_BUF_POOL() macro and replaces it with a
NET_BUF_POOL_DEFINE() macro that internally expands into the buffer
array and new net_buf_pool struct with a given name:

	NET_BUF_POOL_DEFINE(pool_name, ...);

Having a dedicated context struct for the pool has the added benefit
that we can start moving there net_buf members that have the same
value for all buffers from the same pool. The first such member that
gets moved is the destroy callback, thus shrinking net_buf by four
bytes. Another potential candidate is the user_data_size, however
right not that's left out since it would just leave 2 bytes of padding
in net_buf (i.e. not influence its size). Another common value is
buf->size, however that one is also used by net_buf_simple and can
therefore not be moved.

This patch also splits getting buffers from a FIFO and allocating a
new buffer from a pool into two separate APIs: net_buf_get and
net_buf_alloc, thus simplifying the APIs and their usage. There is no
separate 'reserve_head' parameter anymore when allocating, rather the
user is expected to call net_buf_reserve() afterwards if something
else than 0 headroom is desired.

Change-Id: Id91b1e5c2be2deb1274dde47f5edebfe29af383a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-13 21:41:53 +00:00
Kumar Gala 49cd3b1891 drivers: bluetooth: nble: remove unneeded include path additions
We can locally reference the files we need, so don't add a -I we
don't need.

Change-Id: I764aea4177a8995489e0f15f71f7373427b43394
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2016-12-09 08:18:24 +02:00
Johan Hedberg a4b6b2417d Bluetooth: Switch from printf to printk functions
There's now snprintk available that's more light-weight on the stack
than snprintf.

Change-Id: I6b3e4409703ca92fe6b8f4146ff47c490ab826cb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg 9aafa973df Bluetooth: Fix incorrect logging format specifiers
Fix compilation issues that show up if SYS_LOG is mapped to printk
instead of printf. Unlike printf, printk is annotated so that the
compiler catches incorrect format specifiers passed to it.

Change-Id: I4d6f635a0ed61de698727028ea8767dc0ef28bb1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-07 13:15:59 +00:00
Johan Hedberg 2469bd6f87 Bluetooth: Use convenience macros for timeout durations
Using the K_* macros makes it easier to read what exactly the various
timeouts are.

Change-Id: Ia405d3760b8e600af7e33a7221ef6ec717708973
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-18 07:47:50 +02:00
Johan Hedberg 1e20e8dc04 Bluetooth: Fix left-over usage of TICKS_NONE and TICKS_UNLIMITED
Switch left-over usage of TICKS_NONE and TICKS_UNLIMITED to the new
unified kernel counterparts K_NO_WAIT and K_FOREVER.

Change-Id: I2f2a16360e816f9f8791eb216deb3c70b8cc87df
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-12 19:27:34 +02:00
Johan Hedberg 79f020be54 Bluetooth: Flag NBLE as deprecated
The NBLE driver is now deprecated and will be removed in a future
Zephyr version.

Change-Id: I50753f8cf8566ac1e4e73df480c96253c199e6a7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-12 16:18:55 +02:00
Johan Hedberg effbe6743d Bluetooth: drivers/nble: Convert to unified work APIs
Start using the k_work and k_delayed_work APIs.

Change-Id: Iac0525a444c5c4e0f28db08844d7b28e17e905fc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 11:13:47 +02:00
Johan Hedberg 776b3e6871 Bluetooth: drivers/h5: Convert to unified work APIs
Switch to using k_work and k_delayed_work APIs.

Change-Id: I3be18132cc417607adaec0ad711256b94e314c38
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 11:10:00 +02:00
Johan Hedberg 5f5425f20a Bluetooth: drivers: Don't use deprecated NANOKERNEL init level
Don't use the deprecated NANOKERNEL init level. The only requirement
for Bluetooth drivers is for them to be registered before the
application main() runs, so POST_KERNEL should be good enough.

Change-Id: I02a8609bf63e9d608b802576214a2e76211b3965
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:50:47 +02:00
Johan Hedberg c78bfd9a98 Bluetooth: Use k_sleep() instead of deprecated fiber_sleep()
Use the unified kernel API k_sleep() instead of the deprecated
fiber_sleep().

Change-Id: I587d72ca5b53aacc02647b32c3ebceb1d7fe067e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg 918a8e6bac Bluetooth: Use k_thread_spawn() instead of deprecated nano_fiber_start()
Switch to using the unified kernel k_thread_spawn() API instead of
nano_fiber_start().

Change-Id: I325cf467ae2a52c6aec8fc166397c323929e3013
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +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
Szymon Janc 2b16287286 Bluetooth: Use proper timeout defines for net_buf_get_timeout
Use defines from k_fifo intead of legacy API.

Change-Id: Ib8cf0d88240ef145da550b8cf83d2580e7140521
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 06:00:28 +00:00
Szymon Janc e2795499d8 Bluetooth: drivers: Use unified k_fifo API for FIFOs
Change-Id: Id2ef6f9a134e6471c59bf3baedccef219d7f12f6
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg b64e0d4c51 Bluetooth: Kconfig: Remove redundant 'default n' declarations
All boolean options default to 'n' without the need to explicitly
state this. It's only the cases where we want 'default y' where we
need to state this.

Change-Id: I47dbda62462ea437a2423b8508ea2cc640a22e41
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
Johan Hedberg d7f4fd74a9 Bluetooth: Use depends on SERIAL instead of selects
This suppresses warnings for platforms where SERIAL can't be provided.
All the platforms that these drivers are interesting for already
default to SERIAL=y.

Change-Id: Id692f99e018009b30903db8a2c046a6086be01c2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc b73b77652c Bluetooth: nble: Use unified k_sem API for semaphores
Change-Id: I5bf66ab7c3f863945f2c9f9392d773b348020367
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Benjamin Walsh 8cf56bcac7 unified: dissociate system workqueue from common workqueue module
Making a reference to the common work queue code should not necessarily
drag in the system workqueue, since it is possible to use a workqueue
that is not the system workqueue. This is done by moving the system
workqueue into its own code module.

Moving the system workqueue to its own code module allows removing the
NANO_WORKQUEUE and SYSTEM_WORKQUEUE kconfig options, and compiling the
common workqueue code and system workqueue all the time. They are only
linked in the final image if a reference to them exist, same as the
other kernel modules.

Change-Id: I6f48d2542bda24f4702e7c2e317818dd082b3c11
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-04 22:39:54 +00: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
Johan Hedberg 6bc645962a Bluetooth: Move Bluetooth host stack to subsys
Move the Bluetooth host stack from net/bluetooth to
subsys/bluetooth/host. This is preparation for having both host and
controller under the same root, i.e. subsys/bluetooth/.

Change-Id: I3bc796f7e331fca0c485f3890d62b9c03e027b96
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00
Carles Cufi 20952b75e3 Bluetooth: uart: Fix UART TX stall condition
In 3 of our UART driver implementations the ISR is exclusively
used and enabled for the RX path. The existing logic was
susceptible to a stall situation where a polled out transmission
would be interrupted by a reception and then the ISR code
would loop forever due to the TX event being signalled (although
the interrupt itself was disabled) causing the ISR to keep
looping for an RX interrupt.

Change-Id: Ic379e58b1c974aca3cee37d2d81f12c3726fb160
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-01 21:40:39 +02:00
Johan Hedberg 900fbc20ba boards: x86: Don't default to 'y' with NRF51_PM and WAIT_NOP
These options were only needed for a MyNewt-based nRF51 firmware on
these boards (the MyNewt BLE stack is called Nimble, hence the
prj_nimble.conf sample config files). With a Zephyr-based nRF51
firmware these options are no-longer needed, so it's not appropriate
to have them default to enabled. Instead, if they are needed, require
the app-specific configuration to enable them.

Change-Id: Iefbee4d97590af4e11bcedea05fe61f32a147b83
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-01 19:37:26 +00:00
Szymon Janc 4a345d3196 Bluetooth: drivers: Include zephyr.h instead of nanokernel.h
zephyr.h includes required kernel header depending on selected
configuration.

Change-Id: Ieb5666c96f94708a42f605c09eb710f8d2eee4ec
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-28 16:34:17 +02:00
Johan Hedberg 4599255871 Bluetooth: drivers/Kconfig: Fix inconsistency issues
Fix issues with tab vs space as well as missing license/copyright
header in hci/Kconfig.

Change-Id: Id766308dc8eda2d598ea749e5e0d2166014db929
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-28 08:09:08 +03:00
Johan Hedberg 6989bf88e1 Bluetooth: Rename bt_driver to bt_hci_driver
The bt_driver API was created when Zephyr only had a Bluetooth host
stack, but no controller-side functionality. The only "driver" that
was needed for the host was the HCI driver, and hence "HCI" was
omitted from the name.

With support both for host and controller Zephyr will be getting more
Bluetooth driver types, in particular radio drivers. To prepare for
this, move all HCI drivers to drivers/bluetooth/hci/ and rename the
bt_driver API bt_hci_driver.

Change-Id: I82829da80aa61f26c2bb2005380f1e88d069ac7d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-28 08:09:08 +03:00
Carles Cufi d1fe8e0189 Bluetooth: Controller: Fix net_buf memory leak in RX path
Since RSSI events trigger interrupts and signal the RX path
semaphore with a resulting event lenght of 0. Due to this
fact the Controller HCI driver was leaking (i.e. not freeing)
those events, grinding the recv_fiber to a halt.

Issue identified by Szymon Janc.

Change-Id: I3e259b2823717b523ac331f8f787252414fb9290
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-10-28 08:09:08 +03:00
Szymon Janc f187ab3b77 Bluetooth: drivers: Fix non-ASCII characters in NBLE code comments
Change-Id: I52377bd00e8890d30128b7cd3b3796abc4d6431d
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-28 08:09:08 +03:00
Szymon Janc ca1e885914 Bluetooth: drivers: Remove usued variables from H5 driver
Some variables were never used.

Change-Id: Ic6af13ab3292f1859120b9b939da5dfab7813194
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-28 08:09:08 +03:00
Carles Cufi 40b8ea136a Bluetooth: Controller: Set HCI version to 4.2
Report the HCI version supported by the Controller as 4.2,
since it was set as 0 (1.0b) and this confused certain Host
implementations, such as BlueZ.

Change-Id: I809721ee9c2b55e77e6a3ca63688c802a9ffa0ba
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-10-28 08:09:08 +03:00
Ricardo Salveti 26730bec6b Bluetooth: Controller: Make radio compatible with the nRF51 series
Isolate nRF52 specific configurations.

Change-Id: Icde32dc5e2c1753684e4c6bf39a5649652cdb8d0
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2016-10-22 01:25:56 +00:00
Ricardo Salveti 69b9451af1 arm/nordic: use a common header for the nrf51/nrf52 SoC families
Integrating the IRQ definitions for both nRF51 and nRF52, and defining
the set of IRQ values that are common to both.

Also switch the controller, uart and clock drivers to use the common
header definitions.

Change-Id: Id6816d7a97720896cfe4df83656fb8b1f8fb01fa
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2016-10-22 01:25:54 +00:00
Vinayak Chettimada a1c139eb84 Bluetooth: Controller: Remove custom clock control impl.
As part of an effort to closely integrate with Zephyr OS,
removed the custom implementation of clock control
interfaces used in controller code and use the driver model
in Zephyr OS.

Jira: ZEP-897

Change-id: I03efbff471e42b9bd9832818dd20dd5998a60227
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-10-21 07:47:31 +03:00
Luiz Augusto von Dentz ee9f5c1784 Bluetooth: GATT: Pass CCC attribute to changed callback
This way the application can reuse the same callback for multiple CCC
since it can track what CCC is affect by checking the attribute pointer.

Change-Id: I608da643aea07de26b65d67e6db3268d717d0f53
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-10-21 07:47:31 +03:00
Vinayak Chettimada c41d3edda8 Bluetooth: Controller: Alternate Enc procedure for nRF51x SoC
nRF51x SoC is based on ARM Cortex-M0 and running at 16MHz clock.
Due to Radio ISR latency restriction, the CPU utilization within
BLE tIFS of 150 us should not be more than the time radio h/w
takes to get ready. In order to keep short CPU utilization
inside tIFS encryption procedure has been spread over several
connection intervals. In comparison to possible encryption setup
in 3 connection intervals, this commit introduces a encryption
setup being done in 5 connection intervals so that max. CPU time
is well within the permissible limits by nRF51 h/w and tIFS.

Change-Id: I8971d69675836b9e18bea59d95951e0dfe8a7d2d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-10-21 07:47:31 +03:00
Johan Hedberg 7d0eef5f96 Bluetooth: Use proper const type for bt_storage_clear()
The bt_storage_clear() function doesn't modify the data behind the
addr parameter, so the pointer should be decared const.

Change-Id: Icce676f9df80bac26ba4877bb63752559a43339f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-16 09:00:57 +03:00
Vinayak Chettimada 8e25789052 Bluetooth: Controller: Remove custom irq implementation
As part of an effort to closely integrate with Zephyr OS,
removed the custom implementation of IRQ interfaces used
in controller code.

Jira: ZEP-841

Change-id: Ie427f45aeecad51053112371526cb7dc4817248f
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-10-04 08:12:14 +03:00
Vinayak Chettimada 54164b1350 Bluetooth: Controller: Fix SCHED_ADVANCED cond, compilation
Code under SCHED_ADVANCED macro in ctrl.c is used to
disable advanced radio time space scheduling calculations
used for placing non-overlapping observer and master roles;
to populate connection parameter request/response PDU
fields, and autonomous generation of slave initiated
connection parameter requests.

This macro shall always be enabled for optimal and correct
operation of the controller, It shall only be disabled to
debug failures in other part of the controller, to rule out
this code's influence, if any, on the failure being
debugged.

Change-id: I04e5f837ef0a5658361bd3668f583f1e13504570
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-10-04 08:12:14 +03:00
Carles Cufi 2fb8a11906 Bluetooth: Controller: Fix __packed placement
Place __packed at the end of the structure definition in line
with the rest of the Zephyr codebase.

Jira: ZEP-732

Change-Id: I25aa731cbd188a6e23ca2035eb22fa919295bb25
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-10-04 08:12:14 +03:00
Carles Cufi e9d32ed6e1 Bluetooth: Controller: Remove unused macro
Leftover from previous commits, this macro is not used anymore in
the HCI implementation.

Change-Id: I376c92a6b68432d2ff818ea25e68f087131e8479
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-10-04 08:12:14 +03:00
Carles Cufi 2f33724017 Bluetooth: Controller: Use net_buf for evt and ACL RX
Use the net_buf structure directly when populating incoming
ACL data or asynchronous events. This ensures that no additional
memcpy() operations are required and removes completely the
statically allocated buffers in hci.c.

Jira: ZEP-726

Change-Id: I6ac8bd0becb7037ce8ecfac109f44832d23fcfd2
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-10-04 08:12:14 +03:00
Carles Cufi 0a720c4771 Bluetooth: Controller: Use net_buf for CC/CS TX
Preallocate a response event net_buf buffer before processing an
incoming command and provide it to hci.c so that it populates
the event directly, instead of using a temporary buffer than
must then be copied into the return net_buf.
This applies exclusively to Command Complete and Command
Status, since those are the only events that are sent in
direct respone to an incoming command.

Jira: ZEP-726

Change-Id: Ia3ea71ac497690af929c44308760f68491ea829e
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-10-04 08:12:14 +03:00
Carles Cufi d12b6c87c9 Bluetooth: Controller: Use net_buf for HCI RX
Instead of copying the net_buf contents into a temporary
buffer byte-by-byte, the Controller HCI code now handles
incoming commands and ACL packets from the Host directly
in the net_buf containers, to avoid unnecessary memory
copying and to align with the rest of the Bluetooth stack.

Jira: ZEP-726

Change-Id: I9802607d84ee6206218b711e7e6e23dafb70581a
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-10-04 08:12:14 +03:00
Carles Cufi f976decdfa Bluetooth: Controller: Clean up naming in the HCI driver
As part of the effort to consolidate the BLE Controller's
HCI layer, the functions in hci_driver.c now use the "hci_driver_"
prefix when it is sensible to do so, and prefixes have been
removed altogether when they are not required.

Jira: ZEP-726

Change-Id: Icd3e56e0170f15636245ea12a389a5a9e86c166c
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-10-04 08:12:14 +03:00
Carles Cufi 496b02b54a Bluetooth: Controller: Refactor HCI files
As part of the effort to consolidate the BLE Controller's
HCI layer, the following files have been renamed:

* hci.h -> hci_internal.h: contains the HCI API to be used
by the driver
* main.c -> hci_driver.c: Implement bt_driver and includes
initialization and glue code

Jira: ZEP-726

Change-Id: Ica8b3e114da42a766a1b14ce59558cacd899a1a7
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-16 04:40:34 +00:00
Carles Cufi 4c9f1017c8 Bluetooth: Controller: Make HCI endianness-independent
Use the sys_ macros from byteorder.h to access all HCI
structure members that are endianness-dependent.

Jira: ZEP-726

Change-Id: I950f8eaca7048bf7972c2c4c347cfd5bbba17eb6
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 17:28:43 +02:00
Carles Cufi 90871a5e98 Bluetooth: Controller: Implement LE_RAND command
The LE_RAND HCI command was not filling in the rand array
with 8 random numbers as required by the spec.
Please note that the while() loop inside the command's
implementation can take up to hundreds of ms to execute.

Jira: ZEP-726

Change-Id: If27ff861ee5fa7842cd469e99d5bfa8ac47ac2fa
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi ef10baa235 Bluetooth: Controller: Clean up HCI macros
Clean up, document and remove the macros used in hci.c
to access the different parameters and calculate lengths
of events and data structures.

Jira: ZEP-726

Change-Id: I476aa9e061dfe429b5181265167bffa203ed151b
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi ec44eae44d Bluetooth: Controller: Use hci.h for ACL data
Switch to using the definitions in include/bluetooth/hci.h
for ACL data handling, both in RX and TX.

Jira: ZEP-726

Change-Id: I6b5f6de4ff568c4e73432df3edfa7d0a57f22fff
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 92b4458690 Bluetooth: Controller: Remove HCI event definitions from hci.c
Delete all event definitions from hci.c since the code now
uses the ones in include/bluetooth/hci.h exclusively.
This is the fourth and last commit in a series that transitions
from the event structures in hci.c to the ones in hci.h.

Jira: ZEP-726

Change-Id: I625c2aecf759823a1cc73a3ea096564284fe8c52
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 0ed85e24be Bluetooth: Controller: Use hci.h for num complete
Use Zephyr's include/bluetooth/hci.h for the HCI event
Number of Completed Packets.
This is the third commit in a series that transitions from
the event structures in hci.c to the ones in hci.h.

Jira: ZEP-726

Change-Id: I179bceb2f9dc07d7a1a524c3a80f0886f712ec2b
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi a587f2692c Bluetooth: Controller: Use hci.h for data-control evt handling
Use Zephyr's include/bluetooth/hci.h for HCI event
handling in data-related events.
This is the second commit in a series that transitions from
the event structures in hci.c to the ones in hci.h.

Jira: ZEP-726

Change-Id: I0e9e6f709091859af47d90b26f5e7baa830a2838
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi a955f583eb Bluetooth: Controller: Use hci.h for control event handling
Use Zephyr's include/bluetooth/hci.h for HCI event
handling in control events.
This is the first commit in a series that transitions from
the event structures in hci.c to the ones in hci.h.

Jira: ZEP-726

Change-Id: I6f131675add18e2ae061f0fb2cf220ea7057f852
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 0c463077ad Bluetooth: Controller: Unify handling of async events
This changes the way that aysnchronous events are handled
in the BLE controller's HCI layer. It performs all common
operations in a single place to avoid code repetition of the
same memory accesses over and over.

Jira: ZEP-726

Change-Id: Id9e8395944e8800f32dd9749da2b4f5c901c8682
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 9d48ef5888 Bluetooth: Controller: Switch to Zephyr's hci.h for cmd handling
Continue using Zephyr's include/bluetooth/hci.h for HCI command
handling in more of the commands.
This commit deletes all command and command complete and
command status event definitions and structures present in
hci.c.
This is the sixth commit in a series that transitions from
the structures in hci.c to the ones in hci.h.

Jira: ZEP-726

Change-Id: I34635a1f55f3aef124fd5ff005c99cedb40b8a49
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi be2bbbae2d Bluetooth: Controller: Switch to Zephyr's hci.h for cmd handling
Continue using Zephyr's include/bluetooth/hci.h for HCI command
handling in more of the commands.
This commit cleans up hci_cmd_handle() to use the new macros
added in previous commits.
This is the fifth commit in a series that transitions from
the structures in hci.c to the ones in hci.h.

Jira: ZEP-726

Change-Id: I152e02ed15042d367e95432bdd07ae5c74935be8
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 69e1816868 Bluetooth: Controller: Switch to Zephyr's hci.h for cmd handling
Continue using Zephyr's include/bluetooth/hci.h for HCI command
handling in more of the commands.
This commit removes Nordic Semiconductor Vendor-Specific
commands, since they are currently unused and
manufacturer-specific.
This is the fourth commit in a series that transitions from
the structures in hci.c to the ones in hci.h.

Jira: ZEP-726

Change-Id: If0141072489777bfecc06e4aaa5f569898a5c449
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 21b3fa240d Bluetooth: Controller: Switch to Zephyr's hci.h for cmd handling
Continue using Zephyr's include/bluetooth/hci.h for HCI command
handling in more of the commands.
This commit ports the LE controller commands to hci.h.
This is the third commit in a series that transitions from
the structures in hci.c to the ones in hci.h.

Jira: ZEP-726

Change-Id: I3f11cca1da4aa6a20cce9706362818f8f6c87b0a
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Vinayak Chettimada e00eed79aa Bluetooth: Controller: Use BT_ASSERT instead of custom impl.
As part of closer integration into Zephyr, remove the use
of custom assert mechanism and use BT_ASSERT instead.

Jira: ZEP-761

Change-id: I27f37d697b0a84bc001754a8d0b4dbb6ddb54298
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 34cd316301 Bluetooth: Controller: Switch to Zephyr's hci.h for cmd handling
Continue using Zephyr's include/bluetooth/hci.h for HCI command
handling in more of the commands, including the informational ones.
This is the second commit in a series that transitions from
the structures in hci.c to the ones in hci.h.

Jira: ZEP-726

Change-Id: Iecbc7ae5ba2c8435a51d62d59e8095aa25e6dc0e
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Vinayak Chettimada 2253f9b2b0 Bluetooth: Controller: alternate ticker compare set logic
Paranoid with older compare set logic, the changes in this
commit is better in avoiding compares being set to stale
count values (values in past). Compares shall always be set
in future w.r.t to current count value in the counter h/w.

No longer using fp_worker_sched() to explicitly run the
worker because there may be no ticks elapsed when worker
runs, which leads to ticker job running thereafter not to
update the compare to a new value, probably leading to a
stalled controller roles.

Change-id: If07f648357585ebb80c35d1320210eac3137781c
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-07 13:19:37 +00:00
Carles Cufi 42f7ab9443 Bluetooth: Controller: Switch to Zephyr's hci.h for cmd handling
Start using Zephyr's include/bluetooth/hci.h for HCI command
handling.
This is the first commit in a series that transitions from
the structures in hci.c to the ones in hci.h.

Jira: ZEP-726

Change-Id: I1d79586b85d25c8ef707b8a2b19a27a77b08b819
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Carles Cufi cdb197c727 Bluetooth: Controller: Unify handling of CC and CS
Place common code in hci_evt_handle() so as to avoid code
duplication in the handling of command complete and
command status events.

Jira: ZEP-726

Change-Id: I35ffcb63518b52a2b209f83ef6b8bbb1d1b4a849
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Carles Cufi 4ecc06c1e2 Bluetooth: Controller: Unify handling of unknown command
Handle all instances of an unknown OCF in a common place
instead of it being spread in multiple functions.

Jira: ZEP-726

Change-Id: Ibd9ebe429754980b243cb8772702cfeb59b0a18b
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 863e2b5ff5 Bluetooth: Controller: Enable all supported LE states
Controller implementation supports all Bluetooth Spec. v4.2 LE
states. Include the LE Read Supported States Command in Read
Local Supported Commands HCI command complete returned by the
Controller.

Change-id: I399f7c0326b058577e97e6d8a2676afbeb73b6fe
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 7a0561a60f Bluetooth: Controller: Measure and use correct stack size
Use stack_analyse in the recv fiber to print actual stack
usage, use this as default in Kconfig option, and declare a
rx fiber stack of Kconfig supplied stack size.

Change-id: Id97ad2de4f7be3069f93271d60544f760abbf575
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Carles Cufi 2334e225b7 Bluetooth: Controller: Use offsetof() in memory sizing
GCC requires __builtin_offsetof() to be used whenever
sizing arrays with its help. Now that stddef.h
includes conditional compilation, use the macro instead
of hardcoding the GCC usage.

Jira: ZEP-732

Change-Id: Ieb5c694e1dc8323bd1fa2d18711a893f8824c5b1
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Andrei Emeltchenko 68182568cb drivers/nble: Rename nrf51 power management functions
Rename nrf51_enable() to nrf51_wakeup()
and nrf51_disable() to nrf51_allow_sleep().

Change-Id: Ie8e8fa2dde281f212e231e0c4b751d3e0021b6b6
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 09b5998ced Bluetooth: Controller: Fix deadlock in recv fiber
Controller's fiber is expected to read all enqueued events
and data, hence wait on semaphore only after all events and
data are read.

Change-id: I0150f042b0ba91efa712b38903752b20198e5e6e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 5860686013 Bluetooth: Controller: Fix memory required calculation macro
Change-id: I73b06983911590f63728d769c401c8a9a53053d7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Andrei Emeltchenko 7a65695f0a Bluetooth/drivers: Fix missing argument in printf for h5 driver
Change-Id: Ia051f96742a4812c0a1014ec7030191d13544c3b
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-09-07 08:17:26 +03:00
Jonathan Gelie 4ba989f837 Bluetooth: Enable and disable BLE chip sleep mode dynamically
For power consumption matter, UART between quark and BLE chip shall
be disabled in absence of messages. GPIO NBLE_BTWAKE_PIN is used
from Quark to notify BLE chip payload is coming and so enabling UART.
The UART will be disabled by deasserted NBLE_BTWAKE_PIN signal, once
a message has been transmitted.

Change-Id: If538909784363f415f4266f62be57d8d9ff48b09
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 1254ac51ef Bluetooth: Controller: Fix assert on advertise start
Using the shell application, starting advertisement while
the scanner is already running caused the controller to
assert.
The work which is supposed to set the radio active state to
active is not executed before the radio ISR resets the radio
active state, causing the assert. This can happen when a
newly started role is initialized to setup the radio trx and
the radio start code then detects that its hard realtime
instant has passed (as time was spent setting up the ticker
and ticker then firing thereafter) and hence cancels radio
trx.
Optionally (without this commit), dynamic calculation of
preparation time can be disabled by setting a constant time
in the define RADIO_TICKER_PREEMPT_PART_US in ctrl.c to
avoid the assert.

Change-id: Ib4415ec4b1bfdcc89aa0f3912e5a8fdd2e817fde
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 22e3f62e07 Bluetooth: Controller: Fix coding style, use of (void)
Remove use of (void) before unused functions return values.
Replace use of (void) with ARG_UNUSED for unused parameters.

Change-id: I9ffea666f10dbdc01710df723e0df253a1cdd6e6
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Johan Hedberg 2599974189 Bluetooth: Controller: Fix coding style in ctrl.c, util/ and main.c
Initial sweep of controller code to fix the coding style.

Change-Id: Ib71c5a4657a1f162273f2dcd485fe70fff934928
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-07 08:17:26 +03:00
Luiz Augusto von Dentz 50997f2ccd Bluetooth: GATT: Add queuing support
This adds queueing support for requests that requires a response making
it simpler to use the API. The storage is keep in the parameters of the
request so it is up to the application to define how many can be queued
but in case the application don't want a request to block waiting for
a buffer it can use BLUETOOTH_ATT_REQ_COUNT to control the available
buffers which is recommended in case the requests will be sent from the
RX fiber.

Change-Id: I407c3982a7ecdc4a9eff7172d9d0addd46949783
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 5c01a7e3b3 Bluetooth: Controller: Add BLE controller driver
The main.c source file in drivers/bluetooth/controller acts as
the necessary glue between the Link Layer and Zephyr's
Bluetooth subsystem.  It instantiates the required RX fiber and
marshalls the control and data traffic between the BLE radio
and the BLE stack.

Jira: ZEP-702

Origin: Original
Change-Id: Ia62baedcd6e3ea83bd16306779357930f9a6c5f7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 48c48711e6 Bluetooth: Controller: A full, hardware-agnostic BLE Link Layer
The ll/ folder contains a full implementation of a BLE Link Layer
interfacing with a baseband and a radio through radio.h. The
current code implements most Bluetooth 4.2 features and is
currently functional and tested with nRF5x ICs from Nordic
Semiconductor.

Jira: ZEP-702

Origin: Original
Change-Id: Ib79cd97142d1a72c99dcf2a88116ac97ddd90a2b
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada c160a0548d Bluetooth: Controller: Add initial HCI implementation
For the Link Layer to be able to communicate with the rest of
the BLE stack in Zephyr, this barebones HCI controller
implementation includes an initial version of the fundamental
commands and events required.

Jira: ZEP-702

Origin: Original
Change-Id: I38bc9dae34e7075ab8b8178fd6b6659e2dec53b0
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 0d3d1d5c83 Bluetooth: Controller: Add a util folder with basic primitives
The util folder contains memory management, queue management
and misc utilities used by the Link Layer implementation.
This will be in time replaced by Zephyr's native functionality.

Jira: ZEP-702

Origin: Original
Change-Id: Id8602ea41ec44811801dfc582bab244c339eabe3
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 87d4d27731 Bluetooth: Controller: Hardware abstraction layer for nRF5x radio
The drivers/bluetooth/controller path adds a native BLE Link
Layer (controller and HCI) to the Bluetooth subsystem. This first
implementation adds support for the nRF5x series of devices
from Nordic Semiconductor. The hal/ folder inside the controller
contains all IC-specific code to interface with the radio and
baseband.

Jira: ZEP-702

Origin: Original
Change-Id: I4ed61d5f67af6b4735d746a38a5b55f054521075
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Andrei Emeltchenko 6ab1b9cdc4 Bluetooth: Add RAW API interface to Bluetooth
HCI RAW channel API is intended to expose HCI interface to the remote
entity. The local Bluetooth controller gets owned by the remote entity
and host Bluetooth stack is not used. RAW API provides direct access
to packets which are sent and received by Bluetooth HCI drivers.

Change-Id: I4ba2b7ca2c2b0d6c5de6ef1f231d1c5b82125e09
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-09-07 08:17:26 +03:00
Andrei Emeltchenko 712689c9a3 drivers/nble: Use semaphore to control notification rate
At the moment firmware reads everything we send to it over UART and
when an application tries to send too much notifications we are stuck.
The proper approach would be forcing firmware to read from UART only
when there is available memory. In this case we would block on UART
FIFO and everything handles gracefully.
This workaround mimics solution used by firmware project by allowing
to send next notification only after previous was sent correctly.

Change-Id: I56dd5abc4d13735d285415da04db75e7bb8bc459
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-07-22 19:03:43 +00:00
Szymon Janc d2549115ca Bluetooth: Rename connectable_addr member in struct bt_le_oob
Depending on advertising options this can be non-connectable address.
NFC pairing application document also allows broadcaster/observer
roles.

Change-Id: I9b104ac8fb9752a083a7a31fc20598c66f23f608
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-07-22 13:09:30 +02:00
Szymon Janc c6bcb591f6 Bluetooth: Add initial support for OOB data
This allows to query information needed for Out Of Band pairing
or connection creation. Currently supports only BT addresses.

Change-Id: I60bf9344baee552e7743fa8fc1b3cfb3a4765334
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-07-20 20:20:44 +02:00
Johan Hedberg 211ae314e8 Bluetooth: Pass net_buf_simple to scan callback
This lets the callback take advantage of the powerful net_buf API for
parsing the advertising data content.

Change-Id: Id65e6e83efd60c0f36c47bc5446a2e8ec2833d7c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-20 16:19:01 +00:00
Luiz Augusto von Dentz c51bcbb9d9 Bluetooth: GATT: Add write struct parameter to its callback
This makes bt_gatt_write consistent with the rest of the API where the
parameters are passed back to its callback.

Change-Id: Ie94208aa661d3620d0cbc5be4a4fb5b3c3ef061c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-07-20 13:40:55 +00:00
Andrei Emeltchenko 10411ed2f9 drivers/nble: Fix not setting user input expected flag
Fixes SEC/AUT/BV-11 PTS test case at least in GUI mode.

Change-Id: I60e7013f1c66027dabc1b94df87f2da991a5718c
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-07-19 07:29:06 +00:00
Andrei Emeltchenko 9ddbf6a3a1 drivers/nble: Improve debug
Correct that handle is attribute one, print flag to notice cancel
prepared write requests.

Change-Id: I46d747f0466a44460e92fcbaef4e436066c09f4a
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-07-18 09:34:20 +00:00
Andrei Emeltchenko 3a18f7e25c drivers/nble: Update nble_version structure
Add missing build_hash field.

Change-Id: Iee843b0354b7ab1699f75355542b719581b16b08
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-07-15 16:41:33 +03:00
Louis Caron beeafae556 Bluetooth: Align the NBLE firmware version and upgrade SD
The latest NBLE firmware includes a new version
exchange mechanism that is independent from the
RPC function definition.  It also allows using
firmwares that are automatically generated by
the official builders without needing a local
build.
The upgrade of the softdevice fixes several
issues in PTS tests.  The major change in
term of API introduced by this upgrade is that
upon write requests, the offset and data of the
write request must be sent back to the softdevice.

Change-Id: Ie574047a09a4e6fdcbf775bc98d8a61f981cee0c
Signed-off-by: Louis Caron <louis.caron@intel.com>
2016-07-14 13:59:39 +00:00
Luiz Augusto von Dentz 46f48ffec8 Bluetooth: H5: Use delayed work API
This replaces the use of delayed fiber with delayed work which doesn't
require extra stacks.

Change-Id: I3db0c168baabea2503163e26020bf5e4971ce584
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-07-08 12:05:34 +00:00
Szymon Janc 9c68fd4e5b Bluetooth: Add priority buffer for handling critical HCI events
Command Status, Command Complete and Number of Complete Packets are
used for driving TX fibers (HCI and connection). Missing any of
those event will lead to HCI traffic stall.

Priority pool will be used when critical HCI event is received
or normal pool runs out of buffers. The difference with priority
pool is that buffer from it must not be passed to RX fiber and
must be freed from bt_recv.

If driver knows HCI event opcode before requesting buffer for event
it may hint HCI core about preferred pool selection.

Change-Id: Iad14724945bb59721c5ffb6b62d5a8a3e3f70be7
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-06-29 14:51:51 +00:00
Luiz Augusto von Dentz e9083dfcd7 Bluetooth: GATT: Add flags to attribute write callback
This adds flags parameter to write callback which can be used to indicate
that data only need to be prepared with use of BT_GATT_WRITE_FLAG_PREPARE
fixing qualification tests that needs to check authorization or other
errors that cannot be verified with just the permissions.

Change-Id: I3d662b2027718ffb52a280e3bbc9750be14f89ae
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-28 17:36:08 +03:00
Mariusz Skamra 22f3baac91 drivers/nble: Fix included services
This fixes the regression of included services in nble.
Because user_data of BT_GATT_INCLUDE_SERVICE points to the first
attribute of service to include, and the bt_gatt_attr_read uses
memcpy, the pointer to pointer is needed to copy the address contained
in user_data to the buffer.
With this patch, included services work on nble as well as Zephyr.

Change-Id: If360014675c399fafc365185d5c1e41c913c8109
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-06-28 11:01:44 +02:00
Mariusz Skamra db250496b9 drivers/nble: Fix missing return status assignment
Status shall be stored to be returned in the response to the
on_nble_gatts_write_exec_evt.

Change-Id: I03172e4b8833f83bd9b60f10d3cb52a067cc9f34
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-06-23 11:03:35 +02:00
Mariusz Skamra ab8ec1592d drivers/nble: Fix missing FIFO initialization
FIFO object has to be initialized before being used.

Change-Id: I3bd774f60e2585d09cfba657cb2aa50c95e0c2f5
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-06-23 11:03:34 +02:00
Andrei Emeltchenko fbffa2a12f drivers/nble: Fix not unref not connected conn
If conn is not in BT_CONN_CONNECTED state we get extra reference.

Change-Id: Id78db628e776576ea120bda08e3f906c221015c7
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-06-22 17:27:56 +00:00
Mariusz Skamra cc1559ce56 drivers/nble: Add timeout before Conn Param Update as Peripheral
According to Core 4.2 Vol 3, Part C, 9.3.12.2,
The Peripheral device should not perform a Connection Parameter
Update procedure within T_GAP (conn_pause_peripheral) after
establishing a connection.

T_GAP (conn_pause_peripheral) is 5 seconds.
Fixes TC_LE_REJ_BI_01_C.

1/3   L2CAP   TC_LE_REJ_BI_01_C   PASS
2/3   L2CAP   TC_LE_CPU_BI_02_C   PASS
3/3   L2CAP   TC_LE_CPU_BV_01_C   PASS

1/3   GAP   TC_CONN_CPUP_BV_01_C   PASS
2/3   GAP   TC_CONN_CPUP_BV_02_C   PASS
3/3   GAP   TC_CONN_CPUP_BV_03_C   PASS

Change-Id: I66bf57a2b8323b748c15f61b2daecfaa435dbb69
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-06-22 16:01:48 +02:00
Andrei Emeltchenko a0204e22aa drivers/nble: Implement on_nble_gatts_notify_tx_evt()
Print debug statement allowing to track bugs with firmware, this also
removing Not Implemented warnings.

Change-Id: I15b77cd6efb5d9bc75910ef444f746c860ac3c6c
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-06-22 13:12:37 +00:00
Mariusz Skamra ad02f94c29 drivers/nble: Fix return type
This function can return negative value.

Change-Id: If466897821a0d1b718ad210df208ce8a004b3da9
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-06-22 11:25:37 +02:00
Mariusz Skamra b2ba8fbd0c drivers/nble: Split writing part of on_nble_gatts_write_evt
To be reused by on_nble_gatts_write_exec_evt.

Change-Id: I2cb7f3b8e2c33cbede9af3f211e876c4038bef36
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-06-22 11:25:32 +02:00
Mariusz Skamra cad52d1a66 drivers/nble: Fix execute write condition
This fixes the condition that has to be checked while writting attribute
value. According to the GATT API, write() callback returns the "number
of bytes written, or in case of an error BT_GATT_ERR() with a specific
ATT error code".

Change-Id: I4268e1d0585f5ce816ad64ca62232b6d739b780a
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-06-22 10:44:18 +02:00
Louis Caron b7702334c4 drivers/nble: Update firmware to 0620 revision
Update NBLE driver to use the latest firmware fixing the
dependency on the bt_gatt_attr structure size.

Change-Id: Ib93d7d29656028bfb06bbb6ca883816e2a7072fc
Signed-off-by: Louis Caron <louis.caron@intel.com>
2016-06-21 09:24:10 +00:00
Andrei Emeltchenko 5dc16e0b8f drivers/nble: Indicate that there is no buffers for prepare write
Change-Id: Icb81e4be07e33e0eae6d0341847d2c68be091039
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-06-17 11:12:44 +03:00
Andrei Emeltchenko 93693e60c4 drivers/nble: Shorten on_nble_gatts_prep_write_evt() name
on_nble_gatts_prep_write_evt() indicates that this is IPC function
which is not true.

Change-Id: Ic0c5f12136a84abd7b8e6144f7ca67f9b36968fe
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-06-17 11:12:44 +03:00
Andrei Emeltchenko 4b5e220b1f drivers/nble: Update firmware to 0614 revision
Update NBLE driver to use the latest firmware fixing long write and
updating IO capabilities model.

Change-Id: Iea154f934dd6502fce3960763890ac15492c2952
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-06-17 11:12:44 +03:00
Kumar Gala b6dd6ec56b Bluetooth: H4: Remove unused board.h include
The board.h include isn't needed so remove it.

Change-Id: If6e2725007f340afd1b782c0278edd5317dfde0f
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2016-06-17 06:28:26 +00:00