Commit graph

472 commits

Author SHA1 Message Date
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
Andrei Emeltchenko a31a9f9aa3 drivers/nble: Fix compile error with debug enabled
Change-Id: I9b9bff6562b58bbd57595d8ec33d960d1b15c908
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-06-15 14:47:39 +00:00
Andrei Emeltchenko c2ece8aec2 drivers/nble: Fix hanging conn reference
Remove gatts_write_evt() function since it takes conn reference and
forgot to de-reference. Use directly attr->write() instead.

Change-Id: I21737c8feda23ff7df154fcd72327b8ff2d59467
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-06-15 12:08:56 +03:00
Inaky Perez-Gonzalez d49d17f80b doc: remove *.h so documentation generation doesn't complain
With *.h added, the REST processor does not escape it and it thinks is
a non-finished emphasis line (*ddd*). Although the rest generator
should be fixed to escape those things, we don't have the resources to
tackle that and removing '*.h' doesn't alter the meaning.

Change-Id: I6b39551fc8d37d8dd63a68ed70619fc8fb64f2e5
Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
2016-06-15 01:44:54 +00:00
Johan Hedberg 4c95464b9e Bluetooth: Use proper net_buf APIs
Now that buffers can contain fragments we should always use the
net_buf APIs to read/write FIFOs and never the nano_fifo APIs
directly.

Change-Id: I203af43e887145a1b14f33a3729ef721fbd46469
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-13 17:22:05 +03:00
Johan Hedberg ebd5011adf Bluetooth: Update Intel copyright for files modified in 2016
Change-Id: I10a7cab9a7f911b9f64e17bf24ddce82c2f08c40
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-10 12:10:53 +03:00
Johan Hedberg b76426de6f Bluetooth: Fix never yielding if rx_queue always contains data
It's common for the rx_queue to be written to in ISR context (by the
HCI driver). This means that if there's lots of data coming in from
the driver the rx_queue might get empty very rarely. With the current
code this means that the rx fiber might end up not yielding to other
higher priority runnable fibers for long durations (as long as there's
data in the rx_queue).

To solve the issue, call fiber_yield() explicitly after each processed
buffer from the rx_queue. This way we give other fibers a chance to
run even if there's a heavy flow of data from the Bluetooth
controller.

Change-Id: Ib3dbe6536a62360ad5153ed12eee8489645e4109
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-07 21:38:20 +03:00
Luiz Augusto von Dentz 56419a135b drivers/nble: Add buffer pool for prepare writes
This is similar to previous patch which makes the API much more simple
when handling long writes.

Change-Id: Ibd3856863a43927195e23936872a160d5ff94648
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-06 12:28:35 +00:00
Johan Hedberg e8620aaada Bluetooth: Take advantage of net_buf_get_timeout()
Use the more explicit net_buf_get_timeout() call where it makes sense
(e.g. where we always want to wait or never want to wait).

Change-Id: Id1eabe0ad2f9fa79f7be39e51fefa5161f9cc550
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-02 10:32:29 +00:00
Andrei Emeltchenko 2b456dd120 drivers/nble: Implement on_nble_sm_security_request_evt()
Implement handling SM Security Requests. Fixes among others following
Bluetooth PTS test cases:

...
1/6   GATT   TC_GAR_CL_BI_05_C   PASS
2/6   GATT   TC_GAR_CL_BI_22_C   PASS
3/6   GATT   TC_GAR_CL_BI_27_C   PASS
4/6   GATT   TC_GAW_CL_BI_06_C   PASS
5/6   GATT   TC_GAW_CL_BI_24_C   PASS
...

Change-Id: Id35004a134bb9898e3b0dd51309f1762676ca579
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-06-02 12:08:54 +03:00
Andrei Emeltchenko d00b9f0cb9 drivers/nble: Check existence of callback before call
Check that callback is defined before call, fixes issue in
on_nble_sm_status_evt calling cancel callback.

Change-Id: Ie2f49ed6e441f4260dacd16120e09f892c1fd528
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-06-01 08:21:18 +00:00
Szymon Janc d1d0ee7b2d Bluetooth: Allow to call enable function only once
Currently enable procedure can be called only once regardles if it
failed or succeeded.

Change-Id: I3869e97442720860baba7bb1b7610738ca95561a
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-31 11:37:12 +00:00
Szymon Janc d2fa54d4a6 drivers/nble: Use flags for state tracking
Using atomic flags instead of bool allows adding new states easily
without aditional memory footprint.

