Commit graph

656 commits

Author SHA1 Message Date
Peter Bigot f591f3e0bf drivers: bluetooth: hci: replace deprecated gpio_pin callback API
gpio_pin_en/disable_callback are to be replaced by
gpio_pin_interrupt_configure.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-02-05 12:00:36 +01:00
Peter Bigot ddc3f0699f gpio: replace gpio pin write/read with set/get
This API will be deprecated in favor of the new API that clearly
specifies whether it works on logical or physical levels.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-02-05 12:00:36 +01:00
Erwan Gouriou bfc1a50eb9 drivers: hci: spi: update to new GPIO API
Update bluetooth hcp spi driver to new GPIO API.
Following changes have been done:
- Use new gpio api functions
- Get reset, irq and cs flags from dt defines
- Define reset pin as active low and invert set/unset logic.

Tested on disco_l475_iot1 and 96b_carbon.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-02-05 12:00:36 +01:00
Peter Bigot 5e486b98b1 treewide: use full path to ipm.h header
The build infrastructure should not be adding the drivers subdirectory
to the include path.  Fix the legacy uses that depended on that
addition.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-26 17:52:12 +01:00
Carles Cufi 6cf7ac77bf Bluetooth: Always use full path to hci_driver.h
The path to include/drivers should not be in the compiler include path
list, only include/. In order to make this possible, always explictly
refer to hci_driver.h via the drivers/bluetooth/ path and not only
bluetooth/.

Fixes #21974.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-01-16 19:20:39 -05:00
Håkon Øye Amundsen 311b31d9f4 Bluetooth: select BT_RPMSG_NRF53 for non-secure variant of nrf5340
Prior to this you would get compilation error when building
samples for the nrf5340_dk_nrf5340_cpuappns board.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2020-01-10 16:33:00 +01:00
Ulf Magnusson 6ef29c0250 kconfig: Remove some redundant single-item menus and ifs
A single menu within an if like

    if FOO

    menu "blah"

    ...

    endmenu

    endif

can be replaced with

    menu "blah"
            depends on FOO

    ...

    endmenu

Fix up all existing instances.

Also remove redundant extra menus underneath 'menuconfig' symbols.
'menuconfig' already creates a menu.

Also remove the menu in arch/arm/core/aarch32/Kconfig around the
"Floating point ABI" choice. The choice depends on FLOAT, which depends
on CPU_HAS_CPU, so remove the 'depends on CPU_HAS_FPU' too.

Piggyback removing a redundant 'default n' for BME280.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-21 10:26:54 -05:00
ZhongYao Luo 6412c070eb bluetooth: h5: sending priority events through bt_recv_pri
By default all events are processed through bt_recv, which results
in lost events and subsys/bluetooth/hci_core.c:hci_event function
assertions fail to pass

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2019-12-09 17:04:24 +02:00
ZhongYao Luo 994246f7c6 bluetooth: h5: Handling the the zero length ack packet
If H5_HDR_LEN is equal to zero, remaining will grow
negatively, the commit fixes the problem.

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2019-12-09 17:04:24 +02:00
ZhongYao Luo 5758a9e1c6 bluetooth: h5: Fix memory access error
According to the context information, the processing of
net_buf_add_u8 within the get_evt_buf function is
redundant and incorrect.

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2019-12-09 17:04:24 +02:00
Kamil Piszczek 362f2299cd drivers: bluetooth: hci: rpmsg: fix handling of hci events
Fixed handling of HCI events in the HCI driver over RPMsg. Now,
the driver makes use of discardable buffer pool when allocating
memory for certain HCI event types (e.g. Advertising Report Event).
Applications that are flooded with Advertising Reports will run
much better after this change (e.g. Mesh applications).

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-11-28 10:55:32 +02:00
Kamil Piszczek 83107e5ffd drivers: bluetooth: hci: driver based on RPMsg transport
This commit contributes an RPMsg-based transport for BLE HCI.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-11-20 19:29:06 +01:00
Johan Hedberg d67416321e Bluetooth: hci_raw: Add support for specifying buffer headroom
The HCI transport implemented by an application using the HCI raw
interface may have its own buffer headroom requirements. Currently the
available headroom gets completely determined by the selected HCI
driver. E.g. most of the time this is the native controller driver
which doesn't reserve any headroom at all.