Change-Id: I0289a49af8353dc832a33e16ebdd6651c3913fe3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-31 11:04:41 +00:00
Andrei Emeltchenko 47d104530c drivers/nble: Call right function in bt_conn_auth_cancel()
Change-Id: I9e8ced163b95acbcb1835ed4b0de4fd110a2bd54
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-31 11:04:03 +00:00
Andrei Emeltchenko c42ea24886 drivers/nble: Refactor on_nble_sm_status_evt()
Remove NBLE_GAP_SM_EVT_START_PAIRING handling since this is handled
now in the special pairing event and defer negative status handling to
the actual event code processing.

Change-Id: I232d9e5ecd09b2600df3ff04128dfb7f71a2eae2
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-31 11:03:40 +00:00
Andrei Emeltchenko 4a2afe4ade drivers/nble: Implement pairing confirm callback
Implement bt_conn_auth_pairing_confirm() callback.

Change-Id: I53f7fef05833e204e75aeb644efae8db10553e72
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-31 11:03:10 +00:00
Andrei Emeltchenko 0324f39313 drivers/nble: Implement passkey entry
Implement bt_smp_auth_passkey_entry() and bt_conn_auth_passkey_entry()
functions to be used by apps and tester.

Change-Id: I600284334c67840dd0c17991596ad31986bf0afd
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-31 09:49:34 +00:00
Andrei Emeltchenko ed044a7279 drivers/nble: Sync smp code for firmware compatibility
This moves SMP related code to smp.c making code similar to the tree
of firmware developers.

Change-Id: I5b43dcbe40a721e11b64cbdd4203406e721f40cd
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-31 09:39:25 +00:00
Szymon Janc 31912bcb23 Bluetooth: Constify bt_register_starage parameters
There is no need for struct bt_storage being modified by stack.

Change-Id: I732cf94983a29de40d692e802d6a71b8986708df
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-30 12:57:24 +00:00
Andrei Emeltchenko a195351151 drivers/nble: Update RPC to version 0527
Update RPC to the newest RPC introducing some security improvements in
the firmware.

Change-Id: If031bb13927d63e029fcc6da34051257d13632a5
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-30 09:07:50 +00:00
Andrei Emeltchenko 979e10de6f drivers/nble: Fix NULL dereferencing
Fixes dereferencing NULL calling not defined function. Fixes PTS test
TC_GAW_CL_BV_01_C which was failing with the trace:

...
bt: on_nble_gattc_write_rsp (0xa80099e4): conn 0xa8008f60 status 0
***** CPU exception 6
Current thread ID = 0xa80099e4
Faulting segment:address = 0x00000008:0x40000000
eax: 0xa8008f60, ebx: 0xa8008f60, ecx: 0x00000000, edx: 0x00000000
esi: 0xa8009f88, edi: 0x00000000, ebp: 0a8009f80, esp: 0xa8009f70
eflags: 0x00010247
Fatal fiber error! Aborting fiber.
...

Change-Id: Ia76c2ad816e6427b353ab245855a1959c23c5feb
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-30 08:59:10 +00:00
Kumar Gala 9ec2f3be80 Cleanup whitespace in Kconfig files
Convert leading whitespace into tabs in Kconfig files.  Also replaced
double spaces between config and <prompt>.

Change-Id: I341c718ecf4143529b477c239bbde88e18f37062
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2016-05-25 13:28:07 -05:00
Andrei Emeltchenko 171dab4f22 drivers/nble: Defer GATT long write errors to execute response
Defer Prepare write errors to be sent in Execute write response
Per Bluetooth Spec. The Attribute Value validation is done when an
Execute Write Request is received. Hence, any Invalid Offset or
Invalid Attribute Value Length errors are generated when an
Execute Write Request is received. Fixes test case
TC_GAW_SR_BI_33_C (run with shell).

Fixes: ZEP-218

Change-Id: I3dc4583f519e0da2e1f741c9b532d6a6c1970225
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-25 16:44:55 +00:00
Mariusz Skamra 076df0ce73 drivers/nble: Fix GATT Server Indications
This fixes GATT Server indications.
conn handle shall be set to the valid handle, not 0xffff.
If conn passed to bt_gatt_indicate is NULL, indication will be sent
to every client subscribed.

Fix related to ZEP-403

Change-Id: Ie36b957fddfbc5485318bba649d15349e9293868
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-05-25 14:40:04 +00:00
Andrei Emeltchenko db6f45823f drivers/nble: Improve logging for long characteristic
Print flag for write_evt() to distinguish between write and
prepare_write. Add offset printing when reading.

Change-Id: I8b53d8f49657ade39b190ab33e99097bb172077c
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-24 13:19:35 +00:00
Grzegorz Kolodziejczyk 8c3189c646 drivers/nble: Update service db attributes handle
Attributes should have stored their own attribute handle after
registering service. Handle values are assigned to attributes after
registering service and stack has to copy them.

Fixes:
GATT   TC_GAD_SR_BV_03_C      PASS

Change-Id: I8463340960d663161d0f7990390e60f06a1c7259
Signed-off-by: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@tieto.com>
2016-05-23 16:49:08 +02:00
Andrei Emeltchenko 1be6e1cb7d drivers/nble: Skip not matched UIIDs in GATT discovery
Firmware does not filter by UUID so we need to do this ourselves.

Change-Id: I55808836369194fbc5ea7c35db2c72fcda75e4eb
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-20 11:06:52 +00:00
Andrei Emeltchenko 8d7fb04546 drivers/nble: Add debug uuid print in bt_gatt_discover()
Change-Id: Iaf400c1020cf29df780114428c61f9e91c6aac0c
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-20 11:06:35 +00:00
Andrei Emeltchenko 46d825fdab drivers/nble: Check that attribute is withing range
Fix iterating all attributes

Change-Id: If9555a02e76368dbfb952ef0710100a7aef288bd
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-19 18:44:12 +00:00
Andrei Emeltchenko 39557c4706 drivers/nble: Update Nordic RPC to 0518 release
Fixes limited discov mode bug and GATT write long request.
1 mandatory and 9 optional PTS test cases.
Fixes: RTOS-1524
Fixes: RTOS-1551

Change-Id: Iac3618af8d840073b72503cfbdf34b80e4334074
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-18 18:36:26 +03:00
Andrei Emeltchenko 06e0201735 drivers/nble: Update RPC to the latest 0516 firmware
Change-Id: I8552c05be2eeee0c94fdea0a6378bebdd37c7d91
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-16 14:30:22 +03:00
Andrei Emeltchenko e79a2cfa0c drivers/nble: Update RPC to Nordic BLE firmware 0513
This is actually a revert from a previous revert. This updates RPC
following the very recent firmware development.

This reverts commit a146f9ef28.

Change-Id: I67b517c3959b5b78a5ef80fbb338d6cc66e43e8e
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-16 14:18:46 +03:00
Andrei Emeltchenko a1f7e480b1 drivers/nble: Call bt_conn_security() on start pairing event
Call bt_conn_security() the same way it is done in upstream code for
NBLE. Currently use BT_SECURITY_MEDIUM as default sec level.

Makes at least following cases pass:
...
1/6   GATT   TC_GAR_CL_BI_05_C   PASS
2/6   GATT   TC_GAR_CL_BI_17_C   PASS
3/6   GATT   TC_GAR_CL_BI_22_C   PASS
4/6   GATT   TC_GAR_CL_BI_27_C   PASS
5/6   GATT   TC_GAR_CL_BI_33_C   PASS
6/6   GATT   TC_GAW_CL_BI_06_C   PASS
...

Change-Id: I2a0c177a187db931e88e2f82a5bda1c0cc04a112
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-12 15:10:21 +00:00
Andrei Emeltchenko c4ec82cc89 drivers/nble: Implement bt_smp_auth_cancel()
Implement bt_smp_auth_cancel()

Change-Id: Id37709f3a86619ece400d1502da2ed7b83436e9b
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-12 15:10:07 +00:00
Mariusz Skamra 4e68ea947e drivers/nble: Notify about updated connection parameters
This adds a notify_le_param_updated function to call registered
le_param_updated callbacks with new connection parameters.

Change-Id: Idd660f7ca024c2f7712a6a41a51db77e4fc82a00
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-05-12 10:08:39 +00:00
Mariusz Skamra f4451c7030 drivers/nble: Update connection parameters on_nble_gap_connect_evt
This issues connection parametrs update on new connection event,
to mimic Zephyr stack behaviour.