To cover for the needs of HCI raw users, add a new Kconfig variable
for the apps to set to whatever they need. Correspondingly, use the
maximum of the HCI driver and HCI raw headroom requirements for the
buffer pool definitions and the headroom initializations.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-20 19:29:06 +01:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
Marcio Montenegro 5634d70374 drivers: hci: stm32_ipm: add UID BLE address
The STM32WB has a 64 bit Unique Device Number UID.
The UID is used by firmware to derive 48-bit
Device Address EUI-48.

Signed-off-by: Marcio Montenegro <mtuxpe@gmail.com>
2019-11-04 16:40:01 +01:00
Pavlo Hamov 3674d3343f drivers: hci: stm32_ipm: disable proper LSI
LSI1 is used for RTC, LTC2 for RF.
Disable LSI2 instead of LSI1 on BLE with LSE start

Signed-off-by: Pavlo Hamov <pavlo_hamov@jabil.com>
2019-10-18 08:24:42 -05:00
Pavlo Hamov 535bfeb784 drivers: hci: stm32_ipm: Add possibility to work on LSI
Use CLOCK_STM32_LSE as switch for the RF low speed clock source

Signed-off-by: Pavlo Hamov <pavlo_hamov@jabil.com>
2019-10-18 08:24:42 -05:00
Peter Bigot 6e5db350b2 coccinelle: standardize k_sleep calls with integer timeouts
Re-run with updated script to convert integer literal delay arguments to
k_sleep to use the standard timeout macros.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-09 08:38:10 -04:00
Pavlo Hamov 82ed1681f0 drivers: ipm_stm32wb: add workaround for conn_complete
Enhanced connection complete message lacks of
the peer address (FF::FF), which leads to pairing/bonding failure.

Fixes: #19509

Signed-off-by: Pavlo Hamov <pavlo_hamov@jabil.com>
2019-10-04 18:47:31 -07:00
Kumar Gala 8ce0cf0126 kconfig: Convert device tree chosen properties to new kconfigfunctions
Convert how we get the various chosen properties like "zephyr,console"
to use the new kconfig functions like dt_chosen_to_label.

Because of how kconfig parses things we define a set of variables of the
form DT_CHOSEN_Z_<PROP> since comma's are parsed as field seperators in
macros.

This conversion allows us to remove code in gen_defines.py for the
following chosen properties:

zephyr,console
zephyr,shell-uart
zephyr,bt-uart
zephyr,uart-pipe
zephyr,bt-mon-uart
zephyr,uart-mcumgr
zephyr,bt-c2h-uart

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-09-13 11:42:34 -05:00
Roger N'Guessan 1c7eecb1ed Bluetooth: drivers: ipm_st32wb: Fix compilation
Issue faced while running bluetooth sample (peripheral, central, ...)

on stm32wb55rg with the latest zephyr version

Signed-off-by: Roger N'Guessan <roger.nguessan@st.com>
2019-07-09 21:35:44 +03:00
Yaël Boutreux 3704e8b8b4 drivers: bluetooth: hci: spi: Handle when the buffer is empty
Check if the buffer size is not empty before spi transceive and buffer's
data processing. This fixes the need to slow down MCUs to 16MHz when
using BlueNRG-MS chips.
Tested samples : Beacon, Central, Peripheral

Signed-off-by: Yaël Boutreux <yael.boutreux@st.com>
Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@st.com>
Signed-off-by: Alexandre Torgue <alexandre.torgue@st.com>
2019-07-04 09:22:18 -04:00
Johan Hedberg 0d9dab300e Bluetooth: Introduce separate pool for discardable events
Introduce a separate buffer pool for events which the HCI driver
considers discardable. Examples of such events could be e.g.
Advertising Reports. The benefit of having such a pool means that the
if there is a heavy inflow of such events it will not cause the
allocation for other critical events to block and may even eliminate
deadlocks in some cases.

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

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

Fixes #16864

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-01 16:36:15 +03:00
Anas Nashif efb8df5366 cleanup: include/: move misc/stack.h to debug/stack.h
move misc/stack.h to debug/stack.h and
create a shim for backward-compatibility.

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

Related to #16539

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

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

Related to #16539

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

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