Change-Id: Ic3fa86a02ff9a5135a026dfff6d2fbfb890656c1
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-05-12 10:08:29 +00:00
Mariusz Skamra 5a9a5259e2 drivers/nble: Add bt_conn_le_param_update implementation
This adds implementation of bt_conn_le_param_update function.
Connection parameters can be only issued while in slave role,
because, nRF51 supports this procedure over L2CAP only.
Closes ZEP-222.

Change-Id: I2bb5f718b60b8be279f333c9721629662c029a32
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-05-12 10:08:14 +00:00
Mariusz Skamra 0b76866bab drivers/nble: Store new connection parameters
on_nble_gap_conn_update_evt gives information about new
connection parameters. These shall be stored in conn.
Closes ZEP-222.

Change-Id: I69e36136cfae98821b1f5467c72c94dbc6f1d10f
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-05-12 09:39:11 +00:00
Mariusz Skamra 31f6af2e34 drivers/nble: Move bt_le_conn_params_valid function
This function will be used by bt_conn_le_param_update to validate
parameters.

Change-Id: Icd60d74dae3bf467af4b7277d1516b978ba937a5
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-05-12 09:38:52 +00:00
Mariusz Skamra 4e0f6b8758 drivers/nble: Fix setting connection role
According to the data from nble_gap_connect_evt,
role_slave is "0 if connected as master, otherwise as slave",
so to be consistent with our API, this shall be mapped to
either BT_CONN_ROLE_MASTER or BT_CONN_ROLE_SLAVE.

Change-Id: Icf31ef02ea178e04cb28b2611e09b06c23f49704
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-05-12 09:38:39 +00:00
Andrei Emeltchenko 7a51619d89 drivers/nble: Implement on_nble_gatts_write_exec_evt()
Implementing on_nble_gatts_write_exec_evt makes pass test case:
...
GATT   TC_GAW_SR_BV_06_C   PASS
...
Fixes: ZEP-221

Change-Id: I39a78887a990e37a75d9b025b3baf4dee3475bba
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-12 10:18:50 +03:00
Andrei Emeltchenko 51d607f9bd drivers/nble: Fix passing uninitialized req parameters
Fixes passing structure nble_gatt_write_params uninitialized.

Change-Id: Ic092257693eb50b902936f3a5355a6d0e31bc3fe
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-12 09:51:09 +03:00
Luiz Augusto von Dentz 20bfb62308 drivers/nble: Make sure gatt_private is reset properly
gatt_private should be reseted whenever used otherwise other commands
may fail when attempt to use.

Change-Id: I8bdda3d5136368a8f37fd9e2afd97e0957c4e04e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-05-11 11:29:08 +03:00
Luiz Augusto von Dentz 777033f710 Bluetooth: GATT: Make bt_gatt_write take a struct
This makes bt_gatt_write similar to bt_gatt_read where the parameters are
stored in a struct which can be used to store intermediate values while
the operation is in progress.

Change-Id: I3c62af137b99985690cf88dcc37a977a0be891f5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-05-10 17:55:06 +00:00
Andrei Emeltchenko 6a3d32cbee drivers/nble: Update RPC version to 0510
Change-Id: Ied97eaedacfe8d3a053b0732f56791486d8c9561
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-10 10:41:52 +00:00
Mariusz Skamra 3828a2008a drivers/nble: Fix NULL pointer dereference
Due to the recent changes, read parameters pointer is passed as user_data,
not as gatt_private.

Change-Id: I08b59164acfec8d71801ae2a23ce51abad080dc8
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-05-10 11:44:05 +02:00
Andrei Emeltchenko a146f9ef28 Revert "drivers/nble: Update RPC to Nordic BLE to 0509"
Revert to RPC to BLE Radio Module 0425 as it is going to be official
open source release beta.

This reverts commit a52d7d7fe0.

Change-Id: Ibdb98b26bcad0a04849e89622527884a2b67c8d4
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-10 11:56:02 +03:00
Andrei Emeltchenko 22ac4fd13e drivers/nble: Fix passing uninitialized write request structure
Fixes using uninitialized structure nble_gattc_write_param in
nble_gattc_write_req().

Change-Id: I476a3b833994c422691bf96dc0b2174368c47fa6
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-09 16:34:19 +03:00
Andrei Emeltchenko 9178dce953 drivers/nble: Fix passing uninitialized scan parameters
Initialize req to zero, fixing passing uninitialized use_whitelist,
scan_type in nble_gap_connect_req().

Change-Id: I57f957db81f6d7cd3e24e3e7393ba1f055b42330
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-09 16:33:24 +03:00
Andrei Emeltchenko 4616f07f51 drivers/nble: Increase RX buffer pool
Since RPC to the Nordic BLE module has no flow control increase
receive buffer pool to handle events from the module. Without this
NBLE stack is not capable of handling all events and we get "No
buffers" error message.

Change-Id: I0566b30a95ef0a027d4533c83c3c2915018a650a
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-09 15:15:43 +03:00
Andrei Emeltchenko 5a97415bd5 drivers/nble: Fix memory leak with double connection create
on_nble_gap_connect_evt() gets called in a case of incoming connection
but also with outcoming one. In this case connection is already
created so we should use conn_get() instead of conn_new().

Change-Id: I2ed2d0a1844f653000a12eb0f54f52533856bf0d
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-09 15:13:14 +03:00
Andrei Emeltchenko a314368aac drivers/nble: Increase debug for NBLE
Change-Id: I92fca3a8d28aa29f31d0c448b6b9bc9931ce2118
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-06 17:05:40 +03:00
Andrei Emeltchenko a52d7d7fe0 drivers/nble: Update RPC to Nordic BLE to 0509
Update RPC following major RPC update in firmware.

Change-Id: I4094b94319359a59164ac69394937ac1472b8cbe
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-06 11:28:34 +00:00
Szymon Janc a14c932d91 drivers/nble: Fix setting SCAN_RSP data twice
set_ad() already checks for length==0 so there is no need for
checking if sd is valid.

Change-Id: Idc0ce9135eca56a1e8057f3a2129adb0b5e5ddd7
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-05 12:19:36 +00:00
Mariusz Skamra 20c7f47fc0 drivers/nble: Pass read_params as nble user_data
Getting params from user_data seems to work now.

Change-Id: I81bccea9aa6994d3c09a3ff03a49fa6767e7305e
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-05-04 15:24:00 +00:00
Mariusz Skamra ec8a92b93a drivers/nble: Fix NULL pointer dereference
In on_nble_gattc_discover_rsp conn->gatt_private is set to NULL prior
to calling this parser functions. This fixes this issue by passing
discover params pointer to these functions.

Change-Id: I6669cb0d16dc65d532e17f96ceb9cd94dbe6ce08
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-05-04 15:23:39 +00:00
Andrei Emeltchenko 6e60fc8d7c drivers/nble: Update RPC function names
Updating function names prepares for firmware RPC update, to this
moment only names changed.

Change-Id: I8d19e83c5c88a4b41ed803e276652eb15e0d87b1
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-04 14:23:17 +00:00
Johan Hedberg 58ab2526e8 Bluetooth: Make UART draining logic consistent across drivers
There's no need to drain twice if NRF51_PM is enabled, the draining
shouldn't use rx_ready(), and it should happen after disabling
interrupts. Also rename uart.h to util.h to avoid conflicts with
include/uart.h and remove the left-over ISR prototype declaration.

Change-Id: Id38110dd38cf48edfe4a7b8e2e68cd358a9aa5ea
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-04 13:37:44 +00:00
Andrei Emeltchenko 492448b0f9 drivers/nble: Refactor NBLE RPC function names
Update function names following firmware name changing.

Change-Id: I8b42c4d9f5c892abec10d8653544c3e03e4ee80d
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-04 13:19:04 +00:00
Andrei Emeltchenko ef3fd51ade drivers/nble: Refactor gap_internal headers
Change-Id: I9b3ea113df2759b6586c3767acbde644c4cd2fd4
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-04 13:07:31 +00:00
Johan Hedberg caf50a52ea Bluetooth: Fix draining nRF51 FIFO during init
It's possible that there's a queued event from the nRF51 at the point
where we start resetting it, resulting in the stack receiving two NOP
events. To prevent this, make sure to drain the UART while the
controller is in a powered off state.

Change-Id: Ic009e11c11ac750fc76c881c0ffe9bd12d38da0a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-04 15:05:13 +03:00
Szymon Janc 6d5ed390b1 Bluetooth: Simplify advertising API
Instead of requiring application to provide both advertising type
and address type used just require app to provide info if advertising
is connectable or not. Advertising type is set based on provided
SCAN_RSP and local privacy support.