Related to #16539

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

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

Related to #16539

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

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

Related to #16539

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

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

Related to #16539

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

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

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Kumar Gala a614a026b7 dts: Rename DT_.*_GPIO_* to DT_.*_GPIOS_*
Convert DT_.*_GPIO_{CONTROLLER,PIN,FLAGS} ->
	DT_.*_GPIOS_{CONTROLLER,PIN,FLAGS)

Used the following commands to make these conversions:

git grep -l DT_.*_GPIO_CONTROLLER | xargs sed -i 's/DT_\(.*\)_GPIO_CONTROLLER/DT_\1_GPIOS_CONTROLLER/g'
git grep -l DT_.*_GPIO_PIN | xargs sed -i 's/DT_\(.*\)_GPIO_PIN/DT_\1_GPIOS_PIN/g'
git grep -l DT_.*_GPIO_FLAGS | xargs sed -i 's/DT_\(.*\)_GPIO_FLAGS/DT_\1_GPIOS_FLAGS/g'

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-27 13:02:34 -05:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Erwan Gouriou afb4e4ff0f drivers: spi hci: Add spi dedicated rx thread
Get spi hci driver to define its own rx thread, in order
not to mix with bt own RX thread as driver use bt_recv_prio
that expect to be used in a different thread than BT host one.

Fixes #15714

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-06-17 03:17:08 -04:00
Kumar Gala a2693975d7 dts: Convert from DT_<COMPAT>_<INSTANCE>_<PROP> to DT_INST...
Change code from using now deprecated DT_<COMPAT>_<INSTANCE>_<PROP>
defines to using DT_INST_<INSTANCE>_<COMPAT>_<PROP>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-14 08:02:15 -05:00
Anas Nashif 4c32258606 style: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Erwan Gouriou 3d9416bfed drivers/bluetooth/hci: Implement HCI driver for stm32wb
Implement HCI driver for STM32WB. It allows host to controller.
It is based on ST library allowing communication over RAM shared
bewteen chip's C-M4 and C-M0 cores.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-06-03 09:38:19 -04:00
Carles Cufi bca3deb1e7 drivers: Bluetooth: Generalize IC-specific setup hook
In order to generalize the currently specialized nRF51 IC setup hook,
make the following changes:

- Generalize the hook to bt_ic_setup()
- Use a weak NOP version by default
- Move the currently existing one to the board folder

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

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

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Patrik Flykt 97b3bd11a7 drivers: Rename reserved function names
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.

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

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

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

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Kumar Gala ff70b3444f dts: Convert CONFIG_ to DT_ symbols for chosen props
Replace generating CONFIG_ symbols with DT_ symbols for chosen
properties like 'zephyr,console' or 'zephyr,bt-mon-uart'.  We now use a
kconfigfunctions (dt_str_val) to extract the info from dts into Kconfig.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 11:41:26 -06:00
Andrzej Głąbek c047e8e469 drivers: bluetooth: hci_spi: Use DT instead of Kconfig to get HW params
Convert the HCI SPI driver to get the SPI and GPIO settings from Device
Tree instead of Kconfig. The "zephyr,bt-hci-spi" binding is used as
a common one for this purpose ("st,spbtle-rf" is removed), to take
advantage of the new DT_<COMPAT>_<INSTANCE> generated macros and get
rid of related fixups and aliases.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-02-01 19:12:57 -05:00
Patrik Flykt 8ff96b5a57 drivers: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Kumar Gala aa2bdbe322 drivers: Remove board.h include
We either don't need board.h in the driver or we should be include soc.h
instead.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-01 13:21:11 -04:00
Kumar Gala ef1cc3f488 bluetooth: hci: spi: Fix compile warning
drivers/bluetooth/hci/spi.c: In function ‘bt_spi_open’:
drivers/bluetooth/hci/spi.c:475:31: error: passing argument 2 of ‘gpio_init_callback’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  gpio_init_callback(&gpio_cb, bt_spi_isr, BIT(GPIO_IRQ_PIN));
                               ^~~~~~~~~~