When local privacy is enabled it is no longer possible to advertise
using identity address. If such feature is to be required later on
advertising options can be extended.

This gives BT stack full control over what type of address is used
for advertising and is a preparation for random address rotation
and OOB support.

Change-Id: I90e9a683ef3794f155707343c874f75585439325
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-04 11:11:34 +00:00
Andrei Emeltchenko 2b7f0c8ede drivers/nble: Implement notification for all conns
In a case connection is not known implement notification for all
connections the same way it is done for HCI stack. Attribute database
is scanned for CCC attribute and notifications are sent to all
connections.

Change-Id: Id556b4aa5af124aea672891ca89b278c71519643
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-04 08:29:20 +00:00
Andrei Emeltchenko d7a31fa726 drivers/nble: Implement bt_gatt_foreach_attr()
Implement foreach iterator for NBLE.

Change-Id: Iebc158121f7a860ce8827468d21a859e62753ed8
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-04 08:29:08 +00:00
Andrei Emeltchenko bb96f90694 drivers/nble: Refactor CCC changed logic
Use similar to HCI stack cfg structure to keep value.

Change-Id: I54cf731971c5e2822385dc8eb295ce9951969af6
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-04 08:28:56 +00:00
Andrei Emeltchenko 21f23c21ad drivers/nble: Save peer address with CCC write
Save peer address to use it with bt_gatt_notify()

Change-Id: Ie5e3af4cdc2d225c9572e010359f59323ae493a7
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-05-04 08:16:10 +00:00
Grzegorz Kolodziejczyk 3639ddb7a7 Bluetooth: drivers/nble: Fix calling cmd from discov callback
Private gatt data from connection is indicator if another operation is
pending. Some att commands may be called within discovery callback
like subscription on ccc (within characteristic discovery procedure).
Without clearing conn private gatt data member, leads to rejection of
called in callback att command due to being "busy".

Change-Id: I72a35ed82dac2f0538f2d1637163bd2302f0b072
Signed-off-by: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@tieto.com>
2016-04-29 10:50:10 +00:00
Mariusz Skamra 8adb16fc32 drivers/nble: Fix missing write flush() callback
This callback is needed to successfully perform write operation.

Change-Id: I09776dda16dac639320a7e83a66e7a9b31ebea6a
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-04-28 17:34:23 +02:00
Mariusz Skamra 76b6716452 drivers/nble: Fix passing NULL pointer instead of conn to write() cb
conn object pointer has to be passed to the write callback instead
on NULL pointer.

Change-Id: Ifde88be0a43bcd9e1acbe11b16512776cd18fc66
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-04-28 17:32:05 +02:00
Mariusz Skamra a653f8a168 drivers/nble: Fix status returned from on_nble_gatts_write_evt
If attribute has no write callback, BT_ATT_ERR_WRITE_NOT_PERMITTED
error shall be returned.

Change-Id: I9277f8682597ee7f93a1267d2de31b3cc245f1cd
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-04-28 17:29:17 +02:00
Roger Lendenmann 3278f542eb Bluetooth: gatt: include service api definition proposal
* service include macro definition takes reference to
   first service attribute of the included service

Change-Id: Ib2b1defe2c99aea738da791af74a534d56025eae
Signed-off-by: Roger Lendenmann <roger.lendenmann@intel.com>
2016-04-28 10:35:38 +00:00
Andrei Emeltchenko c6f9941311 drivers/nble: Improve debug
Add debug for bt_gatt_notify() and print parameters in
on_nble_gap_conn_update_evt().

Change-Id: I5b61b5dbf508a2ee8e0b79c8636bc2dc710fb2ef
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-04-27 12:02:33 +00:00
Andrei Emeltchenko 5a19423bb4 drivers/nble: Remove unneeded type cast
Since the header was updated type cast is not needed.

Change-Id: I6a232cd8515fb48ef2a0d16cc064effac7b80bfd
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-04-27 12:02:23 +00:00
Johan Hedberg 6a075ace24 Bluetooth: drivers/nble: Initial implementation of bt_storage_clear()
Now that there's a helper for clearing nRF51-side bonds we can use
that in bt_storage_clear().

Change-Id: I9eea4b100834b150e7c55a5141f1624853335c0a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-26 15:21:36 +03:00
Johan Hedberg 0b68af523e Bluetooth: drivers/nble: Clear bonds upon init
To ensure reliable behavior when pairing we need to clear the nRF51
persistent memory upon init.

Change-Id: I204bb27e7c6e33dc5dd006ad9937645e907e770f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-26 15:08:34 +03:00
Johan Hedberg 4832da8db7 Bluetooth: drivers/nble: Fix using too large buffer
The nble firmware supports a max ATT MTU of 23 (i.e. the default).

Change-Id: I70f55b00b50b2ad6540850d594a6d2fb89b11d1a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-25 19:21:28 +00:00
Johan Hedberg 39e63117c4 Bluetooth: drivers/nble: Fix passing NULL to attr->read()
We should be looking up the appropriate connection object and passing
that to the callback.

Change-Id: I04620b301541c8bda45f20e2b1dcca8f71562821
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-25 19:21:10 +00:00
Johan Hedberg 847703d91b Bluetooth: drivers/nble: Fix on_nble_gatts_read_evt() behavior
We need to reset len to 0 in case of failure to prevent the nRF
firmware from reading past the end of buffer. At the same time clean
up the code a bit.

Change-Id: I2ac9a86e0f7704ae55c9b2758e02dfadf650f549
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-25 19:20:58 +00:00
Andrei Emeltchenko 0ff961fb29 drivers/nble: Update Nordic RPC to 0425
Update RPC to Nordic BLE radio module to 0425 revision.

Change-Id: Ieb79821acd5a8fbc4358ea5e1f258834a7932c2c
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-04-25 15:03:53 +03:00
Anas Nashif 1797c8f108 qmsi: uart: use built-in qmsi driver
Change-Id: Ie19aee8dad8ba082891f92a2d42dc71f4ac34dbe
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-04-22 20:55:36 -04:00
Anas Nashif 324a83bed7 nble: Use string name for GPIO driver
Do not depend on specific implementation of the driver, use
well-known driver name used across multiple IPs.

Change-Id: I823fcfa01ce1484dd89f6ade8fbe7017f2084bc6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-04-23 00:54:34 +00:00
Johan Hedberg e3e91d3280 Bluetooth: Add name member to HCI driver struct
This is more of a convenience to let the driver identify itself in
debug logs and the monitor protocol.

Change-Id: I73351477e98d45d6344c180b8088bde29df6f7d9
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-22 18:49:11 +03:00
Johan Hedberg 4488fc6cab Bluetooth: Move HCI device bus information to the driver
The bus that we notify over the monitor protocol is really driver
specific, so let each driver specify their bus type.

Change-Id: Ic3a086fcc06352dbf051e52cef5bf6b8696349ae
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-22 18:49:11 +03:00
Andrei Emeltchenko 5860325b4f drivers/nble: Cleanup Nordic RPC code
Remove handling not used and obsolete function prototypes.

Change-Id: I6086f2e13efe7fc219f237dda710a545bec07612
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-04-21 15:31:09 +00:00
Andrei Emeltchenko 642d596d69 drivers/nble: Update RPC to 0422 revision
Update RPC adding gap_tx_power request and event. Corresponds to BLE
version ATLASEDGE/PVT/FACTORY-386-gc1f694b.

Change-Id: I7e47553af63c3c3405522e37f86d9004dcca46f7
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-04-21 15:30:54 +00:00
Johan Hedberg b090d75d62 Bluetooth: drivers/h5: Remove redundant BT_DBG()
Change-Id: I90e7caadfb357c1c2451b0108d11ce57c0dae77a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-21 10:41:48 +03:00
Andrei Emeltchenko 503d01a96c Bluetooth: Fix typo tupe to type
Fixes compilation with debug for drivers h4 and h5

Change-Id: Ia09ce0a5ca3d684a4f9d25fdfe8530e80a46afac
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-04-21 10:09:30 +03:00
Johan Hedberg 560956c54d Bluetooth: Kconfig: Split debug selection into a choice
This prepares for adding other debug types besides the printf-style
logging to the console.

Change-Id: Ic2ed305192491734da991c4f61fdaace03fd60f2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-20 17:46:09 +03:00
Johan Hedberg d458c616df Bluetooth: Add missing debug log to HCI driver send()
Change-Id: I0842675192cd1fbf3997a8f0d4906f114c0489c1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-19 14:39:55 +03:00
Johan Hedberg 72ce7c7dc1 Bluetooth: Add support for waiting for "NOP" Command Complete
Some controllers will emit an initial "NOP" Command Complete event
during initialization and expect the host to only send commands once
this event has been received. This patch adds a new Kconfig option to
be used in the case of such controllers and defaults this to true on
Arduino 101 with the H:4 driver where this behavior is currently
observed.