In file included from drivers/bluetooth/hci/spi.c:9:0:
include/gpio.h:247:20: note: expected ‘gpio_callback_handler_t {aka void (*)(struct device *, struct gpio_callback *, long unsigned int)}’ but argument is of type ‘void (*)(struct device *, struct gpio_callback *, unsigned int)’
 static inline void gpio_init_callback(struct gpio_callback *callback,
                    ^~~~~~~~~~~~~~~~~~

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-10-29 10:52:00 -04:00
Johan Hedberg 251d99132d Bluetooth: Remove custom stack macros
Now that log processing happens in a separate thread, the
BT_STACK_EXTRA macro is not needed (since there's no significant
overhead), and therefore the BT_STACK macros become unnecessary as
well.

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

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Maureen Helm ad32e3b543 drivers: boards: Merge HAS_DTS_SPI_PINS with HAS_DTS_SPI
Every board that uses dts-enabled spi drivers has a board-level dts, so
there is no need to have separate configs HAS_DTS_SPI_PINS and
HAS_DTS_SPI.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-10-01 21:15:06 -05:00
Maureen Helm 89ccead382 drivers: boards: Merge HAS_DTS_SPI_DEVICE with HAS_DTS_SPI
Every board that uses dts-enabled spi drivers has a board-level dts, so
there is no need to have separate configs HAS_DTS_SPI_DEVICE and
HAS_DTS_SPI.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-10-01 21:15:06 -05:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

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

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Alberto Escolar Piedras 304f26c310 Bluetooth: Userchan: Add missing headers
Added 2 missing headers in drivers/bluetooth/hci/userchan.c
(used by read,write and strtol)

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-02 19:14:19 +02:00
Ulf Magnusson d1684a83a4 Kconfig: Clean up some symbol definitions
- Remove redundant 'n' defaults. 'n' is the default value for bool
  symbols.

  This makes the auto-generated documentation clearer as well: You get
  "implicitly defaults to n" instead of
  "- n if <propagated dependencies>".

- Shorten

      <type>
      prompt "foo"

  to

      <type> "foo"

  This works for all types, not just bool.

- Various formatting nits.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-01 12:47:17 -04:00
Alberto Escolar Piedras 55f6620c3e native_posix: Refactor cmd line options
For each driver/model with command line options.
Move its code for the board file into the driver/model file.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-07-30 22:13:46 -04:00
Ulf Magnusson 3e0a900a31 drivers: bluetooth: Kconfig: Remove redundant 'default n' properties
Bool symbols implicitly default to 'n'.

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

This will make the auto-generated Kconfig documentation have "No
defaults. Implicitly defaults to n." as well, which is clearer than
'default n if ...'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-03 17:11:31 -04:00
Christophe Priouzeau b0c294ce48 bt: hci driver over spi: Configure BlueNRG-MS in controller mode
Configure BlueNRG in controller w/o host.
By disabling 'HCI_reset' via the quirk, we can request to
BluesNRG hardware to be on controller mode just after it is ready.
By the way it's no necessary to manage a 'HCI_reset' when BluesNRG are
initialised (and on controler mode).

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2018-06-29 10:40:25 +02:00
Christophe Priouzeau 7b02e6dc55 bt: hci driver over spi: BlueNRG-MS read until IRQ pin goes low
According to BlueNRG-MS ref manual, SPI master shoul read  from
controller as long as IRQ pin is high.
Introduce a new loop within spi_rx_thread to do so. Since
it is now possible to enter read loop with nothing to read, set
a max attempts limit to be sure to exit the loop.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
2018-06-29 10:40:25 +02:00
Loic Poulain ea5b866763 Bluetooth: hci: spi: Select BT_RECV_IS_RX_THREAD
SPI driver has its own rx thread, select BT_RECV_IS_RX_THREAD.
This fixes build issue because of undefined CONFIG_BT_RX_PRIO.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-06-11 17:28:27 -04:00
Johan Hedberg 7d9896575b Bluetooth: Add HCI User Channel driver for native POSIX port
Introduce a custom HCI driver for the native POSIX port, which opens a
HCI User Channel socket to the Linux kernel to gain access to a local
Bluetooth controller.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-11 17:14:43 -04:00
Yannis Damigos 82c0b8cba1 drivers/bluetooth/hci: Name the choice of BT HCI driver bus
Name the choice of BT HCI driver bus in order to config it
in the board's Kconfig.defconfig file.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-15 15:11:12 -05:00
Erwan Gouriou 00376f08ca dts/bindings: Add reset and irq gpios to "st,spbtle-rf" yaml
In order to generate GPIO definition for control pin of BlueNRG module
define reset-gpio and irq-gpio in st,spbtle-rf yaml binding.

Add HAS_DTS_SPI_PINS kconfig symbol to control use of the '#define'

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2018-05-10 14:21:16 -05:00
Tomasz Bursztyka 3219817d4a drivers/bluetooth: Get rid completely of legacy SPI API in SPI HCI
No need to support legacy API there.
The special usage of CS in BlueNRG is centralized it dedicated functions
to avoid all the #ifdefs everywher.
Also managing transaction error.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka 595340ab8a drivers/bluetooth: Switch SPI based HCI driver to new SPI API
Replacing legacy API calls by news ones.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Yannis Damigos 8faa307d74 dts: add spi device support for SPI bluetooth modules
Provides HAS_DTS_SPI_DEVICE flag to enable dts based
generation for SPI bluetooth modules

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-01-22 18:08:51 -06:00
Carles Cufi 7d764b35f3 cmake: Use path-corrected version of ZEPHYR_BASE
Instead of accessing the environment variable ZEPHYR_BASE every time we
require accessing the source code root, use an intermediate variable
that has OS path separators correctly set to '/' to avoid issues on
Windows.

Note: This removes the ZEPHYR_SOURCE_DIR CMake variable. External
applications using that will need to change to use the new ZEPHYR_BASE
variable.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-11 14:59:03 -05:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

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

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

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

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

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

$ cd build
$ make

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

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Tomasz Bursztyka 5f1360e27d drivers/bluetooth/spi: Do not initialize vendor attribute
As commit introducing it will be reverted.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-10 09:42:45 -04:00
Marti Bolivar 272e8ffccd Bluetooth: hci: spi: add support for new SPI API
Add shim routines for the new SPI driver API.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-15 22:58:02 +03:00
Marti Bolivar bd5c2c07b3 Bluetooth: hci: spi: abstract out legacy SPI API
Some targets (e.g. STM32-based boards) only have SPI drivers using the
new API. To support both these and existing, legacy SPI drivers in the
SPI HCI driver, abstract out the SPI API into shim routines.

There are no behavioral differences due to this patch. The next patch
will add support for the new API.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-15 22:58:02 +03:00
Carles Cufi d5c13a7530 Bluetooth: controller: Rename Kconfig prefix
Rename the BT_CONTROLLER prefix used in all of the Kconfig variables
related to the Bluetooth controller to BT_CTLR.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-14 15:44:56 +03:00
Sebastian Bøe c4176c6526 Kconfig: Hide the "Bluetooth Drivers" menu entry when BT_CONTROLLER
It used to be that there was a fairly empty "Bluetooth Drivers" menu
entry in the drivers menu. This entry was present even though there
was no drivers/bluetooth code being compiled in.

With this patch "Bluetooth Drivers" will no longer be present when
BT_CONTROLLER is enabled.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-09 19:06:14 +03:00
Sebastian Bøe 2120beebf4 Kconfig: Move BT_WAIT_NOP into subsys/bluetooth/host
The CONFIG_BT_WAIT_NOP define is used only by
zephyr/subsys/bluetooth/host/hci_core.c.

It is also the only config in drivers/bluetooth that is in use when
BT_CONTROLLER is enabled. Moving it into the bluetooth subsystem
allows us to restructure the drivers/kconfig code such that the entire
Bluetooth driver menu option is omitted when the BT_CONTROLLER is
enabled.

Moving it will also mean that all configs in drivers/bluetooth will
now be related to configuring the source code in drivers/bluetooth.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-09 19:06:14 +03:00
Johan Hedberg 2975ca0754 Bluetooth: Kconfig: Rename CONFIG_BLUETOOTH_* to CONFIG_BT_*
The API name space for Bluetooth is bt_* and BT_* so it makes sense to
align the Kconfig name space with this. The additional benefit is that
this also makes the names shorter. It is also in line with what Linux
uses for Bluetooth Kconfig entries.

Some Bluetooth-related Networking Kconfig defines are renamed as well
in order to be consistent, such as NET_L2_BLUETOOTH.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-09 11:14:19 +03:00
Sebastian Bøe 197e6e2ba3 Kconfig: Move BLUETOOTH_HCI_RESERVE into subsys/bluetooth/host
There are two kinds of HCI implementations. Bluetooth drivers in
 drivers/bluetooth that implement HCI by using a wired serial
 transport layer to talk to an external controller chip. And a
 bluetooth controller in subsys/bluetooth/controller that directly
 talks to an internal on-chip controller node.

Currently, when the the subsys/bluetooth/controller is used there
still exists exposed to the user a bluetooth driver configuration
menu, even though no external bluetooth driver is in use. This is due
to a dependency on certain configs in driver/bluetooth that are needed
even though no external controller is used.

This patch moves one of these configs, BLUETOOTH_HCI_RESERVE, from
drivers/bluetooth/hci/Kconfig to subsys/bluetooth/host/Kconfig such
that eventually we can omit the entire Bluetooth driver menu option.

This re-organization does not change when the config can be enabled.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-08 23:01:05 +03:00
Savinay Dharmappa c1e5cbfd41 devicetree: Generate BLUETOOTH_UART,UART_PIPE etc config from dt
patch uses chosen property zephyr,bt-uart, zephyr,uart-pipe
and zephyr,bt-mon-uart to determine the uart instance to be
used for bluetooth,uart_pipe and bluetooth_monitor and generate
appropriate configs.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2017-07-19 11:52:35 -04:00
Vinayak Kariappa Chettimada 9a13a0c732 Bluetooth: Add BUILD_ASSERT to check Tx and Rx thread priorities
Added BUILD_ASSERT check for Tx and Rx thread priorities.

The Tx thread priority shall be higher than Rx thread
priority in order to correctly detect transaction violations
in ATT and SMP protocols. The Number of Completed Packets
for a connection shall be processed before any new data is
received and processed for that connection.

The Controller's priority receive thread priority shall be
higher than the Host's Tx and the Controller's Rx thread
priority.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-12 13:50:51 +03:00
Andrew Boie 65a9d2a94a kernel: make K_.*_INITIALIZER private to kernel
Upcoming memory protection features will be placing some additional
constraints on kernel objects:

- They need to reside in memory owned by the kernel and not the
application
- Certain kernel object validation schemes will require some run-time
initialization of all kernel objects before they can be used.

Per Ben these initializer macros were never intended to be public. It is
not forbidden to use them, but doing so requires care: the memory being
initialized must reside in kernel space, and extra runtime
initialization steps may need to be peformed before they are fully
usable as kernel objects. In particular, kernel subsystems or drivers
whose objects are already in kernel memory may still need to use these
macros if they define kernel objects as members of a larger data
structure.

It is intended that application developers instead use the
K_<object>_DEFINE macros, which will automatically put the object in the
right memory and add them to a section which can be iterated over at
boot to complete initiailization.

There was no K_WORK_DEFINE() macro for creating struct k_work objects,
this is now added.

k_poll_event and k_poll_signal are intended to be instatiated from
application memory and have not been changed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-07-10 11:44:56 -07:00
Johan Hedberg ca61452b8e Bluetooth: drivers: Make RX thread priority consistent
The controller and host-side RX threads recently had their priorities
lowered to 8. Make the driver RX threads consistent with this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-07 10:43:58 -07:00
Andy Gross 2920815d23 bluetooth: hci: Kconfig: Fix dependency
This patch changes the BLUETOOTH_SPI to depend on SPI.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2017-06-15 16:14:59 -05:00
Andrew Boie 2d4a36fc1c drivers: use K_THREAD_STACK_DEFINE macros
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-06-09 18:53:28 -04:00
Johan Hedberg 9516d63836 Bluetooth: Remove support for NBLE
NBLE has been deprecated for a few releases now and can be removed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-25 09:03:16 -07:00
Carles Cufi 6c9e563c92 Bluetooth: Move common code to common/
Since more and more code is going to be reused by both the Host and the
Controller, this commit introduces a common/ folder that will contain
everything that is not tied to one of the two components but shared by
them.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-12 12:56:14 +03:00
Andrew Boie 899cf94dbd bluetooth: use k_thread_create()
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
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
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