Change-Id: I440f14a7c07ac27545febf9f85ebcc343e2a4558
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-18 12:58:22 +00:00
Andrei Emeltchenko 2329d54546 arduino: Remove Kconfig warnings rearranging GPIO selection
Remove warnings below:
...
warning: (BLUETOOTH_NRF51_PM) selects GPIO which has unmet direct
dependencies (BOARD_GALILEO || BOARD_QUARK_SE_DEVBOARD &&
NETWORKING_WITH_15_4_TI_CC2520 || SOC_FSL_FRDM_K64F)
...

Change-Id: I15db8cf5f9895e0693e3363974e4cdad533b55a4
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-04-18 12:54:20 +00:00
Anas Nashif 874877519e Bluetooth: include errno.h
Change-Id: I42e9e952780c4ffeba28a857b9a3836dcda5d7ba
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-04-16 02:02:11 +00:00
Andrei Emeltchenko 8418b2eeb3 drivers/nble: Implement read multiple response
Implement on_nble_gattc_read_multiple_rsp().

Change-Id: I25e8e7f74325024fde1737086e4674893f4a105a
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-04-15 17:02:11 +00:00
Mariusz Skamra 1bc53f3f47 drivers/nble: Fix NULL pointer dereference
This fixes conn->gatt_private = NULL pointer dereference that occurs
in the next Read Blob Response, here:

/* TODO: Get params from user_data pointer, not working at the moment */
params = conn->gatt_private;

Change-Id: Icf280c856133a4c91fc10475d3a047809f917f46
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-04-15 11:04:20 +02:00
Szymon Janc c2a1ac8ae7 Bluetooth: Add support for confirming incoming JustWorks pairing
If incoming pairing request would result in JustWorks pairing this
can be used to request consent from user for accepting it.

Change-Id: If0695d0e1bb010bade6a16abe1b57a2ce07856cc
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-04-14 15:20:03 +00:00
Andrei Emeltchenko 931afc81a4 drivers/nble: Fix spelling typo
Change-Id: Ibe5c910a69fccdf4375738ec13cbea9d6c972a41
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-04-14 14:48:51 +00:00
Grzegorz Kolodziejczyk 2bae7b4c5f Bluetooth: drivers/nble: Fix returning included service handle
Parse include function intention is to return last parsed included
service handle. Next discovery iteration of included services should be
started from last found included service handle instead of end handle
from included handle value (which contains attribute handle of included
service declaration and the end group handle, BLUETOOTH SPECIFICATION
Version 4.2 [Vol 3, Part G], 4.5.1).

Change-Id: I73fe4027cb616242e838ea54c61b7780f1838e52
Signed-off-by: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@tieto.com>
2016-04-14 13:47:26 +00:00
Mariusz Skamra ff8b88b634 drivers/nble: Fix handling read errors
If on_nble_gattc_read_rsp returns an error, this error shall be
passed to the application to let know that Read Request/Read Blob Request
was aborted due to ATT error received.

Change-Id: I0efe26ec90fe27a1ab3c791e555ebe682927ab57
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-04-14 12:42:09 +02:00
Mariusz Skamra 5047d54403 drivers/nble: Fix compare logic in on_nble_gattc_read_rsp
The Read Response only contains a Characteristic Value that is less
than or equal to (ATT_MTU – 1) octets in length so, condition
(length < bt_att_get_mtu(conn)) is always true, and the full
Characteristic Value will not be read.

Change-Id: Ib18fbedf277c880dc5cf0ce21fd7d550d12a64ef
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-04-14 12:41:39 +02:00
Johan Hedberg bacdf02061 Bluetooth: drivers/nble: Fix minor coding style issue
Change-Id: I71caf45702f053033fde5c5c0bc4dea22dbe95d1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-12 12:33:24 +03:00
Andrei Emeltchenko e12cf24e6d drivers/nble: Implement multiple read in bt_gatt_read
Implement read multiple characteristics in bt_gatt_read().

Change-Id: I18c11275e4352bfc571b06558116bcbb9b4a32d3
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-04-12 12:09:08 +03:00